@memberjunction/server 5.21.0 → 5.22.0

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.
Files changed (34) hide show
  1. package/README.md +9 -0
  2. package/dist/agents/skip-sdk.d.ts.map +1 -1
  3. package/dist/agents/skip-sdk.js +32 -2
  4. package/dist/agents/skip-sdk.js.map +1 -1
  5. package/dist/generated/generated.d.ts +24 -0
  6. package/dist/generated/generated.d.ts.map +1 -1
  7. package/dist/generated/generated.js +113 -0
  8. package/dist/generated/generated.js.map +1 -1
  9. package/dist/index.d.ts +3 -0
  10. package/dist/index.d.ts.map +1 -1
  11. package/dist/index.js +3 -0
  12. package/dist/index.js.map +1 -1
  13. package/dist/resolvers/PipelineProgressResolver.d.ts +33 -0
  14. package/dist/resolvers/PipelineProgressResolver.d.ts.map +1 -0
  15. package/dist/resolvers/PipelineProgressResolver.js +138 -0
  16. package/dist/resolvers/PipelineProgressResolver.js.map +1 -0
  17. package/dist/resolvers/RunAIAgentResolver.js +4 -4
  18. package/dist/resolvers/RunAIAgentResolver.js.map +1 -1
  19. package/dist/resolvers/SearchKnowledgeResolver.d.ts +85 -0
  20. package/dist/resolvers/SearchKnowledgeResolver.d.ts.map +1 -0
  21. package/dist/resolvers/SearchKnowledgeResolver.js +587 -0
  22. package/dist/resolvers/SearchKnowledgeResolver.js.map +1 -0
  23. package/dist/resolvers/VectorizeEntityResolver.d.ts +21 -0
  24. package/dist/resolvers/VectorizeEntityResolver.d.ts.map +1 -0
  25. package/dist/resolvers/VectorizeEntityResolver.js +134 -0
  26. package/dist/resolvers/VectorizeEntityResolver.js.map +1 -0
  27. package/package.json +63 -62
  28. package/src/agents/skip-sdk.ts +31 -2
  29. package/src/generated/generated.ts +83 -0
  30. package/src/index.ts +3 -0
  31. package/src/resolvers/PipelineProgressResolver.ts +107 -0
  32. package/src/resolvers/RunAIAgentResolver.ts +4 -4
  33. package/src/resolvers/SearchKnowledgeResolver.ts +614 -0
  34. package/src/resolvers/VectorizeEntityResolver.ts +123 -0
