@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
|
@@ -5,67 +5,29 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import { type TabularRepository } from "@workglow/storage";
|
|
7
7
|
import { EventEmitter, EventParameters } from "@workglow/util";
|
|
8
|
-
import {
|
|
8
|
+
import { ModelPrimaryKeyNames, ModelRecord, ModelSchema } from "./ModelSchema";
|
|
9
9
|
/**
|
|
10
10
|
* Events that can be emitted by the ModelRepository
|
|
11
11
|
*/
|
|
12
12
|
export type ModelEventListeners = {
|
|
13
|
-
model_added: (model:
|
|
14
|
-
model_removed: (model:
|
|
15
|
-
|
|
16
|
-
task_model_disconnected: (task: string, model: string) => void;
|
|
17
|
-
model_updated: (model: Model) => void;
|
|
13
|
+
model_added: (model: ModelRecord) => void;
|
|
14
|
+
model_removed: (model: ModelRecord) => void;
|
|
15
|
+
model_updated: (model: ModelRecord) => void;
|
|
18
16
|
};
|
|
19
17
|
export type ModelEvents = keyof ModelEventListeners;
|
|
20
18
|
export type ModelEventListener<Event extends ModelEvents> = ModelEventListeners[Event];
|
|
21
19
|
export type ModelEventParameters<Event extends ModelEvents> = EventParameters<ModelEventListeners, Event>;
|
|
22
|
-
export declare const ModelSchema: {
|
|
23
|
-
readonly type: "object";
|
|
24
|
-
readonly properties: {
|
|
25
|
-
readonly name: {
|
|
26
|
-
readonly type: "string";
|
|
27
|
-
};
|
|
28
|
-
readonly details: {
|
|
29
|
-
readonly type: "string";
|
|
30
|
-
};
|
|
31
|
-
};
|
|
32
|
-
readonly required: readonly ["name", "details"];
|
|
33
|
-
readonly additionalProperties: false;
|
|
34
|
-
};
|
|
35
|
-
export declare const ModelPrimaryKeyNames: readonly ["name"];
|
|
36
20
|
/**
|
|
37
|
-
*
|
|
38
|
-
*/
|
|
39
|
-
export declare const Task2ModelSchema: {
|
|
40
|
-
readonly type: "object";
|
|
41
|
-
readonly properties: {
|
|
42
|
-
readonly task: {
|
|
43
|
-
readonly type: "string";
|
|
44
|
-
};
|
|
45
|
-
readonly model: {
|
|
46
|
-
readonly type: "string";
|
|
47
|
-
};
|
|
48
|
-
};
|
|
49
|
-
readonly required: readonly ["task", "model"];
|
|
50
|
-
readonly additionalProperties: false;
|
|
51
|
-
};
|
|
52
|
-
export declare const Task2ModelPrimaryKeyNames: readonly ["task", "model"];
|
|
53
|
-
/**
|
|
54
|
-
* Abstract base class for managing AI models and their relationships with tasks.
|
|
21
|
+
* Base class for managing AI models and their relationships with tasks.
|
|
55
22
|
* Provides functionality for storing, retrieving, and managing the lifecycle of models
|
|
56
23
|
* and their associations with specific tasks.
|
|
57
24
|
*/
|
|
58
|
-
export declare
|
|
59
|
-
/** Repository type identifier */
|
|
60
|
-
type: string;
|
|
25
|
+
export declare class ModelRepository {
|
|
61
26
|
/**
|
|
62
27
|
* Repository for storing and managing Model instances
|
|
63
28
|
*/
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
* Repository for managing relationships between tasks and models
|
|
67
|
-
*/
|
|
68
|
-
abstract task2ModelTabularRepository: TabularRepository<typeof Task2ModelSchema, typeof Task2ModelPrimaryKeyNames>;
|
|
29
|
+
protected readonly modelTabularRepository: TabularRepository<typeof ModelSchema, typeof ModelPrimaryKeyNames>;
|
|
30
|
+
constructor(modelTabularRepository: TabularRepository<typeof ModelSchema, typeof ModelPrimaryKeyNames>);
|
|
69
31
|
/** Event emitter for repository events */
|
|
70
32
|
protected events: EventEmitter<ModelEventListeners>;
|
|
71
33
|
/**
|
|
@@ -96,21 +58,43 @@ export declare abstract class ModelRepository {
|
|
|
96
58
|
* Adds a new model to the repository
|
|
97
59
|
* @param model - The model instance to add
|
|
98
60
|
*/
|
|
99
|
-
addModel(model:
|
|
61
|
+
addModel(model: ModelRecord): Promise<{
|
|
62
|
+
title: string;
|
|
63
|
+
description: string;
|
|
64
|
+
model_id: string;
|
|
65
|
+
tasks: string[];
|
|
66
|
+
provider: string;
|
|
67
|
+
providerConfig: {
|
|
68
|
+
[x: string]: unknown;
|
|
69
|
+
};
|
|
70
|
+
metadata: {
|
|
71
|
+
[x: string]: unknown;
|
|
72
|
+
};
|
|
73
|
+
}>;
|
|
100
74
|
/**
|
|
101
75
|
* Finds all models associated with a specific task
|
|
102
76
|
* @param task - The task identifier to search for
|
|
103
77
|
* @returns Promise resolving to an array of associated models, or undefined if none found
|
|
104
78
|
*/
|
|
105
|
-
findModelsByTask(task: string): Promise<
|
|
106
|
-
|
|
107
|
-
|
|
79
|
+
findModelsByTask(task: string): Promise<{
|
|
80
|
+
title: string;
|
|
81
|
+
description: string;
|
|
82
|
+
model_id: string;
|
|
83
|
+
tasks: string[];
|
|
84
|
+
provider: string;
|
|
85
|
+
providerConfig: {
|
|
86
|
+
[x: string]: unknown;
|
|
87
|
+
};
|
|
88
|
+
metadata: {
|
|
89
|
+
[x: string]: unknown;
|
|
90
|
+
};
|
|
91
|
+
}[] | undefined>;
|
|
108
92
|
/**
|
|
109
93
|
* Finds all tasks associated with a specific model
|
|
110
94
|
* @param model - The model identifier to search for
|
|
111
95
|
* @returns Promise resolving to an array of associated tasks, or undefined if none found
|
|
112
96
|
*/
|
|
113
|
-
findTasksByModel(
|
|
97
|
+
findTasksByModel(model_id: string): Promise<string[] | undefined>;
|
|
114
98
|
/**
|
|
115
99
|
* Enumerates all tasks in the repository
|
|
116
100
|
* @returns Promise resolving to an array of task identifiers
|
|
@@ -120,27 +104,41 @@ export declare abstract class ModelRepository {
|
|
|
120
104
|
* Enumerates all models in the repository
|
|
121
105
|
* @returns Promise resolving to an array of model instances
|
|
122
106
|
*/
|
|
123
|
-
enumerateAllModels(): Promise<
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
107
|
+
enumerateAllModels(): Promise<{
|
|
108
|
+
title: string;
|
|
109
|
+
description: string;
|
|
110
|
+
model_id: string;
|
|
111
|
+
tasks: string[];
|
|
112
|
+
provider: string;
|
|
113
|
+
providerConfig: {
|
|
114
|
+
[x: string]: unknown;
|
|
115
|
+
};
|
|
116
|
+
metadata: {
|
|
117
|
+
[x: string]: unknown;
|
|
118
|
+
};
|
|
119
|
+
}[] | undefined>;
|
|
130
120
|
/**
|
|
131
|
-
* Retrieves a model by its
|
|
132
|
-
* @param
|
|
121
|
+
* Retrieves a model by its identifier
|
|
122
|
+
* @param modelId - The model_id of the model to find
|
|
133
123
|
* @returns Promise resolving to the found model or undefined if not found
|
|
134
124
|
*/
|
|
135
|
-
findByName(
|
|
125
|
+
findByName(model_id: string): Promise<{
|
|
126
|
+
title: string;
|
|
127
|
+
description: string;
|
|
128
|
+
model_id: string;
|
|
129
|
+
tasks: string[];
|
|
130
|
+
provider: string;
|
|
131
|
+
providerConfig: {
|
|
132
|
+
[x: string]: unknown;
|
|
133
|
+
};
|
|
134
|
+
metadata: {
|
|
135
|
+
[x: string]: unknown;
|
|
136
|
+
};
|
|
137
|
+
} | undefined>;
|
|
136
138
|
/**
|
|
137
139
|
* Gets the total number of models in the repository
|
|
138
140
|
* @returns Promise resolving to the number of stored models
|
|
139
141
|
*/
|
|
140
142
|
size(): Promise<number>;
|
|
141
|
-
/**
|
|
142
|
-
* Clears all models from the repository
|
|
143
|
-
*/
|
|
144
|
-
clear(): Promise<void>;
|
|
145
143
|
}
|
|
146
144
|
//# sourceMappingURL=ModelRepository.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ModelRepository.d.ts","sourceRoot":"","sources":["../../src/model/ModelRepository.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,KAAK,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAC3D,OAAO,
|
|
1
|
+
{"version":3,"file":"ModelRepository.d.ts","sourceRoot":"","sources":["../../src/model/ModelRepository.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,KAAK,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAC3D,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAE/D,OAAO,EAAE,oBAAoB,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE/E;;GAEG;AAEH,MAAM,MAAM,mBAAmB,GAAG;IAChC,WAAW,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,IAAI,CAAC;IAC1C,aAAa,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,IAAI,CAAC;IAC5C,aAAa,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,IAAI,CAAC;CAC7C,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG,MAAM,mBAAmB,CAAC;AAEpD,MAAM,MAAM,kBAAkB,CAAC,KAAK,SAAS,WAAW,IAAI,mBAAmB,CAAC,KAAK,CAAC,CAAC;AAEvF,MAAM,MAAM,oBAAoB,CAAC,KAAK,SAAS,WAAW,IAAI,eAAe,CAC3E,mBAAmB,EACnB,KAAK,CACN,CAAC;AAEF;;;;GAIG;AACH,qBAAa,eAAe;IAC1B;;OAEG;IACH,SAAS,CAAC,QAAQ,CAAC,sBAAsB,EAAE,iBAAiB,CAC1D,OAAO,WAAW,EAClB,OAAO,oBAAoB,CAC5B,CAAC;gBAEA,sBAAsB,EAAE,iBAAiB,CAAC,OAAO,WAAW,EAAE,OAAO,oBAAoB,CAAC;IAK5F,0CAA0C;IAC1C,SAAS,CAAC,MAAM,oCAA2C;IAE3D;;;;OAIG;IACH,EAAE,CAAC,KAAK,SAAS,WAAW,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE,EAAE,kBAAkB,CAAC,KAAK,CAAC;IAIxE;;;;OAIG;IACH,GAAG,CAAC,KAAK,SAAS,WAAW,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE,EAAE,kBAAkB,CAAC,KAAK,CAAC;IAIzE;;;;OAIG;IACH,IAAI,CAAC,KAAK,SAAS,WAAW,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE,EAAE,kBAAkB,CAAC,KAAK,CAAC;IAI1E;;;;OAIG;IACH,MAAM,CAAC,KAAK,SAAS,WAAW,EAAE,IAAI,EAAE,KAAK;IAI7C;;;OAGG;IACG,QAAQ,CAAC,KAAK,EAAE,WAAW;;;;;;;;;;;;;IAMjC;;;;OAIG;IACG,gBAAgB,CAAC,IAAI,EAAE,MAAM;;;;;;;;;;;;;IASnC;;;;OAIG;IACG,gBAAgB,CAAC,QAAQ,EAAE,MAAM;IAOvC;;;OAGG;IACG,iBAAiB;IAcvB;;;OAGG;IACG,kBAAkB;;;;;;;;;;;;;IAMxB;;;;OAIG;IACG,UAAU,CAAC,QAAQ,EAAE,MAAM;;;;;;;;;;;;;IAMjC;;;OAGG;IACG,IAAI,IAAI,OAAO,CAAC,MAAM,CAAC;CAG9B"}
|
|
@@ -0,0 +1,42 @@
|
|
|
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 ModelSchema: {
|
|
8
|
+
readonly type: "object";
|
|
9
|
+
readonly properties: {
|
|
10
|
+
readonly model_id: {
|
|
11
|
+
readonly type: "string";
|
|
12
|
+
};
|
|
13
|
+
readonly tasks: {
|
|
14
|
+
readonly type: "array";
|
|
15
|
+
readonly items: {
|
|
16
|
+
readonly type: "string";
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
readonly title: {
|
|
20
|
+
readonly type: "string";
|
|
21
|
+
};
|
|
22
|
+
readonly description: {
|
|
23
|
+
readonly type: "string";
|
|
24
|
+
};
|
|
25
|
+
readonly provider: {
|
|
26
|
+
readonly type: "string";
|
|
27
|
+
};
|
|
28
|
+
readonly providerConfig: {
|
|
29
|
+
readonly type: "object";
|
|
30
|
+
readonly default: {};
|
|
31
|
+
};
|
|
32
|
+
readonly metadata: {
|
|
33
|
+
readonly type: "object";
|
|
34
|
+
readonly default: {};
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
readonly required: readonly ["model_id", "tasks", "provider", "title", "description", "providerConfig", "metadata"];
|
|
38
|
+
readonly additionalProperties: false;
|
|
39
|
+
};
|
|
40
|
+
export type ModelRecord = FromSchema<typeof ModelSchema>;
|
|
41
|
+
export declare const ModelPrimaryKeyNames: readonly ["model_id"];
|
|
42
|
+
//# sourceMappingURL=ModelSchema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ModelSchema.d.ts","sourceRoot":"","sources":["../../src/model/ModelSchema.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAwB,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAElE,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAaiB,CAAC;AAE1C,MAAM,MAAM,WAAW,GAAG,UAAU,CAAC,OAAO,WAAW,CAAC,CAAC;AACzD,eAAO,MAAM,oBAAoB,uBAAwB,CAAC"}
|
package/dist/node.js
CHANGED
|
@@ -6,34 +6,20 @@ import {
|
|
|
6
6
|
PermanentJobError
|
|
7
7
|
} from "@workglow/job-queue";
|
|
8
8
|
|
|
9
|
-
// src/model/
|
|
9
|
+
// src/model/ModelRegistry.ts
|
|
10
|
+
import { createServiceToken, globalServiceRegistry } from "@workglow/util";
|
|
11
|
+
|
|
12
|
+
// src/model/InMemoryModelRepository.ts
|
|
10
13
|
import { InMemoryTabularRepository } from "@workglow/storage";
|
|
11
14
|
|
|
12
15
|
// src/model/ModelRepository.ts
|
|
13
16
|
import { EventEmitter } from "@workglow/util";
|
|
14
|
-
var ModelSchema = {
|
|
15
|
-
type: "object",
|
|
16
|
-
properties: {
|
|
17
|
-
name: { type: "string" },
|
|
18
|
-
details: { type: "string" }
|
|
19
|
-
},
|
|
20
|
-
required: ["name", "details"],
|
|
21
|
-
additionalProperties: false
|
|
22
|
-
};
|
|
23
|
-
var ModelPrimaryKeyNames = ["name"];
|
|
24
|
-
var Task2ModelSchema = {
|
|
25
|
-
type: "object",
|
|
26
|
-
properties: {
|
|
27
|
-
task: { type: "string" },
|
|
28
|
-
model: { type: "string" }
|
|
29
|
-
},
|
|
30
|
-
required: ["task", "model"],
|
|
31
|
-
additionalProperties: false
|
|
32
|
-
};
|
|
33
|
-
var Task2ModelPrimaryKeyNames = ["task", "model"];
|
|
34
17
|
|
|
35
18
|
class ModelRepository {
|
|
36
|
-
|
|
19
|
+
modelTabularRepository;
|
|
20
|
+
constructor(modelTabularRepository) {
|
|
21
|
+
this.modelTabularRepository = modelTabularRepository;
|
|
22
|
+
}
|
|
37
23
|
events = new EventEmitter;
|
|
38
24
|
on(name, fn) {
|
|
39
25
|
this.events.on(name, fn);
|
|
@@ -48,101 +34,98 @@ class ModelRepository {
|
|
|
48
34
|
return this.events.waitOn(name);
|
|
49
35
|
}
|
|
50
36
|
async addModel(model) {
|
|
51
|
-
await this.modelTabularRepository.put(
|
|
52
|
-
this.models.set(model.name, model);
|
|
37
|
+
await this.modelTabularRepository.put(model);
|
|
53
38
|
this.events.emit("model_added", model);
|
|
54
39
|
return model;
|
|
55
40
|
}
|
|
56
41
|
async findModelsByTask(task) {
|
|
57
42
|
if (typeof task != "string")
|
|
58
43
|
return;
|
|
59
|
-
const
|
|
60
|
-
if (!
|
|
44
|
+
const allModels = await this.modelTabularRepository.getAll();
|
|
45
|
+
if (!allModels || allModels.length === 0)
|
|
46
|
+
return;
|
|
47
|
+
const models = allModels.filter((model) => model.tasks?.includes(task));
|
|
48
|
+
if (models.length === 0)
|
|
61
49
|
return;
|
|
62
|
-
const models = [];
|
|
63
|
-
for (const junction of junctions) {
|
|
64
|
-
const model = await this.modelTabularRepository.get({ name: junction.model });
|
|
65
|
-
if (model)
|
|
66
|
-
models.push(JSON.parse(model.details));
|
|
67
|
-
}
|
|
68
|
-
models.forEach((m) => this.models.set(m.name, m));
|
|
69
|
-
this.taskModels.set(task, models);
|
|
70
50
|
return models;
|
|
71
51
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
async findTasksByModel(model) {
|
|
75
|
-
if (typeof model != "string")
|
|
52
|
+
async findTasksByModel(model_id) {
|
|
53
|
+
if (typeof model_id != "string")
|
|
76
54
|
return;
|
|
77
|
-
const
|
|
78
|
-
if (!
|
|
55
|
+
const modelRecord = await this.modelTabularRepository.get({ model_id });
|
|
56
|
+
if (!modelRecord)
|
|
79
57
|
return;
|
|
80
|
-
return
|
|
58
|
+
return modelRecord.tasks && modelRecord.tasks.length > 0 ? modelRecord.tasks : undefined;
|
|
81
59
|
}
|
|
82
60
|
async enumerateAllTasks() {
|
|
83
|
-
const
|
|
84
|
-
if (!
|
|
61
|
+
const allModels = await this.modelTabularRepository.getAll();
|
|
62
|
+
if (!allModels || allModels.length === 0)
|
|
85
63
|
return;
|
|
86
|
-
const uniqueTasks =
|
|
87
|
-
|
|
64
|
+
const uniqueTasks = new Set;
|
|
65
|
+
for (const model of allModels) {
|
|
66
|
+
if (model.tasks) {
|
|
67
|
+
for (const task of model.tasks) {
|
|
68
|
+
uniqueTasks.add(task);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return uniqueTasks.size > 0 ? Array.from(uniqueTasks) : undefined;
|
|
88
73
|
}
|
|
89
74
|
async enumerateAllModels() {
|
|
90
75
|
const models = await this.modelTabularRepository.getAll();
|
|
91
76
|
if (!models || models.length === 0)
|
|
92
77
|
return;
|
|
93
|
-
|
|
94
|
-
parsedModels.forEach((m) => this.models.set(m.name, m));
|
|
95
|
-
return parsedModels;
|
|
96
|
-
}
|
|
97
|
-
async connectTaskToModel(task, model) {
|
|
98
|
-
await this.task2ModelTabularRepository.put({ task, model });
|
|
99
|
-
this.events.emit("task_model_connected", task, model);
|
|
78
|
+
return models;
|
|
100
79
|
}
|
|
101
|
-
async findByName(
|
|
102
|
-
if (typeof
|
|
103
|
-
return;
|
|
104
|
-
const modelstr = await this.modelTabularRepository.get({ name });
|
|
105
|
-
if (!modelstr)
|
|
80
|
+
async findByName(model_id) {
|
|
81
|
+
if (typeof model_id != "string")
|
|
106
82
|
return;
|
|
107
|
-
const model =
|
|
108
|
-
|
|
109
|
-
return model;
|
|
83
|
+
const model = await this.modelTabularRepository.get({ model_id });
|
|
84
|
+
return model ?? undefined;
|
|
110
85
|
}
|
|
111
86
|
async size() {
|
|
112
87
|
return await this.modelTabularRepository.size();
|
|
113
88
|
}
|
|
114
|
-
async clear() {
|
|
115
|
-
await this.modelTabularRepository.deleteAll();
|
|
116
|
-
}
|
|
117
89
|
}
|
|
118
90
|
|
|
119
|
-
// src/model/
|
|
91
|
+
// src/model/ModelSchema.ts
|
|
92
|
+
var ModelSchema = {
|
|
93
|
+
type: "object",
|
|
94
|
+
properties: {
|
|
95
|
+
model_id: { type: "string" },
|
|
96
|
+
tasks: { type: "array", items: { type: "string" } },
|
|
97
|
+
title: { type: "string" },
|
|
98
|
+
description: { type: "string" },
|
|
99
|
+
provider: { type: "string" },
|
|
100
|
+
providerConfig: { type: "object", default: {} },
|
|
101
|
+
metadata: { type: "object", default: {} }
|
|
102
|
+
},
|
|
103
|
+
required: ["model_id", "tasks", "provider", "title", "description", "providerConfig", "metadata"],
|
|
104
|
+
additionalProperties: false
|
|
105
|
+
};
|
|
106
|
+
var ModelPrimaryKeyNames = ["model_id"];
|
|
107
|
+
|
|
108
|
+
// src/model/InMemoryModelRepository.ts
|
|
120
109
|
class InMemoryModelRepository extends ModelRepository {
|
|
121
|
-
modelTabularRepository;
|
|
122
|
-
task2ModelTabularRepository;
|
|
123
|
-
type = "InMemoryModelRepository";
|
|
124
110
|
constructor() {
|
|
125
|
-
super();
|
|
126
|
-
this.modelTabularRepository = new InMemoryTabularRepository(ModelSchema, ModelPrimaryKeyNames);
|
|
127
|
-
this.task2ModelTabularRepository = new InMemoryTabularRepository(Task2ModelSchema, Task2ModelPrimaryKeyNames, ["model"]);
|
|
111
|
+
super(new InMemoryTabularRepository(ModelSchema, ModelPrimaryKeyNames));
|
|
128
112
|
}
|
|
129
113
|
}
|
|
130
114
|
|
|
131
115
|
// src/model/ModelRegistry.ts
|
|
132
|
-
|
|
116
|
+
var MODEL_REPOSITORY = createServiceToken("model.repository");
|
|
117
|
+
if (!globalServiceRegistry.has(MODEL_REPOSITORY)) {
|
|
118
|
+
globalServiceRegistry.register(MODEL_REPOSITORY, () => new InMemoryModelRepository, true);
|
|
133
119
|
}
|
|
134
|
-
var modelRegistry;
|
|
135
120
|
function getGlobalModelRepository() {
|
|
136
|
-
|
|
137
|
-
modelRegistry = new FallbackModelRegistry;
|
|
138
|
-
return modelRegistry;
|
|
121
|
+
return globalServiceRegistry.get(MODEL_REPOSITORY);
|
|
139
122
|
}
|
|
140
123
|
function setGlobalModelRepository(pr) {
|
|
141
|
-
|
|
124
|
+
globalServiceRegistry.registerInstance(MODEL_REPOSITORY, pr);
|
|
142
125
|
}
|
|
143
126
|
|
|
144
127
|
// src/provider/AiProviderRegistry.ts
|
|
145
|
-
import { globalServiceRegistry, WORKER_MANAGER } from "@workglow/util";
|
|
128
|
+
import { globalServiceRegistry as globalServiceRegistry2, WORKER_MANAGER } from "@workglow/util";
|
|
146
129
|
|
|
147
130
|
class AiProviderRegistry {
|
|
148
131
|
runFnRegistry = new Map;
|
|
@@ -154,7 +137,7 @@ class AiProviderRegistry {
|
|
|
154
137
|
}
|
|
155
138
|
registerAsWorkerRunFn(modelProvider, taskType) {
|
|
156
139
|
const workerFn = async (input, model, update_progress, signal) => {
|
|
157
|
-
const workerManager =
|
|
140
|
+
const workerManager = globalServiceRegistry2.get(WORKER_MANAGER);
|
|
158
141
|
const result = await workerManager.callWorkerFunction(modelProvider, taskType, [input, model], {
|
|
159
142
|
signal,
|
|
160
143
|
onProgress: update_progress
|
|
@@ -536,7 +519,7 @@ class AiTask extends JobQueueTask {
|
|
|
536
519
|
for (const [key, propSchema] of modelTaskProperties) {
|
|
537
520
|
let requestedModels = Array.isArray(input[key]) ? input[key] : [input[key]];
|
|
538
521
|
for (const model of requestedModels) {
|
|
539
|
-
const foundModel = taskModels?.find((m) => m.
|
|
522
|
+
const foundModel = taskModels?.find((m) => m.model_id === model);
|
|
540
523
|
if (!foundModel) {
|
|
541
524
|
throw new TaskConfigurationError(`AiTask: Missing model for '${key}' named '${model}' for task '${this.type}'`);
|
|
542
525
|
}
|
|
@@ -570,7 +553,7 @@ class AiTask extends JobQueueTask {
|
|
|
570
553
|
const taskModels = await getGlobalModelRepository().findModelsByTask(this.type);
|
|
571
554
|
for (const [key, propSchema] of modelTaskProperties) {
|
|
572
555
|
let requestedModels = Array.isArray(input[key]) ? input[key] : [input[key]];
|
|
573
|
-
let usingModels = requestedModels.filter((model) => taskModels?.find((m) => m.
|
|
556
|
+
let usingModels = requestedModels.filter((model) => taskModels?.find((m) => m.model_id === model));
|
|
574
557
|
usingModels = usingModels.length > 1 ? usingModels : usingModels[0];
|
|
575
558
|
input[key] = usingModels;
|
|
576
559
|
}
|
|
@@ -667,7 +650,7 @@ var TypeLanguage = (annotations = {}) => ({
|
|
|
667
650
|
minLength: 2,
|
|
668
651
|
...annotations
|
|
669
652
|
});
|
|
670
|
-
function
|
|
653
|
+
function TypeModelAsString(semantic = "model", options = {}) {
|
|
671
654
|
if (semantic !== "model" && !semantic.startsWith("model:")) {
|
|
672
655
|
throw new Error("Invalid semantic value");
|
|
673
656
|
}
|
|
@@ -680,6 +663,11 @@ function TypeModel(semantic = "model", options = {}) {
|
|
|
680
663
|
type: "string"
|
|
681
664
|
};
|
|
682
665
|
}
|
|
666
|
+
function TypeModel(semantic = "model", options = {}) {
|
|
667
|
+
return {
|
|
668
|
+
oneOf: [TypeModelAsString(semantic, options), ModelSchema]
|
|
669
|
+
};
|
|
670
|
+
}
|
|
683
671
|
var TypeReplicateArray = (type, annotations = {}) => ({
|
|
684
672
|
oneOf: [type, { type: "array", items: type }],
|
|
685
673
|
title: type.title,
|
|
@@ -1303,42 +1291,6 @@ function normalize(vector) {
|
|
|
1303
1291
|
}
|
|
1304
1292
|
return new Float32Array(normalized);
|
|
1305
1293
|
}
|
|
1306
|
-
// src/model/storage/IndexedDbModelRepository.ts
|
|
1307
|
-
import { IndexedDbTabularRepository } from "@workglow/storage";
|
|
1308
|
-
class IndexedDbModelRepository extends ModelRepository {
|
|
1309
|
-
modelTabularRepository;
|
|
1310
|
-
task2ModelTabularRepository;
|
|
1311
|
-
type = "IndexedDbModelRepository";
|
|
1312
|
-
constructor(tableModels = "models", tableTask2Models = "task2models") {
|
|
1313
|
-
super();
|
|
1314
|
-
this.modelTabularRepository = new IndexedDbTabularRepository(tableModels, ModelSchema, ModelPrimaryKeyNames);
|
|
1315
|
-
this.task2ModelTabularRepository = new IndexedDbTabularRepository(tableTask2Models, Task2ModelSchema, Task2ModelPrimaryKeyNames, ["model"]);
|
|
1316
|
-
}
|
|
1317
|
-
}
|
|
1318
|
-
// src/model/storage/PostgresModelRepository.ts
|
|
1319
|
-
import { PostgresTabularRepository } from "@workglow/storage";
|
|
1320
|
-
class PostgresModelRepository extends ModelRepository {
|
|
1321
|
-
type = "PostgresModelRepository";
|
|
1322
|
-
modelTabularRepository;
|
|
1323
|
-
task2ModelTabularRepository;
|
|
1324
|
-
constructor(db, tableModels = "aimodel", tableTask2Models = "aitask2aimodel") {
|
|
1325
|
-
super();
|
|
1326
|
-
this.modelTabularRepository = new PostgresTabularRepository(db, tableModels, ModelSchema, ModelPrimaryKeyNames);
|
|
1327
|
-
this.task2ModelTabularRepository = new PostgresTabularRepository(db, tableTask2Models, Task2ModelSchema, Task2ModelPrimaryKeyNames, ["model"]);
|
|
1328
|
-
}
|
|
1329
|
-
}
|
|
1330
|
-
// src/model/storage/SqliteModelRepository.ts
|
|
1331
|
-
import { SqliteTabularRepository } from "@workglow/storage";
|
|
1332
|
-
class SqliteModelRepository extends ModelRepository {
|
|
1333
|
-
type = "SqliteModelRepository";
|
|
1334
|
-
modelTabularRepository;
|
|
1335
|
-
task2ModelTabularRepository;
|
|
1336
|
-
constructor(dbOrPath, tableModels = "aimodel", tableTask2Models = "aitask2aimodel") {
|
|
1337
|
-
super();
|
|
1338
|
-
this.modelTabularRepository = new SqliteTabularRepository(dbOrPath, tableModels, ModelSchema, ModelPrimaryKeyNames);
|
|
1339
|
-
this.task2ModelTabularRepository = new SqliteTabularRepository(dbOrPath, tableTask2Models, Task2ModelSchema, Task2ModelPrimaryKeyNames, ["model"]);
|
|
1340
|
-
}
|
|
1341
|
-
}
|
|
1342
1294
|
export {
|
|
1343
1295
|
setGlobalModelRepository,
|
|
1344
1296
|
setAiProviderRegistry,
|
|
@@ -1350,6 +1302,7 @@ export {
|
|
|
1350
1302
|
VectorSimilarityTask,
|
|
1351
1303
|
TypedArraySchema,
|
|
1352
1304
|
TypeReplicateArray,
|
|
1305
|
+
TypeModelAsString,
|
|
1353
1306
|
TypeModel,
|
|
1354
1307
|
TypeLanguage,
|
|
1355
1308
|
TextTranslationTask,
|
|
@@ -1377,17 +1330,13 @@ export {
|
|
|
1377
1330
|
TextEmbeddingOutputSchema,
|
|
1378
1331
|
TextEmbeddingInputSchema,
|
|
1379
1332
|
TextEmbedding,
|
|
1380
|
-
Task2ModelSchema,
|
|
1381
|
-
Task2ModelPrimaryKeyNames,
|
|
1382
1333
|
TableFragment,
|
|
1383
|
-
SqliteModelRepository,
|
|
1384
1334
|
SimilarityFn,
|
|
1385
1335
|
Similarity,
|
|
1386
|
-
PostgresModelRepository,
|
|
1387
1336
|
ModelSchema,
|
|
1388
1337
|
ModelRepository,
|
|
1389
1338
|
ModelPrimaryKeyNames,
|
|
1390
|
-
|
|
1339
|
+
MODEL_REPOSITORY,
|
|
1391
1340
|
InMemoryModelRepository,
|
|
1392
1341
|
ImageFragment,
|
|
1393
1342
|
DownloadModelTask,
|
|
@@ -1404,4 +1353,4 @@ export {
|
|
|
1404
1353
|
AiJob
|
|
1405
1354
|
};
|
|
1406
1355
|
|
|
1407
|
-
//# debugId=
|
|
1356
|
+
//# debugId=2B7F40AEBFE9094764756E2164756E21
|