@dudousxd/nestjs-agent-opencode 0.3.0 → 0.4.1
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/README.md +10 -3
- package/dist/durable/index.cjs +283 -14
- package/dist/durable/index.cjs.map +1 -1
- package/dist/durable/index.d.cts +3 -2
- package/dist/durable/index.d.ts +3 -2
- package/dist/durable/index.js +284 -15
- package/dist/durable/index.js.map +1 -1
- package/dist/{engine-Cp5uysaN.d.cts → engine-BX6MLzxs.d.cts} +109 -10
- package/dist/{engine-Cp5uysaN.d.ts → engine-BX6MLzxs.d.ts} +109 -10
- package/dist/index.cjs +279 -12
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +279 -13
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
|
@@ -18,6 +18,10 @@ interface OpenCodeClient {
|
|
|
18
18
|
sessionID: string;
|
|
19
19
|
text: string;
|
|
20
20
|
files?: OpenCodePromptFile[];
|
|
21
|
+
/** Kept on the user message OpenCode records (the engine puts the run id there). */
|
|
22
|
+
metadata?: {
|
|
23
|
+
readonly [key: string]: OpenCodeJson;
|
|
24
|
+
};
|
|
21
25
|
}): Promise<unknown>;
|
|
22
26
|
/** Stops the running execution; OpenCode answers with `session.execution.interrupted`. */
|
|
23
27
|
interrupt(args: {
|
|
@@ -87,17 +91,22 @@ interface OpenCodeClient {
|
|
|
87
91
|
message?: string;
|
|
88
92
|
}): Promise<unknown>;
|
|
89
93
|
};
|
|
90
|
-
/**
|
|
94
|
+
/**
|
|
95
|
+
* The session's messages, newest first with `order: 'desc'`, a page at a time (`cursor.next`).
|
|
96
|
+
* Optional: rewinds a session (regenerate), and lets a turn resumed after a restart recover what
|
|
97
|
+
* the session said while nobody listened.
|
|
98
|
+
*/
|
|
91
99
|
message?: {
|
|
92
100
|
list(args: {
|
|
93
101
|
sessionID: string;
|
|
94
102
|
order?: 'asc' | 'desc';
|
|
95
103
|
limit?: number;
|
|
104
|
+
cursor?: string;
|
|
96
105
|
}): Promise<{
|
|
97
|
-
data:
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
}
|
|
106
|
+
data: OpenCodeMessage[];
|
|
107
|
+
cursor?: {
|
|
108
|
+
next?: string | null;
|
|
109
|
+
};
|
|
101
110
|
}>;
|
|
102
111
|
};
|
|
103
112
|
/** Register an MCP server at a location. Optional (exposing the module's tools). */
|
|
@@ -217,6 +226,39 @@ interface OpenCodeTokens {
|
|
|
217
226
|
write: number;
|
|
218
227
|
};
|
|
219
228
|
}
|
|
229
|
+
/**
|
|
230
|
+
* One of a session's messages, as `message.list` returns them — the fields the engine reads. A
|
|
231
|
+
* `user` message carries the prompt (`text`, `metadata`); an `assistant` message is one model step
|
|
232
|
+
* (`content`, `model`, `tokens`, `cost`, `error`); `idle` marks where an execution ended (`outcome`).
|
|
233
|
+
*/
|
|
234
|
+
interface OpenCodeMessage {
|
|
235
|
+
id: string;
|
|
236
|
+
type: string;
|
|
237
|
+
metadata?: {
|
|
238
|
+
readonly [key: string]: OpenCodeJson;
|
|
239
|
+
};
|
|
240
|
+
text?: string;
|
|
241
|
+
content?: OpenCodeMessagePart[];
|
|
242
|
+
model?: {
|
|
243
|
+
providerID: string;
|
|
244
|
+
id: string;
|
|
245
|
+
};
|
|
246
|
+
cost?: number;
|
|
247
|
+
tokens?: OpenCodeTokens;
|
|
248
|
+
error?: {
|
|
249
|
+
message?: string;
|
|
250
|
+
};
|
|
251
|
+
outcome?: string;
|
|
252
|
+
}
|
|
253
|
+
/** A part of an assistant message: its text, its reasoning, or a tool call and how it went. */
|
|
254
|
+
interface OpenCodeMessagePart {
|
|
255
|
+
type: string;
|
|
256
|
+
text?: string;
|
|
257
|
+
id?: string;
|
|
258
|
+
name?: string;
|
|
259
|
+
/** A tool call's `{ status, input, error }` (a text part's is the provider's own: ignored). */
|
|
260
|
+
state?: unknown;
|
|
261
|
+
}
|
|
220
262
|
|
|
221
263
|
/** How an OpenCode execution ended. */
|
|
222
264
|
type TurnOutcome = {
|
|
@@ -263,6 +305,24 @@ interface OpenCodeUsage {
|
|
|
263
305
|
declare function emptyUsage(): OpenCodeUsage;
|
|
264
306
|
/** `a + b`; a missing side (a milestone journaled before usage travelled) counts as nothing. */
|
|
265
307
|
declare function addUsage(a: OpenCodeUsage | undefined, b: OpenCodeUsage | undefined): OpenCodeUsage;
|
|
308
|
+
/**
|
|
309
|
+
* What a turn took from the session's assistant messages (by OpenCode message id), so a turn rebuilt
|
|
310
|
+
* after a restart takes only the rest. Journaled with every `ask` milestone: what was taken up to
|
|
311
|
+
* there is persisted (the message the ask hangs on) and its usage reported.
|
|
312
|
+
*/
|
|
313
|
+
interface TurnProgress {
|
|
314
|
+
/** Characters of text taken, per assistant message. */
|
|
315
|
+
text: Record<string, number>;
|
|
316
|
+
/** Characters of reasoning taken, per assistant message. */
|
|
317
|
+
reasoning: Record<string, number>;
|
|
318
|
+
/** Tool calls taken (OpenCode's call ids), and those whose result was taken too. */
|
|
319
|
+
called: string[];
|
|
320
|
+
settled: string[];
|
|
321
|
+
/** Assistant messages whose step's usage was counted. */
|
|
322
|
+
steps: string[];
|
|
323
|
+
}
|
|
324
|
+
/** What a turn says when it was rebuilt after a restart and the session left no answer for it. */
|
|
325
|
+
declare const LOST_ANSWER_ERROR = "The answer was lost while the agent restarted; ask again.";
|
|
266
326
|
/** The model a step ran on, as OpenCode names it (`session.step.started`). */
|
|
267
327
|
interface StepModel {
|
|
268
328
|
providerID: string;
|
|
@@ -283,6 +343,7 @@ type Milestone = {
|
|
|
283
343
|
ask: PendingAsk;
|
|
284
344
|
timeoutMs?: number;
|
|
285
345
|
usage?: OpenCodeUsage;
|
|
346
|
+
progress?: TurnProgress;
|
|
286
347
|
} | {
|
|
287
348
|
kind: 'finished';
|
|
288
349
|
outcome: TurnOutcome;
|
|
@@ -319,6 +380,14 @@ interface OpenCodeTurnArgs {
|
|
|
319
380
|
}) => Promise<StepCost>;
|
|
320
381
|
/** What the run spent before this turn object existed (an earlier process, an earlier session). */
|
|
321
382
|
carried?: OpenCodeUsage;
|
|
383
|
+
/** What the turn took before this turn object existed (the last `ask` milestone's progress). */
|
|
384
|
+
progress?: TurnProgress;
|
|
385
|
+
/**
|
|
386
|
+
* Rebuilt in a process that was not listening while the session ran (a durable `observe` re-run
|
|
387
|
+
* after a restart): when the execution ends, what the session said in between is read back from
|
|
388
|
+
* its messages.
|
|
389
|
+
*/
|
|
390
|
+
resumed?: boolean;
|
|
322
391
|
logger: Logger;
|
|
323
392
|
/**
|
|
324
393
|
* An action OpenCode was allowed to run (a person approved it, or the policy did): the approval
|
|
@@ -377,6 +446,8 @@ declare class OpenCodeTurn {
|
|
|
377
446
|
private wroteMessage;
|
|
378
447
|
private ended;
|
|
379
448
|
private stepError;
|
|
449
|
+
/** What this turn object took from the session's assistant messages (see {@link TurnProgress}). */
|
|
450
|
+
private readonly took;
|
|
380
451
|
constructor(a: OpenCodeTurnArgs);
|
|
381
452
|
/**
|
|
382
453
|
* What the session had spent before this turn prompted it (`session.get`). When the execution
|
|
@@ -388,6 +459,8 @@ declare class OpenCodeTurn {
|
|
|
388
459
|
cost?: number;
|
|
389
460
|
tokens?: OpenCodeTokens;
|
|
390
461
|
} | undefined): void;
|
|
462
|
+
/** What the turn took so far: carried from before this turn object, plus what it took. */
|
|
463
|
+
progress(): TurnProgress;
|
|
391
464
|
/** What the run spent so far: carried from before this turn object, plus what it saw. */
|
|
392
465
|
totalUsage(): OpenCodeUsage;
|
|
393
466
|
get sessionId(): string;
|
|
@@ -431,6 +504,8 @@ declare class OpenCodeTurn {
|
|
|
431
504
|
private setInput;
|
|
432
505
|
private innerCalls;
|
|
433
506
|
private onEvent;
|
|
507
|
+
/** Characters taken from an assistant message's text or reasoning. */
|
|
508
|
+
private count;
|
|
434
509
|
private settleTool;
|
|
435
510
|
private modelId;
|
|
436
511
|
/** One model call's usage and cost, into the ledger and the run's total. */
|
|
@@ -456,6 +531,23 @@ declare class OpenCodeTurn {
|
|
|
456
531
|
private addResult;
|
|
457
532
|
/** What the session spent since the baseline that no event of this turn reported. */
|
|
458
533
|
private unreported;
|
|
534
|
+
/**
|
|
535
|
+
* The session's messages since this turn's prompt, oldest first: everything after its newest user
|
|
536
|
+
* message. `undefined` when they cannot be read (no `message.list`, no prompt within reach); empty
|
|
537
|
+
* when the newest prompt is another run's (this turn's never reached the session).
|
|
538
|
+
*/
|
|
539
|
+
private messagesSincePrompt;
|
|
540
|
+
/**
|
|
541
|
+
* A turn rebuilt after a restart heard only what the session said once it re-attached: what it
|
|
542
|
+
* said in between — read back from the session's messages since the prompt, less what an earlier
|
|
543
|
+
* process already took ({@link TurnProgress}) and what this one heard — is taken now, as its
|
|
544
|
+
* events would have been: text, reasoning, tool calls and results, each step's usage. A session
|
|
545
|
+
* that left nothing for the turn fails it ({@link LOST_ANSWER_ERROR}) rather than reading as an
|
|
546
|
+
* empty answer.
|
|
547
|
+
*/
|
|
548
|
+
private recover;
|
|
549
|
+
/** A tool part of a message the turn did not hear: its call, its result, whichever it lacks. */
|
|
550
|
+
private missedTool;
|
|
459
551
|
private end;
|
|
460
552
|
}
|
|
461
553
|
/**
|
|
@@ -685,6 +777,8 @@ declare class OpenCodeToolRefusedError extends Error {
|
|
|
685
777
|
declare class OpenCodeMcpEndpoint {
|
|
686
778
|
private readonly turns;
|
|
687
779
|
private readonly tokens;
|
|
780
|
+
/** Genui telemetry of the UI calls OpenCode makes (its code mode calls tools here, not in the loop). */
|
|
781
|
+
private readonly genui;
|
|
688
782
|
constructor(turns: OpenCodeTurns, tokens: OpenCodeToolsTokens);
|
|
689
783
|
/** The claims of a request's bearer token, or `null`. */
|
|
690
784
|
authenticate(authorization: string | string[] | undefined): OpenCodeToolsClaims | null;
|
|
@@ -796,7 +890,8 @@ declare class OpenCodeTurns implements OnApplicationShutdown {
|
|
|
796
890
|
private readonly host;
|
|
797
891
|
private readonly sessions;
|
|
798
892
|
private readonly settings;
|
|
799
|
-
|
|
893
|
+
/** Read by the MCP endpoint too (genui telemetry of the calls OpenCode makes). */
|
|
894
|
+
readonly store: AgentStore;
|
|
800
895
|
private readonly sink;
|
|
801
896
|
private readonly deps;
|
|
802
897
|
readonly registry: ToolRegistry;
|
|
@@ -812,7 +907,9 @@ declare class OpenCodeTurns implements OnApplicationShutdown {
|
|
|
812
907
|
private readonly spent;
|
|
813
908
|
/** When the tools endpoint was last registered for a location (`server|boot|directory|actor`). */
|
|
814
909
|
private readonly toolsIssued;
|
|
815
|
-
constructor(host: OpenCodeHost, sessions: OpenCodeSessionStore, settings: OpenCodeEngineSettings,
|
|
910
|
+
constructor(host: OpenCodeHost, sessions: OpenCodeSessionStore, settings: OpenCodeEngineSettings,
|
|
911
|
+
/** Read by the MCP endpoint too (genui telemetry of the calls OpenCode makes). */
|
|
912
|
+
store: AgentStore, sink: TokenStreamSink, deps: AgentDepsFactory, registry: ToolRegistry, skills?: SkillsConfig | undefined, memory?: MemoryConfig | undefined, queue?: ChatQueueService | undefined, toolsTokens?: (OpenCodeToolsTokens | null) | undefined, pricingStore?: AgentPricingStore, agentOptions?: {
|
|
816
913
|
priceCatalog?: PriceCatalogOptions | false;
|
|
817
914
|
});
|
|
818
915
|
private readonly prices;
|
|
@@ -923,14 +1020,16 @@ declare class OpenCodeTurns implements OnApplicationShutdown {
|
|
|
923
1020
|
*
|
|
924
1021
|
* `spent` is what the run spent before (the sum of the `usage` of its earlier milestones): a turn
|
|
925
1022
|
* rebuilt here starts from it, so the answer it persists carries the whole run's usage.
|
|
1023
|
+
* `progress` is what the turn took before (its last `ask` milestone's): a turn rebuilt here reads
|
|
1024
|
+
* back from the session's messages, when the execution ends, what nobody heard after that.
|
|
926
1025
|
*/
|
|
927
|
-
observe(runId: string, input: AgentRunInput, handle: SessionHandle, spent?: OpenCodeUsage): Promise<Milestone>;
|
|
1026
|
+
observe(runId: string, input: AgentRunInput, handle: SessionHandle, spent?: OpenCodeUsage, progress?: TurnProgress): Promise<Milestone>;
|
|
928
1027
|
/**
|
|
929
1028
|
* Hand a person's answer back to OpenCode. When the server restarted while the turn waited, the
|
|
930
1029
|
* request is gone with it: a new session is opened, told what the person decided, and prompted
|
|
931
1030
|
* to go on.
|
|
932
1031
|
*/
|
|
933
|
-
reply(runId: string, input: AgentRunInput, handle: SessionHandle, ask: PendingAsk, reply: HumanReply, spent?: OpenCodeUsage): Promise<SessionHandle>;
|
|
1032
|
+
reply(runId: string, input: AgentRunInput, handle: SessionHandle, ask: PendingAsk, reply: HumanReply, spent?: OpenCodeUsage, progress?: TurnProgress): Promise<SessionHandle>;
|
|
934
1033
|
private continueAfterRestart;
|
|
935
1034
|
/** What a session spent so far (`session.get`), or nothing when OpenCode does not say. */
|
|
936
1035
|
private sessionUsage;
|
|
@@ -995,4 +1094,4 @@ declare function openCodeControllers(options: OpenCodeEngineSettings): Type<obje
|
|
|
995
1094
|
/** The providers every OpenCode engine needs: host, session store, settings and the turn steps. */
|
|
996
1095
|
declare function openCodeProviders(options: OpenCodeEngineOptions): Provider[];
|
|
997
1096
|
|
|
998
|
-
export {
|
|
1097
|
+
export { type OpenCodeToolsOptions as A, OpenCodeToolsTokens as B, OpenCodeTurn as C, type OpenCodeTurnContext as D, type OpenCodeUsage as E, type StepCost as F, type StepModel as G, type TurnProgress as H, InMemoryOpenCodeSessionStore as I, addUsage as J, emptyUsage as K, LOST_ANSWER_ERROR as L, type Milestone as M, keyValueOpenCodeSessionStore as N, OpenCodeTurns as O, type PendingAsk as P, openCode as Q, openCodeControllers as R, type SessionHandle as S, type TurnOutcome as T, openCodeProviders as U, usageOf as V, type OpenCodeEngineSettings as a, type OpenCodeHost as b, type OpenCodeEngineOptions as c, type OpenCodeClient as d, type OpenCodeEvent as e, type OpenCodeForm as f, type OpenCodeFormValue as g, type OpenCodeFormField as h, OpenCodeMcpEndpoint as i, type OpenCodeAmendment as j, type OpenCodeCallContext as k, type OpenCodeKeyValue as l, type OpenCodeMessage as m, type OpenCodeMessagePart as n, type OpenCodeModelRef as o, type OpenCodePermissionRequest as p, type OpenCodePermissionRule as q, OpenCodeReplyMismatchError as r, type OpenCodeRunResult as s, type OpenCodeServer as t, type OpenCodeSessionCreate as u, type OpenCodeSessionRef as v, type OpenCodeSessionStore as w, type OpenCodeToolCall as x, OpenCodeToolRefusedError as y, type OpenCodeToolsClaims as z };
|
|
@@ -18,6 +18,10 @@ interface OpenCodeClient {
|
|
|
18
18
|
sessionID: string;
|
|
19
19
|
text: string;
|
|
20
20
|
files?: OpenCodePromptFile[];
|
|
21
|
+
/** Kept on the user message OpenCode records (the engine puts the run id there). */
|
|
22
|
+
metadata?: {
|
|
23
|
+
readonly [key: string]: OpenCodeJson;
|
|
24
|
+
};
|
|
21
25
|
}): Promise<unknown>;
|
|
22
26
|
/** Stops the running execution; OpenCode answers with `session.execution.interrupted`. */
|
|
23
27
|
interrupt(args: {
|
|
@@ -87,17 +91,22 @@ interface OpenCodeClient {
|
|
|
87
91
|
message?: string;
|
|
88
92
|
}): Promise<unknown>;
|
|
89
93
|
};
|
|
90
|
-
/**
|
|
94
|
+
/**
|
|
95
|
+
* The session's messages, newest first with `order: 'desc'`, a page at a time (`cursor.next`).
|
|
96
|
+
* Optional: rewinds a session (regenerate), and lets a turn resumed after a restart recover what
|
|
97
|
+
* the session said while nobody listened.
|
|
98
|
+
*/
|
|
91
99
|
message?: {
|
|
92
100
|
list(args: {
|
|
93
101
|
sessionID: string;
|
|
94
102
|
order?: 'asc' | 'desc';
|
|
95
103
|
limit?: number;
|
|
104
|
+
cursor?: string;
|
|
96
105
|
}): Promise<{
|
|
97
|
-
data:
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
}
|
|
106
|
+
data: OpenCodeMessage[];
|
|
107
|
+
cursor?: {
|
|
108
|
+
next?: string | null;
|
|
109
|
+
};
|
|
101
110
|
}>;
|
|
102
111
|
};
|
|
103
112
|
/** Register an MCP server at a location. Optional (exposing the module's tools). */
|
|
@@ -217,6 +226,39 @@ interface OpenCodeTokens {
|
|
|
217
226
|
write: number;
|
|
218
227
|
};
|
|
219
228
|
}
|
|
229
|
+
/**
|
|
230
|
+
* One of a session's messages, as `message.list` returns them — the fields the engine reads. A
|
|
231
|
+
* `user` message carries the prompt (`text`, `metadata`); an `assistant` message is one model step
|
|
232
|
+
* (`content`, `model`, `tokens`, `cost`, `error`); `idle` marks where an execution ended (`outcome`).
|
|
233
|
+
*/
|
|
234
|
+
interface OpenCodeMessage {
|
|
235
|
+
id: string;
|
|
236
|
+
type: string;
|
|
237
|
+
metadata?: {
|
|
238
|
+
readonly [key: string]: OpenCodeJson;
|
|
239
|
+
};
|
|
240
|
+
text?: string;
|
|
241
|
+
content?: OpenCodeMessagePart[];
|
|
242
|
+
model?: {
|
|
243
|
+
providerID: string;
|
|
244
|
+
id: string;
|
|
245
|
+
};
|
|
246
|
+
cost?: number;
|
|
247
|
+
tokens?: OpenCodeTokens;
|
|
248
|
+
error?: {
|
|
249
|
+
message?: string;
|
|
250
|
+
};
|
|
251
|
+
outcome?: string;
|
|
252
|
+
}
|
|
253
|
+
/** A part of an assistant message: its text, its reasoning, or a tool call and how it went. */
|
|
254
|
+
interface OpenCodeMessagePart {
|
|
255
|
+
type: string;
|
|
256
|
+
text?: string;
|
|
257
|
+
id?: string;
|
|
258
|
+
name?: string;
|
|
259
|
+
/** A tool call's `{ status, input, error }` (a text part's is the provider's own: ignored). */
|
|
260
|
+
state?: unknown;
|
|
261
|
+
}
|
|
220
262
|
|
|
221
263
|
/** How an OpenCode execution ended. */
|
|
222
264
|
type TurnOutcome = {
|
|
@@ -263,6 +305,24 @@ interface OpenCodeUsage {
|
|
|
263
305
|
declare function emptyUsage(): OpenCodeUsage;
|
|
264
306
|
/** `a + b`; a missing side (a milestone journaled before usage travelled) counts as nothing. */
|
|
265
307
|
declare function addUsage(a: OpenCodeUsage | undefined, b: OpenCodeUsage | undefined): OpenCodeUsage;
|
|
308
|
+
/**
|
|
309
|
+
* What a turn took from the session's assistant messages (by OpenCode message id), so a turn rebuilt
|
|
310
|
+
* after a restart takes only the rest. Journaled with every `ask` milestone: what was taken up to
|
|
311
|
+
* there is persisted (the message the ask hangs on) and its usage reported.
|
|
312
|
+
*/
|
|
313
|
+
interface TurnProgress {
|
|
314
|
+
/** Characters of text taken, per assistant message. */
|
|
315
|
+
text: Record<string, number>;
|
|
316
|
+
/** Characters of reasoning taken, per assistant message. */
|
|
317
|
+
reasoning: Record<string, number>;
|
|
318
|
+
/** Tool calls taken (OpenCode's call ids), and those whose result was taken too. */
|
|
319
|
+
called: string[];
|
|
320
|
+
settled: string[];
|
|
321
|
+
/** Assistant messages whose step's usage was counted. */
|
|
322
|
+
steps: string[];
|
|
323
|
+
}
|
|
324
|
+
/** What a turn says when it was rebuilt after a restart and the session left no answer for it. */
|
|
325
|
+
declare const LOST_ANSWER_ERROR = "The answer was lost while the agent restarted; ask again.";
|
|
266
326
|
/** The model a step ran on, as OpenCode names it (`session.step.started`). */
|
|
267
327
|
interface StepModel {
|
|
268
328
|
providerID: string;
|
|
@@ -283,6 +343,7 @@ type Milestone = {
|
|
|
283
343
|
ask: PendingAsk;
|
|
284
344
|
timeoutMs?: number;
|
|
285
345
|
usage?: OpenCodeUsage;
|
|
346
|
+
progress?: TurnProgress;
|
|
286
347
|
} | {
|
|
287
348
|
kind: 'finished';
|
|
288
349
|
outcome: TurnOutcome;
|
|
@@ -319,6 +380,14 @@ interface OpenCodeTurnArgs {
|
|
|
319
380
|
}) => Promise<StepCost>;
|
|
320
381
|
/** What the run spent before this turn object existed (an earlier process, an earlier session). */
|
|
321
382
|
carried?: OpenCodeUsage;
|
|
383
|
+
/** What the turn took before this turn object existed (the last `ask` milestone's progress). */
|
|
384
|
+
progress?: TurnProgress;
|
|
385
|
+
/**
|
|
386
|
+
* Rebuilt in a process that was not listening while the session ran (a durable `observe` re-run
|
|
387
|
+
* after a restart): when the execution ends, what the session said in between is read back from
|
|
388
|
+
* its messages.
|
|
389
|
+
*/
|
|
390
|
+
resumed?: boolean;
|
|
322
391
|
logger: Logger;
|
|
323
392
|
/**
|
|
324
393
|
* An action OpenCode was allowed to run (a person approved it, or the policy did): the approval
|
|
@@ -377,6 +446,8 @@ declare class OpenCodeTurn {
|
|
|
377
446
|
private wroteMessage;
|
|
378
447
|
private ended;
|
|
379
448
|
private stepError;
|
|
449
|
+
/** What this turn object took from the session's assistant messages (see {@link TurnProgress}). */
|
|
450
|
+
private readonly took;
|
|
380
451
|
constructor(a: OpenCodeTurnArgs);
|
|
381
452
|
/**
|
|
382
453
|
* What the session had spent before this turn prompted it (`session.get`). When the execution
|
|
@@ -388,6 +459,8 @@ declare class OpenCodeTurn {
|
|
|
388
459
|
cost?: number;
|
|
389
460
|
tokens?: OpenCodeTokens;
|
|
390
461
|
} | undefined): void;
|
|
462
|
+
/** What the turn took so far: carried from before this turn object, plus what it took. */
|
|
463
|
+
progress(): TurnProgress;
|
|
391
464
|
/** What the run spent so far: carried from before this turn object, plus what it saw. */
|
|
392
465
|
totalUsage(): OpenCodeUsage;
|
|
393
466
|
get sessionId(): string;
|
|
@@ -431,6 +504,8 @@ declare class OpenCodeTurn {
|
|
|
431
504
|
private setInput;
|
|
432
505
|
private innerCalls;
|
|
433
506
|
private onEvent;
|
|
507
|
+
/** Characters taken from an assistant message's text or reasoning. */
|
|
508
|
+
private count;
|
|
434
509
|
private settleTool;
|
|
435
510
|
private modelId;
|
|
436
511
|
/** One model call's usage and cost, into the ledger and the run's total. */
|
|
@@ -456,6 +531,23 @@ declare class OpenCodeTurn {
|
|
|
456
531
|
private addResult;
|
|
457
532
|
/** What the session spent since the baseline that no event of this turn reported. */
|
|
458
533
|
private unreported;
|
|
534
|
+
/**
|
|
535
|
+
* The session's messages since this turn's prompt, oldest first: everything after its newest user
|
|
536
|
+
* message. `undefined` when they cannot be read (no `message.list`, no prompt within reach); empty
|
|
537
|
+
* when the newest prompt is another run's (this turn's never reached the session).
|
|
538
|
+
*/
|
|
539
|
+
private messagesSincePrompt;
|
|
540
|
+
/**
|
|
541
|
+
* A turn rebuilt after a restart heard only what the session said once it re-attached: what it
|
|
542
|
+
* said in between — read back from the session's messages since the prompt, less what an earlier
|
|
543
|
+
* process already took ({@link TurnProgress}) and what this one heard — is taken now, as its
|
|
544
|
+
* events would have been: text, reasoning, tool calls and results, each step's usage. A session
|
|
545
|
+
* that left nothing for the turn fails it ({@link LOST_ANSWER_ERROR}) rather than reading as an
|
|
546
|
+
* empty answer.
|
|
547
|
+
*/
|
|
548
|
+
private recover;
|
|
549
|
+
/** A tool part of a message the turn did not hear: its call, its result, whichever it lacks. */
|
|
550
|
+
private missedTool;
|
|
459
551
|
private end;
|
|
460
552
|
}
|
|
461
553
|
/**
|
|
@@ -685,6 +777,8 @@ declare class OpenCodeToolRefusedError extends Error {
|
|
|
685
777
|
declare class OpenCodeMcpEndpoint {
|
|
686
778
|
private readonly turns;
|
|
687
779
|
private readonly tokens;
|
|
780
|
+
/** Genui telemetry of the UI calls OpenCode makes (its code mode calls tools here, not in the loop). */
|
|
781
|
+
private readonly genui;
|
|
688
782
|
constructor(turns: OpenCodeTurns, tokens: OpenCodeToolsTokens);
|
|
689
783
|
/** The claims of a request's bearer token, or `null`. */
|
|
690
784
|
authenticate(authorization: string | string[] | undefined): OpenCodeToolsClaims | null;
|
|
@@ -796,7 +890,8 @@ declare class OpenCodeTurns implements OnApplicationShutdown {
|
|
|
796
890
|
private readonly host;
|
|
797
891
|
private readonly sessions;
|
|
798
892
|
private readonly settings;
|
|
799
|
-
|
|
893
|
+
/** Read by the MCP endpoint too (genui telemetry of the calls OpenCode makes). */
|
|
894
|
+
readonly store: AgentStore;
|
|
800
895
|
private readonly sink;
|
|
801
896
|
private readonly deps;
|
|
802
897
|
readonly registry: ToolRegistry;
|
|
@@ -812,7 +907,9 @@ declare class OpenCodeTurns implements OnApplicationShutdown {
|
|
|
812
907
|
private readonly spent;
|
|
813
908
|
/** When the tools endpoint was last registered for a location (`server|boot|directory|actor`). */
|
|
814
909
|
private readonly toolsIssued;
|
|
815
|
-
constructor(host: OpenCodeHost, sessions: OpenCodeSessionStore, settings: OpenCodeEngineSettings,
|
|
910
|
+
constructor(host: OpenCodeHost, sessions: OpenCodeSessionStore, settings: OpenCodeEngineSettings,
|
|
911
|
+
/** Read by the MCP endpoint too (genui telemetry of the calls OpenCode makes). */
|
|
912
|
+
store: AgentStore, sink: TokenStreamSink, deps: AgentDepsFactory, registry: ToolRegistry, skills?: SkillsConfig | undefined, memory?: MemoryConfig | undefined, queue?: ChatQueueService | undefined, toolsTokens?: (OpenCodeToolsTokens | null) | undefined, pricingStore?: AgentPricingStore, agentOptions?: {
|
|
816
913
|
priceCatalog?: PriceCatalogOptions | false;
|
|
817
914
|
});
|
|
818
915
|
private readonly prices;
|
|
@@ -923,14 +1020,16 @@ declare class OpenCodeTurns implements OnApplicationShutdown {
|
|
|
923
1020
|
*
|
|
924
1021
|
* `spent` is what the run spent before (the sum of the `usage` of its earlier milestones): a turn
|
|
925
1022
|
* rebuilt here starts from it, so the answer it persists carries the whole run's usage.
|
|
1023
|
+
* `progress` is what the turn took before (its last `ask` milestone's): a turn rebuilt here reads
|
|
1024
|
+
* back from the session's messages, when the execution ends, what nobody heard after that.
|
|
926
1025
|
*/
|
|
927
|
-
observe(runId: string, input: AgentRunInput, handle: SessionHandle, spent?: OpenCodeUsage): Promise<Milestone>;
|
|
1026
|
+
observe(runId: string, input: AgentRunInput, handle: SessionHandle, spent?: OpenCodeUsage, progress?: TurnProgress): Promise<Milestone>;
|
|
928
1027
|
/**
|
|
929
1028
|
* Hand a person's answer back to OpenCode. When the server restarted while the turn waited, the
|
|
930
1029
|
* request is gone with it: a new session is opened, told what the person decided, and prompted
|
|
931
1030
|
* to go on.
|
|
932
1031
|
*/
|
|
933
|
-
reply(runId: string, input: AgentRunInput, handle: SessionHandle, ask: PendingAsk, reply: HumanReply, spent?: OpenCodeUsage): Promise<SessionHandle>;
|
|
1032
|
+
reply(runId: string, input: AgentRunInput, handle: SessionHandle, ask: PendingAsk, reply: HumanReply, spent?: OpenCodeUsage, progress?: TurnProgress): Promise<SessionHandle>;
|
|
934
1033
|
private continueAfterRestart;
|
|
935
1034
|
/** What a session spent so far (`session.get`), or nothing when OpenCode does not say. */
|
|
936
1035
|
private sessionUsage;
|
|
@@ -995,4 +1094,4 @@ declare function openCodeControllers(options: OpenCodeEngineSettings): Type<obje
|
|
|
995
1094
|
/** The providers every OpenCode engine needs: host, session store, settings and the turn steps. */
|
|
996
1095
|
declare function openCodeProviders(options: OpenCodeEngineOptions): Provider[];
|
|
997
1096
|
|
|
998
|
-
export {
|
|
1097
|
+
export { type OpenCodeToolsOptions as A, OpenCodeToolsTokens as B, OpenCodeTurn as C, type OpenCodeTurnContext as D, type OpenCodeUsage as E, type StepCost as F, type StepModel as G, type TurnProgress as H, InMemoryOpenCodeSessionStore as I, addUsage as J, emptyUsage as K, LOST_ANSWER_ERROR as L, type Milestone as M, keyValueOpenCodeSessionStore as N, OpenCodeTurns as O, type PendingAsk as P, openCode as Q, openCodeControllers as R, type SessionHandle as S, type TurnOutcome as T, openCodeProviders as U, usageOf as V, type OpenCodeEngineSettings as a, type OpenCodeHost as b, type OpenCodeEngineOptions as c, type OpenCodeClient as d, type OpenCodeEvent as e, type OpenCodeForm as f, type OpenCodeFormValue as g, type OpenCodeFormField as h, OpenCodeMcpEndpoint as i, type OpenCodeAmendment as j, type OpenCodeCallContext as k, type OpenCodeKeyValue as l, type OpenCodeMessage as m, type OpenCodeMessagePart as n, type OpenCodeModelRef as o, type OpenCodePermissionRequest as p, type OpenCodePermissionRule as q, OpenCodeReplyMismatchError as r, type OpenCodeRunResult as s, type OpenCodeServer as t, type OpenCodeSessionCreate as u, type OpenCodeSessionRef as v, type OpenCodeSessionStore as w, type OpenCodeToolCall as x, OpenCodeToolRefusedError as y, type OpenCodeToolsClaims as z };
|