@valon-technologies/gestalt 0.0.1-alpha.16 → 0.0.1-alpha.18

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/src/s3.ts CHANGED
@@ -26,14 +26,17 @@ import {
26
26
  type S3ObjectMeta as ProtoS3ObjectMeta,
27
27
  type S3ObjectRef as ProtoS3ObjectRef,
28
28
  WriteObjectResponseSchema,
29
- } from "../gen/v1/s3_pb.ts";
29
+ } from "./internal/gen/v1/s3_pb.ts";
30
30
  import { errorMessage, type MaybePromise } from "./api.ts";
31
31
  import { RuntimeProvider, type RuntimeProviderOptions } from "./provider.ts";
32
32
 
33
+ /** Base environment variable for discovering S3 runtime sockets. */
33
34
  export const ENV_S3_SOCKET = "GESTALT_S3_SOCKET";
34
35
  const S3_SOCKET_TOKEN_SUFFIX = "_TOKEN";
35
36
  const S3_RELAY_TOKEN_HEADER = "x-gestalt-host-service-relay-token";
36
- export const ENV_S3_SOCKET_TOKEN = `${ENV_S3_SOCKET}${S3_SOCKET_TOKEN_SUFFIX}`;
37
+ /** Base environment variable for the default S3 relay token. */
38
+ export const ENV_S3_SOCKET_TOKEN =
39
+ `${ENV_S3_SOCKET}${S3_SOCKET_TOKEN_SUFFIX}`;
37
40
  const WRITE_CHUNK_SIZE = 64 * 1024;
38
41
  const textEncoder = new TextEncoder();
39
42
 
@@ -288,14 +291,20 @@ export class S3Provider extends RuntimeProvider {
288
291
  this.presignObjectHandler = options.presignObject;
289
292
  }
290
293
 
294
+ /** Fetches object metadata without reading the object body. */
291
295
  async headObject(ref: ObjectRef): Promise<ObjectMeta> {
292
296
  return await this.headObjectHandler(ref);
293
297
  }
294
298
 
