import { ScheduleSpec, Workflow, WorkflowHandle, WorkflowResultType } from "@temporalio/client"; import { WorkerOptions } from "@temporalio/worker"; import { SendAgentEvent, AgentEvent } from "./agent"; export type CloudConnectionOptions = { engineId: string; apiKey: string; address?: string; apiAddress?: string; temporalNamespace?: string; }; export type ServiceInput = { taskQueue?: string; workflowsPath?: string; agentsPath?: string; functions?: WorkerOptions["activities"]; options?: { rateLimit?: number; maxConcurrentWorkflowRuns?: number; maxConcurrentFunctionRuns?: number; endpoints?: boolean; endpointGroup?: string; webhookUrl?: string; }; connectionOptions?: CloudConnectionOptions; resources?: { targetCpuUsage?: number; targetMemoryUsage?: number; }; }; declare class Restack { private client; private options?; constructor(options?: CloudConnectionOptions); private getConnectionOptions; private createClient; private connect; private createService; private runService; /** * Starts a service with the specified configuration. * * @param {Object} params - The parameters for starting the service. * @param {string} [params.taskQueue='restack'] - The task queue name for the service. * @param {string} [params.workflowsPath] - The path to the workflows directory. * @param {WorkerOptions['activities']} [params.functions] - The functions to be registered with the service. * @param {boolean} [params.endpoints] - Whether to register API endpoints. * @param {Object} [params.options] - Additional options for the service. * @param {number} [params.options.rateLimit] - The rate limit for functions. * @param {number} [params.options.maxConcurrentWorkflowRuns] - The maximum number of concurrent workflow runs. * @param {number} [params.options.maxConcurrentFunctionRuns] - The maximum number of concurrent function runs. * @param {Object} [params.resources] - The resources to be used for the service. * @param {number} [params.resources.targetCpuUsage] - The target CPU usage for the service. * @param {number} [params.resources.targetMemoryUsage] - The target memory usage for the service. * @returns {Promise} A promise that resolves when the service has started. * @throws {Error} If the service fails to start. */ startService({ taskQueue, workflowsPath, agentsPath, functions, options, resources, }: ServiceInput): Promise; /** * Schedules or starts a workflow. * * @param {Object} params - The parameters for scheduling or starting the workflow. * @param {string} params.workflowName - The name of the workflow to schedule or start. * @param {string} params.workflowId - The ID of the workflow. * @param {Object} [params.input] - The input data for the workflow. * @param {string} [params.taskQueue='restack'] - The task queue for the workflow. * @param {ScheduleSpec} [params.schedule] - The schedule specification for the workflow. If not provided, the workflow starts immediately. * @returns {Promise} A promise that resolves to the runId (for immediate start) or scheduleId (for scheduled workflows). * @throws {Error} If the workflow fails to start or schedule. */ scheduleWorkflow({ workflowName, workflowId, input, taskQueue, schedule, event, isAgent, }: { workflowName: string; workflowId: string; input?: { [key: string]: any; }; taskQueue?: string; schedule?: ScheduleSpec; event?: AgentEvent; isAgent?: boolean; }): Promise; /** * Retrieves a workflow handle. * * @param {Object} params - The parameters for retrieving the workflow handle. * @param {string} params.workflowId - The ID of the workflow. * @param {string} params.runId - The run ID of the workflow execution. * @returns {Promise>} A promise that resolves to the workflow handle. * @throws {Error} If the workflow handle cannot be retrieved. */ getWorkflowHandle({ workflowId, runId, }: { workflowId: string; runId?: string; }): Promise>; /** * Retrieves the result of a workflow execution. * * @param {Object} params - The parameters for retrieving the workflow result. * @param {string} params.workflowId - The ID of the workflow. * @param {string} params.runId - The run ID of the workflow execution. * @returns {Promise>} A promise that resolves to the workflow result. * @throws {Error} If the workflow result cannot be retrieved. */ getWorkflowResult({ workflowId, runId, }: { workflowId: string; runId?: string; }): Promise>; /** * Retrieves an agent handle. * * @param {Object} params - The parameters for retrieving the agent handle. * @param {string} params.agentId - The ID of the agent. * @param {string} params.runId - The run ID of the agent execution. * @returns {Promise>} A promise that resolves to the agent handle. * @throws {Error} If the agent handle cannot be retrieved. */ getAgentHandle({ agentId, runId, }: { agentId: string; runId?: string; }): Promise>; /** * Retrieves the result of a agent execution. * * @param {Object} params - The parameters for retrieving the agent result. * @param {string} params.agentId - The ID of the agent. * @param {string} params.runId - The run ID of the agent execution. * @returns {Promise>} A promise that resolves to the agent result. * @throws {Error} If the agent result cannot be retrieved. */ getAgentResult({ agentId, runId, }: { agentId: string; runId?: string; }): Promise>; /** * Sends an event to a running agent. * Cannot be called from a agent, only from a client or a function. * * @param {sendAgentEvent} params - The parameters for sending the agent event. * @param {Object} params.event - The event to send. * @param {string} params.event.name - The name of the event. * @param {any} params.event.input - The input data for the event. * @param {Object} params.agent - The agent information. * @param {string} params.agent.agentId - The ID of the agent. * @param {string} params.agent.runId - The run ID of the agent execution. * @returns {Promise} A promise that resolves to the result of the event execution. * @throws {Error} If the event fails to send. */ sendAgentEvent({ event, agent, waitForCompletion }: SendAgentEvent): Promise; /** * Schedules or starts an agent. * * @param {Object} params - The parameters for scheduling or starting the agent. * @param {string} params.agentName - The name of the agent to schedule or start. * @param {string} params.agentId - The ID of the agent. * @param {Object} [params.input] - The input data for the agent. * @param {string} [params.taskQueue='restack'] - The task queue for the agent. * @param {ScheduleSpec} [params.schedule] - The schedule specification for the agent. If not provided, the agent starts immediately. * @param {Object} [params.event] - The event to send to the agent. * @param {string} [params.event.name] - The name of the event. * @param {any} [params.event.input] - The input data for the event. * @returns {Promise} A promise that resolves to the runId (for immediate start) or scheduleId (for scheduled agent). * @throws {Error} If the agent fails to start or schedule. */ scheduleAgent({ agentName, agentId, input, taskQueue, schedule, event, }: { agentName: string; agentId: string; input?: { [key: string]: any; }; taskQueue?: string; schedule?: ScheduleSpec; event?: AgentEvent; }): Promise; /** * Retrieves the latest data of a agent event. * * @param {Object} params - The parameters for retrieving the agent event. * @param {string} params.agentId - The ID of the agent. * @param {string} params.runId - The run ID of the agent execution. * @param {string} params.eventName - The name of the event. * @returns {Promise>} A promise that resolves to the agent event data. * @throws {Error} If the agent event cannot be retrieved. */ getAgentEvent({ agentId, runId, eventName, }: { agentId: string; runId?: string; eventName: string; }): Promise>; /** * Retrieves the latest state of an agent. * * @param {Object} params - The parameters for retrieving the agent state. * @param {string} params.agentId - The ID of the agent. * @param {string} params.runId - The run ID of the agent execution. * @param {string} params.stateName - The name of the state. * @returns {Promise>} A promise that resolves to the agent state data. * @throws {Error} If the agent state cannot be retrieved. */ getAgentState({ agentId, runId, stateName, }: { agentId: string; runId?: string; stateName: string; }): Promise>; } export default Restack;