@granular-software/sdk 0.4.12 → 0.4.14

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/dist/index.d.mts CHANGED
@@ -86,11 +86,15 @@ interface Subject {
86
86
  updatedAt: number;
87
87
  }
88
88
  /**
89
- * Options for connecting to a sandbox
89
+ * Options for connecting to an ontology environment
90
90
  */
91
91
  interface ConnectOptions {
92
- /** The sandbox name or ID to connect to */
93
- sandbox: string;
92
+ /** The ontology name or ID to connect to */
93
+ ontology: string;
94
+ /** Named environment slot such as `dev` or `prod` */
95
+ environment: string;
96
+ /** Advanced override for the version tag/channel to follow. In the common case, omit this. */
97
+ tagName?: string;
94
98
  /**
95
99
  * External user identifier from your app. This is the primary input for
96
100
  * connecting to a sandbox and the only required user field in the common case.
@@ -211,11 +215,30 @@ interface AssignmentListResponse {
211
215
  items: Assignment[];
212
216
  }
213
217
  /**
214
- * Build policy for environments
218
+ * Version tracking policy for environments.
219
+ *
220
+ * Environments either follow a version tag such as `dev` or `prod`, or they
221
+ * pin themselves to one immutable ontology version.
215
222
  */
216
223
  interface BuildPolicy {
217
- mode: 'current' | 'pinned';
224
+ mode: 'tag' | 'current' | 'pinned';
218
225
  buildId?: string;
226
+ versionId?: string;
227
+ tagId?: string;
228
+ tagName?: string;
229
+ }
230
+ type VersionTracking = BuildPolicy;
231
+ interface VersionTag {
232
+ tagId: string;
233
+ sandboxId: string;
234
+ name: string;
235
+ kind: 'channel' | 'release' | 'system';
236
+ targetBuildId?: string | null;
237
+ targetVersionId?: string | null;
238
+ description?: string | null;
239
+ protected?: boolean;
240
+ createdAt: number;
241
+ updatedAt: number;
219
242
  }
220
243
  /**
221
244
  * An environment links a user (subject) to a sandbox with specific permissions
@@ -223,10 +246,18 @@ interface BuildPolicy {
223
246
  interface EnvironmentData {
224
247
  environmentId: string;
225
248
  sandboxId: string;
249
+ ontologyId?: string;
226
250
  buildId: string;
251
+ versionId: string;
227
252
  subjectId: string;
253
+ envName: string;
254
+ environment?: string;
228
255
  permissionProfileId: string;
256
+ tagId?: string | null;
257
+ tag?: VersionTag | null;
258
+ tracking?: BuildPolicy;
229
259
  buildPolicy: BuildPolicy;
260
+ updateState?: 'up_to_date' | 'update_available' | 'upgrading' | 'failed';
230
261
  createdAt: number;
231
262
  updatedAt: number;
232
263
  }
@@ -236,9 +267,19 @@ interface EnvironmentData {
236
267
  interface CreateEnvironmentData {
237
268
  /** The user/subject ID to create the environment for */
238
269
  subjectId: string;
270
+ /** Named environment slot such as dev or prod */
271
+ environment?: string;
272
+ /** @deprecated Use `environment` instead. */
273
+ envName?: string;
239
274
  /** The permission profile to apply (optional - uses assignment if not specified) */
240
275
  permissionProfileId?: string | null;
241
- /** Build policy (defaults to current build) */
276
+ /** Follow a tag directly */
277
+ tagId?: string;
278
+ /** Follow a tag by name, typically dev or prod */
279
+ tagName?: string;
280
+ /** Pin the environment to a specific version */
281
+ versionId?: string;
282
+ /** Legacy/compat environment tracking input */
242
283
  buildPolicy?: BuildPolicy;
243
284
  }
