@dudko.dev/agent-web-react 0.0.30 → 0.0.32
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 +52 -10
- package/dist/{chunk-EMF7DTGS.js → chunk-G5GGIMD4.js} +29 -1
- package/dist/chunk-G5GGIMD4.js.map +1 -0
- package/dist/{elicitation-CcZe5-EK.d.cts → elicitation-BW7R4iIw.d.cts} +60 -5
- package/dist/{elicitation-CcZe5-EK.d.ts → elicitation-BW7R4iIw.d.ts} +60 -5
- package/dist/index.cjs +501 -29
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +149 -15
- package/dist/index.d.ts +149 -15
- package/dist/index.js +499 -68
- package/dist/index.js.map +1 -1
- package/dist/mcp.cjs +9 -2
- package/dist/mcp.cjs.map +1 -1
- package/dist/mcp.d.cts +9 -6
- package/dist/mcp.d.ts +9 -6
- package/dist/mcp.js +9 -2
- package/dist/mcp.js.map +1 -1
- package/dist/pipeline.cjs.map +1 -1
- package/dist/pipeline.js +1 -1
- package/dist/styles.css +25 -1
- 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
|
|
@@ -345,6 +365,7 @@ var addElicitation = (state, event, extra) => state.elicitations?.some((e) => e.
|
|
|
345
365
|
...event.url ? { url: event.url } : {},
|
|
346
366
|
...extra.stepId ? { stepId: extra.stepId } : {},
|
|
347
367
|
...extra.subagent ? { subagent: extra.subagent } : {},
|
|
368
|
+
...extra.remote ? { remote: true } : {},
|
|
348
369
|
status: "pending"
|
|
349
370
|
}
|
|
350
371
|
]
|
|
@@ -561,6 +582,7 @@ var applySubagent = (state, event, ancestors, ctx) => {
|
|
|
561
582
|
...node?.role ? { role: node.role } : {}
|
|
562
583
|
},
|
|
563
584
|
...inner.skill ? { skill: inner.skill } : {},
|
|
585
|
+
...ctx.remote ? { remote: true } : {},
|
|
564
586
|
status: "pending"
|
|
565
587
|
}
|
|
566
588
|
]
|
|
@@ -585,6 +607,7 @@ var applySubagent = (state, event, ancestors, ctx) => {
|
|
|
585
607
|
case "mcp.elicitation-requested": {
|
|
586
608
|
const node = inner.subagent ? known.subagents.find((s) => s.id === inner.subagent.id) : void 0;
|
|
587
609
|
return addElicitation(known, inner, {
|
|
610
|
+
...ctx.remote ? { remote: true } : {},
|
|
588
611
|
// The subagent's own step ids mean nothing here: the step that delegated it does.
|
|
589
612
|
stepId: (node ?? known.subagents.find((s) => s.id === event.id))?.stepId,
|
|
590
613
|
...inner.subagent ? {
|
|
@@ -623,6 +646,7 @@ var applySubagent = (state, event, ancestors, ctx) => {
|
|
|
623
646
|
return fileDeleted(known, inner.path);
|
|
624
647
|
// An app a subagent's call came with is shown in the turn too, and says whose call it was.
|
|
625
648
|
case "mcp.app": {
|
|
649
|
+
if (ctx.remote) return known;
|
|
626
650
|
const node = known.subagents.find((s) => s.id === event.id);
|
|
627
651
|
return addApp(known, inner, {
|
|
628
652
|
id: event.id,
|
|
@@ -714,14 +738,37 @@ var streamAssistant = (messages, content) => {
|
|
|
714
738
|
}
|
|
715
739
|
return messages;
|
|
716
740
|
};
|
|
741
|
+
var WAITING_ID = "waiting-for-session";
|
|
742
|
+
var withoutBusy = (state) => {
|
|
743
|
+
if (!state.sessionBusy) return state;
|
|
744
|
+
const { sessionBusy: _over, ...rest } = state;
|
|
745
|
+
void _over;
|
|
746
|
+
return { ...rest, queued: rest.queued.filter((q) => q.id !== WAITING_ID) };
|
|
747
|
+
};
|
|
748
|
+
var withoutSubmitted = (state) => {
|
|
749
|
+
if (!state.submitted) return state;
|
|
750
|
+
const { submitted, ...rest } = state;
|
|
751
|
+
const ids = /* @__PURE__ */ new Set([submitted.userId, submitted.assistantId]);
|
|
752
|
+
return { ...rest, messages: rest.messages.filter((m) => !ids.has(m.id)) };
|
|
753
|
+
};
|
|
754
|
+
var keepSubmitted = (state) => {
|
|
755
|
+
if (!state.submitted) return state;
|
|
756
|
+
const { submitted: _kept, ...rest } = state;
|
|
757
|
+
void _kept;
|
|
758
|
+
return rest;
|
|
759
|
+
};
|
|
717
760
|
var applyEvent = (state, event, ctx) => {
|
|
718
761
|
switch (event.type) {
|
|
719
762
|
case "run.start": {
|
|
720
|
-
const base2 = resetRun(state);
|
|
763
|
+
const base2 = resetRun(ctx.remote ? state : withoutSubmitted(state));
|
|
721
764
|
const userId = `msg-${base2.seq}`;
|
|
722
765
|
const assistantId = `msg-${base2.seq + 1}`;
|
|
723
766
|
return {
|
|
724
767
|
...base2,
|
|
768
|
+
// Another tab's run keeps the view of it; a run of this tab's ends it (and any wait).
|
|
769
|
+
...ctx.remote && state.remote ? { remote: state.remote } : {},
|
|
770
|
+
// ...and this tab's sent turn, still waiting for its own run.start (or a session.busy).
|
|
771
|
+
...ctx.remote && state.submitted ? { submitted: state.submitted } : {},
|
|
725
772
|
goal: event.goal,
|
|
726
773
|
runStartedAt: ctx.at,
|
|
727
774
|
runMessageId: assistantId,
|
|
@@ -732,9 +779,16 @@ var applyEvent = (state, event, ctx) => {
|
|
|
732
779
|
role: "user",
|
|
733
780
|
content: event.goal,
|
|
734
781
|
pending: false,
|
|
782
|
+
...ctx.remote ? { remote: true } : {},
|
|
735
783
|
...ctx.attachments?.length ? { attachments: ctx.attachments } : {}
|
|
736
784
|
},
|
|
737
|
-
{
|
|
785
|
+
{
|
|
786
|
+
id: assistantId,
|
|
787
|
+
role: "assistant",
|
|
788
|
+
content: "",
|
|
789
|
+
pending: true,
|
|
790
|
+
...ctx.remote ? { remote: true } : {}
|
|
791
|
+
}
|
|
738
792
|
],
|
|
739
793
|
seq: base2.seq + 2
|
|
740
794
|
};
|
|
@@ -968,9 +1022,15 @@ var applyEvent = (state, event, ctx) => {
|
|
|
968
1022
|
case "file.deleted":
|
|
969
1023
|
return fileDeleted(state, event.path);
|
|
970
1024
|
case "mcp.app":
|
|
971
|
-
return addApp(state, event);
|
|
1025
|
+
return ctx.remote ? state : addApp(state, event);
|
|
972
1026
|
case "message.queued":
|
|
973
|
-
return state.queued.some((q) => q.id === event.id) ? state : {
|
|
1027
|
+
return state.queued.some((q) => q.id === event.id) ? state : {
|
|
1028
|
+
...state,
|
|
1029
|
+
queued: [
|
|
1030
|
+
...state.queued,
|
|
1031
|
+
{ id: event.id, text: event.text, ...event.origin ? { origin: event.origin } : {} }
|
|
1032
|
+
]
|
|
1033
|
+
};
|
|
974
1034
|
case "message.delivered": {
|
|
975
1035
|
const anchor = event.at === "round" ? runningStepId(state.steps) : event.at === "step" ? state.steps[state.steps.length - 1]?.id : void 0;
|
|
976
1036
|
return {
|
|
@@ -978,7 +1038,13 @@ var applyEvent = (state, event, ctx) => {
|
|
|
978
1038
|
queued: state.queued.filter((q) => q.id !== event.id),
|
|
979
1039
|
notes: [
|
|
980
1040
|
...state.notes,
|
|
981
|
-
{
|
|
1041
|
+
{
|
|
1042
|
+
id: event.id,
|
|
1043
|
+
text: event.text,
|
|
1044
|
+
at: event.at,
|
|
1045
|
+
...anchor ? { stepId: anchor } : {},
|
|
1046
|
+
...event.origin ? { origin: event.origin } : {}
|
|
1047
|
+
}
|
|
982
1048
|
]
|
|
983
1049
|
};
|
|
984
1050
|
}
|
|
@@ -1005,6 +1071,8 @@ var applyEvent = (state, event, ctx) => {
|
|
|
1005
1071
|
};
|
|
1006
1072
|
case "mcp.elicitation-requested":
|
|
1007
1073
|
return addElicitation(state, event, {
|
|
1074
|
+
// Asked in the tab that runs the tool call: shown here, answered there.
|
|
1075
|
+
...ctx.remote ? { remote: true } : {},
|
|
1008
1076
|
stepId: event.step?.id,
|
|
1009
1077
|
...event.subagent ? { subagent: event.subagent } : {}
|
|
1010
1078
|
});
|
|
@@ -1024,6 +1092,8 @@ var applyEvent = (state, event, ctx) => {
|
|
|
1024
1092
|
...event.subagent ? { subagent: event.subagent } : {},
|
|
1025
1093
|
...event.app ? { app: event.app } : {},
|
|
1026
1094
|
...event.skill ? { skill: event.skill } : {},
|
|
1095
|
+
// Asked in the tab that runs the tool: shown here, answered there.
|
|
1096
|
+
...ctx.remote ? { remote: true } : {},
|
|
1027
1097
|
status: "pending"
|
|
1028
1098
|
}
|
|
1029
1099
|
]
|
|
@@ -1108,9 +1178,26 @@ var applyEvent = (state, event, ctx) => {
|
|
|
1108
1178
|
};
|
|
1109
1179
|
case "budget.exceeded":
|
|
1110
1180
|
return { ...state, budget: { kind: event.kind, tokens: event.tokens, cap: event.cap } };
|
|
1111
|
-
case "
|
|
1181
|
+
case "session.busy":
|
|
1182
|
+
state = withoutSubmitted(state);
|
|
1112
1183
|
return {
|
|
1113
1184
|
...state,
|
|
1185
|
+
sessionBusy: { heldBy: event.heldBy, ...ctx.goal ? { goal: ctx.goal } : {} },
|
|
1186
|
+
// What the user sent waits with the run: shown as queued, not lost.
|
|
1187
|
+
...ctx.goal ? {
|
|
1188
|
+
queued: [
|
|
1189
|
+
...state.queued.filter((q) => q.id !== WAITING_ID),
|
|
1190
|
+
{ id: WAITING_ID, text: ctx.goal }
|
|
1191
|
+
]
|
|
1192
|
+
} : {}
|
|
1193
|
+
};
|
|
1194
|
+
case "session.acquired":
|
|
1195
|
+
return withoutBusy(state);
|
|
1196
|
+
case "stopped":
|
|
1197
|
+
if (!ctx.remote && state.sessionBusy) return withoutBusy(state);
|
|
1198
|
+
if (!ctx.remote && state.submitted) return withoutSubmitted(state);
|
|
1199
|
+
return {
|
|
1200
|
+
...withoutBusy(state),
|
|
1114
1201
|
stopped: true,
|
|
1115
1202
|
// Nothing of the run is waiting any more once it has stopped (an app's request is not
|
|
1116
1203
|
// the run's).
|
|
@@ -1136,7 +1223,7 @@ var applyEvent = (state, event, ctx) => {
|
|
|
1136
1223
|
};
|
|
1137
1224
|
}
|
|
1138
1225
|
return event.phase === "run" ? {
|
|
1139
|
-
...state,
|
|
1226
|
+
...withoutBusy(keepSubmitted(state)),
|
|
1140
1227
|
error: event.error,
|
|
1141
1228
|
messages: finalizeAssistant(
|
|
1142
1229
|
state.messages,
|
|
@@ -1181,6 +1268,8 @@ var syncRunMessage = (state) => {
|
|
|
1181
1268
|
messages[i] = { ...m, ...patch };
|
|
1182
1269
|
return { ...state, messages };
|
|
1183
1270
|
};
|
|
1271
|
+
var pendingApprovalsOf = (state) => state.approvals.filter((a) => a.status === "pending" && !a.remote);
|
|
1272
|
+
var agentStatusOf = (state) => state.remote?.running && (state.status === "ready" || state.status === "idle") ? "running" : state.status;
|
|
1184
1273
|
var agentStateReducer = (state, action) => {
|
|
1185
1274
|
switch (action.type) {
|
|
1186
1275
|
case "reset":
|
|
@@ -1192,22 +1281,68 @@ var agentStateReducer = (state, action) => {
|
|
|
1192
1281
|
};
|
|
1193
1282
|
case "notebook":
|
|
1194
1283
|
return { ...state, learned: action.lessons };
|
|
1284
|
+
case "submitted": {
|
|
1285
|
+
if (state.submitted) return state;
|
|
1286
|
+
const userId = `msg-${state.seq}`;
|
|
1287
|
+
const assistantId = `msg-${state.seq + 1}`;
|
|
1288
|
+
return {
|
|
1289
|
+
...state,
|
|
1290
|
+
submitted: { userId, assistantId },
|
|
1291
|
+
messages: [
|
|
1292
|
+
...state.messages,
|
|
1293
|
+
{
|
|
1294
|
+
id: userId,
|
|
1295
|
+
role: "user",
|
|
1296
|
+
content: action.goal,
|
|
1297
|
+
pending: false,
|
|
1298
|
+
...action.attachments?.length ? { attachments: action.attachments } : {}
|
|
1299
|
+
},
|
|
1300
|
+
{ id: assistantId, role: "assistant", content: "", pending: true }
|
|
1301
|
+
],
|
|
1302
|
+
seq: state.seq + 2
|
|
1303
|
+
};
|
|
1304
|
+
}
|
|
1195
1305
|
case "status":
|
|
1196
1306
|
return {
|
|
1197
1307
|
...state,
|
|
1198
1308
|
status: action.status,
|
|
1199
1309
|
error: action.status === "error" ? action.error : void 0
|
|
1200
1310
|
};
|
|
1311
|
+
case "remote": {
|
|
1312
|
+
const remote = action.remote;
|
|
1313
|
+
if (!remote) {
|
|
1314
|
+
const { remote: _gone, ...rest } = state;
|
|
1315
|
+
void _gone;
|
|
1316
|
+
return rest;
|
|
1317
|
+
}
|
|
1318
|
+
if (remote.ended === "gone" && state.remote?.running) {
|
|
1319
|
+
return syncRunMessage({
|
|
1320
|
+
...state,
|
|
1321
|
+
remote,
|
|
1322
|
+
messages: finalizeAssistant(state.messages, state.finalText, { error: true })
|
|
1323
|
+
});
|
|
1324
|
+
}
|
|
1325
|
+
return { ...state, remote };
|
|
1326
|
+
}
|
|
1201
1327
|
case "event": {
|
|
1202
1328
|
const next = syncRunMessage(
|
|
1203
|
-
applyEvent(state, action.event, {
|
|
1329
|
+
applyEvent(state, action.event, {
|
|
1330
|
+
at: action.at,
|
|
1331
|
+
attachments: action.attachments,
|
|
1332
|
+
...action.remote ? { remote: true } : {},
|
|
1333
|
+
...action.goal ? { goal: action.goal } : {}
|
|
1334
|
+
})
|
|
1204
1335
|
);
|
|
1205
1336
|
const cap = action.maxEvents ?? 200;
|
|
1206
1337
|
const events = cap > 0 ? [...state.events, action.event].slice(-cap) : [...state.events, action.event];
|
|
1207
1338
|
return { ...next, events };
|
|
1208
1339
|
}
|
|
1209
1340
|
case "undelivered":
|
|
1210
|
-
return {
|
|
1341
|
+
return {
|
|
1342
|
+
...state,
|
|
1343
|
+
queued: action.keepQueued ? state.queued : [],
|
|
1344
|
+
undelivered: action.texts
|
|
1345
|
+
};
|
|
1211
1346
|
case "load": {
|
|
1212
1347
|
const maxSeq = action.messages.reduce((n, m) => {
|
|
1213
1348
|
const k = Number(/^msg-(\d+)$/.exec(m.id)?.[1] ?? -1);
|
|
@@ -1229,8 +1364,39 @@ var agentStateReducer = (state, action) => {
|
|
|
1229
1364
|
|
|
1230
1365
|
// src/util.ts
|
|
1231
1366
|
var errMessage = (err) => err instanceof Error ? err.message : String(err);
|
|
1367
|
+
var coalesce = (fn, ms = 100) => {
|
|
1368
|
+
let timer;
|
|
1369
|
+
return {
|
|
1370
|
+
call: () => {
|
|
1371
|
+
if (timer !== void 0) clearTimeout(timer);
|
|
1372
|
+
timer = setTimeout(() => {
|
|
1373
|
+
timer = void 0;
|
|
1374
|
+
fn();
|
|
1375
|
+
}, ms);
|
|
1376
|
+
},
|
|
1377
|
+
cancel: () => {
|
|
1378
|
+
if (timer !== void 0) clearTimeout(timer);
|
|
1379
|
+
timer = void 0;
|
|
1380
|
+
}
|
|
1381
|
+
};
|
|
1382
|
+
};
|
|
1383
|
+
var listenToOtherTabs = (core6, dbName, listener) => typeof core6.onStorageChange === "function" && dbName ? core6.onStorageChange(dbName, listener) : () => void 0;
|
|
1384
|
+
var followOtherTabs = (core6, dbName, accept, settle, ms = 100) => {
|
|
1385
|
+
const later = coalesce(settle, ms);
|
|
1386
|
+
const off = listenToOtherTabs(core6, dbName, (change) => {
|
|
1387
|
+
if (accept(change)) later.call();
|
|
1388
|
+
});
|
|
1389
|
+
return () => {
|
|
1390
|
+
off();
|
|
1391
|
+
later.cancel();
|
|
1392
|
+
};
|
|
1393
|
+
};
|
|
1232
1394
|
|
|
1233
1395
|
// src/hooks/use-agent.ts
|
|
1396
|
+
var dbNameOf = (store) => {
|
|
1397
|
+
const name = store?.dbName;
|
|
1398
|
+
return typeof name === "string" && name ? name : void 0;
|
|
1399
|
+
};
|
|
1234
1400
|
var useAgent = (config, options = {}) => {
|
|
1235
1401
|
const [state, dispatch] = (0, import_react.useReducer)(agentStateReducer, void 0, createInitialAgentState);
|
|
1236
1402
|
const agentRef = (0, import_react.useRef)(void 0);
|
|
@@ -1303,6 +1469,57 @@ var useAgent = (config, options = {}) => {
|
|
|
1303
1469
|
cancelled = true;
|
|
1304
1470
|
};
|
|
1305
1471
|
}, [generation, autoStart, ...deps ?? []]);
|
|
1472
|
+
const watchRef = (0, import_react.useRef)(void 0);
|
|
1473
|
+
const startedRef = (0, import_react.useRef)(false);
|
|
1474
|
+
const watchDb = options.watch !== false && config.sessionLock !== "off" ? dbNameOf(config.memory) : void 0;
|
|
1475
|
+
(0, import_react.useEffect)(() => {
|
|
1476
|
+
const watchSession3 = core.watchSession;
|
|
1477
|
+
if (!watchDb || typeof watchSession3 !== "function") return;
|
|
1478
|
+
const watch = watchSession3({
|
|
1479
|
+
dbName: watchDb,
|
|
1480
|
+
sessionId,
|
|
1481
|
+
onEvent: (event) => {
|
|
1482
|
+
if (startedRef.current) return;
|
|
1483
|
+
dispatch({
|
|
1484
|
+
type: "event",
|
|
1485
|
+
event,
|
|
1486
|
+
remote: true,
|
|
1487
|
+
maxEvents: optionsRef.current.maxEvents,
|
|
1488
|
+
at: Date.now()
|
|
1489
|
+
});
|
|
1490
|
+
},
|
|
1491
|
+
onState: (s) => {
|
|
1492
|
+
if (startedRef.current && s.running) return;
|
|
1493
|
+
dispatch({
|
|
1494
|
+
type: "remote",
|
|
1495
|
+
remote: {
|
|
1496
|
+
running: s.running,
|
|
1497
|
+
...s.runId ? { runId: s.runId } : {},
|
|
1498
|
+
...s.ended ? { ended: s.ended } : {}
|
|
1499
|
+
}
|
|
1500
|
+
});
|
|
1501
|
+
}
|
|
1502
|
+
});
|
|
1503
|
+
watchRef.current = watch;
|
|
1504
|
+
return () => {
|
|
1505
|
+
watch.close();
|
|
1506
|
+
if (watchRef.current === watch) watchRef.current = void 0;
|
|
1507
|
+
};
|
|
1508
|
+
}, [watchDb, sessionId]);
|
|
1509
|
+
const skillsDb = dbNameOf(typeof config.learning === "object" ? config.learning.store : void 0);
|
|
1510
|
+
(0, import_react.useEffect)(() => {
|
|
1511
|
+
return followOtherTabs(
|
|
1512
|
+
core,
|
|
1513
|
+
skillsDb,
|
|
1514
|
+
(change) => change.kind === "skills",
|
|
1515
|
+
() => {
|
|
1516
|
+
const agent = agentRef.current;
|
|
1517
|
+
if (!agent || typeof agent.reloadLearnedSkills !== "function") return;
|
|
1518
|
+
void agent.reloadLearnedSkills().then((skills) => dispatch({ type: "notebook", lessons: lessonsOf(skills) })).catch(() => {
|
|
1519
|
+
});
|
|
1520
|
+
}
|
|
1521
|
+
);
|
|
1522
|
+
}, [skillsDb]);
|
|
1306
1523
|
(0, import_react.useEffect)(
|
|
1307
1524
|
() => () => {
|
|
1308
1525
|
abortRef.current?.abort();
|
|
@@ -1321,7 +1538,17 @@ var useAgent = (config, options = {}) => {
|
|
|
1321
1538
|
const control = (0, import_agent_web2.createRunControl)();
|
|
1322
1539
|
controlRef.current = control;
|
|
1323
1540
|
let left = [];
|
|
1541
|
+
let stopped = false;
|
|
1542
|
+
let began = false;
|
|
1543
|
+
const shownGoal = runOptions?.label ?? goal;
|
|
1324
1544
|
dispatch({ type: "status", status: "running" });
|
|
1545
|
+
if (shownGoal.trim()) {
|
|
1546
|
+
dispatch({
|
|
1547
|
+
type: "submitted",
|
|
1548
|
+
goal: shownGoal,
|
|
1549
|
+
...runOptions?.attachments?.length ? { attachments: runOptions.attachments } : {}
|
|
1550
|
+
});
|
|
1551
|
+
}
|
|
1325
1552
|
try {
|
|
1326
1553
|
const result = await agent.run(goal, {
|
|
1327
1554
|
signal: controller.signal,
|
|
@@ -1331,12 +1558,18 @@ var useAgent = (config, options = {}) => {
|
|
|
1331
1558
|
...runOptions?.files?.length ? { files: runOptions.files } : {},
|
|
1332
1559
|
onEvent: (event) => {
|
|
1333
1560
|
const start = event.type === "run.start";
|
|
1561
|
+
if (start) {
|
|
1562
|
+
startedRef.current = true;
|
|
1563
|
+
began = true;
|
|
1564
|
+
}
|
|
1334
1565
|
const shown = start && runOptions?.label ? { ...event, goal: runOptions.label } : event;
|
|
1335
1566
|
dispatch({
|
|
1336
1567
|
type: "event",
|
|
1337
1568
|
event: shown,
|
|
1338
1569
|
maxEvents: optionsRef.current.maxEvents,
|
|
1339
1570
|
at: Date.now(),
|
|
1571
|
+
// What the user sent waits with the run: shown as queued meanwhile.
|
|
1572
|
+
...event.type === "session.busy" && shownGoal.trim() ? { goal: shownGoal } : {},
|
|
1340
1573
|
...start && runOptions?.attachments?.length ? { attachments: runOptions.attachments } : {}
|
|
1341
1574
|
});
|
|
1342
1575
|
try {
|
|
@@ -1346,6 +1579,7 @@ var useAgent = (config, options = {}) => {
|
|
|
1346
1579
|
}
|
|
1347
1580
|
});
|
|
1348
1581
|
left = result.undelivered ?? [];
|
|
1582
|
+
stopped = result.stopped;
|
|
1349
1583
|
return result;
|
|
1350
1584
|
} catch (err) {
|
|
1351
1585
|
left = control.pending();
|
|
@@ -1357,11 +1591,13 @@ var useAgent = (config, options = {}) => {
|
|
|
1357
1591
|
return void 0;
|
|
1358
1592
|
} finally {
|
|
1359
1593
|
abortRef.current = void 0;
|
|
1594
|
+
startedRef.current = false;
|
|
1360
1595
|
controlRef.current = void 0;
|
|
1361
1596
|
settleAll({ approved: false, reason: "the run ended" });
|
|
1362
1597
|
dispatch({ type: "status", ...buildStatusRef.current });
|
|
1598
|
+
if (stopped && !began && shownGoal.trim()) left = [shownGoal, ...left];
|
|
1363
1599
|
if (left.length > 0) {
|
|
1364
|
-
if (!controller.signal.aborted && optionsRef.current.followUp !== false) {
|
|
1600
|
+
if (!controller.signal.aborted && !stopped && optionsRef.current.followUp !== false) {
|
|
1365
1601
|
dispatch({ type: "undelivered", texts: [] });
|
|
1366
1602
|
void runRef.current?.(left.join("\n\n"));
|
|
1367
1603
|
} else {
|
|
@@ -1376,6 +1612,24 @@ var useAgent = (config, options = {}) => {
|
|
|
1376
1612
|
);
|
|
1377
1613
|
runRef.current = run;
|
|
1378
1614
|
const send = (0, import_react.useCallback)((text2) => controlRef.current?.send(text2) ?? false, []);
|
|
1615
|
+
const sendRemote = (0, import_react.useCallback)((text2) => {
|
|
1616
|
+
const watch = watchRef.current;
|
|
1617
|
+
const clean = typeof text2 === "string" ? text2.trim() : "";
|
|
1618
|
+
if (!watch?.state.running || !clean) return false;
|
|
1619
|
+
void watch.send(clean).then((ok) => {
|
|
1620
|
+
if (!ok) {
|
|
1621
|
+
dispatch({
|
|
1622
|
+
type: "undelivered",
|
|
1623
|
+
texts: [...stateRef.current.undelivered, clean],
|
|
1624
|
+
keepQueued: true
|
|
1625
|
+
});
|
|
1626
|
+
}
|
|
1627
|
+
});
|
|
1628
|
+
return true;
|
|
1629
|
+
}, []);
|
|
1630
|
+
const stopRemote = (0, import_react.useCallback)(() => {
|
|
1631
|
+
if (watchRef.current?.state.running) void watchRef.current.stop();
|
|
1632
|
+
}, []);
|
|
1379
1633
|
const stopSubagent = (0, import_react.useCallback)(
|
|
1380
1634
|
(id) => controlRef.current?.stopSubagent(id) ?? false,
|
|
1381
1635
|
[]
|
|
@@ -1492,11 +1746,16 @@ var useAgent = (config, options = {}) => {
|
|
|
1492
1746
|
}
|
|
1493
1747
|
return result;
|
|
1494
1748
|
}, []);
|
|
1749
|
+
const remoteRunning = state.remote?.running === true;
|
|
1495
1750
|
return {
|
|
1496
1751
|
...state,
|
|
1752
|
+
// `running` over ready / idle only: a build in progress or an error stays visible.
|
|
1753
|
+
status: agentStatusOf(state),
|
|
1497
1754
|
run,
|
|
1498
1755
|
stop,
|
|
1756
|
+
stopRemote,
|
|
1499
1757
|
send,
|
|
1758
|
+
sendRemote,
|
|
1500
1759
|
stopSubagent,
|
|
1501
1760
|
forgetSkill,
|
|
1502
1761
|
sendUndelivered,
|
|
@@ -1504,9 +1763,10 @@ var useAgent = (config, options = {}) => {
|
|
|
1504
1763
|
reset,
|
|
1505
1764
|
reload,
|
|
1506
1765
|
agent: agentRef.current,
|
|
1507
|
-
isRunning: state.status === "running",
|
|
1508
|
-
isReady: state.status === "ready",
|
|
1509
|
-
|
|
1766
|
+
isRunning: state.status === "running" || remoteRunning,
|
|
1767
|
+
isReady: state.status === "ready" && !remoteRunning,
|
|
1768
|
+
// Another tab's consent requests are answered there, never here.
|
|
1769
|
+
pendingApprovals: pendingApprovalsOf(state),
|
|
1510
1770
|
approve,
|
|
1511
1771
|
deny,
|
|
1512
1772
|
approvalMode,
|
|
@@ -1521,26 +1781,36 @@ var useAgent = (config, options = {}) => {
|
|
|
1521
1781
|
|
|
1522
1782
|
// src/hooks/use-chat-history.ts
|
|
1523
1783
|
var import_react2 = require("react");
|
|
1784
|
+
var core3 = __toESM(require("@dudko.dev/agent-web"), 1);
|
|
1524
1785
|
|
|
1525
1786
|
// src/chat-history.ts
|
|
1787
|
+
var core2 = __toESM(require("@dudko.dev/agent-web"), 1);
|
|
1526
1788
|
var DB_VERSION = 1;
|
|
1527
1789
|
var req = (r) => new Promise((resolve, reject) => {
|
|
1528
1790
|
r.onsuccess = () => resolve(r.result);
|
|
1529
1791
|
r.onerror = () => reject(r.error);
|
|
1530
1792
|
});
|
|
1793
|
+
var committed = (tx, r) => new Promise((resolve, reject) => {
|
|
1794
|
+
tx.oncomplete = () => resolve();
|
|
1795
|
+
tx.onabort = () => reject(tx.error ?? r.error ?? new Error("the transaction was aborted"));
|
|
1796
|
+
tx.onerror = () => reject(tx.error ?? r.error);
|
|
1797
|
+
});
|
|
1531
1798
|
var ChatHistoryStore = class {
|
|
1799
|
+
/** The IndexedDB database (undefined in memory): the name its `chats` notices go out under. */
|
|
1532
1800
|
dbName;
|
|
1801
|
+
name;
|
|
1533
1802
|
storeName;
|
|
1534
1803
|
memory;
|
|
1535
1804
|
db;
|
|
1536
1805
|
constructor(opts = {}) {
|
|
1537
|
-
this.
|
|
1806
|
+
this.name = opts.dbName ?? "agent-web-react";
|
|
1538
1807
|
this.storeName = opts.storeName ?? "chats";
|
|
1539
1808
|
if (opts.memory || typeof indexedDB === "undefined") this.memory = /* @__PURE__ */ new Map();
|
|
1809
|
+
this.dbName = this.memory ? void 0 : this.name;
|
|
1540
1810
|
}
|
|
1541
1811
|
open() {
|
|
1542
1812
|
this.db ??= new Promise((resolve, reject) => {
|
|
1543
|
-
const r = indexedDB.open(this.
|
|
1813
|
+
const r = indexedDB.open(this.name, DB_VERSION);
|
|
1544
1814
|
r.onupgradeneeded = () => {
|
|
1545
1815
|
if (!r.result.objectStoreNames.contains(this.storeName)) {
|
|
1546
1816
|
r.result.createObjectStore(this.storeName, { keyPath: "id" });
|
|
@@ -1558,6 +1828,54 @@ var ChatHistoryStore = class {
|
|
|
1558
1828
|
const db = await this.open();
|
|
1559
1829
|
return db.transaction(this.storeName, mode).objectStore(this.storeName);
|
|
1560
1830
|
}
|
|
1831
|
+
/** One write in its own transaction, resolved once it committed - then the notice. */
|
|
1832
|
+
async write(op, notice) {
|
|
1833
|
+
const db = await this.open();
|
|
1834
|
+
const tx = db.transaction(this.storeName, "readwrite");
|
|
1835
|
+
await committed(tx, op(tx.objectStore(this.storeName)));
|
|
1836
|
+
this.announce(notice);
|
|
1837
|
+
}
|
|
1838
|
+
announce(notice) {
|
|
1839
|
+
if (typeof core2.postStorageChange === "function") {
|
|
1840
|
+
core2.postStorageChange(this.dbName, { kind: "chats", ...notice });
|
|
1841
|
+
}
|
|
1842
|
+
}
|
|
1843
|
+
/**
|
|
1844
|
+
* Read the stored record and write what `merge` makes of it in ONE readwrite transaction: no
|
|
1845
|
+
* other tab's save can land between the read and the write. `merge` is synchronous (a
|
|
1846
|
+
* transaction does not survive an await). Resolves with what was written, once committed.
|
|
1847
|
+
*/
|
|
1848
|
+
async putMerged(id, merge) {
|
|
1849
|
+
if (this.memory) {
|
|
1850
|
+
const record = merge(this.memory.get(id));
|
|
1851
|
+
this.memory.set(record.id, structuredClone(record));
|
|
1852
|
+
return record;
|
|
1853
|
+
}
|
|
1854
|
+
const db = await this.open();
|
|
1855
|
+
const tx = db.transaction(this.storeName, "readwrite");
|
|
1856
|
+
const store = tx.objectStore(this.storeName);
|
|
1857
|
+
let written;
|
|
1858
|
+
let failed;
|
|
1859
|
+
const read = store.get(id);
|
|
1860
|
+
const done = committed(tx, read);
|
|
1861
|
+
read.onsuccess = () => {
|
|
1862
|
+
try {
|
|
1863
|
+
written = merge(read.result);
|
|
1864
|
+
store.put(written);
|
|
1865
|
+
} catch (err) {
|
|
1866
|
+
failed = err;
|
|
1867
|
+
tx.abort();
|
|
1868
|
+
}
|
|
1869
|
+
};
|
|
1870
|
+
try {
|
|
1871
|
+
await done;
|
|
1872
|
+
} catch (err) {
|
|
1873
|
+
throw failed ?? err;
|
|
1874
|
+
}
|
|
1875
|
+
if (!written) throw new Error("the chat could not be saved");
|
|
1876
|
+
this.announce({ op: "put", key: id });
|
|
1877
|
+
return written;
|
|
1878
|
+
}
|
|
1561
1879
|
async list() {
|
|
1562
1880
|
const all = this.memory ? [...this.memory.values()] : await req((await this.tx("readonly")).getAll());
|
|
1563
1881
|
return all.map(({ messages, ...rest }) => ({ ...rest, messageCount: messages.length })).sort((a, b) => b.updatedAt - a.updatedAt);
|
|
@@ -1571,21 +1889,21 @@ var ChatHistoryStore = class {
|
|
|
1571
1889
|
this.memory.set(record.id, structuredClone(record));
|
|
1572
1890
|
return;
|
|
1573
1891
|
}
|
|
1574
|
-
await
|
|
1892
|
+
await this.write((store) => store.put(record), { op: "put", key: record.id });
|
|
1575
1893
|
}
|
|
1576
1894
|
async delete(id) {
|
|
1577
1895
|
if (this.memory) {
|
|
1578
1896
|
this.memory.delete(id);
|
|
1579
1897
|
return;
|
|
1580
1898
|
}
|
|
1581
|
-
await
|
|
1899
|
+
await this.write((store) => store.delete(id), { op: "delete", key: id });
|
|
1582
1900
|
}
|
|
1583
1901
|
async clear() {
|
|
1584
1902
|
if (this.memory) {
|
|
1585
1903
|
this.memory.clear();
|
|
1586
1904
|
return;
|
|
1587
1905
|
}
|
|
1588
|
-
await
|
|
1906
|
+
await this.write((store) => store.clear(), { op: "clear" });
|
|
1589
1907
|
}
|
|
1590
1908
|
};
|
|
1591
1909
|
var chatTitle = (messages) => {
|
|
@@ -1596,6 +1914,61 @@ var chatTitle = (messages) => {
|
|
|
1596
1914
|
var newChatId = () => `chat-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}`;
|
|
1597
1915
|
|
|
1598
1916
|
// src/hooks/use-chat-history.ts
|
|
1917
|
+
var USAGE_KEYS = [
|
|
1918
|
+
"inputTokens",
|
|
1919
|
+
"outputTokens",
|
|
1920
|
+
"totalTokens",
|
|
1921
|
+
"reasoningTokens",
|
|
1922
|
+
"cachedInputTokens",
|
|
1923
|
+
"cacheWriteTokens"
|
|
1924
|
+
];
|
|
1925
|
+
var sumUsage = (base2, more) => {
|
|
1926
|
+
const out = { ...base2 ?? {} };
|
|
1927
|
+
for (const u of more) {
|
|
1928
|
+
if (!u) continue;
|
|
1929
|
+
for (const k of USAGE_KEYS) out[k] = (out[k] ?? 0) + (u[k] ?? 0);
|
|
1930
|
+
}
|
|
1931
|
+
for (const k of USAGE_KEYS) out[k] ??= 0;
|
|
1932
|
+
return out;
|
|
1933
|
+
};
|
|
1934
|
+
var renumber = (own, after) => {
|
|
1935
|
+
let next = after.reduce(
|
|
1936
|
+
(max, m) => Math.max(max, Number(/^msg-(\d+)$/.exec(m.id)?.[1] ?? -1)),
|
|
1937
|
+
-1
|
|
1938
|
+
);
|
|
1939
|
+
return own.map((m) => ({ ...m, id: `msg-${next += 1}` }));
|
|
1940
|
+
};
|
|
1941
|
+
var unchangedSince = (messages, base2) => base2 !== void 0 && messages.length === base2.known.size && messages.every((m) => base2.known.has(m));
|
|
1942
|
+
var mergeChatRecord = (view, stored, base2) => {
|
|
1943
|
+
const local = view.messages.filter((m) => !m.remote);
|
|
1944
|
+
if (!stored || base2 && stored.updatedAt <= base2.updatedAt) {
|
|
1945
|
+
return { record: { ...view, messages: local }, merged: false };
|
|
1946
|
+
}
|
|
1947
|
+
const own = local.filter((m) => !base2?.known.has(m));
|
|
1948
|
+
const messages = [...stored.messages, ...renumber(own, stored.messages)];
|
|
1949
|
+
return {
|
|
1950
|
+
record: {
|
|
1951
|
+
...view,
|
|
1952
|
+
createdAt: stored.createdAt,
|
|
1953
|
+
title: chatTitle(messages),
|
|
1954
|
+
messages,
|
|
1955
|
+
totalUsage: sumUsage(
|
|
1956
|
+
stored.totalUsage,
|
|
1957
|
+
own.map((m) => m.role === "assistant" ? m.usage : void 0)
|
|
1958
|
+
)
|
|
1959
|
+
},
|
|
1960
|
+
merged: true
|
|
1961
|
+
};
|
|
1962
|
+
};
|
|
1963
|
+
var saveChat = async (store, view, base2) => {
|
|
1964
|
+
let merged = false;
|
|
1965
|
+
const record = await store.putMerged(view.id, (stored) => {
|
|
1966
|
+
const out = mergeChatRecord(view, stored, base2);
|
|
1967
|
+
merged = out.merged;
|
|
1968
|
+
return out.record;
|
|
1969
|
+
});
|
|
1970
|
+
return { record, merged };
|
|
1971
|
+
};
|
|
1599
1972
|
var useChatHistory = (agent, options = {}) => {
|
|
1600
1973
|
const enabled = options.enabled !== false;
|
|
1601
1974
|
const store = (0, import_react2.useMemo)(() => options.store ?? new ChatHistoryStore(), [options.store]);
|
|
@@ -1604,6 +1977,8 @@ var useChatHistory = (agent, options = {}) => {
|
|
|
1604
1977
|
const createdRef = (0, import_react2.useRef)(/* @__PURE__ */ new Map());
|
|
1605
1978
|
const agentRef = (0, import_react2.useRef)(agent);
|
|
1606
1979
|
agentRef.current = agent;
|
|
1980
|
+
const baseRef = (0, import_react2.useRef)(void 0);
|
|
1981
|
+
const staleRef = (0, import_react2.useRef)(void 0);
|
|
1607
1982
|
const refresh = (0, import_react2.useCallback)(async () => {
|
|
1608
1983
|
try {
|
|
1609
1984
|
setChats(await store.list());
|
|
@@ -1618,6 +1993,7 @@ var useChatHistory = (agent, options = {}) => {
|
|
|
1618
1993
|
const record = await store.get(id).catch(() => void 0);
|
|
1619
1994
|
if (!record) return;
|
|
1620
1995
|
createdRef.current.set(id, record.createdAt);
|
|
1996
|
+
baseRef.current = { id, known: new Set(record.messages), updatedAt: record.updatedAt };
|
|
1621
1997
|
agentRef.current.loadChat({
|
|
1622
1998
|
sessionId: record.id,
|
|
1623
1999
|
messages: record.messages,
|
|
@@ -1650,13 +2026,43 @@ var useChatHistory = (agent, options = {}) => {
|
|
|
1650
2026
|
active = false;
|
|
1651
2027
|
};
|
|
1652
2028
|
}, [enabled, store]);
|
|
1653
|
-
const { messages, totalUsage, sessionId, isRunning } = agent;
|
|
1654
2029
|
(0, import_react2.useEffect)(() => {
|
|
1655
|
-
if (!enabled
|
|
2030
|
+
if (!enabled) return;
|
|
2031
|
+
let openSaved;
|
|
2032
|
+
return followOtherTabs(
|
|
2033
|
+
core3,
|
|
2034
|
+
store.dbName,
|
|
2035
|
+
(change) => {
|
|
2036
|
+
if (change.kind !== "chats") return false;
|
|
2037
|
+
if (change.op === "put" && change.key === agentRef.current.sessionId) openSaved = change.key;
|
|
2038
|
+
return true;
|
|
2039
|
+
},
|
|
2040
|
+
() => {
|
|
2041
|
+
void refresh();
|
|
2042
|
+
const key = openSaved;
|
|
2043
|
+
openSaved = void 0;
|
|
2044
|
+
const current = agentRef.current;
|
|
2045
|
+
if (key === void 0 || key !== current.sessionId) return;
|
|
2046
|
+
if (current.remote?.running) staleRef.current = key;
|
|
2047
|
+
else if (!current.isRunning) void select(key);
|
|
2048
|
+
}
|
|
2049
|
+
);
|
|
2050
|
+
}, [enabled, store, refresh, select]);
|
|
2051
|
+
const { messages, totalUsage, sessionId, isRunning, remote } = agent;
|
|
2052
|
+
(0, import_react2.useEffect)(() => {
|
|
2053
|
+
if (!enabled || loading || isRunning) return;
|
|
2054
|
+
if (staleRef.current === sessionId) {
|
|
2055
|
+
staleRef.current = void 0;
|
|
2056
|
+
void select(sessionId);
|
|
2057
|
+
return;
|
|
2058
|
+
}
|
|
2059
|
+
if (remote || messages.length === 0) return;
|
|
2060
|
+
const base2 = baseRef.current?.id === sessionId ? baseRef.current : void 0;
|
|
2061
|
+
if (unchangedSince(messages, base2)) return;
|
|
1656
2062
|
const now = Date.now();
|
|
1657
2063
|
const createdAt = createdRef.current.get(sessionId) ?? now;
|
|
1658
2064
|
createdRef.current.set(sessionId, createdAt);
|
|
1659
|
-
const
|
|
2065
|
+
const view = {
|
|
1660
2066
|
id: sessionId,
|
|
1661
2067
|
title: chatTitle(messages),
|
|
1662
2068
|
createdAt,
|
|
@@ -1664,14 +2070,24 @@ var useChatHistory = (agent, options = {}) => {
|
|
|
1664
2070
|
messages,
|
|
1665
2071
|
totalUsage
|
|
1666
2072
|
};
|
|
1667
|
-
void
|
|
2073
|
+
void (async () => {
|
|
2074
|
+
const { record, merged } = await saveChat(store, view, base2);
|
|
2075
|
+
baseRef.current = {
|
|
2076
|
+
id: sessionId,
|
|
2077
|
+
known: new Set(merged ? record.messages : messages),
|
|
2078
|
+
updatedAt: record.updatedAt
|
|
2079
|
+
};
|
|
2080
|
+
await refresh();
|
|
2081
|
+
if (merged && agentRef.current.sessionId === sessionId) await select(sessionId);
|
|
2082
|
+
})().catch(() => {
|
|
1668
2083
|
});
|
|
1669
|
-
}, [enabled, loading, isRunning, messages, totalUsage, sessionId, store, refresh]);
|
|
2084
|
+
}, [enabled, loading, isRunning, remote, messages, totalUsage, sessionId, store, refresh, select]);
|
|
1670
2085
|
return { chats, currentId: sessionId, loading, select, newChat, remove };
|
|
1671
2086
|
};
|
|
1672
2087
|
|
|
1673
2088
|
// src/hooks/use-virtual-files.ts
|
|
1674
2089
|
var import_react3 = require("react");
|
|
2090
|
+
var core4 = __toESM(require("@dudko.dev/agent-web"), 1);
|
|
1675
2091
|
var readDataUrl = (file) => new Promise((resolve, reject) => {
|
|
1676
2092
|
const r = new FileReader();
|
|
1677
2093
|
r.onload = () => resolve(String(r.result));
|
|
@@ -1696,7 +2112,18 @@ var useVirtualFiles = (vfs, prefix = "/") => {
|
|
|
1696
2112
|
(0, import_react3.useEffect)(() => {
|
|
1697
2113
|
if (!vfs) return;
|
|
1698
2114
|
void refresh();
|
|
1699
|
-
|
|
2115
|
+
const local = vfs.onChange(() => void refresh());
|
|
2116
|
+
const namespace = vfs.namespace;
|
|
2117
|
+
const remote = followOtherTabs(
|
|
2118
|
+
core4,
|
|
2119
|
+
vfs.dbName,
|
|
2120
|
+
(change) => change.kind === "files" && (!namespace || change.namespace === namespace),
|
|
2121
|
+
() => void refresh()
|
|
2122
|
+
);
|
|
2123
|
+
return () => {
|
|
2124
|
+
local();
|
|
2125
|
+
remote();
|
|
2126
|
+
};
|
|
1700
2127
|
}, [vfs, refresh]);
|
|
1701
2128
|
const upload = (0, import_react3.useCallback)(
|
|
1702
2129
|
async (file, dir = "/uploads") => {
|
|
@@ -1793,10 +2220,24 @@ var useSpeechToText = (options = {}) => {
|
|
|
1793
2220
|
|
|
1794
2221
|
// src/hooks/use-credentials.ts
|
|
1795
2222
|
var import_react5 = require("react");
|
|
2223
|
+
var core5 = __toESM(require("@dudko.dev/agent-web"), 1);
|
|
1796
2224
|
var import_agent_web3 = require("@dudko.dev/agent-web");
|
|
2225
|
+
var storeDbName = (store) => {
|
|
2226
|
+
const name = store?.dbName;
|
|
2227
|
+
return typeof name === "string" && name ? name : void 0;
|
|
2228
|
+
};
|
|
1797
2229
|
var useCredentials = (store) => {
|
|
1798
2230
|
const resolved = (0, import_react5.useMemo)(() => store ?? new import_agent_web3.VaultCredentialStore(), [store]);
|
|
1799
2231
|
const [version, setVersion] = (0, import_react5.useState)(0);
|
|
2232
|
+
const dbName = storeDbName(resolved);
|
|
2233
|
+
(0, import_react5.useEffect)(() => {
|
|
2234
|
+
return followOtherTabs(
|
|
2235
|
+
core5,
|
|
2236
|
+
dbName,
|
|
2237
|
+
(change) => change.kind === "credentials",
|
|
2238
|
+
() => setVersion((v) => v + 1)
|
|
2239
|
+
);
|
|
2240
|
+
}, [dbName]);
|
|
1800
2241
|
const setKey = (0, import_react5.useCallback)(
|
|
1801
2242
|
async (ref, key) => {
|
|
1802
2243
|
await resolved.setApiKey(ref, key);
|
|
@@ -2194,6 +2635,11 @@ var defaultLabels = {
|
|
|
2194
2635
|
discardUndelivered: "Discard",
|
|
2195
2636
|
stopSubagent: "Stop this subagent",
|
|
2196
2637
|
subagentStopped: "stopped",
|
|
2638
|
+
remoteRunning: "Running in another tab: follow it here, write to it or stop it.",
|
|
2639
|
+
remoteWaitingConsent: "It waits for an answer in the other tab.",
|
|
2640
|
+
remoteGone: "The tab running this conversation closed before it finished.",
|
|
2641
|
+
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",
|
|
2642
|
+
fromAnotherTab: "from another tab",
|
|
2197
2643
|
failed: "failed",
|
|
2198
2644
|
toolCostTitle: "Estimated tokens of the arguments and of the result fed back to the model (chars / 4), and the call's duration",
|
|
2199
2645
|
tierNames: { light: "light", standard: "standard", strong: "strong" },
|
|
@@ -2401,6 +2847,8 @@ var defaultLabels = {
|
|
|
2401
2847
|
skillConsentSize: (bytes, files) => `SKILL.md ${kb(bytes)}${files ? ` \xB7 ${plural(files, "more file", "more files")}` : ""}`,
|
|
2402
2848
|
skillConsentByUri: "Not in the server\u2019s list: the agent asked for it by its address.",
|
|
2403
2849
|
skillConsentNested: (enclosing) => `It sits inside the skill \u201C${enclosing}\u201D: allowing that one did not allow this one.`,
|
|
2850
|
+
skillConsentDynamic: "This server publishes no checksums for this skill: you approve the copy the agent just read, and only that copy is used.",
|
|
2851
|
+
skillConsentNoFileListing: "The server cannot list this skill\u2019s files: that copy is its SKILL.md alone.",
|
|
2404
2852
|
skillConsentPreview: "Show what the agent would read",
|
|
2405
2853
|
skillConsentFiles: (paths, more) => `Its files, read as text and never run: ${paths}${more ? ` and ${more} more` : ""}`,
|
|
2406
2854
|
skillConsentNote: (server, consent) => `Instructions written by the server \u201C${server}\u201D, not by you. They reach the agent only if you allow it${consent === "ask" ? ", and you are asked again in every task that loads them." : " - you are asked again if the server changes them."} They cannot change the agent\u2019s rules or approvals.`,
|
|
@@ -4798,6 +5246,9 @@ ${draftText}` : draftText);
|
|
|
4798
5246
|
inputRef.current?.focus();
|
|
4799
5247
|
}, [draftId, draftText]);
|
|
4800
5248
|
const busy = agent.isRunning;
|
|
5249
|
+
const following = !!agent.remote?.running && !agent.sessionBusy;
|
|
5250
|
+
const steerTo = following ? agent.sendRemote : agent.send;
|
|
5251
|
+
const stopIt = following ? agent.stopRemote : agent.stop;
|
|
4801
5252
|
const ready = agent.isReady && !disabled;
|
|
4802
5253
|
const caps = agent.agent?.capabilities;
|
|
4803
5254
|
const stt = useSpeechToText({
|
|
@@ -4841,7 +5292,7 @@ ${draftText}` : draftText);
|
|
|
4841
5292
|
name: "stop",
|
|
4842
5293
|
description: L.commandDescriptions.stop,
|
|
4843
5294
|
group: L.commandGroups.commands,
|
|
4844
|
-
run:
|
|
5295
|
+
run: stopIt
|
|
4845
5296
|
},
|
|
4846
5297
|
{
|
|
4847
5298
|
name: "autopilot",
|
|
@@ -4893,7 +5344,7 @@ ${draftText}` : draftText);
|
|
|
4893
5344
|
}
|
|
4894
5345
|
}
|
|
4895
5346
|
return [...out, ...commands];
|
|
4896
|
-
}, [agent, builtinCommands, skillCommands, commands, thinking, L]);
|
|
5347
|
+
}, [agent, stopIt, builtinCommands, skillCommands, commands, thinking, L]);
|
|
4897
5348
|
const slash = parseSlash(text2);
|
|
4898
5349
|
const matches = slash && !/\s/.test(text2.trimStart()) ? filterCommands(allCommands, slash.name) : [];
|
|
4899
5350
|
const palette = menu === "commands" && !slash ? allCommands : matches;
|
|
@@ -5067,7 +5518,7 @@ ${draftText}` : draftText);
|
|
|
5067
5518
|
const raw = text2.trim();
|
|
5068
5519
|
const intent = steerIntent({ raw, busy, steering, hasAttachments: pending.length > 0 });
|
|
5069
5520
|
if (intent === "steer") {
|
|
5070
|
-
if (
|
|
5521
|
+
if (steerTo(raw)) setText("");
|
|
5071
5522
|
return;
|
|
5072
5523
|
}
|
|
5073
5524
|
if (intent === "attachments") {
|
|
@@ -5178,6 +5629,7 @@ ${draftText}` : draftText);
|
|
|
5178
5629
|
agent.queued.map((q) => /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "awr-queued__item", role: "status", children: [
|
|
5179
5630
|
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(ClockIcon, { size: 13, className: "awr-queued__icon" }),
|
|
5180
5631
|
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "awr-queued__text", title: q.text, children: q.text }),
|
|
5632
|
+
q.origin === "another-tab" && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "awr-queued__origin", children: L.fromAnotherTab }),
|
|
5181
5633
|
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "awr-queued__state", children: L.queuedWaiting })
|
|
5182
5634
|
] }, q.id)),
|
|
5183
5635
|
agent.undelivered.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "awr-queued__item awr-queued__item--undelivered", role: "status", children: [
|
|
@@ -5459,7 +5911,7 @@ ${draftText}` : draftText);
|
|
|
5459
5911
|
{
|
|
5460
5912
|
type: "button",
|
|
5461
5913
|
className: "awr-sendbtn awr-sendbtn--stop",
|
|
5462
|
-
onClick:
|
|
5914
|
+
onClick: stopIt,
|
|
5463
5915
|
"aria-label": L.stop,
|
|
5464
5916
|
children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(StopIcon, { size: 16 })
|
|
5465
5917
|
}
|
|
@@ -6875,7 +7327,8 @@ var UserNoteRow = ({
|
|
|
6875
7327
|
return /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)("li", { className: `awr-note awr-note--${note.at}`, children: [
|
|
6876
7328
|
/* @__PURE__ */ (0, import_jsx_runtime15.jsx)(SendIcon, { size: 12, className: "awr-note__icon" }),
|
|
6877
7329
|
/* @__PURE__ */ (0, import_jsx_runtime15.jsx)("span", { className: "awr-note__where", children: L.noteAt[note.at] }),
|
|
6878
|
-
/* @__PURE__ */ (0, import_jsx_runtime15.jsx)("q", { className: "awr-note__text", children: note.text })
|
|
7330
|
+
/* @__PURE__ */ (0, import_jsx_runtime15.jsx)("q", { className: "awr-note__text", children: note.text }),
|
|
7331
|
+
note.origin === "another-tab" && /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("span", { className: "awr-note__origin", children: L.fromAnotherTab })
|
|
6879
7332
|
] });
|
|
6880
7333
|
};
|
|
6881
7334
|
var decisionNote = (d, L) => {
|
|
@@ -7271,6 +7724,8 @@ var SkillConsentCard = ({
|
|
|
7271
7724
|
] }),
|
|
7272
7725
|
skill.byUri && /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("p", { className: "awr-approval__from", children: L.skillConsentByUri }),
|
|
7273
7726
|
skill.nestedIn && /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("p", { className: "awr-approval__from awr-approval__nested", children: L.skillConsentNested(skill.nestedIn) }),
|
|
7727
|
+
skill.dynamic && /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("p", { className: "awr-approval__from awr-approval__dynamic", children: L.skillConsentDynamic }),
|
|
7728
|
+
skill.dynamic && skill.noFileListing && /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("p", { className: "awr-approval__from", children: L.skillConsentNoFileListing }),
|
|
7274
7729
|
showPreview && skill.body !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)("details", { className: "awr-approval__preview", children: [
|
|
7275
7730
|
/* @__PURE__ */ (0, import_jsx_runtime18.jsx)("summary", { children: L.skillConsentPreview }),
|
|
7276
7731
|
/* @__PURE__ */ (0, import_jsx_runtime18.jsx)("pre", { className: "awr-approval__quote awr-approval__body", children: skill.body }),
|
|
@@ -7473,6 +7928,7 @@ var AgentChatInner = ({
|
|
|
7473
7928
|
activityOpen = false,
|
|
7474
7929
|
showElicitation = true,
|
|
7475
7930
|
showSkillPreview = true,
|
|
7931
|
+
showOtherTabs = true,
|
|
7476
7932
|
elicitations,
|
|
7477
7933
|
onElicitationAnswer,
|
|
7478
7934
|
renderElicitation,
|
|
@@ -7636,6 +8092,12 @@ var AgentChatInner = ({
|
|
|
7636
8092
|
const Files = components.FilesPanel ?? FilesPanel;
|
|
7637
8093
|
const Approvals = components.ApprovalPrompt ?? ToolApprovalPrompt;
|
|
7638
8094
|
const Elicitations = components.ElicitationPrompt ?? ElicitationPrompt;
|
|
8095
|
+
const tabNotes = showOtherTabs ? [
|
|
8096
|
+
agent.remote?.running && L.remoteRunning,
|
|
8097
|
+
agent.remote?.running && agent.approvals.some((a) => a.remote && a.status === "pending") && L.remoteWaitingConsent,
|
|
8098
|
+
agent.remote?.ended === "gone" && L.remoteGone,
|
|
8099
|
+
agent.sessionBusy && L.sessionBusy(agent.sessionBusy.heldBy)
|
|
8100
|
+
].filter((t) => typeof t === "string") : [];
|
|
7639
8101
|
const loading = agent.modelLoad && agent.modelLoad.progress < 1;
|
|
7640
8102
|
const showReplan = agent.replan && agent.replan.mode !== "continue";
|
|
7641
8103
|
const replanFailedEarly = showReplanFailed && agent.replan?.failed === true && agent.steps.length === 0;
|
|
@@ -7816,6 +8278,7 @@ var AgentChatInner = ({
|
|
|
7816
8278
|
),
|
|
7817
8279
|
/* @__PURE__ */ (0, import_jsx_runtime20.jsxs)("div", { className: cx("awr-chat__footer", classNames.footer), children: [
|
|
7818
8280
|
slots.footerStart,
|
|
8281
|
+
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)) }),
|
|
7819
8282
|
showContext !== false && /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
|
|
7820
8283
|
ContextMeter,
|
|
7821
8284
|
{
|
|
@@ -8227,6 +8690,7 @@ var import_agent_web8 = require("@dudko.dev/agent-web");
|
|
|
8227
8690
|
ModelLoadBar,
|
|
8228
8691
|
PlanView,
|
|
8229
8692
|
SandboxedFrame,
|
|
8693
|
+
SessionBusyError,
|
|
8230
8694
|
SourceView,
|
|
8231
8695
|
StepList,
|
|
8232
8696
|
SubagentRow,
|
|
@@ -8240,6 +8704,7 @@ var import_agent_web8 = require("@dudko.dev/agent-web");
|
|
|
8240
8704
|
VfsSkillStore,
|
|
8241
8705
|
VirtualFileSystem,
|
|
8242
8706
|
agentStateReducer,
|
|
8707
|
+
agentStatusOf,
|
|
8243
8708
|
appDisplayModeAllowed,
|
|
8244
8709
|
appDownloadOf,
|
|
8245
8710
|
appDownloadRefusal,
|
|
@@ -8295,22 +8760,28 @@ var import_agent_web8 = require("@dudko.dev/agent-web");
|
|
|
8295
8760
|
mcpAppSandboxShellCsp,
|
|
8296
8761
|
mcpAppSandboxTarget,
|
|
8297
8762
|
mediaFamilyOf,
|
|
8763
|
+
mergeChatRecord,
|
|
8298
8764
|
mergeLabels,
|
|
8299
8765
|
newChatId,
|
|
8300
8766
|
noticesOf,
|
|
8767
|
+
onStorageChange,
|
|
8301
8768
|
parseSkillMarkdown,
|
|
8302
8769
|
parseSlash,
|
|
8770
|
+
pendingApprovalsOf,
|
|
8771
|
+
postStorageChange,
|
|
8303
8772
|
preloadWebLLMModel,
|
|
8304
8773
|
resolveAppDownload,
|
|
8305
8774
|
sandboxTokens,
|
|
8306
8775
|
sandboxedCsp,
|
|
8307
8776
|
saveAppFile,
|
|
8777
|
+
saveChat,
|
|
8308
8778
|
serveSubagentWorker,
|
|
8309
8779
|
steerIntent,
|
|
8310
8780
|
subagentTree,
|
|
8311
8781
|
supportsImages,
|
|
8312
8782
|
supportsPdf,
|
|
8313
8783
|
tokenizeHtml,
|
|
8784
|
+
unchangedSince,
|
|
8314
8785
|
unloadWebLLMModel,
|
|
8315
8786
|
usageLine,
|
|
8316
8787
|
useAgent,
|
|
@@ -8324,6 +8795,7 @@ var import_agent_web8 = require("@dudko.dev/agent-web");
|
|
|
8324
8795
|
useSpeechToText,
|
|
8325
8796
|
useVirtualFiles,
|
|
8326
8797
|
useWebLLMModel,
|
|
8798
|
+
watchSession,
|
|
8327
8799
|
webSearchOf,
|
|
8328
8800
|
withAttachments,
|
|
8329
8801
|
withCspFirst,
|