@granular-software/sdk 0.4.4 → 0.4.5
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 +1 -1
- package/dist/cli/index.js +14 -7
- package/dist/index.d.mts +54 -1
- package/dist/index.d.ts +54 -1
- package/dist/index.js +33 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +33 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -33,7 +33,7 @@ Inside this monorepo, prefer the workspace package instead of installing from np
|
|
|
33
33
|
By default, the SDK resolves endpoints like this:
|
|
34
34
|
|
|
35
35
|
- Local mode (`NODE_ENV=development`): `ws://localhost:8787/granular`
|
|
36
|
-
- Production mode (default): `wss://api.
|
|
36
|
+
- Production mode (default): `wss://cf-api-gateway.arthur6084.workers.dev/granular`
|
|
37
37
|
|
|
38
38
|
Overrides:
|
|
39
39
|
|
package/dist/cli/index.js
CHANGED
|
@@ -5387,7 +5387,7 @@ var import_dotenv = __toESM(require_main());
|
|
|
5387
5387
|
|
|
5388
5388
|
// src/endpoints.ts
|
|
5389
5389
|
var LOCAL_API_URL = "ws://localhost:8787/granular";
|
|
5390
|
-
var PRODUCTION_API_URL = "wss://api.
|
|
5390
|
+
var PRODUCTION_API_URL = "wss://cf-api-gateway.arthur6084.workers.dev/granular";
|
|
5391
5391
|
var LOCAL_AUTH_URL = "http://localhost:3000";
|
|
5392
5392
|
var PRODUCTION_AUTH_URL = "https://app.granular.software";
|
|
5393
5393
|
function readEnv(name) {
|
|
@@ -5775,6 +5775,9 @@ var ApiClient = class {
|
|
|
5775
5775
|
return false;
|
|
5776
5776
|
}
|
|
5777
5777
|
}
|
|
5778
|
+
async validateKeyOrThrow() {
|
|
5779
|
+
await this.request("/control/sandboxes");
|
|
5780
|
+
}
|
|
5778
5781
|
// ── Sandboxes ──
|
|
5779
5782
|
async listSandboxes() {
|
|
5780
5783
|
const result = await this.request("/control/sandboxes");
|
|
@@ -7847,9 +7850,11 @@ async function initCommand(projectName, options) {
|
|
|
7847
7850
|
const apiUrl = loadApiUrl();
|
|
7848
7851
|
const api = new ApiClient(apiKey, apiUrl);
|
|
7849
7852
|
const validating = spinner("Validating API key...");
|
|
7850
|
-
|
|
7851
|
-
|
|
7852
|
-
|
|
7853
|
+
try {
|
|
7854
|
+
await api.validateKeyOrThrow();
|
|
7855
|
+
} catch (err) {
|
|
7856
|
+
const detail = err?.message ? ` (${err.message})` : "";
|
|
7857
|
+
validating.fail(` API key validation failed${detail}.`);
|
|
7853
7858
|
process.exit(1);
|
|
7854
7859
|
}
|
|
7855
7860
|
validating.succeed(" API key validated.");
|
|
@@ -8015,9 +8020,11 @@ async function loginCommand(options = {}) {
|
|
|
8015
8020
|
}
|
|
8016
8021
|
const spinner2 = spinner("Validating...");
|
|
8017
8022
|
const api = new ApiClient(apiKey, apiUrl);
|
|
8018
|
-
|
|
8019
|
-
|
|
8020
|
-
|
|
8023
|
+
try {
|
|
8024
|
+
await api.validateKeyOrThrow();
|
|
8025
|
+
} catch (err) {
|
|
8026
|
+
const detail = err?.message ? ` (${err.message})` : "";
|
|
8027
|
+
spinner2.fail(` API key validation failed${detail}.`);
|
|
8021
8028
|
process.exit(1);
|
|
8022
8029
|
}
|
|
8023
8030
|
saveApiKey(apiKey);
|
package/dist/index.d.mts
CHANGED
|
@@ -88,6 +88,11 @@ interface ConnectOptions {
|
|
|
88
88
|
/** Optional stable client ID. Defaults to `client_${Date.now()}`. Use a fixed
|
|
89
89
|
* value for long-lived effect hosts so tool catalogs don't accumulate. */
|
|
90
90
|
clientId?: string;
|
|
91
|
+
/** Optional session heap seed. Each item is eagerly hydrated into the session heap on connect. */
|
|
92
|
+
initialHeap?: Array<{
|
|
93
|
+
className: string;
|
|
94
|
+
id: string;
|
|
95
|
+
}>;
|
|
91
96
|
}
|
|
92
97
|
/**
|
|
93
98
|
* A sandbox container
|
|
@@ -454,6 +459,47 @@ interface Prompt {
|
|
|
454
459
|
options?: string[];
|
|
455
460
|
defaultValue?: unknown;
|
|
456
461
|
}
|
|
462
|
+
type SessionHeapFieldType = 'string' | 'number' | 'boolean' | 'null' | 'unknown';
|
|
463
|
+
interface SessionHeapFieldValue {
|
|
464
|
+
name: string;
|
|
465
|
+
type: SessionHeapFieldType;
|
|
466
|
+
value: string | number | boolean | null;
|
|
467
|
+
}
|
|
468
|
+
interface SessionHeapEntry {
|
|
469
|
+
path: string;
|
|
470
|
+
className: string;
|
|
471
|
+
id: string;
|
|
472
|
+
label?: string | null;
|
|
473
|
+
description?: string | null;
|
|
474
|
+
prototypes: string[];
|
|
475
|
+
fields: SessionHeapFieldValue[];
|
|
476
|
+
relatedJobIds: string[];
|
|
477
|
+
source: string;
|
|
478
|
+
createdAt: number;
|
|
479
|
+
updatedAt: number;
|
|
480
|
+
}
|
|
481
|
+
interface SessionHeapList {
|
|
482
|
+
name: string;
|
|
483
|
+
className: string;
|
|
484
|
+
paths: string[];
|
|
485
|
+
relatedJobIds: string[];
|
|
486
|
+
updatedAt: number;
|
|
487
|
+
}
|
|
488
|
+
interface SessionHeapVariable {
|
|
489
|
+
name: string;
|
|
490
|
+
kind: 'entry' | 'list' | 'scalar';
|
|
491
|
+
entryPath?: string;
|
|
492
|
+
listName?: string;
|
|
493
|
+
value?: string | number | boolean | null;
|
|
494
|
+
className?: string;
|
|
495
|
+
updatedAt: number;
|
|
496
|
+
}
|
|
497
|
+
interface SessionHeapSnapshot {
|
|
498
|
+
entriesByPath: Record<string, SessionHeapEntry>;
|
|
499
|
+
listsByName: Record<string, SessionHeapList>;
|
|
500
|
+
variablesByName: Record<string, SessionHeapVariable>;
|
|
501
|
+
updatedAt: number;
|
|
502
|
+
}
|
|
457
503
|
interface WSDisconnectInfo {
|
|
458
504
|
code?: number;
|
|
459
505
|
reason?: string;
|
|
@@ -974,6 +1020,13 @@ declare class Environment extends Session {
|
|
|
974
1020
|
get permissionProfileId(): string;
|
|
975
1021
|
/** The GraphQL API endpoint URL */
|
|
976
1022
|
get apiEndpoint(): string;
|
|
1023
|
+
/**
|
|
1024
|
+
* Return a plain JS snapshot of the synced session heap.
|
|
1025
|
+
*
|
|
1026
|
+
* The heap lives in the Automerge document, so this method does not perform
|
|
1027
|
+
* any extra network roundtrip.
|
|
1028
|
+
*/
|
|
1029
|
+
getHeap(): SessionHeapSnapshot;
|
|
977
1030
|
private getRuntimeBaseUrl;
|
|
978
1031
|
/**
|
|
979
1032
|
* Close the session and disconnect from the sandbox.
|
|
@@ -1427,4 +1480,4 @@ declare class Granular {
|
|
|
1427
1480
|
private request;
|
|
1428
1481
|
}
|
|
1429
1482
|
|
|
1430
|
-
export { type APIError, type AccessTokenProvider, type Assignment, type AssignmentListResponse, type Build, type BuildListResponse, type BuildPolicy, type BuildStatus, type ConnectOptions, type CreateEnvironmentData, type CreatePermissionProfileData, type CreateSandboxData, type DefineRelationshipOptions, type DeleteResponse, type DomainState, type EffectHandler, type EffectHandlerContext, type EffectInfo, type EffectSchema, type EffectWithHandler, type EffectsChangedEvent, type EndpointMode, Environment, type EnvironmentData, type EnvironmentListResponse, Granular, type GranularAuth, type GranularOptions, type GraphQLResult, type InstanceEffectHandler, type InstanceToolHandler, type Job, type JobStatus, type JobSubmitResult, type Manifest, type ManifestContent, type ManifestEffectDeclaration, type ManifestEffectSchema, type ManifestImport, type ManifestListResponse, type ManifestOperation, type ManifestPropertySpec, type ManifestRelationshipDef, type ManifestVolume, type ModelRef, type PermissionProfile, type PermissionProfileListResponse, type PermissionRules, type Prompt, type PublishEffectsResult, type PublishToolsResult, type RPCRequest, type RPCRequestFromServer, type RPCResponse, type RecordObjectOptions, type RecordObjectResult, type RecordUserOptions, type RelationshipInfo, type Sandbox, type SandboxListResponse, Session, type Subject, type SyncMessage, type ToolHandler, type ToolInfo, type ToolInvokeParams, type ToolResultParams, type ToolSchema, type ToolWithHandler, type ToolsChangedEvent, type User, WSClient, type WSClientOptions, type WSDisconnectInfo, type WSReconnectErrorInfo };
|
|
1483
|
+
export { type APIError, type AccessTokenProvider, type Assignment, type AssignmentListResponse, type Build, type BuildListResponse, type BuildPolicy, type BuildStatus, type ConnectOptions, type CreateEnvironmentData, type CreatePermissionProfileData, type CreateSandboxData, type DefineRelationshipOptions, type DeleteResponse, type DomainState, type EffectHandler, type EffectHandlerContext, type EffectInfo, type EffectSchema, type EffectWithHandler, type EffectsChangedEvent, type EndpointMode, Environment, type EnvironmentData, type EnvironmentListResponse, Granular, type GranularAuth, type GranularOptions, type GraphQLResult, type InstanceEffectHandler, type InstanceToolHandler, type Job, type JobStatus, type JobSubmitResult, type Manifest, type ManifestContent, type ManifestEffectDeclaration, type ManifestEffectSchema, type ManifestImport, type ManifestListResponse, type ManifestOperation, type ManifestPropertySpec, type ManifestRelationshipDef, type ManifestVolume, type ModelRef, type PermissionProfile, type PermissionProfileListResponse, type PermissionRules, type Prompt, type PublishEffectsResult, type PublishToolsResult, type RPCRequest, type RPCRequestFromServer, type RPCResponse, type RecordObjectOptions, type RecordObjectResult, type RecordUserOptions, type RelationshipInfo, type Sandbox, type SandboxListResponse, Session, type SessionHeapEntry, type SessionHeapFieldType, type SessionHeapFieldValue, type SessionHeapList, type SessionHeapSnapshot, type SessionHeapVariable, type Subject, type SyncMessage, type ToolHandler, type ToolInfo, type ToolInvokeParams, type ToolResultParams, type ToolSchema, type ToolWithHandler, type ToolsChangedEvent, type User, WSClient, type WSClientOptions, type WSDisconnectInfo, type WSReconnectErrorInfo };
|
package/dist/index.d.ts
CHANGED
|
@@ -88,6 +88,11 @@ interface ConnectOptions {
|
|
|
88
88
|
/** Optional stable client ID. Defaults to `client_${Date.now()}`. Use a fixed
|
|
89
89
|
* value for long-lived effect hosts so tool catalogs don't accumulate. */
|
|
90
90
|
clientId?: string;
|
|
91
|
+
/** Optional session heap seed. Each item is eagerly hydrated into the session heap on connect. */
|
|
92
|
+
initialHeap?: Array<{
|
|
93
|
+
className: string;
|
|
94
|
+
id: string;
|
|
95
|
+
}>;
|
|
91
96
|
}
|
|
92
97
|
/**
|
|
93
98
|
* A sandbox container
|
|
@@ -454,6 +459,47 @@ interface Prompt {
|
|
|
454
459
|
options?: string[];
|
|
455
460
|
defaultValue?: unknown;
|
|
456
461
|
}
|
|
462
|
+
type SessionHeapFieldType = 'string' | 'number' | 'boolean' | 'null' | 'unknown';
|
|
463
|
+
interface SessionHeapFieldValue {
|
|
464
|
+
name: string;
|
|
465
|
+
type: SessionHeapFieldType;
|
|
466
|
+
value: string | number | boolean | null;
|
|
467
|
+
}
|
|
468
|
+
interface SessionHeapEntry {
|
|
469
|
+
path: string;
|
|
470
|
+
className: string;
|
|
471
|
+
id: string;
|
|
472
|
+
label?: string | null;
|
|
473
|
+
description?: string | null;
|
|
474
|
+
prototypes: string[];
|
|
475
|
+
fields: SessionHeapFieldValue[];
|
|
476
|
+
relatedJobIds: string[];
|
|
477
|
+
source: string;
|
|
478
|
+
createdAt: number;
|
|
479
|
+
updatedAt: number;
|
|
480
|
+
}
|
|
481
|
+
interface SessionHeapList {
|
|
482
|
+
name: string;
|
|
483
|
+
className: string;
|
|
484
|
+
paths: string[];
|
|
485
|
+
relatedJobIds: string[];
|
|
486
|
+
updatedAt: number;
|
|
487
|
+
}
|
|
488
|
+
interface SessionHeapVariable {
|
|
489
|
+
name: string;
|
|
490
|
+
kind: 'entry' | 'list' | 'scalar';
|
|
491
|
+
entryPath?: string;
|
|
492
|
+
listName?: string;
|
|
493
|
+
value?: string | number | boolean | null;
|
|
494
|
+
className?: string;
|
|
495
|
+
updatedAt: number;
|
|
496
|
+
}
|
|
497
|
+
interface SessionHeapSnapshot {
|
|
498
|
+
entriesByPath: Record<string, SessionHeapEntry>;
|
|
499
|
+
listsByName: Record<string, SessionHeapList>;
|
|
500
|
+
variablesByName: Record<string, SessionHeapVariable>;
|
|
501
|
+
updatedAt: number;
|
|
502
|
+
}
|
|
457
503
|
interface WSDisconnectInfo {
|
|
458
504
|
code?: number;
|
|
459
505
|
reason?: string;
|
|
@@ -974,6 +1020,13 @@ declare class Environment extends Session {
|
|
|
974
1020
|
get permissionProfileId(): string;
|
|
975
1021
|
/** The GraphQL API endpoint URL */
|
|
976
1022
|
get apiEndpoint(): string;
|
|
1023
|
+
/**
|
|
1024
|
+
* Return a plain JS snapshot of the synced session heap.
|
|
1025
|
+
*
|
|
1026
|
+
* The heap lives in the Automerge document, so this method does not perform
|
|
1027
|
+
* any extra network roundtrip.
|
|
1028
|
+
*/
|
|
1029
|
+
getHeap(): SessionHeapSnapshot;
|
|
977
1030
|
private getRuntimeBaseUrl;
|
|
978
1031
|
/**
|
|
979
1032
|
* Close the session and disconnect from the sandbox.
|
|
@@ -1427,4 +1480,4 @@ declare class Granular {
|
|
|
1427
1480
|
private request;
|
|
1428
1481
|
}
|
|
1429
1482
|
|
|
1430
|
-
export { type APIError, type AccessTokenProvider, type Assignment, type AssignmentListResponse, type Build, type BuildListResponse, type BuildPolicy, type BuildStatus, type ConnectOptions, type CreateEnvironmentData, type CreatePermissionProfileData, type CreateSandboxData, type DefineRelationshipOptions, type DeleteResponse, type DomainState, type EffectHandler, type EffectHandlerContext, type EffectInfo, type EffectSchema, type EffectWithHandler, type EffectsChangedEvent, type EndpointMode, Environment, type EnvironmentData, type EnvironmentListResponse, Granular, type GranularAuth, type GranularOptions, type GraphQLResult, type InstanceEffectHandler, type InstanceToolHandler, type Job, type JobStatus, type JobSubmitResult, type Manifest, type ManifestContent, type ManifestEffectDeclaration, type ManifestEffectSchema, type ManifestImport, type ManifestListResponse, type ManifestOperation, type ManifestPropertySpec, type ManifestRelationshipDef, type ManifestVolume, type ModelRef, type PermissionProfile, type PermissionProfileListResponse, type PermissionRules, type Prompt, type PublishEffectsResult, type PublishToolsResult, type RPCRequest, type RPCRequestFromServer, type RPCResponse, type RecordObjectOptions, type RecordObjectResult, type RecordUserOptions, type RelationshipInfo, type Sandbox, type SandboxListResponse, Session, type Subject, type SyncMessage, type ToolHandler, type ToolInfo, type ToolInvokeParams, type ToolResultParams, type ToolSchema, type ToolWithHandler, type ToolsChangedEvent, type User, WSClient, type WSClientOptions, type WSDisconnectInfo, type WSReconnectErrorInfo };
|
|
1483
|
+
export { type APIError, type AccessTokenProvider, type Assignment, type AssignmentListResponse, type Build, type BuildListResponse, type BuildPolicy, type BuildStatus, type ConnectOptions, type CreateEnvironmentData, type CreatePermissionProfileData, type CreateSandboxData, type DefineRelationshipOptions, type DeleteResponse, type DomainState, type EffectHandler, type EffectHandlerContext, type EffectInfo, type EffectSchema, type EffectWithHandler, type EffectsChangedEvent, type EndpointMode, Environment, type EnvironmentData, type EnvironmentListResponse, Granular, type GranularAuth, type GranularOptions, type GraphQLResult, type InstanceEffectHandler, type InstanceToolHandler, type Job, type JobStatus, type JobSubmitResult, type Manifest, type ManifestContent, type ManifestEffectDeclaration, type ManifestEffectSchema, type ManifestImport, type ManifestListResponse, type ManifestOperation, type ManifestPropertySpec, type ManifestRelationshipDef, type ManifestVolume, type ModelRef, type PermissionProfile, type PermissionProfileListResponse, type PermissionRules, type Prompt, type PublishEffectsResult, type PublishToolsResult, type RPCRequest, type RPCRequestFromServer, type RPCResponse, type RecordObjectOptions, type RecordObjectResult, type RecordUserOptions, type RelationshipInfo, type Sandbox, type SandboxListResponse, Session, type SessionHeapEntry, type SessionHeapFieldType, type SessionHeapFieldValue, type SessionHeapList, type SessionHeapSnapshot, type SessionHeapVariable, type Subject, type SyncMessage, type ToolHandler, type ToolInfo, type ToolInvokeParams, type ToolResultParams, type ToolSchema, type ToolWithHandler, type ToolsChangedEvent, type User, WSClient, type WSClientOptions, type WSDisconnectInfo, type WSReconnectErrorInfo };
|
package/dist/index.js
CHANGED
|
@@ -5089,7 +5089,7 @@ var JobImplementation = class {
|
|
|
5089
5089
|
|
|
5090
5090
|
// src/endpoints.ts
|
|
5091
5091
|
var LOCAL_API_URL = "ws://localhost:8787/granular";
|
|
5092
|
-
var PRODUCTION_API_URL = "wss://api.
|
|
5092
|
+
var PRODUCTION_API_URL = "wss://cf-api-gateway.arthur6084.workers.dev/granular";
|
|
5093
5093
|
function readEnv(name) {
|
|
5094
5094
|
if (typeof process === "undefined" || !process.env) return void 0;
|
|
5095
5095
|
return process.env[name];
|
|
@@ -5176,6 +5176,26 @@ function buildEffectHostUrl(apiUrl, sandboxId, effectClientId, clientId) {
|
|
|
5176
5176
|
url.searchParams.set("clientId", clientId);
|
|
5177
5177
|
return url.toString();
|
|
5178
5178
|
}
|
|
5179
|
+
function createEmptyHeapSnapshot(now = Date.now()) {
|
|
5180
|
+
return {
|
|
5181
|
+
entriesByPath: {},
|
|
5182
|
+
listsByName: {},
|
|
5183
|
+
variablesByName: {},
|
|
5184
|
+
updatedAt: now
|
|
5185
|
+
};
|
|
5186
|
+
}
|
|
5187
|
+
function normalizeHeapSnapshot(raw) {
|
|
5188
|
+
if (!raw || typeof raw !== "object") {
|
|
5189
|
+
return createEmptyHeapSnapshot();
|
|
5190
|
+
}
|
|
5191
|
+
const heap = raw;
|
|
5192
|
+
return {
|
|
5193
|
+
entriesByPath: heap.entriesByPath && typeof heap.entriesByPath === "object" ? JSON.parse(JSON.stringify(heap.entriesByPath)) : {},
|
|
5194
|
+
listsByName: heap.listsByName && typeof heap.listsByName === "object" ? JSON.parse(JSON.stringify(heap.listsByName)) : {},
|
|
5195
|
+
variablesByName: heap.variablesByName && typeof heap.variablesByName === "object" ? JSON.parse(JSON.stringify(heap.variablesByName)) : {},
|
|
5196
|
+
updatedAt: typeof heap.updatedAt === "number" ? heap.updatedAt : Date.now()
|
|
5197
|
+
};
|
|
5198
|
+
}
|
|
5179
5199
|
var Environment = class _Environment extends Session {
|
|
5180
5200
|
envData;
|
|
5181
5201
|
_apiKey;
|
|
@@ -5206,6 +5226,16 @@ var Environment = class _Environment extends Session {
|
|
|
5206
5226
|
get apiEndpoint() {
|
|
5207
5227
|
return this._apiEndpoint;
|
|
5208
5228
|
}
|
|
5229
|
+
/**
|
|
5230
|
+
* Return a plain JS snapshot of the synced session heap.
|
|
5231
|
+
*
|
|
5232
|
+
* The heap lives in the Automerge document, so this method does not perform
|
|
5233
|
+
* any extra network roundtrip.
|
|
5234
|
+
*/
|
|
5235
|
+
getHeap() {
|
|
5236
|
+
const doc = this.document;
|
|
5237
|
+
return normalizeHeapSnapshot(doc?.heap);
|
|
5238
|
+
}
|
|
5209
5239
|
getRuntimeBaseUrl() {
|
|
5210
5240
|
try {
|
|
5211
5241
|
const endpoint = new URL(this._apiEndpoint);
|
|
@@ -6067,7 +6097,8 @@ var Granular = class {
|
|
|
6067
6097
|
method: "POST",
|
|
6068
6098
|
body: JSON.stringify({
|
|
6069
6099
|
environmentId: envData.environmentId,
|
|
6070
|
-
clientId
|
|
6100
|
+
clientId,
|
|
6101
|
+
initialHeap: options.initialHeap
|
|
6071
6102
|
})
|
|
6072
6103
|
});
|
|
6073
6104
|
const client = new WSClient({
|