@workglow/ai 0.0.58 → 0.0.60
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/browser.js +72 -97
- package/dist/browser.js.map +12 -12
- package/dist/bun.js +72 -123
- package/dist/bun.js.map +12 -14
- package/dist/common.d.ts +2 -1
- package/dist/common.d.ts.map +1 -1
- package/dist/model/InMemoryModelRepository.d.ts +14 -0
- package/dist/model/InMemoryModelRepository.d.ts.map +1 -0
- package/dist/model/ModelRegistry.d.ts +12 -0
- package/dist/model/ModelRegistry.d.ts.map +1 -1
- package/dist/model/ModelRepository.d.ts +63 -65
- package/dist/model/ModelRepository.d.ts.map +1 -1
- package/dist/model/ModelSchema.d.ts +42 -0
- package/dist/model/ModelSchema.d.ts.map +1 -0
- package/dist/node.js +72 -123
- package/dist/node.js.map +12 -14
- package/dist/provider/AiProviderRegistry.d.ts +15 -3
- package/dist/provider/AiProviderRegistry.d.ts.map +1 -1
- package/dist/task/DownloadModelTask.d.ts +179 -19
- package/dist/task/DownloadModelTask.d.ts.map +1 -1
- package/dist/task/TextEmbeddingTask.d.ts +77 -9
- package/dist/task/TextEmbeddingTask.d.ts.map +1 -1
- package/dist/task/TextGenerationTask.d.ts +77 -9
- package/dist/task/TextGenerationTask.d.ts.map +1 -1
- package/dist/task/TextQuestionAnswerTask.d.ts +77 -9
- package/dist/task/TextQuestionAnswerTask.d.ts.map +1 -1
- package/dist/task/TextRewriterTask.d.ts +77 -9
- package/dist/task/TextRewriterTask.d.ts.map +1 -1
- package/dist/task/TextSummaryTask.d.ts +77 -9
- package/dist/task/TextSummaryTask.d.ts.map +1 -1
- package/dist/task/TextTranslationTask.d.ts +77 -9
- package/dist/task/TextTranslationTask.d.ts.map +1 -1
- package/dist/task/base/AiTask.d.ts +3 -3
- package/dist/task/base/AiTask.d.ts.map +1 -1
- package/dist/task/base/AiTaskSchemas.d.ts +43 -2
- package/dist/task/base/AiTaskSchemas.d.ts.map +1 -1
- package/dist/types.d.ts +0 -4
- package/dist/types.d.ts.map +1 -1
- package/package.json +9 -12
- package/dist/model/Model.d.ts +0 -26
- package/dist/model/Model.d.ts.map +0 -1
- package/dist/model/storage/InMemoryModelRepository.d.ts +0 -18
- package/dist/model/storage/InMemoryModelRepository.d.ts.map +0 -1
- package/dist/model/storage/IndexedDbModelRepository.d.ts +0 -18
- package/dist/model/storage/IndexedDbModelRepository.d.ts.map +0 -1
- package/dist/model/storage/PostgresModelRepository.d.ts +0 -19
- package/dist/model/storage/PostgresModelRepository.d.ts.map +0 -1
- package/dist/model/storage/SqliteModelRepository.d.ts +0 -18
- package/dist/model/storage/SqliteModelRepository.d.ts.map +0 -1
package/dist/bun.js
CHANGED
|
@@ -7,34 +7,20 @@ import {
|
|
|
7
7
|
PermanentJobError
|
|
8
8
|
} from "@workglow/job-queue";
|
|
9
9
|
|
|
10
|
-
// src/model/
|
|
10
|
+
// src/model/ModelRegistry.ts
|
|
11
|
+
import { createServiceToken, globalServiceRegistry } from "@workglow/util";
|
|
12
|
+
|
|
13
|
+
// src/model/InMemoryModelRepository.ts
|
|
11
14
|
import { InMemoryTabularRepository } from "@workglow/storage";
|
|
12
15
|
|
|
13
16
|
// src/model/ModelRepository.ts
|
|
14
17
|
import { EventEmitter } from "@workglow/util";
|
|
15
|
-
var ModelSchema = {
|
|
16
|
-
type: "object",
|
|
17
|
-
properties: {
|
|
18
|
-
name: { type: "string" },
|
|
19
|
-
details: { type: "string" }
|
|
20
|
-
},
|
|
21
|
-
required: ["name", "details"],
|
|
22
|
-
additionalProperties: false
|
|
23
|
-
};
|
|
24
|
-
var ModelPrimaryKeyNames = ["name"];
|
|
25
|
-
var Task2ModelSchema = {
|
|
26
|
-
type: "object",
|
|
27
|
-
properties: {
|
|
28
|
-
task: { type: "string" },
|
|
29
|
-
model: { type: "string" }
|
|
30
|
-
},
|
|
31
|
-
required: ["task", "model"],
|
|
32
|
-
additionalProperties: false
|
|
33
|
-
};
|
|
34
|
-
var Task2ModelPrimaryKeyNames = ["task", "model"];
|
|
35
18
|
|
|
36
19
|
class ModelRepository {
|
|
37
|
-
|
|
20
|
+
modelTabularRepository;
|
|
21
|
+
constructor(modelTabularRepository) {
|
|
22
|
+
this.modelTabularRepository = modelTabularRepository;
|
|
23
|
+
}
|
|
38
24
|
events = new EventEmitter;
|
|
39
25
|
on(name, fn) {
|
|
40
26
|
this.events.on(name, fn);
|
|
@@ -49,101 +35,98 @@ class ModelRepository {
|
|
|
49
35
|
return this.events.waitOn(name);
|
|
50
36
|
}
|
|
51
37
|
async addModel(model) {
|
|
52
|
-
await this.modelTabularRepository.put(
|
|
53
|
-
this.models.set(model.name, model);
|
|
38
|
+
await this.modelTabularRepository.put(model);
|
|
54
39
|
this.events.emit("model_added", model);
|
|
55
40
|
return model;
|
|
56
41
|
}
|
|
57
42
|
async findModelsByTask(task) {
|
|
58
43
|
if (typeof task != "string")
|
|
59
44
|
return;
|
|
60
|
-
const
|
|
61
|
-
if (!
|
|
45
|
+
const allModels = await this.modelTabularRepository.getAll();
|
|
46
|
+
if (!allModels || allModels.length === 0)
|
|
47
|
+
return;
|
|
48
|
+
const models = allModels.filter((model) => model.tasks?.includes(task));
|
|
49
|
+
if (models.length === 0)
|
|
62
50
|
return;
|
|
63
|
-
const models = [];
|
|
64
|
-
for (const junction of junctions) {
|
|
65
|
-
const model = await this.modelTabularRepository.get({ name: junction.model });
|
|
66
|
-
if (model)
|
|
67
|
-
models.push(JSON.parse(model.details));
|
|
68
|
-
}
|
|
69
|
-
models.forEach((m) => this.models.set(m.name, m));
|
|
70
|
-
this.taskModels.set(task, models);
|
|
71
51
|
return models;
|
|
72
52
|
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
async findTasksByModel(model) {
|
|
76
|
-
if (typeof model != "string")
|
|
53
|
+
async findTasksByModel(model_id) {
|
|
54
|
+
if (typeof model_id != "string")
|
|
77
55
|
return;
|
|
78
|
-
const
|
|
79
|
-
if (!
|
|
56
|
+
const modelRecord = await this.modelTabularRepository.get({ model_id });
|
|
57
|
+
if (!modelRecord)
|
|
80
58
|
return;
|
|
81
|
-
return
|
|
59
|
+
return modelRecord.tasks && modelRecord.tasks.length > 0 ? modelRecord.tasks : undefined;
|
|
82
60
|
}
|
|
83
61
|
async enumerateAllTasks() {
|
|
84
|
-
const
|
|
85
|
-
if (!
|
|
62
|
+
const allModels = await this.modelTabularRepository.getAll();
|
|
63
|
+
if (!allModels || allModels.length === 0)
|
|
86
64
|
return;
|
|
87
|
-
const uniqueTasks =
|
|
88
|
-
|
|
65
|
+
const uniqueTasks = new Set;
|
|
66
|
+
for (const model of allModels) {
|
|
67
|
+
if (model.tasks) {
|
|
68
|
+
for (const task of model.tasks) {
|
|
69
|
+
uniqueTasks.add(task);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return uniqueTasks.size > 0 ? Array.from(uniqueTasks) : undefined;
|
|
89
74
|
}
|
|
90
75
|
async enumerateAllModels() {
|
|
91
76
|
const models = await this.modelTabularRepository.getAll();
|
|
92
77
|
if (!models || models.length === 0)
|
|
93
78
|
return;
|
|
94
|
-
|
|
95
|
-
parsedModels.forEach((m) => this.models.set(m.name, m));
|
|
96
|
-
return parsedModels;
|
|
97
|
-
}
|
|
98
|
-
async connectTaskToModel(task, model) {
|
|
99
|
-
await this.task2ModelTabularRepository.put({ task, model });
|
|
100
|
-
this.events.emit("task_model_connected", task, model);
|
|
79
|
+
return models;
|
|
101
80
|
}
|
|
102
|
-
async findByName(
|
|
103
|
-
if (typeof
|
|
104
|
-
return;
|
|
105
|
-
const modelstr = await this.modelTabularRepository.get({ name });
|
|
106
|
-
if (!modelstr)
|
|
81
|
+
async findByName(model_id) {
|
|
82
|
+
if (typeof model_id != "string")
|
|
107
83
|
return;
|
|
108
|
-
const model =
|
|
109
|
-
|
|
110
|
-
return model;
|
|
84
|
+
const model = await this.modelTabularRepository.get({ model_id });
|
|
85
|
+
return model ?? undefined;
|
|
111
86
|
}
|
|
112
87
|
async size() {
|
|
113
88
|
return await this.modelTabularRepository.size();
|
|
114
89
|
}
|
|
115
|
-
async clear() {
|
|
116
|
-
await this.modelTabularRepository.deleteAll();
|
|
117
|
-
}
|
|
118
90
|
}
|
|
119
91
|
|
|
120
|
-
// src/model/
|
|
92
|
+
// src/model/ModelSchema.ts
|
|
93
|
+
var ModelSchema = {
|
|
94
|
+
type: "object",
|
|
95
|
+
properties: {
|
|
96
|
+
model_id: { type: "string" },
|
|
97
|
+
tasks: { type: "array", items: { type: "string" } },
|
|
98
|
+
title: { type: "string" },
|
|
99
|
+
description: { type: "string" },
|
|
100
|
+
provider: { type: "string" },
|
|
101
|
+
providerConfig: { type: "object", default: {} },
|
|
102
|
+
metadata: { type: "object", default: {} }
|
|
103
|
+
},
|
|
104
|
+
required: ["model_id", "tasks", "provider", "title", "description", "providerConfig", "metadata"],
|
|
105
|
+
additionalProperties: false
|
|
106
|
+
};
|
|
107
|
+
var ModelPrimaryKeyNames = ["model_id"];
|
|
108
|
+
|
|
109
|
+
// src/model/InMemoryModelRepository.ts
|
|
121
110
|
class InMemoryModelRepository extends ModelRepository {
|
|
122
|
-
modelTabularRepository;
|
|
123
|
-
task2ModelTabularRepository;
|
|
124
|
-
type = "InMemoryModelRepository";
|
|
125
111
|
constructor() {
|
|
126
|
-
super();
|
|
127
|
-
this.modelTabularRepository = new InMemoryTabularRepository(ModelSchema, ModelPrimaryKeyNames);
|
|
128
|
-
this.task2ModelTabularRepository = new InMemoryTabularRepository(Task2ModelSchema, Task2ModelPrimaryKeyNames, ["model"]);
|
|
112
|
+
super(new InMemoryTabularRepository(ModelSchema, ModelPrimaryKeyNames));
|
|
129
113
|
}
|
|
130
114
|
}
|
|
131
115
|
|
|
132
116
|
// src/model/ModelRegistry.ts
|
|
133
|
-
|
|
117
|
+
var MODEL_REPOSITORY = createServiceToken("model.repository");
|
|
118
|
+
if (!globalServiceRegistry.has(MODEL_REPOSITORY)) {
|
|
119
|
+
globalServiceRegistry.register(MODEL_REPOSITORY, () => new InMemoryModelRepository, true);
|
|
134
120
|
}
|
|
135
|
-
var modelRegistry;
|
|
136
121
|
function getGlobalModelRepository() {
|
|
137
|
-
|
|
138
|
-
modelRegistry = new FallbackModelRegistry;
|
|
139
|
-
return modelRegistry;
|
|
122
|
+
return globalServiceRegistry.get(MODEL_REPOSITORY);
|
|
140
123
|
}
|
|
141
124
|
function setGlobalModelRepository(pr) {
|
|
142
|
-
|
|
125
|
+
globalServiceRegistry.registerInstance(MODEL_REPOSITORY, pr);
|
|
143
126
|
}
|
|
144
127
|
|
|
145
128
|
// src/provider/AiProviderRegistry.ts
|
|
146
|
-
import { globalServiceRegistry, WORKER_MANAGER } from "@workglow/util";
|
|
129
|
+
import { globalServiceRegistry as globalServiceRegistry2, WORKER_MANAGER } from "@workglow/util";
|
|
147
130
|
|
|
148
131
|
class AiProviderRegistry {
|
|
149
132
|
runFnRegistry = new Map;
|
|
@@ -155,7 +138,7 @@ class AiProviderRegistry {
|
|
|
155
138
|
}
|
|
156
139
|
registerAsWorkerRunFn(modelProvider, taskType) {
|
|
157
140
|
const workerFn = async (input, model, update_progress, signal) => {
|
|
158
|
-
const workerManager =
|
|
141
|
+
const workerManager = globalServiceRegistry2.get(WORKER_MANAGER);
|
|
159
142
|
const result = await workerManager.callWorkerFunction(modelProvider, taskType, [input, model], {
|
|
160
143
|
signal,
|
|
161
144
|
onProgress: update_progress
|
|
@@ -537,7 +520,7 @@ class AiTask extends JobQueueTask {
|
|
|
537
520
|
for (const [key, propSchema] of modelTaskProperties) {
|
|
538
521
|
let requestedModels = Array.isArray(input[key]) ? input[key] : [input[key]];
|
|
539
522
|
for (const model of requestedModels) {
|
|
540
|
-
const foundModel = taskModels?.find((m) => m.
|
|
523
|
+
const foundModel = taskModels?.find((m) => m.model_id === model);
|
|
541
524
|
if (!foundModel) {
|
|
542
525
|
throw new TaskConfigurationError(`AiTask: Missing model for '${key}' named '${model}' for task '${this.type}'`);
|
|
543
526
|
}
|
|
@@ -571,7 +554,7 @@ class AiTask extends JobQueueTask {
|
|
|
571
554
|
const taskModels = await getGlobalModelRepository().findModelsByTask(this.type);
|
|
572
555
|
for (const [key, propSchema] of modelTaskProperties) {
|
|
573
556
|
let requestedModels = Array.isArray(input[key]) ? input[key] : [input[key]];
|
|
574
|
-
let usingModels = requestedModels.filter((model) => taskModels?.find((m) => m.
|
|
557
|
+
let usingModels = requestedModels.filter((model) => taskModels?.find((m) => m.model_id === model));
|
|
575
558
|
usingModels = usingModels.length > 1 ? usingModels : usingModels[0];
|
|
576
559
|
input[key] = usingModels;
|
|
577
560
|
}
|
|
@@ -668,7 +651,7 @@ var TypeLanguage = (annotations = {}) => ({
|
|
|
668
651
|
minLength: 2,
|
|
669
652
|
...annotations
|
|
670
653
|
});
|
|
671
|
-
function
|
|
654
|
+
function TypeModelAsString(semantic = "model", options = {}) {
|
|
672
655
|
if (semantic !== "model" && !semantic.startsWith("model:")) {
|
|
673
656
|
throw new Error("Invalid semantic value");
|
|
674
657
|
}
|
|
@@ -681,6 +664,11 @@ function TypeModel(semantic = "model", options = {}) {
|
|
|
681
664
|
type: "string"
|
|
682
665
|
};
|
|
683
666
|
}
|
|
667
|
+
function TypeModel(semantic = "model", options = {}) {
|
|
668
|
+
return {
|
|
669
|
+
oneOf: [TypeModelAsString(semantic, options), ModelSchema]
|
|
670
|
+
};
|
|
671
|
+
}
|
|
684
672
|
var TypeReplicateArray = (type, annotations = {}) => ({
|
|
685
673
|
oneOf: [type, { type: "array", items: type }],
|
|
686
674
|
title: type.title,
|
|
@@ -1304,42 +1292,6 @@ function normalize(vector) {
|
|
|
1304
1292
|
}
|
|
1305
1293
|
return new Float32Array(normalized);
|
|
1306
1294
|
}
|
|
1307
|
-
// src/model/storage/IndexedDbModelRepository.ts
|
|
1308
|
-
import { IndexedDbTabularRepository } from "@workglow/storage";
|
|
1309
|
-
class IndexedDbModelRepository extends ModelRepository {
|
|
1310
|
-
modelTabularRepository;
|
|
1311
|
-
task2ModelTabularRepository;
|
|
1312
|
-
type = "IndexedDbModelRepository";
|
|
1313
|
-
constructor(tableModels = "models", tableTask2Models = "task2models") {
|
|
1314
|
-
super();
|
|
1315
|
-
this.modelTabularRepository = new IndexedDbTabularRepository(tableModels, ModelSchema, ModelPrimaryKeyNames);
|
|
1316
|
-
this.task2ModelTabularRepository = new IndexedDbTabularRepository(tableTask2Models, Task2ModelSchema, Task2ModelPrimaryKeyNames, ["model"]);
|
|
1317
|
-
}
|
|
1318
|
-
}
|
|
1319
|
-
// src/model/storage/PostgresModelRepository.ts
|
|
1320
|
-
import { PostgresTabularRepository } from "@workglow/storage";
|
|
1321
|
-
class PostgresModelRepository extends ModelRepository {
|
|
1322
|
-
type = "PostgresModelRepository";
|
|
1323
|
-
modelTabularRepository;
|
|
1324
|
-
task2ModelTabularRepository;
|
|
1325
|
-
constructor(db, tableModels = "aimodel", tableTask2Models = "aitask2aimodel") {
|
|
1326
|
-
super();
|
|
1327
|
-
this.modelTabularRepository = new PostgresTabularRepository(db, tableModels, ModelSchema, ModelPrimaryKeyNames);
|
|
1328
|
-
this.task2ModelTabularRepository = new PostgresTabularRepository(db, tableTask2Models, Task2ModelSchema, Task2ModelPrimaryKeyNames, ["model"]);
|
|
1329
|
-
}
|
|
1330
|
-
}
|
|
1331
|
-
// src/model/storage/SqliteModelRepository.ts
|
|
1332
|
-
import { SqliteTabularRepository } from "@workglow/storage";
|
|
1333
|
-
class SqliteModelRepository extends ModelRepository {
|
|
1334
|
-
type = "SqliteModelRepository";
|
|
1335
|
-
modelTabularRepository;
|
|
1336
|
-
task2ModelTabularRepository;
|
|
1337
|
-
constructor(dbOrPath, tableModels = "aimodel", tableTask2Models = "aitask2aimodel") {
|
|
1338
|
-
super();
|
|
1339
|
-
this.modelTabularRepository = new SqliteTabularRepository(dbOrPath, tableModels, ModelSchema, ModelPrimaryKeyNames);
|
|
1340
|
-
this.task2ModelTabularRepository = new SqliteTabularRepository(dbOrPath, tableTask2Models, Task2ModelSchema, Task2ModelPrimaryKeyNames, ["model"]);
|
|
1341
|
-
}
|
|
1342
|
-
}
|
|
1343
1295
|
export {
|
|
1344
1296
|
setGlobalModelRepository,
|
|
1345
1297
|
setAiProviderRegistry,
|
|
@@ -1351,6 +1303,7 @@ export {
|
|
|
1351
1303
|
VectorSimilarityTask,
|
|
1352
1304
|
TypedArraySchema,
|
|
1353
1305
|
TypeReplicateArray,
|
|
1306
|
+
TypeModelAsString,
|
|
1354
1307
|
TypeModel,
|
|
1355
1308
|
TypeLanguage,
|
|
1356
1309
|
TextTranslationTask,
|
|
@@ -1378,17 +1331,13 @@ export {
|
|
|
1378
1331
|
TextEmbeddingOutputSchema,
|
|
1379
1332
|
TextEmbeddingInputSchema,
|
|
1380
1333
|
TextEmbedding,
|
|
1381
|
-
Task2ModelSchema,
|
|
1382
|
-
Task2ModelPrimaryKeyNames,
|
|
1383
1334
|
TableFragment,
|
|
1384
|
-
SqliteModelRepository,
|
|
1385
1335
|
SimilarityFn,
|
|
1386
1336
|
Similarity,
|
|
1387
|
-
PostgresModelRepository,
|
|
1388
1337
|
ModelSchema,
|
|
1389
1338
|
ModelRepository,
|
|
1390
1339
|
ModelPrimaryKeyNames,
|
|
1391
|
-
|
|
1340
|
+
MODEL_REPOSITORY,
|
|
1392
1341
|
InMemoryModelRepository,
|
|
1393
1342
|
ImageFragment,
|
|
1394
1343
|
DownloadModelTask,
|
|
@@ -1405,4 +1354,4 @@ export {
|
|
|
1405
1354
|
AiJob
|
|
1406
1355
|
};
|
|
1407
1356
|
|
|
1408
|
-
//# debugId=
|
|
1357
|
+
//# debugId=15E88D5B6E009F3A64756E2164756E21
|