eve
Version:
Filesystem-first framework for durable backend AI agents that run anywhere.
77 lines • 2.72 kB
TypeScript
import { type Hook } from '#compiled/@workflow/world/index.js';
import { type CryptoKey } from '../encryption.js';
/**
* Get the hook by token to find the associated workflow run,
* and hydrate the `metadata` property if it was set from within
* the workflow run.
*
* @param token - The unique token identifying the hook
*/
export declare function getHookByToken(token: string): Promise<Hook>;
/**
* Resumes a workflow run by sending a payload to a hook identified by its token.
*
* This function is called externally (e.g., from an API route or server action)
* to send data to a hook and resume the associated workflow run.
*
* @param tokenOrHook - The unique token identifying the hook, or the hook object itself
* @param payload - The data payload to send to the hook
* @returns Promise resolving to the hook
* @throws Error if the hook is not found or if there's an error during the process
*
* @example
*
* ```ts
* // In an API route
* import { resumeHook } from '@workflow/core/runtime';
*
* export async function POST(request: Request) {
* const { token, data } = await request.json();
*
* try {
* const hook = await resumeHook(token, data);
* return Response.json({ runId: hook.runId });
* } catch (error) {
* return new Response('Hook not found', { status: 404 });
* }
* }
* ```
*/
export declare function resumeHook<T = any>(tokenOrHook: string | Hook, payload: T, encryptionKeyOverride?: CryptoKey): Promise<Hook>;
/**
* Resumes a webhook by sending a {@link https://developer.mozilla.org/en-US/docs/Web/API/Request | Request}
* object to a hook identified by its token.
*
* This function is called externally (e.g., from an API route or server action)
* to send a request to a webhook and resume the associated workflow run.
*
* @param token - The unique token identifying the hook
* @param request - The request to send to the hook
* @returns Promise resolving to the response
* @throws Error if the hook is not found or if there's an error during the process
*
* @example
*
* ```ts
* // In an API route
* import { resumeWebhook } from '@workflow/core/runtime';
*
* export async function POST(request: Request) {
* const url = new URL(request.url);
* const token = url.searchParams.get('token');
*
* if (!token) {
* return new Response('Missing token', { status: 400 });
* }
*
* try {
* const response = await resumeWebhook(token, request);
* return response;
* } catch (error) {
* return new Response('Webhook not found', { status: 404 });
* }
* }
* ```
*/
export declare function resumeWebhook(token: string, request: Request): Promise<Response>;
//# sourceMappingURL=resume-hook.d.ts.map