@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,146 @@
1
+ import type { AgentId, Conversation, ConversationId } from "../api/index.js";
2
+ import type { AiResult, Place } from "../domain/index.js";
3
+ import type { TrailBuffer } from "./trail/buffer.js";
4
+ /** A file that the chat shows, such as an attachment or a generated file. */
5
+ export interface ChatFile {
6
+ readonly filename: string;
7
+ /** A signed URL that answers the file. */
8
+ readonly url: string;
9
+ }
10
+ /** Downloads and opens chat files by host means, such as the desktop file system. */
11
+ export interface FilePort {
12
+ readonly download: (file: ChatFile) => Promise<void>;
13
+ readonly open: (file: ChatFile) => Promise<void>;
14
+ }
15
+ /** One voice recording that the host makes. */
16
+ export interface SpeechRecording {
17
+ /** Stops the recording and drops it. */
18
+ readonly cancel: () => void;
19
+ /** Stops the recording and answers its text. */
20
+ readonly finish: () => Promise<AiResult<string>>;
21
+ }
22
+ /**
23
+ * Turns the user's voice into message text, for example with a local speech
24
+ * model. A host that passes this port renders its own voice control: the
25
+ * chat then shows no default voice control and never calls the port itself.
26
+ */
27
+ export interface SpeechInputPort {
28
+ readonly record: () => Promise<AiResult<SpeechRecording>>;
29
+ }
30
+ /** The chat state that the host keeps for a Place, for example in a tab. */
31
+ export interface ChatSessionRecord {
32
+ readonly conversationId: ConversationId | null;
33
+ /**
34
+ * `true` when the first message of the open new chat created this
35
+ * Conversation: the host keeps what belongs to that new chat with it.
36
+ */
37
+ readonly fromNewChat?: boolean;
38
+ }
39
+ /**
40
+ * Keeps the chat session of each Place, so that the chat opens where the
41
+ * user left it, and whether the Assistant Sidebar is open. Without
42
+ * `writeAssistantSidebarOpen` the Assistant Sidebar starts closed on each
43
+ * page load.
44
+ */
45
+ export interface SessionStorePort {
46
+ readonly read: (place: Place) => ChatSessionRecord | undefined;
47
+ /** `undefined` when the host keeps no value yet. */
48
+ readonly readAssistantSidebarOpen?: () => boolean | undefined;
49
+ readonly write: (place: Place, session: ChatSessionRecord) => void;
50
+ readonly writeAssistantSidebarOpen?: (open: boolean) => void;
51
+ }
52
+ /** The names of the chat features that the `flags` port can turn off. */
53
+ export declare const chatFeatureFlags: {
54
+ /** The memory switch of a Conversation. */
55
+ readonly memory: "memory";
56
+ /** The Projects of the chat. */
57
+ readonly projects: "projects";
58
+ };
59
+ export type ChatFeatureFlag = (typeof chatFeatureFlags)[keyof typeof chatFeatureFlags];
60
+ /**
61
+ * Tells whether a feature is on for the user. A missing port leaves every
62
+ * flagged feature on; a host maps the names of `chatFeatureFlags` to its own
63
+ * flags.
64
+ */
65
+ export interface FeatureFlagPort {
66
+ readonly isEnabled: (flag: ChatFeatureFlag) => boolean;
67
+ }
68
+ /** What another surface asks the host to open in the chat. */
69
+ export type ChatTarget = Readonly<{
70
+ agentId: AgentId;
71
+ kind: "agent";
72
+ }> | Readonly<{
73
+ conversationId: ConversationId;
74
+ kind: "conversation";
75
+ }>;
76
+ /** Opens the chat at a target, for example from an approvals or activity page. */
77
+ export interface OpenTargetPort {
78
+ readonly open: (target: ChatTarget) => void;
79
+ }
80
+ /** A message that the chat sent to start a turn, and the Conversation that it went to. */
81
+ export type ChatSent = Readonly<{
82
+ conversation: Conversation;
83
+ }>;
84
+ /**
85
+ * Hears each message that the chat sends to start a turn, for example so
86
+ * that the host keeps what the user continues in a tab. The chat calls it
87
+ * once the message goes out; it changes nothing in the chat.
88
+ */
89
+ export interface ChatMessagesPort {
90
+ readonly sent: (sent: ChatSent) => void;
91
+ }
92
+ /**
93
+ * The capabilities that a host gives the chat (ARC-019). Each port is
94
+ * optional: the chat hides the control of a port that the host does not
95
+ * pass. `speechInput` is the other way round: without it the chat shows its
96
+ * default remote voice control where the Place offers remote transcription;
97
+ * with it the host renders its own voice control.
98
+ */
99
+ /**
100
+ * The Context Trail of the tab, as a chat reads it: the chat turns the
101
+ * recording on or off by the "Context Trail enabled" switch of each Place
102
+ * Context that it reads, and each turn that it sends carries the entries.
103
+ * The composer shows the entries as chips and removes the entry of a chip.
104
+ * The buffer of `createTrailBuffer` is one.
105
+ */
106
+ export type ContextTrailPort = Pick<TrailBuffer, "entries" | "recording" | "remove" | "setRecording" | "subscribe">;
107
+ export interface AiHostPorts {
108
+ readonly files?: FilePort;
109
+ readonly flags?: FeatureFlagPort;
110
+ readonly messages?: ChatMessagesPort;
111
+ readonly openTarget?: OpenTargetPort;
112
+ readonly sessions?: SessionStorePort;
113
+ readonly speechInput?: SpeechInputPort;
114
+ /** The Context Trail of the tab; without it, the turns carry no trail. */
115
+ readonly trail?: ContextTrailPort;
116
+ }
117
+ /**
118
+ * The controls that depend on a host port. A control is the port itself when
119
+ * the host passes it and `undefined` when not: hide an undefined control. A
120
+ * flagged control is `true` unless the `flags` port answers off: hide it when
121
+ * it is `false`.
122
+ */
123
+ export interface ChatControls {
124
+ /** Download and open of chat files. */
125
+ readonly files: FilePort | undefined;
126
+ /** The memory switch of a Conversation (flag `chatFeatureFlags.memory`). */
127
+ readonly memory: boolean;
128
+ /** Opening the chat at a target from another surface. */
129
+ readonly openTarget: OpenTargetPort | undefined;
130
+ /** The Projects of the chat (flag `chatFeatureFlags.projects`). */
131
+ readonly projects: boolean;
132
+ /** The Context Trail of the tab: the composer shows its entries as chips. */
133
+ readonly trail: ContextTrailPort | undefined;
134
+ /** Voice input in the composer. */
135
+ readonly voiceInput: SpeechInputPort | undefined;
136
+ }
137
+ /** The controls of a chat on `host`. */
138
+ export declare const chatControls: (host: AiHostPorts) => ChatControls;
139
+ /**
140
+ * A `FilePort` for the browser. It goes to the signed URL of the file
141
+ * unchanged and makes no request of its own, so it sends no credential and
142
+ * needs no CORS rule: `download` follows a download link (the server answers
143
+ * an attachment), `open` shows the file in a new window without an opener.
144
+ * Give it signed URLs only.
145
+ */
146
+ export declare const createBrowserFilePort: () => FilePort;
@@ -0,0 +1,33 @@
1
+ export { recheckAccess } from "./access/access-store.js";
2
+ export type { Visibility } from "./access/access-store.js";
3
+ export { useVisibility, VisibilityGate } from "./access/visibility.js";
4
+ export type { VisibilityGateProps } from "./access/visibility.js";
5
+ export { chatBlockedKinds } from "./blocked-state.js";
6
+ export type { ChatBlockedKind, ChatBlockedState } from "./blocked-state.js";
7
+ export { ChatSessionProvider, useChatSession, useCiChat } from "./chat-session-provider.js";
8
+ export type { ChatSendMode, ChatSession, ChatSessionProviderProps, ChatSessionStatus } from "./chat-session-provider.js";
9
+ export type { ChatSurfaceOptions } from "./chat-surface.js";
10
+ export { chatFeatureFlags, createBrowserFilePort } from "./host-ports.js";
11
+ export type { AiHostPorts, ChatControls, ChatFeatureFlag, ChatMessagesPort, ChatSent, ChatFile, ChatSessionRecord, ChatTarget, ContextTrailPort, FeatureFlagPort, FilePort, OpenTargetPort, SessionStorePort, SpeechInputPort, SpeechRecording } from "./host-ports.js";
12
+ export { IntentsProvider, IntentsRegistryScope, useIntentResult, useIntentsScope, useOptionalIntentsScope, usePieces, useRegisterPiece } from "./intents/intents-provider.js";
13
+ export type { IntentsProviderProps, IntentsRegistryScopeProps, IntentsScope, PieceRegistration } from "./intents/intents-provider.js";
14
+ export type { IntentNotice, IntentResultNotice, IntentWaitStorePort, PageRegistry, PendingIntentWait, Piece, PieceKind, ReturnedIntentHandle } from "./intents/page-registry.js";
15
+ export { useIntentDispatch } from "./intents/use-intent-dispatch.js";
16
+ export type { IntentDispatch, IntentDispatchCall, IntentDispatchOptions, IntentDispatchState, IntentInputs } from "./intents/use-intent-dispatch.js";
17
+ export { useIntents } from "./intents/use-intents.js";
18
+ export type { IntentList } from "./intents/use-intents.js";
19
+ export { useReturnedIntentHandle } from "./intents/use-returned-intent-handle.js";
20
+ export { useHasLaunchTarget, useLaunch } from "./launch/chat-launch.js";
21
+ export type { ChatLaunch, ChatLaunchOptions } from "./launch/chat-launch.js";
22
+ export { useChatLaunchTarget } from "./launch/launch-target.js";
23
+ export type { ChatLaunchTargetOptions } from "./launch/launch-target.js";
24
+ export { submitChatLaunch } from "./launch/submit.js";
25
+ export type { ChatLaunchSession } from "./launch/submit.js";
26
+ export { isOpenRunState, openRunStates } from "./run-state.js";
27
+ export type { TurnRunState } from "./run-state.js";
28
+ export type { ChatCapability, ChatSubmit, NewChat } from "./session-machine.js";
29
+ export { createTrailBuffer, trailBufferSize, turnTrail } from "./trail/buffer.js";
30
+ export type { TrailBuffer } from "./trail/buffer.js";
31
+ export { ContextTrailProvider, useContextTrailEntries, usePageJsonLd, useRecordPageVisit, useTrailBuffer, useTrailEntries, useTrailEvent, useTrailMetadata } from "./trail/trail-provider.js";
32
+ export { readTrailSwitches } from "./trail/switches.js";
33
+ export type { ContextTrailProviderProps } from "./trail/trail-provider.js";
@@ -0,0 +1,22 @@
1
+ import type { CiUIMessage } from "../../domain/index.js";
2
+ import type { ChatSessionStatus } from "../chat-session-provider.js";
3
+ import type { IntentResultNotice } from "./page-registry.js";
4
+ /**
5
+ * How often an open chat reads the transcript again while an Intent card
6
+ * waits for the end of its run (AC-128): no stream carries the end, so the
7
+ * next read joins it.
8
+ */
9
+ export declare const intentCardReloadMs = 5000;
10
+ /** Whether an Intent card of `messages` waits for the end of its run. */
11
+ export declare const intentCardPending: (messages: readonly CiUIMessage[]) => boolean;
12
+ /** Tells which Intent cards of a chat ended since the chat opened its Conversation. */
13
+ export interface IntentCardEndTracker {
14
+ /**
15
+ * The end of each card that ended since the last call, once. The first
16
+ * call after the session gets ready tells nothing: the cards that had
17
+ * ended when the Conversation opened are history.
18
+ */
19
+ readonly observe: (status: ChatSessionStatus, messages: readonly CiUIMessage[]) => readonly IntentResultNotice[];
20
+ }
21
+ /** A tracker of the Intent card ends of one chat. */
22
+ export declare const createIntentCardEndTracker: () => IntentCardEndTracker;
@@ -0,0 +1,28 @@
1
+ import type { IntentInput, IntentOperationId, IntentOutput, IntentsApi } from "../../api/index.js";
2
+ import { AiFailureError } from "../../domain/index.js";
3
+ /**
4
+ * The TanStack Query keys of the Intent controls, one tree per cache scope:
5
+ * the `cacheScope` of the `IntentsProvider` names the caller, so a provider
6
+ * never reads the Intents that another caller may trigger.
7
+ */
8
+ export declare const intentKeys: {
9
+ list: (cacheScope: string) => readonly ["ai", "intents", string, "list"];
10
+ };
11
+ /**
12
+ * Calls one Intent operation: answers its value, or throws its `AiError` as
13
+ * an `AiFailureError`. An adapter that throws instead of answering a result
14
+ * failed to connect, which is `unavailable`.
15
+ */
16
+ export declare const callIntents: <Op extends IntentOperationId>(api: IntentsApi, op: Op, input: IntentInput<Op>, signal?: AbortSignal) => Promise<IntentOutput<Op>>;
17
+ /**
18
+ * The read of the Intents that the caller may trigger now. Without an
19
+ * `IntentsApi` the query never runs.
20
+ */
21
+ export declare const intentListQuery: (cacheScope: string, api: IntentsApi | undefined) => import("@tanstack/react-query").UseQueryOptions<readonly import("../../domain/intents.js").IntentCatalogEntry[], AiFailureError, readonly import("../../domain/intents.js").IntentCatalogEntry[], readonly ["ai", "intents", string, "list"]> & {
22
+ initialData?: import("@tanstack/react-query").InitialDataFunction<readonly import("../../domain/intents.js").IntentCatalogEntry[]> | readonly import("../../domain/intents.js").IntentCatalogEntry[] | undefined;
23
+ } & {
24
+ queryKey: readonly ["ai", "intents", string, "list"] & {
25
+ [dataTagSymbol]: readonly import("../../domain/intents.js").IntentCatalogEntry[];
26
+ [dataTagErrorSymbol]: AiFailureError;
27
+ };
28
+ };
@@ -0,0 +1,108 @@
1
+ import type { ReactNode } from "react";
2
+ import type { AccessCheckPort, IntentsApi } from "../../api/index.js";
3
+ import type { ChatLaunch } from "../launch/chat-launch.js";
4
+ import type { IntentResultNotice, IntentWaitStorePort, PageRegistry, Piece, PieceKind, RegistryScope } from "./page-registry.js";
5
+ /**
6
+ * What the Intent controls below an `IntentsProvider` use: the `IntentsApi`
7
+ * adapter, the Access Check port of the Visibility Gate, the cache scope of
8
+ * the caller, the AI Page Registry and the registry scope of the tree below.
9
+ */
10
+ export interface IntentsScope {
11
+ /** Answers the Visibility Gate; without it every gate answers `denied`. */
12
+ readonly access: AccessCheckPort | undefined;
13
+ /** The adapter of the Intent controls; without it they render nothing. */
14
+ readonly api: IntentsApi | undefined;
15
+ /**
16
+ * The root of every Intent query key: one cache for each `IntentsApi` and
17
+ * caller, so that a provider never reads what another Organization or
18
+ * caller cached.
19
+ */
20
+ readonly cacheScope: string;
21
+ readonly registry: PageRegistry;
22
+ readonly scope: RegistryScope;
23
+ }
24
+ /** The scope of the nearest `IntentsProvider`; `undefined` outside one. */
25
+ export declare const IntentsContext: import("react").Context<IntentsScope | undefined>;
26
+ /** The scope of the nearest `IntentsProvider`; throws outside one. */
27
+ export declare const useIntentsScope: () => IntentsScope;
28
+ /**
29
+ * The scope of the nearest `IntentsProvider`, or `undefined` outside one:
30
+ * for a host part that also runs on a page with no Intents.
31
+ */
32
+ export declare const useOptionalIntentsScope: () => IntentsScope | undefined;
33
+ export interface IntentsProviderProps {
34
+ /** Answers the Access Check of the Visibility Gate; without it every gate answers `denied`. */
35
+ readonly access?: AccessCheckPort | undefined;
36
+ /**
37
+ * The adapter through which the Intent controls reach Collective
38
+ * Intelligence; without it they render nothing. Each adapter object gets
39
+ * its own Intent cache: keep one object for each Organization.
40
+ */
41
+ readonly api: IntentsApi | undefined;
42
+ /**
43
+ * An opaque name of the signed-in caller, such as a user or session id.
44
+ * The Intent hooks cache server data under it, so another caller never
45
+ * reads the cached Intents of the caller before. A new caller also gets a
46
+ * new AI Page Registry, with none of the notices and results of the
47
+ * caller before.
48
+ */
49
+ readonly caller?: string | undefined;
50
+ readonly children?: ReactNode;
51
+ /**
52
+ * Takes a Chat Launch that no chat on the page takes, for example by
53
+ * opening the host's chat page with it. Without it such a launch goes
54
+ * nowhere, and a trigger with the chat Result Target is disabled.
55
+ */
56
+ readonly launchFallback?: ((launch: ChatLaunch) => void) | undefined;
57
+ /**
58
+ * Keeps the pending waits of the AI Page Registry, so that a reload
59
+ * resumes them; without it a pending wait ends with the page. Give each
60
+ * caller its own store: a new caller's registry reads it again.
61
+ */
62
+ readonly waits?: IntentWaitStorePort | undefined;
63
+ }
64
+ /**
65
+ * Gives the Intent controls below it one `IntentsApi`, the Access Check
66
+ * port, a cache scope and the AI Page Registry of the app (AC-048). It needs
67
+ * no chat: `IntentTrigger`, `IntentForm` and `useIntentDispatch` reach only
68
+ * `IntentsApi`. The registry keeps the pending waits in the `waits` port,
69
+ * resumes them after a reload and holds the in-page notices that
70
+ * `<IntentNotices>` shows. Put it at the app root, with one
71
+ * `<IntentNotices>` inside it.
72
+ */
73
+ export declare const IntentsProvider: ({ access, api, caller, children, launchFallback, waits }: IntentsProviderProps) => import("react").JSX.Element;
74
+ export interface IntentsRegistryScopeProps {
75
+ readonly children?: ReactNode;
76
+ }
77
+ /**
78
+ * Opens a child scope of the AI Page Registry for a part of the page: a
79
+ * lookup below it checks this scope first, then its parents.
80
+ */
81
+ export declare const IntentsRegistryScope: ({ children }: IntentsRegistryScopeProps) => import("react").JSX.Element;
82
+ /** A piece that registers while it is mounted. */
83
+ export interface PieceRegistration {
84
+ readonly id: string;
85
+ readonly kind: PieceKind;
86
+ /** Marks the preferred chat of the page, such as the `<ChatDock>`. */
87
+ readonly preferred?: boolean | undefined;
88
+ /**
89
+ * Takes a Chat Launch that reaches this chat; a chat that is collapsed
90
+ * opens itself here. A chat without it is no Launch Target.
91
+ */
92
+ readonly receive?: ((launch: ChatLaunch) => void) | undefined;
93
+ }
94
+ /** Registers a piece in the nearest scope while the calling component is mounted. */
95
+ export declare const useRegisterPiece: (registration: PieceRegistration) => void;
96
+ /**
97
+ * Registers a piece like `useRegisterPiece` inside an `IntentsProvider`, and
98
+ * nothing outside one: for a chat, which runs also on a page with no Intents.
99
+ */
100
+ export declare const useRegisterOptionalPiece: (registration: PieceRegistration) => void;
101
+ /** The mounted pieces of `kind`: those of the nearest scope first, then those of its parents. */
102
+ export declare const usePieces: (kind: PieceKind) => readonly Piece[];
103
+ /**
104
+ * Calls `listener` when an Intent Dispatch of `fqn` on the page ends: a
105
+ * dispatch that ends at once, a Sync wait, or a pending wait of the
106
+ * registry, also after a reload.
107
+ */
108
+ export declare const useIntentResult: (fqn: string, listener: (notice: IntentResultNotice) => void) => void;
@@ -0,0 +1,129 @@
1
+ import type { IntentOutput, IntentsApi } from "../../api/index.js";
2
+ import type { IntentHandle } from "../../domain/index.js";
3
+ import type { ChatLaunch } from "../launch/chat-launch.js";
4
+ /** The end of a run: the Intent Result, or why the run failed. */
5
+ type RunEnd = IntentOutput<"wait">;
6
+ /**
7
+ * A pending wait of the AI Page Registry: an Intent Dispatch with the
8
+ * notification Result Target whose run has not ended yet.
9
+ */
10
+ export interface PendingIntentWait {
11
+ /** The name of the Intent that the in-page notice shows. */
12
+ readonly displayName: string;
13
+ readonly fqn: string;
14
+ readonly handle: IntentHandle;
15
+ }
16
+ /**
17
+ * Keeps the pending waits of the AI Page Registry for the host, for example
18
+ * in the tab session, so that a reload resumes them.
19
+ */
20
+ export interface IntentWaitStorePort {
21
+ readonly read: () => readonly PendingIntentWait[];
22
+ /** Replaces the pending waits that the host keeps. */
23
+ readonly write: (waits: readonly PendingIntentWait[]) => void;
24
+ }
25
+ /** The kinds of piece that register in the AI Page Registry. */
26
+ export type PieceKind = "chat" | "chat_launch" | "intent_trigger" | "trail_source";
27
+ /**
28
+ * A piece on the page: a chat, an Intent trigger, a Chat Launch control or a
29
+ * Context Trail source.
30
+ */
31
+ export interface Piece {
32
+ readonly id: string;
33
+ readonly kind: PieceKind;
34
+ /** `true` for the preferred chat of the page, such as the `<ChatDock>`. */
35
+ readonly preferred: boolean;
36
+ /** Takes a Chat Launch: a chat without it is no Launch Target. */
37
+ readonly receive?: ((launch: ChatLaunch) => void) | undefined;
38
+ }
39
+ /** A part of the page that groups its pieces; the root scope has no parent. */
40
+ export interface RegistryScope {
41
+ readonly parent: RegistryScope | undefined;
42
+ }
43
+ /** The end of an Intent Dispatch on the page, as the listeners of its Intent get it. */
44
+ export interface IntentResultNotice {
45
+ readonly fqn: string;
46
+ /** The Intent Handle of a dispatch that answered `started`; none when the dispatch ended at once. */
47
+ readonly handle: IntentHandle | undefined;
48
+ readonly outcome: RunEnd;
49
+ }
50
+ /**
51
+ * An Intent Handle that the page returned with, such as the page that
52
+ * "Open" on a Studio inbox notice reaches, with the FQN of its Intent.
53
+ */
54
+ export interface ReturnedIntentHandle {
55
+ readonly fqn: string;
56
+ readonly handle: IntentHandle;
57
+ }
58
+ /**
59
+ * The in-page notice of a notification dispatch that ended: `id` is the
60
+ * Intent Handle of a pending wait, or the idempotency key of a dispatch that
61
+ * ended at once.
62
+ */
63
+ export interface IntentNotice {
64
+ readonly displayName: string;
65
+ readonly fqn: string;
66
+ readonly id: string;
67
+ readonly outcome: RunEnd;
68
+ }
69
+ /**
70
+ * What the registry works through: the `IntentsApi`, the port that keeps the
71
+ * waits, and the host's fallback for a Chat Launch that no chat on the page
72
+ * takes, such as opening the host's chat page with the launch.
73
+ */
74
+ export interface RegistryConnection {
75
+ readonly api: IntentsApi | undefined;
76
+ readonly launchFallback?: ((launch: ChatLaunch) => void) | undefined;
77
+ readonly waits: IntentWaitStorePort | undefined;
78
+ }
79
+ /**
80
+ * The state of one app: the pieces on the page by scope, the pending waits,
81
+ * the in-page notices and the listeners of each Intent. Read it with
82
+ * `useSyncExternalStore` through `subscribe`.
83
+ */
84
+ export interface PageRegistry {
85
+ /**
86
+ * Waits through `IntentsApi` on the run end of `returned` and
87
+ * keeps it for the Intent controls and the listeners of its Intent until
88
+ * the answer releases it; a handle that reads `not_found` ends with no
89
+ * result. It shows no in-page notice and keeps nothing in `waits`.
90
+ */
91
+ readonly adopt: (returned: ReturnedIntentHandle) => () => void;
92
+ /** The run end of the latest returned handle of `fqn` that the page keeps. */
93
+ readonly adopted: (fqn: string) => IntentResultNotice | undefined;
94
+ /**
95
+ * Waits through `connection` on each pending wait that its `waits` port
96
+ * keeps, or on the waits in memory without one; the answer stops them.
97
+ */
98
+ readonly connect: (connection: RegistryConnection) => () => void;
99
+ readonly dismiss: (id: string) => void;
100
+ /**
101
+ * Keeps the wait until its run ends, also when the dispatching control
102
+ * leaves the screen; then shows its notice and tells the listeners.
103
+ */
104
+ readonly keep: (wait: PendingIntentWait) => void;
105
+ /**
106
+ * The chat that takes a Chat Launch from `scope`: the chat named `target`,
107
+ * else the preferred chat of the page, else the nearest chat in `scope` or
108
+ * its parents, else the host's launch fallback; `undefined` when nothing
109
+ * takes launches.
110
+ */
111
+ readonly launchTarget: (scope: RegistryScope, target?: string) => Piece | undefined;
112
+ /** Also tells a new listener the run end of each returned handle of `fqn` that the page keeps. */
113
+ readonly listen: (fqn: string, listener: (notice: IntentResultNotice) => void) => () => void;
114
+ readonly notices: () => readonly IntentNotice[];
115
+ /** The pieces of `kind` in `scope` first, then in each parent scope. */
116
+ readonly pieces: (scope: RegistryScope, kind: PieceKind) => readonly Piece[];
117
+ readonly publish: (notice: IntentResultNotice) => void;
118
+ readonly register: (scope: RegistryScope, piece: Piece) => () => void;
119
+ readonly root: RegistryScope;
120
+ /**
121
+ * Shows the in-page notice of a notification dispatch that ended at once;
122
+ * it replaces a notice with the same id.
123
+ */
124
+ readonly show: (notice: IntentNotice) => void;
125
+ readonly subscribe: (onChange: () => void) => () => void;
126
+ }
127
+ /** Makes the registry of one `IntentsProvider`. */
128
+ export declare const createPageRegistry: () => PageRegistry;
129
+ export {};
@@ -0,0 +1,60 @@
1
+ import type { IntentInput } from "../../api/index.js";
2
+ import type { AiError, AiResult, IntentDispatchOutcome, IntentHandle } from "../../domain/index.js";
3
+ type DispatchInput = IntentInput<"dispatch">;
4
+ /** The inputs of an Intent, as JSON. */
5
+ export type IntentInputs = DispatchInput["inputs"];
6
+ /**
7
+ * Where the Intent Result of each dispatch goes, as the app sets it: a
8
+ * notification (with the Studio page that "Open" returns to), or nothing.
9
+ * The chat Result Target dispatches nothing here: `<IntentTrigger>` makes a
10
+ * Chat Launch with it, and the chat dispatches.
11
+ */
12
+ export type IntentDispatchOptions = DispatchInput extends infer Input ? Input extends DispatchInput ? Omit<Input, "fqn" | "idempotencyKey" | "inputs"> : never : never;
13
+ /** The options of one `dispatch()` call. */
14
+ export interface IntentDispatchCall {
15
+ /**
16
+ * The key of this user action; a repeat with the same key and request
17
+ * replays the dispatch. Without it each call makes a new key.
18
+ */
19
+ readonly idempotencyKey?: string;
20
+ }
21
+ /**
22
+ * The state of the latest dispatch: `ready` before it, `working` while it
23
+ * runs or waits for the run end, `needs_input` when inputs are missing or
24
+ * invalid, `done` when the Intent completed or was dispatched, and `failed`
25
+ * when the run failed, the Intent is not allowed or the `IntentsApi` call failed.
26
+ */
27
+ export type IntentDispatchState = "done" | "failed" | "needs_input" | "ready" | "working";
28
+ /** The dispatch of one Intent and the state of its latest dispatch. */
29
+ export interface IntentDispatch {
30
+ /**
31
+ * Dispatches the Intent with these inputs and answers its outcome; when a
32
+ * Sync Intent answers `started` at the Sync wait limit, it answers at the
33
+ * run end. An `IntentsApi` failure is the answer's `AiError`.
34
+ */
35
+ readonly dispatch: (inputs: IntentInputs, call?: IntentDispatchCall) => Promise<AiResult<IntentDispatchOutcome>>;
36
+ /** The `IntentsApi` failure of the latest dispatch. */
37
+ readonly error: AiError | undefined;
38
+ /**
39
+ * The Intent Handle of the latest dispatch that answered `started`; before the
40
+ * first dispatch, the Intent Handle that the page returned with.
41
+ */
42
+ readonly handle: IntentHandle | undefined;
43
+ /**
44
+ * The outcome of the latest dispatch, and the run end that the AI Page
45
+ * Registry waits for once a `started` dispatch ends; before the first
46
+ * dispatch, the run end of the Intent Handle that the page returned with.
47
+ */
48
+ readonly outcome: IntentDispatchOutcome | undefined;
49
+ readonly state: IntentDispatchState;
50
+ }
51
+ /**
52
+ * Dispatches the Intent `fqn` through the `IntentsApi` of `IntentsProvider`;
53
+ * it needs no chat. Each `dispatch()` call is one user action with its own
54
+ * idempotency key; a new call or an unmount stops only the wait of the call
55
+ * before it, never its dispatch request. Before the first dispatch it shows
56
+ * the run end of the Intent Handle of `fqn` that the page returned with
57
+ * (`useReturnedIntentHandle`).
58
+ */
59
+ export declare const useIntentDispatch: (fqn: string, options: IntentDispatchOptions) => IntentDispatch;
60
+ export {};
@@ -0,0 +1,11 @@
1
+ import type { UseQueryResult } from "@tanstack/react-query";
2
+ import type { AiFailureError, IntentCatalogEntry } from "../../domain/index.js";
3
+ /** The Intents that the current user may trigger. */
4
+ export interface IntentList {
5
+ /** `false` without an `IntentsApi` on `IntentsProvider`: hide every Intent control. */
6
+ readonly enabled: boolean;
7
+ /** The catalog entries; idle while `enabled` is `false`. */
8
+ readonly list: UseQueryResult<readonly IntentCatalogEntry[], AiFailureError>;
9
+ }
10
+ /** Lists the Intents that the current user may trigger, through `IntentsApi`. */
11
+ export declare const useIntents: () => IntentList;
@@ -0,0 +1,11 @@
1
+ import type { ReturnedIntentHandle } from "./page-registry.js";
2
+ /**
3
+ * Gives the Intent Result of `returned`, the Intent Handle that the page
4
+ * returned with, to the page while the caller is mounted: the Intent
5
+ * controls of that Intent show it and give it through `onResult` or
6
+ * `render`, and its `useIntentResult` listeners get it, with no new
7
+ * dispatch. A host calls it on the page that "Open" on its inbox notice
8
+ * reaches; `undefined` gives nothing. A handle that reads `not_found`
9
+ * gives no result.
10
+ */
11
+ export declare const useReturnedIntentHandle: (returned: ReturnedIntentHandle | undefined) => void;
@@ -0,0 +1,42 @@
1
+ import type { ContextTrailEntry, PreparedTurn } from "../../domain/index.js";
2
+ /** One Chat Launch: a Prepared Turn, and how the chat that takes it sends it. */
3
+ export interface ChatLaunch {
4
+ /**
5
+ * The Agent of the new Conversation; without it, the Agent pinned on the
6
+ * chat, else plain chat.
7
+ */
8
+ readonly agentId?: string | undefined;
9
+ /**
10
+ * `current` sends the turn into the open Conversation; without it the
11
+ * launch starts a new Conversation.
12
+ */
13
+ readonly conversation?: "current" | undefined;
14
+ /** The id of this launch: the idempotency key of the turn that it sends. */
15
+ readonly launchId: string;
16
+ /** `true` only fills the composer: nothing goes until the user sends it. */
17
+ readonly prefill?: boolean | undefined;
18
+ /**
19
+ * Context Trail entries of the launch, such as the data of the card that
20
+ * launches it: the turn carries them after the trail of the tab, and only
21
+ * while that trail records.
22
+ */
23
+ readonly trail?: readonly ContextTrailEntry[] | undefined;
24
+ readonly turn: PreparedTurn;
25
+ }
26
+ /** How one Chat Launch goes, beside its Prepared Turn. */
27
+ export type ChatLaunchOptions = Omit<ChatLaunch, "launchId" | "turn"> & Readonly<{
28
+ /** The id of the chat that takes the launch, before the preferred chat. */
29
+ target?: string | undefined;
30
+ }>;
31
+ /**
32
+ * Sends a Prepared Turn to its Launch Target at once: the chat named
33
+ * `target`, else the preferred chat of the page, else the nearest chat in
34
+ * scope. Each call makes a new launch id and answers it, or `undefined`
35
+ * when no chat on the page takes the launch.
36
+ */
37
+ export declare const useLaunch: () => ((turn: PreparedTurn, options?: ChatLaunchOptions) => string | undefined);
38
+ /**
39
+ * Whether a Chat Launch from the nearest scope, to the chat named `target`
40
+ * when set, reaches a chat on the page.
41
+ */
42
+ export declare const useHasLaunchTarget: (target?: string) => boolean;
@@ -0,0 +1,25 @@
1
+ import type { ChatSession } from "../chat-session-provider.js";
2
+ import type { ChatLaunchSession } from "./submit.js";
3
+ /** A chat that takes Chat Launches: its id, whether it is preferred, and its session. */
4
+ export type ChatLaunchTargetOptions = Readonly<{
5
+ /** The id that a Chat Launch names as its `target`. */
6
+ id: string;
7
+ /**
8
+ * Called when a Chat Launch reaches this chat, before the chat takes it:
9
+ * for example, a collapsed chat opens itself here (#632 AC-175).
10
+ */
11
+ onLaunch?: (() => void) | undefined;
12
+ /** `true` for the preferred chat of the page, such as the `<AssistantSidebar>`. */
13
+ preferred?: boolean | undefined;
14
+ session: ChatLaunchSession & Pick<ChatSession, "status">;
15
+ }>;
16
+ /**
17
+ * Makes a chat a Launch Target of the AI Page Registry while it is mounted
18
+ * (AC-041): each Chat Launch that reaches it goes into `session` through
19
+ * `submitChatLaunch`. It sends a launch only while the session is `ready`,
20
+ * so a launch never reaches a chat that still reads its Conversations. A
21
+ * chat takes launches only while `ready`; the preferred chat also takes one
22
+ * while its session starts, holds the latest, and sends it once when the
23
+ * session is `ready`. Outside an `IntentsProvider` it registers nothing.
24
+ */
25
+ export declare const useChatLaunchTarget: ({ id, onLaunch, preferred, session }: ChatLaunchTargetOptions) => void;
@@ -0,0 +1,29 @@
1
+ import type { ChatSession } from "../chat-session-provider.js";
2
+ import type { ChatLaunch } from "./chat-launch.js";
3
+ import { AgentId } from "../../api/index.js";
4
+ /**
5
+ * The part of a Chat Session that takes a Chat Launch, with the Agent
6
+ * choice of its chat: the pinned Agent, and whether it offers plain chat
7
+ * (default `true`).
8
+ */
9
+ export type ChatLaunchSession = Pick<ChatSession, "conversationId" | "newChat" | "setDraft" | "submit"> & Readonly<{
10
+ pinnedAgentId?: AgentId | undefined;
11
+ plainChat?: boolean;
12
+ }>;
13
+ /**
14
+ * Submits a Chat Launch into a Chat Session (FLOW-002-STEP-001): the
15
+ * `receive` of a Launch Target calls it with the session of its chat. Without
16
+ * `conversation: "current"` the turn starts a new Conversation: plain chat
17
+ * for an Intent, which an Agent conversation refuses (AC-058), else with the
18
+ * Agent that the launch names, else the Agent pinned on the chat, else plain
19
+ * chat (#632 AC-168); a chat that offers no plain chat only fills its
20
+ * composer then. With it, the turn goes into the open Conversation; while an
21
+ * answer runs there a message waits as a Queued Message (#632 AC-167), and
22
+ * the chat refuses an Intent, a Skill, or a message with its own trail
23
+ * entries as busy (AC-027): a Queued Message keeps only text. The turn goes at
24
+ * once with the launch id as the id of its message, so a retry dispatches
25
+ * nothing again; `prefill` only fills the composer. An Intent turn shows its
26
+ * FQN as its text, and the turn carries the Context Trail of the session's
27
+ * `trail` host port, then the entries of the launch (#632 AC-172).
28
+ */
29
+ export declare const submitChatLaunch: (chat: ChatLaunchSession, { agentId, conversation, launchId, prefill, trail, turn }: ChatLaunch) => void;