refactor(hooks): use unified internal prompt dispatch
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
@@ -17,7 +17,7 @@ import {
|
|||||||
findNearestMessageWithFields,
|
findNearestMessageWithFields,
|
||||||
findNearestMessageWithFieldsFromSDK,
|
findNearestMessageWithFieldsFromSDK,
|
||||||
} from "../../features/hook-message-injector"
|
} from "../../features/hook-message-injector"
|
||||||
import { promptAsyncAfterSessionIdle } from "../shared/prompt-async-gate"
|
import { dispatchInternalPrompt } from "../shared/prompt-async-gate"
|
||||||
|
|
||||||
export async function runAggressiveTruncationStrategy(params: {
|
export async function runAggressiveTruncationStrategy(params: {
|
||||||
sessionID: string
|
sessionID: string
|
||||||
@@ -88,7 +88,8 @@ export async function runAggressiveTruncationStrategy(params: {
|
|||||||
const launchVariant = previousMessage?.model?.variant
|
const launchVariant = previousMessage?.model?.variant
|
||||||
const inheritedTools = resolveInheritedPromptTools(params.sessionID, previousMessage?.tools)
|
const inheritedTools = resolveInheritedPromptTools(params.sessionID, previousMessage?.tools)
|
||||||
|
|
||||||
const promptResult = await promptAsyncAfterSessionIdle({
|
const promptResult = await dispatchInternalPrompt({
|
||||||
|
mode: "async",
|
||||||
client: params.client,
|
client: params.client,
|
||||||
sessionID: params.sessionID,
|
sessionID: params.sessionID,
|
||||||
source: "auto-compact",
|
source: "auto-compact",
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import {
|
|||||||
import { stripAgentListSortPrefix } from "../../shared/agent-display-names"
|
import { stripAgentListSortPrefix } from "../../shared/agent-display-names"
|
||||||
import { log } from "../../shared/logger"
|
import { log } from "../../shared/logger"
|
||||||
import { createInternalAgentContinuationTextPart, resolveInheritedPromptTools } from "../../shared"
|
import { createInternalAgentContinuationTextPart, resolveInheritedPromptTools } from "../../shared"
|
||||||
import { promptAsyncAfterSessionIdle } from "../shared/prompt-async-gate"
|
import { dispatchInternalPrompt } from "../shared/prompt-async-gate"
|
||||||
import { HOOK_NAME } from "./hook-name"
|
import { HOOK_NAME } from "./hook-name"
|
||||||
import { BOULDER_CONTINUATION_PROMPT } from "./system-reminder-templates"
|
import { BOULDER_CONTINUATION_PROMPT } from "./system-reminder-templates"
|
||||||
import { resolveRecentPromptContextForSession } from "./recent-model-resolver"
|
import { resolveRecentPromptContextForSession } from "./recent-model-resolver"
|
||||||
@@ -92,21 +92,22 @@ export async function injectBoulderContinuation(input: {
|
|||||||
: undefined
|
: undefined
|
||||||
const launchVariant = promptContext.model?.variant
|
const launchVariant = promptContext.model?.variant
|
||||||
|
|
||||||
const promptResult = await promptAsyncAfterSessionIdle({
|
const promptResult = await dispatchInternalPrompt({
|
||||||
|
mode: "async",
|
||||||
client: ctx.client,
|
client: ctx.client,
|
||||||
sessionID,
|
sessionID,
|
||||||
source: HOOK_NAME,
|
source: HOOK_NAME,
|
||||||
settleMs: idleSettleMs,
|
settleMs: idleSettleMs,
|
||||||
input: {
|
input: {
|
||||||
path: { id: sessionID },
|
path: { id: sessionID },
|
||||||
body: {
|
body: {
|
||||||
agent: continuationAgent,
|
agent: continuationAgent,
|
||||||
...(launchModel ? { model: launchModel } : {}),
|
...(launchModel ? { model: launchModel } : {}),
|
||||||
...(launchVariant ? { variant: launchVariant } : {}),
|
...(launchVariant ? { variant: launchVariant } : {}),
|
||||||
...(inheritedTools ? { tools: inheritedTools } : {}),
|
...(inheritedTools ? { tools: inheritedTools } : {}),
|
||||||
parts: [createInternalAgentContinuationTextPart(prompt)],
|
parts: [createInternalAgentContinuationTextPart(prompt)],
|
||||||
},
|
},
|
||||||
query: { directory: ctx.directory },
|
query: { directory: ctx.directory },
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
if (promptResult.status === "failed") {
|
if (promptResult.status === "failed") {
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ import { createInternalAgentContinuationTextPart } from "../../shared"
|
|||||||
import { getAgentConfigKey } from "../../shared/agent-display-names"
|
import { getAgentConfigKey } from "../../shared/agent-display-names"
|
||||||
import { log } from "../../shared/logger"
|
import { log } from "../../shared/logger"
|
||||||
import { shouldPromptAfterSessionIdle } from "../shared/session-idle-settle"
|
import { shouldPromptAfterSessionIdle } from "../shared/session-idle-settle"
|
||||||
import { promptAsyncAfterSessionIdle } from "../shared/prompt-async-gate"
|
import { dispatchInternalPrompt } from "../shared/prompt-async-gate"
|
||||||
import { injectBoulderContinuation } from "./boulder-continuation-injector"
|
import { injectBoulderContinuation } from "./boulder-continuation-injector"
|
||||||
import { HOOK_NAME } from "./hook-name"
|
import { HOOK_NAME } from "./hook-name"
|
||||||
import { resolveActiveBoulderSession } from "./resolve-active-boulder-session"
|
import { resolveActiveBoulderSession } from "./resolve-active-boulder-session"
|
||||||
@@ -291,7 +291,8 @@ export async function handleAtlasSessionIdle(input: {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const promptResult = await promptAsyncAfterSessionIdle({
|
const promptResult = await dispatchInternalPrompt({
|
||||||
|
mode: "async",
|
||||||
client: ctx.client,
|
client: ctx.client,
|
||||||
sessionID,
|
sessionID,
|
||||||
source: HOOK_NAME,
|
source: HOOK_NAME,
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import { clearToolInputCache, stopToolInputCacheCleanup } from "../tool-input-ca
|
|||||||
import type { PluginConfig } from "../types"
|
import type { PluginConfig } from "../types"
|
||||||
import { createInternalAgentTextPart, isHookDisabled, log } from "../../../shared"
|
import { createInternalAgentTextPart, isHookDisabled, log } from "../../../shared"
|
||||||
import { resolveSessionEventID } from "../../../shared/event-session-id"
|
import { resolveSessionEventID } from "../../../shared/event-session-id"
|
||||||
import { promptAfterSessionIdle } from "../../../shared/prompt-async-gate"
|
import { dispatchInternalPrompt } from "../../../shared/prompt-async-gate"
|
||||||
import {
|
import {
|
||||||
clearAllSessionHookState,
|
clearAllSessionHookState,
|
||||||
clearSessionHookState,
|
clearSessionHookState,
|
||||||
@@ -109,7 +109,8 @@ export function createSessionEventHandler(
|
|||||||
})
|
})
|
||||||
} else if (stopResult.block && stopResult.injectPrompt) {
|
} else if (stopResult.block && stopResult.injectPrompt) {
|
||||||
log("Stop hook returned block with inject_prompt", { sessionID })
|
log("Stop hook returned block with inject_prompt", { sessionID })
|
||||||
const promptResult = await promptAfterSessionIdle({
|
const promptResult = await dispatchInternalPrompt({
|
||||||
|
mode: "sync",
|
||||||
client: ctx.client,
|
client: ctx.client,
|
||||||
sessionID,
|
sessionID,
|
||||||
source: "claude-code-stop-hook:inject-prompt",
|
source: "claude-code-stop-hook:inject-prompt",
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ import {
|
|||||||
import { AGENT_RECOVERY_PROMPT, NO_TEXT_TAIL_THRESHOLD, RECOVERY_COOLDOWN_MS, RECENT_COMPACTION_WINDOW_MS } from "./constants"
|
import { AGENT_RECOVERY_PROMPT, NO_TEXT_TAIL_THRESHOLD, RECOVERY_COOLDOWN_MS, RECENT_COMPACTION_WINDOW_MS } from "./constants"
|
||||||
import type { CompactionContextClient } from "./types"
|
import type { CompactionContextClient } from "./types"
|
||||||
import type { TailMonitorState } from "./tail-monitor"
|
import type { TailMonitorState } from "./tail-monitor"
|
||||||
import { promptAsyncAfterSessionIdle, releasePromptAsyncReservation } from "../shared/prompt-async-gate"
|
import { dispatchInternalPrompt, releasePromptAsyncReservation } from "../shared/prompt-async-gate"
|
||||||
|
|
||||||
export function createRecoveryLogic(
|
export function createRecoveryLogic(
|
||||||
ctx: CompactionContextClient | undefined,
|
ctx: CompactionContextClient | undefined,
|
||||||
@@ -82,7 +82,8 @@ export function createRecoveryLogic(
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const promptResult = await promptAsyncAfterSessionIdle({
|
const promptResult = await dispatchInternalPrompt({
|
||||||
|
mode: "async",
|
||||||
client: ctx.client,
|
client: ctx.client,
|
||||||
sessionID,
|
sessionID,
|
||||||
source: "compaction-context-injector",
|
source: "compaction-context-injector",
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import {
|
|||||||
resolveInheritedPromptTools,
|
resolveInheritedPromptTools,
|
||||||
} from "../../shared"
|
} from "../../shared"
|
||||||
import { normalizeAgentForPrompt, stripAgentListSortPrefix } from "../../shared/agent-display-names"
|
import { normalizeAgentForPrompt, stripAgentListSortPrefix } from "../../shared/agent-display-names"
|
||||||
import { promptAsyncAfterSessionIdle } from "../shared/prompt-async-gate"
|
import { dispatchInternalPrompt } from "../shared/prompt-async-gate"
|
||||||
|
|
||||||
type MessageInfo = {
|
type MessageInfo = {
|
||||||
agent?: string
|
agent?: string
|
||||||
@@ -139,7 +139,8 @@ export async function injectContinuationPrompt(
|
|||||||
|
|
||||||
let response: unknown
|
let response: unknown
|
||||||
try {
|
try {
|
||||||
const promptResult = await promptAsyncAfterSessionIdle({
|
const promptResult = await dispatchInternalPrompt({
|
||||||
|
mode: "async",
|
||||||
client: ctx.client,
|
client: ctx.client,
|
||||||
sessionID: options.sessionID,
|
sessionID: options.sessionID,
|
||||||
source: "ralph-loop",
|
source: "ralph-loop",
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import { getLastUserRetryPayload } from "./last-user-retry-parts"
|
|||||||
import { extractSessionMessages } from "./session-messages"
|
import { extractSessionMessages } from "./session-messages"
|
||||||
import { resolveRegisteredAgentName } from "../../features/claude-code-session-state"
|
import { resolveRegisteredAgentName } from "../../features/claude-code-session-state"
|
||||||
import {
|
import {
|
||||||
promptAsyncAfterSessionIdle,
|
dispatchInternalPrompt,
|
||||||
releasePromptAsyncReservation,
|
releasePromptAsyncReservation,
|
||||||
} from "../shared/prompt-async-gate"
|
} from "../shared/prompt-async-gate"
|
||||||
|
|
||||||
@@ -157,7 +157,8 @@ export function createAutoRetryHelpers(deps: HookDeps) {
|
|||||||
sessionAwaitingFallbackResult.add(sessionID)
|
sessionAwaitingFallbackResult.add(sessionID)
|
||||||
scheduleSessionFallbackTimeout(sessionID, retryAgent)
|
scheduleSessionFallbackTimeout(sessionID, retryAgent)
|
||||||
|
|
||||||
const promptResult = await promptAsyncAfterSessionIdle({
|
const promptResult = await dispatchInternalPrompt({
|
||||||
|
mode: "async",
|
||||||
client: ctx.client,
|
client: ctx.client,
|
||||||
sessionID,
|
sessionID,
|
||||||
source: `runtime-fallback:${source}`,
|
source: `runtime-fallback:${source}`,
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import type { MessageData, ResumeConfig } from "./types"
|
|||||||
import { readParts } from "./storage/parts-reader"
|
import { readParts } from "./storage/parts-reader"
|
||||||
import { isSqliteBackend } from "../../shared/opencode-storage-detection"
|
import { isSqliteBackend } from "../../shared/opencode-storage-detection"
|
||||||
import { normalizeSDKResponse } from "../../shared"
|
import { normalizeSDKResponse } from "../../shared"
|
||||||
import { promptAsyncAfterSessionIdle } from "../shared/prompt-async-gate"
|
import { dispatchInternalPrompt } from "../shared/prompt-async-gate"
|
||||||
|
|
||||||
type Client = ReturnType<typeof createOpencodeClient>
|
type Client = ReturnType<typeof createOpencodeClient>
|
||||||
type ToolResultContent = { type: "text"; text: string }
|
type ToolResultContent = { type: "text"; text: string }
|
||||||
@@ -169,7 +169,8 @@ export async function recoverToolResultMissing(
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
const promptResult = await promptAsyncAfterSessionIdle({
|
const promptResult = await dispatchInternalPrompt({
|
||||||
|
mode: "async",
|
||||||
client,
|
client,
|
||||||
sessionID,
|
sessionID,
|
||||||
source: options?.source ?? "session-recovery-tool-result-missing",
|
source: options?.source ?? "session-recovery-tool-result-missing",
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import { readParts } from "./storage"
|
|||||||
import type { MessageData } from "./types"
|
import type { MessageData } from "./types"
|
||||||
import { normalizeSDKResponse } from "../../shared"
|
import { normalizeSDKResponse } from "../../shared"
|
||||||
import { isSqliteBackend } from "../../shared/opencode-storage-detection"
|
import { isSqliteBackend } from "../../shared/opencode-storage-detection"
|
||||||
import { promptAsyncAfterSessionIdle } from "../shared/prompt-async-gate"
|
import { dispatchInternalPrompt } from "../shared/prompt-async-gate"
|
||||||
|
|
||||||
type Client = ReturnType<typeof createOpencodeClient>
|
type Client = ReturnType<typeof createOpencodeClient>
|
||||||
|
|
||||||
@@ -119,7 +119,8 @@ export async function recoverUnavailableTool(
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
const promptResult = await promptAsyncAfterSessionIdle<PromptWithToolResultInput>({
|
const promptResult = await dispatchInternalPrompt<PromptWithToolResultInput>({
|
||||||
|
mode: "async",
|
||||||
client,
|
client,
|
||||||
sessionID,
|
sessionID,
|
||||||
source: "session-recovery-unavailable-tool",
|
source: "session-recovery-unavailable-tool",
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import {
|
|||||||
isRealUserMessage,
|
isRealUserMessage,
|
||||||
resolveInheritedPromptTools,
|
resolveInheritedPromptTools,
|
||||||
} from "../../shared"
|
} from "../../shared"
|
||||||
import { promptAsyncAfterSessionIdle } from "../shared/prompt-async-gate"
|
import { dispatchInternalPrompt } from "../shared/prompt-async-gate"
|
||||||
import type { MessageData, ResumeConfig } from "./types"
|
import type { MessageData, ResumeConfig } from "./types"
|
||||||
|
|
||||||
const RECOVERY_RESUME_TEXT = "[session recovered - continuing previous task]"
|
const RECOVERY_RESUME_TEXT = "[session recovered - continuing previous task]"
|
||||||
@@ -38,7 +38,8 @@ export async function resumeSession(client: Client, config: ResumeConfig): Promi
|
|||||||
: undefined
|
: undefined
|
||||||
const launchVariant = config.model?.variant
|
const launchVariant = config.model?.variant
|
||||||
|
|
||||||
const promptResult = await promptAsyncAfterSessionIdle({
|
const promptResult = await dispatchInternalPrompt({
|
||||||
|
mode: "async",
|
||||||
client,
|
client,
|
||||||
sessionID: config.sessionID,
|
sessionID: config.sessionID,
|
||||||
source: "session-recovery",
|
source: "session-recovery",
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import { listUnreadMessages } from "../../features/team-mode/team-mailbox/inbox"
|
|||||||
import { loadRuntimeState, transitionRuntimeState } from "../../features/team-mode/team-state-store/store"
|
import { loadRuntimeState, transitionRuntimeState } from "../../features/team-mode/team-state-store/store"
|
||||||
import { resolveSessionEventID } from "../../shared/event-session-id"
|
import { resolveSessionEventID } from "../../shared/event-session-id"
|
||||||
import { log } from "../../shared/logger"
|
import { log } from "../../shared/logger"
|
||||||
import { promptAsyncAfterSessionIdle } from "../shared/prompt-async-gate"
|
import { dispatchInternalPrompt } from "../shared/prompt-async-gate"
|
||||||
|
|
||||||
type PromptAsyncInput = {
|
type PromptAsyncInput = {
|
||||||
path: { id: string }
|
path: { id: string }
|
||||||
@@ -111,7 +111,8 @@ export function createTeamIdleWakeHint(ctx: TeamIdleWakeHintContext, config: Tea
|
|||||||
}
|
}
|
||||||
|
|
||||||
applyMemberSessionRouting(sessionID, memberEntry)
|
applyMemberSessionRouting(sessionID, memberEntry)
|
||||||
const promptResult = await promptAsyncAfterSessionIdle({
|
const promptResult = await dispatchInternalPrompt({
|
||||||
|
mode: "async",
|
||||||
client: ctx.client,
|
client: ctx.client,
|
||||||
sessionID,
|
sessionID,
|
||||||
source: "team-idle-wake-hint",
|
source: "team-idle-wake-hint",
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ import {
|
|||||||
normalizeAgentForPromptKey,
|
normalizeAgentForPromptKey,
|
||||||
stripAgentListSortPrefix,
|
stripAgentListSortPrefix,
|
||||||
} from "../../shared/agent-display-names"
|
} from "../../shared/agent-display-names"
|
||||||
import { promptAsyncAfterSessionIdle } from "../shared/prompt-async-gate"
|
import { dispatchInternalPrompt } from "../shared/prompt-async-gate"
|
||||||
|
|
||||||
import {
|
import {
|
||||||
CONTINUATION_PROMPT,
|
CONTINUATION_PROMPT,
|
||||||
@@ -187,7 +187,8 @@ ${todoList}`
|
|||||||
: undefined
|
: undefined
|
||||||
const launchVariant = model?.variant
|
const launchVariant = model?.variant
|
||||||
|
|
||||||
const promptResult = await promptAsyncAfterSessionIdle({
|
const promptResult = await dispatchInternalPrompt({
|
||||||
|
mode: "async",
|
||||||
client: ctx.client,
|
client: ctx.client,
|
||||||
sessionID,
|
sessionID,
|
||||||
source: HOOK_NAME,
|
source: HOOK_NAME,
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import {
|
|||||||
isUnstableTask,
|
isUnstableTask,
|
||||||
THINKING_SUMMARY_MAX_CHARS,
|
THINKING_SUMMARY_MAX_CHARS,
|
||||||
} from "./task-message-analyzer"
|
} from "./task-message-analyzer"
|
||||||
import { promptAsyncAfterSessionIdle } from "../shared/prompt-async-gate"
|
import { dispatchInternalPrompt } from "../shared/prompt-async-gate"
|
||||||
|
|
||||||
const HOOK_NAME = "unstable-agent-babysitter"
|
const HOOK_NAME = "unstable-agent-babysitter"
|
||||||
const DEFAULT_TIMEOUT_MS = 120000
|
const DEFAULT_TIMEOUT_MS = 120000
|
||||||
@@ -216,7 +216,8 @@ export function createUnstableAgentBabysitterHook(ctx: BabysitterContext, option
|
|||||||
? { providerID: model.providerID, modelID: model.modelID }
|
? { providerID: model.providerID, modelID: model.modelID }
|
||||||
: undefined
|
: undefined
|
||||||
const launchVariant = model?.variant
|
const launchVariant = model?.variant
|
||||||
const promptResult = await promptAsyncAfterSessionIdle({
|
const promptResult = await dispatchInternalPrompt({
|
||||||
|
mode: "async",
|
||||||
client: ctx.client,
|
client: ctx.client,
|
||||||
sessionID: mainSessionID,
|
sessionID: mainSessionID,
|
||||||
source: HOOK_NAME,
|
source: HOOK_NAME,
|
||||||
|
|||||||
@@ -38,20 +38,9 @@ type PromptClient<TInput> = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type InternalPromptDispatchClient<TInput> = {
|
|
||||||
session?: {
|
|
||||||
status?: () => Promise<unknown>
|
|
||||||
messages?: (input: { path: { id: string }; query: PromptMessagesQuery }) => Promise<unknown>
|
|
||||||
promptAsync?: (input: TInput) => Promise<unknown>
|
|
||||||
prompt?: (input: TInput) => Promise<unknown>
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export type InternalPromptDispatchMode = "async" | "sync"
|
export type InternalPromptDispatchMode = "async" | "sync"
|
||||||
|
|
||||||
export type InternalPromptDispatchArgs<TInput = PromptAsyncInput> = {
|
type InternalPromptDispatchCommonArgs<TInput> = {
|
||||||
mode: InternalPromptDispatchMode
|
|
||||||
client: InternalPromptDispatchClient<TInput>
|
|
||||||
sessionID: string
|
sessionID: string
|
||||||
input: TInput
|
input: TInput
|
||||||
source: string
|
source: string
|
||||||
@@ -62,6 +51,11 @@ export type InternalPromptDispatchArgs<TInput = PromptAsyncInput> = {
|
|||||||
checkToolState?: boolean
|
checkToolState?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type InternalPromptDispatchArgs<TInput = PromptAsyncInput> = InternalPromptDispatchCommonArgs<TInput> & (
|
||||||
|
| { mode: "async"; client: PromptAsyncClient<TInput> }
|
||||||
|
| { mode: "sync"; client: PromptClient<TInput> }
|
||||||
|
)
|
||||||
|
|
||||||
type PromptAsyncReservation = {
|
type PromptAsyncReservation = {
|
||||||
source: string
|
source: string
|
||||||
reservedAt: number
|
reservedAt: number
|
||||||
@@ -386,34 +380,6 @@ async function dispatchAfterSessionIdle<TInput>(args: {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getInternalPromptDispatcher<TInput>(
|
|
||||||
mode: InternalPromptDispatchMode,
|
|
||||||
session: InternalPromptDispatchClient<TInput>["session"],
|
|
||||||
): {
|
|
||||||
sessionName: "promptAsync" | "prompt"
|
|
||||||
dispatch?: (input: TInput) => Promise<unknown>
|
|
||||||
} {
|
|
||||||
if (mode === "async") {
|
|
||||||
if (typeof session?.promptAsync !== "function") {
|
|
||||||
return { sessionName: "promptAsync" }
|
|
||||||
}
|
|
||||||
const dispatchPromptAsync = session.promptAsync.bind(session)
|
|
||||||
return {
|
|
||||||
sessionName: "promptAsync",
|
|
||||||
dispatch: (input) => dispatchPromptAsync(input),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (typeof session?.prompt !== "function") {
|
|
||||||
return { sessionName: "prompt" }
|
|
||||||
}
|
|
||||||
const dispatchPrompt = session.prompt.bind(session)
|
|
||||||
return {
|
|
||||||
sessionName: "prompt",
|
|
||||||
dispatch: (input) => dispatchPrompt(input),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function dispatchInternalPrompt<TInput = PromptAsyncInput>(
|
export async function dispatchInternalPrompt<TInput = PromptAsyncInput>(
|
||||||
args: InternalPromptDispatchArgs<TInput>,
|
args: InternalPromptDispatchArgs<TInput>,
|
||||||
): Promise<InternalPromptDispatchResult> {
|
): Promise<InternalPromptDispatchResult> {
|
||||||
@@ -426,7 +392,24 @@ export async function dispatchInternalPrompt<TInput = PromptAsyncInput>(
|
|||||||
} = args
|
} = args
|
||||||
const postDispatchHoldMs = args.postDispatchHoldMs ?? DEFAULT_PROMPT_ASYNC_POST_DISPATCH_HOLD_MS
|
const postDispatchHoldMs = args.postDispatchHoldMs ?? DEFAULT_PROMPT_ASYNC_POST_DISPATCH_HOLD_MS
|
||||||
const dispatchTimeoutMs = args.dispatchTimeoutMs ?? DEFAULT_PROMPT_DISPATCH_TIMEOUT_MS
|
const dispatchTimeoutMs = args.dispatchTimeoutMs ?? DEFAULT_PROMPT_DISPATCH_TIMEOUT_MS
|
||||||
const { sessionName, dispatch } = getInternalPromptDispatcher(args.mode, client.session)
|
const sessionName = args.mode === "async" ? "promptAsync" : "prompt"
|
||||||
|
const dispatch = (() => {
|
||||||
|
if (args.mode === "async") {
|
||||||
|
const session = args.client.session
|
||||||
|
if (typeof session?.promptAsync !== "function") {
|
||||||
|
return undefined
|
||||||
|
}
|
||||||
|
const dispatchPromptAsync = session.promptAsync.bind(session)
|
||||||
|
return (dispatchInput: TInput) => dispatchPromptAsync(dispatchInput)
|
||||||
|
}
|
||||||
|
|
||||||
|
const session = args.client.session
|
||||||
|
if (typeof session?.prompt !== "function") {
|
||||||
|
return undefined
|
||||||
|
}
|
||||||
|
const dispatchPrompt = session.prompt.bind(session)
|
||||||
|
return (dispatchInput: TInput) => dispatchPrompt(dispatchInput)
|
||||||
|
})()
|
||||||
|
|
||||||
if (!dispatch) {
|
if (!dispatch) {
|
||||||
log(`[prompt-async-gate] ${sessionName} unavailable`, { sessionID, source })
|
log(`[prompt-async-gate] ${sessionName} unavailable`, { sessionID, source })
|
||||||
|
|||||||
Reference in New Issue
Block a user