@agent-api/sdk 1.0.8 → 1.1.1

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.
@@ -0,0 +1,2 @@
1
+ export * from "./core.js";
2
+ export * from "./context.js";
@@ -0,0 +1,2 @@
1
+ export * from "./core.js";
2
+ export * from "./context.js";
@@ -0,0 +1,14 @@
1
+ import type { HTTPClient } from "../internal/http.js";
2
+ import type { ApprovedDeviceAuth, DeviceAuthPollResult, DeviceAuthStart, PollDeviceAuthParams, StartDeviceAuthParams, WaitForDeviceAuthParams } from "../types/auth.js";
3
+ import type { RequestOptions } from "../types/common.js";
4
+ export declare class AuthResource {
5
+ private readonly http;
6
+ constructor(http: HTTPClient);
7
+ startDeviceAuth(params?: StartDeviceAuthParams, options?: RequestOptions): Promise<DeviceAuthStart>;
8
+ pollDeviceAuth(params: PollDeviceAuthParams, options?: RequestOptions): Promise<DeviceAuthPollResult>;
9
+ waitForDeviceAuth(params: WaitForDeviceAuthParams, options?: RequestOptions): Promise<ApprovedDeviceAuth>;
10
+ }
11
+ export declare class DeviceAuthFlowError extends Error {
12
+ readonly result?: DeviceAuthPollResult;
13
+ constructor(message: string, result?: DeviceAuthPollResult);
14
+ }
@@ -0,0 +1,87 @@
1
+ const defaultDevicePollIntervalSeconds = 5;
2
+ export class AuthResource {
3
+ http;
4
+ constructor(http) {
5
+ this.http = http;
6
+ }
7
+ startDeviceAuth(params = {}, options = {}) {
8
+ return this.http.request("POST", "/v1/auth/device/start", params, options);
9
+ }
10
+ pollDeviceAuth(params, options = {}) {
11
+ requireDeviceCode(params.device_code);
12
+ return this.http.request("POST", "/v1/auth/device/poll", params, options);
13
+ }
14
+ async waitForDeviceAuth(params, options = {}) {
15
+ requireDeviceCode(params.device_code);
16
+ const startedAt = Date.now();
17
+ for (;;) {
18
+ throwIfAborted(params.signal);
19
+ const result = await this.pollDeviceAuth({ device_code: params.device_code }, options);
20
+ params.on_poll?.(result);
21
+ if (result.status === "approved" && result.access_token && result.refresh_token) {
22
+ return result;
23
+ }
24
+ if (result.status === "expired" || result.status === "consumed") {
25
+ throw new DeviceAuthFlowError(result.message || `Device auth ${result.status}`, result);
26
+ }
27
+ const timeoutMs = effectiveTimeoutMs(params, result);
28
+ if (timeoutMs !== undefined && Date.now() - startedAt >= timeoutMs) {
29
+ throw new DeviceAuthFlowError("Device auth timed out", result);
30
+ }
31
+ await sleep(pollDelayMs(params, result), params.signal);
32
+ }
33
+ }
34
+ }
35
+ export class DeviceAuthFlowError extends Error {
36
+ result;
37
+ constructor(message, result) {
38
+ super(message);
39
+ this.name = "DeviceAuthFlowError";
40
+ this.result = result;
41
+ Object.setPrototypeOf(this, DeviceAuthFlowError.prototype);
42
+ }
43
+ }
44
+ function requireDeviceCode(deviceCode) {
45
+ if (!deviceCode || !deviceCode.trim()) {
46
+ throw new TypeError("device_code is required");
47
+ }
48
+ }
49
+ function pollDelayMs(params, result) {
50
+ const seconds = params.interval_seconds ?? result.interval_seconds ?? defaultDevicePollIntervalSeconds;
51
+ return Math.max(1, seconds) * 1000;
52
+ }
53
+ function effectiveTimeoutMs(params, result) {
54
+ if (params.timeout_ms !== undefined) {
55
+ return Math.max(0, params.timeout_ms);
56
+ }
57
+ const expiresAt = result.expires_at;
58
+ if (!expiresAt)
59
+ return undefined;
60
+ return Math.max(0, expiresAt * 1000 - Date.now());
61
+ }
62
+ function sleep(ms, signal) {
63
+ if (!signal) {
64
+ return new Promise((resolve) => setTimeout(resolve, ms));
65
+ }
66
+ throwIfAborted(signal);
67
+ return new Promise((resolve, reject) => {
68
+ const timeout = setTimeout(cleanupResolve, ms);
69
+ signal.addEventListener("abort", cleanupReject, { once: true });
70
+ function cleanupResolve() {
71
+ signal?.removeEventListener("abort", cleanupReject);
72
+ resolve();
73
+ }
74
+ function cleanupReject() {
75
+ clearTimeout(timeout);
76
+ reject(abortError());
77
+ }
78
+ });
79
+ }
80
+ function throwIfAborted(signal) {
81
+ if (signal?.aborted) {
82
+ throw abortError();
83
+ }
84
+ }
85
+ function abortError() {
86
+ return new DOMException("Device auth wait aborted", "AbortError");
87
+ }
@@ -0,0 +1,63 @@
1
+ export type DeviceAuthStatus = "pending" | "approved" | "expired" | "consumed" | string;
2
+ export interface DeviceAuthStart {
3
+ device_code: string;
4
+ user_code: string;
5
+ verification_uri: string;
6
+ verification_uri_complete: string;
7
+ expires_at: number;
8
+ interval_seconds: number;
9
+ }
10
+ export interface AuthSession {
11
+ access_token: string;
12
+ refresh_token: string;
13
+ token_type?: string;
14
+ access_token_expires_at: number;
15
+ refresh_token_expires_at?: number;
16
+ user_id: string;
17
+ workspace_id: string;
18
+ workspace_name?: string;
19
+ workspace_role: string;
20
+ scopes: string[];
21
+ }
22
+ export interface DeviceAuthPollResult {
23
+ status: DeviceAuthStatus;
24
+ message?: string;
25
+ interval_seconds?: number;
26
+ expires_at?: number;
27
+ access_token?: string;
28
+ refresh_token?: string;
29
+ token_type?: string;
30
+ access_token_expires_at?: number;
31
+ refresh_token_expires_at?: number;
32
+ user_id?: string;
33
+ workspace_id?: string;
34
+ workspace_name?: string;
35
+ workspace_role?: string;
36
+ scopes?: string[];
37
+ }
38
+ export type ApprovedDeviceAuth = DeviceAuthPollResult & {
39
+ status: "approved";
40
+ access_token: string;
41
+ refresh_token: string;
42
+ access_token_expires_at: number;
43
+ user_id: string;
44
+ workspace_id: string;
45
+ workspace_role: string;
46
+ scopes: string[];
47
+ };
48
+ export interface StartDeviceAuthParams {
49
+ client_name?: string;
50
+ }
51
+ export interface PollDeviceAuthParams {
52
+ device_code: string;
53
+ }
54
+ export interface WaitForDeviceAuthParams extends PollDeviceAuthParams {
55
+ /** Polling interval in seconds. Defaults to the server interval or 5 seconds. */
56
+ interval_seconds?: number;
57
+ /** Overall wait timeout in milliseconds. Defaults to the challenge expiry when present. */
58
+ timeout_ms?: number;
59
+ /** Optional cancellation signal for CLI/Desktop integrations. */
60
+ signal?: AbortSignal;
61
+ /** Called after every poll response, including pending responses. */
62
+ on_poll?: (result: DeviceAuthPollResult) => void;
63
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -6,3 +6,4 @@ export * from "./streaming.js";
6
6
  export * from "./catalog.js";
7
7
  export * from "./volumes.js";
8
8
  export * from "./skills.js";
9
+ export * from "./auth.js";
@@ -6,3 +6,4 @@ export * from "./streaming.js";
6
6
  export * from "./catalog.js";
7
7
  export * from "./volumes.js";
8
8
  export * from "./skills.js";
9
+ export * from "./auth.js";
@@ -2,10 +2,17 @@ import type { AgentCapabilityPreference, ErrorInfo, ModelRoutingMode, ModelRouti
2
2
  import type { ContentPart, Input, MemoryOptions, ReasoningConfig, ResponseFormat } from "./input.js";
3
3
  import type { LocalSkillDescriptor, SkillReference } from "./skills.js";
4
4
  import type { Tool } from "./tools.js";
5
+ export interface CallerContext {
6
+ timezone?: string;
7
+ locale?: string;
8
+ locality?: string;
9
+ extra?: unknown;
10
+ }
5
11
  export interface ResponseCreateParamsBase {
6
12
  input: Input;
7
13
  instructions?: string;
8
14
  language_preference?: string;
15
+ caller_context?: CallerContext;
9
16
  model?: string;
10
17
  models?: string[];
11
18
  model_routing?: ModelRoutingMode;
package/dist/version.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export declare const VERSION = "1.0.8";
2
- export declare const USER_AGENT = "@agent-api/sdk/1.0.8";
1
+ export declare const VERSION = "1.1.1";
2
+ export declare const USER_AGENT = "@agent-api/sdk/1.1.1";
package/dist/version.js CHANGED
@@ -1,2 +1,2 @@
1
- export const VERSION = "1.0.8";
1
+ export const VERSION = "1.1.1";
2
2
  export const USER_AGENT = `@agent-api/sdk/${VERSION}`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agent-api/sdk",
3
- "version": "1.0.8",
3
+ "version": "1.1.1",
4
4
  "description": "Production JavaScript SDK for the Managed Agent API",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -26,6 +26,10 @@
26
26
  ".": {
27
27
  "types": "./dist/index.d.ts",
28
28
  "import": "./dist/index.js"
29
+ },
30
+ "./local": {
31
+ "types": "./dist/local/index.d.ts",
32
+ "import": "./dist/local/index.js"
29
33
  }
30
34
  },
31
35
  "files": [
@@ -42,7 +46,7 @@
42
46
  "build": "tsc -p tsconfig.json",
43
47
  "sync-version": "node scripts/sync-version.mjs",
44
48
  "prepack": "npm run sync-version && npm run build",
45
- "test": "npm run sync-version && npm run build && node --test test/index.test.mjs test/local-function-integration.test.mjs",
49
+ "test": "npm run sync-version && npm run build && node --test test/index.test.mjs test/local-function-integration.test.mjs test/local-runtime.test.mjs",
46
50
  "test:integration": "npm run sync-version && npm run build && node --test test/integration.test.mjs",
47
51
  "test:integration:local-functions": "npm run sync-version && npm run build && node --test test/local-function-integration.test.mjs",
48
52
  "check:routes": "node scripts/check-routes.mjs"
@@ -51,6 +55,7 @@
51
55
  "node": ">=18"
52
56
  },
53
57
  "devDependencies": {
58
+ "@types/node": "^24.0.0",
54
59
  "typescript": "^5.0.0"
55
60
  }
56
61
  }