import type { AgentListParams, AgentState, AgentUpdateParams, } from "@letta-ai/letta-client/resources/agents/agents"; import type { Message } from "@letta-ai/letta-client/resources/agents/messages"; import type { Conversation, ConversationCreateParams, ConversationForkParams, ConversationListParams, ConversationUpdateParams, } from "@letta-ai/letta-client/resources/conversations/conversations"; import type { MessageListParams } from "@letta-ai/letta-client/resources/conversations/messages"; import type { ListMessagesResult, ListModelsResult } from "./types.js"; /** Agent state returned by either the Cloud API or Letta Code app-server. */ export type LettaAgent = AgentState; /** Conversation state returned by either the Cloud API or Letta Code app-server. */ export type LettaConversation = Conversation; /** Raw Letta API message returned from conversation history. */ export type LettaConversationMessage = Message; type Present = Exclude; export interface ListAgentsOptions { before?: Present; after?: Present; limit?: Present; order?: "asc" | "desc"; orderBy?: "createdAt" | "lastRunCompletion"; /** Search agent names. */ query?: Present; /** Match one exact agent name. */ name?: Present; tags?: Present; matchAllTags?: Present; /** Relationships to hydrate in each returned agent. */ include?: Present; } export interface UpdateAgentOptions { name?: AgentUpdateParams["name"]; description?: AgentUpdateParams["description"]; model?: AgentUpdateParams["model"]; modelSettings?: AgentUpdateParams["model_settings"]; system?: AgentUpdateParams["system"]; tags?: AgentUpdateParams["tags"]; hidden?: AgentUpdateParams["hidden"]; contextWindowLimit?: AgentUpdateParams["context_window_limit"]; } export interface ListConversationsOptions { agentId?: Present; after?: Present; limit?: Present; order?: Present; orderBy?: "createdAt" | "lastRunCompletion" | "lastMessageAt"; archiveStatus?: Present; summarySearch?: Present; } export interface CreateConversationOptions { agentId: ConversationCreateParams["agent_id"]; summary?: ConversationCreateParams["summary"]; description?: ConversationCreateParams["description"]; model?: ConversationCreateParams["model"]; modelSettings?: ConversationCreateParams["model_settings"]; contextWindowLimit?: ConversationCreateParams["context_window_limit"]; hidden?: ConversationCreateParams["hidden"]; } export interface UpdateConversationOptions { summary?: ConversationUpdateParams["summary"]; description?: ConversationUpdateParams["description"]; model?: ConversationUpdateParams["model"]; modelSettings?: ConversationUpdateParams["model_settings"]; contextWindowLimit?: ConversationUpdateParams["context_window_limit"]; archived?: ConversationUpdateParams["archived"]; } export interface ForkConversationOptions { /** Include source messages through this message, inclusive. */ messageId?: Present; /** Hide the fork from normal conversation listings. */ hidden?: Present; } export interface ConversationMessagesOptions { /** Return messages before this message ID (cursor for older pages, regardless of `order`). */ before?: Present; /** Return messages after this message ID (cursor for newer pages, regardless of `order`). */ after?: Present; /** Sort order of the returned page. Defaults to "desc" (newest first). */ order?: "asc" | "desc"; limit?: Present; } export type ConversationMessagesResult = ListMessagesResult; export type AgentRepositoryPermissions = "read" | "read_write"; export type AgentRepositoryRecompileTarget = "default" | false; /** A repository relationship persisted on an agent. */ export interface AgentRepository { id: string; name: string; isPrimary: boolean; permissions: AgentRepositoryPermissions; } export interface AttachAgentRepositoryOptions { /** Access granted to the agent. Defaults to `read_write` on the server. */ permissions?: AgentRepositoryPermissions; /** Recompile the agent's default conversation after attachment. Defaults to `default`. */ recompile?: AgentRepositoryRecompileTarget; } export interface DetachAgentRepositoryOptions { /** Recompile the agent's default conversation after detachment. Defaults to `default`. */ recompile?: AgentRepositoryRecompileTarget; } /** Persistent agent-repository relationships. Available on the Cloud backend. */ export interface AgentRepositoriesClient { list(agentId: string): Promise; /** * Persistently attach a repository, wait for the relationship to become * visible, then recompile the agent's default conversation unless disabled. * If recompilation fails, the relationship remains attached and retrying is safe. */ attach( agentId: string, repositoryId: string, options?: AttachAgentRepositoryOptions, ): Promise; /** * Persistently detach a repository, wait for the relationship to disappear, * then recompile the agent's default conversation unless disabled. If * recompilation fails, the relationship remains detached and retrying is safe. */ detach( agentId: string, repositoryId: string, options?: DetachAgentRepositoryOptions, ): Promise; } export interface AgentsClient { /** Persistent repository relationships for this agent. Cloud only. */ readonly repositories: AgentRepositoriesClient; list(options?: ListAgentsOptions): Promise; retrieve(agentId: string): Promise; update( agentId: string, options: UpdateAgentOptions, ): Promise; delete(agentId: string): Promise; } export interface ModelsClient { /** * List the model catalog without opening a session. * * Uses the same normalized result shape as `session.listModels()`, including * availability and BYOK-alias metadata when the backend provides it. */ list(): Promise; } export interface ConversationsClient { list( options?: ListConversationsOptions, ): Promise; retrieve(conversationId: string): Promise; create(options: CreateConversationOptions): Promise; update( conversationId: string, options: UpdateConversationOptions, ): Promise; /** * Create a persistent conversation from the source's in-context history. * Use `update()` to change the fork's model. Archive a temporary fork with * `update(fork.id, { archived: true })` when it is done. */ fork( sourceConversationId: string, options?: ForkConversationOptions, ): Promise; listMessages( conversationId: string, options?: ConversationMessagesOptions, ): Promise; }