@nathapp/nax-agent 0.3.0 → 0.3.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/CHANGELOG.md +15 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +1 -0
- package/dist/native/session/turn-types.d.ts +4 -5
- package/dist/native/session/turn-types.js +8 -8
- package/dist/session/agent-session-errors.d.ts +1 -1
- package/dist/session/agent-session-turn.js +12 -5
- package/dist/session/session-types.d.ts +10 -0
- package/dist/session/turn-event.d.ts +7 -0
- package/dist/session/turn-spend.d.ts +18 -0
- package/dist/session/turn-spend.js +9 -0
- package/dist/tools/index.d.ts +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,21 @@ All notable changes to `@nathapp/nax-agent` are recorded here. The format follow
|
|
|
4
4
|
[Keep a Changelog](https://keepachangelog.com/en/1.1.0/). While the version is `0.x`, a minor
|
|
5
5
|
release may change the public API.
|
|
6
6
|
|
|
7
|
+
## [0.3.1] - 2026-10-07
|
|
8
|
+
|
|
9
|
+
### Added
|
|
10
|
+
|
|
11
|
+
- `attachTurnSpend(err, spend)` and `readTurnSpend(err)`, with the `FailedTurnSpend` type: a backend attaches the spend a failed turn had already incurred to the error it throws, and the turn's `turn_end` reports it (#2367).
|
|
12
|
+
- `OpenSessionOpts.toolAudit` (optional `{ dir, header }`): the tool-audit ledger location and header for an S1 adapter that writes its own ledger (nax's ACP adapter, S4b). nax-agent itself does not read it; native takes its sink from coding-tool support.
|
|
13
|
+
- `resultBytes` (optional) on the `tool_result` turn event: the UTF-8 byte length of the full result before the preview cap.
|
|
14
|
+
- `ToolAuditHeader` is exported from the package entry.
|
|
15
|
+
- `AGENT_SESSION_RATE_LIMITED` error code (a backend's rate-limited turn).
|
|
16
|
+
- `tool_progress` turn event: a running tool's liveness beat (no content), for S1 callers such as nax's idle watchdog. The session facade does not forward it as a session event.
|
|
17
|
+
|
|
18
|
+
### Fixed
|
|
19
|
+
|
|
20
|
+
- `turn_end` of an errored, cancelled or timed-out turn carries `costSource` when the failed turn's spend says how it was priced (#2367).
|
|
21
|
+
|
|
7
22
|
## [0.3.0] - 2026-10-06
|
|
8
23
|
|
|
9
24
|
The backend seam for S4. Breaking: `createAgentSession` takes a `SessionBackend`. nax behaviour unchanged.
|
package/dist/index.d.ts
CHANGED
|
@@ -37,8 +37,9 @@ export type { NativeBackendOptions } from "#src/session/native-backend-options";
|
|
|
37
37
|
export type { ProtocolIds } from "#src/session/protocol-types";
|
|
38
38
|
export type { ApprovalRequest, BackendInfo, BackendOpenContext, OpenedBackend, SessionAskPort, SessionBackend, TurnContribution, } from "#src/session/session-backend";
|
|
39
39
|
export { type AgentSessionAdapter, type AuthStamp, type InteractionExchange, type InvalidToolCallDetail, type OpenSessionOpts, type SendTurnOpts, type SessionHandle, type SessionModel, SessionTurnError, type TrackedSpawnDeadlineOptions, type TurnResult, } from "#src/session/session-types";
|
|
40
|
+
export { attachTurnSpend, type FailedTurnSpend, readTurnSpend } from "#src/session/turn-spend";
|
|
40
41
|
export type { JSONSchema, ToolDescriptor, } from "#src/session/tool-descriptor";
|
|
41
42
|
export { createTurnDeadline, type TurnDeadline, } from "#src/session/turn-deadline";
|
|
42
43
|
export type { TurnEvent, TurnEventSink } from "#src/session/turn-event";
|
|
43
|
-
export { adaptProviderTool, advertisedSchemaBytes, applyModelTruncationPolicy, BASH_TIMEOUT_MS, BASH_TOOL_NAME, buildCommitArgvs, buildGitArgv, buildGrepArgv, type CodingTool, type CodingToolName, type CodingToolOutcome, type CodingToolRuntime, classifyExec, compileToolPolicy, createBashTool, createCodingToolRuntime, createNoOpToolAuditSink, createRunCommandTool, createToolAuditSink, cutBufferToByteCap, DEFAULT_BASH_SHELL, DEFAULT_LOG_FORMAT, DEFAULT_LOG_MAX_COUNT, DEFAULT_TOOL_MAX_BYTES, DEFAULT_TOOL_MAX_FILE_BYTES, type DeclaredCommandRequest, type DeclaredCommandResult, type DeclaredCommandRunner, deleteTool, EXEC_TOOL_NAME, type ExecTarget, editTool, expandMcpRuleGrants, expandProviderGrants, flushOpenToolAuditSinks, GIT_ESCAPE_FLAGS, GIT_READ_VERBS, getCodingTool, gitCommitTool, gitExcludePathspecsOf, gitIgnorePatternsOf, gitTool, globTool, grepTool, isKnownManager, listCodingTools, MAX_PROVIDER_DESCRIPTION_BYTES, MAX_PROVIDER_SCHEMA_BYTES, MCP_RULE_TOOL, MODEL_MAX_BYTES, MODEL_MAX_LINE_CHARS, MODEL_MAX_LINES, type ModelTruncationOptions, mcpRuleAdmits, type NormalizeInput, type NormalizeResult, namespacedToolName, narrowGrants, normalizeExec, normalizeManagerBinary, type PolicyVerdict, PROVIDER_ID_RE, type ProtectedPathsPolicy, type ProviderGrantEntry, type ProviderKind, type ProviderTool, partitionMcpRules, partitionNaxOwnedPaths, providerAttachesTo, READ_CEILING, RESERVED_TOOL_NAMES, type ReadFileSliceOptions, type ReadFileSliceResult, type RegisteredSink, type ResolvedProviderTools, readFileSlice, readTool, registerBuiltinCodingTools, registerBuiltinTool, registerCodingTool, registerToolAuditSink, requestCapabilityTool, resolveProviderTools, resolveWithin, SCRATCHPAD_DIR, SPILL_DIR, type SpillRequest, sanitizeProviderTools, scratchpadListTool, scratchpadReadTool, scratchpadWriteTool, spillRelativePath, substituteCommand, substituteCommandSpec, type ToolAuditSink, type ToolCallContext, type ToolCallRecord, type ToolGrant, type ToolPatternNarrowing, type ToolPolicy, type ToolPolicyOptions, type ToolProvider, type ToolResult, type ToolRunContext, type ToolScope, type TruncateForModelOptions, type TruncationDirection, type TruncationResult, truncateForModel, truncationDirectionFor, unregisterToolAuditSink, validateProviderId, writeSpill, writeTool, } from "#src/tools/index";
|
|
44
|
+
export { adaptProviderTool, advertisedSchemaBytes, applyModelTruncationPolicy, BASH_TIMEOUT_MS, BASH_TOOL_NAME, buildCommitArgvs, buildGitArgv, buildGrepArgv, type CodingTool, type CodingToolName, type CodingToolOutcome, type CodingToolRuntime, classifyExec, compileToolPolicy, createBashTool, createCodingToolRuntime, createNoOpToolAuditSink, createRunCommandTool, createToolAuditSink, cutBufferToByteCap, DEFAULT_BASH_SHELL, DEFAULT_LOG_FORMAT, DEFAULT_LOG_MAX_COUNT, DEFAULT_TOOL_MAX_BYTES, DEFAULT_TOOL_MAX_FILE_BYTES, type DeclaredCommandRequest, type DeclaredCommandResult, type DeclaredCommandRunner, deleteTool, EXEC_TOOL_NAME, type ExecTarget, editTool, expandMcpRuleGrants, expandProviderGrants, flushOpenToolAuditSinks, GIT_ESCAPE_FLAGS, GIT_READ_VERBS, getCodingTool, gitCommitTool, gitExcludePathspecsOf, gitIgnorePatternsOf, gitTool, globTool, grepTool, isKnownManager, listCodingTools, MAX_PROVIDER_DESCRIPTION_BYTES, MAX_PROVIDER_SCHEMA_BYTES, MCP_RULE_TOOL, MODEL_MAX_BYTES, MODEL_MAX_LINE_CHARS, MODEL_MAX_LINES, type ModelTruncationOptions, mcpRuleAdmits, type NormalizeInput, type NormalizeResult, namespacedToolName, narrowGrants, normalizeExec, normalizeManagerBinary, type PolicyVerdict, PROVIDER_ID_RE, type ProtectedPathsPolicy, type ProviderGrantEntry, type ProviderKind, type ProviderTool, partitionMcpRules, partitionNaxOwnedPaths, providerAttachesTo, READ_CEILING, RESERVED_TOOL_NAMES, type ReadFileSliceOptions, type ReadFileSliceResult, type RegisteredSink, type ResolvedProviderTools, readFileSlice, readTool, registerBuiltinCodingTools, registerBuiltinTool, registerCodingTool, registerToolAuditSink, requestCapabilityTool, resolveProviderTools, resolveWithin, SCRATCHPAD_DIR, SPILL_DIR, type SpillRequest, sanitizeProviderTools, scratchpadListTool, scratchpadReadTool, scratchpadWriteTool, spillRelativePath, substituteCommand, substituteCommandSpec, type ToolAuditHeader, type ToolAuditSink, type ToolCallContext, type ToolCallRecord, type ToolGrant, type ToolPatternNarrowing, type ToolPolicy, type ToolPolicyOptions, type ToolProvider, type ToolResult, type ToolRunContext, type ToolScope, type TruncateForModelOptions, type TruncationDirection, type TruncationResult, truncateForModel, truncationDirectionFor, unregisterToolAuditSink, validateProviderId, writeSpill, writeTool, } from "#src/tools/index";
|
|
44
45
|
export { EMPTY_OWNED_PATHS_POLICY, type OwnedBashCandidate, type OwnedPathsPolicy, } from "#src/tools/owned-paths";
|
package/dist/index.js
CHANGED
|
@@ -26,6 +26,7 @@ export { AgentSessionError } from "#src/session/agent-session-errors";
|
|
|
26
26
|
export { NO_OP_INTERACTION_HANDLER, } from "#src/session/interaction-handler";
|
|
27
27
|
export { nativeBackend } from "#src/session/native-backend";
|
|
28
28
|
export { SessionTurnError, } from "#src/session/session-types";
|
|
29
|
+
export { attachTurnSpend, readTurnSpend } from "#src/session/turn-spend";
|
|
29
30
|
export { createTurnDeadline, } from "#src/session/turn-deadline";
|
|
30
31
|
export { adaptProviderTool, advertisedSchemaBytes, applyModelTruncationPolicy, BASH_TIMEOUT_MS, BASH_TOOL_NAME, buildCommitArgvs, buildGitArgv, buildGrepArgv, classifyExec, compileToolPolicy, createBashTool, createCodingToolRuntime, createNoOpToolAuditSink, createRunCommandTool, createToolAuditSink, cutBufferToByteCap, DEFAULT_BASH_SHELL, DEFAULT_LOG_FORMAT, DEFAULT_LOG_MAX_COUNT, DEFAULT_TOOL_MAX_BYTES, DEFAULT_TOOL_MAX_FILE_BYTES, deleteTool, EXEC_TOOL_NAME, editTool, expandMcpRuleGrants, expandProviderGrants, flushOpenToolAuditSinks, GIT_ESCAPE_FLAGS, GIT_READ_VERBS, getCodingTool, gitCommitTool, gitExcludePathspecsOf, gitIgnorePatternsOf, gitTool, globTool, grepTool, isKnownManager, listCodingTools, MAX_PROVIDER_DESCRIPTION_BYTES, MAX_PROVIDER_SCHEMA_BYTES, MCP_RULE_TOOL, MODEL_MAX_BYTES, MODEL_MAX_LINE_CHARS, MODEL_MAX_LINES, mcpRuleAdmits, namespacedToolName, narrowGrants, normalizeExec, normalizeManagerBinary, PROVIDER_ID_RE, partitionMcpRules, partitionNaxOwnedPaths, providerAttachesTo, READ_CEILING, RESERVED_TOOL_NAMES, readFileSlice, readTool, registerBuiltinCodingTools, registerBuiltinTool, registerCodingTool, registerToolAuditSink, requestCapabilityTool, resolveProviderTools, resolveWithin, SCRATCHPAD_DIR, SPILL_DIR, sanitizeProviderTools, scratchpadListTool, scratchpadReadTool, scratchpadWriteTool, spillRelativePath, substituteCommand, substituteCommandSpec, truncateForModel, truncationDirectionFor, unregisterToolAuditSink, validateProviderId, writeSpill, writeTool, } from "#src/tools/index";
|
|
31
32
|
export { EMPTY_OWNED_PATHS_POLICY, } from "#src/tools/owned-paths";
|
|
@@ -6,11 +6,10 @@
|
|
|
6
6
|
* algorithm and the file under the 600-line hard limit (see
|
|
7
7
|
* .nax/rules/project-conventions.md).
|
|
8
8
|
*
|
|
9
|
-
* The failure-usage ledger (`
|
|
10
|
-
* `
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
* public API. Adapter.ts reads through `readNativeTurnFailureUsage` to
|
|
9
|
+
* The failure-usage ledger's native API (`recordNativeTurnFailureUsage` /
|
|
10
|
+
* `readNativeTurnFailureUsage`) also lives here; the WeakMap itself lives in
|
|
11
|
+
* `#src/session/turn-spend`, shared with ACP backends (#2367). The loop's
|
|
12
|
+
* catch block only ever calls the write side through this file's public API. Adapter.ts reads through `readNativeTurnFailureUsage` to
|
|
14
13
|
* attribute round-trip spend to the error a failed turn threw (nax#1840).
|
|
15
14
|
*/
|
|
16
15
|
import type { ConversationMessage, ThinkingBlock, ToolCall } from "@nathapp/nax-ai";
|
|
@@ -6,21 +6,21 @@
|
|
|
6
6
|
* algorithm and the file under the 600-line hard limit (see
|
|
7
7
|
* .nax/rules/project-conventions.md).
|
|
8
8
|
*
|
|
9
|
-
* The failure-usage ledger (`
|
|
10
|
-
* `
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
* public API. Adapter.ts reads through `readNativeTurnFailureUsage` to
|
|
9
|
+
* The failure-usage ledger's native API (`recordNativeTurnFailureUsage` /
|
|
10
|
+
* `readNativeTurnFailureUsage`) also lives here; the WeakMap itself lives in
|
|
11
|
+
* `#src/session/turn-spend`, shared with ACP backends (#2367). The loop's
|
|
12
|
+
* catch block only ever calls the write side through this file's public API. Adapter.ts reads through `readNativeTurnFailureUsage` to
|
|
14
13
|
* attribute round-trip spend to the error a failed turn threw (nax#1840).
|
|
15
14
|
*/
|
|
16
|
-
|
|
15
|
+
import { attachTurnSpend, readTurnSpend } from "#src/session/turn-spend";
|
|
17
16
|
/** Writes the spend a failed turn accumulated, keyed on the error's own identity. */
|
|
18
17
|
export function recordNativeTurnFailureUsage(err, usage) {
|
|
19
|
-
|
|
18
|
+
attachTurnSpend(err, usage);
|
|
20
19
|
}
|
|
21
20
|
/** Reads back what the catch block recorded, if anything did. */
|
|
22
21
|
export function readNativeTurnFailureUsage(err) {
|
|
23
|
-
|
|
22
|
+
const spend = readTurnSpend(err);
|
|
23
|
+
return spend === undefined ? undefined : { tokenUsage: spend.tokenUsage, costUsd: spend.costUsd };
|
|
24
24
|
}
|
|
25
25
|
/**
|
|
26
26
|
* Translate a `TokenUsage`'s cache fields into the spread that the
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* or registerCodingTool's TOOL_NAME_RESERVED.
|
|
5
5
|
*/
|
|
6
6
|
import { NaxError } from "#src/infra/nax-error";
|
|
7
|
-
export type AgentSessionErrorCode = "AGENT_SESSION_INVALID_OPTIONS" | "AGENT_SESSION_EXISTS" | "AGENT_SESSION_BUSY" | "AGENT_SESSION_CLOSED" | "AGENT_SESSION_INVALID_ANSWER" | "AGENT_SESSION_NOT_FOUND" | "AGENT_SESSION_SCHEMA_UNSUPPORTED" | "AGENT_SESSION_MODEL_MISMATCH" | "AGENT_SESSION_SANDBOX_UNAVAILABLE" | "AGENT_SESSION_TOOL_NAME_RESERVED" | "AGENT_SESSION_BACKEND_UNAVAILABLE" | "AGENT_SESSION_AUTH_REQUIRED" | "AGENT_SESSION_CAPABILITY_UNSUPPORTED" | "AGENT_SESSION_BACKEND_MISMATCH";
|
|
7
|
+
export type AgentSessionErrorCode = "AGENT_SESSION_INVALID_OPTIONS" | "AGENT_SESSION_EXISTS" | "AGENT_SESSION_BUSY" | "AGENT_SESSION_CLOSED" | "AGENT_SESSION_INVALID_ANSWER" | "AGENT_SESSION_NOT_FOUND" | "AGENT_SESSION_SCHEMA_UNSUPPORTED" | "AGENT_SESSION_MODEL_MISMATCH" | "AGENT_SESSION_SANDBOX_UNAVAILABLE" | "AGENT_SESSION_TOOL_NAME_RESERVED" | "AGENT_SESSION_BACKEND_UNAVAILABLE" | "AGENT_SESSION_AUTH_REQUIRED" | "AGENT_SESSION_RATE_LIMITED" | "AGENT_SESSION_CAPABILITY_UNSUPPORTED" | "AGENT_SESSION_BACKEND_MISMATCH";
|
|
8
8
|
export declare class AgentSessionError extends NaxError {
|
|
9
9
|
readonly code: AgentSessionErrorCode;
|
|
10
10
|
constructor(message: string, code: AgentSessionErrorCode, context?: Record<string, unknown>);
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { NaxError } from "#src/infra/nax-error";
|
|
2
2
|
import { redactSecrets } from "#src/internal/redact";
|
|
3
|
-
import { readNativeTurnFailureUsage } from "#src/native/session/turn-types";
|
|
4
3
|
import { _agentSessionDeps } from "./agent-session-deps.js";
|
|
5
4
|
import { AgentSessionError } from "./agent-session-errors.js";
|
|
6
5
|
import { createSessionEventChannel } from "./session-event-channel.js";
|
|
7
6
|
import { SessionTurnError } from "./session-types.js";
|
|
7
|
+
import { readTurnSpend } from "./turn-spend.js";
|
|
8
8
|
/** The ask_human budget per turn: nax's agent.maxInteractionTurns default. */
|
|
9
9
|
export const ASK_HUMAN_BUDGET = 10;
|
|
10
10
|
/** Codes of the turn signal's abort reasons. AbortSignal keeps the first reason, so the first cause wins. */
|
|
@@ -57,10 +57,13 @@ function errorOf(err) {
|
|
|
57
57
|
return failure(err.code, message);
|
|
58
58
|
return failure("AGENT_SESSION_TURN_FAILED", message);
|
|
59
59
|
}
|
|
60
|
+
/** A failed turn's spend: attached to its error (#2367), carried by a SessionTurnError, or zero. */
|
|
60
61
|
function spendOf(err) {
|
|
61
|
-
const
|
|
62
|
-
if (
|
|
63
|
-
|
|
62
|
+
const attached = readTurnSpend(err);
|
|
63
|
+
if (attached !== undefined) {
|
|
64
|
+
const { tokenUsage: usage, costUsd, costSource } = attached;
|
|
65
|
+
return costSource === undefined ? { usage, costUsd } : { usage, costUsd, costSource };
|
|
66
|
+
}
|
|
64
67
|
if (err instanceof SessionTurnError)
|
|
65
68
|
return { usage: err.tokenUsage ?? ZERO_USAGE, costUsd: err.estimatedCostUsd ?? 0 };
|
|
66
69
|
return { usage: ZERO_USAGE, costUsd: 0 };
|
|
@@ -84,7 +87,11 @@ function sendTurn(ctx, live, message) {
|
|
|
84
87
|
maxInteractions: ASK_HUMAN_BUDGET,
|
|
85
88
|
turnId: live.turnId,
|
|
86
89
|
signal: live.signal,
|
|
87
|
-
|
|
90
|
+
// tool_progress is a liveness beat for S1 callers (nax's idle watchdog), not a session event.
|
|
91
|
+
onTurnEvent: (event) => {
|
|
92
|
+
if (event.type !== "tool_progress")
|
|
93
|
+
live.emit(event);
|
|
94
|
+
},
|
|
88
95
|
});
|
|
89
96
|
}
|
|
90
97
|
/** Writes the turn marker; a failure is returned, not thrown. */
|
|
@@ -136,6 +136,16 @@ export interface OpenSessionOpts extends TrackedSpawnDeadlineOptions {
|
|
|
136
136
|
* scratch dir reaches the adapter otherwise. ACP ignores it.
|
|
137
137
|
*/
|
|
138
138
|
transcriptDir?: string;
|
|
139
|
+
/**
|
|
140
|
+
* S4b spec 7.4: where an S1 adapter that writes its own tool-audit ledger (nax's
|
|
141
|
+
* ACP adapter) writes it, and the run-scoped header stamped on it. nax fills it
|
|
142
|
+
* from the same resolution the native coding tools use. nax-agent itself does not
|
|
143
|
+
* read it; native takes its sink from coding-tool support.
|
|
144
|
+
*/
|
|
145
|
+
toolAudit?: {
|
|
146
|
+
readonly dir: string;
|
|
147
|
+
readonly header: import("#src/tools/tool-audit").ToolAuditHeader;
|
|
148
|
+
};
|
|
139
149
|
/**
|
|
140
150
|
* Native: identity that owns this session's transcript — the op invocation's
|
|
141
151
|
* `scopeId ?? callId`. Stable across the retries and hops of one invocation,
|
|
@@ -43,6 +43,13 @@ export type TurnEvent = {
|
|
|
43
43
|
readonly callId: string;
|
|
44
44
|
readonly isError: boolean;
|
|
45
45
|
readonly preview: string;
|
|
46
|
+
/** UTF-8 byte length of the full result before the preview cap (S4b spec 7.4). Absent when unknown. */
|
|
47
|
+
readonly resultBytes?: number;
|
|
48
|
+
}
|
|
49
|
+
/** A running tool's liveness beat (an ACP heartbeat); carries no content. Not a session event. */
|
|
50
|
+
| {
|
|
51
|
+
readonly type: "tool_progress";
|
|
52
|
+
readonly callId: string;
|
|
46
53
|
} | {
|
|
47
54
|
readonly type: "usage";
|
|
48
55
|
readonly round: number;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The spend a failed turn had already incurred, attached to the error it throws
|
|
3
|
+
* (#2367). Keyed on the error's identity, so the error itself is rethrown
|
|
4
|
+
* unchanged and keeps its own code. The facade's turn_end reads it on every
|
|
5
|
+
* error path; the native loop writes it through recordNativeTurnFailureUsage
|
|
6
|
+
* (nax#1840), an ACP backend through attachTurnSpend.
|
|
7
|
+
*/
|
|
8
|
+
import type { TokenUsage } from "#src/cost/standard-types";
|
|
9
|
+
import type { CostSource } from "./agent-session-types.ts";
|
|
10
|
+
export interface FailedTurnSpend {
|
|
11
|
+
readonly tokenUsage: TokenUsage;
|
|
12
|
+
readonly costUsd: number;
|
|
13
|
+
readonly costSource?: CostSource;
|
|
14
|
+
}
|
|
15
|
+
/** Attaches the spend a failed turn had already incurred to the error it throws. */
|
|
16
|
+
export declare function attachTurnSpend(err: object, spend: FailedTurnSpend): void;
|
|
17
|
+
/** The spend attached to `err`, if any. */
|
|
18
|
+
export declare function readTurnSpend(err: unknown): FailedTurnSpend | undefined;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
const spendByError = new WeakMap();
|
|
2
|
+
/** Attaches the spend a failed turn had already incurred to the error it throws. */
|
|
3
|
+
export function attachTurnSpend(err, spend) {
|
|
4
|
+
spendByError.set(err, Object.freeze({ ...spend }));
|
|
5
|
+
}
|
|
6
|
+
/** The spend attached to `err`, if any. */
|
|
7
|
+
export function readTurnSpend(err) {
|
|
8
|
+
return typeof err === "object" && err !== null ? spendByError.get(err) : undefined;
|
|
9
|
+
}
|
package/dist/tools/index.d.ts
CHANGED
|
@@ -28,7 +28,7 @@ export type { CodingToolOutcome, CodingToolRuntime, ToolCallContext } from "./ru
|
|
|
28
28
|
export { _codingToolDeps, _resetBuiltinsForTest, createCodingToolRuntime, DEFAULT_TOOL_MAX_BYTES, DEFAULT_TOOL_MAX_FILE_BYTES, registerBuiltinCodingTools, } from "./runtime.ts";
|
|
29
29
|
export { SCRATCHPAD_DIR, scratchpadListTool, scratchpadReadTool, scratchpadWriteTool } from "./scratchpad.ts";
|
|
30
30
|
export { _spillDeps, applyModelTruncationPolicy, type ModelTruncationOptions, SPILL_DIR, type SpillRequest, spillRelativePath, writeSpill, } from "./spill.ts";
|
|
31
|
-
export type { RegisteredSink, ToolAuditSink, ToolCallRecord } from "./tool-audit.ts";
|
|
31
|
+
export type { RegisteredSink, ToolAuditHeader, ToolAuditSink, ToolCallRecord } from "./tool-audit.ts";
|
|
32
32
|
export { createNoOpToolAuditSink, createToolAuditSink, flushOpenToolAuditSinks, registerToolAuditSink, unregisterToolAuditSink, } from "./tool-audit.ts";
|
|
33
33
|
export { cutBufferToByteCap, MODEL_MAX_BYTES, MODEL_MAX_LINE_CHARS, MODEL_MAX_LINES, READ_CEILING, type TruncateForModelOptions, type TruncationDirection, type TruncationResult, truncateForModel, truncationDirectionFor, } from "./truncate.ts";
|
|
34
34
|
export type { CodingToolName, PolicyVerdict, ToolGrant, ToolPolicy, ToolScope } from "./types.ts";
|
package/package.json
CHANGED