@mgamadeus/ddd-agents 0.12.0 → 0.14.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.
Files changed (65) hide show
  1. package/README.md +76 -0
  2. package/dist/admin.js +133 -6
  3. package/dist/admin.js.map +1 -1
  4. package/dist/chat.js +1303 -409
  5. package/dist/chat.js.map +1 -1
  6. package/dist/chunks/{agents-http-trace-mappers-LWNi-3a4.js → agents-http-trace-mappers-juBx_kw5.js} +64 -22
  7. package/dist/chunks/agents-http-trace-mappers-juBx_kw5.js.map +1 -0
  8. package/dist/chunks/{canvas-title-slot-context-BRGnFzYP.js → canvas-label-context-B54MYVLF.js} +16 -4
  9. package/dist/chunks/canvas-label-context-B54MYVLF.js.map +1 -0
  10. package/dist/chunks/{content-from-unified-diff-CovnmG2Q.js → content-from-unified-diff-lgH6CejC.js} +77 -46
  11. package/dist/chunks/content-from-unified-diff-lgH6CejC.js.map +1 -0
  12. package/dist/chunks/{contract-886XjdID.js → contract-CIXLnSqL.js} +2 -1
  13. package/dist/chunks/{contract-886XjdID.js.map → contract-CIXLnSqL.js.map} +1 -1
  14. package/dist/chunks/conversation-B7-evdj_.js.map +1 -1
  15. package/dist/chunks/conversation-trace-fVeh6Lg6.js +6 -0
  16. package/dist/chunks/conversation-trace-fVeh6Lg6.js.map +1 -0
  17. package/dist/chunks/index-DZovGMpG.js.map +1 -1
  18. package/dist/client.js +13 -8
  19. package/dist/client.js.map +1 -1
  20. package/dist/contract.js +3 -1
  21. package/dist/contract.js.map +1 -1
  22. package/dist/files/i18n-keys.json +671 -12
  23. package/dist/files/styles/_surfaces.scss +5 -0
  24. package/dist/renderer.js +10 -8
  25. package/dist/styles.css +920 -39
  26. package/dist/types/admin/connections/AgentConnectionsPanel.d.ts +9 -1
  27. package/dist/types/admin/connections/agent-connection-oauth.d.ts +17 -1
  28. package/dist/types/admin/skills/SkillLoadSourcesPanel.d.ts +20 -0
  29. package/dist/types/admin/skills/agent-skill-catalog-api.d.ts +14 -2
  30. package/dist/types/admin/skills/agent-skill-catalog-types.d.ts +36 -0
  31. package/dist/types/chat/CanvasResizeHandle/CanvasResizeHandle.d.ts +2 -0
  32. package/dist/types/chat/CanvasResizeHandle/use-canvas-resize.d.ts +4 -2
  33. package/dist/types/chat/ConversationMessage/ConversationCallMarkerChip/ConversationCallMarkerChip.d.ts +6 -1
  34. package/dist/types/chat/ConversationMessageList/ConversationMessageList.d.ts +8 -1
  35. package/dist/types/chat/ConversationMessageList/message-times.d.ts +55 -0
  36. package/dist/types/chat/ConversationView.d.ts +3 -0
  37. package/dist/types/chat/ConversationViewBody/ConversationViewBody.d.ts +3 -0
  38. package/dist/types/chat/canvas-layout.d.ts +13 -0
  39. package/dist/types/chat/controller/AgentChatController.d.ts +7 -0
  40. package/dist/types/chat/trace/TaskPlanDrawer.d.ts +45 -0
  41. package/dist/types/chat/trace/TaskPlanPane.d.ts +21 -12
  42. package/dist/types/chat/trace/ToolStepGroup.d.ts +2 -0
  43. package/dist/types/chat/trace/TraceViewModeSwitch.d.ts +10 -2
  44. package/dist/types/chat/trace/index.d.ts +4 -1
  45. package/dist/types/chat/trace/task-plan-tree.d.ts +55 -0
  46. package/dist/types/chat/trace/trace-collect.d.ts +15 -0
  47. package/dist/types/chat/trace/trace-types.d.ts +20 -0
  48. package/dist/types/chat/trace/trace-view-policy.d.ts +17 -0
  49. package/dist/types/client/http/agents-http-trace-mappers.d.ts +8 -1
  50. package/dist/types/client/http/agents-http-trace-wire.d.ts +27 -0
  51. package/dist/types/client/http/agents-http-wire.d.ts +4 -0
  52. package/dist/types/contract/conversation-trace.d.ts +63 -1
  53. package/dist/types/contract/conversation.d.ts +11 -0
  54. package/dist/types/entries/admin.d.ts +3 -2
  55. package/dist/types/entries/chat.d.ts +1 -0
  56. package/dist/types/entries/renderer.d.ts +1 -0
  57. package/dist/types/provider/components/types.d.ts +5 -0
  58. package/dist/types/provider/environment.d.ts +26 -0
  59. package/dist/types/provider/index.d.ts +1 -1
  60. package/dist/types/renderer/canvas/canvas-label-context.d.ts +10 -0
  61. package/package.json +1 -1
  62. package/public-api.json +51 -0
  63. package/dist/chunks/agents-http-trace-mappers-LWNi-3a4.js.map +0 -1
  64. package/dist/chunks/canvas-title-slot-context-BRGnFzYP.js.map +0 -1
  65. package/dist/chunks/content-from-unified-diff-CovnmG2Q.js.map +0 -1
@@ -1,5 +1,6 @@
1
1
  "use client";
2
2
  import "./conversation-B7-evdj_.js";
3
+ import "./conversation-trace-fVeh6Lg6.js";
3
4
  import { t as textKey } from "./text-key-DnoZ4lAk.js";
4
5
  const PHONE_CALL_LIFECYCLE_SIGNAL_SOURCES = ["PHONE_CALL_STARTED", "PHONE_CALL_ENDED"];
5
6
  const REPEATED_TEXT_SUPPRESSED_SIGNAL_SOURCE = "REPEATED_TEXT_SUPPRESSED";
@@ -128,4 +129,4 @@ export {
128
129
  deriveAgentActivity as d,
129
130
  lastWireMessageIsUnansweredUserMessage as l
130
131
  };