244
285
  /**
@@ -267,25 +308,58 @@ interface ManifestListResponse {
267
308
  }
268
309
  type BuildStatus = 'queued' | 'building' | 'completed' | 'failed' | 'canceled';
269
310
  /**
270
- * A build represents a compiled version of a manifest
311
+ * An immutable ontology version derived from a specific manifest revision.
312
+ *
313
+ * The same version may have multiple build runs over time when the manifest
314
+ * content is unchanged but the compilation process is re-executed.
271
315
  */
272
316
  interface Build {
273
317
  buildId: string;
274
318
  sandboxId: string;
275
319
  manifestId: string;
320
+ manifestDigest?: string;
321
+ versionNumber?: number;
276
322
  status: BuildStatus;
277
323
  graphBinaryId?: string | null;
278
324
  logsUri?: string | null;
325
+ latestBuildRunId?: string | null;
326
+ buildRunId?: string;
327
+ createdNewVersion?: boolean;
328
+ environmentCount?: number;
329
+ laggingEnvironmentCount?: number;
330
+ sessionCount?: number;
279
331
  createdAt: number;
280
332
  updatedAt: number;
281
333
  isCurrent?: boolean;
282
334
  }
335
+ type Version = Build;
283
336
  /**
284
- * List response for builds
337
+ * List response for versions
285
338
  */
286
339
  interface BuildListResponse {
287
340
  items: Build[];
288
341
  }
342
+ interface SemanticVersionDiffEntry {
343
+ operationId: string;
344
+ kind: 'create' | 'update' | 'relationship' | 'effect' | 'unknown';
345
+ changeType: 'added' | 'removed' | 'changed';
346
+ label: string;
347
+ additive: boolean;
348
+ breaking: boolean;
349
+ before?: Record<string, unknown>;
350
+ after?: Record<string, unknown>;
351
+ }
352
+ interface SemanticVersionDiff {
353
+ summary: {
354
+ added: number;
355
+ removed: number;
356
+ changed: number;
357
+ additive: number;
358
+ breaking: number;
359
+ onlyAdditiveChanges: boolean;
360
+ };
361
+ entries: SemanticVersionDiffEntry[];
362
+ }
289
363
  /**
290
364
  * Effect handler for static/global effects: receives (input, context)
291
365
  */
@@ -304,6 +378,38 @@ interface EffectHandlerContext {
304
378
  identityId?: string;
305
379
  principalId?: string;
306
380
  };
381
+ behaviors?: ResolvedEffectBehaviors;
382
+ invocation?: EffectInvocationMetadata;
383
+ }
384
+ interface ResolvedEffectPostCondition {
385
+ condition: string;
386
+ description?: string;
387
+ }
388
+ interface ResolvedEffectDryRun {
389
+ enabled: boolean;
390
+ description?: string;
391
+ }
392
+ interface ResolvedEffectReverse {
393
+ handler?: string;
394
+ description?: string;
395
+ }
396
+ interface ResolvedEffectApprovalRequired {
397
+ required: boolean;
398
+ reason?: string;
399
+ mode?: string;
400
+ }
401
+ interface ResolvedEffectBehaviors {
402
+ postCondition?: ResolvedEffectPostCondition;
403
+ dryRun?: ResolvedEffectDryRun;
404
+ reverse?: ResolvedEffectReverse;
405
+ approvalRequired?: ResolvedEffectApprovalRequired;
406
+ }
407
+ type EffectInvocationMode = 'execute' | 'dryRun' | 'reverse';
408
+ interface EffectInvocationMetadata {
409
+ mode?: EffectInvocationMode;
410
+ reverseHandler?: string;
411
+ sourceEffectKey?: string;
412
+ sourceEffectName?: string;
307
413
  }
308
414
  type ToolHandler = (input: any, context: EffectHandlerContext) => Promise<unknown>;
309
415
  /**
@@ -373,6 +479,8 @@ interface ToolSchema {
373
479
  * passed as the first argument to the handler).
374
480
  */
375
481
  static?: boolean;
