@rynfar/meridian 1.45.3 → 1.45.4
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/{cli-yd5cg8mf.js → cli-nb2xe1wm.js} +134 -13
- package/dist/cli.js +1 -1
- package/dist/proxy/adapter.d.ts +1 -1
- package/dist/proxy/adapter.d.ts.map +1 -1
- package/dist/proxy/adapters/claudecode.d.ts +2 -0
- package/dist/proxy/adapters/claudecode.d.ts.map +1 -1
- package/dist/proxy/messages.d.ts +57 -0
- package/dist/proxy/messages.d.ts.map +1 -1
- package/dist/proxy/server.d.ts.map +1 -1
- package/dist/server.js +1 -1
- package/package.json +1 -1
|
@@ -9882,6 +9882,79 @@ function stripNonStandardStreamFields(event) {
|
|
|
9882
9882
|
}
|
|
9883
9883
|
return event;
|
|
9884
9884
|
}
|
|
9885
|
+
var MULTIMODAL_TYPES = new Set(["image", "document", "file"]);
|
|
9886
|
+
function consolidateMultimodalOntoLastUser(structured) {
|
|
9887
|
+
let targetIdx = -1;
|
|
9888
|
+
for (let i = structured.length - 1;i >= 0; i--) {
|
|
9889
|
+
if (Array.isArray(structured[i].message.content)) {
|
|
9890
|
+
targetIdx = i;
|
|
9891
|
+
break;
|
|
9892
|
+
}
|
|
9893
|
+
}
|
|
9894
|
+
if (targetIdx < 0)
|
|
9895
|
+
return structured;
|
|
9896
|
+
const carried = [];
|
|
9897
|
+
const result = structured.map((entry, i) => {
|
|
9898
|
+
const content = entry.message.content;
|
|
9899
|
+
if (i === targetIdx || !Array.isArray(content))
|
|
9900
|
+
return entry;
|
|
9901
|
+
const kept = content.filter((block) => {
|
|
9902
|
+
if (block && typeof block === "object" && MULTIMODAL_TYPES.has(block.type)) {
|
|
9903
|
+
carried.push(block);
|
|
9904
|
+
return false;
|
|
9905
|
+
}
|
|
9906
|
+
return true;
|
|
9907
|
+
});
|
|
9908
|
+
if (kept.length === content.length)
|
|
9909
|
+
return entry;
|
|
9910
|
+
return { ...entry, message: { ...entry.message, content: kept } };
|
|
9911
|
+
});
|
|
9912
|
+
if (carried.length === 0)
|
|
9913
|
+
return structured;
|
|
9914
|
+
const target = result[targetIdx];
|
|
9915
|
+
const existing = target.message.content;
|
|
9916
|
+
const seen = new Set(existing.map((b) => JSON.stringify(b)));
|
|
9917
|
+
const toAppend = carried.filter((b) => {
|
|
9918
|
+
const key = JSON.stringify(b);
|
|
9919
|
+
if (seen.has(key))
|
|
9920
|
+
return false;
|
|
9921
|
+
seen.add(key);
|
|
9922
|
+
return true;
|
|
9923
|
+
});
|
|
9924
|
+
result[targetIdx] = {
|
|
9925
|
+
...target,
|
|
9926
|
+
message: { ...target.message, content: [...existing, ...toAppend] }
|
|
9927
|
+
};
|
|
9928
|
+
return result;
|
|
9929
|
+
}
|
|
9930
|
+
var TOOL_TARGET_KEYS = ["filePath", "file_path", "path", "command", "pattern", "query", "url"];
|
|
9931
|
+
function buildToolUseIndex(messages) {
|
|
9932
|
+
const index = new Map;
|
|
9933
|
+
for (const m of messages) {
|
|
9934
|
+
if (m.role !== "assistant" || !Array.isArray(m.content))
|
|
9935
|
+
continue;
|
|
9936
|
+
for (const block of m.content) {
|
|
9937
|
+
if (block?.type !== "tool_use" || !block.id || typeof block.name !== "string")
|
|
9938
|
+
continue;
|
|
9939
|
+
let target;
|
|
9940
|
+
const input = block.input;
|
|
9941
|
+
if (input && typeof input === "object") {
|
|
9942
|
+
for (const key of TOOL_TARGET_KEYS) {
|
|
9943
|
+
const v = input[key];
|
|
9944
|
+
if (typeof v === "string" && v) {
|
|
9945
|
+
target = v.length > 80 ? v.slice(0, 77) + "..." : v;
|
|
9946
|
+
break;
|
|
9947
|
+
}
|
|
9948
|
+
}
|
|
9949
|
+
}
|
|
9950
|
+
index.set(block.id, { name: block.name, target });
|
|
9951
|
+
}
|
|
9952
|
+
}
|
|
9953
|
+
return index;
|
|
9954
|
+
}
|
|
9955
|
+
function describeToolCall(info) {
|
|
9956
|
+
return info.target ? `[${info.name} ${info.target}]` : `[${info.name}]`;
|
|
9957
|
+
}
|
|
9885
9958
|
|
|
9886
9959
|
// src/proxy/auth.ts
|
|
9887
9960
|
import { createHmac, timingSafeEqual } from "node:crypto";
|
|
@@ -10834,10 +10907,30 @@ function extractClaudeCodeClientCwd(body) {
|
|
|
10834
10907
|
const match2 = systemText.match(/Primary working directory:\s*([^\n<]+)/i);
|
|
10835
10908
|
return match2?.[1]?.trim() || undefined;
|
|
10836
10909
|
}
|
|
10910
|
+
function extractClaudeCodeSessionId(body) {
|
|
10911
|
+
if (!body || typeof body !== "object")
|
|
10912
|
+
return;
|
|
10913
|
+
const metadata = body.metadata;
|
|
10914
|
+
if (!metadata || typeof metadata !== "object")
|
|
10915
|
+
return;
|
|
10916
|
+
const rawUserId = metadata.user_id;
|
|
10917
|
+
let userMetadata = rawUserId;
|
|
10918
|
+
if (typeof rawUserId === "string") {
|
|
10919
|
+
try {
|
|
10920
|
+
userMetadata = JSON.parse(rawUserId);
|
|
10921
|
+
} catch {
|
|
10922
|
+
return;
|
|
10923
|
+
}
|
|
10924
|
+
}
|
|
10925
|
+
if (!userMetadata || typeof userMetadata !== "object")
|
|
10926
|
+
return;
|
|
10927
|
+
const sessionId = userMetadata.session_id;
|
|
10928
|
+
return typeof sessionId === "string" && sessionId.length > 0 ? sessionId : undefined;
|
|
10929
|
+
}
|
|
10837
10930
|
var claudeCodeAdapter = {
|
|
10838
10931
|
name: "claude-code",
|
|
10839
|
-
getSessionId(_c) {
|
|
10840
|
-
return;
|
|
10932
|
+
getSessionId(_c, body) {
|
|
10933
|
+
return extractClaudeCodeSessionId(body);
|
|
10841
10934
|
},
|
|
10842
10935
|
extractWorkingDirectory(_body) {
|
|
10843
10936
|
return;
|
|
@@ -17724,7 +17817,6 @@ async function ensureFreshTokenForProfiles(config) {
|
|
|
17724
17817
|
await ensureFreshToken(store).catch(() => {});
|
|
17725
17818
|
}
|
|
17726
17819
|
}
|
|
17727
|
-
var MULTIMODAL_TYPES = new Set(["image", "document", "file"]);
|
|
17728
17820
|
function hasMultimodalContent(content) {
|
|
17729
17821
|
if (!Array.isArray(content))
|
|
17730
17822
|
return false;
|
|
@@ -17784,7 +17876,7 @@ function flattenAssistantContent(content) {
|
|
|
17784
17876
|
return content.map((b) => b?.type === "text" && b.text ? b.text : "").filter(Boolean).join(`
|
|
17785
17877
|
`);
|
|
17786
17878
|
}
|
|
17787
|
-
function flattenUserContent(content, sanitizeOpts = {}) {
|
|
17879
|
+
function flattenUserContent(content, sanitizeOpts = {}, toolIndex) {
|
|
17788
17880
|
if (typeof content === "string")
|
|
17789
17881
|
return sanitizeTextContent(content, sanitizeOpts);
|
|
17790
17882
|
if (!Array.isArray(content))
|
|
@@ -17793,14 +17885,20 @@ function flattenUserContent(content, sanitizeOpts = {}) {
|
|
|
17793
17885
|
if (b?.type === "text" && b.text)
|
|
17794
17886
|
return sanitizeTextContent(b.text, sanitizeOpts);
|
|
17795
17887
|
if (b?.type === "tool_result") {
|
|
17888
|
+
const info = toolIndex?.get(b.tool_use_id);
|
|
17889
|
+
const label = info ? describeToolCall(info) : undefined;
|
|
17796
17890
|
const inner = b.content;
|
|
17891
|
+
let flat = "";
|
|
17797
17892
|
if (typeof inner === "string")
|
|
17798
|
-
|
|
17799
|
-
if (Array.isArray(inner)) {
|
|
17800
|
-
|
|
17893
|
+
flat = inner;
|
|
17894
|
+
else if (Array.isArray(inner)) {
|
|
17895
|
+
flat = inner.map((ib) => ib?.type === "text" && ib.text ? ib.text : "").filter(Boolean).join(`
|
|
17801
17896
|
`);
|
|
17802
17897
|
}
|
|
17803
|
-
|
|
17898
|
+
if (label)
|
|
17899
|
+
return flat ? `${label}:
|
|
17900
|
+
${flat}` : label;
|
|
17901
|
+
return flat;
|
|
17804
17902
|
}
|
|
17805
17903
|
if (b?.type === "image")
|
|
17806
17904
|
return "[Image attached]";
|
|
@@ -17814,6 +17912,7 @@ function flattenUserContent(content, sanitizeOpts = {}) {
|
|
|
17814
17912
|
}
|
|
17815
17913
|
function buildFreshPrompt(messages, sanitizeOpts = {}) {
|
|
17816
17914
|
const hasMultimodal = messages.some((m) => hasMultimodalContent(m.content));
|
|
17915
|
+
const toolIndex = buildToolUseIndex(messages);
|
|
17817
17916
|
if (hasMultimodal) {
|
|
17818
17917
|
const structured = [];
|
|
17819
17918
|
for (const m of messages) {
|
|
@@ -17834,14 +17933,15 @@ function buildFreshPrompt(messages, sanitizeOpts = {}) {
|
|
|
17834
17933
|
}
|
|
17835
17934
|
}
|
|
17836
17935
|
}
|
|
17936
|
+
const prompt = structured.length > 1 ? consolidateMultimodalOntoLastUser(structured) : structured;
|
|
17837
17937
|
return async function* () {
|
|
17838
|
-
for (const msg of
|
|
17938
|
+
for (const msg of prompt)
|
|
17839
17939
|
yield msg;
|
|
17840
17940
|
}();
|
|
17841
17941
|
}
|
|
17842
17942
|
return messages.map((m) => {
|
|
17843
17943
|
const role = m.role === "assistant" ? "Assistant" : "Human";
|
|
17844
|
-
const content = m.role === "assistant" ? flattenAssistantContent(m.content) : flattenUserContent(m.content, sanitizeOpts);
|
|
17944
|
+
const content = m.role === "assistant" ? flattenAssistantContent(m.content) : flattenUserContent(m.content, sanitizeOpts, toolIndex);
|
|
17845
17945
|
return content ? `${role}: ${content}` : "";
|
|
17846
17946
|
}).filter(Boolean).join(`
|
|
17847
17947
|
|
|
@@ -18079,12 +18179,12 @@ function createProxyServer(config = {}) {
|
|
|
18079
18179
|
const parsedBudget = taskBudgetHeader ? Number.parseInt(taskBudgetHeader, 10) : NaN;
|
|
18080
18180
|
const taskBudget = Number.isFinite(parsedBudget) ? { total: parsedBudget } : body.task_budget ? { total: body.task_budget.total ?? body.task_budget } : undefined;
|
|
18081
18181
|
const betas = betaFilter.forwarded;
|
|
18082
|
-
const agentSessionId = adapter.getSessionId(c);
|
|
18182
|
+
const agentSessionId = adapter.getSessionId(c, body);
|
|
18083
18183
|
const profileSessionId = profile.id !== "default" && agentSessionId ? `${profile.id}:${agentSessionId}` : agentSessionId;
|
|
18084
18184
|
const profileScopedCwd = profile.id !== "default" ? `${clientWorkingDirectory}::profile=${profile.id}` : clientWorkingDirectory;
|
|
18085
18185
|
const lastMessage = Array.isArray(body.messages) ? body.messages[body.messages.length - 1] : undefined;
|
|
18086
18186
|
const lastIsToolResult = Array.isArray(lastMessage?.content) && lastMessage.content.some((b) => b?.type === "tool_result");
|
|
18087
|
-
const isClientDrivenLoop = !agentSessionId && lastIsToolResult;
|
|
18187
|
+
const isClientDrivenLoop = adapter.name !== "claude-code" && !agentSessionId && lastIsToolResult;
|
|
18088
18188
|
const isIndependentSession = requestSource?.startsWith("fork-") || requestSource?.startsWith("subagent-") || isClientDrivenLoop || false;
|
|
18089
18189
|
let lineageResult = isIndependentSession ? { type: "diverged" } : lookupSession(profileSessionId, body.messages || [], profileScopedCwd);
|
|
18090
18190
|
if (lineageResult.type === "undo" && adapter.name === "opencode" && !agentSessionId) {
|
|
@@ -18183,10 +18283,14 @@ function createProxyServer(config = {}) {
|
|
|
18183
18283
|
}
|
|
18184
18284
|
}
|
|
18185
18285
|
}
|
|
18286
|
+
if (structuredMessages.length > 1) {
|
|
18287
|
+
structuredMessages = consolidateMultimodalOntoLastUser(structuredMessages);
|
|
18288
|
+
}
|
|
18186
18289
|
} else {
|
|
18290
|
+
const toolIndex = buildToolUseIndex(allMessages ?? messagesToConvert ?? []);
|
|
18187
18291
|
textPrompt = messagesToConvert?.map((m) => {
|
|
18188
18292
|
const role = m.role === "assistant" ? "Assistant" : "Human";
|
|
18189
|
-
const content = m.role === "assistant" ? flattenAssistantContent(m.content) : flattenUserContent(m.content, sanitizeOpts);
|
|
18293
|
+
const content = m.role === "assistant" ? flattenAssistantContent(m.content) : flattenUserContent(m.content, sanitizeOpts, toolIndex);
|
|
18190
18294
|
return content ? `${role}: ${content}` : "";
|
|
18191
18295
|
}).filter(Boolean).join(`
|
|
18192
18296
|
|
|
@@ -18823,6 +18927,7 @@ Subprocess stderr: ${stderrOutput}`;
|
|
|
18823
18927
|
let hasStructuredOutput = false;
|
|
18824
18928
|
let structuredOutput;
|
|
18825
18929
|
const streamedToolUseIds = new Set;
|
|
18930
|
+
const openClientBlocks = new Set;
|
|
18826
18931
|
try {
|
|
18827
18932
|
let currentSessionId;
|
|
18828
18933
|
const MAX_RATE_LIMIT_RETRIES = 2;
|
|
@@ -19247,6 +19352,15 @@ data: ${JSON.stringify(event)}
|
|
|
19247
19352
|
break;
|
|
19248
19353
|
}
|
|
19249
19354
|
eventsForwarded += 1;
|
|
19355
|
+
if (eventType === "content_block_start") {
|
|
19356
|
+
const idx = event.index;
|
|
19357
|
+
if (typeof idx === "number")
|
|
19358
|
+
openClientBlocks.add(idx);
|
|
19359
|
+
} else if (eventType === "content_block_stop") {
|
|
19360
|
+
const idx = event.index;
|
|
19361
|
+
if (typeof idx === "number")
|
|
19362
|
+
openClientBlocks.delete(idx);
|
|
19363
|
+
}
|
|
19250
19364
|
if (passthrough && eventType === "message_delta" && event.delta?.stop_reason === "tool_use" && streamedToolUseIds.size > 0) {
|
|
19251
19365
|
safeEnqueue(encoder.encode(`event: message_stop
|
|
19252
19366
|
data: ${JSON.stringify({ type: "message_stop" })}
|
|
@@ -19534,6 +19648,13 @@ Subprocess stderr: ${stderrOutput}`;
|
|
|
19534
19648
|
hasDeferredTools,
|
|
19535
19649
|
sdkSessionId: resumeSessionId
|
|
19536
19650
|
})} captured=${capturedToolUses.length}`, requestMeta.requestId);
|
|
19651
|
+
for (const idx of openClientBlocks) {
|
|
19652
|
+
safeEnqueue(encoder.encode(`event: content_block_stop
|
|
19653
|
+
data: ${JSON.stringify({ type: "content_block_stop", index: idx })}
|
|
19654
|
+
|
|
19655
|
+
`), "recover_close_dangling_block");
|
|
19656
|
+
}
|
|
19657
|
+
openClientBlocks.clear();
|
|
19537
19658
|
const unseenToolUses = capturedToolUses.filter((tu) => !streamedToolUseIds.has(tu.id));
|
|
19538
19659
|
for (let i = 0;i < unseenToolUses.length; i++) {
|
|
19539
19660
|
const tu = unseenToolUses[i];
|
package/dist/cli.js
CHANGED
package/dist/proxy/adapter.d.ts
CHANGED
|
@@ -18,7 +18,7 @@ export interface AgentIdentity {
|
|
|
18
18
|
* Extract a session ID from the request.
|
|
19
19
|
* Returns undefined if the agent doesn't provide session tracking.
|
|
20
20
|
*/
|
|
21
|
-
getSessionId(c: Context): string | undefined;
|
|
21
|
+
getSessionId(c: Context, body?: unknown): string | undefined;
|
|
22
22
|
/**
|
|
23
23
|
* Extract the SDK subprocess working directory from the request body.
|
|
24
24
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../../src/proxy/adapter.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAA;AACnC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAA;AAEnE;;;;GAIG;AACH,MAAM,WAAW,aAAa;IAC5B,4DAA4D;IAC5D,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IAErB;;;OAGG;IACH,YAAY,CAAC,CAAC,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../../src/proxy/adapter.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAA;AACnC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAA;AAEnE;;;;GAIG;AACH,MAAM,WAAW,aAAa;IAC5B,4DAA4D;IAC5D,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IAErB;;;OAGG;IACH,YAAY,CAAC,CAAC,EAAE,OAAO,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAAA;IAE5D;;;;;;;;;;;;;;;;OAgBG;IACH,uBAAuB,CAAC,IAAI,EAAE,GAAG,GAAG,MAAM,GAAG,SA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C,IAAI,OAAO,CAAA;IAElC;;;;;;;;OAQG;IACH,yBAAyB,CAAC,IAAI,OAAO,CAAA;IAErC;;;;;;;;;;;;;;;OAeG;IACH,6BAA6B,CAAC,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,GAAG,OAAO,eAAe,EAAE,UAAU,EAAE,CAAA;CAC3G"}
|
|
@@ -17,5 +17,7 @@
|
|
|
17
17
|
* fingerprinting and a system-prompt hint (see server.ts + query.ts).
|
|
18
18
|
*/
|
|
19
19
|
import type { AgentAdapter } from "../adapter";
|
|
20
|
+
/** Extract the stable conversation ID embedded by Claude Code in metadata.user_id. */
|
|
21
|
+
export declare function extractClaudeCodeSessionId(body: unknown): string | undefined;
|
|
20
22
|
export declare const claudeCodeAdapter: AgentAdapter;
|
|
21
23
|
//# sourceMappingURL=claudecode.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"claudecode.d.ts","sourceRoot":"","sources":["../../../src/proxy/adapters/claudecode.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAGH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAiC9C,eAAO,MAAM,iBAAiB,EAAE,YA0F/B,CAAA"}
|
|
1
|
+
{"version":3,"file":"claudecode.d.ts","sourceRoot":"","sources":["../../../src/proxy/adapters/claudecode.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAGH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAiC9C,sFAAsF;AACtF,wBAAgB,0BAA0B,CAAC,IAAI,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAoB5E;AAED,eAAO,MAAM,iBAAiB,EAAE,YA0F/B,CAAA"}
|
package/dist/proxy/messages.d.ts
CHANGED
|
@@ -47,4 +47,61 @@ export declare function getLastUserMessage(messages: Array<{
|
|
|
47
47
|
* path; a no-op when the field is absent, so it is safe to call on every event.
|
|
48
48
|
*/
|
|
49
49
|
export declare function stripNonStandardStreamFields<T>(event: T): T;
|
|
50
|
+
/** Content block types that carry non-text data the model must "see". */
|
|
51
|
+
export declare const MULTIMODAL_TYPES: Set<string>;
|
|
52
|
+
/**
|
|
53
|
+
* Consolidate multimodal blocks (image/document/file) from earlier user turns
|
|
54
|
+
* onto the final user turn of a structured (AsyncIterable) prompt.
|
|
55
|
+
*
|
|
56
|
+
* When the Claude Agent SDK is handed multiple user messages as a streaming
|
|
57
|
+
* iterable, it only surfaces multimodal blocks from the LAST user turn to the
|
|
58
|
+
* model — images sitting in earlier turns (e.g. an image a `read` tool returned
|
|
59
|
+
* mid-conversation) are silently dropped, and the model answers "I cannot see
|
|
60
|
+
* the image" (#553). Moving those blocks onto the final array-content user turn
|
|
61
|
+
* makes them visible; accompanying text is left in place.
|
|
62
|
+
*
|
|
63
|
+
* Notes:
|
|
64
|
+
* - The target is the last entry whose `message.content` is an ARRAY. Flattened
|
|
65
|
+
* assistant turns are string content and can never hold image blocks, so a
|
|
66
|
+
* conversation ending on an assistant turn still lands images on the last
|
|
67
|
+
* real user turn.
|
|
68
|
+
* - Blocks structurally identical to ones already on the target are not
|
|
69
|
+
* re-appended (avoids duplicating a client-re-attached image).
|
|
70
|
+
*
|
|
71
|
+
* Pure: returns a new array; the input and its messages are not mutated. No-op
|
|
72
|
+
* when there are fewer than two array-content user turns or nothing to carry.
|
|
73
|
+
*/
|
|
74
|
+
export declare function consolidateMultimodalOntoLastUser<T extends {
|
|
75
|
+
message: {
|
|
76
|
+
content: unknown;
|
|
77
|
+
};
|
|
78
|
+
}>(structured: T[]): T[];
|
|
79
|
+
/** A tool call the assistant made earlier in the conversation. */
|
|
80
|
+
export interface ToolCallInfo {
|
|
81
|
+
name: string;
|
|
82
|
+
/** Compact human-readable target (file path, command, pattern...), if any. */
|
|
83
|
+
target: string | undefined;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Index every assistant tool_use block in a conversation by id.
|
|
87
|
+
*
|
|
88
|
+
* Used to attribute tool_result blocks during full-history replay: the
|
|
89
|
+
* flattened replay drops assistant tool_use blocks (issues #111/#386 — verbose
|
|
90
|
+
* `[Tool Use: ...]` strings taught the model to imitate fake tool syntax), so
|
|
91
|
+
* without attribution the model sees raw tool outputs as bare user text with
|
|
92
|
+
* no cause — it then denies having made the calls at all ("a file I never
|
|
93
|
+
* created", #552).
|
|
94
|
+
*/
|
|
95
|
+
export declare function buildToolUseIndex(messages: Array<{
|
|
96
|
+
role: string;
|
|
97
|
+
content: any;
|
|
98
|
+
}>): Map<string, ToolCallInfo>;
|
|
99
|
+
/**
|
|
100
|
+
* Render a compact attribution label for a replayed tool result, e.g.
|
|
101
|
+
* `[write tmp/test2.txt]` or `[bash echo hi]`. Deliberately terse and
|
|
102
|
+
* bracket-formatted differently from the banned `[Tool Use: ...]` /
|
|
103
|
+
* `[Tool Result ...]` shapes (#111/#386) so the model reads it as context,
|
|
104
|
+
* not as tool-call syntax to imitate.
|
|
105
|
+
*/
|
|
106
|
+
export declare function describeToolCall(info: ToolCallInfo): string;
|
|
50
107
|
//# sourceMappingURL=messages.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../../src/proxy/messages.ts"],"names":[],"mappings":"AAAA;;GAEG;AAcH;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,GAAG,GAAG,MAAM,CAiBrD;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAUtE;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,OAAO,EAAE,GAAG,OAAO,EAAE,CAM7D;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,KAAK,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,GAAG,CAAA;CAAE,CAAC,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8EAA8E;IAC9E,MAAM,EAAE,MAAM,GAAG,SAAS,CAAA;CAC3B;AAKD;;;;;;;;;GASG;AACH,wBAAgB,iBAAiB,CAC/B,QAAQ,EAAE,KAAK,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,GAAG,CAAA;CAAE,CAAC,GAC9C,GAAG,CAAC,MAAM,EAAE,YAAY,CAAC,CAqB3B;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,YAAY,GAAG,MAAM,CAE3D"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/proxy/server.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AACtE,YAAY,EAAE,WAAW,EAAE,aAAa,EAAE,WAAW,EAAE,CAAA;AAGvD,YAAY,EACV,SAAS,EACT,cAAc,EACd,eAAe,EACf,gBAAgB,EAChB,cAAc,EACd,cAAc,EACd,iBAAiB,EACjB,YAAY,EACZ,aAAa,EACb,WAAW,GACZ,MAAM,aAAa,CAAA;AAKpB,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAA;AAkCnG,OAAO,EACL,kBAAkB,EAClB,WAAW,EACX,oBAAoB,EAEpB,KAAK,aAAa,EAGnB,MAAM,mBAAmB,CAAA;AAG1B,OAAO,EAA+B,iBAAiB,EAAE,mBAAmB,EAAsC,MAAM,iBAAiB,CAAA;AAGzI,OAAO,EAAE,kBAAkB,EAAE,WAAW,EAAE,oBAAoB,EAAE,CAAA;AAChE,OAAO,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,CAAA;AACjD,YAAY,EAAE,aAAa,EAAE,CAAA;
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/proxy/server.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AACtE,YAAY,EAAE,WAAW,EAAE,aAAa,EAAE,WAAW,EAAE,CAAA;AAGvD,YAAY,EACV,SAAS,EACT,cAAc,EACd,eAAe,EACf,gBAAgB,EAChB,cAAc,EACd,cAAc,EACd,iBAAiB,EACjB,YAAY,EACZ,aAAa,EACb,WAAW,GACZ,MAAM,aAAa,CAAA;AAKpB,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAA;AAkCnG,OAAO,EACL,kBAAkB,EAClB,WAAW,EACX,oBAAoB,EAEpB,KAAK,aAAa,EAGnB,MAAM,mBAAmB,CAAA;AAG1B,OAAO,EAA+B,iBAAiB,EAAE,mBAAmB,EAAsC,MAAM,iBAAiB,CAAA;AAGzI,OAAO,EAAE,kBAAkB,EAAE,WAAW,EAAE,oBAAoB,EAAE,CAAA;AAChE,OAAO,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,CAAA;AACjD,YAAY,EAAE,aAAa,EAAE,CAAA;AA2Q7B,wBAAgB,iBAAiB,CAAC,MAAM,GAAE,OAAO,CAAC,WAAW,CAAM,GAAG,WAAW,CA6hGhF;AAWD,wBAAgB,gCAAgC,IAAI,IAAI,CAavD;AAED,wBAAsB,gBAAgB,CAAC,MAAM,GAAE,OAAO,CAAC,WAAW,CAAM,GAAG,OAAO,CAAC,aAAa,CAAC,CAmGhG"}
|
package/dist/server.js
CHANGED
package/package.json
CHANGED