@memberjunction/core-entities 2.73.0 → 2.75.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.
@@ -0,0 +1,47 @@
1
+ import { AIPromptRunEntity } from '../generated/entity_subclasses';
2
+ import { ChatMessage } from '@memberjunction/ai';
3
+ /**
4
+ * Extended AIPromptRunEntity class with helper methods for extracting
5
+ * conversation messages and data from the stored JSON.
6
+ */
7
+ export declare class AIPromptRunEntityExtended extends AIPromptRunEntity {
8
+ /**
9
+ * Parses and extracts all message data from the Messages field.
10
+ * This uses the exact logic from the AI Prompt Run form component.
11
+ * @returns Object containing chatMessages, inputData, and formattedMessages
12
+ */
13
+ ParseMessagesData(): {
14
+ chatMessages: ChatMessage[];
15
+ inputData: any | null;
16
+ formattedMessages: string;
17
+ formattedData: string;
18
+ };
19
+ /**
20
+ * Extracts just the chat messages from the stored Messages JSON field.
21
+ * @returns Array of ChatMessage objects, or empty array if no messages found
22
+ */
23
+ GetChatMessages(): ChatMessage[];
24
+ /**
25
+ * Extracts the data context from the stored Messages JSON field.
26
+ * @returns The data object if found, or null
27
+ */
28
+ GetDataContext(): any | null;
29
+ /**
30
+ * Formats the Messages field for display with proper JSON formatting.
31
+ * @returns Formatted JSON string
32
+ */
33
+ GetFormattedMessages(): string;
34
+ /**
35
+ * Formats the Result field for display with proper JSON formatting.
36
+ * Uses exact logic from AI Prompt Run form.
37
+ * @returns Formatted JSON string
38
+ */
39
+ GetFormattedResult(): string;
40
+ /**
41
+ * Extracts the system prompt from the chat messages.
42
+ * This is useful for re-running prompts with the exact same system prompt.
43
+ * @returns The system prompt content if found, or null
44
+ */
45
+ GetSystemPrompt(): string | null;
46
+ }
47
+ //# sourceMappingURL=AIPromptRunEntityExtended.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AIPromptRunEntityExtended.d.ts","sourceRoot":"","sources":["../../src/custom/AIPromptRunEntityExtended.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AACnE,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEjD;;;GAGG;AACH,qBACa,yBAA0B,SAAQ,iBAAiB;IAE5D;;;;OAIG;IACI,iBAAiB,IAAI;QACxB,YAAY,EAAE,WAAW,EAAE,CAAC;QAC5B,SAAS,EAAE,GAAG,GAAG,IAAI,CAAC;QACtB,iBAAiB,EAAE,MAAM,CAAC;QAC1B,aAAa,EAAE,MAAM,CAAC;KACzB;IA0DD;;;OAGG;IACI,eAAe,IAAI,WAAW,EAAE;IAKvC;;;OAGG;IACI,cAAc,IAAI,GAAG,GAAG,IAAI;IAKnC;;;OAGG;IACI,oBAAoB,IAAI,MAAM;IAKrC;;;;OAIG;IACI,kBAAkB,IAAI,MAAM;IAoBnC;;;;OAIG;IACI,eAAe,IAAI,MAAM,GAAG,IAAI;CAuB1C"}
@@ -0,0 +1,156 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.AIPromptRunEntityExtended = void 0;
10
+ const global_1 = require("@memberjunction/global");
11
+ const core_1 = require("@memberjunction/core");
12
+ const entity_subclasses_1 = require("../generated/entity_subclasses");
13
+ /**
14
+ * Extended AIPromptRunEntity class with helper methods for extracting
15
+ * conversation messages and data from the stored JSON.
16
+ */
17
+ let AIPromptRunEntityExtended = class AIPromptRunEntityExtended extends entity_subclasses_1.AIPromptRunEntity {
18
+ /**
19
+ * Parses and extracts all message data from the Messages field.
20
+ * This uses the exact logic from the AI Prompt Run form component.
21
+ * @returns Object containing chatMessages, inputData, and formattedMessages
22
+ */
23
+ ParseMessagesData() {
24
+ const parseOptions = {
25
+ extractInlineJson: true,
26
+ maxDepth: 100,
27
+ debug: false
28
+ };
29
+ let chatMessages = [];
30
+ let inputData = null;
31
+ let formattedMessages = '';
32
+ let formattedData = '';
33
+ // Format messages with recursive JSON parsing
34
+ if (this.Messages) {
35
+ try {
36
+ const parsed = JSON.parse(this.Messages);
37
+ const recursivelyParsed = (0, global_1.ParseJSONRecursive)(parsed, parseOptions);
38
+ formattedMessages = JSON.stringify(recursivelyParsed, null, 2);
39
+ // Extract messages array and data
40
+ if (recursivelyParsed && typeof recursivelyParsed === 'object') {
41
+ // Extract chat messages if they exist
42
+ if (recursivelyParsed.messages && Array.isArray(recursivelyParsed.messages)) {
43
+ chatMessages = recursivelyParsed.messages;
44
+ }
45
+ else {
46
+ chatMessages = [];
47
+ }
48
+ // Extract data object if it exists
49
+ if (recursivelyParsed.data) {
50
+ inputData = recursivelyParsed.data;
51
+ formattedData = JSON.stringify(recursivelyParsed.data, null, 2);
52
+ }
53
+ else {
54
+ inputData = null;
55
+ formattedData = '';
56
+ }
57
+ }
58
+ }
59
+ catch {
60
+ formattedMessages = this.Messages;
61
+ chatMessages = [];
62
+ inputData = null;
63
+ formattedData = '';
64
+ }
65
+ }
66
+ else {
67
+ formattedMessages = '';
68
+ chatMessages = [];
69
+ inputData = null;
70
+ formattedData = '';
71
+ }
72
+ return {
73
+ chatMessages,
74
+ inputData,
75
+ formattedMessages,
76
+ formattedData
77
+ };
78
+ }
79
+ /**
80
+ * Extracts just the chat messages from the stored Messages JSON field.
81
+ * @returns Array of ChatMessage objects, or empty array if no messages found
82
+ */
83
+ GetChatMessages() {
84
+ const { chatMessages } = this.ParseMessagesData();
85
+ return chatMessages;
86
+ }
87
+ /**
88
+ * Extracts the data context from the stored Messages JSON field.
89
+ * @returns The data object if found, or null
90
+ */
91
+ GetDataContext() {
92
+ const { inputData } = this.ParseMessagesData();
93
+ return inputData;
94
+ }
95
+ /**
96
+ * Formats the Messages field for display with proper JSON formatting.
97
+ * @returns Formatted JSON string
98
+ */
99
+ GetFormattedMessages() {
100
+ const { formattedMessages } = this.ParseMessagesData();
101
+ return formattedMessages;
102
+ }
103
+ /**
104
+ * Formats the Result field for display with proper JSON formatting.
105
+ * Uses exact logic from AI Prompt Run form.
106
+ * @returns Formatted JSON string
107
+ */
108
+ GetFormattedResult() {
109
+ if (!this.Result) {
110
+ return '';
111
+ }
112
+ const parseOptions = {
113
+ extractInlineJson: true,
114
+ maxDepth: 100,
115
+ debug: false
116
+ };
117
+ try {
118
+ const parsed = JSON.parse(this.Result);
119
+ const recursivelyParsed = (0, global_1.ParseJSONRecursive)(parsed, parseOptions);
120
+ return JSON.stringify(recursivelyParsed, null, 2);
121
+ }
122
+ catch {
123
+ return this.Result;
124
+ }
125
+ }
126
+ /**
127
+ * Extracts the system prompt from the chat messages.
128
+ * This is useful for re-running prompts with the exact same system prompt.
129
+ * @returns The system prompt content if found, or null
130
+ */
131
+ GetSystemPrompt() {
132
+ const messages = this.GetChatMessages();
133
+ // Find the first system message
134
+ const systemMessage = messages.find(msg => msg.role === 'system');
135
+ if (!systemMessage) {
136
+ return null;
137
+ }
138
+ // Handle different content types
139
+ if (typeof systemMessage.content === 'string') {
140
+ return systemMessage.content;
141
+ }
142
+ else if (Array.isArray(systemMessage.content)) {
143
+ // If content is an array of content blocks, extract text content
144
+ const textBlocks = systemMessage.content.filter(block => block.type === 'text');
145
+ if (textBlocks.length > 0) {
146
+ return textBlocks.map(block => block.content).join('\n');
147
+ }
148
+ }
149
+ return null;
150
+ }
151
+ };
152
+ exports.AIPromptRunEntityExtended = AIPromptRunEntityExtended;
153
+ exports.AIPromptRunEntityExtended = AIPromptRunEntityExtended = __decorate([
154
+ (0, global_1.RegisterClass)(core_1.BaseEntity, 'MJ: AI Prompt Runs')
155
+ ], AIPromptRunEntityExtended);
156
+ //# sourceMappingURL=AIPromptRunEntityExtended.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AIPromptRunEntityExtended.js","sourceRoot":"","sources":["../../src/custom/AIPromptRunEntityExtended.ts"],"names":[],"mappings":";;;;;;;;;AAAA,mDAA6F;AAC7F,+CAAkD;AAClD,sEAAmE;AAGnE;;;GAGG;AAEI,IAAM,yBAAyB,GAA/B,MAAM,yBAA0B,SAAQ,qCAAiB;IAE5D;;;;OAIG;IACI,iBAAiB;QAMpB,MAAM,YAAY,GAAqB;YACnC,iBAAiB,EAAE,IAAI;YACvB,QAAQ,EAAE,GAAG;YACb,KAAK,EAAE,KAAK;SACf,CAAC;QAEF,IAAI,YAAY,GAAkB,EAAE,CAAC;QACrC,IAAI,SAAS,GAAQ,IAAI,CAAC;QAC1B,IAAI,iBAAiB,GAAW,EAAE,CAAC;QACnC,IAAI,aAAa,GAAW,EAAE,CAAC;QAE/B,8CAA8C;QAC9C,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;YAChB,IAAI,CAAC;gBACD,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;gBACzC,MAAM,iBAAiB,GAAG,IAAA,2BAAkB,EAAC,MAAM,EAAE,YAAY,CAAC,CAAC;gBACnE,iBAAiB,GAAG,IAAI,CAAC,SAAS,CAAC,iBAAiB,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;gBAE/D,kCAAkC;gBAClC,IAAI,iBAAiB,IAAI,OAAO,iBAAiB,KAAK,QAAQ,EAAE,CAAC;oBAC7D,sCAAsC;oBACtC,IAAI,iBAAiB,CAAC,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,iBAAiB,CAAC,QAAQ,CAAC,EAAE,CAAC;wBAC1E,YAAY,GAAG,iBAAiB,CAAC,QAAyB,CAAC;oBAC/D,CAAC;yBAAM,CAAC;wBACJ,YAAY,GAAG,EAAE,CAAC;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