@aj-archipelago/cortex 1.4.27 → 1.4.28

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aj-archipelago/cortex",
3
- "version": "1.4.27",
3
+ "version": "1.4.28",
4
4
  "description": "Cortex is a GraphQL API for AI. It provides a simple, extensible interface for using AI services from OpenAI, Azure and others.",
5
5
  "private": false,
6
6
  "repository": {
@@ -81,19 +81,23 @@ export default {
81
81
 
82
82
  executePathway: async ({args, resolver}) => {
83
83
  try {
84
- const { codingTask, userMessage, inputFiles, codingTaskKeywords } = args;
84
+ const { codingTask, userMessage, inputFiles, codingTaskKeywords, contextId } = args;
85
+
86
+ // pathwayResolver.executePathway should have already extracted contextId from agentContext,
87
+ // but validate it's present as a safety check
88
+ if (!contextId) {
89
+ throw new Error("contextId is required. It should be provided via agentContext or contextId parameter.");
90
+ }
85
91
 
86
92
  let taskSuffix = "";
87
- if (inputFiles) {
93
+ if (inputFiles && Array.isArray(inputFiles) && inputFiles.length > 0) {
88
94
  if (!args.agentContext || !Array.isArray(args.agentContext) || args.agentContext.length === 0) {
89
95
  throw new Error("agentContext is required when using the 'inputFiles' parameter. Use ListFileCollection or SearchFileCollection to find available files.");
90
96
  }
91
97
 
92
98
  // Resolve file parameters to URLs
93
99
  // inputFiles is an array of strings (file hashes or filenames)
94
- const fileReferences = Array.isArray(inputFiles)
95
- ? inputFiles.map(ref => String(ref).trim()).filter(ref => ref.length > 0)
96
- : [];
100
+ const fileReferences = inputFiles.map(ref => String(ref).trim()).filter(ref => ref.length > 0);
97
101
 
98
102
  const resolvedUrls = [];
99
103
  const failedFiles = [];
@@ -142,8 +146,15 @@ export default {
142
146
  const statusMessage = "⚠️ **Task Status**: The coding task has been started and is now running in the background. Don't make up any information about the task or task results - just say that it has been started and is running. The user will be able to see the progress and results of the task, but you will not receive the response. No further action is required from you or the user.";
143
147
  return statusMessage;
144
148
  } catch (error) {
149
+ const errorMessage = error instanceof Error ? error.message : String(error);
145
150
  logger.error(`Error in coding agent tool: ${error instanceof Error ? error.stack || error.message : JSON.stringify(error)}`);
146
- throw error;
151
+
152
+ // Return error as JSON string instead of throwing, so it can be properly detected by the tool execution layer
153
+ resolver.tool = JSON.stringify({ toolUsed: "coding" });
154
+ return JSON.stringify({
155
+ error: errorMessage,
156
+ recoveryMessage: "The coding task could not be started. Please check that all required parameters are provided and try again."
157
+ });
147
158
  }
148
159
  }
149
160
  };
@@ -58,6 +58,15 @@ export default {
58
58
  });
59
59
  }
60
60
 
61
+ // pathwayResolver.executePathway should have already extracted contextId from agentContext,
62
+ // but validate it's present as a safety check
63
+ const { contextId, contextKey } = args;
64
+ if (!contextId) {
65
+ return JSON.stringify({
66
+ error: 'contextId is required. It should be provided via agentContext or contextId parameter.'
67
+ });
68
+ }
69
+
61
70
  // Validate memories array
62
71
  if (!args.memories || !Array.isArray(args.memories) || args.memories.length === 0) {
63
72
  return JSON.stringify({ error: 'memories must be a non-empty array' });
@@ -102,9 +111,9 @@ export default {
102
111
  for (const [section, memoryLines] of Object.entries(memoriesBySection)) {
103
112
  // Read current memory for the section
104
113
  let currentMemory = await callPathway('sys_read_memory', {
105
- contextId: args.contextId,
114
+ contextId: contextId,
106
115
  section: section,
107
- contextKey: args.contextKey
116
+ contextKey: contextKey
108
117
  });
109
118
 
110
119
  // Combine existing memory with new memories
@@ -114,10 +123,10 @@ export default {
114
123
 
115
124
  // Save directly to memory
116
125
  const result = await callPathway('sys_save_memory', {
117
- contextId: args.contextId,
126
+ contextId: contextId,
118
127
  section: section,
119
128
  aiMemory: updatedMemory,
120
- contextKey: args.contextKey
129
+ contextKey: contextKey
121
130
  });
122
131
 
123
132
  results[section] = result;