@collective-intelligence/ai 0.0.0-stage → 0.8.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 (172) hide show
  1. package/AGENTS.md +52 -0
  2. package/README.md +462 -2
  3. package/dist/api/access-check.d.ts +18 -0
  4. package/dist/api/answer-sources.d.ts +48 -0
  5. package/dist/api/attachments-api.d.ts +187 -0
  6. package/dist/api/catalog-api.d.ts +408 -0
  7. package/dist/api/chat-api.d.ts +2401 -0
  8. package/dist/api/chat-surface-api.d.ts +4186 -0
  9. package/dist/api/compaction.d.ts +52 -0
  10. package/dist/api/conversations.d.ts +107 -0
  11. package/dist/api/errors.d.ts +117 -0
  12. package/dist/api/feedback-api.d.ts +185 -0
  13. package/dist/api/files.d.ts +22 -0
  14. package/dist/api/ids.d.ts +33 -0
  15. package/dist/api/index.d.ts +21 -0
  16. package/dist/api/intents-api.d.ts +65 -0
  17. package/dist/api/place-context.d.ts +34 -0
  18. package/dist/api/projects-api.d.ts +718 -0
  19. package/dist/api/speech-api.d.ts +345 -0
  20. package/dist/api/transcript.d.ts +260 -0
  21. package/dist/api/turns.d.ts +196 -0
  22. package/dist/api.d.ts +21 -0
  23. package/dist/api.js +1 -0
  24. package/dist/domain/access.d.ts +29 -0
  25. package/dist/domain/context-trail.d.ts +65 -0
  26. package/dist/domain/data-parts.d.ts +247 -0
  27. package/dist/domain/errors.d.ts +28 -0
  28. package/dist/domain/index.d.ts +14 -0
  29. package/dist/domain/intents.d.ts +101 -0
  30. package/dist/domain/message.d.ts +173 -0
  31. package/dist/domain/place.d.ts +17 -0
  32. package/dist/domain/runtime-value.d.ts +16 -0
  33. package/dist/domain-50vzrrp9.js +2 -0
  34. package/dist/domain-5fpd4fte.js +1 -0
  35. package/dist/domain-9wzbv87n.js +2 -0
  36. package/dist/domain-g97xs965.js +2 -0
  37. package/dist/domain-hk3yw2m7.js +1 -0
  38. package/dist/domain-qyts6dgz.js +0 -0
  39. package/dist/domain-s07s1ry1.js +2 -0
  40. package/dist/domain.d.ts +14 -0
  41. package/dist/domain.js +1 -0
  42. package/dist/headless/access/access-store.d.ts +28 -0
  43. package/dist/headless/access/visibility.d.ts +24 -0
  44. package/dist/headless/blocked-state.d.ts +21 -0
  45. package/dist/headless/chat-registry.d.ts +63 -0
  46. package/dist/headless/chat-session-provider.d.ts +109 -0
  47. package/dist/headless/chat-surface.d.ts +4210 -0
  48. package/dist/headless/host-ports.d.ts +146 -0
  49. package/dist/headless/index.d.ts +33 -0
  50. package/dist/headless/intents/card-ends.d.ts +22 -0
  51. package/dist/headless/intents/intent-call.d.ts +28 -0
  52. package/dist/headless/intents/intents-provider.d.ts +108 -0
  53. package/dist/headless/intents/page-registry.d.ts +129 -0
  54. package/dist/headless/intents/use-intent-dispatch.d.ts +60 -0
  55. package/dist/headless/intents/use-intents.d.ts +11 -0
  56. package/dist/headless/intents/use-returned-intent-handle.d.ts +11 -0
  57. package/dist/headless/launch/chat-launch.d.ts +42 -0
  58. package/dist/headless/launch/launch-target.d.ts +25 -0
  59. package/dist/headless/launch/submit.d.ts +29 -0
  60. package/dist/headless/run-state.d.ts +16 -0
  61. package/dist/headless/sent-files.d.ts +20 -0
  62. package/dist/headless/server-started-turn-follow.proof.d.ts +26 -0
  63. package/dist/headless/session-machine.d.ts +745 -0
  64. package/dist/headless/trail/buffer.d.ts +48 -0
  65. package/dist/headless/trail/json-ld.d.ts +10 -0
  66. package/dist/headless/trail/switches.d.ts +10 -0
  67. package/dist/headless/trail/trail-provider.d.ts +53 -0
  68. package/dist/headless/transcript-messages.d.ts +26 -0
  69. package/dist/headless.d.ts +33 -0
  70. package/dist/headless.js +2 -0
  71. package/dist/transport/chat-client.d.ts +25 -0
  72. package/dist/transport/chat-transport.d.ts +57 -0
  73. package/dist/transport/index.d.ts +6 -0
  74. package/dist/transport/simulated-chat-transport.d.ts +39 -0
  75. package/dist/transport.d.ts +6 -0
  76. package/dist/transport.js +1 -0
  77. package/dist/views/assistant-sidebar/assistant-sidebar.d.ts +15 -0
  78. package/dist/views/assistant-sidebar/layout.d.ts +47 -0
  79. package/dist/views/assistant-sidebar/toggle.d.ts +14 -0
  80. package/dist/views/assistant-sidebar/use-shortcut.d.ts +11 -0
  81. package/dist/views/blocked/chat-blocked-state.d.ts +15 -0
  82. package/dist/views/chat-operations.d.ts +46 -0
  83. package/dist/views/chat-root.d.ts +14 -0
  84. package/dist/views/chat.d.ts +51 -0
  85. package/dist/views/composer/capability-picker.d.ts +77 -0
  86. package/dist/views/composer/capability-pickers.d.ts +24 -0
  87. package/dist/views/composer/chat-composer.d.ts +15 -0
  88. package/dist/views/composer/composer-picks.d.ts +31 -0
  89. package/dist/views/composer/composer-trail.d.ts +21 -0
  90. package/dist/views/composer/draft-attachments.d.ts +36 -0
  91. package/dist/views/composer/queued-messages.d.ts +9 -0
  92. package/dist/views/composer/send-menu.d.ts +11 -0
  93. package/dist/views/composer/slash-suggestions.d.ts +37 -0
  94. package/dist/views/composer/trail-chips.d.ts +15 -0
  95. package/dist/views/composer/voice-input/microphone.d.ts +14 -0
  96. package/dist/views/composer/voice-input/remote-transcription.d.ts +12 -0
  97. package/dist/views/composer/voice-input/use-voice-input.d.ts +30 -0
  98. package/dist/views/composer/voice-input/voice-input.d.ts +15 -0
  99. package/dist/views/dock/chat-dock.d.ts +57 -0
  100. package/dist/views/dock/dock-session.d.ts +22 -0
  101. package/dist/views/header/chat-header.d.ts +10 -0
  102. package/dist/views/header/compaction-controls.d.ts +17 -0
  103. package/dist/views/header/memory-switch.d.ts +16 -0
  104. package/dist/views/index.d.ts +58 -0
  105. package/dist/views/intents/form-fields.d.ts +38 -0
  106. package/dist/views/intents/intent-card.d.ts +61 -0
  107. package/dist/views/intents/intent-form.d.ts +23 -0
  108. package/dist/views/intents/intent-notices.d.ts +39 -0
  109. package/dist/views/intents/intent-trigger.d.ts +46 -0
  110. package/dist/views/intents/labels.d.ts +23 -0
  111. package/dist/views/labels/en.d.ts +3 -0
  112. package/dist/views/labels/index.d.ts +13 -0
  113. package/dist/views/labels/it.d.ts +3 -0
  114. package/dist/views/labels/types.d.ts +7 -0
  115. package/dist/views/launch/chat-launch-button.d.ts +21 -0
  116. package/dist/views/parts/answer-feedback.d.ts +26 -0
  117. package/dist/views/parts/evidence-part.d.ts +8 -0
  118. package/dist/views/parts/file-part.d.ts +8 -0
  119. package/dist/views/parts/image-generation-part.d.ts +9 -0
  120. package/dist/views/parts/image-generation.d.ts +84 -0
  121. package/dist/views/parts/intent-card-part.d.ts +8 -0
  122. package/dist/views/parts/memory-evidence-part.d.ts +7 -0
  123. package/dist/views/parts/message-parts.d.ts +21 -0
  124. package/dist/views/parts/question-part.d.ts +8 -0
  125. package/dist/views/parts/read-aloud.d.ts +23 -0
  126. package/dist/views/parts/reasoning-part.d.ts +8 -0
  127. package/dist/views/parts/steering-message-part.d.ts +7 -0
  128. package/dist/views/parts/text-part.d.ts +4 -0
  129. package/dist/views/parts/tool-part.d.ts +11 -0
  130. package/dist/views/parts/types.d.ts +103 -0
  131. package/dist/views/parts/use-read-aloud.d.ts +13 -0
  132. package/dist/views/run-trace/message-run.d.ts +17 -0
  133. package/dist/views/run-trace/run-stream.d.ts +128 -0
  134. package/dist/views/run-trace/run-trace-parts.d.ts +26 -0
  135. package/dist/views/run-trace/run-trace.d.ts +31 -0
  136. package/dist/views/sidebar/conversation-dialogs.d.ts +38 -0
  137. package/dist/views/sidebar/conversation-row.d.ts +23 -0
  138. package/dist/views/sidebar/conversation-sidebar.d.ts +10 -0
  139. package/dist/views/sidebar/date-groups.d.ts +12 -0
  140. package/dist/views/sidebar/history-filter.d.ts +57 -0
  141. package/dist/views/sidebar/projects/project-dialogs.d.ts +40 -0
  142. package/dist/views/sidebar/projects/project-files.d.ts +16 -0
  143. package/dist/views/sidebar/projects/project-groups.d.ts +19 -0
  144. package/dist/views/sidebar/projects/project-view.d.ts +21 -0
  145. package/dist/views/sidebar/projects/projects-section.d.ts +21 -0
  146. package/dist/views/sidebar/projects/use-chat-projects.d.ts +32 -0
  147. package/dist/views/slots.d.ts +148 -0
  148. package/dist/views/transcript/chat-transcript.d.ts +13 -0
  149. package/dist/views/transcript/sent-trail.d.ts +13 -0
  150. package/dist/views/transcript/use-image-reload.d.ts +16 -0
  151. package/dist/views.d.ts +58 -0
  152. package/dist/views.js +3 -0
  153. package/docs/guide/ai/index.md +377 -0
  154. package/docs/guide/ai/studio.md +245 -0
  155. package/docs/guide/data/connectors.md +267 -0
  156. package/docs/guide/data/datasets.md +145 -0
  157. package/docs/guide/data/documents.md +235 -0
  158. package/docs/guide/data/index.md +62 -0
  159. package/docs/guide/data/knowledge.md +214 -0
  160. package/docs/guide/develop/extensions.md +299 -0
  161. package/docs/guide/develop/external-apps.md +279 -0
  162. package/docs/guide/develop/infrastructure.md +135 -0
  163. package/docs/guide/develop/sdks.md +233 -0
  164. package/docs/guide/index.md +83 -0
  165. package/docs/guide/platform/access.md +311 -0
  166. package/docs/guide/platform/architecture.md +166 -0
  167. package/docs/guide/platform/built-ins.md +225 -0
  168. package/docs/guide/platform/entrypoints.md +318 -0
  169. package/docs/guide/scenarios/index.md +130 -0
  170. package/docs/guide/template/index.md +295 -0
  171. package/docs/guide/template/state-machines.md +294 -0
  172. package/package.json +123 -4
