@granular-software/sdk 0.4.8 → 0.4.9

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
@@ -458,6 +458,51 @@ interface EffectsChangedEvent extends ToolsChangedEvent {
458
458
  type EffectHandler = ToolHandler;
459
459
  type InstanceEffectHandler = InstanceToolHandler;
460
460
  type JobStatus = 'queued' | 'running' | 'succeeded' | 'failed' | 'timeout' | 'canceled';
461
+ type JobFeedbackSentiment = 'good' | 'bad';
462
+ interface JobFeedbackToolCall {
463
+ callId?: string;
464
+ toolName?: string;
465
+ input?: unknown;
466
+ output?: unknown;
467
+ error?: string;
468
+ startedAt?: number;
469
+ completedAt?: number;
470
+ durationMs?: number | null;
471
+ }
472
+ interface JobFeedbackMetadata {
473
+ source: 'sdk';
474
+ status: JobStatus;
475
+ code: string;
476
+ domainRevision?: string;
477
+ createdAt: number;
478
+ startedAt?: number;
479
+ completedAt?: number;
480
+ durationMs?: number | null;
481
+ result?: unknown;
482
+ error?: string;
483
+ stdout: string[];
484
+ stderr: string[];
485
+ toolCalls: JobFeedbackToolCall[];
486
+ }
487
+ interface JobFeedbackInput {
488
+ sentiment: JobFeedbackSentiment;
489
+ comment?: string | null;
490
+ }
491
+ interface JobFeedbackRecord {
492
+ feedbackId: string;
493
+ tenantId?: string;
494
+ sessionId: string;
495
+ environmentId: string;
496
+ sandboxId?: string;
497
+ buildId?: string;
498
+ subjectId?: string;
499
+ jobId: string;
500
+ sentiment: JobFeedbackSentiment;
501
+ comment?: string | null;
502
+ metadata: JobFeedbackMetadata & Record<string, unknown>;
503
+ createdAt: number;
504
+ updatedAt: number;
505
+ }
461
506
  /**
462
507
  * Result from submitting a job
463
508
  */
@@ -474,6 +519,8 @@ interface Job {
474
519
  status: JobStatus;
475
520
  /** Promise that resolves with the job result */
476
521
  result: Promise<unknown>;
522
+ /** Attach user feedback to this job and persist it with job/session metadata */
523
+ leaveFeedback(input: JobFeedbackInput): Promise<JobFeedbackRecord>;
477
524
  /** Subscribe to job events */
478
525
  on(event: string, handler: (data: unknown) => void): void;
479
526
  }
@@ -677,6 +724,58 @@ interface RecordObjectResult {
677
724
  /** Whether the instance was newly created (false = updated) */
678
725
  created: boolean;
679
726
  }
727
+ type RecordImportStatus = 'queued' | 'processing' | 'completed' | 'failed' | 'canceled';
728
+ type RecordImportItemStatus = 'queued' | 'processing' | 'completed' | 'failed' | 'canceled';
729
+ interface RecordImportStats {
730
+ totalRecords: number;
731
+ queuedRecords: number;
732
+ processingRecords: number;
733
+ completedRecords: number;
734
+ failedRecords: number;
735
+ canceledRecords: number;
736
+ awaitingRecords: number;
737
+ }
738
+ interface RecordImportItem {
739
+ itemId: string;
740
+ importId: string;
741
+ tenantId: string;
742
+ environmentId: string;
743
+ className: string;
744
+ id: string;
745
+ label: string | null;
746
+ fields: Record<string, string | number | boolean | null> | null;
747
+ relationships: Record<string, string | string[]> | null;
748
+ status: RecordImportItemStatus;
749
+ attempts: number;
750
+ errorMessage: string | null;
751
+ resultPath: string | null;
752
+ resultCreated: boolean | null;
753
+ createdAt: number;
754
+ updatedAt: number;
755
+ processedAt: number | null;
756
+ }
757
+ interface RecordImport {
758
+ importId: string;
759
+ tenantId: string;
760
+ environmentId: string;
761
+ sandboxId: string;
762
+ subjectId: string;
763
+ status: RecordImportStatus;
764
+ batchSize: number;
765
+ errorMessage: string | null;
766
+ createdAt: number;
767
+ updatedAt: number;
768
+ startedAt: number | null;
769
+ finishedAt: number | null;
770
+ canceledAt: number | null;
771
+ stats: RecordImportStats;
772
+ }
773
+ interface EnvironmentRecordImportSummary extends RecordImportStats {
774
+ environmentId: string;
775
+ totalImports: number;
776
+ activeImports: number;
777
+ updatedAt: number;
778
+ }
680
779
  /**
681
780
  * Property specification in a manifest operation
682
781
  */
@@ -815,6 +914,7 @@ declare class WSClient {
815
914
  private isExplicitlyDisconnected;
816
915
  private options;
817
916
  constructor(options: WSClientOptions);
917
+ get currentSessionId(): string;
818
918
  private clearTokenRefreshTimer;
819
919
  private decodeBase64Url;
820
920
  private getTokenExpiryMs;
@@ -887,6 +987,7 @@ declare class Session {
887
987
  private extractDomainRevisionFromDoc;
888
988
  private buildLegacyEffectContext;
889
989
  get document(): Doc<Record<string, unknown>>;
990
+ get sessionId(): string;
890
991
  get domainRevision(): string | null;
891
992
  /**
892
993
  * Make a raw RPC call to the session's Durable Object.
@@ -1058,6 +1159,7 @@ declare class Environment extends Session {
1058
1159
  */
1059
1160
  getHeap(): SessionHeapSnapshot;
1060
1161
  private getRuntimeBaseUrl;
1162
+ private controlPlaneRequest;
1061
1163
  /**
1062
1164
  * Close the session and disconnect from the sandbox.
1063
1165
  *
@@ -1315,6 +1417,39 @@ declare class Environment extends Session {
1315
1417
  * ```
1316
1418
  */
1317
1419
  recordObject(options: RecordObjectOptions): Promise<RecordObjectResult>;
1420
+ /**
1421
+ * Batch version of `recordObject()`.
1422
+ *
1423
+ * Sends several upserts through the control-plane batch endpoint so the
1424
+ * server can collapse the graph mutations into far fewer round trips.
1425
+ */
1426
+ recordObjects(records: RecordObjectOptions[]): Promise<RecordObjectResult[]>;
1427
+ /**
1428
+ * Queue a background record import for this environment.
1429
+ */
1430
+ enqueueRecordImport(records: RecordObjectOptions[], options?: {
1431
+ batchSize?: number;
1432
+ }): Promise<RecordImport>;
1433
+ /**
1434
+ * List queued or completed record imports for this environment.
1435
+ */
1436
+ listRecordImports(status?: RecordImportStatus): Promise<RecordImport[]>;
1437
+ /**
1438
+ * Fetch the latest aggregate import counters for this environment.
1439
+ */
1440
+ getRecordImportSummary(): Promise<EnvironmentRecordImportSummary>;
1441
+ /**
1442
+ * Convenience helper returning queued + processing records for this environment.
1443
+ */
1444
+ getAwaitingRecordCount(): Promise<number>;
1445
+ /**
1446
+ * Fetch a single record import by id.
1447
+ */
1448
+ getRecordImport(importId: string): Promise<RecordImport>;
1449
+ /**
1450
+ * Cancel a queued/background record import.
1451
+ */
1452
+ cancelRecordImport(importId: string): Promise<RecordImport>;
1318
1453
  /**
1319
1454
  * Removed: environment-scoped effect publication is no longer supported.
1320
1455
  */
@@ -1514,4 +1649,4 @@ declare class Granular {
1514
1649
  private request;
1515
1650
  }
1516
1651
 
1517
- 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 };
1652
+ 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 };
package/dist/index.d.ts CHANGED
@@ -458,6 +458,51 @@ interface EffectsChangedEvent extends ToolsChangedEvent {
458
458
  type EffectHandler = ToolHandler;
459
459
  type InstanceEffectHandler = InstanceToolHandler;
460
460
  type JobStatus = 'queued' | 'running' | 'succeeded' | 'failed' | 'timeout' | 'canceled';
461
+ type JobFeedbackSentiment = 'good' | 'bad';
462
+ interface JobFeedbackToolCall {
463
+ callId?: string;
464
+ toolName?: string;
465
+ input?: unknown;
466
+ output?: unknown;
467
+ error?: string;
468
+ startedAt?: number;
469
+ completedAt?: number;
470
+ durationMs?: number | null;
471
+ }
472
+ interface JobFeedbackMetadata {
473
+ source: 'sdk';
474
+ status: JobStatus;
475
+ code: string;
476
+ domainRevision?: string;
477
+ createdAt: number;
478
+ startedAt?: number;
479
+ completedAt?: number;
480
+ durationMs?: number | null;
481
+ result?: unknown;
482
+ error?: string;
483
+ stdout: string[];
484
+ stderr: string[];
485
+ toolCalls: JobFeedbackToolCall[];
486
+ }
487
+ interface JobFeedbackInput {
488
+ sentiment: JobFeedbackSentiment;
489
+ comment?: string | null;
490
+ }
491
+ interface JobFeedbackRecord {
492
+ feedbackId: string;
493
+ tenantId?: string;
494
+ sessionId: string;
495
+ environmentId: string;
496
+ sandboxId?: string;
497
+ buildId?: string;
498
+ subjectId?: string;
499
+ jobId: string;
500
+ sentiment: JobFeedbackSentiment;
501
+ comment?: string | null;
502
+ metadata: JobFeedbackMetadata & Record<string, unknown>;
503
+ createdAt: number;
504
+ updatedAt: number;
505
+ }
461
506
  /**
462
507
  * Result from submitting a job
463
508
  */
@@ -474,6 +519,8 @@ interface Job {
474
519
  status: JobStatus;
475
520
  /** Promise that resolves with the job result */
476
521
  result: Promise<unknown>;
522
+ /** Attach user feedback to this job and persist it with job/session metadata */
523
+ leaveFeedback(input: JobFeedbackInput): Promise<JobFeedbackRecord>;
477
524
  /** Subscribe to job events */
478
525
  on(event: string, handler: (data: unknown) => void): void;
479
526
  }
@@ -677,6 +724,58 @@ interface RecordObjectResult {
677
724
  /** Whether the instance was newly created (false = updated) */
678
725
  created: boolean;
679
726
  }
727
+ type RecordImportStatus = 'queued' | 'processing' | 'completed' | 'failed' | 'canceled';
728
+ type RecordImportItemStatus = 'queued' | 'processing' | 'completed' | 'failed' | 'canceled';
729
+ interface RecordImportStats {
730
+ totalRecords: number;
731
+ queuedRecords: number;
732
+ processingRecords: number;
733
+ completedRecords: number;
734
+ failedRecords: number;
735
+ canceledRecords: number;
736
+ awaitingRecords: number;
737
+ }
738
+ interface RecordImportItem {
739
+ itemId: string;
740
+ importId: string;
741
+ tenantId: string;
742
+ environmentId: string;
743
+ className: string;
744
+ id: string;
745
+ label: string | null;
746
+ fields: Record<string, string | number | boolean | null> | null;
747
+ relationships: Record<string, string | string[]> | null;
748
+ status: RecordImportItemStatus;
749
+ attempts: number;
750
+ errorMessage: string | null;
751
+ resultPath: string | null;
752
+ resultCreated: boolean | null;
753
+ createdAt: number;
754
+ updatedAt: number;
755
+ processedAt: number | null;
756
+ }
757
+ interface RecordImport {
758
+ importId: string;
759
+ tenantId: string;
760
+ environmentId: string;
761
+ sandboxId: string;
762
+ subjectId: string;
763
+ status: RecordImportStatus;
764
+ batchSize: number;
765
+ errorMessage: string | null;
766
+ createdAt: number;
767
+ updatedAt: number;
768
+ startedAt: number | null;
769
+ finishedAt: number | null;
770
+ canceledAt: number | null;
771
+ stats: RecordImportStats;
772
+ }
773
+ interface EnvironmentRecordImportSummary extends RecordImportStats {
774
+ environmentId: string;
775
+ totalImports: number;
776
+ activeImports: number;
777
+ updatedAt: number;
778
+ }
680
779
  /**
681
780
  * Property specification in a manifest operation
682
781
  */
@@ -815,6 +914,7 @@ declare class WSClient {
815
914
  private isExplicitlyDisconnected;
816
915
  private options;
817
916
  constructor(options: WSClientOptions);
917
+ get currentSessionId(): string;
818
918
  private clearTokenRefreshTimer;
819
919
  private decodeBase64Url;
820
920
  private getTokenExpiryMs;
@@ -887,6 +987,7 @@ declare class Session {
887
987
  private extractDomainRevisionFromDoc;
888
988
  private buildLegacyEffectContext;
889
989
  get document(): Doc<Record<string, unknown>>;
990
+ get sessionId(): string;
890
991
  get domainRevision(): string | null;
891
992
  /**
892
993
  * Make a raw RPC call to the session's Durable Object.
@@ -1058,6 +1159,7 @@ declare class Environment extends Session {
1058
1159
  */
1059
1160
  getHeap(): SessionHeapSnapshot;
1060
1161
  private getRuntimeBaseUrl;
1162
+ private controlPlaneRequest;
1061
1163
  /**
1062
1164
  * Close the session and disconnect from the sandbox.
1063
1165
  *
@@ -1315,6 +1417,39 @@ declare class Environment extends Session {
1315
1417
  * ```
1316
1418
  */
1317
1419
  recordObject(options: RecordObjectOptions): Promise<RecordObjectResult>;
1420
+ /**
1421
+ * Batch version of `recordObject()`.
1422
+ *
1423
+ * Sends several upserts through the control-plane batch endpoint so the
1424
+ * server can collapse the graph mutations into far fewer round trips.
1425
+ */
1426
+ recordObjects(records: RecordObjectOptions[]): Promise<RecordObjectResult[]>;
1427
+ /**
1428
+ * Queue a background record import for this environment.
1429
+ */
1430
+ enqueueRecordImport(records: RecordObjectOptions[], options?: {
1431
+ batchSize?: number;
1432
+ }): Promise<RecordImport>;
1433
+ /**
1434
+ * List queued or completed record imports for this environment.
1435
+ */
1436
+ listRecordImports(status?: RecordImportStatus): Promise<RecordImport[]>;
1437
+ /**
1438
+ * Fetch the latest aggregate import counters for this environment.
1439
+ */
1440
+ getRecordImportSummary(): Promise<EnvironmentRecordImportSummary>;
1441
+ /**
1442
+ * Convenience helper returning queued + processing records for this environment.
1443
+ */
1444
+ getAwaitingRecordCount(): Promise<number>;
1445
+ /**
1446
+ * Fetch a single record import by id.
1447
+ */
1448
+ getRecordImport(importId: string): Promise<RecordImport>;
1449
+ /**
1450
+ * Cancel a queued/background record import.
1451
+ */
1452
+ cancelRecordImport(importId: string): Promise<RecordImport>;
1318
1453
  /**
1319
1454
  * Removed: environment-scoped effect publication is no longer supported.
1320
1455
  */
@@ -1514,4 +1649,4 @@ declare class Granular {
1514
1649
  private request;
1515
1650
  }
1516
1651
 
1517
- 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 };
1652
+ 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 };