131
- //# sourceMappingURL=contract-886XjdID.js.map
132
+ //# sourceMappingURL=contract-CIXLnSqL.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"contract-886XjdID.js","sources":["../../src/chat/last-wire-message-is-unanswered-user-message.ts","../../src/chat/controller/derive-agent-activity.ts","../../src/chat/controller/changed-messages-request.ts"],"sourcesContent":["import type { ChatMessage } from \"./chat-message\";\n\n/** The phone call's started / ended markers — the call marker chip, structural context, never owed work. */\nexport const PHONE_CALL_LIFECYCLE_SIGNAL_SOURCES: readonly string[] = [\"PHONE_CALL_STARTED\", \"PHONE_CALL_ENDED\"];\n/** The loop dropped a repeat of an already delivered text — bookkeeping behind the agent's answer, never owed work. */\nconst REPEATED_TEXT_SUPPRESSED_SIGNAL_SOURCE = \"REPEATED_TEXT_SUPPRESSED\";\n/** The platform wrote a widget on its own (e.g. a follow-up question under the final text) — a notice, never owed work. */\nconst PLATFORM_WIDGET_EMITTED_SIGNAL_SOURCE = \"PLATFORM_WIDGET_EMITTED\";\n/** The frontend's render report of a message's widgets — context for the next turn, never owed work. */\nconst FRONTEND_WIDGET_RENDER_REPORT_SIGNAL_SOURCE = \"FRONTEND_WIDGET_RENDER_REPORT\";\n/**\n * The SIGNAL rows that owe no work — the backend's `owesWork() === false` on a SIGNAL row, pinned by\n * `signal-source-parity.json` (`_signal-source-parity.spec.ts`).\n */\nexport const SIGNAL_SOURCES_THAT_OWE_NO_WORK: readonly string[] = [\n ...PHONE_CALL_LIFECYCLE_SIGNAL_SOURCES,\n REPEATED_TEXT_SUPPRESSED_SIGNAL_SOURCE,\n PLATFORM_WIDGET_EMITTED_SIGNAL_SOURCE,\n FRONTEND_WIDGET_RENDER_REPORT_SIGNAL_SOURCE,\n];\n\n/**\n * Whether the newest WIRE message is the customer's own, still unanswered — the backend's `hasUnansweredInboundMessage`\n * seen from the frontend, walked the same way: ERROR / CHECKPOINT rows are bookkeeping (never rendered, never an\n * answer); a TOOL_MESSAGE (a tool's own widget to the customer, stored role ASSISTANT) is NOT the agent's answer — a\n * customer question followed only by a tool's status widget stays owed; the phone-call lifecycle chips are structural\n * context, never owed work, and so is the platform's notice that it wrote a widget on its own; any other trailing SIGNAL (a widget click, a memory-conflict clarify) IS owed work, exactly\n * like a user message. Only then does a failed run have something to RETRY — the persisted\n * message is re-driven server-side instead of asking the customer to send it again. A walk that diverges from the\n * backend's shows the error card without the button while the backend would accept the retry — keep the two in step.\n *\n * The slice keeps `messages` ordered by `indexInConversation`; the sort here is belt-and-suspenders for a caller that\n * hands in an unordered page, not a fix for an upstream ordering defect.\n */\nexport const lastWireMessageIsUnansweredUserMessage = (messages: ChatMessage[] | null): boolean => {\n if (!messages?.length) {\n return false;\n }\n const sorted = [...messages].sort((a, b) => (a.indexInConversation ?? 0) - (b.indexInConversation ?? 0));\n for (let position = sorted.length - 1; position >= 0; position--) {\n const message = sorted[position];\n if (\n message.messageType === \"ERROR\" ||\n message.messageType === \"CHECKPOINT\" ||\n message.messageType === \"TOOL_MESSAGE\"\n ) {\n continue;\n }\n if (message.messageType === \"SIGNAL\") {\n if (SIGNAL_SOURCES_THAT_OWE_NO_WORK.includes(message.signalSource ?? \"\")) {\n continue;\n }\n return true;\n }\n return message.authorType === \"USER\";\n }\n return false;\n};\n","import type { ConversationMessageStatus } from \"../../contract/conversation\";\nimport type { ChatMessage } from \"../chat-message\";\nimport { textKey } from \"../../provider/text-key\";\nimport { SIGNAL_SOURCES_THAT_OWE_NO_WORK } from \"../last-wire-message-is-unanswered-user-message\";\n\n/** Mirrors App\\Domain\\AI\\Entities\\Conversations\\Agent\\Tools\\DelegateTool::NAME. */\nconst DELEGATE_TOOL_NAME = \"delegate\";\n\n/** Terminal tool-call statuses — mirrors ToolCall::isResolved (COMPLETED / FAILED / CANCELLED). */\nconst RESOLVED_STATUSES: string[] = [\"COMPLETED\", \"FAILED\", \"CANCELLED\"] satisfies ConversationMessageStatus[];\nconst isResolved = (status?: string | null): boolean => status != null && RESOLVED_STATUSES.includes(status);\n\n/** Terminal child run-states — mirrors AIConversationRunState::TERMINAL (COMPLETED / FAILED / CANCELLED). */\nconst TERMINAL_RUN_STATES: string[] = [\"COMPLETED\", \"FAILED\", \"CANCELLED\"];\n\n/** A sub-agent run still waiting to start or actively working (mirrors DelegationSubAgentRun::STATUS_*). */\nconst UNRESOLVED_RUN_STATUSES: string[] = [\"QUEUED\", \"RUNNING\"];\n\n/**\n * A tool call is EFFECTIVELY resolved when its stored status says so — or, for a `delegate` call, when every\n * expanded child already reached a terminal run state: the children are the truth of a fan-out, the stored\n * status is a mirror that a write race can leave stale (a delegate call left RUNNING kept the whole customer\n * chat \"thinking\" for the rest of a setup). An empty or missing expansion proves nothing and falls back to the status.\n */\n/**\n * Rows that never start or continue a turn: the bookkeeping rows (ERROR, CHECKPOINT) and the SIGNAL rows that owe no\n * work (the frontend's widget render report, the platform's own widget notice, phone call markers, a suppressed\n * repeat). They are stored with role USER and may land after the agent's answer; read as the tail they would keep the\n * \"Working on it…\" line under a finished answer forever.\n */\nconst isRowThatOwesNoWork = (message: ChatMessage): boolean =>\n message.messageType === \"ERROR\" ||\n message.messageType === \"CHECKPOINT\" ||\n (message.messageType === \"SIGNAL\" && SIGNAL_SOURCES_THAT_OWE_NO_WORK.includes(message.signalSource ?? \"\"));\n\nconst isEffectivelyResolved = (message: ChatMessage | undefined): boolean => {\n if (message == null) return false;\n if (isResolved(message.toolCall?.status)) return true;\n if (message.toolCall?.name !== DELEGATE_TOOL_NAME) return false;\n const children = message.delegatedConversations ?? [];\n if (children.length === 0) return false;\n // A partial expansion (page cap) proves nothing: the call declared N tasks, N children must be visible.\n const declaredTasks = (message.toolCall?.arguments as { tasks?: unknown[] } | undefined)?.tasks;\n if (Array.isArray(declaredTasks) && declaredTasks.length > children.length) return false;\n return children.every((child) => TERMINAL_RUN_STATES.includes(child.runState ?? \"\"));\n};\n\n/** How many sub-agents spawned by this message are still working. */\nexport const countOutstandingChildren = (message: ChatMessage): number => {\n const children = message.delegatedConversations ?? [];\n if (children.length > 0) {\n return children.filter((child) => !TERMINAL_RUN_STATES.includes(child.runState ?? \"\")).length;\n }\n if (message.toolCall?.name !== DELEGATE_TOOL_NAME) {\n return 0;\n }\n // A NEW row (one `delegate` call = one sub-agent) carries its own run record instead of\n // `delegatedConversations`; no child expanded, so the record's CURRENT run is the truth of whether it is done.\n const subAgent = message.subAgent;\n if (subAgent != null) {\n const currentRun = (subAgent.runs ?? []).find((run) => run.runNumber === subAgent.currentRunNumber);\n return currentRun != null && UNRESOLVED_RUN_STATUSES.includes(currentRun.status ?? \"\") ? 1 : 0;\n }\n if (isResolved(message.toolCall?.status)) {\n return 0;\n }\n const declaredTasks = (message.toolCall?.arguments as { tasks?: unknown[] } | undefined)?.tasks;\n return Array.isArray(declaredTasks) && declaredTasks.length > 0 ? declaredTasks.length : 1;\n};\n\n/** A tool call whose result is still to come — its progress lives in `toolCall.status`, never in the row's status. */\nexport const hasUnresolvedToolCall = (message: ChatMessage): boolean =>\n message.toolCall != null && !isEffectivelyResolved(message);\n\n/** Whether this message's delegation can still change: a child is still working, or the call is not resolved yet. */\nexport const hasDelegationInFlight = (message: ChatMessage): boolean =>\n countOutstandingChildren(message) > 0 ||\n (message.toolCall?.name === DELEGATE_TOOL_NAME && !isEffectivelyResolved(message));\n\nexport type AgentActivity = {\n /** Whether a turn is in flight — drives the indicator's visibility (ConversationView aiThinking). */\n active: boolean;\n /**\n * Translation source string for \"what the agent is doing right now\" (empty when nothing to show). Rendered through\n * the chat's `Text`, so this is the translatable key with %placeholders% — NOT pre-interpolated. The dynamic values\n * arrive via {@link AgentActivity.replacements} and plural form via {@link AgentActivity.context}.\n */\n label: string;\n /** Dynamic values substituted into the %placeholders% of {@link AgentActivity.label} by <Text>. */\n replacements?: Record<string, string | number>;\n /** Plural selector for <Text> when the label is count-dependent. */\n context?: \"one\" | \"other\";\n /** A non-delegate tool is running → show the ASCII wrench spinner instead of a text label. */\n toolRunning?: boolean;\n};\n\n/**\n * Derive \"what the agent is doing right now\" for the agent activity indicator PURELY from the\n * live conversation data: the message tree (refreshed on each realtime-signal tick / on open) plus the signal's\n * coarse runStatus (\"running\" | \"idle\" | \"failed\" | null). No network. Mirrors the backend truth —\n * AIConversation.runState (IDLE/RUNNING/AWAITING_DELEGATES/…) and per-message status/messageType/toolCall — but reads\n * it off the messages the FE already holds, so the indicator is correct even before the first signal emission.\n */\nexport const deriveAgentActivity = (\n messages: ChatMessage[] | null,\n runStatus: string | null,\n): AgentActivity => {\n if (runStatus === \"failed\") {\n // Failure surfaces via ConversationView's error state, not the activity line.\n return { active: false, label: \"\" };\n }\n\n // An optimistic (just-sent, not yet server-assigned) row carries no index — it belongs at the TAIL, the newest\n // thing in the conversation, never at the front, where `?? 0` would park it ahead of every real message.\n const sorted = [...(messages ?? [])].filter((message) => !isRowThatOwesNoWork(message)).sort(\n (a, b) => (a.indexInConversation ?? Number.POSITIVE_INFINITY) - (b.indexInConversation ?? Number.POSITIVE_INFINITY),\n );\n const lastMessage = sorted[sorted.length - 1];\n\n // The owner just sent — the optimistic bubble, or a saved row still awaiting the first response — starts the face\n // thinking immediately, before the server's \"running\" ping arrives (which can lag the send by about a second);\n // checked before the `idle` short-circuit below, whose `runStatus` can still report the PREVIOUS turn's rest state.\n // A rejected POST resets `aiThinking` itself (conversations-message-post.case.ts), so no separate reset is needed.\n if (lastMessage?.role === \"USER\") {\n return { active: true, label: \"\" };\n }\n\n // Sub-agents still working → the orchestrator is parked on its children (backend runState AWAITING_DELEGATES).\n // Counted per CHILD, not per delegate message: a fan-out (`delegate` with N tasks, or a tool result carrying\n // `delegationTasks`, e.g. a LARGE website edit's page packets) is ONE message with N children. The expanded\n // `delegatedConversations` carry each child's runState; without the expand, a `delegate` call still awaiting its\n // verdict counts its declared tasks, else one.\n const unresolvedDelegateCount = sorted.reduce((count, message) => count + countOutstandingChildren(message), 0);\n\n // The turn is at rest and nothing is outstanding → idle, no indicator.\n if (runStatus === \"idle\" && unresolvedDelegateCount === 0) {\n return { active: false, label: \"\" };\n }\n\n if (unresolvedDelegateCount > 0) {\n return {\n active: true,\n label: textKey(\"Waiting for %count% delegations...\"),\n replacements: { count: unresolvedDelegateCount },\n context: unresolvedDelegateCount === 1 ? \"one\" : \"other\",\n };\n }\n\n // A tool-call that hasn't resolved yet → that tool is running now (a delegate call whose children all finished\n // is resolved in effect, whatever its stored status says).\n if (lastMessage?.messageType === \"TOOL_CALL\" && !isEffectivelyResolved(lastMessage)) {\n return {\n active: true,\n label: textKey(\"Running: %tool%...\"),\n replacements: { tool: lastMessage.toolCall?.name ?? \"Tool\" },\n toolRunning: true,\n };\n }\n\n // The model is producing a turn (signal running) — a trailing owner row was already caught above.\n if (runStatus === \"running\") {\n return { active: true, label: \"\" };\n }\n\n return { active: false, label: \"\" };\n};\n","import type { ChangedMessagesRequest, ConversationMessageStatus } from \"../../contract/conversation\";\nimport type { ChatMessage } from \"../chat-message\";\nimport { hasDelegationInFlight, hasUnresolvedToolCall } from \"./derive-agent-activity\";\n\n/** Row statuses that are not final yet (today only a waiting signal row carries one, PENDING until a turn reads it). */\nconst CHANGING_STATUSES: string[] = [\"PENDING\", \"RUNNING\", \"CANCEL_REQUESTED\"] satisfies ConversationMessageStatus[];\n\nconst canStillChange = (message: ChatMessage): boolean =>\n CHANGING_STATUSES.includes(message.status ?? \"\") || hasUnresolvedToolCall(message) || hasDelegationInFlight(message);\n\n/**\n * What a live update reads, given the loaded messages: every row written since the newest loaded one, plus every\n * message from the lowest one that can still change. \"Written since\" goes by id, not index: ids grow with every write,\n * while an index can be taken below the newest loaded one (a call row persisted after the row its execution emitted)\n * or reused (a re-drive after an admin delete-from). The index start never lies below the newest page (a newest-first\n * page of `pageSize` cannot return older rows anyway), so a row a dead worker left pending cannot pin it. Nothing\n * loaded yet → null: the caller reads the newest page as on open. How the request reaches the wire (the filter string)\n * is the binding's matter (`AgentsConversationClient.getChangedMessages`).\n */\nexport const buildChangedMessagesRequest = (\n messages: ChatMessage[] | null,\n pageSize: number,\n): ChangedMessagesRequest | null => {\n const loaded = (messages ?? []).filter((message) => message.indexInConversation != null);\n if (loaded.length === 0) {\n return null;\n }\n const indexes = (list: ChatMessage[]) => list.map((message) => message.indexInConversation as number);\n const highestIndex = Math.max(...indexes(loaded));\n const changing = loaded.filter(canStillChange);\n const fromIndex = Math.max(\n changing.length > 0 ? Math.min(...indexes(changing)) : highestIndex + 1,\n highestIndex - pageSize + 1,\n );\n const highestKnownId = Math.max(...loaded.map((message) => message.id ?? 0));\n return { highestKnownId, fromIndex, pageSize };\n};\n"],"names":[],"mappings":";;;AAGO,MAAM,sCAAyD,CAAC,sBAAsB,kBAAkB;AAE/G,MAAM,yCAAyC;AAE/C,MAAM,wCAAwC;AAE9C,MAAM,8CAA8C;AAK7C,MAAM,kCAAqD;AAAA,EAChE,GAAG;AAAA,EACH;AAAA,EACA;AAAA,EACA;AACF;AAeO,MAAM,yCAAyC,CAAC,aAA4C;AACjG,MAAI,CAAC,UAAU,QAAQ;AACrB,WAAO;AAAA,EACT;AACA,QAA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C;AAChD,QAAM,WAAW,OAAO,OAAO,cAAc;AAC7C,QAAM,YAAY,KAAK;AAAA,IACrB,SAAS,SAAS,IAAI,KAAK,IAAI,GAAG,QAAQ,QAAQ,CAAC,IAAI,eAAe;AAAA,IACtE,eAAe,WAAW;AAAA,EAAA;AAE5B,QAAM,iBAAiB,KAAK,IAAI,GAAG,OAAO,IAAI,CAAC,YAAY,QAAQ,MAAM,CAAC,CAAC;AAC3E,SAAO,EAAE,gBAAgB,WAAW,SAAA;AACtC;"}
1
+ {"version":3,"file":"contract-CIXLnSqL.js","sources":["../../src/chat/last-wire-message-is-unanswered-user-message.ts","../../src/chat/controller/derive-agent-activity.ts","../../src/chat/controller/changed-messages-request.ts"],"sourcesContent":["import type { ChatMessage } from \"./chat-message\";\n\n/** The phone call's started / ended markers — the call marker chip, structural context, never owed work. */\nexport const PHONE_CALL_LIFECYCLE_SIGNAL_SOURCES: readonly string[] = [\"PHONE_CALL_STARTED\", \"PHONE_CALL_ENDED\"];\n/** The loop dropped a repeat of an already delivered text — bookkeeping behind the agent's answer, never owed work. */\nconst REPEATED_TEXT_SUPPRESSED_SIGNAL_SOURCE = \"REPEATED_TEXT_SUPPRESSED\";\n/** The platform wrote a widget on its own (e.g. a follow-up question under the final text) — a notice, never owed work. */\nconst PLATFORM_WIDGET_EMITTED_SIGNAL_SOURCE = \"PLATFORM_WIDGET_EMITTED\";\n/** The frontend's render report of a message's widgets — context for the next turn, never owed work. */\nconst FRONTEND_WIDGET_RENDER_REPORT_SIGNAL_SOURCE = \"FRONTEND_WIDGET_RENDER_REPORT\";\n/**\n * The SIGNAL rows that owe no work — the backend's `owesWork() === false` on a SIGNAL row, pinned by\n * `signal-source-parity.json` (`_signal-source-parity.spec.ts`).\n */\nexport const SIGNAL_SOURCES_THAT_OWE_NO_WORK: readonly string[] = [\n ...PHONE_CALL_LIFECYCLE_SIGNAL_SOURCES,\n REPEATED_TEXT_SUPPRESSED_SIGNAL_SOURCE,\n PLATFORM_WIDGET_EMITTED_SIGNAL_SOURCE,\n FRONTEND_WIDGET_RENDER_REPORT_SIGNAL_SOURCE,\n];\n\n/**\n * Whether the newest WIRE message is the customer's own, still unanswered — the backend's `hasUnansweredInboundMessage`\n * seen from the frontend, walked the same way: ERROR / CHECKPOINT rows are bookkeeping (never rendered, never an\n * answer); a TOOL_MESSAGE (a tool's own widget to the customer, stored role ASSISTANT) is NOT the agent's answer — a\n * customer question followed only by a tool's status widget stays owed; the phone-call lifecycle chips are structural\n * context, never owed work, and so is the platform's notice that it wrote a widget on its own; any other trailing SIGNAL (a widget click, a memory-conflict clarify) IS owed work, exactly\n * like a user message. Only then does a failed run have something to RETRY — the persisted\n * message is re-driven server-side instead of asking the customer to send it again. A walk that diverges from the\n * backend's shows the error card without the button while the backend would accept the retry — keep the two in step.\n *\n * The slice keeps `messages` ordered by `indexInConversation`; the sort here is belt-and-suspenders for a caller that\n * hands in an unordered page, not a fix for an upstream ordering defect.\n */\nexport const lastWireMessageIsUnansweredUserMessage = (messages: ChatMessage[] | null): boolean => {\n if (!messages?.length) {\n return false;\n }\n const sorted = [...messages].sort((a, b) => (a.indexInConversation ?? 0) - (b.indexInConversation ?? 0));\n for (let position = sorted.length - 1; position >= 0; position--) {\n const message = sorted[position];\n if (\n message.messageType === \"ERROR\" ||\n message.messageType === \"CHECKPOINT\" ||\n message.messageType === \"TOOL_MESSAGE\"\n ) {\n continue;\n }\n if (message.messageType === \"SIGNAL\") {\n if (SIGNAL_SOURCES_THAT_OWE_NO_WORK.includes(message.signalSource ?? \"\")) {\n continue;\n }\n return true;\n }\n return message.authorType === \"USER\";\n }\n return false;\n};\n","import type { ConversationMessageStatus } from \"../../contract/conversation\";\nimport type { ChatMessage } from \"../chat-message\";\nimport { textKey } from \"../../provider/text-key\";\nimport { SIGNAL_SOURCES_THAT_OWE_NO_WORK } from \"../last-wire-message-is-unanswered-user-message\";\n\n/** Mirrors App\\Domain\\AI\\Entities\\Conversations\\Agent\\Tools\\DelegateTool::NAME. */\nconst DELEGATE_TOOL_NAME = \"delegate\";\n\n/** Terminal tool-call statuses — mirrors ToolCall::isResolved (COMPLETED / FAILED / CANCELLED). */\nconst RESOLVED_STATUSES: string[] = [\"COMPLETED\", \"FAILED\", \"CANCELLED\"] satisfies ConversationMessageStatus[];\nconst isResolved = (status?: string | null): boolean => status != null && RESOLVED_STATUSES.includes(status);\n\n/** Terminal child run-states — mirrors AIConversationRunState::TERMINAL (COMPLETED / FAILED / CANCELLED). */\nconst TERMINAL_RUN_STATES: string[] = [\"COMPLETED\", \"FAILED\", \"CANCELLED\"];\n\n/** A sub-agent run still waiting to start or actively working (mirrors DelegationSubAgentRun::STATUS_*). */\nconst UNRESOLVED_RUN_STATUSES: string[] = [\"QUEUED\", \"RUNNING\"];\n\n/**\n * A tool call is EFFECTIVELY resolved when its stored status says so — or, for a `delegate` call, when every\n * expanded child already reached a terminal run state: the children are the truth of a fan-out, the stored\n * status is a mirror that a write race can leave stale (a delegate call left RUNNING kept the whole customer\n * chat \"thinking\" for the rest of a setup). An empty or missing expansion proves nothing and falls back to the status.\n */\n/**\n * Rows that never start or continue a turn: the bookkeeping rows (ERROR, CHECKPOINT) and the SIGNAL rows that owe no\n * work (the frontend's widget render report, the platform's own widget notice, phone call markers, a suppressed\n * repeat). They are stored with role USER and may land after the agent's answer; read as the tail they would keep the\n * \"Working on it…\" line under a finished answer forever.\n */\nconst isRowThatOwesNoWork = (message: ChatMessage): boolean =>\n message.messageType === \"ERROR\" ||\n message.messageType === \"CHECKPOINT\" ||\n (message.messageType === \"SIGNAL\" && SIGNAL_SOURCES_THAT_OWE_NO_WORK.includes(message.signalSource ?? \"\"));\n\nconst isEffectivelyResolved = (message: ChatMessage | undefined): boolean => {\n if (message == null) return false;\n if (isResolved(message.toolCall?.status)) return true;\n if (message.toolCall?.name !== DELEGATE_TOOL_NAME) return false;\n const children = message.delegatedConversations ?? [];\n if (children.length === 0) return false;\n // A partial expansion (page cap) proves nothing: the call declared N tasks, N children must be visible.\n const declaredTasks = (message.toolCall?.arguments as { tasks?: unknown[] } | undefined)?.tasks;\n if (Array.isArray(declaredTasks) && declaredTasks.length > children.length) return false;\n return children.every((child) => TERMINAL_RUN_STATES.includes(child.runState ?? \"\"));\n};\n\n/** How many sub-agents spawned by this message are still working. */\nexport const countOutstandingChildren = (message: ChatMessage): number => {\n const children = message.delegatedConversations ?? [];\n if (children.length > 0) {\n return children.filter((child) => !TERMINAL_RUN_STATES.includes(child.runState ?? \"\")).length;\n }\n if (message.toolCall?.name !== DELEGATE_TOOL_NAME) {\n return 0;\n }\n // A NEW row (one `delegate` call = one sub-agent) carries its own run record instead of\n // `delegatedConversations`; no child expanded, so the record's CURRENT run is the truth of whether it is done.\n const subAgent = message.subAgent;\n if (subAgent != null) {\n const currentRun = (subAgent.runs ?? []).find((run) => run.runNumber === subAgent.currentRunNumber);\n return currentRun != null && UNRESOLVED_RUN_STATUSES.includes(currentRun.status ?? \"\") ? 1 : 0;\n }\n if (isResolved(message.toolCall?.status)) {\n return 0;\n }\n const declaredTasks = (message.toolCall?.arguments as { tasks?: unknown[] } | undefined)?.tasks;\n return Array.isArray(declaredTasks) && declaredTasks.length > 0 ? declaredTasks.length : 1;\n};\n\n/** A tool call whose result is still to come — its progress lives in `toolCall.status`, never in the row's status. */\nexport const hasUnresolvedToolCall = (message: ChatMessage): boolean =>\n message.toolCall != null && !isEffectivelyResolved(message);\n\n/** Whether this message's delegation can still change: a child is still working, or the call is not resolved yet. */\nexport const hasDelegationInFlight = (message: ChatMessage): boolean =>\n countOutstandingChildren(message) > 0 ||\n (message.toolCall?.name === DELEGATE_TOOL_NAME && !isEffectivelyResolved(message));\n\nexport type AgentActivity = {\n /** Whether a turn is in flight — drives the indicator's visibility (ConversationView aiThinking). */\n active: boolean;\n /**\n * Translation source string for \"what the agent is doing right now\" (empty when nothing to show). Rendered through\n * the chat's `Text`, so this is the translatable key with %placeholders% — NOT pre-interpolated. The dynamic values\n * arrive via {@link AgentActivity.replacements} and plural form via {@link AgentActivity.context}.\n */\n label: string;\n /** Dynamic values substituted into the %placeholders% of {@link AgentActivity.label} by <Text>. */\n replacements?: Record<string, string | number>;\n /** Plural selector for <Text> when the label is count-dependent. */\n context?: \"one\" | \"other\";\n /** A non-delegate tool is running → show the ASCII wrench spinner instead of a text label. */\n toolRunning?: boolean;\n};\n\n/**\n * Derive \"what the agent is doing right now\" for the agent activity indicator PURELY from the\n * live conversation data: the message tree (refreshed on each realtime-signal tick / on open) plus the signal's\n * coarse runStatus (\"running\" | \"idle\" | \"failed\" | null). No network. Mirrors the backend truth —\n * AIConversation.runState (IDLE/RUNNING/AWAITING_DELEGATES/…) and per-message status/messageType/toolCall — but reads\n * it off the messages the FE already holds, so the indicator is correct even before the first signal emission.\n */\nexport const deriveAgentActivity = (\n messages: ChatMessage[] | null,\n runStatus: string | null,\n): AgentActivity => {\n if (runStatus === \"failed\") {\n // Failure surfaces via ConversationView's error state, not the activity line.\n return { active: false, label: \"\" };\n }\n\n // An optimistic (just-sent, not yet server-assigned) row carries no index — it belongs at the TAIL, the newest\n // thing in the conversation, never at the front, where `?? 0` would park it ahead of every real message.\n const sorted = [...(messages ?? [])].filter((message) => !isRowThatOwesNoWork(message)).sort(\n (a, b) => (a.indexInConversation ?? Number.POSITIVE_INFINITY) - (b.indexInConversation ?? Number.POSITIVE_INFINITY),\n );\n const lastMessage = sorted[sorted.length - 1];\n\n // The owner just sent — the optimistic bubble, or a saved row still awaiting the first response — starts the face\n // thinking immediately, before the server's \"running\" ping arrives (which can lag the send by about a second);\n // checked before the `idle` short-circuit below, whose `runStatus` can still report the PREVIOUS turn's rest state.\n // A rejected POST resets `aiThinking` itself (conversations-message-post.case.ts), so no separate reset is needed.\n if (lastMessage?.role === \"USER\") {\n return { active: true, label: \"\" };\n }\n\n // Sub-agents still working → the orchestrator is parked on its children (backend runState AWAITING_DELEGATES).\n // Counted per CHILD, not per delegate message: a fan-out (`delegate` with N tasks, or a tool result carrying\n // `delegationTasks`, e.g. a LARGE website edit's page packets) is ONE message with N children. The expanded\n // `delegatedConversations` carry each child's runState; without the expand, a `delegate` call still awaiting its\n // verdict counts its declared tasks, else one.\n const unresolvedDelegateCount = sorted.reduce((count, message) => count + countOutstandingChildren(message), 0);\n\n // The turn is at rest and nothing is outstanding → idle, no indicator.\n if (runStatus === \"idle\" && unresolvedDelegateCount === 0) {\n return { active: false, label: \"\" };\n }\n\n if (unresolvedDelegateCount > 0) {\n return {\n active: true,\n label: textKey(\"Waiting for %count% delegations...\"),\n replacements: { count: unresolvedDelegateCount },\n context: unresolvedDelegateCount === 1 ? \"one\" : \"other\",\n };\n }\n\n // A tool-call that hasn't resolved yet → that tool is running now (a delegate call whose children all finished\n // is resolved in effect, whatever its stored status says).\n if (lastMessage?.messageType === \"TOOL_CALL\" && !isEffectivelyResolved(lastMessage)) {\n return {\n active: true,\n label: textKey(\"Running: %tool%...\"),\n replacements: { tool: lastMessage.toolCall?.name ?? \"Tool\" },\n toolRunning: true,\n };\n }\n\n // The model is producing a turn (signal running) — a trailing owner row was already caught above.\n if (runStatus === \"running\") {\n return { active: true, label: \"\" };\n }\n\n return { active: false, label: \"\" };\n};\n","import type { ChangedMessagesRequest, ConversationMessageStatus } from \"../../contract/conversation\";\nimport type { ChatMessage } from \"../chat-message\";\nimport { hasDelegationInFlight, hasUnresolvedToolCall } from \"./derive-agent-activity\";\n\n/** Row statuses that are not final yet (today only a waiting signal row carries one, PENDING until a turn reads it). */\nconst CHANGING_STATUSES: string[] = [\"PENDING\", \"RUNNING\", \"CANCEL_REQUESTED\"] satisfies ConversationMessageStatus[];\n\nconst canStillChange = (message: ChatMessage): boolean =>\n CHANGING_STATUSES.includes(message.status ?? \"\") || hasUnresolvedToolCall(message) || hasDelegationInFlight(message);\n\n/**\n * What a live update reads, given the loaded messages: every row written since the newest loaded one, plus every\n * message from the lowest one that can still change. \"Written since\" goes by id, not index: ids grow with every write,\n * while an index can be taken below the newest loaded one (a call row persisted after the row its execution emitted)\n * or reused (a re-drive after an admin delete-from). The index start never lies below the newest page (a newest-first\n * page of `pageSize` cannot return older rows anyway), so a row a dead worker left pending cannot pin it. Nothing\n * loaded yet → null: the caller reads the newest page as on open. How the request reaches the wire (the filter string)\n * is the binding's matter (`AgentsConversationClient.getChangedMessages`).\n */\nexport const buildChangedMessagesRequest = (\n messages: ChatMessage[] | null,\n pageSize: number,\n): ChangedMessagesRequest | null => {\n const loaded = (messages ?? []).filter((message) => message.indexInConversation != null);\n if (loaded.length === 0) {\n return null;\n }\n const indexes = (list: ChatMessage[]) => list.map((message) => message.indexInConversation as number);\n const highestIndex = Math.max(...indexes(loaded));\n const changing = loaded.filter(canStillChange);\n const fromIndex = Math.max(\n changing.length > 0 ? Math.min(...indexes(changing)) : highestIndex + 1,\n highestIndex - pageSize + 1,\n );\n const highestKnownId = Math.max(...loaded.map((message) => message.id ?? 0));\n return { highestKnownId, fromIndex, pageSize };\n};\n"],"names":[],"mappings":";;;;AAGO,MAAM,sCAAyD,CAAC,sBAAsB,kBAAkB;AAE/G,MAAM,yCAAyC;AAE/C,MAAM,wCAAwC;AAE9C,MAAM,8CAA8C;AAK7C,MAAM,kCAAqD;AAAA,EAChE,GAAG;AAAA,EACH;AAAA,EACA;AAAA,EACA;AACF;AAeO,MAAM,yCAAyC,CAAC,aAA4C;AACjG,MAAI,CAAC,UAAU,QAAQ;AACrB,WAAO;AAAA,EACT;AACA,QAAM,SAAS,CAAC,GAAG,QAAQ,EAAE,KAAK,CAAC,GAAG,OAAO,EAAE,uBAAuB,MAAM,EAAE,uBAAuB,EAAE;AACvG,WAAS,WAAW,OAAO,SAAS,GAAG,YAAY,GAAG,YAAY;AAChE,UAAM,UAAU,OAAO,QAAQ;AAC/B,QACE,QAAQ,gBAAgB,WACxB,QAAQ,gBAAgB,gBACxB,QAAQ,gBAAgB,gBACxB;AACA;AAAA,IACF;AACA,QAAI,QAAQ,gBAAgB,UAAU;AACpC,UAAI,gCAAgC,SAAS,QAAQ,gBAAgB,EAAE,GAAG;AACxE;A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src/contract/conversation.ts"],"sourcesContent":["/**\n * The conversation contract of the package: plain TypeScript types the conversation client port\n * (`client/AgentsConversationClient.ts`) returns and the chat reads. Every field is derived from what the chat files and\n * the chat controller read from the server today (the host application's generated `AIConversation`, `AIConversationMessage`,\n * `AgentActivityLine`, `SemanticSearchHit`, `AIConversationSearchGroup`, `AgentCustomerSelectableModel`); nothing the\n * chat does not read is here.\n *\n * Naming: a field keeps the wire name where the name is neutral (`message`, `indexInConversation`, `role`, `status`,\n * `toolCall`); a name that carries an app's vocabulary is renamed (`aiConversationId` → `conversationId`,\n * the app's own key of the thing the agent works for → `agentSpaceKey`, `summary.title` → `title`). Each field carries a\n * one-line note:\n * - `generic` — every app that runs the agent conversation backend has it;\n * - `app extension` — read by the chat today but specific to one app's backend or debug surface; optional, and a\n * binding may leave it out.\n *\n * Client-side state is NOT part of the contract: the `fresh` tag of a live-arrived message, the optimistic user\n * message without an id and the `isNewConversation` / `isReopenedConversation` flags belong to the package store.\n */\n\n// ── Vocabulary ───────────────────────────────────────────────────────────────────────────────────────────────────\n\n/** The run state of a conversation as the server stores it (`AIConversationRunState`). */\nexport type ConversationRunState =\n | \"IDLE\"\n | \"QUEUED\"\n | \"RUNNING\"\n | \"AWAITING_DELEGATES\"\n | \"FAILED\"\n | \"COMPLETED\"\n | \"CANCELLED\";\n\n/** The three-value run status the live-update signal speaks; the chat keys its indicator and error card off it. */\nexport type ConversationRunStatus = \"running\" | \"idle\" | \"failed\";\n\nexport type ConversationMessageRole = \"SYSTEM\" | \"USER\" | \"ASSISTANT\";\n\nexport type ConversationMessageType = \"TEXT\" | \"TOOL_CALL\" | \"CHECKPOINT\" | \"ERROR\" | \"SIGNAL\" | \"TOOL_MESSAGE\";\n\nexport type ConversationMessageStatus =\n | \"PENDING\"\n | \"RUNNING\"\n | \"CANCEL_REQUESTED\"\n | \"CANCELLED\"\n | \"COMPLETED\"\n | \"FAILED\";\n\nexport type ConversationMessageAuthorType = \"USER\" | \"ASSISTANT\" | \"AGENT\" | \"TOOL\";\n\n/** Run states after which nothing runs any more and the server refuses further customer input. */\nexport const CONVERSATION_RUN_STATES_THAT_END_THE_CONVERSATION: readonly ConversationRunState[] = [\n \"COMPLETED\",\n \"CANCELLED\",\n];\n\n/** Maps a stored run state onto the signal's three-value status (`runStateToSignalStatus` of the live-update hook). */\nexport const readConversationRunStatusOfRunState = (\n runState: string | null | undefined,\n): ConversationRunStatus | null => {\n if (!runState) return null;\n if (runState === \"FAILED\") return \"failed\";\n if (runState === \"RUNNING\" || runState === \"AWAITING_DELEGATES\" || runState === \"QUEUED\") return \"running\";\n return \"idle\";\n};\n\n// ── Conversation ─────────────────────────────────────────────────────────────────────────────────────────────────\n\n/** One step of the progress stepper a purposed conversation declares (`CustomerProgressStep`). */\nexport interface ConversationProgressStep {\n /** generic */\n key: string;\n /** generic — already in the owner's language */\n label: string;\n /** generic */\n status: \"done\" | \"active\" | \"upcoming\";\n}\n\n/** A conversation as the chat, the conversation list and the window around the chat read it. */\nexport interface AgentsConversation {\n /** generic */\n id: number;\n /** generic — the key of the agent space the conversation belongs to */\n agentSpaceKey: number | null;\n /** generic */\n runState: ConversationRunState | null;\n /**\n * generic — set while the server owes a turn on an IDLE conversation (a failed hand-over the recovery re-drives);\n * an IDLE conversation with this set counts as running (`effectiveRunState`)\n */\n agentTurnOwedAt: string | null;\n /** generic — the display title (`summary.title`); null until the first title was generated */\n title: string | null;\n /** generic — the owner set the title by hand; the generated title never replaces it then */\n titleManuallyEdited: boolean;\n /** generic — the generated summary of what the conversation is about (`summary.text`); null until generated */\n summary: string | null;\n /** generic — when the conversation was created, in the server's date-time format */\n created: string | null;\n /** generic — when the conversation was last modified, in the server's date-time format */\n updated: string | null;\n /** generic — the purpose of a purposed conversation (e.g. `Example.Build`, a first-run setup purpose); null otherwise */\n purposeName: string | null;\n /** generic — who started the conversation (`SCHEDULE` for a run of a scheduled task) */\n initiatorType: string | null;\n /** generic — the scheduled task a `SCHEDULE` conversation is a run of */\n scheduleId: number | null;\n /** generic — the entry point a start came from; a start from the same entry point reopens this conversation */\n entryPointKey: string | null;\n /** generic — empty unless the purpose declares a progress stepper */\n progressSteps: ConversationProgressStep[];\n /**\n * generic — the id of the newest stored message; null before the first. The polling default of the live updates\n * (`client/polling/`) reads it to see a new message while the run status stays the same, and hands it to the rules as\n * the signal's `lastMessageId`. Optional: a binding with a push transport may leave it out (the host application's metadata\n * read does not carry it); without it the poller treats every poll of a running turn as a change.\n */\n lastMessageId?: number | null;\n /** app extension — the prompt extension of the host application's older AI-Extensions chat */\n promptExtensionId?: number | null;\n /** app extension — the category of that prompt extension (its colour and product name in the conversation list) */\n promptExtensionCategory?: { alias: string | null; name: string | null } | null;\n}\n\n/**\n * What the server's run-state read answers (`GET …/{id}/runState`): the lean subset of a conversation the live updates\n * poll. Every `AgentsConversation` is one, so a binding without the read may answer it with the metadata read.\n */\nexport type ConversationRunStateRead = Pick<\n AgentsConversation,\n \"id\" | \"runState\" | \"agentTurnOwedAt\" | \"title\" | \"titleManuallyEdited\" | \"summary\" | \"updated\"\n> & {\n /** generic — the id of the newest stored message; null before the first */\n lastMessageId?: number | null;\n};\n\n// ── Messages ─────────────────────────────────────────────────────────────────────────────────────────────────────\n\n/** A sub-agent conversation a delegation started, as far as the chat reads it (`delegatedConversations(select=id,runState)`). */\nexport interface ConversationDelegatedConversation {\n /** generic */\n id: number;\n /** generic */\n runState: ConversationRunState | null;\n}\n\n/** One run of a sub-agent, as the activity derivation reads it (`DelegationSubAgentRun`). */\nexport interface ConversationSubAgentRun {\n /** generic */\n runNumber: number | null;\n /** generic */\n status: string | null;\n}\n\n/** The sub-agent record a newer `delegate` call row carries instead of expanded children (`DelegationSubAgentRecord`). */\nexport interface ConversationSubAgent {\n /** generic */\n currentRunNumber: number | null;\n /** generic */\n runs: ConversationSubAgentRun[];\n}\n\n/** The tool call a `TOOL_CALL` row carries, as far as the chat reads it. */\nexport interface ConversationToolCall {\n /** generic */\n toolCallId: string | null;\n /** generic */\n name: string | null;\n /** generic — the call's arguments as the model wrote them (the `delegate` call's `tasks` is read) */\n arguments: unknown;\n /** generic — the call's own progress; a row's `status` says nothing about it */\n status: string | null;\n}\n\n/** The admin debug numbers of one message (the message forensics panel). */\nexport interface ConversationMessageForensics {\n /** app extension */\n inputTokens: number | null;\n /** app extension */\n outputTokens: number | null;\n /** app extension */\n costInUSD: number | null;\n /** app extension — the stored request snapshot of the model call (model name, reasoning effort, sent at) */\n requestSnapshot: unknown;\n}\n\n/** One stored message of a conversation. */\nexport interface AgentsConversationMessage {\n /** generic */\n id: number;\n /** generic */\n conversationId: number | null;\n /** generic — the position in the conversation; the merge key of every page */\n indexInConversation: number | null;\n /** generic */\n role: ConversationMessageRole | null;\n /** generic */\n messageType: ConversationMessageType | null;\n /** generic — non-final only on a waiting signal row */\n status: ConversationMessageStatus | null;\n /** generic */\n authorType: ConversationMessageAuthorType | null;\n /** generic — the source of a SIGNAL or ERROR row (`AI_BUDGET_REACHED`, `FRONTEND_WIDGET_CLICK`, …) */\n signalSource: string | null;\n /** generic — the text in markdown, widget blocks included */\n message: string;\n /** generic */\n createdDate: string | null;\n /** generic */\n toolCall: ConversationToolCall | null;\n /** generic — the sub-agent conversations a `delegate` call started (older rows) */\n delegatedConversations: ConversationDelegatedConversation[];\n /** generic — the sub-agent record of a `delegate` call (newer rows) */\n subAgent: ConversationSubAgent | null;\n /** app extension — admin debug numbers; absent outside the admin surfaces */\n forensics?: ConversationMessageForensics;\n}\n\n/** A file from the app's media library that rides along with a message. */\nexport interface ConversationAttachmentReference {\n /** generic — the app's id of the file (host application: the media manager file id) */\n fileId: string | number | null;\n /** generic */\n fileName: string | null;\n /** generic — a URL the model and the tools can fetch */\n publicUrl: string | null;\n}\n\n// ── Pages and results of the port ────────────────────────────────────────────────────────────────────────────────\n\n/** A page of messages read newest first (the newest page on open, an older page on scroll-up). */\nexport interface ConversationMessagesPage {\n /** generic — in any order; the store merges by `indexInConversation` */\n messages: AgentsConversationMessage[];\n /** generic — an older page exists */\n hasMoreOlder: boolean;\n}\n\n/**\n * What a live update reads: every message written since the newest known id, plus every message from the lowest\n * loaded index that can still change (`build-live-refetch-query.ts`). The package computes both values.\n */\nexport interface ChangedMessagesRequest {\n /** generic — the highest message id loaded */\n highestKnownId: number;\n /** generic — the lowest index that can still change, never below the newest page */\n fromIndex: number;\n /** generic — the page size of the read; the binding's default (host application: 50, as the chat sends) when omitted */\n pageSize?: number;\n}\n\n/** The answer of a changed-messages read; it says nothing about older pages (the store keeps `hasMoreOlder`). */\nexport interface ChangedConversationMessages {\n /** generic */\n messages: AgentsConversationMessage[];\n}\n\n/** The answer of a start: the new conversation with what it holds so far, or the reopened one of the entry point. */\nexport interface StartedConversation {\n /** generic */\n conversation: AgentsConversation;\n /** generic — the stored messages of a new conversation; empty for a reopened one (the chat reads its newest page) */\n messages: AgentsConversationMessage[];\n /** generic — the start returned the recent conversation of its entry point; nothing was appended, no turn started */\n reopenedExisting: boolean;\n}\n\n/**\n * The record a conversation is about: the entity class as the record's `objectType` and its id. The server checks\n * both (a class the application does not allow and a record the user cannot read answer 404).\n */\nexport interface ConversationSubject {\n /** generic — the record's entity class, e.g. `App\\\\Domain\\\\Support\\\\Entities\\\\Tickets\\\\SupportTicket` */\n entityClass: string;\n /** generic */\n entityId: number;\n}\n\n/** The record a purposed conversation works on ({@link ConversationSubject}); the name of before free conversations had subjects. */\nexport type PurposeSubject = ConversationSubject;\n\n/**\n * The record one conversation is bound to, with what the application said about it when the conversation started:\n * its display name and where the owner opens it. `purposeId` is null for a free conversation about the record.\n */\nexport interface BoundConversationSubject extends ConversationSubject {\n /** generic — the conversation that is bound to the record; null for a record named without a conversation */\n conversationId: number | null;\n /** generic — the record's display name when the conversation started; data, never markup */\n name: string | null;\n /** generic — an absolute URL or a path of the application */\n link: string | null;\n /** generic — the purpose of a purposed conversation for the record */\n purposeId: string | null;\n}\n\n/**\n * The user's conversations about one record (`listConversationsOfSubject`) and the record itself as the application\n * names it now: `subject` carries its name and link (no purpose), also when no conversation about it exists yet;\n * null when the answer named no record.\n */\nexport interface ConversationsOfSubject {\n subject: BoundConversationSubject | null;\n /** generic — root conversations, newest first */\n conversations: AgentsConversation[];\n}\n\n/** The start of a purposed conversation (`startPurpose`). */\nexport interface PurposeStartRequest {\n /** generic — the purpose's name, e.g. `Support.AnswerTicket` */\n purposeId: string;\n /** generic — the space the purpose runs in; omitted when the application's route answers its own space */\n agentSpaceKey?: number;\n /** generic — with a subject the open conversation of the same space, purpose and record is reopened */\n subject?: PurposeSubject;\n /** generic — text added to the kickoff of a NEW conversation (at most 4,000 characters) */\n prefill?: string;\n}\n\n/** The conversation a purposed start opened or reopened; the client opens it by its id. */\nexport interface StartedPurposeConversation {\n /** generic */\n conversationId: number;\n /** generic — the open conversation of the same space, purpose (and subject) was reopened */\n resumedExisting: boolean;\n /** generic — the prefill reached the kickoff (false on a reopen and without a prefill) */\n prefillDelivered: boolean;\n}\n\n/** The answer of a post: the conversation's messages so far (the reply arrives through live updates). */\nexport interface PostedMessage {\n /** generic */\n messages: AgentsConversationMessage[];\n}\n\n/** A model-visible, owner-invisible note into a conversation (a widget click, a render report, a correction). */\n/**\n * What the owner's client shows while the owner writes: the route, its parameters, the record on screen and the tab.\n * Sent with a start, a posted message and an injected signal; the server stores it on that owner row and the agent reads\n * the newest one as one line beside the owner's newest message. Each field is optional and capped\n * ({@link AGENTS_CLIENT_CONTEXT_LIMITS}); the server refuses a request with a field over its cap (HTTP 400).\n */\nexport interface AgentsClientContext {\n /** The path of the route the client shows, e.g. `/tickets/42`. */\n routePath?: string | null;\n /** The parameters of that route by name, values as text. */\n routeParameters?: Record<string, string> | null;\n /** The kind of the record on screen, as the application names it, e.g. `ticket`. */\n recordKind?: string | null;\n /** The id of the record on screen. */\n recordId?: string | number | null;\n /** The tab the client shows. */\n tab?: string | null;\n}\n\n/** The caps of {@link AgentsClientContext} (characters; the route parameters as their `name=value&…` text). */\nexport const AGENTS_CLIENT_CONTEXT_LIMITS = {\n routePathChars: 512,\n routeParametersChars: 512,\n routeParameterCount: 20,\n recordKindChars: 64,\n recordIdChars: 128,\n tabChars: 64,\n} as const;\n\nexport interface ConversationSignal {\n /** generic */\n text: string;\n /** generic — the signal source; the server's default applies when omitted (a widget click) */\n source?: string;\n}\n\n/** How a list read pages and which conversations it includes. */\nexport interface ConversationListQueryOptions {\n /** generic — include conversations that have no summary (title) yet, e.g. a just-started one */\n includeUnsummarized?: boolean;\n /** generic — the host application's history reads the newest 50 */\n paging?: { top?: number; skip?: number };\n}\n\n/** The size of a search answer. */\nexport interface ConversationSearchOptions {\n /** generic — the most groups (or hits) returned; the host application's chat asks for 10 */\n limit?: number;\n /** generic — the excerpt length in characters; the host application's chat asks for 420 */\n excerptLength?: number;\n}\n\n/** app extension — the reconstructed request a model call was sent with (the admin details panel); opaque data. */\nexport type ConversationMessageSentPayload = unknown[];\n\n/** One matched message of a message search (`SemanticSearchHit`). */\nexport interface ConversationMessageSearchHit {\n /** generic */\n messageId: number | null;\n /** generic */\n conversationId: number | null;\n /** generic */\n indexInConversation: number | null;\n /** generic */\n role: string | null;\n /** generic */\n excerpt: string;\n /** generic */\n relevance: number;\n /** generic */\n created: string | null;\n /** generic */\n updated: string | null;\n /** generic — the conversation's title */\n title: string | null;\n}\n\n/** One conversation of a search across conversations, with its matched messages (`AIConversationSearchGroup`). */\nexport interface ConversationSearchGroup {\n /** generic */\n conversationId: number | null;\n /** generic */\n title: string | null;\n /** generic */\n summary: string | null;\n /** generic */\n created: string | null;\n /** generic */\n updated: string | null;\n /** generic */\n relevance: number;\n /** generic */\n hits: ConversationMessageSearchHit[];\n}\n\n/** One generated line of what the agent is doing (`AgentActivityLine`). */\nexport interface ConversationActivityElement {\n /** generic — the row the line narrates; the merge key */\n toolCallMessageId: number;\n /** generic */\n batchId: string | null;\n /** generic */\n state: \"queued\" | \"running\" | \"finished\" | \"failed\" | \"skipped\" | null;\n /** generic */\n kind: \"tool\" | \"delegation\" | \"background\" | \"long\" | \"turnStart\" | null;\n /** generic */\n childCount: number | null;\n /** generic — the 1-based delegation helper that ran the step; null for the assistant's own steps */\n helperIndex: number | null;\n /** generic — the sentence; null while the narrator has not answered */\n line: string | null;\n}\n\n/** The activity of one turn (`GET …/activity`). */\nexport interface ConversationActivity {\n /** generic — the message that started the narrated turn */\n turnMessageId: number | null;\n /** generic */\n turnRunning: boolean;\n /** generic */\n elements: ConversationActivityElement[];\n}\n\n/** A model the owner (host application: an impersonating admin) may pick for the next turns (`AgentCustomerSelectableModel`). */\nexport interface SelectableModel {\n /** generic — the name a send carries */\n name: string;\n /** generic */\n displayName: string;\n /** generic */\n description: string;\n /** generic */\n strengthLevel: number | null;\n /** generic */\n speedLevel: number | null;\n /** app extension — the host application's credit multiplier of the model */\n creditsMultiplier?: number | null;\n}\n\n// ── Live updates ─────────────────────────────────────────────────────────────────────────────────────────────────\n\n/**\n * What a live update carries: a claim check, never content. The chat reads the conversation again when\n * `changeCounter` advances, at once on a terminal status, and until `lastMessageId` is loaded.\n */\nexport interface ConversationChangeSignal {\n /** generic — advances on every change of the conversation */\n changeCounter: number;\n /** generic — the newest message the server wrote; null before the first */\n lastMessageId: number | null;\n /** generic */\n runStatus: ConversationRunStatus | null;\n /** generic — advances when the title or summary was generated again (a light metadata read is enough then) */\n summaryUpdatedAt: number | null;\n /**\n * generic — the binding produced this emission from a run-state read, not from a pushed change (a binding without\n * push, or a push transport whose path is not proven readable, or a check that corrects a stale status). It carries\n * only `runStatus` as news: `changeCounter`, `lastMessageId` and `summaryUpdatedAt` repeat the last pushed values\n * (before any push: a counter that counts down from -1, never equal to a pushed one). The package sets the status\n * from it and reads the conversation again on a status change while the push path is not alive (`isPushPathAlive`).\n */\n isStatusCheck?: boolean;\n /**\n * generic, on a status-check emission — the binding's push path delivers: a pushed change arrived and the path was not\n * denied since. False after a denied read until a push arrives again; then the status checks are the live path and a\n * status change reads the conversation again. A binding without push leaves it out: the package then counts the\n * pushed changes it saw itself.\n */\n isPushPathAlive?: boolean;\n}\n\n/** Why a subscription ended for good: the conversation was deleted or is no longer readable, or the account lost access. */\nexport type ConversationSubscriptionEndReason = \"gone\" | \"forbidden\";\n\n// ── Errors ───────────────────────────────────────────────────────────────────────────────────────────────────────\n\n/**\n * What went wrong, as the chat tells the owner. The codes the chat's error handling reads today map\n * onto it: `AI_BUDGET_REACHED` → `budget`, HTTP 429 / `RATE_LIMIT_EXCEEDED` → `rateLimit`, `CONVERSATION_CLOSED` →\n * `closed`, the not-found and no-access answers → `notFound` / `forbidden` (`conversation-not-found.ts`), no answer or a\n * server failure → `network`, everything else (a refused retry, a cancelled request) → `other` with its `code`.\n */\nexport type AgentsClientErrorKind = \"budget\" | \"rateLimit\" | \"closed\" | \"notFound\" | \"forbidden\" | \"network\" | \"other\";\n\n/** The code `other` carries for a request the client cancelled; the chat shows no error card for it. */\nexport const AGENTS_CLIENT_ERROR_CODE_REQUEST_ABORTED = \"REQUEST_ABORTED\";\n\n/** The one error shape every port function rejects with. */\nexport class AgentsClientError extends Error {\n readonly kind: AgentsClientErrorKind;\n /** The server's stable error code, or the client's own code (`REQUEST_ABORTED`); null when none arrived. */\n readonly code: string | null;\n /** Seconds until a quota frees up again; set only for `rateLimit`. */\n readonly retryAfterSeconds: number | null;\n /** The HTTP status when one arrived (not part of the contract's shape; kept for diagnostics). */\n readonly httpStatus: number | null;\n\n constructor(\n kind: AgentsClientErrorKind,\n details: { message?: string; code?: string | null; retryAfterSeconds?: number | null; httpStatus?: number | null } = {},\n ) {\n super(details.message ?? kind);\n this.name = \"AgentsClientError\";\n this.kind = kind;\n this.code = details.code ?? null;\n this.retryAfterSeconds = kind === \"rateLimit\" ? (details.retryAfterSeconds ?? null) : null;\n this.httpStatus = details.httpStatus ?? null;\n }\n}\n\nexport const isAgentsClientError = (value: unknown): value is AgentsClientError => value instanceof AgentsClientError;\n"],"names":[],"mappings":";AAiDO,MAAM,oDAAqF;AAAA,EAChG;AAAA,EACA;AACF;AAGO,MAAM,sCAAsC,CACjD,aACiC;AACjC,MAAI,CAAC,SAAU,QAAO;AACtB,MAAI,aAAa,SAAU,QAAO;AAClC,MAAI,aAAa,aAAa,aAAa,wBAAwB,aAAa,SAAU,QAAO;AACjG,SAAO;AACT;AAoSO,MAAM,+BAA+B;AAAA,EAC1C,gBAAgB;AAAA,EAChB,sBAAsB;AAAA,EACtB,qBAAqB;AAAA,EACrB,iBAAiB;AAAA,EACjB,eAAe;AAAA,EACf,UAAU;AACZ;AA8JO,MAAM,2CAA2C;AAGjD,MAAM,0BAA0B,MAAM;AAAA,EAS3C,YACE,MACA,UAAqH,IACrH;AACA,UAAM,QAAQ,WAAW,IAAI;AAC7B,SAAK,OAAO;AACZ,SAAK,OAAO;AACZ,SAAK,OAAO,QAAQ,QAAQ;AAC5B,SAAK,oBAAoB,SAAS,cAAe,QAAQ,qBAAqB,OAAQ;AACtF,SAAK,aAAa,QAAQ,cAAc;AAAA,EAC1C;AACF;AAEO,MAAM,sBAAsB,CAAC,UAA+C,iBAAiB;"}
1
+ {"version":3,"file":"conversation-B7-evdj_.js","sources":["../../src/contract/conversation.ts"],"sourcesContent":["import type { ConversationTraceViewPolicy } from \"./conversation-trace\";\n/**\n * The conversation contract of the package: plain TypeScript types the conversation client port\n * (`client/AgentsConversationClient.ts`) returns and the chat reads. Every field is derived from what the chat files and\n * the chat controller read from the server today (the host application's generated `AIConversation`, `AIConversationMessage`,\n * `AgentActivityLine`, `SemanticSearchHit`, `AIConversationSearchGroup`, `AgentCustomerSelectableModel`); nothing the\n * chat does not read is here.\n *\n * Naming: a field keeps the wire name where the name is neutral (`message`, `indexInConversation`, `role`, `status`,\n * `toolCall`); a name that carries an app's vocabulary is renamed (`aiConversationId` → `conversationId`,\n * the app's own key of the thing the agent works for → `agentSpaceKey`, `summary.title` → `title`). Each field carries a\n * one-line note:\n * - `generic` — every app that runs the agent conversation backend has it;\n * - `app extension` — read by the chat today but specific to one app's backend or debug surface; optional, and a\n * binding may leave it out.\n *\n * Client-side state is NOT part of the contract: the `fresh` tag of a live-arrived message, the optimistic user\n * message without an id and the `isNewConversation` / `isReopenedConversation` flags belong to the package store.\n */\n\n// ── Vocabulary ───────────────────────────────────────────────────────────────────────────────────────────────────\n\n/** The run state of a conversation as the server stores it (`AIConversationRunState`). */\nexport type ConversationRunState =\n | \"IDLE\"\n | \"QUEUED\"\n | \"RUNNING\"\n | \"AWAITING_DELEGATES\"\n | \"FAILED\"\n | \"COMPLETED\"\n | \"CANCELLED\";\n\n/** The three-value run status the live-update signal speaks; the chat keys its indicator and error card off it. */\nexport type ConversationRunStatus = \"running\" | \"idle\" | \"failed\";\n\nexport type ConversationMessageRole = \"SYSTEM\" | \"USER\" | \"ASSISTANT\";\n\nexport type ConversationMessageType = \"TEXT\" | \"TOOL_CALL\" | \"CHECKPOINT\" | \"ERROR\" | \"SIGNAL\" | \"TOOL_MESSAGE\";\n\nexport type ConversationMessageStatus =\n | \"PENDING\"\n | \"RUNNING\"\n | \"CANCEL_REQUESTED\"\n | \"CANCELLED\"\n | \"COMPLETED\"\n | \"FAILED\";\n\nexport type ConversationMessageAuthorType = \"USER\" | \"ASSISTANT\" | \"AGENT\" | \"TOOL\";\n\n/** Run states after which nothing runs any more and the server refuses further customer input. */\nexport const CONVERSATION_RUN_STATES_THAT_END_THE_CONVERSATION: readonly ConversationRunState[] = [\n \"COMPLETED\",\n \"CANCELLED\",\n];\n\n/** Maps a stored run state onto the signal's three-value status (`runStateToSignalStatus` of the live-update hook). */\nexport const readConversationRunStatusOfRunState = (\n runState: string | null | undefined,\n): ConversationRunStatus | null => {\n if (!runState) return null;\n if (runState === \"FAILED\") return \"failed\";\n if (runState === \"RUNNING\" || runState === \"AWAITING_DELEGATES\" || runState === \"QUEUED\") return \"running\";\n return \"idle\";\n};\n\n// ── Conversation ─────────────────────────────────────────────────────────────────────────────────────────────────\n\n/** One step of the progress stepper a purposed conversation declares (`CustomerProgressStep`). */\nexport interface ConversationProgressStep {\n /** generic */\n key: string;\n /** generic — already in the owner's language */\n label: string;\n /** generic */\n status: \"done\" | \"active\" | \"upcoming\";\n}\n\n/** A conversation as the chat, the conversation list and the window around the chat read it. */\nexport interface AgentsConversation {\n /** generic */\n id: number;\n /** generic — the key of the agent space the conversation belongs to */\n agentSpaceKey: number | null;\n /** generic */\n runState: ConversationRunState | null;\n /**\n * generic — set while the server owes a turn on an IDLE conversation (a failed hand-over the recovery re-drives);\n * an IDLE conversation with this set counts as running (`effectiveRunState`)\n */\n agentTurnOwedAt: string | null;\n /** generic — the display title (`summary.title`); null until the first title was generated */\n title: string | null;\n /** generic — the owner set the title by hand; the generated title never replaces it then */\n titleManuallyEdited: boolean;\n /** generic — the generated summary of what the conversation is about (`summary.text`); null until generated */\n summary: string | null;\n /** generic — when the conversation was created, in the server's date-time format */\n created: string | null;\n /** generic — when the conversation was last modified, in the server's date-time format */\n updated: string | null;\n /** generic — the purpose of a purposed conversation (e.g. `Example.Build`, a first-run setup purpose); null otherwise */\n purposeName: string | null;\n /** generic — who started the conversation (`SCHEDULE` for a run of a scheduled task) */\n initiatorType: string | null;\n /** generic — the scheduled task a `SCHEDULE` conversation is a run of */\n scheduleId: number | null;\n /** generic — the entry point a start came from; a start from the same entry point reopens this conversation */\n entryPointKey: string | null;\n /** generic — empty unless the purpose declares a progress stepper */\n progressSteps: ConversationProgressStep[];\n /**\n * generic — the id of the newest stored message; null before the first. The polling default of the live updates\n * (`client/polling/`) reads it to see a new message while the run status stays the same, and hands it to the rules as\n * the signal's `lastMessageId`. Optional: a binding with a push transport may leave it out (the host application's metadata\n * read does not carry it); without it the poller treats every poll of a running turn as a change.\n */\n lastMessageId?: number | null;\n /**\n * generic — which trace levels the reader may see in this conversation (`ConversationTraceViewPolicy`): the Short /\n * Normal / Verbose switch offers only those. Absent when the read does not carry it (a binding or an older server).\n */\n traceViewPolicy?: ConversationTraceViewPolicy | null;\n /** app extension — the prompt extension of the host application's older AI-Extensions chat */\n promptExtensionId?: number | null;\n /** app extension — the category of that prompt extension (its colour and product name in the conversation list) */\n promptExtensionCategory?: { alias: string | null; name: string | null } | null;\n}\n\n/**\n * What the server's run-state read answers (`GET …/{id}/runState`): the lean subset of a conversation the live updates\n * poll. Every `AgentsConversation` is one, so a binding without the read may answer it with the metadata read.\n */\nexport type ConversationRunStateRead = Pick<\n AgentsConversation,\n \"id\" | \"runState\" | \"agentTurnOwedAt\" | \"title\" | \"titleManuallyEdited\" | \"summary\" | \"updated\"\n> & {\n /** generic — the id of the newest stored message; null before the first */\n lastMessageId?: number | null;\n};\n\n// ── Messages ─────────────────────────────────────────────────────────────────────────────────────────────────────\n\n/** A sub-agent conversation a delegation started, as far as the chat reads it (`delegatedConversations(select=id,runState)`). */\nexport interface ConversationDelegatedConversation {\n /** generic */\n id: number;\n /** generic */\n runState: ConversationRunState | null;\n}\n\n/** One run of a sub-agent, as the activity derivation reads it (`DelegationSubAgentRun`). */\nexport interface ConversationSubAgentRun {\n /** generic */\n runNumber: number | null;\n /** generic */\n status: string | null;\n}\n\n/** The sub-agent record a newer `delegate` call row carries instead of expanded children (`DelegationSubAgentRecord`). */\nexport interface ConversationSubAgent {\n /** generic */\n currentRunNumber: number | null;\n /** generic */\n runs: ConversationSubAgentRun[];\n}\n\n/** The tool call a `TOOL_CALL` row carries, as far as the chat reads it. */\nexport interface ConversationToolCall {\n /** generic */\n toolCallId: string | null;\n /** generic */\n name: string | null;\n /** generic — the call's arguments as the model wrote them (the `delegate` call's `tasks` is read) */\n arguments: unknown;\n /** generic — the call's own progress; a row's `status` says nothing about it */\n status: string | null;\n}\n\n/** The admin debug numbers of one message (the message forensics panel). */\nexport interface ConversationMessageForensics {\n /** app extension */\n inputTokens: number | null;\n /** app extension */\n outputTokens: number | null;\n /** app extension */\n costInUSD: number | null;\n /** app extension — the stored request snapshot of the model call (model name, reasoning effort, sent at) */\n requestSnapshot: unknown;\n}\n\n/** One stored message of a conversation. */\nexport interface AgentsConversationMessage {\n /** generic */\n id: number;\n /** generic */\n conversationId: number | null;\n /** generic — the position in the conversation; the merge key of every page */\n indexInConversation: number | null;\n /** generic */\n role: ConversationMessageRole | null;\n /** generic */\n messageType: ConversationMessageType | null;\n /** generic — non-final only on a waiting signal row */\n status: ConversationMessageStatus | null;\n /** generic */\n authorType: ConversationMessageAuthorType | null;\n /** generic — the source of a SIGNAL or ERROR row (`AI_BUDGET_REACHED`, `FRONTEND_WIDGET_CLICK`, …) */\n signalSource: string | null;\n /** generic — the text in markdown, widget blocks included */\n message: string;\n /** generic */\n createdDate: string | null;\n /**\n * generic — when the message was written, in the server's date-time format (`ChangeHistory.createdTime`, UTC); the\n * chat's day separators, time heads and exact times read it. Absent from a client that does not send it: no times.\n */\n createdAt?: string | null;\n /** generic */\n toolCall: ConversationToolCall | null;\n /** generic — the sub-agent conversations a `delegate` call started (older rows) */\n delegatedConversations: ConversationDelegatedConversation[];\n /** generic — the sub-agent record of a `delegate` call (newer rows) */\n subAgent: ConversationSubAgent | null;\n /** app extension — admin debug numbers; absent outside the admin surfaces */\n forensics?: ConversationMessageForensics;\n}\n\n/** A file from the app's media library that rides along with a message. */\nexport interface ConversationAttachmentReference {\n /** generic — the app's id of the file (host application: the media manager file id) */\n fileId: string | number | null;\n /** generic */\n fileName: string | null;\n /** generic — a URL the model and the tools can fetch */\n publicUrl: string | null;\n}\n\n// ── Pages and results of the port ────────────────────────────────────────────────────────────────────────────────\n\n/** A page of messages read newest first (the newest page on open, an older page on scroll-up). */\nexport interface ConversationMessagesPage {\n /** generic — in any order; the store merges by `indexInConversation` */\n messages: AgentsConversationMessage[];\n /** generic — an older page exists */\n hasMoreOlder: boolean;\n}\n\n/**\n * What a live update reads: every message written since the newest known id, plus every message from the lowest\n * loaded index that can still change (`build-live-refetch-query.ts`). The package computes both values.\n */\nexport interface ChangedMessagesRequest {\n /** generic — the highest message id loaded */\n highestKnownId: number;\n /** generic — the lowest index that can still change, never below the newest page */\n fromIndex: number;\n /** generic — the page size of the read; the binding's default (host application: 50, as the chat sends) when omitted */\n pageSize?: number;\n}\n\n/** The answer of a changed-messages read; it says nothing about older pages (the store keeps `hasMoreOlder`). */\nexport interface ChangedConversationMessages {\n /** generic */\n messages: AgentsConversationMessage[];\n}\n\n/** The answer of a start: the new conversation with what it holds so far, or the reopened one of the entry point. */\nexport interface StartedConversation {\n /** generic */\n conversation: AgentsConversation;\n /** generic — the stored messages of a new conversation; empty for a reopened one (the chat reads its newest page) */\n messages: AgentsConversationMessage[];\n /** generic — the start returned the recent conversation of its entry point; nothing was appended, no turn started */\n reopenedExisting: boolean;\n}\n\n/**\n * The record a conversation is about: the entity class as the record's `objectType` and its id. The server checks\n * both (a class the application does not allow and a record the user cannot read answer 404).\n */\nexport interface ConversationSubject {\n /** generic — the record's entity class, e.g. `App\\\\Domain\\\\Support\\\\Entities\\\\Tickets\\\\SupportTicket` */\n entityClass: string;\n /** generic */\n entityId: number;\n}\n\n/** The record a purposed conversation works on ({@link ConversationSubject}); the name of before free conversations had subjects. */\nexport type PurposeSubject = ConversationSubject;\n\n/**\n * The record one conversation is bound to, with what the application said about it when the conversation started:\n * its display name and where the owner opens it. `purposeId` is null for a free conversation about the record.\n */\nexport interface BoundConversationSubject extends ConversationSubject {\n /** generic — the conversation that is bound to the record; null for a record named without a conversation */\n conversationId: number | null;\n /** generic — the record's display name when the conversation started; data, never markup */\n name: string | null;\n /** generic — an absolute URL or a path of the application */\n link: string | null;\n /** generic — the purpose of a purposed conversation for the record */\n purposeId: string | null;\n}\n\n/**\n * The user's conversations about one record (`listConversationsOfSubject`) and the record itself as the application\n * names it now: `subject` carries its name and link (no purpose), also when no conversation about it exists yet;\n * null when the answer named no record.\n */\nexport interface ConversationsOfSubject {\n subject: BoundConversationSubject | null;\n /** generic — root conversations, newest first */\n conversations: AgentsConversation[];\n}\n\n/** The start of a purposed conversation (`startPurpose`). */\nexport interface PurposeStartRequest {\n /** generic — the purpose's name, e.g. `Support.AnswerTicket` */\n purposeId: string;\n /** generic — the space the purpose runs in; omitted when the application's route answers its own space */\n agentSpaceKey?: number;\n /** generic — with a subject the open conversation of the same space, purpose and record is reopened */\n subject?: PurposeSubject;\n /** generic — text added to the kickoff of a NEW conversation (at most 4,000 characters) */\n prefill?: string;\n}\n\n/** The conversation a purposed start opened or reopened; the client opens it by its id. */\nexport interface StartedPurposeConversation {\n /** generic */\n conversationId: number;\n /** generic — the open conversation of the same space, purpose (and subject) was reopened */\n resumedExisting: boolean;\n /** generic — the prefill reached the kickoff (false on a reopen and without a prefill) */\n prefillDelivered: boolean;\n}\n\n/** The answer of a post: the conversation's messages so far (the reply arrives through live updates). */\nexport interface PostedMessage {\n /** generic */\n messages: AgentsConversationMessage[];\n}\n\n/** A model-visible, owner-invisible note into a conversation (a widget click, a render report, a correction). */\n/**\n * What the owner's client shows while the owner writes: the route, its parameters, the record on screen and the tab.\n * Sent with a start, a posted message and an injected signal; the server stores it on that owner row and the agent reads\n * the newest one as one line beside the owner's newest message. Each field is optional and capped\n * ({@link AGENTS_CLIENT_CONTEXT_LIMITS}); the server refuses a request with a field over its cap (HTTP 400).\n */\nexport interface AgentsClientContext {\n /** The path of the route the client shows, e.g. `/tickets/42`. */\n routePath?: string | null;\n /** The parameters of that route by name, values as text. */\n routeParameters?: Record<string, string> | null;\n /** The kind of the record on screen, as the application names it, e.g. `ticket`. */\n recordKind?: string | null;\n /** The id of the record on screen. */\n recordId?: string | number | null;\n /** The tab the client shows. */\n tab?: string | null;\n}\n\n/** The caps of {@link AgentsClientContext} (characters; the route parameters as their `name=value&…` text). */\nexport const AGENTS_CLIENT_CONTEXT_LIMITS = {\n routePathChars: 512,\n routeParametersChars: 512,\n routeParameterCount: 20,\n recordKindChars: 64,\n recordIdChars: 128,\n tabChars: 64,\n} as const;\n\nexport interface ConversationSignal {\n /** generic */\n text: string;\n /** generic — the signal source; the server's default applies when omitted (a widget click) */\n source?: string;\n}\n\n/** How a list read pages and which conversations it includes. */\nexport interface ConversationListQueryOptions {\n /** generic — include conversations that have no summary (title) yet, e.g. a just-started one */\n includeUnsummarized?: boolean;\n /** generic — the host application's history reads the newest 50 */\n paging?: { top?: number; skip?: number };\n}\n\n/** The size of a search answer. */\nexport interface ConversationSearchOptions {\n /** generic — the most groups (or hits) returned; the host application's chat asks for 10 */\n limit?: number;\n /** generic — the excerpt length in characters; the host application's chat asks for 420 */\n excerptLength?: number;\n}\n\n/** app extension — the reconstructed request a model call was sent with (the admin details panel); opaque data. */\nexport type ConversationMessageSentPayload = unknown[];\n\n/** One matched message of a message search (`SemanticSearchHit`). */\nexport interface ConversationMessageSearchHit {\n /** generic */\n messageId: number | null;\n /** generic */\n conversationId: number | null;\n /** generic */\n indexInConversation: number | null;\n /** generic */\n role: string | null;\n /** generic */\n excerpt: string;\n /** generic */\n relevance: number;\n /** generic */\n created: string | null;\n /** generic */\n updated: string | null;\n /** generic — the conversation's title */\n title: string | null;\n}\n\n/** One conversation of a search across conversations, with its matched messages (`AIConversationSearchGroup`). */\nexport interface ConversationSearchGroup {\n /** generic */\n conversationId: number | null;\n /** generic */\n title: string | null;\n /** generic */\n summary: string | null;\n /** generic */\n created: string | null;\n /** generic */\n updated: string | null;\n /** generic */\n relevance: number;\n /** generic */\n hits: ConversationMessageSearchHit[];\n}\n\n/** One generated line of what the agent is doing (`AgentActivityLine`). */\nexport interface ConversationActivityElement {\n /** generic — the row the line narrates; the merge key */\n toolCallMessageId: number;\n /** generic */\n batchId: string | null;\n /** generic */\n state: \"queued\" | \"running\" | \"finished\" | \"failed\" | \"skipped\" | null;\n /** generic */\n kind: \"tool\" | \"delegation\" | \"background\" | \"long\" | \"turnStart\" | null;\n /** generic */\n childCount: number | null;\n /** generic — the 1-based delegation helper that ran the step; null for the assistant's own steps */\n helperIndex: number | null;\n /** generic — the sentence; null while the narrator has not answered */\n line: string | null;\n}\n\n/** The activity of one turn (`GET …/activity`). */\nexport interface ConversationActivity {\n /** generic — the message that started the narrated turn */\n turnMessageId: number | null;\n /** generic */\n turnRunning: boolean;\n /** generic */\n elements: ConversationActivityElement[];\n}\n\n/** A model the owner (host application: an impersonating admin) may pick for the next turns (`AgentCustomerSelectableModel`). */\nexport interface SelectableModel {\n /** generic — the name a send carries */\n name: string;\n /** generic */\n displayName: string;\n /** generic */\n description: string;\n /** generic */\n strengthLevel: number | null;\n /** generic */\n speedLevel: number | null;\n /** app extension — the host application's credit multiplier of the model */\n creditsMultiplier?: number | null;\n}\n\n// ── Live updates ─────────────────────────────────────────────────────────────────────────────────────────────────\n\n/**\n * What a live update carries: a claim check, never content. The chat reads the conversation again when\n * `changeCounter` advances, at once on a terminal status, and until `lastMessageId` is loaded.\n */\nexport interface ConversationChangeSignal {\n /** generic — advances on every change of the conversation */\n changeCounter: number;\n /** generic — the newest message the server wrote; null before the first */\n lastMessageId: number | null;\n /** generic */\n runStatus: ConversationRunStatus | null;\n /** generic — advances when the title or summary was generated again (a light metadata read is enough then) */\n summaryUpdatedAt: number | null;\n /**\n * generic — the binding produced this emission from a run-state read, not from a pushed change (a binding without\n * push, or a push transport whose path is not proven readable, or a check that corrects a stale status). It carries\n * only `runStatus` as news: `changeCounter`, `lastMessageId` and `summaryUpdatedAt` repeat the last pushed values\n * (before any push: a counter that counts down from -1, never equal to a pushed one). The package sets the status\n * from it and reads the conversation again on a status change while the push path is not alive (`isPushPathAlive`).\n */\n isStatusCheck?: boolean;\n /**\n * generic, on a status-check emission — the binding's push path delivers: a pushed change arrived and the path was not\n * denied since. False after a denied read until a push arrives again; then the status checks are the live path and a\n * status change reads the conversation again. A binding without push leaves it out: the package then counts the\n * pushed changes it saw itself.\n */\n isPushPathAlive?: boolean;\n}\n\n/** Why a subscription ended for good: the conversation was deleted or is no longer readable, or the account lost access. */\nexport type ConversationSubscriptionEndReason = \"gone\" | \"forbidden\";\n\n// ── Errors ───────────────────────────────────────────────────────────────────────────────────────────────────────\n\n/**\n * What went wrong, as the chat tells the owner. The codes the chat's error handling reads today map\n * onto it: `AI_BUDGET_REACHED` → `budget`, HTTP 429 / `RATE_LIMIT_EXCEEDED` → `rateLimit`, `CONVERSATION_CLOSED` →\n * `closed`, the not-found and no-access answers → `notFound` / `forbidden` (`conversation-not-found.ts`), no answer or a\n * server failure → `network`, everything else (a refused retry, a cancelled request) → `other` with its `code`.\n */\nexport type AgentsClientErrorKind = \"budget\" | \"rateLimit\" | \"closed\" | \"notFound\" | \"forbidden\" | \"network\" | \"other\";\n\n/** The code `other` carries for a request the client cancelled; the chat shows no error card for it. */\nexport const AGENTS_CLIENT_ERROR_CODE_REQUEST_ABORTED = \"REQUEST_ABORTED\";\n\n/** The one error shape every port function rejects with. */\nexport class AgentsClientError extends Error {\n readonly kind: AgentsClientErrorKind;\n /** The server's stable error code, or the client's own code (`REQUEST_ABORTED`); null when none arrived. */\n readonly code: string | null;\n /** Seconds until a quota frees up again; set only for `rateLimit`. */\n readonly retryAfterSeconds: number | null;\n /** The HTTP status when one arrived (not part of the contract's shape; kept for diagnostics). */\n readonly httpStatus: number | null;\n\n constructor(\n kind: AgentsClientErrorKind,\n details: { message?: string; code?: string | null; retryAfterSeconds?: number | null; httpStatus?: number | null } = {},\n ) {\n super(details.message ?? kind);\n this.name = \"AgentsClientError\";\n this.kind = kind;\n this.code = details.code ?? null;\n this.retryAfterSeconds = kind === \"rateLimit\" ? (details.retryAfterSeconds ?? null) : null;\n this.httpStatus = details.httpStatus ?? null;\n }\n}\n\nexport const isAgentsClientError = (value: unknown): value is AgentsClientError => value instanceof AgentsClientError;\n"],"names":[],"mappings":";AAkDO,MAAM,oDAAqF;AAAA,EAChG;AAAA,EACA;AACF;AAGO,MAAM,sCAAsC,CACjD,aACiC;AACjC,MAAI,CAAC,SAAU,QAAO;AACtB,MAAI,aAAa,SAAU,QAAO;AAClC,MAAI,aAAa,aAAa,aAAa,wBAAwB,aAAa,SAAU,QAAO;AACjG,SAAO;AACT;AA8SO,MAAM,+BAA+B;AAAA,EAC1C,gBAAgB;AAAA,EAChB,sBAAsB;AAAA,EACtB,qBAAqB;AAAA,EACrB,iBAAiB;AAAA,EACjB,eAAe;AAAA,EACf,UAAU;AACZ;AA8JO,MAAM,2CAA2C;AAGjD,MAAM,0BAA0B,MAAM;AAAA,EAS3C,YACE,MACA,UAAqH,IACrH;AACA,UAAM,QAAQ,WAAW,IAAI;AAC7B,SAAK,OAAO;AACZ,SAAK,OAAO;AACZ,SAAK,OAAO,QAAQ,QAAQ;AAC5B,SAAK,oBAAoB,SAAS,cAAe,QAAQ,qBAAqB,OAAQ;AACtF,SAAK,aAAa,QAAQ,cAAc;AAAA,EAC1C;AACF;AAEO,MAAM,sBAAsB,CAAC,UAA+C,iBAAiB;"}
@@ -0,0 +1,6 @@
1
+ "use client";
2
+ const CONVERSATION_TRACE_LEVELS = ["RESULT", "STEPS", "DEBUG"];
3
+ export {
4
+ CONVERSATION_TRACE_LEVELS as C
5
+ };
6
+ //# sourceMappingURL=conversation-trace-fVeh6Lg6.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"conversation-trace-fVeh6Lg6.js","sources":["../../src/contract/conversation-trace.ts"],"sourcesContent":["/**\n * The turn trace of a conversation as the conversation client port returns it: what the agent did in each turn, step by\n * step, for the step rows of the chat and of an analysis view. The shape follows the server's trace read\n * (`GET …/{id}/trace`): a field keeps the server's name where it is neutral, and a server name that carries its entity\n * vocabulary is renamed (`initiatorMessageId` → `turnMessageId`, `wasHeldForOwnerConsent` → `isHeldForConsent`,\n * `fileChangeId` → `id`). The server decides how much a read carries (`level`): the fields marked \"debug level\" are\n * null or absent in a read at the level of steps.\n */\n\n// ── Vocabulary ───────────────────────────────────────────────────────────────────────────────────────────────────\n\n/** How much a trace read carries: the steps as the owner may read them, or the debug facts beside them. */\nexport type ConversationTraceLevel = \"RESULT\" | \"STEPS\" | \"DEBUG\";\n\n/** The trace levels from the least to the most: RESULT (the answers only, no steps) < STEPS < DEBUG. */\nexport const CONVERSATION_TRACE_LEVELS: readonly ConversationTraceLevel[] = [\"RESULT\", \"STEPS\", \"DEBUG\"];\n\n/**\n * Which trace levels a reader may see in a conversation (the server's `AgentTraceViewPolicy`, decided by the app's\n * `AgentTraceViewPolicyService`): every level up to `maxDetailLevel`, starting at `defaultDetailLevel`. The server holds\n * the lock (a read above the maximum is lowered); a client only offers what is allowed. `isSwitchShown` is false when\n * a single level is allowed: no Short / Normal / Verbose switch then.\n */\nexport interface ConversationTraceViewPolicy {\n maxDetailLevel: ConversationTraceLevel;\n defaultDetailLevel: ConversationTraceLevel;\n isSwitchShown: boolean;\n}\n\nexport type ConversationTraceStepKind =\n | \"THINKING\"\n | \"MODEL_CALL\"\n | \"TOOL_CALL\"\n | \"SKILL_LOAD\"\n | \"SUB_AGENT\"\n | \"WIDGET\"\n | \"COMPACTION\"\n | \"SIGNAL\"\n | \"DECISION\"\n | \"TASK_PLAN\"\n | \"ERROR\";\n\n/** What a tool does to the data it works on, as the tool declared it. */\nexport type ConversationTraceToolEffect = \"READ\" | \"WORKSPACE\" | \"WRITE\" | \"DELETE\";\n\n/** The status of a step: the stored status of its call, or `ERROR` for an error row. */\nexport type ConversationTraceStepStatus =\n | \"PENDING\"\n | \"RUNNING\"\n | \"COMPLETED\"\n | \"FAILED\"\n | \"CANCEL_REQUESTED\"\n | \"CANCELLED\"\n | \"ERROR\"\n /** A control tool of the loop refused the call by design (`wait_for_sub_agents` on a turn that owes an answer): no failure. */\n | \"REFUSED\";\n\n/** Why a control call was refused (`step.refusalReason`); `other` for a refusal text the server does not know. */\nexport type ConversationTraceRefusalReason = \"turnAnswersOwner\" | \"ownerWroteDuringTurn\" | \"noSubAgentRunning\" | \"other\";\n\n/** What a sub-agent's task is (`subAgent.taskKind`): a task in words, a background job (one tool or operation, no model call), a run that exists already. */\nexport type ConversationTraceSubAgentTaskKind = \"agent\" | \"toolRun\" | \"awaitedRun\";\n\nexport type ConversationFileChangeType = \"ADDED\" | \"MODIFIED\" | \"DELETED\" | \"RENAMED\" | \"DIRECTORY_CREATED\";\n\n/**\n * What a file change carries as its diff: none (not a content change), the whole diff inline (`diffPreview`), a\n * preview with the whole diff stored (`getFileChangeDiff`), a binary file, a file over the size cap, or a diff that\n * could not be computed.\n */\nexport type ConversationFileChangeDiffState = \"NONE\" | \"INLINE\" | \"STORED\" | \"BINARY\" | \"TOO_LARGE\" | \"UNAVAILABLE\";\n\n// ── Parts of a step ──────────────────────────────────────────────────────────────────────────────────────────────\n\n/** A record a call's arguments name by id; the host maps the argument name to a label and a route. */\nexport interface ConversationTraceEntityReference {\n argumentName: string;\n id: number;\n}\n\n/** One field a call changed on one record: the stored column name and its value before and after the call, as text. */\nexport interface ConversationTraceFieldChange {\n fieldName: string;\n /** Null when the record did not exist yet or the field was empty. */\n before: string | null;\n /** Null when the record was deleted or the field was emptied. */\n after: string | null;\n /** A value was cut (a long text, a credential shortened to its first characters). */\n isCut: boolean;\n}\n\n/** What a call did to one record. */\nexport type ConversationTraceRecordChangeOperation = \"CREATED\" | \"CHANGED\" | \"DELETED\";\n\n/** One record a call created, changed or deleted, captured at the call's own write statements. */\nexport interface ConversationTraceRecordChange {\n operation: ConversationTraceRecordChangeOperation;\n /** The table of the record (`SupportDirectives`). */\n tableName: string;\n /** Null for a created record whose id the database assigned. */\n recordId: number | null;\n fieldChanges: ConversationTraceFieldChange[];\n /** Changed fields left out beyond the server's cap. */\n omittedFieldCount: number;\n}\n\n/** The facts of one model call (debug level). */\nexport interface ConversationTraceModelCall {\n modelName: string | null;\n effort: string | null;\n inputTokens: number | null;\n outputTokens: number | null;\n cachedInputTokens: number | null;\n /** The share of the input tokens read from the cache, 0–100. */\n cachePercent: number | null;\n costInUsd: number | null;\n reasoningTokens: number | null;\n /** Input tokens the call wrote to the cache. */\n cacheWriteTokens: number | null;\n /** The provider API the call went through, as the server names it. */\n wireApi: string | null;\n /** The tool the call was forced to choose, when one was forced. */\n forcedToolChoice: string | null;\n /** Milliseconds the provider took, and milliseconds the loop spent around the call. */\n providerCallMs: number | null;\n loopOverheadMs: number | null;\n /** The request of the call is stored (the sent payload can be read). */\n hasStoredPayload: boolean;\n /** The message whose context composition is the context of this call; null when the server names none. */\n contextMessageId: number | null;\n /** 1 for the first model call of the turn, 2 for the next. */\n callNumberInTurn: number | null;\n /** The tools the model called in this call, in order; empty when it answered with text. */\n toolNames: string[];\n /** How the call ended (`toolCalls`, `answer`, `empty`), as the server derives it. */\n stopReason: string | null;\n /** How tools were delivered on the call (`callTool`, `direct`), when stored. */\n toolDelivery: string | null;\n retryCount: number | null;\n}\n\n/** One probability a decision stored beside its answer. */\nexport interface ConversationTraceDecisionProbability {\n name: string;\n /** 0–1. */\n probability: number;\n}\n\n/** A decision the agent's loop took beside the model (a `DECISION` step; debug level). */\nexport interface ConversationTraceDecision {\n /** Which decision it is, as the server keys it (`replyLanguage`, `skillPreload`, `reasoningEffort`, …). */\n site: string | null;\n /** The decision's name in words, as the server words it (\"Reply language\"). */\n siteLabel: string | null;\n /** What keeps two decisions of one site apart (a pass, the tool of a consent, the evicted skill). */\n subject: string | null;\n /** Who decided (`decisionModel`, `rule`, `default`), and the same in words (\"Decision model\", \"Rule · platform\"). */\n engine: string | null;\n engineLabel: string | null;\n /** The site's mode when it decided (`on`, `shadow`). */\n mode: string | null;\n /**\n * Where the decision stands: `APPLIED` (the loop acted on it), `DECIDED` (answered, nothing to apply), `SHADOW`\n * (answered, recorded only), `FALLBACK` (no answer), `SKIPPED` (nobody was asked).\n */\n status: string | null;\n /** What came of it, in one line (\"effort medium → high\"). */\n resultSummary: string | null;\n modelName: string | null;\n modelVersion: string | null;\n /** The call's time; the decisions of one request share it. */\n durationMs: number | null;\n /**\n * How many decisions of the turn one request answered together (all with its duration): the step of the first of\n * them alone carries the duration on its row. Null or absent for a decision with a request of its own.\n */\n sharedRequestDecisionCount?: number | null;\n /** The leading probability of the answer, 0–1. */\n confidence: number | null;\n /** The probabilities the decision stored, highest first. */\n probabilities: ConversationTraceDecisionProbability[];\n /** Why the loop went on without the decision's answer (`FALLBACK`). */\n fallbackReason: string | null;\n /** Why the answer led to no action. */\n skipReason: string | null;\n /** The state the decision was sent, the questions it was asked, the model's raw answers and what the loop resolved from them, each as JSON text. */\n inputJson: string | null;\n isInputCut: boolean;\n questionsJson: string | null;\n isQuestionsCut: boolean;\n outputJson: string | null;\n isOutputCut: boolean;\n outcomeJson: string | null;\n isOutcomeCut: boolean;\n}\n\n/** One skill (or single tool) of a skill load. */\nexport interface ConversationTraceSkillLoadEntry {\n name: string;\n /** `SKILL` or `TOOL`. */\n type: string | null;\n /** `LOADED`, `ALREADY_LOADED`, `NOT_LOADED`. */\n outcome: string | null;\n /** `MODEL`, `DECISION_MODEL`, `PLAN_ITEM`, `STRUCTURAL`, `ALWAYS_LOADED`, `TOOL_CALL`. */\n cause: string | null;\n residentTokens: number | null;\n /** Tokens of the skill with the schemas of its tools. */\n residentTokensWithTools: number | null;\n tools: ConversationTraceLoadedSkillTool[];\n}\n\n/** What a step loaded: a `SKILL_LOAD` step, or a tool call that loaded skills (the entries at debug level only). */\nexport interface ConversationTraceSkillLoad {\n /** `MODEL` (the model asked for it), `PRELOAD` (loaded without a call of the model), `TOOL_CALL` (another tool's call loaded it). */\n cause: string | null;\n loadedCount: number | null;\n notLoadedCount: number | null;\n /** The names the model asked for. */\n requestedNames: string[];\n skills: ConversationTraceSkillLoadEntry[];\n /** What was not loaded and why, as the server stored it. */\n notLoadedText: string | null;\n}\n\n/** One item of a task plan. */\nexport interface ConversationTraceTaskPlanItem {\n key: string;\n /** The item's number in the plan (\"1\", \"1.2\"). */\n numberPath: string | null;\n depth: number;\n title: string;\n /** `open`, `done`, `blocked`, … as the server stores it. */\n status: string | null;\n /**\n * The state the plan shows (`open`, `done`, `blocked`, `not_applicable`): a container derives it from its subtasks, an\n * item below a blocked or not applicable container takes that state. Null from a server that does not send it.\n */\n shownStatus?: string | null;\n /** The one-line note of a terminal state: what was produced, why it is blocked, why it does not apply. */\n statusNote?: string | null;\n /** Only the owner can lift the block. */\n requiresUserAction?: boolean;\n /** The block is transient: the item may be tried again. */\n retryable?: boolean;\n /** The item came from the purpose's seeded plan (false: the agent added it). */\n isSeeded?: boolean;\n /** The seed found the item already satisfied and closed it at the start. */\n isPreResolvedAtSeed?: boolean;\n /** The platform closes the item from the record (a tool call, a widget, a delivered answer), never the agent's tick. */\n closesItself?: boolean;\n /** The platform wrote the item's current terminal state. */\n wasClosedByPlatform?: boolean;\n /** The machine done criterion of a seeded item. */\n doneCriterion?: string | null;\n /** The customer-facing progress step the item belongs to. */\n customerProgressStepKey?: string | null;\n /** Debug level: the agent's instruction, when the title is the customer-facing name. */\n instruction?: string | null;\n /** Debug level: the skills the item needs when it is the plan's next. */\n skillNames?: string[];\n /** Debug level: the seeded declarations that are set. */\n declarations?: ConversationTraceTaskPlanItemDeclaration[];\n /** Debug level: the message index of the evidence the item was closed on, and where the platform closed it. */\n evidenceMessageIndex?: number | null;\n platformResolvedAtMessageIndex?: number | null;\n}\n\n/** One seeded declaration of a task plan item (debug level). */\nexport interface ConversationTraceTaskPlanItemDeclaration {\n name: string;\n /** `text`, `nonEmptyArray`, `nameList`, `bool`, `connectedChannel`, `closedQuestionOptions`, `reasoningEffort`. */\n kind: string;\n value: string;\n}\n\n/** One line of the rejection block a refused plan call returned to the agent (debug level). */\nexport interface ConversationTraceTaskPlanRejection {\n line: string;\n /** The first item key the line names; null when it names none. */\n itemKey: string | null;\n}\n\n/** The compaction of a `COMPACTION` step (the summary text at debug level only). */\nexport interface ConversationTraceCompaction {\n /** The level of the summary (a summary of summaries has a higher one). */\n level: number | null;\n /** Messages the summary stands for, and the positions of the first and the last of them. */\n foldedMessageCount: number | null;\n foldedFromMessageIndex: number | null;\n foldedToMessageIndex: number | null;\n /** Tokens of those messages, and tokens of the summary in their place. */\n tokensBefore: number | null;\n tokensAfter: number | null;\n /** The share of the folded tokens the summary saved, 0–100. */\n compressionPercent: number | null;\n modelName: string | null;\n summaryText: string | null;\n isSummaryCut: boolean;\n /** The facts the compaction keeps beside its summary, as JSON text. */\n preservedFactsJson: string | null;\n}\n\n/** The signal of a `SIGNAL` step: a note the platform wrote into the conversation. */\nexport interface ConversationTraceSignal {\n source: string | null;\n /** The tag of a text that starts with `[SIGNAL:<kind>]` (`plan`, `ui`), else the source in words. */\n kind: string | null;\n /** The tag of a text that starts with `[SIGNAL:<tag>]`, as written; null when the text carries none (the source stays in `source`). */\n tag?: string | null;\n text: string | null;\n isTextCut: boolean;\n}\n\n/** The widget of a `WIDGET` step (the payload at debug level only). */\nexport interface ConversationTraceWidget {\n type: string | null;\n /** Who emitted it (`model`, a tool), as the server names it. */\n emittedBy: string | null;\n /** The payload passed the widget's validation. */\n isValid: boolean;\n /** The widget's own title and summary, where its payload names them. */\n title: string | null;\n summary: string | null;\n payloadJson: string | null;\n isPayloadCut: boolean;\n /** The message that holds the widget. */\n messageId?: number | null;\n /** The id of the `WIDGET` step of the widget (`m<messageId>.widget<ordinal>`). */\n stepId?: string | null;\n}\n\nexport interface ConversationTraceLoadedSkillTool {\n name: string;\n /** Tokens the tool's schema holds in the context. */\n residentTokens: number | null;\n /** Calls of the tool in the conversation so far. */\n usageCount: number | null;\n}\n\n/** A skill loaded at a model call, with its tools (debug level). */\nexport interface ConversationTraceLoadedSkill {\n name: string;\n residentTokens: number | null;\n /** Loaded since the model call before. */\n isNew: boolean;\n /** Loaded by the conversation itself, never by a `load` call. */\n isAlwaysLoaded: boolean;\n /** What loaded the skill (`MODEL`, `DECISION_MODEL`, `PLAN_ITEM`, `STRUCTURAL`, `ALWAYS_LOADED`, …), as the server names it. */\n cause: string | null;\n tools: ConversationTraceLoadedSkillTool[];\n}\n\n/** The shell command of a call (the output at debug level only). */\nexport interface ConversationTraceTerminal {\n command: string | null;\n cwd: string | null;\n exitCode: number | null;\n durationMs: number | null;\n output: string | null;\n errorOutput: string | null;\n /** The output was shortened by the runner. */\n isTruncated: boolean;\n isBackground: boolean;\n timedOut: boolean;\n}\n\n/** One file a call changed (the diff preview at debug level only). */\nexport interface ConversationFileChange {\n id: number | null;\n /** Where the change happened (`SANDBOX`, `CLOUDDRIVE`, `EXTERNAL_DRIVE`). */\n source: string | null;\n /** The kind of the mount (`OWN_DRIVE`, `SHARED_DRIVE`, `EXTERNAL_DRIVE`, `SCRATCH`); the host labels it. */\n mountKind: string | null;\n mountName: string | null;\n driveSpaceId: number | null;\n path: string;\n /** The path before a rename. */\n previousPath: string | null;\n changeType: ConversationFileChangeType | null;\n sizeBefore: number | null;\n sizeAfter: number | null;\n sha256Before: string | null;\n sha256After: string | null;\n contentType: string | null;\n isBinary: boolean;\n linesAdded: number | null;\n linesRemoved: number | null;\n diffState: ConversationFileChangeDiffState | null;\n /** The diff as unified diff text: all of it (`INLINE`) or its start (`STORED`). */\n diffPreview: string | null;\n driveNodeId: number | null;\n driveFileVersionId: number | null;\n externalRevisionId: string | null;\n}\n\nexport interface ConversationTraceSubAgentRun {\n runNumber: number | null;\n /** `QUEUED`, `RUNNING`, `COMPLETED`, `FAILED`, `CANCELLED`, … as the server stores it. */\n status: string | null;\n startedAt: string | null;\n finishedAt: string | null;\n /** What the sub-agent answered its parent. */\n verdict: string | null;\n failureReason: string | null;\n costInUsd: number | null;\n inputTokens: number | null;\n outputTokens: number | null;\n /** What the run reported, readable: the text of a tool response, never its JSON (both levels). */\n resultText?: string | null;\n isResultTextCut?: boolean;\n /** The run stored the serialized response of a tool; `verdict` (the raw JSON) is then debug level only. */\n isToolResponse?: boolean;\n /** A tool response only: it reported an error; null otherwise. */\n isError?: boolean | null;\n}\n\n/** The sub-agent of a `SUB_AGENT` step. */\nexport interface ConversationTraceSubAgent {\n /** The number of the sub-agent in its parent conversation. */\n number: number | null;\n label: string;\n taskText: string | null;\n skillNames: string[];\n childConversationId: number | null;\n /** The status of the newest run. */\n status: string | null;\n runs: ConversationTraceSubAgentRun[];\n /** The model the sub-agent's conversation ran on (debug level). */\n modelName: string | null;\n /** That model as the model catalog names it (\"GPT-6 Luna\"); null when the server names none (debug level). */\n modelLabel?: string | null;\n /** The totals of the sub-agent's conversation over all its runs (debug level). */\n costInUsd: number | null;\n inputTokens: number | null;\n outputTokens: number | null;\n cachedInputTokens: number | null;\n messageCount: number | null;\n /** What the task is; null when the server names none. */\n taskKind?: ConversationTraceSubAgentTaskKind | null;\n /** A `toolRun` task: the tool it runs; null for an operation the application names. */\n toolName?: string | null;\n /** A `toolRun` task: the operation (`executeTool` for a tool, else the application's operation name). */\n operationName?: string | null;\n /** A `toolRun` task: the stable id of the background job, `<operation>:<tool name>` (`executeTool:countRows`) or the operation. */\n backgroundJobKey?: string | null;\n /** The readable verdict of the current run (the text of a tool response for a background job). */\n verdictText?: string | null;\n /** What the current run reported, readable (both levels). */\n resultText?: string | null;\n isResultTextCut?: boolean;\n}\n\n// ── Steps and turns ──────────────────────────────────────────────────────────────────────────────────────────────\n\n/**\n * A message of a turn as the trace carries it: the message that started the turn, or a text the assistant wrote in\n * it. The text is the stored one (widget blocks and line breaks kept) with credentials shortened; a long text is cut\n * (`isTextCut`) and its whole text is read by the per-message read of the audience.\n */\nexport interface ConversationTraceMessage {\n messageId: number | null;\n /** The position of the message in the conversation (`indexInConversation`). */\n messageIndex: number | null;\n /** Who wrote it: `OWNER`, `SIGNAL`, `ORCHESTRATOR` or `PLATFORM` for the message that started a turn, `ASSISTANT` for a text of the assistant. */\n authorKind: string | null;\n text: string;\n /** Characters of the whole text. */\n textChars: number;\n isTextCut: boolean;\n createdAt: string | null;\n /** The source of a signal that started the turn, or the marker of a text the platform wrote in the agent's name; null for a plain message. */\n signalSource: string | null;\n /** A text of the assistant: the model call that wrote it also called tools (a text between two steps, not the turn's answer). */\n isInterim: boolean;\n /** A text of the assistant: the model that wrote it, as the model catalog names it (\"GPT-6 Luna\"), else in words. */\n modelLabel: string | null;\n /** Debug level: the name of that model as the server stores it. */\n modelName: string | null;\n /** The types of the widget blocks the text holds, in order. */\n widgetTypes: string[];\n /** An answer: the widgets it shows, in order (type, title, message; the payload at debug level only). */\n widgets?: ConversationTraceWidget[];\n /** An owner message that arrived while a turn ran, so it started no turn of its own at that moment. */\n isQueuedDuringRun?: boolean;\n /** Such a message: the number of the turn that was running when it arrived. */\n arrivedDuringTurnNumber?: number | null;\n /** Such a message: the number of the turn that took it up (the same turn or the next one); null while none has. */\n handledInTurnNumber?: number | null;\n /** Such a message: the platform note that handed it to the model. */\n foldSignalMessageId?: number | null;\n}\n\n/** One step of a turn. */\nexport interface ConversationTraceStep {\n /** A key that is stable within the turn: the server's step id, else the row's message id, its kind and its position. */\n key: string;\n /** The id the server gives the step, unique within the conversation (never parsed, only compared); null when it sends none. */\n stepId: string | null;\n /** The number of the turn the step belongs to; null when the server names none. */\n turnNumber: number | null;\n kind: ConversationTraceStepKind;\n /** The stored message the step comes from; null for a step from an event. */\n messageId: number | null;\n /** The tool that was called: the real tool, also when the model called it through `call_tool`. */\n toolName: string | null;\n deliveredThroughCallTool: boolean;\n effect: ConversationTraceToolEffect | null;\n status: ConversationTraceStepStatus | null;\n /** The stored status of the call when `status` tells something else (`FAILED` behind `REFUSED`). */\n storedStatus?: string | null;\n /** A `REFUSED` step: why the call was refused. */\n refusalReason?: ConversationTraceRefusalReason | null;\n /** The step of a background job in the trace of its own conversation: the operation it ran (`executeTool` or the application's). */\n backgroundOperationName?: string | null;\n /** That step: the stable id of the job, `<operation>:<tool name>` or the operation. */\n backgroundJobKey?: string | null;\n startedAt: string | null;\n durationMs: number | null;\n /** The narrated activity line, as the owner read it; null when none was narrated. */\n line: string | null;\n /** The tool name in words (`searchServiceAreas` reads \"search service areas\"). */\n toolNameInWords: string | null;\n /** The loaded skills that brought the tool at the time of the call; empty when unknown. */\n toolSkillNames: string[];\n /** The model of a `MODEL_CALL` or `THINKING` step in words (\"GPT6 LUNA\"). */\n modelLabel: string | null;\n /** What the model wrote about its thinking at a `THINKING` or `MODEL_CALL` step, where the provider returned it readable. */\n thinkingSummary?: string | null;\n entityReferences: ConversationTraceEntityReference[];\n /** The records a writing call created, changed or deleted, each field before and after; empty for a read. */\n recordChanges?: ConversationTraceRecordChange[];\n /** Changed records left out beyond the server's cap. */\n omittedRecordChangeCount?: number;\n /** The owner-consent check held a write of the call back. */\n isHeldForConsent: boolean;\n /** A gate refused the call before it ran, or it was dropped as a repeat. */\n isRefused: boolean;\n /** The start of the text of an `ERROR` step. */\n errorText: string | null;\n /** The code of an `ERROR` step, as the server names it, and whether the turn went on with another model call after it. */\n errorCode: string | null;\n wasRetried: boolean;\n /** The widget type of a `WIDGET` step. */\n widgetType: string | null;\n /** The widget of a `WIDGET` step. */\n widget: ConversationTraceWidget | null;\n /** The decision of a `DECISION` step. */\n decision: ConversationTraceDecision | null;\n /** The compaction of a `COMPACTION` step. */\n compaction: ConversationTraceCompaction | null;\n /** The signal of a `SIGNAL` step. */\n signal: ConversationTraceSignal | null;\n /** What the step loaded: a `SKILL_LOAD` step, or a tool call that loaded skills. */\n skillLoad: ConversationTraceSkillLoad | null;\n /** The items of the task plan after a `TASK_PLAN` step; empty when the server sends none. */\n taskPlanItems: ConversationTraceTaskPlanItem[];\n /** Debug level: the rejection lines of a refused plan call. Absent from a server that does not send them. */\n taskPlanRejections?: ConversationTraceTaskPlanRejection[];\n /** The task plan after a `TASK_PLAN` step. */\n taskPlanTitle: string | null;\n /** Top-level items of the plan, and how many of them are open (neither done nor blocked). */\n taskPlanItemCount: number | null;\n taskPlanOpenItemCount: number | null;\n /** Top-level items that are done (or do not apply) and that are blocked; absent from a server that does not send them. */\n taskPlanDoneItemCount?: number | null;\n taskPlanBlockedItemCount?: number | null;\n terminal: ConversationTraceTerminal | null;\n fileChanges: ConversationFileChange[];\n subAgent: ConversationTraceSubAgent | null;\n /** Debug level: the arguments of the call as JSON. */\n argumentsJson: string | null;\n isArgumentsCut: boolean;\n /** Debug level: the stored result of the call (its start when `isResultCut`). */\n result: string | null;\n /** Debug level: characters of the whole stored result. */\n resultChars: number | null;\n isResultCut: boolean;\n /** Debug level: the facts of a `MODEL_CALL` or `THINKING` step. */\n modelCall: ConversationTraceModelCall | null;\n /** Debug level: the skills loaded at a model call; null when they are those of the model call before. */\n loadedSkills: ConversationTraceLoadedSkill[] | null;\n /** Debug level: the skills the call loaded. */\n loadedSkillNames: string[];\n /** The text the assistant wrote in the model call of this step, before the call's tools ran; null without one. */\n assistantText: string | null;\n /** Characters of that whole text. */\n assistantTextChars: number | null;\n isAssistantTextCut: boolean;\n}\n\n/** The figures of one turn (tokens, cost, model and effort at debug level only). */\nexport interface ConversationTurnTraceTotals {\n durationMs: number | null;\n inputTokens: number | null;\n outputTokens: number | null;\n cachedInputTokens: number | null;\n /** The share of the input tokens read from the cache, 0–100. */\n cachePercent: number | null;\n costInUsd: number | null;\n stepCount: number;\n commandCount: number;\n fileCount: number;\n linesAdded: number;\n linesRemoved: number;\n modelName: string | null;\n effort: string | null;\n /** How the turn ended (`answered`, `gaveUp`, `failed`, `cancelled`, `expired`, `waitingForSubAgents`); null while it runs. */\n outcome: string | null;\n}\n\n/** The trace of one turn: the message that started it and what the agent did until its answer. */\nexport interface ConversationTurnTrace {\n /** The number of the turn in its conversation, from 1, oldest first. */\n turnNumber: number;\n /** The message that started the turn (the owner's message, a signal); null for rows before the first one. */\n turnMessageId: number | null;\n /** The position of that message in the conversation (`indexInConversation`); null when the server names none. */\n turnMessageIndex: number | null;\n startedAt: string | null;\n isRunning: boolean;\n /** The owner stopped the turn. */\n isStoppedByOwner: boolean;\n /** The message that started the turn, with its text; null when the server sends none. */\n initiatorMessage: ConversationTraceMessage | null;\n /** The texts the assistant wrote in the turn, in order: interim texts (`isInterim`) and the answer. */\n answerMessages: ConversationTraceMessage[];\n /** Owner messages that arrived while this turn ran (`isQueuedDuringRun`), in order; place them by `messageIndex`. */\n queuedMessages?: ConversationTraceMessage[];\n /** The loop started this turn for a queued owner message after the turn before had ended. */\n isStartedForQueuedOwnerMessage?: boolean;\n /** Such a turn: the platform note that is its first row. */\n startedBySignalMessageId?: number | null;\n steps: ConversationTraceStep[];\n totals: ConversationTurnTraceTotals;\n}\n\n/**\n * How a trace read was asked for: the page of the newest turns, a page from a turn number, or the follow-up read of a\n * running conversation (\"the turns that hold a row after this position\"), which is no page.\n */\nexport type ConversationTraceWindowMode = \"NEWEST\" | \"FROM_TURN\" | \"FOLLOW_UP\";\n\n/** The answer of a trace read. */\nexport interface ConversationTurnTraces {\n conversationId: number | null;\n level: ConversationTraceLevel;\n /** Oldest first. */\n turns: ConversationTurnTrace[];\n /** How the window was asked for; null when the server does not say. */\n windowMode: ConversationTraceWindowMode | null;\n /** Turns of the whole conversation; null when the server names no count. */\n totalTurnCount: number | null;\n /** The numbers of the first and the last turn of `turns`; null for an answer without turns. */\n firstTurnNumber: number | null;\n lastTurnNumber: number | null;\n /**\n * A page read (`NEWEST`, `FROM_TURN`): turns exist before the first, and after the last, turn of the page. Both are\n * false on a follow-up read, which is no page: a reader keeps the paging facts of its page reads.\n */\n hasOlderTurns: boolean;\n hasNewerTurns: boolean;\n /** The position (`indexInConversation`) of the newest row the read saw: the `afterMessageIndex` of the next read. */\n newestMessageIndex: number | null;\n /** A turn runs right now. */\n isRunLive: boolean;\n /** Who may see which level in this conversation; null when the server sends none (an older server). */\n traceViewPolicy: ConversationTraceViewPolicy | null;\n}\n\n/** Which turns a trace read returns. Without options: the newest turns, as many as the server's default window holds. */\nexport interface ConversationTurnTracesOptions {\n /** The level asked for; the server answers at most the level the reader is allowed. */\n level?: ConversationTraceLevel;\n /** The first turn of the window (turns are numbered from 1, oldest first). */\n fromTurnNumber?: number;\n /** Turns of the window. */\n limit?: number;\n /** Only the turns that hold a row after this position, each of them whole: the read that follows a running turn. */\n afterMessageIndex?: number;\n}\n\n/** The answer of a stop of the running turn. */\nexport interface ConversationTurnStop {\n /** A running turn was stopped; false when none ran. */\n isStopped: boolean;\n /** The run state of the conversation after the stop, as the server stores it; null when it names none. */\n runState: string | null;\n}\n\n// ── Context composition and stored diffs ─────────────────────────────────────────────────────────────────────────\n\n/** One part of what a model call was sent (the system prompt, a skill, the tool schemas, the history, …). */\nexport interface ConversationContextSegment {\n key: string;\n /** The segment's name as the server words it. */\n label: string;\n tokens: number;\n /** The share of the context, 0–100. */\n percent: number | null;\n}\n\n/** What one model call was sent, by segment (debug level; the context ring's and the composition bar's data). */\nexport interface ConversationContextComposition {\n messageId: number | null;\n /** Tokens in the context at this call: the provider's count of the newest call when the server names it, else the segments' sum. */\n totalTokens: number | null;\n /**\n * The size the context may reach before the conversation is compacted (the compaction threshold in effect, at most\n * the model's context window); null when the server names none.\n */\n contextWindowTokens: number | null;\n /** The share of that size in use, 0–100 (above 100 while a compaction is due). */\n fillPercent: number | null;\n segments: ConversationContextSegment[];\n}\n\n/** The whole diff of one file change (`diffState` `STORED`). */\nexport interface ConversationFileChangeDiff {\n fileChangeId: number;\n /** Unified diff text. */\n diff: string;\n /** The stored diff itself was cut at the server's cap. */\n isCut: boolean;\n}\n"],"names":[],"mappings":";AAeO,MAAM,4BAA+D,CAAC,UAAU,SAAS,OAAO;"}