theokit 0.22.1 → 0.23.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.
Files changed (71) hide show
  1. package/dist/actions-virtual-module-Z2IXNF72.js +0 -0
  2. package/dist/add-W6FNTAFS.js +0 -0
  3. package/dist/agent-7IGDT55V.js +0 -0
  4. package/dist/agents-typed-client-RIJVHSX4.js +0 -0
  5. package/dist/app-typed-client-YCQC3MZ7.js +0 -0
  6. package/dist/aws-lambda-7GSCNLPY.js +0 -0
  7. package/dist/body-parser-web-FV5HWCY3.js +0 -0
  8. package/dist/broadcast-LUMOJIJT.js +0 -0
  9. package/dist/build-G7WWVZTL.js +0 -0
  10. package/dist/build-request-body-preview-QMWD2IXK.js +0 -0
  11. package/dist/bun-KP2KES6S.js +0 -0
  12. package/dist/check-PD2FTKMM.js +0 -0
  13. package/dist/chunk-2CVV6CNN.js +0 -0
  14. package/dist/chunk-45C3WUQ7.js +0 -0
  15. package/dist/chunk-5ODOE6EF.js +0 -0
  16. package/dist/chunk-AFVTEAES.js +0 -0
  17. package/dist/chunk-AYZCGJXA.js +0 -0
  18. package/dist/chunk-FOZIR3TG.js +0 -0
  19. package/dist/chunk-FRUEDJFX.js +0 -0
  20. package/dist/chunk-GDN3PXFH.js +0 -0
  21. package/dist/chunk-GEQJAFSV.js +0 -0
  22. package/dist/chunk-GSO77FSM.js +0 -0
  23. package/dist/chunk-HGZL5EOI.js +0 -0
  24. package/dist/chunk-HNBWZKIQ.js +0 -0
  25. package/dist/chunk-IEES3CHD.js +0 -0
  26. package/dist/chunk-JAIKGP3Q.js +0 -0
  27. package/dist/chunk-JITNAZXE.js +0 -0
  28. package/dist/chunk-KXA37ONC.js +0 -0
  29. package/dist/chunk-LGVVX3BV.js +0 -0
  30. package/dist/chunk-M6NMS5LR.js +0 -0
  31. package/dist/chunk-P37RZRFV.js +0 -0
  32. package/dist/chunk-TERFLG67.js +0 -0
  33. package/dist/chunk-WR4F4EEZ.js +0 -0
  34. package/dist/chunk-YJWEADAW.js +0 -0
  35. package/dist/cloudflare-C6E5SPAE.js +0 -0
  36. package/dist/configure-agent-registry-ZOBVU3MV.js +0 -0
  37. package/dist/db-3UNAMSFK.js +0 -0
  38. package/dist/deno-deploy-RFZN56X4.js +0 -0
  39. package/dist/dev-SHAN56K5.js +0 -0
  40. package/dist/dev-emit-EFQRBVYS.js +0 -0
  41. package/dist/dispatcher-EJHL6JMJ.js +0 -0
  42. package/dist/docker-LZZB4D5E.js +0 -0
  43. package/dist/generate-373DALPY.js +0 -0
  44. package/dist/info-2OOXFTJX.js +0 -0
  45. package/dist/internal-api-Y5REPVUS.js +0 -0
  46. package/dist/load-config-3EAQTXPH.js +0 -0
  47. package/dist/mcp-P4MHP3VA.js +0 -0
  48. package/dist/netlify-PMLHVPN4.js +0 -0
  49. package/dist/node-BPJ3Z4DT.js +0 -0
  50. package/dist/openapi-ERYWAT3A.js +0 -0
  51. package/dist/registry-3NB7KOUI.js +0 -0
  52. package/dist/router-TLEAOFID.js +0 -0
  53. package/dist/routes-XNS3UM3B.js +0 -0
  54. package/dist/scan-7MJC6PYU.js +0 -0
  55. package/dist/schema-LYOLNHZ7.js +0 -0
  56. package/dist/server/index.d.ts +67 -3
  57. package/dist/server/index.js +42 -0
  58. package/dist/server/index.js.map +1 -1
  59. package/dist/server-error-to-envelope-UUXDSLAZ.js +0 -0
  60. package/dist/server-routes-hmr-VZXOP5YT.js +0 -0
  61. package/dist/services-json-Y3XODNB5.js +0 -0
  62. package/dist/services-typed-client-32KMTTXR.js +0 -0
  63. package/dist/start-RD5WQMIH.js +0 -0
  64. package/dist/static-MB2CD5Y3.js +0 -0
  65. package/dist/storage-manager-ZSQFLEYT.js +0 -0
  66. package/dist/theo-cloud-DQRP6S6M.js +0 -0
  67. package/dist/upgrade-readiness-ACGW44JC.js +0 -0
  68. package/dist/vercel-J6G7ZHYQ.js +0 -0
  69. package/dist/vite-plugin-A7WGYEMD.js +0 -0
  70. package/package.json +9 -9
  71. package/LICENSE +0 -201
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -28,13 +28,13 @@ export { G as GenericFactory, a as PoolLike, P as PostgresDatabaseConfig, c as R
28
28
  import { VerifyFn } from './webhook/index.js';
29
29
  export { BodyTooLargeError, DEFAULT_MAX_BODY_BYTES, DefineWebhookOptions, RawBodyResult, ReadRawBodyOptions, VerifyResult, WebhookContext, WebhookDefinition, defineWebhook, dispatchWebhook, readRawBody, timingSafeEqual } from './webhook/index.js';
30
30
  import { z } from 'zod';
31
- import { AcpTransport } from '@theokit/agents';
31
+ import { AcpTransport, HumanInTheLoopOptions, HitlDecision, streamAgentUIMessages } from '@theokit/agents';
32
32
  import { CustomTool as CustomTool$1 } from '@theokit/sdk';
33
+ import { UIMessageChunk } from 'ai';
33
34
  import { IncomingMessage } from 'node:http';
34
35
  import { W as WebOnRequestHook, b as WebPreHandlerHook, c as WebOnResponseHook, d as WebOnErrorHook } from '../plugin-types-L49QYMb5.js';
35
36
  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 } from '../plugin-types-L49QYMb5.js';