295
- async readObject(ref: ObjectRef, options?: ReadOptions): Promise<ProviderReadResult> {
299
+ /** Reads an object body from the provider implementation. */
300
+ async readObject(
301
+ ref: ObjectRef,
302
+ options?: ReadOptions,
303
+ ): Promise<ProviderReadResult> {
296
304
  return await this.readObjectHandler(ref, options);
297
305
  }
298
306
 
307
+ /** Writes an object body through the provider implementation. */
299
308
  async writeObject(
300
309
  ref: ObjectRef,
301
310
  body: AsyncIterable<Uint8Array>,
@@ -304,14 +313,17 @@ export class S3Provider extends RuntimeProvider {
304
313
  return await this.writeObjectHandler(ref, body, options);
305
314
  }
306
315
 
316
+ /** Deletes an object from the provider implementation. */
307
317
  async deleteObject(ref: ObjectRef): Promise<void> {
308
318
  await this.deleteObjectHandler(ref);
309
319
  }
310
320
 
321
+ /** Lists objects from the provider implementation. */
311
322
  async listObjects(options: ListOptions): Promise<ListPage> {
312
323
  return await this.listObjectsHandler(options);
313
324
  }
314
325
 
326
+ /** Copies an object in the provider implementation. */
315
327
  async copyObject(
316
328
  source: ObjectRef,
317
329
  destination: ObjectRef,
@@ -320,7 +332,11 @@ export class S3Provider extends RuntimeProvider {
320
332
  return await this.copyObjectHandler(source, destination, options);
321
333
  }
322
334
 
323
- async presignObject(ref: ObjectRef, options?: PresignOptions): Promise<PresignResult> {
335
+ /** Generates a presigned URL from the provider implementation. */
336
+ async presignObject(
337
+ ref: ObjectRef,
338
+ options?: PresignOptions,
339
+ ): Promise<PresignResult> {
324
340
  return await this.presignObjectHandler(ref, options);
325
341
  }
326
342
  }
@@ -545,7 +561,8 @@ export class S3 {
545
561
  ...(transportOptions.nodeOptions
546
562
  ? {
547
563
  nodeOptions: {
548
- createConnection: () => connect(transportOptions.nodeOptions!.path),
564
+ createConnection: () =>
565
+ connect({ path: transportOptions.nodeOptions!.path }),
549
566
  },
550
567
  }
551
568
  : {}),
@@ -555,14 +572,17 @@ export class S3 {
555
572
  this.client = createClient(S3Service, transport);
556
573
  }
557
574
 
575
+ /** Returns a convenience helper for the latest version of an object. */
558
576
  object(bucket: string, key: string): S3Object {
559
577
  return new S3Object(this, { bucket, key });
560
578
  }
561
579
 
580
+ /** Returns a convenience helper pinned to a specific object version. */
562
581
  objectVersion(bucket: string, key: string, versionId: string): S3Object {
563
582
  return new S3Object(this, { bucket, key, versionId });
564
583
  }
565
584
 
585
+ /** Fetches object metadata without reading the object body. */
566
586
  async headObject(ref: ObjectRef): Promise<ObjectMeta> {
567
587
  const response = await s3Rpc(() =>
568
588
  this.client.headObject({
@@ -572,6 +592,7 @@ export class S3 {
572
592
  return fromProtoObjectMeta(response.meta);
573
593
  }
574
594
 
595
+ /** Opens a streaming read for an object. */
575
596
  async readObject(ref: ObjectRef, options?: ReadOptions): Promise<ReadResult> {
576
597
  const response = this.client.readObject({
577
598
  ref: toProtoObjectRef(ref),
@@ -588,6 +609,7 @@ export class S3 {
588
609
  };
589
610
  }
590
611
 
612
+ /** Writes an object body and returns the resulting metadata. */
591
613
  async writeObject(
592
614
  ref: ObjectRef,
593
615
  body?: S3BodySource,
@@ -601,6 +623,7 @@ export class S3 {
601
623
  return fromProtoObjectMeta(response.meta);
602
624
  }
603
625
 
626
+ /** Deletes an object. */
604
627
  async deleteObject(ref: ObjectRef): Promise<void> {
605
628
  await s3Rpc(() =>
606
629
  this.client.deleteObject({
@@ -609,6 +632,7 @@ export class S3 {
609
632
  );
610
633
  }
611
634
 
635
+ /** Lists objects within a bucket. */
612
636
  async listObjects(options: ListOptions): Promise<ListPage> {
613
637
  const response = await s3Rpc(() =>
614
638
  this.client.listObjects({
@@ -628,6 +652,7 @@ export class S3 {
628
652
  };
629
653
  }
630
654
 
655
+ /** Copies an object and returns metadata for the destination. */
631
656
  async copyObject(
632
657
  source: ObjectRef,
633
658
  destination: ObjectRef,
@@ -644,7 +669,11 @@ export class S3 {
644
669
  return fromProtoObjectMeta(response.meta);
645
670
  }
646
671
 
647
- async presignObject(ref: ObjectRef, options?: PresignOptions): Promise<PresignResult> {
672
+ /** Generates a presigned URL for an object operation. */
673
+ async presignObject(
674
+ ref: ObjectRef,
675
+ options?: PresignOptions,
676
+ ): Promise<PresignResult> {
648
677
  const requestedMethod = options?.method ?? PresignMethod.Get;
649
678
  const response = await s3Rpc(() =>
650
679
  this.client.presignObject({
@@ -669,6 +698,7 @@ export class S3 {
669
698
  return result;
670
699
  }
671
700
 
701
+ /** Creates a host-mediated object access URL. */
672
702
  async createObjectAccessURL(
673
703
  ref: ObjectRef,
674
704
  options?: ObjectAccessURLOptions,
@@ -704,6 +734,7 @@ export class S3 {
704
734
  return this.objectAccessClient;
705
735
  }
706
736
 
737
+ /** Alias for `createObjectAccessURL`. */
707
738
  async createObjectAccessUrl(
708
739
  ref: ObjectRef,
709
740
  options?: ObjectAccessURLOptions,
@@ -711,6 +742,7 @@ export class S3 {
711
742
  return await this.createObjectAccessURL(ref, options);
712
743
  }
713
744
 
745
+ /** Alias for `createObjectAccessURL`. */
714
746
  async createAccessURL(
715
747
  ref: ObjectRef,
716
748
  options?: ObjectAccessURLOptions,
@@ -718,6 +750,7 @@ export class S3 {
718
750
  return await this.createObjectAccessURL(ref, options);
719
751
  }
720
752
 
753
+ /** Alias for `createObjectAccessURL`. */
721
754
  async createAccessUrl(
722
755
  ref: ObjectRef,
723
756
  options?: ObjectAccessURLOptions,
@@ -846,7 +879,10 @@ export class S3Object {
846
879
  return await this.client.createObjectAccessURL(this.ref, options);
847
880
  }
848
881
 
849
- async createAccessUrl(options?: ObjectAccessURLOptions): Promise<ObjectAccessURL> {
882
+ /** Alias for `createAccessURL`. */
883
+ async createAccessUrl(
884
+ options?: ObjectAccessURLOptions,
885
+ ): Promise<ObjectAccessURL> {
850
886
  return await this.createAccessURL(options);
851
887
  }
852
888
  }
@@ -0,0 +1,43 @@
1
+ import { create } from "@bufbuild/protobuf";
2
+
3
+ import {
4
+ AgentHost as AgentHostService,
5
+ AgentProvider as AgentProviderService,
6
+ CancelAgentProviderTurnRequestSchema,
7
+ CreateAgentProviderSessionRequestSchema,
8
+ CreateAgentProviderTurnRequestSchema,
9
+ ExecuteAgentToolResponseSchema,
10
+ GetAgentProviderCapabilitiesRequestSchema,
11
+ GetAgentProviderSessionRequestSchema,
12
+ GetAgentProviderTurnRequestSchema,
13
+ ListAgentProviderTurnEventsRequestSchema,
14
+ ListAgentToolsResponseSchema,
15
+ ListedAgentToolSchema,
16
+ } from "./internal/gen/v1/agent_pb.ts";
17
+
18
+ export const agentContractServices: Record<string, unknown> = {
19
+ AgentHost: AgentHostService,
20
+ AgentHostService,
21
+ AgentProvider: AgentProviderService,
22
+ AgentProviderService,
23
+ };
24
+
25
+ export const agentContractSchemas: Record<string, unknown> = {
26
+ CancelAgentProviderTurnRequestSchema,
27
+ CreateAgentProviderSessionRequestSchema,
28
+ CreateAgentProviderTurnRequestSchema,
29
+ ExecuteAgentToolResponseSchema,
30
+ GetAgentProviderCapabilitiesRequestSchema,
31
+ GetAgentProviderSessionRequestSchema,
32
+ GetAgentProviderTurnRequestSchema,
33
+ ListAgentProviderTurnEventsRequestSchema,
34
+ ListAgentToolsResponseSchema,
35
+ ListedAgentToolSchema,
36
+ };
37
+
38
+ export function createAgentContractMessage<T = unknown>(
39
+ schema: unknown,
40
+ input: Record<string, unknown>,
41
+ ): T {
42
+ return create(schema as never, input as never) as T;
43
+ }
@@ -24,57 +24,84 @@ import {
24
24
  type ManagedWorkflowSchedule,
25
25
  type ManagedWorkflowEventTrigger,
26
26
  type WorkflowEvent,
27
- } from "../gen/v1/workflow_pb.ts";
27
+ } from "./internal/gen/v1/workflow_pb.ts";
28
28
  import type { Request } from "./api.ts";
29
29
 
30
+ /** Environment variable containing the workflow-manager host-service target. */
30
31
  export const ENV_WORKFLOW_MANAGER_SOCKET = "GESTALT_WORKFLOW_MANAGER_SOCKET";
31
- export const ENV_WORKFLOW_MANAGER_SOCKET_TOKEN = `${ENV_WORKFLOW_MANAGER_SOCKET}_TOKEN`;
32
+ /** Environment variable containing the optional workflow-manager relay token. */
33
+ export const ENV_WORKFLOW_MANAGER_SOCKET_TOKEN =
34
+ `${ENV_WORKFLOW_MANAGER_SOCKET}_TOKEN`;
32
35
  const WORKFLOW_MANAGER_RELAY_TOKEN_HEADER =
33
36
  "x-gestalt-host-service-relay-token";
34
37
 
38
+ /** Managed workflow schedule message returned by the host manager. */
35
39
  export type ManagedWorkflowScheduleMessage = ManagedWorkflowSchedule;
40
+ /** Managed workflow event-trigger message returned by the host manager. */
36
41
  export type ManagedWorkflowEventTriggerMessage = ManagedWorkflowEventTrigger;
42
+ /** Workflow event message returned after publishing an event. */
37
43
  export type WorkflowEventMessage = WorkflowEvent;
44
+ /** Shape accepted when creating a workflow schedule. */
38
45
  export type WorkflowManagerCreateScheduleInput = MessageInitShape<
39
46
  typeof WorkflowManagerCreateScheduleRequestSchema
40
47
  >;
48
+ /** Shape accepted when creating an event trigger. */
41
49
  export type WorkflowManagerCreateTriggerInput = MessageInitShape<
42
50
  typeof WorkflowManagerCreateEventTriggerRequestSchema
43
51
  >;
52
+ /** Shape accepted when fetching a workflow schedule. */
44
53
  export type WorkflowManagerGetScheduleInput = MessageInitShape<
45
54
  typeof WorkflowManagerGetScheduleRequestSchema
46
55
  >;
56
+ /** Shape accepted when fetching an event trigger. */
47
57
  export type WorkflowManagerGetTriggerInput = MessageInitShape<
48
58
  typeof WorkflowManagerGetEventTriggerRequestSchema
49
59
  >;
60
+ /** Shape accepted when updating a workflow schedule. */
50
61
  export type WorkflowManagerUpdateScheduleInput = MessageInitShape<
51
62
  typeof WorkflowManagerUpdateScheduleRequestSchema
52
63
  >;
64
+ /** Shape accepted when updating an event trigger. */
53
65
  export type WorkflowManagerUpdateTriggerInput = MessageInitShape<
54
66
  typeof WorkflowManagerUpdateEventTriggerRequestSchema
55
67
  >;
68
+ /** Shape accepted when deleting a workflow schedule. */
56
69
  export type WorkflowManagerDeleteScheduleInput = MessageInitShape<
57
70
  typeof WorkflowManagerDeleteScheduleRequestSchema
58
71
  >;
72
+ /** Shape accepted when deleting an event trigger. */
59
73
  export type WorkflowManagerDeleteTriggerInput = MessageInitShape<
60
74
  typeof WorkflowManagerDeleteEventTriggerRequestSchema
61
75
  >;
76
+ /** Shape accepted when pausing a workflow schedule. */
62
77
  export type WorkflowManagerPauseScheduleInput = MessageInitShape<
63
78
  typeof WorkflowManagerPauseScheduleRequestSchema
64
79
  >;
80
+ /** Shape accepted when pausing an event trigger. */
65
81
  export type WorkflowManagerPauseTriggerInput = MessageInitShape<
66
82
  typeof WorkflowManagerPauseEventTriggerRequestSchema
67
83
  >;
84
+ /** Shape accepted when resuming a workflow schedule. */
68
85
  export type WorkflowManagerResumeScheduleInput = MessageInitShape<
69
86
  typeof WorkflowManagerResumeScheduleRequestSchema
70
87
  >;
88
+ /** Shape accepted when resuming an event trigger. */
71
89
  export type WorkflowManagerResumeTriggerInput = MessageInitShape<
72
90
  typeof WorkflowManagerResumeEventTriggerRequestSchema
73
91
  >;
92
+ /** Shape accepted when publishing a workflow event. */
74
93
  export type WorkflowManagerPublishEventInput = MessageInitShape<
75
94
  typeof WorkflowManagerPublishEventRequestSchema
76
95
  >;
77
96
 
97
+ /**
98
+ * Client for creating and controlling workflow schedules and event triggers.
99
+ *
100
+ * The constructor accepts either a Gestalt request or an invocation token. Each
101
+ * manager call forwards that token to the host service. When constructed from a
102
+ * request, create operations reuse the request idempotency key unless the call
103
+ * provides one explicitly.
104
+ */
78
105
  export class WorkflowManager {
79
106
  private readonly client: Client<typeof WorkflowManagerHostService>;
80
107
  private readonly invocationToken: string;
@@ -104,6 +131,7 @@ export class WorkflowManager {
104
131
  this.client = createClient(WorkflowManagerHostService, transport);
105
132
  }
106
133
 
134
+ /** Creates a workflow schedule. */
107
135
  async createSchedule(
108
136
  request: WorkflowManagerCreateScheduleInput,
109
137
  ): Promise<ManagedWorkflowScheduleMessage> {
@@ -114,6 +142,7 @@ export class WorkflowManager {
114
142
  });
115
143
  }
116
144
 
145
+ /** Fetches one workflow schedule. */
117
146
  async getSchedule(
118
147
  request: WorkflowManagerGetScheduleInput,
119
148
  ): Promise<ManagedWorkflowScheduleMessage> {
@@ -123,6 +152,7 @@ export class WorkflowManager {
123
152
  });
124
153
  }
125
154
 
155
+ /** Updates a workflow schedule. */
126
156
  async updateSchedule(
127
157
  request: WorkflowManagerUpdateScheduleInput,
128
158
  ): Promise<ManagedWorkflowScheduleMessage> {
@@ -132,6 +162,7 @@ export class WorkflowManager {
132
162
  });
133
163
  }
134
164
 
165
+ /** Deletes a workflow schedule. */
135
166
  async deleteSchedule(
136
167
  request: WorkflowManagerDeleteScheduleInput,
137
168
  ): Promise<void> {
@@ -141,6 +172,7 @@ export class WorkflowManager {
141
172
  });
142
173
  }
143
174
 
175
+ /** Pauses a workflow schedule. */
144
176
  async pauseSchedule(
145
177
  request: WorkflowManagerPauseScheduleInput,
146
178
  ): Promise<ManagedWorkflowScheduleMessage> {
@@ -150,6 +182,7 @@ export class WorkflowManager {
150
182
  });
151
183
  }
152
184
 
185
+ /** Resumes a workflow schedule. */
153
186
  async resumeSchedule(
154
187
  request: WorkflowManagerResumeScheduleInput,
155
188
  ): Promise<ManagedWorkflowScheduleMessage> {
@@ -159,6 +192,7 @@ export class WorkflowManager {
159
192
  });
160
193
  }
161
194
 
195
+ /** Creates an event trigger. */
162
196
  async createTrigger(
163
197
  request: WorkflowManagerCreateTriggerInput,
164
198
  ): Promise<ManagedWorkflowEventTriggerMessage> {
@@ -169,6 +203,7 @@ export class WorkflowManager {
169
203
  });
170
204
  }
171
205
 
206
+ /** Fetches one event trigger. */
172
207
  async getTrigger(
173
208
  request: WorkflowManagerGetTriggerInput,
174
209
  ): Promise<ManagedWorkflowEventTriggerMessage> {
@@ -178,6 +213,7 @@ export class WorkflowManager {
178
213
  });
179
214
  }
180
215
 
216
+ /** Updates an event trigger. */
181
217
  async updateTrigger(
182
218
  request: WorkflowManagerUpdateTriggerInput,
183
219
  ): Promise<ManagedWorkflowEventTriggerMessage> {
@@ -187,6 +223,7 @@ export class WorkflowManager {
187
223
  });
188
224
  }
189
225
 
226
+ /** Deletes an event trigger. */
190
227
  async deleteTrigger(
191
228
  request: WorkflowManagerDeleteTriggerInput,
192
229
  ): Promise<void> {
@@ -196,6 +233,7 @@ export class WorkflowManager {
196
233
  });
197
234
  }
198
235
 
236
+ /** Pauses an event trigger. */
199
237
  async pauseTrigger(
200
238
  request: WorkflowManagerPauseTriggerInput,
201
239
  ): Promise<ManagedWorkflowEventTriggerMessage> {
@@ -205,6 +243,7 @@ export class WorkflowManager {
205
243
  });
206
244
  }
207
245
 
246
+ /** Resumes an event trigger. */
208
247
  async resumeTrigger(
209
248
  request: WorkflowManagerResumeTriggerInput,
210
249
  ): Promise<ManagedWorkflowEventTriggerMessage> {
@@ -214,6 +253,7 @@ export class WorkflowManager {
214
253
  });
215
254
  }
216
255
 
256
+ /** Publishes an event into the workflow manager. */
217
257
  async publishEvent(
218
258
  request: WorkflowManagerPublishEventInput,
219
259
  ): Promise<WorkflowEventMessage> {
package/src/workflow.ts CHANGED
@@ -44,12 +44,19 @@ import {
44
44
  type UpsertWorkflowProviderScheduleRequest,
45
45
  type WorkflowEvent,
46
46
  WorkflowRunStatus,
47
- } from "../gen/v1/workflow_pb.ts";
47
+ } from "./internal/gen/v1/workflow_pb.ts";
48
48
  import { errorMessage, type MaybePromise } from "./api.ts";
49
49
  import { RuntimeProvider, type RuntimeProviderOptions } from "./provider.ts";
50
50
 
51
+ /** Environment variable containing the workflow-host service socket path. */
51
52
  export const ENV_WORKFLOW_HOST_SOCKET = "GESTALT_WORKFLOW_HOST_SOCKET";
52
53
 
54
+ /**
55
+ * Generated workflow protocol message types commonly used by providers.
56
+ *
57
+ * These are re-exported so workflow provider code can type runs, schedules,
58
+ * triggers, and operation-invocation requests without importing from `gen`.
59
+ */
53
60
  export type {
54
61
  BoundWorkflowEventTrigger,
55
62
  BoundWorkflowRun,
@@ -77,6 +84,7 @@ export type {
77
84
  };
78
85
  export { WorkflowRunStatus };
79
86
 
87
+ /** Handlers and runtime metadata for a workflow provider. */
80
88
  export interface WorkflowProviderOptions extends RuntimeProviderOptions {
81
89
  startRun: (
82
90
  request: StartWorkflowProviderRunRequest,
@@ -131,6 +139,7 @@ export interface WorkflowProviderOptions extends RuntimeProviderOptions {
131
139
  ) => MaybePromise<void>;
132
140
  }
133
141
 
142
+ /** Runtime provider implementation for the Gestalt workflow host contract. */
134
143
  export class WorkflowProvider extends RuntimeProvider {
135
144
  readonly kind = "workflow" as const;
136
145
 
@@ -276,12 +285,14 @@ export class WorkflowProvider extends RuntimeProvider {
276
285
  }
277
286
  }
278
287
 
288
+ /** Creates a workflow provider for export from a provider module. */
279
289
  export function defineWorkflowProvider(
280
290
  options: WorkflowProviderOptions,
281
291
  ): WorkflowProvider {
282
292
  return new WorkflowProvider(options);
283
293
  }
284
294
 
295
+ /** Runtime type guard for workflow providers loaded from user modules. */
285
296
  export function isWorkflowProvider(value: unknown): value is WorkflowProvider {
286
297
  return (
287
298
  value instanceof WorkflowProvider ||
@@ -309,6 +320,7 @@ export function isWorkflowProvider(value: unknown): value is WorkflowProvider {
309
320
  );
310
321
  }
311
322
 
323
+ /** Client for invoking operations from workflow provider code. */
312
324
  export class WorkflowHost {
313
325
  private readonly client: Client<typeof WorkflowHostService>;
314
326
 
@@ -320,12 +332,13 @@ export class WorkflowHost {
320
332
  const transport = createGrpcTransport({
321
333
  baseUrl: "http://localhost",
322
334
  nodeOptions: {
323
- createConnection: () => connect(socketPath),
335
+ createConnection: () => connect({ path: socketPath }),
324
336
  },
325
337
  });
326
338
  this.client = createClient(WorkflowHostService, transport);
327
339
  }
328
340
 
341
+ /** Invokes an operation through the workflow host service. */
329
342
  async invokeOperation(
330
343
  request: InvokeWorkflowOperationRequest,
331
344
  ): Promise<InvokeWorkflowOperationResponse> {
@@ -333,6 +346,7 @@ export class WorkflowHost {
333
346
  }
334
347
  }
335
348
 
349
+ /** Builds the Connect service implementation used by the TypeScript runtime. */
336
350
  export function createWorkflowProviderService(
337
351
  provider: WorkflowProvider,
338
352
  ): Partial<ServiceImpl<typeof WorkflowProviderService>> {
package/tsconfig.json CHANGED
@@ -18,6 +18,6 @@
18
18
  "docs/entrypoints/**/*.ts",
19
19
  "src/**/*.ts",
20
20
  "tests/**/*.ts",
21
- "gen/**/*.ts"
21
+ "src/internal/gen/**/*.ts"
22
22
  ]
23
23
  }