@ghuri/ai-widget 0.3.0 → 0.3.2

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/README.md CHANGED
@@ -36,7 +36,8 @@ chat.addEventListener('ghuri:tool-result', (e) => {/* e.detail: toolName, input,
36
36
  `--ghuri-accent`, `--ghuri-accent-text`, `--ghuri-accent-soft`, `--ghuri-accent-soft-text`, `--ghuri-accent-border`,
37
37
  `--ghuri-surface`, `--ghuri-background`, `--ghuri-muted-surface`, `--ghuri-text`, `--ghuri-muted`, `--ghuri-border`,
38
38
  `--ghuri-success`, `--ghuri-warning`, `--ghuri-warning-soft`, `--ghuri-danger`, `--ghuri-danger-soft`,
39
- `--ghuri-allowed`, `--ghuri-allowed-soft` (the "Allowed" tag and bar),
39
+ `--ghuri-allowed`, `--ghuri-allowed-soft` (the "Allowed" tag and bar; optional, derived from `--ghuri-success` and
40
+ `--ghuri-surface` when not set),
40
41
  `--ghuri-font`, `--ghuri-font-size`, `--ghuri-radius`, `--ghuri-radius-sm`, `--ghuri-bubble-radius`,
41
42
  `--ghuri-shadow`, `--ghuri-page-width`, and `--ghuri-kite-maroon` / `-red` / `-green` (lift them in dark mode).
42
43
 
@@ -55,6 +56,13 @@ and only `http(s)` and `mailto` links become links (new tab, no referrer). Enter
55
56
  and Enter during IME composition (Bangla keyboards) never sends. While a reply is streaming, closing the tab asks
56
57
  first.
57
58
 
59
+ ## Pictures from tools
60
+
61
+ A product tool can return pictures (MCP `image` content), for example a screenshot of a draft design. When the
62
+ profile has `toolImages` on, the model sees them, and the widget shows them as thumbnails on the tool step (tap to see
63
+ one large; part `tool-pictures`, `lightbox`). `ghuri:tool-result` gets them as `images: [{ mediaType, data }]` (base64)
64
+ next to `output`. They are drawn as `data:` URLs: a strict CSP needs `img-src data:`.
65
+
58
66
  ## Photos
59
67
 
60
68
  Give `uploadFile` and the widget offers photos (button, drag and drop, paste) in conversations that take them:
@@ -71,6 +79,8 @@ chat.configure({
71
79
  thumbnailUrl: new URL(f.url, location.origin).href }
72
80
  },
73
81
  attachments: { maxCount: 10, maxBytes: 5 * 1024 * 1024 }, // defaults; also accept, maxEdge (2048)
82
+ // Optional: a photo uploaded but not sent (chip removed, draft left behind). Delete it if your upload created it.
83
+ discardFile: async ({ ref }) => { /* delete ref from your library if this upload created it */ },
74
84
  })
75
85
  chat.addEventListener('ghuri:attachment-error', (e) => { /* e.detail: { name, reason: type|size|count|upload } */ })
