@pgege/kaboo-react 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,8 +1,9 @@
1
1
  import { a as KabooInterruptHandlerProps, I as InterruptReason, A as ActivityState, D as DrillState, S as StreamGroup, T as ToolCall, b as InterruptRendererProps, c as TimelineEntry } from './KabooInterruptHandler-BO2Uv3gS.js';
2
2
  export { d as ApprovalReason, F as FormQuestion, e as FormReason, f as InterruptData } from './KabooInterruptHandler-BO2Uv3gS.js';
3
3
  import * as react from 'react';
4
- import { ReactElement, ReactNode } from 'react';
5
- import { CopilotKitProps } from '@copilotkit/react-core/v2';
4
+ import { ReactElement, ReactNode, ComponentProps } from 'react';
5
+ import { CopilotKitProps, CopilotChatInput } from '@copilotkit/react-core/v2';
6
+ import { InputContent, AttachmentUploadResult, AttachmentsConfig } from '@copilotkit/shared';
6
7
 
7
8
  /**
8
9
  * A map of custom renderers for structured agent output, keyed by the output
@@ -79,6 +80,117 @@ declare function DrillProvider({ children }: {
79
80
  children: ReactNode;
80
81
  }): react.JSX.Element;
81
82
 
83
+ /**
84
+ * Wire keys shared with kaboo-workflows. A file attachment carries its id/kind/
85
+ * name in the CopilotKit `InputContent` part `metadata` under these keys; the
86
+ * Python side reads the same keys back out. Kept snake_case so both stacks
87
+ * agree without a translation layer.
88
+ */
89
+ declare const REFERENCE_METADATA_KEYS: {
90
+ /** Metadata key carrying the reference id. */
91
+ readonly id: "kaboo_id";
92
+ /** Metadata key carrying the reference kind. */
93
+ readonly kind: "kaboo_kind";
94
+ /** Metadata key carrying the reference display name. */
95
+ readonly name: "kaboo_name";
96
+ };
97
+ /** AG-UI `state` key under which object-transport references travel. */
98
+ declare const REFERENCES_STATE_KEY = "kaboo_references";
99
+ /**
100
+ * How a reference reaches the agent.
101
+ *
102
+ * - `attachment` — a file/blob (pdf, image, csv, …). Serialized as a CopilotKit
103
+ * `InputContent` part; its bytes are resolvable server-side. Files are the
104
+ * only blob-capable transport.
105
+ * - `object` — a pointer to a custom entity (table, dashboard, ticket, …).
106
+ * Serialized into `state.kaboo_references`; resolved by the app's own MCP
107
+ * tool. Never carries bytes.
108
+ */
109
+ type ReferenceTransport = "attachment" | "object";
110
+ /**
111
+ * One selectable item surfaced by a {@link ReferenceProvider} in the `@` menu.
112
+ * `data` is provider-defined and threaded back to {@link ReferenceProvider.toReference}.
113
+ */
114
+ interface ReferenceItem<T = unknown> {
115
+ /** Stable id for the underlying entity (provider scope). */
116
+ id: string;
117
+ /** Human label shown in the menu and used as the default mention chip text. */
118
+ label: string;
119
+ /** Optional secondary line (e.g. a path, table schema, owner). */
120
+ description?: string;
121
+ /** Provider-defined payload passed to {@link ReferenceProvider.toReference}. */
122
+ data?: T;
123
+ }
124
+ /**
125
+ * A reference that has been selected and is pending on the composer, before it
126
+ * is serialized onto the outgoing message.
127
+ */
128
+ type PendingReference = {
129
+ /** Blob-capable transport discriminant. */
130
+ transport: "attachment";
131
+ /** Reference kind (e.g. `"file"`). */
132
+ kind: string;
133
+ /** Stable reference id, shared with the backend manifest. */
134
+ id: string;
135
+ /** File name shown on the chip. */
136
+ name: string;
137
+ /** MIME type of the file. */
138
+ mimeType: string;
139
+ /** Byte source: a fetchable URL, or inline base64. */
140
+ source: {
141
+ /** A fetchable URL (preferred; keeps transport and log small). */
142
+ url: string;
143
+ } | {
144
+ /** Inline base64 payload (fallback for small files). */
145
+ data: string;
146
+ };
147
+ } | {
148
+ /** Pointer-only transport discriminant. */
149
+ transport: "object";
150
+ /** Reference kind (e.g. `"table"`), resolved by your MCP tool. */
151
+ kind: string;
152
+ /** Stable reference id, shared with the backend manifest. */
153
+ id: string;
154
+ /** Label shown on the chip. */
155
+ name: string;
156
+ /** Arbitrary extra context threaded through to the resolver. */
157
+ meta?: Record<string, unknown>;
158
+ };
159
+ /**
160
+ * A pluggable entry in the `@` reference menu. File upload ships as a built-in
161
+ * provider (see `uploadProvider`); apps register their own for entities/actions
162
+ * (tables, dashboards, tickets, …).
163
+ *
164
+ * A provider is either *searchable* (supplies {@link search} so its items list
165
+ * live in the menu) or *action-only* (omits {@link search}; selecting its group
166
+ * row runs {@link onSelect}, e.g. opening a file picker).
167
+ */
168
+ interface ReferenceProvider<T = unknown> {
169
+ /** Stable provider id, e.g. `"upload" | "table" | "dashboard"`. */
170
+ id: string;
171
+ /** Group heading shown in the `@` menu. */
172
+ label: string;
173
+ /** Optional icon rendered beside the group heading. */
174
+ icon?: ReactNode;
175
+ /**
176
+ * Return the items to list for the current query. Omit for an action-only
177
+ * provider (its group row triggers {@link onSelect} directly).
178
+ */
179
+ search?: (query: string) => ReferenceItem<T>[] | Promise<ReferenceItem<T>[]>;
180
+ /** Custom row renderer; falls back to `label` + `description`. */
181
+ renderItem?: (item: ReferenceItem<T>) => ReactNode;
182
+ /**
183
+ * Side effect when an item (or the action-only group row) is chosen, e.g.
184
+ * opening a file dialog or running an action. Called before {@link toReference}.
185
+ */
186
+ onSelect?: (item: ReferenceItem<T>) => void | Promise<void>;
187
+ /**
188
+ * How a chosen item serializes onto the message. Omit for pure actions that
189
+ * produce their reference asynchronously (e.g. upload, via its own callback).
190
+ */
191
+ toReference?: (item: ReferenceItem<T>) => PendingReference;
192
+ }
193
+
82
194
  /** Props for {@link KabooProvider}. */
