@goah/cli 0.11.5 → 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 (242) 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 +13148 -506
  38. package/dist/console/assets/index-3sYrDMmt.css +1 -0
  39. package/dist/console/assets/index-B1vGMXKr.js +52 -0
  40. package/dist/console/assets/index-B1vGMXKr.js.map +1 -0
  41. package/dist/console/index.html +2 -2
  42. package/dist/dist-65MDQA4Q.js +1126 -0
  43. package/dist/dist-KNR2XL6J.js +39 -0
  44. package/dist/execution.d.ts +557 -2
  45. package/dist/execution.js +37 -2
  46. package/dist/faux-runner-worker.js +128 -0
  47. package/dist/google-generative-ai-YMHXZSFE.js +422 -0
  48. package/dist/google-vertex-X6DB3ZQ6.js +471 -0
  49. package/dist/index.d.ts +855 -44
  50. package/dist/index.js +84 -257
  51. package/dist/kernel.d.ts +39 -2
  52. package/dist/kernel.js +21 -2
  53. package/dist/mistral-conversations-TY3MMD6G.js +718 -0
  54. package/dist/multipart-parser-F6M4NJZU.js +373 -0
  55. package/dist/openai-codex-responses-BRDUMLN5.js +1374 -0
  56. package/dist/openai-completions-CX634XN3.js +1139 -0
  57. package/dist/openai-responses-HMCXJIHT.js +300 -0
  58. package/dist/openrouter-images-KTWET2H2.js +148 -0
  59. package/dist/pi-messages-XL5OEC4K.js +307 -0
  60. package/dist/pi-worker.js +671 -0
  61. package/dist/runner-pi.d.ts +342 -2
  62. package/dist/runner-pi.js +46 -2
  63. package/dist/runner-registry-M776E3SE.js +22 -0
  64. package/dist/sqlite.d.ts +446 -2
  65. package/dist/sqlite.js +15 -2
  66. package/dist/src-F2KBSV4T.js +1398 -0
  67. package/dist/supervisor.d.ts +625 -2
  68. package/dist/supervisor.js +39 -2
  69. package/dist/testkit.d.ts +564 -2
  70. package/dist/testkit.js +127 -2
  71. package/dist/transcript.d.ts +84 -0
  72. package/dist/transcript.js +25 -0
  73. package/dist/verification-worker.js +72 -0
  74. package/package.json +3 -28
  75. package/dist/cli.d.ts.map +0 -1
  76. package/dist/cli.js.map +0 -1
  77. package/dist/console/assets/index-BJTGvlCH.js +0 -52
  78. package/dist/console/assets/index-BJTGvlCH.js.map +0 -1
  79. package/dist/console/assets/index-msBn41Cl.css +0 -1
  80. package/dist/control.d.ts +0 -106
  81. package/dist/control.d.ts.map +0 -1
  82. package/dist/control.js +0 -215
  83. package/dist/control.js.map +0 -1
  84. package/dist/execution.d.ts.map +0 -1
  85. package/dist/execution.js.map +0 -1
  86. package/dist/index.d.ts.map +0 -1
  87. package/dist/index.js.map +0 -1
  88. package/dist/inspect.d.ts +0 -61
  89. package/dist/inspect.d.ts.map +0 -1
  90. package/dist/inspect.js +0 -110
  91. package/dist/inspect.js.map +0 -1
  92. package/dist/kernel.d.ts.map +0 -1
  93. package/dist/kernel.js.map +0 -1
  94. package/dist/live-config.d.ts +0 -10
  95. package/dist/live-config.d.ts.map +0 -1
  96. package/dist/live-config.js +0 -44
  97. package/dist/live-config.js.map +0 -1
  98. package/dist/metrics.d.ts +0 -2
  99. package/dist/metrics.d.ts.map +0 -1
  100. package/dist/metrics.js +0 -2
  101. package/dist/metrics.js.map +0 -1
  102. package/dist/prompt-queue.d.ts +0 -13
  103. package/dist/prompt-queue.d.ts.map +0 -1
  104. package/dist/prompt-queue.js +0 -30
  105. package/dist/prompt-queue.js.map +0 -1
  106. package/dist/runner-pi.d.ts.map +0 -1
  107. package/dist/runner-pi.js.map +0 -1
  108. package/dist/runner-registry.d.ts +0 -8
  109. package/dist/runner-registry.d.ts.map +0 -1
  110. package/dist/runner-registry.js +0 -12
  111. package/dist/runner-registry.js.map +0 -1
  112. package/dist/searchable-select.d.ts +0 -24
  113. package/dist/searchable-select.d.ts.map +0 -1
  114. package/dist/searchable-select.js +0 -61
  115. package/dist/searchable-select.js.map +0 -1
  116. package/dist/secret-input.d.ts +0 -8
  117. package/dist/secret-input.d.ts.map +0 -1
  118. package/dist/secret-input.js +0 -14
  119. package/dist/secret-input.js.map +0 -1
  120. package/dist/session.d.ts +0 -2
  121. package/dist/session.d.ts.map +0 -1
  122. package/dist/session.js +0 -2
  123. package/dist/session.js.map +0 -1
  124. package/dist/setup-wizard.d.ts +0 -11
  125. package/dist/setup-wizard.d.ts.map +0 -1
  126. package/dist/setup-wizard.js +0 -130
  127. package/dist/setup-wizard.js.map +0 -1
  128. package/dist/sqlite.d.ts.map +0 -1
  129. package/dist/sqlite.js.map +0 -1
  130. package/dist/supervisor.d.ts.map +0 -1
  131. package/dist/supervisor.js.map +0 -1
  132. package/dist/testkit.d.ts.map +0 -1
  133. package/dist/testkit.js.map +0 -1
  134. package/dist/tui-theme.d.ts +0 -16
  135. package/dist/tui-theme.d.ts.map +0 -1
  136. package/dist/tui-theme.js +0 -18
  137. package/dist/tui-theme.js.map +0 -1
  138. package/dist/tui.d.ts +0 -18
  139. package/dist/tui.d.ts.map +0 -1
  140. package/dist/tui.js +0 -583
  141. package/dist/tui.js.map +0 -1
  142. package/dist/update.d.ts +0 -15
  143. package/dist/update.d.ts.map +0 -1
  144. package/dist/update.js +0 -59
  145. package/dist/update.js.map +0 -1
  146. package/dist/web-console.d.ts +0 -33
  147. package/dist/web-console.d.ts.map +0 -1
  148. package/dist/web-console.js +0 -252
  149. package/dist/web-console.js.map +0 -1
  150. package/dist/welcome.d.ts +0 -30
  151. package/dist/welcome.d.ts.map +0 -1
  152. package/dist/welcome.js +0 -81
  153. package/dist/welcome.js.map +0 -1
  154. package/node_modules/goah-ledger-contract/dist/execution.d.ts +0 -402
  155. package/node_modules/goah-ledger-contract/dist/execution.d.ts.map +0 -1
  156. package/node_modules/goah-ledger-contract/dist/execution.js +0 -40
  157. package/node_modules/goah-ledger-contract/dist/execution.js.map +0 -1
  158. package/node_modules/goah-ledger-contract/dist/index.d.ts +0 -5
  159. package/node_modules/goah-ledger-contract/dist/index.d.ts.map +0 -1
  160. package/node_modules/goah-ledger-contract/dist/index.js +0 -5
  161. package/node_modules/goah-ledger-contract/dist/index.js.map +0 -1
  162. package/node_modules/goah-ledger-contract/dist/kernel.d.ts +0 -37
  163. package/node_modules/goah-ledger-contract/dist/kernel.d.ts.map +0 -1
  164. package/node_modules/goah-ledger-contract/dist/kernel.js +0 -8
  165. package/node_modules/goah-ledger-contract/dist/kernel.js.map +0 -1
  166. package/node_modules/goah-ledger-contract/dist/metrics.d.ts +0 -40
  167. package/node_modules/goah-ledger-contract/dist/metrics.d.ts.map +0 -1
  168. package/node_modules/goah-ledger-contract/dist/metrics.js +0 -25
  169. package/node_modules/goah-ledger-contract/dist/metrics.js.map +0 -1
  170. package/node_modules/goah-ledger-contract/dist/session.d.ts +0 -63
  171. package/node_modules/goah-ledger-contract/dist/session.d.ts.map +0 -1
  172. package/node_modules/goah-ledger-contract/dist/session.js +0 -115
  173. package/node_modules/goah-ledger-contract/dist/session.js.map +0 -1
  174. package/node_modules/goah-ledger-contract/package.json +0 -29
  175. package/node_modules/goah-ledger-sqlite/dist/index.d.ts +0 -77
  176. package/node_modules/goah-ledger-sqlite/dist/index.d.ts.map +0 -1
  177. package/node_modules/goah-ledger-sqlite/dist/index.js +0 -884
  178. package/node_modules/goah-ledger-sqlite/dist/index.js.map +0 -1
  179. package/node_modules/goah-ledger-sqlite/package.json +0 -26
  180. package/node_modules/goah-runner-pi/dist/configurator.d.ts +0 -20
  181. package/node_modules/goah-runner-pi/dist/configurator.d.ts.map +0 -1
  182. package/node_modules/goah-runner-pi/dist/configurator.js +0 -267
  183. package/node_modules/goah-runner-pi/dist/configurator.js.map +0 -1
  184. package/node_modules/goah-runner-pi/dist/credential-store.d.ts +0 -12
  185. package/node_modules/goah-runner-pi/dist/credential-store.d.ts.map +0 -1
  186. package/node_modules/goah-runner-pi/dist/credential-store.js +0 -69
  187. package/node_modules/goah-runner-pi/dist/credential-store.js.map +0 -1
  188. package/node_modules/goah-runner-pi/dist/env-spec.d.ts +0 -17
  189. package/node_modules/goah-runner-pi/dist/env-spec.d.ts.map +0 -1
  190. package/node_modules/goah-runner-pi/dist/env-spec.js +0 -95
  191. package/node_modules/goah-runner-pi/dist/env-spec.js.map +0 -1
  192. package/node_modules/goah-runner-pi/dist/index.d.ts +0 -64
  193. package/node_modules/goah-runner-pi/dist/index.d.ts.map +0 -1
  194. package/node_modules/goah-runner-pi/dist/index.js +0 -241
  195. package/node_modules/goah-runner-pi/dist/index.js.map +0 -1
  196. package/node_modules/goah-runner-pi/dist/model-provider.d.ts +0 -30
  197. package/node_modules/goah-runner-pi/dist/model-provider.d.ts.map +0 -1
  198. package/node_modules/goah-runner-pi/dist/model-provider.js +0 -96
  199. package/node_modules/goah-runner-pi/dist/model-provider.js.map +0 -1
  200. package/node_modules/goah-runner-pi/dist/pi-worker.d.ts +0 -29
  201. package/node_modules/goah-runner-pi/dist/pi-worker.d.ts.map +0 -1
  202. package/node_modules/goah-runner-pi/dist/pi-worker.js +0 -428
  203. package/node_modules/goah-runner-pi/dist/pi-worker.js.map +0 -1
  204. package/node_modules/goah-runner-pi/dist/test-helpers.d.ts +0 -4
  205. package/node_modules/goah-runner-pi/dist/test-helpers.d.ts.map +0 -1
  206. package/node_modules/goah-runner-pi/dist/test-helpers.js +0 -11
  207. package/node_modules/goah-runner-pi/dist/test-helpers.js.map +0 -1
  208. package/node_modules/goah-runner-pi/dist/verification-worker.d.ts +0 -2
  209. package/node_modules/goah-runner-pi/dist/verification-worker.d.ts.map +0 -1
  210. package/node_modules/goah-runner-pi/dist/verification-worker.js +0 -48
  211. package/node_modules/goah-runner-pi/dist/verification-worker.js.map +0 -1
  212. package/node_modules/goah-runner-pi/package.json +0 -28
  213. package/node_modules/goah-supervisor/dist/context-view.d.ts +0 -31
  214. package/node_modules/goah-supervisor/dist/context-view.d.ts.map +0 -1
  215. package/node_modules/goah-supervisor/dist/context-view.js +0 -71
  216. package/node_modules/goah-supervisor/dist/context-view.js.map +0 -1
  217. package/node_modules/goah-supervisor/dist/index.d.ts +0 -94
  218. package/node_modules/goah-supervisor/dist/index.d.ts.map +0 -1
  219. package/node_modules/goah-supervisor/dist/index.js +0 -888
  220. package/node_modules/goah-supervisor/dist/index.js.map +0 -1
  221. package/node_modules/goah-supervisor/dist/roles.d.ts +0 -3
  222. package/node_modules/goah-supervisor/dist/roles.d.ts.map +0 -1
  223. package/node_modules/goah-supervisor/dist/roles.js +0 -14
  224. package/node_modules/goah-supervisor/dist/roles.js.map +0 -1
  225. package/node_modules/goah-supervisor/dist/verification.d.ts +0 -82
  226. package/node_modules/goah-supervisor/dist/verification.d.ts.map +0 -1
  227. package/node_modules/goah-supervisor/dist/verification.js +0 -110
  228. package/node_modules/goah-supervisor/dist/verification.js.map +0 -1
  229. package/node_modules/goah-supervisor/package.json +0 -26
  230. package/node_modules/goah-testkit/dist/faux-runner-worker.d.ts +0 -2
  231. package/node_modules/goah-testkit/dist/faux-runner-worker.d.ts.map +0 -1
  232. package/node_modules/goah-testkit/dist/faux-runner-worker.js +0 -75
  233. package/node_modules/goah-testkit/dist/faux-runner-worker.js.map +0 -1
  234. package/node_modules/goah-testkit/dist/index.d.ts +0 -52
  235. package/node_modules/goah-testkit/dist/index.d.ts.map +0 -1
  236. package/node_modules/goah-testkit/dist/index.js +0 -113
  237. package/node_modules/goah-testkit/dist/index.js.map +0 -1
  238. package/node_modules/goah-testkit/dist/mock-connector-worker.d.ts +0 -2
  239. package/node_modules/goah-testkit/dist/mock-connector-worker.d.ts.map +0 -1
  240. package/node_modules/goah-testkit/dist/mock-connector-worker.js +0 -29
  241. package/node_modules/goah-testkit/dist/mock-connector-worker.js.map +0 -1
  242. package/node_modules/goah-testkit/package.json +0 -29
