theokit 0.1.0-alpha.8 → 0.2.1

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 (138) hide show
  1. package/dist/actions-virtual-module-E6PU47GV.js +175 -0
  2. package/dist/actions-virtual-module-E6PU47GV.js.map +1 -0
  3. package/dist/actions-virtual-module-E7IELVHL.js +174 -0
  4. package/dist/actions-virtual-module-E7IELVHL.js.map +1 -0
  5. package/dist/add-2ZFFGGE4.js +0 -0
  6. package/dist/app-typed-client-4L4L4BWD.js +289 -0
  7. package/dist/app-typed-client-4L4L4BWD.js.map +1 -0
  8. package/dist/app-typed-client-6PAT6VOL.js +289 -0
  9. package/dist/app-typed-client-6PAT6VOL.js.map +1 -0
  10. package/dist/aws-lambda-PONVF3UX.js +0 -0
  11. package/dist/broadcast-QOQGUNNK.js +0 -0
  12. package/dist/{build-IQQYCA3B.js → build-EWZDEDT3.js} +37 -11
  13. package/dist/build-EWZDEDT3.js.map +1 -0
  14. package/dist/build-request-body-preview-EOP2Y4F3.js +52 -0
  15. package/dist/build-request-body-preview-EOP2Y4F3.js.map +1 -0
  16. package/dist/build-request-body-preview-II2235E6.js +54 -0
  17. package/dist/build-request-body-preview-II2235E6.js.map +1 -0
  18. package/dist/bun-DITMZMKL.js +0 -0
  19. package/dist/check-PZR67OY5.js +0 -0
  20. package/dist/{chunk-GQSTRXXB.js → chunk-2BQYEBCK.js} +77 -68
  21. package/dist/chunk-2BQYEBCK.js.map +1 -0
  22. package/dist/{chunk-FRBYJANT.js → chunk-4W447H7M.js} +195 -41
  23. package/dist/chunk-4W447H7M.js.map +1 -0
  24. package/dist/chunk-5ODOE6EF.js +0 -0
  25. package/dist/chunk-7DHGV77J.js +140 -0
  26. package/dist/chunk-7DHGV77J.js.map +1 -0
  27. package/dist/{chunk-WQCPKA2L.js → chunk-C27AZN46.js} +570 -165
  28. package/dist/chunk-C27AZN46.js.map +1 -0
  29. package/dist/chunk-ERAZNHHR.js +73 -0
  30. package/dist/chunk-ERAZNHHR.js.map +1 -0
  31. package/dist/chunk-F3TG5FJV.js +97 -0
  32. package/dist/chunk-F3TG5FJV.js.map +1 -0
  33. package/dist/chunk-KJVEJILQ.js +109 -0
  34. package/dist/chunk-KJVEJILQ.js.map +1 -0
  35. package/dist/chunk-KT3MWNZG.js +0 -0
  36. package/dist/{chunk-MCP6Y5BA.js → chunk-M23FP2AS.js} +25 -1
  37. package/dist/chunk-M23FP2AS.js.map +1 -0
  38. package/dist/{chunk-S3JBIFKS.js → chunk-MG7H3LAW.js} +2 -2
  39. package/dist/chunk-MOT42NAH.js +165 -0
  40. package/dist/chunk-MOT42NAH.js.map +1 -0
  41. package/dist/chunk-O7335ZGH.js +0 -0
  42. package/dist/{chunk-OEB3OIYP.js → chunk-OJHO2X7C.js} +497 -168
  43. package/dist/chunk-OJHO2X7C.js.map +1 -0
  44. package/dist/chunk-QLGES2HC.js +189 -0
  45. package/dist/chunk-QLGES2HC.js.map +1 -0
  46. package/dist/{chunk-JZ5WEG3S.js → chunk-SEVYARIU.js} +9 -5
  47. package/dist/chunk-SEVYARIU.js.map +1 -0
  48. package/dist/{chunk-ZK5JCE5J.js → chunk-TFECHXR5.js} +201 -43
  49. package/dist/chunk-TFECHXR5.js.map +1 -0
  50. package/dist/chunk-WSJKACWB.js +17 -0
  51. package/dist/chunk-WSJKACWB.js.map +1 -0
  52. package/dist/chunk-WZ7CPVQB.js +0 -0
  53. package/dist/chunk-XMS5VRIK.js +0 -0
  54. package/dist/chunk-Y5KE6YFP.js +0 -0
  55. package/dist/{chunk-3Q36SEDK.js → chunk-ZBWROIIO.js} +43 -2
  56. package/dist/{chunk-3Q36SEDK.js.map → chunk-ZBWROIIO.js.map} +1 -1
  57. package/dist/chunk-ZOXNJV2O.js +358 -0
  58. package/dist/chunk-ZOXNJV2O.js.map +1 -0
  59. package/dist/cli/index.js +22 -7
  60. package/dist/cli/index.js.map +1 -1
  61. package/dist/client/index.d.ts +31 -1
  62. package/dist/client/index.js +100 -0
  63. package/dist/client/index.js.map +1 -1
  64. package/dist/cloudflare-RBANU3SE.js +0 -0
  65. package/dist/configure-agent-registry-6YGTJYBC.js +0 -0
  66. package/dist/deno-deploy-J7LI6HNL.js +0 -0
  67. package/dist/{dev-VN6WS3CM.js → dev-74KPI5C5.js} +15 -7
  68. package/dist/dev-74KPI5C5.js.map +1 -0
  69. package/dist/dev-emit-3CHM73TV.js +390 -0
  70. package/dist/dev-emit-3CHM73TV.js.map +1 -0
  71. package/dist/dev-emit-I3CKOHML.js +44 -0
  72. package/dist/dev-emit-I3CKOHML.js.map +1 -0
  73. package/dist/devtools/entry.js +653 -243
  74. package/dist/devtools/entry.js.map +1 -1
  75. package/dist/dispatcher-AQJGI3HU.js +8 -0
  76. package/dist/dispatcher-E6QV32BO.js +83 -0
  77. package/dist/dispatcher-E6QV32BO.js.map +1 -0
  78. package/dist/{dist-UZV7J3YI.js → dist-R2Q7GVDW.js} +10412 -11961
  79. package/dist/dist-R2Q7GVDW.js.map +1 -0
  80. package/dist/docker-EZDA5FT7.js +0 -0
  81. package/dist/{generate-SIO4JSKJ.js → generate-DT4IIAHF.js} +88 -22
  82. package/dist/generate-DT4IIAHF.js.map +1 -0
  83. package/dist/index.d.ts +108 -1
  84. package/dist/index.js +5 -2
  85. package/dist/index.js.map +1 -1
  86. package/dist/{info-B3UOXFUF.js → info-VM7EK4JC.js} +3 -3
  87. package/dist/lib-NST3PNZX.js +0 -0
  88. package/dist/netlify-IFY6ZGFV.js +0 -0
  89. package/dist/node-KWZI3CKV.js +0 -0
  90. package/dist/openapi-CBASKC7W.js +84 -0
  91. package/dist/openapi-CBASKC7W.js.map +1 -0
  92. package/dist/proper-lockfile-MVKMQGFK.js +0 -0
  93. package/dist/{registry-BB3UYAOG.js → registry-QGSNLJKJ.js} +2 -2
  94. package/dist/{routes-CAGFZKUK.js → routes-7O4NUDYS.js} +9 -7
  95. package/dist/{routes-CAGFZKUK.js.map → routes-7O4NUDYS.js.map} +1 -1
  96. package/dist/scan-C2BOKLSY.js +0 -0
  97. package/dist/{schema-Cxq2qqwh.d.ts → schema-CjVly9c_.d.ts} +43 -1
  98. package/dist/{schema-MVB2FVK6.js → schema-JAKF23GR.js} +2 -2
  99. package/dist/server/cost/index.d.ts +7 -0
  100. package/dist/server/cost/index.js +1 -1
  101. package/dist/server/index.d.ts +219 -47
  102. package/dist/server/index.js +101 -114
  103. package/dist/server/index.js.map +1 -1
  104. package/dist/services-typed-client-ZX5JUHH3.js +0 -0
  105. package/dist/sqlite-vec-54KB4RD3.js +0 -0
  106. package/dist/{start-CSLJQXV3.js → start-5JTFWF4T.js} +20 -14
  107. package/dist/start-5JTFWF4T.js.map +1 -0
  108. package/dist/{static-BH6JQNM2.js → static-6PZZBY7G.js} +4 -4
  109. package/dist/storage-manager-D5KBXXKB.js +0 -0
  110. package/dist/theo-cloud-3K4DGB3S.js +0 -0
  111. package/dist/{upgrade-readiness-OHL36FQL.js → upgrade-readiness-Q46KTG2J.js} +6 -1
  112. package/dist/upgrade-readiness-Q46KTG2J.js.map +1 -0
  113. package/dist/vercel-RHADE5IP.js +0 -0
  114. package/dist/vite-plugin/index.d.ts +25 -1
  115. package/dist/vite-plugin/index.js +5 -2
  116. package/dist/{vite-plugin-WA3G45YY.js → vite-plugin-3EQP2JYM.js} +7 -6
  117. package/dist/vite-plugin-3EQP2JYM.js.map +1 -0
  118. package/package.json +10 -8
  119. package/LICENSE +0 -201
  120. package/dist/build-IQQYCA3B.js.map +0 -1
  121. package/dist/chunk-FRBYJANT.js.map +0 -1
  122. package/dist/chunk-GQSTRXXB.js.map +0 -1
  123. package/dist/chunk-JZ5WEG3S.js.map +0 -1
  124. package/dist/chunk-MCP6Y5BA.js.map +0 -1
  125. package/dist/chunk-OEB3OIYP.js.map +0 -1
  126. package/dist/chunk-WQCPKA2L.js.map +0 -1
  127. package/dist/chunk-ZK5JCE5J.js.map +0 -1
  128. package/dist/dev-VN6WS3CM.js.map +0 -1
  129. package/dist/dist-UZV7J3YI.js.map +0 -1
  130. package/dist/generate-SIO4JSKJ.js.map +0 -1
  131. package/dist/start-CSLJQXV3.js.map +0 -1
  132. package/dist/upgrade-readiness-OHL36FQL.js.map +0 -1
  133. /package/dist/{chunk-S3JBIFKS.js.map → chunk-MG7H3LAW.js.map} +0 -0
  134. /package/dist/{schema-MVB2FVK6.js.map → dispatcher-AQJGI3HU.js.map} +0 -0
  135. /package/dist/{info-B3UOXFUF.js.map → info-VM7EK4JC.js.map} +0 -0
  136. /package/dist/{registry-BB3UYAOG.js.map → registry-QGSNLJKJ.js.map} +0 -0
  137. /package/dist/{vite-plugin-WA3G45YY.js.map → schema-JAKF23GR.js.map} +0 -0
  138. /package/dist/{static-BH6JQNM2.js.map → static-6PZZBY7G.js.map} +0 -0
