@anvia/studio 0.5.5 → 0.5.7
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/index.d.ts +6 -1
- package/dist/index.js +194 -314
- package/dist/index.js.map +1 -1
- package/dist/ui/assets/ArrowClockwise.es-BmQVpKSP.js +2 -0
- package/dist/ui/assets/ArrowClockwise.es-BmQVpKSP.js.map +1 -0
- package/dist/ui/assets/Path.es-_A9Dgf5g.js +2 -0
- package/dist/ui/assets/Path.es-_A9Dgf5g.js.map +1 -0
- package/dist/ui/assets/Play.es-CD4VDp0t.js +2 -0
- package/dist/ui/assets/Play.es-CD4VDp0t.js.map +1 -0
- package/dist/ui/assets/agents-page-DhI_yXft.js +2 -0
- package/dist/ui/assets/agents-page-DhI_yXft.js.map +1 -0
- package/dist/ui/assets/badge-CNbpc5Sm.js +2 -0
- package/dist/ui/assets/badge-CNbpc5Sm.js.map +1 -0
- package/dist/ui/assets/evals-page-D7c1f_3g.js +2 -0
- package/dist/ui/assets/evals-page-D7c1f_3g.js.map +1 -0
- package/dist/ui/assets/index-BBfu6qlV.css +1 -0
- package/dist/ui/assets/index-ZVqWotd2.js +55 -0
- package/dist/ui/assets/index-ZVqWotd2.js.map +1 -0
- package/dist/ui/assets/jsx-runtime-ZfyQks-z.js +2 -0
- package/dist/ui/assets/jsx-runtime-ZfyQks-z.js.map +1 -0
- package/dist/ui/assets/knowledge-page-BC58KH0x.js +2 -0
- package/dist/ui/assets/knowledge-page-BC58KH0x.js.map +1 -0
- package/dist/ui/assets/mcps-page-q6-GgvSQ.js +2 -0
- package/dist/ui/assets/mcps-page-q6-GgvSQ.js.map +1 -0
- package/dist/ui/assets/memory-page-DzYytliI.js +2 -0
- package/dist/ui/assets/memory-page-DzYytliI.js.map +1 -0
- package/dist/ui/assets/pipelines-page-DtxX27Jz.css +1 -0
- package/dist/ui/assets/pipelines-page-waqYX8YQ.js +8 -0
- package/dist/ui/assets/pipelines-page-waqYX8YQ.js.map +1 -0
- package/dist/ui/assets/renderers-DBx9o89u.js +30 -0
- package/dist/ui/assets/renderers-DBx9o89u.js.map +1 -0
- package/dist/ui/assets/sessions-page-DrD_19ku.js +6 -0
- package/dist/ui/assets/sessions-page-DrD_19ku.js.map +1 -0
- package/dist/ui/assets/status-page-4-V7jY6F.js +2 -0
- package/dist/ui/assets/status-page-4-V7jY6F.js.map +1 -0
- package/dist/ui/assets/tools-page-DuyWVX2b.js +2 -0
- package/dist/ui/assets/tools-page-DuyWVX2b.js.map +1 -0
- package/dist/ui/assets/trace-browser-DwQWfo7X.js +10 -0
- package/dist/ui/assets/trace-browser-DwQWfo7X.js.map +1 -0
- package/dist/ui/assets/transcript-item-BJyZu-ue.js +3 -0
- package/dist/ui/assets/transcript-item-BJyZu-ue.js.map +1 -0
- package/dist/ui/index.html +3 -2
- package/package.json +7 -6
- package/dist/ui/assets/index-DMFsvim-.css +0 -1
- package/dist/ui/assets/index-LEUUFgN3.js +0 -101
- package/dist/ui/assets/index-LEUUFgN3.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -9,6 +9,64 @@ import { Pipeline } from "@anvia/core/pipeline";
|
|
|
9
9
|
import { serve } from "@hono/node-server";
|
|
10
10
|
import { Hono as HonoApp } from "hono";
|
|
11
11
|
|
|
12
|
+
// src/runtime/json.ts
|
|
13
|
+
function toJsonValue(value) {
|
|
14
|
+
return toJsonValueInternal(value, /* @__PURE__ */ new WeakSet());
|
|
15
|
+
}
|
|
16
|
+
function toJsonValueInternal(value, seen) {
|
|
17
|
+
if (value === null || typeof value === "string" || typeof value === "boolean") {
|
|
18
|
+
return value;
|
|
19
|
+
}
|
|
20
|
+
if (typeof value === "number") {
|
|
21
|
+
return Number.isFinite(value) ? value : String(value);
|
|
22
|
+
}
|
|
23
|
+
if (value === void 0) {
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
if (Array.isArray(value)) {
|
|
27
|
+
if (seen.has(value)) {
|
|
28
|
+
return "[Circular]";
|
|
29
|
+
}
|
|
30
|
+
seen.add(value);
|
|
31
|
+
try {
|
|
32
|
+
return value.map((item) => toJsonValueInternal(item, seen));
|
|
33
|
+
} finally {
|
|
34
|
+
seen.delete(value);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
if (typeof value === "object") {
|
|
38
|
+
if (seen.has(value)) {
|
|
39
|
+
return "[Circular]";
|
|
40
|
+
}
|
|
41
|
+
seen.add(value);
|
|
42
|
+
try {
|
|
43
|
+
return compactJsonObjectInternal(value, seen);
|
|
44
|
+
} finally {
|
|
45
|
+
seen.delete(value);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return String(value);
|
|
49
|
+
}
|
|
50
|
+
function compactJsonObject(values) {
|
|
51
|
+
return compactJsonObjectInternal(values, /* @__PURE__ */ new WeakSet());
|
|
52
|
+
}
|
|
53
|
+
function compactJsonObjectInternal(values, seen) {
|
|
54
|
+
const entries = Object.entries(values).flatMap(
|
|
55
|
+
([key, value]) => value === void 0 ? [] : [[key, toJsonValueInternal(value, seen)]]
|
|
56
|
+
);
|
|
57
|
+
return Object.fromEntries(entries);
|
|
58
|
+
}
|
|
59
|
+
function serializeUnknown(error) {
|
|
60
|
+
if (error instanceof Error) {
|
|
61
|
+
return compactJsonObject({
|
|
62
|
+
name: error.name,
|
|
63
|
+
message: error.message,
|
|
64
|
+
stack: error.stack
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
return toJsonValue(error);
|
|
68
|
+
}
|
|
69
|
+
|
|
12
70
|
// src/traces/trace-observer.ts
|
|
13
71
|
var StudioTraceObserver = class {
|
|
14
72
|
constructor(options) {
|
|
@@ -64,7 +122,7 @@ var StudioRunTraceObserver = class {
|
|
|
64
122
|
turn: args.turn,
|
|
65
123
|
startedAt,
|
|
66
124
|
input: toJsonValue(args.request),
|
|
67
|
-
error:
|
|
125
|
+
error: serializeUnknown(errorArgs.error),
|
|
68
126
|
metadata: generationMetadata(args)
|
|
69
127
|
})
|
|
70
128
|
);
|
|
@@ -100,7 +158,7 @@ var StudioRunTraceObserver = class {
|
|
|
100
158
|
turn: args.turn,
|
|
101
159
|
startedAt,
|
|
102
160
|
input: parseOrString(args.args),
|
|
103
|
-
error:
|
|
161
|
+
error: serializeUnknown(errorArgs.error),
|
|
104
162
|
metadata: toolMetadata(args, false)
|
|
105
163
|
});
|
|
106
164
|
this.observations.push(parentObservation);
|
|
@@ -119,7 +177,7 @@ var StudioRunTraceObserver = class {
|
|
|
119
177
|
async error(args) {
|
|
120
178
|
await this.save("error", {
|
|
121
179
|
endedAt: /* @__PURE__ */ new Date(),
|
|
122
|
-
error:
|
|
180
|
+
error: serializeUnknown(args.error),
|
|
123
181
|
usage: args.usage,
|
|
124
182
|
messages: toJsonValue(args.messages)
|
|
125
183
|
});
|
|
@@ -263,7 +321,7 @@ var ChildAgentToolTraceAccumulator = class {
|
|
|
263
321
|
status: "error",
|
|
264
322
|
turn: this.parent.turn,
|
|
265
323
|
startedAt: /* @__PURE__ */ new Date(),
|
|
266
|
-
error:
|
|
324
|
+
error: serializeUnknown(child.error),
|
|
267
325
|
metadata: this.childMetadata(agentId, agentName, childTurn)
|
|
268
326
|
})
|
|
269
327
|
);
|
|
@@ -493,12 +551,6 @@ function toolMetadata(args, skipped, result) {
|
|
|
493
551
|
function byteLength(value) {
|
|
494
552
|
return new TextEncoder().encode(value).length;
|
|
495
553
|
}
|
|
496
|
-
function compactJsonObject(values) {
|
|
497
|
-
const entries = Object.entries(values).flatMap(
|
|
498
|
-
([key, value]) => value === void 0 ? [] : [[key, toJsonValue(value)]]
|
|
499
|
-
);
|
|
500
|
-
return Object.fromEntries(entries);
|
|
501
|
-
}
|
|
502
554
|
function durationMs(startedAt, endedAt) {
|
|
503
555
|
return Math.max(0, endedAt.getTime() - startedAt.getTime());
|
|
504
556
|
}
|
|
@@ -515,31 +567,6 @@ function isRecord(value) {
|
|
|
515
567
|
function stringValue(value) {
|
|
516
568
|
return typeof value === "string" ? value : void 0;
|
|
517
569
|
}
|
|
518
|
-
function serializeError(error) {
|
|
519
|
-
if (error instanceof Error) {
|
|
520
|
-
return compactJsonObject({
|
|
521
|
-
name: error.name,
|
|
522
|
-
message: error.message,
|
|
523
|
-
stack: error.stack
|
|
524
|
-
});
|
|
525
|
-
}
|
|
526
|
-
return toJsonValue(error);
|
|
527
|
-
}
|
|
528
|
-
function toJsonValue(value) {
|
|
529
|
-
if (value === null || typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
|
|
530
|
-
return value;
|
|
531
|
-
}
|
|
532
|
-
if (value === void 0) {
|
|
533
|
-
return null;
|
|
534
|
-
}
|
|
535
|
-
if (Array.isArray(value)) {
|
|
536
|
-
return value.map((item) => toJsonValue(item));
|
|
537
|
-
}
|
|
538
|
-
if (typeof value === "object") {
|
|
539
|
-
return compactJsonObject(value);
|
|
540
|
-
}
|
|
541
|
-
return String(value);
|
|
542
|
-
}
|
|
543
570
|
|
|
544
571
|
// src/ui/routes.tsx
|
|
545
572
|
import { readFile } from "fs/promises";
|
|
@@ -798,6 +825,88 @@ import {
|
|
|
798
825
|
parseToolArgs
|
|
799
826
|
} from "@anvia/core/tool";
|
|
800
827
|
|
|
828
|
+
// src/runtime/transcript.ts
|
|
829
|
+
function renumberTranscript(entries) {
|
|
830
|
+
return entries.map((entry, entryId) => ({ ...entry, entryId }));
|
|
831
|
+
}
|
|
832
|
+
function transcriptFromMessages(messages) {
|
|
833
|
+
const transcript = [];
|
|
834
|
+
for (const message of messages) {
|
|
835
|
+
if (message.role === "system") {
|
|
836
|
+
continue;
|
|
837
|
+
}
|
|
838
|
+
if (message.role === "user") {
|
|
839
|
+
for (const content of message.content) {
|
|
840
|
+
if (content.type === "text") {
|
|
841
|
+
transcript.push({
|
|
842
|
+
entryId: transcript.length,
|
|
843
|
+
kind: "message",
|
|
844
|
+
role: "user",
|
|
845
|
+
text: content.text
|
|
846
|
+
});
|
|
847
|
+
}
|
|
848
|
+
}
|
|
849
|
+
continue;
|
|
850
|
+
}
|
|
851
|
+
if (message.role === "tool") {
|
|
852
|
+
for (const content of message.content) {
|
|
853
|
+
transcript.push({
|
|
854
|
+
entryId: transcript.length,
|
|
855
|
+
kind: "tool",
|
|
856
|
+
toolName: "tool_result",
|
|
857
|
+
callId: content.callId ?? content.id,
|
|
858
|
+
result: content.content.map(
|
|
859
|
+
(item) => "text" in item ? item.text : `[image:${item.mediaType ?? "image/png"}]`
|
|
860
|
+
).join("\n"),
|
|
861
|
+
structuredResult: content.content
|
|
862
|
+
});
|
|
863
|
+
}
|
|
864
|
+
continue;
|
|
865
|
+
}
|
|
866
|
+
for (const content of message.content) {
|
|
867
|
+
if (content.type === "text") {
|
|
868
|
+
appendAssistantTranscriptText(transcript, content.text);
|
|
869
|
+
} else if (content.type === "reasoning") {
|
|
870
|
+
transcript.push({
|
|
871
|
+
entryId: transcript.length,
|
|
872
|
+
kind: "reasoning",
|
|
873
|
+
...content.id === void 0 ? {} : { reasoningId: content.id },
|
|
874
|
+
text: content.text
|
|
875
|
+
});
|
|
876
|
+
} else if (content.type === "tool_call") {
|
|
877
|
+
transcript.push({
|
|
878
|
+
entryId: transcript.length,
|
|
879
|
+
kind: "tool",
|
|
880
|
+
toolName: content.function.name,
|
|
881
|
+
callId: content.callId ?? content.id,
|
|
882
|
+
args: formatJson(content.function.arguments)
|
|
883
|
+
});
|
|
884
|
+
}
|
|
885
|
+
}
|
|
886
|
+
}
|
|
887
|
+
return transcript;
|
|
888
|
+
}
|
|
889
|
+
function appendAssistantTranscriptText(transcript, text) {
|
|
890
|
+
const last = transcript.at(-1);
|
|
891
|
+
if (last?.kind === "message" && last.role === "assistant") {
|
|
892
|
+
last.text = `${last.text}${text}`;
|
|
893
|
+
return;
|
|
894
|
+
}
|
|
895
|
+
transcript.push({
|
|
896
|
+
entryId: transcript.length,
|
|
897
|
+
kind: "message",
|
|
898
|
+
role: "assistant",
|
|
899
|
+
text
|
|
900
|
+
});
|
|
901
|
+
}
|
|
902
|
+
function formatJson(value) {
|
|
903
|
+
try {
|
|
904
|
+
return JSON.stringify(value, null, 2);
|
|
905
|
+
} catch {
|
|
906
|
+
return String(value);
|
|
907
|
+
}
|
|
908
|
+
}
|
|
909
|
+
|
|
801
910
|
// src/storage/memory-store.ts
|
|
802
911
|
function createInMemoryStudioStore() {
|
|
803
912
|
return new InMemoryStudioStore();
|
|
@@ -858,7 +967,7 @@ var InMemoryStudioStore = class {
|
|
|
858
967
|
await this.saveSessionRunTranscript({
|
|
859
968
|
id: input.context.sessionId,
|
|
860
969
|
runId: studioRunId(input.context) ?? input.runId,
|
|
861
|
-
transcript:
|
|
970
|
+
transcript: transcriptFromMessages(input.messages),
|
|
862
971
|
status: "error",
|
|
863
972
|
error: serializeJsonError(input.error)
|
|
864
973
|
});
|
|
@@ -965,6 +1074,10 @@ var InMemoryStudioStore = class {
|
|
|
965
1074
|
this.pipelineRuns.set(input.runId, record);
|
|
966
1075
|
return record;
|
|
967
1076
|
}
|
|
1077
|
+
getPipelineRun(options) {
|
|
1078
|
+
const run = this.pipelineRuns.get(options.runId);
|
|
1079
|
+
return run?.pipelineId === options.pipelineId ? run : void 0;
|
|
1080
|
+
}
|
|
968
1081
|
listPipelineRuns(options) {
|
|
969
1082
|
return [...this.pipelineRuns.values()].filter((run) => run.pipelineId === options.pipelineId).sort((left, right) => Date.parse(right.startedAt) - Date.parse(left.startedAt)).slice(0, options.limit);
|
|
970
1083
|
}
|
|
@@ -1007,9 +1120,6 @@ function traceAgentId(trace) {
|
|
|
1007
1120
|
const nestedMetadata = trace.metadata?.metadata;
|
|
1008
1121
|
return isJsonObject(nestedMetadata) && typeof nestedMetadata.agentId === "string" ? nestedMetadata.agentId : void 0;
|
|
1009
1122
|
}
|
|
1010
|
-
function renumberTranscript(entries) {
|
|
1011
|
-
return entries.map((entry, entryId) => ({ ...entry, entryId }));
|
|
1012
|
-
}
|
|
1013
1123
|
function studioRunId(context) {
|
|
1014
1124
|
const value = context.metadata?.studioRunId;
|
|
1015
1125
|
return typeof value === "string" && value.length > 0 ? value : void 0;
|
|
@@ -1023,40 +1133,6 @@ function serializeJsonError(error) {
|
|
|
1023
1133
|
}
|
|
1024
1134
|
return isJsonValue(error) ? error : String(error);
|
|
1025
1135
|
}
|
|
1026
|
-
function transcriptFromMessagesFallback(messages) {
|
|
1027
|
-
const transcript = [];
|
|
1028
|
-
for (const message of messages) {
|
|
1029
|
-
if (message.role === "system") {
|
|
1030
|
-
continue;
|
|
1031
|
-
}
|
|
1032
|
-
if (message.role === "user") {
|
|
1033
|
-
for (const content of message.content) {
|
|
1034
|
-
if (content.type === "text") {
|
|
1035
|
-
transcript.push({
|
|
1036
|
-
entryId: transcript.length,
|
|
1037
|
-
kind: "message",
|
|
1038
|
-
role: "user",
|
|
1039
|
-
text: content.text
|
|
1040
|
-
});
|
|
1041
|
-
}
|
|
1042
|
-
}
|
|
1043
|
-
continue;
|
|
1044
|
-
}
|
|
1045
|
-
if (message.role === "assistant") {
|
|
1046
|
-
for (const content of message.content) {
|
|
1047
|
-
if (content.type === "text") {
|
|
1048
|
-
transcript.push({
|
|
1049
|
-
entryId: transcript.length,
|
|
1050
|
-
kind: "message",
|
|
1051
|
-
role: "assistant",
|
|
1052
|
-
text: content.text
|
|
1053
|
-
});
|
|
1054
|
-
}
|
|
1055
|
-
}
|
|
1056
|
-
}
|
|
1057
|
-
}
|
|
1058
|
-
return transcript;
|
|
1059
|
-
}
|
|
1060
1136
|
function isJsonObject(value) {
|
|
1061
1137
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1062
1138
|
}
|
|
@@ -1204,7 +1280,7 @@ var SqliteSessionStore = class {
|
|
|
1204
1280
|
async recordError(input) {
|
|
1205
1281
|
const runId = studioRunId2(input.context) ?? input.runId;
|
|
1206
1282
|
const existing = this.getSessionRun(input.context.sessionId, runId);
|
|
1207
|
-
const transcript = existing === void 0 || parseJsonArray(existing.transcript_json).length === 0 ?
|
|
1283
|
+
const transcript = existing === void 0 || parseJsonArray(existing.transcript_json).length === 0 ? transcriptFromMessages(input.messages) : parseJsonArray(existing.transcript_json);
|
|
1208
1284
|
await this.saveSessionRunTranscript({
|
|
1209
1285
|
id: input.context.sessionId,
|
|
1210
1286
|
runId,
|
|
@@ -1260,7 +1336,7 @@ var SqliteSessionStore = class {
|
|
|
1260
1336
|
$sessionId: input.id,
|
|
1261
1337
|
$status: input.status,
|
|
1262
1338
|
$title: input.title ?? null,
|
|
1263
|
-
$transcript: JSON.stringify(
|
|
1339
|
+
$transcript: JSON.stringify(renumberTranscript(input.transcript)),
|
|
1264
1340
|
$error: input.error === void 0 ? null : JSON.stringify(input.error),
|
|
1265
1341
|
$now: now
|
|
1266
1342
|
});
|
|
@@ -1511,6 +1587,19 @@ var SqliteSessionStore = class {
|
|
|
1511
1587
|
...input.durationMs === void 0 ? {} : { durationMs: input.durationMs }
|
|
1512
1588
|
};
|
|
1513
1589
|
}
|
|
1590
|
+
getPipelineRun(options) {
|
|
1591
|
+
const db = this.database();
|
|
1592
|
+
const row = db.prepare(
|
|
1593
|
+
`SELECT run_id, pipeline_id, status, input_json, output_json, error_json,
|
|
1594
|
+
metadata_json, started_at, ended_at, duration_ms
|
|
1595
|
+
FROM anvia_studio_pipeline_runs
|
|
1596
|
+
WHERE pipeline_id = $pipelineId AND run_id = $runId`
|
|
1597
|
+
).get({
|
|
1598
|
+
$pipelineId: options.pipelineId,
|
|
1599
|
+
$runId: options.runId
|
|
1600
|
+
});
|
|
1601
|
+
return row === void 0 ? void 0 : toPipelineRun(row);
|
|
1602
|
+
}
|
|
1514
1603
|
listPipelineRuns(options) {
|
|
1515
1604
|
const db = this.database();
|
|
1516
1605
|
const rows = db.prepare(
|
|
@@ -1918,7 +2007,7 @@ function toSession(row, messages, runRows = []) {
|
|
|
1918
2007
|
return {
|
|
1919
2008
|
...summary,
|
|
1920
2009
|
messages,
|
|
1921
|
-
transcript:
|
|
2010
|
+
transcript: renumberTranscript(runTranscript)
|
|
1922
2011
|
};
|
|
1923
2012
|
}
|
|
1924
2013
|
function toSessionSummary(row) {
|
|
@@ -2086,9 +2175,6 @@ function parseJsonValue(value) {
|
|
|
2086
2175
|
}
|
|
2087
2176
|
return JSON.parse(value);
|
|
2088
2177
|
}
|
|
2089
|
-
function renumberTranscript2(entries) {
|
|
2090
|
-
return entries.map((entry, entryId) => ({ ...entry, entryId }));
|
|
2091
|
-
}
|
|
2092
2178
|
function studioRunId2(context) {
|
|
2093
2179
|
const value = context.metadata?.studioRunId;
|
|
2094
2180
|
return typeof value === "string" && value.length > 0 ? value : void 0;
|
|
@@ -2105,138 +2191,6 @@ function serializeJsonError2(error) {
|
|
|
2105
2191
|
}
|
|
2106
2192
|
return String(error);
|
|
2107
2193
|
}
|
|
2108
|
-
function transcriptFromMessagesFallback2(messages) {
|
|
2109
|
-
const transcript = [];
|
|
2110
|
-
for (const message of messages) {
|
|
2111
|
-
if (message.role === "system") {
|
|
2112
|
-
continue;
|
|
2113
|
-
}
|
|
2114
|
-
if (message.role === "user") {
|
|
2115
|
-
for (const content of message.content) {
|
|
2116
|
-
if (content.type === "text") {
|
|
2117
|
-
transcript.push({
|
|
2118
|
-
entryId: transcript.length,
|
|
2119
|
-
kind: "message",
|
|
2120
|
-
role: "user",
|
|
2121
|
-
text: content.text
|
|
2122
|
-
});
|
|
2123
|
-
}
|
|
2124
|
-
}
|
|
2125
|
-
continue;
|
|
2126
|
-
}
|
|
2127
|
-
if (message.role === "tool") {
|
|
2128
|
-
for (const content of message.content) {
|
|
2129
|
-
transcript.push({
|
|
2130
|
-
entryId: transcript.length,
|
|
2131
|
-
kind: "tool",
|
|
2132
|
-
toolName: "tool_result",
|
|
2133
|
-
callId: content.callId ?? content.id,
|
|
2134
|
-
result: content.content.map(
|
|
2135
|
-
(item) => "text" in item ? item.text : `[image:${item.mediaType ?? "image/png"}]`
|
|
2136
|
-
).join("\n"),
|
|
2137
|
-
structuredResult: content.content
|
|
2138
|
-
});
|
|
2139
|
-
}
|
|
2140
|
-
continue;
|
|
2141
|
-
}
|
|
2142
|
-
for (const content of message.content) {
|
|
2143
|
-
if (content.type === "text") {
|
|
2144
|
-
appendAssistantTranscriptText(transcript, content.text);
|
|
2145
|
-
} else if (content.type === "reasoning") {
|
|
2146
|
-
transcript.push({
|
|
2147
|
-
entryId: transcript.length,
|
|
2148
|
-
kind: "reasoning",
|
|
2149
|
-
...content.id === void 0 ? {} : { reasoningId: content.id },
|
|
2150
|
-
text: content.text
|
|
2151
|
-
});
|
|
2152
|
-
} else if (content.type === "tool_call") {
|
|
2153
|
-
transcript.push({
|
|
2154
|
-
entryId: transcript.length,
|
|
2155
|
-
kind: "tool",
|
|
2156
|
-
toolName: content.function.name,
|
|
2157
|
-
callId: content.callId ?? content.id,
|
|
2158
|
-
args: formatJson(content.function.arguments)
|
|
2159
|
-
});
|
|
2160
|
-
}
|
|
2161
|
-
}
|
|
2162
|
-
}
|
|
2163
|
-
return transcript;
|
|
2164
|
-
}
|
|
2165
|
-
function appendAssistantTranscriptText(transcript, text) {
|
|
2166
|
-
const last = transcript.at(-1);
|
|
2167
|
-
if (last?.kind === "message" && last.role === "assistant") {
|
|
2168
|
-
last.text = `${last.text}${text}`;
|
|
2169
|
-
return;
|
|
2170
|
-
}
|
|
2171
|
-
transcript.push({
|
|
2172
|
-
entryId: transcript.length,
|
|
2173
|
-
kind: "message",
|
|
2174
|
-
role: "assistant",
|
|
2175
|
-
text
|
|
2176
|
-
});
|
|
2177
|
-
}
|
|
2178
|
-
function formatJson(value) {
|
|
2179
|
-
try {
|
|
2180
|
-
return JSON.stringify(value, null, 2);
|
|
2181
|
-
} catch {
|
|
2182
|
-
return String(value);
|
|
2183
|
-
}
|
|
2184
|
-
}
|
|
2185
|
-
|
|
2186
|
-
// src/runtime/json.ts
|
|
2187
|
-
function toJsonValue2(value) {
|
|
2188
|
-
return toJsonValueInternal(value, /* @__PURE__ */ new WeakSet());
|
|
2189
|
-
}
|
|
2190
|
-
function toJsonValueInternal(value, seen) {
|
|
2191
|
-
if (value === null || typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
|
|
2192
|
-
return value;
|
|
2193
|
-
}
|
|
2194
|
-
if (value === void 0) {
|
|
2195
|
-
return null;
|
|
2196
|
-
}
|
|
2197
|
-
if (Array.isArray(value)) {
|
|
2198
|
-
if (seen.has(value)) {
|
|
2199
|
-
return "[Circular]";
|
|
2200
|
-
}
|
|
2201
|
-
seen.add(value);
|
|
2202
|
-
try {
|
|
2203
|
-
return value.map((item) => toJsonValueInternal(item, seen));
|
|
2204
|
-
} finally {
|
|
2205
|
-
seen.delete(value);
|
|
2206
|
-
}
|
|
2207
|
-
}
|
|
2208
|
-
if (typeof value === "object") {
|
|
2209
|
-
if (seen.has(value)) {
|
|
2210
|
-
return "[Circular]";
|
|
2211
|
-
}
|
|
2212
|
-
seen.add(value);
|
|
2213
|
-
try {
|
|
2214
|
-
return compactJsonObjectInternal(value, seen);
|
|
2215
|
-
} finally {
|
|
2216
|
-
seen.delete(value);
|
|
2217
|
-
}
|
|
2218
|
-
}
|
|
2219
|
-
return String(value);
|
|
2220
|
-
}
|
|
2221
|
-
function compactJsonObject2(values) {
|
|
2222
|
-
return compactJsonObjectInternal(values, /* @__PURE__ */ new WeakSet());
|
|
2223
|
-
}
|
|
2224
|
-
function compactJsonObjectInternal(values, seen) {
|
|
2225
|
-
const entries = Object.entries(values).flatMap(
|
|
2226
|
-
([key, value]) => value === void 0 ? [] : [[key, toJsonValueInternal(value, seen)]]
|
|
2227
|
-
);
|
|
2228
|
-
return Object.fromEntries(entries);
|
|
2229
|
-
}
|
|
2230
|
-
function serializeUnknown(error) {
|
|
2231
|
-
if (error instanceof Error) {
|
|
2232
|
-
return compactJsonObject2({
|
|
2233
|
-
name: error.name,
|
|
2234
|
-
message: error.message,
|
|
2235
|
-
stack: error.stack
|
|
2236
|
-
});
|
|
2237
|
-
}
|
|
2238
|
-
return toJsonValue2(error);
|
|
2239
|
-
}
|
|
2240
2194
|
|
|
2241
2195
|
// src/runtime/tool-metadata.ts
|
|
2242
2196
|
import { ToolSet } from "@anvia/core/tool";
|
|
@@ -2353,7 +2307,7 @@ function isPipelineLogStore(store) {
|
|
|
2353
2307
|
}
|
|
2354
2308
|
function isPipelineRunStore(store) {
|
|
2355
2309
|
const candidate = store;
|
|
2356
|
-
return typeof candidate.savePipelineRun === "function" && typeof candidate.listPipelineRuns === "function";
|
|
2310
|
+
return typeof candidate.savePipelineRun === "function" && typeof candidate.getPipelineRun === "function" && typeof candidate.listPipelineRuns === "function";
|
|
2357
2311
|
}
|
|
2358
2312
|
function unsupportedCapabilities(stores) {
|
|
2359
2313
|
return [
|
|
@@ -2427,7 +2381,7 @@ function agentRuntimeSummary(agent) {
|
|
|
2427
2381
|
id: agent.id,
|
|
2428
2382
|
...name === void 0 ? {} : { name },
|
|
2429
2383
|
...description === void 0 ? {} : { description },
|
|
2430
|
-
model:
|
|
2384
|
+
model: toJsonValue(agent.agent.model),
|
|
2431
2385
|
toolCount: tools.length,
|
|
2432
2386
|
staticToolCount: tools.filter((item) => item.source === "static").length,
|
|
2433
2387
|
dynamicToolCount: tools.filter((item) => item.source === "dynamic").length,
|
|
@@ -2604,15 +2558,8 @@ function errorResponse(c, status, code, message, details) {
|
|
|
2604
2558
|
}
|
|
2605
2559
|
return c.json(body, status);
|
|
2606
2560
|
}
|
|
2607
|
-
function
|
|
2608
|
-
|
|
2609
|
-
return {
|
|
2610
|
-
name: error.name,
|
|
2611
|
-
message: error.message,
|
|
2612
|
-
...error.stack === void 0 ? {} : { stack: error.stack }
|
|
2613
|
-
};
|
|
2614
|
-
}
|
|
2615
|
-
return isJsonValue2(error) ? error : String(error);
|
|
2561
|
+
function serializeError(error) {
|
|
2562
|
+
return serializeUnknown(error);
|
|
2616
2563
|
}
|
|
2617
2564
|
|
|
2618
2565
|
// src/runtime/approvals.ts
|
|
@@ -2890,7 +2837,7 @@ function registerEvalRoutes(app, props) {
|
|
|
2890
2837
|
...body.concurrency === void 0 ? {} : { concurrency: body.concurrency }
|
|
2891
2838
|
});
|
|
2892
2839
|
const endedAt = Date.now();
|
|
2893
|
-
const jsonResult =
|
|
2840
|
+
const jsonResult = toJsonValue(result);
|
|
2894
2841
|
const response = {
|
|
2895
2842
|
runId,
|
|
2896
2843
|
suiteId: suite.id ?? suite.name,
|
|
@@ -3125,7 +3072,7 @@ function dynamicContextItem(item) {
|
|
|
3125
3072
|
return {
|
|
3126
3073
|
id: item.id,
|
|
3127
3074
|
kind: "dynamic_context",
|
|
3128
|
-
...text === void 0 ? { document:
|
|
3075
|
+
...text === void 0 ? { document: toJsonValue(item.document) } : { text },
|
|
3129
3076
|
...item.metadata === void 0 ? {} : { metadata: jsonObjectFromRecord(item.metadata) }
|
|
3130
3077
|
};
|
|
3131
3078
|
}
|
|
@@ -3140,7 +3087,7 @@ function dynamicToolItem(item) {
|
|
|
3140
3087
|
toolName,
|
|
3141
3088
|
description,
|
|
3142
3089
|
parameterKeys: parameterKeys(definition.parameters),
|
|
3143
|
-
document:
|
|
3090
|
+
document: toJsonValue(item.document),
|
|
3144
3091
|
...item.metadata === void 0 ? {} : { metadata: jsonObjectFromRecord(item.metadata) }
|
|
3145
3092
|
};
|
|
3146
3093
|
}
|
|
@@ -3290,7 +3237,7 @@ function evidenceToolName(value) {
|
|
|
3290
3237
|
return [value.name];
|
|
3291
3238
|
}
|
|
3292
3239
|
function jsonObjectFromRecord(value) {
|
|
3293
|
-
return
|
|
3240
|
+
return compactJsonObject(value);
|
|
3294
3241
|
}
|
|
3295
3242
|
function isRecord2(value) {
|
|
3296
3243
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
@@ -3491,7 +3438,7 @@ function withStudioStreamErrors(events) {
|
|
|
3491
3438
|
function studioStreamError(error) {
|
|
3492
3439
|
return {
|
|
3493
3440
|
type: "error",
|
|
3494
|
-
error:
|
|
3441
|
+
error: serializeError(error)
|
|
3495
3442
|
};
|
|
3496
3443
|
}
|
|
3497
3444
|
|
|
@@ -3743,7 +3690,7 @@ function pipelineRunFailedLog(pipelineId, runId, error, startedAt) {
|
|
|
3743
3690
|
message: "Pipeline run failed",
|
|
3744
3691
|
metadata: cleanMetadata({
|
|
3745
3692
|
durationMs: Date.now() - startedAt,
|
|
3746
|
-
error:
|
|
3693
|
+
error: serializeError(error)
|
|
3747
3694
|
})
|
|
3748
3695
|
};
|
|
3749
3696
|
}
|
|
@@ -3784,7 +3731,7 @@ function pipelineStageLog(pipelineId, runId, event) {
|
|
|
3784
3731
|
metadata: cleanMetadata({
|
|
3785
3732
|
...nodeMetadata(event.node),
|
|
3786
3733
|
durationMs: event.durationMs,
|
|
3787
|
-
error:
|
|
3734
|
+
error: serializeError(event.error)
|
|
3788
3735
|
})
|
|
3789
3736
|
};
|
|
3790
3737
|
}
|
|
@@ -3932,7 +3879,7 @@ async function* persistStreamingSessionTranscript(props) {
|
|
|
3932
3879
|
...title,
|
|
3933
3880
|
transcript,
|
|
3934
3881
|
status: event.type === "final" ? "success" : event.type === "error" ? "error" : "running",
|
|
3935
|
-
...event.type === "error" ? { error:
|
|
3882
|
+
...event.type === "error" ? { error: serializeError(event.error) } : {}
|
|
3936
3883
|
});
|
|
3937
3884
|
if (nextSession === void 0) {
|
|
3938
3885
|
throw new Error("Session not found");
|
|
@@ -3947,7 +3894,7 @@ async function* persistStreamingSessionTranscript(props) {
|
|
|
3947
3894
|
...title,
|
|
3948
3895
|
transcript,
|
|
3949
3896
|
status: "error",
|
|
3950
|
-
error:
|
|
3897
|
+
error: serializeError(error)
|
|
3951
3898
|
});
|
|
3952
3899
|
throw error;
|
|
3953
3900
|
}
|
|
@@ -4169,7 +4116,7 @@ function errorText(error) {
|
|
|
4169
4116
|
if (typeof error === "string") {
|
|
4170
4117
|
return error;
|
|
4171
4118
|
}
|
|
4172
|
-
return JSON.stringify(
|
|
4119
|
+
return JSON.stringify(serializeError(error));
|
|
4173
4120
|
}
|
|
4174
4121
|
function findChildAgentToolEvent(childEvents, event) {
|
|
4175
4122
|
for (let index = childEvents.length - 1; index >= 0; index -= 1) {
|
|
@@ -4183,58 +4130,6 @@ function findChildAgentToolEvent(childEvents, event) {
|
|
|
4183
4130
|
}
|
|
4184
4131
|
return void 0;
|
|
4185
4132
|
}
|
|
4186
|
-
function transcriptFromMessages(messages) {
|
|
4187
|
-
const transcript = [];
|
|
4188
|
-
for (const message of messages) {
|
|
4189
|
-
if (message.role === "system") {
|
|
4190
|
-
continue;
|
|
4191
|
-
}
|
|
4192
|
-
if (message.role === "user") {
|
|
4193
|
-
for (const content of message.content) {
|
|
4194
|
-
if (content.type === "text") {
|
|
4195
|
-
transcript.push({
|
|
4196
|
-
entryId: transcript.length,
|
|
4197
|
-
kind: "message",
|
|
4198
|
-
role: "user",
|
|
4199
|
-
text: content.text
|
|
4200
|
-
});
|
|
4201
|
-
}
|
|
4202
|
-
}
|
|
4203
|
-
continue;
|
|
4204
|
-
}
|
|
4205
|
-
if (message.role === "tool") {
|
|
4206
|
-
for (const content of message.content) {
|
|
4207
|
-
transcript.push({
|
|
4208
|
-
entryId: transcript.length,
|
|
4209
|
-
kind: "tool",
|
|
4210
|
-
toolName: "tool_result",
|
|
4211
|
-
callId: content.callId ?? content.id,
|
|
4212
|
-
result: content.content.map(
|
|
4213
|
-
(item) => "text" in item ? item.text : `[image:${item.mediaType ?? "image/png"}]`
|
|
4214
|
-
).join("\n"),
|
|
4215
|
-
structuredResult: content.content
|
|
4216
|
-
});
|
|
4217
|
-
}
|
|
4218
|
-
continue;
|
|
4219
|
-
}
|
|
4220
|
-
for (const content of message.content) {
|
|
4221
|
-
if (content.type === "text") {
|
|
4222
|
-
appendTranscriptAssistantText(transcript, content.text);
|
|
4223
|
-
} else if (content.type === "reasoning") {
|
|
4224
|
-
appendTranscriptReasoningText(transcript, content.text, content.id);
|
|
4225
|
-
} else if (content.type === "tool_call") {
|
|
4226
|
-
transcript.push({
|
|
4227
|
-
entryId: transcript.length,
|
|
4228
|
-
kind: "tool",
|
|
4229
|
-
toolName: content.function.name,
|
|
4230
|
-
callId: content.callId ?? content.id,
|
|
4231
|
-
args: formatJson2(content.function.arguments)
|
|
4232
|
-
});
|
|
4233
|
-
}
|
|
4234
|
-
}
|
|
4235
|
-
}
|
|
4236
|
-
return transcript;
|
|
4237
|
-
}
|
|
4238
4133
|
function messageToTranscriptEntry(message, entryId) {
|
|
4239
4134
|
const role = typeof message === "string" || message.role !== "assistant" ? "user" : "assistant";
|
|
4240
4135
|
return {
|
|
@@ -4517,11 +4412,10 @@ function registerPipelineRoutes(app, props) {
|
|
|
4517
4412
|
return body.error;
|
|
4518
4413
|
}
|
|
4519
4414
|
const sourceRunId = c.req.param("runId");
|
|
4520
|
-
const
|
|
4415
|
+
const sourceRun = await props.runStore.getPipelineRun({
|
|
4521
4416
|
pipelineId: pipeline.id,
|
|
4522
|
-
|
|
4417
|
+
runId: sourceRunId
|
|
4523
4418
|
});
|
|
4524
|
-
const sourceRun = runs.find((run) => run.runId === sourceRunId);
|
|
4525
4419
|
if (sourceRun === void 0) {
|
|
4526
4420
|
return errorResponse(c, 404, "not_found", "Pipeline run not found");
|
|
4527
4421
|
}
|
|
@@ -4578,7 +4472,7 @@ async function executePipelineRun(c, props, pipeline, body) {
|
|
|
4578
4472
|
}
|
|
4579
4473
|
}
|
|
4580
4474
|
});
|
|
4581
|
-
const jsonOutput =
|
|
4475
|
+
const jsonOutput = toJsonValue(output);
|
|
4582
4476
|
const endedAt = Date.now();
|
|
4583
4477
|
await savePipelineRun(props.runStore, {
|
|
4584
4478
|
runId,
|
|
@@ -4613,7 +4507,7 @@ async function executePipelineRun(c, props, pipeline, body) {
|
|
|
4613
4507
|
pipelineId: pipeline.id,
|
|
4614
4508
|
status: "error",
|
|
4615
4509
|
input: body.input,
|
|
4616
|
-
error:
|
|
4510
|
+
error: serializeError(error),
|
|
4617
4511
|
...body.metadata === void 0 ? {} : { metadata: body.metadata },
|
|
4618
4512
|
startedAt: startedAtIso,
|
|
4619
4513
|
endedAt: new Date(endedAt).toISOString(),
|
|
@@ -4623,7 +4517,7 @@ async function executePipelineRun(c, props, pipeline, body) {
|
|
|
4623
4517
|
props.logStore,
|
|
4624
4518
|
pipelineRunFailedLog(pipeline.id, runId, error, startedAt)
|
|
4625
4519
|
);
|
|
4626
|
-
return errorResponse(c, 500, "internal_error", "Pipeline run failed",
|
|
4520
|
+
return errorResponse(c, 500, "internal_error", "Pipeline run failed", serializeError(error));
|
|
4627
4521
|
}
|
|
4628
4522
|
}
|
|
4629
4523
|
function pipelineDetail(pipeline) {
|
|
@@ -4653,7 +4547,7 @@ async function* pipelineRunEvents(props) {
|
|
|
4653
4547
|
}
|
|
4654
4548
|
}
|
|
4655
4549
|
}).then(async (output) => {
|
|
4656
|
-
const jsonOutput =
|
|
4550
|
+
const jsonOutput = toJsonValue(output);
|
|
4657
4551
|
const endedAt = Date.now();
|
|
4658
4552
|
await savePipelineRun(props.runStore, {
|
|
4659
4553
|
runId: props.runId,
|
|
@@ -4691,7 +4585,7 @@ async function* pipelineRunEvents(props) {
|
|
|
4691
4585
|
pipelineId: props.pipeline.id,
|
|
4692
4586
|
status: "error",
|
|
4693
4587
|
input: props.input,
|
|
4694
|
-
error:
|
|
4588
|
+
error: serializeError(error),
|
|
4695
4589
|
...props.metadata === void 0 ? {} : { metadata: props.metadata },
|
|
4696
4590
|
startedAt: props.startedAtIso,
|
|
4697
4591
|
endedAt: new Date(endedAt).toISOString(),
|
|
@@ -4704,7 +4598,7 @@ async function* pipelineRunEvents(props) {
|
|
|
4704
4598
|
if (log !== void 0) {
|
|
4705
4599
|
events.push({ type: "pipeline_log", log });
|
|
4706
4600
|
}
|
|
4707
|
-
events.push({ type: "error", error:
|
|
4601
|
+
events.push({ type: "error", error: serializeError(error) });
|
|
4708
4602
|
}).finally(() => events.close());
|
|
4709
4603
|
try {
|
|
4710
4604
|
while (true) {
|
|
@@ -4815,20 +4709,6 @@ function isJsonValue3(value) {
|
|
|
4815
4709
|
}
|
|
4816
4710
|
return false;
|
|
4817
4711
|
}
|
|
4818
|
-
function toJsonValue3(value) {
|
|
4819
|
-
if (isJsonValue3(value)) {
|
|
4820
|
-
return value;
|
|
4821
|
-
}
|
|
4822
|
-
if (value === void 0) {
|
|
4823
|
-
return null;
|
|
4824
|
-
}
|
|
4825
|
-
try {
|
|
4826
|
-
const parsed = JSON.parse(JSON.stringify(value));
|
|
4827
|
-
return isJsonValue3(parsed) ? parsed : String(value);
|
|
4828
|
-
} catch {
|
|
4829
|
-
return String(value);
|
|
4830
|
-
}
|
|
4831
|
-
}
|
|
4832
4712
|
|
|
4833
4713
|
// src/runtime/questions.ts
|
|
4834
4714
|
import { createHook as createHook2 } from "@anvia/core/agent";
|
|
@@ -5197,7 +5077,7 @@ function runFailedLog(sessionId, runId, error, startedAt) {
|
|
|
5197
5077
|
message: "Run failed",
|
|
5198
5078
|
metadata: cleanMetadata2({
|
|
5199
5079
|
durationMs: Date.now() - startedAt,
|
|
5200
|
-
error:
|
|
5080
|
+
error: serializeError(error)
|
|
5201
5081
|
})
|
|
5202
5082
|
};
|
|
5203
5083
|
}
|
|
@@ -5480,7 +5360,7 @@ function childAgentLog(event, sessionId, runId) {
|
|
|
5480
5360
|
parentToolName: event.toolName,
|
|
5481
5361
|
agentId: event.agentId,
|
|
5482
5362
|
hasAgentName: event.agentName !== void 0,
|
|
5483
|
-
error:
|
|
5363
|
+
error: serializeError(child.error)
|
|
5484
5364
|
})
|
|
5485
5365
|
}
|
|
5486
5366
|
];
|
|
@@ -5798,11 +5678,11 @@ function registerToolRoutes(app, props) {
|
|
|
5798
5678
|
agentId,
|
|
5799
5679
|
toolName,
|
|
5800
5680
|
status: "success",
|
|
5801
|
-
result:
|
|
5681
|
+
result: toJsonValue(result),
|
|
5802
5682
|
durationMs: ended - started,
|
|
5803
5683
|
startedAt,
|
|
5804
5684
|
endedAt: new Date(ended).toISOString(),
|
|
5805
|
-
events: events.map(
|
|
5685
|
+
events: events.map(toJsonValue)
|
|
5806
5686
|
});
|
|
5807
5687
|
} catch (error) {
|
|
5808
5688
|
const ended = Date.now();
|
|
@@ -5815,7 +5695,7 @@ function registerToolRoutes(app, props) {
|
|
|
5815
5695
|
durationMs: ended - started,
|
|
5816
5696
|
startedAt,
|
|
5817
5697
|
endedAt: new Date(ended).toISOString(),
|
|
5818
|
-
events: events.map(
|
|
5698
|
+
events: events.map(toJsonValue)
|
|
5819
5699
|
},
|
|
5820
5700
|
500
|
|
5821
5701
|
);
|
|
@@ -6266,14 +6146,14 @@ function createStudioApp(options) {
|
|
|
6266
6146
|
...optionalTitle(body.message),
|
|
6267
6147
|
transcript: transcriptFromMessages(messages.slice(session.messageCount)),
|
|
6268
6148
|
status: "error",
|
|
6269
|
-
error:
|
|
6149
|
+
error: serializeError(error)
|
|
6270
6150
|
});
|
|
6271
6151
|
await appendSessionLog(
|
|
6272
6152
|
stores.sessions,
|
|
6273
6153
|
runFailedLog(session.id, runId, error, runStartedAt)
|
|
6274
6154
|
);
|
|
6275
6155
|
}
|
|
6276
|
-
return errorResponse(c, 500, "internal_error", "Agent run failed",
|
|
6156
|
+
return errorResponse(c, 500, "internal_error", "Agent run failed", serializeError(error));
|
|
6277
6157
|
}
|
|
6278
6158
|
});
|
|
6279
6159
|
if (stores.sessions !== void 0) {
|