// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. import { APIResource } from '../../core/resource'; import * as RepoAPI from './repo'; import * as FileAPI from './file'; import { FileDeleteParams, FileDownloadParams, FileDownloadResponse, FileUploadParams } from './file'; import { APIPromise } from '../../core/api-promise'; import { Stream } from '../../core/streaming'; import { buildHeaders } from '../../internal/headers'; import { RequestOptions } from '../../internal/request-options'; import { path } from '../../internal/utils/path'; export class Repo extends APIResource { file: FileAPI.File = new FileAPI.File(this._client); /** * Create a new repository from the provided template. * * @example * ```ts * const repoInfo = await client.repo.create(); * ``` */ create(body: RepoCreateParams, options?: RequestOptions): APIPromise { return this._client.post('/repo', { body, ...options }); } /** * Retrieve relevant content from a repository based on a query. * * @example * ```ts * const repo = await client.repo.retrieve( * '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', * { query: 'x' }, * ); * ``` */ retrieve( repoID: string, body: RepoRetrieveParams, options?: RequestOptions, ): APIPromise { return this._client.post(path`/repo/${repoID}/retrieve`, { body, ...options }); } /** * Apply repository changes. * * See the model docs for details of each update variant: * * - RepoUpdateFiles - snapshot replacement of tracked files * - RepoUpdateDiff - explicit write/delete/rename operations * - RepoUpdateGit - pull & merge from a remote Git repository * * Returns: RepoInfo: Includes the new repo head and, when determinable, a list of * changed files for convenience. * * Error codes: 400: Invalid request type / diff operation / failed remote merge. * 404: Referenced file for delete/rename does not exist. 423: Repository lock * contention. * * @example * ```ts * const repoInfo = await client.repo.update( * '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', * ); * ``` */ update(repoID: string, body: RepoUpdateParams, options?: RequestOptions): APIPromise { return this._client.post(path`/repo/${repoID}/update`, { body, ...options }); } /** * Get metadata for all repositories owned by the user. * * @example * ```ts * const repos = await client.repo.list(); * ``` */ list( query: RepoListParams | null | undefined = {}, options?: RequestOptions, ): APIPromise { return this._client.get('/repo', { query, ...options }); } /** * Delete a repository and its associated data. * * @example * ```ts * await client.repo.delete( * '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', * ); * ``` */ delete(repoID: string, options?: RequestOptions): APIPromise { return this._client.delete(path`/repo/${repoID}`, { ...options, headers: buildHeaders([{ Accept: '*/*' }, options?.headers]), }); } /** * Run a user-defined agent from the template repo configuration. Returns real-time * updates as Server-Sent Events (SSE). * * @example * ```ts * const response = await client.repo.agent( * '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', * { * agent_inputs: { * prompt: 'Review this code for security issues', * file_path: 'src/main.py', * }, * agent_name: 'code_review', * }, * ); * ``` */ agent( repoID: string, body: RepoAgentParams, options?: RequestOptions, ): APIPromise> { return this._client.post(path`/repo/${repoID}/agent`, { body, ...options, headers: buildHeaders([{ Accept: 'text/event-stream' }, options?.headers]), stream: true, }) as APIPromise>; } /** * Return all readable tracked files in a repository. * * If a `commit` is provided, read file contents from that commit; otherwise read * from the working directory. * * @example * ```ts * const response = await client.repo.clone( * '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', * ); * ``` */ clone( repoID: string, query: RepoCloneParams | null | undefined = {}, options?: RequestOptions, ): APIPromise { return this._client.get(path`/repo/${repoID}/clone`, { query, ...options }); } /** * Get the embedding status for a repository. */ embeddingStatus( repoID: string, query: RepoEmbeddingStatusParams | null | undefined = {}, options?: RequestOptions, ): APIPromise { return this._client.get(path`/repo/${repoID}/embedding_status`, { query, ...options }); } /** * Get metadata for a single repository. * * @example * ```ts * const repoMetadata = await client.repo.get( * '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', * ); * ``` */ get(repoID: string, options?: RequestOptions): APIPromise { return this._client.get(path`/repo/${repoID}`, options); } /** * Run a user-defined agent from the template repo configuration. Returns real-time * updates as Server-Sent Events (SSE). * * @example * ```ts * const response = await client.repo.search( * '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e', * { query: 'Find all instances of TODO comments' }, * ); * ``` */ search( repoID: string, body: RepoSearchParams, options?: RequestOptions, ): APIPromise> { const params = { agent_inputs: { query: body.query }, agent_name: 'relace-search', continue: false, }; return this._client.post(path`/repo/${repoID}/agent`, { body: params, ...options, headers: buildHeaders([{ Accept: 'text/event-stream' }, options?.headers]), stream: true, }) as APIPromise>; } } /** * Text file payload used in create/update requests. * * Attributes: filename: Repository-relative path (POSIX). Directories are created * as needed. Treated as UTF-8 text; binary content should be avoided. content: * Full in-memory textual content to write. */ export interface File { content: string; filename: string; } export interface RepoInfo { repo_head: string; repo_id: string; changed_files?: Array | null; } export interface RepoMetadata { auto_index: boolean; created_at: string; metadata: { [key: string]: string } | null; repo_id: string; updated_at: string | null; } export interface RepoRetrieveResponse { hash: string; pending_embeddings: number; results: Array; } export namespace RepoRetrieveResponse { export interface Result { filename: string; score: number; content?: string | null; } } export interface RepoListResponse { items: Array; total_items: number; next_page?: number | null; } /** * Server-Sent Events stream */ export type RepoAgentResponse = { event?: string | null; data: any; }; /** * Response containing all readable files in a repository. */ export interface RepoCloneResponse { files: Array; } export interface RepoEmbeddingStatusResponse { completed_embeddings: number; hash: string; pending_embeddings: number; } export interface RepoCreateParams { auto_index?: boolean; metadata?: { [key: string]: string } | null; source?: | RepoCreateParams.RepoCreateGitSource | RepoCreateParams.RepoCreateFilesSource | RepoCreateParams.RepoCreateRelaceSource | null; } export namespace RepoCreateParams { export interface RepoCreateGitSource { type: 'git'; url: string; branch?: string | null; hash?: string | null; } export interface RepoCreateFilesSource { files: Array; type: 'files'; } export interface RepoCreateRelaceSource { repo_id: string; type: 'relace'; copy_metadata?: boolean; copy_remote?: boolean; } } export interface RepoRetrieveParams { query: string; branch?: string | null; hash?: string | null; include_content?: boolean; rerank?: boolean; score_threshold?: number; token_limit?: number; } export interface RepoUpdateParams { metadata?: { [key: string]: string } | null; /** * Snapshot-style repository update. * * Treat the provided `files` list as the complete authoritative set of tracked * text files. Any previously tracked file that is not present in the list will be * deleted. Each listed file is created or overwritten. * * This mirrors the semantics of replacing the working tree with exactly the * supplied set (excluding ignored/untracked items). Binary files are skipped * downstream during embedding. * * Attributes: type: Discriminator literal `"files"`. files: List of files that * should exist after the operation. */ source?: | RepoUpdateParams.RepoUpdateFiles | RepoUpdateParams.RepoUpdateDiff | RepoUpdateParams.RepoUpdateGit | null; } export namespace RepoUpdateParams { /** * Snapshot-style repository update. * * Treat the provided `files` list as the complete authoritative set of tracked * text files. Any previously tracked file that is not present in the list will be * deleted. Each listed file is created or overwritten. * * This mirrors the semantics of replacing the working tree with exactly the * supplied set (excluding ignored/untracked items). Binary files are skipped * downstream during embedding. * * Attributes: type: Discriminator literal `"files"`. files: List of files that * should exist after the operation. */ export interface RepoUpdateFiles { files: Array; type: 'files'; } /** * Explicit patch consisting of write/delete/rename operations. * * Operations are collected and then applied in three phases: deletes, writes, * renames. Within a single request duplicate operations targeting the same path * are not currently validated; the _last_ write wins for a file, and the final * mapping for each rename source path is used. Future improvements may add * canonicalisation/validation. * * Attributes: type: Discriminator literal `"diff"`. operations: Heterogeneous list * of file operations (see individual operation model docstrings for semantics). */ export interface RepoUpdateDiff { operations: Array< | RepoUpdateDiff.FileWriteOperation | RepoUpdateDiff.FileDeleteOperation | RepoUpdateDiff.FileRenameOperation >; type: 'diff'; } export namespace RepoUpdateDiff { /** * Create or overwrite a file with textual content. * * Used inside a :class:`RepoUpdateDiff`. The final content for a path is the value * from the last write operation targeting that path within the request (operations * are aggregated; order is not otherwise significant). * * Attributes: type: Discriminator literal `"write"`. filename: Target file path * (created if missing; parent dirs auto-created). content: UTF-8 text content. */ export interface FileWriteOperation { content: string; filename: string; type: 'write'; } /** * Delete a file or (recursively) a directory. * * If the referenced path does not exist the update request fails with 404. * * Attributes: type: Discriminator literal `"delete"`. filename: File or directory * path to remove. */ export interface FileDeleteOperation { filename: string; type: 'delete'; } /** * Rename (move) a file. * * Renames are applied after all writes and deletes have been processed to avoid * transient conflicts. The source path must exist at execution time or the request * fails with 404. Directory renames are not currently supported explicitly (only * existing paths that resolve to files are expected). * * Attributes: type: Discriminator literal `"rename"`. old_filename: Existing file * path. new_filename: Destination file path (created parent dirs as needed). */ export interface FileRenameOperation { new_filename: string; old_filename: string; type: 'rename'; } } export interface RepoUpdateGit { type: 'git'; url: string; branch?: string | null; } } export interface RepoListParams { created_after?: string | null; created_before?: string | null; filter_metadata?: string | null; order_by?: 'created_at' | 'updated_at'; order_descending?: boolean; page_size?: number; page_start?: number; } export interface RepoAgentParams { /** * Input parameters for the agent */ agent_inputs: { [key: string]: string }; /** * Name of the agent to run */ agent_name: string; /** * Whether to continue from previous chat history */ continue?: boolean; /** * Optional configuration overrides for agent execution */ overrides?: RepoAgentParams.Overrides | null; } export namespace RepoAgentParams { /** * Optional configuration overrides for agent execution */ export interface Overrides { /** * Maximum tokens for model output */ max_tokens?: number | null; /** * Maximum number of turns in the conversation */ max_turns?: number | null; /** * Model name to use for agent execution */ model_name?: string | null; /** * Number of retries for failed prompts */ prompt_retries?: number | null; /** * Timeout in seconds for prompt execution */ prompt_timeout?: number | null; /** * System prompt override */ system?: string | null; /** * List of tools to enable */ tools?: Array | null; /** * User prompt override */ user?: string | null; } } export interface RepoCloneParams { commit?: string | null; } export interface RepoEmbeddingStatusParams { branch?: string | null; hash?: string | null; } export interface RepoSearchParams { /** * Search query string */ query: string; } export declare namespace Repo { export { type File as File, type RepoInfo as RepoInfo, type RepoMetadata as RepoMetadata, type RepoRetrieveResponse as RepoRetrieveResponse, type RepoListResponse as RepoListResponse, type RepoAgentResponse as RepoAgentResponse, type RepoCloneResponse as RepoCloneResponse, type RepoEmbeddingStatusResponse as RepoEmbeddingStatusResponse, type RepoCreateParams as RepoCreateParams, type RepoRetrieveParams as RepoRetrieveParams, type RepoUpdateParams as RepoUpdateParams, type RepoListParams as RepoListParams, type RepoAgentParams as RepoAgentParams, type RepoCloneParams as RepoCloneParams, type RepoEmbeddingStatusParams as RepoEmbeddingStatusParams, type RepoSearchParams as RepoSearchParams, }; export { type FileDownloadResponse as FileDownloadResponse, type FileDeleteParams as FileDeleteParams, type FileDownloadParams as FileDownloadParams, type FileUploadParams as FileUploadParams, }; }