@execbox/core 0.4.1 → 0.5.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 (60) hide show
  1. package/README.md +5 -0
  2. package/dist/errors-B9ADBuDH.d.cts +29 -0
  3. package/dist/errors-B9ADBuDH.d.cts.map +1 -0
  4. package/dist/errors-DlbJQYs7.d.ts +29 -0
  5. package/dist/errors-DlbJQYs7.d.ts.map +1 -0
  6. package/dist/{errors-BXpyBhCI.js → errors-wS8yjQhS.js} +1 -1
  7. package/dist/{errors-BXpyBhCI.js.map → errors-wS8yjQhS.js.map} +1 -1
  8. package/dist/{errors-BGSgVV40.cjs → errors-xD8r6fCf.cjs} +1 -1
  9. package/dist/{errors-BGSgVV40.cjs.map → errors-xD8r6fCf.cjs.map} +1 -1
  10. package/dist/{executor-_CO7E1U7.d.ts → executor-B7q7K_27.d.ts} +2 -2
  11. package/dist/{executor-_CO7E1U7.d.ts.map → executor-B7q7K_27.d.ts.map} +1 -1
  12. package/dist/{executor-CEXp0gYP.d.cts → executor-BsE5nF-j.d.cts} +1 -1
  13. package/dist/{executor-CEXp0gYP.d.cts.map → executor-BsE5nF-j.d.cts.map} +1 -1
  14. package/dist/index.cjs +3 -16
  15. package/dist/index.d.cts +4 -4
  16. package/dist/index.d.ts +4 -4
  17. package/dist/index.js +3 -5
  18. package/dist/mcp/index.cjs +2 -2
  19. package/dist/mcp/index.d.cts +1 -1
  20. package/dist/mcp/index.d.cts.map +1 -1
  21. package/dist/mcp/index.d.ts +2 -2
  22. package/dist/mcp/index.js +2 -2
  23. package/dist/protocol/index.cjs +2 -2
  24. package/dist/protocol/index.d.ts +1 -1
  25. package/dist/protocol/index.js +2 -2
  26. package/dist/{resolveProvider-DfcSnwnp.cjs → resolveProvider-BZYSw8Qk.cjs} +2 -2
  27. package/dist/{resolveProvider-DfcSnwnp.cjs.map → resolveProvider-BZYSw8Qk.cjs.map} +1 -1
  28. package/dist/{resolveProvider-BHuwOGBm.js → resolveProvider-UqQxdF4j.js} +2 -2
  29. package/dist/{resolveProvider-BHuwOGBm.js.map → resolveProvider-UqQxdF4j.js.map} +1 -1
  30. package/dist/{runner-nUCF59Au.js → runner-6GMM-5ur.js} +2 -2
  31. package/dist/{runner-nUCF59Au.js.map → runner-6GMM-5ur.js.map} +1 -1
  32. package/dist/{runner-FSGSGEpx.d.ts → runner-ClFrFnz9.d.ts} +1 -1
  33. package/dist/{runner-FSGSGEpx.d.ts.map → runner-ClFrFnz9.d.ts.map} +1 -1
  34. package/dist/{runner-BxbJ5eWb.cjs → runner-CsrfDub-.cjs} +2 -2
  35. package/dist/{runner-BxbJ5eWb.cjs.map → runner-CsrfDub-.cjs.map} +1 -1
  36. package/dist/runtime.cjs +90 -0
  37. package/dist/runtime.cjs.map +1 -0
  38. package/dist/runtime.d.cts +65 -0
  39. package/dist/runtime.d.cts.map +1 -0
  40. package/dist/runtime.d.ts +65 -0
  41. package/dist/runtime.d.ts.map +1 -0
  42. package/dist/runtime.js +74 -0
  43. package/dist/runtime.js.map +1 -0
  44. package/package.json +7 -7
  45. package/dist/_internal/index.cjs +0 -45
  46. package/dist/_internal/index.cjs.map +0 -1
  47. package/dist/_internal/index.d.cts +0 -21
  48. package/dist/_internal/index.d.cts.map +0 -1
  49. package/dist/_internal/index.d.ts +0 -22
  50. package/dist/_internal/index.d.ts.map +0 -1
  51. package/dist/_internal/index.js +0 -30
  52. package/dist/_internal/index.js.map +0 -1
  53. package/dist/errors-B3IY3ID-.d.cts +0 -69
  54. package/dist/errors-B3IY3ID-.d.cts.map +0 -1
  55. package/dist/errors-BbUru7ko.d.ts +0 -69
  56. package/dist/errors-BbUru7ko.d.ts.map +0 -1
  57. package/dist/normalize-B80ZCnxe.cjs +0 -54
  58. package/dist/normalize-B80ZCnxe.cjs.map +0 -1
  59. package/dist/normalize-dfQC7HWx.js +0 -48
  60. package/dist/normalize-dfQC7HWx.js.map +0 -1
package/README.md CHANGED
@@ -32,6 +32,11 @@ npm install @execbox/core @execbox/quickjs
32
32
 
33
33
  Swap in `@execbox/remote` or `@execbox/isolated-vm` when you need a different runtime boundary.
34
34
 
35
+ ## Runtime Implementer Surface
36
+
37
+ Application code should usually import from `@execbox/core`, `@execbox/core/mcp`, or `@execbox/core/protocol`.
38
+ Executor and runner packages should import shared runtime helpers from `@execbox/core/runtime` instead. That subpath contains the manifest dispatcher, runtime option defaults, timeout helpers, log formatting, code normalization, and error normalization used to keep runtime implementations aligned.
39
+
35
40
  ## Smallest Working Usage
36
41
 
