@gea-ai/agent-sdk 0.1.261010-alpha.0 → 0.1.261012-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agent-call.d.ts +52 -26
- package/dist/agent-call.js +36 -11
- package/dist/agent-channel-author-runtime.d.ts +13 -13
- package/dist/agent-run-host.d.ts +8 -0
- package/dist/agent-run-host.js +49 -2
- package/dist/agent-session-children.js +3 -1
- package/dist/agent-session-execution.d.ts +87 -1
- package/dist/agent-session-execution.js +227 -44
- package/dist/agent-session-inbox.d.ts +160 -0
- package/dist/agent-session-inbox.js +981 -42
- package/dist/agent-session-runner.d.ts +3 -0
- package/dist/agent-session-runner.js +10 -0
- package/dist/agent-session.js +152 -8
- package/dist/agent-worker-context.d.ts +4 -0
- package/dist/agent-worker-context.js +18 -0
- package/dist/agent-worker.js +260 -76
- package/dist/session-authority.d.ts +44 -1
- package/dist/session-authority.js +2 -2
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +2 -2
package/dist/agent-call.d.ts
CHANGED
|
@@ -1,6 +1,32 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
1
2
|
import { type AgentWorkerToolInitialization } from "@gea-ai/contract/agent-worker-tools";
|
|
2
3
|
import type { AgentHostBinding } from "./agent-worker.js";
|
|
3
4
|
import type { StudioArtifactScope } from "@gea-ai/contract/studio-artifacts";
|
|
5
|
+
/** Fresh Sessions keep the declared-target rule. A resume only needs sessionId. */
|
|
6
|
+
export declare function workerAgentToolInputSchema(input: {
|
|
7
|
+
agents: NonNullable<AgentWorkerToolInitialization["agents"]>;
|
|
8
|
+
canCopy?: boolean;
|
|
9
|
+
artifactScope?: StudioArtifactScope;
|
|
10
|
+
}): z.ZodObject<{
|
|
11
|
+
sessionId: z.ZodOptional<z.ZodUUID>;
|
|
12
|
+
target: z.ZodOptional<z.ZodString>;
|
|
13
|
+
message: z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
14
|
+
role: z.ZodLiteral<"user">;
|
|
15
|
+
parts: z.ZodArray<z.ZodObject<{
|
|
16
|
+
type: z.ZodLiteral<"text">;
|
|
17
|
+
text: z.ZodString;
|
|
18
|
+
}, z.core.$strict>>;
|
|
19
|
+
}, z.core.$strict>]> | z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
20
|
+
role: z.ZodLiteral<"user">;
|
|
21
|
+
parts: z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
|
|
22
|
+
type: z.ZodLiteral<"text">;
|
|
23
|
+
text: z.ZodString;
|
|
24
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
25
|
+
type: z.ZodLiteral<"file">;
|
|
26
|
+
file_id: z.ZodUUID;
|
|
27
|
+
}, z.core.$strict>]>>;
|
|
28
|
+
}, z.core.$strict>]>;
|
|
29
|
+
}, z.core.$strip>;
|
|
4
30
|
/** The host opens a fresh Worker invocation; only its visible answer returns to the caller. */
|
|
5
31
|
export declare function createWorkerAgentTool(input: {
|
|
6
32
|
agents: NonNullable<AgentWorkerToolInitialization["agents"]>;
|
|
@@ -14,7 +40,7 @@ export declare function createWorkerAgentTool(input: {
|
|
|
14
40
|
metadata?: import("@ai-sdk/provider").JSONObject;
|
|
15
41
|
inputSchema: import("ai").FlexibleSchema<{
|
|
16
42
|
sessionId?: string | undefined;
|
|
17
|
-
target
|
|
43
|
+
target?: string | undefined;
|
|
18
44
|
message: string | {
|
|
19
45
|
role: "user";
|
|
20
46
|
parts: ({
|
|
@@ -35,7 +61,7 @@ export declare function createWorkerAgentTool(input: {
|
|
|
35
61
|
contextSchema?: import("ai").FlexibleSchema<import("@ai-sdk/provider-utils").Context> | undefined;
|
|
36
62
|
needsApproval?: boolean | import("@ai-sdk/provider-utils").ToolNeedsApprovalFunction<{
|
|
37
63
|
sessionId?: string | undefined;
|
|
38
|
-
target
|
|
64
|
+
target?: string | undefined;
|
|
39
65
|
message: string | {
|
|
40
66
|
role: "user";
|
|
41
67
|
parts: ({
|
|
@@ -60,7 +86,7 @@ export declare function createWorkerAgentTool(input: {
|
|
|
60
86
|
onInputAvailable?: ((options: {
|
|
61
87
|
input: {
|
|
62
88
|
sessionId?: string | undefined;
|
|
63
|
-
target
|
|
89
|
+
target?: string | undefined;
|
|
64
90
|
message: string | {
|
|
65
91
|
role: "user";
|
|
66
92
|
parts: ({
|
|
@@ -83,7 +109,7 @@ export declare function createWorkerAgentTool(input: {
|
|
|
83
109
|
toolCallId: string;
|
|
84
110
|
input: {
|
|
85
111
|
sessionId?: string | undefined;
|
|
86
|
-
target
|
|
112
|
+
target?: string | undefined;
|
|
87
113
|
message: string | {
|
|
88
114
|
role: "user";
|
|
89
115
|
parts: ({
|
|
@@ -145,7 +171,7 @@ export declare function createWorkerAgentTool(input: {
|
|
|
145
171
|
}> | undefined;
|
|
146
172
|
execute: import("ai").ToolExecuteFunction<{
|
|
147
173
|
sessionId?: string | undefined;
|
|
148
|
-
target
|
|
174
|
+
target?: string | undefined;
|
|
149
175
|
message: string | {
|
|
150
176
|
role: "user";
|
|
151
177
|
parts: ({
|
|
@@ -191,7 +217,7 @@ export declare function createWorkerAgentTool(input: {
|
|
|
191
217
|
inputExamples?: {
|
|
192
218
|
input: NoInfer<{
|
|
193
219
|
sessionId?: string | undefined;
|
|
194
|
-
target
|
|
220
|
+
target?: string | undefined;
|
|
195
221
|
message: string | {
|
|
196
222
|
role: "user";
|
|
197
223
|
parts: ({
|
|
@@ -219,7 +245,7 @@ export declare function createWorkerAgentTool(input: {
|
|
|
219
245
|
} & {
|
|
220
246
|
execute: import("ai").ToolExecuteFunction<{
|
|
221
247
|
sessionId?: string | undefined;
|
|
222
|
-
target
|
|
248
|
+
target?: string | undefined;
|
|
223
249
|
message: string | {
|
|
224
250
|
role: "user";
|
|
225
251
|
parts: ({
|
|
@@ -263,7 +289,7 @@ export declare function createWorkerAgentTool(input: {
|
|
|
263
289
|
metadata?: import("@ai-sdk/provider").JSONObject;
|
|
264
290
|
inputSchema: import("ai").FlexibleSchema<{
|
|
265
291
|
sessionId?: string | undefined;
|
|
266
|
-
target
|
|
292
|
+
target?: string | undefined;
|
|
267
293
|
message: string | {
|
|
268
294
|
role: "user";
|
|
269
295
|
parts: ({
|
|
@@ -284,7 +310,7 @@ export declare function createWorkerAgentTool(input: {
|
|
|
284
310
|
contextSchema?: import("ai").FlexibleSchema<import("@ai-sdk/provider-utils").Context> | undefined;
|
|
285
311
|
needsApproval?: boolean | import("@ai-sdk/provider-utils").ToolNeedsApprovalFunction<{
|
|
286
312
|
sessionId?: string | undefined;
|
|
287
|
-
target
|
|
313
|
+
target?: string | undefined;
|
|
288
314
|
message: string | {
|
|
289
315
|
role: "user";
|
|
290
316
|
parts: ({
|
|
@@ -309,7 +335,7 @@ export declare function createWorkerAgentTool(input: {
|
|
|
309
335
|
onInputAvailable?: ((options: {
|
|
310
336
|
input: {
|
|
311
337
|
sessionId?: string | undefined;
|
|
312
|
-
target
|
|
338
|
+
target?: string | undefined;
|
|
313
339
|
message: string | {
|
|
314
340
|
role: "user";
|
|
315
341
|
parts: ({
|
|
@@ -332,7 +358,7 @@ export declare function createWorkerAgentTool(input: {
|
|
|
332
358
|
toolCallId: string;
|
|
333
359
|
input: {
|
|
334
360
|
sessionId?: string | undefined;
|
|
335
|
-
target
|
|
361
|
+
target?: string | undefined;
|
|
336
362
|
message: string | {
|
|
337
363
|
role: "user";
|
|
338
364
|
parts: ({
|
|
@@ -394,7 +420,7 @@ export declare function createWorkerAgentTool(input: {
|
|
|
394
420
|
}> | undefined;
|
|
395
421
|
execute: import("ai").ToolExecuteFunction<{
|
|
396
422
|
sessionId?: string | undefined;
|
|
397
|
-
target
|
|
423
|
+
target?: string | undefined;
|
|
398
424
|
message: string | {
|
|
399
425
|
role: "user";
|
|
400
426
|
parts: ({
|
|
@@ -440,7 +466,7 @@ export declare function createWorkerAgentTool(input: {
|
|
|
440
466
|
inputExamples?: {
|
|
441
467
|
input: NoInfer<{
|
|
442
468
|
sessionId?: string | undefined;
|
|
443
|
-
target
|
|
469
|
+
target?: string | undefined;
|
|
444
470
|
message: string | {
|
|
445
471
|
role: "user";
|
|
446
472
|
parts: ({
|
|
@@ -468,7 +494,7 @@ export declare function createWorkerAgentTool(input: {
|
|
|
468
494
|
} & {
|
|
469
495
|
execute: import("ai").ToolExecuteFunction<{
|
|
470
496
|
sessionId?: string | undefined;
|
|
471
|
-
target
|
|
497
|
+
target?: string | undefined;
|
|
472
498
|
message: string | {
|
|
473
499
|
role: "user";
|
|
474
500
|
parts: ({
|
|
@@ -512,7 +538,7 @@ export declare function createWorkerAgentTool(input: {
|
|
|
512
538
|
metadata?: import("@ai-sdk/provider").JSONObject;
|
|
513
539
|
inputSchema: import("ai").FlexibleSchema<{
|
|
514
540
|
sessionId?: string | undefined;
|
|
515
|
-
target
|
|
541
|
+
target?: string | undefined;
|
|
516
542
|
message: string | {
|
|
517
543
|
role: "user";
|
|
518
544
|
parts: ({
|
|
@@ -533,7 +559,7 @@ export declare function createWorkerAgentTool(input: {
|
|
|
533
559
|
contextSchema?: import("ai").FlexibleSchema<import("@ai-sdk/provider-utils").Context> | undefined;
|
|
534
560
|
needsApproval?: boolean | import("@ai-sdk/provider-utils").ToolNeedsApprovalFunction<{
|
|
535
561
|
sessionId?: string | undefined;
|
|
536
|
-
target
|
|
562
|
+
target?: string | undefined;
|
|
537
563
|
message: string | {
|
|
538
564
|
role: "user";
|
|
539
565
|
parts: ({
|
|
@@ -558,7 +584,7 @@ export declare function createWorkerAgentTool(input: {
|
|
|
558
584
|
onInputAvailable?: ((options: {
|
|
559
585
|
input: {
|
|
560
586
|
sessionId?: string | undefined;
|
|
561
|
-
target
|
|
587
|
+
target?: string | undefined;
|
|
562
588
|
message: string | {
|
|
563
589
|
role: "user";
|
|
564
590
|
parts: ({
|
|
@@ -581,7 +607,7 @@ export declare function createWorkerAgentTool(input: {
|
|
|
581
607
|
toolCallId: string;
|
|
582
608
|
input: {
|
|
583
609
|
sessionId?: string | undefined;
|
|
584
|
-
target
|
|
610
|
+
target?: string | undefined;
|
|
585
611
|
message: string | {
|
|
586
612
|
role: "user";
|
|
587
613
|
parts: ({
|
|
@@ -643,7 +669,7 @@ export declare function createWorkerAgentTool(input: {
|
|
|
643
669
|
}> | undefined;
|
|
644
670
|
execute: import("ai").ToolExecuteFunction<{
|
|
645
671
|
sessionId?: string | undefined;
|
|
646
|
-
target
|
|
672
|
+
target?: string | undefined;
|
|
647
673
|
message: string | {
|
|
648
674
|
role: "user";
|
|
649
675
|
parts: ({
|
|
@@ -693,7 +719,7 @@ export declare function createWorkerAgentTool(input: {
|
|
|
693
719
|
} & {
|
|
694
720
|
execute: import("ai").ToolExecuteFunction<{
|
|
695
721
|
sessionId?: string | undefined;
|
|
696
|
-
target
|
|
722
|
+
target?: string | undefined;
|
|
697
723
|
message: string | {
|
|
698
724
|
role: "user";
|
|
699
725
|
parts: ({
|
|
@@ -737,7 +763,7 @@ export declare function createWorkerAgentTool(input: {
|
|
|
737
763
|
metadata?: import("@ai-sdk/provider").JSONObject;
|
|
738
764
|
inputSchema: import("ai").FlexibleSchema<{
|
|
739
765
|
sessionId?: string | undefined;
|
|
740
|
-
target
|
|
766
|
+
target?: string | undefined;
|
|
741
767
|
message: string | {
|
|
742
768
|
role: "user";
|
|
743
769
|
parts: ({
|
|
@@ -758,7 +784,7 @@ export declare function createWorkerAgentTool(input: {
|
|
|
758
784
|
contextSchema?: import("ai").FlexibleSchema<import("@ai-sdk/provider-utils").Context> | undefined;
|
|
759
785
|
needsApproval?: boolean | import("@ai-sdk/provider-utils").ToolNeedsApprovalFunction<{
|
|
760
786
|
sessionId?: string | undefined;
|
|
761
|
-
target
|
|
787
|
+
target?: string | undefined;
|
|
762
788
|
message: string | {
|
|
763
789
|
role: "user";
|
|
764
790
|
parts: ({
|
|
@@ -783,7 +809,7 @@ export declare function createWorkerAgentTool(input: {
|
|
|
783
809
|
onInputAvailable?: ((options: {
|
|
784
810
|
input: {
|
|
785
811
|
sessionId?: string | undefined;
|
|
786
|
-
target
|
|
812
|
+
target?: string | undefined;
|
|
787
813
|
message: string | {
|
|
788
814
|
role: "user";
|
|
789
815
|
parts: ({
|
|
@@ -806,7 +832,7 @@ export declare function createWorkerAgentTool(input: {
|
|
|
806
832
|
toolCallId: string;
|
|
807
833
|
input: {
|
|
808
834
|
sessionId?: string | undefined;
|
|
809
|
-
target
|
|
835
|
+
target?: string | undefined;
|
|
810
836
|
message: string | {
|
|
811
837
|
role: "user";
|
|
812
838
|
parts: ({
|
|
@@ -868,7 +894,7 @@ export declare function createWorkerAgentTool(input: {
|
|
|
868
894
|
}> | undefined;
|
|
869
895
|
execute: import("ai").ToolExecuteFunction<{
|
|
870
896
|
sessionId?: string | undefined;
|
|
871
|
-
target
|
|
897
|
+
target?: string | undefined;
|
|
872
898
|
message: string | {
|
|
873
899
|
role: "user";
|
|
874
900
|
parts: ({
|
|
@@ -918,7 +944,7 @@ export declare function createWorkerAgentTool(input: {
|
|
|
918
944
|
} & {
|
|
919
945
|
execute: import("ai").ToolExecuteFunction<{
|
|
920
946
|
sessionId?: string | undefined;
|
|
921
|
-
target
|
|
947
|
+
target?: string | undefined;
|
|
922
948
|
message: string | {
|
|
923
949
|
role: "user";
|
|
924
950
|
parts: ({
|
package/dist/agent-call.js
CHANGED
|
@@ -5,20 +5,45 @@ import { parseJsonEventStream } from "@ai-sdk/provider-utils";
|
|
|
5
5
|
import { tool, uiMessageChunkSchema } from "ai";
|
|
6
6
|
import { agentSubagentConcurrencyErrorSchema, agentRemoteAdmissionErrorSchema, agentCallInputSchema, agentCallTextMessageSchema, agentRunCallResultSchema, getAgentCallFileIds, } from "@gea-ai/contract/agent-worker-tools";
|
|
7
7
|
import { captureTraceContext } from "./trace-context.js";
|
|
8
|
+
/** Fresh Sessions keep the declared-target rule. A resume only needs sessionId. */
|
|
9
|
+
export function workerAgentToolInputSchema(input) {
|
|
10
|
+
const message = input.artifactScope
|
|
11
|
+
? agentCallInputSchema.shape.message
|
|
12
|
+
: agentCallTextMessageSchema;
|
|
13
|
+
const keys = new Set(input.agents.map((agent) => agent.key));
|
|
14
|
+
return z
|
|
15
|
+
.object({
|
|
16
|
+
sessionId: z.uuid().optional(),
|
|
17
|
+
target: z.string().trim().min(1).max(80).optional(),
|
|
18
|
+
message,
|
|
19
|
+
})
|
|
20
|
+
.superRefine((value, context) => {
|
|
21
|
+
if (value.sessionId)
|
|
22
|
+
return;
|
|
23
|
+
if (value.target === undefined) {
|
|
24
|
+
if (keys.size > 0 && !input.canCopy) {
|
|
25
|
+
context.addIssue({
|
|
26
|
+
code: "custom",
|
|
27
|
+
path: ["target"],
|
|
28
|
+
message: "A new Session requires a declared target.",
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
if (!keys.has(value.target)) {
|
|
34
|
+
context.addIssue({
|
|
35
|
+
code: "custom",
|
|
36
|
+
path: ["target"],
|
|
37
|
+
message: "Select a declared target for a new Session.",
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
}
|
|
8
42
|
/** The host opens a fresh Worker invocation; only its visible answer returns to the caller. */
|
|
9
43
|
export function createWorkerAgentTool(input) {
|
|
10
44
|
return tool({
|
|
11
|
-
description: `Start an Agent Run in a new or idle child Session. Use runWait with returned runIds and runCancel to cancel. Use sessionId to continue the same Session. ${input.canCopy ? "Omit target to create a copy of yourself." : "Select a declared target."} Available targets: ${JSON.stringify(input.agents)}. Supply context in message.${input.artifactScope ? " To send selected files, use a user message with file parts containing immutable Artifact file_id values. Refer to attachments by filename or order in task text; remote transfer may assign new IDs, exposed to the child in Attached Artifact metadata. IDs hardcoded in text are not rewritten." : ""}`,
|
|
12
|
-
inputSchema:
|
|
13
|
-
target: input.agents.length
|
|
14
|
-
? input.canCopy
|
|
15
|
-
? z.enum(input.agents.map((agent) => agent.key)).optional()
|
|
16
|
-
: z.enum(input.agents.map((agent) => agent.key))
|
|
17
|
-
: z.never().optional(),
|
|
18
|
-
message: input.artifactScope
|
|
19
|
-
? agentCallInputSchema.shape.message
|
|
20
|
-
: agentCallTextMessageSchema,
|
|
21
|
-
}),
|
|
45
|
+
description: `Start an Agent Run in a new or idle child Session. Use runWait with returned runIds and runCancel to cancel. Use sessionId to continue the same Session; target may be omitted or name the recorded Agent. ${input.canCopy ? "Omit target to create a copy of yourself." : "Select a declared target for a new Session."} Available targets: ${JSON.stringify(input.agents)}. Supply context in message.${input.artifactScope ? " To send selected files, use a user message with file parts containing immutable Artifact file_id values. Refer to attachments by filename or order in task text; remote transfer may assign new IDs, exposed to the child in Attached Artifact metadata. IDs hardcoded in text are not rewritten." : ""}`,
|
|
46
|
+
inputSchema: workerAgentToolInputSchema(input),
|
|
22
47
|
execute: async (value, options) => {
|
|
23
48
|
const fileIds = getAgentCallFileIds(value.message);
|
|
24
49
|
const response = await input.host.fetch("/internal/agent-worker-host/v1/agents/runs", {
|
|
@@ -19,19 +19,6 @@ export declare function executeChannelBehavior(input: {
|
|
|
19
19
|
environment: AgentChannelFetchEnvironment;
|
|
20
20
|
signal: AbortSignal;
|
|
21
21
|
}): Promise<{
|
|
22
|
-
sequence: number;
|
|
23
|
-
duplicate: boolean;
|
|
24
|
-
} | {
|
|
25
|
-
state: AgentChannelJson;
|
|
26
|
-
intents: {
|
|
27
|
-
key: string;
|
|
28
|
-
payload: AgentChannelJson;
|
|
29
|
-
eventId: string;
|
|
30
|
-
operationId: string;
|
|
31
|
-
}[];
|
|
32
|
-
cursor: number;
|
|
33
|
-
idempotencyWindowMs?: number | undefined;
|
|
34
|
-
} | {
|
|
35
22
|
status: "sent";
|
|
36
23
|
receipt?: AgentChannelJson | undefined;
|
|
37
24
|
} | {
|
|
@@ -56,6 +43,19 @@ export declare function executeChannelBehavior(input: {
|
|
|
56
43
|
message: string;
|
|
57
44
|
retryable: boolean;
|
|
58
45
|
};
|
|
46
|
+
} | {
|
|
47
|
+
sequence: number;
|
|
48
|
+
duplicate: boolean;
|
|
49
|
+
} | {
|
|
50
|
+
state: AgentChannelJson;
|
|
51
|
+
intents: {
|
|
52
|
+
key: string;
|
|
53
|
+
payload: AgentChannelJson;
|
|
54
|
+
eventId: string;
|
|
55
|
+
operationId: string;
|
|
56
|
+
}[];
|
|
57
|
+
cursor: number;
|
|
58
|
+
idempotencyWindowMs?: number | undefined;
|
|
59
59
|
} | {
|
|
60
60
|
events: {
|
|
61
61
|
id: string;
|
package/dist/agent-run-host.d.ts
CHANGED
|
@@ -7,6 +7,12 @@ export type { RemoteRunFetch, RemoteRunDestination, RemoteInputFiles, RemoteFile
|
|
|
7
7
|
export { readWorkerAgentResponse } from "./agent-call.js";
|
|
8
8
|
export { streamManagedAgentSessionRun } from "./agent-session-stream.js";
|
|
9
9
|
export type AgentChildRunSession = (operation: string, body: unknown, traceContext?: TraceContext) => Promise<Response>;
|
|
10
|
+
/**
|
|
11
|
+
* Renders child Run updates for a parent model turn. Upstream dropped the task-era
|
|
12
|
+
* helper without a replacement; App Server adapters still need one summary shape.
|
|
13
|
+
* JSON escaping can expand each character sixfold; leave room for Run identities.
|
|
14
|
+
*/
|
|
15
|
+
export declare function formatAgentChildRunUpdates(runs: Pick<AgentChildRun, "id" | "sessionId" | "agentKey" | "target" | "outcome">[]): string;
|
|
10
16
|
/** Invocation transport only. SDK Sessions own Run state, waits, completion and wakeups. */
|
|
11
17
|
export declare class AgentRunHost {
|
|
12
18
|
private readonly host;
|
|
@@ -17,6 +23,8 @@ export declare class AgentRunHost {
|
|
|
17
23
|
private readonly shutdown;
|
|
18
24
|
constructor(host: {
|
|
19
25
|
session: AgentChildRunSession;
|
|
26
|
+
/** Native App Server owns Worker handles; this callback only admits the resolved target. */
|
|
27
|
+
dispatch?(run: AgentChildRun, execution?: AgentSessionInboxExecution): Promise<void>;
|
|
20
28
|
/** Authorize against the root Session and return its retained child binding. */
|
|
21
29
|
resolveSession?(sessionId: string): Promise<Response>;
|
|
22
30
|
remoteFetch?(destination: RemoteRunDestination, path: string, init?: RequestInit): Promise<Response>;
|
package/dist/agent-run-host.js
CHANGED
|
@@ -5,6 +5,26 @@ import { agentChildRunSchema, agentChildSessionSchema, getAgentCallFileIds, agen
|
|
|
5
5
|
import { readWorkerAgentResponse } from "./agent-call.js";
|
|
6
6
|
export { readWorkerAgentResponse } from "./agent-call.js";
|
|
7
7
|
export { streamManagedAgentSessionRun } from "./agent-session-stream.js";
|
|
8
|
+
/**
|
|
9
|
+
* Renders child Run updates for a parent model turn. Upstream dropped the task-era
|
|
10
|
+
* helper without a replacement; App Server adapters still need one summary shape.
|
|
11
|
+
* JSON escaping can expand each character sixfold; leave room for Run identities.
|
|
12
|
+
*/
|
|
13
|
+
export function formatAgentChildRunUpdates(runs) {
|
|
14
|
+
const textLimit = Math.floor(170_000 / Math.max(1, runs.length) / 6);
|
|
15
|
+
return `Agent Run updates:\n${JSON.stringify(runs.map(({ id, sessionId, agentKey, target, outcome }) => {
|
|
16
|
+
const text = outcome?.text ?? "";
|
|
17
|
+
return {
|
|
18
|
+
runId: id,
|
|
19
|
+
sessionId,
|
|
20
|
+
agentKey,
|
|
21
|
+
...(target ? { target } : {}),
|
|
22
|
+
status: outcome?.status ?? "working",
|
|
23
|
+
text: text.slice(0, textLimit),
|
|
24
|
+
...(text.length > textLimit ? { textTruncated: true } : {}),
|
|
25
|
+
};
|
|
26
|
+
}))}`;
|
|
27
|
+
}
|
|
8
28
|
/** Invocation transport only. SDK Sessions own Run state, waits, completion and wakeups. */
|
|
9
29
|
export class AgentRunHost {
|
|
10
30
|
host;
|
|
@@ -131,8 +151,26 @@ export class AgentRunHost {
|
|
|
131
151
|
...sessionInput,
|
|
132
152
|
...(authorizedSession ? { authorizedSession } : {}),
|
|
133
153
|
});
|
|
134
|
-
if (!response.ok)
|
|
154
|
+
if (!response.ok) {
|
|
155
|
+
// Bundles from before root-authorized resume use a strict children/start
|
|
156
|
+
// schema. They reject the unknown authorizedSession field as
|
|
157
|
+
// invalid_request and cannot admit a Session that is not already on
|
|
158
|
+
// their ledger. Do not invent a second admission path for them.
|
|
159
|
+
if (response.status === 400 && authorizedSession) {
|
|
160
|
+
const body = await Result.tryPromise(() => response.clone().json());
|
|
161
|
+
if (body.isOk() &&
|
|
162
|
+
z
|
|
163
|
+
.object({ reason: z.literal("invalid_request") })
|
|
164
|
+
.safeParse(body.value).success) {
|
|
165
|
+
await response.body?.cancel();
|
|
166
|
+
return Response.json({
|
|
167
|
+
error: "NESTED_RESUME_REQUIRES_NEW_SDK",
|
|
168
|
+
reason: "Rebuild this Agent bundle with the current SDK before resuming a Session opened by another Agent.",
|
|
169
|
+
}, { status: 400 });
|
|
170
|
+
}
|
|
171
|
+
}
|
|
135
172
|
return response;
|
|
173
|
+
}
|
|
136
174
|
const { run, scheduled } = agentChildRunStartResultSchema.parse(await response.json());
|
|
137
175
|
if ((await this.host.register(run)) !== run.id)
|
|
138
176
|
throw new Error("Child Run registration did not complete.");
|
|
@@ -252,8 +290,17 @@ export class AgentRunHost {
|
|
|
252
290
|
dispatch(run, inboxExecution) {
|
|
253
291
|
if (this.closed)
|
|
254
292
|
throw new Error("Run dispatcher is stopping.");
|
|
255
|
-
if (this.executions.has(run.id) ||
|
|
293
|
+
if (this.executions.has(run.id) ||
|
|
294
|
+
run.outcome ||
|
|
295
|
+
(run.cancelRequested && run.destination.type !== "remote"))
|
|
256
296
|
return;
|
|
297
|
+
if (this.host.dispatch && run.destination.type !== "remote") {
|
|
298
|
+
this.track(this.host.dispatch(run, inboxExecution), {
|
|
299
|
+
runId: run.id,
|
|
300
|
+
sessionId: run.sessionId,
|
|
301
|
+
});
|
|
302
|
+
return;
|
|
303
|
+
}
|
|
257
304
|
const cancellation = new AbortController();
|
|
258
305
|
this.executions.set(run.id, cancellation);
|
|
259
306
|
this.host.onEvent?.({
|
|
@@ -4,7 +4,7 @@ import { readTraceContext } from "./trace-context.js";
|
|
|
4
4
|
import { traceContextSchema } from "@gea-ai/contract/traces";
|
|
5
5
|
import { DEFAULT_MAX_CONCURRENT_SUBAGENTS, maxConcurrentSubagentsSchema, } from "@gea-ai/contract/agent-packages";
|
|
6
6
|
import { AGENT_SUBAGENT_CONCURRENCY_HEADER, agentChildRunSchema, agentChildSessionSchema, agentChildRunStartInputSchema, agentChildRunDestinationSchema, agentChildRunOutcomeSchema, agentChildRunListInputSchema, } from "@gea-ai/contract/agent-worker-tools";
|
|
7
|
-
import { notifyAgentSessionChildRun, scheduleAgentSessionChildRunChanges, queueAgentSessionChildRun, acceptAgentSessionChildRun, inheritedAgentSessionMetadata, } from "./agent-session-inbox.js";
|
|
7
|
+
import { notifyAgentSessionChildRun, scheduleAgentSessionChildRunChanges, queueAgentSessionChildRun, acceptAgentSessionChildRun, isAgentSessionAdmissionBlocked, inheritedAgentSessionMetadata, } from "./agent-session-inbox.js";
|
|
8
8
|
import { getChildRun, getChildSession, listChildRuns, putChildRun, readChildRunIndex, readChildRuns, saveChildRunIndex, } from "./agent-session-child-store.js";
|
|
9
9
|
const runIdSchema = z.strictObject({ runId: z.uuid() });
|
|
10
10
|
const startSchema = agentChildRunStartInputSchema.extend({
|
|
@@ -88,6 +88,8 @@ export async function handleAgentSessionChildren(request, storage) {
|
|
|
88
88
|
}
|
|
89
89
|
case "start":
|
|
90
90
|
case "reserve": {
|
|
91
|
+
if (await isAgentSessionAdmissionBlocked(tx))
|
|
92
|
+
return Response.json({ error: "session_archived" }, { status: 409 });
|
|
91
93
|
const input = startSchema.parse(value);
|
|
92
94
|
const remote = path.endsWith("/reserve");
|
|
93
95
|
const index = await readChildRunIndex(tx);
|
|
@@ -1,2 +1,88 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { agentSessionExecutionCompleteSchema, agentSessionExecutionPauseSchema, agentSessionExecutionStartSchema, type AgentSessionMessage } from "@gea-ai/contract/agent-session";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import type { AgentSessionStorage, AgentSessionTransactionStorage } from "./agent-session.js";
|
|
4
|
+
export declare class SessionProtocolError extends Error {
|
|
5
|
+
readonly reason: string;
|
|
6
|
+
readonly status: number;
|
|
7
|
+
constructor(reason: string, status?: number);
|
|
8
|
+
}
|
|
9
|
+
/** Inbox admission/consumption and its UI history commit in the same Session transaction. */
|
|
10
|
+
export declare function appendAgentSessionInputMessages(tx: AgentSessionTransactionStorage, messages: AgentSessionMessage[], runId: string): Promise<void>;
|
|
11
|
+
/** Shared by managed admission and inbox begin, within the same Session transaction. */
|
|
12
|
+
export declare function startAgentSessionInvocation(tx: AgentSessionTransactionStorage, input: z.infer<typeof agentSessionExecutionStartSchema>): Promise<{
|
|
13
|
+
duplicate: boolean;
|
|
14
|
+
revision: number;
|
|
15
|
+
turn: {
|
|
16
|
+
packageVersionId: string;
|
|
17
|
+
requestId: string;
|
|
18
|
+
runId: string;
|
|
19
|
+
workerDeploymentId: string;
|
|
20
|
+
status: "running" | "waiting";
|
|
21
|
+
cancelRequestedAt: string | null;
|
|
22
|
+
activeStreamId: string | null;
|
|
23
|
+
attempt: number;
|
|
24
|
+
attemptId: string;
|
|
25
|
+
leaseExpiresAt: string;
|
|
26
|
+
leaseOwner: "host" | "worker";
|
|
27
|
+
nextMutationSequence: number;
|
|
28
|
+
lastMutation: {
|
|
29
|
+
digest: string;
|
|
30
|
+
revision: number;
|
|
31
|
+
} | null;
|
|
32
|
+
};
|
|
33
|
+
}>;
|
|
34
|
+
/** Commit a logical terminal in the caller's Session transaction. */
|
|
35
|
+
export declare function completeAgentSessionInvocation(tx: AgentSessionTransactionStorage, input: z.output<typeof agentSessionExecutionCompleteSchema>): Promise<{
|
|
36
|
+
duplicate: boolean;
|
|
37
|
+
outcome: {
|
|
38
|
+
attemptId: string;
|
|
39
|
+
runId: string;
|
|
40
|
+
modelCalls?: {
|
|
41
|
+
callId: string;
|
|
42
|
+
runId: string;
|
|
43
|
+
source: "agent" | "context";
|
|
44
|
+
label?: string | undefined;
|
|
45
|
+
model: string;
|
|
46
|
+
status: "aborted" | "completed" | "failed";
|
|
47
|
+
occurredAt: string;
|
|
48
|
+
usage: import("ai").LanguageModelUsage | null;
|
|
49
|
+
}[] | undefined;
|
|
50
|
+
attempt: number;
|
|
51
|
+
completedAt: string;
|
|
52
|
+
status: "aborted" | "error" | "finished" | "interrupted";
|
|
53
|
+
revision: number;
|
|
54
|
+
accounting?: {
|
|
55
|
+
eventType: "completed" | "failed";
|
|
56
|
+
model: string;
|
|
57
|
+
provider: string;
|
|
58
|
+
pricingKey?: string | undefined;
|
|
59
|
+
resourceSnapshot: Record<string, unknown>;
|
|
60
|
+
metadata?: Record<string, unknown> | undefined;
|
|
61
|
+
usage?: import("ai").LanguageModelUsage | null | undefined;
|
|
62
|
+
} | undefined;
|
|
63
|
+
};
|
|
64
|
+
}>;
|
|
65
|
+
/** Park the active attempt as waiting, in the caller's Session transaction. */
|
|
66
|
+
export declare function pauseAgentSessionInvocation(tx: AgentSessionTransactionStorage, input: z.output<typeof agentSessionExecutionPauseSchema>): Promise<{
|
|
67
|
+
duplicate: boolean;
|
|
68
|
+
turn: {
|
|
69
|
+
packageVersionId: string;
|
|
70
|
+
requestId: string;
|
|
71
|
+
runId: string;
|
|
72
|
+
workerDeploymentId: string;
|
|
73
|
+
status: "running" | "waiting";
|
|
74
|
+
cancelRequestedAt: string | null;
|
|
75
|
+
activeStreamId: string | null;
|
|
76
|
+
attempt: number;
|
|
77
|
+
attemptId: string;
|
|
78
|
+
leaseExpiresAt: string;
|
|
79
|
+
leaseOwner: "host" | "worker";
|
|
80
|
+
nextMutationSequence: number;
|
|
81
|
+
lastMutation: {
|
|
82
|
+
digest: string;
|
|
83
|
+
revision: number;
|
|
84
|
+
} | null;
|
|
85
|
+
};
|
|
86
|
+
revision: number;
|
|
87
|
+
}>;
|
|
2
88
|
export declare function handleAgentSessionExecutionRequest(request: Request, storage: AgentSessionStorage): Promise<Response>;
|