@valon-technologies/gestalt 0.0.1-alpha.17 → 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 +1029 -219
- package/src/api.ts +54 -0
- package/src/auth.ts +3 -3
- package/src/authorization.ts +1702 -52
- package/src/cache.ts +5 -4
- package/src/catalog.ts +22 -0
- package/src/http-subject.ts +13 -2
- package/src/index.ts +194 -17
- package/src/indexeddb.ts +5 -16
- package/src/internal/gen/v1/agent_pb.ts +353 -74
- package/src/internal/gen/v1/authentication_pb.ts +1 -1
- package/src/internal/gen/v1/authorization_pb.ts +505 -27
- package/src/internal/gen/v1/cache_pb.ts +1 -1
- package/src/internal/gen/v1/datastore_pb.ts +1 -1
- package/src/internal/gen/v1/external_credential_pb.ts +434 -29
- package/src/internal/gen/v1/plugin_pb.ts +92 -22
- package/src/internal/gen/v1/pluginruntime_pb.ts +95 -6
- package/src/internal/gen/v1/runtime_pb.ts +1 -1
- package/src/internal/gen/v1/s3_pb.ts +1 -1
- package/src/internal/gen/v1/secrets_pb.ts +1 -1
- package/src/internal/gen/v1/workflow_pb.ts +349 -67
- 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 +81 -53
- package/src/runtime.ts +72 -0
- package/src/s3.ts +15 -29
- 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,60 +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 ResolvedAgentTool,
|
|
70
|
-
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,
|
|
71
68
|
} from "./internal/gen/v1/agent_pb.ts";
|
|
72
69
|
import { errorMessage, type MaybePromise } from "./api.ts";
|
|
73
|
-
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";
|
|
74
89
|
|
|
75
90
|
/** Environment variable containing the agent-host service target. */
|
|
76
91
|
export const ENV_AGENT_HOST_SOCKET = "GESTALT_AGENT_HOST_SOCKET";
|
|
@@ -78,124 +93,496 @@ export const ENV_AGENT_HOST_SOCKET = "GESTALT_AGENT_HOST_SOCKET";
|
|
|
78
93
|
export const ENV_AGENT_HOST_SOCKET_TOKEN = `${ENV_AGENT_HOST_SOCKET}_TOKEN`;
|
|
79
94
|
const AGENT_HOST_RELAY_TOKEN_HEADER = "x-gestalt-host-service-relay-token";
|
|
80
95
|
|
|
81
|
-
/**
|
|
82
|
-
|
|
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
|
-
|
|
152
|
-
|
|
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
|
+
}
|
|
153
540
|
|
|
154
541
|
/** Handlers and runtime metadata for an agent provider. */
|
|
155
|
-
export interface AgentProviderOptions extends
|
|
542
|
+
export interface AgentProviderOptions extends ProviderBaseOptions {
|
|
156
543
|
createSession?: (
|
|
157
544
|
request: CreateAgentProviderSessionRequest,
|
|
158
|
-
) => MaybePromise<
|
|
545
|
+
) => MaybePromise<AgentSession>;
|
|
159
546
|
getSession?: (
|
|
160
547
|
request: GetAgentProviderSessionRequest,
|
|
161
|
-
) => MaybePromise<
|
|
548
|
+
) => MaybePromise<AgentSession>;
|
|
162
549
|
listSessions?: (
|
|
163
550
|
request: ListAgentProviderSessionsRequest,
|
|
164
|
-
) => MaybePromise<
|
|
551
|
+
) => MaybePromise<readonly AgentSession[] | ListAgentProviderSessionsResponse>;
|
|
165
552
|
updateSession?: (
|
|
166
553
|
request: UpdateAgentProviderSessionRequest,
|
|
167
|
-
) => MaybePromise<
|
|
554
|
+
) => MaybePromise<AgentSession>;
|
|
168
555
|
createTurn?: (
|
|
169
556
|
request: CreateAgentProviderTurnRequest,
|
|
170
|
-
) => MaybePromise<
|
|
557
|
+
) => MaybePromise<AgentTurn>;
|
|
171
558
|
getTurn?: (
|
|
172
559
|
request: GetAgentProviderTurnRequest,
|
|
173
|
-
) => MaybePromise<
|
|
560
|
+
) => MaybePromise<AgentTurn>;
|
|
174
561
|
listTurns?: (
|
|
175
562
|
request: ListAgentProviderTurnsRequest,
|
|
176
|
-
) => MaybePromise<
|
|
563
|
+
) => MaybePromise<readonly AgentTurn[] | ListAgentProviderTurnsResponse>;
|
|
177
564
|
cancelTurn?: (
|
|
178
565
|
request: CancelAgentProviderTurnRequest,
|
|
179
|
-
) => MaybePromise<
|
|
566
|
+
) => MaybePromise<AgentTurn>;
|
|
180
567
|
listTurnEvents?: (
|
|
181
568
|
request: ListAgentProviderTurnEventsRequest,
|
|
182
|
-
) => MaybePromise<
|
|
569
|
+
) => MaybePromise<readonly AgentTurnEvent[] | ListAgentProviderTurnEventsResponse>;
|
|
183
570
|
getInteraction?: (
|
|
184
571
|
request: GetAgentProviderInteractionRequest,
|
|
185
|
-
) => MaybePromise<
|
|
572
|
+
) => MaybePromise<AgentInteraction>;
|
|
186
573
|
listInteractions?: (
|
|
187
574
|
request: ListAgentProviderInteractionsRequest,
|
|
188
|
-
) => MaybePromise<
|
|
575
|
+
) => MaybePromise<readonly AgentInteraction[] | ListAgentProviderInteractionsResponse>;
|
|
189
576
|
resolveInteraction?: (
|
|
190
577
|
request: ResolveAgentProviderInteractionRequest,
|
|
191
|
-
) => MaybePromise<
|
|
578
|
+
) => MaybePromise<AgentInteraction>;
|
|
192
579
|
getCapabilities?: (
|
|
193
580
|
request: GetAgentProviderCapabilitiesRequest,
|
|
194
|
-
) => MaybePromise<
|
|
581
|
+
) => MaybePromise<AgentProviderCapabilities>;
|
|
195
582
|
}
|
|
196
583
|
|
|
197
584
|
/** Runtime provider implementation for the Gestalt agent host contract. */
|
|
198
|
-
export class AgentProvider extends
|
|
585
|
+
export class AgentProvider extends ProviderBase {
|
|
199
586
|
readonly kind = "agent" as const;
|
|
200
587
|
|
|
201
588
|
private readonly createSessionHandler: AgentProviderOptions["createSession"];
|
|
@@ -231,7 +618,7 @@ export class AgentProvider extends RuntimeProvider {
|
|
|
231
618
|
|
|
232
619
|
async createSession(
|
|
233
620
|
request: CreateAgentProviderSessionRequest,
|
|
234
|
-
): Promise<
|
|
621
|
+
): Promise<AgentSession> {
|
|
235
622
|
return await requireAgentProviderHandler(
|
|
236
623
|
"create session",
|
|
237
624
|
this.createSessionHandler,
|
|
@@ -241,7 +628,7 @@ export class AgentProvider extends RuntimeProvider {
|
|
|
241
628
|
|
|
242
629
|
async getSession(
|
|
243
630
|
request: GetAgentProviderSessionRequest,
|
|
244
|
-
): Promise<
|
|
631
|
+
): Promise<AgentSession> {
|
|
245
632
|
return await requireAgentProviderHandler(
|
|
246
633
|
"get session",
|
|
247
634
|
this.getSessionHandler,
|
|
@@ -251,7 +638,7 @@ export class AgentProvider extends RuntimeProvider {
|
|
|
251
638
|
|
|
252
639
|
async listSessions(
|
|
253
640
|
request: ListAgentProviderSessionsRequest,
|
|
254
|
-
): Promise<
|
|
641
|
+
): Promise<readonly AgentSession[] | ListAgentProviderSessionsResponse> {
|
|
255
642
|
return await requireAgentProviderHandler(
|
|
256
643
|
"list sessions",
|
|
257
644
|
this.listSessionsHandler,
|
|
@@ -261,7 +648,7 @@ export class AgentProvider extends RuntimeProvider {
|
|
|
261
648
|
|
|
262
649
|
async updateSession(
|
|
263
650
|
request: UpdateAgentProviderSessionRequest,
|
|
264
|
-
): Promise<
|
|
651
|
+
): Promise<AgentSession> {
|
|
265
652
|
return await requireAgentProviderHandler(
|
|
266
653
|
"update session",
|
|
267
654
|
this.updateSessionHandler,
|
|
@@ -271,7 +658,7 @@ export class AgentProvider extends RuntimeProvider {
|
|
|
271
658
|
|
|
272
659
|
async createTurn(
|
|
273
660
|
request: CreateAgentProviderTurnRequest,
|
|
274
|
-
): Promise<
|
|
661
|
+
): Promise<AgentTurn> {
|
|
275
662
|
return await requireAgentProviderHandler(
|
|
276
663
|
"create turn",
|
|
277
664
|
this.createTurnHandler,
|
|
@@ -281,7 +668,7 @@ export class AgentProvider extends RuntimeProvider {
|
|
|
281
668
|
|
|
282
669
|
async getTurn(
|
|
283
670
|
request: GetAgentProviderTurnRequest,
|
|
284
|
-
): Promise<
|
|
671
|
+
): Promise<AgentTurn> {
|
|
285
672
|
return await requireAgentProviderHandler(
|
|
286
673
|
"get turn",
|
|
287
674
|
this.getTurnHandler,
|
|
@@ -291,7 +678,7 @@ export class AgentProvider extends RuntimeProvider {
|
|
|
291
678
|
|
|
292
679
|
async listTurns(
|
|
293
680
|
request: ListAgentProviderTurnsRequest,
|
|
294
|
-
): Promise<
|
|
681
|
+
): Promise<readonly AgentTurn[] | ListAgentProviderTurnsResponse> {
|
|
295
682
|
return await requireAgentProviderHandler(
|
|
296
683
|
"list turns",
|
|
297
684
|
this.listTurnsHandler,
|
|
@@ -301,7 +688,7 @@ export class AgentProvider extends RuntimeProvider {
|
|
|
301
688
|
|
|
302
689
|
async cancelTurn(
|
|
303
690
|
request: CancelAgentProviderTurnRequest,
|
|
304
|
-
): Promise<
|
|
691
|
+
): Promise<AgentTurn> {
|
|
305
692
|
return await requireAgentProviderHandler(
|
|
306
693
|
"cancel turn",
|
|
307
694
|
this.cancelTurnHandler,
|
|
@@ -311,7 +698,7 @@ export class AgentProvider extends RuntimeProvider {
|
|
|
311
698
|
|
|
312
699
|
async listTurnEvents(
|
|
313
700
|
request: ListAgentProviderTurnEventsRequest,
|
|
314
|
-
): Promise<
|
|
701
|
+
): Promise<readonly AgentTurnEvent[] | ListAgentProviderTurnEventsResponse> {
|
|
315
702
|
return await requireAgentProviderHandler(
|
|
316
703
|
"list turn events",
|
|
317
704
|
this.listTurnEventsHandler,
|
|
@@ -321,7 +708,7 @@ export class AgentProvider extends RuntimeProvider {
|
|
|
321
708
|
|
|
322
709
|
async getInteraction(
|
|
323
710
|
request: GetAgentProviderInteractionRequest,
|
|
324
|
-
): Promise<
|
|
711
|
+
): Promise<AgentInteraction> {
|
|
325
712
|
return await requireAgentProviderHandler(
|
|
326
713
|
"get interaction",
|
|
327
714
|
this.getInteractionHandler,
|
|
@@ -331,7 +718,7 @@ export class AgentProvider extends RuntimeProvider {
|
|
|
331
718
|
|
|
332
719
|
async listInteractions(
|
|
333
720
|
request: ListAgentProviderInteractionsRequest,
|
|
334
|
-
): Promise<
|
|
721
|
+
): Promise<readonly AgentInteraction[] | ListAgentProviderInteractionsResponse> {
|
|
335
722
|
return await requireAgentProviderHandler(
|
|
336
723
|
"list interactions",
|
|
337
724
|
this.listInteractionsHandler,
|
|
@@ -341,7 +728,7 @@ export class AgentProvider extends RuntimeProvider {
|
|
|
341
728
|
|
|
342
729
|
async resolveInteraction(
|
|
343
730
|
request: ResolveAgentProviderInteractionRequest,
|
|
344
|
-
): Promise<
|
|
731
|
+
): Promise<AgentInteraction> {
|
|
345
732
|
return await requireAgentProviderHandler(
|
|
346
733
|
"resolve interaction",
|
|
347
734
|
this.resolveInteractionHandler,
|
|
@@ -350,11 +737,8 @@ export class AgentProvider extends RuntimeProvider {
|
|
|
350
737
|
}
|
|
351
738
|
|
|
352
739
|
async getCapabilities(
|
|
353
|
-
request: GetAgentProviderCapabilitiesRequest =
|
|
354
|
-
|
|
355
|
-
{},
|
|
356
|
-
),
|
|
357
|
-
): Promise<MessageInitShape<typeof AgentProviderCapabilitiesSchema>> {
|
|
740
|
+
request: GetAgentProviderCapabilitiesRequest = {},
|
|
741
|
+
): Promise<AgentProviderCapabilities> {
|
|
358
742
|
return await requireAgentProviderHandler(
|
|
359
743
|
"get capabilities",
|
|
360
744
|
this.getCapabilitiesHandler,
|
|
@@ -368,54 +752,369 @@ export function defineAgentProvider(options: AgentProviderOptions): AgentProvide
|
|
|
368
752
|
return new AgentProvider(options);
|
|
369
753
|
}
|
|
370
754
|
|
|
371
|
-
function
|
|
372
|
-
|
|
373
|
-
):
|
|
374
|
-
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
|
+
};
|
|
375
818
|
}
|
|
376
819
|
|
|
377
|
-
function
|
|
378
|
-
|
|
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
|
+
};
|
|
883
|
+
}
|
|
884
|
+
|
|
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,
|
|
379
951
|
): MessageInitShape<typeof AgentTurnEventSchema> {
|
|
380
|
-
const display = event.display;
|
|
381
|
-
if (!display) {
|
|
382
|
-
return event as MessageInitShape<typeof AgentTurnEventSchema>;
|
|
383
|
-
}
|
|
384
952
|
return {
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
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
|
+
};
|
|
393
1008
|
}
|
|
394
1009
|
|
|
395
|
-
function
|
|
396
|
-
|
|
1010
|
+
function agentSubjectFromProto(
|
|
1011
|
+
subject?: ProtoAgentSubjectContext | undefined,
|
|
1012
|
+
): AgentSubjectContext | undefined {
|
|
1013
|
+
if (subject === undefined) {
|
|
397
1014
|
return undefined;
|
|
398
1015
|
}
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
1016
|
+
return {
|
|
1017
|
+
subjectId: subject.subjectId,
|
|
1018
|
+
subjectKind: subject.subjectKind,
|
|
1019
|
+
credentialSubjectId: subject.credentialSubjectId,
|
|
1020
|
+
displayName: subject.displayName,
|
|
1021
|
+
authSource: subject.authSource,
|
|
1022
|
+
};
|
|
406
1023
|
}
|
|
407
1024
|
|
|
408
|
-
function
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
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
|
+
};
|
|
419
1118
|
}
|
|
420
1119
|
|
|
421
1120
|
/** Runtime type guard for agent providers loaded from user modules. */
|
|
@@ -452,14 +1151,75 @@ export class AgentHost {
|
|
|
452
1151
|
async executeTool(
|
|
453
1152
|
request: ExecuteAgentToolRequest,
|
|
454
1153
|
): Promise<ExecuteAgentToolResponse> {
|
|
455
|
-
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
|
+
);
|
|
456
1174
|
}
|
|
457
1175
|
|
|
458
1176
|
/** Lists host tools visible to the current agent request. */
|
|
459
1177
|
async listTools(
|
|
460
1178
|
request: ListAgentToolsRequest,
|
|
461
1179
|
): Promise<ListAgentToolsResponse> {
|
|
462
|
-
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
|
+
);
|
|
1199
|
+
}
|
|
1200
|
+
|
|
1201
|
+
/** Resolves a configured agent connection for the current turn. */
|
|
1202
|
+
async resolveConnection(
|
|
1203
|
+
request: ResolveAgentConnectionRequest,
|
|
1204
|
+
): Promise<ResolvedAgentConnection> {
|
|
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
|
+
);
|
|
463
1223
|
}
|
|
464
1224
|
}
|
|
465
1225
|
|
|
@@ -522,106 +1282,156 @@ export function createAgentProviderService(
|
|
|
522
1282
|
async createSession(request) {
|
|
523
1283
|
return create(
|
|
524
1284
|
AgentSessionSchema,
|
|
525
|
-
|
|
526
|
-
|
|
1285
|
+
agentSessionToProto(
|
|
1286
|
+
await invokeAgentProvider("create session", () =>
|
|
1287
|
+
provider.createSession(createAgentProviderSessionRequestFromProto(request)),
|
|
1288
|
+
),
|
|
527
1289
|
),
|
|
528
1290
|
);
|
|
529
1291
|
},
|
|
530
1292
|
async getSession(request) {
|
|
531
1293
|
return create(
|
|
532
1294
|
AgentSessionSchema,
|
|
533
|
-
|
|
534
|
-
|
|
1295
|
+
agentSessionToProto(
|
|
1296
|
+
await invokeAgentProvider("get session", () =>
|
|
1297
|
+
provider.getSession(getAgentProviderSessionRequestFromProto(request)),
|
|
1298
|
+
),
|
|
535
1299
|
),
|
|
536
1300
|
);
|
|
537
1301
|
},
|
|
538
1302
|
async listSessions(request) {
|
|
1303
|
+
const response = await invokeAgentProvider("list sessions", () =>
|
|
1304
|
+
provider.listSessions(listAgentProviderSessionsRequestFromProto(request)),
|
|
1305
|
+
);
|
|
539
1306
|
return create(ListAgentProviderSessionsResponseSchema, {
|
|
540
|
-
sessions:
|
|
541
|
-
provider.listSessions(request),
|
|
542
|
-
),
|
|
1307
|
+
sessions: listSessionsResult(response).map(agentSessionToProto),
|
|
543
1308
|
});
|
|
544
1309
|
},
|
|
545
1310
|
async updateSession(request) {
|
|
546
1311
|
return create(
|
|
547
1312
|
AgentSessionSchema,
|
|
548
|
-
|
|
549
|
-
|
|
1313
|
+
agentSessionToProto(
|
|
1314
|
+
await invokeAgentProvider("update session", () =>
|
|
1315
|
+
provider.updateSession(updateAgentProviderSessionRequestFromProto(request)),
|
|
1316
|
+
),
|
|
550
1317
|
),
|
|
551
1318
|
);
|
|
552
1319
|
},
|
|
553
1320
|
async createTurn(request) {
|
|
554
1321
|
return create(
|
|
555
1322
|
AgentTurnSchema,
|
|
556
|
-
|
|
557
|
-
|
|
1323
|
+
agentTurnToProto(
|
|
1324
|
+
await invokeAgentProvider("create turn", () =>
|
|
1325
|
+
provider.createTurn(createAgentProviderTurnRequestFromProto(request)),
|
|
1326
|
+
),
|
|
558
1327
|
),
|
|
559
1328
|
);
|
|
560
1329
|
},
|
|
561
1330
|
async getTurn(request) {
|
|
562
1331
|
return create(
|
|
563
1332
|
AgentTurnSchema,
|
|
564
|
-
|
|
1333
|
+
agentTurnToProto(
|
|
1334
|
+
await invokeAgentProvider("get turn", () =>
|
|
1335
|
+
provider.getTurn(getAgentProviderTurnRequestFromProto(request)),
|
|
1336
|
+
),
|
|
1337
|
+
),
|
|
565
1338
|
);
|
|
566
1339
|
},
|
|
567
1340
|
async listTurns(request) {
|
|
1341
|
+
const response = await invokeAgentProvider("list turns", () =>
|
|
1342
|
+
provider.listTurns(listAgentProviderTurnsRequestFromProto(request)),
|
|
1343
|
+
);
|
|
568
1344
|
return create(ListAgentProviderTurnsResponseSchema, {
|
|
569
|
-
turns:
|
|
570
|
-
provider.listTurns(request),
|
|
571
|
-
),
|
|
1345
|
+
turns: listTurnsResult(response).map(agentTurnToProto),
|
|
572
1346
|
});
|
|
573
1347
|
},
|
|
574
1348
|
async cancelTurn(request) {
|
|
575
1349
|
return create(
|
|
576
1350
|
AgentTurnSchema,
|
|
577
|
-
|
|
578
|
-
|
|
1351
|
+
agentTurnToProto(
|
|
1352
|
+
await invokeAgentProvider("cancel turn", () =>
|
|
1353
|
+
provider.cancelTurn(cancelAgentProviderTurnRequestFromProto(request)),
|
|
1354
|
+
),
|
|
579
1355
|
),
|
|
580
1356
|
);
|
|
581
1357
|
},
|
|
582
1358
|
async listTurnEvents(request) {
|
|
1359
|
+
const response = await invokeAgentProvider("list turn events", () =>
|
|
1360
|
+
provider.listTurnEvents(listAgentProviderTurnEventsRequestFromProto(request)),
|
|
1361
|
+
);
|
|
583
1362
|
return create(ListAgentProviderTurnEventsResponseSchema, {
|
|
584
|
-
events:
|
|
585
|
-
await invokeAgentProvider("list turn events", () =>
|
|
586
|
-
provider.listTurnEvents(request),
|
|
587
|
-
),
|
|
588
|
-
),
|
|
1363
|
+
events: listTurnEventsResult(response).map(agentTurnEventToProto),
|
|
589
1364
|
});
|
|
590
1365
|
},
|
|
591
1366
|
async getInteraction(request) {
|
|
592
1367
|
return create(
|
|
593
1368
|
AgentInteractionSchema,
|
|
594
|
-
|
|
595
|
-
|
|
1369
|
+
agentInteractionToProto(
|
|
1370
|
+
await invokeAgentProvider("get interaction", () =>
|
|
1371
|
+
provider.getInteraction(getAgentProviderInteractionRequestFromProto(request)),
|
|
1372
|
+
),
|
|
596
1373
|
),
|
|
597
1374
|
);
|
|
598
1375
|
},
|
|
599
1376
|
async listInteractions(request) {
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
1377
|
+
const response = await invokeAgentProvider("list interactions", () =>
|
|
1378
|
+
provider.listInteractions(
|
|
1379
|
+
listAgentProviderInteractionsRequestFromProto(request),
|
|
603
1380
|
),
|
|
1381
|
+
);
|
|
1382
|
+
return create(ListAgentProviderInteractionsResponseSchema, {
|
|
1383
|
+
interactions: listInteractionsResult(response).map(agentInteractionToProto),
|
|
604
1384
|
});
|
|
605
1385
|
},
|
|
606
1386
|
async resolveInteraction(request) {
|
|
607
1387
|
return create(
|
|
608
1388
|
AgentInteractionSchema,
|
|
609
|
-
|
|
610
|
-
|
|
1389
|
+
agentInteractionToProto(
|
|
1390
|
+
await invokeAgentProvider("resolve interaction", () =>
|
|
1391
|
+
provider.resolveInteraction(
|
|
1392
|
+
resolveAgentProviderInteractionRequestFromProto(request),
|
|
1393
|
+
),
|
|
1394
|
+
),
|
|
611
1395
|
),
|
|
612
1396
|
);
|
|
613
1397
|
},
|
|
614
1398
|
async getCapabilities(request) {
|
|
615
1399
|
return create(
|
|
616
1400
|
AgentProviderCapabilitiesSchema,
|
|
617
|
-
|
|
618
|
-
|
|
1401
|
+
capabilitiesToProto(
|
|
1402
|
+
await invokeAgentProvider("get capabilities", () =>
|
|
1403
|
+
provider.getCapabilities({}),
|
|
1404
|
+
),
|
|
619
1405
|
),
|
|
620
1406
|
);
|
|
621
1407
|
},
|
|
622
1408
|
};
|
|
623
1409
|
}
|
|
624
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
|
+
|
|
625
1435
|
async function requireAgentProviderHandler<Request, Response>(
|
|
626
1436
|
action: string,
|
|
627
1437
|
fn: ((request: Request) => MaybePromise<Response>) | undefined,
|