theokit 0.76.2 → 0.77.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/README.md +59 -0
- package/dist/{actions-virtual-module-52O6HJZT.js → actions-virtual-module-UIX5YWZR.js} +4 -4
- package/dist/{actions-virtual-module-HS4W7HQU.js → actions-virtual-module-V5Q4XVL5.js} +2 -2
- package/dist/add-DOR7HORT.js +23 -0
- package/dist/{agent-HCK5RHH7.js → agent-MJWQRSJ2.js} +2 -2
- package/dist/{app-typed-client-CJCOALMM.js → app-typed-client-6FQB5FQO.js} +4 -4
- package/dist/{app-typed-client-BWITJLJA.js → app-typed-client-JCBQGPMP.js} +2 -2
- package/dist/{build-Y3CWTWP6.js → build-QDZEOCJ3.js} +4 -4
- package/dist/{chunk-W2I6L4IJ.js → chunk-35OI2TKT.js} +2 -2
- package/dist/{chunk-OIYSUQM7.js → chunk-3TCWOHLY.js} +4 -2
- package/dist/{chunk-OIYSUQM7.js.map → chunk-3TCWOHLY.js.map} +1 -1
- package/dist/{chunk-UQQQ3V43.js → chunk-3XR6CBUA.js} +65 -5
- package/dist/chunk-3XR6CBUA.js.map +1 -0
- package/dist/{chunk-BTDTHXUI.js → chunk-BFDEEJOK.js} +1 -1
- package/dist/{chunk-BTDTHXUI.js.map → chunk-BFDEEJOK.js.map} +1 -1
- package/dist/{chunk-XI4FALFZ.js → chunk-E22GPCCO.js} +24 -1
- package/dist/chunk-E22GPCCO.js.map +1 -0
- package/dist/{chunk-OED37LE5.js → chunk-GNV34JMI.js} +37 -3
- package/dist/chunk-GNV34JMI.js.map +1 -0
- package/dist/{chunk-2SGNODVJ.js → chunk-HNALEGOL.js} +40 -10
- package/dist/chunk-HNALEGOL.js.map +1 -0
- package/dist/{chunk-ZQJORKBM.js → chunk-HZAXFD55.js} +49 -2
- package/dist/chunk-HZAXFD55.js.map +1 -0
- package/dist/{add-3VLFUPF4.js → chunk-JVXDEIT4.js} +15 -12
- package/dist/chunk-JVXDEIT4.js.map +1 -0
- package/dist/{chunk-PVCXREGE.js → chunk-KQBY62AE.js} +2 -2
- package/dist/{chunk-BXQCJJPT.js → chunk-N5YHENWJ.js} +2 -2
- package/dist/{chunk-FEK25JUL.js → chunk-OKFRGAYZ.js} +67 -9
- package/dist/chunk-OKFRGAYZ.js.map +1 -0
- package/dist/{chunk-XDLFOATW.js → chunk-OSSNCUS6.js} +4 -4
- package/dist/{chunk-C2BRSL4W.js → chunk-PQWVT6JC.js} +11 -1
- package/dist/{chunk-C2BRSL4W.js.map → chunk-PQWVT6JC.js.map} +1 -1
- package/dist/{chunk-47FFT43U.js → chunk-YH5CDWLU.js} +25 -1
- package/dist/chunk-YH5CDWLU.js.map +1 -0
- package/dist/cli/index.js +12 -12
- package/dist/{db-ZWDKD57T.js → db-5WOK6HA2.js} +3 -3
- package/dist/{define-middleware-BOHpPOBs.d.ts → define-middleware-D7LFaTv-.d.ts} +27 -2
- package/dist/{dev-R2ZYHZV4.js → dev-N5LQFLBR.js} +9 -7
- package/dist/dev-N5LQFLBR.js.map +1 -0
- package/dist/{generate-ORWEIXCL.js → generate-OA5ARO3P.js} +120 -52
- package/dist/generate-OA5ARO3P.js.map +1 -0
- package/dist/{index-DfsJ3Qhk.d.ts → index-C2lcEI-4.d.ts} +2 -2
- package/dist/index.d.ts +1 -0
- package/dist/index.js +5 -4
- package/dist/index.js.map +1 -1
- package/dist/{info-IPMW56PI.js → info-ELSPSCXK.js} +3 -3
- package/dist/{internal-api-6RAOYIET.js → internal-api-5FTPYSEQ.js} +2 -2
- package/dist/{internal-api-YGFPLQ4E.js → internal-api-H3C2ID6N.js} +4 -4
- package/dist/{job-backend-WvUs5rO1.d.ts → job-backend-BX-PwnZW.d.ts} +25 -0
- package/dist/{load-config-USRR4GXP.js → load-config-SKLFH7YL.js} +3 -3
- package/dist/{mcp-FBXEX45H.js → mcp-3ENI2IPS.js} +3 -3
- package/dist/{openapi-CA3E3LZH.js → openapi-OVXYHZ2S.js} +3 -3
- package/dist/{preview-DLIVPM7A.js → preview-GP6J6IGJ.js} +3 -3
- package/dist/{routes-BJ7GGRCV.js → routes-UNJ77IQU.js} +3 -3
- package/dist/{schema-FBM2UH72.js → schema-2EAIJFWA.js} +2 -2
- package/dist/server/define/index.d.ts +5 -4
- package/dist/server/define/index.js +1 -1
- package/dist/server/http/index.d.ts +4 -3
- package/dist/server/http/index.js +3 -3
- package/dist/server/index.d.ts +5 -5
- package/dist/server/index.js +7 -5
- package/dist/server/index.js.map +1 -1
- package/dist/server/jobs/index.d.ts +75 -6
- package/dist/server/jobs/index.js +4 -2
- package/dist/{server-boundary-EKIGYL7B.js → server-boundary-5ZTBC2KF.js} +2 -2
- package/dist/{server-boundary-IDWIB24L.js → server-boundary-DTF6ZEUO.js} +4 -4
- package/dist/{start-LNT5UVSY.js → start-EJFYT7ZU.js} +13 -37
- package/dist/start-EJFYT7ZU.js.map +1 -0
- package/dist/vite-plugin/index.js +5 -4
- package/dist/{vite-plugin-LE42ZIGV.js → vite-plugin-MNZHNOM4.js} +6 -6
- package/dist/vite-plugin-MNZHNOM4.js.map +1 -0
- package/package.json +1 -1
- package/dist/add-3VLFUPF4.js.map +0 -1
- package/dist/chunk-2SGNODVJ.js.map +0 -1
- package/dist/chunk-47FFT43U.js.map +0 -1
- package/dist/chunk-FEK25JUL.js.map +0 -1
- package/dist/chunk-OED37LE5.js.map +0 -1
- package/dist/chunk-UQQQ3V43.js.map +0 -1
- package/dist/chunk-XI4FALFZ.js.map +0 -1
- package/dist/chunk-ZQJORKBM.js.map +0 -1
- package/dist/dev-R2ZYHZV4.js.map +0 -1
- package/dist/generate-ORWEIXCL.js.map +0 -1
- package/dist/start-LNT5UVSY.js.map +0 -1
- /package/dist/{actions-virtual-module-52O6HJZT.js.map → actions-virtual-module-UIX5YWZR.js.map} +0 -0
- /package/dist/{actions-virtual-module-HS4W7HQU.js.map → actions-virtual-module-V5Q4XVL5.js.map} +0 -0
- /package/dist/{agent-HCK5RHH7.js.map → add-DOR7HORT.js.map} +0 -0
- /package/dist/{internal-api-6RAOYIET.js.map → agent-MJWQRSJ2.js.map} +0 -0
- /package/dist/{app-typed-client-CJCOALMM.js.map → app-typed-client-6FQB5FQO.js.map} +0 -0
- /package/dist/{app-typed-client-BWITJLJA.js.map → app-typed-client-JCBQGPMP.js.map} +0 -0
- /package/dist/{build-Y3CWTWP6.js.map → build-QDZEOCJ3.js.map} +0 -0
- /package/dist/{chunk-W2I6L4IJ.js.map → chunk-35OI2TKT.js.map} +0 -0
- /package/dist/{chunk-PVCXREGE.js.map → chunk-KQBY62AE.js.map} +0 -0
- /package/dist/{chunk-BXQCJJPT.js.map → chunk-N5YHENWJ.js.map} +0 -0
- /package/dist/{chunk-XDLFOATW.js.map → chunk-OSSNCUS6.js.map} +0 -0
- /package/dist/{db-ZWDKD57T.js.map → db-5WOK6HA2.js.map} +0 -0
- /package/dist/{info-IPMW56PI.js.map → info-ELSPSCXK.js.map} +0 -0
- /package/dist/{load-config-USRR4GXP.js.map → internal-api-5FTPYSEQ.js.map} +0 -0
- /package/dist/{internal-api-YGFPLQ4E.js.map → internal-api-H3C2ID6N.js.map} +0 -0
- /package/dist/{schema-FBM2UH72.js.map → load-config-SKLFH7YL.js.map} +0 -0
- /package/dist/{mcp-FBXEX45H.js.map → mcp-3ENI2IPS.js.map} +0 -0
- /package/dist/{openapi-CA3E3LZH.js.map → openapi-OVXYHZ2S.js.map} +0 -0
- /package/dist/{preview-DLIVPM7A.js.map → preview-GP6J6IGJ.js.map} +0 -0
- /package/dist/{routes-BJ7GGRCV.js.map → routes-UNJ77IQU.js.map} +0 -0
- /package/dist/{vite-plugin-LE42ZIGV.js.map → schema-2EAIJFWA.js.map} +0 -0
- /package/dist/{server-boundary-EKIGYL7B.js.map → server-boundary-5ZTBC2KF.js.map} +0 -0
- /package/dist/{server-boundary-IDWIB24L.js.map → server-boundary-DTF6ZEUO.js.map} +0 -0
package/dist/cli/index.js
CHANGED
|
@@ -15,7 +15,7 @@ function cliVersion() {
|
|
|
15
15
|
// src/cli/index.ts
|
|
16
16
|
var cli = cac("theokit");
|
|
17
17
|
cli.command("dev", "Start development server").option("--port <port>", "Port number").option("--crons", "Schedule the crons in dev too (off by default)").action(async (options) => {
|
|
18
|
-
const { devCommand } = await import("../dev-
|
|
18
|
+
const { devCommand } = await import("../dev-N5LQFLBR.js");
|
|
19
19
|
await devCommand({
|
|
20
20
|
port: options.port ? Number(options.port) : void 0,
|
|
21
21
|
crons: options.crons === true
|
|
@@ -23,7 +23,7 @@ cli.command("dev", "Start development server").option("--port <port>", "Port num
|
|
|
23
23
|
});
|
|
24
24
|
cli.command("build", "Build for production").option("--target <target>", "Deploy target (node, vercel, cloudflare)").action(async (options) => {
|
|
25
25
|
try {
|
|
26
|
-
const { buildCommand } = await import("../build-
|
|
26
|
+
const { buildCommand } = await import("../build-QDZEOCJ3.js");
|
|
27
27
|
await buildCommand({ target: options.target });
|
|
28
28
|
} catch (err) {
|
|
29
29
|
const msg = err instanceof Error ? err.message : String(err);
|
|
@@ -35,7 +35,7 @@ cli.command("build", "Build for production").option("--target <target>", "Deploy
|
|
|
35
35
|
});
|
|
36
36
|
cli.command("start", "Start production server").option("--port <port>", "Port number").action(async (options) => {
|
|
37
37
|
try {
|
|
38
|
-
const { startCommand } = await import("../start-
|
|
38
|
+
const { startCommand } = await import("../start-EJFYT7ZU.js");
|
|
39
39
|
await startCommand({ port: options.port ? Number(options.port) : void 0 });
|
|
40
40
|
} catch (err) {
|
|
41
41
|
const msg = err instanceof Error ? err.message : String(err);
|
|
@@ -47,7 +47,7 @@ cli.command("start", "Start production server").option("--port <port>", "Port nu
|
|
|
47
47
|
});
|
|
48
48
|
cli.command("preview", "Build for production, then serve it \u2014 one step (B-030)").option("--port <port>", "Port number").option("--target <target>", "Deploy target (node, vercel, cloudflare)").action(async (options) => {
|
|
49
49
|
try {
|
|
50
|
-
const { previewCommand } = await import("../preview-
|
|
50
|
+
const { previewCommand } = await import("../preview-GP6J6IGJ.js");
|
|
51
51
|
await previewCommand({
|
|
52
52
|
port: options.port ? Number(options.port) : void 0,
|
|
53
53
|
target: options.target
|
|
@@ -65,7 +65,7 @@ cli.command(
|
|
|
65
65
|
"Scaffold a route, action, page, ws, controller, agent, toolbox, workflow, eval, sandbox, schedule, memory, or resource (resource accepts field:type args)"
|
|
66
66
|
).action(async (type, name, fields) => {
|
|
67
67
|
try {
|
|
68
|
-
const { generateCommand } = await import("../generate-
|
|
68
|
+
const { generateCommand } = await import("../generate-OA5ARO3P.js");
|
|
69
69
|
await generateCommand(type, name, fields.length > 0 ? fields : void 0);
|
|
70
70
|
} catch (err) {
|
|
71
71
|
const msg = err instanceof Error ? err.message : String(err);
|
|
@@ -80,7 +80,7 @@ cli.command(
|
|
|
80
80
|
"Run an agent in the terminal (stream + tool calls + approval)"
|
|
81
81
|
).action(async (name, message) => {
|
|
82
82
|
try {
|
|
83
|
-
const { agentCommand } = await import("../agent-
|
|
83
|
+
const { agentCommand } = await import("../agent-MJWQRSJ2.js");
|
|
84
84
|
const { sawError } = await agentCommand(name, message);
|
|
85
85
|
if (sawError) process.exit(1);
|
|
86
86
|
} catch (err) {
|
|
@@ -111,7 +111,7 @@ cli.command("agent sessions gc", "Collect old transcripts for this project (dry
|
|
|
111
111
|
});
|
|
112
112
|
cli.command("mcp <agent>", "Serve an agent as an MCP server over stdio (for desktop MCP clients)").action(async (agent) => {
|
|
113
113
|
try {
|
|
114
|
-
const { mcpCommand } = await import("../mcp-
|
|
114
|
+
const { mcpCommand } = await import("../mcp-3ENI2IPS.js");
|
|
115
115
|
await mcpCommand(agent);
|
|
116
116
|
} catch (err) {
|
|
117
117
|
const msg = err instanceof Error ? err.message : String(err);
|
|
@@ -123,7 +123,7 @@ cli.command("mcp <agent>", "Serve an agent as an MCP server over stdio (for desk
|
|
|
123
123
|
});
|
|
124
124
|
cli.command("routes", "List all routes, actions, and WebSocket endpoints").action(async () => {
|
|
125
125
|
try {
|
|
126
|
-
const { routesCommand } = await import("../routes-
|
|
126
|
+
const { routesCommand } = await import("../routes-UNJ77IQU.js");
|
|
127
127
|
await routesCommand();
|
|
128
128
|
} catch (err) {
|
|
129
129
|
const msg = err instanceof Error ? err.message : String(err);
|
|
@@ -160,11 +160,11 @@ cli.command("check", "Run typecheck + scan + (optional) eslint").option(
|
|
|
160
160
|
await checkCommand();
|
|
161
161
|
});
|
|
162
162
|
cli.command("add <package>", "Install a known TheoKit adapter or plugin (whitelist-only)").action(async (pkg) => {
|
|
163
|
-
const { addCommand } = await import("../add-
|
|
163
|
+
const { addCommand } = await import("../add-DOR7HORT.js");
|
|
164
164
|
await addCommand(pkg);
|
|
165
165
|
});
|
|
166
166
|
cli.command("info", "Print environment info (runtime, config, routes)").action(async () => {
|
|
167
|
-
const { infoCommand } = await import("../info-
|
|
167
|
+
const { infoCommand } = await import("../info-ELSPSCXK.js");
|
|
168
168
|
await infoCommand();
|
|
169
169
|
});
|
|
170
170
|
cli.command("doctor", "Report the RESOLVED state of this installation (never prints a secret)").action(async () => {
|
|
@@ -176,7 +176,7 @@ cli.command(
|
|
|
176
176
|
"Generate <distDir>/openapi.json from route schemas (opt-in via config.openapi)"
|
|
177
177
|
).option("--dry-run", "Print the document to stdout without writing to disk (EC-3)").action(async (options) => {
|
|
178
178
|
try {
|
|
179
|
-
const { openapiCommand } = await import("../openapi-
|
|
179
|
+
const { openapiCommand } = await import("../openapi-OVXYHZ2S.js");
|
|
180
180
|
await openapiCommand({ dryRun: Boolean(options.dryRun) });
|
|
181
181
|
} catch (err) {
|
|
182
182
|
const msg = err instanceof Error ? err.message : String(err);
|
|
@@ -238,7 +238,7 @@ cli.command(
|
|
|
238
238
|
"Database commands: generate (write SQL migration files), migrate (apply them), push (diff the schema into the database, no files), seed"
|
|
239
239
|
).action(async (action) => {
|
|
240
240
|
try {
|
|
241
|
-
const { dbCommandCli } = await import("../db-
|
|
241
|
+
const { dbCommandCli } = await import("../db-5WOK6HA2.js");
|
|
242
242
|
await dbCommandCli(action);
|
|
243
243
|
} catch (err) {
|
|
244
244
|
const msg = err instanceof Error ? err.message : String(err);
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
import "tsx/esm";
|
|
3
3
|
import {
|
|
4
4
|
loadConfig
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-35OI2TKT.js";
|
|
6
6
|
import "./chunk-3QPVEJ7D.js";
|
|
7
7
|
import "./chunk-O5JZ6ROY.js";
|
|
8
|
-
import "./chunk-
|
|
8
|
+
import "./chunk-PQWVT6JC.js";
|
|
9
9
|
import "./chunk-L4V5V2TI.js";
|
|
10
10
|
import "./chunk-MAJZ2L3A.js";
|
|
11
11
|
|
|
@@ -83,4 +83,4 @@ export {
|
|
|
83
83
|
dbCommand,
|
|
84
84
|
dbCommandCli
|
|
85
85
|
};
|
|
86
|
-
//# sourceMappingURL=db-
|
|
86
|
+
//# sourceMappingURL=db-5WOK6HA2.js.map
|
|
@@ -1,6 +1,31 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { R as RoutePolicy } from './route-policy-BHXQDzBF.js';
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* The `ctx` a `route()` handler receives, open to declaration merging.
|
|
6
|
+
*
|
|
7
|
+
* At runtime `ctx` holds what `server/context.ts` returns, what plugins decorate and, when
|
|
8
|
+
* `theo.config.ts` sets `jobs.backend`, `ctx.queue`. The framework cannot see the config from a
|
|
9
|
+
* route file, so it types none of those keys: each is `unknown` until the app declares it, which is
|
|
10
|
+
* the stance of `ctx-reconciliation.ts` (a key typed as present on a route where it is absent is the
|
|
11
|
+
* lie that contract rules out). Before this interface the whole `ctx` was `unknown`, so even
|
|
12
|
+
* `ctx.queue` needed a cast (usetheokit/theokit#1073).
|
|
13
|
+
*
|
|
14
|
+
* An app declares what its config provides, once, in a `.d.ts` file. The scaffold's
|
|
15
|
+
* `types/jobs.d.ts` carries this block, commented out, for apps that set `jobs.backend`:
|
|
16
|
+
*
|
|
17
|
+
* ```ts
|
|
18
|
+
* declare module 'theokit/server/define' {
|
|
19
|
+
* interface RouteContext {
|
|
20
|
+
* queue: import('theokit/server/jobs').QueueClient
|
|
21
|
+
* }
|
|
22
|
+
* }
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
interface RouteContext {
|
|
26
|
+
[key: string]: unknown;
|
|
27
|
+
}
|
|
28
|
+
|
|
4
29
|
/**
|
|
5
30
|
* core/contracts/route-config.ts
|
|
6
31
|
*
|
|
@@ -16,7 +41,7 @@ import { R as RoutePolicy } from './route-policy-BHXQDzBF.js';
|
|
|
16
41
|
* `tests/unit/route-config-generic-arity.test.ts`.
|
|
17
42
|
*/
|
|
18
43
|
|
|
19
|
-
interface RouteConfig<TQuery extends z.ZodType = z.ZodUndefined, TBody extends z.ZodType = z.ZodUndefined, TParams extends z.ZodType = z.ZodUndefined, TCtx =
|
|
44
|
+
interface RouteConfig<TQuery extends z.ZodType = z.ZodUndefined, TBody extends z.ZodType = z.ZodUndefined, TParams extends z.ZodType = z.ZodUndefined, TCtx = RouteContext, TResponse = unknown> {
|
|
20
45
|
query?: TQuery;
|
|
21
46
|
body?: TBody;
|
|
22
47
|
params?: TParams;
|
|
@@ -107,4 +132,4 @@ interface RouteConfig<TQuery extends z.ZodType = z.ZodUndefined, TBody extends z
|
|
|
107
132
|
type MiddlewareNext = () => Promise<Response | undefined>;
|
|
108
133
|
type MiddlewareHandler = (request: Request, context: Record<string, unknown>, next: MiddlewareNext) => Response | undefined | void | Promise<Response | undefined | void>;
|
|
109
134
|
|
|
110
|
-
export type { MiddlewareHandler as M, RouteConfig as R,
|
|
135
|
+
export type { MiddlewareHandler as M, RouteConfig as R, RouteContext as a, MiddlewareNext as b };
|
|
@@ -16,19 +16,20 @@ import {
|
|
|
16
16
|
initCacheEngineFromConfig,
|
|
17
17
|
loadCronModules,
|
|
18
18
|
loadJobModules,
|
|
19
|
+
prepareJobBackend,
|
|
19
20
|
startJobWorker
|
|
20
|
-
} from "./chunk-
|
|
21
|
+
} from "./chunk-GNV34JMI.js";
|
|
21
22
|
import {
|
|
22
23
|
preflightNodeAndBindings
|
|
23
24
|
} from "./chunk-KTMQUYED.js";
|
|
24
25
|
import {
|
|
25
26
|
theoPluginAsync
|
|
26
|
-
} from "./chunk-
|
|
27
|
-
import "./chunk-
|
|
27
|
+
} from "./chunk-HNALEGOL.js";
|
|
28
|
+
import "./chunk-HZAXFD55.js";
|
|
28
29
|
import "./chunk-BDH5GKFZ.js";
|
|
29
30
|
import "./chunk-3PWQQWT6.js";
|
|
30
31
|
import "./chunk-FDOOBTXJ.js";
|
|
31
|
-
import "./chunk-
|
|
32
|
+
import "./chunk-E22GPCCO.js";
|
|
32
33
|
import "./chunk-4JRXZTVQ.js";
|
|
33
34
|
import "./chunk-FNJVSFEC.js";
|
|
34
35
|
import "./chunk-WSMLSIS5.js";
|
|
@@ -42,12 +43,12 @@ import "./chunk-4WP7A7RX.js";
|
|
|
42
43
|
import "./chunk-Z7CJHDLS.js";
|
|
43
44
|
import {
|
|
44
45
|
loadConfig
|
|
45
|
-
} from "./chunk-
|
|
46
|
+
} from "./chunk-35OI2TKT.js";
|
|
46
47
|
import {
|
|
47
48
|
loadEnv
|
|
48
49
|
} from "./chunk-3QPVEJ7D.js";
|
|
49
50
|
import "./chunk-O5JZ6ROY.js";
|
|
50
|
-
import "./chunk-
|
|
51
|
+
import "./chunk-PQWVT6JC.js";
|
|
51
52
|
import {
|
|
52
53
|
orchestrateDev
|
|
53
54
|
} from "./chunk-L4V5V2TI.js";
|
|
@@ -79,6 +80,7 @@ async function startDevServer(cwd, options) {
|
|
|
79
80
|
validateProjectStructure(cwd, config.appDir);
|
|
80
81
|
await initCacheEngineFromConfig(config.cache);
|
|
81
82
|
await configureStorageManagerFromConfig(config.storage);
|
|
83
|
+
await prepareJobBackend(config);
|
|
82
84
|
const orchestration = await orchestrateDev({
|
|
83
85
|
cwd,
|
|
84
86
|
services: config.services
|
|
@@ -177,4 +179,4 @@ export {
|
|
|
177
179
|
devCommand,
|
|
178
180
|
startDevServer
|
|
179
181
|
};
|
|
180
|
-
//# sourceMappingURL=dev-
|
|
182
|
+
//# sourceMappingURL=dev-N5LQFLBR.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/cli/commands/dev.ts"],"sourcesContent":["import { resolve } from 'node:path'\n\nimport react from '@vitejs/plugin-react'\nimport { createServer, type Plugin, type ServerOptions, type ViteDevServer } from 'vite'\n\nimport { loadConfig } from '../../config/load-config.js'\nimport { loadEnv } from '../../config/load-env.js'\nimport type { TheoConfig } from '../../config/schema.js'\nimport { validateProjectStructure } from '../../config/validate-structure.js'\nimport { initCacheEngineFromConfig } from '../../server/cache-bootstrap.js'\nimport { createCronScheduler } from '../../server/cron/cron-runtime-node.js'\nimport { cronScanDirs, listCronFiles } from '../../server/cron/cron-scan.js'\nimport { listJobFiles } from '../../server/jobs/job-scan.js'\nimport { orchestrateDev } from '../../services/index.js'\nimport { theoPluginAsync } from '../../vite-plugin/index.js'\nimport { preflightNodeAndBindings } from '../preflight-node-version.js'\n\nimport { configureStorageManagerFromConfig } from './start/bootstrap-stages.js'\nimport { loadCronModules } from './start/cron-bootstrap.js'\nimport { loadJobModules, prepareJobBackend, startJobWorker } from './start/job-bootstrap.js'\n\ninterface DevOptions {\n port?: number\n /** Schedule the crons in dev (`theokit dev --crons`). Off by default (usetheokit/theokit#1017). */\n crons?: boolean\n}\n\n/**\n * The Vite `server` block, as a pure function of the loaded config — the same reasoning\n * `buildSecurityHeaders` is written down with: a setting that reaches Vite only from inside a\n * booted dev server can be asserted only by booting one, and a setting nobody can assert is how a\n * config field ends up existing and doing nothing (#555).\n *\n * Every key here is omitted rather than set to `undefined` when the app said nothing, so Vite's own\n * defaults apply. That matters most for `allowedHosts`, where the falsy value is `[]` — an empty\n * allowlist blocks every host, loopback included, so writing one on silence would turn \"no opinion\"\n * into \"refuse everything\".\n */\nexport function buildDevServerOptions(config: TheoConfig, port: number): ServerOptions {\n return {\n port,\n host: config.host,\n open: config.open,\n strictPort: config.strictPort,\n ...(config.allowedHosts !== undefined ? { allowedHosts: config.allowedHosts } : {}),\n warmup: config.warmup ?? {\n clientFiles: ['./app/**/*.tsx', './app/**/*.ts'],\n },\n }\n}\n\nexport async function startDevServer(cwd: string, options?: DevOptions): Promise<ViteDevServer> {\n // Preflight (FIRST — BEFORE anything that touches native bindings):\n // verifies Node version + native binding ABI match. Emits actionable\n // error referencing `nvm use` + `pnpm rebuild` when the dev server\n // was spawned under the wrong Node (common gotcha with `nohup env ...`\n // stripping the nvm PATH prefix).\n preflightNodeAndBindings(cwd)\n\n // Phase 1 (T1.2) — Load .env files into process.env BEFORE any module\n // reads them. Must run before loadConfig() so theo.config.ts functions\n // referencing process.env.* resolve correctly.\n loadEnv({ cwd, mode: 'development' })\n\n const config = await loadConfig(cwd)\n // #95 — pass config.appDir so the structure gate honors a custom frontend dir (e.g. apps/web).\n validateProjectStructure(cwd, config.appDir)\n\n // #352 — same engine, same config key, so `revalidateTag` behaves identically\n // under `theo dev` and `theo start`. A cache that only exists in production is\n // a cache nobody develops against.\n await initCacheEngineFromConfig(config.cache)\n\n // #1020 — the storage counterpart. `start` applied `config.storage` and `dev` did not, so every\n // `usePostgres(...)` threw \"Database not configured\" in development.\n await configureStorageManagerFromConfig(config.storage)\n\n // #1072 — create the job table before Vite serves a route that enqueues into it. A failure stops\n // the boot here, before any service or port is taken.\n await prepareJobBackend(config)\n\n // Wave 2 (T1.1) — spawn polyglot services BEFORE Vite. Healthcheck gates\n // readiness. Empty `services: {}` → early return (Wave 1 BC preserved).\n const orchestration = await orchestrateDev({\n cwd,\n services: config.services,\n })\n if (!orchestration.allHealthy) {\n await orchestration.stop()\n throw new Error(\n `[services] services failed healthcheck: ${orchestration.unhealthy.join(', ')}. ` +\n `Check that each declared service binds its port and responds 200 on its ` +\n `healthcheck path within 30s.`,\n )\n }\n\n // Phase 7 — legacy fs-mtime sweep removed: SDK's Agent.registry handles\n // LRU + idle eviction natively (configurable via theo.config.ts >\n // agents.registry; lazy-configured on first request).\n\n const port = options?.port ?? config.port\n // Narrow the rateLimit union: only the legacy flat shape (windowMs+max)\n // flows into the theoPlugin's RateLimitConfig parameter. The per-route\n // variant is consumed inside the api-middleware via the loaded user\n // config separately.\n const flatRateLimit =\n config.rateLimit && 'windowMs' in config.rateLimit && 'max' in config.rateLimit\n ? config.rateLimit\n : undefined\n // theoPluginAsync auto-chains @theokit/ui + @tailwindcss/vite via\n // top-level Plugin[] return (sync `theoPlugin()` factory's config()\n // hook returning {plugins:[...]} is silently dropped by Vite — see\n // commit history). Spread the result so Vite flattens them.\n let server: ViteDevServer\n try {\n const theoPlugins = await theoPluginAsync({\n root: cwd,\n rateLimit: flatRateLimit,\n ssr: config.ssr,\n // #95 — honor config `serverDir` (default \"server\") so route/action discovery scans it.\n serverDir: config.serverDir,\n // #95 follow-up — honor config `agentsDir` (default \"agents\") for the agent scan/middleware.\n agentsDir: config.agentsDir,\n // #95 follow-up — honor config `appDir` (default \"app\") for the file-based router + SSR/client entry.\n appDir: config.appDir,\n // Wave 2 (T3.1) — wire typed-client plugin when services declared.\n services: config.services,\n // T4.1 (canvas-ecosystem-refactor / ADR D6) — passthrough peer-deps\n // that plugins import dynamically (e.g., mermaid via plugin-canvas).\n viteOptimizeDeps: config.viteOptimizeDeps,\n })\n server = await createServer({\n root: cwd,\n plugins: [react(), ...theoPlugins] as Plugin[],\n server: buildDevServerOptions(config, port),\n logLevel: options?.port === 0 ? 'silent' : undefined,\n })\n\n await server.listen()\n } catch (err) {\n // EC-1 / try-finally pattern: if Vite create/listen fails AFTER services\n // started, stop them so we don't leak child processes.\n await orchestration.stop()\n throw err\n }\n\n // EC-1 fix: attach orchestration.stop() to the underlying HTTP server's\n // close event via Node-native API. We do NOT mutate `server.close`\n // (fragile across Vite upgrades). httpServer is `http.Server | null`.\n server.httpServer?.on('close', () => {\n void orchestration.stop()\n })\n\n await startDevJobWorker(server, cwd, config)\n await startDevCrons(server, cwd, config, options?.crons === true)\n\n return server\n}\n\n/**\n * The job worker `theokit start` runs, in development too (usetheokit/theokit#1010): `ctx.queue`\n * works in dev since #1009, and a queue nothing drains would make every job untestable without a\n * production build. Job files load through Vite, like routes, and the worker stops with the server.\n */\nasync function startDevJobWorker(\n server: ViteDevServer,\n cwd: string,\n config: TheoConfig,\n): Promise<void> {\n const files = listJobFiles(resolve(cwd, config.serverDir, 'jobs'))\n const definitions = await loadJobModules(files, (filePath) => server.ssrLoadModule(filePath))\n const jobs = startJobWorker(config, definitions)\n if (jobs.summary !== undefined) console.log(`\\n ${jobs.summary}`)\n server.httpServer?.on('close', () => {\n void jobs.worker?.stop()\n })\n}\n\n/**\n * Crons in development (usetheokit/theokit#1017). `dev` had no cron code path and said nothing, so\n * a new cron neither fired nor got explained until `build` plus `start`. Scheduling is opt-in\n * (`--crons`): a cron that sends an email or charges a card should not do it on every dev boot\n * unasked. Either way the boot log says what happens to the declared crons. Files load through\n * Vite once at boot, so an edit to a cron applies after a restart. Single process, so no lock.\n */\nasync function startDevCrons(\n server: ViteDevServer,\n cwd: string,\n config: TheoConfig,\n schedule: boolean,\n): Promise<void> {\n const dirs = cronScanDirs(cwd, config.serverDir, config.agentsDir)\n const files = listCronFiles([dirs.crons, dirs.schedules])\n if (files.length === 0) return\n if (!schedule) {\n console.log(\n `\\n Crons: ${String(files.length)} declared, not scheduled in dev. ` +\n 'Run `theokit dev --crons` to schedule them (edits apply after a restart).',\n )\n return\n }\n const definitions = await loadCronModules(files, (filePath) => server.ssrLoadModule(filePath))\n const scheduler = createCronScheduler(definitions)\n scheduler.start()\n console.log(\n `\\n Crons: ${String(definitions.length)} scheduled in dev (--crons); edits apply after a restart.`,\n )\n server.httpServer?.on('close', () => {\n scheduler.stop()\n })\n}\n\nexport async function devCommand(options: DevOptions): Promise<void> {\n try {\n const cwd = process.cwd()\n const server = await startDevServer(cwd, options)\n server.printUrls()\n } catch (err) {\n const msg = err instanceof Error ? err.message : String(err)\n console.error(`\\n ✗ ${msg}\\n`)\n process.exit(1)\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAAS,eAAe;AAExB,OAAO,WAAW;AAClB,SAAS,oBAAyE;AAmC3E,SAAS,sBAAsB,QAAoB,MAA6B;AACrF,SAAO;AAAA,IACL;AAAA,IACA,MAAM,OAAO;AAAA,IACb,MAAM,OAAO;AAAA,IACb,YAAY,OAAO;AAAA,IACnB,GAAI,OAAO,iBAAiB,SAAY,EAAE,cAAc,OAAO,aAAa,IAAI,CAAC;AAAA,IACjF,QAAQ,OAAO,UAAU;AAAA,MACvB,aAAa,CAAC,kBAAkB,eAAe;AAAA,IACjD;AAAA,EACF;AACF;AAEA,eAAsB,eAAe,KAAa,SAA8C;AAM9F,2BAAyB,GAAG;AAK5B,UAAQ,EAAE,KAAK,MAAM,cAAc,CAAC;AAEpC,QAAM,SAAS,MAAM,WAAW,GAAG;AAEnC,2BAAyB,KAAK,OAAO,MAAM;AAK3C,QAAM,0BAA0B,OAAO,KAAK;AAI5C,QAAM,kCAAkC,OAAO,OAAO;AAItD,QAAM,kBAAkB,MAAM;AAI9B,QAAM,gBAAgB,MAAM,eAAe;AAAA,IACzC;AAAA,IACA,UAAU,OAAO;AAAA,EACnB,CAAC;AACD,MAAI,CAAC,cAAc,YAAY;AAC7B,UAAM,cAAc,KAAK;AACzB,UAAM,IAAI;AAAA,MACR,2CAA2C,cAAc,UAAU,KAAK,IAAI,CAAC;AAAA,IAG/E;AAAA,EACF;AAMA,QAAM,OAAO,SAAS,QAAQ,OAAO;AAKrC,QAAM,gBACJ,OAAO,aAAa,cAAc,OAAO,aAAa,SAAS,OAAO,YAClE,OAAO,YACP;AAKN,MAAI;AACJ,MAAI;AACF,UAAM,cAAc,MAAM,gBAAgB;AAAA,MACxC,MAAM;AAAA,MACN,WAAW;AAAA,MACX,KAAK,OAAO;AAAA;AAAA,MAEZ,WAAW,OAAO;AAAA;AAAA,MAElB,WAAW,OAAO;AAAA;AAAA,MAElB,QAAQ,OAAO;AAAA;AAAA,MAEf,UAAU,OAAO;AAAA;AAAA;AAAA,MAGjB,kBAAkB,OAAO;AAAA,IAC3B,CAAC;AACD,aAAS,MAAM,aAAa;AAAA,MAC1B,MAAM;AAAA,MACN,SAAS,CAAC,MAAM,GAAG,GAAG,WAAW;AAAA,MACjC,QAAQ,sBAAsB,QAAQ,IAAI;AAAA,MAC1C,UAAU,SAAS,SAAS,IAAI,WAAW;AAAA,IAC7C,CAAC;AAED,UAAM,OAAO,OAAO;AAAA,EACtB,SAAS,KAAK;AAGZ,UAAM,cAAc,KAAK;AACzB,UAAM;AAAA,EACR;AAKA,SAAO,YAAY,GAAG,SAAS,MAAM;AACnC,SAAK,cAAc,KAAK;AAAA,EAC1B,CAAC;AAED,QAAM,kBAAkB,QAAQ,KAAK,MAAM;AAC3C,QAAM,cAAc,QAAQ,KAAK,QAAQ,SAAS,UAAU,IAAI;AAEhE,SAAO;AACT;AAOA,eAAe,kBACb,QACA,KACA,QACe;AACf,QAAM,QAAQ,aAAa,QAAQ,KAAK,OAAO,WAAW,MAAM,CAAC;AACjE,QAAM,cAAc,MAAM,eAAe,OAAO,CAAC,aAAa,OAAO,cAAc,QAAQ,CAAC;AAC5F,QAAM,OAAO,eAAe,QAAQ,WAAW;AAC/C,MAAI,KAAK,YAAY,OAAW,SAAQ,IAAI;AAAA,IAAO,KAAK,OAAO,EAAE;AACjE,SAAO,YAAY,GAAG,SAAS,MAAM;AACnC,SAAK,KAAK,QAAQ,KAAK;AAAA,EACzB,CAAC;AACH;AASA,eAAe,cACb,QACA,KACA,QACA,UACe;AACf,QAAM,OAAO,aAAa,KAAK,OAAO,WAAW,OAAO,SAAS;AACjE,QAAM,QAAQ,cAAc,CAAC,KAAK,OAAO,KAAK,SAAS,CAAC;AACxD,MAAI,MAAM,WAAW,EAAG;AACxB,MAAI,CAAC,UAAU;AACb,YAAQ;AAAA,MACN;AAAA,WAAc,OAAO,MAAM,MAAM,CAAC;AAAA,IAEpC;AACA;AAAA,EACF;AACA,QAAM,cAAc,MAAM,gBAAgB,OAAO,CAAC,aAAa,OAAO,cAAc,QAAQ,CAAC;AAC7F,QAAM,YAAY,oBAAoB,WAAW;AACjD,YAAU,MAAM;AAChB,UAAQ;AAAA,IACN;AAAA,WAAc,OAAO,YAAY,MAAM,CAAC;AAAA,EAC1C;AACA,SAAO,YAAY,GAAG,SAAS,MAAM;AACnC,cAAU,KAAK;AAAA,EACjB,CAAC;AACH;AAEA,eAAsB,WAAW,SAAoC;AACnE,MAAI;AACF,UAAM,MAAM,QAAQ,IAAI;AACxB,UAAM,SAAS,MAAM,eAAe,KAAK,OAAO;AAChD,WAAO,UAAU;AAAA,EACnB,SAAS,KAAK;AACZ,UAAM,MAAM,eAAe,QAAQ,IAAI,UAAU,OAAO,GAAG;AAC3D,YAAQ,MAAM;AAAA,WAAS,GAAG;AAAA,CAAI;AAC9B,YAAQ,KAAK,CAAC;AAAA,EAChB;AACF;","names":[]}
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import "tsx/esm";
|
|
3
|
+
import {
|
|
4
|
+
detectProjectPackageManager
|
|
5
|
+
} from "./chunk-JVXDEIT4.js";
|
|
3
6
|
import {
|
|
4
7
|
cronScanDirs,
|
|
5
8
|
isDiscoverableCronFile,
|
|
@@ -11,16 +14,16 @@ import {
|
|
|
11
14
|
import "./chunk-Z7CJHDLS.js";
|
|
12
15
|
import {
|
|
13
16
|
loadConfig
|
|
14
|
-
} from "./chunk-
|
|
17
|
+
} from "./chunk-35OI2TKT.js";
|
|
15
18
|
import "./chunk-3QPVEJ7D.js";
|
|
16
19
|
import "./chunk-O5JZ6ROY.js";
|
|
17
|
-
import "./chunk-
|
|
20
|
+
import "./chunk-PQWVT6JC.js";
|
|
18
21
|
import "./chunk-L4V5V2TI.js";
|
|
19
22
|
import "./chunk-MAJZ2L3A.js";
|
|
20
23
|
|
|
21
24
|
// src/cli/commands/generate.ts
|
|
22
|
-
import { existsSync as existsSync2, mkdirSync as mkdirSync2, writeFileSync as writeFileSync2 } from "fs";
|
|
23
|
-
import { dirname as dirname3,
|
|
25
|
+
import { existsSync as existsSync2, mkdirSync as mkdirSync2, readFileSync as readFileSync2, writeFileSync as writeFileSync2 } from "fs";
|
|
26
|
+
import { dirname as dirname3, posix, resolve as resolve4 } from "path";
|
|
24
27
|
|
|
25
28
|
// src/cli/commands/generate-containment.ts
|
|
26
29
|
import { isAbsolute, relative, resolve, sep } from "path";
|
|
@@ -37,6 +40,15 @@ function pathTraversalRefusal(cwd, filePath) {
|
|
|
37
40
|
};
|
|
38
41
|
}
|
|
39
42
|
|
|
43
|
+
// src/cli/commands/generate-names.ts
|
|
44
|
+
function toPascalCase(name) {
|
|
45
|
+
return name.split(/[-/]/).map((s) => s.charAt(0).toUpperCase() + s.slice(1)).join("");
|
|
46
|
+
}
|
|
47
|
+
function toCamelCase(name) {
|
|
48
|
+
const pascal = toPascalCase(name);
|
|
49
|
+
return pascal.charAt(0).toLowerCase() + pascal.slice(1);
|
|
50
|
+
}
|
|
51
|
+
|
|
40
52
|
// src/cli/commands/generate-policy-placeholder.ts
|
|
41
53
|
var UNDECIDED_POLICY_IDENT = "undecidedPolicy";
|
|
42
54
|
function undecidedPolicyDeclaration(routePath, what) {
|
|
@@ -427,6 +439,66 @@ Nothing was written.`
|
|
|
427
439
|
return { status: "created", filePath: routeIndexPath, kind: "resource", name };
|
|
428
440
|
}
|
|
429
441
|
|
|
442
|
+
// src/cli/commands/generate-sandbox.ts
|
|
443
|
+
function generateSandboxTemplate(name) {
|
|
444
|
+
const camel = toCamelCase(name);
|
|
445
|
+
const base = name.split("/").pop() ?? name;
|
|
446
|
+
const snake = base.replace(/-/g, "_");
|
|
447
|
+
return [
|
|
448
|
+
`import { mkdtempSync } from 'node:fs'`,
|
|
449
|
+
`import { tmpdir } from 'node:os'`,
|
|
450
|
+
`import { join } from 'node:path'`,
|
|
451
|
+
``,
|
|
452
|
+
`import {`,
|
|
453
|
+
` createSandboxBackend,`,
|
|
454
|
+
` resolveSandboxPosture,`,
|
|
455
|
+
` SandboxNotAvailableError,`,
|
|
456
|
+
`} from '@theokit/sdk/sandbox'`,
|
|
457
|
+
`import { tool } from 'theokit/server/define'`,
|
|
458
|
+
`import { z } from 'zod'`,
|
|
459
|
+
``,
|
|
460
|
+
`/**`,
|
|
461
|
+
` * An agent tool that runs a shell command under bubblewrap confinement (Linux): the filesystem is`,
|
|
462
|
+
` * read-only apart from a scratch directory and /tmp, the network is cut, and the environment is`,
|
|
463
|
+
` * reduced to an allowlist. The command can still READ anything your user can read. Confinement`,
|
|
464
|
+
` * limits what a command can change; it is not a boundary for hostile code, which needs a container`,
|
|
465
|
+
` * or VM backend.`,
|
|
466
|
+
` *`,
|
|
467
|
+
` * Where bubblewrap is missing or cannot run (macOS, Windows, many containers) nothing confines the`,
|
|
468
|
+
` * command, so the tool refuses with \`SandboxNotAvailableError\`. To run commands on the host anyway,`,
|
|
469
|
+
` * with your user's full filesystem and network access, set THEOKIT_SANDBOX_ALLOW_UNCONFINED=1, and`,
|
|
470
|
+
` * only for commands you trust.`,
|
|
471
|
+
` *`,
|
|
472
|
+
` * Connect it to your agent with \`.tool(...)\`:`,
|
|
473
|
+
` *`,
|
|
474
|
+
` * // agents/chat.ts`,
|
|
475
|
+
` * import { ${camel}Tool } from './sandbox/${base}.js'`,
|
|
476
|
+
` * AgentBuilder.create().model(...).tool(${camel}Tool).build()`,
|
|
477
|
+
` */`,
|
|
478
|
+
`const MODE = 'workspace-write'`,
|
|
479
|
+
`let scratchDir: string | undefined`,
|
|
480
|
+
``,
|
|
481
|
+
`export const ${camel}Tool = tool('${snake}')`,
|
|
482
|
+
` .describe('Run a shell command and return its output.')`,
|
|
483
|
+
` .input(z.object({ command: z.string().describe('The shell command to run, e.g. "ls -la"') }))`,
|
|
484
|
+
` .execute(async ({ command }) => {`,
|
|
485
|
+
` const posture = resolveSandboxPosture({ mode: MODE })`,
|
|
486
|
+
` if (!posture.enforced && process.env.THEOKIT_SANDBOX_ALLOW_UNCONFINED !== '1') {`,
|
|
487
|
+
` throw new SandboxNotAvailableError(`,
|
|
488
|
+
` \`Refusing to run the command without confinement: \${posture.detail}. \` +`,
|
|
489
|
+
` 'Install bubblewrap, or set THEOKIT_SANDBOX_ALLOW_UNCONFINED=1 to run it on the host.',`,
|
|
490
|
+
` )`,
|
|
491
|
+
` }`,
|
|
492
|
+
` scratchDir ??= mkdtempSync(join(tmpdir(), '${base}-'))`,
|
|
493
|
+
` const sandbox = createSandboxBackend({ mode: MODE, workDir: scratchDir, timeoutMs: 5_000 })`,
|
|
494
|
+
` const { stdout, stderr, exitCode } = await sandbox.execute(command)`,
|
|
495
|
+
` return exitCode === 0 ? stdout : \`exit \${exitCode}: \${stderr}\``,
|
|
496
|
+
` })`,
|
|
497
|
+
` .build()`,
|
|
498
|
+
``
|
|
499
|
+
].join("\n");
|
|
500
|
+
}
|
|
501
|
+
|
|
430
502
|
// src/cli/commands/generate-schedule.ts
|
|
431
503
|
import { basename, dirname as dirname2, extname, relative as relative2, resolve as resolve3, sep as sep2 } from "path";
|
|
432
504
|
|
|
@@ -586,13 +658,6 @@ function hasReservedSegment(name) {
|
|
|
586
658
|
const basename2 = name.includes("/") ? name.split("/").pop() ?? name : name;
|
|
587
659
|
return RESERVED_BASENAMES.has(basename2);
|
|
588
660
|
}
|
|
589
|
-
function toPascalCase(name) {
|
|
590
|
-
return name.split(/[-/]/).map((s) => s.charAt(0).toUpperCase() + s.slice(1)).join("");
|
|
591
|
-
}
|
|
592
|
-
function toCamelCase(name) {
|
|
593
|
-
const pascal = toPascalCase(name);
|
|
594
|
-
return pascal.charAt(0).toLowerCase() + pascal.slice(1);
|
|
595
|
-
}
|
|
596
661
|
function generateRouteTemplate(name, displayPath) {
|
|
597
662
|
return [
|
|
598
663
|
`import { route, type AccessDecision } from 'theokit/server/define'`,
|
|
@@ -730,36 +795,6 @@ function generateEvalTemplate(name) {
|
|
|
730
795
|
``
|
|
731
796
|
].join("\n");
|
|
732
797
|
}
|
|
733
|
-
function generateSandboxTemplate(name) {
|
|
734
|
-
const camel = toCamelCase(name);
|
|
735
|
-
const base = name.split("/").pop() ?? name;
|
|
736
|
-
const snake = base.replace(/-/g, "_");
|
|
737
|
-
return [
|
|
738
|
-
`import { tool } from 'theokit/server/define'`,
|
|
739
|
-
`import { LocalSandbox } from '@theokit/sdk/sandbox'`,
|
|
740
|
-
`import { z } from 'zod'`,
|
|
741
|
-
``,
|
|
742
|
-
`/**`,
|
|
743
|
-
` * A sandbox-backed agent tool. \`LocalSandbox\` (@theokit/sdk) runs a shell command with a timeout +`,
|
|
744
|
-
` * output cap, isolated from your app process \u2014 so the agent can run commands SAFELY. This IS an agent`,
|
|
745
|
-
` * capability: connect it to your agent with \`.tool(...)\`:`,
|
|
746
|
-
` *`,
|
|
747
|
-
` * // agents/chat.ts`,
|
|
748
|
-
` * import { ${camel}Tool } from './sandbox/${base}.js'`,
|
|
749
|
-
` * AgentBuilder.create().model(...).tool(${camel}Tool).build()`,
|
|
750
|
-
` */`,
|
|
751
|
-
`export const ${camel}Tool = tool('${snake}')`,
|
|
752
|
-
` .describe('Run a shell command in an isolated sandbox and return its output.')`,
|
|
753
|
-
` .input(z.object({ command: z.string().describe('The shell command to run, e.g. "ls -la"') }))`,
|
|
754
|
-
` .execute(async ({ command }) => {`,
|
|
755
|
-
` const sandbox = new LocalSandbox({ timeoutMs: 5_000 })`,
|
|
756
|
-
` const { stdout, stderr, exitCode } = await sandbox.execute(command)`,
|
|
757
|
-
` return exitCode === 0 ? stdout : \`exit \${exitCode}: \${stderr}\``,
|
|
758
|
-
` })`,
|
|
759
|
-
` .build()`,
|
|
760
|
-
``
|
|
761
|
-
].join("\n");
|
|
762
|
-
}
|
|
763
798
|
function generateMemoryTemplate(_name) {
|
|
764
799
|
return [
|
|
765
800
|
`/**`,
|
|
@@ -940,20 +975,53 @@ function writeTarget(cwd, type, name, { filePath, content }) {
|
|
|
940
975
|
writeFileSync2(testPath, generateActionTestTemplate(name));
|
|
941
976
|
}
|
|
942
977
|
}
|
|
943
|
-
if (type === "controller"
|
|
944
|
-
|
|
978
|
+
if (type === "controller") {
|
|
979
|
+
const message = controllerDependencyNotice(cwd);
|
|
980
|
+
if (message !== void 0) return { status: "created", filePath, kind: type, name, message };
|
|
945
981
|
}
|
|
946
982
|
return { status: "created", filePath, kind: type, name };
|
|
947
983
|
}
|
|
948
|
-
var
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
984
|
+
var CONTROLLER_DEPENDENCIES = ["@theokit/http", "reflect-metadata"];
|
|
985
|
+
var CONTROLLER_DEV_DEPENDENCIES = ["@swc/core"];
|
|
986
|
+
function controllerDependencyNotice(cwd) {
|
|
987
|
+
const declared = declaredPackages(cwd);
|
|
988
|
+
const missing = CONTROLLER_DEPENDENCIES.filter((pkg) => !declared.names.has(pkg));
|
|
989
|
+
const missingDev = CONTROLLER_DEV_DEPENDENCIES.filter((pkg) => !declared.names.has(pkg));
|
|
990
|
+
if (missing.length === 0 && missingDev.length === 0) return void 0;
|
|
991
|
+
const pm = detectProjectPackageManager(cwd);
|
|
992
|
+
const commands = [
|
|
993
|
+
...missing.length > 0 ? [installCommand(pm, missing, false)] : [],
|
|
994
|
+
...missingDev.length > 0 ? [installCommand(pm, missingDev, true)] : []
|
|
995
|
+
];
|
|
996
|
+
return [
|
|
997
|
+
`A controller build needs ${[...missing, ...missingDev].join(", ")}, which ${declared.source} does not declare.`,
|
|
998
|
+
`Install before running the app: ${commands.join(" && ")}`
|
|
999
|
+
].join(" ");
|
|
1000
|
+
}
|
|
1001
|
+
function installCommand(pm, packages, dev) {
|
|
1002
|
+
const verb = pm === "npm" ? "install" : "add";
|
|
1003
|
+
return [pm, verb, ...dev ? ["-D"] : [], ...packages].join(" ");
|
|
1004
|
+
}
|
|
1005
|
+
function declaredPackages(cwd) {
|
|
1006
|
+
const path = resolve4(cwd, "package.json");
|
|
1007
|
+
if (!existsSync2(path)) return { names: /* @__PURE__ */ new Set(), source: "the project (it has no package.json)" };
|
|
1008
|
+
let manifest;
|
|
1009
|
+
try {
|
|
1010
|
+
manifest = JSON.parse(readFileSync2(path, "utf-8"));
|
|
1011
|
+
} catch (error) {
|
|
1012
|
+
const reason = error instanceof Error ? error.message : String(error);
|
|
1013
|
+
return { names: /* @__PURE__ */ new Set(), source: `package.json (it does not parse: ${reason})` };
|
|
1014
|
+
}
|
|
1015
|
+
const names = /* @__PURE__ */ new Set();
|
|
1016
|
+
if (typeof manifest === "object" && manifest !== null) {
|
|
1017
|
+
for (const field of ["dependencies", "devDependencies"]) {
|
|
1018
|
+
const listed = manifest[field];
|
|
1019
|
+
if (typeof listed === "object" && listed !== null) {
|
|
1020
|
+
for (const pkg of Object.keys(listed)) names.add(pkg);
|
|
1021
|
+
}
|
|
1022
|
+
}
|
|
956
1023
|
}
|
|
1024
|
+
return { names, source: "package.json" };
|
|
957
1025
|
}
|
|
958
1026
|
async function generate(opts) {
|
|
959
1027
|
const refused = refuseOptions(opts);
|
|
@@ -1000,4 +1068,4 @@ export {
|
|
|
1000
1068
|
generate,
|
|
1001
1069
|
generateCommand
|
|
1002
1070
|
};
|
|
1003
|
-
//# sourceMappingURL=generate-
|
|
1071
|
+
//# sourceMappingURL=generate-OA5ARO3P.js.map
|