@x-code-cli/core 0.1.7 → 0.1.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/agent/file-ingest.d.ts +62 -0
- package/dist/agent/file-ingest.d.ts.map +1 -0
- package/dist/agent/file-ingest.js +390 -0
- package/dist/agent/file-ingest.js.map +1 -0
- package/dist/agent/light-compact.d.ts +13 -0
- package/dist/agent/light-compact.d.ts.map +1 -0
- package/dist/agent/light-compact.js +106 -0
- package/dist/agent/light-compact.js.map +1 -0
- package/dist/agent/loop-guard.d.ts +50 -0
- package/dist/agent/loop-guard.d.ts.map +1 -0
- package/dist/agent/loop-guard.js +107 -0
- package/dist/agent/loop-guard.js.map +1 -0
- package/dist/agent/loop-state.d.ts +11 -0
- package/dist/agent/loop-state.d.ts.map +1 -1
- package/dist/agent/loop-state.js +2 -0
- package/dist/agent/loop-state.js.map +1 -1
- package/dist/agent/loop.d.ts +2 -2
- package/dist/agent/loop.d.ts.map +1 -1
- package/dist/agent/loop.js +65 -8
- package/dist/agent/loop.js.map +1 -1
- package/dist/agent/messages.d.ts +5 -2
- package/dist/agent/messages.d.ts.map +1 -1
- package/dist/agent/messages.js.map +1 -1
- package/dist/agent/provider-compat.d.ts +7 -0
- package/dist/agent/provider-compat.d.ts.map +1 -1
- package/dist/agent/provider-compat.js +122 -0
- package/dist/agent/provider-compat.js.map +1 -1
- package/dist/agent/system-prompt.js +3 -3
- package/dist/agent/system-prompt.js.map +1 -1
- package/dist/agent/tool-execution.d.ts.map +1 -1
- package/dist/agent/tool-execution.js +68 -26
- package/dist/agent/tool-execution.js.map +1 -1
- package/dist/agent/tool-result-sanitize.d.ts +8 -0
- package/dist/agent/tool-result-sanitize.d.ts.map +1 -0
- package/dist/agent/tool-result-sanitize.js +77 -0
- package/dist/agent/tool-result-sanitize.js.map +1 -0
- package/dist/agent/vision-fallback.d.ts +22 -0
- package/dist/agent/vision-fallback.d.ts.map +1 -0
- package/dist/agent/vision-fallback.js +127 -0
- package/dist/agent/vision-fallback.js.map +1 -0
- package/dist/index.d.ts +8 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -1
- package/dist/index.js.map +1 -1
- package/dist/providers/cache-control.d.ts +29 -0
- package/dist/providers/cache-control.d.ts.map +1 -0
- package/dist/providers/cache-control.js +93 -0
- package/dist/providers/cache-control.js.map +1 -0
- package/dist/providers/capabilities.d.ts +15 -0
- package/dist/providers/capabilities.d.ts.map +1 -0
- package/dist/providers/capabilities.js +38 -0
- package/dist/providers/capabilities.js.map +1 -0
- package/dist/tools/index.d.ts +31 -5
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js +1 -10
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/read-file.d.ts +29 -1
- package/dist/tools/read-file.d.ts.map +1 -1
- package/dist/tools/read-file.js +103 -10
- package/dist/tools/read-file.js.map +1 -1
- package/dist/tools/shell-provider.d.ts +13 -0
- package/dist/tools/shell-provider.d.ts.map +1 -0
- package/dist/tools/shell-provider.js +74 -0
- package/dist/tools/shell-provider.js.map +1 -0
- package/dist/tools/shell-utils.d.ts +1 -7
- package/dist/tools/shell-utils.d.ts.map +1 -1
- package/dist/tools/shell-utils.js +0 -17
- package/dist/tools/shell-utils.js.map +1 -1
- package/dist/tools/truncate.d.ts +36 -0
- package/dist/tools/truncate.d.ts.map +1 -0
- package/dist/tools/truncate.js +118 -0
- package/dist/tools/truncate.js.map +1 -0
- package/dist/tools/web-search.js +2 -2
- package/dist/tools/web-search.js.map +1 -1
- package/dist/utils/shell-error.d.ts +12 -0
- package/dist/utils/shell-error.d.ts.map +1 -0
- package/dist/utils/shell-error.js +73 -0
- package/dist/utils/shell-error.js.map +1 -0
- package/package.json +21 -12
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
// @x-code-cli/core — Tool-output truncation
|
|
2
|
+
//
|
|
3
|
+
// Dual-budget truncation (lines OR bytes, whichever hits first). The 20/80
|
|
4
|
+
// head/tail split is from gemini-cli; the per-tool direction is from opencode.
|
|
5
|
+
// Shell output wants head-only (the tail repeats the prompt / exit line and
|
|
6
|
+
// the head carries the action), while file reads and grep results prefer
|
|
7
|
+
// head+tail so both the top-of-file context and the last section remain
|
|
8
|
+
// visible.
|
|
9
|
+
//
|
|
10
|
+
// Why not a separate char budget? For ASCII, chars == bytes, so a char budget
|
|
11
|
+
// is redundant with the byte budget. For non-ASCII (CJK code/comments), the
|
|
12
|
+
// byte budget is the one that actually matches how providers bill — they
|
|
13
|
+
// count UTF-8 bytes, not UTF-16 code units. Running two size axes (chars +
|
|
14
|
+
// bytes) made the slice logic three-pass and produced no behavioural win.
|
|
15
|
+
/** Default per-result line cap. Above this we keep a head/tail slice. */
|
|
16
|
+
export const MAX_TOOL_RESULT_LINES = 2000;
|
|
17
|
+
/** Default per-result byte cap (UTF-8). Covers both ASCII single-line
|
|
18
|
+
* minified dumps and non-ASCII content where a modest char count still adds
|
|
19
|
+
* up to a lot of wire bytes. */
|
|
20
|
+
export const MAX_TOOL_RESULT_BYTES = 50 * 1024;
|
|
21
|
+
/** Head:tail ratio when slicing. 0.2 keeps the first 20% + last 80%. */
|
|
22
|
+
export const DEFAULT_HEAD_RATIO = 0.2;
|
|
23
|
+
/** Per-turn aggregate cap across all tool results in one assistant message.
|
|
24
|
+
* Not enforced yet — tracked via agent loop state for future telemetry and
|
|
25
|
+
* eventual reactive compaction (mirrors claude-code's 200k-char ceiling). */
|
|
26
|
+
export const MAX_AGGREGATE_TOOL_RESULT_BYTES = 200 * 1024;
|
|
27
|
+
function byteLength(str) {
|
|
28
|
+
return Buffer.byteLength(str, 'utf-8');
|
|
29
|
+
}
|
|
30
|
+
/** Byte-aware slice that always cuts on a UTF-8 boundary so we don't produce
|
|
31
|
+
* a replacement char. Walks back up to 4 bytes to find a clean boundary. */
|
|
32
|
+
function sliceBytes(buf, bytes, direction) {
|
|
33
|
+
if (buf.length <= bytes)
|
|
34
|
+
return buf;
|
|
35
|
+
if (direction === 'head') {
|
|
36
|
+
let end = bytes;
|
|
37
|
+
// Back off to the last full codepoint start byte: continuation bytes in
|
|
38
|
+
// UTF-8 have the high bits `10xxxxxx`; we want to stop before them.
|
|
39
|
+
while (end > 0 && (buf[end] & 0xc0) === 0x80)
|
|
40
|
+
end--;
|
|
41
|
+
return buf.subarray(0, end);
|
|
42
|
+
}
|
|
43
|
+
let start = buf.length - bytes;
|
|
44
|
+
while (start < buf.length && (buf[start] & 0xc0) === 0x80)
|
|
45
|
+
start++;
|
|
46
|
+
return buf.subarray(start);
|
|
47
|
+
}
|
|
48
|
+
function applyLineSlice(result, maxLines, direction, headRatio) {
|
|
49
|
+
const lines = result.split('\n');
|
|
50
|
+
if (lines.length <= maxLines)
|
|
51
|
+
return { result: { sliced: result, headEnd: null }, linesDropped: 0 };
|
|
52
|
+
if (direction === 'head') {
|
|
53
|
+
return {
|
|
54
|
+
result: { sliced: lines.slice(0, maxLines).join('\n'), headEnd: null },
|
|
55
|
+
linesDropped: lines.length - maxLines,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
if (direction === 'tail') {
|
|
59
|
+
return {
|
|
60
|
+
result: { sliced: lines.slice(-maxLines).join('\n'), headEnd: null },
|
|
61
|
+
linesDropped: lines.length - maxLines,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
const headLines = Math.max(1, Math.floor(maxLines * headRatio));
|
|
65
|
+
const tailLines = maxLines - headLines;
|
|
66
|
+
const head = lines.slice(0, headLines).join('\n');
|
|
67
|
+
const tail = lines.slice(-tailLines).join('\n');
|
|
68
|
+
return { result: { sliced: head + '\n' + tail, headEnd: head.length }, linesDropped: lines.length - maxLines };
|
|
69
|
+
}
|
|
70
|
+
function applyByteSlice(input, maxBytes, direction, headRatio) {
|
|
71
|
+
const buf = Buffer.from(input.sliced, 'utf-8');
|
|
72
|
+
if (buf.length <= maxBytes)
|
|
73
|
+
return input;
|
|
74
|
+
if (direction === 'head')
|
|
75
|
+
return { sliced: sliceBytes(buf, maxBytes, 'head').toString('utf-8'), headEnd: null };
|
|
76
|
+
if (direction === 'tail')
|
|
77
|
+
return { sliced: sliceBytes(buf, maxBytes, 'tail').toString('utf-8'), headEnd: null };
|
|
78
|
+
const headBudget = Math.max(256, Math.floor(maxBytes * headRatio));
|
|
79
|
+
const tailBudget = maxBytes - headBudget;
|
|
80
|
+
const head = sliceBytes(buf, headBudget, 'head').toString('utf-8');
|
|
81
|
+
const tail = sliceBytes(buf, tailBudget, 'tail').toString('utf-8');
|
|
82
|
+
return { sliced: head + tail, headEnd: head.length };
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Truncate tool output to the line / byte budget. Returns the input unchanged
|
|
86
|
+
* if it fits both. Adds a one-line marker so the model can tell intentional
|
|
87
|
+
* omission from corrupted output.
|
|
88
|
+
*/
|
|
89
|
+
export function truncateToolResult(result, options = {}) {
|
|
90
|
+
const maxLines = options.maxLines ?? MAX_TOOL_RESULT_LINES;
|
|
91
|
+
const maxBytes = options.maxBytes ?? MAX_TOOL_RESULT_BYTES;
|
|
92
|
+
const direction = options.direction ?? 'head-tail';
|
|
93
|
+
const headRatio = options.headRatio ?? DEFAULT_HEAD_RATIO;
|
|
94
|
+
const origLines = (result.match(/\n/g)?.length ?? 0) + 1;
|
|
95
|
+
const origBytes = byteLength(result);
|
|
96
|
+
const origChars = result.length;
|
|
97
|
+
if (origLines <= maxLines && origBytes <= maxBytes)
|
|
98
|
+
return result;
|
|
99
|
+
// Line slice first: preserves structured chunking for line-oriented output
|
|
100
|
+
// (grep matches, listDir entries). After the line cut we may still be over
|
|
101
|
+
// the byte budget — a long single line or CJK-heavy content where the line
|
|
102
|
+
// count was fine — and the byte slice handles the remainder.
|
|
103
|
+
const lineSlice = applyLineSlice(result, maxLines, direction, headRatio);
|
|
104
|
+
const byteSlice = applyByteSlice(lineSlice.result, maxBytes, direction, headRatio);
|
|
105
|
+
const droppedChars = origChars - byteSlice.sliced.length;
|
|
106
|
+
const marker = lineSlice.linesDropped > 0
|
|
107
|
+
? `[truncated: ${lineSlice.linesDropped} lines / ${droppedChars.toLocaleString()} chars dropped — narrow the tool args or read specific ranges]`
|
|
108
|
+
: `[truncated: ${droppedChars.toLocaleString()} chars dropped — output exceeded byte budget]`;
|
|
109
|
+
if (direction === 'head')
|
|
110
|
+
return `${byteSlice.sliced}\n\n${marker}`;
|
|
111
|
+
if (direction === 'tail')
|
|
112
|
+
return `${marker}\n\n${byteSlice.sliced}`;
|
|
113
|
+
if (byteSlice.headEnd != null && byteSlice.headEnd > 0 && byteSlice.headEnd < byteSlice.sliced.length) {
|
|
114
|
+
return `${byteSlice.sliced.slice(0, byteSlice.headEnd)}\n\n${marker}\n\n${byteSlice.sliced.slice(byteSlice.headEnd)}`;
|
|
115
|
+
}
|
|
116
|
+
return `${marker}\n\n${byteSlice.sliced}`;
|
|
117
|
+
}
|
|
118
|
+
//# sourceMappingURL=truncate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"truncate.js","sourceRoot":"","sources":["../../src/tools/truncate.ts"],"names":[],"mappings":"AAAA,4CAA4C;AAC5C,EAAE;AACF,2EAA2E;AAC3E,+EAA+E;AAC/E,4EAA4E;AAC5E,yEAAyE;AACzE,wEAAwE;AACxE,WAAW;AACX,EAAE;AACF,8EAA8E;AAC9E,4EAA4E;AAC5E,yEAAyE;AACzE,2EAA2E;AAC3E,0EAA0E;AAE1E,yEAAyE;AACzE,MAAM,CAAC,MAAM,qBAAqB,GAAG,IAAI,CAAA;AAEzC;;iCAEiC;AACjC,MAAM,CAAC,MAAM,qBAAqB,GAAG,EAAE,GAAG,IAAI,CAAA;AAE9C,wEAAwE;AACxE,MAAM,CAAC,MAAM,kBAAkB,GAAG,GAAG,CAAA;AAErC;;8EAE8E;AAC9E,MAAM,CAAC,MAAM,+BAA+B,GAAG,GAAG,GAAG,IAAI,CAAA;AAoBzD,SAAS,UAAU,CAAC,GAAW;IAC7B,OAAO,MAAM,CAAC,UAAU,CAAC,GA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,GAAG,MAAM,OAAO,SAAS,CAAC,MAAM,EAAE,CAAA;AAC3C,CAAC"}
|
package/dist/tools/web-search.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { tool } from 'ai';
|
|
3
3
|
import { z } from 'zod';
|
|
4
4
|
import { reportProgress } from './progress.js';
|
|
5
|
-
import {
|
|
5
|
+
import { getShellProvider } from './shell-provider.js';
|
|
6
6
|
const YEAR = new Date().getFullYear();
|
|
7
7
|
const BRAVE_TIMEOUT_MS = 15_000;
|
|
8
8
|
async function searchWithTavily(query, maxResults) {
|
|
@@ -29,7 +29,7 @@ async function searchWithBrave(query, maxResults) {
|
|
|
29
29
|
return (data.web?.results ?? []).map((r) => ({ title: r.title, url: r.url, content: r.description }));
|
|
30
30
|
}
|
|
31
31
|
function buildMissingKeyError() {
|
|
32
|
-
const { type } =
|
|
32
|
+
const { type } = getShellProvider();
|
|
33
33
|
let setupBlock;
|
|
34
34
|
if (type === 'powershell') {
|
|
35
35
|
setupBlock = [
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"web-search.js","sourceRoot":"","sources":["../../src/tools/web-search.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,OAAO,EAAE,IAAI,EAAE,MAAM,IAAI,CAAA;AAEzB,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;AAC9C,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"web-search.js","sourceRoot":"","sources":["../../src/tools/web-search.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,OAAO,EAAE,IAAI,EAAE,MAAM,IAAI,CAAA;AAEzB,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;AAC9C,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAA;AAEtD,MAAM,IAAI,GAAG,IAA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CAAC,CAAC,CAAC,CAAC,MAAM,eAAe,CAAC,KAAK,EAAE,CAAC,CAAC,CAAA;YAC9F,OAAO,aAAa,CAAC,OAAO,CAAC,CAAA;QAC/B,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,MAAM,GAAG,GAAG,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;YAC5D,OAAO,oBAAoB,SAAS,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,OAAO,MAAM,GAAG,EAAE,CAAA;QACtE,CAAC;IACH,CAAC;CACF,CAAC,CAAA"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Collapse PowerShell error blocks in `text` to a single summary line each.
|
|
3
|
+
* The summary preserves the opening `At line:X char:Y` header (the only
|
|
4
|
+
* diagnostic signal we keep) and discards the body, caret, category and
|
|
5
|
+
* fully-qualified-id continuations.
|
|
6
|
+
*
|
|
7
|
+
* Returns the input unchanged if no recognisable block is found. Safe to call
|
|
8
|
+
* on arbitrary shell output — lines that don't fall inside a block pass
|
|
9
|
+
* through verbatim.
|
|
10
|
+
*/
|
|
11
|
+
export declare function foldShellErrorNoise(text: string): string;
|
|
12
|
+
//# sourceMappingURL=shell-error.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shell-error.d.ts","sourceRoot":"","sources":["../../src/utils/shell-error.ts"],"names":[],"mappings":"AAgCA;;;;;;;;;GASG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAkCxD"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
// @x-code-cli/core — Shell stderr noise folding
|
|
2
|
+
//
|
|
3
|
+
// PowerShell and cmd emit multi-line diagnostics for every parse/syntax error:
|
|
4
|
+
// the `At line:X char:Y` header, a line of the offending source, a caret
|
|
5
|
+
// underline (`+ ~~~~`), a free-form description line, then the tail markers
|
|
6
|
+
// (`+ CategoryInfo` and `+ FullyQualifiedErrorId`). When the agent loops on
|
|
7
|
+
// a misquoted command, those 5–10 line stacks stack up in context faster
|
|
8
|
+
// than the actual diagnostic signal. We collapse each block to a single line.
|
|
9
|
+
//
|
|
10
|
+
// The detection model:
|
|
11
|
+
// - A block STARTS at a line matching `At line:X char:Y`.
|
|
12
|
+
// - A block ENDS at whichever comes first: (a) a `FullyQualifiedErrorId`
|
|
13
|
+
// line (that's always the PS-emitted terminator), (b) another block
|
|
14
|
+
// start, (c) a hard scan cap.
|
|
15
|
+
// - The scan cap guards against pathological input where a FQID line is
|
|
16
|
+
// missing — we won't silently devour unrelated output.
|
|
17
|
+
/** Max lines we'll consume in a single block. PS stacks are ~5 lines and
|
|
18
|
+
* never approach 12; anything past that is probably not part of the block. */
|
|
19
|
+
const BLOCK_SCAN_LIMIT = 12;
|
|
20
|
+
const PS_BLOCK_START = /^At line:\d+ char:\d+/;
|
|
21
|
+
const PS_FQID_LINE = /^\s*\+\s*FullyQualifiedErrorId\s*:/;
|
|
22
|
+
function isBlockStart(line) {
|
|
23
|
+
return PS_BLOCK_START.test(line);
|
|
24
|
+
}
|
|
25
|
+
function isFqidTerminator(line) {
|
|
26
|
+
return PS_FQID_LINE.test(line);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Collapse PowerShell error blocks in `text` to a single summary line each.
|
|
30
|
+
* The summary preserves the opening `At line:X char:Y` header (the only
|
|
31
|
+
* diagnostic signal we keep) and discards the body, caret, category and
|
|
32
|
+
* fully-qualified-id continuations.
|
|
33
|
+
*
|
|
34
|
+
* Returns the input unchanged if no recognisable block is found. Safe to call
|
|
35
|
+
* on arbitrary shell output — lines that don't fall inside a block pass
|
|
36
|
+
* through verbatim.
|
|
37
|
+
*/
|
|
38
|
+
export function foldShellErrorNoise(text) {
|
|
39
|
+
if (!text)
|
|
40
|
+
return text;
|
|
41
|
+
// Fast path: most shell output isn't a PS error stack.
|
|
42
|
+
if (!text.includes('At line:'))
|
|
43
|
+
return text;
|
|
44
|
+
const lines = text.split(/\r?\n/);
|
|
45
|
+
const out = [];
|
|
46
|
+
let i = 0;
|
|
47
|
+
while (i < lines.length) {
|
|
48
|
+
const line = lines[i];
|
|
49
|
+
if (!isBlockStart(line)) {
|
|
50
|
+
out.push(line);
|
|
51
|
+
i++;
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
out.push(`${line.trim()} [PS parse error — details folded]`);
|
|
55
|
+
i++;
|
|
56
|
+
// Consume the body of the block. We stop at the natural terminator
|
|
57
|
+
// (`FullyQualifiedErrorId`) or at a new block header (in case multiple
|
|
58
|
+
// errors were concatenated). The scan cap is a defensive safety net;
|
|
59
|
+
// real PS errors never hit it.
|
|
60
|
+
let scanned = 0;
|
|
61
|
+
while (i < lines.length && scanned < BLOCK_SCAN_LIMIT) {
|
|
62
|
+
if (isBlockStart(lines[i]))
|
|
63
|
+
break;
|
|
64
|
+
const terminator = isFqidTerminator(lines[i]);
|
|
65
|
+
i++;
|
|
66
|
+
scanned++;
|
|
67
|
+
if (terminator)
|
|
68
|
+
break;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return out.join('\n');
|
|
72
|
+
}
|
|
73
|
+
//# sourceMappingURL=shell-error.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shell-error.js","sourceRoot":"","sources":["../../src/utils/shell-error.ts"],"names":[],"mappings":"AAAA,gDAAgD;AAChD,EAAE;AACF,+EAA+E;AAC/E,yEAAyE;AACzE,4EAA4E;AAC5E,4EAA4E;AAC5E,yEAAyE;AACzE,8EAA8E;AAC9E,EAAE;AACF,uBAAuB;AACvB,4DAA4D;AAC5D,2EAA2E;AAC3E,wEAAwE;AACxE,kCAAkC;AAClC,0EAA0E;AAC1E,2DAA2D;AAE3D;+EAC+E;AAC/E,MAAM,gBAAgB,GAAG,EAAE,CAAA;AAE3B,MAAM,cAAc,G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,KAAK,CAAC,CAAC,CAAC,CAAC,CAAA;YAC7C,CAAC,EAAE,CAAA;YACH,OAAO,EAAE,CAAA;YACT,IAAI,UAAU;gBAAE,MAAK;QACvB,CAAC;IACH,CAAC;IAED,OAAO,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;AACvB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@x-code-cli/core",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.8",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/woai3c/x-code-cli",
|
|
@@ -20,25 +20,34 @@
|
|
|
20
20
|
"node": ">=20.19.0"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"ai": "^
|
|
23
|
+
"@ai-sdk/alibaba": "^1.0.0",
|
|
24
24
|
"@ai-sdk/anthropic": "^3.0.0",
|
|
25
|
-
"@ai-sdk/openai": "^3.0.0",
|
|
26
|
-
"@ai-sdk/google": "^3.0.0",
|
|
27
|
-
"@ai-sdk/xai": "^3.0.0",
|
|
28
25
|
"@ai-sdk/deepseek": "^2.0.0",
|
|
29
|
-
"@ai-sdk/
|
|
26
|
+
"@ai-sdk/google": "^3.0.0",
|
|
30
27
|
"@ai-sdk/moonshotai": "^2.0.0",
|
|
28
|
+
"@ai-sdk/openai": "^3.0.0",
|
|
31
29
|
"@ai-sdk/openai-compatible": "^2.0.0",
|
|
32
|
-
"
|
|
33
|
-
"zod": "^3.25.76",
|
|
34
|
-
"globby": "^14.0.0",
|
|
35
|
-
"execa": "^9.0.0",
|
|
30
|
+
"@ai-sdk/xai": "^3.0.0",
|
|
36
31
|
"@tavily/core": "^0.7.0",
|
|
37
32
|
"@vscode/ripgrep": "^1.17.0",
|
|
33
|
+
"ai": "^6.0.0",
|
|
34
|
+
"chalk": "^5.4.0",
|
|
38
35
|
"cheerio": "^1.0.0",
|
|
39
|
-
"turndown": "^7.2.0",
|
|
40
36
|
"diff": "^8.0.0",
|
|
41
|
-
"
|
|
37
|
+
"execa": "^9.0.0",
|
|
38
|
+
"file-type": "^22.0.1",
|
|
39
|
+
"globby": "^14.0.0",
|
|
40
|
+
"mammoth": "^1.12.0",
|
|
41
|
+
"officeparser": "^6.1.0",
|
|
42
|
+
"pdf-parse": "^2.4.5",
|
|
43
|
+
"tesseract.js": "^7.0.0",
|
|
44
|
+
"turndown": "^7.2.0",
|
|
45
|
+
"xlsx": "^0.18.5",
|
|
46
|
+
"zhipu-ai-provider": "^0.2.0",
|
|
47
|
+
"zod": "^3.25.76"
|
|
48
|
+
},
|
|
49
|
+
"devDependencies": {
|
|
50
|
+
"@types/pdf-parse": "^1.1.5"
|
|
42
51
|
},
|
|
43
52
|
"scripts": {
|
|
44
53
|
"build": "tsc -b",
|