76
86
  ```
@@ -37,6 +37,8 @@ export declare class ChatClient {
37
37
  /** The app's photo policy for new conversations, once Ghuri AI told us (`loadCapabilities`). */
38
38
  private policy;
39
39
  private loadingPolicy;
40
+ /** Set once the widget asked (it was shown); a new conversation then asks again, an ended client does not. */
41
+ private capabilitiesWanted;
40
42
  constructor(opts: ChatClientOptions);
41
43
  getState(): ChatState;
42
44
  /** Called on every change; returns the unsubscribe function. */
@@ -89,6 +91,8 @@ export declare class ChatClient {
89
91
  retryUpload(id: string): void;
90
92
  private startUpload;
91
93
  /** Stop every upload and free every preview (the conversation is replaced). */
94
+ /** Tell the product an uploaded photo will not be sent (it may delete it). Never throws. */
95
+ private discard;
92
96
  private dropPhotos;
93
97
  /** Confirm or cancel the waiting changes: one decision for each, sent together. */
94
98
  decide(decisions: Decision[]): Promise<void>;
@@ -108,6 +112,8 @@ export declare class ChatClient {
108
112
  dismissProblem(): void;
109
113
  /** Start a new conversation (the next message creates it). */
110
114
  newConversation(): void;
115
+ /** Forget the open conversation (new conversation, end). */
116
+ private reset;
111
117
  /** The user's conversations in this product and tenant, newest first. */
112
118
  listConversations(opts?: {
113
119
  limit?: number;
@@ -1,6 +1,6 @@
1
1
  export { ATTACHMENT_DEFAULTS, ChatClient, problemFor } from './client';
2
2
  export { messagesFromHistory } from './history';
3
- export { parsedOutput } from './output';
3
+ export { parsedOutput, splitSavedOutput, splitToolOutput, type ToolImage } from './output';
4
4
  export { prepareImage, scaledSize } from './prepare';
5
5
  export { parseSse, readChunks, SseParser, type StreamChunk } from './sse';
6
6
  export type * from './types';
@@ -1,2 +1,28 @@
1
1
  /** Text that is a JSON object or array, parsed; anything else unchanged. */
2
2
  export declare function parsedOutput(output: unknown): unknown;
3
+ /** A picture a tool returned (a screenshot of a draft design, for example), base64. */
4
+ export interface ToolImage {
5
+ mediaType: string;
6
+ data: string;
7
+ width?: number;
8
+ height?: number;
9
+ }
10
+ /**
11
+ * A live tool result (`tool-output-available`): Ghuri AI streams checked pictures as
12
+ * `{ ghuriToolImages: 1, output, images }` and sends anything a product shaped like that as text, so only this shape
13
+ * draws pictures here. Saved conversations go through `splitSavedOutput`.
14
+ */
15
+ export declare function splitToolOutput(raw: unknown): {
16
+ output: unknown;
17
+ images: ToolImage[];
18
+ };
19
+ /**
20
+ * A saved tool result with pictures: what the model was given (`{ type: 'content', value: [text…, file…] }`). Ghuri AI
21
+ * saves that shape only for checked pictures; a product's own JSON is saved as `{ type: 'json' }`.
22
+ */
23
+ export declare function splitSavedOutput(saved: {
24
+ value?: unknown;
25
+ }): {
26
+ output: unknown;
27
+ images: ToolImage[];
28
+ };
@@ -1,3 +1,4 @@
1
+ import type { ToolImage } from './output';
1
2
  /** What the product's backend returns when it starts a session (Ghuri AI's `POST /v1/sessions` answer). */
2
3
  export interface SessionInfo {
3
4
  sessionId: string;
@@ -19,6 +20,12 @@ export interface ChatClientOptions {
19
20
  * it, the widget offers photos in conversations that take them; without it, never. Ghuri AI never gets the bytes.
20
21
  */
21
22
  uploadFile?: UploadFile;
23
+ /**
24
+ * Called for a photo that was uploaded but will not be sent: removed from the message, left in a draft the user
25
+ * moved away from, or finished uploading after it was removed. The product may delete it (only what this upload
26
+ * created). Never called for a photo that was sent. Errors are ignored.
27
+ */
28
+ discardFile?: (attachment: Attachment) => void | Promise<void>;
22
29
  /** Limits checked before uploading (the product checks again). */
23
30
  attachments?: AttachmentOptions;
24
31
  /**
@@ -125,6 +132,8 @@ export interface ToolPart {
125
132
  state: 'input' | 'running' | 'awaiting-approval' | 'done' | 'error' | 'denied';
126
133
  approvalId?: string;
127
134
  output?: unknown;
135
+ /** Pictures the tool returned (e.g. screenshots of a draft design), base64. */
136
+ images?: ToolImage[];
128
137
  errorText?: string;
129
138
  /** It ran without a confirm card, on an allowance the user gave for this conversation ("Allowed"). */
130
139
  allowed?: boolean;
@@ -261,6 +270,8 @@ export interface ChatEvents {
261
270
  title?: string;
262
271
  input: unknown;
263
272
  output?: unknown;
273
+ /** Pictures the tool returned, if any. */
274
+ images?: ToolImage[];
264
275
  error?: string;
265
276
  };
266
277
  /** The reply paused on changes the user must decide. */