@workglow/ai 0.2.29 → 0.2.31

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 CHANGED
@@ -35,8 +35,12 @@ import {
35
35
  AiJobInput,
36
36
  } from "@workglow/ai";
37
37
  import { Workflow, getTaskQueueRegistry, TaskInput, TaskOutput } from "@workglow/task-graph";
38
- import { ConcurrencyLimiter, JobQueueClient, JobQueueServer } from "@workglow/job-queue";
39
- import { InMemoryQueueStorage } from "@workglow/storage";
38
+ import {
39
+ ConcurrencyLimiter,
40
+ InMemoryQueueStorage,
41
+ JobQueueClient,
42
+ JobQueueServer,
43
+ } from "@workglow/job-queue";
40
44
  import { HF_TRANSFORMERS_ONNX } from "@workglow/ai-provider/hf-transformers";
41
45
  import { registerHuggingFaceTransformersInline } from "@workglow/ai-provider/hf-transformers/runtime";
42
46
 
@@ -438,8 +442,12 @@ Each provider needs a job queue for task execution:
438
442
 
439
443
  ```typescript
440
444
  import { getTaskQueueRegistry, TaskInput, TaskOutput } from "@workglow/task-graph";
441
- import { ConcurrencyLimiter, JobQueueClient, JobQueueServer } from "@workglow/job-queue";
442
- import { InMemoryQueueStorage } from "@workglow/storage";
445
+ import {
446
+ ConcurrencyLimiter,
447
+ InMemoryQueueStorage,
448
+ JobQueueClient,
449
+ JobQueueServer,
450
+ } from "@workglow/job-queue";
443
451
  import { AiJob, AiJobInput } from "@workglow/ai";
444
452
  import { HF_TRANSFORMERS_ONNX } from "@workglow/ai-provider/hf-transformers";
445
453
 
@@ -527,20 +535,20 @@ The AI package provides a comprehensive set of tasks for building RAG pipelines.
527
535
 
528
536
  ### Vector and Storage Tasks
529
537
 
530
- | Task | Description |
531
- | ----------------------- | --------------------------------------------------------------------------------- |
532
- | `ChunkVectorUpsertTask` | Stores chunks + their embeddings in a KnowledgeBase (input: `chunks` + `vector`) |
533
- | `VectorQuantizeTask` | Quantizes vectors for storage efficiency |
538
+ | Task | Description |
539
+ | ----------------------- | -------------------------------------------------------------------------------- |
540
+ | `ChunkVectorUpsertTask` | Stores chunks + their embeddings in a KnowledgeBase (input: `chunks` + `vector`) |
541
+ | `VectorQuantizeTask` | Quantizes vectors for storage efficiency |
534
542
 
535
543
  ### Retrieval and Generation Tasks
536
544
 
537
- | Task | Description |
538
- | -------------------- | ------------------------------------------------------------------------ |
539
- | `ChunkRetrievalTask` | End-to-end retrieval: embeds the query, runs similarity or hybrid search |
540
- | `QueryExpanderTask` | Expands queries (multi-query / synonyms) for better retrieval coverage |
541
- | `RerankerTask` | Reranks search results (simple heuristic or reciprocal-rank-fusion) |
545
+ | Task | Description |
546
+ | -------------------- | --------------------------------------------------------------------------- |
547
+ | `ChunkRetrievalTask` | End-to-end retrieval: embeds the query, runs similarity or hybrid search |
548
+ | `QueryExpanderTask` | Expands queries (multi-query / synonyms) for better retrieval coverage |
549
+ | `RerankerTask` | Reranks search results (simple heuristic or reciprocal-rank-fusion) |
542
550
  | `HierarchyJoinTask` | Enriches retrieved metadata with parent summaries, section titles, entities |
543
- | `ContextBuilderTask` | Builds formatted context for LLM prompts |
551
+ | `ContextBuilderTask` | Builds formatted context for LLM prompts |
544
552
 
545
553
  ### Complete RAG Workflow Example
546
554
 
package/dist/browser.js CHANGED
@@ -10,7 +10,7 @@ import {
10
10
  import { getLogger } from "@workglow/util/worker";
11
11
 
12
12
  // src/provider/AiProviderRegistry.ts
13
- import { globalServiceRegistry, WORKER_MANAGER } from "@workglow/util/worker";
13
+ import { createServiceToken, globalServiceRegistry, WORKER_MANAGER } from "@workglow/util/worker";
14
14
  class AiProviderRegistry {
15
15
  runFnRegistry = new Map;
16
16
  streamFnRegistry = new Map;
@@ -143,13 +143,20 @@ class AiProviderRegistry {
143
143
  return runFn;
144
144
  }
145
145
  }
146
- var providerRegistry = new AiProviderRegistry;
147
- function getAiProviderRegistry() {
148
- return providerRegistry;
146
+ var AI_PROVIDER_REGISTRY = createServiceToken("ai.provider.registry");
147
+ function getAiProviderRegistry(registry = globalServiceRegistry) {
148
+ if (!registry.has(AI_PROVIDER_REGISTRY)) {
149
+ registerAiProviderDefaults(registry);
150
+ }
151
+ return registry.get(AI_PROVIDER_REGISTRY);
152
+ }
153
+ function setAiProviderRegistry(pr, registry = globalServiceRegistry) {
154
+ registry.registerInstance(AI_PROVIDER_REGISTRY, pr);
149
155
  }
150
- function setAiProviderRegistry(pr) {
151
- providerRegistry = pr;
156
+ function registerAiProviderDefaults(registry = globalServiceRegistry) {
157
+ registry.registerIfAbsent(AI_PROVIDER_REGISTRY, () => new AiProviderRegistry, true);
152
158
  }
159
+ registerAiProviderDefaults();
153
160
 
154
161
  // src/errors/ImageGenerationErrors.ts
155
162
  class ProviderUnsupportedFeatureError extends Error {
@@ -701,41 +708,48 @@ class InMemoryModelRepository extends ModelRepository {
701
708
 
702
709
  // src/model/ModelRegistry.ts
703
710
  import {
704
- createServiceToken,
711
+ createServiceToken as createServiceToken2,
705
712
  globalServiceRegistry as globalServiceRegistry2,
706
713
  registerInputCompactor,
707
714
  registerInputResolver
708
715
  } from "@workglow/util";
709
- var MODEL_REPOSITORY = createServiceToken("model.repository");
710
- globalServiceRegistry2.registerIfAbsent(MODEL_REPOSITORY, () => new InMemoryModelRepository, true);
711
- function getGlobalModelRepository() {
712
- return globalServiceRegistry2.get(MODEL_REPOSITORY);
716
+ var MODEL_REPOSITORY = createServiceToken2("model.repository");
717
+ function getGlobalModelRepository(registry = globalServiceRegistry2) {
718
+ if (!registry.has(MODEL_REPOSITORY)) {
719
+ registerModelDefaults(registry);
720
+ }
721
+ return registry.get(MODEL_REPOSITORY);
713
722
  }
714
- function setGlobalModelRepository(repository) {
715
- globalServiceRegistry2.registerInstance(MODEL_REPOSITORY, repository);
723
+ function setGlobalModelRepository(repository, registry = globalServiceRegistry2) {
724
+ registry.registerInstance(MODEL_REPOSITORY, repository);
716
725
  }
717
- async function resolveModelFromRegistry(id, format, registry) {
718
- const modelRepo = registry.has(MODEL_REPOSITORY) ? registry.get(MODEL_REPOSITORY) : getGlobalModelRepository();
726
+ async function resolveModelFromRegistry(id, _format, registry) {
727
+ const modelRepo = getGlobalModelRepository(registry);
719
728
  const model = await modelRepo.findByName(id);
720
729
  if (!model) {
721
730
  throw new Error(`Model "${id}" not found in repository`);
722
731
  }
723
732
  return model;
724
733
  }
725
- registerInputResolver("model", resolveModelFromRegistry);
726
- registerInputCompactor("model", async (value, _format, registry) => {
734
+ async function compactModel(value, _format, registry) {
727
735
  if (typeof value === "object" && value !== null && "model_id" in value) {
728
736
  const id = value.model_id;
729
737
  if (typeof id !== "string")
730
738
  return;
731
- const modelRepo = registry.has(MODEL_REPOSITORY) ? registry.get(MODEL_REPOSITORY) : getGlobalModelRepository();
739
+ const modelRepo = getGlobalModelRepository(registry);
732
740
  const model = await modelRepo.findByName(id);
733
741
  if (!model)
734
742
  return;
735
743
  return id;
736
744
  }
737
745
  return;
738
- });
746
+ }
747
+ function registerModelDefaults(registry = globalServiceRegistry2) {
748
+ registry.registerIfAbsent(MODEL_REPOSITORY, () => new InMemoryModelRepository, true);
749
+ registerInputResolver("model", resolveModelFromRegistry, registry);
750
+ registerInputCompactor("model", compactModel, registry);
751
+ }
752
+ registerModelDefaults();
739
753
 
740
754
  // src/provider/AiProvider.ts
741
755
  import { globalServiceRegistry as globalServiceRegistry3, WORKER_MANAGER as WORKER_MANAGER2 } from "@workglow/util/worker";
@@ -1971,7 +1985,7 @@ var outputSchema2 = {
1971
1985
 
1972
1986
  class ChunkVectorUpsertTask extends Task3 {
1973
1987
  static type = "ChunkVectorUpsertTask";
1974
- static category = "Vector Store";
1988
+ static category = "Document";
1975
1989
  static title = "Add to Vector Store";
1976
1990
  static description = "Store chunks + their embeddings in a knowledge base (1:1 aligned)";
1977
1991
  static cacheable = false;
@@ -2748,8 +2762,11 @@ var documentEnricher = (input, config) => {
2748
2762
  Workflow9.prototype.documentEnricher = CreateWorkflow9(DocumentEnricherTask);
2749
2763
 
2750
2764
  // src/task/DocumentUpsertTask.ts
2751
- import { Document, TypeKnowledgeBase as TypeKnowledgeBase3 } from "@workglow/knowledge-base";
2752
- import { DocumentMetadataSchema } from "@workglow/knowledge-base";
2765
+ import {
2766
+ Document,
2767
+ DocumentMetadataSchema,
2768
+ TypeKnowledgeBase as TypeKnowledgeBase3
2769
+ } from "@workglow/knowledge-base";
2753
2770
  import { CreateWorkflow as CreateWorkflow10, Task as Task6, Workflow as Workflow10 } from "@workglow/task-graph";
2754
2771
  var inputSchema5 = {
2755
2772
  type: "object",
@@ -2797,7 +2814,7 @@ var outputSchema5 = {
2797
2814
 
2798
2815
  class DocumentUpsertTask extends Task6 {
2799
2816
  static type = "DocumentUpsertTask";
2800
- static category = "Vector Store";
2817
+ static category = "Document";
2801
2818
  static title = "Add Document";
2802
2819
  static description = "Persist a parsed document tree to a knowledge base";
2803
2820
  static cacheable = false;
@@ -4133,7 +4150,7 @@ var outputSchema8 = {
4133
4150
 
4134
4151
  class KbToDocumentsTask extends Task9 {
4135
4152
  static type = "KbToDocumentsTask";
4136
- static category = "Vector Store";
4153
+ static category = "Document";
4137
4154
  static title = "Knowledge Base to Documents";
4138
4155
  static description = "List documents from a knowledge base, optionally filtering to only those that need embedding";
4139
4156
  static cacheable = false;
@@ -7267,7 +7284,9 @@ export {
7267
7284
  setAiProviderRegistry,
7268
7285
  resolveAiProviderGpuQueueConcurrency,
7269
7286
  reranker,
7287
+ registerModelDefaults,
7270
7288
  registerAiTasks,
7289
+ registerAiProviderDefaults,
7271
7290
  queryExpander,
7272
7291
  poseLandmarker,
7273
7292
  objectDetection,
@@ -7441,7 +7460,8 @@ export {
7441
7460
  AiImageOutputTask,
7442
7461
  AiChatTask,
7443
7462
  AiChatOutputSchema,
7444
- AiChatInputSchema
7463
+ AiChatInputSchema,
7464
+ AI_PROVIDER_REGISTRY
7445
7465
  };
7446
7466
 
7447
- //# debugId=D9E399F9E044625464756E2164756E21
7467
+ //# debugId=FC532F021ACF6E6364756E2164756E21