@dudko.dev/agent-web-react 0.0.31 → 0.0.33
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 +35 -8
- package/dist/{chunk-EMF7DTGS.js → chunk-G5GGIMD4.js} +29 -1
- package/dist/chunk-G5GGIMD4.js.map +1 -0
- package/dist/{elicitation-DbW6QKxS.d.cts → elicitation-B6h_-yLg.d.cts} +62 -3
- package/dist/{elicitation-DbW6QKxS.d.ts → elicitation-B6h_-yLg.d.ts} +62 -3
- package/dist/index.cjs +515 -33
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +153 -16
- package/dist/index.d.ts +153 -16
- package/dist/index.js +513 -72
- package/dist/index.js.map +1 -1
- package/dist/mcp.d.cts +2 -2
- package/dist/mcp.d.ts +2 -2
- package/dist/pipeline.cjs.map +1 -1
- package/dist/pipeline.js +1 -1
- package/dist/styles.css +23 -0
- package/package.json +4 -3
- package/dist/chunk-EMF7DTGS.js.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
8
|
var __export = (target, all) => {
|
|
7
9
|
for (var name in all)
|
|
@@ -15,6 +17,14 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
17
|
}
|
|
16
18
|
return to;
|
|
17
19
|
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
18
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
29
|
|
|
20
30
|
// src/index.ts
|
|
@@ -82,6 +92,7 @@ __export(src_exports, {
|
|
|
82
92
|
ModelLoadBar: () => ModelLoadBar,
|
|
83
93
|
PlanView: () => PlanView,
|
|
84
94
|
SandboxedFrame: () => SandboxedFrame,
|
|
95
|
+
SessionBusyError: () => import_agent_web8.SessionBusyError,
|
|
85
96
|
SourceView: () => SourceView,
|
|
86
97
|
StepList: () => StepList,
|
|
87
98
|
SubagentRow: () => SubagentRow,
|
|
@@ -95,6 +106,7 @@ __export(src_exports, {
|
|
|
95
106
|
VfsSkillStore: () => import_agent_web8.VfsSkillStore,
|
|
96
107
|
VirtualFileSystem: () => import_agent_web8.VirtualFileSystem,
|
|
97
108
|
agentStateReducer: () => agentStateReducer,
|
|
109
|
+
agentStatusOf: () => agentStatusOf,
|
|
98
110
|
appDisplayModeAllowed: () => appDisplayModeAllowed,
|
|
99
111
|
appDownloadOf: () => appDownloadOf,
|
|
100
112
|
appDownloadRefusal: () => appDownloadRefusal,
|
|
@@ -150,22 +162,28 @@ __export(src_exports, {
|
|
|
150
162
|
mcpAppSandboxShellCsp: () => mcpAppSandboxShellCsp,
|
|
151
163
|
mcpAppSandboxTarget: () => mcpAppSandboxTarget,
|
|
152
164
|
mediaFamilyOf: () => mediaFamilyOf,
|
|
165
|
+
mergeChatRecord: () => mergeChatRecord,
|
|
153
166
|
mergeLabels: () => mergeLabels,
|
|
154
167
|
newChatId: () => newChatId,
|
|
155
168
|
noticesOf: () => noticesOf,
|
|
169
|
+
onStorageChange: () => import_agent_web8.onStorageChange,
|
|
156
170
|
parseSkillMarkdown: () => import_agent_web8.parseSkillMarkdown,
|
|
157
171
|
parseSlash: () => parseSlash,
|
|
172
|
+
pendingApprovalsOf: () => pendingApprovalsOf,
|
|
173
|
+
postStorageChange: () => import_agent_web8.postStorageChange,
|
|
158
174
|
preloadWebLLMModel: () => import_agent_web8.preloadWebLLMModel,
|
|
159
175
|
resolveAppDownload: () => resolveAppDownload,
|
|
160
176
|
sandboxTokens: () => sandboxTokens,
|
|
161
177
|
sandboxedCsp: () => sandboxedCsp,
|
|
162
178
|
saveAppFile: () => saveAppFile,
|
|
179
|
+
saveChat: () => saveChat,
|
|
163
180
|
serveSubagentWorker: () => import_agent_web8.serveSubagentWorker,
|
|
164
181
|
steerIntent: () => steerIntent,
|
|
165
182
|
subagentTree: () => subagentTree,
|
|
166
183
|
supportsImages: () => import_agent_web8.supportsImages,
|
|
167
184
|
supportsPdf: () => import_agent_web8.supportsPdf,
|
|
168
185
|
tokenizeHtml: () => tokenizeHtml,
|
|
186
|
+
unchangedSince: () => unchangedSince,
|
|
169
187
|
unloadWebLLMModel: () => import_agent_web8.unloadWebLLMModel,
|
|
170
188
|
usageLine: () => usageLine,
|
|
171
189
|
useAgent: () => useAgent,
|
|
@@ -179,6 +197,7 @@ __export(src_exports, {
|
|
|
179
197
|
useSpeechToText: () => useSpeechToText,
|
|
180
198
|
useVirtualFiles: () => useVirtualFiles,
|
|
181
199
|
useWebLLMModel: () => useWebLLMModel,
|
|
200
|
+
watchSession: () => import_agent_web8.watchSession,
|
|
182
201
|
webSearchOf: () => webSearchOf,
|
|
183
202
|
withAttachments: () => withAttachments,
|
|
184
203
|
withCspFirst: () => withCspFirst,
|
|
@@ -188,6 +207,7 @@ module.exports = __toCommonJS(src_exports);
|
|
|
188
207
|
|
|
189
208
|
// src/hooks/use-agent.ts
|
|
190
209
|
var import_react = require("react");
|
|
210
|
+
var core = __toESM(require("@dudko.dev/agent-web"), 1);
|
|
191
211
|
var import_agent_web2 = require("@dudko.dev/agent-web");
|
|
192
212
|
|
|
193
213
|
// src/approval-queue.ts
|
|
@@ -309,6 +329,7 @@ var createInitialAgentState = () => ({
|
|
|
309
329
|
events: [],
|
|
310
330
|
seq: 0
|
|
311
331
|
});
|
|
332
|
+
var BLOCKER_MARK = "[BLOCKER]";
|
|
312
333
|
var resetRun = (state) => ({
|
|
313
334
|
...createInitialAgentState(),
|
|
314
335
|
status: state.status,
|
|
@@ -345,6 +366,7 @@ var addElicitation = (state, event, extra) => state.elicitations?.some((e) => e.
|
|
|
345
366
|
...event.url ? { url: event.url } : {},
|
|
346
367
|
...extra.stepId ? { stepId: extra.stepId } : {},
|
|
347
368
|
...extra.subagent ? { subagent: extra.subagent } : {},
|
|
369
|
+
...extra.remote ? { remote: true } : {},
|
|
348
370
|
status: "pending"
|
|
349
371
|
}
|
|
350
372
|
]
|
|
@@ -561,6 +583,7 @@ var applySubagent = (state, event, ancestors, ctx) => {
|
|
|
561
583
|
...node?.role ? { role: node.role } : {}
|
|
562
584
|
},
|
|
563
585
|
...inner.skill ? { skill: inner.skill } : {},
|
|
586
|
+
...ctx.remote ? { remote: true } : {},
|
|
564
587
|
status: "pending"
|
|
565
588
|
}
|
|
566
589
|
]
|
|
@@ -585,6 +608,7 @@ var applySubagent = (state, event, ancestors, ctx) => {
|
|
|
585
608
|
case "mcp.elicitation-requested": {
|
|
586
609
|
const node = inner.subagent ? known.subagents.find((s) => s.id === inner.subagent.id) : void 0;
|
|
587
610
|
return addElicitation(known, inner, {
|
|
611
|
+
...ctx.remote ? { remote: true } : {},
|
|
588
612
|
// The subagent's own step ids mean nothing here: the step that delegated it does.
|
|
589
613
|
stepId: (node ?? known.subagents.find((s) => s.id === event.id))?.stepId,
|
|
590
614
|
...inner.subagent ? {
|
|
@@ -623,6 +647,7 @@ var applySubagent = (state, event, ancestors, ctx) => {
|
|
|
623
647
|
return fileDeleted(known, inner.path);
|
|
624
648
|
// An app a subagent's call came with is shown in the turn too, and says whose call it was.
|
|
625
649
|
case "mcp.app": {
|
|
650
|
+
if (ctx.remote) return known;
|
|
626
651
|
const node = known.subagents.find((s) => s.id === event.id);
|
|
627
652
|
return addApp(known, inner, {
|
|
628
653
|
id: event.id,
|
|
@@ -714,14 +739,37 @@ var streamAssistant = (messages, content) => {
|
|
|
714
739
|
}
|
|
715
740
|
return messages;
|
|
716
741
|
};
|
|
742
|
+
var WAITING_ID = "waiting-for-session";
|
|
743
|
+
var withoutBusy = (state) => {
|
|
744
|
+
if (!state.sessionBusy) return state;
|
|
745
|
+
const { sessionBusy: _over, ...rest } = state;
|
|
746
|
+
void _over;
|
|
747
|
+
return { ...rest, queued: rest.queued.filter((q) => q.id !== WAITING_ID) };
|
|
748
|
+
};
|
|
749
|
+
var withoutSubmitted = (state) => {
|
|
750
|
+
if (!state.submitted) return state;
|
|
751
|
+
const { submitted, ...rest } = state;
|
|
752
|
+
const ids = /* @__PURE__ */ new Set([submitted.userId, submitted.assistantId]);
|
|
753
|
+
return { ...rest, messages: rest.messages.filter((m) => !ids.has(m.id)) };
|
|
754
|
+
};
|
|
755
|
+
var keepSubmitted = (state) => {
|
|
756
|
+
if (!state.submitted) return state;
|
|
757
|
+
const { submitted: _kept, ...rest } = state;
|
|
758
|
+
void _kept;
|
|
759
|
+
return rest;
|
|
760
|
+
};
|
|
717
761
|
var applyEvent = (state, event, ctx) => {
|
|
718
762
|
switch (event.type) {
|
|
719
763
|
case "run.start": {
|
|
720
|
-
const base2 = resetRun(state);
|
|
764
|
+
const base2 = resetRun(ctx.remote ? state : withoutSubmitted(state));
|
|
721
765
|
const userId = `msg-${base2.seq}`;
|
|
722
766
|
const assistantId = `msg-${base2.seq + 1}`;
|
|
723
767
|
return {
|
|
724
768
|
...base2,
|
|
769
|
+
// Another tab's run keeps the view of it; a run of this tab's ends it (and any wait).
|
|
770
|
+
...ctx.remote && state.remote ? { remote: state.remote } : {},
|
|
771
|
+
// ...and this tab's sent turn, still waiting for its own run.start (or a session.busy).
|
|
772
|
+
...ctx.remote && state.submitted ? { submitted: state.submitted } : {},
|
|
725
773
|
goal: event.goal,
|
|
726
774
|
runStartedAt: ctx.at,
|
|
727
775
|
runMessageId: assistantId,
|
|
@@ -732,9 +780,16 @@ var applyEvent = (state, event, ctx) => {
|
|
|
732
780
|
role: "user",
|
|
733
781
|
content: event.goal,
|
|
734
782
|
pending: false,
|
|
783
|
+
...ctx.remote ? { remote: true } : {},
|
|
735
784
|
...ctx.attachments?.length ? { attachments: ctx.attachments } : {}
|
|
736
785
|
},
|
|
737
|
-
{
|
|
786
|
+
{
|
|
787
|
+
id: assistantId,
|
|
788
|
+
role: "assistant",
|
|
789
|
+
content: "",
|
|
790
|
+
pending: true,
|
|
791
|
+
...ctx.remote ? { remote: true } : {}
|
|
792
|
+
}
|
|
738
793
|
],
|
|
739
794
|
seq: base2.seq + 2
|
|
740
795
|
};
|
|
@@ -816,7 +871,13 @@ var applyEvent = (state, event, ctx) => {
|
|
|
816
871
|
case "step.text-delta":
|
|
817
872
|
return {
|
|
818
873
|
...state,
|
|
819
|
-
|
|
874
|
+
// "[BLOCKER]" is the executor's signal to the core that a step cannot be completed (the
|
|
875
|
+
// core strips it from the step's summary): never a word for the user. Stripped from the
|
|
876
|
+
// text as it accumulates, so a marker split across two deltas goes too.
|
|
877
|
+
steps: patchStep(state.steps, event.step.id, (s) => ({
|
|
878
|
+
...s,
|
|
879
|
+
text: (s.text + event.delta).split(BLOCKER_MARK).join("")
|
|
880
|
+
}))
|
|
820
881
|
};
|
|
821
882
|
case "step.tool-call": {
|
|
822
883
|
const tagged = new Set(
|
|
@@ -968,9 +1029,15 @@ var applyEvent = (state, event, ctx) => {
|
|
|
968
1029
|
case "file.deleted":
|
|
969
1030
|
return fileDeleted(state, event.path);
|
|
970
1031
|
case "mcp.app":
|
|
971
|
-
return addApp(state, event);
|
|
1032
|
+
return ctx.remote ? state : addApp(state, event);
|
|
972
1033
|
case "message.queued":
|
|
973
|
-
return state.queued.some((q) => q.id === event.id) ? state : {
|
|
1034
|
+
return state.queued.some((q) => q.id === event.id) ? state : {
|
|
1035
|
+
...state,
|
|
1036
|
+
queued: [
|
|
1037
|
+
...state.queued,
|
|
1038
|
+
{ id: event.id, text: event.text, ...event.origin ? { origin: event.origin } : {} }
|
|
1039
|
+
]
|
|
1040
|
+
};
|
|
974
1041
|
case "message.delivered": {
|
|
975
1042
|
const anchor = event.at === "round" ? runningStepId(state.steps) : event.at === "step" ? state.steps[state.steps.length - 1]?.id : void 0;
|
|
976
1043
|
return {
|
|
@@ -978,7 +1045,13 @@ var applyEvent = (state, event, ctx) => {
|
|
|
978
1045
|
queued: state.queued.filter((q) => q.id !== event.id),
|
|
979
1046
|
notes: [
|
|
980
1047
|
...state.notes,
|
|
981
|
-
{
|
|
1048
|
+
{
|
|
1049
|
+
id: event.id,
|
|
1050
|
+
text: event.text,
|
|
1051
|
+
at: event.at,
|
|
1052
|
+
...anchor ? { stepId: anchor } : {},
|
|
1053
|
+
...event.origin ? { origin: event.origin } : {}
|
|
1054
|
+
}
|
|
982
1055
|
]
|
|
983
1056
|
};
|
|
984
1057
|
}
|
|
@@ -1005,6 +1078,8 @@ var applyEvent = (state, event, ctx) => {
|
|
|
1005
1078
|
};
|
|
1006
1079
|
case "mcp.elicitation-requested":
|
|
1007
1080
|
return addElicitation(state, event, {
|
|
1081
|
+
// Asked in the tab that runs the tool call: shown here, answered there.
|
|
1082
|
+
...ctx.remote ? { remote: true } : {},
|
|
1008
1083
|
stepId: event.step?.id,
|
|
1009
1084
|
...event.subagent ? { subagent: event.subagent } : {}
|
|
1010
1085
|
});
|
|
@@ -1024,6 +1099,8 @@ var applyEvent = (state, event, ctx) => {
|
|
|
1024
1099
|
...event.subagent ? { subagent: event.subagent } : {},
|
|
1025
1100
|
...event.app ? { app: event.app } : {},
|
|
1026
1101
|
...event.skill ? { skill: event.skill } : {},
|
|
1102
|
+
// Asked in the tab that runs the tool: shown here, answered there.
|
|
1103
|
+
...ctx.remote ? { remote: true } : {},
|
|
1027
1104
|
status: "pending"
|
|
1028
1105
|
}
|
|
1029
1106
|
]
|
|
@@ -1108,9 +1185,26 @@ var applyEvent = (state, event, ctx) => {
|
|
|
1108
1185
|
};
|
|
1109
1186
|
case "budget.exceeded":
|
|
1110
1187
|
return { ...state, budget: { kind: event.kind, tokens: event.tokens, cap: event.cap } };
|
|
1111
|
-
case "
|
|
1188
|
+
case "session.busy":
|
|
1189
|
+
state = withoutSubmitted(state);
|
|
1112
1190
|
return {
|
|
1113
1191
|
...state,
|
|
1192
|
+
sessionBusy: { heldBy: event.heldBy, ...ctx.goal ? { goal: ctx.goal } : {} },
|
|
1193
|
+
// What the user sent waits with the run: shown as queued, not lost.
|
|
1194
|
+
...ctx.goal ? {
|
|
1195
|
+
queued: [
|
|
1196
|
+
...state.queued.filter((q) => q.id !== WAITING_ID),
|
|
1197
|
+
{ id: WAITING_ID, text: ctx.goal }
|
|
1198
|
+
]
|
|
1199
|
+
} : {}
|
|
1200
|
+
};
|
|
1201
|
+
case "session.acquired":
|
|
1202
|
+
return withoutBusy(state);
|
|
1203
|
+
case "stopped":
|
|
1204
|
+
if (!ctx.remote && state.sessionBusy) return withoutBusy(state);
|
|
1205
|
+
if (!ctx.remote && state.submitted) return withoutSubmitted(state);
|
|
1206
|
+
return {
|
|
1207
|
+
...withoutBusy(state),
|
|
1114
1208
|
stopped: true,
|
|
1115
1209
|
// Nothing of the run is waiting any more once it has stopped (an app's request is not
|
|
1116
1210
|
// the run's).
|
|
@@ -1136,8 +1230,9 @@ var applyEvent = (state, event, ctx) => {
|
|
|
1136
1230
|
};
|
|
1137
1231
|
}
|
|
1138
1232
|
return event.phase === "run" ? {
|
|
1139
|
-
...state,
|
|
1233
|
+
...withoutBusy(keepSubmitted(state)),
|
|
1140
1234
|
error: event.error,
|
|
1235
|
+
errorCode: event.code,
|
|
1141
1236
|
messages: finalizeAssistant(
|
|
1142
1237
|
state.messages,
|
|
1143
1238
|
state.finalText || `Error: ${event.error}`,
|
|
@@ -1181,6 +1276,8 @@ var syncRunMessage = (state) => {
|
|
|
1181
1276
|
messages[i] = { ...m, ...patch };
|
|
1182
1277
|
return { ...state, messages };
|
|
1183
1278
|
};
|
|
1279
|
+
var pendingApprovalsOf = (state) => state.approvals.filter((a) => a.status === "pending" && !a.remote);
|
|
1280
|
+
var agentStatusOf = (state) => state.remote?.running && (state.status === "ready" || state.status === "idle") ? "running" : state.status;
|
|
1184
1281
|
var agentStateReducer = (state, action) => {
|
|
1185
1282
|
switch (action.type) {
|
|
1186
1283
|
case "reset":
|
|
@@ -1192,22 +1289,69 @@ var agentStateReducer = (state, action) => {
|
|
|
1192
1289
|
};
|
|
1193
1290
|
case "notebook":
|
|
1194
1291
|
return { ...state, learned: action.lessons };
|
|
1292
|
+
case "submitted": {
|
|
1293
|
+
if (state.submitted) return state;
|
|
1294
|
+
const userId = `msg-${state.seq}`;
|
|
1295
|
+
const assistantId = `msg-${state.seq + 1}`;
|
|
1296
|
+
return {
|
|
1297
|
+
...state,
|
|
1298
|
+
submitted: { userId, assistantId },
|
|
1299
|
+
messages: [
|
|
1300
|
+
...state.messages,
|
|
1301
|
+
{
|
|
1302
|
+
id: userId,
|
|
1303
|
+
role: "user",
|
|
1304
|
+
content: action.goal,
|
|
1305
|
+
pending: false,
|
|
1306
|
+
...action.attachments?.length ? { attachments: action.attachments } : {}
|
|
1307
|
+
},
|
|
1308
|
+
{ id: assistantId, role: "assistant", content: "", pending: true }
|
|
1309
|
+
],
|
|
1310
|
+
seq: state.seq + 2
|
|
1311
|
+
};
|
|
1312
|
+
}
|
|
1195
1313
|
case "status":
|
|
1196
1314
|
return {
|
|
1197
1315
|
...state,
|
|
1198
1316
|
status: action.status,
|
|
1199
|
-
error: action.status === "error" ? action.error : void 0
|
|
1317
|
+
error: action.status === "error" ? action.error : void 0,
|
|
1318
|
+
errorCode: void 0
|
|
1200
1319
|
};
|
|
1320
|
+
case "remote": {
|
|
1321
|
+
const remote = action.remote;
|
|
1322
|
+
if (!remote) {
|
|
1323
|
+
const { remote: _gone, ...rest } = state;
|
|
1324
|
+
void _gone;
|
|
1325
|
+
return rest;
|
|
1326
|
+
}
|
|
1327
|
+
if (remote.ended === "gone" && state.remote?.running) {
|
|
1328
|
+
return syncRunMessage({
|
|
1329
|
+
...state,
|
|
1330
|
+
remote,
|
|
1331
|
+
messages: finalizeAssistant(state.messages, state.finalText, { error: true })
|
|
1332
|
+
});
|
|
1333
|
+
}
|
|
1334
|
+
return { ...state, remote };
|
|
1335
|
+
}
|
|
1201
1336
|
case "event": {
|
|
1202
1337
|
const next = syncRunMessage(
|
|
1203
|
-
applyEvent(state, action.event, {
|
|
1338
|
+
applyEvent(state, action.event, {
|
|
1339
|
+
at: action.at,
|
|
1340
|
+
attachments: action.attachments,
|
|
1341
|
+
...action.remote ? { remote: true } : {},
|
|
1342
|
+
...action.goal ? { goal: action.goal } : {}
|
|
1343
|
+
})
|
|
1204
1344
|
);
|
|
1205
1345
|
const cap = action.maxEvents ?? 200;
|
|
1206
1346
|
const events = cap > 0 ? [...state.events, action.event].slice(-cap) : [...state.events, action.event];
|
|
1207
1347
|
return { ...next, events };
|
|
1208
1348
|
}
|
|
1209
1349
|
case "undelivered":
|
|
1210
|
-
return {
|
|
1350
|
+
return {
|
|
1351
|
+
...state,
|
|
1352
|
+
queued: action.keepQueued ? state.queued : [],
|
|
1353
|
+
undelivered: action.texts
|
|
1354
|
+
};
|
|
1211
1355
|
case "load": {
|
|
1212
1356
|
const maxSeq = action.messages.reduce((n, m) => {
|
|
1213
1357
|
const k = Number(/^msg-(\d+)$/.exec(m.id)?.[1] ?? -1);
|
|
@@ -1229,8 +1373,39 @@ var agentStateReducer = (state, action) => {
|
|
|
1229
1373
|
|
|
1230
1374
|
// src/util.ts
|
|
1231
1375
|
var errMessage = (err) => err instanceof Error ? err.message : String(err);
|
|
1376
|
+
var coalesce = (fn, ms = 100) => {
|
|
1377
|
+
let timer;
|
|
1378
|
+
return {
|
|
1379
|
+
call: () => {
|
|
1380
|
+
if (timer !== void 0) clearTimeout(timer);
|
|
1381
|
+
timer = setTimeout(() => {
|
|
1382
|
+
timer = void 0;
|
|
1383
|
+
fn();
|
|
1384
|
+
}, ms);
|
|
1385
|
+
},
|
|
1386
|
+
cancel: () => {
|
|
1387
|
+
if (timer !== void 0) clearTimeout(timer);
|
|
1388
|
+
timer = void 0;
|
|
1389
|
+
}
|
|
1390
|
+
};
|
|
1391
|
+
};
|
|
1392
|
+
var listenToOtherTabs = (core6, dbName, listener) => typeof core6.onStorageChange === "function" && dbName ? core6.onStorageChange(dbName, listener) : () => void 0;
|
|
1393
|
+
var followOtherTabs = (core6, dbName, accept, settle, ms = 100) => {
|
|
1394
|
+
const later = coalesce(settle, ms);
|
|
1395
|
+
const off = listenToOtherTabs(core6, dbName, (change) => {
|
|
1396
|
+
if (accept(change)) later.call();
|
|
1397
|
+
});
|
|
1398
|
+
return () => {
|
|
1399
|
+
off();
|
|
1400
|
+
later.cancel();
|
|
1401
|
+
};
|
|
1402
|
+
};
|
|
1232
1403
|
|
|
1233
1404
|
// src/hooks/use-agent.ts
|
|
1405
|
+
var dbNameOf = (store) => {
|
|
1406
|
+
const name = store?.dbName;
|
|
1407
|
+
return typeof name === "string" && name ? name : void 0;
|
|
1408
|
+
};
|
|
1234
1409
|
var useAgent = (config, options = {}) => {
|
|
1235
1410
|
const [state, dispatch] = (0, import_react.useReducer)(agentStateReducer, void 0, createInitialAgentState);
|
|
1236
1411
|
const agentRef = (0, import_react.useRef)(void 0);
|
|
@@ -1303,6 +1478,57 @@ var useAgent = (config, options = {}) => {
|
|
|
1303
1478
|
cancelled = true;
|
|
1304
1479
|
};
|
|
1305
1480
|
}, [generation, autoStart, ...deps ?? []]);
|
|
1481
|
+
const watchRef = (0, import_react.useRef)(void 0);
|
|
1482
|
+
const startedRef = (0, import_react.useRef)(false);
|
|
1483
|
+
const watchDb = options.watch !== false && config.sessionLock !== "off" ? dbNameOf(config.memory) : void 0;
|
|
1484
|
+
(0, import_react.useEffect)(() => {
|
|
1485
|
+
const watchSession3 = core.watchSession;
|
|
1486
|
+
if (!watchDb || typeof watchSession3 !== "function") return;
|
|
1487
|
+
const watch = watchSession3({
|
|
1488
|
+
dbName: watchDb,
|
|
1489
|
+
sessionId,
|
|
1490
|
+
onEvent: (event) => {
|
|
1491
|
+
if (startedRef.current) return;
|
|
1492
|
+
dispatch({
|
|
1493
|
+
type: "event",
|
|
1494
|
+
event,
|
|
1495
|
+
remote: true,
|
|
1496
|
+
maxEvents: optionsRef.current.maxEvents,
|
|
1497
|
+
at: Date.now()
|
|
1498
|
+
});
|
|
1499
|
+
},
|
|
1500
|
+
onState: (s) => {
|
|
1501
|
+
if (startedRef.current && s.running) return;
|
|
1502
|
+
dispatch({
|
|
1503
|
+
type: "remote",
|
|
1504
|
+
remote: {
|
|
1505
|
+
running: s.running,
|
|
1506
|
+
...s.runId ? { runId: s.runId } : {},
|
|
1507
|
+
...s.ended ? { ended: s.ended } : {}
|
|
1508
|
+
}
|
|
1509
|
+
});
|
|
1510
|
+
}
|
|
1511
|
+
});
|
|
1512
|
+
watchRef.current = watch;
|
|
1513
|
+
return () => {
|
|
1514
|
+
watch.close();
|
|
1515
|
+
if (watchRef.current === watch) watchRef.current = void 0;
|
|
1516
|
+
};
|
|
1517
|
+
}, [watchDb, sessionId]);
|
|
1518
|
+
const skillsDb = dbNameOf(typeof config.learning === "object" ? config.learning.store : void 0);
|
|
1519
|
+
(0, import_react.useEffect)(() => {
|
|
1520
|
+
return followOtherTabs(
|
|
1521
|
+
core,
|
|
1522
|
+
skillsDb,
|
|
1523
|
+
(change) => change.kind === "skills",
|
|
1524
|
+
() => {
|
|
1525
|
+
const agent = agentRef.current;
|
|
1526
|
+
if (!agent || typeof agent.reloadLearnedSkills !== "function") return;
|
|
1527
|
+
void agent.reloadLearnedSkills().then((skills) => dispatch({ type: "notebook", lessons: lessonsOf(skills) })).catch(() => {
|
|
1528
|
+
});
|
|
1529
|
+
}
|
|
1530
|
+
);
|
|
1531
|
+
}, [skillsDb]);
|
|
1306
1532
|
(0, import_react.useEffect)(
|
|
1307
1533
|
() => () => {
|
|
1308
1534
|
abortRef.current?.abort();
|
|
@@ -1321,7 +1547,17 @@ var useAgent = (config, options = {}) => {
|
|
|
1321
1547
|
const control = (0, import_agent_web2.createRunControl)();
|
|
1322
1548
|
controlRef.current = control;
|
|
1323
1549
|
let left = [];
|
|
1550
|
+
let stopped = false;
|
|
1551
|
+
let began = false;
|
|
1552
|
+
const shownGoal = runOptions?.label ?? goal;
|
|
1324
1553
|
dispatch({ type: "status", status: "running" });
|
|
1554
|
+
if (shownGoal.trim()) {
|
|
1555
|
+
dispatch({
|
|
1556
|
+
type: "submitted",
|
|
1557
|
+
goal: shownGoal,
|
|
1558
|
+
...runOptions?.attachments?.length ? { attachments: runOptions.attachments } : {}
|
|
1559
|
+
});
|
|
1560
|
+
}
|
|
1325
1561
|
try {
|
|
1326
1562
|
const result = await agent.run(goal, {
|
|
1327
1563
|
signal: controller.signal,
|
|
@@ -1331,12 +1567,18 @@ var useAgent = (config, options = {}) => {
|
|
|
1331
1567
|
...runOptions?.files?.length ? { files: runOptions.files } : {},
|
|
1332
1568
|
onEvent: (event) => {
|
|
1333
1569
|
const start = event.type === "run.start";
|
|
1570
|
+
if (start) {
|
|
1571
|
+
startedRef.current = true;
|
|
1572
|
+
began = true;
|
|
1573
|
+
}
|
|
1334
1574
|
const shown = start && runOptions?.label ? { ...event, goal: runOptions.label } : event;
|
|
1335
1575
|
dispatch({
|
|
1336
1576
|
type: "event",
|
|
1337
1577
|
event: shown,
|
|
1338
1578
|
maxEvents: optionsRef.current.maxEvents,
|
|
1339
1579
|
at: Date.now(),
|
|
1580
|
+
// What the user sent waits with the run: shown as queued meanwhile.
|
|
1581
|
+
...event.type === "session.busy" && shownGoal.trim() ? { goal: shownGoal } : {},
|
|
1340
1582
|
...start && runOptions?.attachments?.length ? { attachments: runOptions.attachments } : {}
|
|
1341
1583
|
});
|
|
1342
1584
|
try {
|
|
@@ -1346,6 +1588,7 @@ var useAgent = (config, options = {}) => {
|
|
|
1346
1588
|
}
|
|
1347
1589
|
});
|
|
1348
1590
|
left = result.undelivered ?? [];
|
|
1591
|
+
stopped = result.stopped;
|
|
1349
1592
|
return result;
|
|
1350
1593
|
} catch (err) {
|
|
1351
1594
|
left = control.pending();
|
|
@@ -1357,11 +1600,13 @@ var useAgent = (config, options = {}) => {
|
|
|
1357
1600
|
return void 0;
|
|
1358
1601
|
} finally {
|
|
1359
1602
|
abortRef.current = void 0;
|
|
1603
|
+
startedRef.current = false;
|
|
1360
1604
|
controlRef.current = void 0;
|
|
1361
1605
|
settleAll({ approved: false, reason: "the run ended" });
|
|
1362
1606
|
dispatch({ type: "status", ...buildStatusRef.current });
|
|
1607
|
+
if (stopped && !began && shownGoal.trim()) left = [shownGoal, ...left];
|
|
1363
1608
|
if (left.length > 0) {
|
|
1364
|
-
if (!controller.signal.aborted && optionsRef.current.followUp !== false) {
|
|
1609
|
+
if (!controller.signal.aborted && !stopped && optionsRef.current.followUp !== false) {
|
|
1365
1610
|
dispatch({ type: "undelivered", texts: [] });
|
|
1366
1611
|
void runRef.current?.(left.join("\n\n"));
|
|
1367
1612
|
} else {
|
|
@@ -1376,6 +1621,24 @@ var useAgent = (config, options = {}) => {
|
|
|
1376
1621
|
);
|
|
1377
1622
|
runRef.current = run;
|
|
1378
1623
|
const send = (0, import_react.useCallback)((text2) => controlRef.current?.send(text2) ?? false, []);
|
|
1624
|
+
const sendRemote = (0, import_react.useCallback)((text2) => {
|
|
1625
|
+
const watch = watchRef.current;
|
|
1626
|
+
const clean = typeof text2 === "string" ? text2.trim() : "";
|
|
1627
|
+
if (!watch?.state.running || !clean) return false;
|
|
1628
|
+
void watch.send(clean).then((ok) => {
|
|
1629
|
+
if (!ok) {
|
|
1630
|
+
dispatch({
|
|
1631
|
+
type: "undelivered",
|
|
1632
|
+
texts: [...stateRef.current.undelivered, clean],
|
|
1633
|
+
keepQueued: true
|
|
1634
|
+
});
|
|
1635
|
+
}
|
|
1636
|
+
});
|
|
1637
|
+
return true;
|
|
1638
|
+
}, []);
|
|
1639
|
+
const stopRemote = (0, import_react.useCallback)(() => {
|
|
1640
|
+
if (watchRef.current?.state.running) void watchRef.current.stop();
|
|
1641
|
+
}, []);
|
|
1379
1642
|
const stopSubagent = (0, import_react.useCallback)(
|
|
1380
1643
|
(id) => controlRef.current?.stopSubagent(id) ?? false,
|
|
1381
1644
|
[]
|
|
@@ -1492,11 +1755,16 @@ var useAgent = (config, options = {}) => {
|
|
|
1492
1755
|
}
|
|
1493
1756
|
return result;
|
|
1494
1757
|
}, []);
|
|
1758
|
+
const remoteRunning = state.remote?.running === true;
|
|
1495
1759
|
return {
|
|
1496
1760
|
...state,
|
|
1761
|
+
// `running` over ready / idle only: a build in progress or an error stays visible.
|
|
1762
|
+
status: agentStatusOf(state),
|
|
1497
1763
|
run,
|
|
1498
1764
|
stop,
|
|
1765
|
+
stopRemote,
|
|
1499
1766
|
send,
|
|
1767
|
+
sendRemote,
|
|
1500
1768
|
stopSubagent,
|
|
1501
1769
|
forgetSkill,
|
|
1502
1770
|
sendUndelivered,
|
|
@@ -1504,9 +1772,10 @@ var useAgent = (config, options = {}) => {
|
|
|
1504
1772
|
reset,
|
|
1505
1773
|
reload,
|
|
1506
1774
|
agent: agentRef.current,
|
|
1507
|
-
isRunning: state.status === "running",
|
|
1508
|
-
isReady: state.status === "ready",
|
|
1509
|
-
|
|
1775
|
+
isRunning: state.status === "running" || remoteRunning,
|
|
1776
|
+
isReady: state.status === "ready" && !remoteRunning,
|
|
1777
|
+
// Another tab's consent requests are answered there, never here.
|
|
1778
|
+
pendingApprovals: pendingApprovalsOf(state),
|
|
1510
1779
|
approve,
|
|
1511
1780
|
deny,
|
|
1512
1781
|
approvalMode,
|
|
@@ -1521,26 +1790,36 @@ var useAgent = (config, options = {}) => {
|
|
|
1521
1790
|
|
|
1522
1791
|
// src/hooks/use-chat-history.ts
|
|
1523
1792
|
var import_react2 = require("react");
|
|
1793
|
+
var core3 = __toESM(require("@dudko.dev/agent-web"), 1);
|
|
1524
1794
|
|
|
1525
1795
|
// src/chat-history.ts
|
|
1796
|
+
var core2 = __toESM(require("@dudko.dev/agent-web"), 1);
|
|
1526
1797
|
var DB_VERSION = 1;
|
|
1527
1798
|
var req = (r) => new Promise((resolve, reject) => {
|
|
1528
1799
|
r.onsuccess = () => resolve(r.result);
|
|
1529
1800
|
r.onerror = () => reject(r.error);
|
|
1530
1801
|
});
|
|
1802
|
+
var committed = (tx, r) => new Promise((resolve, reject) => {
|
|
1803
|
+
tx.oncomplete = () => resolve();
|
|
1804
|
+
tx.onabort = () => reject(tx.error ?? r.error ?? new Error("the transaction was aborted"));
|
|
1805
|
+
tx.onerror = () => reject(tx.error ?? r.error);
|
|
1806
|
+
});
|
|
1531
1807
|
var ChatHistoryStore = class {
|
|
1808
|
+
/** The IndexedDB database (undefined in memory): the name its `chats` notices go out under. */
|
|
1532
1809
|
dbName;
|
|
1810
|
+
name;
|
|
1533
1811
|
storeName;
|
|
1534
1812
|
memory;
|
|
1535
1813
|
db;
|
|
1536
1814
|
constructor(opts = {}) {
|
|
1537
|
-
this.
|
|
1815
|
+
this.name = opts.dbName ?? "agent-web-react";
|
|
1538
1816
|
this.storeName = opts.storeName ?? "chats";
|
|
1539
1817
|
if (opts.memory || typeof indexedDB === "undefined") this.memory = /* @__PURE__ */ new Map();
|
|
1818
|
+
this.dbName = this.memory ? void 0 : this.name;
|
|
1540
1819
|
}
|
|
1541
1820
|
open() {
|
|
1542
1821
|
this.db ??= new Promise((resolve, reject) => {
|
|
1543
|
-
const r = indexedDB.open(this.
|
|
1822
|
+
const r = indexedDB.open(this.name, DB_VERSION);
|
|
1544
1823
|
r.onupgradeneeded = () => {
|
|
1545
1824
|
if (!r.result.objectStoreNames.contains(this.storeName)) {
|
|
1546
1825
|
r.result.createObjectStore(this.storeName, { keyPath: "id" });
|
|
@@ -1558,6 +1837,54 @@ var ChatHistoryStore = class {
|
|
|
1558
1837
|
const db = await this.open();
|
|
1559
1838
|
return db.transaction(this.storeName, mode).objectStore(this.storeName);
|
|
1560
1839
|
}
|
|
1840
|
+
/** One write in its own transaction, resolved once it committed - then the notice. */
|
|
1841
|
+
async write(op, notice) {
|
|
1842
|
+
const db = await this.open();
|
|
1843
|
+
const tx = db.transaction(this.storeName, "readwrite");
|
|
1844
|
+
await committed(tx, op(tx.objectStore(this.storeName)));
|
|
1845
|
+
this.announce(notice);
|
|
1846
|
+
}
|
|
1847
|
+
announce(notice) {
|
|
1848
|
+
if (typeof core2.postStorageChange === "function") {
|
|
1849
|
+
core2.postStorageChange(this.dbName, { kind: "chats", ...notice });
|
|
1850
|
+
}
|
|
1851
|
+
}
|
|
1852
|
+
/**
|
|
1853
|
+
* Read the stored record and write what `merge` makes of it in ONE readwrite transaction: no
|
|
1854
|
+
* other tab's save can land between the read and the write. `merge` is synchronous (a
|
|
1855
|
+
* transaction does not survive an await). Resolves with what was written, once committed.
|
|
1856
|
+
*/
|
|
1857
|
+
async putMerged(id, merge) {
|
|
1858
|
+
if (this.memory) {
|
|
1859
|
+
const record = merge(this.memory.get(id));
|
|
1860
|
+
this.memory.set(record.id, structuredClone(record));
|
|
1861
|
+
return record;
|
|
1862
|
+
}
|
|
1863
|
+
const db = await this.open();
|
|
1864
|
+
const tx = db.transaction(this.storeName, "readwrite");
|
|
1865
|
+
const store = tx.objectStore(this.storeName);
|
|
1866
|
+
let written;
|
|
1867
|
+
let failed;
|
|
1868
|
+
const read = store.get(id);
|
|
1869
|
+
const done = committed(tx, read);
|
|
1870
|
+
read.onsuccess = () => {
|
|
1871
|
+
try {
|
|
1872
|
+
written = merge(read.result);
|
|
1873
|
+
store.put(written);
|
|
1874
|
+
} catch (err) {
|
|
1875
|
+
failed = err;
|
|
1876
|
+
tx.abort();
|
|
1877
|
+
}
|
|
1878
|
+
};
|
|
1879
|
+
try {
|
|
1880
|
+
await done;
|
|
1881
|
+
} catch (err) {
|
|
1882
|
+
throw failed ?? err;
|
|
1883
|
+
}
|
|
1884
|
+
if (!written) throw new Error("the chat could not be saved");
|
|
1885
|
+
this.announce({ op: "put", key: id });
|
|
1886
|
+
return written;
|
|
1887
|
+
}
|
|
1561
1888
|
async list() {
|
|
1562
1889
|
const all = this.memory ? [...this.memory.values()] : await req((await this.tx("readonly")).getAll());
|
|
1563
1890
|
return all.map(({ messages, ...rest }) => ({ ...rest, messageCount: messages.length })).sort((a, b) => b.updatedAt - a.updatedAt);
|
|
@@ -1571,21 +1898,21 @@ var ChatHistoryStore = class {
|
|
|
1571
1898
|
this.memory.set(record.id, structuredClone(record));
|
|
1572
1899
|
return;
|
|
1573
1900
|
}
|
|
1574
|
-
await
|
|
1901
|
+
await this.write((store) => store.put(record), { op: "put", key: record.id });
|
|
1575
1902
|
}
|
|
1576
1903
|
async delete(id) {
|
|
1577
1904
|
if (this.memory) {
|
|
1578
1905
|
this.memory.delete(id);
|
|
1579
1906
|
return;
|
|
1580
1907
|
}
|
|
1581
|
-
await
|
|
1908
|
+
await this.write((store) => store.delete(id), { op: "delete", key: id });
|
|
1582
1909
|
}
|
|
1583
1910
|
async clear() {
|
|
1584
1911
|
if (this.memory) {
|
|
1585
1912
|
this.memory.clear();
|
|
1586
1913
|
return;
|
|
1587
1914
|
}
|
|
1588
|
-
await
|
|
1915
|
+
await this.write((store) => store.clear(), { op: "clear" });
|
|
1589
1916
|
}
|
|
1590
1917
|
};
|
|
1591
1918
|
var chatTitle = (messages) => {
|
|
@@ -1596,6 +1923,61 @@ var chatTitle = (messages) => {
|
|
|
1596
1923
|
var newChatId = () => `chat-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}`;
|
|
1597
1924
|
|
|
1598
1925
|
// src/hooks/use-chat-history.ts
|
|
1926
|
+
var USAGE_KEYS = [
|
|
1927
|
+
"inputTokens",
|
|
1928
|
+
"outputTokens",
|
|
1929
|
+
"totalTokens",
|
|
1930
|
+
"reasoningTokens",
|
|
1931
|
+
"cachedInputTokens",
|
|
1932
|
+
"cacheWriteTokens"
|
|
1933
|
+
];
|
|
1934
|
+
var sumUsage = (base2, more) => {
|
|
1935
|
+
const out = { ...base2 ?? {} };
|
|
1936
|
+
for (const u of more) {
|
|
1937
|
+
if (!u) continue;
|
|
1938
|
+
for (const k of USAGE_KEYS) out[k] = (out[k] ?? 0) + (u[k] ?? 0);
|
|
1939
|
+
}
|
|
1940
|
+
for (const k of USAGE_KEYS) out[k] ??= 0;
|
|
1941
|
+
return out;
|
|
1942
|
+
};
|
|
1943
|
+
var renumber = (own, after) => {
|
|
1944
|
+
let next = after.reduce(
|
|
1945
|
+
(max, m) => Math.max(max, Number(/^msg-(\d+)$/.exec(m.id)?.[1] ?? -1)),
|
|
1946
|
+
-1
|
|
1947
|
+
);
|
|
1948
|
+
return own.map((m) => ({ ...m, id: `msg-${next += 1}` }));
|
|
1949
|
+
};
|
|
1950
|
+
var unchangedSince = (messages, base2) => base2 !== void 0 && messages.length === base2.known.size && messages.every((m) => base2.known.has(m));
|
|
1951
|
+
var mergeChatRecord = (view, stored, base2) => {
|
|
1952
|
+
const local = view.messages.filter((m) => !m.remote);
|
|
1953
|
+
if (!stored || base2 && stored.updatedAt <= base2.updatedAt) {
|
|
1954
|
+
return { record: { ...view, messages: local }, merged: false };
|
|
1955
|
+
}
|
|
1956
|
+
const own = local.filter((m) => !base2?.known.has(m));
|
|
1957
|
+
const messages = [...stored.messages, ...renumber(own, stored.messages)];
|
|
1958
|
+
return {
|
|
1959
|
+
record: {
|
|
1960
|
+
...view,
|
|
1961
|
+
createdAt: stored.createdAt,
|
|
1962
|
+
title: chatTitle(messages),
|
|
1963
|
+
messages,
|
|
1964
|
+
totalUsage: sumUsage(
|
|
1965
|
+
stored.totalUsage,
|
|
1966
|
+
own.map((m) => m.role === "assistant" ? m.usage : void 0)
|
|
1967
|
+
)
|
|
1968
|
+
},
|
|
1969
|
+
merged: true
|
|
1970
|
+
};
|
|
1971
|
+
};
|
|
1972
|
+
var saveChat = async (store, view, base2) => {
|
|
1973
|
+
let merged = false;
|
|
1974
|
+
const record = await store.putMerged(view.id, (stored) => {
|
|
1975
|
+
const out = mergeChatRecord(view, stored, base2);
|
|
1976
|
+
merged = out.merged;
|
|
1977
|
+
return out.record;
|
|
1978
|
+
});
|
|
1979
|
+
return { record, merged };
|
|
1980
|
+
};
|
|
1599
1981
|
var useChatHistory = (agent, options = {}) => {
|
|
1600
1982
|
const enabled = options.enabled !== false;
|
|
1601
1983
|
const store = (0, import_react2.useMemo)(() => options.store ?? new ChatHistoryStore(), [options.store]);
|
|
@@ -1604,6 +1986,8 @@ var useChatHistory = (agent, options = {}) => {
|
|
|
1604
1986
|
const createdRef = (0, import_react2.useRef)(/* @__PURE__ */ new Map());
|
|
1605
1987
|
const agentRef = (0, import_react2.useRef)(agent);
|
|
1606
1988
|
agentRef.current = agent;
|
|
1989
|
+
const baseRef = (0, import_react2.useRef)(void 0);
|
|
1990
|
+
const staleRef = (0, import_react2.useRef)(void 0);
|
|
1607
1991
|
const refresh = (0, import_react2.useCallback)(async () => {
|
|
1608
1992
|
try {
|
|
1609
1993
|
setChats(await store.list());
|
|
@@ -1618,6 +2002,7 @@ var useChatHistory = (agent, options = {}) => {
|
|
|
1618
2002
|
const record = await store.get(id).catch(() => void 0);
|
|
1619
2003
|
if (!record) return;
|
|
1620
2004
|
createdRef.current.set(id, record.createdAt);
|
|
2005
|
+
baseRef.current = { id, known: new Set(record.messages), updatedAt: record.updatedAt };
|
|
1621
2006
|
agentRef.current.loadChat({
|
|
1622
2007
|
sessionId: record.id,
|
|
1623
2008
|
messages: record.messages,
|
|
@@ -1650,13 +2035,43 @@ var useChatHistory = (agent, options = {}) => {
|
|
|
1650
2035
|
active = false;
|
|
1651
2036
|
};
|
|
1652
2037
|
}, [enabled, store]);
|
|
1653
|
-
const { messages, totalUsage, sessionId, isRunning } = agent;
|
|
1654
2038
|
(0, import_react2.useEffect)(() => {
|
|
1655
|
-
if (!enabled
|
|
2039
|
+
if (!enabled) return;
|
|
2040
|
+
let openSaved;
|
|
2041
|
+
return followOtherTabs(
|
|
2042
|
+
core3,
|
|
2043
|
+
store.dbName,
|
|
2044
|
+
(change) => {
|
|
2045
|
+
if (change.kind !== "chats") return false;
|
|
2046
|
+
if (change.op === "put" && change.key === agentRef.current.sessionId) openSaved = change.key;
|
|
2047
|
+
return true;
|
|
2048
|
+
},
|
|
2049
|
+
() => {
|
|
2050
|
+
void refresh();
|
|
2051
|
+
const key = openSaved;
|
|
2052
|
+
openSaved = void 0;
|
|
2053
|
+
const current = agentRef.current;
|
|
2054
|
+
if (key === void 0 || key !== current.sessionId) return;
|
|
2055
|
+
if (current.remote?.running) staleRef.current = key;
|
|
2056
|
+
else if (!current.isRunning) void select(key);
|
|
2057
|
+
}
|
|
2058
|
+
);
|
|
2059
|
+
}, [enabled, store, refresh, select]);
|
|
2060
|
+
const { messages, totalUsage, sessionId, isRunning, remote } = agent;
|
|
2061
|
+
(0, import_react2.useEffect)(() => {
|
|
2062
|
+
if (!enabled || loading || isRunning) return;
|
|
2063
|
+
if (staleRef.current === sessionId) {
|
|
2064
|
+
staleRef.current = void 0;
|
|
2065
|
+
void select(sessionId);
|
|
2066
|
+
return;
|
|
2067
|
+
}
|
|
2068
|
+
if (remote || messages.length === 0) return;
|
|
2069
|
+
const base2 = baseRef.current?.id === sessionId ? baseRef.current : void 0;
|
|
2070
|
+
if (unchangedSince(messages, base2)) return;
|
|
1656
2071
|
const now = Date.now();
|
|
1657
2072
|
const createdAt = createdRef.current.get(sessionId) ?? now;
|
|
1658
2073
|
createdRef.current.set(sessionId, createdAt);
|
|
1659
|
-
const
|
|
2074
|
+
const view = {
|
|
1660
2075
|
id: sessionId,
|
|
1661
2076
|
title: chatTitle(messages),
|
|
1662
2077
|
createdAt,
|
|
@@ -1664,14 +2079,24 @@ var useChatHistory = (agent, options = {}) => {
|
|
|
1664
2079
|
messages,
|
|
1665
2080
|
totalUsage
|
|
1666
2081
|
};
|
|
1667
|
-
void
|
|
2082
|
+
void (async () => {
|
|
2083
|
+
const { record, merged } = await saveChat(store, view, base2);
|
|
2084
|
+
baseRef.current = {
|
|
2085
|
+
id: sessionId,
|
|
2086
|
+
known: new Set(merged ? record.messages : messages),
|
|
2087
|
+
updatedAt: record.updatedAt
|
|
2088
|
+
};
|
|
2089
|
+
await refresh();
|
|
2090
|
+
if (merged && agentRef.current.sessionId === sessionId) await select(sessionId);
|
|
2091
|
+
})().catch(() => {
|
|
1668
2092
|
});
|
|
1669
|
-
}, [enabled, loading, isRunning, messages, totalUsage, sessionId, store, refresh]);
|
|
2093
|
+
}, [enabled, loading, isRunning, remote, messages, totalUsage, sessionId, store, refresh, select]);
|
|
1670
2094
|
return { chats, currentId: sessionId, loading, select, newChat, remove };
|
|
1671
2095
|
};
|
|
1672
2096
|
|
|
1673
2097
|
// src/hooks/use-virtual-files.ts
|
|
1674
2098
|
var import_react3 = require("react");
|
|
2099
|
+
var core4 = __toESM(require("@dudko.dev/agent-web"), 1);
|
|
1675
2100
|
var readDataUrl = (file) => new Promise((resolve, reject) => {
|
|
1676
2101
|
const r = new FileReader();
|
|
1677
2102
|
r.onload = () => resolve(String(r.result));
|
|
@@ -1696,7 +2121,18 @@ var useVirtualFiles = (vfs, prefix = "/") => {
|
|
|
1696
2121
|
(0, import_react3.useEffect)(() => {
|
|
1697
2122
|
if (!vfs) return;
|
|
1698
2123
|
void refresh();
|
|
1699
|
-
|
|
2124
|
+
const local = vfs.onChange(() => void refresh());
|
|
2125
|
+
const namespace = vfs.namespace;
|
|
2126
|
+
const remote = followOtherTabs(
|
|
2127
|
+
core4,
|
|
2128
|
+
vfs.dbName,
|
|
2129
|
+
(change) => change.kind === "files" && (!namespace || change.namespace === namespace),
|
|
2130
|
+
() => void refresh()
|
|
2131
|
+
);
|
|
2132
|
+
return () => {
|
|
2133
|
+
local();
|
|
2134
|
+
remote();
|
|
2135
|
+
};
|
|
1700
2136
|
}, [vfs, refresh]);
|
|
1701
2137
|
const upload = (0, import_react3.useCallback)(
|
|
1702
2138
|
async (file, dir = "/uploads") => {
|
|
@@ -1793,10 +2229,24 @@ var useSpeechToText = (options = {}) => {
|
|
|
1793
2229
|
|
|
1794
2230
|
// src/hooks/use-credentials.ts
|
|
1795
2231
|
var import_react5 = require("react");
|
|
2232
|
+
var core5 = __toESM(require("@dudko.dev/agent-web"), 1);
|
|
1796
2233
|
var import_agent_web3 = require("@dudko.dev/agent-web");
|
|
2234
|
+
var storeDbName = (store) => {
|
|
2235
|
+
const name = store?.dbName;
|
|
2236
|
+
return typeof name === "string" && name ? name : void 0;
|
|
2237
|
+
};
|
|
1797
2238
|
var useCredentials = (store) => {
|
|
1798
2239
|
const resolved = (0, import_react5.useMemo)(() => store ?? new import_agent_web3.VaultCredentialStore(), [store]);
|
|
1799
2240
|
const [version, setVersion] = (0, import_react5.useState)(0);
|
|
2241
|
+
const dbName = storeDbName(resolved);
|
|
2242
|
+
(0, import_react5.useEffect)(() => {
|
|
2243
|
+
return followOtherTabs(
|
|
2244
|
+
core5,
|
|
2245
|
+
dbName,
|
|
2246
|
+
(change) => change.kind === "credentials",
|
|
2247
|
+
() => setVersion((v) => v + 1)
|
|
2248
|
+
);
|
|
2249
|
+
}, [dbName]);
|
|
1800
2250
|
const setKey = (0, import_react5.useCallback)(
|
|
1801
2251
|
async (ref, key) => {
|
|
1802
2252
|
await resolved.setApiKey(ref, key);
|
|
@@ -2194,6 +2644,11 @@ var defaultLabels = {
|
|
|
2194
2644
|
discardUndelivered: "Discard",
|
|
2195
2645
|
stopSubagent: "Stop this subagent",
|
|
2196
2646
|
subagentStopped: "stopped",
|
|
2647
|
+
remoteRunning: "Running in another tab: follow it here, write to it or stop it.",
|
|
2648
|
+
remoteWaitingConsent: "It waits for an answer in the other tab.",
|
|
2649
|
+
remoteGone: "The tab running this conversation closed before it finished.",
|
|
2650
|
+
sessionBusy: (heldBy) => heldBy === "this-tab" ? "Waiting for the other run of this conversation to finish\u2026" : "Waiting for the other tab to finish this conversation\u2026",
|
|
2651
|
+
fromAnotherTab: "from another tab",
|
|
2197
2652
|
failed: "failed",
|
|
2198
2653
|
toolCostTitle: "Estimated tokens of the arguments and of the result fed back to the model (chars / 4), and the call's duration",
|
|
2199
2654
|
tierNames: { light: "light", standard: "standard", strong: "strong" },
|
|
@@ -4800,6 +5255,9 @@ ${draftText}` : draftText);
|
|
|
4800
5255
|
inputRef.current?.focus();
|
|
4801
5256
|
}, [draftId, draftText]);
|
|
4802
5257
|
const busy = agent.isRunning;
|
|
5258
|
+
const following = !!agent.remote?.running && !agent.sessionBusy;
|
|
5259
|
+
const steerTo = following ? agent.sendRemote : agent.send;
|
|
5260
|
+
const stopIt = following ? agent.stopRemote : agent.stop;
|
|
4803
5261
|
const ready = agent.isReady && !disabled;
|
|
4804
5262
|
const caps = agent.agent?.capabilities;
|
|
4805
5263
|
const stt = useSpeechToText({
|
|
@@ -4843,7 +5301,7 @@ ${draftText}` : draftText);
|
|
|
4843
5301
|
name: "stop",
|
|
4844
5302
|
description: L.commandDescriptions.stop,
|
|
4845
5303
|
group: L.commandGroups.commands,
|
|
4846
|
-
run:
|
|
5304
|
+
run: stopIt
|
|
4847
5305
|
},
|
|
4848
5306
|
{
|
|
4849
5307
|
name: "autopilot",
|
|
@@ -4895,7 +5353,7 @@ ${draftText}` : draftText);
|
|
|
4895
5353
|
}
|
|
4896
5354
|
}
|
|
4897
5355
|
return [...out, ...commands];
|
|
4898
|
-
}, [agent, builtinCommands, skillCommands, commands, thinking, L]);
|
|
5356
|
+
}, [agent, stopIt, builtinCommands, skillCommands, commands, thinking, L]);
|
|
4899
5357
|
const slash = parseSlash(text2);
|
|
4900
5358
|
const matches = slash && !/\s/.test(text2.trimStart()) ? filterCommands(allCommands, slash.name) : [];
|
|
4901
5359
|
const palette = menu === "commands" && !slash ? allCommands : matches;
|
|
@@ -5069,7 +5527,7 @@ ${draftText}` : draftText);
|
|
|
5069
5527
|
const raw = text2.trim();
|
|
5070
5528
|
const intent = steerIntent({ raw, busy, steering, hasAttachments: pending.length > 0 });
|
|
5071
5529
|
if (intent === "steer") {
|
|
5072
|
-
if (
|
|
5530
|
+
if (steerTo(raw)) setText("");
|
|
5073
5531
|
return;
|
|
5074
5532
|
}
|
|
5075
5533
|
if (intent === "attachments") {
|
|
@@ -5180,6 +5638,7 @@ ${draftText}` : draftText);
|
|
|
5180
5638
|
agent.queued.map((q) => /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "awr-queued__item", role: "status", children: [
|
|
5181
5639
|
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(ClockIcon, { size: 13, className: "awr-queued__icon" }),
|
|
5182
5640
|
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "awr-queued__text", title: q.text, children: q.text }),
|
|
5641
|
+
q.origin === "another-tab" && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "awr-queued__origin", children: L.fromAnotherTab }),
|
|
5183
5642
|
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "awr-queued__state", children: L.queuedWaiting })
|
|
5184
5643
|
] }, q.id)),
|
|
5185
5644
|
agent.undelivered.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "awr-queued__item awr-queued__item--undelivered", role: "status", children: [
|
|
@@ -5461,7 +5920,7 @@ ${draftText}` : draftText);
|
|
|
5461
5920
|
{
|
|
5462
5921
|
type: "button",
|
|
5463
5922
|
className: "awr-sendbtn awr-sendbtn--stop",
|
|
5464
|
-
onClick:
|
|
5923
|
+
onClick: stopIt,
|
|
5465
5924
|
"aria-label": L.stop,
|
|
5466
5925
|
children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(StopIcon, { size: 16 })
|
|
5467
5926
|
}
|
|
@@ -6877,7 +7336,8 @@ var UserNoteRow = ({
|
|
|
6877
7336
|
return /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)("li", { className: `awr-note awr-note--${note.at}`, children: [
|
|
6878
7337
|
/* @__PURE__ */ (0, import_jsx_runtime15.jsx)(SendIcon, { size: 12, className: "awr-note__icon" }),
|
|
6879
7338
|
/* @__PURE__ */ (0, import_jsx_runtime15.jsx)("span", { className: "awr-note__where", children: L.noteAt[note.at] }),
|
|
6880
|
-
/* @__PURE__ */ (0, import_jsx_runtime15.jsx)("q", { className: "awr-note__text", children: note.text })
|
|
7339
|
+
/* @__PURE__ */ (0, import_jsx_runtime15.jsx)("q", { className: "awr-note__text", children: note.text }),
|
|
7340
|
+
note.origin === "another-tab" && /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("span", { className: "awr-note__origin", children: L.fromAnotherTab })
|
|
6881
7341
|
] });
|
|
6882
7342
|
};
|
|
6883
7343
|
var decisionNote = (d, L) => {
|
|
@@ -7409,13 +7869,18 @@ var UsageBadge = ({
|
|
|
7409
7869
|
const media = showCalls ? usage.mediaCalls ?? 0 : 0;
|
|
7410
7870
|
const decisions = showCalls ? usage.decisionCalls ?? 0 : 0;
|
|
7411
7871
|
if (usage.totalTokens === 0 && media === 0 && decisions === 0) return null;
|
|
7872
|
+
const mediaText = media ? L.usageMedia(media, {
|
|
7873
|
+
imagesGenerated: usage.imagesGenerated ?? 0,
|
|
7874
|
+
speechCharacters: usage.speechCharacters ?? 0,
|
|
7875
|
+
transcriptionSeconds: usage.transcriptionSeconds ?? 0
|
|
7876
|
+
}) : "";
|
|
7412
7877
|
const reasoning = usage.reasoningTokens ?? 0;
|
|
7413
7878
|
const cached = usage.cachedInputTokens ?? 0;
|
|
7414
7879
|
const title = [
|
|
7415
7880
|
`${usage.inputTokens} in + ${usage.outputTokens} out = ${usage.totalTokens} tokens`,
|
|
7416
7881
|
reasoning ? `${reasoning} thinking` : "",
|
|
7417
7882
|
cached ? `${cached} input tokens from the prompt cache` : "",
|
|
7418
|
-
|
|
7883
|
+
mediaText,
|
|
7419
7884
|
decisions ? L.usageDecisions(decisions) : ""
|
|
7420
7885
|
].filter(Boolean).join(" \xB7 ");
|
|
7421
7886
|
return /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)("span", { className: ["awr-usage", className].filter(Boolean).join(" "), title, children: [
|
|
@@ -7425,7 +7890,7 @@ var UsageBadge = ({
|
|
|
7425
7890
|
"\u2193",
|
|
7426
7891
|
!compact && reasoning > 0 && ` \xB7 ${formatTokens(reasoning)} think`,
|
|
7427
7892
|
!compact && cached > 0 && ` \xB7 ${formatTokens(cached)} cached`,
|
|
7428
|
-
!compact &&
|
|
7893
|
+
!compact && mediaText && ` \xB7 ${mediaText}`,
|
|
7429
7894
|
!compact && decisions > 0 && ` \xB7 ${L.usageDecisions(decisions)}`
|
|
7430
7895
|
] });
|
|
7431
7896
|
};
|
|
@@ -7477,6 +7942,7 @@ var AgentChatInner = ({
|
|
|
7477
7942
|
activityOpen = false,
|
|
7478
7943
|
showElicitation = true,
|
|
7479
7944
|
showSkillPreview = true,
|
|
7945
|
+
showOtherTabs = true,
|
|
7480
7946
|
elicitations,
|
|
7481
7947
|
onElicitationAnswer,
|
|
7482
7948
|
renderElicitation,
|
|
@@ -7640,6 +8106,12 @@ var AgentChatInner = ({
|
|
|
7640
8106
|
const Files = components.FilesPanel ?? FilesPanel;
|
|
7641
8107
|
const Approvals = components.ApprovalPrompt ?? ToolApprovalPrompt;
|
|
7642
8108
|
const Elicitations = components.ElicitationPrompt ?? ElicitationPrompt;
|
|
8109
|
+
const tabNotes = showOtherTabs ? [
|
|
8110
|
+
agent.remote?.running && L.remoteRunning,
|
|
8111
|
+
agent.remote?.running && agent.approvals.some((a) => a.remote && a.status === "pending") && L.remoteWaitingConsent,
|
|
8112
|
+
agent.remote?.ended === "gone" && L.remoteGone,
|
|
8113
|
+
agent.sessionBusy && L.sessionBusy(agent.sessionBusy.heldBy)
|
|
8114
|
+
].filter((t) => typeof t === "string") : [];
|
|
7643
8115
|
const loading = agent.modelLoad && agent.modelLoad.progress < 1;
|
|
7644
8116
|
const showReplan = agent.replan && agent.replan.mode !== "continue";
|
|
7645
8117
|
const replanFailedEarly = showReplanFailed && agent.replan?.failed === true && agent.steps.length === 0;
|
|
@@ -7820,6 +8292,7 @@ var AgentChatInner = ({
|
|
|
7820
8292
|
),
|
|
7821
8293
|
/* @__PURE__ */ (0, import_jsx_runtime20.jsxs)("div", { className: cx("awr-chat__footer", classNames.footer), children: [
|
|
7822
8294
|
slots.footerStart,
|
|
8295
|
+
tabNotes.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime20.jsx)("div", { className: "awr-tabnote", role: "status", children: tabNotes.map((text2) => /* @__PURE__ */ (0, import_jsx_runtime20.jsx)("p", { className: "awr-tabnote__text", children: text2 }, text2)) }),
|
|
7823
8296
|
showContext !== false && /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
|
|
7824
8297
|
ContextMeter,
|
|
7825
8298
|
{
|
|
@@ -8231,6 +8704,7 @@ var import_agent_web8 = require("@dudko.dev/agent-web");
|
|
|
8231
8704
|
ModelLoadBar,
|
|
8232
8705
|
PlanView,
|
|
8233
8706
|
SandboxedFrame,
|
|
8707
|
+
SessionBusyError,
|
|
8234
8708
|
SourceView,
|
|
8235
8709
|
StepList,
|
|
8236
8710
|
SubagentRow,
|
|
@@ -8244,6 +8718,7 @@ var import_agent_web8 = require("@dudko.dev/agent-web");
|
|
|
8244
8718
|
VfsSkillStore,
|
|
8245
8719
|
VirtualFileSystem,
|
|
8246
8720
|
agentStateReducer,
|
|
8721
|
+
agentStatusOf,
|
|
8247
8722
|
appDisplayModeAllowed,
|
|
8248
8723
|
appDownloadOf,
|
|
8249
8724
|
appDownloadRefusal,
|
|
@@ -8299,22 +8774,28 @@ var import_agent_web8 = require("@dudko.dev/agent-web");
|
|
|
8299
8774
|
mcpAppSandboxShellCsp,
|
|
8300
8775
|
mcpAppSandboxTarget,
|
|
8301
8776
|
mediaFamilyOf,
|
|
8777
|
+
mergeChatRecord,
|
|
8302
8778
|
mergeLabels,
|
|
8303
8779
|
newChatId,
|
|
8304
8780
|
noticesOf,
|
|
8781
|
+
onStorageChange,
|
|
8305
8782
|
parseSkillMarkdown,
|
|
8306
8783
|
parseSlash,
|
|
8784
|
+
pendingApprovalsOf,
|
|
8785
|
+
postStorageChange,
|
|
8307
8786
|
preloadWebLLMModel,
|
|
8308
8787
|
resolveAppDownload,
|
|
8309
8788
|
sandboxTokens,
|
|
8310
8789
|
sandboxedCsp,
|
|
8311
8790
|
saveAppFile,
|
|
8791
|
+
saveChat,
|
|
8312
8792
|
serveSubagentWorker,
|
|
8313
8793
|
steerIntent,
|
|
8314
8794
|
subagentTree,
|
|
8315
8795
|
supportsImages,
|
|
8316
8796
|
supportsPdf,
|
|
8317
8797
|
tokenizeHtml,
|
|
8798
|
+
unchangedSince,
|
|
8318
8799
|
unloadWebLLMModel,
|
|
8319
8800
|
usageLine,
|
|
8320
8801
|
useAgent,
|
|
@@ -8328,6 +8809,7 @@ var import_agent_web8 = require("@dudko.dev/agent-web");
|
|
|
8328
8809
|
useSpeechToText,
|
|
8329
8810
|
useVirtualFiles,
|
|
8330
8811
|
useWebLLMModel,
|
|
8812
|
+
watchSession,
|
|
8331
8813
|
webSearchOf,
|
|
8332
8814
|
withAttachments,
|
|
8333
8815
|
withCspFirst,
|