theokit 0.51.0 → 0.52.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 (68) hide show
  1. package/dist/action-protocol-tGm3NKRg.d.ts +170 -0
  2. package/dist/{actions-virtual-module-FJIFAQUA.js → actions-virtual-module-SNG4JC35.js} +2 -2
  3. package/dist/{actions-virtual-module-D52G2ACL.js → actions-virtual-module-VJYKUIXE.js} +4 -3
  4. package/dist/actions-virtual-module-VJYKUIXE.js.map +1 -0
  5. package/dist/{agent-PLEYEX37.js → agent-AHGYRVQX.js} +2 -2
  6. package/dist/{app-typed-client-MPQDKS35.js → app-typed-client-FQVMEG4Z.js} +2 -2
  7. package/dist/{app-typed-client-XPYFYUPN.js → app-typed-client-ZZIASI4A.js} +4 -3
  8. package/dist/app-typed-client-ZZIASI4A.js.map +1 -0
  9. package/dist/{build-MGNDNTXH.js → build-3AYYQZGQ.js} +2 -2
  10. package/dist/{chunk-DY5W5OWQ.js → chunk-2E7JLV7L.js} +2 -2
  11. package/dist/{chunk-5K7WIT3Z.js → chunk-5BOKW3GX.js} +5 -172
  12. package/dist/chunk-5BOKW3GX.js.map +1 -0
  13. package/dist/{chunk-575RV3CD.js → chunk-E53UIFH6.js} +1 -1
  14. package/dist/chunk-E53UIFH6.js.map +1 -0
  15. package/dist/{chunk-75MWRZDP.js → chunk-I4ELCXNV.js} +7 -7
  16. package/dist/{chunk-MTWZ54OI.js → chunk-MBFD6NHB.js} +7 -7
  17. package/dist/{chunk-YJDWSM4D.js → chunk-PFAVZL4F.js} +2 -2
  18. package/dist/{chunk-IQRL5KZL.js → chunk-VGE6AKEJ.js} +2 -2
  19. package/dist/{chunk-DVYILYM6.js → chunk-YZCD3DWE.js} +2 -2
  20. package/dist/chunk-ZDUO4IYN.js +174 -0
  21. package/dist/chunk-ZDUO4IYN.js.map +1 -0
  22. package/dist/cli/index.js +6 -6
  23. package/dist/client/index.d.ts +117 -1
  24. package/dist/client/index.js +144 -3
  25. package/dist/client/index.js.map +1 -1
  26. package/dist/{dev-2NEKDLEY.js → dev-W7OXHMSP.js} +4 -4
  27. package/dist/{index-B_Pk2JXn.d.ts → index-C8YN9dpF.d.ts} +3 -165
  28. package/dist/index.js +4 -3
  29. package/dist/index.js.map +1 -1
  30. package/dist/{internal-api-OOJT7L6I.js → internal-api-EL25ADPR.js} +2 -2
  31. package/dist/{internal-api-PYWIJTLF.js → internal-api-S6BGJCZP.js} +4 -3
  32. package/dist/{mcp-5AWKPETM.js → mcp-7BXBN7PD.js} +2 -2
  33. package/dist/{preview-D2RKY5ZA.js → preview-4ZTFJG2D.js} +3 -3
  34. package/dist/server/http/index.d.ts +2 -1
  35. package/dist/server/http/index.js +9 -7
  36. package/dist/server/index.d.ts +2 -1
  37. package/dist/server/index.js +9 -7
  38. package/dist/server/index.js.map +1 -1
  39. package/dist/{server-boundary-YIRMIYAS.js → server-boundary-RNM25WWD.js} +2 -2
  40. package/dist/{server-boundary-ITRJTWT4.js → server-boundary-XRXVVUMO.js} +4 -3
  41. package/dist/server-boundary-XRXVVUMO.js.map +1 -0
  42. package/dist/{start-DMOVSFBL.js → start-WILEDDW2.js} +3 -3
  43. package/dist/vite-plugin/index.js +4 -3
  44. package/dist/{vite-plugin-6KDMU3E2.js → vite-plugin-2XM35VNV.js} +4 -4
  45. package/package.json +1 -1
  46. package/dist/actions-virtual-module-D52G2ACL.js.map +0 -1
  47. package/dist/app-typed-client-XPYFYUPN.js.map +0 -1
  48. package/dist/chunk-575RV3CD.js.map +0 -1
  49. package/dist/chunk-5K7WIT3Z.js.map +0 -1
  50. package/dist/server-boundary-ITRJTWT4.js.map +0 -1
  51. /package/dist/{actions-virtual-module-FJIFAQUA.js.map → actions-virtual-module-SNG4JC35.js.map} +0 -0
  52. /package/dist/{agent-PLEYEX37.js.map → agent-AHGYRVQX.js.map} +0 -0
  53. /package/dist/{app-typed-client-MPQDKS35.js.map → app-typed-client-FQVMEG4Z.js.map} +0 -0
  54. /package/dist/{build-MGNDNTXH.js.map → build-3AYYQZGQ.js.map} +0 -0
  55. /package/dist/{chunk-DY5W5OWQ.js.map → chunk-2E7JLV7L.js.map} +0 -0
  56. /package/dist/{chunk-75MWRZDP.js.map → chunk-I4ELCXNV.js.map} +0 -0
  57. /package/dist/{chunk-MTWZ54OI.js.map → chunk-MBFD6NHB.js.map} +0 -0
  58. /package/dist/{chunk-YJDWSM4D.js.map → chunk-PFAVZL4F.js.map} +0 -0
  59. /package/dist/{chunk-IQRL5KZL.js.map → chunk-VGE6AKEJ.js.map} +0 -0
  60. /package/dist/{chunk-DVYILYM6.js.map → chunk-YZCD3DWE.js.map} +0 -0
  61. /package/dist/{dev-2NEKDLEY.js.map → dev-W7OXHMSP.js.map} +0 -0
  62. /package/dist/{internal-api-OOJT7L6I.js.map → internal-api-EL25ADPR.js.map} +0 -0
  63. /package/dist/{internal-api-PYWIJTLF.js.map → internal-api-S6BGJCZP.js.map} +0 -0
  64. /package/dist/{mcp-5AWKPETM.js.map → mcp-7BXBN7PD.js.map} +0 -0
  65. /package/dist/{preview-D2RKY5ZA.js.map → preview-4ZTFJG2D.js.map} +0 -0
  66. /package/dist/{server-boundary-YIRMIYAS.js.map → server-boundary-RNM25WWD.js.map} +0 -0
  67. /package/dist/{start-DMOVSFBL.js.map → start-WILEDDW2.js.map} +0 -0
  68. /package/dist/{vite-plugin-6KDMU3E2.js.map → vite-plugin-2XM35VNV.js.map} +0 -0