@@ -0,0 +1,123 @@
1
+ import { Resolver, Mutation, Arg, Ctx, ObjectType, Field, Float } from 'type-graphql';
2
+ import { AppContext } from '../types.js';
3
+ import { LogError, LogStatus, UserInfo } from '@memberjunction/core';
4
+ import { ResolverBase } from '../generic/ResolverBase.js';
5
+ import { EntityVectorSyncer, VectorizeEntityParams, VectorizeProgressUpdate } from '@memberjunction/ai-vector-sync';
6
+ import { PubSubManager } from '../generic/PubSubManager.js';
7
+ import { PipelineProgressNotification } from './PipelineProgressResolver.js';
8
+ import { v4 as uuidv4 } from 'uuid';
9
+
10
+ const PIPELINE_PROGRESS_TOPIC = 'PIPELINE_PROGRESS';
11
+
12
+ @ObjectType()
13
+ export class VectorizeEntityResult {
14
+ @Field()
15
+ Success: boolean;
16
+
17
+ @Field({ nullable: true })
18
+ Status?: string;
19
+
20
+ @Field({ nullable: true })
21
+ ErrorMessage?: string;
22
+
23
+ @Field({ nullable: true })
24
+ PipelineRunID?: string;
25
+ }
26
+
27
+ @Resolver()
28
+ export class VectorizeEntityResolver extends ResolverBase {
29
+ @Mutation(() => VectorizeEntityResult)
30
+ async VectorizeEntity(
31
+ @Arg('entityDocumentID') entityDocumentID: string,
32
+ @Arg('entityID') entityID: string,
33
+ @Arg('batchSize', () => Float, { nullable: true }) batchSize?: number,
34
+ @Ctx() { userPayload }: AppContext = {} as AppContext
35
+ ): Promise<VectorizeEntityResult> {
36
+ try {
37
+ const currentUser = this.GetUserFromPayload(userPayload);
38
+ if (!currentUser) {
39
+ return { Success: false, Status: 'Error', ErrorMessage: 'Unable to determine current user' };
40
+ }
41
+
42
+ const pipelineRunID = uuidv4();
43
+ LogStatus(`VectorizeEntity: starting pipeline ${pipelineRunID} for entity document ${entityDocumentID}`);
44
+
45
+ // Fire-and-forget: start the pipeline in the background and return immediately.
46
+ // Progress is delivered to the client via the PipelineProgress GraphQL subscription.
47
+ this.runPipelineInBackground(pipelineRunID, entityDocumentID, entityID, batchSize, currentUser);
48
+
49
+ return {
50
+ Success: true,
51
+ Status: 'Started',
52
+ PipelineRunID: pipelineRunID,
53
+ };
54
+ } catch (error) {
55
+ const msg = error instanceof Error ? error.message : String(error);
56
+ LogError(`VectorizeEntity mutation failed: ${msg}`);
57
+ return {
58
+ Success: false,
59
+ Status: 'Error',
60
+ ErrorMessage: msg
61
+ };
62
+ }
63
+ }
64
+
65
+ /**
66
+ * Runs the vectorization pipeline in the background, publishing progress
67
+ * updates via PubSub so the client can subscribe via PipelineProgress.
68
+ */
69
+ private async runPipelineInBackground(
70
+ pipelineRunID: string,
71
+ entityDocumentID: string,
72
+ entityID: string,
73
+ batchSize: number | undefined,
74
+ currentUser: UserInfo
75
+ ): Promise<void> {
76
+ try {
77
+ const syncer = new EntityVectorSyncer();
78
+ await syncer.Config(true, currentUser);
79
+
80
+ const params: VectorizeEntityParams = {
81
+ entityDocumentID,
82
+ entityID,
83
+ listBatchCount: batchSize || 50,
84
+ VectorizeBatchCount: batchSize || 50,
85
+ UpsertBatchCount: batchSize || 50,
86
+ OnProgress: (update: VectorizeProgressUpdate) => {
87
+ LogStatus(`VectorizeEntity pipeline ${pipelineRunID}: ${update.Stage} ${update.ProcessedRecords}/${update.TotalRecords} (${update.PercentComplete}%)`);
88
+ this.publishProgress(pipelineRunID, update);
89
+ },
90
+ };
91
+
92
+ const result = await syncer.VectorizeEntity(params, currentUser);
93
+ LogStatus(`VectorizeEntity pipeline ${pipelineRunID} complete: success=${result.success}`);
94
+ } catch (error) {
95
+ const msg = error instanceof Error ? error.message : String(error);
96
+ LogError(`VectorizeEntity pipeline ${pipelineRunID} failed: ${msg}`);
97
+
98
+ // Publish error notification so the client knows the pipeline failed
99
+ this.publishProgress(pipelineRunID, {
100
+ TotalRecords: 0,
101
+ ProcessedRecords: 0,
102
+ Stage: 'error',
103
+ PercentComplete: 0,
104
+ ElapsedMs: 0,
105
+ });
106
+ }
107
+ }
108
+
109
+ /**
110
+ * Publish a progress update to the PipelineProgress subscription topic.
111
+ */
112
+ private publishProgress(pipelineRunID: string, update: VectorizeProgressUpdate): void {
113
+ const notification: PipelineProgressNotification = {
114
+ PipelineRunID: pipelineRunID,
115
+ Stage: update.Stage,
116
+ TotalItems: update.TotalRecords,
117
+ ProcessedItems: update.ProcessedRecords,
118
+ ElapsedMs: update.ElapsedMs,
119
+ PercentComplete: update.PercentComplete,
120
+ };
121
+ PubSubManager.Instance.Publish(PIPELINE_PROGRESS_TOPIC, { ...notification });
122
+ }
123
+ }