This repository has no description
0

Configure Feed

Select the types of activity you want to include in your feed.

niri / src / runner / loop-shared.ts
2.1 kB 78 lines
1import OpenAI from "openai" 2import type { LoopHooks, LoopState } from "./types" 3 4export type FunctionToolCall = OpenAI.Chat.ChatCompletionMessageToolCall & { type: "function" } 5 6export type ToolArgs = { 7 command?: string 8 query?: string 9 max_lines?: number 10 timeout_ms?: number 11 path?: string 12 start_line?: number 13 end_line?: number 14 old_text?: string 15 new_text?: string 16 note?: string 17 detail?: string 18 limit?: number 19 status?: string 20 item_id?: string 21 action?: string 22 channel_id?: string 23 channel_ids?: string[] 24 before_message_id?: string 25 content?: string 26 source_item_id?: string 27 reference_message?: string 28 reply_mode?: string 29 [key: string]: unknown 30} 31 32export type ToolExecutionOutcome = { shouldRest?: boolean; isWait?: boolean } 33 34export type CompletionTurnResult = { 35 message: OpenAI.Chat.ChatCompletionMessage 36 usage?: OpenAI.Completions.CompletionUsage 37 emittedText: boolean 38 emittedThinking: boolean 39 bufferedThinking: string 40 /** Runner-measured completion stream duration in milliseconds. */ 41 elapsedMs?: number 42 /** Runner-computed completion throughput in tokens per second. */ 43 tokensPerSecond?: number 44} 45 46export type CompletionRequest = { 47 model: string 48 messages: OpenAI.Chat.ChatCompletionMessageParam[] 49 tools: OpenAI.Chat.ChatCompletionTool[] 50 tool_choice: "required" | "auto" | "none" 51 include_reasoning?: boolean 52 reasoning?: { enabled?: boolean; exclude?: boolean; effort?: "none" | "minimal" | "low" | "medium" | "high" | "xhigh" } 53 provider?: { require_parameters?: boolean } 54 enable_thinking?: boolean 55 chat_template_kwargs?: { enable_thinking?: boolean } 56} 57 58export type ToolCallAssembly = { 59 id: string 60 type: "function" 61 function: { 62 name: string 63 arguments: string 64 } 65} 66 67export type ToolArgKey = keyof ToolArgs 68export type ArgTuple<K extends readonly ToolArgKey[]> = { [I in keyof K]: ToolArgs[K[I]] } 69 70export type ToolExecutionContext = { 71 convId: number 72 state: LoopState 73 hooks: LoopHooks 74 call: FunctionToolCall 75 args: ToolArgs 76} 77 78export type ToolHandler = (ctx: ToolExecutionContext) => Promise<ToolExecutionOutcome>