@ably/ai-transport 0.1.0 → 0.2.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 +91 -100
- package/dist/ably-ai-transport.js +1553 -1238
- package/dist/ably-ai-transport.js.map +1 -1
- package/dist/ably-ai-transport.umd.cjs +1 -1
- package/dist/ably-ai-transport.umd.cjs.map +1 -1
- package/dist/constants.d.ts +116 -42
- package/dist/core/agent.d.ts +29 -0
- package/dist/core/codec/decoder.d.ts +20 -23
- package/dist/core/codec/encoder.d.ts +11 -8
- package/dist/core/codec/index.d.ts +1 -2
- package/dist/core/codec/lifecycle-tracker.d.ts +10 -9
- package/dist/core/codec/types.d.ts +407 -115
- package/dist/core/transport/agent-session.d.ts +10 -0
- package/dist/core/transport/branch-chain.d.ts +43 -0
- package/dist/core/transport/client-session.d.ts +13 -0
- package/dist/core/transport/decode-fold.d.ts +47 -0
- package/dist/core/transport/headers.d.ts +96 -18
- package/dist/core/transport/index.d.ts +5 -6
- package/dist/core/transport/internal/bounded-map.d.ts +20 -0
- package/dist/core/transport/invocation.d.ts +74 -0
- package/dist/core/transport/load-conversation.d.ts +128 -0
- package/dist/core/transport/load-history.d.ts +39 -0
- package/dist/core/transport/pipe-stream.d.ts +9 -9
- package/dist/core/transport/run-manager.d.ts +78 -0
- package/dist/core/transport/tree.d.ts +373 -109
- package/dist/core/transport/types/agent.d.ts +353 -0
- package/dist/core/transport/types/client.d.ts +168 -0
- package/dist/core/transport/types/shared.d.ts +24 -0
- package/dist/core/transport/types/tree.d.ts +315 -0
- package/dist/core/transport/types/view.d.ts +222 -0
- package/dist/core/transport/types.d.ts +13 -553
- package/dist/core/transport/view.d.ts +272 -84
- package/dist/errors.d.ts +21 -10
- package/dist/index.d.ts +6 -8
- package/dist/logger.d.ts +12 -0
- package/dist/react/ably-ai-transport-react.js +976 -990
- package/dist/react/ably-ai-transport-react.js.map +1 -1
- package/dist/react/ably-ai-transport-react.umd.cjs +1 -1
- package/dist/react/ably-ai-transport-react.umd.cjs.map +1 -1
- package/dist/react/contexts/client-session-context.d.ts +36 -0
- package/dist/react/contexts/client-session-provider.d.ts +53 -0
- package/dist/react/create-session-hooks.d.ts +116 -0
- package/dist/react/index.d.ts +12 -12
- package/dist/react/internal/use-resolved-session.d.ts +36 -0
- package/dist/react/use-ably-messages.d.ts +17 -14
- package/dist/react/use-client-session.d.ts +81 -0
- package/dist/react/use-create-view.d.ts +14 -13
- package/dist/react/use-tree.d.ts +30 -15
- package/dist/react/use-view.d.ts +82 -51
- package/dist/utils.d.ts +32 -23
- package/dist/vercel/ably-ai-transport-vercel.js +2573 -2086
- package/dist/vercel/ably-ai-transport-vercel.js.map +1 -1
- package/dist/vercel/ably-ai-transport-vercel.umd.cjs +1 -1
- package/dist/vercel/ably-ai-transport-vercel.umd.cjs.map +1 -1
- package/dist/vercel/codec/decoder.d.ts +5 -18
- package/dist/vercel/codec/encoder.d.ts +6 -36
- package/dist/vercel/codec/events.d.ts +51 -0
- package/dist/vercel/codec/index.d.ts +24 -12
- package/dist/vercel/codec/reducer.d.ts +144 -0
- package/dist/vercel/codec/tool-transitions.d.ts +2 -2
- package/dist/vercel/index.d.ts +4 -5
- package/dist/vercel/react/ably-ai-transport-vercel-react.js +3907 -3266
- package/dist/vercel/react/ably-ai-transport-vercel-react.js.map +1 -1
- package/dist/vercel/react/ably-ai-transport-vercel-react.umd.cjs +33 -8
- package/dist/vercel/react/ably-ai-transport-vercel-react.umd.cjs.map +1 -1
- package/dist/vercel/react/contexts/chat-transport-context.d.ts +7 -6
- package/dist/vercel/react/contexts/chat-transport-provider.d.ts +53 -41
- package/dist/vercel/react/index.d.ts +1 -2
- package/dist/vercel/react/use-chat-transport.d.ts +30 -26
- package/dist/vercel/react/use-message-sync.d.ts +17 -30
- package/dist/vercel/run-end-reason.d.ts +29 -0
- package/dist/vercel/transport/chat-transport.d.ts +43 -24
- package/dist/vercel/transport/index.d.ts +25 -21
- package/dist/vercel/transport/run-output-stream.d.ts +56 -0
- package/dist/version.d.ts +2 -0
- package/package.json +30 -23
- package/src/constants.ts +124 -51
- package/src/core/agent.ts +68 -0
- package/src/core/codec/decoder.ts +71 -98
- package/src/core/codec/encoder.ts +113 -65
- package/src/core/codec/index.ts +13 -6
- package/src/core/codec/lifecycle-tracker.ts +10 -9
- package/src/core/codec/types.ts +436 -120
- package/src/core/transport/agent-session.ts +1344 -0
- package/src/core/transport/branch-chain.ts +58 -0
- package/src/core/transport/client-session.ts +775 -0
- package/src/core/transport/decode-fold.ts +91 -0
- package/src/core/transport/headers.ts +181 -22
- package/src/core/transport/index.ts +25 -26
- package/src/core/transport/internal/bounded-map.ts +27 -0
- package/src/core/transport/invocation.ts +98 -0
- package/src/core/transport/load-conversation.ts +355 -0
- package/src/core/transport/load-history.ts +269 -0
- package/src/core/transport/pipe-stream.ts +54 -39
- package/src/core/transport/run-manager.ts +249 -0
- package/src/core/transport/tree.ts +926 -308
- package/src/core/transport/types/agent.ts +407 -0
- package/src/core/transport/types/client.ts +211 -0
- package/src/core/transport/types/shared.ts +27 -0
- package/src/core/transport/types/tree.ts +344 -0
- package/src/core/transport/types/view.ts +259 -0
- package/src/core/transport/types.ts +13 -706
- package/src/core/transport/view.ts +864 -433
- package/src/errors.ts +22 -9
- package/src/event-emitter.ts +3 -2
- package/src/index.ts +52 -41
- package/src/logger.ts +14 -1
- package/src/react/contexts/client-session-context.ts +41 -0
- package/src/react/contexts/client-session-provider.tsx +186 -0
- package/src/react/create-session-hooks.ts +141 -0
- package/src/react/index.ts +23 -13
- package/src/react/internal/use-resolved-session.ts +63 -0
- package/src/react/use-ably-messages.ts +32 -22
- package/src/react/use-client-session.ts +201 -0
- package/src/react/use-create-view.ts +33 -29
- package/src/react/use-tree.ts +61 -30
- package/src/react/use-view.ts +139 -97
- package/src/utils.ts +63 -45
- package/src/vercel/codec/decoder.ts +336 -258
- package/src/vercel/codec/encoder.ts +343 -205
- package/src/vercel/codec/events.ts +87 -0
- package/src/vercel/codec/index.ts +60 -13
- package/src/vercel/codec/reducer.ts +977 -0
- package/src/vercel/codec/tool-transitions.ts +2 -2
- package/src/vercel/index.ts +6 -19
- package/src/vercel/react/contexts/chat-transport-context.ts +7 -6
- package/src/vercel/react/contexts/chat-transport-provider.tsx +87 -59
- package/src/vercel/react/index.ts +3 -5
- package/src/vercel/react/use-chat-transport.ts +47 -49
- package/src/vercel/react/use-message-sync.ts +80 -39
- package/src/vercel/run-end-reason.ts +78 -0
- package/src/vercel/transport/chat-transport.ts +392 -98
- package/src/vercel/transport/index.ts +39 -38
- package/src/vercel/transport/run-output-stream.ts +170 -0
- package/src/version.ts +2 -0
- package/dist/core/transport/client-transport.d.ts +0 -10
- package/dist/core/transport/decode-history.d.ts +0 -43
- package/dist/core/transport/server-transport.d.ts +0 -7
- package/dist/core/transport/stream-router.d.ts +0 -29
- package/dist/core/transport/turn-manager.d.ts +0 -37
- package/dist/react/contexts/transport-context.d.ts +0 -31
- package/dist/react/contexts/transport-provider.d.ts +0 -49
- package/dist/react/create-transport-hooks.d.ts +0 -124
- package/dist/react/use-active-turns.d.ts +0 -12
- package/dist/react/use-client-transport.d.ts +0 -80
- package/dist/vercel/codec/accumulator.d.ts +0 -21
- package/dist/vercel/react/use-staged-add-tool-approval-response.d.ts +0 -30
- package/dist/vercel/tool-approvals.d.ts +0 -124
- package/dist/vercel/tool-events.d.ts +0 -26
- package/src/core/transport/client-transport.ts +0 -977
- package/src/core/transport/decode-history.ts +0 -485
- package/src/core/transport/server-transport.ts +0 -612
- package/src/core/transport/stream-router.ts +0 -136
- package/src/core/transport/turn-manager.ts +0 -165
- package/src/react/contexts/transport-context.ts +0 -37
- package/src/react/contexts/transport-provider.tsx +0 -164
- package/src/react/create-transport-hooks.ts +0 -144
- package/src/react/use-active-turns.ts +0 -72
- package/src/react/use-client-transport.ts +0 -197
- package/src/vercel/codec/accumulator.ts +0 -588
- package/src/vercel/react/use-staged-add-tool-approval-response.ts +0 -87
- package/src/vercel/tool-approvals.ts +0 -380
- package/src/vercel/tool-events.ts +0 -53
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import { ClientTransport } from '../core/transport/types.js';
|
|
2
|
-
/**
|
|
3
|
-
* useClientTransport — read a ClientTransport from the nearest TransportProvider.
|
|
4
|
-
*
|
|
5
|
-
* The transport is created by {@link TransportProvider}, which also wraps the subtree
|
|
6
|
-
* with Ably's `ChannelProvider`. This hook is a thin context reader — it does not
|
|
7
|
-
* create or manage transport state.
|
|
8
|
-
*
|
|
9
|
-
* **Provider lookup**
|
|
10
|
-
* - Omit `channelName` to use the innermost `TransportProvider` in the tree.
|
|
11
|
-
* - Pass `channelName` to look up a specific provider by name.
|
|
12
|
-
* - Pass `skip: true` to receive a stub transport that throws on any access —
|
|
13
|
-
* safe to hold in state before auth or other conditions are ready.
|
|
14
|
-
*
|
|
15
|
-
* **Error handling**
|
|
16
|
-
* - When no matching provider is found, or when the provider's `createClientTransport`
|
|
17
|
-
* call threw, `transportError` is set on the returned object instead of throwing.
|
|
18
|
-
* The component can render an error state without an error boundary.
|
|
19
|
-
* - Pass `onError` to receive post-construction transport errors (e.g. send failures,
|
|
20
|
-
* channel continuity loss) without wiring `transport.on('error', ...)` manually.
|
|
21
|
-
*/
|
|
22
|
-
import * as Ably from 'ably';
|
|
23
|
-
/**
|
|
24
|
-
* Return value of {@link useClientTransport}.
|
|
25
|
-
*
|
|
26
|
-
* `transport` is always a valid object. When `skip` is `true`, when no provider was
|
|
27
|
-
* found, or when the provider's transport construction failed, `transport` is a stub
|
|
28
|
-
* that throws {@link Ably.ErrorInfo} on every access.
|
|
29
|
-
* Check `transportError` before using `transport` to avoid those throws.
|
|
30
|
-
*/
|
|
31
|
-
export interface ClientTransportHandle<TEvent, TMessage> {
|
|
32
|
-
/**
|
|
33
|
-
* The resolved transport.
|
|
34
|
-
*
|
|
35
|
-
* A throwing stub when `skip` is `true`, when no matching {@link TransportProvider}
|
|
36
|
-
* was found in the tree, or when transport construction failed.
|
|
37
|
-
*/
|
|
38
|
-
transport: ClientTransport<TEvent, TMessage>;
|
|
39
|
-
/**
|
|
40
|
-
* Set when no matching {@link TransportProvider} was found, when transport
|
|
41
|
-
* construction failed, and `skip` is `false`.
|
|
42
|
-
* `undefined` when the transport resolved successfully or when `skip` is `true`.
|
|
43
|
-
*/
|
|
44
|
-
transportError?: Ably.ErrorInfo | undefined;
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* Read a {@link ClientTransport} from the nearest {@link TransportProvider}.
|
|
48
|
-
*
|
|
49
|
-
* Returns `{ transport, transportError }`. When no provider is found or transport
|
|
50
|
-
* construction failed, `transportError` is set and `transport` is a stub that throws
|
|
51
|
-
* on access — the hook never throws during render.
|
|
52
|
-
*
|
|
53
|
-
* Pass `onError` to subscribe to post-construction transport errors
|
|
54
|
-
* (e.g. {@link ErrorCode.TransportSendFailed}, {@link ErrorCode.ChannelContinuityLost})
|
|
55
|
-
* without calling `transport.on('error', …)` manually. The subscription is
|
|
56
|
-
* created when the transport resolves and removed on unmount.
|
|
57
|
-
* @param props - Hook options.
|
|
58
|
-
* @param props.channelName - Look up a specific provider by channel name; omit for the nearest.
|
|
59
|
-
* @param props.skip - When `true`, return the stub transport immediately without reading context.
|
|
60
|
-
* @param props.onError - Called whenever the resolved transport emits an error event.
|
|
61
|
-
* @returns `{ transport, transportError }`.
|
|
62
|
-
*/
|
|
63
|
-
export declare const useClientTransport: <TEvent, TMessage>({ channelName, skip, onError, }?: {
|
|
64
|
-
/**
|
|
65
|
-
* Channel name passed to the enclosing {@link TransportProvider}.
|
|
66
|
-
* Omit to use the nearest provider in the tree.
|
|
67
|
-
*/
|
|
68
|
-
channelName?: string;
|
|
69
|
-
/**
|
|
70
|
-
* When `true`, skip context lookup and return a stub transport that throws on
|
|
71
|
-
* any access. Use when a condition (auth, feature flag) is not yet resolved.
|
|
72
|
-
*/
|
|
73
|
-
skip?: boolean;
|
|
74
|
-
/**
|
|
75
|
-
* Called whenever the resolved transport emits an error event.
|
|
76
|
-
* The subscription is established once the transport resolves and
|
|
77
|
-
* automatically removed on unmount or when the transport changes.
|
|
78
|
-
*/
|
|
79
|
-
onError?: (error: Ably.ErrorInfo) => void;
|
|
80
|
-
}) => ClientTransportHandle<TEvent, TMessage>;
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { MessageAccumulator } from '../../core/codec/types.js';
|
|
2
|
-
/**
|
|
3
|
-
* Vercel AI SDK Message Accumulator
|
|
4
|
-
*
|
|
5
|
-
* Builds and maintains a UIMessage[] list from decoder outputs.
|
|
6
|
-
* Implements MessageAccumulator<UIMessageChunk, UIMessage>.
|
|
7
|
-
*
|
|
8
|
-
* The accumulator consumes DecoderOutput[] from the decoder and groups
|
|
9
|
-
* streaming events into UIMessage objects using lifecycle boundaries
|
|
10
|
-
* (start/finish). Complete messages (from writeMessages) are inserted
|
|
11
|
-
* directly.
|
|
12
|
-
*
|
|
13
|
-
* Multiple messages can be in-progress concurrently — each is identified
|
|
14
|
-
* by the `messageId` field on DecoderOutput (read from x-ably-msg-id).
|
|
15
|
-
*/
|
|
16
|
-
import type * as AI from 'ai';
|
|
17
|
-
/**
|
|
18
|
-
* Create a Vercel AI SDK accumulator that builds UIMessage[] from decoder outputs.
|
|
19
|
-
* @returns A {@link MessageAccumulator} for UIMessageChunk/UIMessage.
|
|
20
|
-
*/
|
|
21
|
-
export declare const createAccumulator: () => MessageAccumulator<AI.UIMessageChunk, AI.UIMessage>;
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { ChatAddToolApproveResponseFunction } from 'ai';
|
|
2
|
-
import { ClientTransport } from '../../core/transport/types.js';
|
|
3
|
-
/**
|
|
4
|
-
* useStagedAddToolApprovalResponse — wrap useChat's `addToolApprovalResponse`
|
|
5
|
-
* so the approval response is also applied to the transport tree
|
|
6
|
-
* synchronously at click time.
|
|
7
|
-
*
|
|
8
|
-
* Patching the tree at click time eliminates the useChat↔tree divergence
|
|
9
|
-
* the ChatTransport would otherwise have to reconcile via a history
|
|
10
|
-
* overlay, and closes the observer-turn race that could wipe the
|
|
11
|
-
* approval state between `addToolApprovalResponse` and
|
|
12
|
-
* `sendAutomaticallyWhen`'s evaluation.
|
|
13
|
-
*
|
|
14
|
-
* Use this in place of useChat's raw `addToolApprovalResponse` wherever
|
|
15
|
-
* you wire Approve / Deny buttons.
|
|
16
|
-
*/
|
|
17
|
-
import type * as AI from 'ai';
|
|
18
|
-
/**
|
|
19
|
-
* Returns a function with the same signature as useChat's
|
|
20
|
-
* `addToolApprovalResponse`, but additionally applies the approval
|
|
21
|
-
* response to the transport tree via `stageMessage` before delegating.
|
|
22
|
-
*
|
|
23
|
-
* If the tool call identified by `opts.id` isn't found in the tree,
|
|
24
|
-
* the tree update is skipped and the raw function is still called —
|
|
25
|
-
* matches useChat's tolerant behavior for stale approval ids.
|
|
26
|
-
* @param transport - The client transport whose tree to patch.
|
|
27
|
-
* @param addToolApprovalResponse - The raw function from `useChat()`.
|
|
28
|
-
* @returns A drop-in replacement that patches the tree then delegates.
|
|
29
|
-
*/
|
|
30
|
-
export declare const useStagedAddToolApprovalResponse: (transport: ClientTransport<AI.UIMessageChunk, AI.UIMessage>, addToolApprovalResponse: ChatAddToolApproveResponseFunction) => ChatAddToolApproveResponseFunction;
|
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
import { MessageNode, StreamResponseOptions, StreamResult, Turn } from '../core/transport/types.js';
|
|
2
|
-
/**
|
|
3
|
-
* Server-side helpers for processing a tool-approval turn.
|
|
4
|
-
*
|
|
5
|
-
* When a Vercel AI SDK tool is marked `needsApproval`, `streamText` pauses
|
|
6
|
-
* after emitting a `dynamic-tool` part in state `approval-requested`. To
|
|
7
|
-
* resume, the server must:
|
|
8
|
-
*
|
|
9
|
-
* 1. Patch the UIMessage history so the pending tool part reflects the
|
|
10
|
-
* user's decision (`approval-responded` or `output-denied`).
|
|
11
|
-
* 2. Strip the client-appended "Approved: …" user message, because
|
|
12
|
-
* `streamText`'s multi-step loop only auto-executes pending tool
|
|
13
|
-
* calls when the conversation ends on a tool/assistant message.
|
|
14
|
-
* 3. Disable `needsApproval` on just-approved tools so the multi-step
|
|
15
|
-
* loop doesn't immediately pause again on the same tool.
|
|
16
|
-
* 4. Redirect the resulting `tool-output-available` / `tool-output-error`
|
|
17
|
-
* chunks back to the ORIGINAL assistant message (the one that held
|
|
18
|
-
* the `approval-requested` part) via `x-ably-amend`, instead of
|
|
19
|
-
* letting them land on the new assistant message this turn produces.
|
|
20
|
-
*
|
|
21
|
-
* `prepareApprovalTurn` covers steps 1–3; `streamResponseWithApprovalRedirect`
|
|
22
|
-
* covers step 4.
|
|
23
|
-
*/
|
|
24
|
-
import type * as AI from 'ai';
|
|
25
|
-
/**
|
|
26
|
-
* A user's decision on a pending tool approval. The client ships an array of
|
|
27
|
-
* these to the server in the POST body; the server feeds them to
|
|
28
|
-
* `prepareApprovalTurn` (to patch history) and
|
|
29
|
-
* `streamResponseWithApprovalRedirect` (to route tool outputs back to the
|
|
30
|
-
* original assistant message).
|
|
31
|
-
*
|
|
32
|
-
* Intentionally does not carry `toolName` or `input` — those are redundant
|
|
33
|
-
* with what's already on the UIMessage history part.
|
|
34
|
-
*/
|
|
35
|
-
export interface ToolApprovalDecision {
|
|
36
|
-
/**
|
|
37
|
-
* The `toolCallId` of the pending `dynamic-tool` part being approved/denied.
|
|
38
|
-
* Must match a part already in the history; decisions that don't match any
|
|
39
|
-
* part are ignored by {@link applyToolApprovalsToHistory}.
|
|
40
|
-
*/
|
|
41
|
-
toolCallId: string;
|
|
42
|
-
/** Whether the user approved or denied the tool call. */
|
|
43
|
-
approved: boolean;
|
|
44
|
-
/**
|
|
45
|
-
* The `x-ably-msg-id` of the assistant message whose `dynamic-tool` part
|
|
46
|
-
* is being responded to. When approved and the tool executes successfully,
|
|
47
|
-
* the output is published cross-turn targeting this message.
|
|
48
|
-
*/
|
|
49
|
-
targetMsgId: string;
|
|
50
|
-
/** Optional reason accompanying the response. */
|
|
51
|
-
reason?: string;
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* Patch `dynamic-tool` parts in the history to reflect a batch of approval
|
|
55
|
-
* decisions. Pure — returns a new array; input is not mutated.
|
|
56
|
-
*
|
|
57
|
-
* Approved decisions transition the matching part to `approval-responded`,
|
|
58
|
-
* which `convertToModelMessages` will expand into a `tool-approval-response`
|
|
59
|
-
* model message for `streamText`'s multi-step loop. Denied decisions
|
|
60
|
-
* transition to `output-denied`.
|
|
61
|
-
*
|
|
62
|
-
* Messages and parts whose `toolCallId` is not referenced by any decision
|
|
63
|
-
* are passed through by reference.
|
|
64
|
-
* @param messages - The UIMessage history (user + assistant messages).
|
|
65
|
-
* @param decisions - Approval decisions keyed by `toolCallId`.
|
|
66
|
-
* @returns A new array with matching tool parts transitioned.
|
|
67
|
-
*/
|
|
68
|
-
export declare const applyToolApprovalsToHistory: (messages: AI.UIMessage[], decisions: ToolApprovalDecision[]) => AI.UIMessage[];
|
|
69
|
-
/** Options for {@link prepareApprovalTurn}. */
|
|
70
|
-
export interface PrepareApprovalTurnOptions<T extends Record<string, object>> {
|
|
71
|
-
/** The full UIMessage history (user + assistant messages for this conversation). */
|
|
72
|
-
messages: AI.UIMessage[];
|
|
73
|
-
/** The user's approval decisions for this request, if any. */
|
|
74
|
-
decisions: ToolApprovalDecision[] | undefined;
|
|
75
|
-
/**
|
|
76
|
-
* The tool dictionary that will be passed to `streamText`. Typed with a
|
|
77
|
-
* structural `object` value constraint so it accepts `Record<string, Tool>`
|
|
78
|
-
* regardless of which copy of the `ai` peer dep typed it.
|
|
79
|
-
*/
|
|
80
|
-
tools: T;
|
|
81
|
-
}
|
|
82
|
-
/** Result of {@link prepareApprovalTurn}. */
|
|
83
|
-
export interface PrepareApprovalTurnResult<T extends Record<string, object>> {
|
|
84
|
-
/** Model-format messages ready to pass to `streamText({ messages })`. */
|
|
85
|
-
modelMessages: AI.ModelMessage[];
|
|
86
|
-
/** Tools with `needsApproval` disabled for any tool that was just approved. */
|
|
87
|
-
tools: T;
|
|
88
|
-
}
|
|
89
|
-
/**
|
|
90
|
-
* One-shot transform to ready a history + tool dict for a `streamText` call
|
|
91
|
-
* on an approval turn. Returns the patched model-message array and the
|
|
92
|
-
* effective tools dict.
|
|
93
|
-
*
|
|
94
|
-
* When `decisions` is absent or empty, this is a thin wrapper around
|
|
95
|
-
* `convertToModelMessages(messages)` that returns the original tools — so
|
|
96
|
-
* callers can use it uniformly regardless of whether the request carries
|
|
97
|
-
* approvals.
|
|
98
|
-
* @param options - See {@link PrepareApprovalTurnOptions}.
|
|
99
|
-
* @returns See {@link PrepareApprovalTurnResult}.
|
|
100
|
-
*/
|
|
101
|
-
export declare const prepareApprovalTurn: <T extends Record<string, object>>(options: PrepareApprovalTurnOptions<T>) => Promise<PrepareApprovalTurnResult<T>>;
|
|
102
|
-
/** Options for {@link streamResponseWithApprovalRedirect}. */
|
|
103
|
-
export interface StreamResponseWithApprovalRedirectOptions extends StreamResponseOptions<AI.UIMessageChunk> {
|
|
104
|
-
/**
|
|
105
|
-
* The approval decisions this turn is resolving. Only approved decisions
|
|
106
|
-
* redirect tool outputs — denied decisions have already been reflected
|
|
107
|
-
* in the history and produce no tool output to capture.
|
|
108
|
-
*/
|
|
109
|
-
decisions: ToolApprovalDecision[] | undefined;
|
|
110
|
-
}
|
|
111
|
-
export declare const streamResponseWithApprovalRedirect: (turn: Turn<AI.UIMessageChunk, AI.UIMessage>, stream: ReadableStream<AI.UIMessageChunk>, options: StreamResponseWithApprovalRedirectOptions) => Promise<StreamResult>;
|
|
112
|
-
/**
|
|
113
|
-
* Walk the conversation history and synthesize a {@link ToolApprovalDecision}
|
|
114
|
-
* for each `dynamic-tool` part in `approval-responded` (approved) or
|
|
115
|
-
* `output-denied` (denied) state.
|
|
116
|
-
*
|
|
117
|
-
* Use in server routes where the client flips the tool part state directly
|
|
118
|
-
* (via useChat's `addToolApprovalResponse` and our
|
|
119
|
-
* `useStagedAddToolApprovalResponse`) and ships it through the history
|
|
120
|
-
* overlay instead of a separate `toolApprovals` body field.
|
|
121
|
-
* @param history - The conversation history nodes from the POST body.
|
|
122
|
-
* @returns Approval decisions derived from the history, in walk order.
|
|
123
|
-
*/
|
|
124
|
-
export declare const extractApprovalDecisionsFromHistory: (history: readonly MessageNode<AI.UIMessage>[]) => ToolApprovalDecision[];
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { EventsNode, MessageNode } from '../core/transport/types.js';
|
|
2
|
-
/**
|
|
3
|
-
* Server-side helper for folding client-shipped events into an in-memory
|
|
4
|
-
* history array before handing it to `convertToModelMessages` / `streamText`.
|
|
5
|
-
*
|
|
6
|
-
* When a client-executed tool resolves, the client stages the resulting
|
|
7
|
-
* `tool-output-available` / `tool-output-error` chunk via
|
|
8
|
-
* `transport.stageEvents(msgId, [...])`. The next send flushes it into the
|
|
9
|
-
* POST body's `events` field. The server republishes the event on the
|
|
10
|
-
* channel via `turn.addEvents`, and must also merge it into the in-memory
|
|
11
|
-
* history so the LLM sees the tool result this turn.
|
|
12
|
-
*/
|
|
13
|
-
import type * as AI from 'ai';
|
|
14
|
-
/**
|
|
15
|
-
* Fold a batch of client-shipped events into an in-memory history array.
|
|
16
|
-
*
|
|
17
|
-
* Mirrors the optimistic tree update in
|
|
18
|
-
* `DefaultClientTransport._internalSend` (src/core/transport/client-transport.ts)
|
|
19
|
-
* so the server can rebuild the same message state before handing it to
|
|
20
|
-
* `convertToModelMessages` / `streamText`.
|
|
21
|
-
* @param events - The events shipped by the client.
|
|
22
|
-
* @param nodes - The history messages from the POST body.
|
|
23
|
-
* @returns A new array with tool-result events applied to the matching
|
|
24
|
-
* messages. Non-targeted messages are passed through unchanged.
|
|
25
|
-
*/
|
|
26
|
-
export declare const applyToolEventsToHistory: (events: EventsNode<AI.UIMessageChunk>[], nodes: MessageNode<AI.UIMessage>[]) => MessageNode<AI.UIMessage>[];
|