@granular-software/sdk 0.4.1 → 0.4.2
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 +17 -14
- package/dist/adapters/anthropic.d.mts +1 -1
- package/dist/adapters/anthropic.d.ts +1 -1
- package/dist/adapters/langchain.d.mts +1 -1
- package/dist/adapters/langchain.d.ts +1 -1
- package/dist/adapters/mastra.d.mts +1 -1
- package/dist/adapters/mastra.d.ts +1 -1
- package/dist/adapters/openai.d.mts +1 -1
- package/dist/adapters/openai.d.ts +1 -1
- package/dist/cli/index.js +123 -39
- package/dist/index.d.mts +51 -162
- package/dist/index.d.ts +51 -162
- package/dist/index.js +304 -264
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +304 -264
- package/dist/index.mjs.map +1 -1
- package/dist/{types-BOPsFZYi.d.mts → types-C0AVRsVR.d.mts} +85 -31
- package/dist/{types-BOPsFZYi.d.ts → types-C0AVRsVR.d.ts} +85 -31
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as Automerge from '@automerge/automerge';
|
|
2
|
-
import { W as WSClientOptions, T as ToolWithHandler, P as PublishToolsResult, J as Job, a as ToolHandler, I as InstanceToolHandler, b as ToolInfo, c as ToolsChangedEvent, D as DomainState, G as GranularOptions, R as RecordUserOptions, U as User, C as ConnectOptions,
|
|
3
|
-
export {
|
|
2
|
+
import { W as WSClientOptions, T as ToolWithHandler, P as PublishToolsResult, J as Job, a as ToolHandler, I as InstanceToolHandler, E as EffectInfo, b as ToolInfo, c as EffectsChangedEvent, d as ToolsChangedEvent, D as DomainState, G as GranularOptions, R as RecordUserOptions, U as User, C as ConnectOptions, e as EnvironmentData, f as GraphQLResult, g as DefineRelationshipOptions, h as RelationshipInfo, M as ModelRef, i as ManifestContent, j as RecordObjectOptions, k as RecordObjectResult, S as SandboxListResponse, l as Sandbox, m as CreateSandboxData, n as DeleteResponse, o as PermissionProfile, p as CreatePermissionProfileData, q as CreateEnvironmentData, r as Subject, A as AssignmentListResponse } from './types-C0AVRsVR.mjs';
|
|
3
|
+
export { ag as APIError, t as AccessTokenProvider, y as Assignment, L as Build, N as BuildListResponse, B as BuildPolicy, K as BuildStatus, Y as EffectHandler, O as EffectHandlerContext, Q as EffectSchema, V as EffectWithHandler, u as EndpointMode, z as EnvironmentListResponse, v as GranularAuth, Z as InstanceEffectHandler, _ as JobStatus, $ as JobSubmitResult, F as Manifest, ac as ManifestEffectDeclaration, ab as ManifestEffectSchema, ae as ManifestImport, H as ManifestListResponse, ad as ManifestOperation, a9 as ManifestPropertySpec, aa as ManifestRelationshipDef, af as ManifestVolume, x as PermissionProfileListResponse, w as PermissionRules, a0 as Prompt, X as PublishEffectsResult, a3 as RPCRequest, a6 as RPCRequestFromServer, a4 as RPCResponse, a5 as SyncMessage, a7 as ToolInvokeParams, a8 as ToolResultParams, s as ToolSchema, a1 as WSDisconnectInfo, a2 as WSReconnectErrorInfo } from './types-C0AVRsVR.mjs';
|
|
4
4
|
import { Doc } from '@automerge/automerge/slim';
|
|
5
5
|
|
|
6
6
|
declare class WSClient {
|
|
@@ -89,6 +89,7 @@ declare class Session {
|
|
|
89
89
|
/** Last known tools for diffing */
|
|
90
90
|
private lastKnownTools;
|
|
91
91
|
constructor(client: WSClient, clientId?: string);
|
|
92
|
+
private buildLegacyEffectContext;
|
|
92
93
|
get document(): Doc<Record<string, unknown>>;
|
|
93
94
|
get domainRevision(): string | null;
|
|
94
95
|
/**
|
|
@@ -122,101 +123,11 @@ declare class Session {
|
|
|
122
123
|
status: 'warming' | 'hot' | 'unknown';
|
|
123
124
|
};
|
|
124
125
|
}>;
|
|
125
|
-
/**
|
|
126
|
-
* Publish tools to the sandbox and register handlers for reverse-RPC.
|
|
127
|
-
*
|
|
128
|
-
* Tools can be:
|
|
129
|
-
* - **Instance methods**: set `className` (handler receives `(objectId, params)`)
|
|
130
|
-
* - **Static methods**: set `className` + `static: true` (handler receives `(params)`)
|
|
131
|
-
* - **Global tools**: omit `className` (handler receives `(params)`)
|
|
132
|
-
*
|
|
133
|
-
* Both `inputSchema` and `outputSchema` accept JSON Schema objects. The
|
|
134
|
-
* `outputSchema` drives the return type in the auto-generated TypeScript
|
|
135
|
-
* class declarations that sandbox code imports from `./sandbox-tools`.
|
|
136
|
-
*
|
|
137
|
-
* This method:
|
|
138
|
-
* 1. Extracts tool schemas (including `outputSchema`) from the provided tools
|
|
139
|
-
* 2. Publishes them via `client.publishRawToolCatalog` RPC
|
|
140
|
-
* 3. Registers handlers locally for `tool.invoke` RPC calls
|
|
141
|
-
* 4. Returns the `domainRevision` needed for job submission
|
|
142
|
-
*
|
|
143
|
-
* @param tools - Array of tools with handlers
|
|
144
|
-
* @param revision - Optional revision string (default: "1.0.0")
|
|
145
|
-
* @returns PublishToolsResult with domainRevision
|
|
146
|
-
*
|
|
147
|
-
* @example
|
|
148
|
-
* ```typescript
|
|
149
|
-
* await env.publishTools([
|
|
150
|
-
* {
|
|
151
|
-
* name: 'get_bio',
|
|
152
|
-
* description: 'Get biography of an author',
|
|
153
|
-
* className: 'author',
|
|
154
|
-
* inputSchema: { type: 'object', properties: { detailed: { type: 'boolean' } } },
|
|
155
|
-
* outputSchema: { type: 'object', properties: { bio: { type: 'string' } }, required: ['bio'] },
|
|
156
|
-
* handler: async (id, params) => ({ bio: `Bio of ${id}` }),
|
|
157
|
-
* },
|
|
158
|
-
* ]);
|
|
159
|
-
* ```
|
|
160
|
-
*/
|
|
161
126
|
publishTools(tools: ToolWithHandler[], revision?: string): Promise<PublishToolsResult>;
|
|
162
|
-
/**
|
|
163
|
-
* Publish a single effect (tool) to the sandbox.
|
|
164
|
-
*
|
|
165
|
-
* Adds the effect to the local registry and re-publishes the
|
|
166
|
-
* full tool catalog to the server. If an effect with the same
|
|
167
|
-
* name already exists, it is replaced.
|
|
168
|
-
*
|
|
169
|
-
* @param effect - The effect (tool) to publish
|
|
170
|
-
* @returns PublishToolsResult with domainRevision
|
|
171
|
-
*
|
|
172
|
-
* @example
|
|
173
|
-
* ```typescript
|
|
174
|
-
* await env.publishEffect({
|
|
175
|
-
* name: 'get_bio',
|
|
176
|
-
* description: 'Get biography of an author',
|
|
177
|
-
* className: 'author',
|
|
178
|
-
* inputSchema: { type: 'object', properties: { detailed: { type: 'boolean' } } },
|
|
179
|
-
* handler: async (id, params) => ({ bio: `Bio of ${id}` }),
|
|
180
|
-
* });
|
|
181
|
-
* ```
|
|
182
|
-
*/
|
|
183
127
|
publishEffect(effect: ToolWithHandler): Promise<PublishToolsResult>;
|
|
184
|
-
/**
|
|
185
|
-
* Publish multiple effects (tools) at once.
|
|
186
|
-
*
|
|
187
|
-
* Adds all effects to the local registry and re-publishes the
|
|
188
|
-
* full tool catalog in a single RPC call.
|
|
189
|
-
*
|
|
190
|
-
* @param effects - Array of effects to publish
|
|
191
|
-
* @returns PublishToolsResult with domainRevision
|
|
192
|
-
*
|
|
193
|
-
* @example
|
|
194
|
-
* ```typescript
|
|
195
|
-
* await env.publishEffects([
|
|
196
|
-
* { name: 'get_bio', description: '...', inputSchema: {}, handler: async (id) => ({}) },
|
|
197
|
-
* { name: 'search', description: '...', inputSchema: {}, handler: async (params) => ({}) },
|
|
198
|
-
* ]);
|
|
199
|
-
* ```
|
|
200
|
-
*/
|
|
201
128
|
publishEffects(effects: ToolWithHandler[]): Promise<PublishToolsResult>;
|
|
202
|
-
/**
|
|
203
|
-
* Remove an effect by name and re-publish the remaining catalog.
|
|
204
|
-
*
|
|
205
|
-
* @param name - The name of the effect to remove
|
|
206
|
-
* @returns PublishToolsResult with domainRevision
|
|
207
|
-
*/
|
|
208
129
|
unpublishEffect(name: string): Promise<PublishToolsResult>;
|
|
209
|
-
/**
|
|
210
|
-
* Remove all effects and publish an empty catalog.
|
|
211
|
-
*
|
|
212
|
-
* @returns PublishToolsResult with domainRevision
|
|
213
|
-
*/
|
|
214
130
|
unpublishAllEffects(): Promise<PublishToolsResult>;
|
|
215
|
-
/**
|
|
216
|
-
* Internal: re-publish the full effect catalog to the server.
|
|
217
|
-
* Called after any mutation to the effects Map.
|
|
218
|
-
*/
|
|
219
|
-
private _syncEffects;
|
|
220
131
|
/**
|
|
221
132
|
* Submit a job to execute code in the sandbox.
|
|
222
133
|
*
|
|
@@ -229,8 +140,8 @@ declare class Session {
|
|
|
229
140
|
* const books = await tolkien.get_books();
|
|
230
141
|
* ```
|
|
231
142
|
*
|
|
232
|
-
*
|
|
233
|
-
* `
|
|
143
|
+
* Effect calls (instance methods, static methods, global functions) trigger
|
|
144
|
+
* `effect.invoke` RPC back to the sandbox effect host, where the registered handlers
|
|
234
145
|
* execute locally and return the result to the sandbox.
|
|
235
146
|
*/
|
|
236
147
|
submitJob(code: string, domainRevision?: string): Promise<Job>;
|
|
@@ -244,15 +155,23 @@ declare class Session {
|
|
|
244
155
|
*/
|
|
245
156
|
answerPrompt(promptId: string, answer: unknown): Promise<void>;
|
|
246
157
|
/**
|
|
247
|
-
* Get the current list of available
|
|
248
|
-
* Consolidates
|
|
158
|
+
* Get the current list of available effects.
|
|
159
|
+
* Consolidates effect declarations and live availability for the session.
|
|
160
|
+
*/
|
|
161
|
+
getEffects(): EffectInfo[];
|
|
162
|
+
/**
|
|
163
|
+
* Backwards-compatible alias for `getEffects()`.
|
|
249
164
|
*/
|
|
250
165
|
getTools(): ToolInfo[];
|
|
251
166
|
/**
|
|
252
|
-
* Subscribe to
|
|
167
|
+
* Subscribe to effect changes (added, removed, updated).
|
|
253
168
|
* @param callback - Function called with change events
|
|
254
169
|
* @returns Unsubscribe function
|
|
255
170
|
*/
|
|
171
|
+
onEffectsChanged(callback: (event: EffectsChangedEvent) => void): () => void;
|
|
172
|
+
/**
|
|
173
|
+
* Backwards-compatible alias for `onEffectsChanged()`.
|
|
174
|
+
*/
|
|
256
175
|
onToolsChanged(callback: (event: ToolsChangedEvent) => void): () => void;
|
|
257
176
|
/**
|
|
258
177
|
* Get the current domain state and available tools
|
|
@@ -295,7 +214,7 @@ declare class Session {
|
|
|
295
214
|
private setupEventHandlers;
|
|
296
215
|
protected emit(event: string, data: unknown): void;
|
|
297
216
|
/**
|
|
298
|
-
* Check for changes in the
|
|
217
|
+
* Check for changes in the effect catalog and emit change events if needed.
|
|
299
218
|
*/
|
|
300
219
|
private checkForToolChanges;
|
|
301
220
|
}
|
|
@@ -306,10 +225,10 @@ declare class Session {
|
|
|
306
225
|
* After connecting, you can:
|
|
307
226
|
* 1. Define your domain ontology via `applyManifest()` (classes, properties, relationships)
|
|
308
227
|
* 2. Record object instances via `recordObject()` (with fields and relationship attachments)
|
|
309
|
-
* 3.
|
|
228
|
+
* 3. Register sandbox-scoped effects via `granular.registerEffect()` / `granular.registerEffects()`
|
|
310
229
|
* 4. Submit jobs via `submitJob()` that import auto-generated typed classes from `./sandbox-tools`
|
|
311
230
|
* 5. Execute GraphQL queries via `graphql()` (authenticated automatically)
|
|
312
|
-
* 6. List available
|
|
231
|
+
* 6. List available effects via `getEffects()` and listen for updates via `onEffectsChanged()`
|
|
313
232
|
*
|
|
314
233
|
* Tool calls from the sandbox automatically invoke your handlers via reverse-RPC.
|
|
315
234
|
*
|
|
@@ -591,64 +510,23 @@ declare class Environment extends Session {
|
|
|
591
510
|
*/
|
|
592
511
|
recordObject(options: RecordObjectOptions): Promise<RecordObjectResult>;
|
|
593
512
|
/**
|
|
594
|
-
*
|
|
595
|
-
* This is the main entry point for setting up tools.
|
|
596
|
-
*
|
|
597
|
-
* @example
|
|
598
|
-
* ```typescript
|
|
599
|
-
* const tools = [
|
|
600
|
-
* {
|
|
601
|
-
* name: 'get_weather',
|
|
602
|
-
* description: 'Get weather for a city',
|
|
603
|
-
* inputSchema: { type: 'object', properties: { city: { type: 'string' } } },
|
|
604
|
-
* handler: async ({ city }) => ({ temp: 22 }),
|
|
605
|
-
* },
|
|
606
|
-
* ];
|
|
607
|
-
*
|
|
608
|
-
* const { domainRevision } = await environment.publishTools(tools);
|
|
609
|
-
*
|
|
610
|
-
* // Now submit jobs that use those tools
|
|
611
|
-
* const job = await environment.submitJob(`
|
|
612
|
-
* import { Author } from './sandbox-tools';
|
|
613
|
-
* const weather = await Author.get_weather({ city: 'Paris' });
|
|
614
|
-
* return weather;
|
|
615
|
-
* `);
|
|
616
|
-
*
|
|
617
|
-
* const result = await job.result;
|
|
618
|
-
* ```
|
|
513
|
+
* Removed: environment-scoped effect publication is no longer supported.
|
|
619
514
|
*/
|
|
620
515
|
publishTools(tools: ToolWithHandler[], revision?: string): Promise<PublishToolsResult>;
|
|
621
516
|
/**
|
|
622
|
-
*
|
|
623
|
-
*
|
|
624
|
-
* Adds the effect to the local registry and re-publishes the
|
|
625
|
-
* full tool catalog to the server. If an effect with the same
|
|
626
|
-
* name already exists, it is replaced.
|
|
627
|
-
*
|
|
628
|
-
* @example
|
|
629
|
-
* ```typescript
|
|
630
|
-
* await env.publishEffect({
|
|
631
|
-
* name: 'get_bio',
|
|
632
|
-
* description: 'Get biography',
|
|
633
|
-
* inputSchema: { type: 'object', properties: { detailed: { type: 'boolean' } } },
|
|
634
|
-
* handler: async (params) => ({ bio: 'Hello' }),
|
|
635
|
-
* });
|
|
636
|
-
* ```
|
|
517
|
+
* Removed: environment-scoped effect publication is no longer supported.
|
|
637
518
|
*/
|
|
638
519
|
publishEffect(effect: ToolWithHandler): Promise<PublishToolsResult>;
|
|
639
520
|
/**
|
|
640
|
-
*
|
|
641
|
-
*
|
|
642
|
-
* Adds all effects to the local registry and re-publishes the
|
|
643
|
-
* full tool catalog in a single RPC call.
|
|
521
|
+
* Removed: environment-scoped effect publication is no longer supported.
|
|
644
522
|
*/
|
|
645
523
|
publishEffects(effects: ToolWithHandler[]): Promise<PublishToolsResult>;
|
|
646
524
|
/**
|
|
647
|
-
*
|
|
525
|
+
* Removed: environment-scoped effect publication is no longer supported.
|
|
648
526
|
*/
|
|
649
527
|
unpublishEffect(name: string): Promise<PublishToolsResult>;
|
|
650
528
|
/**
|
|
651
|
-
*
|
|
529
|
+
* Removed: environment-scoped effect publication is no longer supported.
|
|
652
530
|
*/
|
|
653
531
|
unpublishAllEffects(): Promise<PublishToolsResult>;
|
|
654
532
|
}
|
|
@@ -660,10 +538,12 @@ declare class Granular {
|
|
|
660
538
|
private WebSocketCtor?;
|
|
661
539
|
private onUnexpectedClose?;
|
|
662
540
|
private onReconnectError?;
|
|
663
|
-
/** Sandbox-level effect registry: sandboxId → (
|
|
541
|
+
/** Sandbox-level effect registry: sandboxId → (effectKey → ToolWithHandler) */
|
|
664
542
|
private sandboxEffects;
|
|
665
|
-
/**
|
|
666
|
-
private
|
|
543
|
+
/** Live sandbox-scoped effect hosts keyed by sandboxId */
|
|
544
|
+
private sandboxEffectHosts;
|
|
545
|
+
/** In-flight host connection promises to avoid duplicate concurrent connects */
|
|
546
|
+
private sandboxEffectHostPromises;
|
|
667
547
|
/**
|
|
668
548
|
* Create a new Granular client
|
|
669
549
|
* @param options - Client configuration
|
|
@@ -688,8 +568,9 @@ declare class Granular {
|
|
|
688
568
|
/**
|
|
689
569
|
* Connect to a sandbox and establish a real-time environment session.
|
|
690
570
|
*
|
|
691
|
-
*
|
|
692
|
-
*
|
|
571
|
+
* Effects are registered at the sandbox level via `granular.registerEffect()`
|
|
572
|
+
* or `granular.registerEffects()`. Sessions pick up live availability from
|
|
573
|
+
* the sandbox registry automatically.
|
|
693
574
|
*
|
|
694
575
|
* @param options - Connection options
|
|
695
576
|
* @returns An active environment session
|
|
@@ -706,10 +587,12 @@ declare class Granular {
|
|
|
706
587
|
* user,
|
|
707
588
|
* });
|
|
708
589
|
*
|
|
709
|
-
*
|
|
710
|
-
*
|
|
711
|
-
*
|
|
712
|
-
*
|
|
590
|
+
* await granular.registerEffect('my-sandbox', {
|
|
591
|
+
* name: 'greet',
|
|
592
|
+
* description: 'Say hello',
|
|
593
|
+
* inputSchema: { type: 'object', properties: {} },
|
|
594
|
+
* handler: async () => 'Hello!',
|
|
595
|
+
* });
|
|
713
596
|
*
|
|
714
597
|
* // Submit job
|
|
715
598
|
* const job = await environment.submitJob(`
|
|
@@ -721,13 +604,19 @@ declare class Granular {
|
|
|
721
604
|
* ```
|
|
722
605
|
*/
|
|
723
606
|
connect(options: ConnectOptions): Promise<Environment>;
|
|
607
|
+
private activateEnvironment;
|
|
608
|
+
private getSandboxEffectMap;
|
|
609
|
+
private serializeEffect;
|
|
610
|
+
private publishSandboxEffectCatalog;
|
|
611
|
+
private syncSandboxEffectCatalog;
|
|
612
|
+
private startEffectHostHeartbeat;
|
|
613
|
+
private stopEffectHostHeartbeat;
|
|
614
|
+
private synchronizeEffectHost;
|
|
615
|
+
private ensureSandboxEffectHost;
|
|
616
|
+
private disconnectSandboxEffectHost;
|
|
724
617
|
/**
|
|
725
618
|
* Register an effect (tool) for a specific sandbox.
|
|
726
619
|
*
|
|
727
|
-
* The effect will be automatically published to:
|
|
728
|
-
* 1. Any currently active environments for this sandbox
|
|
729
|
-
* 2. Any new environments created/connected for this sandbox
|
|
730
|
-
*
|
|
731
620
|
* @param sandboxNameOrId - The name or ID of the sandbox
|
|
732
621
|
* @param effect - The tool definition and handler
|
|
733
622
|
*/
|
|
@@ -741,8 +630,8 @@ declare class Granular {
|
|
|
741
630
|
/**
|
|
742
631
|
* Unregister an effect from a sandbox.
|
|
743
632
|
*
|
|
744
|
-
* Removes it from the local registry and
|
|
745
|
-
*
|
|
633
|
+
* Removes it from the local sandbox registry and updates the
|
|
634
|
+
* sandbox-scoped live catalog.
|
|
746
635
|
*/
|
|
747
636
|
unregisterEffect(sandboxNameOrId: string, name: string): Promise<void>;
|
|
748
637
|
/**
|
|
@@ -815,4 +704,4 @@ declare class Granular {
|
|
|
815
704
|
private request;
|
|
816
705
|
}
|
|
817
706
|
|
|
818
|
-
export { AssignmentListResponse, ConnectOptions, CreateEnvironmentData, CreatePermissionProfileData, CreateSandboxData, DefineRelationshipOptions, DeleteResponse, DomainState, Environment, EnvironmentData, Granular, GranularOptions, GraphQLResult, InstanceToolHandler, Job, ManifestContent, ModelRef, PermissionProfile, PublishToolsResult, RecordObjectOptions, RecordObjectResult, RecordUserOptions, RelationshipInfo, Sandbox, SandboxListResponse, Session, Subject, ToolHandler, ToolInfo, ToolWithHandler, ToolsChangedEvent, User, WSClient, WSClientOptions };
|
|
707
|
+
export { AssignmentListResponse, ConnectOptions, CreateEnvironmentData, CreatePermissionProfileData, CreateSandboxData, DefineRelationshipOptions, DeleteResponse, DomainState, EffectInfo, EffectsChangedEvent, Environment, EnvironmentData, Granular, GranularOptions, GraphQLResult, InstanceToolHandler, Job, ManifestContent, ModelRef, PermissionProfile, PublishToolsResult, RecordObjectOptions, RecordObjectResult, RecordUserOptions, RelationshipInfo, Sandbox, SandboxListResponse, Session, Subject, ToolHandler, ToolInfo, ToolWithHandler, ToolsChangedEvent, User, WSClient, WSClientOptions };
|