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

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.
@@ -1,4 +1,3 @@
1
- import type { MessageInitShape } from "@bufbuild/protobuf";
2
1
  import {
3
2
  createClient,
4
3
  type Client,
@@ -7,24 +6,41 @@ import {
7
6
  import { createGrpcTransport } from "@connectrpc/connect-node";
8
7
 
9
8
  import {
10
- AgentManagerCancelTurnRequestSchema,
11
- AgentManagerCreateSessionRequestSchema,
12
- AgentManagerCreateTurnRequestSchema,
13
- AgentManagerGetSessionRequestSchema,
14
- AgentManagerGetTurnRequestSchema,
15
9
  AgentManagerHost as AgentManagerHostService,
16
- AgentManagerListInteractionsRequestSchema,
17
- AgentManagerListSessionsRequestSchema,
18
- AgentManagerListTurnEventsRequestSchema,
19
- AgentManagerListTurnsRequestSchema,
20
- AgentManagerResolveInteractionRequestSchema,
21
- AgentManagerUpdateSessionRequestSchema,
10
+ type AgentInteraction as ProtoAgentInteraction,
11
+ type AgentSession as ProtoAgentSession,
12
+ type AgentTurn as ProtoAgentTurn,
13
+ type AgentTurnEvent as ProtoAgentTurnEvent,
14
+ } from "./internal/gen/v1/agent_pb.ts";
15
+ import type { Request } from "./api.ts";
16
+ import {
17
+ agentActorFromProto,
18
+ agentMessageFromProto,
19
+ agentMessageToProto,
20
+ agentToolRefToProto,
21
+ agentTurnDisplayFromProto,
22
+ } from "./agent-conversions.ts";
23
+ import {
24
+ AgentExecutionStatus,
25
+ AgentInteractionState,
26
+ AgentInteractionType,
27
+ AgentSessionState,
28
+ AgentToolSourceMode,
22
29
  type AgentInteraction,
30
+ type AgentMessage,
23
31
  type AgentSession,
32
+ type AgentToolRef,
24
33
  type AgentTurn,
25
34
  type AgentTurnEvent,
26
- } from "./internal/gen/v1/agent_pb.ts";
27
- import type { Request } from "./api.ts";
35
+ } from "./agent.ts";
36
+ import {
37
+ dateFromTimestamp,
38
+ type JsonObjectInput,
39
+ } from "./protocol.ts";
40
+ import {
41
+ optionalObjectFromStruct,
42
+ optionalStruct,
43
+ } from "./protocol-internal.ts";
28
44
 
29
45
  /** Environment variable containing the agent-manager host-service target. */
30
46
  export const ENV_AGENT_MANAGER_SOCKET = "GESTALT_AGENT_MANAGER_SOCKET";
@@ -33,50 +49,98 @@ export const ENV_AGENT_MANAGER_SOCKET_TOKEN =
33
49
  `${ENV_AGENT_MANAGER_SOCKET}_TOKEN`;
34
50
  const AGENT_MANAGER_RELAY_TOKEN_HEADER = "x-gestalt-host-service-relay-token";
35
51
 
52
+ export interface AgentManagerWorkspaceGitCheckout {
53
+ url?: string | undefined;
54
+ ref?: string | undefined;
55
+ path?: string | undefined;
56
+ }
57
+
58
+ export interface AgentManagerWorkspace {
59
+ checkouts?: readonly AgentManagerWorkspaceGitCheckout[] | undefined;
60
+ cwd?: string | undefined;
61
+ }
62
+
36
63
  /** Shape accepted when creating an agent session through the host manager. */
37
- export type AgentManagerCreateSessionInput = MessageInitShape<
38
- typeof AgentManagerCreateSessionRequestSchema
39
- >;
64
+ export interface AgentManagerCreateSessionInput {
65
+ providerName: string;
66
+ model?: string | undefined;
67
+ clientRef?: string | undefined;
68
+ metadata?: JsonObjectInput | undefined;
69
+ idempotencyKey?: string | undefined;
70
+ workspace?: AgentManagerWorkspace | undefined;
71
+ }
72
+
40
73
  /** Shape accepted when fetching an agent session through the host manager. */
41
- export type AgentManagerGetSessionInput = MessageInitShape<
42
- typeof AgentManagerGetSessionRequestSchema
43
- >;
74
+ export interface AgentManagerGetSessionInput {
75
+ sessionId: string;
76
+ }
77
+
44
78
  /** Shape accepted when listing agent sessions through the host manager. */
45
- export type AgentManagerListSessionsInput = MessageInitShape<
46
- typeof AgentManagerListSessionsRequestSchema
47
- >;
79
+ export interface AgentManagerListSessionsInput {
80
+ providerName?: string | undefined;
81
+ state?: AgentSessionState | undefined;
82
+ limit?: number | undefined;
83
+ summaryOnly?: boolean | undefined;
84
+ }
85
+
48
86
  /** Shape accepted when updating an agent session through the host manager. */
49
- export type AgentManagerUpdateSessionInput = MessageInitShape<
50
- typeof AgentManagerUpdateSessionRequestSchema
51
- >;
87
+ export interface AgentManagerUpdateSessionInput {
88
+ sessionId: string;
89
+ clientRef?: string | undefined;
90
+ state?: AgentSessionState | undefined;
91
+ metadata?: JsonObjectInput | undefined;
92
+ }
93
+
52
94
  /** Shape accepted when creating an agent turn through the host manager. */
53
- export type AgentManagerCreateTurnInput = MessageInitShape<
54
- typeof AgentManagerCreateTurnRequestSchema
55
- >;
95
+ export interface AgentManagerCreateTurnInput {
96
+ sessionId: string;
97
+ model?: string | undefined;
98
+ messages?: readonly AgentMessage[] | undefined;
99
+ toolRefs?: readonly AgentToolRef[] | undefined;
100
+ toolSource?: AgentToolSourceMode | undefined;
101
+ responseSchema?: JsonObjectInput | undefined;
102
+ metadata?: JsonObjectInput | undefined;
103
+ idempotencyKey?: string | undefined;
104
+ modelOptions?: JsonObjectInput | undefined;
105
+ }
106
+
56
107
  /** Shape accepted when fetching an agent turn through the host manager. */
57
- export type AgentManagerGetTurnInput = MessageInitShape<
58
- typeof AgentManagerGetTurnRequestSchema
59
- >;
108
+ export interface AgentManagerGetTurnInput {
109
+ turnId: string;
110
+ }
111
+
60
112
  /** Shape accepted when listing agent turns through the host manager. */
61
- export type AgentManagerListTurnsInput = MessageInitShape<
62
- typeof AgentManagerListTurnsRequestSchema
63
- >;
113
+ export interface AgentManagerListTurnsInput {
114
+ sessionId: string;
115
+ status?: AgentExecutionStatus | undefined;
116
+ limit?: number | undefined;
117
+ summaryOnly?: boolean | undefined;
118
+ }
119
+
64
120
  /** Shape accepted when cancelling an agent turn through the host manager. */
65
- export type AgentManagerCancelTurnInput = MessageInitShape<
66
- typeof AgentManagerCancelTurnRequestSchema
67
- >;
121
+ export interface AgentManagerCancelTurnInput {
122
+ turnId: string;
123
+ reason?: string | undefined;
124
+ }
125
+
68
126
  /** Shape accepted when listing events for an agent turn. */
69
- export type AgentManagerListTurnEventsInput = MessageInitShape<
70
- typeof AgentManagerListTurnEventsRequestSchema
71
- >;
127
+ export interface AgentManagerListTurnEventsInput {
128
+ turnId: string;
129
+ afterSeq?: bigint | number | undefined;
130
+ limit?: number | undefined;
131
+ }
132
+
72
133
  /** Shape accepted when listing agent interactions. */
73
- export type AgentManagerListInteractionsInput = MessageInitShape<
74
- typeof AgentManagerListInteractionsRequestSchema
75
- >;
134
+ export interface AgentManagerListInteractionsInput {
135
+ turnId: string;
136
+ }
137
+
76
138
  /** Shape accepted when resolving an agent interaction. */
77
- export type AgentManagerResolveInteractionInput = MessageInitShape<
78
- typeof AgentManagerResolveInteractionRequestSchema
79
- >;
139
+ export interface AgentManagerResolveInteractionInput {
140
+ turnId: string;
141
+ interactionId: string;
142
+ resolution?: JsonObjectInput | undefined;
143
+ }
80
144
 
81
145
  /**
82
146
  * Client for managing agent sessions, turns, events, and interactions.
@@ -113,18 +177,27 @@ export class AgentManager {
113
177
  async createSession(
114
178
  request: AgentManagerCreateSessionInput,
115
179
  ): Promise<AgentSession> {
116
- return await this.client.createSession({
117
- ...request,
118
- invocationToken: this.invocationToken,
119
- });
180
+ return agentSessionFromProto(
181
+ await this.client.createSession({
182
+ providerName: request.providerName,
183
+ model: request.model ?? "",
184
+ clientRef: request.clientRef ?? "",
185
+ metadata: optionalStruct(request.metadata),
186
+ idempotencyKey: request.idempotencyKey ?? "",
187
+ invocationToken: this.invocationToken,
188
+ workspace: workspaceToProto(request.workspace),
189
+ }),
190
+ );
120
191
  }
121
192
 
122
193
  /** Fetches one agent session. */
123
194
  async getSession(request: AgentManagerGetSessionInput): Promise<AgentSession> {
124
- return await this.client.getSession({
125
- ...request,
126
- invocationToken: this.invocationToken,
127
- });
195
+ return agentSessionFromProto(
196
+ await this.client.getSession({
197
+ sessionId: request.sessionId,
198
+ invocationToken: this.invocationToken,
199
+ }),
200
+ );
128
201
  }
129
202
 
130
203
  /** Lists agent sessions visible to the invocation token. */
@@ -132,53 +205,79 @@ export class AgentManager {
132
205
  request: AgentManagerListSessionsInput = {},
133
206
  ): Promise<AgentSession[]> {
134
207
  const response = await this.client.listSessions({
135
- ...request,
208
+ providerName: request.providerName ?? "",
136
209
  invocationToken: this.invocationToken,
210
+ state: request.state ?? AgentSessionState.UNSPECIFIED,
211
+ limit: request.limit ?? 0,
212
+ summaryOnly: request.summaryOnly ?? false,
137
213
  });
138
- return [...response.sessions];
214
+ return response.sessions.map(agentSessionFromProto);
139
215
  }
140
216
 
141
217
  /** Updates mutable fields on an agent session. */
142
218
  async updateSession(
143
219
  request: AgentManagerUpdateSessionInput,
144
220
  ): Promise<AgentSession> {
145
- return await this.client.updateSession({
146
- ...request,
147
- invocationToken: this.invocationToken,
148
- });
221
+ return agentSessionFromProto(
222
+ await this.client.updateSession({
223
+ sessionId: request.sessionId,
224
+ clientRef: request.clientRef ?? "",
225
+ state: request.state ?? AgentSessionState.UNSPECIFIED,
226
+ metadata: optionalStruct(request.metadata),
227
+ invocationToken: this.invocationToken,
228
+ }),
229
+ );
149
230
  }
150
231
 
151
232
  /** Creates an agent turn. */
152
233
  async createTurn(request: AgentManagerCreateTurnInput): Promise<AgentTurn> {
153
- return await this.client.createTurn({
154
- ...request,
155
- invocationToken: this.invocationToken,
156
- });
234
+ return agentTurnFromProto(
235
+ await this.client.createTurn({
236
+ sessionId: request.sessionId,
237
+ model: request.model ?? "",
238
+ messages: request.messages?.map(agentMessageToProto) ?? [],
239
+ toolRefs: request.toolRefs?.map(agentToolRefToProto) ?? [],
240
+ toolSource: request.toolSource ?? AgentToolSourceMode.UNSPECIFIED,
241
+ responseSchema: optionalStruct(request.responseSchema),
242
+ metadata: optionalStruct(request.metadata),
243
+ idempotencyKey: request.idempotencyKey ?? "",
244
+ invocationToken: this.invocationToken,
245
+ modelOptions: optionalStruct(request.modelOptions),
246
+ }),
247
+ );
157
248
  }
158
249
 
159
250
  /** Fetches one agent turn. */
160
251
  async getTurn(request: AgentManagerGetTurnInput): Promise<AgentTurn> {
161
- return await this.client.getTurn({
162
- ...request,
163
- invocationToken: this.invocationToken,
164
- });
252
+ return agentTurnFromProto(
253
+ await this.client.getTurn({
254
+ turnId: request.turnId,
255
+ invocationToken: this.invocationToken,
256
+ }),
257
+ );
165
258
  }
166
259
 
167
260
  /** Lists turns for an agent session. */
168
261
  async listTurns(request: AgentManagerListTurnsInput): Promise<AgentTurn[]> {
169
262
  const response = await this.client.listTurns({
170
- ...request,
263
+ sessionId: request.sessionId,
171
264
  invocationToken: this.invocationToken,
265
+ status: request.status ?? AgentExecutionStatus.UNSPECIFIED,
266
+ limit: request.limit ?? 0,
267
+ summaryOnly: request.summaryOnly ?? false,
172
268
  });
173
- return [...response.turns];
269
+ return response.turns.map(agentTurnFromProto);
174
270
  }
175
271
 
176
272
  /** Cancels an in-progress agent turn. */
177
273
  async cancelTurn(request: AgentManagerCancelTurnInput): Promise<AgentTurn> {
178
- return await this.client.cancelTurn({
179
- ...request,
180
- invocationToken: this.invocationToken,
181
- });
274
+ return agentTurnFromProto(
275
+ await this.client.cancelTurn({
276
+ turnId: request.turnId,
277
+ reason: request.reason ?? "",
278
+ invocationToken: this.invocationToken,
279
+ }),
280
+ );
182
281
  }
183
282
 
184
283
  /** Lists events emitted for an agent turn. */
@@ -186,10 +285,12 @@ export class AgentManager {
186
285
  request: AgentManagerListTurnEventsInput,
187
286
  ): Promise<AgentTurnEvent[]> {
188
287
  const response = await this.client.listTurnEvents({
189
- ...request,
288
+ turnId: request.turnId,
289
+ afterSeq: BigInt(request.afterSeq ?? 0),
290
+ limit: request.limit ?? 0,
190
291
  invocationToken: this.invocationToken,
191
292
  });
192
- return [...response.events];
293
+ return response.events.map(agentTurnEventFromProto);
193
294
  }
194
295
 
195
296
  /** Lists pending or completed agent interactions. */
@@ -197,20 +298,24 @@ export class AgentManager {
197
298
  request: AgentManagerListInteractionsInput,
198
299
  ): Promise<AgentInteraction[]> {
199
300
  const response = await this.client.listInteractions({
200
- ...request,
301
+ turnId: request.turnId,
201
302
  invocationToken: this.invocationToken,
202
303
  });
203
- return [...response.interactions];
304
+ return response.interactions.map(agentInteractionFromProto);
204
305
  }
205
306
 
206
307
  /** Resolves an agent interaction with a host response. */
207
308
  async resolveInteraction(
208
309
  request: AgentManagerResolveInteractionInput,
209
310
  ): Promise<AgentInteraction> {
210
- return await this.client.resolveInteraction({
211
- ...request,
212
- invocationToken: this.invocationToken,
213
- });
311
+ return agentInteractionFromProto(
312
+ await this.client.resolveInteraction({
313
+ turnId: request.turnId,
314
+ interactionId: request.interactionId,
315
+ resolution: optionalStruct(request.resolution),
316
+ invocationToken: this.invocationToken,
317
+ }),
318
+ );
214
319
  }
215
320
  }
