@juspay/neurolink 12.11.3 → 12.12.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/CHANGELOG.md +3 -4
- package/dist/browser/neurolink.min.js +533 -581
- package/dist/constants/enums.d.ts +13 -0
- package/dist/constants/enums.js +14 -0
- package/dist/core/baseProvider.d.ts +71 -3
- package/dist/core/baseProvider.js +152 -44
- package/dist/core/modules/GenerationHandler.d.ts +22 -24
- package/dist/core/modules/GenerationHandler.js +28 -463
- package/dist/core/nativeGenerateLoop.d.ts +35 -0
- package/dist/core/nativeGenerateLoop.js +261 -0
- package/dist/files/fileTools.d.ts +5 -5
- package/dist/index.d.ts +1 -0
- package/dist/index.js +4 -0
- package/dist/middleware/builtin/guardrails.d.ts +0 -5
- package/dist/middleware/builtin/guardrails.js +33 -5
- package/dist/middleware/factory.js +1 -1
- package/dist/middleware/wrapLanguageModel.d.ts +18 -0
- package/dist/middleware/wrapLanguageModel.js +53 -0
- package/dist/processors/media/AudioProcessor.js +46 -11
- package/dist/providers/amazonSagemaker.d.ts +17 -1
- package/dist/providers/amazonSagemaker.js +110 -0
- package/dist/providers/anthropic/client.d.ts +11 -0
- package/dist/providers/anthropic/client.js +148 -1
- package/dist/providers/catalog/index.generated.d.ts +1 -1
- package/dist/providers/catalog/index.generated.js +3 -0
- package/dist/providers/catalog/loader.js +1 -0
- package/dist/providers/catalog/mancer.json +192 -0
- package/dist/providers/configuredOpenAICompat.d.ts +11 -0
- package/dist/providers/configuredOpenAICompat.js +16 -0
- package/dist/providers/googleVertex/client.d.ts +0 -9
- package/dist/providers/googleVertex/client.js +0 -33
- package/dist/providers/openaiChatCompletionsBase.d.ts +21 -1
- package/dist/providers/openaiChatCompletionsBase.js +178 -0
- package/dist/providers/providerTypeUtils.d.ts +1 -2
- package/dist/providers/providerTypeUtils.js +5 -1
- package/dist/types/aiCompat.d.ts +485 -0
- package/dist/types/aiCompat.js +17 -0
- package/dist/types/conversation.d.ts +1 -1
- package/dist/types/generate.d.ts +52 -0
- package/dist/types/middleware.d.ts +3 -6
- package/dist/types/providerCatalog.generated.d.ts +2 -2
- package/dist/types/providers.d.ts +14 -1
- package/dist/types/tools.d.ts +2 -2
- package/dist/utils/generationErrors.d.ts +78 -6
- package/dist/utils/generationErrors.js +114 -6
- package/dist/utils/nativeSingleShot.d.ts +3 -0
- package/dist/utils/nativeSingleShot.js +83 -0
- package/dist/utils/tool.d.ts +30 -5
- package/dist/utils/tool.js +43 -5
- package/package.json +3 -6
- package/dist/utils/generation.d.ts +0 -8
- package/dist/utils/generation.js +0 -8
|
@@ -0,0 +1,485 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Local declarations of the tool, schema, message and model-protocol types
|
|
3
|
+
* that used to be re-exported from `ai` and `@ai-sdk/provider`.
|
|
4
|
+
*
|
|
5
|
+
* These are deliberately faithful to the upstream shapes rather than
|
|
6
|
+
* simplified. An earlier attempt declared `Tool` with `unknown` generic
|
|
7
|
+
* defaults and 66 type errors followed, because the upstream defaults are
|
|
8
|
+
* `any` and that is load-bearing: `NeverOptional` resolves its
|
|
9
|
+
* `0 extends 1 & N` branch under `any`, which makes `execute` and
|
|
10
|
+
* `outputSchema` OPTIONAL on a bare `Tool`. That optionality is the only
|
|
11
|
+
* reason a plain `Record<string, Tool>` satisfies `ToolSet`, which this
|
|
12
|
+
* codebase relies on in a dozen places.
|
|
13
|
+
*
|
|
14
|
+
* `any` therefore appears here on purpose and nowhere else. Each use is a
|
|
15
|
+
* reproduction of an upstream generic default, not a loosened annotation.
|
|
16
|
+
*/
|
|
17
|
+
import type { z } from "zod";
|
|
18
|
+
export type { JSONSchema7, JSONSchema7Definition } from "json-schema";
|
|
19
|
+
import type { JSONSchema7 } from "json-schema";
|
|
20
|
+
export type SchemaValidationResult<OBJECT> = {
|
|
21
|
+
success: true;
|
|
22
|
+
value: OBJECT;
|
|
23
|
+
} | {
|
|
24
|
+
success: false;
|
|
25
|
+
error: unknown;
|
|
26
|
+
};
|
|
27
|
+
export type Schema<OBJECT = unknown> = {
|
|
28
|
+
readonly _type: OBJECT;
|
|
29
|
+
readonly jsonSchema: JSONSchema7;
|
|
30
|
+
readonly validate?: (value: unknown) => SchemaValidationResult<OBJECT> | PromiseLike<SchemaValidationResult<OBJECT>>;
|
|
31
|
+
};
|
|
32
|
+
export type LazySchema<OBJECT = unknown> = () => FlexibleSchema<OBJECT>;
|
|
33
|
+
export type ZodSchema<OBJECT = unknown> = z.ZodType<OBJECT>;
|
|
34
|
+
export type StandardSchema<OBJECT = unknown> = {
|
|
35
|
+
readonly "~standard": {
|
|
36
|
+
readonly version: 1;
|
|
37
|
+
readonly vendor: string;
|
|
38
|
+
readonly validate: (value: unknown) => unknown;
|
|
39
|
+
readonly types?: {
|
|
40
|
+
readonly input: unknown;
|
|
41
|
+
readonly output: OBJECT;
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
export type FlexibleSchema<SCHEMA = any> = Schema<SCHEMA> | LazySchema<SCHEMA> | ZodSchema<SCHEMA> | StandardSchema<SCHEMA>;
|
|
46
|
+
export type InferSchema<SCHEMA> = SCHEMA extends ZodSchema<infer T> ? T : SCHEMA extends StandardSchema<infer T> ? T : SCHEMA extends LazySchema<infer T> ? T : SCHEMA extends Schema<infer T> ? T : never;
|
|
47
|
+
export type ToolCallOptions = {
|
|
48
|
+
toolCallId: string;
|
|
49
|
+
messages: ModelMessage[];
|
|
50
|
+
abortSignal?: AbortSignal;
|
|
51
|
+
experimental_context?: unknown;
|
|
52
|
+
};
|
|
53
|
+
export type ToolExecuteFunction<INPUT, OUTPUT> = (input: INPUT, options: ToolCallOptions) => AsyncIterable<OUTPUT> | PromiseLike<OUTPUT> | OUTPUT;
|
|
54
|
+
export type ToolNeedsApprovalFunction<INPUT> = (input: INPUT, options: ToolCallOptions) => boolean | PromiseLike<boolean>;
|
|
55
|
+
/**
|
|
56
|
+
* The upstream conditional that decides whether `execute` is required.
|
|
57
|
+
* Under `any` the first branch wins and everything becomes optional, which is
|
|
58
|
+
* what a bare `Tool` relies on.
|
|
59
|
+
*/
|
|
60
|
+
export type NeverOptional<N, T> = 0 extends 1 & N ? Partial<T> : [N] extends [never] ? Partial<Record<keyof T, undefined>> : T;
|
|
61
|
+
export type ToolOutputProperties<INPUT, OUTPUT> = NeverOptional<OUTPUT, {
|
|
62
|
+
execute: ToolExecuteFunction<INPUT, OUTPUT>;
|
|
63
|
+
outputSchema?: FlexibleSchema<OUTPUT>;
|
|
64
|
+
} | {
|
|
65
|
+
outputSchema: FlexibleSchema<OUTPUT>;
|
|
66
|
+
execute?: never;
|
|
67
|
+
}>;
|
|
68
|
+
export type Tool<INPUT = any, OUTPUT = any> = {
|
|
69
|
+
description?: string;
|
|
70
|
+
title?: string;
|
|
71
|
+
providerOptions?: Record<string, Record<string, unknown>>;
|
|
72
|
+
inputSchema: FlexibleSchema<INPUT>;
|
|
73
|
+
inputExamples?: Array<{
|
|
74
|
+
input: INPUT;
|
|
75
|
+
}>;
|
|
76
|
+
needsApproval?: boolean | ToolNeedsApprovalFunction<INPUT>;
|
|
77
|
+
strict?: boolean;
|
|
78
|
+
onInputStart?: (options: ToolCallOptions) => void | PromiseLike<void>;
|
|
79
|
+
onInputDelta?: (options: {
|
|
80
|
+
inputTextDelta: string;
|
|
81
|
+
} & ToolCallOptions) => void | PromiseLike<void>;
|
|
82
|
+
onInputAvailable?: (options: {
|
|
83
|
+
input: INPUT;
|
|
84
|
+
} & ToolCallOptions) => void | PromiseLike<void>;
|
|
85
|
+
} & ToolOutputProperties<INPUT, OUTPUT> & {
|
|
86
|
+
toModelOutput?: (options: {
|
|
87
|
+
toolCallId: string;
|
|
88
|
+
input: INPUT;
|
|
89
|
+
output: OUTPUT;
|
|
90
|
+
}) => unknown | PromiseLike<unknown>;
|
|
91
|
+
} & ({
|
|
92
|
+
type?: undefined | "function";
|
|
93
|
+
} | {
|
|
94
|
+
type: "dynamic";
|
|
95
|
+
} | {
|
|
96
|
+
type: "provider";
|
|
97
|
+
id: `${string}.${string}`;
|
|
98
|
+
args: Record<string, unknown>;
|
|
99
|
+
supportsDeferredResults?: boolean;
|
|
100
|
+
});
|
|
101
|
+
export type ToolSet = Record<string, (Tool<never, never> | Tool<any, any> | Tool<any, never> | Tool<never, any>) & Pick<Tool<any, any>, "execute" | "onInputAvailable" | "onInputStart" | "onInputDelta" | "needsApproval">>;
|
|
102
|
+
/** Upstream bounds this by `Record<string, unknown>`, not by `ToolSet`. */
|
|
103
|
+
export type ToolChoice<TOOLS extends Record<string, unknown>> = "auto" | "none" | "required" | {
|
|
104
|
+
type: "tool";
|
|
105
|
+
toolName: Extract<keyof TOOLS, string>;
|
|
106
|
+
};
|
|
107
|
+
export type InferToolInput<TOOL extends Tool> = TOOL extends Tool<infer INPUT, any> ? INPUT : never;
|
|
108
|
+
export type InferToolOutput<TOOL extends Tool> = TOOL extends Tool<any, infer OUTPUT> ? OUTPUT : never;
|
|
109
|
+
export type ToolApprovalRequest = {
|
|
110
|
+
type: "tool-approval-request";
|
|
111
|
+
approvalId: string;
|
|
112
|
+
toolCallId: string;
|
|
113
|
+
};
|
|
114
|
+
export type ToolApprovalResponse = {
|
|
115
|
+
type: "tool-approval-response";
|
|
116
|
+
approvalId: string;
|
|
117
|
+
approved: boolean;
|
|
118
|
+
reason?: string;
|
|
119
|
+
providerExecuted?: boolean;
|
|
120
|
+
};
|
|
121
|
+
export type DataContent = string | Uint8Array | ArrayBuffer | Buffer;
|
|
122
|
+
export type TextPart = {
|
|
123
|
+
type: "text";
|
|
124
|
+
text: string;
|
|
125
|
+
providerOptions?: Record<string, Record<string, unknown>>;
|
|
126
|
+
};
|
|
127
|
+
export type ImagePart = {
|
|
128
|
+
type: "image";
|
|
129
|
+
image: DataContent | URL;
|
|
130
|
+
mediaType?: string;
|
|
131
|
+
providerOptions?: Record<string, Record<string, unknown>>;
|
|
132
|
+
};
|
|
133
|
+
export type FilePart = {
|
|
134
|
+
type: "file";
|
|
135
|
+
data: DataContent | URL;
|
|
136
|
+
filename?: string;
|
|
137
|
+
mediaType: string;
|
|
138
|
+
providerOptions?: Record<string, Record<string, unknown>>;
|
|
139
|
+
};
|
|
140
|
+
export type ReasoningPart = {
|
|
141
|
+
type: "reasoning";
|
|
142
|
+
text: string;
|
|
143
|
+
providerOptions?: Record<string, Record<string, unknown>>;
|
|
144
|
+
};
|
|
145
|
+
export type ToolCallPart = {
|
|
146
|
+
type: "tool-call";
|
|
147
|
+
toolCallId: string;
|
|
148
|
+
toolName: string;
|
|
149
|
+
input: unknown;
|
|
150
|
+
providerExecuted?: boolean;
|
|
151
|
+
providerOptions?: Record<string, Record<string, unknown>>;
|
|
152
|
+
};
|
|
153
|
+
export type ToolResultPart = {
|
|
154
|
+
type: "tool-result";
|
|
155
|
+
toolCallId: string;
|
|
156
|
+
toolName: string;
|
|
157
|
+
output: unknown;
|
|
158
|
+
providerExecuted?: boolean;
|
|
159
|
+
providerOptions?: Record<string, Record<string, unknown>>;
|
|
160
|
+
};
|
|
161
|
+
export type UserContent = string | Array<TextPart | ImagePart | FilePart>;
|
|
162
|
+
export type AssistantContent = string | Array<TextPart | FilePart | ReasoningPart | ToolCallPart | ToolResultPart | ToolApprovalRequest>;
|
|
163
|
+
export type ToolContent = Array<ToolResultPart | ToolApprovalResponse>;
|
|
164
|
+
export type SystemModelMessage = {
|
|
165
|
+
role: "system";
|
|
166
|
+
content: string;
|
|
167
|
+
providerOptions?: Record<string, Record<string, unknown>>;
|
|
168
|
+
};
|
|
169
|
+
export type UserModelMessage = {
|
|
170
|
+
role: "user";
|
|
171
|
+
content: UserContent;
|
|
172
|
+
providerOptions?: Record<string, Record<string, unknown>>;
|
|
173
|
+
};
|
|
174
|
+
export type AssistantModelMessage = {
|
|
175
|
+
role: "assistant";
|
|
176
|
+
content: AssistantContent;
|
|
177
|
+
providerOptions?: Record<string, Record<string, unknown>>;
|
|
178
|
+
};
|
|
179
|
+
export type ToolModelMessage = {
|
|
180
|
+
role: "tool";
|
|
181
|
+
content: ToolContent;
|
|
182
|
+
providerOptions?: Record<string, Record<string, unknown>>;
|
|
183
|
+
};
|
|
184
|
+
export type ModelMessage = SystemModelMessage | UserModelMessage | AssistantModelMessage | ToolModelMessage;
|
|
185
|
+
export type FinishReason = "stop" | "length" | "content-filter" | "tool-calls" | "error" | "other";
|
|
186
|
+
export type LanguageModelUsage = {
|
|
187
|
+
inputTokens: number | undefined;
|
|
188
|
+
outputTokens: number | undefined;
|
|
189
|
+
totalTokens: number | undefined;
|
|
190
|
+
inputTokenDetails?: {
|
|
191
|
+
noCacheTokens?: number | undefined;
|
|
192
|
+
cacheReadTokens?: number | undefined;
|
|
193
|
+
cacheWriteTokens?: number | undefined;
|
|
194
|
+
};
|
|
195
|
+
outputTokenDetails?: {
|
|
196
|
+
textTokens?: number | undefined;
|
|
197
|
+
reasoningTokens?: number | undefined;
|
|
198
|
+
};
|
|
199
|
+
reasoningTokens?: number | undefined;
|
|
200
|
+
cachedInputTokens?: number | undefined;
|
|
201
|
+
};
|
|
202
|
+
export type LanguageModelRequestMetadata = {
|
|
203
|
+
body?: unknown;
|
|
204
|
+
};
|
|
205
|
+
export type LanguageModelResponseMetadata = {
|
|
206
|
+
id: string;
|
|
207
|
+
timestamp: Date;
|
|
208
|
+
modelId: string;
|
|
209
|
+
headers?: Record<string, string>;
|
|
210
|
+
};
|
|
211
|
+
export type LanguageModelV3Message = ModelMessage;
|
|
212
|
+
export type LanguageModelV3Prompt = ModelMessage[];
|
|
213
|
+
export type LanguageModelV3CallOptions = {
|
|
214
|
+
prompt: LanguageModelV3Prompt;
|
|
215
|
+
maxOutputTokens?: number;
|
|
216
|
+
temperature?: number;
|
|
217
|
+
topP?: number;
|
|
218
|
+
topK?: number;
|
|
219
|
+
presencePenalty?: number;
|
|
220
|
+
frequencyPenalty?: number;
|
|
221
|
+
stopSequences?: string[];
|
|
222
|
+
seed?: number;
|
|
223
|
+
tools?: Array<{
|
|
224
|
+
type: "function";
|
|
225
|
+
name: string;
|
|
226
|
+
description?: string;
|
|
227
|
+
inputSchema?: unknown;
|
|
228
|
+
strict?: boolean;
|
|
229
|
+
providerOptions?: Record<string, Record<string, unknown>>;
|
|
230
|
+
} | {
|
|
231
|
+
type: "provider-defined";
|
|
232
|
+
id: string;
|
|
233
|
+
name: string;
|
|
234
|
+
args: Record<string, unknown>;
|
|
235
|
+
}>;
|
|
236
|
+
toolChoice?: LanguageModelV3ToolChoice;
|
|
237
|
+
responseFormat?: {
|
|
238
|
+
type: "text" | "json";
|
|
239
|
+
schema?: Record<string, unknown>;
|
|
240
|
+
name?: string;
|
|
241
|
+
description?: string;
|
|
242
|
+
};
|
|
243
|
+
abortSignal?: AbortSignal;
|
|
244
|
+
headers?: Record<string, string | undefined>;
|
|
245
|
+
includeRawChunks?: boolean;
|
|
246
|
+
providerOptions?: Record<string, Record<string, unknown>>;
|
|
247
|
+
};
|
|
248
|
+
export type LanguageModelV3ToolCall = {
|
|
249
|
+
type: "tool-call";
|
|
250
|
+
toolCallId: string;
|
|
251
|
+
toolName: string;
|
|
252
|
+
input: string;
|
|
253
|
+
providerExecuted?: boolean;
|
|
254
|
+
};
|
|
255
|
+
export type LanguageModelV3Source = {
|
|
256
|
+
type: "source";
|
|
257
|
+
sourceType: string;
|
|
258
|
+
id: string;
|
|
259
|
+
url?: string;
|
|
260
|
+
title?: string;
|
|
261
|
+
};
|
|
262
|
+
export type LanguageModelV3ToolChoice = {
|
|
263
|
+
type: "auto";
|
|
264
|
+
} | {
|
|
265
|
+
type: "none";
|
|
266
|
+
} | {
|
|
267
|
+
type: "required";
|
|
268
|
+
} | {
|
|
269
|
+
type: "tool";
|
|
270
|
+
toolName: string;
|
|
271
|
+
};
|
|
272
|
+
export type LanguageModelV3Content = {
|
|
273
|
+
type: "text";
|
|
274
|
+
text: string;
|
|
275
|
+
} | {
|
|
276
|
+
type: "reasoning";
|
|
277
|
+
text: string;
|
|
278
|
+
} | {
|
|
279
|
+
type: "file";
|
|
280
|
+
data: unknown;
|
|
281
|
+
mediaType: string;
|
|
282
|
+
} | LanguageModelV3ToolCall | LanguageModelV3Source | ({
|
|
283
|
+
type: "tool-result";
|
|
284
|
+
} & Record<string, unknown>) | ({
|
|
285
|
+
type: "tool-approval-request";
|
|
286
|
+
} & Record<string, unknown>);
|
|
287
|
+
/** Per-direction token counts, as the v3 providers report them. */
|
|
288
|
+
export type LanguageModelV3TokenCount = {
|
|
289
|
+
total?: number;
|
|
290
|
+
noCache?: number;
|
|
291
|
+
cacheRead?: number;
|
|
292
|
+
cacheWrite?: number;
|
|
293
|
+
text?: number;
|
|
294
|
+
reasoning?: number;
|
|
295
|
+
};
|
|
296
|
+
export type LanguageModelV3Usage = {
|
|
297
|
+
inputTokens: LanguageModelV3TokenCount;
|
|
298
|
+
outputTokens: LanguageModelV3TokenCount;
|
|
299
|
+
};
|
|
300
|
+
export type LanguageModelV3FinishReason = {
|
|
301
|
+
unified: FinishReason | string;
|
|
302
|
+
raw?: string;
|
|
303
|
+
};
|
|
304
|
+
export type LanguageModelV3GenerateResult = {
|
|
305
|
+
content: LanguageModelV3Content[];
|
|
306
|
+
finishReason: LanguageModelV3FinishReason;
|
|
307
|
+
usage: LanguageModelV3Usage;
|
|
308
|
+
warnings?: unknown[];
|
|
309
|
+
request?: unknown;
|
|
310
|
+
response?: unknown;
|
|
311
|
+
providerMetadata?: Record<string, Record<string, unknown>>;
|
|
312
|
+
};
|
|
313
|
+
/**
|
|
314
|
+
* Discriminated rather than a loose record: consumers switch on `type` and
|
|
315
|
+
* read variant-specific fields (a finish part's usage, a tool-call's input).
|
|
316
|
+
*/
|
|
317
|
+
export type LanguageModelV3StreamPart = {
|
|
318
|
+
type: "text-start";
|
|
319
|
+
id?: string;
|
|
320
|
+
} | {
|
|
321
|
+
type: "text-delta";
|
|
322
|
+
id?: string;
|
|
323
|
+
delta: string;
|
|
324
|
+
} | {
|
|
325
|
+
type: "text-end";
|
|
326
|
+
id?: string;
|
|
327
|
+
} | {
|
|
328
|
+
type: "reasoning-start";
|
|
329
|
+
id?: string;
|
|
330
|
+
} | {
|
|
331
|
+
type: "reasoning-delta";
|
|
332
|
+
id?: string;
|
|
333
|
+
delta: string;
|
|
334
|
+
} | {
|
|
335
|
+
type: "reasoning-end";
|
|
336
|
+
id?: string;
|
|
337
|
+
} | {
|
|
338
|
+
type: "tool-call";
|
|
339
|
+
toolCallId: string;
|
|
340
|
+
toolName: string;
|
|
341
|
+
input: string;
|
|
342
|
+
providerExecuted?: boolean;
|
|
343
|
+
} | ({
|
|
344
|
+
type: "tool-input-start";
|
|
345
|
+
} & Record<string, unknown>) | ({
|
|
346
|
+
type: "tool-input-delta";
|
|
347
|
+
} & Record<string, unknown>) | ({
|
|
348
|
+
type: "tool-input-end";
|
|
349
|
+
} & Record<string, unknown>) | ({
|
|
350
|
+
type: "tool-result";
|
|
351
|
+
} & Record<string, unknown>) | {
|
|
352
|
+
type: "source";
|
|
353
|
+
sourceType: string;
|
|
354
|
+
id: string;
|
|
355
|
+
url?: string;
|
|
356
|
+
title?: string;
|
|
357
|
+
} | ({
|
|
358
|
+
type: "file";
|
|
359
|
+
} & Record<string, unknown>) | ({
|
|
360
|
+
type: "stream-start";
|
|
361
|
+
} & Record<string, unknown>) | ({
|
|
362
|
+
type: "response-metadata";
|
|
363
|
+
} & Record<string, unknown>) | ({
|
|
364
|
+
type: "raw";
|
|
365
|
+
} & Record<string, unknown>) | {
|
|
366
|
+
type: "error";
|
|
367
|
+
error: unknown;
|
|
368
|
+
} | {
|
|
369
|
+
type: "finish";
|
|
370
|
+
finishReason: LanguageModelV3FinishReason;
|
|
371
|
+
usage: LanguageModelV3Usage;
|
|
372
|
+
providerMetadata?: Record<string, Record<string, unknown>>;
|
|
373
|
+
};
|
|
374
|
+
export type LanguageModelV3StreamResult = {
|
|
375
|
+
stream: ReadableStream<LanguageModelV3StreamPart>;
|
|
376
|
+
request?: unknown;
|
|
377
|
+
response?: unknown;
|
|
378
|
+
};
|
|
379
|
+
export type LanguageModelV3 = {
|
|
380
|
+
readonly specificationVersion: "v3";
|
|
381
|
+
readonly provider: string;
|
|
382
|
+
readonly modelId: string;
|
|
383
|
+
readonly supportedUrls: Record<string, RegExp[]> | PromiseLike<Record<string, RegExp[]>>;
|
|
384
|
+
doGenerate(options: LanguageModelV3CallOptions): PromiseLike<LanguageModelV3GenerateResult>;
|
|
385
|
+
doStream(options: LanguageModelV3CallOptions): PromiseLike<LanguageModelV3StreamResult>;
|
|
386
|
+
};
|
|
387
|
+
export type LanguageModelV3Middleware = {
|
|
388
|
+
readonly specificationVersion: "v3";
|
|
389
|
+
overrideProvider?: (options: {
|
|
390
|
+
model: LanguageModelV3;
|
|
391
|
+
}) => string;
|
|
392
|
+
overrideModelId?: (options: {
|
|
393
|
+
model: LanguageModelV3;
|
|
394
|
+
}) => string;
|
|
395
|
+
overrideSupportedUrls?: (options: {
|
|
396
|
+
model: LanguageModelV3;
|
|
397
|
+
}) => Record<string, RegExp[]> | PromiseLike<Record<string, RegExp[]>>;
|
|
398
|
+
transformParams?: (options: {
|
|
399
|
+
type: "generate" | "stream";
|
|
400
|
+
params: LanguageModelV3CallOptions;
|
|
401
|
+
model: LanguageModelV3;
|
|
402
|
+
}) => PromiseLike<LanguageModelV3CallOptions>;
|
|
403
|
+
wrapGenerate?: (options: {
|
|
404
|
+
doGenerate: () => PromiseLike<LanguageModelV3GenerateResult>;
|
|
405
|
+
doStream: () => PromiseLike<LanguageModelV3StreamResult>;
|
|
406
|
+
params: LanguageModelV3CallOptions;
|
|
407
|
+
model: LanguageModelV3;
|
|
408
|
+
}) => PromiseLike<LanguageModelV3GenerateResult>;
|
|
409
|
+
wrapStream?: (options: {
|
|
410
|
+
doGenerate: () => PromiseLike<LanguageModelV3GenerateResult>;
|
|
411
|
+
doStream: () => PromiseLike<LanguageModelV3StreamResult>;
|
|
412
|
+
params: LanguageModelV3CallOptions;
|
|
413
|
+
model: LanguageModelV3;
|
|
414
|
+
}) => PromiseLike<LanguageModelV3StreamResult>;
|
|
415
|
+
};
|
|
416
|
+
export type LanguageModelMiddleware = LanguageModelV3Middleware;
|
|
417
|
+
/** Upstream also admits a v2 model and a bare id string. */
|
|
418
|
+
export type LanguageModel = string | LanguageModelV3;
|
|
419
|
+
export type EmbeddingModel = string | Record<string, unknown>;
|
|
420
|
+
export type ImageModel = string | Record<string, unknown>;
|
|
421
|
+
export type StepResult<TOOLS extends ToolSet = ToolSet> = {
|
|
422
|
+
readonly stepNumber?: number;
|
|
423
|
+
readonly content: Array<{
|
|
424
|
+
type: string;
|
|
425
|
+
} & Record<string, unknown>>;
|
|
426
|
+
readonly text: string;
|
|
427
|
+
readonly reasoning?: unknown;
|
|
428
|
+
readonly reasoningText?: string;
|
|
429
|
+
readonly files?: unknown[];
|
|
430
|
+
readonly sources?: unknown[];
|
|
431
|
+
readonly toolCalls: Array<{
|
|
432
|
+
toolName: string;
|
|
433
|
+
toolCallId?: string;
|
|
434
|
+
input?: unknown;
|
|
435
|
+
} & Record<string, unknown>>;
|
|
436
|
+
readonly toolResults: Array<{
|
|
437
|
+
toolName?: string;
|
|
438
|
+
toolCallId?: string;
|
|
439
|
+
output?: unknown;
|
|
440
|
+
} & Record<string, unknown>>;
|
|
441
|
+
readonly stepType?: string;
|
|
442
|
+
readonly finishReason: FinishReason;
|
|
443
|
+
readonly rawFinishReason?: string;
|
|
444
|
+
readonly usage: LanguageModelUsage;
|
|
445
|
+
readonly warnings?: unknown[];
|
|
446
|
+
readonly request?: LanguageModelRequestMetadata;
|
|
447
|
+
readonly response?: LanguageModelResponseMetadata & {
|
|
448
|
+
messages: ModelMessage[];
|
|
449
|
+
body?: unknown;
|
|
450
|
+
};
|
|
451
|
+
readonly providerMetadata?: Record<string, Record<string, unknown>>;
|
|
452
|
+
readonly tools?: TOOLS;
|
|
453
|
+
};
|
|
454
|
+
export type GenerateTextResult<TOOLS extends ToolSet = ToolSet, OUTPUT = unknown> = StepResult<TOOLS> & {
|
|
455
|
+
readonly steps: Array<StepResult<TOOLS>>;
|
|
456
|
+
readonly totalUsage: LanguageModelUsage;
|
|
457
|
+
readonly experimental_output?: OUTPUT;
|
|
458
|
+
};
|
|
459
|
+
export type ToolCallRepairFunction<TOOLS extends ToolSet = ToolSet> = (options: {
|
|
460
|
+
system: string | undefined;
|
|
461
|
+
messages: ModelMessage[];
|
|
462
|
+
toolCall: LanguageModelV3ToolCall;
|
|
463
|
+
tools: TOOLS;
|
|
464
|
+
inputSchema: (options: {
|
|
465
|
+
toolName: string;
|
|
466
|
+
}) => JSONSchema7;
|
|
467
|
+
error: Error;
|
|
468
|
+
}) => Promise<LanguageModelV3ToolCall | null>;
|
|
469
|
+
export type PrepareStepResult<TOOLS extends Record<string, Tool> = Record<string, Tool>> = {
|
|
470
|
+
model?: LanguageModel;
|
|
471
|
+
toolChoice?: ToolChoice<TOOLS>;
|
|
472
|
+
activeTools?: Array<keyof TOOLS>;
|
|
473
|
+
system?: string;
|
|
474
|
+
messages?: ModelMessage[];
|
|
475
|
+
providerOptions?: Record<string, Record<string, unknown>>;
|
|
476
|
+
tools?: TOOLS;
|
|
477
|
+
};
|
|
478
|
+
export type PrepareStepFunction<TOOLS extends Record<string, Tool> = Record<string, Tool>> = (options: {
|
|
479
|
+
steps: Array<StepResult<ToolSet>>;
|
|
480
|
+
stepNumber: number;
|
|
481
|
+
model: LanguageModel;
|
|
482
|
+
messages: ModelMessage[];
|
|
483
|
+
maxSteps?: number;
|
|
484
|
+
experimental_context?: unknown;
|
|
485
|
+
}) => PrepareStepResult<TOOLS> | undefined | PromiseLike<PrepareStepResult<TOOLS> | undefined>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Local declarations of the tool, schema, message and model-protocol types
|
|
3
|
+
* that used to be re-exported from `ai` and `@ai-sdk/provider`.
|
|
4
|
+
*
|
|
5
|
+
* These are deliberately faithful to the upstream shapes rather than
|
|
6
|
+
* simplified. An earlier attempt declared `Tool` with `unknown` generic
|
|
7
|
+
* defaults and 66 type errors followed, because the upstream defaults are
|
|
8
|
+
* `any` and that is load-bearing: `NeverOptional` resolves its
|
|
9
|
+
* `0 extends 1 & N` branch under `any`, which makes `execute` and
|
|
10
|
+
* `outputSchema` OPTIONAL on a bare `Tool`. That optionality is the only
|
|
11
|
+
* reason a plain `Record<string, Tool>` satisfies `ToolSet`, which this
|
|
12
|
+
* codebase relies on in a dozen places.
|
|
13
|
+
*
|
|
14
|
+
* `any` therefore appears here on purpose and nowhere else. Each use is a
|
|
15
|
+
* reproduction of an upstream generic default, not a loosened annotation.
|
|
16
|
+
*/
|
|
17
|
+
export {};
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
*/
|
|
35
35
|
import type { HippocampusMemory, HippocampusStorageConfig } from "./memory.js";
|
|
36
36
|
import type { ObservabilityConfig } from "./observability.js";
|
|
37
|
-
export type { ModelMessage, SystemModelMessage, UserModelMessage, AssistantModelMessage, ToolModelMessage, TextPart, ImagePart, FilePart, ToolCallPart, ToolResultPart, AssistantContent, UserContent, ToolContent, DataContent, } from "
|
|
37
|
+
export type { ModelMessage, SystemModelMessage, UserModelMessage, AssistantModelMessage, ToolModelMessage, TextPart, ImagePart, FilePart, ToolCallPart, ToolResultPart, AssistantContent, UserContent, ToolContent, DataContent, } from "./aiCompat.js";
|
|
38
38
|
/**
|
|
39
39
|
* Legacy public alias for the Hippocampus storage configuration.
|
|
40
40
|
* The structural definition lives in `./memory.ts`; this re-export keeps
|
package/dist/types/generate.d.ts
CHANGED
|
@@ -1557,3 +1557,55 @@ export type GenerationCallConfig = {
|
|
|
1557
1557
|
/** Set on the single toolChoice:"none" re-ask so it can never recurse. */
|
|
1558
1558
|
isToolReask?: boolean;
|
|
1559
1559
|
};
|
|
1560
|
+
/**
|
|
1561
|
+
* Inputs to the shared native generate loop (`core/nativeGenerateLoop.ts`).
|
|
1562
|
+
* One loop serves every provider whose delegating model exposes a v3-shaped
|
|
1563
|
+
* `doGenerate`; the provider supplies the wire details.
|
|
1564
|
+
*/
|
|
1565
|
+
export type NativeGenerateLoopArgs = {
|
|
1566
|
+
doGenerate: (options: Record<string, unknown>) => Promise<Record<string, unknown>>;
|
|
1567
|
+
/** Conversation in the message-builder shape each doGenerate converts itself. */
|
|
1568
|
+
conversation: Array<Record<string, unknown>>;
|
|
1569
|
+
/** Tool declarations in the v3 shape doGenerate already knows how to convert. */
|
|
1570
|
+
tools?: Array<Record<string, unknown>>;
|
|
1571
|
+
/** Registered tools, used to execute a call the model asks for. */
|
|
1572
|
+
toolsRecord: Record<string, unknown>;
|
|
1573
|
+
toolChoice?: unknown;
|
|
1574
|
+
responseFormat?: Record<string, unknown>;
|
|
1575
|
+
providerOptions?: Record<string, Record<string, unknown>>;
|
|
1576
|
+
maxSteps: number;
|
|
1577
|
+
maxOutputTokens?: number;
|
|
1578
|
+
temperature?: number;
|
|
1579
|
+
abortSignal?: AbortSignal;
|
|
1580
|
+
/** Per-tool-execution cap, forwarded into `guardToolExecutor`. */
|
|
1581
|
+
toolTimeoutMs?: number;
|
|
1582
|
+
/** Wraps one step: retry ladder plus provider error classification. */
|
|
1583
|
+
runStep: (call: () => Promise<Record<string, unknown>>) => Promise<Record<string, unknown>>;
|
|
1584
|
+
};
|
|
1585
|
+
export type NativeGenerateLoopResult = {
|
|
1586
|
+
text: string;
|
|
1587
|
+
finishReason: string;
|
|
1588
|
+
rawFinishReason?: string;
|
|
1589
|
+
inputTokens: number;
|
|
1590
|
+
outputTokens: number;
|
|
1591
|
+
cacheReadTokens: number;
|
|
1592
|
+
cacheWriteTokens: number;
|
|
1593
|
+
toolsUsed: string[];
|
|
1594
|
+
steps: number;
|
|
1595
|
+
};
|
|
1596
|
+
export type SingleShotRequest = {
|
|
1597
|
+
system?: string;
|
|
1598
|
+
prompt: string;
|
|
1599
|
+
maxOutputTokens?: number;
|
|
1600
|
+
temperature?: number;
|
|
1601
|
+
abortSignal?: AbortSignal;
|
|
1602
|
+
};
|
|
1603
|
+
export type SingleShotResult = {
|
|
1604
|
+
text: string;
|
|
1605
|
+
usage?: {
|
|
1606
|
+
inputTokens?: number;
|
|
1607
|
+
outputTokens?: number;
|
|
1608
|
+
totalTokens?: number;
|
|
1609
|
+
};
|
|
1610
|
+
finishReason?: string;
|
|
1611
|
+
};
|
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
import type { JsonValue } from "../types/common.js";
|
|
2
2
|
import type { EvaluationData, GetPromptFunction } from "./evaluation.js";
|
|
3
3
|
import type { AuthenticatedUser, RouteDefinition, ServerContext } from "./server.js";
|
|
4
|
-
import type { LanguageModelMiddleware as BaseLanguageModelMiddleware } from "
|
|
5
|
-
export type { LanguageModelMiddleware } from "
|
|
6
|
-
export type { LanguageModelV3, LanguageModelV3CallOptions, LanguageModelV3Message, LanguageModelV3Prompt, LanguageModelV3StreamPart, LanguageModelV3ToolCall, LanguageModelV3ToolChoice, LanguageModelV3Source, LanguageModelV3Middleware, JSONSchema7, } from "
|
|
7
|
-
import type { LanguageModelV3 } from "@ai-sdk/provider";
|
|
8
|
-
export type LanguageModelV3GenerateResult = Awaited<ReturnType<LanguageModelV3["doGenerate"]>>;
|
|
9
|
-
export type LanguageModelV3StreamResult = Awaited<ReturnType<LanguageModelV3["doStream"]>>;
|
|
4
|
+
import type { LanguageModelMiddleware as BaseLanguageModelMiddleware } from "./aiCompat.js";
|
|
5
|
+
export type { LanguageModelMiddleware } from "./aiCompat.js";
|
|
6
|
+
export type { LanguageModelV3, LanguageModelV3CallOptions, LanguageModelV3Message, LanguageModelV3Prompt, LanguageModelV3StreamPart, LanguageModelV3ToolCall, LanguageModelV3ToolChoice, LanguageModelV3Source, LanguageModelV3Middleware, LanguageModelV3GenerateResult, LanguageModelV3StreamResult, JSONSchema7, } from "./aiCompat.js";
|
|
10
7
|
/**
|
|
11
8
|
* Metadata type for NeuroLink middleware
|
|
12
9
|
* Provides additional information about middleware without affecting execution
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export type CatalogProviderName = "baseten" | "cerebras" | "cloudflare" | "fireworks" | "gmicloud" | "groq" | "inception-labs" | "io-intelligence" | "mistral" | "perplexity" | "sambanova" | "together-ai" | "upstage" | "xai";
|
|
2
|
-
export type CatalogCredentialKey = "baseten" | "cerebras" | "cloudflare" | "fireworks" | "gmicloud" | "groq" | "inceptionLabs" | "ioIntelligence" | "mistral" | "perplexity" | "sambanova" | "together" | "upstage" | "xai";
|
|
1
|
+
export type CatalogProviderName = "baseten" | "cerebras" | "cloudflare" | "fireworks" | "gmicloud" | "groq" | "inception-labs" | "io-intelligence" | "mancer" | "mistral" | "perplexity" | "sambanova" | "together-ai" | "upstage" | "xai";
|
|
2
|
+
export type CatalogCredentialKey = "baseten" | "cerebras" | "cloudflare" | "fireworks" | "gmicloud" | "groq" | "inceptionLabs" | "ioIntelligence" | "mancer" | "mistral" | "perplexity" | "sambanova" | "together" | "upstage" | "xai";
|
|
@@ -12,7 +12,7 @@ import type { ProviderError, ProviderErrorRule } from "./errors.js";
|
|
|
12
12
|
import type { ExternalMCPToolInfo } from "./externalMcp.js";
|
|
13
13
|
import type { ClaudeSubscriptionTier, AnthropicAuthMethod, AnthropicAuthConfig, SubscriptionInfo, OAuthToken } from "./subscription.js";
|
|
14
14
|
import type { Tool } from "./tools.js";
|
|
15
|
-
export type { LanguageModel, EmbeddingModel, ImageModel, GenerateTextResult, StepResult, ToolCallRepairFunction, PrepareStepFunction, PrepareStepResult, FinishReason, LanguageModelUsage, LanguageModelRequestMetadata, LanguageModelResponseMetadata, } from "
|
|
15
|
+
export type { LanguageModel, EmbeddingModel, ImageModel, GenerateTextResult, StepResult, ToolCallRepairFunction, PrepareStepFunction, PrepareStepResult, FinishReason, LanguageModelUsage, LanguageModelRequestMetadata, LanguageModelResponseMetadata, } from "./aiCompat.js";
|
|
16
16
|
export type { ClaudeSubscriptionTier, AnthropicAuthMethod, AnthropicAuthConfig, SubscriptionInfo, } from "./subscription.js";
|
|
17
17
|
/**
|
|
18
18
|
* Generic AI SDK model interface
|
|
@@ -199,6 +199,10 @@ export type NeurolinkCredentials = {
|
|
|
199
199
|
apiKey?: string;
|
|
200
200
|
baseURL?: string;
|
|
201
201
|
};
|
|
202
|
+
mancer?: {
|
|
203
|
+
apiKey?: string;
|
|
204
|
+
baseURL?: string;
|
|
205
|
+
};
|
|
202
206
|
mistral?: {
|
|
203
207
|
apiKey?: string;
|
|
204
208
|
baseURL?: string;
|
|
@@ -671,6 +675,15 @@ export type OpenAICompatCatalogEntry = {
|
|
|
671
675
|
modelEnvVar: string;
|
|
672
676
|
/** Default model when modelEnvVar is unset. */
|
|
673
677
|
defaultModel: string;
|
|
678
|
+
/**
|
|
679
|
+
* Whether the vendor accepts native tool definitions, from the catalog's
|
|
680
|
+
* `capabilities.tools`. `false` makes the provider's `supportsTools()`
|
|
681
|
+
* answer false, so no `tools` array ever reaches a wire that rejects one
|
|
682
|
+
* (Mancer's free model answers 400 BAD_PARAMETERS to any tool list).
|
|
683
|
+
* Omitted means "not declared": fall through to the model registry, the
|
|
684
|
+
* same default every hand-written provider uses.
|
|
685
|
+
*/
|
|
686
|
+
supportsTools?: boolean;
|
|
674
687
|
/**
|
|
675
688
|
* The literal passed as ProviderFactory.registerProvider()'s defaultModel
|
|
676
689
|
* argument (resolved before the provider is constructed). Preserves each
|
package/dist/types/tools.d.ts
CHANGED
|
@@ -9,8 +9,8 @@ import type { ValidationError } from "../utils/parameterValidation.js";
|
|
|
9
9
|
import type { MCPToolAnnotations } from "./mcp.js";
|
|
10
10
|
import type { Logger } from "./utilities.js";
|
|
11
11
|
import type { HITLExecutionState } from "./hitl.js";
|
|
12
|
-
import type { Tool } from "
|
|
13
|
-
export type { Tool, ToolSet, ToolChoice,
|
|
12
|
+
import type { Tool } from "./aiCompat.js";
|
|
13
|
+
export type { Tool, ToolSet, ToolChoice, ToolExecuteFunction, ToolApprovalRequest, ToolApprovalResponse, InferToolInput, InferToolOutput, Schema, FlexibleSchema, InferSchema, } from "./aiCompat.js";
|
|
14
14
|
/**
|
|
15
15
|
* Commonly used Zod schema type aliases for cleaner type declarations
|
|
16
16
|
*/
|