@mgamadeus/ddd-agents 0.1.1 → 0.1.3

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 (95) hide show
  1. package/README.md +129 -0
  2. package/dist/chat.js +407 -265
  3. package/dist/chat.js.map +1 -1
  4. package/dist/chunks/{ConversationMessageInputComposerWidgets-BO3jS0eZ.js → ConversationMessageInputComposerWidgets-r_RwCqr7.js} +11 -8
  5. package/dist/chunks/ConversationMessageInputComposerWidgets-r_RwCqr7.js.map +1 -0
  6. package/dist/chunks/{WebSearchResultsConversationWidget-H6cbTapV.js → WebSearchResultsConversationWidget-BXt98hGu.js} +161 -102
  7. package/dist/chunks/WebSearchResultsConversationWidget-BXt98hGu.js.map +1 -0
  8. package/dist/chunks/{canvas-behaviours-AvzKSYyv.js → canvas-behaviours-BpN_1xdZ.js} +2 -2
  9. package/dist/chunks/{canvas-behaviours-AvzKSYyv.js.map → canvas-behaviours-BpN_1xdZ.js.map} +1 -1
  10. package/dist/chunks/{canvas-reducers-Cdxt8yDF.js → canvas-reducers-CuX6L1zg.js} +3 -3
  11. package/dist/chunks/{canvas-reducers-Cdxt8yDF.js.map → canvas-reducers-CuX6L1zg.js.map} +1 -1
  12. package/dist/chunks/{canvasBodies-CsLrZ-M-.js → canvasBodies-Ds-cTn47.js} +9 -6
  13. package/dist/chunks/{canvasBodies-CsLrZ-M-.js.map → canvasBodies-Ds-cTn47.js.map} +1 -1
  14. package/dist/chunks/{canvasStorage-EvQsGdto.js → canvasStorage-DHNluopA.js} +2 -2
  15. package/dist/chunks/{canvasStorage-EvQsGdto.js.map → canvasStorage-DHNluopA.js.map} +1 -1
  16. package/dist/chunks/compose-attachment-message-text-FvVJbrge.js +8 -0
  17. package/dist/chunks/compose-attachment-message-text-FvVJbrge.js.map +1 -0
  18. package/dist/chunks/{contract-BxmMxYPF.js → contract-kmmw_19Y.js} +5 -4
  19. package/dist/chunks/contract-kmmw_19Y.js.map +1 -0
  20. package/dist/chunks/{conversation-BEF0aesf.js → conversation-CbWEHPbL.js} +12 -3
  21. package/dist/chunks/conversation-CbWEHPbL.js.map +1 -0
  22. package/dist/chunks/host-color-scheme-Jhb7JZR7.js +30 -0
  23. package/dist/chunks/host-color-scheme-Jhb7JZR7.js.map +1 -0
  24. package/dist/chunks/{index-7Qc_3GbG.js → link-navigation-DyTApNeA.js} +156 -73
  25. package/dist/chunks/link-navigation-DyTApNeA.js.map +1 -0
  26. package/dist/chunks/text-key-DnoZ4lAk.js +6 -0
  27. package/dist/chunks/text-key-DnoZ4lAk.js.map +1 -0
  28. package/dist/chunks/{widget-click-signal-sources-1gIs1yiN.js → widget-click-signal-sources-Ch-y8gxw.js} +9 -5
  29. package/dist/chunks/{widget-click-signal-sources-1gIs1yiN.js.map → widget-click-signal-sources-Ch-y8gxw.js.map} +1 -1
  30. package/dist/chunks/{widget-image-readiness-signal-D3ci53xr.js → widget-image-readiness-signal-C5yaKpJJ.js} +2 -2
  31. package/dist/chunks/{widget-image-readiness-signal-D3ci53xr.js.map → widget-image-readiness-signal-C5yaKpJJ.js.map} +1 -1
  32. package/dist/chunks/{widget-name-resolver-D_ZzXy-Q.js → widget-name-resolver-DboFMAq2.js} +25 -25
  33. package/dist/chunks/widget-name-resolver-DboFMAq2.js.map +1 -0
  34. package/dist/chunks/{withPollingChangeSubscription-B16htQGd.js → withPollingChangeSubscription-CWavoKjJ.js} +7 -3
  35. package/dist/chunks/withPollingChangeSubscription-CWavoKjJ.js.map +1 -0
  36. package/dist/client-testing.js +7 -8
  37. package/dist/client-testing.js.map +1 -1
  38. package/dist/client.js +470 -2
  39. package/dist/client.js.map +1 -1
  40. package/dist/contract.js +6 -5
  41. package/dist/files/chat/Conversation.module.scss +1 -1
  42. package/dist/files/chat/ConversationViewBody/ConversationViewBody.module.scss +1 -1
  43. package/dist/files/i18n-keys.json +1636 -0
  44. package/dist/files/image-render/WidgetImageRender.module.scss +9 -3
  45. package/dist/files/styles/_surfaces.scss +6 -6
  46. package/dist/image-render.js +7 -7
  47. package/dist/index.js +64 -55
  48. package/dist/index.js.map +1 -1
  49. package/dist/kit.js +2 -2
  50. package/dist/preview.js +8 -8
  51. package/dist/provider.js +61 -52
  52. package/dist/provider.js.map +1 -1
  53. package/dist/renderer.js +16 -15
  54. package/dist/styles.css +318 -122
  55. package/dist/types/chat/AgentChat/AgentChat.d.ts +6 -0
  56. package/dist/types/chat/AgentChatActivityDots/AgentChatActivityDots.d.ts +11 -0
  57. package/dist/types/chat/AgentChatActivityIndicator/AgentChatActivityIndicator.d.ts +7 -2
  58. package/dist/types/chat/AgentChatActivityStack/AgentChatActivityStack.d.ts +15 -0
  59. package/dist/types/chat/controller/AgentChatController.d.ts +38 -1
  60. package/dist/types/chat/controller/activity-ticker.d.ts +5 -2
  61. package/dist/types/chat/controller/chat-activity-timing.d.ts +30 -0
  62. package/dist/types/chat/controller/use-activity-ticker.d.ts +6 -0
  63. package/dist/types/chat/controller/use-conversation-activity.d.ts +6 -2
  64. package/dist/types/client/AgentsConversationClient.d.ts +7 -1
  65. package/dist/types/client/compose-attachment-message-text.d.ts +7 -0
  66. package/dist/types/client/http/agents-http-mappers.d.ts +30 -0
  67. package/dist/types/client/http/agents-http-wire.d.ts +201 -0
  68. package/dist/types/client/http/createAgentsHttpConversationClient.d.ts +64 -0
  69. package/dist/types/client/polling/createPollingConversationChangeSubscription.d.ts +7 -4
  70. package/dist/types/client/polling/withPollingChangeSubscription.d.ts +3 -2
  71. package/dist/types/contract/conversation.d.ts +35 -0
  72. package/dist/types/entries/chat.d.ts +6 -2
  73. package/dist/types/entries/client.d.ts +4 -0
  74. package/dist/types/entries/renderer.d.ts +1 -0
  75. package/dist/types/entries/widgets.d.ts +1 -1
  76. package/dist/types/provider/components/types.d.ts +5 -2
  77. package/dist/types/provider/environment.d.ts +20 -0
  78. package/dist/types/provider/host-color-scheme.d.ts +24 -0
  79. package/dist/types/provider/index.d.ts +4 -0
  80. package/dist/types/provider/link-navigation.d.ts +28 -0
  81. package/dist/types/provider/text-key.d.ts +6 -0
  82. package/dist/types/renderer/MarkdownLink.d.ts +8 -6
  83. package/dist/types/widgets/CanvasLauncherWidget/use-canvas-viable.d.ts +43 -9
  84. package/dist/types/widgets/EntityMentionConversationWidget/shared/entity-mention-presentation.d.ts +1 -1
  85. package/dist/types/widgets/_shared/modern/WidgetKpiValue.d.ts +2 -1
  86. package/dist/widgets.js +43 -40
  87. package/package.json +4 -2
  88. package/public-api.json +101 -18
  89. package/dist/chunks/ConversationMessageInputComposerWidgets-BO3jS0eZ.js.map +0 -1
  90. package/dist/chunks/WebSearchResultsConversationWidget-H6cbTapV.js.map +0 -1
  91. package/dist/chunks/contract-BxmMxYPF.js.map +0 -1
  92. package/dist/chunks/conversation-BEF0aesf.js.map +0 -1
  93. package/dist/chunks/index-7Qc_3GbG.js.map +0 -1
  94. package/dist/chunks/widget-name-resolver-D_ZzXy-Q.js.map +0 -1
  95. package/dist/chunks/withPollingChangeSubscription-B16htQGd.js.map +0 -1
