@goah/cli 0.13.0 → 0.13.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (236) hide show
  1. package/dist/LICENSE +201 -0
  2. package/dist/THIRD-PARTY-NOTICES.md +2319 -0
  3. package/dist/anthropic-messages-WBFOHES5.js +7214 -0
  4. package/dist/azure-openai-responses-NZFH3PO6.js +253 -0
  5. package/dist/chunk-25XSBFX6.js +639 -0
  6. package/dist/chunk-2QBQZGXF.js +110 -0
  7. package/dist/chunk-2ZP2NBW3.js +345 -0
  8. package/dist/chunk-4KA63VNZ.js +2 -0
  9. package/dist/chunk-4M6TXTT5.js +86 -0
  10. package/dist/chunk-4US7ZHT3.js +20 -0
  11. package/dist/chunk-6M3OOCKO.js +11809 -0
  12. package/dist/chunk-7AXAFDPG.js +17 -0
  13. package/dist/chunk-BXA47DTF.js +548 -0
  14. package/dist/chunk-FSBUS2BI.js +26 -0
  15. package/dist/chunk-GKDRAHLI.js +4787 -0
  16. package/dist/chunk-H462EFJP.js +89 -0
  17. package/dist/chunk-IIJQ3DW4.js +35 -0
  18. package/dist/chunk-JQD5EWJY.js +34 -0
  19. package/dist/chunk-K26BVR6O.js +61 -0
  20. package/dist/chunk-KAO7WIXG.js +31 -0
  21. package/dist/chunk-LBKI23CC.js +9810 -0
  22. package/dist/chunk-LKBKZEHT.js +41 -0
  23. package/dist/chunk-MD7TLTXZ.js +18 -0
  24. package/dist/chunk-MPXK7QBL.js +868 -0
  25. package/dist/chunk-NRLGWZJC.js +11 -0
  26. package/dist/chunk-PFEV3HWI.js +1178 -0
  27. package/dist/chunk-QBD6EJ2Z.js +1746 -0
  28. package/dist/chunk-R6I3VKME.js +132 -0
  29. package/dist/chunk-TJON22J4.js +87 -0
  30. package/dist/chunk-ULY36ME4.js +33097 -0
  31. package/dist/chunk-VWEV4LTH.js +25 -0
  32. package/dist/chunk-X7UWW2PN.js +883 -0
  33. package/dist/chunk-XALZLRYK.js +9221 -0
  34. package/dist/chunk-XPQKM3L7.js +57 -0
  35. package/dist/chunk-YH6YJ2IB.js +1773 -0
  36. package/dist/cli.d.ts +0 -2
  37. package/dist/cli.js +13123 -580
  38. package/dist/console/assets/{index-Rtc_B7cs.js → index-B1vGMXKr.js} +11 -11
  39. package/dist/console/assets/{index-Rtc_B7cs.js.map → index-B1vGMXKr.js.map} +1 -1
  40. package/dist/console/index.html +1 -1
  41. package/dist/dist-65MDQA4Q.js +1126 -0
  42. package/dist/dist-KNR2XL6J.js +39 -0
  43. package/dist/execution.d.ts +557 -2
  44. package/dist/execution.js +37 -2
  45. package/dist/faux-runner-worker.js +128 -0
  46. package/dist/google-generative-ai-YMHXZSFE.js +422 -0
  47. package/dist/google-vertex-X6DB3ZQ6.js +471 -0
  48. package/dist/index.d.ts +853 -25
  49. package/dist/index.js +84 -385
  50. package/dist/kernel.d.ts +39 -2
  51. package/dist/kernel.js +21 -2
  52. package/dist/mistral-conversations-TY3MMD6G.js +718 -0
  53. package/dist/multipart-parser-F6M4NJZU.js +373 -0
  54. package/dist/openai-codex-responses-BRDUMLN5.js +1374 -0
  55. package/dist/openai-completions-CX634XN3.js +1139 -0
  56. package/dist/openai-responses-HMCXJIHT.js +300 -0
  57. package/dist/openrouter-images-KTWET2H2.js +148 -0
  58. package/dist/pi-messages-XL5OEC4K.js +307 -0
  59. package/dist/pi-worker.js +671 -0
  60. package/dist/runner-pi.d.ts +342 -2
  61. package/dist/runner-pi.js +46 -2
  62. package/dist/runner-registry-M776E3SE.js +22 -0
  63. package/dist/sqlite.d.ts +446 -2
  64. package/dist/sqlite.js +15 -2
  65. package/dist/src-F2KBSV4T.js +1398 -0
  66. package/dist/supervisor.d.ts +625 -2
  67. package/dist/supervisor.js +39 -2
  68. package/dist/testkit.d.ts +564 -2
  69. package/dist/testkit.js +127 -2
  70. package/dist/transcript.d.ts +84 -2
  71. package/dist/transcript.js +25 -2
  72. package/dist/verification-worker.js +72 -0
  73. package/package.json +2 -26
  74. package/dist/cli.d.ts.map +0 -1
  75. package/dist/cli.js.map +0 -1
  76. package/dist/control.d.ts +0 -106
  77. package/dist/control.d.ts.map +0 -1
  78. package/dist/control.js +0 -242
  79. package/dist/control.js.map +0 -1
  80. package/dist/execution.d.ts.map +0 -1
  81. package/dist/execution.js.map +0 -1
  82. package/dist/index.d.ts.map +0 -1
  83. package/dist/index.js.map +0 -1
  84. package/dist/kernel.d.ts.map +0 -1
  85. package/dist/kernel.js.map +0 -1
  86. package/dist/live-config.d.ts +0 -10
  87. package/dist/live-config.d.ts.map +0 -1
  88. package/dist/live-config.js +0 -44
  89. package/dist/live-config.js.map +0 -1
  90. package/dist/prompt-queue.d.ts +0 -13
  91. package/dist/prompt-queue.d.ts.map +0 -1
  92. package/dist/prompt-queue.js +0 -35
  93. package/dist/prompt-queue.js.map +0 -1
  94. package/dist/runner-pi.d.ts.map +0 -1
  95. package/dist/runner-pi.js.map +0 -1
  96. package/dist/runner-registry.d.ts +0 -8
  97. package/dist/runner-registry.d.ts.map +0 -1
  98. package/dist/runner-registry.js +0 -12
  99. package/dist/runner-registry.js.map +0 -1
  100. package/dist/searchable-select.d.ts +0 -24
  101. package/dist/searchable-select.d.ts.map +0 -1
  102. package/dist/searchable-select.js +0 -61
  103. package/dist/searchable-select.js.map +0 -1
  104. package/dist/secret-input.d.ts +0 -8
  105. package/dist/secret-input.d.ts.map +0 -1
  106. package/dist/secret-input.js +0 -14
  107. package/dist/secret-input.js.map +0 -1
  108. package/dist/setup-wizard.d.ts +0 -22
  109. package/dist/setup-wizard.d.ts.map +0 -1
  110. package/dist/setup-wizard.js +0 -154
  111. package/dist/setup-wizard.js.map +0 -1
  112. package/dist/sqlite.d.ts.map +0 -1
  113. package/dist/sqlite.js.map +0 -1
  114. package/dist/supervisor.d.ts.map +0 -1
  115. package/dist/supervisor.js.map +0 -1
  116. package/dist/testkit.d.ts.map +0 -1
  117. package/dist/testkit.js.map +0 -1
  118. package/dist/thread-inspect.d.ts +0 -47
  119. package/dist/thread-inspect.d.ts.map +0 -1
  120. package/dist/thread-inspect.js +0 -78
  121. package/dist/thread-inspect.js.map +0 -1
  122. package/dist/transcript.d.ts.map +0 -1
  123. package/dist/transcript.js.map +0 -1
  124. package/dist/tui-theme.d.ts +0 -17
  125. package/dist/tui-theme.d.ts.map +0 -1
  126. package/dist/tui-theme.js +0 -19
  127. package/dist/tui-theme.js.map +0 -1
  128. package/dist/tui.d.ts +0 -24
  129. package/dist/tui.d.ts.map +0 -1
  130. package/dist/tui.js +0 -784
  131. package/dist/tui.js.map +0 -1
  132. package/dist/update.d.ts +0 -16
  133. package/dist/update.d.ts.map +0 -1
  134. package/dist/update.js +0 -67
  135. package/dist/update.js.map +0 -1
  136. package/dist/web-console.d.ts +0 -33
  137. package/dist/web-console.d.ts.map +0 -1
  138. package/dist/web-console.js +0 -242
  139. package/dist/web-console.js.map +0 -1
  140. package/dist/welcome.d.ts +0 -30
  141. package/dist/welcome.d.ts.map +0 -1
  142. package/dist/welcome.js +0 -69
  143. package/dist/welcome.js.map +0 -1
  144. package/node_modules/goah-ledger-contract/dist/execution.d.ts +0 -544
  145. package/node_modules/goah-ledger-contract/dist/execution.d.ts.map +0 -1
  146. package/node_modules/goah-ledger-contract/dist/execution.js +0 -52
  147. package/node_modules/goah-ledger-contract/dist/execution.js.map +0 -1
  148. package/node_modules/goah-ledger-contract/dist/index.d.ts +0 -4
  149. package/node_modules/goah-ledger-contract/dist/index.d.ts.map +0 -1
  150. package/node_modules/goah-ledger-contract/dist/index.js +0 -4
  151. package/node_modules/goah-ledger-contract/dist/index.js.map +0 -1
  152. package/node_modules/goah-ledger-contract/dist/kernel.d.ts +0 -37
  153. package/node_modules/goah-ledger-contract/dist/kernel.d.ts.map +0 -1
  154. package/node_modules/goah-ledger-contract/dist/kernel.js +0 -8
  155. package/node_modules/goah-ledger-contract/dist/kernel.js.map +0 -1
  156. package/node_modules/goah-ledger-contract/dist/transcript.d.ts +0 -63
  157. package/node_modules/goah-ledger-contract/dist/transcript.d.ts.map +0 -1
  158. package/node_modules/goah-ledger-contract/dist/transcript.js +0 -115
  159. package/node_modules/goah-ledger-contract/dist/transcript.js.map +0 -1
  160. package/node_modules/goah-ledger-contract/package.json +0 -28
  161. package/node_modules/goah-ledger-sqlite/dist/index.d.ts +0 -86
  162. package/node_modules/goah-ledger-sqlite/dist/index.d.ts.map +0 -1
  163. package/node_modules/goah-ledger-sqlite/dist/index.js +0 -1254
  164. package/node_modules/goah-ledger-sqlite/dist/index.js.map +0 -1
  165. package/node_modules/goah-ledger-sqlite/package.json +0 -26
  166. package/node_modules/goah-runner-pi/dist/configurator.d.ts +0 -20
  167. package/node_modules/goah-runner-pi/dist/configurator.d.ts.map +0 -1
  168. package/node_modules/goah-runner-pi/dist/configurator.js +0 -423
  169. package/node_modules/goah-runner-pi/dist/configurator.js.map +0 -1
  170. package/node_modules/goah-runner-pi/dist/credential-store.d.ts +0 -14
  171. package/node_modules/goah-runner-pi/dist/credential-store.d.ts.map +0 -1
  172. package/node_modules/goah-runner-pi/dist/credential-store.js +0 -163
  173. package/node_modules/goah-runner-pi/dist/credential-store.js.map +0 -1
  174. package/node_modules/goah-runner-pi/dist/env-spec.d.ts +0 -17
  175. package/node_modules/goah-runner-pi/dist/env-spec.d.ts.map +0 -1
  176. package/node_modules/goah-runner-pi/dist/env-spec.js +0 -95
  177. package/node_modules/goah-runner-pi/dist/env-spec.js.map +0 -1
  178. package/node_modules/goah-runner-pi/dist/index.d.ts +0 -76
  179. package/node_modules/goah-runner-pi/dist/index.d.ts.map +0 -1
  180. package/node_modules/goah-runner-pi/dist/index.js +0 -326
  181. package/node_modules/goah-runner-pi/dist/index.js.map +0 -1
  182. package/node_modules/goah-runner-pi/dist/model-provider.d.ts +0 -30
  183. package/node_modules/goah-runner-pi/dist/model-provider.d.ts.map +0 -1
  184. package/node_modules/goah-runner-pi/dist/model-provider.js +0 -96
  185. package/node_modules/goah-runner-pi/dist/model-provider.js.map +0 -1
  186. package/node_modules/goah-runner-pi/dist/pi-worker.d.ts +0 -31
  187. package/node_modules/goah-runner-pi/dist/pi-worker.d.ts.map +0 -1
  188. package/node_modules/goah-runner-pi/dist/pi-worker.js +0 -579
  189. package/node_modules/goah-runner-pi/dist/pi-worker.js.map +0 -1
  190. package/node_modules/goah-runner-pi/dist/steering-no-ack.test-fixture.d.ts +0 -2
  191. package/node_modules/goah-runner-pi/dist/steering-no-ack.test-fixture.d.ts.map +0 -1
  192. package/node_modules/goah-runner-pi/dist/steering-no-ack.test-fixture.js +0 -3
  193. package/node_modules/goah-runner-pi/dist/steering-no-ack.test-fixture.js.map +0 -1
  194. package/node_modules/goah-runner-pi/dist/steering-reject.test-fixture.d.ts +0 -2
  195. package/node_modules/goah-runner-pi/dist/steering-reject.test-fixture.d.ts.map +0 -1
  196. package/node_modules/goah-runner-pi/dist/steering-reject.test-fixture.js +0 -5
  197. package/node_modules/goah-runner-pi/dist/steering-reject.test-fixture.js.map +0 -1
  198. package/node_modules/goah-runner-pi/dist/steering-worker.test-fixture.d.ts +0 -2
  199. package/node_modules/goah-runner-pi/dist/steering-worker.test-fixture.d.ts.map +0 -1
  200. package/node_modules/goah-runner-pi/dist/steering-worker.test-fixture.js +0 -5
  201. package/node_modules/goah-runner-pi/dist/steering-worker.test-fixture.js.map +0 -1
  202. package/node_modules/goah-runner-pi/dist/test-helpers.d.ts +0 -4
  203. package/node_modules/goah-runner-pi/dist/test-helpers.d.ts.map +0 -1
  204. package/node_modules/goah-runner-pi/dist/test-helpers.js +0 -13
  205. package/node_modules/goah-runner-pi/dist/test-helpers.js.map +0 -1
  206. package/node_modules/goah-runner-pi/dist/verification-worker.d.ts +0 -2
  207. package/node_modules/goah-runner-pi/dist/verification-worker.d.ts.map +0 -1
  208. package/node_modules/goah-runner-pi/dist/verification-worker.js +0 -46
  209. package/node_modules/goah-runner-pi/dist/verification-worker.js.map +0 -1
  210. package/node_modules/goah-runner-pi/package.json +0 -28
  211. package/node_modules/goah-supervisor/dist/context-view.d.ts +0 -30
  212. package/node_modules/goah-supervisor/dist/context-view.d.ts.map +0 -1
  213. package/node_modules/goah-supervisor/dist/context-view.js +0 -58
  214. package/node_modules/goah-supervisor/dist/context-view.js.map +0 -1
  215. package/node_modules/goah-supervisor/dist/index.d.ts +0 -96
  216. package/node_modules/goah-supervisor/dist/index.d.ts.map +0 -1
  217. package/node_modules/goah-supervisor/dist/index.js +0 -1075
  218. package/node_modules/goah-supervisor/dist/index.js.map +0 -1
  219. package/node_modules/goah-supervisor/dist/roles.d.ts +0 -4
  220. package/node_modules/goah-supervisor/dist/roles.d.ts.map +0 -1
  221. package/node_modules/goah-supervisor/dist/roles.js +0 -29
  222. package/node_modules/goah-supervisor/dist/roles.js.map +0 -1
  223. package/node_modules/goah-supervisor/dist/verification.d.ts +0 -61
  224. package/node_modules/goah-supervisor/dist/verification.d.ts.map +0 -1
  225. package/node_modules/goah-supervisor/dist/verification.js +0 -135
  226. package/node_modules/goah-supervisor/dist/verification.js.map +0 -1
  227. package/node_modules/goah-supervisor/package.json +0 -26
  228. package/node_modules/goah-testkit/dist/faux-runner-worker.d.ts +0 -2
  229. package/node_modules/goah-testkit/dist/faux-runner-worker.d.ts.map +0 -1
  230. package/node_modules/goah-testkit/dist/faux-runner-worker.js +0 -82
  231. package/node_modules/goah-testkit/dist/faux-runner-worker.js.map +0 -1
  232. package/node_modules/goah-testkit/dist/index.d.ts +0 -49
  233. package/node_modules/goah-testkit/dist/index.d.ts.map +0 -1
  234. package/node_modules/goah-testkit/dist/index.js +0 -96
  235. package/node_modules/goah-testkit/dist/index.js.map +0 -1
  236. package/node_modules/goah-testkit/package.json +0 -29
