@athenaintel/react 0.55.0 → 0.56.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -0
- package/dist/agent-runtime/src/answer-label.cjs +8 -2
- package/dist/agent-runtime/src/answer-label.cjs.map +1 -1
- package/dist/agent-runtime/src/answer-label.d.ts +10 -4
- package/dist/agent-runtime/src/answer-label.js +8 -2
- package/dist/agent-runtime/src/answer-label.js.map +1 -1
- package/dist/agent-runtime/src/deep-agent-transport-recipe.cjs +6 -3
- package/dist/agent-runtime/src/deep-agent-transport-recipe.cjs.map +1 -1
- package/dist/agent-runtime/src/deep-agent-transport-recipe.js +6 -3
- package/dist/agent-runtime/src/deep-agent-transport-recipe.js.map +1 -1
- package/dist/agent-runtime/src/edit-command.cjs +40 -19
- package/dist/agent-runtime/src/edit-command.cjs.map +1 -1
- package/dist/agent-runtime/src/edit-command.d.ts +2 -0
- package/dist/agent-runtime/src/edit-command.js +41 -20
- package/dist/agent-runtime/src/edit-command.js.map +1 -1
- package/dist/agent-runtime/src/generated/runconfig-contract.cjs +8 -0
- package/dist/agent-runtime/src/generated/runconfig-contract.cjs.map +1 -1
- package/dist/agent-runtime/src/generated/runconfig-contract.d.ts +9 -0
- package/dist/agent-runtime/src/generated/runconfig-contract.js +8 -0
- package/dist/agent-runtime/src/generated/runconfig-contract.js.map +1 -1
- package/dist/agent-runtime/src/history-store.cjs +426 -0
- package/dist/agent-runtime/src/history-store.cjs.map +1 -0
- package/dist/agent-runtime/src/history-store.d.ts +282 -0
- package/dist/agent-runtime/src/history-store.js +426 -0
- package/dist/agent-runtime/src/history-store.js.map +1 -0
- package/dist/agent-runtime/src/index.d.ts +4 -4
- package/dist/agent-runtime/src/message-window.cjs +43 -5
- package/dist/agent-runtime/src/message-window.cjs.map +1 -1
- package/dist/agent-runtime/src/message-window.d.ts +26 -2
- package/dist/agent-runtime/src/message-window.js +44 -6
- package/dist/agent-runtime/src/message-window.js.map +1 -1
- package/dist/agent-runtime/src/offline-status.cjs.map +1 -1
- package/dist/agent-runtime/src/offline-status.d.ts +85 -4
- package/dist/agent-runtime/src/offline-status.js.map +1 -1
- package/dist/agent-runtime/src/runtime.d.ts +1 -0
- package/dist/agent-runtime/src/tool-metadata.cjs +8 -0
- package/dist/agent-runtime/src/tool-metadata.cjs.map +1 -1
- package/dist/agent-runtime/src/tool-metadata.js +8 -0
- package/dist/agent-runtime/src/tool-metadata.js.map +1 -1
- package/dist/agent-runtime/src/use-deep-agent-thread.cjs +8 -16
- package/dist/agent-runtime/src/use-deep-agent-thread.cjs.map +1 -1
- package/dist/agent-runtime/src/use-deep-agent-thread.d.ts +1 -9
- package/dist/agent-runtime/src/use-deep-agent-thread.js +9 -17
- package/dist/agent-runtime/src/use-deep-agent-thread.js.map +1 -1
- package/dist/agent-runtime/src/use-deep-agent-window-sync.cjs +86 -79
- package/dist/agent-runtime/src/use-deep-agent-window-sync.cjs.map +1 -1
- package/dist/agent-runtime/src/use-deep-agent-window-sync.d.ts +2 -27
- package/dist/agent-runtime/src/use-deep-agent-window-sync.js +89 -82
- package/dist/agent-runtime/src/use-deep-agent-window-sync.js.map +1 -1
- package/dist/chat/super-grouping/CollapsibleGroup.cjs +1 -1
- package/dist/chat/super-grouping/CollapsibleGroup.cjs.map +1 -1
- package/dist/chat/super-grouping/CollapsibleGroup.d.ts +6 -5
- package/dist/chat/super-grouping/CollapsibleGroup.js +1 -1
- package/dist/chat/super-grouping/CollapsibleGroup.js.map +1 -1
- package/dist/chat/super-grouping/earlier-steps-button.cjs +5 -6
- package/dist/chat/super-grouping/earlier-steps-button.cjs.map +1 -1
- package/dist/chat/super-grouping/earlier-steps-button.d.ts +6 -6
- package/dist/chat/super-grouping/earlier-steps-button.js +5 -6
- package/dist/chat/super-grouping/earlier-steps-button.js.map +1 -1
- package/dist/chat/super-grouping/toolkit-map.cjs +1 -0
- package/dist/chat/super-grouping/toolkit-map.cjs.map +1 -1
- package/dist/chat/super-grouping/toolkit-map.js +1 -0
- package/dist/chat/super-grouping/toolkit-map.js.map +1 -1
- package/dist/chat/super-grouping/use-turn-steps.cjs +3 -3
- package/dist/chat/super-grouping/use-turn-steps.js +1 -1
- package/dist/chat-ui/thread/statewire-history-edge.cjs +0 -4
- package/dist/chat-ui/thread/statewire-history-edge.cjs.map +1 -1
- package/dist/chat-ui/thread/statewire-history-edge.d.ts +5 -7
- package/dist/chat-ui/thread/statewire-history-edge.js +1 -5
- package/dist/chat-ui/thread/statewire-history-edge.js.map +1 -1
- package/dist/provider/AthenaProvider.cjs +12 -11
- package/dist/provider/AthenaProvider.cjs.map +1 -1
- package/dist/provider/AthenaProvider.js +11 -10
- package/dist/provider/AthenaProvider.js.map +1 -1
- package/dist/provider/statewire-window-context.cjs.map +1 -1
- package/dist/provider/statewire-window-context.d.ts +8 -8
- package/dist/provider/statewire-window-context.js.map +1 -1
- package/dist/react/package.json.cjs +1 -1
- package/dist/react/package.json.js +1 -1
- package/dist/runtime/useAthenaStatewireRuntime.cjs +0 -2
- package/dist/runtime/useAthenaStatewireRuntime.cjs.map +1 -1
- package/dist/runtime/useAthenaStatewireRuntime.d.ts +5 -5
- package/dist/runtime/useAthenaStatewireRuntime.js +0 -2
- package/dist/runtime/useAthenaStatewireRuntime.js.map +1 -1
- package/package.json +1 -1
- package/dist/agent-runtime/src/history-pages.cjs +0 -279
- package/dist/agent-runtime/src/history-pages.cjs.map +0 -1
- package/dist/agent-runtime/src/history-pages.d.ts +0 -252
- package/dist/agent-runtime/src/history-pages.js +0 -279
- package/dist/agent-runtime/src/history-pages.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"history-store.cjs","sources":["../../../../agent-runtime/src/history-store.ts"],"sourcesContent":["import type { LangChainMessage } from '@assistant-ui/react-langgraph';\nimport {\n DEEP_AGENT_HISTORY_PAGE_COMMAND,\n DEEP_AGENT_HISTORY_PAGE_PROTOCOL_VERSION,\n DEEP_AGENT_MAIN_NS,\n DEEP_AGENT_MAX_HISTORY_PAGE_STEPS,\n DEEP_AGENT_MAX_HISTORY_PAGE_TURNS,\n DEEP_AGENT_MESSAGE_HISTORY_HEADER,\n DEEP_AGENT_MESSAGE_HISTORY_PAGED,\n} from './generated/runconfig-contract';\nimport { QUIET_TOOL_NAMES } from './tool-names';\n\n/**\n * Older history on the client — the client half of agora's `history/page`.\n *\n * On a host whose `protocol` lane advertises\n * `DEEP_AGENT_HISTORY_PAGE_PROTOCOL_VERSION`, an attach states only its head\n * (and its lane follows) on `athena/interest`, and says on its attach headers\n * that it keeps older history itself ({@link withDeclaredPagedHistory}).\n * Older messages come back from the one-shot `history/page` command\n * (`{before, turns}` answers whole turns ending before `before`, oldest\n * first; a long turn rides as its prompt and answer, its steps counted) and\n * live here, never in the attach's view, so the interest document stays the\n * same small size however deep the viewer scrolls, and scrolling back moves\n * the page anchor instead of growing a list.\n *\n * The store keeps each message's parent as the reader sees the transcript,\n * and which message starts it. Every read of the interest window records the\n * parents its live chain shows, so a message that slides out of the head (the\n * host holds the head down to its floor for at most\n * `DEEP_AGENT_MAX_HELD_HEAD` messages) stays reachable here, and a re-attach\n * on any pod finds what was loaded. A page records the parents it shows (a\n * summarized turn's answer follows its prompt). A host parent never changes:\n * an edit or rewind mints new ids, a branch switch keeps each id's parent.\n * {@link readDeepAgentMessageWindow} joins the store under the live chain by\n * walking parents back from its first message, so only ancestors of the live\n * view are ever shown: a rewound tail is never reached.\n *\n * A summarized turn's left-out steps come back on request (`history/page`\n * with its `turn`, newest first, {@link DeepAgentHistoryStore.loadSteps}) and\n * are spliced in where the page left them out: between the turn's prompt and\n * the first message shown after it. The join marks each summarized turn on\n * its first reply message ({@link DEEP_AGENT_TURN_STEPS_KEY}), so a renderer\n * reads its exact counts (\"Used 313 tools\") and can offer the steps still\n * left out.\n *\n * One store per conversation, shared by every reader in the JS context (the\n * converter, the edit path, the history edge), so they agree on what is\n * loaded. The registry keeps the most recently read\n * {@link DEEP_AGENT_HISTORY_STORE_LIMIT} conversations.\n */\n\n/** Conversations whose stores the registry keeps (least recently read evicted). */\nexport const DEEP_AGENT_HISTORY_STORE_LIMIT = 8;\n\n/** Steps of one summarized turn one `history/page` asks for. */\nexport const DEEP_AGENT_TURN_STEPS_PAGE = 100;\n\n/** `additional_kwargs` key the join marks a summarized turn's first reply message with. */\nexport const DEEP_AGENT_TURN_STEPS_KEY = 'athena_turn_steps';\n\n/**\n * What a summarized turn's page left out (`steps` on a `history/page` turn):\n * counted over the left-out messages only, so a reader adds what it holds.\n */\nexport interface DeepAgentHistoryTurnSteps {\n /** Messages left out. */\n count: number;\n /** Tool calls among the messages left out. */\n tools: number;\n /** Of which `task` delegations. */\n delegations: number;\n /** The oldest and newest message left out. */\n first: string | null;\n last: string | null;\n}\n\n/** A turn a page summarized: what it left out, and where. */\nexport interface DeepAgentHistorySummarizedTurn {\n steps: DeepAgentHistoryTurnSteps;\n /**\n * The message the left-out steps end before: the first the page shows after\n * the turn's prompt, or — for a turn cut short by what the asker held — the\n * message the page was asked before.\n */\n resume: string;\n}\n\n/** One `history/page` answer, read off the wire. */\nexport interface DeepAgentHistoryPage {\n /** The message the page ends before. */\n before: string;\n /** Oldest first. */\n messages: LangChainMessage[];\n /** Whether the transcript holds messages older than the page. */\n moreBefore: boolean;\n /** The page's summarized turns, by their first message's id. */\n summarized?: ReadonlyMap<string, DeepAgentHistorySummarizedTurn>;\n}\n\n/** One `history/page` answer to `{turn, before, steps}`: a summarized turn's steps. */\nexport interface DeepAgentTurnStepsPage {\n turn: string;\n /** Steps, oldest first. */\n messages: LangChainMessage[];\n /** Older steps of the turn remain. */\n moreBefore: boolean;\n}\n\n/** What the store holds older than one message. */\nexport interface DeepAgentHistoryOlder {\n /** Ids, oldest first, ending right before the message asked about. */\n ids: string[];\n messages: LangChainMessage[];\n /** Whether anything older than `ids[0]` (or the message itself) may exist. */\n hasOlder: boolean;\n}\n\n/**\n * The marker the join puts on a summarized turn's first reply message: the\n * turn's steps not shown yet, so a renderer reads exact counts and knows\n * whether opening it has steps to fetch ({@link loadDeepAgentTurnSteps}).\n */\nexport interface DeepAgentTurnStepsMarker {\n /** The turn's first message: the id its steps are paged by. */\n turn: string;\n /** The conversation it belongs to (its history store). */\n thread: string;\n /** Steps not loaded yet. */\n hiddenSteps: number;\n /** Tool calls among them. */\n hiddenTools: number;\n /** Of which `task` delegations. */\n hiddenDelegations: number;\n /** The oldest step loaded; `undefined` while none is. */\n before: string | undefined;\n}\n\n/** How the store asks the host: the thread's `sendCommand` (its answer, the command's payload). */\nexport type DeepAgentHistorySend = (command: HistoryPageCommand | TurnStepsCommand) => unknown;\n\nexport interface DeepAgentHistoryStore {\n /**\n * Whether the host refused `history/page` although its `protocol` lane\n * advertises it (a host without the command): readers then read the live\n * view alone and page by interest, until {@link markServed}.\n */\n readonly unserved: boolean;\n /** The connection the refusal came on (`markUnserved`): a later one may land on a host that serves it. */\n readonly unservedBy: unknown;\n /** Bumped on every change readers can see (a page, steps, the unserved flag). */\n readonly version: number;\n markUnserved(connection?: unknown): void;\n markServed(): void;\n /**\n * Record what a live chain shows: each entry's parent is the one before it,\n * and with `startsTranscript` its first entry has none. Messages are kept by\n * id (the newest form seen). Silent: a live chain changes nothing its own\n * reader shows.\n */\n recordChain(\n ids: readonly string[],\n messages: ReadonlyMap<string, LangChainMessage>,\n startsTranscript: boolean\n ): void;\n /**\n * Take in one page; notifies. `false` for an empty page that told nothing\n * new. A page's messages are the transcript as the reader sees it: a\n * summarized turn's answer follows its prompt, its steps left out.\n */\n addPage(page: DeepAgentHistoryPage): boolean;\n /**\n * Take in a summarized turn's older steps, spliced in where its page left\n * them out; notifies. `false` for a turn the store does not hold.\n */\n addSteps(page: DeepAgentTurnStepsPage): boolean;\n /** What a summarized turn's page left out, by the turn's first message id. */\n turnSteps(turnId: string): DeepAgentHistoryTurnSteps | undefined;\n /** Everything the store holds older than `id`, walking parents back. */\n olderThan(id: string): DeepAgentHistoryOlder;\n /** The host parent of `id`: `null` at the transcript's start, `undefined` while unknown. */\n parentOf(id: string): string | null | undefined;\n /**\n * `messages` (a transcript as a reader shows it, oldest first) with each\n * summarized turn's marker on its first reply message\n * ({@link DEEP_AGENT_TURN_STEPS_KEY}); the same array when none applies.\n */\n markTurns(threadId: string, messages: LangChainMessage[]): LangChainMessage[];\n /** Whether a steps request for the turn is in flight — the loader's dedupe. */\n isLoadingSteps(turn: string): boolean;\n /**\n * Fetches a summarized turn's next older steps (`history/page` with its\n * `turn`) into the store. A turn already loading, unknown, or with no steps\n * left is a no-op. Rejects with the host's refusal, or when the answer is\n * not a page this client reads.\n */\n loadSteps(options: { send: DeepAgentHistorySend; turn: string; steps?: number }): Promise<void>;\n subscribe(listener: () => void): () => void;\n}\n\ninterface SummarizedTurnState extends DeepAgentHistorySummarizedTurn {\n /** The message the page showed right after the gap; `resume` moves down as steps load. */\n shownAfter: string;\n /** Steps loaded, oldest first. */\n loaded: LangChainMessage[];\n /** Older steps remain to load. */\n more: boolean;\n}\n\n/**\n * The tool calls among `messages` a converter shows. The host counts every\n * call of a turn; a quiet call (`QUIET_TOOL_NAMES`) never renders, so it stays\n * in the hidden count once loaded and the turn's total holds still as its\n * steps load.\n */\nfunction toolCalls(messages: readonly LangChainMessage[]): { tools: number; delegations: number } {\n let tools = 0;\n let delegations = 0;\n for (const message of messages) {\n if (message.type !== 'ai') continue;\n for (const call of message.tool_calls ?? []) {\n if (QUIET_TOOL_NAMES.has(call.name)) continue;\n tools += 1;\n if (call.name === 'task') delegations += 1;\n }\n }\n return { tools, delegations };\n}\n\n/** The marked copy of a message, reused while the message and its marker are the same. */\nconst markedCopies = new WeakMap<object, { key: string; message: LangChainMessage }>();\n\nfunction withMarker(message: LangChainMessage, marker: DeepAgentTurnStepsMarker): LangChainMessage {\n const key = `${marker.thread}\\u0000${marker.turn}\\u0000${marker.hiddenSteps}\\u0000${marker.hiddenTools}\\u0000${marker.hiddenDelegations}\\u0000${marker.before ?? ''}`;\n const cached = markedCopies.get(message);\n if (cached?.key === key) return cached.message;\n // Every wire message carries `additional_kwargs` in practice; the upstream\n // type leaves it off tool messages.\n const kwargs = (message as { additional_kwargs?: Record<string, unknown> }).additional_kwargs;\n const marked = {\n ...message,\n additional_kwargs: { ...(kwargs ?? {}), [DEEP_AGENT_TURN_STEPS_KEY]: marker },\n } as LangChainMessage;\n markedCopies.set(message, { key, message: marked });\n return marked;\n}\n\nexport function createDeepAgentHistoryStore(): DeepAgentHistoryStore {\n const parents = new Map<string, string | null>();\n const summaries = new Map<string, SummarizedTurnState>();\n /** A summarized turn by the messages its marker may start at: its prompt and where its steps resume. */\n const turnStarts = new Map<string, string>();\n const messages = new Map<string, LangChainMessage>();\n const loadingSteps = new Set<string>();\n const listeners = new Set<() => void>();\n let unserved = false;\n let unservedBy: unknown;\n let version = 0;\n const notify = () => {\n version += 1;\n for (const listener of [...listeners]) listener();\n };\n const marker = (threadId: string, turn: string, state: SummarizedTurnState): DeepAgentTurnStepsMarker => {\n // The host counts only the messages the page left out; of those, the\n // steps loaded since render on their own, so they leave the hidden count.\n const loaded = toolCalls(state.loaded);\n return {\n turn,\n thread: threadId,\n hiddenSteps: state.more ? Math.max(0, state.steps.count - state.loaded.length) : 0,\n hiddenTools: Math.max(0, state.steps.tools - loaded.tools),\n hiddenDelegations: Math.max(0, state.steps.delegations - loaded.delegations),\n before: state.loaded[0]?.id,\n };\n };\n const store: DeepAgentHistoryStore = {\n get unserved() {\n return unserved;\n },\n get unservedBy() {\n return unservedBy;\n },\n get version() {\n return version;\n },\n markUnserved(connection) {\n unservedBy = connection;\n if (unserved) return;\n unserved = true;\n notify();\n },\n markServed() {\n unservedBy = undefined;\n if (!unserved) return;\n unserved = false;\n notify();\n },\n recordChain(ids, chainMessages, startsTranscript) {\n for (let index = 0; index < ids.length; index += 1) {\n const id = ids[index] as string;\n if (index > 0) parents.set(id, ids[index - 1] as string);\n else if (startsTranscript) parents.set(id, null);\n const message = chainMessages.get(id);\n if (message !== undefined) messages.set(id, message);\n }\n },\n addPage({ before, messages: page, moreBefore, summarized }) {\n let changed = false;\n const setParent = (id: string, parent: string | null) => {\n if (parents.get(id) === parent) return;\n parents.set(id, parent);\n changed = true;\n };\n const ids: string[] = [];\n for (const message of page) {\n if (typeof message.id !== 'string' || !message.id) continue;\n ids.push(message.id);\n if (messages.get(message.id) !== message) {\n messages.set(message.id, message);\n changed = true;\n }\n }\n for (const [index, id] of ids.entries()) {\n if (index > 0) setParent(id, ids[index - 1] as string);\n else if (!moreBefore) setParent(id, null);\n else if (parents.get(id) === null) {\n // The host says more lies before it: a remembered start was wrong.\n parents.delete(id);\n changed = true;\n }\n }\n const last = ids.at(-1);\n if (last !== undefined) setParent(before, last);\n else if (!moreBefore) setParent(before, null);\n for (const [turn, summary] of summarized ?? []) {\n const held = summaries.get(turn);\n if (held === undefined) {\n summaries.set(turn, {\n ...summary,\n shownAfter: summary.resume,\n loaded: [],\n more: summary.steps.count > 0,\n });\n turnStarts.set(turn, turn);\n turnStarts.set(summary.resume, turn);\n changed = true;\n continue;\n }\n const oldest = held.loaded[0];\n const newest = held.loaded.at(-1);\n if (oldest !== undefined && newest !== undefined) {\n // The same turn paged again (another reader asked the same page):\n // keep the steps already spliced in where the page left them out.\n setParent(oldest.id as string, parents.get(held.shownAfter) ?? null);\n setParent(held.shownAfter, newest.id as string);\n }\n }\n if (unserved) {\n unserved = false;\n unservedBy = undefined;\n changed = true;\n }\n if (changed) notify();\n return changed;\n },\n addSteps({ turn, messages: steps, moreBefore }) {\n const held = summaries.get(turn);\n if (held === undefined) return false;\n const loadedIds = new Set(held.loaded.map((message) => message.id));\n const fresh = steps.filter(\n (message) => typeof message.id === 'string' && message.id && !loadedIds.has(message.id)\n );\n const more = moreBefore && fresh.length > 0;\n if (fresh.length === 0) {\n if (held.more === more) return false;\n held.more = more;\n notify();\n return true;\n }\n // Splice the steps in where the gap is: after what precedes it (the\n // prompt), before where the shown transcript resumes.\n const above = parents.get(held.resume);\n const freshIds = fresh.map((message) => message.id as string);\n for (const [index, id] of freshIds.entries()) {\n messages.set(id, fresh[index] as LangChainMessage);\n if (index > 0) parents.set(id, freshIds[index - 1] as string);\n else if (above !== undefined) parents.set(id, above);\n }\n parents.set(held.resume, freshIds.at(-1) as string);\n turnStarts.delete(held.resume);\n held.resume = freshIds[0] as string;\n turnStarts.set(held.resume, turn);\n held.loaded = [...fresh, ...held.loaded];\n held.more = more;\n notify();\n return true;\n },\n olderThan(id) {\n const ids: string[] = [];\n const older: LangChainMessage[] = [];\n const seen = new Set<string>([id]);\n let parent = parents.get(id);\n while (typeof parent === 'string' && !seen.has(parent)) {\n const message = messages.get(parent);\n if (message === undefined) break;\n seen.add(parent);\n ids.push(parent);\n older.push(message);\n parent = parents.get(parent);\n }\n ids.reverse();\n older.reverse();\n return { ids, messages: older, hasOlder: parent !== null };\n },\n parentOf(id) {\n return parents.get(id);\n },\n turnSteps(turnId) {\n return summaries.get(turnId)?.steps;\n },\n markTurns(threadId, transcript) {\n if (summaries.size === 0) return transcript;\n let marked: LangChainMessage[] | null = null;\n let pending: DeepAgentTurnStepsMarker | null = null;\n const started = new Set<string>();\n for (const [index, message] of transcript.entries()) {\n const id = typeof message.id === 'string' ? message.id : undefined;\n const turn = id === undefined ? undefined : turnStarts.get(id);\n if (turn !== undefined && !started.has(turn)) {\n started.add(turn);\n const state = summaries.get(turn) as SummarizedTurnState;\n pending = marker(threadId, turn, state);\n } else if (message.type === 'human') {\n // The turn showed no reply before the next one began.\n pending = null;\n }\n // The marker rides an assistant message: a tool result whose call is\n // older than what is shown converts to no row.\n if (pending === null || message.type !== 'ai') continue;\n marked ??= [...transcript];\n marked[index] = withMarker(message, pending);\n pending = null;\n }\n return marked ?? transcript;\n },\n isLoadingSteps(turn) {\n return loadingSteps.has(turn);\n },\n async loadSteps({ send, turn, steps = DEEP_AGENT_TURN_STEPS_PAGE }) {\n const held = summaries.get(turn);\n if (held === undefined || !held.more || loadingSteps.has(turn)) return;\n loadingSteps.add(turn);\n try {\n const answer = readTurnStepsResult(await send(buildTurnStepsCommand({ turn, before: held.resume, steps })));\n if (answer === null || answer.turn !== turn) {\n throw new Error('history/page answered steps in a shape this client cannot read');\n }\n store.addSteps(answer);\n } finally {\n loadingSteps.delete(turn);\n }\n },\n subscribe(listener) {\n listeners.add(listener);\n return () => {\n listeners.delete(listener);\n };\n },\n };\n return store;\n}\n\n/**\n * The registry lives on `globalThis`, not in module scope, because two copies\n * of this module can run in one page: the SDK bundles agent-runtime into its\n * dist while a host (Spaces, the Chrome extension, the Office add-in) imports\n * it directly. The host's thread joins pages through its copy while the SDK's\n * history edge and steps control load them through their own; both must see\n * one store per conversation.\n */\nconst HISTORY_STORES = Symbol.for('@athenaintel/agent-runtime/history-stores');\n\ninterface HistoryStoreRegistry {\n stores: Map<string, DeepAgentHistoryStore>;\n listeners: Set<() => void>;\n version: number;\n}\n\ntype HistoryStoreRegistryHost = typeof globalThis & { [HISTORY_STORES]?: HistoryStoreRegistry };\n\n// process-local: this client only — the older history it has read, in memory; nothing is persisted\nfunction registry(): HistoryStoreRegistry {\n const host = globalThis as HistoryStoreRegistryHost;\n return (host[HISTORY_STORES] ??= { stores: new Map(), listeners: new Set(), version: 0 });\n}\n\nconst notifyRegistry = () => {\n const shared = registry();\n shared.version += 1;\n for (const listener of [...shared.listeners]) listener();\n};\n\n/** The conversation's history store, created on first use and marked most recently read. */\nexport function deepAgentHistoryStore(threadId: string): DeepAgentHistoryStore {\n const { stores } = registry();\n let store = stores.get(threadId);\n if (store !== undefined) {\n stores.delete(threadId);\n stores.set(threadId, store);\n return store;\n }\n store = createDeepAgentHistoryStore();\n store.subscribe(notifyRegistry);\n stores.set(threadId, store);\n while (stores.size > DEEP_AGENT_HISTORY_STORE_LIMIT) {\n const oldest = stores.keys().next().value as string;\n stores.delete(oldest);\n }\n return store;\n}\n\n/** The conversation's store if the registry holds one, without creating or touching it. */\nexport function peekDeepAgentHistoryStore(threadId: string): DeepAgentHistoryStore | undefined {\n return registry().stores.get(threadId);\n}\n\n/** Any store's visible change (a page, steps, the unserved flag): what a converter re-runs on. */\nexport function subscribeDeepAgentHistory(listener: () => void): () => void {\n const { listeners } = registry();\n listeners.add(listener);\n return () => {\n listeners.delete(listener);\n };\n}\n\nexport function deepAgentHistoryVersion(): number {\n return registry().version;\n}\n\n/** Drop every conversation's store (sign-out, an identity change, tests). */\nexport function clearDeepAgentHistoryStores(): void {\n const { stores } = registry();\n if (stores.size === 0) return;\n stores.clear();\n notifyRegistry();\n}\n\n/**\n * Fetch the next older steps of the summarized turn a marker names, into its\n * conversation's store (the converter re-runs and shows them). A no-op when\n * the store is gone (evicted, cleared) or the turn has no steps left.\n */\nexport function loadDeepAgentTurnSteps({\n send,\n marker,\n steps,\n}: {\n send: DeepAgentHistorySend;\n marker: Pick<DeepAgentTurnStepsMarker, 'thread' | 'turn' | 'hiddenSteps'>;\n steps?: number;\n}): Promise<void> {\n if (marker.hiddenSteps === 0) return Promise.resolve();\n const store = peekDeepAgentHistoryStore(marker.thread);\n if (store === undefined) return Promise.resolve();\n return store.loadSteps({ send, turn: marker.turn, ...(steps !== undefined && { steps }) });\n}\n\n/** Whether a steps request for the marker's turn is in flight. */\nexport function isLoadingDeepAgentTurnSteps(marker: Pick<DeepAgentTurnStepsMarker, 'thread' | 'turn'>): boolean {\n return peekDeepAgentHistoryStore(marker.thread)?.isLoadingSteps(marker.turn) ?? false;\n}\n\n/** Whether the host's advertised contract version serves `history/page`. */\nexport function hostServesHistoryPage(version: number | null | undefined): boolean {\n return typeof version === 'number' && version >= DEEP_AGENT_HISTORY_PAGE_PROTOCOL_VERSION;\n}\n\n/**\n * Whether a `history/page` failure says this host does not serve the\n * command: statewire's `unknown-command`, a host without it although its\n * `protocol` lane advertises it. Any other refusal (a vanished anchor, a\n * malformed request, a host that cannot answer right now) is that page's\n * failure, reported to the reader, who may ask again; it never takes the\n * conversation off its store, whose history stays shown.\n */\nexport function isHistoryPageUnserved(error: unknown): boolean {\n const failure = (error as { failure?: { fate?: unknown; code?: unknown } } | null | undefined)\n ?.failure;\n return failure?.fate === 'rejected' && failure.code === 'unknown-command';\n}\n\n/**\n * Attach headers saying the client keeps older history itself\n * (`x-athena-deep-agent-history: paged`): the host then holds its head down\n * to its floor for at most `DEEP_AGENT_MAX_HELD_HEAD` messages, since what\n * slides out stays in the store. Every attach of this build says so: every\n * reader joins the store (`readDeepAgentMessageWindow`). An explicit entry\n * wins.\n */\nexport function withDeclaredPagedHistory(headers: Record<string, string>): Record<string, string> {\n if (DEEP_AGENT_MESSAGE_HISTORY_HEADER in headers) return headers;\n return { ...headers, [DEEP_AGENT_MESSAGE_HISTORY_HEADER]: DEEP_AGENT_MESSAGE_HISTORY_PAGED };\n}\n\n/**\n * The windowed wire's page commands on the statewire command union, so\n * `sendCommand({ type: 'history/page', … })` typechecks wherever the\n * deep-agent host is driven (an attach-ACL read, like `history/lane`).\n */\ndeclare module '@assistant-ui/core' {\n namespace Assistant {\n interface Commands {\n /** One page of older transcript history. */\n historyPage: HistoryPageCommand;\n /** One summarized turn's steps. */\n historyTurnSteps: TurnStepsCommand;\n }\n }\n}\n\n/**\n * The turns `history/page` reads per page: about a screen and a half of\n * conversation, however long each run was (a long turn rides as its prompt\n * and answer, its steps counted).\n */\nexport const DEEP_AGENT_HISTORY_PAGE_TURNS = 10;\n\n/** The `history/page` command: up to `turns` whole turns ending before `before`. */\nexport interface HistoryPageCommand {\n readonly type: typeof DEEP_AGENT_HISTORY_PAGE_COMMAND;\n readonly before: string;\n readonly turns: number;\n}\n\n/** The `history/page` command asking for one summarized turn's steps older than `before`. */\nexport interface TurnStepsCommand {\n readonly type: typeof DEEP_AGENT_HISTORY_PAGE_COMMAND;\n readonly turn: string;\n readonly before?: string;\n readonly steps: number;\n}\n\nexport function buildHistoryPageCommand({\n before,\n turns = DEEP_AGENT_HISTORY_PAGE_TURNS,\n}: {\n before: string;\n turns?: number;\n}): HistoryPageCommand {\n return {\n type: DEEP_AGENT_HISTORY_PAGE_COMMAND,\n before,\n turns: Math.max(1, Math.min(DEEP_AGENT_MAX_HISTORY_PAGE_TURNS, Math.trunc(turns))),\n };\n}\n\nexport function buildTurnStepsCommand({\n turn,\n before,\n steps = DEEP_AGENT_TURN_STEPS_PAGE,\n}: {\n turn: string;\n before?: string | undefined;\n steps?: number;\n}): TurnStepsCommand {\n return {\n type: DEEP_AGENT_HISTORY_PAGE_COMMAND,\n turn,\n ...(before !== undefined && { before }),\n steps: Math.max(1, Math.min(DEEP_AGENT_MAX_HISTORY_PAGE_STEPS, Math.trunc(steps))),\n };\n}\n\nconst isRecord = (value: unknown): value is Record<string, unknown> =>\n typeof value === 'object' && value !== null && !Array.isArray(value);\n\nconst isCount = (value: unknown): value is number =>\n typeof value === 'number' && Number.isInteger(value) && value >= 0;\n\nconst isId = (value: unknown): value is string => typeof value === 'string' && value.length > 0;\n\nconst readTurnSteps = (value: unknown): DeepAgentHistoryTurnSteps | null | undefined => {\n if (value === null) return null;\n if (!isRecord(value)) return undefined;\n const { count, tools, delegations, first, last } = value;\n if (!isCount(count) || !isCount(tools) || !isCount(delegations)) return undefined;\n const id = (entry: unknown) => (isId(entry) ? entry : null);\n return { count, tools, delegations, first: id(first), last: id(last) };\n};\n\nfunction readMessages(value: unknown): LangChainMessage[] | null {\n if (!Array.isArray(value)) return null;\n for (const message of value) {\n if (!isRecord(message) || !isId(message.id)) return null;\n }\n return value as LangChainMessage[];\n}\n\n/**\n * A `history/page` answer to `{before, turns}` read as one page of messages:\n * the turns' shown messages, oldest first (a summarized turn's prompt and\n * answer, its steps left out and counted in `summarized`). `null` when\n * malformed.\n */\nexport function readHistoryPageResult(\n payload: unknown,\n before: string\n): (DeepAgentHistoryPage & { summarized: ReadonlyMap<string, DeepAgentHistorySummarizedTurn> }) | null {\n if (!isRecord(payload) || !Array.isArray(payload.turns) || !isRecord(payload.more)) return null;\n if (typeof payload.more.before !== 'boolean') return null;\n const page: LangChainMessage[] = [];\n const turns: { id: string; messages: LangChainMessage[]; steps: DeepAgentHistoryTurnSteps | null }[] = [];\n for (const turn of payload.turns) {\n if (!isRecord(turn) || !isId(turn.id)) return null;\n const turnMessages = readMessages(turn.messages);\n if (turnMessages === null) return null;\n const steps = readTurnSteps(turn.steps);\n if (steps === undefined && turn.steps !== undefined) return null;\n turns.push({ id: turn.id, messages: turnMessages, steps: steps ?? null });\n page.push(...turnMessages);\n }\n const summarized = new Map<string, DeepAgentHistorySummarizedTurn>();\n for (const [index, turn] of turns.entries()) {\n if (turn.steps === null) continue;\n // The steps left out sit right after the prompt; the shown transcript\n // resumes at the next message the page carries, or — a turn the asker's\n // own messages cut short — at the message the page was asked before.\n const shown = turn.messages[0]?.id === turn.id ? turn.messages.slice(1) : turn.messages;\n const resume = shown[0]?.id ?? turns[index + 1]?.messages[0]?.id ?? before;\n summarized.set(turn.id, { steps: turn.steps, resume });\n }\n return { before, messages: page, moreBefore: payload.more.before, summarized };\n}\n\n/** A `history/page` answer to `{turn, before?, steps}`, or `null` when it is malformed. */\nexport function readTurnStepsResult(payload: unknown): DeepAgentTurnStepsPage | null {\n if (!isRecord(payload) || !isId(payload.turn) || !isRecord(payload.more)) return null;\n if (typeof payload.more.before !== 'boolean') return null;\n const steps = readMessages(payload.messages);\n if (steps === null) return null;\n return { turn: payload.turn, messages: steps, moreBefore: payload.more.before };\n}\n\n/** The marker a join put on a source message, or `undefined`. */\nexport function readTurnStepsMarker(message: unknown): DeepAgentTurnStepsMarker | undefined {\n if (!isRecord(message) || !isRecord(message.additional_kwargs)) return undefined;\n const marker = message.additional_kwargs[DEEP_AGENT_TURN_STEPS_KEY];\n if (!isRecord(marker) || !isId(marker.turn) || !isId(marker.thread)) return undefined;\n const { hiddenSteps, hiddenTools, hiddenDelegations, before } = marker;\n if (!isCount(hiddenSteps) || !isCount(hiddenTools) || !isCount(hiddenDelegations)) return undefined;\n return {\n turn: marker.turn,\n thread: marker.thread,\n hiddenSteps,\n hiddenTools,\n hiddenDelegations,\n before: isId(before) ? before : undefined,\n };\n}\n\n/** The interest-request shape a page is reported as (telemetry parity with interest pages). */\nexport function historyPageAsInterestRequest(command: HistoryPageCommand): {\n ns: typeof DEEP_AGENT_MAIN_NS;\n before: number;\n at: string;\n} {\n return { ns: DEEP_AGENT_MAIN_NS, before: command.turns, at: command.before };\n}\n"],"names":["QUIET_TOOL_NAMES","DEEP_AGENT_HISTORY_PAGE_PROTOCOL_VERSION","DEEP_AGENT_MESSAGE_HISTORY_HEADER","DEEP_AGENT_MESSAGE_HISTORY_PAGED","DEEP_AGENT_HISTORY_PAGE_COMMAND","DEEP_AGENT_MAX_HISTORY_PAGE_TURNS","DEEP_AGENT_MAX_HISTORY_PAGE_STEPS","DEEP_AGENT_MAIN_NS"],"mappings":";;;;AAqDO,MAAM,iCAAiC;AAGvC,MAAM,6BAA6B;AAGnC,MAAM,4BAA4B;AA4JzC,SAAS,UAAU,UAA+E;AAChG,MAAI,QAAQ;AACZ,MAAI,cAAc;AAClB,aAAW,WAAW,UAAU;AAC9B,QAAI,QAAQ,SAAS,KAAM;AAC3B,eAAW,QAAQ,QAAQ,cAAc,CAAA,GAAI;AAC3C,UAAIA,2BAAiB,IAAI,KAAK,IAAI,EAAG;AACrC,eAAS;AACT,UAAI,KAAK,SAAS,OAAQ,gBAAe;AAAA,IAC3C;AAAA,EACF;AACA,SAAO,EAAE,OAAO,YAAA;AAClB;AAGA,MAAM,mCAAmB,QAAA;AAEzB,SAAS,WAAW,SAA2B,QAAoD;AACjG,QAAM,MAAM,GAAG,OAAO,MAAM,KAAS,OAAO,IAAI,KAAS,OAAO,WAAW,KAAS,OAAO,WAAW,KAAS,OAAO,iBAAiB,KAAS,OAAO,UAAU,EAAE;AACnK,QAAM,SAAS,aAAa,IAAI,OAAO;AACvC,OAAI,iCAAQ,SAAQ,IAAK,QAAO,OAAO;AAGvC,QAAM,SAAU,QAA4D;AAC5E,QAAM,SAAS;AAAA,IACb,GAAG;AAAA,IACH,mBAAmB,EAAE,GAAI,UAAU,CAAA,GAAK,CAAC,yBAAyB,GAAG,OAAA;AAAA,EAAO;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C1F,SAAO;AAAA,IACL,MAAM,OAAO;AAAA,IACb,QAAQ,OAAO;AAAA,IACf;AAAA,IACA;AAAA,IACA;AAAA,IACA,QAAQ,KAAK,MAAM,IAAI,SAAS;AAAA,EAAA;AAEpC;AAGO,SAAS,6BAA6B,SAI3C;AACA,SAAO,EAAE,IAAIC,kBAAAA,oBAAoB,QAAQ,QAAQ,OAAO,IAAI,QAAQ,OAAA;AACtE;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
import type { LangChainMessage } from '@assistant-ui/react-langgraph';
|
|
2
|
+
import { DEEP_AGENT_HISTORY_PAGE_COMMAND, DEEP_AGENT_MAIN_NS } from './generated/runconfig-contract';
|
|
3
|
+
/**
|
|
4
|
+
* Older history on the client — the client half of agora's `history/page`.
|
|
5
|
+
*
|
|
6
|
+
* On a host whose `protocol` lane advertises
|
|
7
|
+
* `DEEP_AGENT_HISTORY_PAGE_PROTOCOL_VERSION`, an attach states only its head
|
|
8
|
+
* (and its lane follows) on `athena/interest`, and says on its attach headers
|
|
9
|
+
* that it keeps older history itself ({@link withDeclaredPagedHistory}).
|
|
10
|
+
* Older messages come back from the one-shot `history/page` command
|
|
11
|
+
* (`{before, turns}` answers whole turns ending before `before`, oldest
|
|
12
|
+
* first; a long turn rides as its prompt and answer, its steps counted) and
|
|
13
|
+
* live here, never in the attach's view, so the interest document stays the
|
|
14
|
+
* same small size however deep the viewer scrolls, and scrolling back moves
|
|
15
|
+
* the page anchor instead of growing a list.
|
|
16
|
+
*
|
|
17
|
+
* The store keeps each message's parent as the reader sees the transcript,
|
|
18
|
+
* and which message starts it. Every read of the interest window records the
|
|
19
|
+
* parents its live chain shows, so a message that slides out of the head (the
|
|
20
|
+
* host holds the head down to its floor for at most
|
|
21
|
+
* `DEEP_AGENT_MAX_HELD_HEAD` messages) stays reachable here, and a re-attach
|
|
22
|
+
* on any pod finds what was loaded. A page records the parents it shows (a
|
|
23
|
+
* summarized turn's answer follows its prompt). A host parent never changes:
|
|
24
|
+
* an edit or rewind mints new ids, a branch switch keeps each id's parent.
|
|
25
|
+
* {@link readDeepAgentMessageWindow} joins the store under the live chain by
|
|
26
|
+
* walking parents back from its first message, so only ancestors of the live
|
|
27
|
+
* view are ever shown: a rewound tail is never reached.
|
|
28
|
+
*
|
|
29
|
+
* A summarized turn's left-out steps come back on request (`history/page`
|
|
30
|
+
* with its `turn`, newest first, {@link DeepAgentHistoryStore.loadSteps}) and
|
|
31
|
+
* are spliced in where the page left them out: between the turn's prompt and
|
|
32
|
+
* the first message shown after it. The join marks each summarized turn on
|
|
33
|
+
* its first reply message ({@link DEEP_AGENT_TURN_STEPS_KEY}), so a renderer
|
|
34
|
+
* reads its exact counts ("Used 313 tools") and can offer the steps still
|
|
35
|
+
* left out.
|
|
36
|
+
*
|
|
37
|
+
* One store per conversation, shared by every reader in the JS context (the
|
|
38
|
+
* converter, the edit path, the history edge), so they agree on what is
|
|
39
|
+
* loaded. The registry keeps the most recently read
|
|
40
|
+
* {@link DEEP_AGENT_HISTORY_STORE_LIMIT} conversations.
|
|
41
|
+
*/
|
|
42
|
+
/** Conversations whose stores the registry keeps (least recently read evicted). */
|
|
43
|
+
export declare const DEEP_AGENT_HISTORY_STORE_LIMIT = 8;
|
|
44
|
+
/** Steps of one summarized turn one `history/page` asks for. */
|
|
45
|
+
export declare const DEEP_AGENT_TURN_STEPS_PAGE = 100;
|
|
46
|
+
/** `additional_kwargs` key the join marks a summarized turn's first reply message with. */
|
|
47
|
+
export declare const DEEP_AGENT_TURN_STEPS_KEY = "athena_turn_steps";
|
|
48
|
+
/**
|
|
49
|
+
* What a summarized turn's page left out (`steps` on a `history/page` turn):
|
|
50
|
+
* counted over the left-out messages only, so a reader adds what it holds.
|
|
51
|
+
*/
|
|
52
|
+
export interface DeepAgentHistoryTurnSteps {
|
|
53
|
+
/** Messages left out. */
|
|
54
|
+
count: number;
|
|
55
|
+
/** Tool calls among the messages left out. */
|
|
56
|
+
tools: number;
|
|
57
|
+
/** Of which `task` delegations. */
|
|
58
|
+
delegations: number;
|
|
59
|
+
/** The oldest and newest message left out. */
|
|
60
|
+
first: string | null;
|
|
61
|
+
last: string | null;
|
|
62
|
+
}
|
|
63
|
+
/** A turn a page summarized: what it left out, and where. */
|
|
64
|
+
export interface DeepAgentHistorySummarizedTurn {
|
|
65
|
+
steps: DeepAgentHistoryTurnSteps;
|
|
66
|
+
/**
|
|
67
|
+
* The message the left-out steps end before: the first the page shows after
|
|
68
|
+
* the turn's prompt, or — for a turn cut short by what the asker held — the
|
|
69
|
+
* message the page was asked before.
|
|
70
|
+
*/
|
|
71
|
+
resume: string;
|
|
72
|
+
}
|
|
73
|
+
/** One `history/page` answer, read off the wire. */
|
|
74
|
+
export interface DeepAgentHistoryPage {
|
|
75
|
+
/** The message the page ends before. */
|
|
76
|
+
before: string;
|
|
77
|
+
/** Oldest first. */
|
|
78
|
+
messages: LangChainMessage[];
|
|
79
|
+
/** Whether the transcript holds messages older than the page. */
|
|
80
|
+
moreBefore: boolean;
|
|
81
|
+
/** The page's summarized turns, by their first message's id. */
|
|
82
|
+
summarized?: ReadonlyMap<string, DeepAgentHistorySummarizedTurn>;
|
|
83
|
+
}
|
|
84
|
+
/** One `history/page` answer to `{turn, before, steps}`: a summarized turn's steps. */
|
|
85
|
+
export interface DeepAgentTurnStepsPage {
|
|
86
|
+
turn: string;
|
|
87
|
+
/** Steps, oldest first. */
|
|
88
|
+
messages: LangChainMessage[];
|
|
89
|
+
/** Older steps of the turn remain. */
|
|
90
|
+
moreBefore: boolean;
|
|
91
|
+
}
|
|
92
|
+
/** What the store holds older than one message. */
|
|
93
|
+
export interface DeepAgentHistoryOlder {
|
|
94
|
+
/** Ids, oldest first, ending right before the message asked about. */
|
|
95
|
+
ids: string[];
|
|
96
|
+
messages: LangChainMessage[];
|
|
97
|
+
/** Whether anything older than `ids[0]` (or the message itself) may exist. */
|
|
98
|
+
hasOlder: boolean;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* The marker the join puts on a summarized turn's first reply message: the
|
|
102
|
+
* turn's steps not shown yet, so a renderer reads exact counts and knows
|
|
103
|
+
* whether opening it has steps to fetch ({@link loadDeepAgentTurnSteps}).
|
|
104
|
+
*/
|
|
105
|
+
export interface DeepAgentTurnStepsMarker {
|
|
106
|
+
/** The turn's first message: the id its steps are paged by. */
|
|
107
|
+
turn: string;
|
|
108
|
+
/** The conversation it belongs to (its history store). */
|
|
109
|
+
thread: string;
|
|
110
|
+
/** Steps not loaded yet. */
|
|
111
|
+
hiddenSteps: number;
|
|
112
|
+
/** Tool calls among them. */
|
|
113
|
+
hiddenTools: number;
|
|
114
|
+
/** Of which `task` delegations. */
|
|
115
|
+
hiddenDelegations: number;
|
|
116
|
+
/** The oldest step loaded; `undefined` while none is. */
|
|
117
|
+
before: string | undefined;
|
|
118
|
+
}
|
|
119
|
+
/** How the store asks the host: the thread's `sendCommand` (its answer, the command's payload). */
|
|
120
|
+
export type DeepAgentHistorySend = (command: HistoryPageCommand | TurnStepsCommand) => unknown;
|
|
121
|
+
export interface DeepAgentHistoryStore {
|
|
122
|
+
/**
|
|
123
|
+
* Whether the host refused `history/page` although its `protocol` lane
|
|
124
|
+
* advertises it (a host without the command): readers then read the live
|
|
125
|
+
* view alone and page by interest, until {@link markServed}.
|
|
126
|
+
*/
|
|
127
|
+
readonly unserved: boolean;
|
|
128
|
+
/** The connection the refusal came on (`markUnserved`): a later one may land on a host that serves it. */
|
|
129
|
+
readonly unservedBy: unknown;
|
|
130
|
+
/** Bumped on every change readers can see (a page, steps, the unserved flag). */
|
|
131
|
+
readonly version: number;
|
|
132
|
+
markUnserved(connection?: unknown): void;
|
|
133
|
+
markServed(): void;
|
|
134
|
+
/**
|
|
135
|
+
* Record what a live chain shows: each entry's parent is the one before it,
|
|
136
|
+
* and with `startsTranscript` its first entry has none. Messages are kept by
|
|
137
|
+
* id (the newest form seen). Silent: a live chain changes nothing its own
|
|
138
|
+
* reader shows.
|
|
139
|
+
*/
|
|
140
|
+
recordChain(ids: readonly string[], messages: ReadonlyMap<string, LangChainMessage>, startsTranscript: boolean): void;
|
|
141
|
+
/**
|
|
142
|
+
* Take in one page; notifies. `false` for an empty page that told nothing
|
|
143
|
+
* new. A page's messages are the transcript as the reader sees it: a
|
|
144
|
+
* summarized turn's answer follows its prompt, its steps left out.
|
|
145
|
+
*/
|
|
146
|
+
addPage(page: DeepAgentHistoryPage): boolean;
|
|
147
|
+
/**
|
|
148
|
+
* Take in a summarized turn's older steps, spliced in where its page left
|
|
149
|
+
* them out; notifies. `false` for a turn the store does not hold.
|
|
150
|
+
*/
|
|
151
|
+
addSteps(page: DeepAgentTurnStepsPage): boolean;
|
|
152
|
+
/** What a summarized turn's page left out, by the turn's first message id. */
|
|
153
|
+
turnSteps(turnId: string): DeepAgentHistoryTurnSteps | undefined;
|
|
154
|
+
/** Everything the store holds older than `id`, walking parents back. */
|
|
155
|
+
olderThan(id: string): DeepAgentHistoryOlder;
|
|
156
|
+
/** The host parent of `id`: `null` at the transcript's start, `undefined` while unknown. */
|
|
157
|
+
parentOf(id: string): string | null | undefined;
|
|
158
|
+
/**
|
|
159
|
+
* `messages` (a transcript as a reader shows it, oldest first) with each
|
|
160
|
+
* summarized turn's marker on its first reply message
|
|
161
|
+
* ({@link DEEP_AGENT_TURN_STEPS_KEY}); the same array when none applies.
|
|
162
|
+
*/
|
|
163
|
+
markTurns(threadId: string, messages: LangChainMessage[]): LangChainMessage[];
|
|
164
|
+
/** Whether a steps request for the turn is in flight — the loader's dedupe. */
|
|
165
|
+
isLoadingSteps(turn: string): boolean;
|
|
166
|
+
/**
|
|
167
|
+
* Fetches a summarized turn's next older steps (`history/page` with its
|
|
168
|
+
* `turn`) into the store. A turn already loading, unknown, or with no steps
|
|
169
|
+
* left is a no-op. Rejects with the host's refusal, or when the answer is
|
|
170
|
+
* not a page this client reads.
|
|
171
|
+
*/
|
|
172
|
+
loadSteps(options: {
|
|
173
|
+
send: DeepAgentHistorySend;
|
|
174
|
+
turn: string;
|
|
175
|
+
steps?: number;
|
|
176
|
+
}): Promise<void>;
|
|
177
|
+
subscribe(listener: () => void): () => void;
|
|
178
|
+
}
|
|
179
|
+
export declare function createDeepAgentHistoryStore(): DeepAgentHistoryStore;
|
|
180
|
+
/** The conversation's history store, created on first use and marked most recently read. */
|
|
181
|
+
export declare function deepAgentHistoryStore(threadId: string): DeepAgentHistoryStore;
|
|
182
|
+
/** The conversation's store if the registry holds one, without creating or touching it. */
|
|
183
|
+
export declare function peekDeepAgentHistoryStore(threadId: string): DeepAgentHistoryStore | undefined;
|
|
184
|
+
/** Any store's visible change (a page, steps, the unserved flag): what a converter re-runs on. */
|
|
185
|
+
export declare function subscribeDeepAgentHistory(listener: () => void): () => void;
|
|
186
|
+
export declare function deepAgentHistoryVersion(): number;
|
|
187
|
+
/** Drop every conversation's store (sign-out, an identity change, tests). */
|
|
188
|
+
export declare function clearDeepAgentHistoryStores(): void;
|
|
189
|
+
/**
|
|
190
|
+
* Fetch the next older steps of the summarized turn a marker names, into its
|
|
191
|
+
* conversation's store (the converter re-runs and shows them). A no-op when
|
|
192
|
+
* the store is gone (evicted, cleared) or the turn has no steps left.
|
|
193
|
+
*/
|
|
194
|
+
export declare function loadDeepAgentTurnSteps({ send, marker, steps, }: {
|
|
195
|
+
send: DeepAgentHistorySend;
|
|
196
|
+
marker: Pick<DeepAgentTurnStepsMarker, 'thread' | 'turn' | 'hiddenSteps'>;
|
|
197
|
+
steps?: number;
|
|
198
|
+
}): Promise<void>;
|
|
199
|
+
/** Whether a steps request for the marker's turn is in flight. */
|
|
200
|
+
export declare function isLoadingDeepAgentTurnSteps(marker: Pick<DeepAgentTurnStepsMarker, 'thread' | 'turn'>): boolean;
|
|
201
|
+
/** Whether the host's advertised contract version serves `history/page`. */
|
|
202
|
+
export declare function hostServesHistoryPage(version: number | null | undefined): boolean;
|
|
203
|
+
/**
|
|
204
|
+
* Whether a `history/page` failure says this host does not serve the
|
|
205
|
+
* command: statewire's `unknown-command`, a host without it although its
|
|
206
|
+
* `protocol` lane advertises it. Any other refusal (a vanished anchor, a
|
|
207
|
+
* malformed request, a host that cannot answer right now) is that page's
|
|
208
|
+
* failure, reported to the reader, who may ask again; it never takes the
|
|
209
|
+
* conversation off its store, whose history stays shown.
|
|
210
|
+
*/
|
|
211
|
+
export declare function isHistoryPageUnserved(error: unknown): boolean;
|
|
212
|
+
/**
|
|
213
|
+
* Attach headers saying the client keeps older history itself
|
|
214
|
+
* (`x-athena-deep-agent-history: paged`): the host then holds its head down
|
|
215
|
+
* to its floor for at most `DEEP_AGENT_MAX_HELD_HEAD` messages, since what
|
|
216
|
+
* slides out stays in the store. Every attach of this build says so: every
|
|
217
|
+
* reader joins the store (`readDeepAgentMessageWindow`). An explicit entry
|
|
218
|
+
* wins.
|
|
219
|
+
*/
|
|
220
|
+
export declare function withDeclaredPagedHistory(headers: Record<string, string>): Record<string, string>;
|
|
221
|
+
/**
|
|
222
|
+
* The windowed wire's page commands on the statewire command union, so
|
|
223
|
+
* `sendCommand({ type: 'history/page', … })` typechecks wherever the
|
|
224
|
+
* deep-agent host is driven (an attach-ACL read, like `history/lane`).
|
|
225
|
+
*/
|
|
226
|
+
declare module '@assistant-ui/core' {
|
|
227
|
+
namespace Assistant {
|
|
228
|
+
interface Commands {
|
|
229
|
+
/** One page of older transcript history. */
|
|
230
|
+
historyPage: HistoryPageCommand;
|
|
231
|
+
/** One summarized turn's steps. */
|
|
232
|
+
historyTurnSteps: TurnStepsCommand;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* The turns `history/page` reads per page: about a screen and a half of
|
|
238
|
+
* conversation, however long each run was (a long turn rides as its prompt
|
|
239
|
+
* and answer, its steps counted).
|
|
240
|
+
*/
|
|
241
|
+
export declare const DEEP_AGENT_HISTORY_PAGE_TURNS = 10;
|
|
242
|
+
/** The `history/page` command: up to `turns` whole turns ending before `before`. */
|
|
243
|
+
export interface HistoryPageCommand {
|
|
244
|
+
readonly type: typeof DEEP_AGENT_HISTORY_PAGE_COMMAND;
|
|
245
|
+
readonly before: string;
|
|
246
|
+
readonly turns: number;
|
|
247
|
+
}
|
|
248
|
+
/** The `history/page` command asking for one summarized turn's steps older than `before`. */
|
|
249
|
+
export interface TurnStepsCommand {
|
|
250
|
+
readonly type: typeof DEEP_AGENT_HISTORY_PAGE_COMMAND;
|
|
251
|
+
readonly turn: string;
|
|
252
|
+
readonly before?: string;
|
|
253
|
+
readonly steps: number;
|
|
254
|
+
}
|
|
255
|
+
export declare function buildHistoryPageCommand({ before, turns, }: {
|
|
256
|
+
before: string;
|
|
257
|
+
turns?: number;
|
|
258
|
+
}): HistoryPageCommand;
|
|
259
|
+
export declare function buildTurnStepsCommand({ turn, before, steps, }: {
|
|
260
|
+
turn: string;
|
|
261
|
+
before?: string | undefined;
|
|
262
|
+
steps?: number;
|
|
263
|
+
}): TurnStepsCommand;
|
|
264
|
+
/**
|
|
265
|
+
* A `history/page` answer to `{before, turns}` read as one page of messages:
|
|
266
|
+
* the turns' shown messages, oldest first (a summarized turn's prompt and
|
|
267
|
+
* answer, its steps left out and counted in `summarized`). `null` when
|
|
268
|
+
* malformed.
|
|
269
|
+
*/
|
|
270
|
+
export declare function readHistoryPageResult(payload: unknown, before: string): (DeepAgentHistoryPage & {
|
|
271
|
+
summarized: ReadonlyMap<string, DeepAgentHistorySummarizedTurn>;
|
|
272
|
+
}) | null;
|
|
273
|
+
/** A `history/page` answer to `{turn, before?, steps}`, or `null` when it is malformed. */
|
|
274
|
+
export declare function readTurnStepsResult(payload: unknown): DeepAgentTurnStepsPage | null;
|
|
275
|
+
/** The marker a join put on a source message, or `undefined`. */
|
|
276
|
+
export declare function readTurnStepsMarker(message: unknown): DeepAgentTurnStepsMarker | undefined;
|
|
277
|
+
/** The interest-request shape a page is reported as (telemetry parity with interest pages). */
|
|
278
|
+
export declare function historyPageAsInterestRequest(command: HistoryPageCommand): {
|
|
279
|
+
ns: typeof DEEP_AGENT_MAIN_NS;
|
|
280
|
+
before: number;
|
|
281
|
+
at: string;
|
|
282
|
+
};
|