@workglow/ai-provider 0.0.115 → 0.0.117
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/{HFT_JobRunFns-zkv5fx65.js → HFT_JobRunFns-yx418d60.js} +7 -3
- package/dist/{HFT_JobRunFns-zkv5fx65.js.map → HFT_JobRunFns-yx418d60.js.map} +1 -1
- package/dist/anthropic/common/Anthropic_JobRunFns.d.ts.map +1 -1
- package/dist/anthropic/index.js +97 -17
- package/dist/anthropic/index.js.map +3 -3
- package/dist/google-gemini/common/Gemini_JobRunFns.d.ts.map +1 -1
- package/dist/google-gemini/index.js +106 -16
- package/dist/google-gemini/index.js.map +3 -3
- package/dist/hf-transformers/common/HFT_JobRunFns.d.ts +78 -3
- package/dist/hf-transformers/common/HFT_JobRunFns.d.ts.map +1 -1
- package/dist/hf-transformers/index.js +11 -7
- package/dist/hf-transformers/index.js.map +2 -2
- package/dist/index-m0r2hvfz.js +57 -0
- package/dist/index-m0r2hvfz.js.map +10 -0
- package/dist/{index-zqq3kw0n.js → index-qett8dfp.js} +58 -55
- package/dist/index-qett8dfp.js.map +11 -0
- package/dist/{index-8at2wpp1.js → index-tvb9nd5b.js} +128 -44
- package/dist/index-tvb9nd5b.js.map +10 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +105 -6
- package/dist/index.js.map +7 -4
- package/dist/provider-hf-inference/common/HFI_JobRunFns.d.ts.map +1 -1
- package/dist/provider-hf-inference/index.js +15 -25
- package/dist/provider-hf-inference/index.js.map +3 -3
- package/dist/provider-llamacpp/common/LlamaCpp_JobRunFns.d.ts +3 -1
- package/dist/provider-llamacpp/common/LlamaCpp_JobRunFns.d.ts.map +1 -1
- package/dist/provider-llamacpp/index.js +158 -14
- package/dist/provider-llamacpp/index.js.map +3 -3
- package/dist/provider-ollama/common/Ollama_JobRunFns.browser.d.ts.map +1 -1
- package/dist/provider-ollama/common/Ollama_JobRunFns.d.ts.map +1 -1
- package/dist/provider-ollama/index.browser.js +6 -6
- package/dist/provider-ollama/index.browser.js.map +3 -3
- package/dist/provider-ollama/index.js +14 -21
- package/dist/provider-ollama/index.js.map +3 -3
- package/dist/provider-openai/common/OpenAI_JobRunFns.d.ts +0 -6
- package/dist/provider-openai/common/OpenAI_JobRunFns.d.ts.map +1 -1
- package/dist/provider-openai/index.js +20 -34
- package/dist/provider-openai/index.js.map +3 -3
- package/dist/web-browser/WebBrowserProvider.d.ts +40 -0
- package/dist/web-browser/WebBrowserProvider.d.ts.map +1 -0
- package/dist/web-browser/WebBrowser_Worker.d.ts +7 -0
- package/dist/web-browser/WebBrowser_Worker.d.ts.map +1 -0
- package/dist/web-browser/common/WebBrowser_Constants.d.ts +15 -0
- package/dist/web-browser/common/WebBrowser_Constants.d.ts.map +1 -0
- package/dist/web-browser/common/WebBrowser_JobRunFns.d.ts +20 -0
- package/dist/web-browser/common/WebBrowser_JobRunFns.d.ts.map +1 -0
- package/dist/web-browser/common/WebBrowser_ModelSchema.d.ts +185 -0
- package/dist/web-browser/common/WebBrowser_ModelSchema.d.ts.map +1 -0
- package/dist/web-browser/index.d.ts +11 -0
- package/dist/web-browser/index.d.ts.map +1 -0
- package/dist/web-browser/index.js +457 -0
- package/dist/web-browser/index.js.map +14 -0
- package/package.json +23 -19
- package/dist/index-8at2wpp1.js.map +0 -10
- package/dist/index-dvb390cv.js +0 -58
- package/dist/index-dvb390cv.js.map +0 -10
- package/dist/index-zqq3kw0n.js.map +0 -11
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Steven Roussey <sroussey@gmail.com>
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import { FromSchema } from "@workglow/util";
|
|
7
|
+
export declare const WebBrowserModelSchema: {
|
|
8
|
+
readonly type: "object";
|
|
9
|
+
readonly properties: {
|
|
10
|
+
readonly provider: {
|
|
11
|
+
readonly const: "WEB_BROWSER";
|
|
12
|
+
readonly description: "Discriminator: Chrome Built-in AI (Gemini Nano).";
|
|
13
|
+
};
|
|
14
|
+
readonly provider_config: {
|
|
15
|
+
readonly type: "object";
|
|
16
|
+
readonly description: "Chrome Built-in AI configuration.";
|
|
17
|
+
readonly properties: {
|
|
18
|
+
readonly summary_type: {
|
|
19
|
+
readonly type: "string";
|
|
20
|
+
readonly enum: readonly ["tl;dr", "key-points", "teaser", "headline"];
|
|
21
|
+
readonly description: "Summarization style (Summarizer API only).";
|
|
22
|
+
};
|
|
23
|
+
readonly summary_length: {
|
|
24
|
+
readonly type: "string";
|
|
25
|
+
readonly enum: readonly ["short", "medium", "long"];
|
|
26
|
+
readonly description: "Desired summary length (Summarizer API only).";
|
|
27
|
+
};
|
|
28
|
+
readonly summary_format: {
|
|
29
|
+
readonly type: "string";
|
|
30
|
+
readonly enum: readonly ["plain-text", "markdown"];
|
|
31
|
+
readonly description: "Output format for summaries (Summarizer API only).";
|
|
32
|
+
};
|
|
33
|
+
readonly rewriter_tone: {
|
|
34
|
+
readonly type: "string";
|
|
35
|
+
readonly enum: readonly ["as-is", "more-formal", "more-casual"];
|
|
36
|
+
readonly description: "Tone for rewriting (Rewriter API only).";
|
|
37
|
+
};
|
|
38
|
+
readonly rewriter_length: {
|
|
39
|
+
readonly type: "string";
|
|
40
|
+
readonly enum: readonly ["as-is", "shorter", "longer"];
|
|
41
|
+
readonly description: "Length adjustment for rewriting (Rewriter API only).";
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
readonly required: readonly [];
|
|
45
|
+
readonly additionalProperties: false;
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
readonly required: readonly ["provider", "provider_config"];
|
|
49
|
+
readonly additionalProperties: true;
|
|
50
|
+
};
|
|
51
|
+
export declare const WebBrowserModelRecordSchema: {
|
|
52
|
+
readonly type: "object";
|
|
53
|
+
readonly properties: {
|
|
54
|
+
readonly provider: {
|
|
55
|
+
readonly const: "WEB_BROWSER";
|
|
56
|
+
readonly description: "Discriminator: Chrome Built-in AI (Gemini Nano).";
|
|
57
|
+
};
|
|
58
|
+
readonly provider_config: {
|
|
59
|
+
readonly type: "object";
|
|
60
|
+
readonly description: "Chrome Built-in AI configuration.";
|
|
61
|
+
readonly properties: {
|
|
62
|
+
readonly summary_type: {
|
|
63
|
+
readonly type: "string";
|
|
64
|
+
readonly enum: readonly ["tl;dr", "key-points", "teaser", "headline"];
|
|
65
|
+
readonly description: "Summarization style (Summarizer API only).";
|
|
66
|
+
};
|
|
67
|
+
readonly summary_length: {
|
|
68
|
+
readonly type: "string";
|
|
69
|
+
readonly enum: readonly ["short", "medium", "long"];
|
|
70
|
+
readonly description: "Desired summary length (Summarizer API only).";
|
|
71
|
+
};
|
|
72
|
+
readonly summary_format: {
|
|
73
|
+
readonly type: "string";
|
|
74
|
+
readonly enum: readonly ["plain-text", "markdown"];
|
|
75
|
+
readonly description: "Output format for summaries (Summarizer API only).";
|
|
76
|
+
};
|
|
77
|
+
readonly rewriter_tone: {
|
|
78
|
+
readonly type: "string";
|
|
79
|
+
readonly enum: readonly ["as-is", "more-formal", "more-casual"];
|
|
80
|
+
readonly description: "Tone for rewriting (Rewriter API only).";
|
|
81
|
+
};
|
|
82
|
+
readonly rewriter_length: {
|
|
83
|
+
readonly type: "string";
|
|
84
|
+
readonly enum: readonly ["as-is", "shorter", "longer"];
|
|
85
|
+
readonly description: "Length adjustment for rewriting (Rewriter API only).";
|
|
86
|
+
};
|
|
87
|
+
};
|
|
88
|
+
readonly required: readonly [];
|
|
89
|
+
readonly additionalProperties: false;
|
|
90
|
+
};
|
|
91
|
+
readonly model_id: {
|
|
92
|
+
readonly type: "string";
|
|
93
|
+
};
|
|
94
|
+
readonly tasks: {
|
|
95
|
+
readonly type: "array";
|
|
96
|
+
readonly items: {
|
|
97
|
+
readonly type: "string";
|
|
98
|
+
};
|
|
99
|
+
readonly "x-ui-editor": "multiselect";
|
|
100
|
+
};
|
|
101
|
+
readonly title: {
|
|
102
|
+
readonly type: "string";
|
|
103
|
+
};
|
|
104
|
+
readonly description: {
|
|
105
|
+
readonly type: "string";
|
|
106
|
+
readonly "x-ui-editor": "textarea";
|
|
107
|
+
};
|
|
108
|
+
readonly metadata: {
|
|
109
|
+
readonly type: "object";
|
|
110
|
+
readonly default: {};
|
|
111
|
+
readonly "x-ui-hidden": true;
|
|
112
|
+
};
|
|
113
|
+
};
|
|
114
|
+
readonly required: readonly ["model_id", "tasks", "provider", "title", "description", "provider_config", "metadata", "provider", "provider_config"];
|
|
115
|
+
readonly additionalProperties: false;
|
|
116
|
+
};
|
|
117
|
+
export type WebBrowserModelRecord = FromSchema<typeof WebBrowserModelRecordSchema>;
|
|
118
|
+
export declare const WebBrowserModelConfigSchema: {
|
|
119
|
+
readonly type: "object";
|
|
120
|
+
readonly properties: {
|
|
121
|
+
readonly provider: {
|
|
122
|
+
readonly const: "WEB_BROWSER";
|
|
123
|
+
readonly description: "Discriminator: Chrome Built-in AI (Gemini Nano).";
|
|
124
|
+
};
|
|
125
|
+
readonly provider_config: {
|
|
126
|
+
readonly type: "object";
|
|
127
|
+
readonly description: "Chrome Built-in AI configuration.";
|
|
128
|
+
readonly properties: {
|
|
129
|
+
readonly summary_type: {
|
|
130
|
+
readonly type: "string";
|
|
131
|
+
readonly enum: readonly ["tl;dr", "key-points", "teaser", "headline"];
|
|
132
|
+
readonly description: "Summarization style (Summarizer API only).";
|
|
133
|
+
};
|
|
134
|
+
readonly summary_length: {
|
|
135
|
+
readonly type: "string";
|
|
136
|
+
readonly enum: readonly ["short", "medium", "long"];
|
|
137
|
+
readonly description: "Desired summary length (Summarizer API only).";
|
|
138
|
+
};
|
|
139
|
+
readonly summary_format: {
|
|
140
|
+
readonly type: "string";
|
|
141
|
+
readonly enum: readonly ["plain-text", "markdown"];
|
|
142
|
+
readonly description: "Output format for summaries (Summarizer API only).";
|
|
143
|
+
};
|
|
144
|
+
readonly rewriter_tone: {
|
|
145
|
+
readonly type: "string";
|
|
146
|
+
readonly enum: readonly ["as-is", "more-formal", "more-casual"];
|
|
147
|
+
readonly description: "Tone for rewriting (Rewriter API only).";
|
|
148
|
+
};
|
|
149
|
+
readonly rewriter_length: {
|
|
150
|
+
readonly type: "string";
|
|
151
|
+
readonly enum: readonly ["as-is", "shorter", "longer"];
|
|
152
|
+
readonly description: "Length adjustment for rewriting (Rewriter API only).";
|
|
153
|
+
};
|
|
154
|
+
};
|
|
155
|
+
readonly required: readonly [];
|
|
156
|
+
readonly additionalProperties: false;
|
|
157
|
+
};
|
|
158
|
+
readonly model_id: {
|
|
159
|
+
readonly type: "string";
|
|
160
|
+
};
|
|
161
|
+
readonly tasks: {
|
|
162
|
+
readonly type: "array";
|
|
163
|
+
readonly items: {
|
|
164
|
+
readonly type: "string";
|
|
165
|
+
};
|
|
166
|
+
readonly "x-ui-editor": "multiselect";
|
|
167
|
+
};
|
|
168
|
+
readonly title: {
|
|
169
|
+
readonly type: "string";
|
|
170
|
+
};
|
|
171
|
+
readonly description: {
|
|
172
|
+
readonly type: "string";
|
|
173
|
+
readonly "x-ui-editor": "textarea";
|
|
174
|
+
};
|
|
175
|
+
readonly metadata: {
|
|
176
|
+
readonly type: "object";
|
|
177
|
+
readonly default: {};
|
|
178
|
+
readonly "x-ui-hidden": true;
|
|
179
|
+
};
|
|
180
|
+
};
|
|
181
|
+
readonly required: readonly ["provider", "provider_config", "provider", "provider_config"];
|
|
182
|
+
readonly additionalProperties: false;
|
|
183
|
+
};
|
|
184
|
+
export type WebBrowserModelConfig = FromSchema<typeof WebBrowserModelConfigSchema>;
|
|
185
|
+
//# sourceMappingURL=WebBrowser_ModelSchema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"WebBrowser_ModelSchema.d.ts","sourceRoot":"","sources":["../../../src/web-browser/common/WebBrowser_ModelSchema.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAwB,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAGlE,eAAO,MAAM,qBAAqB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA2CO,CAAC;AAE1C,eAAO,MAAM,2BAA2B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAQC,CAAC;AAE1C,MAAM,MAAM,qBAAqB,GAAG,UAAU,CAAC,OAAO,2BAA2B,CAAC,CAAC;AAEnF,eAAO,MAAM,2BAA2B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAQC,CAAC;AAE1C,MAAM,MAAM,qBAAqB,GAAG,UAAU,CAAC,OAAO,2BAA2B,CAAC,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Steven Roussey <sroussey@gmail.com>
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
export * from "./common/WebBrowser_Constants";
|
|
7
|
+
export * from "./common/WebBrowser_JobRunFns";
|
|
8
|
+
export * from "./common/WebBrowser_ModelSchema";
|
|
9
|
+
export * from "./WebBrowserProvider";
|
|
10
|
+
export * from "./WebBrowser_Worker";
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/web-browser/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,cAAc,+BAA+B,CAAC;AAC9C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,iCAAiC,CAAC;AAChD,cAAc,sBAAsB,CAAC;AACrC,cAAc,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,457 @@
|
|
|
1
|
+
import"../index.browser-6j5pq722.js";
|
|
2
|
+
|
|
3
|
+
// src/web-browser/common/WebBrowser_Constants.ts
|
|
4
|
+
var WEB_BROWSER = "WEB_BROWSER";
|
|
5
|
+
var WebBrowserPipelineTask = {
|
|
6
|
+
summarizer: "summarizer",
|
|
7
|
+
"language-detector": "language-detector",
|
|
8
|
+
translator: "translator",
|
|
9
|
+
prompt: "prompt",
|
|
10
|
+
rewriter: "rewriter"
|
|
11
|
+
};
|
|
12
|
+
// src/web-browser/common/WebBrowser_JobRunFns.ts
|
|
13
|
+
import { PermanentJobError } from "@workglow/job-queue";
|
|
14
|
+
import { getLogger } from "@workglow/util";
|
|
15
|
+
function getConfig(model) {
|
|
16
|
+
return model?.provider_config ?? {};
|
|
17
|
+
}
|
|
18
|
+
function getApi(name, global) {
|
|
19
|
+
if (!global) {
|
|
20
|
+
throw new PermanentJobError(`Chrome Built-in AI "${name}" API is not available in this browser.`);
|
|
21
|
+
}
|
|
22
|
+
return global;
|
|
23
|
+
}
|
|
24
|
+
async function ensureAvailable(name, factory) {
|
|
25
|
+
const status = await factory.availability();
|
|
26
|
+
if (status === "unavailable") {
|
|
27
|
+
throw new PermanentJobError(`Chrome Built-in AI "${name}" is not available (status: "no"). ` + `Ensure you are using a compatible Chrome version with the flag enabled.`);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
async function* snapshotStreamToTextDeltas(stream, port, buildFallbackOutput) {
|
|
31
|
+
const reader = stream.getReader();
|
|
32
|
+
let previousSnapshot = "";
|
|
33
|
+
try {
|
|
34
|
+
while (true) {
|
|
35
|
+
const { done, value } = await reader.read();
|
|
36
|
+
if (done)
|
|
37
|
+
break;
|
|
38
|
+
if (value.startsWith(previousSnapshot)) {
|
|
39
|
+
const delta = value.slice(previousSnapshot.length);
|
|
40
|
+
previousSnapshot = value;
|
|
41
|
+
if (delta) {
|
|
42
|
+
yield { type: "text-delta", port, textDelta: delta };
|
|
43
|
+
}
|
|
44
|
+
} else {
|
|
45
|
+
previousSnapshot = value;
|
|
46
|
+
yield { type: "snapshot", data: buildFallbackOutput(value) };
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
} finally {
|
|
50
|
+
reader.releaseLock();
|
|
51
|
+
}
|
|
52
|
+
yield { type: "finish", data: {} };
|
|
53
|
+
}
|
|
54
|
+
async function* snapshotStreamToSnapshots(stream, buildOutput) {
|
|
55
|
+
const reader = stream.getReader();
|
|
56
|
+
try {
|
|
57
|
+
while (true) {
|
|
58
|
+
const { done, value } = await reader.read();
|
|
59
|
+
if (done)
|
|
60
|
+
break;
|
|
61
|
+
yield { type: "snapshot", data: buildOutput(value) };
|
|
62
|
+
}
|
|
63
|
+
} finally {
|
|
64
|
+
reader.releaseLock();
|
|
65
|
+
}
|
|
66
|
+
yield { type: "finish", data: {} };
|
|
67
|
+
}
|
|
68
|
+
var WebBrowser_TextSummary = async (input, model, update_progress, signal) => {
|
|
69
|
+
const factory = getApi("Summarizer", globalThis?.ai?.summarizer ?? (typeof Summarizer !== "undefined" ? Summarizer : undefined));
|
|
70
|
+
await ensureAvailable("Summarizer", factory);
|
|
71
|
+
const config = getConfig(model);
|
|
72
|
+
if (Array.isArray(input.text)) {
|
|
73
|
+
getLogger().warn("WebBrowser_TextSummary: array input received; processing sequentially");
|
|
74
|
+
const results = [];
|
|
75
|
+
for (const item of input.text) {
|
|
76
|
+
const summarizer2 = await factory.create({
|
|
77
|
+
type: config.summary_type,
|
|
78
|
+
length: config.summary_length,
|
|
79
|
+
format: config.summary_format
|
|
80
|
+
});
|
|
81
|
+
try {
|
|
82
|
+
results.push(await summarizer2.summarize(item, { signal }));
|
|
83
|
+
} finally {
|
|
84
|
+
summarizer2.destroy();
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
update_progress(100, "Completed text summarization");
|
|
88
|
+
return { text: results };
|
|
89
|
+
}
|
|
90
|
+
const summarizer = await factory.create({
|
|
91
|
+
type: config.summary_type,
|
|
92
|
+
length: config.summary_length,
|
|
93
|
+
format: config.summary_format
|
|
94
|
+
});
|
|
95
|
+
try {
|
|
96
|
+
const text = await summarizer.summarize(input.text, { signal });
|
|
97
|
+
update_progress(100, "Completed text summarization");
|
|
98
|
+
return { text };
|
|
99
|
+
} finally {
|
|
100
|
+
summarizer.destroy();
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
var WebBrowser_TextLanguageDetection = async (input, model, update_progress, signal) => {
|
|
104
|
+
const factory = getApi("LanguageDetector", typeof LanguageDetector !== "undefined" ? LanguageDetector : undefined);
|
|
105
|
+
await ensureAvailable("LanguageDetector", factory);
|
|
106
|
+
if (Array.isArray(input.text)) {
|
|
107
|
+
getLogger().warn("WebBrowser_TextLanguageDetection: array input received; processing sequentially");
|
|
108
|
+
const allResults = [];
|
|
109
|
+
for (const item of input.text) {
|
|
110
|
+
const detector2 = await factory.create();
|
|
111
|
+
try {
|
|
112
|
+
const detected = await detector2.detect(item, { signal });
|
|
113
|
+
const mapped = detected.map((d) => ({ language: d.detectedLanguage, score: d.confidence })).slice(0, input.maxLanguages ?? 5);
|
|
114
|
+
allResults.push(mapped);
|
|
115
|
+
} finally {
|
|
116
|
+
detector2.destroy();
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
update_progress(100, "Completed language detection");
|
|
120
|
+
return { languages: allResults };
|
|
121
|
+
}
|
|
122
|
+
const detector = await factory.create();
|
|
123
|
+
try {
|
|
124
|
+
const detected = await detector.detect(input.text, { signal });
|
|
125
|
+
const languages = detected.map((d) => ({ language: d.detectedLanguage, score: d.confidence })).slice(0, input.maxLanguages ?? 5);
|
|
126
|
+
update_progress(100, "Completed language detection");
|
|
127
|
+
return { languages };
|
|
128
|
+
} finally {
|
|
129
|
+
detector.destroy();
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
var WebBrowser_TextTranslation = async (input, model, update_progress, signal) => {
|
|
133
|
+
const factory = getApi("Translator", typeof Translator !== "undefined" ? Translator : undefined);
|
|
134
|
+
await ensureAvailable("Translator", factory);
|
|
135
|
+
const translationAvailability = await factory.availability({
|
|
136
|
+
sourceLanguage: input.source_lang,
|
|
137
|
+
targetLanguage: input.target_lang
|
|
138
|
+
});
|
|
139
|
+
if (!translationAvailability || translationAvailability === "unavailable") {
|
|
140
|
+
throw new PermanentJobError(`Translator not available for language pair ${String(input.source_lang)} -> ${String(input.target_lang)}`);
|
|
141
|
+
}
|
|
142
|
+
if (Array.isArray(input.text)) {
|
|
143
|
+
getLogger().warn("WebBrowser_TextTranslation: array input received; processing sequentially");
|
|
144
|
+
const results = [];
|
|
145
|
+
for (const item of input.text) {
|
|
146
|
+
const translator2 = await factory.create({
|
|
147
|
+
sourceLanguage: input.source_lang,
|
|
148
|
+
targetLanguage: input.target_lang
|
|
149
|
+
});
|
|
150
|
+
try {
|
|
151
|
+
results.push(await translator2.translate(item, { signal }));
|
|
152
|
+
} finally {
|
|
153
|
+
translator2.destroy();
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
update_progress(100, "Completed text translation");
|
|
157
|
+
return { text: results, target_lang: input.target_lang };
|
|
158
|
+
}
|
|
159
|
+
const translator = await factory.create({
|
|
160
|
+
sourceLanguage: input.source_lang,
|
|
161
|
+
targetLanguage: input.target_lang
|
|
162
|
+
});
|
|
163
|
+
try {
|
|
164
|
+
const text = await translator.translate(input.text, { signal });
|
|
165
|
+
update_progress(100, "Completed text translation");
|
|
166
|
+
return { text, target_lang: input.target_lang };
|
|
167
|
+
} finally {
|
|
168
|
+
translator.destroy();
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
var WebBrowser_TextGeneration = async (input, model, update_progress, signal) => {
|
|
172
|
+
const factory = getApi("LanguageModel", typeof LanguageModel !== "undefined" ? LanguageModel : undefined);
|
|
173
|
+
await ensureAvailable("LanguageModel", factory);
|
|
174
|
+
if (Array.isArray(input.prompt)) {
|
|
175
|
+
getLogger().warn("WebBrowser_TextGeneration: array input received; processing sequentially");
|
|
176
|
+
const results = [];
|
|
177
|
+
for (const item of input.prompt) {
|
|
178
|
+
const session2 = await factory.create({
|
|
179
|
+
temperature: input.temperature ?? undefined
|
|
180
|
+
});
|
|
181
|
+
try {
|
|
182
|
+
results.push(await session2.prompt(item, { signal }));
|
|
183
|
+
} finally {
|
|
184
|
+
session2.destroy();
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
update_progress(100, "Completed text generation");
|
|
188
|
+
return { text: results };
|
|
189
|
+
}
|
|
190
|
+
const session = await factory.create({
|
|
191
|
+
temperature: input.temperature ?? undefined
|
|
192
|
+
});
|
|
193
|
+
try {
|
|
194
|
+
const text = await session.prompt(input.prompt, { signal });
|
|
195
|
+
update_progress(100, "Completed text generation");
|
|
196
|
+
return { text };
|
|
197
|
+
} finally {
|
|
198
|
+
session.destroy();
|
|
199
|
+
}
|
|
200
|
+
};
|
|
201
|
+
var WebBrowser_TextRewriter = async (input, model, update_progress, signal) => {
|
|
202
|
+
const factory = getApi("Rewriter", typeof Rewriter !== "undefined" ? Rewriter : undefined);
|
|
203
|
+
await ensureAvailable("Rewriter", factory);
|
|
204
|
+
const config = getConfig(model);
|
|
205
|
+
if (Array.isArray(input.text)) {
|
|
206
|
+
getLogger().warn("WebBrowser_TextRewriter: array input received; processing sequentially");
|
|
207
|
+
const results = [];
|
|
208
|
+
for (const item of input.text) {
|
|
209
|
+
const rewriter2 = await factory.create({
|
|
210
|
+
tone: config.rewriter_tone,
|
|
211
|
+
length: config.rewriter_length
|
|
212
|
+
});
|
|
213
|
+
try {
|
|
214
|
+
results.push(await rewriter2.rewrite(item, {
|
|
215
|
+
signal,
|
|
216
|
+
context: input.prompt
|
|
217
|
+
}));
|
|
218
|
+
} finally {
|
|
219
|
+
rewriter2.destroy();
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
update_progress(100, "Completed text rewriting");
|
|
223
|
+
return { text: results };
|
|
224
|
+
}
|
|
225
|
+
const rewriter = await factory.create({
|
|
226
|
+
tone: config.rewriter_tone,
|
|
227
|
+
length: config.rewriter_length
|
|
228
|
+
});
|
|
229
|
+
try {
|
|
230
|
+
const text = await rewriter.rewrite(input.text, {
|
|
231
|
+
signal,
|
|
232
|
+
context: input.prompt
|
|
233
|
+
});
|
|
234
|
+
update_progress(100, "Completed text rewriting");
|
|
235
|
+
return { text };
|
|
236
|
+
} finally {
|
|
237
|
+
rewriter.destroy();
|
|
238
|
+
}
|
|
239
|
+
};
|
|
240
|
+
var WebBrowser_ModelInfo = async (input) => {
|
|
241
|
+
return {
|
|
242
|
+
model: input.model,
|
|
243
|
+
is_local: true,
|
|
244
|
+
is_remote: false,
|
|
245
|
+
supports_browser: true,
|
|
246
|
+
supports_node: false,
|
|
247
|
+
is_cached: false,
|
|
248
|
+
is_loaded: false,
|
|
249
|
+
file_sizes: null
|
|
250
|
+
};
|
|
251
|
+
};
|
|
252
|
+
var WebBrowser_TextSummary_Stream = async function* (input, model, signal) {
|
|
253
|
+
const factory = getApi("Summarizer", typeof Summarizer !== "undefined" ? Summarizer : undefined);
|
|
254
|
+
await ensureAvailable("Summarizer", factory);
|
|
255
|
+
const config = getConfig(model);
|
|
256
|
+
const summarizer = await factory.create({
|
|
257
|
+
type: config.summary_type,
|
|
258
|
+
length: config.summary_length,
|
|
259
|
+
format: config.summary_format
|
|
260
|
+
});
|
|
261
|
+
try {
|
|
262
|
+
const stream = summarizer.summarizeStreaming(input.text, { signal });
|
|
263
|
+
yield* snapshotStreamToTextDeltas(stream, "text", (text) => ({ text }));
|
|
264
|
+
} finally {
|
|
265
|
+
summarizer.destroy();
|
|
266
|
+
}
|
|
267
|
+
};
|
|
268
|
+
var WebBrowser_TextTranslation_Stream = async function* (input, model, signal) {
|
|
269
|
+
const factory = getApi("Translator", typeof Translator !== "undefined" ? Translator : undefined);
|
|
270
|
+
let status;
|
|
271
|
+
try {
|
|
272
|
+
status = await factory.availability({
|
|
273
|
+
sourceLanguage: input.source_lang,
|
|
274
|
+
targetLanguage: input.target_lang
|
|
275
|
+
});
|
|
276
|
+
} catch (error) {
|
|
277
|
+
throw new PermanentJobError(`Chrome Built-in AI "Translator" is not available (status: "no"). ` + `Ensure you are using a compatible Chrome version with the flag enabled.`);
|
|
278
|
+
}
|
|
279
|
+
if (status === "unavailable") {
|
|
280
|
+
throw new PermanentJobError(`Chrome Built-in AI "Translator" is not available (status: "no"). ` + `Ensure you are using a compatible Chrome version with the flag enabled.`);
|
|
281
|
+
}
|
|
282
|
+
const translator = await factory.create({
|
|
283
|
+
sourceLanguage: input.source_lang,
|
|
284
|
+
targetLanguage: input.target_lang
|
|
285
|
+
});
|
|
286
|
+
try {
|
|
287
|
+
const stream = translator.translateStreaming(input.text, { signal });
|
|
288
|
+
yield* snapshotStreamToSnapshots(stream, (text) => ({
|
|
289
|
+
text,
|
|
290
|
+
target_lang: input.target_lang
|
|
291
|
+
}));
|
|
292
|
+
} finally {
|
|
293
|
+
translator.destroy();
|
|
294
|
+
}
|
|
295
|
+
};
|
|
296
|
+
var WebBrowser_TextGeneration_Stream = async function* (input, model, signal) {
|
|
297
|
+
const factory = getApi("LanguageModel", typeof LanguageModel !== "undefined" ? LanguageModel : undefined);
|
|
298
|
+
await ensureAvailable("LanguageModel", factory);
|
|
299
|
+
const session = await factory.create({
|
|
300
|
+
temperature: input.temperature ?? undefined
|
|
301
|
+
});
|
|
302
|
+
try {
|
|
303
|
+
const stream = session.promptStreaming(input.prompt, { signal });
|
|
304
|
+
yield* snapshotStreamToTextDeltas(stream, "text", (text) => ({
|
|
305
|
+
text
|
|
306
|
+
}));
|
|
307
|
+
} finally {
|
|
308
|
+
session.destroy();
|
|
309
|
+
}
|
|
310
|
+
};
|
|
311
|
+
var WebBrowser_TextRewriter_Stream = async function* (input, model, signal) {
|
|
312
|
+
const factory = getApi("Rewriter", typeof Rewriter !== "undefined" ? Rewriter : undefined);
|
|
313
|
+
await ensureAvailable("Rewriter", factory);
|
|
314
|
+
const config = getConfig(model);
|
|
315
|
+
const rewriter = await factory.create({
|
|
316
|
+
tone: config.rewriter_tone,
|
|
317
|
+
length: config.rewriter_length
|
|
318
|
+
});
|
|
319
|
+
try {
|
|
320
|
+
const stream = rewriter.rewriteStreaming(input.text, {
|
|
321
|
+
signal,
|
|
322
|
+
context: input.prompt
|
|
323
|
+
});
|
|
324
|
+
yield* snapshotStreamToTextDeltas(stream, "text", (text) => ({ text }));
|
|
325
|
+
} finally {
|
|
326
|
+
rewriter.destroy();
|
|
327
|
+
}
|
|
328
|
+
};
|
|
329
|
+
var WEB_BROWSER_TASKS = {
|
|
330
|
+
ModelInfoTask: WebBrowser_ModelInfo,
|
|
331
|
+
TextSummaryTask: WebBrowser_TextSummary,
|
|
332
|
+
TextLanguageDetectionTask: WebBrowser_TextLanguageDetection,
|
|
333
|
+
TextTranslationTask: WebBrowser_TextTranslation,
|
|
334
|
+
TextGenerationTask: WebBrowser_TextGeneration,
|
|
335
|
+
TextRewriterTask: WebBrowser_TextRewriter
|
|
336
|
+
};
|
|
337
|
+
var WEB_BROWSER_STREAM_TASKS = {
|
|
338
|
+
TextSummaryTask: WebBrowser_TextSummary_Stream,
|
|
339
|
+
TextTranslationTask: WebBrowser_TextTranslation_Stream,
|
|
340
|
+
TextGenerationTask: WebBrowser_TextGeneration_Stream,
|
|
341
|
+
TextRewriterTask: WebBrowser_TextRewriter_Stream
|
|
342
|
+
};
|
|
343
|
+
// src/web-browser/common/WebBrowser_ModelSchema.ts
|
|
344
|
+
import { ModelConfigSchema, ModelRecordSchema } from "@workglow/ai";
|
|
345
|
+
var WebBrowserModelSchema = {
|
|
346
|
+
type: "object",
|
|
347
|
+
properties: {
|
|
348
|
+
provider: {
|
|
349
|
+
const: WEB_BROWSER,
|
|
350
|
+
description: "Discriminator: Chrome Built-in AI (Gemini Nano)."
|
|
351
|
+
},
|
|
352
|
+
provider_config: {
|
|
353
|
+
type: "object",
|
|
354
|
+
description: "Chrome Built-in AI configuration.",
|
|
355
|
+
properties: {
|
|
356
|
+
summary_type: {
|
|
357
|
+
type: "string",
|
|
358
|
+
enum: ["tl;dr", "key-points", "teaser", "headline"],
|
|
359
|
+
description: "Summarization style (Summarizer API only)."
|
|
360
|
+
},
|
|
361
|
+
summary_length: {
|
|
362
|
+
type: "string",
|
|
363
|
+
enum: ["short", "medium", "long"],
|
|
364
|
+
description: "Desired summary length (Summarizer API only)."
|
|
365
|
+
},
|
|
366
|
+
summary_format: {
|
|
367
|
+
type: "string",
|
|
368
|
+
enum: ["plain-text", "markdown"],
|
|
369
|
+
description: "Output format for summaries (Summarizer API only)."
|
|
370
|
+
},
|
|
371
|
+
rewriter_tone: {
|
|
372
|
+
type: "string",
|
|
373
|
+
enum: ["as-is", "more-formal", "more-casual"],
|
|
374
|
+
description: "Tone for rewriting (Rewriter API only)."
|
|
375
|
+
},
|
|
376
|
+
rewriter_length: {
|
|
377
|
+
type: "string",
|
|
378
|
+
enum: ["as-is", "shorter", "longer"],
|
|
379
|
+
description: "Length adjustment for rewriting (Rewriter API only)."
|
|
380
|
+
}
|
|
381
|
+
},
|
|
382
|
+
required: [],
|
|
383
|
+
additionalProperties: false
|
|
384
|
+
}
|
|
385
|
+
},
|
|
386
|
+
required: ["provider", "provider_config"],
|
|
387
|
+
additionalProperties: true
|
|
388
|
+
};
|
|
389
|
+
var WebBrowserModelRecordSchema = {
|
|
390
|
+
type: "object",
|
|
391
|
+
properties: {
|
|
392
|
+
...ModelRecordSchema.properties,
|
|
393
|
+
...WebBrowserModelSchema.properties
|
|
394
|
+
},
|
|
395
|
+
required: [...ModelRecordSchema.required, ...WebBrowserModelSchema.required],
|
|
396
|
+
additionalProperties: false
|
|
397
|
+
};
|
|
398
|
+
var WebBrowserModelConfigSchema = {
|
|
399
|
+
type: "object",
|
|
400
|
+
properties: {
|
|
401
|
+
...ModelConfigSchema.properties,
|
|
402
|
+
...WebBrowserModelSchema.properties
|
|
403
|
+
},
|
|
404
|
+
required: [...ModelConfigSchema.required, ...WebBrowserModelSchema.required],
|
|
405
|
+
additionalProperties: false
|
|
406
|
+
};
|
|
407
|
+
// src/web-browser/WebBrowserProvider.ts
|
|
408
|
+
import {
|
|
409
|
+
AiProvider
|
|
410
|
+
} from "@workglow/ai";
|
|
411
|
+
class WebBrowserProvider extends AiProvider {
|
|
412
|
+
name = WEB_BROWSER;
|
|
413
|
+
isLocal = true;
|
|
414
|
+
supportsBrowser = true;
|
|
415
|
+
taskTypes = [
|
|
416
|
+
"ModelInfoTask",
|
|
417
|
+
"TextSummaryTask",
|
|
418
|
+
"TextLanguageDetectionTask",
|
|
419
|
+
"TextTranslationTask",
|
|
420
|
+
"TextGenerationTask",
|
|
421
|
+
"TextRewriterTask"
|
|
422
|
+
];
|
|
423
|
+
constructor(tasks, streamTasks, reactiveTasks) {
|
|
424
|
+
super(tasks, streamTasks, reactiveTasks);
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
// src/web-browser/WebBrowser_Worker.ts
|
|
428
|
+
import { getLogger as getLogger2, globalServiceRegistry, WORKER_SERVER } from "@workglow/util";
|
|
429
|
+
function WEB_BROWSER_WORKER_JOBRUN_REGISTER() {
|
|
430
|
+
const workerServer = globalServiceRegistry.get(WORKER_SERVER);
|
|
431
|
+
new WebBrowserProvider(WEB_BROWSER_TASKS, WEB_BROWSER_STREAM_TASKS).registerOnWorkerServer(workerServer);
|
|
432
|
+
workerServer.sendReady();
|
|
433
|
+
getLogger2().info("WEB_BROWSER_WORKER_JOBRUN registered");
|
|
434
|
+
}
|
|
435
|
+
export {
|
|
436
|
+
WebBrowser_TextTranslation_Stream,
|
|
437
|
+
WebBrowser_TextTranslation,
|
|
438
|
+
WebBrowser_TextSummary_Stream,
|
|
439
|
+
WebBrowser_TextSummary,
|
|
440
|
+
WebBrowser_TextRewriter_Stream,
|
|
441
|
+
WebBrowser_TextRewriter,
|
|
442
|
+
WebBrowser_TextLanguageDetection,
|
|
443
|
+
WebBrowser_TextGeneration_Stream,
|
|
444
|
+
WebBrowser_TextGeneration,
|
|
445
|
+
WebBrowser_ModelInfo,
|
|
446
|
+
WebBrowserProvider,
|
|
447
|
+
WebBrowserPipelineTask,
|
|
448
|
+
WebBrowserModelSchema,
|
|
449
|
+
WebBrowserModelRecordSchema,
|
|
450
|
+
WebBrowserModelConfigSchema,
|
|
451
|
+
WEB_BROWSER_WORKER_JOBRUN_REGISTER,
|
|
452
|
+
WEB_BROWSER_TASKS,
|
|
453
|
+
WEB_BROWSER_STREAM_TASKS,
|
|
454
|
+
WEB_BROWSER
|
|
455
|
+
};
|
|
456
|
+
|
|
457
|
+
//# debugId=2D3A8A06C95D0C3D64756E2164756E21
|