@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,22 @@
|
|
|
1
|
+
import type { IAnthropicMessagesFailure, IAnthropicMessagesModel, TAnthropicMessagesErrorType } from './interfaces.js';
|
|
2
|
+
/**
|
|
3
|
+
* A request this service refuses, in the Anthropic error shape. Callbacks throw it to answer with their
|
|
4
|
+
* own status and message, for example an `authenticate` that refuses a credential with 401.
|
|
5
|
+
*/
|
|
6
|
+
export declare class AnthropicMessagesError extends Error {
|
|
7
|
+
readonly failure: Readonly<IAnthropicMessagesFailure>;
|
|
8
|
+
constructor(statusArg: number, typeArg: TAnthropicMessagesErrorType, messageArg: string, detailsArg?: {
|
|
9
|
+
retryAfterSeconds?: number;
|
|
10
|
+
shouldRetry?: boolean;
|
|
11
|
+
}, optionsArg?: ErrorOptions);
|
|
12
|
+
}
|
|
13
|
+
export declare const invalidRequest: (messageArg: string) => AnthropicMessagesError;
|
|
14
|
+
/** The one wording an Anthropic client compacts its conversation on. */
|
|
15
|
+
export declare const promptTooLong: (detailArg: string) => IAnthropicMessagesFailure;
|
|
16
|
+
/**
|
|
17
|
+
* States a failure of a request in the Anthropic shape: a refusal a callback threw, the model's own dialect,
|
|
18
|
+
* a usage or rate limit, a provider HTTP failure, and anything else as an `api_error` naming the error.
|
|
19
|
+
*/
|
|
20
|
+
export declare const describeFailure: (errorArg: unknown, modelArg?: IAnthropicMessagesModel) => IAnthropicMessagesFailure;
|
|
21
|
+
export declare const failureBody: (failureArg: IAnthropicMessagesFailure, requestIdArg: string) => string;
|
|
22
|
+
export declare const failureHeaders: (failureArg: IAnthropicMessagesFailure) => Record<string, string>;
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import * as plugins from './plugins.js';
|
|
2
|
+
/**
|
|
3
|
+
* A request this service refuses, in the Anthropic error shape. Callbacks throw it to answer with their
|
|
4
|
+
* own status and message, for example an `authenticate` that refuses a credential with 401.
|
|
5
|
+
*/
|
|
6
|
+
export class AnthropicMessagesError extends Error {
|
|
7
|
+
failure;
|
|
8
|
+
constructor(statusArg, typeArg, messageArg, detailsArg = {}, optionsArg) {
|
|
9
|
+
super(messageArg, optionsArg);
|
|
10
|
+
this.name = 'AnthropicMessagesError';
|
|
11
|
+
this.failure = Object.freeze({ status: statusArg, type: typeArg, message: messageArg, ...detailsArg });
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
export const invalidRequest = (messageArg) => new AnthropicMessagesError(400, 'invalid_request_error', messageArg);
|
|
15
|
+
/** The one wording an Anthropic client compacts its conversation on. */
|
|
16
|
+
export const promptTooLong = (detailArg) => ({
|
|
17
|
+
status: 400,
|
|
18
|
+
type: 'invalid_request_error',
|
|
19
|
+
message: `prompt is too long: ${detailArg}`,
|
|
20
|
+
});
|
|
21
|
+
const maximumMessageLength = 1024;
|
|
22
|
+
const bounded = (textArg) => textArg.length > maximumMessageLength
|
|
23
|
+
? `${textArg.slice(0, maximumMessageLength)}...`
|
|
24
|
+
: textArg;
|
|
25
|
+
const isAbort = (errorArg) => errorArg instanceof Error && (errorArg.name === 'AbortError' || errorArg.name === 'TimeoutError');
|
|
26
|
+
const fromLimit = (errorArg) => {
|
|
27
|
+
if (!plugins.isModelLimitError(errorArg))
|
|
28
|
+
return undefined;
|
|
29
|
+
const limit = errorArg.limit;
|
|
30
|
+
const waitMs = limit.retryAfterMs ?? (limit.resetsAt === undefined ? undefined : limit.resetsAt - Date.now());
|
|
31
|
+
return {
|
|
32
|
+
status: 429,
|
|
33
|
+
type: 'rate_limit_error',
|
|
34
|
+
message: errorArg.message,
|
|
35
|
+
...(waitMs === undefined ? {} : { retryAfterSeconds: Math.max(1, Math.ceil(waitMs / 1000)) }),
|
|
36
|
+
shouldRetry: limit.kind === 'rate_limit',
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
const fromApiCall = (errorArg) => {
|
|
40
|
+
if (!plugins.APICallError.isInstance(errorArg))
|
|
41
|
+
return undefined;
|
|
42
|
+
const status = errorArg.statusCode;
|
|
43
|
+
const detail = bounded(errorArg.message);
|
|
44
|
+
if (status === 400 || status === 422) {
|
|
45
|
+
return { status: 400, type: 'invalid_request_error', message: `The model provider refused the request: ${detail}` };
|
|
46
|
+
}
|
|
47
|
+
if (status === 401 || status === 403) {
|
|
48
|
+
return {
|
|
49
|
+
status: 403,
|
|
50
|
+
type: 'permission_error',
|
|
51
|
+
message: `The model provider refused this account's credentials: ${detail}`,
|
|
52
|
+
shouldRetry: false,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
if (status === 404) {
|
|
56
|
+
return { status: 404, type: 'not_found_error', message: `The model provider does not know this model: ${detail}` };
|
|
57
|
+
}
|
|
58
|
+
if (status === 413) {
|
|
59
|
+
return { status: 413, type: 'request_too_large', message: `The model provider refused the request size: ${detail}` };
|
|
60
|
+
}
|
|
61
|
+
if (status === 429) {
|
|
62
|
+
return { status: 429, type: 'rate_limit_error', message: `The model provider is rate limiting: ${detail}`, shouldRetry: true };
|
|
63
|
+
}
|
|
64
|
+
return {
|
|
65
|
+
status: 500,
|
|
66
|
+
type: 'api_error',
|
|
67
|
+
message: `The model provider failed${status === undefined ? '' : ` with HTTP ${status}`}: ${detail}`,
|
|
68
|
+
shouldRetry: errorArg.isRetryable,
|
|
69
|
+
};
|
|
70
|
+
};
|
|
71
|
+
/**
|
|
72
|
+
* States a failure of a request in the Anthropic shape: a refusal a callback threw, the model's own dialect,
|
|
73
|
+
* a usage or rate limit, a provider HTTP failure, and anything else as an `api_error` naming the error.
|
|
74
|
+
*/
|
|
75
|
+
export const describeFailure = (errorArg, modelArg) => {
|
|
76
|
+
if (errorArg instanceof AnthropicMessagesError)
|
|
77
|
+
return errorArg.failure;
|
|
78
|
+
return modelArg?.classifyFailure?.(errorArg)
|
|
79
|
+
?? fromLimit(errorArg)
|
|
80
|
+
?? fromApiCall(errorArg)
|
|
81
|
+
?? (isAbort(errorArg)
|
|
82
|
+
? { status: 499, type: 'api_error', message: 'The request was aborted.' }
|
|
83
|
+
: {
|
|
84
|
+
status: 500,
|
|
85
|
+
type: 'api_error',
|
|
86
|
+
message: `The model call failed: ${bounded(errorArg instanceof Error
|
|
87
|
+
? `${errorArg.name}: ${errorArg.message}`
|
|
88
|
+
: String(errorArg))}`,
|
|
89
|
+
});
|
|
90
|
+
};
|
|
91
|
+
export const failureBody = (failureArg, requestIdArg) => JSON.stringify({
|
|
92
|
+
type: 'error',
|
|
93
|
+
error: { type: failureArg.type, message: failureArg.message },
|
|
94
|
+
request_id: requestIdArg,
|
|
95
|
+
});
|
|
96
|
+
export const failureHeaders = (failureArg) => ({
|
|
97
|
+
...(failureArg.retryAfterSeconds === undefined ? {} : { 'retry-after': String(failureArg.retryAfterSeconds) }),
|
|
98
|
+
...(failureArg.shouldRetry === undefined ? {} : { 'x-should-retry': String(failureArg.shouldRetry) }),
|
|
99
|
+
});
|
|
100
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZXJyb3JzLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHNfYW50aHJvcGljX21lc3NhZ2VzL2Vycm9ycy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEtBQUssT0FBTyxNQUFNLGNBQWMsQ0FBQztBQU94Qzs7O0dBR0c7QUFDSCxNQUFNLE9BQU8sc0JBQXVCLFNBQVEsS0FBSztJQUMvQixPQUFPLENBQXNDO0lBRTdELFlBQ0UsU0FBaUIsRUFDakIsT0FBb0MsRUFDcEMsVUFBa0IsRUFDbEIsYUFBb0UsRUFBRSxFQUN0RSxVQUF5QjtRQUV6QixLQUFLLENBQUMsVUFBVSxFQUFFLFVBQVUsQ0FBQyxDQUFDO1FBQzlCLElBQUksQ0FBQyxJQUFJLEdBQUcsd0JBQXdC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QyxPQUFPLEVBQUU7b0JBQ3pDLENBQUMsQ0FBQyxNQUFNLENBQUMsUUFBUSxDQUFDLENBQUMsRUFBRTthQUN4QixDQUFDLENBQUM7QUFDVCxDQUFDLENBQUM7QUFFRixNQUFNLENBQUMsTUFBTSxXQUFXLEdBQUcsQ0FBQyxVQUFxQyxFQUFFLFlBQW9CLEVBQVUsRUFBRSxDQUFDLElBQUksQ0FBQyxTQUFTLENBQUM7SUFDakgsSUFBSSxFQUFFLE9BQU87SUFDYixLQUFLLEVBQUUsRUFBRSxJQUFJLEVBQUUsVUFBVSxDQUFDLElBQUksRUFBRSxPQUFPLEVBQUUsVUFBVSxDQUFDLE9BQU8sRUFBRTtJQUM3RCxVQUFVLEVBQUUsWUFBWTtDQUN6QixDQUFDLENBQUM7QUFFSCxNQUFNLENBQUMsTUFBTSxjQUFjLEdBQUcsQ0FBQyxVQUFxQyxFQUEwQixFQUFFLENBQUMsQ0FBQztJQUNoRyxHQUFHLENBQUMsVUFBVSxDQUFDLGlCQUFpQixLQUFLLFNBQVMsQ0FBQyxDQUFDLENBQUMsRUFBRSxDQUFDLENBQUMsQ0FBQyxFQUFFLGFBQWEsRUFBRSxNQUFNLENBQUMsVUFBVSxDQUFDLGlCQUFpQixDQUFDLEVBQUUsQ0FBQztJQUM5RyxHQUFHLENBQUMsVUFBVSxDQUFDLFdBQVcsS0FBSyxTQUFTLENBQUMsQ0FBQyxDQUFDLEVBQUUsQ0FBQyxDQUFDLENBQUMsRUFBRSxnQkFBZ0IsRUFBRSxNQUFNLENBQUMsVUFBVSxDQUFDLFdBQVcsQ0FBQyxFQUFFLENBQUM7Q0FDdEcsQ0FBQyxDQUFDIn0=
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { AnthropicMessagesError } from './errors.js';
|
|
2
|
+
export { classifyOpenAiResponsesMessagesFailure, createOpenAiResponsesMessagesDialect, type IOpenAiResponsesMessagesDialectOptions, } from './openai.js';
|
|
3
|
+
export { createAnthropicMessagesService } from './service.js';
|
|
4
|
+
export type { TAnthropicMessagesContentBlock, IAnthropicMessagesControls, IAnthropicMessagesFailure, IAnthropicMessagesMessage, IAnthropicMessagesModel, IAnthropicMessagesModelListing, IAnthropicMessagesService, IAnthropicMessagesServiceOptions, IAnthropicMessagesUsage, IAnthropicMessagesUsageEvent, IAnthropicMessagesUsageReporter, TAnthropicMessagesEffort, TAnthropicMessagesErrorType, TAnthropicMessagesStopReason, TAnthropicMessagesStreamEvent, } from './interfaces.js';
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { AnthropicMessagesError } from './errors.js';
|
|
2
|
+
export { classifyOpenAiResponsesMessagesFailure, createOpenAiResponsesMessagesDialect, } from './openai.js';
|
|
3
|
+
export { createAnthropicMessagesService } from './service.js';
|
|
4
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90c19hbnRocm9waWNfbWVzc2FnZXMvaW5kZXgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxFQUFFLHNCQUFzQixFQUFFLE1BQU0sYUFBYSxDQUFDO0FBQ3JELE9BQU8sRUFDTCxzQ0FBc0MsRUFDdEMsb0NBQW9DLEdBRXJDLE1BQU0sYUFBYSxDQUFDO0FBQ3JCLE9BQU8sRUFBRSw4QkFBOEIsRUFBRSxNQUFNLGNBQWMsQ0FBQyJ9
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import type * as plugins from './plugins.js';
|
|
2
|
+
/** The Anthropic error types this service answers with. */
|
|
3
|
+
export type TAnthropicMessagesErrorType = 'invalid_request_error' | 'authentication_error' | 'permission_error' | 'not_found_error' | 'request_too_large' | 'rate_limit_error' | 'api_error' | 'overloaded_error';
|
|
4
|
+
/** A failure as the Anthropic Messages API states it: an HTTP status, an error type and a message. */
|
|
5
|
+
export interface IAnthropicMessagesFailure {
|
|
6
|
+
status: number;
|
|
7
|
+
type: TAnthropicMessagesErrorType;
|
|
8
|
+
message: string;
|
|
9
|
+
/** Seconds a client waits before the next attempt, sent as `retry-after`. */
|
|
10
|
+
retryAfterSeconds?: number;
|
|
11
|
+
/** Sent as `x-should-retry`. */
|
|
12
|
+
shouldRetry?: boolean;
|
|
13
|
+
}
|
|
14
|
+
/** The effort levels an Anthropic client asks for in `output_config.effort`. */
|
|
15
|
+
export type TAnthropicMessagesEffort = 'low' | 'medium' | 'high' | 'xhigh' | 'max';
|
|
16
|
+
/**
|
|
17
|
+
* What one request asks of the model beyond its prompt and tools, in provider-independent terms.
|
|
18
|
+
* A model's `providerOptions` turns these into its provider's own options.
|
|
19
|
+
*/
|
|
20
|
+
export interface IAnthropicMessagesControls {
|
|
21
|
+
/** The reasoning effort to send, already fitted to the model's `reasoningEfforts`; absent for the model's default. */
|
|
22
|
+
reasoningEffort?: string;
|
|
23
|
+
/** Whether the client asked for thinking blocks; without it no reasoning text is requested or returned. */
|
|
24
|
+
thinking: boolean;
|
|
25
|
+
/** False when the client set `disable_parallel_tool_use`. */
|
|
26
|
+
parallelToolCalls: boolean;
|
|
27
|
+
/** The client's session id (`x-claude-code-session-id`), for a provider prompt cache key. */
|
|
28
|
+
sessionId?: string;
|
|
29
|
+
}
|
|
30
|
+
/** One model this service serves, as the consumer resolves it for a request. */
|
|
31
|
+
export interface IAnthropicMessagesModel {
|
|
32
|
+
/** The language model that answers the request. */
|
|
33
|
+
model: plugins.LanguageModelV4;
|
|
34
|
+
/** The model's provider options for one request. */
|
|
35
|
+
providerOptions: (controls: IAnthropicMessagesControls) => plugins.SharedV4ProviderOptions;
|
|
36
|
+
/**
|
|
37
|
+
* The reasoning efforts the model accepts, lowest first. A requested effort the model lacks is fitted to
|
|
38
|
+
* the nearest lower one it has, and the response names the substitution in `x-flexharness-effort-fitted`.
|
|
39
|
+
* Unset, the requested effort is sent as it is.
|
|
40
|
+
*/
|
|
41
|
+
reasoningEfforts?: readonly string[];
|
|
42
|
+
/**
|
|
43
|
+
* Names the account and provider a thinking signature belongs to. A signature from another scope, for
|
|
44
|
+
* example one written while the conversation ran on another account, is not sent back to the model.
|
|
45
|
+
*/
|
|
46
|
+
signatureScope: string;
|
|
47
|
+
/**
|
|
48
|
+
* Whether `max_tokens` is sent as the model's output limit. A backend that takes no output limit, such as
|
|
49
|
+
* ChatGPT's Codex backend, is served without one, and the response says so in `x-flexharness-max-tokens`.
|
|
50
|
+
*/
|
|
51
|
+
sendsMaxTokens: boolean;
|
|
52
|
+
/** The longest tool name the model accepts; longer names are sent under a stable alias and mapped back. */
|
|
53
|
+
toolNameLimit?: number;
|
|
54
|
+
/** Reads the model provider's own failures first; the generic rules handle the rest. */
|
|
55
|
+
classifyFailure?: (error: unknown) => IAnthropicMessagesFailure | undefined;
|
|
56
|
+
}
|
|
57
|
+
/** A model as `GET /v1/models` lists it. */
|
|
58
|
+
export interface IAnthropicMessagesModelListing {
|
|
59
|
+
id: string;
|
|
60
|
+
displayName?: string;
|
|
61
|
+
description?: string;
|
|
62
|
+
}
|
|
63
|
+
/** Token usage of one answered request, as the model reported it. */
|
|
64
|
+
export interface IAnthropicMessagesUsageEvent<TContext> {
|
|
65
|
+
context: TContext;
|
|
66
|
+
modelId: string;
|
|
67
|
+
usage: plugins.LanguageModelV4Usage;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Where the usage of answered requests goes. `record` runs after the answer is complete, so bookkeeping can
|
|
71
|
+
* never change an answer; a `record` that throws or rejects is handed to `failed` with its event, which the
|
|
72
|
+
* host must handle. A `failed` that throws itself is an unhandled rejection of the host.
|
|
73
|
+
*/
|
|
74
|
+
export interface IAnthropicMessagesUsageReporter<TContext> {
|
|
75
|
+
record: (event: IAnthropicMessagesUsageEvent<TContext>) => void | Promise<void>;
|
|
76
|
+
failed: (error: unknown, event: IAnthropicMessagesUsageEvent<TContext>) => void;
|
|
77
|
+
}
|
|
78
|
+
export interface IAnthropicMessagesServiceOptions<TContext> {
|
|
79
|
+
/**
|
|
80
|
+
* Authenticates a request and returns what the other callbacks need to serve it. Throw an
|
|
81
|
+
* `AnthropicMessagesError` to refuse it, for example with status 401 for a wrong credential.
|
|
82
|
+
*/
|
|
83
|
+
authenticate: (request: Request) => Promise<TContext>;
|
|
84
|
+
/**
|
|
85
|
+
* The model a request names, or `undefined` when this service does not serve that id. `signal` aborts when
|
|
86
|
+
* the client leaves, so a slow resolution (such as renewing access) can stop early.
|
|
87
|
+
*/
|
|
88
|
+
resolveModel: (modelId: string, context: TContext, signal: AbortSignal) => Promise<IAnthropicMessagesModel | undefined>;
|
|
89
|
+
/** The models `GET /v1/models` lists and an unknown model id's refusal names. */
|
|
90
|
+
listModels: (context: TContext) => Promise<readonly IAnthropicMessagesModelListing[]>;
|
|
91
|
+
/**
|
|
92
|
+
* The HMAC-SHA256 key thinking signatures are written and verified with: at least 32 random bytes, kept
|
|
93
|
+
* secret by the host and used for nothing else. A signature this key did not write is not sent back to the
|
|
94
|
+
* model, so a host that keeps the key across restarts keeps the reasoning of conversations it answered.
|
|
95
|
+
*/
|
|
96
|
+
signatureKey: Uint8Array;
|
|
97
|
+
/** Receives the usage of every request the model finished, once its answer has been delivered. */
|
|
98
|
+
usage?: IAnthropicMessagesUsageReporter<TContext>;
|
|
99
|
+
/** Interval of `ping` events while a stream is otherwise silent. Defaults to 15 seconds. */
|
|
100
|
+
pingIntervalMs?: number;
|
|
101
|
+
/** Largest accepted request body. Defaults to 32 MiB, the Messages API limit. */
|
|
102
|
+
maxRequestBytes?: number;
|
|
103
|
+
}
|
|
104
|
+
export interface IAnthropicMessagesService {
|
|
105
|
+
/** Answers one HTTP request of the Anthropic Messages API. */
|
|
106
|
+
handle: (request: Request) => Promise<Response>;
|
|
107
|
+
}
|
|
108
|
+
/** Usage in the Anthropic shape: input tokens exclude the ones read from cache. */
|
|
109
|
+
export interface IAnthropicMessagesUsage {
|
|
110
|
+
input_tokens: number;
|
|
111
|
+
output_tokens: number;
|
|
112
|
+
cache_creation_input_tokens: number;
|
|
113
|
+
cache_read_input_tokens: number;
|
|
114
|
+
}
|
|
115
|
+
export type TAnthropicMessagesStopReason = 'end_turn' | 'max_tokens' | 'stop_sequence' | 'tool_use' | 'refusal';
|
|
116
|
+
export type TAnthropicMessagesContentBlock = {
|
|
117
|
+
type: 'text';
|
|
118
|
+
text: string;
|
|
119
|
+
} | {
|
|
120
|
+
type: 'thinking';
|
|
121
|
+
thinking: string;
|
|
122
|
+
signature: string;
|
|
123
|
+
} | {
|
|
124
|
+
type: 'tool_use';
|
|
125
|
+
id: string;
|
|
126
|
+
name: string;
|
|
127
|
+
input: unknown;
|
|
128
|
+
};
|
|
129
|
+
/** A complete answer, as a non-streaming request receives it. */
|
|
130
|
+
export interface IAnthropicMessagesMessage {
|
|
131
|
+
id: string;
|
|
132
|
+
type: 'message';
|
|
133
|
+
role: 'assistant';
|
|
134
|
+
model: string;
|
|
135
|
+
content: TAnthropicMessagesContentBlock[];
|
|
136
|
+
stop_reason: TAnthropicMessagesStopReason | null;
|
|
137
|
+
stop_sequence: string | null;
|
|
138
|
+
usage: IAnthropicMessagesUsage;
|
|
139
|
+
}
|
|
140
|
+
export type TAnthropicMessagesContentDelta = {
|
|
141
|
+
type: 'text_delta';
|
|
142
|
+
text: string;
|
|
143
|
+
} | {
|
|
144
|
+
type: 'thinking_delta';
|
|
145
|
+
thinking: string;
|
|
146
|
+
} | {
|
|
147
|
+
type: 'signature_delta';
|
|
148
|
+
signature: string;
|
|
149
|
+
} | {
|
|
150
|
+
type: 'input_json_delta';
|
|
151
|
+
partial_json: string;
|
|
152
|
+
};
|
|
153
|
+
/** One server-sent event of a streamed answer. */
|
|
154
|
+
export type TAnthropicMessagesStreamEvent = {
|
|
155
|
+
type: 'message_start';
|
|
156
|
+
message: IAnthropicMessagesMessage;
|
|
157
|
+
} | {
|
|
158
|
+
type: 'content_block_start';
|
|
159
|
+
index: number;
|
|
160
|
+
content_block: TAnthropicMessagesContentBlock;
|
|
161
|
+
} | {
|
|
162
|
+
type: 'content_block_delta';
|
|
163
|
+
index: number;
|
|
164
|
+
delta: TAnthropicMessagesContentDelta;
|
|
165
|
+
} | {
|
|
166
|
+
type: 'content_block_stop';
|
|
167
|
+
index: number;
|
|
168
|
+
} | {
|
|
169
|
+
type: 'message_delta';
|
|
170
|
+
delta: {
|
|
171
|
+
stop_reason: TAnthropicMessagesStopReason;
|
|
172
|
+
stop_sequence: string | null;
|
|
173
|
+
};
|
|
174
|
+
usage: IAnthropicMessagesUsage;
|
|
175
|
+
} | {
|
|
176
|
+
type: 'message_stop';
|
|
177
|
+
} | {
|
|
178
|
+
type: 'ping';
|
|
179
|
+
} | {
|
|
180
|
+
type: 'error';
|
|
181
|
+
error: {
|
|
182
|
+
type: TAnthropicMessagesErrorType;
|
|
183
|
+
message: string;
|
|
184
|
+
};
|
|
185
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { IAnthropicMessagesFailure, IAnthropicMessagesModel } from './interfaces.js';
|
|
2
|
+
export interface IOpenAiResponsesMessagesDialectOptions {
|
|
3
|
+
/**
|
|
4
|
+
* Whether the model reasons. A reasoning model is asked for its encrypted reasoning, which a thinking
|
|
5
|
+
* signature carries back to it, so a conversation keeps its reasoning across turns and tool calls.
|
|
6
|
+
*/
|
|
7
|
+
reasoning: boolean;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Reads the OpenAI Responses failures the generic rules cannot: an input beyond the model's context window
|
|
11
|
+
* answers with the wording an Anthropic client compacts its conversation on.
|
|
12
|
+
*/
|
|
13
|
+
export declare const classifyOpenAiResponsesMessagesFailure: (errorArg: unknown) => IAnthropicMessagesFailure | undefined;
|
|
14
|
+
/**
|
|
15
|
+
* The OpenAI Responses dialect of a served model: nothing is stored at the provider, reasoning returns
|
|
16
|
+
* encrypted so a thinking signature can carry it, reasoning summaries are requested only when the client
|
|
17
|
+
* asked for thinking, and the client's session id keys the provider's prompt cache.
|
|
18
|
+
*/
|
|
19
|
+
export declare const createOpenAiResponsesMessagesDialect: (optionsArg: IOpenAiResponsesMessagesDialectOptions) => Pick<IAnthropicMessagesModel, "providerOptions" | "classifyFailure">;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import * as plugins from './plugins.js';
|
|
2
|
+
import { promptTooLong } from './errors.js';
|
|
3
|
+
const isRecord = (valueArg) => typeof valueArg === 'object' && valueArg !== null && !Array.isArray(valueArg);
|
|
4
|
+
/** The OpenAI error of a failure: an HTTP error body, a failed response, or an error frame of a stream. */
|
|
5
|
+
const readOpenAiError = (valueArg) => {
|
|
6
|
+
if (!isRecord(valueArg))
|
|
7
|
+
return undefined;
|
|
8
|
+
if (isRecord(valueArg.error))
|
|
9
|
+
return valueArg.error;
|
|
10
|
+
if (isRecord(valueArg.response) && isRecord(valueArg.response.error))
|
|
11
|
+
return valueArg.response.error;
|
|
12
|
+
if ('code' in valueArg)
|
|
13
|
+
return valueArg;
|
|
14
|
+
return undefined;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Reads the OpenAI Responses failures the generic rules cannot: an input beyond the model's context window
|
|
18
|
+
* answers with the wording an Anthropic client compacts its conversation on.
|
|
19
|
+
*/
|
|
20
|
+
export const classifyOpenAiResponsesMessagesFailure = (errorArg) => {
|
|
21
|
+
const error = plugins.APICallError.isInstance(errorArg) ? readOpenAiError(errorArg.data) : readOpenAiError(errorArg);
|
|
22
|
+
if (error?.code !== 'context_length_exceeded')
|
|
23
|
+
return undefined;
|
|
24
|
+
return promptTooLong(typeof error.message === 'string' ? error.message : 'the input exceeds the model\'s context window.');
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* The OpenAI Responses dialect of a served model: nothing is stored at the provider, reasoning returns
|
|
28
|
+
* encrypted so a thinking signature can carry it, reasoning summaries are requested only when the client
|
|
29
|
+
* asked for thinking, and the client's session id keys the provider's prompt cache.
|
|
30
|
+
*/
|
|
31
|
+
export const createOpenAiResponsesMessagesDialect = (optionsArg) => ({
|
|
32
|
+
providerOptions: (controlsArg) => ({
|
|
33
|
+
openai: {
|
|
34
|
+
store: false,
|
|
35
|
+
...(optionsArg.reasoning
|
|
36
|
+
? {
|
|
37
|
+
forceReasoning: true,
|
|
38
|
+
reasoningSummary: controlsArg.thinking ? 'auto' : null,
|
|
39
|
+
...(controlsArg.reasoningEffort === undefined ? {} : { reasoningEffort: controlsArg.reasoningEffort }),
|
|
40
|
+
}
|
|
41
|
+
: {}),
|
|
42
|
+
...(controlsArg.parallelToolCalls ? {} : { parallelToolCalls: false }),
|
|
43
|
+
...(controlsArg.sessionId === undefined ? {} : { promptCacheKey: controlsArg.sessionId }),
|
|
44
|
+
},
|
|
45
|
+
}),
|
|
46
|
+
classifyFailure: classifyOpenAiResponsesMessagesFailure,
|
|
47
|
+
});
|
|
48
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoib3BlbmFpLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHNfYW50aHJvcGljX21lc3NhZ2VzL29wZW5haS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEtBQUssT0FBTyxNQUFNLGNBQWMsQ0FBQztBQUN4QyxPQUFPLEVBQUUsYUFBYSxFQUFFLE1BQU0sYUFBYSxDQUFDO0FBVzVDLE1BQU0sUUFBUSxHQUFHLENBQUMsUUFBaUIsRUFBdUMsRUFBRSxDQUMxRSxPQUFPLFFBQVEsS0FBSyxRQUFRLElBQUksUUFBUSxLQUFLLElBQUksSUFBSSxDQUFDLEtBQUssQ0FBQyxPQUFPLENBQUMsUUFBUSxDQUFDLENBQUM7QUFFaEYsMkdBQTJHO0FBQzNHLE1BQU0sZUFBZSxHQUFHLENBQUMsUUFBaUIsRUFBcUQsRUFBRTtJQUMvRixJQUFJLENBQUMsUUFBUSxDQUFDLFFBQVEsQ0FBQztRQUFFLE9BQU8sU0FBUyxDQUFDO0lBQzFDLElBQUksUUFBU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sQ0FBQyxDQUFDO1FBQzdELE1BQU0sRUFBRTtZQUNOLEtBQUssRUFBRSxLQUFLO1lBQ1osR0FBRyxDQUFDLFVBQVUsQ0FBQyxTQUFTO2dCQUN0QixDQUFDLENBQUM7b0JBQ0EsY0FBYyxFQUFFLElBQUk7b0JBQ3BCLGdCQUFnQixFQUFFLFdBQVcsQ0FBQyxRQUFRLENBQUMsQ0FBQyxDQUFDLE1BQU0sQ0FBQyxDQUFDLENBQUMsSUFBSTtvQkFDdEQsR0FBRyxDQUFDLFdBQVcsQ0FBQyxlQUFlLEtBQUssU0FBUyxDQUFDLENBQUMsQ0FBQyxFQUFFLENBQUMsQ0FBQyxDQUFDLEVBQUUsZUFBZSxFQUFFLFdBQVcsQ0FBQyxlQUFlLEVBQUUsQ0FBQztpQkFDdkc7Z0JBQ0QsQ0FBQyxDQUFDLEVBQUUsQ0FBQztZQUNQLEdBQUcsQ0FBQyxXQUFXLENBQUMsaUJBQWlCLENBQUMsQ0FBQyxDQUFDLEVBQUUsQ0FBQyxDQUFDLENBQUMsRUFBRSxpQkFBaUIsRUFBRSxLQUFLLEVBQUUsQ0FBQztZQUN0RSxHQUFHLENBQUMsV0FBVyxDQUFDLFNBQVMsS0FBSyxTQUFTLENBQUMsQ0FBQyxDQUFDLEVBQUUsQ0FBQyxDQUFDLENBQUMsRUFBRSxjQUFjLEVBQUUsV0FBVyxDQUFDLFNBQVMsRUFBRSxDQUFDO1NBQzFGO0tBQ0YsQ0FBQztJQUNGLGVBQWUsRUFBRSxzQ0FBc0M7Q0FDeEQsQ0FBQyxDQUFDIn0=
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { APICallError } from '@ai-sdk/provider';
|
|
2
|
+
import { isModelLimitError } from '@modelprofile.com/flexharness-models';
|
|
3
|
+
export { APICallError, isModelLimitError };
|
|
4
|
+
export type { JSONObject, JSONValue, LanguageModelV4, LanguageModelV4CallOptions, LanguageModelV4FilePart, LanguageModelV4FinishReason, LanguageModelV4FunctionTool, LanguageModelV4Message, LanguageModelV4Prompt, LanguageModelV4ReasoningPart, LanguageModelV4StreamPart, LanguageModelV4TextPart, LanguageModelV4ToolCallPart, LanguageModelV4ToolChoice, LanguageModelV4ToolResultOutput, LanguageModelV4ToolResultPart, LanguageModelV4Usage, SharedV4ProviderMetadata, SharedV4ProviderOptions, SharedV4Warning, } from '@ai-sdk/provider';
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { APICallError } from '@ai-sdk/provider';
|
|
2
|
+
import { isModelLimitError } from '@modelprofile.com/flexharness-models';
|
|
3
|
+
export { APICallError, isModelLimitError };
|
|
4
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicGx1Z2lucy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzX2FudGhyb3BpY19tZXNzYWdlcy9wbHVnaW5zLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sRUFBRSxZQUFZLEVBQUUsTUFBTSxrQkFBa0IsQ0FBQztBQUNoRCxPQUFPLEVBQUUsaUJBQWlCLEVBQUUsTUFBTSxzQ0FBc0MsQ0FBQztBQUV6RSxPQUFPLEVBQUUsWUFBWSxFQUFFLGlCQUFpQixFQUFFLENBQUMifQ==
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import type * as plugins from './plugins.js';
|
|
2
|
+
import type { IAnthropicMessagesModel, TAnthropicMessagesEffort } from './interfaces.js';
|
|
3
|
+
import type { ThinkingSignatures } from './signature.js';
|
|
4
|
+
type TParsedFile = {
|
|
5
|
+
kind: 'file';
|
|
6
|
+
mediaType: string;
|
|
7
|
+
data: {
|
|
8
|
+
type: 'data';
|
|
9
|
+
data: string;
|
|
10
|
+
} | {
|
|
11
|
+
type: 'url';
|
|
12
|
+
url: URL;
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
type TParsedText = {
|
|
16
|
+
kind: 'text';
|
|
17
|
+
text: string;
|
|
18
|
+
};
|
|
19
|
+
type TParsedToolResult = {
|
|
20
|
+
kind: 'tool_result';
|
|
21
|
+
toolUseId: string;
|
|
22
|
+
isError: boolean;
|
|
23
|
+
content: string | Array<TParsedText | TParsedFile>;
|
|
24
|
+
};
|
|
25
|
+
type TParsedUserBlock = TParsedText | TParsedFile | TParsedToolResult;
|
|
26
|
+
type TParsedAssistantBlock = TParsedText | {
|
|
27
|
+
kind: 'thinking';
|
|
28
|
+
thinking: string;
|
|
29
|
+
signature: string;
|
|
30
|
+
} | {
|
|
31
|
+
kind: 'redacted_thinking';
|
|
32
|
+
} | {
|
|
33
|
+
kind: 'tool_use';
|
|
34
|
+
id: string;
|
|
35
|
+
name: string;
|
|
36
|
+
input: unknown;
|
|
37
|
+
};
|
|
38
|
+
type TParsedMessage = {
|
|
39
|
+
role: 'system';
|
|
40
|
+
text: string;
|
|
41
|
+
} | {
|
|
42
|
+
role: 'user';
|
|
43
|
+
blocks: TParsedUserBlock[];
|
|
44
|
+
} | {
|
|
45
|
+
role: 'assistant';
|
|
46
|
+
blocks: TParsedAssistantBlock[];
|
|
47
|
+
};
|
|
48
|
+
interface IParsedTool {
|
|
49
|
+
name: string;
|
|
50
|
+
description?: string;
|
|
51
|
+
inputSchema: plugins.LanguageModelV4FunctionTool['inputSchema'];
|
|
52
|
+
strict?: boolean;
|
|
53
|
+
inputExamples?: Array<{
|
|
54
|
+
input: plugins.JSONObject;
|
|
55
|
+
}>;
|
|
56
|
+
}
|
|
57
|
+
type TParsedToolChoice = {
|
|
58
|
+
type: 'auto';
|
|
59
|
+
} | {
|
|
60
|
+
type: 'any';
|
|
61
|
+
} | {
|
|
62
|
+
type: 'none';
|
|
63
|
+
} | {
|
|
64
|
+
type: 'tool';
|
|
65
|
+
name: string;
|
|
66
|
+
};
|
|
67
|
+
/** A request of the Messages API, checked and reduced to what this service translates. */
|
|
68
|
+
export interface IAnthropicMessagesParsedRequest {
|
|
69
|
+
modelId: string;
|
|
70
|
+
stream: boolean;
|
|
71
|
+
maxTokens: number;
|
|
72
|
+
system: string[];
|
|
73
|
+
messages: TParsedMessage[];
|
|
74
|
+
tools: IParsedTool[];
|
|
75
|
+
toolChoice?: TParsedToolChoice;
|
|
76
|
+
parallelToolCalls: boolean;
|
|
77
|
+
thinking: false | {
|
|
78
|
+
display: 'summarized' | 'omitted';
|
|
79
|
+
};
|
|
80
|
+
effort?: TAnthropicMessagesEffort;
|
|
81
|
+
responseFormat?: {
|
|
82
|
+
type: 'json';
|
|
83
|
+
schema: plugins.LanguageModelV4FunctionTool['inputSchema'];
|
|
84
|
+
};
|
|
85
|
+
temperature?: number;
|
|
86
|
+
topP?: number;
|
|
87
|
+
topK?: number;
|
|
88
|
+
stopSequences?: string[];
|
|
89
|
+
}
|
|
90
|
+
/** Checks a Messages API request body and reduces it to what this service translates. */
|
|
91
|
+
export declare const parseAnthropicMessagesRequest: (bodyArg: unknown) => IAnthropicMessagesParsedRequest;
|
|
92
|
+
/** Maps tool names to the names the model is sent, for a model with a shorter tool name limit. */
|
|
93
|
+
export declare class ToolNames {
|
|
94
|
+
private readonly toModel;
|
|
95
|
+
private readonly fromModel;
|
|
96
|
+
static create(namesArg: Iterable<string>, limitArg: number | undefined): Promise<ToolNames>;
|
|
97
|
+
sent(nameArg: string): string;
|
|
98
|
+
/** The client's name for a tool the model called, or `undefined` for a name the request never offered. */
|
|
99
|
+
received(nameArg: string): string | undefined;
|
|
100
|
+
}
|
|
101
|
+
export interface IAnthropicMessagesModelCall {
|
|
102
|
+
options: Omit<plugins.LanguageModelV4CallOptions, 'abortSignal'>;
|
|
103
|
+
toolNames: ToolNames;
|
|
104
|
+
/** Response headers that name what this request received differently from what it asked for. */
|
|
105
|
+
notices: Record<string, string>;
|
|
106
|
+
}
|
|
107
|
+
/** Translates a parsed request into the call of one model. */
|
|
108
|
+
export declare const createAnthropicMessagesModelCall: (requestArg: IAnthropicMessagesParsedRequest, modelArg: IAnthropicMessagesModel, signaturesArg: ThinkingSignatures, sessionIdArg: string | undefined) => Promise<IAnthropicMessagesModelCall>;
|
|
109
|
+
export {};
|