482
+ /** Declarative runtime behaviors attached to the effect. */
483
+ metamodels?: ManifestEffectMetamodelSpec;
376
484
  }
377
485
  type EffectSchema = ToolSchema;
378
486
  /**
@@ -387,6 +495,8 @@ type EffectSchema = ToolSchema;
387
495
  */
388
496
  interface ToolWithHandler extends ToolSchema {
389
497
  handler: ToolHandler | InstanceToolHandler;
498
+ dryRunHandler?: ToolHandler | InstanceToolHandler;
499
+ reverseHandler?: ToolHandler | InstanceToolHandler;
390
500
  }
391
501
  type EffectWithHandler = ToolWithHandler;
392
502
  /**
@@ -411,6 +521,7 @@ interface DomainState {
411
521
  description?: string;
412
522
  inputSchema?: Record<string, unknown>;
413
523
  outputSchema?: Record<string, unknown>;
524
+ metamodels?: ManifestEffectMetamodelSpec;
414
525
  }>;
415
526
  [key: string]: unknown;
416
527
  }
@@ -437,6 +548,8 @@ interface ToolInfo {
437
548
  className?: string;
438
549
  /** Whether this is a static method */
439
550
  static?: boolean;
551
+ /** Declarative runtime behaviors attached to the effect. */
552
+ metamodels?: ManifestEffectMetamodelSpec;
440
553
  }
441
554
  interface EffectInfo extends ToolInfo {
442
555
  }
@@ -795,6 +908,65 @@ interface ManifestPropertySpec {
795
908
  type?: string;
796
909
  description?: string;
797
910
  required?: boolean;
911
+ note?: string | string[];
912
+ enum?: string[] | ManifestEnumRuleSpec;
913
+ filterBy?: boolean | string[] | ManifestFilterBySpec;
914
+ validate?: ManifestValidationRuleSpec[];
915
+ }
916
+ type ManifestValidationOperator = 'eq' | 'neq' | 'gt' | 'gte' | 'lt' | 'lte' | 'true' | 'false' | 'regex' | 'contains' | 'not_contains' | 'starts_with' | 'ends_with';
917
+ interface ManifestEnumRuleSpec {
918
+ values: string[];
919
+ message?: string;
920
+ }
921
+ interface ManifestFilterBySpec {
922
+ operators: string[];
923
+ scalarType?: string;
924
+ }
925
+ interface ManifestValidationRuleSpec {
926
+ operator: ManifestValidationOperator;
927
+ stringValue?: string;
928
+ numberValue?: number;
929
+ booleanValue?: boolean;
930
+ message?: string;
931
+ }
932
+ interface ManifestStateMachineStateSpec {
933
+ name: string;
934
+ isFinal?: boolean;
935
+ }
936
+ interface ManifestStateMachineTransitionSpec {
937
+ name: string;
938
+ from: string;
939
+ to: string;
940
+ }
941
+ interface ManifestStateMachineSpec {
942
+ name: string;
943
+ entryState: string;
944
+ states: Array<string | ManifestStateMachineStateSpec>;
945
+ transitions: ManifestStateMachineTransitionSpec[];
946
+ finalStates?: string[];
947
+ }
948
+ interface ManifestPostConditionSpec {
949
+ condition: string;
950
+ description?: string;
951
+ }
952
+ interface ManifestDryRunSpec {
953
+ enabled?: boolean;
954
+ description?: string;
955
+ }
956
+ interface ManifestReverseSpec {
957
+ handler?: string;
958
+ description?: string;
959
+ }
960
+ interface ManifestApprovalRequiredSpec {
961
+ required?: boolean;
962
+ reason?: string;
963
+ mode?: string;
964
+ }
965
+ interface ManifestEffectMetamodelSpec {
966
+ postCondition?: string | ManifestPostConditionSpec;
967
+ dryRun?: boolean | ManifestDryRunSpec;
968
+ reverse?: string | ManifestReverseSpec;
969
+ approvalRequired?: boolean | ManifestApprovalRequiredSpec;
798
970
  }
