@koda-sl/baker-bridge 0.191.0-dev.9e99fc957 → 0.192.0-dev.8d6f5633e
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/README.md +2 -2
- package/dist/broker/baker-api.d.ts +7 -0
- package/dist/broker/baker-api.d.ts.map +1 -1
- package/dist/broker/baker-api.js +6 -1
- package/dist/broker/baker-api.js.map +1 -1
- package/dist/broker/credential-text.d.ts +2 -0
- package/dist/broker/credential-text.d.ts.map +1 -1
- package/dist/broker/credential-text.js.map +1 -1
- package/dist/broker/proxy.d.ts.map +1 -1
- package/dist/broker/proxy.integration.test.js +57 -2
- package/dist/broker/proxy.integration.test.js.map +1 -1
- package/dist/broker/proxy.js +97 -6
- package/dist/broker/proxy.js.map +1 -1
- package/dist/broker/usage-reporter.d.ts +9 -5
- package/dist/broker/usage-reporter.d.ts.map +1 -1
- package/dist/broker/usage-reporter.js +20 -4
- package/dist/broker/usage-reporter.js.map +1 -1
- package/dist/broker/usage-reporter.test.js +42 -3
- package/dist/broker/usage-reporter.test.js.map +1 -1
- package/dist/hono/bridge-job.d.ts.map +1 -1
- package/dist/hono/bridge-job.js +12 -4
- package/dist/hono/bridge-job.js.map +1 -1
- package/dist/hono/bridge-job.test.js +60 -186
- package/dist/hono/bridge-job.test.js.map +1 -1
- package/dist/hono/connection-input.d.ts.map +1 -1
- package/dist/hono/connection-input.js +6 -5
- package/dist/hono/connection-input.js.map +1 -1
- package/dist/hono/credential-scrub.d.ts +1 -6
- package/dist/hono/credential-scrub.d.ts.map +1 -1
- package/dist/hono/credential-scrub.js +13 -18
- package/dist/hono/credential-scrub.js.map +1 -1
- package/dist/hono/credential-scrub.test.js +0 -8
- package/dist/hono/credential-scrub.test.js.map +1 -1
- package/dist/hono/progress-note.d.ts +6 -0
- package/dist/hono/progress-note.d.ts.map +1 -0
- package/dist/hono/progress-note.js +25 -0
- package/dist/hono/progress-note.js.map +1 -0
- package/dist/hono/skill-language.d.ts +4 -3
- package/dist/hono/skill-language.d.ts.map +1 -1
- package/dist/hono/skill-language.js +14 -5
- package/dist/hono/skill-language.js.map +1 -1
- package/package.json +1 -1
- package/dist/hono/tool-result-budget.d.ts +0 -7
- package/dist/hono/tool-result-budget.d.ts.map +0 -1
- package/dist/hono/tool-result-budget.js +0 -180
- package/dist/hono/tool-result-budget.js.map +0 -1
|
@@ -510,6 +510,49 @@ describe("BridgeJobExecutor", () => {
|
|
|
510
510
|
},
|
|
511
511
|
]);
|
|
512
512
|
});
|
|
513
|
+
it("previews a progress note streamed as thinking, and not the empty reasoning", async () => {
|
|
514
|
+
const previewed = [];
|
|
515
|
+
const relay = { ...recordingRelay(), previewText: (_target, delta) => previewed.push(delta) };
|
|
516
|
+
const executor = createExecutor({
|
|
517
|
+
relay,
|
|
518
|
+
model: "claude-opus-5-5",
|
|
519
|
+
queryResults: [
|
|
520
|
+
scriptedMessages({ type: "stream_event", event: { type: "message_start" } }, {
|
|
521
|
+
type: "stream_event",
|
|
522
|
+
event: { type: "content_block_delta", index: 0, delta: { type: "thinking_delta", thinking: "" } },
|
|
523
|
+
}, {
|
|
524
|
+
type: "stream_event",
|
|
525
|
+
event: {
|
|
526
|
+
type: "content_block_delta",
|
|
527
|
+
index: 1,
|
|
528
|
+
delta: { type: "thinking_delta", thinking: "Found the campaign; checking its budget next." },
|
|
529
|
+
},
|
|
530
|
+
}, resultMessage(0, "session_next")),
|
|
531
|
+
],
|
|
532
|
+
});
|
|
533
|
+
await executor.execute({ threadId: "thread_1", turnId: "turn_1", prompt: "Check it" }, activeControls());
|
|
534
|
+
expect(previewed).toEqual(["Found the campaign; checking its budget next."]);
|
|
535
|
+
});
|
|
536
|
+
it("previews no thinking from a model whose thinking is reasoning, not a note", async () => {
|
|
537
|
+
const previewed = [];
|
|
538
|
+
const relay = { ...recordingRelay(), previewText: (_target, delta) => previewed.push(delta) };
|
|
539
|
+
const executor = createExecutor({
|
|
540
|
+
relay,
|
|
541
|
+
model: "claude-haiku-5-5",
|
|
542
|
+
queryResults: [
|
|
543
|
+
scriptedMessages({ type: "stream_event", event: { type: "message_start" } }, {
|
|
544
|
+
type: "stream_event",
|
|
545
|
+
event: {
|
|
546
|
+
type: "content_block_delta",
|
|
547
|
+
index: 0,
|
|
548
|
+
delta: { type: "thinking_delta", thinking: "The user wants the budget, so first I should look up" },
|
|
549
|
+
},
|
|
550
|
+
}, resultMessage(0, "session_next")),
|
|
551
|
+
],
|
|
552
|
+
});
|
|
553
|
+
await executor.execute({ threadId: "thread_1", turnId: "turn_1", prompt: "Check it" }, activeControls());
|
|
554
|
+
expect(previewed).toEqual([]);
|
|
555
|
+
});
|
|
513
556
|
it("previews a step with the input it streamed, not the empty one it opened with", async () => {
|
|
514
557
|
const relay = recordingRelay();
|
|
515
558
|
const executor = createExecutor({
|
|
@@ -5500,6 +5543,23 @@ describe("BridgeJobExecutor review mode", () => {
|
|
|
5500
5543
|
const options = await spanishTurnAfter(apiErrorMessage("a1", "API Error: Server error mid-response. The response above may be incomplete.", "server_error"), assistantMessage("a2", "Ahora reviso el banner de las cuatro landings de verano."));
|
|
5501
5544
|
expect(await contextAfterTool(options, "Read")).toBeUndefined();
|
|
5502
5545
|
});
|
|
5546
|
+
it("names the drift in a progress note Opus 5.5 returned as a thinking block", async () => {
|
|
5547
|
+
const options = await spanishTurnAfter({
|
|
5548
|
+
type: "assistant",
|
|
5549
|
+
uuid: "a1",
|
|
5550
|
+
parent_tool_use_id: null,
|
|
5551
|
+
message: {
|
|
5552
|
+
role: "assistant",
|
|
5553
|
+
model: "claude-opus-5-5",
|
|
5554
|
+
content: [
|
|
5555
|
+
{ type: "thinking", thinking: "", signature: "AAAA" },
|
|
5556
|
+
{ type: "thinking", thinking: "Found the campaign, now checking its budget.", signature: "BBBB" },
|
|
5557
|
+
],
|
|
5558
|
+
stop_reason: "tool_use",
|
|
5559
|
+
},
|
|
5560
|
+
});
|
|
5561
|
+
expect(await contextAfterTool(options, "Read")).toContain("Your last line to the user was not in Spanish.");
|
|
5562
|
+
});
|
|
5503
5563
|
it("names the drift to the main thread, not to a subagent's own tool call", async () => {
|
|
5504
5564
|
const options = await spanishTurnAfter(assistantMessage("a1", "Now the definition, then a live test."));
|
|
5505
5565
|
expect(await contextAfterTool(options, "Read", { agent_id: "agent_1" })).toBeUndefined();
|
|
@@ -5885,190 +5945,4 @@ describe("agentFeature", () => {
|
|
|
5885
5945
|
expect(agentFeature({})).toBe("agent.turn");
|
|
5886
5946
|
});
|
|
5887
5947
|
});
|
|
5888
|
-
describe("BridgeJobExecutor connected-app results", () => {
|
|
5889
|
-
/** What the model reads after `toolName` returns `response`: the last rewrite any PostToolUse hook made, as the SDK keeps it. */
|
|
5890
|
-
async function toolOutputTheModelReads(toolName, response, caller = {}, job = {}) {
|
|
5891
|
-
const queryInputs = [];
|
|
5892
|
-
const executor = createExecutor({ queryInputs });
|
|
5893
|
-
await executor.execute({ threadId: "t", turnId: "turn_1", prompt: "Read the thread", ...job }, activeControls());
|
|
5894
|
-
const options = queryInputs[0]?.options;
|
|
5895
|
-
if (!options)
|
|
5896
|
-
throw new Error("expected the turn to start one query");
|
|
5897
|
-
const toolUseId = `toolu_${Math.random().toString(36).slice(2)}`;
|
|
5898
|
-
const input = {
|
|
5899
|
-
hook_event_name: "PostToolUse",
|
|
5900
|
-
tool_name: toolName,
|
|
5901
|
-
tool_input: {},
|
|
5902
|
-
tool_response: response,
|
|
5903
|
-
tool_use_id: toolUseId,
|
|
5904
|
-
session_id: "s",
|
|
5905
|
-
transcript_path: "",
|
|
5906
|
-
cwd: "/",
|
|
5907
|
-
...caller,
|
|
5908
|
-
};
|
|
5909
|
-
const hooks = (options.hooks?.PostToolUse ?? [])
|
|
5910
|
-
.filter((matcher) => matcher.matcher === undefined || new RegExp(`^(?:${matcher.matcher})$`).test(toolName))
|
|
5911
|
-
.flatMap((matcher) => matcher.hooks);
|
|
5912
|
-
let output = response;
|
|
5913
|
-
for (const hook of hooks) {
|
|
5914
|
-
const result = await hook(input, toolUseId, { signal: new AbortController().signal });
|
|
5915
|
-
const specific = "hookSpecificOutput" in result ? result.hookSpecificOutput : undefined;
|
|
5916
|
-
if (specific?.hookEventName === "PostToolUse" && specific.updatedToolOutput !== undefined) {
|
|
5917
|
-
output = specific.updatedToolOutput;
|
|
5918
|
-
}
|
|
5919
|
-
}
|
|
5920
|
-
return output;
|
|
5921
|
-
}
|
|
5922
|
-
function textTheModelReads(output) {
|
|
5923
|
-
return Array.isArray(output) ? output.map((block) => block.text ?? "").join("") : "";
|
|
5924
|
-
}
|
|
5925
|
-
/** The file the shortened answer points the agent to. */
|
|
5926
|
-
function savedAnswer(text) {
|
|
5927
|
-
const path = /\/\S+\.json/.exec(text)?.[0];
|
|
5928
|
-
if (!path)
|
|
5929
|
-
throw new Error(`expected the answer to name the file it was saved to: ${text.slice(0, 300)}`);
|
|
5930
|
-
return readFileSync(path, "utf8");
|
|
5931
|
-
}
|
|
5932
|
-
const searchResponse = () => JSON.parse(readFileSync(new URL("./composio-search-tools.test.json", import.meta.url), "utf8"));
|
|
5933
|
-
// BAKER-1855: one Slack tool search answered 17 KB of plans, pitfalls and schemas.
|
|
5934
|
-
it("hands the agent a connected app's tool search as an outline under 2 KB, the whole answer saved for it to read", async () => {
|
|
5935
|
-
const response = searchResponse();
|
|
5936
|
-
const output = await toolOutputTheModelReads("mcp__composio_company__COMPOSIO_SEARCH_TOOLS", response);
|
|
5937
|
-
const text = textTheModelReads(output);
|
|
5938
|
-
expect(Buffer.byteLength(text)).toBeLessThanOrEqual(2048);
|
|
5939
|
-
for (const slug of ["SLACK_FETCH_MESSAGE_THREAD_FROM_A_CONVERSATION", "SLACK_SEARCH_MESSAGES"]) {
|
|
5940
|
-
expect(text).toContain(slug);
|
|
5941
|
-
}
|
|
5942
|
-
expect(savedAnswer(text)).toBe(response[0]?.text);
|
|
5943
|
-
});
|
|
5944
|
-
it.each([
|
|
5945
|
-
["a chat turn", {}],
|
|
5946
|
-
["a scheduled agent's run", { unattended: true }],
|
|
5947
|
-
["a Session review", { review: { threadIds: [], chatFacts: { chatId: "chat_1" } } }],
|
|
5948
|
-
[
|
|
5949
|
-
"a task",
|
|
5950
|
-
{ unattended: true, builder: { runId: "run_1", title: "Summer landing", outputSchema: { type: "object" } } },
|
|
5951
|
-
],
|
|
5952
|
-
])("shortens a connected app's tool search in %s", async (_mode, job) => {
|
|
5953
|
-
const output = await toolOutputTheModelReads("mcp__composio_company__COMPOSIO_SEARCH_TOOLS", searchResponse(), {}, job);
|
|
5954
|
-
const text = textTheModelReads(output);
|
|
5955
|
-
expect(Buffer.byteLength(text)).toBeLessThanOrEqual(2048);
|
|
5956
|
-
expect(text).toContain("SLACK_FETCH_MESSAGE_THREAD_FROM_A_CONVERSATION");
|
|
5957
|
-
});
|
|
5958
|
-
it("shortens a connected app's tool search a subagent ran, as it does the Session's own", async () => {
|
|
5959
|
-
const output = await toolOutputTheModelReads("mcp__composio_company__COMPOSIO_SEARCH_TOOLS", searchResponse(), {
|
|
5960
|
-
agent_id: "agent_1",
|
|
5961
|
-
agent_type: "general-purpose",
|
|
5962
|
-
});
|
|
5963
|
-
expect(Buffer.byteLength(textTheModelReads(output))).toBeLessThanOrEqual(2048);
|
|
5964
|
-
});
|
|
5965
|
-
// BAKER-3344: a Slack send answered 16 KB, Slack's own rendering of the message the agent had just written.
|
|
5966
|
-
it("hands the agent a connected Slack send as an outline that keeps its receipt, under 2 KB", async () => {
|
|
5967
|
-
const written = "Daily summary: spend is up 12% week on week, and two ad sets are over budget.";
|
|
5968
|
-
const richText = Array.from({ length: 40 }, (_, line) => ({
|
|
5969
|
-
type: "rich_text_section",
|
|
5970
|
-
elements: [{ type: "text", text: `${written} (${line})`, style: { bold: line % 2 === 0 } }],
|
|
5971
|
-
}));
|
|
5972
|
-
const send = {
|
|
5973
|
-
successful: true,
|
|
5974
|
-
data: {
|
|
5975
|
-
results: [
|
|
5976
|
-
{
|
|
5977
|
-
response: {
|
|
5978
|
-
successful: true,
|
|
5979
|
-
data: {
|
|
5980
|
-
ok: true,
|
|
5981
|
-
channel: "C05CUQ8B7QB",
|
|
5982
|
-
ts: "1794645585.123456",
|
|
5983
|
-
message: {
|
|
5984
|
-
app_id: "A09DP8VR3DF",
|
|
5985
|
-
bot_id: "B09DP8VR3DF",
|
|
5986
|
-
type: "message",
|
|
5987
|
-
text: written,
|
|
5988
|
-
ts: "1794645585.123456",
|
|
5989
|
-
blocks: [{ type: "rich_text", block_id: "LZ3J/V", elements: richText }],
|
|
5990
|
-
},
|
|
5991
|
-
},
|
|
5992
|
-
},
|
|
5993
|
-
tool_slug: "SLACK_SEND_MESSAGE",
|
|
5994
|
-
index: 0,
|
|
5995
|
-
},
|
|
5996
|
-
],
|
|
5997
|
-
total_count: 1,
|
|
5998
|
-
success_count: 1,
|
|
5999
|
-
error_count: 0,
|
|
6000
|
-
},
|
|
6001
|
-
error: null,
|
|
6002
|
-
log_id: "log_test",
|
|
6003
|
-
};
|
|
6004
|
-
const output = await toolOutputTheModelReads("mcp__composio_company__COMPOSIO_MULTI_EXECUTE_TOOL", [
|
|
6005
|
-
{ type: "text", text: JSON.stringify(send) },
|
|
6006
|
-
]);
|
|
6007
|
-
const text = textTheModelReads(output);
|
|
6008
|
-
expect(Buffer.byteLength(text)).toBeLessThanOrEqual(2048);
|
|
6009
|
-
for (const receipt of ['"ok":true', '"channel":"C05CUQ8B7QB"', '"ts":"1794645585.123456"']) {
|
|
6010
|
-
expect(text).toContain(receipt);
|
|
6011
|
-
}
|
|
6012
|
-
expect(JSON.parse(savedAnswer(text))).toEqual(send);
|
|
6013
|
-
});
|
|
6014
|
-
it("shortens a large answer from any connected tool, not only the managed apps", async () => {
|
|
6015
|
-
const deals = Array.from({ length: 200 }, (_, n) => ({
|
|
6016
|
-
id: `deal_${n}`,
|
|
6017
|
-
name: `Spring renewal ${n}`,
|
|
6018
|
-
notes: "Call back. ".repeat(20),
|
|
6019
|
-
}));
|
|
6020
|
-
const output = await toolOutputTheModelReads("mcp__acme_crm__list_deals", [
|
|
6021
|
-
{ type: "text", text: JSON.stringify({ deals, total: 200 }) },
|
|
6022
|
-
]);
|
|
6023
|
-
const text = textTheModelReads(output);
|
|
6024
|
-
expect(Buffer.byteLength(text)).toBeLessThanOrEqual(2048);
|
|
6025
|
-
expect(text).toContain("deal_0");
|
|
6026
|
-
expect(JSON.parse(savedAnswer(text)).deals).toHaveLength(200);
|
|
6027
|
-
});
|
|
6028
|
-
it("keeps a provider's error message whole while shortening the rest of the answer", async () => {
|
|
6029
|
-
const providerMessage = `Slack API error: channel_not_found. ${"The channel may be archived or the app is not a member of it. ".repeat(12)}`;
|
|
6030
|
-
const batch = {
|
|
6031
|
-
successful: false,
|
|
6032
|
-
data: {
|
|
6033
|
-
results: [
|
|
6034
|
-
{
|
|
6035
|
-
response: {
|
|
6036
|
-
successful: true,
|
|
6037
|
-
data: {
|
|
6038
|
-
messages: Array.from({ length: 80 }, (_, n) => ({ ts: `${n}`, text: "Thread reply ".repeat(10) })),
|
|
6039
|
-
},
|
|
6040
|
-
},
|
|
6041
|
-
tool_slug: "SLACK_FETCH_MESSAGE_THREAD_FROM_A_CONVERSATION",
|
|
6042
|
-
index: 0,
|
|
6043
|
-
},
|
|
6044
|
-
{ error: providerMessage, tool_slug: "SLACK_SEND_MESSAGE", index: 1 },
|
|
6045
|
-
],
|
|
6046
|
-
total_count: 2,
|
|
6047
|
-
success_count: 1,
|
|
6048
|
-
error_count: 1,
|
|
6049
|
-
},
|
|
6050
|
-
error: "1 out of 2 tools failed",
|
|
6051
|
-
};
|
|
6052
|
-
const output = await toolOutputTheModelReads("mcp__composio_company__COMPOSIO_MULTI_EXECUTE_TOOL", [
|
|
6053
|
-
{ type: "text", text: JSON.stringify(batch) },
|
|
6054
|
-
]);
|
|
6055
|
-
const text = textTheModelReads(output);
|
|
6056
|
-
expect(Buffer.byteLength(text)).toBeLessThan(Buffer.byteLength(JSON.stringify(batch)) / 4);
|
|
6057
|
-
expect(text).toContain(JSON.stringify(providerMessage));
|
|
6058
|
-
expect(text).toContain('"error":"1 out of 2 tools failed"');
|
|
6059
|
-
});
|
|
6060
|
-
it("passes a short answer through as it came", async () => {
|
|
6061
|
-
const failure = [
|
|
6062
|
-
{
|
|
6063
|
-
type: "text",
|
|
6064
|
-
text: JSON.stringify({
|
|
6065
|
-
successful: false,
|
|
6066
|
-
data: { results: [{ error: "channel_not_found", tool_slug: "SLACK_SEND_MESSAGE", index: 0 }] },
|
|
6067
|
-
error: "1 out of 1 tools failed",
|
|
6068
|
-
}),
|
|
6069
|
-
},
|
|
6070
|
-
];
|
|
6071
|
-
expect(await toolOutputTheModelReads("mcp__composio_company__COMPOSIO_MULTI_EXECUTE_TOOL", failure)).toEqual(failure);
|
|
6072
|
-
});
|
|
6073
|
-
});
|
|
6074
5948
|
//# sourceMappingURL=bridge-job.test.js.map
|