UNPKG

@promptbook/remote-server

Version:

Promptbook: Create persistent AI agents that turn your company's scattered knowledge into action

90 lines (89 loc) 3.39 kB
import OpenAI from 'openai'; import type { ChatPromptResult } from '../../execution/PromptResult'; import type { ScriptExecutionTools } from '../../execution/ScriptExecutionTools'; import type { Prompt } from '../../types/Prompt'; import type { string_date_iso8601, string_token } from '../../types/string_token'; import { OpenAiAssistantExecutionToolsProgressReporter } from './OpenAiAssistantExecutionToolsProgressReporter'; /** * Shared context for one assistant chat call after prompt preparation finishes. * * @private helper of `OpenAiAssistantExecutionToolsToolRunner` */ type AssistantChatCallContext = { readonly client: OpenAI; readonly prompt: Prompt; readonly rawPromptContent: string; readonly threadMessages: ReadonlyArray<OpenAI.Beta.ThreadCreateAndRunParams.Thread.Message>; readonly start: string_date_iso8601; readonly onProgress: (chunk: ChatPromptResult) => void; }; /** * Runs assistant requests that require OpenAI Runs API tool execution. * * @private helper of `OpenAiAssistantExecutionTools` */ export declare class OpenAiAssistantExecutionToolsToolRunner { private readonly options; /** * Creates one tool runner instance. */ constructor(options: { readonly assistantId: string_token; readonly isVerbose: boolean; readonly scriptExecutionTools?: ScriptExecutionTools | ReadonlyArray<ScriptExecutionTools>; readonly progressReporter: OpenAiAssistantExecutionToolsProgressReporter; }); /** * Runs assistant calls with tools through the non-streaming Runs API. */ callChatModelStreamWithTools(context: AssistantChatCallContext): Promise<ChatPromptResult>; /** * Builds the non-streaming assistant request payload used when tool calls are enabled. */ private createAssistantToolRunRequest; /** * Starts the assistant run and keeps polling until the run completes or fails. */ private executeAssistantToolRun; /** * Polls one assistant run, executing and submitting tool outputs when OpenAI requests them. */ private waitForAssistantToolRun; /** * Executes all required assistant tool calls and submits their outputs back to OpenAI. */ private submitAssistantRequiredToolOutputs; /** * Waits a bit and then fetches the latest assistant run status. */ private retrieveAssistantRunAfterDelay; /** * Executes each function tool requested by the assistant and records progress snapshots. */ private executeAssistantRequiredToolCalls; /** * Executes one function tool requested by the assistant. */ private executeAssistantRequiredToolCall; /** * Creates the initial pending snapshot for one assistant tool call. */ private createPendingAssistantToolCall; /** * Resolves the configured script tools for assistant tool execution. */ private resolveAssistantScriptTools; /** * Executes the configured script tool for one assistant-requested function call. */ private executeAssistantFunctionTool; /** * Finalizes one assistant tool-call snapshot after execution ends. */ private createCompletedAssistantToolCall; /** * Extracts the latest assistant text response from a completed thread. */ private extractCompletedAssistantTextContent; } export {};