@granular-software/sdk 0.4.30 → 0.4.31

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 CHANGED
@@ -66,9 +66,9 @@ import { Granular, type ManifestContent } from "@granular-software/sdk";
66
66
  const granular = new Granular({ apiKey: process.env.GRANULAR_API_KEY });
67
67
 
68
68
  // 1. Connect to the default dev environment for one of your app users
69
- const env = await granular.connect({
69
+ const env = await granular.openEnvironment({
70
70
  ontology: "my-ontology",
71
- environment: "dev",
71
+ tag: "dev",
72
72
  userId: "user_123",
73
73
  permissions: ["agent"],
74
74
  name: "Jane Doe", // optional
@@ -130,7 +130,7 @@ await env.recordObject({
130
130
  });
131
131
 
132
132
  // 4. Register live effect handlers for effects already declared in the ontology manifest
133
- await granular.registerEffects(env.sandboxId, [
133
+ await granular.ontology(env.sandboxId).effects.registerMany([
134
134
  {
135
135
  name: "get_billing_summary",
136
136
  description: "Get billing summary for a customer",
@@ -167,7 +167,8 @@ await granular.registerEffects(env.sandboxId, [
167
167
  ]);
168
168
 
169
169
  // 6. Submit a job — the sandbox gets fully typed OOP classes!
170
- const job = await env.submitJob(`
170
+ const session = await env.sessions.create();
171
+ const job = await session.submitJob(`
171
172
  import { Customer } from './sandbox-tools';
172
173
 
173
174
  // list() discovers instances; get({ path }) hydrates a specific graph object
@@ -195,15 +196,15 @@ Effects must be declared ahead of time in the ontology version manifest with `wi
195
196
  ## Core Flow
196
197
 
197
198
  ```
198
- declare effects in the manifest → `granular build` creates or reuses a version → `connect({ ontology, environment, userId })` opens a named environment → `recordObject()` or `recordObjects()` → `registerEffects()` → `submitJob()`
199
+ declare effects in the manifest → `granular build` creates or reuses a version → `openEnvironment({ ontology, tag, userId })` resolves the user's environment → `recordObject()` or `recordObjects()` → `granular.ontology(...).effects.registerMany()` → `environment.sessions.create()` → `session.submitJob()`
199
200
  ```
200
201
 
201
- 1. **`connect()`** — Connect to an ontology environment for a given `userId`, returning an `Environment`
202
+ 1. **`openEnvironment()`** — Resolve or create an ontology environment for a given `userId`, returning an `Environment`
202
203
  2. **`recordUser()`** — Optional explicit user upsert when you want the returned `granularId`
203
204
  3. **`applyManifest()`** — Define your domain ontology (classes, properties, relationships)
204
205
  4. **`recordObject()` / `recordObjects()`** — Use `recordObject()` for one targeted upsert. Use `recordObjects()` for immediate multi-record writes with chunk progress.
205
- 5. **`granular.registerEffects()`** — Register sandbox-scoped live handlers for effects declared in the ontology manifest
206
- 6. **`submitJob()`** — Execute code in the sandbox that uses the auto-generated typed classes
206
+ 5. **`granular.ontology(...).effects.registerMany()`** — Register ontology-scoped live handlers for effects declared in the ontology manifest
207
+ 6. **`environment.sessions.create()` / `session.submitJob()`** — Open a live session and execute code against the sandbox runtime
207
208
 
208
209
  ## Defining the Domain Ontology
209
210
 
@@ -263,9 +264,9 @@ await env.applyManifest(manifest);
263
264
  After defining the ontology, connect as a user and populate it with data:
264
265
 
265
266
  ```typescript
266
- const env = await granular.connect({
267
+ const env = await granular.openEnvironment({
267
268
  ontology: "library-app",
268
- environment: "dev",
269
+ tag: "dev",
269
270
  userId: "user_123",
270
271
  permissions: ["agent"],
271
272
  });
@@ -307,10 +308,10 @@ For one-off writes, `recordObject(...)` is still the clearest choice. For large
307
308
 
308
309
  ## Effect Definitions
309
310
 
310
- Effects are declared in the manifest with `withEffect`, then their live handlers are registered at sandbox scope. Effects can be **instance methods**, **static methods**, or **global functions**. Both `inputSchema` and `outputSchema` use JSON Schema:
311
+ Effects are declared in the manifest with `withEffect`, then their live handlers are registered at ontology scope. Effects can be **instance methods**, **static methods**, or **global functions**. Both `inputSchema` and `outputSchema` use JSON Schema:
311
312
 
312
313
  ```typescript
313
- await granular.registerEffects(env.sandboxId, [
314
+ await granular.ontology(env.sandboxId).effects.registerMany([
314
315
  // Instance method: called as `tolkien.get_bio({ detailed: true })`
315
316
  // Handler receives (objectId, params)
316
317
  {
@@ -553,9 +554,9 @@ See [examples/](./examples/) for runnable code:
553
554
 
554
555
  Registers a user identity and their assigned permission profiles.
555
556
 
556
- ### `granular.connect(options)`
557
+ ### `granular.openEnvironment(options)`
557
558
 
558
- Connects to an environment session for the specified user. Pass `ontology` and `environment` explicitly, for example `environment: 'dev'` or `environment: 'prod'`. Only pass `tagName` for advanced overrides.
559
+ Resolves or creates an environment handle for the specified user. Pass `ontology` and a tag such as `tag: 'dev'` or `tag: 'prod'`.
559
560
 
560
561
  ### `environment.applyManifest(manifest)`
561
562
 
@@ -585,15 +586,15 @@ Returns relationship definitions for a given class.
585
586
 
586
587
  Lists related instances through a relationship.
587
588
 
588
- ### `granular.registerEffects(sandboxId, effects)`
589
+ ### `granular.ontology(sandboxId).effects.registerMany(effects)`
589
590
 
590
- Registers sandbox-scoped live handlers for effects declared in the ontology manifest. Effects can be instance methods (`className` set, `static` omitted), static methods (`static: true`), or global functions (no `className`).
591
+ Registers ontology-scoped live handlers for effects declared in the ontology manifest. Effects can be instance methods (`className` set, `static` omitted), static methods (`static: true`), or global functions (no `className`).
591
592
 
592
- ### `environment.submitJob(code)`
593
+ ### `environment.sessions.create(options?)` / `session.submitJob(code)`
593
594
 
594
- Submits code to be executed in the sandbox. The code imports typed classes from `./sandbox-tools`.
595
+ Open a live runtime session for the environment, then submit code to the sandbox. The code imports typed classes from `./sandbox-tools`.
595
596
 
596
- ### `environment.getDomainDocumentation()`
597
+ ### `session.getDomainDocumentation()`
597
598
 
598
599
  Get auto-generated TypeScript class declarations. Pass this to LLMs to help them write correct code.
599
600
 
@@ -601,7 +602,7 @@ Get auto-generated TypeScript class declarations. Pass this to LLMs to help them
601
602
 
602
603
  Execute a GraphQL query against the environment's graph. Authenticated automatically.
603
604
 
604
- ### `environment.on(event, handler)`
605
+ ### `session.on(event, handler)`
605
606
 
606
607
  Listen for events: `'effect:invoke'`, `'effect:result'`, `'job:status'`, `'stdout'`, etc. Legacy `'tool:*'` aliases still exist internally but are no longer the primary model.
607
608
 
@@ -616,3 +617,7 @@ Extract the real-world ID from a graph path by stripping the class prefix.
616
617
  ## License
617
618
 
618
619
  MIT
620
+
621
+ ## License
622
+
623
+ MIT
@@ -1,4 +1,4 @@
1
- import { P as Prompt, e as Environment, c as SessionHeapSnapshot, b3 as ManifestContent, aB as RecordObjectOptions, T as ToolWithHandler, G as Granular, C as ConnectOptions, z as CreateEnvironmentData, j as GranularOptions } from './client-BVvOMfln.mjs';
1
+ import { P as Prompt, f as EnvironmentSession, c as SessionHeapSnapshot, b8 as ManifestContent, aG as RecordObjectOptions, T as ToolWithHandler, G as Granular, C as ConnectOptions, J as CreateEnvironmentData, k as GranularOptions } from './client-CTH1hfwe.mjs';
2
2
  import { GeneratedJobCodeIssue, HarnessControllerBudgets } from './agent-harness.mjs';
3
3
  import '@automerge/automerge';
4
4
  import '@automerge/automerge/slim';
@@ -49,7 +49,7 @@ interface AgentEvalExpectations {
49
49
  }
50
50
  interface AgentEvalCheckContext {
51
51
  conversation: AgentEvalConversation;
52
- environment: Environment;
52
+ environment: EnvironmentSession;
53
53
  turnDir: string;
54
54
  request: string;
55
55
  responseText: string;
@@ -73,7 +73,7 @@ interface AgentEvalInspection {
73
73
  }
74
74
  interface AgentEvalSetupContext {
75
75
  conversation: AgentEvalConversation;
76
- environment: Environment;
76
+ environment: EnvironmentSession;
77
77
  turnDir: string;
78
78
  }
79
79
  interface AgentEvalSetup {
@@ -84,7 +84,7 @@ interface AgentEvalSetup {
84
84
  }
85
85
  interface AgentEvalPrepareContext {
86
86
  conversation: AgentEvalConversation;
87
- environment: Environment;
87
+ environment: EnvironmentSession;
88
88
  turnDir: string;
89
89
  }
90
90
  interface AgentEvalStep {
@@ -148,7 +148,7 @@ interface AgentEvalHarnessOptions {
148
148
  openEnvironment?: (input: {
149
149
  label: string;
150
150
  clientId: string;
151
- }) => Promise<Environment>;
151
+ }) => Promise<EnvironmentSession>;
152
152
  generator: AgentEvalTurnGenerator;
153
153
  artifactBaseDir?: string;
154
154
  suiteName?: string;
@@ -159,7 +159,7 @@ interface AgentEvalHarnessOptions {
159
159
  }
160
160
  interface AgentEvalConversation {
161
161
  label: string;
162
- environment: Environment;
162
+ environment: EnvironmentSession;
163
163
  history: AgentEvalHistoryEntry[];
164
164
  promptEvents: PendingPromptEvent[];
165
165
  artifactDir: string;
@@ -224,6 +224,7 @@ declare function runAgentEvalSuite(options: {
224
224
  }): Promise<AgentEvalSuiteResult>;
225
225
  declare function createAgentEvalHarness(options: AgentEvalHarnessOptions): {
226
226
  artifactDir: string;
227
+ granular: Granular;
227
228
  openConversation: (label: string) => Promise<AgentEvalConversation>;
228
229
  closeConversation: (conversation: AgentEvalConversation) => Promise<void>;
229
230
  runTurn: (input: {
@@ -1,4 +1,4 @@
1
- import { P as Prompt, e as Environment, c as SessionHeapSnapshot, b3 as ManifestContent, aB as RecordObjectOptions, T as ToolWithHandler, G as Granular, C as ConnectOptions, z as CreateEnvironmentData, j as GranularOptions } from './client-BVvOMfln.js';
1
+ import { P as Prompt, f as EnvironmentSession, c as SessionHeapSnapshot, b8 as ManifestContent, aG as RecordObjectOptions, T as ToolWithHandler, G as Granular, C as ConnectOptions, J as CreateEnvironmentData, k as GranularOptions } from './client-CTH1hfwe.js';
2
2
  import { GeneratedJobCodeIssue, HarnessControllerBudgets } from './agent-harness.js';
3
3
  import '@automerge/automerge';
4
4
  import '@automerge/automerge/slim';
@@ -49,7 +49,7 @@ interface AgentEvalExpectations {
49
49
  }
50
50
  interface AgentEvalCheckContext {
51
51
  conversation: AgentEvalConversation;
52
- environment: Environment;
52
+ environment: EnvironmentSession;
53
53
  turnDir: string;
54
54
  request: string;
55
55
  responseText: string;
@@ -73,7 +73,7 @@ interface AgentEvalInspection {
73
73
  }
74
74
  interface AgentEvalSetupContext {
75
75
  conversation: AgentEvalConversation;
76
- environment: Environment;
76
+ environment: EnvironmentSession;
77
77
  turnDir: string;
78
78
  }
79
79
  interface AgentEvalSetup {
@@ -84,7 +84,7 @@ interface AgentEvalSetup {
84
84
  }
85
85
  interface AgentEvalPrepareContext {
86
86
  conversation: AgentEvalConversation;
87
- environment: Environment;
87
+ environment: EnvironmentSession;
88
88
  turnDir: string;
89
89
  }
90
90
  interface AgentEvalStep {
@@ -148,7 +148,7 @@ interface AgentEvalHarnessOptions {
148
148
  openEnvironment?: (input: {
149
149
  label: string;
150
150
  clientId: string;
151
- }) => Promise<Environment>;
151
+ }) => Promise<EnvironmentSession>;
152
152
  generator: AgentEvalTurnGenerator;
153
153
  artifactBaseDir?: string;
154
154
  suiteName?: string;
@@ -159,7 +159,7 @@ interface AgentEvalHarnessOptions {
159
159
  }
160
160
  interface AgentEvalConversation {
161
161
  label: string;
162
- environment: Environment;
162
+ environment: EnvironmentSession;
163
163
  history: AgentEvalHistoryEntry[];
164
164
  promptEvents: PendingPromptEvent[];
165
165
  artifactDir: string;
@@ -224,6 +224,7 @@ declare function runAgentEvalSuite(options: {
224
224
  }): Promise<AgentEvalSuiteResult>;
225
225
  declare function createAgentEvalHarness(options: AgentEvalHarnessOptions): {
226
226
  artifactDir: string;
227
+ granular: Granular;
227
228
  openConversation: (label: string) => Promise<AgentEvalConversation>;
228
229
  closeConversation: (conversation: AgentEvalConversation) => Promise<void>;
229
230
  runTurn: (input: {