eve 0.30.7 → 0.31.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/CHANGELOG.md +36 -0
- package/README.md +5 -6
- package/dist/src/acp/adapter.d.ts +10 -4
- package/dist/src/acp/adapter.js +1 -1
- package/dist/src/channel/adapter-context.d.ts +1 -1
- package/dist/src/channel/adapter.d.ts +2 -4
- package/dist/src/channel/adapter.js +1 -1
- package/dist/src/channel/channel-address.d.ts +58 -0
- package/dist/src/channel/channel-address.js +1 -0
- package/dist/src/channel/channel-operations.d.ts +72 -0
- package/dist/src/channel/channel-operations.js +1 -0
- package/dist/src/channel/compiled-channel.d.ts +10 -6
- package/dist/src/channel/cross-channel-receive.d.ts +13 -25
- package/dist/src/channel/cross-channel-receive.js +2 -2
- package/dist/src/channel/receive-target.d.ts +1 -2
- package/dist/src/channel/routes.d.ts +21 -149
- package/dist/src/channel/schedule.d.ts +1 -1
- package/dist/src/channel/schedule.js +1 -1
- package/dist/src/channel/send-input.d.ts +6 -0
- package/dist/src/channel/send-input.js +1 -0
- package/dist/src/channel/session.d.ts +44 -30
- package/dist/src/channel/session.js +1 -1
- package/dist/src/channel/types.d.ts +8 -35
- package/dist/src/chunks/{use-eve-agent-k-XHfrJT.js → use-eve-agent-CF5D6jSV.js} +361 -367
- package/dist/src/chunks/{use-eve-agent-BXMIf5fR.js → use-eve-agent-DbYZLG0h.js} +364 -368
- package/dist/src/cli/commands/agent-prompt/build-and-verify.md +1 -2
- package/dist/src/cli/commands/channel-add-conflicts.js +1 -1
- package/dist/src/cli/commands/info.d.ts +1 -1
- package/dist/src/cli/commands/info.js +1 -1
- package/dist/src/cli/commands/registry-metadata.d.ts +15 -0
- package/dist/src/cli/commands/registry-metadata.js +1 -0
- package/dist/src/cli/commands/registry-package.d.ts +46 -0
- package/dist/src/cli/commands/registry-package.js +1 -0
- package/dist/src/cli/commands/registry.d.ts +1 -1
- package/dist/src/cli/commands/registry.js +4 -4
- package/dist/src/cli/dev/tui/runner.d.ts +1 -1
- package/dist/src/cli/dev/tui/runner.js +1 -1
- package/dist/src/cli/dev/tui/subagent-pump.js +1 -1
- package/dist/src/cli/dev/tui/terminal-renderer.js +2 -2
- package/dist/src/cli/dev/tui/tui.js +1 -1
- package/dist/src/cli/invoke/invoke.d.ts +1 -1
- package/dist/src/cli/invoke/invoke.js +1 -1
- package/dist/src/cli/invoke/result.d.ts +0 -11
- package/dist/src/cli/invoke/result.js +1 -1
- package/dist/src/client/client-error.d.ts +2 -0
- package/dist/src/client/client-error.js +1 -1
- package/dist/src/client/client.d.ts +7 -14
- package/dist/src/client/client.js +1 -1
- package/dist/src/client/eve-agent-store.d.ts +4 -4
- package/dist/src/client/eve-agent-store.js +1 -1
- package/dist/src/client/index.d.ts +3 -2
- package/dist/src/client/index.js +1 -1
- package/dist/src/client/message-reducer-types.d.ts +3 -0
- package/dist/src/client/message-reducer.js +1 -1
- package/dist/src/client/message-response.d.ts +2 -7
- package/dist/src/client/message-response.js +1 -1
- package/dist/src/client/open-stream.js +1 -1
- package/dist/src/client/session-controls.d.ts +29 -0
- package/dist/src/client/session-controls.js +1 -0
- package/dist/src/client/session-utils.d.ts +0 -20
- package/dist/src/client/session-utils.js +1 -1
- package/dist/src/client/session.d.ts +26 -90
- package/dist/src/client/session.js +1 -1
- package/dist/src/client/sessions.d.ts +20 -0
- package/dist/src/client/sessions.js +1 -0
- package/dist/src/client/types.d.ts +26 -47
- package/dist/src/compiler/extension-compatibility.d.ts +10 -10
- package/dist/src/compiler/extension-compatibility.js +1 -1
- package/dist/src/compiler/normalize-subagent.js +1 -1
- package/dist/src/evals/cli/eval-client.js +1 -1
- package/dist/src/evals/context.js +1 -1
- package/dist/src/evals/session.d.ts +7 -6
- package/dist/src/evals/session.js +1 -1
- package/dist/src/evals/types.d.ts +9 -9
- package/dist/src/execution/agent-handle-dispatch.js +1 -1
- package/dist/src/execution/cancel-descendant-turns-step.js +1 -1
- package/dist/src/execution/dispatch-runtime-actions-step.js +1 -1
- package/dist/src/execution/remote-agent-dispatch.d.ts +1 -3
- package/dist/src/execution/remote-agent-dispatch.js +1 -1
- package/dist/src/execution/runtime-context.js +1 -1
- package/dist/src/execution/runtime-errors.d.ts +1 -1
- package/dist/src/execution/session-command-token.d.ts +2 -0
- package/dist/src/execution/session-command-token.js +1 -1
- package/dist/src/execution/settle-cancelled-turn-step.js +1 -1
- package/dist/src/execution/subagent-hitl-proxy.js +1 -1
- package/dist/src/execution/tool-auth.d.ts +1 -1
- package/dist/src/execution/tool-auth.js +1 -1
- package/dist/src/execution/turn-control-receiver.d.ts +2 -2
- package/dist/src/execution/turn-workflow.js +1 -1
- package/dist/src/execution/workflow-entry.js +1 -1
- package/dist/src/execution/workflow-runtime.js +1 -1
- package/dist/src/harness/cancelled-turn-emission.d.ts +1 -1
- package/dist/src/harness/cancelled-turn-emission.js +1 -1
- package/dist/src/harness/emission-state.d.ts +25 -0
- package/dist/src/harness/emission-state.js +1 -0
- package/dist/src/harness/emission.d.ts +5 -37
- package/dist/src/harness/emission.js +1 -1
- package/dist/src/harness/handles/prompt.d.ts +22 -3
- package/dist/src/harness/handles/prompt.js +1 -1
- package/dist/src/harness/handles/store.d.ts +0 -5
- package/dist/src/harness/handles/store.js +1 -1
- package/dist/src/harness/ordered-stream-emitter.d.ts +3 -2
- package/dist/src/harness/ordered-stream-emitter.js +1 -1
- package/dist/src/harness/runtime-actions.js +1 -1
- package/dist/src/harness/session-limit-enforcement.js +1 -1
- package/dist/src/harness/tool-loop.js +1 -1
- package/dist/src/harness/tools.d.ts +1 -1
- package/dist/src/harness/tools.js +1 -1
- package/dist/src/internal/application/package.js +1 -1
- package/dist/src/internal/nitro/dev-runtime-artifacts.js +1 -1
- package/dist/src/internal/nitro/dev-runtime-source-snapshot-copy.js +1 -1
- package/dist/src/internal/nitro/dev-runtime-source-snapshot-local-roots.d.ts +15 -0
- package/dist/src/internal/nitro/dev-runtime-source-snapshot-local-roots.js +1 -0
- package/dist/src/internal/nitro/dev-runtime-source-snapshot.d.ts +14 -2
- package/dist/src/internal/nitro/dev-runtime-source-snapshot.js +1 -1
- package/dist/src/internal/nitro/host/dev-server-http.js +1 -1
- package/dist/src/internal/nitro/routes/channel-dispatch.d.ts +2 -5
- package/dist/src/internal/nitro/routes/channel-dispatch.js +1 -1
- package/dist/src/internal/nitro/routes/channel-route-context.d.ts +4 -3
- package/dist/src/internal/nitro/routes/channel-route-context.js +1 -1
- package/dist/src/packages/eve-catalog/src/index.js +1 -1
- package/dist/src/protocol/cancel-turn.d.ts +9 -4
- package/dist/src/protocol/cancel-turn.js +1 -1
- package/dist/src/protocol/message.d.ts +27 -17
- package/dist/src/protocol/message.js +2 -2
- package/dist/src/protocol/reset-session.d.ts +1 -1
- package/dist/src/protocol/routes.d.ts +27 -47
- package/dist/src/protocol/routes.js +1 -1
- package/dist/src/public/channels/chat-sdk/chatSdkChannel.d.ts +19 -21
- package/dist/src/public/channels/chat-sdk/chatSdkChannel.js +2 -2
- package/dist/src/public/channels/discord/discordChannel.d.ts +5 -4
- package/dist/src/public/channels/discord/discordChannel.js +1 -1
- package/dist/src/public/channels/eve.d.ts +11 -10
- package/dist/src/public/channels/eve.js +1 -1
- package/dist/src/public/channels/github/dispatch.d.ts +8 -8
- package/dist/src/public/channels/github/dispatch.js +1 -1
- package/dist/src/public/channels/github/githubChannel.d.ts +4 -3
- package/dist/src/public/channels/github/githubChannel.js +1 -1
- package/dist/src/public/channels/github/pr-context.d.ts +1 -1
- package/dist/src/public/channels/index.d.ts +1 -1
- package/dist/src/public/channels/linear/linearChannel.d.ts +4 -3
- package/dist/src/public/channels/linear/linearChannel.js +1 -1
- package/dist/src/public/channels/slack/index.d.ts +1 -1
- package/dist/src/public/channels/slack/interactions.d.ts +3 -4
- package/dist/src/public/channels/slack/interactions.js +1 -1
- package/dist/src/public/channels/slack/session-operations.d.ts +37 -0
- package/dist/src/public/channels/slack/session-operations.js +1 -0
- package/dist/src/public/channels/slack/slackChannel.d.ts +56 -74
- package/dist/src/public/channels/slack/slackChannel.js +1 -1
- package/dist/src/public/channels/teams/teamsChannel.d.ts +4 -3
- package/dist/src/public/channels/teams/teamsChannel.js +1 -1
- package/dist/src/public/channels/telegram/telegramChannel.d.ts +5 -4
- package/dist/src/public/channels/telegram/telegramChannel.js +1 -1
- package/dist/src/public/channels/twilio/twilioChannel.d.ts +4 -3
- package/dist/src/public/channels/twilio/twilioChannel.js +1 -1
- package/dist/src/public/definitions/callback-context.d.ts +1 -2
- package/dist/src/public/definitions/channel.d.ts +22 -86
- package/dist/src/public/definitions/channel.js +1 -1
- package/dist/src/public/definitions/hook.d.ts +1 -0
- package/dist/src/public/definitions/remote-agent.js +1 -1
- package/dist/src/public/definitions/schedule.d.ts +16 -16
- package/dist/src/public/definitions/tool.d.ts +5 -5
- package/dist/src/public/schedules/index.d.ts +1 -1
- package/dist/src/react/use-eve-agent.d.ts +7 -4
- package/dist/src/react/use-eve-agent.js +1 -1
- package/dist/src/runtime/agent/bootstrap-model-utils.d.ts +11 -0
- package/dist/src/runtime/agent/bootstrap-model-utils.js +1 -1
- package/dist/src/runtime/agent/mock-model-adapter.js +1 -1
- package/dist/src/runtime/agent/mock-model-fixtures.js +2 -2
- package/dist/src/runtime/prompt/compose.js +1 -1
- package/dist/src/runtime/subagents/dynamic-remote-agent-config.js +1 -1
- package/dist/src/runtime/types.d.ts +2 -2
- package/dist/src/services/inspect-application.d.ts +1 -1
- package/dist/src/services/inspect-application.js +1 -1
- package/dist/src/setup/channel-add-conflicts.js +1 -1
- package/dist/src/setup/integrations/linear/setup.js +1 -1
- package/dist/src/setup/scaffold/create/project.js +1 -1
- package/dist/src/setup/scaffold/create/web-template.d.ts +1 -1
- package/dist/src/setup/scaffold/create/web-template.js +29 -17
- package/dist/src/shared/async-iterable.d.ts +2 -0
- package/dist/src/shared/async-iterable.js +1 -0
- package/dist/src/shared/channel-definition.d.ts +7 -7
- package/dist/src/shared/schedule-definition.d.ts +2 -2
- package/dist/src/shared/tool-definition.d.ts +1 -1
- package/dist/src/svelte/index.js +1 -1
- package/dist/src/svelte/use-eve-agent.d.ts +8 -5
- package/dist/src/svelte/use-eve-agent.js +1 -1
- package/dist/src/vue/index.js +1 -1
- package/dist/src/vue/use-eve-agent.d.ts +8 -5
- package/dist/src/vue/use-eve-agent.js +1 -1
- package/docs/README.md +6 -6
- package/docs/channels/chat-sdk.mdx +5 -6
- package/docs/channels/custom.mdx +116 -144
- package/docs/channels/discord.mdx +1 -1
- package/docs/channels/eve.mdx +76 -30
- package/docs/channels/github.mdx +1 -1
- package/docs/channels/linear.mdx +10 -10
- package/docs/channels/overview.mdx +2 -2
- package/docs/channels/slack.mdx +46 -15
- package/docs/channels/telegram.mdx +1 -1
- package/docs/channels/twilio.mdx +1 -1
- package/docs/concepts/default-harness.md +11 -3
- package/docs/concepts/execution-model-and-durability.mdx +17 -5
- package/docs/concepts/sessions-runs-and-streaming.md +45 -16
- package/docs/evals/cases.mdx +3 -3
- package/docs/evals/targets.mdx +1 -1
- package/docs/guides/auth-and-route-protection.md +2 -1
- package/docs/guides/client/continuations.mdx +50 -77
- package/docs/guides/client/messages.mdx +29 -33
- package/docs/guides/client/output-schema.mdx +7 -14
- package/docs/guides/client/overview.mdx +40 -11
- package/docs/guides/client/streaming.mdx +18 -23
- package/docs/guides/frontend/nuxt.mdx +1 -1
- package/docs/guides/frontend/overview.mdx +40 -36
- package/docs/guides/frontend/sveltekit.mdx +1 -1
- package/docs/guides/frontend/use-eve-agent-svelte.mdx +19 -23
- package/docs/guides/frontend/use-eve-agent-vue.mdx +21 -25
- package/docs/guides/hooks.md +1 -1
- package/docs/guides/instrumentation.md +1 -1
- package/docs/install-integrations.mdx +4 -2
- package/docs/patterns/dynamic-scheduling.md +16 -15
- package/docs/reference/cli.md +4 -1
- package/docs/schedules.mdx +10 -11
- package/docs/subagents.mdx +1 -1
- package/docs/tools/human-in-the-loop.md +1 -1
- package/docs/tools/overview.mdx +26 -2
- package/docs/tutorial/ship-it.mdx +1 -1
- package/package.json +1 -1
- package/dist/src/channel/cancel.d.ts +0 -6
- package/dist/src/channel/cancel.js +0 -1
- package/dist/src/channel/clear-session.d.ts +0 -4
- package/dist/src/channel/clear-session.js +0 -1
- package/dist/src/channel/compact-session.d.ts +0 -4
- package/dist/src/channel/compact-session.js +0 -1
- package/dist/src/channel/reset-session.d.ts +0 -6
- package/dist/src/channel/reset-session.js +0 -1
- package/dist/src/channel/resolve-active-session.d.ts +0 -4
- package/dist/src/channel/resolve-active-session.js +0 -1
- package/dist/src/channel/send.d.ts +0 -6
- package/dist/src/channel/send.js +0 -1
|
@@ -3,7 +3,6 @@ import { type InputRequest } from "#client/index.js";
|
|
|
3
3
|
import type { ConnectionAuthorizationChallenge } from "#public/connections/errors.js";
|
|
4
4
|
declare const invokeResumeSchema: z.ZodObject<{
|
|
5
5
|
session: z.ZodObject<{
|
|
6
|
-
continuationToken: z.ZodOptional<z.ZodString>;
|
|
7
6
|
sessionId: z.ZodString;
|
|
8
7
|
streamIndex: z.ZodNumber;
|
|
9
8
|
}, z.core.$strict>;
|
|
@@ -32,7 +31,6 @@ declare const invocationInputRequestSchema: z.ZodObject<{
|
|
|
32
31
|
declare const invokeResultSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
33
32
|
resume: z.ZodObject<{
|
|
34
33
|
session: z.ZodObject<{
|
|
35
|
-
continuationToken: z.ZodOptional<z.ZodString>;
|
|
36
34
|
sessionId: z.ZodString;
|
|
37
35
|
streamIndex: z.ZodNumber;
|
|
38
36
|
}, z.core.$strict>;
|
|
@@ -62,7 +60,6 @@ declare const invokeResultSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
62
60
|
}, z.core.$strict>>>;
|
|
63
61
|
resume: z.ZodObject<{
|
|
64
62
|
session: z.ZodObject<{
|
|
65
|
-
continuationToken: z.ZodOptional<z.ZodString>;
|
|
66
63
|
sessionId: z.ZodString;
|
|
67
64
|
streamIndex: z.ZodNumber;
|
|
68
65
|
}, z.core.$strict>;
|
|
@@ -83,7 +80,6 @@ declare const invokeResultSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
83
80
|
}, z.core.$strict>>>;
|
|
84
81
|
resume: z.ZodObject<{
|
|
85
82
|
session: z.ZodObject<{
|
|
86
|
-
continuationToken: z.ZodOptional<z.ZodString>;
|
|
87
83
|
sessionId: z.ZodString;
|
|
88
84
|
streamIndex: z.ZodNumber;
|
|
89
85
|
}, z.core.$strict>;
|
|
@@ -105,7 +101,6 @@ declare const invokeResultSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
105
101
|
}, z.core.$strict>], "status">;
|
|
106
102
|
resume: z.ZodObject<{
|
|
107
103
|
session: z.ZodObject<{
|
|
108
|
-
continuationToken: z.ZodOptional<z.ZodString>;
|
|
109
104
|
sessionId: z.ZodString;
|
|
110
105
|
streamIndex: z.ZodNumber;
|
|
111
106
|
}, z.core.$strict>;
|
|
@@ -125,7 +120,6 @@ declare const invokeResultSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
125
120
|
message: z.ZodString;
|
|
126
121
|
resume: z.ZodOptional<z.ZodObject<{
|
|
127
122
|
session: z.ZodObject<{
|
|
128
|
-
continuationToken: z.ZodOptional<z.ZodString>;
|
|
129
123
|
sessionId: z.ZodString;
|
|
130
124
|
streamIndex: z.ZodNumber;
|
|
131
125
|
}, z.core.$strict>;
|
|
@@ -216,7 +210,6 @@ export declare const invokeResultJsonSchema: {
|
|
|
216
210
|
"~standard": z.core.ZodStandardSchemaWithJSON<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
217
211
|
resume: z.ZodObject<{
|
|
218
212
|
session: z.ZodObject<{
|
|
219
|
-
continuationToken: z.ZodOptional<z.ZodString>;
|
|
220
213
|
sessionId: z.ZodString;
|
|
221
214
|
streamIndex: z.ZodNumber;
|
|
222
215
|
}, z.core.$strict>;
|
|
@@ -246,7 +239,6 @@ export declare const invokeResultJsonSchema: {
|
|
|
246
239
|
}, z.core.$strict>>>;
|
|
247
240
|
resume: z.ZodObject<{
|
|
248
241
|
session: z.ZodObject<{
|
|
249
|
-
continuationToken: z.ZodOptional<z.ZodString>;
|
|
250
242
|
sessionId: z.ZodString;
|
|
251
243
|
streamIndex: z.ZodNumber;
|
|
252
244
|
}, z.core.$strict>;
|
|
@@ -267,7 +259,6 @@ export declare const invokeResultJsonSchema: {
|
|
|
267
259
|
}, z.core.$strict>>>;
|
|
268
260
|
resume: z.ZodObject<{
|
|
269
261
|
session: z.ZodObject<{
|
|
270
|
-
continuationToken: z.ZodOptional<z.ZodString>;
|
|
271
262
|
sessionId: z.ZodString;
|
|
272
263
|
streamIndex: z.ZodNumber;
|
|
273
264
|
}, z.core.$strict>;
|
|
@@ -289,7 +280,6 @@ export declare const invokeResultJsonSchema: {
|
|
|
289
280
|
}, z.core.$strict>], "status">;
|
|
290
281
|
resume: z.ZodObject<{
|
|
291
282
|
session: z.ZodObject<{
|
|
292
|
-
continuationToken: z.ZodOptional<z.ZodString>;
|
|
293
283
|
sessionId: z.ZodString;
|
|
294
284
|
streamIndex: z.ZodNumber;
|
|
295
285
|
}, z.core.$strict>;
|
|
@@ -309,7 +299,6 @@ export declare const invokeResultJsonSchema: {
|
|
|
309
299
|
message: z.ZodString;
|
|
310
300
|
resume: z.ZodOptional<z.ZodObject<{
|
|
311
301
|
session: z.ZodObject<{
|
|
312
|
-
continuationToken: z.ZodOptional<z.ZodString>;
|
|
313
302
|
sessionId: z.ZodString;
|
|
314
303
|
streamIndex: z.ZodNumber;
|
|
315
304
|
}, z.core.$strict>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{inputOptionSchema,inputRequestSchema}from"#client/index.js";import{z}from"#compiled/zod/index.js";const sessionCursorSchema=z.object({
|
|
1
|
+
import{inputOptionSchema,inputRequestSchema}from"#client/index.js";import{z}from"#compiled/zod/index.js";const sessionCursorSchema=z.object({sessionId:z.string().min(1),streamIndex:z.number().int().nonnegative()}).strict(),targetSchema=z.discriminatedUnion(`kind`,[z.object({kind:z.literal(`local`)}).strict(),z.object({kind:z.literal(`remote`),serverUrl:z.url()}).strict()]),invokeResumeSchema=z.object({session:sessionCursorSchema,target:targetSchema}).strict(),invocationInputRequestSchema=inputRequestSchema.omit({action:!0,display:!0,options:!0}).extend({options:z.array(inputOptionSchema.omit({style:!0})).optional()}),authorizationChallengeSchema=z.object({displayName:z.string().optional(),expiresAt:z.string().optional(),instructions:z.string().optional(),url:z.string().optional(),userCode:z.string().optional()}).strict(),authorizationInterruptSchema=z.object({authorization:authorizationChallengeSchema.optional(),description:z.string(),name:z.string(),webhookUrl:z.string().optional()}).strict(),turnOutcomeSchema=z.discriminatedUnion(`status`,[z.object({message:z.string().optional(),status:z.literal(`completed`)}).strict(),z.object({message:z.string(),status:z.literal(`failed`)}).strict()]),invokeResultSchema=z.discriminatedUnion(`status`,[z.object({resume:invokeResumeSchema,status:z.literal(`running`)}).strict(),z.object({requests:z.array(invocationInputRequestSchema).readonly(),resume:invokeResumeSchema,status:z.literal(`input-required`)}).strict(),z.object({authorizations:z.array(authorizationInterruptSchema).min(1).readonly(),resume:invokeResumeSchema,status:z.literal(`authorization-required`)}).strict(),z.object({outcome:turnOutcomeSchema,resume:invokeResumeSchema,status:z.literal(`ready`)}).strict(),z.object({message:z.string(),status:z.literal(`failed`)}).strict(),z.object({code:z.string().optional(),message:z.string(),resume:invokeResumeSchema.optional(),status:z.literal(`authentication-required`)}).strict()]);function projectInvocationInputRequest(e){let{allowFreeform:t,kind:n,options:r,prompt:i,requestId:a}=e;return{allowFreeform:t,kind:n,options:r?.map(({description:e,id:t,label:n})=>({description:e,id:t,label:n})),prompt:i,requestId:a}}function parseInvokeResumeInput(e){let t=invokeResultSchema.safeParse(e);if(t.success&&`resume`in t.data&&t.data.resume!==void 0)return t.data;throw Error(`Resume JSON is not a valid resumable eve invoke result.`)}const invokeResultJsonSchema={...z.toJSONSchema(invokeResultSchema,{io:`input`,target:`draft-2020-12`,unrepresentable:`any`}),$id:`https://eve.dev/schemas/invoke-result.json`,title:`eve invoke result`};export{invokeResultJsonSchema,parseInvokeResumeInput,projectInvocationInputRequest};
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
* Error thrown when the eve server returns a non-successful HTTP response.
|
|
3
3
|
*/
|
|
4
4
|
export declare class ClientError extends Error {
|
|
5
|
+
/** Stable eve error code when the response body provides one. */
|
|
6
|
+
readonly code: string | undefined;
|
|
5
7
|
/**
|
|
6
8
|
* HTTP status code returned by the server.
|
|
7
9
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{isObject}from"#shared/guards.js";var ClientError=class extends Error{status;body;headers;constructor(e,t,n){let r=t||`Server returned ${e}
|
|
1
|
+
import{isObject}from"#shared/guards.js";var ClientError=class extends Error{code;status;body;headers;constructor(e,t,n){let r=t||`Server returned ${e}.`,i;try{let e=JSON.parse(t);isObject(e)&&(typeof e.error==`string`&&(r=e.error),typeof e.code==`string`&&(i=e.code))}catch{}super(r),this.name=`ClientError`,this.code=i,this.status=e,this.body=t,this.headers=Object.freeze(Object.fromEntries(new Headers(n).entries()))}};export{ClientError};
|
|
@@ -1,14 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type { AgentInfoResult, ClientOptions, HealthResult
|
|
1
|
+
import { ClientSessions } from "#client/sessions.js";
|
|
2
|
+
import type { AgentInfoResult, ClientOptions, HealthResult } from "#client/types.js";
|
|
3
3
|
/**
|
|
4
4
|
* HTTP client for talking to a deployed eve agent.
|
|
5
5
|
*
|
|
6
|
-
* A single client is bound to one host and auth configuration.
|
|
7
|
-
*
|
|
8
|
-
*
|
|
6
|
+
* A single client is bound to one host and auth configuration. Its
|
|
7
|
+
* `sessions` collection can create or attach many independent fixed session
|
|
8
|
+
* handles.
|
|
9
9
|
*/
|
|
10
10
|
export declare class Client {
|
|
11
11
|
#private;
|
|
12
|
+
/** Explicit create/attach surface for ID-addressed sessions. */
|
|
13
|
+
readonly sessions: ClientSessions;
|
|
12
14
|
constructor(options: ClientOptions);
|
|
13
15
|
/**
|
|
14
16
|
* Checks the health of the eve agent server.
|
|
@@ -38,13 +40,4 @@ export declare class Client {
|
|
|
38
40
|
* auth/header cascade used by {@link health}, {@link info}, and sessions.
|
|
39
41
|
*/
|
|
40
42
|
fetch(path: string, init?: RequestInit): Promise<Response>;
|
|
41
|
-
/**
|
|
42
|
-
* Creates a {@link ClientSession} handle for one conversation.
|
|
43
|
-
*
|
|
44
|
-
* - **No arguments**: starts a fresh conversation. The first
|
|
45
|
-
* `session.send()` call creates the run on the server.
|
|
46
|
-
* - **{@link SessionState}**: resumes a previously serialized session.
|
|
47
|
-
* - **string**: shorthand for resuming with a continuation token alone.
|
|
48
|
-
*/
|
|
49
|
-
session(state?: SessionState | string): ClientSession;
|
|
50
43
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{EVE_HEALTH_ROUTE_PATH,EVE_INFO_ROUTE_PATH}from"#protocol/routes.js";import{encodeBasicCredentials}from"#internal/http/basic-auth.js";import{
|
|
1
|
+
import{EVE_HEALTH_ROUTE_PATH,EVE_INFO_ROUTE_PATH}from"#protocol/routes.js";import{encodeBasicCredentials}from"#internal/http/basic-auth.js";import{AgentInfoResponseError}from"#client/agent-info-error.js";import{AgentInfoResultSchema}from"#client/agent-info-schema.js";import{ClientError}from"#client/client-error.js";import{ClientSessions}from"#client/sessions.js";import{createClientUrl}from"#client/url.js";import{VERCEL_TRUSTED_OIDC_IDP_TOKEN_HEADER}from"#client/types.js";var Client=class{#e;#t;#n;#r;sessions;constructor(e){this.#n=e.host,this.#e=e.auth,this.#t=e.headers,this.#r=e.redirect,this.sessions=new ClientSessions({host:this.#n,redirect:this.#r,resolveHeaders:e=>this.#i(e)})}async health(){let t=createClientUrl(this.#n,EVE_HEALTH_ROUTE_PATH),n=await this.#i(),r=await fetch(t,withRedirectPolicy({headers:n},this.#r));if(!r.ok){let e=await r.text();throw new ClientError(r.status,e,r.headers)}return await r.json()}async info(){let e=await this.fetch(EVE_INFO_ROUTE_PATH);if(!e.ok){let t=await e.text();throw new ClientError(e.status,t,e.headers)}let n;try{n=await e.json()}catch{throw new AgentInfoResponseError}let i=AgentInfoResultSchema.safeParse(n);if(!i.success)throw new AgentInfoResponseError(i.error.issues.slice(0,5).map(e=>{let t=e.path.join(`.`);return t.length===0?e.message:`${t}: ${e.message}`}));return i.data}async fetch(e,t={}){let n=createClientUrl(this.#n,e),r=await this.#i(headersInitToRecord(t.headers));return await fetch(n,withRedirectPolicy({...t,headers:r},this.#r))}async#i(e){let t=new Headers,[n,r]=await Promise.all([resolveHeadersValue(this.#t),this.#a()]);for(let[e,r]of Object.entries(n))t.set(e,r);for(let[e,n]of Object.entries(r))t.set(e,n);if(e)for(let[n,r]of Object.entries(e))t.set(n,r);return t}async#a(){let e=this.#e;if(!e)return{};if(`vercelOidc`in e){let t=(await resolveTokenValue(e.vercelOidc.token)).trim();return t.length===0?{}:{authorization:`Bearer ${t}`,[VERCEL_TRUSTED_OIDC_IDP_TOKEN_HEADER]:t}}if(`bearer`in e){let t=(await resolveTokenValue(e.bearer)).trim();return t.length===0?{}:{authorization:`Bearer ${t}`}}if(`basic`in e){let t=await resolveTokenValue(e.basic.password);return{authorization:`Basic ${encodeBasicCredentials(e.basic.username,t)}`}}return{}}};async function resolveTokenValue(e){return typeof e==`function`?e():e}async function resolveHeadersValue(e){return e===void 0?{}:typeof e==`function`?await e():e}function headersInitToRecord(e){return e===void 0?{}:Object.fromEntries(new Headers(e).entries())}function withRedirectPolicy(e,t){return t===void 0?e:{...e,redirect:t}}export{Client};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { EveAgentReducer } from "#client/reducer.js";
|
|
2
2
|
import type { ClientSession } from "#client/session.js";
|
|
3
3
|
import type { MessageStreamEvent } from "#protocol/message.js";
|
|
4
|
-
import type { ClientAuth, HeadersValue, SendTurnPayload,
|
|
4
|
+
import type { ClientAuth, HeadersValue, SendTurnPayload, ClientSessionState } from "#client/types.js";
|
|
5
5
|
/**
|
|
6
6
|
* Lifecycle state of an {@link EveAgentStore}: `ready` (idle), `submitted`
|
|
7
7
|
* (turn sent, awaiting the first event), `streaming` (events arriving), and
|
|
@@ -25,7 +25,7 @@ export interface EveAgentStoreSnapshot<TData> {
|
|
|
25
25
|
readonly data: TData;
|
|
26
26
|
readonly error: Error | undefined;
|
|
27
27
|
readonly events: readonly MessageStreamEvent[];
|
|
28
|
-
readonly session:
|
|
28
|
+
readonly session: ClientSessionState | undefined;
|
|
29
29
|
readonly status: EveAgentStoreStatus;
|
|
30
30
|
}
|
|
31
31
|
/**
|
|
@@ -39,7 +39,7 @@ export interface EveAgentStoreCallbacks<TData> {
|
|
|
39
39
|
readonly onError?: (error: Error) => void;
|
|
40
40
|
readonly onEvent?: (event: MessageStreamEvent) => void;
|
|
41
41
|
readonly onFinish?: (snapshot: EveAgentStoreSnapshot<TData>) => void;
|
|
42
|
-
readonly onSessionChange?: (session:
|
|
42
|
+
readonly onSessionChange?: (session: ClientSessionState | undefined) => void;
|
|
43
43
|
readonly prepareSend?: PrepareSend;
|
|
44
44
|
}
|
|
45
45
|
/**
|
|
@@ -62,7 +62,7 @@ export interface EveAgentStoreInit<TData> {
|
|
|
62
62
|
readonly host?: string;
|
|
63
63
|
/** Ordered prefix of the session stream used to rehydrate projected state. */
|
|
64
64
|
readonly initialEvents?: readonly MessageStreamEvent[];
|
|
65
|
-
readonly initialSession?:
|
|
65
|
+
readonly initialSession?: ClientSessionState;
|
|
66
66
|
readonly optimistic?: boolean;
|
|
67
67
|
readonly reducer: EveAgentReducer<TData>;
|
|
68
68
|
readonly session?: ClientSession;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{toError}from"#shared/errors.js";import{createEventDeduper}from"#protocol/event-dedupe.js";import{Client}from"#client/client.js";var EveAgentStore=class{#e;#t;#n;#r=new Set;#
|
|
1
|
+
import{toError}from"#shared/errors.js";import{createEventDeduper}from"#protocol/event-dedupe.js";import{Client}from"#client/client.js";var EveAgentStore=class{#e;#t;#n;#r;#i=new Set;#a=createEventDeduper();#o;#s={};#c;#l;#u;#d=0;#f;#p;#m;#h;#g=`ready`;constructor(e){this.#t=e.session!==void 0,this.#e=this.#t?void 0:new Client({auth:e.auth,headers:e.headers,host:e.host??``});let t=[];for(let n of e.initialEvents??[])this.#a.admit(n)&&t.push(n);this.#u=t,this.#p=[...this.#u],this.#n=e.optimistic??!0,this.#r=e.reducer,this.#m=e.session??(e.initialSession===void 0?void 0:this.#e?.sessions.attach(e.initialSession.sessionId,{streamIndex:e.initialSession.streamIndex})),this.#c=this.#k(this.#p),this.#h=this.#A()}get snapshot(){return this.#h}setCallbacks(e){this.#s=e}subscribe(e){return this.#i.add(e),()=>{this.#i.delete(e)}}async send(t){if(this.#g===`streaming`||this.#g===`submitted`)throw Error(`eve session is already processing a turn.`);let n=this.#y(),r=new AbortController;this.#o=r,this.#l=void 0,this.#g=`submitted`,this.#j();try{let e=await this.#s.prepareSend?.(t)??t;if(assertExclusiveTurnInput(e),!this.#x(n))return;this.#S(e),this.#C(e),this.#j();let i={...e,signal:createAbortSignal(e.signal,r.signal)},a=await this.#v(i),o=!1;for await(let e of a){if(!this.#x(n))return;o||(o=!0,this.#g=`streaming`),this.#a.admit(e)&&(this.#u=[...this.#u,e],this.#w(e),this.#s.onEvent?.(e),this.#T(e),this.#j())}if(!this.#x(n))return;this.#g=this.#l===void 0?`ready`:`error`}catch(t){if(!this.#x(n))return;isAbortError(t)?(this.#g=`ready`,this.#E(toError(t))):(this.#l=toError(t),this.#g=`error`,this.#E(this.#l),this.#s.onError?.(this.#l))}finally{this.#x(n)&&(this.#o=void 0,this.#s.onSessionChange?.(this.#m?.state),this.#j(),this.#s.onFinish?.(this.#h))}}stop(){this.#o?.abort()}reset(){this.#b(),this.stop(),this.#o=void 0,this.#t||(this.#m=void 0),this.#u=[],this.#a=createEventDeduper(),this.#f=void 0,this.#p=[],this.#c=this.#r.initial(),this.#l=void 0,this.#g=`ready`,this.#s.onSessionChange?.(this.#m?.state),this.#j()}async#_(e){if(this.#e===void 0)throw Error(`An external eve session is required before sending.`);if(e.message===void 0)throw Error(`Cannot answer an input request before the session starts.`);let t=await this.#e.sessions.create({...e,message:e.message});return this.#m=t.session,this.#s.onSessionChange?.(t.session.state),this.#j(),t.response}async#v(e){if(this.#m===void 0)return await this.#_(e);if(e.inputResponses===void 0){let{message:t,...n}=e;return await this.#m.send(t,n)}let{inputResponses:t,...n}=e;return await this.#m.respond(t,n)}#y(){return this.#d+=1,this.#d}#b(){this.#d+=1}#x(e){return this.#d===e}#S(e){if(!this.#n||e.message===void 0)return;let t=createSubmissionId(),n={createdAt:Date.now(),id:t,message:summarizeUserContent(e.message)};this.#f=n,this.#D({data:{createdAt:n.createdAt,message:n.message,submissionId:n.id},type:`client.message.submitted`})}#C(e){e.inputResponses===void 0||e.inputResponses.length===0||this.#D({data:{createdAt:Date.now(),responses:e.inputResponses},type:`client.input.responded`})}#w(e){if(e.type===`message.received`&&this.#f!==void 0){let t=this.#f.id;this.#f=void 0,this.#O(e=>e.type===`client.message.submitted`&&e.data.submissionId===t,e);return}this.#D(e)}#T(e){let t=toTerminalStreamFailureError(e);t!==void 0&&(this.#g=`error`,this.#E(t),this.#l===void 0&&(this.#l=t,this.#s.onError?.(t)))}#E(e){let t=this.#f;t!==void 0&&(this.#f=void 0,this.#O(e=>e.type===`client.message.submitted`&&e.data.submissionId===t.id,{data:{createdAt:t.createdAt,error:{message:e.message},message:t.message,submissionId:t.id},type:`client.message.failed`}))}#D(e){this.#p=[...this.#p,e],this.#c=this.#r.reduce(this.#c,e)}#O(e,t){let n=!1;this.#p=this.#p.map(r=>!n&&e(r)?(n=!0,t):r),n||(this.#p=[...this.#p,t]),this.#c=this.#k(this.#p)}#k(e){let t=this.#r.initial();for(let n of e)t=this.#r.reduce(t,n);return t}#A(){return{data:this.#c,error:this.#l,events:this.#u,session:this.#m?.state,status:this.#g}}#j(){this.#h=this.#A();for(let e of this.#i)e()}};function assertExclusiveTurnInput(e){if(e.message!==void 0==(e.inputResponses!==void 0))throw Error(`A turn requires exactly one of message or inputResponses.`)}let submissionSequence=0;function createSubmissionId(){let e=globalThis.crypto?.randomUUID;return e===void 0?(submissionSequence+=1,`submission_${submissionSequence.toString()}`):e.call(globalThis.crypto)}function createAbortSignal(e,t){return e?AbortSignal.any([e,t]):t}function summarizeUserContent(e){if(typeof e==`string`)return e;let t=[];for(let n of e){if(n.type===`text`){t.push(n.text);continue}n.type===`file`&&t.push(n.filename?`[file: ${n.filename}]`:`[file]`)}return t.join(`
|
|
2
2
|
`)}function isAbortError(e){return e instanceof Error&&e.name===`AbortError`}function toTerminalStreamFailureError(e){if(e.type!==`session.failed`)return;let t=Error(e.data.message);return t.name=e.data.code,t}export{EveAgentStore};
|
|
@@ -6,11 +6,12 @@ export { defaultMessageReducer } from "#client/message-reducer.js";
|
|
|
6
6
|
export { createDataUrlFilePart, createTextWithFileContent } from "#client/file-parts.js";
|
|
7
7
|
export { MessageResponse } from "#client/message-response.js";
|
|
8
8
|
export { ClientSession } from "#client/session.js";
|
|
9
|
+
export { ClientSessions, type CreatedClientSession } from "#client/sessions.js";
|
|
9
10
|
export type { EveAgentStoreCallbacks, EveAgentStoreInit, EveAgentStoreSnapshot, EveAgentStoreStatus, PrepareSend, } from "#client/eve-agent-store.js";
|
|
10
|
-
export type { AgentInfoEntry, AgentInfoChannelEntry, AgentInfoChannels, AgentInfoConnectionEntry, AgentInfoDynamicResolverEntry, AgentInfoFrameworkChannelEntry, AgentInfoFrameworkToolEntry, AgentInfoHookEntry, AgentInfoInstructions, AgentInfoInstructionsEntry, AgentInfoResult, AgentInfoSandboxEntry, AgentInfoScheduleEntry, AgentInfoSkillEntry, AgentInfoSource, AgentInfoSubagentEntry, AgentInfoToolEntry, AgentInfoTools, CancelSessionResult, ClearResult, CompactResult, ClientAuth, ClientOptions, ClientRedirectPolicy, HeadersValue, HealthResult, MessageResult, ResetResult, ResolvedStreamReconnectPolicy, SendTurnInput,
|
|
11
|
+
export type { AgentInfoEntry, AgentInfoChannelEntry, AgentInfoChannels, AgentInfoConnectionEntry, AgentInfoDynamicResolverEntry, AgentInfoFrameworkChannelEntry, AgentInfoFrameworkToolEntry, AgentInfoHookEntry, AgentInfoInstructions, AgentInfoInstructionsEntry, AgentInfoResult, AgentInfoSandboxEntry, AgentInfoScheduleEntry, AgentInfoSkillEntry, AgentInfoSource, AgentInfoSubagentEntry, AgentInfoToolEntry, AgentInfoTools, CancelSessionResult, ClearResult, CompactResult, ClientAuth, ClientOptions, ClientRedirectPolicy, HeadersValue, HealthResult, MessageResult, RespondTurnOptions, ResetResult, ResolvedStreamReconnectPolicy, SendTurnInput, SendTurnOptions, SessionSnapshot, ClientSessionState, StreamOptions, StreamReconnectPolicy, StreamReconnectRetryPolicy, TokenValue, } from "#client/types.js";
|
|
11
12
|
export type { EveAgentReducer, EveAgentReducerEvent, ClientInputRespondedEvent, ClientMessageFailedEvent, ClientMessageSubmittedEvent, } from "#client/reducer.js";
|
|
12
13
|
export type { EveAuthorizationChallenge, EveAuthorizationOutcome, EveAuthorizationPart, EveMessageData, EveDynamicToolPart, EveMessageInputRequest, EveMessage, EveMessageMetadata, EveMessagePart, EveMessageToolMetadata, } from "#client/message-reducer.js";
|
|
13
|
-
export type { ActionResultStreamEvent, ActionsRequestedStreamEvent, AssistantStepFinishReason, AuthorizationOutcome, CompactionCompletedStreamEvent, CompactionRequestedStreamEvent, AuthorizationCompletedStreamEvent, ConnectionAuthorizationOutcome, AuthorizationRequiredStreamEvent, HandleMessageStreamEvent, MessageStreamEventMeta, InputRequestedStreamEvent, MessageAppendedStreamEvent, MessageCompletedStreamEvent, MessageReceivedPart, MessageReceivedStreamEvent, ReasoningAppendedStreamEvent, ReasoningCompletedStreamEvent, ResultCompletedStreamEvent, SessionCompletedStreamEvent, SessionFailedStreamEvent, SessionStartedStreamEvent, SessionWaitingStreamEvent, MessageStreamEvent, StepCompletedStreamEvent, StepFailedStreamEvent, StepStartedStreamEvent, SubagentCalledStreamEvent, SubagentChildEventStreamEvent, SubagentCompletedStreamEvent, SubagentStartedStreamEvent, TurnCancelledStreamEvent, TurnCompletedStreamEvent, TurnFailedStreamEvent, TurnStartedStreamEvent, TurnFailureStreamEvent, } from "#protocol/message.js";
|
|
14
|
+
export type { ActionPartialStreamEvent, ActionResultStreamEvent, ActionsRequestedStreamEvent, AssistantStepFinishReason, AuthorizationOutcome, CompactionCompletedStreamEvent, CompactionRequestedStreamEvent, AuthorizationCompletedStreamEvent, ConnectionAuthorizationOutcome, AuthorizationRequiredStreamEvent, HandleMessageStreamEvent, MessageStreamEventMeta, InputRequestedStreamEvent, MessageAppendedStreamEvent, MessageCompletedStreamEvent, MessageReceivedPart, MessageReceivedStreamEvent, ReasoningAppendedStreamEvent, ReasoningCompletedStreamEvent, ResultCompletedStreamEvent, SessionCompletedStreamEvent, SessionFailedStreamEvent, SessionStartedStreamEvent, SessionWaitingStreamEvent, MessageStreamEvent, StepCompletedStreamEvent, StepFailedStreamEvent, StepStartedStreamEvent, SubagentCalledStreamEvent, SubagentChildEventStreamEvent, SubagentCompletedStreamEvent, SubagentStartedStreamEvent, TurnCancelledStreamEvent, TurnCompletedStreamEvent, TurnFailedStreamEvent, TurnStartedStreamEvent, TurnFailureStreamEvent, } from "#protocol/message.js";
|
|
14
15
|
export { isCurrentTurnBoundaryEvent, isTurnFailureEvent } from "#protocol/message.js";
|
|
15
16
|
export type { InputOption, InputRequest, InputRequestKind, InputResponse, } from "#runtime/input/types.js";
|
|
16
17
|
export { inputOptionSchema, inputRequestKindSchema, inputRequestSchema, inputResponseSchema, isInputRequest, isInputResponse, } from "#runtime/input/types.js";
|
package/dist/src/client/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{isCurrentTurnBoundaryEvent,isTurnFailureEvent}from"#protocol/message.js";import{AgentInfoResponseError}from"#client/agent-info-error.js";import{ClientError}from"#client/client-error.js";import{
|
|
1
|
+
import{isCurrentTurnBoundaryEvent,isTurnFailureEvent}from"#protocol/message.js";import{AgentInfoResponseError}from"#client/agent-info-error.js";import{ClientError}from"#client/client-error.js";import{ClientSessions}from"#client/sessions.js";import{Client}from"#client/client.js";import{EveAgentStore}from"#client/eve-agent-store.js";import{defaultMessageReducer}from"#client/message-reducer.js";import{createDataUrlFilePart,createTextWithFileContent}from"#client/file-parts.js";import{MessageResponse}from"#client/message-response.js";import{ClientSession}from"#client/session.js";import{inputOptionSchema,inputRequestKindSchema,inputRequestSchema,inputResponseSchema,isInputRequest,isInputResponse}from"#runtime/input/types.js";import{resolveTextToResponse,resolveTextToResponses}from"#channel/resolve-text.js";export{AgentInfoResponseError,Client,ClientError,ClientSession,ClientSessions,EveAgentStore,MessageResponse,createDataUrlFilePart,createTextWithFileContent,defaultMessageReducer,inputOptionSchema,inputRequestKindSchema,inputRequestSchema,inputResponseSchema,isCurrentTurnBoundaryEvent,isInputRequest,isInputResponse,isTurnFailureEvent,resolveTextToResponse,resolveTextToResponses};
|
|
@@ -108,6 +108,8 @@ export type EveAuthorizationPart = {
|
|
|
108
108
|
* `"output-available"`, `"output-error"` (`errorText` set), or `"output-denied"`
|
|
109
109
|
* (`approval.approved` is `false`). Which of `input`, `output`, `errorText`, and
|
|
110
110
|
* `approval` are present depends on `state`, so narrow on `state` before reading them.
|
|
111
|
+
* Preliminary generator output uses `"output-available"` with `partial: true`;
|
|
112
|
+
* the terminal tool result clears that flag.
|
|
111
113
|
* `toolName` and `toolMetadata.eve` ({@link EveMessageToolMetadata}) record call identity.
|
|
112
114
|
*/
|
|
113
115
|
export type EveDynamicToolPart = {
|
|
@@ -160,6 +162,7 @@ export type EveDynamicToolPart = {
|
|
|
160
162
|
readonly errorText?: never;
|
|
161
163
|
readonly input: unknown;
|
|
162
164
|
readonly output: unknown;
|
|
165
|
+
readonly partial?: true;
|
|
163
166
|
readonly state: "output-available";
|
|
164
167
|
} | {
|
|
165
168
|
readonly approval?: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createAuthorizationCompletedPart,createAuthorizationRequiredPart}from"#client/authorization-message-parts.js";import{approvedApproval,createToolMetadata,mergeToolMetadata,normalizeActionRequest,normalizeActionResult,stringifyUnknown,toMessageInputRequest}from"#client/message-action-parts.js";function defaultMessageReducer(){return{initial(){return{messages:[]}},reduce(e,t){return reduceMessageData(e,t)}}}function reduceMessageData(e,
|
|
1
|
+
import{createAuthorizationCompletedPart,createAuthorizationRequiredPart}from"#client/authorization-message-parts.js";import{approvedApproval,createToolMetadata,mergeToolMetadata,normalizeActionRequest,normalizeActionResult,stringifyUnknown,toMessageInputRequest}from"#client/message-action-parts.js";function defaultMessageReducer(){return{initial(){return{messages:[]}},reduce(e,t){return reduceMessageData(e,t)}}}function reduceMessageData(e,c){switch(c.type){case`client.message.submitted`:return upsertMessage(e,{id:optimisticUserMessageId(c.data.submissionId),metadata:{optimistic:!0,status:`submitted`},parts:[{type:`text`,text:c.data.message}],role:`user`});case`client.message.failed`:return upsertMessage(e,{id:optimisticUserMessageId(c.data.submissionId),metadata:{optimistic:!0,status:`failed`},parts:[{type:`text`,text:c.data.message}],role:`user`});case`client.input.responded`:{let t=e;for(let e of c.data.responses)t=respondToInputRequest(t,e);return t}case`message.received`:return upsertMessage(e,{id:`${c.data.turnId}:user`,metadata:{status:`complete`,turnId:c.data.turnId},parts:projectReceivedParts(c.data.parts,c.data.message),role:`user`});case`step.started`:return updateAssistantMessage(e,c.data.turnId,e=>ensureStepStartPart(e,c.data.stepIndex));case`reasoning.appended`:return updateAssistantMessage(e,c.data.turnId,e=>upsertRun(ensureStepStartPart(e,c.data.stepIndex),{state:`streaming`,stepIndex:c.data.stepIndex,text:c.data.reasoningSoFar,type:`reasoning`}));case`reasoning.completed`:return updateAssistantMessage(e,c.data.turnId,e=>upsertRun(ensureStepStartPart(e,c.data.stepIndex),{state:`done`,stepIndex:c.data.stepIndex,text:c.data.reasoning,type:`reasoning`}));case`actions.requested`:{let t=e;for(let e of c.data.actions){let n=normalizeActionRequest(e);t=updateAssistantMessage(t,c.data.turnId,t=>upsertPart(ensureStepStartPart(t,c.data.stepIndex),{input:`input`in e?e.input:void 0,state:`input-available`,stepIndex:c.data.stepIndex,toolCallId:e.callId,toolMetadata:createToolMetadata(n),toolName:n.toolName,type:`dynamic-tool`}))}return t}case`input.requested`:{let t=e;for(let e of c.data.requests){let n=normalizeActionRequest(e.action);t=updateAssistantMessage(t,c.data.turnId,t=>upsertPart(ensureStepStartPart(t,c.data.stepIndex),{approval:{id:e.requestId},input:e.action.input,state:`approval-requested`,stepIndex:c.data.stepIndex,toolCallId:e.action.callId,toolMetadata:createToolMetadata(n,{inputRequest:toMessageInputRequest(e)}),toolName:n.toolName,type:`dynamic-tool`}))}return t}case`action.result`:{let t=normalizeActionResult(c.data.result),a=findToolPart(e,c.data.result.callId),s=c.data.error?.code===`TOOL_EXECUTION_DENIED`,l=c.data.status===`failed`&&!s,u=a?.approval?.id??c.data.result.callId,d=mergeToolMetadata(a?.toolMetadata,createToolMetadata(t)),f={input:a?.input,stepIndex:c.data.stepIndex,toolCallId:c.data.result.callId,toolMetadata:d,toolName:a?.toolName??t.toolName,type:`dynamic-tool`},p;return p=s?{...f,approval:{approved:!1,id:u,reason:c.data.error?.message},state:`output-denied`}:l?{...f,approval:approvedApproval(a),errorText:c.data.error?.message??stringifyUnknown(c.data.result.output),state:`output-error`}:{...f,approval:approvedApproval(a),output:c.data.result.output,state:`output-available`},a===void 0?updateAssistantMessage(e,c.data.turnId,e=>upsertPart(ensureStepStartPart(e,c.data.stepIndex),p)):updateToolPart(e,c.data.result.callId,p)}case`action.partial`:{let t=findToolPart(e,c.data.result.callId);if(t!==void 0&&isSettledToolPart(t))return e;let a=normalizeActionResult(c.data.result),o={approval:approvedApproval(t),input:t?.input,output:c.data.result.output,partial:!0,state:`output-available`,stepIndex:c.data.stepIndex,toolCallId:c.data.result.callId,toolMetadata:mergeToolMetadata(t?.toolMetadata,createToolMetadata(a)),toolName:t?.toolName??a.toolName,type:`dynamic-tool`};return t===void 0?updateAssistantMessage(e,c.data.turnId,e=>upsertPart(ensureStepStartPart(e,c.data.stepIndex),o)):updateToolPart(e,c.data.result.callId,o)}case`authorization.required`:return updateAssistantMessage(e,c.data.turnId,e=>upsertPart(ensureStepStartPart(e,c.data.stepIndex),createAuthorizationRequiredPart(c)));case`authorization.completed`:return completeAuthorization(e,c);case`message.appended`:return updateAssistantMessage(e,c.data.turnId,e=>upsertRun(ensureStepStartPart(e,c.data.stepIndex),{state:`streaming`,stepIndex:c.data.stepIndex,text:c.data.messageSoFar,type:`text`}));case`message.completed`:return updateAssistantMessage(e,c.data.turnId,e=>c.data.message===null?removeTextPart(e,c.data.stepIndex):upsertRun(ensureStepStartPart(e,c.data.stepIndex),{state:`done`,stepIndex:c.data.stepIndex,text:c.data.message,type:`text`}));case`result.completed`:return updateAssistantMetadata(e,c.data.turnId,{result:c.data.result});case`turn.completed`:return updateAssistantMetadata(e,c.data.turnId,{status:`complete`});case`turn.cancelled`:return updateAssistantMessage(e,c.data.turnId,e=>({...e,metadata:{...e.metadata,status:`complete`},parts:e.parts.map(e=>(e.type===`text`||e.type===`reasoning`)&&e.state===`streaming`?{...e,state:`done`}:e)}));case`turn.failed`:case`session.failed`:return e;default:return e}}function respondToInputRequest(e,t){let n=findToolPartByApprovalId(e,t.requestId);if(!n)return e;let r={id:t.requestId};return t.text!==void 0&&(r.reason=t.text),updateToolPart(e,n.toolCallId,{approval:r,input:n.input,state:`approval-responded`,stepIndex:n.stepIndex,toolCallId:n.toolCallId,toolMetadata:mergeToolMetadata(n.toolMetadata,{eve:{inputResponse:t,kind:n.toolMetadata?.eve?.kind??`unknown`,name:n.toolMetadata?.eve?.name??n.toolName}}),toolName:n.toolName,type:`dynamic-tool`})}function updateAssistantMessage(e,t,n){return upsertMessage(e,n(e.messages.find(e=>e.role===`assistant`&&e.metadata?.turnId===t)??createAssistantMessage(t)))}function updateAssistantMetadata(e,t,n){return updateAssistantMessage(e,t,e=>({...e,metadata:{...e.metadata,...n}}))}function createAssistantMessage(e){return{id:`${e}:assistant`,metadata:{status:`streaming`,turnId:e},parts:[],role:`assistant`}}function ensureStepStartPart(e,t){let n=e.parts.filter(e=>e.type===`step-start`).length;if(n>t)return e;let r=t-n+1;return{...e,parts:[...e.parts,...Array.from({length:r},()=>({type:`step-start`}))]}}function upsertPart(e,t){let n=e.parts.findIndex(e=>partKey(e)===partKey(t)),r=n===-1?[...e.parts,t]:[...e.parts.slice(0,n),t,...e.parts.slice(n+1)];return{...e,metadata:{...e.metadata,status:t.type===`text`&&t.state===`done`?`complete`:`streaming`},parts:r}}function upsertRun(e,t){let n=-1;for(let r=e.parts.length-1;r>=0;--r){let i=e.parts[r];if(i?.type===t.type&&i.stepIndex===t.stepIndex){n=r;break}}let r=n!==-1&&e.parts[n].state===`streaming`?[...e.parts.slice(0,n),t,...e.parts.slice(n+1)]:[...e.parts,t];return{...e,metadata:{...e.metadata,status:t.type===`text`&&t.state===`done`?`complete`:`streaming`},parts:r}}function removeTextPart(e,t){let n=e.parts.filter(e=>e.type!==`text`||e.stepIndex!==t);return n.length===e.parts.length?e:{...e,metadata:{...e.metadata,status:`complete`},parts:n}}function updateToolPart(e,t,n){let r=e.messages.find(e=>e.role===`assistant`&&e.parts.some(e=>e.type===`dynamic-tool`&&e.toolCallId===t));return r?upsertMessage(e,upsertPart(r,n)):e}function completeAuthorization(t,n){let r=findLatestPendingAuthorizationPart(t,n.data.name),i=createAuthorizationCompletedPart(n,r);return r===void 0?updateAssistantMessage(t,n.data.turnId,e=>upsertPart(ensureStepStartPart(e,n.data.stepIndex),i)):updateAuthorizationPart(t,r,i)}function updateAuthorizationPart(e,t,n){let r=e.messages.find(e=>e.role===`assistant`&&e.parts.some(e=>e===t));return r?upsertMessage(e,upsertPart(r,n)):e}function findToolPart(e,t){for(let n of e.messages)for(let e of n.parts)if(e.type===`dynamic-tool`&&e.toolCallId===t)return e}function isSettledToolPart(e){return e.state===`output-denied`||e.state===`output-error`||e.state===`output-available`&&e.partial!==!0}function findLatestPendingAuthorizationPart(e,t){for(let n=e.messages.length-1;n>=0;--n){let r=e.messages[n];if(r?.role===`assistant`)for(let e=r.parts.length-1;e>=0;--e){let n=r.parts[e];if(n?.type===`authorization`&&n.state===`required`&&n.name===t)return n}}}function findToolPartByApprovalId(e,t){for(let n of e.messages)for(let e of n.parts)if(e.type===`dynamic-tool`&&e.approval?.id===t)return e}function projectReceivedParts(e,t){return e?.map(e=>e.type===`text`?{state:`done`,text:e.text,type:`text`}:{filename:e.filename,mediaType:e.mediaType,size:e.size,type:`file`,url:e.url})??[{state:`done`,text:t,type:`text`}]}function partKey(e){switch(e.type){case`text`:return`text:${e.stepIndex??0}`;case`reasoning`:return`reasoning:${e.stepIndex??0}`;case`file`:return`file:${e.stepIndex??0}:${e.filename??e.url??e.mediaType}`;case`step-start`:return`step-start`;case`authorization`:return`authorization:${e.turnId}:${e.stepIndex}:${e.name}`;case`dynamic-tool`:return`dynamic-tool:${e.toolCallId}`}}function upsertMessage(e,t){let n=e.messages.findIndex(e=>e.id===t.id);return n===-1?{messages:[...e.messages,t]}:{messages:[...e.messages.slice(0,n),t,...e.messages.slice(n+1)]}}function optimisticUserMessageId(e){return`optimistic:${e}:user`}export{defaultMessageReducer};
|
|
@@ -4,23 +4,18 @@ import type { MessageResult } from "#client/types.js";
|
|
|
4
4
|
* Internal configuration passed to construct a {@link MessageResponse}.
|
|
5
5
|
*/
|
|
6
6
|
interface MessageResponseInput {
|
|
7
|
-
readonly continuationToken?: string;
|
|
8
7
|
readonly createStream: () => AsyncGenerator<MessageStreamEvent>;
|
|
9
8
|
readonly sessionId: string;
|
|
10
9
|
}
|
|
11
10
|
/**
|
|
12
11
|
* The response from {@link ClientSession.send}.
|
|
13
12
|
*
|
|
14
|
-
* Like `fetch()`, the response exposes
|
|
15
|
-
*
|
|
13
|
+
* Like `fetch()`, the response exposes its session ID as soon as the POST
|
|
14
|
+
* completes. Collect the event stream via
|
|
16
15
|
* {@link result} or iterate it with `for await...of`.
|
|
17
16
|
*/
|
|
18
17
|
export declare class MessageResponse<TOutput = unknown> implements AsyncIterable<MessageStreamEvent> {
|
|
19
18
|
#private;
|
|
20
|
-
/**
|
|
21
|
-
* Continuation token returned by the server for follow-up messages.
|
|
22
|
-
*/
|
|
23
|
-
readonly continuationToken: string | undefined;
|
|
24
19
|
/**
|
|
25
20
|
* Session ID assigned by the server.
|
|
26
21
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{summarizeTurnEvents}from"#client/session-utils.js";import{extractCompletedResult}from"#client/output-schema.js";var MessageResponse=class{
|
|
1
|
+
import{summarizeTurnEvents}from"#client/session-utils.js";import{extractCompletedResult}from"#client/output-schema.js";var MessageResponse=class{sessionId;#e=!1;#t;constructor(e){this.sessionId=e.sessionId,this.#t=e.createStream}async result(){let t=[];for await(let e of this)t.push(e);let n=summarizeTurnEvents(t);return{data:extractCompletedResult(t),events:t,inputRequests:n.inputRequests,message:n.message,sessionId:this.sessionId,status:n.status}}[Symbol.asyncIterator](){if(this.#e)throw Error(`MessageResponse has already been consumed.`);return this.#e=!0,this.#t()}};export{MessageResponse};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{createEveSessionStreamRoutePath}from"#protocol/routes.js";import{EVE_STREAM_TAIL_INDEX_HEADER}from"#protocol/message.js";import{ClientError}from"#client/client-error.js";import{createClientUrl}from"#client/url.js";import{isStreamDisconnectError,readNdjsonStream}from"#client/ndjson.js";const DEFAULT_STREAM_RECONNECT_POLICY={retryableErrorStatuses:new Set([404,409,425,500,502,503,504]),streamIdleReconnectPolicy:{baseDelayMs:250,maxAttempts:5,maxDelayMs:4e3},streamOpenReconnectPolicy:{baseDelayMs:250,maxAttempts:12,maxDelayMs:5e3}},NO_STREAM_RECONNECT_POLICY={...DEFAULT_STREAM_RECONNECT_POLICY,streamIdleReconnectPolicy:{...DEFAULT_STREAM_RECONNECT_POLICY.streamIdleReconnectPolicy,maxAttempts:0},streamOpenReconnectPolicy:{...DEFAULT_STREAM_RECONNECT_POLICY.streamOpenReconnectPolicy,maxAttempts:1}};function resolveRetryPolicy(e,t){return{...t,...e}}function resolveStreamReconnectPolicy(e){if(e&&`reconnect`in e&&e.reconnect===!1)return NO_STREAM_RECONNECT_POLICY;let t=e;return{retryableErrorStatuses:t?.retryableErrorStatuses?new Set(t.retryableErrorStatuses):DEFAULT_STREAM_RECONNECT_POLICY.retryableErrorStatuses,streamIdleReconnectPolicy:resolveRetryPolicy(t?.streamIdleReconnectPolicy,DEFAULT_STREAM_RECONNECT_POLICY.streamIdleReconnectPolicy),streamOpenReconnectPolicy:resolveRetryPolicy(t?.streamOpenReconnectPolicy,DEFAULT_STREAM_RECONNECT_POLICY.streamOpenReconnectPolicy)}}async function*followStreamIterable(e){if(e.follow===!1&&e.startIndex<0)throw Error(`stream({ follow: false }) requires a nonnegative startIndex; a tail-relative cursor cannot be bounded.`);let n=resolveStreamReconnectPolicy(e.streamReconnectPolicy),r=n.streamIdleReconnectPolicy,a=e.startIndex,o=r.baseDelayMs,s=0,c=!0,l;for(;;){let u;try{u=await openStreamBody({...e,retryPolicy:n,startIndex:a,requestTailIndex:e.follow===!1&&l===void 0})}catch(t){if(e.signal?.aborted)return;throw t}if(e.follow===!1&&l===void 0&&(l=u.tailIndex,l===void 0))throw await u.body.cancel().catch(()=>{}),Error(`stream({ follow: false }) requires the server to report the ${EVE_STREAM_TAIL_INDEX_HEADER} header. The agent may be running an older eve version.`);if(l!==void 0&&a>l){await u.body.cancel().catch(()=>{});return}let d=!1;try{for await(let e of readNdjsonStream(u.body))if(a+=1,d=!0,o=r.baseDelayMs,s=0,yield e,l!==void 0&&a>l)return}catch(e){if(!isStreamDisconnectError(e))throw e}if(e.signal?.aborted||e.startIndex<0||r.maxAttempts===0||!d&&!c&&(s+=1)>=r.maxAttempts||(c=!1,await sleep(o,e.signal),e.signal?.aborted))return;o=Math.min(o*2,r.maxDelayMs)}}async function openStreamBody(t){let i=t.retryPolicy??DEFAULT_STREAM_RECONNECT_POLICY,o=i.streamOpenReconnectPolicy,s,c,l,u=o.baseDelayMs,d={};t.startIndex!==0&&(d.startIndex=String(t.startIndex)),t.requestTailIndex===!0&&(d.includeTailIndex=`1`);for(let a=0;a<o.maxAttempts;a+=1){let f=createClientUrl(t.host,createEveSessionStreamRoutePath(t.sessionId),Object.keys(d).length>0?d:void 0),p=await t.resolveHeaders(),m;try{m=await fetch(f,{cache:`no-store`,headers:p,redirect:t.redirect,signal:t.signal??null})}catch(e){if(t.signal?.aborted||!isStreamDisconnectError(e)||a===o.maxAttempts-1)throw e;await sleep(u,t.signal),u=Math.min(u*2,o.maxDelayMs);continue}if(m.ok){if(!m.body)throw new ClientError(m.status,`Response body is null.`,m.headers);return{body:m.body,tailIndex:parseTailIndexHeader(m.headers)}}if(s=m.status,c=await m.text(),l=m.headers,!i.retryableErrorStatuses.has(m.status))throw new ClientError(m.status,c,m.headers);a<o.maxAttempts-1&&(await sleep(u,t.signal),u=Math.min(u*2,o.maxDelayMs))}throw new ClientError(s??0,c??`Failed to open message stream.`,l)}function parseTailIndexHeader(e){let n=e.get(EVE_STREAM_TAIL_INDEX_HEADER);if(n===null||!/^-?\d+$/.test(n))return;let r=Number(n);return Number.isSafeInteger(r)?r:void 0}async function sleep(e,t){t?.aborted||await new Promise(n=>{let onAbort=()=>{clearTimeout(r),n()},r=setTimeout(()=>{t?.removeEventListener(`abort`,onAbort),n()},e);t?.addEventListener(`abort`,onAbort,{once:!0})})}export{followStreamIterable,openStreamBody};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { CancelSessionResult, ClearResult, ClientRedirectPolicy, CompactResult, ResetResult } from "#client/types.js";
|
|
2
|
+
interface SessionControlContext {
|
|
3
|
+
readonly host: string;
|
|
4
|
+
readonly redirect?: ClientRedirectPolicy;
|
|
5
|
+
resolveHeaders(): Promise<Headers>;
|
|
6
|
+
}
|
|
7
|
+
export declare function cancelClientSession(input: {
|
|
8
|
+
readonly context: SessionControlContext;
|
|
9
|
+
readonly options?: {
|
|
10
|
+
readonly turnId?: string;
|
|
11
|
+
};
|
|
12
|
+
readonly sessionId: string;
|
|
13
|
+
}): Promise<CancelSessionResult>;
|
|
14
|
+
export declare function clearClientSession(input: {
|
|
15
|
+
readonly context: SessionControlContext;
|
|
16
|
+
readonly sessionId: string;
|
|
17
|
+
}): Promise<ClearResult>;
|
|
18
|
+
export declare function compactClientSession(input: {
|
|
19
|
+
readonly context: SessionControlContext;
|
|
20
|
+
readonly sessionId: string;
|
|
21
|
+
}): Promise<CompactResult>;
|
|
22
|
+
export declare function resetClientSession(input: {
|
|
23
|
+
readonly context: SessionControlContext;
|
|
24
|
+
readonly options?: {
|
|
25
|
+
readonly reason?: string;
|
|
26
|
+
};
|
|
27
|
+
readonly sessionId: string;
|
|
28
|
+
}): Promise<ResetResult>;
|
|
29
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{createEveSessionCancelRoutePath,createEveSessionClearRoutePath,createEveSessionCompactRoutePath,createEveSessionResetRoutePath}from"#protocol/routes.js";import{ClientError}from"#client/client-error.js";import{createClientUrl}from"#client/url.js";import{CancelTurnResponseSchema}from"#protocol/cancel-turn.js";import{ClearResponseSchema}from"#protocol/clear-session.js";import{CompactResponseSchema}from"#protocol/compact-session.js";import{ResetResponseSchema}from"#protocol/reset-session.js";async function cancelClientSession(t){let{payload:n,response:r}=await postJson({body:t.options,context:t.context,operation:`Cancel`,path:createEveSessionCancelRoutePath(t.sessionId)}),i=CancelTurnResponseSchema.safeParse(n);if(!i.success||i.data.status===`accepted`&&i.data.sessionId!==t.sessionId)throw Error(`Cancel route returned an invalid response (${r.status}).`);return i.data.status===`accepted`?{sessionId:i.data.sessionId,status:`accepted`}:{status:`no_active_turn`}}async function clearClientSession(e){let{payload:n}=await postJson({context:e.context,operation:`Clear`,path:createEveSessionClearRoutePath(e.sessionId)}),r=ClearResponseSchema.safeParse(n);if(!r.success||r.data.status===`accepted`&&r.data.sessionId!==e.sessionId)throw Error(`Clear route returned an invalid response.`);return r.data.status===`accepted`?{sessionId:r.data.sessionId,status:`accepted`}:{status:`no_active_session`}}async function compactClientSession(e){let{payload:t}=await postJson({context:e.context,operation:`Compact`,path:createEveSessionCompactRoutePath(e.sessionId)}),r=CompactResponseSchema.safeParse(t);if(!r.success||r.data.status===`accepted`&&r.data.sessionId!==e.sessionId)throw Error(`Compact route returned an invalid response.`);return r.data.status===`accepted`?{sessionId:r.data.sessionId,status:`accepted`}:{status:`no_active_session`}}async function resetClientSession(e){let{payload:t}=await postJson({body:e.options,context:e.context,operation:`Reset`,path:createEveSessionResetRoutePath(e.sessionId)}),n=ResetResponseSchema.safeParse(t);if(!n.success||n.data.status===`reset`&&n.data.previousSessionId!==e.sessionId)throw Error(`Reset route returned an invalid response.`);return n.data.status===`reset`?{previousSessionId:n.data.previousSessionId,status:`reset`}:{status:`no_active_session`}}async function postJson(e){let t=await e.context.resolveHeaders();t.set(`content-type`,`application/json`);let n=await fetch(createClientUrl(e.context.host,e.path),withRedirectPolicy({body:e.body===void 0?void 0:JSON.stringify(e.body),headers:t,method:`POST`},e.context.redirect)),r=await n.text();if(!n.ok)throw new ClientError(n.status,r,n.headers);try{return{payload:JSON.parse(r),response:n}}catch{throw Error(`${e.operation} route returned invalid JSON (${n.status}).`)}}function withRedirectPolicy(e,t){return t===void 0?e:{...e,redirect:t}}export{cancelClientSession,clearClientSession,compactClientSession,resetClientSession};
|
|
@@ -1,25 +1,5 @@
|
|
|
1
1
|
import type { AuthorizationRequiredStreamEvent, TurnFailureStreamEvent, UnstampedMessageStreamEvent } from "#protocol/message.js";
|
|
2
|
-
import type { SessionState } from "#client/types.js";
|
|
3
2
|
import type { InputRequest } from "#runtime/input/types.js";
|
|
4
|
-
/**
|
|
5
|
-
* Returns a fresh session state with no active run.
|
|
6
|
-
*/
|
|
7
|
-
export declare function createInitialSessionState(): SessionState;
|
|
8
|
-
/**
|
|
9
|
-
* Advances the session cursor after one streamed turn completes.
|
|
10
|
-
*
|
|
11
|
-
* When the boundary event is `session.waiting`, the session is preserved for
|
|
12
|
-
* the next message. For `session.completed` and `session.failed`, the session
|
|
13
|
-
* resets so the next call starts a new conversation. Without a boundary, the
|
|
14
|
-
* session stays resumable from its advanced cursor.
|
|
15
|
-
*/
|
|
16
|
-
export declare function advanceSession(input: {
|
|
17
|
-
readonly continuationToken?: string;
|
|
18
|
-
readonly events: readonly UnstampedMessageStreamEvent[];
|
|
19
|
-
readonly preserveCompletedSessions?: boolean;
|
|
20
|
-
readonly sessionId: string;
|
|
21
|
-
readonly session: SessionState;
|
|
22
|
-
}): SessionState;
|
|
23
3
|
/** A connection authorization challenge that remains unresolved at a turn boundary. */
|
|
24
4
|
export interface PendingAuthorization {
|
|
25
5
|
readonly authorization?: AuthorizationRequiredStreamEvent["data"]["authorization"];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{isCurrentTurnBoundaryEvent,isTurnFailureEvent}from"#protocol/message.js";function
|
|
1
|
+
import{isCurrentTurnBoundaryEvent,isTurnFailureEvent}from"#protocol/message.js";function summarizeTurnEvents(n){let r,i,a,o=[],s=new Map;for(let c of n)isCurrentTurnBoundaryEvent(c)&&(r=c),isTurnFailureEvent(c)&&(i=c),isFinalMessageCompleted(c)&&(a=c.data.message??void 0),c.type===`input.requested`&&o.push(...c.data.requests),c.type===`authorization.required`&&s.set(c.data.name,c.data),c.type===`authorization.completed`&&s.delete(c.data.name);return{boundary:r,failure:i,inputRequests:o,message:a,pendingAuthorizations:[...s.values()],status:r?.type===`session.waiting`?`waiting`:r?.type===`session.failed`?`failed`:`completed`}}async function collectTurnEvents(t){let n=[];for await(let r of t)if(n.push(r),isCurrentTurnBoundaryEvent(r))break;return n}function isFinalMessageCompleted(e){return e.type===`message.completed`&&e.data.finishReason!==`tool-calls`}export{collectTurnEvents,summarizeTurnEvents};
|
|
@@ -1,112 +1,48 @@
|
|
|
1
1
|
import type { MessageStreamEvent } from "#protocol/message.js";
|
|
2
2
|
import { MessageResponse } from "#client/message-response.js";
|
|
3
|
-
import type {
|
|
3
|
+
import type { InputResponse } from "#runtime/input/types.js";
|
|
4
|
+
import type { CancelSessionResult, ClearResult, ClientSessionState, CompactResult, ClientRedirectPolicy, RespondTurnOptions, ResetResult, SendTurnInput, SendTurnOptions, SessionSnapshot, StreamOptions } from "#client/types.js";
|
|
4
5
|
/**
|
|
5
6
|
* Internal interface that a {@link ClientSession} uses to access client-level
|
|
6
7
|
* configuration without depending on the full {@link Client} class.
|
|
7
8
|
*/
|
|
8
|
-
interface
|
|
9
|
+
export interface ClientSessionContext {
|
|
9
10
|
readonly host: string;
|
|
10
|
-
readonly preserveCompletedSessions: boolean;
|
|
11
11
|
readonly redirect?: ClientRedirectPolicy;
|
|
12
12
|
resolveHeaders(perRequest?: Readonly<Record<string, string>>): Promise<Headers>;
|
|
13
13
|
}
|
|
14
|
-
/**
|
|
15
|
-
* One conversation with an eve agent.
|
|
16
|
-
*
|
|
17
|
-
* A session tracks conversation state (continuation token, session ID, stream
|
|
18
|
-
* cursor) automatically across {@link send} calls. Read the state from
|
|
19
|
-
* the {@link state} getter and serialize it to persist a session.
|
|
20
|
-
*/
|
|
14
|
+
/** One fixed, ID-addressed conversation with an eve agent. */
|
|
21
15
|
export declare class ClientSession {
|
|
22
16
|
#private;
|
|
23
17
|
/** @internal */
|
|
24
|
-
constructor(context:
|
|
25
|
-
/**
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
*
|
|
34
|
-
* The read starts at the beginning of the session and stops at the durable
|
|
35
|
-
* tail observed when it opens. The returned cursor points exactly after the
|
|
36
|
-
* returned events, so it can hydrate a UI and resume without a gap.
|
|
37
|
-
* Reading a snapshot does not advance or reset this handle's state.
|
|
38
|
-
*
|
|
39
|
-
* @throws {Error} If the session has no session ID (no message has been sent
|
|
40
|
-
* yet).
|
|
41
|
-
*/
|
|
18
|
+
constructor(context: ClientSessionContext, state: ClientSessionState);
|
|
19
|
+
/** @internal */
|
|
20
|
+
static create<TOutput = unknown>(context: ClientSessionContext, input: SendTurnInput<TOutput>): Promise<{
|
|
21
|
+
readonly response: MessageResponse<TOutput>;
|
|
22
|
+
readonly session: ClientSession;
|
|
23
|
+
}>;
|
|
24
|
+
/** Current fixed session identity and durable stream cursor. */
|
|
25
|
+
get state(): ClientSessionState;
|
|
26
|
+
/** Reads a finite prefix through the durable tail without advancing this handle. */
|
|
42
27
|
snapshot(options?: {
|
|
43
28
|
readonly signal?: AbortSignal;
|
|
44
29
|
}): Promise<SessionSnapshot>;
|
|
45
|
-
/**
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
* headers in a single request.
|
|
51
|
-
*/
|
|
52
|
-
send<TOutput = unknown>(input: SendTurnInput<TOutput>): Promise<MessageResponse<TOutput>>;
|
|
53
|
-
/**
|
|
54
|
-
* Requests cooperative cancellation of this session's active turn.
|
|
55
|
-
*
|
|
56
|
-
* Both `accepted` and `no_active_turn` are successful outcomes. The latter
|
|
57
|
-
* means the active turn settled before the request arrived or the session is
|
|
58
|
-
* already parked. `turnId` limits the request to the turn the caller
|
|
59
|
-
* observed; a stale guard is consumed as a benign no-op. Credentials are
|
|
60
|
-
* resolved immediately before the request.
|
|
61
|
-
*
|
|
62
|
-
* @throws {Error} If this handle has not started or attached to a session.
|
|
63
|
-
* @throws {ClientError} If the cancel route returns a non-successful status.
|
|
64
|
-
*/
|
|
30
|
+
/** Sends a message to this exact session ID. */
|
|
31
|
+
send<TOutput = unknown>(message: SendTurnInput<TOutput>["message"], options?: SendTurnOptions<TOutput>): Promise<MessageResponse<TOutput>>;
|
|
32
|
+
/** Answers pending input requests on this exact session ID. */
|
|
33
|
+
respond<TOutput = unknown>(inputResponses: readonly InputResponse[], options?: RespondTurnOptions<TOutput>): Promise<MessageResponse<TOutput>>;
|
|
34
|
+
/** Requests cooperative cancellation of this session's active turn. */
|
|
65
35
|
cancel(options?: {
|
|
66
|
-
turnId?: string;
|
|
36
|
+
readonly turnId?: string;
|
|
67
37
|
}): Promise<CancelSessionResult>;
|
|
68
|
-
/**
|
|
69
|
-
* Queues removal of this session's durable model-message history. The
|
|
70
|
-
* session identity, agent configuration, state, limits, and sandbox remain.
|
|
71
|
-
* Consume the durable stream through `context.cleared` and its following
|
|
72
|
-
* `session.waiting` boundary before sending another turn.
|
|
73
|
-
*/
|
|
38
|
+
/** Queues removal of this session's durable model-message history. */
|
|
74
39
|
clear(): Promise<ClearResult>;
|
|
75
|
-
/**
|
|
76
|
-
* Queues context compaction without sending model input. The request is
|
|
77
|
-
* asynchronous; consume the durable event stream through its next session
|
|
78
|
-
* boundary before sending another turn. `compaction.completed` confirms that
|
|
79
|
-
* summarization succeeded. A never-started handle is a successful no-op.
|
|
80
|
-
*/
|
|
40
|
+
/** Queues context compaction without sending model input. */
|
|
81
41
|
compact(): Promise<CompactResult>;
|
|
82
|
-
/**
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
* fresh conversation and initializes a new session-scoped sandbox on first
|
|
88
|
-
* sandbox use. Resetting a never-started handle is a successful no-op. After
|
|
89
|
-
* a successful reset, this handle has no session state.
|
|
90
|
-
*
|
|
91
|
-
* @throws {ClientError} If the reset route returns a non-successful status.
|
|
92
|
-
*/
|
|
93
|
-
reset(): Promise<ResetResult>;
|
|
94
|
-
/**
|
|
95
|
-
* Opens this session's event stream for the current session ID.
|
|
96
|
-
*
|
|
97
|
-
* Resumes from the session's stored stream cursor unless `options.startIndex`
|
|
98
|
-
* overrides it. By default, the stream reconnects from its cursor when the
|
|
99
|
-
* connection ends; pass `streamReconnectPolicy: { reconnect: false }` to use
|
|
100
|
-
* one connection. Negative indices read relative to the current tail on one connection
|
|
101
|
-
* and do not advance the stored absolute cursor.
|
|
102
|
-
*
|
|
103
|
-
* Pass `follow: false` for a bounded read: yields events up to the durable
|
|
104
|
-
* tail observed when the stream opens, then returns instead of following.
|
|
105
|
-
* The stored cursor still advances past the consumed events.
|
|
106
|
-
*
|
|
107
|
-
* @throws {Error} If the session has no session ID (no message has been sent
|
|
108
|
-
* yet), or if `follow: false` is combined with a negative `startIndex`.
|
|
109
|
-
*/
|
|
42
|
+
/** Terminally retires this exact session ID. The handle remains pinned to it. */
|
|
43
|
+
reset(options?: {
|
|
44
|
+
readonly reason?: string;
|
|
45
|
+
}): Promise<ResetResult>;
|
|
46
|
+
/** Opens this session's durable event stream from its stored cursor. */
|
|
110
47
|
stream(options?: StreamOptions): AsyncIterable<MessageStreamEvent>;
|
|
111
48
|
}
|
|
112
|
-
export {};
|