@@ -0,0 +1,48 @@
1
+ import type { ContextTrailEntry, PageVisit, TrailEventPush, TrailMetadataData } from "../../domain/index.js";
2
+ /** The trail buffer size: the most entries that the browser keeps for a tab. */
3
+ export declare const trailBufferSize = 50;
4
+ /**
5
+ * The bounded browser buffer of one tab's Context Trail (ARC-023). It
6
+ * records only while the Place Context says that the trail is enabled; a
7
+ * chat turn carries its entries. Read it with `useSyncExternalStore`
8
+ * through `subscribe` and `entries`.
9
+ */
10
+ export interface TrailBuffer {
11
+ /** Drops the Trail Metadata of `source`: its piece left the screen. */
12
+ readonly clearMetadata: (source: string) => void;
13
+ /** The entries, the oldest first: the same array until an entry changes. */
14
+ readonly entries: () => readonly ContextTrailEntry[];
15
+ /** Adds a Trail Event of the piece `source`. */
16
+ readonly pushEvent: (source: string, push: TrailEventPush) => void;
17
+ /**
18
+ * Adds a Page Visit. The page of the latest Page Visit makes no new visit:
19
+ * a new title only changes the title of that visit.
20
+ */
21
+ readonly recordPageVisit: (visit: Omit<PageVisit, "at">) => void;
22
+ /** Whether the buffer records: only once a Place Context said that the trail is enabled. */
23
+ readonly recording: () => boolean;
24
+ /** Removes an entry for the user. It stays removed until it changes. */
25
+ readonly remove: (entry: ContextTrailEntry) => void;
26
+ /** Sets the one Trail Metadata entry of `source`; a change makes it the newest entry. */
27
+ readonly setMetadata: (source: string, data: TrailMetadataData) => void;
28
+ /**
29
+ * Takes the "Context Trail enabled" switch of a Place Context answer; the
30
+ * latest answer counts. A disabled trail records nothing and drops the
31
+ * entries that it holds.
32
+ */
33
+ readonly setRecording: (enabled: boolean) => void;
34
+ readonly subscribe: (onChange: () => void) => () => void;
35
+ }
36
+ /**
37
+ * Makes an empty trail buffer that records nothing until `setRecording(true)`.
38
+ * Over the trail buffer size it drops the oldest Page Visit or Trail Event
39
+ * first; Trail Metadata goes only when nothing else is left.
40
+ */
41
+ export declare const createTrailBuffer: (now?: () => string) => TrailBuffer;
42
+ /**
43
+ * The trail that a chat turn carries now: the entries of the tab, the
44
+ * oldest first, then the `launched` entries of a Chat Launch. Nothing while
45
+ * the trail does not record, also not the `launched` entries, and nothing
46
+ * when it holds no entry. The backend keeps the newest entries within 16 KiB.
47
+ */
48
+ export declare const turnTrail: (trail: Pick<TrailBuffer, "entries" | "recording"> | undefined, launched?: readonly ContextTrailEntry[]) => readonly ContextTrailEntry[] | undefined;
@@ -0,0 +1,10 @@
1
+ import type { TrailBuffer } from "./buffer.js";
2
+ /** The prefix of the trail sources of the reader. */
3
+ export declare const readerSource = "json-ld";
4
+ /**
5
+ * Reads the `<script type="application/ld+json">` blocks of the page into
6
+ * `trail` as Trail Metadata, and follows the blocks as they change, until
7
+ * the returned stop runs; the stop drops the entries of the reader. It
8
+ * never reads the GTM data layer (AC-207).
9
+ */
10
+ export declare const readPageJsonLd: (trail: Pick<TrailBuffer, "clearMetadata" | "setMetadata">) => (() => void);
@@ -0,0 +1,10 @@
1
+ import type { ChatSurfaceOptions } from "../chat-surface.js";
2
+ import type { ContextTrailPort } from "../host-ports.js";
3
+ /**
4
+ * Reads the Place Context of the chat mount `api` and turns the recording
5
+ * of `trail` on or off by its "Context Trail enabled" switch (AC-037). A
6
+ * host calls it for the Place that shows, also on a page with no chat, so
7
+ * the trail records there. After a failed read the trail keeps its state:
8
+ * it records nothing until a Place Context said that the trail is enabled.
9
+ */
10
+ export declare const readTrailSwitches: (api: ChatSurfaceOptions, trail: Pick<ContextTrailPort, "setRecording">) => Promise<void>;
@@ -0,0 +1,53 @@
1
+ import type { ReactNode } from "react";
2
+ import type { ContextTrailEntry, PageVisit, TrailEventPush, TrailMetadataData } from "../../domain/index.js";
3
+ import type { TrailBuffer } from "./buffer.js";
4
+ export interface ContextTrailProviderProps {
5
+ readonly children?: ReactNode;
6
+ /**
7
+ * The trail buffer of the tab, from `createTrailBuffer`. Give the same
8
+ * buffer to the `trail` host port of each chat, so that its turns carry it.
9
+ */
10
+ readonly trail: TrailBuffer;
11
+ }
12
+ /**
13
+ * Gives the trail hooks below it the Context Trail of the tab (ARC-023).
14
+ * Put it at the app root. Without it, the trail hooks record nothing.
15
+ */
16
+ export declare const ContextTrailProvider: ({ children, trail }: ContextTrailProviderProps) => import("react").JSX.Element;
17
+ /** The trail buffer of the nearest `ContextTrailProvider`, for the `trail` host port of a chat. */
18
+ export declare const useTrailBuffer: () => TrailBuffer | undefined;
19
+ /** The entries of `trail`, the oldest first; none without a trail. */
20
+ export declare const useTrailEntries: (trail: Pick<TrailBuffer, "entries" | "subscribe"> | undefined) => readonly ContextTrailEntry[];
21
+ /** The entries of the Context Trail of the tab, the oldest first; none outside a provider. */
22
+ export declare const useContextTrailEntries: () => readonly ContextTrailEntry[];
23
+ /**
24
+ * Records a Page Visit for each page that the user opens: call it in the
25
+ * page shell of the host with the app, the page id and the page title. The
26
+ * trail keeps it only while it records.
27
+ */
28
+ export declare const useRecordPageVisit: ({ app, page, title }: Omit<PageVisit, "at">) => void;
29
+ /**
30
+ * Sets what the calling piece shows now as Trail Metadata, shaped like
31
+ * JSON-LD (`{ "@type": "Facility", name: "Milano Nord" }`). The entry
32
+ * changes when `data` changes, and goes away when the piece unmounts.
33
+ * Inside an `IntentsProvider`, the AI Page Registry holds the piece as a
34
+ * trail source while it is mounted. `source` names the piece in the trail;
35
+ * it names one piece only.
36
+ */
37
+ export declare const useTrailMetadata: (data: TrailMetadataData, source?: string) => void;
38
+ /**
39
+ * Answers a push for Trail Events of the calling piece, like a data layer
40
+ * push: `push({ event: "filter_applied", status: "open" })`. The trail
41
+ * keeps the events in push order, and records nothing while it does not
42
+ * record.
43
+ */
44
+ export declare const useTrailEvent: (source?: string) => ((push: TrailEventPush) => void);
45
+ /**
46
+ * Turns the JSON-LD reader on (AC-206): while the calling component is
47
+ * mounted and the trail records, the `<script type="application/ld+json">`
48
+ * blocks of the page are Trail Metadata, and follow the blocks as they
49
+ * change. Without it the trail reads no block. It never reads the GTM data
50
+ * layer (AC-207). Inside an `IntentsProvider`, the AI Page Registry holds
51
+ * the reader as a trail source while it is mounted.
52
+ */
53
+ export declare const usePageJsonLd: () => void;
@@ -0,0 +1,26 @@
1
+ import type { InvocationId, Transcript } from "../api/index.js";
2
+ import type { CiUIMessage } from "../domain/index.js";
3
+ /**
4
+ * The newest turn of a Conversation while it has not ended; the chat
5
+ * resumes it. A plain turn names its invocation. An Agent turn's transcript
6
+ * does not: the stream that the chat resumes names it (`null`).
7
+ */
8
+ export type OpenTurn = Readonly<{
9
+ invocationId: InvocationId | null;
10
+ }>;
11
+ /** The messages of a Conversation for the AI SDK chat, and the turn that is still open. */
12
+ export type ConversationMessages = Readonly<{
13
+ messages: CiUIMessage[];
14
+ openTurn: OpenTurn | null;
15
+ }>;
16
+ /** The media type of a file whose type storage does not know. */
17
+ export declare const unknownMediaType = "application/octet-stream";
18
+ /**
19
+ * The messages of a Conversation from its transcript, for the AI SDK chat
20
+ * (Q249): each user message with its chat attachments before its text,
21
+ * then its answer with the Steering Messages of its turn, its generated
22
+ * images, its text, its Intent cards and its memory evidence. An answer has the id of its turn and a user message `user-` and
23
+ * that id. The answer of an open turn is left out: the chat resumes the
24
+ * turn, whose stream sends that answer from its start.
25
+ */
26
+ export declare const conversationMessages: (transcript: Transcript) => ConversationMessages;
@@ -0,0 +1,33 @@
1
+ export { recheckAccess } from "./headless/access/access-store.js";
2
+ export type { Visibility } from "./headless/access/access-store.js";
3
+ export { useVisibility, VisibilityGate } from "./headless/access/visibility.js";
4
+ export type { VisibilityGateProps } from "./headless/access/visibility.js";
5
+ export { chatBlockedKinds } from "./headless/blocked-state.js";
6
+ export type { ChatBlockedKind, ChatBlockedState } from "./headless/blocked-state.js";
7
+ export { ChatSessionProvider, useChatSession, useCiChat } from "./headless/chat-session-provider.js";
8
+ export type { ChatSendMode, ChatSession, ChatSessionProviderProps, ChatSessionStatus } from "./headless/chat-session-provider.js";
9
+ export type { ChatSurfaceOptions } from "./headless/chat-surface.js";
10
+ export { chatFeatureFlags, createBrowserFilePort } from "./headless/host-ports.js";
11
+ export type { AiHostPorts, ChatControls, ChatFeatureFlag, ChatMessagesPort, ChatSent, ChatFile, ChatSessionRecord, ChatTarget, ContextTrailPort, FeatureFlagPort, FilePort, OpenTargetPort, SessionStorePort, SpeechInputPort, SpeechRecording } from "./headless/host-ports.js";
12
+ export { IntentsProvider, IntentsRegistryScope, useIntentResult, useIntentsScope, useOptionalIntentsScope, usePieces, useRegisterPiece } from "./headless/intents/intents-provider.js";
13
+ export type { IntentsProviderProps, IntentsRegistryScopeProps, IntentsScope, PieceRegistration } from "./headless/intents/intents-provider.js";
14
+ export type { IntentNotice, IntentResultNotice, IntentWaitStorePort, PageRegistry, PendingIntentWait, Piece, PieceKind, ReturnedIntentHandle } from "./headless/intents/page-registry.js";
15
+ export { useIntentDispatch } from "./headless/intents/use-intent-dispatch.js";
16
+ export type { IntentDispatch, IntentDispatchCall, IntentDispatchOptions, IntentDispatchState, IntentInputs } from "./headless/intents/use-intent-dispatch.js";
17
+ export { useIntents } from "./headless/intents/use-intents.js";
18
+ export type { IntentList } from "./headless/intents/use-intents.js";
19
+ export { useReturnedIntentHandle } from "./headless/intents/use-returned-intent-handle.js";
20
+ export { useHasLaunchTarget, useLaunch } from "./headless/launch/chat-launch.js";
21
+ export type { ChatLaunch, ChatLaunchOptions } from "./headless/launch/chat-launch.js";
22
+ export { useChatLaunchTarget } from "./headless/launch/launch-target.js";
23
+ export type { ChatLaunchTargetOptions } from "./headless/launch/launch-target.js";
24
+ export { submitChatLaunch } from "./headless/launch/submit.js";
25
+ export type { ChatLaunchSession } from "./headless/launch/submit.js";
26
+ export { isOpenRunState, openRunStates } from "./headless/run-state.js";
27
+ export type { TurnRunState } from "./headless/run-state.js";
28
+ export type { ChatCapability, ChatSubmit, NewChat } from "./headless/session-machine.js";
29
+ export { createTrailBuffer, trailBufferSize, turnTrail } from "./headless/trail/buffer.js";
30
+ export type { TrailBuffer } from "./headless/trail/buffer.js";
31
+ export { ContextTrailProvider, useContextTrailEntries, usePageJsonLd, useRecordPageVisit, useTrailBuffer, useTrailEntries, useTrailEvent, useTrailMetadata } from "./headless/trail/trail-provider.js";
32
+ export { readTrailSwitches } from "./headless/trail/switches.js";
33
+ export type { ContextTrailProviderProps } from "./headless/trail/trail-provider.js";
@@ -0,0 +1,2 @@
1
+ "use client";
2
+ import{useIntentsScope2,useOptionalIntentsScope2,IntentsProvider2,IntentsRegistryScope2,useRegisterPiece2,usePieces2,useIntentResult2,chatBlockedKinds2,chatSurfaceLayer,callChatSurface,retryRead,chatFeatureFlags2,createBrowserFilePort2,openRunStates2,isOpenRunState2,trailBufferSize2,createTrailBuffer2,turnTrail2,useChatSession2,useCiChat2,ChatSessionProvider2,useIntentDispatch2,useIntents2,useLaunch2,useHasLaunchTarget2,submitChatLaunch2,useChatLaunchTarget2,ContextTrailProvider2,useTrailBuffer2,useTrailEntries2,useContextTrailEntries2,useRecordPageVisit2,useTrailMetadata2,useTrailEvent2,usePageJsonLd2}from"./domain-hk3yw2m7.js";import"./domain-g97xs965.js";import"./domain-5fpd4fte.js";import"./domain-50vzrrp9.js";import"./domain-s07s1ry1.js";var noVersion=Number.NEGATIVE_INFINITY;var accessCheckTargetLimit=200;var focusCount=0;var focusRechecks=new Set;var countingFocus=false;var onFocus=()=>{focusCount+=1;for(const recheck of focusRechecks){recheck()}};var countFocus=()=>{if(!countingFocus){countingFocus=true;window.addEventListener("focus",onFocus)}};var accessKey=(target)=>{switch(target.kind){case"capability":{return JSON.stringify([target.kind,target.code,target.mode])}case"entity_schema":{return JSON.stringify([target.kind,target.fqn,target.access])}case"dataset":{return JSON.stringify([target.kind,target.id])}default:{return JSON.stringify([target.kind,target.fqn])}}};var createAccessStore=(port)=>{let version=noVersion;const entries=new Map;const watchers=new Map;const askedAt=new Map;const inFlight=new Set;const queued=new Set;const askAgain=new Set;const batches=new Set;const notify=(keys)=>{for(const key of keys){for(const listener of watchers.get(key)?.listeners??[]){listener()}}};const outdated=(key)=>(entries.get(key)?.version??version)<version&&(askedAt.get(key)??noVersion)<version;const staleKeys=()=>[...watchers.keys()].filter(outdated);const needsAnswer=(key)=>{const entry=entries.get(key);return entry===undefined||entry.focus<focusCount||outdated(key)};const enqueue=(keys)=>{const idle=queued.size===0;for(const key of keys){if(!inFlight.has(key)){queued.add(key)}}return idle&&queued.size>0};const check=async(keys)=>{const targets=keys.flatMap((key)=>watchers.get(key)?.target??[]);const batch=new AbortController;const focus=focusCount;batches.add(batch);for(const key of keys){inFlight.add(key);askedAt.set(key,version)}const result=await port.check(targets,{signal:batch.signal}).catch(()=>null);batches.delete(batch);if(batch.signal.aborted){return[]}const response=result?.ok===true?result.value:undefined;for(const[index,key]of keys.entries()){inFlight.delete(key);const answer=response?.answers[index];entries.set(key,response===undefined||answer===undefined?{answer:"denied",focus,version:noVersion}:{answer,focus,version:response.accessVersion})}version=Math.max(version,response?.accessVersion??noVersion);notify(keys);const again=keys.filter((key)=>askAgain.delete(key));return[...staleKeys(),...again]};const send=async()=>{const keys=[...queued].filter((key)=>watchers.has(key));queued.clear();const chunks=Array.from({length:Math.ceil(keys.length/accessCheckTargetLimit)},(_,at)=>keys.slice(at*accessCheckTargetLimit,(at+1)*accessCheckTargetLimit));const again=await Promise.all(chunks.map((chunk)=>check(chunk)));if(enqueue(again.flat())){queueMicrotask(()=>{send()})}};const ask=(keys)=>{if(enqueue(keys)){queueMicrotask(()=>{send()})}};const askAll=()=>{for(const key of inFlight){askAgain.add(key)}ask(watchers.keys())};const stop=()=>{focusRechecks.delete(askAll);for(const batch of batches){batch.abort()}batches.clear();inFlight.clear();askAgain.clear()};return{recheck:askAll,visibility:(target)=>entries.get(accessKey(target))?.answer??"loading",watch:(target,onChange)=>{const key=accessKey(target);countFocus();focusRechecks.add(askAll);const watcher=watchers.get(key)??{listeners:new Set,target};watcher.listeners.add(onChange);watchers.set(key,watcher);if(needsAnswer(key)){ask([key])}return()=>{watcher.listeners.delete(onChange);if(watcher.listeners.size===0){watchers.delete(key)}if(watchers.size===0){stop()}}}}};var stores=new WeakMap;var accessStoreFor=(port,cacheScope)=>{const byCaller=stores.get(port)??new Map;stores.set(port,byCaller);const known=byCaller.get(cacheScope);if(known!==undefined){return known}const store=createAccessStore(port);byCaller.set(cacheScope,store);return store};var recheckAccess=(port)=>{for(const store of stores.get(port)?.values()??[]){store.recheck()}};import{useCallback,useMemo,useState,useSyncExternalStore}from"react";var stopNothing=()=>{};var useVisibility=(target)=>{const{access,cacheScope}=useIntentsScope2();const store=useMemo(()=>access===undefined?undefined:accessStoreFor(access,cacheScope),[access,cacheScope]);const[watched,setWatched]=useState(target);if(accessKey(watched)!==accessKey(target)){setWatched(target)}const subscribe=useCallback((onChange)=>store?.watch(watched,onChange)??stopNothing,[store,watched]);const snapshot=useCallback(()=>store?.visibility(watched)??"denied",[store,watched]);return useSyncExternalStore(subscribe,snapshot,snapshot)};var VisibilityGate=({children,fallback,target})=>{const visibility=useVisibility(target);if(visibility==="allowed"){return children}return visibility==="denied"?fallback:null};import{useEffect}from"react";var useReturnedIntentHandle=(returned)=>{const{registry}=useIntentsScope2();const fqn=returned?.fqn;const handle=returned?.handle;useEffect(()=>fqn===undefined||handle===undefined?undefined:registry.adopt({fqn,handle}),[fqn,handle,registry])};import*as Effect from"effect/Effect";var readTrailSwitches=(api,trail)=>Effect.runPromise(retryRead(callChatSurface((client)=>client.chat.getPlaceContext())).pipe(Effect.tap(({contextTrailEnabled})=>Effect.sync(()=>{trail.setRecording(contextTrailEnabled)})),Effect.ignore,Effect.provide(chatSurfaceLayer(api))));export{ChatSessionProvider2 as ChatSessionProvider,ContextTrailProvider2 as ContextTrailProvider,IntentsProvider2 as IntentsProvider,IntentsRegistryScope2 as IntentsRegistryScope,VisibilityGate,chatBlockedKinds2 as chatBlockedKinds,chatFeatureFlags2 as chatFeatureFlags,createBrowserFilePort2 as createBrowserFilePort,createTrailBuffer2 as createTrailBuffer,isOpenRunState2 as isOpenRunState,openRunStates2 as openRunStates,readTrailSwitches,recheckAccess,submitChatLaunch2 as submitChatLaunch,trailBufferSize2 as trailBufferSize,turnTrail2 as turnTrail,useChatLaunchTarget2 as useChatLaunchTarget,useChatSession2 as useChatSession,useCiChat2 as useCiChat,useContextTrailEntries2 as useContextTrailEntries,useHasLaunchTarget2 as useHasLaunchTarget,useIntentDispatch2 as useIntentDispatch,useIntentResult2 as useIntentResult,useIntents2 as useIntents,useIntentsScope2 as useIntentsScope,useLaunch2 as useLaunch,useOptionalIntentsScope2 as useOptionalIntentsScope,usePageJsonLd2 as usePageJsonLd,usePieces2 as usePieces,useRecordPageVisit2 as useRecordPageVisit,useRegisterPiece2 as useRegisterPiece,useReturnedIntentHandle,useTrailBuffer2 as useTrailBuffer,useTrailEntries2 as useTrailEntries,useTrailEvent2 as useTrailEvent,useTrailMetadata2 as useTrailMetadata,useVisibility};
@@ -0,0 +1,25 @@
1
+ import * as Effect from "effect/Effect";
2
+ import * as Stream from "effect/Stream";
3
+ import type { ConversationId } from "../api/index.js";
4
+ import type { CiUIMessage } from "../domain/index.js";
5
+ import type { ChatTransportOptions } from "./chat-transport.js";
6
+ import { AiFailureError } from "../domain/index.js";
7
+ /** One turn of a chat client: the new message of a Conversation. */
8
+ export type ChatClientTurn = Readonly<{
9
+ conversationId: ConversationId;
10
+ /** The user's message, or the assistant message that carries an approval answer or a `ci_ask_user` output. */
11
+ message: CiUIMessage;
12
+ }>;
13
+ /** A chat without React, for server code (Q233). */
14
+ export type ChatClient = Readonly<{
15
+ /** Sends the turn and gives the answer once it ends. */
16
+ send: (turn: ChatClientTurn) => Effect.Effect<CiUIMessage, AiFailureError>;
17
+ /** Sends the turn and gives each state of the answer as it streams. */
18
+ stream: (turn: ChatClientTurn) => Stream.Stream<CiUIMessage, AiFailureError>;
19
+ }>;
20
+ /**
21
+ * The chat client of one mount (AC-309): it sends a turn through
22
+ * {@link createChatTransport} and reads the answer with the AI SDK
23
+ * `readUIMessageStream`. An `error` chunk in the answer fails it.
24
+ */
25
+ export declare const createChatClient: (options: ChatTransportOptions) => ChatClient;
@@ -0,0 +1,57 @@
1
+ import type { ChatTransport, HttpChatTransportInitOptions } from "ai";
2
+ import * as Effect from "effect/Effect";
3
+ import type { CiUIMessage } from "../domain/index.js";
4
+ import { ConversationId } from "../api/index.js";
5
+ import { AiFailureError } from "../domain/index.js";
6
+ /** A fetch: the platform's, or one that adds what a mount needs. */
7
+ export type ChatFetch = (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
8
+ export type ChatTransportOptions = Readonly<{
9
+ /** The mount: the backend origin and its prefix, for example `https://ci.example/application/v1`, or a proxy or BFF base. */
10
+ baseUrl: string | URL;
11
+ /** The fetch of every request, for example one that adds the session or the app's credentials. */
12
+ fetch?: ChatFetch;
13
+ /** Headers of every request, or a function that gives them per request. */
14
+ headers?: HttpChatTransportInitOptions<CiUIMessage>["headers"];
15
+ }>;
16
+ /** A resume found no running turn in the Conversation (the stream route answered 204). */
17
+ export type ResumeEmpty = Readonly<{
18
+ conversationId: ConversationId;
19
+ }>;
20
+ /**
21
+ * The CI chat transport: the AI SDK `ChatTransport` of `CiUIMessage`, and
22
+ * the "resume empty" signal that the session machine listens to (Q258).
23
+ * Every failure is an `AiFailureError`, except an abort.
24
+ */
25
+ export interface CiChatTransport extends ChatTransport<CiUIMessage> {
26
+ /** Calls `listener` on each resume that finds no running turn; returns the function that stops it. */
27
+ readonly onResumeEmpty: (listener: (event: ResumeEmpty) => void) => () => void;
28
+ }
29
+ /** The Conversation id of an AI SDK chat id: the chat is keyed by its Conversation. */
30
+ export declare const conversationIdOf: (chatId: string) => Effect.Effect<ConversationId, AiFailureError>;
31
+ /** The message that a send carries: the last one of the chat. */
32
+ export declare const lastMessage: (messages: readonly CiUIMessage[]) => Effect.Effect<CiUIMessage, AiFailureError>;
33
+ /** The listeners of one transport's "resume empty" signal. */
34
+ export declare const makeResumeEmptySignal: () => {
35
+ emit: (event: ResumeEmpty) => void;
36
+ subscribe: (listener: (event: ResumeEmpty) => void) => () => void;
37
+ };
38
+ /**
39
+ * The typed failure of a chat request: the envelope of a refused request,
40
+ * else the code of its HTTP status; a request that reached no server is
41
+ * `unavailable`.
42
+ */
43
+ export declare const toAiFailure: (cause: unknown) => AiFailureError;
44
+ /**
45
+ * Runs one transport operation for the AI SDK, which takes Promises; its
46
+ * failure rejects the Promise as it is.
47
+ */
48
+ export declare const runForChat: <A>(operation: Effect.Effect<A, Error>) => Promise<A>;
49
+ /**
50
+ * The chat transport of one mount (AC-307, AC-325): an AI SDK
51
+ * `DefaultChatTransport` that posts `POST /chat/:conversationId` with only
52
+ * the last message and the trigger, and resumes with
53
+ * `GET /chat/:conversationId/stream` (Q266). The AI SDK chat id is the
54
+ * Conversation id. The send body is the chat contract alone: a `body`
55
+ * given to the AI SDK send is not sent.
56
+ */
57
+ export declare const createChatTransport: (options: ChatTransportOptions) => CiChatTransport;
@@ -0,0 +1,6 @@
1
+ export { createChatClient } from "./chat-client.js";
2
+ export type { ChatClient, ChatClientTurn } from "./chat-client.js";
3
+ export { createChatTransport } from "./chat-transport.js";
4
+ export type { ChatFetch, ChatTransportOptions, CiChatTransport, ResumeEmpty } from "./chat-transport.js";
5
+ export { createSimulatedChatTransport } from "./simulated-chat-transport.js";
6
+ export type { CiUIMessageChunk, SimulatedAnswer, SimulatedChatScript, SimulatedTurn } from "./simulated-chat-transport.js";
@@ -0,0 +1,39 @@
1
+ import type { InferUIMessageChunk } from "ai";
2
+ import type { ConversationId } from "../api/index.js";
3
+ import type { CiUIMessage } from "../domain/index.js";
4
+ import type { CiChatTransport } from "./chat-transport.js";
5
+ /** One chunk of the UI message stream of a CI answer. */
6
+ export type CiUIMessageChunk = InferUIMessageChunk<CiUIMessage>;
7
+ /** The turn that a simulated chat answers: what `POST /chat/:conversationId` would carry. */
8
+ export type SimulatedTurn = Readonly<{
9
+ conversationId: ConversationId;
10
+ message: CiUIMessage;
11
+ } & ({
12
+ messageId: string;
13
+ trigger: "regenerate-message";
14
+ } | {
15
+ trigger: "submit-message";
16
+ })>;
17
+ /** A prepared answer: plain text, or the exact UI message stream chunks. */
18
+ export type SimulatedAnswer = Readonly<{
19
+ chunks: readonly CiUIMessageChunk[];
20
+ }> | Readonly<{
21
+ text: string;
22
+ }>;
23
+ /** The prepared answers of a simulated chat. */
24
+ export type SimulatedChatScript = Readonly<{
25
+ /** The answer to each turn. */
26
+ answer: (turn: SimulatedTurn) => SimulatedAnswer;
27
+ /** The pause before each chunk, so the answer streams as a server's does. Defaults to 0. */
28
+ chunkDelayMs?: number;
29
+ /** The running turn's stream that a resume finds; `null` (the default) when no turn runs. */
30
+ resume?: (conversationId: ConversationId) => SimulatedAnswer | null;
31
+ }>;
32
+ /**
33
+ * The simulated chat transport (AC-308, Q222): the second adapter of the
34
+ * `ChatTransport` seam. It plays prepared answers as a UI message stream, so
35
+ * a chat renders them as it renders a server answer. A resume without a
36
+ * running turn sends "resume empty", as the HTTP transport does on 204.
37
+ * Chat ids are Conversation ids, as with the HTTP transport.
38
+ */
39
+ export declare const createSimulatedChatTransport: (script: SimulatedChatScript) => CiChatTransport;
@@ -0,0 +1,6 @@
1
+ export { createChatClient } from "./transport/chat-client.js";
2
+ export type { ChatClient, ChatClientTurn } from "./transport/chat-client.js";
3
+ export { createChatTransport } from "./transport/chat-transport.js";
4
+ export type { ChatFetch, ChatTransportOptions, CiChatTransport, ResumeEmpty } from "./transport/chat-transport.js";
5
+ export { createSimulatedChatTransport } from "./transport/simulated-chat-transport.js";
6
+ export type { CiUIMessageChunk, SimulatedAnswer, SimulatedChatScript, SimulatedTurn } from "./transport/simulated-chat-transport.js";
@@ -0,0 +1 @@
1
+ import{ConversationId2}from"./domain-5fpd4fte.js";import{aiErrorCodes2,AiFailureError2}from"./domain-9wzbv87n.js";import{readUIMessageStream}from"ai";import*as Effect2 from"effect/Effect";import*as Option2 from"effect/Option";import*as Stream from"effect/Stream";import{APICallError,DefaultChatTransport}from"ai";import*as Effect from"effect/Effect";import*as Option from"effect/Option";import*as Schema from"effect/Schema";var invalidRequest=(message)=>new AiFailureError2({code:"invalid_request",message,retryable:false});var decodeConversationId=Schema.decodeUnknownOption(ConversationId2);var conversationIdOf=(chatId)=>Effect.fromOption(decodeConversationId(chatId),()=>invalidRequest(`The chat id "${chatId}" is not a Conversation id.`));var lastMessage=(messages)=>Effect.fromOption(Option.fromUndefinedOr(messages.at(-1)),()=>invalidRequest("A chat send has no message."));var makeResumeEmptySignal=()=>{const listeners=new Set;return{emit:(event)=>{for(const listener of listeners){listener(event)}},subscribe:(listener)=>{listeners.add(listener);return()=>{listeners.delete(listener)}}}};var decodeFailureEnvelope=Schema.decodeUnknownOption(Schema.fromJsonString(Schema.Struct({error:Schema.Struct({code:Schema.Literals(aiErrorCodes2),details:Schema.optionalKey(Schema.Struct({reason:Schema.optionalKey(Schema.String)})),message:Schema.String,retryable:Schema.Boolean})})));var codeOfStatus=(status)=>{switch(status){case 400:case 422:{return"invalid_request"}case 401:{return"unauthenticated"}case 403:{return"forbidden"}case 404:{return"not_found"}case 409:{return"conflict"}case 429:{return"rate_limited"}case 502:case 503:case 504:{return"unavailable"}default:{return"internal"}}};var toAiFailure=(cause)=>{if(cause instanceof AiFailureError2){return cause}if(APICallError.isInstance(cause)){return Option.match(decodeFailureEnvelope(cause.responseBody??""),{onNone:()=>{const code=codeOfStatus(cause.statusCode??500);return new AiFailureError2({code,message:cause.message,retryable:code==="rate_limited"||code==="unavailable"},{cause})},onSome:({error:failure})=>{const error={code:failure.code,message:failure.message,retryable:failure.retryable};const reason=failure.details?.reason;return new AiFailureError2(reason===undefined?error:{...error,reason},{cause})}})}if(cause instanceof TypeError){return new AiFailureError2({code:"unavailable",message:cause.message,retryable:true},{cause})}return new AiFailureError2({code:"internal",message:cause instanceof Error?cause.message:String(cause),retryable:false},{cause})};var sdkFetch=(fetch)=>Object.assign((input,init)=>fetch(input,init),{preconnect:()=>null});var runForChat=(operation)=>Effect.runPromise(operation);var isRequestAbort=(cause)=>cause instanceof Error&&cause.name==="AbortError";var requestFailure=(cause)=>isRequestAbort(cause)?cause:toAiFailure(cause);var createChatTransport=(options)=>{const base=String(options.baseUrl).replace(/\/+$/u,"");const chatUrl=(chatId)=>Effect.map(conversationIdOf(chatId),(id)=>`${base}/chat/${id}`);const resumeEmpty=makeResumeEmptySignal();const init={prepareReconnectToStreamRequest:({id})=>runForChat(Effect.map(chatUrl(id),(url)=>({api:`${url}/stream`}))),prepareSendMessagesRequest:({id,messageId,messages,trigger})=>runForChat(Effect.gen(function*sendRequest(){const body={message:yield*lastMessage(messages),trigger};return{api:yield*chatUrl(id),body:messageId===undefined?body:{...body,messageId}}}))};if(options.fetch!==undefined){init.fetch=sdkFetch(options.fetch)}if(options.headers!==undefined){init.headers=options.headers}const http=new DefaultChatTransport(init);return{onResumeEmpty:resumeEmpty.subscribe,reconnectToStream:(request)=>runForChat(Effect.gen(function*resume(){const stream=yield*Effect.tryPromise({catch:requestFailure,try:()=>http.reconnectToStream(request)});if(stream===null){const conversationId=yield*conversationIdOf(request.chatId);resumeEmpty.emit({conversationId})}return stream})),resumeStreamIsReplay:http.resumeStreamIsReplay,sendMessages:(request)=>runForChat(Effect.tryPromise({catch:requestFailure,try:()=>http.sendMessages(request)}))}};var endedWithoutAnswer=()=>new AiFailureError2({code:"internal",message:"The chat answer ended without a message.",retryable:true});var createChatClient=(options)=>{const transport=createChatTransport(options);const stream=({conversationId,message})=>Stream.unwrap(Effect2.tryPromise({catch:toAiFailure,try:(abortSignal)=>transport.sendMessages({abortSignal,chatId:conversationId,messageId:undefined,messages:[message],trigger:"submit-message"})}).pipe(Effect2.map((chunks)=>Stream.fromAsyncIterable(readUIMessageStream({stream:chunks,terminateOnError:true}),toAiFailure))));return{send:(turn)=>Stream.runLast(stream(turn)).pipe(Effect2.flatMap(Option2.match({onNone:()=>Effect2.fail(endedWithoutAnswer()),onSome:Effect2.succeed}))),stream}};import*as Duration from"effect/Duration";import*as Effect3 from"effect/Effect";import*as Schedule from"effect/Schedule";import*as Stream2 from"effect/Stream";var textChunks=(text)=>[{type:"start"},{id:"text-1",type:"text-start"},...text.split(/(?<=\s)/u).map((delta)=>({delta,id:"text-1",type:"text-delta"})),{id:"text-1",type:"text-end"},{type:"finish"}];var play=(answer,chunkDelayMs)=>{const chunks=Stream2.fromIterable("chunks"in answer?answer.chunks:textChunks(answer.text));return Stream2.toReadableStream(chunkDelayMs>0?chunks.pipe(Stream2.schedule(Schedule.spaced(Duration.millis(chunkDelayMs)))):chunks)};var createSimulatedChatTransport=(script)=>{const chunkDelayMs=script.chunkDelayMs??0;const resumeEmpty=makeResumeEmptySignal();return{onResumeEmpty:resumeEmpty.subscribe,reconnectToStream:({chatId})=>runForChat(Effect3.gen(function*resume(){const conversationId=yield*conversationIdOf(chatId);const running=script.resume?.(conversationId)??null;if(running===null){resumeEmpty.emit({conversationId});return null}return play(running,chunkDelayMs)})),resumeStreamIsReplay:true,sendMessages:({chatId,messageId,messages,trigger})=>runForChat(Effect3.gen(function*answer(){const conversationId=yield*conversationIdOf(chatId);const message=yield*lastMessage(messages);const turn=trigger==="regenerate-message"&&messageId!==undefined?{conversationId,message,messageId,trigger}:{conversationId,message,trigger:"submit-message"};return play(script.answer(turn),chunkDelayMs)}))}};export{createChatClient,createChatTransport,createSimulatedChatTransport};
@@ -0,0 +1,15 @@
1
+ import type { ChatProps } from "../chat.js";
2
+ export type AssistantSidebarProps = Omit<ChatProps, "components" | "onLaunch" | "preferred"> & Readonly<{
3
+ /** The title of the header, such as the name of the assistant; it also names the sidebar. */
4
+ title: string;
5
+ }>;
6
+ /**
7
+ * The shared chat for the right panel of an `AssistantSidebarLayout`
8
+ * (#632 AC-041, AC-236–AC-240): the header with the title, delete and
9
+ * Collapse, then the `<Chat>` with its transcript, its Conversation list
10
+ * and its composer, which shows the trail chips. It is the preferred chat
11
+ * of the page: a Chat Launch that names no target comes here and opens the
12
+ * sidebar, also while its session still starts. Render it inside a
13
+ * `ChatSessionProvider`, as `<Chat>`.
14
+ */
15
+ export declare const AssistantSidebar: ({ title, ...chatProps }: AssistantSidebarProps) => import("react").JSX.Element;
@@ -0,0 +1,47 @@
1
+ import type { ReactNode } from "react";
2
+ import type { SessionStorePort } from "../../headless/index.js";
3
+ /**
4
+ * The keys of the two Assistant Sidebar shortcuts: the modifiers `Alt`,
5
+ * `Ctrl`, `Meta` and `Shift`, then one key, joined by `+`, such as
6
+ * `Ctrl+Shift+A`.
7
+ */
8
+ export interface AssistantSidebarShortcuts {
9
+ /** Opens the Assistant Sidebar when it is closed and puts the cursor in its composer. Default `Ctrl+/`. */
10
+ readonly focusComposer?: string | undefined;
11
+ /** Opens and closes the Assistant Sidebar. Default `Ctrl+J`. */
12
+ readonly toggle?: string | undefined;
13
+ }
14
+ export interface AssistantSidebarLayoutProps {
15
+ /** The page: it gets narrower while the Assistant Sidebar is open. */
16
+ readonly children?: ReactNode;
17
+ readonly className?: string | undefined;
18
+ /**
19
+ * The `sessions` port of the host, which keeps whether the sidebar is
20
+ * open across pages and reloads; without it the sidebar starts closed.
21
+ */
22
+ readonly sessions?: Pick<SessionStorePort, "readAssistantSidebarOpen" | "writeAssistantSidebarOpen"> | undefined;
23
+ readonly shortcuts?: AssistantSidebarShortcuts | undefined;
24
+ /** The docked panel at the right side: an `<AssistantSidebar>` in its `ChatSessionProvider`. */
25
+ readonly sidebar: ReactNode;
26
+ }
27
+ /** The open state of the Assistant Sidebar of a layout, for the sidebar and its toggle. */
28
+ interface AssistantSidebarState {
29
+ /** The id of the element that holds the sidebar, which the toggle controls. */
30
+ readonly controlsId: string;
31
+ readonly open: boolean;
32
+ readonly setOpen: (open: boolean) => void;
33
+ }
34
+ /** The open state of the `AssistantSidebarLayout` around the caller. */
35
+ export declare const useAssistantSidebar: () => AssistantSidebarState;
36
+ /**
37
+ * The page with the Assistant Sidebar docked at its right side, in one
38
+ * `ResizablePanelGroup`: the open sidebar takes width from the page, and
39
+ * the user can drag its edge. The open state goes through the host
40
+ * `sessions` port, so the sidebar stays open across pages (#632 Q86). A
41
+ * closed sidebar stays mounted, hidden, so that its preferred chat takes a
42
+ * Chat Launch and opens (#632 AC-175). Two shortcuts that the app sets open
43
+ * and close the sidebar (default `Ctrl+J`) and put the cursor in its
44
+ * composer (default `Ctrl+/`).
45
+ */
46
+ export declare const AssistantSidebarLayout: ({ children, className, sessions, shortcuts, sidebar }: AssistantSidebarLayoutProps) => import("react").JSX.Element;
47
+ export {};
@@ -0,0 +1,14 @@
1
+ import type { ChatLabels, ChatLocale } from "../labels/index.js";
2
+ export interface AssistantSidebarToggleProps {
3
+ readonly className?: string | undefined;
4
+ /** Labels that replace the labels of the locale; the button reads `assistantSidebarToggle`. */
5
+ readonly labels?: Partial<ChatLabels> | undefined;
6
+ /** The language of the labels; `en` when not set. */
7
+ readonly locale?: ChatLocale | undefined;
8
+ }
9
+ /**
10
+ * The button for the top bar of the app that opens a closed Assistant
11
+ * Sidebar and closes an open one. Render it inside the
12
+ * `AssistantSidebarLayout`.
13
+ */
14
+ export declare const AssistantSidebarToggle: ({ className, labels, locale }: AssistantSidebarToggleProps) => import("react").JSX.Element;
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Calls `onPress` when the user presses `shortcut` anywhere on the page:
3
+ * the modifiers `Alt`, `Ctrl`, `Meta` and `Shift`, then one key, joined by
4
+ * `+`, such as `Ctrl+J` or `Ctrl+/`. The press must have exactly these
5
+ * modifiers, except Shift for a key without letter case, which some
6
+ * keyboard layouts type with Shift (`/` on an Italian keyboard); with Alt, a
7
+ * letter matches its key also when Option changes the typed character. A
8
+ * held key calls once, and the browser does not run its own action for the
9
+ * key. Pass a stable `onPress`: a new one listens again.
10
+ */
11
+ export declare const useShortcut: (shortcut: string, onPress: () => void) => void;
@@ -0,0 +1,15 @@
1
+ import type { ChatBlockedStateProps } from "../slots.js";
2
+ /** The title and the description label of each blocked state (D16, AC-208). */
3
+ export declare const blockedLabels: {
4
+ readonly app_not_available: readonly ["appNotAvailable", "appNotAvailableDescription"];
5
+ readonly chat_not_available: readonly ["chatNotAvailable", "chatNotAvailableDescription"];
6
+ readonly service_not_available: readonly ["serviceNotAvailable", "serviceNotAvailableDescription"];
7
+ readonly sign_in_to_chat: readonly ["signInToChat", "signInToChatDescription"];
8
+ };
9
+ /**
10
+ * Shown instead of the chat when the chat cannot run for this user here
11
+ * (AC-204, AC-205, AC-206): sign in to chat, chat not available, app not
12
+ * available or service not available. A service that is not available
13
+ * offers to try again.
14
+ */
15
+ export declare const ChatBlockedState: ({ blocked, className, labels }: ChatBlockedStateProps) => import("react").JSX.Element;
@@ -0,0 +1,46 @@
1
+ import type * as Effect from "effect/Effect";
2
+ import type { ChatSurfaceClient } from "../api/index.js";
3
+ import type { AiError, AiResult } from "../domain/index.js";
4
+ import type { ChatLabels } from "./labels/index.js";
5
+ /** One operation of the typed `ChatSurfaceApi` client. */
6
+ export type ChatOperation<A, E> = (client: ChatSurfaceClient) => Effect.Effect<A, E>;
7
+ /** A read of the default chat: its last answer, and whether it reads now. */
8
+ export type ChatRead<A> = Readonly<{
9
+ isLoading: boolean;
10
+ /** Reads again; the last answer stays until the new one comes. */
11
+ reload: () => void;
12
+ /** The last answer; `null` before the first one and for a read that is off. */
13
+ result: AiResult<A> | null;
14
+ }>;
15
+ /**
16
+ * Reads one operation of the Chat Session's typed client when the component
17
+ * mounts, through `useChatSession().call`. The component reads its
18
+ * operation once: give it a `key` that changes with what it reads.
19
+ */
20
+ export declare const useChatRead: <A, E>(operation: ChatOperation<A, E>, enabled?: boolean) => ChatRead<A>;
21
+ /** A write of the default chat, run as a transition. */
22
+ export type ChatAction = Readonly<{
23
+ /** The failure of the last run; a new run clears it. */
24
+ failure: AiError | null;
25
+ isPending: boolean;
26
+ /** Forgets the failure of the last run. */
27
+ reset: () => void;
28
+ /** Runs an operation; `onDone` gets its answer when it succeeds. */
29
+ run: <A, E>(operation: ChatOperation<A, E>, onDone?: (value: A) => void) => void;
30
+ }>;
31
+ /**
32
+ * Runs writes of the Chat Session's typed client (a rename, a Project, the
33
+ * memory switch) as Actions: the transition holds the pending state, and the
34
+ * failure of the last run stays until the next run.
35
+ */
36
+ export declare const useChatAction: () => ChatAction;
37
+ /**
38
+ * The text of a chat failure that does not block the chat: why a Chat Launch
39
+ * was refused (a busy Conversation, AC-027; an Agent conversation, AC-058);
40
+ * the server's own words for a refusal that says why — a budget refusal
41
+ * (`rate_limited`, "Budget denied: …") or a turn that cannot run until
42
+ * someone changes the setup (`unavailable` that is not retryable, such as
43
+ * "No AI model is available for Studio chat.") — else the generic "This
44
+ * action failed. Try again.".
45
+ */
46
+ export declare const failureText: (failure: AiError, labels: Pick<ChatLabels, "actionFailed" | "launchIntoAgentConversation" | "launchIntoBusyConversation">) => string;
@@ -0,0 +1,14 @@
1
+ import type { ReactNode } from "react";
2
+ export type ChatRootProps = Readonly<{
3
+ children?: ReactNode;
4
+ className?: string | undefined;
5
+ }>;
6
+ /**
7
+ * The chat root (AC-212): the element with the `ci-root` class and the
8
+ * `data-ci-root` attribute. It sets no theme token and takes no theme or
9
+ * color scheme (AC-401): the host app sets the shadcn tokens and the `.dark`
10
+ * class on an ancestor (AC-219). It is the portal container of the dialogs,
11
+ * popovers, menus and tooltips of its subtree, so they render inside it
12
+ * (AC-220).
13
+ */
14
+ export declare const ChatRoot: ({ children, className }: ChatRootProps) => import("react").JSX.Element;
@@ -0,0 +1,51 @@
1
+ import type { Place } from "../domain/index.js";
2
+ import type { ChatLabels, ChatLocale } from "./labels/index.js";
3
+ import type { ChatClassNames, ChatComponents, ChatSlots } from "./slots.js";
4
+ /**
5
+ * The props of the default chat. It has no `theme` and no `colorScheme`
6
+ * prop (AC-401): the host app sets the shadcn tokens and the `.dark` class.
7
+ */
8
+ export type ChatProps = Readonly<{
9
+ /** A class name for each part, beside its `data-part` attribute (AC-197). */
10
+ classNames?: ChatClassNames;
11
+ /** Parts that replace the default parts, by part name (AC-196). */
12
+ components?: ChatComponents;
13
+ /** Narrows the History Scope of the list to these Places, inside the Place's ceiling (AC-245). */
14
+ historyScope?: readonly Place[];
15
+ /**
16
+ * The id of the chat as a Launch Target (AC-041): a Chat Launch that names
17
+ * it as its `target` comes to this chat. Default: an id of its own.
18
+ */
19
+ id?: string;
20
+ /** Labels that replace the labels of the locale with the same name (AC-200). */
21
+ labels?: Partial<ChatLabels>;
22
+ /** The language of the labels; `en` when not set (AC-199). */
23
+ locale?: ChatLocale;
24
+ /**
25
+ * Called when a Chat Launch reaches this chat, before the chat takes it:
26
+ * for example, a collapsed panel opens itself (#632 AC-175).
27
+ */
28
+ onLaunch?: () => void;
29
+ /** Every new Conversation starts with this agent (AC-202). */
30
+ pinnedAgentId?: string;
31
+ /** The Place where the chat runs: the Place of its `ChatSessionProvider`. */
32
+ place: Place;
33
+ /** `true` makes this chat the preferred Launch Target of the page (#632 AC-174). */
34
+ preferred?: boolean;
35
+ /**
36
+ * `false` hides plain chat (AC-203): without a pinned agent, a new
37
+ * Conversation starts only with an agent that the user picks. Default
38
+ * `true`.
39
+ */
40
+ plainChat?: boolean;
41
+ /** Content at fixed places of the layout (AC-195). */
42
+ slots?: ChatSlots;
43
+ }>;
44
+ /**
45
+ * The default chat (AC-194): the Conversation sidebar, the header, the
46
+ * transcript and the composer with the Studio layout, or the blocked state
47
+ * when the chat cannot run. It renders inside the chat root (`.ci-root`,
48
+ * AC-212) over the Chat Session of the nearest `ChatSessionProvider`, and
49
+ * reads all data through the headless hooks.
50
+ */
51
+ export declare const Chat: ({ classNames, components, historyScope, id, labels, locale, onLaunch, pinnedAgentId, place, plainChat, preferred, slots }: ChatProps) => import("react").JSX.Element;