@superatomai/sdk-node 0.0.78 → 0.0.79
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/dist/index.js +48 -5
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +48 -5
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -345,7 +345,8 @@ var UserQueryFiltersSchema = z3.object({
|
|
|
345
345
|
username: z3.string().optional(),
|
|
346
346
|
email: z3.string().optional(),
|
|
347
347
|
role: z3.string().optional(),
|
|
348
|
-
fullname: z3.string().optional()
|
|
348
|
+
fullname: z3.string().optional(),
|
|
349
|
+
id: z3.number().optional()
|
|
349
350
|
});
|
|
350
351
|
var UsersRequestPayloadSchema = z3.object({
|
|
351
352
|
operation: z3.enum(["create", "update", "delete", "getAll", "getOne", "query"]),
|
|
@@ -12332,7 +12333,8 @@ async function pickComponentWithLLM(prompt, components, anthropicApiKey, groqApi
|
|
|
12332
12333
|
outputSchema: tool.outputSchema
|
|
12333
12334
|
});
|
|
12334
12335
|
logger.info(`[DASH_COMP_REQ] Tool ${tool.name} executed successfully`);
|
|
12335
|
-
|
|
12336
|
+
const resultJson = JSON.stringify(result2, null, 2);
|
|
12337
|
+
return resultJson + "\n\n[REMINDER: The above is tool output for verification. You MUST still respond with ONLY the JSON component selection object. Do NOT summarize or describe these results.]";
|
|
12336
12338
|
};
|
|
12337
12339
|
const result = await LLM.streamWithTools(
|
|
12338
12340
|
{
|
|
@@ -12350,18 +12352,59 @@ async function pickComponentWithLLM(prompt, components, anthropicApiKey, groqApi
|
|
|
12350
12352
|
5
|
|
12351
12353
|
// max iterations
|
|
12352
12354
|
);
|
|
12353
|
-
|
|
12354
|
-
|
|
12355
|
+
let jsonMatch = result.match(/\{[\s\S]*\}/);
|
|
12356
|
+
let parsedResult = jsonMatch ? (() => {
|
|
12357
|
+
try {
|
|
12358
|
+
return JSON.parse(jsonMatch[0]);
|
|
12359
|
+
} catch {
|
|
12360
|
+
return null;
|
|
12361
|
+
}
|
|
12362
|
+
})() : null;
|
|
12363
|
+
const isValidComponent = parsedResult && parsedResult.componentId && parsedResult.props;
|
|
12364
|
+
if (!isValidComponent && executedTools.length > 0) {
|
|
12365
|
+
const toolDataSummary = executedTools.map(
|
|
12366
|
+
(t) => `Tool "${t.name}" was called with params ${JSON.stringify(t.params)} and returned:
|
|
12367
|
+
${JSON.stringify(t.result, null, 2).substring(0, 5e3)}`
|
|
12368
|
+
).join("\n\n");
|
|
12369
|
+
const retryUserPrompt = `Original user request: ${prompt}
|
|
12370
|
+
|
|
12371
|
+
The following tool was already called and returned data:
|
|
12372
|
+
${toolDataSummary}
|
|
12373
|
+
|
|
12374
|
+
Using this data, select the appropriate component and respond with ONLY the JSON component selection object. No explanation, no markdown, just JSON.`;
|
|
12375
|
+
const retryResult = await LLM.text(
|
|
12376
|
+
{
|
|
12377
|
+
sys: prompts.system,
|
|
12378
|
+
user: retryUserPrompt
|
|
12379
|
+
},
|
|
12380
|
+
{
|
|
12381
|
+
model,
|
|
12382
|
+
maxTokens: 4096,
|
|
12383
|
+
temperature: 0.1,
|
|
12384
|
+
apiKey
|
|
12385
|
+
}
|
|
12386
|
+
);
|
|
12387
|
+
jsonMatch = retryResult.match(/\{[\s\S]*\}/);
|
|
12388
|
+
parsedResult = jsonMatch ? (() => {
|
|
12389
|
+
try {
|
|
12390
|
+
return JSON.parse(jsonMatch[0]);
|
|
12391
|
+
} catch {
|
|
12392
|
+
return null;
|
|
12393
|
+
}
|
|
12394
|
+
})() : null;
|
|
12395
|
+
}
|
|
12355
12396
|
if (!parsedResult) {
|
|
12356
12397
|
errors.push("Failed to parse LLM response as JSON");
|
|
12357
12398
|
errors.push(`LLM Response: ${result}`);
|
|
12399
|
+
logger.error(`[DASH_COMP_REQ] Failed to parse JSON from LLM response`);
|
|
12358
12400
|
return { success: false, errors };
|
|
12359
12401
|
}
|
|
12360
|
-
logger.
|
|
12402
|
+
logger.info(`[DASH_COMP_REQ] Parsed component: ${parsedResult.componentName} (${parsedResult.componentId})`);
|
|
12361
12403
|
logger.file("[DASH_COMP_REQ] LLM response:", JSON.stringify(parsedResult, null, 2));
|
|
12362
12404
|
if (!parsedResult.componentId || !parsedResult.props) {
|
|
12363
12405
|
errors.push("Invalid LLM response: missing componentId or props");
|
|
12364
12406
|
errors.push(`LLM Response: ${result}`);
|
|
12407
|
+
logger.error(`[DASH_COMP_REQ] Invalid structure - missing componentId: ${!parsedResult.componentId}, missing props: ${!parsedResult.props}`);
|
|
12365
12408
|
userPromptErrorLogger.logError("DASH_COMP_REQ", "Invalid LLM response structure", {
|
|
12366
12409
|
prompt,
|
|
12367
12410
|
result: parsedResult,
|