@coder/ai-sdk-agent 0.7.1 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -2
- package/dist/index.d.ts +4 -4
- package/dist/index.js +9 -6
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -196,6 +196,15 @@ Pass a Coder **API token** or **session token** as `token`; it is sent as the
|
|
|
196
196
|
`Coder-Session-Token` header (REST) and used to authenticate the streaming WebSocket. Create
|
|
197
197
|
a token with `coder tokens create`, or reuse your CLI session.
|
|
198
198
|
|
|
199
|
+
When `baseUrl`/`token` are not passed, they default from the `CODER_URL` and
|
|
200
|
+
`CODER_SESSION_TOKEN` environment variables (the same convention as
|
|
201
|
+
`@coder/ai-sdk-sandbox`'s transports); explicit settings win over the
|
|
202
|
+
environment. With the variables set, connection config disappears entirely:
|
|
203
|
+
|
|
204
|
+
```ts
|
|
205
|
+
const agent = new CoderAgent({ organizationId }); // uses CODER_URL + CODER_SESSION_TOKEN
|
|
206
|
+
```
|
|
207
|
+
|
|
199
208
|
You can also pass a pre‑built client:
|
|
200
209
|
|
|
201
210
|
```ts
|
|
@@ -675,7 +684,8 @@ Coder servers — no experimental endpoints.
|
|
|
675
684
|
named "80" and never resolve; serve the preview on a higher port.
|
|
676
685
|
|
|
677
686
|
The preview helpers call non‑chat endpoints, so they need `baseUrl` + `token`
|
|
678
|
-
credentials — pass them alongside `client` if you construct one yourself
|
|
687
|
+
credentials — pass them alongside `client` if you construct one yourself (or
|
|
688
|
+
let them default from `CODER_URL`/`CODER_SESSION_TOKEN`).
|
|
679
689
|
|
|
680
690
|
## Workspaces & quota
|
|
681
691
|
|
|
@@ -835,7 +845,7 @@ sequence pinpoints _where_ a turn died:
|
|
|
835
845
|
|
|
836
846
|
| field | description |
|
|
837
847
|
| --------------------------------- | ------------------------------------------------------------------------------------------------ |
|
|
838
|
-
| `client` \| (`baseUrl` + `token`) | connection (one or the other)
|
|
848
|
+
| `client` \| (`baseUrl` + `token`) | connection (one or the other; `baseUrl`/`token` default from `CODER_URL`/`CODER_SESSION_TOKEN`) |
|
|
839
849
|
| `organizationId` | org UUID that owns the chat (required) |
|
|
840
850
|
| `model` | model hint: UUID, `provider:model`, model id, or display‑name substring |
|
|
841
851
|
| `instructions` | system prompt |
|
package/dist/index.d.ts
CHANGED
|
@@ -820,13 +820,13 @@ interface CoderAgentSettings<TOOLS extends ToolSet = {}> {
|
|
|
820
820
|
* A pre-built {@link CoderChatClient}, used instead of constructing one from
|
|
821
821
|
* `baseUrl`/`token`. The preview helpers ({@link CoderAgent.getPreview},
|
|
822
822
|
* {@link CoderAgent.sharePreview}) call non-chat endpoints and therefore
|
|
823
|
-
* still need credentials — pass `baseUrl` + `token` alongside `client`
|
|
824
|
-
* enable them.
|
|
823
|
+
* still need credentials — pass `baseUrl` + `token` alongside `client` (or
|
|
824
|
+
* set `CODER_URL` + `CODER_SESSION_TOKEN`) to enable them.
|
|
825
825
|
*/
|
|
826
826
|
client?: CoderChatClient;
|
|
827
|
-
/** Coder deployment base URL, e.g. `https://dev.coder.com`. */
|
|
827
|
+
/** Coder deployment base URL, e.g. `https://dev.coder.com`. Defaults to `CODER_URL`. */
|
|
828
828
|
baseUrl?: string;
|
|
829
|
-
/** Coder API/session token (sent as `Coder-Session-Token`). */
|
|
829
|
+
/** Coder API/session token (sent as `Coder-Session-Token`). Defaults to `CODER_SESSION_TOKEN`. */
|
|
830
830
|
token?: string;
|
|
831
831
|
fetch?: CoderChatClientOptions["fetch"];
|
|
832
832
|
webSocketFactory?: CoderChatClientOptions["webSocketFactory"];
|
package/dist/index.js
CHANGED
|
@@ -2466,25 +2466,28 @@ var CoderAgent = class {
|
|
|
2466
2466
|
#settleRetryDelayMs;
|
|
2467
2467
|
constructor(settings) {
|
|
2468
2468
|
assertSupportedAiVersion();
|
|
2469
|
+
const env = globalThis.process?.env;
|
|
2470
|
+
const baseUrl = settings.baseUrl ?? env?.CODER_URL;
|
|
2471
|
+
const token = settings.token ?? env?.CODER_SESSION_TOKEN;
|
|
2469
2472
|
if (settings.client) {
|
|
2470
2473
|
this.#client = settings.client;
|
|
2471
|
-
} else if (
|
|
2474
|
+
} else if (baseUrl && token) {
|
|
2472
2475
|
this.#client = new CoderChatClient({
|
|
2473
|
-
baseUrl
|
|
2474
|
-
token
|
|
2476
|
+
baseUrl,
|
|
2477
|
+
token,
|
|
2475
2478
|
fetch: settings.fetch,
|
|
2476
2479
|
webSocketFactory: settings.webSocketFactory,
|
|
2477
2480
|
onTransportEvent: settings.onTransportEvent
|
|
2478
2481
|
});
|
|
2479
2482
|
} else {
|
|
2480
2483
|
throw new CoderAgentError(
|
|
2481
|
-
"CoderAgent requires either `client` or both `baseUrl` and `token
|
|
2484
|
+
"CoderAgent requires either `client` or both `baseUrl` and `token` (or the CODER_URL and CODER_SESSION_TOKEN environment variables)."
|
|
2482
2485
|
);
|
|
2483
2486
|
}
|
|
2484
2487
|
this.#organizationId = settings.organizationId;
|
|
2485
2488
|
this.#workspaceFiles = settings.workspaceFiles;
|
|
2486
2489
|
this.#workspaceId = settings.workspaceId;
|
|
2487
|
-
this.#workspaceApi =
|
|
2490
|
+
this.#workspaceApi = baseUrl && token ? { baseUrl, token, fetch: settings.fetch } : void 0;
|
|
2488
2491
|
this.#settleDeadlineMs = sanitizeDelayMs(settings.settleDeadlineMs, SETTLE_DEADLINE_MS);
|
|
2489
2492
|
this.#settleRetryDelayMs = sanitizeDelayMs(settings.settleRetryDelayMs, SETTLE_RETRY_DELAY_MS);
|
|
2490
2493
|
if (settings.workspaceFiles && settings.workspaceId && settings.workspaceFiles.workspaceId !== settings.workspaceId) {
|
|
@@ -2658,7 +2661,7 @@ var CoderAgent = class {
|
|
|
2658
2661
|
}
|
|
2659
2662
|
if (!this.#workspaceApi) {
|
|
2660
2663
|
throw new CoderAgentError(
|
|
2661
|
-
`${method}() needs the deployment's REST credentials \u2014 construct the CoderAgent with \`baseUrl\` and \`token\` (they can accompany \`client\`).`
|
|
2664
|
+
`${method}() needs the deployment's REST credentials \u2014 construct the CoderAgent with \`baseUrl\` and \`token\` (they can accompany \`client\`), or set the CODER_URL and CODER_SESSION_TOKEN environment variables.`
|
|
2662
2665
|
);
|
|
2663
2666
|
}
|
|
2664
2667
|
return { conn: this.#workspaceApi, workspaceId: this.#workspaceId };
|