@@ -0,0 +1,300 @@
1
+ import { createRequire as __goahCreateRequire } from "node:module";
2
+ const require = __goahCreateRequire(import.meta.url);
3
+ import {
4
+ splitDeferredTools
5
+ } from "./chunk-LKBKZEHT.js";
6
+ import {
7
+ buildCopilotDynamicHeaders,
8
+ hasCopilotVisionInput
9
+ } from "./chunk-JQD5EWJY.js";
10
+ import {
11
+ convertResponsesMessages,
12
+ convertResponsesTools,
13
+ processResponsesStream
14
+ } from "./chunk-25XSBFX6.js";
15
+ import {
16
+ clampOpenAIPromptCacheKey
17
+ } from "./chunk-7AXAFDPG.js";
18
+ import "./chunk-4US7ZHT3.js";
19
+ import {
20
+ OpenAI
21
+ } from "./chunk-LBKI23CC.js";
22
+ import {
23
+ formatProviderError,
24
+ normalizeProviderError
25
+ } from "./chunk-H462EFJP.js";
26
+ import {
27
+ buildBaseOptions,
28
+ createGrammarToolInputProperties
29
+ } from "./chunk-BXA47DTF.js";
30
+ import {
31
+ retryProviderRequest
32
+ } from "./chunk-4M6TXTT5.js";
33
+ import "./chunk-NRLGWZJC.js";
34
+ import {
35
+ headersToRecord
36
+ } from "./chunk-FSBUS2BI.js";
37
+ import {
38
+ getProviderEnvValue
39
+ } from "./chunk-IIJQ3DW4.js";
40
+ import "./chunk-2ZP2NBW3.js";
41
+ import {
42
+ clampThinkingLevel
43
+ } from "./chunk-MPXK7QBL.js";
44
+ import {
45
+ AssistantMessageEventStream
46
+ } from "./chunk-2QBQZGXF.js";
47
+ import "./chunk-XPQKM3L7.js";
48
+
49
+ // ../../node_modules/@earendil-works/pi-ai/dist/api/openai-responses.js
50
+ var OPENAI_TOOL_CALL_PROVIDERS = /* @__PURE__ */ new Set(["openai", "openai-codex", "opencode"]);
51
+ var OPENAI_RESPONSES_MIN_OUTPUT_TOKENS = 16;
52
+ function hasHeader(headers, name) {
53
+ if (!headers)
54
+ return false;
55
+ const expected = name.toLowerCase();
56
+ for (const [key, value] of Object.entries(headers)) {
57
+ if (key.toLowerCase() === expected && value !== null && value.trim().length > 0)
58
+ return true;
59
+ }
60
+ return false;
61
+ }
62
+ function getClientApiKey(provider, apiKey, headers) {
63
+ if (apiKey)
64
+ return apiKey;
65
+ if (hasHeader(headers, "authorization") || hasHeader(headers, "cf-aig-authorization"))
66
+ return "unused";
67
+ throw new Error(`No API key for provider: ${provider}`);
68
+ }
69
+ function detectSessionAffinityFormat(model) {
70
+ return model.provider === "openrouter" || model.baseUrl.includes("openrouter.ai") ? "openrouter" : "openai";
71
+ }
72
+ function resolveCacheRetention(cacheRetention, env) {
73
+ if (cacheRetention) {
74
+ return cacheRetention;
75
+ }
76
+ if (getProviderEnvValue("PI_CACHE_RETENTION", env) === "long") {
77
+ return "long";
78
+ }
79
+ return "short";
80
+ }
81
+ function getCompat(model) {
82
+ return {
83
+ supportsDeveloperRole: model.compat?.supportsDeveloperRole ?? true,
84
+ sessionAffinityFormat: model.compat?.sessionAffinityFormat ?? detectSessionAffinityFormat(model),
85
+ supportsLongCacheRetention: model.compat?.supportsLongCacheRetention ?? true,
86
+ supportsStrictMode: model.compat?.supportsStrictMode ?? false,
87
+ supportsOpenAIGrammarTools: model.compat?.supportsOpenAIGrammarTools ?? false,
88
+ supportsAdditionalTools: model.compat?.supportsAdditionalTools ?? false,
89
+ supportsToolSearch: model.compat?.supportsToolSearch ?? false,
90
+ supportsExplicitPromptCacheMode: model.compat?.supportsExplicitPromptCacheMode ?? false
91
+ };
92
+ }
93
+ function getPromptCacheRetention(compat, cacheRetention) {
94
+ return cacheRetention === "long" && compat.supportsLongCacheRetention ? "24h" : void 0;
95
+ }
96
+ function formatOpenAIResponsesError(error) {
97
+ return formatProviderError(normalizeProviderError(error), "OpenAI API error");
98
+ }
99
+ var stream = (model, context, options) => {
100
+ const stream2 = new AssistantMessageEventStream();
101
+ (async () => {
102
+ const output = {
103
+ role: "assistant",
104
+ content: [],
105
+ api: model.api,
106
+ provider: model.provider,
107
+ model: model.id,
108
+ usage: {
109
+ input: 0,
110
+ output: 0,
111
+ cacheRead: 0,
112
+ cacheWrite: 0,
113
+ totalTokens: 0,
114
+ cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 }
115
+ },
116
+ stopReason: "pending",
117
+ timestamp: Date.now()
118
+ };
119
+ try {
120
+ const apiKey = getClientApiKey(model.provider, options?.apiKey, options?.headers);
121
+ const cacheRetention = resolveCacheRetention(options?.cacheRetention, options?.env);
122
+ const cacheSessionId = cacheRetention === "none" ? void 0 : options?.sessionId;
123
+ const compat = getCompat(model);
124
+ const grammarToolInputProperties = createGrammarToolInputProperties(context.tools, compat.supportsOpenAIGrammarTools);
125
+ const client = createClient(model, context, apiKey, options?.headers, options?.fetch, cacheSessionId);
126
+ let params = buildParams(model, context, options, compat, grammarToolInputProperties);
127
+ const nextParams = await options?.onPayload?.(params, model);
128
+ if (nextParams !== void 0) {
129
+ params = nextParams;
130
+ }
131
+ const requestOptions = {
132
+ ...options?.signal ? { signal: options.signal } : {},
133
+ ...options?.timeoutMs !== void 0 ? { timeout: options.timeoutMs } : {},
134
+ maxRetries: 0
135
+ };
136
+ const { data: openaiStream, response } = await retryProviderRequest(() => client.responses.create(params, requestOptions).withResponse(), {
137
+ maxRetries: options?.maxRetries,
138
+ maxRetryDelayMs: options?.maxRetryDelayMs,
139
+ signal: options?.signal
140
+ });
141
+ await options?.onResponse?.({ status: response.status, headers: headersToRecord(response.headers) }, model);
142
+ stream2.push({ type: "start", partial: output });
143
+ await processResponsesStream(openaiStream, output, stream2, model, {
144
+ serviceTier: options?.serviceTier,
145
+ grammarToolInputProperties,
146
+ applyServiceTierPricing: (usage, serviceTier) => applyServiceTierPricing(usage, serviceTier, model)
147
+ });
148
+ if (options?.signal?.aborted) {
149
+ throw new Error("Request was aborted");
150
+ }
151
+ if (output.stopReason === "pending") {
152
+ throw new Error("OpenAI Responses stream ended without a stop reason");
153
+ }
154
+ if (output.stopReason === "aborted" || output.stopReason === "error") {
155
+ throw new Error(output.errorMessage || "An unknown error occurred");
156
+ }
157
+ stream2.push({ type: "done", reason: output.stopReason, message: output });
158
+ stream2.end();
159
+ } catch (error) {
160
+ for (const block of output.content) {
161
+ delete block.index;
162
+ delete block.partialJson;
163
+ delete block.customInput;
164
+ }
165
+ output.stopReason = options?.signal?.aborted ? "aborted" : "error";
166
+ output.errorMessage = formatOpenAIResponsesError(error);
167
+ stream2.push({ type: "error", reason: output.stopReason, error: output });
168
+ stream2.end();
169
+ }
170
+ })();
171
+ return stream2;
172
+ };
173
+ var streamSimple = (model, context, options) => {
174
+ getClientApiKey(model.provider, options?.apiKey, options?.headers);
175
+ const base = buildBaseOptions(model, context, options, options?.apiKey);
176
+ const clampedReasoning = options?.reasoning ? clampThinkingLevel(model, options.reasoning) : void 0;
177
+ const reasoningEffort = clampedReasoning === "off" ? void 0 : clampedReasoning;
178
+ return stream(model, context, {
179
+ ...base,
180
+ reasoningEffort
181
+ });
182
+ };
183
+ function createClient(model, context, apiKey, optionsHeaders, fetch, sessionId) {
184
+ const compat = getCompat(model);
185
+ const headers = { ...model.headers };
186
+ if (model.provider === "github-copilot") {
187
+ const hasImages = hasCopilotVisionInput(context.messages);
188
+ const copilotHeaders = buildCopilotDynamicHeaders({
189
+ messages: context.messages,
190
+ hasImages
191
+ });
192
+ Object.assign(headers, copilotHeaders);
193
+ }
194
+ if (sessionId) {
195
+ if (compat.sessionAffinityFormat === "openrouter") {
196
+ headers["x-session-id"] = sessionId;
197
+ } else {
198
+ if (compat.sessionAffinityFormat === "openai") {
199
+ headers.session_id = sessionId;
200
+ }
201
+ headers["x-client-request-id"] = sessionId;
202
+ }
203
+ }
204
+ if (optionsHeaders) {
205
+ Object.assign(headers, optionsHeaders);
206
+ }
207
+ return new OpenAI({
208
+ apiKey,
209
+ baseURL: model.baseUrl,
210
+ dangerouslyAllowBrowser: true,
211
+ fetch,
212
+ defaultHeaders: headers
213
+ });
214
+ }
215
+ function buildParams(model, context, options, compat = getCompat(model), grammarToolInputProperties = createGrammarToolInputProperties(context.tools, compat.supportsOpenAIGrammarTools)) {
216
+ const deferredToolsMode = compat.supportsAdditionalTools ? "additional-tools" : compat.supportsToolSearch ? "tool-search" : void 0;
217
+ const toolPlacement = splitDeferredTools(context, deferredToolsMode !== void 0);
218
+ const messages = convertResponsesMessages(model, context, OPENAI_TOOL_CALL_PROVIDERS, {
219
+ grammarToolInputProperties,
220
+ deferredTools: toolPlacement.deferred,
221
+ deferredToolsMode,
222
+ toolOptions: {
223
+ supportsStrictMode: compat.supportsStrictMode,
224
+ supportsOpenAIGrammarTools: compat.supportsOpenAIGrammarTools
225
+ }
226
+ });
227
+ const cacheRetention = resolveCacheRetention(options?.cacheRetention, options?.env);
228
+ const disableImplicitPromptCache = cacheRetention === "none" && compat.supportsExplicitPromptCacheMode;
229
+ const params = {
230
+ model: model.id,
231
+ input: messages,
232
+ stream: true,
233
+ prompt_cache_key: cacheRetention === "none" ? void 0 : clampOpenAIPromptCacheKey(options?.sessionId),
234
+ prompt_cache_retention: getPromptCacheRetention(compat, cacheRetention),
235
+ prompt_cache_options: disableImplicitPromptCache ? { mode: "explicit" } : void 0,
236
+ store: false
237
+ };
238
+ if (options?.maxTokens) {
239
+ params.max_output_tokens = Math.max(options.maxTokens, OPENAI_RESPONSES_MIN_OUTPUT_TOKENS);
240
+ }
241
+ if (options?.temperature !== void 0) {
242
+ params.temperature = options?.temperature;
243
+ }
244
+ if (options?.serviceTier !== void 0) {
245
+ params.service_tier = options.serviceTier;
246
+ }
247
+ if (toolPlacement.immediate.length > 0) {
248
+ params.tools = convertResponsesTools(toolPlacement.immediate, {
249
+ supportsStrictMode: compat.supportsStrictMode,
250
+ supportsOpenAIGrammarTools: compat.supportsOpenAIGrammarTools
251
+ });
252
+ }
253
+ if (options?.toolChoice !== void 0) {
254
+ params.tool_choice = options.toolChoice;
255
+ }
256
+ if (model.reasoning) {
257
+ if (options?.reasoningEffort || options?.reasoningSummary) {
258
+ const effort = options?.reasoningEffort ? model.thinkingLevelMap?.[options.reasoningEffort] ?? options.reasoningEffort : "medium";
259
+ params.reasoning = {
260
+ effort,
261
+ summary: options?.reasoningSummary || "auto"
262
+ };
263
+ params.include = ["reasoning.encrypted_content"];
264
+ } else if (model.provider !== "github-copilot" && model.thinkingLevelMap?.off !== null) {
265
+ params.reasoning = {
266
+ effort: model.thinkingLevelMap?.off ?? "none"
267
+ };
268
+ }
269
+ if (model.provider === "xai")
270
+ params.include = ["reasoning.encrypted_content"];
271
+ }
272
+ if (options?.samplingParams) {
273
+ Object.assign(params, options.samplingParams);
274
+ }
275
+ return params;
276
+ }
277
+ function getServiceTierCostMultiplier(model, serviceTier) {
278
+ switch (serviceTier) {
279
+ case "flex":
280
+ return 0.5;
281
+ case "priority":
282
+ return model.id === "gpt-5.5" ? 2.5 : 2;
283
+ default:
284
+ return 1;
285
+ }
286
+ }
287
+ function applyServiceTierPricing(usage, serviceTier, model) {
288
+ const multiplier = getServiceTierCostMultiplier(model, serviceTier);
289
+ if (multiplier === 1)
290
+ return;
291
+ usage.cost.input *= multiplier;
292
+ usage.cost.output *= multiplier;
293
+ usage.cost.cacheRead *= multiplier;
294
+ usage.cost.cacheWrite *= multiplier;
295
+ usage.cost.total = usage.cost.input + usage.cost.output + usage.cost.cacheRead + usage.cost.cacheWrite;
296
+ }
297
+ export {
298
+ stream,
299
+ streamSimple
300
+ };
@@ -0,0 +1,148 @@
1
+ import { createRequire as __goahCreateRequire } from "node:module";
2
+ const require = __goahCreateRequire(import.meta.url);
3
+ import {
4
+ OpenAI
5
+ } from "./chunk-LBKI23CC.js";
6
+ import {
7
+ formatProviderError,
8
+ normalizeProviderError
9
+ } from "./chunk-H462EFJP.js";
10
+ import {
11
+ retryProviderRequest
12
+ } from "./chunk-4M6TXTT5.js";
13
+ import {
14
+ sanitizeSurrogates
15
+ } from "./chunk-NRLGWZJC.js";
16
+ import {
17
+ headersToRecord,
18
+ providerHeadersToRecord
19
+ } from "./chunk-FSBUS2BI.js";
20
+ import "./chunk-XPQKM3L7.js";
21
+
22
+ // ../../node_modules/@earendil-works/pi-ai/dist/api/openrouter-images.js
23
+ var generateImages = async (model, context, options) => {
24
+ const output = {
25
+ api: model.api,
26
+ provider: model.provider,
27
+ model: model.id,
28
+ output: [],
29
+ stopReason: "stop",
30
+ timestamp: Date.now()
31
+ };
32
+ try {
33
+ const apiKey = options?.apiKey;
34
+ if (!apiKey) {
35
+ throw new Error(`No API key for provider: ${model.provider}`);
36
+ }
37
+ const client = createClient(model, apiKey, options?.headers, options?.fetch);
38
+ let params = buildParams(model, context);
39
+ const nextParams = await options?.onPayload?.(params, model);
40
+ if (nextParams !== void 0) {
41
+ params = nextParams;
42
+ }
43
+ const requestOptions = {
44
+ ...options?.signal ? { signal: options.signal } : {},
45
+ ...options?.timeoutMs !== void 0 ? { timeout: options.timeoutMs } : {},
46
+ maxRetries: 0
47
+ };
48
+ const { data: response, response: rawResponse } = await retryProviderRequest(() => client.chat.completions.create(params, requestOptions).withResponse(), {
49
+ maxRetries: options?.maxRetries,
50
+ maxRetryDelayMs: options?.maxRetryDelayMs,
51
+ signal: options?.signal
52
+ });
53
+ await options?.onResponse?.({ status: rawResponse.status, headers: headersToRecord(rawResponse.headers) }, model);
54
+ const imageResponse = response;
55
+ output.responseId = imageResponse.id;
56
+ if (imageResponse.usage) {
57
+ output.usage = parseUsage(imageResponse.usage, model);
58
+ }
59
+ const choice = imageResponse.choices[0];
60
+ if (choice) {
61
+ const content = choice.message.content;
62
+ if (typeof content === "string" && content.length > 0) {
63
+ output.output.push({ type: "text", text: content });
64
+ }
65
+ for (const image of choice.message.images ?? []) {
66
+ const imageUrl = typeof image.image_url === "string" ? image.image_url : image.image_url?.url;
67
+ if (!imageUrl?.startsWith("data:"))
68
+ continue;
69
+ const matches = imageUrl.match(/^data:([^;]+);base64,(.+)$/);
70
+ if (!matches)
71
+ continue;
72
+ output.output.push({
73
+ type: "image",
74
+ mimeType: matches[1],
75
+ data: matches[2]
76
+ });
77
+ }
78
+ }
79
+ return output;
80
+ } catch (error) {
81
+ output.stopReason = options?.signal?.aborted ? "aborted" : "error";
82
+ output.errorMessage = formatProviderError(normalizeProviderError(error));
83
+ return output;
84
+ }
85
+ };
86
+ function createClient(model, apiKey, optionsHeaders, fetch) {
87
+ return new OpenAI({
88
+ apiKey,
89
+ baseURL: model.baseUrl,
90
+ dangerouslyAllowBrowser: true,
91
+ fetch,
92
+ defaultHeaders: providerHeadersToRecord({ ...model.headers, ...optionsHeaders })
93
+ });
94
+ }
95
+ function buildParams(model, context) {
96
+ const content = context.input.map((item) => {
97
+ if (item.type === "text") {
98
+ return {
99
+ type: "text",
100
+ text: sanitizeSurrogates(item.text)
101
+ };
102
+ }
103
+ return {
104
+ type: "image_url",
105
+ image_url: {
106
+ url: `data:${item.mimeType};base64,${item.data}`
107
+ }
108
+ };
109
+ });
110
+ return {
111
+ model: model.id,
112
+ messages: [
113
+ {
114
+ role: "user",
115
+ content
116
+ }
117
+ ],
118
+ stream: false,
119
+ modalities: model.output.includes("text") ? ["image", "text"] : ["image"]
120
+ };
121
+ }
122
+ function parseUsage(rawUsage, model) {
123
+ const promptTokens = rawUsage.prompt_tokens || 0;
124
+ const reportedCachedTokens = rawUsage.prompt_tokens_details?.cached_tokens || 0;
125
+ const cacheWriteTokens = rawUsage.prompt_tokens_details?.cache_write_tokens || 0;
126
+ const cacheReadTokens = cacheWriteTokens > 0 ? Math.max(0, reportedCachedTokens - cacheWriteTokens) : reportedCachedTokens;
127
+ const input = Math.max(0, promptTokens - cacheReadTokens - cacheWriteTokens);
128
+ const output = rawUsage.completion_tokens || 0;
129
+ const usage = {
130
+ input,
131
+ output,
132
+ cacheRead: cacheReadTokens,
133
+ cacheWrite: cacheWriteTokens,
134
+ totalTokens: input + output + cacheReadTokens + cacheWriteTokens,
135
+ cost: {
136
+ input: model.cost.input / 1e6 * input,
137
+ output: model.cost.output / 1e6 * output,
138
+ cacheRead: model.cost.cacheRead / 1e6 * cacheReadTokens,
139
+ cacheWrite: model.cost.cacheWrite / 1e6 * cacheWriteTokens,
140
+ total: 0
141
+ }
142
+ };
143
+ usage.cost.total = usage.cost.input + usage.cost.output + usage.cost.cacheRead + usage.cost.cacheWrite;
144
+ return usage;
145
+ }
146
+ export {
147
+ generateImages
148
+ };