@anvia/client 1.5.0 → 1.7.0
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 +28 -0
- package/dist/durable-chat.d.ts +51 -0
- package/dist/durable-chat.d.ts.map +1 -0
- package/dist/durable-chat.js +933 -0
- package/dist/durable-chat.js.map +1 -0
- package/dist/durable.d.ts +71 -65
- package/dist/durable.d.ts.map +1 -0
- package/dist/durable.js +213 -253
- package/dist/durable.js.map +1 -1
- package/dist/event-transport-CcP1zaST.js +103 -0
- package/dist/event-transport-CcP1zaST.js.map +1 -0
- package/dist/event-transport-rXxwo4BK.d.ts +88 -0
- package/dist/event-transport-rXxwo4BK.d.ts.map +1 -0
- package/dist/index.d.ts +62 -415
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1968 -2382
- package/dist/index.js.map +1 -1
- package/dist/streams-BXxF27Hp.js +156 -0
- package/dist/streams-BXxF27Hp.js.map +1 -0
- package/dist/transport/index.d.ts +2 -91
- package/dist/transport/index.js +3 -23
- package/dist/types-Bt4tUcST.d.ts +348 -0
- package/dist/types-Bt4tUcST.d.ts.map +1 -0
- package/dist/types-CqJxMo_1.js +466 -0
- package/dist/types-CqJxMo_1.js.map +1 -0
- package/package.json +11 -7
- package/dist/chunk-PD72KNCV.js +0 -150
- package/dist/chunk-PD72KNCV.js.map +0 -1
- package/dist/chunk-RK5U6WVJ.js +0 -127
- package/dist/chunk-RK5U6WVJ.js.map +0 -1
- package/dist/transport/index.js.map +0 -1
package/README.md
CHANGED
|
@@ -75,7 +75,35 @@ These committed progress events are separate from token-delta chat streams.
|
|
|
75
75
|
|
|
76
76
|
See the [durable HTTP guide](../../docs/packages/durable.md#http-server-and-client).
|
|
77
77
|
|
|
78
|
+
### Chat UI transport
|
|
79
|
+
|
|
80
|
+
The optional `@anvia/client/durable-chat` entrypoint exports `createDurableChatTransport`, which
|
|
81
|
+
adapts a durable endpoint to the `ClientTransport` contract used by `useChat` from `@anvia/react`
|
|
82
|
+
and the `@anvia/react-ui` primitives. Create one transport per chat session; the agent, session and
|
|
83
|
+
request identity live there, not in an individual message request.
|
|
84
|
+
|
|
85
|
+
```ts
|
|
86
|
+
const transport = createDurableChatTransport({ client, agentId, sessionId });
|
|
87
|
+
const chat = useChat({ transport });
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
The adapter submits the last user message with `enqueue: true` by default, maps durable journal
|
|
91
|
+
events to `anvia.client.v3` frames, routes interaction responses to the run that produced them, and
|
|
92
|
+
uses the durable run id and sequence as `{ streamId, after }` for resume. Aborting the subscription
|
|
93
|
+
detaches only; use `transport.controller.cancel()`, `retry()`, `resolveTool()` or
|
|
94
|
+
`reattach(runId, after)` for explicit run control. A busy session is reported as
|
|
95
|
+
`DurableBusyError` with the run to reattach to. Client history is discarded in favour of the
|
|
96
|
+
durable transcript, so `regenerate()` and `reset()` are approximate; thread lists are not covered.
|
|
97
|
+
|
|
78
98
|
`DurableClient` also exposes `submitGraph`, `listGraphs`, `graphSnapshot`, `streamGraph`, and
|
|
79
99
|
`cancelGraph`. Graph snapshots contain renderable nodes/edges and explicit waiting reasons.
|
|
80
100
|
Use each node's `runId` with the existing response/retry/reconciliation methods. Graph streams
|
|
81
101
|
carry `graphId` and `taskId`; refresh the snapshot to obtain the latest graph-wide state.
|
|
102
|
+
|
|
103
|
+
## Restarted generations
|
|
104
|
+
|
|
105
|
+
A repeated `generation_start` for an unfinished turn emits `message_reset` before
|
|
106
|
+
new content. The reducer clears that message's parts, metadata, and generation state
|
|
107
|
+
while preserving its ID and role. Completed turns and other agent scopes are unaffected.
|
|
108
|
+
Upgrade both server and frontend copies of `@anvia/client` together so the frontend
|
|
109
|
+
validator recognizes this event.
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { DurableClient } from "./durable.js";
|
|
2
|
+
import { f as ClientStreamCursor, g as ClientStreamRequest, v as ClientTransport } from "./types-Bt4tUcST.js";
|
|
3
|
+
import { ToolResultOutput } from "@anvia/core/completion";
|
|
4
|
+
/**
|
|
5
|
+
* Thrown when a submission is rejected because the session already has unfinished work (HTTP 409).
|
|
6
|
+
* `runId` is that run when it could be read back from the session; `undefined` when the lookup
|
|
7
|
+
* failed. Reattach to `runId` instead of submitting again. Aborting a stream never raises this.
|
|
8
|
+
*/
|
|
9
|
+
export declare class DurableBusyError extends Error {
|
|
10
|
+
readonly runId: string | undefined;
|
|
11
|
+
readonly code: "session_busy";
|
|
12
|
+
constructor(runId: string | undefined, message?: string);
|
|
13
|
+
}
|
|
14
|
+
/** Methods the adapter needs. A structural subset of `DurableClient`, so tests can fake it. */
|
|
15
|
+
export type DurableChatClient = Pick<DurableClient, "submit" | "stream" | "respond" | "resolveTool" | "retry" | "cancel" | "listRuns">;
|
|
16
|
+
/**
|
|
17
|
+
* Run controls that `useChat` does not expose. `stop()` only aborts the subscription; cancellation
|
|
18
|
+
* is always this explicit `cancel()`.
|
|
19
|
+
*/
|
|
20
|
+
export type DurableChatController = {
|
|
21
|
+
/** Run last submitted or reattached. Undefined before the first successful send. */
|
|
22
|
+
readonly activeRunId: string | undefined;
|
|
23
|
+
/** Point later interaction responses and `send({ resume })` at an existing run. */
|
|
24
|
+
reattach(runId: string, after?: number): void;
|
|
25
|
+
cancel(runId?: string): Promise<void>;
|
|
26
|
+
retry(runId?: string): Promise<void>;
|
|
27
|
+
resolveTool(operationId: string, output: ToolResultOutput, runId?: string): Promise<void>;
|
|
28
|
+
};
|
|
29
|
+
export type CreateDurableChatTransportOptions = {
|
|
30
|
+
client: DurableChatClient;
|
|
31
|
+
agentId: string;
|
|
32
|
+
sessionId: string;
|
|
33
|
+
/** Defaults to a UUID per submission. Return a stable id to deduplicate one prompt. */
|
|
34
|
+
requestId?: () => string;
|
|
35
|
+
/** Queue behind unfinished session work instead of failing. Defaults to true. */
|
|
36
|
+
enqueue?: boolean;
|
|
37
|
+
};
|
|
38
|
+
export type DurableChatTransport = ClientTransport<ClientStreamRequest> & {
|
|
39
|
+
readonly controller: DurableChatController;
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* Transport `useChat` can pass to talk to `@anvia/durable`.
|
|
43
|
+
*
|
|
44
|
+
* Only the last user message of a `messages` request is submitted; durable keeps the transcript,
|
|
45
|
+
* so the rest of the client history is discarded. An `interaction_response` is delivered to the
|
|
46
|
+
* remembered run and then the stream resumes from the last applied sequence. Abort detaches the
|
|
47
|
+
* SSE subscription and does not cancel the run.
|
|
48
|
+
*/
|
|
49
|
+
export declare function createDurableChatTransport(options: CreateDurableChatTransportOptions): DurableChatTransport;
|
|
50
|
+
export type { ClientStreamCursor };
|
|
51
|
+
//# sourceMappingURL=durable-chat.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"durable-chat.d.ts","names":[],"sources":["../src/durable-chat.ts"],"mappings":";;;;;;;;qBAuBa,yBAAyB;WAIzB;WAHF;EAGE,YAAA,2BACT;;;YAiBQ,oBAAoB,KAC9B;;;;;YAQU;;WAED;;EAET,SAAS,eAAe;EACxB,OAAO,iBAAiB;EACxB,MAAM,iBAAiB;EACvB,YAAY,qBAAqB,QAAQ,kBAAkB,iBAAiB;;YAGlE;EACV,QAAQ;EACR;EACA;;EAEA;;EAEA;;YAGU,uBAAuB,gBAAgB;WACxC,YAAY;;;;;;;;;;wBAkBP,2BACd,SAAS,oCACR"}
|