@minded-ai/mindedjs 1.0.67 → 1.0.69

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 (45) hide show
  1. package/dist/agent.d.ts +2 -0
  2. package/dist/agent.d.ts.map +1 -1
  3. package/dist/agent.js +9 -2
  4. package/dist/agent.js.map +1 -1
  5. package/dist/index.d.ts +1 -1
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/interfaces/zendesk.d.ts +20 -0
  8. package/dist/interfaces/zendesk.d.ts.map +1 -0
  9. package/dist/interfaces/zendesk.js +95 -0
  10. package/dist/interfaces/zendesk.js.map +1 -0
  11. package/dist/nodes/addAppToolNode.d.ts.map +1 -1
  12. package/dist/nodes/addAppToolNode.js +4 -1
  13. package/dist/nodes/addAppToolNode.js.map +1 -1
  14. package/dist/nodes/addPromptNode.d.ts.map +1 -1
  15. package/dist/nodes/addPromptNode.js +4 -1
  16. package/dist/nodes/addPromptNode.js.map +1 -1
  17. package/dist/nodes/addToolNode.d.ts +3 -1
  18. package/dist/nodes/addToolNode.d.ts.map +1 -1
  19. package/dist/nodes/addToolNode.js +5 -2
  20. package/dist/nodes/addToolNode.js.map +1 -1
  21. package/dist/nodes/nodeFactory.js +1 -1
  22. package/dist/nodes/nodeFactory.js.map +1 -1
  23. package/dist/platform/mindedConnectionTypes.d.ts +11 -1
  24. package/dist/platform/mindedConnectionTypes.d.ts.map +1 -1
  25. package/dist/platform/mindedConnectionTypes.js +2 -0
  26. package/dist/platform/mindedConnectionTypes.js.map +1 -1
  27. package/dist/playbooks/playbooks.d.ts +16 -0
  28. package/dist/playbooks/playbooks.d.ts.map +1 -0
  29. package/dist/playbooks/playbooks.js +204 -0
  30. package/dist/playbooks/playbooks.js.map +1 -0
  31. package/dist/types/Agent.types.d.ts +7 -3
  32. package/dist/types/Agent.types.d.ts.map +1 -1
  33. package/dist/types/Agent.types.js +0 -1
  34. package/dist/types/Agent.types.js.map +1 -1
  35. package/package.json +6 -2
  36. package/src/agent.ts +11 -2
  37. package/src/index.ts +2 -2
  38. package/src/interfaces/zendesk.ts +100 -0
  39. package/src/nodes/addAppToolNode.ts +5 -1
  40. package/src/nodes/addPromptNode.ts +5 -1
  41. package/src/nodes/addToolNode.ts +10 -2
  42. package/src/nodes/nodeFactory.ts +1 -1
  43. package/src/platform/mindedConnectionTypes.ts +12 -1
  44. package/src/playbooks/playbooks.ts +203 -0
  45. package/src/types/Agent.types.ts +13 -6
