eve 0.21.0 → 0.22.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.
Files changed (114) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/dist/src/channel/adapter.d.ts +3 -7
  3. package/dist/src/compiler/manifest.d.ts +16 -26
  4. package/dist/src/compiler/manifest.js +1 -1
  5. package/dist/src/compiler/normalize-agent-config.js +1 -1
  6. package/dist/src/compiler/normalize-hook.d.ts +2 -2
  7. package/dist/src/compiler/normalize-instructions.d.ts +3 -3
  8. package/dist/src/compiler/normalize-instructions.js +1 -1
  9. package/dist/src/compiler/normalize-skill.js +1 -1
  10. package/dist/src/compiler/normalize-tool.d.ts +2 -2
  11. package/dist/src/context/container.d.ts +2 -0
  12. package/dist/src/context/dynamic-model-lifecycle.d.ts +19 -0
  13. package/dist/src/context/dynamic-model-lifecycle.js +1 -0
  14. package/dist/src/context/keys.d.ts +13 -1
  15. package/dist/src/context/keys.js +1 -1
  16. package/dist/src/discover/manifest.d.ts +8 -0
  17. package/dist/src/evals/cli/eval.js +2 -2
  18. package/dist/src/evals/reporters/index.d.ts +1 -0
  19. package/dist/src/evals/reporters/index.js +1 -1
  20. package/dist/src/evals/runner/reporters/console.d.ts +10 -11
  21. package/dist/src/evals/runner/reporters/console.js +1 -1
  22. package/dist/src/execution/node-step.js +1 -1
  23. package/dist/src/execution/sandbox/bindings/microsandbox-options.d.ts +2 -2
  24. package/dist/src/execution/sandbox/bindings/microsandbox.d.ts +2 -2
  25. package/dist/src/execution/sandbox/ensure.js +1 -1
  26. package/dist/src/execution/session.js +2 -2
  27. package/dist/src/execution/workflow-steps.js +1 -1
  28. package/dist/src/harness/emission.d.ts +1 -0
  29. package/dist/src/harness/emission.js +1 -1
  30. package/dist/src/harness/input-extraction.d.ts +1 -0
  31. package/dist/src/harness/input-extraction.js +1 -1
  32. package/dist/src/harness/input-requests.js +1 -1
  33. package/dist/src/harness/step-hooks.d.ts +4 -1
  34. package/dist/src/harness/step-hooks.js +1 -1
  35. package/dist/src/harness/tool-call-input-errors.d.ts +8 -0
  36. package/dist/src/harness/tool-call-input-errors.js +1 -0
  37. package/dist/src/harness/tool-loop.js +1 -1
  38. package/dist/src/harness/types.d.ts +9 -0
  39. package/dist/src/internal/application/package.js +1 -1
  40. package/dist/src/internal/authored-definition/core.js +1 -1
  41. package/dist/src/internal/authored-definition/schema-backed.js +1 -1
  42. package/dist/src/internal/nitro/host/sandbox-shutdown-plugin.js +1 -1
  43. package/dist/src/internal/nitro/host/types.d.ts +2 -2
  44. package/dist/src/internal/nitro/routes/agent-info/build-agent-info-response.d.ts +2 -2
  45. package/dist/src/internal/nitro/routes/agent-info/load-agent-info-data.d.ts +4 -4
  46. package/dist/src/internal/runtime-model.d.ts +1 -1
  47. package/dist/src/protocol/message.d.ts +1 -0
  48. package/dist/src/public/channels/chat-sdk/chatSdkChannel.d.ts +1 -1
  49. package/dist/src/public/channels/chat-sdk/chatSdkChannel.js +2 -2
  50. package/dist/src/public/channels/discord/discordChannel.d.ts +2 -2
  51. package/dist/src/public/channels/discord/discordChannel.js +1 -1
  52. package/dist/src/public/channels/eve.d.ts +1 -1
  53. package/dist/src/public/channels/eve.js +1 -1
  54. package/dist/src/public/channels/github/dispatch.d.ts +1 -1
  55. package/dist/src/public/channels/github/githubChannel.d.ts +2 -2
  56. package/dist/src/public/channels/github/githubChannel.js +1 -1
  57. package/dist/src/public/channels/index.d.ts +2 -2
  58. package/dist/src/public/channels/index.js +1 -1
  59. package/dist/src/public/channels/linear/linearChannel.d.ts +1 -1
  60. package/dist/src/public/channels/linear/linearChannel.js +1 -1
  61. package/dist/src/public/channels/slack/interactions.d.ts +1 -1
  62. package/dist/src/public/channels/slack/slackChannel.d.ts +2 -2
  63. package/dist/src/public/channels/slack/slackChannel.js +1 -1
  64. package/dist/src/public/channels/teams/teamsChannel.d.ts +2 -2
  65. package/dist/src/public/channels/teams/teamsChannel.js +1 -1
  66. package/dist/src/public/channels/telegram/telegramChannel.d.ts +2 -2
  67. package/dist/src/public/channels/telegram/telegramChannel.js +1 -1
  68. package/dist/src/public/channels/twilio/twilioChannel.d.ts +2 -2
  69. package/dist/src/public/channels/twilio/twilioChannel.js +1 -1
  70. package/dist/src/public/definitions/agent.d.ts +1 -1
  71. package/dist/src/public/definitions/channel.d.ts +99 -0
  72. package/dist/src/public/definitions/channel.js +1 -1
  73. package/dist/src/public/definitions/hook.d.ts +3 -10
  74. package/dist/src/public/definitions/instructions.d.ts +2 -18
  75. package/dist/src/public/definitions/schedule.d.ts +4 -17
  76. package/dist/src/public/definitions/tool.d.ts +10 -4
  77. package/dist/src/public/definitions/tool.js +1 -1
  78. package/dist/src/public/hooks/index.d.ts +1 -1
  79. package/dist/src/public/hooks/index.js +1 -1
  80. package/dist/src/public/index.d.ts +2 -0
  81. package/dist/src/public/index.js +1 -1
  82. package/dist/src/public/sandbox/backends/default.d.ts +2 -2
  83. package/dist/src/public/sandbox/backends/microsandbox.d.ts +2 -2
  84. package/dist/src/public/sandbox/microsandbox-sandbox.d.ts +1 -1
  85. package/dist/src/public/sandbox/microsandbox.d.ts +1 -1
  86. package/dist/src/runtime/agent/bootstrap.d.ts +8 -0
  87. package/dist/src/runtime/agent/bootstrap.js +1 -1
  88. package/dist/src/runtime/agent/resolve-model.d.ts +16 -1
  89. package/dist/src/runtime/agent/resolve-model.js +1 -1
  90. package/dist/src/runtime/hooks/registry.d.ts +2 -1
  91. package/dist/src/runtime/prompt/compose.d.ts +2 -2
  92. package/dist/src/runtime/resolve-agent.js +1 -1
  93. package/dist/src/runtime/schedules/register.d.ts +2 -2
  94. package/dist/src/runtime/schedules/resolve-schedule.d.ts +4 -4
  95. package/dist/src/runtime/types.d.ts +7 -4
  96. package/dist/src/setup/scaffold/create/project.js +1 -1
  97. package/dist/src/shared/agent-definition.d.ts +30 -7
  98. package/dist/src/shared/agent-definition.js +1 -1
  99. package/dist/src/shared/channel-definition.d.ts +92 -0
  100. package/dist/src/shared/channel-definition.js +1 -0
  101. package/dist/src/shared/dynamic-tool-definition.d.ts +18 -8
  102. package/dist/src/shared/dynamic-tool-definition.js +1 -1
  103. package/dist/src/shared/hook-definition.d.ts +36 -0
  104. package/dist/src/shared/hook-definition.js +1 -0
  105. package/dist/src/shared/instructions-definition.d.ts +26 -0
  106. package/dist/src/shared/instructions-definition.js +1 -0
  107. package/dist/src/shared/schedule-definition.d.ts +34 -0
  108. package/dist/src/shared/schedule-definition.js +1 -0
  109. package/dist/src/source-change/apply-model-name.js +1 -1
  110. package/docs/agent-config.md +44 -0
  111. package/docs/guides/dynamic-capabilities.md +18 -2
  112. package/package.json +1 -1
  113. package/dist/src/public/definitions/defineChannel.d.ts +0 -157
  114. package/dist/src/public/definitions/defineChannel.js +0 -1
