@modelprofile.com/flexharness-providers 9.0.0 → 9.2.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_openai_account/plugins.d.ts +2 -0
- package/dist_ts_openai_account/plugins.js +4 -1
- package/dist_ts_openai_account/smartai.providers.interfaces.d.ts +6 -22
- package/dist_ts_openai_account/smartai.providers.openai.js +15 -134
- package/dist_ts_openai_auth/index.d.ts +1 -2
- package/dist_ts_openai_auth/index.js +2 -3
- package/dist_ts_openai_auth/interfaces.d.ts +1 -1
- package/dist_ts_openai_auth/smartai.auth.openai.d.ts +3 -15
- package/dist_ts_openai_auth/smartai.auth.openai.js +3 -17
- package/dist_ts_openai_auth/smartai.connection.openai.d.ts +1 -1
- package/dist_ts_openai_auth/smartai.connection.openai.js +2 -3
- 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 +1 -1
- 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/openai/index.d.ts +5 -1
- package/dist_ts_providers/openai/index.js +5 -1
- package/dist_ts_providers/openai/plugins.d.ts +4 -4
- package/dist_ts_providers/openai/plugins.js +3 -3
- package/dist_ts_providers/openai/smartai.chatgpt.catalog.d.ts +61 -0
- package/dist_ts_providers/openai/smartai.chatgpt.catalog.js +252 -0
- package/{dist_ts_openai_auth/smartai.limits.openai.d.ts → dist_ts_providers/openai/smartai.chatgpt.limits.d.ts} +2 -2
- package/dist_ts_providers/openai/smartai.chatgpt.limits.js +49 -0
- package/dist_ts_providers/openai/smartai.chatgpt.middleware.d.ts +10 -0
- package/dist_ts_providers/openai/smartai.chatgpt.middleware.js +60 -0
- package/dist_ts_providers/openai/smartai.chatgpt.openai.d.ts +92 -0
- package/dist_ts_providers/openai/smartai.chatgpt.openai.js +160 -0
- 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 +14 -2
- package/readme.md +9 -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_openai_account/plugins.ts +5 -0
- package/ts_openai_account/smartai.providers.interfaces.ts +11 -25
- package/ts_openai_account/smartai.providers.openai.ts +16 -135
- package/ts_openai_auth/index.ts +4 -2
- package/ts_openai_auth/interfaces.ts +1 -1
- package/ts_openai_auth/smartai.auth.openai.ts +12 -24
- package/ts_openai_auth/smartai.connection.openai.ts +5 -3
- package/ts_providers/anthropic/index.ts +1 -1
- package/ts_providers/anthropic/plugins.ts +1 -0
- 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/openai/index.ts +30 -1
- package/ts_providers/openai/plugins.ts +5 -3
- package/ts_providers/openai/readme.md +60 -7
- package/ts_providers/openai/smartai.chatgpt.catalog.ts +319 -0
- package/{ts_openai_auth/smartai.limits.openai.ts → ts_providers/openai/smartai.chatgpt.limits.ts} +6 -7
- package/ts_providers/openai/smartai.chatgpt.middleware.ts +71 -0
- package/ts_providers/openai/smartai.chatgpt.openai.ts +271 -0
- package/ts_providers/perplexity/index.ts +1 -1
- package/ts_providers/perplexity/plugins.ts +1 -1
- package/ts_providers/readme.md +9 -0
- package/ts_providers/xai/index.ts +1 -1
- package/ts_providers/xai/plugins.ts +1 -1
- package/dist_ts_openai_auth/smartai.limits.openai.js +0 -49
- package/dist_ts_openai_auth/smartai.middleware.openai.d.ts +0 -6
- package/dist_ts_openai_auth/smartai.middleware.openai.js +0 -47
- package/ts_openai_auth/smartai.middleware.openai.ts +0 -55
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import * as plugins from './plugins.js';
|
|
2
|
+
import { promptTooLong } from './errors.js';
|
|
3
|
+
import type { IAnthropicMessagesControls, IAnthropicMessagesFailure, IAnthropicMessagesModel } from './interfaces.js';
|
|
4
|
+
|
|
5
|
+
export interface IOpenAiResponsesMessagesDialectOptions {
|
|
6
|
+
/**
|
|
7
|
+
* Whether the model reasons. A reasoning model is asked for its encrypted reasoning, which a thinking
|
|
8
|
+
* signature carries back to it, so a conversation keeps its reasoning across turns and tool calls.
|
|
9
|
+
*/
|
|
10
|
+
reasoning: boolean;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const isRecord = (valueArg: unknown): valueArg is Record<string, unknown> =>
|
|
14
|
+
typeof valueArg === 'object' && valueArg !== null && !Array.isArray(valueArg);
|
|
15
|
+
|
|
16
|
+
/** The OpenAI error of a failure: an HTTP error body, a failed response, or an error frame of a stream. */
|
|
17
|
+
const readOpenAiError = (valueArg: unknown): { code?: unknown; message?: unknown } | undefined => {
|
|
18
|
+
if (!isRecord(valueArg)) return undefined;
|
|
19
|
+
if (isRecord(valueArg.error)) return valueArg.error;
|
|
20
|
+
if (isRecord(valueArg.response) && isRecord(valueArg.response.error)) return valueArg.response.error;
|
|
21
|
+
if ('code' in valueArg) return valueArg;
|
|
22
|
+
return undefined;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Reads the OpenAI Responses failures the generic rules cannot: an input beyond the model's context window
|
|
27
|
+
* answers with the wording an Anthropic client compacts its conversation on.
|
|
28
|
+
*/
|
|
29
|
+
export const classifyOpenAiResponsesMessagesFailure = (errorArg: unknown): IAnthropicMessagesFailure | undefined => {
|
|
30
|
+
const error = plugins.APICallError.isInstance(errorArg) ? readOpenAiError(errorArg.data) : readOpenAiError(errorArg);
|
|
31
|
+
if (error?.code !== 'context_length_exceeded') return undefined;
|
|
32
|
+
return promptTooLong(typeof error.message === 'string' ? error.message : 'the input exceeds the model\'s context window.');
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* The OpenAI Responses dialect of a served model: nothing is stored at the provider, reasoning returns
|
|
37
|
+
* encrypted so a thinking signature can carry it, reasoning summaries are requested only when the client
|
|
38
|
+
* asked for thinking, and the client's session id keys the provider's prompt cache.
|
|
39
|
+
*/
|
|
40
|
+
export const createOpenAiResponsesMessagesDialect = (
|
|
41
|
+
optionsArg: IOpenAiResponsesMessagesDialectOptions,
|
|
42
|
+
): Pick<IAnthropicMessagesModel, 'providerOptions' | 'classifyFailure'> => ({
|
|
43
|
+
providerOptions: (controlsArg: IAnthropicMessagesControls) => ({
|
|
44
|
+
openai: {
|
|
45
|
+
store: false,
|
|
46
|
+
...(optionsArg.reasoning
|
|
47
|
+
? {
|
|
48
|
+
forceReasoning: true,
|
|
49
|
+
reasoningSummary: controlsArg.thinking ? 'auto' : null,
|
|
50
|
+
...(controlsArg.reasoningEffort === undefined ? {} : { reasoningEffort: controlsArg.reasoningEffort }),
|
|
51
|
+
}
|
|
52
|
+
: {}),
|
|
53
|
+
...(controlsArg.parallelToolCalls ? {} : { parallelToolCalls: false }),
|
|
54
|
+
...(controlsArg.sessionId === undefined ? {} : { promptCacheKey: controlsArg.sessionId }),
|
|
55
|
+
},
|
|
56
|
+
}),
|
|
57
|
+
classifyFailure: classifyOpenAiResponsesMessagesFailure,
|
|
58
|
+
});
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { APICallError } from '@ai-sdk/provider';
|
|
2
|
+
import { isModelLimitError } from '@modelprofile.com/flexharness-models';
|
|
3
|
+
|
|
4
|
+
export { APICallError, isModelLimitError };
|
|
5
|
+
export type {
|
|
6
|
+
JSONObject,
|
|
7
|
+
JSONValue,
|
|
8
|
+
LanguageModelV4,
|
|
9
|
+
LanguageModelV4CallOptions,
|
|
10
|
+
LanguageModelV4FilePart,
|
|
11
|
+
LanguageModelV4FinishReason,
|
|
12
|
+
LanguageModelV4FunctionTool,
|
|
13
|
+
LanguageModelV4Message,
|
|
14
|
+
LanguageModelV4Prompt,
|
|
15
|
+
LanguageModelV4ReasoningPart,
|
|
16
|
+
LanguageModelV4StreamPart,
|
|
17
|
+
LanguageModelV4TextPart,
|
|
18
|
+
LanguageModelV4ToolCallPart,
|
|
19
|
+
LanguageModelV4ToolChoice,
|
|
20
|
+
LanguageModelV4ToolResultOutput,
|
|
21
|
+
LanguageModelV4ToolResultPart,
|
|
22
|
+
LanguageModelV4Usage,
|
|
23
|
+
SharedV4ProviderMetadata,
|
|
24
|
+
SharedV4ProviderOptions,
|
|
25
|
+
SharedV4Warning,
|
|
26
|
+
} from '@ai-sdk/provider';
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
Serves the Anthropic Messages API over FlexHarness models, so an Anthropic client such as Claude Code can
|
|
2
|
+
run on another provider's model.
|
|
3
|
+
|
|
4
|
+
Part of the [FlexHarness toolbox](https://code.foss.global/modelprofile.com/flexharness).
|
|
5
|
+
Install the components your project uses. Provider adapters are registered explicitly;
|
|
6
|
+
the agent and harness do not install or register vendor SDKs.
|
|
7
|
+
|
|
8
|
+
```sh
|
|
9
|
+
pnpm add @modelprofile.com/flexharness-providers
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
See the [toolbox usage and migration guide](https://code.foss.global/modelprofile.com/flexharness#readme)
|
|
13
|
+
for composition examples and the SmartAI/SmartAgent migration map.
|
|
14
|
+
|
|
15
|
+
## Serving a model
|
|
16
|
+
|
|
17
|
+
`createAnthropicMessagesService()` answers WHATWG `Request`s with `Response`s, so any HTTP server can host
|
|
18
|
+
it; `/anthropic-messages/node` hosts it on a Node HTTP server. It serves `POST /v1/messages`, streamed as the
|
|
19
|
+
Anthropic event sequence or whole, and `GET /v1/models`. `POST /v1/messages/count_tokens` answers 404, on
|
|
20
|
+
which an Anthropic client estimates token counts itself, and `HEAD /api/hello`, a client's connection
|
|
21
|
+
warm-up, answers 200 without a credential.
|
|
22
|
+
|
|
23
|
+
```typescript
|
|
24
|
+
import {
|
|
25
|
+
AnthropicMessagesError,
|
|
26
|
+
createAnthropicMessagesService,
|
|
27
|
+
createOpenAiResponsesMessagesDialect,
|
|
28
|
+
} from '@modelprofile.com/flexharness-providers/anthropic-messages';
|
|
29
|
+
import {
|
|
30
|
+
createOpenAiChatGptResolvingModelConnection,
|
|
31
|
+
createOpenAiModelProvider,
|
|
32
|
+
} from '@modelprofile.com/flexharness-providers/openai';
|
|
33
|
+
|
|
34
|
+
const service = createAnthropicMessagesService({
|
|
35
|
+
authenticate: async (request) => {
|
|
36
|
+
if (request.headers.get('authorization') !== `Bearer ${sessionToken}`) {
|
|
37
|
+
throw new AnthropicMessagesError(401, 'authentication_error', 'The session token is not valid.');
|
|
38
|
+
}
|
|
39
|
+
return session;
|
|
40
|
+
},
|
|
41
|
+
resolveModel: async (modelId, session) => {
|
|
42
|
+
const entry = session.catalog.find((model) => model.modelId === modelId);
|
|
43
|
+
if (!entry) return undefined;
|
|
44
|
+
const connection = createOpenAiChatGptResolvingModelConnection({ expectedIdentity, resolveAccess });
|
|
45
|
+
return {
|
|
46
|
+
model: createOpenAiModelProvider().getModel({ provider: 'openai', model: modelId, connection }),
|
|
47
|
+
...createOpenAiResponsesMessagesDialect({ reasoning: entry.reasoningEfforts.length > 0 }),
|
|
48
|
+
reasoningEfforts: entry.reasoningEfforts.map((effort) => effort.effort),
|
|
49
|
+
signatureScope: `openai:${expectedIdentity.accountId}`,
|
|
50
|
+
sendsMaxTokens: false,
|
|
51
|
+
toolNameLimit: 64,
|
|
52
|
+
};
|
|
53
|
+
},
|
|
54
|
+
listModels: async (session) => session.catalog.map((model) => ({ id: model.modelId, displayName: model.displayName })),
|
|
55
|
+
signatureKey, // 32 or more random bytes from the host's secret store
|
|
56
|
+
usage: {
|
|
57
|
+
record: async (event) => ledger.add(event),
|
|
58
|
+
failed: (error, event) => log.error('usage bookkeeping failed', { error, modelId: event.modelId }),
|
|
59
|
+
},
|
|
60
|
+
});
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
`usage.record` runs after an answer is complete and outside its path, so bookkeeping never changes an
|
|
64
|
+
answer. A `record` that throws or rejects is handed to `usage.failed` with its event; the host handles it
|
|
65
|
+
there, and a `failed` that throws itself is an unhandled rejection of the host.
|
|
66
|
+
|
|
67
|
+
## What is translated
|
|
68
|
+
|
|
69
|
+
System prompts, text, images, PDF and text documents, tool definitions, tool calls, tool results with text
|
|
70
|
+
and images, tool choice (including `disable_parallel_tool_use`), mid-conversation system messages,
|
|
71
|
+
thinking, `output_config.effort` and a JSON schema output format.
|
|
72
|
+
|
|
73
|
+
Thinking comes back with a signature that carries the reasoning metadata of the model's own reasoning part
|
|
74
|
+
(for OpenAI, the reasoning item and its encrypted content). A client returns thinking blocks unchanged, so
|
|
75
|
+
the reasoning reaches the model again on the next turn. The client holds the signature, so it is
|
|
76
|
+
authenticated with an HMAC-SHA256 under `signatureKey`, which the host provides: at least 32 random bytes,
|
|
77
|
+
kept secret and used for nothing else. A shorter key is refused when the service is created. A signature the
|
|
78
|
+
key did not write or that was changed, one written under another `signatureScope`, such as another account,
|
|
79
|
+
and a redacted thinking block are not sent back; the response counts them in
|
|
80
|
+
`x-flexharness-thinking-dropped`. A host that keeps its key across restarts keeps the reasoning of the
|
|
81
|
+
conversations it answered; a new key drops the thinking signed under the old one.
|
|
82
|
+
|
|
83
|
+
Response headers name what a request received differently from what it asked for:
|
|
84
|
+
|
|
85
|
+
| Header | Meaning |
|
|
86
|
+
| --- | --- |
|
|
87
|
+
| `x-flexharness-effort-fitted` | The requested effort the model lacks and the one sent instead, as `max=>xhigh` |
|
|
88
|
+
| `x-flexharness-max-tokens` | `not-sent` when the model takes no output limit (`sendsMaxTokens: false`) |
|
|
89
|
+
| `x-flexharness-thinking-dropped` | The number of thinking blocks not sent back to the model |
|
|
90
|
+
| `x-flexharness-model-warnings` | The model's own warnings, such as an unsupported sampling setting |
|
|
91
|
+
|
|
92
|
+
## What is refused
|
|
93
|
+
|
|
94
|
+
A field that cannot be translated faithfully is refused with a 400 that names it: server-side context
|
|
95
|
+
management, code execution containers, remote MCP servers, deferred tool loading and server tools. The
|
|
96
|
+
server tool refusal names the tool type after `Input tag`, the wording on which an Anthropic client continues
|
|
97
|
+
without that tool. Prompt cache markers, citations, metadata and the service tier are hints to Anthropic's own
|
|
98
|
+
service and are accepted without effect; the provider caches prompts by the session id instead.
|
|
99
|
+
|
|
100
|
+
Failures answer in the Anthropic error shape. A usage or rate limit (`ModelLimitError`) is a 429 with
|
|
101
|
+
`retry-after` in seconds until the reset. An input beyond the model's context window is the
|
|
102
|
+
`prompt is too long` refusal an Anthropic client compacts its conversation on. A provider that refuses the
|
|
103
|
+
account's credentials is a 403. A failure after a stream began is an `error` event, and a stream that stays
|
|
104
|
+
silent sends `ping` events.
|
|
105
|
+
|
|
106
|
+
## Issue Reporting and Security
|
|
107
|
+
|
|
108
|
+
Report issues and security concerns through [community.foss.global](https://community.foss.global).
|
|
109
|
+
|
|
110
|
+
## License and Legal Information
|
|
111
|
+
|
|
112
|
+
This repository contains open-source code licensed under the MIT License. A copy of the license can be found in the repository license file.
|
|
113
|
+
|
|
114
|
+
**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.
|
|
115
|
+
|
|
116
|
+
### Trademarks
|
|
117
|
+
|
|
118
|
+
This project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH or third parties, and are not included within the scope of the MIT license granted herein.
|
|
119
|
+
|
|
120
|
+
Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines or the guidelines of the respective third-party owners, and any usage must be approved in writing. Third-party trademarks used herein are the property of their respective owners and used only in a descriptive manner, e.g. for an implementation of an API or similar.
|
|
121
|
+
|
|
122
|
+
### Company Information
|
|
123
|
+
|
|
124
|
+
Task Venture Capital GmbH<br>
|
|
125
|
+
Registered at District Court Bremen HRB 35230 HB, Germany
|
|
126
|
+
|
|
127
|
+
For any legal inquiries or further information, please contact us via email at hello@task.vc.
|
|
128
|
+
|
|
129
|
+
By using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.
|