@opencode/util 0.0.0-dev-1160 → 0.0.0-dev-1176
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/execute-output.d.ts +10 -0
- package/dist/execute-output.js +22 -0
- package/package.json +1 -1
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Code Mode's `execute` output for display. The tool returns its result (compact JSON for structured values) followed
|
|
3
|
+
* by optional "Warnings:" and "Logs:" sections. A JSON result comes back indented as `json`, the sections as `rest`,
|
|
4
|
+
* and `text` joins them.
|
|
5
|
+
*/
|
|
6
|
+
export declare function formatExecuteOutput(output: string): {
|
|
7
|
+
json: string | undefined;
|
|
8
|
+
rest: string | undefined;
|
|
9
|
+
text: string;
|
|
10
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Option, Schema } from "effect";
|
|
2
|
+
const decodeJson = Schema.decodeUnknownOption(Schema.fromJsonString(Schema.Unknown));
|
|
3
|
+
/**
|
|
4
|
+
* Code Mode's `execute` output for display. The tool returns its result (compact JSON for structured values) followed
|
|
5
|
+
* by optional "Warnings:" and "Logs:" sections. A JSON result comes back indented as `json`, the sections as `rest`,
|
|
6
|
+
* and `text` joins them.
|
|
7
|
+
*/
|
|
8
|
+
export function formatExecuteOutput(output) {
|
|
9
|
+
const end = output.search(/\n\n(Warnings|Logs):\n/);
|
|
10
|
+
const result = end === -1 ? output : output.slice(0, end);
|
|
11
|
+
const rest = end === -1 ? undefined : output.slice(end).trim();
|
|
12
|
+
const json = indentedJson(result);
|
|
13
|
+
return { json, rest, text: rest === undefined ? (json ?? result) : `${json ?? result}\n\n${rest}` };
|
|
14
|
+
}
|
|
15
|
+
function indentedJson(text) {
|
|
16
|
+
if (!text.startsWith("{") && !text.startsWith("["))
|
|
17
|
+
return;
|
|
18
|
+
const decoded = decodeJson(text);
|
|
19
|
+
if (Option.isNone(decoded))
|
|
20
|
+
return;
|
|
21
|
+
return JSON.stringify(decoded.value, null, 2);
|
|
22
|
+
}
|