@@ -2,6 +2,7 @@ import type { CallSettings, LanguageModel } from "ai";
2
2
  import type { StandardJSONSchemaV1 } from "#compiled/@standard-schema/spec/index.js";
3
3
  import type { JsonObject } from "#shared/json.js";
4
4
  import type { ModuleSourceRef } from "#shared/source-ref.js";
5
+ import { type DynamicResolveContext, type DynamicSentinel } from "#shared/dynamic-tool-definition.js";
5
6
  /**
6
7
  * Optional overrides that eve forwards to the AI SDK model runtime call for
7
8
  * this model.
@@ -46,11 +47,32 @@ export type InternalAgentModelDefinition = {
46
47
  providerOptions?: Record<string, JsonObject>;
47
48
  };
48
49
  /**
49
- * The model handle you assign to an agent's `model` field. This is the AI SDK
50
- * `LanguageModel` value (for example, the result of a provider or gateway
51
- * model call), not an eve-authored definition object.
50
+ * A concrete model handle: an AI Gateway model id string or an AI SDK
51
+ * `LanguageModel` instance.
52
52
  */
53
- export type PublicAgentModelDefinition = LanguageModel;
53
+ export type PublicAgentStaticModelDefinition = string | LanguageModel;
54
+ /** Context passed to dynamic model event handlers; the shared dynamic resolver context. */
55
+ export type AgentModelResolveContext = DynamicResolveContext;
56
+ export interface PublicAgentModelSelectionDefinition {
57
+ readonly model: PublicAgentStaticModelDefinition;
58
+ /** Context window of the selected model, in tokens; never inherited from the fallback. */
59
+ readonly modelContextWindowTokens?: number;
60
+ /** Provider options for the selected model; defaults to the agent-level `modelOptions`. */
61
+ readonly modelOptions?: AgentModelOptionsDefinition;
62
+ }
63
+ export type PublicAgentDynamicModelResult = PublicAgentStaticModelDefinition | PublicAgentModelSelectionDefinition | null;
64
+ export type AgentModelResolver = (event: unknown, ctx: AgentModelResolveContext) => PublicAgentDynamicModelResult | Promise<PublicAgentDynamicModelResult>;
65
+ export type PublicAgentDynamicModelDefinition = DynamicSentinel<PublicAgentDynamicModelResult, PublicAgentStaticModelDefinition>;
66
+ export interface PublicAgentDynamicModelDefinitionInput {
67
+ /** Compiled static model: build-time metadata and the active model when no scope is set. */
68
+ readonly fallback: PublicAgentStaticModelDefinition;
69
+ readonly events: DynamicSentinel<PublicAgentDynamicModelResult>["events"];
70
+ }
71
+ export declare function isDynamicModelDefinition(value: unknown): value is PublicAgentDynamicModelDefinition;
72
+ /**
73
+ * The model handle you assign to an agent's `model` field.
74
+ */
75
+ export type PublicAgentModelDefinition = PublicAgentStaticModelDefinition | PublicAgentDynamicModelDefinition;
54
76
  export interface InternalAgentCompactionDefinition {
55
77
  /**
56
78
  * Optional model used only for generating compaction summaries.
@@ -85,7 +107,7 @@ export interface PublicAgentCompactionDefinition {
85
107
  *
86
108
  * When omitted, eve uses the active turn model for the summary call.
87
109
  */
88
- readonly model?: PublicAgentModelDefinition;
110
+ readonly model?: PublicAgentStaticModelDefinition;
89
111
  /**
90
112
  * Fraction of the primary model context window that triggers compaction.
91
113
  *
@@ -239,8 +261,9 @@ export type PublicAgentDefinition = {
239
261
  */
240
262
  readonly experimental?: AgentExperimentalDefinition;
241
263
  /**
242
- * Language model used for agent turns. Accepts an AI Gateway model ID or any
243
- * AI SDK-compatible language model.
264
+ * Language model used for agent turns. Accepts an AI Gateway model ID, any AI
265
+ * SDK-compatible language model, or `defineDynamic({ fallback, events })` for
266
+ * scoped dynamic model selection.
244
267
  */
245
268
  readonly model: PublicAgentModelDefinition;
246
269
  /**
@@ -1 +1 @@
1
- export{};
1
+ import{isDynamicSentinel}from"#shared/dynamic-tool-definition.js";function isDynamicModelDefinition(e){return isDynamicSentinel(e)&&`fallback`in e}export{isDynamicModelDefinition};
@@ -0,0 +1,92 @@
1
+ import { type ChannelCors } from "#channel/cors.js";
2
+ import type { RouteDefinition, SendFn } from "#channel/routes.js";
3
+ import type { Session, SessionHandle } from "#channel/session.js";
4
+ import type { SessionAuthContext } from "#channel/types.js";
5
+ /**
6
+ * Enriched return shape from a channel's {@link ChannelAdapter.fetchFile}
7
+ * function. Return a bare {@link Buffer} when only bytes are known, or
8
+ * this record when the fetch discovers a more accurate `mediaType` or
9
+ * `filename` (e.g. from an HTTP `Content-Type` header).
10
+ *
11
+ * When fields are provided, staging prefers them over the values the
12
+ * channel populated at ingestion time.
13
+ */
14
+ export interface FetchFileResult {
15
+ readonly bytes: Buffer;
16
+ readonly mediaType?: string;
17
+ readonly filename?: string;
18
+ }
19
+ export type FetchFileFunction = (url: string) => Promise<Buffer | FetchFileResult | null>;
20
+ /**
21
+ * Input passed to a channel's `receive` callback when another channel or
22
+ * schedule proactively routes a message to it.
23
+ */
24
+ export interface GenericReceiveInput<TReceiveTarget = Record<string, unknown>> {
25
+ readonly message: string;
26
+ readonly target: Readonly<TReceiveTarget>;
27
+ readonly auth: SessionAuthContext | null;
28
+ }
29
+ /**
30
+ * The object passed to {@link defineChannel}. `routes` is required; `state`
31
+ * seeds durable adapter state, `context` builds the per-step `channel` argument
32
+ * for `events` and `deliver`, `events` handle session lifecycle, `receive`
33
+ * accepts cross-channel handoffs, `fetchFile` stages remote file URLs, and
34
+ * `metadata` projects observability data.
35
+ *
36
+ * Generics: `TState` (adapter state), `TCtx` (context factory return type),
37
+ * `TReceiveTarget` (cross-channel target shape), `TMetadata` (instrumentation
38
+ * projection).
39
+ */
40
+ export interface GenericChannelDefinition<TEvents, TState = undefined, TCtx = void, TReceiveTarget = Record<string, unknown>, TMetadata extends Record<string, unknown> = Record<string, unknown>> {
41
+ readonly state?: TState;
42
+ /**
43
+ * CORS policy for this channel's HTTP routes. `true` enables H3/Nitro's
44
+ * permissive defaults (`origin`, methods, request headers, and exposed
45
+ * headers all `"*"`); `false` or omission leaves CORS untouched. Pass an
46
+ * object for a serializable subset of H3/Nitro CORS options.
47
+ */
48
+ readonly cors?: ChannelCors;
49
+ /**
50
+ * Builds the per-step channel context handed to `events` and `deliver`.
51
+ * Receives the live {@link SessionHandle}, so a factory can close over it to
52
+ * register late-bound callbacks. eve writes state mutations made inside the
53
+ * returned context back through `adapter.state`.
54
+ *
55
+ * Return the channel-owned context (thread handles, API clients, etc.). The
56
+ * framework passes it as the `channel` argument to event handlers (with
57
+ * {@link ChannelSessionOps} injected) and passes {@link SessionContext} as a
58
+ * separate `ctx` argument.
59
+ */
60
+ context?(state: NonNullable<TState>, session: SessionHandle): TCtx;
61
+ readonly routes: readonly RouteDefinition<TState>[];
62
+ receive?(input: GenericReceiveInput<TReceiveTarget>, args: {
63
+ send: SendFn<TState>;
64
+ }): Promise<Session>;
65
+ readonly events?: TEvents;
66
+ /**
67
+ * Fetches bytes for a `URL` object encountered on a `FilePart.data` by the
68
+ * staging pipeline. Return `null` to pass the URL through to the model
69
+ * provider unchanged, or bytes / {@link FetchFileResult} to stage the file to
70
+ * the sandbox.
71
+ */
72
+ readonly fetchFile?: FetchFileFunction;
73
+ /**
74
+ * Channel-owned metadata exposed to instrumentation callbacks. This is the
75
+ * channel's public observability surface, not a dump of durable adapter state,
76
+ * so keep it small. Return an object of JSON primitives, arrays, and plain
77
+ * objects: eve omits `undefined` properties and drops projections containing
78
+ * values such as `Date` or `Map`.
79
+ */
80
+ readonly metadata?: (state: NonNullable<TState>) => TMetadata;
81
+ /**
82
+ * Identifier of the adapter family this channel belongs to. Set by
83
+ * higher-level wrappers (e.g. `slackChannel` passes `"slack"`) so downstream
84
+ * consumers can render typed channel chips instead of bucketing everything
85
+ * under "unknown".
86
+ *
87
+ * Authors calling `defineChannel` directly do not need to set this; the
88
+ * framework defaults to `"http"` for stateless channels and `"defineChannel"`
89
+ * for stateful ones.
90
+ */
91
+ readonly kindHint?: string;
92
+ }
@@ -0,0 +1 @@
1
+ import"#channel/cors.js";export{};
@@ -107,22 +107,32 @@ export type DynamicToolEvents = {
107
107
  * the slot directory (tools/ vs skills/) determines the required return,
108
108
  * validated at runtime by the respective resolver.
109
109
  */
110
- export type DynamicEvents = {
111
- readonly [K in DynamicToolEventName]?: (event: unknown, ctx: DynamicResolveContext) => unknown | Promise<unknown>;
110
+ export type DynamicEvents<TResult = unknown> = {
111
+ readonly [K in DynamicToolEventName]?: (event: unknown, ctx: DynamicResolveContext) => TResult | Promise<TResult>;
112
+ };
113
+ export type DynamicEventsWithFallback<TResult = unknown> = {
114
+ readonly [K in DynamicToolEventName]?: (event: unknown, ctx: DynamicResolveContext) => Exclude<TResult, undefined> | Promise<Exclude<TResult, undefined>>;
112
115
  };
113
116
  /**
114
117
  * Marker discriminator for a `defineDynamic({ events })` export.
115
118
  */
116
119
  export declare const DYNAMIC_SENTINEL_KIND: "eve:dynamic";
117
120
  /**
118
- * Return value of `defineDynamic`: the runtime shape of a
119
- * `defineDynamic({ events })` export, stamped with a sentinel kind the
120
- * compiler/normalizer detects.
121
+ * Return value of `defineDynamic`: the runtime shape of a dynamic export,
122
+ * stamped with a sentinel kind the compiler/normalizer detects. `TFallback`
123
+ * is `never` except for dynamic agent models, the only slot with a fallback.
121
124
  */
122
- export interface DynamicSentinel {
125
+ export type DynamicSentinel<TResult = unknown, TFallback = never> = {
123
126
  readonly kind: typeof DYNAMIC_SENTINEL_KIND;
124
- readonly events: DynamicEvents;
125
- }
127
+ readonly events: DynamicEvents<TResult>;
128
+ } & ([TFallback] extends [never] ? object : {
129
+ readonly fallback: TFallback;
130
+ });
131
+ /**
132
+ * Throws when a dynamic sentinel outside the agent `model` slot carries a
133
+ * `fallback` — anywhere else it would be silently dead configuration.
134
+ */
135
+ export declare function rejectDynamicSentinelFallback(sentinel: DynamicSentinel, message: string): void;
126
136
  export declare function isDynamicSentinel(value: unknown): value is DynamicSentinel;
127
137
  /**
128
138
  * Symbol-based brand stamped by `defineTool` on every entry. Invisible
@@ -1 +1 @@
1
- const ALLOWED_DYNAMIC_TOOL_EVENTS=new Set([`session.started`,`turn.started`,`step.started`]),ALLOWED_DYNAMIC_INSTRUCTION_EVENTS=new Set([`session.started`,`turn.started`]),ALLOWED_DYNAMIC_SKILL_EVENTS=new Set([`session.started`,`turn.started`]),DYNAMIC_SENTINEL_KIND=`eve:dynamic`;function isDynamicSentinel(e){return typeof e==`object`&&!!e&&e.kind===`eve:dynamic`}const TOOL_BRAND=Symbol.for(`eve:tool-brand`);function isBrandedToolEntry(e){return typeof e==`object`&&!!e&&e[TOOL_BRAND]===!0}const INSTRUCTIONS_BRAND=Symbol.for(`eve:instructions-brand`);function isBrandedInstructionsEntry(e){return typeof e==`object`&&!!e&&e[INSTRUCTIONS_BRAND]===!0}const SKILL_BRAND=Symbol.for(`eve:skill-brand`);function isBrandedSkillEntry(e){return typeof e==`object`&&!!e&&e[SKILL_BRAND]===!0}export{ALLOWED_DYNAMIC_INSTRUCTION_EVENTS,ALLOWED_DYNAMIC_SKILL_EVENTS,ALLOWED_DYNAMIC_TOOL_EVENTS,DYNAMIC_SENTINEL_KIND,INSTRUCTIONS_BRAND,SKILL_BRAND,TOOL_BRAND,isBrandedInstructionsEntry,isBrandedSkillEntry,isBrandedToolEntry,isDynamicSentinel};
1
+ const ALLOWED_DYNAMIC_TOOL_EVENTS=new Set([`session.started`,`turn.started`,`step.started`]),ALLOWED_DYNAMIC_INSTRUCTION_EVENTS=new Set([`session.started`,`turn.started`]),ALLOWED_DYNAMIC_SKILL_EVENTS=new Set([`session.started`,`turn.started`]),DYNAMIC_SENTINEL_KIND=`eve:dynamic`;function rejectDynamicSentinelFallback(e,t){if(`fallback`in e)throw Error(`${t} "fallback" is only supported on a dynamic agent model (the "model" field in agent.ts). For dynamic tools, skills, and instructions, author a static entry as the default or return null.`)}function isDynamicSentinel(e){return typeof e==`object`&&!!e&&e.kind===`eve:dynamic`}const TOOL_BRAND=Symbol.for(`eve:tool-brand`);function isBrandedToolEntry(e){return typeof e==`object`&&!!e&&e[TOOL_BRAND]===!0}const INSTRUCTIONS_BRAND=Symbol.for(`eve:instructions-brand`);function isBrandedInstructionsEntry(e){return typeof e==`object`&&!!e&&e[INSTRUCTIONS_BRAND]===!0}const SKILL_BRAND=Symbol.for(`eve:skill-brand`);function isBrandedSkillEntry(e){return typeof e==`object`&&!!e&&e[SKILL_BRAND]===!0}export{ALLOWED_DYNAMIC_INSTRUCTION_EVENTS,ALLOWED_DYNAMIC_SKILL_EVENTS,ALLOWED_DYNAMIC_TOOL_EVENTS,DYNAMIC_SENTINEL_KIND,INSTRUCTIONS_BRAND,SKILL_BRAND,TOOL_BRAND,isBrandedInstructionsEntry,isBrandedSkillEntry,isBrandedToolEntry,isDynamicSentinel,rejectDynamicSentinelFallback};
@@ -0,0 +1,36 @@
1
+ type BaseEvent = {
2
+ type: string;
3
+ };
4
+ /**
5
+ * Side-effect-only handler for one accepted runtime stream event.
6
+ *
7
+ * `TEvent` is one variant of the runtime stream-event union.
8
+ * {@link GenericStreamEventHooks} infers `TEvent` from the event key.
9
+ */
10
+ export type GenericStreamEventHook<TEvent extends BaseEvent, TContext> = (event: TEvent, ctx: TContext) => void | Promise<void>;
11
+ /**
12
+ * Map of stream-event subscribers an authored hook file may declare.
13
+ *
14
+ * `*` matches every accepted runtime stream event and runs after the
15
+ * typed handler for that event (if any).
16
+ */
17
+ export type GenericStreamEventHooks<TEvent extends BaseEvent, TContext> = {
18
+ readonly "*"?: GenericStreamEventHook<TEvent, TContext>;
19
+ } & {
20
+ readonly [K in TEvent["type"]]?: GenericStreamEventHook<Extract<TEvent, {
21
+ type: K;
22
+ }>, TContext>;
23
+ };
24
+ /**
25
+ * Public hook definition authored in `agent/hooks/*.ts`.
26
+ *
27
+ * Hook files declare stream-event subscribers (under `events:`) that
28
+ * fire after eve has accepted and durably recorded each event.
29
+ * Handlers are observe-only: they cannot inject model context. To
30
+ * contribute runtime model messages, use `defineDynamic` +
31
+ * `defineInstructions` in `agent/instructions/`.
32
+ */
33
+ export interface GenericHookDefinition<TEvent extends BaseEvent, TContext> {
34
+ readonly events?: GenericStreamEventHooks<TEvent, TContext>;
35
+ }
36
+ export {};
@@ -0,0 +1 @@
1
+ export{};
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Public definition for an instructions prompt authored in markdown or
3
+ * TypeScript.
4
+ *
5
+ * Authored at the agent root as either `instructions.md` or
6
+ * `instructions.{ts,cts,mts,js,cjs,mjs}`, or inside the
7
+ * `agent/instructions/` directory for multi-file setups. Module-backed
8
+ * static instructions execute once at build time. The compiler captures
9
+ * the resulting markdown into the compiled manifest.
10
+ *
11
+ * When used inside a `defineDynamic` handler, the runtime lowers the
12
+ * returned markdown to `{ role: "system", content: markdown }`.
13
+ * Instructions produce system messages only. Use channel `context` for
14
+ * user-role messages.
15
+ */
16
+ export interface PublicInstructionsDefinition {
17
+ markdown: string;
18
+ }
19
+ /**
20
+ * Internal definition for an instructions prompt authored in markdown or
21
+ * TypeScript.
22
+ */
23
+ export interface InternalInstructionsDefinition {
24
+ name: string;
25
+ markdown: string;
26
+ }
@@ -0,0 +1 @@
1
+ export{};
@@ -0,0 +1,34 @@
1
+ /**
2
+ * The `run` form of {@link ScheduleDefinition} invokes this handler when a
3
+ * schedule's cron fires. It receives {@link ScheduleHandlerArgs} (`receive`,
4
+ * `waitUntil`, `appAuth`) and may return synchronously or as a promise.
5
+ */
6
+ export type GenericScheduleRunHandler<TArgs> = (args: TArgs) => Promise<void> | void;
7
+ /** Constraint shape that bounds the authored keys accepted by {@link defineSchedule}. */
8
+ export interface GenericScheduleDefinitionFields<TArgs> {
9
+ readonly cron: string;
10
+ readonly markdown?: string;
11
+ readonly run?: GenericScheduleRunHandler<TArgs>;
12
+ }
13
+ /**
14
+ * Public definition for a schedule authored in TypeScript. Provide a required
15
+ * `cron` expression plus exactly one of `markdown` or `run`:
16
+ *
17
+ * - `markdown`: fire-and-forget agent invocation. The framework runs the agent
18
+ * on the prompt and discards the output (equivalent to the `<name>.md`
19
+ * markdown form).
20
+ * - `run`: full handler ({@link GenericScheduleRunHandler}). Receives
21
+ * `{ receive, waitUntil, appAuth }` and decides what to do.
22
+ *
23
+ * Identity is derived from the file path under `agent/schedules/`; authored
24
+ * definitions do not carry a `name` field.
25
+ */
26
+ export type GenericScheduleDefinition<TArgs> = {
27
+ readonly cron: string;
28
+ readonly markdown: string;
29
+ readonly run?: never;
30
+ } | {
31
+ readonly cron: string;
32
+ readonly markdown?: never;
33
+ readonly run: GenericScheduleRunHandler<TArgs>;
34
+ };
@@ -0,0 +1 @@
1
+ export{};
@@ -1,2 +1,2 @@
1
- import{parseWithNitroRolldownAst}from"#internal/bundler/nitro-rolldown.js";const AGENT_FACTORY=`defineAgent`;async function applyModelNameToSource(e,n){let r=await parseAgentSource(e);if(`kind`in r)return r;if((r.errors?.length??0)>0){let t=r.errors?.[0];return{kind:`bail`,reason:`agent.ts does not parse: ${t?.message??`unknown parse error`}`,line:parseErrorLine(e,t)}}let i=findDefineAgentObject(r.program??r,AGENT_FACTORY);if(i===void 0)return{kind:`bail`,reason:`no \`export default ${AGENT_FACTORY}({ ... })\` call found`,line:1};let a=findStringLiteralProperty(i,`model`);if(a===void 0)return{kind:`bail`,reason:"`model` is absent or is not a string literal (e.g. an env reference, a template, or an inlined SDK model)",line:lineAt(e,i.start??0)};let o=a.value;if(o===n)return{kind:`applied`,from:o,to:n,nextSource:e};let s=a.raw?.[0]===`'`?`'`:`"`,c=`${s}${escapeForQuote(n,s)}${s}`;return{kind:`applied`,from:o,to:n,nextSource:e.slice(0,a.start)+c+e.slice(a.end)}}async function parseAgentSource(t){try{return await parseWithNitroRolldownAst(`agent.ts`,t)}catch(e){let n=e;return{kind:`bail`,reason:`agent.ts does not parse: ${n.message??`unknown parse error`}`,line:parseErrorLine(t,n)}}}function unwrapExpression(e){let t=e;for(;t.type===`ParenthesizedExpression`||t.type===`TSAsExpression`||t.type===`TSSatisfiesExpression`;){if(t.expression===void 0||t.expression===null)return t;t=t.expression}return t}function findDefineAgentObject(e,t){for(let n of e.body??[]){if(n.type!==`ExportDefaultDeclaration`)continue;let e=n.declaration;if(e==null||e.type!==`CallExpression`&&e.type!==`ParenthesizedExpression`&&e.type!==`TSAsExpression`&&e.type!==`TSSatisfiesExpression`)continue;let r=unwrapExpression(e);if(r.type!==`CallExpression`||!isFactoryCallee(r.callee,t))continue;let i=r.arguments?.[0];if(i===void 0||i.type===`SpreadElement`)continue;let a=unwrapExpression(i);if(a.type===`ObjectExpression`)return a}}function isFactoryCallee(e,t){return e?.type===`Identifier`&&e.name===t}function findStringLiteralProperty(e,t){for(let n of e.properties){if(n.type!==`Property`||n.computed||!keyMatches(n.key,t))continue;let e=n.value;if(!isAstNode(e))continue;let r=unwrapExpression(e);return r.type===`Literal`&&typeof r.value==`string`&&r.start!==void 0&&r.end!==void 0?r:void 0}}function keyMatches(e,t){return e===void 0?!1:e.type===`Identifier`?e.name===t:e.type===`Literal`?typeof e.value==`string`&&e.value===t:!1}function isAstNode(e){return typeof e==`object`&&!!e&&typeof e.type==`string`}function parseErrorLine(e,t){return typeof t?.loc?.line==`number`?t.loc.line:lineAt(e,t?.labels?.[0]?.start??t?.start??0)}function escapeForQuote(e,t){return e.replaceAll(`\\`,`\\\\`).replaceAll(t,`\\${t}`)}function lineAt(e,t){let n=1;for(let r=0;r<t&&r<e.length;r+=1)e[r]===`
1
+ import{parseWithNitroRolldownAst}from"#internal/bundler/nitro-rolldown.js";const AGENT_FACTORY=`defineAgent`;async function applyModelNameToSource(e,n){let r=await parseAgentSource(e);if(`kind`in r)return r;if((r.errors?.length??0)>0){let t=r.errors?.[0];return{kind:`bail`,reason:`agent.ts does not parse: ${t?.message??`unknown parse error`}`,line:parseErrorLine(e,t)}}let i=findDefineAgentObject(r.program??r,AGENT_FACTORY);if(i===void 0)return{kind:`bail`,reason:`no \`export default ${AGENT_FACTORY}({ ... })\` call found`,line:1};let a=findStringLiteralProperty(i,`model`);if(a===void 0)return{kind:`bail`,reason:"`model` is absent or is not a string literal (e.g. an env reference, a template, an inlined SDK model, or a defineDynamic() dynamic model)",line:lineAt(e,i.start??0)};let o=a.value;if(o===n)return{kind:`applied`,from:o,to:n,nextSource:e};let s=a.raw?.[0]===`'`?`'`:`"`,c=`${s}${escapeForQuote(n,s)}${s}`;return{kind:`applied`,from:o,to:n,nextSource:e.slice(0,a.start)+c+e.slice(a.end)}}async function parseAgentSource(t){try{return await parseWithNitroRolldownAst(`agent.ts`,t)}catch(e){let n=e;return{kind:`bail`,reason:`agent.ts does not parse: ${n.message??`unknown parse error`}`,line:parseErrorLine(t,n)}}}function unwrapExpression(e){let t=e;for(;t.type===`ParenthesizedExpression`||t.type===`TSAsExpression`||t.type===`TSSatisfiesExpression`;){if(t.expression===void 0||t.expression===null)return t;t=t.expression}return t}function findDefineAgentObject(e,t){for(let n of e.body??[]){if(n.type!==`ExportDefaultDeclaration`)continue;let e=n.declaration;if(e==null||e.type!==`CallExpression`&&e.type!==`ParenthesizedExpression`&&e.type!==`TSAsExpression`&&e.type!==`TSSatisfiesExpression`)continue;let r=unwrapExpression(e);if(r.type!==`CallExpression`||!isFactoryCallee(r.callee,t))continue;let i=r.arguments?.[0];if(i===void 0||i.type===`SpreadElement`)continue;let a=unwrapExpression(i);if(a.type===`ObjectExpression`)return a}}function isFactoryCallee(e,t){return e?.type===`Identifier`&&e.name===t}function findStringLiteralProperty(e,t){for(let n of e.properties){if(n.type!==`Property`||n.computed||!keyMatches(n.key,t))continue;let e=n.value;if(!isAstNode(e))continue;let r=unwrapExpression(e);return r.type===`Literal`&&typeof r.value==`string`&&r.start!==void 0&&r.end!==void 0?r:void 0}}function keyMatches(e,t){return e===void 0?!1:e.type===`Identifier`?e.name===t:e.type===`Literal`?typeof e.value==`string`&&e.value===t:!1}function isAstNode(e){return typeof e==`object`&&!!e&&typeof e.type==`string`}function parseErrorLine(e,t){return typeof t?.loc?.line==`number`?t.loc.line:lineAt(e,t?.labels?.[0]?.start??t?.start??0)}function escapeForQuote(e,t){return e.replaceAll(`\\`,`\\\\`).replaceAll(t,`\\${t}`)}function lineAt(e,t){let n=1;for(let r=0;r<t&&r<e.length;r+=1)e[r]===`
2
2
  `&&(n+=1);return n}export{applyModelNameToSource};
@@ -43,6 +43,50 @@ version uses hyphens (`claude-opus-4-8`), while the Gateway id above uses a dot
43
43
 
44
44
  Model use is subject to the terms, data-processing commitments, retention behavior, and available controls of the selected provider and routing path. Review the [AI Gateway model catalog](https://vercel.com/ai-gateway/models) for gateway-routed models, and review the provider's terms when you configure a direct `LanguageModel`.
45
45
 
46
+ ### Choose the model dynamically
47
+
48
+ `model` also accepts `defineDynamic({ fallback, events })`. `fallback` is the
49
+ compiled static model: it anchors build-time metadata (routing, credentials,
50
+ context window) and serves whenever no dynamic selection is set.
51
+
52
+ ```ts title="agent/agent.ts"
53
+ import { defineAgent, defineDynamic } from "eve";
54
+
55
+ export default defineAgent({
56
+ model: defineDynamic({
57
+ fallback: "anthropic/claude-sonnet-5",
58
+ events: {
59
+ "session.started": (_event, ctx) =>
60
+ ctx.session.auth.initiator?.attributes.plan === "enterprise"
61
+ ? "anthropic/claude-opus-4.8"
62
+ : null,
63
+ },
64
+ }),
65
+ });
66
+ ```
67
+
68
+ Handlers receive the shared [dynamic resolver
69
+ context](./guides/dynamic-capabilities) (`ctx.session`, `ctx.channel`,
70
+ `ctx.messages`) and return a gateway model id, an AI SDK `LanguageModel`, a
71
+ selection object, or `null` to leave the scope unset.
72
+
73
+ - **Scopes.** `session.started` (once per session), `turn.started` (once per
74
+ turn), `step.started` (every model step). Precedence: step > turn >
75
+ session > `fallback`. Prefer `session.started`: prompt caches are per
76
+ model, so every switch re-ingests the conversation at uncached prices.
77
+ - **Failures degrade, never fail the turn.** A resolver that throws or
78
+ returns an invalid selection logs an error and leaves its scope unset.
79
+ Build-time validation covers only `fallback`; a selected model without
80
+ credentials fails at request time.
81
+ - **Serialization.** Session/turn selections must be model id strings; return
82
+ live `LanguageModel` objects only from `step.started`.
83
+ - **Selection object.** `{ model, modelContextWindowTokens?, modelOptions? }`.
84
+ Set `modelContextWindowTokens` when the selected model's window differs
85
+ from the fallback's — it is never inherited. Omitted `modelOptions` reuses
86
+ the agent-level `modelOptions`.
87
+
88
+ Runtime identity reports a dynamic agent's model as `dynamic:<fallback id>`.
89
+
46
90
  ## Reasoning effort
47
91
 
48
92
  Set `reasoning` to control the model's reasoning effort through AI SDK's
@@ -1,9 +1,25 @@
1
1
  ---
2
2
  title: "Dynamic Capabilities"
3
- description: "Resolve tools, skills, and instructions at runtime with defineDynamic: the resolver events, execution order, and how dynamic tools survive step boundaries."
3
+ description: "Resolve models, tools, skills, and instructions at runtime: dynamic model selection, defineDynamic resolver events, execution order, and durable dynamic tools."
4
4
  ---
5
5
 
6
- `defineDynamic` resolves tools, skills, and instructions at runtime from a session event instead of declaring them up front. Reach for it when the right capabilities aren't known until the session starts, because they hinge on who the caller is, what tenant they belong to, feature flags, or external data. The [tools](../tools), [skills](../skills), and [instructions](../instructions) guides each point here for their dynamic form.
6
+ `defineDynamic` resolves the model, tools, skills, and instructions at runtime from a session event instead of declaring them up front. Reach for it when the right capability isn't known until the session starts, because it hinges on who the caller is, what tenant they belong to, feature flags, or external data. The [tools](../tools), [skills](../skills), and [instructions](../instructions) guides each point here for their dynamic form.
7
+
8
+ ## Dynamic models
9
+
10
+ The `model` field in `agent.ts` accepts `defineDynamic({ fallback, events })`.
11
+ Resolvers run at `session.started`, `turn.started`, or `step.started`
12
+ (precedence: step > turn > session > `fallback`); `null` leaves a scope unset
13
+ and failures degrade to the next scope. Prefer `session.started` — prompt
14
+ caches are per model, so switching mid-session re-ingests the conversation at
15
+ uncached prices. See
16
+ [agent configuration](../agent-config#choose-the-model-dynamically) for the
17
+ full contract.
18
+
19
+ `fallback` is model-only: the agent always needs exactly one model, and the
20
+ compiled fallback anchors build-time metadata. Tools, skills, and instructions
21
+ default by authoring a static entry (or returning `null`), so `fallback` on
22
+ their `defineDynamic` export is a build error.
7
23
 
8
24
  ## Dynamic tools
9
25
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eve",
3
- "version": "0.21.0",
3
+ "version": "0.22.0",
4
4
  "private": false,
5
5
  "description": "Filesystem-first framework for durable backend AI agents that run anywhere.",
6
6
  "keywords": [
@@ -1,157 +0,0 @@
1
- import type { FetchFileResult } from "#channel/adapter.js";
2
- import { CHANNEL_SENTINEL } from "#channel/compiled-channel.js";
3
- import { type ChannelCors, type ChannelCorsOptions } from "#channel/cors.js";
4
- import type { TypedReceiveTarget } from "#channel/receive-target.js";
5
- import type { SessionAuthContext } from "#channel/types.js";
6
- import type { HandleMessageStreamEvent } from "#protocol/message.js";
7
- import type { SessionContext } from "#public/definitions/callback-context.js";
8
- import type { RouteDefinition, SendFn } from "#channel/routes.js";
9
- import type { Session, SessionHandle } from "#channel/session.js";
10
- declare const CHANNEL_METADATA_TYPE: unique symbol;
11
- export type { Session, SessionHandle } from "#channel/session.js";
12
- export type { ChannelCors, ChannelCorsOptions } from "#channel/cors.js";
13
- export { GET, POST, PUT, PATCH, DELETE, WS } from "#channel/routes.js";
14
- export type { HttpRouteDefinition, RouteDefinition, RouteHandlerArgs, SendFn, SendOptions, SendPayload, GetSessionFn, WebSocketMessage, WebSocketPeer, WebSocketRouteDefinition, WebSocketRouteHandler, WebSocketRouteHooks, WebSocketUpgradeRequest, WebSocketUpgradeResult, } from "#channel/routes.js";
15
- type EventData<T extends HandleMessageStreamEvent["type"]> = Extract<HandleMessageStreamEvent, {
16
- type: T;
17
- }> extends {
18
- data: infer D;
19
- } ? D : undefined;
20
- /**
21
- * Session operations on the `channel` argument of every channel event handler.
22
- */
23
- export interface ChannelSessionOps {
24
- readonly continuationToken: string;
25
- setContinuationToken(token: string): void;
26
- }
27
- /**
28
- * Channel context passed to event handlers: `TCtx` intersected with
29
- * {@link ChannelSessionOps}.
30
- */
31
- export type ChannelContext<TCtx> = TCtx & ChannelSessionOps;
32
- type ChannelEventHandler<T extends HandleMessageStreamEvent["type"], TCtx> = (data: EventData<T>, channel: ChannelContext<TCtx>, ctx: SessionContext) => void | Promise<void>;
33
- type ChannelSessionFailedHandler<TCtx> = (data: EventData<"session.failed">, channel: ChannelContext<TCtx>) => void | Promise<void>;
34
- /**
35
- * Optional handlers keyed by session lifecycle event name. Each handler receives
36
- * the event `data`, the {@link ChannelContext}, and a {@link SessionContext}
37
- * `ctx`. The `session.failed` handler is the exception: it receives only `data`
38
- * and the channel context, with no `ctx`.
39
- */
40
- export interface ChannelEvents<TCtx = void> {
41
- readonly "turn.started"?: ChannelEventHandler<"turn.started", TCtx>;
42
- readonly "actions.requested"?: ChannelEventHandler<"actions.requested", TCtx>;
43
- readonly "action.result"?: ChannelEventHandler<"action.result", TCtx>;
44
- readonly "message.completed"?: ChannelEventHandler<"message.completed", TCtx>;
45
- readonly "message.appended"?: ChannelEventHandler<"message.appended", TCtx>;
46
- readonly "reasoning.appended"?: ChannelEventHandler<"reasoning.appended", TCtx>;
47
- readonly "reasoning.completed"?: ChannelEventHandler<"reasoning.completed", TCtx>;
48
- readonly "input.requested"?: ChannelEventHandler<"input.requested", TCtx>;
49
- readonly "turn.failed"?: ChannelEventHandler<"turn.failed", TCtx>;
50
- readonly "turn.completed"?: ChannelEventHandler<"turn.completed", TCtx>;
51
- readonly "session.failed"?: ChannelSessionFailedHandler<TCtx>;
52
- readonly "session.completed"?: ChannelEventHandler<"session.completed", TCtx>;
53
- readonly "session.waiting"?: ChannelEventHandler<"session.waiting", TCtx>;
54
- readonly "authorization.required"?: ChannelEventHandler<"authorization.required", TCtx>;
55
- readonly "authorization.completed"?: ChannelEventHandler<"authorization.completed", TCtx>;
56
- }
57
- /**
58
- * Input passed to a channel's `receive` callback when another channel or
59
- * schedule proactively routes a message to it.
60
- */
61
- export interface ReceiveInput<TReceiveTarget = Record<string, unknown>> {
62
- readonly message: string;
63
- readonly target: Readonly<TReceiveTarget>;
64
- readonly auth: SessionAuthContext | null;
65
- }
66
- /**
67
- * The object passed to {@link defineChannel}. `routes` is required; `state`
68
- * seeds durable adapter state, `context` builds the per-step `channel` argument
69
- * for `events` and `deliver`, `events` handle session lifecycle, `receive`
70
- * accepts cross-channel handoffs, `fetchFile` stages remote file URLs, and
71
- * `metadata` projects observability data.
72
- *
73
- * Generics: `TState` (adapter state), `TCtx` (context factory return type),
74
- * `TReceiveTarget` (cross-channel target shape), `TMetadata` (instrumentation
75
- * projection).
76
- */
77
- export interface ChannelDefinition<TState = undefined, TCtx = void, TReceiveTarget = Record<string, unknown>, TMetadata extends Record<string, unknown> = Record<string, unknown>> {
78
- readonly state?: TState;
79
- /**
80
- * CORS policy for this channel's HTTP routes. `true` enables H3/Nitro's
81
- * permissive defaults (`origin`, methods, request headers, and exposed
82
- * headers all `"*"`); `false` or omission leaves CORS untouched. Pass an
83
- * object for a serializable subset of H3/Nitro CORS options.
84
- */
85
- readonly cors?: ChannelCors;
86
- /**
87
- * Builds the per-step channel context handed to `events` and `deliver`.
88
- * Receives the live {@link SessionHandle}, so a factory can close over it to
89
- * register late-bound callbacks. eve writes state mutations made inside the
90
- * returned context back through `adapter.state`.
91
- *
92
- * Return the channel-owned context (thread handles, API clients, etc.). The
93
- * framework passes it as the `channel` argument to event handlers (with
94
- * {@link ChannelSessionOps} injected) and passes {@link SessionContext} as a
95
- * separate `ctx` argument.
96
- */
97
- context?(state: NonNullable<TState>, session: SessionHandle): TCtx;
98
- readonly routes: readonly RouteDefinition<TState>[];
99
- receive?(input: ReceiveInput<TReceiveTarget>, args: {
100
- send: SendFn<TState>;
101
- }): Promise<Session>;
102
- readonly events?: ChannelEvents<TCtx>;
103
- /**
104
- * Fetches bytes for a `URL` object encountered on a `FilePart.data` by the
105
- * staging pipeline. Return `null` to pass the URL through to the model
106
- * provider unchanged, or bytes / {@link FetchFileResult} to stage the file to
107
- * the sandbox.
108
- */
109
- readonly fetchFile?: (url: string) => Promise<Buffer | FetchFileResult | null>;
110
- /**
111
- * Channel-owned metadata exposed to instrumentation callbacks. This is the
112
- * channel's public observability surface, not a dump of durable adapter state,
113
- * so keep it small. Return an object of JSON primitives, arrays, and plain
114
- * objects: eve omits `undefined` properties and drops projections containing
115
- * values such as `Date` or `Map`.
116
- */
117
- readonly metadata?: (state: NonNullable<TState>) => TMetadata;
118
- /**
119
- * Identifier of the adapter family this channel belongs to. Set by
120
- * higher-level wrappers (e.g. `slackChannel` passes `"slack"`) so downstream
121
- * consumers can render typed channel chips instead of bucketing everything
122
- * under "unknown".
123
- *
124
- * Authors calling `defineChannel` directly do not need to set this; the
125
- * framework defaults to `"http"` for stateless channels and `"defineChannel"`
126
- * for stateful ones.
127
- */
128
- readonly kindHint?: string;
129
- }
130
- /**
131
- * Opaque channel value produced by {@link defineChannel} and exported from
132
- * `agent/channels/<name>.ts`. Exposes the channel's routes, an optional
133
- * `receive` hook, and (via a phantom property) its metadata shape. Unlike
134
- * {@link ChannelDefinition} it has no `TCtx` parameter: the context type is
135
- * internal to the definition.
136
- */
137
- export interface Channel<TState = undefined, TReceiveTarget = Record<string, unknown>, TMetadata extends Record<string, unknown> = Record<string, unknown>> extends TypedReceiveTarget<TReceiveTarget> {
138
- readonly __kind: typeof CHANNEL_SENTINEL;
139
- readonly [CHANNEL_METADATA_TYPE]?: TMetadata;
140
- readonly routes: readonly RouteDefinition<TState>[];
141
- readonly cors?: ChannelCorsOptions;
142
- readonly receive?: (input: ReceiveInput<TReceiveTarget>, args: {
143
- send: SendFn<TState>;
144
- }) => Promise<Session>;
145
- }
146
- /**
147
- * Extracts the metadata projection type (`TMetadata`) from a {@link Channel}.
148
- * Resolves to `Record<string, unknown>` when the value is not a Channel.
149
- */
150
- export type InferChannelMetadata<TChannel> = TChannel extends Channel<any, any, infer TMetadata> ? TMetadata : Record<string, unknown>;
151
- /**
152
- * Builds a {@link Channel} from a {@link ChannelDefinition}. Returns a value
153
- * placed at `agent/channels/<name>.ts`; the file path supplies the channel name
154
- * (do not add a `name` field). `TCtx` (the context factory's return type) is
155
- * internal to the definition and is not part of the returned Channel signature.
156
- */
157
- export declare function defineChannel<TState = undefined, TCtx = void, TReceiveTarget = Record<string, unknown>, TMetadata extends Record<string, unknown> = Record<string, unknown>>(definition: ChannelDefinition<TState, TCtx, TReceiveTarget, TMetadata>): Channel<TState, TReceiveTarget, TMetadata>;
@@ -1 +0,0 @@
1
- import{CHANNEL_SENTINEL}from"#channel/compiled-channel.js";import{defaultDeliverResult}from"#channel/adapter.js";import{buildCallbackContext}from"#context/build-callback-context.js";import{normalizeChannelCors}from"#channel/cors.js";import{HTTP_ADAPTER_KIND}from"#channel/http.js";import{DELETE,GET,PATCH,POST,PUT,WS}from"#channel/routes.js";function defineChannel(t){let n=buildAdapter(t),i=normalizeChannelCors(t.cors);return{__kind:CHANNEL_SENTINEL,routes:t.routes,adapter:n,cors:i,receive:t.receive}}function buildAdapter(e){let r=e.state!=null,a=e.context!=null,o=e.fetchFile!==void 0,s=e.metadata,c=r||a||s!==void 0,l={},u=!1,d=[`turn.started`,`actions.requested`,`action.result`,`message.completed`,`message.appended`,`reasoning.appended`,`reasoning.completed`,`input.requested`,`turn.failed`,`turn.completed`,`session.failed`,`session.completed`,`session.waiting`,`authorization.required`,`authorization.completed`],f=e.events;for(let e of d){let t=f?.[e];t&&(u=!0,l[e]=(r,i)=>{let a={...i,continuationToken:i.session?.continuationToken??``,setContinuationToken:e=>i.session?.setContinuationToken(e)};return e===`session.failed`?t(r,a):t(r,a,buildCallbackContext())})}return!c&&!u&&!o?{kind:e.kindHint??HTTP_ADAPTER_KIND}:{kind:e.kindHint??`defineChannel`,state:r?{...e.state}:{},fetchFile:e.fetchFile,instrumentation:s===void 0?void 0:{metadata(e){return s(e)}},createAdapterContext(t){let n=t.state,r=t.session;return{...a?e.context(n,r):{},state:n,ctx:t.ctx,session:r}},deliver(e){return defaultDeliverResult(e)},...l}}export{DELETE,GET,PATCH,POST,PUT,WS,defineChannel};