@tensorpass/aiconnect-react 0.0.0-stage → 0.1.1
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/LICENSE +202 -0
- package/NOTICE +4 -0
- package/README.md +15 -2
- package/dist/AboutView.d.ts +1 -0
- package/dist/AboutView.js +8 -0
- package/dist/AboutView.js.map +1 -0
- package/dist/AiConnectProvider.d.ts +26 -0
- package/dist/AiConnectProvider.js +44 -0
- package/dist/AiConnectProvider.js.map +1 -0
- package/dist/BrandMark.d.ts +3 -0
- package/dist/BrandMark.js +8 -0
- package/dist/BrandMark.js.map +1 -0
- package/dist/ConnectButton.d.ts +4 -0
- package/dist/ConnectButton.js +15 -0
- package/dist/ConnectButton.js.map +1 -0
- package/dist/ConnectModal.d.ts +1 -0
- package/dist/ConnectModal.js +68 -0
- package/dist/ConnectModal.js.map +1 -0
- package/dist/ConnectRing.d.ts +3 -0
- package/dist/ConnectRing.js +8 -0
- package/dist/ConnectRing.js.map +1 -0
- package/dist/WebAccountStep.d.ts +13 -0
- package/dist/WebAccountStep.js +34 -0
- package/dist/WebAccountStep.js.map +1 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.js +12 -0
- package/dist/index.js.map +1 -0
- package/dist/launcher.d.ts +11 -0
- package/dist/launcher.js +46 -0
- package/dist/launcher.js.map +1 -0
- package/dist/launchers.css +150 -0
- package/dist/messages.d.ts +15 -0
- package/dist/messages.js +46 -0
- package/dist/messages.js.map +1 -0
- package/dist/moduleMessages.d.ts +29 -0
- package/dist/moduleMessages.js +147 -0
- package/dist/moduleMessages.js.map +1 -0
- package/dist/modules/AiChatInline.d.ts +3 -0
- package/dist/modules/AiChatInline.js +18 -0
- package/dist/modules/AiChatInline.js.map +1 -0
- package/dist/modules/AiChatPage.d.ts +4 -0
- package/dist/modules/AiChatPage.js +23 -0
- package/dist/modules/AiChatPage.js.map +1 -0
- package/dist/modules/AiChatPanel.d.ts +4 -0
- package/dist/modules/AiChatPanel.js +22 -0
- package/dist/modules/AiChatPanel.js.map +1 -0
- package/dist/modules/AiChatPopup.d.ts +4 -0
- package/dist/modules/AiChatPopup.js +21 -0
- package/dist/modules/AiChatPopup.js.map +1 -0
- package/dist/modules/AiSearch.d.ts +3 -0
- package/dist/modules/AiSearch.js +76 -0
- package/dist/modules/AiSearch.js.map +1 -0
- package/dist/modules/Launcher.d.ts +9 -0
- package/dist/modules/Launcher.js +8 -0
- package/dist/modules/Launcher.js.map +1 -0
- package/dist/modules/parts/AccountBadge.d.ts +3 -0
- package/dist/modules/parts/AccountBadge.js +15 -0
- package/dist/modules/parts/AccountBadge.js.map +1 -0
- package/dist/modules/parts/AnswerText.d.ts +8 -0
- package/dist/modules/parts/AnswerText.js +43 -0
- package/dist/modules/parts/AnswerText.js.map +1 -0
- package/dist/modules/parts/ChatFrame.d.ts +12 -0
- package/dist/modules/parts/ChatFrame.js +16 -0
- package/dist/modules/parts/ChatFrame.js.map +1 -0
- package/dist/modules/parts/Composer.d.ts +13 -0
- package/dist/modules/parts/Composer.js +64 -0
- package/dist/modules/parts/Composer.js.map +1 -0
- package/dist/modules/parts/ConnectNote.d.ts +4 -0
- package/dist/modules/parts/ConnectNote.js +51 -0
- package/dist/modules/parts/ConnectNote.js.map +1 -0
- package/dist/modules/parts/ConnectStep.d.ts +4 -0
- package/dist/modules/parts/ConnectStep.js +17 -0
- package/dist/modules/parts/ConnectStep.js.map +1 -0
- package/dist/modules/parts/Conversation.d.ts +22 -0
- package/dist/modules/parts/Conversation.js +69 -0
- package/dist/modules/parts/Conversation.js.map +1 -0
- package/dist/modules/parts/PlanOffer.d.ts +3 -0
- package/dist/modules/parts/PlanOffer.js +79 -0
- package/dist/modules/parts/PlanOffer.js.map +1 -0
- package/dist/modules/parts/ToolActivity.d.ts +5 -0
- package/dist/modules/parts/ToolActivity.js +33 -0
- package/dist/modules/parts/ToolActivity.js.map +1 -0
- package/dist/modules/parts/accountModel.d.ts +2 -0
- package/dist/modules/parts/accountModel.js +13 -0
- package/dist/modules/parts/accountModel.js.map +1 -0
- package/dist/modules/parts/answerMarkdown.d.ts +32 -0
- package/dist/modules/parts/answerMarkdown.js +105 -0
- package/dist/modules/parts/answerMarkdown.js.map +1 -0
- package/dist/modules/parts/icons.d.ts +10 -0
- package/dist/modules/parts/icons.js +15 -0
- package/dist/modules/parts/icons.js.map +1 -0
- package/dist/modules/parts/moduleAnalytics.d.ts +5 -0
- package/dist/modules/parts/moduleAnalytics.js +9 -0
- package/dist/modules/parts/moduleAnalytics.js.map +1 -0
- package/dist/modules/parts/moduleClass.d.ts +1 -0
- package/dist/modules/parts/moduleClass.js +6 -0
- package/dist/modules/parts/moduleClass.js.map +1 -0
- package/dist/modules/parts/planPrice.d.ts +2 -0
- package/dist/modules/parts/planPrice.js +8 -0
- package/dist/modules/parts/planPrice.js.map +1 -0
- package/dist/modules/parts/useModuleChat.d.ts +24 -0
- package/dist/modules/parts/useModuleChat.js +117 -0
- package/dist/modules/parts/useModuleChat.js.map +1 -0
- package/dist/modules/parts/useModuleHandle.d.ts +3 -0
- package/dist/modules/parts/useModuleHandle.js +12 -0
- package/dist/modules/parts/useModuleHandle.js.map +1 -0
- package/dist/modules/types.d.ts +28 -0
- package/dist/modules/types.js +5 -0
- package/dist/modules/types.js.map +1 -0
- package/dist/modules/useOverlay.d.ts +20 -0
- package/dist/modules/useOverlay.js +102 -0
- package/dist/modules/useOverlay.js.map +1 -0
- package/dist/pickerMessages.d.ts +35 -0
- package/dist/pickerMessages.js +222 -0
- package/dist/pickerMessages.js.map +1 -0
- package/dist/styles.css +1721 -0
- package/dist/useAiChat.d.ts +33 -0
- package/dist/useAiChat.js +143 -0
- package/dist/useAiChat.js.map +1 -0
- package/dist/webAccountMessages.d.ts +24 -0
- package/dist/webAccountMessages.js +130 -0
- package/dist/webAccountMessages.js.map +1 -0
- package/package.json +53 -4
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { jsxs as _jsxs, jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
// The conversation of a chat module. Empty, it shows its heading, the connection step and the
|
|
3
|
+
// suggested questions, under the wallet's ring in the full page mode. Then each turn shows the
|
|
4
|
+
// visitor's question, the site's tools as they run, the answer as it streams and the site's own
|
|
5
|
+
// result cards, and the last answer's error comes with a way to ask again, or, for a TensorPass account
|
|
6
|
+
// without a plan, the offer to subscribe. The view follows the answer down while the visitor stays at the
|
|
7
|
+
// bottom.
|
|
8
|
+
import { useEffect, useRef } from 'react';
|
|
9
|
+
import { useAiConnect } from "../../AiConnectProvider.js";
|
|
10
|
+
import { ConnectRing } from "../../ConnectRing.js";
|
|
11
|
+
import { AnswerText } from "./AnswerText.js";
|
|
12
|
+
import { ConnectStep } from "./ConnectStep.js";
|
|
13
|
+
import { PlanOffer } from "./PlanOffer.js";
|
|
14
|
+
import { useActionAttribute } from "./moduleAnalytics.js";
|
|
15
|
+
import { ArrowIcon, WaveIcon } from "./icons.js";
|
|
16
|
+
import { ToolActivityList } from "./ToolActivity.js";
|
|
17
|
+
// The plan gateway's refusal of a TensorPass account without a subscription.
|
|
18
|
+
const PLAN_INACTIVE = 'plan_inactive';
|
|
19
|
+
// How close to the bottom, in pixels, the visitor counts as following the answer.
|
|
20
|
+
const FOLLOW_DISTANCE = 56;
|
|
21
|
+
function Question({ text }) {
|
|
22
|
+
const { moduleMessages } = useAiConnect();
|
|
23
|
+
return (_jsxs("p", { className: "aic-question", children: [_jsxs("span", { className: "aic-visually-hidden", children: [moduleMessages.question, ": "] }), text] }));
|
|
24
|
+
}
|
|
25
|
+
// What a turn shows under its question: the tools as they run, a thinking line until the first
|
|
26
|
+
// words arrive, the answer, whether the visitor stopped it, and the site's own result cards.
|
|
27
|
+
export function TurnBody({ turn, live, stopped, view, linkAllowed }) {
|
|
28
|
+
const { moduleMessages } = useAiConnect();
|
|
29
|
+
const toolRunning = turn.tools.some((activity) => activity.result === null);
|
|
30
|
+
const results = view.renderToolResults?.(turn);
|
|
31
|
+
return (_jsxs(_Fragment, { children: [_jsx(ToolActivityList, { tools: turn.tools, labels: view.toolLabels }), live && !turn.answer && !toolRunning ? (_jsxs("p", { className: "aic-thinking", children: [_jsx(WaveIcon, { size: 16, className: "aic-live-arcs" }), moduleMessages.thinking] })) : null, _jsx(AnswerText, { text: turn.answer, streaming: live && Boolean(turn.answer), linkAllowed: linkAllowed, blocked: Boolean(turn.blocked) }), stopped ? _jsxs("p", { className: "aic-stopped", children: [_jsx("i", { "aria-hidden": "true" }), moduleMessages.stopped] }) : null, results ? _jsx("div", { className: "aic-results", children: results }) : null] }));
|
|
32
|
+
}
|
|
33
|
+
export function Suggestions({ items, onPick }) {
|
|
34
|
+
const { moduleMessages } = useAiConnect();
|
|
35
|
+
const tracking = useActionAttribute('suggestion');
|
|
36
|
+
if (!items?.length) {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
return (_jsx("ul", { className: "aic-suggestions", "aria-label": moduleMessages.suggestionsLabel, children: items.map((question) => (_jsx("li", { children: _jsxs("button", { type: "button", className: "aic-suggestion", onClick: () => onPick(question), ...tracking, children: [_jsx("span", { children: question }), _jsx(ArrowIcon, {})] }) }, question))) }));
|
|
40
|
+
}
|
|
41
|
+
// Keeps the log scrolled to its end while the visitor reads at the bottom, and lets them scroll up.
|
|
42
|
+
// An empty conversation stays at its top, where its heading is.
|
|
43
|
+
function useFollowAnswer(logRef, chat) {
|
|
44
|
+
const following = useRef(true);
|
|
45
|
+
const asked = chat.turns.length + (chat.pendingQuestion ? 1 : 0);
|
|
46
|
+
useEffect(() => {
|
|
47
|
+
following.current = true;
|
|
48
|
+
}, [asked]);
|
|
49
|
+
useEffect(() => {
|
|
50
|
+
const log = logRef.current;
|
|
51
|
+
if (log && asked > 0 && following.current) {
|
|
52
|
+
log.scrollTop = log.scrollHeight;
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
return () => {
|
|
56
|
+
const log = logRef.current;
|
|
57
|
+
if (log) {
|
|
58
|
+
following.current = log.scrollHeight - log.scrollTop - log.clientHeight < FOLLOW_DISTANCE;
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
export function Conversation({ chat, intro, suggestions, ...view }) {
|
|
63
|
+
const { moduleMessages } = useAiConnect();
|
|
64
|
+
const logRef = useRef(null);
|
|
65
|
+
const onScroll = useFollowAnswer(logRef, chat);
|
|
66
|
+
const empty = chat.turns.length === 0 && !chat.pendingQuestion;
|
|
67
|
+
return (_jsxs("div", { ref: logRef, className: "aic-log", role: "log", "aria-busy": chat.busy, onScroll: onScroll, children: [empty ? (_jsxs("div", { className: "aic-empty", children: [_jsx("div", { className: "aic-empty-ring", children: _jsx(ConnectRing, { live: false }) }), _jsx("h3", { className: "aic-intro", children: intro }), _jsx(ConnectStep, { pending: false }), _jsx(Suggestions, { items: suggestions, onPick: chat.ask })] })) : null, _jsxs("ol", { className: "aic-turns", children: [chat.turns.map((turn, index) => (_jsxs("li", { className: "aic-turn", children: [_jsx(Question, { text: turn.question }), _jsx(TurnBody, { turn: turn, view: view, stopped: chat.stopped.includes(index), linkAllowed: chat.linkAllowed, live: chat.busy && index === chat.turns.length - 1 })] }, index))), chat.pendingQuestion ? (_jsxs("li", { className: "aic-turn", children: [_jsx(Question, { text: chat.pendingQuestion }), _jsx(ConnectStep, { pending: true })] })) : null] }), chat.refusal === PLAN_INACTIVE ? _jsx(PlanOffer, { onActive: chat.retry }) : null, chat.error && chat.refusal !== PLAN_INACTIVE ? (_jsxs("div", { className: "aic-error", role: "alert", children: [_jsx("p", { children: chat.error }), _jsx("button", { type: "button", className: "aic-text-button", onClick: chat.retry, children: moduleMessages.retry })] })) : null] }));
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=Conversation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Conversation.js","sourceRoot":"","sources":["../../../src/modules/parts/Conversation.tsx"],"names":[],"mappings":";AAAA,8FAA8F;AAC9F,+FAA+F;AAC/F,gGAAg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I,CAAC,IAAI,IAAI,KAAK,KAAK,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,GAAI,KAHjD,KAAK,CAIT,CACN,CAAC,EACD,IAAI,CAAC,eAAe,CAAC,CAAC,CAAC,CACtB,cAAI,SAAS,EAAC,UAAU,aAAC,KAAC,QAAQ,IAAC,IAAI,EAAE,IAAI,CAAC,eAAe,GAAI,EAAA,KAAC,WAAW,IAAC,OAAO,SAAG,IAAK,CAC9F,CAAC,CAAC,CAAC,IAAI,IACL,EACJ,IAAI,CAAC,OAAO,KAAK,aAAa,CAAC,CAAC,CAAC,KAAC,SAAS,IAAC,QAAQ,EAAE,IAAI,CAAC,KAAK,GAAI,CAAC,CAAC,CAAC,IAAI,EAC3E,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,OAAO,KAAK,aAAa,CAAC,CAAC,CAAC,CAC9C,eAAK,SAAS,EAAC,WAAW,EAAC,IAAI,EAAC,OAAO,aACrC,sBAAI,IAAI,CAAC,KAAK,GAAK,EACnB,iBAAQ,IAAI,EAAC,QAAQ,EAAC,SAAS,EAAC,iBAAiB,EAAC,OAAO,EAAE,IAAI,CAAC,KAAK,YAAG,cAAc,CAAC,KAAK,GAAU,IAClG,CACP,CAAC,CAAC,CAAC,IAAI,IACJ,CACP,CAAC;AACJ,CAAC","sourcesContent":["// The conversation of a chat module. Empty, it shows its heading, the connection step and the\n// suggested questions, under the wallet's ring in the full page mode. Then each turn shows the\n// visitor's question, the site's tools as they run, the answer as it streams and the site's own\n// result cards, and the last answer's error comes with a way to ask again, or, for a TensorPass account\n// without a plan, the offer to subscribe. The view follows the answer down while the visitor stays at the\n// bottom.\n\nimport { useEffect, useRef } from 'react';\nimport type { RefObject } from 'react';\nimport { useAiConnect } from '../../AiConnectProvider.tsx';\nimport { ConnectRing } from '../../ConnectRing.tsx';\nimport type { ChatTurn } from '../../useAiChat.ts';\nimport type { AiModuleProps } from '../types.ts';\nimport { AnswerText } from './AnswerText.tsx';\nimport { ConnectStep } from './ConnectStep.tsx';\nimport { PlanOffer } from './PlanOffer.tsx';\nimport { useActionAttribute } from './moduleAnalytics.ts';\nimport { ArrowIcon, WaveIcon } from './icons.tsx';\nimport { ToolActivityList } from './ToolActivity.tsx';\nimport type { ModuleChat } from './useModuleChat.ts';\n\nexport type TurnView = Pick<AiModuleProps, 'toolLabels' | 'renderToolResults'>;\n\nexport interface TurnBodyProps {\n turn: ChatTurn;\n live: boolean;\n stopped: boolean;\n view: TurnView;\n linkAllowed: (href: string) => boolean;\n}\n\n// The plan gateway's refusal of a TensorPass account without a subscription.\nconst PLAN_INACTIVE = 'plan_inactive';\n\n// How close to the bottom, in pixels, the visitor counts as following the answer.\nconst FOLLOW_DISTANCE = 56;\n\nfunction Question({ text }: { text: string }) {\n const { moduleMessages } = useAiConnect();\n return (\n <p className=\"aic-question\">\n <span className=\"aic-visually-hidden\">{moduleMessages.question}: </span>{text}\n </p>\n );\n}\n\n// What a turn shows under its question: the tools as they run, a thinking line until the first\n// words arrive, the answer, whether the visitor stopped it, and the site's own result cards.\nexport function TurnBody({ turn, live, stopped, view, linkAllowed }: TurnBodyProps) {\n const { moduleMessages } = useAiConnect();\n const toolRunning = turn.tools.some((activity) => activity.result === null);\n const results = view.renderToolResults?.(turn);\n return (\n <>\n <ToolActivityList tools={turn.tools} labels={view.toolLabels} />\n {live && !turn.answer && !toolRunning ? (\n <p className=\"aic-thinking\"><WaveIcon size={16} className=\"aic-live-arcs\" />{moduleMessages.thinking}</p>\n ) : null}\n <AnswerText text={turn.answer} streaming={live && Boolean(turn.answer)} linkAllowed={linkAllowed}\n blocked={Boolean(turn.blocked)} />\n {stopped ? <p className=\"aic-stopped\"><i aria-hidden=\"true\" />{moduleMessages.stopped}</p> : null}\n {results ? <div className=\"aic-results\">{results}</div> : null}\n </>\n );\n}\n\nexport function Suggestions({ items, onPick }: { items?: string[]; onPick: (question: string) => void }) {\n const { moduleMessages } = useAiConnect();\n const tracking = useActionAttribute('suggestion');\n if (!items?.length) {\n return null;\n }\n return (\n <ul className=\"aic-suggestions\" aria-label={moduleMessages.suggestionsLabel}>\n {items.map((question) => (\n <li key={question}>\n <button type=\"button\" className=\"aic-suggestion\" onClick={() => onPick(question)} {...tracking}>\n <span>{question}</span><ArrowIcon />\n </button>\n </li>\n ))}\n </ul>\n );\n}\n\n// Keeps the log scrolled to its end while the visitor reads at the bottom, and lets them scroll up.\n// An empty conversation stays at its top, where its heading is.\nfunction useFollowAnswer(logRef: RefObject<HTMLDivElement | null>, chat: ModuleChat) {\n const following = useRef(true);\n const asked = chat.turns.length + (chat.pendingQuestion ? 1 : 0);\n useEffect(() => {\n following.current = true;\n }, [asked]);\n useEffect(() => {\n const log = logRef.current;\n if (log && asked > 0 && following.current) {\n log.scrollTop = log.scrollHeight;\n }\n });\n return () => {\n const log = logRef.current;\n if (log) {\n following.current = log.scrollHeight - log.scrollTop - log.clientHeight < FOLLOW_DISTANCE;\n }\n };\n}\n\nexport interface ConversationProps extends TurnView {\n chat: ModuleChat;\n intro: string;\n suggestions?: string[];\n}\n\nexport function Conversation({ chat, intro, suggestions, ...view }: ConversationProps) {\n const { moduleMessages } = useAiConnect();\n const logRef = useRef<HTMLDivElement>(null);\n const onScroll = useFollowAnswer(logRef, chat);\n const empty = chat.turns.length === 0 && !chat.pendingQuestion;\n return (\n <div ref={logRef} className=\"aic-log\" role=\"log\" aria-busy={chat.busy} onScroll={onScroll}>\n {empty ? (\n <div className=\"aic-empty\">\n <div className=\"aic-empty-ring\"><ConnectRing live={false} /></div>\n <h3 className=\"aic-intro\">{intro}</h3>\n <ConnectStep pending={false} />\n <Suggestions items={suggestions} onPick={chat.ask} />\n </div>\n ) : null}\n <ol className=\"aic-turns\">\n {chat.turns.map((turn, index) => (\n <li key={index} className=\"aic-turn\">\n <Question text={turn.question} />\n <TurnBody turn={turn} view={view} stopped={chat.stopped.includes(index)} linkAllowed={chat.linkAllowed}\n live={chat.busy && index === chat.turns.length - 1} />\n </li>\n ))}\n {chat.pendingQuestion ? (\n <li className=\"aic-turn\"><Question text={chat.pendingQuestion} /><ConnectStep pending /></li>\n ) : null}\n </ol>\n {chat.refusal === PLAN_INACTIVE ? <PlanOffer onActive={chat.retry} /> : null}\n {chat.error && chat.refusal !== PLAN_INACTIVE ? (\n <div className=\"aic-error\" role=\"alert\">\n <p>{chat.error}</p>\n <button type=\"button\" className=\"aic-text-button\" onClick={chat.retry}>{moduleMessages.retry}</button>\n </div>\n ) : null}\n </div>\n );\n}\n"]}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
// The chat's offer to subscribe, in place of the error, when the TensorPass account the visitor signed in
|
|
3
|
+
// with has no plan yet: the plans with their levels and monthly price as TensorPass sends them, and a
|
|
4
|
+
// button for each that opens TensorPass's billing page in a new tab. When the page regains focus, the
|
|
5
|
+
// subscription is read once; once it is active, the visitor's question goes out on its own.
|
|
6
|
+
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
7
|
+
import { useAiConnect } from "../../AiConnectProvider.js";
|
|
8
|
+
import { modelLabel } from "./accountModel.js";
|
|
9
|
+
import { priceText } from "./planPrice.js";
|
|
10
|
+
// The plans, read when the card shows, and the question sent again, once, when the plan is active.
|
|
11
|
+
function usePlans(access, onActive) {
|
|
12
|
+
const [plans, setPlans] = useState(access ? { kind: 'loading' } : { kind: 'failed' });
|
|
13
|
+
const activated = useRef(false);
|
|
14
|
+
const latestOnActive = useRef(onActive);
|
|
15
|
+
useEffect(() => {
|
|
16
|
+
latestOnActive.current = onActive;
|
|
17
|
+
});
|
|
18
|
+
const read = useCallback(() => {
|
|
19
|
+
if (!access) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
access.subscription().then((subscription) => {
|
|
23
|
+
if (subscription.status !== 'active') {
|
|
24
|
+
setPlans({ kind: 'ready', plans: subscription.plans });
|
|
25
|
+
}
|
|
26
|
+
else if (!activated.current) {
|
|
27
|
+
activated.current = true;
|
|
28
|
+
latestOnActive.current();
|
|
29
|
+
}
|
|
30
|
+
}, () => setPlans({ kind: 'failed' }));
|
|
31
|
+
}, [access]);
|
|
32
|
+
useEffect(() => {
|
|
33
|
+
read();
|
|
34
|
+
window.addEventListener('focus', read);
|
|
35
|
+
return () => window.removeEventListener('focus', read);
|
|
36
|
+
}, [read]);
|
|
37
|
+
return { plans, read };
|
|
38
|
+
}
|
|
39
|
+
// Opens the tab during the click, as browsers allow, then sends it to the billing page once TensorPass
|
|
40
|
+
// gives its address. The tab gets no handle on the site's page.
|
|
41
|
+
function openBillingPage(access, plan) {
|
|
42
|
+
const tab = window.open('', '_blank');
|
|
43
|
+
if (tab) {
|
|
44
|
+
tab.opener = null;
|
|
45
|
+
}
|
|
46
|
+
return access.billingPage(plan).then((url) => {
|
|
47
|
+
if (tab) {
|
|
48
|
+
tab.location.href = url;
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
location.assign(url);
|
|
52
|
+
}
|
|
53
|
+
}, (error) => {
|
|
54
|
+
tab?.close();
|
|
55
|
+
throw error;
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
function PlanRow({ offer, onChoose }) {
|
|
59
|
+
const { locale, webMessages } = useAiConnect();
|
|
60
|
+
const copy = webMessages.plan;
|
|
61
|
+
return (_jsxs("li", { className: "aic-plan", children: [_jsxs("div", { className: "aic-plan-copy", children: [_jsx("p", { className: "aic-plan-name", children: offer.name }), _jsx("p", { className: "aic-plan-levels", children: offer.levels.map((level) => modelLabel(level, 'tensorpass')).join(', ') })] }), offer.price ? (_jsx("p", { className: "aic-plan-price", children: copy.perMonth.replace('{price}', priceText(offer.price, locale)) })) : null, _jsx("button", { type: "button", className: "aic-button aic-plan-choose", onClick: onChoose, children: copy.choose.replace('{plan}', offer.name) })] }));
|
|
62
|
+
}
|
|
63
|
+
export function PlanOffer({ onActive }) {
|
|
64
|
+
const { client, webMessages, moduleMessages } = useAiConnect();
|
|
65
|
+
const [access] = useState(() => client.planAccess());
|
|
66
|
+
const { plans, read } = usePlans(access, onActive);
|
|
67
|
+
const [choice, setChoice] = useState('none');
|
|
68
|
+
const copy = webMessages.plan;
|
|
69
|
+
const choose = (plan) => {
|
|
70
|
+
if (access) {
|
|
71
|
+
openBillingPage(access, plan).then(() => setChoice('waiting'), () => setChoice('failed'));
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
return (_jsxs("div", { className: "aic-plan-offer", role: "status", children: [_jsx("p", { className: "aic-plan-title", children: copy.title }), _jsx("p", { className: "aic-plan-text", children: choice === 'waiting' ? copy.waiting : copy.text }), plans.kind === 'ready' ? (_jsx("ul", { className: "aic-plans", children: plans.plans.map((offer) => _jsx(PlanRow, { offer: offer, onChoose: () => choose(offer.id) }, offer.id)) })) : null, plans.kind === 'failed' || choice === 'failed' ? (_jsxs("p", { className: "aic-plan-text", role: "alert", children: [copy.failed, ' ', _jsx("button", { type: "button", className: "aic-text-button", onClick: () => {
|
|
75
|
+
setChoice('none');
|
|
76
|
+
read();
|
|
77
|
+
}, children: moduleMessages.retry })] })) : null] }));
|
|
78
|
+
}
|
|
79
|
+
//# sourceMappingURL=PlanOffer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PlanOffer.js","sourceRoot":"","sources":["../../../src/modules/parts/PlanOffer.tsx"],"names":[],"mappings":";AAAA,0GAA0G;AAC1G,sGAAsG;AACtG,sGAAsG;AACtG,4FAA4F;AAE5F,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAEjE,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA6B,CAAC;AAC3D,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAI3C,mGAAmG;AACnG,SAAS,QAAQ,CAAC,MAAyB,EAAE,QAAoB;IAC/D,MAAM,CAAC,KAAK,EA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AAK,EAC9C,YAAG,SAAS,EAAC,eAAe,YAAE,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,GAAK,EACjF,KAAK,CAAC,IAAI,KAAK,OAAO,CAAC,CAAC,CAAC,CACxB,aAAI,SAAS,EAAC,WAAW,YACtB,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAC,OAAO,IAAgB,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,IAAxD,KAAK,CAAC,EAAE,CAAoD,CAAC,GACpG,CACN,CAAC,CAAC,CAAC,IAAI,EACP,KAAK,CAAC,IAAI,KAAK,QAAQ,IAAI,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,CAChD,aAAG,SAAS,EAAC,eAAe,EAAC,IAAI,EAAC,OAAO,aACtC,IAAI,CAAC,MAAM,EAAE,GAAG,EACjB,iBAAQ,IAAI,EAAC,QAAQ,EAAC,SAAS,EAAC,iBAAiB,EAAC,OAAO,EAAE,GAAG,EAAE;4BAC9D,SAAS,CAAC,MAAM,CAAC,CAAC;4BAClB,IAAI,EAAE,CAAC;wBACT,CAAC,YAAG,cAAc,CAAC,KAAK,GAAU,IAChC,CACL,CAAC,CAAC,CAAC,IAAI,IACJ,CACP,CAAC;AACJ,CAAC","sourcesContent":["// The chat's offer to subscribe, in place of the error, when the TensorPass account the visitor signed in\n// with has no plan yet: the plans with their levels and monthly price as TensorPass sends them, and a\n// button for each that opens TensorPass's billing page in a new tab. When the page regains focus, the\n// subscription is read once; once it is active, the visitor's question goes out on its own.\n\nimport { useCallback, useEffect, useRef, useState } from 'react';\nimport type { PlanAccess, PlanOffer as Offer } from '@tensorpass/aiconnect';\nimport { useAiConnect } from '../../AiConnectProvider.tsx';\nimport { modelLabel } from './accountModel.ts';\nimport { priceText } from './planPrice.ts';\n\ntype Plans = { kind: 'loading' } | { kind: 'ready'; plans: Offer[] } | { kind: 'failed' };\n\n// The plans, read when the card shows, and the question sent again, once, when the plan is active.\nfunction usePlans(access: PlanAccess | null, onActive: () => void) {\n const [plans, setPlans] = useState<Plans>(access ? { kind: 'loading' } : { kind: 'failed' });\n const activated = useRef(false);\n const latestOnActive = useRef(onActive);\n useEffect(() => {\n latestOnActive.current = onActive;\n });\n const read = useCallback(() => {\n if (!access) {\n return;\n }\n access.subscription().then((subscription) => {\n if (subscription.status !== 'active') {\n setPlans({ kind: 'ready', plans: subscription.plans });\n } else if (!activated.current) {\n activated.current = true;\n latestOnActive.current();\n }\n }, () => setPlans({ kind: 'failed' }));\n }, [access]);\n useEffect(() => {\n read();\n window.addEventListener('focus', read);\n return () => window.removeEventListener('focus', read);\n }, [read]);\n return { plans, read };\n}\n\n// Opens the tab during the click, as browsers allow, then sends it to the billing page once TensorPass\n// gives its address. The tab gets no handle on the site's page.\nfunction openBillingPage(access: PlanAccess, plan: string): Promise<void> {\n const tab = window.open('', '_blank');\n if (tab) {\n tab.opener = null;\n }\n return access.billingPage(plan).then((url) => {\n if (tab) {\n tab.location.href = url;\n } else {\n location.assign(url);\n }\n }, (error: unknown) => {\n tab?.close();\n throw error;\n });\n}\n\nfunction PlanRow({ offer, onChoose }: { offer: Offer; onChoose: () => void }) {\n const { locale, webMessages } = useAiConnect();\n const copy = webMessages.plan;\n return (\n <li className=\"aic-plan\">\n <div className=\"aic-plan-copy\">\n <p className=\"aic-plan-name\">{offer.name}</p>\n <p className=\"aic-plan-levels\">{offer.levels.map((level) => modelLabel(level, 'tensorpass')).join(', ')}</p>\n </div>\n {offer.price ? (\n <p className=\"aic-plan-price\">{copy.perMonth.replace('{price}', priceText(offer.price, locale))}</p>\n ) : null}\n <button type=\"button\" className=\"aic-button aic-plan-choose\" onClick={onChoose}>\n {copy.choose.replace('{plan}', offer.name)}\n </button>\n </li>\n );\n}\n\nexport function PlanOffer({ onActive }: { onActive: () => void }) {\n const { client, webMessages, moduleMessages } = useAiConnect();\n const [access] = useState(() => client.planAccess());\n const { plans, read } = usePlans(access, onActive);\n const [choice, setChoice] = useState<'none' | 'waiting' | 'failed'>('none');\n const copy = webMessages.plan;\n const choose = (plan: string) => {\n if (access) {\n openBillingPage(access, plan).then(() => setChoice('waiting'), () => setChoice('failed'));\n }\n };\n return (\n <div className=\"aic-plan-offer\" role=\"status\">\n <p className=\"aic-plan-title\">{copy.title}</p>\n <p className=\"aic-plan-text\">{choice === 'waiting' ? copy.waiting : copy.text}</p>\n {plans.kind === 'ready' ? (\n <ul className=\"aic-plans\">\n {plans.plans.map((offer) => <PlanRow key={offer.id} offer={offer} onChoose={() => choose(offer.id)} />)}\n </ul>\n ) : null}\n {plans.kind === 'failed' || choice === 'failed' ? (\n <p className=\"aic-plan-text\" role=\"alert\">\n {copy.failed}{' '}\n <button type=\"button\" className=\"aic-text-button\" onClick={() => {\n setChoice('none');\n read();\n }}>{moduleMessages.retry}</button>\n </p>\n ) : null}\n </div>\n );\n}\n"]}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useAiConnect } from "../../AiConnectProvider.js";
|
|
3
|
+
import { CheckIcon } from "./icons.js";
|
|
4
|
+
// The conversation loop and McpToolSource both hand a failed tool's result back with this prefix.
|
|
5
|
+
const TOOL_ERROR = 'Tool error:';
|
|
6
|
+
const SUMMARY_LENGTH = 60;
|
|
7
|
+
function statusOf({ result }) {
|
|
8
|
+
if (result === null) {
|
|
9
|
+
return 'running';
|
|
10
|
+
}
|
|
11
|
+
return result.startsWith(TOOL_ERROR) ? 'failed' : 'done';
|
|
12
|
+
}
|
|
13
|
+
function argumentSummary(args) {
|
|
14
|
+
const summary = Object.entries(args)
|
|
15
|
+
.filter(([, value]) => value !== undefined && value !== null && value !== '')
|
|
16
|
+
.map(([name, value]) => `${name} ${typeof value === 'string' ? value : JSON.stringify(value)}`)
|
|
17
|
+
.join(', ');
|
|
18
|
+
return summary.length > SUMMARY_LENGTH ? `${summary.slice(0, SUMMARY_LENGTH - 1)}…` : summary;
|
|
19
|
+
}
|
|
20
|
+
function ToolRow({ activity, label }) {
|
|
21
|
+
const { moduleMessages } = useAiConnect();
|
|
22
|
+
const status = statusOf(activity);
|
|
23
|
+
const summary = argumentSummary(activity.call.arguments);
|
|
24
|
+
return (_jsxs("li", { className: "aic-tool", "data-status": status, children: [_jsx("span", { className: "aic-tool-light", "aria-hidden": "true", children: status === 'done' ? _jsx(CheckIcon, {}) : null }), label ? _jsx("span", { className: "aic-tool-label", children: label }) : (_jsx("code", { className: "aic-tool-name", children: activity.call.name })), summary ? _jsx("span", { className: "aic-tool-args", children: summary }) : null, status === 'failed' ? _jsx("span", { className: "aic-tool-failed", children: moduleMessages.toolFailed }) : (_jsx("span", { className: "aic-visually-hidden", children: status === 'running' ? moduleMessages.toolRunning : moduleMessages.toolDone }))] }));
|
|
25
|
+
}
|
|
26
|
+
export function ToolActivityList({ tools, labels }) {
|
|
27
|
+
const shown = tools.filter((activity) => activity.visible !== false);
|
|
28
|
+
if (shown.length === 0) {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
return (_jsx("ul", { className: "aic-tools", children: shown.map((activity, index) => (_jsx(ToolRow, { activity: activity, label: labels?.[activity.call.name] }, `${index}:${activity.call.id}`))) }));
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=ToolActivity.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ToolActivity.js","sourceRoot":"","sources":["../../../src/modules/parts/ToolActivity.tsx"],"names":[],"mappings":";AAKA,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA6B,CAAC;AAC3D,OAAO,EAAE,SAAS,EAAE,MAAM,YAAa,CAAC;AAIxC,kGAAkG;AAClG,MAAM,UAAU,GAAG,aAAa,CAAC;AACjC,MAAM,cAAc,GAAG,EAAE,CAAC;AA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1G,CAAC,GACC,CACN,CAAC;AACJ,CAAC","sourcesContent":["// The tool calls of a turn as they run: a cyan light while the site's tool works, a check once its\n// result is back, and the arguments the visitor's AI chose, so the visitor sees what was searched. The\n// tools the site keeps out of `visibleTools` run without a line.\n\nimport type { ToolActivity as Activity } from '../../useAiChat.ts';\nimport { useAiConnect } from '../../AiConnectProvider.tsx';\nimport { CheckIcon } from './icons.tsx';\n\ntype ToolStatus = 'running' | 'done' | 'failed';\n\n// The conversation loop and McpToolSource both hand a failed tool's result back with this prefix.\nconst TOOL_ERROR = 'Tool error:';\nconst SUMMARY_LENGTH = 60;\n\nfunction statusOf({ result }: Activity): ToolStatus {\n if (result === null) {\n return 'running';\n }\n return result.startsWith(TOOL_ERROR) ? 'failed' : 'done';\n}\n\nfunction argumentSummary(args: Record<string, unknown>): string {\n const summary = Object.entries(args)\n .filter(([, value]) => value !== undefined && value !== null && value !== '')\n .map(([name, value]) => `${name} ${typeof value === 'string' ? value : JSON.stringify(value)}`)\n .join(', ');\n return summary.length > SUMMARY_LENGTH ? `${summary.slice(0, SUMMARY_LENGTH - 1)}…` : summary;\n}\n\nfunction ToolRow({ activity, label }: { activity: Activity; label?: string }) {\n const { moduleMessages } = useAiConnect();\n const status = statusOf(activity);\n const summary = argumentSummary(activity.call.arguments);\n return (\n <li className=\"aic-tool\" data-status={status}>\n <span className=\"aic-tool-light\" aria-hidden=\"true\">{status === 'done' ? <CheckIcon /> : null}</span>\n {label ? <span className=\"aic-tool-label\">{label}</span> : (\n <code className=\"aic-tool-name\">{activity.call.name}</code>\n )}\n {summary ? <span className=\"aic-tool-args\">{summary}</span> : null}\n {status === 'failed' ? <span className=\"aic-tool-failed\">{moduleMessages.toolFailed}</span> : (\n <span className=\"aic-visually-hidden\">\n {status === 'running' ? moduleMessages.toolRunning : moduleMessages.toolDone}\n </span>\n )}\n </li>\n );\n}\n\nexport function ToolActivityList({ tools, labels }: { tools: Activity[]; labels?: Record<string, string> }) {\n const shown = tools.filter((activity) => activity.visible !== false);\n if (shown.length === 0) {\n return null;\n }\n return (\n <ul className=\"aic-tools\">\n {shown.map((activity, index) => (\n <ToolRow key={`${index}:${activity.call.id}`} activity={activity} label={labels?.[activity.call.name]} />\n ))}\n </ul>\n );\n}\n"]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// The model the account badge names: the plan's level by its name for TensorPass, such as Smart, and the
|
|
2
|
+
// model's own short name for OpenRouter, such as auto for openrouter/auto. The wallet names its model
|
|
3
|
+
// itself, so its name stays as it is.
|
|
4
|
+
export function modelLabel(model, account) {
|
|
5
|
+
if (account === 'tensorpass') {
|
|
6
|
+
return model.charAt(0).toUpperCase() + model.slice(1);
|
|
7
|
+
}
|
|
8
|
+
if (account === 'openrouter') {
|
|
9
|
+
return model.slice(model.lastIndexOf('/') + 1);
|
|
10
|
+
}
|
|
11
|
+
return model;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=accountModel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"accountModel.js","sourceRoot":"","sources":["../../../src/modules/parts/accountModel.ts"],"names":[],"mappings":"AAAA,yGAAyG;AACzG,sGAAsG;AACtG,sCAAsC;AAItC,MAAM,UAAU,UAAU,CAAC,KAAa,EAAE,OAAsB;IAC9D,IAAI,OAAO,KAAK,YAAY,EAAE,CAAC;QAC7B,OAAO,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IACxD,CAAC;IACD,IAAI,OAAO,KAAK,YAAY,EAAE,CAAC;QAC7B,OAAO,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,WAAW,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC;IACjD,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["// The model the account badge names: the plan's level by its name for TensorPass, such as Smart, and the\n// model's own short name for OpenRouter, such as auto for openrouter/auto. The wallet names its model\n// itself, so its name stays as it is.\n\nimport type { WebAccountId } from '@tensorpass/aiconnect';\n\nexport function modelLabel(model: string, account?: WebAccountId): string {\n if (account === 'tensorpass') {\n return model.charAt(0).toUpperCase() + model.slice(1);\n }\n if (account === 'openrouter') {\n return model.slice(model.lastIndexOf('/') + 1);\n }\n return model;\n}\n"]}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export type InlineRun = {
|
|
2
|
+
kind: 'text';
|
|
3
|
+
text: string;
|
|
4
|
+
} | {
|
|
5
|
+
kind: 'strong';
|
|
6
|
+
text: string;
|
|
7
|
+
} | {
|
|
8
|
+
kind: 'em';
|
|
9
|
+
text: string;
|
|
10
|
+
} | {
|
|
11
|
+
kind: 'code';
|
|
12
|
+
text: string;
|
|
13
|
+
} | {
|
|
14
|
+
kind: 'link';
|
|
15
|
+
text: string;
|
|
16
|
+
href: string;
|
|
17
|
+
};
|
|
18
|
+
export type AnswerBlock = {
|
|
19
|
+
kind: 'paragraph';
|
|
20
|
+
runs: InlineRun[];
|
|
21
|
+
} | {
|
|
22
|
+
kind: 'heading';
|
|
23
|
+
runs: InlineRun[];
|
|
24
|
+
} | {
|
|
25
|
+
kind: 'list';
|
|
26
|
+
ordered: boolean;
|
|
27
|
+
items: InlineRun[][];
|
|
28
|
+
};
|
|
29
|
+
export declare function onSite(href: string): boolean;
|
|
30
|
+
export declare function inlineRuns(text: string): InlineRun[];
|
|
31
|
+
export declare function keepAllowedLinks(blocks: AnswerBlock[], allowed: (href: string) => boolean): AnswerBlock[];
|
|
32
|
+
export declare function answerBlocks(text: string): AnswerBlock[];
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
// The answer's text as the blocks a module draws: paragraphs, headings, and bulleted or numbered
|
|
2
|
+
// lists, each made of inline runs (plain, bold, italic, code, link). Models write light Markdown
|
|
3
|
+
// even when asked for plain text, so the module shows it as formatting. A mark the stream has not
|
|
4
|
+
// closed yet stays plain text until its closing half arrives. An image is never drawn, since it would
|
|
5
|
+
// load by itself: its description stays as text. A link the conversation's guards do not allow stays
|
|
6
|
+
// as its words.
|
|
7
|
+
import { leadsToSitePage } from '@tensorpass/aiconnect';
|
|
8
|
+
const INLINE = /\*\*([^*\n]+)\*\*|`([^`\n]+)`|!\[([^\]\n]*)\]\([^)\s]+\)|\[([^\]\n]+)\]\(([^)\s]+)\)|\*([^*\s][^*\n]*?)\*/g;
|
|
9
|
+
const BULLET = /^\s*[-*•]\s+(.*)$/;
|
|
10
|
+
const NUMBERED = /^\s*\d+[.)]\s+(.*)$/;
|
|
11
|
+
const HEADING = /^\s*#{1,6}\s+(.*)$/;
|
|
12
|
+
const WEB_OR_MAIL = /^(https?:\/\/|mailto:)/i;
|
|
13
|
+
// Whether `href` stays on the page's own site, read as the conversation's guards read it.
|
|
14
|
+
export function onSite(href) {
|
|
15
|
+
return leadsToSitePage(href, globalThis.location?.origin);
|
|
16
|
+
}
|
|
17
|
+
// Links open only to the web, to mail, or to a page of the site itself.
|
|
18
|
+
function opensSafely(href) {
|
|
19
|
+
return WEB_OR_MAIL.test(href) || onSite(href);
|
|
20
|
+
}
|
|
21
|
+
function markRun(match) {
|
|
22
|
+
const [whole, strong, code, imageText, linkText, href, em] = match;
|
|
23
|
+
if (strong !== undefined) {
|
|
24
|
+
return { kind: 'strong', text: strong };
|
|
25
|
+
}
|
|
26
|
+
if (code !== undefined) {
|
|
27
|
+
return { kind: 'code', text: code };
|
|
28
|
+
}
|
|
29
|
+
if (imageText !== undefined) {
|
|
30
|
+
return { kind: 'text', text: imageText };
|
|
31
|
+
}
|
|
32
|
+
if (linkText !== undefined) {
|
|
33
|
+
return opensSafely(href) ? { kind: 'link', text: linkText, href } : { kind: 'text', text: whole };
|
|
34
|
+
}
|
|
35
|
+
return { kind: 'em', text: em };
|
|
36
|
+
}
|
|
37
|
+
export function inlineRuns(text) {
|
|
38
|
+
const runs = [];
|
|
39
|
+
let cursor = 0;
|
|
40
|
+
for (const match of text.matchAll(INLINE)) {
|
|
41
|
+
if (match.index > cursor) {
|
|
42
|
+
runs.push({ kind: 'text', text: text.slice(cursor, match.index) });
|
|
43
|
+
}
|
|
44
|
+
runs.push(markRun(match));
|
|
45
|
+
cursor = match.index + match[0].length;
|
|
46
|
+
}
|
|
47
|
+
if (cursor < text.length) {
|
|
48
|
+
runs.push({ kind: 'text', text: text.slice(cursor) });
|
|
49
|
+
}
|
|
50
|
+
return runs;
|
|
51
|
+
}
|
|
52
|
+
function listItem(line) {
|
|
53
|
+
const bullet = BULLET.exec(line);
|
|
54
|
+
if (bullet) {
|
|
55
|
+
return { ordered: false, text: bullet[1] };
|
|
56
|
+
}
|
|
57
|
+
const numbered = NUMBERED.exec(line);
|
|
58
|
+
return numbered ? { ordered: true, text: numbered[1] } : null;
|
|
59
|
+
}
|
|
60
|
+
// Adds a line to the blocks read so far: a list item joins the list above it, a heading stands
|
|
61
|
+
// alone, and other lines join the paragraph above them until a blank line ends it.
|
|
62
|
+
function addLine(blocks, line, afterBlank) {
|
|
63
|
+
const last = blocks.at(-1);
|
|
64
|
+
const item = listItem(line);
|
|
65
|
+
if (item) {
|
|
66
|
+
if (last?.kind === 'list' && last.ordered === item.ordered) {
|
|
67
|
+
last.items.push(inlineRuns(item.text));
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
blocks.push({ kind: 'list', ordered: item.ordered, items: [inlineRuns(item.text)] });
|
|
71
|
+
}
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
const heading = HEADING.exec(line);
|
|
75
|
+
if (heading) {
|
|
76
|
+
blocks.push({ kind: 'heading', runs: inlineRuns(heading[1]) });
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
if (last?.kind === 'paragraph' && !afterBlank) {
|
|
80
|
+
last.runs.push({ kind: 'text', text: '\n' }, ...inlineRuns(line));
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
blocks.push({ kind: 'paragraph', runs: inlineRuns(line) });
|
|
84
|
+
}
|
|
85
|
+
// The blocks with every link the guards do not allow turned back into its words.
|
|
86
|
+
export function keepAllowedLinks(blocks, allowed) {
|
|
87
|
+
const runs = (items) => items.map((run) => (run.kind === 'link' && !allowed(run.href) ? { kind: 'text', text: run.text } : run));
|
|
88
|
+
return blocks.map((block) => (block.kind === 'list'
|
|
89
|
+
? { ...block, items: block.items.map(runs) }
|
|
90
|
+
: { ...block, runs: runs(block.runs) }));
|
|
91
|
+
}
|
|
92
|
+
export function answerBlocks(text) {
|
|
93
|
+
const blocks = [];
|
|
94
|
+
let afterBlank = true;
|
|
95
|
+
for (const line of text.split('\n')) {
|
|
96
|
+
if (!line.trim()) {
|
|
97
|
+
afterBlank = true;
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
100
|
+
addLine(blocks, line, afterBlank);
|
|
101
|
+
afterBlank = false;
|
|
102
|
+
}
|
|
103
|
+
return blocks;
|
|
104
|
+
}
|
|
105
|
+
//# sourceMappingURL=answerMarkdown.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"answerMarkdown.js","sourceRoot":"","sources":["../../../src/modules/parts/answerMarkdown.ts"],"names":[],"mappings":"AAAA,iGAAiG;AACjG,iGAAiG;AACjG,kGAAkG;AAClG,sGAAsG;AACtG,qGAAqG;AACrG,gBAAgB;AAEhB,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAcxD,MAAM,MAAM,GAAG,4GAA4G,CAAC;AAC5H,MAAM,MAAM,GAAG,mBAAmB,CAAC;AACnC,MAAM,QAAQ,GAAG,qBAAqB,CAAC;AACvC,MAAM,OAAO,GAAG,oBAAoB,CAAC;AACrC,MAAM,WAAW,GAAG,yBAAyB,CAAC;AAE9C,0FAA0F;AAC1F,MAAM,UAAU,MAAM,CAAC,IAAY;IACjC,OAAO,eAAe,CAAC,IAAI,EAAE,UAAU,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;AAC5D,CAAC;AAED,wEAAwE;AACxE,SAAS,WAAW,CAAC,IAAY;IAC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AAK,MAAM,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,GAAG,CACnF,CAAC,CAAC;IACH,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,IAAI,KAAK,MAAM;QACjD,CAAC,CAAC,EAAE,GAAG,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE;QAC5C,CAAC,CAAC,EAAE,GAAG,KAAK,EAAE,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC;AAC7C,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,IAAY;IACvC,MAAM,MAAM,GAAkB,EAAE,CAAC;IACjC,IAAI,UAAU,GAAG,IAAI,CAAC;IACtB,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC;QACpC,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,EAAE,CAAC;YACjB,UAAU,GAAG,IAAI,CAAC;YAClB,SAAS;QACX,CAAC;QACD,OAAO,CAAC,MAAM,EAAE,IAAI,EAAE,UAAU,CAAC,CAAC;QAClC,UAAU,GAAG,KAAK,CAAC;IACrB,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["// The answer's text as the blocks a module draws: paragraphs, headings, and bulleted or numbered\n// lists, each made of inline runs (plain, bold, italic, code, link). Models write light Markdown\n// even when asked for plain text, so the module shows it as formatting. A mark the stream has not\n// closed yet stays plain text until its closing half arrives. An image is never drawn, since it would\n// load by itself: its description stays as text. A link the conversation's guards do not allow stays\n// as its words.\n\nimport { leadsToSitePage } from '@tensorpass/aiconnect';\n\nexport type InlineRun =\n | { kind: 'text'; text: string }\n | { kind: 'strong'; text: string }\n | { kind: 'em'; text: string }\n | { kind: 'code'; text: string }\n | { kind: 'link'; text: string; href: string };\n\nexport type AnswerBlock =\n | { kind: 'paragraph'; runs: InlineRun[] }\n | { kind: 'heading'; runs: InlineRun[] }\n | { kind: 'list'; ordered: boolean; items: InlineRun[][] };\n\nconst INLINE = /\\*\\*([^*\\n]+)\\*\\*|`([^`\\n]+)`|!\\[([^\\]\\n]*)\\]\\([^)\\s]+\\)|\\[([^\\]\\n]+)\\]\\(([^)\\s]+)\\)|\\*([^*\\s][^*\\n]*?)\\*/g;\nconst BULLET = /^\\s*[-*•]\\s+(.*)$/;\nconst NUMBERED = /^\\s*\\d+[.)]\\s+(.*)$/;\nconst HEADING = /^\\s*#{1,6}\\s+(.*)$/;\nconst WEB_OR_MAIL = /^(https?:\\/\\/|mailto:)/i;\n\n// Whether `href` stays on the page's own site, read as the conversation's guards read it.\nexport function onSite(href: string): boolean {\n return leadsToSitePage(href, globalThis.location?.origin);\n}\n\n// Links open only to the web, to mail, or to a page of the site itself.\nfunction opensSafely(href: string): boolean {\n return WEB_OR_MAIL.test(href) || onSite(href);\n}\n\nfunction markRun(match: RegExpExecArray): InlineRun {\n const [whole, strong, code, imageText, linkText, href, em] = match;\n if (strong !== undefined) {\n return { kind: 'strong', text: strong };\n }\n if (code !== undefined) {\n return { kind: 'code', text: code };\n }\n if (imageText !== undefined) {\n return { kind: 'text', text: imageText };\n }\n if (linkText !== undefined) {\n return opensSafely(href) ? { kind: 'link', text: linkText, href } : { kind: 'text', text: whole };\n }\n return { kind: 'em', text: em };\n}\n\nexport function inlineRuns(text: string): InlineRun[] {\n const runs: InlineRun[] = [];\n let cursor = 0;\n for (const match of text.matchAll(INLINE)) {\n if (match.index > cursor) {\n runs.push({ kind: 'text', text: text.slice(cursor, match.index) });\n }\n runs.push(markRun(match));\n cursor = match.index + match[0].length;\n }\n if (cursor < text.length) {\n runs.push({ kind: 'text', text: text.slice(cursor) });\n }\n return runs;\n}\n\ninterface ListItemLine {\n ordered: boolean;\n text: string;\n}\n\nfunction listItem(line: string): ListItemLine | null {\n const bullet = BULLET.exec(line);\n if (bullet) {\n return { ordered: false, text: bullet[1] };\n }\n const numbered = NUMBERED.exec(line);\n return numbered ? { ordered: true, text: numbered[1] } : null;\n}\n\n// Adds a line to the blocks read so far: a list item joins the list above it, a heading stands\n// alone, and other lines join the paragraph above them until a blank line ends it.\nfunction addLine(blocks: AnswerBlock[], line: string, afterBlank: boolean): void {\n const last = blocks.at(-1);\n const item = listItem(line);\n if (item) {\n if (last?.kind === 'list' && last.ordered === item.ordered) {\n last.items.push(inlineRuns(item.text));\n } else {\n blocks.push({ kind: 'list', ordered: item.ordered, items: [inlineRuns(item.text)] });\n }\n return;\n }\n const heading = HEADING.exec(line);\n if (heading) {\n blocks.push({ kind: 'heading', runs: inlineRuns(heading[1]) });\n return;\n }\n if (last?.kind === 'paragraph' && !afterBlank) {\n last.runs.push({ kind: 'text', text: '\\n' }, ...inlineRuns(line));\n return;\n }\n blocks.push({ kind: 'paragraph', runs: inlineRuns(line) });\n}\n\n// The blocks with every link the guards do not allow turned back into its words.\nexport function keepAllowedLinks(blocks: AnswerBlock[], allowed: (href: string) => boolean): AnswerBlock[] {\n const runs = (items: InlineRun[]) => items.map((run): InlineRun => (\n run.kind === 'link' && !allowed(run.href) ? { kind: 'text', text: run.text } : run\n ));\n return blocks.map((block) => (block.kind === 'list'\n ? { ...block, items: block.items.map(runs) }\n : { ...block, runs: runs(block.runs) }));\n}\n\nexport function answerBlocks(text: string): AnswerBlock[] {\n const blocks: AnswerBlock[] = [];\n let afterBlank = true;\n for (const line of text.split('\\n')) {\n if (!line.trim()) {\n afterBlank = true;\n continue;\n }\n addLine(blocks, line, afterBlank);\n afterBlank = false;\n }\n return blocks;\n}\n"]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare const WaveIcon: ({ size, className }: {
|
|
2
|
+
size?: number;
|
|
3
|
+
className?: string;
|
|
4
|
+
}) => import("react").JSX.Element;
|
|
5
|
+
export declare const SendIcon: () => import("react").JSX.Element;
|
|
6
|
+
export declare const CloseIcon: () => import("react").JSX.Element;
|
|
7
|
+
export declare const NewChatIcon: () => import("react").JSX.Element;
|
|
8
|
+
export declare const SearchIcon: () => import("react").JSX.Element;
|
|
9
|
+
export declare const CheckIcon: () => import("react").JSX.Element;
|
|
10
|
+
export declare const ArrowIcon: () => import("react").JSX.Element;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { WAVE_ARCS, WAVE_STROKE_WIDTH } from "../../launcher.js";
|
|
3
|
+
function Stroke({ children, size = 18, width = 2, className }) {
|
|
4
|
+
return (_jsx("svg", { className: className, width: size, height: size, viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: width, strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", focusable: "false", children: children }));
|
|
5
|
+
}
|
|
6
|
+
// The three arcs, each its own path so a live answer can light them one after the other.
|
|
7
|
+
export const WaveIcon = ({ size = 18, className }) => (_jsx(Stroke, { size: size, width: WAVE_STROKE_WIDTH, className: className, children: WAVE_ARCS.map((arc, index) => _jsx("path", { className: `aic-w${index + 1}`, d: arc }, arc)) }));
|
|
8
|
+
export const SendIcon = () => _jsx(Stroke, { size: 18, width: 2.4, children: _jsx("path", { d: "M12 19V5M6 11l6-6 6 6" }) });
|
|
9
|
+
export const CloseIcon = () => _jsx(Stroke, { size: 18, children: _jsx("path", { d: "M6 6l12 12M18 6 6 18" }) });
|
|
10
|
+
export const NewChatIcon = () => (_jsxs(Stroke, { size: 18, children: [_jsx("path", { d: "M12 4H7a3 3 0 0 0-3 3v10a3 3 0 0 0 3 3h10a3 3 0 0 0 3-3v-5" }), _jsx("path", { d: "M17.5 3.5a2.1 2.1 0 0 1 3 3L13 14l-4 1 1-4z" })] }));
|
|
11
|
+
export const SearchIcon = () => (_jsxs(Stroke, { size: 18, children: [_jsx("circle", { cx: "11", cy: "11", r: "6.5" }), _jsx("path", { d: "m20 20-4.2-4.2" })] }));
|
|
12
|
+
export const CheckIcon = () => _jsx(Stroke, { size: 12, width: 3, children: _jsx("path", { d: "m5 12 5 5 9-10" }) });
|
|
13
|
+
// Points along the reading direction; the stylesheet mirrors it in right to left.
|
|
14
|
+
export const ArrowIcon = () => _jsx(Stroke, { size: 16, className: "aic-arrow", children: _jsx("path", { d: "M5 12h14M13 6l6 6-6 6" }) });
|
|
15
|
+
//# sourceMappingURL=icons.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"icons.js","sourceRoot":"","sources":["../../../src/modules/parts/icons.tsx"],"names":[],"mappings":";AAIA,OAAO,EAAE,SAAS,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AASjE,SAAS,MAAM,CAAC,EAAE,QAAQ,EAAE,IAAI,GAAG,EAAE,EAAE,KAAK,GAAG,CAAC,EAAE,SAAS,EAAe;IACxE,OAAO,CACL,cAAK,SAAS,EAAE,SAAS,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAC,WAAW,EAAC,IAAI,EAAC,MAAM,EAAC,MAAM,EAAC,cAAc,EACzG,WAAW,EAAE,KAAK,EAAE,aAAa,EAAC,OAAO,EAAC,cAAc,EAAC,OAAO,iBAAa,MAAM,EAAC,SAAS,EAAC,OAAO,YACpG,QAAQ,GACL,CACP,CAAC;AACJ,CAAC;AAED,yFAAyF;AACzF,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,EAAE,IAAI,GAAG,EAAE,EAAE,SAAS,EAAyC,EAAE,EAAE,CAAC,CAC3F,KAAC,MAAM,IAAC,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,iBAAiB,EAAE,SAAS,EAAE,SAAS,YAC/D,SAAS,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE,CAAC,eAAgB,SAAS,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grid, round caps and joins).\n// The wave is the wallet's mark: the contactless arcs that light up while the visitor's AI answers.\n\nimport type { ReactNode } from 'react';\nimport { WAVE_ARCS, WAVE_STROKE_WIDTH } from '../../launcher.ts';\n\ninterface StrokeProps {\n children: ReactNode;\n size?: number;\n width?: number;\n className?: string;\n}\n\nfunction Stroke({ children, size = 18, width = 2, className }: StrokeProps) {\n return (\n <svg className={className} width={size} height={size} viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\"\n strokeWidth={width} strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\" focusable=\"false\">\n {children}\n </svg>\n );\n}\n\n// The three arcs, each its own path so a live answer can light them one after the other.\nexport const WaveIcon = ({ size = 18, className }: { size?: number; className?: string }) => (\n <Stroke size={size} width={WAVE_STROKE_WIDTH} className={className}>\n {WAVE_ARCS.map((arc, index) => <path key={arc} className={`aic-w${index + 1}`} d={arc} />)}\n </Stroke>\n);\n\nexport const SendIcon = () => <Stroke size={18} width={2.4}><path d=\"M12 19V5M6 11l6-6 6 6\" /></Stroke>;\n\nexport const CloseIcon = () => <Stroke size={18}><path d=\"M6 6l12 12M18 6 6 18\" /></Stroke>;\n\nexport const NewChatIcon = () => (\n <Stroke size={18}>\n <path d=\"M12 4H7a3 3 0 0 0-3 3v10a3 3 0 0 0 3 3h10a3 3 0 0 0 3-3v-5\" />\n <path d=\"M17.5 3.5a2.1 2.1 0 0 1 3 3L13 14l-4 1 1-4z\" />\n </Stroke>\n);\n\nexport const SearchIcon = () => (\n <Stroke size={18}><circle cx=\"11\" cy=\"11\" r=\"6.5\" /><path d=\"m20 20-4.2-4.2\" /></Stroke>\n);\n\nexport const CheckIcon = () => <Stroke size={12} width={3}><path d=\"m5 12 5 5 9-10\" /></Stroke>;\n\n// Points along the reading direction; the stylesheet mirrors it in right to left.\nexport const ArrowIcon = () => <Stroke size={16} className=\"aic-arrow\"><path d=\"M5 12h14M13 6l6 6-6 6\" /></Stroke>;\n"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// The name a site gives a module's actions for its click analytics (`analytics` on the module): each
|
|
2
|
+
// action button of the module carries `data-analytics` with that name and the action, such as `try-send`.
|
|
3
|
+
import { createContext, useContext } from 'react';
|
|
4
|
+
export const ModuleAnalytics = createContext(undefined);
|
|
5
|
+
export function useActionAttribute(action) {
|
|
6
|
+
const name = useContext(ModuleAnalytics);
|
|
7
|
+
return name ? { 'data-analytics': `${name}-${action}` } : {};
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=moduleAnalytics.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"moduleAnalytics.js","sourceRoot":"","sources":["../../../src/modules/parts/moduleAnalytics.ts"],"names":[],"mappings":"AAAA,qGAAqG;AACrG,0GAA0G;AAE1G,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAIlD,MAAM,CAAC,MAAM,eAAe,GAAG,aAAa,CAAqB,SAAS,CAAC,CAAC;AAE5E,MAAM,UAAU,kBAAkB,CAAC,MAAoB;IACrD,MAAM,IAAI,GAAG,UAAU,CAAC,eAAe,CAAC,CAAC;IACzC,OAAO,IAAI,CAAC,CAAC,CAAC,EAAE,gBAAgB,EAAE,GAAG,IAAI,IAAI,MAAM,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;AAC/D,CAAC","sourcesContent":["// The name a site gives a module's actions for its click analytics (`analytics` on the module): each\n// action button of the module carries `data-analytics` with that name and the action, such as `try-send`.\n\nimport { createContext, useContext } from 'react';\n\nexport type ModuleAction = 'install' | 'connect' | 'send' | 'suggestion';\n\nexport const ModuleAnalytics = createContext<string | undefined>(undefined);\n\nexport function useActionAttribute(action: ModuleAction): { 'data-analytics'?: string } {\n const name = useContext(ModuleAnalytics);\n return name ? { 'data-analytics': `${name}-${action}` } : {};\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function moduleClass(form: string, className?: string): string;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
// The class list of a module's outer element: the shared module class, the form's own, and the
|
|
2
|
+
// class the site adds.
|
|
3
|
+
export function moduleClass(form, className) {
|
|
4
|
+
return ['aic-module', `aic-${form}`, className].filter(Boolean).join(' ');
|
|
5
|
+
}
|
|
6
|
+
//# sourceMappingURL=moduleClass.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"moduleClass.js","sourceRoot":"","sources":["../../../src/modules/parts/moduleClass.ts"],"names":[],"mappings":"AAAA,+FAA+F;AAC/F,uBAAuB;AAEvB,MAAM,UAAU,WAAW,CAAC,IAAY,EAAE,SAAkB;IAC1D,OAAO,CAAC,YAAY,EAAE,OAAO,IAAI,EAAE,EAAE,SAAS,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC5E,CAAC","sourcesContent":["// The class list of a module's outer element: the shared module class, the form's own, and the\n// class the site adds.\n\nexport function moduleClass(form: string, className?: string): string {\n return ['aic-module', `aic-${form}`, className].filter(Boolean).join(' ');\n}\n"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// A plan's monthly price in the page's language, read from the currency's smallest unit as TensorPass
|
|
2
|
+
// sends it, such as 2000 cents for US$20.
|
|
3
|
+
export function priceText(price, locale) {
|
|
4
|
+
const format = new Intl.NumberFormat(locale, { style: 'currency', currency: price.currency });
|
|
5
|
+
const digits = format.resolvedOptions().maximumFractionDigits ?? 2;
|
|
6
|
+
return format.format(price.amount / 10 ** digits);
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=planPrice.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"planPrice.js","sourceRoot":"","sources":["../../../src/modules/parts/planPrice.ts"],"names":[],"mappings":"AAAA,sGAAsG;AACtG,0CAA0C;AAI1C,MAAM,UAAU,SAAS,CAAC,KAAgB,EAAE,MAAc;IACxD,MAAM,MAAM,GAAG,IAAI,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE,EAAE,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC;IAC9F,MAAM,MAAM,GAAG,MAAM,CAAC,eAAe,EAAE,CAAC,qBAAqB,IAAI,CAAC,CAAC;IACnE,OAAO,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,GAAG,EAAE,IAAI,MAAM,CAAC,CAAC;AACpD,CAAC","sourcesContent":["// A plan's monthly price in the page's language, read from the currency's smallest unit as TensorPass\n// sends it, such as 2000 cents for US$20.\n\nimport type { PlanPrice } from '@tensorpass/aiconnect';\n\nexport function priceText(price: PlanPrice, locale: string): string {\n const format = new Intl.NumberFormat(locale, { style: 'currency', currency: price.currency });\n const digits = format.resolvedOptions().maximumFractionDigits ?? 2;\n return format.format(price.amount / 10 ** digits);\n}\n"]}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { GuardPolicy, ToolSource } from '@tensorpass/aiconnect';
|
|
2
|
+
export interface ModuleChatOptions {
|
|
3
|
+
system: string;
|
|
4
|
+
tools?: ToolSource;
|
|
5
|
+
mcp?: string;
|
|
6
|
+
guards?: GuardPolicy;
|
|
7
|
+
}
|
|
8
|
+
export declare function useModuleChat({ system, tools, mcp, guards }: ModuleChatOptions): {
|
|
9
|
+
ask: (question: string) => void;
|
|
10
|
+
stop: () => void;
|
|
11
|
+
reset: () => void;
|
|
12
|
+
retry: () => void;
|
|
13
|
+
pendingQuestion: string | null;
|
|
14
|
+
stopped: number[];
|
|
15
|
+
turns: import("../../useAiChat.ts").ChatTurn[];
|
|
16
|
+
send: (question: string) => Promise<void>;
|
|
17
|
+
dropFailedTurn: () => void;
|
|
18
|
+
busy: boolean;
|
|
19
|
+
error: string | null;
|
|
20
|
+
refusal: string | null;
|
|
21
|
+
connected: boolean;
|
|
22
|
+
linkAllowed: (href: string) => boolean;
|
|
23
|
+
};
|
|
24
|
+
export type ModuleChat = ReturnType<typeof useModuleChat>;
|