@flue/client 0.0.6 → 0.0.8
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.mjs +18 -38
- package/package.json +27 -27
package/dist/index.mjs
CHANGED
|
@@ -191,12 +191,6 @@ async function runShell(command, options) {
|
|
|
191
191
|
//#endregion
|
|
192
192
|
//#region src/prompt.ts
|
|
193
193
|
/**
|
|
194
|
-
* Checks if a Valibot schema represents a plain string type.
|
|
195
|
-
*/
|
|
196
|
-
function isStringSchema(schema) {
|
|
197
|
-
return schema.type === "string";
|
|
198
|
-
}
|
|
199
|
-
/**
|
|
200
194
|
* Checks if a skill name is a file path (contains '/' or ends with '.md').
|
|
201
195
|
*/
|
|
202
196
|
function isFilePath(name) {
|
|
@@ -222,10 +216,9 @@ function buildSkillPrompt(name, args, schema) {
|
|
|
222
216
|
isFilePath(name) ? `Read and use the .opencode/skills/${name} skill.` : `Use the ${name} skill.`
|
|
223
217
|
];
|
|
224
218
|
if (args && Object.keys(args).length > 0) parts.push(`\nArguments:\n${JSON.stringify(args, null, 2)}`);
|
|
225
|
-
if (schema)
|
|
226
|
-
else {
|
|
219
|
+
if (schema) {
|
|
227
220
|
const { $schema: _, ...schemaWithoutMeta } = toJsonSchema(schema, { errorMode: "ignore" });
|
|
228
|
-
parts.push("\nWhen complete, output your result between these exact delimiters
|
|
221
|
+
parts.push("\nWhen complete, you MUST output your result between these exact delimiters conforming to this schema:", "```json", JSON.stringify(schemaWithoutMeta, null, 2), "```", "", "Example: (Object)", "---RESULT_START---", "{\"key\": \"value\"}", "---RESULT_END---", "", "Example: (String)", "---RESULT_START---", "Hello, world!", "---RESULT_END---");
|
|
229
222
|
}
|
|
230
223
|
return parts.join("\n");
|
|
231
224
|
}
|
|
@@ -255,43 +248,30 @@ function extractResult(parts, schema, sessionId) {
|
|
|
255
248
|
rawOutput: allText
|
|
256
249
|
});
|
|
257
250
|
}
|
|
258
|
-
|
|
259
|
-
if (schema.type === "
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
rawOutput: resultBlock,
|
|
266
|
-
validationErrors: parseResult.issues
|
|
267
|
-
});
|
|
268
|
-
}
|
|
269
|
-
console.log(`[flue] extractResult: validated string result (${resultBlock.length} chars)`);
|
|
270
|
-
return parseResult.output;
|
|
271
|
-
}
|
|
272
|
-
let parsed;
|
|
273
|
-
try {
|
|
274
|
-
parsed = JSON.parse(resultBlock);
|
|
275
|
-
} catch (err) {
|
|
276
|
-
console.error(`[flue] extractResult: JSON parse failed for block: ${resultBlock.slice(0, 200)}`);
|
|
277
|
-
throw new SkillOutputError("Failed to parse result block as JSON.", {
|
|
251
|
+
let result = resultBlock;
|
|
252
|
+
if (schema.type === "object" || schema.type === "array") try {
|
|
253
|
+
result = JSON.parse(result);
|
|
254
|
+
} catch {
|
|
255
|
+
console.error("[flue] extractResult: schema validation failed", schema);
|
|
256
|
+
console.error("[flue] extractResult: parsed value was:", JSON.stringify(resultBlock));
|
|
257
|
+
throw new SkillOutputError("Result does not match the expected schema.", {
|
|
278
258
|
sessionId,
|
|
279
259
|
rawOutput: resultBlock,
|
|
280
|
-
validationErrors:
|
|
260
|
+
validationErrors: ["JSON.parse(result) failed"]
|
|
281
261
|
});
|
|
282
262
|
}
|
|
283
|
-
const
|
|
284
|
-
if (!
|
|
285
|
-
console.error("[flue] extractResult: schema validation failed",
|
|
286
|
-
console.error("[flue] extractResult: parsed value was:", JSON.stringify(
|
|
263
|
+
const parsedResult = v.safeParse(schema, result);
|
|
264
|
+
if (!parsedResult.success) {
|
|
265
|
+
console.error("[flue] extractResult: schema validation failed", parsedResult.issues);
|
|
266
|
+
console.error("[flue] extractResult: parsed value was:", JSON.stringify(result));
|
|
287
267
|
throw new SkillOutputError("Result does not match the expected schema.", {
|
|
288
268
|
sessionId,
|
|
289
|
-
rawOutput:
|
|
290
|
-
validationErrors:
|
|
269
|
+
rawOutput: result,
|
|
270
|
+
validationErrors: parsedResult.issues
|
|
291
271
|
});
|
|
292
272
|
}
|
|
293
|
-
console.log("[flue] extractResult: validated result:", JSON.stringify(
|
|
294
|
-
return
|
|
273
|
+
console.log("[flue] extractResult: validated result:", JSON.stringify(parsedResult.output));
|
|
274
|
+
return parsedResult.output;
|
|
295
275
|
}
|
|
296
276
|
/**
|
|
297
277
|
* Extracts the content of the last ---RESULT_START--- / ---RESULT_END--- block from text.
|
package/package.json
CHANGED
|
@@ -1,28 +1,28 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
2
|
+
"name": "@flue/client",
|
|
3
|
+
"version": "0.0.8",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"exports": {
|
|
6
|
+
".": {
|
|
7
|
+
"types": "./dist/index.d.mts",
|
|
8
|
+
"import": "./dist/index.mjs"
|
|
9
|
+
}
|
|
10
|
+
},
|
|
11
|
+
"main": "./dist/index.mjs",
|
|
12
|
+
"types": "./dist/index.d.mts",
|
|
13
|
+
"files": [
|
|
14
|
+
"dist"
|
|
15
|
+
],
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"@opencode-ai/sdk": "^1.1.56",
|
|
18
|
+
"@valibot/to-json-schema": "^1.0.0",
|
|
19
|
+
"valibot": "^1.0.0"
|
|
20
|
+
},
|
|
21
|
+
"devDependencies": {
|
|
22
|
+
"tsdown": "^0.20.3"
|
|
23
|
+
},
|
|
24
|
+
"scripts": {
|
|
25
|
+
"build": "tsdown",
|
|
26
|
+
"check:types": "tsc --noEmit"
|
|
27
|
+
}
|
|
28
|
+
}
|