@@ -0,0 +1,17 @@
1
+ import { createRequire as __goahCreateRequire } from "node:module";
2
+ const require = __goahCreateRequire(import.meta.url);
3
+
4
+ // ../../node_modules/@earendil-works/pi-ai/dist/api/openai-prompt-cache.js
5
+ var OPENAI_PROMPT_CACHE_KEY_MAX_LENGTH = 64;
6
+ function clampOpenAIPromptCacheKey(key) {
7
+ if (key === void 0)
8
+ return void 0;
9
+ const chars = Array.from(key);
10
+ if (chars.length <= OPENAI_PROMPT_CACHE_KEY_MAX_LENGTH)
11
+ return key;
12
+ return chars.slice(0, OPENAI_PROMPT_CACHE_KEY_MAX_LENGTH).join("");
13
+ }
14
+
15
+ export {
16
+ clampOpenAIPromptCacheKey
17
+ };
@@ -0,0 +1,548 @@
1
+ import { createRequire as __goahCreateRequire } from "node:module";
2
+ const require = __goahCreateRequire(import.meta.url);
3
+
4
+ // ../../node_modules/@earendil-works/pi-ai/dist/api/constrained-sampling.js
5
+ var UnsupportedStrictJsonSchemaError = class extends Error {
6
+ };
7
+ var UNSUPPORTED_STRICT_SCHEMA_KEYS = [
8
+ "$ref",
9
+ "$defs",
10
+ "definitions",
11
+ "allOf",
12
+ "oneOf",
13
+ "patternProperties",
14
+ "dependentSchemas",
15
+ "dependencies",
16
+ "unevaluatedProperties",
17
+ "propertyNames",
18
+ "contains",
19
+ "prefixItems",
20
+ "not",
21
+ "if",
22
+ "then",
23
+ "else"
24
+ ];
25
+ function isJsonSchemaObject(value) {
26
+ return typeof value === "object" && value !== null && !Array.isArray(value);
27
+ }
28
+ function isStructuredSchema(schema) {
29
+ if (!isJsonSchemaObject(schema))
30
+ return false;
31
+ const types = typeof schema.type === "string" ? [schema.type] : Array.isArray(schema.type) ? schema.type : [];
32
+ return types.includes("object") || types.includes("array") || schema.properties !== void 0 || schema.items !== void 0;
33
+ }
34
+ function schemaAllowsNull(schema) {
35
+ if (!isJsonSchemaObject(schema))
36
+ return false;
37
+ if (schema.type === "null" || Array.isArray(schema.type) && schema.type.includes("null"))
38
+ return true;
39
+ if (schema.const === null || Array.isArray(schema.enum) && schema.enum.includes(null))
40
+ return true;
41
+ return Array.isArray(schema.anyOf) && schema.anyOf.some((variant) => schemaAllowsNull(variant));
42
+ }
43
+ function makeJsonSchemaNodeStrict(schema) {
44
+ if (!isJsonSchemaObject(schema)) {
45
+ throw new UnsupportedStrictJsonSchemaError("boolean schemas are unsupported");
46
+ }
47
+ for (const key of UNSUPPORTED_STRICT_SCHEMA_KEYS) {
48
+ if (schema[key] !== void 0) {
49
+ throw new UnsupportedStrictJsonSchemaError(`${key} schemas are unsupported`);
50
+ }
51
+ }
52
+ if (schema.anyOf !== void 0) {
53
+ if (!Array.isArray(schema.anyOf) || schema.anyOf.length === 0) {
54
+ throw new UnsupportedStrictJsonSchemaError("anyOf must contain at least one schema");
55
+ }
56
+ for (const variant of schema.anyOf) {
57
+ if (isStructuredSchema(variant)) {
58
+ throw new UnsupportedStrictJsonSchemaError("object and array unions are unsupported");
59
+ }
60
+ makeJsonSchemaNodeStrict(variant);
61
+ }
62
+ }
63
+ if (schema.items !== void 0) {
64
+ if (Array.isArray(schema.items)) {
65
+ throw new UnsupportedStrictJsonSchemaError("tuple schemas are unsupported");
66
+ }
67
+ makeJsonSchemaNodeStrict(schema.items);
68
+ }
69
+ const isObjectSchema = schema.type === "object";
70
+ if (schema.properties !== void 0 && !isObjectSchema) {
71
+ throw new UnsupportedStrictJsonSchemaError("properties require type object");
72
+ }
73
+ if (!isObjectSchema)
74
+ return;
75
+ if (schema.additionalProperties !== void 0 && schema.additionalProperties !== false) {
76
+ throw new UnsupportedStrictJsonSchemaError("schema-valued or true additionalProperties is unsupported");
77
+ }
78
+ if (schema.properties !== void 0 && !isJsonSchemaObject(schema.properties)) {
79
+ throw new UnsupportedStrictJsonSchemaError("object properties must be a schema map");
80
+ }
81
+ if (schema.required !== void 0 && (!Array.isArray(schema.required) || schema.required.some((key) => typeof key !== "string"))) {
82
+ throw new UnsupportedStrictJsonSchemaError("object required must be a string array");
83
+ }
84
+ const properties = schema.properties ?? {};
85
+ const propertyNames = Object.keys(properties);
86
+ const required = new Set(Array.isArray(schema.required) ? schema.required : []);
87
+ if ([...required].some((key) => !propertyNames.includes(key))) {
88
+ throw new UnsupportedStrictJsonSchemaError("required contains an unknown property");
89
+ }
90
+ for (const [key, property] of Object.entries(properties)) {
91
+ makeJsonSchemaNodeStrict(property);
92
+ if (!required.has(key) && !schemaAllowsNull(property)) {
93
+ properties[key] = { anyOf: [property, { type: "null" }] };
94
+ }
95
+ }
96
+ schema.required = propertyNames;
97
+ schema.additionalProperties = false;
98
+ }
99
+ function makeStrictJsonSchema(schema) {
100
+ const cloned = structuredClone(schema);
101
+ if (!isJsonSchemaObject(cloned)) {
102
+ throw new UnsupportedStrictJsonSchemaError("root schema must have type object");
103
+ }
104
+ makeJsonSchemaNodeStrict(cloned);
105
+ if (cloned.type !== "object") {
106
+ throw new UnsupportedStrictJsonSchemaError("root schema must have type object");
107
+ }
108
+ return cloned;
109
+ }
110
+ function getJsonSchemaToolParameters(tool, strict) {
111
+ return strict === true ? makeStrictJsonSchema(tool.parameters) : tool.parameters;
112
+ }
113
+ function getGrammarToolInput(toolName, arguments_, inputProperty) {
114
+ const input = arguments_[inputProperty];
115
+ if (typeof input !== "string") {
116
+ throw new Error(`Grammar tool call "${toolName}" requires argument "${inputProperty}" to be a string.`);
117
+ }
118
+ return input;
119
+ }
120
+ function appendGrammarToolInputJsonDelta(buffer, inputProperty, nextInput, close) {
121
+ if (buffer.closed) {
122
+ if (close && nextInput === buffer.input)
123
+ return void 0;
124
+ throw new Error(`grammar tool input for property "${inputProperty}" changed after it was closed`);
125
+ }
126
+ if (!nextInput.startsWith(buffer.input)) {
127
+ throw new Error(`grammar tool input for property "${inputProperty}" changed non-monotonically`);
128
+ }
129
+ const inputDelta = nextInput.slice(buffer.input.length);
130
+ if (!close && inputDelta.length === 0)
131
+ return void 0;
132
+ let delta = "";
133
+ if (!buffer.started) {
134
+ delta += `{${JSON.stringify(inputProperty)}:"`;
135
+ buffer.started = true;
136
+ }
137
+ delta += JSON.stringify(inputDelta).slice(1, -1);
138
+ buffer.input = nextInput;
139
+ if (close) {
140
+ delta += '"}';
141
+ buffer.closed = true;
142
+ }
143
+ return delta;
144
+ }
145
+ function inferGrammarInputProperty(tool) {
146
+ const schema = tool.parameters;
147
+ if (schema.type !== "object") {
148
+ throw new Error("grammar constrained sampling requires an object parameter schema");
149
+ }
150
+ if (!Array.isArray(schema.required) || schema.required.length !== 1 || typeof schema.required[0] !== "string") {
151
+ throw new Error("grammar constrained sampling requires exactly one required string property");
152
+ }
153
+ const inputProperty = schema.required[0];
154
+ if (!schema.properties?.[inputProperty]) {
155
+ throw new Error(`grammar constrained sampling requires a properties entry for ${inputProperty}`);
156
+ }
157
+ if (schema.properties[inputProperty]?.type !== "string") {
158
+ throw new Error(`grammar constrained sampling property ${inputProperty} must have type string`);
159
+ }
160
+ return inputProperty;
161
+ }
162
+ function resolveJsonSchemaStrictSampling(tool, supportsStrictMode) {
163
+ const config = tool.constrainedSampling;
164
+ if (!config || config.type !== "json_schema")
165
+ return void 0;
166
+ if (supportsStrictMode) {
167
+ try {
168
+ makeStrictJsonSchema(tool.parameters);
169
+ return true;
170
+ } catch (error) {
171
+ if (!(error instanceof UnsupportedStrictJsonSchemaError))
172
+ throw error;
173
+ if (config.strict !== "require")
174
+ return void 0;
175
+ throw new Error(`Tool "${tool.name}" requires JSON-schema constrained sampling, but ${error.message}.`);
176
+ }
177
+ }
178
+ if (config.strict === "require") {
179
+ throw new Error(`Tool "${tool.name}" requires JSON-schema constrained sampling, but strict tools are unsupported.`);
180
+ }
181
+ return void 0;
182
+ }
183
+ function resolveGrammarConstrainedSampling(tool, supportsOpenAIGrammarTools) {
184
+ const config = tool.constrainedSampling;
185
+ if (!config || config.type !== "grammar") {
186
+ return void 0;
187
+ }
188
+ if (!supportsOpenAIGrammarTools) {
189
+ return void 0;
190
+ }
191
+ const larkDefinition = config.variants.openai_lark;
192
+ const regexDefinition = config.variants.openai_regex;
193
+ const hasLarkDefinition = typeof larkDefinition === "string" && larkDefinition.trim().length > 0;
194
+ const hasRegexDefinition = typeof regexDefinition === "string" && regexDefinition.trim().length > 0;
195
+ if (!hasLarkDefinition && !hasRegexDefinition) {
196
+ throw new Error(`Tool "${tool.name}" cannot use grammar constrained sampling: no supported grammar variant was provided.`);
197
+ }
198
+ try {
199
+ return {
200
+ format: hasLarkDefinition ? "lark" : "regex",
201
+ definition: hasLarkDefinition ? larkDefinition : regexDefinition,
202
+ inputProperty: inferGrammarInputProperty(tool)
203
+ };
204
+ } catch (error) {
205
+ const message = error instanceof Error ? error.message : String(error);
206
+ throw new Error(`Tool "${tool.name}" cannot use grammar constrained sampling: ${message}.`);
207
+ }
208
+ }
209
+ function createGrammarToolInputProperties(tools, supportsOpenAIGrammarTools) {
210
+ const properties = /* @__PURE__ */ new Map();
211
+ for (const tool of tools ?? []) {
212
+ const grammar = resolveGrammarConstrainedSampling(tool, supportsOpenAIGrammarTools);
213
+ if (grammar) {
214
+ properties.set(tool.name, grammar.inputProperty);
215
+ }
216
+ }
217
+ return properties;
218
+ }
219
+
220
+ // ../../node_modules/@earendil-works/pi-ai/dist/utils/estimate.js
221
+ var CHARS_PER_TOKEN = 4;
222
+ var ESTIMATED_IMAGE_CHARS = 4800;
223
+ function calculateContextTokens(usage) {
224
+ return usage.totalTokens || usage.input + usage.output + usage.cacheRead + usage.cacheWrite;
225
+ }
226
+ function safeJsonStringify(value) {
227
+ try {
228
+ return JSON.stringify(value) ?? "undefined";
229
+ } catch {
230
+ return "[unserializable]";
231
+ }
232
+ }
233
+ function estimateTextAndImageContentChars(content) {
234
+ if (typeof content === "string")
235
+ return content.length;
236
+ let chars = 0;
237
+ for (const block of content)
238
+ chars += block.type === "text" ? block.text.length : ESTIMATED_IMAGE_CHARS;
239
+ return chars;
240
+ }
241
+ function estimateTextTokens(text) {
242
+ return Math.ceil(text.length / CHARS_PER_TOKEN);
243
+ }
244
+ function estimateTextAndImageContentTokens(content) {
245
+ return Math.ceil(estimateTextAndImageContentChars(content) / CHARS_PER_TOKEN);
246
+ }
247
+ function estimateMessageTokens(message) {
248
+ let chars = 0;
249
+ if (message.role === "user")
250
+ return estimateTextAndImageContentTokens(message.content);
251
+ if (message.role === "toolResult")
252
+ return estimateTextAndImageContentTokens(message.content);
253
+ for (const block of message.content) {
254
+ if (block.type === "text") {
255
+ chars += block.text.length;
256
+ } else if (block.type === "thinking") {
257
+ chars += block.thinking.length;
258
+ } else {
259
+ chars += block.name.length + safeJsonStringify(block.arguments).length;
260
+ }
261
+ }
262
+ return Math.ceil(chars / CHARS_PER_TOKEN);
263
+ }
264
+ function getLastAssistantUsageInfo(messages) {
265
+ let latestPrefixTimestamp = Number.NEGATIVE_INFINITY;
266
+ let usageInfo;
267
+ for (let i = 0; i < messages.length; i++) {
268
+ const message = messages[i];
269
+ if (message.role === "assistant") {
270
+ const assistant = message;
271
+ const usageAppliesToPrefix = assistant.timestamp >= latestPrefixTimestamp;
272
+ if (usageAppliesToPrefix && assistant.stopReason !== "aborted" && assistant.stopReason !== "error" && calculateContextTokens(assistant.usage) > 0) {
273
+ usageInfo = { usage: assistant.usage, index: i };
274
+ }
275
+ }
276
+ latestPrefixTimestamp = Math.max(latestPrefixTimestamp, message.timestamp);
277
+ }
278
+ return usageInfo;
279
+ }
280
+ function estimateMessages(messages) {
281
+ const usageInfo = getLastAssistantUsageInfo(messages);
282
+ if (usageInfo) {
283
+ const usageTokens = calculateContextTokens(usageInfo.usage);
284
+ let trailingTokens = 0;
285
+ for (let i = usageInfo.index + 1; i < messages.length; i++) {
286
+ trailingTokens += estimateMessageTokens(messages[i]);
287
+ }
288
+ return { tokens: usageTokens + trailingTokens, usageTokens, trailingTokens, lastUsageIndex: usageInfo.index };
289
+ }
290
+ let tokens = 0;
291
+ for (const message of messages)
292
+ tokens += estimateMessageTokens(message);
293
+ return { tokens, usageTokens: 0, trailingTokens: tokens, lastUsageIndex: null };
294
+ }
295
+ function estimateToolsTokens(tools) {
296
+ if (!tools || tools.length === 0)
297
+ return 0;
298
+ return estimateTextTokens(safeJsonStringify(tools));
299
+ }
300
+ function isMessageArray(value) {
301
+ return Array.isArray(value);
302
+ }
303
+ function estimateContextTokens(context) {
304
+ if (isMessageArray(context))
305
+ return estimateMessages(context);
306
+ const estimate = estimateMessages(context.messages);
307
+ if (estimate.lastUsageIndex !== null) {
308
+ const addedNames = new Set(context.messages.slice(estimate.lastUsageIndex + 1).filter((message) => message.role === "toolResult").flatMap((message) => message.addedToolNames ?? []));
309
+ const addedToolTokens = estimateToolsTokens(context.tools?.filter((tool) => addedNames.has(tool.name)));
310
+ return {
311
+ tokens: estimate.tokens + addedToolTokens,
312
+ usageTokens: estimate.usageTokens,
313
+ trailingTokens: estimate.trailingTokens + addedToolTokens,
314
+ lastUsageIndex: estimate.lastUsageIndex
315
+ };
316
+ }
317
+ const prefixTokens = (context.systemPrompt ? estimateTextTokens(context.systemPrompt) : 0) + estimateToolsTokens(context.tools);
318
+ return {
319
+ tokens: estimate.tokens + prefixTokens,
320
+ usageTokens: estimate.usageTokens,
321
+ trailingTokens: estimate.trailingTokens + prefixTokens,
322
+ lastUsageIndex: estimate.lastUsageIndex
323
+ };
324
+ }
325
+
326
+ // ../../node_modules/@earendil-works/pi-ai/dist/api/simple-options.js
327
+ var CONTEXT_SAFETY_TOKENS = 4096;
328
+ var MIN_MAX_TOKENS = 1;
329
+ function clampMaxTokensToContext(model, context, maxTokens) {
330
+ if (model.contextWindow <= 0)
331
+ return Math.max(MIN_MAX_TOKENS, maxTokens);
332
+ const available = model.contextWindow - estimateContextTokens(context).tokens - CONTEXT_SAFETY_TOKENS;
333
+ return Math.min(maxTokens, Math.max(MIN_MAX_TOKENS, available));
334
+ }
335
+ function buildBaseOptions(model, context, options, apiKey) {
336
+ const samplingParams = model.samplingParams || options?.samplingParams ? { ...model.samplingParams, ...options?.samplingParams } : void 0;
337
+ return {
338
+ temperature: options?.temperature,
339
+ samplingParams,
340
+ maxTokens: clampMaxTokensToContext(model, context, options?.maxTokens ?? model.maxTokens),
341
+ signal: options?.signal,
342
+ telemetryContext: options?.telemetryContext,
343
+ apiKey: apiKey || options?.apiKey,
344
+ fetch: options?.fetch,
345
+ transport: options?.transport,
346
+ cacheRetention: options?.cacheRetention,
347
+ sessionId: options?.sessionId,
348
+ headers: options?.headers,
349
+ onPayload: options?.onPayload,
350
+ onResponse: options?.onResponse,
351
+ timeoutMs: options?.timeoutMs,
352
+ websocketConnectTimeoutMs: options?.websocketConnectTimeoutMs,
353
+ maxRetries: options?.maxRetries,
354
+ maxRetryDelayMs: options?.maxRetryDelayMs,
355
+ metadata: options?.metadata,
356
+ env: options?.env
357
+ };
358
+ }
359
+ var MIN_ANSWER_TOKENS = 1024;
360
+ function clampReasoning(effort) {
361
+ return effort === "xhigh" || effort === "max" ? "high" : effort;
362
+ }
363
+ function adjustMaxTokensForThinking(baseMaxTokens, modelMaxTokens, reasoningLevel, customBudgets) {
364
+ const defaultBudgets = {
365
+ minimal: 1024,
366
+ low: 2048,
367
+ medium: 8192,
368
+ high: 16384
369
+ };
370
+ const budgets = { ...defaultBudgets, ...customBudgets };
371
+ const level = clampReasoning(reasoningLevel);
372
+ let thinkingBudget = budgets[level];
373
+ const maxTokens = baseMaxTokens === void 0 ? modelMaxTokens : Math.min(baseMaxTokens + thinkingBudget, modelMaxTokens);
374
+ if (maxTokens <= thinkingBudget) {
375
+ thinkingBudget = Math.max(0, maxTokens - MIN_ANSWER_TOKENS);
376
+ }
377
+ return { maxTokens, thinkingBudget };
378
+ }
379
+
380
+ // ../../node_modules/@earendil-works/pi-ai/dist/api/transform-messages.js
381
+ var NON_VISION_USER_IMAGE_PLACEHOLDER = "(image omitted: model does not support images)";
382
+ var NON_VISION_TOOL_IMAGE_PLACEHOLDER = "(tool image omitted: model does not support images)";
383
+ function replaceImagesWithPlaceholder(content, placeholder) {
384
+ const result = [];
385
+ let previousWasPlaceholder = false;
386
+ for (const block of content) {
387
+ if (block.type === "image") {
388
+ if (!previousWasPlaceholder) {
389
+ result.push({ type: "text", text: placeholder });
390
+ }
391
+ previousWasPlaceholder = true;
392
+ continue;
393
+ }
394
+ result.push(block);
395
+ previousWasPlaceholder = block.text === placeholder;
396
+ }
397
+ return result;
398
+ }
399
+ function downgradeUnsupportedImages(messages, model) {
400
+ if (model.input.includes("image")) {
401
+ return messages;
402
+ }
403
+ return messages.map((msg) => {
404
+ if (msg.role === "user" && Array.isArray(msg.content)) {
405
+ return {
406
+ ...msg,
407
+ content: replaceImagesWithPlaceholder(msg.content, NON_VISION_USER_IMAGE_PLACEHOLDER)
408
+ };
409
+ }
410
+ if (msg.role === "toolResult") {
411
+ return {
412
+ ...msg,
413
+ content: replaceImagesWithPlaceholder(msg.content, NON_VISION_TOOL_IMAGE_PLACEHOLDER)
414
+ };
415
+ }
416
+ return msg;
417
+ });
418
+ }
419
+ function transformMessages(messages, model, normalizeToolCallId) {
420
+ const toolCallIdMap = /* @__PURE__ */ new Map();
421
+ const normalizedMessages = messages.map((msg) => msg.content == null ? { ...msg, content: [] } : msg);
422
+ const imageAwareMessages = downgradeUnsupportedImages(normalizedMessages, model);
423
+ const transformed = imageAwareMessages.map((msg) => {
424
+ if (msg.role === "user") {
425
+ return msg;
426
+ }
427
+ if (msg.role === "toolResult") {
428
+ const normalizedId = toolCallIdMap.get(msg.toolCallId);
429
+ if (normalizedId && normalizedId !== msg.toolCallId) {
430
+ return { ...msg, toolCallId: normalizedId };
431
+ }
432
+ return msg;
433
+ }
434
+ if (msg.role === "assistant") {
435
+ const assistantMsg = msg;
436
+ const isSameModel = assistantMsg.provider === model.provider && assistantMsg.api === model.api && assistantMsg.model === model.id;
437
+ const transformedContent = assistantMsg.content.flatMap((block) => {
438
+ if (block.type === "thinking") {
439
+ if (block.redacted) {
440
+ return isSameModel ? block : [];
441
+ }
442
+ if (isSameModel && block.thinkingSignature)
443
+ return block;
444
+ if (!block.thinking || block.thinking.trim() === "")
445
+ return [];
446
+ if (isSameModel)
447
+ return block;
448
+ return {
449
+ type: "text",
450
+ text: block.thinking
451
+ };
452
+ }
453
+ if (block.type === "text") {
454
+ if (isSameModel)
455
+ return block;
456
+ return {
457
+ type: "text",
458
+ text: block.text
459
+ };
460
+ }
461
+ if (block.type === "toolCall") {
462
+ const toolCall = block;
463
+ let normalizedToolCall = toolCall;
464
+ if (!isSameModel && toolCall.thoughtSignature) {
465
+ normalizedToolCall = { ...toolCall };
466
+ delete normalizedToolCall.thoughtSignature;
467
+ }
468
+ if (!isSameModel && normalizeToolCallId) {
469
+ const normalizedId = normalizeToolCallId(toolCall.id, model, assistantMsg);
470
+ if (normalizedId !== toolCall.id) {
471
+ toolCallIdMap.set(toolCall.id, normalizedId);
472
+ normalizedToolCall = { ...normalizedToolCall, id: normalizedId };
473
+ }
474
+ }
475
+ return normalizedToolCall;
476
+ }
477
+ return block;
478
+ });
479
+ return {
480
+ ...assistantMsg,
481
+ content: transformedContent
482
+ };
483
+ }
484
+ return msg;
485
+ });
486
+ const result = [];
487
+ let pendingToolCalls = [];
488
+ let existingToolResultIds = /* @__PURE__ */ new Set();
489
+ const insertSyntheticToolResults = () => {
490
+ if (pendingToolCalls.length > 0) {
491
+ for (const tc of pendingToolCalls) {
492
+ if (!existingToolResultIds.has(tc.id)) {
493
+ result.push({
494
+ role: "toolResult",
495
+ toolCallId: tc.id,
496
+ toolName: tc.name,
497
+ content: [{ type: "text", text: "No result provided" }],
498
+ isError: true,
499
+ timestamp: Date.now()
500
+ });
501
+ }
502
+ }
503
+ pendingToolCalls = [];
504
+ existingToolResultIds = /* @__PURE__ */ new Set();
505
+ }
506
+ };
507
+ for (let i = 0; i < transformed.length; i++) {
508
+ const msg = transformed[i];
509
+ if (msg.role === "assistant") {
510
+ insertSyntheticToolResults();
511
+ const assistantMsg = msg;
512
+ if (assistantMsg.stopReason === "error" || assistantMsg.stopReason === "aborted") {
513
+ continue;
514
+ }
515
+ const toolCalls = assistantMsg.content.filter((b) => b.type === "toolCall");
516
+ if (toolCalls.length > 0) {
517
+ pendingToolCalls = toolCalls;
518
+ existingToolResultIds = /* @__PURE__ */ new Set();
519
+ }
520
+ result.push(msg);
521
+ } else if (msg.role === "toolResult") {
522
+ existingToolResultIds.add(msg.toolCallId);
523
+ result.push(msg);
524
+ } else if (msg.role === "user") {
525
+ insertSyntheticToolResults();
526
+ result.push(msg);
527
+ } else {
528
+ result.push(msg);
529
+ }
530
+ }
531
+ insertSyntheticToolResults();
532
+ return result;
533
+ }
534
+
535
+ export {
536
+ getJsonSchemaToolParameters,
537
+ getGrammarToolInput,
538
+ appendGrammarToolInputJsonDelta,
539
+ resolveJsonSchemaStrictSampling,
540
+ resolveGrammarConstrainedSampling,
541
+ createGrammarToolInputProperties,
542
+ clampMaxTokensToContext,
543
+ buildBaseOptions,
544
+ MIN_ANSWER_TOKENS,
545
+ clampReasoning,
546
+ adjustMaxTokensForThinking,
547
+ transformMessages
548
+ };
@@ -0,0 +1,26 @@
1
+ import { createRequire as __goahCreateRequire } from "node:module";
2
+ const require = __goahCreateRequire(import.meta.url);
3
+
4
+ // ../../node_modules/@earendil-works/pi-ai/dist/utils/headers.js
5
+ function headersToRecord(headers) {
6
+ const result = {};
7
+ for (const [key, value] of headers.entries()) {
8
+ result[key] = value;
9
+ }
10
+ return result;
11
+ }
12
+ function providerHeadersToRecord(headers) {
13
+ if (!headers)
14
+ return void 0;
15
+ const result = {};
16
+ for (const [key, value] of Object.entries(headers)) {
17
+ if (value !== null)
18
+ result[key] = value;
19
+ }
20
+ return Object.keys(result).length > 0 ? result : void 0;
21
+ }
22
+
23
+ export {
24
+ headersToRecord,
25
+ providerHeadersToRecord
26
+ };