37
42
  ```ts
@@ -0,0 +1,29 @@
1
+ /**
2
+ * @packageDocumentation
3
+ * Public TypeScript declarations for this package entrypoint.
4
+ */
5
+ import { u as ExecuteErrorCode } from "./runner-DSgvu6Ad.cjs";
6
+
7
+ //#region src/errors.d.ts
8
+
9
+ /**
10
+ * Structured failure used internally to propagate executor and tool errors.
11
+ */
12
+ declare class ExecuteFailure extends Error {
13
+ code: ExecuteErrorCode;
14
+ /**
15
+ * Creates a structured failure with a trusted executor or tool error code.
16
+ */
17
+ constructor(code: ExecuteErrorCode, message: string);
18
+ }
19
+ /**
20
+ * Returns whether a thrown value is an {@link ExecuteFailure}.
21
+ */
22
+ declare function isExecuteFailure(value: unknown): value is ExecuteFailure;
23
+ /**
24
+ * Returns whether a value can be serialized through the JSON-only host/guest boundary.
25
+ */
26
+ declare function isJsonSerializable(value: unknown, active?: Set<object>, memo?: WeakSet<object>): boolean;
27
+ //#endregion
28
+ export { isExecuteFailure as n, isJsonSerializable as r, ExecuteFailure as t };
29
+ //# sourceMappingURL=errors-B9ADBuDH.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors-B9ADBuDH.d.cts","names":[],"sources":["../src/errors.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;AAKA,CAAA,CAAA;AACQ,OAAA,CAAA,KAAA,CADK,cAAA,CAAA,OAAA,CAAuB,KAAA,CAC5B;EAKY,IAAA,CAAA,CALZ,gBAKY;EANgB,CAAA,CAAA;;AAgBpC,CAAA,CAAA,CAAA,CAAA;EAOgB,WAAA,CAAA,IAAA,CAAA,CAjBI,gBAmBZ,CAAA,CAAA,OACF,CAAA,CAAA,MAAA,CAAA;;;;;iBAVU,gBAAA,2BAA2C;;;;iBAO3C,kBAAA,0BAER,oBACF"}
@@ -0,0 +1,29 @@
1
+ /**
2
+ * @packageDocumentation
3
+ * Public TypeScript declarations for this package entrypoint.
4
+ */
5
+ import { u as ExecuteErrorCode } from "./runner-ClFrFnz9.js";
6
+
7
+ //#region src/errors.d.ts
8
+
9
+ /**
10
+ * Structured failure used internally to propagate executor and tool errors.
11
+ */
12
+ declare class ExecuteFailure extends Error {
13
+ code: ExecuteErrorCode;
14
+ /**
15
+ * Creates a structured failure with a trusted executor or tool error code.
16
+ */
17
+ constructor(code: ExecuteErrorCode, message: string);
18
+ }
19
+ /**
20
+ * Returns whether a thrown value is an {@link ExecuteFailure}.
21
+ */
22
+ declare function isExecuteFailure(value: unknown): value is ExecuteFailure;
23
+ /**
24
+ * Returns whether a value can be serialized through the JSON-only host/guest boundary.
25
+ */
26
+ declare function isJsonSerializable(value: unknown, active?: Set<object>, memo?: WeakSet<object>): boolean;
27
+ //#endregion
28
+ export { isExecuteFailure as n, isJsonSerializable as r, ExecuteFailure as t };
29
+ //# sourceMappingURL=errors-DlbJQYs7.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors-DlbJQYs7.d.ts","names":[],"sources":["../src/errors.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;AAKA,CAAA,CAAA;AACQ,OAAA,CAAA,KAAA,CADK,cAAA,CAAA,OAAA,CAAuB,KAAA,CAC5B;EAKY,IAAA,CAAA,CALZ,gBAKY;EANgB,CAAA,CAAA;;AAgBpC,CAAA,CAAA,CAAA,CAAA;EAOgB,WAAA,CAAA,IAAA,CAAA,CAjBI,gBAmBZ,CAAA,CAAA,OACF,CAAA,CAAA,MAAA,CAAA;;;;;iBAVU,gBAAA,2BAA2C;;;;iBAO3C,kBAAA,0BAER,oBACF"}
@@ -58,4 +58,4 @@ function isJsonSerializable(value, active = /* @__PURE__ */ new Set(), memo = /*
58
58
 
59
59
  //#endregion
60
60
  export { isExecuteFailure as n, isJsonSerializable as r, ExecuteFailure as t };
61
- //# sourceMappingURL=errors-BXpyBhCI.js.map
61
+ //# sourceMappingURL=errors-wS8yjQhS.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"errors-BXpyBhCI.js","names":[],"sources":["../src/errors.ts"],"sourcesContent":["import type { ExecuteErrorCode } from \"./types\";\n\n/**\n * Structured failure used internally to propagate executor and tool errors.\n */\nexport class ExecuteFailure extends Error {\n code: ExecuteErrorCode;\n\n /**\n * Creates a structured failure with a trusted executor or tool error code.\n */\n constructor(code: ExecuteErrorCode, message: string) {\n super(message);\n this.code = code;\n this.name = \"ExecuteFailure\";\n }\n}\n\n/**\n * Returns whether a thrown value is an {@link ExecuteFailure}.\n */\nexport function isExecuteFailure(value: unknown): value is ExecuteFailure {\n return value instanceof ExecuteFailure;\n}\n\n/**\n * Returns whether a value can be serialized through the JSON-only host/guest boundary.\n */\nexport function isJsonSerializable(\n value: unknown,\n active = new Set<object>(),\n memo = new WeakSet<object>(),\n): boolean {\n if (value === null) {\n return true;\n }\n\n switch (typeof value) {\n case \"string\":\n case \"boolean\":\n return true;\n case \"number\":\n return Number.isFinite(value);\n case \"bigint\":\n case \"function\":\n case \"symbol\":\n case \"undefined\":\n return false;\n case \"object\": {\n const objectValue = value as object;\n\n if (memo.has(objectValue)) {\n return true;\n }\n\n if (active.has(objectValue)) {\n return false;\n }\n\n active.add(objectValue);\n let isSerializable = false;\n\n try {\n if (Array.isArray(value)) {\n isSerializable = value.every((item) =>\n isJsonSerializable(item, active, memo),\n );\n return isSerializable;\n }\n\n const prototype = Object.getPrototypeOf(value);\n if (prototype !== Object.prototype && prototype !== null) {\n return false;\n }\n\n isSerializable = Object.values(value).every((item) =>\n isJsonSerializable(item, active, memo),\n );\n return isSerializable;\n } finally {\n active.delete(objectValue);\n if (isSerializable) {\n memo.add(objectValue);\n }\n }\n }\n }\n\n return false;\n}\n"],"mappings":";;;;AAKA,IAAa,iBAAb,cAAoC,MAAM;CACxC;;;;CAKA,YAAY,MAAwB,SAAiB;AACnD,QAAM,QAAQ;AACd,OAAK,OAAO;AACZ,OAAK,OAAO;;;;;;AAOhB,SAAgB,iBAAiB,OAAyC;AACxE,QAAO,iBAAiB;;;;;AAM1B,SAAgB,mBACd,OACA,yBAAS,IAAI,KAAa,EAC1B,uBAAO,IAAI,SAAiB,EACnB;AACT,KAAI,UAAU,KACZ,QAAO;AAGT,SAAQ,OAAO,OAAf;EACE,KAAK;EACL,KAAK,UACH,QAAO;EACT,KAAK,SACH,QAAO,OAAO,SAAS,MAAM;EAC/B,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK,YACH,QAAO;EACT,KAAK,UAAU;GACb,MAAM,cAAc;AAEpB,OAAI,KAAK,IAAI,YAAY,CACvB,QAAO;AAGT,OAAI,OAAO,IAAI,YAAY,CACzB,QAAO;AAGT,UAAO,IAAI,YAAY;GACvB,IAAI,iBAAiB;AAErB,OAAI;AACF,QAAI,MAAM,QAAQ,MAAM,EAAE;AACxB,sBAAiB,MAAM,OAAO,SAC5B,mBAAmB,MAAM,QAAQ,KAAK,CACvC;AACD,YAAO;;IAGT,MAAM,YAAY,OAAO,eAAe,MAAM;AAC9C,QAAI,cAAc,OAAO,aAAa,cAAc,KAClD,QAAO;AAGT,qBAAiB,OAAO,OAAO,MAAM,CAAC,OAAO,SAC3C,mBAAmB,MAAM,QAAQ,KAAK,CACvC;AACD,WAAO;aACC;AACR,WAAO,OAAO,YAAY;AAC1B,QAAI,eACF,MAAK,IAAI,YAAY;;;;AAM7B,QAAO"}
1
+ {"version":3,"file":"errors-wS8yjQhS.js","names":[],"sources":["../src/errors.ts"],"sourcesContent":["import type { ExecuteErrorCode } from \"./types\";\n\n/**\n * Structured failure used internally to propagate executor and tool errors.\n */\nexport class ExecuteFailure extends Error {\n code: ExecuteErrorCode;\n\n /**\n * Creates a structured failure with a trusted executor or tool error code.\n */\n constructor(code: ExecuteErrorCode, message: string) {\n super(message);\n this.code = code;\n this.name = \"ExecuteFailure\";\n }\n}\n\n/**\n * Returns whether a thrown value is an {@link ExecuteFailure}.\n */\nexport function isExecuteFailure(value: unknown): value is ExecuteFailure {\n return value instanceof ExecuteFailure;\n}\n\n/**\n * Returns whether a value can be serialized through the JSON-only host/guest boundary.\n */\nexport function isJsonSerializable(\n value: unknown,\n active = new Set<object>(),\n memo = new WeakSet<object>(),\n): boolean {\n if (value === null) {\n return true;\n }\n\n switch (typeof value) {\n case \"string\":\n case \"boolean\":\n return true;\n case \"number\":\n return Number.isFinite(value);\n case \"bigint\":\n case \"function\":\n case \"symbol\":\n case \"undefined\":\n return false;\n case \"object\": {\n const objectValue = value as object;\n\n if (memo.has(objectValue)) {\n return true;\n }\n\n if (active.has(objectValue)) {\n return false;\n }\n\n active.add(objectValue);\n let isSerializable = false;\n\n try {\n if (Array.isArray(value)) {\n isSerializable = value.every((item) =>\n isJsonSerializable(item, active, memo),\n );\n return isSerializable;\n }\n\n const prototype = Object.getPrototypeOf(value);\n if (prototype !== Object.prototype && prototype !== null) {\n return false;\n }\n\n isSerializable = Object.values(value).every((item) =>\n isJsonSerializable(item, active, memo),\n );\n return isSerializable;\n } finally {\n active.delete(objectValue);\n if (isSerializable) {\n memo.add(objectValue);\n }\n }\n }\n }\n\n return false;\n}\n"],"mappings":";;;;AAKA,IAAa,iBAAb,cAAoC,MAAM;CACxC;;;;CAKA,YAAY,MAAwB,SAAiB;AACnD,QAAM,QAAQ;AACd,OAAK,OAAO;AACZ,OAAK,OAAO;;;;;;AAOhB,SAAgB,iBAAiB,OAAyC;AACxE,QAAO,iBAAiB;;;;;AAM1B,SAAgB,mBACd,OACA,yBAAS,IAAI,KAAa,EAC1B,uBAAO,IAAI,SAAiB,EACnB;AACT,KAAI,UAAU,KACZ,QAAO;AAGT,SAAQ,OAAO,OAAf;EACE,KAAK;EACL,KAAK,UACH,QAAO;EACT,KAAK,SACH,QAAO,OAAO,SAAS,MAAM;EAC/B,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK,YACH,QAAO;EACT,KAAK,UAAU;GACb,MAAM,cAAc;AAEpB,OAAI,KAAK,IAAI,YAAY,CACvB,QAAO;AAGT,OAAI,OAAO,IAAI,YAAY,CACzB,QAAO;AAGT,UAAO,IAAI,YAAY;GACvB,IAAI,iBAAiB;AAErB,OAAI;AACF,QAAI,MAAM,QAAQ,MAAM,EAAE;AACxB,sBAAiB,MAAM,OAAO,SAC5B,mBAAmB,MAAM,QAAQ,KAAK,CACvC;AACD,YAAO;;IAGT,MAAM,YAAY,OAAO,eAAe,MAAM;AAC9C,QAAI,cAAc,OAAO,aAAa,cAAc,KAClD,QAAO;AAGT,qBAAiB,OAAO,OAAO,MAAM,CAAC,OAAO,SAC3C,mBAAmB,MAAM,QAAQ,KAAK,CACvC;AACD,WAAO;aACC;AACR,WAAO,OAAO,YAAY;AAC1B,QAAI,eACF,MAAK,IAAI,YAAY;;;;AAM7B,QAAO"}
@@ -76,4 +76,4 @@ Object.defineProperty(exports, 'isJsonSerializable', {
76
76
  return isJsonSerializable;
77
77
  }
78
78
  });
79
- //# sourceMappingURL=errors-BGSgVV40.cjs.map
79
+ //# sourceMappingURL=errors-xD8r6fCf.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"errors-BGSgVV40.cjs","names":[],"sources":["../src/errors.ts"],"sourcesContent":["import type { ExecuteErrorCode } from \"./types\";\n\n/**\n * Structured failure used internally to propagate executor and tool errors.\n */\nexport class ExecuteFailure extends Error {\n code: ExecuteErrorCode;\n\n /**\n * Creates a structured failure with a trusted executor or tool error code.\n */\n constructor(code: ExecuteErrorCode, message: string) {\n super(message);\n this.code = code;\n this.name = \"ExecuteFailure\";\n }\n}\n\n/**\n * Returns whether a thrown value is an {@link ExecuteFailure}.\n */\nexport function isExecuteFailure(value: unknown): value is ExecuteFailure {\n return value instanceof ExecuteFailure;\n}\n\n/**\n * Returns whether a value can be serialized through the JSON-only host/guest boundary.\n */\nexport function isJsonSerializable(\n value: unknown,\n active = new Set<object>(),\n memo = new WeakSet<object>(),\n): boolean {\n if (value === null) {\n return true;\n }\n\n switch (typeof value) {\n case \"string\":\n case \"boolean\":\n return true;\n case \"number\":\n return Number.isFinite(value);\n case \"bigint\":\n case \"function\":\n case \"symbol\":\n case \"undefined\":\n return false;\n case \"object\": {\n const objectValue = value as object;\n\n if (memo.has(objectValue)) {\n return true;\n }\n\n if (active.has(objectValue)) {\n return false;\n }\n\n active.add(objectValue);\n let isSerializable = false;\n\n try {\n if (Array.isArray(value)) {\n isSerializable = value.every((item) =>\n isJsonSerializable(item, active, memo),\n );\n return isSerializable;\n }\n\n const prototype = Object.getPrototypeOf(value);\n if (prototype !== Object.prototype && prototype !== null) {\n return false;\n }\n\n isSerializable = Object.values(value).every((item) =>\n isJsonSerializable(item, active, memo),\n );\n return isSerializable;\n } finally {\n active.delete(objectValue);\n if (isSerializable) {\n memo.add(objectValue);\n }\n }\n }\n }\n\n return false;\n}\n"],"mappings":";;;;;AAKA,IAAa,iBAAb,cAAoC,MAAM;CACxC;;;;CAKA,YAAY,MAAwB,SAAiB;AACnD,QAAM,QAAQ;AACd,OAAK,OAAO;AACZ,OAAK,OAAO;;;;;;AAOhB,SAAgB,iBAAiB,OAAyC;AACxE,QAAO,iBAAiB;;;;;AAM1B,SAAgB,mBACd,OACA,yBAAS,IAAI,KAAa,EAC1B,uBAAO,IAAI,SAAiB,EACnB;AACT,KAAI,UAAU,KACZ,QAAO;AAGT,SAAQ,OAAO,OAAf;EACE,KAAK;EACL,KAAK,UACH,QAAO;EACT,KAAK,SACH,QAAO,OAAO,SAAS,MAAM;EAC/B,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK,YACH,QAAO;EACT,KAAK,UAAU;GACb,MAAM,cAAc;AAEpB,OAAI,KAAK,IAAI,YAAY,CACvB,QAAO;AAGT,OAAI,OAAO,IAAI,YAAY,CACzB,QAAO;AAGT,UAAO,IAAI,YAAY;GACvB,IAAI,iBAAiB;AAErB,OAAI;AACF,QAAI,MAAM,QAAQ,MAAM,EAAE;AACxB,sBAAiB,MAAM,OAAO,SAC5B,mBAAmB,MAAM,QAAQ,KAAK,CACvC;AACD,YAAO;;IAGT,MAAM,YAAY,OAAO,eAAe,MAAM;AAC9C,QAAI,cAAc,OAAO,aAAa,cAAc,KAClD,QAAO;AAGT,qBAAiB,OAAO,OAAO,MAAM,CAAC,OAAO,SAC3C,mBAAmB,MAAM,QAAQ,KAAK,CACvC;AACD,WAAO;aACC;AACR,WAAO,OAAO,YAAY;AAC1B,QAAI,eACF,MAAK,IAAI,YAAY;;;;AAM7B,QAAO"}
1
+ {"version":3,"file":"errors-xD8r6fCf.cjs","names":[],"sources":["../src/errors.ts"],"sourcesContent":["import type { ExecuteErrorCode } from \"./types\";\n\n/**\n * Structured failure used internally to propagate executor and tool errors.\n */\nexport class ExecuteFailure extends Error {\n code: ExecuteErrorCode;\n\n /**\n * Creates a structured failure with a trusted executor or tool error code.\n */\n constructor(code: ExecuteErrorCode, message: string) {\n super(message);\n this.code = code;\n this.name = \"ExecuteFailure\";\n }\n}\n\n/**\n * Returns whether a thrown value is an {@link ExecuteFailure}.\n */\nexport function isExecuteFailure(value: unknown): value is ExecuteFailure {\n return value instanceof ExecuteFailure;\n}\n\n/**\n * Returns whether a value can be serialized through the JSON-only host/guest boundary.\n */\nexport function isJsonSerializable(\n value: unknown,\n active = new Set<object>(),\n memo = new WeakSet<object>(),\n): boolean {\n if (value === null) {\n return true;\n }\n\n switch (typeof value) {\n case \"string\":\n case \"boolean\":\n return true;\n case \"number\":\n return Number.isFinite(value);\n case \"bigint\":\n case \"function\":\n case \"symbol\":\n case \"undefined\":\n return false;\n case \"object\": {\n const objectValue = value as object;\n\n if (memo.has(objectValue)) {\n return true;\n }\n\n if (active.has(objectValue)) {\n return false;\n }\n\n active.add(objectValue);\n let isSerializable = false;\n\n try {\n if (Array.isArray(value)) {\n isSerializable = value.every((item) =>\n isJsonSerializable(item, active, memo),\n );\n return isSerializable;\n }\n\n const prototype = Object.getPrototypeOf(value);\n if (prototype !== Object.prototype && prototype !== null) {\n return false;\n }\n\n isSerializable = Object.values(value).every((item) =>\n isJsonSerializable(item, active, memo),\n );\n return isSerializable;\n } finally {\n active.delete(objectValue);\n if (isSerializable) {\n memo.add(objectValue);\n }\n }\n }\n }\n\n return false;\n}\n"],"mappings":";;;;;AAKA,IAAa,iBAAb,cAAoC,MAAM;CACxC;;;;CAKA,YAAY,MAAwB,SAAiB;AACnD,QAAM,QAAQ;AACd,OAAK,OAAO;AACZ,OAAK,OAAO;;;;;;AAOhB,SAAgB,iBAAiB,OAAyC;AACxE,QAAO,iBAAiB;;;;;AAM1B,SAAgB,mBACd,OACA,yBAAS,IAAI,KAAa,EAC1B,uBAAO,IAAI,SAAiB,EACnB;AACT,KAAI,UAAU,KACZ,QAAO;AAGT,SAAQ,OAAO,OAAf;EACE,KAAK;EACL,KAAK,UACH,QAAO;EACT,KAAK,SACH,QAAO,OAAO,SAAS,MAAM;EAC/B,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK,YACH,QAAO;EACT,KAAK,UAAU;GACb,MAAM,cAAc;AAEpB,OAAI,KAAK,IAAI,YAAY,CACvB,QAAO;AAGT,OAAI,OAAO,IAAI,YAAY,CACzB,QAAO;AAGT,UAAO,IAAI,YAAY;GACvB,IAAI,iBAAiB;AAErB,OAAI;AACF,QAAI,MAAM,QAAQ,MAAM,EAAE;AACxB,sBAAiB,MAAM,OAAO,SAC5B,mBAAmB,MAAM,QAAQ,KAAK,CACvC;AACD,YAAO;;IAGT,MAAM,YAAY,OAAO,eAAe,MAAM;AAC9C,QAAI,cAAc,OAAO,aAAa,cAAc,KAClD,QAAO;AAGT,qBAAiB,OAAO,OAAO,MAAM,CAAC,OAAO,SAC3C,mBAAmB,MAAM,QAAQ,KAAK,CACvC;AACD,WAAO;aACC;AACR,WAAO,OAAO,YAAY;AAC1B,QAAI,eACF,MAAK,IAAI,YAAY;;;;AAM7B,QAAO"}
@@ -2,7 +2,7 @@
2
2
  * @packageDocumentation
3
3
  * Public TypeScript declarations for this package entrypoint.
4
4
  */
5
- import { d as ExecuteResult, m as ResolvedToolProvider, t as ExecutionOptions } from "./runner-FSGSGEpx.js";
5
+ import { d as ExecuteResult, m as ResolvedToolProvider, t as ExecutionOptions } from "./runner-ClFrFnz9.js";
6
6
 
7
7
  //#region src/executor/executor.d.ts
8
8
 
@@ -26,4 +26,4 @@ interface Executor {
26
26
  }
27
27
  //#endregion
28
28
  export { ExecutorPoolOptions as n, Executor as t };
29
- //# sourceMappingURL=executor-_CO7E1U7.d.ts.map
29
+ //# sourceMappingURL=executor-B7q7K_27.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"executor-_CO7E1U7.d.ts","names":[],"sources":["../src/executor/executor.ts"],"sourcesContent":[],"mappings":";;;;;;;;;AAOA,CAAA,CAAA,CAAA,QAAA,CAAA,OAAA,CAAA,QAAA,CAAA,GAAA,CAAA,QAAA,CAAA,eAAA,CAAA,IAAA,CAAA,GAAA,CAAA;AAUA,CAAA,CAAA,CAAA,IAAA,CAAA,IAAA,CAAA,MAAA,CAAA,KAAA,CAAA,KAAA,CAAA,QAAA,CAAA,CAAA,CAAA,KAAA,CAAA,KAAA,CAAA,OAAA,CAAA,GAAA,CAAA,SAAA;;AAIc,SAAA,CAdG,mBAAA,CAcH;EACD,aAAA,CAAA,CAAA,CAAA,MAAA;EAAR,OAAA,CAAA,CAAA,MAAA;EACS,OAAA,CAAA,CAAA,CAAA,MAAA;EACc,OAAA,CAAA,CAAA,CAAA,OAAA,CAAA,CAAA,CAAA,MAAA;;;;;UAPX,QAAA;mCAGF,kCACD,mBACT,QAAQ;cACC;4BACc"}
1
+ {"version":3,"file":"executor-B7q7K_27.d.ts","names":[],"sources":["../src/executor/executor.ts"],"sourcesContent":[],"mappings":";;;;;;;;;AAOA,CAAA,CAAA,CAAA,QAAA,CAAA,OAAA,CAAA,QAAA,CAAA,GAAA,CAAA,QAAA,CAAA,eAAA,CAAA,IAAA,CAAA,GAAA,CAAA;AAUA,CAAA,CAAA,CAAA,IAAA,CAAA,IAAA,CAAA,MAAA,CAAA,KAAA,CAAA,KAAA,CAAA,QAAA,CAAA,CAAA,CAAA,KAAA,CAAA,KAAA,CAAA,OAAA,CAAA,GAAA,CAAA,SAAA;;AAIc,SAAA,CAdG,mBAAA,CAcH;EACD,aAAA,CAAA,CAAA,CAAA,MAAA;EAAR,OAAA,CAAA,CAAA,MAAA;EACS,OAAA,CAAA,CAAA,CAAA,MAAA;EACc,OAAA,CAAA,CAAA,CAAA,OAAA,CAAA,CAAA,CAAA,MAAA;;;;;UAPX,QAAA;mCAGF,kCACD,mBACT,QAAQ;cACC;4BACc"}
@@ -26,4 +26,4 @@ interface Executor {
26
26
  }
27
27
  //#endregion
28
28
  export { ExecutorPoolOptions as n, Executor as t };
29
- //# sourceMappingURL=executor-CEXp0gYP.d.cts.map
29
+ //# sourceMappingURL=executor-BsE5nF-j.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"executor-CEXp0gYP.d.cts","names":[],"sources":["../src/executor/executor.ts"],"sourcesContent":[],"mappings":";;;;;;;;;AAOA,CAAA,CAAA,CAAA,QAAA,CAAA,OAAA,CAAA,QAAA,CAAA,GAAA,CAAA,QAAA,CAAA,eAAA,CAAA,IAAA,CAAA,GAAA,CAAA;AAUA,CAAA,CAAA,CAAA,IAAA,CAAA,IAAA,CAAA,MAAA,CAAA,KAAA,CAAA,KAAA,CAAA,QAAA,CAAA,CAAA,CAAA,KAAA,CAAA,KAAA,CAAA,OAAA,CAAA,GAAA,CAAA,SAAA;;AAIc,SAAA,CAdG,mBAAA,CAcH;EACD,aAAA,CAAA,CAAA,CAAA,MAAA;EAAR,OAAA,CAAA,CAAA,MAAA;EACS,OAAA,CAAA,CAAA,CAAA,MAAA;EACc,OAAA,CAAA,CAAA,CAAA,OAAA,CAAA,CAAA,CAAA,MAAA;;;;;UAPX,QAAA;mCAGF,kCACD,mBACT,QAAQ;cACC;4BACc"}
1
+ {"version":3,"file":"executor-BsE5nF-j.d.cts","names":[],"sources":["../src/executor/executor.ts"],"sourcesContent":[],"mappings":";;;;;;;;;AAOA,CAAA,CAAA,CAAA,QAAA,CAAA,OAAA,CAAA,QAAA,CAAA,GAAA,CAAA,QAAA,CAAA,eAAA,CAAA,IAAA,CAAA,GAAA,CAAA;AAUA,CAAA,CAAA,CAAA,IAAA,CAAA,IAAA,CAAA,MAAA,CAAA,KAAA,CAAA,KAAA,CAAA,QAAA,CAAA,CAAA,CAAA,KAAA,CAAA,KAAA,CAAA,OAAA,CAAA,GAAA,CAAA,SAAA;;AAIc,SAAA,CAdG,mBAAA,CAcH;EACD,aAAA,CAAA,CAAA,CAAA,MAAA;EAAR,OAAA,CAAA,CAAA,MAAA;EACS,OAAA,CAAA,CAAA,CAAA,MAAA;EACc,OAAA,CAAA,CAAA,CAAA,OAAA,CAAA,CAAA,CAAA,MAAA;;;;;UAPX,QAAA;mCAGF,kCACD,mBACT,QAAQ;cACC;4BACc"}
package/dist/index.cjs CHANGED
@@ -1,27 +1,14 @@
1
- const require_resolveProvider = require('./resolveProvider-DfcSnwnp.cjs');
2
- const require_runner = require('./runner-BxbJ5eWb.cjs');
3
- const require_normalize = require('./normalize-B80ZCnxe.cjs');
4
- const require_errors = require('./errors-BGSgVV40.cjs');
1
+ const require_resolveProvider = require('./resolveProvider-BZYSw8Qk.cjs');
2
+ const require_errors = require('./errors-xD8r6fCf.cjs');
5
3
 
6
4
  exports.ExecuteFailure = require_errors.ExecuteFailure;
7
5
  exports.assertValidIdentifier = require_resolveProvider.assertValidIdentifier;
8
- exports.createExecutionContext = require_runner.createExecutionContext;
9
- exports.createTimeoutExecuteResult = require_runner.createTimeoutExecuteResult;
10
- exports.createToolCallDispatcher = require_runner.createToolCallDispatcher;
11
- exports.extractProviderManifests = require_runner.extractProviderManifests;
12
- exports.formatConsoleLine = require_runner.formatConsoleLine;
13
6
  exports.generateTypesFromJsonSchema = require_resolveProvider.generateTypesFromJsonSchema;
14
- exports.getExecutionTimeoutMessage = require_runner.getExecutionTimeoutMessage;
15
7
  exports.isExecuteFailure = require_errors.isExecuteFailure;
16
8
  exports.isJsonSerializable = require_errors.isJsonSerializable;
17
- exports.isKnownExecuteErrorCode = require_runner.isKnownExecuteErrorCode;
18
9
  exports.isReservedWord = require_resolveProvider.isReservedWord;
19
10
  exports.isValidIdentifier = require_resolveProvider.isValidIdentifier;
20
- exports.normalizeCode = require_normalize.normalizeCode;
21
- exports.normalizeThrownMessage = require_runner.normalizeThrownMessage;
22
- exports.normalizeThrownName = require_runner.normalizeThrownName;
23
11
  exports.resolveProvider = require_resolveProvider.resolveProvider;
24
12
  exports.sanitizeIdentifier = require_resolveProvider.sanitizeIdentifier;
25
13
  exports.sanitizeToolName = require_resolveProvider.sanitizeToolName;
26
- exports.serializePropertyName = require_resolveProvider.serializePropertyName;
27
- exports.truncateLogs = require_runner.truncateLogs;
14
+ exports.serializePropertyName = require_resolveProvider.serializePropertyName;
package/dist/index.d.cts CHANGED
@@ -2,9 +2,9 @@
2
2
  * @packageDocumentation
3
3
  * Public TypeScript declarations for this package entrypoint.
4
4
  */
5
- import { _ as ToolProvider, a as ToolCall, c as extractProviderManifests, d as ExecuteResult, f as JsonSchema, g as ToolExecutionContext, h as ToolDescriptor, i as ProviderToolManifest, l as ExecuteError, m as ResolvedToolProvider, n as ExecutorRuntimeOptions, o as ToolCallResult, p as ResolvedToolDescriptor, r as ProviderManifest, s as createToolCallDispatcher, t as ExecutionOptions, u as ExecuteErrorCode, v as ToolSchema, y as TypegenToolDescriptor } from "./runner-DSgvu6Ad.cjs";
6
- import { a as createExecutionContext, c as getExecutionTimeoutMessage, d as normalizeThrownName, f as truncateLogs, i as normalizeCode, l as isKnownExecuteErrorCode, n as isExecuteFailure, o as createTimeoutExecuteResult, r as isJsonSerializable, s as formatConsoleLine, t as ExecuteFailure, u as normalizeThrownMessage } from "./errors-B3IY3ID-.cjs";
7
- import { n as ExecutorPoolOptions, t as Executor } from "./executor-CEXp0gYP.cjs";
5
+ import { _ as ToolProvider, a as ToolCall, d as ExecuteResult, f as JsonSchema, g as ToolExecutionContext, h as ToolDescriptor, i as ProviderToolManifest, l as ExecuteError, m as ResolvedToolProvider, n as ExecutorRuntimeOptions, o as ToolCallResult, p as ResolvedToolDescriptor, r as ProviderManifest, t as ExecutionOptions, u as ExecuteErrorCode, v as ToolSchema, y as TypegenToolDescriptor } from "./runner-DSgvu6Ad.cjs";
6
+ import { n as ExecutorPoolOptions, t as Executor } from "./executor-BsE5nF-j.cjs";
7
+ import { n as isExecuteFailure, r as isJsonSerializable, t as ExecuteFailure } from "./errors-B9ADBuDH.cjs";
8
8
 
9
9
  //#region src/identifier.d.ts
10
10
  /**
@@ -46,5 +46,5 @@ declare function resolveProvider(provider: ToolProvider): ResolvedToolProvider;
46
46
  */
47
47
  declare function generateTypesFromJsonSchema(providerName: string, tools: Record<string, TypegenToolDescriptor>): string;
48
48
  //#endregion
49
- export { type ExecuteError, type ExecuteErrorCode, ExecuteFailure, type ExecuteResult, type ExecutionOptions, type Executor, type ExecutorPoolOptions, type ExecutorRuntimeOptions, type JsonSchema, type ProviderManifest, type ProviderToolManifest, type ResolvedToolDescriptor, type ResolvedToolProvider, type ToolCall, type ToolCallResult, type ToolDescriptor, type ToolExecutionContext, type ToolProvider, type ToolSchema, type TypegenToolDescriptor, assertValidIdentifier, createExecutionContext, createTimeoutExecuteResult, createToolCallDispatcher, extractProviderManifests, formatConsoleLine, generateTypesFromJsonSchema, getExecutionTimeoutMessage, isExecuteFailure, isJsonSerializable, isKnownExecuteErrorCode, isReservedWord, isValidIdentifier, normalizeCode, normalizeThrownMessage, normalizeThrownName, resolveProvider, sanitizeIdentifier, sanitizeToolName, serializePropertyName, truncateLogs };
49
+ export { type ExecuteError, type ExecuteErrorCode, ExecuteFailure, type ExecuteResult, type ExecutionOptions, type Executor, type ExecutorPoolOptions, type ExecutorRuntimeOptions, type JsonSchema, type ProviderManifest, type ProviderToolManifest, type ResolvedToolDescriptor, type ResolvedToolProvider, type ToolCall, type ToolCallResult, type ToolDescriptor, type ToolExecutionContext, type ToolProvider, type ToolSchema, type TypegenToolDescriptor, assertValidIdentifier, generateTypesFromJsonSchema, isExecuteFailure, isJsonSerializable, isReservedWord, isValidIdentifier, resolveProvider, sanitizeIdentifier, sanitizeToolName, serializePropertyName };
50
50
  //# sourceMappingURL=index.d.cts.map
package/dist/index.d.ts CHANGED
@@ -2,9 +2,9 @@
2
2
  * @packageDocumentation
3
3
  * Public TypeScript declarations for this package entrypoint.
4
4
  */
5
- import { _ as ToolProvider, a as ToolCall, c as extractProviderManifests, d as ExecuteResult, f as JsonSchema, g as ToolExecutionContext, h as ToolDescriptor, i as ProviderToolManifest, l as ExecuteError, m as ResolvedToolProvider, n as ExecutorRuntimeOptions, o as ToolCallResult, p as ResolvedToolDescriptor, r as ProviderManifest, s as createToolCallDispatcher, t as ExecutionOptions, u as ExecuteErrorCode, v as ToolSchema, y as TypegenToolDescriptor } from "./runner-FSGSGEpx.js";
6
- import { a as createExecutionContext, c as getExecutionTimeoutMessage, d as normalizeThrownName, f as truncateLogs, i as normalizeCode, l as isKnownExecuteErrorCode, n as isExecuteFailure, o as createTimeoutExecuteResult, r as isJsonSerializable, s as formatConsoleLine, t as ExecuteFailure, u as normalizeThrownMessage } from "./errors-BbUru7ko.js";
7
- import { n as ExecutorPoolOptions, t as Executor } from "./executor-_CO7E1U7.js";
5
+ import { _ as ToolProvider, a as ToolCall, d as ExecuteResult, f as JsonSchema, g as ToolExecutionContext, h as ToolDescriptor, i as ProviderToolManifest, l as ExecuteError, m as ResolvedToolProvider, n as ExecutorRuntimeOptions, o as ToolCallResult, p as ResolvedToolDescriptor, r as ProviderManifest, t as ExecutionOptions, u as ExecuteErrorCode, v as ToolSchema, y as TypegenToolDescriptor } from "./runner-ClFrFnz9.js";
6
+ import { n as ExecutorPoolOptions, t as Executor } from "./executor-B7q7K_27.js";
7
+ import { n as isExecuteFailure, r as isJsonSerializable, t as ExecuteFailure } from "./errors-DlbJQYs7.js";
8
8
 
9
9
  //#region src/identifier.d.ts
10
10
  /**
@@ -46,5 +46,5 @@ declare function resolveProvider(provider: ToolProvider): ResolvedToolProvider;
46
46
  */
47
47
  declare function generateTypesFromJsonSchema(providerName: string, tools: Record<string, TypegenToolDescriptor>): string;
48
48
  //#endregion
49
- export { type ExecuteError, type ExecuteErrorCode, ExecuteFailure, type ExecuteResult, type ExecutionOptions, type Executor, type ExecutorPoolOptions, type ExecutorRuntimeOptions, type JsonSchema, type ProviderManifest, type ProviderToolManifest, type ResolvedToolDescriptor, type ResolvedToolProvider, type ToolCall, type ToolCallResult, type ToolDescriptor, type ToolExecutionContext, type ToolProvider, type ToolSchema, type TypegenToolDescriptor, assertValidIdentifier, createExecutionContext, createTimeoutExecuteResult, createToolCallDispatcher, extractProviderManifests, formatConsoleLine, generateTypesFromJsonSchema, getExecutionTimeoutMessage, isExecuteFailure, isJsonSerializable, isKnownExecuteErrorCode, isReservedWord, isValidIdentifier, normalizeCode, normalizeThrownMessage, normalizeThrownName, resolveProvider, sanitizeIdentifier, sanitizeToolName, serializePropertyName, truncateLogs };
49
+ export { type ExecuteError, type ExecuteErrorCode, ExecuteFailure, type ExecuteResult, type ExecutionOptions, type Executor, type ExecutorPoolOptions, type ExecutorRuntimeOptions, type JsonSchema, type ProviderManifest, type ProviderToolManifest, type ResolvedToolDescriptor, type ResolvedToolProvider, type ToolCall, type ToolCallResult, type ToolDescriptor, type ToolExecutionContext, type ToolProvider, type ToolSchema, type TypegenToolDescriptor, assertValidIdentifier, generateTypesFromJsonSchema, isExecuteFailure, isJsonSerializable, isReservedWord, isValidIdentifier, resolveProvider, sanitizeIdentifier, sanitizeToolName, serializePropertyName };
50
50
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -1,6 +1,4 @@
1
- import { a as formatConsoleLine, c as normalizeThrownMessage, i as createTimeoutExecuteResult, l as normalizeThrownName, n as extractProviderManifests, o as getExecutionTimeoutMessage, r as createExecutionContext, s as isKnownExecuteErrorCode, t as createToolCallDispatcher, u as truncateLogs } from "./runner-nUCF59Au.js";
2
- import { c as isReservedWord, d as serializePropertyName, l as isValidIdentifier, n as generateTypesFromJsonSchema, o as sanitizeToolName, s as assertValidIdentifier, t as resolveProvider, u as sanitizeIdentifier } from "./resolveProvider-BHuwOGBm.js";
3
- import { t as normalizeCode } from "./normalize-dfQC7HWx.js";
4
- import { n as isExecuteFailure, r as isJsonSerializable, t as ExecuteFailure } from "./errors-BXpyBhCI.js";
1
+ import { c as isReservedWord, d as serializePropertyName, l as isValidIdentifier, n as generateTypesFromJsonSchema, o as sanitizeToolName, s as assertValidIdentifier, t as resolveProvider, u as sanitizeIdentifier } from "./resolveProvider-UqQxdF4j.js";
2
+ import { n as isExecuteFailure, r as isJsonSerializable, t as ExecuteFailure } from "./errors-wS8yjQhS.js";
5
3
 
6
- export { ExecuteFailure, assertValidIdentifier, createExecutionContext, createTimeoutExecuteResult, createToolCallDispatcher, extractProviderManifests, formatConsoleLine, generateTypesFromJsonSchema, getExecutionTimeoutMessage, isExecuteFailure, isJsonSerializable, isKnownExecuteErrorCode, isReservedWord, isValidIdentifier, normalizeCode, normalizeThrownMessage, normalizeThrownName, resolveProvider, sanitizeIdentifier, sanitizeToolName, serializePropertyName, truncateLogs };
4
+ export { ExecuteFailure, assertValidIdentifier, generateTypesFromJsonSchema, isExecuteFailure, isJsonSerializable, isReservedWord, isValidIdentifier, resolveProvider, sanitizeIdentifier, sanitizeToolName, serializePropertyName };
@@ -1,5 +1,5 @@
1
- const require_resolveProvider = require('../resolveProvider-DfcSnwnp.cjs');
2
- require('../errors-BGSgVV40.cjs');
1
+ const require_resolveProvider = require('../resolveProvider-BZYSw8Qk.cjs');
2
+ require('../errors-xD8r6fCf.cjs');
3
3
  let zod = require("zod");
4
4
  zod = require_resolveProvider.__toESM(zod);
5
5
  let __modelcontextprotocol_sdk_server_mcp_js = require("@modelcontextprotocol/sdk/server/mcp.js");
@@ -3,7 +3,7 @@
3
3
  * Public TypeScript declarations for this package entrypoint.
4
4
  */
5
5
  import { d as ExecuteResult, f as JsonSchema, g as ToolExecutionContext, l as ExecuteError, m as ResolvedToolProvider, n as ExecutorRuntimeOptions, p as ResolvedToolDescriptor, t as ExecutionOptions, u as ExecuteErrorCode } from "../runner-DSgvu6Ad.cjs";
6
- import { t as Executor } from "../executor-CEXp0gYP.cjs";
6
+ import { t as Executor } from "../executor-BsE5nF-j.cjs";
7
7
  import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
8
8
  import { Implementation } from "@modelcontextprotocol/sdk/types.js";
9
9
  import { Client } from "@modelcontextprotocol/sdk/client/index.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.cts","names":[],"sources":["../../src/mcp/createMcpToolProvider.ts","../../src/mcp/codeMcpServer.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;;;;AAYY,IAAA,CAAA,mBAAA,CAAA,CAAA,CAAmB;EAQnB,MAAA,CAAA,CAPF,MAOE;EAQA,UAAA,CAAA,CAAA,CAdG,cAcU;AAUzB,CAAA;AAiBA,CAAA,CAAA;AAUA,CAAA,CAAA,CAAA,KAAA,CAAA,GAAA,CAAA,MAAA,CAAA,MAAA,CAAA,IAAA,CAAA,QAAA,CAAA,QAAA,CAAA,SAAA,CAAA,OAAA;;AAIe,IAAA,CAjDH,mBAAA,CAAA,CAAA,CAiDG;EAEA,MAAA,CAAA,CAlDL,SAkDK;EAAO,UAAA,CAAA,CAAA,CAjDP,cAiDO;AAqEtB,CAAA;;;;AAGG,IAAA,CAnHS,aAAA,CAAA,CAAA,CAAgB,mBAmHzB,CAAA,CAAA,CAnH+C,mBAmH/C;;AAsDH,CAAA,CAAA,CAAA,OAAA,CAAA,GAAA,CAAA,QAAA,CAAA,MAAA,CAAA,QAAA,CAAA,IAAA,C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A,CAAA,KAAA,CAAA;EAAO,CAAA,CAAA,CAAA,CAAA,QAAA,CAAA,MAAA,CAAA,KAAA,CAAA,GAAA,CAAA,GAAA,CAAA,OAAA,CAAA,KAAA,CAAA,CAAA,CAAA;EAqEA,KAAA,CAAA,CAAA,CAAA;IACZ,OAAA,CAAA,CAAA,CAAA,MAAA;IACC,MAAA,CAAA,CAAA,CAAA,MAAA;IACA,MAAA,CAAA,CAAA,CAAA,MAAA;EAAR,CAAA;;AAsDH,CAAA,CAAA;;;AAGW,OAAA,CAAA,QAAA,CCAW,aAAA,CDAX,MAAA,CAAA,CCCD,aDDC,CAAA,CAAA,OAAA,CAAA,CCEA,oBDFA,CAAA,CAAA,CCGR,ODHQ,CCGA,SDHA,CAAA"}
@@ -2,8 +2,8 @@
2
2
  * @packageDocumentation
3
3
  * Public TypeScript declarations for this package entrypoint.
4
4
  */
5
- import { d as ExecuteResult, f as JsonSchema, g as ToolExecutionContext, l as ExecuteError, m as ResolvedToolProvider, n as ExecutorRuntimeOptions, p as ResolvedToolDescriptor, t as ExecutionOptions, u as ExecuteErrorCode } from "../runner-FSGSGEpx.js";
6
- import { t as Executor } from "../executor-_CO7E1U7.js";
5
+ import { d as ExecuteResult, f as JsonSchema, g as ToolExecutionContext, l as ExecuteError, m as ResolvedToolProvider, n as ExecutorRuntimeOptions, p as ResolvedToolDescriptor, t as ExecutionOptions, u as ExecuteErrorCode } from "../runner-ClFrFnz9.js";
6
+ import { t as Executor } from "../executor-B7q7K_27.js";
7
7
  import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
8
8
  import { Client } from "@modelcontextprotocol/sdk/client/index.js";
9
9
  import { Implementation } from "@modelcontextprotocol/sdk/types.js";
package/dist/mcp/index.js CHANGED
@@ -1,5 +1,5 @@
1
- import { a as renderNamespaceDeclaration, i as renderDocComment, r as schemaToType, t as resolveProvider } from "../resolveProvider-BHuwOGBm.js";
2
- import "../errors-BXpyBhCI.js";
1
+ import { a as renderNamespaceDeclaration, i as renderDocComment, r as schemaToType, t as resolveProvider } from "../resolveProvider-UqQxdF4j.js";
2
+ import "../errors-wS8yjQhS.js";
3
3
  import * as z from "zod";
4
4
  import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
5
5
  import { Client } from "@modelcontextprotocol/sdk/client/index.js";
@@ -1,5 +1,5 @@
1
- const require_runner = require('../runner-BxbJ5eWb.cjs');
2
- require('../errors-BGSgVV40.cjs');
1
+ require('../errors-xD8r6fCf.cjs');
2
+ const require_runner = require('../runner-CsrfDub-.cjs');
3
3
 
4
4
  //#region src/protocol/messages.ts
5
5
  function isRecord(value) {
@@ -2,7 +2,7 @@
2
2
  * @packageDocumentation
3
3
  * Public TypeScript declarations for this package entrypoint.
4
4
  */
5
- import { a as ToolCall, d as ExecuteResult, f as JsonSchema, g as ToolExecutionContext, i as ProviderToolManifest, l as ExecuteError, m as ResolvedToolProvider, n as ExecutorRuntimeOptions, o as ToolCallResult, p as ResolvedToolDescriptor, r as ProviderManifest, u as ExecuteErrorCode } from "../runner-FSGSGEpx.js";
5
+ import { a as ToolCall, d as ExecuteResult, f as JsonSchema, g as ToolExecutionContext, i as ProviderToolManifest, l as ExecuteError, m as ResolvedToolProvider, n as ExecutorRuntimeOptions, o as ToolCallResult, p as ResolvedToolDescriptor, r as ProviderManifest, u as ExecuteErrorCode } from "../runner-ClFrFnz9.js";
6
6
 
7
7
  //#region src/protocol/messages.d.ts
8
8
 
@@ -1,5 +1,5 @@
1
- import { n as extractProviderManifests, o as getExecutionTimeoutMessage, t as createToolCallDispatcher } from "../runner-nUCF59Au.js";
2
- import "../errors-BXpyBhCI.js";
1
+ import "../errors-wS8yjQhS.js";
2
+ import { n as extractProviderManifests, o as getExecutionTimeoutMessage, t as createToolCallDispatcher } from "../runner-6GMM-5ur.js";
3
3
 
4
4
  //#region src/protocol/messages.ts
5
5
  function isRecord(value) {
@@ -25,7 +25,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
25
25
  }) : target, mod));
26
26
 
27
27
  //#endregion
28
- const require_errors = require('./errors-BGSgVV40.cjs');
28
+ const require_errors = require('./errors-xD8r6fCf.cjs');
29
29
  let ajv = require("ajv");
30
30
  ajv = __toESM(ajv);
31
31
  let zod = require("zod");
@@ -385,4 +385,4 @@ Object.defineProperty(exports, 'serializePropertyName', {
385
385
  return serializePropertyName;
386
386
  }
387
387
  });
388
- //# sourceMappingURL=resolveProvider-DfcSnwnp.cjs.map
388
+ //# sourceMappingURL=resolveProvider-BZYSw8Qk.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"resolveProvider-DfcSnwnp.cjs","names":["isRecord","lines: string[]","ajv","Ajv","originalToSafeName: Record<string, string>","safeToOriginalName: Record<string, string>","resolvedTools: Record<string, ResolvedToolDescriptor>","typegenTools: Record<string, TypegenToolDescriptor>","ExecuteFailure","isJsonSerializable","isExecuteFailure"],"sources":["../src/identifier.ts","../src/sanitize.ts","../src/schema/normalizeSchema.ts","../src/typegen/render.ts","../src/typegen/jsonSchema.ts","../src/provider/resolveProvider.ts"],"sourcesContent":["const RESERVED_WORDS = new Set([\n \"await\",\n \"break\",\n \"case\",\n \"catch\",\n \"class\",\n \"const\",\n \"continue\",\n \"debugger\",\n \"default\",\n \"delete\",\n \"do\",\n \"else\",\n \"enum\",\n \"export\",\n \"extends\",\n \"false\",\n \"finally\",\n \"for\",\n \"function\",\n \"if\",\n \"import\",\n \"in\",\n \"instanceof\",\n \"new\",\n \"null\",\n \"return\",\n \"super\",\n \"switch\",\n \"this\",\n \"throw\",\n \"true\",\n \"try\",\n \"typeof\",\n \"var\",\n \"void\",\n \"while\",\n \"with\",\n \"yield\",\n]);\n\nconst UNDERSCORE_CHAR_CODE = 95;\n\nfunction trimEdgeUnderscores(value: string): string {\n let start = 0;\n let end = value.length;\n\n while (start < end && value.charCodeAt(start) === UNDERSCORE_CHAR_CODE) {\n start += 1;\n }\n\n while (end > start && value.charCodeAt(end - 1) === UNDERSCORE_CHAR_CODE) {\n end -= 1;\n }\n\n return value.slice(start, end);\n}\n\n/**\n * Returns whether the value is a valid JavaScript identifier.\n */\nexport function isValidIdentifier(value: string): boolean {\n return /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(value);\n}\n\n/**\n * Returns whether the identifier is reserved in JavaScript source.\n */\nexport function isReservedWord(value: string): boolean {\n return RESERVED_WORDS.has(value);\n}\n\n/**\n * Throws when the value cannot be used as a bare JavaScript identifier.\n */\nexport function assertValidIdentifier(\n value: string,\n label = \"identifier\",\n): void {\n if (!isValidIdentifier(value) || isReservedWord(value)) {\n throw new Error(`Invalid ${label}: ${value}`);\n }\n}\n\n/**\n * Converts a raw identifier-like value into a safe JavaScript identifier.\n */\nexport function sanitizeIdentifier(value: string): string {\n const sanitized = value.trim().replace(/[^A-Za-z0-9_$]+/g, \"_\");\n\n const trimmed = trimEdgeUnderscores(sanitized);\n\n let safeName = trimmed.length > 0 ? trimmed : \"_\";\n\n if (/^[0-9]/.test(safeName)) {\n safeName = `_${safeName}`;\n }\n\n if (isReservedWord(safeName)) {\n safeName = `${safeName}_`;\n }\n\n return safeName;\n}\n\n/**\n * Renders the name as a bare identifier when possible, otherwise as a string literal.\n */\nexport function serializePropertyName(name: string): string {\n return isValidIdentifier(name) ? name : JSON.stringify(name);\n}\n","import { sanitizeIdentifier } from \"./identifier\";\n\n/**\n * Converts a raw tool name into a safe JavaScript identifier.\n */\nexport function sanitizeToolName(name: string): string {\n return sanitizeIdentifier(name);\n}\n","import * as zod from \"zod\";\nimport type { ZodRawShape, ZodTypeAny } from \"zod\";\n\nimport type { JsonSchema, ToolSchema } from \"../types\";\n\nconst z = \"z\" in zod && typeof zod.z === \"object\" ? zod.z : zod;\nconst toJsonSchema =\n (\"toJSONSchema\" in zod ? zod.toJSONSchema : undefined) ??\n (\"toJSONSchema\" in z ? z.toJSONSchema : undefined);\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === \"object\" && value !== null;\n}\n\nfunction isZodSchema(value: unknown): value is ZodTypeAny {\n return isRecord(value) && typeof value.safeParse === \"function\";\n}\n\nfunction isZodRawShape(value: unknown): value is ZodRawShape {\n return (\n isRecord(value) &&\n Object.keys(value).length > 0 &&\n Object.values(value).every(isZodSchema)\n );\n}\n\nfunction normalizeZodSchema(schema: ZodTypeAny): JsonSchema {\n if (typeof toJsonSchema !== \"function\") {\n throw new Error(\"Installed zod package does not expose toJSONSchema\");\n }\n\n const jsonSchema = toJsonSchema(schema) as JsonSchema & {\n $schema?: string;\n };\n\n if (\"$schema\" in jsonSchema) {\n const { $schema: _ignored, ...rest } = jsonSchema;\n return rest;\n }\n\n return jsonSchema;\n}\n\n/**\n * Normalizes supported tool schema inputs to the JSON Schema form used internally.\n */\nexport function normalizeToolSchema(\n schema: ToolSchema | undefined,\n phase: \"input\" | \"output\",\n toolName: string,\n): JsonSchema | undefined {\n if (schema === undefined) {\n return undefined;\n }\n\n if (isZodSchema(schema)) {\n return normalizeZodSchema(schema);\n }\n\n if (isZodRawShape(schema)) {\n return normalizeZodSchema(z.object(schema));\n }\n\n if (isRecord(schema)) {\n return schema;\n }\n\n throw new Error(\n `Unsupported ${phase} schema for tool ${toolName}. Expected JSON Schema, a Zod schema, or an MCP-style Zod shape.`,\n );\n}\n","/**\n * Indents each line of the given string by a specified number of levels.\n */\nexport function indent(value: string, level = 1): string {\n return value\n .split(\"\\n\")\n .map((line) => `${\" \".repeat(level)}${line}`)\n .join(\"\\n\");\n}\n\n/**\n * Renders a short TSDoc-style block when documentation is available.\n */\nexport function renderDocComment(lines: string[]): string {\n if (lines.length === 0) {\n return \"\";\n }\n\n return [\"/**\", ...lines.map((line) => ` * ${line}`), \" */\"].join(\"\\n\");\n}\n\n/**\n * Renders a namespace declaration with optional members.\n */\nexport function renderNamespaceDeclaration(\n name: string,\n members: string[],\n): string {\n if (members.length === 0) {\n return `declare namespace ${name} {}`;\n }\n\n return `declare namespace ${name} {\\n${indent(members.join(\"\\n\\n\"))}\\n}`;\n}\n","import { isValidIdentifier, serializePropertyName } from \"../identifier\";\nimport type { JsonSchema, TypegenToolDescriptor } from \"../types\";\nimport { indent, renderDocComment, renderNamespaceDeclaration } from \"./render\";\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === \"object\" && value !== null;\n}\n\nexport { indent } from \"./render\";\n\n/**\n * Converts a supported JSON Schema fragment into a TypeScript type expression.\n */\nexport function schemaToType(\n schema: JsonSchema | undefined,\n level = 0,\n): string {\n if (!schema) {\n return \"unknown\";\n }\n\n if (\n \"allOf\" in schema ||\n \"anyOf\" in schema ||\n \"oneOf\" in schema ||\n \"$ref\" in schema ||\n Array.isArray(schema.type)\n ) {\n return \"unknown\";\n }\n\n switch (schema.type) {\n case \"string\":\n return \"string\";\n case \"number\":\n case \"integer\":\n return \"number\";\n case \"boolean\":\n return \"boolean\";\n case \"null\":\n return \"null\";\n case \"array\": {\n const itemType = schemaToType(\n isRecord(schema.items) ? (schema.items as JsonSchema) : undefined,\n level + 1,\n );\n\n if (isValidIdentifier(itemType)) {\n return `${itemType}[]`;\n }\n\n return `Array<${itemType}>`;\n }\n case \"object\": {\n const properties = isRecord(schema.properties) ? schema.properties : {};\n const required = new Set(\n Array.isArray(schema.required)\n ? schema.required.filter(\n (value): value is string => typeof value === \"string\",\n )\n : [],\n );\n const entries = Object.entries(properties);\n\n if (entries.length === 0) {\n return \"Record<string, unknown>\";\n }\n\n const lines = entries.map(([name, propertySchema]) => {\n const propertyType = schemaToType(\n isRecord(propertySchema) ? (propertySchema as JsonSchema) : undefined,\n level + 1,\n );\n const optionalToken = required.has(name) ? \"\" : \"?\";\n return `${serializePropertyName(name)}${optionalToken}: ${propertyType};`;\n });\n\n return `{\\n${indent(lines.join(\"\\n\"), level + 1)}\\n${\" \".repeat(level)}}`;\n }\n default:\n return \"unknown\";\n }\n}\n\nfunction formatToolDeclaration(\n name: string,\n tool: TypegenToolDescriptor,\n): string {\n const lines: string[] = [];\n const comment = tool.description ? renderDocComment([tool.description]) : \"\";\n if (comment) {\n lines.push(comment);\n }\n\n const inputType = schemaToType(tool.inputSchema);\n const outputType = schemaToType(tool.outputSchema);\n lines.push(`function ${name}(input: ${inputType}): Promise<${outputType}>;`);\n\n return lines.join(\"\\n\");\n}\n\n/**\n * Generates a namespace declaration for a provider's tool schemas.\n */\nexport function generateTypesFromJsonSchema(\n providerName: string,\n tools: Record<string, TypegenToolDescriptor>,\n): string {\n return renderNamespaceDeclaration(\n providerName,\n Object.entries(tools).map(([name, tool]) =>\n formatToolDeclaration(name, tool),\n ),\n );\n}\n","import Ajv, { type AnySchemaObject, type ValidateFunction } from \"ajv\";\n\nimport {\n ExecuteFailure,\n isExecuteFailure,\n isJsonSerializable,\n} from \"../errors\";\nimport { assertValidIdentifier } from \"../identifier\";\nimport { sanitizeToolName } from \"../sanitize\";\nimport { normalizeToolSchema } from \"../schema/normalizeSchema\";\nimport { generateTypesFromJsonSchema } from \"../typegen/jsonSchema\";\nimport type {\n JsonSchema,\n ResolvedToolDescriptor,\n ResolvedToolProvider,\n ToolExecutionContext,\n ToolProvider,\n TypegenToolDescriptor,\n} from \"../types\";\n\nconst DEFAULT_PROVIDER_NAME = \"codemode\";\nfunction assertValidNamespace(name: string): void {\n assertValidIdentifier(name, \"provider namespace\");\n}\n\nfunction compileValidator(\n ajv: Ajv,\n schema: JsonSchema | undefined,\n): ValidateFunction | undefined {\n return schema ? ajv.compile(schema as AnySchemaObject) : undefined;\n}\n\nfunction formatValidationMessage(\n ajv: Ajv,\n phase: \"input\" | \"output\",\n toolName: string,\n validator: ValidateFunction,\n): string {\n return `Invalid ${phase} for tool ${toolName}: ${ajv.errorsText(validator.errors)}`;\n}\n\n/**\n * Resolves a tool provider into the validated, sanitized shape consumed by executors.\n */\nexport function resolveProvider(provider: ToolProvider): ResolvedToolProvider {\n const name = provider.name ?? DEFAULT_PROVIDER_NAME;\n assertValidNamespace(name);\n\n // strict: false allows schemas with extra keywords (e.g. Zod-generated $schema)\n // that don't conform to the strict JSON Schema vocabulary.\n const ajv = new Ajv({\n allErrors: true,\n strict: false,\n });\n\n const originalToSafeName: Record<string, string> = {};\n const safeToOriginalName: Record<string, string> = {};\n const usedSafeNames = new Set<string>();\n const resolvedTools: Record<string, ResolvedToolDescriptor> = {};\n const typegenTools: Record<string, TypegenToolDescriptor> = {};\n\n for (const [originalName, descriptor] of Object.entries(provider.tools)) {\n const baseSafeName = sanitizeToolName(originalName);\n let safeName = baseSafeName;\n let suffix = 2;\n\n while (usedSafeNames.has(safeName)) {\n safeName = `${baseSafeName}__${suffix}`;\n suffix += 1;\n }\n\n usedSafeNames.add(safeName);\n originalToSafeName[originalName] = safeName;\n safeToOriginalName[safeName] = originalName;\n\n const inputSchema = normalizeToolSchema(\n descriptor.inputSchema,\n \"input\",\n originalName,\n );\n const outputSchema = normalizeToolSchema(\n descriptor.outputSchema,\n \"output\",\n originalName,\n );\n const inputValidator = compileValidator(ajv, inputSchema);\n const outputValidator = compileValidator(ajv, outputSchema);\n\n resolvedTools[safeName] = {\n description: descriptor.description,\n execute: async (\n input: unknown,\n context: ToolExecutionContext,\n ): Promise<unknown> => {\n if (inputValidator && !inputValidator(input)) {\n throw new ExecuteFailure(\n \"validation_error\",\n formatValidationMessage(ajv, \"input\", originalName, inputValidator),\n );\n }\n\n try {\n const result = await descriptor.execute(input, context);\n\n if (!isJsonSerializable(result)) {\n throw new ExecuteFailure(\n \"serialization_error\",\n `Tool ${originalName} returned a non-serializable value`,\n );\n }\n\n if (outputValidator && !outputValidator(result)) {\n throw new ExecuteFailure(\n \"validation_error\",\n formatValidationMessage(\n ajv,\n \"output\",\n originalName,\n outputValidator,\n ),\n );\n }\n\n return result;\n } catch (error) {\n if (isExecuteFailure(error)) {\n throw error;\n }\n\n throw new ExecuteFailure(\n \"tool_error\",\n error instanceof Error\n ? error.message\n : `Tool ${originalName} failed`,\n );\n }\n },\n inputSchema,\n originalName,\n outputSchema,\n safeName,\n };\n\n typegenTools[safeName] = {\n description: descriptor.description,\n inputSchema,\n outputSchema,\n };\n }\n\n return {\n name,\n originalToSafeName,\n safeToOriginalName,\n tools: resolvedTools,\n types: provider.types ?? generateTypesFromJsonSchema(name, typegenTools),\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,MAAM,iBAAiB,IAAI,IAAI;CAC7B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD,CAAC;AAEF,MAAM,uBAAuB;AAE7B,SAAS,oBAAoB,OAAuB;CAClD,IAAI,QAAQ;CACZ,IAAI,MAAM,MAAM;AAEhB,QAAO,QAAQ,OAAO,MAAM,WAAW,MAAM,KAAK,qBAChD,UAAS;AAGX,QAAO,MAAM,SAAS,MAAM,WAAW,MAAM,EAAE,KAAK,qBAClD,QAAO;AAGT,QAAO,MAAM,MAAM,OAAO,IAAI;;;;;AAMhC,SAAgB,kBAAkB,OAAwB;AACxD,QAAO,6BAA6B,KAAK,MAAM;;;;;AAMjD,SAAgB,eAAe,OAAwB;AACrD,QAAO,eAAe,IAAI,MAAM;;;;;AAMlC,SAAgB,sBACd,OACA,QAAQ,cACF;AACN,KAAI,CAAC,kBAAkB,MAAM,IAAI,eAAe,MAAM,CACpD,OAAM,IAAI,MAAM,WAAW,MAAM,IAAI,QAAQ;;;;;AAOjD,SAAgB,mBAAmB,OAAuB;CAGxD,MAAM,UAAU,oBAFE,MAAM,MAAM,CAAC,QAAQ,oBAAoB,IAAI,CAEjB;CAE9C,IAAI,WAAW,QAAQ,SAAS,IAAI,UAAU;AAE9C,KAAI,SAAS,KAAK,SAAS,CACzB,YAAW,IAAI;AAGjB,KAAI,eAAe,SAAS,CAC1B,YAAW,GAAG,SAAS;AAGzB,QAAO;;;;;AAMT,SAAgB,sBAAsB,MAAsB;AAC1D,QAAO,kBAAkB,K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AAQ,SAAS,MAAM,EAAE;EACvE,MAAM,eAAe,iBAAiB,aAAa;EACnD,IAAI,WAAW;EACf,IAAI,SAAS;AAEb,SAAO,cAAc,IAAI,SAAS,EAAE;AAClC,cAAW,GAAG,aAAa,IAAI;AAC/B,aAAU;;AAGZ,gBAAc,IAAI,SAAS;AAC3B,qBAAmB,gBAAgB;AACnC,qBAAmB,YAAY;EAE/B,MAAM,cAAc,oBAClB,WAAW,aACX,SACA,aACD;EACD,MAAM,eAAe,oBACnB,WAAW,cACX,UACA,aACD;EACD,MAAM,iBAAiB,iBAAiBL,OAAK,YAAY;EACzD,MAAM,kBAAkB,iBAAiBA,OAAK,aAAa;AAE3D,gBAAc,YAAY;GACxB,aAAa,WAAW;GACxB,SAAS,OACP,OACA,YACqB;AACrB,QAAI,kBAAkB,CAAC,eAAe,MAAM,CAC1C,OAAM,IAAIM,8BACR,oBACA,wBAAwBN,OAAK,SAAS,cAAc,eAAe,CACpE;AAGH,QAAI;KACF,MAAM,SAAS,MAAM,WAAW,QAAQ,OAAO,QAAQ;AAEvD,SAAI,CAACO,kCAAmB,OAAO,CAC7B,OAAM,IAAID,8BACR,uBACA,QAAQ,aAAa,oCACtB;AAGH,SAAI,mBAAmB,CAAC,gBAAgB,OAAO,CAC7C,OAAM,IAAIA,8BACR,oBACA,wBACEN,OACA,UACA,cACA,gBACD,CACF;AAGH,YAAO;aACA,OAAO;AACd,SAAIQ,gCAAiB,MAAM,CACzB,OAAM;AAGR,WAAM,IAAIF,8BACR,cACA,iBAAiB,QACb,MAAM,UACN,QAAQ,aAAa,SAC1B;;;GAGL;GACA;GACA;GACA;GACD;AAED,eAAa,YAAY;GACvB,aAAa,WAAW;GACxB;GACA;GACD;;AAGH,QAAO;EACL;EACA;EACA;EACA,OAAO;EACP,OAAO,SAAS,SAAS,4BAA4B,MAAM,aAAa;EACzE"}
1
+ {"version":3,"file":"resolveProvider-BZYSw8Qk.cjs","names":["isRecord","lines: string[]","ajv","Ajv","originalToSafeName: Record<string, string>","safeToOriginalName: Record<string, string>","resolvedTools: Record<string, ResolvedToolDescriptor>","typegenTools: Record<string, TypegenToolDescriptor>","ExecuteFailure","isJsonSerializable","isExecuteFailure"],"sources":["../src/identifier.ts","../src/sanitize.ts","../src/schema/normalizeSchema.ts","../src/typegen/render.ts","../src/typegen/jsonSchema.ts","../src/provider/resolveProvider.ts"],"sourcesContent":["const RESERVED_WORDS = new Set([\n \"await\",\n \"break\",\n \"case\",\n \"catch\",\n \"class\",\n \"const\",\n \"continue\",\n \"debugger\",\n \"default\",\n \"delete\",\n \"do\",\n \"else\",\n \"enum\",\n \"export\",\n \"extends\",\n \"false\",\n \"finally\",\n \"for\",\n \"function\",\n \"if\",\n \"import\",\n \"in\",\n \"instanceof\",\n \"new\",\n \"null\",\n \"return\",\n \"super\",\n \"switch\",\n \"this\",\n \"throw\",\n \"true\",\n \"try\",\n \"typeof\",\n \"var\",\n \"void\",\n \"while\",\n \"with\",\n \"yield\",\n]);\n\nconst UNDERSCORE_CHAR_CODE = 95;\n\nfunction trimEdgeUnderscores(value: string): string {\n let start = 0;\n let end = value.length;\n\n while (start < end && value.charCodeAt(start) === UNDERSCORE_CHAR_CODE) {\n start += 1;\n }\n\n while (end > start && value.charCodeAt(end - 1) === UNDERSCORE_CHAR_CODE) {\n end -= 1;\n }\n\n return value.slice(start, end);\n}\n\n/**\n * Returns whether the value is a valid JavaScript identifier.\n */\nexport function isValidIdentifier(value: string): boolean {\n return /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(value);\n}\n\n/**\n * Returns whether the identifier is reserved in JavaScript source.\n */\nexport function isReservedWord(value: string): boolean {\n return RESERVED_WORDS.has(value);\n}\n\n/**\n * Throws when the value cannot be used as a bare JavaScript identifier.\n */\nexport function assertValidIdentifier(\n value: string,\n label = \"identifier\",\n): void {\n if (!isValidIdentifier(value) || isReservedWord(value)) {\n throw new Error(`Invalid ${label}: ${value}`);\n }\n}\n\n/**\n * Converts a raw identifier-like value into a safe JavaScript identifier.\n */\nexport function sanitizeIdentifier(value: string): string {\n const sanitized = value.trim().replace(/[^A-Za-z0-9_$]+/g, \"_\");\n\n const trimmed = trimEdgeUnderscores(sanitized);\n\n let safeName = trimmed.length > 0 ? trimmed : \"_\";\n\n if (/^[0-9]/.test(safeName)) {\n safeName = `_${safeName}`;\n }\n\n if (isReservedWord(safeName)) {\n safeName = `${safeName}_`;\n }\n\n return safeName;\n}\n\n/**\n * Renders the name as a bare identifier when possible, otherwise as a string literal.\n */\nexport function serializePropertyName(name: string): string {\n return isValidIdentifier(name) ? name : JSON.stringify(name);\n}\n","import { sanitizeIdentifier } from \"./identifier\";\n\n/**\n * Converts a raw tool name into a safe JavaScript identifier.\n */\nexport function sanitizeToolName(name: string): string {\n return sanitizeIdentifier(name);\n}\n","import * as zod from \"zod\";\nimport type { ZodRawShape, ZodTypeAny } from \"zod\";\n\nimport type { JsonSchema, ToolSchema } from \"../types\";\n\nconst z = \"z\" in zod && typeof zod.z === \"object\" ? zod.z : zod;\nconst toJsonSchema =\n (\"toJSONSchema\" in zod ? zod.toJSONSchema : undefined) ??\n (\"toJSONSchema\" in z ? z.toJSONSchema : undefined);\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === \"object\" && value !== null;\n}\n\nfunction isZodSchema(value: unknown): value is ZodTypeAny {\n return isRecord(value) && typeof value.safeParse === \"function\";\n}\n\nfunction isZodRawShape(value: unknown): value is ZodRawShape {\n return (\n isRecord(value) &&\n Object.keys(value).length > 0 &&\n Object.values(value).every(isZodSchema)\n );\n}\n\nfunction normalizeZodSchema(schema: ZodTypeAny): JsonSchema {\n if (typeof toJsonSchema !== \"function\") {\n throw new Error(\"Installed zod package does not expose toJSONSchema\");\n }\n\n const jsonSchema = toJsonSchema(schema) as JsonSchema & {\n $schema?: string;\n };\n\n if (\"$schema\" in jsonSchema) {\n const { $schema: _ignored, ...rest } = jsonSchema;\n return rest;\n }\n\n return jsonSchema;\n}\n\n/**\n * Normalizes supported tool schema inputs to the JSON Schema form used internally.\n */\nexport function normalizeToolSchema(\n schema: ToolSchema | undefined,\n phase: \"input\" | \"output\",\n toolName: string,\n): JsonSchema | undefined {\n if (schema === undefined) {\n return undefined;\n }\n\n if (isZodSchema(schema)) {\n return normalizeZodSchema(schema);\n }\n\n if (isZodRawShape(schema)) {\n return normalizeZodSchema(z.object(schema));\n }\n\n if (isRecord(schema)) {\n return schema;\n }\n\n throw new Error(\n `Unsupported ${phase} schema for tool ${toolName}. Expected JSON Schema, a Zod schema, or an MCP-style Zod shape.`,\n );\n}\n","/**\n * Indents each line of the given string by a specified number of levels.\n */\nexport function indent(value: string, level = 1): string {\n return value\n .split(\"\\n\")\n .map((line) => `${\" \".repeat(level)}${line}`)\n .join(\"\\n\");\n}\n\n/**\n * Renders a short TSDoc-style block when documentation is available.\n */\nexport function renderDocComment(lines: string[]): string {\n if (lines.length === 0) {\n return \"\";\n }\n\n return [\"/**\", ...lines.map((line) => ` * ${line}`), \" */\"].join(\"\\n\");\n}\n\n/**\n * Renders a namespace declaration with optional members.\n */\nexport function renderNamespaceDeclaration(\n name: string,\n members: string[],\n): string {\n if (members.length === 0) {\n return `declare namespace ${name} {}`;\n }\n\n return `declare namespace ${name} {\\n${indent(members.join(\"\\n\\n\"))}\\n}`;\n}\n","import { isValidIdentifier, serializePropertyName } from \"../identifier\";\nimport type { JsonSchema, TypegenToolDescriptor } from \"../types\";\nimport { indent, renderDocComment, renderNamespaceDeclaration } from \"./render\";\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === \"object\" && value !== null;\n}\n\nexport { indent } from \"./render\";\n\n/**\n * Converts a supported JSON Schema fragment into a TypeScript type expression.\n */\nexport function schemaToType(\n schema: JsonSchema | undefined,\n level = 0,\n): string {\n if (!schema) {\n return \"unknown\";\n }\n\n if (\n \"allOf\" in schema ||\n \"anyOf\" in schema ||\n \"oneOf\" in schema ||\n \"$ref\" in schema ||\n Array.isArray(schema.type)\n ) {\n return \"unknown\";\n }\n\n switch (schema.type) {\n case \"string\":\n return \"string\";\n case \"number\":\n case \"integer\":\n return \"number\";\n case \"boolean\":\n return \"boolean\";\n case \"null\":\n return \"null\";\n case \"array\": {\n const itemType = schemaToType(\n isRecord(schema.items) ? (schema.items as JsonSchema) : undefined,\n level + 1,\n );\n\n if (isValidIdentifier(itemType)) {\n return `${itemType}[]`;\n }\n\n return `Array<${itemType}>`;\n }\n case \"object\": {\n const properties = isRecord(schema.properties) ? schema.properties : {};\n const required = new Set(\n Array.isArray(schema.required)\n ? schema.required.filter(\n (value): value is string => typeof value === \"string\",\n )\n : [],\n );\n const entries = Object.entries(properties);\n\n if (entries.length === 0) {\n return \"Record<string, unknown>\";\n }\n\n const lines = entries.map(([name, propertySchema]) => {\n const propertyType = schemaToType(\n isRecord(propertySchema) ? (propertySchema as JsonSchema) : undefined,\n level + 1,\n );\n const optionalToken = required.has(name) ? \"\" : \"?\";\n return `${serializePropertyName(name)}${optionalToken}: ${propertyType};`;\n });\n\n return `{\\n${indent(lines.join(\"\\n\"), level + 1)}\\n${\" \".repeat(level)}}`;\n }\n default:\n return \"unknown\";\n }\n}\n\nfunction formatToolDeclaration(\n name: string,\n tool: TypegenToolDescriptor,\n): string {\n const lines: string[] = [];\n const comment = tool.description ? renderDocComment([tool.description]) : \"\";\n if (comment) {\n lines.push(comment);\n }\n\n const inputType = schemaToType(tool.inputSchema);\n const outputType = schemaToType(tool.outputSchema);\n lines.push(`function ${name}(input: ${inputType}): Promise<${outputType}>;`);\n\n return lines.join(\"\\n\");\n}\n\n/**\n * Generates a namespace declaration for a provider's tool schemas.\n */\nexport function generateTypesFromJsonSchema(\n providerName: string,\n tools: Record<string, TypegenToolDescriptor>,\n): string {\n return renderNamespaceDeclaration(\n providerName,\n Object.entries(tools).map(([name, tool]) =>\n formatToolDeclaration(name, tool),\n ),\n );\n}\n","import Ajv, { type AnySchemaObject, type ValidateFunction } from \"ajv\";\n\nimport {\n ExecuteFailure,\n isExecuteFailure,\n isJsonSerializable,\n} from \"../errors\";\nimport { assertValidIdentifier } from \"../identifier\";\nimport { sanitizeToolName } from \"../sanitize\";\nimport { normalizeToolSchema } from \"../schema/normalizeSchema\";\nimport { generateTypesFromJsonSchema } from \"../typegen/jsonSchema\";\nimport type {\n JsonSchema,\n ResolvedToolDescriptor,\n ResolvedToolProvider,\n ToolExecutionContext,\n ToolProvider,\n TypegenToolDescriptor,\n} from \"../types\";\n\nconst DEFAULT_PROVIDER_NAME = \"codemode\";\nfunction assertValidNamespace(name: string): void {\n assertValidIdentifier(name, \"provider namespace\");\n}\n\nfunction compileValidator(\n ajv: Ajv,\n schema: JsonSchema | undefined,\n): ValidateFunction | undefined {\n return schema ? ajv.compile(schema as AnySchemaObject) : undefined;\n}\n\nfunction formatValidationMessage(\n ajv: Ajv,\n phase: \"input\" | \"output\",\n toolName: string,\n validator: ValidateFunction,\n): string {\n return `Invalid ${phase} for tool ${toolName}: ${ajv.errorsText(validator.errors)}`;\n}\n\n/**\n * Resolves a tool provider into the validated, sanitized shape consumed by executors.\n */\nexport function resolveProvider(provider: ToolProvider): ResolvedToolProvider {\n const name = provider.name ?? DEFAULT_PROVIDER_NAME;\n assertValidNamespace(name);\n\n // strict: false allows schemas with extra keywords (e.g. Zod-generated $schema)\n // that don't conform to the strict JSON Schema vocabulary.\n const ajv = new Ajv({\n allErrors: true,\n strict: false,\n });\n\n const originalToSafeName: Record<string, string> = {};\n const safeToOriginalName: Record<string, string> = {};\n const usedSafeNames = new Set<string>();\n const resolvedTools: Record<string, ResolvedToolDescriptor> = {};\n const typegenTools: Record<string, TypegenToolDescriptor> = {};\n\n for (const [originalName, descriptor] of Object.entries(provider.tools)) {\n const baseSafeName = sanitizeToolName(originalName);\n let safeName = baseSafeName;\n let suffix = 2;\n\n while (usedSafeNames.has(safeName)) {\n safeName = `${baseSafeName}__${suffix}`;\n suffix += 1;\n }\n\n usedSafeNames.add(safeName);\n originalToSafeName[originalName] = safeName;\n safeToOriginalName[safeName] = originalName;\n\n const inputSchema = normalizeToolSchema(\n descriptor.inputSchema,\n \"input\",\n originalName,\n );\n const outputSchema = normalizeToolSchema(\n descriptor.outputSchema,\n \"output\",\n originalName,\n );\n const inputValidator = compileValidator(ajv, inputSchema);\n const outputValidator = compileValidator(ajv, outputSchema);\n\n resolvedTools[safeName] = {\n description: descriptor.description,\n execute: async (\n input: unknown,\n context: ToolExecutionContext,\n ): Promise<unknown> => {\n if (inputValidator && !inputValidator(input)) {\n throw new ExecuteFailure(\n \"validation_error\",\n formatValidationMessage(ajv, \"input\", originalName, inputValidator),\n );\n }\n\n try {\n const result = await descriptor.execute(input, context);\n\n if (!isJsonSerializable(result)) {\n throw new ExecuteFailure(\n \"serialization_error\",\n `Tool ${originalName} returned a non-serializable value`,\n );\n }\n\n if (outputValidator && !outputValidator(result)) {\n throw new ExecuteFailure(\n \"validation_error\",\n formatValidationMessage(\n ajv,\n \"output\",\n originalName,\n outputValidator,\n ),\n );\n }\n\n return result;\n } catch (error) {\n if (isExecuteFailure(error)) {\n throw error;\n }\n\n throw new ExecuteFailure(\n \"tool_error\",\n error instanceof Error\n ? error.message\n : `Tool ${originalName} failed`,\n );\n }\n },\n inputSchema,\n originalName,\n outputSchema,\n safeName,\n };\n\n typegenTools[safeName] = {\n description: descriptor.description,\n inputSchema,\n outputSchema,\n };\n }\n\n return {\n name,\n originalToSafeName,\n safeToOriginalName,\n tools: resolvedTools,\n types: provider.types ?? generateTypesFromJsonSchema(name, typegenTools),\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,MAAM,iBAAiB,IAAI,IAAI;CAC7B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD,CAAC;AAEF,MAAM,uBAAuB;AAE7B,SAAS,oBAAoB,O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D,gBAAc,YAAY;GACxB,aAAa,WAAW;GACxB,SAAS,OACP,OACA,YACqB;AACrB,QAAI,kBAAkB,CAAC,eAAe,MAAM,CAC1C,OAAM,IAAIM,8BACR,oBACA,wBAAwBN,OAAK,SAAS,cAAc,eAAe,CACpE;AAGH,QAAI;KACF,MAAM,SAAS,MAAM,WAAW,QAAQ,OAAO,QAAQ;AAEvD,SAAI,CAACO,kCAAmB,OAAO,CAC7B,OAAM,IAAID,8BACR,uBACA,QAAQ,aAAa,oCACtB;AAGH,SAAI,mBAAmB,CAAC,gBAAgB,OAAO,CAC7C,OAAM,IAAIA,8BACR,oBACA,wBACEN,OACA,UACA,cACA,gBACD,CACF;AAGH,YAAO;aACA,OAAO;AACd,SAAIQ,gCAAiB,MAAM,CACzB,OAAM;AAGR,WAAM,IAAIF,8BACR,cACA,iBAAiB,QACb,MAAM,UACN,QAAQ,aAAa,SAC1B;;;GAGL;GACA;GACA;GACA;GACD;AAED,eAAa,YAAY;GACvB,aAAa,WAAW;GACxB;GACA;GACD;;AAGH,QAAO;EACL;EACA;EACA;EACA,OAAO;EACP,OAAO,SAAS,SAAS,4BAA4B,MAAM,aAAa;EACzE"}
@@ -1,4 +1,4 @@
1
- import { n as isExecuteFailure, r as isJsonSerializable, t as ExecuteFailure } from "./errors-BXpyBhCI.js";
1
+ import { n as isExecuteFailure, r as isJsonSerializable, t as ExecuteFailure } from "./errors-wS8yjQhS.js";
2
2
  import Ajv from "ajv";
3
3
  import * as zod from "zod";
4
4
 
@@ -285,4 +285,4 @@ function resolveProvider(provider) {
285
285
 
286
286
  //#endregion
287
287
  export { renderNamespaceDeclaration as a, isReservedWord as c, serializePropertyName as d, renderDocComment as i, isValidIdentifier as l, generateTypesFromJsonSchema as n, sanitizeToolName as o, schemaToType as r, assertValidIdentifier as s, resolveProvider as t, sanitizeIdentifier as u };
288
- //# sourceMappingURL=resolveProvider-BHuwOGBm.js.map
288
+ //# sourceMappingURL=resolveProvider-UqQxdF4j.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"resolveProvider-BHuwOGBm.js","names":["isRecord","lines: string[]","originalToSafeName: Record<string, string>","safeToOriginalName: Record<string, string>","resolvedTools: Record<string, ResolvedToolDescriptor>","typegenTools: Record<string, TypegenToolDescriptor>"],"sources":["../src/identifier.ts","../src/sanitize.ts","../src/schema/normalizeSchema.ts","../src/typegen/render.ts","../src/typegen/jsonSchema.ts","../src/provider/resolveProvider.ts"],"sourcesContent":["const RESERVED_WORDS = new Set([\n \"await\",\n \"break\",\n \"case\",\n \"catch\",\n \"class\",\n \"const\",\n \"continue\",\n \"debugger\",\n \"default\",\n \"delete\",\n \"do\",\n \"else\",\n \"enum\",\n \"export\",\n \"extends\",\n \"false\",\n \"finally\",\n \"for\",\n \"function\",\n \"if\",\n \"import\",\n \"in\",\n \"instanceof\",\n \"new\",\n \"null\",\n \"return\",\n \"super\",\n \"switch\",\n \"this\",\n \"throw\",\n \"true\",\n \"try\",\n \"typeof\",\n \"var\",\n \"void\",\n \"while\",\n \"with\",\n \"yield\",\n]);\n\nconst UNDERSCORE_CHAR_CODE = 95;\n\nfunction trimEdgeUnderscores(value: string): string {\n let start = 0;\n let end = value.length;\n\n while (start < end && value.charCodeAt(start) === UNDERSCORE_CHAR_CODE) {\n start += 1;\n }\n\n while (end > start && value.charCodeAt(end - 1) === UNDERSCORE_CHAR_CODE) {\n end -= 1;\n }\n\n return value.slice(start, end);\n}\n\n/**\n * Returns whether the value is a valid JavaScript identifier.\n */\nexport function isValidIdentifier(value: string): boolean {\n return /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(value);\n}\n\n/**\n * Returns whether the identifier is reserved in JavaScript source.\n */\nexport function isReservedWord(value: string): boolean {\n return RESERVED_WORDS.has(value);\n}\n\n/**\n * Throws when the value cannot be used as a bare JavaScript identifier.\n */\nexport function assertValidIdentifier(\n value: string,\n label = \"identifier\",\n): void {\n if (!isValidIdentifier(value) || isReservedWord(value)) {\n throw new Error(`Invalid ${label}: ${value}`);\n }\n}\n\n/**\n * Converts a raw identifier-like value into a safe JavaScript identifier.\n */\nexport function sanitizeIdentifier(value: string): string {\n const sanitized = value.trim().replace(/[^A-Za-z0-9_$]+/g, \"_\");\n\n const trimmed = trimEdgeUnderscores(sanitized);\n\n let safeName = trimmed.length > 0 ? trimmed : \"_\";\n\n if (/^[0-9]/.test(safeName)) {\n safeName = `_${safeName}`;\n }\n\n if (isReservedWord(safeName)) {\n safeName = `${safeName}_`;\n }\n\n return safeName;\n}\n\n/**\n * Renders the name as a bare identifier when possible, otherwise as a string literal.\n */\nexport function serializePropertyName(name: string): string {\n return isValidIdentifier(name) ? name : JSON.stringify(name);\n}\n","import { sanitizeIdentifier } from \"./identifier\";\n\n/**\n * Converts a raw tool name into a safe JavaScript identifier.\n */\nexport function sanitizeToolName(name: string): string {\n return sanitizeIdentifier(name);\n}\n","import * as zod from \"zod\";\nimport type { ZodRawShape, ZodTypeAny } from \"zod\";\n\nimport type { JsonSchema, ToolSchema } from \"../types\";\n\nconst z = \"z\" in zod && typeof zod.z === \"object\" ? zod.z : zod;\nconst toJsonSchema =\n (\"toJSONSchema\" in zod ? zod.toJSONSchema : undefined) ??\n (\"toJSONSchema\" in z ? z.toJSONSchema : undefined);\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === \"object\" && value !== null;\n}\n\nfunction isZodSchema(value: unknown): value is ZodTypeAny {\n return isRecord(value) && typeof value.safeParse === \"function\";\n}\n\nfunction isZodRawShape(value: unknown): value is ZodRawShape {\n return (\n isRecord(value) &&\n Object.keys(value).length > 0 &&\n Object.values(value).every(isZodSchema)\n );\n}\n\nfunction normalizeZodSchema(schema: ZodTypeAny): JsonSchema {\n if (typeof toJsonSchema !== \"function\") {\n throw new Error(\"Installed zod package does not expose toJSONSchema\");\n }\n\n const jsonSchema = toJsonSchema(schema) as JsonSchema & {\n $schema?: string;\n };\n\n if (\"$schema\" in jsonSchema) {\n const { $schema: _ignored, ...rest } = jsonSchema;\n return rest;\n }\n\n return jsonSchema;\n}\n\n/**\n * Normalizes supported tool schema inputs to the JSON Schema form used internally.\n */\nexport function normalizeToolSchema(\n schema: ToolSchema | undefined,\n phase: \"input\" | \"output\",\n toolName: string,\n): JsonSchema | undefined {\n if (schema === undefined) {\n return undefined;\n }\n\n if (isZodSchema(schema)) {\n return normalizeZodSchema(schema);\n }\n\n if (isZodRawShape(schema)) {\n return normalizeZodSchema(z.object(schema));\n }\n\n if (isRecord(schema)) {\n return schema;\n }\n\n throw new Error(\n `Unsupported ${phase} schema for tool ${toolName}. Expected JSON Schema, a Zod schema, or an MCP-style Zod shape.`,\n );\n}\n","/**\n * Indents each line of the given string by a specified number of levels.\n */\nexport function indent(value: string, level = 1): string {\n return value\n .split(\"\\n\")\n .map((line) => `${\" \".repeat(level)}${line}`)\n .join(\"\\n\");\n}\n\n/**\n * Renders a short TSDoc-style block when documentation is available.\n */\nexport function renderDocComment(lines: string[]): string {\n if (lines.length === 0) {\n return \"\";\n }\n\n return [\"/**\", ...lines.map((line) => ` * ${line}`), \" */\"].join(\"\\n\");\n}\n\n/**\n * Renders a namespace declaration with optional members.\n */\nexport function renderNamespaceDeclaration(\n name: string,\n members: string[],\n): string {\n if (members.length === 0) {\n return `declare namespace ${name} {}`;\n }\n\n return `declare namespace ${name} {\\n${indent(members.join(\"\\n\\n\"))}\\n}`;\n}\n","import { isValidIdentifier, serializePropertyName } from \"../identifier\";\nimport type { JsonSchema, TypegenToolDescriptor } from \"../types\";\nimport { indent, renderDocComment, renderNamespaceDeclaration } from \"./render\";\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === \"object\" && value !== null;\n}\n\nexport { indent } from \"./render\";\n\n/**\n * Converts a supported JSON Schema fragment into a TypeScript type expression.\n */\nexport function schemaToType(\n schema: JsonSchema | undefined,\n level = 0,\n): string {\n if (!schema) {\n return \"unknown\";\n }\n\n if (\n \"allOf\" in schema ||\n \"anyOf\" in schema ||\n \"oneOf\" in schema ||\n \"$ref\" in schema ||\n Array.isArray(schema.type)\n ) {\n return \"unknown\";\n }\n\n switch (schema.type) {\n case \"string\":\n return \"string\";\n case \"number\":\n case \"integer\":\n return \"number\";\n case \"boolean\":\n return \"boolean\";\n case \"null\":\n return \"null\";\n case \"array\": {\n const itemType = schemaToType(\n isRecord(schema.items) ? (schema.items as JsonSchema) : undefined,\n level + 1,\n );\n\n if (isValidIdentifier(itemType)) {\n return `${itemType}[]`;\n }\n\n return `Array<${itemType}>`;\n }\n case \"object\": {\n const properties = isRecord(schema.properties) ? schema.properties : {};\n const required = new Set(\n Array.isArray(schema.required)\n ? schema.required.filter(\n (value): value is string => typeof value === \"string\",\n )\n : [],\n );\n const entries = Object.entries(properties);\n\n if (entries.length === 0) {\n return \"Record<string, unknown>\";\n }\n\n const lines = entries.map(([name, propertySchema]) => {\n const propertyType = schemaToType(\n isRecord(propertySchema) ? (propertySchema as JsonSchema) : undefined,\n level + 1,\n );\n const optionalToken = required.has(name) ? \"\" : \"?\";\n return `${serializePropertyName(name)}${optionalToken}: ${propertyType};`;\n });\n\n return `{\\n${indent(lines.join(\"\\n\"), level + 1)}\\n${\" \".repeat(level)}}`;\n }\n default:\n return \"unknown\";\n }\n}\n\nfunction formatToolDeclaration(\n name: string,\n tool: TypegenToolDescriptor,\n): string {\n const lines: string[] = [];\n const comment = tool.description ? renderDocComment([tool.description]) : \"\";\n if (comment) {\n lines.push(comment);\n }\n\n const inputType = schemaToType(tool.inputSchema);\n const outputType = schemaToType(tool.outputSchema);\n lines.push(`function ${name}(input: ${inputType}): Promise<${outputType}>;`);\n\n return lines.join(\"\\n\");\n}\n\n/**\n * Generates a namespace declaration for a provider's tool schemas.\n */\nexport function generateTypesFromJsonSchema(\n providerName: string,\n tools: Record<string, TypegenToolDescriptor>,\n): string {\n return renderNamespaceDeclaration(\n providerName,\n Object.entries(tools).map(([name, tool]) =>\n formatToolDeclaration(name, tool),\n ),\n );\n}\n","import Ajv, { type AnySchemaObject, type ValidateFunction } from \"ajv\";\n\nimport {\n ExecuteFailure,\n isExecuteFailure,\n isJsonSerializable,\n} from \"../errors\";\nimport { assertValidIdentifier } from \"../identifier\";\nimport { sanitizeToolName } from \"../sanitize\";\nimport { normalizeToolSchema } from \"../schema/normalizeSchema\";\nimport { generateTypesFromJsonSchema } from \"../typegen/jsonSchema\";\nimport type {\n JsonSchema,\n ResolvedToolDescriptor,\n ResolvedToolProvider,\n ToolExecutionContext,\n ToolProvider,\n TypegenToolDescriptor,\n} from \"../types\";\n\nconst DEFAULT_PROVIDER_NAME = \"codemode\";\nfunction assertValidNamespace(name: string): void {\n assertValidIdentifier(name, \"provider namespace\");\n}\n\nfunction compileValidator(\n ajv: Ajv,\n schema: JsonSchema | undefined,\n): ValidateFunction | undefined {\n return schema ? ajv.compile(schema as AnySchemaObject) : undefined;\n}\n\nfunction formatValidationMessage(\n ajv: Ajv,\n phase: \"input\" | \"output\",\n toolName: string,\n validator: ValidateFunction,\n): string {\n return `Invalid ${phase} for tool ${toolName}: ${ajv.errorsText(validator.errors)}`;\n}\n\n/**\n * Resolves a tool provider into the validated, sanitized shape consumed by executors.\n */\nexport function resolveProvider(provider: ToolProvider): ResolvedToolProvider {\n const name = provider.name ?? DEFAULT_PROVIDER_NAME;\n assertValidNamespace(name);\n\n // strict: false allows schemas with extra keywords (e.g. Zod-generated $schema)\n // that don't conform to the strict JSON Schema vocabulary.\n const ajv = new Ajv({\n allErrors: true,\n strict: false,\n });\n\n const originalToSafeName: Record<string, string> = {};\n const safeToOriginalName: Record<string, string> = {};\n const usedSafeNames = new Set<string>();\n const resolvedTools: Record<string, ResolvedToolDescriptor> = {};\n const typegenTools: Record<string, TypegenToolDescriptor> = {};\n\n for (const [originalName, descriptor] of Object.entries(provider.tools)) {\n const baseSafeName = sanitizeToolName(originalName);\n let safeName = baseSafeName;\n let suffix = 2;\n\n while (usedSafeNames.has(safeName)) {\n safeName = `${baseSafeName}__${suffix}`;\n suffix += 1;\n }\n\n usedSafeNames.add(safeName);\n originalToSafeName[originalName] = safeName;\n safeToOriginalName[safeName] = originalName;\n\n const inputSchema = normalizeToolSchema(\n descriptor.inputSchema,\n \"input\",\n originalName,\n );\n const outputSchema = normalizeToolSchema(\n descriptor.outputSchema,\n \"output\",\n originalName,\n );\n const inputValidator = compileValidator(ajv, inputSchema);\n const outputValidator = compileValidator(ajv, outputSchema);\n\n resolvedTools[safeName] = {\n description: descriptor.description,\n execute: async (\n input: unknown,\n context: ToolExecutionContext,\n ): Promise<unknown> => {\n if (inputValidator && !inputValidator(input)) {\n throw new ExecuteFailure(\n \"validation_error\",\n formatValidationMessage(ajv, \"input\", originalName, inputValidator),\n );\n }\n\n try {\n const result = await descriptor.execute(input, context);\n\n if (!isJsonSerializable(result)) {\n throw new ExecuteFailure(\n \"serialization_error\",\n `Tool ${originalName} returned a non-serializable value`,\n );\n }\n\n if (outputValidator && !outputValidator(result)) {\n throw new ExecuteFailure(\n \"validation_error\",\n formatValidationMessage(\n ajv,\n \"output\",\n originalName,\n outputValidator,\n ),\n );\n }\n\n return result;\n } catch (error) {\n if (isExecuteFailure(error)) {\n throw error;\n }\n\n throw new ExecuteFailure(\n \"tool_error\",\n error instanceof Error\n ? error.message\n : `Tool ${originalName} failed`,\n );\n }\n },\n inputSchema,\n originalName,\n outputSchema,\n safeName,\n };\n\n typegenTools[safeName] = {\n description: descriptor.description,\n inputSchema,\n outputSchema,\n };\n }\n\n return {\n name,\n originalToSafeName,\n safeToOriginalName,\n tools: resolvedTools,\n types: provider.types ?? generateTypesFromJsonSchema(name, typegenTools),\n };\n}\n"],"mappings":";;;;;AAAA,MAAM,iBAAiB,IAAI,IAAI;CAC7B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD,CAAC;AAEF,MAAM,uBAAuB;AAE7B,SAAS,oB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3D,gBAAc,YAAY;GACxB,aAAa,WAAW;GACxB,SAAS,OACP,OACA,YACqB;AACrB,QAAI,kBAAkB,CAAC,eAAe,MAAM,CAC1C,OAAM,IAAI,eACR,oBACA,wBAAwB,KAAK,SAAS,cAAc,eAAe,CACpE;AAGH,QAAI;KACF,MAAM,SAAS,MAAM,WAAW,QAAQ,OAAO,QAAQ;AAEvD,SAAI,CAAC,mBAAmB,OAAO,CAC7B,OAAM,IAAI,eACR,uBACA,QAAQ,aAAa,oCACtB;AAGH,SAAI,mBAAmB,CAAC,gBAAgB,OAAO,CAC7C,OAAM,IAAI,eACR,oBACA,wBACE,KACA,UACA,cACA,gBACD,CACF;AAGH,YAAO;aACA,OAAO;AACd,SAAI,iBAAiB,MAAM,CACzB,OAAM;AAGR,WAAM,IAAI,eACR,cACA,iBAAiB,QACb,MAAM,UACN,QAAQ,aAAa,SAC1B;;;GAGL;GACA;GACA;GACA;GACD;AAED,eAAa,YAAY;GACvB,aAAa,WAAW;GACxB;GACA;GACD;;AAGH,QAAO;EACL;EACA;EACA;EACA,OAAO;EACP,OAAO,SAAS,SAAS,4BAA4B,MAAM,aAAa;EACzE"}
1
+ {"version":3,"file":"resolveProvider-UqQxdF4j.js","names":["isRecord","lines: string[]","originalToSafeName: Record<string, string>","safeToOriginalName: Record<string, string>","resolvedTools: Record<string, ResolvedToolDescriptor>","typegenTools: Record<string, TypegenToolDescriptor>"],"sources":["../src/identifier.ts","../src/sanitize.ts","../src/schema/normalizeSchema.ts","../src/typegen/render.ts","../src/typegen/jsonSchema.ts","../src/provider/resolveProvider.ts"],"sourcesContent":["const RESERVED_WORDS = new Set([\n \"await\",\n \"break\",\n \"case\",\n \"catch\",\n \"class\",\n \"const\",\n \"continue\",\n \"debugger\",\n \"default\",\n \"delete\",\n \"do\",\n \"else\",\n \"enum\",\n \"export\",\n \"extends\",\n \"false\",\n \"finally\",\n \"for\",\n \"function\",\n \"if\",\n \"import\",\n \"in\",\n \"instanceof\",\n \"new\",\n \"null\",\n \"return\",\n \"super\",\n \"switch\",\n \"this\",\n \"throw\",\n \"true\",\n \"try\",\n \"typeof\",\n \"var\",\n \"void\",\n \"while\",\n \"with\",\n \"yield\",\n]);\n\nconst UNDERSCORE_CHAR_CODE = 95;\n\nfunction trimEdgeUnderscores(value: string): string {\n let start = 0;\n let end = value.length;\n\n while (start < end && value.charCodeAt(start) === UNDERSCORE_CHAR_CODE) {\n start += 1;\n }\n\n while (end > start && value.charCodeAt(end - 1) === UNDERSCORE_CHAR_CODE) {\n end -= 1;\n }\n\n return value.slice(start, end);\n}\n\n/**\n * Returns whether the value is a valid JavaScript identifier.\n */\nexport function isValidIdentifier(value: string): boolean {\n return /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(value);\n}\n\n/**\n * Returns whether the identifier is reserved in JavaScript source.\n */\nexport function isReservedWord(value: string): boolean {\n return RESERVED_WORDS.has(value);\n}\n\n/**\n * Throws when the value cannot be used as a bare JavaScript identifier.\n */\nexport function assertValidIdentifier(\n value: string,\n label = \"identifier\",\n): void {\n if (!isValidIdentifier(value) || isReservedWord(value)) {\n throw new Error(`Invalid ${label}: ${value}`);\n }\n}\n\n/**\n * Converts a raw identifier-like value into a safe JavaScript identifier.\n */\nexport function sanitizeIdentifier(value: string): string {\n const sanitized = value.trim().replace(/[^A-Za-z0-9_$]+/g, \"_\");\n\n const trimmed = trimEdgeUnderscores(sanitized);\n\n let safeName = trimmed.length > 0 ? trimmed : \"_\";\n\n if (/^[0-9]/.test(safeName)) {\n safeName = `_${safeName}`;\n }\n\n if (isReservedWord(safeName)) {\n safeName = `${safeName}_`;\n }\n\n return safeName;\n}\n\n/**\n * Renders the name as a bare identifier when possible, otherwise as a string literal.\n */\nexport function serializePropertyName(name: string): string {\n return isValidIdentifier(name) ? name : JSON.stringify(name);\n}\n","import { sanitizeIdentifier } from \"./identifier\";\n\n/**\n * Converts a raw tool name into a safe JavaScript identifier.\n */\nexport function sanitizeToolName(name: string): string {\n return sanitizeIdentifier(name);\n}\n","import * as zod from \"zod\";\nimport type { ZodRawShape, ZodTypeAny } from \"zod\";\n\nimport type { JsonSchema, ToolSchema } from \"../types\";\n\nconst z = \"z\" in zod && typeof zod.z === \"object\" ? zod.z : zod;\nconst toJsonSchema =\n (\"toJSONSchema\" in zod ? zod.toJSONSchema : undefined) ??\n (\"toJSONSchema\" in z ? z.toJSONSchema : undefined);\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === \"object\" && value !== null;\n}\n\nfunction isZodSchema(value: unknown): value is ZodTypeAny {\n return isRecord(value) && typeof value.safeParse === \"function\";\n}\n\nfunction isZodRawShape(value: unknown): value is ZodRawShape {\n return (\n isRecord(value) &&\n Object.keys(value).length > 0 &&\n Object.values(value).every(isZodSchema)\n );\n}\n\nfunction normalizeZodSchema(schema: ZodTypeAny): JsonSchema {\n if (typeof toJsonSchema !== \"function\") {\n throw new Error(\"Installed zod package does not expose toJSONSchema\");\n }\n\n const jsonSchema = toJsonSchema(schema) as JsonSchema & {\n $schema?: string;\n };\n\n if (\"$schema\" in jsonSchema) {\n const { $schema: _ignored, ...rest } = jsonSchema;\n return rest;\n }\n\n return jsonSchema;\n}\n\n/**\n * Normalizes supported tool schema inputs to the JSON Schema form used internally.\n */\nexport function normalizeToolSchema(\n schema: ToolSchema | undefined,\n phase: \"input\" | \"output\",\n toolName: string,\n): JsonSchema | undefined {\n if (schema === undefined) {\n return undefined;\n }\n\n if (isZodSchema(schema)) {\n return normalizeZodSchema(schema);\n }\n\n if (isZodRawShape(schema)) {\n return normalizeZodSchema(z.object(schema));\n }\n\n if (isRecord(schema)) {\n return schema;\n }\n\n throw new Error(\n `Unsupported ${phase} schema for tool ${toolName}. Expected JSON Schema, a Zod schema, or an MCP-style Zod shape.`,\n );\n}\n","/**\n * Indents each line of the given string by a specified number of levels.\n */\nexport function indent(value: string, level = 1): string {\n return value\n .split(\"\\n\")\n .map((line) => `${\" \".repeat(level)}${line}`)\n .join(\"\\n\");\n}\n\n/**\n * Renders a short TSDoc-style block when documentation is available.\n */\nexport function renderDocComment(lines: string[]): string {\n if (lines.length === 0) {\n return \"\";\n }\n\n return [\"/**\", ...lines.map((line) => ` * ${line}`), \" */\"].join(\"\\n\");\n}\n\n/**\n * Renders a namespace declaration with optional members.\n */\nexport function renderNamespaceDeclaration(\n name: string,\n members: string[],\n): string {\n if (members.length === 0) {\n return `declare namespace ${name} {}`;\n }\n\n return `declare namespace ${name} {\\n${indent(members.join(\"\\n\\n\"))}\\n}`;\n}\n","import { isValidIdentifier, serializePropertyName } from \"../identifier\";\nimport type { JsonSchema, TypegenToolDescriptor } from \"../types\";\nimport { indent, renderDocComment, renderNamespaceDeclaration } from \"./render\";\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === \"object\" && value !== null;\n}\n\nexport { indent } from \"./render\";\n\n/**\n * Converts a supported JSON Schema fragment into a TypeScript type expression.\n */\nexport function schemaToType(\n schema: JsonSchema | undefined,\n level = 0,\n): string {\n if (!schema) {\n return \"unknown\";\n }\n\n if (\n \"allOf\" in schema ||\n \"anyOf\" in schema ||\n \"oneOf\" in schema ||\n \"$ref\" in schema ||\n Array.isArray(schema.type)\n ) {\n return \"unknown\";\n }\n\n switch (schema.type) {\n case \"string\":\n return \"string\";\n case \"number\":\n case \"integer\":\n return \"number\";\n case \"boolean\":\n return \"boolean\";\n case \"null\":\n return \"null\";\n case \"array\": {\n const itemType = schemaToType(\n isRecord(schema.items) ? (schema.items as JsonSchema) : undefined,\n level + 1,\n );\n\n if (isValidIdentifier(itemType)) {\n return `${itemType}[]`;\n }\n\n return `Array<${itemType}>`;\n }\n case \"object\": {\n const properties = isRecord(schema.properties) ? schema.properties : {};\n const required = new Set(\n Array.isArray(schema.required)\n ? schema.required.filter(\n (value): value is string => typeof value === \"string\",\n )\n : [],\n );\n const entries = Object.entries(properties);\n\n if (entries.length === 0) {\n return \"Record<string, unknown>\";\n }\n\n const lines = entries.map(([name, propertySchema]) => {\n const propertyType = schemaToType(\n isRecord(propertySchema) ? (propertySchema as JsonSchema) : undefined,\n level + 1,\n );\n const optionalToken = required.has(name) ? \"\" : \"?\";\n return `${serializePropertyName(name)}${optionalToken}: ${propertyType};`;\n });\n\n return `{\\n${indent(lines.join(\"\\n\"), level + 1)}\\n${\" \".repeat(level)}}`;\n }\n default:\n return \"unknown\";\n }\n}\n\nfunction formatToolDeclaration(\n name: string,\n tool: TypegenToolDescriptor,\n): string {\n const lines: string[] = [];\n const comment = tool.description ? renderDocComment([tool.description]) : \"\";\n if (comment) {\n lines.push(comment);\n }\n\n const inputType = schemaToType(tool.inputSchema);\n const outputType = schemaToType(tool.outputSchema);\n lines.push(`function ${name}(input: ${inputType}): Promise<${outputType}>;`);\n\n return lines.join(\"\\n\");\n}\n\n/**\n * Generates a namespace declaration for a provider's tool schemas.\n */\nexport function generateTypesFromJsonSchema(\n providerName: string,\n tools: Record<string, TypegenToolDescriptor>,\n): string {\n return renderNamespaceDeclaration(\n providerName,\n Object.entries(tools).map(([name, tool]) =>\n formatToolDeclaration(name, tool),\n ),\n );\n}\n","import Ajv, { type AnySchemaObject, type ValidateFunction } from \"ajv\";\n\nimport {\n ExecuteFailure,\n isExecuteFailure,\n isJsonSerializable,\n} from \"../errors\";\nimport { assertValidIdentifier } from \"../identifier\";\nimport { sanitizeToolName } from \"../sanitize\";\nimport { normalizeToolSchema } from \"../schema/normalizeSchema\";\nimport { generateTypesFromJsonSchema } from \"../typegen/jsonSchema\";\nimport type {\n JsonSchema,\n ResolvedToolDescriptor,\n ResolvedToolProvider,\n ToolExecutionContext,\n ToolProvider,\n TypegenToolDescriptor,\n} from \"../types\";\n\nconst DEFAULT_PROVIDER_NAME = \"codemode\";\nfunction assertValidNamespace(name: string): void {\n assertValidIdentifier(name, \"provider namespace\");\n}\n\nfunction compileValidator(\n ajv: Ajv,\n schema: JsonSchema | undefined,\n): ValidateFunction | undefined {\n return schema ? ajv.compile(schema as AnySchemaObject) : undefined;\n}\n\nfunction formatValidationMessage(\n ajv: Ajv,\n phase: \"input\" | \"output\",\n toolName: string,\n validator: ValidateFunction,\n): string {\n return `Invalid ${phase} for tool ${toolName}: ${ajv.errorsText(validator.errors)}`;\n}\n\n/**\n * Resolves a tool provider into the validated, sanitized shape consumed by executors.\n */\nexport function resolveProvider(provider: ToolProvider): ResolvedToolProvider {\n const name = provider.name ?? DEFAULT_PROVIDER_NAME;\n assertValidNamespace(name);\n\n // strict: false allows schemas with extra keywords (e.g. Zod-generated $schema)\n // that don't conform to the strict JSON Schema vocabulary.\n const ajv = new Ajv({\n allErrors: true,\n strict: false,\n });\n\n const originalToSafeName: Record<string, string> = {};\n const safeToOriginalName: Record<string, string> = {};\n const usedSafeNames = new Set<string>();\n const resolvedTools: Record<string, ResolvedToolDescriptor> = {};\n const typegenTools: Record<string, TypegenToolDescriptor> = {};\n\n for (const [originalName, descriptor] of Object.entries(provider.tools)) {\n const baseSafeName = sanitizeToolName(originalName);\n let safeName = baseSafeName;\n let suffix = 2;\n\n while (usedSafeNames.has(safeName)) {\n safeName = `${baseSafeName}__${suffix}`;\n suffix += 1;\n }\n\n usedSafeNames.add(safeName);\n originalToSafeName[originalName] = safeName;\n safeToOriginalName[safeName] = originalName;\n\n const inputSchema = normalizeToolSchema(\n descriptor.inputSchema,\n \"input\",\n originalName,\n );\n const outputSchema = normalizeToolSchema(\n descriptor.outputSchema,\n \"output\",\n originalName,\n );\n const inputValidator = compileValidator(ajv, inputSchema);\n const outputValidator = compileValidator(ajv, outputSchema);\n\n resolvedTools[safeName] = {\n description: descriptor.description,\n execute: async (\n input: unknown,\n context: ToolExecutionContext,\n ): Promise<unknown> => {\n if (inputValidator && !inputValidator(input)) {\n throw new ExecuteFailure(\n \"validation_error\",\n formatValidationMessage(ajv, \"input\", originalName, inputValidator),\n );\n }\n\n try {\n const result = await descriptor.execute(input, context);\n\n if (!isJsonSerializable(result)) {\n throw new ExecuteFailure(\n \"serialization_error\",\n `Tool ${originalName} returned a non-serializable value`,\n );\n }\n\n if (outputValidator && !outputValidator(result)) {\n throw new ExecuteFailure(\n \"validation_error\",\n formatValidationMessage(\n ajv,\n \"output\",\n originalName,\n outputValidator,\n ),\n );\n }\n\n return result;\n } catch (error) {\n if (isExecuteFailure(error)) {\n throw error;\n }\n\n throw new ExecuteFailure(\n \"tool_error\",\n error instanceof Error\n ? error.message\n : `Tool ${originalName} failed`,\n );\n }\n },\n inputSchema,\n originalName,\n outputSchema,\n safeName,\n };\n\n typegenTools[safeName] = {\n description: descriptor.description,\n inputSchema,\n outputSchema,\n };\n }\n\n return {\n name,\n originalToSafeName,\n safeToOriginalName,\n tools: resolvedTools,\n types: provider.types ?? generateTypesFromJsonSchema(name, typegenTools),\n };\n}\n"],"mappings":";;;;;AAAA,MAAM,iBAAiB,IAAI,IAAI;CAC7B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD,CAAC;AAEF,MAAM,uBAAuB;AAE7B,SAAS,oBAAoB,OAAuB;CAClD,IAAI,QAAQ;CACZ,IAAI,MAAM,MAAM;AAEhB,QAAO,QAAQ,OAAO,MAAM,WAAW,MAAM,KAAK,qBAChD,UAAS;AAGX,QAAO,MAAM,SAAS,MAAM,WAAW,MAAM,EAAE,KAAK,qBAClD,QAAO;AAGT,QAAO,MAAM,MAAM,OAAO,IAAI;;;;;AAMhC,SAAgB,kBAAkB,OAAwB;AACxD,QAAO,6BAA6B,KAAK,MAAM;;;;;AAMjD,SAAgB,eAAe,OAAwB;AACrD,QAAO,eAAe,IAAI,MAAM;;;;;AAMlC,SAAgB,sBACd,OACA,QAAQ,cACF;AACN,KAAI,CAAC,kBAAkB,MAAM,IAAI,eAAe,MAAM,CACpD,OAAM,IAAI,MAAM,WAAW,MAAM,IAAI,QAAQ;;;;;AAOjD,SAAgB,mBAAmB,O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,UACN,QAAQ,aAAa,SAC1B;;;GAGL;GACA;GACA;GACA;GACD;AAED,eAAa,YAAY;GACvB,aAAa,WAAW;GACxB;GACA;GACD;;AAGH,QAAO;EACL;EACA;EACA;EACA,OAAO;EACP,OAAO,SAAS,SAAS,4BAA4B,MAAM,aAAa;EACzE"}
@@ -1,4 +1,4 @@
1
- import { n as isExecuteFailure, r as isJsonSerializable, t as ExecuteFailure } from "./errors-BXpyBhCI.js";
1
+ import { n as isExecuteFailure, r as isJsonSerializable, t as ExecuteFailure } from "./errors-wS8yjQhS.js";
2
2
 
3
3
  //#region src/executor/shared.ts
4
4
  const EXECUTION_TIMEOUT_MESSAGE = "Execution timed out";
@@ -173,4 +173,4 @@ function createToolCallDispatcher(providers, signal) {
173
173
 
174
174
  //#endregion
175
175
  export { formatConsoleLine as a, normalizeThrownMessage as c, createTimeoutExecuteResult as i, normalizeThrownName as l, extractProviderManifests as n, getExecutionTimeoutMessage as o, createExecutionContext as r, isKnownExecuteErrorCode as s, createToolCallDispatcher as t, truncateLogs as u };
176
- //# sourceMappingURL=runner-nUCF59Au.js.map
176
+ //# sourceMappingURL=runner-6GMM-5ur.js.map