@@ -24,6 +24,12 @@ export interface AgentChatProps extends Omit<AgentChatControllerProps, Defaulted
24
24
  chatScrollRef?: RefObject<HTMLDivElement | null>;
25
25
  /** The agent's activity at the tail of the thread. Default: `AgentChatActivityIndicator` (dots and the ticker line). */
26
26
  ThinkingIndicator?: ComponentType<AgentChatActivityProps>;
27
+ /**
28
+ * The frosted band at the top of the message column that blurs what scrolls under a top bar floating over the chat.
29
+ * Shown, it follows the chat pane (`confineTopBlurBandToChatPane` defaults to true then). Default false: the default
30
+ * chat has no floating top bar.
31
+ */
32
+ showsTopBlurBand?: boolean;
27
33
  }
28
34
  /**
29
35
  * The agent chat with the package defaults (`./chat`): `<AgentsProvider client={client}><AgentChat
@@ -0,0 +1,11 @@
1
+ /** How the three dots move: `bounce` hops them in turn (the indicator's default); `pulse` only fades and grows them, calmly. */
2
+ export type AgentChatActivityDotsVariant = "bounce" | "pulse";
3
+ export interface AgentChatActivityDotsProps {
4
+ /** Default `bounce`. */
5
+ variant?: AgentChatActivityDotsVariant;
6
+ }
7
+ /**
8
+ * The three working dots of the activity components, decorative (`aria-hidden`). Coloured by `--agents-fg-light`;
9
+ * still under `prefers-reduced-motion`.
10
+ */
11
+ export declare const AgentChatActivityDots: ({ variant }: AgentChatActivityDotsProps) => import("react/jsx-runtime").JSX.Element;
@@ -1,8 +1,13 @@
1
+ import { type AgentChatActivityDotsVariant } from "../AgentChatActivityDots/AgentChatActivityDots";
1
2
  import type { AgentChatActivityProps } from "../controller/AgentChatController";
3
+ export interface AgentChatActivityIndicatorProps extends AgentChatActivityProps {
4
+ /** How the dots move: `bounce` (the default) or the calm `pulse`. */
5
+ dotsVariant?: AgentChatActivityDotsVariant;
6
+ }
2
7
  /**
3
8
  * The package default of the agent's activity at the tail of the thread (`AgentChat`'s `ThinkingIndicator`): three
4
9
  * dots and the line the activity ticker shows right now — the step the agent works on — while a turn runs; nothing
5
10
  * between turns or after a failed one (the error card speaks then). An app with an agent avatar replaces it
6
- * (host application: the agent's face beside the same ticker lines).
11
+ * (host application: the agent's face beside the same ticker lines). `AgentChatActivityStack` is the stacked feed.
7
12
  */