@@ -0,0 +1,203 @@
1
+ import * as fs from 'fs';
2
+ import * as path from 'path';
3
+ import * as yaml from 'js-yaml';
4
+ import * as ejs from 'ejs';
5
+ import { MindedConnection } from '../platform/mindedConnection';
6
+ import { MindedConnectionSocketMessageType } from '../platform/mindedConnectionTypes';
7
+ import { getConfig } from '../platform/config';
8
+ import { logger } from '../utils/logger';
9
+ import { OutputBlockData } from '@editorjs/editorjs';
10
+
11
+ export type Playbook = {
12
+ id: string;
13
+ name: string;
14
+ blocks: OutputBlockData[];
15
+ }
16
+
17
+ /**
18
+ * Convert EditorJS blocks to markdown
19
+ */
20
+ function editorJsToMarkdown(blocks: OutputBlockData[]): string {
21
+ if (!blocks || blocks.length === 0) {
22
+ return '';
23
+ }
24
+
25
+ return blocks.map(block => {
26
+ switch (block.type) {
27
+ case 'header': {
28
+ const level = block.data?.level || 1;
29
+ const headerPrefix = '#'.repeat(level);
30
+ return `${headerPrefix} ${block.data?.text || ''}`;
31
+ }
32
+
33
+ case 'paragraph': {
34
+ return block.data?.text || '';
35
+ }
36
+
37
+ case 'list': {
38
+ const items = block.data?.items || [];
39
+ const style = block.data?.style || 'unordered';
40
+ return items.map((item: string, index: number) => {
41
+ if (style === 'ordered') {
42
+ return `${index + 1}. ${item}`;
43
+ } else {
44
+ return `- ${item}`;
45
+ }
46
+ }).join('\n');
47
+ }
48
+
49
+ case 'quote': {
50
+ const text = block.data?.text || '';
51
+ const caption = block.data?.caption ? `\n*${block.data.caption}*` : '';
52
+ return `> ${text}${caption}`;
53
+ }
54
+
55
+ case 'code': {
56
+ const code = block.data?.code || '';
57
+ return `\`\`\`\n${code}\n\`\`\``;
58
+ }
59
+
60
+ case 'delimiter': {
61
+ return '---';
62
+ }
63
+
64
+ default: {
65
+ logger.warn(`Unknown playbook block type: ${block.type}`);
66
+ return '';
67
+ }
68
+ }
69
+ }).join('\n\n');
70
+ }
71
+
72
+ /**
73
+ * Load playbooks from directories or platform
74
+ */
75
+ export async function loadPlaybooks(
76
+ mindedConnection: MindedConnection | null,
77
+ playbooksDirectories?: string[]
78
+ ): Promise<Playbook[]> {
79
+ const { env, isDeployed } = getConfig();
80
+ let playbooks: Playbook[] = [];
81
+
82
+ if (['sandbox-staging', 'sandbox'].includes(env) && isDeployed && mindedConnection) {
83
+ // Load from platform
84
+ const response = await mindedConnection.awaitEmit<object, { playbooks?: Playbook[]; error?: string }>(
85
+ MindedConnectionSocketMessageType.GET_PLAYBOOKS,
86
+ {},
87
+ );
88
+
89
+ if (response?.error) {
90
+ throw new Error(`Failed to load playbooks from platform: ${response.error}`);
91
+ }
92
+
93
+ playbooks = response?.playbooks || [];
94
+ } else if (playbooksDirectories) {
95
+ // Load from directories
96
+ playbooks = loadPlaybooksFromDirectories(playbooksDirectories);
97
+ }
98
+
99
+ return playbooks;
100
+ }
101
+
102
+ /**
103
+ * Load playbooks from local directories
104
+ */
105
+ function loadPlaybooksFromDirectories(directories: string[]): Playbook[] {
106
+ const playbooks: Playbook[] = [];
107
+
108
+ for (const directory of directories) {
109
+ if (!fs.existsSync(directory)) {
110
+ logger.info(`Playbooks directory does not exist: ${directory}`);
111
+ continue;
112
+ }
113
+
114
+ const files = getAllYamlFiles(directory);
115
+
116
+ for (const file of files) {
117
+ try {
118
+ const fileContent = fs.readFileSync(file, 'utf8');
119
+ const playbook = yaml.load(fileContent) as Playbook;
120
+
121
+ if (playbook && playbook.name && playbook.blocks) {
122
+ playbooks.push(playbook);
123
+ logger.info(`Loaded playbook: ${playbook.name} from ${file}`);
124
+ } else {
125
+ logger.warn(`Invalid playbook structure in ${file}`);
126
+ }
127
+ } catch (error) {
128
+ logger.error(`Failed to load playbook file ${file}: ${error}`);
129
+ }
130
+ }
131
+ }
132
+
133
+ return playbooks;
134
+ }
135
+
136
+ /**
137
+ * Recursively get all YAML files in a directory
138
+ */
139
+ function getAllYamlFiles(dir: string): string[] {
140
+ const files: string[] = [];
141
+ const entries = fs.readdirSync(dir, { withFileTypes: true });
142
+
143
+ for (const entry of entries) {
144
+ const fullPath = path.join(dir, entry.name);
145
+ if (entry.isDirectory()) {
146
+ files.push(...getAllYamlFiles(fullPath));
147
+ } else if (entry.name.endsWith('.yaml') || entry.name.endsWith('.yml')) {
148
+ files.push(fullPath);
149
+ }
150
+ }
151
+
152
+ return files;
153
+ }
154
+
155
+ /**
156
+ * Compile playbooks into a single string with EJS and placeholders
157
+ */
158
+ export function compilePlaybooks(playbooks: Playbook[], params: Record<string, any> = {}): string {
159
+ if (playbooks.length === 0) {
160
+ return '';
161
+ }
162
+
163
+ // Combine all playbooks into sections
164
+ const sections = playbooks.map((playbook) => {
165
+ const markdownContent = editorJsToMarkdown(playbook.blocks);
166
+ return `# ${playbook.name}\n${markdownContent}`;
167
+ });
168
+
169
+ const combinedPlaybooks = sections.join('\n\n');
170
+
171
+ try {
172
+ // First, render with EJS
173
+ let compiledPlaybooks = ejs.render(combinedPlaybooks, params);
174
+
175
+ // Then, replace placeholders in {} format
176
+ compiledPlaybooks = replacePlaceholders(compiledPlaybooks, params);
177
+
178
+ return compiledPlaybooks;
179
+ } catch (error) {
180
+ logger.error({ message: 'Error compiling playbooks', error });
181
+ return combinedPlaybooks; // Return uncompiled if there's an error
182
+ }
183
+ }
184
+
185
+ /**
186
+ * Replace placeholders in {key} format
187
+ */
188
+ function replacePlaceholders(text: string, params: Record<string, any>): string {
189
+ return text.replace(/\{([^}]+)\}/g, (match, key) => {
190
+ const keys = key.split('.');
191
+ let value: any = params;
192
+
193
+ for (const k of keys) {
194
+ if (value && typeof value === 'object' && k in value) {
195
+ value = value[k];
196
+ } else {
197
+ return match; // Return original if key not found
198
+ }
199
+ }
200
+
201
+ return String(value);
202
+ });
203
+ }
@@ -1,13 +1,20 @@
1
- import { AgentEventRequestPayloads, AgentEventResponsePayloads } from "../events/AgentEvents";
2
- import { LLMConfig } from "./LLM.types";
1
+ import { AgentEventRequestPayloads, AgentEventResponsePayloads } from '../events/AgentEvents';
2
+ import { LLMConfig } from './LLM.types';
3
3
 
