@browser-ai/core 1.0.0 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +32 -379
- package/dist/index.d.mts +41 -70
- package/dist/index.d.ts +41 -70
- package/dist/index.js +98 -62
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +93 -56
- package/dist/index.mjs.map +1 -1
- package/package.json +72 -72
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { LanguageModelV3, LanguageModelV3CallOptions, LanguageModelV3GenerateResult, LanguageModelV3StreamResult, EmbeddingModelV3, EmbeddingModelV3CallOptions, EmbeddingModelV3Result, ProviderV3 } from '@ai-sdk/provider';
|
|
2
2
|
import { TextEmbedder } from '@mediapipe/tasks-text';
|
|
3
3
|
import { UIMessage } from 'ai';
|
|
4
4
|
|
|
5
|
-
type
|
|
6
|
-
interface
|
|
5
|
+
type BrowserAIChatModelId = "text";
|
|
6
|
+
interface BrowserAIChatSettings extends LanguageModelCreateOptions {
|
|
7
7
|
/**
|
|
8
8
|
* Expected input types for the session, for multimodal inputs.
|
|
9
9
|
*/
|
|
@@ -11,25 +11,25 @@ interface BuiltInAIChatSettings extends LanguageModelCreateOptions {
|
|
|
11
11
|
type: "text" | "image" | "audio";
|
|
12
12
|
languages?: string[];
|
|
13
13
|
}>;
|
|
14
|
+
/**
|
|
15
|
+
* Callback invoked when the model quota is exceeded.
|
|
16
|
+
* @see [Prompt API Quota Overflow](https://github.com/webmachinelearning/prompt-api?tab=readme-ov-file#tokenization-context-window-length-limits-and-overflow)
|
|
17
|
+
* @param event
|
|
18
|
+
*/
|
|
19
|
+
onQuotaOverflow?: (event: Event) => void;
|
|
14
20
|
}
|
|
15
21
|
/**
|
|
16
|
-
* Check if the browser supports the
|
|
17
|
-
* @returns true if the browser supports the
|
|
18
|
-
*/
|
|
19
|
-
declare function doesBrowserSupportBuiltInAI(): boolean;
|
|
20
|
-
/**
|
|
21
|
-
* Check if the Prompt API is available
|
|
22
|
-
* @deprecated Use `doesBrowserSupportBuiltInAI()` instead for clearer naming
|
|
23
|
-
* @returns true if the browser supports the built-in AI API, false otherwise
|
|
22
|
+
* Check if the browser supports the browser AI API
|
|
23
|
+
* @returns true if the browser supports the browser AI API, false otherwise
|
|
24
24
|
*/
|
|
25
|
-
declare function
|
|
26
|
-
declare class
|
|
27
|
-
readonly specificationVersion = "
|
|
28
|
-
readonly modelId:
|
|
25
|
+
declare function doesBrowserSupportBrowserAI(): boolean;
|
|
26
|
+
declare class BrowserAIChatLanguageModel implements LanguageModelV3 {
|
|
27
|
+
readonly specificationVersion = "v3";
|
|
28
|
+
readonly modelId: BrowserAIChatModelId;
|
|
29
29
|
readonly provider = "browser-ai";
|
|
30
30
|
private readonly config;
|
|
31
31
|
private readonly sessionManager;
|
|
32
|
-
constructor(modelId:
|
|
32
|
+
constructor(modelId: BrowserAIChatModelId, options?: BrowserAIChatSettings);
|
|
33
33
|
readonly supportedUrls: Record<string, RegExp[]>;
|
|
34
34
|
/**
|
|
35
35
|
* Gets a session with the specified options
|
|
@@ -45,24 +45,9 @@ declare class BuiltInAIChatLanguageModel implements LanguageModelV2 {
|
|
|
45
45
|
* @throws {LoadSettingError} When the Prompt API is not available or model needs to be downloaded
|
|
46
46
|
* @throws {UnsupportedFunctionalityError} When unsupported features like file input are used
|
|
47
47
|
*/
|
|
48
|
-
doGenerate(options:
|
|
49
|
-
content: LanguageModelV2Content[];
|
|
50
|
-
finishReason: LanguageModelV2FinishReason;
|
|
51
|
-
usage: {
|
|
52
|
-
inputTokens: undefined;
|
|
53
|
-
outputTokens: undefined;
|
|
54
|
-
totalTokens: undefined;
|
|
55
|
-
};
|
|
56
|
-
request: {
|
|
57
|
-
body: {
|
|
58
|
-
messages: LanguageModelMessage[];
|
|
59
|
-
options: LanguageModelPromptOptions & LanguageModelCreateCoreOptions;
|
|
60
|
-
};
|
|
61
|
-
};
|
|
62
|
-
warnings: LanguageModelV2CallWarning[];
|
|
63
|
-
}>;
|
|
48
|
+
doGenerate(options: LanguageModelV3CallOptions): Promise<LanguageModelV3GenerateResult>;
|
|
64
49
|
/**
|
|
65
|
-
* Check the availability of the
|
|
50
|
+
* Check the availability of the browser AI model
|
|
66
51
|
* @returns Promise resolving to "unavailable", "available", or "available-after-download"
|
|
67
52
|
*/
|
|
68
53
|
availability(): Promise<Availability>;
|
|
@@ -90,18 +75,10 @@ declare class BuiltInAIChatLanguageModel implements LanguageModelV2 {
|
|
|
90
75
|
* @throws {LoadSettingError} When the Prompt API is not available or model needs to be downloaded
|
|
91
76
|
* @throws {UnsupportedFunctionalityError} When unsupported features like file input are used
|
|
92
77
|
*/
|
|
93
|
-
doStream(options:
|
|
94
|
-
stream: ReadableStream<LanguageModelV2StreamPart>;
|
|
95
|
-
request: {
|
|
96
|
-
body: {
|
|
97
|
-
messages: LanguageModelMessage[];
|
|
98
|
-
options: LanguageModelPromptOptions & LanguageModelCreateCoreOptions;
|
|
99
|
-
};
|
|
100
|
-
};
|
|
101
|
-
}>;
|
|
78
|
+
doStream(options: LanguageModelV3CallOptions): Promise<LanguageModelV3StreamResult>;
|
|
102
79
|
}
|
|
103
80
|
|
|
104
|
-
interface
|
|
81
|
+
interface BrowserAIEmbeddingModelSettings {
|
|
105
82
|
/**
|
|
106
83
|
* An optional base path to specify the directory the Wasm files should be loaded from.
|
|
107
84
|
* @default 'https://pub-ddcfe353995744e89b8002f16bf98575.r2.dev/text_wasm_internal.js'
|
|
@@ -139,8 +116,8 @@ interface BuiltInAIEmbeddingModelSettings {
|
|
|
139
116
|
*/
|
|
140
117
|
delegate?: "CPU" | "GPU";
|
|
141
118
|
}
|
|
142
|
-
declare class
|
|
143
|
-
readonly specificationVersion = "
|
|
119
|
+
declare class BrowserAIEmbeddingModel implements EmbeddingModelV3 {
|
|
120
|
+
readonly specificationVersion = "v3";
|
|
144
121
|
readonly provider = "google-mediapipe";
|
|
145
122
|
readonly modelId: string;
|
|
146
123
|
readonly supportsParallelCalls = true;
|
|
@@ -148,57 +125,51 @@ declare class BuiltInAIEmbeddingModel implements EmbeddingModelV2<string> {
|
|
|
148
125
|
private settings;
|
|
149
126
|
private modelAssetBuffer;
|
|
150
127
|
private textEmbedder;
|
|
151
|
-
constructor(settings?:
|
|
128
|
+
constructor(settings?: BrowserAIEmbeddingModelSettings);
|
|
152
129
|
protected getTextEmbedder: () => Promise<TextEmbedder>;
|
|
153
|
-
doEmbed: (options:
|
|
154
|
-
values: string[];
|
|
155
|
-
abortSignal?: AbortSignal;
|
|
156
|
-
}) => Promise<{
|
|
157
|
-
embeddings: Array<EmbeddingModelV2Embedding>;
|
|
158
|
-
rawResponse?: Record<PropertyKey, any>;
|
|
159
|
-
}>;
|
|
130
|
+
doEmbed: (options: EmbeddingModelV3CallOptions) => Promise<EmbeddingModelV3Result>;
|
|
160
131
|
}
|
|
161
132
|
|
|
162
|
-
interface
|
|
163
|
-
(modelId?:
|
|
133
|
+
interface BrowserAIProvider extends ProviderV3 {
|
|
134
|
+
(modelId?: BrowserAIChatModelId, settings?: BrowserAIChatSettings): BrowserAIChatLanguageModel;
|
|
164
135
|
/**
|
|
165
136
|
* Creates a model for text generation.
|
|
166
137
|
*/
|
|
167
|
-
languageModel(modelId:
|
|
138
|
+
languageModel(modelId: BrowserAIChatModelId, settings?: BrowserAIChatSettings): BrowserAIChatLanguageModel;
|
|
168
139
|
/**
|
|
169
140
|
* Creates a model for text generation.
|
|
170
141
|
*/
|
|
171
|
-
chat(modelId:
|
|
172
|
-
|
|
173
|
-
|
|
142
|
+
chat(modelId: BrowserAIChatModelId, settings?: BrowserAIChatSettings): BrowserAIChatLanguageModel;
|
|
143
|
+
embedding(modelId: "embedding", settings?: BrowserAIEmbeddingModelSettings): EmbeddingModelV3;
|
|
144
|
+
embeddingModel: (modelId: "embedding", settings?: BrowserAIEmbeddingModelSettings) => EmbeddingModelV3;
|
|
174
145
|
imageModel(modelId: string): never;
|
|
175
146
|
speechModel(modelId: string): never;
|
|
176
147
|
transcriptionModel(modelId: string): never;
|
|
177
148
|
}
|
|
178
|
-
interface
|
|
149
|
+
interface BrowserAIProviderSettings {
|
|
179
150
|
}
|
|
180
151
|
/**
|
|
181
|
-
* Create a
|
|
152
|
+
* Create a BrowserAI provider instance.
|
|
182
153
|
*/
|
|
183
|
-
declare function
|
|
154
|
+
declare function createBrowserAI(options?: BrowserAIProviderSettings): BrowserAIProvider;
|
|
184
155
|
/**
|
|
185
|
-
* Default
|
|
156
|
+
* Default BrowserAI provider instance.
|
|
186
157
|
*/
|
|
187
|
-
declare const
|
|
158
|
+
declare const browserAI: BrowserAIProvider;
|
|
188
159
|
|
|
189
160
|
/**
|
|
190
|
-
* UI message type for
|
|
161
|
+
* UI message type for browser AI features with custom data parts.
|
|
191
162
|
*
|
|
192
163
|
* Extends base UIMessage to include specific data part schemas
|
|
193
|
-
* for
|
|
164
|
+
* for browser AI functionality such as model download progress tracking
|
|
194
165
|
*
|
|
195
166
|
* @example
|
|
196
167
|
* // Import and use with useChat hook from @ai-sdk/react
|
|
197
168
|
* ```typescript
|
|
198
169
|
* import { useChat } from "@ai-sdk/react";
|
|
199
|
-
* import {
|
|
170
|
+
* import { BrowserAIUIMessage } from "@browser-ai/core";
|
|
200
171
|
*
|
|
201
|
-
* const { messages, sendMessage } = useChat<
|
|
172
|
+
* const { messages, sendMessage } = useChat<BrowserAIUIMessage>({
|
|
202
173
|
* onData: (dataPart) => {
|
|
203
174
|
* if (dataPart.type === 'data-modelDownloadProgress') {
|
|
204
175
|
* console.log(`Download: ${dataPart.data.progress}%`);
|
|
@@ -212,7 +183,7 @@ declare const builtInAI: BuiltInAIProvider;
|
|
|
212
183
|
*
|
|
213
184
|
* @see {@link https://v5.ai-sdk.dev/docs/reference/ai-sdk-ui/use-chat | useChat hook documentation}
|
|
214
185
|
*/
|
|
215
|
-
type
|
|
186
|
+
type BrowserAIUIMessage = UIMessage<
|
|
216
187
|
never, // No custom metadata type
|
|
217
188
|
{
|
|
218
189
|
/**
|
|
@@ -240,4 +211,4 @@ type BuiltInAIUIMessage = UIMessage<
|
|
|
240
211
|
}
|
|
241
212
|
>;
|
|
242
213
|
|
|
243
|
-
export {
|
|
214
|
+
export { BrowserAIChatLanguageModel, type BrowserAIChatSettings, BrowserAIEmbeddingModel, type BrowserAIEmbeddingModelSettings, type BrowserAIProvider, type BrowserAIProviderSettings, type BrowserAIUIMessage, browserAI, createBrowserAI, doesBrowserSupportBrowserAI };
|
package/dist/index.js
CHANGED
|
@@ -20,16 +20,15 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/index.ts
|
|
21
21
|
var index_exports = {};
|
|
22
22
|
__export(index_exports, {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
isBuiltInAIModelAvailable: () => isBuiltInAIModelAvailable
|
|
23
|
+
BrowserAIChatLanguageModel: () => BrowserAIChatLanguageModel,
|
|
24
|
+
BrowserAIEmbeddingModel: () => BrowserAIEmbeddingModel,
|
|
25
|
+
browserAI: () => browserAI,
|
|
26
|
+
createBrowserAI: () => createBrowserAI,
|
|
27
|
+
doesBrowserSupportBrowserAI: () => doesBrowserSupportBrowserAI
|
|
29
28
|
});
|
|
30
29
|
module.exports = __toCommonJS(index_exports);
|
|
31
30
|
|
|
32
|
-
// src/convert-to-
|
|
31
|
+
// src/convert-to-browser-ai-messages.ts
|
|
33
32
|
var import_provider = require("@ai-sdk/provider");
|
|
34
33
|
|
|
35
34
|
// src/tool-calling/format-tool-results.ts
|
|
@@ -56,7 +55,7 @@ ${payloads.join("\n")}
|
|
|
56
55
|
\`\`\``;
|
|
57
56
|
}
|
|
58
57
|
|
|
59
|
-
// src/convert-to-
|
|
58
|
+
// src/convert-to-browser-ai-messages.ts
|
|
60
59
|
function convertBase64ToUint8Array(base64) {
|
|
61
60
|
try {
|
|
62
61
|
const binaryString = atob(base64);
|
|
@@ -125,6 +124,8 @@ function convertToolResultOutput(output) {
|
|
|
125
124
|
return { value: output.value, isError: true };
|
|
126
125
|
case "content":
|
|
127
126
|
return { value: output.value, isError: false };
|
|
127
|
+
case "execution-denied":
|
|
128
|
+
return { value: output.reason, isError: true };
|
|
128
129
|
default: {
|
|
129
130
|
const exhaustiveCheck = output;
|
|
130
131
|
return { value: exhaustiveCheck, isError: false };
|
|
@@ -140,7 +141,7 @@ function toToolResult(part) {
|
|
|
140
141
|
isError
|
|
141
142
|
};
|
|
142
143
|
}
|
|
143
|
-
function
|
|
144
|
+
function convertToBrowserAIMessages(prompt) {
|
|
144
145
|
const normalizedPrompt = prompt.slice();
|
|
145
146
|
let systemMessage;
|
|
146
147
|
const messages = [];
|
|
@@ -376,17 +377,17 @@ function parseJsonFunctionCalls(response) {
|
|
|
376
377
|
}
|
|
377
378
|
|
|
378
379
|
// src/utils/warnings.ts
|
|
379
|
-
function createUnsupportedSettingWarning(
|
|
380
|
+
function createUnsupportedSettingWarning(feature, details) {
|
|
380
381
|
return {
|
|
381
|
-
type: "unsupported
|
|
382
|
-
|
|
382
|
+
type: "unsupported",
|
|
383
|
+
feature,
|
|
383
384
|
details
|
|
384
385
|
};
|
|
385
386
|
}
|
|
386
387
|
function createUnsupportedToolWarning(tool, details) {
|
|
387
388
|
return {
|
|
388
|
-
type: "unsupported
|
|
389
|
-
tool
|
|
389
|
+
type: "unsupported",
|
|
390
|
+
feature: `tool:${tool.name}`,
|
|
390
391
|
details
|
|
391
392
|
};
|
|
392
393
|
}
|
|
@@ -558,7 +559,7 @@ var SessionManager = class {
|
|
|
558
559
|
async getSession(options) {
|
|
559
560
|
if (typeof LanguageModel === "undefined") {
|
|
560
561
|
throw new import_provider2.LoadSettingError({
|
|
561
|
-
message: "Prompt API is not available. This library requires Chrome or Edge browser with
|
|
562
|
+
message: "Prompt API is not available. This library requires Chrome or Edge browser with browser AI capabilities."
|
|
562
563
|
});
|
|
563
564
|
}
|
|
564
565
|
if (this.session) {
|
|
@@ -572,6 +573,16 @@ var SessionManager = class {
|
|
|
572
573
|
}
|
|
573
574
|
const sessionOptions = this.prepareSessionOptions(options);
|
|
574
575
|
this.session = await LanguageModel.create(sessionOptions);
|
|
576
|
+
const onQuotaOverflow = options?.onQuotaOverflow || this.baseOptions.onQuotaOverflow;
|
|
577
|
+
if (onQuotaOverflow) {
|
|
578
|
+
this.session.addEventListener("quotaoverflow", onQuotaOverflow);
|
|
579
|
+
} else {
|
|
580
|
+
this.session.addEventListener("quotaoverflow", () => {
|
|
581
|
+
console.warn(
|
|
582
|
+
"Model quota exceeded. Consider handling 'quotaoverflow' event."
|
|
583
|
+
);
|
|
584
|
+
});
|
|
585
|
+
}
|
|
575
586
|
return this.session;
|
|
576
587
|
}
|
|
577
588
|
/**
|
|
@@ -596,7 +607,7 @@ var SessionManager = class {
|
|
|
596
607
|
return this.getSession({ onDownloadProgress });
|
|
597
608
|
}
|
|
598
609
|
/**
|
|
599
|
-
* Checks the availability status of the
|
|
610
|
+
* Checks the availability status of the browser AI model
|
|
600
611
|
*
|
|
601
612
|
* @returns Promise resolving to availability status
|
|
602
613
|
* - "unavailable": Model is not supported
|
|
@@ -652,6 +663,7 @@ var SessionManager = class {
|
|
|
652
663
|
systemMessage,
|
|
653
664
|
expectedInputs,
|
|
654
665
|
onDownloadProgress,
|
|
666
|
+
onQuotaOverflow,
|
|
655
667
|
...createOptions
|
|
656
668
|
} = options;
|
|
657
669
|
Object.assign(mergedOptions, createOptions);
|
|
@@ -936,11 +948,8 @@ ${this.FENCE_END}`;
|
|
|
936
948
|
}
|
|
937
949
|
};
|
|
938
950
|
|
|
939
|
-
// src/
|
|
940
|
-
function
|
|
941
|
-
return typeof LanguageModel !== "undefined";
|
|
942
|
-
}
|
|
943
|
-
function isBuiltInAIModelAvailable() {
|
|
951
|
+
// src/browser-ai-language-model.ts
|
|
952
|
+
function doesBrowserSupportBrowserAI() {
|
|
944
953
|
return typeof LanguageModel !== "undefined";
|
|
945
954
|
}
|
|
946
955
|
function extractToolName(content) {
|
|
@@ -1000,9 +1009,9 @@ function extractArgumentsContent(content) {
|
|
|
1000
1009
|
}
|
|
1001
1010
|
return result;
|
|
1002
1011
|
}
|
|
1003
|
-
var
|
|
1012
|
+
var BrowserAIChatLanguageModel = class {
|
|
1004
1013
|
constructor(modelId, options = {}) {
|
|
1005
|
-
this.specificationVersion = "
|
|
1014
|
+
this.specificationVersion = "v3";
|
|
1006
1015
|
this.provider = "browser-ai";
|
|
1007
1016
|
this.supportedUrls = {
|
|
1008
1017
|
"image/*": [/^https?:\/\/.+$/],
|
|
@@ -1070,7 +1079,7 @@ var BuiltInAIChatLanguageModel = class {
|
|
|
1070
1079
|
);
|
|
1071
1080
|
}
|
|
1072
1081
|
const hasMultiModalInput = hasMultimodalContent(prompt);
|
|
1073
|
-
const { systemMessage, messages } =
|
|
1082
|
+
const { systemMessage, messages } = convertToBrowserAIMessages(prompt);
|
|
1074
1083
|
const promptOptions = {};
|
|
1075
1084
|
if (responseFormat?.type === "json") {
|
|
1076
1085
|
promptOptions.responseConstraint = responseFormat.schema;
|
|
@@ -1141,11 +1150,19 @@ var BuiltInAIChatLanguageModel = class {
|
|
|
1141
1150
|
}
|
|
1142
1151
|
return {
|
|
1143
1152
|
content: parts,
|
|
1144
|
-
finishReason: "tool-calls",
|
|
1153
|
+
finishReason: { unified: "tool-calls", raw: "tool-calls" },
|
|
1145
1154
|
usage: {
|
|
1146
|
-
inputTokens:
|
|
1147
|
-
|
|
1148
|
-
|
|
1155
|
+
inputTokens: {
|
|
1156
|
+
total: void 0,
|
|
1157
|
+
noCache: void 0,
|
|
1158
|
+
cacheRead: void 0,
|
|
1159
|
+
cacheWrite: void 0
|
|
1160
|
+
},
|
|
1161
|
+
outputTokens: {
|
|
1162
|
+
total: void 0,
|
|
1163
|
+
text: void 0,
|
|
1164
|
+
reasoning: void 0
|
|
1165
|
+
}
|
|
1149
1166
|
},
|
|
1150
1167
|
request: { body: { messages: promptMessages, options: promptOptions } },
|
|
1151
1168
|
warnings
|
|
@@ -1159,18 +1176,26 @@ var BuiltInAIChatLanguageModel = class {
|
|
|
1159
1176
|
];
|
|
1160
1177
|
return {
|
|
1161
1178
|
content,
|
|
1162
|
-
finishReason: "stop",
|
|
1179
|
+
finishReason: { unified: "stop", raw: "stop" },
|
|
1163
1180
|
usage: {
|
|
1164
|
-
inputTokens:
|
|
1165
|
-
|
|
1166
|
-
|
|
1181
|
+
inputTokens: {
|
|
1182
|
+
total: void 0,
|
|
1183
|
+
noCache: void 0,
|
|
1184
|
+
cacheRead: void 0,
|
|
1185
|
+
cacheWrite: void 0
|
|
1186
|
+
},
|
|
1187
|
+
outputTokens: {
|
|
1188
|
+
total: void 0,
|
|
1189
|
+
text: void 0,
|
|
1190
|
+
reasoning: void 0
|
|
1191
|
+
}
|
|
1167
1192
|
},
|
|
1168
1193
|
request: { body: { messages: promptMessages, options: promptOptions } },
|
|
1169
1194
|
warnings
|
|
1170
1195
|
};
|
|
1171
1196
|
}
|
|
1172
1197
|
/**
|
|
1173
|
-
* Check the availability of the
|
|
1198
|
+
* Check the availability of the browser AI model
|
|
1174
1199
|
* @returns Promise resolving to "unavailable", "available", or "available-after-download"
|
|
1175
1200
|
*/
|
|
1176
1201
|
async availability() {
|
|
@@ -1274,9 +1299,17 @@ var BuiltInAIChatLanguageModel = class {
|
|
|
1274
1299
|
type: "finish",
|
|
1275
1300
|
finishReason,
|
|
1276
1301
|
usage: {
|
|
1277
|
-
inputTokens:
|
|
1278
|
-
|
|
1279
|
-
|
|
1302
|
+
inputTokens: {
|
|
1303
|
+
total: session.inputUsage,
|
|
1304
|
+
noCache: void 0,
|
|
1305
|
+
cacheRead: void 0,
|
|
1306
|
+
cacheWrite: void 0
|
|
1307
|
+
},
|
|
1308
|
+
outputTokens: {
|
|
1309
|
+
total: void 0,
|
|
1310
|
+
text: void 0,
|
|
1311
|
+
reasoning: void 0
|
|
1312
|
+
}
|
|
1280
1313
|
}
|
|
1281
1314
|
});
|
|
1282
1315
|
controller.close();
|
|
@@ -1289,7 +1322,7 @@ var BuiltInAIChatLanguageModel = class {
|
|
|
1289
1322
|
if (currentReader) {
|
|
1290
1323
|
currentReader.cancel().catch(() => void 0);
|
|
1291
1324
|
}
|
|
1292
|
-
finishStream("stop");
|
|
1325
|
+
finishStream({ unified: "stop", raw: "aborted" });
|
|
1293
1326
|
};
|
|
1294
1327
|
if (options.abortSignal) {
|
|
1295
1328
|
options.abortSignal.addEventListener("abort", abortHandler);
|
|
@@ -1502,17 +1535,17 @@ var BuiltInAIChatLanguageModel = class {
|
|
|
1502
1535
|
fenceDetector.clearBuffer();
|
|
1503
1536
|
}
|
|
1504
1537
|
if (!toolBlockDetected || toolCalls.length === 0) {
|
|
1505
|
-
finishStream("stop");
|
|
1538
|
+
finishStream({ unified: "stop", raw: "stop" });
|
|
1506
1539
|
return;
|
|
1507
1540
|
}
|
|
1508
1541
|
if (trailingTextAfterBlock) {
|
|
1509
1542
|
emitTextDelta(trailingTextAfterBlock);
|
|
1510
1543
|
}
|
|
1511
|
-
finishStream("tool-calls");
|
|
1544
|
+
finishStream({ unified: "tool-calls", raw: "tool-calls" });
|
|
1512
1545
|
return;
|
|
1513
1546
|
}
|
|
1514
1547
|
if (!finished && !aborted) {
|
|
1515
|
-
finishStream("other");
|
|
1548
|
+
finishStream({ unified: "other", raw: "other" });
|
|
1516
1549
|
}
|
|
1517
1550
|
} catch (error) {
|
|
1518
1551
|
controller.enqueue({ type: "error", error });
|
|
@@ -1531,11 +1564,11 @@ var BuiltInAIChatLanguageModel = class {
|
|
|
1531
1564
|
}
|
|
1532
1565
|
};
|
|
1533
1566
|
|
|
1534
|
-
// src/
|
|
1567
|
+
// src/browser-ai-embedding-model.ts
|
|
1535
1568
|
var import_tasks_text = require("@mediapipe/tasks-text");
|
|
1536
|
-
var
|
|
1569
|
+
var BrowserAIEmbeddingModel = class {
|
|
1537
1570
|
constructor(settings = {}) {
|
|
1538
|
-
this.specificationVersion = "
|
|
1571
|
+
this.specificationVersion = "v3";
|
|
1539
1572
|
this.provider = "google-mediapipe";
|
|
1540
1573
|
this.modelId = "embedding";
|
|
1541
1574
|
this.supportsParallelCalls = true;
|
|
@@ -1575,11 +1608,14 @@ var BuiltInAIEmbeddingModel = class {
|
|
|
1575
1608
|
});
|
|
1576
1609
|
return {
|
|
1577
1610
|
embeddings,
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1611
|
+
providerMetadata: {
|
|
1612
|
+
mediapipe: {
|
|
1613
|
+
model: "universal_sentence_encoder",
|
|
1614
|
+
provider: "google-mediapipe",
|
|
1615
|
+
processed_texts: options.values.length
|
|
1616
|
+
}
|
|
1617
|
+
},
|
|
1618
|
+
warnings: []
|
|
1583
1619
|
};
|
|
1584
1620
|
};
|
|
1585
1621
|
this.settings = { ...this.settings, ...settings };
|
|
@@ -1590,27 +1626,28 @@ var BuiltInAIEmbeddingModel = class {
|
|
|
1590
1626
|
}
|
|
1591
1627
|
};
|
|
1592
1628
|
|
|
1593
|
-
// src/
|
|
1629
|
+
// src/browser-ai-provider.ts
|
|
1594
1630
|
var import_provider3 = require("@ai-sdk/provider");
|
|
1595
|
-
function
|
|
1631
|
+
function createBrowserAI(options = {}) {
|
|
1596
1632
|
const createChatModel = (modelId, settings) => {
|
|
1597
|
-
return new
|
|
1633
|
+
return new BrowserAIChatLanguageModel(modelId, settings);
|
|
1598
1634
|
};
|
|
1599
1635
|
const createEmbeddingModel = (modelId, settings) => {
|
|
1600
|
-
return new
|
|
1636
|
+
return new BrowserAIEmbeddingModel(settings);
|
|
1601
1637
|
};
|
|
1602
1638
|
const provider = function(modelId = "text", settings) {
|
|
1603
1639
|
if (new.target) {
|
|
1604
1640
|
throw new Error(
|
|
1605
|
-
"The
|
|
1641
|
+
"The BrowserAI model function cannot be called with the new keyword."
|
|
1606
1642
|
);
|
|
1607
1643
|
}
|
|
1608
1644
|
return createChatModel(modelId, settings);
|
|
1609
1645
|
};
|
|
1646
|
+
provider.specificationVersion = "v3";
|
|
1610
1647
|
provider.languageModel = createChatModel;
|
|
1611
1648
|
provider.chat = createChatModel;
|
|
1612
|
-
provider.
|
|
1613
|
-
provider.
|
|
1649
|
+
provider.embedding = createEmbeddingModel;
|
|
1650
|
+
provider.embeddingModel = createEmbeddingModel;
|
|
1614
1651
|
provider.imageModel = (modelId) => {
|
|
1615
1652
|
throw new import_provider3.NoSuchModelError({ modelId, modelType: "imageModel" });
|
|
1616
1653
|
};
|
|
@@ -1622,14 +1659,13 @@ function createBuiltInAI(options = {}) {
|
|
|
1622
1659
|
};
|
|
1623
1660
|
return provider;
|
|
1624
1661
|
}
|
|
1625
|
-
var
|
|
1662
|
+
var browserAI = createBrowserAI();
|
|
1626
1663
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1627
1664
|
0 && (module.exports = {
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
isBuiltInAIModelAvailable
|
|
1665
|
+
BrowserAIChatLanguageModel,
|
|
1666
|
+
BrowserAIEmbeddingModel,
|
|
1667
|
+
browserAI,
|
|
1668
|
+
createBrowserAI,
|
|
1669
|
+
doesBrowserSupportBrowserAI
|
|
1634
1670
|
});
|
|
1635
1671
|
//# sourceMappingURL=index.js.map
|