8
- export declare const AgentChatActivityIndicator: (props: AgentChatActivityProps) => import("react/jsx-runtime").JSX.Element | null;
13
+ export declare const AgentChatActivityIndicator: (props: AgentChatActivityIndicatorProps) => import("react/jsx-runtime").JSX.Element | null;
@@ -0,0 +1,15 @@
1
+ import type { AgentChatActivityProps } from "../controller/AgentChatController";
2
+ /** The lines the stack keeps on screen: the newest one and about three readable ranks above it, the oldest under the mask. */
3
+ export declare const ACTIVITY_STACK_VISIBLE_LINES = 4;
4
+ /**
5
+ * The stacked activity feed at the tail of the thread, a drop-in `ThinkingIndicator` of `AgentChat`
6
+ * (`<AgentChat ThinkingIndicator={AgentChatActivityStack} />`): one generated sentence per tool call of the running
7
+ * turn, the newest at the bottom at full size, the older ones drifting up, smaller and fainter under a top mask.
8
+ * Before the first sentence it shows the calm dots and "Working on it…"; once a sentence is told, only sentences. It
9
+ * fades out over the success beat when the turn ends, and shows nothing between turns or after a failed turn.
10
+ *
11
+ * The moving layer is decorative (`aria-hidden`); a polite status region carries the newest sentence. The motion
12
+ * follows the chat's timing (`activityTiming`: the line pace and the success beat), stays still under
13
+ * `prefers-reduced-motion`, and every colour comes from the `--agents-*` variables.
14
+ */
15
+ export declare const AgentChatActivityStack: (props: AgentChatActivityProps) => import("react/jsx-runtime").JSX.Element | null;
@@ -1,7 +1,8 @@
1
- import { type ComponentType, type ReactNode, type RefObject } from "react";
1
+ import { type ComponentType, type ReactNode, type Ref, type RefObject } from "react";
2
2
  import type { AgentsConversationClient } from "../../client/AgentsConversationClient";
3
3
  import { type ConversationAttachmentReference } from "../../contract/conversation";
4
4
  import type { AgentsChatStore } from "../store/create-agents-chat-store";
5
+ import { type AgentChatActivityTiming, type ResolvedAgentChatActivityTiming } from "./chat-activity-timing";
5
6
  import type { ChatScrollTarget } from "./chat-scroll-target";
6
7
  import { type ActivityTicker, type ActivityTickerTurn } from "./use-activity-ticker";
7
8
  /** What the host's activity components get: the turn's state and the paced lines of the activity ticker. */
@@ -15,11 +16,21 @@ export interface AgentChatActivityProps {
15
16
  isAgentWorkingOnTask: boolean;
16
17
  /** The key of the agent space the chat is open on. */
17
18
  agentSpaceKey: number;
19
+ /** The chat's resolved activity timing (`activityTiming`, the environment's, the package's), for the component's motion. */
20
+ activityTiming?: ResolvedAgentChatActivityTiming;
18
21
  }
19
22
  /** What the host's activity history under a message gets: the finished turn that message started, if any. */
20
23
  export interface AgentChatActivityHistoryProps {
21
24
  turn: ActivityTickerTurn | null;
22
25
  }
26
+ /** What a host does with the composer of a mounted chat (`AgentChat`'s `composerRef`). */
27
+ export interface AgentChatComposerHandle {
28
+ /**
29
+ * Replaces the composer's draft with `text` (empty clears it) and puts the caret at its end — never sends. Does
30
+ * nothing while the composer is not shown (a closed conversation).
31
+ */
32
+ setComposerDraft: (text: string) => void;
33
+ }
23
34
  /** Where the model of the next send comes from — read at send time (an admin's pick can change between renders). */
