@teaflask/assistant 0.11.5 → 0.11.6
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/dist/components/use-child-replay-stream.js +33 -18
- package/dist/core/connection-epoch.d.ts +1 -1
- package/dist/core/connection-epoch.js +3 -2
- package/dist/core/conversation-adoption.js +3 -2
- package/dist/core/conversation-send.js +25 -3
- package/dist/core/conversation-store.d.ts +1 -0
- package/dist/core/conversation-store.js +1 -0
- package/dist/transport/load-replay-agent.js +18 -0
- package/package.json +5 -4
|
@@ -7,7 +7,7 @@ import { TailSlotPool } from "../core/tail-slot-pool.js";
|
|
|
7
7
|
import { toolCancelRecorder, withToolCancelAnchored, } from "../core/tool-cancel-anchors.js";
|
|
8
8
|
import { toolErrorRecorder, withToolErrorAnchored, } from "../core/tool-error-anchors.js";
|
|
9
9
|
import { EMPTY_WITHDRAWN_REPLIES, withdrawnReplyRecorder, withoutWithdrawnReplies, withRepliesWithdrawn, } from "../core/withdrawn-anchors.js";
|
|
10
|
-
import {
|
|
10
|
+
import { loadReplayAgent } from "../transport/load-replay-agent.js";
|
|
11
11
|
import { streamUrlForChild } from "../transport/serving-api.js";
|
|
12
12
|
import { resumeMarkerRecorder } from "../transport/stream-resume.js";
|
|
13
13
|
const THREADLESS_ANCHORS = {
|
|
@@ -44,22 +44,37 @@ export function useChildReplayStream({ session, threadId, childSessionId, refres
|
|
|
44
44
|
if (!tailed) {
|
|
45
45
|
return;
|
|
46
46
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
47
|
+
let cancelled = false;
|
|
48
|
+
let close;
|
|
49
|
+
void loadReplayAgent()
|
|
50
|
+
.then((Agent) => {
|
|
51
|
+
if (cancelled)
|
|
52
|
+
return;
|
|
53
|
+
close = openChildReplayStream(Agent, {
|
|
54
|
+
session,
|
|
55
|
+
threadId,
|
|
56
|
+
childSessionId,
|
|
57
|
+
refreshLedger,
|
|
58
|
+
disposedRef,
|
|
59
|
+
setStreamEnd,
|
|
60
|
+
record: {
|
|
61
|
+
setMessages,
|
|
62
|
+
setToolErrors,
|
|
63
|
+
setToolCancels,
|
|
64
|
+
setResumeAnchors,
|
|
65
|
+
setBlockTimings,
|
|
66
|
+
setWithdrawnReplies,
|
|
67
|
+
},
|
|
68
|
+
});
|
|
69
|
+
})
|
|
70
|
+
.catch(() => {
|
|
71
|
+
if (!cancelled)
|
|
72
|
+
setStreamEnd("error");
|
|
62
73
|
});
|
|
74
|
+
return () => {
|
|
75
|
+
cancelled = true;
|
|
76
|
+
close?.();
|
|
77
|
+
};
|
|
63
78
|
}, [session, threadId, childSessionId, tailed, attempt, refreshLedger]);
|
|
64
79
|
const anchors = useMemo(() => ({
|
|
65
80
|
...THREADLESS_ANCHORS,
|
|
@@ -96,8 +111,8 @@ function useChildTailLease(streamEnd) {
|
|
|
96
111
|
const slotDenied = useSyncExternalStore(CHILD_TAIL_SLOTS.subscribe, () => CHILD_TAIL_SLOTS.waiting(leaseId), () => false);
|
|
97
112
|
return { tailed, slotDenied };
|
|
98
113
|
}
|
|
99
|
-
function openChildReplayStream({ session, threadId, childSessionId, refreshLedger, disposedRef, setStreamEnd, record, }) {
|
|
100
|
-
const agent = new
|
|
114
|
+
function openChildReplayStream(Agent, { session, threadId, childSessionId, refreshLedger, disposedRef, setStreamEnd, record, }) {
|
|
115
|
+
const agent = new Agent({
|
|
101
116
|
streamUrl: streamUrlForChild(session, threadId, childSessionId),
|
|
102
117
|
streamThreadId: childSessionId,
|
|
103
118
|
authorizedFetch: session.authorizedFetch,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Message } from "@ag-ui/core";
|
|
2
2
|
import type { AssistantTelemetryEvent } from "../contract/telemetry.js";
|
|
3
|
-
import { ServingReplayStreamAgent } from "../transport/replay-stream-agent.js";
|
|
3
|
+
import type { ServingReplayStreamAgent } from "../transport/replay-stream-agent.js";
|
|
4
4
|
import { type StreamResumeStore } from "../transport/stream-resume.js";
|
|
5
5
|
import type { TokenSession } from "../transport/token-session.js";
|
|
6
6
|
import { type ApprovalInbox, type ApprovalCardModel } from "./approval-inbox.js";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { readyReplayAgent } from "../transport/load-replay-agent.js";
|
|
2
2
|
import { getAssistantThread, resolveTurnToolResults, streamUrlForThread, } from "../transport/serving-api.js";
|
|
3
3
|
import { resumeMarkerRecorder, resumeSnapshotRecorder, } from "../transport/stream-resume.js";
|
|
4
4
|
import { approvalInboxRecorder, } from "./approval-inbox.js";
|
|
@@ -39,7 +39,8 @@ export function markerAnchorsOf(resume) {
|
|
|
39
39
|
};
|
|
40
40
|
}
|
|
41
41
|
export function beginConnectionEpoch(deps) {
|
|
42
|
-
const
|
|
42
|
+
const Agent = readyReplayAgent();
|
|
43
|
+
const agent = new Agent({
|
|
43
44
|
streamUrl: streamUrlForThread(deps.session, deps.threadId),
|
|
44
45
|
streamThreadId: deps.streamThreadId,
|
|
45
46
|
authorizedFetch: deps.session.authorizedFetch,
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { withReplayAgent } from "../transport/load-replay-agent.js";
|
|
1
2
|
import { clearStoredThread, readStoredThread, readStoredThreadFor, writeStoredThread, } from "../persistence/stored-thread.js";
|
|
2
3
|
import { getAssistantThread, listAssistantThreads, } from "../transport/serving-api.js";
|
|
3
4
|
import { noteThreadRead } from "./dispatch-poll.js";
|
|
@@ -30,7 +31,7 @@ export function resumeStoredThreadFromStore(store) {
|
|
|
30
31
|
store._threadOpening = true;
|
|
31
32
|
publishStore(store);
|
|
32
33
|
}
|
|
33
|
-
getAssistantThread(store.deps.session, stored.threadId)
|
|
34
|
+
withReplayAgent(getAssistantThread(store.deps.session, stored.threadId))
|
|
34
35
|
.then((detail) => {
|
|
35
36
|
if (store._resumeRequest === request) {
|
|
36
37
|
_adoptThreadDetail(store, detail);
|
|
@@ -63,7 +64,7 @@ export function openThreadFromStore(store, thread) {
|
|
|
63
64
|
store._threadOpening = true;
|
|
64
65
|
publishStore(store);
|
|
65
66
|
const request = store._resumeRequest;
|
|
66
|
-
getAssistantThread(store.deps.session, thread.id)
|
|
67
|
+
withReplayAgent(getAssistantThread(store.deps.session, thread.id))
|
|
67
68
|
.then((detail) => {
|
|
68
69
|
if (store._resumeRequest !== request) {
|
|
69
70
|
return;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { loadReplayAgent, replayAgentReady, } from "../transport/load-replay-agent.js";
|
|
1
2
|
import { sendAssistantMessage, stopAssistantTurn, } from "../transport/serving-api.js";
|
|
2
3
|
import { ServingApiError } from "../transport/serving-error.js";
|
|
3
4
|
import { enterConversationFromSend } from "./conversation-adoption.js";
|
|
@@ -10,6 +11,7 @@ export async function sendMessageFromStore(store, message, attachmentIds = [], o
|
|
|
10
11
|
store._turnFailure = null;
|
|
11
12
|
store._streamInterrupted = false;
|
|
12
13
|
store._stopping = false;
|
|
14
|
+
const sendId = ++store._sendSequence;
|
|
13
15
|
store._pendingSend = true;
|
|
14
16
|
store._pendingEcho = {
|
|
15
17
|
messageId: `optimistic-user-${String(nextOptimisticMessageId++)}`,
|
|
@@ -18,9 +20,26 @@ export async function sendMessageFromStore(store, message, attachmentIds = [], o
|
|
|
18
20
|
};
|
|
19
21
|
publishStore(store);
|
|
20
22
|
const sentPick = store._modelPick;
|
|
23
|
+
const threadId = store._active?.thread.id;
|
|
24
|
+
const request = store._resumeRequest;
|
|
21
25
|
try {
|
|
26
|
+
if (!replayAgentReady()) {
|
|
27
|
+
const stale = () => store._disposed ||
|
|
28
|
+
request !== store._resumeRequest ||
|
|
29
|
+
sendId !== store._sendSequence;
|
|
30
|
+
try {
|
|
31
|
+
await loadReplayAgent();
|
|
32
|
+
}
|
|
33
|
+
catch (error) {
|
|
34
|
+
if (stale())
|
|
35
|
+
return false;
|
|
36
|
+
throw error;
|
|
37
|
+
}
|
|
38
|
+
if (stale())
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
22
41
|
const response = await sendAssistantMessage(store.deps.session, {
|
|
23
|
-
thread_id:
|
|
42
|
+
thread_id: threadId,
|
|
24
43
|
message,
|
|
25
44
|
attachment_ids: attachmentIds,
|
|
26
45
|
...(sentPick !== null && {
|
|
@@ -52,8 +71,11 @@ export async function sendMessageFromStore(store, message, attachmentIds = [], o
|
|
|
52
71
|
return false;
|
|
53
72
|
}
|
|
54
73
|
finally {
|
|
55
|
-
store.
|
|
56
|
-
|
|
74
|
+
if (sendId === store._sendSequence) {
|
|
75
|
+
store._pendingSend = false;
|
|
76
|
+
if (!store._disposed)
|
|
77
|
+
publishStore(store);
|
|
78
|
+
}
|
|
57
79
|
}
|
|
58
80
|
}
|
|
59
81
|
export function markComposerRefocusHandledFromStore(store) {
|
|
@@ -55,6 +55,7 @@ export declare class AssistantConversationStore {
|
|
|
55
55
|
_reconnectNonce: number;
|
|
56
56
|
_backgroundAttachNonce: number;
|
|
57
57
|
_pendingSend: boolean;
|
|
58
|
+
_sendSequence: number;
|
|
58
59
|
_pendingEcho: ComposerContract["pendingEcho"];
|
|
59
60
|
_composerRefocusPending: boolean;
|
|
60
61
|
_modelPick: ComposerModelPick | null;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
let loaded;
|
|
2
|
+
export async function loadReplayAgent() {
|
|
3
|
+
return (loaded ??= (await import("./replay-stream-agent.js"))
|
|
4
|
+
.ServingReplayStreamAgent);
|
|
5
|
+
}
|
|
6
|
+
export function readyReplayAgent() {
|
|
7
|
+
if (loaded === undefined)
|
|
8
|
+
throw new Error("Replay transport has not been loaded");
|
|
9
|
+
return loaded;
|
|
10
|
+
}
|
|
11
|
+
export function replayAgentReady() {
|
|
12
|
+
return loaded !== undefined;
|
|
13
|
+
}
|
|
14
|
+
export function withReplayAgent(request) {
|
|
15
|
+
return loaded !== undefined
|
|
16
|
+
? request
|
|
17
|
+
: Promise.all([request, loadReplayAgent()]).then(([response]) => response);
|
|
18
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@teaflask/assistant",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.6",
|
|
4
4
|
"description": "The AI assistant for your product: drop it into your React app or any page with a script tag.",
|
|
5
5
|
"license": "FSL-1.1-ALv2",
|
|
6
6
|
"author": "Teaflask",
|
|
@@ -49,8 +49,8 @@
|
|
|
49
49
|
"**/*.css"
|
|
50
50
|
],
|
|
51
51
|
"dependencies": {
|
|
52
|
-
"@ag-ui/client": "1.0.
|
|
53
|
-
"@ag-ui/core": "1.0.
|
|
52
|
+
"@ag-ui/client": "1.0.5",
|
|
53
|
+
"@ag-ui/core": "1.0.5",
|
|
54
54
|
"@shikijs/langs": "^4.4.3",
|
|
55
55
|
"lucide-react": "^1.47.0",
|
|
56
56
|
"marked": "^18.0.13",
|
|
@@ -59,7 +59,8 @@
|
|
|
59
59
|
"remark-gfm": "^4.0.1",
|
|
60
60
|
"rxjs": "7.8.1",
|
|
61
61
|
"shiki": "^4.4.3",
|
|
62
|
-
"use-stick-to-bottom": "^1.1.6"
|
|
62
|
+
"use-stick-to-bottom": "^1.1.6",
|
|
63
|
+
"zod": "^4.6.7"
|
|
63
64
|
},
|
|
64
65
|
"peerDependencies": {
|
|
65
66
|
"react": "^18.3.0 || ^19.0.0",
|