fix(prompt-gate): bind session messages receiver
This commit is contained in:
@@ -242,6 +242,50 @@ describe("dispatchInternalPrompt shared gate behavior", () => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test("#given SDK messages depends on its session receiver #when latest assistant waits on tools #then method binding is preserved and no prompt is sent", async () => {
|
||||||
|
// given
|
||||||
|
let promptCalls = 0
|
||||||
|
const session = {
|
||||||
|
_client: {
|
||||||
|
messages: [
|
||||||
|
{
|
||||||
|
info: { id: "msg_user", role: "user" },
|
||||||
|
parts: [{ type: "text", text: "run work" }],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
info: { id: "msg_assistant", role: "assistant", finish: "tool-calls" },
|
||||||
|
parts: [{ type: "tool_use", id: "toolu_pending", state: { status: "running" } }],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
async messages(
|
||||||
|
this: { _client: { messages: unknown[] } },
|
||||||
|
_input: { path: { id: string }; query: { directory: string } },
|
||||||
|
) {
|
||||||
|
return { data: this._client.messages }
|
||||||
|
},
|
||||||
|
async promptAsync() {
|
||||||
|
promptCalls += 1
|
||||||
|
},
|
||||||
|
}
|
||||||
|
const client = { session }
|
||||||
|
|
||||||
|
// when
|
||||||
|
const result = await dispatchInternalPrompt({
|
||||||
|
mode: "async",
|
||||||
|
client,
|
||||||
|
sessionID: "ses_bound_messages",
|
||||||
|
input: { path: { id: "ses_bound_messages" }, body: { parts: [] } },
|
||||||
|
source: "test:bound-messages",
|
||||||
|
settleMs: 0,
|
||||||
|
postDispatchHoldMs: 0,
|
||||||
|
})
|
||||||
|
|
||||||
|
// then
|
||||||
|
expect(result.status).toBe("active")
|
||||||
|
expect(promptCalls).toBe(0)
|
||||||
|
})
|
||||||
|
|
||||||
test("#given session.status reports busy #when an internal promptAsync is requested #then no prompt is sent", async () => {
|
test("#given session.status reports busy #when an internal promptAsync is requested #then no prompt is sent", async () => {
|
||||||
// given
|
// given
|
||||||
let promptCalls = 0
|
let promptCalls = 0
|
||||||
|
|||||||
@@ -238,10 +238,11 @@ async function sessionLatestAssistantIsWaitingOnTools<TInput>(args: {
|
|||||||
source: string
|
source: string
|
||||||
timeoutMs: number
|
timeoutMs: number
|
||||||
}): Promise<boolean> {
|
}): Promise<boolean> {
|
||||||
const messages = args.client.session?.messages
|
const session = args.client.session
|
||||||
if (typeof messages !== "function") {
|
if (typeof session?.messages !== "function") {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
const messages = session.messages.bind(session)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await withDispatchTimeout(
|
const response = await withDispatchTimeout(
|
||||||
|
|||||||
Reference in New Issue
Block a user