@@ -7,7 +7,7 @@ import {
7
7
  } from "./chunk-SSYDEKWF.js";
8
8
  import {
9
9
  dispatchControllerRequest
10
- } from "./chunk-IQRL5KZL.js";
10
+ } from "./chunk-VGE6AKEJ.js";
11
11
  import {
12
12
  broadcastToDevtools
13
13
  } from "./chunk-OIGJOYX6.js";
@@ -53,7 +53,7 @@ import {
53
53
  incomingMessageToHandlerRequest,
54
54
  sendError,
55
55
  writeWebResponseToServerResponse
56
- } from "./chunk-5K7WIT3Z.js";
56
+ } from "./chunk-5BOKW3GX.js";
57
57
  import {
58
58
  findSuggestion
59
59
  } from "./chunk-NTDN54XO.js";
@@ -3476,19 +3476,19 @@ async function theoPluginAsync(rootOrOptions) {
3476
3476
  })
3477
3477
  );
3478
3478
  }
3479
- const { appTypedClientPlugin } = await import("./app-typed-client-XPYFYUPN.js");
3479
+ const { appTypedClientPlugin } = await import("./app-typed-client-ZZIASI4A.js");
3480
3480
  const appClientPlugin = appTypedClientPlugin({
3481
3481
  cwd: projectRoot,
3482
3482
  serverDir: serverDirAbs,
3483
3483
  distDir: resolve10(projectRoot, ".theokit")
3484
3484
  });
3485
- const { actionsVirtualModule } = await import("./actions-virtual-module-D52G2ACL.js");
3485
+ const { actionsVirtualModule } = await import("./actions-virtual-module-VJYKUIXE.js");
3486
3486
  const actionsPlugin = actionsVirtualModule({
3487
3487
  serverDir: serverDirAbs,
3488
3488
  distDir: resolve10(projectRoot, ".theokit")
3489
3489
  });
3490
3490
  const { agentsTypedClientPlugin } = await import("./agents-typed-client-INR2E7B3.js");
