@valon-technologies/gestalt 0.0.1-alpha.18 → 0.0.1-alpha.19
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 +34 -12
- package/package.json +5 -3
- package/src/agent-conversions.ts +201 -0
- package/src/agent-manager.ts +272 -83
- package/src/agent.ts +1023 -224
- package/src/api.ts +42 -0
- package/src/auth.ts +3 -3
- package/src/authorization.ts +1700 -51
- package/src/cache.ts +3 -3
- package/src/catalog.ts +22 -0
- package/src/http-subject.ts +9 -2
- package/src/index.ts +191 -17
- package/src/indexeddb.ts +3 -15
- package/src/internal/gen/v1/agent_pb.ts +137 -51
- package/src/internal/gen/v1/authorization_pb.ts +505 -27
- package/src/internal/gen/v1/plugin_pb.ts +67 -21
- package/src/internal/gen/v1/pluginruntime_pb.ts +95 -6
- package/src/internal/gen/v1/workflow_pb.ts +344 -62
- package/src/invoker.ts +6 -35
- package/src/plugin.ts +12 -12
- package/src/pluginruntime.ts +337 -49
- package/src/protocol/v1.ts +19 -0
- package/src/protocol-internal.ts +19 -0
- package/src/protocol.ts +183 -0
- package/src/provider-kind.ts +7 -3
- package/src/provider.ts +21 -13
- package/src/runtime-log-host.ts +80 -52
- package/src/runtime.ts +67 -0
- package/src/s3.ts +13 -28
- package/src/secrets.ts +3 -3
- package/src/workflow-manager.ts +350 -121
- package/src/workflow.ts +2598 -389
package/src/agent.ts
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
create,
|
|
3
|
-
fromJson,
|
|
4
|
-
isMessage,
|
|
5
|
-
type JsonValue,
|
|
6
3
|
type MessageInitShape,
|
|
7
4
|
} from "@bufbuild/protobuf";
|
|
8
|
-
import { ValueSchema, type Value } from "@bufbuild/protobuf/wkt";
|
|
9
5
|
import {
|
|
10
6
|
Code,
|
|
11
7
|
ConnectError,
|
|
@@ -17,62 +13,79 @@ import {
|
|
|
17
13
|
import { createGrpcTransport } from "@connectrpc/connect-node";
|
|
18
14
|
|
|
19
15
|
import {
|
|
20
|
-
AgentExecutionStatus,
|
|
21
16
|
AgentHost as AgentHostService,
|
|
22
17
|
AgentInteractionSchema,
|
|
23
|
-
AgentInteractionState,
|
|
24
|
-
AgentInteractionType,
|
|
25
|
-
AgentMessagePartType,
|
|
26
18
|
AgentProvider as AgentProviderService,
|
|
27
19
|
AgentProviderCapabilitiesSchema,
|
|
28
20
|
AgentSessionSchema,
|
|
29
|
-
AgentSessionState,
|
|
30
|
-
AgentToolSourceMode,
|
|
31
|
-
AgentTurnDisplaySchema,
|
|
32
21
|
AgentTurnEventSchema,
|
|
33
22
|
AgentTurnSchema,
|
|
23
|
+
AgentExecutionStatus as ProtoAgentExecutionStatus,
|
|
24
|
+
AgentInteractionState as ProtoAgentInteractionState,
|
|
25
|
+
AgentInteractionType as ProtoAgentInteractionType,
|
|
26
|
+
AgentMessagePartType as ProtoAgentMessagePartType,
|
|
27
|
+
AgentSessionState as ProtoAgentSessionState,
|
|
28
|
+
AgentToolSourceMode as ProtoAgentToolSourceMode,
|
|
29
|
+
ExecuteAgentToolRequestSchema,
|
|
34
30
|
GetAgentProviderCapabilitiesRequestSchema,
|
|
31
|
+
ListAgentToolsRequestSchema,
|
|
35
32
|
ListAgentProviderInteractionsResponseSchema,
|
|
36
33
|
ListAgentProviderSessionsResponseSchema,
|
|
37
34
|
ListAgentProviderTurnEventsResponseSchema,
|
|
38
35
|
ListAgentProviderTurnsResponseSchema,
|
|
39
|
-
|
|
40
|
-
type
|
|
41
|
-
type
|
|
42
|
-
type
|
|
43
|
-
type
|
|
44
|
-
type
|
|
45
|
-
type
|
|
46
|
-
type
|
|
47
|
-
type
|
|
48
|
-
type
|
|
49
|
-
type
|
|
50
|
-
type
|
|
51
|
-
type
|
|
52
|
-
type
|
|
53
|
-
type
|
|
54
|
-
type
|
|
55
|
-
type
|
|
56
|
-
type
|
|
57
|
-
type
|
|
58
|
-
type
|
|
59
|
-
type
|
|
60
|
-
type
|
|
61
|
-
type
|
|
62
|
-
type
|
|
63
|
-
type
|
|
64
|
-
type
|
|
65
|
-
type
|
|
66
|
-
type
|
|
67
|
-
type
|
|
68
|
-
type
|
|
69
|
-
type
|
|
70
|
-
type
|
|
71
|
-
type ResolvedAgentTool,
|
|
72
|
-
type UpdateAgentProviderSessionRequest,
|
|
36
|
+
ResolveAgentConnectionRequestSchema,
|
|
37
|
+
type AgentActor as ProtoAgentActor,
|
|
38
|
+
type AgentInteraction as ProtoAgentInteraction,
|
|
39
|
+
type AgentMessagePartImageRef as ProtoAgentMessagePartImageRef,
|
|
40
|
+
type AgentMessagePartToolCall as ProtoAgentMessagePartToolCall,
|
|
41
|
+
type AgentMessagePartToolResult as ProtoAgentMessagePartToolResult,
|
|
42
|
+
type AgentSession as ProtoAgentSession,
|
|
43
|
+
type AgentSubjectContext as ProtoAgentSubjectContext,
|
|
44
|
+
type AgentToolRef as ProtoAgentToolRef,
|
|
45
|
+
type AgentTurn as ProtoAgentTurn,
|
|
46
|
+
type AgentTurnEvent as ProtoAgentTurnEvent,
|
|
47
|
+
type CancelAgentProviderTurnRequest as ProtoCancelAgentProviderTurnRequest,
|
|
48
|
+
type CreateAgentProviderSessionRequest as ProtoCreateAgentProviderSessionRequest,
|
|
49
|
+
type CreateAgentProviderTurnRequest as ProtoCreateAgentProviderTurnRequest,
|
|
50
|
+
type ExecuteAgentToolRequest as ProtoExecuteAgentToolRequest,
|
|
51
|
+
type ExecuteAgentToolResponse as ProtoExecuteAgentToolResponse,
|
|
52
|
+
type GetAgentProviderCapabilitiesRequest as ProtoGetAgentProviderCapabilitiesRequest,
|
|
53
|
+
type GetAgentProviderInteractionRequest as ProtoGetAgentProviderInteractionRequest,
|
|
54
|
+
type GetAgentProviderSessionRequest as ProtoGetAgentProviderSessionRequest,
|
|
55
|
+
type GetAgentProviderTurnRequest as ProtoGetAgentProviderTurnRequest,
|
|
56
|
+
type ListAgentToolsRequest as ProtoListAgentToolsRequest,
|
|
57
|
+
type ListAgentToolsResponse as ProtoListAgentToolsResponse,
|
|
58
|
+
type ListAgentProviderInteractionsRequest as ProtoListAgentProviderInteractionsRequest,
|
|
59
|
+
type ListAgentProviderSessionsRequest as ProtoListAgentProviderSessionsRequest,
|
|
60
|
+
type ListAgentProviderTurnEventsRequest as ProtoListAgentProviderTurnEventsRequest,
|
|
61
|
+
type ListAgentProviderTurnsRequest as ProtoListAgentProviderTurnsRequest,
|
|
62
|
+
type ListedAgentTool as ProtoListedAgentTool,
|
|
63
|
+
type ResolveAgentConnectionRequest as ProtoResolveAgentConnectionRequest,
|
|
64
|
+
type ResolveAgentProviderInteractionRequest as ProtoResolveAgentProviderInteractionRequest,
|
|
65
|
+
type ResolvedAgentConnection as ProtoResolvedAgentConnection,
|
|
66
|
+
type ResolvedAgentTool as ProtoResolvedAgentTool,
|
|
67
|
+
type UpdateAgentProviderSessionRequest as ProtoUpdateAgentProviderSessionRequest,
|
|
73
68
|
} from "./internal/gen/v1/agent_pb.ts";
|
|
74
69
|
import { errorMessage, type MaybePromise } from "./api.ts";
|
|
75
|
-
import {
|
|
70
|
+
import {
|
|
71
|
+
agentActorFromProto,
|
|
72
|
+
agentActorToProto,
|
|
73
|
+
agentMessageFromProto,
|
|
74
|
+
agentMessageToProto,
|
|
75
|
+
agentToolRefFromProto,
|
|
76
|
+
agentTurnDisplayToProto,
|
|
77
|
+
} from "./agent-conversions.ts";
|
|
78
|
+
import {
|
|
79
|
+
dateFromTimestamp,
|
|
80
|
+
timestampFromDate,
|
|
81
|
+
type JsonInput,
|
|
82
|
+
type JsonObjectInput,
|
|
83
|
+
} from "./protocol.ts";
|
|
84
|
+
import {
|
|
85
|
+
optionalObjectFromStruct,
|
|
86
|
+
optionalStruct,
|
|
87
|
+
} from "./protocol-internal.ts";
|
|
88
|
+
import { ProviderBase, type ProviderBaseOptions } from "./provider.ts";
|
|
76
89
|
|
|
77
90
|
/** Environment variable containing the agent-host service target. */
|
|
78
91
|
export const ENV_AGENT_HOST_SOCKET = "GESTALT_AGENT_HOST_SOCKET";
|
|
@@ -80,126 +93,496 @@ export const ENV_AGENT_HOST_SOCKET = "GESTALT_AGENT_HOST_SOCKET";
|
|
|
80
93
|
export const ENV_AGENT_HOST_SOCKET_TOKEN = `${ENV_AGENT_HOST_SOCKET}_TOKEN`;
|
|
81
94
|
const AGENT_HOST_RELAY_TOKEN_HEADER = "x-gestalt-host-service-relay-token";
|
|
82
95
|
|
|
83
|
-
/**
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
export
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
}
|
|
96
|
+
/** Native message-part type constants for authored agent messages. */
|
|
97
|
+
export const AgentMessagePartType = {
|
|
98
|
+
UNSPECIFIED: ProtoAgentMessagePartType.UNSPECIFIED,
|
|
99
|
+
TEXT: ProtoAgentMessagePartType.TEXT,
|
|
100
|
+
JSON: ProtoAgentMessagePartType.JSON,
|
|
101
|
+
TOOL_CALL: ProtoAgentMessagePartType.TOOL_CALL,
|
|
102
|
+
TOOL_RESULT: ProtoAgentMessagePartType.TOOL_RESULT,
|
|
103
|
+
IMAGE_REF: ProtoAgentMessagePartType.IMAGE_REF,
|
|
104
|
+
} as const;
|
|
105
|
+
export type AgentMessagePartType =
|
|
106
|
+
(typeof AgentMessagePartType)[keyof typeof AgentMessagePartType];
|
|
107
|
+
|
|
108
|
+
/** Native tool-source constants for authored agent provider capabilities. */
|
|
109
|
+
export const AgentToolSourceMode = {
|
|
110
|
+
UNSPECIFIED: ProtoAgentToolSourceMode.UNSPECIFIED,
|
|
111
|
+
MCP_CATALOG: ProtoAgentToolSourceMode.MCP_CATALOG,
|
|
112
|
+
} as const;
|
|
113
|
+
export type AgentToolSourceMode =
|
|
114
|
+
(typeof AgentToolSourceMode)[keyof typeof AgentToolSourceMode];
|
|
115
|
+
|
|
116
|
+
/** Native execution-status constants for authored agent turns. */
|
|
117
|
+
export const AgentExecutionStatus = {
|
|
118
|
+
UNSPECIFIED: ProtoAgentExecutionStatus.UNSPECIFIED,
|
|
119
|
+
PENDING: ProtoAgentExecutionStatus.PENDING,
|
|
120
|
+
RUNNING: ProtoAgentExecutionStatus.RUNNING,
|
|
121
|
+
SUCCEEDED: ProtoAgentExecutionStatus.SUCCEEDED,
|
|
122
|
+
FAILED: ProtoAgentExecutionStatus.FAILED,
|
|
123
|
+
CANCELED: ProtoAgentExecutionStatus.CANCELED,
|
|
124
|
+
WAITING_FOR_INPUT: ProtoAgentExecutionStatus.WAITING_FOR_INPUT,
|
|
125
|
+
} as const;
|
|
126
|
+
export type AgentExecutionStatus =
|
|
127
|
+
(typeof AgentExecutionStatus)[keyof typeof AgentExecutionStatus];
|
|
128
|
+
|
|
129
|
+
/** Native session-state constants for authored agent sessions. */
|
|
130
|
+
export const AgentSessionState = {
|
|
131
|
+
UNSPECIFIED: ProtoAgentSessionState.UNSPECIFIED,
|
|
132
|
+
ACTIVE: ProtoAgentSessionState.ACTIVE,
|
|
133
|
+
ARCHIVED: ProtoAgentSessionState.ARCHIVED,
|
|
134
|
+
} as const;
|
|
135
|
+
export type AgentSessionState =
|
|
136
|
+
(typeof AgentSessionState)[keyof typeof AgentSessionState];
|
|
137
|
+
|
|
138
|
+
/** Native interaction-type constants for authored agent interactions. */
|
|
139
|
+
export const AgentInteractionType = {
|
|
140
|
+
UNSPECIFIED: ProtoAgentInteractionType.UNSPECIFIED,
|
|
141
|
+
APPROVAL: ProtoAgentInteractionType.APPROVAL,
|
|
142
|
+
CLARIFICATION: ProtoAgentInteractionType.CLARIFICATION,
|
|
143
|
+
INPUT: ProtoAgentInteractionType.INPUT,
|
|
144
|
+
} as const;
|
|
145
|
+
export type AgentInteractionType =
|
|
146
|
+
(typeof AgentInteractionType)[keyof typeof AgentInteractionType];
|
|
147
|
+
|
|
148
|
+
/** Native interaction-state constants for authored agent interactions. */
|
|
149
|
+
export const AgentInteractionState = {
|
|
150
|
+
UNSPECIFIED: ProtoAgentInteractionState.UNSPECIFIED,
|
|
151
|
+
PENDING: ProtoAgentInteractionState.PENDING,
|
|
152
|
+
RESOLVED: ProtoAgentInteractionState.RESOLVED,
|
|
153
|
+
CANCELED: ProtoAgentInteractionState.CANCELED,
|
|
154
|
+
} as const;
|
|
155
|
+
export type AgentInteractionState =
|
|
156
|
+
(typeof AgentInteractionState)[keyof typeof AgentInteractionState];
|
|
157
|
+
|
|
158
|
+
export interface AgentMessagePartToolCall {
|
|
159
|
+
id?: string | undefined;
|
|
160
|
+
toolId?: string | undefined;
|
|
161
|
+
arguments?: JsonObjectInput | undefined;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
export interface AgentMessagePartToolResult {
|
|
165
|
+
toolCallId?: string | undefined;
|
|
166
|
+
status?: number | undefined;
|
|
167
|
+
content?: string | undefined;
|
|
168
|
+
output?: JsonObjectInput | undefined;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
export interface AgentMessagePartImageRef {
|
|
172
|
+
uri?: string | undefined;
|
|
173
|
+
mimeType?: string | undefined;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
export interface AgentMessagePart {
|
|
177
|
+
type?: AgentMessagePartType | undefined;
|
|
178
|
+
text?: string | undefined;
|
|
179
|
+
json?: JsonObjectInput | undefined;
|
|
180
|
+
toolCall?: AgentMessagePartToolCall | undefined;
|
|
181
|
+
toolResult?: AgentMessagePartToolResult | undefined;
|
|
182
|
+
imageRef?: AgentMessagePartImageRef | undefined;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
export interface AgentMessage {
|
|
186
|
+
role?: string | undefined;
|
|
187
|
+
text?: string | undefined;
|
|
188
|
+
parts?: readonly AgentMessagePart[] | undefined;
|
|
189
|
+
metadata?: JsonObjectInput | undefined;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
export interface AgentActor {
|
|
193
|
+
subjectId?: string | undefined;
|
|
194
|
+
subjectKind?: string | undefined;
|
|
195
|
+
displayName?: string | undefined;
|
|
196
|
+
authSource?: string | undefined;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
export interface AgentSubjectContext {
|
|
200
|
+
subjectId?: string | undefined;
|
|
201
|
+
subjectKind?: string | undefined;
|
|
202
|
+
credentialSubjectId?: string | undefined;
|
|
203
|
+
displayName?: string | undefined;
|
|
204
|
+
authSource?: string | undefined;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
export interface AgentToolRef {
|
|
208
|
+
plugin?: string | undefined;
|
|
209
|
+
operation?: string | undefined;
|
|
210
|
+
connection?: string | undefined;
|
|
211
|
+
instance?: string | undefined;
|
|
212
|
+
title?: string | undefined;
|
|
213
|
+
description?: string | undefined;
|
|
214
|
+
system?: string | undefined;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
export interface ResolvedAgentTool {
|
|
218
|
+
id?: string | undefined;
|
|
219
|
+
name?: string | undefined;
|
|
220
|
+
description?: string | undefined;
|
|
221
|
+
parametersSchema?: JsonObjectInput | undefined;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
export interface AgentProviderCapabilities {
|
|
225
|
+
streamingText?: boolean | undefined;
|
|
226
|
+
toolCalls?: boolean | undefined;
|
|
227
|
+
parallelToolCalls?: boolean | undefined;
|
|
228
|
+
structuredOutput?: boolean | undefined;
|
|
229
|
+
interactions?: boolean | undefined;
|
|
230
|
+
resumableTurns?: boolean | undefined;
|
|
231
|
+
reasoningSummaries?: boolean | undefined;
|
|
232
|
+
boundedListHydration?: boolean | undefined;
|
|
233
|
+
supportedToolSources?: readonly AgentToolSourceMode[] | undefined;
|
|
234
|
+
supportsSessionStart?: boolean | undefined;
|
|
235
|
+
supportsPreparedWorkspace?: boolean | undefined;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
export interface AgentSession {
|
|
239
|
+
id?: string | undefined;
|
|
240
|
+
providerName?: string | undefined;
|
|
241
|
+
model?: string | undefined;
|
|
242
|
+
clientRef?: string | undefined;
|
|
243
|
+
state?: AgentSessionState | undefined;
|
|
244
|
+
metadata?: JsonObjectInput | undefined;
|
|
245
|
+
createdBy?: AgentActor | undefined;
|
|
246
|
+
createdAt?: Date | undefined;
|
|
247
|
+
updatedAt?: Date | undefined;
|
|
248
|
+
lastTurnAt?: Date | undefined;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
export interface AgentSessionStartHookOutput {
|
|
252
|
+
additionalContext?: boolean | undefined;
|
|
253
|
+
metadata?: boolean | undefined;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
export interface AgentSessionStartHook {
|
|
257
|
+
id?: string | undefined;
|
|
258
|
+
type?: string | undefined;
|
|
259
|
+
command?: readonly string[] | undefined;
|
|
260
|
+
cwd?: string | undefined;
|
|
261
|
+
timeout?: string | undefined;
|
|
262
|
+
env?: Record<string, string> | undefined;
|
|
263
|
+
output?: AgentSessionStartHookOutput | undefined;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
export interface AgentSessionStartConfig {
|
|
267
|
+
hooks?: readonly AgentSessionStartHook[] | undefined;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
export interface AgentPreparedWorkspace {
|
|
271
|
+
root?: string | undefined;
|
|
272
|
+
cwd?: string | undefined;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
export interface CreateAgentProviderSessionRequest {
|
|
276
|
+
sessionId: string;
|
|
277
|
+
idempotencyKey: string;
|
|
278
|
+
model: string;
|
|
279
|
+
clientRef: string;
|
|
280
|
+
metadata?: JsonObjectInput | undefined;
|
|
281
|
+
createdBy?: AgentActor | undefined;
|
|
282
|
+
subject?: AgentSubjectContext | undefined;
|
|
283
|
+
sessionStart?: AgentSessionStartConfig | undefined;
|
|
284
|
+
preparedWorkspace?: AgentPreparedWorkspace | undefined;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
export interface GetAgentProviderSessionRequest {
|
|
288
|
+
sessionId: string;
|
|
289
|
+
subject?: AgentSubjectContext | undefined;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
export interface ListAgentProviderSessionsRequest {
|
|
293
|
+
subject?: AgentSubjectContext | undefined;
|
|
294
|
+
sessionIds: readonly string[];
|
|
295
|
+
state: AgentSessionState;
|
|
296
|
+
limit: number;
|
|
297
|
+
summaryOnly: boolean;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
export interface ListAgentProviderSessionsResponse {
|
|
301
|
+
sessions: readonly AgentSession[];
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
export interface UpdateAgentProviderSessionRequest {
|
|
305
|
+
sessionId: string;
|
|
306
|
+
clientRef: string;
|
|
307
|
+
state: AgentSessionState;
|
|
308
|
+
metadata?: JsonObjectInput | undefined;
|
|
309
|
+
subject?: AgentSubjectContext | undefined;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
export interface AgentTurn {
|
|
313
|
+
id?: string | undefined;
|
|
314
|
+
sessionId?: string | undefined;
|
|
315
|
+
providerName?: string | undefined;
|
|
316
|
+
model?: string | undefined;
|
|
317
|
+
status?: AgentExecutionStatus | undefined;
|
|
318
|
+
messages?: readonly AgentMessage[] | undefined;
|
|
319
|
+
outputText?: string | undefined;
|
|
320
|
+
structuredOutput?: JsonObjectInput | undefined;
|
|
321
|
+
statusMessage?: string | undefined;
|
|
322
|
+
createdBy?: AgentActor | undefined;
|
|
323
|
+
createdAt?: Date | undefined;
|
|
324
|
+
startedAt?: Date | undefined;
|
|
325
|
+
completedAt?: Date | undefined;
|
|
326
|
+
executionRef?: string | undefined;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
export interface AgentTurnDisplay {
|
|
330
|
+
kind?: string | undefined;
|
|
331
|
+
phase?: string | undefined;
|
|
332
|
+
text?: string | undefined;
|
|
333
|
+
label?: string | undefined;
|
|
334
|
+
ref?: string | undefined;
|
|
335
|
+
parentRef?: string | undefined;
|
|
336
|
+
input?: JsonInput | undefined;
|
|
337
|
+
output?: JsonInput | undefined;
|
|
338
|
+
error?: JsonInput | undefined;
|
|
339
|
+
action?: string | undefined;
|
|
340
|
+
format?: string | undefined;
|
|
341
|
+
language?: string | undefined;
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
export interface CreateAgentProviderTurnRequest {
|
|
345
|
+
turnId: string;
|
|
346
|
+
sessionId: string;
|
|
347
|
+
idempotencyKey: string;
|
|
348
|
+
model: string;
|
|
349
|
+
messages: readonly AgentMessage[];
|
|
350
|
+
tools: readonly ResolvedAgentTool[];
|
|
351
|
+
responseSchema?: JsonObjectInput | undefined;
|
|
352
|
+
metadata?: JsonObjectInput | undefined;
|
|
353
|
+
createdBy?: AgentActor | undefined;
|
|
354
|
+
executionRef: string;
|
|
355
|
+
toolRefs: readonly AgentToolRef[];
|
|
356
|
+
toolSource: AgentToolSourceMode;
|
|
357
|
+
subject?: AgentSubjectContext | undefined;
|
|
358
|
+
modelOptions?: JsonObjectInput | undefined;
|
|
359
|
+
runGrant: string;
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
export interface GetAgentProviderTurnRequest {
|
|
363
|
+
turnId: string;
|
|
364
|
+
subject?: AgentSubjectContext | undefined;
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
export interface ListAgentProviderTurnsRequest {
|
|
368
|
+
sessionId: string;
|
|
369
|
+
subject?: AgentSubjectContext | undefined;
|
|
370
|
+
turnIds: readonly string[];
|
|
371
|
+
status: AgentExecutionStatus;
|
|
372
|
+
limit: number;
|
|
373
|
+
summaryOnly: boolean;
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
export interface ListAgentProviderTurnsResponse {
|
|
377
|
+
turns: readonly AgentTurn[];
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
export interface CancelAgentProviderTurnRequest {
|
|
381
|
+
turnId: string;
|
|
382
|
+
reason: string;
|
|
383
|
+
subject?: AgentSubjectContext | undefined;
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
export interface AgentTurnEvent {
|
|
387
|
+
id?: string | undefined;
|
|
388
|
+
turnId?: string | undefined;
|
|
389
|
+
seq?: bigint | number | undefined;
|
|
390
|
+
type?: string | undefined;
|
|
391
|
+
source?: string | undefined;
|
|
392
|
+
visibility?: string | undefined;
|
|
393
|
+
data?: JsonObjectInput | undefined;
|
|
394
|
+
createdAt?: Date | undefined;
|
|
395
|
+
display?: AgentTurnDisplay | undefined;
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
export interface ListAgentProviderTurnEventsRequest {
|
|
399
|
+
turnId: string;
|
|
400
|
+
afterSeq: bigint;
|
|
401
|
+
limit: number;
|
|
402
|
+
subject?: AgentSubjectContext | undefined;
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
export interface ListAgentProviderTurnEventsResponse {
|
|
406
|
+
events: readonly AgentTurnEvent[];
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
export interface AgentInteraction {
|
|
410
|
+
id?: string | undefined;
|
|
411
|
+
type?: AgentInteractionType | undefined;
|
|
412
|
+
state?: AgentInteractionState | undefined;
|
|
413
|
+
title?: string | undefined;
|
|
414
|
+
prompt?: string | undefined;
|
|
415
|
+
request?: JsonObjectInput | undefined;
|
|
416
|
+
resolution?: JsonObjectInput | undefined;
|
|
417
|
+
createdAt?: Date | undefined;
|
|
418
|
+
resolvedAt?: Date | undefined;
|
|
419
|
+
turnId?: string | undefined;
|
|
420
|
+
sessionId?: string | undefined;
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
export interface GetAgentProviderInteractionRequest {
|
|
424
|
+
interactionId: string;
|
|
425
|
+
subject?: AgentSubjectContext | undefined;
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
export interface ListAgentProviderInteractionsRequest {
|
|
429
|
+
turnId: string;
|
|
430
|
+
subject?: AgentSubjectContext | undefined;
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
export interface ListAgentProviderInteractionsResponse {
|
|
434
|
+
interactions: readonly AgentInteraction[];
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
export interface ResolveAgentProviderInteractionRequest {
|
|
438
|
+
interactionId: string;
|
|
439
|
+
resolution?: JsonObjectInput | undefined;
|
|
440
|
+
subject?: AgentSubjectContext | undefined;
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
export interface GetAgentProviderCapabilitiesRequest {}
|
|
444
|
+
|
|
445
|
+
export interface ExecuteAgentToolRequest {
|
|
446
|
+
sessionId: string;
|
|
447
|
+
turnId: string;
|
|
448
|
+
toolCallId: string;
|
|
449
|
+
toolId: string;
|
|
450
|
+
arguments?: JsonObjectInput | undefined;
|
|
451
|
+
idempotencyKey?: string | undefined;
|
|
452
|
+
runGrant?: string | undefined;
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
export interface ExecuteAgentToolResponse {
|
|
456
|
+
status: number;
|
|
457
|
+
body: string;
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
export interface AgentToolAnnotations {
|
|
461
|
+
readOnlyHint?: boolean | undefined;
|
|
462
|
+
idempotentHint?: boolean | undefined;
|
|
463
|
+
destructiveHint?: boolean | undefined;
|
|
464
|
+
openWorldHint?: boolean | undefined;
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
export interface ListedAgentTool {
|
|
468
|
+
id: string;
|
|
469
|
+
mcpName: string;
|
|
470
|
+
title: string;
|
|
471
|
+
description: string;
|
|
472
|
+
inputSchema: string;
|
|
473
|
+
outputSchema: string;
|
|
474
|
+
annotations?: AgentToolAnnotations | undefined;
|
|
475
|
+
ref?: AgentToolRef | undefined;
|
|
476
|
+
tags: readonly string[];
|
|
477
|
+
searchText: string;
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
export interface ListAgentToolsRequest {
|
|
481
|
+
sessionId: string;
|
|
482
|
+
turnId: string;
|
|
483
|
+
pageSize?: number | undefined;
|
|
484
|
+
pageToken?: string | undefined;
|
|
485
|
+
runGrant?: string | undefined;
|
|
486
|
+
query?: string | undefined;
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
export interface ListAgentToolsResponse {
|
|
490
|
+
tools: readonly ListedAgentTool[];
|
|
491
|
+
nextPageToken: string;
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
export interface ResolveAgentConnectionRequest {
|
|
495
|
+
sessionId: string;
|
|
496
|
+
turnId: string;
|
|
497
|
+
connection: string;
|
|
498
|
+
instance?: string | undefined;
|
|
499
|
+
runGrant?: string | undefined;
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
export interface ResolvedAgentConnection {
|
|
503
|
+
connectionId: string;
|
|
504
|
+
connection: string;
|
|
505
|
+
instance: string;
|
|
506
|
+
mode: string;
|
|
507
|
+
headers: Record<string, string>;
|
|
508
|
+
params: Record<string, string>;
|
|
509
|
+
expiresAt?: Date | undefined;
|
|
510
|
+
}
|
|
511
|
+
/** Plain-object input for listing tools available to one agent turn. */
|
|
512
|
+
export interface AgentHostListToolsInput {
|
|
513
|
+
sessionId: string;
|
|
514
|
+
turnId: string;
|
|
515
|
+
runGrant?: string | undefined;
|
|
516
|
+
pageSize?: number | undefined;
|
|
517
|
+
pageToken?: string | undefined;
|
|
518
|
+
query?: string | undefined;
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
/** Plain-object input for executing a tool during one agent turn. */
|
|
522
|
+
export interface AgentHostExecuteToolInput {
|
|
523
|
+
sessionId: string;
|
|
524
|
+
turnId: string;
|
|
525
|
+
toolCallId: string;
|
|
526
|
+
toolId: string;
|
|
527
|
+
arguments?: JsonObjectInput | undefined;
|
|
528
|
+
runGrant?: string | undefined;
|
|
529
|
+
idempotencyKey?: string | undefined;
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
/** Plain-object input for resolving a configured connection during one turn. */
|
|
533
|
+
export interface AgentHostResolveConnectionInput {
|
|
534
|
+
sessionId: string;
|
|
535
|
+
turnId: string;
|
|
536
|
+
connection: string;
|
|
537
|
+
instance?: string | undefined;
|
|
538
|
+
runGrant?: string | undefined;
|
|
539
|
+
}
|
|
157
540
|
|
|
158
541
|
/** Handlers and runtime metadata for an agent provider. */
|
|
159
|
-
export interface AgentProviderOptions extends
|
|
542
|
+
export interface AgentProviderOptions extends ProviderBaseOptions {
|
|
160
543
|
createSession?: (
|
|
161
544
|
request: CreateAgentProviderSessionRequest,
|
|
162
|
-
) => MaybePromise<
|
|
545
|
+
) => MaybePromise<AgentSession>;
|
|
163
546
|
getSession?: (
|
|
164
547
|
request: GetAgentProviderSessionRequest,
|
|
165
|
-
) => MaybePromise<
|
|
548
|
+
) => MaybePromise<AgentSession>;
|
|
166
549
|
listSessions?: (
|
|
167
550
|
request: ListAgentProviderSessionsRequest,
|
|
168
|
-
) => MaybePromise<
|
|
551
|
+
) => MaybePromise<readonly AgentSession[] | ListAgentProviderSessionsResponse>;
|
|
169
552
|
updateSession?: (
|
|
170
553
|
request: UpdateAgentProviderSessionRequest,
|
|
171
|
-
) => MaybePromise<
|
|
554
|
+
) => MaybePromise<AgentSession>;
|
|
172
555
|
createTurn?: (
|
|
173
556
|
request: CreateAgentProviderTurnRequest,
|
|
174
|
-
) => MaybePromise<
|
|
557
|
+
) => MaybePromise<AgentTurn>;
|
|
175
558
|
getTurn?: (
|
|
176
559
|
request: GetAgentProviderTurnRequest,
|
|
177
|
-
) => MaybePromise<
|
|
560
|
+
) => MaybePromise<AgentTurn>;
|
|
178
561
|
listTurns?: (
|
|
179
562
|
request: ListAgentProviderTurnsRequest,
|
|
180
|
-
) => MaybePromise<
|
|
563
|
+
) => MaybePromise<readonly AgentTurn[] | ListAgentProviderTurnsResponse>;
|
|
181
564
|
cancelTurn?: (
|
|
182
565
|
request: CancelAgentProviderTurnRequest,
|
|
183
|
-
) => MaybePromise<
|
|
566
|
+
) => MaybePromise<AgentTurn>;
|
|
184
567
|
listTurnEvents?: (
|
|
185
568
|
request: ListAgentProviderTurnEventsRequest,
|
|
186
|
-
) => MaybePromise<
|
|
569
|
+
) => MaybePromise<readonly AgentTurnEvent[] | ListAgentProviderTurnEventsResponse>;
|
|
187
570
|
getInteraction?: (
|
|
188
571
|
request: GetAgentProviderInteractionRequest,
|
|
189
|
-
) => MaybePromise<
|
|
572
|
+
) => MaybePromise<AgentInteraction>;
|
|
190
573
|
listInteractions?: (
|
|
191
574
|
request: ListAgentProviderInteractionsRequest,
|
|
192
|
-
) => MaybePromise<
|
|
575
|
+
) => MaybePromise<readonly AgentInteraction[] | ListAgentProviderInteractionsResponse>;
|
|
193
576
|
resolveInteraction?: (
|
|
194
577
|
request: ResolveAgentProviderInteractionRequest,
|
|
195
|
-
) => MaybePromise<
|
|
578
|
+
) => MaybePromise<AgentInteraction>;
|
|
196
579
|
getCapabilities?: (
|
|
197
580
|
request: GetAgentProviderCapabilitiesRequest,
|
|
198
|
-
) => MaybePromise<
|
|
581
|
+
) => MaybePromise<AgentProviderCapabilities>;
|
|
199
582
|
}
|
|
200
583
|
|
|
201
584
|
/** Runtime provider implementation for the Gestalt agent host contract. */
|
|
202
|
-
export class AgentProvider extends
|
|
585
|
+
export class AgentProvider extends ProviderBase {
|
|
203
586
|
readonly kind = "agent" as const;
|
|
204
587
|
|
|
205
588
|
private readonly createSessionHandler: AgentProviderOptions["createSession"];
|
|
@@ -235,7 +618,7 @@ export class AgentProvider extends RuntimeProvider {
|
|
|
235
618
|
|
|
236
619
|
async createSession(
|
|
237
620
|
request: CreateAgentProviderSessionRequest,
|
|
238
|
-
): Promise<
|
|
621
|
+
): Promise<AgentSession> {
|
|
239
622
|
return await requireAgentProviderHandler(
|
|
240
623
|
"create session",
|
|
241
624
|
this.createSessionHandler,
|
|
@@ -245,7 +628,7 @@ export class AgentProvider extends RuntimeProvider {
|
|
|
245
628
|
|
|
246
629
|
async getSession(
|
|
247
630
|
request: GetAgentProviderSessionRequest,
|
|
248
|
-
): Promise<
|
|
631
|
+
): Promise<AgentSession> {
|
|
249
632
|
return await requireAgentProviderHandler(
|
|
250
633
|
"get session",
|
|
251
634
|
this.getSessionHandler,
|
|
@@ -255,7 +638,7 @@ export class AgentProvider extends RuntimeProvider {
|
|
|
255
638
|
|
|
256
639
|
async listSessions(
|
|
257
640
|
request: ListAgentProviderSessionsRequest,
|
|
258
|
-
): Promise<
|
|
641
|
+
): Promise<readonly AgentSession[] | ListAgentProviderSessionsResponse> {
|
|
259
642
|
return await requireAgentProviderHandler(
|
|
260
643
|
"list sessions",
|
|
261
644
|
this.listSessionsHandler,
|
|
@@ -265,7 +648,7 @@ export class AgentProvider extends RuntimeProvider {
|
|
|
265
648
|
|
|
266
649
|
async updateSession(
|
|
267
650
|
request: UpdateAgentProviderSessionRequest,
|
|
268
|
-
): Promise<
|
|
651
|
+
): Promise<AgentSession> {
|
|
269
652
|
return await requireAgentProviderHandler(
|
|
270
653
|
"update session",
|
|
271
654
|
this.updateSessionHandler,
|
|
@@ -275,7 +658,7 @@ export class AgentProvider extends RuntimeProvider {
|
|
|
275
658
|
|
|
276
659
|
async createTurn(
|
|
277
660
|
request: CreateAgentProviderTurnRequest,
|
|
278
|
-
): Promise<
|
|
661
|
+
): Promise<AgentTurn> {
|
|
279
662
|
return await requireAgentProviderHandler(
|
|
280
663
|
"create turn",
|
|
281
664
|
this.createTurnHandler,
|
|
@@ -285,7 +668,7 @@ export class AgentProvider extends RuntimeProvider {
|
|
|
285
668
|
|
|
286
669
|
async getTurn(
|
|
287
670
|
request: GetAgentProviderTurnRequest,
|
|
288
|
-
): Promise<
|
|
671
|
+
): Promise<AgentTurn> {
|
|
289
672
|
return await requireAgentProviderHandler(
|
|
290
673
|
"get turn",
|
|
291
674
|
this.getTurnHandler,
|
|
@@ -295,7 +678,7 @@ export class AgentProvider extends RuntimeProvider {
|
|
|
295
678
|
|
|
296
679
|
async listTurns(
|
|
297
680
|
request: ListAgentProviderTurnsRequest,
|
|
298
|
-
): Promise<
|
|
681
|
+
): Promise<readonly AgentTurn[] | ListAgentProviderTurnsResponse> {
|
|
299
682
|
return await requireAgentProviderHandler(
|
|
300
683
|
"list turns",
|
|
301
684
|
this.listTurnsHandler,
|
|
@@ -305,7 +688,7 @@ export class AgentProvider extends RuntimeProvider {
|
|
|
305
688
|
|
|
306
689
|
async cancelTurn(
|
|
307
690
|
request: CancelAgentProviderTurnRequest,
|
|
308
|
-
): Promise<
|
|
691
|
+
): Promise<AgentTurn> {
|
|
309
692
|
return await requireAgentProviderHandler(
|
|
310
693
|
"cancel turn",
|
|
311
694
|
this.cancelTurnHandler,
|
|
@@ -315,7 +698,7 @@ export class AgentProvider extends RuntimeProvider {
|
|
|
315
698
|
|
|
316
699
|
async listTurnEvents(
|
|
317
700
|
request: ListAgentProviderTurnEventsRequest,
|
|
318
|
-
): Promise<
|
|
701
|
+
): Promise<readonly AgentTurnEvent[] | ListAgentProviderTurnEventsResponse> {
|
|
319
702
|
return await requireAgentProviderHandler(
|
|
320
703
|
"list turn events",
|
|
321
704
|
this.listTurnEventsHandler,
|
|
@@ -325,7 +708,7 @@ export class AgentProvider extends RuntimeProvider {
|
|
|
325
708
|
|
|
326
709
|
async getInteraction(
|
|
327
710
|
request: GetAgentProviderInteractionRequest,
|
|
328
|
-
): Promise<
|
|
711
|
+
): Promise<AgentInteraction> {
|
|
329
712
|
return await requireAgentProviderHandler(
|
|
330
713
|
"get interaction",
|
|
331
714
|
this.getInteractionHandler,
|
|
@@ -335,7 +718,7 @@ export class AgentProvider extends RuntimeProvider {
|
|
|
335
718
|
|
|
336
719
|
async listInteractions(
|
|
337
720
|
request: ListAgentProviderInteractionsRequest,
|
|
338
|
-
): Promise<
|
|
721
|
+
): Promise<readonly AgentInteraction[] | ListAgentProviderInteractionsResponse> {
|
|
339
722
|
return await requireAgentProviderHandler(
|
|
340
723
|
"list interactions",
|
|
341
724
|
this.listInteractionsHandler,
|
|
@@ -345,7 +728,7 @@ export class AgentProvider extends RuntimeProvider {
|
|
|
345
728
|
|
|
346
729
|
async resolveInteraction(
|
|
347
730
|
request: ResolveAgentProviderInteractionRequest,
|
|
348
|
-
): Promise<
|
|
731
|
+
): Promise<AgentInteraction> {
|
|
349
732
|
return await requireAgentProviderHandler(
|
|
350
733
|
"resolve interaction",
|
|
351
734
|
this.resolveInteractionHandler,
|
|
@@ -354,11 +737,8 @@ export class AgentProvider extends RuntimeProvider {
|
|
|
354
737
|
}
|
|
355
738
|
|
|
356
739
|
async getCapabilities(
|
|
357
|
-
request: GetAgentProviderCapabilitiesRequest =
|
|
358
|
-
|
|
359
|
-
{},
|
|
360
|
-
),
|
|
361
|
-
): Promise<MessageInitShape<typeof AgentProviderCapabilitiesSchema>> {
|
|
740
|
+
request: GetAgentProviderCapabilitiesRequest = {},
|
|
741
|
+
): Promise<AgentProviderCapabilities> {
|
|
362
742
|
return await requireAgentProviderHandler(
|
|
363
743
|
"get capabilities",
|
|
364
744
|
this.getCapabilitiesHandler,
|
|
@@ -372,54 +752,369 @@ export function defineAgentProvider(options: AgentProviderOptions): AgentProvide
|
|
|
372
752
|
return new AgentProvider(options);
|
|
373
753
|
}
|
|
374
754
|
|
|
375
|
-
function
|
|
376
|
-
|
|
377
|
-
):
|
|
378
|
-
return
|
|
755
|
+
function createAgentProviderSessionRequestFromProto(
|
|
756
|
+
request: ProtoCreateAgentProviderSessionRequest,
|
|
757
|
+
): CreateAgentProviderSessionRequest {
|
|
758
|
+
return {
|
|
759
|
+
sessionId: request.sessionId,
|
|
760
|
+
idempotencyKey: request.idempotencyKey,
|
|
761
|
+
model: request.model,
|
|
762
|
+
clientRef: request.clientRef,
|
|
763
|
+
metadata: optionalObjectFromStruct(request.metadata),
|
|
764
|
+
createdBy: agentActorFromProto(request.createdBy),
|
|
765
|
+
subject: agentSubjectFromProto(request.subject),
|
|
766
|
+
sessionStart: request.sessionStart === undefined ? undefined : {
|
|
767
|
+
hooks: request.sessionStart.hooks.map((hook) => ({
|
|
768
|
+
id: hook.id,
|
|
769
|
+
type: hook.type,
|
|
770
|
+
command: [...hook.command],
|
|
771
|
+
cwd: hook.cwd,
|
|
772
|
+
timeout: hook.timeout,
|
|
773
|
+
env: { ...hook.env },
|
|
774
|
+
output: hook.output === undefined ? undefined : {
|
|
775
|
+
additionalContext: hook.output.additionalContext,
|
|
776
|
+
metadata: hook.output.metadata,
|
|
777
|
+
},
|
|
778
|
+
})),
|
|
779
|
+
},
|
|
780
|
+
preparedWorkspace: request.preparedWorkspace === undefined ? undefined : {
|
|
781
|
+
root: request.preparedWorkspace.root,
|
|
782
|
+
cwd: request.preparedWorkspace.cwd,
|
|
783
|
+
},
|
|
784
|
+
};
|
|
785
|
+
}
|
|
786
|
+
|
|
787
|
+
function getAgentProviderSessionRequestFromProto(
|
|
788
|
+
request: ProtoGetAgentProviderSessionRequest,
|
|
789
|
+
): GetAgentProviderSessionRequest {
|
|
790
|
+
return {
|
|
791
|
+
sessionId: request.sessionId,
|
|
792
|
+
subject: agentSubjectFromProto(request.subject),
|
|
793
|
+
};
|
|
794
|
+
}
|
|
795
|
+
|
|
796
|
+
function listAgentProviderSessionsRequestFromProto(
|
|
797
|
+
request: ProtoListAgentProviderSessionsRequest,
|
|
798
|
+
): ListAgentProviderSessionsRequest {
|
|
799
|
+
return {
|
|
800
|
+
subject: agentSubjectFromProto(request.subject),
|
|
801
|
+
sessionIds: [...request.sessionIds],
|
|
802
|
+
state: request.state as AgentSessionState,
|
|
803
|
+
limit: request.limit,
|
|
804
|
+
summaryOnly: request.summaryOnly,
|
|
805
|
+
};
|
|
806
|
+
}
|
|
807
|
+
|
|
808
|
+
function updateAgentProviderSessionRequestFromProto(
|
|
809
|
+
request: ProtoUpdateAgentProviderSessionRequest,
|
|
810
|
+
): UpdateAgentProviderSessionRequest {
|
|
811
|
+
return {
|
|
812
|
+
sessionId: request.sessionId,
|
|
813
|
+
clientRef: request.clientRef,
|
|
814
|
+
state: request.state as AgentSessionState,
|
|
815
|
+
metadata: optionalObjectFromStruct(request.metadata),
|
|
816
|
+
subject: agentSubjectFromProto(request.subject),
|
|
817
|
+
};
|
|
818
|
+
}
|
|
819
|
+
|
|
820
|
+
function createAgentProviderTurnRequestFromProto(
|
|
821
|
+
request: ProtoCreateAgentProviderTurnRequest,
|
|
822
|
+
): CreateAgentProviderTurnRequest {
|
|
823
|
+
return {
|
|
824
|
+
turnId: request.turnId,
|
|
825
|
+
sessionId: request.sessionId,
|
|
826
|
+
idempotencyKey: request.idempotencyKey,
|
|
827
|
+
model: request.model,
|
|
828
|
+
messages: request.messages.map(agentMessageFromProto),
|
|
829
|
+
tools: request.tools.map(resolvedAgentToolFromProto),
|
|
830
|
+
responseSchema: optionalObjectFromStruct(request.responseSchema),
|
|
831
|
+
metadata: optionalObjectFromStruct(request.metadata),
|
|
832
|
+
createdBy: agentActorFromProto(request.createdBy),
|
|
833
|
+
executionRef: request.executionRef,
|
|
834
|
+
toolRefs: request.toolRefs.map(agentToolRefFromProto),
|
|
835
|
+
toolSource: request.toolSource as AgentToolSourceMode,
|
|
836
|
+
subject: agentSubjectFromProto(request.subject),
|
|
837
|
+
modelOptions: optionalObjectFromStruct(request.modelOptions),
|
|
838
|
+
runGrant: request.runGrant,
|
|
839
|
+
};
|
|
840
|
+
}
|
|
841
|
+
|
|
842
|
+
function getAgentProviderTurnRequestFromProto(
|
|
843
|
+
request: ProtoGetAgentProviderTurnRequest,
|
|
844
|
+
): GetAgentProviderTurnRequest {
|
|
845
|
+
return {
|
|
846
|
+
turnId: request.turnId,
|
|
847
|
+
subject: agentSubjectFromProto(request.subject),
|
|
848
|
+
};
|
|
849
|
+
}
|
|
850
|
+
|
|
851
|
+
function listAgentProviderTurnsRequestFromProto(
|
|
852
|
+
request: ProtoListAgentProviderTurnsRequest,
|
|
853
|
+
): ListAgentProviderTurnsRequest {
|
|
854
|
+
return {
|
|
855
|
+
sessionId: request.sessionId,
|
|
856
|
+
subject: agentSubjectFromProto(request.subject),
|
|
857
|
+
turnIds: [...request.turnIds],
|
|
858
|
+
status: request.status as AgentExecutionStatus,
|
|
859
|
+
limit: request.limit,
|
|
860
|
+
summaryOnly: request.summaryOnly,
|
|
861
|
+
};
|
|
862
|
+
}
|
|
863
|
+
|
|
864
|
+
function cancelAgentProviderTurnRequestFromProto(
|
|
865
|
+
request: ProtoCancelAgentProviderTurnRequest,
|
|
866
|
+
): CancelAgentProviderTurnRequest {
|
|
867
|
+
return {
|
|
868
|
+
turnId: request.turnId,
|
|
869
|
+
reason: request.reason,
|
|
870
|
+
subject: agentSubjectFromProto(request.subject),
|
|
871
|
+
};
|
|
872
|
+
}
|
|
873
|
+
|
|
874
|
+
function listAgentProviderTurnEventsRequestFromProto(
|
|
875
|
+
request: ProtoListAgentProviderTurnEventsRequest,
|
|
876
|
+
): ListAgentProviderTurnEventsRequest {
|
|
877
|
+
return {
|
|
878
|
+
turnId: request.turnId,
|
|
879
|
+
afterSeq: request.afterSeq,
|
|
880
|
+
limit: request.limit,
|
|
881
|
+
subject: agentSubjectFromProto(request.subject),
|
|
882
|
+
};
|
|
379
883
|
}
|
|
380
884
|
|
|
381
|
-
function
|
|
382
|
-
|
|
885
|
+
function getAgentProviderInteractionRequestFromProto(
|
|
886
|
+
request: ProtoGetAgentProviderInteractionRequest,
|
|
887
|
+
): GetAgentProviderInteractionRequest {
|
|
888
|
+
return {
|
|
889
|
+
interactionId: request.interactionId,
|
|
890
|
+
subject: agentSubjectFromProto(request.subject),
|
|
891
|
+
};
|
|
892
|
+
}
|
|
893
|
+
|
|
894
|
+
function listAgentProviderInteractionsRequestFromProto(
|
|
895
|
+
request: ProtoListAgentProviderInteractionsRequest,
|
|
896
|
+
): ListAgentProviderInteractionsRequest {
|
|
897
|
+
return {
|
|
898
|
+
turnId: request.turnId,
|
|
899
|
+
subject: agentSubjectFromProto(request.subject),
|
|
900
|
+
};
|
|
901
|
+
}
|
|
902
|
+
|
|
903
|
+
function resolveAgentProviderInteractionRequestFromProto(
|
|
904
|
+
request: ProtoResolveAgentProviderInteractionRequest,
|
|
905
|
+
): ResolveAgentProviderInteractionRequest {
|
|
906
|
+
return {
|
|
907
|
+
interactionId: request.interactionId,
|
|
908
|
+
resolution: optionalObjectFromStruct(request.resolution),
|
|
909
|
+
subject: agentSubjectFromProto(request.subject),
|
|
910
|
+
};
|
|
911
|
+
}
|
|
912
|
+
|
|
913
|
+
function agentSessionToProto(
|
|
914
|
+
session: AgentSession,
|
|
915
|
+
): MessageInitShape<typeof AgentSessionSchema> {
|
|
916
|
+
return {
|
|
917
|
+
id: session.id ?? "",
|
|
918
|
+
providerName: session.providerName ?? "",
|
|
919
|
+
model: session.model ?? "",
|
|
920
|
+
clientRef: session.clientRef ?? "",
|
|
921
|
+
state: session.state ?? AgentSessionState.UNSPECIFIED,
|
|
922
|
+
metadata: optionalStruct(session.metadata),
|
|
923
|
+
createdBy: agentActorToProto(session.createdBy),
|
|
924
|
+
createdAt: optionalTimestamp(session.createdAt),
|
|
925
|
+
updatedAt: optionalTimestamp(session.updatedAt),
|
|
926
|
+
lastTurnAt: optionalTimestamp(session.lastTurnAt),
|
|
927
|
+
};
|
|
928
|
+
}
|
|
929
|
+
|
|
930
|
+
function agentTurnToProto(turn: AgentTurn): MessageInitShape<typeof AgentTurnSchema> {
|
|
931
|
+
return {
|
|
932
|
+
id: turn.id ?? "",
|
|
933
|
+
sessionId: turn.sessionId ?? "",
|
|
934
|
+
providerName: turn.providerName ?? "",
|
|
935
|
+
model: turn.model ?? "",
|
|
936
|
+
status: turn.status ?? AgentExecutionStatus.UNSPECIFIED,
|
|
937
|
+
messages: turn.messages?.map(agentMessageToProto) ?? [],
|
|
938
|
+
outputText: turn.outputText ?? "",
|
|
939
|
+
structuredOutput: optionalStruct(turn.structuredOutput),
|
|
940
|
+
statusMessage: turn.statusMessage ?? "",
|
|
941
|
+
createdBy: agentActorToProto(turn.createdBy),
|
|
942
|
+
createdAt: optionalTimestamp(turn.createdAt),
|
|
943
|
+
startedAt: optionalTimestamp(turn.startedAt),
|
|
944
|
+
completedAt: optionalTimestamp(turn.completedAt),
|
|
945
|
+
executionRef: turn.executionRef ?? "",
|
|
946
|
+
};
|
|
947
|
+
}
|
|
948
|
+
|
|
949
|
+
function agentTurnEventToProto(
|
|
950
|
+
event: AgentTurnEvent,
|
|
383
951
|
): MessageInitShape<typeof AgentTurnEventSchema> {
|
|
384
|
-
const display = event.display;
|
|
385
|
-
if (!display) {
|
|
386
|
-
return event as MessageInitShape<typeof AgentTurnEventSchema>;
|
|
387
|
-
}
|
|
388
952
|
return {
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
953
|
+
id: event.id ?? "",
|
|
954
|
+
turnId: event.turnId ?? "",
|
|
955
|
+
seq: typeof event.seq === "number" ? BigInt(event.seq) : (event.seq ?? 0n),
|
|
956
|
+
type: event.type ?? "",
|
|
957
|
+
source: event.source ?? "",
|
|
958
|
+
visibility: event.visibility ?? "",
|
|
959
|
+
data: optionalStruct(event.data),
|
|
960
|
+
createdAt: optionalTimestamp(event.createdAt),
|
|
961
|
+
display: agentTurnDisplayToProto(event.display),
|
|
962
|
+
};
|
|
963
|
+
}
|
|
964
|
+
|
|
965
|
+
function agentInteractionToProto(
|
|
966
|
+
interaction: AgentInteraction,
|
|
967
|
+
): MessageInitShape<typeof AgentInteractionSchema> {
|
|
968
|
+
return {
|
|
969
|
+
id: interaction.id ?? "",
|
|
970
|
+
type: interaction.type ?? AgentInteractionType.UNSPECIFIED,
|
|
971
|
+
state: interaction.state ?? AgentInteractionState.UNSPECIFIED,
|
|
972
|
+
title: interaction.title ?? "",
|
|
973
|
+
prompt: interaction.prompt ?? "",
|
|
974
|
+
request: optionalStruct(interaction.request),
|
|
975
|
+
resolution: optionalStruct(interaction.resolution),
|
|
976
|
+
createdAt: optionalTimestamp(interaction.createdAt),
|
|
977
|
+
resolvedAt: optionalTimestamp(interaction.resolvedAt),
|
|
978
|
+
turnId: interaction.turnId ?? "",
|
|
979
|
+
sessionId: interaction.sessionId ?? "",
|
|
980
|
+
};
|
|
981
|
+
}
|
|
982
|
+
|
|
983
|
+
function capabilitiesToProto(
|
|
984
|
+
capabilities: AgentProviderCapabilities,
|
|
985
|
+
): MessageInitShape<typeof AgentProviderCapabilitiesSchema> {
|
|
986
|
+
return {
|
|
987
|
+
streamingText: capabilities.streamingText ?? false,
|
|
988
|
+
toolCalls: capabilities.toolCalls ?? false,
|
|
989
|
+
parallelToolCalls: capabilities.parallelToolCalls ?? false,
|
|
990
|
+
structuredOutput: capabilities.structuredOutput ?? false,
|
|
991
|
+
interactions: capabilities.interactions ?? false,
|
|
992
|
+
resumableTurns: capabilities.resumableTurns ?? false,
|
|
993
|
+
reasoningSummaries: capabilities.reasoningSummaries ?? false,
|
|
994
|
+
boundedListHydration: capabilities.boundedListHydration ?? false,
|
|
995
|
+
supportedToolSources: [...(capabilities.supportedToolSources ?? [])],
|
|
996
|
+
supportsSessionStart: capabilities.supportsSessionStart ?? false,
|
|
997
|
+
supportsPreparedWorkspace: capabilities.supportsPreparedWorkspace ?? false,
|
|
998
|
+
};
|
|
999
|
+
}
|
|
1000
|
+
|
|
1001
|
+
function resolvedAgentToolFromProto(tool: ProtoResolvedAgentTool): ResolvedAgentTool {
|
|
1002
|
+
return {
|
|
1003
|
+
id: tool.id,
|
|
1004
|
+
name: tool.name,
|
|
1005
|
+
description: tool.description,
|
|
1006
|
+
parametersSchema: optionalObjectFromStruct(tool.parametersSchema),
|
|
1007
|
+
};
|
|
397
1008
|
}
|
|
398
1009
|
|
|
399
|
-
function
|
|
400
|
-
|
|
1010
|
+
function agentSubjectFromProto(
|
|
1011
|
+
subject?: ProtoAgentSubjectContext | undefined,
|
|
1012
|
+
): AgentSubjectContext | undefined {
|
|
1013
|
+
if (subject === undefined) {
|
|
401
1014
|
return undefined;
|
|
402
1015
|
}
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
1016
|
+
return {
|
|
1017
|
+
subjectId: subject.subjectId,
|
|
1018
|
+
subjectKind: subject.subjectKind,
|
|
1019
|
+
credentialSubjectId: subject.credentialSubjectId,
|
|
1020
|
+
displayName: subject.displayName,
|
|
1021
|
+
authSource: subject.authSource,
|
|
1022
|
+
};
|
|
410
1023
|
}
|
|
411
1024
|
|
|
412
|
-
function
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
1025
|
+
function optionalTimestamp(value?: Date | undefined) {
|
|
1026
|
+
return value === undefined ? undefined : timestampFromDate(value);
|
|
1027
|
+
}
|
|
1028
|
+
|
|
1029
|
+
function executeToolRequestToProto(
|
|
1030
|
+
request: ExecuteAgentToolRequest,
|
|
1031
|
+
): ProtoExecuteAgentToolRequest {
|
|
1032
|
+
return create(ExecuteAgentToolRequestSchema, {
|
|
1033
|
+
sessionId: request.sessionId,
|
|
1034
|
+
turnId: request.turnId,
|
|
1035
|
+
toolCallId: request.toolCallId,
|
|
1036
|
+
toolId: request.toolId,
|
|
1037
|
+
arguments: optionalStruct(request.arguments),
|
|
1038
|
+
idempotencyKey: request.idempotencyKey ?? "",
|
|
1039
|
+
runGrant: request.runGrant ?? "",
|
|
1040
|
+
});
|
|
1041
|
+
}
|
|
1042
|
+
|
|
1043
|
+
function executeToolResponseFromProto(
|
|
1044
|
+
response: ProtoExecuteAgentToolResponse,
|
|
1045
|
+
): ExecuteAgentToolResponse {
|
|
1046
|
+
return {
|
|
1047
|
+
status: response.status,
|
|
1048
|
+
body: response.body,
|
|
1049
|
+
};
|
|
1050
|
+
}
|
|
1051
|
+
|
|
1052
|
+
function listToolsRequestToProto(request: ListAgentToolsRequest): ProtoListAgentToolsRequest {
|
|
1053
|
+
return create(ListAgentToolsRequestSchema, {
|
|
1054
|
+
sessionId: request.sessionId,
|
|
1055
|
+
turnId: request.turnId,
|
|
1056
|
+
pageSize: request.pageSize ?? 0,
|
|
1057
|
+
pageToken: request.pageToken ?? "",
|
|
1058
|
+
runGrant: request.runGrant ?? "",
|
|
1059
|
+
query: request.query ?? "",
|
|
1060
|
+
});
|
|
1061
|
+
}
|
|
1062
|
+
|
|
1063
|
+
function listToolsResponseFromProto(
|
|
1064
|
+
response: ProtoListAgentToolsResponse,
|
|
1065
|
+
): ListAgentToolsResponse {
|
|
1066
|
+
return {
|
|
1067
|
+
tools: response.tools.map(listedToolFromProto),
|
|
1068
|
+
nextPageToken: response.nextPageToken,
|
|
1069
|
+
};
|
|
1070
|
+
}
|
|
1071
|
+
|
|
1072
|
+
function listedToolFromProto(tool: ProtoListedAgentTool): ListedAgentTool {
|
|
1073
|
+
return {
|
|
1074
|
+
id: tool.id,
|
|
1075
|
+
mcpName: tool.mcpName,
|
|
1076
|
+
title: tool.title,
|
|
1077
|
+
description: tool.description,
|
|
1078
|
+
inputSchema: tool.inputSchema,
|
|
1079
|
+
outputSchema: tool.outputSchema,
|
|
1080
|
+
annotations: tool.annotations === undefined ? undefined : {
|
|
1081
|
+
readOnlyHint: tool.annotations.readOnlyHint,
|
|
1082
|
+
idempotentHint: tool.annotations.idempotentHint,
|
|
1083
|
+
destructiveHint: tool.annotations.destructiveHint,
|
|
1084
|
+
openWorldHint: tool.annotations.openWorldHint,
|
|
1085
|
+
},
|
|
1086
|
+
ref: tool.ref === undefined ? undefined : agentToolRefFromProto(tool.ref),
|
|
1087
|
+
tags: [...tool.tags],
|
|
1088
|
+
searchText: tool.searchText,
|
|
1089
|
+
};
|
|
1090
|
+
}
|
|
1091
|
+
|
|
1092
|
+
function resolveConnectionRequestToProto(
|
|
1093
|
+
request: ResolveAgentConnectionRequest,
|
|
1094
|
+
): ProtoResolveAgentConnectionRequest {
|
|
1095
|
+
return create(ResolveAgentConnectionRequestSchema, {
|
|
1096
|
+
sessionId: request.sessionId,
|
|
1097
|
+
turnId: request.turnId,
|
|
1098
|
+
connection: request.connection,
|
|
1099
|
+
instance: request.instance ?? "",
|
|
1100
|
+
runGrant: request.runGrant ?? "",
|
|
1101
|
+
});
|
|
1102
|
+
}
|
|
1103
|
+
|
|
1104
|
+
function resolvedConnectionFromProto(
|
|
1105
|
+
connection: ProtoResolvedAgentConnection,
|
|
1106
|
+
): ResolvedAgentConnection {
|
|
1107
|
+
return {
|
|
1108
|
+
connectionId: connection.connectionId,
|
|
1109
|
+
connection: connection.connection,
|
|
1110
|
+
instance: connection.instance,
|
|
1111
|
+
mode: connection.mode,
|
|
1112
|
+
headers: { ...connection.headers },
|
|
1113
|
+
params: { ...connection.params },
|
|
1114
|
+
expiresAt: connection.expiresAt === undefined
|
|
1115
|
+
? undefined
|
|
1116
|
+
: dateFromTimestamp(connection.expiresAt),
|
|
1117
|
+
};
|
|
423
1118
|
}
|
|
424
1119
|
|
|
425
1120
|
/** Runtime type guard for agent providers loaded from user modules. */
|
|
@@ -456,21 +1151,75 @@ export class AgentHost {
|
|
|
456
1151
|
async executeTool(
|
|
457
1152
|
request: ExecuteAgentToolRequest,
|
|
458
1153
|
): Promise<ExecuteAgentToolResponse> {
|
|
459
|
-
return
|
|
1154
|
+
return executeToolResponseFromProto(
|
|
1155
|
+
await this.client.executeTool(executeToolRequestToProto(request)),
|
|
1156
|
+
);
|
|
1157
|
+
}
|
|
1158
|
+
|
|
1159
|
+
/** Executes a host tool using plain TypeScript request fields. */
|
|
1160
|
+
async executeToolForTurn(
|
|
1161
|
+
input: AgentHostExecuteToolInput,
|
|
1162
|
+
): Promise<ExecuteAgentToolResponse> {
|
|
1163
|
+
return await this.executeTool(
|
|
1164
|
+
{
|
|
1165
|
+
sessionId: input.sessionId,
|
|
1166
|
+
turnId: input.turnId,
|
|
1167
|
+
toolCallId: input.toolCallId,
|
|
1168
|
+
toolId: input.toolId,
|
|
1169
|
+
arguments: input.arguments,
|
|
1170
|
+
runGrant: input.runGrant ?? "",
|
|
1171
|
+
idempotencyKey: input.idempotencyKey ?? "",
|
|
1172
|
+
},
|
|
1173
|
+
);
|
|
460
1174
|
}
|
|
461
1175
|
|
|
462
1176
|
/** Lists host tools visible to the current agent request. */
|
|
463
1177
|
async listTools(
|
|
464
1178
|
request: ListAgentToolsRequest,
|
|
465
1179
|
): Promise<ListAgentToolsResponse> {
|
|
466
|
-
return
|
|
1180
|
+
return listToolsResponseFromProto(
|
|
1181
|
+
await this.client.listTools(listToolsRequestToProto(request)),
|
|
1182
|
+
);
|
|
1183
|
+
}
|
|
1184
|
+
|
|
1185
|
+
/** Lists host tools using plain TypeScript request fields. */
|
|
1186
|
+
async listToolsForTurn(
|
|
1187
|
+
input: AgentHostListToolsInput,
|
|
1188
|
+
): Promise<ListAgentToolsResponse> {
|
|
1189
|
+
return await this.listTools(
|
|
1190
|
+
{
|
|
1191
|
+
sessionId: input.sessionId,
|
|
1192
|
+
turnId: input.turnId,
|
|
1193
|
+
runGrant: input.runGrant ?? "",
|
|
1194
|
+
pageSize: input.pageSize ?? 0,
|
|
1195
|
+
pageToken: input.pageToken ?? "",
|
|
1196
|
+
query: input.query ?? "",
|
|
1197
|
+
},
|
|
1198
|
+
);
|
|
467
1199
|
}
|
|
468
1200
|
|
|
469
1201
|
/** Resolves a configured agent connection for the current turn. */
|
|
470
1202
|
async resolveConnection(
|
|
471
1203
|
request: ResolveAgentConnectionRequest,
|
|
472
1204
|
): Promise<ResolvedAgentConnection> {
|
|
473
|
-
return
|
|
1205
|
+
return resolvedConnectionFromProto(
|
|
1206
|
+
await this.client.resolveConnection(resolveConnectionRequestToProto(request)),
|
|
1207
|
+
);
|
|
1208
|
+
}
|
|
1209
|
+
|
|
1210
|
+
/** Resolves an agent connection using plain TypeScript request fields. */
|
|
1211
|
+
async resolveConnectionForTurn(
|
|
1212
|
+
input: AgentHostResolveConnectionInput,
|
|
1213
|
+
): Promise<ResolvedAgentConnection> {
|
|
1214
|
+
return await this.resolveConnection(
|
|
1215
|
+
{
|
|
1216
|
+
sessionId: input.sessionId,
|
|
1217
|
+
turnId: input.turnId,
|
|
1218
|
+
connection: input.connection,
|
|
1219
|
+
instance: input.instance ?? "",
|
|
1220
|
+
runGrant: input.runGrant ?? "",
|
|
1221
|
+
},
|
|
1222
|
+
);
|
|
474
1223
|
}
|
|
475
1224
|
}
|
|
476
1225
|
|
|
@@ -533,106 +1282,156 @@ export function createAgentProviderService(
|
|
|
533
1282
|
async createSession(request) {
|
|
534
1283
|
return create(
|
|
535
1284
|
AgentSessionSchema,
|
|
536
|
-
|
|
537
|
-
|
|
1285
|
+
agentSessionToProto(
|
|
1286
|
+
await invokeAgentProvider("create session", () =>
|
|
1287
|
+
provider.createSession(createAgentProviderSessionRequestFromProto(request)),
|
|
1288
|
+
),
|
|
538
1289
|
),
|
|
539
1290
|
);
|
|
540
1291
|
},
|
|
541
1292
|
async getSession(request) {
|
|
542
1293
|
return create(
|
|
543
1294
|
AgentSessionSchema,
|
|
544
|
-
|
|
545
|
-
|
|
1295
|
+
agentSessionToProto(
|
|
1296
|
+
await invokeAgentProvider("get session", () =>
|
|
1297
|
+
provider.getSession(getAgentProviderSessionRequestFromProto(request)),
|
|
1298
|
+
),
|
|
546
1299
|
),
|
|
547
1300
|
);
|
|
548
1301
|
},
|
|
549
1302
|
async listSessions(request) {
|
|
1303
|
+
const response = await invokeAgentProvider("list sessions", () =>
|
|
1304
|
+
provider.listSessions(listAgentProviderSessionsRequestFromProto(request)),
|
|
1305
|
+
);
|
|
550
1306
|
return create(ListAgentProviderSessionsResponseSchema, {
|
|
551
|
-
sessions:
|
|
552
|
-
provider.listSessions(request),
|
|
553
|
-
),
|
|
1307
|
+
sessions: listSessionsResult(response).map(agentSessionToProto),
|
|
554
1308
|
});
|
|
555
1309
|
},
|
|
556
1310
|
async updateSession(request) {
|
|
557
1311
|
return create(
|
|
558
1312
|
AgentSessionSchema,
|
|
559
|
-
|
|
560
|
-
|
|
1313
|
+
agentSessionToProto(
|
|
1314
|
+
await invokeAgentProvider("update session", () =>
|
|
1315
|
+
provider.updateSession(updateAgentProviderSessionRequestFromProto(request)),
|
|
1316
|
+
),
|
|
561
1317
|
),
|
|
562
1318
|
);
|
|
563
1319
|
},
|
|
564
1320
|
async createTurn(request) {
|
|
565
1321
|
return create(
|
|
566
1322
|
AgentTurnSchema,
|
|
567
|
-
|
|
568
|
-
|
|
1323
|
+
agentTurnToProto(
|
|
1324
|
+
await invokeAgentProvider("create turn", () =>
|
|
1325
|
+
provider.createTurn(createAgentProviderTurnRequestFromProto(request)),
|
|
1326
|
+
),
|
|
569
1327
|
),
|
|
570
1328
|
);
|
|
571
1329
|
},
|
|
572
1330
|
async getTurn(request) {
|
|
573
1331
|
return create(
|
|
574
1332
|
AgentTurnSchema,
|
|
575
|
-
|
|
1333
|
+
agentTurnToProto(
|
|
1334
|
+
await invokeAgentProvider("get turn", () =>
|
|
1335
|
+
provider.getTurn(getAgentProviderTurnRequestFromProto(request)),
|
|
1336
|
+
),
|
|
1337
|
+
),
|
|
576
1338
|
);
|
|
577
1339
|
},
|
|
578
1340
|
async listTurns(request) {
|
|
1341
|
+
const response = await invokeAgentProvider("list turns", () =>
|
|
1342
|
+
provider.listTurns(listAgentProviderTurnsRequestFromProto(request)),
|
|
1343
|
+
);
|
|
579
1344
|
return create(ListAgentProviderTurnsResponseSchema, {
|
|
580
|
-
turns:
|
|
581
|
-
provider.listTurns(request),
|
|
582
|
-
),
|
|
1345
|
+
turns: listTurnsResult(response).map(agentTurnToProto),
|
|
583
1346
|
});
|
|
584
1347
|
},
|
|
585
1348
|
async cancelTurn(request) {
|
|
586
1349
|
return create(
|
|
587
1350
|
AgentTurnSchema,
|
|
588
|
-
|
|
589
|
-
|
|
1351
|
+
agentTurnToProto(
|
|
1352
|
+
await invokeAgentProvider("cancel turn", () =>
|
|
1353
|
+
provider.cancelTurn(cancelAgentProviderTurnRequestFromProto(request)),
|
|
1354
|
+
),
|
|
590
1355
|
),
|
|
591
1356
|
);
|
|
592
1357
|
},
|
|
593
1358
|
async listTurnEvents(request) {
|
|
1359
|
+
const response = await invokeAgentProvider("list turn events", () =>
|
|
1360
|
+
provider.listTurnEvents(listAgentProviderTurnEventsRequestFromProto(request)),
|
|
1361
|
+
);
|
|
594
1362
|
return create(ListAgentProviderTurnEventsResponseSchema, {
|
|
595
|
-
events:
|
|
596
|
-
await invokeAgentProvider("list turn events", () =>
|
|
597
|
-
provider.listTurnEvents(request),
|
|
598
|
-
),
|
|
599
|
-
),
|
|
1363
|
+
events: listTurnEventsResult(response).map(agentTurnEventToProto),
|
|
600
1364
|
});
|
|
601
1365
|
},
|
|
602
1366
|
async getInteraction(request) {
|
|
603
1367
|
return create(
|
|
604
1368
|
AgentInteractionSchema,
|
|
605
|
-
|
|
606
|
-
|
|
1369
|
+
agentInteractionToProto(
|
|
1370
|
+
await invokeAgentProvider("get interaction", () =>
|
|
1371
|
+
provider.getInteraction(getAgentProviderInteractionRequestFromProto(request)),
|
|
1372
|
+
),
|
|
607
1373
|
),
|
|
608
1374
|
);
|
|
609
1375
|
},
|
|
610
1376
|
async listInteractions(request) {
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
1377
|
+
const response = await invokeAgentProvider("list interactions", () =>
|
|
1378
|
+
provider.listInteractions(
|
|
1379
|
+
listAgentProviderInteractionsRequestFromProto(request),
|
|
614
1380
|
),
|
|
1381
|
+
);
|
|
1382
|
+
return create(ListAgentProviderInteractionsResponseSchema, {
|
|
1383
|
+
interactions: listInteractionsResult(response).map(agentInteractionToProto),
|
|
615
1384
|
});
|
|
616
1385
|
},
|
|
617
1386
|
async resolveInteraction(request) {
|
|
618
1387
|
return create(
|
|
619
1388
|
AgentInteractionSchema,
|
|
620
|
-
|
|
621
|
-
|
|
1389
|
+
agentInteractionToProto(
|
|
1390
|
+
await invokeAgentProvider("resolve interaction", () =>
|
|
1391
|
+
provider.resolveInteraction(
|
|
1392
|
+
resolveAgentProviderInteractionRequestFromProto(request),
|
|
1393
|
+
),
|
|
1394
|
+
),
|
|
622
1395
|
),
|
|
623
1396
|
);
|
|
624
1397
|
},
|
|
625
1398
|
async getCapabilities(request) {
|
|
626
1399
|
return create(
|
|
627
1400
|
AgentProviderCapabilitiesSchema,
|
|
628
|
-
|
|
629
|
-
|
|
1401
|
+
capabilitiesToProto(
|
|
1402
|
+
await invokeAgentProvider("get capabilities", () =>
|
|
1403
|
+
provider.getCapabilities({}),
|
|
1404
|
+
),
|
|
630
1405
|
),
|
|
631
1406
|
);
|
|
632
1407
|
},
|
|
633
1408
|
};
|
|
634
1409
|
}
|
|
635
1410
|
|
|
1411
|
+
function listSessionsResult(
|
|
1412
|
+
value: readonly AgentSession[] | ListAgentProviderSessionsResponse,
|
|
1413
|
+
): readonly AgentSession[] {
|
|
1414
|
+
return "sessions" in value ? value.sessions : value;
|
|
1415
|
+
}
|
|
1416
|
+
|
|
1417
|
+
function listTurnsResult(
|
|
1418
|
+
value: readonly AgentTurn[] | ListAgentProviderTurnsResponse,
|
|
1419
|
+
): readonly AgentTurn[] {
|
|
1420
|
+
return "turns" in value ? value.turns : value;
|
|
1421
|
+
}
|
|
1422
|
+
|
|
1423
|
+
function listTurnEventsResult(
|
|
1424
|
+
value: readonly AgentTurnEvent[] | ListAgentProviderTurnEventsResponse,
|
|
1425
|
+
): readonly AgentTurnEvent[] {
|
|
1426
|
+
return "events" in value ? value.events : value;
|
|
1427
|
+
}
|
|
1428
|
+
|
|
1429
|
+
function listInteractionsResult(
|
|
1430
|
+
value: readonly AgentInteraction[] | ListAgentProviderInteractionsResponse,
|
|
1431
|
+
): readonly AgentInteraction[] {
|
|
1432
|
+
return "interactions" in value ? value.interactions : value;
|
|
1433
|
+
}
|
|
1434
|
+
|
|
636
1435
|
async function requireAgentProviderHandler<Request, Response>(
|
|
637
1436
|
action: string,
|
|
638
1437
|
fn: ((request: Request) => MaybePromise<Response>) | undefined,
|