theokit 0.15.2 → 0.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{agent-MN7XGJR3.js → agent-BBK42EPJ.js} +3 -3
- package/dist/{agents-typed-client-SAWAAH7K.js → agents-typed-client-D3LXWGCF.js} +6 -4
- package/dist/agents-typed-client-D3LXWGCF.js.map +1 -0
- package/dist/{agents-typed-client-UTEQUA63.js → agents-typed-client-LQ36PCHL.js} +6 -4
- package/dist/agents-typed-client-LQ36PCHL.js.map +1 -0
- package/dist/{build-QDAFSKKW.js → build-LZ4QSZ63.js} +2 -2
- package/dist/{chunk-UOR6JTCI.js → chunk-3HLO7KAK.js} +235 -40
- package/dist/chunk-3HLO7KAK.js.map +1 -0
- package/dist/{chunk-ZJDKAD3L.js → chunk-7HBLJ5BU.js} +217 -37
- package/dist/chunk-7HBLJ5BU.js.map +1 -0
- package/dist/{chunk-KGFNWIMS.js → chunk-AXVP326H.js} +3 -3
- package/dist/chunk-AXVP326H.js.map +1 -0
- package/dist/{chunk-NBWB4S46.js → chunk-FIZXWL73.js} +11 -2
- package/dist/{chunk-NBWB4S46.js.map → chunk-FIZXWL73.js.map} +1 -1
- package/dist/{chunk-OTFIRP6S.js → chunk-Q6KPASBB.js} +12 -4
- package/dist/chunk-Q6KPASBB.js.map +1 -0
- package/dist/cli/index.js +4 -4
- package/dist/client/index.d.ts +8 -1
- package/dist/client/index.js.map +1 -1
- package/dist/{dev-TEE4T6ZB.js → dev-P4GENSZK.js} +4 -4
- package/dist/index.js +1 -1
- package/dist/server/define/index.d.ts +14 -3
- package/dist/server/define/index.js +1 -1
- package/dist/server/index.js +1 -1
- package/dist/{start-7MQEEQH4.js → start-4VPYN2OS.js} +3 -3
- package/dist/vite-plugin/index.js +1 -1
- package/dist/{vite-plugin-GC6WCU4P.js → vite-plugin-23BBKL3F.js} +4 -4
- package/package.json +3 -2
- package/dist/agents-typed-client-SAWAAH7K.js.map +0 -1
- package/dist/agents-typed-client-UTEQUA63.js.map +0 -1
- package/dist/chunk-KGFNWIMS.js.map +0 -1
- package/dist/chunk-OTFIRP6S.js.map +0 -1
- package/dist/chunk-UOR6JTCI.js.map +0 -1
- package/dist/chunk-ZJDKAD3L.js.map +0 -1
- /package/dist/{agent-MN7XGJR3.js.map → agent-BBK42EPJ.js.map} +0 -0
- /package/dist/{build-QDAFSKKW.js.map → build-LZ4QSZ63.js.map} +0 -0
- /package/dist/{dev-TEE4T6ZB.js.map → dev-P4GENSZK.js.map} +0 -0
- /package/dist/{start-7MQEEQH4.js.map → start-4VPYN2OS.js.map} +0 -0
- /package/dist/{vite-plugin-GC6WCU4P.js.map → vite-plugin-23BBKL3F.js.map} +0 -0
|
@@ -3,7 +3,7 @@ import "tsx/esm";
|
|
|
3
3
|
import {
|
|
4
4
|
getApprovalRegistry,
|
|
5
5
|
resolveProvider
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-FIZXWL73.js";
|
|
7
7
|
import {
|
|
8
8
|
loadEnv
|
|
9
9
|
} from "./chunk-GDN3PXFH.js";
|
|
@@ -178,7 +178,7 @@ async function agentCommand(name, message, deps = {}) {
|
|
|
178
178
|
async function createAgentSsrLoader(projectRoot) {
|
|
179
179
|
const { createServer } = await import("vite");
|
|
180
180
|
const react = (await import("@vitejs/plugin-react")).default;
|
|
181
|
-
const { theoPluginAsync } = await import("./vite-plugin-
|
|
181
|
+
const { theoPluginAsync } = await import("./vite-plugin-23BBKL3F.js");
|
|
182
182
|
const { loadConfig } = await import("./load-config-JKYO5RFK.js");
|
|
183
183
|
const config = await loadConfig(projectRoot);
|
|
184
184
|
const theoPlugins = await theoPluginAsync({
|
|
@@ -206,4 +206,4 @@ async function createAgentSsrLoader(projectRoot) {
|
|
|
206
206
|
export {
|
|
207
207
|
agentCommand
|
|
208
208
|
};
|
|
209
|
-
//# sourceMappingURL=agent-
|
|
209
|
+
//# sourceMappingURL=agent-BBK42EPJ.js.map
|
|
@@ -33,7 +33,9 @@ function generateAgentsDts({
|
|
|
33
33
|
imports.push(
|
|
34
34
|
` import type ${alias} from '${importPath(dtsOutPath, projectRoot, agent.filePath)}'`
|
|
35
35
|
);
|
|
36
|
-
entries.push(
|
|
36
|
+
entries.push(
|
|
37
|
+
` '${agent.name}': { input: InferAgentInput<${alias}>; tools: InferAgentToolNames<${alias}> }`
|
|
38
|
+
);
|
|
37
39
|
}
|
|
38
40
|
const body = entries.length > 0 ? `{
|
|
39
41
|
${entries.join("\n")}
|
|
@@ -44,14 +46,14 @@ ${entries.join("\n")}
|
|
|
44
46
|
` : "";
|
|
45
47
|
return `${FILE_HEADER}
|
|
46
48
|
declare module '@theo/agents' {
|
|
47
|
-
import type { InferAgentInput } from '@theokit/agents'
|
|
49
|
+
import type { InferAgentInput, InferAgentToolNames } from '@theokit/agents'
|
|
48
50
|
import type { UseAgentReturn } from 'theokit/client'
|
|
49
51
|
${importBlock}
|
|
50
52
|
export interface AppAgents ${body}
|
|
51
53
|
|
|
52
54
|
export function useAgent<K extends keyof AppAgents>(
|
|
53
55
|
name: K,
|
|
54
|
-
): UseAgentReturn<AppAgents[K]['input']>
|
|
56
|
+
): UseAgentReturn<AppAgents[K]['input'], AppAgents[K]['tools']>
|
|
55
57
|
}
|
|
56
58
|
`;
|
|
57
59
|
}
|
|
@@ -139,4 +141,4 @@ export {
|
|
|
139
141
|
agentsTypedClientPlugin,
|
|
140
142
|
generateAgentsDts
|
|
141
143
|
};
|
|
142
|
-
//# sourceMappingURL=agents-typed-client-
|
|
144
|
+
//# sourceMappingURL=agents-typed-client-D3LXWGCF.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/vite-plugin/agents-typed-client.ts"],"sourcesContent":["/* eslint-disable security/detect-non-literal-fs-filename --\n * Codegen-time fs ops: all paths derive from `opts.projectRoot` / `opts.distDir`\n * (vite plugin opts — trusted, set by the framework's CLI). Never serves HTTP input.\n */\n/**\n * M2 (theokit-ai-first) — end-to-end typed binding for the `agents/*.ts` convention.\n *\n * Sibling of `app-typed-client.ts` (kept separate so the `@theo/client` output stays\n * byte-unchanged). Two parts:\n *\n * 1. `generateAgentsDts({ manifest, dtsOutPath, projectRoot })` — pure function emitting\n * `.theokit/agents.d.ts` (the virtual `@theo/agents` module) with `AppAgents` mapping\n * each scanned agent to `InferAgentInput` of its `defineAgent({ input })` schema, plus a\n * typed `useAgent` signature — so the client binds to `/api/agents/<name>` with the right\n * request type and ZERO manual wiring (DoD line 2).\n * 2. `agentsTypedClientPlugin(opts)` — Vite plugin that emits (1), rewrites on `agents/*`\n * changes, and serves the virtual `@theo/agents` runtime (`useAgent` from `theokit/client`).\n */\nimport { existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from 'node:fs'\nimport { dirname, posix } from 'node:path'\n\nimport type { Plugin, ViteDevServer } from 'vite'\n\nimport type { TheoManifest } from '../server/internal-api.js'\n\nconst FILE_HEADER = `// AUTO-GENERATED by theokit — do not edit.\n// Source: theokit/packages/theo/src/vite-plugin/agents-typed-client.ts (M2).\n// To refresh: \\`pnpm dev\\` or \\`pnpm build\\` regenerates this on every agents/ change.\n\n/* eslint-disable */\n`\n\n/** A safe TS identifier alias for an agent (name may contain path separators). */\nfunction aliasFor(name: string): string {\n return `_agent_${name.replace(/[^\\w$]/g, '_')}`\n}\n\n/** Relative `import type` path from the .d.ts dir to the agent source (extension stripped). */\nfunction importPath(dtsOutPath: string, projectRoot: string, filePath: string): string {\n const fromDir = dirname(dtsOutPath).replace(/\\\\/g, '/')\n const abs = posix.join(projectRoot.replace(/\\\\/g, '/'), filePath.replace(/\\\\/g, '/'))\n const noExt = abs.replace(/\\.[jt]sx?$/, '')\n let rel = posix.relative(fromDir, noExt)\n if (!rel.startsWith('.')) rel = `./${rel}`\n return rel\n}\n\nexport interface GenerateAgentsDtsOptions {\n manifest: TheoManifest\n /** Absolute path to the .d.ts that will be emitted (drives the import paths). */\n dtsOutPath: string\n /** Absolute project root — agents live at `<projectRoot>/agents`. */\n projectRoot: string\n}\n\nexport function generateAgentsDts({\n manifest,\n dtsOutPath,\n projectRoot,\n}: GenerateAgentsDtsOptions): string {\n const agents = manifest.agents ?? []\n const imports: string[] = []\n const entries: string[] = []\n for (const agent of agents) {\n const alias = aliasFor(agent.name)\n imports.push(\n ` import type ${alias} from '${importPath(dtsOutPath, projectRoot, agent.filePath)}'`,\n )\n entries.push(\n ` '${agent.name}': { input: InferAgentInput<${alias}>; tools: InferAgentToolNames<${alias}> }`,\n )\n }\n\n const body =\n entries.length > 0\n ? `{\\n${entries.join('\\n')}\\n }`\n : `{\\n // No agents detected — add \\`agents/*.ts\\` to populate this binding.\\n }`\n\n const importBlock = imports.length > 0 ? `${imports.join('\\n')}\\n` : ''\n\n return `${FILE_HEADER}\ndeclare module '@theo/agents' {\n import type { InferAgentInput, InferAgentToolNames } from '@theokit/agents'\n import type { UseAgentReturn } from 'theokit/client'\n${importBlock}\n export interface AppAgents ${body}\n\n export function useAgent<K extends keyof AppAgents>(\n name: K,\n ): UseAgentReturn<AppAgents[K]['input'], AppAgents[K]['tools']>\n}\n`\n}\n\n// ─── Vite plugin ─────────────────────────────────────────────────────────────\n\nconst VIRTUAL_AGENTS_ID = '@theo/agents'\nconst RESOLVED_AGENTS_ID = '\\0@theo/agents'\n\nexport interface AgentsTypedClientPluginOptions {\n /** Absolute project root (agents live at `<projectRoot>/agents`). */\n projectRoot: string\n /** Absolute `.theokit/` output dir (where `agents.d.ts` lands). */\n distDir: string\n /** Injects the scanned agents; returns the current manifest-shaped agent list. */\n scanManifest: (projectRoot: string) => TheoManifest\n}\n\n/** Atomic write via tmp + rename; skips when content is unchanged. */\nfunction writeIfChanged(filePath: string, content: string): void {\n if (existsSync(filePath)) {\n try {\n if (readFileSync(filePath, 'utf-8') === content) return\n } catch {\n /* fall through to write */\n }\n }\n mkdirSync(dirname(filePath), { recursive: true })\n const tmp = `${filePath}.${process.pid}.tmp`\n writeFileSync(tmp, content)\n renameSync(tmp, filePath)\n}\n\nfunction emitAgentsDts(opts: AgentsTypedClientPluginOptions): string {\n const dtsOutPath = posix.join(opts.distDir.replace(/\\\\/g, '/'), 'agents.d.ts')\n const content = generateAgentsDts({\n manifest: opts.scanManifest(opts.projectRoot),\n dtsOutPath,\n projectRoot: opts.projectRoot,\n })\n writeIfChanged(dtsOutPath, content)\n return dtsOutPath\n}\n\nexport function agentsTypedClientPlugin(opts: AgentsTypedClientPluginOptions): Plugin {\n let debounce: NodeJS.Timeout | undefined\n let viteServer: ViteDevServer | undefined\n\n const scheduleEmit = (): void => {\n if (debounce) clearTimeout(debounce)\n debounce = setTimeout(() => {\n try {\n emitAgentsDts(opts)\n if (viteServer) {\n const mod = viteServer.moduleGraph.getModuleById(RESOLVED_AGENTS_ID)\n if (mod) viteServer.moduleGraph.invalidateModule(mod)\n }\n } catch (err) {\n console.error('[theokit:agents-typed-client] codegen error:', err)\n }\n }, 100)\n }\n\n return {\n name: 'theokit:agents-typed-client',\n enforce: 'post',\n configResolved() {\n try {\n emitAgentsDts(opts)\n } catch (err) {\n console.error('[theokit:agents-typed-client] initial codegen error:', err)\n }\n },\n buildEnd() {\n try {\n emitAgentsDts(opts)\n } catch (err) {\n console.error('[theokit:agents-typed-client] buildEnd codegen error:', err)\n }\n },\n configureServer(server) {\n viteServer = server\n const agentsGlob = posix.join(opts.projectRoot.replace(/\\\\/g, '/'), 'agents')\n const onFile = (file: string): void => {\n if (file.replace(/\\\\/g, '/').startsWith(agentsGlob)) scheduleEmit()\n }\n server.watcher.on('add', onFile)\n server.watcher.on('change', onFile)\n server.watcher.on('unlink', onFile)\n },\n resolveId(id) {\n return id === VIRTUAL_AGENTS_ID ? RESOLVED_AGENTS_ID : null\n },\n load(id) {\n if (id === RESOLVED_AGENTS_ID) {\n return `export { useAgent } from 'theokit/client'\\n`\n }\n return null\n },\n }\n}\n"],"mappings":";;;AAkBA,SAAS,YAAY,WAAW,cAAc,YAAY,qBAAqB;AAC/E,SAAS,SAAS,aAAa;AAM/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BAAQ,MAAM,yDAAyD,GAAG;AAAA,MAC5E;AAAA,IACF;AAAA,IACA,gBAAgB,QAAQ;AACtB,mBAAa;AACb,YAAM,aAAa,MAAM,KAAK,KAAK,YAAY,QAAQ,OAAO,GAAG,GAAG,QAAQ;AAC5E,YAAM,SAAS,CAAC,SAAuB;AACrC,YAAI,KAAK,QAAQ,OAAO,GAAG,EAAE,WAAW,UAAU,EAAG,cAAa;AAAA,MACpE;AACA,aAAO,QAAQ,GAAG,OAAO,MAAM;AAC/B,aAAO,QAAQ,GAAG,UAAU,MAAM;AAClC,aAAO,QAAQ,GAAG,UAAU,MAAM;AAAA,IACpC;AAAA,IACA,UAAU,IAAI;AACZ,aAAO,OAAO,oBAAoB,qBAAqB;AAAA,IACzD;AAAA,IACA,KAAK,IAAI;AACP,UAAI,OAAO,oBAAoB;AAC7B,eAAO;AAAA;AAAA,MACT;AACA,aAAO;AAAA,IACT;AAAA,EACF;AACF;","names":[]}
|
|
@@ -34,7 +34,9 @@ function generateAgentsDts({
|
|
|
34
34
|
imports.push(
|
|
35
35
|
` import type ${alias} from '${importPath(dtsOutPath, projectRoot, agent.filePath)}'`
|
|
36
36
|
);
|
|
37
|
-
entries.push(
|
|
37
|
+
entries.push(
|
|
38
|
+
` '${agent.name}': { input: InferAgentInput<${alias}>; tools: InferAgentToolNames<${alias}> }`
|
|
39
|
+
);
|
|
38
40
|
}
|
|
39
41
|
const body = entries.length > 0 ? `{
|
|
40
42
|
${entries.join("\n")}
|
|
@@ -45,14 +47,14 @@ ${entries.join("\n")}
|
|
|
45
47
|
` : "";
|
|
46
48
|
return `${FILE_HEADER}
|
|
47
49
|
declare module '@theo/agents' {
|
|
48
|
-
import type { InferAgentInput } from '@theokit/agents'
|
|
50
|
+
import type { InferAgentInput, InferAgentToolNames } from '@theokit/agents'
|
|
49
51
|
import type { UseAgentReturn } from 'theokit/client'
|
|
50
52
|
${importBlock}
|
|
51
53
|
export interface AppAgents ${body}
|
|
52
54
|
|
|
53
55
|
export function useAgent<K extends keyof AppAgents>(
|
|
54
56
|
name: K,
|
|
55
|
-
): UseAgentReturn<AppAgents[K]['input']>
|
|
57
|
+
): UseAgentReturn<AppAgents[K]['input'], AppAgents[K]['tools']>
|
|
56
58
|
}
|
|
57
59
|
`;
|
|
58
60
|
}
|
|
@@ -140,4 +142,4 @@ export {
|
|
|
140
142
|
agentsTypedClientPlugin,
|
|
141
143
|
generateAgentsDts
|
|
142
144
|
};
|
|
143
|
-
//# sourceMappingURL=agents-typed-client-
|
|
145
|
+
//# sourceMappingURL=agents-typed-client-LQ36PCHL.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/vite-plugin/agents-typed-client.ts"],"sourcesContent":["/* eslint-disable security/detect-non-literal-fs-filename --\n * Codegen-time fs ops: all paths derive from `opts.projectRoot` / `opts.distDir`\n * (vite plugin opts — trusted, set by the framework's CLI). Never serves HTTP input.\n */\n/**\n * M2 (theokit-ai-first) — end-to-end typed binding for the `agents/*.ts` convention.\n *\n * Sibling of `app-typed-client.ts` (kept separate so the `@theo/client` output stays\n * byte-unchanged). Two parts:\n *\n * 1. `generateAgentsDts({ manifest, dtsOutPath, projectRoot })` — pure function emitting\n * `.theokit/agents.d.ts` (the virtual `@theo/agents` module) with `AppAgents` mapping\n * each scanned agent to `InferAgentInput` of its `defineAgent({ input })` schema, plus a\n * typed `useAgent` signature — so the client binds to `/api/agents/<name>` with the right\n * request type and ZERO manual wiring (DoD line 2).\n * 2. `agentsTypedClientPlugin(opts)` — Vite plugin that emits (1), rewrites on `agents/*`\n * changes, and serves the virtual `@theo/agents` runtime (`useAgent` from `theokit/client`).\n */\nimport { existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from 'node:fs'\nimport { dirname, posix } from 'node:path'\n\nimport type { Plugin, ViteDevServer } from 'vite'\n\nimport type { TheoManifest } from '../server/internal-api.js'\n\nconst FILE_HEADER = `// AUTO-GENERATED by theokit — do not edit.\n// Source: theokit/packages/theo/src/vite-plugin/agents-typed-client.ts (M2).\n// To refresh: \\`pnpm dev\\` or \\`pnpm build\\` regenerates this on every agents/ change.\n\n/* eslint-disable */\n`\n\n/** A safe TS identifier alias for an agent (name may contain path separators). */\nfunction aliasFor(name: string): string {\n return `_agent_${name.replace(/[^\\w$]/g, '_')}`\n}\n\n/** Relative `import type` path from the .d.ts dir to the agent source (extension stripped). */\nfunction importPath(dtsOutPath: string, projectRoot: string, filePath: string): string {\n const fromDir = dirname(dtsOutPath).replace(/\\\\/g, '/')\n const abs = posix.join(projectRoot.replace(/\\\\/g, '/'), filePath.replace(/\\\\/g, '/'))\n const noExt = abs.replace(/\\.[jt]sx?$/, '')\n let rel = posix.relative(fromDir, noExt)\n if (!rel.startsWith('.')) rel = `./${rel}`\n return rel\n}\n\nexport interface GenerateAgentsDtsOptions {\n manifest: TheoManifest\n /** Absolute path to the .d.ts that will be emitted (drives the import paths). */\n dtsOutPath: string\n /** Absolute project root — agents live at `<projectRoot>/agents`. */\n projectRoot: string\n}\n\nexport function generateAgentsDts({\n manifest,\n dtsOutPath,\n projectRoot,\n}: GenerateAgentsDtsOptions): string {\n const agents = manifest.agents ?? []\n const imports: string[] = []\n const entries: string[] = []\n for (const agent of agents) {\n const alias = aliasFor(agent.name)\n imports.push(\n ` import type ${alias} from '${importPath(dtsOutPath, projectRoot, agent.filePath)}'`,\n )\n entries.push(\n ` '${agent.name}': { input: InferAgentInput<${alias}>; tools: InferAgentToolNames<${alias}> }`,\n )\n }\n\n const body =\n entries.length > 0\n ? `{\\n${entries.join('\\n')}\\n }`\n : `{\\n // No agents detected — add \\`agents/*.ts\\` to populate this binding.\\n }`\n\n const importBlock = imports.length > 0 ? `${imports.join('\\n')}\\n` : ''\n\n return `${FILE_HEADER}\ndeclare module '@theo/agents' {\n import type { InferAgentInput, InferAgentToolNames } from '@theokit/agents'\n import type { UseAgentReturn } from 'theokit/client'\n${importBlock}\n export interface AppAgents ${body}\n\n export function useAgent<K extends keyof AppAgents>(\n name: K,\n ): UseAgentReturn<AppAgents[K]['input'], AppAgents[K]['tools']>\n}\n`\n}\n\n// ─── Vite plugin ─────────────────────────────────────────────────────────────\n\nconst VIRTUAL_AGENTS_ID = '@theo/agents'\nconst RESOLVED_AGENTS_ID = '\\0@theo/agents'\n\nexport interface AgentsTypedClientPluginOptions {\n /** Absolute project root (agents live at `<projectRoot>/agents`). */\n projectRoot: string\n /** Absolute `.theokit/` output dir (where `agents.d.ts` lands). */\n distDir: string\n /** Injects the scanned agents; returns the current manifest-shaped agent list. */\n scanManifest: (projectRoot: string) => TheoManifest\n}\n\n/** Atomic write via tmp + rename; skips when content is unchanged. */\nfunction writeIfChanged(filePath: string, content: string): void {\n if (existsSync(filePath)) {\n try {\n if (readFileSync(filePath, 'utf-8') === content) return\n } catch {\n /* fall through to write */\n }\n }\n mkdirSync(dirname(filePath), { recursive: true })\n const tmp = `${filePath}.${process.pid}.tmp`\n writeFileSync(tmp, content)\n renameSync(tmp, filePath)\n}\n\nfunction emitAgentsDts(opts: AgentsTypedClientPluginOptions): string {\n const dtsOutPath = posix.join(opts.distDir.replace(/\\\\/g, '/'), 'agents.d.ts')\n const content = generateAgentsDts({\n manifest: opts.scanManifest(opts.projectRoot),\n dtsOutPath,\n projectRoot: opts.projectRoot,\n })\n writeIfChanged(dtsOutPath, content)\n return dtsOutPath\n}\n\nexport function agentsTypedClientPlugin(opts: AgentsTypedClientPluginOptions): Plugin {\n let debounce: NodeJS.Timeout | undefined\n let viteServer: ViteDevServer | undefined\n\n const scheduleEmit = (): void => {\n if (debounce) clearTimeout(debounce)\n debounce = setTimeout(() => {\n try {\n emitAgentsDts(opts)\n if (viteServer) {\n const mod = viteServer.moduleGraph.getModuleById(RESOLVED_AGENTS_ID)\n if (mod) viteServer.moduleGraph.invalidateModule(mod)\n }\n } catch (err) {\n console.error('[theokit:agents-typed-client] codegen error:', err)\n }\n }, 100)\n }\n\n return {\n name: 'theokit:agents-typed-client',\n enforce: 'post',\n configResolved() {\n try {\n emitAgentsDts(opts)\n } catch (err) {\n console.error('[theokit:agents-typed-client] initial codegen error:', err)\n }\n },\n buildEnd() {\n try {\n emitAgentsDts(opts)\n } catch (err) {\n console.error('[theokit:agents-typed-client] buildEnd codegen error:', err)\n }\n },\n configureServer(server) {\n viteServer = server\n const agentsGlob = posix.join(opts.projectRoot.replace(/\\\\/g, '/'), 'agents')\n const onFile = (file: string): void => {\n if (file.replace(/\\\\/g, '/').startsWith(agentsGlob)) scheduleEmit()\n }\n server.watcher.on('add', onFile)\n server.watcher.on('change', onFile)\n server.watcher.on('unlink', onFile)\n },\n resolveId(id) {\n return id === VIRTUAL_AGENTS_ID ? RESOLVED_AGENTS_ID : null\n },\n load(id) {\n if (id === RESOLVED_AGENTS_ID) {\n return `export { useAgent } from 'theokit/client'\\n`\n }\n return null\n },\n }\n}\n"],"mappings":";;;;AAkBA,SAAS,YAAY,WAAW,cAAc,YAAY,qBAAqB;AAC/E,SAAS,SAAS,aAAa;AAM/B,IAAM,cAAc;AAAA;AAAA;AAAA;AAAA;AAAA;AAQpB,SAAS,SAAS,MAAsB;AACtC,SAAO,UAAU,KAAK,QAAQ,WAAW,GAAG,CAAC;AAC/C;AAGA,SAAS,WAAW,YAAoB,aAAqB,UAA0B;AACrF,QAAM,UAAU,QAAQ,UAAU,EAAE,QAAQ,OAAO,GAAG;AACtD,QAAM,MAAM,MAAM,KAAK,YAAY,QAAQ,OAAO,GAAG,GAAG,SAAS,QAAQ,OAAO,GAAG,CAAC;AACpF,QAAM,QAAQ,IAAI,QAAQ,cAAc,EAAE;AAC1C,MAAI,MAAM,MAAM,SAAS,SAAS,KAAK;AACvC,MAAI,CAAC,IAAI,WAAW,GAAG,EAAG,OAAM,KAAK,GAAG;AACxC,SAAO;AACT;AAUO,SAAS,kBAAkB;AAAA,EAChC;AAAA,EACA;AAAA,EACA;AACF,GAAqC;AACnC,QAAM,SAAS,SAAS,UAAU,CAAC;AACnC,QAAM,UAAoB,CAAC;AAC3B,QAAM,UAAoB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options) {
|
|
|
531
531
|
`);
|
|
532
532
|
}
|
|
533
533
|
async function runAdapterBuild(target, config, cwd) {
|
|
534
|
-
const { theoPluginAsync } = await import("./vite-plugin-
|
|
534
|
+
const { theoPluginAsync } = await import("./vite-plugin-23BBKL3F.js");
|
|
535
535
|
const { default: react } = await import("@vitejs/plugin-react");
|
|
536
536
|
const ctx = {
|
|
537
537
|
// `react()` may return Plugin or Plugin[] depending on version; spread the
|
|
@@ -606,4 +606,4 @@ function relativize3(absPath, root) {
|
|
|
606
606
|
export {
|
|
607
607
|
buildCommand
|
|
608
608
|
};
|
|
609
|
-
//# sourceMappingURL=build-
|
|
609
|
+
//# sourceMappingURL=build-LZ4QSZ63.js.map
|
|
@@ -984,6 +984,50 @@ function createActionMiddleware(vite, serverDir, options) {
|
|
|
984
984
|
// src/vite-plugin/agent-middleware.ts
|
|
985
985
|
import { randomUUID as randomUUID2 } from "crypto";
|
|
986
986
|
|
|
987
|
+
// src/server/agent/agent-card-handler.ts
|
|
988
|
+
import {
|
|
989
|
+
buildAgentCard,
|
|
990
|
+
compileAgentModule
|
|
991
|
+
} from "@theokit/agents";
|
|
992
|
+
var WELL_KNOWN = /^\/\.well-known\/([^/]+)\/agent-card\.json$/;
|
|
993
|
+
function isAgentCardPath(urlPath) {
|
|
994
|
+
const match = WELL_KNOWN.exec(urlPath);
|
|
995
|
+
return match ? decodeURIComponent(match[1]) : null;
|
|
996
|
+
}
|
|
997
|
+
function toManifestEntry(name, route, mod) {
|
|
998
|
+
const compiled = compileAgentModule(mod, `agent card for "${name}"`);
|
|
999
|
+
return {
|
|
1000
|
+
name,
|
|
1001
|
+
route,
|
|
1002
|
+
stream: compiled.stream,
|
|
1003
|
+
mainLoop: { method: "", strategy: "" },
|
|
1004
|
+
guards: [],
|
|
1005
|
+
interceptors: [],
|
|
1006
|
+
tools: compiled.tools.map((t) => ({
|
|
1007
|
+
name: t.name,
|
|
1008
|
+
description: t.description,
|
|
1009
|
+
approval: false,
|
|
1010
|
+
trace: false,
|
|
1011
|
+
audit: false
|
|
1012
|
+
})),
|
|
1013
|
+
subAgents: []
|
|
1014
|
+
};
|
|
1015
|
+
}
|
|
1016
|
+
function handleAgentCard(mod, name, route, baseUrl) {
|
|
1017
|
+
try {
|
|
1018
|
+
const card = buildAgentCard(toManifestEntry(name, route, mod), { baseUrl });
|
|
1019
|
+
return new Response(JSON.stringify(card), {
|
|
1020
|
+
status: 200,
|
|
1021
|
+
headers: { "content-type": "application/json; charset=utf-8" }
|
|
1022
|
+
});
|
|
1023
|
+
} catch (err) {
|
|
1024
|
+
return new Response(
|
|
1025
|
+
JSON.stringify({ error: { code: "AGENT_CARD_FAILED", message: err instanceof Error ? err.message : "card build failed" } }),
|
|
1026
|
+
{ status: 500, headers: { "content-type": "application/json; charset=utf-8" } }
|
|
1027
|
+
);
|
|
1028
|
+
}
|
|
1029
|
+
}
|
|
1030
|
+
|
|
987
1031
|
// src/server/agent/approval-registry.ts
|
|
988
1032
|
var serverRegistry;
|
|
989
1033
|
function getApprovalRegistry() {
|
|
@@ -1005,7 +1049,13 @@ function createInProcessApprovalRegistry() {
|
|
|
1005
1049
|
const timer = setTimeout(() => {
|
|
1006
1050
|
settle(opts.onTimeout === "proceed");
|
|
1007
1051
|
}, opts.timeoutMs);
|
|
1008
|
-
|
|
1052
|
+
const info = {
|
|
1053
|
+
approvalId,
|
|
1054
|
+
toolName: opts.toolName,
|
|
1055
|
+
question: opts.question,
|
|
1056
|
+
expiresAt: Date.now() + opts.timeoutMs
|
|
1057
|
+
};
|
|
1058
|
+
pending.set(approvalId, { settle, timer, info });
|
|
1009
1059
|
});
|
|
1010
1060
|
},
|
|
1011
1061
|
resolve(approvalId, approved) {
|
|
@@ -1013,6 +1063,9 @@ function createInProcessApprovalRegistry() {
|
|
|
1013
1063
|
if (!entry) return false;
|
|
1014
1064
|
entry.settle(approved);
|
|
1015
1065
|
return true;
|
|
1066
|
+
},
|
|
1067
|
+
list() {
|
|
1068
|
+
return [...pending.values()].map((p) => p.info);
|
|
1016
1069
|
}
|
|
1017
1070
|
};
|
|
1018
1071
|
}
|
|
@@ -1069,9 +1122,94 @@ async function handleAgentApproval(request, urlPath, registry2, csrfMode = "stri
|
|
|
1069
1122
|
});
|
|
1070
1123
|
}
|
|
1071
1124
|
|
|
1125
|
+
// src/server/agent/list-approvals-handler.ts
|
|
1126
|
+
var LIST_PATH = /^\/api\/agents\/([^/]+)\/approvals$/;
|
|
1127
|
+
function isListApprovalsPath(urlPath) {
|
|
1128
|
+
const match = LIST_PATH.exec(urlPath);
|
|
1129
|
+
return match ? decodeURIComponent(match[1]) : null;
|
|
1130
|
+
}
|
|
1131
|
+
function handleListApprovals(registry2) {
|
|
1132
|
+
return new Response(JSON.stringify({ approvals: registry2.list() }), {
|
|
1133
|
+
status: 200,
|
|
1134
|
+
headers: { "content-type": "application/json; charset=utf-8" }
|
|
1135
|
+
});
|
|
1136
|
+
}
|
|
1137
|
+
|
|
1138
|
+
// src/server/agent/mcp-handler.ts
|
|
1139
|
+
import {
|
|
1140
|
+
buildMcpToolDescriptors,
|
|
1141
|
+
compileAgentModule as compileAgentModule2,
|
|
1142
|
+
mcpServerInfo
|
|
1143
|
+
} from "@theokit/agents";
|
|
1144
|
+
var MCP_PATH = /^\/api\/agents\/([^/]+)\/mcp$/;
|
|
1145
|
+
function isMcpPath(urlPath) {
|
|
1146
|
+
const match = MCP_PATH.exec(urlPath);
|
|
1147
|
+
return match ? decodeURIComponent(match[1]) : null;
|
|
1148
|
+
}
|
|
1149
|
+
function isJsonRpcRequest(body) {
|
|
1150
|
+
return typeof body === "object" && body !== null && body.jsonrpc === "2.0" && typeof body.method === "string";
|
|
1151
|
+
}
|
|
1152
|
+
function jsonResponse(payload) {
|
|
1153
|
+
return new Response(JSON.stringify(payload), {
|
|
1154
|
+
status: 200,
|
|
1155
|
+
headers: { "content-type": "application/json; charset=utf-8" }
|
|
1156
|
+
});
|
|
1157
|
+
}
|
|
1158
|
+
function toEntry(name, mod) {
|
|
1159
|
+
const compiled = compileAgentModule2(mod, `mcp server for "${name}"`);
|
|
1160
|
+
return {
|
|
1161
|
+
name,
|
|
1162
|
+
route: `/api/agents/${name}`,
|
|
1163
|
+
stream: compiled.stream,
|
|
1164
|
+
mainLoop: { method: "", strategy: "" },
|
|
1165
|
+
guards: [],
|
|
1166
|
+
interceptors: [],
|
|
1167
|
+
tools: compiled.tools.map((t) => ({
|
|
1168
|
+
name: t.name,
|
|
1169
|
+
description: t.description,
|
|
1170
|
+
approval: false,
|
|
1171
|
+
trace: false,
|
|
1172
|
+
audit: false
|
|
1173
|
+
})),
|
|
1174
|
+
subAgents: []
|
|
1175
|
+
};
|
|
1176
|
+
}
|
|
1177
|
+
function handleMcpJsonRpc(mod, name, body) {
|
|
1178
|
+
if (!isJsonRpcRequest(body)) {
|
|
1179
|
+
return jsonResponse({ jsonrpc: "2.0", id: null, error: { code: -32600, message: "Invalid Request" } });
|
|
1180
|
+
}
|
|
1181
|
+
const { id, method } = body;
|
|
1182
|
+
try {
|
|
1183
|
+
const entry = toEntry(name, mod);
|
|
1184
|
+
if (method === "initialize") {
|
|
1185
|
+
const info = mcpServerInfo(entry);
|
|
1186
|
+
return jsonResponse({
|
|
1187
|
+
jsonrpc: "2.0",
|
|
1188
|
+
id,
|
|
1189
|
+
result: {
|
|
1190
|
+
protocolVersion: info.protocolVersion,
|
|
1191
|
+
capabilities: { tools: {} },
|
|
1192
|
+
serverInfo: { name: info.name, version: info.version }
|
|
1193
|
+
}
|
|
1194
|
+
});
|
|
1195
|
+
}
|
|
1196
|
+
if (method === "tools/list") {
|
|
1197
|
+
return jsonResponse({ jsonrpc: "2.0", id, result: { tools: buildMcpToolDescriptors(entry) } });
|
|
1198
|
+
}
|
|
1199
|
+
return jsonResponse({ jsonrpc: "2.0", id, error: { code: -32601, message: `Method not found: ${method}` } });
|
|
1200
|
+
} catch (err) {
|
|
1201
|
+
return jsonResponse({
|
|
1202
|
+
jsonrpc: "2.0",
|
|
1203
|
+
id,
|
|
1204
|
+
error: { code: -32603, message: err instanceof Error ? err.message : "Internal error" }
|
|
1205
|
+
});
|
|
1206
|
+
}
|
|
1207
|
+
}
|
|
1208
|
+
|
|
1072
1209
|
// src/server/agent/mount-agent.ts
|
|
1073
1210
|
import {
|
|
1074
|
-
compileAgentModule,
|
|
1211
|
+
compileAgentModule as compileAgentModule3,
|
|
1212
|
+
resolveEnabledSkills,
|
|
1075
1213
|
streamAgentUIMessages
|
|
1076
1214
|
} from "@theokit/agents";
|
|
1077
1215
|
function partText(part) {
|
|
@@ -1109,7 +1247,11 @@ async function mountAgent(mod, request, apiKey, source = "agent module", csrfMod
|
|
|
1109
1247
|
return jsonError2(403, "CSRF_FAILED", `CSRF check failed: ${csrf.reason}`);
|
|
1110
1248
|
}
|
|
1111
1249
|
}
|
|
1112
|
-
const compiled =
|
|
1250
|
+
const compiled = compileAgentModule3(mod, source);
|
|
1251
|
+
if (compiled.skillsResolver) {
|
|
1252
|
+
const enabled = await resolveEnabledSkills(compiled.skillsResolver, compiled.runContext ?? {});
|
|
1253
|
+
if (enabled !== void 0) compiled.skills = { enabled, autoInject: true };
|
|
1254
|
+
}
|
|
1113
1255
|
let body = null;
|
|
1114
1256
|
try {
|
|
1115
1257
|
body = await request.json();
|
|
@@ -1123,9 +1265,12 @@ async function mountAgent(mod, request, apiKey, source = "agent module", csrfMod
|
|
|
1123
1265
|
const registry2 = getApprovalRegistry();
|
|
1124
1266
|
const hitl = gated && gated.size > 0 ? {
|
|
1125
1267
|
gated,
|
|
1126
|
-
awaitApproval: (approvalId, opts) => registry2.register(approvalId, {
|
|
1268
|
+
awaitApproval: (approvalId, opts, toolName) => registry2.register(approvalId, {
|
|
1127
1269
|
timeoutMs: opts.timeout ?? 3e5,
|
|
1128
|
-
onTimeout: opts.onTimeout ?? "abort"
|
|
1270
|
+
onTimeout: opts.onTimeout ?? "abort",
|
|
1271
|
+
// M14 — surface toolName + question in GET /approvals (the plugin forwards c.name).
|
|
1272
|
+
toolName,
|
|
1273
|
+
question: opts.question
|
|
1129
1274
|
})
|
|
1130
1275
|
} : void 0;
|
|
1131
1276
|
return uiMessageStreamResponse(
|
|
@@ -1239,11 +1384,84 @@ function pickHeaderString(value) {
|
|
|
1239
1384
|
|
|
1240
1385
|
// src/vite-plugin/agent-middleware.ts
|
|
1241
1386
|
var PREFIX2 = "/api/agents/";
|
|
1387
|
+
async function serveApprove(req, res, urlPath, csrfMode, log) {
|
|
1388
|
+
const method = (req.method ?? "POST").toUpperCase();
|
|
1389
|
+
if (method !== "POST") {
|
|
1390
|
+
sendError(res, "METHOD_NOT_ALLOWED", "Approve endpoints accept POST", 405, void 0, log.requestId);
|
|
1391
|
+
logRequest({ method, url: req.url ?? "", status: 405, duration: Date.now() - log.start, requestId: log.requestId });
|
|
1392
|
+
return;
|
|
1393
|
+
}
|
|
1394
|
+
try {
|
|
1395
|
+
const response = await handleAgentApproval(incomingMessageToWebRequest(req), urlPath, getApprovalRegistry(), csrfMode);
|
|
1396
|
+
await writeWebResponseToServerResponse(response, res);
|
|
1397
|
+
} catch (err) {
|
|
1398
|
+
sendError(res, "INTERNAL", err instanceof Error ? err.message : "Approve handler failed", 500, void 0, log.requestId);
|
|
1399
|
+
}
|
|
1400
|
+
logRequest({ method, url: req.url ?? "", status: res.statusCode, duration: Date.now() - log.start, requestId: log.requestId });
|
|
1401
|
+
}
|
|
1402
|
+
async function serveMcp(req, res, next, mcpAgentName, deps) {
|
|
1403
|
+
const requestId = randomUUID2();
|
|
1404
|
+
const start = Date.now();
|
|
1405
|
+
res.setHeader("x-request-id", requestId);
|
|
1406
|
+
const method = (req.method ?? "POST").toUpperCase();
|
|
1407
|
+
const agent = scanAgents(deps.projectRoot).find((a) => a.name === mcpAgentName);
|
|
1408
|
+
if (method !== "POST" || !agent) {
|
|
1409
|
+
next();
|
|
1410
|
+
return;
|
|
1411
|
+
}
|
|
1412
|
+
try {
|
|
1413
|
+
const body = await incomingMessageToWebRequest(req).json();
|
|
1414
|
+
const mod = await deps.loadModule(agent.filePath);
|
|
1415
|
+
await writeWebResponseToServerResponse(handleMcpJsonRpc(mod, agent.name, body), res);
|
|
1416
|
+
} catch (err) {
|
|
1417
|
+
sendError(res, "INTERNAL", err instanceof Error ? err.message : "MCP handler failed", 500, void 0, requestId);
|
|
1418
|
+
}
|
|
1419
|
+
logRequest({ method, url: req.url ?? "", status: res.statusCode, duration: Date.now() - start, requestId });
|
|
1420
|
+
}
|
|
1421
|
+
async function serveListApprovals(req, res, next, log) {
|
|
1422
|
+
const method = (req.method ?? "GET").toUpperCase();
|
|
1423
|
+
if (method !== "GET") {
|
|
1424
|
+
next();
|
|
1425
|
+
return;
|
|
1426
|
+
}
|
|
1427
|
+
await writeWebResponseToServerResponse(handleListApprovals(getApprovalRegistry()), res);
|
|
1428
|
+
logRequest({
|
|
1429
|
+
method,
|
|
1430
|
+
url: req.url ?? "",
|
|
1431
|
+
status: res.statusCode,
|
|
1432
|
+
duration: Date.now() - log.start,
|
|
1433
|
+
requestId: log.requestId
|
|
1434
|
+
});
|
|
1435
|
+
}
|
|
1436
|
+
async function serveAgentCard(req, res, next, cardAgentName, deps) {
|
|
1437
|
+
const requestId = randomUUID2();
|
|
1438
|
+
const start = Date.now();
|
|
1439
|
+
res.setHeader("x-request-id", requestId);
|
|
1440
|
+
const method = (req.method ?? "GET").toUpperCase();
|
|
1441
|
+
const agent = scanAgents(deps.projectRoot).find((a) => a.name === cardAgentName);
|
|
1442
|
+
if (method !== "GET" || !agent) {
|
|
1443
|
+
next();
|
|
1444
|
+
return;
|
|
1445
|
+
}
|
|
1446
|
+
try {
|
|
1447
|
+
const mod = await deps.loadModule(agent.filePath);
|
|
1448
|
+
const baseUrl = `http://${req.headers.host ?? "localhost"}`;
|
|
1449
|
+
await writeWebResponseToServerResponse(handleAgentCard(mod, agent.name, agent.agentPath, baseUrl), res);
|
|
1450
|
+
} catch (err) {
|
|
1451
|
+
sendError(res, "INTERNAL", err instanceof Error ? err.message : "Agent card failed", 500, void 0, requestId);
|
|
1452
|
+
}
|
|
1453
|
+
logRequest({ method, url: req.url ?? "", status: res.statusCode, duration: Date.now() - start, requestId });
|
|
1454
|
+
}
|
|
1242
1455
|
function createAgentMiddleware(vite, projectRoot, csrfMode = "strict") {
|
|
1243
1456
|
const loadModule = createViteLoader(vite);
|
|
1244
1457
|
return (req, res, next) => {
|
|
1245
1458
|
void (async () => {
|
|
1246
1459
|
const url = req.url ?? "";
|
|
1460
|
+
const cardAgentName = isAgentCardPath(url.split("?")[0]);
|
|
1461
|
+
if (cardAgentName) {
|
|
1462
|
+
await serveAgentCard(req, res, next, cardAgentName, { projectRoot, loadModule });
|
|
1463
|
+
return;
|
|
1464
|
+
}
|
|
1247
1465
|
if (!url.startsWith(PREFIX2)) {
|
|
1248
1466
|
next();
|
|
1249
1467
|
return;
|
|
@@ -1253,39 +1471,16 @@ function createAgentMiddleware(vite, projectRoot, csrfMode = "strict") {
|
|
|
1253
1471
|
res.setHeader("x-request-id", requestId);
|
|
1254
1472
|
const urlPath = url.split("?")[0];
|
|
1255
1473
|
if (isApprovalPath(urlPath)) {
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
logRequest({ method: method2, url, status: 405, duration: Date.now() - start, requestId });
|
|
1267
|
-
return;
|
|
1268
|
-
}
|
|
1269
|
-
try {
|
|
1270
|
-
const request = incomingMessageToWebRequest(req);
|
|
1271
|
-
const response = await handleAgentApproval(
|
|
1272
|
-
request,
|
|
1273
|
-
urlPath,
|
|
1274
|
-
getApprovalRegistry(),
|
|
1275
|
-
csrfMode
|
|
1276
|
-
);
|
|
1277
|
-
await writeWebResponseToServerResponse(response, res);
|
|
1278
|
-
} catch (err) {
|
|
1279
|
-
sendError(
|
|
1280
|
-
res,
|
|
1281
|
-
"INTERNAL",
|
|
1282
|
-
err instanceof Error ? err.message : "Approve handler failed",
|
|
1283
|
-
500,
|
|
1284
|
-
void 0,
|
|
1285
|
-
requestId
|
|
1286
|
-
);
|
|
1287
|
-
}
|
|
1288
|
-
logRequest({ method: method2, url, status: res.statusCode, duration: Date.now() - start, requestId });
|
|
1474
|
+
await serveApprove(req, res, urlPath, csrfMode, { requestId, start });
|
|
1475
|
+
return;
|
|
1476
|
+
}
|
|
1477
|
+
if (isListApprovalsPath(urlPath)) {
|
|
1478
|
+
await serveListApprovals(req, res, next, { requestId, start });
|
|
1479
|
+
return;
|
|
1480
|
+
}
|
|
1481
|
+
const mcpAgentName = isMcpPath(urlPath);
|
|
1482
|
+
if (mcpAgentName) {
|
|
1483
|
+
await serveMcp(req, res, next, mcpAgentName, { projectRoot, loadModule });
|
|
1289
1484
|
return;
|
|
1290
1485
|
}
|
|
1291
1486
|
const agent = scanAgents(projectRoot).find((a) => a.agentPath === urlPath);
|
|
@@ -2699,7 +2894,7 @@ async function theoPluginAsync(rootOrOptions) {
|
|
|
2699
2894
|
serverDir: resolve9(projectRoot, "server"),
|
|
2700
2895
|
distDir: resolve9(projectRoot, ".theokit")
|
|
2701
2896
|
});
|
|
2702
|
-
const { agentsTypedClientPlugin } = await import("./agents-typed-client-
|
|
2897
|
+
const { agentsTypedClientPlugin } = await import("./agents-typed-client-D3LXWGCF.js");
|
|
2703
2898
|
const { generateManifest } = await import("./internal-api-5BDI6N5U.js");
|
|
2704
2899
|
const agentsClientPlugin = agentsTypedClientPlugin({
|
|
2705
2900
|
projectRoot,
|
|
@@ -2878,4 +3073,4 @@ export {
|
|
|
2878
3073
|
theoPluginAsync,
|
|
2879
3074
|
theoPlugin
|
|
2880
3075
|
};
|
|
2881
|
-
//# sourceMappingURL=chunk-
|
|
3076
|
+
//# sourceMappingURL=chunk-3HLO7KAK.js.map
|