3491
- const { generateManifest } = await import("./internal-api-PYWIJTLF.js");
3491
+ const { generateManifest } = await import("./internal-api-S6BGJCZP.js");
3492
3492
  const agentsClientPlugin = agentsTypedClientPlugin({
3493
3493
  projectRoot,
3494
3494
  agentsDir: agentsDirName,
@@ -3505,7 +3505,7 @@ async function theoPluginAsync(rootOrOptions) {
3505
3505
  const controllerTransformPlugin = controllerSwcTransformPlugin({
3506
3506
  serverDir: serverDirAbs
3507
3507
  });
3508
- const { serverOnlyImportBoundary } = await import("./server-boundary-ITRJTWT4.js");
3508
+ const { serverOnlyImportBoundary } = await import("./server-boundary-XRXVVUMO.js");
3509
3509
  const serverBoundaryPlugin = serverOnlyImportBoundary({
3510
3510
  projectRoot,
3511
3511
  serverDir: serverDirAbs
@@ -3688,4 +3688,4 @@ export {
3688
3688
  theoPluginAsync,
3689
3689
  theoPlugin
3690
3690
  };
3691
- //# sourceMappingURL=chunk-75MWRZDP.js.map
3691
+ //# sourceMappingURL=chunk-I4ELCXNV.js.map
@@ -12,7 +12,7 @@ import {
12
12
  serveMatchedAuxRoute,
13
13
  serveThroughPluginLifecycle,
14
14
  setupSsrDevMiddleware
15
- } from "./chunk-DY5W5OWQ.js";
15
+ } from "./chunk-2E7JLV7L.js";
16
16
  import {
17
17
  resolveTheoRootDir
18
18
  } from "./chunk-FDOOBTXJ.js";
@@ -38,7 +38,7 @@ import {
38
38
  mountAgent,
39
39
  readAgentPolicy,
40
40
  writeWebResponseToServerResponse
41
- } from "./chunk-575RV3CD.js";
41
+ } from "./chunk-E53UIFH6.js";
42
42
  import {
43
43
  getApprovalRegistry,
44
44
  resolveProvider
@@ -2179,19 +2179,19 @@ async function theoPluginAsync(rootOrOptions) {
2179
2179
  })
2180
2180
  );
2181
2181
  }
2182
- const { appTypedClientPlugin } = await import("./app-typed-client-MPQDKS35.js");
2182
+ const { appTypedClientPlugin } = await import("./app-typed-client-FQVMEG4Z.js");
2183
2183
  const appClientPlugin = appTypedClientPlugin({
2184
2184
  cwd: projectRoot,
2185
2185
  serverDir: serverDirAbs,
2186
2186
  distDir: resolve5(projectRoot, ".theokit")
2187
2187
  });
2188
- const { actionsVirtualModule } = await import("./actions-virtual-module-FJIFAQUA.js");
2188
+ const { actionsVirtualModule } = await import("./actions-virtual-module-SNG4JC35.js");
2189
2189
  const actionsPlugin = actionsVirtualModule({
2190
2190
  serverDir: serverDirAbs,
2191
2191
  distDir: resolve5(projectRoot, ".theokit")
2192
2192
  });
2193
2193
  const { agentsTypedClientPlugin } = await import("./agents-typed-client-D4OA2TXB.js");
2194
- const { generateManifest } = await import("./internal-api-OOJT7L6I.js");
2194
+ const { generateManifest } = await import("./internal-api-EL25ADPR.js");
2195
2195
  const agentsClientPlugin = agentsTypedClientPlugin({
2196
2196
  projectRoot,
2197
2197
  agentsDir: agentsDirName,
@@ -2208,7 +2208,7 @@ async function theoPluginAsync(rootOrOptions) {
2208
2208
  const controllerTransformPlugin = controllerSwcTransformPlugin({
2209
2209
  serverDir: serverDirAbs
2210
2210
  });
2211
- const { serverOnlyImportBoundary } = await import("./server-boundary-YIRMIYAS.js");
2211
+ const { serverOnlyImportBoundary } = await import("./server-boundary-RNM25WWD.js");
2212
2212
  const serverBoundaryPlugin = serverOnlyImportBoundary({
2213
2213
  projectRoot,
2214
2214
  serverDir: serverDirAbs
@@ -2383,4 +2383,4 @@ export {
2383
2383
  theoPluginAsync,
2384
2384
  theoPlugin
2385
2385
  };
2386
- //# sourceMappingURL=chunk-MTWZ54OI.js.map
2386
+ //# sourceMappingURL=chunk-MBFD6NHB.js.map
@@ -178,7 +178,7 @@ async function agentCommand(name, message, deps = {}) {
178
178
  async function createAgentSsrLoader(projectRoot) {
179
179
  const { createServer } = await import("vite");
180
180
  const react = (await import("@vitejs/plugin-react")).default;
181
- const { theoPluginAsync } = await import("./vite-plugin-6KDMU3E2.js");
181
+ const { theoPluginAsync } = await import("./vite-plugin-2XM35VNV.js");
182
182
  const { loadConfig } = await import("./load-config-4ATXQUN3.js");
183
183
  const config = await loadConfig(projectRoot);
184
184
  const theoPlugins = await theoPluginAsync({
@@ -212,4 +212,4 @@ export {
212
212
  agentCommand,
213
213
  createAgentSsrLoader
214
214
  };
215
- //# sourceMappingURL=chunk-YJDWSM4D.js.map
215
+ //# sourceMappingURL=chunk-PFAVZL4F.js.map
@@ -2,7 +2,7 @@ import {
2
2
  dispatchCsrfWarn,
3
3
  incomingMessageToWebRequest,
4
4
  sendError
5
- } from "./chunk-5K7WIT3Z.js";
5
+ } from "./chunk-5BOKW3GX.js";
6
6
  import {
7
7
  enforceCsrf
8
8
  } from "./chunk-P6OS7652.js";
@@ -108,4 +108,4 @@ export {
108
108
  scanControllerModules,
109
109
  dispatchControllerRequest
110
110
  };
111
- //# sourceMappingURL=chunk-IQRL5KZL.js.map
111
+ //# sourceMappingURL=chunk-VGE6AKEJ.js.map
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  validateRouteInput
3
- } from "./chunk-5K7WIT3Z.js";
3
+ } from "./chunk-5BOKW3GX.js";
4
4
  import {
5
5
  evaluateRoutePolicy,
6
6
  subjectFromContext
@@ -270,4 +270,4 @@ export {
270
270
  callProcedure,
271
271
  createOpenApiHandler
272
272
  };
273
- //# sourceMappingURL=chunk-DVYILYM6.js.map
273
+ //# sourceMappingURL=chunk-YZCD3DWE.js.map
@@ -0,0 +1,174 @@
1
+ // src/core/contracts/action-protocol.ts
2
+ var CODE_TO_STATUS = {
3
+ VALIDATION_ERROR: 422,
4
+ BAD_REQUEST: 400,
5
+ UNAUTHORIZED: 401,
6
+ FORBIDDEN: 403,
7
+ NOT_FOUND: 404,
8
+ METHOD_NOT_ALLOWED: 405,
9
+ CONFLICT: 409,
10
+ CONTENT_TOO_LARGE: 413,
11
+ PAYLOAD_TOO_LARGE: 413,
12
+ UNSUPPORTED_MEDIA_TYPE: 415,
13
+ TOO_MANY_REQUESTS: 429,
14
+ INTERNAL_SERVER_ERROR: 500
15
+ };
16
+ var STATUS_TO_CODE = {
17
+ 400: "BAD_REQUEST",
18
+ 401: "UNAUTHORIZED",
19
+ 403: "FORBIDDEN",
20
+ 404: "NOT_FOUND",
21
+ 405: "METHOD_NOT_ALLOWED",
22
+ 409: "CONFLICT",
23
+ 413: "PAYLOAD_TOO_LARGE",
24
+ 415: "UNSUPPORTED_MEDIA_TYPE",
25
+ 422: "VALIDATION_ERROR",
26
+ 429: "TOO_MANY_REQUESTS",
27
+ 500: "INTERNAL_SERVER_ERROR"
28
+ };
29
+ var ActionError = class _ActionError extends Error {
30
+ // Discriminator widened to the full union so subclasses can narrow to their
31
+ // specific literal (TypeScript would otherwise reject the override). Concrete
32
+ // values are still always exact literals at runtime.
33
+ type = "TheoActionError";
34
+ code;
35
+ status;
36
+ constructor(params) {
37
+ super(params.message ?? params.code);
38
+ this.code = params.code;
39
+ this.status = _ActionError.codeToStatus(params.code);
40
+ if (params.stack) {
41
+ this.stack = params.stack;
42
+ }
43
+ }
44
+ /**
45
+ * G5 T2.4 — canonical envelope view of the action error. Maps the G3
46
+ * ActionErrorCode to a canonical TheoErrorCode (VALIDATION_ERROR ↔
47
+ * UNPROCESSABLE_ENTITY, CONTENT_TOO_LARGE ↔ PAYLOAD_TOO_LARGE) so consumer
48
+ * UI / SDK code can switch on the unified envelope.
49
+ *
50
+ * Subclasses override to populate `ext` (see `ActionInputError.envelope`).
51
+ */
52
+ get envelope() {
53
+ return {
54
+ code: _ActionError.toTheoErrorCode(this.code),
55
+ message: this.message
56
+ };
57
+ }
58
+ /**
59
+ * Translate G3 ActionErrorCode → canonical TheoErrorCode (blueprint
60
+ * Recommendations § "G3 ActionError becomes inaugural envelope user").
61
+ */
62
+ static toTheoErrorCode(code) {
63
+ if (code === "VALIDATION_ERROR") return "UNPROCESSABLE_ENTITY";
64
+ if (code === "CONTENT_TOO_LARGE") return "PAYLOAD_TOO_LARGE";
65
+ return code;
66
+ }
67
+ static codeToStatus(code) {
68
+ return CODE_TO_STATUS[code];
69
+ }
70
+ static statusToCode(status) {
71
+ return STATUS_TO_CODE[status] ?? "INTERNAL_SERVER_ERROR";
72
+ }
73
+ /**
74
+ * Parse a serialized error JSON back into the typed class hierarchy.
75
+ * Distinguishes `TheoActionInputError` (with `issues` array) from
76
+ * `TheoActionError` via the `type` discriminator. Falls back to
77
+ * `INTERNAL_SERVER_ERROR` for malformed bodies (non-object, missing
78
+ * `type`, unknown `code`).
79
+ */
80
+ static fromJson(body) {
81
+ if (typeof body !== "object" || body === null) {
82
+ return new _ActionError({ code: "INTERNAL_SERVER_ERROR" });
83
+ }
84
+ const obj = body;
85
+ if (obj.type === "TheoActionInputError" && Array.isArray(obj.issues)) {
86
+ return new ActionInputError(obj.issues);
87
+ }
88
+ if (obj.type === "TheoActionError" && typeof obj.code === "string" && obj.code in CODE_TO_STATUS) {
89
+ return new _ActionError({
90
+ code: obj.code,
91
+ message: typeof obj.message === "string" ? obj.message : void 0
92
+ });
93
+ }
94
+ return new _ActionError({ code: "INTERNAL_SERVER_ERROR" });
95
+ }
96
+ };
97
+ var ActionInputError = class extends ActionError {
98
+ type = "TheoActionInputError";
99
+ issues;
100
+ fields;
101
+ constructor(rawIssues) {
102
+ super({ code: "VALIDATION_ERROR", message: "Validation failed" });
103
+ this.issues = extractUniversalIssues(rawIssues);
104
+ this.fields = buildFieldsMap(this.issues);
105
+ }
106
+ /**
107
+ * G5 T2.4 — envelope view with ValidationFieldsExt populated from .fields.
108
+ * UI consumers can `switch (env.code)` on `UNPROCESSABLE_ENTITY` and read
109
+ * `(env.ext as ValidationFieldsExt).fields` for field-level rendering.
110
+ */
111
+ get envelope() {
112
+ return {
113
+ code: "UNPROCESSABLE_ENTITY",
114
+ message: this.message,
115
+ ext: { fields: this.fields }
116
+ };
117
+ }
118
+ };
119
+ function buildFieldsMap(issues) {
120
+ const fields = {};
121
+ const seen = /* @__PURE__ */ new Set();
122
+ for (const issue of issues) {
123
+ const key = issue.path.length === 0 ? "" : issue.path.join(".");
124
+ const dedupeKey = `${key}\0${issue.message}`;
125
+ if (seen.has(dedupeKey)) continue;
126
+ seen.add(dedupeKey);
127
+ const bucket = fields[key] ?? [];
128
+ bucket.push(issue.message);
129
+ fields[key] = bucket;
130
+ }
131
+ return fields;
132
+ }
133
+ function extractUniversalIssues(raw) {
134
+ if (!Array.isArray(raw)) return [];
135
+ const out = [];
136
+ for (const entry of raw) {
137
+ if (typeof entry !== "object" || entry === null) continue;
138
+ const obj = entry;
139
+ if (!Array.isArray(obj.path)) continue;
140
+ if (typeof obj.message !== "string") continue;
141
+ const path = [];
142
+ let pathValid = true;
143
+ for (const seg of obj.path) {
144
+ if (typeof seg === "string" || typeof seg === "number") {
145
+ path.push(seg);
146
+ } else {
147
+ pathValid = false;
148
+ break;
149
+ }
150
+ }
151
+ if (!pathValid) continue;
152
+ out.push({
153
+ path,
154
+ message: obj.message,
155
+ code: typeof obj.code === "string" ? obj.code : void 0
156
+ });
157
+ }
158
+ return out;
159
+ }
160
+ function isActionError(value) {
161
+ return value instanceof ActionError;
162
+ }
163
+ function isInputError(value) {
164
+ return value instanceof ActionInputError;
165
+ }
166
+
167
+ export {
168
+ ActionError,
169
+ ActionInputError,
170
+ extractUniversalIssues,
171
+ isActionError,
172
+ isInputError
173
+ };
174
+ //# sourceMappingURL=chunk-ZDUO4IYN.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/core/contracts/action-protocol.ts"],"mappings":";AA8CA,IAAM,iBAAkD;AAAA,EACtD,kBAAkB;AAAA,EAClB,aAAa;AAAA,EACb,cAAc;AAAA,EACd,WAAW;AAAA,EACX,WAAW;AAAA,EACX,oBAAoB;AAAA,EACpB,UAAU;AAAA,EACV,mBAAmB;AAAA,EACnB,mBAAmB;AAAA,EACnB,wBAAwB;AAAA,EACxB,mBAAmB;AAAA,EACnB,uBAAuB;AACzB;AAEA,IAAM,iBAAkD;AAAA,EACtD,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AACP;AAmBO,IAAM,cAAN,MAAM,qBAAoB,MAAM;AAAA;AAAA;AAAA;AAAA,EAI5B,OAAmD;AAAA,EACnD;AAAA,EACA;AAAA,EAET,YAAY,QAAqE;AAC/E,UAAM,OAAO,WAAW,OAAO,IAAI;AACnC,SAAK,OAAO,OAAO;AACnB,SAAK,SAAS,aAAY,aAAa,OAAO,IAAI;AAClD,QAAI,OAAO,OAAO;AAChB,WAAK,QAAQ,OAAO;AAAA,IACtB;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA,IAAI,WAA8B;AAChC,WAAO;AAAA,MACL,MAAM,aAAY,gBAAgB,KAAK,IAAI;AAAA,MAC3C,SAAS,KAAK;AAAA,IAChB;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,OAAO,gBAAgB,MAAsC;AAC3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
15
15
  // src/cli/index.ts
16
16
  var cli = cac("theokit");
17
17
  cli.command("dev", "Start development server").option("--port <port>", "Port number").action(async (options) => {
18
- const { devCommand } = await import("../dev-2NEKDLEY.js");
18
+ const { devCommand } = await import("../dev-W7OXHMSP.js");
19
19
  await devCommand({ port: options.port ? Number(options.port) : void 0 });
20
20
  });
21
21
  cli.command("build", "Build for production").option("--target <target>", "Deploy target (node, vercel, cloudflare)").action(async (options) => {
22
22
  try {
23
- const { buildCommand } = await import("../build-MGNDNTXH.js");
23
+ const { buildCommand } = await import("../build-3AYYQZGQ.js");
24
24
  await buildCommand({ target: options.target });
25
25
  } catch (err) {
26
26
  const msg = err instanceof Error ? err.message : String(err);
@@ -32,7 +32,7 @@ cli.command("build", "Build for production").option("--target <target>", "Deploy
32
32
  });
33
33
  cli.command("start", "Start production server").option("--port <port>", "Port number").action(async (options) => {
34
34
  try {
35
- const { startCommand } = await import("../start-DMOVSFBL.js");
35
+ const { startCommand } = await import("../start-WILEDDW2.js");
36
36
  await startCommand({ port: options.port ? Number(options.port) : void 0 });
37
37
  } catch (err) {
38
38
  const msg = err instanceof Error ? err.message : String(err);
@@ -44,7 +44,7 @@ cli.command("start", "Start production server").option("--port <port>", "Port nu
44
44
  });
45
45
  cli.command("preview", "Build for production, then serve it \u2014 one step (B-030)").option("--port <port>", "Port number").option("--target <target>", "Deploy target (node, vercel, cloudflare)").action(async (options) => {
46
46
  try {
47
- const { previewCommand } = await import("../preview-D2RKY5ZA.js");
47
+ const { previewCommand } = await import("../preview-4ZTFJG2D.js");
48
48
  await previewCommand({
49
49
  port: options.port ? Number(options.port) : void 0,
50
50
  target: options.target
@@ -77,7 +77,7 @@ cli.command(
77
77
  "Run an agent in the terminal (stream + tool calls + approval)"
78
78
  ).action(async (name, message) => {
79
79
  try {
80
- const { agentCommand } = await import("../agent-PLEYEX37.js");
80
+ const { agentCommand } = await import("../agent-AHGYRVQX.js");
81
81
  const { sawError } = await agentCommand(name, message);
82
82
  if (sawError) process.exit(1);
83
83
  } catch (err) {
@@ -108,7 +108,7 @@ cli.command("agent sessions gc", "Collect old transcripts for this project (dry
108
108
  });
109
109
  cli.command("mcp <agent>", "Serve an agent as an MCP server over stdio (for desktop MCP clients)").action(async (agent) => {
110
110
  try {
111
- const { mcpCommand } = await import("../mcp-5AWKPETM.js");
111
+ const { mcpCommand } = await import("../mcp-7BXBN7PD.js");
112
112
  await mcpCommand(agent);
113
113
  } catch (err) {
114
114
  const msg = err instanceof Error ? err.message : String(err);
@@ -2,6 +2,8 @@ import { z } from 'zod';
2
2
  import { T as TheoErrorEnvelope } from '../error-envelope-DG47lt8E.js';
3
3
  export { FetchOptionsLike, Fetcher, QueryKey, UseTheoQueryConfig, buildUseTheoQueryConfig, stableQueryKey } from '../react-query/index.js';
4
4
  export { AgentClient, AgentClientState, AgentHandle, AgentStreamInterruptedError, AgentTransport, ApprovalDecision, ChannelPushSource, ChannelTransport, ChannelTransportOptions, ChannelTurnHandlers, HttpTransport, HttpTransportOptions, InProcessApprovalRequestLike, InProcessAwaitApproval, InProcessRunInput, InProcessRunner, InProcessTransport, InProcessTransportOptions, RequestContext, agentHandle, consumeChunkStream, consumeUIMessageStream, isAgentHandle, responseToChunkStream } from '@theokit/agents/client';
5
+ import { A as ActionError } from '../action-protocol-tGm3NKRg.js';
6
+ export { a as ActionErrorCode, b as ActionInputError, c as ActionResult, i as isActionError, d as isInputError } from '../action-protocol-tGm3NKRg.js';
5
7
  export { PendingApproval, UseAgentOptions, UseAgentReturn, UseAgentStatus, useAgent } from '@theokit/agents/client/react';
6
8
  export { AgentClientHandle, CreateAgentClientOptions, createAgentClient } from './core.js';
7
9
  import * as react from 'react';
@@ -118,6 +120,120 @@ interface Batcher {
118
120
  }
119
121
  declare function createBatcher(options: BatcherOptions): Batcher;
120
122
 
123
+ /**
124
+ * usetheokit/theokit#453 — the framework-agnostic store behind {@link useAction}.
125
+ *
126
+ * `core/contracts/action-protocol.ts` opens by describing itself as the "cross-boundary contract
127
+ * for `defineAction` + `useAction`" and points the client half at `@theokit/react/useAction` — a
128
+ * package outside this repository, with one version, no `repository` field, and a
129
+ * `@theokit/sdk ^1.1.0` peer against a published 4.x. The server half of that contract has always
130
+ * lived here; this is the client half arriving.
131
+ *
132
+ * The state machine lives in a store rather than in the hook, following `useAgent`: it is testable
133
+ * with no DOM, and a non-React surface can subscribe to it directly. The hook in `use-action.ts` is
134
+ * a `useSyncExternalStore` binding over it.
135
+ */
136
+ /**
137
+ * What a generated callable resolves.
138
+ *
139
+ * Deliberately NOT `ActionResult`, whose `error` is an `ActionError` instance: the envelope crosses
140
+ * the wire as JSON, so what arrives is a plain object, and a callable typed against the class would
141
+ * be one no honest implementation can satisfy. `error` is `unknown` here and normalized on the way
142
+ * into the state.
143
+ *
144
+ * Both keys are present — the generated facade always emits both — which is also what tells an
145
+ * envelope apart from a payload that merely has a field named `data` or `error`.
146
+ */
147
+ interface ActionEnvelope<TData = unknown> {
148
+ readonly data: TData | undefined;
149
+ readonly error: unknown;
150
+ }
151
+ /**
152
+ * A callable shaped like the ones `@theo/actions` generates. They resolve an
153
+ * {@link ActionEnvelope} rather than throwing — including for network failure — but a hand-written
154
+ * callable that resolves a bare value or throws is handled too, since consumers pass both.
155
+ */
156
+ type ActionCallable<TInput = unknown, TData = unknown> = (input: TInput) => Promise<ActionEnvelope<TData> | TData>;
157
+ type ActionStatus = 'idle' | 'pending' | 'error' | 'success';
158
+ /** The observable state, one frozen object per transition (`useSyncExternalStore` contract). */
159
+ interface ActionState<TInput = unknown, TData = unknown> {
160
+ readonly status: ActionStatus;
161
+ readonly data: TData | undefined;
162
+ readonly error: ActionError | undefined;
163
+ /** The input of the most recent call — what a retry button replays. */
164
+ readonly variables: TInput | undefined;
165
+ }
166
+ /**
167
+ * Holds `{status, data, error, variables}` for one action callable and notifies subscribers on each
168
+ * transition.
169
+ */
170
+ declare class ActionClient<TInput = unknown, TData = unknown> {
171
+ #private;
172
+ constructor(action: ActionCallable<TInput, TData>);
173
+ /** Subscribe to state changes; returns an unsubscribe fn. */
174
+ subscribe: (listener: () => void) => (() => void);
175
+ /**
176
+ * The current snapshot, stable by reference until the next transition. Allocating here instead
177
+ * would re-render a React consumer forever.
178
+ */
179
+ getSnapshot: () => ActionState<TInput, TData>;
180
+ /** Invoke the action, resolving its data or rejecting with a typed {@link ActionError}. */
181
+ mutateAsync: (input: TInput) => Promise<TData>;
182
+ /**
183
+ * Fire-and-forget: the outcome lands in the state, and the returned promise is consumed here so a
184
+ * failure does not surface as an unhandled rejection in a component that only reads `isError`.
185
+ */
186
+ mutate: (input: TInput) => void;
187
+ /** Back to idle, discarding whatever is in flight. */
188
+ reset: () => void;
189
+ }
190
+
191
+ /**
192
+ * usetheokit/theokit#453 — call a server action from a component and track its state.
193
+ *
194
+ * The framework already generates the typed callable (`@theo/actions`), serves it at
195
+ * `/api/__actions/`, and defines the error hierarchy it answers with. This is the last piece:
196
+ *
197
+ * ```tsx
198
+ * import { actions } from '@theo/actions'
199
+ * import { useAction } from 'theokit/client'
200
+ *
201
+ * function SaveButton() {
202
+ * const save = useAction(actions.saveMemory)
203
+ * return (
204
+ * <button disabled={save.isPending} onClick={() => save.mutate({ content: 'hi' })}>
205
+ * {save.isPending ? 'Saving…' : 'Save'}
206
+ * </button>
207
+ * )
208
+ * }
209
+ * ```
210
+ *
211
+ * A failure lands in `error` as the protocol's own {@link ActionError} — so a validation failure is
212
+ * an `ActionInputError` with its `fields` map intact, which is what a form library binds to.
213
+ *
214
+ * The state machine lives in {@link ActionClient}; this is a `useSyncExternalStore` binding over it,
215
+ * the same shape as `useAgent`.
216
+ */
217
+ interface UseActionResult<TInput = unknown, TData = unknown> {
218
+ /** The data of the most recent successful call. */
219
+ data: TData | undefined;
220
+ /** The typed error of the most recent failed call. */
221
+ error: ActionError | undefined;
222
+ isIdle: boolean;
223
+ isPending: boolean;
224
+ isError: boolean;
225
+ isSuccess: boolean;
226
+ /** The input of the most recent call — what a retry button replays. */
227
+ variables: TInput | undefined;
228
+ /** Fire and forget; read the outcome off `isPending` / `error`. */
229
+ mutate: (input: TInput) => void;
230
+ /** Await the data, or catch the typed {@link ActionError}. */
231
+ mutateAsync: (input: TInput) => Promise<TData>;
232
+ /** Back to idle, discarding whatever is in flight. */
233
+ reset: () => void;
234
+ }
235
+ declare function useAction<TInput = unknown, TData = unknown>(action: ActionCallable<TInput, TData>): UseActionResult<TInput, TData>;
236
+
121
237
  type PrefetchBehavior = 'none' | 'intent' | 'viewport';
122
238
  interface LinkProps extends LinkProps$1 {
123
239
  /** Prefetch strategy. Default: 'intent' (on hover + focus). */
@@ -299,4 +415,4 @@ declare function mountMcpApp(container: HTMLElement, resource: {
299
415
  html: string;
300
416
  }, opts: McpAppHostOptions): McpAppHandle;
301
417
 
302
- export { type BatchRequest, type BatchResponse, type BatchTransport, type Batcher, type BatcherOptions, type CreateAppClientOptions, type GuestMessage, Image, type ImageProps, type InferBody, type InferQuery, type InferResponse, Link, type LinkProps, MCP_APP_SANDBOX, type McpAppHandle, type McpAppHostOptions, Metadata, type MetadataProps, type PrefetchBehavior, TheoFetchError, type TheoFetchOptions, createAppClient, createBatcher, createGuestMessageHandler, mountMcpApp, theoFetch };
418
+ export { type ActionCallable, ActionClient, type ActionEnvelope, ActionError, type ActionState, type ActionStatus, type BatchRequest, type BatchResponse, type BatchTransport, type Batcher, type BatcherOptions, type CreateAppClientOptions, type GuestMessage, Image, type ImageProps, type InferBody, type InferQuery, type InferResponse, Link, type LinkProps, MCP_APP_SANDBOX, type McpAppHandle, type McpAppHostOptions, Metadata, type MetadataProps, type PrefetchBehavior, TheoFetchError, type TheoFetchOptions, type UseActionResult, createAppClient, createBatcher, createGuestMessageHandler, mountMcpApp, theoFetch, useAction };