36
37
  export { a as ServiceDefinition, S as ServicesConfig, b as ServicesConfigInput, c as ServicesConfigOutput } from '../schema-BpH6ivDY.js';
37
- import 'ai';
38
38
  import 'vite';
39
39
 
40
40
  /**
@@ -869,6 +869,70 @@ interface ChannelWebhookConfig {
869
869
  */
870
870
  declare function handleChannelWebhook(request: Request, urlPath: string, config: ChannelWebhookConfig): Promise<Response>;
871
871
 
872
+ /**
873
+ * M35 (multi-surface) — the in-process agent-turn seam (Model A).
874
+ *
875
+ * The FRAMEWORK-owned sibling of the HTTP `mountAgent` and the stdout `runAgentInTerminal`: it runs a
876
+ * compiled agent with the SAME `compileAgentModule` + SAME `streamAgentUIMessages` (G2 — reuses the
877
+ * SDK runtime, reimplements nothing), but returns the raw `UIMessageChunk` generator so ANY consumer
878
+ * drives it directly — the Ink TUI (M35), a Tauri window (M36), or a test — in a SINGLE process with
879
+ * NO HTTP loopback, NO port, and NO CSRF (there is no network boundary to defend).
880
+ *
881
+ * The ONLY difference from the HTTP mount is HITL resolution: the mount pauses the run and resolves
882
+ * the approval via a SECOND HTTP request to `/approve/:id` (the approval registry). In-process there
883
+ * is no second request — the caller resolves the approval INLINE via `awaitApproval` (e.g. the Ink
884
+ * TUI's y/n prompt). The gated-tool map is `compiled.hitl` verbatim, so the pause semantics are
885
+ * byte-identical to the HTTP path; only the resolver differs. Parity with the mount is by
886
+ * construction: both compile the module, resolve function-form skills, and call `streamAgentUIMessages`
887
+ * with the same `{ message, sessionId, hitl }`.
888
+ *
889
+ * Consumers WILL still receive `tool-approval-request` chunks from the returned generator — they are
890
+ * INFORMATIONAL (render them or ignore them). The authoritative human gate is `awaitApproval`, which
891
+ * the SDK awaits BEFORE the gated tool runs; the chunk is not the gate.
892
+ */
893
+
894
+ /** An inline approval request handed to the caller's `awaitApproval` (the Ink/Tauri prompt). */
895
+ interface InProcessApprovalRequest {
896
+ approvalId: string;
897
+ toolName: string;
898
+ opts: HumanInTheLoopOptions;
899
+ }
900
+ /** Resolve one gated-tool approval inline (approve/deny, or a structured {@link HitlDecision}). */
901
+ type InProcessAwaitApproval = (req: InProcessApprovalRequest) => Promise<boolean | HitlDecision>;
902
+ interface StreamAgentTurnInProcessInput {
903
+ message: string;
904
+ /** Resume key; a fresh id per run when omitted. */
905
+ sessionId?: string;
906
+ /**
907
+ * Inline HITL resolver — required IFF the agent has `@HumanInTheLoop`-gated tools. Omitting it for a
908
+ * gated agent is a fail-fast error, never a silent bypass (Rule 8, the #99 lesson).
909
+ */
910
+ awaitApproval?: InProcessAwaitApproval;
911
+ /** Labels a fail-fast `AgentDefinitionError` (the file path). */
912
+ source?: string;
913
+ /** Abort signal forwarded to the SDK stream (client disconnect / window close). */
914
+ signal?: AbortSignal;
915
+ }
916
+ /** Injectable stream fn (defaults to the real SDK bridge) — lets tests drive a deterministic stream. */
917
+ interface StreamAgentTurnDeps {
918
+ stream: typeof streamAgentUIMessages;
919
+ }
920
+ /**
921
+ * Thrown when a gated agent is run in-process without an `awaitApproval` resolver. Refusing loudly is
922
+ * the correct posture: silently running a `@HumanInTheLoop`-gated tool with no human gate is exactly
923
+ * the #99 class of bug. Typed so callers can catch it distinctly.
924
+ */
925
+ declare class InProcessApprovalRequiredError extends Error {
926
+ constructor(toolNames: readonly string[]);
927
+ }
928
+ /**
929
+ * Run a compiled agent in-process and return its `UIMessageChunk` stream. `apiKey` is resolved by the
930
+ * caller (same contract as the HTTP mount). Validation + compile happen SYNCHRONOUSLY (so a gated
931
+ * agent without a resolver throws at call time, not lazily on first iteration); the returned value is
932
+ * the SDK's `streamAgentUIMessages` generator.
933
+ */
934
+ declare function streamAgentTurnInProcess(mod: unknown, apiKey: string, input: StreamAgentTurnInProcessInput, deps?: StreamAgentTurnDeps): AsyncGenerator<UIMessageChunk>;
935
+
872
936
  /**
873
937
  * M30 (ADR-0041) — MCP Apps: `ui://` HTML resources for the MCP server (M16).
874
938
  *
@@ -1317,4 +1381,4 @@ interface LoadEnvResult {
1317
1381
  declare function _resetEnvCache(): void;
1318
1382
  declare function loadEnv(options?: LoadEnvOptions): LoadEnvResult;
1319
1383
 
1320
- 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, CTX_WRITERS, 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, type ContextValue, CustomTool, DEFAULT_EXCLUDED_QUERY_PARAMS, type DefineCachedFunctionOptions, FileTooLargeError, type GetOrComputeOptions, InMemoryCacheAdapter, type InMemoryCacheAdapterOptions, type JobsAugmentedCtx, type KeyDerivationOptions, type LoadEnvOptions, type LoadEnvResult, type McpResourceContents, type McpResourceDescriptor, NodeAcpTransport, type NormalizedCacheConfig, type OpenApiDocsOptions, type ParsedBody, type ProcedureInput, ProcedureInputError, ProcedureOutputError, type QueueClientLike, type RawRouteInput, type RevalidateResult, type RouteCacheOptions, RouteConfig, type RouteInputChannel, type RouteInputSchemas, type RouteInputValidation, type RouteRule, type RouteRules, type Sandbox, type SerializedActionResult, type SerializedResponse, type StdioStreams, THEO_T_PREFIX, type UniversalZodIssue, type UploadedFile, type VendorAgentClient, type VendorAgentToolConfig, VerifyFn, type WorkflowLike, type WorkflowToolConfig, _resetCacheEngine, _resetEnvCache, buildResourceDescriptors, callProcedure, compileRouteRules, createACPTool, createCacheEngine, createCodeMode, createOpenApiHandler, createVendorAgentTool, createWorkflowTool, defineAppResource, defineCachedFunction, defineCachedRoute, deriveKey as deriveCacheKey, deserializeResponse, executeWebRequest, extractAppResources, extractUniversalIssues, getCacheControlHeader, getCacheEngine, handleChannelWebhook, handleMcpStdioLine, initCacheEngine, isActionError, isChannelPath, isInputError, loadEnv, parseChannelPath, parseRequestBody, readAppResource, resolveRouteRule, revalidatePath, revalidateTag, serializeResponse, serveMcpStdio, updateTag, validateExpire as validateCacheExpire, validateMaxAge as validateCacheMaxAge, validateTags as validateCacheTags, validateRouteInput };
1384
+ 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, CTX_WRITERS, 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, type ContextValue, CustomTool, DEFAULT_EXCLUDED_QUERY_PARAMS, type DefineCachedFunctionOptions, FileTooLargeError, type GetOrComputeOptions, InMemoryCacheAdapter, type InMemoryCacheAdapterOptions, type InProcessApprovalRequest, InProcessApprovalRequiredError, type InProcessAwaitApproval, type JobsAugmentedCtx, type KeyDerivationOptions, type LoadEnvOptions, type LoadEnvResult, type McpResourceContents, type McpResourceDescriptor, NodeAcpTransport, type NormalizedCacheConfig, type OpenApiDocsOptions, type ParsedBody, type ProcedureInput, ProcedureInputError, ProcedureOutputError, type QueueClientLike, type RawRouteInput, type RevalidateResult, type RouteCacheOptions, RouteConfig, type RouteInputChannel, type RouteInputSchemas, type RouteInputValidation, type RouteRule, type RouteRules, type Sandbox, type SerializedActionResult, type SerializedResponse, type StdioStreams, type StreamAgentTurnDeps, type StreamAgentTurnInProcessInput, THEO_T_PREFIX, type UniversalZodIssue, type UploadedFile, type VendorAgentClient, type VendorAgentToolConfig, VerifyFn, type WorkflowLike, type WorkflowToolConfig, _resetCacheEngine, _resetEnvCache, buildResourceDescriptors, callProcedure, compileRouteRules, createACPTool, createCacheEngine, createCodeMode, createOpenApiHandler, createVendorAgentTool, createWorkflowTool, defineAppResource, defineCachedFunction, defineCachedRoute, deriveKey as deriveCacheKey, deserializeResponse, executeWebRequest, extractAppResources, extractUniversalIssues, getCacheControlHeader, getCacheEngine, handleChannelWebhook, handleMcpStdioLine, initCacheEngine, isActionError, isChannelPath, isInputError, loadEnv, parseChannelPath, parseRequestBody, readAppResource, resolveRouteRule, revalidatePath, revalidateTag, serializeResponse, serveMcpStdio, streamAgentTurnInProcess, updateTag, validateExpire as validateCacheExpire, validateMaxAge as validateCacheMaxAge, validateTags as validateCacheTags, validateRouteInput };
@@ -1315,6 +1315,46 @@ async function handleChannelWebhook(request, urlPath, config) {
1315
1315
  });
1316
1316
  }
1317
1317
 
1318
+ // src/server/agent/stream-agent-turn-in-process.ts
1319
+ import {
1320
+ compileAgentModule,
1321
+ resolveEnabledSkills,
1322
+ streamAgentUIMessages
1323
+ } from "@theokit/agents";
1324
+ var InProcessApprovalRequiredError = class extends Error {
1325
+ constructor(toolNames) {
1326
+ super(
1327
+ `Agent has HITL-gated tool(s) [${toolNames.join(", ")}] but no \`awaitApproval\` resolver was supplied to streamAgentTurnInProcess. In-process runs must resolve approvals inline \u2014 pass awaitApproval, or remove the gate. Refused (fail-closed).`
1328
+ );
1329
+ this.name = "InProcessApprovalRequiredError";
1330
+ }
1331
+ };
1332
+ function streamAgentTurnInProcess(mod, apiKey, input, deps = { stream: streamAgentUIMessages }) {
1333
+ const compiled = compileAgentModule(mod, input.source);
1334
+ const gated = compiled.hitl;
1335
+ if (gated && gated.size > 0 && !input.awaitApproval) {
1336
+ throw new InProcessApprovalRequiredError([...gated.keys()]);
1337
+ }
1338
+ const resolve2 = input.awaitApproval;
1339
+ const hitl = gated && gated.size > 0 && resolve2 ? {
1340
+ gated,
1341
+ awaitApproval: (approvalId, opts, toolName) => resolve2({ approvalId, toolName, opts })
1342
+ } : void 0;
1343
+ const sessionId = input.sessionId ?? crypto.randomUUID();
1344
+ return (async function* () {
1345
+ if (compiled.skillsResolver) {
1346
+ const enabled = await resolveEnabledSkills(compiled.skillsResolver, compiled.runContext ?? {});
1347
+ if (enabled !== void 0) compiled.skills = { enabled, autoInject: true };
1348
+ }
1349
+ yield* deps.stream(compiled, apiKey, {
1350
+ message: input.message,
1351
+ sessionId,
1352
+ hitl,
1353
+ signal: input.signal
1354
+ });
1355
+ })();
1356
+ }
1357
+
1318
1358
  // src/server/agent/mcp-stdio.ts
1319
1359
  async function handleMcpStdioLine(line, mod, name, appResources = []) {
1320
1360
  const trimmed = line.trim();
@@ -1452,6 +1492,7 @@ export {
1452
1492
  InMemoryJobBackend,
1453
1493
  InMemoryStore,
1454
1494
  InMemoryUsageStorage,
1495
+ InProcessApprovalRequiredError,
1455
1496
  InvalidPluginShapeError,
1456
1497
  JOB_MANIFEST_SCHEMA_VERSION,
1457
1498
  JsonStdoutSink,
@@ -1626,6 +1667,7 @@ export {
1626
1667
  serveStaticFile,
1627
1668
  serverErrorToEnvelope,
1628
1669
  setCookie,
1670
+ streamAgentTurnInProcess,
1629
1671
  superjsonTransformer,
1630
1672
  timingSafeEqual,
1631
1673
  tool,