@agentclientprotocol/claude-agent-acp 0.106.0 → 0.106.1-preview.10
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 +1 -76
- package/dist/async-tasks.d.ts +1 -1
- package/dist/async-tasks.js +1 -1
- package/dist/context-window.d.ts +11 -9
- package/dist/context-window.d.ts.map +1 -1
- package/dist/context-window.js +12 -13
- package/dist/managed-policy.d.ts +9 -0
- package/dist/managed-policy.d.ts.map +1 -1
- package/dist/managed-policy.js +25 -0
- package/dist/native-subagents.d.ts +72 -9
- package/dist/native-subagents.d.ts.map +1 -1
- package/dist/native-subagents.js +130 -12
- package/dist/session-failure-extension.d.ts +15 -1
- package/dist/session-failure-extension.d.ts.map +1 -1
- package/dist/session-failure-extension.js +63 -0
- package/dist/session-fast-mode.d.ts +16 -10
- package/dist/session-fast-mode.d.ts.map +1 -1
- package/dist/session-fast-mode.js +36 -25
- package/dist/session-index/transcript-scan.d.ts +4 -2
- package/dist/session-index/transcript-scan.d.ts.map +1 -1
- package/dist/session-index/transcript-scan.js +67 -12
- package/dist/session-model.d.ts +22 -16
- package/dist/session-model.d.ts.map +1 -1
- package/dist/session-model.js +66 -38
- package/dist/session-usage.d.ts +8 -17
- package/dist/session-usage.d.ts.map +1 -1
- package/dist/session-usage.js +8 -21
- package/dist/settings.d.ts +2 -0
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js +12 -0
- package/dist/subagent-replay.d.ts +16 -1
- package/dist/subagent-replay.d.ts.map +1 -1
- package/dist/subagent-replay.js +28 -1
- package/dist/tool-calls/renderer.d.ts +26 -0
- package/dist/tool-calls/renderer.d.ts.map +1 -1
- package/dist/tool-calls/renderer.js +30 -0
- package/dist/v1/acp-agent.d.ts +31 -68
- package/dist/v1/acp-agent.d.ts.map +1 -1
- package/dist/v1/acp-agent.js +71 -271
- package/dist/v1/async-task-stop.d.ts +11 -0
- package/dist/v1/async-task-stop.d.ts.map +1 -0
- package/dist/v1/async-task-stop.js +18 -0
- package/dist/v1/session-fingerprint.d.ts +16 -0
- package/dist/v1/session-fingerprint.d.ts.map +1 -0
- package/dist/v1/session-fingerprint.js +129 -0
- package/dist/v1/steering.d.ts +48 -0
- package/dist/v1/steering.d.ts.map +1 -0
- package/dist/v1/steering.js +41 -0
- package/dist/v2/agent.js +10 -4
- package/dist/v2/outcome.d.ts +3 -2
- package/dist/v2/outcome.d.ts.map +1 -1
- package/dist/v2/outcome.js +8 -3
- package/dist/v2/reports.d.ts +2 -2
- package/dist/v2/reports.d.ts.map +1 -1
- package/dist/v2/reports.js +3 -6
- package/dist/v2/session.d.ts +11 -4
- package/dist/v2/session.d.ts.map +1 -1
- package/dist/v2/session.js +18 -4
- package/dist/v2/setup.js +1 -1
- package/dist/v2/stream.d.ts +2 -4
- package/dist/v2/stream.d.ts.map +1 -1
- package/dist/v2/stream.js +5 -9
- package/dist/v2/subagent-replay.js +2 -2
- package/dist/v2/tasks.d.ts +29 -11
- package/dist/v2/tasks.d.ts.map +1 -1
- package/dist/v2/tasks.js +69 -19
- package/dist/v2/tool-call.js +3 -0
- package/package.json +5 -5
package/dist/native-subagents.js
CHANGED
|
@@ -64,6 +64,11 @@ export class NativeSubagentRuntime {
|
|
|
64
64
|
* input, and the call that delegated the run.
|
|
65
65
|
*/
|
|
66
66
|
handbacks = new Map();
|
|
67
|
+
/**
|
|
68
|
+
* The RFD form: the agent that each TaskStop or SendMessage call names (see
|
|
69
|
+
* {@link targetAgentId}), until the call's final update.
|
|
70
|
+
*/
|
|
71
|
+
targetByToolCall = new Map();
|
|
67
72
|
generationByTaskId = new Map();
|
|
68
73
|
pending = new Map();
|
|
69
74
|
pendingCount = 0;
|
|
@@ -112,7 +117,11 @@ export class NativeSubagentRuntime {
|
|
|
112
117
|
if (!routed)
|
|
113
118
|
return routed;
|
|
114
119
|
this.rememberSendMessage(routed);
|
|
115
|
-
|
|
120
|
+
if (this.form !== "rfd")
|
|
121
|
+
return routed;
|
|
122
|
+
this.rememberTarget(routed);
|
|
123
|
+
const shown = this.routeRfdSendMessage(routed, forcedSessionId);
|
|
124
|
+
return shown && this.withTarget(shown);
|
|
116
125
|
}
|
|
117
126
|
/**
|
|
118
127
|
* The RFD form: the work state that the client holds for the announced child
|
|
@@ -587,7 +596,11 @@ export class NativeSubagentRuntime {
|
|
|
587
596
|
for (const pending of this.takePending(child.parentToolUseId))
|
|
588
597
|
await deliver(pending);
|
|
589
598
|
}
|
|
590
|
-
if (this.form === "rfd") {
|
|
599
|
+
if (this.form === "rfd" && end?.unobservable) {
|
|
600
|
+
// The child's `cancel` goes with it: a forgotten child cannot be stopped.
|
|
601
|
+
await this.reportState(child, { state: "unknown" }, { capabilities: null });
|
|
602
|
+
}
|
|
603
|
+
else if (this.form === "rfd") {
|
|
591
604
|
await this.reportState(child, rfdEndState(state, end));
|
|
592
605
|
child.missingError = state === "failed" && !end?.error && !end?.unexplained;
|
|
593
606
|
if (child.parentToolUseId)
|
|
@@ -616,14 +629,28 @@ export class NativeSubagentRuntime {
|
|
|
616
629
|
}
|
|
617
630
|
/**
|
|
618
631
|
* Ends every child that still runs, because the stream ended or the
|
|
619
|
-
* conversation was reset. AIR's draft reports `state` for each.
|
|
620
|
-
*
|
|
621
|
-
*
|
|
622
|
-
*
|
|
632
|
+
* conversation was reset. AIR's draft reports `state` for each.
|
|
633
|
+
*
|
|
634
|
+
* The RFD form, at the end of the stream: Claude Code's process ran the
|
|
635
|
+
* children and is gone, or the caller closes the query next, which
|
|
636
|
+
* terminates it, so their work ended. Its cause is unknown, so each is idle with no stop reason: a
|
|
637
|
+
* child that a cancel stopped already reported it from the SDK's events,
|
|
638
|
+
* and a background child that outlived the cancel was not cancelled.
|
|
639
|
+
*
|
|
640
|
+
* The RFD form, at a conversation reset (`mayStillRun`): Claude Code can
|
|
641
|
+
* keep the old conversation's subagents running, and the caller forgets
|
|
642
|
+
* them next (`clear`), so no later event of theirs is reported. Their work
|
|
643
|
+
* did not end as far as the adapter knows, so each is `unknown`, as the
|
|
644
|
+
* RFD requires when a child can no longer be observed, and loses its
|
|
645
|
+
* `cancel` capability. A child that is idle keeps its state.
|
|
623
646
|
*/
|
|
624
|
-
async finishAll(state, deliver) {
|
|
647
|
+
async finishAll(state, deliver, { mayStillRun = false } = {}) {
|
|
625
648
|
const errors = [];
|
|
626
|
-
const end = this.form
|
|
649
|
+
const end = this.form !== "rfd"
|
|
650
|
+
? undefined
|
|
651
|
+
: mayStillRun
|
|
652
|
+
? { unobservable: true }
|
|
653
|
+
: { unexplained: true };
|
|
627
654
|
try {
|
|
628
655
|
for (const taskId of [...this.children.keys()].reverse()) {
|
|
629
656
|
try {
|
|
@@ -966,13 +993,21 @@ export class NativeSubagentRuntime {
|
|
|
966
993
|
await this.publishCwd(child);
|
|
967
994
|
await this.publishConfiguration(child);
|
|
968
995
|
}
|
|
969
|
-
/**
|
|
970
|
-
|
|
996
|
+
/**
|
|
997
|
+
* The RFD form: publishes the work state of `child` on its parent, with
|
|
998
|
+
* `capabilities` when the child's change with it.
|
|
999
|
+
*/
|
|
1000
|
+
async reportState(child, state, capabilities) {
|
|
971
1001
|
child.workState = state.state;
|
|
972
1002
|
child.missingError = false;
|
|
973
1003
|
await this.publish({
|
|
974
1004
|
sessionId: child.parentSessionId,
|
|
975
|
-
update: {
|
|
1005
|
+
update: {
|
|
1006
|
+
sessionUpdate: "subagent_update",
|
|
1007
|
+
sessionId: child.sessionId,
|
|
1008
|
+
...capabilities,
|
|
1009
|
+
state,
|
|
1010
|
+
},
|
|
976
1011
|
});
|
|
977
1012
|
}
|
|
978
1013
|
/**
|
|
@@ -1147,6 +1182,43 @@ export class NativeSubagentRuntime {
|
|
|
1147
1182
|
return null;
|
|
1148
1183
|
return unexposedControlFallback(sendMessage.initial, notification, sendMessage.sender);
|
|
1149
1184
|
}
|
|
1185
|
+
/** The RFD form: remembers the agent that a TaskStop or SendMessage call names. */
|
|
1186
|
+
rememberTarget({ update }) {
|
|
1187
|
+
if (update.sessionUpdate !== "tool_call" && update.sessionUpdate !== "tool_call_update")
|
|
1188
|
+
return;
|
|
1189
|
+
const claudeMeta = update._meta?.claudeCode;
|
|
1190
|
+
const agentId = targetAgentId(claudeMeta?.toolName, update.rawInput);
|
|
1191
|
+
if (agentId !== undefined)
|
|
1192
|
+
this.targetByToolCall.set(update.toolCallId, agentId);
|
|
1193
|
+
}
|
|
1194
|
+
/**
|
|
1195
|
+
* The RFD form: `notification`, an update that the client is shown, with
|
|
1196
|
+
* the RFD's `session` reference when it is of a tool call that operates on
|
|
1197
|
+
* an announced child of another session (see {@link withSessionReference}):
|
|
1198
|
+
*
|
|
1199
|
+
* - a TaskStop or SendMessage call that names the child by its agent id;
|
|
1200
|
+
* - a SendMessage call that resumed the child, and stays shown because a
|
|
1201
|
+
* permission request showed it;
|
|
1202
|
+
* - an Agent/Task call that launched the child, and stays shown for the
|
|
1203
|
+
* same reason.
|
|
1204
|
+
*
|
|
1205
|
+
* The RFD requires the announcement before the reference, so a call whose
|
|
1206
|
+
* child is not announced yet gets none.
|
|
1207
|
+
*/
|
|
1208
|
+
withTarget(notification) {
|
|
1209
|
+
const { update } = notification;
|
|
1210
|
+
if (update.sessionUpdate !== "tool_call" && update.sessionUpdate !== "tool_call_update") {
|
|
1211
|
+
return notification;
|
|
1212
|
+
}
|
|
1213
|
+
const agentId = this.targetByToolCall.get(update.toolCallId);
|
|
1214
|
+
if (isFinalToolCallStatus(update.status))
|
|
1215
|
+
this.targetByToolCall.delete(update.toolCallId);
|
|
1216
|
+
const child = this.childByParentToolUse.get(update.toolCallId) ??
|
|
1217
|
+
(agentId !== undefined ? this.children.get(agentId) : undefined);
|
|
1218
|
+
if (!child?.announced || child.sessionId === notification.sessionId)
|
|
1219
|
+
return notification;
|
|
1220
|
+
return withSessionReference(notification, child.sessionId);
|
|
1221
|
+
}
|
|
1150
1222
|
/** Whether `update` is of an Agent/Task call, by its tool name or, in the
|
|
1151
1223
|
* RFD form, by the id of a call the client is not shown. */
|
|
1152
1224
|
isControlUpdate(update) {
|
|
@@ -1206,6 +1278,7 @@ export class NativeSubagentRuntime {
|
|
|
1206
1278
|
this.hiddenLaunches.clear();
|
|
1207
1279
|
this.hiddenSendMessages.clear();
|
|
1208
1280
|
this.handbacks.clear();
|
|
1281
|
+
this.targetByToolCall.clear();
|
|
1209
1282
|
this.generationByTaskId.clear();
|
|
1210
1283
|
this.pending.clear();
|
|
1211
1284
|
this.pendingCount = 0;
|
|
@@ -1486,7 +1559,7 @@ async function publishPrompt(child, prompt, toolUseId, sender, publish, { replac
|
|
|
1486
1559
|
* prompt goes from the parent to the child, a SendMessage call, whose message
|
|
1487
1560
|
* goes from its sender to a child, or a child's SubagentHandback call, whose
|
|
1488
1561
|
* report goes from the child to the parent. Both views use the
|
|
1489
|
-
* call's tool use id, and each names the other with the
|
|
1562
|
+
* call's tool use id, and each names the other with the RFD's
|
|
1490
1563
|
* `recipientMessageId` and `senderMessageId`.
|
|
1491
1564
|
*/
|
|
1492
1565
|
export function linkedSessionMessages(toolUseId, senderSessionId, recipientSessionId, text) {
|
|
@@ -1508,6 +1581,48 @@ export function linkedSessionMessages(toolUseId, senderSessionId, recipientSessi
|
|
|
1508
1581
|
},
|
|
1509
1582
|
];
|
|
1510
1583
|
}
|
|
1584
|
+
/**
|
|
1585
|
+
* The RFD form: the agent that a tool call names as the one it operates on:
|
|
1586
|
+
* the `task_id` of a TaskStop call, or the `to` of a SendMessage call. It is
|
|
1587
|
+
* an agent only if it is the id of one: an agent's id is its child session's
|
|
1588
|
+
* id. Both tools also take a name, which is not resolved here: Claude Code
|
|
1589
|
+
* resolves it, and the adapter cannot tell which agent it picked. `undefined`
|
|
1590
|
+
* for any other call.
|
|
1591
|
+
*/
|
|
1592
|
+
export function targetAgentId(toolName, rawInput) {
|
|
1593
|
+
if (typeof rawInput !== "object" || rawInput === null)
|
|
1594
|
+
return undefined;
|
|
1595
|
+
const input = rawInput;
|
|
1596
|
+
if (toolName === "TaskStop")
|
|
1597
|
+
return nonBlankString(input.task_id);
|
|
1598
|
+
if (toolName === "SendMessage")
|
|
1599
|
+
return nonBlankString(input.to);
|
|
1600
|
+
return undefined;
|
|
1601
|
+
}
|
|
1602
|
+
/**
|
|
1603
|
+
* The RFD form: `notification`, a tool call's report, with a `session`
|
|
1604
|
+
* reference to `sessionId` after its content: `{ "type": "session",
|
|
1605
|
+
* "sessionId": "..." }`, which links the call to the session it operates on.
|
|
1606
|
+
* A `tool_call_update` replaces the content that the client holds, so the
|
|
1607
|
+
* reference goes on every report that carries content, and a
|
|
1608
|
+
* `tool_call_update` without content is returned as it is.
|
|
1609
|
+
*/
|
|
1610
|
+
export function withSessionReference(notification, sessionId) {
|
|
1611
|
+
const { update } = notification;
|
|
1612
|
+
if (update.sessionUpdate !== "tool_call" && update.sessionUpdate !== "tool_call_update") {
|
|
1613
|
+
return notification;
|
|
1614
|
+
}
|
|
1615
|
+
if (update.sessionUpdate === "tool_call_update" && update.content == null)
|
|
1616
|
+
return notification;
|
|
1617
|
+
const content = update.content ?? [];
|
|
1618
|
+
if (content.some((item) => item.type === "session" && item.sessionId === sessionId)) {
|
|
1619
|
+
return notification;
|
|
1620
|
+
}
|
|
1621
|
+
return {
|
|
1622
|
+
...notification,
|
|
1623
|
+
update: { ...update, content: [...content, { type: "session", sessionId }] },
|
|
1624
|
+
};
|
|
1625
|
+
}
|
|
1511
1626
|
/**
|
|
1512
1627
|
* The tool with which a child hands its report to its parent, when Claude
|
|
1513
1628
|
* Code runs in hand-back mode. The Agent/Task result then only says that the
|
|
@@ -1576,6 +1691,9 @@ function isWorking(child) {
|
|
|
1576
1691
|
* A task that a worker restart orphaned, or that was still running when the
|
|
1577
1692
|
* stream ended, is idle with no stop reason: its work ended, but the adapter
|
|
1578
1693
|
* did not see a cancellation or a failure, which the RFD forbids claiming.
|
|
1694
|
+
*
|
|
1695
|
+
* A child that the adapter can no longer observe and that may still run is
|
|
1696
|
+
* not idle but `unknown` (see `NativeSubagentRuntime.finishAll`).
|
|
1579
1697
|
*/
|
|
1580
1698
|
export function rfdEndState(state, end) {
|
|
1581
1699
|
if (end?.unexplained || end?.reason === "worker_restart")
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ClientCapabilities, SessionNotification } from "@agentclientprotocol/sdk/unstable";
|
|
2
|
-
import { getSessionMessages, type SDKAssistantMessageError } from "@anthropic-ai/claude-agent-sdk";
|
|
2
|
+
import { getSessionMessages, type SDKAPIRetryMessage, type SDKAssistantMessageError } from "@anthropic-ai/claude-agent-sdk";
|
|
3
3
|
export declare function airSessionFailureCapabilityMeta(...additionalCapabilities: string[]): Record<string, unknown>;
|
|
4
4
|
export type ClaudeFailureKind = "access_denied" | "advisory" | "auth_required" | "bad_request" | "budget_exhausted" | "context_exhausted" | "internal_error" | "overloaded" | "provider_error" | "quota_exhausted" | "rate_limited" | "transport_lost" | "worker_shutdown";
|
|
5
5
|
type AirSessionFailureCategory = "connection" | "access" | "limit" | "request" | "service" | "unknown";
|
|
@@ -92,6 +92,20 @@ export declare class SessionFailureController {
|
|
|
92
92
|
publish(kind: ClaudeFailureKind, failureOptions?: SessionFailureOptions): Promise<void>;
|
|
93
93
|
restore(id: string, kind: ClaudeFailureKind, title: string, active?: boolean): Promise<boolean>;
|
|
94
94
|
}
|
|
95
|
+
/** The `api_retry` message fields the warning reads. `error` is optional
|
|
96
|
+
* because an older CLI can omit it; the warning then treats it as `unknown`. */
|
|
97
|
+
type ApiRetryWarningInput = Pick<SDKAPIRetryMessage, "attempt" | "max_retries" | "error_status" | "retry_delay_ms" | "no_response"> & {
|
|
98
|
+
error?: SDKAssistantMessageError;
|
|
99
|
+
};
|
|
100
|
+
/** The title and the `details` of an `api_retry` warning. The title says the
|
|
101
|
+
* attempt and, for a `no_response` retry, how long the CLI waited and will
|
|
102
|
+
* wait. The details say the cause and the wait before the next attempt, e.g.
|
|
103
|
+
* "HTTP 529 (overloaded). Next attempt in 8s." The details do not repeat the
|
|
104
|
+
* `no_response` wait. */
|
|
105
|
+
export declare function apiRetryWarning(message: ApiRetryWarningInput): {
|
|
106
|
+
title: string;
|
|
107
|
+
details: string;
|
|
108
|
+
};
|
|
95
109
|
export declare function providerFailureCategory(errorKind?: SDKAssistantMessageError, isUsageLimit?: boolean): ClaudeFailureKind;
|
|
96
110
|
export {};
|
|
97
111
|
//# sourceMappingURL=session-failure-extension.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session-failure-extension.d.ts","sourceRoot":"","sources":["../src/session-failure-extension.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,mCAAmC,CAAC;AACjG,OAAO,EACL,kBAAkB,EAClB,KAAK,wBAAwB,EAE9B,MAAM,gCAAgC,CAAC;AASxC,wBAAgB,+BAA+B,CAAC,GAAG,sBAAsB,EAAE,MAAM,EAAE,2BAElF;AAED,MAAM,MAAM,iBAAiB,GACzB,eAAe,GACf,UAAU,GACV,eAAe,GACf,aAAa,GACb,kBAAkB,GAClB,mBAAmB,GACnB,gBAAgB,GAChB,YAAY,GACZ,gBAAgB,GAChB,iBAAiB,GACjB,cAAc,GACd,gBAAgB,GAChB,iBAAiB,CAAC;AAEtB,KAAK,yBAAyB,GAC5B,YAAY,GAAG,QAAQ,GAAG,OAAO,GAAG,SAAS,GAAG,SAAS,GAAG,SAAS,CAAC;AAExE,KAAK,yBAAyB,GAAG,SAAS,GAAG,OAAO,CAAC;AACrD,KAAK,uBAAuB,GAAG,OAAO,GAAG,OAAO,GAAG,aAAa,CAAC;AAEjE,KAAK,4BAA4B,GAC/B,OAAO,GAAG,cAAc,GAAG,oBAAoB,GAAG,aAAa,GAAG,gBAAgB,CAAC;AAErF,MAAM,MAAM,uBAAuB,GAAG;IACpC,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,iBAAiB,CAAC;IACxB,QAAQ,EAAE,yBAAyB,CAAC;IACpC,MAAM,CAAC,EAA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mDzC,OAAO,CACX,IAAI,EAAE,iBAAiB,EACvB,cAAc,GAAE,qBAA0B,GACzC,OAAO,CAAC,IAAI,CAAC;IAMV,OAAO,CACX,EAAE,EAAE,MAAM,EACV,IAAI,EAAE,iBAAiB,EACvB,KAAK,EAAE,MAAM,EACb,MAAM,UAAO,GACZ,OAAO,CAAC,OAAO,CAAC;CAsBpB;AAED,wBAAgB,uBAAuB,CACrC,SAAS,CAAC,EAAE,wBAAwB,EACpC,YAAY,UAAQ,GACnB,iBAAiB,CAkCnB"}
|
|
1
|
+
{"version":3,"file":"session-failure-extension.d.ts","sourceRoot":"","sources":["../src/session-failure-extension.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,mCAAmC,CAAC;AACjG,OAAO,EACL,kBAAkB,EAClB,KAAK,kBAAkB,EACvB,KAAK,wBAAwB,EAE9B,MAAM,gCAAgC,CAAC;AASxC,wBAAgB,+BAA+B,CAAC,GAAG,sBAAsB,EAAE,MAAM,EAAE,2BAElF;AAED,MAAM,MAAM,iBAAiB,GACzB,eAAe,GACf,UAAU,GACV,eAAe,GACf,aAAa,GACb,kBAAkB,GAClB,mBAAmB,GACnB,gBAAgB,GAChB,YAAY,GACZ,gBAAgB,GAChB,iBAAiB,GACjB,cAAc,GACd,gBAAgB,GAChB,iBAAiB,CAAC;AAEtB,KAAK,yBAAyB,GAC5B,YAAY,GAAG,QAAQ,GAAG,OAAO,GAAG,SAAS,GAAG,SAAS,GAAG,SAAS,CAAC;AAExE,KAAK,yBAAyB,GAAG,SAAS,GAAG,OAAO,CAAC;AACrD,KAAK,uBAAuB,GAAG,OAAO,GAAG,OAAO,GAAG,aAAa,CAAC;AAEjE,KAAK,4BAA4B,GAC/B,OAAO,GAAG,cAAc,GAAG,oBAAoB,GAAG,aAAa,GAAG,gBAAgB,CAAC;AAErF,MAAM,MAAM,uBAAuB,GAAG;IACpC,EAAE,EAAE,MAAM,CAAC;IACX,QA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IAUb,OAAO,CACX,IAAI,EAAE,iBAAiB,EACvB,cAAc,GAAE,qBAA0B,GACzC,OAAO,CAAC,uBAAuB,GAAG,SAAS,CAAC;IAmDzC,OAAO,CACX,IAAI,EAAE,iBAAiB,EACvB,cAAc,GAAE,qBAA0B,GACzC,OAAO,CAAC,IAAI,CAAC;IAMV,OAAO,CACX,EAAE,EAAE,MAAM,EACV,IAAI,EAAE,iBAAiB,EACvB,KAAK,EAAE,MAAM,EACb,MAAM,UAAO,GACZ,OAAO,CAAC,OAAO,CAAC;CAsBpB;AAkCD;iFACiF;AACjF,KAAK,oBAAoB,GAAG,IAAI,CAC9B,kBAAkB,EAClB,SAAS,GAAG,aAAa,GAAG,cAAc,GAAG,gBAAgB,GAAG,aAAa,CAC9E,GAAG;IAAE,KAAK,CAAC,EAAE,wBAAwB,CAAA;CAAE,CAAC;AAiBzC;;;;0BAI0B;AAC1B,wBAAgB,eAAe,CAAC,OAAO,EAAE,oBAAoB,GAAG;IAC9D,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;CACjB,CAcA;AAED,wBAAgB,uBAAuB,CACrC,SAAS,CAAC,EAAE,wBAAwB,EACpC,YAAY,UAAQ,GACnB,iBAAiB,CAkCnB"}
|
|
@@ -326,6 +326,69 @@ export class SessionFailureController {
|
|
|
326
326
|
return true;
|
|
327
327
|
}
|
|
328
328
|
}
|
|
329
|
+
/** Formats a wait in whole seconds, at least 1s: `8000` → `"8s"`. */
|
|
330
|
+
function retrySeconds(ms) {
|
|
331
|
+
return `${Math.max(1, Math.round(ms / 1000))}s`;
|
|
332
|
+
}
|
|
333
|
+
/** The wait before the next attempt: `0` → `"now"`, `8000` → `"in 8s"`, and
|
|
334
|
+
* from 120 s whole minutes rounded up: `1_800_000` → `"in 30m"`. The CLI sends
|
|
335
|
+
* `0` for a `no_response` retry and minutes for a background rate-limit wait. */
|
|
336
|
+
function nextAttemptDelay(ms) {
|
|
337
|
+
const seconds = Math.round(ms / 1000);
|
|
338
|
+
if (seconds <= 0)
|
|
339
|
+
return "now";
|
|
340
|
+
if (seconds < 120)
|
|
341
|
+
return `in ${seconds}s`;
|
|
342
|
+
return `in ${Math.ceil(ms / 60_000)}m`;
|
|
343
|
+
}
|
|
344
|
+
/** Plain-English names of the SDK error kinds. `unknown` has none: it adds
|
|
345
|
+
* nothing to the HTTP status or the connection error. */
|
|
346
|
+
const RETRY_ERROR_KIND_LABELS = {
|
|
347
|
+
authentication_failed: "authentication failed",
|
|
348
|
+
oauth_org_not_allowed: "organization not allowed",
|
|
349
|
+
account_on_hold: "account on hold",
|
|
350
|
+
verification_required: "verification required",
|
|
351
|
+
billing_error: "billing error",
|
|
352
|
+
rate_limit: "rate limited",
|
|
353
|
+
overloaded: "overloaded",
|
|
354
|
+
invalid_request: "invalid request",
|
|
355
|
+
model_not_found: "model not found",
|
|
356
|
+
server_error: "server error",
|
|
357
|
+
max_output_tokens: "output token limit",
|
|
358
|
+
cloud_credential_error: "cloud credential error",
|
|
359
|
+
};
|
|
360
|
+
/** The cause of a retry. A null `error_status` with a kind is not always a
|
|
361
|
+
* lost connection: the CLI maps an SSE `overloaded_error` event after HTTP 200
|
|
362
|
+
* to `overloaded` with no status. */
|
|
363
|
+
function apiRetryCause(message) {
|
|
364
|
+
const kind = message.error ?? "unknown";
|
|
365
|
+
const label = kind === "unknown"
|
|
366
|
+
? undefined
|
|
367
|
+
: (RETRY_ERROR_KIND_LABELS[kind] ?? String(kind).replaceAll("_", " "));
|
|
368
|
+
if (message.error_status !== null) {
|
|
369
|
+
return `HTTP ${message.error_status}${label ? ` (${label})` : ""}.`;
|
|
370
|
+
}
|
|
371
|
+
return label ? `No HTTP status (${label}).` : "Connection error: no HTTP response.";
|
|
372
|
+
}
|
|
373
|
+
/** The title and the `details` of an `api_retry` warning. The title says the
|
|
374
|
+
* attempt and, for a `no_response` retry, how long the CLI waited and will
|
|
375
|
+
* wait. The details say the cause and the wait before the next attempt, e.g.
|
|
376
|
+
* "HTTP 529 (overloaded). Next attempt in 8s." The details do not repeat the
|
|
377
|
+
* `no_response` wait. */
|
|
378
|
+
export function apiRetryWarning(message) {
|
|
379
|
+
// `no_response` (SDK 0.3.261+): the API sent no response headers
|
|
380
|
+
// within the first-byte window, so this retry waits longer for
|
|
381
|
+
// them. Say so — "attempt 1 of 1" alone reads like a final
|
|
382
|
+
// failure, and the wait is what the user is about to sit through.
|
|
383
|
+
const noResponse = message.no_response
|
|
384
|
+
? ` No response after ${retrySeconds(message.no_response.waited_ms)}; waiting up to ${retrySeconds(message.no_response.retry_wait_ms)}.`
|
|
385
|
+
: "";
|
|
386
|
+
const title = message.error_status === null
|
|
387
|
+
? `Reconnecting to Claude, attempt ${message.attempt} of ${message.max_retries}.${noResponse}`
|
|
388
|
+
: `Retrying Claude, attempt ${message.attempt} of ${message.max_retries}.${noResponse}`;
|
|
389
|
+
const delay = nextAttemptDelay(message.retry_delay_ms);
|
|
390
|
+
return { title, details: `${apiRetryCause(message)} Next attempt ${delay}.` };
|
|
391
|
+
}
|
|
329
392
|
export function providerFailureCategory(errorKind, isUsageLimit = false) {
|
|
330
393
|
if (isUsageLimit)
|
|
331
394
|
return "quota_exhausted";
|
|
@@ -10,11 +10,15 @@ export declare const FAST_MODE_OFF = "off";
|
|
|
10
10
|
* docs) keeps the toggle on so it reflects the user's intent — only an
|
|
11
11
|
* explicit `off` clears it. */
|
|
12
12
|
export declare function fastModeStateEnabled(state: FastModeState): boolean;
|
|
13
|
+
/** The user-facing explanation of a `fast_mode_disabled_reason`: `undefined`
|
|
14
|
+
* for no reason, `sdk_opt_in_required` or `pending`; the table text when there
|
|
15
|
+
* is one; else a generic text naming the code (a reason a newer SDK added). */
|
|
16
|
+
export declare function explainFastModeDisabledReason(reason: FastModeDisabledReason | undefined): string | undefined;
|
|
13
17
|
/** Normalize an SDK-reported `fast_mode_disabled_reason` to the one we retain:
|
|
14
|
-
* a reason
|
|
15
|
-
*
|
|
16
|
-
* exactly what the user can see, so
|
|
17
|
-
* `sdk_opt_in_required` never churn the config option. */
|
|
18
|
+
* a reason {@link explainFastModeDisabledReason} explains (including codes a
|
|
19
|
+
* newer SDK adds), else `undefined`. State comparisons (see
|
|
20
|
+
* `fastModeStateChange`) then track exactly what the user can see, so
|
|
21
|
+
* `sdk_opt_in_required` and `pending` never churn the config option. */
|
|
18
22
|
export declare function normalizeFastModeDisabledReason(reason: FastModeDisabledReason | undefined): FastModeDisabledReason | undefined;
|
|
19
23
|
/** Build the Fast mode config option. When the Client supports boolean config
|
|
20
24
|
* options we expose a native `type: "boolean"` toggle; otherwise we degrade to
|
|
@@ -53,15 +57,17 @@ export type FastModeOptionState = {
|
|
|
53
57
|
* off), or the same state with the same explainable reason.
|
|
54
58
|
*
|
|
55
59
|
* `reason` is the SDK's `fast_mode_disabled_reason`, reported alongside the
|
|
56
|
-
* state.
|
|
57
|
-
* {@link normalizeFastModeDisabledReason}
|
|
58
|
-
* `sdk_opt_in_required`
|
|
59
|
-
* option, while a real blocker updates the description even when the
|
|
60
|
+
* state. Every reason except `sdk_opt_in_required` and `pending` is retained
|
|
61
|
+
* (see {@link normalizeFastModeDisabledReason}; unknown future codes get the
|
|
62
|
+
* generic text), so `sdk_opt_in_required` on every turn's result can't churn
|
|
63
|
+
* the option, while a real blocker updates the description even when the
|
|
60
64
|
* toggle's own value is unchanged.
|
|
61
65
|
*
|
|
62
66
|
* `notice` is set when the user had Fast mode on and the SDK turned it off
|
|
63
|
-
*
|
|
64
|
-
*
|
|
67
|
+
* with a retained reason: the description carries the same explanation, but a
|
|
68
|
+
* toggle silently snapping back is worth saying out loud once. Off with no
|
|
69
|
+
* reason, `sdk_opt_in_required` or `pending` stays quiet: a `result` can carry
|
|
70
|
+
* the turn-start snapshot, so a notice there would falsely say "turned off". */
|
|
65
71
|
export declare function fastModeStateChange(current: {
|
|
66
72
|
enabled: boolean;
|
|
67
73
|
disabledReason?: FastModeDisabledReason;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session-fast-mode.d.ts","sourceRoot":"","sources":["../src/session-fast-mode.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EACV,mBAAmB,EACnB,6BAA6B,EAC9B,MAAM,mCAAmC,CAAC;AAC3C,OAAO,KAAK,EAAE,sBAAsB,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAC;AAG5F,eAAO,MAAM,mBAAmB,SAAS,CAAC;AAE1C;+DAC+D;AAC/D,eAAO,MAAM,YAAY,OAAO,CAAC;AACjC,eAAO,MAAM,aAAa,QAAQ,CAAC;AAGnC;;;gCAGgC;AAChC,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,aAAa,GAAG,OAAO,CAElE;
|
|
1
|
+
{"version":3,"file":"session-fast-mode.d.ts","sourceRoot":"","sources":["../src/session-fast-mode.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EACV,mBAAmB,EACnB,6BAA6B,EAC9B,MAAM,mCAAmC,CAAC;AAC3C,OAAO,KAAK,EAAE,sBAAsB,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAC;AAG5F,eAAO,MAAM,mBAAmB,SAAS,CAAC;AAE1C;+DAC+D;AAC/D,eAAO,MAAM,YAAY,OAAO,CAAC;AACjC,eAAO,MAAM,aAAa,QAAQ,CAAC;AAGnC;;;gCAGgC;AAChC,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,aAAa,GAAG,OAAO,CAElE;AAyBD;;gFAEgF;AAChF,wBAAgB,6BAA6B,CAC3C,MAAM,EAAE,sBAAsB,GAAG,SAAS,GACzC,MAAM,GAAG,SAAS,CAGpB;AAED;;;;yEAIyE;AACzE,wBAAgB,+BAA+B,CAC7C,MAAM,EAAE,sBAAsB,GAAG,SAAS,GACzC,sBAAsB,GAAG,SAAS,CAEpC;AAED;;;;;;;;;+CAS+C;AAC/C,wBAAgB,0BAA0B,CACxC,OAAO,EAAE,OAAO,EAChB,gBAAgB,EAAE,OAAO,EACzB,cAAc,CAAC,EAAE,sBAAsB,GACtC,mBAAmB,CAsBrB;AAED;;0CAE0C;AAC1C,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,6BAA6B,GAAG,OAAO,CAerF;AAED;6EAC6E;AAC7E,MAAM,MAAM,mBAAmB,GAAG;IAChC,SAAS,EAAE,OAAO,CAAC;IACnB,OAAO,EAAE,OAAO,CAAC;IACjB,4DAA4D;IAC5D,gBAAgB,EAAE,OAAO,CAAC;IAC1B;kDAC8C;IAC9C,cAAc,CAAC,EAAE,sBAAsB,CAAC;CACzC,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;iFAqBiF;AACjF,wBAAgB,mBAAmB,CACjC,OAAO,EAAE;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,cAAc,CAAC,EAAE,sBAAsB,CAAA;CAAE,EACtE,KAAK,EAAE,aAAa,GAAG,SAAS,EAChC,MAAM,EAAE,sBAAsB,GAAG,SAAS,GAExC;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,cAAc,CAAC,EAAE,sBAAsB,CAAC;IAAC,MAAM,CAAC,EAAE,iBAAiB,CAAA;CAAE,GACzF,SAAS,CAuBZ;AAED;6CAC6C;AAC7C,MAAM,MAAM,iBAAiB,GAAG;IAC9B,MAAM,EAAE;QAAE,QAAQ,EAAE,SAAS,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,MAAM,CAAA;KAAE,CAAC;IACpE,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC"}
|
|
@@ -19,16 +19,9 @@ const FAST_MODE_DESCRIPTION = "Faster responses on supported models";
|
|
|
19
19
|
export function fastModeStateEnabled(state) {
|
|
20
20
|
return state !== "off";
|
|
21
21
|
}
|
|
22
|
-
/** User-facing explanations for the SDK's `fast_mode_disabled_reason` values
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
* - `sdk_opt_in_required`: every SDK session starts here (the toggle IS the
|
|
26
|
-
* opt-in), so it describes the default, not a problem.
|
|
27
|
-
* - `preference`: the user turned Fast mode off themselves.
|
|
28
|
-
* - `pending`: eligibility is still resolving; the next report supersedes it.
|
|
29
|
-
* - `unknown`: nothing meaningful to say.
|
|
30
|
-
* Unknown future reasons fall through the same way (open set — the SDK's docs
|
|
31
|
-
* say to ignore values you don't handle). */
|
|
22
|
+
/** User-facing explanations for the SDK's `fast_mode_disabled_reason` values.
|
|
23
|
+
* Every reason is explained except the two in {@link FAST_MODE_UNEXPLAINED_REASONS};
|
|
24
|
+
* a code missing here gets the generic text from {@link explainFastModeDisabledReason}. */
|
|
32
25
|
const FAST_MODE_UNAVAILABLE_EXPLANATIONS = {
|
|
33
26
|
free: "not available on the free plan",
|
|
34
27
|
extra_usage_disabled: "requires extra usage to be enabled for this account",
|
|
@@ -36,14 +29,32 @@ const FAST_MODE_UNAVAILABLE_EXPLANATIONS = {
|
|
|
36
29
|
not_first_party: "not available on this API provider",
|
|
37
30
|
disabled_by_env: "disabled by environment configuration",
|
|
38
31
|
network_error: "eligibility could not be verified (network error)",
|
|
32
|
+
preference: "not enabled for your organization or API gateway",
|
|
33
|
+
unknown: "currently unavailable",
|
|
39
34
|
};
|
|
35
|
+
/** Reasons that are never explained:
|
|
36
|
+
* - `sdk_opt_in_required`: every SDK session starts here (the toggle IS the
|
|
37
|
+
* opt-in), so it describes the default, not a problem.
|
|
38
|
+
* - `pending`: eligibility is still resolving; the next report supersedes it. */
|
|
39
|
+
const FAST_MODE_UNEXPLAINED_REASONS = new Set([
|
|
40
|
+
"sdk_opt_in_required",
|
|
41
|
+
"pending",
|
|
42
|
+
]);
|
|
43
|
+
/** The user-facing explanation of a `fast_mode_disabled_reason`: `undefined`
|
|
44
|
+
* for no reason, `sdk_opt_in_required` or `pending`; the table text when there
|
|
45
|
+
* is one; else a generic text naming the code (a reason a newer SDK added). */
|
|
46
|
+
export function explainFastModeDisabledReason(reason) {
|
|
47
|
+
if (reason === undefined || FAST_MODE_UNEXPLAINED_REASONS.has(reason))
|
|
48
|
+
return undefined;
|
|
49
|
+
return FAST_MODE_UNAVAILABLE_EXPLANATIONS[reason] ?? `not available (${reason})`;
|
|
50
|
+
}
|
|
40
51
|
/** Normalize an SDK-reported `fast_mode_disabled_reason` to the one we retain:
|
|
41
|
-
* a reason
|
|
42
|
-
*
|
|
43
|
-
* exactly what the user can see, so
|
|
44
|
-
* `sdk_opt_in_required` never churn the config option. */
|
|
52
|
+
* a reason {@link explainFastModeDisabledReason} explains (including codes a
|
|
53
|
+
* newer SDK adds), else `undefined`. State comparisons (see
|
|
54
|
+
* `fastModeStateChange`) then track exactly what the user can see, so
|
|
55
|
+
* `sdk_opt_in_required` and `pending` never churn the config option. */
|
|
45
56
|
export function normalizeFastModeDisabledReason(reason) {
|
|
46
|
-
return reason
|
|
57
|
+
return explainFastModeDisabledReason(reason) !== undefined ? reason : undefined;
|
|
47
58
|
}
|
|
48
59
|
/** Build the Fast mode config option. When the Client supports boolean config
|
|
49
60
|
* options we expose a native `type: "boolean"` toggle; otherwise we degrade to
|
|
@@ -56,9 +67,7 @@ export function normalizeFastModeDisabledReason(reason) {
|
|
|
56
67
|
* stay on. Ignored while enabled: a reason reported alongside an `on`/`cooldown`
|
|
57
68
|
* state isn't blocking anything right now. */
|
|
58
69
|
export function createFastModeConfigOption(enabled, useBooleanOption, disabledReason) {
|
|
59
|
-
const explanation = enabled
|
|
60
|
-
? undefined
|
|
61
|
-
: disabledReason && FAST_MODE_UNAVAILABLE_EXPLANATIONS[disabledReason];
|
|
70
|
+
const explanation = enabled ? undefined : explainFastModeDisabledReason(disabledReason);
|
|
62
71
|
const base = {
|
|
63
72
|
id: FAST_MODE_CONFIG_ID,
|
|
64
73
|
name: "Fast mode",
|
|
@@ -105,15 +114,17 @@ export function resolveFastModeEnabled(params) {
|
|
|
105
114
|
* off), or the same state with the same explainable reason.
|
|
106
115
|
*
|
|
107
116
|
* `reason` is the SDK's `fast_mode_disabled_reason`, reported alongside the
|
|
108
|
-
* state.
|
|
109
|
-
* {@link normalizeFastModeDisabledReason}
|
|
110
|
-
* `sdk_opt_in_required`
|
|
111
|
-
* option, while a real blocker updates the description even when the
|
|
117
|
+
* state. Every reason except `sdk_opt_in_required` and `pending` is retained
|
|
118
|
+
* (see {@link normalizeFastModeDisabledReason}; unknown future codes get the
|
|
119
|
+
* generic text), so `sdk_opt_in_required` on every turn's result can't churn
|
|
120
|
+
* the option, while a real blocker updates the description even when the
|
|
112
121
|
* toggle's own value is unchanged.
|
|
113
122
|
*
|
|
114
123
|
* `notice` is set when the user had Fast mode on and the SDK turned it off
|
|
115
|
-
*
|
|
116
|
-
*
|
|
124
|
+
* with a retained reason: the description carries the same explanation, but a
|
|
125
|
+
* toggle silently snapping back is worth saying out loud once. Off with no
|
|
126
|
+
* reason, `sdk_opt_in_required` or `pending` stays quiet: a `result` can carry
|
|
127
|
+
* the turn-start snapshot, so a notice there would falsely say "turned off". */
|
|
117
128
|
export function fastModeStateChange(current, state, reason) {
|
|
118
129
|
if (state === undefined || state === "cooldown")
|
|
119
130
|
return undefined;
|
|
@@ -123,7 +134,7 @@ export function fastModeStateChange(current, state, reason) {
|
|
|
123
134
|
const disabledReason = enabled ? undefined : normalizeFastModeDisabledReason(reason);
|
|
124
135
|
if (enabled === current.enabled && disabledReason === current.disabledReason)
|
|
125
136
|
return undefined;
|
|
126
|
-
const explanation = disabledReason
|
|
137
|
+
const explanation = explainFastModeDisabledReason(disabledReason);
|
|
127
138
|
if (!current.enabled || enabled || explanation === undefined) {
|
|
128
139
|
return { enabled, disabledReason };
|
|
129
140
|
}
|
|
@@ -133,7 +133,8 @@ export declare function scanTranscript({ head, tail }: HeadTail, options?: {
|
|
|
133
133
|
/** Whether the first record of the transcript is a sidechain one, which the
|
|
134
134
|
* SDK never lists. */
|
|
135
135
|
export declare function isSidechainTranscript(head: string): boolean;
|
|
136
|
-
/** The last `
|
|
136
|
+
/** The title of the last `custom-title` record of the tail, as the SDK reads
|
|
137
|
+
* it (see {@link lastRecordField}). */
|
|
137
138
|
export declare function tailCustomTitle({ tail, sdkTail }: HeadTail): string | undefined;
|
|
138
139
|
/** The last agent name of a transcript, as AIR's native Claude provider
|
|
139
140
|
* reads it: the top-level `agentName` of any record, from the tail, else
|
|
@@ -155,7 +156,8 @@ export type SdkTitles = {
|
|
|
155
156
|
*/
|
|
156
157
|
export declare function sdkTitles({ head, tail: wholeLines, sdkTail }: HeadTail, sidecarTitle?: string): SdkTitles;
|
|
157
158
|
/** The title of a transcript without a custom title, in the SDK's order: AI
|
|
158
|
-
* title, last prompt, summary, first prompt.
|
|
159
|
+
* title, last prompt, summary, first prompt. The last prompt and the summary
|
|
160
|
+
* are the field of a record of any type. */
|
|
159
161
|
export declare function generatedTitle({ head, tail }: HeadTail): string | undefined;
|
|
160
162
|
/** The time of the last `"timestamp"` in the last 64 KB of a file, cut
|
|
161
163
|
* line included, epoch ms: a record longer than that still ends with it. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transcript-scan.d.ts","sourceRoot":"","sources":["../../src/session-index/transcript-scan.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACvC,OAAO,EAAqB,KAAK,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAchF,MAAM,MAAM,SAAS,GAAG,UAAU,GAAG,YAAY,CAAC;AAElD,MAAM,MAAM,eAAe,GAAG;IAC5B,wEAAwE;IACxE,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB;0BACsB;IACtB,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,gDAAgD;IAChD,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB;8EAC0E;IAC1E,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,mCAAmC;IACnC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,kCAAkC;IAClC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;qDACiD;IACjD,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB;kEAC8D;IAC9D,cAAc,CAAC,EAAE,OAAO,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AAM,MAAM,SAAS,GAAG;IACtB,uEAAuE;IACvE,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,wEAAwE;IACxE,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF;;;;;;GAMG;AACH,wBAAgB,SAAS,CACvB,EAAE,IAAI,EAAE,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,EAAE,QAAQ,EAC7C,YAAY,CAAC,EAAE,MAAM,GACpB,SAAS,CASX;AAED;;6CAE6C;AAC7C,wBAAgB,cAAc,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,QAAQ,GAAG,MAAM,GAAG,SAAS,CAQ3E;AAED;6EAC6E;AAC7E,wBAAsB,aAAa,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAgB/F;AAID;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAsBrE;AAOD;0EAC0E;AAC1E,wBAAsB,UAAU,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CA2BnE"}
|
|
@@ -469,7 +469,60 @@ function stringFields(text, key) {
|
|
|
469
469
|
}
|
|
470
470
|
return values;
|
|
471
471
|
}
|
|
472
|
-
|
|
472
|
+
/** The string `field` of the JSON record `line`, which is of `type` when one
|
|
473
|
+
* is given. `null` when the line is no JSON. */
|
|
474
|
+
function recordField(line, field, type) {
|
|
475
|
+
let record;
|
|
476
|
+
try {
|
|
477
|
+
record = JSON.parse(line);
|
|
478
|
+
}
|
|
479
|
+
catch {
|
|
480
|
+
return null;
|
|
481
|
+
}
|
|
482
|
+
if (typeof record !== "object" || record === null)
|
|
483
|
+
return undefined;
|
|
484
|
+
if (type !== undefined && record.type !== type)
|
|
485
|
+
return undefined;
|
|
486
|
+
const value = record[field];
|
|
487
|
+
return typeof value === "string" ? value : undefined;
|
|
488
|
+
}
|
|
489
|
+
/**
|
|
490
|
+
* The top-level string `field` of the last record of `text` that has one,
|
|
491
|
+
* as the SDK reads a session's metadata since 0.3.323: it parses each line
|
|
492
|
+
* that names the field, from the last one back. A `"customTitle":"…"` inside
|
|
493
|
+
* a message, such as a tool result that shows a transcript, is no title.
|
|
494
|
+
*
|
|
495
|
+
* With `type`, only a record of that `type` counts, and a line that names
|
|
496
|
+
* the type but is no JSON is read from its last `{"type":"<type>"` that does
|
|
497
|
+
* not follow `:`, `,` or `[`: a record appended to a line whose write was cut
|
|
498
|
+
* off. The record that the start of the tail window cuts has no such start
|
|
499
|
+
* in the window, and is not read.
|
|
500
|
+
*
|
|
501
|
+
* Undefined when the field of that record is empty: older records are not
|
|
502
|
+
* searched.
|
|
503
|
+
*/
|
|
504
|
+
function lastRecordField(text, field, type) {
|
|
505
|
+
const fieldMarker = `"${field}":`;
|
|
506
|
+
const typeMarkers = type === undefined ? undefined : [`"type":"${type}"`, `"type": "${type}"`];
|
|
507
|
+
const lines = text.split("\n");
|
|
508
|
+
for (let i = lines.length - 1; i >= 0; i--) {
|
|
509
|
+
const line = lines[i];
|
|
510
|
+
if (!line.includes(fieldMarker))
|
|
511
|
+
continue;
|
|
512
|
+
if (typeMarkers && !typeMarkers.some((marker) => line.includes(marker)))
|
|
513
|
+
continue;
|
|
514
|
+
let value = recordField(line, field, type);
|
|
515
|
+
if (value === null && typeMarkers) {
|
|
516
|
+
const start = line.lastIndexOf(`{${typeMarkers[0]}`);
|
|
517
|
+
if (start > 0 && !":,[".includes(line[start - 1])) {
|
|
518
|
+
value = recordField(line.slice(start), field, type);
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
if (typeof value === "string")
|
|
522
|
+
return value || undefined;
|
|
523
|
+
}
|
|
524
|
+
return undefined;
|
|
525
|
+
}
|
|
473
526
|
/** Whether the first record of the transcript is a sidechain one, which the
|
|
474
527
|
* SDK never lists. */
|
|
475
528
|
export function isSidechainTranscript(head) {
|
|
@@ -477,9 +530,10 @@ export function isSidechainTranscript(head) {
|
|
|
477
530
|
const first = newline >= 0 ? head.slice(0, newline) : head;
|
|
478
531
|
return first.includes('"isSidechain":true') || first.includes('"isSidechain": true');
|
|
479
532
|
}
|
|
480
|
-
/** The last `
|
|
533
|
+
/** The title of the last `custom-title` record of the tail, as the SDK reads
|
|
534
|
+
* it (see {@link lastRecordField}). */
|
|
481
535
|
export function tailCustomTitle({ tail, sdkTail }) {
|
|
482
|
-
return
|
|
536
|
+
return lastRecordField(sdkTail ?? tail, "customTitle", "custom-title");
|
|
483
537
|
}
|
|
484
538
|
/** The last non-blank top-level `agentName` of the records of `text`, the
|
|
485
539
|
* name `/rename`, a `rename_session` and AIR write with the custom title. */
|
|
@@ -512,20 +566,21 @@ export function transcriptAgentName({ head, tail }) {
|
|
|
512
566
|
*/
|
|
513
567
|
export function sdkTitles({ head, tail: wholeLines, sdkTail }, sidecarTitle) {
|
|
514
568
|
const tail = sdkTail ?? wholeLines;
|
|
515
|
-
const customTitle =
|
|
569
|
+
const customTitle = lastRecordField(tail, "customTitle", "custom-title") ??
|
|
516
570
|
sidecarTitle ??
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
571
|
+
lastRecordField(head, "customTitle", "custom-title") ??
|
|
572
|
+
lastRecordField(tail, "aiTitle", "ai-title") ??
|
|
573
|
+
lastRecordField(head, "aiTitle", "ai-title");
|
|
520
574
|
return { customTitle, summary: customTitle ?? generatedTitle({ head, tail }) };
|
|
521
575
|
}
|
|
522
576
|
/** The title of a transcript without a custom title, in the SDK's order: AI
|
|
523
|
-
* title, last prompt, summary, first prompt.
|
|
577
|
+
* title, last prompt, summary, first prompt. The last prompt and the summary
|
|
578
|
+
* are the field of a record of any type. */
|
|
524
579
|
export function generatedTitle({ head, tail }) {
|
|
525
|
-
return (
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
580
|
+
return (lastRecordField(tail, "aiTitle", "ai-title") ??
|
|
581
|
+
lastRecordField(head, "aiTitle", "ai-title") ??
|
|
582
|
+
lastRecordField(tail, "lastPrompt") ??
|
|
583
|
+
lastRecordField(tail, "summary") ??
|
|
529
584
|
(firstPrompt(head) || mediaPrompt(head) || undefined));
|
|
530
585
|
}
|
|
531
586
|
/** The time of the last `"timestamp"` in the last 64 KB of a file, cut
|