theokit 0.16.0 → 0.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/actions-virtual-module-G4BANOLW.js +0 -0
- package/dist/add-W6FNTAFS.js +0 -0
- package/dist/{agent-BBK42EPJ.js → agent-TZ5JZUJ7.js} +3 -3
- package/dist/agents-typed-client-LQ36PCHL.js +0 -0
- package/dist/app-typed-client-Z6BHD4MF.js +0 -0
- package/dist/aws-lambda-7GSCNLPY.js +0 -0
- package/dist/body-parser-web-FV5HWCY3.js +0 -0
- package/dist/broadcast-LUMOJIJT.js +0 -0
- package/dist/{build-LZ4QSZ63.js → build-5PSDDMFB.js} +2 -2
- 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-34YQOXGM.js +0 -0
- package/dist/chunk-45C3WUQ7.js +0 -0
- package/dist/chunk-567NA7Y6.js +0 -0
- package/dist/chunk-5ODOE6EF.js +0 -0
- package/dist/{chunk-7HBLJ5BU.js → chunk-CC5WOQUV.js} +69 -188
- package/dist/chunk-CC5WOQUV.js.map +1 -0
- package/dist/{chunk-AXVP326H.js → chunk-CWVBDUDC.js} +17 -3
- package/dist/chunk-CWVBDUDC.js.map +1 -0
- package/dist/{chunk-3HLO7KAK.js → chunk-DEO2VAJE.js} +163 -71
- package/dist/chunk-DEO2VAJE.js.map +1 -0
- package/dist/chunk-FOZIR3TG.js +0 -0
- package/dist/chunk-GBXLKYIA.js +0 -0
- package/dist/chunk-GDN3PXFH.js +0 -0
- package/dist/chunk-HGZL5EOI.js +0 -0
- package/dist/chunk-HNBWZKIQ.js +0 -0
- package/dist/chunk-IEES3CHD.js +0 -0
- package/dist/chunk-JAIKGP3Q.js +0 -0
- package/dist/chunk-JQSFBJR5.js +0 -0
- package/dist/chunk-KXA37ONC.js +0 -0
- package/dist/{chunk-FIZXWL73.js → chunk-M6NMS5LR.js} +8 -7
- package/dist/{chunk-FIZXWL73.js.map → chunk-M6NMS5LR.js.map} +1 -1
- package/dist/chunk-NXTF5PPW.js +0 -0
- package/dist/chunk-P37RZRFV.js +0 -0
- package/dist/chunk-WR4F4EEZ.js +0 -0
- package/dist/{chunk-Q6KPASBB.js → chunk-XVFMSNDE.js} +247 -7
- package/dist/chunk-XVFMSNDE.js.map +1 -0
- package/dist/{chunk-5UUOGAJH.js → chunk-XWS4RZCE.js} +47 -1
- package/dist/{chunk-5UUOGAJH.js.map → chunk-XWS4RZCE.js.map} +1 -1
- package/dist/chunk-YJAUJXZS.js +0 -0
- package/dist/cli/index.js +4 -4
- package/dist/client/index.d.ts +51 -1
- package/dist/client/index.js +43 -0
- package/dist/client/index.js.map +1 -1
- 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/deno-deploy-RFZN56X4.js +0 -0
- package/dist/{dev-P4GENSZK.js → dev-A7NESJ7S.js} +4 -4
- package/dist/dev-emit-VJ5CFMPY.js +0 -0
- package/dist/dispatcher-EJHL6JMJ.js +0 -0
- package/dist/docker-LZZB4D5E.js +0 -0
- package/dist/generate-OMKHQ7OM.js +0 -0
- package/dist/index.js +2 -2
- package/dist/info-7PE2PZJI.js +0 -0
- package/dist/internal-api-J27TYE2I.js +0 -0
- package/dist/load-config-JKYO5RFK.js +0 -0
- package/dist/netlify-PMLHVPN4.js +0 -0
- package/dist/node-BPJ3Z4DT.js +0 -0
- package/dist/openapi-MXMLZCXC.js +0 -0
- package/dist/registry-XJUYD2OU.js +0 -0
- package/dist/router-TLEAOFID.js +0 -0
- package/dist/routes-NNBEZSGN.js +0 -0
- package/dist/scan-7MJC6PYU.js +0 -0
- package/dist/schema-7CAY6IZR.js +0 -0
- package/dist/server/define/index.d.ts +29 -4
- package/dist/server/define/index.js +3 -1
- package/dist/server/index.d.ts +286 -4
- package/dist/server/index.js +234 -2
- package/dist/server/index.js.map +1 -1
- 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-4VPYN2OS.js → start-WGOKQEUW.js} +31 -7
- package/dist/start-WGOKQEUW.js.map +1 -0
- package/dist/static-7ARBVDJF.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 +2 -2
- package/dist/{vite-plugin-23BBKL3F.js → vite-plugin-DBS2USI4.js} +4 -4
- package/package.json +11 -11
- package/LICENSE +0 -201
- package/dist/chunk-3HLO7KAK.js.map +0 -1
- package/dist/chunk-7HBLJ5BU.js.map +0 -1
- package/dist/chunk-AXVP326H.js.map +0 -1
- package/dist/chunk-Q6KPASBB.js.map +0 -1
- package/dist/start-4VPYN2OS.js.map +0 -1
- /package/dist/{agent-BBK42EPJ.js.map → agent-TZ5JZUJ7.js.map} +0 -0
- /package/dist/{build-LZ4QSZ63.js.map → build-5PSDDMFB.js.map} +0 -0
- /package/dist/{dev-P4GENSZK.js.map → dev-A7NESJ7S.js.map} +0 -0
- /package/dist/{vite-plugin-23BBKL3F.js.map → vite-plugin-DBS2USI4.js.map} +0 -0
package/dist/server/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { RouteConfig } from './define/index.js';
|
|
2
|
-
export { ActionAccept, ActionConfig, ChannelHandler,
|
|
1
|
+
import { RouteConfig, CustomTool } from './define/index.js';
|
|
2
|
+
export { ActionAccept, ActionConfig, ChannelHandler, DefineAgentToolSpec, MiddlewareHandler, ToolTransform, WebChannelHandler, applyTransform, defineAction, defineAgentTool, defineChannel, defineMiddleware, defineRoute, defineTheoPlugin, defineWebChannel, uiMessageStreamResponse } from './define/index.js';
|
|
3
3
|
export { W as WebSocketHandler, a as WebSocketHandlerWeb, b as WebSocketLike, d as defineWebSocket, c as defineWebSocketWeb } from '../define-websocket-CdK94O-D.js';
|
|
4
4
|
export { H as HEALTH_PATH, a as HealthRouteConfig, b as READY_PATH, c as ReadyRouteConfig, d as ReservedResponse, R as ReservedRoutes, e as defineHealthRoute, f as defineReadyRoute, s as serveReservedRoute } from '../health-route-C0hk64_U.js';
|
|
5
5
|
export { B as BATCH_PATH, a as BatchExecuteFn, b as BatchPathConflictError, c as BatchPayload, d as BatchRequestItem, e as BatchResponse, f as BatchResultItem, C as CookieOptions, g as CorsConfig, h as CorsHandler, i as CorsOrigin, j as CorsWebHandler, k as CustomErrorPages, E as ExecuteActionOptions, l as ExecuteRouteContext, H as HandleBatchOptions, M as MAX_ERROR_HTML_BYTES, m as MiddlewareResult, N as NotFoundError, S as STRIPPED_HEADERS, n as SendErrorInput, o as SendErrorOptions, T as TRACE_HEADER, p as TRACE_PARENT_HEADER, q as TheoError, r as TheoTransformer, _ as _resetMiddlewareCacheForTests, s as appendCookieToHeaders, t as appendDeleteCookieToHeaders, u as createCorsHandler, v as createCorsWebHandler, w as deleteCookie, x as envelopeCodeToStatus, y as executeAction, z as executeRoute, A as extractTraceId, D as extractTraceIdFromRequest, F as fromUnknown, G as getCookie, I as getCookieFromRequest, J as handleBatchRequest, K as handleRequestError, L as handleWebRequestError, O as jsonTransformer, P as loadCustomErrorPages, Q as matchesOrigin, R as parseCookieHeader, U as parseTraceparent, V as resolveTransformer, W as runMiddlewareAndContext, X as sendError, Y as sendJson, Z as serializeCookie, $ as serveStaticFile, a0 as serverErrorToEnvelope, a1 as setCookie, a2 as superjsonTransformer } from '../index-B40qUSrQ.js';
|
|
@@ -25,8 +25,11 @@ export { a as CsrfReadinessRouteSummary, C as CsrfReadinessStore, b as CsrfReadi
|
|
|
25
25
|
export { P as PostgresFactory, R as RedisFactory, S as StorageManager, g as getStorageManager } from '../storage-manager-C4jsO0Tp.js';
|
|
26
26
|
export { Db0Database, UnstorageInstance, useDatabase, useUnstorage } from './storage/index.js';
|
|
27
27
|
export { G as GenericFactory, a as PoolLike, P as PostgresDatabaseConfig, c as RedisLike, R as RedisServerConfig, S as ServerConfig, d as StorageAdapter, b as StorageConfig, T as TlsConfig } from '../storage-types-DsDTCPbp.js';
|
|
28
|
-
|
|
28
|
+
import { VerifyFn } from './webhook/index.js';
|
|
29
|
+
export { BodyTooLargeError, DEFAULT_MAX_BODY_BYTES, DefineWebhookOptions, RawBodyResult, ReadRawBodyOptions, VerifyResult, WebhookContext, WebhookDefinition, defineWebhook, dispatchWebhook, readRawBody, timingSafeEqual } from './webhook/index.js';
|
|
29
30
|
import { z } from 'zod';
|
|
31
|
+
import { AcpTransport } from '@theokit/agents';
|
|
32
|
+
import { CustomTool as CustomTool$1 } from '@theokit/sdk';
|
|
30
33
|
import { IncomingMessage } from 'node:http';
|
|
31
34
|
import { W as WebOnRequestHook, b as WebPreHandlerHook, c as WebOnResponseHook, d as WebOnErrorHook } from '../plugin-types-DNJGxr4Z.js';
|
|
32
35
|
export { e as HookName, H as HookResult, O as OnErrorHook, f as OnRequestHook, g as OnResponseHook, P as PluginContext, h as PluginErrorContext, i as PreHandlerHook, R as RunHookOptions, a as TheoApp, T as TheoPlugin, j as definePlugin } from '../plugin-types-DNJGxr4Z.js';
|
|
@@ -647,6 +650,285 @@ declare const THEO_T_PREFIX = "_THEO_T_";
|
|
|
647
650
|
declare const DEFAULT_MAX_AGE = 1;
|
|
648
651
|
declare const DEFAULT_SWR_MULTIPLIER = 60;
|
|
649
652
|
|
|
653
|
+
/**
|
|
654
|
+
* M26 (ADR-0041) — `createWorkflowTool`: wrap an SDK `Workflow` as a `CustomTool`.
|
|
655
|
+
*
|
|
656
|
+
* THIN adapter. `packages/workflows/` stays G13-forbidden — the workflow ENGINE is the SDK's
|
|
657
|
+
* (`Workflow.create(...).run(input)`). This exposes an already-built `Workflow` to an agent as one
|
|
658
|
+
* callable tool: it validates the tool input, delegates to `workflow.run(input)`, and shapes the
|
|
659
|
+
* result for the model. It calls no LLM, dispatches no tool, and runs no orchestration of its own —
|
|
660
|
+
* the SDK owns all of that (sdk-runtime.md / G2).
|
|
661
|
+
*/
|
|
662
|
+
|
|
663
|
+
/**
|
|
664
|
+
* Structural stand-in for the SDK `Workflow` (the adapter never imports the SDK type — keeps the
|
|
665
|
+
* SDK an optional peer). Any object with a `run(input)` resolving to `{ status, output }` matches.
|
|
666
|
+
*/
|
|
667
|
+
interface WorkflowLike {
|
|
668
|
+
run(input: unknown): Promise<{
|
|
669
|
+
status: string;
|
|
670
|
+
output: unknown;
|
|
671
|
+
runId?: string;
|
|
672
|
+
}>;
|
|
673
|
+
}
|
|
674
|
+
/** Config for {@link createWorkflowTool}. `inputSchema` defaults to an open object. */
|
|
675
|
+
interface WorkflowToolConfig {
|
|
676
|
+
/** Tool name surfaced to the LLM. */
|
|
677
|
+
name: string;
|
|
678
|
+
/** Tool description surfaced to the LLM. */
|
|
679
|
+
description: string;
|
|
680
|
+
/** Zod schema for the workflow input (defaults to `z.object({}).passthrough()`). */
|
|
681
|
+
inputSchema?: z.ZodType;
|
|
682
|
+
}
|
|
683
|
+
/**
|
|
684
|
+
* Wrap an SDK `Workflow` as a {@link CustomTool}. Fails fast if `workflow` does not expose a
|
|
685
|
+
* `run()` method (the SDK Workflow contract), so a mis-wired call is caught at definition time, not
|
|
686
|
+
* at the first invocation (error-handling.md).
|
|
687
|
+
*/
|
|
688
|
+
declare function createWorkflowTool(workflow: WorkflowLike, config: WorkflowToolConfig): CustomTool;
|
|
689
|
+
|
|
690
|
+
/** Stdio transport backed by a spawned subprocess (the default for {@link createACPTool}). */
|
|
691
|
+
declare class NodeAcpTransport implements AcpTransport {
|
|
692
|
+
private readonly proc;
|
|
693
|
+
constructor(command: string, args?: string[], cwd?: string);
|
|
694
|
+
send(line: string): void;
|
|
695
|
+
subscribe(onData: (chunk: string) => void): void;
|
|
696
|
+
close(): void;
|
|
697
|
+
}
|
|
698
|
+
interface AcpToolConfig {
|
|
699
|
+
/** Executable for the coding agent (e.g. `claude`, `amp`, `codex`). */
|
|
700
|
+
command: string;
|
|
701
|
+
/** Command-line arguments. */
|
|
702
|
+
args?: string[];
|
|
703
|
+
/** Working directory for the spawned agent. */
|
|
704
|
+
cwd?: string;
|
|
705
|
+
/** Tool name the model calls. */
|
|
706
|
+
name: string;
|
|
707
|
+
/** Tool description surfaced to the model. */
|
|
708
|
+
description: string;
|
|
709
|
+
/**
|
|
710
|
+
* REQUIRED — decide file/shell permission requests from the coding agent. Security by default:
|
|
711
|
+
* there is NO default-allow. Return `{ granted: boolean }` (may be async).
|
|
712
|
+
*/
|
|
713
|
+
onPermissionRequest: (params: unknown) => {
|
|
714
|
+
granted: boolean;
|
|
715
|
+
} | Promise<{
|
|
716
|
+
granted: boolean;
|
|
717
|
+
}>;
|
|
718
|
+
/** Injected transport factory (defaults to spawning via {@link NodeAcpTransport}) — for tests. */
|
|
719
|
+
transportFactory?: (config: AcpToolConfig) => AcpTransport;
|
|
720
|
+
}
|
|
721
|
+
/** Wrap a coding agent as a `CustomTool`. Fails fast if `onPermissionRequest` is missing. */
|
|
722
|
+
declare function createACPTool(config: AcpToolConfig): CustomTool$1;
|
|
723
|
+
|
|
724
|
+
/**
|
|
725
|
+
* M28 (ADR-0041) — `createVendorAgentTool`: expose a third-party agent SDK (Claude Agent SDK,
|
|
726
|
+
* OpenAI, Cursor) behind a uniform `CustomTool`, mirroring the M17 ACP pattern.
|
|
727
|
+
*
|
|
728
|
+
* The vendor RUNTIME stays theirs — TheoKit only wires. The vendor client is INJECTED (the real
|
|
729
|
+
* vendor SDK client in prod, a fake in tests), so no vendor dependency enters core; vendor-specific
|
|
730
|
+
* client packages belong under `@theokit/agent-*`, never here. This calls no LLM of its own and runs
|
|
731
|
+
* no loop — it delegates each prompt to `client.query(...)` (sdk-runtime.md / G2). Resume is threaded
|
|
732
|
+
* via the vendor's own session id.
|
|
733
|
+
*/
|
|
734
|
+
|
|
735
|
+
/**
|
|
736
|
+
* Structural contract a vendor agent client must satisfy (the adapter never imports a vendor type).
|
|
737
|
+
* `query` runs one turn; `resumeSessionId` continues a prior vendor session; the returned
|
|
738
|
+
* `sessionId` identifies the session to resume next.
|
|
739
|
+
*/
|
|
740
|
+
interface VendorAgentClient {
|
|
741
|
+
query(prompt: string, opts?: {
|
|
742
|
+
resumeSessionId?: string;
|
|
743
|
+
}): Promise<{
|
|
744
|
+
text: string;
|
|
745
|
+
sessionId?: string;
|
|
746
|
+
}>;
|
|
747
|
+
}
|
|
748
|
+
/** Config for {@link createVendorAgentTool}. */
|
|
749
|
+
interface VendorAgentToolConfig {
|
|
750
|
+
/** Vendor label (e.g. `claude`, `openai`, `cursor`). Drives the default tool name. */
|
|
751
|
+
vendor: string;
|
|
752
|
+
/** The injected vendor client (real SDK client in prod, a fake in tests). */
|
|
753
|
+
client: VendorAgentClient;
|
|
754
|
+
/** Tool name the model calls (defaults to `<vendor>_agent`). */
|
|
755
|
+
name?: string;
|
|
756
|
+
/** Tool description surfaced to the model (defaults to a one-line delegate hint). */
|
|
757
|
+
description?: string;
|
|
758
|
+
/**
|
|
759
|
+
* Side-channel callback invoked with the vendor session id after each turn — lets the app capture
|
|
760
|
+
* it for a later resume WITHOUT leaking session bookkeeping into the model's view of the result.
|
|
761
|
+
*/
|
|
762
|
+
onSession?: (sessionId: string) => void;
|
|
763
|
+
}
|
|
764
|
+
/**
|
|
765
|
+
* Wrap a vendor agent SDK as a {@link CustomTool}. Fails fast if `vendor` is empty or the client
|
|
766
|
+
* does not expose `query()` (error-handling.md) — a mis-wired call is caught at definition time.
|
|
767
|
+
*/
|
|
768
|
+
declare function createVendorAgentTool(config: VendorAgentToolConfig): CustomTool;
|
|
769
|
+
|
|
770
|
+
/**
|
|
771
|
+
* M29 (ADR-0041) — `createCodeMode`: expose a set of tools to agent-authored code run inside an
|
|
772
|
+
* ISOLATION boundary, so the agent composes tools programmatically instead of one call at a time.
|
|
773
|
+
*
|
|
774
|
+
* Security posture (the whole point of this feature):
|
|
775
|
+
* - The isolation boundary (`sandbox`) is **injected**, never hand-rolled here (Top-risk 1). The app
|
|
776
|
+
* supplies a vetted sandbox — isolated-vm, QuickJS-WASM, or a locked-down worker. TheoKit core
|
|
777
|
+
* ships no VM and adds no sandbox dependency (same posture as the injected deploy adapter / the
|
|
778
|
+
* M17 transport). `node:vm` is NOT a security boundary and MUST NOT be used as the sandbox.
|
|
779
|
+
* - TheoKit owns the **restricted API** (only the declared tools are reachable from the code — no
|
|
780
|
+
* `fs`, `process`, `require`, or network unless a declared, permission-gated tool provides it) and
|
|
781
|
+
* the **mandatory permission gate**: every tool call from the code passes `onPermissionRequest`
|
|
782
|
+
* first, and there is NO default-allow (mirrors M17 `onPermissionRequest`).
|
|
783
|
+
*
|
|
784
|
+
* Threat model (summary): a malicious model could author code that (a) calls a dangerous tool, or
|
|
785
|
+
* (b) tries to reach a host capability. (a) is stopped by the permission gate (deny → the API call
|
|
786
|
+
* throws). (b) is stopped by the injected sandbox (the restricted API is the ONLY surface the code
|
|
787
|
+
* sees). If the app injects a weak sandbox, (b) is on the app — hence the vetted-sandbox requirement.
|
|
788
|
+
*/
|
|
789
|
+
|
|
790
|
+
/** The restricted API handed to sandboxed code: declared tool names → permission-gated callables. */
|
|
791
|
+
type CodeModeApi = Record<string, (args: unknown) => Promise<unknown>>;
|
|
792
|
+
/** The injected isolation boundary. The app supplies a vetted implementation. */
|
|
793
|
+
interface Sandbox {
|
|
794
|
+
/** Run `code` with access to ONLY `api` (the restricted tool surface). Resolve the code's result. */
|
|
795
|
+
run(code: string, api: CodeModeApi): Promise<unknown>;
|
|
796
|
+
}
|
|
797
|
+
/** A permission decision for one tool call from sandboxed code. */
|
|
798
|
+
interface CodeModePermission {
|
|
799
|
+
granted: boolean;
|
|
800
|
+
/** Optional reason surfaced to the model on denial. */
|
|
801
|
+
reason?: string;
|
|
802
|
+
}
|
|
803
|
+
interface CodeModeConfig {
|
|
804
|
+
/** The tools reachable from the code (the restricted API). */
|
|
805
|
+
tools: CustomTool[];
|
|
806
|
+
/** The injected isolation boundary (vetted sandbox — NEVER node:vm). */
|
|
807
|
+
sandbox: Sandbox;
|
|
808
|
+
/**
|
|
809
|
+
* REQUIRED — decide each tool call the code attempts. Security by default: NO default-allow.
|
|
810
|
+
* Return `{ granted }` (may be async). Mirrors M17 `onPermissionRequest`.
|
|
811
|
+
*/
|
|
812
|
+
onPermissionRequest: (req: {
|
|
813
|
+
tool: string;
|
|
814
|
+
args: unknown;
|
|
815
|
+
}) => CodeModePermission | Promise<CodeModePermission>;
|
|
816
|
+
/** Tool name the model calls (default `run_code`). */
|
|
817
|
+
name?: string;
|
|
818
|
+
/** Tool description surfaced to the model. */
|
|
819
|
+
description?: string;
|
|
820
|
+
}
|
|
821
|
+
/** Thrown when the permission gate denies a tool call from sandboxed code. */
|
|
822
|
+
declare class CodeModePermissionDeniedError extends Error {
|
|
823
|
+
constructor(tool: string, reason?: string);
|
|
824
|
+
}
|
|
825
|
+
/**
|
|
826
|
+
* Build a code-mode `CustomTool`. Fails fast if `onPermissionRequest` or `sandbox` is missing
|
|
827
|
+
* (security by default). The returned tool takes `{ code }`, assembles the permission-gated restricted
|
|
828
|
+
* API from `tools`, runs the code in the injected sandbox, and returns the code's result.
|
|
829
|
+
*/
|
|
830
|
+
declare function createCodeMode(config: CodeModeConfig): CustomTool;
|
|
831
|
+
|
|
832
|
+
/**
|
|
833
|
+
* M27 (ADR-0041) — channel webhook routes: `POST /api/agents/<name>/channels/<platform>/webhook`.
|
|
834
|
+
*
|
|
835
|
+
* Auto-generates a per-platform inbound webhook endpoint that VALIDATES the platform signature
|
|
836
|
+
* (reusing the existing webhook `VerifyFn` providers — Slack/Telegram/Discord — never a hand-rolled
|
|
837
|
+
* scheme) and hands the parsed payload to an injected `onMessage` seam. The seam is where an app
|
|
838
|
+
* wires the SDK gateway package (`@theokit/gateway-*`) that translates the payload into an agent
|
|
839
|
+
* turn — TheoKit provides the route + signature gate, NOT the gateway's parsing (G2 / it does not
|
|
840
|
+
* reimplement the gateway).
|
|
841
|
+
*/
|
|
842
|
+
|
|
843
|
+
/** Parsed `{ agent, platform }` from a channel webhook path, or `null` when it doesn't match. */
|
|
844
|
+
declare function parseChannelPath(urlPath: string): {
|
|
845
|
+
agent: string;
|
|
846
|
+
platform: string;
|
|
847
|
+
} | null;
|
|
848
|
+
/** True when `urlPath` targets a channel webhook (dev/prod routing branches on this). */
|
|
849
|
+
declare function isChannelPath(urlPath: string): boolean;
|
|
850
|
+
/** The inbound message handed to the app after signature validation passes. */
|
|
851
|
+
interface ChannelMessage {
|
|
852
|
+
agent: string;
|
|
853
|
+
platform: string;
|
|
854
|
+
/** The parsed JSON payload from the platform (the gateway translates this to an agent turn). */
|
|
855
|
+
payload: unknown;
|
|
856
|
+
}
|
|
857
|
+
interface ChannelWebhookConfig {
|
|
858
|
+
/** Per-platform signature validators (e.g. `{ slack: slack({...}), telegram: telegram({...}) }`). */
|
|
859
|
+
validators: Record<string, VerifyFn>;
|
|
860
|
+
/** Handoff seam — wire the SDK gateway / agent here. Invoked only after signature validation. */
|
|
861
|
+
onMessage: (message: ChannelMessage) => void | Promise<void>;
|
|
862
|
+
}
|
|
863
|
+
/**
|
|
864
|
+
* Handle one channel webhook request. Returns:
|
|
865
|
+
* 404 UNKNOWN_PLATFORM — no validator configured for `<platform>`
|
|
866
|
+
* 400 BAD_REQUEST — path is not a channel webhook, or the body is not JSON
|
|
867
|
+
* 401 INVALID_SIGNATURE — the platform signature check failed (negative case)
|
|
868
|
+
* 200 { ok: true } — validated + handed to `onMessage`
|
|
869
|
+
*/
|
|
870
|
+
declare function handleChannelWebhook(request: Request, urlPath: string, config: ChannelWebhookConfig): Promise<Response>;
|
|
871
|
+
|
|
872
|
+
/**
|
|
873
|
+
* M30 (ADR-0041) — MCP Apps: `ui://` HTML resources for the MCP server (M16).
|
|
874
|
+
*
|
|
875
|
+
* A tool can declare a `ui://` HTML resource; the MCP server advertises it via `resources/list` and
|
|
876
|
+
* serves the HTML via `resources/read`. The client renders it in a SANDBOXED iframe (see
|
|
877
|
+
* `mcp-app-host.ts`). Pure data transforms here — no LLM, no runtime (ADR-0040 § D2 home concern).
|
|
878
|
+
*
|
|
879
|
+
* Security: only the `ui://` scheme is accepted (an app UI resource), never `http(s)://` — the HTML
|
|
880
|
+
* is rendered sandboxed on the client, and the scheme gate keeps a tool from smuggling a remote URL
|
|
881
|
+
* into the app surface.
|
|
882
|
+
*/
|
|
883
|
+
/** A declared `ui://` app resource. */
|
|
884
|
+
interface AppResource {
|
|
885
|
+
uri: string;
|
|
886
|
+
name: string;
|
|
887
|
+
mimeType: 'text/html';
|
|
888
|
+
html: string;
|
|
889
|
+
description?: string;
|
|
890
|
+
}
|
|
891
|
+
/** Input to {@link defineAppResource}. */
|
|
892
|
+
interface AppResourceInput {
|
|
893
|
+
/** MUST start with `ui://`. */
|
|
894
|
+
uri: string;
|
|
895
|
+
name: string;
|
|
896
|
+
html: string;
|
|
897
|
+
description?: string;
|
|
898
|
+
}
|
|
899
|
+
/** An MCP `resources/list` descriptor (no HTML body — that comes from `resources/read`). */
|
|
900
|
+
interface McpResourceDescriptor {
|
|
901
|
+
uri: string;
|
|
902
|
+
name: string;
|
|
903
|
+
mimeType: 'text/html';
|
|
904
|
+
description?: string;
|
|
905
|
+
}
|
|
906
|
+
/** An MCP `resources/read` result. */
|
|
907
|
+
interface McpResourceContents {
|
|
908
|
+
contents: {
|
|
909
|
+
uri: string;
|
|
910
|
+
mimeType: 'text/html';
|
|
911
|
+
text: string;
|
|
912
|
+
}[];
|
|
913
|
+
}
|
|
914
|
+
/**
|
|
915
|
+
* Declare a `ui://` HTML app resource. Fails fast if the uri is not a `ui://` scheme or the HTML is
|
|
916
|
+
* empty (error-handling.md) — a misconfigured resource is caught at definition time.
|
|
917
|
+
*/
|
|
918
|
+
declare function defineAppResource(input: AppResourceInput): AppResource;
|
|
919
|
+
/** Map app resources to MCP `resources/list` descriptors (the HTML body is omitted from the list). */
|
|
920
|
+
declare function buildResourceDescriptors(resources: readonly AppResource[]): McpResourceDescriptor[];
|
|
921
|
+
/** Serve the HTML for `uri` as an MCP `resources/read` result, or `null` when unknown. */
|
|
922
|
+
declare function readAppResource(resources: readonly AppResource[], uri: string): McpResourceContents | null;
|
|
923
|
+
/**
|
|
924
|
+
* M30 wiring — extract the App resources an agent module declares via a named `appResources` export
|
|
925
|
+
* (`export const appResources = [defineAppResource(...)]`). Returns only the well-formed entries; a
|
|
926
|
+
* module without the export (or with a malformed one) yields `[]`. This is how per-agent `ui://`
|
|
927
|
+
* resources reach the MCP server's `resources/list` + `resources/read` without a runtime dependency
|
|
928
|
+
* from `@theokit/agents` on this theo-side type (the module exports them; the serving path reads them).
|
|
929
|
+
*/
|
|
930
|
+
declare function extractAppResources(mod: unknown): AppResource[];
|
|
931
|
+
|
|
650
932
|
interface UploadedFile {
|
|
651
933
|
fieldname: string;
|
|
652
934
|
filename: string;
|
|
@@ -843,4 +1125,4 @@ interface LoadEnvResult {
|
|
|
843
1125
|
declare function _resetEnvCache(): void;
|
|
844
1126
|
declare function loadEnv(options?: LoadEnvOptions): LoadEnvResult;
|
|
845
1127
|
|
|
846
|
-
export { ActionError, type ActionErrorCode, ActionInputError, type ActionManifestEntry, type ActionResult, type BodyParserOptions, DEFAULT_MAX_AGE as CACHE_DEFAULT_MAX_AGE, DEFAULT_MAX_ENTRY_SIZE as CACHE_DEFAULT_MAX_ENTRY_SIZE, DEFAULT_SWR_MULTIPLIER as CACHE_DEFAULT_SWR_MULTIPLIER, CACHE_TAG_MAX_ITEMS, CACHE_TAG_MAX_LENGTH, type CacheControlInput, type CacheEngine, type CacheEngineOptions, type CacheEntry, type CacheStatus, type CacheStorageAdapter, type CacheStore, type CacheStoreAdmin, type ValidationResult as CacheValidationResult, type CachedFunction, type CachedRouteConfig, type CompiledRouteRule, DEFAULT_EXCLUDED_QUERY_PARAMS, type DefineCachedFunctionOptions, FileTooLargeError, type GetOrComputeOptions, InMemoryCacheAdapter, type InMemoryCacheAdapterOptions, type KeyDerivationOptions, type LoadEnvOptions, type LoadEnvResult, type NormalizedCacheConfig, type OpenApiDocsOptions, type ParsedBody, type RevalidateResult, type RouteCacheOptions, RouteConfig, type RouteRule, type RouteRules, type SerializedActionResult, type SerializedResponse, THEO_T_PREFIX, type UniversalZodIssue, type UploadedFile, _resetCacheEngine, _resetEnvCache, compileRouteRules, createCacheEngine, createOpenApiHandler, defineCachedFunction, defineCachedRoute, deriveKey as deriveCacheKey, deserializeResponse, executeWebRequest, extractUniversalIssues, getCacheControlHeader, getCacheEngine, initCacheEngine, isActionError, isInputError, loadEnv, parseRequestBody, resolveRouteRule, revalidatePath, revalidateTag, serializeResponse, updateTag, validateExpire as validateCacheExpire, validateMaxAge as validateCacheMaxAge, validateTags as validateCacheTags };
|
|
1128
|
+
export { type AcpToolConfig, ActionError, type ActionErrorCode, ActionInputError, type ActionManifestEntry, type ActionResult, type AppResource, type AppResourceInput, type BodyParserOptions, DEFAULT_MAX_AGE as CACHE_DEFAULT_MAX_AGE, DEFAULT_MAX_ENTRY_SIZE as CACHE_DEFAULT_MAX_ENTRY_SIZE, DEFAULT_SWR_MULTIPLIER as CACHE_DEFAULT_SWR_MULTIPLIER, CACHE_TAG_MAX_ITEMS, CACHE_TAG_MAX_LENGTH, type CacheControlInput, type CacheEngine, type CacheEngineOptions, type CacheEntry, type CacheStatus, type CacheStorageAdapter, type CacheStore, type CacheStoreAdmin, type ValidationResult as CacheValidationResult, type CachedFunction, type CachedRouteConfig, type ChannelMessage, type ChannelWebhookConfig, type CodeModeApi, type CodeModeConfig, type CodeModePermission, CodeModePermissionDeniedError, type CompiledRouteRule, CustomTool, DEFAULT_EXCLUDED_QUERY_PARAMS, type DefineCachedFunctionOptions, FileTooLargeError, type GetOrComputeOptions, InMemoryCacheAdapter, type InMemoryCacheAdapterOptions, type KeyDerivationOptions, type LoadEnvOptions, type LoadEnvResult, type McpResourceContents, type McpResourceDescriptor, NodeAcpTransport, type NormalizedCacheConfig, type OpenApiDocsOptions, type ParsedBody, type RevalidateResult, type RouteCacheOptions, RouteConfig, type RouteRule, type RouteRules, type Sandbox, type SerializedActionResult, type SerializedResponse, THEO_T_PREFIX, type UniversalZodIssue, type UploadedFile, type VendorAgentClient, type VendorAgentToolConfig, VerifyFn, type WorkflowLike, type WorkflowToolConfig, _resetCacheEngine, _resetEnvCache, buildResourceDescriptors, compileRouteRules, createACPTool, createCacheEngine, createCodeMode, createOpenApiHandler, createVendorAgentTool, createWorkflowTool, defineAppResource, defineCachedFunction, defineCachedRoute, deriveKey as deriveCacheKey, deserializeResponse, executeWebRequest, extractAppResources, extractUniversalIssues, getCacheControlHeader, getCacheEngine, handleChannelWebhook, initCacheEngine, isActionError, isChannelPath, isInputError, loadEnv, parseChannelPath, parseRequestBody, readAppResource, resolveRouteRule, revalidatePath, revalidateTag, serializeResponse, updateTag, validateExpire as validateCacheExpire, validateMaxAge as validateCacheMaxAge, validateTags as validateCacheTags };
|
package/dist/server/index.js
CHANGED
|
@@ -50,12 +50,16 @@ import {
|
|
|
50
50
|
} from "../chunk-ESC54TAK.js";
|
|
51
51
|
import {
|
|
52
52
|
_resetEnvCache,
|
|
53
|
+
buildResourceDescriptors,
|
|
54
|
+
defineAppResource,
|
|
53
55
|
executeWebRequest,
|
|
56
|
+
extractAppResources,
|
|
54
57
|
jsonTransformer,
|
|
55
58
|
loadEnv,
|
|
59
|
+
readAppResource,
|
|
56
60
|
resolveTransformer,
|
|
57
61
|
superjsonTransformer
|
|
58
|
-
} from "../chunk-
|
|
62
|
+
} from "../chunk-XWS4RZCE.js";
|
|
59
63
|
import {
|
|
60
64
|
findSuggestion,
|
|
61
65
|
levenshtein
|
|
@@ -160,6 +164,7 @@ import "../chunk-6NEXVBPY.js";
|
|
|
160
164
|
import "../chunk-7MQOHNHE.js";
|
|
161
165
|
import "../chunk-X2VVCJ4V.js";
|
|
162
166
|
import {
|
|
167
|
+
applyTransform,
|
|
163
168
|
defineAction,
|
|
164
169
|
defineAgentTool,
|
|
165
170
|
defineChannel,
|
|
@@ -169,7 +174,7 @@ import {
|
|
|
169
174
|
defineWebChannel,
|
|
170
175
|
defineWebSocket,
|
|
171
176
|
defineWebSocketWeb
|
|
172
|
-
} from "../chunk-
|
|
177
|
+
} from "../chunk-CWVBDUDC.js";
|
|
173
178
|
import {
|
|
174
179
|
uiMessageStreamResponse
|
|
175
180
|
} from "../chunk-JZHT3LW7.js";
|
|
@@ -1095,6 +1100,219 @@ function resolveRouteRule(path, compiled) {
|
|
|
1095
1100
|
return void 0;
|
|
1096
1101
|
}
|
|
1097
1102
|
|
|
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(tool, reason) {
|
|
1221
|
+
const suffix = reason ? `: ${reason}` : "";
|
|
1222
|
+
super(`code-mode: tool '${tool}' denied by permission gate${suffix}`);
|
|
1223
|
+
this.name = "CodeModePermissionDeniedError";
|
|
1224
|
+
}
|
|
1225
|
+
};
|
|
1226
|
+
function createCodeMode(config) {
|
|
1227
|
+
if (typeof config.onPermissionRequest !== "function") {
|
|
1228
|
+
throw new Error(
|
|
1229
|
+
"createCodeMode requires onPermissionRequest (security by default \u2014 no default-allow for any tool)."
|
|
1230
|
+
);
|
|
1231
|
+
}
|
|
1232
|
+
const sandboxRun = config.sandbox?.run;
|
|
1233
|
+
if (typeof sandboxRun !== "function") {
|
|
1234
|
+
throw new Error(
|
|
1235
|
+
"createCodeMode requires an injected `sandbox` with a run() method (a vetted isolation boundary \u2014 never node:vm)."
|
|
1236
|
+
);
|
|
1237
|
+
}
|
|
1238
|
+
const api = {};
|
|
1239
|
+
for (const tool of config.tools) {
|
|
1240
|
+
api[tool.name] = async (args) => {
|
|
1241
|
+
const decision = await config.onPermissionRequest({ tool: tool.name, args });
|
|
1242
|
+
if (!decision.granted) throw new CodeModePermissionDeniedError(tool.name, decision.reason);
|
|
1243
|
+
return tool.handler(args);
|
|
1244
|
+
};
|
|
1245
|
+
}
|
|
1246
|
+
return {
|
|
1247
|
+
name: config.name ?? "run_code",
|
|
1248
|
+
description: config.description ?? "Run code that composes the available tools. Only the declared tools are callable.",
|
|
1249
|
+
inputSchema: {
|
|
1250
|
+
type: "object",
|
|
1251
|
+
properties: { code: { type: "string", description: "The code to run in the sandbox." } },
|
|
1252
|
+
required: ["code"]
|
|
1253
|
+
},
|
|
1254
|
+
handler: async (input) => {
|
|
1255
|
+
const code = typeof input.code === "string" ? input.code : "";
|
|
1256
|
+
const result = await config.sandbox.run(code, api);
|
|
1257
|
+
return typeof result === "string" ? result : JSON.stringify(result);
|
|
1258
|
+
}
|
|
1259
|
+
};
|
|
1260
|
+
}
|
|
1261
|
+
|
|
1262
|
+
// src/server/agent/channel-webhook.ts
|
|
1263
|
+
var CHANNEL_PATH = /^\/api\/agents\/([^/]+)\/channels\/([^/]+)\/webhook$/;
|
|
1264
|
+
function parseChannelPath(urlPath) {
|
|
1265
|
+
const match = CHANNEL_PATH.exec(urlPath);
|
|
1266
|
+
if (!match) return null;
|
|
1267
|
+
return { agent: decodeURIComponent(match[1]), platform: decodeURIComponent(match[2]) };
|
|
1268
|
+
}
|
|
1269
|
+
function isChannelPath(urlPath) {
|
|
1270
|
+
return CHANNEL_PATH.test(urlPath);
|
|
1271
|
+
}
|
|
1272
|
+
function jsonError(status, code, message) {
|
|
1273
|
+
return new Response(JSON.stringify({ error: { code, message } }), {
|
|
1274
|
+
status,
|
|
1275
|
+
headers: { "content-type": "application/json" }
|
|
1276
|
+
});
|
|
1277
|
+
}
|
|
1278
|
+
async function handleChannelWebhook(request, urlPath, config) {
|
|
1279
|
+
const parsed = parseChannelPath(urlPath);
|
|
1280
|
+
if (parsed === null) {
|
|
1281
|
+
return jsonError(
|
|
1282
|
+
400,
|
|
1283
|
+
"BAD_REQUEST",
|
|
1284
|
+
"Path must be /api/agents/<name>/channels/<platform>/webhook."
|
|
1285
|
+
);
|
|
1286
|
+
}
|
|
1287
|
+
if (!Object.hasOwn(config.validators, parsed.platform)) {
|
|
1288
|
+
return jsonError(
|
|
1289
|
+
404,
|
|
1290
|
+
"UNKNOWN_PLATFORM",
|
|
1291
|
+
`No validator configured for platform '${parsed.platform}'.`
|
|
1292
|
+
);
|
|
1293
|
+
}
|
|
1294
|
+
const verify = config.validators[parsed.platform];
|
|
1295
|
+
const verifyResult = await verify(request.clone());
|
|
1296
|
+
if (!verifyResult.ok) {
|
|
1297
|
+
return jsonError(
|
|
1298
|
+
401,
|
|
1299
|
+
"INVALID_SIGNATURE",
|
|
1300
|
+
`Signature validation failed: ${verifyResult.reason}`
|
|
1301
|
+
);
|
|
1302
|
+
}
|
|
1303
|
+
let payload;
|
|
1304
|
+
try {
|
|
1305
|
+
payload = await request.json();
|
|
1306
|
+
} catch {
|
|
1307
|
+
return jsonError(400, "BAD_REQUEST", "Request body must be JSON.");
|
|
1308
|
+
}
|
|
1309
|
+
await config.onMessage({ agent: parsed.agent, platform: parsed.platform, payload });
|
|
1310
|
+
return new Response(JSON.stringify({ ok: true }), {
|
|
1311
|
+
status: 200,
|
|
1312
|
+
headers: { "content-type": "application/json" }
|
|
1313
|
+
});
|
|
1314
|
+
}
|
|
1315
|
+
|
|
1098
1316
|
// src/server/serialization.ts
|
|
1099
1317
|
import superjson from "superjson";
|
|
1100
1318
|
function serializeResponse(data) {
|
|
@@ -1140,6 +1358,7 @@ export {
|
|
|
1140
1358
|
CSRF_WARN_CODE,
|
|
1141
1359
|
CSRF_WARN_DOCS_URL,
|
|
1142
1360
|
ChannelManager,
|
|
1361
|
+
CodeModePermissionDeniedError,
|
|
1143
1362
|
ConsoleObservabilityAdapter,
|
|
1144
1363
|
CsrfReadinessStore,
|
|
1145
1364
|
DEFAULT_CSP,
|
|
@@ -1162,6 +1381,7 @@ export {
|
|
|
1162
1381
|
JOB_MANIFEST_SCHEMA_VERSION,
|
|
1163
1382
|
JsonStdoutSink,
|
|
1164
1383
|
MAX_ERROR_HTML_BYTES,
|
|
1384
|
+
NodeAcpTransport,
|
|
1165
1385
|
NonRetryableError,
|
|
1166
1386
|
NoopObservabilityAdapter,
|
|
1167
1387
|
NoopSpan,
|
|
@@ -1185,16 +1405,20 @@ export {
|
|
|
1185
1405
|
appendCookieToHeaders,
|
|
1186
1406
|
appendDeleteCookieToHeaders,
|
|
1187
1407
|
applySecurityHeaders,
|
|
1408
|
+
applyTransform,
|
|
1188
1409
|
assertProductionSecret,
|
|
1189
1410
|
buildCronManifest,
|
|
1190
1411
|
buildJobManifest,
|
|
1412
|
+
buildResourceDescriptors,
|
|
1191
1413
|
buildSecurityHeaders,
|
|
1192
1414
|
checkThrottle,
|
|
1193
1415
|
clearOidcCache,
|
|
1194
1416
|
compilePattern,
|
|
1195
1417
|
compileRouteRules,
|
|
1196
1418
|
convertToAwsCron,
|
|
1419
|
+
createACPTool,
|
|
1197
1420
|
createCacheEngine,
|
|
1421
|
+
createCodeMode,
|
|
1198
1422
|
createCorsHandler,
|
|
1199
1423
|
createCorsWebHandler,
|
|
1200
1424
|
createCronScheduler,
|
|
@@ -1214,10 +1438,13 @@ export {
|
|
|
1214
1438
|
createRouteRateLimiterWeb,
|
|
1215
1439
|
createSessionManager,
|
|
1216
1440
|
createSessionManagerWeb,
|
|
1441
|
+
createVendorAgentTool,
|
|
1217
1442
|
createViteLoader,
|
|
1443
|
+
createWorkflowTool,
|
|
1218
1444
|
decrypt,
|
|
1219
1445
|
defineAction,
|
|
1220
1446
|
defineAgentTool,
|
|
1447
|
+
defineAppResource,
|
|
1221
1448
|
defineCachedFunction,
|
|
1222
1449
|
defineCachedRoute,
|
|
1223
1450
|
defineChannel,
|
|
@@ -1247,6 +1474,7 @@ export {
|
|
|
1247
1474
|
executeAction,
|
|
1248
1475
|
executeRoute,
|
|
1249
1476
|
executeWebRequest,
|
|
1477
|
+
extractAppResources,
|
|
1250
1478
|
extractTraceId,
|
|
1251
1479
|
extractTraceIdFromRequest,
|
|
1252
1480
|
extractUniversalIssues,
|
|
@@ -1265,6 +1493,7 @@ export {
|
|
|
1265
1493
|
getCookieFromRequest,
|
|
1266
1494
|
getStorageManager,
|
|
1267
1495
|
handleBatchRequest,
|
|
1496
|
+
handleChannelWebhook,
|
|
1268
1497
|
handleCspReport,
|
|
1269
1498
|
handleCspReportRequest,
|
|
1270
1499
|
handleCsrfReadiness,
|
|
@@ -1273,6 +1502,7 @@ export {
|
|
|
1273
1502
|
handleWebRequestError,
|
|
1274
1503
|
initCacheEngine,
|
|
1275
1504
|
isActionError,
|
|
1505
|
+
isChannelPath,
|
|
1276
1506
|
isInputError,
|
|
1277
1507
|
jsonTransformer,
|
|
1278
1508
|
levenshtein,
|
|
@@ -1286,10 +1516,12 @@ export {
|
|
|
1286
1516
|
matchesOrigin,
|
|
1287
1517
|
normalizeLegacy,
|
|
1288
1518
|
normalizeNew,
|
|
1519
|
+
parseChannelPath,
|
|
1289
1520
|
parseCookieHeader,
|
|
1290
1521
|
parseRequestBody,
|
|
1291
1522
|
parseTraceparent,
|
|
1292
1523
|
pkceChallengeFromVerifier,
|
|
1524
|
+
readAppResource,
|
|
1293
1525
|
readRawBody,
|
|
1294
1526
|
recordAttempt,
|
|
1295
1527
|
requireAuth,
|