linkque-cli-v2 1.4.3 → 1.4.5
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/linkquejs.js +147 -48
- package/package.json +1 -1
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/{chunk-Y36JLYIE.js → chunk-CLYLJ5MD.js} +1257 -1217
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/{chunk-OMFQ2KRJ.js → chunk-NFVKWQGM.js} +1 -1
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/{chunk-SAQYWJAA.js → chunk-S75HFRLD.js} +1 -1
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/runtime/handler/chat.js +59 -9
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/runtime/handler/clientCapability.js +2 -2
- package/vendor/linkque-agent-appwrite-integrate/dist/esm/runtime/protocol.js +2 -2
- package/vendor/linkque-agent-appwrite-integrate/package.json +1 -1
- package/worker.js +468 -383
package/linkquejs.js
CHANGED
|
@@ -23801,21 +23801,8 @@ function cloneBinding(binding) {
|
|
|
23801
23801
|
return JSON.parse(JSON.stringify(binding));
|
|
23802
23802
|
}
|
|
23803
23803
|
|
|
23804
|
-
// ../linkque-agent-runtime/dist/esm/core/mcpProxyTool.js
|
|
23805
|
-
var MCP_PROXY_DESCRIPTION = [
|
|
23806
|
-
"MCP \u7F51\u5173:\u53D1\u73B0\u5E76\u8C03\u7528 MCP server \u63D0\u4F9B\u7684\u5DE5\u5177\u3002\u53EF\u7528\u52A8\u4F5C:",
|
|
23807
|
-
"- mcp({}) \u6216 mcp({ status: true }):\u67E5\u770B\u6240\u6709 server \u8FDE\u63A5\u72B6\u6001\u4E0E\u5DE5\u5177\u6570\u3002",
|
|
23808
|
-
'- mcp({ connect: "server" }):\u8FDE\u63A5\u5E76\u5237\u65B0\u67D0 server \u7684\u5DE5\u5177\u5217\u8868\u3002',
|
|
23809
|
-
'- mcp({ server: "name" }):\u5217\u51FA\u8BE5 server \u7684\u5DE5\u5177\u3002',
|
|
23810
|
-
'- mcp({ search: "\u5173\u952E\u8BCD" }):\u6309\u540D\u79F0/\u63CF\u8FF0\u6A21\u7CCA\u641C\u7D22\u5DE5\u5177(\u7A7A\u683C\u5206\u8BCD OR)\u3002',
|
|
23811
|
-
'- mcp({ searches: ["\u5173\u952E\u8BCD1", "\u5173\u952E\u8BCD2"] }):\u4E00\u6B21\u6267\u884C\u591A\u7EC4\u641C\u7D22\u5E76\u6309 query \u5206\u7EC4\u8FD4\u56DE(\u6700\u591A 5 \u7EC4)\u3002',
|
|
23812
|
-
'- mcp({ describe: "toolName" }):\u67E5\u770B\u67D0\u5DE5\u5177\u7684\u53C2\u6570 schema\u3002',
|
|
23813
|
-
'- mcp({ tool: "toolName", args: { ... } }):\u8C03\u7528\u67D0\u5DE5\u5177,args \u4E3A\u5BF9\u8C61\u3002',
|
|
23814
|
-
"\u53EF\u7528 server \u540D\u89C1 mcp({}) \u8F93\u51FA\u3002\u4EC5\u5728\u786E\u9700\u8C03\u7528 MCP \u5DE5\u5177\u65F6\u4F7F\u7528\u672C\u5DE5\u5177\u3002",
|
|
23815
|
-
"\u4EC5 mcp({}) \u5217\u51FA\u7684\u5DE5\u5177\u53EF\u8C03\u7528(\u672A\u58F0\u660E\u7684\u5DE5\u5177\u4E0D\u4F1A\u51FA\u73B0)\u3002"
|
|
23816
|
-
].join("\n");
|
|
23817
|
-
|
|
23818
23804
|
// ../linkque-agent-protocol/dist/esm/telemetry/telemetryEnums.js
|
|
23805
|
+
var CONTENT_VALUE_MAX_LENGTH = 16 * 1024;
|
|
23819
23806
|
var ETelemetryAttribute;
|
|
23820
23807
|
(function(ETelemetryAttribute2) {
|
|
23821
23808
|
ETelemetryAttribute2["HARNESS_TELEMETRY_SCHEMA_VERSION"] = "harness.telemetry.schema.version";
|
|
@@ -23872,6 +23859,7 @@ var ETelemetryAttribute;
|
|
|
23872
23859
|
ETelemetryAttribute2["GEN_AI_REQUEST_MODEL"] = "gen_ai.request.model";
|
|
23873
23860
|
ETelemetryAttribute2["GEN_AI_RESPONSE_MODEL"] = "gen_ai.response.model";
|
|
23874
23861
|
ETelemetryAttribute2["GEN_AI_RESPONSE_ID"] = "gen_ai.response.id";
|
|
23862
|
+
ETelemetryAttribute2["LINKQUE_CONTENT_VALUE_TRUNCATED"] = "linkque.content.value.truncated";
|
|
23875
23863
|
ETelemetryAttribute2["GEN_AI_RESPONSE_FINISH_REASONS"] = "gen_ai.response.finish_reasons";
|
|
23876
23864
|
ETelemetryAttribute2["GEN_AI_USAGE_INPUT_TOKENS"] = "gen_ai.usage.input_tokens";
|
|
23877
23865
|
ETelemetryAttribute2["GEN_AI_USAGE_OUTPUT_TOKENS"] = "gen_ai.usage.output_tokens";
|
|
@@ -23975,11 +23963,13 @@ var ETelemetryEventName;
|
|
|
23975
23963
|
ETelemetryEventName2["HISTORY_APPEND_FINISHED"] = "linkque.history.append.finished";
|
|
23976
23964
|
ETelemetryEventName2["HOOK_DRAIN_STARTED"] = "linkque.hook.drain.started";
|
|
23977
23965
|
ETelemetryEventName2["HOOK_DRAIN_FINISHED"] = "linkque.hook.drain.finished";
|
|
23978
|
-
ETelemetryEventName2["
|
|
23966
|
+
ETelemetryEventName2["CONTENT_RECORDED"] = "linkque.content.recorded";
|
|
23979
23967
|
})(ETelemetryEventName || (ETelemetryEventName = {}));
|
|
23980
23968
|
var ETelemetryContentSection;
|
|
23981
23969
|
(function(ETelemetryContentSection2) {
|
|
23982
23970
|
ETelemetryContentSection2["QUERY_INPUT"] = "query.input";
|
|
23971
|
+
ETelemetryContentSection2["MODEL_OUTPUT"] = "model.output";
|
|
23972
|
+
ETelemetryContentSection2["MCP_ACTION_OUTPUT"] = "mcp_action.output";
|
|
23983
23973
|
ETelemetryContentSection2["TOOL_INPUT"] = "tool.input";
|
|
23984
23974
|
ETelemetryContentSection2["TOOL_OUTPUT"] = "tool.output";
|
|
23985
23975
|
ETelemetryContentSection2["MCP_REQUESTED_INPUT"] = "mcp.requested_input";
|
|
@@ -24157,6 +24147,20 @@ var ETelemetryVersion;
|
|
|
24157
24147
|
ETelemetryVersion2["V1_0"] = "1.0";
|
|
24158
24148
|
})(ETelemetryVersion || (ETelemetryVersion = {}));
|
|
24159
24149
|
|
|
24150
|
+
// ../linkque-agent-runtime/dist/esm/core/mcpProxyTool.js
|
|
24151
|
+
var MCP_PROXY_DESCRIPTION = [
|
|
24152
|
+
"MCP \u7F51\u5173:\u53D1\u73B0\u5E76\u8C03\u7528 MCP server \u63D0\u4F9B\u7684\u5DE5\u5177\u3002\u53EF\u7528\u52A8\u4F5C:",
|
|
24153
|
+
"- mcp({}) \u6216 mcp({ status: true }):\u67E5\u770B\u6240\u6709 server \u8FDE\u63A5\u72B6\u6001\u4E0E\u5DE5\u5177\u6570\u3002",
|
|
24154
|
+
'- mcp({ connect: "server" }):\u8FDE\u63A5\u5E76\u5237\u65B0\u67D0 server \u7684\u5DE5\u5177\u5217\u8868\u3002',
|
|
24155
|
+
'- mcp({ server: "name" }):\u5217\u51FA\u8BE5 server \u7684\u5DE5\u5177\u3002',
|
|
24156
|
+
'- mcp({ search: "\u5173\u952E\u8BCD" }):\u6309\u540D\u79F0/\u63CF\u8FF0\u6A21\u7CCA\u641C\u7D22\u5DE5\u5177(\u7A7A\u683C\u5206\u8BCD OR)\u3002',
|
|
24157
|
+
'- mcp({ searches: ["\u5173\u952E\u8BCD1", "\u5173\u952E\u8BCD2"] }):\u4E00\u6B21\u6267\u884C\u591A\u7EC4\u641C\u7D22\u5E76\u6309 query \u5206\u7EC4\u8FD4\u56DE(\u6700\u591A 5 \u7EC4)\u3002',
|
|
24158
|
+
'- mcp({ describe: "toolName" }):\u67E5\u770B\u67D0\u5DE5\u5177\u7684\u53C2\u6570 schema\u3002',
|
|
24159
|
+
'- mcp({ tool: "toolName", args: { ... } }):\u8C03\u7528\u67D0\u5DE5\u5177,args \u4E3A\u5BF9\u8C61\u3002',
|
|
24160
|
+
"\u53EF\u7528 server \u540D\u89C1 mcp({}) \u8F93\u51FA\u3002\u4EC5\u5728\u786E\u9700\u8C03\u7528 MCP \u5DE5\u5177\u65F6\u4F7F\u7528\u672C\u5DE5\u5177\u3002",
|
|
24161
|
+
"\u4EC5 mcp({}) \u5217\u51FA\u7684\u5DE5\u5177\u53EF\u8C03\u7528(\u672A\u58F0\u660E\u7684\u5DE5\u5177\u4E0D\u4F1A\u51FA\u73B0)\u3002"
|
|
24162
|
+
].join("\n");
|
|
24163
|
+
|
|
24160
24164
|
// ../linkque-agent-runtime/dist/esm/core/telemetry/telemetryEnums.js
|
|
24161
24165
|
var ETelemetryDiagnosticCode;
|
|
24162
24166
|
(function(ETelemetryDiagnosticCode2) {
|
|
@@ -34515,6 +34519,7 @@ var allowedAttributeKeys = /* @__PURE__ */ new Set([
|
|
|
34515
34519
|
ETelemetryAttribute.GEN_AI_REQUEST_MODEL,
|
|
34516
34520
|
ETelemetryAttribute.GEN_AI_RESPONSE_MODEL,
|
|
34517
34521
|
ETelemetryAttribute.GEN_AI_RESPONSE_ID,
|
|
34522
|
+
ETelemetryAttribute.LINKQUE_CONTENT_VALUE_TRUNCATED,
|
|
34518
34523
|
ETelemetryAttribute.GEN_AI_RESPONSE_FINISH_REASONS,
|
|
34519
34524
|
ETelemetryAttribute.GEN_AI_USAGE_INPUT_TOKENS,
|
|
34520
34525
|
ETelemetryAttribute.GEN_AI_USAGE_OUTPUT_TOKENS,
|
|
@@ -40507,7 +40512,7 @@ var RUNTIME_CAPABILITIES_PATH = ".platform-sdk/runtime-capabilities.json";
|
|
|
40507
40512
|
var LEGACY_RUNTIME_CARD_SCHEMA_VERSIONS = ["2", "3"];
|
|
40508
40513
|
var DRAFT_FILE_MAX_BYTES = 1024 * 1024;
|
|
40509
40514
|
var DRAFT_LIST_LIMIT = 1e3;
|
|
40510
|
-
var AGENT_CONFIG_MAX_BYTES =
|
|
40515
|
+
var AGENT_CONFIG_MAX_BYTES = 16777215;
|
|
40511
40516
|
var FINALIZE_LOCK_PATH = ".linkque/runtime/card-finalize.lock";
|
|
40512
40517
|
var FINALIZE_LOCK_TIMEOUT_MS = 6e4;
|
|
40513
40518
|
var FINALIZE_LOCK_RETRY_MS = 100;
|
|
@@ -40629,8 +40634,12 @@ async function rollbackCardFinalize(cwd, rollbackToken) {
|
|
|
40629
40634
|
}
|
|
40630
40635
|
async function validateCardBindingsFromDisk(cwd, draftId, fieldId) {
|
|
40631
40636
|
const directory = draftDirectory(cwd, draftId);
|
|
40632
|
-
const
|
|
40633
|
-
|
|
40637
|
+
const bundle = await readBundle(directory, draftId);
|
|
40638
|
+
return validateCardBindingsForBundle(cwd, draftId, bundle, fieldId);
|
|
40639
|
+
}
|
|
40640
|
+
async function validateCardBindingsForBundle(cwd, draftId, bundle, fieldId) {
|
|
40641
|
+
const directory = draftDirectory(cwd, draftId);
|
|
40642
|
+
const [contextValue, configValue] = await Promise.all([
|
|
40634
40643
|
readOptionalJson(import_path22.default.join(directory, "binding-context.json")),
|
|
40635
40644
|
readRequiredJson(import_path22.default.join(cwd, AGENT_CONFIG_PATH))
|
|
40636
40645
|
]);
|
|
@@ -40666,15 +40675,15 @@ async function validateCardBindingsFromDisk(cwd, draftId, fieldId) {
|
|
|
40666
40675
|
};
|
|
40667
40676
|
}
|
|
40668
40677
|
async function finalizeCardWhileLocked(cwd, draftId, expectedDraftChecksum) {
|
|
40669
|
-
const
|
|
40678
|
+
const directory = draftDirectory(cwd, draftId);
|
|
40679
|
+
const bundle = await readBundle(directory, draftId);
|
|
40680
|
+
const validation = await validateCardBindingsForBundle(cwd, draftId, bundle);
|
|
40670
40681
|
if (validation.draftChecksum !== expectedDraftChecksum) {
|
|
40671
40682
|
throw new LinkqueCliError(
|
|
40672
40683
|
"CARD_FINALIZE_CONFLICT",
|
|
40673
40684
|
"\u5361\u7247\u8349\u7A3F\u5728\u6821\u9A8C\u540E\u5DF2\u53D8\u5316\uFF0C\u62D2\u7EDD finalize"
|
|
40674
40685
|
);
|
|
40675
40686
|
}
|
|
40676
|
-
const directory = draftDirectory(cwd, draftId);
|
|
40677
|
-
const bundle = await readBundle(directory, draftId);
|
|
40678
40687
|
const runtimeSupportedSchemaVersions = await readRuntimeSupportedSchemaVersions(cwd);
|
|
40679
40688
|
if (!runtimeSupportedSchemaVersions.includes(bundle.manifest.schemaVersion)) {
|
|
40680
40689
|
throw new LinkqueCliError(
|
|
@@ -40700,17 +40709,6 @@ async function finalizeCardWhileLocked(cwd, draftId, expectedDraftChecksum) {
|
|
|
40700
40709
|
const existingIndex = resources.findIndex(
|
|
40701
40710
|
(resource) => resource.resourceType === "CARD" && resource.resourceId === bundle.manifest.resourceId
|
|
40702
40711
|
);
|
|
40703
|
-
const existing = existingIndex >= 0 ? resources[existingIndex] : void 0;
|
|
40704
|
-
const existingRevision = isJsonObject(existing?.config) && typeof existing.config.revision === "string" ? existing.config.revision : void 0;
|
|
40705
|
-
const saved = parseSavedMarker(
|
|
40706
|
-
await readOptionalJson(import_path22.default.join(directory, "saved.json"))
|
|
40707
|
-
);
|
|
40708
|
-
if ((bundle.manifest.baseRevision ?? void 0) !== existingRevision && (saved === void 0 || saved.cardRevision !== existingRevision)) {
|
|
40709
|
-
throw new LinkqueCliError(
|
|
40710
|
-
"CARD_FINALIZE_CONFLICT",
|
|
40711
|
-
"\u5DF2\u4FDD\u5B58\u5361\u7247 revision \u4E0E\u8349\u7A3F baseRevision \u4E0D\u4E00\u81F4"
|
|
40712
|
-
);
|
|
40713
|
-
}
|
|
40714
40712
|
const bindings = bundle.manifest.bindings ?? [];
|
|
40715
40713
|
const cardRevision = createA2UICardRevision(
|
|
40716
40714
|
validation.draftStructureChecksum,
|
|
@@ -42220,6 +42218,15 @@ var decodeLogRecord = (source, record2, byteRange, push) => {
|
|
|
42220
42218
|
const startedAt = nanoToMs(record2.timeUnixNano);
|
|
42221
42219
|
const outcome = strAttr(attributes, ETelemetryAttribute.HARNESS_OPERATION_OUTCOME);
|
|
42222
42220
|
const body = record2.body !== void 0 ? decodeAnyValue(record2.body) : void 0;
|
|
42221
|
+
if (body && typeof body === "object" && "valueJson" in body) {
|
|
42222
|
+
const content = body;
|
|
42223
|
+
try {
|
|
42224
|
+
content.value = JSON.parse(String(content.valueJson));
|
|
42225
|
+
} catch {
|
|
42226
|
+
content.availability = "unavailable";
|
|
42227
|
+
}
|
|
42228
|
+
delete content.valueJson;
|
|
42229
|
+
}
|
|
42223
42230
|
push({
|
|
42224
42231
|
kind: "event",
|
|
42225
42232
|
identity,
|
|
@@ -42242,8 +42249,20 @@ var decodeSpan = (source, span, byteRange, push) => {
|
|
|
42242
42249
|
const finishedAt = nanoToMs(span.endTimeUnixNano);
|
|
42243
42250
|
const statusCode = span.status?.code;
|
|
42244
42251
|
const outcome = strAttr(attributes, ETelemetryAttribute.HARNESS_OPERATION_OUTCOME) ?? (statusCode === 2 ? "error" : statusCode === 1 ? "success" : void 0);
|
|
42252
|
+
const links = [];
|
|
42253
|
+
if (Array.isArray(span.links)) {
|
|
42254
|
+
for (const link3 of span.links) {
|
|
42255
|
+
if (!link3 || typeof link3.traceId !== "string" || typeof link3.spanId !== "string")
|
|
42256
|
+
continue;
|
|
42257
|
+
const attrs = decodeAttributes(link3.attributes);
|
|
42258
|
+
const relation = attrs[ETelemetryAttribute.LINKQUE_LINK_RELATION];
|
|
42259
|
+
if (typeof relation === "string")
|
|
42260
|
+
links.push({ traceId: link3.traceId, spanId: link3.spanId, relation });
|
|
42261
|
+
}
|
|
42262
|
+
}
|
|
42245
42263
|
push({
|
|
42246
42264
|
kind: "span",
|
|
42265
|
+
links,
|
|
42247
42266
|
identity,
|
|
42248
42267
|
name: typeof span.name === "string" ? span.name : void 0,
|
|
42249
42268
|
attributes: Object.freeze(attributes),
|
|
@@ -42330,11 +42349,12 @@ function decodeOtlpLine(line, source, byteRange) {
|
|
|
42330
42349
|
}
|
|
42331
42350
|
|
|
42332
42351
|
// ../linkque-agent-runtime-trace/dist/esm/summarize.js
|
|
42352
|
+
var import_node_crypto2 = require("node:crypto");
|
|
42333
42353
|
var dedupKey = (advanceId, suffix) => `${advanceId ?? ""}
|
|
42334
42354
|
${suffix ?? ""}`;
|
|
42335
42355
|
var extractQueryInput = (facts) => {
|
|
42336
42356
|
for (const fact of facts) {
|
|
42337
|
-
if (fact.name !== ETelemetryEventName.
|
|
42357
|
+
if (fact.name !== ETelemetryEventName.CONTENT_RECORDED)
|
|
42338
42358
|
continue;
|
|
42339
42359
|
const body = fact.body;
|
|
42340
42360
|
if (!body || body.section !== ETelemetryContentSection.QUERY_INPUT)
|
|
@@ -42390,6 +42410,22 @@ var buildOperations = (facts) => {
|
|
|
42390
42410
|
relation: "parent"
|
|
42391
42411
|
});
|
|
42392
42412
|
}
|
|
42413
|
+
const spanOperations = new Map(facts.filter((f3) => f3.kind === "span" && f3.identity.operationId).map((f3) => [`${f3.identity.traceId}:${f3.identity.spanId}`, f3.identity.operationId]));
|
|
42414
|
+
const linkKeys = /* @__PURE__ */ new Set();
|
|
42415
|
+
for (const fact of facts) {
|
|
42416
|
+
if (!fact.identity.operationId)
|
|
42417
|
+
continue;
|
|
42418
|
+
for (const link3 of fact.links ?? []) {
|
|
42419
|
+
const source = spanOperations.get(`${link3.traceId}:${link3.spanId}`);
|
|
42420
|
+
if (!source)
|
|
42421
|
+
continue;
|
|
42422
|
+
const key = `${source}:${fact.identity.operationId}:${link3.relation}`;
|
|
42423
|
+
if (linkKeys.has(key))
|
|
42424
|
+
continue;
|
|
42425
|
+
linkKeys.add(key);
|
|
42426
|
+
relations.push({ fromOperationId: source, toOperationId: fact.identity.operationId, relation: link3.relation });
|
|
42427
|
+
}
|
|
42428
|
+
}
|
|
42393
42429
|
operations.sort((a, b3) => (a.startedAt ?? Infinity) - (b3.startedAt ?? Infinity) || a.operationId.localeCompare(b3.operationId));
|
|
42394
42430
|
return { operations, relations };
|
|
42395
42431
|
};
|
|
@@ -42448,13 +42484,22 @@ var buildUsage = (facts) => {
|
|
|
42448
42484
|
};
|
|
42449
42485
|
var buildContentDescriptors = (facts) => {
|
|
42450
42486
|
const byKey = /* @__PURE__ */ new Map();
|
|
42487
|
+
const replyChunks = /* @__PURE__ */ new Map();
|
|
42451
42488
|
for (const fact of facts) {
|
|
42452
|
-
if (fact.name !== ETelemetryEventName.
|
|
42489
|
+
if (fact.name !== ETelemetryEventName.CONTENT_RECORDED)
|
|
42453
42490
|
continue;
|
|
42454
42491
|
const body = fact.body;
|
|
42455
42492
|
if (!body?.section)
|
|
42456
42493
|
continue;
|
|
42457
42494
|
const { operationId, recordId, advanceId } = fact.identity;
|
|
42495
|
+
if (body.section === "model.output" && typeof body.chunkIndex === "number") {
|
|
42496
|
+
const key = `${advanceId}:${operationId}:model.output`;
|
|
42497
|
+
const chunks = replyChunks.get(key) ?? /* @__PURE__ */ new Map();
|
|
42498
|
+
if (recordId)
|
|
42499
|
+
chunks.set(recordId, fact);
|
|
42500
|
+
replyChunks.set(key, chunks);
|
|
42501
|
+
continue;
|
|
42502
|
+
}
|
|
42458
42503
|
const dedup = `${advanceId ?? ""}
|
|
42459
42504
|
${recordId ?? ""}
|
|
42460
42505
|
${body.section}`;
|
|
@@ -42470,12 +42515,27 @@ ${body.section}`;
|
|
|
42470
42515
|
...operationId ? { operationId } : {},
|
|
42471
42516
|
section: body.section,
|
|
42472
42517
|
contentRef,
|
|
42473
|
-
|
|
42474
|
-
|
|
42518
|
+
valueDigest: (0, import_node_crypto2.createHash)("sha256").update(JSON.stringify(body.value) ?? "").digest("hex"),
|
|
42519
|
+
...body.value && typeof body.value === "object" && (body.section.endsWith(".output") || body.section === "knowledge.input") ? {
|
|
42520
|
+
result: Object.fromEntries(Object.entries(body.value).filter(([key, value]) => ["status", "name", "isError", "action", "server", "knowledgeBaseId"].includes(key) && ["string", "boolean"].includes(typeof value)))
|
|
42475
42521
|
} : {},
|
|
42476
42522
|
availability: body.availability === "available" ? "available" : body.availability === "partial" ? "partial" : body.availability === "unavailable" ? "unavailable" : "not_recorded"
|
|
42477
42523
|
});
|
|
42478
42524
|
}
|
|
42525
|
+
for (const [key, records] of replyChunks) {
|
|
42526
|
+
const chunks = [...records.values()].sort((a, b3) => a.body.chunkIndex - b3.body.chunkIndex);
|
|
42527
|
+
if (!chunks.length)
|
|
42528
|
+
continue;
|
|
42529
|
+
const { advanceId, operationId } = chunks[0].identity;
|
|
42530
|
+
const bodies = chunks.map((chunk) => chunk.body);
|
|
42531
|
+
const complete = bodies.every((body, index) => body.chunkIndex === index) && bodies.at(-1)?.final && bodies.at(-1)?.availability === "available";
|
|
42532
|
+
byKey.set(key, {
|
|
42533
|
+
operationId,
|
|
42534
|
+
section: "model.output",
|
|
42535
|
+
contentRef: { advanceId, operationId, section: "model.output", recordIds: chunks.map((chunk) => chunk.identity.recordId) },
|
|
42536
|
+
availability: complete ? "available" : "partial"
|
|
42537
|
+
});
|
|
42538
|
+
}
|
|
42479
42539
|
return [...byKey.values()];
|
|
42480
42540
|
};
|
|
42481
42541
|
var buildDetailRef = (identity) => Buffer.from(JSON.stringify({
|
|
@@ -42511,6 +42571,7 @@ function summarize(input) {
|
|
|
42511
42571
|
|
|
42512
42572
|
// src/utils/otlpScanner.ts
|
|
42513
42573
|
var import_node_path12 = __toESM(require("node:path"));
|
|
42574
|
+
var import_node_crypto3 = require("node:crypto");
|
|
42514
42575
|
var import_promises20 = require("node:fs/promises");
|
|
42515
42576
|
|
|
42516
42577
|
// src/commands/runs/types.ts
|
|
@@ -42531,7 +42592,9 @@ var parseDetailRef = (ref) => {
|
|
|
42531
42592
|
return void 0;
|
|
42532
42593
|
if (decoded.runId !== void 0 && typeof decoded.runId !== "string")
|
|
42533
42594
|
return void 0;
|
|
42595
|
+
if (decoded.readWindow !== void 0 && (!Array.isArray(decoded.readWindow) || decoded.readWindow.length > 8 || decoded.readWindow.some((entry) => !entry || !["logs", "traces"].includes(entry.source) || !Number.isSafeInteger(entry.bytes) || entry.bytes < 0 || !/^[a-f0-9]{64}$/.test(entry.digest)))) return void 0;
|
|
42534
42596
|
return {
|
|
42597
|
+
readWindow: decoded.readWindow,
|
|
42535
42598
|
advanceId: decoded.advanceId,
|
|
42536
42599
|
threadId: decoded.threadId,
|
|
42537
42600
|
runId: decoded.runId
|
|
@@ -42559,18 +42622,20 @@ var scanFile = (content, source) => {
|
|
|
42559
42622
|
}
|
|
42560
42623
|
return { facts, warnings };
|
|
42561
42624
|
};
|
|
42562
|
-
async function scanRetainedLogs(cwd) {
|
|
42625
|
+
async function scanRetainedLogs(cwd, pinned) {
|
|
42563
42626
|
const dir = import_node_path12.default.join(cwd, LOGS_ROOT);
|
|
42564
42627
|
let files;
|
|
42565
42628
|
try {
|
|
42566
42629
|
files = await (0, import_promises20.readdir)(dir);
|
|
42567
42630
|
} catch (error2) {
|
|
42568
42631
|
if (isNodeError(error2, "ENOENT"))
|
|
42569
|
-
return { facts: [], warnings: ["source_unavailable"] };
|
|
42632
|
+
return { facts: [], warnings: ["source_unavailable"], readWindow: [] };
|
|
42570
42633
|
throw error2;
|
|
42571
42634
|
}
|
|
42572
42635
|
const facts = [];
|
|
42573
42636
|
const warnings = [];
|
|
42637
|
+
const readWindow = [];
|
|
42638
|
+
const remaining = new Set(pinned);
|
|
42574
42639
|
const retainedFiles = /* @__PURE__ */ new Map();
|
|
42575
42640
|
for (const [source, file] of Object.entries(OTLP_LOG_FILES)) {
|
|
42576
42641
|
for (let index = 0; index <= 3; index++) {
|
|
@@ -42583,13 +42648,25 @@ async function scanRetainedLogs(cwd) {
|
|
|
42583
42648
|
const source = retainedFiles.get(file);
|
|
42584
42649
|
const filePath = import_node_path12.default.join(dir, file);
|
|
42585
42650
|
const before = await (0, import_promises20.stat)(filePath);
|
|
42586
|
-
const content = await (0, import_promises20.readFile)(filePath
|
|
42651
|
+
const content = await (0, import_promises20.readFile)(filePath);
|
|
42587
42652
|
const after = await (0, import_promises20.stat)(filePath);
|
|
42588
42653
|
if (before.ino !== after.ino || after.size < before.size) {
|
|
42589
42654
|
warnings.push("log_rotated_during_read");
|
|
42590
42655
|
continue;
|
|
42591
42656
|
}
|
|
42592
|
-
|
|
42657
|
+
let complete = content.subarray(0, content.lastIndexOf(10) + 1);
|
|
42658
|
+
let window;
|
|
42659
|
+
if (pinned) {
|
|
42660
|
+
window = [...remaining].find((entry) => entry.source === source && content.length >= entry.bytes && (0, import_node_crypto3.createHash)("sha256").update(content.subarray(0, entry.bytes)).digest("hex") === entry.digest);
|
|
42661
|
+
if (!window) continue;
|
|
42662
|
+
remaining.delete(window);
|
|
42663
|
+
complete = content.subarray(0, window.bytes);
|
|
42664
|
+
} else {
|
|
42665
|
+
if (complete.length !== content.length) warnings.push("incomplete_tail");
|
|
42666
|
+
window = { source, bytes: complete.length, digest: (0, import_node_crypto3.createHash)("sha256").update(complete).digest("hex") };
|
|
42667
|
+
}
|
|
42668
|
+
readWindow.push(window);
|
|
42669
|
+
const decoded = scanFile(complete.toString("utf8"), source);
|
|
42593
42670
|
for (const fact of decoded.facts) facts.push(fact);
|
|
42594
42671
|
for (const warning of decoded.warnings) warnings.push(warning);
|
|
42595
42672
|
} catch (error2) {
|
|
@@ -42599,11 +42676,12 @@ async function scanRetainedLogs(cwd) {
|
|
|
42599
42676
|
}
|
|
42600
42677
|
if (!selected.some((file) => retainedFiles.get(file) === "logs") || !selected.some((file) => retainedFiles.get(file) === "traces"))
|
|
42601
42678
|
warnings.push("signal_unavailable");
|
|
42602
|
-
|
|
42679
|
+
if (pinned && remaining.size) warnings.push("read_window_expired");
|
|
42680
|
+
return { facts, warnings: [...new Set(warnings)], readWindow };
|
|
42603
42681
|
}
|
|
42604
42682
|
|
|
42605
42683
|
// src/commands/runs/listScanner.ts
|
|
42606
|
-
var isContentRecord = (fact) => fact.name === ETelemetryEventName.
|
|
42684
|
+
var isContentRecord = (fact) => fact.name === ETelemetryEventName.CONTENT_RECORDED;
|
|
42607
42685
|
var decodeContentBody = (fact) => {
|
|
42608
42686
|
const body = fact.body;
|
|
42609
42687
|
return body ?? {};
|
|
@@ -42729,17 +42807,21 @@ ${g2.identity.runId ?? ""}` === latestRun.runKey
|
|
|
42729
42807
|
var scanExecution = async (input) => {
|
|
42730
42808
|
const identity = input.detailRef === void 0 ? void 0 : parseDetailRef(input.detailRef);
|
|
42731
42809
|
if (input.detailRef !== void 0 && !identity) return null;
|
|
42732
|
-
const { facts, warnings } = await scanRetainedLogs(input.cwd);
|
|
42810
|
+
const { facts, warnings, readWindow } = await scanRetainedLogs(input.cwd, identity?.readWindow);
|
|
42811
|
+
if (warnings.includes("read_window_expired")) return null;
|
|
42733
42812
|
if (identity) {
|
|
42734
42813
|
const filtered = facts.filter(
|
|
42735
42814
|
(f3) => (!identity.threadId || f3.identity.threadId === identity.threadId) && (!identity.advanceId || f3.identity.advanceId === identity.advanceId) && (!identity.runId || f3.identity.runId === identity.runId)
|
|
42736
42815
|
);
|
|
42737
42816
|
if (!filtered.length) return null;
|
|
42738
|
-
|
|
42817
|
+
const { readWindow: _window, ...executionIdentity } = identity;
|
|
42818
|
+
const snapshot2 = summarize({ identity: executionIdentity, facts: filtered, observation: { warnings } });
|
|
42819
|
+
return { ...snapshot2, detailRef: input.detailRef };
|
|
42739
42820
|
}
|
|
42740
42821
|
const selected = selectLatestAdvance(facts, input.threadId, input.runId);
|
|
42741
42822
|
if (!selected) return null;
|
|
42742
|
-
|
|
42823
|
+
const snapshot = summarize({ ...selected, observation: { warnings } });
|
|
42824
|
+
return { ...snapshot, detailRef: Buffer.from(JSON.stringify({ ...selected.identity, readWindow })).toString("base64") };
|
|
42743
42825
|
};
|
|
42744
42826
|
|
|
42745
42827
|
// src/commands/runs/contentScanner.ts
|
|
@@ -42772,14 +42854,31 @@ var scanContent = async (input) => {
|
|
|
42772
42854
|
if (value !== void 0 && (typeof value !== "string" || !value))
|
|
42773
42855
|
return null;
|
|
42774
42856
|
}
|
|
42857
|
+
if (contentRef.recordIds !== void 0 && (!Array.isArray(contentRef.recordIds) || !contentRef.recordIds.length || contentRef.recordIds.length > 128 || contentRef.recordIds.some((id) => typeof id !== "string" || !id))) return null;
|
|
42775
42858
|
if (input.cursor !== void 0 && !/^(0|[1-9][0-9]*)$/.test(input.cursor))
|
|
42776
42859
|
return null;
|
|
42777
42860
|
if (input.maxBytes !== void 0 && (!Number.isSafeInteger(input.maxBytes) || input.maxBytes < 1))
|
|
42778
42861
|
return null;
|
|
42779
|
-
const { facts } = await scanRetainedLogs(input.cwd);
|
|
42780
|
-
|
|
42781
|
-
|
|
42862
|
+
const { facts, warnings } = await scanRetainedLogs(input.cwd, identity.readWindow);
|
|
42863
|
+
if (warnings.includes("read_window_expired")) return { availability: "unavailable" };
|
|
42864
|
+
let matched = facts.find(
|
|
42865
|
+
(f3) => f3.name === ETelemetryEventName.CONTENT_RECORDED && (!identity.threadId || f3.identity.threadId === identity.threadId) && (!identity.advanceId || f3.identity.advanceId === identity.advanceId) && (!identity.runId || f3.identity.runId === identity.runId) && matchContentRef(f3, contentRef)
|
|
42782
42866
|
);
|
|
42867
|
+
if (contentRef.recordIds) {
|
|
42868
|
+
const byRecord = new Map(facts.filter((f3) => f3.name === ETelemetryEventName.CONTENT_RECORDED && f3.identity.advanceId === identity.advanceId && (!identity.threadId || f3.identity.threadId === identity.threadId) && (!identity.runId || f3.identity.runId === identity.runId) && f3.identity.operationId === contentRef.operationId).map((f3) => [f3.identity.recordId, f3]));
|
|
42869
|
+
const chunks = contentRef.recordIds.map((id) => byRecord.get(id));
|
|
42870
|
+
if (chunks.some((chunk) => !chunk)) return { availability: "unavailable" };
|
|
42871
|
+
const values = chunks.map((chunk) => chunk.body);
|
|
42872
|
+
if (values.some((value) => value.section !== "model.output" || typeof value.value !== "string")) return null;
|
|
42873
|
+
const prefix = [];
|
|
42874
|
+
for (const value of values) {
|
|
42875
|
+
if (value.chunkIndex !== prefix.length) break;
|
|
42876
|
+
prefix.push(value);
|
|
42877
|
+
}
|
|
42878
|
+
if (!prefix.length) return { availability: "unavailable" };
|
|
42879
|
+
const complete = prefix.length === values.length && prefix.at(-1)?.final && prefix.at(-1)?.availability === "available";
|
|
42880
|
+
matched = { ...chunks[0], body: { value: prefix.map((value) => value.value).join(""), availability: complete ? "available" : "partial" } };
|
|
42881
|
+
}
|
|
42783
42882
|
if (!matched) {
|
|
42784
42883
|
return { availability: "unavailable" };
|
|
42785
42884
|
}
|