
import { BaseEvent } from "@ag-ui/client";

//#region src/v2/runtime/intelligence-platform/client.d.ts
/**
 * Client for the CopilotKit Intelligence Platform REST API.
 *
 * Construct the client once and pass it to any consumers that need it
 * (e.g. `CopilotRuntime`, `IntelligenceAgentRunner`):
 *
 * ```ts
 * import { CopilotKitIntelligence, CopilotRuntime } from "@copilotkit/runtime";
 *
 * const intelligence = new CopilotKitIntelligence({
 *   apiUrl: "https://api.copilotkit.ai",
 *   wsUrl: "wss://api.copilotkit.ai",
 *   apiKey: process.env.COPILOTKIT_API_KEY!,
 *   organizationId: process.env.COPILOTKIT_ORGANIZATION_ID!,
 * });
 *
 * const runtime = new CopilotRuntime({
 *   agents,
 *   intelligence,
 * });
 * ```
 */
/** Payload passed to `onThreadDeleted` listeners. */
interface ThreadDeletedPayload {
  threadId: string;
  userId: string;
  agentId: string;
}
interface CopilotKitIntelligenceConfig {
  /** Base URL of the intelligence platform API, e.g. "https://api.copilotkit.ai" */
  apiUrl: string;
  /** Intelligence websocket base URL. Runner and client socket URLs are derived from this. */
  wsUrl: string;
  /** API key for authenticating with the intelligence platform */
  apiKey: string;
  /** Organization identifier used for self-hosted Intelligence instances */
  organizationId: string;
  /**
   * Initial listener invoked after a thread is created.
   * Prefer {@link CopilotKitIntelligence.onThreadCreated} for multiple listeners.
   */
  onThreadCreated?: (thread: ThreadSummary) => void;
  /**
   * Initial listener invoked after a thread is updated.
   * Prefer {@link CopilotKitIntelligence.onThreadUpdated} for multiple listeners.
   */
  onThreadUpdated?: (thread: ThreadSummary) => void;
  /**
   * Initial listener invoked after a thread is deleted.
   * Prefer {@link CopilotKitIntelligence.onThreadDeleted} for multiple listeners.
   */
  onThreadDeleted?: (params: ThreadDeletedPayload) => void;
}
/**
 * Summary metadata for a single thread returned by the platform.
 *
 * This is the shape returned by list, get, create, and update operations.
 * It does not include the thread's message history — use
 * {@link CopilotKitIntelligence.getThreadMessages} for that.
 */
interface ThreadSummary {
  /** Platform-assigned unique identifier. */
  id: string;
  /** Human-readable display name, or `null` if the thread has not been named. */
  name: string | null;
  /** ISO-8601 timestamp of the most recent agent run on this thread. */
  lastRunAt?: string;
  /** ISO-8601 timestamp of the most recent metadata update. */
  lastUpdatedAt?: string;
  /** ISO-8601 timestamp when the thread was created. */
  createdAt?: string;
  /** ISO-8601 timestamp when the thread was last updated. */
  updatedAt?: string;
  /** Whether the thread has been archived. Archived threads are excluded from default list results. */
  archived?: boolean;
  /** The agent that owns this thread. */
  agentId?: string;
  /** The user who created this thread. */
  createdById?: string;
  /** The organization this thread belongs to. */
  organizationId?: string;
}
/** Response from listing threads for a user/agent pair. */
interface ListThreadsResponse {
  /** The matching threads, sorted by the platform's default ordering. */
  threads: ThreadSummary[];
  /** Join code for subscribing to realtime metadata updates for these threads. */
  joinCode: string;
  /** Short-lived token for authenticating the realtime subscription. */
  joinToken?: string;
  /** Opaque cursor for fetching the next page. `null` or absent when there are no more pages. */
  nextCursor?: string | null;
}
/**
 * Fields that can be updated on a thread via {@link CopilotKitIntelligence.updateThread}.
 *
 * Additional platform-specific fields can be passed as extra keys and will be
 * forwarded to the PATCH request body.
 */