799
971
  /**
800
972
  * Relationship definition between two classes
@@ -832,6 +1004,7 @@ interface ManifestEffectDeclaration {
832
1004
  outputSchema?: ManifestEffectSchema;
833
1005
  stability?: 'stable' | 'experimental' | 'deprecated';
834
1006
  tags?: string[];
1007
+ metamodels?: ManifestEffectMetamodelSpec;
835
1008
  }
836
1009
  /**
837
1010
  * A single operation in a manifest volume
@@ -847,6 +1020,10 @@ interface ManifestOperation {
847
1020
  instanceOf?: string;
848
1021
  /** Define submodels/fields */
849
1022
  has?: Record<string, ManifestPropertySpec>;
1023
+ /** Advisory notes attached to the model/class itself */
1024
+ note?: string | string[];
1025
+ /** State machines attached to the created or targeted class */
1026
+ stateMachines?: ManifestStateMachineSpec[];
850
1027
  /** Define a relationship between two classes */
851
1028
  defineRelationship?: ManifestRelationshipDef;
852
1029
  /** Declare a build-owned effect */
@@ -1150,8 +1327,16 @@ declare class Environment extends Session {
1150
1327
  get environmentId(): string;
1151
1328
  /** The sandbox ID */
1152
1329
  get sandboxId(): string;
1330
+ /** The ontology ID */
1331
+ get ontologyId(): string;
1153
1332
  /** The subject ID */
1154
1333
  get subjectId(): string;
1334
+ /** The named environment slot, such as dev or prod */
1335
+ get envName(): string;
1336
+ /** The named environment slot, such as dev or prod */
1337
+ get environment(): string;
1338
+ /** The resolved ontology version backing this environment */
1339
+ get versionId(): string;
1155
1340
  /** Internal Granular user identifier for this environment */
1156
1341
  get granularId(): string;
1157
1342
  /** The permission profile ID */
@@ -1384,6 +1569,13 @@ declare class Environment extends Session {
1384
1569
  * Strips the alias prefix, returning the bare model path.
1385
1570
  */
1386
1571
  private _resolveAlias;
1572
+ private _runGraphql;
1573
+ private _applyFieldMetamodels;
1574
+ private _applyModelMetamodels;
1575
+ private _ensureWorkspaceToolsRoot;
1576
+ private _storeEffectSchemas;
1577
+ private _applyEffectMetamodels;
1578
+ private _applyEffectDeclaration;
1387
1579
  /**
1388
1580
  * Apply a single manifest operation via GraphQL
1389
1581
  */
@@ -1515,7 +1707,7 @@ declare class Granular {
1515
1707
  recordUser(options: RecordUserOptions): Promise<User>;
1516
1708
  private resolveConnectUser;
1517
1709
  /**
1518
- * Connect to a sandbox and establish a real-time environment session.
1710
+ * Connect to an ontology environment and establish a real-time session.
1519
1711
  *
1520
1712
  * Effects are registered at the sandbox level via `granular.registerEffect()`
1521
1713
  * or `granular.registerEffects()`. Sessions pick up live availability from
@@ -1527,7 +1719,8 @@ declare class Granular {
1527
1719
  * @example
1528
1720
  * ```typescript
1529
1721
  * const environment = await granular.connect({
1530
- * sandbox: 'my-sandbox',
1722
+ * ontology: 'my-ontology',
1723
+ * environment: 'dev',
1531
1724
  * userId: 'user_123',
1532
1725
  * permissions: ['agent'],
1533
1726
  * });
@@ -1547,13 +1740,14 @@ declare class Granular {
1547
1740
  *
1548
1741
  * console.log(await job.result); // 'Hello!'
1549
1742
  * ```
1550
- */
1743
+ */
1551
1744
  connect(options: ConnectOptions): Promise<Environment>;
1552
1745
  private activateEnvironment;
1553
1746
  private getSandboxEffectMap;
1554
1747
  private serializeEffect;
1555
1748
  private publishSandboxEffectCatalog;
1556
1749
  private syncSandboxEffectCatalog;
1750
+ private recoverEffectHost;
1557
1751
  private startEffectHostHeartbeat;
1558
1752
  private stopEffectHostHeartbeat;
1559
1753
  private synchronizeEffectHost;
@@ -1656,4 +1850,13 @@ declare class Granular {
1656
1850
  private request;
1657
1851
  }
1658
1852
 
1659
- 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, type EnvironmentRecordImportSummary, Granular, type GranularAuth, type GranularOptions, type GraphQLResult, type InstanceEffectHandler, type InstanceToolHandler, type Job, type JobFeedbackInput, type JobFeedbackMetadata, type JobFeedbackRecord, type JobFeedbackSentiment, type JobFeedbackToolCall, 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 RecordImport, type RecordImportItem, type RecordImportItemStatus, type RecordImportStats, type RecordImportStatus, 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 };
1853
+ type EffectRuntimeRequest = {
1854
+ effectKey: string;
1855
+ effectName: string;
1856
+ input: unknown;
1857
+ context?: EffectHandlerContext;
1858
+ };
1859
+ declare function normalizeEffectBehaviors(value?: ManifestEffectMetamodelSpec | ResolvedEffectBehaviors | null): ResolvedEffectBehaviors;
1860
+ declare function invokeRegisteredEffect(effectMap: Map<string, ToolWithHandler>, request: EffectRuntimeRequest): Promise<unknown>;
1861
+
1862
+ 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 EffectInvocationMetadata, type EffectInvocationMode, type EffectSchema, type EffectWithHandler, type EffectsChangedEvent, type EndpointMode, Environment, type EnvironmentData, type EnvironmentListResponse, type EnvironmentRecordImportSummary, Granular, type GranularAuth, type GranularOptions, type GraphQLResult, type InstanceEffectHandler, type InstanceToolHandler, type Job, type JobFeedbackInput, type JobFeedbackMetadata, type JobFeedbackRecord, type JobFeedbackSentiment, type JobFeedbackToolCall, type JobStatus, type JobSubmitResult, type Manifest, type ManifestApprovalRequiredSpec, type ManifestContent, type ManifestDryRunSpec, type ManifestEffectDeclaration, type ManifestEffectMetamodelSpec, type ManifestEffectSchema, type ManifestEnumRuleSpec, type ManifestFilterBySpec, type ManifestImport, type ManifestListResponse, type ManifestOperation, type ManifestPostConditionSpec, type ManifestPropertySpec, type ManifestRelationshipDef, type ManifestReverseSpec, type ManifestStateMachineSpec, type ManifestStateMachineStateSpec, type ManifestStateMachineTransitionSpec, type ManifestValidationOperator, type ManifestValidationRuleSpec, type ManifestVolume, type ModelRef, type PermissionProfile, type PermissionProfileListResponse, type PermissionRules, type Prompt, type PublishEffectsResult, type PublishToolsResult, type RPCRequest, type RPCRequestFromServer, type RPCResponse, type RecordImport, type RecordImportItem, type RecordImportItemStatus, type RecordImportStats, type RecordImportStatus, type RecordObjectOptions, type RecordObjectResult, type RecordUserOptions, type RelationshipInfo, type ResolvedEffectApprovalRequired, type ResolvedEffectBehaviors, type ResolvedEffectDryRun, type ResolvedEffectPostCondition, type ResolvedEffectReverse, type Sandbox, type SandboxListResponse, type SemanticVersionDiff, type SemanticVersionDiffEntry, 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, type Version, type VersionTag, type VersionTracking, WSClient, type WSClientOptions, type WSDisconnectInfo, type WSReconnectErrorInfo, invokeRegisteredEffect, normalizeEffectBehaviors };