theokit 0.68.0 → 0.69.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 +21 -0
- package/dist/{actions-virtual-module-SE44BKR4.js → actions-virtual-module-DH3N34I6.js} +6 -6
- package/dist/{actions-virtual-module-3OPYLD76.js → actions-virtual-module-OMIFGXK6.js} +3 -3
- package/dist/adapters/agent-mount.d.ts +190 -2
- package/dist/adapters/agent-mount.js +18 -3
- package/dist/adapters/security-headers.d.ts +17 -1
- package/dist/adapters/security-headers.js +7 -0
- package/dist/adapters/security-headers.js.map +1 -1
- package/dist/{agent-UBDDP2L5.js → agent-7RPGAKTY.js} +3 -3
- package/dist/{app-typed-client-RAFEBA7S.js → app-typed-client-C4LRUSIS.js} +6 -6
- package/dist/{app-typed-client-BE3PV3JY.js → app-typed-client-R6OUJZEE.js} +3 -3
- package/dist/{aws-lambda-R76PWR27.js → aws-lambda-OCJM5YGB.js} +35 -23
- package/dist/aws-lambda-OCJM5YGB.js.map +1 -0
- package/dist/{build-U4HVYY6F.js → build-CGFKWZ73.js} +10 -5
- package/dist/build-CGFKWZ73.js.map +1 -0
- package/dist/{bun-NPBIAWSU.js → bun-KRUAWYRW.js} +51 -39
- package/dist/bun-KRUAWYRW.js.map +1 -0
- package/dist/{chunk-GQNBZDYK.js → chunk-2FHNJ7LI.js} +1 -1
- package/dist/{chunk-GQNBZDYK.js.map → chunk-2FHNJ7LI.js.map} +1 -1
- package/dist/chunk-3T5XLDOH.js +807 -0
- package/dist/chunk-3T5XLDOH.js.map +1 -0
- package/dist/{chunk-GDF2XQOO.js → chunk-425FJKKO.js} +5 -3
- package/dist/chunk-425FJKKO.js.map +1 -0
- package/dist/{chunk-7THO4PRL.js → chunk-4WB62S22.js} +7 -4
- package/dist/{chunk-7THO4PRL.js.map → chunk-4WB62S22.js.map} +1 -1
- package/dist/chunk-BDPD5HEO.js +554 -0
- package/dist/chunk-BDPD5HEO.js.map +1 -0
- package/dist/{chunk-UETVDZBE.js → chunk-BINRCILF.js} +4 -1
- package/dist/{chunk-UETVDZBE.js.map → chunk-BINRCILF.js.map} +1 -1
- package/dist/{chunk-AROOYXI5.js → chunk-BTDTHXUI.js} +2 -2
- package/dist/chunk-FFGP2LGQ.js +465 -0
- package/dist/chunk-FFGP2LGQ.js.map +1 -0
- package/dist/{chunk-CO7Q75IS.js → chunk-I2H6KRCQ.js} +8 -8
- package/dist/{chunk-ENRT6DAU.js → chunk-IDWN2OSG.js} +15 -2
- package/dist/chunk-IDWN2OSG.js.map +1 -0
- package/dist/{chunk-GAJOZJWD.js → chunk-MOGTMGGA.js} +5 -2
- package/dist/chunk-MOGTMGGA.js.map +1 -0
- package/dist/{chunk-LADTWXOB.js → chunk-QVXMAHZC.js} +40 -551
- package/dist/chunk-QVXMAHZC.js.map +1 -0
- package/dist/{chunk-G2NWAVGG.js → chunk-SJ4AW54X.js} +44 -3
- package/dist/chunk-SJ4AW54X.js.map +1 -0
- package/dist/{chunk-Q7T3UQ4L.js → chunk-SRJBH5E5.js} +16 -738
- package/dist/chunk-SRJBH5E5.js.map +1 -0
- package/dist/{chunk-QGNSZ2ZK.js → chunk-T2LDLVVV.js} +3 -3
- package/dist/{chunk-FYYKMPST.js → chunk-TJPENLGQ.js} +3 -3
- package/dist/chunk-V5SSTT3C.js +52 -0
- package/dist/chunk-V5SSTT3C.js.map +1 -0
- package/dist/chunk-XG6SQUEP.js +27 -0
- package/dist/chunk-XG6SQUEP.js.map +1 -0
- package/dist/cli/index.js +6 -6
- package/dist/client/index.d.ts +20 -0
- package/dist/client/index.js.map +1 -1
- package/dist/{cloudflare-5HU56XIH.js → cloudflare-GK4VD3EU.js} +36 -13
- package/dist/cloudflare-GK4VD3EU.js.map +1 -0
- package/dist/{define-middleware-D2n71Svm.d.ts → define-middleware-BOHpPOBs.d.ts} +1 -1
- package/dist/{deno-deploy-BXOQ45LD.js → deno-deploy-WMNXRVGL.js} +37 -36
- package/dist/deno-deploy-WMNXRVGL.js.map +1 -0
- package/dist/{dev-E3USPAWQ.js → dev-72ISY3BP.js} +5 -5
- package/dist/{index-B9iVBHJI.d.ts → index-DZ_G5iY2.d.ts} +31 -4
- package/dist/index.js +7 -6
- package/dist/index.js.map +1 -1
- package/dist/{internal-api-OOTVIOH2.js → internal-api-CEZSXGRB.js} +3 -3
- package/dist/{internal-api-VAKXXW6F.js → internal-api-XRIBUACB.js} +8 -7
- package/dist/match-DaKsL73w.d.ts +28 -0
- package/dist/{mcp-7UOQM4FW.js → mcp-S2AOB3RE.js} +3 -3
- package/dist/{match-Dw4CNXJH.d.ts → module-loader-DCip7NoL.d.ts} +1 -28
- package/dist/{netlify-LPJAPMQ2.js → netlify-VOL54SC7.js} +23 -20
- package/dist/netlify-VOL54SC7.js.map +1 -0
- package/dist/{preview-GPMF43QX.js → preview-WA4HORUQ.js} +3 -3
- package/dist/{registry-UOWTDUFL.js → registry-DDBXDHJ2.js} +7 -7
- package/dist/server/cost/index.d.ts +14 -1
- package/dist/server/cost/index.js +1 -1
- package/dist/server/define/index.d.ts +1 -1
- package/dist/server/define/index.js +2 -3
- package/dist/server/http/index.d.ts +4 -3
- package/dist/server/http/index.js +11 -8
- package/dist/server/index.d.ts +5 -4
- package/dist/server/index.js +13 -10
- package/dist/server/index.js.map +1 -1
- package/dist/server/scan/index.d.ts +3 -2
- package/dist/{server-boundary-A3HW27C7.js → server-boundary-S3G4CSNK.js} +3 -3
- package/dist/{server-boundary-V6PCM22J.js → server-boundary-YN5HAICY.js} +6 -6
- package/dist/{start-6WEPXA3X.js → start-ZTMQLNJI.js} +4 -4
- package/dist/{vercel-YUZADKGV.js → vercel-LZTDSDJF.js} +42 -28
- package/dist/vercel-LZTDSDJF.js.map +1 -0
- package/dist/vite-plugin/index.js +7 -6
- package/dist/{vite-plugin-WBF5NXGW.js → vite-plugin-Z7AJG3M2.js} +5 -5
- package/package.json +4 -4
- package/dist/aws-lambda-R76PWR27.js.map +0 -1
- package/dist/build-U4HVYY6F.js.map +0 -1
- package/dist/bun-NPBIAWSU.js.map +0 -1
- package/dist/chunk-6B3CMPE4.js +0 -192
- package/dist/chunk-6B3CMPE4.js.map +0 -1
- package/dist/chunk-7L7LQ2GU.js +0 -16
- package/dist/chunk-7L7LQ2GU.js.map +0 -1
- package/dist/chunk-ENRT6DAU.js.map +0 -1
- package/dist/chunk-G2NWAVGG.js.map +0 -1
- package/dist/chunk-GAJOZJWD.js.map +0 -1
- package/dist/chunk-GDF2XQOO.js.map +0 -1
- package/dist/chunk-LADTWXOB.js.map +0 -1
- package/dist/chunk-O55RLSGG.js +0 -127
- package/dist/chunk-O55RLSGG.js.map +0 -1
- package/dist/chunk-Q7T3UQ4L.js.map +0 -1
- package/dist/cloudflare-5HU56XIH.js.map +0 -1
- package/dist/deno-deploy-BXOQ45LD.js.map +0 -1
- package/dist/netlify-LPJAPMQ2.js.map +0 -1
- package/dist/vercel-YUZADKGV.js.map +0 -1
- /package/dist/{actions-virtual-module-SE44BKR4.js.map → actions-virtual-module-DH3N34I6.js.map} +0 -0
- /package/dist/{actions-virtual-module-3OPYLD76.js.map → actions-virtual-module-OMIFGXK6.js.map} +0 -0
- /package/dist/{agent-UBDDP2L5.js.map → agent-7RPGAKTY.js.map} +0 -0
- /package/dist/{app-typed-client-RAFEBA7S.js.map → app-typed-client-C4LRUSIS.js.map} +0 -0
- /package/dist/{app-typed-client-BE3PV3JY.js.map → app-typed-client-R6OUJZEE.js.map} +0 -0
- /package/dist/{chunk-AROOYXI5.js.map → chunk-BTDTHXUI.js.map} +0 -0
- /package/dist/{chunk-CO7Q75IS.js.map → chunk-I2H6KRCQ.js.map} +0 -0
- /package/dist/{chunk-QGNSZ2ZK.js.map → chunk-T2LDLVVV.js.map} +0 -0
- /package/dist/{chunk-FYYKMPST.js.map → chunk-TJPENLGQ.js.map} +0 -0
- /package/dist/{dev-E3USPAWQ.js.map → dev-72ISY3BP.js.map} +0 -0
- /package/dist/{internal-api-OOTVIOH2.js.map → internal-api-CEZSXGRB.js.map} +0 -0
- /package/dist/{internal-api-VAKXXW6F.js.map → internal-api-XRIBUACB.js.map} +0 -0
- /package/dist/{mcp-7UOQM4FW.js.map → mcp-S2AOB3RE.js.map} +0 -0
- /package/dist/{preview-GPMF43QX.js.map → preview-WA4HORUQ.js.map} +0 -0
- /package/dist/{registry-UOWTDUFL.js.map → registry-DDBXDHJ2.js.map} +0 -0
- /package/dist/{server-boundary-A3HW27C7.js.map → server-boundary-S3G4CSNK.js.map} +0 -0
- /package/dist/{server-boundary-V6PCM22J.js.map → server-boundary-YN5HAICY.js.map} +0 -0
- /package/dist/{start-6WEPXA3X.js.map → start-ZTMQLNJI.js.map} +0 -0
- /package/dist/{vite-plugin-WBF5NXGW.js.map → vite-plugin-Z7AJG3M2.js.map} +0 -0
|
@@ -7,32 +7,29 @@ import {
|
|
|
7
7
|
} from "./chunk-SSYDEKWF.js";
|
|
8
8
|
import {
|
|
9
9
|
dispatchControllerRequest
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-425FJKKO.js";
|
|
11
|
+
import {
|
|
12
|
+
createAgentSubjectResolver,
|
|
13
|
+
isAgentCardPath,
|
|
14
|
+
matchAgentAuxRoute,
|
|
15
|
+
serveMatchedAuxRoute
|
|
16
|
+
} from "./chunk-BDPD5HEO.js";
|
|
11
17
|
import {
|
|
12
|
-
RUN_ID_HEADER,
|
|
13
|
-
SSE_BASE_HEADERS,
|
|
14
|
-
SSE_DONE_FRAME,
|
|
15
18
|
admitAgentRequest,
|
|
16
19
|
agentAccessDenied,
|
|
17
20
|
cacheSchema,
|
|
18
21
|
closePauseSpan,
|
|
19
22
|
createObservabilityPluginFromConfig,
|
|
20
|
-
encodeSse,
|
|
21
|
-
formatSseFrame,
|
|
22
23
|
getApprovalRegistry,
|
|
23
|
-
getRunEventCache,
|
|
24
24
|
loggingSchema,
|
|
25
|
-
makeThreadStartRun,
|
|
26
|
-
mintRunId,
|
|
27
25
|
mountAgent,
|
|
28
26
|
observabilitySchema,
|
|
29
|
-
parseAgentRequestBody,
|
|
30
27
|
rateLimitSchema,
|
|
31
28
|
readAgentPolicy,
|
|
32
29
|
securitySchema,
|
|
33
30
|
storageSchema,
|
|
34
31
|
uploadSchema
|
|
35
|
-
} from "./chunk-
|
|
32
|
+
} from "./chunk-MOGTMGGA.js";
|
|
36
33
|
import {
|
|
37
34
|
broadcastToDevtools
|
|
38
35
|
} from "./chunk-OIGJOYX6.js";
|
|
@@ -52,21 +49,19 @@ import {
|
|
|
52
49
|
import {
|
|
53
50
|
BATCH_PATH,
|
|
54
51
|
createCorsHandler,
|
|
55
|
-
createServerContext,
|
|
56
|
-
createWebRequestSource,
|
|
57
52
|
executeAction,
|
|
58
53
|
executeRoute,
|
|
59
|
-
handleBatchRequest
|
|
54
|
+
handleBatchRequest
|
|
55
|
+
} from "./chunk-SRJBH5E5.js";
|
|
56
|
+
import {
|
|
57
|
+
createWebRequestSource,
|
|
60
58
|
incomingMessageToHandlerRequest,
|
|
61
59
|
sendError,
|
|
62
60
|
writeWebResponseToServerResponse
|
|
63
|
-
} from "./chunk-
|
|
61
|
+
} from "./chunk-3T5XLDOH.js";
|
|
64
62
|
import {
|
|
65
63
|
validateCsrfRequest
|
|
66
64
|
} from "./chunk-P6OS7652.js";
|
|
67
|
-
import {
|
|
68
|
-
subjectFromContext
|
|
69
|
-
} from "./chunk-ENRT6DAU.js";
|
|
70
65
|
import {
|
|
71
66
|
findSuggestion
|
|
72
67
|
} from "./chunk-NTDN54XO.js";
|
|
@@ -93,11 +88,6 @@ import {
|
|
|
93
88
|
import {
|
|
94
89
|
scanAgents
|
|
95
90
|
} from "./chunk-KDP2HURW.js";
|
|
96
|
-
import {
|
|
97
|
-
extractAppResources,
|
|
98
|
-
handleMcpJsonRpc,
|
|
99
|
-
isMcpPath
|
|
100
|
-
} from "./chunk-TQEE36VD.js";
|
|
101
91
|
import {
|
|
102
92
|
resolveProvider
|
|
103
93
|
} from "./chunk-ICXXHV4V.js";
|
|
@@ -110,7 +100,7 @@ import {
|
|
|
110
100
|
|
|
111
101
|
// src/vite-plugin/index.ts
|
|
112
102
|
import { existsSync as existsSync8 } from "node:fs";
|
|
113
|
-
import { resolve as
|
|
103
|
+
import { resolve as resolve9, dirname as dirname4 } from "node:path";
|
|
114
104
|
import { fileURLToPath } from "node:url";
|
|
115
105
|
|
|
116
106
|
// src/vite-plugin/config-hook.ts
|
|
@@ -785,7 +775,7 @@ async function resolvePluginConfig(projectRoot) {
|
|
|
785
775
|
}
|
|
786
776
|
|
|
787
777
|
// src/vite-plugin/configure-server-hook.ts
|
|
788
|
-
import { resolve as
|
|
778
|
+
import { resolve as resolve7, basename } from "node:path";
|
|
789
779
|
|
|
790
780
|
// src/devtools/server-side/route-manifest.ts
|
|
791
781
|
function buildPath(parents, segment) {
|
|
@@ -1025,52 +1015,6 @@ function createActionMiddleware(vite, serverDir, options) {
|
|
|
1025
1015
|
// src/vite-plugin/agent-middleware.ts
|
|
1026
1016
|
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
1027
1017
|
|
|
1028
|
-
// src/server/agent/agent-card-handler.ts
|
|
1029
|
-
import { buildAgentCard, compileLoadedAgentModule } from "@theokit/agents";
|
|
1030
|
-
var WELL_KNOWN = /^\/\.well-known\/([^/]+)\/agent-card\.json$/;
|
|
1031
|
-
function isAgentCardPath(urlPath) {
|
|
1032
|
-
const match = WELL_KNOWN.exec(urlPath);
|
|
1033
|
-
return match ? decodeURIComponent(match[1]) : null;
|
|
1034
|
-
}
|
|
1035
|
-
function toManifestEntry(name, route, mod) {
|
|
1036
|
-
const compiled = compileLoadedAgentModule(mod, `agent card for "${name}"`);
|
|
1037
|
-
return {
|
|
1038
|
-
name,
|
|
1039
|
-
route,
|
|
1040
|
-
stream: compiled.stream,
|
|
1041
|
-
mainLoop: { method: "", strategy: "" },
|
|
1042
|
-
guards: [],
|
|
1043
|
-
interceptors: [],
|
|
1044
|
-
tools: compiled.tools.map((t) => ({
|
|
1045
|
-
name: t.name,
|
|
1046
|
-
description: t.description,
|
|
1047
|
-
approval: false,
|
|
1048
|
-
trace: false,
|
|
1049
|
-
audit: false
|
|
1050
|
-
})),
|
|
1051
|
-
subAgents: []
|
|
1052
|
-
};
|
|
1053
|
-
}
|
|
1054
|
-
function handleAgentCard(mod, name, route, baseUrl) {
|
|
1055
|
-
try {
|
|
1056
|
-
const card = buildAgentCard(toManifestEntry(name, route, mod), { baseUrl });
|
|
1057
|
-
return new Response(JSON.stringify(card), {
|
|
1058
|
-
status: 200,
|
|
1059
|
-
headers: { "content-type": "application/json; charset=utf-8" }
|
|
1060
|
-
});
|
|
1061
|
-
} catch (err) {
|
|
1062
|
-
return new Response(
|
|
1063
|
-
JSON.stringify({
|
|
1064
|
-
error: {
|
|
1065
|
-
code: "AGENT_CARD_FAILED",
|
|
1066
|
-
message: err instanceof Error ? err.message : "card build failed"
|
|
1067
|
-
}
|
|
1068
|
-
}),
|
|
1069
|
-
{ status: 500, headers: { "content-type": "application/json; charset=utf-8" } }
|
|
1070
|
-
);
|
|
1071
|
-
}
|
|
1072
|
-
}
|
|
1073
|
-
|
|
1074
1018
|
// src/server/agent/approve-agent.ts
|
|
1075
1019
|
var APPROVE_SEGMENT = "/approve/";
|
|
1076
1020
|
var APPROVE_PATH = /^\/api\/agents\/([^/]+)\/approve\/([^/]+)$/;
|
|
@@ -1160,445 +1104,6 @@ async function handleAgentApproval(request, urlPath, registry, csrfMode = "stric
|
|
|
1160
1104
|
});
|
|
1161
1105
|
}
|
|
1162
1106
|
|
|
1163
|
-
// src/server/agent/handle-agent-run-reconnect.ts
|
|
1164
|
-
var RUN_STREAM_PATH = /^\/api\/agents\/([^/]+)\/runs\/([^/]+)\/stream$/;
|
|
1165
|
-
function isAgentRunStreamPath(urlPath) {
|
|
1166
|
-
const m = RUN_STREAM_PATH.exec(urlPath);
|
|
1167
|
-
return m ? { name: decodeURIComponent(m[1]), runId: decodeURIComponent(m[2]) } : null;
|
|
1168
|
-
}
|
|
1169
|
-
function parseLastEventId(raw) {
|
|
1170
|
-
if (raw === null) return -1;
|
|
1171
|
-
const n = Number.parseInt(raw, 10);
|
|
1172
|
-
return Number.isInteger(n) && n >= 0 ? n : -1;
|
|
1173
|
-
}
|
|
1174
|
-
function handleAgentRunReconnect(runId, request, cache) {
|
|
1175
|
-
if (!cache.has(runId)) {
|
|
1176
|
-
return new Response(
|
|
1177
|
-
JSON.stringify({ error: { code: "RUN_NOT_FOUND", message: `Unknown run '${runId}'.` } }),
|
|
1178
|
-
{
|
|
1179
|
-
status: 404,
|
|
1180
|
-
headers: { "content-type": "application/json" }
|
|
1181
|
-
}
|
|
1182
|
-
);
|
|
1183
|
-
}
|
|
1184
|
-
const afterSeq = parseLastEventId(request.headers.get("last-event-id"));
|
|
1185
|
-
const stream = new ReadableStream({
|
|
1186
|
-
start(controller) {
|
|
1187
|
-
let closed = false;
|
|
1188
|
-
const safeEnqueue = (text) => {
|
|
1189
|
-
if (closed) return;
|
|
1190
|
-
try {
|
|
1191
|
-
controller.enqueue(encodeSse(text));
|
|
1192
|
-
} catch {
|
|
1193
|
-
}
|
|
1194
|
-
};
|
|
1195
|
-
const close = () => {
|
|
1196
|
-
if (closed) return;
|
|
1197
|
-
safeEnqueue(SSE_DONE_FRAME);
|
|
1198
|
-
closed = true;
|
|
1199
|
-
try {
|
|
1200
|
-
controller.close();
|
|
1201
|
-
} catch {
|
|
1202
|
-
}
|
|
1203
|
-
};
|
|
1204
|
-
const res = cache.attach(
|
|
1205
|
-
runId,
|
|
1206
|
-
afterSeq,
|
|
1207
|
-
(frame) => {
|
|
1208
|
-
safeEnqueue(formatSseFrame(frame.seq, frame.data));
|
|
1209
|
-
},
|
|
1210
|
-
() => {
|
|
1211
|
-
close();
|
|
1212
|
-
}
|
|
1213
|
-
);
|
|
1214
|
-
if (!res.known) {
|
|
1215
|
-
close();
|
|
1216
|
-
return;
|
|
1217
|
-
}
|
|
1218
|
-
for (const frame of res.replay) {
|
|
1219
|
-
safeEnqueue(formatSseFrame(frame.seq, frame.data));
|
|
1220
|
-
}
|
|
1221
|
-
if (res.ended) {
|
|
1222
|
-
close();
|
|
1223
|
-
return;
|
|
1224
|
-
}
|
|
1225
|
-
request.signal.addEventListener("abort", () => {
|
|
1226
|
-
res.unsubscribe();
|
|
1227
|
-
close();
|
|
1228
|
-
});
|
|
1229
|
-
}
|
|
1230
|
-
});
|
|
1231
|
-
return new Response(stream, { headers: { ...SSE_BASE_HEADERS, [RUN_ID_HEADER]: runId } });
|
|
1232
|
-
}
|
|
1233
|
-
|
|
1234
|
-
// src/server/agent/thread-dispatcher.ts
|
|
1235
|
-
function postThreadFollowUp(deps, sessionId, message) {
|
|
1236
|
-
if (deps.registry.getActive(sessionId) !== null) {
|
|
1237
|
-
deps.registry.queue(sessionId, { message });
|
|
1238
|
-
return { queued: true };
|
|
1239
|
-
}
|
|
1240
|
-
return { runId: startAndPump(deps, sessionId, message) };
|
|
1241
|
-
}
|
|
1242
|
-
function startAndPump(deps, sessionId, message) {
|
|
1243
|
-
const runId = mintRunId();
|
|
1244
|
-
deps.cache.begin(runId);
|
|
1245
|
-
deps.registry.startRun(sessionId, runId);
|
|
1246
|
-
pumpIntoCache(deps, sessionId, runId, deps.startRun(sessionId, message));
|
|
1247
|
-
return runId;
|
|
1248
|
-
}
|
|
1249
|
-
function pumpIntoCache(deps, sessionId, runId, chunks) {
|
|
1250
|
-
void (async () => {
|
|
1251
|
-
try {
|
|
1252
|
-
for await (const chunk of chunks) {
|
|
1253
|
-
deps.cache.append(runId, JSON.stringify(chunk));
|
|
1254
|
-
}
|
|
1255
|
-
} catch {
|
|
1256
|
-
} finally {
|
|
1257
|
-
deps.cache.end(runId);
|
|
1258
|
-
const next = deps.registry.endRun(sessionId, runId);
|
|
1259
|
-
if (next !== void 0) startAndPump(deps, sessionId, next.message);
|
|
1260
|
-
}
|
|
1261
|
-
})();
|
|
1262
|
-
}
|
|
1263
|
-
|
|
1264
|
-
// src/server/agent/thread-run-registry.ts
|
|
1265
|
-
function createInProcessThreadRunRegistry() {
|
|
1266
|
-
const threads = /* @__PURE__ */ new Map();
|
|
1267
|
-
const ensure = (sessionId) => {
|
|
1268
|
-
let s = threads.get(sessionId);
|
|
1269
|
-
if (s === void 0) {
|
|
1270
|
-
s = { activeRunId: null, queue: [], waiters: /* @__PURE__ */ new Set() };
|
|
1271
|
-
threads.set(sessionId, s);
|
|
1272
|
-
}
|
|
1273
|
-
return s;
|
|
1274
|
-
};
|
|
1275
|
-
return {
|
|
1276
|
-
getActive(sessionId) {
|
|
1277
|
-
return threads.get(sessionId)?.activeRunId ?? null;
|
|
1278
|
-
},
|
|
1279
|
-
startRun(sessionId, runId) {
|
|
1280
|
-
const s = ensure(sessionId);
|
|
1281
|
-
s.activeRunId = runId;
|
|
1282
|
-
const waiters = [...s.waiters];
|
|
1283
|
-
s.waiters.clear();
|
|
1284
|
-
for (const cb of waiters) cb(runId);
|
|
1285
|
-
},
|
|
1286
|
-
endRun(sessionId, runId) {
|
|
1287
|
-
const s = threads.get(sessionId);
|
|
1288
|
-
if (s?.activeRunId !== runId) return void 0;
|
|
1289
|
-
s.activeRunId = null;
|
|
1290
|
-
return s.queue.shift();
|
|
1291
|
-
},
|
|
1292
|
-
queue(sessionId, followUp) {
|
|
1293
|
-
ensure(sessionId).queue.push(followUp);
|
|
1294
|
-
},
|
|
1295
|
-
onNextRun(sessionId, cb) {
|
|
1296
|
-
const s = ensure(sessionId);
|
|
1297
|
-
s.waiters.add(cb);
|
|
1298
|
-
return () => {
|
|
1299
|
-
s.waiters.delete(cb);
|
|
1300
|
-
};
|
|
1301
|
-
}
|
|
1302
|
-
};
|
|
1303
|
-
}
|
|
1304
|
-
var serverRegistry;
|
|
1305
|
-
function getThreadRunRegistry() {
|
|
1306
|
-
serverRegistry ??= createInProcessThreadRunRegistry();
|
|
1307
|
-
return serverRegistry;
|
|
1308
|
-
}
|
|
1309
|
-
|
|
1310
|
-
// src/server/agent/handle-thread-routes.ts
|
|
1311
|
-
var THREAD_MESSAGE_PATH = /^\/api\/agents\/([^/]+)\/threads\/([^/]+)\/message$/;
|
|
1312
|
-
var THREAD_STREAM_PATH = /^\/api\/agents\/([^/]+)\/threads\/([^/]+)\/stream$/;
|
|
1313
|
-
var DEFAULT_IDLE_WAIT_MS = 3e4;
|
|
1314
|
-
function matchThread(re, urlPath) {
|
|
1315
|
-
const m = re.exec(urlPath);
|
|
1316
|
-
return m ? { name: decodeURIComponent(m[1]), sessionId: decodeURIComponent(m[2]) } : null;
|
|
1317
|
-
}
|
|
1318
|
-
var isThreadMessagePath = (urlPath) => matchThread(THREAD_MESSAGE_PATH, urlPath);
|
|
1319
|
-
var isThreadStreamPath = (urlPath) => matchThread(THREAD_STREAM_PATH, urlPath);
|
|
1320
|
-
function jsonError2(status, code, message) {
|
|
1321
|
-
return new Response(JSON.stringify({ error: { code, message } }), {
|
|
1322
|
-
status,
|
|
1323
|
-
headers: { "content-type": "application/json; charset=utf-8" }
|
|
1324
|
-
});
|
|
1325
|
-
}
|
|
1326
|
-
async function handleThreadMessage(args) {
|
|
1327
|
-
const { mod, apiKey, sessionId, request, source, agentName, csrfMode = "strict" } = args;
|
|
1328
|
-
if (csrfMode === "strict") {
|
|
1329
|
-
const csrf = validateCsrfRequest(request);
|
|
1330
|
-
if (!csrf.valid) return jsonError2(403, "CSRF_FAILED", `CSRF check failed: ${csrf.reason}`);
|
|
1331
|
-
}
|
|
1332
|
-
let body = null;
|
|
1333
|
-
try {
|
|
1334
|
-
body = await request.json();
|
|
1335
|
-
} catch {
|
|
1336
|
-
}
|
|
1337
|
-
const input = parseAgentRequestBody(body);
|
|
1338
|
-
if (input === null) {
|
|
1339
|
-
return jsonError2(400, "BAD_REQUEST", "Request must contain a non-empty message.");
|
|
1340
|
-
}
|
|
1341
|
-
const result = postThreadFollowUp(
|
|
1342
|
-
{
|
|
1343
|
-
registry: getThreadRunRegistry(),
|
|
1344
|
-
cache: getRunEventCache(),
|
|
1345
|
-
// usetheokit/theokit#381 — the request goes with it, so the run's spans join the trace of
|
|
1346
|
-
// the caller that queued it instead of opening one of their own.
|
|
1347
|
-
startRun: makeThreadStartRun(mod, apiKey, source, agentName, request)
|
|
1348
|
-
},
|
|
1349
|
-
sessionId,
|
|
1350
|
-
input.message
|
|
1351
|
-
);
|
|
1352
|
-
const headers = { "content-type": "application/json; charset=utf-8" };
|
|
1353
|
-
if ("runId" in result) headers[RUN_ID_HEADER] = result.runId;
|
|
1354
|
-
return new Response(JSON.stringify(result), { status: 202, headers });
|
|
1355
|
-
}
|
|
1356
|
-
function handleThreadStream(sessionId, request, registry = getThreadRunRegistry(), cache = getRunEventCache(), idleWaitMs = DEFAULT_IDLE_WAIT_MS) {
|
|
1357
|
-
const active = registry.getActive(sessionId);
|
|
1358
|
-
if (active !== null && cache.has(active)) {
|
|
1359
|
-
return handleAgentRunReconnect(active, request, cache);
|
|
1360
|
-
}
|
|
1361
|
-
return waitThenAttachStream(sessionId, request, registry, cache, idleWaitMs);
|
|
1362
|
-
}
|
|
1363
|
-
function waitThenAttachStream(sessionId, request, registry, cache, idleWaitMs) {
|
|
1364
|
-
const stream = new ReadableStream({
|
|
1365
|
-
start(controller) {
|
|
1366
|
-
let closed = false;
|
|
1367
|
-
const send = (text) => {
|
|
1368
|
-
if (closed) return;
|
|
1369
|
-
try {
|
|
1370
|
-
controller.enqueue(encodeSse(text));
|
|
1371
|
-
} catch {
|
|
1372
|
-
}
|
|
1373
|
-
};
|
|
1374
|
-
let detachAttach;
|
|
1375
|
-
const close = () => {
|
|
1376
|
-
if (closed) return;
|
|
1377
|
-
send(SSE_DONE_FRAME);
|
|
1378
|
-
closed = true;
|
|
1379
|
-
try {
|
|
1380
|
-
controller.close();
|
|
1381
|
-
} catch {
|
|
1382
|
-
}
|
|
1383
|
-
};
|
|
1384
|
-
const offNext = registry.onNextRun(sessionId, (runId) => {
|
|
1385
|
-
const res = cache.attach(
|
|
1386
|
-
runId,
|
|
1387
|
-
-1,
|
|
1388
|
-
(frame) => {
|
|
1389
|
-
send(formatSseFrame(frame.seq, frame.data));
|
|
1390
|
-
},
|
|
1391
|
-
() => {
|
|
1392
|
-
close();
|
|
1393
|
-
}
|
|
1394
|
-
);
|
|
1395
|
-
if (!res.known) {
|
|
1396
|
-
close();
|
|
1397
|
-
return;
|
|
1398
|
-
}
|
|
1399
|
-
for (const frame of res.replay) send(formatSseFrame(frame.seq, frame.data));
|
|
1400
|
-
if (res.ended) {
|
|
1401
|
-
close();
|
|
1402
|
-
return;
|
|
1403
|
-
}
|
|
1404
|
-
detachAttach = res.unsubscribe;
|
|
1405
|
-
});
|
|
1406
|
-
const teardownWaiter = () => {
|
|
1407
|
-
offNext();
|
|
1408
|
-
detachAttach?.();
|
|
1409
|
-
};
|
|
1410
|
-
const timer = setTimeout(() => {
|
|
1411
|
-
teardownWaiter();
|
|
1412
|
-
close();
|
|
1413
|
-
}, idleWaitMs);
|
|
1414
|
-
timer.unref();
|
|
1415
|
-
request.signal.addEventListener("abort", () => {
|
|
1416
|
-
teardownWaiter();
|
|
1417
|
-
clearTimeout(timer);
|
|
1418
|
-
close();
|
|
1419
|
-
});
|
|
1420
|
-
}
|
|
1421
|
-
});
|
|
1422
|
-
return new Response(stream, { headers: { ...SSE_BASE_HEADERS } });
|
|
1423
|
-
}
|
|
1424
|
-
|
|
1425
|
-
// src/server/agent/list-approvals-handler.ts
|
|
1426
|
-
var LIST_PATH = /^\/api\/agents\/([^/]+)\/approvals$/;
|
|
1427
|
-
function isListApprovalsPath(urlPath) {
|
|
1428
|
-
const match = LIST_PATH.exec(urlPath);
|
|
1429
|
-
return match ? decodeURIComponent(match[1]) : null;
|
|
1430
|
-
}
|
|
1431
|
-
function handleListApprovals(registry, subject) {
|
|
1432
|
-
const visible = registry.list().filter((approval) => {
|
|
1433
|
-
const owner = registry.ownerOf(approval.approvalId);
|
|
1434
|
-
return owner === void 0 || owner === subject;
|
|
1435
|
-
});
|
|
1436
|
-
return new Response(JSON.stringify({ approvals: visible }), {
|
|
1437
|
-
status: 200,
|
|
1438
|
-
headers: { "content-type": "application/json; charset=utf-8" }
|
|
1439
|
-
});
|
|
1440
|
-
}
|
|
1441
|
-
|
|
1442
|
-
// src/server/agent/serve-aux-routes.ts
|
|
1443
|
-
function jsonError3(status, code, message) {
|
|
1444
|
-
return new Response(JSON.stringify({ error: { code, message } }), {
|
|
1445
|
-
status,
|
|
1446
|
-
headers: { "content-type": "application/json; charset=utf-8" }
|
|
1447
|
-
});
|
|
1448
|
-
}
|
|
1449
|
-
function routeFor(deps, name, build) {
|
|
1450
|
-
if (name === null) return null;
|
|
1451
|
-
const agent = deps.agents.find((a) => a.name === name);
|
|
1452
|
-
return agent === void 0 ? null : build(agent);
|
|
1453
|
-
}
|
|
1454
|
-
function matchGetAuxRoute(verb, urlPath, deps) {
|
|
1455
|
-
if (verb !== "GET") return null;
|
|
1456
|
-
const card = routeFor(
|
|
1457
|
-
deps,
|
|
1458
|
-
isAgentCardPath(urlPath),
|
|
1459
|
-
(agent) => ({ kind: "card", agent })
|
|
1460
|
-
);
|
|
1461
|
-
if (card !== null) return card;
|
|
1462
|
-
const approvals = routeFor(
|
|
1463
|
-
deps,
|
|
1464
|
-
isListApprovalsPath(urlPath),
|
|
1465
|
-
(agent) => ({ kind: "approvals", agent })
|
|
1466
|
-
);
|
|
1467
|
-
if (approvals !== null) return approvals;
|
|
1468
|
-
const run = isAgentRunStreamPath(urlPath);
|
|
1469
|
-
if (run !== null) {
|
|
1470
|
-
return routeFor(
|
|
1471
|
-
deps,
|
|
1472
|
-
run.name,
|
|
1473
|
-
(agent) => ({ kind: "run-stream", agent, runId: run.runId })
|
|
1474
|
-
);
|
|
1475
|
-
}
|
|
1476
|
-
const stream = isThreadStreamPath(urlPath);
|
|
1477
|
-
if (stream === null) return null;
|
|
1478
|
-
return routeFor(
|
|
1479
|
-
deps,
|
|
1480
|
-
stream.name,
|
|
1481
|
-
(agent) => ({ kind: "thread-stream", agent, sessionId: stream.sessionId })
|
|
1482
|
-
);
|
|
1483
|
-
}
|
|
1484
|
-
async function matchPostAuxRoute(verb, urlPath, deps) {
|
|
1485
|
-
if (verb !== "POST") return null;
|
|
1486
|
-
const msg = isThreadMessagePath(urlPath);
|
|
1487
|
-
if (msg !== null) {
|
|
1488
|
-
return routeFor(
|
|
1489
|
-
deps,
|
|
1490
|
-
msg.name,
|
|
1491
|
-
(agent2) => ({ kind: "thread-message", agent: agent2, sessionId: msg.sessionId })
|
|
1492
|
-
);
|
|
1493
|
-
}
|
|
1494
|
-
const agent = routeFor(deps, isMcpPath(urlPath), (found) => found);
|
|
1495
|
-
if (agent === null) return null;
|
|
1496
|
-
const mod = await deps.loadModule(agent.filePath);
|
|
1497
|
-
return isMcpExposed(mod) ? { kind: "mcp", agent, mod } : null;
|
|
1498
|
-
}
|
|
1499
|
-
async function matchAgentAuxRoute(method, urlPath, deps) {
|
|
1500
|
-
const verb = method.toUpperCase();
|
|
1501
|
-
return matchGetAuxRoute(verb, urlPath, deps) ?? await matchPostAuxRoute(verb, urlPath, deps);
|
|
1502
|
-
}
|
|
1503
|
-
async function admitAux(deps, agent, params, body) {
|
|
1504
|
-
const mod = await deps.loadModule(agent.filePath);
|
|
1505
|
-
const resolve11 = deps.resolveSubject;
|
|
1506
|
-
const admitted = { subject: null };
|
|
1507
|
-
const recording = resolve11 === void 0 ? void 0 : async () => {
|
|
1508
|
-
admitted.subject = await resolve11();
|
|
1509
|
-
return admitted.subject;
|
|
1510
|
-
};
|
|
1511
|
-
const decision = await admitAgentRequest(
|
|
1512
|
-
readAgentPolicy(mod, agent.filePath),
|
|
1513
|
-
recording,
|
|
1514
|
-
params,
|
|
1515
|
-
body
|
|
1516
|
-
);
|
|
1517
|
-
const refusal = decision.allowed ? null : agentAccessDenied(decision, params);
|
|
1518
|
-
return { refusal, subject: admitted.subject?.id };
|
|
1519
|
-
}
|
|
1520
|
-
async function serveMatchedAuxRoute(route, request, deps) {
|
|
1521
|
-
if (route.kind === "card") {
|
|
1522
|
-
const mod = await deps.loadModule(route.agent.filePath);
|
|
1523
|
-
return handleAgentCard(mod, route.agent.name, route.agent.agentPath, deps.baseUrl);
|
|
1524
|
-
}
|
|
1525
|
-
if (route.kind === "approvals") {
|
|
1526
|
-
const admission = await admitAux(deps, route.agent, {
|
|
1527
|
-
agent: route.agent.name,
|
|
1528
|
-
endpoint: "approvals"
|
|
1529
|
-
});
|
|
1530
|
-
if (admission.refusal !== null) return admission.refusal;
|
|
1531
|
-
return handleListApprovals(getApprovalRegistry(), admission.subject);
|
|
1532
|
-
}
|
|
1533
|
-
if (route.kind === "run-stream") {
|
|
1534
|
-
return handleAgentRunReconnect(route.runId, request, getRunEventCache());
|
|
1535
|
-
}
|
|
1536
|
-
if (route.kind === "mcp") return serveMcpRoute(route, request, deps);
|
|
1537
|
-
return serveThreadRoute(route, request, deps);
|
|
1538
|
-
}
|
|
1539
|
-
async function serveThreadRoute(route, request, deps) {
|
|
1540
|
-
const { agent, sessionId } = route;
|
|
1541
|
-
if (route.kind === "thread-stream") {
|
|
1542
|
-
const { refusal: refusal2 } = await admitAux(deps, agent, {
|
|
1543
|
-
agent: agent.name,
|
|
1544
|
-
endpoint: "thread-stream",
|
|
1545
|
-
sessionId
|
|
1546
|
-
});
|
|
1547
|
-
return refusal2 ?? handleThreadStream(sessionId, request);
|
|
1548
|
-
}
|
|
1549
|
-
const { refusal } = await admitAux(deps, agent, {
|
|
1550
|
-
agent: agent.name,
|
|
1551
|
-
endpoint: "thread-message",
|
|
1552
|
-
sessionId
|
|
1553
|
-
});
|
|
1554
|
-
if (refusal !== null) return refusal;
|
|
1555
|
-
if (deps.resolveApiKey === void 0) {
|
|
1556
|
-
return jsonError3(
|
|
1557
|
-
501,
|
|
1558
|
-
"NOT_CONFIGURED",
|
|
1559
|
-
"Thread follow-up requires a provider API key (resolveApiKey was not provided to serveMatchedAuxRoute)."
|
|
1560
|
-
);
|
|
1561
|
-
}
|
|
1562
|
-
const mod = await deps.loadModule(agent.filePath);
|
|
1563
|
-
return handleThreadMessage({
|
|
1564
|
-
mod,
|
|
1565
|
-
// Passed unresolved: `makeThreadStartRun` calls it once the module is compiled and the
|
|
1566
|
-
// model is known (theokit#328).
|
|
1567
|
-
apiKey: deps.resolveApiKey,
|
|
1568
|
-
sessionId,
|
|
1569
|
-
request,
|
|
1570
|
-
source: `agent "${agent.name}"`,
|
|
1571
|
-
// usetheokit/theokit#406 — the label above reads well in an `AgentDefinitionError` and is not
|
|
1572
|
-
// a name; the spans get the name, so the same agent is one series whichever route started it.
|
|
1573
|
-
agentName: agent.name,
|
|
1574
|
-
csrfMode: deps.csrfMode ?? "strict"
|
|
1575
|
-
});
|
|
1576
|
-
}
|
|
1577
|
-
async function serveMcpRoute(route, request, deps) {
|
|
1578
|
-
const { agent, mod } = route;
|
|
1579
|
-
const mcpParams = { agent: agent.name, endpoint: "mcp" };
|
|
1580
|
-
const mcpDecision = await admitAgentRequest(
|
|
1581
|
-
readAgentPolicy(mod, agent.filePath),
|
|
1582
|
-
deps.resolveSubject,
|
|
1583
|
-
mcpParams
|
|
1584
|
-
);
|
|
1585
|
-
if (!mcpDecision.allowed) return agentAccessDenied(mcpDecision, mcpParams);
|
|
1586
|
-
const csrfMode = deps.csrfMode ?? "strict";
|
|
1587
|
-
if (csrfMode === "strict") {
|
|
1588
|
-
const csrf = validateCsrfRequest(request);
|
|
1589
|
-
if (!csrf.valid) return jsonError3(403, "CSRF_FAILED", `CSRF check failed: ${csrf.reason}`);
|
|
1590
|
-
}
|
|
1591
|
-
let body = null;
|
|
1592
|
-
try {
|
|
1593
|
-
body = await request.json();
|
|
1594
|
-
} catch {
|
|
1595
|
-
}
|
|
1596
|
-
return handleMcpJsonRpc(mod, agent.name, body, extractAppResources(mod));
|
|
1597
|
-
}
|
|
1598
|
-
function isMcpExposed(mod) {
|
|
1599
|
-
return mod?.mcp === true;
|
|
1600
|
-
}
|
|
1601
|
-
|
|
1602
1107
|
// src/server/http/plugin-lifecycle.ts
|
|
1603
1108
|
function messageOf2(err, fallback) {
|
|
1604
1109
|
return err instanceof Error ? err.message : fallback;
|
|
@@ -1627,22 +1132,6 @@ async function serveThroughPluginLifecycle(target, serve) {
|
|
|
1627
1132
|
if (pluginRunner) await pluginRunner.runOnResponse(pluginCtx);
|
|
1628
1133
|
}
|
|
1629
1134
|
|
|
1630
|
-
// src/server/http/resolve-agent-subject.ts
|
|
1631
|
-
function createAgentSubjectResolver(sources) {
|
|
1632
|
-
let pending;
|
|
1633
|
-
return () => {
|
|
1634
|
-
pending ??= resolve5(sources);
|
|
1635
|
-
return pending;
|
|
1636
|
-
};
|
|
1637
|
-
}
|
|
1638
|
-
async function resolve5(sources) {
|
|
1639
|
-
const { req, res, loadModule, serverDir, pluginRunner } = sources;
|
|
1640
|
-
const produced = serverDir === void 0 ? {} : await createServerContext(req, res, loadModule, serverDir);
|
|
1641
|
-
const ctx = produced ?? {};
|
|
1642
|
-
pluginRunner?.applyDecorations(ctx);
|
|
1643
|
-
return subjectFromContext(ctx);
|
|
1644
|
-
}
|
|
1645
|
-
|
|
1646
1135
|
// src/vite-plugin/agent-middleware.ts
|
|
1647
1136
|
var PREFIX2 = "/api/agents/";
|
|
1648
1137
|
async function serveApprove(req, res, urlPath, deps, log) {
|
|
@@ -1867,7 +1356,7 @@ async function serveAgentTurn(t) {
|
|
|
1867
1356
|
}
|
|
1868
1357
|
|
|
1869
1358
|
// src/vite-plugin/api-middleware.ts
|
|
1870
|
-
import { resolve as
|
|
1359
|
+
import { resolve as resolve5 } from "node:path";
|
|
1871
1360
|
function shouldBypassApiMiddleware(url, prefixes) {
|
|
1872
1361
|
if (!url.startsWith("/api/")) return true;
|
|
1873
1362
|
if (prefixes.length === 0) return false;
|
|
@@ -1915,10 +1404,10 @@ async function handleBatchIfMatch(req, res, ctx) {
|
|
|
1915
1404
|
async function handleBatchInline(req, res, batching, requestId) {
|
|
1916
1405
|
try {
|
|
1917
1406
|
const chunks = [];
|
|
1918
|
-
await new Promise((
|
|
1407
|
+
await new Promise((resolve10, reject) => {
|
|
1919
1408
|
req.on("data", (c) => chunks.push(c));
|
|
1920
1409
|
req.on("end", () => {
|
|
1921
|
-
|
|
1410
|
+
resolve10();
|
|
1922
1411
|
});
|
|
1923
1412
|
req.on("error", reject);
|
|
1924
1413
|
});
|
|
@@ -1974,7 +1463,7 @@ async function runPluginsBeforeRouteMatch(pluginRunner, reqCtx) {
|
|
|
1974
1463
|
}
|
|
1975
1464
|
async function tryControllerFallthrough(ctx) {
|
|
1976
1465
|
const handled = await dispatchControllerRequest({
|
|
1977
|
-
controllersDir:
|
|
1466
|
+
controllersDir: resolve5(ctx.serverDir, "controllers"),
|
|
1978
1467
|
loadModule: ctx.loadModule,
|
|
1979
1468
|
req: ctx.req,
|
|
1980
1469
|
res: ctx.res,
|
|
@@ -2120,7 +1609,7 @@ function createApiMiddleware(vite, serverDir, rateLimitConfigOrOptions) {
|
|
|
2120
1609
|
|
|
2121
1610
|
// src/vite-plugin/ssr-dev-middleware.ts
|
|
2122
1611
|
import { readFileSync as readFileSync2 } from "node:fs";
|
|
2123
|
-
import { resolve as
|
|
1612
|
+
import { resolve as resolve6 } from "node:path";
|
|
2124
1613
|
|
|
2125
1614
|
// src/core/contracts/find-root-div.ts
|
|
2126
1615
|
function maskHtmlComments(html) {
|
|
@@ -2211,7 +1700,7 @@ function setupSsrDevMiddleware(server, opts) {
|
|
|
2211
1700
|
return;
|
|
2212
1701
|
}
|
|
2213
1702
|
try {
|
|
2214
|
-
const indexPath =
|
|
1703
|
+
const indexPath = resolve6(opts.projectRoot, "index.html");
|
|
2215
1704
|
let template = readFileSync2(indexPath, "utf-8");
|
|
2216
1705
|
const nonce = generateNonce();
|
|
2217
1706
|
template = await server.transformIndexHtml(url, template);
|
|
@@ -2354,7 +1843,7 @@ async function runConfigureServer(server, ctx) {
|
|
|
2354
1843
|
csrfReadinessStore
|
|
2355
1844
|
})
|
|
2356
1845
|
);
|
|
2357
|
-
const configPath =
|
|
1846
|
+
const configPath = resolve7(ctx.projectRoot, "theo.config.ts");
|
|
2358
1847
|
server.watcher.on("change", (file) => {
|
|
2359
1848
|
if (file === configPath) {
|
|
2360
1849
|
console.warn(
|
|
@@ -2384,7 +1873,7 @@ async function runConfigureServer(server, ctx) {
|
|
|
2384
1873
|
const openApiCfg = ctx.resolvedOpenApi;
|
|
2385
1874
|
const { reEmitOpenApi } = await import("./dev-emit-7RT624PM.js");
|
|
2386
1875
|
const openApiServerDir = ctx.serverDir;
|
|
2387
|
-
const openApiDistDir =
|
|
1876
|
+
const openApiDistDir = resolve7(ctx.projectRoot, ctx.resolvedDistDir);
|
|
2388
1877
|
const isRouteFileForOpenApi = (file) => file.startsWith(openApiServerDir) && /\.(ts|tsx|js|mjs)$/.test(file);
|
|
2389
1878
|
void reEmitOpenApi(openApiServerDir, openApiDistDir, openApiCfg);
|
|
2390
1879
|
server.watcher.on("change", (file) => {
|
|
@@ -2691,7 +2180,7 @@ async function integrateUseTheoUI(cwd, opts) {
|
|
|
2691
2180
|
|
|
2692
2181
|
// src/vite-plugin/transform-html-hook.ts
|
|
2693
2182
|
import { existsSync as existsSync7 } from "node:fs";
|
|
2694
|
-
import { resolve as
|
|
2183
|
+
import { resolve as resolve8 } from "node:path";
|
|
2695
2184
|
|
|
2696
2185
|
// src/vite-plugin/inject-devtools.ts
|
|
2697
2186
|
var DEVTOOLS_VIRTUAL_ID = "/@theo/devtools/entry.js";
|
|
@@ -2791,7 +2280,7 @@ function runTransformIndexHtml(html, ctx) {
|
|
|
2791
2280
|
next = devtools.html;
|
|
2792
2281
|
const styles = injectStylesheets(next, {
|
|
2793
2282
|
isDev: ctx.isDevMode.value,
|
|
2794
|
-
hasPackage: (name) => existsSync7(
|
|
2283
|
+
hasPackage: (name) => existsSync7(resolve8(ctx.projectRoot, "node_modules", ...name.split("/")))
|
|
2795
2284
|
});
|
|
2796
2285
|
next = styles.html;
|
|
2797
2286
|
return next;
|
|
@@ -3502,7 +2991,7 @@ function findConsumerConfig(projectRoot, basename2) {
|
|
|
3502
2991
|
let dir = projectRoot;
|
|
3503
2992
|
for (let level = 0; level < 3; level++) {
|
|
3504
2993
|
for (const ext of extensions) {
|
|
3505
|
-
const candidate =
|
|
2994
|
+
const candidate = resolve9(dir, `${basename2}${ext}`);
|
|
3506
2995
|
if (existsSync8(candidate)) return candidate;
|
|
3507
2996
|
}
|
|
3508
2997
|
const parent = dirname4(dir);
|
|
@@ -3514,7 +3003,7 @@ function findConsumerConfig(projectRoot, basename2) {
|
|
|
3514
3003
|
async function theoPluginAsync(rootOrOptions) {
|
|
3515
3004
|
const options = typeof rootOrOptions === "string" ? { root: rootOrOptions } : rootOrOptions ?? {};
|
|
3516
3005
|
const projectRoot = options.root ?? process.cwd();
|
|
3517
|
-
const serverDirAbs =
|
|
3006
|
+
const serverDirAbs = resolve9(projectRoot, options.serverDir ?? "server");
|
|
3518
3007
|
const agentsDirName = options.agentsDir ?? "agents";
|
|
3519
3008
|
const consumerTailwindConfig = findConsumerConfig(projectRoot, "tailwind.config");
|
|
3520
3009
|
const consumerPostcssConfig = findConsumerConfig(projectRoot, "postcss.config");
|
|
@@ -3534,24 +3023,24 @@ async function theoPluginAsync(rootOrOptions) {
|
|
|
3534
3023
|
);
|
|
3535
3024
|
}
|
|
3536
3025
|
const { assetsMapPlugin } = await import("./assets-map-CV2YZ3MY.js");
|
|
3537
|
-
const assetsMap = assetsMapPlugin({ appDir:
|
|
3538
|
-
const { appTypedClientPlugin } = await import("./app-typed-client-
|
|
3026
|
+
const assetsMap = assetsMapPlugin({ appDir: resolve9(projectRoot, options.appDir ?? "app") });
|
|
3027
|
+
const { appTypedClientPlugin } = await import("./app-typed-client-C4LRUSIS.js");
|
|
3539
3028
|
const appClientPlugin = appTypedClientPlugin({
|
|
3540
3029
|
cwd: projectRoot,
|
|
3541
3030
|
serverDir: serverDirAbs,
|
|
3542
|
-
distDir:
|
|
3031
|
+
distDir: resolve9(projectRoot, ".theokit")
|
|
3543
3032
|
});
|
|
3544
|
-
const { actionsVirtualModule } = await import("./actions-virtual-module-
|
|
3033
|
+
const { actionsVirtualModule } = await import("./actions-virtual-module-DH3N34I6.js");
|
|
3545
3034
|
const actionsPlugin = actionsVirtualModule({
|
|
3546
3035
|
serverDir: serverDirAbs,
|
|
3547
|
-
distDir:
|
|
3036
|
+
distDir: resolve9(projectRoot, ".theokit")
|
|
3548
3037
|
});
|
|
3549
3038
|
const { agentsTypedClientPlugin } = await import("./agents-typed-client-PVUZU65B.js");
|
|
3550
|
-
const { generateManifest } = await import("./internal-api-
|
|
3039
|
+
const { generateManifest } = await import("./internal-api-XRIBUACB.js");
|
|
3551
3040
|
const agentsClientPlugin = agentsTypedClientPlugin({
|
|
3552
3041
|
projectRoot,
|
|
3553
3042
|
agentsDir: agentsDirName,
|
|
3554
|
-
distDir:
|
|
3043
|
+
distDir: resolve9(projectRoot, ".theokit"),
|
|
3555
3044
|
// Agents live at <projectRoot>/<agentsDir>; generateManifest scans them via the server dir's
|
|
3556
3045
|
// parent (projectRoot for the canonical layout) + the agents dir name (#95 follow-up).
|
|
3557
3046
|
scanManifest: () => generateManifest(serverDirAbs, projectRoot, agentsDirName)
|
|
@@ -3564,7 +3053,7 @@ async function theoPluginAsync(rootOrOptions) {
|
|
|
3564
3053
|
const controllerTransformPlugin = controllerSwcTransformPlugin({
|
|
3565
3054
|
serverDir: serverDirAbs
|
|
3566
3055
|
});
|
|
3567
|
-
const { serverOnlyImportBoundary } = await import("./server-boundary-
|
|
3056
|
+
const { serverOnlyImportBoundary } = await import("./server-boundary-YN5HAICY.js");
|
|
3568
3057
|
const serverBoundaryPlugin = serverOnlyImportBoundary({
|
|
3569
3058
|
projectRoot,
|
|
3570
3059
|
serverDir: serverDirAbs
|
|
@@ -3586,10 +3075,10 @@ async function theoPluginAsync(rootOrOptions) {
|
|
|
3586
3075
|
}
|
|
3587
3076
|
function buildOptimizeDepsInclude(projectRoot, viteOptimizeDeps) {
|
|
3588
3077
|
const include = [];
|
|
3589
|
-
if (existsSync8(
|
|
3078
|
+
if (existsSync8(resolve9(projectRoot, "node_modules", "@theokit", "ui"))) {
|
|
3590
3079
|
include.push("@theokit/ui");
|
|
3591
3080
|
}
|
|
3592
|
-
if (existsSync8(
|
|
3081
|
+
if (existsSync8(resolve9(projectRoot, "node_modules", "lucide-react"))) {
|
|
3593
3082
|
include.push("lucide-react");
|
|
3594
3083
|
}
|
|
3595
3084
|
include.push("devalue");
|
|
@@ -3615,8 +3104,8 @@ var VIRTUAL_MODULE_IDS = {
|
|
|
3615
3104
|
function theoPlugin(rootOrOptions) {
|
|
3616
3105
|
const options = typeof rootOrOptions === "string" ? { root: rootOrOptions } : rootOrOptions ?? {};
|
|
3617
3106
|
const projectRoot = options.root ?? process.cwd();
|
|
3618
|
-
const appDir =
|
|
3619
|
-
const serverDir =
|
|
3107
|
+
const appDir = resolve9(projectRoot, options.appDir ?? "app");
|
|
3108
|
+
const serverDir = resolve9(projectRoot, options.serverDir ?? "server");
|
|
3620
3109
|
const agentsDir = options.agentsDir ?? "agents";
|
|
3621
3110
|
const ssrEnabled = options.ssr ?? false;
|
|
3622
3111
|
const currentDir = dirname4(fileURLToPath(import.meta.url));
|
|
@@ -3748,4 +3237,4 @@ export {
|
|
|
3748
3237
|
theoPluginAsync,
|
|
3749
3238
|
theoPlugin
|
|
3750
3239
|
};
|
|
3751
|
-
//# sourceMappingURL=chunk-
|
|
3240
|
+
//# sourceMappingURL=chunk-QVXMAHZC.js.map
|