theokit 0.2.4 → 0.4.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-HWNTIEPI.js → actions-virtual-module-IY46EEEX.js} +2 -2
- package/dist/{actions-virtual-module-SEIPACG5.js → actions-virtual-module-XNHDNCZ6.js} +2 -2
- package/dist/add-2ZFFGGE4.js +0 -0
- package/dist/{app-typed-client-6GC6VWXS.js → app-typed-client-OUJO3V5J.js} +10 -5
- package/dist/{app-typed-client-6GC6VWXS.js.map → app-typed-client-OUJO3V5J.js.map} +1 -1
- package/dist/{app-typed-client-US2ZXBEC.js → app-typed-client-YOMWSA3F.js} +11 -6
- package/dist/{app-typed-client-US2ZXBEC.js.map → app-typed-client-YOMWSA3F.js.map} +1 -1
- package/dist/audit-log-BQWM5YLG.d.ts +60 -0
- package/dist/{aws-lambda-XYCGZH3I.js → aws-lambda-GKSTX6HD.js} +3 -3
- package/dist/body-parser-web-MUWBKZ3F.js +70 -0
- package/dist/body-parser-web-MUWBKZ3F.js.map +1 -0
- package/dist/broadcast-QOQGUNNK.js +0 -0
- package/dist/{build-MREW6MVS.js → build-D4J7XECU.js} +33 -24
- package/dist/build-D4J7XECU.js.map +1 -0
- package/dist/build-request-body-preview-II2235E6.js +0 -0
- package/dist/{bun-K73TQEWC.js → bun-ISHSNFIO.js} +3 -3
- package/dist/{check-PZR67OY5.js → check-NXYPLM6M.js} +2 -2
- package/dist/{chunk-WZ7CPVQB.js → chunk-27LWMYNK.js} +28 -24
- package/dist/chunk-27LWMYNK.js.map +1 -0
- package/dist/{chunk-5OKZY2VL.js → chunk-2F4FROEQ.js} +1695 -1522
- package/dist/chunk-2F4FROEQ.js.map +1 -0
- package/dist/chunk-4HBI7DHP.js +20 -0
- package/dist/chunk-4HBI7DHP.js.map +1 -0
- package/dist/{chunk-X4JAX2U3.js → chunk-4S2UCILN.js} +180 -125
- package/dist/chunk-4S2UCILN.js.map +1 -0
- package/dist/{chunk-C52GSJPF.js → chunk-4S6YHNG2.js} +11 -8
- package/dist/chunk-4S6YHNG2.js.map +1 -0
- package/dist/chunk-5ODOE6EF.js +0 -0
- package/dist/{chunk-KJVEJILQ.js → chunk-5PU65T5W.js} +9 -3
- package/dist/chunk-5PU65T5W.js.map +1 -0
- package/dist/chunk-5QW7IQQU.js +36 -0
- package/dist/chunk-5QW7IQQU.js.map +1 -0
- package/dist/chunk-5Z2727GV.js +1324 -0
- package/dist/chunk-5Z2727GV.js.map +1 -0
- package/dist/{chunk-YLBSSEHX.js → chunk-6NEXVBPY.js} +5 -15
- package/dist/chunk-6NEXVBPY.js.map +1 -0
- package/dist/chunk-7MQOHNHE.js +36 -0
- package/dist/chunk-7MQOHNHE.js.map +1 -0
- package/dist/{chunk-TPCT3MXV.js → chunk-ABVITXFH.js} +405 -272
- package/dist/chunk-ABVITXFH.js.map +1 -0
- package/dist/chunk-ASDXVRJD.js +185 -0
- package/dist/chunk-ASDXVRJD.js.map +1 -0
- package/dist/chunk-B3L3TJVF.js +406 -0
- package/dist/chunk-B3L3TJVF.js.map +1 -0
- package/dist/{chunk-PB4GR7EP.js → chunk-C3ZZ56YZ.js} +1 -18
- package/dist/chunk-C3ZZ56YZ.js.map +1 -0
- package/dist/{chunk-O7335ZGH.js → chunk-CG563V5M.js} +5 -3
- package/dist/chunk-CG563V5M.js.map +1 -0
- package/dist/{chunk-5OFPQK6N.js → chunk-COXLEZCN.js} +2 -1
- package/dist/chunk-COXLEZCN.js.map +1 -0
- package/dist/{chunk-O4BLVPML.js → chunk-DNMSV3R3.js} +22 -28
- package/dist/chunk-DNMSV3R3.js.map +1 -0
- package/dist/chunk-E3JH6YUM.js +1 -0
- package/dist/chunk-ESC54TAK.js +220 -0
- package/dist/chunk-ESC54TAK.js.map +1 -0
- package/dist/chunk-FI7MPTJW.js +77 -0
- package/dist/chunk-FI7MPTJW.js.map +1 -0
- package/dist/chunk-H4J2LECY.js +201 -0
- package/dist/chunk-H4J2LECY.js.map +1 -0
- package/dist/chunk-IAJ2JVEH.js +256 -0
- package/dist/chunk-IAJ2JVEH.js.map +1 -0
- package/dist/{chunk-F3TG5FJV.js → chunk-IEZCAT2I.js} +7 -1
- package/dist/{chunk-F3TG5FJV.js.map → chunk-IEZCAT2I.js.map} +1 -1
- package/dist/chunk-JHEAWR3L.js +1 -0
- package/dist/chunk-JQSKBMXP.js +17 -0
- package/dist/chunk-JQSKBMXP.js.map +1 -0
- package/dist/{chunk-4QTKSLTO.js → chunk-K4M64WD6.js} +9 -5
- package/dist/{chunk-4QTKSLTO.js.map → chunk-K4M64WD6.js.map} +1 -1
- package/dist/chunk-KI7OWQUX.js +293 -0
- package/dist/chunk-KI7OWQUX.js.map +1 -0
- package/dist/chunk-KT3MWNZG.js +0 -0
- package/dist/{chunk-ZJW5FFYJ.js → chunk-LC5PYNJP.js} +2 -2
- package/dist/{chunk-X2OLD264.js → chunk-M2EY7KDR.js} +1228 -1124
- package/dist/chunk-M2EY7KDR.js.map +1 -0
- package/dist/{chunk-YWWHK7R6.js → chunk-MR7OLIC6.js} +3 -3
- package/dist/chunk-NM4WF3XD.js +63 -0
- package/dist/chunk-NM4WF3XD.js.map +1 -0
- package/dist/chunk-NPMCKOX4.js +1 -0
- package/dist/{chunk-VRHXOKRP.js → chunk-NZXH2LQQ.js} +86 -83
- package/dist/chunk-NZXH2LQQ.js.map +1 -0
- package/dist/{chunk-2BQYEBCK.js → chunk-OLPB36O2.js} +87 -5
- package/dist/chunk-OLPB36O2.js.map +1 -0
- package/dist/chunk-PIVX3DYW.js +142 -0
- package/dist/chunk-PIVX3DYW.js.map +1 -0
- package/dist/{chunk-7TOMTMHT.js → chunk-R7OC6UDK.js} +2 -1
- package/dist/chunk-R7OC6UDK.js.map +1 -0
- package/dist/chunk-RESN62GB.js +269 -0
- package/dist/chunk-RESN62GB.js.map +1 -0
- package/dist/{chunk-64JI5LTO.js → chunk-RMU7EBRO.js} +2 -2
- package/dist/chunk-RMU7EBRO.js.map +1 -0
- package/dist/chunk-TQYSPYKU.js +131 -0
- package/dist/chunk-TQYSPYKU.js.map +1 -0
- package/dist/chunk-TSLSIRBR.js +107 -0
- package/dist/chunk-TSLSIRBR.js.map +1 -0
- package/dist/{chunk-XP7YXRHO.js → chunk-U6TPSW4L.js} +37 -5
- package/dist/chunk-U6TPSW4L.js.map +1 -0
- package/dist/chunk-UD3LFGDL.js +45 -0
- package/dist/chunk-UD3LFGDL.js.map +1 -0
- package/dist/chunk-UUFYP2UM.js +161 -0
- package/dist/chunk-UUFYP2UM.js.map +1 -0
- package/dist/{chunk-SNDZQ64K.js → chunk-VBZCVFSA.js} +85 -3
- package/dist/chunk-VBZCVFSA.js.map +1 -0
- package/dist/chunk-VMEWD57H.js +137 -0
- package/dist/chunk-VMEWD57H.js.map +1 -0
- package/dist/{chunk-BE2LKDI7.js → chunk-WEGALZEU.js} +3 -3
- package/dist/{chunk-ZOXNJV2O.js → chunk-WGHJD6I7.js} +35 -138
- package/dist/chunk-WGHJD6I7.js.map +1 -0
- package/dist/chunk-XMS5VRIK.js +0 -0
- package/dist/chunk-Y4H3JNVK.js +18 -0
- package/dist/chunk-Y4H3JNVK.js.map +1 -0
- package/dist/chunk-Z5IGLBWE.js +329 -0
- package/dist/chunk-Z5IGLBWE.js.map +1 -0
- package/dist/chunk-ZEGYW52B.js +26 -0
- package/dist/chunk-ZEGYW52B.js.map +1 -0
- package/dist/chunk-ZJQ4O76G.js +87 -0
- package/dist/chunk-ZJQ4O76G.js.map +1 -0
- package/dist/cli/index.js +44 -9
- package/dist/cli/index.js.map +1 -1
- package/dist/client/index.d.ts +107 -1
- package/dist/client/index.js +152 -6
- package/dist/client/index.js.map +1 -1
- package/dist/{cloudflare-LCAOTRYZ.js → cloudflare-OJGJ7R2D.js} +3 -3
- package/dist/configure-agent-registry-6YGTJYBC.js +0 -0
- package/dist/cookies-MJKMGJ7N.js +22 -0
- package/dist/csrf-BBrEZSBW.d.ts +107 -0
- package/dist/csrf-readiness-store-CjIoub3U.d.ts +43 -0
- package/dist/define-websocket-CdK94O-D.d.ts +64 -0
- package/dist/{deno-deploy-ZN4RE5HF.js → deno-deploy-BHWKFTOW.js} +3 -3
- package/dist/{dev-6P2DM33Q.js → dev-MJVSRZGF.js} +13 -13
- package/dist/{dev-emit-MLDFOLUU.js → dev-emit-5VPRCHOD.js} +39 -142
- package/dist/dev-emit-5VPRCHOD.js.map +1 -0
- package/dist/{dev-emit-PRSRPDHA.js → dev-emit-HHP2XJXE.js} +5 -5
- package/dist/devtools/entry.js +185 -131
- package/dist/devtools/entry.js.map +1 -1
- package/dist/{dispatcher-AQJGI3HU.js → dispatcher-63LBXYLE.js} +2 -2
- package/dist/{dispatcher-E6QV32BO.js → dispatcher-EJME6C6M.js} +5 -2
- package/dist/dispatcher-EJME6C6M.js.map +1 -0
- package/dist/{dist-E6BL4ZVY.js → dist-KRW6OVD4.js} +7 -7
- package/dist/dist-KRW6OVD4.js.map +1 -0
- package/dist/docker-EZDA5FT7.js +0 -0
- package/dist/error-envelope-BsNzzAV5.d.ts +62 -0
- package/dist/{generate-DT4IIAHF.js → generate-AZ2K6Z2Z.js} +75 -2
- package/dist/generate-AZ2K6Z2Z.js.map +1 -0
- package/dist/index-DWWEdFh5.d.ts +399 -0
- package/dist/index.d.ts +161 -1391
- package/dist/index.js +20 -8
- package/dist/index.js.map +1 -1
- package/dist/{info-FJ4NXKTB.js → info-47VB62MV.js} +5 -5
- package/dist/job-backend-CgC8Xf33.d.ts +68 -0
- package/dist/{lib-NL5JXGEB.js → lib-NST3PNZX.js} +31 -31
- package/dist/lib-NST3PNZX.js.map +1 -0
- package/dist/module-loader-Cfz7dgCP.d.ts +26 -0
- package/dist/{netlify-5VQ22Z2P.js → netlify-GSNSJGMN.js} +3 -3
- package/dist/{node-3APTLGWB.js → node-6I5B6RL3.js} +3 -3
- package/dist/node-6I5B6RL3.js.map +1 -0
- package/dist/{openapi-SOKZTFE3.js → openapi-NFLSNNVQ.js} +10 -10
- package/dist/plugin-runner-BGBkzgi0.d.ts +95 -0
- package/dist/plugin-types-DNJGxr4Z.d.ts +79 -0
- package/dist/{proper-lockfile-4Y3DP3RP.js → proper-lockfile-MVKMQGFK.js} +27 -27
- package/dist/proper-lockfile-MVKMQGFK.js.map +1 -0
- package/dist/rate-limit-BdNDZ3vt.d.ts +58 -0
- package/dist/registry-QHEZ3BWB.js +25 -0
- package/dist/router-RGZFX75G.js +274 -0
- package/dist/router-RGZFX75G.js.map +1 -0
- package/dist/{routes-XVRAUH6H.js → routes-3A4XGIEJ.js} +6 -6
- package/dist/{scan-C2BOKLSY.js → scan-NQFI5S7P.js} +2 -2
- package/dist/scan-NQFI5S7P.js.map +1 -0
- package/dist/schema-D3v8VB7o.d.ts +76 -0
- package/dist/{schema-VR6YNVLQ.js → schema-KZVOV333.js} +5 -3
- package/dist/schema-KZVOV333.js.map +1 -0
- package/dist/server/agent/index.d.ts +229 -0
- package/dist/server/agent/index.js +16 -0
- package/dist/server/agent/index.js.map +1 -0
- package/dist/server/auth/index.d.ts +46 -1
- package/dist/server/auth/index.js +10 -3
- package/dist/server/cost/index.d.ts +1 -3
- package/dist/server/cost/index.js +1 -1
- package/dist/server/cron/index.js +4 -2
- package/dist/server/define/index.d.ts +281 -0
- package/dist/server/define/index.js +26 -0
- package/dist/server/define/index.js.map +1 -0
- package/dist/server/http/index.d.ts +10 -0
- package/dist/server/http/index.js +74 -0
- package/dist/server/http/index.js.map +1 -0
- package/dist/server/index.d.ts +151 -1677
- package/dist/server/index.js +558 -1102
- package/dist/server/index.js.map +1 -1
- package/dist/server/jobs/index.d.ts +348 -2
- package/dist/server/jobs/index.js +5 -3
- package/dist/server/observability/index.d.ts +324 -0
- package/dist/server/observability/index.js +48 -0
- package/dist/server/observability/index.js.map +1 -0
- package/dist/server/plugins/index.d.ts +17 -0
- package/dist/server/plugins/index.js +17 -0
- package/dist/server/plugins/index.js.map +1 -0
- package/dist/server/rate-limit/index.d.ts +105 -0
- package/dist/server/rate-limit/index.js +25 -0
- package/dist/server/rate-limit/index.js.map +1 -0
- package/dist/server/realtime/index.d.ts +15 -0
- package/dist/server/realtime/index.js +8 -0
- package/dist/server/realtime/index.js.map +1 -0
- package/dist/server/scan/index.d.ts +106 -0
- package/dist/server/scan/index.js +43 -0
- package/dist/server/scan/index.js.map +1 -0
- package/dist/server/security/index.d.ts +193 -0
- package/dist/server/security/index.js +50 -0
- package/dist/server/security/index.js.map +1 -0
- package/dist/server/storage/index.d.ts +22 -0
- package/dist/server/storage/index.js +14 -0
- package/dist/server/storage/index.js.map +1 -0
- package/dist/server/webhook/index.d.ts +148 -0
- package/dist/server/webhook/index.js +19 -0
- package/dist/server/webhook/index.js.map +1 -0
- package/dist/server-error-to-envelope-NO4CCAFQ.js +8 -0
- package/dist/server-error-to-envelope-NO4CCAFQ.js.map +1 -0
- package/dist/server-error-to-envelope-UJK6OWDJ.js +134 -0
- package/dist/server-error-to-envelope-UJK6OWDJ.js.map +1 -0
- package/dist/server-routes-hmr-GZJGPWMS.js +44 -0
- package/dist/server-routes-hmr-GZJGPWMS.js.map +1 -0
- package/dist/server-routes-hmr-PBHSKCQJ.js +42 -0
- package/dist/server-routes-hmr-PBHSKCQJ.js.map +1 -0
- package/dist/services-json-Z2QNGVPW.js +142 -0
- package/dist/services-json-Z2QNGVPW.js.map +1 -0
- package/dist/{services-typed-client-XWYYBWGW.js → services-typed-client-KK6RHRDG.js} +2 -2
- package/dist/{services-typed-client-ZX5JUHH3.js → services-typed-client-T7M5VPBP.js} +2 -2
- package/dist/{sqlite-vec-ARPNUBWT.js → sqlite-vec-54KB4RD3.js} +2 -2
- package/dist/sqlite-vec-54KB4RD3.js.map +1 -0
- package/dist/{start-R7XSQL5L.js → start-CGSZPBAG.js} +23 -23
- package/dist/start-CGSZPBAG.js.map +1 -0
- package/dist/{static-TZBVBDTB.js → static-QI5NQT2X.js} +6 -6
- package/dist/storage-manager-C4jsO0Tp.d.ts +89 -0
- package/dist/storage-manager-D5KBXXKB.js +0 -0
- package/dist/{storage-types-DtIVejC1.d.ts → storage-types-DsDTCPbp.d.ts} +1 -1
- package/dist/{theo-cloud-3K4DGB3S.js → theo-cloud-RSQCBNXL.js} +4 -4
- package/dist/theo-cloud-RSQCBNXL.js.map +1 -0
- package/dist/upgrade-readiness-GUJBCJIS.js +0 -0
- package/dist/{vercel-MWW24ABC.js → vercel-TKPZK62A.js} +3 -3
- package/dist/vite-plugin/index.d.ts +3 -1
- package/dist/vite-plugin/index.js +20 -8
- package/dist/{vite-plugin-6MPHTKIW.js → vite-plugin-CR4JDFUQ.js} +9 -9
- package/dist/vite-plugin-CR4JDFUQ.js.map +1 -0
- package/package.json +59 -10
- package/LICENSE +0 -201
- package/dist/build-MREW6MVS.js.map +0 -1
- package/dist/chunk-2BQYEBCK.js.map +0 -1
- package/dist/chunk-5OFPQK6N.js.map +0 -1
- package/dist/chunk-5OKZY2VL.js.map +0 -1
- package/dist/chunk-64JI5LTO.js.map +0 -1
- package/dist/chunk-7TOMTMHT.js.map +0 -1
- package/dist/chunk-C52GSJPF.js.map +0 -1
- package/dist/chunk-CZM6WWWS.js +0 -2450
- package/dist/chunk-CZM6WWWS.js.map +0 -1
- package/dist/chunk-KJVEJILQ.js.map +0 -1
- package/dist/chunk-O4BLVPML.js.map +0 -1
- package/dist/chunk-O7335ZGH.js.map +0 -1
- package/dist/chunk-PB4GR7EP.js.map +0 -1
- package/dist/chunk-SNDZQ64K.js.map +0 -1
- package/dist/chunk-TPCT3MXV.js.map +0 -1
- package/dist/chunk-VRHXOKRP.js.map +0 -1
- package/dist/chunk-WZ7CPVQB.js.map +0 -1
- package/dist/chunk-X2OLD264.js.map +0 -1
- package/dist/chunk-X4JAX2U3.js.map +0 -1
- package/dist/chunk-XP7YXRHO.js.map +0 -1
- package/dist/chunk-YLBSSEHX.js.map +0 -1
- package/dist/chunk-ZOXNJV2O.js.map +0 -1
- package/dist/dev-emit-MLDFOLUU.js.map +0 -1
- package/dist/dispatcher-E6QV32BO.js.map +0 -1
- package/dist/dist-E6BL4ZVY.js.map +0 -1
- package/dist/generate-DT4IIAHF.js.map +0 -1
- package/dist/index-li83Swxa.d.ts +0 -506
- package/dist/lib-NL5JXGEB.js.map +0 -1
- package/dist/proper-lockfile-4Y3DP3RP.js.map +0 -1
- package/dist/registry-5QFTLOL2.js +0 -25
- package/dist/schema-CjVly9c_.d.ts +0 -274
- package/dist/sqlite-vec-ARPNUBWT.js.map +0 -1
- package/dist/start-R7XSQL5L.js.map +0 -1
- package/dist/theo-cloud-3K4DGB3S.js.map +0 -1
- /package/dist/{actions-virtual-module-HWNTIEPI.js.map → actions-virtual-module-IY46EEEX.js.map} +0 -0
- /package/dist/{actions-virtual-module-SEIPACG5.js.map → actions-virtual-module-XNHDNCZ6.js.map} +0 -0
- /package/dist/{aws-lambda-XYCGZH3I.js.map → aws-lambda-GKSTX6HD.js.map} +0 -0
- /package/dist/{bun-K73TQEWC.js.map → bun-ISHSNFIO.js.map} +0 -0
- /package/dist/{check-PZR67OY5.js.map → check-NXYPLM6M.js.map} +0 -0
- /package/dist/{dispatcher-AQJGI3HU.js.map → chunk-E3JH6YUM.js.map} +0 -0
- /package/dist/{node-3APTLGWB.js.map → chunk-JHEAWR3L.js.map} +0 -0
- /package/dist/{chunk-ZJW5FFYJ.js.map → chunk-LC5PYNJP.js.map} +0 -0
- /package/dist/{chunk-YWWHK7R6.js.map → chunk-MR7OLIC6.js.map} +0 -0
- /package/dist/{scan-C2BOKLSY.js.map → chunk-NPMCKOX4.js.map} +0 -0
- /package/dist/{chunk-BE2LKDI7.js.map → chunk-WEGALZEU.js.map} +0 -0
- /package/dist/{cloudflare-LCAOTRYZ.js.map → cloudflare-OJGJ7R2D.js.map} +0 -0
- /package/dist/{schema-VR6YNVLQ.js.map → cookies-MJKMGJ7N.js.map} +0 -0
- /package/dist/{deno-deploy-ZN4RE5HF.js.map → deno-deploy-BHWKFTOW.js.map} +0 -0
- /package/dist/{dev-6P2DM33Q.js.map → dev-MJVSRZGF.js.map} +0 -0
- /package/dist/{dev-emit-PRSRPDHA.js.map → dev-emit-HHP2XJXE.js.map} +0 -0
- /package/dist/{vite-plugin-6MPHTKIW.js.map → dispatcher-63LBXYLE.js.map} +0 -0
- /package/dist/{info-FJ4NXKTB.js.map → info-47VB62MV.js.map} +0 -0
- /package/dist/{netlify-5VQ22Z2P.js.map → netlify-GSNSJGMN.js.map} +0 -0
- /package/dist/{openapi-SOKZTFE3.js.map → openapi-NFLSNNVQ.js.map} +0 -0
- /package/dist/{registry-5QFTLOL2.js.map → registry-QHEZ3BWB.js.map} +0 -0
- /package/dist/{routes-XVRAUH6H.js.map → routes-3A4XGIEJ.js.map} +0 -0
- /package/dist/{services-typed-client-XWYYBWGW.js.map → services-typed-client-KK6RHRDG.js.map} +0 -0
- /package/dist/{services-typed-client-ZX5JUHH3.js.map → services-typed-client-T7M5VPBP.js.map} +0 -0
- /package/dist/{static-TZBVBDTB.js.map → static-QI5NQT2X.js.map} +0 -0
- /package/dist/{vercel-MWW24ABC.js.map → vercel-TKPZK62A.js.map} +0 -0
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
import { a as AgentErrorEvent, A as AgentEvent } from '../../agent-events-B3KNV9ER.js';
|
|
2
|
+
export { b as AgentMessageEvent, e as AgentRunErrorCode, c as AgentToolCallEvent, d as AgentToolResultEvent } from '../../agent-events-B3KNV9ER.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Item #4 — `streamAgentRun`
|
|
6
|
+
*
|
|
7
|
+
* Adapter that consumes the `@theokit/sdk` `Run.stream()` async generator
|
|
8
|
+
* (SDKMessage variants) and yields TheoKit `AgentEvent`s suitable for SSE
|
|
9
|
+
* via `defineAgentEndpoint`. One line at the consumer side:
|
|
10
|
+
*
|
|
11
|
+
* ```ts
|
|
12
|
+
* const run = await agent.send(message)
|
|
13
|
+
* yield* streamAgentRun(run)
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* Mapping table (SDK → AgentEvent):
|
|
17
|
+
*
|
|
18
|
+
* | SDK message | AgentEvent yielded |
|
|
19
|
+
* |---|---|
|
|
20
|
+
* | assistant.content[].type==='text' | { type: 'message', content } |
|
|
21
|
+
* | assistant.content[].type==='tool_use'| (none — covered by tool_call below) |
|
|
22
|
+
* | tool_call(status='running') | { type: 'tool_call', name, args, id } |
|
|
23
|
+
* | tool_call(status='completed') | { type: 'tool_result', name, data, id }|
|
|
24
|
+
* | tool_call(status='error') | { type: 'error', message, id } |
|
|
25
|
+
* | run.wait() status==='error' | { type: 'error', message } |
|
|
26
|
+
* | run.wait() status==='cancelled' | (none — cancel ≠ error) |
|
|
27
|
+
* | system / user / thinking / status / | (none — internal SDK telemetry) |
|
|
28
|
+
* | task / request / object_delta | |
|
|
29
|
+
*
|
|
30
|
+
* Abort semantics: when the consumer calls `generator.return()` on the
|
|
31
|
+
* outer `defineAgentEndpoint` generator, `streamAgentRun` exits the
|
|
32
|
+
* `for await` loop and does NOT call `run.wait()`. Cleanup of in-flight
|
|
33
|
+
* SDK resources is the SDK consumer's responsibility (`run.cancel()`).
|
|
34
|
+
*/
|
|
35
|
+
/**
|
|
36
|
+
* Local mirror of the SDK's `Run` interface — only the surfaces we consume.
|
|
37
|
+
* The message contract is minimal (just `{ type: string }`) so the SDK's
|
|
38
|
+
* `SDKMessage` discriminated union IS structurally assignable without any
|
|
39
|
+
* cast at the consumer site (covariant — TS accepts the SDK's typed message
|
|
40
|
+
* as the wider `{ type: string }`). Property access inside `streamAgentRun`
|
|
41
|
+
* narrows via runtime type guards.
|
|
42
|
+
*
|
|
43
|
+
* `import type` from `@theokit/sdk` would couple TheoKit to the SDK at type-
|
|
44
|
+
* resolution time even for consumers who never use the agent surface.
|
|
45
|
+
*/
|
|
46
|
+
interface AgentRunLike {
|
|
47
|
+
stream: () => AsyncIterable<{
|
|
48
|
+
type: string;
|
|
49
|
+
}>;
|
|
50
|
+
wait: () => Promise<AgentRunResult>;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Re-exported as a convenience for test fixtures. Production code typically
|
|
54
|
+
* passes an SDK `Run` directly (structural match via `{ type: string }`).
|
|
55
|
+
*/
|
|
56
|
+
type AgentRunStreamMessage = {
|
|
57
|
+
type: 'assistant';
|
|
58
|
+
message: {
|
|
59
|
+
role: 'assistant';
|
|
60
|
+
content: {
|
|
61
|
+
type: string;
|
|
62
|
+
text?: string;
|
|
63
|
+
}[];
|
|
64
|
+
};
|
|
65
|
+
} | {
|
|
66
|
+
type: 'tool_call';
|
|
67
|
+
name: string;
|
|
68
|
+
status: 'running' | 'completed' | 'error';
|
|
69
|
+
args?: unknown;
|
|
70
|
+
result?: unknown;
|
|
71
|
+
call_id: string;
|
|
72
|
+
} | {
|
|
73
|
+
type: string;
|
|
74
|
+
[k: string]: unknown;
|
|
75
|
+
};
|
|
76
|
+
/** Subset of the SDK `RunResult` we consume. */
|
|
77
|
+
interface AgentRunResult {
|
|
78
|
+
status: 'finished' | 'error' | 'cancelled';
|
|
79
|
+
error?: {
|
|
80
|
+
message: string;
|
|
81
|
+
code?: string;
|
|
82
|
+
cause?: unknown;
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Map an SDK error to the AgentErrorEvent shape. Pure function — easy to test.
|
|
87
|
+
*
|
|
88
|
+
* Backward compat (D4): non-AgentRunError throws yield only `message` field
|
|
89
|
+
* (legacy shape); discriminated fields stay `undefined`.
|
|
90
|
+
*
|
|
91
|
+
* Return type is the specific `AgentErrorEvent` (not the union) for ergonomic
|
|
92
|
+
* call-site access — `errorToEvent(err).code` works without narrowing.
|
|
93
|
+
*/
|
|
94
|
+
declare function errorToEvent(err: unknown, id?: string): AgentErrorEvent;
|
|
95
|
+
declare function streamAgentRun(run: AgentRunLike): AsyncGenerator<AgentEvent, void, unknown>;
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Item #5 — `createConversationHistory`
|
|
99
|
+
*
|
|
100
|
+
* Orchestrator that resolves a stable `agentId` from (explicit → session →
|
|
101
|
+
* cookie → fresh UUID), then returns an `@theokit/sdk` `Agent` via
|
|
102
|
+
* `Agent.getOrCreate(agentId, options)`. Conversation turns auto-persist in
|
|
103
|
+
* `<cwd>/.theokit/agents/<agentId>/messages.jsonl` — SDK owns the storage
|
|
104
|
+
* (ADR D1). `MemorySettings` (facts recall layer) is opt-in passthrough via
|
|
105
|
+
* `options.memory` (ADR D2).
|
|
106
|
+
*
|
|
107
|
+
* Security: agentId from cookie/explicit is attacker-controlled. The SDK
|
|
108
|
+
* uses it as a filesystem path component AND we serialize it into Set-Cookie.
|
|
109
|
+
* EC-1 enforces a strict regex `^[a-zA-Z0-9_-]{1,128}$` at every entry point;
|
|
110
|
+
* invalid values fall through (treated as "missing") rather than throw.
|
|
111
|
+
*/
|
|
112
|
+
/**
|
|
113
|
+
* Minimum surface of an SDK Agent that consumers care about post-creation.
|
|
114
|
+
* Structural match — any object with `send` + `dispose` of compatible
|
|
115
|
+
* shape works. `send` returns a `SdkRunLike` (a Run-shaped object) that
|
|
116
|
+
* `streamAgentRun` can consume. Permissive `unknown` for now; consumers
|
|
117
|
+
* who want stricter types can cast to the SDK's own types.
|
|
118
|
+
*
|
|
119
|
+
* **T5.2 (architecture-cleanup) — DP-7 decision: KEEP (Opt B).** The 5 duck-typed
|
|
120
|
+
* mirrors below were flagged as "over-engineered" by the 2026-05-27 architecture
|
|
121
|
+
* review. Decision: KEEP them because `@theokit/sdk` is `devDependency` (not
|
|
122
|
+
* required at runtime for consumers that don't use agent features). Removing
|
|
123
|
+
* the mirrors would force a hard runtime dep on the SDK, breaking consumers
|
|
124
|
+
* who build TheoKit apps without the agent layer.
|
|
125
|
+
*
|
|
126
|
+
* @kept Defensive duck-type. Do NOT replace with direct SDK type imports unless
|
|
127
|
+
* `@theokit/sdk` is promoted from devDependency to dependency. If promoting,
|
|
128
|
+
* ALSO drop the mirrors (Opt A from the architecture-cleanup plan T5.2).
|
|
129
|
+
*/
|
|
130
|
+
interface SdkRunLike {
|
|
131
|
+
stream: () => AsyncIterable<{
|
|
132
|
+
type: string;
|
|
133
|
+
}>;
|
|
134
|
+
wait: () => Promise<{
|
|
135
|
+
status: 'finished' | 'error' | 'cancelled';
|
|
136
|
+
error?: {
|
|
137
|
+
message: string;
|
|
138
|
+
};
|
|
139
|
+
}>;
|
|
140
|
+
}
|
|
141
|
+
interface SdkAgent {
|
|
142
|
+
send: (message: string, options?: unknown) => Promise<SdkRunLike>;
|
|
143
|
+
dispose: () => Promise<void>;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Phase 2 — structural duck-type of `@theokit/sdk`'s `ConversationStorageAdapter`.
|
|
147
|
+
*
|
|
148
|
+
* D2 (decoupling): we mirror the SDK's shape locally rather than hard-import
|
|
149
|
+
* the SDK type. This lets consumers pass any object matching the structural
|
|
150
|
+
* contract (own implementation, SDK's `FileSystemConversationStorage`,
|
|
151
|
+
* `InMemoryConversationStorage`, or a Postgres/Redis recipe).
|
|
152
|
+
*
|
|
153
|
+
* EC-5 (SHOULD TEST — sync drift detection): the SDK type MUST be assignable
|
|
154
|
+
* to this interface AND vice-versa. A contract test asserts both directions.
|
|
155
|
+
*
|
|
156
|
+
* `unknown` for the message payload avoids coupling to the SDK's `SDKMessage`
|
|
157
|
+
* shape. Real consumers cast at the call site if they need stricter types.
|
|
158
|
+
*/
|
|
159
|
+
interface ConversationStorageLike {
|
|
160
|
+
getMessages(conversationId: string): Promise<readonly unknown[]>;
|
|
161
|
+
appendMessage(conversationId: string, message: unknown): Promise<void>;
|
|
162
|
+
deleteConversation(conversationId: string): Promise<void>;
|
|
163
|
+
listConversationIds?(opts?: {
|
|
164
|
+
limit?: number;
|
|
165
|
+
}): Promise<readonly string[] | undefined>;
|
|
166
|
+
dispose?(): Promise<void>;
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Minimum surface of `AgentOptions` accepted by `Agent.getOrCreate`. Forward-
|
|
170
|
+
* compatible: callers pass whatever the SDK supports (memory, tools, etc.).
|
|
171
|
+
*
|
|
172
|
+
* Phase 2 adds typed `conversationStorage` slot. The index signature still
|
|
173
|
+
* passes everything else opaquely.
|
|
174
|
+
*/
|
|
175
|
+
interface SdkAgentOptions {
|
|
176
|
+
apiKey?: string;
|
|
177
|
+
model?: {
|
|
178
|
+
id: string;
|
|
179
|
+
};
|
|
180
|
+
tools?: readonly unknown[];
|
|
181
|
+
memory?: Record<string, unknown>;
|
|
182
|
+
/**
|
|
183
|
+
* Phase 2 (Production-Readiness #1) — pluggable conversation persistence.
|
|
184
|
+
* Default (when omitted): SDK falls back to `FileSystemConversationStorage`.
|
|
185
|
+
* Required for serverless / multi-host deploys.
|
|
186
|
+
*/
|
|
187
|
+
conversationStorage?: ConversationStorageLike;
|
|
188
|
+
[key: string]: unknown;
|
|
189
|
+
}
|
|
190
|
+
interface ConversationHistoryArgs {
|
|
191
|
+
/** Request — for reading the conversation cookie. */
|
|
192
|
+
request: Request | {
|
|
193
|
+
headers?: {
|
|
194
|
+
cookie?: string;
|
|
195
|
+
} | Headers;
|
|
196
|
+
};
|
|
197
|
+
/**
|
|
198
|
+
* Response-like surface that accepts a `Set-Cookie` header. The primitive
|
|
199
|
+
* appends a Set-Cookie line when issuing a new conversation id. If absent,
|
|
200
|
+
* the primitive still reads the existing cookie but cannot issue a new
|
|
201
|
+
* one — useful for read-only contexts.
|
|
202
|
+
*/
|
|
203
|
+
response?: {
|
|
204
|
+
headers: Headers;
|
|
205
|
+
};
|
|
206
|
+
/** Explicit override — wins over session/cookie/uuid (ADR D3 step 1). */
|
|
207
|
+
agentId?: string;
|
|
208
|
+
/** Auth session containing a `conversationId` field — ADR D3 step 2. */
|
|
209
|
+
session?: {
|
|
210
|
+
conversationId?: string;
|
|
211
|
+
} | null;
|
|
212
|
+
/** SDK AgentOptions forwarded to Agent.getOrCreate. apiKey + model required. */
|
|
213
|
+
options: SdkAgentOptions;
|
|
214
|
+
/** Cookie name override. Default: 'theo_conversation'. */
|
|
215
|
+
cookieName?: string;
|
|
216
|
+
/** Cookie max-age in seconds. Default + min: 30 days. Non-positive coerced to default (EC-4). */
|
|
217
|
+
cookieMaxAge?: number;
|
|
218
|
+
}
|
|
219
|
+
interface ConversationHistoryResult {
|
|
220
|
+
/** The SDK Agent, ready to receive `agent.send(message)`. */
|
|
221
|
+
agent: SdkAgent;
|
|
222
|
+
/** The resolved conversation id (useful for logging / debugging). */
|
|
223
|
+
conversationId: string;
|
|
224
|
+
/** True when the id was newly generated (no prior cookie / session). */
|
|
225
|
+
isNew: boolean;
|
|
226
|
+
}
|
|
227
|
+
declare function createConversationHistory(args: ConversationHistoryArgs): Promise<ConversationHistoryResult>;
|
|
228
|
+
|
|
229
|
+
export { AgentErrorEvent, AgentEvent, type AgentRunLike, type AgentRunResult, type AgentRunStreamMessage, type ConversationHistoryArgs, type ConversationHistoryResult, type ConversationStorageLike, type SdkAgent, type SdkAgentOptions, type SdkRunLike, createConversationHistory, errorToEvent, streamAgentRun };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__resetSdkForTests,
|
|
3
|
+
__setSdkForTests,
|
|
4
|
+
createConversationHistory,
|
|
5
|
+
errorToEvent,
|
|
6
|
+
streamAgentRun
|
|
7
|
+
} from "../../chunk-RESN62GB.js";
|
|
8
|
+
import "../../chunk-DGUM43GV.js";
|
|
9
|
+
export {
|
|
10
|
+
__resetSdkForTests,
|
|
11
|
+
__setSdkForTests,
|
|
12
|
+
createConversationHistory,
|
|
13
|
+
errorToEvent,
|
|
14
|
+
streamAgentRun
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -49,6 +49,51 @@ interface SessionManager<TSession> {
|
|
|
49
49
|
rotateSession(req: IncomingMessage, res: ServerResponse): Promise<TSession | null>;
|
|
50
50
|
}
|
|
51
51
|
declare function createSessionManager<TSession>(config: SessionConfig): SessionManager<TSession>;
|
|
52
|
+
/**
|
|
53
|
+
* T5a.2 Phase D slice 3/3 — Web-Standards session manager.
|
|
54
|
+
*
|
|
55
|
+
* Mirror of `SessionManager<TSession>` for the Web `Request` + `Headers`
|
|
56
|
+
* shape. Same `SessionConfig`, same encryption (`encrypt`/`decrypt` from
|
|
57
|
+
* `./crypto.js`), same dual-key rotation logic (CR-002 constant-time
|
|
58
|
+
* decrypt fallback walk + transparent re-encrypt), same OWASP A07
|
|
59
|
+
* `rotateSession` invariant.
|
|
60
|
+
*
|
|
61
|
+
* **Signature differences vs `SessionManager`:**
|
|
62
|
+
* - Read methods take `Request` (instead of `IncomingMessage`).
|
|
63
|
+
* - Write methods take a `Headers` instance to mutate (instead of
|
|
64
|
+
* `ServerResponse`) — caller passes the headers they're building
|
|
65
|
+
* for their `Response` constructor.
|
|
66
|
+
*
|
|
67
|
+
* Uses `getCookieFromRequest` / `appendCookieToHeaders` /
|
|
68
|
+
* `appendDeleteCookieToHeaders` from Phase B slice 6/6.
|
|
69
|
+
*/
|
|
70
|
+
interface SessionManagerWeb<TSession> {
|
|
71
|
+
getSession(request: Request): Promise<TSession | null>;
|
|
72
|
+
getSessionWithMeta(request: Request): Promise<{
|
|
73
|
+
data: TSession | null;
|
|
74
|
+
meta: SessionMeta;
|
|
75
|
+
}>;
|
|
76
|
+
createSession(target: Headers, data: TSession): Promise<void>;
|
|
77
|
+
destroySession(target: Headers): void;
|
|
78
|
+
rotateSession(request: Request, target: Headers): Promise<TSession | null>;
|
|
79
|
+
}
|
|
80
|
+
declare function createSessionManagerWeb<TSession>(config: SessionConfig): SessionManagerWeb<TSession>;
|
|
81
|
+
/**
|
|
82
|
+
* T5a.2 Phase D slice 3/3 — Web-Standards transparent re-encrypt helper.
|
|
83
|
+
*
|
|
84
|
+
* Mirror of `rotateIfNeeded(sm, req, res)` for the Web Request + Headers
|
|
85
|
+
* shape. Reads session via `getSessionWithMeta`; if the cookie was
|
|
86
|
+
* decrypted with a legacy secret (index > 0), re-issues the cookie with
|
|
87
|
+
* the newest secret via `createSession(target, data)`.
|
|
88
|
+
*
|
|
89
|
+
* **EC-4 honest framing:** unlike the IncomingMessage path where the
|
|
90
|
+
* timing constraint is "before `res.writeHead` fires", the Web Request
|
|
91
|
+
* path's constraint is "before the `Response` object is constructed and
|
|
92
|
+
* returned to the runtime". Caller MUST invoke `rotateIfNeededWeb`
|
|
93
|
+
* BEFORE building the final `Response(body, { headers: target })` so the
|
|
94
|
+
* re-encrypted Set-Cookie lands on the wire.
|
|
95
|
+
*/
|
|
96
|
+
declare function rotateIfNeededWeb<TSession>(sm: SessionManagerWeb<TSession>, request: Request, target: Headers): Promise<TSession | null>;
|
|
52
97
|
/**
|
|
53
98
|
* T3.2 — Transparent re-encrypt helper (EC-4 timing-safe wrapper).
|
|
54
99
|
*
|
|
@@ -371,4 +416,4 @@ declare function clearOidcCache(): void;
|
|
|
371
416
|
*/
|
|
372
417
|
declare function discoverOidcProvider(issuer: string | URL): Promise<OidcMetadata>;
|
|
373
418
|
|
|
374
|
-
export { AuthRequiredError, type BackupCode, type BackupCodeOptions, type OidcMetadata, type PkceChallenge, type SessionConfig, type SessionManager, type SessionMeta, type ThrottleOptions, type ThrottleState, type TotpAlgorithm, type TotpOptions, type TotpUriOptions, type VerifyTotpOptions, _resetKeyCacheForTests, assertProductionSecret, checkThrottle, clearOidcCache, createSessionManager, decrypt, discoverOidcProvider, encrypt, generateBackupCodes, generateNonce, generateOAuthState, generatePkceChallenge, generateTotp, generateTotpSecret, pkceChallengeFromVerifier, recordAttempt, requireAuth, rotateIfNeeded, totpUri, verifyBackupCode, verifyOAuthState, verifyTotp };
|
|
419
|
+
export { AuthRequiredError, type BackupCode, type BackupCodeOptions, type OidcMetadata, type PkceChallenge, type SessionConfig, type SessionManager, type SessionManagerWeb, type SessionMeta, type ThrottleOptions, type ThrottleState, type TotpAlgorithm, type TotpOptions, type TotpUriOptions, type VerifyTotpOptions, _resetKeyCacheForTests, assertProductionSecret, checkThrottle, clearOidcCache, createSessionManager, createSessionManagerWeb, decrypt, discoverOidcProvider, encrypt, generateBackupCodes, generateNonce, generateOAuthState, generatePkceChallenge, generateTotp, generateTotpSecret, pkceChallengeFromVerifier, recordAttempt, requireAuth, rotateIfNeeded, rotateIfNeededWeb, totpUri, verifyBackupCode, verifyOAuthState, verifyTotp };
|
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
checkThrottle,
|
|
5
5
|
clearOidcCache,
|
|
6
6
|
createSessionManager,
|
|
7
|
+
createSessionManagerWeb,
|
|
7
8
|
decrypt,
|
|
8
9
|
discoverOidcProvider,
|
|
9
10
|
encrypt,
|
|
@@ -15,16 +16,20 @@ import {
|
|
|
15
16
|
pkceChallengeFromVerifier,
|
|
16
17
|
recordAttempt,
|
|
17
18
|
rotateIfNeeded,
|
|
19
|
+
rotateIfNeededWeb,
|
|
18
20
|
totpUri,
|
|
19
21
|
verifyBackupCode,
|
|
20
22
|
verifyOAuthState,
|
|
21
23
|
verifyTotp
|
|
22
|
-
} from "../../chunk-
|
|
24
|
+
} from "../../chunk-NZXH2LQQ.js";
|
|
25
|
+
import {
|
|
26
|
+
generateNonce
|
|
27
|
+
} from "../../chunk-C3ZZ56YZ.js";
|
|
28
|
+
import "../../chunk-ZJQ4O76G.js";
|
|
23
29
|
import {
|
|
24
30
|
AuthRequiredError,
|
|
25
|
-
generateNonce,
|
|
26
31
|
requireAuth
|
|
27
|
-
} from "../../chunk-
|
|
32
|
+
} from "../../chunk-4HBI7DHP.js";
|
|
28
33
|
import "../../chunk-DGUM43GV.js";
|
|
29
34
|
export {
|
|
30
35
|
AuthRequiredError,
|
|
@@ -33,6 +38,7 @@ export {
|
|
|
33
38
|
checkThrottle,
|
|
34
39
|
clearOidcCache,
|
|
35
40
|
createSessionManager,
|
|
41
|
+
createSessionManagerWeb,
|
|
36
42
|
decrypt,
|
|
37
43
|
discoverOidcProvider,
|
|
38
44
|
encrypt,
|
|
@@ -46,6 +52,7 @@ export {
|
|
|
46
52
|
recordAttempt,
|
|
47
53
|
requireAuth,
|
|
48
54
|
rotateIfNeeded,
|
|
55
|
+
rotateIfNeededWeb,
|
|
49
56
|
totpUri,
|
|
50
57
|
verifyBackupCode,
|
|
51
58
|
verifyOAuthState,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { d as StorageAdapter } from '../../storage-types-DsDTCPbp.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Cost tracking types (R0.5.11).
|
|
@@ -147,8 +147,6 @@ declare class InMemoryUsageStorage implements UsageStorageAdapter, StorageAdapte
|
|
|
147
147
|
dispose(): Promise<void>;
|
|
148
148
|
record(input: UsageRecord | ToolUsageRecord): Promise<void>;
|
|
149
149
|
getUsage(query: UsageQuery): Promise<UsageResult>;
|
|
150
|
-
/** @internal — test helper to inspect raw record stream */
|
|
151
|
-
__getRecords(): readonly (UsageRecord | ToolUsageRecord)[];
|
|
152
150
|
}
|
|
153
151
|
|
|
154
152
|
interface TrackAgentToolsOptions {
|
|
@@ -13,8 +13,10 @@ import {
|
|
|
13
13
|
translateCronToVercel,
|
|
14
14
|
validateCronSchedule,
|
|
15
15
|
writeCronManifest
|
|
16
|
-
} from "../../chunk-
|
|
17
|
-
import "../../chunk-
|
|
16
|
+
} from "../../chunk-K4M64WD6.js";
|
|
17
|
+
import "../../chunk-Y4H3JNVK.js";
|
|
18
|
+
import "../../chunk-6NEXVBPY.js";
|
|
19
|
+
import "../../chunk-7MQOHNHE.js";
|
|
18
20
|
import "../../chunk-X2VVCJ4V.js";
|
|
19
21
|
import "../../chunk-DGUM43GV.js";
|
|
20
22
|
export {
|
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { A as AgentEvent } from '../../agent-events-B3KNV9ER.js';
|
|
3
|
+
import { b as WebSocketLike } from '../../define-websocket-CdK94O-D.js';
|
|
4
|
+
export { W as WebSocketHandler, a as WebSocketHandlerWeb, d as defineWebSocket, c as defineWebSocketWeb } from '../../define-websocket-CdK94O-D.js';
|
|
5
|
+
import { IncomingMessage } from 'node:http';
|
|
6
|
+
import { T as TheoPlugin } from '../../plugin-types-DNJGxr4Z.js';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* core/contracts/route-config.ts
|
|
10
|
+
*
|
|
11
|
+
* Canonical home for `RouteConfig<TQuery, TBody, TParams, TCtx, TResponse>` —
|
|
12
|
+
* the contract shape consumed by `defineRoute()` (server) and
|
|
13
|
+
* `defineCachedRoute()` (cache).
|
|
14
|
+
*
|
|
15
|
+
* Moved here in T2.2 of architecture-cleanup so `cache → core/contracts`
|
|
16
|
+
* is the legal edge (replacing the prior `cache → server` violation).
|
|
17
|
+
*
|
|
18
|
+
* GAP-4 (plan v1.1): the 5-arity generic shape `<TQuery, TBody, TParams, TCtx, TResponse>`
|
|
19
|
+
* MUST be preserved byte-by-byte. Type tests assert this in
|
|
20
|
+
* `tests/unit/route-config-generic-arity.test.ts`.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
interface RouteConfig<TQuery extends z.ZodType = z.ZodUndefined, TBody extends z.ZodType = z.ZodUndefined, TParams extends z.ZodType = z.ZodUndefined, TCtx = unknown, TResponse = unknown> {
|
|
24
|
+
query?: TQuery;
|
|
25
|
+
body?: TBody;
|
|
26
|
+
params?: TParams;
|
|
27
|
+
status?: number;
|
|
28
|
+
/**
|
|
29
|
+
* Opt out of CSRF enforcement for this route. Use for endpoints that
|
|
30
|
+
* legitimately receive third-party POSTs (Stripe webhooks, GitHub
|
|
31
|
+
* webhooks, OAuth callbacks). Defaults to enforced per `config.security.csrf`.
|
|
32
|
+
*
|
|
33
|
+
* Setting `csrf: false` only disables the per-route check — it does NOT
|
|
34
|
+
* disable the global mode setting for other routes.
|
|
35
|
+
*/
|
|
36
|
+
csrf?: false;
|
|
37
|
+
handler: (ctx: {
|
|
38
|
+
query: z.infer<TQuery>;
|
|
39
|
+
body: z.infer<TBody>;
|
|
40
|
+
params: z.infer<TParams>;
|
|
41
|
+
request: Request;
|
|
42
|
+
ctx: TCtx;
|
|
43
|
+
}) => TResponse | Promise<TResponse>;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Define a typed HTTP route.
|
|
48
|
+
* Identity function — provides type inference for route handlers.
|
|
49
|
+
*/
|
|
50
|
+
declare function defineRoute<TQuery extends z.ZodType = z.ZodUndefined, TBody extends z.ZodType = z.ZodUndefined, TParams extends z.ZodType = z.ZodUndefined, TCtx = unknown, TResponse = unknown>(config: RouteConfig<TQuery, TBody, TParams, TCtx, TResponse>): RouteConfig<TQuery, TBody, TParams, TCtx, TResponse>;
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Action wire-protocol accept mode per plan g3-server-actions-and-useaction
|
|
54
|
+
* v1.2 ADR D1. Default behavior (when omitted) is `'json'`. `'form'` opts the
|
|
55
|
+
* action into FormData multipart parsing for progressive-enhancement forms;
|
|
56
|
+
* the runtime in `server/http/action-execute.ts` will coerce FormData entries
|
|
57
|
+
* against the `input` schema via `formDataToObject` (Astro pattern).
|
|
58
|
+
*/
|
|
59
|
+
type ActionAccept = 'form' | 'json';
|
|
60
|
+
interface ActionConfig<TInput extends z.ZodType, TCtx = unknown> {
|
|
61
|
+
/**
|
|
62
|
+
* Zod input schema. Required: every action declares its input contract via
|
|
63
|
+
* Zod (architecture rule: zod-is-SSOT). The shape becomes the handler's
|
|
64
|
+
* typed `input` parameter via `z.infer<TInput>`.
|
|
65
|
+
*/
|
|
66
|
+
input: TInput;
|
|
67
|
+
/**
|
|
68
|
+
* Wire-protocol accept mode. Defaults to `'json'` when omitted. Setting
|
|
69
|
+
* `'form'` switches the runtime to FormData multipart parsing — the input
|
|
70
|
+
* schema MUST be `z.object(...)` so field-by-field coercion can drive
|
|
71
|
+
* boolean string / number / array coercion (Astro pattern).
|
|
72
|
+
*/
|
|
73
|
+
accept?: ActionAccept;
|
|
74
|
+
handler: (ctx: {
|
|
75
|
+
input: z.infer<TInput>;
|
|
76
|
+
ctx: TCtx;
|
|
77
|
+
}) => unknown;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Define a typed server action.
|
|
81
|
+
*
|
|
82
|
+
* Identity function — provides type inference for action handlers. The
|
|
83
|
+
* runtime that consumes the config (validation + invocation + serialization)
|
|
84
|
+
* lives in `server/http/action-execute.ts`.
|
|
85
|
+
*
|
|
86
|
+
* Per plan g3-server-actions-and-useaction v1.2 § Phase 1 / T1.2: the new
|
|
87
|
+
* `accept?: 'form' | 'json'` field is the only contract change vs the
|
|
88
|
+
* pre-G3 identity. Existing callsites (`defineAction({input, handler})`)
|
|
89
|
+
* continue to compile — `accept` is opt-in.
|
|
90
|
+
*/
|
|
91
|
+
declare function defineAction<TInput extends z.ZodType, TCtx = unknown>(config: ActionConfig<TInput, TCtx>): ActionConfig<TInput, TCtx>;
|
|
92
|
+
|
|
93
|
+
type MiddlewareHandler = (request: Request, next: (request: Request) => Promise<Response>) => Response | Promise<Response>;
|
|
94
|
+
/**
|
|
95
|
+
* Define a middleware handler.
|
|
96
|
+
* Identity function — provides type annotation for middleware.
|
|
97
|
+
*/
|
|
98
|
+
declare function defineMiddleware(handler: MiddlewareHandler): MiddlewareHandler;
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* T5.1 — defineAgentEndpoint
|
|
102
|
+
*
|
|
103
|
+
* Sugar over defineRoute (ADR D4). Accepts an async generator that yields
|
|
104
|
+
* AgentEvents and produces a RouteConfig whose handler returns a Response
|
|
105
|
+
* streaming Server-Sent Events (SSE).
|
|
106
|
+
*
|
|
107
|
+
* Wire format: `data: <JSON>\n\n` per event. Standards-compliant.
|
|
108
|
+
*
|
|
109
|
+
* The generator may throw — the wrapper catches and emits a final
|
|
110
|
+
* `{ type: 'error', message }` event before closing the stream.
|
|
111
|
+
*
|
|
112
|
+
* The wrapper observes `request.signal` (EC-7) — when aborted, the
|
|
113
|
+
* underlying generator is told to `return()` and the stream closes
|
|
114
|
+
* promptly.
|
|
115
|
+
*
|
|
116
|
+
* Note (EC-12, Out of Scope): SSE backpressure (slow consumer) is not
|
|
117
|
+
* handled here. For high-frequency token streaming consider a different
|
|
118
|
+
* transport (WS) or a buffer policy. This MVP enqueues each event
|
|
119
|
+
* immediately.
|
|
120
|
+
*/
|
|
121
|
+
interface AgentEndpointHandlerArgs<TCtx = unknown, TBody = unknown> {
|
|
122
|
+
query: undefined;
|
|
123
|
+
body: TBody;
|
|
124
|
+
params: undefined;
|
|
125
|
+
request: Request;
|
|
126
|
+
ctx: TCtx;
|
|
127
|
+
/**
|
|
128
|
+
* Mutable headers bag that the wrapper merges into the SSE response BEFORE
|
|
129
|
+
* the stream starts. Used by `createConversationHistory` to issue a
|
|
130
|
+
* conversation-id cookie on first request. Append entries via
|
|
131
|
+
* `cookieHeaders.append('set-cookie', '<cookie-string>')`.
|
|
132
|
+
*
|
|
133
|
+
* Cookies appended AFTER the first yield are NOT applied — the response
|
|
134
|
+
* headers commit when the wrapper constructs the Response, before the
|
|
135
|
+
* async generator runs. This is per HTTP semantics, not a wrapper choice.
|
|
136
|
+
*/
|
|
137
|
+
cookieHeaders: Headers;
|
|
138
|
+
/**
|
|
139
|
+
* Phase 3 (Production-Readiness #5) — request abort signal.
|
|
140
|
+
*
|
|
141
|
+
* Fires when the SSE client disconnects (browser closes tab, abort fetch,
|
|
142
|
+
* etc.). Thread this to `agent.send(msg, { signal })` so the SDK cancels
|
|
143
|
+
* the in-flight provider call — STOPS TOKENS FROM CHARGING for output
|
|
144
|
+
* the user will never receive.
|
|
145
|
+
*
|
|
146
|
+
* EC-1 (MUST FIX): the signal is derived via duck-type detection
|
|
147
|
+
* (`'aborted' in r.signal && typeof r.signal.addEventListener === 'function'`)
|
|
148
|
+
* to survive cross-realm scenarios (Node 18 polyfills, undici, Edge
|
|
149
|
+
* runtimes with their own AbortSignal globals). `instanceof AbortSignal`
|
|
150
|
+
* would fail in those cases.
|
|
151
|
+
*/
|
|
152
|
+
signal: AbortSignal;
|
|
153
|
+
}
|
|
154
|
+
interface AgentEndpointConfig<TCtx = unknown, TBody = unknown> {
|
|
155
|
+
handler: (args: AgentEndpointHandlerArgs<TCtx, TBody>) => AsyncGenerator<AgentEvent, void, unknown>;
|
|
156
|
+
}
|
|
157
|
+
declare function defineAgentEndpoint<TBody = unknown, TCtx = unknown>(config: AgentEndpointConfig<TCtx, TBody>): RouteConfig<z.ZodUndefined, z.ZodUndefined, z.ZodUndefined, TCtx, Response>;
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Item #4 — `defineAgentTool`
|
|
161
|
+
*
|
|
162
|
+
* Sugar over the `@theokit/sdk` `CustomTool` contract. Takes a Zod schema +
|
|
163
|
+
* handler and produces a structurally-compatible `CustomTool` that
|
|
164
|
+
* `Agent.create({ tools: [...] })` accepts.
|
|
165
|
+
*
|
|
166
|
+
* Uses Zod v4's native `z.toJSONSchema()` to convert the input schema to
|
|
167
|
+
* JSON Schema for LLM providers.
|
|
168
|
+
*
|
|
169
|
+
* Handler error propagation:
|
|
170
|
+
* `defineAgentTool` parses the input via the Zod schema BEFORE calling the
|
|
171
|
+
* user handler. Invalid input throws a `ZodError`, which the SDK's tool-
|
|
172
|
+
* dispatcher (or the `streamAgentRun` adapter) sees as a tool failure and
|
|
173
|
+
* surfaces as an `error` AgentEvent on the SSE wire (ADR D3).
|
|
174
|
+
*/
|
|
175
|
+
/**
|
|
176
|
+
* Local mirror of the SDK's `CustomTool` interface. We don't `import type`
|
|
177
|
+
* from `@theokit/sdk` because the SDK is an optional peer (consumers who
|
|
178
|
+
* never call `defineAgentTool` shouldn't need it installed). The shape is
|
|
179
|
+
* the wire contract; any structurally-matching object is accepted by
|
|
180
|
+
* `Agent.create({ tools })`.
|
|
181
|
+
*
|
|
182
|
+
* @public
|
|
183
|
+
*/
|
|
184
|
+
interface CustomTool {
|
|
185
|
+
name: string;
|
|
186
|
+
description: string;
|
|
187
|
+
inputSchema: Record<string, unknown>;
|
|
188
|
+
handler: (input: Record<string, unknown>) => string | Promise<string>;
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Spec accepted by {@link defineAgentTool}. `inputSchema` is a Zod 3 schema
|
|
192
|
+
* rooted in `z.object(...)`. The `handler` argument type is inferred via
|
|
193
|
+
* `z.infer<T>`.
|
|
194
|
+
*
|
|
195
|
+
* @public
|
|
196
|
+
*/
|
|
197
|
+
interface DefineAgentToolSpec<T extends z.ZodType> {
|
|
198
|
+
/** Tool name surfaced to the LLM. Must match `^[a-zA-Z][a-zA-Z0-9_-]{0,63}$`. */
|
|
199
|
+
name: string;
|
|
200
|
+
/** Description surfaced to the LLM. Required — drives tool-selection accuracy. */
|
|
201
|
+
description: string;
|
|
202
|
+
/** Zod schema describing the input. Must be `z.object(...)` at the root. */
|
|
203
|
+
inputSchema: T;
|
|
204
|
+
/** Handler invoked with the parsed input. */
|
|
205
|
+
handler: (input: z.infer<T>) => string | Promise<string>;
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Build a {@link CustomTool} from a Zod 3 schema + handler.
|
|
209
|
+
*
|
|
210
|
+
* Behavior:
|
|
211
|
+
* - Validates `name` matches the LLM tool-name regex.
|
|
212
|
+
* - Requires `inputSchema` to be a `ZodObject` (Anthropic + SDK contract).
|
|
213
|
+
* - Warns (not throws) if `description` is empty — empty descriptions
|
|
214
|
+
* degrade LLM tool selection.
|
|
215
|
+
* - Converts the Zod schema to JSON Schema 7 inline (no `$ref`s — LLMs handle
|
|
216
|
+
* inline schemas more reliably).
|
|
217
|
+
* - Strips the top-level `$schema` field (Anthropic rejects schemas with
|
|
218
|
+
* `$schema` at root in some provider modes).
|
|
219
|
+
* - Wraps the handler to parse the input via the Zod schema BEFORE invoking
|
|
220
|
+
* the user code — bad LLM-supplied input throws `ZodError`, which the SDK
|
|
221
|
+
* converts to `tool_result(isError)`.
|
|
222
|
+
*
|
|
223
|
+
* @public
|
|
224
|
+
*/
|
|
225
|
+
declare function defineAgentTool<T extends z.ZodType>(spec: DefineAgentToolSpec<T>): CustomTool;
|
|
226
|
+
|
|
227
|
+
interface ChannelHandler<TMessage = unknown> {
|
|
228
|
+
onSubscribe?: (ws: WebSocketLike, room: string, req: IncomingMessage) => void;
|
|
229
|
+
onMessage?: (ws: WebSocketLike, room: string, data: TMessage) => void;
|
|
230
|
+
onUnsubscribe?: (ws: WebSocketLike, room: string) => void;
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Define a channel handler for WebSocket rooms.
|
|
234
|
+
* Identity function — provides type inference for channel handlers.
|
|
235
|
+
*/
|
|
236
|
+
declare function defineChannel<TMessage = unknown>(handler: ChannelHandler<TMessage>): ChannelHandler<TMessage>;
|
|
237
|
+
/**
|
|
238
|
+
* T5a.2 Phase F slice 2/3 — Web-Standards channel handler.
|
|
239
|
+
*
|
|
240
|
+
* Mirror of `ChannelHandler<TMessage>` for the Web `Request` shape.
|
|
241
|
+
* `onSubscribe` receives `request: Request` instead of `req: IncomingMessage`
|
|
242
|
+
* — the rest of the surface (onMessage, onUnsubscribe) is shape-agnostic
|
|
243
|
+
* (WebSocketLike is already Web-standards-compatible per `define-websocket.ts`).
|
|
244
|
+
*
|
|
245
|
+
* Per `docs/plans/t5a2-incoming-message-to-request-shape-refactor-plan.md`
|
|
246
|
+
* v1.0 § Phase F.
|
|
247
|
+
*
|
|
248
|
+
* **Architectural note:** WebSocket upgrade semantics differ across
|
|
249
|
+
* runtimes:
|
|
250
|
+
* - Node: `WebSocketServer.handleUpgrade(req, socket, head, cb)` —
|
|
251
|
+
* hands you `req: IncomingMessage` at the upgrade handshake.
|
|
252
|
+
* - CF Workers: `new WebSocketPair()` + `request.headers` (the upgrade
|
|
253
|
+
* handshake IS a Web Request) — hands you `request: Request`.
|
|
254
|
+
* - Bun: `server.upgrade(request, { data })` — same Web Request shape.
|
|
255
|
+
* - Deno: `Deno.upgradeWebSocket(request)` — same Web Request shape.
|
|
256
|
+
*
|
|
257
|
+
* Channel handlers targeting CF/Bun/Deno use `WebChannelHandler`; legacy
|
|
258
|
+
* Node consumers stay on `ChannelHandler`. Cross-runtime channels ship
|
|
259
|
+
* both shapes.
|
|
260
|
+
*/
|
|
261
|
+
interface WebChannelHandler<TMessage = unknown> {
|
|
262
|
+
onSubscribe?: (ws: WebSocketLike, room: string, request: Request) => void;
|
|
263
|
+
onMessage?: (ws: WebSocketLike, room: string, data: TMessage) => void;
|
|
264
|
+
onUnsubscribe?: (ws: WebSocketLike, room: string) => void;
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* Web-Standards `defineChannel` sibling. Identity function — provides
|
|
268
|
+
* type inference for Web channel handlers.
|
|
269
|
+
*/
|
|
270
|
+
declare function defineWebChannel<TMessage = unknown>(handler: WebChannelHandler<TMessage>): WebChannelHandler<TMessage>;
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* Identity function for defining a Theo plugin.
|
|
274
|
+
*
|
|
275
|
+
* **Note:** Prefer `definePlugin` (shorter, canonical name per ADR-0008 D6).
|
|
276
|
+
* Both functions are identical — `defineTheoPlugin` is kept as an alias for
|
|
277
|
+
* existing in-tree consumers without forcing a migration sweep.
|
|
278
|
+
*/
|
|
279
|
+
declare function defineTheoPlugin(plugin: TheoPlugin): TheoPlugin;
|
|
280
|
+
|
|
281
|
+
export { type ActionAccept, type ActionConfig, type AgentEndpointConfig, type AgentEndpointHandlerArgs, type ChannelHandler, type CustomTool, type DefineAgentToolSpec, type MiddlewareHandler, type RouteConfig, type WebChannelHandler, WebSocketLike, defineAction, defineAgentEndpoint, defineAgentTool, defineChannel, defineMiddleware, defineRoute, defineTheoPlugin, defineWebChannel };
|