@granular-software/sdk 0.3.3 → 0.4.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.
@@ -5,15 +5,31 @@
5
5
  /**
6
6
  * Configuration for the Granular client
7
7
  */
8
+ type AccessTokenProvider = () => Promise<string | null | undefined> | string | null | undefined;
9
+ type EndpointMode = 'auto' | 'local' | 'production';
8
10
  interface GranularOptions {
9
11
  /** Your Granular API key (for service/CLI auth; use with GRANULAR_API_KEY) */
10
12
  apiKey?: string;
11
13
  /** Application/session JWT (for user-context auth; use from simulator or getAccessToken) */
12
14
  token?: string;
15
+ /** Optional provider used to refresh JWT before WebSocket (re)connect attempts */
16
+ tokenProvider?: AccessTokenProvider;
13
17
  /** Optional API URL (for on-prem or testing) */
14
18
  apiUrl?: string;
19
+ /** Optional endpoint mode when apiUrl is not explicitly provided */
20
+ endpointMode?: EndpointMode;
15
21
  /** Optional WebSocket constructor (for Node.js environments) */
16
22
  WebSocketCtor?: any;
23
+ /**
24
+ * Optional callback invoked when a connected WebSocket closes unexpectedly.
25
+ * Useful for forwarding close diagnostics to monitoring (e.g., Sentry).
26
+ */
27
+ onUnexpectedClose?: (info: WSDisconnectInfo) => void;
28
+ /**
29
+ * Optional callback invoked when automatic reconnect fails.
30
+ * Useful to capture auth or gateway rejection causes.
31
+ */
32
+ onReconnectError?: (info: WSReconnectErrorInfo) => void;
17
33
  }
18
34
  /** Resolved auth credential: either apiKey or token must be provided */
19
35
  type GranularAuth = string;
@@ -401,11 +417,28 @@ interface Prompt {
401
417
  options?: string[];
402
418
  defaultValue?: unknown;
403
419
  }
420
+ interface WSDisconnectInfo {
421
+ code?: number;
422
+ reason?: string;
423
+ wasClean?: boolean;
424
+ unexpected: boolean;
425
+ timestamp: number;
426
+ reconnectScheduled: boolean;
427
+ reconnectDelayMs?: number;
428
+ }
429
+ interface WSReconnectErrorInfo {
430
+ sessionId: string;
431
+ error: string;
432
+ timestamp: number;
433
+ }
404
434
  interface WSClientOptions {
405
435
  url: string;
406
436
  sessionId: string;
407
437
  token: string;
438
+ tokenProvider?: AccessTokenProvider;
408
439
  WebSocketCtor?: any;
440
+ onUnexpectedClose?: (info: WSDisconnectInfo) => void;
441
+ onReconnectError?: (info: WSReconnectErrorInfo) => void;
409
442
  }