83
195
  interface KabooProviderProps {
84
196
  /** URL of the CopilotKit runtime endpoint (e.g. `/api/copilotkit`). */
@@ -95,6 +207,11 @@ interface KabooProviderProps {
95
207
  disableInterruptHandler?: boolean;
96
208
  /** Skip auto-mounting the built-in {@link KabooInlineCards}. */
97
209
  disableInlineCards?: boolean;
210
+ /**
211
+ * `@` reference providers made available to the composer / `useReferences`.
212
+ * File upload is not implicit — include `uploadProvider()` to offer uploads.
213
+ */
214
+ references?: ReferenceProvider[];
98
215
  /** Extra props forwarded to the underlying `<CopilotKit>`. */
99
216
  copilotKitProps?: Partial<Omit<CopilotKitProps, "children" | "runtimeUrl" | "agent" | "threadId">>;
100
217
  /** Your app subtree, rendered inside all kaboo contexts. */
@@ -125,7 +242,7 @@ interface KabooProviderProps {
125
242
  * }
126
243
  * ```
127
244
  */
128
- declare function KabooProvider({ runtimeUrl, agent, threadId, structuredRenderers, interruptRenderers, disableInterruptHandler, disableInlineCards, copilotKitProps, children, }: KabooProviderProps): react.JSX.Element;
245
+ declare function KabooProvider({ runtimeUrl, agent, threadId, structuredRenderers, interruptRenderers, disableInterruptHandler, disableInlineCards, references, copilotKitProps, children, }: KabooProviderProps): react.JSX.Element;
129
246
 
130
247
  /**
131
248
  * An open interrupt published onto the InterruptBridge so an owning agent card
@@ -243,6 +360,209 @@ declare function useActivity(): ActivityState;
243
360
  */
244
361
  declare function useDrill(): DrillState;
245
362
 
363
+ /**
364
+ * Mint a stable reference id. Client-minted so the same id travels in the
365
+ * message/state AND is what the agent later reads from the manifest and passes
366
+ * to a tool. Prefixed by kind for readability in logs/manifests.
367
+ */
368
+ declare function mintReferenceId(kind: string): string;
369
+ /**
370
+ * The textual marker kept at a reference's mention position in the message
371
+ * text, so the model sees *where* each reference was cited (correlated to the
372
+ * manifest by id). Chip UIs render `@name`; the serialized text keeps this
373
+ * token.
374
+ */
375
+ declare function referenceMarker(ref: PendingReference): string;
376
+ /**
377
+ * Turn an `attachment`-transport reference into a CopilotKit `InputContent`
378
+ * part, stamping the reference id/kind/name into `metadata` so kaboo-workflows
379
+ * can key its registry off the same id the model reads from the manifest.
380
+ */
381
+ declare function attachmentToInputContent(ref: Extract<PendingReference, {
382
+ transport: "attachment";
383
+ }>): InputContent;
384
+ /** The serialized shape of an object reference inside `state.kaboo_references`. */
385
+ interface SerializedObjectReference {
386
+ /** Reference kind (e.g. `"table"`), resolved by the app's MCP tool. */
387
+ kind: string;
388
+ /** Stable reference id, shared with the backend manifest. */
389
+ id: string;
390
+ /** Human-readable label. */
391
+ name: string;
392
+ /** Arbitrary extra context threaded through to the resolver. */
393
+ meta?: Record<string, unknown>;
394
+ }
395
+ /** Project an `object`-transport reference to its wire shape. */
396
+ declare function objectToStateEntry(ref: Extract<PendingReference, {
397
+ transport: "object";
398
+ }>): SerializedObjectReference;
399
+ /** The fully serialized outgoing payload derived from a set of pending references. */
400
+ interface SerializedReferences {
401
+ /** `InputContent` parts for attachment-transport references (append after text). */
402
+ attachmentParts: InputContent[];
403
+ /** Object-transport references destined for `state.kaboo_references`. */
404
+ objectReferences: SerializedObjectReference[];
405
+ }
406
+ /** Split + serialize pending references into attachment parts and object-state entries. */
407
+ declare function serializeReferences(refs: PendingReference[]): SerializedReferences;
408
+ /**
409
+ * Merge object references into an existing AG-UI `state` under
410
+ * {@link REFERENCES_STATE_KEY}. Returns a new object; empty input clears the key
411
+ * so a prior turn's references never leak into the next run.
412
+ */
413
+ declare function withReferenceState(state: Record<string, unknown> | undefined, objectReferences: SerializedObjectReference[]): Record<string, unknown>;
414
+ /**
415
+ * Build the multimodal `content` array for a user message: the typed text
416
+ * (already containing positional markers) followed by the attachment parts.
417
+ * AG-UI content is an ordered array, so parts are appended after the text.
418
+ */
419
+ declare function buildUserContent(text: string, attachmentParts: InputContent[]): InputContent[];
420
+
421
+ /** Value exposed by {@link useReferences}. */
422
+ interface ReferencesContextValue {
423
+ /** Registered `@` providers (upload built-in + app-defined). */
424
+ providers: ReferenceProvider[];
425
+ /** References currently staged on the composer. */
426
+ pending: PendingReference[];
427
+ /** Stage a reference (deduped by id). */
428
+ addReference: (ref: PendingReference) => void;
429
+ /** Remove a staged reference by id. */
430
+ removeReference: (id: string) => void;
431
+ /** Clear all staged references (call after a message is sent). */
432
+ clearReferences: () => void;
433
+ /**
434
+ * Object references sent with each user message, keyed by message id. Object
435
+ * references ride `state.kaboo_references` rather than the message content, so
436
+ * they'd otherwise be invisible in the sent bubble — this lets the user
437
+ * message renderer show them as chips.
438
+ */
439
+ messageReferences: Record<string, PendingReference[]>;
440
+ /** Record the object references attached to a sent user message. */
441
+ recordMessageReferences: (messageId: string, refs: PendingReference[]) => void;
442
+ }
443
+ /** Props for {@link ReferencesProvider}. */
444
+ interface ReferencesProviderProps {
445
+ /** The `@` provider registry. File upload is not implicit — pass `uploadProvider()`. */
446
+ providers?: ReferenceProvider[];
447
+ /**
448
+ * Sync staged object-transport references into the bound agent's
449
+ * `state.kaboo_references` as they change, so a plain `<CopilotChat>` send
450
+ * still carries them. Default `true`. Attachment references travel on the
451
+ * message itself and are unaffected.
452
+ */
453
+ syncObjectStateTo?: string | false;
454
+ /** The subtree that can stage and read references. */
455
+ children: ReactNode;
456
+ }
457
+ /**
458
+ * Holds the `@` reference registry and the composer's staged references, and
459
+ * (by default) mirrors object references into the agent's AG-UI state. Mounted
460
+ * automatically by {@link KabooProvider}; read it via {@link useReferences}.
461
+ */
462
+ declare function ReferencesProvider({ providers, syncObjectStateTo, children, }: ReferencesProviderProps): react.JSX.Element;
463
+ /**
464
+ * Mirrors staged object-transport references into the bound agent's
465
+ * `state.kaboo_references`. Mounted by {@link ReferencesProvider} when
466
+ * `syncObjectStateTo` is set.
467
+ */
468
+ declare function ReferenceStateSync({ agentId, pending, }: {
469
+ agentId?: string;
470
+ pending: PendingReference[];
471
+ }): null;
472
+ /**
473
+ * Access the `@` reference registry and staged references.
474
+ *
475
+ * @example
476
+ * ```tsx
477
+ * const { providers, pending, addReference } = useReferences();
478
+ * ```
479
+ */
480
+ declare function useReferences(): ReferencesContextValue;
481
+
482
+ type CopilotInputProps = ComponentProps<typeof CopilotChatInput>;
483
+ /**
484
+ * Props for {@link KabooReferenceInput}. This is a drop-in value for
485
+ * `<CopilotChat input={…}>`, so it receives every prop CopilotKit hands the
486
+ * input slot (value, onChange, onSubmitMessage, …) plus a couple of
487
+ * kaboo-specific knobs.
488
+ */
489
+ interface KabooReferenceInputProps extends CopilotInputProps {
490
+ /** Character that opens the reference popover from the editor. Default `"@"`. */
491
+ trigger?: string;
492
+ }
493
+ /**
494
+ * A `<CopilotChat input={…}>` slot that keeps CopilotKit's native input chrome
495
+ * (send button, disclaimer, theme, layout) but replaces the plain textarea with
496
+ * a lightweight rich editor. References — your objects (via `@`) and files (via
497
+ * the `+` button or the "attach a file" row) — render as interactive inline
498
+ * chips: click a chip to swap it for another, or its `×` to remove it. The `+`
499
+ * and `@` triggers open the *same* searchable popover. Object references ride
500
+ * `state.kaboo_references` (agent sees them inline as `@name`); files ride the
501
+ * message as attachment parts (agent is made aware via the manifest). On submit
502
+ * the editor builds the multimodal message and runs the agent.
503
+ *
504
+ * @example
505
+ * ```tsx
506
+ * <KabooProvider references={[uploadProvider({ onUpload }), tableProvider]} …>
507
+ * <CopilotChat input={KabooReferenceInput} />
508
+ * </KabooProvider>
509
+ * ```
510
+ */
511
+ declare function KabooReferenceInput({ trigger, ...inputProps }: KabooReferenceInputProps): react.JSX.Element;
512
+
513
+ /** Configuration for the built-in file {@link uploadProvider}. */
514
+ interface UploadProviderConfig {
515
+ /** Provider id in the `@` menu. Default `"upload"`. */
516
+ id?: string;
517
+ /** Group label in the `@` menu. Default `"Upload"`. */
518
+ label?: string;
519
+ /** Reference kind stamped on emitted attachments. Default `"file"`. */
520
+ kind?: string;
521
+ /** `accept` filter for the file picker (e.g. `"image/*,.pdf"`). */
522
+ accept?: string;
523
+ /** Max file size in bytes. Files above this are rejected. Default 20MB. */
524
+ maxSize?: number;
525
+ /**
526
+ * Store the file and return a fetchable source. Return a `url` (presigned or
527
+ * public — the server fetches it with no auth) or inline `data` (base64).
528
+ * When omitted, the file is inlined as base64 (fine for small files/tests,
529
+ * bloats the event log for large ones).
530
+ */
531
+ onUpload?: (file: File) => AttachmentUploadResult | Promise<AttachmentUploadResult>;
532
+ }
533
+ /** Internal marker: identifies a {@link ReferenceProvider} produced by {@link uploadProvider}. */
534
+ declare const UPLOAD_MARKER: "__kabooUpload";
535
+ /** A {@link ReferenceProvider} carrying its resolved upload config for the composer. */
536
+ interface UploadReferenceProvider extends ReferenceProvider {
537
+ /** Resolved upload config the composer reads to drive the file picker. */
538
+ [UPLOAD_MARKER]: Required<Pick<UploadProviderConfig, "kind" | "maxSize">> & Pick<UploadProviderConfig, "accept" | "onUpload">;
539
+ }
540
+ /**
541
+ * Upload one file and return the pending attachment reference (id minted here).
542
+ * Uses `config.onUpload` when provided, else inlines the bytes as base64.
543
+ */
544
+ declare function uploadFileToReference(file: File, config: UploadProviderConfig): Promise<PendingReference>;
545
+ /**
546
+ * Built-in file-upload {@link ReferenceProvider}. Action-only: choosing it in
547
+ * the `@` menu opens the file picker; the composer uploads the file (via
548
+ * `onUpload` or base64) and adds an `attachment`-transport reference.
549
+ *
550
+ * @example
551
+ * ```tsx
552
+ * <KabooProvider references={[uploadProvider({ accept: "image/*,.pdf", onUpload })]} ...>
553
+ * ```
554
+ */
555
+ declare function uploadProvider(config?: UploadProviderConfig): UploadReferenceProvider;
556
+ /** Narrow a provider to an {@link UploadReferenceProvider}. */
557
+ declare function isUploadProvider(provider: ReferenceProvider): provider is UploadReferenceProvider;
558
+ /**
559
+ * Build a CopilotKit `AttachmentsConfig` from an upload config, wrapping
560
+ * `onUpload` so every uploaded file carries kaboo id/kind/name in its
561
+ * `InputContent` metadata. Pass to `<CopilotChat attachments={...}>` to use
562
+ * CopilotKit's native attachment UI instead of the `@` composer.
563
+ */
564
+ declare function buildAttachmentsConfig(config?: UploadProviderConfig): AttachmentsConfig;
565
+
246
566
  /** A `[groupId, group]` pair, as returned by the group-hierarchy helpers. */
247
567
  type GroupEntry = [string, StreamGroup];
248
568
  /**
@@ -554,4 +874,4 @@ declare function formatToolResult(raw: string): {
554
874
  */
555
875
  declare function normalizeResult(result: string | undefined): string | null;
556
876
 
557
- export { type ActiveInterrupt, ActivityPanel, ActivityState, AgentCard, type AgentCardProps, DrillDetailView, DrillProvider, DrillState, GlassTabs, type GroupEntry, InterruptBridgeProvider, InterruptBridgePublisher, InterruptReason, InterruptRenderer, InterruptRendererProps, KabooActivityProvider, type KabooActivityProviderProps, KabooProvider, type KabooProviderProps, MarkdownContent, MiniTable, StreamGroup, type StructuredRenderers, StructuredRenderersContext, Timeline, TimelineEntry, type TimelineProps, ToolCall, ToolRow, directChildren, formatToolInput, formatToolResult, normalizeResult, topLevelGroups, useActivity, useDrill, useInterruptBridge, useInterruptFor };
877
+ export { type ActiveInterrupt, ActivityPanel, ActivityState, AgentCard, type AgentCardProps, DrillDetailView, DrillProvider, DrillState, GlassTabs, type GroupEntry, InterruptBridgeProvider, InterruptBridgePublisher, InterruptReason, InterruptRenderer, InterruptRendererProps, KabooActivityProvider, type KabooActivityProviderProps, KabooProvider, type KabooProviderProps, KabooReferenceInput, type KabooReferenceInputProps, MarkdownContent, MiniTable, type PendingReference, REFERENCES_STATE_KEY, REFERENCE_METADATA_KEYS, type ReferenceItem, type ReferenceProvider, ReferenceStateSync, type ReferenceTransport, type ReferencesContextValue, ReferencesProvider, type ReferencesProviderProps, type SerializedObjectReference, type SerializedReferences, StreamGroup, type StructuredRenderers, StructuredRenderersContext, Timeline, TimelineEntry, type TimelineProps, ToolCall, ToolRow, UPLOAD_MARKER, type UploadProviderConfig, type UploadReferenceProvider, attachmentToInputContent, buildAttachmentsConfig, buildUserContent, directChildren, formatToolInput, formatToolResult, isUploadProvider, mintReferenceId, normalizeResult, objectToStateEntry, referenceMarker, serializeReferences, topLevelGroups, uploadFileToReference, uploadProvider, useActivity, useDrill, useInterruptBridge, useInterruptFor, useReferences, withReferenceState };