Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ import { OneCLI } from "@onecli-sh/sdk";

const onecli = new OneCLI({
apiKey: "oc_...", // optional: falls back to ONECLI_API_KEY env var
url: "http://localhost:3000", // optional: falls back to ONECLI_URL env var, then https://app.onecli.sh
url: "http://localhost:3000", // optional: falls back to ONECLI_URL env var, then https://api.onecli.sh
});

// Get raw container configuration
Expand All @@ -77,7 +77,7 @@ const active = await onecli.applyContainerConfig(args);
| Variable | Description |
| ---------------- | -------------------------------------------------------- |
| `ONECLI_API_KEY` | User API key (`oc_...`). Used when `apiKey` is not passed to constructor. |
| `ONECLI_URL` | Base URL of OneCLI instance. Defaults to `https://app.onecli.sh`. |
| `ONECLI_URL` | Base URL of OneCLI instance. Defaults to `https://api.onecli.sh`. |

## API Reference

Expand All @@ -92,7 +92,7 @@ new OneCLI(options?: OneCLIOptions)
| Option | Type | Required | Default | Description |
| --------- | -------- | -------- | ----------------------------------- | ------------------------------- |
| `apiKey` | `string` | No | `ONECLI_API_KEY` env var | User API key (`oc_...`) |
| `url` | `string` | No | `ONECLI_URL` or `https://app.onecli.sh` | Base URL of the OneCLI instance |
| `url` | `string` | No | `ONECLI_URL` or `https://api.onecli.sh` | Base URL of the OneCLI instance |
| `timeout` | `number` | No | `5000` | Request timeout in milliseconds |

