chat-js 1.0.0-alpha.8 → 1.0.0-beta.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 +7 -5
- package/dist/index.js +7161 -6308
- package/package.json +2 -2
- package/templates/chat-app/agent/agent.ts +0 -2
- package/templates/chat-app/app/editor.css +0 -6
- package/templates/chat-app/app/layout.tsx +11 -18
- package/templates/chat-app/app/opengraph-image.png +0 -0
- package/templates/chat-app/chat.config.ts +0 -44
- package/templates/chat-app/chatjs/core/gateway/runtime.ts +0 -7
- package/templates/chat-app/chatjs/core/ui/slots.tsx +15 -5
- package/templates/chat-app/chatjs/generated/installed-chat-ui.ts +4 -0
- package/templates/chat-app/chatjs/generated/installed.ts +2 -0
- package/templates/chat-app/chatjs/plugins/guest-chat/signed-out.tsx +7 -4
- package/templates/chat-app/chatjs/plugins/mcp/routes/connectors-page.tsx +4 -1
- package/templates/chat-app/chatjs/plugins/mcp/ui/connectors-settings.tsx +1 -1
- package/templates/chat-app/chatjs/plugins/mcp/ui/mcp-connect-dialog.tsx +1 -1
- package/templates/chat-app/chatjs/plugins/mcp/ui/mcp-create-dialog.tsx +1 -1
- package/templates/chat-app/chatjs/plugins/model-preferences/model-row.tsx +3 -0
- package/templates/chat-app/chatjs/plugins/model-preferences/models-settings.tsx +1 -0
- package/templates/chat-app/chatjs/plugins/projects/routes/project-page.tsx +10 -1
- package/templates/chat-app/chatjs/plugins/projects/ui/delete-project-dialog.tsx +0 -3
- package/templates/chat-app/chatjs/plugins/projects/ui/project-icon-picker.tsx +1 -0
- package/templates/chat-app/chatjs/plugins/streamdown-math/chat-ui.ts +11 -0
- package/templates/chat-app/chatjs/plugins/streamdown-math/plugin.json +6 -0
- package/templates/chat-app/chatjs/plugins/streamdown-mermaid/chat-ui.ts +10 -0
- package/templates/chat-app/chatjs/plugins/streamdown-mermaid/plugin.json +6 -0
- package/templates/chat-app/chatjs/providers/gateway.ts +49 -55
- package/templates/chat-app/chatjs/tools/generate-image/tool.test.ts +3 -14
- package/templates/chat-app/components/ai-elements/response.tsx +16 -15
- package/templates/chat-app/components/auth-form-view.tsx +35 -43
- package/templates/chat-app/components/chat/chat-composer.tsx +55 -20
- package/templates/chat-app/components/chat/chat-sidebar.tsx +5 -3
- package/templates/chat-app/components/composer/prompt-form.tsx +7 -1
- package/templates/chat-app/components/eve/eve-chat-error.tsx +12 -2
- package/templates/chat-app/components/eve/eve-conversation.tsx +223 -154
- package/templates/chat-app/components/eve/eve-creation-recovery.tsx +32 -1
- package/templates/chat-app/components/eve/eve-history-list.tsx +1 -1
- package/templates/chat-app/components/model-selection-indicator.tsx +12 -10
- package/templates/chat-app/components/model-selector-view.tsx +211 -186
- package/templates/chat-app/components/new-chat-button.tsx +1 -1
- package/templates/chat-app/components/settings/settings-nav.tsx +1 -1
- package/templates/chat-app/components/settings/settings-navigation-link.tsx +1 -0
- package/templates/chat-app/components/sidebar-top-row.tsx +1 -1
- package/templates/chat-app/components/ui/sidebar.tsx +1 -1
- package/templates/chat-app/components/ui/trace.tsx +1 -1
- package/templates/chat-app/hooks/use-auto-focus.ts +12 -13
- package/templates/chat-app/lib/ai/active-gateway.ts +0 -9
- package/templates/chat-app/lib/ai/app-models.test.ts +0 -4
- package/templates/chat-app/lib/ai/app-models.ts +11 -6
- package/templates/chat-app/lib/ai/gateways/registry.ts +4 -31
- package/templates/chat-app/lib/ai/model-catalog.ts +50 -0
- package/templates/chat-app/lib/ai/models.ts +4 -39
- package/templates/chat-app/lib/ai/providers.ts +2 -16
- package/templates/chat-app/lib/config-schema.ts +0 -96
- package/templates/chat-app/lib/devtools-disabled.ts +1 -0
- package/templates/chat-app/lib/eve/model-selection.test.ts +47 -50
- package/templates/chat-app/lib/eve/model-selection.ts +5 -37
- package/templates/chat-app/lib/eve/tool-cost.test.ts +18 -6
- package/templates/chat-app/lib/eve/tool-cost.ts +10 -18
- package/templates/chat-app/oxfmt.config.ts +0 -2
- package/templates/chat-app/package.json +7 -9
- package/templates/chat-app/proxy.ts +2 -4
- package/templates/chat-app/scripts/build-eve.test.ts +56 -0
- package/templates/chat-app/scripts/build-eve.ts +12 -5
- package/templates/chat-app/scripts/check-env.ts +2 -17
- package/templates/chat-app/scripts/environment-validation-report.ts +1 -20
- package/templates/chat-app/trpc/react.tsx +2 -2
- package/templates/electron/forge.config.ts +1 -19
- package/templates/electron/scripts/write-branding.ts +1 -5
- package/templates/chat-app/app/privacy/page.tsx +0 -153
- package/templates/chat-app/app/terms/page.tsx +0 -270
- package/templates/chat-app/components/ai-elements/context-hover.radix.tsx +0 -15
- package/templates/chat-app/components/ai-elements/context-hover.tsx +0 -17
- package/templates/chat-app/components/ai-elements/context.tsx +0 -405
- package/templates/chat-app/components/composer/editor.css +0 -96
- package/templates/chat-app/components/lexical-chat-input.tsx +0 -276
- package/templates/chat-app/components/model-selection-indicator.radix.tsx +0 -17
- package/templates/chat-app/components/ui/resizable.tsx +0 -49
- package/templates/chat-app/lib/ai/gateways/fallback-models.ts +0 -29
- package/templates/chat-app/lib/ai/models.generated.ts +0 -4242
- package/templates/chat-app/lib/ai/usage-token-details.test.ts +0 -76
- package/templates/chat-app/lib/ai/usage-token-details.ts +0 -33
- package/templates/chat-app/scripts/fetch-models.ts +0 -30
- package/templates/chat-app/scripts/gateway-snapshot-warning.test.ts +0 -9
|
@@ -1,270 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
|
|
3
|
-
import { config } from "@/lib/config";
|
|
4
|
-
|
|
5
|
-
const getPlanTypesLabel = ({
|
|
6
|
-
hasFree,
|
|
7
|
-
hasPro,
|
|
8
|
-
}: {
|
|
9
|
-
readonly hasFree: boolean;
|
|
10
|
-
readonly hasPro: boolean;
|
|
11
|
-
}): string => {
|
|
12
|
-
if (hasFree && hasPro) {
|
|
13
|
-
return "free and paid";
|
|
14
|
-
}
|
|
15
|
-
if (hasPro) {
|
|
16
|
-
return "paid";
|
|
17
|
-
}
|
|
18
|
-
return "free";
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
const PricingSection = ({
|
|
22
|
-
hasAnyPlan,
|
|
23
|
-
planTypesLabel,
|
|
24
|
-
hasFree,
|
|
25
|
-
hasPro,
|
|
26
|
-
currencySymbol,
|
|
27
|
-
paymentProcessors,
|
|
28
|
-
}: {
|
|
29
|
-
readonly hasAnyPlan: boolean;
|
|
30
|
-
readonly planTypesLabel: string;
|
|
31
|
-
readonly hasFree: boolean;
|
|
32
|
-
readonly hasPro: boolean;
|
|
33
|
-
readonly currencySymbol: string;
|
|
34
|
-
readonly paymentProcessors: readonly string[];
|
|
35
|
-
}): React.JSX.Element => {
|
|
36
|
-
if (!hasAnyPlan) {
|
|
37
|
-
return (
|
|
38
|
-
<>
|
|
39
|
-
<p>
|
|
40
|
-
{config.appName} currently does not offer paid plans. If we introduce
|
|
41
|
-
paid features in the future, this section will be updated and you will
|
|
42
|
-
be notified in advance.
|
|
43
|
-
</p>
|
|
44
|
-
{paymentProcessors.length > 0 && (
|
|
45
|
-
<p>
|
|
46
|
-
When payments are enabled, billing will be processed by{" "}
|
|
47
|
-
{paymentProcessors.join(", ")}. We will not store payment card
|
|
48
|
-
details; payment data will be handled directly by our providers
|
|
49
|
-
according to their policies and security standards.
|
|
50
|
-
</p>
|
|
51
|
-
)}
|
|
52
|
-
</>
|
|
53
|
-
);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
return (
|
|
57
|
-
<>
|
|
58
|
-
<p>
|
|
59
|
-
{config.appName} offers {planTypesLabel} subscription plans.
|
|
60
|
-
</p>
|
|
61
|
-
<ul>
|
|
62
|
-
{hasFree && (
|
|
63
|
-
<li>
|
|
64
|
-
<strong>{config.pricing?.free?.name}:</strong>{" "}
|
|
65
|
-
{config.pricing?.free?.summary}
|
|
66
|
-
</li>
|
|
67
|
-
)}
|
|
68
|
-
{hasPro && (
|
|
69
|
-
<li>
|
|
70
|
-
<strong>{config.pricing?.pro?.name}:</strong> {currencySymbol}
|
|
71
|
-
{config.pricing?.pro?.monthlyPrice}/month —{" "}
|
|
72
|
-
{config.pricing?.pro?.summary}
|
|
73
|
-
</li>
|
|
74
|
-
)}
|
|
75
|
-
</ul>
|
|
76
|
-
{paymentProcessors.length > 0 && (
|
|
77
|
-
<p>
|
|
78
|
-
We use third-party payment processors to handle billing and payments:{" "}
|
|
79
|
-
{paymentProcessors.join(", ")}. {config.appName} does not store any
|
|
80
|
-
payment card details, bank information, or other sensitive payment
|
|
81
|
-
data. All payment information is processed directly by our providers.
|
|
82
|
-
</p>
|
|
83
|
-
)}
|
|
84
|
-
{hasPro && (
|
|
85
|
-
<ul>
|
|
86
|
-
<li>Billing is monthly and charged automatically</li>
|
|
87
|
-
<li>All fees are non-refundable except as expressly stated</li>
|
|
88
|
-
<li>We may change prices with 30 days notice</li>
|
|
89
|
-
<li>You are responsible for applicable taxes</li>
|
|
90
|
-
<li>Failed payments may result in suspension or termination</li>
|
|
91
|
-
</ul>
|
|
92
|
-
)}
|
|
93
|
-
</>
|
|
94
|
-
);
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
const TermsPage = (): React.JSX.Element => {
|
|
98
|
-
const currencySymbolMap: Record<string, string> = {
|
|
99
|
-
EUR: "€",
|
|
100
|
-
GBP: "£",
|
|
101
|
-
USD: "$",
|
|
102
|
-
};
|
|
103
|
-
|
|
104
|
-
const currencyCode = config.pricing?.currency;
|
|
105
|
-
const currencySymbol =
|
|
106
|
-
typeof currencyCode === "string" && currencyCode !== ""
|
|
107
|
-
? (currencySymbolMap[currencyCode] ?? currencyCode)
|
|
108
|
-
: "";
|
|
109
|
-
const hasFree = Boolean(config.pricing?.free);
|
|
110
|
-
const hasPro = Boolean(config.pricing?.pro);
|
|
111
|
-
const hasAnyPlan = hasFree || hasPro;
|
|
112
|
-
const paymentProcessors = Array.isArray(config.services?.paymentProcessors)
|
|
113
|
-
? config.services.paymentProcessors
|
|
114
|
-
: [];
|
|
115
|
-
const planTypesLabel = getPlanTypesLabel({ hasFree, hasPro });
|
|
116
|
-
|
|
117
|
-
return (
|
|
118
|
-
<main className="prose dark:prose-invert container mx-auto max-w-3xl py-10">
|
|
119
|
-
<h1>{config.policies.terms.title}</h1>
|
|
120
|
-
{(config.policies.terms.lastUpdated ?? "").length > 0 ? (
|
|
121
|
-
<p>
|
|
122
|
-
<strong>Last updated:</strong> {config.policies.terms.lastUpdated}
|
|
123
|
-
</p>
|
|
124
|
-
) : null}
|
|
125
|
-
|
|
126
|
-
<p>
|
|
127
|
-
Welcome to {config.appName}. These Terms of Service govern your use of
|
|
128
|
-
our website and services. By using {config.appName}, you agree to these
|
|
129
|
-
terms in full. If you disagree with any part of these terms, please do
|
|
130
|
-
not use our service.
|
|
131
|
-
</p>
|
|
132
|
-
|
|
133
|
-
<h2>1. Acceptance of Terms</h2>
|
|
134
|
-
<p>
|
|
135
|
-
By accessing or using {config.appName}, you acknowledge that you have
|
|
136
|
-
read, understood, and agree to be bound by these Terms of Service. We
|
|
137
|
-
reserve the right to modify these terms at any time, and such
|
|
138
|
-
modifications shall be effective immediately upon posting. Your
|
|
139
|
-
continued use of {config.appName} after any modifications indicates your
|
|
140
|
-
acceptance of the modified terms.
|
|
141
|
-
</p>
|
|
142
|
-
|
|
143
|
-
<h2>2. Description of Service</h2>
|
|
144
|
-
<p>
|
|
145
|
-
{config.appName} helps users find information using AI. Our service is
|
|
146
|
-
hosted on {config.services.hosting} and integrates with AI technology
|
|
147
|
-
providers including {config.services.aiProviders.join(", ")} to deliver
|
|
148
|
-
results and content generation capabilities.
|
|
149
|
-
</p>
|
|
150
|
-
|
|
151
|
-
<h2>3. User Conduct</h2>
|
|
152
|
-
<ul>
|
|
153
|
-
<li>Comply with applicable laws and regulations</li>
|
|
154
|
-
<li>Respect intellectual property rights</li>
|
|
155
|
-
<li>Do not distribute malware or harmful code</li>
|
|
156
|
-
<li>Do not attempt unauthorized access to our systems</li>
|
|
157
|
-
<li>Do not scrape or conduct automated queries</li>
|
|
158
|
-
<li>Do not generate or distribute illegal or harmful content</li>
|
|
159
|
-
<li>Do not interfere with the proper functioning of the service</li>
|
|
160
|
-
</ul>
|
|
161
|
-
|
|
162
|
-
<h2>4. Content and Results</h2>
|
|
163
|
-
<ul>
|
|
164
|
-
<li>
|
|
165
|
-
No guarantees on accuracy, completeness, or reliability of results
|
|
166
|
-
</li>
|
|
167
|
-
<li>Generated content is based on your queries</li>
|
|
168
|
-
<li>
|
|
169
|
-
We may link to third-party websites that we do not control; use your
|
|
170
|
-
own judgment
|
|
171
|
-
</li>
|
|
172
|
-
</ul>
|
|
173
|
-
|
|
174
|
-
<h2>5. Intellectual Property</h2>
|
|
175
|
-
<p>
|
|
176
|
-
All content, features, and functionality of {config.appName} are the
|
|
177
|
-
property of {config.organization.name} or its licensors and are
|
|
178
|
-
protected by intellectual property laws.
|
|
179
|
-
</p>
|
|
180
|
-
|
|
181
|
-
<h2>6. Third-Party Services</h2>
|
|
182
|
-
<p>
|
|
183
|
-
{config.appName} relies on third-party services to provide
|
|
184
|
-
functionality:
|
|
185
|
-
</p>
|
|
186
|
-
<ul>
|
|
187
|
-
<li>Hosting: {config.services.hosting}</li>
|
|
188
|
-
<li>AI providers: {config.services.aiProviders.join(", ")}</li>
|
|
189
|
-
{config.services.paymentProcessors.length > 0 ? (
|
|
190
|
-
<li>
|
|
191
|
-
Payments: {config.services.paymentProcessors.join(", ")} for billing
|
|
192
|
-
and subscription management
|
|
193
|
-
</li>
|
|
194
|
-
) : null}
|
|
195
|
-
</ul>
|
|
196
|
-
<p>
|
|
197
|
-
These third-party services have their own terms and privacy policies and
|
|
198
|
-
may process your data as described in our Privacy Policy. Payment data
|
|
199
|
-
is processed directly by our payment providers according to their
|
|
200
|
-
respective privacy policies and security standards.
|
|
201
|
-
</p>
|
|
202
|
-
|
|
203
|
-
<h2>7. Pricing and Billing</h2>
|
|
204
|
-
<PricingSection
|
|
205
|
-
currencySymbol={currencySymbol}
|
|
206
|
-
hasAnyPlan={hasAnyPlan}
|
|
207
|
-
hasFree={hasFree}
|
|
208
|
-
hasPro={hasPro}
|
|
209
|
-
paymentProcessors={paymentProcessors}
|
|
210
|
-
planTypesLabel={planTypesLabel}
|
|
211
|
-
/>
|
|
212
|
-
|
|
213
|
-
<h2>8. Cancellation and Refunds</h2>
|
|
214
|
-
<p>
|
|
215
|
-
You may cancel your subscription at any time through your account
|
|
216
|
-
settings or by contacting us. Upon cancellation, your subscription
|
|
217
|
-
remains active until the end of the billing period, after which your
|
|
218
|
-
account reverts to the free plan.
|
|
219
|
-
</p>
|
|
220
|
-
<p>
|
|
221
|
-
<strong>No Refund Policy</strong>: All subscription fees are final and
|
|
222
|
-
non-refundable.
|
|
223
|
-
</p>
|
|
224
|
-
|
|
225
|
-
<h2>9. Privacy</h2>
|
|
226
|
-
<p>
|
|
227
|
-
Your use of {config.appName} is also governed by our Privacy Policy,
|
|
228
|
-
which is incorporated by reference.
|
|
229
|
-
</p>
|
|
230
|
-
|
|
231
|
-
<h2>10. Limitation of Liability</h2>
|
|
232
|
-
<p>
|
|
233
|
-
To the maximum extent permitted by law, {config.organization.name} shall
|
|
234
|
-
not be liable for indirect, incidental, special, consequential, or
|
|
235
|
-
punitive damages.
|
|
236
|
-
</p>
|
|
237
|
-
|
|
238
|
-
<h2>11. Disclaimers</h2>
|
|
239
|
-
<p>
|
|
240
|
-
{config.appName} is provided "as is" and "as
|
|
241
|
-
available" without any warranties of any kind, either express or
|
|
242
|
-
implied.
|
|
243
|
-
</p>
|
|
244
|
-
|
|
245
|
-
<h2>12. Termination</h2>
|
|
246
|
-
<p>
|
|
247
|
-
We may suspend or terminate your access for conduct that violates these
|
|
248
|
-
Terms or is harmful to others, us, or third parties.
|
|
249
|
-
</p>
|
|
250
|
-
|
|
251
|
-
<h2>13. Governing Law</h2>
|
|
252
|
-
<p>
|
|
253
|
-
These Terms are governed by the laws of {config.legal.governingLaw}.
|
|
254
|
-
</p>
|
|
255
|
-
|
|
256
|
-
<h2>14. Contact Us</h2>
|
|
257
|
-
<p>
|
|
258
|
-
If you have any questions about these Terms of Service, contact us at{" "}
|
|
259
|
-
{config.organization.contact.legalEmail}
|
|
260
|
-
</p>
|
|
261
|
-
|
|
262
|
-
<p>
|
|
263
|
-
By using {config.appName}, you agree to these Terms of Service and our
|
|
264
|
-
Privacy Policy.
|
|
265
|
-
</p>
|
|
266
|
-
</main>
|
|
267
|
-
);
|
|
268
|
-
};
|
|
269
|
-
|
|
270
|
-
export default TermsPage;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
|
|
3
|
-
import React from "react";
|
|
4
|
-
import type { ComponentProps, ReactElement } from "react";
|
|
5
|
-
import { HoverCard, HoverCardTrigger } from "@/components/ui/hover-card";
|
|
6
|
-
|
|
7
|
-
export const ContextHover = (
|
|
8
|
-
props: ComponentProps<typeof HoverCard>
|
|
9
|
-
): React.JSX.Element => <HoverCard openDelay={0} closeDelay={0} {...props} />;
|
|
10
|
-
|
|
11
|
-
export const ContextHoverTrigger = ({
|
|
12
|
-
button,
|
|
13
|
-
}: {
|
|
14
|
-
readonly button: ReactElement;
|
|
15
|
-
}): React.JSX.Element => <HoverCardTrigger asChild>{button}</HoverCardTrigger>;
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
|
|
3
|
-
import React from "react";
|
|
4
|
-
import type { ComponentProps, ReactElement } from "react";
|
|
5
|
-
import { HoverCard, HoverCardTrigger } from "@/components/ui/hover-card";
|
|
6
|
-
|
|
7
|
-
export const ContextHover = (
|
|
8
|
-
props: ComponentProps<typeof HoverCard>
|
|
9
|
-
): React.JSX.Element => <HoverCard {...props} />;
|
|
10
|
-
|
|
11
|
-
export const ContextHoverTrigger = ({
|
|
12
|
-
button,
|
|
13
|
-
}: {
|
|
14
|
-
readonly button: ReactElement;
|
|
15
|
-
}): React.JSX.Element => (
|
|
16
|
-
<HoverCardTrigger delay={0} closeDelay={0} render={button} />
|
|
17
|
-
);
|
|
@@ -1,405 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
|
|
3
|
-
import { hasCustomContent } from "@/components/custom-content";
|
|
4
|
-
|
|
5
|
-
import type { ComponentProps, JSX as ReactJSX } from "react";
|
|
6
|
-
import React, { createContext, useContext, useMemo } from "react";
|
|
7
|
-
import { getUsage } from "tokenlens";
|
|
8
|
-
import { Button } from "@/components/ui/button";
|
|
9
|
-
import {
|
|
10
|
-
HoverCardContent,
|
|
11
|
-
} from "@/components/ui/hover-card";
|
|
12
|
-
import { ContextHover, ContextHoverTrigger } from "./context-hover";
|
|
13
|
-
import { Progress } from "@/components/ui/progress";
|
|
14
|
-
import type { ReadonlyNativeSurface } from "@/lib/readonly-native-surface";
|
|
15
|
-
import type { StoredLanguageModelUsage } from "@/lib/ai/usage-token-details";
|
|
16
|
-
import { cn } from "@/lib/utils";
|
|
17
|
-
import { getUsageTokenDetails } from "@/lib/ai/usage-token-details";
|
|
18
|
-
|
|
19
|
-
const PERCENT_MAX = 100;
|
|
20
|
-
const NO_KNOWN_TOKENS = 0;
|
|
21
|
-
const NO_KNOWN_COST = 0;
|
|
22
|
-
|
|
23
|
-
type ModelId = string;
|
|
24
|
-
|
|
25
|
-
interface ContextSchema {
|
|
26
|
-
usedTokens: number;
|
|
27
|
-
maxTokens: number;
|
|
28
|
-
usage?: StoredLanguageModelUsage;
|
|
29
|
-
modelId?: ModelId;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
const ContextContext = createContext<ContextSchema | null>(null);
|
|
33
|
-
|
|
34
|
-
const useContextValue = (): ContextSchema => {
|
|
35
|
-
const context = useContext(ContextContext);
|
|
36
|
-
|
|
37
|
-
if (!context) {
|
|
38
|
-
throw new Error("Context components must be used within Context");
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
return context;
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
type ContextProps = ComponentProps<typeof ContextHover> & ContextSchema;
|
|
45
|
-
|
|
46
|
-
const Context = ({
|
|
47
|
-
usedTokens,
|
|
48
|
-
maxTokens,
|
|
49
|
-
usage,
|
|
50
|
-
modelId,
|
|
51
|
-
...props
|
|
52
|
-
}: ContextProps): ReactJSX.Element => {
|
|
53
|
-
const contextValue = useMemo(
|
|
54
|
-
() => ({ maxTokens, modelId, usage, usedTokens }),
|
|
55
|
-
[maxTokens, modelId, usage, usedTokens]
|
|
56
|
-
);
|
|
57
|
-
|
|
58
|
-
return (
|
|
59
|
-
<ContextContext.Provider value={contextValue}>
|
|
60
|
-
<ContextHover {...props} />
|
|
61
|
-
</ContextContext.Provider>
|
|
62
|
-
);
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
type ContextTriggerProps = ComponentProps<typeof Button>;
|
|
66
|
-
|
|
67
|
-
const ContextTrigger = ({
|
|
68
|
-
children,
|
|
69
|
-
...props
|
|
70
|
-
}: ContextTriggerProps): React.JSX.Element => {
|
|
71
|
-
const { usedTokens, maxTokens } = useContextValue();
|
|
72
|
-
const usedPercent = usedTokens / maxTokens;
|
|
73
|
-
const renderedPercent = new Intl.NumberFormat("en-US", {
|
|
74
|
-
maximumFractionDigits: 1,
|
|
75
|
-
style: "percent",
|
|
76
|
-
}).format(usedPercent);
|
|
77
|
-
|
|
78
|
-
return (
|
|
79
|
-
<ContextHoverTrigger button={
|
|
80
|
-
<Button type="button" variant="outline" size="sm" {...props}>
|
|
81
|
-
{children ?? <span>{renderedPercent} context</span>}
|
|
82
|
-
</Button>
|
|
83
|
-
} />
|
|
84
|
-
);
|
|
85
|
-
};
|
|
86
|
-
|
|
87
|
-
type ContextContentProps = (Omit<ComponentProps<typeof HoverCardContent>, "className"> & { className?: string });
|
|
88
|
-
|
|
89
|
-
const ContextContent = ({
|
|
90
|
-
className,
|
|
91
|
-
...props
|
|
92
|
-
}: ContextContentProps): React.JSX.Element => (
|
|
93
|
-
<HoverCardContent
|
|
94
|
-
className={cn("min-w-60 divide-y overflow-hidden p-0", className)}
|
|
95
|
-
{...props}
|
|
96
|
-
/>
|
|
97
|
-
);
|
|
98
|
-
|
|
99
|
-
type ContextContentHeaderProps = ComponentProps<"div">;
|
|
100
|
-
|
|
101
|
-
const ContextContentHeader = ({
|
|
102
|
-
children,
|
|
103
|
-
className,
|
|
104
|
-
...props
|
|
105
|
-
}: ContextContentHeaderProps): React.JSX.Element => {
|
|
106
|
-
const { usedTokens, maxTokens } = useContextValue();
|
|
107
|
-
const usedPercent = usedTokens / maxTokens;
|
|
108
|
-
const displayPct = new Intl.NumberFormat("en-US", {
|
|
109
|
-
maximumFractionDigits: 1,
|
|
110
|
-
style: "percent",
|
|
111
|
-
}).format(usedPercent);
|
|
112
|
-
const used = new Intl.NumberFormat("en-US", {
|
|
113
|
-
notation: "compact",
|
|
114
|
-
}).format(usedTokens);
|
|
115
|
-
const total = new Intl.NumberFormat("en-US", {
|
|
116
|
-
notation: "compact",
|
|
117
|
-
}).format(maxTokens);
|
|
118
|
-
|
|
119
|
-
return (
|
|
120
|
-
<div className={cn("w-full space-y-2 p-3", className)} {...props}>
|
|
121
|
-
{children ?? (
|
|
122
|
-
<>
|
|
123
|
-
<div className="flex items-center justify-between gap-3 text-xs">
|
|
124
|
-
<p>{displayPct}</p>
|
|
125
|
-
<p className="text-muted-foreground font-mono">
|
|
126
|
-
{used} / {total}
|
|
127
|
-
</p>
|
|
128
|
-
</div>
|
|
129
|
-
<div className="space-y-2">
|
|
130
|
-
<Progress aria-label="Context used" value={usedPercent * PERCENT_MAX} />
|
|
131
|
-
</div>
|
|
132
|
-
</>
|
|
133
|
-
)}
|
|
134
|
-
</div>
|
|
135
|
-
);
|
|
136
|
-
};
|
|
137
|
-
|
|
138
|
-
type ContextContentBodyProps = ComponentProps<"div">;
|
|
139
|
-
|
|
140
|
-
const ContextContentBody = ({
|
|
141
|
-
children,
|
|
142
|
-
className,
|
|
143
|
-
...props
|
|
144
|
-
}: ContextContentBodyProps): React.JSX.Element => (
|
|
145
|
-
<div className={cn("w-full p-3", className)} {...props}>
|
|
146
|
-
{children}
|
|
147
|
-
</div>
|
|
148
|
-
);
|
|
149
|
-
|
|
150
|
-
type ContextContentFooterProps = ComponentProps<"div">;
|
|
151
|
-
|
|
152
|
-
const ContextContentFooter = ({
|
|
153
|
-
children,
|
|
154
|
-
className,
|
|
155
|
-
...props
|
|
156
|
-
}: ContextContentFooterProps): React.JSX.Element => {
|
|
157
|
-
const { modelId, usage } = useContextValue();
|
|
158
|
-
const costUSD =
|
|
159
|
-
typeof modelId === "string" && modelId !== ""
|
|
160
|
-
? getUsage({
|
|
161
|
-
modelId,
|
|
162
|
-
usage: {
|
|
163
|
-
input: usage?.inputTokens ?? NO_KNOWN_TOKENS,
|
|
164
|
-
output: usage?.outputTokens ?? NO_KNOWN_TOKENS,
|
|
165
|
-
},
|
|
166
|
-
}).costUSD?.totalUSD
|
|
167
|
-
: undefined;
|
|
168
|
-
const totalCost = new Intl.NumberFormat("en-US", {
|
|
169
|
-
currency: "USD",
|
|
170
|
-
style: "currency",
|
|
171
|
-
}).format(costUSD ?? NO_KNOWN_COST);
|
|
172
|
-
|
|
173
|
-
return (
|
|
174
|
-
<div
|
|
175
|
-
className={cn(
|
|
176
|
-
"bg-secondary flex w-full items-center justify-between gap-3 p-3 text-xs",
|
|
177
|
-
className
|
|
178
|
-
)}
|
|
179
|
-
{...props}
|
|
180
|
-
>
|
|
181
|
-
{children ?? (
|
|
182
|
-
<>
|
|
183
|
-
<span className="text-muted-foreground">Total cost</span>
|
|
184
|
-
<span>{totalCost}</span>
|
|
185
|
-
</>
|
|
186
|
-
)}
|
|
187
|
-
</div>
|
|
188
|
-
);
|
|
189
|
-
};
|
|
190
|
-
|
|
191
|
-
type ContextInputUsageProps = ComponentProps<"div">;
|
|
192
|
-
type ContextUsageResult =
|
|
193
|
-
| Exclude<React.ReactNode, false | undefined>
|
|
194
|
-
| React.JSX.Element
|
|
195
|
-
| null;
|
|
196
|
-
|
|
197
|
-
const TokensWithCost = ({
|
|
198
|
-
tokens,
|
|
199
|
-
costText,
|
|
200
|
-
}: {
|
|
201
|
-
readonly tokens?: number;
|
|
202
|
-
readonly costText?: string;
|
|
203
|
-
}): React.JSX.Element => (
|
|
204
|
-
<span>
|
|
205
|
-
{tokens === undefined
|
|
206
|
-
? "—"
|
|
207
|
-
: new Intl.NumberFormat("en-US", {
|
|
208
|
-
notation: "compact",
|
|
209
|
-
}).format(tokens)}
|
|
210
|
-
{typeof costText === "string" && costText !== "" ? (
|
|
211
|
-
<span className="text-muted-foreground ml-2">• {costText}</span>
|
|
212
|
-
) : null}
|
|
213
|
-
</span>
|
|
214
|
-
);
|
|
215
|
-
|
|
216
|
-
const ContextInputUsage = ({
|
|
217
|
-
className,
|
|
218
|
-
children,
|
|
219
|
-
...props
|
|
220
|
-
}: ContextInputUsageProps): ContextUsageResult => {
|
|
221
|
-
const { usage, modelId } = useContextValue();
|
|
222
|
-
const inputTokens = usage?.inputTokens ?? NO_KNOWN_TOKENS;
|
|
223
|
-
|
|
224
|
-
if (hasCustomContent(children)) {
|
|
225
|
-
return children;
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
if (!inputTokens) {
|
|
229
|
-
return null;
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
const inputCost =
|
|
233
|
-
typeof modelId === "string" && modelId !== ""
|
|
234
|
-
? getUsage({
|
|
235
|
-
modelId,
|
|
236
|
-
usage: { input: inputTokens, output: NO_KNOWN_TOKENS },
|
|
237
|
-
}).costUSD?.totalUSD
|
|
238
|
-
: undefined;
|
|
239
|
-
const inputCostText = new Intl.NumberFormat("en-US", {
|
|
240
|
-
currency: "USD",
|
|
241
|
-
style: "currency",
|
|
242
|
-
}).format(inputCost ?? NO_KNOWN_COST);
|
|
243
|
-
|
|
244
|
-
return (
|
|
245
|
-
<div
|
|
246
|
-
className={cn("flex items-center justify-between text-xs", className)}
|
|
247
|
-
{...props}
|
|
248
|
-
>
|
|
249
|
-
<span className="text-muted-foreground">Input</span>
|
|
250
|
-
<TokensWithCost costText={inputCostText} tokens={inputTokens} />
|
|
251
|
-
</div>
|
|
252
|
-
);
|
|
253
|
-
};
|
|
254
|
-
|
|
255
|
-
type ContextOutputUsageProps = ComponentProps<"div">;
|
|
256
|
-
|
|
257
|
-
const ContextOutputUsage = ({
|
|
258
|
-
className,
|
|
259
|
-
children,
|
|
260
|
-
...props
|
|
261
|
-
}: ContextOutputUsageProps): ContextUsageResult => {
|
|
262
|
-
const { usage, modelId } = useContextValue();
|
|
263
|
-
const outputTokens = usage?.outputTokens ?? NO_KNOWN_TOKENS;
|
|
264
|
-
|
|
265
|
-
if (hasCustomContent(children)) {
|
|
266
|
-
return children;
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
if (!outputTokens) {
|
|
270
|
-
return null;
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
const outputCost =
|
|
274
|
-
typeof modelId === "string" && modelId !== ""
|
|
275
|
-
? getUsage({
|
|
276
|
-
modelId,
|
|
277
|
-
usage: { input: NO_KNOWN_TOKENS, output: outputTokens },
|
|
278
|
-
}).costUSD?.totalUSD
|
|
279
|
-
: undefined;
|
|
280
|
-
const outputCostText = new Intl.NumberFormat("en-US", {
|
|
281
|
-
currency: "USD",
|
|
282
|
-
style: "currency",
|
|
283
|
-
}).format(outputCost ?? NO_KNOWN_COST);
|
|
284
|
-
|
|
285
|
-
return (
|
|
286
|
-
<div
|
|
287
|
-
className={cn("flex items-center justify-between text-xs", className)}
|
|
288
|
-
{...props}
|
|
289
|
-
>
|
|
290
|
-
<span className="text-muted-foreground">Output</span>
|
|
291
|
-
<TokensWithCost costText={outputCostText} tokens={outputTokens} />
|
|
292
|
-
</div>
|
|
293
|
-
);
|
|
294
|
-
};
|
|
295
|
-
|
|
296
|
-
type ContextReasoningUsageProps = ComponentProps<"div">;
|
|
297
|
-
|
|
298
|
-
const ContextReasoningUsage = ({
|
|
299
|
-
className,
|
|
300
|
-
children,
|
|
301
|
-
...props
|
|
302
|
-
}: ContextReasoningUsageProps): ContextUsageResult => {
|
|
303
|
-
const { usage, modelId } = useContextValue();
|
|
304
|
-
const { reasoningTokens } = getUsageTokenDetails(usage);
|
|
305
|
-
|
|
306
|
-
if (hasCustomContent(children)) {
|
|
307
|
-
return children;
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
if (!reasoningTokens) {
|
|
311
|
-
return null;
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
const reasoningCost =
|
|
315
|
-
typeof modelId === "string" && modelId !== ""
|
|
316
|
-
? getUsage({
|
|
317
|
-
modelId,
|
|
318
|
-
usage: { reasoningTokens },
|
|
319
|
-
}).costUSD?.totalUSD
|
|
320
|
-
: undefined;
|
|
321
|
-
const reasoningCostText = new Intl.NumberFormat("en-US", {
|
|
322
|
-
currency: "USD",
|
|
323
|
-
style: "currency",
|
|
324
|
-
}).format(reasoningCost ?? NO_KNOWN_COST);
|
|
325
|
-
|
|
326
|
-
return (
|
|
327
|
-
<div
|
|
328
|
-
className={cn("flex items-center justify-between text-xs", className)}
|
|
329
|
-
{...props}
|
|
330
|
-
>
|
|
331
|
-
<span className="text-muted-foreground">Reasoning</span>
|
|
332
|
-
<TokensWithCost costText={reasoningCostText} tokens={reasoningTokens} />
|
|
333
|
-
</div>
|
|
334
|
-
);
|
|
335
|
-
};
|
|
336
|
-
|
|
337
|
-
type ContextCacheUsageProps = ComponentProps<"div">;
|
|
338
|
-
|
|
339
|
-
const ContextCacheUsage = ({
|
|
340
|
-
className,
|
|
341
|
-
children,
|
|
342
|
-
...props
|
|
343
|
-
}: ContextCacheUsageProps): ContextUsageResult => {
|
|
344
|
-
const { usage, modelId } = useContextValue();
|
|
345
|
-
const cacheTokens = getUsageTokenDetails(usage).cachedInputTokens;
|
|
346
|
-
|
|
347
|
-
if (hasCustomContent(children)) {
|
|
348
|
-
return children;
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
if (!cacheTokens) {
|
|
352
|
-
return null;
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
const cacheCost =
|
|
356
|
-
typeof modelId === "string" && modelId !== ""
|
|
357
|
-
? getUsage({
|
|
358
|
-
modelId,
|
|
359
|
-
usage: {
|
|
360
|
-
cacheReads: cacheTokens,
|
|
361
|
-
input: NO_KNOWN_TOKENS,
|
|
362
|
-
output: NO_KNOWN_TOKENS,
|
|
363
|
-
},
|
|
364
|
-
}).costUSD?.totalUSD
|
|
365
|
-
: undefined;
|
|
366
|
-
const cacheCostText = new Intl.NumberFormat("en-US", {
|
|
367
|
-
currency: "USD",
|
|
368
|
-
style: "currency",
|
|
369
|
-
}).format(cacheCost ?? NO_KNOWN_COST);
|
|
370
|
-
|
|
371
|
-
return (
|
|
372
|
-
<div
|
|
373
|
-
className={cn("flex items-center justify-between text-xs", className)}
|
|
374
|
-
{...props}
|
|
375
|
-
>
|
|
376
|
-
<span className="text-muted-foreground">Cache</span>
|
|
377
|
-
<TokensWithCost costText={cacheCostText} tokens={cacheTokens} />
|
|
378
|
-
</div>
|
|
379
|
-
);
|
|
380
|
-
};
|
|
381
|
-
|
|
382
|
-
export {
|
|
383
|
-
Context,
|
|
384
|
-
ContextCacheUsage,
|
|
385
|
-
ContextContent,
|
|
386
|
-
ContextContentBody,
|
|
387
|
-
ContextContentFooter,
|
|
388
|
-
ContextContentHeader,
|
|
389
|
-
ContextInputUsage,
|
|
390
|
-
ContextOutputUsage,
|
|
391
|
-
ContextReasoningUsage,
|
|
392
|
-
ContextTrigger,
|
|
393
|
-
};
|
|
394
|
-
export type {
|
|
395
|
-
ContextCacheUsageProps,
|
|
396
|
-
ContextContentBodyProps,
|
|
397
|
-
ContextContentFooterProps,
|
|
398
|
-
ContextContentHeaderProps,
|
|
399
|
-
ContextContentProps,
|
|
400
|
-
ContextInputUsageProps,
|
|
401
|
-
ContextOutputUsageProps,
|
|
402
|
-
ContextProps,
|
|
403
|
-
ContextReasoningUsageProps,
|
|
404
|
-
ContextTriggerProps,
|
|
405
|
-
};
|