@stll/chat 0.4.2 → 0.4.4
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/link.d.ts +5 -1
- package/dist/link.js +27 -10
- package/package.json +5 -5
package/dist/link.d.ts
CHANGED
|
@@ -17,6 +17,10 @@ type ChatLinkProps = Omit<AnchorHTMLAttributes<HTMLAnchorElement>, "href" | "tar
|
|
|
17
17
|
/** A tray chip whose label is the whole point (a decision's case number and
|
|
18
18
|
* date) keeps it up to the row's width instead of the compact 20ch cap. */
|
|
19
19
|
fullLabel?: boolean | undefined;
|
|
20
|
+
/** What a link whose text is itself a URL shows: the bare host (a chip for
|
|
21
|
+
* a model's cited URL) or the text as written (a URL a person typed, whose
|
|
22
|
+
* path and query are what they meant). */
|
|
23
|
+
urlLabel?: "host" | "written" | undefined;
|
|
20
24
|
};
|
|
21
25
|
/**
|
|
22
26
|
* Gives the link rendered inside it fixed ids, so a surface that renders the
|
|
@@ -28,5 +32,5 @@ export declare const ChatLinkIdScope: ({ children, id }: {
|
|
|
28
32
|
children: ReactNode;
|
|
29
33
|
id: string;
|
|
30
34
|
}) => import("react").JSX.Element;
|
|
31
|
-
export declare const ChatLink: ({ appearance, children, fullLabel, href, iconSource, id, newTabLabel, title, ...anchorProps }: ChatLinkProps) => import("react").JSX.Element;
|
|
35
|
+
export declare const ChatLink: ({ appearance, children, fullLabel, href, iconSource, id, newTabLabel, title, urlLabel, ...anchorProps }: ChatLinkProps) => import("react").JSX.Element;
|
|
32
36
|
export {};
|
package/dist/link.js
CHANGED
|
@@ -4,6 +4,7 @@ import { createContext, isValidElement, use, useId, useState } from "react";
|
|
|
4
4
|
import { GitHubLogoIcon, XLogoIcon } from "@stll/ui/brand-icons";
|
|
5
5
|
import { GlobeIcon } from "@stll/ui/icons";
|
|
6
6
|
import { Tooltip, TooltipPopup, TooltipTrigger } from "@stll/ui/tooltip";
|
|
7
|
+
import { TruncatedText } from "@stll/ui/truncated-text";
|
|
7
8
|
// src/link.tsx
|
|
8
9
|
const CHAT_LINK_ATTRIBUTES = {
|
|
9
10
|
target: "_blank",
|
|
@@ -47,6 +48,21 @@ const BUNDLED_ICONS = /* @__PURE__ */ new Map([
|
|
|
47
48
|
["www.twitter.com", X_LINK_ICON]
|
|
48
49
|
]);
|
|
49
50
|
const hasBundledChatLinkIcon = (hostname) => BUNDLED_ICONS.has(hostname);
|
|
51
|
+
/**
|
|
52
|
+
* A link's visible label: its own text, unless that text is just a URL a
|
|
53
|
+
* model cited, which shows as the bare host.
|
|
54
|
+
*/
|
|
55
|
+
const linkLabel = (children, hostname, urlLabel) => {
|
|
56
|
+
const text = linkText(children).trim();
|
|
57
|
+
return text && (urlLabel === "written" || normalizeChatLink(text) === null) ? children : hostname.replace(/^www\./u, "");
|
|
58
|
+
};
|
|
59
|
+
/** A tray chip cuts its label short; an inline link runs with the prose. A
|
|
60
|
+
* tray chip whose label is the whole point keeps it up to the row's width. */
|
|
61
|
+
const ChatLinkLabel = ({ appearance, children, fullLabel }) => appearance === "tray" ? /* @__PURE__ */ jsx(TruncatedText, {
|
|
62
|
+
className: fullLabel ? void 0 : "max-w-[20ch]",
|
|
63
|
+
render: /* @__PURE__ */ jsx("bdi", {}),
|
|
64
|
+
children
|
|
65
|
+
}) : /* @__PURE__ */ jsx("bdi", { children });
|
|
50
66
|
const ChatLinkIdContext = createContext(void 0);
|
|
51
67
|
/**
|
|
52
68
|
* Gives the link rendered inside it fixed ids, so a surface that renders the
|
|
@@ -74,7 +90,7 @@ const LinkHint = ({ children, hint, hintId, id }) => hint ? /* @__PURE__ */ jsxs
|
|
|
74
90
|
id: hintId,
|
|
75
91
|
children: hint
|
|
76
92
|
})] }) : children;
|
|
77
|
-
const ChatLink = ({ appearance = "inline", children, fullLabel = false, href, iconSource, id, newTabLabel, title, ...anchorProps }) => {
|
|
93
|
+
const ChatLink = ({ appearance = "inline", children, fullLabel = false, href, iconSource, id, newTabLabel, title, urlLabel = "host", ...anchorProps }) => {
|
|
78
94
|
const hint = newTabLabel ?? title;
|
|
79
95
|
const generatedId = useId();
|
|
80
96
|
const baseId = use(ChatLinkIdContext) ?? generatedId;
|
|
@@ -82,7 +98,6 @@ const ChatLink = ({ appearance = "inline", children, fullLabel = false, href, ic
|
|
|
82
98
|
const triggerId = id ?? baseId;
|
|
83
99
|
const ownId = hint || id === void 0 ? {} : { id };
|
|
84
100
|
const className = appearance === "tray" ? "bg-muted/50 hover:bg-muted inline-flex max-w-full min-w-0 shrink-0 items-center gap-1 rounded-md border px-1.5 py-0.5 text-xs focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-ring" : CHAT_LINK_CLASS_NAME;
|
|
85
|
-
const labelClassName = appearance === "tray" ? fullLabel ? "min-w-0 truncate" : "max-w-[20ch] truncate" : void 0;
|
|
86
101
|
const target = normalizeChatLink(href);
|
|
87
102
|
if (!target) {
|
|
88
103
|
const parsed = URL.canParse(href) ? new URL(href) : null;
|
|
@@ -90,8 +105,9 @@ const ChatLink = ({ appearance = "inline", children, fullLabel = false, href, ic
|
|
|
90
105
|
const safeMail = parsed?.protocol === "mailto:";
|
|
91
106
|
if (!safeLocal && !safeMail || /[\p{Cc}\p{Cf}]/u.test(href)) return appearance === "tray" ? /* @__PURE__ */ jsx("span", {
|
|
92
107
|
className,
|
|
93
|
-
children: /* @__PURE__ */ jsx(
|
|
94
|
-
|
|
108
|
+
children: /* @__PURE__ */ jsx(ChatLinkLabel, {
|
|
109
|
+
appearance,
|
|
110
|
+
fullLabel,
|
|
95
111
|
children: children ?? href
|
|
96
112
|
})
|
|
97
113
|
}) : /* @__PURE__ */ jsx("span", { children: children ?? href });
|
|
@@ -107,15 +123,15 @@ const ChatLink = ({ appearance = "inline", children, fullLabel = false, href, ic
|
|
|
107
123
|
href,
|
|
108
124
|
target: CHAT_LINK_ATTRIBUTES.target,
|
|
109
125
|
rel: CHAT_LINK_ATTRIBUTES.rel,
|
|
110
|
-
children: /* @__PURE__ */ jsx(
|
|
111
|
-
|
|
126
|
+
children: /* @__PURE__ */ jsx(ChatLinkLabel, {
|
|
127
|
+
appearance,
|
|
128
|
+
fullLabel,
|
|
112
129
|
children: children ?? href
|
|
113
130
|
})
|
|
114
131
|
})
|
|
115
132
|
});
|
|
116
133
|
}
|
|
117
|
-
const
|
|
118
|
-
const label = text && normalizeChatLink(text) === null ? children : target.hostname.replace(/^www\./u, "");
|
|
134
|
+
const label = linkLabel(children, target.hostname, urlLabel);
|
|
119
135
|
let icon = /* @__PURE__ */ jsx(GlobeIcon, {
|
|
120
136
|
"aria-hidden": "true",
|
|
121
137
|
className: "size-[1em]"
|
|
@@ -139,8 +155,9 @@ const ChatLink = ({ appearance = "inline", children, fullLabel = false, href, ic
|
|
|
139
155
|
"aria-hidden": "true",
|
|
140
156
|
className: appearance === "tray" ? "flex shrink-0" : "me-1 inline-block align-[-0.125em]",
|
|
141
157
|
children: icon
|
|
142
|
-
}), /* @__PURE__ */ jsx(
|
|
143
|
-
|
|
158
|
+
}), /* @__PURE__ */ jsx(ChatLinkLabel, {
|
|
159
|
+
appearance,
|
|
160
|
+
fullLabel,
|
|
144
161
|
children: label
|
|
145
162
|
})]
|
|
146
163
|
})
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stll/chat",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.4",
|
|
4
4
|
"description": "Typed React chat composer, message stream, model selector, and transport runtime primitives.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ai",
|
|
@@ -83,16 +83,16 @@
|
|
|
83
83
|
"pack:dry-run": "bun pm pack --dry-run",
|
|
84
84
|
"test": "bun test src",
|
|
85
85
|
"typecheck": "bun check --no-pretty --all --project=tsconfig.json",
|
|
86
|
-
"lint": "cd ../.. && bun
|
|
87
|
-
"lint:fix": "cd ../.. && bun
|
|
86
|
+
"lint": "cd ../.. && bun scripts/lint.ts packages/chat",
|
|
87
|
+
"lint:fix": "cd ../.. && bun scripts/lint.ts --fix packages/chat",
|
|
88
88
|
"prepack": "bun run build",
|
|
89
89
|
"test:property": "bun test --preload @stll/property-testing/preload $(grep -rlE 'fc\\.assert|assertProperty' src --include='*.test.ts')"
|
|
90
90
|
},
|
|
91
91
|
"dependencies": {
|
|
92
92
|
"@ag-ui/core": "1.0.3",
|
|
93
|
-
"@stll/ai-catalog": "^0.
|
|
93
|
+
"@stll/ai-catalog": "^0.12.0",
|
|
94
94
|
"@stll/html": "0.1.1",
|
|
95
|
-
"@stll/ui": "^0.
|
|
95
|
+
"@stll/ui": "^0.69.0",
|
|
96
96
|
"@tanstack/ai-client": "0.38.0",
|
|
97
97
|
"@types/hast": "^3.0.5",
|
|
98
98
|
"better-result": "3.0.1",
|