@genesislcap/foundation-ai 15.91.0 → 15.92.0-GENC-1665.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/README.md +26 -103
- package/dist/dts/ai-provider.d.ts +5 -3
- package/dist/dts/ai-provider.d.ts.map +1 -1
- package/dist/dts/index.d.ts +7 -4
- package/dist/dts/index.d.ts.map +1 -1
- package/dist/dts/providers/openai-provider.d.ts +8 -7
- package/dist/dts/providers/openai-provider.d.ts.map +1 -1
- package/dist/dts/transports/anthropic-transport.d.ts +47 -0
- package/dist/dts/transports/anthropic-transport.d.ts.map +1 -1
- package/dist/dts/transports/budget-exhausted-error.d.ts +5 -7
- package/dist/dts/transports/budget-exhausted-error.d.ts.map +1 -1
- package/dist/dts/transports/context-overflow-error.d.ts.map +1 -1
- package/dist/dts/transports/openai-transport.d.ts +119 -0
- package/dist/dts/transports/openai-transport.d.ts.map +1 -0
- package/dist/dts/types/chat.types.d.ts +33 -0
- package/dist/dts/types/chat.types.d.ts.map +1 -1
- package/dist/dts/types/config.types.d.ts +45 -17
- package/dist/dts/types/config.types.d.ts.map +1 -1
- package/dist/dts/utils/token-cost.d.ts +90 -2
- package/dist/dts/utils/token-cost.d.ts.map +1 -1
- package/dist/dts/utils/tool-schema.d.ts +38 -0
- package/dist/dts/utils/tool-schema.d.ts.map +1 -1
- package/dist/esm/ai-provider.js +21 -14
- package/dist/esm/index.js +4 -2
- package/dist/esm/providers/openai-provider.js +15 -9
- package/dist/esm/transports/anthropic-transport.js +236 -44
- package/dist/esm/transports/budget-exhausted-error.js +6 -7
- package/dist/esm/transports/context-overflow-error.js +2 -0
- package/dist/esm/transports/openai-transport.js +752 -0
- package/dist/esm/types/config.types.js +15 -1
- package/dist/esm/utils/token-cost.js +153 -11
- package/dist/esm/utils/tool-schema.js +108 -0
- package/dist/foundation-ai.api.json +1868 -112
- package/dist/foundation-ai.d.ts +366 -30
- package/package.json +9 -9
- package/dist/dts/transports/server-openai-transport.d.ts +0 -23
- package/dist/dts/transports/server-openai-transport.d.ts.map +0 -1
- package/dist/esm/transports/server-openai-transport.js +0 -94
package/README.md
CHANGED
|
@@ -12,7 +12,7 @@ Provider-agnostic AI configuration and shared utilities. Configure once at app b
|
|
|
12
12
|
|
|
13
13
|
**Supported providers:**
|
|
14
14
|
|
|
15
|
-
- **OpenAI
|
|
15
|
+
- **OpenAI** – the Responses API, through your server proxy (`serverEndpoint`) or directly with an `apiKey` in trusted contexts. See [OpenAI](#openai).
|
|
16
16
|
- **Chrome built-in AI** – Prompt API / Gemini Nano (no API key; Chrome 138+)
|
|
17
17
|
|
|
18
18
|
Each provider exposes capabilities such as `interpretCriteria` (natural language to structured criteria). Future capabilities (e.g. summarization) will be added as optional methods on the same interface.
|
|
@@ -69,17 +69,20 @@ Add `@genesislcap/foundation-ai` as a dependency. Run `npm run bootstrap` after
|
|
|
69
69
|
|
|
70
70
|
### 1. Resolve config (Chrome-first or OpenAI)
|
|
71
71
|
|
|
72
|
-
Use `resolveAIConfig` to prefer Chrome when available, with
|
|
72
|
+
Use `resolveAIConfig` to prefer Chrome when available, with a cloud provider as fallback. The cloud
|
|
73
|
+
config it returns carries no endpoint, so add your proxy's `serverEndpoint` before creating the provider:
|
|
73
74
|
|
|
74
75
|
```ts
|
|
75
76
|
import { createAIProvider, resolveAIConfig, AIProvider } from '@genesislcap/foundation-ai';
|
|
76
77
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
provider: 'openai',
|
|
80
|
-
model: 'gpt-4o-mini',
|
|
78
|
+
const resolved = await resolveAIConfig({
|
|
79
|
+
provider: 'openai', // default model: gpt-6-luna
|
|
81
80
|
preferChrome: true,
|
|
82
81
|
});
|
|
82
|
+
const aiConfig =
|
|
83
|
+
resolved && 'providerType' in resolved && resolved.providerType === 'openai'
|
|
84
|
+
? { ...resolved, serverEndpoint: '/gwf/ai-service/api/openai/chat' }
|
|
85
|
+
: resolved;
|
|
83
86
|
```
|
|
84
87
|
|
|
85
88
|
### 2. Register provider in DI
|
|
@@ -109,105 +112,24 @@ if (aiProvider?.interpretCriteria) {
|
|
|
109
112
|
|
|
110
113
|
---
|
|
111
114
|
|
|
112
|
-
##
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
Create a `*-web-handler.kts` file in your Genesis app's scripts folder (e.g. `src/main/genesis/scripts/`). Example for OpenAI:
|
|
119
|
-
|
|
120
|
-
```kotlin
|
|
121
|
-
/**
|
|
122
|
-
* AI web handler - proxies OpenAI Chat Completions requests.
|
|
123
|
-
* API key is read from OPENAI_API_KEY env var (never exposed to client).
|
|
124
|
-
*/
|
|
125
|
-
import com.fasterxml.jackson.annotation.JsonAlias
|
|
126
|
-
import com.fasterxml.jackson.annotation.JsonProperty
|
|
127
|
-
import com.fasterxml.jackson.databind.ObjectMapper
|
|
128
|
-
import java.net.URI
|
|
129
|
-
import java.net.http.HttpClient
|
|
130
|
-
import java.net.http.HttpRequest
|
|
131
|
-
import java.net.http.HttpResponse
|
|
132
|
-
import java.nio.charset.StandardCharsets
|
|
133
|
-
|
|
134
|
-
data class ChatCompletionsRequest(
|
|
135
|
-
val provider: String = "openai",
|
|
136
|
-
val model: String = "gpt-4o-mini",
|
|
137
|
-
@JsonProperty("SYSTEM_PROMPT") @JsonAlias("systemPrompt") val systemPrompt: String,
|
|
138
|
-
@JsonProperty("USER_PROMPT") @JsonAlias("userPrompt") val userPrompt: String,
|
|
139
|
-
@JsonProperty("RESPONSE_SCHEMA") @JsonAlias("responseSchema") val responseSchema: Map<String, Any>? = null,
|
|
140
|
-
)
|
|
141
|
-
|
|
142
|
-
data class ChatCompletionsResponse(
|
|
143
|
-
val content: String,
|
|
144
|
-
)
|
|
145
|
-
|
|
146
|
-
webHandlers("ai-service") {
|
|
147
|
-
val httpClient = HttpClient.newBuilder().build()
|
|
148
|
-
val apiKey = java.lang.System.getenv("OPENAI_API_KEY")
|
|
149
|
-
|
|
150
|
-
endpoint<ChatCompletionsRequest, ChatCompletionsResponse>(POST, "chat-completions") {
|
|
151
|
-
handleRequest {
|
|
152
|
-
val req = body
|
|
153
|
-
if (req.provider != "openai") {
|
|
154
|
-
throw IllegalStateException("Only 'openai' provider is supported for now")
|
|
155
|
-
}
|
|
156
|
-
if (apiKey.isNullOrBlank()) {
|
|
157
|
-
throw IllegalStateException("OPENAI_API_KEY is not configured on the server")
|
|
158
|
-
}
|
|
159
|
-
val responseFormat = req.responseSchema?.let { schema ->
|
|
160
|
-
mapOf(
|
|
161
|
-
"type" to "json_schema",
|
|
162
|
-
"json_schema" to mapOf(
|
|
163
|
-
"name" to "structured_response",
|
|
164
|
-
"strict" to true,
|
|
165
|
-
"schema" to schema,
|
|
166
|
-
),
|
|
167
|
-
)
|
|
168
|
-
}
|
|
169
|
-
val openAiBody = mapOf(
|
|
170
|
-
"model" to req.model,
|
|
171
|
-
"messages" to listOf(
|
|
172
|
-
mapOf("role" to "system", "content" to req.systemPrompt),
|
|
173
|
-
mapOf("role" to "user", "content" to req.userPrompt),
|
|
174
|
-
),
|
|
175
|
-
) + (responseFormat?.let { mapOf("response_format" to it) } ?: emptyMap())
|
|
176
|
-
|
|
177
|
-
val objectMapper = ObjectMapper()
|
|
178
|
-
val requestBody = objectMapper.writeValueAsString(openAiBody)
|
|
179
|
-
val request = HttpRequest.newBuilder()
|
|
180
|
-
.uri(URI.create("https://api.openai.com/v1/chat/completions"))
|
|
181
|
-
.header("Authorization", "Bearer $apiKey")
|
|
182
|
-
.header("Content-Type", "application/json")
|
|
183
|
-
.POST(HttpRequest.BodyPublishers.ofString(requestBody, StandardCharsets.UTF_8))
|
|
184
|
-
.build()
|
|
185
|
-
|
|
186
|
-
val response = httpClient.send(request, HttpResponse.BodyHandlers.ofString(StandardCharsets.UTF_8))
|
|
187
|
-
|
|
188
|
-
if (response.statusCode() >= 400) {
|
|
189
|
-
LOG.error("OpenAI API error: ${response.statusCode()} - ${response.body()}")
|
|
190
|
-
throw RuntimeException("OpenAI API error: ${response.statusCode()}")
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
val json = objectMapper.readTree(response.body())
|
|
194
|
-
val choices = json.path("choices")
|
|
195
|
-
val content = if (choices.isArray && !choices.isEmpty) {
|
|
196
|
-
choices.get(0).path("message").path("content").asText()
|
|
197
|
-
} else ""
|
|
198
|
-
ChatCompletionsResponse(content = content)
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
```
|
|
115
|
+
## OpenAI
|
|
116
|
+
|
|
117
|
+
`OpenAIAIConfig` (`providerType: 'openai'`) builds an `OpenAIProvider` on `OpenAITransport`: criteria,
|
|
118
|
+
prompt and chat, on the Responses API. Supported models are `SUPPORTED_OPENAI_MODEL_IDS`; the default is
|
|
119
|
+
`gpt-6-luna`.
|
|
203
120
|
|
|
204
|
-
|
|
121
|
+
- **Server proxy (recommended):** set `serverEndpoint` to your proxy route. The transport posts the
|
|
122
|
+
Responses request body there; the proxy adds the API key, calls `https://api.openai.com/v1/responses` and
|
|
123
|
+
returns the response. The key stays on the server. There is no default endpoint. Genesis Create's
|
|
124
|
+
ai-service mounts one at `/api/openai/chat` (behind the gateway, `/gwf/ai-service/api/openai/chat`).
|
|
125
|
+
- **Direct:** set `apiKey` and the transport calls OpenAI itself. Only use this in trusted contexts, since
|
|
126
|
+
the key is in the client.
|
|
205
127
|
|
|
206
|
-
|
|
128
|
+
With neither `serverEndpoint` nor `apiKey`, a request throws.
|
|
207
129
|
|
|
208
130
|
### Error codes a proxy can send
|
|
209
131
|
|
|
210
|
-
The Anthropic and
|
|
132
|
+
The Anthropic, Gemini and OpenAI transports read a `code` from a proxy's JSON error body, `{ "code": "…", "error": "…" }`,
|
|
211
133
|
and act on it whatever the status:
|
|
212
134
|
|
|
213
135
|
- `NO_API_KEY`, `BAD_API_KEY`, `KEY_UNREADABLE`, `MODEL_NOT_ALLOWED`, `BAD_REQUEST`, `FALLBACKS_NOT_SUPPORTED`
|
|
@@ -233,10 +155,11 @@ for each. The `error` text is for the console only. A proxy should use these con
|
|
|
233
155
|
To force a specific provider instead of using `resolveAIConfig`:
|
|
234
156
|
|
|
235
157
|
```ts
|
|
236
|
-
//
|
|
158
|
+
// OpenAI through your server proxy
|
|
237
159
|
Registration.instance(AIProvider, createAIProvider({
|
|
238
|
-
|
|
239
|
-
model: 'gpt-
|
|
160
|
+
providerType: 'openai',
|
|
161
|
+
model: 'gpt-6-luna',
|
|
162
|
+
serverEndpoint: '/gwf/ai-service/api/openai/chat',
|
|
240
163
|
}));
|
|
241
164
|
|
|
242
165
|
// Chrome only (when available)
|
|
@@ -44,7 +44,7 @@ export interface AIProvider {
|
|
|
44
44
|
/**
|
|
45
45
|
* Creates an AIProvider from config.
|
|
46
46
|
* Uses ChromeProvider when providerType is 'chrome'.
|
|
47
|
-
* Uses
|
|
47
|
+
* Uses GeminiProvider, AnthropicProvider or OpenAIProvider for their `providerType`.
|
|
48
48
|
* Otherwise returns DefaultAIProvider.
|
|
49
49
|
* When the AI feature flag is disabled (?feature.ai), always returns DefaultAIProvider.
|
|
50
50
|
*
|
|
@@ -62,7 +62,7 @@ export interface ResolveAIConfigOptions {
|
|
|
62
62
|
/**
|
|
63
63
|
* Model name.
|
|
64
64
|
*
|
|
65
|
-
* - OpenAI default
|
|
65
|
+
* - OpenAI: only {@link SUPPORTED_OPENAI_MODEL_IDS} (default `gpt-6-luna`).
|
|
66
66
|
* - Gemini: only {@link SUPPORTED_GEMINI_MODEL_IDS} (default `gemini-2.5-flash-lite`).
|
|
67
67
|
* - Anthropic: only {@link SUPPORTED_ANTHROPIC_MODEL_IDS} (default `claude-haiku-4-5-20251001`).
|
|
68
68
|
*/
|
|
@@ -72,7 +72,9 @@ export interface ResolveAIConfigOptions {
|
|
|
72
72
|
}
|
|
73
73
|
/**
|
|
74
74
|
* Resolves AI config, optionally preferring Chrome when available.
|
|
75
|
-
* Use before registering AIProvider.
|
|
75
|
+
* Use before registering AIProvider. The cloud configs it returns carry no endpoint: add
|
|
76
|
+
* `serverEndpoint` (a server proxy) or `apiKey` (direct, trusted contexts only) before
|
|
77
|
+
* `createAIProvider`.
|
|
76
78
|
* Returns null when the AI feature flag is disabled (?feature.ai).
|
|
77
79
|
*
|
|
78
80
|
* @beta
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ai-provider.d.ts","sourceRoot":"","sources":["../../src/ai-provider.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAC3D,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,gBAAgB,CAAC;AAU/D,OAAO,
|
|
1
|
+
{"version":3,"file":"ai-provider.d.ts","sourceRoot":"","sources":["../../src/ai-provider.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAC3D,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,gBAAgB,CAAC;AAU/D,OAAO,EAIL,KAAK,QAAQ,EACb,KAAK,QAAQ,EAIb,KAAK,4BAA4B,EAKlC,MAAM,SAAS,CAAC;AACjB,OAAO,KAAK,EAAE,WAAW,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAI3F;;;;;;;;GAQG;AACH,MAAM,WAAW,UAAU;IACzB,iBAAiB,CAAC,CAChB,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,wBAAwB,GAChC,OAAO,CAAC,4BAA4B,GAAG,IAAI,CAAC,CAAC;IAEhD;;OAEG;IACH,SAAS,CAAC,IAAI,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC,CAAC;IAEvC;;;OAGG;IACH,eAAe,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAElC;;;;;;OAMG;IACH,MAAM,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,kBAAkB,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAExE;;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U,CAAC,GAAG,GAAG,CAAC,MAAM,EAAE,UAAU,CAAC,EAC/D,OAAO,GAAE;QAAE,OAAO,CAAC,EAAE,MAAM,CAAA;KAAO,GACjC,IAAI;IASP,SAAS,CAAC,QAAQ,EAAE,MAAM,IAAI,GAAG,MAAM,IAAI;IAO3C;;;;OAIG;IACH,OAAO,CAAC,MAAM;CAGf"}
|
package/dist/dts/index.d.ts
CHANGED
|
@@ -7,6 +7,9 @@ export { GeminiProvider } from './providers/gemini-provider';
|
|
|
7
7
|
export { AnthropicTransport, ResponseTruncatedError } from './transports/anthropic-transport';
|
|
8
8
|
export { BUDGETED_VENDORS, BudgetExhaustedError, DEFAULT_BUDGET_EXHAUSTED_MESSAGE, isBudgetedVendor, VENDOR_LABELS, vendorTypeOfLabel, } from './transports/budget-exhausted-error';
|
|
9
9
|
export { GeminiTransport, MalformedFunctionCallError } from './transports/gemini-transport';
|
|
10
|
+
export { OpenAITransport } from './transports/openai-transport';
|
|
11
|
+
export type { OpenAITransportConfig } from './transports/openai-transport';
|
|
12
|
+
export { OpenAIProvider } from './providers/openai-provider';
|
|
10
13
|
export { DEFAULT_PROVIDER_REFUSED_MESSAGE, PROVIDER_REFUSED_CODE, ProviderRefusedError, } from './transports/provider-refused';
|
|
11
14
|
export type { ProviderRefusalKind } from './transports/provider-refused';
|
|
12
15
|
export { ContextOverflowError, contextOverflowOf, DEFAULT_CONTEXT_OVERFLOW_MESSAGE, } from './transports/context-overflow-error';
|
|
@@ -18,10 +21,10 @@ export { buildTierProviders } from './tiers/build-tier-providers';
|
|
|
18
21
|
export type { BuildTierProvidersOptions } from './tiers/build-tier-providers';
|
|
19
22
|
export { AI_FEATURE_FLAG, isAIFeatureEnabled } from './utils/feature-flags';
|
|
20
23
|
export { ChatTemperature } from './utils/temperature';
|
|
21
|
-
export { ANTHROPIC_CACHE_READ_MULTIPLIER, ANTHROPIC_CACHE_WRITE_1H_MULTIPLIER, ANTHROPIC_CACHE_WRITE_5M_MULTIPLIER, anthropicRatesFor, anthropicTokenCost, GEMINI_CACHED_INPUT_MULTIPLIER, GEMINI_LONG_CONTEXT_THRESHOLD, geminiRatesFor, geminiTokenCost, } from './utils/token-cost';
|
|
22
|
-
export type { AnthropicUsageRecord, GeminiUsageRecord, TokenCost, TokenCostBreakdown, TokenRates, } from './utils/token-cost';
|
|
23
|
-
export { SUPPORTED_ANTHROPIC_MODEL_IDS, SUPPORTED_GEMINI_MODEL_IDS, vendorOfModel } from './types';
|
|
24
|
-
export type { AIConfig, AIStatus, AIProviderType, AnthropicAIConfig, AnthropicModelId, ChromeAIConfig, ChromeAvailability, GeminiAIConfig, GeminiModelId,
|
|
24
|
+
export { ANTHROPIC_CACHE_READ_MULTIPLIER, ANTHROPIC_CACHE_WRITE_1H_MULTIPLIER, ANTHROPIC_CACHE_WRITE_5M_MULTIPLIER, anthropicCacheReadMultiplierFor, ANTHROPIC_LONG_CONTEXT_THRESHOLD, anthropicRatesFor, anthropicTokenCost, GEMINI_CACHED_INPUT_MULTIPLIER, GEMINI_LONG_CONTEXT_THRESHOLD, geminiRatesFor, geminiTokenCost, OPENAI_CACHE_WRITE_12H_MULTIPLIER, OPENAI_CACHE_WRITE_30M_MULTIPLIER, OPENAI_LONG_CONTEXT_INPUT_MULTIPLIER, OPENAI_LONG_CONTEXT_OUTPUT_MULTIPLIER, OPENAI_LONG_CONTEXT_THRESHOLD, openaiRatesFor, openaiTokenCost, } from './utils/token-cost';
|
|
25
|
+
export type { AnthropicUsageRecord, GeminiUsageRecord, OpenAIUsageRecord, TokenCost, TokenCostBreakdown, TokenRates, } from './utils/token-cost';
|
|
26
|
+
export { SUPPORTED_ANTHROPIC_MODEL_IDS, SUPPORTED_GEMINI_MODEL_IDS, SUPPORTED_OPENAI_MODEL_IDS, vendorOfModel, } from './types';
|
|
27
|
+
export type { AIConfig, AIStatus, AIProviderType, AnthropicAIConfig, AnthropicModelId, ChromeAIConfig, ChromeAvailability, GeminiAIConfig, GeminiModelId, OpenAIAIConfig, OpenAIModelId, } from './types';
|
|
25
28
|
export type { AggregateUsage, AgentPickerMode, ChatAgentConfig, ChatAgentPickerConfig, ChatAnimationsConfig, ChatNotificationsConfig, ChatAttachment, ChatConfig, ChatContextConfig, ChatCostHistoryConfig, ChatDebugLogSubmission, ChatDebugLogNoteConfig, ChatDebugLogSubmitConfig, ChatDriverResult, ChatFallback, ChatHandlerCapabilities, ChatImageAttachment, ChatInputDuringExecutionMode, CachePolicy, ChatMessage, ChatMessageFeedback, ChatMessageFeedbackConfig, ChatMessageFeedbackRating, ChatInteraction, ChatRequestOptions, ChatResponseMeta, ChatRole, ChatStreamChunk, ChatTextAttachment, ChatThinkingLevel, ChatThinkingPolicy, ChatToolCall, ChatToolCallUnknown, ChatToolChoice, ChatToolDefinition, ChatToolHandlers, ChatToolResult, ChatUiConfig, CondensePolicy, CondenseResult, CondenseTrigger, ChatSuggestionsConfig, HandOffCompletion, HandOffRefusal, HandOffRequest, HandOffResult, InteractionEdit, InteractionPresentation, InteractionRequestOptions, InteractionResult, MessageCompaction, ModelTagAppearance, SubAgentFailureReason, SubAgentRequestOptions, TimestampDisplay, TurnFailureReason, } from './types/chat.types';
|
|
26
29
|
export { isChatToolCallUnknown } from './types/chat.types';
|
|
27
30
|
export type { ChatTransport } from './types/chat-transport.types';
|
package/dist/dts/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,8BAA8B,EAC9B,yBAAyB,EACzB,eAAe,GAChB,MAAM,eAAe,CAAC;AACvB,YAAY,EACV,UAAU,EACV,6BAA6B,EAC7B,4BAA4B,GAC7B,MAAM,eAAe,CAAC;AAKvB,OAAO,EACL,kBAAkB,EAClB,0BAA0B,EAC1B,mBAAmB,GACpB,MAAM,kBAAkB,CAAC;AAC1B,YAAY,EAAE,0BAA0B,EAAE,MAAM,kBAAkB,CAAC;AACn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AAM,0BAA0B,CAAC;AACvE,YAAY,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAC;AAC5D,YAAY,EAAE,wBAAwB,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC1E,YAAY,EACV,oBAAoB,EACpB,mBAAmB,EACnB,4BAA4B,GAC7B,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,4BAA4B,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAC"}
|
|
@@ -1,23 +1,24 @@
|
|
|
1
1
|
import type { AIProvider } from '../ai-provider';
|
|
2
2
|
import type { CriteriaInterpretContext } from '../interactions';
|
|
3
|
-
import
|
|
3
|
+
import { OpenAITransport } from '../transports/openai-transport';
|
|
4
|
+
import type { AIStatus, CriteriaInterpretationResult } from '../types';
|
|
5
|
+
import type { ChatMessage, ChatRequestOptions } from '../types/chat.types';
|
|
4
6
|
export interface OpenAIProviderConfig {
|
|
5
7
|
criteriaInstructions?: string;
|
|
6
8
|
}
|
|
7
9
|
/**
|
|
8
|
-
* General OpenAI provider
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* @remarks
|
|
12
|
-
* Configure via createAIProvider with ServerAIConfig (provider, model).
|
|
10
|
+
* General OpenAI provider, on `OpenAITransport` (the Responses API, direct or via a server proxy):
|
|
11
|
+
* criteria, prompt and chat — the same shape as its Gemini and Anthropic twins.
|
|
13
12
|
*
|
|
14
13
|
* @beta
|
|
15
14
|
*/
|
|
16
15
|
export declare class OpenAIProvider implements AIProvider {
|
|
17
16
|
private readonly transport;
|
|
18
17
|
private readonly criteriaInstructions?;
|
|
19
|
-
constructor(config: OpenAIProviderConfig, transport:
|
|
18
|
+
constructor(config: OpenAIProviderConfig, transport: OpenAITransport);
|
|
20
19
|
getStatus(): Promise<AIStatus>;
|
|
21
20
|
interpretCriteria(input: string, context: CriteriaInterpretContext): Promise<CriteriaInterpretationResult | null>;
|
|
21
|
+
prompt(message: string, options?: ChatRequestOptions): Promise<string>;
|
|
22
|
+
chat(history: ChatMessage[], userMessage: string, options?: ChatRequestOptions): Promise<ChatMessage>;
|
|
22
23
|
}
|
|
23
24
|
//# sourceMappingURL=openai-provider.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"openai-provider.d.ts","sourceRoot":"","sources":["../../../src/providers/openai-provider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AACjD,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"openai-provider.d.ts","sourceRoot":"","sources":["../../../src/providers/openai-provider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AACjD,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,iBAAiB,CAAC;AAOhE,OAAO,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AACjE,OAAO,KAAK,EAAE,QAAQ,EAAE,4BAA4B,EAAE,MAAM,UAAU,CAAC;AACvE,OAAO,KAAK,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAG3E,MAAM,WAAW,oBAAoB;IACnC,oBAAoB,CAAC,EAAE,MAAM,CAAC;CAC/B;AAED;;;;;GAKG;AACH,qBAAa,cAAe,YAAW,UAAU;IAC/C,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAkB;IAC5C,OAAO,CAAC,QAAQ,CAAC,oBAAoB,CAAC,CAAS;gBAEnC,MAAM,EAAE,oBAAoB,EAAE,SAAS,EAAE,eAAe;IAK9D,SAAS,IAAI,OAAO,CAAC,QAAQ,CAAC;IAK9B,iBAAiB,CACrB,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,wBAAwB,GAChC,OAAO,CAAC,4BAA4B,GAAG,IAAI,CAAC;IAmBzC,MAAM,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,kBAAkB,GAAG,OAAO,CAAC,MAAM,CAAC;IAKtE,IAAI,CACR,OAAO,EAAE,WAAW,EAAE,EACtB,WAAW,EAAE,MAAM,EACnB,OAAO,CAAC,EAAE,kBAAkB,GAC3B,OAAO,CAAC,WAAW,CAAC;CAGxB"}
|
|
@@ -32,6 +32,21 @@ export interface AnthropicTransportConfig {
|
|
|
32
32
|
* Hard cap on tokens generated per response. Defaults to 4096.
|
|
33
33
|
*/
|
|
34
34
|
maxTokens?: number;
|
|
35
|
+
/**
|
|
36
|
+
* What the API does with a replayed thinking block whose conversation changed since it was
|
|
37
|
+
* produced (preserved thinking), on the models that run that check (the Claude 5.5 family).
|
|
38
|
+
*
|
|
39
|
+
* - `'drop_block'` (default): drop the block and every later one for that request, and report
|
|
40
|
+
* each drop in the response's `input_transformations` (surfaced on
|
|
41
|
+
* {@link ChatResponseMeta.inputTransformations}). The turn succeeds without that reasoning.
|
|
42
|
+
* - `'error'`: a mismatch is a 400 — for tests that must prove the history is append-only.
|
|
43
|
+
* - `'omit'`: send neither the field nor its beta header. For a proxy that does not forward
|
|
44
|
+
* `anthropic-beta`, where the field alone is a 400. The account's own default then applies:
|
|
45
|
+
* a 400 on accounts created on or after 2026-08-31.
|
|
46
|
+
*
|
|
47
|
+
* Sent only with adaptive thinking; a turn whose thinking is off never carries it.
|
|
48
|
+
*/
|
|
49
|
+
thinkingBlockBinding?: 'drop_block' | 'error' | 'omit';
|
|
35
50
|
}
|
|
36
51
|
/**
|
|
37
52
|
* Thrown when a response was cut off at the output-token limit (Anthropic
|
|
@@ -117,6 +132,9 @@ export declare class AnthropicTransport implements AITransport, ChatTransport, C
|
|
|
117
132
|
* on this model. Latched, because it would otherwise fire on every turn of a tool loop.
|
|
118
133
|
*/
|
|
119
134
|
private warnedThinkingClamped;
|
|
135
|
+
/** Set once the forced-tool-choice downgrade has been logged; see `downgradeForcedToolChoice`. */
|
|
136
|
+
private warnedToolChoiceDowngraded;
|
|
137
|
+
private readonly thinkingBlockBinding;
|
|
120
138
|
/**
|
|
121
139
|
* Serving-model ids already reported as unrecognised. Per-id rather than a single flag, so a
|
|
122
140
|
* second unknown model is still announced. See {@link AnthropicTransport.servingModel}.
|
|
@@ -155,6 +173,35 @@ export declare class AnthropicTransport implements AITransport, ChatTransport, C
|
|
|
155
173
|
resetLifetimeCost(): void;
|
|
156
174
|
sendStructuredPrompt(options: StructuredPromptOptions): Promise<string>;
|
|
157
175
|
sendChatMessage(history: ChatMessage[], userMessage: string, options?: ChatRequestOptions): Promise<ChatMessage>;
|
|
176
|
+
/**
|
|
177
|
+
* Set `tool_choice` from the caller's {@link ChatToolChoice}. `'required'`/`{ tool }` force a
|
|
178
|
+
* tool call so a turn can only end via one (e.g. a sub-agent's completion tool); on a model that
|
|
179
|
+
* rejects forcing they are downgraded (see `downgradeForcedToolChoice`), and the instruction
|
|
180
|
+
* that replaces them is returned for the tail.
|
|
181
|
+
*/
|
|
182
|
+
private applyToolChoice;
|
|
183
|
+
/**
|
|
184
|
+
* Preserved thinking (5.5 family): say what a changed history does to replayed thinking, rather
|
|
185
|
+
* than inheriting the account default (a 400 on accounts created on or after 2026-08-31).
|
|
186
|
+
* Adaptive only — `between_tools` and `disabled` reject the field — and a fresh object, so the
|
|
187
|
+
* shared `adaptive` constant in `anthropicThinking` is never mutated.
|
|
188
|
+
*/
|
|
189
|
+
private withBlockBinding;
|
|
190
|
+
/**
|
|
191
|
+
* Stand-in for a forced tool call on a model that rejects `tool_choice` `any`/`tool` with a 400
|
|
192
|
+
* (Opus 5.5, Sonnet 5.5). The request goes out with `tool_choice` omitted (`auto`), and:
|
|
193
|
+
*
|
|
194
|
+
* - for a NAMED tool, that tool's schema is enforced (`strict: true`), so a call that does
|
|
195
|
+
* happen has valid arguments — the half of forcing that `auto` can still guarantee. Not done
|
|
196
|
+
* for `'required'`: enforcing every tool in a large surface can exceed the provider's
|
|
197
|
+
* per-request compilation limits, and a tool the caller enforced already carries it;
|
|
198
|
+
* - an instruction naming the tool is returned for the caller to append to the tail.
|
|
199
|
+
*
|
|
200
|
+
* `auto` lets the model answer in text instead, so the caller is told: a one-time warning here,
|
|
201
|
+
* and `responseMeta.toolChoiceDowngraded` on every affected response, which a driver uses to
|
|
202
|
+
* nudge and retry once when no tool was called.
|
|
203
|
+
*/
|
|
204
|
+
private downgradeForcedToolChoice;
|
|
158
205
|
/**
|
|
159
206
|
* Place prompt-cache breakpoints on the outgoing request per the resolved {@link CachePolicy}.
|
|
160
207
|
* A breakpoint is `cache_control: {type:'ephemeral'}` on a content block / tool / system block;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"anthropic-transport.d.ts","sourceRoot":"","sources":["../../../src/transports/anthropic-transport.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,WAAW,EAChB,KAAK,gBAAgB,EACrB,KAAK,sBAAsB,EAC3B,KAAK,uBAAuB,EAC7B,MAAM,UAAU,CAAC;AAClB,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AACnE,OAAO,KAAK,EAGV,WAAW,EACX,kBAAkB,
|
|
1
|
+
{"version":3,"file":"anthropic-transport.d.ts","sourceRoot":"","sources":["../../../src/transports/anthropic-transport.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,WAAW,EAChB,KAAK,gBAAgB,EACrB,KAAK,sBAAsB,EAC3B,KAAK,uBAAuB,EAC7B,MAAM,UAAU,CAAC;AAClB,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AACnE,OAAO,KAAK,EAGV,WAAW,EACX,kBAAkB,EAOnB,MAAM,qBAAqB,CAAC;AA+T7B,MAAM,WAAW,wBAAwB;IACvC;;;OAGG;IACH,KAAK,CAAC,EAAE,gBAAgB,CAAC;IACzB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;;OAIG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB;;;;;;OAMG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;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AC,YAAY;IAqBpB;;;;;;;;;;;;;;;;;;;;;OAqBG;IACH,OAAO,CAAC,iBAAiB;IASzB,iFAAiF;IACjF,OAAO,CAAC,WAAW;IAoBnB,OAAO,CAAC,qBAAqB;IAqN7B,OAAO,CAAC,aAAa;IAkCrB,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,iBAAiB,CAAO;IAChD,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,0BAA0B,CAAO;IACzD,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,iBAAiB,CAAO;IAChD,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,kBAAkB,CAIxC;IAEF,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,eAAe,CAAQ;YAEjC,IAAI;CA8BnB"}
|
|
@@ -56,13 +56,11 @@ export declare const VENDOR_LABELS: Readonly<Record<Exclude<AIProviderType, 'non
|
|
|
56
56
|
* and if it is reachable, `blocked` then derives true and locks a composer with
|
|
57
57
|
* headroom left.
|
|
58
58
|
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
* Anthropic and Gemini alone. So it can never raise a 402, and a 402 is never
|
|
65
|
-
* a statement about it.
|
|
59
|
+
* `chrome` is excluded for that reason: it runs on-device — no pot to exhaust, and free.
|
|
60
|
+
*
|
|
61
|
+
* `openai` is metered (GENC-1829): ai-service budgets it on its own `SpentUsdOpenai` counter and
|
|
62
|
+
* proxies it on `/api/openai/chat`. The proxy computes `otherVendorAvailable` over the vendors it
|
|
63
|
+
* OFFERS, so with OpenAI switched off there a 402 still says nothing about it.
|
|
66
64
|
*
|
|
67
65
|
* @beta
|
|
68
66
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"budget-exhausted-error.d.ts","sourceRoot":"","sources":["../../../src/transports/budget-exhausted-error.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAA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;GA0BG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"context-overflow-error.d.ts","sourceRoot":"","sources":["../../../src/transports/context-overflow-error.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AA+C5D;;;;;;;;;GASG;AACH,eAAO,MAAM,gCAAgC,QAEE,CAAC;AAEhD;;;;;;;;;GASG;AACH,qBAAa,oBAAqB,SAAQ,KAAK;IAE3C,uEAAuE;IACvE,QAAQ,CAAC,WAAW,EAAE,MAAM;IAC5B,sEAAsE;IACtE,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM;IAC9B,sEAAsE;IACtE,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM;IAC7B,6FAA6F;IAC7F,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM;;IAPxB,uEAAuE;IAC9D,WAAW,EAAE,MAAM;IAC5B,sEAAsE;IAC7D,YAAY,CAAC,EAAE,MAAM;IAC9B,sEAAsE;IAC7D,WAAW,CAAC,EAAE,MAAM;IAC7B,6FAA6F;IACpF,MAAM,CAAC,EAAE,MAAM;CAU3B;AAwBD;;;;;;;;;;;GAWG;AACH,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,cAAc,GAAG,SAAS,EACnC,MAAM,EAAE,MAAM,GAAG,SAAS,EAC1B,OAAO,EAAE,OAAO,GACf;IAAE,YAAY,CAAC,EAAE,MAAM,CAAC;IAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,SAAS,CAY/E"}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { type AITransport, type CostReportingTransport, type OpenAIModelId, type StructuredPromptOptions } from '../types';
|
|
2
|
+
import type { ChatTransport } from '../types/chat-transport.types';
|
|
3
|
+
import type { ChatMessage, ChatRequestOptions, ChatThinkingPolicy } from '../types/chat.types';
|
|
4
|
+
type OpenAIEffort = 'none' | 'low' | 'medium' | 'high' | 'max';
|
|
5
|
+
/**
|
|
6
|
+
* The effort to send for a policy, or `undefined` to omit the field and take the model's default.
|
|
7
|
+
* `'auto'` omits it too: every model here already decides its own depth by default, so there is no
|
|
8
|
+
* opt-in to send.
|
|
9
|
+
*/
|
|
10
|
+
export declare function openaiEffortFor(model: OpenAIModelId, policy?: ChatThinkingPolicy): OpenAIEffort | undefined;
|
|
11
|
+
/** @beta */
|
|
12
|
+
export interface OpenAITransportConfig {
|
|
13
|
+
/** Defaults to `gpt-6-luna`. Only {@link SUPPORTED_OPENAI_MODEL_IDS} are accepted. */
|
|
14
|
+
model?: OpenAIModelId;
|
|
15
|
+
timeout?: number;
|
|
16
|
+
/**
|
|
17
|
+
* Inactivity window (ms) on the server-proxied heartbeat path. Ignored on direct API calls.
|
|
18
|
+
* Defaults to 30_000.
|
|
19
|
+
*/
|
|
20
|
+
stallTimeout?: number;
|
|
21
|
+
/** API key for direct calls to the OpenAI API. Must be provided explicitly. */
|
|
22
|
+
apiKey?: string;
|
|
23
|
+
/** Server-proxy endpoint (e.g. `/gwf/ai-service/api/openai/chat`). Used when no API key is set. */
|
|
24
|
+
serverEndpoint?: string;
|
|
25
|
+
/** Per-request `max_output_tokens` default. Omitted (model ceiling) when unset. */
|
|
26
|
+
maxTokens?: number;
|
|
27
|
+
/**
|
|
28
|
+
* `reasoning.summary` to request when the turn reasons. Defaults to `'none'` (no summary
|
|
29
|
+
* requested): OpenAI may require organisation verification before it returns summaries, and an
|
|
30
|
+
* unverified organisation would otherwise see every reasoning turn rejected.
|
|
31
|
+
*/
|
|
32
|
+
reasoningSummary?: 'auto' | 'concise' | 'detailed' | 'none';
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Transport for OpenAI's Responses API. Calls it directly when `apiKey` is provided, otherwise
|
|
36
|
+
* posts to a server-proxy endpoint (ai-service `/api/openai/chat`) that adds the key, meters spend
|
|
37
|
+
* and frames the stream.
|
|
38
|
+
*
|
|
39
|
+
* Stateless by design: `store: false`, no `previous_response_id`. Everything a later turn needs
|
|
40
|
+
* (encrypted reasoning, `phase`) rides on the persisted `ChatMessage`s, so sessions survive restore
|
|
41
|
+
* and vendor switches the same way they do on the other transports.
|
|
42
|
+
*
|
|
43
|
+
* Implements `AITransport` (structured prompt) and `ChatTransport` (multi-turn chat).
|
|
44
|
+
*
|
|
45
|
+
* @beta
|
|
46
|
+
*/
|
|
47
|
+
export declare class OpenAITransport implements AITransport, ChatTransport, CostReportingTransport {
|
|
48
|
+
private readonly model;
|
|
49
|
+
private readonly timeout;
|
|
50
|
+
private readonly stallTimeout;
|
|
51
|
+
private readonly apiKey;
|
|
52
|
+
private readonly serverEndpoint;
|
|
53
|
+
private readonly maxTokens;
|
|
54
|
+
private readonly reasoningSummary;
|
|
55
|
+
private lifetimeCostUsd;
|
|
56
|
+
/** Net of write premiums, so it can go negative on a cold cache — same contract as Anthropic. */
|
|
57
|
+
private lifetimeSavingsUsd;
|
|
58
|
+
/**
|
|
59
|
+
* The clamped policies already warned about, so each warns once rather than on every turn of a
|
|
60
|
+
* tool loop. Per policy: a `minimal` warning must not silence the costlier `off` one.
|
|
61
|
+
*/
|
|
62
|
+
private readonly warnedThinkingClamped;
|
|
63
|
+
constructor(config?: OpenAITransportConfig);
|
|
64
|
+
getConfig(): {
|
|
65
|
+
provider: 'openai';
|
|
66
|
+
model: OpenAIModelId;
|
|
67
|
+
contextLimit: number;
|
|
68
|
+
};
|
|
69
|
+
getLifetimeCost(): number;
|
|
70
|
+
getLifetimeSavings(): number;
|
|
71
|
+
resetLifetimeCost(): void;
|
|
72
|
+
sendStructuredPrompt(options: StructuredPromptOptions): Promise<string>;
|
|
73
|
+
sendChatMessage(history: ChatMessage[], userMessage: string, options?: ChatRequestOptions): Promise<ChatMessage>;
|
|
74
|
+
/** Undo strict mode's absent-becomes-null, in tool arguments and in a `responseSchema` answer. */
|
|
75
|
+
private restoreOptionalFields;
|
|
76
|
+
/**
|
|
77
|
+
* The Responses request body for a turn. Public for tests and for hosts that want to inspect the
|
|
78
|
+
* exact wire shape; not part of the stable contract.
|
|
79
|
+
*
|
|
80
|
+
* @internal
|
|
81
|
+
*/
|
|
82
|
+
buildRequestBody(history: ChatMessage[], userMessage: string, options?: ChatRequestOptions): Record<string, unknown>;
|
|
83
|
+
private warnIfThinkingClamped;
|
|
84
|
+
private toInputItems;
|
|
85
|
+
/**
|
|
86
|
+
* A tool result, always as content parts — never the plain-string form. A cache hit needs the
|
|
87
|
+
* whole rendered prefix to match, and a breakpoint can only sit on a part, so a string output
|
|
88
|
+
* that became an array when it carried one would render differently on the next turn.
|
|
89
|
+
*/
|
|
90
|
+
private toFunctionCallOutput;
|
|
91
|
+
/**
|
|
92
|
+
* Put a history-scope breakpoint on every stored item that can carry one — a user message's last
|
|
93
|
+
* text part or a tool result's — up to the latest `MAX_HISTORY_BREAKPOINTS`.
|
|
94
|
+
*
|
|
95
|
+
* One breakpoint on the last item (Anthropic's shape) never hits on OpenAI: lookup checks only the
|
|
96
|
+
* breakpoints in this request, and the last item moves every turn, so the previous turn's boundary
|
|
97
|
+
* was unmarked and every turn rewrote the whole history to cache. Marking each boundary keeps the
|
|
98
|
+
* previous turn's in the request. Assistant items cannot carry one.
|
|
99
|
+
*/
|
|
100
|
+
private markHistoryBreakpoints;
|
|
101
|
+
private static readonly COST_DECIMAL_PLACES;
|
|
102
|
+
private usageFromResponse;
|
|
103
|
+
private fromResponse;
|
|
104
|
+
private buildEndpoint;
|
|
105
|
+
/**
|
|
106
|
+
* 429 is retried only once the proxy has ruled out an account wall — `insufficient_quota` and the
|
|
107
|
+
* spend-limit codes arrive as `PROVIDER_REFUSED`, which `postWithRetry` never retries. 500/502/503
|
|
108
|
+
* are OpenAI's documented transient faults (`server_error`, `server_is_overloaded`).
|
|
109
|
+
*/
|
|
110
|
+
private static readonly RATE_LIMIT_STATUS;
|
|
111
|
+
private static readonly SERVER_ERROR_STATUS;
|
|
112
|
+
private static readonly BAD_GATEWAY_STATUS;
|
|
113
|
+
private static readonly SERVICE_UNAVAILABLE_STATUS;
|
|
114
|
+
private static readonly RETRYABLE_STATUSES;
|
|
115
|
+
private static readonly BACKOFF_BASE_MS;
|
|
116
|
+
private post;
|
|
117
|
+
}
|
|
118
|
+
export {};
|
|
119
|
+
//# sourceMappingURL=openai-transport.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openai-transport.d.ts","sourceRoot":"","sources":["../../../src/transports/openai-transport.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,WAAW,EAChB,KAAK,sBAAsB,EAC3B,KAAK,aAAa,EAClB,KAAK,uBAAuB,EAC7B,MAAM,UAAU,CAAC;AAClB,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AACnE,OAAO,KAAK,EAEV,WAAW,EACX,kBAAkB,EAElB,kBAAkB,EAInB,MAAM,qBAAqB,CAAC;AAwC7B,KAAK,YAAY,GAAG,MAAM,GAAG,KAAK,GAAG,QAAQ,GAAG,MAAM,GAAG,KAAK,CAAC;AAe/D;;;;GAIG;AACH,wBAAgB,eAAe,CAC7B,KAAK,EAAE,aAAa,EACpB,MAAM,CAAC,EAAE,kBAAkB,GAC1B,YAAY,GAAG,SAAS,CAI1B;AAmDD,YAAY;AACZ,MAAM,WAAW,qBAAqB;IACpC,sFAAsF;IACtF,KAAK,CAAC,EAAE,aAAa,CAAC;IACtB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;OAGG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,+EAA+E;IAC/E,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,mGAAmG;IACnG,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,mFAAmF;IACnF,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;;OAIG;IACH,gBAAgB,CAAC,EA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C;IAkF1B,OAAO,CAAC,qBAAqB;IAe7B,OAAO,CAAC,YAAY;IAqEpB;;;;OAIG;IACH,OAAO,CAAC,oBAAoB;IAU5B;;;;;;;;OAQG;IACH,OAAO,CAAC,sBAAsB;IA2B9B,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,mBAAmB,CAAK;IAEhD,OAAO,CAAC,iBAAiB;IA4DzB,OAAO,CAAC,YAAY;IAiHpB,OAAO,CAAC,aAAa;IA6BrB;;;;OAIG;IACH,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,iBAAiB,CAAO;IAChD,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,mBAAmB,CAAO;IAClD,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,kBAAkB,CAAO;IACjD,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,0BAA0B,CAAO;IACzD,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,kBAAkB,CAKxC;IACF,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,eAAe,CAAQ;YAEjC,IAAI;CAenB"}
|
|
@@ -552,6 +552,18 @@ export interface ChatMessage {
|
|
|
552
552
|
* and `providerName`.
|
|
553
553
|
*/
|
|
554
554
|
provider?: AIProviderType;
|
|
555
|
+
/**
|
|
556
|
+
* Opaque, provider-specific state attached to this MESSAGE that must round-trip back to the
|
|
557
|
+
* originating provider on later requests — the message-level twin of
|
|
558
|
+
* `ChatToolCall.providerMetadata`, same contract: keyed by provider id, a transport reads only its
|
|
559
|
+
* own key, and the contents are not part of the stable public contract.
|
|
560
|
+
*
|
|
561
|
+
* Exists because some state belongs to a turn that made no tool call. OpenAI's Responses API marks
|
|
562
|
+
* each assistant message with a `phase` (`commentary` / `final_answer`) and attaches encrypted
|
|
563
|
+
* reasoning items to it; with no tool call to hang them on, a text-only turn would lose both, and a
|
|
564
|
+
* preamble replayed without its `phase` can be read back as the final answer.
|
|
565
|
+
*/
|
|
566
|
+
providerMetadata?: Record<string, unknown>;
|
|
555
567
|
}
|
|
556
568
|
/**
|
|
557
569
|
* Metadata for a `'compacted-summary'` message — the destructive replacement of
|
|
@@ -682,6 +694,27 @@ export interface ChatResponseMeta {
|
|
|
682
694
|
};
|
|
683
695
|
/** Provider block reason when the prompt/response was blocked rather than generated. */
|
|
684
696
|
blockReason?: string;
|
|
697
|
+
/**
|
|
698
|
+
* The request asked to FORCE a tool call (`toolChoice: 'required'` or `{ tool }`), and the model
|
|
699
|
+
* rejects forced tool use (Anthropic Opus 5.5 / Sonnet 5.5), so it went out as `'auto'` plus an
|
|
700
|
+
* instruction to call the tool. The reply may therefore be text with no tool call, which a
|
|
701
|
+
* forced request could never return; a driver that relies on forcing should check this and
|
|
702
|
+
* retry. Absent on every request that was sent as asked.
|
|
703
|
+
*/
|
|
704
|
+
toolChoiceDowngraded?: boolean;
|
|
705
|
+
/**
|
|
706
|
+
* What the provider changed in the request before the model saw it (Anthropic
|
|
707
|
+
* `input_transformations`), verbatim. Today: thinking blocks dropped by preserved thinking's
|
|
708
|
+
* checks — `type: 'thinking_dropped'`, `path` into the sent `messages` (e.g.
|
|
709
|
+
* `'messages.7.content.0'`), `reason` `'prefix_binding_mismatch'` (earlier history changed) or
|
|
710
|
+
* `'model_binding_mismatch'` (the conversation switched model). `type` and `reason` are open
|
|
711
|
+
* sets. Absent when nothing was changed.
|
|
712
|
+
*/
|
|
713
|
+
inputTransformations?: Array<{
|
|
714
|
+
type: string;
|
|
715
|
+
path?: string;
|
|
716
|
+
reason?: string;
|
|
717
|
+
}>;
|
|
685
718
|
}
|
|
686
719
|
/**
|
|
687
720
|
* JSON Schema-based tool definition for function calling.
|