import { HookOptions } from './common'; /** * Extended hook options that include signal configuration. * Used by `execHook()` and `execHookBatch()`. */ export interface ExecHookOptions extends HookOptions { /** Signal ID to send after hook execution; if not provided, a random one will be generated */ signalId?: string; } /** * Combines `hook()` + `waitFor()` into a single call: spawns a hook * function on a target workflow and suspends the current workflow until * the hook signals completion. This is the recommended pattern for * request/response communication between workflow threads. * * ## Signal Injection * * A `signalId` is automatically generated (or use the one you provide) * and injected as the **last argument** to the hooked function as * `{ signal: string, $durable: true }`. The hook function must call * `Durable.workflow.signal(signalInfo.signal, result)` to deliver * its response back to the waiting workflow. * * ## Difference from `execChild` * * - `execChild` spawns a **new** workflow job with its own lifecycle. * - `execHook` runs within an **existing** workflow's job, in an * isolated dimensional thread. This is lighter-weight and shares * the parent job's data namespace. * * ## Examples * * ```typescript * import { Durable } from '@hotmeshio/hotmesh'; * * // Orchestrator: spawn a hook and await its result * export async function reviewWorkflow(docId: string): Promise { * const verdict = await Durable.workflow.execHook<{ approved: boolean }>({ * taskQueue: 'reviewers', * workflowName: 'reviewDocument', * args: [docId], * }); * * return verdict.approved ? 'accepted' : 'rejected'; * } * ``` * * ```typescript * // The hooked function (runs on the 'reviewers' worker) * export async function reviewDocument( * docId: string, * signalInfo?: { signal: string; $durable: boolean }, * ): Promise<{ approved: boolean }> { * const { analyzeDocument } = Durable.workflow.proxyActivities(); * const score = await analyzeDocument(docId); * const result = { approved: score > 0.8 }; * * // Signal the waiting workflow with the result * if (signalInfo?.signal) { * await Durable.workflow.signal(signalInfo.signal, result); * } * return result; * } * ``` * * ```typescript * // With explicit signalId for traceability * const result = await Durable.workflow.execHook({ * taskQueue: 'analyzers', * workflowName: 'runAnalysis', * args: [datasetId], * signalId: `analysis-${datasetId}`, * }); * ``` * * @template T - The type of data returned by the hook function's signal. * @param {ExecHookOptions} options - Hook configuration including target workflow and arguments. * @returns {Promise} The signal result from the hooked function. */ export declare function execHook(options: ExecHookOptions): Promise;