@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,107 @@
1
+ import { Resolver, Subscription, Root, ObjectType, Field, Float, Mutation, Arg, Ctx, PubSub, PubSubEngine } from 'type-graphql';
2
+ import { AppContext } from '../types.js';
3
+ import { LogStatus, LogError } from '@memberjunction/core';
4
+ import { ResolverBase } from '../generic/ResolverBase.js';
5
+
6
+ const PIPELINE_PROGRESS_TOPIC = 'PIPELINE_PROGRESS';
7
+
8
+ /**
9
+ * Stage of the knowledge pipeline.
10
+ */
11
+ export type PipelineStageType = 'extract' | 'autotag' | 'vectorize' | 'complete' | 'error';
12
+
13
+ @ObjectType()
14
+ export class PipelineProgressNotification {
15
+ @Field()
16
+ PipelineRunID: string;
17
+
18
+ @Field()
19
+ Stage: string;
20
+
21
+ @Field()
22
+ TotalItems: number;
23
+
24
+ @Field()
25
+ ProcessedItems: number;
26
+
27
+ @Field({ nullable: true })
28
+ CurrentItem?: string;
29
+
30
+ @Field(() => Float)
31
+ ElapsedMs: number;
32
+
33
+ @Field(() => Float, { nullable: true })
34
+ EstimatedRemainingMs?: number;
35
+
36
+ @Field(() => Float)
37
+ PercentComplete: number;
38
+ }
39
+
40
+ @ObjectType()
41
+ export class PipelineStartResult {
42
+ @Field()
43
+ Success: boolean;
44
+
45
+ @Field()
46
+ PipelineRunID: string;
47
+
48
+ @Field({ nullable: true })
49
+ ErrorMessage?: string;
50
+ }
51
+
52
+ @Resolver()
53
+ export class PipelineProgressResolver extends ResolverBase {
54
+ /**
55
+ * Subscribe to pipeline progress notifications for a specific pipeline run.
56
+ */
57
+ @Subscription(() => PipelineProgressNotification, {
58
+ topics: PIPELINE_PROGRESS_TOPIC,
59
+ filter: ({ payload, args }: { payload: PipelineProgressNotification; args: { pipelineRunID: string } }) => {
60
+ return payload.PipelineRunID === args.pipelineRunID;
61
+ },
62
+ })
63
+ PipelineProgress(
64
+ @Root() notification: PipelineProgressNotification,
65
+ @Arg('pipelineRunID') _pipelineRunID: string
66
+ ): PipelineProgressNotification {
67
+ return notification;
68
+ }
69
+
70
+ /**
71
+ * Publish a pipeline progress update. Called internally by the pipeline engine.
72
+ */
73
+ @Mutation(() => Boolean)
74
+ async PublishPipelineProgress(
75
+ @Arg('pipelineRunID') pipelineRunID: string,
76
+ @Arg('stage') stage: string,
77
+ @Arg('totalItems') totalItems: number,
78
+ @Arg('processedItems') processedItems: number,
79
+ @Arg('currentItem', { nullable: true }) currentItem: string | undefined,
80
+ @Arg('elapsedMs', () => Float) elapsedMs: number,
81
+ @Arg('estimatedRemainingMs', () => Float, { nullable: true }) estimatedRemainingMs: number | undefined,
82
+ @PubSub() pubSub: PubSubEngine,
83
+ @Ctx() { userPayload }: AppContext = {} as AppContext
84
+ ): Promise<boolean> {
85
+ try {
86
+ const percentComplete = totalItems > 0 ? Math.round((processedItems / totalItems) * 100) : 0;
87
+
88
+ const notification: PipelineProgressNotification = {
89
+ PipelineRunID: pipelineRunID,
90
+ Stage: stage,
91
+ TotalItems: totalItems,
92
+ ProcessedItems: processedItems,
93
+ CurrentItem: currentItem,
94
+ ElapsedMs: elapsedMs,
95
+ EstimatedRemainingMs: estimatedRemainingMs,
96
+ PercentComplete: percentComplete,
97
+ };
98
+
99
+ await pubSub.publish(PIPELINE_PROGRESS_TOPIC, notification);
100
+ LogStatus(`PipelineProgress: ${stage} ${processedItems}/${totalItems} (${percentComplete}%)`);
101
+ return true;
102
+ } catch (error) {
103
+ LogError(`PipelineProgressResolver.PublishPipelineProgress failed: ${error}`);
104
+ return false;
105
+ }
106
+ }
107
+ }
@@ -390,10 +390,10 @@ export class RunAIAgentResolver extends ResolverBase {
390
390
  // Validate agent
391
391
  const agentEntity = await this.validateAgent(agentId, currentUser);
392
392
 
393
- // @jordanfanapour IMPORTANT TO-DO for various engine classes (via base engine class) and here for AI Agent Runner and for AI Prompt Runner, need to be able to pass in a IMetadataProvider for it to use
394
- // for multi-user server environments like this one
395
- // Create AI agent runner
396
- const agentRunner = new AgentRunner();
393
+ // Create AI agent runner with the per-request isolated provider so all agent DB operations
394
+ // (AIAgentRun, AIAgentRunSteps, AIAgentRequests, AIPromptRuns) never share the global
395
+ // singleton's transaction state with concurrent requests (e.g. conversation deletes).
396
+ const agentRunner = new AgentRunner(p);
397
397
 
398
398
  // Track agent run for streaming (use ref to update later)
399
399
  const agentRunRef = { current: null as any };