@ai-matrx/chat 0.4.19 → 0.4.20

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/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # @ai-matrx/chat
2
2
 
3
+ ## 0.4.20 — The credential capture card moves into the package
4
+
5
+ - New `@ai-matrx/chat/agents/ui-first-tools/ui/CredentialCaptureCard`: the one card for an agent
6
+ that hit a login it has no saved credential for. Host ports `save(values)` and
7
+ `dismiss(reason)`; the card owns the leak boundary and the deadline. Replaces the browser
8
+ extension's and the website Cloud Browser's separate copies.
9
+
3
10
  ## 0.4.19 — Release verification repair
4
11
 
5
12
  - Restores the resume-stall coverage in the package's Jest module suite: the
@@ -0,0 +1,31 @@
1
+ export interface CredentialCaptureField {
2
+ fieldKey: string;
3
+ label: string;
4
+ /** Mask the box (password-style). */
5
+ secret: boolean;
6
+ }
7
+ /** The card's spec. Field NAMES only — a value has no place to ride in on it. */
8
+ export interface CredentialCaptureSpec {
9
+ /** Stable id of this request (tool call id or handoff id); scopes input ids. */
10
+ id: string;
11
+ host: string;
12
+ displayName: string;
13
+ branch: "known" | "unknown";
14
+ /** Epoch ms after which the agent has moved on and no write may happen. */
15
+ expiresAtMs: number;
16
+ fields: CredentialCaptureField[];
17
+ }
18
+ export type CredentialCaptureSaveResult = {
19
+ ok: true;
20
+ } | {
21
+ ok: false;
22
+ message?: string;
23
+ };
24
+ export type CredentialCaptureDismissReason = "cancelled" | "expired";
25
+ export interface CredentialCaptureCardProps {
26
+ spec: CredentialCaptureSpec;
27
+ save: (values: Record<string, string>) => Promise<CredentialCaptureSaveResult>;
28
+ dismiss: (reason: CredentialCaptureDismissReason) => void | Promise<void>;
29
+ }
30
+ export declare function CredentialCaptureCard({ spec, save, dismiss }: CredentialCaptureCardProps): import("react").JSX.Element;
31
+ export default CredentialCaptureCard;
@@ -0,0 +1,137 @@
1
+ "use client";
2
+ import { jsx, jsxs } from "react/jsx-runtime";
3
+ import { useCallback, useEffect, useRef, useState } from "react";
4
+ import { KeyRound, Loader2, ShieldCheck } from "lucide-react";
5
+ import { Input } from "@ai-matrx/design-system";
6
+ import { Button } from "@ai-matrx/design-system/controls";
7
+ import { AgentCardShell } from "./AgentCardShell.js";
8
+ function CredentialCaptureCard({ spec, save, dismiss }) {
9
+ const [values, setValues] = useState({});
10
+ const [busy, setBusy] = useState(false);
11
+ const [error, setError] = useState(null);
12
+ const [expired, setExpired] = useState(() => Date.now() >= spec.expiresAtMs);
13
+ const busyRef = useRef(false);
14
+ const dismissRef = useRef(dismiss);
15
+ dismissRef.current = dismiss;
16
+ useEffect(() => () => setValues({}), []);
17
+ useEffect(() => {
18
+ const ms = spec.expiresAtMs - Date.now();
19
+ if (ms <= 0) return;
20
+ const timer = setTimeout(() => {
21
+ setExpired(true);
22
+ if (busyRef.current) return;
23
+ setValues({});
24
+ void Promise.resolve(dismissRef.current("expired")).catch(() => void 0);
25
+ }, ms);
26
+ return () => clearTimeout(timer);
27
+ }, [spec.id, spec.expiresAtMs]);
28
+ const allFilled = spec.fields.every((f) => (values[f.fieldKey] ?? "").length > 0);
29
+ const onCancel = useCallback(async () => {
30
+ setValues({});
31
+ setBusy(true);
32
+ try {
33
+ await dismiss(expired ? "expired" : "cancelled");
34
+ } catch (cause) {
35
+ setError(cause instanceof Error ? cause.message : "Could not close this sign-in request.");
36
+ } finally {
37
+ setBusy(false);
38
+ }
39
+ }, [dismiss, expired]);
40
+ const onSave = useCallback(async () => {
41
+ if (busyRef.current) return;
42
+ if (expired || Date.now() >= spec.expiresAtMs) {
43
+ setExpired(true);
44
+ setValues({});
45
+ return;
46
+ }
47
+ busyRef.current = true;
48
+ setBusy(true);
49
+ setError(null);
50
+ const typed = {};
51
+ for (const f of spec.fields) typed[f.fieldKey] = values[f.fieldKey] ?? "";
52
+ let result;
53
+ try {
54
+ result = await save(typed);
55
+ } catch (cause) {
56
+ result = { ok: false, message: cause instanceof Error ? cause.message : void 0 };
57
+ }
58
+ setValues({});
59
+ busyRef.current = false;
60
+ setBusy(false);
61
+ if (result.ok) return;
62
+ if (Date.now() >= spec.expiresAtMs) {
63
+ setExpired(true);
64
+ void Promise.resolve(dismiss("expired")).catch(() => void 0);
65
+ return;
66
+ }
67
+ setError(result.message || "Could not save this sign-in. Try again or cancel.");
68
+ }, [dismiss, expired, save, spec, values]);
69
+ return /* @__PURE__ */ jsxs(
70
+ AgentCardShell,
71
+ {
72
+ tone: "warning",
73
+ icon: KeyRound,
74
+ eyebrow: "Sign-in needed",
75
+ title: `Save a login for ${spec.host}`,
76
+ titleInline: true,
77
+ "aria-label": `Save a login for ${spec.host}`,
78
+ badge: spec.branch === "known" ? /* @__PURE__ */ jsxs("span", { className: "inline-flex items-center gap-1 rounded-full bg-muted px-2 py-0.5 text-xs", children: [
79
+ /* @__PURE__ */ jsx(ShieldCheck, { className: "size-3" }),
80
+ " Known site"
81
+ ] }) : null,
82
+ footer: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-2", children: [
83
+ /* @__PURE__ */ jsx(Button, { variant: "quiet", disabled: busy, onClick: () => void onCancel(), children: expired ? "Dismiss" : "Cancel" }),
84
+ /* @__PURE__ */ jsxs(
85
+ Button,
86
+ {
87
+ variant: "primary",
88
+ disabled: busy || expired || !allFilled,
89
+ onClick: () => void onSave(),
90
+ children: [
91
+ busy ? /* @__PURE__ */ jsx(Loader2, { className: "mr-1 size-3 animate-spin" }) : null,
92
+ "Save and continue"
93
+ ]
94
+ }
95
+ )
96
+ ] }),
97
+ children: [
98
+ /* @__PURE__ */ jsxs("p", { className: "mb-3 text-xs text-muted-foreground", children: [
99
+ "Your agent needs to sign in to",
100
+ " ",
101
+ /* @__PURE__ */ jsx("span", { className: "font-medium text-foreground", children: spec.displayName }),
102
+ ". Enter it here; it goes to your vault and ",
103
+ /* @__PURE__ */ jsx("span", { className: "font-medium text-foreground", children: "the agent never sees it" }),
104
+ "."
105
+ ] }),
106
+ /* @__PURE__ */ jsx("div", { className: "grid gap-2", children: spec.fields.map((field) => {
107
+ const inputId = `capture-${spec.id}-${field.fieldKey}`;
108
+ return /* @__PURE__ */ jsxs("label", { htmlFor: inputId, className: "grid gap-1", children: [
109
+ /* @__PURE__ */ jsx("span", { className: "text-xs text-muted-foreground", children: field.label }),
110
+ /* @__PURE__ */ jsx(
111
+ Input,
112
+ {
113
+ id: inputId,
114
+ type: field.secret ? "password" : "text",
115
+ autoComplete: field.secret ? "new-password" : "off",
116
+ value: values[field.fieldKey] ?? "",
117
+ disabled: busy || expired,
118
+ className: "text-base",
119
+ onChange: (event) => {
120
+ const next = event.target.value;
121
+ setValues((prev) => ({ ...prev, [field.fieldKey]: next }));
122
+ }
123
+ }
124
+ )
125
+ ] }, field.fieldKey);
126
+ }) }),
127
+ expired ? /* @__PURE__ */ jsx("p", { className: "mt-2 text-xs text-muted-foreground", children: "This request expired and your agent has moved on. Ask it to try the sign-in again." }) : null,
128
+ error ? /* @__PURE__ */ jsx("p", { className: "mt-2 text-xs text-destructive", children: error }) : null
129
+ ]
130
+ }
131
+ );
132
+ }
133
+ var CredentialCaptureCard_default = CredentialCaptureCard;
134
+ export {
135
+ CredentialCaptureCard,
136
+ CredentialCaptureCard_default as default
137
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-matrx/chat",
3
- "version": "0.4.19",
3
+ "version": "0.4.20",
4
4
  "description": "THE one AI Matrx person-to-agent chat system: the full chat (running agents, conversations, tool calls, streaming, context, surfaces, voice) as per-module subpaths @ai-matrx/chat/<domain>/<module> over a host contract (/host, /host/react) whose only required value is a db; plus the kernel compatibility entries (., /external-store, /matrx, /react, /tools, styles.css, tokens.css) until P28.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -226,26 +226,26 @@
226
226
  "server-only": "^0.0.1",
227
227
  "uuid": "^14.0.2",
228
228
  "zod": "^4.6.5",
229
+ "@ai-matrx/alchemy": "latest",
229
230
  "@ai-matrx/associations": "latest",
230
231
  "@ai-matrx/browser-audio": "latest",
231
- "@ai-matrx/alchemy": "latest",
232
232
  "@ai-matrx/canvas": "latest",
233
233
  "@ai-matrx/content-ir": "latest",
234
234
  "@ai-matrx/agents": "latest",
235
235
  "@ai-matrx/content-ir-react": "latest",
236
- "@ai-matrx/design-system": "latest",
236
+ "@ai-matrx/data": "latest",
237
237
  "@ai-matrx/diff": "latest",
238
- "@ai-matrx/icons": "latest",
238
+ "@ai-matrx/design-system": "latest",
239
+ "@ai-matrx/kit": "latest",
239
240
  "@ai-matrx/media": "latest",
240
241
  "@ai-matrx/print": "latest",
241
242
  "@ai-matrx/realtime": "latest",
242
243
  "@ai-matrx/records": "latest",
243
244
  "@ai-matrx/records-ui": "latest",
244
- "@ai-matrx/rich-content": "latest",
245
- "@ai-matrx/rich-editor": "latest",
245
+ "@ai-matrx/icons": "latest",
246
246
  "@ai-matrx/tap-target": "latest",
247
- "@ai-matrx/data": "latest",
248
- "@ai-matrx/kit": "latest"
247
+ "@ai-matrx/rich-editor": "latest",
248
+ "@ai-matrx/rich-content": "latest"
249
249
  },
250
250
  "devDependencies": {
251
251
  "@arethetypeswrong/cli": "^0.18.5",