@lace-cloud/chat-core 0.0.1-bootstrap.0 → 0.6.3-next.25704378412
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/LICENSE +19 -0
- package/README.md +75 -8
- package/dist/index.cjs +803 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.mts +321 -0
- package/dist/index.d.ts +321 -0
- package/dist/index.mjs +764 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +33 -8
- package/index.js +0 -1
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
import { CanvasView, LaceTransport } from '@lace-cloud/host';
|
|
2
|
+
import { CanvasView as CanvasView$1 } from '@lace-cloud/proto';
|
|
3
|
+
|
|
4
|
+
type TextPart = {
|
|
5
|
+
kind: 'text';
|
|
6
|
+
value: string;
|
|
7
|
+
};
|
|
8
|
+
type ToolCallPart = {
|
|
9
|
+
kind: 'tool-call';
|
|
10
|
+
callId: string;
|
|
11
|
+
name: string;
|
|
12
|
+
input: unknown;
|
|
13
|
+
};
|
|
14
|
+
type ToolResultPart = {
|
|
15
|
+
kind: 'tool-result';
|
|
16
|
+
callId: string;
|
|
17
|
+
content: TextPart[];
|
|
18
|
+
isError?: boolean;
|
|
19
|
+
};
|
|
20
|
+
type Part = TextPart | ToolCallPart | ToolResultPart;
|
|
21
|
+
type ChatMessageRole = 'user' | 'assistant';
|
|
22
|
+
type ChatMessage = {
|
|
23
|
+
role: ChatMessageRole;
|
|
24
|
+
content: Part[];
|
|
25
|
+
};
|
|
26
|
+
type ChatStreamEvent = {
|
|
27
|
+
type: 'text';
|
|
28
|
+
value: string;
|
|
29
|
+
} | {
|
|
30
|
+
type: 'tool-call';
|
|
31
|
+
callId: string;
|
|
32
|
+
name: string;
|
|
33
|
+
input: unknown;
|
|
34
|
+
};
|
|
35
|
+
type ToolSchema = {
|
|
36
|
+
name: string;
|
|
37
|
+
description: string;
|
|
38
|
+
inputSchema: Record<string, unknown>;
|
|
39
|
+
};
|
|
40
|
+
type ToolResult = {
|
|
41
|
+
content: string;
|
|
42
|
+
isError?: boolean;
|
|
43
|
+
};
|
|
44
|
+
type ChatModel = {
|
|
45
|
+
readonly __chatModelBrand: unique symbol;
|
|
46
|
+
};
|
|
47
|
+
interface Disposable {
|
|
48
|
+
dispose(): void;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
interface ChatHostAdapter {
|
|
52
|
+
/**
|
|
53
|
+
* Resolve the default chat model for a turn. Return `null` if no
|
|
54
|
+
* model is available (the agentic loop will emit a `no-model`
|
|
55
|
+
* event to the webview).
|
|
56
|
+
*/
|
|
57
|
+
selectModel(): Promise<ChatModel | null>;
|
|
58
|
+
/**
|
|
59
|
+
* Send a request to the model and stream events back. The
|
|
60
|
+
* returned async iterable must yield events for each part the
|
|
61
|
+
* model produces. Tool-result parts are *not* yielded — core
|
|
62
|
+
* synthesizes those after dispatching the tools itself.
|
|
63
|
+
*
|
|
64
|
+
* The adapter is responsible for honouring `signal` (cancelling
|
|
65
|
+
* the in-flight request when it fires) and for mapping its
|
|
66
|
+
* native model stream onto {@link ChatStreamEvent}.
|
|
67
|
+
*/
|
|
68
|
+
sendRequest(model: ChatModel, messages: ChatMessage[], tools: ToolSchema[], signal: AbortSignal): AsyncIterable<ChatStreamEvent>;
|
|
69
|
+
/**
|
|
70
|
+
* Persist history under the given key. The adapter picks the
|
|
71
|
+
* storage surface — VS Code uses `context.workspaceState`;
|
|
72
|
+
* JetBrains would use `PropertiesComponent` or similar.
|
|
73
|
+
*
|
|
74
|
+
* `messages` is JSON-safe by construction (all `Part` variants
|
|
75
|
+
* are plain data), so implementations can stringify directly.
|
|
76
|
+
*/
|
|
77
|
+
saveHistory(key: string, messages: ChatMessage[]): Promise<void>;
|
|
78
|
+
/** Restore history previously persisted under `key`. Returns `null` if absent. */
|
|
79
|
+
loadHistory(key: string): Promise<ChatMessage[] | null>;
|
|
80
|
+
/**
|
|
81
|
+
* Read a user-visible configuration value, scoped to the chat
|
|
82
|
+
* subsystem. `key` is dot-separated (e.g. `'proactivity'`); the
|
|
83
|
+
* adapter maps it onto its native config system.
|
|
84
|
+
*/
|
|
85
|
+
getConfig<T>(key: string, defaultValue: T): T;
|
|
86
|
+
/** Current workspace name, used to label the engine session. `null` outside a workspace. */
|
|
87
|
+
getWorkspaceName(): string | null;
|
|
88
|
+
/** Write to the IDE's log surface (VS Code OutputChannel, JetBrains Logger, etc.). */
|
|
89
|
+
log(message: string): void;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
type CompletedTurn = {
|
|
93
|
+
messageId: string;
|
|
94
|
+
userText: string;
|
|
95
|
+
assistantText: string;
|
|
96
|
+
toolCalls: Array<{
|
|
97
|
+
name: string;
|
|
98
|
+
input: unknown;
|
|
99
|
+
resultContent: string;
|
|
100
|
+
isError?: boolean;
|
|
101
|
+
}>;
|
|
102
|
+
};
|
|
103
|
+
type ProactiveSuggestion = {
|
|
104
|
+
id: string;
|
|
105
|
+
text: string;
|
|
106
|
+
};
|
|
107
|
+
type ContextSummary = {
|
|
108
|
+
nodeCount: number;
|
|
109
|
+
warningCount: number;
|
|
110
|
+
errorCount: number;
|
|
111
|
+
sessionId: string | null;
|
|
112
|
+
};
|
|
113
|
+
type WebviewToHost = {
|
|
114
|
+
type: 'webview-ready';
|
|
115
|
+
} | {
|
|
116
|
+
type: 'user-turn';
|
|
117
|
+
text: string;
|
|
118
|
+
} | {
|
|
119
|
+
type: 'cancel-turn';
|
|
120
|
+
} | {
|
|
121
|
+
type: 'accept-proactive-suggestion';
|
|
122
|
+
id: string;
|
|
123
|
+
};
|
|
124
|
+
type HostToWebview = {
|
|
125
|
+
type: 'history';
|
|
126
|
+
turns: CompletedTurn[];
|
|
127
|
+
} | {
|
|
128
|
+
type: 'token';
|
|
129
|
+
text: string;
|
|
130
|
+
} | {
|
|
131
|
+
type: 'tool-call';
|
|
132
|
+
callId: string;
|
|
133
|
+
name: string;
|
|
134
|
+
input: unknown;
|
|
135
|
+
} | {
|
|
136
|
+
type: 'tool-result';
|
|
137
|
+
callId: string;
|
|
138
|
+
name: string;
|
|
139
|
+
content: string;
|
|
140
|
+
isError?: boolean;
|
|
141
|
+
} | {
|
|
142
|
+
type: 'turn-complete';
|
|
143
|
+
messageId: string;
|
|
144
|
+
} | {
|
|
145
|
+
type: 'turn-cancelled';
|
|
146
|
+
} | {
|
|
147
|
+
type: 'history-cleared';
|
|
148
|
+
} | {
|
|
149
|
+
type: 'no-model';
|
|
150
|
+
} | {
|
|
151
|
+
type: 'engine-unavailable';
|
|
152
|
+
} | {
|
|
153
|
+
type: 'context-summary';
|
|
154
|
+
summary: ContextSummary;
|
|
155
|
+
} | {
|
|
156
|
+
type: 'proactive-suggestion';
|
|
157
|
+
suggestion: ProactiveSuggestion;
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
type ToolHandler = (input: Record<string, unknown>) => Promise<ToolResult>;
|
|
161
|
+
type ToolRegistration = {
|
|
162
|
+
schema: ToolSchema;
|
|
163
|
+
handler: ToolHandler;
|
|
164
|
+
};
|
|
165
|
+
interface ToolRegistry {
|
|
166
|
+
register(schema: ToolSchema, handler: ToolHandler): void;
|
|
167
|
+
getHandler(name: string): ToolHandler | undefined;
|
|
168
|
+
listSchemas(): ToolSchema[];
|
|
169
|
+
listNames(): string[];
|
|
170
|
+
}
|
|
171
|
+
declare function createToolRegistry(): ToolRegistry;
|
|
172
|
+
|
|
173
|
+
interface WebviewTransport {
|
|
174
|
+
/** Send a message to the webview. */
|
|
175
|
+
postMessage(message: HostToWebview): void;
|
|
176
|
+
/**
|
|
177
|
+
* Subscribe to messages coming from the webview. Call
|
|
178
|
+
* `dispose()` on the returned value to unsubscribe.
|
|
179
|
+
*/
|
|
180
|
+
onMessage(listener: (message: WebviewToHost) => void): Disposable;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
type AgentControllerOptions = {
|
|
184
|
+
adapter: ChatHostAdapter;
|
|
185
|
+
transport: WebviewTransport;
|
|
186
|
+
toolRegistry: ToolRegistry;
|
|
187
|
+
buildSystemPrompt: (availableSystems: string[]) => string;
|
|
188
|
+
getAvailableSystems: () => string[];
|
|
189
|
+
getCanvasView: () => CanvasView | null;
|
|
190
|
+
historyKey: string;
|
|
191
|
+
maxToolRounds?: number;
|
|
192
|
+
completedTurnCap?: number;
|
|
193
|
+
};
|
|
194
|
+
declare class AgentController {
|
|
195
|
+
private readonly opts;
|
|
196
|
+
private history;
|
|
197
|
+
private completedTurns;
|
|
198
|
+
private activeTurn;
|
|
199
|
+
private transportSubscription;
|
|
200
|
+
private readonly telemetry;
|
|
201
|
+
constructor(opts: AgentControllerOptions);
|
|
202
|
+
/** Load persisted history and start listening for webview messages. */
|
|
203
|
+
init(): Promise<void>;
|
|
204
|
+
/** Cancel any active turn and unsubscribe from the webview. */
|
|
205
|
+
dispose(): void;
|
|
206
|
+
/** Drop in-memory and persisted history. */
|
|
207
|
+
clearHistory(): Promise<void>;
|
|
208
|
+
/** Push a context-summary banner into the chat UI. */
|
|
209
|
+
postContextSummary(summary: ContextSummary): void;
|
|
210
|
+
/** Forward a proactive suggestion from the watcher to the chat UI. */
|
|
211
|
+
postProactiveSuggestion(suggestion: ProactiveSuggestion): void;
|
|
212
|
+
/** Notify the chat UI that the engine is unavailable for this session. */
|
|
213
|
+
postEngineUnavailable(): void;
|
|
214
|
+
private handleWebviewMessage;
|
|
215
|
+
private runTurn;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* Trim message history to the most recent `turnCap` turns. A turn
|
|
220
|
+
* is one user message followed by one assistant message (plus any
|
|
221
|
+
* interleaved tool traffic the assistant emits). Keeping the last
|
|
222
|
+
* `turnCap` turns is approximated by keeping `turnCap * 2` messages
|
|
223
|
+
* — exact turn boundaries aren't worth tracking for a bounded cap.
|
|
224
|
+
*/
|
|
225
|
+
declare function capRecentMessages(messages: ChatMessage[], turnCap?: number): ChatMessage[];
|
|
226
|
+
|
|
227
|
+
type StateUpdatedLike = {
|
|
228
|
+
view: CanvasView$1 | undefined;
|
|
229
|
+
};
|
|
230
|
+
type GenerateProgressLike = {
|
|
231
|
+
stage: string;
|
|
232
|
+
message: string;
|
|
233
|
+
};
|
|
234
|
+
type GenerateSuccessLike = {
|
|
235
|
+
files_written: string[];
|
|
236
|
+
files: Record<string, string>;
|
|
237
|
+
};
|
|
238
|
+
type GenerateErrorLike = {
|
|
239
|
+
message: string;
|
|
240
|
+
diagnostics: Array<{
|
|
241
|
+
message: string;
|
|
242
|
+
instance_id?: string;
|
|
243
|
+
address?: string;
|
|
244
|
+
}>;
|
|
245
|
+
};
|
|
246
|
+
type EngineEventLike = {
|
|
247
|
+
state_updated?: StateUpdatedLike;
|
|
248
|
+
generate_progress?: GenerateProgressLike;
|
|
249
|
+
generate_success?: GenerateSuccessLike;
|
|
250
|
+
generate_error?: GenerateErrorLike;
|
|
251
|
+
};
|
|
252
|
+
type RuleState = {
|
|
253
|
+
prevErrorCount: number;
|
|
254
|
+
prevNodeIds: Set<string>;
|
|
255
|
+
};
|
|
256
|
+
declare function initialRuleState(): RuleState;
|
|
257
|
+
declare function matchUnwiredRequiredInput(event: EngineEventLike, state: RuleState): ProactiveSuggestion | null;
|
|
258
|
+
declare function matchGenerateError(event: EngineEventLike): ProactiveSuggestion | null;
|
|
259
|
+
declare function matchErrorsAppeared(event: EngineEventLike, state: RuleState): ProactiveSuggestion | null;
|
|
260
|
+
declare function matchAll(event: EngineEventLike, state: RuleState): ProactiveSuggestion | null;
|
|
261
|
+
declare function advanceState(event: EngineEventLike, state: RuleState): RuleState;
|
|
262
|
+
|
|
263
|
+
type ProactivityWatcherOptions = {
|
|
264
|
+
transport: LaceTransport;
|
|
265
|
+
sessionId: string;
|
|
266
|
+
adapter: Pick<ChatHostAdapter, 'getConfig' | 'log'>;
|
|
267
|
+
onSuggestion: (suggestion: ProactiveSuggestion) => void;
|
|
268
|
+
};
|
|
269
|
+
declare class ProactivityWatcher {
|
|
270
|
+
private readonly opts;
|
|
271
|
+
private stream;
|
|
272
|
+
private ruleState;
|
|
273
|
+
private retried;
|
|
274
|
+
private stopped;
|
|
275
|
+
constructor(opts: ProactivityWatcherOptions);
|
|
276
|
+
start(): void;
|
|
277
|
+
stop(): void;
|
|
278
|
+
private handleEvent;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
declare function buildSystemPrompt(systems?: string[]): string;
|
|
282
|
+
|
|
283
|
+
type ToolInvocationRecord = {
|
|
284
|
+
name: string;
|
|
285
|
+
params: unknown;
|
|
286
|
+
durationMs: number;
|
|
287
|
+
isError: boolean;
|
|
288
|
+
resultPreview: string;
|
|
289
|
+
};
|
|
290
|
+
type SessionMetadata = {
|
|
291
|
+
sessionId: string;
|
|
292
|
+
prompt: string;
|
|
293
|
+
command?: string;
|
|
294
|
+
toolCalls: ToolInvocationRecord[];
|
|
295
|
+
rounds: number;
|
|
296
|
+
startTime: number;
|
|
297
|
+
endTime?: number;
|
|
298
|
+
};
|
|
299
|
+
type Telemetry = {
|
|
300
|
+
startSession(prompt: string, command?: string): SessionMetadata;
|
|
301
|
+
logToolInvocation(session: SessionMetadata, name: string, params: unknown, result: {
|
|
302
|
+
content: string;
|
|
303
|
+
isError?: boolean;
|
|
304
|
+
}, durationMs: number): void;
|
|
305
|
+
endSession(session: SessionMetadata, maxToolRounds?: number): void;
|
|
306
|
+
};
|
|
307
|
+
declare function createTelemetry(log: (message: string) => void): Telemetry;
|
|
308
|
+
|
|
309
|
+
type FormatOptions = {
|
|
310
|
+
/** Compact: single-line lists. Detailed (default): markdown headers and bullets. */
|
|
311
|
+
compact?: boolean;
|
|
312
|
+
};
|
|
313
|
+
/**
|
|
314
|
+
* Format a CanvasView as a text summary.
|
|
315
|
+
*
|
|
316
|
+
* - compact mode: terse one-liner lists (used for chat context injection)
|
|
317
|
+
* - detailed mode: markdown with headers (used for describe_graph tool output)
|
|
318
|
+
*/
|
|
319
|
+
declare function formatCanvasState(view: CanvasView | undefined, opts?: FormatOptions): string;
|
|
320
|
+
|
|
321
|
+
export { AgentController, type AgentControllerOptions, type ChatHostAdapter, type ChatMessage, type ChatMessageRole, type ChatModel, type ChatStreamEvent, type CompletedTurn, type ContextSummary, type Disposable, type EngineEventLike, type HostToWebview, type Part, type ProactiveSuggestion, ProactivityWatcher, type ProactivityWatcherOptions, type RuleState, type SessionMetadata, type Telemetry, type TextPart, type ToolCallPart, type ToolHandler, type ToolInvocationRecord, type ToolRegistration, type ToolRegistry, type ToolResult, type ToolResultPart, type ToolSchema, type WebviewToHost, type WebviewTransport, advanceState, buildSystemPrompt, capRecentMessages, createTelemetry, createToolRegistry, formatCanvasState, initialRuleState, matchAll, matchErrorsAppeared, matchGenerateError, matchUnwiredRequiredInput };
|