UNPKG

adk-typescript

Version:

TypeScript port of Google's Agent Development Kit (ADK)

108 lines (107 loc) 3.26 kB
/** * Utility functions for code execution. */ import { Content, Part } from "../models/types"; /** * A structure that contains a file name and its content. */ export interface File { /** * The name of the file with file extension (e.g., "file.csv"). */ name: string; /** * The base64-encoded bytes of the file content. */ content: string; /** * The mime type of the file (e.g., "image/png"). */ mimeType: string; } /** * A structure that contains the input of code execution. */ export interface CodeExecutionInput { /** * The code to execute. */ code: string; /** * The input files available to the code. */ inputFiles: File[]; /** * The execution ID for the stateful code execution. */ executionId?: string; } /** * A structure that contains the result of code execution. */ export interface CodeExecutionResult { /** * The standard output of the code execution. */ stdout: string; /** * The standard error of the code execution. */ stderr: string; /** * The output files from the code execution. */ outputFiles: File[]; } /** * Extensions to the Part interface for code execution */ interface ExecutableCodePart extends Part { executableCode?: { code: string; language: string; }; } /** * Utility functions for code execution. */ export declare class CodeExecutionUtils { /** * Gets the file content as a base64-encoded string. * * @param data - The file content bytes. * @returns The file content as a base64-encoded string. */ static getEncodedFileContent(data: Uint8Array): string; /** * Extracts the first code block from the content and truncate everything after it. * * @param content - The mutable content to extract the code from. * @param codeBlockDelimiters - The list of the enclosing delimiters to identify the code blocks. * @returns The first code block if found, otherwise undefined. */ static extractCodeAndTruncateContent(content: Content, codeBlockDelimiters: [string, string][]): string | undefined; /** * Builds an executable code part with code string. * * @param code - The code string. * @returns The constructed executable code part. */ static buildExecutableCodePart(code: string): ExecutableCodePart; /** * Builds the code execution result part from the code execution result. * * @param codeExecutionResult - The code execution result. * @returns The constructed code execution result part. */ static buildCodeExecutionResultPart(codeExecutionResult: CodeExecutionResult): Part; /** * Converts the code execution parts to text parts in a Content. * * @param content - The mutable content to convert the code execution parts to text parts. * @param codeBlockDelimiter - The delimiter to format the code block. * @param executionResultDelimiters - The delimiter to format the code execution result. */ static convertCodeExecutionParts(content: Content, codeBlockDelimiter: [string, string], executionResultDelimiters: [string, string]): void; } export {};