@modelprofile.com/flexharness-providers 9.1.0 → 9.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist_ts_anthropic_messages/errors.d.ts +22 -0
- package/dist_ts_anthropic_messages/errors.js +100 -0
- package/dist_ts_anthropic_messages/index.d.ts +4 -0
- package/dist_ts_anthropic_messages/index.js +4 -0
- package/dist_ts_anthropic_messages/interfaces.d.ts +185 -0
- package/dist_ts_anthropic_messages/interfaces.js +2 -0
- package/dist_ts_anthropic_messages/openai.d.ts +19 -0
- package/dist_ts_anthropic_messages/openai.js +48 -0
- package/dist_ts_anthropic_messages/plugins.d.ts +4 -0
- package/dist_ts_anthropic_messages/plugins.js +4 -0
- package/dist_ts_anthropic_messages/request.d.ts +109 -0
- package/dist_ts_anthropic_messages/request.js +554 -0
- package/dist_ts_anthropic_messages/service.d.ts +8 -0
- package/dist_ts_anthropic_messages/service.js +274 -0
- package/dist_ts_anthropic_messages/signature.d.ts +16 -0
- package/dist_ts_anthropic_messages/signature.js +91 -0
- package/dist_ts_anthropic_messages/stream.d.ts +48 -0
- package/dist_ts_anthropic_messages/stream.js +220 -0
- package/dist_ts_anthropic_messages_node/index.d.ts +8 -0
- package/dist_ts_anthropic_messages_node/index.js +93 -0
- package/dist_ts_anthropic_messages_node/plugins.d.ts +6 -0
- package/dist_ts_anthropic_messages_node/plugins.js +4 -0
- package/dist_ts_media_openai/index.js +2 -3
- package/dist_ts_media_openai/plugins.d.ts +2 -0
- package/dist_ts_media_openai/plugins.js +5 -1
- package/dist_ts_openai_account/index.d.ts +1 -1
- package/dist_ts_openai_account/index.js +2 -2
- package/dist_ts_openai_account/plugins.d.ts +3 -0
- package/dist_ts_openai_account/plugins.js +3 -1
- package/dist_ts_openai_account/smartai.providers.credentials.d.ts +2 -2
- package/dist_ts_openai_account/smartai.providers.credentials.js +3 -4
- package/dist_ts_openai_account/smartai.providers.interfaces.d.ts +6 -7
- package/dist_ts_openai_account/smartai.providers.openai.js +15 -16
- package/dist_ts_openai_auth/index.d.ts +1 -1
- package/dist_ts_openai_auth/index.js +2 -2
- package/dist_ts_openai_auth/interfaces.d.ts +1 -1
- package/dist_ts_openai_auth/plugins.d.ts +3 -0
- package/dist_ts_openai_auth/plugins.js +4 -0
- package/dist_ts_openai_auth/smartai.auth.openai.d.ts +1 -2
- package/dist_ts_openai_auth/smartai.auth.openai.js +27 -27
- package/dist_ts_openai_auth/smartai.connection.openai.d.ts +3 -3
- package/dist_ts_openai_auth/smartai.connection.openai.js +6 -6
- package/dist_ts_openai_auth_files/index.d.ts +6 -6
- package/dist_ts_openai_auth_files/index.js +3 -4
- package/dist_ts_openai_auth_files/plugins.d.ts +3 -0
- package/dist_ts_openai_auth_files/plugins.js +4 -1
- package/dist_ts_providers/anthropic/index.d.ts +1 -1
- package/dist_ts_providers/anthropic/index.js +1 -1
- package/dist_ts_providers/anthropic/plugins.d.ts +4 -3
- package/dist_ts_providers/anthropic/plugins.js +3 -3
- package/dist_ts_providers/anthropic/smartai.middleware.anthropic.d.ts +2 -3
- package/dist_ts_providers/anthropic/smartai.middleware.anthropic.js +3 -3
- package/dist_ts_providers/google/index.d.ts +1 -1
- package/dist_ts_providers/google/index.js +1 -1
- package/dist_ts_providers/google/plugins.d.ts +1 -1
- package/dist_ts_providers/groq/index.d.ts +1 -1
- package/dist_ts_providers/groq/index.js +1 -1
- package/dist_ts_providers/groq/plugins.d.ts +1 -1
- package/dist_ts_providers/mistral/index.d.ts +1 -1
- package/dist_ts_providers/mistral/index.js +1 -1
- package/dist_ts_providers/mistral/plugins.d.ts +1 -1
- package/dist_ts_providers/ollama/index.d.ts +2 -2
- package/dist_ts_providers/ollama/index.js +1 -1
- package/dist_ts_providers/ollama/interfaces.d.ts +2 -2
- package/dist_ts_providers/ollama/plugins.d.ts +2 -0
- package/dist_ts_providers/ollama/plugins.js +2 -0
- package/dist_ts_providers/ollama/smartai.provider.ollama.d.ts +2 -2
- package/dist_ts_providers/ollama/smartai.provider.ollama.js +1 -1
- package/dist_ts_providers/openai/index.d.ts +1 -1
- package/dist_ts_providers/openai/index.js +1 -1
- package/dist_ts_providers/openai/plugins.d.ts +1 -1
- package/dist_ts_providers/openai/smartai.chatgpt.catalog.d.ts +2 -0
- package/dist_ts_providers/openai/smartai.chatgpt.catalog.js +8 -1
- package/dist_ts_providers/openai/smartai.chatgpt.middleware.d.ts +5 -1
- package/dist_ts_providers/openai/smartai.chatgpt.middleware.js +25 -12
- package/dist_ts_providers/openai/smartai.limits.openai.d.ts +4 -1
- package/dist_ts_providers/openai/smartai.limits.openai.js +10 -5
- package/dist_ts_providers/perplexity/index.d.ts +1 -1
- package/dist_ts_providers/perplexity/index.js +1 -1
- package/dist_ts_providers/perplexity/plugins.d.ts +1 -1
- package/dist_ts_providers/xai/index.d.ts +1 -1
- package/dist_ts_providers/xai/index.js +1 -1
- package/dist_ts_providers/xai/plugins.d.ts +1 -1
- package/package.json +23 -11
- package/readme.md +1 -0
- package/ts_anthropic_messages/errors.ts +124 -0
- package/ts_anthropic_messages/index.ts +24 -0
- package/ts_anthropic_messages/interfaces.ts +173 -0
- package/ts_anthropic_messages/openai.ts +58 -0
- package/ts_anthropic_messages/plugins.ts +26 -0
- package/ts_anthropic_messages/readme.md +129 -0
- package/ts_anthropic_messages/request.ts +652 -0
- package/ts_anthropic_messages/service.ts +312 -0
- package/ts_anthropic_messages/signature.ts +107 -0
- package/ts_anthropic_messages/stream.ts +260 -0
- package/ts_anthropic_messages_node/index.ts +99 -0
- package/ts_anthropic_messages_node/plugins.ts +7 -0
- package/ts_anthropic_messages_node/readme.md +50 -0
- package/ts_media_openai/index.ts +1 -2
- package/ts_media_openai/plugins.ts +6 -0
- package/ts_openai_account/index.ts +1 -1
- package/ts_openai_account/plugins.ts +37 -0
- package/ts_openai_account/smartai.providers.credentials.ts +3 -5
- package/ts_openai_account/smartai.providers.interfaces.ts +6 -12
- package/ts_openai_account/smartai.providers.openai.ts +18 -31
- package/ts_openai_auth/index.ts +1 -1
- package/ts_openai_auth/interfaces.ts +1 -1
- package/ts_openai_auth/plugins.ts +17 -0
- package/ts_openai_auth/smartai.auth.openai.ts +28 -33
- package/ts_openai_auth/smartai.connection.openai.ts +7 -11
- package/ts_openai_auth_files/index.ts +19 -28
- package/ts_openai_auth_files/plugins.ts +10 -0
- package/ts_providers/anthropic/index.ts +1 -1
- package/ts_providers/anthropic/plugins.ts +11 -1
- package/ts_providers/anthropic/smartai.middleware.anthropic.ts +3 -5
- package/ts_providers/google/index.ts +1 -1
- package/ts_providers/google/plugins.ts +1 -1
- package/ts_providers/groq/index.ts +1 -1
- package/ts_providers/groq/plugins.ts +1 -1
- package/ts_providers/mistral/index.ts +1 -1
- package/ts_providers/mistral/plugins.ts +1 -1
- package/ts_providers/ollama/index.ts +2 -2
- package/ts_providers/ollama/interfaces.ts +2 -2
- package/ts_providers/ollama/plugins.ts +12 -0
- package/ts_providers/ollama/smartai.provider.ollama.ts +11 -21
- package/ts_providers/openai/index.ts +1 -1
- package/ts_providers/openai/plugins.ts +1 -0
- package/ts_providers/openai/readme.md +9 -6
- package/ts_providers/openai/smartai.chatgpt.catalog.ts +11 -0
- package/ts_providers/openai/smartai.chatgpt.middleware.ts +27 -11
- package/ts_providers/openai/smartai.limits.openai.ts +12 -4
- package/ts_providers/perplexity/index.ts +1 -1
- package/ts_providers/perplexity/plugins.ts +1 -1
- package/ts_providers/readme.md +1 -0
- package/ts_providers/xai/index.ts +1 -1
- package/ts_providers/xai/plugins.ts +1 -1
|
@@ -1,14 +1,4 @@
|
|
|
1
|
-
import type
|
|
2
|
-
LanguageModelV3,
|
|
3
|
-
LanguageModelV3CallOptions,
|
|
4
|
-
LanguageModelV3GenerateResult,
|
|
5
|
-
LanguageModelV3StreamResult,
|
|
6
|
-
LanguageModelV3StreamPart,
|
|
7
|
-
LanguageModelV3Prompt,
|
|
8
|
-
LanguageModelV3Content,
|
|
9
|
-
LanguageModelV3Usage,
|
|
10
|
-
LanguageModelV3FinishReason,
|
|
11
|
-
} from '@ai-sdk/provider';
|
|
1
|
+
import type * as plugins from './plugins.js';
|
|
12
2
|
import type { IOllamaModelRequest, IOllamaModelOptions } from './interfaces.js';
|
|
13
3
|
|
|
14
4
|
interface IOllamaMessage {
|
|
@@ -33,7 +23,7 @@ interface IOllamaTool {
|
|
|
33
23
|
/**
|
|
34
24
|
* Convert AI SDK V3 prompt messages to Ollama's message format.
|
|
35
25
|
*/
|
|
36
|
-
function convertPromptToOllamaMessages(prompt: LanguageModelV3Prompt): IOllamaMessage[] {
|
|
26
|
+
function convertPromptToOllamaMessages(prompt: plugins.LanguageModelV3Prompt): IOllamaMessage[] {
|
|
37
27
|
const messages: IOllamaMessage[] = [];
|
|
38
28
|
|
|
39
29
|
for (const msg of prompt) {
|
|
@@ -106,7 +96,7 @@ function convertPromptToOllamaMessages(prompt: LanguageModelV3Prompt): IOllamaMe
|
|
|
106
96
|
/**
|
|
107
97
|
* Convert AI SDK V3 tools to Ollama's tool format.
|
|
108
98
|
*/
|
|
109
|
-
function convertToolsToOllamaTools(tools: LanguageModelV3CallOptions['tools']): IOllamaTool[] | undefined {
|
|
99
|
+
function convertToolsToOllamaTools(tools: plugins.LanguageModelV3CallOptions['tools']): IOllamaTool[] | undefined {
|
|
110
100
|
if (!tools || tools.length === 0) return undefined;
|
|
111
101
|
|
|
112
102
|
return tools
|
|
@@ -121,7 +111,7 @@ function convertToolsToOllamaTools(tools: LanguageModelV3CallOptions['tools']):
|
|
|
121
111
|
}));
|
|
122
112
|
}
|
|
123
113
|
|
|
124
|
-
function makeUsage(promptTokens?: number, completionTokens?: number): LanguageModelV3Usage {
|
|
114
|
+
function makeUsage(promptTokens?: number, completionTokens?: number): plugins.LanguageModelV3Usage {
|
|
125
115
|
return {
|
|
126
116
|
inputTokens: {
|
|
127
117
|
total: promptTokens,
|
|
@@ -137,7 +127,7 @@ function makeUsage(promptTokens?: number, completionTokens?: number): LanguageMo
|
|
|
137
127
|
};
|
|
138
128
|
}
|
|
139
129
|
|
|
140
|
-
function makeFinishReason(reason?: string): LanguageModelV3FinishReason {
|
|
130
|
+
function makeFinishReason(reason?: string): plugins.LanguageModelV3FinishReason {
|
|
141
131
|
if (reason === 'tool_calls' || reason === 'tool-calls') {
|
|
142
132
|
return { unified: 'tool-calls', raw: reason };
|
|
143
133
|
}
|
|
@@ -154,7 +144,7 @@ function generateId(): string {
|
|
|
154
144
|
* Calls Ollama's native /api/chat endpoint directly to support
|
|
155
145
|
* think, num_ctx, temperature, and other model options.
|
|
156
146
|
*/
|
|
157
|
-
export function createOllamaModel(options: IOllamaModelRequest): LanguageModelV3 {
|
|
147
|
+
export function createOllamaModel(options: IOllamaModelRequest): plugins.LanguageModelV3 {
|
|
158
148
|
const baseUrl = options.baseUrl ?? 'http://localhost:11434';
|
|
159
149
|
const modelId = options.model;
|
|
160
150
|
const ollamaOpts: IOllamaModelOptions = { ...options.ollamaOptions };
|
|
@@ -164,13 +154,13 @@ export function createOllamaModel(options: IOllamaModelRequest): LanguageModelV3
|
|
|
164
154
|
ollamaOpts.temperature = 0.55;
|
|
165
155
|
}
|
|
166
156
|
|
|
167
|
-
const model: LanguageModelV3 = {
|
|
157
|
+
const model: plugins.LanguageModelV3 = {
|
|
168
158
|
specificationVersion: 'v3',
|
|
169
159
|
provider: 'ollama',
|
|
170
160
|
modelId,
|
|
171
161
|
supportedUrls: {},
|
|
172
162
|
|
|
173
|
-
async doGenerate(callOptions: LanguageModelV3CallOptions): Promise<LanguageModelV3GenerateResult> {
|
|
163
|
+
async doGenerate(callOptions: plugins.LanguageModelV3CallOptions): Promise<plugins.LanguageModelV3GenerateResult> {
|
|
174
164
|
const messages = convertPromptToOllamaMessages(callOptions.prompt);
|
|
175
165
|
const tools = convertToolsToOllamaTools(callOptions.tools);
|
|
176
166
|
|
|
@@ -215,7 +205,7 @@ export function createOllamaModel(options: IOllamaModelRequest): LanguageModelV3
|
|
|
215
205
|
const message = result.message as Record<string, unknown>;
|
|
216
206
|
|
|
217
207
|
// Build content array
|
|
218
|
-
const content: LanguageModelV3Content[] = [];
|
|
208
|
+
const content: plugins.LanguageModelV3Content[] = [];
|
|
219
209
|
|
|
220
210
|
// Add reasoning if present
|
|
221
211
|
if (message.thinking && typeof message.thinking === 'string') {
|
|
@@ -256,7 +246,7 @@ export function createOllamaModel(options: IOllamaModelRequest): LanguageModelV3
|
|
|
256
246
|
};
|
|
257
247
|
},
|
|
258
248
|
|
|
259
|
-
async doStream(callOptions: LanguageModelV3CallOptions): Promise<LanguageModelV3StreamResult> {
|
|
249
|
+
async doStream(callOptions: plugins.LanguageModelV3CallOptions): Promise<plugins.LanguageModelV3StreamResult> {
|
|
260
250
|
const messages = convertPromptToOllamaMessages(callOptions.prompt);
|
|
261
251
|
const tools = convertToolsToOllamaTools(callOptions.tools);
|
|
262
252
|
|
|
@@ -304,7 +294,7 @@ export function createOllamaModel(options: IOllamaModelRequest): LanguageModelV3
|
|
|
304
294
|
let hasToolCalls = false;
|
|
305
295
|
let closed = false;
|
|
306
296
|
|
|
307
|
-
const stream = new ReadableStream<LanguageModelV3StreamPart>({
|
|
297
|
+
const stream = new ReadableStream<plugins.LanguageModelV3StreamPart>({
|
|
308
298
|
async pull(controller) {
|
|
309
299
|
if (closed) return;
|
|
310
300
|
|
|
@@ -62,7 +62,7 @@ export interface IOpenAiModelOptions extends plugins.ISmartAiOptions {
|
|
|
62
62
|
api?: TOpenAiApi;
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
-
export const createOpenAiModelProvider = (): plugins.IModelProvider<IOpenAiModelOptions> => ({
|
|
65
|
+
export const createOpenAiModelProvider = (): plugins.IModelProvider<IOpenAiModelOptions, plugins.LanguageModelV4> => ({
|
|
66
66
|
id: 'openai',
|
|
67
67
|
getModel: (options) => {
|
|
68
68
|
const api = options.api ?? 'responses';
|
|
@@ -43,8 +43,9 @@ const model = models.getModel({
|
|
|
43
43
|
A spent API balance (`insufficient_quota`) fails as a `ModelLimitError` of kind `usage_limit`,
|
|
44
44
|
and any other 429 as kind `rate_limit` with the `retry-after` delay; see the toolbox readme's
|
|
45
45
|
usage and rate limits section. A `connection` can add its own limit dialect with
|
|
46
|
-
`classifyLimit`, which is consulted first.
|
|
47
|
-
|
|
46
|
+
`classifyLimit`, which is consulted first. A limit a stream reports, in a `response.failed` or an
|
|
47
|
+
`error` event, before or after the answer began, is classified the same way. `classifyOpenAiLimit`
|
|
48
|
+
and `readOpenAiError` are exported for connections that extend the OpenAI dialect.
|
|
48
49
|
|
|
49
50
|
## ChatGPT with access from an account authority
|
|
50
51
|
|
|
@@ -93,11 +94,13 @@ included, in the catalog's priority order, with the first listed model marked `i
|
|
|
93
94
|
rejected token fails with an `OpenAiChatGptAuthError` whose `status` is 401, so a caller resolves
|
|
94
95
|
again with `rejectedGeneration` and repeats the read; an abort rejects with the signal's reason;
|
|
95
96
|
anything else is an `OpenAiChatGptModelListError` whose `code` is `NETWORK_FAILED`, `HTTP_ERROR`
|
|
96
|
-
(with `status`) or `PROTOCOL_ERROR`.
|
|
97
|
+
(with `status`) or `PROTOCOL_ERROR`. A model whose catalog entry states its context window carries it as
|
|
98
|
+
`contextWindow`, in tokens.
|
|
97
99
|
|
|
98
|
-
Both ChatGPT connections classify Codex limits with `classifyOpenAiChatGptLimit` and move system
|
|
99
|
-
|
|
100
|
-
|
|
100
|
+
Both ChatGPT connections classify Codex limits with `classifyOpenAiChatGptLimit` and move the system
|
|
101
|
+
messages a prompt opens with into the Responses `instructions` with
|
|
102
|
+
`createOpenAiChatGptInstructionsMiddleware()`; a system message later in the conversation stays in its
|
|
103
|
+
place as a `developer` input item. Both are exported here for connections of their own.
|
|
101
104
|
|
|
102
105
|
The `/auth` subpath keeps its connections, which derive identity from the token itself, and
|
|
103
106
|
re-exports the ChatGPT limit classifier, the instructions middleware, the Codex base URL, the
|
|
@@ -40,6 +40,8 @@ export interface IOpenAiChatGptModel {
|
|
|
40
40
|
supportsPersonality: boolean;
|
|
41
41
|
serviceTiers: IOpenAiChatGptModelServiceTier[];
|
|
42
42
|
defaultServiceTier?: string;
|
|
43
|
+
/** The context window in tokens, as the catalog states it; absent when the catalog states none. */
|
|
44
|
+
contextWindow?: number;
|
|
43
45
|
/** The first listed model, or the first model when none is listed. */
|
|
44
46
|
isDefault: boolean;
|
|
45
47
|
}
|
|
@@ -193,6 +195,14 @@ const projectCatalog = (valueArg: unknown): IOpenAiChatGptModel[] => {
|
|
|
193
195
|
description: boundedString(rawTier.description, 1024, true),
|
|
194
196
|
};
|
|
195
197
|
});
|
|
198
|
+
const contextWindow = rawModel.context_window;
|
|
199
|
+
if (
|
|
200
|
+
contextWindow !== null
|
|
201
|
+
&& contextWindow !== undefined
|
|
202
|
+
&& (!Number.isSafeInteger(contextWindow) || (contextWindow as number) < 1)
|
|
203
|
+
) {
|
|
204
|
+
throw protocolError();
|
|
205
|
+
}
|
|
196
206
|
const modelMessages = isRecord(rawModel.model_messages) ? rawModel.model_messages : undefined;
|
|
197
207
|
const variables = isRecord(modelMessages?.instructions_variables)
|
|
198
208
|
? modelMessages.instructions_variables
|
|
@@ -225,6 +235,7 @@ const projectCatalog = (valueArg: unknown): IOpenAiChatGptModel[] => {
|
|
|
225
235
|
...(rawModel.default_service_tier === null || rawModel.default_service_tier === undefined
|
|
226
236
|
? {}
|
|
227
237
|
: { defaultServiceTier: boundedString(rawModel.default_service_tier, 128) }),
|
|
238
|
+
...(contextWindow === null || contextWindow === undefined ? {} : { contextWindow: contextWindow as number }),
|
|
228
239
|
isDefault: false,
|
|
229
240
|
},
|
|
230
241
|
};
|
|
@@ -2,9 +2,16 @@ import type * as plugins from './plugins.js';
|
|
|
2
2
|
|
|
3
3
|
const isNonEmptyString = (value: unknown): value is string => typeof value === 'string' && value.trim().length > 0;
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
type TPrompt = plugins.LanguageModelV4CallOptions['prompt'];
|
|
6
|
+
|
|
7
|
+
/** The number of system messages the prompt opens with, before its first other message. */
|
|
8
|
+
const countLeadingSystemMessages = (prompt: TPrompt): number => {
|
|
9
|
+
const firstOther = prompt.findIndex((message) => message.role !== 'system');
|
|
10
|
+
return firstOther === -1 ? prompt.length : firstOther;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
const joinSystemInstructions = (messages: TPrompt): string | undefined => {
|
|
14
|
+
const instructions = messages
|
|
8
15
|
.map((message) => message.content)
|
|
9
16
|
.filter(isNonEmptyString);
|
|
10
17
|
|
|
@@ -17,34 +24,43 @@ const hasUnsupportedChatGptCacheRetention = (options: plugins.JSONObject): boole
|
|
|
17
24
|
|
|
18
25
|
/**
|
|
19
26
|
* ChatGPT's Codex backend requires top-level Responses API instructions.
|
|
20
|
-
*
|
|
27
|
+
*
|
|
28
|
+
* The system messages a prompt opens with become those instructions. A system message later in the
|
|
29
|
+
* conversation keeps its place and is sent as a `developer` input item, the role the Codex backend reads
|
|
30
|
+
* mid-conversation instructions in, so moving it would neither reorder the conversation nor change the
|
|
31
|
+
* instructions prefix a prompt cache keys on. A caller's own `instructions` or `systemMessageMode` is kept.
|
|
21
32
|
*/
|
|
22
33
|
export function createOpenAiChatGptInstructionsMiddleware(): plugins.LanguageModelV4Middleware {
|
|
23
34
|
return {
|
|
24
35
|
specificationVersion: 'v4',
|
|
25
36
|
transformParams: async ({ params }) => {
|
|
26
|
-
const instructions = getSystemInstructions(params.prompt);
|
|
27
37
|
const providerOptions = params.providerOptions ?? {};
|
|
28
38
|
const openAiProviderOptions = providerOptions.openai ?? {};
|
|
29
|
-
const
|
|
39
|
+
const leadingCount = countLeadingSystemMessages(params.prompt);
|
|
40
|
+
const shouldHoist = leadingCount > 0 && !isNonEmptyString(openAiProviderOptions.instructions);
|
|
41
|
+
const instructions = shouldHoist ? joinSystemInstructions(params.prompt.slice(0, leadingCount)) : undefined;
|
|
42
|
+
const prompt = shouldHoist ? params.prompt.slice(leadingCount) : params.prompt;
|
|
43
|
+
const keepsSystemMessages = prompt.some((message) => message.role === 'system');
|
|
44
|
+
const shouldSetDeveloperMode = keepsSystemMessages && openAiProviderOptions.systemMessageMode === undefined;
|
|
30
45
|
const shouldStripCacheRetention = hasUnsupportedChatGptCacheRetention(openAiProviderOptions);
|
|
31
46
|
|
|
32
|
-
if (!
|
|
47
|
+
if (!shouldHoist && !shouldSetDeveloperMode && !shouldStripCacheRetention) {
|
|
33
48
|
return params;
|
|
34
49
|
}
|
|
35
50
|
|
|
36
51
|
const nextOpenAiProviderOptions: plugins.JSONObject = { ...openAiProviderOptions };
|
|
37
52
|
delete nextOpenAiProviderOptions.promptCacheRetention;
|
|
38
53
|
delete nextOpenAiProviderOptions.prompt_cache_retention;
|
|
39
|
-
if (
|
|
54
|
+
if (instructions) {
|
|
40
55
|
nextOpenAiProviderOptions.instructions = instructions;
|
|
41
56
|
}
|
|
57
|
+
if (shouldSetDeveloperMode) {
|
|
58
|
+
nextOpenAiProviderOptions.systemMessageMode = 'developer';
|
|
59
|
+
}
|
|
42
60
|
|
|
43
61
|
return {
|
|
44
62
|
...params,
|
|
45
|
-
prompt
|
|
46
|
-
? params.prompt.filter((message) => message.role !== 'system')
|
|
47
|
-
: params.prompt,
|
|
63
|
+
prompt,
|
|
48
64
|
providerOptions: {
|
|
49
65
|
...providerOptions,
|
|
50
66
|
openai: nextOpenAiProviderOptions,
|
|
@@ -1,19 +1,27 @@
|
|
|
1
1
|
import * as plugins from './plugins.js';
|
|
2
2
|
|
|
3
|
-
/**
|
|
3
|
+
/**
|
|
4
|
+
* The error object of an OpenAI error body, of a Responses `response.failed` stream frame or of a
|
|
5
|
+
* Responses `error` stream frame.
|
|
6
|
+
*/
|
|
4
7
|
export interface IOpenAiErrorDetails {
|
|
5
8
|
/** The error's `type` and `code`; HTTP bodies name the error in `type`, stream frames in `code`. */
|
|
6
9
|
readonly identifiers: readonly string[];
|
|
7
10
|
readonly fields: Readonly<Record<string, unknown>>;
|
|
8
11
|
}
|
|
9
12
|
|
|
13
|
+
function readIdentifiers(...values: unknown[]): string[] {
|
|
14
|
+
return values.filter((value): value is string => typeof value === 'string');
|
|
15
|
+
}
|
|
16
|
+
|
|
10
17
|
export function readOpenAiError(body: unknown): IOpenAiErrorDetails | undefined {
|
|
11
18
|
const envelope = plugins.readJsonRecord(body);
|
|
12
19
|
const fields = plugins.readJsonRecord(envelope?.error)
|
|
13
20
|
?? plugins.readJsonRecord(plugins.readJsonRecord(envelope?.response)?.error);
|
|
14
|
-
if (
|
|
15
|
-
|
|
16
|
-
return { identifiers, fields };
|
|
21
|
+
if (fields) return { identifiers: readIdentifiers(fields.type, fields.code), fields };
|
|
22
|
+
// an `error` stream frame may carry its fields beside `type: 'error'`, which names the frame, not the error
|
|
23
|
+
if (envelope?.type === 'error') return { identifiers: readIdentifiers(envelope.code), fields: envelope };
|
|
24
|
+
return undefined;
|
|
17
25
|
}
|
|
18
26
|
|
|
19
27
|
/** OpenAI API limits: `insufficient_quota` is an exhausted balance, any other 429 a rate limit. */
|
|
@@ -2,7 +2,7 @@ import * as plugins from './plugins.js';
|
|
|
2
2
|
|
|
3
3
|
export interface IPerplexityModelOptions extends plugins.ISmartAiOptions { provider: 'perplexity'; }
|
|
4
4
|
|
|
5
|
-
export const createPerplexityModelProvider = (): plugins.IModelProvider<IPerplexityModelOptions> => ({
|
|
5
|
+
export const createPerplexityModelProvider = (): plugins.IModelProvider<IPerplexityModelOptions, plugins.LanguageModelV4> => ({
|
|
6
6
|
id: 'perplexity',
|
|
7
7
|
getModel: (options) => plugins.createPerplexity({ apiKey: options.apiKey })(options.model),
|
|
8
8
|
});
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { createPerplexity } from '@ai-sdk/perplexity';
|
|
2
2
|
export { createPerplexity };
|
|
3
|
-
export type { IModelProvider, ISmartAiOptions } from '@modelprofile.com/flexharness-models';
|
|
3
|
+
export type { IModelProvider, ISmartAiOptions, LanguageModelV4 } from '@modelprofile.com/flexharness-models';
|
package/ts_providers/readme.md
CHANGED
|
@@ -31,6 +31,7 @@ factories; use a provider subpath to import just that implementation.
|
|
|
31
31
|
| `/auth/files` | Explicit interoperability with external credential files |
|
|
32
32
|
| `/media` | OpenAI audio and image generation |
|
|
33
33
|
| `/research` | Anthropic research utilities |
|
|
34
|
+
| `/anthropic-messages`, `/anthropic-messages/node` | Serves the Anthropic Messages API over FlexHarness models, for Anthropic clients such as Claude Code |
|
|
34
35
|
|
|
35
36
|
Provider SDKs are installed together. Authentication, file access and vendor media
|
|
36
37
|
are separate entrypoints and are not imported by the provider factory root. For
|
|
@@ -2,7 +2,7 @@ import * as plugins from './plugins.js';
|
|
|
2
2
|
|
|
3
3
|
export interface IXaiModelOptions extends plugins.ISmartAiOptions { provider: 'xai'; }
|
|
4
4
|
|
|
5
|
-
export const createXaiModelProvider = (): plugins.IModelProvider<IXaiModelOptions> => ({
|
|
5
|
+
export const createXaiModelProvider = (): plugins.IModelProvider<IXaiModelOptions, plugins.LanguageModelV4> => ({
|
|
6
6
|
id: 'xai',
|
|
7
7
|
getModel: (options) => plugins.createXai({ apiKey: options.apiKey })(options.model),
|
|
8
8
|
});
|