juneau 0.5.1 → 0.5.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -384,6 +384,9 @@ import { AiChatProvider } from 'juneau';
384
384
  | `context` | `Record<string, unknown>` | Initial context forwarded to every adapter call. Update per-page via `setContext()`. |
385
385
  | `onProposalConfirm` | `(id, payload) => void` | Called when user confirms a proposal card. |
386
386
  | `onProposalCancel` | `(id) => void` | Called when user cancels a proposal card. |
387
+ | `initialMessages` | `AiMessage[]` | Restored conversation to start with (see Chat history). |
388
+ | `historyLimit` | `number` | Max messages sent to the adapter per request. Rendering never trimmed. |
389
+ | `onMessagesChange` | `(messages) => void` | Called when the conversation settles. Use to persist. |
387
390
 
388
391
  **Updating context per page:**
389
392
 
@@ -407,6 +410,27 @@ function InvoicesPage() {
407
410
  }
408
411
  ```
409
412
 
413
+ **Replace vs merge:** passing an object to `setContext` **replaces** the whole context. To keep existing keys (e.g. a `sessionId` set elsewhere) while updating others, use the updater form:
414
+
415
+ ```tsx
416
+ setContext(prev => ({ ...prev, page: 'invoices' }));
417
+ ```
418
+
419
+ **Consuming chat state outside a guaranteed provider:**
420
+
421
+ `useAiChatContext()` throws when called outside `<AiChatProvider>` — fail fast is right for components that require it. For components that may render outside the provider (e.g. during sign-out transitions), use the exported `AiChatContext` with plain `useContext` and handle `null`:
422
+
423
+ ```tsx
424
+ import { useContext } from 'react';
425
+ import { AiChatContext } from 'juneau';
426
+
427
+ function OptionalChatButton() {
428
+ const chat = useContext(AiChatContext); // AiChatContextValue | null
429
+ if (!chat) return null;
430
+ return <button onClick={() => chat.sendMessageWithText('Help')}>Ask AI</button>;
431
+ }
432
+ ```
433
+
410
434
  ---
411
435
 
412
436
  ## Components
@@ -4,8 +4,15 @@ export type AiChatContextValue = UseAiChatReturn & {
4
4
  * Update the context forwarded to every adapter.sendMessage call.
5
5
  * Call this on each page/view to tell the AI where the user is,
6
6
  * what tools are available, etc.
7
+ *
8
+ * Passing an object REPLACES the whole context. To merge with what's
9
+ * already there (e.g. keep a sessionId while updating the page), use the
10
+ * updater form:
11
+ *
12
+ * @example
13
+ * setContext(prev => ({ ...prev, pageId: 'invoices' }));
7
14
  */
8
- setContext: (ctx: Record<string, unknown>) => void;
15
+ setContext: (ctx: Record<string, unknown> | ((prev: Record<string, unknown> | undefined) => Record<string, unknown>)) => void;
9
16
  };
10
17
  export declare const AiChatContext: import("react").Context<AiChatContextValue | null>;
11
18
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"AiChatContext.d.ts","sourceRoot":"","sources":["../../src/context/AiChatContext.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAE1D,MAAM,MAAM,kBAAkB,GAAG,eAAe,GAAG;IACjD;;;;OAIG;IACH,UAAU,EAAE,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,IAAI,CAAC;CACpD,CAAC;AAEF,eAAO,MAAM,aAAa,oDAAiD,CAAC;AAE5E;;;GAGG;AACH,wBAAgB,gBAAgB,IAAI,kBAAkB,CASrD"}
1
+ {"version":3,"file":"AiChatContext.d.ts","sourceRoot":"","sources":["../../src/context/AiChatContext.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAE1D,MAAM,MAAM,kBAAkB,GAAG,eAAe,GAAG;IACjD;;;;;;;;;;;OAWG;IACH,UAAU,EAAE,CACV,GAAG,EACC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GACvB,CAAC,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,KAAK,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,KACzE,IAAI,CAAC;CACX,CAAC;AAEF,eAAO,MAAM,aAAa,oDAAiD,CAAC;AAE5E;;;GAGG;AACH,wBAAgB,gBAAgB,IAAI,kBAAkB,CASrD"}
@@ -1 +1 @@
1
- {"version":3,"file":"AiChatProvider.d.ts","sourceRoot":"","sources":["../../src/context/AiChatProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAyB,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAE9D,OAAO,KAAK,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAGjE,KAAK,KAAK,GAAG;IACX,OAAO,EAAE,gBAAgB,CAAC;IAC1B,kFAAkF;IAClF,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAClC,iBAAiB,CAAC,EAAE,CAAC,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,KAAK,IAAI,CAAC;IACnE,gBAAgB,CAAC,EAAE,CAAC,UAAU,EAAE,MAAM,KAAK,IAAI,CAAC;IAChD,2FAA2F;IAC3F,eAAe,CAAC,EAAE,SAAS,EAAE,CAAC;IAC9B,gFAAgF;IAChF,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,sFAAsF;IACtF,gBAAgB,CAAC,EAAE,CAAC,QAAQ,EAAE,SAAS,EAAE,KAAK,IAAI,CAAC;IACnD,QAAQ,EAAE,SAAS,CAAC;CACrB,CAAC;AAEF,wBAAgB,cAAc,CAAC,EAC7B,OAAO,EACP,OAAO,EAAE,cAAc,EACvB,iBAAiB,EACjB,gBAAgB,EAChB,eAAe,EACf,YAAY,EACZ,gBAAgB,EAChB,QAAQ,GACT,EAAE,KAAK,+BAsBP"}
1
+ {"version":3,"file":"AiChatProvider.d.ts","sourceRoot":"","sources":["../../src/context/AiChatProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAyB,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAE9D,OAAO,KAAK,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAGjE,KAAK,KAAK,GAAG;IACX,OAAO,EAAE,gBAAgB,CAAC;IAC1B,kFA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