4
- export type EmitSignature<Memory, E extends keyof AgentEventRequestPayloads<Memory>> = (event: E, payload: AgentEventRequestPayloads<Memory>[E]) => Promise<(AgentEventResponsePayloads<Memory>[E])[]>;
4
+ export type EmitSignature<Memory, E extends keyof AgentEventRequestPayloads<Memory>> = (
5
+ event: E,
6
+ payload: AgentEventRequestPayloads<Memory>[E],
7
+ ) => Promise<AgentEventResponsePayloads<Memory>[E][]>;
5
8
 
6
9
  export type MindedSDKConfig = {
7
10
  flows: string[];
8
11
  llm: LLMConfig;
9
12
  tools: string[];
10
- }
13
+ /**
14
+ * Optional directories containing playbook definition files. If omitted, no playbooks will be loaded.
15
+ */
16
+ playbooks?: string[];
17
+ };
11
18
 
12
19
  /**
13
20
  * Parameters for the Agent invoke method
@@ -37,7 +44,7 @@ export interface TriggerInvocationHistory extends FlowHistory {
37
44
  appName?: string;
38
45
  triggerName: string;
39
46
  triggerBody: any;
40
- };
47
+ }
41
48
 
42
49
  export interface AppActionInvocationHistory extends FlowHistory {
43
50
  type: FlowHistoryType.APP_ACTION_INVOCATION;
@@ -47,4 +54,4 @@ export interface AppActionInvocationHistory extends FlowHistory {
47
54
  export enum SessionType {
48
55
  VOICE = 'voice',
49
56
  TEXT = 'text',
50
- }
57
+ }