410
443
  interface RPCRequest {
411
444
  type: 'rpc';
@@ -636,4 +669,4 @@ interface DeleteResponse {
636
669
  deleted: boolean;
637
670
  }
638
671
 
639
- export type { ManifestOperation as $, AssignmentListResponse as A, BuildPolicy as B, ConnectOptions as C, DomainState as D, EnvironmentData as E, BuildListResponse as F, GranularOptions as G, JobStatus as H, InstanceToolHandler as I, Job as J, JobSubmitResult as K, Prompt as L, ModelRef as M, RPCRequest as N, RPCResponse as O, PublishToolsResult as P, SyncMessage as Q, RecordUserOptions as R, SandboxListResponse as S, ToolWithHandler as T, User as U, RPCRequestFromServer as V, WSClientOptions as W, ToolInvokeParams as X, ToolResultParams as Y, ManifestPropertySpec as Z, ManifestRelationshipDef as _, ToolHandler as a, ManifestImport as a0, ManifestVolume as a1, APIError as a2, ToolInfo as b, ToolsChangedEvent as c, GraphQLResult as d, DefineRelationshipOptions as e, RelationshipInfo as f, ManifestContent as g, RecordObjectOptions as h, RecordObjectResult as i, Sandbox as j, CreateSandboxData as k, DeleteResponse as l, PermissionProfile as m, CreatePermissionProfileData as n, CreateEnvironmentData as o, Subject as p, ToolSchema as q, GranularAuth as r, PermissionRules as s, PermissionProfileListResponse as t, Assignment as u, EnvironmentListResponse as v, Manifest as w, ManifestListResponse as x, BuildStatus as y, Build as z };
672
+ export type { ToolInvokeParams as $, AssignmentListResponse as A, BuildPolicy as B, ConnectOptions as C, DomainState as D, EnvironmentData as E, BuildStatus as F, GranularOptions as G, Build as H, InstanceToolHandler as I, Job as J, BuildListResponse as K, JobStatus as L, ModelRef as M, JobSubmitResult as N, Prompt as O, PublishToolsResult as P, WSDisconnectInfo as Q, RecordUserOptions as R, SandboxListResponse as S, ToolWithHandler as T, User as U, WSReconnectErrorInfo as V, WSClientOptions as W, RPCRequest as X, RPCResponse as Y, SyncMessage as Z, RPCRequestFromServer as _, ToolHandler as a, ToolResultParams as a0, ManifestPropertySpec as a1, ManifestRelationshipDef as a2, ManifestOperation as a3, ManifestImport as a4, ManifestVolume as a5, APIError as a6, ToolInfo as b, ToolsChangedEvent as c, GraphQLResult as d, DefineRelationshipOptions as e, RelationshipInfo as f, ManifestContent as g, RecordObjectOptions as h, RecordObjectResult as i, Sandbox as j, CreateSandboxData as k, DeleteResponse as l, PermissionProfile as m, CreatePermissionProfileData as n, CreateEnvironmentData as o, Subject as p, ToolSchema as q, AccessTokenProvider as r, EndpointMode as s, GranularAuth as t, PermissionRules as u, PermissionProfileListResponse as v, Assignment as w, EnvironmentListResponse as x, Manifest as y, ManifestListResponse as z };
@@ -5,15 +5,31 @@
5
5
  /**
6
6
  * Configuration for the Granular client
7
7
  */
8
+ type AccessTokenProvider = () => Promise<string | null | undefined> | string | null | undefined;
9
+ type EndpointMode = 'auto' | 'local' | 'production';
8
10
  interface GranularOptions {
9
11
  /** Your Granular API key (for service/CLI auth; use with GRANULAR_API_KEY) */
10
12
  apiKey?: string;
11
13
  /** Application/session JWT (for user-context auth; use from simulator or getAccessToken) */
12
14
  token?: string;
15
+ /** Optional provider used to refresh JWT before WebSocket (re)connect attempts */
16
+ tokenProvider?: AccessTokenProvider;
13
17
  /** Optional API URL (for on-prem or testing) */
14
18
  apiUrl?: string;
19
+ /** Optional endpoint mode when apiUrl is not explicitly provided */
20
+ endpointMode?: EndpointMode;
15
21
  /** Optional WebSocket constructor (for Node.js environments) */
16
22
  WebSocketCtor?: any;
23
+ /**
24
+ * Optional callback invoked when a connected WebSocket closes unexpectedly.
25
+ * Useful for forwarding close diagnostics to monitoring (e.g., Sentry).
26
+ */
27
+ onUnexpectedClose?: (info: WSDisconnectInfo) => void;
28
+ /**
29
+ * Optional callback invoked when automatic reconnect fails.
30
+ * Useful to capture auth or gateway rejection causes.
31
+ */
32
+ onReconnectError?: (info: WSReconnectErrorInfo) => void;
17
33
  }
18
34
  /** Resolved auth credential: either apiKey or token must be provided */
19
35
  type GranularAuth = string;
@@ -401,11 +417,28 @@ interface Prompt {
401
417
  options?: string[];
402
418
  defaultValue?: unknown;
403
419
  }
420
+ interface WSDisconnectInfo {
421
+ code?: number;
422
+ reason?: string;
423
+ wasClean?: boolean;
424
+ unexpected: boolean;
425
+ timestamp: number;
426
+ reconnectScheduled: boolean;
427
+ reconnectDelayMs?: number;
428
+ }
429
+ interface WSReconnectErrorInfo {
430
+ sessionId: string;
431
+ error: string;
432
+ timestamp: number;
433
+ }
404
434
  interface WSClientOptions {
405
435
  url: string;
406
436
  sessionId: string;
407
437
  token: string;
438
+ tokenProvider?: AccessTokenProvider;
408
439
  WebSocketCtor?: any;
440
+ onUnexpectedClose?: (info: WSDisconnectInfo) => void;
441
+ onReconnectError?: (info: WSReconnectErrorInfo) => void;
409
442
  }
410
443
  interface RPCRequest {
411
444
  type: 'rpc';
@@ -636,4 +669,4 @@ interface DeleteResponse {
636
669
  deleted: boolean;
637
670
  }
638
671
 
639
- export type { ManifestOperation as $, AssignmentListResponse as A, BuildPolicy as B, ConnectOptions as C, DomainState as D, EnvironmentData as E, BuildListResponse as F, GranularOptions as G, JobStatus as H, InstanceToolHandler as I, Job as J, JobSubmitResult as K, Prompt as L, ModelRef as M, RPCRequest as N, RPCResponse as O, PublishToolsResult as P, SyncMessage as Q, RecordUserOptions as R, SandboxListResponse as S, ToolWithHandler as T, User as U, RPCRequestFromServer as V, WSClientOptions as W, ToolInvokeParams as X, ToolResultParams as Y, ManifestPropertySpec as Z, ManifestRelationshipDef as _, ToolHandler as a, ManifestImport as a0, ManifestVolume as a1, APIError as a2, ToolInfo as b, ToolsChangedEvent as c, GraphQLResult as d, DefineRelationshipOptions as e, RelationshipInfo as f, ManifestContent as g, RecordObjectOptions as h, RecordObjectResult as i, Sandbox as j, CreateSandboxData as k, DeleteResponse as l, PermissionProfile as m, CreatePermissionProfileData as n, CreateEnvironmentData as o, Subject as p, ToolSchema as q, GranularAuth as r, PermissionRules as s, PermissionProfileListResponse as t, Assignment as u, EnvironmentListResponse as v, Manifest as w, ManifestListResponse as x, BuildStatus as y, Build as z };
672
+ export type { ToolInvokeParams as $, AssignmentListResponse as A, BuildPolicy as B, ConnectOptions as C, DomainState as D, EnvironmentData as E, BuildStatus as F, GranularOptions as G, Build as H, InstanceToolHandler as I, Job as J, BuildListResponse as K, JobStatus as L, ModelRef as M, JobSubmitResult as N, Prompt as O, PublishToolsResult as P, WSDisconnectInfo as Q, RecordUserOptions as R, SandboxListResponse as S, ToolWithHandler as T, User as U, WSReconnectErrorInfo as V, WSClientOptions as W, RPCRequest as X, RPCResponse as Y, SyncMessage as Z, RPCRequestFromServer as _, ToolHandler as a, ToolResultParams as a0, ManifestPropertySpec as a1, ManifestRelationshipDef as a2, ManifestOperation as a3, ManifestImport as a4, ManifestVolume as a5, APIError as a6, ToolInfo as b, ToolsChangedEvent as c, GraphQLResult as d, DefineRelationshipOptions as e, RelationshipInfo as f, ManifestContent as g, RecordObjectOptions as h, RecordObjectResult as i, Sandbox as j, CreateSandboxData as k, DeleteResponse as l, PermissionProfile as m, CreatePermissionProfileData as n, CreateEnvironmentData as o, Subject as p, ToolSchema as q, AccessTokenProvider as r, EndpointMode as s, GranularAuth as t, PermissionRules as u, PermissionProfileListResponse as v, Assignment as w, EnvironmentListResponse as x, Manifest as y, ManifestListResponse as z };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@granular-software/sdk",
3
- "version": "0.3.3",
3
+ "version": "0.4.1",
4
4
  "description": "TypeScript SDK and CLI for Granular - define, build, and deploy AI sandboxes",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",