@moxxy/sdk 0.10.0 → 0.12.0
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/elision-state.d.ts.map +1 -1
- package/dist/elision-state.js +6 -0
- package/dist/elision-state.js.map +1 -1
- package/dist/events.d.ts +33 -1
- package/dist/events.d.ts.map +1 -1
- package/dist/index.d.ts +8 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/mode-helpers.d.ts +12 -0
- package/dist/mode-helpers.d.ts.map +1 -1
- package/dist/mode-helpers.js +105 -3
- package/dist/mode-helpers.js.map +1 -1
- package/dist/mode.d.ts +9 -0
- package/dist/mode.d.ts.map +1 -1
- package/dist/mode.js.map +1 -1
- package/dist/plugin.d.ts +10 -1
- package/dist/plugin.d.ts.map +1 -1
- package/dist/provider-login-bridge.d.ts +53 -0
- package/dist/provider-login-bridge.d.ts.map +1 -0
- package/dist/provider-login-bridge.js +95 -0
- package/dist/provider-login-bridge.js.map +1 -0
- package/dist/provider.d.ts +53 -0
- package/dist/provider.d.ts.map +1 -1
- package/dist/session-like.d.ts +36 -0
- package/dist/session-like.d.ts.map +1 -1
- package/dist/subagent.d.ts +6 -0
- package/dist/subagent.d.ts.map +1 -1
- package/dist/surface.d.ts +159 -0
- package/dist/surface.d.ts.map +1 -0
- package/dist/surface.js +27 -0
- package/dist/surface.js.map +1 -0
- package/dist/tool-display.d.ts +73 -0
- package/dist/tool-display.d.ts.map +1 -0
- package/dist/tool-display.js +66 -0
- package/dist/tool-display.js.map +1 -0
- package/package.json +5 -1
- package/src/elision-state.ts +5 -0
- package/src/events.ts +36 -0
- package/src/index.ts +43 -0
- package/src/loop-helpers.test.ts +40 -0
- package/src/mode-helpers.ts +114 -3
- package/src/mode.ts +7 -0
- package/src/plugin.ts +10 -1
- package/src/provider-login-bridge.test.ts +78 -0
- package/src/provider-login-bridge.ts +105 -0
- package/src/provider.ts +45 -2
- package/src/session-like.ts +38 -0
- package/src/subagent.ts +6 -0
- package/src/surface.ts +173 -0
- package/src/tool-display.test.ts +71 -0
- package/src/tool-display.ts +118 -0
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Channel-agnostic "rich tool result" payloads.
|
|
3
|
+
*
|
|
4
|
+
* A tool whose result is more than a line of text (a file diff, eventually a
|
|
5
|
+
* table or chart) returns a `ToolDisplayResult`: a short `forModel` string the
|
|
6
|
+
* model sees, plus a structured `display` every channel can render natively.
|
|
7
|
+
* The projection layer (see `mode-helpers.ts`) sends ONLY `forModel` to the
|
|
8
|
+
* model, so the rich payload never bloats the context window.
|
|
9
|
+
*
|
|
10
|
+
* The first (and currently only) display kind is `file-diff`, emitted by the
|
|
11
|
+
* built-in Write/Edit tools. It carries the changed slices of a file (a few
|
|
12
|
+
* lines of context around each edit) — never the whole file — so the payload
|
|
13
|
+
* stays bounded regardless of file size. Channels render it as a classic diff:
|
|
14
|
+
* line numbers, +/- markers, green/red line backgrounds.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/** One rendered line of a diff. */
|
|
18
|
+
export interface DiffLine {
|
|
19
|
+
readonly kind: 'context' | 'add' | 'del';
|
|
20
|
+
readonly text: string;
|
|
21
|
+
/** 1-based line number in the OLD file (del + context lines). */
|
|
22
|
+
readonly oldNo?: number;
|
|
23
|
+
/** 1-based line number in the NEW file (add + context lines). */
|
|
24
|
+
readonly newNo?: number;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** A contiguous changed region plus its surrounding context lines. */
|
|
28
|
+
export interface DiffHunk {
|
|
29
|
+
readonly oldStart: number;
|
|
30
|
+
readonly oldLines: number;
|
|
31
|
+
readonly newStart: number;
|
|
32
|
+
readonly newLines: number;
|
|
33
|
+
readonly lines: ReadonlyArray<DiffLine>;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** Structured diff for a single file write/edit. */
|
|
37
|
+
export interface FileDiffDisplay {
|
|
38
|
+
readonly kind: 'file-diff';
|
|
39
|
+
/** Display path — relative to cwd when possible, else absolute. */
|
|
40
|
+
readonly path: string;
|
|
41
|
+
readonly mode: 'create' | 'update';
|
|
42
|
+
readonly added: number;
|
|
43
|
+
readonly removed: number;
|
|
44
|
+
readonly hunks: ReadonlyArray<DiffHunk>;
|
|
45
|
+
/** Set when a very large diff was capped (some hunks/lines dropped). */
|
|
46
|
+
readonly truncated?: boolean;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** Extensible union of structured tool-result payloads. */
|
|
50
|
+
export type ToolDisplay = FileDiffDisplay;
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* The shape a tool returns when it wants a rich, channel-rendered result.
|
|
54
|
+
* `forModel` is the only thing the model sees; `display` is for channels.
|
|
55
|
+
*/
|
|
56
|
+
export interface ToolDisplayResult {
|
|
57
|
+
readonly forModel: string;
|
|
58
|
+
readonly display: ToolDisplay;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export function isToolDisplayResult(x: unknown): x is ToolDisplayResult {
|
|
62
|
+
return (
|
|
63
|
+
typeof x === 'object' &&
|
|
64
|
+
x !== null &&
|
|
65
|
+
typeof (x as { forModel?: unknown }).forModel === 'string' &&
|
|
66
|
+
isToolDisplay((x as { display?: unknown }).display)
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export function isToolDisplay(x: unknown): x is ToolDisplay {
|
|
71
|
+
return isFileDiffDisplay(x);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export function isFileDiffDisplay(x: unknown): x is FileDiffDisplay {
|
|
75
|
+
return (
|
|
76
|
+
typeof x === 'object' &&
|
|
77
|
+
x !== null &&
|
|
78
|
+
(x as { kind?: unknown }).kind === 'file-diff' &&
|
|
79
|
+
Array.isArray((x as { hunks?: unknown }).hunks)
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** Human summary, e.g. "Added 10 lines, removed 1 line". */
|
|
84
|
+
export function fileDiffSummary(d: FileDiffDisplay): string {
|
|
85
|
+
const plural = (n: number, w: string): string => `${n} ${w}${n === 1 ? '' : 's'}`;
|
|
86
|
+
const parts: string[] = [];
|
|
87
|
+
if (d.added > 0 || d.removed === 0) parts.push(`Added ${plural(d.added, 'line')}`);
|
|
88
|
+
if (d.removed > 0) parts.push(`${parts.length ? 'removed' : 'Removed'} ${plural(d.removed, 'line')}`);
|
|
89
|
+
let summary = parts.join(', ');
|
|
90
|
+
if (d.truncated) summary += ' (diff truncated)';
|
|
91
|
+
return summary;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** Verb for the diff header — "Create" for new files, else "Update". */
|
|
95
|
+
export function fileDiffVerb(d: FileDiffDisplay): string {
|
|
96
|
+
return d.mode === 'create' ? 'Create' : 'Update';
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** Gutter number a renderer should show for a line (new number, or old for deletions). */
|
|
100
|
+
export function diffGutterNo(line: DiffLine): number | undefined {
|
|
101
|
+
return line.kind === 'del' ? line.oldNo : line.newNo;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** A renderable row: either a diff line or a gap marker between hunks. */
|
|
105
|
+
export type DiffRow = DiffLine | { readonly kind: 'gap' };
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Flatten a file diff's hunks into a single row list, inserting a `gap` marker
|
|
109
|
+
* between non-contiguous hunks (channels render it as a `⋯` separator).
|
|
110
|
+
*/
|
|
111
|
+
export function toDiffRows(d: FileDiffDisplay): DiffRow[] {
|
|
112
|
+
const rows: DiffRow[] = [];
|
|
113
|
+
d.hunks.forEach((hunk, i) => {
|
|
114
|
+
if (i > 0) rows.push({ kind: 'gap' });
|
|
115
|
+
for (const line of hunk.lines) rows.push(line);
|
|
116
|
+
});
|
|
117
|
+
return rows;
|
|
118
|
+
}
|