The Open Framework for Building Agents
refactor(eve): infer authored channel metadata from values (#740)
Casey Gowrie9a594c211119
diff --git a/.changeset/strong-channel-values.md b/.changeset/strong-channel-values.mdnew file mode 100644index 000000000..01e6a2ded--- /dev/null+++ b/.changeset/strong-channel-values.md@@ -0,0 +1,7 @@+---+"eve": minor+---++Infer authored channel metadata directly from the channel definition passed to `isChannel`, without compiler-generated declarations. Use `isChannel(...)` whenever you need authored metadata type narrowing; direct `channel:<name>` comparisons continue to identify channels but no longer narrow authored metadata.++The `.eve/**/*.d.ts` TypeScript include is no longer needed. Existing apps may remove it, but leaving the unmatched glob in place does not change typechecking.diff --git a/apps/fixtures/agent-tui-client/tsconfig.json b/apps/fixtures/agent-tui-client/tsconfig.jsonindex 8e342f89c..85e3eceb8 100644--- a/apps/fixtures/agent-tui-client/tsconfig.json+++ b/apps/fixtures/agent-tui-client/tsconfig.json@@ -13,5 +13,5 @@"noEmit": true,"types": ["node"]},- "include": ["agent/**/*.ts", "evals/**/*.ts", ".eve/**/*.d.ts"]+ "include": ["agent/**/*.ts", "evals/**/*.ts"]}diff --git a/apps/fixtures/weather-agent/tsconfig.json b/apps/fixtures/weather-agent/tsconfig.jsonindex 9e204d4a9..e7581a7e8 100644--- a/apps/fixtures/weather-agent/tsconfig.json+++ b/apps/fixtures/weather-agent/tsconfig.json@@ -22,6 +22,6 @@"allowJs": true,"rootDir": "."},- "include": ["agent/**/*", "evals/**/*", ".eve/**/*.d.ts"],+ "include": ["agent/**/*", "evals/**/*"],"exclude": ["node_modules", "dist", "build", ".turbo", ".vercel"]}diff --git a/apps/frameworks/next/tsconfig.json b/apps/frameworks/next/tsconfig.jsonindex 19b826879..3a13f90a7 100644--- a/apps/frameworks/next/tsconfig.json+++ b/apps/frameworks/next/tsconfig.json@@ -26,7 +26,6 @@"next-env.d.ts","**/*.ts","**/*.tsx",- ".eve/**/*.d.ts",".next/types/**/*.ts",".next/dev/types/**/*.ts","**/*.mts"diff --git a/apps/templates/web-chat-next/tsconfig.json b/apps/templates/web-chat-next/tsconfig.jsonindex f22cd39fb..62f193217 100644--- a/apps/templates/web-chat-next/tsconfig.json+++ b/apps/templates/web-chat-next/tsconfig.json@@ -27,7 +27,6 @@"next-env.d.ts","**/*.ts","**/*.tsx",- ".eve/**/*.d.ts",".next/types/**/*.ts",".next/dev/types/**/*.ts"],diff --git a/docs/guides/instrumentation.md b/docs/guides/instrumentation.mdindex e16fd9c35..b036cb36a 100644--- a/docs/guides/instrumentation.md+++ b/docs/guides/instrumentation.md@@ -94,7 +94,7 @@ The callback receives:- `channel`: the channel's `kind` and the metadata projected by the active channel- `modelInput`: the final instructions and messages passed to the model call-A channel exposes its identity through `kind`, the discriminant you narrow on. For authored channels it is `channel:<name>`, where `<name>` is the channel's filename under `agent/channels/`, so `agent/channels/support.ts` is `channel:support`. Framework channels use `http`, `schedule`, or `subagent`, and an unrecognized or absent kind normalizes to `unknown`. The kind is also emitted as the `eve.channel.kind` span attribute. eve emits compiler-owned typings keyed by the channel filename, so you can narrow either by checking `input.channel.kind === "channel:support"` or by using `isChannel(input.channel, supportChannel)`.+A channel exposes its identity through `kind`. For authored channels it is `channel:<name>`, where `<name>` is the channel's filename under `agent/channels/`, so `agent/channels/support.ts` is `channel:support`. Framework channels use `http`, `schedule`, or `subagent`, and an unrecognized or absent kind normalizes to `unknown`. The kind is also emitted as the `eve.channel.kind` span attribute. To access an authored channel's metadata with its precise type, import the channel definition and narrow with `isChannel(input.channel, supportChannel)`.Channel metadata is channel-owned. Built-in channels expose only the fields they choose to make observable; Slack, for example, projects `channelId`, `teamId`, `threadTs`, and `triggeringUserId` from its durable channel state. User-authored channels expose their own projection by returning `metadata(state)` from `defineChannel`. Runtime instrumentation never falls back to raw channel state.diff --git a/e2e/fixtures/agent-basic-runtime/tsconfig.json b/e2e/fixtures/agent-basic-runtime/tsconfig.jsonindex 8e342f89c..85e3eceb8 100644--- a/e2e/fixtures/agent-basic-runtime/tsconfig.json+++ b/e2e/fixtures/agent-basic-runtime/tsconfig.json@@ -13,5 +13,5 @@"noEmit": true,"types": ["node"]},- "include": ["agent/**/*.ts", "evals/**/*.ts", ".eve/**/*.d.ts"]+ "include": ["agent/**/*.ts", "evals/**/*.ts"]}diff --git a/e2e/fixtures/agent-channels/tsconfig.json b/e2e/fixtures/agent-channels/tsconfig.jsonindex 8e342f89c..85e3eceb8 100644--- a/e2e/fixtures/agent-channels/tsconfig.json+++ b/e2e/fixtures/agent-channels/tsconfig.json@@ -13,5 +13,5 @@"noEmit": true,"types": ["node"]},- "include": ["agent/**/*.ts", "evals/**/*.ts", ".eve/**/*.d.ts"]+ "include": ["agent/**/*.ts", "evals/**/*.ts"]}diff --git a/e2e/fixtures/agent-model/tsconfig.json b/e2e/fixtures/agent-model/tsconfig.jsonindex 8e342f89c..85e3eceb8 100644--- a/e2e/fixtures/agent-model/tsconfig.json+++ b/e2e/fixtures/agent-model/tsconfig.json@@ -13,5 +13,5 @@"noEmit": true,"types": ["node"]},- "include": ["agent/**/*.ts", "evals/**/*.ts", ".eve/**/*.d.ts"]+ "include": ["agent/**/*.ts", "evals/**/*.ts"]}diff --git a/e2e/fixtures/agent-openapi-swagger/tsconfig.json b/e2e/fixtures/agent-openapi-swagger/tsconfig.jsonindex 8e342f89c..85e3eceb8 100644--- a/e2e/fixtures/agent-openapi-swagger/tsconfig.json+++ b/e2e/fixtures/agent-openapi-swagger/tsconfig.json@@ -13,5 +13,5 @@"noEmit": true,"types": ["node"]},- "include": ["agent/**/*.ts", "evals/**/*.ts", ".eve/**/*.d.ts"]+ "include": ["agent/**/*.ts", "evals/**/*.ts"]}diff --git a/e2e/fixtures/agent-prompt-cache/tsconfig.json b/e2e/fixtures/agent-prompt-cache/tsconfig.jsonindex 66f5b1ea5..33033274f 100644--- a/e2e/fixtures/agent-prompt-cache/tsconfig.json+++ b/e2e/fixtures/agent-prompt-cache/tsconfig.json@@ -13,5 +13,5 @@"noEmit": true,"types": ["node"]},- "include": ["agent/**/*.ts", "evals/**/*.ts", ".eve/**/*.d.ts"]+ "include": ["agent/**/*.ts", "evals/**/*.ts"]}diff --git a/e2e/fixtures/agent-schedules/tsconfig.json b/e2e/fixtures/agent-schedules/tsconfig.jsonindex 8e342f89c..85e3eceb8 100644--- a/e2e/fixtures/agent-schedules/tsconfig.json+++ b/e2e/fixtures/agent-schedules/tsconfig.json@@ -13,5 +13,5 @@"noEmit": true,"types": ["node"]},- "include": ["agent/**/*.ts", "evals/**/*.ts", ".eve/**/*.d.ts"]+ "include": ["agent/**/*.ts", "evals/**/*.ts"]}diff --git a/e2e/fixtures/agent-session-limits/tsconfig.json b/e2e/fixtures/agent-session-limits/tsconfig.jsonindex 8e342f89c..85e3eceb8 100644--- a/e2e/fixtures/agent-session-limits/tsconfig.json+++ b/e2e/fixtures/agent-session-limits/tsconfig.json@@ -13,5 +13,5 @@"noEmit": true,"types": ["node"]},- "include": ["agent/**/*.ts", "evals/**/*.ts", ".eve/**/*.d.ts"]+ "include": ["agent/**/*.ts", "evals/**/*.ts"]}diff --git a/e2e/fixtures/agent-skills/tsconfig.json b/e2e/fixtures/agent-skills/tsconfig.jsonindex 8e342f89c..85e3eceb8 100644--- a/e2e/fixtures/agent-skills/tsconfig.json+++ b/e2e/fixtures/agent-skills/tsconfig.json@@ -13,5 +13,5 @@"noEmit": true,"types": ["node"]},- "include": ["agent/**/*.ts", "evals/**/*.ts", ".eve/**/*.d.ts"]+ "include": ["agent/**/*.ts", "evals/**/*.ts"]}diff --git a/e2e/fixtures/agent-subagents-hitl/tsconfig.json b/e2e/fixtures/agent-subagents-hitl/tsconfig.jsonindex 8e342f89c..85e3eceb8 100644--- a/e2e/fixtures/agent-subagents-hitl/tsconfig.json+++ b/e2e/fixtures/agent-subagents-hitl/tsconfig.json@@ -13,5 +13,5 @@"noEmit": true,"types": ["node"]},- "include": ["agent/**/*.ts", "evals/**/*.ts", ".eve/**/*.d.ts"]+ "include": ["agent/**/*.ts", "evals/**/*.ts"]}diff --git a/e2e/fixtures/agent-subagents/tsconfig.json b/e2e/fixtures/agent-subagents/tsconfig.jsonindex 8e342f89c..85e3eceb8 100644--- a/e2e/fixtures/agent-subagents/tsconfig.json+++ b/e2e/fixtures/agent-subagents/tsconfig.json@@ -13,5 +13,5 @@"noEmit": true,"types": ["node"]},- "include": ["agent/**/*.ts", "evals/**/*.ts", ".eve/**/*.d.ts"]+ "include": ["agent/**/*.ts", "evals/**/*.ts"]}diff --git a/e2e/fixtures/agent-tools-hitl-openai/tsconfig.json b/e2e/fixtures/agent-tools-hitl-openai/tsconfig.jsonindex 66f5b1ea5..33033274f 100644--- a/e2e/fixtures/agent-tools-hitl-openai/tsconfig.json+++ b/e2e/fixtures/agent-tools-hitl-openai/tsconfig.json@@ -13,5 +13,5 @@"noEmit": true,"types": ["node"]},- "include": ["agent/**/*.ts", "evals/**/*.ts", ".eve/**/*.d.ts"]+ "include": ["agent/**/*.ts", "evals/**/*.ts"]}diff --git a/e2e/fixtures/agent-tools-hitl/tsconfig.json b/e2e/fixtures/agent-tools-hitl/tsconfig.jsonindex 8e342f89c..85e3eceb8 100644--- a/e2e/fixtures/agent-tools-hitl/tsconfig.json+++ b/e2e/fixtures/agent-tools-hitl/tsconfig.json@@ -13,5 +13,5 @@"noEmit": true,"types": ["node"]},- "include": ["agent/**/*.ts", "evals/**/*.ts", ".eve/**/*.d.ts"]+ "include": ["agent/**/*.ts", "evals/**/*.ts"]}diff --git a/e2e/fixtures/agent-tools-sandbox/tsconfig.json b/e2e/fixtures/agent-tools-sandbox/tsconfig.jsonindex 8e342f89c..85e3eceb8 100644--- a/e2e/fixtures/agent-tools-sandbox/tsconfig.json+++ b/e2e/fixtures/agent-tools-sandbox/tsconfig.json@@ -13,5 +13,5 @@"noEmit": true,"types": ["node"]},- "include": ["agent/**/*.ts", "evals/**/*.ts", ".eve/**/*.d.ts"]+ "include": ["agent/**/*.ts", "evals/**/*.ts"]}diff --git a/e2e/fixtures/agent-tools/tsconfig.json b/e2e/fixtures/agent-tools/tsconfig.jsonindex 8e342f89c..85e3eceb8 100644--- a/e2e/fixtures/agent-tools/tsconfig.json+++ b/e2e/fixtures/agent-tools/tsconfig.json@@ -13,5 +13,5 @@"noEmit": true,"types": ["node"]},- "include": ["agent/**/*.ts", "evals/**/*.ts", ".eve/**/*.d.ts"]+ "include": ["agent/**/*.ts", "evals/**/*.ts"]}diff --git a/e2e/fixtures/agent-workflow-stress/tsconfig.json b/e2e/fixtures/agent-workflow-stress/tsconfig.jsonindex 8e342f89c..85e3eceb8 100644--- a/e2e/fixtures/agent-workflow-stress/tsconfig.json+++ b/e2e/fixtures/agent-workflow-stress/tsconfig.json@@ -13,5 +13,5 @@"noEmit": true,"types": ["node"]},- "include": ["agent/**/*.ts", "evals/**/*.ts", ".eve/**/*.d.ts"]+ "include": ["agent/**/*.ts", "evals/**/*.ts"]}diff --git a/e2e/fixtures/extensions/tsconfig.json b/e2e/fixtures/extensions/tsconfig.jsonindex 8e342f89c..85e3eceb8 100644--- a/e2e/fixtures/extensions/tsconfig.json+++ b/e2e/fixtures/extensions/tsconfig.json@@ -13,5 +13,5 @@"noEmit": true,"types": ["node"]},- "include": ["agent/**/*.ts", "evals/**/*.ts", ".eve/**/*.d.ts"]+ "include": ["agent/**/*.ts", "evals/**/*.ts"]}diff --git a/packages/eve/src/cli/commands/info.test.ts b/packages/eve/src/cli/commands/info.test.tsindex eee966183..e82203672 100644--- a/packages/eve/src/cli/commands/info.test.ts+++ b/packages/eve/src/cli/commands/info.test.ts@@ -80,7 +80,6 @@ function makeCompiledState(): CompileAgentResult {},paths: {appRoot: APP_ROOT,- channelInstrumentationTypesPath: `${APP_ROOT}/.eve/compile/channel-instrumentation.d.ts`,compiledManifestPath: `${APP_ROOT}/.eve/compile/compiled-agent-manifest.json`,compileDirectoryPath: `${APP_ROOT}/.eve/compile`,compileMetadataPath: `${APP_ROOT}/.eve/compile/compile-metadata.json`,diff --git a/packages/eve/src/compiler/artifacts.ts b/packages/eve/src/compiler/artifacts.tsindex 627fcfdaf..a08252948 100644--- a/packages/eve/src/compiler/artifacts.ts+++ b/packages/eve/src/compiler/artifacts.ts@@ -7,10 +7,6 @@ import { summarizeDiscoverDiagnostics } from "#discover/diagnostics.js";import { normalizeLogicalPath } from "#discover/filesystem.js";import type { AgentSourceManifest } from "#discover/manifest.js";import { resolveInstalledPackageInfo } from "#internal/application/package.js";-import {- CHANNEL_INSTRUMENTATION_TYPES_FILE_NAME,- createChannelInstrumentationTypesSource,-} from "#compiler/channel-instrumentation-types.js";import type { CompiledAgentManifest } from "#compiler/manifest.js";import { createCompiledModuleMapSource } from "#compiler/module-map.js";import { compileAgentManifest } from "#compiler/normalize-manifest.js";@@ -41,7 +37,6 @@ export const COMPILE_METADATA_VERSION = 5;*/export interface CompilerArtifactPaths {appRoot: string;- channelInstrumentationTypesPath: string;compiledManifestPath: string;compileDirectoryPath: string;compileMetadataPath: string;@@ -121,10 +116,6 @@ export function resolveCompilerArtifactPaths(appRoot: string): CompilerArtifactPreturn {appRoot: resolvedAppRoot,- channelInstrumentationTypesPath: join(- compileDirectoryPath,- CHANNEL_INSTRUMENTATION_TYPES_FILE_NAME,- ),compiledManifestPath: join(compileDirectoryPath, "compiled-agent-manifest.json"),compileDirectoryPath,compileMetadataPath: join(compileDirectoryPath, "compile-metadata.json"),@@ -214,10 +205,6 @@ export async function writeCompilerArtifacts(manifest: compiledManifest,moduleMapPath: paths.moduleMapPath,});- const channelInstrumentationTypesSource = createChannelInstrumentationTypesSource({- manifest: compiledManifest,- typesPath: paths.channelInstrumentationTypesPath,- });const metadata = createCompileMetadata({appRoot: input.appRoot,diagnosticsArtifactJson,@@ -238,7 +225,6 @@ export async function writeCompilerArtifacts(writeFile(paths.compiledManifestPath, compiledManifestJson),writeFile(paths.diagnosticsPath, diagnosticsArtifactJson),writeFile(paths.discoveryManifestPath, discoveryManifestJson),- writeFile(paths.channelInstrumentationTypesPath, channelInstrumentationTypesSource),writeFile(paths.moduleMapPath, moduleMapSource),writeFile(paths.compileMetadataPath, metadataJson),]);diff --git a/packages/eve/src/compiler/channel-instrumentation-types.test.ts b/packages/eve/src/compiler/channel-instrumentation-types.test.tsdeleted file mode 100644index 20fe2b211..000000000--- a/packages/eve/src/compiler/channel-instrumentation-types.test.ts+++ /dev/null@@ -1,137 +0,0 @@-import { describe, expect, it } from "vitest";--import {- CHANNEL_INSTRUMENTATION_TYPES_FILE_NAME,- createChannelInstrumentationTypesSource,-} from "#compiler/channel-instrumentation-types.js";-import {- COMPILED_AGENT_MANIFEST_VERSION,- createCompiledAgentManifest,- type CompiledChannelEntry,- type CompiledChannelDefinition,-} from "#compiler/manifest.js";-import type { ChannelMethod } from "#public/definitions/channel.js";--function createChannel(input: {- readonly exportName?: string;- readonly logicalPath: string;- readonly method?: ChannelMethod;- readonly name: string;- readonly sourceId?: string;- readonly urlPath?: string;-}): CompiledChannelDefinition {- const channel: CompiledChannelDefinition = {- kind: "channel",- logicalPath: input.logicalPath,- method: input.method ?? "POST",- name: input.name,- sourceId: input.sourceId ?? input.logicalPath,- sourceKind: "module",- urlPath: input.urlPath ?? `/${input.name}`,- };-- if (input.exportName !== undefined) {- return {- ...channel,- exportName: input.exportName,- };- }-- return channel;-}--function createManifest(channels: readonly CompiledChannelEntry[]) {- return createCompiledAgentManifest({- agentRoot: "/workspace/app/agent",- appRoot: "/workspace/app",- channels,- config: {- model: {- contextWindowTokens: 128_000,- id: "openai/gpt-5.4-mini",- routing: { kind: "gateway", target: "openai" },- },- name: "test-agent",- },- });-}--describe("createChannelInstrumentationTypesSource", () => {- it("emits deterministic ambient metadata map entries for authored channels", () => {- const source = createChannelInstrumentationTypesSource({- manifest: createManifest([- createChannel({- logicalPath: "channels/support.ts",- method: "POST",- name: "support",- urlPath: "/support",- }),- createChannel({- logicalPath: "channels/support.ts",- method: "GET",- name: "support",- urlPath: "/support/events",- }),- {- kind: "disabled",- logicalPath: "channels/legacy.ts",- name: "legacy",- },- createChannel({- exportName: "opsChannel",- logicalPath: "channels/ops.mts",- name: "ops",- }),- ]),- typesPath: `/workspace/app/.eve/compile/${CHANNEL_INSTRUMENTATION_TYPES_FILE_NAME}`,- });-- expect(source).toBe(- [- "// Generated by eve. Do not edit by hand.",- 'import type { InferChannelMetadata } from "eve/channels";',- "",- 'declare module "eve/channels" {',- " interface ChannelMetadataMap {",- ' readonly "channel:ops": InferChannelMetadata<typeof import("../../agent/channels/ops.mjs").opsChannel>;',- ' readonly "channel:support": InferChannelMetadata<typeof import("../../agent/channels/support.js").default>;',- " }",- " interface ChannelReferenceMap {",- ' readonly "channel:ops": typeof import("../../agent/channels/ops.mjs").opsChannel;',- ' readonly "channel:support": typeof import("../../agent/channels/support.js").default;',- " }",- "}",- "",- ].join("\n"),- );- });-- it("emits an empty declaration for agents without active channels", () => {- const source = createChannelInstrumentationTypesSource({- manifest: {- ...createManifest([- {- kind: "disabled",- logicalPath: "channels/support.ts",- name: "support",- },- ]),- version: COMPILED_AGENT_MANIFEST_VERSION,- },- typesPath: `/workspace/app/.eve/compile/${CHANNEL_INSTRUMENTATION_TYPES_FILE_NAME}`,- });-- expect(source).toBe(- [- "// Generated by eve. Do not edit by hand.",- 'import type { InferChannelMetadata } from "eve/channels";',- "",- 'declare module "eve/channels" {',- " interface ChannelMetadataMap {}",- " interface ChannelReferenceMap {}",- "}",- "",- ].join("\n"),- );- });-});diff --git a/packages/eve/src/compiler/channel-instrumentation-types.ts b/packages/eve/src/compiler/channel-instrumentation-types.tsdeleted file mode 100644index 7ed39e8f3..000000000--- a/packages/eve/src/compiler/channel-instrumentation-types.ts+++ /dev/null@@ -1,138 +0,0 @@-import { dirname, join, relative } from "node:path";--import type { CompiledAgentManifest, CompiledChannelDefinition } from "#compiler/manifest.js";--interface ChannelInstrumentationTypesSourceInput {- readonly manifest: CompiledAgentManifest;- readonly typesPath: string;-}--interface ChannelInstrumentationDeclaration {- readonly exportName?: string;- readonly importSpecifier: string;- readonly kind: string;-}--export const CHANNEL_INSTRUMENTATION_TYPES_FILE_NAME = "channel-instrumentation-types.d.ts";--export function createChannelInstrumentationTypesSource(- input: ChannelInstrumentationTypesSourceInput,-): string {- const declarations = collectChannelInstrumentationDeclarations(input);- const body =- declarations.length === 0- ? [" interface ChannelMetadataMap {}", " interface ChannelReferenceMap {}"]- : [- " interface ChannelMetadataMap {",- ...declarations.map(- (declaration) =>- ` readonly ${JSON.stringify(declaration.kind)}: InferChannelMetadata<${renderImportedChannelType(declaration)}>;`,- ),- " }",- " interface ChannelReferenceMap {",- ...declarations.map(- (declaration) =>- ` readonly ${JSON.stringify(declaration.kind)}: ${renderImportedChannelType(declaration)};`,- ),- " }",- ];-- return [- "// Generated by eve. Do not edit by hand.",- 'import type { InferChannelMetadata } from "eve/channels";',- "",- 'declare module "eve/channels" {',- ...body,- "}",- "",- ].join("\n");-}--function collectChannelInstrumentationDeclarations(- input: ChannelInstrumentationTypesSourceInput,-): ChannelInstrumentationDeclaration[] {- const typesDirectory = dirname(input.typesPath);- const declarationsByKind = new Map<string, ChannelInstrumentationDeclaration>();-- for (const channel of [...input.manifest.channels]- .filter((entry): entry is CompiledChannelDefinition => entry.kind === "channel")- .sort(compareCompiledChannels)) {- const kind = `channel:${channel.name}`;-- if (declarationsByKind.has(kind)) {- continue;- }-- declarationsByKind.set(kind, {- exportName: channel.exportName,- importSpecifier: createChannelImportSpecifier({- agentRoot: input.manifest.agentRoot,- channel,- fromDirectory: typesDirectory,- }),- kind,- });- }-- return [...declarationsByKind.values()];-}--function compareCompiledChannels(- left: CompiledChannelDefinition,- right: CompiledChannelDefinition,-): number {- return (- left.name.localeCompare(right.name) ||- left.logicalPath.localeCompare(right.logicalPath) ||- (left.exportName ?? "").localeCompare(right.exportName ?? "") ||- left.sourceId.localeCompare(right.sourceId) ||- left.method.localeCompare(right.method) ||- left.urlPath.localeCompare(right.urlPath)- );-}--function createChannelImportSpecifier(input: {- readonly agentRoot: string;- readonly channel: CompiledChannelDefinition;- readonly fromDirectory: string;-}): string {- const targetPath = join(input.agentRoot, toRuntimeImportLogicalPath(input.channel.logicalPath));- const relativeSpecifier = relative(input.fromDirectory, targetPath).replaceAll("\\", "/");-- if (relativeSpecifier.startsWith(".")) {- return relativeSpecifier;- }-- return `./${relativeSpecifier}`;-}--function toRuntimeImportLogicalPath(logicalPath: string): string {- if (logicalPath.endsWith(".mts")) {- return `${logicalPath.slice(0, -".mts".length)}.mjs`;- }-- if (logicalPath.endsWith(".cts")) {- return `${logicalPath.slice(0, -".cts".length)}.cjs`;- }-- if (logicalPath.endsWith(".ts")) {- return `${logicalPath.slice(0, -".ts".length)}.js`;- }-- return logicalPath;-}--function renderImportedChannelType(declaration: ChannelInstrumentationDeclaration): string {- const exportName = declaration.exportName ?? "default";- const importedModule = `import(${JSON.stringify(declaration.importSpecifier)})`;-- if (isIdentifierName(exportName)) {- return `typeof ${importedModule}.${exportName}`;- }-- return `typeof ${importedModule}[${JSON.stringify(exportName)}]`;-}--function isIdentifierName(value: string): boolean {- return /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(value);-}diff --git a/packages/eve/src/harness/instrumentation-runtime-context.test.ts b/packages/eve/src/harness/instrumentation-runtime-context.test.tsindex b20e9ad76..474e5fd2b 100644--- a/packages/eve/src/harness/instrumentation-runtime-context.test.ts+++ b/packages/eve/src/harness/instrumentation-runtime-context.test.ts@@ -14,14 +14,6 @@ import type {InstrumentationStepStartedEventResult,} from "#public/instrumentation/index.js";-declare module "#public/channels/index.js" {- interface ChannelMetadataMap {- readonly "channel:support": {- readonly triggeringUserId: string | null;- } & Readonly<Record<string, unknown>>;- }-}-const session: HarnessSession = {agent: {modelReference: { id: "test-model" },@@ -183,7 +175,10 @@ describe("buildTelemetryRuntimeContext", () => {input.channel.kind === "channel:support"? {runtimeContext: {- "slack.user_id": input.channel.metadata.triggeringUserId ?? "",+ "slack.user_id":+ typeof input.channel.metadata["triggeringUserId"] === "string"+ ? input.channel.metadata["triggeringUserId"]+ : "",},}: { runtimeContext: {} },@@ -234,6 +229,6 @@ describe("buildTelemetryRuntimeContext", () => {if (captured?.channel.kind !== "channel:support") {throw new Error("expected support channel");}- expect(captured.channel.metadata.nested).toEqual({ value: "original" });+ expect(captured.channel.metadata).toMatchObject({ nested: { value: "original" } });});});diff --git a/packages/eve/src/harness/tool-loop.test.ts b/packages/eve/src/harness/tool-loop.test.tsindex 9396dbb2f..5d2b37b89 100644--- a/packages/eve/src/harness/tool-loop.test.ts+++ b/packages/eve/src/harness/tool-loop.test.ts@@ -52,14 +52,6 @@ import {EMPTY_DELIVERY_SENTINEL,} from "#shared/empty-delivery.js";-declare module "#public/channels/index.js" {- interface ChannelMetadataMap {- readonly "channel:support": {- readonly triggeringUserId: string | null;- } & Readonly<Record<string, unknown>>;- }-}-vi.mock("ai", () => ({ToolLoopAgent: vi.fn(),gateway: {@@ -8385,7 +8377,10 @@ describe("createToolLoopHarness", () => {return {runtimeContext: {"eve.session.id": "user-override",- "slack.user_id": input.channel.metadata.triggeringUserId ?? "",+ "slack.user_id":+ typeof input.channel.metadata["triggeringUserId"] === "string"+ ? input.channel.metadata["triggeringUserId"]+ : "","turn.id": input.turn.id,},};diff --git a/packages/eve/src/public/channels/index.ts b/packages/eve/src/public/channels/index.tsindex b83b3be0c..f78fb7f1c 100644--- a/packages/eve/src/public/channels/index.ts+++ b/packages/eve/src/public/channels/index.ts@@ -36,11 +36,7 @@ export {} from "#channel/websocket-upgrade-server.js";import { getChannelInstrumentationKind } from "#channel/compiled-channel.js";-import type { Channel } from "#public/definitions/channel.js";--// ----------------------------------------------------------------------------// Channel metadata maps and isChannel narrowing-// ---------------------------------------------------------------------------+import type { Channel, InferChannelMetadata } from "#public/definitions/channel.js";/*** Base channel metadata shape used by framework channel kinds.@@ -48,90 +44,38 @@ import type { Channel } from "#public/definitions/channel.js";export type InstrumentationChannelMetadata = Readonly<Record<string, unknown>>;/**- * Channel metadata projections keyed by channel kind.- *- * Built-in channel packages ship declaration-merged entries (e.g. Slack- * ships `"channel:slack"`). The eve compiler generates entries for- * authored channels at build time.- */-export interface ChannelMetadataMap {- readonly http: InstrumentationChannelMetadata;- readonly schedule: InstrumentationChannelMetadata;- readonly subagent: InstrumentationChannelMetadata;- readonly unknown: InstrumentationChannelMetadata;- readonly "channel:slack": import("#public/channels/slack/slackChannel.js").SlackInstrumentationMetadata;- readonly "channel:chat-sdk": import("#public/channels/chat-sdk/chatSdkChannel.js").ChatSdkInstrumentationMetadata;- readonly "channel:discord": import("#public/channels/discord/index.js").DiscordInstrumentationMetadata;- readonly "channel:twilio": import("#public/channels/twilio/twilioChannel.js").TwilioInstrumentationMetadata;- readonly "channel:teams": import("#public/channels/teams/index.js").TeamsInstrumentationMetadata;- readonly "channel:telegram": import("#public/channels/telegram/index.js").TelegramInstrumentationMetadata;- readonly "channel:linear": import("#public/channels/linear/index.js").LinearInstrumentationMetadata;-}--/**- * Union of all known channel kind discriminators (the keys of- * {@link ChannelMetadataMap}): the framework kinds `"http"`, `"schedule"`,- * `"subagent"`, and `"unknown"`, plus a `"channel:<slug>"` entry for each- * built-in and compiler-generated authored channel.+ * Kind discriminator exposed to instrumentation and dynamic resolvers.*/-export type InstrumentationChannelKind = keyof ChannelMetadataMap;+export type InstrumentationChannelKind =+ | "http"+ | "schedule"+ | "subagent"+ | "unknown"+ | `channel:${string}`;/**- * Channel values keyed by path-derived channel kind.- *- * Entries are generated by the eve compiler for authored channels.- * Built-in channel entries are declared inline above.- * Used by {@link isChannel} to resolve a channel value to its kind string.- */-export interface ChannelReferenceMap {- readonly "channel:slack": import("#public/channels/slack/slackChannel.js").SlackChannel;- readonly "channel:chat-sdk": import("#public/channels/chat-sdk/chatSdkChannel.js").ChatSdkChannel;- readonly "channel:discord": import("#public/channels/discord/discordChannel.js").DiscordChannel;- readonly "channel:twilio": import("#public/channels/twilio/twilioChannel.js").TwilioChannel;- readonly "channel:teams": import("#public/channels/teams/teamsChannel.js").TeamsChannel;- readonly "channel:telegram": import("#public/channels/telegram/telegramChannel.js").TelegramChannel;- readonly "channel:linear": import("#public/channels/linear/linearChannel.js").LinearChannel;-}--/**- * One arm of {@link InstrumentationChannel}: a channel of kind `K` paired with- * its matching {@link ChannelMetadataMap} metadata projection.+ * Instrumentation projection for one channel kind.*/export interface InstrumentationChannelForKind<K extends InstrumentationChannelKind> {readonly kind: K;- readonly metadata: ChannelMetadataMap[K];+ readonly metadata: InstrumentationChannelMetadata;}/**- * Discriminated union over every {@link InstrumentationChannelKind}, each arm- * carrying its `kind` string and matching `metadata`. This is the channel shape- * instrumentation callbacks receive as `input.channel`; narrow it with- * {@link isChannel}.+ * Channel shape received by instrumentation callbacks and dynamic resolvers.+ * Use {@link isChannel} with a channel definition to narrow authored metadata.*/-export type InstrumentationChannel = {- readonly [K in InstrumentationChannelKind]: InstrumentationChannelForKind<K>;-}[InstrumentationChannelKind];--type ChannelReferenceKind<TChannel> = {- readonly [K in keyof ChannelReferenceMap]: [TChannel] extends [ChannelReferenceMap[K]]- ? [ChannelReferenceMap[K]] extends [TChannel]- ? K- : never- : never;-}[keyof ChannelReferenceMap];+export type InstrumentationChannel = InstrumentationChannelForKind<InstrumentationChannelKind>;/**- * The {@link InstrumentationChannel} arm matching the app-owned channel value- * `TChannel`, resolved through its compiler-derived `channel:<slug>` identity in- * {@link ChannelReferenceMap}. Used as the narrowed type produced by- * {@link isChannel}.+ * Instrumentation channel narrowed to the metadata projected by `TChannel`.*/-export type InstrumentationChannelForChannel<TChannel> = Extract<- InstrumentationChannel,- {- readonly kind: Extract<ChannelReferenceKind<TChannel>, InstrumentationChannelKind>;- }->;+export type InstrumentationChannelForChannel<TChannel extends Channel<any, any, any>> = Omit<+ InstrumentationChannelForKind<`channel:${string}`>,+ "metadata"+> & {+ readonly metadata: InferChannelMetadata<TChannel>;+};/*** Narrows a channel by comparing it to an app-owned channel value imported@@ -139,8 +83,8 @@ export type InstrumentationChannelForChannel<TChannel> = Extract<** Works with both instrumentation resolver inputs (`input.channel`) and* dynamic resolver inputs (`ctx.channel`). The comparison uses the- * compiler's path-derived `channel:<slug>` identity. Metadata narrows to- * the channel's declared `ChannelMetadataMap` entry on success.+ * compiler's path-derived `channel:<slug>` identity. Metadata is inferred+ * directly from the target channel definition.*/export function isChannel<TChannel extends Channel<any, any, any>>(channel: InstrumentationChannel | { readonly kind?: string },diff --git a/packages/eve/src/public/instrumentation/index.test.ts b/packages/eve/src/public/instrumentation/index.test.tsindex 4a8e0b208..91224083e 100644--- a/packages/eve/src/public/instrumentation/index.test.ts+++ b/packages/eve/src/public/instrumentation/index.test.ts@@ -1,10 +1,7 @@import { describe, expect, it } from "vitest";-import {- CHANNEL_SENTINEL,- setChannelInstrumentationKind,- type CompiledChannel,-} from "#channel/compiled-channel.js";+import { setChannelInstrumentationKind, type CompiledChannel } from "#channel/compiled-channel.js";+import { defineChannel, POST } from "#public/definitions/channel.js";import { isChannel, type InstrumentationChannel } from "#public/instrumentation/index.js";type SupportMetadata = {@@ -12,31 +9,22 @@ type SupportMetadata = {readonly queueId: string | null;};-const supportChannel: CompiledChannel<undefined, Record<string, unknown>, SupportMetadata> = {- __kind: CHANNEL_SENTINEL,- adapter: { kind: "defineChannel" },- routes: [- {- method: "POST",- path: "/support",- handler: async () => new Response("ok"),- },- ],-};+function createSupportChannel() {+ return defineChannel({+ metadata: (): SupportMetadata => ({ priority: "high", queueId: null }),+ routes: [POST("/support", async () => new Response("ok"))],+ });+}-declare module "#public/channels/index.js" {- interface ChannelMetadataMap {- readonly "channel:is-channel-test": SupportMetadata;- }+const supportChannel = createSupportChannel();- interface ChannelReferenceMap {- readonly "channel:is-channel-test": typeof supportChannel;- }+function stampSupportChannel(): void {+ setChannelInstrumentationKind(supportChannel as CompiledChannel, "channel:is-channel-test");}describe("isChannel", () => {it("compares instrumentation input to the compiler-stamped channel identity", () => {- setChannelInstrumentationKind(supportChannel, "channel:is-channel-test");+ stampSupportChannel();const input: InstrumentationChannel = {kind: "channel:is-channel-test",@@ -60,7 +48,7 @@ describe("isChannel", () => {});it("returns false when the instrumentation channel kind does not match", () => {- setChannelInstrumentationKind(supportChannel, "channel:is-channel-test");+ stampSupportChannel();expect(isChannel(@@ -74,7 +62,7 @@ describe("isChannel", () => {});it("accepts the DynamicResolveContext.channel shape (optional kind)", () => {- setChannelInstrumentationKind(supportChannel, "channel:is-channel-test");+ stampSupportChannel();const resolveCtxChannel: {readonly kind?: string;@@ -85,11 +73,8 @@ describe("isChannel", () => {});it("recognizes a separately evaluated copy of the authored channel", () => {- setChannelInstrumentationKind(supportChannel, "channel:is-channel-test");- const importedCopy: typeof supportChannel = {- ...supportChannel,- adapter: { kind: "defineChannel" },- };+ stampSupportChannel();+ const importedCopy = createSupportChannel();expect(isChannel(@@ -103,7 +88,7 @@ describe("isChannel", () => {});it("returns false for DynamicResolveContext.channel with undefined kind", () => {- setChannelInstrumentationKind(supportChannel, "channel:is-channel-test");+ stampSupportChannel();const noKind: { readonly kind?: string } = {};expect(isChannel(noKind, supportChannel)).toBe(false);diff --git a/packages/eve/src/public/instrumentation/index.ts b/packages/eve/src/public/instrumentation/index.tsindex db4a16f50..5412e055a 100644--- a/packages/eve/src/public/instrumentation/index.ts+++ b/packages/eve/src/public/instrumentation/index.ts@@ -14,8 +14,6 @@ import type { JsonObject } from "#shared/json.js";// imports continue to work. The canonical home is `eve/channels`.export {isChannel,- type ChannelMetadataMap,- type ChannelReferenceMap,type InstrumentationChannel,type InstrumentationChannelForChannel,type InstrumentationChannelForKind,diff --git a/packages/eve/src/setup/scaffold/create/project.ts b/packages/eve/src/setup/scaffold/create/project.tsindex e6fd7fe4f..ea8c42c81 100644--- a/packages/eve/src/setup/scaffold/create/project.ts+++ b/packages/eve/src/setup/scaffold/create/project.ts@@ -238,7 +238,7 @@ const SHARED_TEMPLATE_FILES: Record<string, string> = {"skipLibCheck": true,"noEmit": true},- "include": ["agent/**/*.ts", "evals/**/*.ts", ".eve/**/*.d.ts"]+ "include": ["agent/**/*.ts", "evals/**/*.ts"]}`,".gitignore": `node_modulesdiff --git a/packages/eve/src/setup/scaffold/create/web-template.ts b/packages/eve/src/setup/scaffold/create/web-template.tsindex b080d6156..78356ba1a 100644--- a/packages/eve/src/setup/scaffold/create/web-template.ts+++ b/packages/eve/src/setup/scaffold/create/web-template.ts@@ -72,7 +72,7 @@ export const WEB_APP_TEMPLATE_FILES = {"postcss.config.mjs":'const config = {\n plugins: {\n "@tailwindcss/postcss": {},\n },\n};\n\nexport default config;\n',"tsconfig.json":- '{\n "$schema": "https://json.schemastore.org/tsconfig",\n "compilerOptions": {\n "target": "ES2017",\n "lib": ["dom", "dom.iterable", "esnext"],\n "allowJs": true,\n "skipLibCheck": true,\n "strict": true,\n "noEmit": true,\n "esModuleInterop": true,\n "module": "esnext",\n "moduleResolution": "Bundler",\n "resolveJsonModule": true,\n "isolatedModules": true,\n "jsx": "react-jsx",\n "incremental": true,\n "plugins": [\n {\n "name": "next"\n }\n ],\n "paths": {\n "@/*": ["./*"]\n }\n },\n "include": [\n "next-env.d.ts",\n "**/*.ts",\n "**/*.tsx",\n ".eve/**/*.d.ts",\n ".next/types/**/*.ts",\n ".next/dev/types/**/*.ts"\n ],\n "exclude": ["node_modules"]\n}\n',+ '{\n "$schema": "https://json.schemastore.org/tsconfig",\n "compilerOptions": {\n "target": "ES2017",\n "lib": ["dom", "dom.iterable", "esnext"],\n "allowJs": true,\n "skipLibCheck": true,\n "strict": true,\n "noEmit": true,\n "esModuleInterop": true,\n "module": "esnext",\n "moduleResolution": "Bundler",\n "resolveJsonModule": true,\n "isolatedModules": true,\n "jsx": "react-jsx",\n "incremental": true,\n "plugins": [\n {\n "name": "next"\n }\n ],\n "paths": {\n "@/*": ["./*"]\n }\n },\n "include": [\n "next-env.d.ts",\n "**/*.ts",\n "**/*.tsx",\n ".next/types/**/*.ts",\n ".next/dev/types/**/*.ts"\n ],\n "exclude": ["node_modules"]\n}\n',} as const;export const WEB_APP_TEMPLATE_PACKAGE_JSON = {diff --git a/packages/eve/src/setup/scaffold/index.integration.test.ts b/packages/eve/src/setup/scaffold/index.integration.test.tsindex 4a31e4cc3..9b927513e 100644--- a/packages/eve/src/setup/scaffold/index.integration.test.ts+++ b/packages/eve/src/setup/scaffold/index.integration.test.ts@@ -203,6 +203,10 @@ describe("ensureChannel", () => {expect(packageJson).toContain('"dev:eve": "eve dev"');expect(packageJson).toContain('"start:eve": "eve start"');expect(JSON.parse(packageJson)).toMatchObject({ engines: { node: "24.x" } });+ const tsconfig = JSON.parse(await readFile(join(projectRoot, "tsconfig.json"), "utf8")) as {+ include?: string[];+ };+ expect(tsconfig.include).not.toContain(".eve/**/*.d.ts");await expect(readFile(join(projectRoot, "pnpm-workspace.yaml"), "utf8")).resolves.toBe(PNPM_WORKSPACE_CONTENT,);@@ -801,8 +805,10 @@ describe("scaffoldBaseProject", () => {expect(packageJson).toContain('"@types/node": "24.x"');const tsconfig = JSON.parse(await readFile(join(projectRoot, "tsconfig.json"), "utf8")) as {compilerOptions: { types?: string[] };+ include?: string[];};expect(tsconfig.compilerOptions.types).toEqual(["node"]);+ expect(tsconfig.include).toEqual(["agent/**/*.ts", "evals/**/*.ts"]);await expect(readFile(join(projectRoot, "pnpm-workspace.yaml"), "utf8")).resolves.toBe(PNPM_WORKSPACE_CONTENT,);diff --git a/packages/eve/test/scenarios/compile-agent.scenario.test.ts b/packages/eve/test/scenarios/compile-agent.scenario.test.tsindex f1be307bc..88793e647 100644--- a/packages/eve/test/scenarios/compile-agent.scenario.test.ts+++ b/packages/eve/test/scenarios/compile-agent.scenario.test.ts@@ -145,14 +145,12 @@ describe("compiler artifacts", () => {diagnosticsText,metadataText,moduleMapText,- channelInstrumentationTypesText,] = await Promise.all([readFile(writtenArtifacts.paths.compiledManifestPath, "utf8"),readFile(writtenArtifacts.paths.discoveryManifestPath, "utf8"),readFile(writtenArtifacts.paths.diagnosticsPath, "utf8"),readFile(writtenArtifacts.paths.compileMetadataPath, "utf8"),readFile(writtenArtifacts.paths.moduleMapPath, "utf8"),- readFile(writtenArtifacts.paths.channelInstrumentationTypesPath, "utf8"),]);expect(normalizeArtifactValue(JSON.parse(discoveryManifestText), appRoot)).toMatchObject({@@ -285,22 +283,6 @@ describe("compiler artifacts", () => {expect(moduleMapText).toContain('"nodes": Object.freeze({');expect(moduleMapText).toContain(`"${ROOT_COMPILED_AGENT_NODE_ID}": Object.freeze({`);expect(moduleMapText).toContain('"agent.mjs": module_0');- expect(channelInstrumentationTypesText).toBe(- [- "// Generated by eve. Do not edit by hand.",- 'import type { InferChannelMetadata } from "eve/channels";',- "",- 'declare module "eve/channels" {',- " interface ChannelMetadataMap {",- ' readonly "channel:support": InferChannelMetadata<typeof import("../../agent/channels/support.mjs").default>;',- " }",- " interface ChannelReferenceMap {",- ' readonly "channel:support": typeof import("../../agent/channels/support.mjs").default;',- " }",- "}",- "",- ].join("\n"),- );expect(moduleMapText).not.toContain('"subagents": Object.freeze({');});@@ -482,7 +464,7 @@ describe("compiler artifacts", () => {});describe("compileAgent", () => {- it("generates channel metadata typings that narrow instrumentation input", async () => {+ it("narrows authored channel metadata without generated declarations", async () => {const app = await scenarioApp({files: {"agent/agent.mjs": 'export default { model: "openai/gpt-5.4" };\n',@@ -507,7 +489,7 @@ describe("compileAgent", () => {" if (!isChannel(input.channel, supportChannel)) return undefined;"," const queueId: string | null = input.channel.metadata.queueId;",' const priority: "high" = input.channel.metadata.priority;',- " // @ts-expect-error generated metadata contains no arbitrary fallback keys.",+ " // @ts-expect-error channel metadata contains no arbitrary fallback keys."," input.channel.metadata.missing;",' return { runtimeContext: { "support.has_queue": String(queueId !== null), "support.priority": priority } };'," },",@@ -517,7 +499,7 @@ describe("compileAgent", () => {].join("\n"),},installDependencies: true,- name: "channel-instrumentation-types",+ name: "authored-channel-metadata",});const appRoot = app.appRoot;await writeFile(@@ -535,25 +517,13 @@ describe("compileAgent", () => {typeRoots: [ROOT_TYPE_DEFINITIONS],types: ["node"],},- include: ["agent/**/*.ts", ".eve/**/*.d.ts"],+ include: ["agent/**/*.ts"],},null,2,)}\n`,);- const result = await compileAgent({- startPath: appRoot,- });- const generatedTypes = await readFile(result.paths.channelInstrumentationTypesPath, "utf8");-- expect(generatedTypes).toContain(- 'readonly "channel:support": InferChannelMetadata<typeof import("../../agent/channels/support.js").default>;',- );- expect(generatedTypes).toContain(- 'readonly "channel:support": typeof import("../../agent/channels/support.js").default;',- );-await expectTscToPass([TSC_BIN_PATH, "-p", join(appRoot, "tsconfig.json")], {cwd: REPO_ROOT,});