interface UpdateThreadRequest {
  /** New human-readable display name for the thread. */
  name?: string;
  [key: string]: unknown;
}
/** Parameters for creating a new thread via {@link CopilotKitIntelligence.createThread}. */
interface CreateThreadRequest {
  /** Client-generated unique identifier for the new thread. */
  threadId: string;
  /** The user creating the thread. Used for authorization and scoping. */
  userId: string;
  /** The agent this thread belongs to. */
  agentId: string;
  /** Optional initial display name. If omitted, the thread is unnamed until explicitly renamed. */
  name?: string;
}
/** Credentials returned when locking or joining a thread's realtime channel. */
interface ThreadConnectionResponse {
  /** Short-lived token for authenticating the Phoenix channel join. */
  joinToken: string;
  /** Optional join code that can be shared with other clients to join the same channel. */
  joinCode?: string;
  /** Lock metadata echoed back by the platform. */
  lock?: ThreadLockInfo;
}
interface SubscribeToThreadsRequest {
  userId: string;
}
interface SubscribeToThreadsResponse {
  joinToken: string;
}
interface ConnectThreadBootstrapResponse {
  mode: "bootstrap";
  latestEventId: string | null;
  events: BaseEvent[];
}
interface ConnectThreadLiveResponse {
  mode: "live";
  joinToken: string;
  joinFromEventId: string | null;
  events: BaseEvent[];
}
type ConnectThreadResponse = ConnectThreadBootstrapResponse | ConnectThreadLiveResponse | null;
/** A single message within a thread's persisted history. */
interface ThreadMessage {
  /** Unique identifier for this message. */
  id: string;
  /** Message role, e.g. `"user"`, `"assistant"`, `"tool"`. */
  role: string;
  /** Text content of the message. May be absent for tool-call-only messages. */
  content?: string;
  /** Tool calls initiated by this message (assistant role only). */
  toolCalls?: Array<{
    id: string;
    name: string; /** JSON-encoded arguments passed to the tool. */
    args: string;
  }>;
  /** For tool-result messages, the ID of the tool call this message responds to. */
  toolCallId?: string;
}
/** Response from {@link CopilotKitIntelligence.getThreadMessages}. */
interface ThreadMessagesResponse {
  messages: ThreadMessage[];
}
interface AcquireThreadLockRequest {
  threadId: string;
  runId: string;
  userId: string;
  /** Custom Redis key prefix for the lock (default: "thread"). */
  lockKeyPrefix?: string;
  /** Lock TTL in seconds. When set, the lock auto-expires after this duration. */
  ttlSeconds?: number;
}
interface RenewThreadLockRequest {
  threadId: string;
  runId: string;
  /** New TTL to set on the lock in seconds. */
  ttlSeconds: number;
  /** Must match the prefix used when acquiring. */
  lockKeyPrefix?: string;
}
interface RenewThreadLockResponse {
  ttlSeconds: number;
}
interface ThreadLockInfo {
  key: string;
  ttlSeconds: number | null;
}
declare class CopilotKitIntelligence {
  #private;
  constructor(config: CopilotKitIntelligenceConfig);
  /**
   * Register a listener invoked whenever a thread is created.
   *
   * Multiple listeners can be registered. Each call returns an unsubscribe
   * function that removes the listener when called.
   *
   * @param callback - Receives the newly created {@link ThreadSummary}.
   * @returns A function that removes this listener when called.
   *
   * @example
   * ```ts
   * const unsubscribe = intelligence.onThreadCreated((thread) => {
   *   console.log("Thread created:", thread.id);
   * });
   * // later…
   * unsubscribe();
   * ```
   */
  onThreadCreated(callback: (thread: ThreadSummary) => void): () => void;
  /**
   * Register a listener invoked whenever a thread is updated (including archive).
   *
   * Multiple listeners can be registered. Each call returns an unsubscribe
   * function that removes the listener when called.
   *
   * @param callback - Receives the updated {@link ThreadSummary}.
   * @returns A function that removes this listener when called.
   */
  onThreadUpdated(callback: (thread: ThreadSummary) => void): () => void;
  /**
   * Register a listener invoked whenever a thread is deleted.
   *
   * Multiple listeners can be registered. Each call returns an unsubscribe
   * function that removes the listener when called.
   *
   * @param callback - Receives the {@link ThreadDeletedPayload} identifying
   *   the deleted thread.
   * @returns A function that removes this listener when called.
   */
  onThreadDeleted(callback: (params: ThreadDeletedPayload) => void): () => void;
  ɵgetApiUrl(): string;
  ɵgetRunnerWsUrl(): string;
  ɵgetClientWsUrl(): string;
  ɵgetOrganizationId(): string;
  ɵgetRunnerAuthToken(): string;
  /**
   * List all non-archived threads for a given user and agent.
   *
   * @param params.userId - User whose threads to list.
   * @param params.agentId - Agent whose threads to list.
   * @returns The thread list along with realtime subscription credentials.
   * @throws {@link PlatformRequestError} on non-2xx responses.
   */
  listThreads(params: {
    userId: string;
    agentId: string;
    includeArchived?: boolean;
    limit?: number;
    cursor?: string;
  }): Promise<ListThreadsResponse>;
  ɵsubscribeToThreads(params: SubscribeToThreadsRequest): Promise<SubscribeToThreadsResponse>;
  /**
   * Update thread metadata (e.g. name).
   *
   * Triggers the `onThreadUpdated` lifecycle callback on success.
   *
   * @returns The updated thread summary.
   * @throws {@link PlatformRequestError} on non-2xx responses.
   */
  updateThread(params: {
    threadId: string;
    userId: string;
    agentId: string;
    updates: UpdateThreadRequest;
  }): Promise<ThreadSummary>;
  /**
   * Create a new thread on the platform.
   *
   * Triggers the `onThreadCreated` lifecycle callback on success.
   *
   * @returns The newly created thread summary.
   * @throws {@link PlatformRequestError} with status 409 if a thread with the
   *   same `threadId` already exists.
   */
  createThread(params: CreateThreadRequest): Promise<ThreadSummary>;
  /**
   * Fetch a single thread by ID.
   *
   * @returns The thread summary.
   * @throws {@link PlatformRequestError} with status 404 if the thread does
   *   not exist.
   */
  getThread(params: {
    threadId: string;
  }): Promise<ThreadSummary>;
  /**
   * Get an existing thread or create it if it does not exist.
   *
   * Handles the race where a concurrent request creates the thread between
   * the initial 404 and the subsequent `createThread` call by catching the
   * 409 Conflict and retrying the get.
   *
   * Triggers the `onThreadCreated` lifecycle callback when a new thread is
   * created.
   *
   * @returns An object containing the thread and a `created` flag indicating
   *   whether the thread was newly created (`true`) or already existed (`false`).
   * @throws {@link PlatformRequestError} on non-2xx responses other than
   *   404 (get) and 409 (create race).
   */
  getOrCreateThread(params: CreateThreadRequest): Promise<{
    thread: ThreadSummary;
    created: boolean;
  }>;
  /**
   * Fetch the full message history for a thread.
   *
   * @returns All persisted messages in chronological order.
   * @throws {@link PlatformRequestError} on non-2xx responses.
   */
  getThreadMessages(params: {
    threadId: string;
  }): Promise<ThreadMessagesResponse>;
  /**
   * Mark a thread as archived.
   *
   * Archived threads are excluded from {@link listThreads} results.
   * Triggers the `onThreadUpdated` lifecycle callback on success.
   *
   * @throws {@link PlatformRequestError} on non-2xx responses.
   */
  archiveThread(params: {
    threadId: string;
    userId: string;
    agentId: string;
  }): Promise<void>;
  /**
   * Permanently delete a thread and its message history.
   *
   * This is irreversible. Triggers the `onThreadDeleted` lifecycle callback
   * on success.
   *
   * @throws {@link PlatformRequestError} on non-2xx responses.
   */
  deleteThread(params: {
    threadId: string;
    userId: string;
    agentId: string;
  }): Promise<void>;
  ɵacquireThreadLock(params: AcquireThreadLockRequest): Promise<ThreadConnectionResponse>;
  ɵrenewThreadLock(params: RenewThreadLockRequest): Promise<RenewThreadLockResponse>;
  ɵgetActiveJoinCode(params: {
    threadId: string;
    userId: string;
  }): Promise<ThreadConnectionResponse>;
  ɵconnectThread(params: {
    threadId: string;
    userId: string;
    lastSeenEventId?: string | null;
  }): Promise<ConnectThreadResponse>;
}
//#endregion
export { CopilotKitIntelligence, CopilotKitIntelligenceConfig, CreateThreadRequest, ListThreadsResponse, SubscribeToThreadsRequest, SubscribeToThreadsResponse, ThreadSummary, UpdateThreadRequest };
//# sourceMappingURL=client.d.cts.map