24
35
  export interface AgentChatSendModelSource {
25
36
  readModelForNextSend: () => string | undefined;
@@ -46,6 +57,13 @@ export interface AgentChatControllerProps {
46
57
  scrollTarget?: ChatScrollTarget;
47
58
  /** Each finished turn's activity lines stay in the thread above its answer (rendered by `ActivityHistory`). */
48
59
  keepActivityHistoryAfterAnswer?: boolean;
60
+ /**
61
+ * The timing of the activity reads and of the working indicator's lines (the 3 s read window, the line paces, the
62
+ * success beat). Each field the chat leaves out comes from `AgentsEnvironment.chatActivityTiming`, else the package's
63
+ * value. A host whose realtime push writes `activityUpdatedAt` when the narrator finishes lowers the read window, so a
64
+ * narrated line shows at once.
65
+ */
66
+ activityTiming?: AgentChatActivityTiming;
49
67
  /** The host shows one conversation the owner may not leave: no starting ideas (the agent speaks first). */
50
68
  isPinnedToSingleConversation?: boolean;
51
69
  /** App extension of the widget context: the chat is the app's guided first-run setup. */
@@ -87,6 +105,25 @@ export interface AgentChatControllerProps {
87
105
  ActivityHistory?: ComponentType<AgentChatActivityHistoryProps>;
88
106
  /** Rendered inside the chat's widget provider (the host's canvas syncs). */
89
107
  children?: ReactNode;
108
+ /**
109
+ * The chat renders without the canvas split: no side pane, the message column alone. Default false. Without a canvas
110
+ * surface of the host's own (`hostHasCanvasSurface`), every canvas open is then ignored.
111
+ */
112
+ disableSplitView?: boolean;
113
+ /**
114
+ * Whether a canvas may open in this chat: false ignores every open request (reason `noSurface`), true lets the canvas
115
+ * state open while the host draws it (with `disableSplitView`: in a surface of its own, e.g. `CanvasPane`). Default:
116
+ * true with the split view, false without it.
117
+ */
118
+ hostHasCanvasSurface?: boolean;
119
+ /**
120
+ * The host paints the chat's background behind it (the pane stays transparent, the frosted top band of a floating
121
+ * top bar keeps its look). Default true; false gives the chat the package's own background
122
+ * (`--agents-chat-background`).
123
+ */
124
+ backgroundPaintedByHost?: boolean;
125
+ /** The handle of the composer: put a draft into the mounted chat without a remount (`setComposerDraft`). */
126
+ composerRef?: Ref<AgentChatComposerHandle>;
90
127
  }
91
128
  /**
92
129
  * The agent chat: the controller over the conversation client port and the chat store — open, pages,
@@ -56,8 +56,11 @@ export declare const showActivityLine: (queue: ActivityTickerQueue, line: Activi
56
56
  * a sentence never show (only generated sentences appear).
57
57
  */
58
58
  export declare const receiveActivityElements: (queue: ActivityTickerQueue, elements: ActivityElement[], now: number) => ActivityTickerQueue;
59
- /** Milliseconds until the next waiting line may be shown; null when nothing waits. */
60
- export declare const msUntilNextActivityLine: (queue: ActivityTickerQueue, now: number) => number | null;
59
+ /**
60
+ * Milliseconds until the next waiting line may be shown; null when nothing waits. The paces default to
61
+ * {@link LINE_PACE_MS} and {@link BACKLOG_LINE_PACE_MS} (a host sets its own through the chat's `activityTiming`).
62
+ */
63
+ export declare const msUntilNextActivityLine: (queue: ActivityTickerQueue, now: number, linePaceMs?: number, backlogLinePaceMs?: number) => number | null;
61
64
  /** Show the oldest waiting line. The caller's timer decides when (see {@link msUntilNextActivityLine}). */
62
65
  export declare const releaseNextActivityLine: (queue: ActivityTickerQueue, now: number) => ActivityTickerQueue;
63
66
  /** Show every waiting line at once, oldest first — the turn has ended and the answer is on screen. */
@@ -0,0 +1,30 @@
1
+ /**
2
+ * The timing of the chat's activity lines and of its working indicator, for a host whose delivery differs from the
3
+ * package's polling default. Every field is optional and defaults to the package's value; a value that is no finite
4
+ * number at or above 0 counts as unset.
5
+ *
6
+ * A host with a realtime push that writes `activityUpdatedAt` when the narrator finishes lowers
7
+ * `activityRequestWindowMs` (and the paces), so a narrated line shows as soon as the push arrives instead of after the
8
+ * next 3 s window.
9
+ */
10
+ export interface AgentChatActivityTiming {
11
+ /** At most one activity read per this many milliseconds per conversation. Default 3000 (`ACTIVITY_REQUEST_WINDOW_MS`). */
12
+ activityRequestWindowMs?: number;
13
+ /** While a turn runs, an activity read also fires on this cadence (the floor for a dead signal). Default 4000 (`RUNNING_FLOOR_MS`). */
14
+ runningFloorMs?: number;
15
+ /** The least time a line stands beside the working face before the next one replaces it. Default 2200 (`LINE_PACE_MS`). */
16
+ linePaceMs?: number;
17
+ /** The shorter wait while more than two lines are queued. Default 1400 (`BACKLOG_LINE_PACE_MS`). */
18
+ backlogLinePaceMs?: number;
19
+ /** How long the face's success beat rests after the turn before it turns idle. Default 1400 (`SUCCESS_BEAT_MS`). */
20
+ successBeatMs?: number;
21
+ }
22
+ /** Every timing value set: the resolved form the chat's hooks read. */
23
+ export type ResolvedAgentChatActivityTiming = Required<AgentChatActivityTiming>;
24
+ /** The package's timing: what a chat uses when neither the chat nor the environment names a value. */
25
+ export declare const DEFAULT_AGENT_CHAT_ACTIVITY_TIMING: ResolvedAgentChatActivityTiming;
26
+ /**
27
+ * The timing of one chat: each field from the first source that sets a usable value — the chat's own
28
+ * (`AgentChat activityTiming`), then the environment's (`AgentsEnvironment.chatActivityTiming`), then the package's.
29
+ */
30
+ export declare const resolveAgentChatActivityTiming: (...sources: (AgentChatActivityTiming | null | undefined)[]) => ResolvedAgentChatActivityTiming;
@@ -19,6 +19,12 @@ interface UseActivityTickerParams {
19
19
  * it; false = they fade out with the line beside the face and nothing remains.
20
20
  */
21
21
  keepActivityHistoryAfterAnswer?: boolean;
22
+ /** The least time a line stands beside the face. Default `LINE_PACE_MS` (2200). */
23
+ linePaceMs?: number;
24
+ /** The shorter wait while more than two lines are queued. Default `BACKLOG_LINE_PACE_MS` (1400). */
25
+ backlogLinePaceMs?: number;
26
+ /** The success beat's rest. Default {@link SUCCESS_BEAT_MS}. */
27
+ successBeatMs?: number;
22
28
  }
23
29
  /** One turn's lines — the turn running now, in the face's success beat, or kept in the thread. */
24
30
  export interface ActivityTickerTurn {
@@ -15,6 +15,10 @@ type Params = {
15
15
  /** Advances on every signal tick the host acts on (its message refetch); each advance asks for the activity too. */
16
16
  signalVersion: number;
17
17
  enabled?: boolean;
18
+ /** At most one request per this many milliseconds. Default {@link ACTIVITY_REQUEST_WINDOW_MS}. */
19
+ activityRequestWindowMs?: number;
20
+ /** The request cadence while a turn runs. Default {@link RUNNING_FLOOR_MS}. */
21
+ runningFloorMs?: number;
18
22
  };
19
23
  type Result = {
20
24
  /** The rows of the stack in row order; empty before the first turn of this mount. */
@@ -29,10 +33,10 @@ type Result = {
29
33
  * `getConversationActivity` (`AgentsConversationClientProvider`) while the customer watches a running turn and merges the answer into the stack. Frontend-driven on purpose: nothing is
30
34
  * generated for a hidden tab or a closed chat. The turn is pinned when it starts (`turnMessageId` from the first
31
35
  * answer), so a message the customer sends mid-turn does not move the window. Debounced to one request per
32
- * {@link ACTIVITY_REQUEST_WINDOW_MS} with one trailing request after a burst; a terminal status fires one request for
36
+ * {@link ACTIVITY_REQUEST_WINDOW_MS} (or the host's `activityRequestWindowMs`) with one trailing request after a burst; a terminal status fires one request for
33
37
  * the finished lines, and the requests go on until the endpoint answers that the turn ended — then the stack rests
34
38
  * until the next turn. A failed run ends the turn with that last request, whatever it answers, and so do
35
39
  * {@link MAX_FAILED_REQUESTS_AFTER_SIGNAL_ENDED} failed requests in a row once the signal stopped saying "running".
36
40
  */
37
- export declare const useConversationActivity: ({ conversationId, runStatus, signalVersion, enabled, }: Params) => Result;
41
+ export declare const useConversationActivity: ({ conversationId, runStatus, signalVersion, enabled, activityRequestWindowMs, runningFloorMs, }: Params) => Result;
38
42
  export {};
@@ -1,4 +1,4 @@
1
- import type { AgentsConversation, ChangedConversationMessages, ChangedMessagesRequest, ConversationActivity, ConversationAttachmentReference, ConversationChangeSignal, ConversationListQueryOptions, ConversationMessageSearchHit, ConversationMessageSentPayload, ConversationMessagesPage, ConversationSearchGroup, ConversationSearchOptions, ConversationSignal, ConversationSubscriptionEndReason, PostedMessage, SelectableModel, StartedConversation } from "../contract/conversation";
1
+ import type { AgentsConversation, ChangedConversationMessages, ChangedMessagesRequest, ConversationActivity, ConversationAttachmentReference, ConversationChangeSignal, ConversationListQueryOptions, ConversationMessageSearchHit, ConversationMessageSentPayload, ConversationMessagesPage, ConversationRunStateRead, ConversationSearchGroup, ConversationSearchOptions, ConversationSignal, ConversationSubscriptionEndReason, PostedMessage, SelectableModel, StartedConversation } from "../contract/conversation";
2
2
  /**
3
3
  * The conversation client port (one function per row of the table, derived from the chat
4
4
  * controller's requests). The package calls only this; an app binds it over its own request layer; the package
@@ -14,6 +14,12 @@ import type { AgentsConversation, ChangedConversationMessages, ChangedMessagesRe
14
14
  export interface AgentsConversationClient {
15
15
  /** The conversation without messages: title, run state, the owed-turn mark, purpose, initiator. */
16
16
  getConversationMetadata: (conversationId: number) => Promise<AgentsConversation>;
17
+ /**
18
+ * The server's lean run-state read: run state, owed turn, newest message id, title and summary. Optional: the
19
+ * polling default of the live updates (`withPollingChangeSubscription`) reads it instead of `getConversationMetadata`
20
+ * when the binding has it.
21
+ */
22
+ getConversationRunState?: (conversationId: number) => Promise<ConversationRunStateRead>;
17
23
  /** The newest page, each message with its delegated children's `{ id, runState }`. */
18
24
  getNewestMessagesPage: (conversationId: number, pageSize: number) => Promise<ConversationMessagesPage>;
19
25
  /** The page before `beforeIndex` (scroll-up). */
@@ -0,0 +1,7 @@
1
+ import type { ConversationAttachmentReference } from "../contract/conversation";
2
+ /**
3
+ * The message text a send with attachments stores: the typed text plus one reference line per attachment. The
4
+ * conversation routes of the package take the text only, so a binding carries the attachments in it; the chat shows the
5
+ * optimistic owner message with the same text (`AgentsConversationClient.composeSentMessageText`).
6
+ */
7
+ export declare const composeAttachmentMessageText: (text: string, attachments: ConversationAttachmentReference[] | undefined) => string;
@@ -0,0 +1,30 @@
1
+ import { AgentsClientError, type AgentsClientContext, type AgentsConversation, type AgentsConversationMessage, type ConversationActivity, type ConversationMessageSearchHit, type ConversationRunStateRead, type ConversationSearchGroup, type SelectableModel } from "../../contract/conversation";
2
+ import type { WireClientContext, WireConversation, WireConversationActivityResponse, WireConversationMessage, WireConversationRunStateResponse, WireConversationSearchGroup, WireErrorBody, WireSelectableModel, WireSemanticSearchHit, WireSet } from "./agents-http-wire";
3
+ /** The elements of a serialized set (`{ elements: [...] }`), a plain array, or the values of a keyed object. */
4
+ export declare const readWireSetElements: <Element>(wireSet: WireSet<Element> | Record<string, Element> | null | undefined) => Element[];
5
+ /** An `AIConversation` as the contract's conversation. */
6
+ export declare const mapWireConversation: (wireConversation: WireConversation) => AgentsConversation;
7
+ /** An `AIConversationMessage` as the contract's message. */
8
+ export declare const mapWireConversationMessage: (wireMessage: WireConversationMessage) => AgentsConversationMessage;
9
+ /** The run-state read (`AIConversationRunStateGetResponseDto`). */
10
+ export declare const mapWireConversationRunState: (wireRunState: WireConversationRunStateResponse) => ConversationRunStateRead;
11
+ /** The activity of a turn (`AIConversationActivityGetResponseDto`). */
12
+ export declare const mapWireConversationActivity: (wireActivity: WireConversationActivityResponse) => ConversationActivity;
13
+ /** A `SemanticSearchHit`. */
14
+ export declare const mapWireSearchHit: (wireHit: WireSemanticSearchHit) => ConversationMessageSearchHit;
15
+ /** An `AIConversationSearchGroup`. */
16
+ export declare const mapWireSearchGroup: (wireGroup: WireConversationSearchGroup) => ConversationSearchGroup;
17
+ /** An `AgentCustomerSelectableModel`. */
18
+ export declare const mapWireSelectableModel: (wireModel: WireSelectableModel) => SelectableModel;
19
+ /**
20
+ * A refused request as the port's error: the stable code first (`errorCode` of the JSON body), then the status — 429
21
+ * `rateLimit` (with `Retry-After`), 404 `notFound`, 403 and 401 `forbidden`, 5xx `network`, everything else `other`.
22
+ */
23
+ export declare const mapHttpFailureToAgentsClientError: (httpStatus: number, wireErrorBody: WireErrorBody | null, retryAfterHeader: string | null) => AgentsClientError;
24
+ /**
25
+ * The client context as the body field `clientContext` carries it (`AgentClientContext`): the route parameters as a
26
+ * list of `{name, value}`. A field over its cap ({@link AGENTS_CLIENT_CONTEXT_LIMITS}) or with a control character is
27
+ * left out — never cut — so a send never fails on the context; the route parameters go together or not at all.
28
+ * Undefined when nothing is left.
29
+ */
30
+ export declare const mapClientContextToWire: (clientContext: AgentsClientContext | null | undefined) => WireClientContext | undefined;
@@ -0,0 +1,201 @@
1
+ /**
2
+ * The wire shapes of the module's own conversation routes (`AgentConversationReadsTrait`, `AgentConversationWritesTrait`,
3
+ * `AgentConversationStartTrait`, `AgentSelectableModelsTrait`): the response DTOs and the entities they serialize, as far
4
+ * as the HTTP binding reads them. Every field is optional on the wire — a read hides some (the forensics outside an admin
5
+ * session, the summary on message rows), and an application may derive the classes — so the mappers
6
+ * (`agents-http-mappers.ts`) default each one. An entity set arrives as `{ elements: [...] }`; the mappers also take a
7
+ * plain array.
8
+ */
9
+ /** An entity set or object set as the server serializes it. */
10
+ export type WireSet<Element> = {
11
+ elements?: Element[] | null;
12
+ } | Element[];
13
+ /** `AIConversationSummary`. */
14
+ export interface WireConversationSummary {
15
+ title?: string | null;
16
+ text?: string | null;
17
+ manuallyEdited?: boolean | null;
18
+ }
19
+ /** `CustomerProgressStep`. */
20
+ export interface WireCustomerProgressStep {
21
+ key?: string | null;
22
+ customerLabel?: string | null;
23
+ status?: string | null;
24
+ }
25
+ /** `ChangeHistory` (`ChangeHistoryTrait`). */
26
+ export interface WireChangeHistory {
27
+ createdTime?: string | null;
28
+ modifiedTime?: string | null;
29
+ }
30
+ /** `AIConversation`. */
31
+ export interface WireConversation {
32
+ id?: number | null;
33
+ agentSpaceId?: number | null;
34
+ runState?: string | null;
35
+ agentTurnOwedAt?: string | null;
36
+ summary?: WireConversationSummary | null;
37
+ changeHistory?: WireChangeHistory | null;
38
+ /** Flat date-times, as a derived class or a projection may write them. */
39
+ created?: string | null;
40
+ updated?: string | null;
41
+ purposeName?: string | null;
42
+ initiatorType?: string | null;
43
+ scheduleId?: number | null;
44
+ entryPointKey?: string | null;
45
+ customerProgressSteps?: WireSet<WireCustomerProgressStep> | null;
46
+ lastMessageId?: number | null;
47
+ aiPromptExtensionId?: number | null;
48
+ messages?: WireSet<WireConversationMessage> | null;
49
+ }
50
+ /** `ToolCall`. */
51
+ export interface WireToolCall {
52
+ toolCallId?: string | null;
53
+ name?: string | null;
54
+ arguments?: unknown;
55
+ status?: string | null;
56
+ }
57
+ /** `DelegationSubAgentRun`. */
58
+ export interface WireDelegationSubAgentRun {
59
+ runNumber?: number | null;
60
+ status?: string | null;
61
+ }
62
+ /** `DelegationSubAgentRecord`. */
63
+ export interface WireDelegationSubAgentRecord {
64
+ currentRunNumber?: number | null;
65
+ runs?: WireSet<WireDelegationSubAgentRun> | Record<string, WireDelegationSubAgentRun> | null;
66
+ }
67
+ /** `AIConversationMessage`. */
68
+ export interface WireConversationMessage {
69
+ id?: number | null;
70
+ aiConversationId?: number | null;
71
+ indexInConversation?: number | null;
72
+ role?: string | null;
73
+ messageType?: string | null;
74
+ status?: string | null;
75
+ authorType?: string | null;
76
+ signalSource?: string | null;
77
+ message?: string | null;
78
+ createdDate?: string | null;
79
+ toolCall?: WireToolCall | null;
80
+ delegatedConversations?: WireSet<{
81
+ id?: number | null;
82
+ runState?: string | null;
83
+ }> | null;
84
+ /** `DelegationResults`: the sub-agent record of a newer `delegate` call row. */
85
+ delegationResults?: {
86
+ subAgent?: WireDelegationSubAgentRecord | null;
87
+ } | null;
88
+ /** The admin-only forensics; hidden outside an impersonating admin session. */
89
+ inputTokens?: number | null;
90
+ outputTokens?: number | null;
91
+ costInUSD?: number | null;
92
+ requestSnapshot?: unknown;
93
+ }
94
+ /** `AgentActivityLine`. */
95
+ export interface WireActivityLine {
96
+ toolCallMessageId?: number | null;
97
+ batchId?: string | null;
98
+ state?: string | null;
99
+ kind?: string | null;
100
+ childCount?: number | null;
101
+ helperIndex?: number | null;
102
+ line?: string | null;
103
+ }
104
+ /** `SemanticSearchHit`. */
105
+ export interface WireSemanticSearchHit {
106
+ messageId?: number | null;
107
+ conversationId?: number | null;
108
+ indexInConversation?: number | null;
109
+ role?: string | null;
110
+ excerpt?: string | null;
111
+ relevance?: number | null;
112
+ created?: string | null;
113
+ updated?: string | null;
114
+ title?: string | null;
115
+ }
116
+ /** `AIConversationSearchGroup`. */
117
+ export interface WireConversationSearchGroup {
118
+ conversationId?: number | null;
119
+ title?: string | null;
120
+ summary?: string | null;
121
+ created?: string | null;
122
+ updated?: string | null;
123
+ relevance?: number | null;
124
+ hits?: WireSet<WireSemanticSearchHit> | null;
125
+ }
126
+ /** `AgentCustomerSelectableModel`. */
127
+ export interface WireSelectableModel {
128
+ name?: string | null;
129
+ displayName?: string | null;
130
+ description?: string | null;
131
+ strengthLevel?: number | null;
132
+ speedLevel?: number | null;
133
+ creditsMultiplier?: number | null;
134
+ }
135
+ /** `AIConversationGetResponseDto` (get, postMessage, injectSignal, retry, title). */
136
+ export interface WireConversationResponse {
137
+ aiConversation?: WireConversation | null;
138
+ }
139
+ /** `AIConversationStartWithMessagePostResponseDto`. */
140
+ export interface WireConversationStartResponse extends WireConversationResponse {
141
+ reopenedExistingConversation?: boolean | null;
142
+ }
143
+ /** `AIConversationsGetResponseDto`. */
144
+ export interface WireConversationsResponse {
145
+ aiConversations?: WireSet<WireConversation> | null;
146
+ }
147
+ /** `AIConversationMessagesGetResponseDto`. */
148
+ export interface WireConversationMessagesResponse {
149
+ messages?: WireSet<WireConversationMessage> | null;
150
+ hasMoreOlder?: boolean | null;
151
+ }
152
+ /** `AIConversationRunStateGetResponseDto`. */
153
+ export interface WireConversationRunStateResponse {
154
+ id?: number | null;
155
+ runState?: string | null;
156
+ agentTurnOwedAt?: string | null;
157
+ lastMessageId?: number | null;
158
+ title?: string | null;
159
+ titleManuallyEdited?: boolean | null;
160
+ summary?: string | null;
161
+ updated?: string | null;
162
+ }
163
+ /** `AIConversationActivityGetResponseDto`. */
164
+ export interface WireConversationActivityResponse {
165
+ turnMessageId?: number | null;
166
+ turnRunning?: boolean | null;
167
+ elements?: WireSet<WireActivityLine> | null;
168
+ }
169
+ /** `AIConversationSearchGetResponseDto`. */
170
+ export interface WireConversationSearchResponse {
171
+ conversations?: WireSet<WireConversationSearchGroup> | null;
172
+ }
173
+ /** `AIConversationMessageSearchGetResponseDto`. */
174
+ export interface WireConversationMessageSearchResponse {
175
+ hits?: WireSet<WireSemanticSearchHit> | null;
176
+ }
177
+ /** `AIConversationSelectableModelsGetResponseDto`. */
178
+ export interface WireSelectableModelsResponse {
179
+ models?: WireSet<WireSelectableModel> | null;
180
+ }
181
+ /** One route parameter of `AgentClientContext` on the wire. */
182
+ export interface WireClientContextRouteParameter {
183
+ name: string;
184
+ value: string;
185
+ }
186
+ /** `AgentClientContext`: the body field `clientContext` of a start, a posted message and an injected signal. */
187
+ export interface WireClientContext {
188
+ routePath?: string;
189
+ routeParameters?: WireClientContextRouteParameter[];
190
+ recordKind?: string;
191
+ recordId?: string;
192
+ tab?: string;
193
+ }
194
+ /** The JSON error body of a refused request (`errorCode` on the coded exceptions, `retryAfterSeconds` on a quota). */
195
+ export interface WireErrorBody {
196
+ error?: string | null;
197
+ message?: string | null;
198
+ errorCode?: string | null;
199
+ code?: string | null;
200
+ retryAfterSeconds?: number | null;
201
+ }
@@ -0,0 +1,64 @@
1
+ import type { AgentsConversationClient, AgentsConversationClientBindingOptions } from "../AgentsConversationClient";
2
+ import { type AgentsClientContext } from "../../contract/conversation";
3
+ import type { PollingConversationChangeSubscriptionOptions } from "../polling/createPollingConversationChangeSubscription";
4
+ /** What every request of the binding carries from the host: headers, credentials, mode, cache. */
5
+ export type AgentsHttpFetchOptions = Omit<RequestInit, "method" | "body">;
6
+ export interface AgentsHttpConversationClientOptions extends AgentsConversationClientBindingOptions {
7
+ /**
8
+ * Where the application's conversations controller is mounted (its `#[Route]`): a path such as
9
+ * `/api/agents/conversations` or an absolute URL. The module's routes are relative to it.
10
+ */
11
+ baseUrl: string;
12
+ /**
13
+ * Request options every request carries (credentials, an authorization header). A function is called per request,
14
+ * so it may hand out a fresh token. Default: none (the browser's defaults: same-origin credentials).
15
+ */
16
+ fetchOptions?: AgentsHttpFetchOptions | (() => AgentsHttpFetchOptions | Promise<AgentsHttpFetchOptions>);
17
+ /** The fetch function. Default: the global `fetch`. */
18
+ fetch?: typeof fetch;
19
+ /**
20
+ * The application's start route below `baseUrl` (`AgentConversationStartTrait` declares none). Default: `/start` for
21
+ * a start without an agent space (key 0), `/start/{agentSpaceKey}` otherwise — the start DTO reads `agentSpaceId`
22
+ * from the path.
23
+ */
24
+ buildStartPath?: (agentSpaceKey: number) => string;
25
+ /**
26
+ * The controller uses `AgentSelectableModelsTrait` (`GET …/selectable-models`): the client offers
27
+ * `getSelectableModels` and the chat shows the model picker. Default false.
28
+ */
29
+ hasSelectableModelsRoute?: boolean;
30
+ /**
31
+ * The live updates: the polling default over the run-state read (`withPollingChangeSubscription`), which also reads
32
+ * at once after a post, a signal or a retry the server accepted. The intervals of
33
+ * `PollingConversationChangeSubscriptionOptions`; `false` = no subscription (the host adds its own push transport).
34
+ * Default: polling with the default intervals.
35
+ */
36
+ polling?: PollingConversationChangeSubscriptionOptions | false;
37
+ /**
38
+ * What the owner's client shows, read on every start, posted message and injected signal and sent as the body field
39
+ * `clientContext` (the route, its parameters, the record on screen, the tab). The agent reads the newest one as one
40
+ * line beside the owner's newest message. A field over its cap is left out, never cut. Default: none.
41
+ */
42
+ clientContext?: (operation: AgentsClientContextOperation) => AgentsClientContext | null | undefined;
43
+ }
44
+ /** The writes that carry the client context. */
45
+ export type AgentsClientContextOperation = "startConversation" | "postMessage" | "injectSignal";
46
+ /** The page size of a changed-messages read when the request names none (as the chat sends it). */
47
+ export declare const AGENTS_HTTP_DEFAULT_CHANGED_MESSAGES_PAGE_SIZE = 50;
48
+ /**
49
+ * The conversation client over the module's own conversation routes (`AgentConversationReadsTrait`,
50
+ * `AgentConversationWritesTrait`, the application's start route of `AgentConversationStartTrait`, optionally
51
+ * `AgentSelectableModelsTrait`): `baseUrl` is where the application mounted its conversations controller, `fetchOptions`
52
+ * what every request carries. Every function rejects with `AgentsClientError`. The client comes with live updates —
53
+ * the polling default over the run-state read, which also reads at once after an accepted send — unless `polling` is
54
+ * `false`.
55
+ *
56
+ * ```ts
57
+ * const client = createAgentsHttpConversationClient({
58
+ * baseUrl: "/api/agents/conversations",
59
+ * fetchOptions: () => ({ headers: { Authorization: `Bearer ${readToken()}` } }),
60
+ * });
61
+ * <AgentsProvider client={client}><AgentChat /></AgentsProvider>
62
+ * ```
63
+ */
64
+ export declare const createAgentsHttpConversationClient: (options: AgentsHttpConversationClientOptions) => AgentsConversationClient;
@@ -1,4 +1,4 @@
1
- import { type AgentsConversation, type ConversationChangeSignal, type ConversationRunStatus, type ConversationSubscriptionEndReason } from "../../contract/conversation";
1
+ import { type ConversationChangeSignal, type ConversationRunStateRead, type ConversationRunStatus, type ConversationSubscriptionEndReason } from "../../contract/conversation";
2
2
  /** Read interval while a turn runs (or right after a local send). */
3
3
  export declare const POLLING_RUNNING_INTERVAL_MS = 2000;
4
4
  /** Read interval while the conversation is idle or failed. */
@@ -10,8 +10,11 @@ export declare const POLLING_MAX_BACKOFF_MS = 60000;
10
10
  * server may store the owner's message before it marks the turn as running.
11
11
  */
12
12
  export declare const POLLING_LOCAL_ACTIVITY_WINDOW_MS = 10000;
13
- /** Reads a conversation's metadata — the port's `getConversationMetadata`. */
14
- export type ConversationMetadataReader = (conversationId: number) => Promise<AgentsConversation>;
13
+ /**
14
+ * Reads a conversation's run state — the port's `getConversationRunState`, or its `getConversationMetadata` (every
15
+ * conversation carries the fields the poller reads).
16
+ */
17
+ export type ConversationMetadataReader = (conversationId: number) => Promise<ConversationRunStateRead>;
15
18
  /** The timer functions the poller uses; a spec hands in fake ones. */
16
19
  export interface PollingTimers {
17
20
  setTimeout: (callback: () => void, delayMs: number) => unknown;
@@ -51,7 +54,7 @@ export interface PollingConversationChangeSubscription {
51
54
  * The three-value run status a polled read reports: the stored run state, and "running" for an idle conversation the
52
55
  * server owes a turn (`agentTurnOwedAt`), as the chat's own derivation does.
53
56
  */
54
- export declare const readPolledRunStatus: (conversation: AgentsConversation) => ConversationRunStatus | null;
57
+ export declare const readPolledRunStatus: (conversation: Pick<ConversationRunStateRead, "runState" | "agentTurnOwedAt">) => ConversationRunStatus | null;
55
58
  /**
56
59
  * The polling default of `subscribeToConversationChanges` over a metadata read: every 2 s while a turn
57
60
  * runs, every 20 s while idle, at once after `notifyLocalActivity`; paused while the page is hidden and read once when
@@ -5,7 +5,8 @@ export type AgentsConversationClientWithChangeSubscription = AgentsConversationC
5
5
  /**
6
6
  * The client with live updates: a client that brings its own `subscribeToConversationChanges` (a push
7
7
  * transport — the host application's Firebase binding) is returned as it is; any other gets the polling default over its
8
- * `getConversationMetadata` (`createPollingConversationChangeSubscription`, `options` tune the intervals). The default
9
- * `AgentChat` calls this by itself.
8
+ * `getConversationRunState` when it has one, else over its `getConversationMetadata`
9
+ * (`createPollingConversationChangeSubscription`, `options` tune the intervals). A post, a signal or a retry the server
10
+ * accepted reads at once. The default `AgentChat` calls this by itself.
10
11
  */
11
12
  export declare const withPollingChangeSubscription: (client: AgentsConversationClient, options?: PollingConversationChangeSubscriptionOptions) => AgentsConversationClientWithChangeSubscription;
@@ -85,6 +85,14 @@ export interface AgentsConversation {
85
85
  name: string | null;
86
86
  } | null;
87
87
  }
88
+ /**
89
+ * What the server's run-state read answers (`GET …/{id}/runState`): the lean subset of a conversation the live updates
90
+ * poll. Every `AgentsConversation` is one, so a binding without the read may answer it with the metadata read.
91
+ */
92
+ export type ConversationRunStateRead = Pick<AgentsConversation, "id" | "runState" | "agentTurnOwedAt" | "title" | "titleManuallyEdited" | "summary" | "updated"> & {
93
+ /** generic — the id of the newest stored message; null before the first */
94
+ lastMessageId?: number | null;
95
+ };
88
96
  /** A sub-agent conversation a delegation started, as far as the chat reads it (`delegatedConversations(select=id,runState)`). */
89
97
  export interface ConversationDelegatedConversation {
90
98
  /** generic */
@@ -207,6 +215,33 @@ export interface PostedMessage {
207
215
  messages: AgentsConversationMessage[];
208
216
  }
209
217
  /** A model-visible, owner-invisible note into a conversation (a widget click, a render report, a correction). */
218
+ /**
219
+ * What the owner's client shows while the owner writes: the route, its parameters, the record on screen and the tab.
220
+ * Sent with a start, a posted message and an injected signal; the server stores it on that owner row and the agent reads
221
+ * the newest one as one line beside the owner's newest message. Each field is optional and capped
222
+ * ({@link AGENTS_CLIENT_CONTEXT_LIMITS}); the server refuses a request with a field over its cap (HTTP 400).
223
+ */
224
+ export interface AgentsClientContext {
225
+ /** The path of the route the client shows, e.g. `/tickets/42`. */
226
+ routePath?: string | null;
227
+ /** The parameters of that route by name, values as text. */
228
+ routeParameters?: Record<string, string> | null;
229
+ /** The kind of the record on screen, as the application names it, e.g. `ticket`. */
230
+ recordKind?: string | null;
231
+ /** The id of the record on screen. */
232
+ recordId?: string | number | null;
233
+ /** The tab the client shows. */
234
+ tab?: string | null;
235
+ }
236
+ /** The caps of {@link AgentsClientContext} (characters; the route parameters as their `name=value&…` text). */
237
+ export declare const AGENTS_CLIENT_CONTEXT_LIMITS: {
238
+ readonly routePathChars: 512;
239
+ readonly routeParametersChars: 512;
240
+ readonly routeParameterCount: 20;
241
+ readonly recordKindChars: 64;
242
+ readonly recordIdChars: 128;
243
+ readonly tabChars: 64;
244
+ };
210
245
  export interface ConversationSignal {
211
246
  /** generic */
212
247
  text: string;