@workglow/ai 0.2.16 → 0.2.17

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/node.js CHANGED
@@ -14,7 +14,7 @@ import { globalServiceRegistry, WORKER_MANAGER } from "@workglow/util/worker";
14
14
  class AiProviderRegistry {
15
15
  runFnRegistry = new Map;
16
16
  streamFnRegistry = new Map;
17
- reactiveRunFnRegistry = new Map;
17
+ previewRunFnRegistry = new Map;
18
18
  providers = new Map;
19
19
  strategyResolvers = new Map;
20
20
  defaultStrategy;
@@ -30,7 +30,7 @@ class AiProviderRegistry {
30
30
  for (const [, providerMap] of this.streamFnRegistry) {
31
31
  providerMap.delete(name);
32
32
  }
33
- for (const [, providerMap] of this.reactiveRunFnRegistry) {
33
+ for (const [, providerMap] of this.previewRunFnRegistry) {
34
34
  providerMap.delete(name);
35
35
  }
36
36
  }
@@ -108,25 +108,24 @@ class AiProviderRegistry {
108
108
  const taskTypeMap = this.streamFnRegistry.get(taskType);
109
109
  return taskTypeMap?.get(modelProvider);
110
110
  }
111
- registerAsWorkerReactiveRunFn(modelProvider, taskType) {
112
- const reactiveFn = async (input, output, model) => {
111
+ registerAsWorkerPreviewRunFn(modelProvider, taskType) {
112
+ const previewFn = async (input, model) => {
113
113
  const workerManager = globalServiceRegistry.get(WORKER_MANAGER);
114
- return workerManager.callWorkerReactiveFunction(modelProvider, taskType, [
114
+ return workerManager.callWorkerPreviewFunction(modelProvider, taskType, [
115
115
  input,
116
- output,
117
116
  model
118
117
  ]);
119
118
  };
120
- this.registerReactiveRunFn(modelProvider, taskType, reactiveFn);
119
+ this.registerPreviewRunFn(modelProvider, taskType, previewFn);
121
120
  }
122
- registerReactiveRunFn(modelProvider, taskType, reactiveRunFn) {
123
- if (!this.reactiveRunFnRegistry.has(taskType)) {
124
- this.reactiveRunFnRegistry.set(taskType, new Map);
121
+ registerPreviewRunFn(modelProvider, taskType, previewRunFn) {
122
+ if (!this.previewRunFnRegistry.has(taskType)) {
123
+ this.previewRunFnRegistry.set(taskType, new Map);
125
124
  }
126
- this.reactiveRunFnRegistry.get(taskType).set(modelProvider, reactiveRunFn);
125
+ this.previewRunFnRegistry.get(taskType).set(modelProvider, previewRunFn);
127
126
  }
128
- getReactiveRunFn(modelProvider, taskType) {
129
- const taskTypeMap = this.reactiveRunFnRegistry.get(taskType);
127
+ getPreviewRunFn(modelProvider, taskType) {
128
+ const taskTypeMap = this.previewRunFnRegistry.get(taskType);
130
129
  return taskTypeMap?.get(modelProvider);
131
130
  }
132
131
  getDirectRunFn(modelProvider, taskType) {
@@ -721,11 +720,11 @@ function resolveAiProviderGpuQueueConcurrency(concurrency) {
721
720
  class AiProvider {
722
721
  tasks;
723
722
  streamTasks;
724
- reactiveTasks;
725
- constructor(tasks, streamTasks, reactiveTasks) {
723
+ previewTasks;
724
+ constructor(tasks, streamTasks, previewTasks) {
726
725
  this.tasks = tasks;
727
726
  this.streamTasks = streamTasks;
728
- this.reactiveTasks = reactiveTasks;
727
+ this.previewTasks = previewTasks;
729
728
  }
730
729
  get supportedTaskTypes() {
731
730
  return this.taskTypes;
@@ -736,8 +735,8 @@ class AiProvider {
736
735
  getStreamFn(taskType) {
737
736
  return this.streamTasks?.[taskType];
738
737
  }
739
- getReactiveRunFn(taskType) {
740
- return this.reactiveTasks?.[taskType];
738
+ getPreviewRunFn(taskType) {
739
+ return this.previewTasks?.[taskType];
741
740
  }
742
741
  async register(options = {}) {
743
742
  const isInline = !!this.tasks;
@@ -765,7 +764,7 @@ class AiProvider {
765
764
  for (const taskType of this.taskTypes) {
766
765
  registry.registerAsWorkerRunFn(this.name, taskType);
767
766
  registry.registerAsWorkerStreamFn(this.name, taskType);
768
- registry.registerAsWorkerReactiveRunFn(this.name, taskType);
767
+ registry.registerAsWorkerPreviewRunFn(this.name, taskType);
769
768
  }
770
769
  } else {
771
770
  for (const [taskType, fn] of Object.entries(this.tasks)) {
@@ -777,9 +776,9 @@ class AiProvider {
777
776
  }
778
777
  }
779
778
  }
780
- if (this.reactiveTasks) {
781
- for (const [taskType, fn] of Object.entries(this.reactiveTasks)) {
782
- registry.registerReactiveRunFn(this.name, taskType, fn);
779
+ if (this.previewTasks) {
780
+ for (const [taskType, fn] of Object.entries(this.previewTasks)) {
781
+ registry.registerPreviewRunFn(this.name, taskType, fn);
783
782
  }
784
783
  }
785
784
  registry.registerProvider(this);
@@ -802,9 +801,9 @@ class AiProvider {
802
801
  workerServer.registerStreamFunction(taskType, fn);
803
802
  }
804
803
  }
805
- if (this.reactiveTasks) {
806
- for (const [taskType, fn] of Object.entries(this.reactiveTasks)) {
807
- workerServer.registerReactiveFunction(taskType, fn);
804
+ if (this.previewTasks) {
805
+ for (const [taskType, fn] of Object.entries(this.previewTasks)) {
806
+ workerServer.registerPreviewFunction(taskType, fn);
808
807
  }
809
808
  }
810
809
  }
@@ -1111,16 +1110,16 @@ class AiTask extends Task {
1111
1110
  const model = input.model;
1112
1111
  return model?.provider;
1113
1112
  }
1114
- async executeReactive(input, output, context) {
1113
+ async executePreview(input, context) {
1115
1114
  const model = input.model;
1116
1115
  if (model && typeof model === "object" && model.provider) {
1117
1116
  const taskType = this.constructor.runtype ?? this.constructor.type;
1118
- const reactiveFn = getAiProviderRegistry().getReactiveRunFn(model.provider, taskType);
1119
- if (reactiveFn) {
1120
- return reactiveFn(input, output, model);
1117
+ const previewFn = getAiProviderRegistry().getPreviewRunFn(model.provider, taskType);
1118
+ if (previewFn) {
1119
+ return previewFn(input, model);
1121
1120
  }
1122
1121
  }
1123
- return super.executeReactive(input, output, context);
1122
+ return super.executePreview(input, context);
1124
1123
  }
1125
1124
  async validateInput(input) {
1126
1125
  const inputSchema = this.inputSchema();
@@ -2030,7 +2029,11 @@ Workflow4.prototype.chunkVectorUpsert = CreateWorkflow4(ChunkVectorUpsertTask);
2030
2029
 
2031
2030
  // src/task/ContextBuilderTask.ts
2032
2031
  import { estimateTokens } from "@workglow/knowledge-base";
2033
- import { CreateWorkflow as CreateWorkflow6, Task as Task4, Workflow as Workflow6 } from "@workglow/task-graph";
2032
+ import {
2033
+ CreateWorkflow as CreateWorkflow6,
2034
+ Task as Task4,
2035
+ Workflow as Workflow6
2036
+ } from "@workglow/task-graph";
2034
2037
 
2035
2038
  // src/task/CountTokensTask.ts
2036
2039
  import { CreateWorkflow as CreateWorkflow5, Workflow as Workflow5 } from "@workglow/task-graph";
@@ -2196,7 +2199,10 @@ class ContextBuilderTask extends Task4 {
2196
2199
  static outputSchema() {
2197
2200
  return outputSchema3;
2198
2201
  }
2199
- async executeReactive(input, _output, context) {
2202
+ async execute(input, context) {
2203
+ return this.executePreview(input, context);
2204
+ }
2205
+ async executePreview(input, context) {
2200
2206
  const {
2201
2207
  chunks,
2202
2208
  metadata = [],
@@ -6674,7 +6680,10 @@ class VectorQuantizeTask extends Task16 {
6674
6680
  static outputSchema() {
6675
6681
  return outputSchema14;
6676
6682
  }
6677
- async executeReactive(input) {
6683
+ async execute(input) {
6684
+ return this.executePreview(input);
6685
+ }
6686
+ async executePreview(input) {
6678
6687
  const { vector, targetType, normalize = true } = input;
6679
6688
  const isArray = Array.isArray(vector);
6680
6689
  const vectors = isArray ? vector : [vector];
@@ -6849,7 +6858,15 @@ class VectorSimilarityTask extends GraphAsTask {
6849
6858
  static outputSchema() {
6850
6859
  return SimilarityOutputSchema;
6851
6860
  }
6852
- async executeReactive({ query, vectors, method, topK }) {
6861
+ async execute(input) {
6862
+ return this.executePreview(input);
6863
+ }
6864
+ async executePreview({
6865
+ query,
6866
+ vectors,
6867
+ method,
6868
+ topK
6869
+ }) {
6853
6870
  let similarities = [];
6854
6871
  const fnName = method;
6855
6872
  const fn = similarityFunctions[fnName];
@@ -7260,4 +7277,4 @@ export {
7260
7277
  AiChatInputSchema
7261
7278
  };
7262
7279
 
7263
- //# debugId=89474E7F4F6A44CB64756E2164756E21
7280
+ //# debugId=819459ADB283D9E664756E2164756E21