@tonyclaw/agent-inspector 3.0.16 → 3.0.18
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/.output/nitro.json +1 -1
- package/.output/public/assets/{CompareDrawer-BJmxAiM0.js → CompareDrawer-Daj03-RL.js} +1 -1
- package/.output/public/assets/ProxyViewerContainer-BLCRQtU_.js +106 -0
- package/.output/public/assets/{ReplayDialog-CkLdOMJr.js → ReplayDialog-5FR5crdo.js} +1 -1
- package/.output/public/assets/{RequestAnatomy-DemOFfSc.js → RequestAnatomy-DF0hHdQY.js} +1 -1
- package/.output/public/assets/{ResponseView-9LhpuDo7.js → ResponseView-BwkMSsUa.js} +2 -2
- package/.output/public/assets/{StreamingChunkSequence-RRWYBOdz.js → StreamingChunkSequence-CKeUd58x.js} +1 -1
- package/.output/public/assets/{_sessionId-CWEh2Jsn.js → _sessionId-CThgXa41.js} +1 -1
- package/.output/public/assets/index-BHXN1Fsx.css +1 -0
- package/.output/public/assets/{index-Lwir70Rs.js → index-ClQ7Vi3J.js} +1 -1
- package/.output/public/assets/{index-hjNWJZGE.js → index-gm3A0idN.js} +1 -1
- package/.output/public/assets/{json-viewer-D8gvbDlB.js → json-viewer-BA-W-PZq.js} +1 -1
- package/.output/public/assets/{main-ovrz0tyD.js → main-BnRC1932.js} +2 -2
- package/.output/server/_libs/@opentelemetry/semantic-conventions+[...].mjs +2658 -0
- package/.output/server/_libs/agent-base.mjs +234 -0
- package/.output/server/_libs/anthropic-ai__sdk.mjs +6042 -0
- package/.output/server/_libs/atomically.mjs +3 -0
- package/.output/server/_libs/base64-js.mjs +102 -0
- package/.output/server/_libs/bignumber.js.mjs +1353 -0
- package/.output/server/_libs/buffer-equal-constant-time.mjs +38 -0
- package/.output/server/_libs/data-uri-to-buffer.mjs +39 -0
- package/.output/server/_libs/debug.mjs +547 -0
- package/.output/server/_libs/ecdsa-sig-formatter.mjs +162 -0
- package/.output/server/_libs/extend.mjs +2 -1
- package/.output/server/_libs/fetch-blob.mjs +287 -0
- package/.output/server/_libs/formdata-polyfill.mjs +88 -0
- package/.output/server/_libs/gaxios.mjs +927 -0
- package/.output/server/_libs/gcp-metadata.mjs +322 -0
- package/.output/server/_libs/google-auth-library.mjs +6339 -0
- package/.output/server/_libs/google-logging-utils.mjs +385 -0
- package/.output/server/_libs/google__genai.mjs +18034 -0
- package/.output/server/_libs/has-flag.mjs +16 -0
- package/.output/server/_libs/https-proxy-agent.mjs +280 -0
- package/.output/server/_libs/json-bigint.mjs +413 -0
- package/.output/server/_libs/jwa.mjs +233 -0
- package/.output/server/_libs/jws.mjs +298 -0
- package/.output/server/_libs/lucide-react.mjs +261 -226
- package/.output/server/_libs/mariozechner__pi-agent-core.mjs +824 -0
- package/.output/server/_libs/mariozechner__pi-ai.mjs +22889 -0
- package/.output/server/_libs/mistralai__mistralai.mjs +32045 -0
- package/.output/server/_libs/ms.mjs +120 -0
- package/.output/server/_libs/node-domexception.mjs +17 -0
- package/.output/server/_libs/node-fetch.mjs +1578 -0
- package/.output/server/_libs/ohash.mjs +1 -1
- package/.output/server/_libs/openai.mjs +6766 -0
- package/.output/server/_libs/opentelemetry__api.mjs +1678 -0
- package/.output/server/_libs/p-retry.mjs +87 -0
- package/.output/server/_libs/partial-json.mjs +244 -0
- package/.output/server/_libs/react-dom.mjs +5 -5
- package/.output/server/_libs/react-markdown.mjs +2 -2
- package/.output/server/_libs/react.mjs +30 -0
- package/.output/server/_libs/readable-stream.mjs +5 -5
- package/.output/server/_libs/retry.mjs +236 -0
- package/.output/server/_libs/safe-buffer.mjs +63 -1
- package/.output/server/_libs/srvx.mjs +2 -2
- package/.output/server/_libs/supports-color.mjs +108 -0
- package/.output/server/_libs/tanstack__router-core.mjs +1 -1
- package/.output/server/_libs/typebox.mjs +6596 -0
- package/.output/server/_libs/util-deprecate.mjs +2 -2
- package/.output/server/_libs/vfile.mjs +2 -2
- package/.output/server/_libs/web-streams-polyfill.mjs +4282 -0
- package/.output/server/_libs/ws.mjs +3715 -0
- package/.output/server/_libs/zod-to-json-schema.mjs +1207 -0
- package/.output/server/_libs/zod.mjs +597 -9
- package/.output/server/{_sessionId-zI_GFX_7.mjs → _sessionId-Bi3ZIrqT.mjs} +14 -13
- package/.output/server/_ssr/{CompareDrawer-Ckcx1RVu.mjs → CompareDrawer-BYZS_hCR.mjs} +14 -13
- package/.output/server/_ssr/{ProxyViewerContainer-BgXewlIr.mjs → ProxyViewerContainer-BE4umfVs.mjs} +205 -106
- package/.output/server/_ssr/{ReplayDialog-wx3nDtZn.mjs → ReplayDialog-BlID2ZH4.mjs} +15 -14
- package/.output/server/_ssr/{RequestAnatomy-DN80zt0G.mjs → RequestAnatomy-CGJ2lkzT.mjs} +14 -13
- package/.output/server/_ssr/{ResponseView-DD7rTu_l.mjs → ResponseView-DDjcGf7M.mjs} +14 -13
- package/.output/server/_ssr/{StreamingChunkSequence-DAgz6Vvw.mjs → StreamingChunkSequence-G7B8M5G2.mjs} +14 -13
- package/.output/server/_ssr/{index-dcTjp8du.mjs → index-ClQ9FvRJ.mjs} +13 -12
- package/.output/server/_ssr/index.mjs +4 -4
- package/.output/server/_ssr/{json-viewer-N2cuzGWR.mjs → json-viewer-CFbpkiBJ.mjs} +14 -13
- package/.output/server/_ssr/{router-BfQ0QsD5.mjs → router-Cq8LEvhE.mjs} +523 -97
- package/.output/server/_tanstack-start-manifest_v-p7J0QCMh.mjs +4 -0
- package/.output/server/index.mjs +75 -75
- package/package.json +4 -1
- package/src/components/ProxyViewer.tsx +3 -0
- package/src/components/pi-agent/PiAgentPanel.tsx +204 -0
- package/src/components/proxy-viewer/LogEntry.tsx +54 -19
- package/src/components/proxy-viewer/logEntryVisibility.ts +22 -0
- package/src/lib/piAgentContract.ts +21 -0
- package/src/routes/api/pi-agent.ts +29 -0
- package/src/services/piAgent.ts +390 -0
- package/.output/public/assets/ProxyViewerContainer-C40Nig73.js +0 -106
- package/.output/public/assets/index-HRfrFVYw.css +0 -1
- package/.output/server/_tanstack-start-manifest_v-BXnYrbcJ.mjs +0 -4
|
@@ -16,16 +16,16 @@ import { Worker } from "node:worker_threads";
|
|
|
16
16
|
import { M as McpServer, W as WebStandardStreamableHTTPServerTransport, R as ResourceTemplate } from "../_libs/modelcontextprotocol__server.mjs";
|
|
17
17
|
import { J as JSZip } from "../_libs/jszip.mjs";
|
|
18
18
|
import { homedir } from "node:os";
|
|
19
|
-
import { d as object, b as string, a as array, r as record, _ as _enum, u as union,
|
|
19
|
+
import { d as object, b as string, a as array, n as number, r as record, _ as _enum, u as union, c as boolean, e as unknown, l as literal, h as _null, k as lazy, g as discriminatedUnion } from "../_libs/zod.mjs";
|
|
20
20
|
import "../_libs/tiny-warning.mjs";
|
|
21
21
|
import "../_libs/tanstack__router-core.mjs";
|
|
22
22
|
import "../_libs/cookie-es.mjs";
|
|
23
23
|
import "../_libs/seroval.mjs";
|
|
24
24
|
import "../_libs/seroval-plugins.mjs";
|
|
25
|
+
import "node:stream";
|
|
25
26
|
import "../_libs/tanstack__history.mjs";
|
|
26
27
|
import "../_libs/tiny-invariant.mjs";
|
|
27
28
|
import "node:stream/web";
|
|
28
|
-
import "node:stream";
|
|
29
29
|
import "../_libs/react-dom.mjs";
|
|
30
30
|
import "util";
|
|
31
31
|
import "async_hooks";
|
|
@@ -38,6 +38,7 @@ import "node:assert";
|
|
|
38
38
|
import "../_libs/dot-prop.mjs";
|
|
39
39
|
import "../_libs/env-paths.mjs";
|
|
40
40
|
import "../_libs/atomically.mjs";
|
|
41
|
+
import "node:events";
|
|
41
42
|
import "../_libs/stubborn-fs.mjs";
|
|
42
43
|
import "../_libs/stubborn-utils.mjs";
|
|
43
44
|
import "../_libs/when-exit.mjs";
|
|
@@ -65,7 +66,7 @@ import "../_libs/immediate.mjs";
|
|
|
65
66
|
import "../_libs/setimmediate.mjs";
|
|
66
67
|
import "../_libs/pako.mjs";
|
|
67
68
|
const faviconSvg = "data:image/svg+xml,%3csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2024%2024'%20role='img'%20aria-label='Agent%20Inspector'%3e%3cg%20fill='none'%20stroke='%23f59e0b'%20stroke-width='1.5'%20stroke-linecap='round'%20stroke-linejoin='round'%20%3e%3cpath%20d='M5%2013%20C5%209%208%207%2012%207%20C16%207%2019%209%2019%2013%20C19%2016%2016%2018%2012%2018%20C8%2018%205%2016%205%2013%20Z'%20/%3e%3cpath%20d='M5%2011%20C3.5%209.5%201.5%2010%202%2012.5%20C2.5%2014%204%2013.5%205%2012.5'%20/%3e%3cpath%20d='M19%2011%20C20.5%209.5%2022.5%2010%2022%2012.5%20C21.5%2014%2020%2013.5%2019%2012.5'%20/%3e%3cline%20x1='10'%20y1='7'%20x2='9.5'%20y2='5'%20/%3e%3cline%20x1='14'%20y1='7'%20x2='14.5'%20y2='5'%20/%3e%3cline%20x1='6.5'%20y1='16'%20x2='4.5'%20y2='19.5'%20/%3e%3cline%20x1='9'%20y1='17.5'%20x2='8'%20y2='20.5'%20/%3e%3cline%20x1='15'%20y1='17.5'%20x2='16'%20y2='20.5'%20/%3e%3cline%20x1='17.5'%20y1='16'%20x2='19.5'%20y2='19.5'%20/%3e%3c/g%3e%3ccircle%20cx='9.5'%20cy='4.5'%20r='0.9'%20fill='%23f59e0b'%20/%3e%3ccircle%20cx='14.5'%20cy='4.5'%20r='0.9'%20fill='%23f59e0b'%20/%3e%3c/svg%3e";
|
|
68
|
-
const appCss = "/assets/index-
|
|
69
|
+
const appCss = "/assets/index-BHXN1Fsx.css";
|
|
69
70
|
const CHUNK_LOAD_RELOAD_AT_KEY = "agent-inspector.chunkLoadReloadAt";
|
|
70
71
|
const CHUNK_LOAD_RELOAD_WINDOW_MS = 15e3;
|
|
71
72
|
const CHUNK_LOAD_FAILURE_PATTERNS = [
|
|
@@ -134,7 +135,7 @@ function installChunkLoadRecovery() {
|
|
|
134
135
|
window.removeEventListener("error", handleError);
|
|
135
136
|
};
|
|
136
137
|
}
|
|
137
|
-
const Route$
|
|
138
|
+
const Route$M = createRootRoute({
|
|
138
139
|
head: () => ({
|
|
139
140
|
meta: [
|
|
140
141
|
{ charSet: "utf-8" },
|
|
@@ -177,8 +178,8 @@ function RootDocument({ children }) {
|
|
|
177
178
|
] })
|
|
178
179
|
] });
|
|
179
180
|
}
|
|
180
|
-
const $$splitComponentImporter$1 = () => import("./index-
|
|
181
|
-
const Route$
|
|
181
|
+
const $$splitComponentImporter$1 = () => import("./index-ClQ9FvRJ.mjs");
|
|
182
|
+
const Route$L = createFileRoute("/")({
|
|
182
183
|
ssr: false,
|
|
183
184
|
component: lazyRouteComponent($$splitComponentImporter$1, "component")
|
|
184
185
|
});
|
|
@@ -221,8 +222,8 @@ function decodeSessionIdFromPath(encoded) {
|
|
|
221
222
|
function getSessionPath(sessionId) {
|
|
222
223
|
return `/session/${encodeSessionIdForPath(sessionId)}`;
|
|
223
224
|
}
|
|
224
|
-
const $$splitComponentImporter = () => import("../_sessionId-
|
|
225
|
-
const Route$
|
|
225
|
+
const $$splitComponentImporter = () => import("../_sessionId-Bi3ZIrqT.mjs");
|
|
226
|
+
const Route$K = createFileRoute("/session/$sessionId")({
|
|
226
227
|
ssr: false,
|
|
227
228
|
component: lazyRouteComponent($$splitComponentImporter, "component"),
|
|
228
229
|
parseParams: (params) => ({
|
|
@@ -1132,7 +1133,7 @@ function objectFromUnknown$1(value) {
|
|
|
1132
1133
|
if (typeof value === "object" || typeof value === "function") return value;
|
|
1133
1134
|
return null;
|
|
1134
1135
|
}
|
|
1135
|
-
function readProperty$
|
|
1136
|
+
function readProperty$5(value, name2) {
|
|
1136
1137
|
let current = objectFromUnknown$1(value);
|
|
1137
1138
|
while (current !== null) {
|
|
1138
1139
|
const desc = Object.getOwnPropertyDescriptor(current, name2);
|
|
@@ -1146,7 +1147,7 @@ function readProperty$4(value, name2) {
|
|
|
1146
1147
|
return void 0;
|
|
1147
1148
|
}
|
|
1148
1149
|
function readFunction$1(value, name2) {
|
|
1149
|
-
const property = readProperty$
|
|
1150
|
+
const property = readProperty$5(value, name2);
|
|
1150
1151
|
return typeof property === "function" ? property : null;
|
|
1151
1152
|
}
|
|
1152
1153
|
function callMethod$1(target, methodName, args) {
|
|
@@ -1188,7 +1189,7 @@ function execSql$1(db, sql) {
|
|
|
1188
1189
|
return result !== void 0;
|
|
1189
1190
|
}
|
|
1190
1191
|
function sqliteConstructorFromModule$1(moduleValue, exportName) {
|
|
1191
|
-
const exportedValue = readProperty$
|
|
1192
|
+
const exportedValue = readProperty$5(moduleValue, exportName);
|
|
1192
1193
|
if (typeof exportedValue === "function") {
|
|
1193
1194
|
return (path2) => Reflect.construct(exportedValue, [path2]);
|
|
1194
1195
|
}
|
|
@@ -1331,11 +1332,11 @@ function entryParams(entry) {
|
|
|
1331
1332
|
];
|
|
1332
1333
|
}
|
|
1333
1334
|
function readNumber$1(row, name2) {
|
|
1334
|
-
const value = readProperty$
|
|
1335
|
+
const value = readProperty$5(row, name2);
|
|
1335
1336
|
return typeof value === "number" && Number.isFinite(value) ? value : null;
|
|
1336
1337
|
}
|
|
1337
1338
|
function readString$2(row, name2) {
|
|
1338
|
-
const value = readProperty$
|
|
1339
|
+
const value = readProperty$5(row, name2);
|
|
1339
1340
|
return typeof value === "string" ? value : null;
|
|
1340
1341
|
}
|
|
1341
1342
|
function readBoolean(row, name2) {
|
|
@@ -2201,7 +2202,7 @@ function objectFromUnknown(value) {
|
|
|
2201
2202
|
if (typeof value === "object" || typeof value === "function") return value;
|
|
2202
2203
|
return null;
|
|
2203
2204
|
}
|
|
2204
|
-
function readProperty$
|
|
2205
|
+
function readProperty$4(value, name2) {
|
|
2205
2206
|
let current = objectFromUnknown(value);
|
|
2206
2207
|
while (current !== null) {
|
|
2207
2208
|
const desc = Object.getOwnPropertyDescriptor(current, name2);
|
|
@@ -2215,7 +2216,7 @@ function readProperty$3(value, name2) {
|
|
|
2215
2216
|
return void 0;
|
|
2216
2217
|
}
|
|
2217
2218
|
function readFunction(value, name2) {
|
|
2218
|
-
const property = readProperty$
|
|
2219
|
+
const property = readProperty$4(value, name2);
|
|
2219
2220
|
return typeof property === "function" ? property : null;
|
|
2220
2221
|
}
|
|
2221
2222
|
function callMethod(target, methodName, args) {
|
|
@@ -2253,7 +2254,7 @@ function closeDatabase(db) {
|
|
|
2253
2254
|
callMethod(db, "close", []);
|
|
2254
2255
|
}
|
|
2255
2256
|
function sqliteConstructorFromModule(moduleValue, exportName) {
|
|
2256
|
-
const exportedValue = readProperty$
|
|
2257
|
+
const exportedValue = readProperty$4(moduleValue, exportName);
|
|
2257
2258
|
if (typeof exportedValue === "function") {
|
|
2258
2259
|
return (path2) => Reflect.construct(exportedValue, [path2]);
|
|
2259
2260
|
}
|
|
@@ -2344,11 +2345,11 @@ async function archiveSessionLog(log) {
|
|
|
2344
2345
|
}
|
|
2345
2346
|
}
|
|
2346
2347
|
function readString$1(row, name2) {
|
|
2347
|
-
const value = readProperty$
|
|
2348
|
+
const value = readProperty$4(row, name2);
|
|
2348
2349
|
return typeof value === "string" ? value : null;
|
|
2349
2350
|
}
|
|
2350
2351
|
function readNumber(row, name2) {
|
|
2351
|
-
const value = readProperty$
|
|
2352
|
+
const value = readProperty$4(row, name2);
|
|
2352
2353
|
return typeof value === "number" && Number.isFinite(value) ? value : null;
|
|
2353
2354
|
}
|
|
2354
2355
|
function logFromJson(value) {
|
|
@@ -4188,24 +4189,24 @@ const anthropicProvider = {
|
|
|
4188
4189
|
};
|
|
4189
4190
|
registry.register(anthropicProvider);
|
|
4190
4191
|
const MAX_CHUNKS = 1e3;
|
|
4191
|
-
function readProperty$
|
|
4192
|
+
function readProperty$3(value, key) {
|
|
4192
4193
|
if (value === null || typeof value !== "object" || Array.isArray(value)) return void 0;
|
|
4193
4194
|
return Object.getOwnPropertyDescriptor(value, key)?.value;
|
|
4194
4195
|
}
|
|
4195
4196
|
function readStringProperty$2(value, key) {
|
|
4196
|
-
const property = readProperty$
|
|
4197
|
+
const property = readProperty$3(value, key);
|
|
4197
4198
|
return typeof property === "string" ? property : null;
|
|
4198
4199
|
}
|
|
4199
4200
|
function readNumberProperty(value, key) {
|
|
4200
|
-
const property = readProperty$
|
|
4201
|
+
const property = readProperty$3(value, key);
|
|
4201
4202
|
return typeof property === "number" && Number.isFinite(property) ? property : null;
|
|
4202
4203
|
}
|
|
4203
4204
|
function readObjectProperty(value, key) {
|
|
4204
|
-
const property = readProperty$
|
|
4205
|
+
const property = readProperty$3(value, key);
|
|
4205
4206
|
return property !== null && typeof property === "object" && !Array.isArray(property) ? property : null;
|
|
4206
4207
|
}
|
|
4207
4208
|
function readArrayProperty$1(value, key) {
|
|
4208
|
-
const property = readProperty$
|
|
4209
|
+
const property = readProperty$3(value, key);
|
|
4209
4210
|
return Array.isArray(property) ? property : [];
|
|
4210
4211
|
}
|
|
4211
4212
|
function parseSseEvents(raw) {
|
|
@@ -4397,7 +4398,7 @@ function extractChatCompletionsStream(events, log, fallbackModel, collectChunks)
|
|
|
4397
4398
|
}
|
|
4398
4399
|
function parseResponsesResponse(value) {
|
|
4399
4400
|
const fromResponseProperty = OpenAIResponsesResponseSchema.safeParse(
|
|
4400
|
-
readProperty$
|
|
4401
|
+
readProperty$3(value, "response")
|
|
4401
4402
|
);
|
|
4402
4403
|
if (fromResponseProperty.success) return fromResponseProperty.data;
|
|
4403
4404
|
const direct = OpenAIResponsesResponseSchema.safeParse(value);
|
|
@@ -6409,30 +6410,30 @@ function parseJson$1(raw) {
|
|
|
6409
6410
|
return { ok: false };
|
|
6410
6411
|
}
|
|
6411
6412
|
}
|
|
6412
|
-
function isRecord$
|
|
6413
|
+
function isRecord$2(value) {
|
|
6413
6414
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
6414
6415
|
}
|
|
6415
|
-
function readProperty$
|
|
6416
|
-
if (!isRecord$
|
|
6416
|
+
function readProperty$2(value, key) {
|
|
6417
|
+
if (!isRecord$2(value)) return void 0;
|
|
6417
6418
|
return Object.getOwnPropertyDescriptor(value, key)?.value;
|
|
6418
6419
|
}
|
|
6419
6420
|
function hasOwnProperty(value, key) {
|
|
6420
6421
|
return Object.getOwnPropertyDescriptor(value, key) !== void 0;
|
|
6421
6422
|
}
|
|
6422
6423
|
function readString(value, key) {
|
|
6423
|
-
const property = readProperty$
|
|
6424
|
+
const property = readProperty$2(value, key);
|
|
6424
6425
|
return typeof property === "string" ? property : null;
|
|
6425
6426
|
}
|
|
6426
6427
|
function readArray(value, key) {
|
|
6427
|
-
const property = readProperty$
|
|
6428
|
+
const property = readProperty$2(value, key);
|
|
6428
6429
|
return Array.isArray(property) ? property : [];
|
|
6429
6430
|
}
|
|
6430
6431
|
function readStringArray(value, key) {
|
|
6431
6432
|
return readArray(value, key).filter((item) => typeof item === "string");
|
|
6432
6433
|
}
|
|
6433
6434
|
function readObject(value, key) {
|
|
6434
|
-
const property = readProperty$
|
|
6435
|
-
return isRecord$
|
|
6435
|
+
const property = readProperty$2(value, key);
|
|
6436
|
+
return isRecord$2(property) ? property : null;
|
|
6436
6437
|
}
|
|
6437
6438
|
function normalizeExpectedType(typeName) {
|
|
6438
6439
|
switch (typeName) {
|
|
@@ -6449,7 +6450,7 @@ function normalizeExpectedType(typeName) {
|
|
|
6449
6450
|
}
|
|
6450
6451
|
}
|
|
6451
6452
|
function schemaTypes(schema) {
|
|
6452
|
-
const typeValue = readProperty$
|
|
6453
|
+
const typeValue = readProperty$2(schema, "type");
|
|
6453
6454
|
const rawTypes = Array.isArray(typeValue) ? typeValue : [typeValue];
|
|
6454
6455
|
const types = [];
|
|
6455
6456
|
for (const rawType of rawTypes) {
|
|
@@ -6477,7 +6478,7 @@ function actualType(value) {
|
|
|
6477
6478
|
case "function":
|
|
6478
6479
|
case "object":
|
|
6479
6480
|
case "symbol":
|
|
6480
|
-
return isRecord$
|
|
6481
|
+
return isRecord$2(value) ? "object" : "unknown";
|
|
6481
6482
|
}
|
|
6482
6483
|
return "unknown";
|
|
6483
6484
|
}
|
|
@@ -6494,7 +6495,7 @@ function matchesExpectedType(value, expected) {
|
|
|
6494
6495
|
case "number":
|
|
6495
6496
|
return typeof value === "number" && Number.isFinite(value);
|
|
6496
6497
|
case "object":
|
|
6497
|
-
return isRecord$
|
|
6498
|
+
return isRecord$2(value);
|
|
6498
6499
|
case "string":
|
|
6499
6500
|
return typeof value === "string";
|
|
6500
6501
|
}
|
|
@@ -6539,7 +6540,7 @@ function schemaAllowsObjectValidation(schema, expectedTypes) {
|
|
|
6539
6540
|
return expectedTypes.includes("object");
|
|
6540
6541
|
}
|
|
6541
6542
|
function schemaAllowsArrayValidation(schema, expectedTypes) {
|
|
6542
|
-
if (expectedTypes.length === 0) return readProperty$
|
|
6543
|
+
if (expectedTypes.length === 0) return readProperty$2(schema, "items") !== void 0;
|
|
6543
6544
|
return expectedTypes.includes("array");
|
|
6544
6545
|
}
|
|
6545
6546
|
function addTypeWarning(warnings, toolName, path2, expectedTypes, value) {
|
|
@@ -6572,7 +6573,7 @@ function validateObjectSchema(schema, value, toolName, path2, warnings) {
|
|
|
6572
6573
|
}
|
|
6573
6574
|
}
|
|
6574
6575
|
function validateArraySchema(schema, value, toolName, path2, warnings) {
|
|
6575
|
-
const itemsSchema = readProperty$
|
|
6576
|
+
const itemsSchema = readProperty$2(schema, "items");
|
|
6576
6577
|
if (itemsSchema === void 0) return;
|
|
6577
6578
|
let index = 0;
|
|
6578
6579
|
for (const item of value) {
|
|
@@ -6581,7 +6582,7 @@ function validateArraySchema(schema, value, toolName, path2, warnings) {
|
|
|
6581
6582
|
}
|
|
6582
6583
|
}
|
|
6583
6584
|
function validateEnum(schema, value, toolName, path2, warnings) {
|
|
6584
|
-
const enumValue = readProperty$
|
|
6585
|
+
const enumValue = readProperty$2(schema, "enum");
|
|
6585
6586
|
if (Array.isArray(enumValue) && enumValue.length > 0 && !enumMatches(value, enumValue)) {
|
|
6586
6587
|
warnings.push(
|
|
6587
6588
|
`Tool call "${toolName}" ${pathLabel(path2)} expected one of ${formatJsonValue(
|
|
@@ -6599,7 +6600,7 @@ function validateEnum(schema, value, toolName, path2, warnings) {
|
|
|
6599
6600
|
}
|
|
6600
6601
|
}
|
|
6601
6602
|
function validateValueAgainstSchema(schema, value, toolName, path2, warnings) {
|
|
6602
|
-
if (!isRecord$
|
|
6603
|
+
if (!isRecord$2(schema)) return;
|
|
6603
6604
|
const expectedTypes = schemaTypes(schema);
|
|
6604
6605
|
if (expectedTypes.length > 0 && !matchesAnyExpectedType(value, expectedTypes)) {
|
|
6605
6606
|
addTypeWarning(warnings, toolName, path2, expectedTypes, value);
|
|
@@ -6607,7 +6608,7 @@ function validateValueAgainstSchema(schema, value, toolName, path2, warnings) {
|
|
|
6607
6608
|
}
|
|
6608
6609
|
validateEnum(schema, value, toolName, path2, warnings);
|
|
6609
6610
|
if (schemaAllowsObjectValidation(schema, expectedTypes)) {
|
|
6610
|
-
if (isRecord$
|
|
6611
|
+
if (isRecord$2(value)) {
|
|
6611
6612
|
validateObjectSchema(schema, value, toolName, path2, warnings);
|
|
6612
6613
|
} else if (expectedTypes.length === 0) {
|
|
6613
6614
|
warnings.push(
|
|
@@ -6628,7 +6629,7 @@ function validateValueAgainstSchema(schema, value, toolName, path2, warnings) {
|
|
|
6628
6629
|
function extractAnthropicToolSchemas(request) {
|
|
6629
6630
|
const tools = /* @__PURE__ */ new Map();
|
|
6630
6631
|
for (const tool of readArray(request, "tools")) {
|
|
6631
|
-
if (!isRecord$
|
|
6632
|
+
if (!isRecord$2(tool)) continue;
|
|
6632
6633
|
const name2 = readString(tool, "name");
|
|
6633
6634
|
if (name2 === null || name2 === "") continue;
|
|
6634
6635
|
tools.set(name2, {
|
|
@@ -6698,7 +6699,7 @@ function extractOpenAIToolCalls(response) {
|
|
|
6698
6699
|
for (const call of readArray(message, "tool_calls")) {
|
|
6699
6700
|
const functionCall = readObject(call, "function");
|
|
6700
6701
|
const name2 = functionCall === null ? null : readString(functionCall, "name");
|
|
6701
|
-
const parsedArguments = functionCall === null ? { value: {}, issue: "function block is missing" } : parseOpenAIArguments(readProperty$
|
|
6702
|
+
const parsedArguments = functionCall === null ? { value: {}, issue: "function block is missing" } : parseOpenAIArguments(readProperty$2(functionCall, "arguments"));
|
|
6702
6703
|
calls.push({
|
|
6703
6704
|
name: name2,
|
|
6704
6705
|
arguments: parsedArguments.value,
|
|
@@ -6709,7 +6710,7 @@ function extractOpenAIToolCalls(response) {
|
|
|
6709
6710
|
}
|
|
6710
6711
|
const legacyFunctionCall = readObject(message, "function_call");
|
|
6711
6712
|
if (legacyFunctionCall !== null) {
|
|
6712
|
-
const parsedArguments = parseOpenAIArguments(readProperty$
|
|
6713
|
+
const parsedArguments = parseOpenAIArguments(readProperty$2(legacyFunctionCall, "arguments"));
|
|
6713
6714
|
calls.push({
|
|
6714
6715
|
name: readString(legacyFunctionCall, "name"),
|
|
6715
6716
|
arguments: parsedArguments.value,
|
|
@@ -6725,7 +6726,7 @@ function extractOpenAIToolCalls(response) {
|
|
|
6725
6726
|
outputIndex++;
|
|
6726
6727
|
continue;
|
|
6727
6728
|
}
|
|
6728
|
-
const parsedArguments = parseOpenAIArguments(readProperty$
|
|
6729
|
+
const parsedArguments = parseOpenAIArguments(readProperty$2(item, "arguments"));
|
|
6729
6730
|
calls.push({
|
|
6730
6731
|
name: readString(item, "name"),
|
|
6731
6732
|
arguments: parsedArguments.value,
|
|
@@ -6746,7 +6747,7 @@ function extractAnthropicToolCalls(response) {
|
|
|
6746
6747
|
}
|
|
6747
6748
|
calls.push({
|
|
6748
6749
|
name: readString(block, "name"),
|
|
6749
|
-
arguments: readProperty$
|
|
6750
|
+
arguments: readProperty$2(block, "input") ?? {},
|
|
6750
6751
|
argumentIssue: null,
|
|
6751
6752
|
location: `content[${contentIndex}]`
|
|
6752
6753
|
});
|
|
@@ -7696,7 +7697,7 @@ async function handleProxy(req) {
|
|
|
7696
7697
|
}
|
|
7697
7698
|
return handleStreamingResponse(upstreamRes, req, startTime, upstreamUrl, log, captureFullDetails);
|
|
7698
7699
|
}
|
|
7699
|
-
const Route$
|
|
7700
|
+
const Route$J = createFileRoute("/proxy/$")({
|
|
7700
7701
|
server: {
|
|
7701
7702
|
handlers: {
|
|
7702
7703
|
GET: ({ request }) => handleProxy(request),
|
|
@@ -7717,7 +7718,7 @@ function parsePositiveInt$4(value) {
|
|
|
7717
7718
|
function parseBooleanFlag(value) {
|
|
7718
7719
|
return value === "1" || value === "true";
|
|
7719
7720
|
}
|
|
7720
|
-
const Route$
|
|
7721
|
+
const Route$I = createFileRoute("/api/sessions")({
|
|
7721
7722
|
server: {
|
|
7722
7723
|
handlers: {
|
|
7723
7724
|
GET: async ({ request }) => {
|
|
@@ -9182,7 +9183,7 @@ function parsePositiveInt$3(value, fallback) {
|
|
|
9182
9183
|
if (!Number.isInteger(parsed) || parsed < 1) return fallback;
|
|
9183
9184
|
return parsed;
|
|
9184
9185
|
}
|
|
9185
|
-
const Route$
|
|
9186
|
+
const Route$H = createFileRoute("/api/runs")({
|
|
9186
9187
|
server: {
|
|
9187
9188
|
handlers: {
|
|
9188
9189
|
GET: ({ request }) => {
|
|
@@ -9228,7 +9229,7 @@ const ProviderInputSchema = object({
|
|
|
9228
9229
|
modelMetadata: array(ProviderModelMetadataSchema).optional(),
|
|
9229
9230
|
source: _enum(["company", "personal"]).optional()
|
|
9230
9231
|
});
|
|
9231
|
-
const Route$
|
|
9232
|
+
const Route$G = createFileRoute("/api/providers")({
|
|
9232
9233
|
server: {
|
|
9233
9234
|
handlers: {
|
|
9234
9235
|
GET: ({ request }) => {
|
|
@@ -9263,6 +9264,422 @@ const Route$F = createFileRoute("/api/providers")({
|
|
|
9263
9264
|
}
|
|
9264
9265
|
}
|
|
9265
9266
|
});
|
|
9267
|
+
const PiAgentRequestSchema = object({
|
|
9268
|
+
question: string().trim().min(1).max(4e3),
|
|
9269
|
+
sessionId: string().trim().min(1).optional(),
|
|
9270
|
+
providerId: string().trim().min(1).optional(),
|
|
9271
|
+
model: string().trim().min(1).optional(),
|
|
9272
|
+
logLimit: number().int().min(1).max(80).optional()
|
|
9273
|
+
});
|
|
9274
|
+
const PiAgentResponseSchema = object({
|
|
9275
|
+
answer: string(),
|
|
9276
|
+
providerId: string(),
|
|
9277
|
+
providerName: string(),
|
|
9278
|
+
model: string(),
|
|
9279
|
+
protocol: _enum(["openaiResponses", "openaiChat", "anthropic"]),
|
|
9280
|
+
logCount: number().int().nonnegative()
|
|
9281
|
+
});
|
|
9282
|
+
function isRecord$1(value) {
|
|
9283
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
9284
|
+
}
|
|
9285
|
+
function normalizeAnthropicStopReason(value) {
|
|
9286
|
+
switch (value) {
|
|
9287
|
+
case "end_turn":
|
|
9288
|
+
case "tool_use":
|
|
9289
|
+
return value;
|
|
9290
|
+
case "max_tokens":
|
|
9291
|
+
return "length";
|
|
9292
|
+
default:
|
|
9293
|
+
return null;
|
|
9294
|
+
}
|
|
9295
|
+
}
|
|
9296
|
+
function normalizeOpenAIFinishReason(value) {
|
|
9297
|
+
switch (value) {
|
|
9298
|
+
case "stop":
|
|
9299
|
+
case "length":
|
|
9300
|
+
return value;
|
|
9301
|
+
case "max_tokens":
|
|
9302
|
+
return "length";
|
|
9303
|
+
default:
|
|
9304
|
+
return null;
|
|
9305
|
+
}
|
|
9306
|
+
}
|
|
9307
|
+
function isResponsesLengthLimitReason(value) {
|
|
9308
|
+
switch (value) {
|
|
9309
|
+
case "max_output_tokens":
|
|
9310
|
+
case "max_tokens":
|
|
9311
|
+
return true;
|
|
9312
|
+
default:
|
|
9313
|
+
return false;
|
|
9314
|
+
}
|
|
9315
|
+
}
|
|
9316
|
+
function extractStopReason(log) {
|
|
9317
|
+
if (log.responseText === null) return null;
|
|
9318
|
+
try {
|
|
9319
|
+
let json = JSON.parse(log.responseText);
|
|
9320
|
+
if (typeof json === "string") {
|
|
9321
|
+
json = JSON.parse(json);
|
|
9322
|
+
}
|
|
9323
|
+
if (!isRecord$1(json)) return null;
|
|
9324
|
+
if (typeof json.stop_reason === "string") {
|
|
9325
|
+
return normalizeAnthropicStopReason(json.stop_reason);
|
|
9326
|
+
}
|
|
9327
|
+
if (Array.isArray(json.choices)) {
|
|
9328
|
+
for (const choice of json.choices) {
|
|
9329
|
+
if (!isRecord$1(choice) || typeof choice.finish_reason !== "string") continue;
|
|
9330
|
+
const reason = normalizeOpenAIFinishReason(choice.finish_reason);
|
|
9331
|
+
if (reason !== null) return reason;
|
|
9332
|
+
}
|
|
9333
|
+
}
|
|
9334
|
+
if (Array.isArray(json.output)) {
|
|
9335
|
+
for (const item of json.output) {
|
|
9336
|
+
if (isRecord$1(item) && item.type === "function_call") {
|
|
9337
|
+
return "tool_use";
|
|
9338
|
+
}
|
|
9339
|
+
}
|
|
9340
|
+
if (json.status === "completed") {
|
|
9341
|
+
return "stop";
|
|
9342
|
+
}
|
|
9343
|
+
}
|
|
9344
|
+
if (json.status === "incomplete" && isRecord$1(json.incomplete_details)) {
|
|
9345
|
+
const reason = json.incomplete_details.reason;
|
|
9346
|
+
if (typeof reason === "string" && isResponsesLengthLimitReason(reason)) {
|
|
9347
|
+
return "length";
|
|
9348
|
+
}
|
|
9349
|
+
}
|
|
9350
|
+
return null;
|
|
9351
|
+
} catch {
|
|
9352
|
+
return null;
|
|
9353
|
+
}
|
|
9354
|
+
}
|
|
9355
|
+
function isTurnBoundary(stopReason) {
|
|
9356
|
+
return stopReason === "end_turn" || stopReason === "stop" || stopReason === "length";
|
|
9357
|
+
}
|
|
9358
|
+
const DEFAULT_LOG_LIMIT = 24;
|
|
9359
|
+
const MAX_TEXT_SNIPPET = 900;
|
|
9360
|
+
const MAX_CONTEXT_CHARS = 18e3;
|
|
9361
|
+
const PI_AGENT_MAX_OUTPUT_TOKENS = 900;
|
|
9362
|
+
const DEFAULT_CONTEXT_WINDOW = 128e3;
|
|
9363
|
+
function nonEmpty(value) {
|
|
9364
|
+
return value !== void 0 && value.trim() !== "" ? value.trim() : void 0;
|
|
9365
|
+
}
|
|
9366
|
+
function firstModel(provider) {
|
|
9367
|
+
const explicitModel = nonEmpty(provider.model);
|
|
9368
|
+
if (explicitModel !== void 0) return explicitModel;
|
|
9369
|
+
for (const model of provider.models) {
|
|
9370
|
+
const trimmed = nonEmpty(model);
|
|
9371
|
+
if (trimmed !== void 0) return trimmed;
|
|
9372
|
+
}
|
|
9373
|
+
return void 0;
|
|
9374
|
+
}
|
|
9375
|
+
function providerCandidates(request) {
|
|
9376
|
+
if (request.providerId === void 0) {
|
|
9377
|
+
return getProviders().toSorted((left, right) => {
|
|
9378
|
+
const leftCompanyRank = left.source === "company" ? 0 : 1;
|
|
9379
|
+
const rightCompanyRank = right.source === "company" ? 0 : 1;
|
|
9380
|
+
if (leftCompanyRank !== rightCompanyRank) return leftCompanyRank - rightCompanyRank;
|
|
9381
|
+
return left.name.localeCompare(right.name);
|
|
9382
|
+
});
|
|
9383
|
+
}
|
|
9384
|
+
const provider = getProvider(request.providerId);
|
|
9385
|
+
return provider === void 0 ? [] : [provider];
|
|
9386
|
+
}
|
|
9387
|
+
function selectProvider(request) {
|
|
9388
|
+
for (const provider of providerCandidates(request)) {
|
|
9389
|
+
const modelName = request.model ?? firstModel(provider);
|
|
9390
|
+
if (modelName === void 0) continue;
|
|
9391
|
+
const responsesBaseUrl = nonEmpty(provider.openaiResponsesBaseUrl);
|
|
9392
|
+
if (responsesBaseUrl !== void 0) {
|
|
9393
|
+
return {
|
|
9394
|
+
provider,
|
|
9395
|
+
modelName,
|
|
9396
|
+
protocol: "openaiResponses",
|
|
9397
|
+
api: "openai-responses",
|
|
9398
|
+
baseUrl: responsesBaseUrl,
|
|
9399
|
+
upstreamPath: "/v1/responses"
|
|
9400
|
+
};
|
|
9401
|
+
}
|
|
9402
|
+
const openaiBaseUrl = nonEmpty(provider.openaiBaseUrl);
|
|
9403
|
+
if (openaiBaseUrl !== void 0) {
|
|
9404
|
+
return {
|
|
9405
|
+
provider,
|
|
9406
|
+
modelName,
|
|
9407
|
+
protocol: "openaiChat",
|
|
9408
|
+
api: "openai-completions",
|
|
9409
|
+
baseUrl: openaiBaseUrl,
|
|
9410
|
+
upstreamPath: "/v1/chat/completions"
|
|
9411
|
+
};
|
|
9412
|
+
}
|
|
9413
|
+
const anthropicBaseUrl = nonEmpty(provider.anthropicBaseUrl);
|
|
9414
|
+
if (anthropicBaseUrl !== void 0) {
|
|
9415
|
+
return {
|
|
9416
|
+
provider,
|
|
9417
|
+
modelName,
|
|
9418
|
+
protocol: "anthropic",
|
|
9419
|
+
api: "anthropic-messages",
|
|
9420
|
+
baseUrl: anthropicBaseUrl,
|
|
9421
|
+
upstreamPath: "/v1/messages"
|
|
9422
|
+
};
|
|
9423
|
+
}
|
|
9424
|
+
}
|
|
9425
|
+
return null;
|
|
9426
|
+
}
|
|
9427
|
+
function truncate$1(value, maxLength) {
|
|
9428
|
+
if (value.length <= maxLength) return value;
|
|
9429
|
+
return `${value.slice(0, maxLength)}
|
|
9430
|
+
...[truncated ${String(value.length - maxLength)} chars]`;
|
|
9431
|
+
}
|
|
9432
|
+
function readProperty$1(value, key) {
|
|
9433
|
+
if (value === null || typeof value !== "object" || Array.isArray(value)) return void 0;
|
|
9434
|
+
return Object.getOwnPropertyDescriptor(value, key)?.value;
|
|
9435
|
+
}
|
|
9436
|
+
function collectStringProperties(value, keys, output) {
|
|
9437
|
+
if (value === null || typeof value !== "object") return;
|
|
9438
|
+
for (const key of keys) {
|
|
9439
|
+
const property = readProperty$1(value, key);
|
|
9440
|
+
if (typeof property === "string" && property.trim() !== "") {
|
|
9441
|
+
output.add(property.trim());
|
|
9442
|
+
}
|
|
9443
|
+
}
|
|
9444
|
+
}
|
|
9445
|
+
function collectToolNamesFromUnknown(value, output, depth = 0) {
|
|
9446
|
+
if (depth > 5 || value === null || typeof value !== "object") return;
|
|
9447
|
+
collectStringProperties(value, ["name", "tool_name"], output);
|
|
9448
|
+
collectStringProperties(readProperty$1(value, "function"), ["name"], output);
|
|
9449
|
+
if (Array.isArray(value)) {
|
|
9450
|
+
for (const item of value) {
|
|
9451
|
+
collectToolNamesFromUnknown(item, output, depth + 1);
|
|
9452
|
+
}
|
|
9453
|
+
return;
|
|
9454
|
+
}
|
|
9455
|
+
for (const candidateKey of ["tools", "tool_calls", "content", "output", "input", "messages"]) {
|
|
9456
|
+
collectToolNamesFromUnknown(readProperty$1(value, candidateKey), output, depth + 1);
|
|
9457
|
+
}
|
|
9458
|
+
}
|
|
9459
|
+
function collectToolNames(log) {
|
|
9460
|
+
const tools = /* @__PURE__ */ new Set();
|
|
9461
|
+
for (const raw of [log.rawRequestBody, log.responseText]) {
|
|
9462
|
+
if (raw === null || raw.trim() === "") continue;
|
|
9463
|
+
try {
|
|
9464
|
+
const parsed = JSON.parse(raw);
|
|
9465
|
+
collectToolNamesFromUnknown(parsed, tools);
|
|
9466
|
+
} catch {
|
|
9467
|
+
}
|
|
9468
|
+
}
|
|
9469
|
+
return [...tools].slice(0, 12);
|
|
9470
|
+
}
|
|
9471
|
+
function summarizeLog(log) {
|
|
9472
|
+
const stopReason = extractStopReason(log);
|
|
9473
|
+
const tools = collectToolNames(log);
|
|
9474
|
+
const requestSnippet = log.rawRequestBody !== null ? truncate$1(log.rawRequestBody, MAX_TEXT_SNIPPET) : "[not captured]";
|
|
9475
|
+
const responseSnippet = log.responseText !== null ? truncate$1(log.responseText, MAX_TEXT_SNIPPET) : "[not captured]";
|
|
9476
|
+
const warnings = log.warnings !== void 0 && log.warnings.length > 0 ? log.warnings : [];
|
|
9477
|
+
return [
|
|
9478
|
+
`Log #${String(log.id)} ${log.timestamp}`,
|
|
9479
|
+
`path=${log.path} format=${log.apiFormat} model=${log.model ?? "unknown"} provider=${log.providerName ?? "unknown"}`,
|
|
9480
|
+
`session=${log.sessionId ?? "unknown"} pid=${log.clientPid?.toString() ?? "unknown"} status=${log.responseStatus?.toString() ?? "pending"} streaming=${String(log.streaming)}`,
|
|
9481
|
+
`elapsedMs=${log.elapsedMs?.toString() ?? "unknown"} firstChunkMs=${log.firstChunkMs?.toString() ?? "unknown"} tokens=${log.inputTokens?.toString() ?? "?"}/${log.outputTokens?.toString() ?? "?"} stop=${stopReason ?? "unknown"}`,
|
|
9482
|
+
tools.length > 0 ? `tools=${tools.join(", ")}` : "tools=none detected",
|
|
9483
|
+
warnings.length > 0 ? `warnings=${warnings.join(" | ")}` : "warnings=none",
|
|
9484
|
+
log.error !== null && log.error !== void 0 ? `error=${log.error}` : "error=none",
|
|
9485
|
+
`requestSnippet:
|
|
9486
|
+
${requestSnippet}`,
|
|
9487
|
+
`responseSnippet:
|
|
9488
|
+
${responseSnippet}`
|
|
9489
|
+
].join("\n");
|
|
9490
|
+
}
|
|
9491
|
+
async function buildInspectorContext(request) {
|
|
9492
|
+
const limit = request.logLimit ?? DEFAULT_LOG_LIMIT;
|
|
9493
|
+
const page = await listLogsPage({
|
|
9494
|
+
sessionId: request.sessionId,
|
|
9495
|
+
offset: 0,
|
|
9496
|
+
limit,
|
|
9497
|
+
includeBodies: true
|
|
9498
|
+
});
|
|
9499
|
+
const logs = page.logs.slice(-limit);
|
|
9500
|
+
const context = truncate$1(logs.map(summarizeLog).join("\n\n---\n\n"), MAX_CONTEXT_CHARS);
|
|
9501
|
+
return { context, logCount: logs.length };
|
|
9502
|
+
}
|
|
9503
|
+
function buildSystemPrompt() {
|
|
9504
|
+
return [
|
|
9505
|
+
"You are Pi Agent, the built-in analysis agent inside TonyClaw Agent Inspector.",
|
|
9506
|
+
"Analyze AI coding tool requests, responses, provider behavior, sessions, turns, tools, token usage, and hanging interactions.",
|
|
9507
|
+
"Be concrete. Cite log ids when possible. Distinguish evidence from inference.",
|
|
9508
|
+
"Give a short diagnosis first, then the likely cause, then practical next actions.",
|
|
9509
|
+
"Do not invent raw data that is not present in the Inspector context."
|
|
9510
|
+
].join("\n");
|
|
9511
|
+
}
|
|
9512
|
+
function buildUserPrompt(question, context) {
|
|
9513
|
+
return [
|
|
9514
|
+
`User question:
|
|
9515
|
+
${question}`,
|
|
9516
|
+
"",
|
|
9517
|
+
"Inspector context:",
|
|
9518
|
+
context !== "" ? context : "No logs were loaded for this scope."
|
|
9519
|
+
].join("\n");
|
|
9520
|
+
}
|
|
9521
|
+
function stripUrlSuffix(value, suffix) {
|
|
9522
|
+
if (!value.endsWith(suffix)) return null;
|
|
9523
|
+
const stripped = value.slice(0, -suffix.length);
|
|
9524
|
+
return stripped === "" ? "/" : stripped;
|
|
9525
|
+
}
|
|
9526
|
+
function sdkBaseUrlFromFinalUrl(finalUrl, protocol) {
|
|
9527
|
+
try {
|
|
9528
|
+
const url = new URL(finalUrl);
|
|
9529
|
+
const pathname = url.pathname.replace(/\/+$/, "");
|
|
9530
|
+
const suffixes = protocol === "openaiResponses" ? ["/responses"] : protocol === "openaiChat" ? ["/chat/completions"] : ["/v1/messages", "/messages"];
|
|
9531
|
+
for (const suffix of suffixes) {
|
|
9532
|
+
const nextPath = stripUrlSuffix(pathname, suffix);
|
|
9533
|
+
if (nextPath !== null) {
|
|
9534
|
+
url.pathname = nextPath;
|
|
9535
|
+
return url.toString().replace(/\/+$/, "");
|
|
9536
|
+
}
|
|
9537
|
+
}
|
|
9538
|
+
} catch {
|
|
9539
|
+
}
|
|
9540
|
+
return finalUrl.replace(/\/+$/, "");
|
|
9541
|
+
}
|
|
9542
|
+
function buildPiBaseUrl(selected) {
|
|
9543
|
+
const finalUrl = buildUpstreamUrl(selected.baseUrl, selected.upstreamPath);
|
|
9544
|
+
return sdkBaseUrlFromFinalUrl(finalUrl, selected.protocol);
|
|
9545
|
+
}
|
|
9546
|
+
function modelMetadataFor(provider, modelName) {
|
|
9547
|
+
const metadata = provider.modelMetadata?.find((item) => item.model === modelName);
|
|
9548
|
+
return {
|
|
9549
|
+
contextWindow: metadata?.contextWindow ?? DEFAULT_CONTEXT_WINDOW,
|
|
9550
|
+
outputLimit: metadata?.outputLimit ?? PI_AGENT_MAX_OUTPUT_TOKENS
|
|
9551
|
+
};
|
|
9552
|
+
}
|
|
9553
|
+
function buildPiHeaders(provider) {
|
|
9554
|
+
if (provider.authHeader !== AUTH_HEADER_X_API_KEY) return void 0;
|
|
9555
|
+
return { [AUTH_HEADER_X_API_KEY]: provider.apiKey };
|
|
9556
|
+
}
|
|
9557
|
+
function buildPiModel(selected) {
|
|
9558
|
+
const metadata = modelMetadataFor(selected.provider, selected.modelName);
|
|
9559
|
+
const usageModelName = getModelUsageName(selected.modelName, selected.provider.name);
|
|
9560
|
+
return {
|
|
9561
|
+
id: usageModelName,
|
|
9562
|
+
name: selected.modelName,
|
|
9563
|
+
api: selected.api,
|
|
9564
|
+
provider: selected.provider.name,
|
|
9565
|
+
baseUrl: buildPiBaseUrl(selected),
|
|
9566
|
+
reasoning: false,
|
|
9567
|
+
input: ["text"],
|
|
9568
|
+
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
|
|
9569
|
+
contextWindow: metadata.contextWindow,
|
|
9570
|
+
maxTokens: Math.max(metadata.outputLimit, PI_AGENT_MAX_OUTPUT_TOKENS),
|
|
9571
|
+
headers: buildPiHeaders(selected.provider)
|
|
9572
|
+
};
|
|
9573
|
+
}
|
|
9574
|
+
function textFromAssistantMessage(message) {
|
|
9575
|
+
const parts = [];
|
|
9576
|
+
for (const block of message.content) {
|
|
9577
|
+
if (block.type === "text" && block.text.trim() !== "") {
|
|
9578
|
+
parts.push(block.text);
|
|
9579
|
+
}
|
|
9580
|
+
}
|
|
9581
|
+
return parts.join("\n").trim();
|
|
9582
|
+
}
|
|
9583
|
+
function stripReasoningTags(value) {
|
|
9584
|
+
const stripped = value.replace(/<think>[\s\S]*?<\/think>/gi, "").trim();
|
|
9585
|
+
return stripped !== "" ? stripped : value.trim();
|
|
9586
|
+
}
|
|
9587
|
+
function lastAssistantMessage(messages) {
|
|
9588
|
+
for (let index = messages.length - 1; index >= 0; index -= 1) {
|
|
9589
|
+
const message = messages[index];
|
|
9590
|
+
if (message !== void 0 && message.role === "assistant") return message;
|
|
9591
|
+
}
|
|
9592
|
+
return null;
|
|
9593
|
+
}
|
|
9594
|
+
function buildContext(question, inspectorContext) {
|
|
9595
|
+
return {
|
|
9596
|
+
systemPrompt: buildSystemPrompt(),
|
|
9597
|
+
messages: [
|
|
9598
|
+
{
|
|
9599
|
+
role: "user",
|
|
9600
|
+
content: buildUserPrompt(question, inspectorContext),
|
|
9601
|
+
timestamp: Date.now()
|
|
9602
|
+
}
|
|
9603
|
+
]
|
|
9604
|
+
};
|
|
9605
|
+
}
|
|
9606
|
+
async function askPi(selected, question, inspectorContext) {
|
|
9607
|
+
const { Agent } = await import(
|
|
9608
|
+
/* @vite-ignore */
|
|
9609
|
+
"../_libs/mariozechner__pi-agent-core.mjs"
|
|
9610
|
+
);
|
|
9611
|
+
const model = buildPiModel(selected);
|
|
9612
|
+
const agent = new Agent({
|
|
9613
|
+
initialState: {
|
|
9614
|
+
model,
|
|
9615
|
+
systemPrompt: buildSystemPrompt(),
|
|
9616
|
+
tools: []
|
|
9617
|
+
},
|
|
9618
|
+
getApiKey: () => selected.provider.apiKey,
|
|
9619
|
+
sessionId: selected.provider.id,
|
|
9620
|
+
maxRetryDelayMs: 1e4
|
|
9621
|
+
});
|
|
9622
|
+
const context = buildContext(question, inspectorContext);
|
|
9623
|
+
await agent.prompt(context.messages);
|
|
9624
|
+
const assistantMessage = lastAssistantMessage(agent.state.messages);
|
|
9625
|
+
if (assistantMessage === null) {
|
|
9626
|
+
return agent.state.errorMessage ?? "Pi Agent returned no assistant message.";
|
|
9627
|
+
}
|
|
9628
|
+
const answer = textFromAssistantMessage(assistantMessage);
|
|
9629
|
+
if (answer !== "") return stripReasoningTags(answer);
|
|
9630
|
+
return assistantMessage.errorMessage ?? "Pi Agent received an empty provider response.";
|
|
9631
|
+
}
|
|
9632
|
+
async function runPiAgent(request) {
|
|
9633
|
+
const selected = selectProvider(request);
|
|
9634
|
+
if (selected === null) {
|
|
9635
|
+
return {
|
|
9636
|
+
answer: "Pi Agent needs at least one Provider with OpenAI Responses, OpenAI Chat, or Anthropic Messages configured.",
|
|
9637
|
+
providerId: "",
|
|
9638
|
+
providerName: "No provider",
|
|
9639
|
+
model: "",
|
|
9640
|
+
protocol: "openaiChat",
|
|
9641
|
+
logCount: 0
|
|
9642
|
+
};
|
|
9643
|
+
}
|
|
9644
|
+
const { context, logCount } = await buildInspectorContext(request);
|
|
9645
|
+
let answer;
|
|
9646
|
+
try {
|
|
9647
|
+
answer = await askPi(selected, request.question, context);
|
|
9648
|
+
} catch (err) {
|
|
9649
|
+
answer = `Pi Agent provider request failed: ${err instanceof Error ? err.message : String(err)}`;
|
|
9650
|
+
}
|
|
9651
|
+
return {
|
|
9652
|
+
answer,
|
|
9653
|
+
providerId: selected.provider.id,
|
|
9654
|
+
providerName: selected.provider.name,
|
|
9655
|
+
model: selected.modelName,
|
|
9656
|
+
protocol: selected.protocol,
|
|
9657
|
+
logCount
|
|
9658
|
+
};
|
|
9659
|
+
}
|
|
9660
|
+
const Route$F = createFileRoute("/api/pi-agent")({
|
|
9661
|
+
server: {
|
|
9662
|
+
handlers: {
|
|
9663
|
+
POST: async ({ request }) => {
|
|
9664
|
+
let body;
|
|
9665
|
+
try {
|
|
9666
|
+
body = await request.json();
|
|
9667
|
+
} catch {
|
|
9668
|
+
return Response.json({ error: "Invalid JSON body" }, { status: 400 });
|
|
9669
|
+
}
|
|
9670
|
+
const parsed = PiAgentRequestSchema.safeParse(body);
|
|
9671
|
+
if (!parsed.success) {
|
|
9672
|
+
return Response.json(
|
|
9673
|
+
{ error: "Invalid Pi-agent request", details: parsed.error.format() },
|
|
9674
|
+
{ status: 400 }
|
|
9675
|
+
);
|
|
9676
|
+
}
|
|
9677
|
+
const result = await runPiAgent(parsed.data);
|
|
9678
|
+
return Response.json(result);
|
|
9679
|
+
}
|
|
9680
|
+
}
|
|
9681
|
+
}
|
|
9682
|
+
});
|
|
9266
9683
|
const Route$E = createFileRoute("/api/models")({
|
|
9267
9684
|
server: {
|
|
9268
9685
|
handlers: {
|
|
@@ -9271,7 +9688,7 @@ const Route$E = createFileRoute("/api/models")({
|
|
|
9271
9688
|
}
|
|
9272
9689
|
});
|
|
9273
9690
|
const name = "@tonyclaw/agent-inspector";
|
|
9274
|
-
const version = "3.0.
|
|
9691
|
+
const version = "3.0.18";
|
|
9275
9692
|
const packageJson = {
|
|
9276
9693
|
name,
|
|
9277
9694
|
version
|
|
@@ -17669,70 +18086,75 @@ const Route = createFileRoute("/api/ecosystem/packages/$packageId/help")({
|
|
|
17669
18086
|
}
|
|
17670
18087
|
}
|
|
17671
18088
|
});
|
|
17672
|
-
const IndexRoute = Route$
|
|
18089
|
+
const IndexRoute = Route$L.update({
|
|
17673
18090
|
id: "/",
|
|
17674
18091
|
path: "/",
|
|
17675
|
-
getParentRoute: () => Route$
|
|
18092
|
+
getParentRoute: () => Route$M
|
|
17676
18093
|
});
|
|
17677
|
-
const SessionSessionIdRoute = Route$
|
|
18094
|
+
const SessionSessionIdRoute = Route$K.update({
|
|
17678
18095
|
id: "/session/$sessionId",
|
|
17679
18096
|
path: "/session/$sessionId",
|
|
17680
|
-
getParentRoute: () => Route$
|
|
18097
|
+
getParentRoute: () => Route$M
|
|
17681
18098
|
});
|
|
17682
|
-
const ProxySplatRoute = Route$
|
|
18099
|
+
const ProxySplatRoute = Route$J.update({
|
|
17683
18100
|
id: "/proxy/$",
|
|
17684
18101
|
path: "/proxy/$",
|
|
17685
|
-
getParentRoute: () => Route$
|
|
18102
|
+
getParentRoute: () => Route$M
|
|
17686
18103
|
});
|
|
17687
|
-
const ApiSessionsRoute = Route$
|
|
18104
|
+
const ApiSessionsRoute = Route$I.update({
|
|
17688
18105
|
id: "/api/sessions",
|
|
17689
18106
|
path: "/api/sessions",
|
|
17690
|
-
getParentRoute: () => Route$
|
|
18107
|
+
getParentRoute: () => Route$M
|
|
17691
18108
|
});
|
|
17692
|
-
const ApiRunsRoute = Route$
|
|
18109
|
+
const ApiRunsRoute = Route$H.update({
|
|
17693
18110
|
id: "/api/runs",
|
|
17694
18111
|
path: "/api/runs",
|
|
17695
|
-
getParentRoute: () => Route$
|
|
18112
|
+
getParentRoute: () => Route$M
|
|
17696
18113
|
});
|
|
17697
|
-
const ApiProvidersRoute = Route$
|
|
18114
|
+
const ApiProvidersRoute = Route$G.update({
|
|
17698
18115
|
id: "/api/providers",
|
|
17699
18116
|
path: "/api/providers",
|
|
17700
|
-
getParentRoute: () => Route$
|
|
18117
|
+
getParentRoute: () => Route$M
|
|
18118
|
+
});
|
|
18119
|
+
const ApiPiAgentRoute = Route$F.update({
|
|
18120
|
+
id: "/api/pi-agent",
|
|
18121
|
+
path: "/api/pi-agent",
|
|
18122
|
+
getParentRoute: () => Route$M
|
|
17701
18123
|
});
|
|
17702
18124
|
const ApiModelsRoute = Route$E.update({
|
|
17703
18125
|
id: "/api/models",
|
|
17704
18126
|
path: "/api/models",
|
|
17705
|
-
getParentRoute: () => Route$
|
|
18127
|
+
getParentRoute: () => Route$M
|
|
17706
18128
|
});
|
|
17707
18129
|
const ApiMcpRoute = Route$D.update({
|
|
17708
18130
|
id: "/api/mcp",
|
|
17709
18131
|
path: "/api/mcp",
|
|
17710
|
-
getParentRoute: () => Route$
|
|
18132
|
+
getParentRoute: () => Route$M
|
|
17711
18133
|
});
|
|
17712
18134
|
const ApiLogsRoute = Route$C.update({
|
|
17713
18135
|
id: "/api/logs",
|
|
17714
18136
|
path: "/api/logs",
|
|
17715
|
-
getParentRoute: () => Route$
|
|
18137
|
+
getParentRoute: () => Route$M
|
|
17716
18138
|
});
|
|
17717
18139
|
const ApiHealthRoute = Route$B.update({
|
|
17718
18140
|
id: "/api/health",
|
|
17719
18141
|
path: "/api/health",
|
|
17720
|
-
getParentRoute: () => Route$
|
|
18142
|
+
getParentRoute: () => Route$M
|
|
17721
18143
|
});
|
|
17722
18144
|
const ApiGroupsRoute = Route$A.update({
|
|
17723
18145
|
id: "/api/groups",
|
|
17724
18146
|
path: "/api/groups",
|
|
17725
|
-
getParentRoute: () => Route$
|
|
18147
|
+
getParentRoute: () => Route$M
|
|
17726
18148
|
});
|
|
17727
18149
|
const ApiConfigRoute = Route$z.update({
|
|
17728
18150
|
id: "/api/config",
|
|
17729
18151
|
path: "/api/config",
|
|
17730
|
-
getParentRoute: () => Route$
|
|
18152
|
+
getParentRoute: () => Route$M
|
|
17731
18153
|
});
|
|
17732
18154
|
const ApiAlertsRoute = Route$y.update({
|
|
17733
18155
|
id: "/api/alerts",
|
|
17734
18156
|
path: "/api/alerts",
|
|
17735
|
-
getParentRoute: () => Route$
|
|
18157
|
+
getParentRoute: () => Route$M
|
|
17736
18158
|
});
|
|
17737
18159
|
const ApiRunsRunIdRoute = Route$x.update({
|
|
17738
18160
|
id: "/$runId",
|
|
@@ -17777,17 +18199,17 @@ const ApiLogsIdRoute = Route$q.update({
|
|
|
17777
18199
|
const ApiKnowledgeSearchRoute = Route$p.update({
|
|
17778
18200
|
id: "/api/knowledge/search",
|
|
17779
18201
|
path: "/api/knowledge/search",
|
|
17780
|
-
getParentRoute: () => Route$
|
|
18202
|
+
getParentRoute: () => Route$M
|
|
17781
18203
|
});
|
|
17782
18204
|
const ApiKnowledgeProjectContextRoute = Route$o.update({
|
|
17783
18205
|
id: "/api/knowledge/project-context",
|
|
17784
18206
|
path: "/api/knowledge/project-context",
|
|
17785
|
-
getParentRoute: () => Route$
|
|
18207
|
+
getParentRoute: () => Route$M
|
|
17786
18208
|
});
|
|
17787
18209
|
const ApiKnowledgeCandidatesRoute = Route$n.update({
|
|
17788
18210
|
id: "/api/knowledge/candidates",
|
|
17789
18211
|
path: "/api/knowledge/candidates",
|
|
17790
|
-
getParentRoute: () => Route$
|
|
18212
|
+
getParentRoute: () => Route$M
|
|
17791
18213
|
});
|
|
17792
18214
|
const ApiGroupsGroupIdRoute = Route$m.update({
|
|
17793
18215
|
id: "/$groupId",
|
|
@@ -17797,12 +18219,12 @@ const ApiGroupsGroupIdRoute = Route$m.update({
|
|
|
17797
18219
|
const ApiEcosystemTasksRoute = Route$l.update({
|
|
17798
18220
|
id: "/api/ecosystem/tasks",
|
|
17799
18221
|
path: "/api/ecosystem/tasks",
|
|
17800
|
-
getParentRoute: () => Route$
|
|
18222
|
+
getParentRoute: () => Route$M
|
|
17801
18223
|
});
|
|
17802
18224
|
const ApiEcosystemPackagesRoute = Route$k.update({
|
|
17803
18225
|
id: "/api/ecosystem/packages",
|
|
17804
18226
|
path: "/api/ecosystem/packages",
|
|
17805
|
-
getParentRoute: () => Route$
|
|
18227
|
+
getParentRoute: () => Route$M
|
|
17806
18228
|
});
|
|
17807
18229
|
const ApiConfigPathsRoute = Route$j.update({
|
|
17808
18230
|
id: "/paths",
|
|
@@ -17872,7 +18294,7 @@ const ApiProvidersProviderIdTestLogRoute = Route$7.update({
|
|
|
17872
18294
|
const ApiKnowledgeSessionsSessionIdCandidatesRoute = Route$6.update({
|
|
17873
18295
|
id: "/api/knowledge/sessions/$sessionId/candidates",
|
|
17874
18296
|
path: "/api/knowledge/sessions/$sessionId/candidates",
|
|
17875
|
-
getParentRoute: () => Route$
|
|
18297
|
+
getParentRoute: () => Route$M
|
|
17876
18298
|
});
|
|
17877
18299
|
const ApiKnowledgeCandidatesCandidateIdPromoteRoute = Route$5.update({
|
|
17878
18300
|
id: "/promote",
|
|
@@ -17882,7 +18304,7 @@ const ApiKnowledgeCandidatesCandidateIdPromoteRoute = Route$5.update({
|
|
|
17882
18304
|
const ApiEcosystemRecipesRecipeIdRunRoute = Route$4.update({
|
|
17883
18305
|
id: "/api/ecosystem/recipes/$recipeId/run",
|
|
17884
18306
|
path: "/api/ecosystem/recipes/$recipeId/run",
|
|
17885
|
-
getParentRoute: () => Route$
|
|
18307
|
+
getParentRoute: () => Route$M
|
|
17886
18308
|
});
|
|
17887
18309
|
const ApiEcosystemPackagesPackageIdUpgradeRoute = Route$3.update({
|
|
17888
18310
|
id: "/$packageId/upgrade",
|
|
@@ -18005,6 +18427,7 @@ const rootRouteChildren = {
|
|
|
18005
18427
|
ApiLogsRoute: ApiLogsRouteWithChildren,
|
|
18006
18428
|
ApiMcpRoute,
|
|
18007
18429
|
ApiModelsRoute,
|
|
18430
|
+
ApiPiAgentRoute,
|
|
18008
18431
|
ApiProvidersRoute: ApiProvidersRouteWithChildren,
|
|
18009
18432
|
ApiRunsRoute: ApiRunsRouteWithChildren,
|
|
18010
18433
|
ApiSessionsRoute,
|
|
@@ -18018,7 +18441,7 @@ const rootRouteChildren = {
|
|
|
18018
18441
|
ApiEcosystemRecipesRecipeIdRunRoute,
|
|
18019
18442
|
ApiKnowledgeSessionsSessionIdCandidatesRoute
|
|
18020
18443
|
};
|
|
18021
|
-
const routeTree = Route$
|
|
18444
|
+
const routeTree = Route$M._addFileChildren(rootRouteChildren)._addFileTypes();
|
|
18022
18445
|
function getRouter() {
|
|
18023
18446
|
const router2 = createRouter({
|
|
18024
18447
|
routeTree,
|
|
@@ -18045,24 +18468,27 @@ const router = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProper
|
|
|
18045
18468
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
18046
18469
|
export {
|
|
18047
18470
|
AnthropicResponseSchema$1 as A,
|
|
18048
|
-
|
|
18471
|
+
previewUpstreamUrl as B,
|
|
18049
18472
|
CapturedLogSchema as C,
|
|
18050
18473
|
DEFAULT_CAPTURE_MODE as D,
|
|
18051
|
-
|
|
18052
|
-
|
|
18474
|
+
createPendingProviderTestResults as E,
|
|
18475
|
+
ProviderTestResultsSchema as F,
|
|
18053
18476
|
GroupEvidenceReadResponseSchema as G,
|
|
18054
|
-
|
|
18477
|
+
createFailedProviderTestResults as H,
|
|
18055
18478
|
InspectorGroupsListResponseSchema as I,
|
|
18056
|
-
|
|
18479
|
+
MAX_PROVIDER_TEST_TIMEOUT_SECONDS as J,
|
|
18057
18480
|
KnowledgeCandidateSchema as K,
|
|
18058
18481
|
LogBodyChunkSchema as L,
|
|
18059
18482
|
MAX_SLOW_RESPONSE_THRESHOLD_SECONDS as M,
|
|
18060
|
-
|
|
18483
|
+
PiAgentResponseSchema as N,
|
|
18061
18484
|
OpenAIRequestSchema as O,
|
|
18062
18485
|
ProviderConfigSchema as P,
|
|
18063
|
-
|
|
18064
|
-
|
|
18486
|
+
resolveProviderContextWindow as Q,
|
|
18487
|
+
Route$K as R,
|
|
18488
|
+
isPlainRecord as S,
|
|
18065
18489
|
TimeDisplayFormatSchema as T,
|
|
18490
|
+
StreamingChunkSchema$1 as U,
|
|
18491
|
+
router as V,
|
|
18066
18492
|
DEFAULT_SLOW_RESPONSE_THRESHOLD_SECONDS as a,
|
|
18067
18493
|
DEFAULT_PROVIDER_TEST_TIMEOUT_SECONDS as b,
|
|
18068
18494
|
DEFAULT_TIME_DISPLAY_FORMAT as c,
|
|
@@ -18074,19 +18500,19 @@ export {
|
|
|
18074
18500
|
apiFormatForPath as i,
|
|
18075
18501
|
getSessionPath as j,
|
|
18076
18502
|
stripClaudeCodeBillingHeader as k,
|
|
18077
|
-
|
|
18078
|
-
|
|
18079
|
-
|
|
18080
|
-
|
|
18503
|
+
isTurnBoundary as l,
|
|
18504
|
+
extractStopReason as m,
|
|
18505
|
+
AlertSummarySchema as n,
|
|
18506
|
+
AlertListResponseSchema as o,
|
|
18081
18507
|
packageJson as p,
|
|
18082
|
-
|
|
18083
|
-
|
|
18508
|
+
DeleteInspectorGroupsResponseSchema as q,
|
|
18509
|
+
GroupEvidenceExportResultSchema as r,
|
|
18084
18510
|
safeGetOwnProperty as s,
|
|
18085
|
-
|
|
18086
|
-
|
|
18087
|
-
|
|
18088
|
-
|
|
18089
|
-
|
|
18090
|
-
|
|
18091
|
-
|
|
18511
|
+
DeleteInspectorGroupResponseSchema as t,
|
|
18512
|
+
providerHasContextMetadata as u,
|
|
18513
|
+
maskApiKey as v,
|
|
18514
|
+
findProviderModelMetadata as w,
|
|
18515
|
+
PATH_V1_MESSAGES as x,
|
|
18516
|
+
PATH_V1_CHAT_COMPLETIONS as y,
|
|
18517
|
+
PATH_V1_RESPONSES as z
|
|
18092
18518
|
};
|