@superatomai/sdk-node 0.0.35 → 0.0.36
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.d.mts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +53 -29
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +53 -29
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -3585,18 +3585,26 @@ var LLM = class {
|
|
|
3585
3585
|
const client = new import_sdk.default({
|
|
3586
3586
|
apiKey
|
|
3587
3587
|
});
|
|
3588
|
+
const apiMessages = [{
|
|
3589
|
+
role: "user",
|
|
3590
|
+
content: messages.user
|
|
3591
|
+
}];
|
|
3592
|
+
const prefill = messages.prefill || (json ? "{" : void 0);
|
|
3593
|
+
if (prefill) {
|
|
3594
|
+
apiMessages.push({
|
|
3595
|
+
role: "assistant",
|
|
3596
|
+
content: prefill
|
|
3597
|
+
});
|
|
3598
|
+
}
|
|
3588
3599
|
const stream = await client.messages.create({
|
|
3589
3600
|
model: modelName,
|
|
3590
3601
|
max_tokens: options.maxTokens || 1e3,
|
|
3591
3602
|
temperature: options.temperature,
|
|
3592
3603
|
system: this._normalizeSystemPrompt(messages.sys),
|
|
3593
|
-
messages:
|
|
3594
|
-
role: "user",
|
|
3595
|
-
content: messages.user
|
|
3596
|
-
}],
|
|
3604
|
+
messages: apiMessages,
|
|
3597
3605
|
stream: true
|
|
3598
3606
|
});
|
|
3599
|
-
let fullText = "";
|
|
3607
|
+
let fullText = prefill || "";
|
|
3600
3608
|
let usage = null;
|
|
3601
3609
|
for await (const chunk of stream) {
|
|
3602
3610
|
if (chunk.type === "content_block_delta" && chunk.delta.type === "text_delta") {
|
|
@@ -4132,40 +4140,56 @@ var LLM = class {
|
|
|
4132
4140
|
openChar = "[";
|
|
4133
4141
|
closeChar = "]";
|
|
4134
4142
|
}
|
|
4135
|
-
if (startIdx
|
|
4136
|
-
|
|
4137
|
-
|
|
4138
|
-
|
|
4139
|
-
|
|
4140
|
-
|
|
4141
|
-
|
|
4142
|
-
|
|
4143
|
-
|
|
4144
|
-
|
|
4145
|
-
|
|
4146
|
-
|
|
4147
|
-
|
|
4148
|
-
|
|
4149
|
-
|
|
4150
|
-
|
|
4151
|
-
|
|
4152
|
-
|
|
4153
|
-
|
|
4154
|
-
|
|
4143
|
+
if (startIdx === -1) {
|
|
4144
|
+
const preview = text.length > 500 ? text.substring(0, 500) + "..." : text;
|
|
4145
|
+
throw new Error(`No JSON found in response. LLM returned plain text instead of JSON.
|
|
4146
|
+
|
|
4147
|
+
Full response:
|
|
4148
|
+
${preview}`);
|
|
4149
|
+
}
|
|
4150
|
+
let depth = 0;
|
|
4151
|
+
let inString = false;
|
|
4152
|
+
let endIdx = -1;
|
|
4153
|
+
for (let i = startIdx; i < jsonText.length; i++) {
|
|
4154
|
+
const char = jsonText[i];
|
|
4155
|
+
const prevChar = i > 0 ? jsonText[i - 1] : "";
|
|
4156
|
+
if (char === '"' && prevChar !== "\\") {
|
|
4157
|
+
inString = !inString;
|
|
4158
|
+
continue;
|
|
4159
|
+
}
|
|
4160
|
+
if (!inString) {
|
|
4161
|
+
if (char === openChar) {
|
|
4162
|
+
depth++;
|
|
4163
|
+
} else if (char === closeChar) {
|
|
4164
|
+
depth--;
|
|
4165
|
+
if (depth === 0) {
|
|
4166
|
+
endIdx = i;
|
|
4167
|
+
break;
|
|
4155
4168
|
}
|
|
4156
4169
|
}
|
|
4157
4170
|
}
|
|
4158
|
-
|
|
4159
|
-
|
|
4160
|
-
|
|
4171
|
+
}
|
|
4172
|
+
if (endIdx !== -1) {
|
|
4173
|
+
jsonText = jsonText.substring(startIdx, endIdx + 1);
|
|
4174
|
+
} else {
|
|
4175
|
+
const preview = text.length > 500 ? text.substring(0, 500) + "..." : text;
|
|
4176
|
+
throw new Error(`Incomplete JSON - no matching closing ${closeChar} found.
|
|
4177
|
+
|
|
4178
|
+
Full response:
|
|
4179
|
+
${preview}`);
|
|
4161
4180
|
}
|
|
4162
4181
|
try {
|
|
4163
4182
|
const repairedJson = (0, import_jsonrepair.jsonrepair)(jsonText);
|
|
4164
4183
|
return JSON.parse(repairedJson);
|
|
4165
4184
|
} catch (error) {
|
|
4185
|
+
const preview = text.length > 500 ? text.substring(0, 500) + "..." : text;
|
|
4166
4186
|
throw new Error(`Failed to parse JSON: ${error instanceof Error ? error.message : String(error)}
|
|
4167
4187
|
|
|
4168
|
-
|
|
4188
|
+
Extracted JSON:
|
|
4189
|
+
${jsonText.substring(0, 300)}...
|
|
4190
|
+
|
|
4191
|
+
Full response:
|
|
4192
|
+
${preview}`);
|
|
4169
4193
|
}
|
|
4170
4194
|
}
|
|
4171
4195
|
};
|