@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.
- package/dist/LICENSE +201 -0
- package/dist/THIRD-PARTY-NOTICES.md +2319 -0
- package/dist/anthropic-messages-WBFOHES5.js +7214 -0
- package/dist/azure-openai-responses-NZFH3PO6.js +253 -0
- package/dist/chunk-25XSBFX6.js +639 -0
- package/dist/chunk-2QBQZGXF.js +110 -0
- package/dist/chunk-2ZP2NBW3.js +345 -0
- package/dist/chunk-4KA63VNZ.js +2 -0
- package/dist/chunk-4M6TXTT5.js +86 -0
- package/dist/chunk-4US7ZHT3.js +20 -0
- package/dist/chunk-6M3OOCKO.js +11809 -0
- package/dist/chunk-7AXAFDPG.js +17 -0
- package/dist/chunk-BXA47DTF.js +548 -0
- package/dist/chunk-FSBUS2BI.js +26 -0
- package/dist/chunk-GKDRAHLI.js +4787 -0
- package/dist/chunk-H462EFJP.js +89 -0
- package/dist/chunk-IIJQ3DW4.js +35 -0
- package/dist/chunk-JQD5EWJY.js +34 -0
- package/dist/chunk-K26BVR6O.js +61 -0
- package/dist/chunk-KAO7WIXG.js +31 -0
- package/dist/chunk-LBKI23CC.js +9810 -0
- package/dist/chunk-LKBKZEHT.js +41 -0
- package/dist/chunk-MD7TLTXZ.js +18 -0
- package/dist/chunk-MPXK7QBL.js +868 -0
- package/dist/chunk-NRLGWZJC.js +11 -0
- package/dist/chunk-PFEV3HWI.js +1178 -0
- package/dist/chunk-QBD6EJ2Z.js +1746 -0
- package/dist/chunk-R6I3VKME.js +132 -0
- package/dist/chunk-TJON22J4.js +87 -0
- package/dist/chunk-ULY36ME4.js +33097 -0
- package/dist/chunk-VWEV4LTH.js +25 -0
- package/dist/chunk-X7UWW2PN.js +883 -0
- package/dist/chunk-XALZLRYK.js +9221 -0
- package/dist/chunk-XPQKM3L7.js +57 -0
- package/dist/chunk-YH6YJ2IB.js +1773 -0
- package/dist/cli.d.ts +0 -2
- package/dist/cli.js +13123 -580
- package/dist/console/assets/{index-Rtc_B7cs.js → index-B1vGMXKr.js} +11 -11
- package/dist/console/assets/{index-Rtc_B7cs.js.map → index-B1vGMXKr.js.map} +1 -1
- package/dist/console/index.html +1 -1
- package/dist/dist-65MDQA4Q.js +1126 -0
- package/dist/dist-KNR2XL6J.js +39 -0
- package/dist/execution.d.ts +557 -2
- package/dist/execution.js +37 -2
- package/dist/faux-runner-worker.js +128 -0
- package/dist/google-generative-ai-YMHXZSFE.js +422 -0
- package/dist/google-vertex-X6DB3ZQ6.js +471 -0
- package/dist/index.d.ts +853 -25
- package/dist/index.js +84 -385
- package/dist/kernel.d.ts +39 -2
- package/dist/kernel.js +21 -2
- package/dist/mistral-conversations-TY3MMD6G.js +718 -0
- package/dist/multipart-parser-F6M4NJZU.js +373 -0
- package/dist/openai-codex-responses-BRDUMLN5.js +1374 -0
- package/dist/openai-completions-CX634XN3.js +1139 -0
- package/dist/openai-responses-HMCXJIHT.js +300 -0
- package/dist/openrouter-images-KTWET2H2.js +148 -0
- package/dist/pi-messages-XL5OEC4K.js +307 -0
- package/dist/pi-worker.js +671 -0
- package/dist/runner-pi.d.ts +342 -2
- package/dist/runner-pi.js +46 -2
- package/dist/runner-registry-M776E3SE.js +22 -0
- package/dist/sqlite.d.ts +446 -2
- package/dist/sqlite.js +15 -2
- package/dist/src-F2KBSV4T.js +1398 -0
- package/dist/supervisor.d.ts +625 -2
- package/dist/supervisor.js +39 -2
- package/dist/testkit.d.ts +564 -2
- package/dist/testkit.js +127 -2
- package/dist/transcript.d.ts +84 -2
- package/dist/transcript.js +25 -2
- package/dist/verification-worker.js +72 -0
- package/package.json +2 -26
- package/dist/cli.d.ts.map +0 -1
- package/dist/cli.js.map +0 -1
- package/dist/control.d.ts +0 -106
- package/dist/control.d.ts.map +0 -1
- package/dist/control.js +0 -242
- package/dist/control.js.map +0 -1
- package/dist/execution.d.ts.map +0 -1
- package/dist/execution.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/kernel.d.ts.map +0 -1
- package/dist/kernel.js.map +0 -1
- package/dist/live-config.d.ts +0 -10
- package/dist/live-config.d.ts.map +0 -1
- package/dist/live-config.js +0 -44
- package/dist/live-config.js.map +0 -1
- package/dist/prompt-queue.d.ts +0 -13
- package/dist/prompt-queue.d.ts.map +0 -1
- package/dist/prompt-queue.js +0 -35
- package/dist/prompt-queue.js.map +0 -1
- package/dist/runner-pi.d.ts.map +0 -1
- package/dist/runner-pi.js.map +0 -1
- package/dist/runner-registry.d.ts +0 -8
- package/dist/runner-registry.d.ts.map +0 -1
- package/dist/runner-registry.js +0 -12
- package/dist/runner-registry.js.map +0 -1
- package/dist/searchable-select.d.ts +0 -24
- package/dist/searchable-select.d.ts.map +0 -1
- package/dist/searchable-select.js +0 -61
- package/dist/searchable-select.js.map +0 -1
- package/dist/secret-input.d.ts +0 -8
- package/dist/secret-input.d.ts.map +0 -1
- package/dist/secret-input.js +0 -14
- package/dist/secret-input.js.map +0 -1
- package/dist/setup-wizard.d.ts +0 -22
- package/dist/setup-wizard.d.ts.map +0 -1
- package/dist/setup-wizard.js +0 -154
- package/dist/setup-wizard.js.map +0 -1
- package/dist/sqlite.d.ts.map +0 -1
- package/dist/sqlite.js.map +0 -1
- package/dist/supervisor.d.ts.map +0 -1
- package/dist/supervisor.js.map +0 -1
- package/dist/testkit.d.ts.map +0 -1
- package/dist/testkit.js.map +0 -1
- package/dist/thread-inspect.d.ts +0 -47
- package/dist/thread-inspect.d.ts.map +0 -1
- package/dist/thread-inspect.js +0 -78
- package/dist/thread-inspect.js.map +0 -1
- package/dist/transcript.d.ts.map +0 -1
- package/dist/transcript.js.map +0 -1
- package/dist/tui-theme.d.ts +0 -17
- package/dist/tui-theme.d.ts.map +0 -1
- package/dist/tui-theme.js +0 -19
- package/dist/tui-theme.js.map +0 -1
- package/dist/tui.d.ts +0 -24
- package/dist/tui.d.ts.map +0 -1
- package/dist/tui.js +0 -784
- package/dist/tui.js.map +0 -1
- package/dist/update.d.ts +0 -16
- package/dist/update.d.ts.map +0 -1
- package/dist/update.js +0 -67
- package/dist/update.js.map +0 -1
- package/dist/web-console.d.ts +0 -33
- package/dist/web-console.d.ts.map +0 -1
- package/dist/web-console.js +0 -242
- package/dist/web-console.js.map +0 -1
- package/dist/welcome.d.ts +0 -30
- package/dist/welcome.d.ts.map +0 -1
- package/dist/welcome.js +0 -69
- package/dist/welcome.js.map +0 -1
- package/node_modules/goah-ledger-contract/dist/execution.d.ts +0 -544
- package/node_modules/goah-ledger-contract/dist/execution.d.ts.map +0 -1
- package/node_modules/goah-ledger-contract/dist/execution.js +0 -52
- package/node_modules/goah-ledger-contract/dist/execution.js.map +0 -1
- package/node_modules/goah-ledger-contract/dist/index.d.ts +0 -4
- package/node_modules/goah-ledger-contract/dist/index.d.ts.map +0 -1
- package/node_modules/goah-ledger-contract/dist/index.js +0 -4
- package/node_modules/goah-ledger-contract/dist/index.js.map +0 -1
- package/node_modules/goah-ledger-contract/dist/kernel.d.ts +0 -37
- package/node_modules/goah-ledger-contract/dist/kernel.d.ts.map +0 -1
- package/node_modules/goah-ledger-contract/dist/kernel.js +0 -8
- package/node_modules/goah-ledger-contract/dist/kernel.js.map +0 -1
- package/node_modules/goah-ledger-contract/dist/transcript.d.ts +0 -63
- package/node_modules/goah-ledger-contract/dist/transcript.d.ts.map +0 -1
- package/node_modules/goah-ledger-contract/dist/transcript.js +0 -115
- package/node_modules/goah-ledger-contract/dist/transcript.js.map +0 -1
- package/node_modules/goah-ledger-contract/package.json +0 -28
- package/node_modules/goah-ledger-sqlite/dist/index.d.ts +0 -86
- package/node_modules/goah-ledger-sqlite/dist/index.d.ts.map +0 -1
- package/node_modules/goah-ledger-sqlite/dist/index.js +0 -1254
- package/node_modules/goah-ledger-sqlite/dist/index.js.map +0 -1
- package/node_modules/goah-ledger-sqlite/package.json +0 -26
- package/node_modules/goah-runner-pi/dist/configurator.d.ts +0 -20
- package/node_modules/goah-runner-pi/dist/configurator.d.ts.map +0 -1
- package/node_modules/goah-runner-pi/dist/configurator.js +0 -423
- package/node_modules/goah-runner-pi/dist/configurator.js.map +0 -1
- package/node_modules/goah-runner-pi/dist/credential-store.d.ts +0 -14
- package/node_modules/goah-runner-pi/dist/credential-store.d.ts.map +0 -1
- package/node_modules/goah-runner-pi/dist/credential-store.js +0 -163
- package/node_modules/goah-runner-pi/dist/credential-store.js.map +0 -1
- package/node_modules/goah-runner-pi/dist/env-spec.d.ts +0 -17
- package/node_modules/goah-runner-pi/dist/env-spec.d.ts.map +0 -1
- package/node_modules/goah-runner-pi/dist/env-spec.js +0 -95
- package/node_modules/goah-runner-pi/dist/env-spec.js.map +0 -1
- package/node_modules/goah-runner-pi/dist/index.d.ts +0 -76
- package/node_modules/goah-runner-pi/dist/index.d.ts.map +0 -1
- package/node_modules/goah-runner-pi/dist/index.js +0 -326
- package/node_modules/goah-runner-pi/dist/index.js.map +0 -1
- package/node_modules/goah-runner-pi/dist/model-provider.d.ts +0 -30
- package/node_modules/goah-runner-pi/dist/model-provider.d.ts.map +0 -1
- package/node_modules/goah-runner-pi/dist/model-provider.js +0 -96
- package/node_modules/goah-runner-pi/dist/model-provider.js.map +0 -1
- package/node_modules/goah-runner-pi/dist/pi-worker.d.ts +0 -31
- package/node_modules/goah-runner-pi/dist/pi-worker.d.ts.map +0 -1
- package/node_modules/goah-runner-pi/dist/pi-worker.js +0 -579
- package/node_modules/goah-runner-pi/dist/pi-worker.js.map +0 -1
- package/node_modules/goah-runner-pi/dist/steering-no-ack.test-fixture.d.ts +0 -2
- package/node_modules/goah-runner-pi/dist/steering-no-ack.test-fixture.d.ts.map +0 -1
- package/node_modules/goah-runner-pi/dist/steering-no-ack.test-fixture.js +0 -3
- package/node_modules/goah-runner-pi/dist/steering-no-ack.test-fixture.js.map +0 -1
- package/node_modules/goah-runner-pi/dist/steering-reject.test-fixture.d.ts +0 -2
- package/node_modules/goah-runner-pi/dist/steering-reject.test-fixture.d.ts.map +0 -1
- package/node_modules/goah-runner-pi/dist/steering-reject.test-fixture.js +0 -5
- package/node_modules/goah-runner-pi/dist/steering-reject.test-fixture.js.map +0 -1
- package/node_modules/goah-runner-pi/dist/steering-worker.test-fixture.d.ts +0 -2
- package/node_modules/goah-runner-pi/dist/steering-worker.test-fixture.d.ts.map +0 -1
- package/node_modules/goah-runner-pi/dist/steering-worker.test-fixture.js +0 -5
- package/node_modules/goah-runner-pi/dist/steering-worker.test-fixture.js.map +0 -1
- package/node_modules/goah-runner-pi/dist/test-helpers.d.ts +0 -4
- package/node_modules/goah-runner-pi/dist/test-helpers.d.ts.map +0 -1
- package/node_modules/goah-runner-pi/dist/test-helpers.js +0 -13
- package/node_modules/goah-runner-pi/dist/test-helpers.js.map +0 -1
- package/node_modules/goah-runner-pi/dist/verification-worker.d.ts +0 -2
- package/node_modules/goah-runner-pi/dist/verification-worker.d.ts.map +0 -1
- package/node_modules/goah-runner-pi/dist/verification-worker.js +0 -46
- package/node_modules/goah-runner-pi/dist/verification-worker.js.map +0 -1
- package/node_modules/goah-runner-pi/package.json +0 -28
- package/node_modules/goah-supervisor/dist/context-view.d.ts +0 -30
- package/node_modules/goah-supervisor/dist/context-view.d.ts.map +0 -1
- package/node_modules/goah-supervisor/dist/context-view.js +0 -58
- package/node_modules/goah-supervisor/dist/context-view.js.map +0 -1
- package/node_modules/goah-supervisor/dist/index.d.ts +0 -96
- package/node_modules/goah-supervisor/dist/index.d.ts.map +0 -1
- package/node_modules/goah-supervisor/dist/index.js +0 -1075
- package/node_modules/goah-supervisor/dist/index.js.map +0 -1
- package/node_modules/goah-supervisor/dist/roles.d.ts +0 -4
- package/node_modules/goah-supervisor/dist/roles.d.ts.map +0 -1
- package/node_modules/goah-supervisor/dist/roles.js +0 -29
- package/node_modules/goah-supervisor/dist/roles.js.map +0 -1
- package/node_modules/goah-supervisor/dist/verification.d.ts +0 -61
- package/node_modules/goah-supervisor/dist/verification.d.ts.map +0 -1
- package/node_modules/goah-supervisor/dist/verification.js +0 -135
- package/node_modules/goah-supervisor/dist/verification.js.map +0 -1
- package/node_modules/goah-supervisor/package.json +0 -26
- package/node_modules/goah-testkit/dist/faux-runner-worker.d.ts +0 -2
- package/node_modules/goah-testkit/dist/faux-runner-worker.d.ts.map +0 -1
- package/node_modules/goah-testkit/dist/faux-runner-worker.js +0 -82
- package/node_modules/goah-testkit/dist/faux-runner-worker.js.map +0 -1
- package/node_modules/goah-testkit/dist/index.d.ts +0 -49
- package/node_modules/goah-testkit/dist/index.d.ts.map +0 -1
- package/node_modules/goah-testkit/dist/index.js +0 -96
- package/node_modules/goah-testkit/dist/index.js.map +0 -1
- 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
|
+
};
|