@coder/ai-sdk-agent 0.8.0 → 0.9.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 +128 -50
- package/dist/index.d.ts +270 -26
- package/dist/index.js +464 -90
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -344,12 +344,27 @@ interface TransportEventBase {
|
|
|
344
344
|
/** Wall-clock observation time in ms since epoch (`Date.now()`). */
|
|
345
345
|
timestamp: number;
|
|
346
346
|
}
|
|
347
|
+
/**
|
|
348
|
+
* Names the `CoderChatClient` operation performing an HTTP exchange (issue
|
|
349
|
+
* #112). The public client method names are the stable vocabulary, so
|
|
350
|
+
* subscribers can classify per-operation timings without reverse-engineering
|
|
351
|
+
* `path` (whose API prefix is private and may change). New client methods
|
|
352
|
+
* extend this union; treat unrecognized values as "some other operation"
|
|
353
|
+
* rather than matching exhaustively.
|
|
354
|
+
*/
|
|
355
|
+
type CoderClientOperation = "listModelConfigs" | "resolveModelConfigId" | "createChat" | "getChat" | "createChatMessage" | "getMessages" | "submitToolResults" | "interruptChat" | "deleteQueuedMessage" | "updateChat" | "archiveChat" | "uploadChatFile" | "getChatFile";
|
|
347
356
|
interface HttpTransportEventBase extends TransportEventBase {
|
|
348
357
|
/**
|
|
349
358
|
* Correlates a request with its response/error. Monotonically increasing
|
|
350
359
|
* per client instance.
|
|
351
360
|
*/
|
|
352
361
|
id: number;
|
|
362
|
+
/**
|
|
363
|
+
* The client operation performing this exchange — the public
|
|
364
|
+
* `CoderChatClient` method name. `archiveChat` stamps its own operation
|
|
365
|
+
* even though it issues the same `PATCH` as `updateChat`.
|
|
366
|
+
*/
|
|
367
|
+
op: CoderClientOperation;
|
|
353
368
|
/** HTTP method, e.g. `POST`. */
|
|
354
369
|
method: string;
|
|
355
370
|
/**
|
|
@@ -415,14 +430,31 @@ interface StreamOpenTransportEvent extends StreamTransportEventBase {
|
|
|
415
430
|
}
|
|
416
431
|
/**
|
|
417
432
|
* A decoded stream event arrived on the wire. Emitted at arrival time for
|
|
418
|
-
* every event in a frame batch
|
|
419
|
-
*
|
|
420
|
-
*
|
|
421
|
-
*
|
|
433
|
+
* every event in a frame batch — after a redial, chatd's replay of the
|
|
434
|
+
* in-progress episode is still visible here, stamped with the reader's own
|
|
435
|
+
* replay verdict (`forwarded`). `event` is the decoded object by reference
|
|
436
|
+
* (no copy): do not mutate it.
|
|
422
437
|
*/
|
|
423
438
|
interface StreamEventTransportEvent extends StreamTransportEventBase {
|
|
424
439
|
type: "ws:event";
|
|
425
440
|
event: ChatStreamEvent;
|
|
441
|
+
/**
|
|
442
|
+
* The reader's replay disposition for this frame (issue #111): `false`
|
|
443
|
+
* exactly when the episode filter suppresses it from the consumption path —
|
|
444
|
+
* a redial's replay of an in-progress delta at or below the last yielded
|
|
445
|
+
* `seq` of the same episode — and `true` when the reader forwards it to its
|
|
446
|
+
* consumer. It is a dedup verdict, not a delivery receipt: a consumer
|
|
447
|
+
* tearing down mid-queue can still discard a forwarded frame.
|
|
448
|
+
*
|
|
449
|
+
* Snapshot dedup is deliberately NOT reflected here: repeated or revised
|
|
450
|
+
* `message` snapshots are always `forwarded: true`, because reconciling
|
|
451
|
+
* them is the consumer's job past the transport layer — TurnTranslator's
|
|
452
|
+
* per-message emitted-content ledger decides what a revision re-emits.
|
|
453
|
+
* That disposition is not stamped on transport frames; subscribers needing
|
|
454
|
+
* content fidelity must consume model output (or TurnTranslator), not
|
|
455
|
+
* `ws:event`.
|
|
456
|
+
*/
|
|
457
|
+
forwarded: boolean;
|
|
426
458
|
}
|
|
427
459
|
/**
|
|
428
460
|
* The connection ended. Exactly one per dial: carries `code`/`reason` when
|
|
@@ -586,7 +618,10 @@ interface StreamChatEventsOptions {
|
|
|
586
618
|
* in-progress generation attempt's `message_part` deltas from `seq` 1, so
|
|
587
619
|
* parts of an episode
|
|
588
620
|
* (`history_version`, `generation_attempt`) at or below the last yielded `seq`
|
|
589
|
-
* are suppressed here rather than double-yielded.
|
|
621
|
+
* are suppressed here rather than double-yielded. That episode filter runs at
|
|
622
|
+
* frame arrival (not at consumption), so each frame's `ws:event` can carry
|
|
623
|
+
* the reader's own verdict as `forwarded` (issue #111) while `timestamp`
|
|
624
|
+
* keeps meaning arrival time. The iteration ends in five
|
|
590
625
|
* ways: `signal` aborting (clean return), a non-transient 4xx upgrade
|
|
591
626
|
* rejection (terminal {@link CoderApiError} — bad/expired token or a deleted
|
|
592
627
|
* chat cannot succeed on retry, while 408/425/429 consume the redial budget),
|
|
@@ -690,6 +725,15 @@ declare class CoderChatClient {
|
|
|
690
725
|
wait?: boolean;
|
|
691
726
|
signal?: AbortSignal;
|
|
692
727
|
}): Promise<Chat>;
|
|
728
|
+
/**
|
|
729
|
+
* Withdraw a QUEUED (not yet materialized) message from the chat's
|
|
730
|
+
* submission queue (`DELETE /queue/{id}`). `queuedMessageId` is the
|
|
731
|
+
* queue-entry id from `CreateChatMessageResponse.queued_message` — a
|
|
732
|
+
* different id space from committed chat message ids. Rejects with a
|
|
733
|
+
* {@link CoderApiError}: 404 when the entry no longer exists (already
|
|
734
|
+
* promoted into history, or deleted), 409 when the chat has no queue.
|
|
735
|
+
*/
|
|
736
|
+
deleteQueuedMessage(chatId: string, queuedMessageId: number, signal?: AbortSignal): Promise<void>;
|
|
693
737
|
updateChat(chatId: string, req: UpdateChatRequest, signal?: AbortSignal): Promise<void>;
|
|
694
738
|
/** Convenience: archive a chat (soft-hide; safe for cleanup). */
|
|
695
739
|
archiveChat(chatId: string, signal?: AbortSignal): Promise<void>;
|
|
@@ -815,6 +859,37 @@ interface ChatAttachment extends UploadedChatFile {
|
|
|
815
859
|
*/
|
|
816
860
|
toFilePart(): FilePart;
|
|
817
861
|
}
|
|
862
|
+
/**
|
|
863
|
+
* Result of {@link CoderAgent.interrupt}: `interrupted: false` means there was
|
|
864
|
+
* no chat to interrupt (neither a live session nor a
|
|
865
|
+
* {@link CoderAgent.lastKnownChatId}) and no server call was made.
|
|
866
|
+
*/
|
|
867
|
+
type CoderInterruptResult = {
|
|
868
|
+
interrupted: true;
|
|
869
|
+
chatId: string;
|
|
870
|
+
} | {
|
|
871
|
+
interrupted: false;
|
|
872
|
+
chatId?: undefined;
|
|
873
|
+
};
|
|
874
|
+
/**
|
|
875
|
+
* Result of {@link CoderAgent.archive}: `archived: false` means there was no
|
|
876
|
+
* chat to archive (neither a live session nor a
|
|
877
|
+
* {@link CoderAgent.lastKnownChatId}) and no server call was made. Failures
|
|
878
|
+
* still throw — see {@link CoderAgent.archive}. `chatId` is the primary
|
|
879
|
+
* target (the session's or last-known chat); `archivedChatIds` additionally
|
|
880
|
+
* lists every chat archived by the call, oldest first — more than one when
|
|
881
|
+
* earlier stranded chats ({@link CoderAgent.strandedChatIds}) were retired
|
|
882
|
+
* alongside it.
|
|
883
|
+
*/
|
|
884
|
+
type CoderArchiveResult = {
|
|
885
|
+
archived: true;
|
|
886
|
+
chatId: string;
|
|
887
|
+
archivedChatIds: string[];
|
|
888
|
+
} | {
|
|
889
|
+
archived: false;
|
|
890
|
+
chatId?: undefined;
|
|
891
|
+
archivedChatIds?: undefined;
|
|
892
|
+
};
|
|
818
893
|
interface CoderAgentSettings<TOOLS extends ToolSet = {}> {
|
|
819
894
|
/**
|
|
820
895
|
* A pre-built {@link CoderChatClient}, used instead of constructing one from
|
|
@@ -859,6 +934,16 @@ interface CoderAgentSettings<TOOLS extends ToolSet = {}> {
|
|
|
859
934
|
planMode?: "" | "plan";
|
|
860
935
|
/** Resume an existing chat (session) instead of creating a new one. */
|
|
861
936
|
chatId?: string;
|
|
937
|
+
/**
|
|
938
|
+
* Resume cursor for `chatId`: the newest chat message id a previous
|
|
939
|
+
* instance had already seen. Persist {@link CoderAgent.lastSeenMessageId}
|
|
940
|
+
* alongside the chat id when a turn ends and supply both here — the resumed
|
|
941
|
+
* turn then skips its pre-prompt seed GET (the single-message history probe
|
|
942
|
+
* that would otherwise establish the cursor). Without it, behavior is
|
|
943
|
+
* unchanged. Must be a positive integer obtained from the getter, and
|
|
944
|
+
* requires `chatId`; anything else fails construction.
|
|
945
|
+
*/
|
|
946
|
+
lastSeenMessageId?: number;
|
|
862
947
|
/** Stable agent id (exposed as {@link CoderAgent.id}). */
|
|
863
948
|
id?: string;
|
|
864
949
|
/** System instructions → chatd `system_prompt`. */
|
|
@@ -964,6 +1049,33 @@ declare class CoderAgent<TOOLS extends ToolSet = {}> implements Agent<never, TOO
|
|
|
964
1049
|
get client(): CoderChatClient;
|
|
965
1050
|
/** The current chatd chat id, once a turn has started. */
|
|
966
1051
|
get chatId(): string | undefined;
|
|
1052
|
+
/**
|
|
1053
|
+
* The session's resume cursor: the newest chat message id observed, or
|
|
1054
|
+
* `undefined` before any turn has streamed. Persist it alongside
|
|
1055
|
+
* {@link chatId} when a turn ends and supply both to a future instance
|
|
1056
|
+
* ({@link CoderAgentSettings.lastSeenMessageId}) to skip the resumed turn's
|
|
1057
|
+
* pre-prompt seed GET. Read it between turns, not mid-generation.
|
|
1058
|
+
*/
|
|
1059
|
+
get lastSeenMessageId(): number | undefined;
|
|
1060
|
+
/**
|
|
1061
|
+
* The last chat id this agent created or attached to, retained for CLEANUP
|
|
1062
|
+
* even after the session was dropped — a fresh-chat stream failure discards
|
|
1063
|
+
* the session ({@link CoderAgent.chatId} becomes `undefined`, so a retry
|
|
1064
|
+
* starts fresh), but the failed chat still exists server-side.
|
|
1065
|
+
* {@link CoderAgent.archive} and {@link CoderAgent.interrupt} fall back to
|
|
1066
|
+
* this id; generation never does. Superseded when a later turn creates or
|
|
1067
|
+
* attaches to another chat; cleared once {@link CoderAgent.archive}
|
|
1068
|
+
* succeeds against it.
|
|
1069
|
+
*/
|
|
1070
|
+
get lastKnownChatId(): string | undefined;
|
|
1071
|
+
/**
|
|
1072
|
+
* Chat ids stranded by automatic session discards and not yet cleaned up,
|
|
1073
|
+
* oldest first. Each retryable fresh-chat stream failure strands one chat,
|
|
1074
|
+
* so with `maxRetries` > 0 several can accumulate while only the final
|
|
1075
|
+
* attempt's error (and {@link CoderAgent.lastKnownChatId}) names the
|
|
1076
|
+
* newest. {@link CoderAgent.archive} retires all of them.
|
|
1077
|
+
*/
|
|
1078
|
+
get strandedChatIds(): string[];
|
|
967
1079
|
generate(options: Parameters<InnerAgent<TOOLS>["generate"]>[0]): ReturnType<InnerAgent<TOOLS>["generate"]>;
|
|
968
1080
|
stream(options: Parameters<InnerAgent<TOOLS>["stream"]>[0]): ReturnType<InnerAgent<TOOLS>["stream"]>;
|
|
969
1081
|
/**
|
|
@@ -972,33 +1084,61 @@ declare class CoderAgent<TOOLS extends ToolSet = {}> implements Agent<never, TOO
|
|
|
972
1084
|
* `id`, `provider`/`model`, or `display_name`.
|
|
973
1085
|
*/
|
|
974
1086
|
listModels(signal?: AbortSignal): Promise<ChatModelConfig[]>;
|
|
975
|
-
/**
|
|
1087
|
+
/**
|
|
1088
|
+
* Start a fresh chatd chat on the next turn. The dropped chat still exists
|
|
1089
|
+
* server-side: {@link CoderAgent.archive} / {@link CoderAgent.interrupt}
|
|
1090
|
+
* keep targeting it (via {@link CoderAgent.lastKnownChatId}) until a new
|
|
1091
|
+
* chat supersedes it or an archive succeeds against it.
|
|
1092
|
+
*/
|
|
976
1093
|
resetSession(): void;
|
|
977
1094
|
/**
|
|
978
1095
|
* Interrupt the in-flight generation, if any. Resolves as soon as the server
|
|
979
1096
|
* acknowledges the interrupt — the run keeps winding down asynchronously for
|
|
980
1097
|
* a few seconds afterwards (see {@link CoderAgent.archive}).
|
|
1098
|
+
*
|
|
1099
|
+
* Targets the session's chat, or — after the session was dropped (a
|
|
1100
|
+
* fresh-chat stream failure, or {@link CoderAgent.resetSession}) — the
|
|
1101
|
+
* {@link CoderAgent.lastKnownChatId}, whose run may still be winding down
|
|
1102
|
+
* server-side. With neither, there is nothing to interrupt and it resolves
|
|
1103
|
+
* `{ interrupted: false }` without a server call (inspect the result rather
|
|
1104
|
+
* than relying on a silent no-op).
|
|
981
1105
|
*/
|
|
982
1106
|
interrupt(opts?: {
|
|
983
1107
|
signal?: AbortSignal;
|
|
984
|
-
}): Promise<
|
|
1108
|
+
}): Promise<CoderInterruptResult>;
|
|
985
1109
|
/**
|
|
986
1110
|
* Archive the underlying chat (safe cleanup; hides it from listings).
|
|
987
1111
|
*
|
|
1112
|
+
* Targets the session's chat, or — after the session was dropped (a
|
|
1113
|
+
* fresh-chat stream failure, or {@link CoderAgent.resetSession}) — the
|
|
1114
|
+
* {@link CoderAgent.lastKnownChatId}, so the stranded chat is still cleaned
|
|
1115
|
+
* up; chats stranded by EARLIER automatic discards
|
|
1116
|
+
* ({@link CoderAgent.strandedChatIds} — `maxRetries` can accumulate several)
|
|
1117
|
+
* are retired in the same call. On success each archived id is cleared as a
|
|
1118
|
+
* cleanup target; with no id at all, there is nothing to archive and it
|
|
1119
|
+
* resolves `{ archived: false }` without a server call (inspect the result
|
|
1120
|
+
* rather than relying on a silent no-op).
|
|
1121
|
+
*
|
|
988
1122
|
* A freshly interrupted/settled chat can keep winding down server-side for a
|
|
989
1123
|
* few seconds, during which the server rejects archiving with a 409. Those
|
|
990
|
-
* 409s are retried (~1s apart
|
|
991
|
-
* `
|
|
992
|
-
*
|
|
1124
|
+
* 409s are retried (~1s apart — see `settleRetryDelayMs`) inside ONE
|
|
1125
|
+
* `settleDeadlineMs` window (~15s) shared by the whole call — however many
|
|
1126
|
+
* chats it archives — and the last 409 is rethrown if the window closes
|
|
1127
|
+
* first; any other failure, including a caller abort, rethrows immediately.
|
|
1128
|
+
* Chats are archived oldest first, each id cleared as its archive succeeds —
|
|
1129
|
+
* a mid-list failure rethrows and leaves the remaining ids targetable by a
|
|
1130
|
+
* later retry.
|
|
993
1131
|
*/
|
|
994
1132
|
archive(opts?: {
|
|
995
1133
|
signal?: AbortSignal;
|
|
996
|
-
}): Promise<
|
|
1134
|
+
}): Promise<CoderArchiveResult>;
|
|
997
1135
|
/**
|
|
998
1136
|
* Clean up the chat when the agent leaves an `await using` scope, so cleanup
|
|
999
1137
|
* rides scope exit instead of a separate call you have to remember in a
|
|
1000
1138
|
* `finally`. Interrupts any in-flight server run, then archives the chat
|
|
1001
|
-
* (retrying while the interrupted run settles)
|
|
1139
|
+
* (retrying while the interrupted run settles) — including a chat stranded
|
|
1140
|
+
* by a session discard (see {@link CoderAgent.lastKnownChatId}), which a
|
|
1141
|
+
* failed `generate()` would otherwise leak. Best-effort and bounded
|
|
1002
1142
|
* (~15s overall): disposal errors are swallowed after the bounded attempts
|
|
1003
1143
|
* so they can't mask the scope's own error — call {@link CoderAgent.archive}
|
|
1004
1144
|
* directly when you need guaranteed cleanup.
|
|
@@ -1074,6 +1214,17 @@ interface CoderLanguageModelConfig {
|
|
|
1074
1214
|
planMode?: "" | "plan";
|
|
1075
1215
|
/** Resume an existing chat instead of creating a new one. */
|
|
1076
1216
|
chatId?: string;
|
|
1217
|
+
/**
|
|
1218
|
+
* Resume cursor for `chatId`: the newest chat message id a previous
|
|
1219
|
+
* instance had already seen — persist {@link CoderLanguageModel.lastSeenMessageId}
|
|
1220
|
+
* alongside the chat id and supply both here. Skips the resumed turn's
|
|
1221
|
+
* pre-prompt seed GET (the single-message history probe that would
|
|
1222
|
+
* otherwise establish the cursor); without it, behavior is unchanged and
|
|
1223
|
+
* the seed GET remains the fallback. Must be a positive integer obtained
|
|
1224
|
+
* from the getter, and requires `chatId` (the constructor rejects anything
|
|
1225
|
+
* else — a wrong cursor would silently misattribute replayed history).
|
|
1226
|
+
*/
|
|
1227
|
+
lastSeenMessageId?: number;
|
|
1077
1228
|
/**
|
|
1078
1229
|
* Per-segment time budget in milliseconds, applied to each model round-trip
|
|
1079
1230
|
* (one `doStream`/`doGenerate` call: chat creation or message/tool-result
|
|
@@ -1128,10 +1279,52 @@ declare class CoderLanguageModel implements LanguageModelV4 {
|
|
|
1128
1279
|
readonly supportedUrls: Record<string, RegExp[]>;
|
|
1129
1280
|
constructor(config: CoderLanguageModelConfig);
|
|
1130
1281
|
get chatId(): string | undefined;
|
|
1282
|
+
/**
|
|
1283
|
+
* The resume cursor: the newest chat message id this session has observed,
|
|
1284
|
+
* or `undefined` before any turn has streamed (nothing to persist then —
|
|
1285
|
+
* a fresh instance seeds from history instead). Persist it alongside
|
|
1286
|
+
* {@link chatId} once a turn settles and supply both to a future instance
|
|
1287
|
+
* ({@link CoderLanguageModelConfig.lastSeenMessageId}) to skip the resumed
|
|
1288
|
+
* turn's pre-prompt seed GET. Read it between turns, not mid-generation:
|
|
1289
|
+
* the cursor advances when a segment ends.
|
|
1290
|
+
*/
|
|
1291
|
+
get lastSeenMessageId(): number | undefined;
|
|
1292
|
+
/**
|
|
1293
|
+
* The last chat id this model created or attached to, for CLEANUP targeting
|
|
1294
|
+
* only — generation always targets {@link chatId}. It survives
|
|
1295
|
+
* {@link resetSession} (including the automatic session discard after a
|
|
1296
|
+
* fresh-chat stream failure, which clears {@link chatId} so a retry starts
|
|
1297
|
+
* fresh while the failed chat still exists server-side), is superseded when
|
|
1298
|
+
* a later turn creates or attaches to another chat, and is cleared via
|
|
1299
|
+
* {@link noteChatCleanedUp} once cleanup actually succeeded against it.
|
|
1300
|
+
*/
|
|
1301
|
+
get lastKnownChatId(): string | undefined;
|
|
1302
|
+
/**
|
|
1303
|
+
* Chat ids stranded by automatic session discards and not yet cleaned up,
|
|
1304
|
+
* oldest first. Each retryable fresh-chat stream failure strands one chat;
|
|
1305
|
+
* under AI-SDK `maxRetries` several can accumulate while only the final
|
|
1306
|
+
* attempt's error (and {@link lastKnownChatId}) names the newest —
|
|
1307
|
+
* `CoderAgent.archive()` retires all of them. Ids leave the list only via
|
|
1308
|
+
* {@link noteChatCleanedUp}.
|
|
1309
|
+
*/
|
|
1310
|
+
get strandedChatIds(): string[];
|
|
1311
|
+
/**
|
|
1312
|
+
* Forgets `chatId` as a cleanup target — call it only after cleanup
|
|
1313
|
+
* actually succeeded against that chat (e.g. `CoderAgent.archive()`
|
|
1314
|
+
* archived it), so later cleanup calls don't re-target an already-archived
|
|
1315
|
+
* chat: removes it from {@link strandedChatIds} and, when it is the
|
|
1316
|
+
* last-known id, clears {@link lastKnownChatId} (match-guarded: a stale
|
|
1317
|
+
* completion must not erase a newer chat's id). The session field
|
|
1318
|
+
* ({@link chatId}) is deliberately untouched — archiving does not reset the
|
|
1319
|
+
* session.
|
|
1320
|
+
*/
|
|
1321
|
+
noteChatCleanedUp(chatId: string): void;
|
|
1131
1322
|
/**
|
|
1132
1323
|
* Drops the current session so the next turn creates a fresh chat. Also
|
|
1133
1324
|
* closes the retained event stream, if any (fire-and-forget — a sync reset
|
|
1134
1325
|
* must not wait on socket teardown, and `close()` never rejects).
|
|
1326
|
+
* {@link lastKnownChatId} deliberately survives the reset: the dropped chat
|
|
1327
|
+
* still exists server-side and cleanup must still be able to target it.
|
|
1135
1328
|
*/
|
|
1136
1329
|
resetSession(): void;
|
|
1137
1330
|
/**
|
|
@@ -1158,6 +1351,34 @@ declare class CoderLanguageModel implements LanguageModelV4 {
|
|
|
1158
1351
|
doGenerate(options: LanguageModelV4CallOptions): Promise<LanguageModelV4GenerateResult>;
|
|
1159
1352
|
}
|
|
1160
1353
|
|
|
1354
|
+
/** Constructor options for {@link TurnTranslator}. */
|
|
1355
|
+
interface TurnTranslatorOptions {
|
|
1356
|
+
dynamicToolNames: ReadonlySet<string>;
|
|
1357
|
+
turnCursor?: number;
|
|
1358
|
+
/**
|
|
1359
|
+
* Tool-call ids whose results the session already submitted. With the
|
|
1360
|
+
* stream retained across segments (and redialed with the turn's original
|
|
1361
|
+
* cursor), a reconnect can replay a previous segment's `action_required`
|
|
1362
|
+
* snapshot; re-emitting an already-answered call would make the AI SDK
|
|
1363
|
+
* execute the tool a second time. A live reference — the set grows as
|
|
1364
|
+
* later segments submit results.
|
|
1365
|
+
*/
|
|
1366
|
+
submittedToolCallIds?: ReadonlySet<string>;
|
|
1367
|
+
/**
|
|
1368
|
+
* Present when the submission was QUEUED (`CreateChatMessageResponse`
|
|
1369
|
+
* carried no committed `message`): `turnCursor` is then only the PRE-TURN
|
|
1370
|
+
* cursor, and attribution is withheld until the queue entry materializes as
|
|
1371
|
+
* this turn's own user message — see {@link QueuedSubmissionGate} for the
|
|
1372
|
+
* correlation protocol. `id`/`content` come from the response's
|
|
1373
|
+
* `queued_message`; either may be absent on unexpected wire shapes, which
|
|
1374
|
+
* degrades matching (no confirmation / match-any) but never widens
|
|
1375
|
+
* attribution beyond the first observed user message.
|
|
1376
|
+
*/
|
|
1377
|
+
queuedSubmission?: {
|
|
1378
|
+
id?: number;
|
|
1379
|
+
content?: readonly ChatMessagePart[];
|
|
1380
|
+
};
|
|
1381
|
+
}
|
|
1161
1382
|
/**
|
|
1162
1383
|
* Translates one chatd turn's {@link ChatStreamEvent} stream into a sequence of
|
|
1163
1384
|
* `LanguageModelV4StreamPart`s for the AI SDK.
|
|
@@ -1178,27 +1399,40 @@ declare class CoderLanguageModel implements LanguageModelV4 {
|
|
|
1178
1399
|
* Client (custom) tool calls are emitted from the reliable `action_required`
|
|
1179
1400
|
* event and left for the AI SDK to execute. chatd's own server-side tools are
|
|
1180
1401
|
* surfaced best-effort as `providerExecuted` tool calls/results.
|
|
1402
|
+
*
|
|
1403
|
+
* A QUEUED submission additionally starts behind an attribution gate: until
|
|
1404
|
+
* the queue entry materializes as this turn's own user message, every event
|
|
1405
|
+
* belongs to the chat's concurrent run and is withheld (see
|
|
1406
|
+
* {@link QueuedSubmissionGate} and {@link TurnTranslatorOptions.queuedSubmission}).
|
|
1181
1407
|
*/
|
|
1182
1408
|
declare class TurnTranslator {
|
|
1183
1409
|
#private;
|
|
1184
|
-
constructor(opts:
|
|
1185
|
-
dynamicToolNames: ReadonlySet<string>;
|
|
1186
|
-
turnCursor?: number;
|
|
1187
|
-
/**
|
|
1188
|
-
* Tool-call ids whose results the session already submitted. With the
|
|
1189
|
-
* stream retained across segments (and redialed with the turn's original
|
|
1190
|
-
* cursor), a reconnect can replay a previous segment's `action_required`
|
|
1191
|
-
* snapshot; re-emitting an already-answered call would make the AI SDK
|
|
1192
|
-
* execute the tool a second time. A live reference — the set grows as
|
|
1193
|
-
* later segments submit results.
|
|
1194
|
-
*/
|
|
1195
|
-
submittedToolCallIds?: ReadonlySet<string>;
|
|
1196
|
-
});
|
|
1410
|
+
constructor(opts: TurnTranslatorOptions);
|
|
1197
1411
|
get terminalStatus(): ChatStatus | undefined;
|
|
1198
1412
|
/** Whether a client (custom) tool call has been emitted this turn. */
|
|
1199
1413
|
get clientToolCallSeen(): boolean;
|
|
1200
1414
|
get maxMessageId(): number;
|
|
1201
1415
|
get error(): ChatErrorPayload | undefined;
|
|
1416
|
+
/**
|
|
1417
|
+
* The turn's EFFECTIVE attribution cursor: the constructor's `turnCursor`
|
|
1418
|
+
* until a queued submission anchors, the materialized user message's id
|
|
1419
|
+
* after. Distinct from the stream's redial cursor, which deliberately stays
|
|
1420
|
+
* the turn's original `after_id` (see `streamChatEvents`).
|
|
1421
|
+
*/
|
|
1422
|
+
get turnCursor(): number;
|
|
1423
|
+
/**
|
|
1424
|
+
* Whether a queued submission is still awaiting its own user-message
|
|
1425
|
+
* snapshot (#114). While true, nothing is attributed to this turn — no
|
|
1426
|
+
* content, usage, tool calls, or settle statuses — because the stream
|
|
1427
|
+
* window still belongs to the chat's concurrent run.
|
|
1428
|
+
*/
|
|
1429
|
+
get awaitingQueuedSubmission(): boolean;
|
|
1430
|
+
/**
|
|
1431
|
+
* Set when a queued submission's wait can never complete (see
|
|
1432
|
+
* {@link QueuedSubmissionGate}); the model layer throws it so the turn
|
|
1433
|
+
* fails fast instead of hanging until timeout/abort.
|
|
1434
|
+
*/
|
|
1435
|
+
get queuedSubmissionDeadEnd(): ChatErrorPayload | undefined;
|
|
1202
1436
|
ingest(ev: ChatStreamEvent): LanguageModelV4StreamPart[];
|
|
1203
1437
|
finish(): LanguageModelV4StreamPart[];
|
|
1204
1438
|
}
|
|
@@ -1340,11 +1574,21 @@ declare class CoderApiError extends CoderAgentError {
|
|
|
1340
1574
|
*/
|
|
1341
1575
|
declare class CoderStreamError extends APICallError {
|
|
1342
1576
|
name: string;
|
|
1577
|
+
/**
|
|
1578
|
+
* The chatd chat id the failed turn had created or attached to, when known.
|
|
1579
|
+
* A fresh-chat stream failure discards the session so a retry starts on a
|
|
1580
|
+
* fresh chat (`CoderAgent.chatId` becomes `undefined`), but the failed chat
|
|
1581
|
+
* still exists server-side — this field names it so callers can clean it up
|
|
1582
|
+
* (`CoderAgent.archive()` also retains it as the last-known cleanup target).
|
|
1583
|
+
* `undefined` when the failure happened before any chat existed.
|
|
1584
|
+
*/
|
|
1585
|
+
readonly chatId: string | undefined;
|
|
1343
1586
|
constructor(args: {
|
|
1344
1587
|
message: string;
|
|
1345
1588
|
url: string;
|
|
1346
1589
|
cause?: unknown;
|
|
1347
1590
|
isRetryable?: boolean;
|
|
1591
|
+
chatId?: string;
|
|
1348
1592
|
});
|
|
1349
1593
|
}
|
|
1350
1594
|
/** A chat generation ended in an error status. */
|
|
@@ -1357,4 +1601,4 @@ declare class CoderChatError extends CoderAgentError {
|
|
|
1357
1601
|
constructor(payload: ChatErrorPayload);
|
|
1358
1602
|
}
|
|
1359
1603
|
|
|
1360
|
-
export { CHAT_ATTACHMENT_MEDIA_TYPES, CODER_PROVIDER_OPTIONS, type Chat, type ChatAttachment, type ChatAttachmentMediaType, type ChatBusyBehavior, type ChatClientType, type ChatErrorPayload, type ChatFileInput, type ChatInputPart, type ChatInputPartType, type ChatMessage, type ChatMessagePart, type ChatMessagePartType, type ChatMessageRole, type ChatMessageUsage, type ChatMessagesResponse, type ChatMessagesToUIMessagesOptions, type ChatModelConfig, type ChatPlanMode, type ChatQueuedMessage, type ChatStatus, type ChatStreamActionRequired, type ChatStreamEvent, type ChatStreamEventType, type ChatStreamMessagePart, type ChatStreamRetry, type ChatStreamStatus, type ChatStreamToolCall, type ChatWatchEvent, type ChatWatchEventKind, CoderAgent, CoderAgentError, type CoderAgentSettings, CoderApiError, CoderChatClient, type CoderChatClientOptions, CoderChatError, type CoderFileProviderOptions, CoderLanguageModel, type CoderLanguageModelConfig, CoderStreamError, type CoderTransportEvent, type CreateChatMessageRequest, type CreateChatMessageResponse, type CreateChatRequest, type DynamicTool, type FileContent, type FilePartUploader, type HttpErrorTransportEvent, type HttpRequestTransportEvent, type HttpResponseTransportEvent, MAX_CHAT_FILE_SIZE_BYTES, type PreviewShareLevel, type ResolvedFile, type SegmentSettleTransportEvent, type SegmentStartTransportEvent, type SharePreviewOptions, type SharedWorkspacePreview, type StreamCloseTransportEvent, type StreamDialTransportEvent, type StreamErrorTransportEvent, type StreamEventTransportEvent, type StreamOpenTransportEvent, type StreamRedialTransportEvent, type SubmitToolResultsRequest, TERMINAL_STATUSES, type ToolResult, type TransportEventHandler, type TurnAction, TurnTranslator, type UpdateChatRequest, type UploadChatFileResponse, type UploadedChatFile, type UserContent, type WatchChatEventsOptions, type WebSocketFactory, type WebSocketLike, type WorkspaceFileStore, type WorkspacePlacement, type WorkspacePreview, type WorkspacePreviewOptions, chatMessagesToUIMessages, classifyTurnAction, dataContentToFileContent, dynamicToolNames, extractSystemPrompt, resolveFileContent, streamChatEvents, toolsToDynamicTools, userContentToInputParts, watchChatEvents };
|
|
1604
|
+
export { CHAT_ATTACHMENT_MEDIA_TYPES, CODER_PROVIDER_OPTIONS, type Chat, type ChatAttachment, type ChatAttachmentMediaType, type ChatBusyBehavior, type ChatClientType, type ChatErrorPayload, type ChatFileInput, type ChatInputPart, type ChatInputPartType, type ChatMessage, type ChatMessagePart, type ChatMessagePartType, type ChatMessageRole, type ChatMessageUsage, type ChatMessagesResponse, type ChatMessagesToUIMessagesOptions, type ChatModelConfig, type ChatPlanMode, type ChatQueuedMessage, type ChatStatus, type ChatStreamActionRequired, type ChatStreamEvent, type ChatStreamEventType, type ChatStreamMessagePart, type ChatStreamRetry, type ChatStreamStatus, type ChatStreamToolCall, type ChatWatchEvent, type ChatWatchEventKind, CoderAgent, CoderAgentError, type CoderAgentSettings, CoderApiError, type CoderArchiveResult, CoderChatClient, type CoderChatClientOptions, CoderChatError, type CoderClientOperation, type CoderFileProviderOptions, type CoderInterruptResult, CoderLanguageModel, type CoderLanguageModelConfig, CoderStreamError, type CoderTransportEvent, type CreateChatMessageRequest, type CreateChatMessageResponse, type CreateChatRequest, type DynamicTool, type FileContent, type FilePartUploader, type HttpErrorTransportEvent, type HttpRequestTransportEvent, type HttpResponseTransportEvent, MAX_CHAT_FILE_SIZE_BYTES, type PreviewShareLevel, type ResolvedFile, type SegmentSettleTransportEvent, type SegmentStartTransportEvent, type SharePreviewOptions, type SharedWorkspacePreview, type StreamCloseTransportEvent, type StreamDialTransportEvent, type StreamErrorTransportEvent, type StreamEventTransportEvent, type StreamOpenTransportEvent, type StreamRedialTransportEvent, type SubmitToolResultsRequest, TERMINAL_STATUSES, type ToolResult, type TransportEventHandler, type TurnAction, TurnTranslator, type TurnTranslatorOptions, type UpdateChatRequest, type UploadChatFileResponse, type UploadedChatFile, type UserContent, type WatchChatEventsOptions, type WebSocketFactory, type WebSocketLike, type WorkspaceFileStore, type WorkspacePlacement, type WorkspacePreview, type WorkspacePreviewOptions, chatMessagesToUIMessages, classifyTurnAction, dataContentToFileContent, dynamicToolNames, extractSystemPrompt, resolveFileContent, streamChatEvents, toolsToDynamicTools, userContentToInputParts, watchChatEvents };
|