@solidxai/core-ui 0.1.22 → 0.1.23-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/core/solid-agent/SolidAgent.module.css +65 -0
- package/dist/components/core/solid-agent/SolidAgentChat.d.ts.map +1 -1
- package/dist/components/core/solid-agent/SolidAgentChat.js +190 -64
- package/dist/components/core/solid-agent/SolidAgentChat.js.map +1 -1
- package/dist/components/core/solid-agent/SolidAgentChat.tsx +201 -5
- package/dist/components/core/solid-agent/agentEvents.d.ts.map +1 -1
- package/dist/components/core/solid-agent/agentEvents.js +21 -18
- package/dist/components/core/solid-agent/agentEvents.js.map +1 -1
- package/dist/components/core/solid-agent/agentEvents.ts +7 -3
- package/dist/components/core/solid-agent/client/agentAttachmentMedia.d.ts +8 -5
- package/dist/components/core/solid-agent/client/agentAttachmentMedia.d.ts.map +1 -1
- package/dist/components/core/solid-agent/client/agentAttachmentMedia.js +71 -23
- package/dist/components/core/solid-agent/client/agentAttachmentMedia.js.map +1 -1
- package/dist/components/core/solid-agent/client/agentAttachmentMedia.ts +52 -25
- package/dist/components/core/solid-agent/client/agentRuntime.d.ts +5 -0
- package/dist/components/core/solid-agent/client/agentRuntime.d.ts.map +1 -1
- package/dist/components/core/solid-agent/client/agentRuntime.js +90 -5
- package/dist/components/core/solid-agent/client/agentRuntime.js.map +1 -1
- package/dist/components/core/solid-agent/client/agentRuntime.ts +37 -1
- package/dist/components/core/solid-agent/client/agentSocket.d.ts +5 -0
- package/dist/components/core/solid-agent/client/agentSocket.d.ts.map +1 -1
- package/dist/components/core/solid-agent/client/agentSocket.js +19 -2
- package/dist/components/core/solid-agent/client/agentSocket.js.map +1 -1
- package/dist/components/core/solid-agent/client/agentSocket.ts +12 -2
- package/dist/components/core/solid-agent/humanReview.d.ts +5 -1
- package/dist/components/core/solid-agent/humanReview.d.ts.map +1 -1
- package/dist/components/core/solid-agent/humanReview.js +35 -4
- package/dist/components/core/solid-agent/humanReview.js.map +1 -1
- package/dist/components/core/solid-agent/humanReview.ts +37 -5
- package/dist/components/core/solid-agent/types.d.ts +57 -0
- package/dist/components/core/solid-agent/types.d.ts.map +1 -1
- package/dist/components/core/solid-agent/types.js.map +1 -1
- package/dist/components/core/solid-agent/types.ts +25 -1
- package/dist/components/core/solid-agent/widgets/DefaultAgentChatHeaderWidget.d.ts +1 -1
- package/dist/components/core/solid-agent/widgets/DefaultAgentChatHeaderWidget.d.ts.map +1 -1
- package/dist/components/core/solid-agent/widgets/DefaultAgentChatHeaderWidget.js +5 -5
- package/dist/components/core/solid-agent/widgets/DefaultAgentChatHeaderWidget.js.map +1 -1
- package/dist/components/core/solid-agent/widgets/DefaultAgentChatHeaderWidget.tsx +2 -6
- package/dist/components/core/solid-agent/widgets/DefaultAgentToolCallWidget.d.ts.map +1 -1
- package/dist/components/core/solid-agent/widgets/DefaultAgentToolCallWidget.js +4 -1
- package/dist/components/core/solid-agent/widgets/DefaultAgentToolCallWidget.js.map +1 -1
- package/dist/components/core/solid-agent/widgets/DefaultAgentToolCallWidget.tsx +5 -0
- package/dist/components/core/solid-agent/widgets/DefaultThinkingChatWidget.d.ts.map +1 -1
- package/dist/components/core/solid-agent/widgets/DefaultThinkingChatWidget.js +2 -3
- package/dist/components/core/solid-agent/widgets/DefaultThinkingChatWidget.js.map +1 -1
- package/dist/components/core/solid-agent/widgets/DefaultThinkingChatWidget.tsx +0 -2
- package/dist/components/core/solid-agent/widgets/solidChatWidgets.module.css +39 -3
- package/dist/helpers/registry.d.ts +2 -0
- package/dist/helpers/registry.d.ts.map +1 -1
- package/dist/helpers/registry.js +6 -0
- package/dist/helpers/registry.js.map +1 -1
- package/dist/helpers/registry.ts +6 -0
- package/dist/index.d.ts +7 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/dist/index.ts +15 -0
- package/dist/redux/features/agentSlice.d.ts +5 -1
- package/dist/redux/features/agentSlice.d.ts.map +1 -1
- package/dist/redux/features/agentSlice.js +12 -1
- package/dist/redux/features/agentSlice.js.map +1 -1
- package/dist/redux/features/agentSlice.ts +11 -0
- package/dist/routes/pages/admin/core/AgentJobsInboxPage.d.ts.map +1 -1
- package/dist/routes/pages/admin/core/AgentJobsInboxPage.js +25 -8
- package/dist/routes/pages/admin/core/AgentJobsInboxPage.js.map +1 -1
- package/dist/routes/pages/admin/core/AgentJobsInboxPage.tsx +28 -4
- package/dist/types/extension-registry.d.ts +2 -0
- package/dist/types/extension-registry.d.ts.map +1 -1
- package/dist/types/extension-registry.js +2 -0
- package/dist/types/extension-registry.js.map +1 -1
- package/dist/types/extension-registry.ts +2 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/solid-core.d.ts +27 -0
- package/package.json +1 -1
|
@@ -2,7 +2,8 @@ import { describeToolArgs, isLlmMetadata, parseToolResult } from "./agentFormat"
|
|
|
2
2
|
import { parseWidgetContent, isSameAssistantContent } from "./thread/inlineWidget";
|
|
3
3
|
export { isSameAssistantContent };
|
|
4
4
|
import { AgentEventTypes, type AgentChatEvent, type AgentChatItem, type AgentCommand, type AgentUsageStats, type AgentWireFrame } from "./types";
|
|
5
|
-
import { humanReviewAnswerItem, humanReviewId, humanReviewItem, type HumanReview } from "./humanReview";
|
|
5
|
+
import { humanReviewAnswerItem, humanReviewId, humanReviewItem, isHumanReviewKind, type HumanReview } from "./humanReview";
|
|
6
|
+
import { normalizeToolFiles } from "./toolFiles";
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* Turns agent events into thread items. Used by agentSlice for live socket frames and by the
|
|
@@ -92,8 +93,7 @@ function setPendingReview(state: AgentThreadState, data: Record<string, any> | n
|
|
|
92
93
|
}
|
|
93
94
|
state.pendingReview = null;
|
|
94
95
|
state.reviewSubmitting = false;
|
|
95
|
-
if (!data || !Number.isInteger(requestId) || typeof data.question !== "string"
|
|
96
|
-
|| (data.kind !== "input" && data.kind !== "approval")) return;
|
|
96
|
+
if (!data || !Number.isInteger(requestId) || typeof data.question !== "string" || !isHumanReviewKind(data.kind)) return;
|
|
97
97
|
const request: HumanReview = {
|
|
98
98
|
requestId, kind: data.kind, question: data.question, options: data.options,
|
|
99
99
|
context: data.context ?? null, toolName: data.tool_name ?? data.toolName ?? null,
|
|
@@ -347,10 +347,14 @@ export function applyAgentEvent(state: AgentThreadState, event: AgentChatEvent,
|
|
|
347
347
|
if (tool) {
|
|
348
348
|
const output = eventData.output ?? frame.content ?? "";
|
|
349
349
|
const parsed = output ? parseToolResult(String(output)) : null;
|
|
350
|
+
const files = normalizeToolFiles(eventData.files);
|
|
351
|
+
// agentEventId lets the UI fetch the stored files (agentEvent media) later.
|
|
352
|
+
const agentEventId = eventData.agentEventId ?? frame.id;
|
|
350
353
|
tool.eventData = {
|
|
351
354
|
...tool.eventData,
|
|
352
355
|
duration_ms: eventData.duration_ms ?? frame.duration_ms,
|
|
353
356
|
...(parsed ? { status: parsed.status, output: parsed.text, output_raw: String(output) } : {}),
|
|
357
|
+
...(files.length ? { files, ...(agentEventId != null ? { agentEventId } : {}) } : {}),
|
|
354
358
|
};
|
|
355
359
|
}
|
|
356
360
|
freezeLiveTool(state);
|
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type AgentToolFileMedia } from "../toolFiles";
|
|
2
|
+
import { type AgentChatItem } from "../types";
|
|
3
|
+
/** URLs of the files a tool returned, stored on its ToolResult agentEvent. Empty while SolidX has not linked them yet. */
|
|
4
|
+
export declare function fetchToolFileMedia(agentEventId: string | number): Promise<AgentToolFileMedia[]>;
|
|
2
5
|
/**
|
|
3
|
-
* Replayed user messages only know their attachments' names
|
|
4
|
-
*
|
|
5
|
-
* such event in one request and put them
|
|
6
|
-
* when nothing is stored or the request fails.
|
|
6
|
+
* Replayed user messages only know their attachments' names, and tool calls only the names of the
|
|
7
|
+
* files the tool returned. The files themselves are stored on the agentEvent (media field
|
|
8
|
+
* `attachments`) by the agent, so fetch fresh URLs for every such event in one request and put them
|
|
9
|
+
* on the thread items. Items are returned unchanged when nothing is stored or the request fails.
|
|
7
10
|
*/
|
|
8
11
|
export declare function resolveAttachmentMedia(items: AgentChatItem[]): Promise<AgentChatItem[]>;
|
|
9
12
|
//# sourceMappingURL=agentAttachmentMedia.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agentAttachmentMedia.d.ts","sourceRoot":"","sources":["../../../../../src/components/core/solid-agent/client/agentAttachmentMedia.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"agentAttachmentMedia.d.ts","sourceRoot":"","sources":["../../../../../src/components/core/solid-agent/client/agentAttachmentMedia.ts"],"names":[],"mappings":"AAGA,OAAO,EAAsB,KAAK,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAC3E,OAAO,EAA6C,KAAK,aAAa,EAAE,MAAM,UAAU,CAAC;AA+CzF,0HAA0H;AAC1H,wBAAsB,kBAAkB,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,kBAAkB,EAAE,CAAC,CAMrG;AAED;;;;;GAKG;AACH,wBAAsB,sBAAsB,CAAC,KAAK,EAAE,aAAa,EAAE,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC,CA6B7F"}
|
|
@@ -48,6 +48,8 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
48
48
|
import qs from "qs";
|
|
49
49
|
import { solidGet } from "../../../../http/solidHttp";
|
|
50
50
|
import { normalizeAssetUrl } from "../../../../helpers/assetUrl";
|
|
51
|
+
import { mergeToolFileMedia } from "../toolFiles";
|
|
52
|
+
import { AgentEventTypes } from "../types";
|
|
51
53
|
/** Media field on the agentEvent model that stores chat attachments (solid-core metadata). */
|
|
52
54
|
var ATTACHMENTS_FIELD = "attachments";
|
|
53
55
|
/** Solid's response interceptor wraps bodies as { data: <payload> }; find the records array. */
|
|
@@ -60,15 +62,73 @@ function unwrapRecords(body) {
|
|
|
60
62
|
}
|
|
61
63
|
return [];
|
|
62
64
|
}
|
|
65
|
+
/** The stored media of each agentEvent, by event id. Throws when SolidX cannot be asked. */
|
|
66
|
+
function fetchEventMedia(eventIds) {
|
|
67
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
68
|
+
var query, response, mediaByEvent;
|
|
69
|
+
return __generator(this, function (_a) {
|
|
70
|
+
switch (_a.label) {
|
|
71
|
+
case 0:
|
|
72
|
+
query = qs.stringify({
|
|
73
|
+
filters: { id: { $in: eventIds.map(Number) } },
|
|
74
|
+
populateMedia: [ATTACHMENTS_FIELD],
|
|
75
|
+
fields: ["id"],
|
|
76
|
+
limit: eventIds.length,
|
|
77
|
+
offset: 0,
|
|
78
|
+
}, { encodeValuesOnly: true });
|
|
79
|
+
return [4 /*yield*/, solidGet("/agent-event?".concat(query))];
|
|
80
|
+
case 1:
|
|
81
|
+
response = _a.sent();
|
|
82
|
+
mediaByEvent = new Map();
|
|
83
|
+
unwrapRecords(response === null || response === void 0 ? void 0 : response.data).forEach(function (record) {
|
|
84
|
+
var _a, _b;
|
|
85
|
+
var media = (_b = (_a = record === null || record === void 0 ? void 0 : record._media) === null || _a === void 0 ? void 0 : _a[ATTACHMENTS_FIELD]) !== null && _b !== void 0 ? _b : [];
|
|
86
|
+
if (media.length)
|
|
87
|
+
mediaByEvent.set(String(record.id), media);
|
|
88
|
+
});
|
|
89
|
+
return [2 /*return*/, mediaByEvent];
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
function toolFileMedia(media) {
|
|
95
|
+
return media.flatMap(function (file) {
|
|
96
|
+
var url = normalizeAssetUrl(file._full_url);
|
|
97
|
+
if (!url)
|
|
98
|
+
return [];
|
|
99
|
+
var id = Number(file.id);
|
|
100
|
+
return [__assign(__assign(__assign({}, (Number.isInteger(id) ? { id: id } : {})), (file.originalFileName ? { name: file.originalFileName } : {})), { url: url })];
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
/** URLs of the files a tool returned, stored on its ToolResult agentEvent. Empty while SolidX has not linked them yet. */
|
|
104
|
+
export function fetchToolFileMedia(agentEventId) {
|
|
105
|
+
var _a;
|
|
106
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
107
|
+
var _b, _c;
|
|
108
|
+
return __generator(this, function (_d) {
|
|
109
|
+
switch (_d.label) {
|
|
110
|
+
case 0:
|
|
111
|
+
_d.trys.push([0, 2, , 3]);
|
|
112
|
+
_b = toolFileMedia;
|
|
113
|
+
return [4 /*yield*/, fetchEventMedia([agentEventId])];
|
|
114
|
+
case 1: return [2 /*return*/, _b.apply(void 0, [(_a = (_d.sent()).get(String(agentEventId))) !== null && _a !== void 0 ? _a : []])];
|
|
115
|
+
case 2:
|
|
116
|
+
_c = _d.sent();
|
|
117
|
+
return [2 /*return*/, []];
|
|
118
|
+
case 3: return [2 /*return*/];
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
}
|
|
63
123
|
/**
|
|
64
|
-
* Replayed user messages only know their attachments' names
|
|
65
|
-
*
|
|
66
|
-
* such event in one request and put them
|
|
67
|
-
* when nothing is stored or the request fails.
|
|
124
|
+
* Replayed user messages only know their attachments' names, and tool calls only the names of the
|
|
125
|
+
* files the tool returned. The files themselves are stored on the agentEvent (media field
|
|
126
|
+
* `attachments`) by the agent, so fetch fresh URLs for every such event in one request and put them
|
|
127
|
+
* on the thread items. Items are returned unchanged when nothing is stored or the request fails.
|
|
68
128
|
*/
|
|
69
129
|
export function resolveAttachmentMedia(items) {
|
|
70
130
|
return __awaiter(this, void 0, void 0, function () {
|
|
71
|
-
var eventIds,
|
|
131
|
+
var eventIds, mediaByEvent, _a;
|
|
72
132
|
return __generator(this, function (_b) {
|
|
73
133
|
switch (_b.label) {
|
|
74
134
|
case 0:
|
|
@@ -77,33 +137,17 @@ export function resolveAttachmentMedia(items) {
|
|
|
77
137
|
.filter(function (id) { return id !== undefined && id !== null && id !== ""; });
|
|
78
138
|
if (!eventIds.length)
|
|
79
139
|
return [2 /*return*/, items];
|
|
80
|
-
records = [];
|
|
81
140
|
_b.label = 1;
|
|
82
141
|
case 1:
|
|
83
142
|
_b.trys.push([1, 3, , 4]);
|
|
84
|
-
|
|
85
|
-
filters: { id: { $in: eventIds.map(Number) } },
|
|
86
|
-
populateMedia: [ATTACHMENTS_FIELD],
|
|
87
|
-
fields: ["id"],
|
|
88
|
-
limit: eventIds.length,
|
|
89
|
-
offset: 0,
|
|
90
|
-
}, { encodeValuesOnly: true });
|
|
91
|
-
return [4 /*yield*/, solidGet("/agent-event?".concat(query))];
|
|
143
|
+
return [4 /*yield*/, fetchEventMedia(eventIds)];
|
|
92
144
|
case 2:
|
|
93
|
-
|
|
94
|
-
records = unwrapRecords(response === null || response === void 0 ? void 0 : response.data);
|
|
145
|
+
mediaByEvent = _b.sent();
|
|
95
146
|
return [3 /*break*/, 4];
|
|
96
147
|
case 3:
|
|
97
148
|
_a = _b.sent();
|
|
98
149
|
return [2 /*return*/, items];
|
|
99
150
|
case 4:
|
|
100
|
-
mediaByEvent = new Map();
|
|
101
|
-
records.forEach(function (record) {
|
|
102
|
-
var _a, _b;
|
|
103
|
-
var media = (_b = (_a = record === null || record === void 0 ? void 0 : record._media) === null || _a === void 0 ? void 0 : _a[ATTACHMENTS_FIELD]) !== null && _b !== void 0 ? _b : [];
|
|
104
|
-
if (media.length)
|
|
105
|
-
mediaByEvent.set(String(record.id), media);
|
|
106
|
-
});
|
|
107
151
|
if (!mediaByEvent.size)
|
|
108
152
|
return [2 /*return*/, items];
|
|
109
153
|
return [2 /*return*/, items.map(function (item) {
|
|
@@ -111,6 +155,10 @@ export function resolveAttachmentMedia(items) {
|
|
|
111
155
|
var media = mediaByEvent.get(String((_a = item.eventData) === null || _a === void 0 ? void 0 : _a.agentEventId));
|
|
112
156
|
if (!media)
|
|
113
157
|
return item;
|
|
158
|
+
if (item.eventType === AgentEventTypes.toolCalling) {
|
|
159
|
+
var files = Array.isArray(item.eventData.files) ? item.eventData.files : [];
|
|
160
|
+
return __assign(__assign({}, item), { eventData: __assign(__assign({}, item.eventData), { files: mergeToolFileMedia(files, toolFileMedia(media)) }) });
|
|
161
|
+
}
|
|
114
162
|
var attachments = media.map(function (file) {
|
|
115
163
|
var _a, _b, _c;
|
|
116
164
|
return ({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agentAttachmentMedia.js","sourceRoot":"","sources":["../../../../../src/components/core/solid-agent/client/agentAttachmentMedia.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AACtD,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;
|
|
1
|
+
{"version":3,"file":"agentAttachmentMedia.js","sourceRoot":"","sources":["../../../../../src/components/core/solid-agent/client/agentAttachmentMedia.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AACtD,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,EAAE,kBAAkB,EAA2B,MAAM,cAAc,CAAC;AAC3E,OAAO,EAAE,eAAe,EAAgD,MAAM,UAAU,CAAC;AAEzF,8FAA8F;AAC9F,IAAM,iBAAiB,GAAG,aAAa,CAAC;AAIxC,gGAAgG;AAChG,SAAS,aAAa,CAAC,IAAS;IAC5B,IAAI,IAAI,GAAG,IAAI,CAAC;IAChB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,IAAI,IAAI,EAAE,CAAC,EAAE,EAAE;QAChC,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC;YAAE,OAA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import { mergeToolFileMedia, type AgentToolFileMedia } from \"../toolFiles\";\nimport { AgentEventTypes, type AgentAttachmentMeta, type AgentChatItem } from \"../types\";\n\n/** Media field on the agentEvent model that stores chat attachments (solid-core metadata). */\nconst ATTACHMENTS_FIELD = \"attachments\";\n\ntype StoredMedia = { id?: number | string; _full_url?: string; originalFileName?: string; mimeType?: string; fileSize?: number };\n\n/** Solid's response interceptor wraps bodies as { data: <payload> }; find the records array. */\nfunction unwrapRecords(body: any): any[] {\n let node = body;\n for (let i = 0; i < 4 && node; i++) {\n if (Array.isArray(node.records)) return node.records;\n node = node.data;\n }\n return [];\n}\n\n/** The stored media of each agentEvent, by event id. Throws when SolidX cannot be asked. */\nasync function fetchEventMedia(eventIds: Array<string | number>): Promise<Map<string, StoredMedia[]>> {\n const query = qs.stringify(\n {\n filters: { id: { $in: eventIds.map(Number) } },\n populateMedia: [ATTACHMENTS_FIELD],\n fields: [\"id\"],\n limit: eventIds.length,\n offset: 0,\n },\n { encodeValuesOnly: true },\n );\n const response = await solidGet(`/agent-event?${query}`);\n const mediaByEvent = new Map<string, StoredMedia[]>();\n unwrapRecords(response?.data).forEach((record) => {\n const media: StoredMedia[] = record?._media?.[ATTACHMENTS_FIELD] ?? [];\n if (media.length) mediaByEvent.set(String(record.id), media);\n });\n return mediaByEvent;\n}\n\nfunction toolFileMedia(media: StoredMedia[]): AgentToolFileMedia[] {\n return media.flatMap((file) => {\n const url = normalizeAssetUrl(file._full_url);\n if (!url) return [];\n const id = Number(file.id);\n return [{ ...(Number.isInteger(id) ? { id } : {}), ...(file.originalFileName ? { name: file.originalFileName } : {}), url }];\n });\n}\n\n/** URLs of the files a tool returned, stored on its ToolResult agentEvent. Empty while SolidX has not linked them yet. */\nexport async function fetchToolFileMedia(agentEventId: string | number): Promise<AgentToolFileMedia[]> {\n try {\n return toolFileMedia((await fetchEventMedia([agentEventId])).get(String(agentEventId)) ?? []);\n } catch {\n return [];\n }\n}\n\n/**\n * Replayed user messages only know their attachments' names, and tool calls only the names of the\n * files the tool returned. The files themselves are stored on the agentEvent (media field\n * `attachments`) by the agent, so fetch fresh URLs for every such event in one request and put them\n * on the thread items. Items are returned unchanged when nothing is stored or the request fails.\n */\nexport async function resolveAttachmentMedia(items: AgentChatItem[]): Promise<AgentChatItem[]> {\n const eventIds = items\n .map((item) => item.eventData?.agentEventId)\n .filter((id): id is string | number => id !== undefined && id !== null && id !== \"\");\n if (!eventIds.length) return items;\n\n let mediaByEvent: Map<string, StoredMedia[]>;\n try {\n mediaByEvent = await fetchEventMedia(eventIds);\n } catch {\n return items;\n }\n if (!mediaByEvent.size) return items;\n\n return items.map((item) => {\n const media = mediaByEvent.get(String(item.eventData?.agentEventId));\n if (!media) return item;\n if (item.eventType === AgentEventTypes.toolCalling) {\n const files = Array.isArray(item.eventData.files) ? item.eventData.files : [];\n return { ...item, eventData: { ...item.eventData, files: mergeToolFileMedia(files, toolFileMedia(media)) } };\n }\n const attachments: AgentAttachmentMeta[] = media.map((file) => ({\n name: file.originalFileName ?? \"attachment\",\n mimeType: file.mimeType ?? \"\",\n size: Number(file.fileSize ?? 0),\n url: normalizeAssetUrl(file._full_url),\n }));\n return { ...item, eventData: { ...item.eventData, attachments } };\n });\n}\n"]}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import qs from "qs";
|
|
2
2
|
import { solidGet } from "../../../../http/solidHttp";
|
|
3
3
|
import { normalizeAssetUrl } from "../../../../helpers/assetUrl";
|
|
4
|
-
import
|
|
4
|
+
import { mergeToolFileMedia, type AgentToolFileMedia } from "../toolFiles";
|
|
5
|
+
import { AgentEventTypes, type AgentAttachmentMeta, type AgentChatItem } from "../types";
|
|
5
6
|
|
|
6
7
|
/** Media field on the agentEvent model that stores chat attachments (solid-core metadata). */
|
|
7
8
|
const ATTACHMENTS_FIELD = "attachments";
|
|
8
9
|
|
|
9
|
-
type StoredMedia = { _full_url?: string; originalFileName?: string; mimeType?: string; fileSize?: number };
|
|
10
|
+
type StoredMedia = { id?: number | string; _full_url?: string; originalFileName?: string; mimeType?: string; fileSize?: number };
|
|
10
11
|
|
|
11
12
|
/** Solid's response interceptor wraps bodies as { data: <payload> }; find the records array. */
|
|
12
13
|
function unwrapRecords(body: any): any[] {
|
|
@@ -18,11 +19,50 @@ function unwrapRecords(body: any): any[] {
|
|
|
18
19
|
return [];
|
|
19
20
|
}
|
|
20
21
|
|
|
22
|
+
/** The stored media of each agentEvent, by event id. Throws when SolidX cannot be asked. */
|
|
23
|
+
async function fetchEventMedia(eventIds: Array<string | number>): Promise<Map<string, StoredMedia[]>> {
|
|
24
|
+
const query = qs.stringify(
|
|
25
|
+
{
|
|
26
|
+
filters: { id: { $in: eventIds.map(Number) } },
|
|
27
|
+
populateMedia: [ATTACHMENTS_FIELD],
|
|
28
|
+
fields: ["id"],
|
|
29
|
+
limit: eventIds.length,
|
|
30
|
+
offset: 0,
|
|
31
|
+
},
|
|
32
|
+
{ encodeValuesOnly: true },
|
|
33
|
+
);
|
|
34
|
+
const response = await solidGet(`/agent-event?${query}`);
|
|
35
|
+
const mediaByEvent = new Map<string, StoredMedia[]>();
|
|
36
|
+
unwrapRecords(response?.data).forEach((record) => {
|
|
37
|
+
const media: StoredMedia[] = record?._media?.[ATTACHMENTS_FIELD] ?? [];
|
|
38
|
+
if (media.length) mediaByEvent.set(String(record.id), media);
|
|
39
|
+
});
|
|
40
|
+
return mediaByEvent;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function toolFileMedia(media: StoredMedia[]): AgentToolFileMedia[] {
|
|
44
|
+
return media.flatMap((file) => {
|
|
45
|
+
const url = normalizeAssetUrl(file._full_url);
|
|
46
|
+
if (!url) return [];
|
|
47
|
+
const id = Number(file.id);
|
|
48
|
+
return [{ ...(Number.isInteger(id) ? { id } : {}), ...(file.originalFileName ? { name: file.originalFileName } : {}), url }];
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** URLs of the files a tool returned, stored on its ToolResult agentEvent. Empty while SolidX has not linked them yet. */
|
|
53
|
+
export async function fetchToolFileMedia(agentEventId: string | number): Promise<AgentToolFileMedia[]> {
|
|
54
|
+
try {
|
|
55
|
+
return toolFileMedia((await fetchEventMedia([agentEventId])).get(String(agentEventId)) ?? []);
|
|
56
|
+
} catch {
|
|
57
|
+
return [];
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
21
61
|
/**
|
|
22
|
-
* Replayed user messages only know their attachments' names
|
|
23
|
-
*
|
|
24
|
-
* such event in one request and put them
|
|
25
|
-
* when nothing is stored or the request fails.
|
|
62
|
+
* Replayed user messages only know their attachments' names, and tool calls only the names of the
|
|
63
|
+
* files the tool returned. The files themselves are stored on the agentEvent (media field
|
|
64
|
+
* `attachments`) by the agent, so fetch fresh URLs for every such event in one request and put them
|
|
65
|
+
* on the thread items. Items are returned unchanged when nothing is stored or the request fails.
|
|
26
66
|
*/
|
|
27
67
|
export async function resolveAttachmentMedia(items: AgentChatItem[]): Promise<AgentChatItem[]> {
|
|
28
68
|
const eventIds = items
|
|
@@ -30,34 +70,21 @@ export async function resolveAttachmentMedia(items: AgentChatItem[]): Promise<Ag
|
|
|
30
70
|
.filter((id): id is string | number => id !== undefined && id !== null && id !== "");
|
|
31
71
|
if (!eventIds.length) return items;
|
|
32
72
|
|
|
33
|
-
let
|
|
73
|
+
let mediaByEvent: Map<string, StoredMedia[]>;
|
|
34
74
|
try {
|
|
35
|
-
|
|
36
|
-
{
|
|
37
|
-
filters: { id: { $in: eventIds.map(Number) } },
|
|
38
|
-
populateMedia: [ATTACHMENTS_FIELD],
|
|
39
|
-
fields: ["id"],
|
|
40
|
-
limit: eventIds.length,
|
|
41
|
-
offset: 0,
|
|
42
|
-
},
|
|
43
|
-
{ encodeValuesOnly: true },
|
|
44
|
-
);
|
|
45
|
-
const response = await solidGet(`/agent-event?${query}`);
|
|
46
|
-
records = unwrapRecords(response?.data);
|
|
75
|
+
mediaByEvent = await fetchEventMedia(eventIds);
|
|
47
76
|
} catch {
|
|
48
77
|
return items;
|
|
49
78
|
}
|
|
50
|
-
|
|
51
|
-
const mediaByEvent = new Map<string, StoredMedia[]>();
|
|
52
|
-
records.forEach((record) => {
|
|
53
|
-
const media: StoredMedia[] = record?._media?.[ATTACHMENTS_FIELD] ?? [];
|
|
54
|
-
if (media.length) mediaByEvent.set(String(record.id), media);
|
|
55
|
-
});
|
|
56
79
|
if (!mediaByEvent.size) return items;
|
|
57
80
|
|
|
58
81
|
return items.map((item) => {
|
|
59
82
|
const media = mediaByEvent.get(String(item.eventData?.agentEventId));
|
|
60
83
|
if (!media) return item;
|
|
84
|
+
if (item.eventType === AgentEventTypes.toolCalling) {
|
|
85
|
+
const files = Array.isArray(item.eventData.files) ? item.eventData.files : [];
|
|
86
|
+
return { ...item, eventData: { ...item.eventData, files: mergeToolFileMedia(files, toolFileMedia(media)) } };
|
|
87
|
+
}
|
|
61
88
|
const attachments: AgentAttachmentMeta[] = media.map((file) => ({
|
|
62
89
|
name: file.originalFileName ?? "attachment",
|
|
63
90
|
mimeType: file.mimeType ?? "",
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type AgentState } from "../../../../redux/features/agentSlice";
|
|
2
2
|
import { type AgentRuntimeType, type AgentAttachment, type AgentContext, type AgentMessageContext, type AgentSessionOptions } from "../types";
|
|
3
|
+
import { AgentBrowserChannel } from "./agentBrowser";
|
|
3
4
|
import { AgentSocket } from "./agentSocket";
|
|
4
5
|
/**
|
|
5
6
|
* A live connection to one agent backend. The "solidx" runtime is shared by the floating window and
|
|
@@ -30,6 +31,8 @@ export declare class AgentRuntime {
|
|
|
30
31
|
readonly agentRuntime: AgentRuntimeType;
|
|
31
32
|
private persistSession;
|
|
32
33
|
readonly socket: AgentSocket;
|
|
34
|
+
/** Live view and control of the session's browser (AgentHub browser tools). */
|
|
35
|
+
readonly browser: AgentBrowserChannel;
|
|
33
36
|
private pendingDelta;
|
|
34
37
|
private frame;
|
|
35
38
|
private unsubscribers;
|
|
@@ -72,6 +75,8 @@ export declare class AgentRuntime {
|
|
|
72
75
|
dispose(): void;
|
|
73
76
|
private loadHistory;
|
|
74
77
|
private handleFrame;
|
|
78
|
+
/** Fetches the stored URLs of the screenshots and downloads a tool just returned. */
|
|
79
|
+
private resolveToolFiles;
|
|
75
80
|
private publish;
|
|
76
81
|
private lastTurnCompleteContent;
|
|
77
82
|
private lastTurnCompleteTime;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agentRuntime.d.ts","sourceRoot":"","sources":["../../../../../src/components/core/solid-agent/client/agentRuntime.ts"],"names":[],"mappings":"AAEA,OAAO,
|
|
1
|
+
{"version":3,"file":"agentRuntime.d.ts","sourceRoot":"","sources":["../../../../../src/components/core/solid-agent/client/agentRuntime.ts"],"names":[],"mappings":"AAEA,OAAO,EAQH,KAAK,UAAU,EAClB,MAAM,uCAAuC,CAAC;AAO/C,OAAO,EAAmB,KAAK,gBAAgB,EAAE,KAAK,eAAe,EAAuB,KAAK,YAAY,EAAE,KAAK,mBAAmB,EAAE,KAAK,mBAAmB,EAAuB,MAAM,UAAU,CAAC;AAEzM,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAGrD,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAG5C;;;;;;GAMG;AAEH,KAAK,QAAQ,GAAG,CAAC,MAAM,EAAE,GAAG,KAAK,GAAG,CAAC;AACrC,KAAK,aAAa,GAAG,MAAM,UAAU,GAAG,SAAS,CAAC;AA0BlD,wBAAgB,iBAAiB,IAAI,MAAM,CAM1C;AAED,wBAAgB,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAM9D;AAED,wBAAgB,yBAAyB,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,QAOzE;AAED,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAO3D;AAED,wBAAgB,kBAAkB,CAAC,QAAQ,EAA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E,QAAQ,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,mBAAmB;IAOxE,oBAAoB,CAAC,IAAI,EAAE,mBAAmB;IAM9C,MAAM,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,mBAAmB;IAkBjF,SAAS;IAMf,OAAO,CAAC,iBAAiB;IAOzB,OAAO;YAUO,WAAW;IAwCzB,OAAO,CAAC,WAAW;IAkEnB,qFAAqF;IACrF,OAAO,CAAC,gBAAgB;IAmBxB,OAAO,CAAC,OAAO;IAIf,OAAO,CAAC,uBAAuB,CAAuB;IACtD,OAAO,CAAC,oBAAoB,CAAK;IAEjC,OAAO,CAAC,aAAa;IAqCrB,OAAO,CAAC,WAAW;CAUtB;AAID,wFAAwF;AACxF,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,aAAa,GAAG,YAAY,CAQ9G;AAED,wBAAgB,eAAe,IAAI,YAAY,GAAG,IAAI,CAErD;AAED,kFAAkF;AAClF,wBAAgB,mBAAmB,SAIlC"}
|
|
@@ -47,7 +47,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
47
47
|
};
|
|
48
48
|
import { eventBus } from "../../../../helpers/eventBus";
|
|
49
49
|
import { getAgentChatWidgetCatalog } from "../../../../helpers/registry";
|
|
50
|
-
import { agentConnectionChanged, agentEventReceived, agentHistoryLoaded, agentHistoryLoadingChanged, agentThreadReset, agentUserMessageAdded, } from "../../../../redux/features/agentSlice";
|
|
50
|
+
import { agentConnectionChanged, agentEventReceived, agentHistoryLoaded, agentHistoryLoadingChanged, agentThreadReset, agentToolFilesResolved, agentUserMessageAdded, } from "../../../../redux/features/agentSlice";
|
|
51
51
|
import { historyToItems, isSameAssistantContent, normalizeAgentFrame } from "../agentEvents";
|
|
52
52
|
import { parseWidgetContent } from "../thread/inlineWidget";
|
|
53
53
|
import { humanReviewAllowsChoice, humanReviewId } from "../humanReview";
|
|
@@ -55,7 +55,8 @@ import { SOLID_AGENT_EVENTS } from "../sdk/solidAgent";
|
|
|
55
55
|
import { emitBeforeUserMessageSend } from "./beforeUserMessageSend";
|
|
56
56
|
import { emitAgentPublicEvent } from "./agentPublicEvents";
|
|
57
57
|
import { AgentEventTypes } from "../types";
|
|
58
|
-
import { resolveAttachmentMedia } from "./agentAttachmentMedia";
|
|
58
|
+
import { fetchToolFileMedia, resolveAttachmentMedia } from "./agentAttachmentMedia";
|
|
59
|
+
import { AgentBrowserChannel } from "./agentBrowser";
|
|
59
60
|
import { clearAllAgentAuth } from "./agentAuth";
|
|
60
61
|
import { fetchSessionHistory, uploadAgentAttachments } from "./agentRest";
|
|
61
62
|
import { AgentSocket } from "./agentSocket";
|
|
@@ -161,6 +162,8 @@ export function setStoredSessionOptions(provider, opts) {
|
|
|
161
162
|
// Storage blocked
|
|
162
163
|
}
|
|
163
164
|
}
|
|
165
|
+
/** Linking tool files to their event can lag the live ToolResult frame by a moment. */
|
|
166
|
+
var TOOL_FILE_RETRY_MS = [0, 1500, 4000];
|
|
164
167
|
var AgentRuntime = /** @class */ (function () {
|
|
165
168
|
function AgentRuntime(agentUrl, dispatch, getState, agentRuntime, persistSession, sessionOwnerKey, agentName) {
|
|
166
169
|
var _this = this;
|
|
@@ -203,6 +206,13 @@ var AgentRuntime = /** @class */ (function () {
|
|
|
203
206
|
writable: true,
|
|
204
207
|
value: void 0
|
|
205
208
|
});
|
|
209
|
+
/** Live view and control of the session's browser (AgentHub browser tools). */
|
|
210
|
+
Object.defineProperty(this, "browser", {
|
|
211
|
+
enumerable: true,
|
|
212
|
+
configurable: true,
|
|
213
|
+
writable: true,
|
|
214
|
+
value: void 0
|
|
215
|
+
});
|
|
206
216
|
Object.defineProperty(this, "pendingDelta", {
|
|
207
217
|
enumerable: true,
|
|
208
218
|
configurable: true,
|
|
@@ -297,7 +307,9 @@ var AgentRuntime = /** @class */ (function () {
|
|
|
297
307
|
speed: (_b = getStoredSpeed(initialProvider)) !== null && _b !== void 0 ? _b : undefined,
|
|
298
308
|
};
|
|
299
309
|
this.socket = new AgentSocket(agentUrl, persistSession ? readSessionId(this.sessionKey) : null, agentRuntime === "agentHub", initialProvider, initialModel, initialOptions, agentRuntime === "agentHub" ? getAgentChatWidgetCatalog(agentName) : []);
|
|
310
|
+
this.browser = new AgentBrowserChannel(this.socket);
|
|
300
311
|
this.socket.setOnSessionExpired(function () {
|
|
312
|
+
_this.browser.reset();
|
|
301
313
|
if (_this.persistSession)
|
|
302
314
|
writeSessionId(_this.sessionKey, null);
|
|
303
315
|
if (_this.frame != null) {
|
|
@@ -525,6 +537,7 @@ var AgentRuntime = /** @class */ (function () {
|
|
|
525
537
|
if (provider && opts)
|
|
526
538
|
setStoredSessionOptions(provider, opts);
|
|
527
539
|
this.lastContext = undefined;
|
|
540
|
+
this.browser.reset();
|
|
528
541
|
this.dispatch(agentThreadReset());
|
|
529
542
|
this.socket.newSession(__assign(__assign({}, (provider ? { provider: provider, model: model } : {})), (opts || {})));
|
|
530
543
|
}
|
|
@@ -572,6 +585,7 @@ var AgentRuntime = /** @class */ (function () {
|
|
|
572
585
|
setStoredProviderAndModel(provider, model);
|
|
573
586
|
if (provider && opts)
|
|
574
587
|
setStoredSessionOptions(provider, opts);
|
|
588
|
+
this.browser.reset();
|
|
575
589
|
this.dispatch(agentThreadReset());
|
|
576
590
|
this.dispatch(agentHistoryLoadingChanged(true));
|
|
577
591
|
this.socket.resume(sessionId, __assign(__assign({}, (provider ? { provider: provider, model: model } : {})), (opts || {})));
|
|
@@ -621,6 +635,7 @@ var AgentRuntime = /** @class */ (function () {
|
|
|
621
635
|
this.unsubscribers.forEach(function (off) { return off(); });
|
|
622
636
|
if (this.frame != null)
|
|
623
637
|
cancelAnimationFrame(this.frame);
|
|
638
|
+
this.browser.dispose();
|
|
624
639
|
this.socket.close();
|
|
625
640
|
}
|
|
626
641
|
});
|
|
@@ -700,6 +715,9 @@ var AgentRuntime = /** @class */ (function () {
|
|
|
700
715
|
var _this = this;
|
|
701
716
|
var _a, _b, _c, _d, _e;
|
|
702
717
|
var event = normalizeAgentFrame(frame);
|
|
718
|
+
// Browser frames stay out of Redux and the SDK events.
|
|
719
|
+
if (event.eventType.startsWith("browser_") && this.browser.handle(event.eventType, event.eventData))
|
|
720
|
+
return;
|
|
703
721
|
if (event.eventType === AgentEventTypes.sessionStarted) {
|
|
704
722
|
var state = this.getState();
|
|
705
723
|
if ((state === null || state === void 0 ? void 0 : state.pendingReview) || (state === null || state === void 0 ? void 0 : state.reviewResuming)) {
|
|
@@ -707,6 +725,7 @@ var AgentRuntime = /** @class */ (function () {
|
|
|
707
725
|
this.dispatch(agentThreadReset());
|
|
708
726
|
}
|
|
709
727
|
var sessionId = (_b = (_a = frame.session_id) !== null && _a !== void 0 ? _a : event.eventData.session_id) !== null && _b !== void 0 ? _b : null;
|
|
728
|
+
this.browser.sessionStarted(sessionId);
|
|
710
729
|
this.publish(this.hadPriorSession ? "onSessionResumed" : "onSessionStarted", { sessionId: sessionId });
|
|
711
730
|
this.hadPriorSession = true;
|
|
712
731
|
}
|
|
@@ -752,6 +771,72 @@ var AgentRuntime = /** @class */ (function () {
|
|
|
752
771
|
this.flushTokens();
|
|
753
772
|
this.dispatch(agentEventReceived(event));
|
|
754
773
|
this.emitSdkEvents(event);
|
|
774
|
+
if (event.eventType === AgentEventTypes.toolResult && this.persistSession)
|
|
775
|
+
this.resolveToolFiles(event.eventData);
|
|
776
|
+
}
|
|
777
|
+
});
|
|
778
|
+
/** Fetches the stored URLs of the screenshots and downloads a tool just returned. */
|
|
779
|
+
Object.defineProperty(AgentRuntime.prototype, "resolveToolFiles", {
|
|
780
|
+
enumerable: false,
|
|
781
|
+
configurable: true,
|
|
782
|
+
writable: true,
|
|
783
|
+
value: function (eventData) {
|
|
784
|
+
var _this = this;
|
|
785
|
+
var agentEventId = eventData.agentEventId;
|
|
786
|
+
var stored = Array.isArray(eventData.files) && eventData.files.some(function (file) { return (file === null || file === void 0 ? void 0 : file.mediaId) != null; });
|
|
787
|
+
if (agentEventId == null || !stored)
|
|
788
|
+
return;
|
|
789
|
+
var generation = this.historyGeneration;
|
|
790
|
+
void (function () { return __awaiter(_this, void 0, void 0, function () {
|
|
791
|
+
var _loop_1, this_1, _i, TOOL_FILE_RETRY_MS_1, delay, state_1;
|
|
792
|
+
return __generator(this, function (_a) {
|
|
793
|
+
switch (_a.label) {
|
|
794
|
+
case 0:
|
|
795
|
+
_loop_1 = function (delay) {
|
|
796
|
+
var media;
|
|
797
|
+
return __generator(this, function (_b) {
|
|
798
|
+
switch (_b.label) {
|
|
799
|
+
case 0:
|
|
800
|
+
if (!delay) return [3 /*break*/, 2];
|
|
801
|
+
return [4 /*yield*/, new Promise(function (resolve) { return setTimeout(resolve, delay); })];
|
|
802
|
+
case 1:
|
|
803
|
+
_b.sent();
|
|
804
|
+
_b.label = 2;
|
|
805
|
+
case 2:
|
|
806
|
+
if (generation !== this_1.historyGeneration)
|
|
807
|
+
return [2 /*return*/, { value: void 0 }];
|
|
808
|
+
return [4 /*yield*/, fetchToolFileMedia(agentEventId)];
|
|
809
|
+
case 3:
|
|
810
|
+
media = _b.sent();
|
|
811
|
+
if (generation !== this_1.historyGeneration)
|
|
812
|
+
return [2 /*return*/, { value: void 0 }];
|
|
813
|
+
if (media.length) {
|
|
814
|
+
this_1.dispatch(agentToolFilesResolved({ agentEventId: agentEventId, media: media }));
|
|
815
|
+
return [2 /*return*/, { value: void 0 }];
|
|
816
|
+
}
|
|
817
|
+
return [2 /*return*/];
|
|
818
|
+
}
|
|
819
|
+
});
|
|
820
|
+
};
|
|
821
|
+
this_1 = this;
|
|
822
|
+
_i = 0, TOOL_FILE_RETRY_MS_1 = TOOL_FILE_RETRY_MS;
|
|
823
|
+
_a.label = 1;
|
|
824
|
+
case 1:
|
|
825
|
+
if (!(_i < TOOL_FILE_RETRY_MS_1.length)) return [3 /*break*/, 4];
|
|
826
|
+
delay = TOOL_FILE_RETRY_MS_1[_i];
|
|
827
|
+
return [5 /*yield**/, _loop_1(delay)];
|
|
828
|
+
case 2:
|
|
829
|
+
state_1 = _a.sent();
|
|
830
|
+
if (typeof state_1 === "object")
|
|
831
|
+
return [2 /*return*/, state_1.value];
|
|
832
|
+
_a.label = 3;
|
|
833
|
+
case 3:
|
|
834
|
+
_i++;
|
|
835
|
+
return [3 /*break*/, 1];
|
|
836
|
+
case 4: return [2 /*return*/];
|
|
837
|
+
}
|
|
838
|
+
});
|
|
839
|
+
}); })();
|
|
755
840
|
}
|
|
756
841
|
});
|
|
757
842
|
Object.defineProperty(AgentRuntime.prototype, "publish", {
|
|
@@ -781,14 +866,14 @@ var AgentRuntime = /** @class */ (function () {
|
|
|
781
866
|
if (provider)
|
|
782
867
|
setStoredProviderAndModel(provider, model !== null && model !== void 0 ? model : undefined);
|
|
783
868
|
eventBus.emit(SOLID_AGENT_EVENTS.sessionChanged, { sessionId: sessionId, agentType: this.agentRuntime, provider: provider, model: model });
|
|
784
|
-
var
|
|
869
|
+
var state_2 = this.getState();
|
|
785
870
|
var historyId = (_h = (_g = event.frame.history_session_id) !== null && _g !== void 0 ? _g : event.eventData.history_session_id) !== null && _h !== void 0 ? _h : sessionId;
|
|
786
871
|
if (historyId !== this.historySessionId) {
|
|
787
872
|
this.resetHistoryLoads();
|
|
788
873
|
this.historySessionId = historyId;
|
|
789
874
|
}
|
|
790
|
-
if (event.eventType === AgentEventTypes.sessionStarted &&
|
|
791
|
-
|
|
875
|
+
if (event.eventType === AgentEventTypes.sessionStarted && state_2 &&
|
|
876
|
+
state_2.items.every(function (item) { var _a, _b; return item.id === humanReviewId((_b = (_a = state_2.pendingReview) === null || _a === void 0 ? void 0 : _a.requestId) !== null && _b !== void 0 ? _b : 0); }) && historyId) {
|
|
792
877
|
void this.loadHistory(historyId, 1);
|
|
793
878
|
}
|
|
794
879
|
else if (event.eventType === AgentEventTypes.sessionStarted)
|