#### `onecli.getContainerConfig()`
Expand Down Expand Up @@ -123,7 +123,7 @@ const active = await onecli.applyContainerConfig(args, {
| `addHostMapping` | `boolean` | `true` | Add `host.docker.internal` mapping on Linux |

**What it does:**
1. Fetches `/api/container-config` with `Authorization: Bearer {apiKey}`
1. Fetches `/v1/container-config` with `Authorization: Bearer {apiKey}`
2. Pushes `-e KEY=VALUE` for each server-controlled environment variable
3. Writes CA certificate to a temp file and mounts it into the container
4. Builds a combined CA bundle (system CAs + OneCLI CA) so curl, Python, Go, etc. also trust OneCLI
Expand Down
2 changes: 1 addition & 1 deletion src/agents/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export class AgentsClient {
input: CreateAgentInput,
options?: RequestOptions,
): Promise<CreateAgentResponse> => {
const url = `${this.baseUrl}/api/agents`;
const url = `${this.baseUrl}/v1/agents`;

try {
const res = await fetch(url, {
Expand Down
6 changes: 3 additions & 3 deletions src/approvals/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export class ApprovalClient {
): Promise<string> {
if (this.gatewayUrl) return this.gatewayUrl;

const url = `${this.baseUrl}/api/gateway-url`;
const url = `${this.baseUrl}/v1/gateway-url`;
const res = await fetch(url, {
headers: this.buildAuthHeaders(projectId),
signal: AbortSignal.timeout(5000),
Expand Down Expand Up @@ -147,7 +147,7 @@ export class ApprovalClient {
): Promise<PollResponse> {
this.abortController = new AbortController();

let url = `${gatewayUrl}/api/approvals/pending`;
let url = `${gatewayUrl}/v1/approvals/pending`;
if (this.inFlight.size > 0) {
const exclude = [...this.inFlight].join(",");
url += `?exclude=${encodeURIComponent(exclude)}`;
Expand Down Expand Up @@ -177,7 +177,7 @@ export class ApprovalClient {
decision: string,
projectId?: string | null,
): Promise<void> {
const url = `${gatewayUrl}/api/approvals/${encodeURIComponent(id)}/decision`;
const url = `${gatewayUrl}/v1/approvals/${encodeURIComponent(id)}/decision`;

const headers = this.buildAuthHeaders(projectId);
headers["Content-Type"] = "application/json";
Expand Down
2 changes: 1 addition & 1 deletion src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import type {
ProvisionProjectResponse,
} from "./provisions/types.js";

const DEFAULT_URL = "https://app.onecli.sh";
const DEFAULT_URL = "https://api.onecli.sh";
const DEFAULT_TIMEOUT = 5000;

export class OneCLI {
Expand Down
6 changes: 3 additions & 3 deletions src/container/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export class ContainerClient {
* Fetch the gateway skill markdown from OneCLI.
*/
getGatewaySkill = async (options?: RequestOptions): Promise<string> => {
const url = `${this.baseUrl}/api/skill/gateway`;
const url = `${this.baseUrl}/v1/skill/gateway`;
try {
const res = await fetch(url, {
headers: this.buildHeaders(options),
Expand Down Expand Up @@ -75,8 +75,8 @@ export class ContainerClient {
): Promise<ContainerConfig> => {
const { agent, ...requestOptions } = options ?? {};
const url = agent
? `${this.baseUrl}/api/container-config?agent=${encodeURIComponent(agent)}`
: `${this.baseUrl}/api/container-config`;
? `${this.baseUrl}/v1/container-config?agent=${encodeURIComponent(agent)}`
: `${this.baseUrl}/v1/container-config`;

try {
const res = await fetch(url, {
Expand Down
2 changes: 1 addition & 1 deletion src/provisions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export class ProvisionClient {
input?: ProvisionProjectInput,
options?: RequestOptions,
): Promise<ProvisionProjectResponse> => {
const url = `${this.baseUrl}/api/team/provisions`;
const url = `${this.baseUrl}/v1/team/provisions`;

try {
const res = await fetch(url, {
Expand Down
4 changes: 2 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export interface OneCLIOptions {

/**
* Base URL of the OneCLI instance.
* Falls back to `ONECLI_URL` env var, then `https://app.onecli.sh`.
* Falls back to `ONECLI_URL` env var, then `https://api.onecli.sh`.
*/
url?: string;

Expand All @@ -21,7 +21,7 @@ export interface OneCLIOptions {
/**
* Gateway URL for manual approval polling.
* Falls back to `ONECLI_GATEWAY_URL` env var, then auto-resolved
* from the web app via `GET /api/gateway-url`.
* from the web app via `GET /v1/gateway-url`.
*/
gatewayUrl?: string;

Expand Down
6 changes: 3 additions & 3 deletions test/agents/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe("AgentsClient", () => {
client.createAgent({ name: "Test", identifier: "test" });

expect(fetchSpy).toHaveBeenCalledWith(
"http://localhost:3000/api/agents",
"http://localhost:3000/v1/agents",
expect.any(Object),
);
});
Expand All @@ -50,7 +50,7 @@ describe("AgentsClient", () => {
await client.createAgent({ name: "My Agent", identifier: "my-agent" });

expect(fetchSpy).toHaveBeenCalledWith(
"http://localhost:3000/api/agents",
"http://localhost:3000/v1/agents",
expect.objectContaining({
method: "POST",
headers: {
Expand Down Expand Up @@ -118,7 +118,7 @@ describe("AgentsClient", () => {
client.createAgent({ name: "Test", identifier: "test" }),
).rejects.toMatchObject({
statusCode: 401,
url: "http://localhost:3000/api/agents",
url: "http://localhost:3000/v1/agents",
});
});

Expand Down
2 changes: 1 addition & 1 deletion test/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ describe("OneCLI", () => {
oc.getContainerConfig();

expect(fetchSpy).toHaveBeenCalledWith(
"http://options-url:3000/api/container-config",
"http://options-url:3000/v1/container-config",
expect.any(Object),
);

Expand Down
6 changes: 3 additions & 3 deletions test/container/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ describe("ContainerClient", () => {
client.getContainerConfig();

expect(fetchSpy).toHaveBeenCalledWith(
"http://localhost:3000/api/container-config",
"http://localhost:3000/v1/container-config",
expect.any(Object),
);
});
Expand All @@ -57,7 +57,7 @@ describe("ContainerClient", () => {
await client.getContainerConfig();

expect(fetchSpy).toHaveBeenCalledWith(
"http://localhost:3000/api/container-config",
"http://localhost:3000/v1/container-config",
expect.objectContaining({
headers: { Authorization: "Bearer oc_mykey" },
}),
Expand Down Expand Up @@ -118,7 +118,7 @@ describe("ContainerClient", () => {
);
await expect(client.getContainerConfig()).rejects.toMatchObject({
statusCode: 401,
url: "http://localhost:3000/api/container-config",
url: "http://localhost:3000/v1/container-config",
});
});

Expand Down
6 changes: 3 additions & 3 deletions test/errors.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ describe("OneCLIError", () => {
describe("OneCLIRequestError", () => {
it("sets name, url, statusCode, and formatted message", () => {
const err = new OneCLIRequestError("Not Found", {
url: "http://localhost:3000/api/container-config",
url: "http://localhost:3000/v1/container-config",
statusCode: 404,
});
expect(err.name).toBe("OneCLIRequestError");
expect(err.url).toBe("http://localhost:3000/api/container-config");
expect(err.url).toBe("http://localhost:3000/v1/container-config");
expect(err.statusCode).toBe(404);
expect(err.message).toBe(
"[URL=http://localhost:3000/api/container-config] [StatusCode=404] Not Found",
"[URL=http://localhost:3000/v1/container-config] [StatusCode=404] Not Found",
);
expect(err).toBeInstanceOf(Error);
});
Expand Down
Loading