import type { Conversation, Message } from '../types.js'; export type AuthenticatedFetchFn = (url: string, init?: RequestInit) => Promise; /** * REST API client for conversation CRUD and message history. * * Gateway REST responses use snake_case and some types do not match the * agentic-sdk camelCase public types. This client performs all normalization * internally so callers always see the SDK-native shapes. */ export declare class ConversationAPI { private readonly authenticatedFetch; private readonly httpBase; constructor(gatewayUrl: string, authenticatedFetch: AuthenticatedFetchFn); listConversations(): Promise; createConversation(title?: string): Promise; deleteConversation(conversationId: string): Promise; renameConversation(conversationId: string, title: string): Promise; /** 置顶(spec §3.4)。幂等;不带 body、不设 Content-Type。 */ pinConversation(conversationId: string): Promise<{ pinnedAt: number; }>; /** 取消置顶(spec §3.4)。幂等。 */ unpinConversation(conversationId: string): Promise; getMessages(conversationId: string, options?: { before?: number; limit?: number; }): Promise<{ messages: Message[]; hasMore: boolean; oldestSequenceNumber: number | null; }>; } /** * Walk the raw REST history payload, transforming gateway storage shape * (one row per LLM iteration + role:'tool' rows for each tool result) into * the SDK consumer shape (one Message per logical turn, toolCalls fully * populated). Two passes: * * 1. Tool-result merge — each `role:'tool'` message's content is folded * into the matching prior assistant.toolCalls[].result, the standalone * tool entry dropped (#21). Mirrors streaming `updateToolCall`. * #728 exception: a successful SendUserMessage (brief) tool_result is * NOT folded — the card is removed and the brief message is synthesized * as a standalone user-visible assistant Message (see below). * * 2. Consecutive-assistant merge — multi-iteration turns (assistant → * tool → assistant → tool → assistant) collapse into one Message: * content concatenated, toolCalls concatenated in order. Mirrors * streaming where `addToolCall` / `appendContent` keep folding into * the same status='streaming' assistant until `finish` (no `finish` * between LLM iterations within one user turn). * * Orphan tool messages (no matching tool_call_id in any prior assistant) * are dropped with a console.warn — `Message['role']` doesn't include * 'tool', so surfacing them would defeat the purpose. #728 exception: * orphans matching the full brief success contract are synthesized (page * boundaries deterministically split caller/tool rows). * * 🔴 **公开导出面**(optima-gateway#1585 Task 7):optima-gateway 的 gateway-core 用它做**跨仓 * 契约测试** —— 把落库行走完自己的出口链(COO 历史过滤器 → `projectMessageForWire`)之后喂给 * 本函数,断言「过滤不新增无结果工具卡」「brief 气泡正文逐字保留」「抹正文不产生新空气泡」。 * * 为什么这一半搬不进 `@optima-chat/gateway-protocol`:那个包是**纯常量与类型**,而这里是**归一 * 逻辑**(tool→caller 配对、连续 assistant 合并、孤儿丢弃、#728 brief 合成)。COO task-conv 正则 * 那一半已经提升进协议包(两侧 import 同一个源,optima-gateway#2041),这一半只能靠 SDK 开导出面。 * * ⚠️ 本次**只加 `export` 关键字,函数体一字未动**。 * ⚠️ 同时从 `src/index.ts` 与 `src/client/index.ts` **两处**导出:非 React 消费者(如 gateway-core * 的 `environment: 'node'` vitest)必须走 `/client` 子路径,从根入口会拉起 ChatProvider + React。 */ export declare function mergeAndMap(rawList: unknown[], conversationId: string): Message[]; //# sourceMappingURL=conversation-api.d.ts.map