theokit 0.30.0 → 0.30.2
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/LICENSE +201 -0
- package/dist/{actions-virtual-module-PBLLMJY4.js → actions-virtual-module-XHVLBFNN.js} +7 -7
- package/dist/actions-virtual-module-Z2IXNF72.js +0 -0
- package/dist/add-W6FNTAFS.js +0 -0
- package/dist/agent-I5QEOMCN.js +0 -0
- package/dist/agents-typed-client-5DCGDWFZ.js +0 -0
- package/dist/{app-typed-client-EXHUWPOI.js → app-typed-client-4PAUHTO6.js} +7 -7
- package/dist/app-typed-client-YCQC3MZ7.js +0 -0
- package/dist/aws-lambda-7GSCNLPY.js +0 -0
- package/dist/body-parser-web-FV5HWCY3.js +0 -0
- package/dist/boot/index.js +3 -3
- package/dist/broadcast-LUMOJIJT.js +0 -0
- package/dist/build-V2QEBE7I.js +0 -0
- package/dist/build-request-body-preview-QMWD2IXK.js +0 -0
- package/dist/bun-KP2KES6S.js +0 -0
- package/dist/check-PD2FTKMM.js +0 -0
- package/dist/chunk-2CVV6CNN.js +0 -0
- package/dist/chunk-45C3WUQ7.js +0 -0
- package/dist/{chunk-UYFZ6DDW.js → chunk-4MTCKE5I.js} +1 -189
- package/dist/chunk-4MTCKE5I.js.map +1 -0
- package/dist/chunk-5ODOE6EF.js +0 -0
- package/dist/chunk-63BUBV5L.js +64 -0
- package/dist/chunk-63BUBV5L.js.map +1 -0
- package/dist/chunk-AFVTEAES.js +0 -0
- package/dist/chunk-FOZIR3TG.js +0 -0
- package/dist/chunk-FRUEDJFX.js +0 -0
- package/dist/chunk-GDN3PXFH.js +0 -0
- package/dist/chunk-GEQJAFSV.js +0 -0
- package/dist/chunk-GSO77FSM.js +0 -0
- package/dist/{chunk-EHUT4FMG.js → chunk-HAOPVC47.js} +29 -27
- package/dist/{chunk-EHUT4FMG.js.map → chunk-HAOPVC47.js.map} +1 -1
- package/dist/chunk-HGZL5EOI.js +0 -0
- package/dist/chunk-HNBWZKIQ.js +0 -0
- package/dist/chunk-HZ6USUHC.js +191 -0
- package/dist/chunk-HZ6USUHC.js.map +1 -0
- package/dist/chunk-IEES3CHD.js +0 -0
- package/dist/chunk-JAIKGP3Q.js +0 -0
- package/dist/chunk-KXA37ONC.js +0 -0
- package/dist/chunk-M6NMS5LR.js +0 -0
- package/dist/chunk-P37RZRFV.js +0 -0
- package/dist/chunk-S7L6H3KP.js +0 -0
- package/dist/chunk-SPFMJAFW.js +326 -0
- package/dist/chunk-SPFMJAFW.js.map +1 -0
- package/dist/chunk-TERFLG67.js +0 -0
- package/dist/{chunk-DMGVH3VG.js → chunk-V3X5FWJA.js} +5 -62
- package/dist/chunk-V3X5FWJA.js.map +1 -0
- package/dist/chunk-VRVNM3QL.js +0 -0
- package/dist/chunk-WR4F4EEZ.js +0 -0
- package/dist/chunk-Y4TOVMNC.js +0 -0
- package/dist/chunk-YJWEADAW.js +0 -0
- package/dist/cloudflare-C6E5SPAE.js +0 -0
- package/dist/configure-agent-registry-ZOBVU3MV.js +0 -0
- package/dist/db-3UNAMSFK.js +0 -0
- package/dist/define-agent-tool-ChaGymol.d.ts +88 -0
- package/dist/deno-deploy-RFZN56X4.js +0 -0
- package/dist/dev-5ZQMWVFC.js +0 -0
- package/dist/dev-emit-EFQRBVYS.js +0 -0
- package/dist/dispatcher-EJHL6JMJ.js +0 -0
- package/dist/docker-LZZB4D5E.js +0 -0
- package/dist/generate-373DALPY.js +0 -0
- package/dist/index.js +11 -10
- package/dist/index.js.map +1 -1
- package/dist/info-2OOXFTJX.js +0 -0
- package/dist/{internal-api-JIR3HRKF.js → internal-api-QSP2HCUU.js} +20 -20
- package/dist/internal-api-Y5REPVUS.js +0 -0
- package/dist/load-config-3EAQTXPH.js +0 -0
- package/dist/mcp-VMKWB2BY.js +0 -0
- package/dist/netlify-PMLHVPN4.js +0 -0
- package/dist/node-BPJ3Z4DT.js +0 -0
- package/dist/openapi-ERYWAT3A.js +0 -0
- package/dist/registry-3NB7KOUI.js +0 -0
- package/dist/router-TLEAOFID.js +0 -0
- package/dist/routes-XNS3UM3B.js +0 -0
- package/dist/scan-7MJC6PYU.js +0 -0
- package/dist/schema-LYOLNHZ7.js +0 -0
- package/dist/server/agent/index.d.ts +387 -0
- package/dist/server/agent/index.js +43 -0
- package/dist/server/agent/index.js.map +1 -0
- package/dist/server/auth/index.js +1 -1
- package/dist/server/define/index.d.ts +3 -86
- package/dist/server/define/index.js +4 -2
- package/dist/server/index.d.ts +10 -387
- package/dist/server/index.js +112 -398
- package/dist/server/index.js.map +1 -1
- package/dist/server/jobs/index.js +4 -4
- package/dist/server/scan/index.js +1 -1
- package/dist/server/webhook/index.d.ts +4 -45
- package/dist/server-error-to-envelope-UUXDSLAZ.js +0 -0
- package/dist/server-routes-hmr-VZXOP5YT.js +0 -0
- package/dist/services-json-Y3XODNB5.js +0 -0
- package/dist/services-typed-client-32KMTTXR.js +0 -0
- package/dist/start-IFTLTEPZ.js +0 -0
- package/dist/static-MB2CD5Y3.js +0 -0
- package/dist/storage-manager-ZSQFLEYT.js +0 -0
- package/dist/theo-cloud-DQRP6S6M.js +0 -0
- package/dist/upgrade-readiness-ACGW44JC.js +0 -0
- package/dist/vercel-J6G7ZHYQ.js +0 -0
- package/dist/vite-plugin/index.js +11 -10
- package/dist/vite-plugin-BNI7YLCD.js +0 -0
- package/dist/webhook-types-CNUZY7o1.d.ts +45 -0
- package/package.json +14 -10
- package/dist/chunk-DMGVH3VG.js.map +0 -1
- package/dist/chunk-UYFZ6DDW.js.map +0 -1
- /package/dist/{actions-virtual-module-PBLLMJY4.js.map → actions-virtual-module-XHVLBFNN.js.map} +0 -0
- /package/dist/{app-typed-client-EXHUWPOI.js.map → app-typed-client-4PAUHTO6.js.map} +0 -0
- /package/dist/{internal-api-JIR3HRKF.js.map → internal-api-QSP2HCUU.js.map} +0 -0
package/dist/server/index.js
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
import {
|
|
2
|
+
StorageManager,
|
|
3
|
+
getStorageManager,
|
|
4
|
+
useDatabase,
|
|
5
|
+
useUnstorage
|
|
6
|
+
} from "../chunk-ESC54TAK.js";
|
|
1
7
|
import {
|
|
2
8
|
BodyTooLargeError,
|
|
3
9
|
DEFAULT_MAX_BODY_BYTES,
|
|
@@ -6,6 +12,11 @@ import {
|
|
|
6
12
|
readRawBody,
|
|
7
13
|
timingSafeEqual
|
|
8
14
|
} from "../chunk-UUFYP2UM.js";
|
|
15
|
+
import {
|
|
16
|
+
MAX_ERROR_HTML_BYTES,
|
|
17
|
+
loadCustomErrorPages,
|
|
18
|
+
serveStaticFile
|
|
19
|
+
} from "../chunk-OPLICDUB.js";
|
|
9
20
|
import {
|
|
10
21
|
DuplicateJobNameError,
|
|
11
22
|
InMemoryJobBackend,
|
|
@@ -42,30 +53,60 @@ import {
|
|
|
42
53
|
} from "../chunk-NM4WF3XD.js";
|
|
43
54
|
import "../chunk-E3JH6YUM.js";
|
|
44
55
|
import "../chunk-JHEAWR3L.js";
|
|
45
|
-
import {
|
|
46
|
-
StorageManager,
|
|
47
|
-
getStorageManager,
|
|
48
|
-
useDatabase,
|
|
49
|
-
useUnstorage
|
|
50
|
-
} from "../chunk-ESC54TAK.js";
|
|
51
56
|
import {
|
|
52
57
|
_resetEnvCache,
|
|
53
|
-
buildResourceDescriptors,
|
|
54
|
-
defineAppResource,
|
|
55
58
|
executeWebRequest,
|
|
56
|
-
extractAppResources,
|
|
57
|
-
handleMcpJsonRpc,
|
|
58
59
|
jsonTransformer,
|
|
59
60
|
loadEnv,
|
|
60
|
-
readAppResource,
|
|
61
61
|
resolveTransformer,
|
|
62
62
|
superjsonTransformer,
|
|
63
63
|
validateRouteInput
|
|
64
|
-
} from "../chunk-
|
|
64
|
+
} from "../chunk-4MTCKE5I.js";
|
|
65
|
+
import {
|
|
66
|
+
ActionError,
|
|
67
|
+
ActionInputError,
|
|
68
|
+
BATCH_PATH,
|
|
69
|
+
BatchPathConflictError,
|
|
70
|
+
STRIPPED_HEADERS,
|
|
71
|
+
TRACE_HEADER,
|
|
72
|
+
TRACE_PARENT_HEADER,
|
|
73
|
+
_resetMiddlewareCacheForTests,
|
|
74
|
+
createCorsHandler,
|
|
75
|
+
createCorsWebHandler,
|
|
76
|
+
executeAction,
|
|
77
|
+
executeRoute,
|
|
78
|
+
extractTraceId,
|
|
79
|
+
extractTraceIdFromRequest,
|
|
80
|
+
extractUniversalIssues,
|
|
81
|
+
handleBatchRequest,
|
|
82
|
+
handleRequestError,
|
|
83
|
+
handleWebRequestError,
|
|
84
|
+
isActionError,
|
|
85
|
+
isInputError,
|
|
86
|
+
matchesOrigin,
|
|
87
|
+
parseTraceparent,
|
|
88
|
+
runMiddlewareAndContext,
|
|
89
|
+
sendError,
|
|
90
|
+
sendJson
|
|
91
|
+
} from "../chunk-TGTNRUH3.js";
|
|
92
|
+
import {
|
|
93
|
+
DuplicateContextKeyError,
|
|
94
|
+
createOutbox,
|
|
95
|
+
createOutboxDispatcher,
|
|
96
|
+
createQueueClient
|
|
97
|
+
} from "../chunk-GY5Q27BJ.js";
|
|
65
98
|
import {
|
|
66
99
|
findSuggestion,
|
|
67
100
|
levenshtein
|
|
68
101
|
} from "../chunk-5QW7IQQU.js";
|
|
102
|
+
import {
|
|
103
|
+
FileTooLargeError,
|
|
104
|
+
_resetWarnOnceForTests,
|
|
105
|
+
createLogger,
|
|
106
|
+
logRequest,
|
|
107
|
+
parseRequestBody,
|
|
108
|
+
warnOnce
|
|
109
|
+
} from "../chunk-WFNLNIJX.js";
|
|
69
110
|
import {
|
|
70
111
|
DuplicateDecorationError,
|
|
71
112
|
DuplicatePluginError,
|
|
@@ -95,6 +136,9 @@ import {
|
|
|
95
136
|
writeManifest
|
|
96
137
|
} from "../chunk-RKDH4DWL.js";
|
|
97
138
|
import "../chunk-WSJKACWB.js";
|
|
139
|
+
import {
|
|
140
|
+
scanMiddlewares
|
|
141
|
+
} from "../chunk-ZEGYW52B.js";
|
|
98
142
|
import {
|
|
99
143
|
CSP_REPORT_PATH,
|
|
100
144
|
CSRF_READINESS_PATH,
|
|
@@ -111,6 +155,49 @@ import {
|
|
|
111
155
|
normalizeLegacy,
|
|
112
156
|
normalizeNew
|
|
113
157
|
} from "../chunk-JBCHWRKF.js";
|
|
158
|
+
import {
|
|
159
|
+
CSRF_WARN_CODE,
|
|
160
|
+
CSRF_WARN_DOCS_URL,
|
|
161
|
+
enforceCsrf,
|
|
162
|
+
matchDisallowed,
|
|
163
|
+
validateCsrf,
|
|
164
|
+
validateCsrfRequest
|
|
165
|
+
} from "../chunk-TSLSIRBR.js";
|
|
166
|
+
import {
|
|
167
|
+
JsonStdoutSink,
|
|
168
|
+
createNoOpLogger,
|
|
169
|
+
safeAudit
|
|
170
|
+
} from "../chunk-UD3LFGDL.js";
|
|
171
|
+
import {
|
|
172
|
+
envelopeCodeToStatus
|
|
173
|
+
} from "../chunk-X32XEJXR.js";
|
|
174
|
+
import {
|
|
175
|
+
NotFoundError,
|
|
176
|
+
TheoError,
|
|
177
|
+
fromUnknown,
|
|
178
|
+
serverErrorToEnvelope
|
|
179
|
+
} from "../chunk-UVXB2ER7.js";
|
|
180
|
+
import {
|
|
181
|
+
CodeModePermissionDeniedError,
|
|
182
|
+
InProcessApprovalRequiredError,
|
|
183
|
+
NodeAcpTransport,
|
|
184
|
+
createACPTool,
|
|
185
|
+
createCodeMode,
|
|
186
|
+
createVendorAgentTool,
|
|
187
|
+
createWorkflowTool,
|
|
188
|
+
handleChannelWebhook,
|
|
189
|
+
handleMcpStdioLine,
|
|
190
|
+
isChannelPath,
|
|
191
|
+
parseChannelPath,
|
|
192
|
+
serveMcpStdio,
|
|
193
|
+
streamAgentTurnInProcess
|
|
194
|
+
} from "../chunk-SPFMJAFW.js";
|
|
195
|
+
import {
|
|
196
|
+
buildResourceDescriptors,
|
|
197
|
+
defineAppResource,
|
|
198
|
+
extractAppResources,
|
|
199
|
+
readAppResource
|
|
200
|
+
} from "../chunk-HZ6USUHC.js";
|
|
114
201
|
import {
|
|
115
202
|
AuthRequiredError,
|
|
116
203
|
_resetKeyCacheForTests,
|
|
@@ -137,6 +224,16 @@ import {
|
|
|
137
224
|
verifyOAuthState,
|
|
138
225
|
verifyTotp
|
|
139
226
|
} from "../chunk-SJIRP73B.js";
|
|
227
|
+
import {
|
|
228
|
+
appendCookieToHeaders,
|
|
229
|
+
appendDeleteCookieToHeaders,
|
|
230
|
+
deleteCookie,
|
|
231
|
+
getCookie,
|
|
232
|
+
getCookieFromRequest,
|
|
233
|
+
parseCookieHeader,
|
|
234
|
+
serializeCookie,
|
|
235
|
+
setCookie
|
|
236
|
+
} from "../chunk-ZJQ4O76G.js";
|
|
140
237
|
import {
|
|
141
238
|
generateNonce
|
|
142
239
|
} from "../chunk-C3ZZ56YZ.js";
|
|
@@ -167,8 +264,6 @@ import "../chunk-7MQOHNHE.js";
|
|
|
167
264
|
import "../chunk-X2VVCJ4V.js";
|
|
168
265
|
import {
|
|
169
266
|
action,
|
|
170
|
-
applyTransform,
|
|
171
|
-
defineAgentTool,
|
|
172
267
|
defineChannel,
|
|
173
268
|
defineWebChannel,
|
|
174
269
|
middleware,
|
|
@@ -177,7 +272,7 @@ import {
|
|
|
177
272
|
tool,
|
|
178
273
|
uiMessageStreamResponse,
|
|
179
274
|
websocket
|
|
180
|
-
} from "../chunk-
|
|
275
|
+
} from "../chunk-V3X5FWJA.js";
|
|
181
276
|
import {
|
|
182
277
|
HEALTH_PATH,
|
|
183
278
|
READY_PATH,
|
|
@@ -186,86 +281,8 @@ import {
|
|
|
186
281
|
serveReservedRoute
|
|
187
282
|
} from "../chunk-V3LJN2GS.js";
|
|
188
283
|
import {
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
serveStaticFile
|
|
192
|
-
} from "../chunk-OPLICDUB.js";
|
|
193
|
-
import {
|
|
194
|
-
ActionError,
|
|
195
|
-
ActionInputError,
|
|
196
|
-
BATCH_PATH,
|
|
197
|
-
BatchPathConflictError,
|
|
198
|
-
STRIPPED_HEADERS,
|
|
199
|
-
TRACE_HEADER,
|
|
200
|
-
TRACE_PARENT_HEADER,
|
|
201
|
-
_resetMiddlewareCacheForTests,
|
|
202
|
-
createCorsHandler,
|
|
203
|
-
createCorsWebHandler,
|
|
204
|
-
executeAction,
|
|
205
|
-
executeRoute,
|
|
206
|
-
extractTraceId,
|
|
207
|
-
extractTraceIdFromRequest,
|
|
208
|
-
extractUniversalIssues,
|
|
209
|
-
handleBatchRequest,
|
|
210
|
-
handleRequestError,
|
|
211
|
-
handleWebRequestError,
|
|
212
|
-
isActionError,
|
|
213
|
-
isInputError,
|
|
214
|
-
matchesOrigin,
|
|
215
|
-
parseTraceparent,
|
|
216
|
-
runMiddlewareAndContext,
|
|
217
|
-
sendError,
|
|
218
|
-
sendJson
|
|
219
|
-
} from "../chunk-TGTNRUH3.js";
|
|
220
|
-
import {
|
|
221
|
-
DuplicateContextKeyError,
|
|
222
|
-
createOutbox,
|
|
223
|
-
createOutboxDispatcher,
|
|
224
|
-
createQueueClient
|
|
225
|
-
} from "../chunk-GY5Q27BJ.js";
|
|
226
|
-
import {
|
|
227
|
-
FileTooLargeError,
|
|
228
|
-
_resetWarnOnceForTests,
|
|
229
|
-
createLogger,
|
|
230
|
-
logRequest,
|
|
231
|
-
parseRequestBody,
|
|
232
|
-
warnOnce
|
|
233
|
-
} from "../chunk-WFNLNIJX.js";
|
|
234
|
-
import {
|
|
235
|
-
scanMiddlewares
|
|
236
|
-
} from "../chunk-ZEGYW52B.js";
|
|
237
|
-
import {
|
|
238
|
-
CSRF_WARN_CODE,
|
|
239
|
-
CSRF_WARN_DOCS_URL,
|
|
240
|
-
enforceCsrf,
|
|
241
|
-
matchDisallowed,
|
|
242
|
-
validateCsrf,
|
|
243
|
-
validateCsrfRequest
|
|
244
|
-
} from "../chunk-TSLSIRBR.js";
|
|
245
|
-
import {
|
|
246
|
-
JsonStdoutSink,
|
|
247
|
-
createNoOpLogger,
|
|
248
|
-
safeAudit
|
|
249
|
-
} from "../chunk-UD3LFGDL.js";
|
|
250
|
-
import {
|
|
251
|
-
envelopeCodeToStatus
|
|
252
|
-
} from "../chunk-X32XEJXR.js";
|
|
253
|
-
import {
|
|
254
|
-
NotFoundError,
|
|
255
|
-
TheoError,
|
|
256
|
-
fromUnknown,
|
|
257
|
-
serverErrorToEnvelope
|
|
258
|
-
} from "../chunk-UVXB2ER7.js";
|
|
259
|
-
import {
|
|
260
|
-
appendCookieToHeaders,
|
|
261
|
-
appendDeleteCookieToHeaders,
|
|
262
|
-
deleteCookie,
|
|
263
|
-
getCookie,
|
|
264
|
-
getCookieFromRequest,
|
|
265
|
-
parseCookieHeader,
|
|
266
|
-
serializeCookie,
|
|
267
|
-
setCookie
|
|
268
|
-
} from "../chunk-ZJQ4O76G.js";
|
|
284
|
+
applyTransform
|
|
285
|
+
} from "../chunk-63BUBV5L.js";
|
|
269
286
|
import "../chunk-DGUM43GV.js";
|
|
270
287
|
|
|
271
288
|
// src/server/openapi/serve-docs.ts
|
|
@@ -1100,309 +1117,6 @@ function resolveRouteRule(path, compiled) {
|
|
|
1100
1117
|
return void 0;
|
|
1101
1118
|
}
|
|
1102
1119
|
|
|
1103
|
-
// src/server/agent/workflow-tool.ts
|
|
1104
|
-
import { z } from "zod";
|
|
1105
|
-
var FAILURE_STATUSES = /* @__PURE__ */ new Set(["failed", "error", "cancelled", "canceled"]);
|
|
1106
|
-
function createWorkflowTool(workflow, config) {
|
|
1107
|
-
const runFn = workflow?.run;
|
|
1108
|
-
if (typeof runFn !== "function") {
|
|
1109
|
-
throw new Error(
|
|
1110
|
-
"createWorkflowTool: the SDK does not expose a Workflow (expected an object with a run() method). Pass a `Workflow.create(...).\u2026build()` instance from @theokit/sdk."
|
|
1111
|
-
);
|
|
1112
|
-
}
|
|
1113
|
-
const inputSchema = config.inputSchema ?? z.looseObject({});
|
|
1114
|
-
return defineAgentTool({
|
|
1115
|
-
name: config.name,
|
|
1116
|
-
description: config.description,
|
|
1117
|
-
inputSchema,
|
|
1118
|
-
handler: async (input) => {
|
|
1119
|
-
const run = await workflow.run(input);
|
|
1120
|
-
if (FAILURE_STATUSES.has(run.status)) {
|
|
1121
|
-
throw new Error(
|
|
1122
|
-
`createWorkflowTool(${JSON.stringify(config.name)}): workflow run ${run.runId ? `'${run.runId}' ` : ""}failed with status '${run.status}'.`
|
|
1123
|
-
);
|
|
1124
|
-
}
|
|
1125
|
-
return typeof run.output === "string" ? run.output : JSON.stringify(run.output);
|
|
1126
|
-
}
|
|
1127
|
-
});
|
|
1128
|
-
}
|
|
1129
|
-
|
|
1130
|
-
// src/server/agent/acp-tool.ts
|
|
1131
|
-
import { spawn } from "child_process";
|
|
1132
|
-
import { AcpClient } from "@theokit/agents";
|
|
1133
|
-
import { encodeAcpMessage } from "@theokit/agents";
|
|
1134
|
-
var NodeAcpTransport = class {
|
|
1135
|
-
// stdin=pipe, stdout=pipe, stderr=inherit → the third stream is null.
|
|
1136
|
-
proc;
|
|
1137
|
-
constructor(command, args = [], cwd) {
|
|
1138
|
-
this.proc = spawn(command, args, { cwd, stdio: ["pipe", "pipe", "inherit"] });
|
|
1139
|
-
}
|
|
1140
|
-
send(line) {
|
|
1141
|
-
this.proc.stdin.write(line);
|
|
1142
|
-
}
|
|
1143
|
-
subscribe(onData) {
|
|
1144
|
-
this.proc.stdout.on("data", (buf) => {
|
|
1145
|
-
onData(buf.toString("utf8"));
|
|
1146
|
-
});
|
|
1147
|
-
}
|
|
1148
|
-
close() {
|
|
1149
|
-
this.proc.kill();
|
|
1150
|
-
}
|
|
1151
|
-
};
|
|
1152
|
-
function defaultTransport(config) {
|
|
1153
|
-
return new NodeAcpTransport(config.command, config.args, config.cwd);
|
|
1154
|
-
}
|
|
1155
|
-
function createACPTool(config) {
|
|
1156
|
-
if (typeof config.onPermissionRequest !== "function") {
|
|
1157
|
-
throw new Error("[theokit] createACPTool requires onPermissionRequest (security by default \u2014 no default-allow)");
|
|
1158
|
-
}
|
|
1159
|
-
const makeTransport = config.transportFactory ?? defaultTransport;
|
|
1160
|
-
return {
|
|
1161
|
-
name: config.name,
|
|
1162
|
-
description: config.description,
|
|
1163
|
-
inputSchema: {
|
|
1164
|
-
type: "object",
|
|
1165
|
-
properties: { message: { type: "string", description: "The task/prompt for the coding agent." } },
|
|
1166
|
-
required: ["message"]
|
|
1167
|
-
},
|
|
1168
|
-
handler: async (input) => {
|
|
1169
|
-
const message = typeof input.message === "string" ? input.message : "";
|
|
1170
|
-
const client = new AcpClient(makeTransport(config));
|
|
1171
|
-
client.onRequest("session/request_permission", (params) => config.onPermissionRequest(params));
|
|
1172
|
-
const result = await client.request("session/prompt", { message });
|
|
1173
|
-
return result.text ?? "";
|
|
1174
|
-
}
|
|
1175
|
-
};
|
|
1176
|
-
}
|
|
1177
|
-
|
|
1178
|
-
// src/server/agent/vendor-agent-tool.ts
|
|
1179
|
-
function createVendorAgentTool(config) {
|
|
1180
|
-
if (!config.vendor || config.vendor.length === 0) {
|
|
1181
|
-
throw new Error('createVendorAgentTool: `vendor` is required (e.g. "claude", "openai").');
|
|
1182
|
-
}
|
|
1183
|
-
const queryFn = config.client?.query;
|
|
1184
|
-
if (typeof queryFn !== "function") {
|
|
1185
|
-
throw new Error(
|
|
1186
|
-
`createVendorAgentTool(${JSON.stringify(config.vendor)}): the vendor client does not expose a query() method. Pass the vendor SDK client (or a @theokit/agent-* wrapper).`
|
|
1187
|
-
);
|
|
1188
|
-
}
|
|
1189
|
-
const name = config.name ?? `${config.vendor}_agent`;
|
|
1190
|
-
const description = config.description ?? `Delegate a task to the ${config.vendor} agent and return its answer.`;
|
|
1191
|
-
return {
|
|
1192
|
-
name,
|
|
1193
|
-
description,
|
|
1194
|
-
inputSchema: {
|
|
1195
|
-
type: "object",
|
|
1196
|
-
properties: {
|
|
1197
|
-
prompt: { type: "string", description: "The task/prompt for the vendor agent." },
|
|
1198
|
-
resumeSessionId: {
|
|
1199
|
-
type: "string",
|
|
1200
|
-
description: "Optional vendor session id to resume a prior conversation."
|
|
1201
|
-
}
|
|
1202
|
-
},
|
|
1203
|
-
required: ["prompt"]
|
|
1204
|
-
},
|
|
1205
|
-
handler: async (input) => {
|
|
1206
|
-
const prompt = typeof input.prompt === "string" ? input.prompt : "";
|
|
1207
|
-
const resumeSessionId = typeof input.resumeSessionId === "string" ? input.resumeSessionId : void 0;
|
|
1208
|
-
const result = await config.client.query(
|
|
1209
|
-
prompt,
|
|
1210
|
-
resumeSessionId !== void 0 ? { resumeSessionId } : void 0
|
|
1211
|
-
);
|
|
1212
|
-
if (result.sessionId !== void 0 && config.onSession) config.onSession(result.sessionId);
|
|
1213
|
-
return result.text;
|
|
1214
|
-
}
|
|
1215
|
-
};
|
|
1216
|
-
}
|
|
1217
|
-
|
|
1218
|
-
// src/server/agent/code-mode.ts
|
|
1219
|
-
var CodeModePermissionDeniedError = class extends Error {
|
|
1220
|
-
constructor(tool2, reason) {
|
|
1221
|
-
const suffix = reason ? `: ${reason}` : "";
|
|
1222
|
-
super(`code-mode: tool '${tool2}' denied by permission gate${suffix}`);
|
|
1223
|
-
this.name = "CodeModePermissionDeniedError";
|
|
1224
|
-
}
|
|
1225
|
-
};
|
|
1226
|
-
function describeToolInput(inputSchema) {
|
|
1227
|
-
const props = inputSchema.properties ?? {};
|
|
1228
|
-
const required = new Set(inputSchema.required ?? []);
|
|
1229
|
-
const entries = Object.entries(props).map(([key, spec]) => {
|
|
1230
|
-
const type = typeof spec.type === "string" ? spec.type : "unknown";
|
|
1231
|
-
return `${key}${required.has(key) ? "" : "?"}: ${type}`;
|
|
1232
|
-
});
|
|
1233
|
-
return entries.length > 0 ? `{ ${entries.join(", ")} }` : "{}";
|
|
1234
|
-
}
|
|
1235
|
-
function generateCodeModeInstructions(tools, toolName) {
|
|
1236
|
-
const calls = tools.map((t) => `- \`await api.${t.name}(${describeToolInput(t.inputSchema)})\` \u2014 ${t.description}`).join("\n");
|
|
1237
|
-
return [
|
|
1238
|
-
`The \`${toolName}\` tool runs your code in a sandbox. Your code may call ONLY these functions (each bridges to a real, validated tool on the host):`,
|
|
1239
|
-
calls,
|
|
1240
|
-
"Write an async function body that composes these calls and return exactly ONE structured result. Prefer `Promise.all` for independent calls; do arithmetic and aggregation in code, not in prose."
|
|
1241
|
-
].join("\n\n");
|
|
1242
|
-
}
|
|
1243
|
-
function createCodeMode(config) {
|
|
1244
|
-
if (typeof config.onPermissionRequest !== "function") {
|
|
1245
|
-
throw new Error(
|
|
1246
|
-
"createCodeMode requires onPermissionRequest (security by default \u2014 no default-allow for any tool)."
|
|
1247
|
-
);
|
|
1248
|
-
}
|
|
1249
|
-
const sandboxRun = config.sandbox?.run;
|
|
1250
|
-
if (typeof sandboxRun !== "function") {
|
|
1251
|
-
throw new Error(
|
|
1252
|
-
"createCodeMode requires an injected `sandbox` with a run() method (a vetted isolation boundary \u2014 never node:vm)."
|
|
1253
|
-
);
|
|
1254
|
-
}
|
|
1255
|
-
if (config.tools.length === 0) {
|
|
1256
|
-
throw new Error(
|
|
1257
|
-
"createCodeMode requires a non-empty tools[] \u2014 the restricted API would be empty."
|
|
1258
|
-
);
|
|
1259
|
-
}
|
|
1260
|
-
const api = {};
|
|
1261
|
-
for (const tool3 of config.tools) {
|
|
1262
|
-
api[tool3.name] = async (args) => {
|
|
1263
|
-
const decision = await config.onPermissionRequest({ tool: tool3.name, args });
|
|
1264
|
-
if (!decision.granted) throw new CodeModePermissionDeniedError(tool3.name, decision.reason);
|
|
1265
|
-
return tool3.handler(args);
|
|
1266
|
-
};
|
|
1267
|
-
}
|
|
1268
|
-
const name = config.name ?? "run_code";
|
|
1269
|
-
const tool2 = {
|
|
1270
|
-
name,
|
|
1271
|
-
description: config.description ?? "Run code that composes the available tools. Only the declared tools are callable.",
|
|
1272
|
-
inputSchema: {
|
|
1273
|
-
type: "object",
|
|
1274
|
-
properties: { code: { type: "string", description: "The code to run in the sandbox." } },
|
|
1275
|
-
required: ["code"]
|
|
1276
|
-
},
|
|
1277
|
-
handler: async (input) => {
|
|
1278
|
-
const code = typeof input.code === "string" ? input.code : "";
|
|
1279
|
-
const result = await config.sandbox.run(code, api);
|
|
1280
|
-
return typeof result === "string" ? result : JSON.stringify(result);
|
|
1281
|
-
}
|
|
1282
|
-
};
|
|
1283
|
-
return { tool: tool2, instructions: generateCodeModeInstructions(config.tools, name) };
|
|
1284
|
-
}
|
|
1285
|
-
|
|
1286
|
-
// src/server/agent/channel-webhook.ts
|
|
1287
|
-
var CHANNEL_PATH = /^\/api\/agents\/([^/]+)\/channels\/([^/]+)\/webhook$/;
|
|
1288
|
-
function parseChannelPath(urlPath) {
|
|
1289
|
-
const match = CHANNEL_PATH.exec(urlPath);
|
|
1290
|
-
if (!match) return null;
|
|
1291
|
-
return { agent: decodeURIComponent(match[1]), platform: decodeURIComponent(match[2]) };
|
|
1292
|
-
}
|
|
1293
|
-
function isChannelPath(urlPath) {
|
|
1294
|
-
return CHANNEL_PATH.test(urlPath);
|
|
1295
|
-
}
|
|
1296
|
-
function jsonError(status, code, message) {
|
|
1297
|
-
return new Response(JSON.stringify({ error: { code, message } }), {
|
|
1298
|
-
status,
|
|
1299
|
-
headers: { "content-type": "application/json" }
|
|
1300
|
-
});
|
|
1301
|
-
}
|
|
1302
|
-
async function handleChannelWebhook(request, urlPath, config) {
|
|
1303
|
-
const parsed = parseChannelPath(urlPath);
|
|
1304
|
-
if (parsed === null) {
|
|
1305
|
-
return jsonError(
|
|
1306
|
-
400,
|
|
1307
|
-
"BAD_REQUEST",
|
|
1308
|
-
"Path must be /api/agents/<name>/channels/<platform>/webhook."
|
|
1309
|
-
);
|
|
1310
|
-
}
|
|
1311
|
-
if (!Object.hasOwn(config.validators, parsed.platform)) {
|
|
1312
|
-
return jsonError(
|
|
1313
|
-
404,
|
|
1314
|
-
"UNKNOWN_PLATFORM",
|
|
1315
|
-
`No validator configured for platform '${parsed.platform}'.`
|
|
1316
|
-
);
|
|
1317
|
-
}
|
|
1318
|
-
const verify = config.validators[parsed.platform];
|
|
1319
|
-
const verifyResult = await verify(request.clone());
|
|
1320
|
-
if (!verifyResult.ok) {
|
|
1321
|
-
return jsonError(
|
|
1322
|
-
401,
|
|
1323
|
-
"INVALID_SIGNATURE",
|
|
1324
|
-
`Signature validation failed: ${verifyResult.reason}`
|
|
1325
|
-
);
|
|
1326
|
-
}
|
|
1327
|
-
let payload;
|
|
1328
|
-
try {
|
|
1329
|
-
payload = await request.json();
|
|
1330
|
-
} catch {
|
|
1331
|
-
return jsonError(400, "BAD_REQUEST", "Request body must be JSON.");
|
|
1332
|
-
}
|
|
1333
|
-
await config.onMessage({ agent: parsed.agent, platform: parsed.platform, payload });
|
|
1334
|
-
return new Response(JSON.stringify({ ok: true }), {
|
|
1335
|
-
status: 200,
|
|
1336
|
-
headers: { "content-type": "application/json" }
|
|
1337
|
-
});
|
|
1338
|
-
}
|
|
1339
|
-
|
|
1340
|
-
// src/server/agent/stream-agent-turn-in-process.ts
|
|
1341
|
-
import {
|
|
1342
|
-
compileAgentModule,
|
|
1343
|
-
resolveEnabledSkills,
|
|
1344
|
-
streamAgentUIMessages
|
|
1345
|
-
} from "@theokit/agents";
|
|
1346
|
-
var InProcessApprovalRequiredError = class extends Error {
|
|
1347
|
-
constructor(toolNames) {
|
|
1348
|
-
super(
|
|
1349
|
-
`Agent has HITL-gated tool(s) [${toolNames.join(", ")}] but no \`awaitApproval\` resolver was supplied to streamAgentTurnInProcess. In-process runs must resolve approvals inline \u2014 pass awaitApproval, or remove the gate. Refused (fail-closed).`
|
|
1350
|
-
);
|
|
1351
|
-
this.name = "InProcessApprovalRequiredError";
|
|
1352
|
-
}
|
|
1353
|
-
};
|
|
1354
|
-
function streamAgentTurnInProcess(mod, apiKey, input, deps = { stream: streamAgentUIMessages }) {
|
|
1355
|
-
const compiled = compileAgentModule(mod, input.source);
|
|
1356
|
-
const gated = compiled.hitl;
|
|
1357
|
-
if (gated && gated.size > 0 && !input.awaitApproval) {
|
|
1358
|
-
throw new InProcessApprovalRequiredError([...gated.keys()]);
|
|
1359
|
-
}
|
|
1360
|
-
const resolve2 = input.awaitApproval;
|
|
1361
|
-
const hitl = gated && gated.size > 0 && resolve2 ? {
|
|
1362
|
-
gated,
|
|
1363
|
-
awaitApproval: (approvalId, opts, toolName) => resolve2({ approvalId, toolName, opts })
|
|
1364
|
-
} : void 0;
|
|
1365
|
-
const sessionId = input.sessionId ?? crypto.randomUUID();
|
|
1366
|
-
return (async function* () {
|
|
1367
|
-
if (compiled.skillsResolver) {
|
|
1368
|
-
const enabled = await resolveEnabledSkills(compiled.skillsResolver, compiled.runContext ?? {});
|
|
1369
|
-
if (enabled !== void 0) compiled.skills = { enabled, autoInject: true };
|
|
1370
|
-
}
|
|
1371
|
-
yield* deps.stream(compiled, apiKey, {
|
|
1372
|
-
message: input.message,
|
|
1373
|
-
sessionId,
|
|
1374
|
-
hitl,
|
|
1375
|
-
signal: input.signal
|
|
1376
|
-
});
|
|
1377
|
-
})();
|
|
1378
|
-
}
|
|
1379
|
-
|
|
1380
|
-
// src/server/agent/mcp-stdio.ts
|
|
1381
|
-
async function handleMcpStdioLine(line, mod, name, appResources = []) {
|
|
1382
|
-
const trimmed = line.trim();
|
|
1383
|
-
if (trimmed.length === 0) return null;
|
|
1384
|
-
let body;
|
|
1385
|
-
try {
|
|
1386
|
-
body = JSON.parse(trimmed);
|
|
1387
|
-
} catch {
|
|
1388
|
-
return JSON.stringify({
|
|
1389
|
-
jsonrpc: "2.0",
|
|
1390
|
-
id: null,
|
|
1391
|
-
error: { code: -32700, message: "Parse error" }
|
|
1392
|
-
});
|
|
1393
|
-
}
|
|
1394
|
-
const response = await handleMcpJsonRpc(mod, name, body, appResources);
|
|
1395
|
-
const payload = await response.json();
|
|
1396
|
-
return JSON.stringify(payload);
|
|
1397
|
-
}
|
|
1398
|
-
async function serveMcpStdio(mod, name, appResources, streams) {
|
|
1399
|
-
for await (const line of streams.lines) {
|
|
1400
|
-
const out = await handleMcpStdioLine(line, mod, name, appResources);
|
|
1401
|
-
if (out !== null) streams.write(`${out}
|
|
1402
|
-
`);
|
|
1403
|
-
}
|
|
1404
|
-
}
|
|
1405
|
-
|
|
1406
1120
|
// src/server/serialization.ts
|
|
1407
1121
|
import superjson from "superjson";
|
|
1408
1122
|
function serializeResponse(data) {
|