216
321
 
@@ -226,6 +331,90 @@ function normalizeInvocationToken(requestOrToken: Request | string): string {
226
331
  return trimmed;
227
332
  }
228
333
 
334
+ function workspaceToProto(workspace?: AgentManagerWorkspace | undefined) {
335
+ if (workspace === undefined) {
336
+ return undefined;
337
+ }
338
+ return {
339
+ checkouts: workspace.checkouts?.map((checkout) => ({
340
+ url: checkout.url ?? "",
341
+ ref: checkout.ref ?? "",
342
+ path: checkout.path ?? "",
343
+ })) ?? [],
344
+ cwd: workspace.cwd ?? "",
345
+ };
346
+ }
347
+
348
+ function agentSessionFromProto(session: ProtoAgentSession): AgentSession {
349
+ return {
350
+ id: session.id,
351
+ providerName: session.providerName,
352
+ model: session.model,
353
+ clientRef: session.clientRef,
354
+ state: session.state as AgentSessionState,
355
+ metadata: optionalObjectFromStruct(session.metadata),
356
+ createdBy: agentActorFromProto(session.createdBy),
357
+ createdAt: optionalDate(session.createdAt),
358
+ updatedAt: optionalDate(session.updatedAt),
359
+ lastTurnAt: optionalDate(session.lastTurnAt),
360
+ };
361
+ }
362
+
363
+ function agentTurnFromProto(turn: ProtoAgentTurn): AgentTurn {
364
+ return {
365
+ id: turn.id,
366
+ sessionId: turn.sessionId,
367
+ providerName: turn.providerName,
368
+ model: turn.model,
369
+ status: turn.status as AgentExecutionStatus,
370
+ messages: turn.messages.map(agentMessageFromProto),
371
+ outputText: turn.outputText,
372
+ structuredOutput: optionalObjectFromStruct(turn.structuredOutput),
373
+ statusMessage: turn.statusMessage,
374
+ createdBy: agentActorFromProto(turn.createdBy),
375
+ createdAt: optionalDate(turn.createdAt),
376
+ startedAt: optionalDate(turn.startedAt),
377
+ completedAt: optionalDate(turn.completedAt),
378
+ executionRef: turn.executionRef,
379
+ };
380
+ }
381
+
382
+ function agentTurnEventFromProto(event: ProtoAgentTurnEvent): AgentTurnEvent {
383
+ return {
384
+ id: event.id,
385
+ turnId: event.turnId,
386
+ seq: event.seq,
387
+ type: event.type,
388
+ source: event.source,
389
+ visibility: event.visibility,
390
+ data: optionalObjectFromStruct(event.data),
391
+ createdAt: optionalDate(event.createdAt),
392
+ display: agentTurnDisplayFromProto(event.display),
393
+ };
394
+ }
395
+
396
+ function agentInteractionFromProto(
397
+ interaction: ProtoAgentInteraction,
398
+ ): AgentInteraction {
399
+ return {
400
+ id: interaction.id,
401
+ type: interaction.type as AgentInteractionType,
402
+ state: interaction.state as AgentInteractionState,
403
+ title: interaction.title,
404
+ prompt: interaction.prompt,
405
+ request: optionalObjectFromStruct(interaction.request),
406
+ resolution: optionalObjectFromStruct(interaction.resolution),
407
+ createdAt: optionalDate(interaction.createdAt),
408
+ resolvedAt: optionalDate(interaction.resolvedAt),
409
+ turnId: interaction.turnId,
410
+ sessionId: interaction.sessionId,
411
+ };
412
+ }
413
+
414
+ function optionalDate(timestamp?: Parameters<typeof dateFromTimestamp>[0]) {
415
+ return timestamp === undefined ? undefined : dateFromTimestamp(timestamp);
416
+ }
417
+
229
418
  function agentManagerTransportOptions(rawTarget: string): {
230
419
  baseUrl: string;
231
420
  nodeOptions?: { path: string };