@dudousxd/nestjs-agent-react 0.15.0 → 0.17.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/README.md CHANGED
@@ -563,6 +563,52 @@ and patches a streamed title in place; `rename`/`remove` are optimistic and roll
563
563
  through `POST <base>/messages/:id/feedback`, and maps a message streamed in this session to the row
564
564
  its run persisted (the live message carries `metadata.runId`).
565
565
 
566
+ ### Picking a model and an agent
567
+
568
+ ```tsx
569
+ import { useAgents, useModels } from '@dudousxd/nestjs-agent-react';
570
+
571
+ const [model, setModel] = useState<string | undefined>();
572
+ const chat = useAgentChat({ backend, model }); // sent as the body's `model` on every turn
573
+ const { providers, find, defaultModel } = useModels({ backend: chat.backend, agent: 'support' });
574
+ const { agents } = useAgents({ backend: chat.backend });
575
+
576
+ <select value={model ?? defaultModel ?? ''} onChange={(e) => setModel(e.target.value)}>
577
+ {providers.map((p) => (
578
+ <optgroup key={p.id} label={p.label}>
579
+ {p.models.map((m) => (
580
+ <option key={m.id} value={m.id} disabled={!m.available}>
581
+ {m.label} {m.badges?.join(' · ')} {m.available ? '' : `(${m.unavailableReason ?? 'unavailable'})`}
582
+ </option>
583
+ ))}
584
+ </optgroup>
585
+ ))}
586
+ </select>
587
+ ```
588
+
589
+ `useModels` reads `GET <base>/models?agent=` (models grouped by provider, with badges and
590
+ availability; `models` is the same list flattened, `find(id)` looks one up). A single send can
591
+ override with `sendMessage(msg, { body: { model } })`; `chat.setThreadModel(id)` pins a model on
592
+ the thread (`null` unpins), so every later turn without its own runs on it. The server refuses a
593
+ model its catalog does not offer as available.
594
+
595
+ ### Quota
596
+
597
+ ```tsx
598
+ import { QuotaBlockedError, useQuota } from '@dudousxd/nestjs-agent-react';
599
+
600
+ const quota = useQuota({ backend }); // GET <base>/quota
601
+ const chat = useAgentChat({ backend, blocked: quota.blocked });
602
+
603
+ <meter value={quota.month?.usedUsd} max={quota.month?.limitUsd} />
604
+ {quota.blocked ? <p>{quota.blocked.reason}</p> : null}
605
+ ```
606
+
607
+ `useQuota` returns every window (`day`, `month`, …) with its usage and ceilings, and `blocked` when
608
+ one is exhausted; it re-reads after every run a chat on the same backend settles (`pollMs` to poll
609
+ as well). With `blocked` passed in, `sendMessage`/`regenerate` reject with `QuotaBlockedError`
610
+ instead of starting a turn the server would refuse with `429`.
611
+
566
612
  ### The transport, standalone
567
613
 
568
614
  `AgentChatTransport` is a plain AI SDK v7 `ChatTransport` — wire it straight into `useChat` for the SSE