eve 0.38.0 → 0.38.1
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 +7 -0
- package/dist/src/compiler/extension-compatibility.d.ts +5 -0
- package/dist/src/compiler/extension-compatibility.js +1 -1
- package/dist/src/compiler/normalize-extension.d.ts +10 -1
- package/dist/src/compiler/normalize-extension.js +1 -1
- package/dist/src/compiler/normalize-manifest.js +1 -1
- package/dist/src/compiler/normalize-subagent.d.ts +1 -0
- package/dist/src/compiler/normalize-subagent.js +1 -1
- package/dist/src/discover/discover-agent.js +1 -1
- package/dist/src/discover/discover-subagent.js +1 -1
- package/dist/src/internal/application/package.js +1 -1
- package/dist/src/internal/authored-module-map-loader.js +1 -1
- package/dist/src/internal/nitro/host/extension-capability-requirements.js +1 -1
- package/dist/src/public/channels/mcp.d.ts +2 -2
- package/dist/src/public/channels/mcp.js +1 -1
- package/dist/src/setup/scaffold/create/extension.js +1 -1
- package/dist/src/setup/scaffold/create/project.js +1 -1
- package/docs/extensions.md +14 -6
- package/docs/subagents/index.mdx +3 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# eve
|
|
2
2
|
|
|
3
|
+
## 0.38.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- d23467d: Allow extensions to contribute namespaced subagents, including their tools, configuration access, nested subagents, and directory-mount overrides.
|
|
8
|
+
- cb2fa2a: Configure MCP channel endpoints with `route`, default them to `/eve/v1/mcp`, and derive OAuth protected-resource metadata paths from the MCP resource identifier.
|
|
9
|
+
|
|
3
10
|
## 0.38.0
|
|
4
11
|
|
|
5
12
|
### Minor Changes
|
|
@@ -30,6 +30,11 @@ declare const EXTENSION_CAPABILITY_CONTRACTS: {
|
|
|
30
30
|
readonly supported: readonly [1];
|
|
31
31
|
readonly dropped: {};
|
|
32
32
|
};
|
|
33
|
+
readonly subagent: {
|
|
34
|
+
readonly current: 1;
|
|
35
|
+
readonly supported: readonly [1];
|
|
36
|
+
readonly dropped: {};
|
|
37
|
+
};
|
|
33
38
|
readonly connection: {
|
|
34
39
|
readonly current: 5;
|
|
35
40
|
readonly supported: readonly [1, 2, 3, 4, 5];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{readFile,writeFile}from"node:fs/promises";import{z}from"#compiled/zod/index.js";import{join}from"node:path";import{formatValidationError}from"#runtime/validation.js";const EXTENSION_COMPATIBILITY_MANIFEST_KIND=`eve-extension`,EXTENSION_COMPATIBILITY_MANIFEST_FORMAT_VERSION=1,EXTENSION_COMPATIBILITY_MANIFEST_FILENAME=`_manifest.json`,EXTENSION_CAPABILITY_CONTRACTS={extension:{current:1,supported:[1],dropped:{}},tool:{current:13,supported:[1,2,3,4,5,6,7,8,9,10,11,12,13],dropped:{}},dynamicTool:{current:17,supported:[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17],dropped:{}},channel:{current:1,supported:[1],dropped:{}},schedule:{current:1,supported:[1],dropped:{}},connection:{current:5,supported:[1,2,3,4,5],dropped:{}},hook:{current:13,supported:[10,11,12,13],dropped:{1:`Model identity moved from session.started runtime metadata to step.started call attribution.`,2:`Model identity moved from session.started runtime metadata to step.started call attribution.`,3:`Model identity moved from session.started runtime metadata to step.started call attribution.`,4:`Model identity moved from session.started runtime metadata to step.started call attribution.`,5:`Model identity moved from session.started runtime metadata to step.started call attribution.`,6:`Model identity moved from session.started runtime metadata to step.started call attribution.`,7:`Model identity moved from session.started runtime metadata to step.started call attribution.`,8:`Model identity moved from session.started runtime metadata to step.started call attribution.`,9:`Model identity moved from session.started runtime metadata to step.started call attribution.`}},skill:{current:1,supported:[1],dropped:{}},dynamicSkill:{current:11,supported:[1,2,3,4,5,6,7,8,9,10,11],dropped:{}},instructions:{current:2,supported:[1,2],dropped:{}},dynamicInstructions:{current:12,supported:[1,2,3,4,5,6,7,8,9,10,11,12],dropped:{}},config:{current:1,supported:[1],dropped:{}},state:{current:3,supported:[1,2,3],dropped:{}}},EXTENSION_CAPABILITY_VERSIONS=Object.fromEntries(Object.entries(EXTENSION_CAPABILITY_CONTRACTS).map(([e,t])=>[e,t.current])),EXTENSION_CAPABILITY_SUPPORT=Object.keys(EXTENSION_CAPABILITY_CONTRACTS).reduce((e,t)=>(e[t]=EXTENSION_CAPABILITY_CONTRACTS[t].supported,e),{}),extensionCompatibilityManifestSchema=z.object({kind:z.literal(EXTENSION_COMPATIBILITY_MANIFEST_KIND),formatVersion:z.literal(1),builtWithEve:z.string().min(1),requires:z.record(z.string(),z.number().int().positive())}).strict();function serializeExtensionCompatibilityManifest(e){return`${JSON.stringify(e,null,2)}\n`}function parseExtensionCompatibilityManifest(e,t){let n;try{n=JSON.parse(e)}catch(e){throw Error(`Extension compatibility manifest "${t}" is not valid JSON: ${e instanceof Error?e.message:String(e)}`)}let r=extensionCompatibilityManifestSchema.safeParse(n);if(!r.success)throw Error(`Extension compatibility manifest "${t}" is invalid. ${formatValidationError(r.error)}`);return r.data}async function readExtensionCompatibilityManifest(t){return parseExtensionCompatibilityManifest(await readFile(t,`utf8`),t)}async function writeExtensionCompatibilityManifest(e,n){await writeFile(join(e,EXTENSION_COMPATIBILITY_MANIFEST_FILENAME),serializeExtensionCompatibilityManifest(n),`utf8`)}function findUnsupportedExtensionCapabilities(e,t=EXTENSION_CAPABILITY_SUPPORT){return Object.entries(e.requires).flatMap(([e,n])=>{let r=Object.hasOwn(t,e)?t[e]??[]:[];return r.includes(n)?[]:[{capability:e,requiredVersion:n,supportedVersions:r}]}).sort((e,t)=>e.capability.localeCompare(t.capability))}export{EXTENSION_CAPABILITY_SUPPORT,EXTENSION_CAPABILITY_VERSIONS,EXTENSION_COMPATIBILITY_MANIFEST_FILENAME,EXTENSION_COMPATIBILITY_MANIFEST_FORMAT_VERSION,EXTENSION_COMPATIBILITY_MANIFEST_KIND,findUnsupportedExtensionCapabilities,parseExtensionCompatibilityManifest,readExtensionCompatibilityManifest,serializeExtensionCompatibilityManifest,writeExtensionCompatibilityManifest};
|
|
1
|
+
import{readFile,writeFile}from"node:fs/promises";import{z}from"#compiled/zod/index.js";import{join}from"node:path";import{formatValidationError}from"#runtime/validation.js";const EXTENSION_COMPATIBILITY_MANIFEST_KIND=`eve-extension`,EXTENSION_COMPATIBILITY_MANIFEST_FORMAT_VERSION=1,EXTENSION_COMPATIBILITY_MANIFEST_FILENAME=`_manifest.json`,EXTENSION_CAPABILITY_CONTRACTS={extension:{current:1,supported:[1],dropped:{}},tool:{current:13,supported:[1,2,3,4,5,6,7,8,9,10,11,12,13],dropped:{}},dynamicTool:{current:17,supported:[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17],dropped:{}},channel:{current:1,supported:[1],dropped:{}},schedule:{current:1,supported:[1],dropped:{}},subagent:{current:1,supported:[1],dropped:{}},connection:{current:5,supported:[1,2,3,4,5],dropped:{}},hook:{current:13,supported:[10,11,12,13],dropped:{1:`Model identity moved from session.started runtime metadata to step.started call attribution.`,2:`Model identity moved from session.started runtime metadata to step.started call attribution.`,3:`Model identity moved from session.started runtime metadata to step.started call attribution.`,4:`Model identity moved from session.started runtime metadata to step.started call attribution.`,5:`Model identity moved from session.started runtime metadata to step.started call attribution.`,6:`Model identity moved from session.started runtime metadata to step.started call attribution.`,7:`Model identity moved from session.started runtime metadata to step.started call attribution.`,8:`Model identity moved from session.started runtime metadata to step.started call attribution.`,9:`Model identity moved from session.started runtime metadata to step.started call attribution.`}},skill:{current:1,supported:[1],dropped:{}},dynamicSkill:{current:11,supported:[1,2,3,4,5,6,7,8,9,10,11],dropped:{}},instructions:{current:2,supported:[1,2],dropped:{}},dynamicInstructions:{current:12,supported:[1,2,3,4,5,6,7,8,9,10,11,12],dropped:{}},config:{current:1,supported:[1],dropped:{}},state:{current:3,supported:[1,2,3],dropped:{}}},EXTENSION_CAPABILITY_VERSIONS=Object.fromEntries(Object.entries(EXTENSION_CAPABILITY_CONTRACTS).map(([e,t])=>[e,t.current])),EXTENSION_CAPABILITY_SUPPORT=Object.keys(EXTENSION_CAPABILITY_CONTRACTS).reduce((e,t)=>(e[t]=EXTENSION_CAPABILITY_CONTRACTS[t].supported,e),{}),extensionCompatibilityManifestSchema=z.object({kind:z.literal(EXTENSION_COMPATIBILITY_MANIFEST_KIND),formatVersion:z.literal(1),builtWithEve:z.string().min(1),requires:z.record(z.string(),z.number().int().positive())}).strict();function serializeExtensionCompatibilityManifest(e){return`${JSON.stringify(e,null,2)}\n`}function parseExtensionCompatibilityManifest(e,t){let n;try{n=JSON.parse(e)}catch(e){throw Error(`Extension compatibility manifest "${t}" is not valid JSON: ${e instanceof Error?e.message:String(e)}`)}let r=extensionCompatibilityManifestSchema.safeParse(n);if(!r.success)throw Error(`Extension compatibility manifest "${t}" is invalid. ${formatValidationError(r.error)}`);return r.data}async function readExtensionCompatibilityManifest(t){return parseExtensionCompatibilityManifest(await readFile(t,`utf8`),t)}async function writeExtensionCompatibilityManifest(e,n){await writeFile(join(e,EXTENSION_COMPATIBILITY_MANIFEST_FILENAME),serializeExtensionCompatibilityManifest(n),`utf8`)}function findUnsupportedExtensionCapabilities(e,t=EXTENSION_CAPABILITY_SUPPORT){return Object.entries(e.requires).flatMap(([e,n])=>{let r=Object.hasOwn(t,e)?t[e]??[]:[];return r.includes(n)?[]:[{capability:e,requiredVersion:n,supportedVersions:r}]}).sort((e,t)=>e.capability.localeCompare(t.capability))}export{EXTENSION_CAPABILITY_SUPPORT,EXTENSION_CAPABILITY_VERSIONS,EXTENSION_COMPATIBILITY_MANIFEST_FILENAME,EXTENSION_COMPATIBILITY_MANIFEST_FORMAT_VERSION,EXTENSION_COMPATIBILITY_MANIFEST_KIND,findUnsupportedExtensionCapabilities,parseExtensionCompatibilityManifest,readExtensionCompatibilityManifest,serializeExtensionCompatibilityManifest,writeExtensionCompatibilityManifest};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type AgentSourceManifest, type LocalSubagentSourceRef, type ResolvedExtensionMount } from "#discover/manifest.js";
|
|
2
2
|
import type { CompiledChannelEntry, CompiledConnectionDefinition, CompiledDynamicInstructionsDefinition, CompiledDynamicSkillDefinition, CompiledDynamicToolDefinition, CompiledHookDefinition, CompiledInstructionsDefinition, CompiledScheduleDefinition, CompiledSkillDefinition, CompiledToolDefinition } from "#compiler/manifest.js";
|
|
3
3
|
import type { ManifestCompileContext } from "#compiler/normalize-helpers.js";
|
|
4
4
|
/**
|
|
@@ -35,6 +35,15 @@ export declare function compileExtensionContributions(input: {
|
|
|
35
35
|
readonly consumerAgentRoot: string;
|
|
36
36
|
readonly externalDependencies: readonly string[];
|
|
37
37
|
}): Promise<CompiledExtensionContributions>;
|
|
38
|
+
/** Composes one mount's root-visible subagents under its namespace. */
|
|
39
|
+
export declare function composeExtensionSubagentSources(input: {
|
|
40
|
+
readonly consumerAgentRoot: string;
|
|
41
|
+
readonly mount: ResolvedExtensionMount;
|
|
42
|
+
}): LocalSubagentSourceRef[];
|
|
43
|
+
/** Returns authored and mounted-extension subagents visible from one agent node. */
|
|
44
|
+
export declare function composeAgentSubagentSources(manifest: AgentSourceManifest): LocalSubagentSourceRef[];
|
|
45
|
+
/** Earlier entries win, matching directory-override precedence for other slots. */
|
|
46
|
+
export declare function mergeExtensionSubagentSources(primary: readonly LocalSubagentSourceRef[], secondary: readonly LocalSubagentSourceRef[]): LocalSubagentSourceRef[];
|
|
38
47
|
export interface DisabledToolTarget {
|
|
39
48
|
/** Namespaced target, e.g. `crm__search`. */
|
|
40
49
|
readonly name: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{join,relative}from"node:path";import{compileChannelDefinition}from"#compiler/normalize-channel.js";import{compileConnectionDefinition}from"#compiler/normalize-connection.js";import{compileHookEntry}from"#compiler/normalize-hook.js";import{compileInstructionsEntry}from"#compiler/normalize-instructions.js";import{compileScheduleDefinition}from"#compiler/normalize-schedule.js";import{compileSkillSource}from"#compiler/normalize-skill.js";import{compileToolEntry}from"#compiler/normalize-tool.js";async function compileExtensionContributions(e){let{mount:t,consumerAgentRoot:n}=e,r={externalDependencies:e.externalDependencies},i=await composeManifestContributions({manifest:t.manifest,namespace:t.namespace,consumerAgentRoot:n,options:r,sourceIdScope:`ext:${t.namespace}`,role:`extension`});if(t.overrides===void 0)return i.contributions;let a=await composeManifestContributions({manifest:t.overrides,namespace:t.namespace,consumerAgentRoot:n,options:r,sourceIdScope:`ext-override:${t.namespace}`,role:`override`});return applyOverrideDisables({merged:mergeContributions(a.contributions,i.contributions),disables:a.disabledToolTargets,extensionToolNames:new Set(i.contributions.tools.map(e=>e.name)),extensionDynamicToolSlugs:new Set(i.contributions.dynamicTools.map(e=>e.slug)),namespace:t.namespace})}function applyOverrideDisables(e){if(e.disables.length===0)return e.merged;let t=e.namespace.length+2,n=new Set;for(let r of e.disables){if(!e.extensionToolNames.has(r.name)&&!e.extensionDynamicToolSlugs.has(r.name)){let n=[...e.extensionToolNames,...e.extensionDynamicToolSlugs].map(e=>e.slice(t)).sort();throw Error(`The override "agent/extensions/${e.namespace}/${r.logicalPath}" calls disableTool(), but the "${e.namespace}" extension contributes no tool named "${r.name.slice(t)}". It contributes: ${n.length>0?n.join(`, `):`(no tools)`}.`)}n.add(r.name)}return{...e.merged,tools:e.merged.tools.filter(e=>!n.has(e.name)),dynamicTools:e.merged.dynamicTools.filter(e=>!n.has(e.slug))}}async function composeManifestContributions(
|
|
1
|
+
import{join,relative}from"node:path";import{compileChannelDefinition}from"#compiler/normalize-channel.js";import{createPathDerivedSourceId}from"#discover/manifest.js";import{compileConnectionDefinition}from"#compiler/normalize-connection.js";import{compileHookEntry}from"#compiler/normalize-hook.js";import{compileInstructionsEntry}from"#compiler/normalize-instructions.js";import{compileScheduleDefinition}from"#compiler/normalize-schedule.js";import{compileSkillSource}from"#compiler/normalize-skill.js";import{compileToolEntry}from"#compiler/normalize-tool.js";async function compileExtensionContributions(e){let{mount:t,consumerAgentRoot:n}=e,r={externalDependencies:e.externalDependencies},i=await composeManifestContributions({manifest:t.manifest,namespace:t.namespace,consumerAgentRoot:n,options:r,sourceIdScope:`ext:${t.namespace}`,role:`extension`});if(t.overrides===void 0)return i.contributions;let a=await composeManifestContributions({manifest:t.overrides,namespace:t.namespace,consumerAgentRoot:n,options:r,sourceIdScope:`ext-override:${t.namespace}`,role:`override`});return applyOverrideDisables({merged:mergeContributions(a.contributions,i.contributions),disables:a.disabledToolTargets,extensionToolNames:new Set(i.contributions.tools.map(e=>e.name)),extensionDynamicToolSlugs:new Set(i.contributions.dynamicTools.map(e=>e.slug)),namespace:t.namespace})}function composeExtensionSubagentSources(e){let t=scopeExtensionSubagents({consumerAgentRoot:e.consumerAgentRoot,manifest:e.mount.manifest,namespace:e.mount.namespace,sourceIdScope:`ext:${e.mount.namespace}`,sourceRoot:e.mount.sourceRoot});return e.mount.overrides===void 0?t:mergeExtensionSubagentSources(scopeExtensionSubagents({consumerAgentRoot:e.consumerAgentRoot,manifest:e.mount.overrides,namespace:e.mount.namespace,sourceIdScope:`ext-override:${e.mount.namespace}`,sourceRoot:e.mount.overrides.agentRoot}),t)}function composeAgentSubagentSources(e){return[...e.subagents,...[...e.resolvedExtensions].sort((e,t)=>e.namespace.localeCompare(t.namespace)).flatMap(t=>composeExtensionSubagentSources({consumerAgentRoot:e.agentRoot,mount:t}))]}function mergeExtensionSubagentSources(e,t){return dedupeBy([...e,...t],e=>e.subagentId)}function scopeExtensionSubagents(e){return e.manifest.subagents.map(n=>({...scopeExtensionSubagentSource(n,e.sourceRoot,e.sourceIdScope),logicalPath:relative(e.consumerAgentRoot,n.entryPath).replaceAll(`\\`,`/`),subagentId:`${e.namespace}__${n.subagentId}`}))}function scopeExtensionSubagentSource(e,t,n){return{...e,manifest:scopeExtensionSubagentManifest(e.manifest,t,n),sourceId:scopeExtensionSourceId(t,e.entryPath,n)}}function scopeExtensionSubagentManifest(t,n,r){let scopeRef=i=>({...i,sourceId:scopeExtensionSourceId(n,join(t.agentRoot,i.logicalPath),r)});return{...t,channels:t.channels.map(scopeRef),connections:t.connections.map(scopeRef),...t.configModule===void 0?{}:{configModule:scopeRef(t.configModule)},extensions:t.extensions.map(scopeRef),hooks:t.hooks.map(scopeRef),instructions:t.instructions.map(scopeRef),lib:t.lib.map(scopeRef),sandbox:t.sandbox===null?null:scopeRef(t.sandbox),sandboxWorkspaces:t.sandboxWorkspaces.map(scopeRef),schedules:t.schedules.map(scopeRef),skills:t.skills.map(scopeRef),subagents:t.subagents.map(e=>scopeExtensionSubagentSource(e,n,r)),tools:t.tools.map(scopeRef)}}function scopeExtensionSourceId(e,n,i){return`${i}:${createPathDerivedSourceId(relative(e,n).replaceAll(`\\`,`/`))}`}function applyOverrideDisables(e){if(e.disables.length===0)return e.merged;let t=e.namespace.length+2,n=new Set;for(let r of e.disables){if(!e.extensionToolNames.has(r.name)&&!e.extensionDynamicToolSlugs.has(r.name)){let n=[...e.extensionToolNames,...e.extensionDynamicToolSlugs].map(e=>e.slice(t)).sort();throw Error(`The override "agent/extensions/${e.namespace}/${r.logicalPath}" calls disableTool(), but the "${e.namespace}" extension contributes no tool named "${r.name.slice(t)}". It contributes: ${n.length>0?n.join(`, `):`(no tools)`}.`)}n.add(r.name)}return{...e.merged,tools:e.merged.tools.filter(e=>!n.has(e.name)),dynamicTools:e.merged.dynamicTools.filter(e=>!n.has(e.slug))}}async function composeManifestContributions(r){let{manifest:o,namespace:s,consumerAgentRoot:c,options:l,sourceIdScope:u,role:d}=r,f=o.agentRoot,p=`${s}__`,scopeSourceId=e=>`${u}:${e}`,rebase=n=>relative(c,join(f,n)).replaceAll(`\\`,`/`),m=(await Promise.all(o.channels.map(e=>compileChannelDefinition(f,e,l)))).flat().map(e=>e.kind===`disabled`?{...e,name:`${p}${e.name}`,logicalPath:rebase(e.logicalPath)}:{...e,name:`${p}${e.name}`,sourceId:scopeSourceId(e.sourceId),logicalPath:rebase(e.logicalPath)}),h=[],g=[],_=[];for(let e of o.tools){let t=await compileToolEntry(f,e,l);if(t.kind===`tool`)h.push({...t.definition,name:`${p}${t.definition.name}`,sourceId:scopeSourceId(t.definition.sourceId),logicalPath:rebase(t.definition.logicalPath)});else if(t.kind===`dynamic-tool`)g.push({...t.definition,slug:`${p}${t.definition.slug}`,extensionNamespace:s,sourceId:scopeSourceId(t.definition.sourceId),logicalPath:rebase(t.definition.logicalPath)});else if(t.kind===`workflow-tool`)throw Error(`${describeExtensionSource(d,s,e.logicalPath)} enables the Workflow tool, but the Workflow tool is the consuming agent's to enable, not an extension's. Remove it.`);else if(t.kind===`web-search-tool`)throw Error(`${describeExtensionSource(d,s,e.logicalPath)} configures web search, but the web search provider is the consuming agent's to configure, not an extension's. Remove it.`);else if(d===`extension`)throw Error(`${describeExtensionSource(d,s,e.logicalPath)} calls disableTool(), but an extension cannot disable framework tools — that is the consuming agent's to own. Remove it.`);else _.push({name:`${p}${t.name}`,logicalPath:e.logicalPath})}let v=o.hooks.map(e=>{let t=compileHookEntry(e);return{...t,slug:`${p}${t.slug}`,sourceId:scopeSourceId(t.sourceId),logicalPath:rebase(t.logicalPath)}}),y=[],b=[];for(let e of o.skills){let t=await compileSkillSource(f,e,l);t.kind===`skill`?y.push({...t.definition,name:`${p}${t.definition.name}`,sourceId:scopeSourceId(t.definition.sourceId),logicalPath:rebase(t.definition.logicalPath)}):b.push({...t.definition,slug:`${p}${t.definition.slug}`,extensionNamespace:s,sourceId:scopeSourceId(t.definition.sourceId),logicalPath:rebase(t.definition.logicalPath)})}let x=(await Promise.all(o.connections.map(e=>compileConnectionDefinition(f,e,l)))).map(e=>({...e,connectionName:`${p}${e.connectionName}`,sourceId:scopeSourceId(e.sourceId),logicalPath:rebase(e.logicalPath)})),S=[],C=[];for(let e of o.instructions){let t=await compileInstructionsEntry(f,e,l);t.kind===`instructions`?C.push({...t.definition,sourceId:scopeSourceId(t.definition.sourceId),logicalPath:rebase(t.definition.logicalPath)}):S.push({...t.definition,slug:`${p}${t.definition.slug}`,sourceId:scopeSourceId(t.definition.sourceId),logicalPath:rebase(t.definition.logicalPath)})}return{contributions:{channels:m,tools:h,dynamicTools:g,hooks:v,skills:y,dynamicSkills:b,dynamicInstructions:S,connections:x,instructions:C,schedules:await Promise.all(o.schedules.map(async e=>{let t=await compileScheduleDefinition(f,e,l);return{...t,name:`${p}${t.name}`,sourceId:scopeSourceId(t.sourceId),logicalPath:rebase(t.logicalPath)}}))},disabledToolTargets:_}}function describeExtensionSource(e,t,n){return e===`override`?`The override "agent/extensions/${t}/${n}"`:`The "${t}" extension's "${n}"`}function mergeContributions(e,t){let n=new Set(e.channels.map(e=>e.name));return{channels:[...e.channels,...t.channels.filter(e=>!n.has(e.name))],tools:dedupeBy([...e.tools,...t.tools],e=>e.name),dynamicTools:dedupeBy([...e.dynamicTools,...t.dynamicTools],e=>e.slug),connections:dedupeBy([...e.connections,...t.connections],e=>e.connectionName),skills:dedupeBy([...e.skills,...t.skills],e=>e.name),schedules:dedupeBy([...e.schedules,...t.schedules],e=>e.name),hooks:[...e.hooks,...t.hooks],dynamicSkills:[...e.dynamicSkills,...t.dynamicSkills],dynamicInstructions:[...e.dynamicInstructions,...t.dynamicInstructions],instructions:[...e.instructions,...t.instructions]}}function dedupeBy(e,t){let n=new Set,r=[];for(let i of e){let e=t(i);n.has(e)||(n.add(e),r.push(i))}return r}export{applyOverrideDisables,compileExtensionContributions,composeAgentSubagentSources,composeExtensionSubagentSources,mergeContributions,mergeExtensionSubagentSources};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{compileChannelDefinition}from"#compiler/normalize-channel.js";import{ROOT_COMPILED_AGENT_NODE_ID,createCompiledAgentManifest,createCompiledAgentNodeManifest,createCompiledAgentResources}from"#compiler/manifest.js";import{compileConnectionDefinition}from"#compiler/normalize-connection.js";import{compileHookEntry}from"#compiler/normalize-hook.js";import{compileInstructionsEntry}from"#compiler/normalize-instructions.js";import{compileScheduleDefinition}from"#compiler/normalize-schedule.js";import{compileSkillSource}from"#compiler/normalize-skill.js";import{compileToolEntry}from"#compiler/normalize-tool.js";import{mountRefNamespace,packageStateNamespace}from"#discover/extensions.js";import{createCompiledRuntimeModelCatalogLoader}from"#compiler/model-catalog.js";import{compileAgentConfig}from"#compiler/normalize-agent-config.js";import{compileExtensionContributions}from"#compiler/normalize-extension.js";import{compileSandboxDefinition}from"#compiler/normalize-sandbox.js";import{compileSubagentGraph}from"#compiler/normalize-subagent.js";async function compileAgentManifest(e){let r={modelCatalog:createCompiledRuntimeModelCatalogLoader(e.appRoot)},i=await compileAgentNodeManifest(e,r),a=await compileSubagentGraph({appRoot:e.appRoot,compileAgentNodeManifest,compileAgentResources,context:r,externalDependencies:i.config.build?.externalDependencies??[],parentNodeId:ROOT_COMPILED_AGENT_NODE_ID,subagents:e
|
|
1
|
+
import{compileChannelDefinition}from"#compiler/normalize-channel.js";import{ROOT_COMPILED_AGENT_NODE_ID,createCompiledAgentManifest,createCompiledAgentNodeManifest,createCompiledAgentResources}from"#compiler/manifest.js";import{compileConnectionDefinition}from"#compiler/normalize-connection.js";import{compileHookEntry}from"#compiler/normalize-hook.js";import{compileInstructionsEntry}from"#compiler/normalize-instructions.js";import{compileScheduleDefinition}from"#compiler/normalize-schedule.js";import{compileSkillSource}from"#compiler/normalize-skill.js";import{compileToolEntry}from"#compiler/normalize-tool.js";import{mountRefNamespace,packageStateNamespace}from"#discover/extensions.js";import{createCompiledRuntimeModelCatalogLoader}from"#compiler/model-catalog.js";import{compileAgentConfig}from"#compiler/normalize-agent-config.js";import{compileExtensionContributions,composeAgentSubagentSources}from"#compiler/normalize-extension.js";import{compileSandboxDefinition}from"#compiler/normalize-sandbox.js";import{compileSubagentGraph}from"#compiler/normalize-subagent.js";async function compileAgentManifest(e){let r={modelCatalog:createCompiledRuntimeModelCatalogLoader(e.appRoot)},i=await compileAgentNodeManifest(e,r),a=await compileSubagentGraph({appRoot:e.appRoot,compileAgentNodeManifest,compileAgentResources,context:r,externalDependencies:i.config.build?.externalDependencies??[],parentAgentRoot:e.agentRoot,parentNodeId:ROOT_COMPILED_AGENT_NODE_ID,subagents:composeAgentSubagentSources(e)});return createCompiledAgentManifest({...i,extensionMounts:i.extensionMounts,remoteAgents:a.remoteAgents,subagentEdges:a.edges,subagents:a.nodes})}async function compileAgentNodeManifest(e,t,n={}){let i=Object.hasOwn(n,`agentConfigDefinition`)?await compileAgentConfig(e,t,{definition:n.agentConfigDefinition}):await compileAgentConfig(e,t);if(n.allowRootOnlyConfig===!1&&i.experimental?.workflow!==void 0)throw Error(`Workflow runtime configuration is only supported on the root agent config. Remove "experimental.workflow" from "${e.agentId}".`);if(n.allowRootOnlyConfig===!1&&i.experimental?.tasks!==void 0)throw Error(`Background tasks are only supported on the root agent config. Remove "experimental.tasks" from "${e.agentId}".`);let a=mergeExternalDependencies(n.externalDependencies,i.build?.externalDependencies),o=a.length===0?i:{...i,build:{...i.build,externalDependencies:a}};return createCompiledAgentNodeManifest({...await compileAgentResources(e,t,{externalDependencies:a}),config:o})}async function compileAgentResources(t,n,r={}){let s=[...r.externalDependencies??[]],c=await Promise.all(t.tools.map(e=>compileToolEntry(t.agentRoot,e,{externalDependencies:s}))),l=[],u=[],d=[],f,p;for(let e of c)e.kind===`tool`?l.push(e.definition):e.kind===`dynamic-tool`?u.push(e.definition):e.kind===`workflow-tool`?f={maxSubagents:e.maxSubagents}:e.kind===`web-search-tool`?p=e.provider:d.push(e.name);let m=(await Promise.all(t.channels.map(n=>compileChannelDefinition(t.agentRoot,n,{externalDependencies:s})))).flat(),h=await Promise.all(t.skills.map(e=>compileSkillSource(t.agentRoot,e,{externalDependencies:s}))),g=[],_=[];for(let e of h)e.kind===`skill`?g.push(e.definition):_.push(e.definition);let v=await Promise.all(t.instructions.map(e=>compileInstructionsEntry(t.agentRoot,e,{externalDependencies:s}))),y=[],b=[];for(let e of v)e.kind===`instructions`?y.push(e.definition):b.push(e.definition);let x=await Promise.all(t.connections.map(e=>compileConnectionDefinition(t.agentRoot,e,{externalDependencies:s}))),S=t.hooks.map(e=>compileHookEntry(e)),C=await Promise.all(t.schedules.map(e=>compileScheduleDefinition(t.agentRoot,e,{externalDependencies:s}))),w=new Set(l.map(e=>e.name)),T=new Set(u.map(e=>e.slug)),E=new Set(x.map(e=>e.connectionName)),D=new Set(g.map(e=>e.name)),O=[];for(let e of[...t.resolvedExtensions].sort((e,t)=>e.namespace.localeCompare(t.namespace))){let r=await compileExtensionContributions({mount:e,context:n,consumerAgentRoot:t.agentRoot,externalDependencies:s});m.push(...r.channels);for(let e of r.tools)w.has(e.name)||(w.add(e.name),l.push(e));for(let e of r.dynamicTools)T.has(e.slug)||(T.add(e.slug),u.push(e));for(let e of r.connections)E.has(e.connectionName)||(E.add(e.connectionName),x.push(e));for(let e of r.skills)D.has(e.name)||(D.add(e.name),g.push(e));C.push(...r.schedules),S.push(...r.hooks),_.push(...r.dynamicSkills),b.push(...r.dynamicInstructions),O.push(...r.instructions)}let k=[...y,...O];return createCompiledAgentResources({agentRoot:t.agentRoot,appRoot:t.appRoot,channels:m,extensionMounts:compileExtensionMounts(t),connections:x,diagnosticsSummary:t.diagnosticsSummary,disabledFrameworkTools:d,workflowTool:f,webSearchProvider:p,dynamicSkills:_,dynamicTools:u,hooks:S,sandbox:t.sandbox===null?null:await compileSandboxDefinition(t.agentRoot,t.sandbox,{externalDependencies:s}),sandboxWorkspaces:t.sandboxWorkspaces.map(e=>({logicalPath:e.logicalPath,rootEntries:[...e.rootEntries],sourceId:e.sourceId,sourcePath:e.sourcePath})),schedules:C,dynamicInstructions:b,skills:g,instructions:k,tools:l})}function compileExtensionMounts(e){return e.resolvedExtensions.map(t=>{let n=e.extensions.find(e=>mountRefNamespace(e.logicalPath)===t.namespace);return{namespace:t.namespace,packageName:t.packageName,packageNamespace:packageStateNamespace(t.packageName),sourceRoot:t.sourceRoot,mountSourceId:n?.sourceId??`extensions/${t.namespace}`,mountLogicalPath:n?.logicalPath??`extensions/${t.namespace}`}})}function mergeExternalDependencies(...e){let t=new Set;for(let n of e)for(let e of n??[])t.add(e);return[...t]}export{compileAgentManifest};
|
|
@@ -29,6 +29,7 @@ export declare function compileSubagentGraph(input: {
|
|
|
29
29
|
readonly compileAgentResources: CompileAgentResourcesFn;
|
|
30
30
|
readonly context: ManifestCompileContext;
|
|
31
31
|
readonly externalDependencies?: readonly string[];
|
|
32
|
+
readonly parentAgentRoot: string;
|
|
32
33
|
readonly parentNodeId: string;
|
|
33
34
|
readonly subagents: readonly LocalSubagentSourceRef[];
|
|
34
35
|
}): Promise<{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{expectBoolean,expectFunction,expectObjectRecord,expectOnlyKnownKeys,expectString}from"#internal/authored-module.js";import{EVE_SESSION_ROUTE_PATH}from"#protocol/routes.js";import{serializeOutputSchema}from"#shared/tool-schema.js";import{createCompiledSubagentNodeId}from"#compiler/manifest.js";import{loadModuleBackedDefinition}from"#compiler/normalize-helpers.js";import{isDynamicSentinel}from"#shared/dynamic-tool-definition.js";import{
|
|
1
|
+
import{expectBoolean,expectFunction,expectObjectRecord,expectOnlyKnownKeys,expectString}from"#internal/authored-module.js";import{EVE_SESSION_ROUTE_PATH}from"#protocol/routes.js";import{join,relative}from"node:path";import{serializeOutputSchema}from"#shared/tool-schema.js";import{createCompiledSubagentNodeId}from"#compiler/manifest.js";import{loadModuleBackedDefinition}from"#compiler/normalize-helpers.js";import{createPathDerivedSourceId}from"#discover/manifest.js";import{isDynamicSentinel}from"#shared/dynamic-tool-definition.js";import{composeAgentSubagentSources}from"#compiler/normalize-extension.js";const ALLOWED_DYNAMIC_SUBAGENT_EVENTS=new Set([`session.started`,`turn.started`]);async function compileSubagentGraph(e){let t=[],n=[],r=[];for(let i of e.subagents){let a=await compileSubagentDefinition({appRoot:e.appRoot,compileAgentNodeManifest:e.compileAgentNodeManifest,compileAgentResources:e.compileAgentResources,context:e.context,externalDependencies:e.externalDependencies,parentAgentRoot:e.parentAgentRoot,parentNodeId:e.parentNodeId,source:i});if(a.kind===`remote`){r.push(a.node);continue}t.push(a.node,...a.descendants.nodes),n.push({childNodeId:a.node.nodeId,parentNodeId:e.parentNodeId},...a.descendants.edges)}return{edges:n,nodes:t,remoteAgents:r}}async function compileSubagentDefinition(e){let t=e.source.manifest.configModule;if(t===void 0)throw Error(`Subagent "${e.source.logicalPath}" is missing an agent config module.`);let n=createSubagentConfigModuleSourceRef(e.source,t,e.parentAgentRoot),r=await loadModuleBackedDefinition({agentRoot:e.source.manifest.agentRoot,displayPath:n.logicalPath,externalDependencies:e.externalDependencies,kind:`subagent config`,source:t}),i=normalizeDynamicSubagentDefinition(r,`Expected the dynamic subagent config export "${t.exportName??`default`}" from "${n.logicalPath}" to match the public eve shape.`);return i===void 0&&readAgentDefinitionKind(r)===`remote`?{kind:`remote`,node:compileRemoteAgent({parentAgentRoot:e.parentAgentRoot,source:e.source,value:r})}:{kind:`local`,...await compileLocalSubagent({...e,agentConfigDefinition:i===void 0?r:void 0,configResolver:i===void 0?void 0:{...t,...i.definition,build:i.build}})}}async function compileSubagent(e){let t=createCompiledSubagentNodeId(e.parentNodeId,e.source.sourceId),n=e.source.subagentId,r={...e.source.manifest,appRoot:e.appRoot},i=mergeExternalDependencies(e.externalDependencies,e.configResolver?.build?.externalDependencies),a={entryPath:e.source.entryPath,logicalPath:e.source.logicalPath,name:n,nodeId:t,rootPath:e.source.rootPath,sourceId:e.source.sourceId,sourceKind:`module`};if(e.configResolver===void 0){let n=await e.compileAgentNodeManifest(r,e.context,{agentConfigDefinition:e.agentConfigDefinition,allowRootOnlyConfig:!1,externalDependencies:i}),o=n.config.description;if(!o)throw Error(`Local subagent "${e.source.logicalPath}" is missing a "description" field on its agent config. Add \`description\` to \`defineAgent({ ... })\` so the parent agent can decide when to delegate to this subagent.`);let s=await compileSubagentGraph({appRoot:e.appRoot,compileAgentNodeManifest:e.compileAgentNodeManifest,context:e.context,compileAgentResources:e.compileAgentResources,externalDependencies:n.config.build?.externalDependencies??i,parentAgentRoot:e.source.manifest.agentRoot,parentNodeId:t,subagents:composeAgentSubagentSources(e.source.manifest)});return{descendants:s,node:{...a,agent:{...n,remoteAgents:[...s.remoteAgents]},description:o}}}let o=await e.compileAgentResources(r,e.context,{externalDependencies:i}),s=await compileSubagentGraph({appRoot:e.appRoot,compileAgentNodeManifest:e.compileAgentNodeManifest,context:e.context,compileAgentResources:e.compileAgentResources,externalDependencies:i,parentAgentRoot:e.source.manifest.agentRoot,parentNodeId:t,subagents:composeAgentSubagentSources(e.source.manifest)});return{descendants:s,node:{...a,agent:{...o,remoteAgents:[...s.remoteAgents]},configResolver:e.configResolver}}}const compileLocalSubagent=compileSubagent;function compileRemoteAgent(e){let t=e.source.manifest.configModule;if(t===void 0)throw Error(`Remote agent "${e.source.logicalPath}" is missing a config module.`);assertRemoteAgentDefinitionHasNoLocalPackageEntries(e.source);let n=createSubagentConfigModuleSourceRef(e.source,t,e.parentAgentRoot),r=normalizeRemoteAgentDefinition(e.value,`Expected the remote agent config export "${t.exportName??`default`}" from "${n.logicalPath}" to match the public eve shape.`),i={...n,description:r.description,entryPath:e.source.entryPath,name:e.source.subagentId,nodeId:e.source.sourceId,outputSchema:r.outputSchema,path:r.path,rootPath:e.source.rootPath};return r.url===void 0?i:{...i,url:r.url}}function normalizeDynamicSubagentDefinition(e,i){if(!isDynamicSentinel(e))return;let a=expectObjectRecord(e,i);expectOnlyKnownKeys(a,[`build`,`events`,`kind`],i);let o=a.build===void 0?void 0:normalizeDynamicSubagentBuild(a.build,i),s=expectObjectRecord(a.events,i),c=[];for(let[e,n]of Object.entries(s)){if(!ALLOWED_DYNAMIC_SUBAGENT_EVENTS.has(e))throw Error(`${i} Dynamic subagents support only "session.started" and "turn.started" handlers.`);expectFunction(n,i),c.push(e)}let l={definition:{eventNames:c}};return o!==void 0&&(l.build=o),l}function normalizeDynamicSubagentBuild(e,t){let a=expectObjectRecord(e,t);if(expectOnlyKnownKeys(a,[`externalDependencies`],t),a.externalDependencies===void 0)return{};if(!Array.isArray(a.externalDependencies))throw Error(t);return{externalDependencies:a.externalDependencies.map(e=>expectString(e,t))}}function mergeExternalDependencies(...e){return[...new Set(e.flatMap(e=>e??[]))]}function createSubagentConfigModuleSourceRef(e,t,n){let r=relative(n,join(e.manifest.agentRoot,t.logicalPath)).replaceAll(`\\`,`/`),i={logicalPath:r,sourceId:t.sourceId.startsWith(`ext:`)||t.sourceId.startsWith(`ext-override:`)?t.sourceId:createPathDerivedSourceId(r),sourceKind:`module`};return t.exportName!==void 0&&(i.exportName=t.exportName),i}function readAgentDefinitionKind(e){return typeof e!=`object`||!e?`local`:e.kind===`remote`?`remote`:`local`}function normalizeRemoteAgentDefinition(t,o){let s=expectObjectRecord(t,o);if(expectOnlyKnownKeys(s,[`auth`,`description`,`forwardPrincipal`,`headers`,`kind`,`outputSchema`,`path`,`url`],o),s.kind!==`remote`)throw Error(`${o} Expected "kind" to be "remote".`);return s.forwardPrincipal!==void 0&&expectBoolean(s.forwardPrincipal,`${o} Expected "forwardPrincipal" to be a boolean.`),{description:expectString(s.description,o),outputSchema:serializeOutputSchema(s.outputSchema),path:s.path===void 0?EVE_SESSION_ROUTE_PATH:expectString(s.path,o),url:typeof s.url==`function`?void 0:expectString(s.url,o)}}function assertRemoteAgentDefinitionHasNoLocalPackageEntries(e){let t=e.manifest,n=[t.connections.length>0?`connections/`:void 0,t.hooks.length>0?`hooks/`:void 0,t.instructions.length>0?`instructions`:void 0,t.lib.length>0?`lib/`:void 0,t.sandbox===null?void 0:`sandbox/`,t.sandboxWorkspaces.length>0?`sandbox/workspace/`:void 0,t.schedules.length>0?`schedules/`:void 0,t.skills.length>0?`skills/`:void 0,t.subagents.length>0?`subagents/`:void 0,t.tools.length>0?`tools/`:void 0].filter(e=>e!==void 0);if(n.length!==0)throw Error(`Remote subagent definition "${e.logicalPath}" cannot include local package entries. Remove unsupported entries: ${n.join(`, `)}.`)}export{compileSubagentGraph};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{join,resolve}from"node:path";import{createDiscoverErrorDiagnostic}from"#discover/diagnostics.js";import{SUPPORTED_AUTHORED_MODULE_FILE_EXTENSIONS,classifyAgentRootEntry,normalizeLogicalPath}from"#discover/filesystem.js";import{createDiskProjectSource}from"#discover/project-source.js";import{DISCOVER_EXTENSION_AGENT_CONFIG_UNSUPPORTED,DISCOVER_EXTENSION_MOUNT_AMBIGUOUS,DISCOVER_EXTENSION_MOUNT_MISSING_DECLARATION,DISCOVER_EXTENSION_NESTED_MOUNT_UNSUPPORTED,DISCOVER_EXTENSION_OVERRIDE_OUTSIDE_MOUNT,DISCOVER_EXTENSION_SANDBOX_UNSUPPORTED,locateExtensionMount,mountNamespace}from"#discover/extensions.js";import{
|
|
1
|
+
import{join,resolve}from"node:path";import{createDiscoverErrorDiagnostic}from"#discover/diagnostics.js";import{SUPPORTED_AUTHORED_MODULE_FILE_EXTENSIONS,classifyAgentRootEntry,normalizeLogicalPath}from"#discover/filesystem.js";import{createDiskProjectSource}from"#discover/project-source.js";import{createAgentSourceManifest,createModuleSourceRef}from"#discover/manifest.js";import{DISCOVER_EXTENSION_AGENT_CONFIG_UNSUPPORTED,DISCOVER_EXTENSION_MOUNT_AMBIGUOUS,DISCOVER_EXTENSION_MOUNT_MISSING_DECLARATION,DISCOVER_EXTENSION_NESTED_MOUNT_UNSUPPORTED,DISCOVER_EXTENSION_OVERRIDE_OUTSIDE_MOUNT,DISCOVER_EXTENSION_SANDBOX_UNSUPPORTED,locateExtensionMount,mountNamespace}from"#discover/extensions.js";import{DISCOVER_CHANNELS_DIRECTORY_INVALID,DISCOVER_EXTENSIONS_DIRECTORY_INVALID,DISCOVER_HOOKS_DIRECTORY_INVALID,DISCOVER_TOOLS_DIRECTORY_INVALID,createChannelNameDiagnostic,createExtensionNameDiagnostic,createHookNameDiagnostic,createToolNameDiagnostic,createUnsupportedRootDirectoryDiagnostics,discoverFlatModuleSource,discoverInstructionsSource,discoverNamedSourceDirectory,readSortedDirectoryEntries}from"#discover/grammar.js";import{discoverConnectionSources}from"#discover/connections.js";import{discoverSubagents}from"#discover/discover-subagent.js";import{discoverLibSources}from"#discover/lib.js";import{discoverSandboxSource}from"#discover/sandbox.js";import{discoverScheduleSources}from"#discover/schedules.js";import{discoverSkills}from"#discover/skills.js";import{stripNpmPackageScope}from"#shared/package-name.js";async function discoverAgent(r){let a=r.source??createDiskProjectSource(),c=resolve(r.appRoot),u=resolve(r.agentRoot),d=r.role??`agent`,p=[],h=await tryReadPackageJsonName(a,c),g=await readSortedDirectoryEntries(a,u);p.push(...createUnsupportedRootDirectoryDiagnostics({classifyEntry:classifyAgentRootEntry,createUnsupportedDirectoryMessage(e){return`Ignoring unsupported directory "${e}/" in the agent root.`},rootEntries:g,rootPath:u}));let _=await discoverInstructionsSource({rootEntries:g,rootPath:u,source:a,required:d!==`extension`});p.push(..._.diagnostics);let v=discoverFlatModuleSource({rootEntries:g,rootPath:u,slotName:`agent`});p.push(...v.diagnostics);let y=await discoverNamedSourceDirectory({directoryName:`channels`,invalidDirectoryCode:DISCOVER_CHANNELS_DIRECTORY_INVALID,invalidDirectoryMessage:`Expected "${join(u,`channels`)}" to be a directory of authored channels.`,recursive:!0,rootEntries:g,rootPath:u,source:a,validateSegment:createChannelNameDiagnostic});p.push(...y.diagnostics);let b=await discoverLibSources({agentRoot:u,rootEntries:g,source:a});p.push(...b.diagnostics);let x=await discoverScheduleSources({agentRoot:u,rootEntries:g,source:a});p.push(...x.diagnostics);let S=await discoverConnectionSources({rootEntries:g,rootPath:u,source:a});p.push(...S.diagnostics);let C=await discoverSandboxSource({rootEntries:g,rootPath:u,source:a});p.push(...C.diagnostics),d===`extension`&&(v.module!==void 0&&p.push(createDiscoverErrorDiagnostic({code:DISCOVER_EXTENSION_AGENT_CONFIG_UNSUPPORTED,message:`An extension may not declare agent config (agent.ts) — model, limits, and sandbox are the consuming agent's to own.`,sourcePath:join(u,v.module.logicalPath)})),C.sandbox!==null&&p.push(createDiscoverErrorDiagnostic({code:DISCOVER_EXTENSION_SANDBOX_UNSUPPORTED,message:`An extension may not declare a sandbox — it is the consuming agent's to own.`,sourcePath:join(u,C.sandbox.logicalPath)})));let w=await discoverNamedSourceDirectory({directoryName:`tools`,invalidDirectoryCode:DISCOVER_TOOLS_DIRECTORY_INVALID,invalidDirectoryMessage:`Expected "${join(u,`tools`)}" to be a directory of authored tools.`,recursive:!0,rootEntries:g,rootPath:u,source:a,validateSegment:createToolNameDiagnostic});p.push(...w.diagnostics);let T=await discoverNamedSourceDirectory({directoryName:`hooks`,invalidDirectoryCode:DISCOVER_HOOKS_DIRECTORY_INVALID,invalidDirectoryMessage:`Expected "${join(u,`hooks`)}" to be a directory of authored hooks.`,recursive:!0,rootEntries:g,rootPath:u,source:a,validateSegment:createHookNameDiagnostic});p.push(...T.diagnostics);let E=await discoverNamedSourceDirectory({directoryName:`extensions`,invalidDirectoryCode:DISCOVER_EXTENSIONS_DIRECTORY_INVALID,invalidDirectoryMessage:`Expected "${join(u,`extensions`)}" to be a directory of extension mounts.`,recursive:!1,rootEntries:g,rootPath:u,source:a,validateSegment:createExtensionNameDiagnostic});p.push(...E.diagnostics);let D=await discoverSkills({agentRoot:u,source:a});p.push(...D.diagnostics);let O=await discoverSubagents({agentRoot:u,appRoot:c,source:a});p.push(...O.diagnostics);let k=await collectExtensionMounts({agentRoot:u,fileMounts:E.sources,rootEntries:g,source:a});p.push(...k.diagnostics),p.push(...detectRootNamespaceCollisions({agentRoot:u,namespaces:k.mounts.map(e=>e.namespace),sources:[...w.sources,...S.connections,...D.skills,...x.schedules,...O.subagents]}));let A=[];if(d!==`agent`)for(let t of k.mounts)p.push(createDiscoverErrorDiagnostic({code:DISCOVER_EXTENSION_NESTED_MOUNT_UNSUPPORTED,message:`"${t.mountRef.logicalPath}" mounts an extension from inside an extension, which is not supported yet. Extensions cannot mount other extensions; remove the "extensions/" slot.`,sourcePath:join(u,t.mountRef.logicalPath)}));else{let e=await resolveExtensionMounts({agentRoot:u,appRoot:c,mounts:k.mounts,source:a});p.push(...e.diagnostics),A=e.mounts}let j={agentRoot:u,appRoot:c,channels:y.sources,connections:S.connections,packageName:h,diagnostics:p,extensions:k.mounts.map(e=>e.mountRef),resolvedExtensions:A,hooks:T.sources,lib:b.lib,instructions:_.instructions,sandbox:C.sandbox,sandboxWorkspaces:C.sandboxWorkspace===null?[]:[C.sandboxWorkspace],schedules:x.schedules,skills:D.skills,tools:w.sources,subagents:O.subagents};return v.module!==void 0&&(j.configModule=v.module),{diagnostics:p,manifest:createAgentSourceManifest(j)}}async function resolveExtensionMounts(e){let t=[],n=[];for(let r of e.mounts){let i=await locateExtensionMount({source:e.source,agentRoot:e.agentRoot,appRoot:e.appRoot,mount:r.mountRef,namespace:r.namespace});if(t.push(...i.diagnostics),i.location===void 0)continue;let a=await discoverAgent({agentRoot:i.location.sourceRoot,appRoot:i.location.packageRoot,source:e.source,role:`extension`});t.push(...a.diagnostics);let o;if(r.overridesRoot!==void 0){let n=await discoverAgent({agentRoot:r.overridesRoot,appRoot:e.appRoot,source:e.source,role:`extension`});t.push(...n.diagnostics),o=n.manifest}n.push({namespace:i.location.namespace,specifier:i.location.specifier,packageName:i.location.packageName,packageRoot:i.location.packageRoot,sourceRoot:i.location.sourceRoot,manifest:a.manifest,overrides:o})}return{diagnostics:t,mounts:n}}async function discoverExtensionMountDeclarations(n){let r=n.source??createDiskProjectSource(),i=resolve(n.agentRoot),a=await readSortedDirectoryEntries(r,i),s=await discoverNamedSourceDirectory({directoryName:`extensions`,invalidDirectoryCode:DISCOVER_EXTENSIONS_DIRECTORY_INVALID,invalidDirectoryMessage:`Expected "${join(i,`extensions`)}" to be a directory of extension mounts.`,recursive:!1,rootEntries:a,rootPath:i,source:r,validateSegment:createExtensionNameDiagnostic}),c=await collectExtensionMounts({agentRoot:i,fileMounts:s.sources,rootEntries:a,source:r});return{diagnostics:[...s.diagnostics,...c.diagnostics],mounts:c.mounts}}async function collectExtensionMounts(t){let r=[],i=join(t.agentRoot,`extensions`),o=t.fileMounts.map(e=>({namespace:mountNamespace(e.logicalPath),mountRef:e})),s=new Set(o.map(e=>e.namespace)),l=t.rootEntries.find(e=>e.name===`extensions`),f=[],p=new Set;if(l?.isDirectory()===!0){let o=await readSortedDirectoryEntries(t.source,i);for(let l of o){if(!l.isDirectory())continue;let o=l.name,u=join(i,o),m=createExtensionNameDiagnostic(o,u);if(m!==null){r.push(m);continue}let h=discoverFlatModuleSource({rootEntries:await readSortedDirectoryEntries(t.source,u),rootPath:u,slotName:`extension`});if(r.push(...h.diagnostics),h.module===void 0){r.push(createDiscoverErrorDiagnostic({code:DISCOVER_EXTENSION_MOUNT_MISSING_DECLARATION,message:`Extension mount directory "extensions/${o}/" must declare its mount in "extension.ts" (or another supported module extension).`,sourcePath:u}));continue}s.has(o)&&p.add(o),f.push({namespace:o,mountRef:createModuleSourceRef({logicalPath:normalizeLogicalPath(join(`extensions`,o,h.module.logicalPath))}),overridesRoot:u})}}for(let e of p)r.push(createDiscoverErrorDiagnostic({code:DISCOVER_EXTENSION_MOUNT_AMBIGUOUS,message:`Extension namespace "${e}" is claimed by both a file mount ("extensions/${e}.ts") and a directory mount ("extensions/${e}/"). Keep only one.`,sourcePath:i}));return{diagnostics:r,mounts:[...o,...f].filter(e=>!p.has(e.namespace))}}function detectRootNamespaceCollisions(t){if(t.namespaces.length===0)return[];let r=[];for(let i of t.sources){let a=rootContributionName(i.logicalPath),o=t.namespaces.find(e=>a.startsWith(`${e}__`));o!==void 0&&r.push(createDiscoverErrorDiagnostic({code:DISCOVER_EXTENSION_OVERRIDE_OUTSIDE_MOUNT,message:`"${i.logicalPath}" uses the "${o}__" prefix reserved for the mounted extension "${o}". Override an extension's contributions inside its mount directory ("extensions/${o}/…"), not at the agent root.`,sourcePath:join(t.agentRoot,i.logicalPath)}))}return r}function rootContributionName(e){let t=e.slice(e.indexOf(`/`)+1),n=t.split(`/`)[0]??t;for(let e of SUPPORTED_AUTHORED_MODULE_FILE_EXTENSIONS)if(n.toLowerCase().endsWith(e))return n.slice(0,n.length-e.length);return n}async function tryReadPackageJsonName(t,n){try{let r=join(n,`package.json`),i=JSON.parse(await t.readTextFile(r)).name;return typeof i!=`string`||i.length===0?void 0:stripNpmPackageScope(i)}catch{return}}export{detectRootNamespaceCollisions,discoverAgent,discoverExtensionMountDeclarations,resolveExtensionMounts};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{join,relative,resolve}from"node:path";import{detectRootNamespaceCollisions,discoverExtensionMountDeclarations,resolveExtensionMounts}from"#discover/discover-agent.js";import{createDiscoverErrorDiagnostic}from"#discover/diagnostics.js";import{classifyLocalSubagentEntry,getDirectoryEntryType,getSupportedModuleBaseName,normalizeLogicalPath}from"#discover/filesystem.js";import{createDiskProjectSource}from"#discover/project-source.js";import{createAgentSourceManifest,createLocalSubagentSourceRef,createModuleSourceRef}from"#discover/manifest.js";import{DISCOVER_HOOKS_DIRECTORY_INVALID,DISCOVER_TOOLS_DIRECTORY_INVALID,createHookNameDiagnostic,createToolNameDiagnostic,createUnsupportedRootDirectoryDiagnostics,discoverFlatModuleSource,discoverInstructionsSource,discoverNamedSourceDirectory,readSortedDirectoryEntries}from"#discover/grammar.js";import{discoverConnectionSources}from"#discover/connections.js";import{discoverLibSources}from"#discover/lib.js";import{discoverSandboxSource}from"#discover/sandbox.js";import{discoverSkills}from"#discover/skills.js";const DISCOVER_LOCAL_SUBAGENT_SCHEDULES_INVALID=`discover/local-subagent-schedules-invalid`,DISCOVER_REQUIRED_SUBAGENT_CONFIG_MODULE_MISSING=`discover/required-subagent-config-module-missing`,DISCOVER_SUBAGENTS_DIRECTORY_INVALID=`discover/subagents-directory-invalid`;async function discoverSubagents(r){let i=r.source??createDiskProjectSource(),a=resolve(r.agentRoot),s=resolve(r.subagentsDirectoryPath??join(a,`subagents`)),c=normalizeLogicalPath(r.subagentsLogicalPath??relative(a,s)),f=await i.stat(s);if(f===`missing`)return{diagnostics:[],subagents:[]};if(f!==`directory`)return{diagnostics:[createDiscoverErrorDiagnostic({code:DISCOVER_SUBAGENTS_DIRECTORY_INVALID,message:`Expected "${s}" to be a directory of authored subagents.`,sourcePath:s})],subagents:[]};let p=await readSortedDirectoryEntries(i,s),m=[],h=[];for(let t of p){if(t.isFile()){let n=getSupportedModuleBaseName(t.name);if(n===null)continue;h.push(discoverSingleFileSubagent({agentRoot:a,appRoot:r.appRoot,subagentId:n,subagentLogicalPath:join(c,t.name),subagentPath:join(s,t.name)}));continue}if(!t.isDirectory())continue;let n=await discoverLocalSubagentPackage({appRoot:r.appRoot,source:i,subagentId:t.name,subagentLogicalPath:join(c,t.name),subagentRoot:join(s,t.name)});m.push(...n.diagnostics),h.push(n.subagent)}return{diagnostics:m,subagents:h}}function discoverSingleFileSubagent(e){let t=createModuleSourceRef({logicalPath:e.subagentLogicalPath}),n=createAgentSourceManifest({agentId:e.subagentId,agentRoot:e.agentRoot,appRoot:e.appRoot,configModule:t});return createLocalSubagentSourceRef({entryPath:e.subagentPath,logicalPath:e.subagentLogicalPath,manifest:n,rootPath:e.agentRoot,subagentId:e.subagentId})}async function discoverLocalSubagentPackage(t){let n=[],o=await readSortedDirectoryEntries(t.source,t.subagentRoot);n.push(...createUnsupportedRootDirectoryDiagnostics({classifyEntry:classifyLocalSubagentEntry,createUnsupportedDirectoryMessage(e){return`Ignoring unsupported directory "${e}/" in the local subagent root.`},rootEntries:o,rootPath:t.subagentRoot}));let c=await discoverInstructionsSource({required:!1,rootEntries:o,rootPath:t.subagentRoot,source:t.source});n.push(...c.diagnostics);let l=discoverFlatModuleSource({missingDiagnostic:{code:DISCOVER_REQUIRED_SUBAGENT_CONFIG_MODULE_MISSING,message:`Expected one authored subagent config module at "agent.ts", "agent.cts", "agent.mts", "agent.js", "agent.cjs", or "agent.mjs".`},rootEntries:o,rootPath:t.subagentRoot,slotName:`agent`});n.push(...l.diagnostics);let u=await discoverConnectionSources({rootEntries:o,rootPath:t.subagentRoot,source:t.source});n.push(...u.diagnostics);let d=await discoverSandboxSource({rootEntries:o,rootPath:t.subagentRoot,source:t.source});n.push(...d.diagnostics);let m=await discoverNamedSourceDirectory({directoryName:`tools`,invalidDirectoryCode:DISCOVER_TOOLS_DIRECTORY_INVALID,invalidDirectoryMessage:`Expected "${join(t.subagentRoot,`tools`)}" to be a directory of authored tools.`,recursive:!0,rootEntries:o,rootPath:t.subagentRoot,source:t.source,validateSegment:createToolNameDiagnostic});n.push(...m.diagnostics);let g=await discoverNamedSourceDirectory({directoryName:`hooks`,invalidDirectoryCode:DISCOVER_HOOKS_DIRECTORY_INVALID,invalidDirectoryMessage:`Expected "${join(t.subagentRoot,`hooks`)}" to be a directory of authored hooks.`,recursive:!0,rootEntries:o,rootPath:t.subagentRoot,source:t.source,validateSegment:createHookNameDiagnostic});n.push(...g.diagnostics);let _=await discoverLibSources({agentRoot:t.subagentRoot,rootEntries:o,source:t.source});n.push(..._.diagnostics),n.push(...createLocalSubagentScheduleDiagnostics(t.subagentRoot,o));let v=await discoverSkills({agentRoot:t.subagentRoot,source:t.source});n.push(...v.diagnostics);let y=await discoverSubagents({agentRoot:t.subagentRoot,appRoot:t.appRoot,source:t.source});n.push(...y.diagnostics);let b=await discoverExtensionMountDeclarations({agentRoot:t.subagentRoot,source:t.source});n.push(...b.diagnostics),n.push(...detectRootNamespaceCollisions({agentRoot:t.subagentRoot,namespaces:b.mounts.map(e=>e.namespace),sources:[...m.sources,...u.connections,...v.skills]}));let x=await resolveExtensionMounts({agentRoot:t.subagentRoot,appRoot:t.appRoot,mounts:b.mounts,source:t.source});n.push(...x.diagnostics);let S={agentRoot:t.subagentRoot,appRoot:t.appRoot,connections:u.connections,diagnostics:n,extensions:b.mounts.map(e=>e.mountRef),resolvedExtensions:x.mounts,hooks:g.sources,lib:_.lib,instructions:c.instructions,sandbox:d.sandbox,sandboxWorkspaces:d.sandboxWorkspace===null?[]:[d.sandboxWorkspace],skills:v.skills,tools:m.sources,subagents:y.subagents};l.module!==void 0&&(S.configModule=l.module);let C=createAgentSourceManifest(S);return{diagnostics:n,subagent:createLocalSubagentSourceRef({entryPath:t.subagentRoot,logicalPath:t.subagentLogicalPath,manifest:C,rootPath:t.subagentRoot,subagentId:t.subagentId})}}function createLocalSubagentScheduleDiagnostics(t,n){return n.flatMap(n=>classifyLocalSubagentEntry(n.name,getDirectoryEntryType(n))===`invalid-schedules-directory`?[createDiscoverErrorDiagnostic({code:DISCOVER_LOCAL_SUBAGENT_SCHEDULES_INVALID,message:`Local subagent packages cannot define schedules at "${join(t,n.name)}".`,sourcePath:join(t,n.name)})]:[])}export{DISCOVER_LOCAL_SUBAGENT_SCHEDULES_INVALID,DISCOVER_REQUIRED_SUBAGENT_CONFIG_MODULE_MISSING,DISCOVER_SUBAGENTS_DIRECTORY_INVALID,discoverSubagents};
|
|
1
|
+
import{join,relative,resolve}from"node:path";import{detectRootNamespaceCollisions,discoverExtensionMountDeclarations,resolveExtensionMounts}from"#discover/discover-agent.js";import{createDiscoverErrorDiagnostic}from"#discover/diagnostics.js";import{classifyLocalSubagentEntry,getDirectoryEntryType,getSupportedModuleBaseName,normalizeLogicalPath}from"#discover/filesystem.js";import{createDiskProjectSource}from"#discover/project-source.js";import{createAgentSourceManifest,createLocalSubagentSourceRef,createModuleSourceRef}from"#discover/manifest.js";import{DISCOVER_HOOKS_DIRECTORY_INVALID,DISCOVER_TOOLS_DIRECTORY_INVALID,createHookNameDiagnostic,createToolNameDiagnostic,createUnsupportedRootDirectoryDiagnostics,discoverFlatModuleSource,discoverInstructionsSource,discoverNamedSourceDirectory,readSortedDirectoryEntries}from"#discover/grammar.js";import{discoverConnectionSources}from"#discover/connections.js";import{discoverLibSources}from"#discover/lib.js";import{discoverSandboxSource}from"#discover/sandbox.js";import{discoverSkills}from"#discover/skills.js";const DISCOVER_LOCAL_SUBAGENT_SCHEDULES_INVALID=`discover/local-subagent-schedules-invalid`,DISCOVER_REQUIRED_SUBAGENT_CONFIG_MODULE_MISSING=`discover/required-subagent-config-module-missing`,DISCOVER_SUBAGENTS_DIRECTORY_INVALID=`discover/subagents-directory-invalid`;async function discoverSubagents(r){let i=r.source??createDiskProjectSource(),a=resolve(r.agentRoot),s=resolve(r.subagentsDirectoryPath??join(a,`subagents`)),c=normalizeLogicalPath(r.subagentsLogicalPath??relative(a,s)),f=await i.stat(s);if(f===`missing`)return{diagnostics:[],subagents:[]};if(f!==`directory`)return{diagnostics:[createDiscoverErrorDiagnostic({code:DISCOVER_SUBAGENTS_DIRECTORY_INVALID,message:`Expected "${s}" to be a directory of authored subagents.`,sourcePath:s})],subagents:[]};let p=await readSortedDirectoryEntries(i,s),m=[],h=[];for(let t of p){if(t.isFile()){let n=getSupportedModuleBaseName(t.name);if(n===null)continue;h.push(discoverSingleFileSubagent({agentRoot:a,appRoot:r.appRoot,subagentId:n,subagentLogicalPath:join(c,t.name),subagentPath:join(s,t.name)}));continue}if(!t.isDirectory())continue;let n=await discoverLocalSubagentPackage({appRoot:r.appRoot,source:i,subagentId:t.name,subagentLogicalPath:join(c,t.name),subagentRoot:join(s,t.name)});m.push(...n.diagnostics),h.push(n.subagent)}return{diagnostics:m,subagents:h}}function discoverSingleFileSubagent(e){let t=createModuleSourceRef({logicalPath:e.subagentLogicalPath}),n=createAgentSourceManifest({agentId:e.subagentId,agentRoot:e.agentRoot,appRoot:e.appRoot,configModule:t});return createLocalSubagentSourceRef({entryPath:e.subagentPath,logicalPath:e.subagentLogicalPath,manifest:n,rootPath:e.agentRoot,subagentId:e.subagentId})}async function discoverLocalSubagentPackage(t){let n=[],o=await readSortedDirectoryEntries(t.source,t.subagentRoot);n.push(...createUnsupportedRootDirectoryDiagnostics({classifyEntry:classifyLocalSubagentEntry,createUnsupportedDirectoryMessage(e){return`Ignoring unsupported directory "${e}/" in the local subagent root.`},rootEntries:o,rootPath:t.subagentRoot}));let c=await discoverInstructionsSource({required:!1,rootEntries:o,rootPath:t.subagentRoot,source:t.source});n.push(...c.diagnostics);let l=discoverFlatModuleSource({missingDiagnostic:{code:DISCOVER_REQUIRED_SUBAGENT_CONFIG_MODULE_MISSING,message:`Expected one authored subagent config module at "agent.ts", "agent.cts", "agent.mts", "agent.js", "agent.cjs", or "agent.mjs".`},rootEntries:o,rootPath:t.subagentRoot,slotName:`agent`});n.push(...l.diagnostics);let u=await discoverConnectionSources({rootEntries:o,rootPath:t.subagentRoot,source:t.source});n.push(...u.diagnostics);let d=await discoverSandboxSource({rootEntries:o,rootPath:t.subagentRoot,source:t.source});n.push(...d.diagnostics);let m=await discoverNamedSourceDirectory({directoryName:`tools`,invalidDirectoryCode:DISCOVER_TOOLS_DIRECTORY_INVALID,invalidDirectoryMessage:`Expected "${join(t.subagentRoot,`tools`)}" to be a directory of authored tools.`,recursive:!0,rootEntries:o,rootPath:t.subagentRoot,source:t.source,validateSegment:createToolNameDiagnostic});n.push(...m.diagnostics);let g=await discoverNamedSourceDirectory({directoryName:`hooks`,invalidDirectoryCode:DISCOVER_HOOKS_DIRECTORY_INVALID,invalidDirectoryMessage:`Expected "${join(t.subagentRoot,`hooks`)}" to be a directory of authored hooks.`,recursive:!0,rootEntries:o,rootPath:t.subagentRoot,source:t.source,validateSegment:createHookNameDiagnostic});n.push(...g.diagnostics);let _=await discoverLibSources({agentRoot:t.subagentRoot,rootEntries:o,source:t.source});n.push(..._.diagnostics),n.push(...createLocalSubagentScheduleDiagnostics(t.subagentRoot,o));let v=await discoverSkills({agentRoot:t.subagentRoot,source:t.source});n.push(...v.diagnostics);let y=await discoverSubagents({agentRoot:t.subagentRoot,appRoot:t.appRoot,source:t.source});n.push(...y.diagnostics);let b=await discoverExtensionMountDeclarations({agentRoot:t.subagentRoot,source:t.source});n.push(...b.diagnostics),n.push(...detectRootNamespaceCollisions({agentRoot:t.subagentRoot,namespaces:b.mounts.map(e=>e.namespace),sources:[...m.sources,...u.connections,...v.skills,...y.subagents]}));let x=await resolveExtensionMounts({agentRoot:t.subagentRoot,appRoot:t.appRoot,mounts:b.mounts,source:t.source});n.push(...x.diagnostics);let S={agentRoot:t.subagentRoot,appRoot:t.appRoot,connections:u.connections,diagnostics:n,extensions:b.mounts.map(e=>e.mountRef),resolvedExtensions:x.mounts,hooks:g.sources,lib:_.lib,instructions:c.instructions,sandbox:d.sandbox,sandboxWorkspaces:d.sandboxWorkspace===null?[]:[d.sandboxWorkspace],skills:v.skills,tools:m.sources,subagents:y.subagents};l.module!==void 0&&(S.configModule=l.module);let C=createAgentSourceManifest(S);return{diagnostics:n,subagent:createLocalSubagentSourceRef({entryPath:t.subagentRoot,logicalPath:t.subagentLogicalPath,manifest:C,rootPath:t.subagentRoot,subagentId:t.subagentId})}}function createLocalSubagentScheduleDiagnostics(t,n){return n.flatMap(n=>classifyLocalSubagentEntry(n.name,getDirectoryEntryType(n))===`invalid-schedules-directory`?[createDiscoverErrorDiagnostic({code:DISCOVER_LOCAL_SUBAGENT_SCHEDULES_INVALID,message:`Local subagent packages cannot define schedules at "${join(t,n.name)}".`,sourcePath:join(t,n.name)})]:[])}export{DISCOVER_LOCAL_SUBAGENT_SCHEDULES_INVALID,DISCOVER_REQUIRED_SUBAGENT_CONFIG_MODULE_MISSING,DISCOVER_SUBAGENTS_DIRECTORY_INVALID,discoverSubagents};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createRequire}from"node:module";import{basename,dirname,join}from"node:path";import{existsSync,readFileSync,realpathSync}from"node:fs";import{fileURLToPath}from"node:url";import{EVE_PACKAGE_NAME}from"#internal/package-name.js";let cachedPackageInfo,cachedPackageLocation;const BUNDLED_FALLBACK_PACKAGE_VERSION=`0.38.
|
|
1
|
+
import{createRequire}from"node:module";import{basename,dirname,join}from"node:path";import{existsSync,readFileSync,realpathSync}from"node:fs";import{fileURLToPath}from"node:url";import{EVE_PACKAGE_NAME}from"#internal/package-name.js";let cachedPackageInfo,cachedPackageLocation;const BUNDLED_FALLBACK_PACKAGE_VERSION=`0.38.1`,WORKFLOW_MODULE_ALIASES={"workflow/errors":`src/compiled/@workflow/errors/index.js`,"workflow/internal/private":`src/compiled/@workflow/core/private.js`};function resolveFallbackPackageVersion(){return BUNDLED_FALLBACK_PACKAGE_VERSION.startsWith(`__`)?`0.0.0`:BUNDLED_FALLBACK_PACKAGE_VERSION}const FALLBACK_PACKAGE_INFO={name:EVE_PACKAGE_NAME,version:resolveFallbackPackageVersion()};function resolveCurrentModulePath(){return typeof __filename==`string`?__filename:resolveCurrentModulePathFromStack()}function resolveCurrentModulePathFromStack(){let e=Error.prepareStackTrace;try{Error.prepareStackTrace=(e,t)=>t;let e=Error().stack?.[0]?.getFileName();if(typeof e!=`string`||e.length===0)throw Error(`Failed to resolve the current module path from the stack trace.`);return e.startsWith(`file:`)?fileURLToPath(e):e}finally{Error.prepareStackTrace=e}}const require=createRequire(resolveCurrentModulePath());function tryResolveVerifiedPackageRoot(e){try{let t=realpathSync.native(e);return tryReadInstalledPackageInfo(t,EVE_PACKAGE_NAME)===void 0?void 0:dirname(t)}catch{return}}function findNearestVerifiedPackageRoot(e){let t=e;for(;;){let e=tryResolveVerifiedPackageRoot(join(t,`package.json`));if(e!==void 0)return e;let i=dirname(t);if(i===t)return;t=i}}function tryResolveDirectBuildLocation(e){let i=dirname(e);for(;;){if(basename(i)===`dist`){let e=tryResolveVerifiedPackageRoot(join(dirname(i),`package.json`));if(e!==void 0)return{packageBuildRoot:i,packageRoot:e}}let e=dirname(i);if(e===i)return;i=e}}function isSourceCheckout(e){return existsSync(join(e,`src`,`internal`,`application`,`package.ts`))}function tryCreatePackageLocation(e){if(isSourceCheckout(e))return{packageBuildRoot:null,packageRoot:e};let t=join(e,`dist`);if(existsSync(t))return{packageBuildRoot:t,packageRoot:e}}function resolveSelfPackageJsonPath(t){return createRequire(t).resolve(`${EVE_PACKAGE_NAME}/package.json`)}function resolvePackageLocationFromModulePath(e,t=resolveSelfPackageJsonPath){let r=realpathSync.native(e),i=tryResolveDirectBuildLocation(r);if(i!==void 0)return i;let a=findNearestVerifiedPackageRoot(dirname(r));if(a!==void 0&&isSourceCheckout(a))return{packageBuildRoot:null,packageRoot:a};try{let e=tryResolveVerifiedPackageRoot(t(r)),n=e===void 0?void 0:tryCreatePackageLocation(e);if(n!==void 0)return n}catch{}let o=a===void 0?void 0:tryCreatePackageLocation(a);if(o!==void 0)return o;throw Error(`Failed to resolve the eve package root from "${e}".`)}function resolvePackageLocation(){return cachedPackageLocation??=resolvePackageLocationFromModulePath(resolveCurrentModulePath()),cachedPackageLocation}function resolvePackageBuildRoot(){return resolvePackageLocation().packageBuildRoot}function resolvePackageRoot(){return resolvePackageLocation().packageRoot}function tryResolvePackageRoot(){try{return resolvePackageRoot()}catch{return}}function rewriteSourceFilePathForBuild(e){return e.replace(/\.[cm]?tsx?$/,`.js`)}function resolvePackageSourceFilePath(e){let t=resolvePackageBuildRoot();return t===null?join(resolvePackageRoot(),e):join(t,rewriteSourceFilePathForBuild(e))}function resolvePackageSourceDirectoryPath(e){let t=resolvePackageBuildRoot();return join(t===null?resolvePackageRoot():t,e)}function resolvePackageDependencyPath(e){return require.resolve(e)}function resolvePackageCompiledFilePath(e){let t=resolvePackageBuildRoot();return t===null?join(resolvePackageRoot(),`.generated`,`compiled`,e.replace(/^src\/compiled\//,``)):join(t,e)}function normalizeInstalledPackageInfo(e){let t=e;if(!(typeof t.name!=`string`||typeof t.version!=`string`))return{name:t.name,version:t.version}}function tryReadInstalledPackageInfo(e,t){let n=normalizeInstalledPackageInfo(JSON.parse(readFileSync(e,`utf8`)));if(n?.name===t)return n}function resolveInstalledPackageInfo(){if(cachedPackageInfo)return cachedPackageInfo;let e=tryResolvePackageRoot(),t=e===void 0?void 0:tryReadInstalledPackageInfo(join(e,`package.json`),EVE_PACKAGE_NAME);if(t)return cachedPackageInfo=t,cachedPackageInfo;try{let e=tryReadInstalledPackageInfo(require.resolve(`${EVE_PACKAGE_NAME}/package.json`),EVE_PACKAGE_NAME);if(e)return cachedPackageInfo=e,cachedPackageInfo}catch{}return cachedPackageInfo={...FALLBACK_PACKAGE_INFO},cachedPackageInfo}function readWorkflowVersionFromManifest(e){let t=e;for(let e of[t.devDependencies,t.dependencies,t.peerDependencies]){let t=e?.[`@workflow/core`];if(typeof t==`string`&&t.trim().length>0)return t}}function resolveExpectedWorkflowVersion(){let e=tryResolvePackageRoot();if(e!==void 0)try{return readWorkflowVersionFromManifest(JSON.parse(readFileSync(join(e,`package.json`),`utf8`)))}catch{}try{return readWorkflowVersionFromManifest(JSON.parse(readFileSync(require.resolve(`${EVE_PACKAGE_NAME}/package.json`),`utf8`)))}catch{return}}function resolveWorkflowModulePath(e){if(e===`workflow`)return resolvePackageSourceFilePath(`src/internal/workflow/index.ts`);if(e===`workflow/api`||e===`workflow/runtime`)return resolvePackageSourceFilePath(`src/internal/workflow/runtime.ts`);if(e===`workflow/internal/builtins`)return resolvePackageSourceFilePath(`src/internal/workflow/builtins.ts`);let t=WORKFLOW_MODULE_ALIASES[e];return t===void 0?require.resolve(e):resolvePackageCompiledFilePath(t)}export{resolveExpectedWorkflowVersion,resolveInstalledPackageInfo,resolvePackageCompiledFilePath,resolvePackageDependencyPath,resolvePackageLocationFromModulePath,resolvePackageRoot,resolvePackageSourceDirectoryPath,resolvePackageSourceFilePath,resolveWorkflowModulePath};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{join}from"node:path";import{pathToFileURL}from"node:url";import{collectModuleRefsForManifest,compiledModuleMapSchema}from"#compiler/module-map.js";import{ROOT_COMPILED_AGENT_NODE_ID}from"#compiler/manifest.js";import{formatValidationError}from"#runtime/validation.js";import{loadAuthoredModuleNamespace}from"#internal/authored-module-loader.js";import{loadCompiledManifest}from"#runtime/loaders/manifest.js";import{readMaterializedAuthoredModuleIndex}from"#internal/materialized-authored-modules.js";const EXT_CONFIG_SCOPE=Symbol.for(`eve.ext-config-scope`);async function loadCompiledModuleMapFromAuthoredSource(e){return await hydrateCompiledModuleMapFromManifest(await loadCompiledManifest({compiledArtifactsSource:e.compiledArtifactsSource}),e.compiledArtifactsSource.appRoot)}async function hydrateCompiledModuleMapFromManifest(e,t){let n=await readMaterializedAuthoredModuleIndex(t);if(n!==void 0)return await loadMaterializedCompiledModuleMap({moduleMapPath:n.moduleMap,runtimeAppRoot:t});let r={},a=[{agentRoot:e.agentRoot,externalDependencies:e.config.build?.externalDependencies??[],manifest:e,nodeId:ROOT_COMPILED_AGENT_NODE_ID},...[...e.subagents].sort((e,t)=>e.nodeId.localeCompare(t.nodeId)).map(e=>({additionalModuleRef:e.configResolver,agentRoot:e.agent.agentRoot,externalDependencies:e.configResolver===void 0?e.agent.config.build?.externalDependencies??[]:e.configResolver.build?.externalDependencies??[],manifest:e.agent,nodeId:e.nodeId}))]
|
|
1
|
+
import{join}from"node:path";import{pathToFileURL}from"node:url";import{collectModuleRefsForManifest,compiledModuleMapSchema}from"#compiler/module-map.js";import{ROOT_COMPILED_AGENT_NODE_ID}from"#compiler/manifest.js";import{formatValidationError}from"#runtime/validation.js";import{loadAuthoredModuleNamespace}from"#internal/authored-module-loader.js";import{loadCompiledManifest}from"#runtime/loaders/manifest.js";import{readMaterializedAuthoredModuleIndex}from"#internal/materialized-authored-modules.js";const EXT_CONFIG_SCOPE=Symbol.for(`eve.ext-config-scope`);async function loadCompiledModuleMapFromAuthoredSource(e){return await hydrateCompiledModuleMapFromManifest(await loadCompiledManifest({compiledArtifactsSource:e.compiledArtifactsSource}),e.compiledArtifactsSource.appRoot)}async function hydrateCompiledModuleMapFromManifest(e,t){let n=await readMaterializedAuthoredModuleIndex(t);if(n!==void 0)return await loadMaterializedCompiledModuleMap({moduleMapPath:n.moduleMap,runtimeAppRoot:t});let r={},a=[{agentRoot:e.agentRoot,externalDependencies:e.config.build?.externalDependencies??[],manifest:e,nodeId:ROOT_COMPILED_AGENT_NODE_ID},...[...e.subagents].sort((e,t)=>e.nodeId.localeCompare(t.nodeId)).map(e=>({additionalModuleRef:e.configResolver,agentRoot:e.agent.agentRoot,externalDependencies:e.configResolver===void 0?e.agent.config.build?.externalDependencies??[]:e.configResolver.build?.externalDependencies??[],manifest:e.agent,nodeId:e.nodeId}))],o=new Map(a.map(e=>[e.nodeId,e.manifest])),s=new Map(e.subagentEdges.map(e=>[e.childNodeId,e.parentNodeId])),l=new Map,extensionNamespacesForNode=e=>{let t=l.get(e);if(t!==void 0)return t;let n=s.get(e),r=new Map(n===void 0?[]:extensionNamespacesForNode(n));for(let t of o.get(e)?.extensionMounts??[])r.set(t.namespace,t.packageNamespace);return l.set(e,r),r};for(let e of a){let t={byMountNamespace:extensionNamespacesForNode(e.nodeId),byMountSourceId:new Map(e.manifest.extensionMounts.map(e=>[e.mountSourceId,e.packageNamespace]))};r[e.nodeId]={modules:await hydrateCompiledNodeScope({agentRoot:e.agentRoot,additionalModuleRef:e.additionalModuleRef,externalDependencies:e.externalDependencies,manifest:e.manifest,scopeIndex:t})}}return{nodes:r}}async function loadMaterializedCompiledModuleMap(n){let i=join(n.runtimeAppRoot,`.eve`,`compile`,n.moduleMapPath),o=await import(`${pathToFileURL(i).href}?generation=${encodeURIComponent(n.moduleMapPath)}`),s=compiledModuleMapSchema.safeParse(o.moduleMap??o.default);if(!s.success)throw Error(`Expected materialized authored module map "${i}" to export a valid compiled eve module map. ${formatValidationError(s.error)}`);return s.data}function extensionNamespaceForSourceId(e,t){let n=e.match(/^ext:([^:]+):/);return n===null?void 0:t.byMountNamespace.get(n[1])}async function hydrateCompiledNodeScope(t){let r=[...collectModuleRefsForManifest(t.manifest),...t.additionalModuleRef===void 0?[]:[t.additionalModuleRef]].sort((e,t)=>e.sourceId.localeCompare(t.sourceId)),i=globalThis,a={};for(let n of r){let r=join(t.agentRoot,n.logicalPath),s=extensionNamespaceForSourceId(n.sourceId,t.scopeIndex),c=t.scopeIndex.byMountSourceId.get(n.sourceId);c!==void 0&&(i[EXT_CONFIG_SCOPE]=c);try{a[n.sourceId]=await loadAuthoredModuleNamespace(r,{externalDependencies:t.externalDependencies,extensionScopeNamespace:s})}finally{c!==void 0&&(i[EXT_CONFIG_SCOPE]=void 0)}}return a}export{loadCompiledModuleMapFromAuthoredSource};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{join}from"node:path";import{compileInstructionsEntry}from"#compiler/normalize-instructions.js";import{compileSkillSource}from"#compiler/normalize-skill.js";import{compileToolEntry}from"#compiler/normalize-tool.js";import{loadAuthoredModuleNamespace}from"#internal/authored-module-loader.js";import{EXTENSION_CAPABILITY_VERSIONS}from"#compiler/extension-compatibility.js";import{extensionUsesState}from"#internal/nitro/host/extension-state-usage.js";async function deriveExtensionCapabilityRequirements(
|
|
1
|
+
import{join}from"node:path";import{compileInstructionsEntry}from"#compiler/normalize-instructions.js";import{compileSkillSource}from"#compiler/normalize-skill.js";import{compileToolEntry}from"#compiler/normalize-tool.js";import{loadAuthoredModuleNamespace}from"#internal/authored-module-loader.js";import{EXTENSION_CAPABILITY_VERSIONS}from"#compiler/extension-compatibility.js";import{extensionUsesState}from"#internal/nitro/host/extension-state-usage.js";async function deriveExtensionCapabilityRequirements(r){let i=new Set([`extension`]),a={externalDependencies:r.runtimeDependencies},o=collectSubagentManifests(r.manifest),[s,c,l,u,d]=await Promise.all([Promise.all(o.flatMap(e=>e.tools.map(t=>compileToolEntry(e.agentRoot,t,a)))),Promise.all(o.flatMap(e=>e.skills.map(t=>compileSkillSource(e.agentRoot,t,a)))),Promise.all(o.flatMap(e=>e.instructions.map(n=>compileInstructionsEntry(e.agentRoot,n,a)))),loadAuthoredModuleNamespace(join(r.sourceRoot,r.declarationModule.logicalPath),{externalDependencies:r.runtimeDependencies}),extensionUsesState(r.sourceRoot)]);s.length>0&&i.add(`tool`),s.some(e=>e.kind===`dynamic-tool`)&&i.add(`dynamicTool`),o.some(e=>e.channels.length>0)&&i.add(`channel`),o.some(e=>e.connections.length>0)&&i.add(`connection`),o.some(e=>e.hooks.length>0)&&i.add(`hook`),o.some(e=>e.schedules.length>0)&&i.add(`schedule`),o.some(e=>e.subagents.length>0)&&i.add(`subagent`),c.length>0&&i.add(`skill`),c.some(e=>e.kind===`dynamic-skill`)&&i.add(`dynamicSkill`),l.length>0&&i.add(`instructions`),l.some(e=>e.kind===`dynamic-instructions`)&&i.add(`dynamicInstructions`);let f=u[r.declarationModule.exportName??`default`];return(typeof f==`function`||typeof f==`object`&&f)&&`schema`in f&&f.schema!==void 0&&i.add(`config`),d&&i.add(`state`),Object.fromEntries(Object.keys(EXTENSION_CAPABILITY_VERSIONS).filter(e=>i.has(e)).map(e=>[e,EXTENSION_CAPABILITY_VERSIONS[e]]))}function collectSubagentManifests(e){return[e,...e.subagents.flatMap(e=>collectSubagentManifests(e.manifest))]}export{deriveExtensionCapabilityRequirements};
|
|
@@ -3,8 +3,8 @@ import { type AuthFn } from "#public/channels/auth.js";
|
|
|
3
3
|
export interface McpChannelInput {
|
|
4
4
|
/** Existing eve route-auth policy. Use `none()` for explicit public access. */
|
|
5
5
|
readonly auth: AuthFn<Request> | readonly AuthFn<Request>[];
|
|
6
|
-
/**
|
|
7
|
-
readonly
|
|
6
|
+
/** Override the default MCP route path (`/eve/v1/mcp`). */
|
|
7
|
+
readonly route?: string;
|
|
8
8
|
}
|
|
9
9
|
/** Public MCP channel exposing durable agent invocation compatibility tools. */
|
|
10
10
|
export type McpChannel = Channel;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{z}from"#compiled/zod/index.js";import{resolveInstalledPackageInfo}from"#internal/application/package.js";import{inputRequestSchema,inputResponseSchema}from"#runtime/input/types.js";import{parseJsonObject}from"#shared/json.js";import{DELETE,GET,HEAD,OPTIONS,POST,defineChannel}from"#public/definitions/channel.js";import{escapeAuthChallengeParameter,readOAuthResourceOptions,routeAuth}from"#public/channels/auth.js";import{readAgentInfoRouteResponse,readRouteChannelName,readRouteSessionCreator}from"#internal/nitro/routes/channel-route-context.js";import{WorkflowAgentInvocationExecution}from"#internal/invocation/workflow-execution.js";import{validateMcpHttpRequest,validateMcpMetadataRequest}from"#internal/mcp/http-security.js";import{createMcpStreamableHttpServer,defineMcpTool}from"#internal/mcp/streamable-http-server.js";import{createMcpProtectedResourceMetadata,createMcpResourceChallenge}from"#internal/mcp/protected-resource.js";function mcpChannel(e){if(e?.auth===void 0)throw Error(`mcpChannel requires auth. Use none() for explicit public access.`);let t=e.path??`/mcp`,n=readOAuthResourceOptions(e.auth),r=[GET(t,async(t,r)=>await authenticateMcpRequest(t,r,e.auth,n)),POST(t,async(t,r)=>await authenticateMcpRequest(t,r,e.auth,n)),DELETE(t,async(t,r)=>await authenticateMcpRequest(t,r,e.auth,n))];return n!==void 0&&r.unshift(...protectedResourceMetadataRoutes(n,t)),defineChannel({routes:r})}function protectedResourceMetadataRoutes(e,t){let n=e.metadataPath??`/.well-known/oauth-protected-resource`;return[GET(n,async n=>protectedResourceMetadataResponse(n,e,t,!1)),HEAD(n,async n=>protectedResourceMetadataResponse(n,e,t,!0)),OPTIONS(n,async e=>protectedResourceMetadataOptionsResponse(e))]}function protectedResourceMetadataResponse(e,t,n,r){let i=validateMcpMetadataRequest(e);if(i!==void 0)return i;let a=t.resource??new URL(n,new URL(e.url).origin).toString(),o=t.issuer===void 0?t.authorizationServers:[t.issuer],s=Response.json(createMcpProtectedResourceMetadata({authorizationServers:o,resource:a,scopesSupported:t.scopes}),{headers:{"access-control-allow-origin":`*`,"cache-control":`no-store`}});return r?new Response(null,{headers:s.headers,status:s.status}):s}function protectedResourceMetadataOptionsResponse(e){let t=validateMcpMetadataRequest(e);if(t!==void 0)return t;let n=new Headers({"access-control-allow-methods":`GET, HEAD, OPTIONS`,"access-control-allow-origin":`*`,"cache-control":`no-store`}),r=e.headers.get(`access-control-request-headers`);return r!==null&&(n.set(`access-control-allow-headers`,r),n.set(`vary`,`Access-Control-Request-Headers`)),new Response(null,{headers:n,status:204})}function addResourceChallenge(e,t,n){if(e.status!==401&&e.status!==403)return e;let r=n.metadataPath??`/.well-known/oauth-protected-resource`,i=n.resource??new URL(t.url).origin,a=new URL(r,i).toString(),o=new Headers(e.headers),s=o.get(`www-authenticate`);if(e.status===401)o.set(`www-authenticate`,mergeMcpBearerChallenge(s,a,n.scopes));else{let t=augmentInsufficientScopeChallenge(s,a);if(t===void 0)return e;o.set(`www-authenticate`,t)}return new Response(e.body,{headers:o,status:e.status,statusText:e.statusText})}function mergeMcpBearerChallenge(e,t,n){let r=parseAuthChallenges(e),i=r.find(e=>e.scheme.toLowerCase()===`bearer`&&hasAuthParameter(e.value,`error`))??r.find(e=>e.scheme.toLowerCase()===`bearer`);return replaceBearerChallenges(r,i,i===void 0?createMcpResourceChallenge(t,n):augmentBearerChallenge(i.value,t,n))}function augmentInsufficientScopeChallenge(e,t){let n=parseAuthChallenges(e),r=n.find(e=>e.scheme.toLowerCase()===`bearer`&&hasAuthParameter(e.value,`error`,`insufficient_scope`));if(r!==void 0)return replaceBearerChallenges(n,r,augmentBearerChallenge(r.value,t))}function replaceBearerChallenges(e,t,n){let r=[],i=!1;for(let a of e){if(a.scheme.toLowerCase()!==`bearer`){r.push(a.value);continue}!i&&a===t&&(r.push(n),i=!0)}return i||r.push(n),r.join(`, `)}function augmentBearerChallenge(e,t,n){let r=e;return hasAuthParameter(r,`resource_metadata`)||(r=appendAuthParameter(r,`resource_metadata`,t)),n?.length&&!hasAuthParameter(r,`scope`)&&(r=appendAuthParameter(r,`scope`,n.join(` `))),r}function appendAuthParameter(e,t,n){return`${e}${e.trim().toLowerCase()===`bearer`?` `:`, `}${t}="${escapeAuthChallengeParameter(n)}"`}function hasAuthParameter(e,t,n){let r=t.replaceAll(/[.*+?^${}()|[\]\\]/g,`\\$&`);if(n===void 0)return RegExp(`(?:^|[\\s,])${r}\\s*=`,`i`).test(e);let i=n.replaceAll(/[.*+?^${}()|[\]\\]/g,`\\$&`);return RegExp(`(?:^|[\\s,])${r}\\s*=\\s*(?:"${i}"|${i})(?=$|[\\s,])`,`i`).test(e)}function parseAuthChallenges(e){if(e===null)return[];let t=[];for(let n of splitQuotedHeaderList(e)){let e=readChallengeScheme(n);if(e!==void 0){t.push({scheme:e,value:n});continue}let r=t.at(-1);r!==void 0&&(r.value+=`, ${n}`)}return t}function splitQuotedHeaderList(e){let t=[],n=!1,r=!1,i=0;for(let a=0;a<e.length;a++){let o=e[a];if(n)n=!1;else if(o===`\\`)n=!0;else if(o===`"`)r=!r;else if(o===`,`&&!r){let n=e.slice(i,a).trim();n.length>0&&t.push(n),i=a+1}}let a=e.slice(i).trim();return a.length>0&&t.push(a),t}function readChallengeScheme(e){let t=/^([!#$%&'*+\-.^_`|~0-9A-Za-z]+)(?:\s+|$)/.exec(e);if(t===null)return;let n=t[1];if(n!==void 0)return e.slice(n.length).trimStart().startsWith(`=`)?void 0:n}async function authenticateMcpRequest(e,t,n,r){let i=validateMcpHttpRequest(e);if(i!==void 0)return i;let a=await routeAuth(e,n);return a instanceof Response?r===void 0?a:addResourceChallenge(a,e,r):await handleMcpRequest(e,t,a)}async function handleMcpRequest(e,n,r){let i=readRouteSessionCreator(n),a=readRouteChannelName(n),o=readAgentInfoRouteResponse(n);if(a===void 0||i===void 0||o===void 0)return Response.json({error:`MCP requires agent route context.`},{status:500});let s=await o();if(!s.ok)return s;let c=await s.json();if(typeof c.agent?.name!=`string`)return Response.json({error:`MCP requires compiled agent metadata.`},{status:500});let l=typeof c.agent.description==`string`?c.agent.description:void 0,u=new WorkflowAgentInvocationExecution({createSession:i,from:n.from});return await createMcpStreamableHttpServer({authenticate:async()=>r,name:c.agent.name,tools:createInvocationTools(u,l,r.authenticator===`none`&&r.principalType===`anonymous`),version:resolveInstalledPackageInfo().version})(e)}function createInvocationTools(t,n,i){let a=i?` On this public channel, the invocation ID is a bearer capability until workflow retention expires.`:``,o=`Starts durable work and returns an invocation handle immediately.${a}`;return[defineMcpTool({definition:{annotations:{destructiveHint:!0,idempotentHint:!1,openWorldHint:!0,readOnlyHint:!1},description:n===void 0?o:`${n} ${o}`,inputSchema:z.strictObject({message:z.string().min(1),outputSchema:z.looseObject({}).optional()}),name:`agent_start`,outputSchema:AGENT_INVOCATION_OUTPUT_SCHEMA},async call(e,n){return invocationResult(await t.create({auth:n.auth,message:e.message,outputSchema:asJsonObject(e.outputSchema)}))}}),defineMcpTool({definition:{annotations:{destructiveHint:!1,idempotentHint:!0,openWorldHint:!1,readOnlyHint:!0},description:`Reads complete durable invocation state.${a}`,inputSchema:z.strictObject({invocationId:z.string().min(1)}),name:`agent_get`,outputSchema:AGENT_INVOCATION_OUTPUT_SCHEMA},async call(e,n){return invocationResult(requiredInvocation(await t.read({auth:n.auth,invocationId:e.invocationId})))}}),defineMcpTool({definition:{annotations:{destructiveHint:!0,idempotentHint:!1,openWorldHint:!0,readOnlyHint:!1},description:`Answers a pending input request on a durable invocation.`,inputSchema:z.strictObject({invocationId:z.string().min(1),responses:z.array(inputResponseSchema).min(1)}),name:`agent_update`,outputSchema:AGENT_INVOCATION_OUTPUT_SCHEMA},async call(e,n){return invocationResult(requiredMutation(await t.update({auth:n.auth,invocationId:e.invocationId,responses:e.responses})))}}),defineMcpTool({definition:{annotations:{destructiveHint:!0,idempotentHint:!0,openWorldHint:!1,readOnlyHint:!1},description:`Requests cancellation of a durable invocation. Read it again to observe acknowledgement.`,inputSchema:z.strictObject({invocationId:z.string().min(1)}),name:`agent_cancel`,outputSchema:AGENT_INVOCATION_OUTPUT_SCHEMA},async call(e,n){return invocationResult(requiredInvocation(await t.cancel({auth:n.auth,invocationId:e.invocationId})))}})]}function requiredInvocation(e){if(e===void 0)throw Error(`Invocation not found.`);return e}function requiredMutation(e){switch(e.type){case`success`:return e.invocation;case`conflict`:throw Error(e.message);case`not_found`:throw Error(`Invocation not found.`)}}function invocationResult(e){let t=parseJsonObject(e);return{content:[{text:JSON.stringify(t),type:`text`}],structuredContent:t}}function asJsonObject(e){if(e===void 0)return;let t=parseJsonObject(e);return validateOutputSchemaComplexity(t),t}const AUTHORIZATION_CHALLENGE_SCHEMA=z.strictObject({displayName:z.string().optional(),expiresAt:z.iso.datetime().optional(),instructions:z.string().optional(),url:z.url().optional(),userCode:z.string().optional()}),AUTHORIZATION_REQUEST_SCHEMA=z.strictObject({authorization:AUTHORIZATION_CHALLENGE_SCHEMA.optional(),description:z.string(),name:z.string(),webhookUrl:z.url().optional()}),MCP_INPUT_REQUEST_SCHEMA=inputRequestSchema.safeExtend({action:z.strictObject({callId:z.string(),input:z.record(z.string(),z.json()),kind:z.literal(`tool-call`),toolName:z.string()})}),AGENT_INVOCATION_BASE_SCHEMA=z.strictObject({createdAt:z.iso.datetime(),expiresAt:z.iso.datetime().optional(),invocationId:z.string()}),AGENT_INVOCATION_OUTPUT_SCHEMA=z.discriminatedUnion(`status`,[AGENT_INVOCATION_BASE_SCHEMA.extend({pollAfterMs:z.number().int().nonnegative(),result:z.json().optional(),status:z.literal(`working`)}),AGENT_INVOCATION_BASE_SCHEMA.extend({inputRequests:z.record(z.string(),MCP_INPUT_REQUEST_SCHEMA),result:z.json().optional(),status:z.literal(`input_required`)}),AGENT_INVOCATION_BASE_SCHEMA.extend({authorizations:z.array(AUTHORIZATION_REQUEST_SCHEMA).min(1),pollAfterMs:z.number().int().nonnegative(),result:z.json().optional(),status:z.literal(`authorization_required`)}),AGENT_INVOCATION_BASE_SCHEMA.extend({result:z.json().optional(),status:z.literal(`completed`)}),AGENT_INVOCATION_BASE_SCHEMA.extend({error:z.strictObject({code:z.number().int(),data:z.json().optional(),message:z.string()}),status:z.literal(`failed`)}),AGENT_INVOCATION_BASE_SCHEMA.extend({status:z.literal(`cancelled`)})]);function validateOutputSchemaComplexity(e){if(new TextEncoder().encode(JSON.stringify(e)).byteLength>65536)throw Error(`outputSchema must be at most 65536 bytes.`);let t=0,visit=(e,n)=>{if(t++,t>2048)throw Error(`outputSchema must contain at most 2048 nodes.`);if(n>32)throw Error(`outputSchema must be at most 32 levels deep.`);if(Array.isArray(e)){for(let t of e)visit(t,n+1);return}if(!(typeof e!=`object`||!e))for(let[t,r]of Object.entries(e)){if(t===`$ref`&&typeof r==`string`&&!r.startsWith(`#`))throw Error(`outputSchema external $ref values are not supported.`);visit(r,n+1)}};visit(e,0)}export{mcpChannel};
|
|
1
|
+
import{z}from"#compiled/zod/index.js";import{resolveInstalledPackageInfo}from"#internal/application/package.js";import{inputRequestSchema,inputResponseSchema}from"#runtime/input/types.js";import{parseJsonObject}from"#shared/json.js";import{DELETE,GET,HEAD,OPTIONS,POST,defineChannel}from"#public/definitions/channel.js";import{escapeAuthChallengeParameter,readOAuthResourceOptions,routeAuth}from"#public/channels/auth.js";import{readAgentInfoRouteResponse,readRouteChannelName,readRouteSessionCreator}from"#internal/nitro/routes/channel-route-context.js";import{WorkflowAgentInvocationExecution}from"#internal/invocation/workflow-execution.js";import{validateMcpHttpRequest,validateMcpMetadataRequest}from"#internal/mcp/http-security.js";import{createMcpStreamableHttpServer,defineMcpTool}from"#internal/mcp/streamable-http-server.js";import{createMcpProtectedResourceMetadata,createMcpResourceChallenge}from"#internal/mcp/protected-resource.js";function mcpChannel(e){if(e?.auth===void 0)throw Error(`mcpChannel requires auth. Use none() for explicit public access.`);let t=e.route??`/eve/v1/mcp`,n=readOAuthResourceOptions(e.auth),r=[GET(t,async(t,r)=>await authenticateMcpRequest(t,r,e.auth,n)),POST(t,async(t,r)=>await authenticateMcpRequest(t,r,e.auth,n)),DELETE(t,async(t,r)=>await authenticateMcpRequest(t,r,e.auth,n))];return n!==void 0&&r.unshift(...protectedResourceMetadataRoutes(n,t)),defineChannel({routes:r})}function protectedResourceMetadataRoutes(e,t){let n=protectedResourceMetadataPath(e,t);return[GET(n,async n=>protectedResourceMetadataResponse(n,e,t,!1)),HEAD(n,async n=>protectedResourceMetadataResponse(n,e,t,!0)),OPTIONS(n,async e=>protectedResourceMetadataOptionsResponse(e))]}function protectedResourceMetadataPath(e,t){if(e.metadataPath!==void 0)return e.metadataPath;let n=e.resource===void 0?t:new URL(e.resource).pathname;return n===`/`?`/.well-known/oauth-protected-resource`:`/.well-known/oauth-protected-resource${n}`}function protectedResourceMetadataResponse(e,t,n,r){let i=validateMcpMetadataRequest(e);if(i!==void 0)return i;let a=t.resource??new URL(n,new URL(e.url).origin).toString(),o=t.issuer===void 0?t.authorizationServers:[t.issuer],s=Response.json(createMcpProtectedResourceMetadata({authorizationServers:o,resource:a,scopesSupported:t.scopes}),{headers:{"access-control-allow-origin":`*`,"cache-control":`no-store`}});return r?new Response(null,{headers:s.headers,status:s.status}):s}function protectedResourceMetadataOptionsResponse(e){let t=validateMcpMetadataRequest(e);if(t!==void 0)return t;let n=new Headers({"access-control-allow-methods":`GET, HEAD, OPTIONS`,"access-control-allow-origin":`*`,"cache-control":`no-store`}),r=e.headers.get(`access-control-request-headers`);return r!==null&&(n.set(`access-control-allow-headers`,r),n.set(`vary`,`Access-Control-Request-Headers`)),new Response(null,{headers:n,status:204})}function addResourceChallenge(e,t,n){if(e.status!==401&&e.status!==403)return e;let r=protectedResourceMetadataPath(n,new URL(t.url).pathname),i=n.resource??new URL(t.url).origin,a=new URL(r,i).toString(),o=new Headers(e.headers),s=o.get(`www-authenticate`);if(e.status===401)o.set(`www-authenticate`,mergeMcpBearerChallenge(s,a,n.scopes));else{let t=augmentInsufficientScopeChallenge(s,a);if(t===void 0)return e;o.set(`www-authenticate`,t)}return new Response(e.body,{headers:o,status:e.status,statusText:e.statusText})}function mergeMcpBearerChallenge(e,t,n){let r=parseAuthChallenges(e),i=r.find(e=>e.scheme.toLowerCase()===`bearer`&&hasAuthParameter(e.value,`error`))??r.find(e=>e.scheme.toLowerCase()===`bearer`);return replaceBearerChallenges(r,i,i===void 0?createMcpResourceChallenge(t,n):augmentBearerChallenge(i.value,t,n))}function augmentInsufficientScopeChallenge(e,t){let n=parseAuthChallenges(e),r=n.find(e=>e.scheme.toLowerCase()===`bearer`&&hasAuthParameter(e.value,`error`,`insufficient_scope`));if(r!==void 0)return replaceBearerChallenges(n,r,augmentBearerChallenge(r.value,t))}function replaceBearerChallenges(e,t,n){let r=[],i=!1;for(let a of e){if(a.scheme.toLowerCase()!==`bearer`){r.push(a.value);continue}!i&&a===t&&(r.push(n),i=!0)}return i||r.push(n),r.join(`, `)}function augmentBearerChallenge(e,t,n){let r=e;return hasAuthParameter(r,`resource_metadata`)||(r=appendAuthParameter(r,`resource_metadata`,t)),n?.length&&!hasAuthParameter(r,`scope`)&&(r=appendAuthParameter(r,`scope`,n.join(` `))),r}function appendAuthParameter(e,t,n){return`${e}${e.trim().toLowerCase()===`bearer`?` `:`, `}${t}="${escapeAuthChallengeParameter(n)}"`}function hasAuthParameter(e,t,n){let r=t.replaceAll(/[.*+?^${}()|[\]\\]/g,`\\$&`);if(n===void 0)return RegExp(`(?:^|[\\s,])${r}\\s*=`,`i`).test(e);let i=n.replaceAll(/[.*+?^${}()|[\]\\]/g,`\\$&`);return RegExp(`(?:^|[\\s,])${r}\\s*=\\s*(?:"${i}"|${i})(?=$|[\\s,])`,`i`).test(e)}function parseAuthChallenges(e){if(e===null)return[];let t=[];for(let n of splitQuotedHeaderList(e)){let e=readChallengeScheme(n);if(e!==void 0){t.push({scheme:e,value:n});continue}let r=t.at(-1);r!==void 0&&(r.value+=`, ${n}`)}return t}function splitQuotedHeaderList(e){let t=[],n=!1,r=!1,i=0;for(let a=0;a<e.length;a++){let o=e[a];if(n)n=!1;else if(o===`\\`)n=!0;else if(o===`"`)r=!r;else if(o===`,`&&!r){let n=e.slice(i,a).trim();n.length>0&&t.push(n),i=a+1}}let a=e.slice(i).trim();return a.length>0&&t.push(a),t}function readChallengeScheme(e){let t=/^([!#$%&'*+\-.^_`|~0-9A-Za-z]+)(?:\s+|$)/.exec(e);if(t===null)return;let n=t[1];if(n!==void 0)return e.slice(n.length).trimStart().startsWith(`=`)?void 0:n}async function authenticateMcpRequest(e,t,n,r){let i=validateMcpHttpRequest(e);if(i!==void 0)return i;let a=await routeAuth(e,n);return a instanceof Response?r===void 0?a:addResourceChallenge(a,e,r):await handleMcpRequest(e,t,a)}async function handleMcpRequest(e,n,r){let i=readRouteSessionCreator(n),a=readRouteChannelName(n),o=readAgentInfoRouteResponse(n);if(a===void 0||i===void 0||o===void 0)return Response.json({error:`MCP requires agent route context.`},{status:500});let s=await o();if(!s.ok)return s;let c=await s.json();if(typeof c.agent?.name!=`string`)return Response.json({error:`MCP requires compiled agent metadata.`},{status:500});let l=typeof c.agent.description==`string`?c.agent.description:void 0,u=new WorkflowAgentInvocationExecution({createSession:i,from:n.from});return await createMcpStreamableHttpServer({authenticate:async()=>r,name:c.agent.name,tools:createInvocationTools(u,l,r.authenticator===`none`&&r.principalType===`anonymous`),version:resolveInstalledPackageInfo().version})(e)}function createInvocationTools(t,n,i){let a=i?` On this public channel, the invocation ID is a bearer capability until workflow retention expires.`:``,o=`Starts durable work and returns an invocation handle immediately.${a}`;return[defineMcpTool({definition:{annotations:{destructiveHint:!0,idempotentHint:!1,openWorldHint:!0,readOnlyHint:!1},description:n===void 0?o:`${n} ${o}`,inputSchema:z.strictObject({message:z.string().min(1),outputSchema:z.looseObject({}).optional()}),name:`agent_start`,outputSchema:AGENT_INVOCATION_OUTPUT_SCHEMA},async call(e,n){return invocationResult(await t.create({auth:n.auth,message:e.message,outputSchema:asJsonObject(e.outputSchema)}))}}),defineMcpTool({definition:{annotations:{destructiveHint:!1,idempotentHint:!0,openWorldHint:!1,readOnlyHint:!0},description:`Reads complete durable invocation state.${a}`,inputSchema:z.strictObject({invocationId:z.string().min(1)}),name:`agent_get`,outputSchema:AGENT_INVOCATION_OUTPUT_SCHEMA},async call(e,n){return invocationResult(requiredInvocation(await t.read({auth:n.auth,invocationId:e.invocationId})))}}),defineMcpTool({definition:{annotations:{destructiveHint:!0,idempotentHint:!1,openWorldHint:!0,readOnlyHint:!1},description:`Answers a pending input request on a durable invocation.`,inputSchema:z.strictObject({invocationId:z.string().min(1),responses:z.array(inputResponseSchema).min(1)}),name:`agent_update`,outputSchema:AGENT_INVOCATION_OUTPUT_SCHEMA},async call(e,n){return invocationResult(requiredMutation(await t.update({auth:n.auth,invocationId:e.invocationId,responses:e.responses})))}}),defineMcpTool({definition:{annotations:{destructiveHint:!0,idempotentHint:!0,openWorldHint:!1,readOnlyHint:!1},description:`Requests cancellation of a durable invocation. Read it again to observe acknowledgement.`,inputSchema:z.strictObject({invocationId:z.string().min(1)}),name:`agent_cancel`,outputSchema:AGENT_INVOCATION_OUTPUT_SCHEMA},async call(e,n){return invocationResult(requiredInvocation(await t.cancel({auth:n.auth,invocationId:e.invocationId})))}})]}function requiredInvocation(e){if(e===void 0)throw Error(`Invocation not found.`);return e}function requiredMutation(e){switch(e.type){case`success`:return e.invocation;case`conflict`:throw Error(e.message);case`not_found`:throw Error(`Invocation not found.`)}}function invocationResult(e){let t=parseJsonObject(e);return{content:[{text:JSON.stringify(t),type:`text`}],structuredContent:t}}function asJsonObject(e){if(e===void 0)return;let t=parseJsonObject(e);return validateOutputSchemaComplexity(t),t}const AUTHORIZATION_CHALLENGE_SCHEMA=z.strictObject({displayName:z.string().optional(),expiresAt:z.iso.datetime().optional(),instructions:z.string().optional(),url:z.url().optional(),userCode:z.string().optional()}),AUTHORIZATION_REQUEST_SCHEMA=z.strictObject({authorization:AUTHORIZATION_CHALLENGE_SCHEMA.optional(),description:z.string(),name:z.string(),webhookUrl:z.url().optional()}),MCP_INPUT_REQUEST_SCHEMA=inputRequestSchema.safeExtend({action:z.strictObject({callId:z.string(),input:z.record(z.string(),z.json()),kind:z.literal(`tool-call`),toolName:z.string()})}),AGENT_INVOCATION_BASE_SCHEMA=z.strictObject({createdAt:z.iso.datetime(),expiresAt:z.iso.datetime().optional(),invocationId:z.string()}),AGENT_INVOCATION_OUTPUT_SCHEMA=z.discriminatedUnion(`status`,[AGENT_INVOCATION_BASE_SCHEMA.extend({pollAfterMs:z.number().int().nonnegative(),result:z.json().optional(),status:z.literal(`working`)}),AGENT_INVOCATION_BASE_SCHEMA.extend({inputRequests:z.record(z.string(),MCP_INPUT_REQUEST_SCHEMA),result:z.json().optional(),status:z.literal(`input_required`)}),AGENT_INVOCATION_BASE_SCHEMA.extend({authorizations:z.array(AUTHORIZATION_REQUEST_SCHEMA).min(1),pollAfterMs:z.number().int().nonnegative(),result:z.json().optional(),status:z.literal(`authorization_required`)}),AGENT_INVOCATION_BASE_SCHEMA.extend({result:z.json().optional(),status:z.literal(`completed`)}),AGENT_INVOCATION_BASE_SCHEMA.extend({error:z.strictObject({code:z.number().int(),data:z.json().optional(),message:z.string()}),status:z.literal(`failed`)}),AGENT_INVOCATION_BASE_SCHEMA.extend({status:z.literal(`cancelled`)})]);function validateOutputSchemaComplexity(e){if(new TextEncoder().encode(JSON.stringify(e)).byteLength>65536)throw Error(`outputSchema must be at most 65536 bytes.`);let t=0,visit=(e,n)=>{if(t++,t>2048)throw Error(`outputSchema must contain at most 2048 nodes.`);if(n>32)throw Error(`outputSchema must be at most 32 levels deep.`);if(Array.isArray(e)){for(let t of e)visit(t,n+1);return}if(!(typeof e!=`object`||!e))for(let[t,r]of Object.entries(e)){if(t===`$ref`&&typeof r==`string`&&!r.startsWith(`#`))throw Error(`outputSchema external $ref values are not supported.`);visit(r,n+1)}};visit(e,0)}export{mcpChannel};
|
|
@@ -29,5 +29,5 @@ export default defineExtension({
|
|
|
29
29
|
dist
|
|
30
30
|
.DS_Store
|
|
31
31
|
*.tsbuildinfo
|
|
32
|
-
`,"AGENTS.md":"# eve Extension Package\n\nThis package is an eve extension — a reusable package of tools, channels,\nconnections, skills, schedules, hooks, and instruction fragments that a consuming agent\nmounts under `agent/extensions/`.\n\nBefore writing code, read the Extensions guide from the installed eve package\ndocs. In most installs, those docs are at `node_modules/eve/docs/extensions.md`.\nIn workspaces or local package installs, resolve the installed `eve` package\nlocation first and read its `docs/extensions.md`. If package docs are\nunavailable, use https://eve.dev/docs/extensions as a fallback.\n\n## Authoring\n\n- Declare the extension in `extension/extension.ts` with `defineExtension` from\n `eve/extension`. Config is optional; read bound values via the handle's\n `.config` in tools, channels, schedules, and
|
|
32
|
+
`,"AGENTS.md":"# eve Extension Package\n\nThis package is an eve extension — a reusable package of tools, channels,\nconnections, skills, schedules, subagents, hooks, and instruction fragments that a consuming agent\nmounts under `agent/extensions/`.\n\nBefore writing code, read the Extensions guide from the installed eve package\ndocs. In most installs, those docs are at `node_modules/eve/docs/extensions.md`.\nIn workspaces or local package installs, resolve the installed `eve` package\nlocation first and read its `docs/extensions.md`. If package docs are\nunavailable, use https://eve.dev/docs/extensions as a fallback.\n\n## Authoring\n\n- Declare the extension in `extension/extension.ts` with `defineExtension` from\n `eve/extension`. Config is optional; read bound values via the handle's\n `.config` in tools, channels, schedules, hooks, and tools inside contributed subagents.\n- Add contributions under `extension/` the same way as in an agent:\n `tools/`, `channels/`, `connections/`, `skills/`, `schedules/`, `subagents/`, `hooks/`, and\n optional instruction fragments. Names come from file paths; the mount supplies the namespace, so\n name tools for what they do (`search`, not `crm_search`).\n- The extension root cannot declare `agent.ts`, `sandbox`, or nested\n `extensions/`. A subagent under `extension/subagents/` owns its own agent\n configuration and sandbox.\n\n## Build and publish\n\n`eve extension build` (wired to `build`/`prepare`) transforms the complete\nagent-shaped source tree into `dist/extension/`, emits type declarations and a\ncompatibility manifest, and fills the package `exports` map. Ship `dist/` only.\nKeep `eve` as a required wildcard peer so the consumer's eve is the one that runs;\neve validates extension compatibility from the generated manifest. Keep the eve\ndevelopment dependency pinned exactly so builds remain reproducible. Upgrade it\nwhen the extension intentionally adopts a newer eve authoring API.\n","CLAUDE.md":`@AGENTS.md
|
|
33
33
|
`,"package.json":packageJsonTemplate(e)}}async function assertCanCreateInPlace(e,n){if(!await pathExists(e))return;let i=blockingCreateInPlaceEntries(await readdir(e));if(i.length>0&&!n){let e=i.slice(0,5).join(`, `),t=i.length>5?`, and ${i.length-5} more`:``;throw Error(`Cannot create project in current directory because it is not empty. Found: ${e}${t}. Use an empty directory.`)}}async function scaffoldExtensionProject(r){let s=resolve(r.targetDirectory??process.cwd(),r.projectName),c=r.projectName===`.`,l=r.overwriteExisting??!1,u=r.packageManager??`pnpm`,d=resolveEvePackageContract(r.evePackage??DEFAULT_EVE_PACKAGE_CONTRACT),f=pinnedNodeEngineMajor(d.nodeEngine),p=resolve(r.workspaceProbeDirectory??s),m=isPackageManagerWorkspaceMember(u,p);if(c)await assertCanCreateInPlace(s,l);else if(await pathExists(s))throw Error(`Cannot create project because "${s}" already exists.`);let h={appName:basename(s),eveVersion:d.version,zodPackageVersion:resolveVersionToken(`zodPackageVersion`,r.zodPackageVersion??`4.4.3`),typescriptPackageVersion:resolveVersionToken(`typescriptPackageVersion`,r.typescriptPackageVersion??`7.0.2`),nodeTypesVersion:f,nodeEngine:f};await mkdir(s,{recursive:!0});for(let[e,i]of Object.entries(templateFiles(!m))){let a=`${s}/${e}`,o=await pathExists(a);await writeTextFile(a,renderTemplate(i,h),{force:c&&l}),o&&await r.onOverwriteFile?.(a)}return await applyPackageManagerWorkspaceConfiguration({packageManager:u,projectRoot:s,workspaceProbeRoot:p,onWorkspaceRootMutation:r.onWorkspaceRootMutation}),await patchWorkspaceRootPackageJson(u,p,{nodeEngineRequirement:d.nodeEngine,onWorkspaceRootMutation:r.onWorkspaceRootMutation}),s}export{scaffoldExtensionProject};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{pinnedNodeEngineMajor}from"../../node-engine.js";import{SUPPORTED_AUTHORED_MODULE_FILE_EXTENSIONS}from"../update/module-files.js";import{pathExists,writeTextFile}from"../files.js";import{blockingCreateInPlaceEntries}from"../create-in-place.js";import{resolveVersionToken}from"../version-tokens.js";import{applyPackageManagerWorkspaceConfiguration,isPackageManagerWorkspaceMember,patchWorkspaceRootPackageJson}from"../workspace-root.js";import{WEB_APP_TEMPLATE_FILES}from"./web-template.js";import{mkdir,readdir,stat}from"node:fs/promises";import{basename,join,resolve}from"node:path";const CURRENT_DIRECTORY_PROJECT_NAME=`.`,DEFAULT_AI_PACKAGE_VERSION=`^7.0.58`,DEFAULT_CONNECT_PACKAGE_VERSION=`0.4.3`,DEFAULT_ZOD_PACKAGE_VERSION=`4.4.3`,DEFAULT_EVE_PACKAGE_CONTRACT={version:`0.38.
|
|
1
|
+
import{pinnedNodeEngineMajor}from"../../node-engine.js";import{SUPPORTED_AUTHORED_MODULE_FILE_EXTENSIONS}from"../update/module-files.js";import{pathExists,writeTextFile}from"../files.js";import{blockingCreateInPlaceEntries}from"../create-in-place.js";import{resolveVersionToken}from"../version-tokens.js";import{applyPackageManagerWorkspaceConfiguration,isPackageManagerWorkspaceMember,patchWorkspaceRootPackageJson}from"../workspace-root.js";import{WEB_APP_TEMPLATE_FILES}from"./web-template.js";import{mkdir,readdir,stat}from"node:fs/promises";import{basename,join,resolve}from"node:path";const CURRENT_DIRECTORY_PROJECT_NAME=`.`,DEFAULT_AI_PACKAGE_VERSION=`^7.0.58`,DEFAULT_CONNECT_PACKAGE_VERSION=`0.4.3`,DEFAULT_ZOD_PACKAGE_VERSION=`4.4.3`,DEFAULT_EVE_PACKAGE_CONTRACT={version:`0.38.1`,nodeEngine:`>=24`};function resolveEvePackageContract(e=DEFAULT_EVE_PACKAGE_CONTRACT){return{version:resolveVersionToken(`evePackage.version`,e.version),nodeEngine:resolveVersionToken(`evePackage.nodeEngine`,e.nodeEngine)}}function modelProviderSlug(e){let t=(e.split(`/`)[0]??``).replaceAll(/[^A-Za-z0-9._-]/gu,``);return t.length>0?t:`anthropic`}function byokProviderEnvVar(e){let t=modelProviderSlug(e).toUpperCase().replaceAll(/[^A-Z0-9]/gu,`_`);return`${/^[0-9]/.test(t)?`_`:``}${t}_API_KEY`}function agentTemplateFiles(e,t){return{"agent/agent.ts":BASE_AGENT_TEMPLATE.replaceAll(`__EVE_INIT_MODEL__`,e).replaceAll(`__EVE_INIT_REASONING__`,reasoningTemplateLine(t)),"agent/channels/eve.ts":WEB_APP_TEMPLATE_FILES[`agent/channels/eve.ts`],"agent/instructions.md":AGENT_INSTRUCTIONS_TEMPLATE}}function reasoningTemplateLine(e){return e===void 0||e===`provider-default`?``:` reasoning: "${e}",\n`}function renderTemplate(e,t){return e.replaceAll(`__EVE_INIT_APP_NAME__`,t.appName).replaceAll(`__EVE_INIT_MODEL__`,t.model).replaceAll(`__EVE_INIT_REASONING__`,reasoningTemplateLine(t.reasoning)).replaceAll(`__EVE_INIT_BYOK_PROVIDER__`,modelProviderSlug(t.model)).replaceAll(`__EVE_INIT_BYOK_ENV_VAR__`,byokProviderEnvVar(t.model)).replaceAll(`__EVE_INIT_PACKAGE_VERSION__`,formatEveDependencySpecifier(t.eveVersion)).replaceAll(`__EVE_INIT_AI_SDK_VERSION__`,t.aiPackageVersion).replaceAll(`__EVE_INIT_CONNECT_VERSION__`,t.connectPackageVersion).replaceAll(`__EVE_INIT_ZOD_VERSION__`,t.zodPackageVersion).replaceAll(`__EVE_INIT_TYPESCRIPT_VERSION__`,t.typescriptPackageVersion).replaceAll(`__EVE_INIT_TYPES_NODE_VERSION__`,t.nodeTypesVersion).replaceAll(`__EVE_INIT_NODE_ENGINE__`,t.nodeEngine)}function formatEveDependencySpecifier(e){return/^\d+\.\d+\.\d+(?:[-+][0-9A-Za-z-.]+)?$/.test(e)?`^${e}`:e}const BASE_AGENT_TEMPLATE=`import { defineAgent } from "eve";
|
|
2
2
|
|
|
3
3
|
export default defineAgent({
|
|
4
4
|
model: "__EVE_INIT_MODEL__",
|
package/docs/extensions.md
CHANGED
|
@@ -3,7 +3,7 @@ title: "Extensions"
|
|
|
3
3
|
description: "Package reusable eve capabilities and mount them from npm or a monorepo workspace."
|
|
4
4
|
---
|
|
5
5
|
|
|
6
|
-
Extensions package eve tools, channels, connections, skills, schedules, instruction fragments, and hooks. An author builds an extension package; each agent that uses it declares the package as a dependency and mounts it. The package can be published to a package registry or kept private inside a monorepo workspace.
|
|
6
|
+
Extensions package eve tools, channels, connections, skills, schedules, subagents, instruction fragments, and hooks. An author builds an extension package; each agent that uses it declares the package as a dependency and mounts it. The package can be published to a package registry or kept private inside a monorepo workspace.
|
|
7
7
|
|
|
8
8
|
Ready-made extensions can also be distributed through an eve integration registry. See [Add Integrations](./install-integrations) to discover and add one with `eve add`; this page explains how extension packages are authored, mounted, configured, and overridden.
|
|
9
9
|
|
|
@@ -33,6 +33,7 @@ An extension uses the same file conventions as an agent for its contributions:
|
|
|
33
33
|
connections/api.ts
|
|
34
34
|
skills/triage/SKILL.md
|
|
35
35
|
schedules/sync.ts
|
|
36
|
+
subagents/reviewer/agent.ts
|
|
36
37
|
instructions.md
|
|
37
38
|
hooks/audit.ts
|
|
38
39
|
lib/http.ts
|
|
@@ -40,9 +41,9 @@ An extension uses the same file conventions as an agent for its contributions:
|
|
|
40
41
|
|
|
41
42
|
Each listed slot accepts the same authored forms as its agent counterpart. Static and dynamic tools, skills, and instructions all work in an extension: `extension/instructions.ts` is as valid as `extension/instructions.md`, and `extension/tools/` can contain `defineDynamic(...)`.
|
|
42
43
|
|
|
43
|
-
Names come from paths, so call the tool `search`, not `crm_search`; the consumer's mount adds the `crm__` prefix. The same prefix applies to channel and
|
|
44
|
+
Names come from paths, so call the tool `search`, not `crm_search`; the consumer's mount adds the `crm__` prefix. The same prefix applies to channel, schedule, and parent-visible subagent IDs, while channel route paths and schedule cron expressions stay unchanged. Keep shared code in `extension/lib/`.
|
|
44
45
|
|
|
45
|
-
|
|
46
|
+
The extension root cannot declare agent configuration, a sandbox, or nested extensions. A subagent contributed under `extension/subagents/` owns its own agent configuration and sandbox like any other [declared subagent](./subagents).
|
|
46
47
|
|
|
47
48
|
### Add configuration and contributions
|
|
48
49
|
|
|
@@ -82,6 +83,12 @@ If no configuration is needed, export `defineExtension()` and let consumers re-e
|
|
|
82
83
|
|
|
83
84
|
`defineState` is automatically scoped to the extension package, so the same state name does not collide with the consumer or another extension.
|
|
84
85
|
|
|
86
|
+
### Add a subagent
|
|
87
|
+
|
|
88
|
+
Author a subagent under `extension/subagents/<id>/` using the same files as a subagent declared by an agent. Mounting the extension as `crm` exposes `extension/subagents/reviewer/` to the consuming agent node as `crm__reviewer`. The subagent's own tools, connections, skills, hooks, instructions, sandbox, and nested subagents remain isolated inside its node and keep their path-derived names.
|
|
89
|
+
|
|
90
|
+
Modules inside the contributed subagent can import the extension handle. For example, a tool under `extension/subagents/reviewer/tools/` can read the configuration bound by the consumer's `agent/extensions/crm.ts` mount.
|
|
91
|
+
|
|
85
92
|
### Build and optionally publish
|
|
86
93
|
|
|
87
94
|
The scaffold's `package.json` declares separate source and distribution roots:
|
|
@@ -170,7 +177,7 @@ export default crm({ apiKey: process.env.CRM_API_KEY! });
|
|
|
170
177
|
|
|
171
178
|
Set `CRM_API_KEY` in the consumer's environment, such as `.env.local` for local development.
|
|
172
179
|
|
|
173
|
-
The mount adds `crm__` to named contributions: `tools/search.ts` becomes `crm__search`, `channels/webhook.ts` becomes `crm__webhook`, `schedules/sync.ts` becomes `crm__sync`,
|
|
180
|
+
The mount adds `crm__` to named contributions: `tools/search.ts` becomes `crm__search`, `channels/webhook.ts` becomes `crm__webhook`, `schedules/sync.ts` becomes `crm__sync`, `connections/api.ts` becomes `crm__api`, and `subagents/reviewer/` becomes `crm__reviewer`. Channels keep their declared route paths, and schedules keep their cron expressions.
|
|
174
181
|
|
|
175
182
|
For an extension with no configuration, mount its default export directly:
|
|
176
183
|
|
|
@@ -276,7 +283,7 @@ import crm from "@acme/crm";
|
|
|
276
283
|
export default crm({ apiKey: process.env.CRM_API_KEY! });
|
|
277
284
|
```
|
|
278
285
|
|
|
279
|
-
A same-named consumer channel, tool, connection, skill, or
|
|
286
|
+
A same-named consumer channel, tool, connection, skill, schedule, or subagent wins. To adjust an extension tool, import it from the package's `./tools` export and define it again:
|
|
280
287
|
|
|
281
288
|
```ts title="agent/extensions/crm/tools/search.ts"
|
|
282
289
|
import { search } from "@acme/crm/tools";
|
|
@@ -296,7 +303,7 @@ export default disableTool();
|
|
|
296
303
|
|
|
297
304
|
Hooks and instruction fragments are additive, so they cannot be replaced. To replace a dynamic tool, use a dynamic definition in the same slot; dynamic tools win over same-named static tools at runtime. `disableTool()` removes either kind.
|
|
298
305
|
|
|
299
|
-
The `crm__` prefix is reserved for this directory mount. A consumer cannot override the extension from `agent/tools/`, `agent/connections/`, or another agent-root slot.
|
|
306
|
+
The `crm__` prefix is reserved for this directory mount. A consumer cannot override the extension from `agent/tools/`, `agent/connections/`, `agent/subagents/`, or another agent-root slot.
|
|
300
307
|
|
|
301
308
|
### Use an extension tool result in a hook
|
|
302
309
|
|
|
@@ -333,4 +340,5 @@ At build time, eve checks the extension's generated capability metadata. If the
|
|
|
333
340
|
- [Connections](/docs/connections): integrate external services
|
|
334
341
|
- [Channels](/docs/channels/overview): receive messages and expose routes
|
|
335
342
|
- [Schedules](/docs/schedules): run the agent on a cron cadence
|
|
343
|
+
- [Subagents](/docs/subagents): delegate to declared specialists
|
|
336
344
|
- [Hooks](/docs/guides/hooks): observe agent events
|
package/docs/subagents/index.mdx
CHANGED
|
@@ -50,6 +50,8 @@ export default defineAgent({
|
|
|
50
50
|
|
|
51
51
|
`description` is required. The parent reads it to decide whether to delegate, so the compiler rejects any subagent whose `agent.ts` leaves it out.
|
|
52
52
|
|
|
53
|
+
A mounted extension can also contribute declared subagents from `extension/subagents/`. The mount namespace prefixes the subagent visible to the consuming agent node: mounting an extension as `crm` exposes its `reviewer` subagent as `crm__reviewer`. The contributed subagent keeps its own isolated tools, connections, skills, hooks, instructions, sandbox, and nested subagents, and its modules can read configuration from the extension handle. See [Extensions](./extensions#add-a-subagent) for the authoring and override behavior.
|
|
54
|
+
|
|
53
55
|
### Conditional availability
|
|
54
56
|
|
|
55
57
|
To expose a declared subagent only for certain sessions or turns, export
|
|
@@ -153,7 +155,7 @@ Declared subagents can call nested subagents defined under their own directories
|
|
|
153
155
|
|
|
154
156
|
`Workflow` is also root-only. Child sessions can still call their own declared or remote subagents, but they receive neither `Workflow` nor the built-in `agent`. The Workflow tool's `maxSubagents` option caps the number of calls made by one program (default 100); see [Workflow Tool](./subagents/workflow-tool).
|
|
155
157
|
|
|
156
|
-
A declared subagent's tool name is the bare path-derived name, with no prefix. `agent/subagents/researcher/` registers as the tool `researcher`.
|
|
158
|
+
A directly declared subagent's tool name is the bare path-derived name, with no prefix. `agent/subagents/researcher/` registers as the tool `researcher`. A subagent supplied by a mounted extension includes the mount namespace, such as `crm__reviewer`. The model, approvals, logs, and evals reference the resulting name. Its input schema is:
|
|
157
159
|
|
|
158
160
|
```ts
|
|
159
161
|
{
|