@@ -1,3 +1,8 @@
1
+ import {
2
+ generateManifest,
3
+ loadManifest,
4
+ writeManifest
5
+ } from "../chunk-ERAZNHHR.js";
1
6
  import {
2
7
  _resetKeyCacheForTests,
3
8
  assertProductionSecret,
@@ -28,7 +33,7 @@ import {
28
33
  InMemoryUsageStorage,
29
34
  trackAgentRun,
30
35
  trackAgentTools
31
- } from "../chunk-MCP6Y5BA.js";
36
+ } from "../chunk-M23FP2AS.js";
32
37
  import {
33
38
  CRON_MANIFEST_SCHEMA_VERSION,
34
39
  DuplicateCronNameError,
@@ -62,6 +67,8 @@ import {
62
67
  generateNewTraceContext
63
68
  } from "../chunk-YLBSSEHX.js";
64
69
  import {
70
+ ActionError,
71
+ ActionInputError,
65
72
  BATCH_PATH,
66
73
  BatchPathConflictError,
67
74
  CSP_REPORT_PATH,
@@ -69,6 +76,7 @@ import {
69
76
  CSRF_READINESS_RESET_PATH,
70
77
  CSRF_WARN_CODE,
71
78
  CSRF_WARN_DOCS_URL,
79
+ CsrfReadinessStore,
72
80
  DEFAULT_CSP,
73
81
  DEFAULT_PERMISSIONS_POLICY,
74
82
  DuplicateDecorationError,
@@ -86,7 +94,6 @@ import {
86
94
  _resetWarnOnceForTests,
87
95
  applySecurityHeaders,
88
96
  buildSecurityHeaders,
89
- compilePattern,
90
97
  createCorsHandler,
91
98
  createLogger,
92
99
  createNoOpLogger,
@@ -98,16 +105,18 @@ import {
98
105
  executeAction,
99
106
  executeRoute,
100
107
  extractTraceId,
108
+ extractUniversalIssues,
101
109
  findSuggestion,
102
110
  handleBatchRequest,
103
111
  handleCspReport,
104
112
  handleCsrfReadiness,
113
+ isActionError,
114
+ isInputError,
105
115
  jsonTransformer,
106
116
  levenshtein,
107
117
  loadEnv,
108
118
  logRequest,
109
119
  matchDisallowed,
110
- matchRoute,
111
120
  matchesOrigin,
112
121
  normalizeLegacy,
113
122
  normalizeNew,
@@ -117,15 +126,23 @@ import {
117
126
  runMiddlewareAndContext,
118
127
  safeAudit,
119
128
  scanMiddlewares,
120
- scanServerActions,
121
- scanServerRoutes,
122
- scanWebSocketRoutes,
123
129
  sendError,
124
130
  sendJson,
125
131
  superjsonTransformer,
126
132
  validateCsrf,
127
133
  warnOnce
128
- } from "../chunk-OEB3OIYP.js";
134
+ } from "../chunk-OJHO2X7C.js";
135
+ import {
136
+ compilePattern,
137
+ matchRoute,
138
+ scanServerRoutes,
139
+ scanWebSocketRoutes
140
+ } from "../chunk-2BQYEBCK.js";
141
+ import {
142
+ ActionScanError,
143
+ scanServerActions,
144
+ scanServerActionsEnriched
145
+ } from "../chunk-7DHGV77J.js";
129
146
  import {
130
147
  AuthRequiredError,
131
148
  generateNonce,
@@ -138,6 +155,7 @@ import {
138
155
  createQueueClient
139
156
  } from "../chunk-GY5Q27BJ.js";
140
157
  import "../chunk-X2VVCJ4V.js";
158
+ import "../chunk-WSJKACWB.js";
141
159
  import {
142
160
  __require
143
161
  } from "../chunk-DGUM43GV.js";
@@ -399,62 +417,6 @@ function serveStaticFile(req, res, clientDir) {
399
417
  return true;
400
418
  }
401
419
 
402
- // src/server/scan/manifest.ts
403
- import { existsSync as existsSync3, readFileSync as readFileSync3, writeFileSync, mkdirSync } from "fs";
404
- import { join, resolve as resolve3, relative } from "path";
405
- function generateManifest(serverDir) {
406
- const routes = scanServerRoutes(serverDir);
407
- const actions = scanServerActions(serverDir);
408
- const websockets = scanWebSocketRoutes(serverDir);
409
- return {
410
- version: 1,
411
- generatedAt: (/* @__PURE__ */ new Date()).toISOString(),
412
- routes: routes.map((r) => ({
413
- filePath: relative(serverDir, r.filePath),
414
- routePath: r.routePath,
415
- paramNames: r.paramNames
416
- })),
417
- actions: actions.map((a) => ({
418
- filePath: relative(serverDir, a.filePath),
419
- actionPath: a.actionPath
420
- })),
421
- websockets: websockets.map((w) => ({
422
- filePath: relative(serverDir, w.filePath),
423
- wsPath: w.wsPath
424
- }))
425
- };
426
- }
427
- function writeManifest(manifest, outputDir) {
428
- mkdirSync(outputDir, { recursive: true });
429
- const manifestPath = join(outputDir, "manifest.json");
430
- writeFileSync(manifestPath, JSON.stringify(manifest, null, 2));
431
- }
432
- function loadManifest(distDir, serverDir) {
433
- const manifestPath = join(distDir, "manifest.json");
434
- if (!existsSync3(manifestPath)) {
435
- throw new Error(`No manifest found at ${manifestPath}. Run "theo build" first.`);
436
- }
437
- const raw = JSON.parse(readFileSync3(manifestPath, "utf-8"));
438
- const routes = raw.routes.map((r) => {
439
- const { pattern, paramNames } = compilePattern(r.routePath);
440
- return {
441
- filePath: resolve3(serverDir, r.filePath),
442
- routePath: r.routePath,
443
- paramNames,
444
- pattern
445
- };
446
- });
447
- const actions = raw.actions.map((a) => ({
448
- filePath: resolve3(serverDir, a.filePath),
449
- actionPath: a.actionPath
450
- }));
451
- const websockets = raw.websockets.map((w) => ({
452
- filePath: resolve3(serverDir, w.filePath),
453
- wsPath: w.wsPath
454
- }));
455
- return { routes, actions, websockets };
456
- }
457
-
458
420
  // src/server/agent/stream-agent-run.ts
459
421
  function safeJsonStringify(value) {
460
422
  try {
@@ -551,6 +513,53 @@ async function* streamAgentRun(run) {
551
513
  }
552
514
  }
553
515
 
516
+ // src/server/agent/provider-resolver.ts
517
+ var DEFAULT_REGISTRY = [
518
+ {
519
+ name: "openrouter",
520
+ envKey: "OPENROUTER_API_KEY",
521
+ baseUrl: "https://openrouter.ai/api/v1",
522
+ priority: 1
523
+ },
524
+ {
525
+ name: "openai",
526
+ envKey: "OPENAI_API_KEY",
527
+ baseUrl: "https://api.openai.com/v1",
528
+ priority: 2
529
+ },
530
+ {
531
+ name: "anthropic",
532
+ envKey: "ANTHROPIC_API_KEY",
533
+ baseUrl: "https://api.anthropic.com",
534
+ priority: 3
535
+ }
536
+ ];
537
+ var registry = [...DEFAULT_REGISTRY];
538
+ function resolveProvider() {
539
+ const sorted = [...registry].sort((a, b) => a.priority - b.priority);
540
+ for (const desc of sorted) {
541
+ const apiKey = process.env[desc.envKey];
542
+ if (apiKey && apiKey.length > 0) {
543
+ return {
544
+ name: desc.name,
545
+ apiKey,
546
+ baseUrl: desc.baseUrl
547
+ };
548
+ }
549
+ }
550
+ const envKeys = sorted.map((p) => p.envKey).join(" OR ");
551
+ throw new Error(
552
+ `No LLM provider API key found in environment. Set one of: ${envKeys}. Get a free OpenRouter key at https://openrouter.ai/keys (recommended \u2014 one key, many models).`
553
+ );
554
+ }
555
+ function tryResolveProvider() {
556
+ try {
557
+ return resolveProvider();
558
+ } catch {
559
+ return null;
560
+ }
561
+ }
562
+
554
563
  // src/server/agent/create-conversation-history.ts
555
564
  var sdkOverride = void 0;
556
565
  function __setSdkForTests(sdk) {
@@ -645,10 +654,29 @@ async function createConversationHistory(args) {
645
654
  });
646
655
  args.response.headers.append("set-cookie", cookie);
647
656
  }
657
+ const resolvedOptions = autoResolveProviderIfNeeded(args.options);
648
658
  const sdk = await loadSdk();
649
- const agent = await sdk.Agent.getOrCreate(conversationId, args.options);
659
+ const agent = await sdk.Agent.getOrCreate(conversationId, resolvedOptions);
650
660
  return { agent, conversationId, isNew };
651
661
  }
662
+ function autoResolveProviderIfNeeded(options) {
663
+ if (typeof options.apiKey === "string" && options.apiKey.length > 0) {
664
+ return options;
665
+ }
666
+ const resolved = tryResolveProvider();
667
+ if (resolved === null) {
668
+ throw new Error(
669
+ "No LLM provider API key found in environment. Set OPENROUTER_API_KEY (recommended \u2014 gateway to many models) OR OPENAI_API_KEY OR ANTHROPIC_API_KEY in your .env. Get a free OpenRouter key at https://openrouter.ai/keys. (Pass `options.apiKey` explicitly to bypass auto-resolution.)"
670
+ );
671
+ }
672
+ return {
673
+ ...options,
674
+ apiKey: resolved.apiKey,
675
+ providers: {
676
+ routes: [{ capability: "chat", provider: resolved.name, baseUrl: resolved.baseUrl }]
677
+ }
678
+ };
679
+ }
652
680
 
653
681
  // src/server/rate-limit/rate-limit-per-route.ts
654
682
  import { createHash } from "crypto";
@@ -803,54 +831,6 @@ var ChannelManager = class {
803
831
  }
804
832
  };
805
833
 
806
- // src/server/security/csrf-readiness-store.ts
807
- var CsrfReadinessStore = class _CsrfReadinessStore {
808
- static MAX_ENTRIES = 1e3;
809
- entries = /* @__PURE__ */ new Map();
810
- keyFor(event) {
811
- return `${event.method}\0${event.path}\0${event.reason}`;
812
- }
813
- record(event) {
814
- const key = this.keyFor(event);
815
- const now = (/* @__PURE__ */ new Date()).toISOString();
816
- const existing = this.entries.get(key);
817
- if (existing) {
818
- existing.count++;
819
- existing.lastSeen = now;
820
- return;
821
- }
822
- if (this.entries.size >= _CsrfReadinessStore.MAX_ENTRIES) {
823
- const firstKey = this.entries.keys().next().value;
824
- if (firstKey !== void 0) this.entries.delete(firstKey);
825
- }
826
- this.entries.set(key, { count: 1, firstSeen: now, lastSeen: now });
827
- }
828
- summary() {
829
- let total = 0;
830
- const routes = [];
831
- for (const [key, entry] of this.entries) {
832
- const [method, path, reason] = key.split("\0");
833
- routes.push({
834
- method,
835
- path,
836
- reason,
837
- count: entry.count,
838
- firstSeen: entry.firstSeen,
839
- lastSeen: entry.lastSeen
840
- });
841
- total += entry.count;
842
- }
843
- return {
844
- generatedAt: (/* @__PURE__ */ new Date()).toISOString(),
845
- totalEvents: total,
846
- routes
847
- };
848
- }
849
- reset() {
850
- this.entries.clear();
851
- }
852
- };
853
-
854
834
  // src/server/storage/storage-manager.ts
855
835
  var StorageManager = class {
856
836
  #config;
@@ -1621,8 +1601,8 @@ function createCacheEngine(opts) {
1621
1601
  function claimAndRun(key, fn, options, skipWrite) {
1622
1602
  let resolveOuter;
1623
1603
  let rejectOuter;
1624
- const outerPromise = new Promise((resolve4, reject) => {
1625
- resolveOuter = resolve4;
1604
+ const outerPromise = new Promise((resolve3, reject) => {
1605
+ resolveOuter = resolve3;
1626
1606
  rejectOuter = reject;
1627
1607
  });
1628
1608
  void outerPromise.catch(() => {
@@ -1965,6 +1945,9 @@ function definePlugin(plugin) {
1965
1945
  return plugin;
1966
1946
  }
1967
1947
  export {
1948
+ ActionError,
1949
+ ActionInputError,
1950
+ ActionScanError,
1968
1951
  AuthRequiredError,
1969
1952
  BATCH_PATH,
1970
1953
  BatchPathConflictError,
@@ -2070,6 +2053,7 @@ export {
2070
2053
  executeAction,
2071
2054
  executeRoute,
2072
2055
  extractTraceId,
2056
+ extractUniversalIssues,
2073
2057
  findSuggestion,
2074
2058
  generateBackupCodes,
2075
2059
  generateManifest,
@@ -2086,6 +2070,8 @@ export {
2086
2070
  handleCspReport,
2087
2071
  handleCsrfReadiness,
2088
2072
  initCacheEngine,
2073
+ isActionError,
2074
+ isInputError,
2089
2075
  jsonTransformer,
2090
2076
  levenshtein,
2091
2077
  loadCustomErrorPages,
@@ -2116,6 +2102,7 @@ export {
2116
2102
  scanJobs,
2117
2103
  scanMiddlewares,
2118
2104
  scanServerActions,
2105
+ scanServerActionsEnriched,
2119
2106
  scanServerRoutes,
2120
2107
  scanWebSocketRoutes,
2121
2108
  sendError,