@agent-native/core 0.7.1 → 0.7.2
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/action.d.ts +8 -0
- package/dist/action.d.ts.map +1 -1
- package/dist/action.js +18 -0
- package/dist/action.js.map +1 -1
- package/dist/agent/production-agent.d.ts +9 -0
- package/dist/agent/production-agent.d.ts.map +1 -1
- package/dist/agent/production-agent.js +148 -36
- package/dist/agent/production-agent.js.map +1 -1
- package/dist/agent/run-manager.d.ts.map +1 -1
- package/dist/agent/run-manager.js +20 -1
- package/dist/agent/run-manager.js.map +1 -1
- package/dist/agent/run-store.d.ts +14 -0
- package/dist/agent/run-store.d.ts.map +1 -1
- package/dist/agent/run-store.js +63 -6
- package/dist/agent/run-store.js.map +1 -1
- package/dist/agent/types.d.ts +2 -0
- package/dist/agent/types.d.ts.map +1 -1
- package/dist/cli/create.js +1 -1
- package/dist/cli/create.js.map +1 -1
- package/dist/cli/setup-agents.d.ts.map +1 -1
- package/dist/cli/setup-agents.js +0 -2
- package/dist/cli/setup-agents.js.map +1 -1
- package/dist/cli/templates-meta.d.ts +52 -0
- package/dist/cli/templates-meta.d.ts.map +1 -0
- package/dist/cli/templates-meta.js +165 -0
- package/dist/cli/templates-meta.js.map +1 -0
- package/dist/client/AgentPanel.d.ts +5 -1
- package/dist/client/AgentPanel.d.ts.map +1 -1
- package/dist/client/AgentPanel.js +279 -30
- package/dist/client/AgentPanel.js.map +1 -1
- package/dist/client/AssistantChat.d.ts +2 -1
- package/dist/client/AssistantChat.d.ts.map +1 -1
- package/dist/client/AssistantChat.js +172 -40
- package/dist/client/AssistantChat.js.map +1 -1
- package/dist/client/ConnectBuilderCard.d.ts +21 -0
- package/dist/client/ConnectBuilderCard.d.ts.map +1 -0
- package/dist/client/ConnectBuilderCard.js +196 -0
- package/dist/client/ConnectBuilderCard.js.map +1 -0
- package/dist/client/FeedbackButton.d.ts +15 -0
- package/dist/client/FeedbackButton.d.ts.map +1 -0
- package/dist/client/FeedbackButton.js +72 -0
- package/dist/client/FeedbackButton.js.map +1 -0
- package/dist/client/IframeEmbed.d.ts +17 -0
- package/dist/client/IframeEmbed.d.ts.map +1 -0
- package/dist/client/IframeEmbed.js +108 -0
- package/dist/client/IframeEmbed.js.map +1 -0
- package/dist/client/MultiTabAssistantChat.d.ts.map +1 -1
- package/dist/client/MultiTabAssistantChat.js +34 -7
- package/dist/client/MultiTabAssistantChat.js.map +1 -1
- package/dist/client/agent-chat-adapter.d.ts.map +1 -1
- package/dist/client/agent-chat-adapter.js +34 -15
- package/dist/client/agent-chat-adapter.js.map +1 -1
- package/dist/client/agent-chat.d.ts +6 -0
- package/dist/client/agent-chat.d.ts.map +1 -1
- package/dist/client/agent-chat.js +7 -0
- package/dist/client/agent-chat.js.map +1 -1
- package/dist/client/composer/MentionPopover.d.ts.map +1 -1
- package/dist/client/composer/MentionPopover.js +27 -24
- package/dist/client/composer/MentionPopover.js.map +1 -1
- package/dist/client/composer/TiptapComposer.d.ts +3 -1
- package/dist/client/composer/TiptapComposer.d.ts.map +1 -1
- package/dist/client/composer/TiptapComposer.js +21 -4
- package/dist/client/composer/TiptapComposer.js.map +1 -1
- package/dist/client/embed.d.ts +28 -0
- package/dist/client/embed.d.ts.map +1 -0
- package/dist/client/embed.js +50 -0
- package/dist/client/embed.js.map +1 -0
- package/dist/client/index.d.ts +4 -1
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +4 -1
- package/dist/client/index.js.map +1 -1
- package/dist/client/integrations/IntegrationsPanel.js +2 -2
- package/dist/client/integrations/IntegrationsPanel.js.map +1 -1
- package/dist/client/onboarding/OnboardingBanner.js +2 -2
- package/dist/client/onboarding/OnboardingBanner.js.map +1 -1
- package/dist/client/onboarding/OnboardingPanel.d.ts.map +1 -1
- package/dist/client/onboarding/OnboardingPanel.js +139 -52
- package/dist/client/onboarding/OnboardingPanel.js.map +1 -1
- package/dist/client/onboarding/SetupButton.d.ts.map +1 -1
- package/dist/client/onboarding/SetupButton.js +13 -3
- package/dist/client/onboarding/SetupButton.js.map +1 -1
- package/dist/client/org/TeamPage.d.ts.map +1 -1
- package/dist/client/org/TeamPage.js +12 -7
- package/dist/client/org/TeamPage.js.map +1 -1
- package/dist/client/resources/ResourceEditor.d.ts.map +1 -1
- package/dist/client/resources/ResourceEditor.js +57 -2
- package/dist/client/resources/ResourceEditor.js.map +1 -1
- package/dist/client/resources/ResourceTree.d.ts +5 -1
- package/dist/client/resources/ResourceTree.d.ts.map +1 -1
- package/dist/client/resources/ResourceTree.js +17 -10
- package/dist/client/resources/ResourceTree.js.map +1 -1
- package/dist/client/resources/ResourcesPanel.d.ts.map +1 -1
- package/dist/client/resources/ResourcesPanel.js +12 -10
- package/dist/client/resources/ResourcesPanel.js.map +1 -1
- package/dist/client/settings/AgentsSection.d.ts.map +1 -1
- package/dist/client/settings/AgentsSection.js +6 -3
- package/dist/client/settings/AgentsSection.js.map +1 -1
- package/dist/client/settings/ComingSoonSection.js +1 -1
- package/dist/client/settings/ComingSoonSection.js.map +1 -1
- package/dist/client/settings/LLMSection.d.ts.map +1 -1
- package/dist/client/settings/LLMSection.js +1 -1
- package/dist/client/settings/LLMSection.js.map +1 -1
- package/dist/client/settings/SettingsPanel.d.ts.map +1 -1
- package/dist/client/settings/SettingsPanel.js +16 -23
- package/dist/client/settings/SettingsPanel.js.map +1 -1
- package/dist/client/settings/SettingsSection.js +2 -2
- package/dist/client/settings/SettingsSection.js.map +1 -1
- package/dist/client/settings/UsageSection.d.ts +2 -0
- package/dist/client/settings/UsageSection.d.ts.map +1 -0
- package/dist/client/settings/UsageSection.js +70 -0
- package/dist/client/settings/UsageSection.js.map +1 -0
- package/dist/client/use-action.d.ts.map +1 -1
- package/dist/client/use-action.js +67 -4
- package/dist/client/use-action.js.map +1 -1
- package/dist/client/use-db-sync.d.ts +25 -2
- package/dist/client/use-db-sync.d.ts.map +1 -1
- package/dist/client/use-db-sync.js +62 -1
- package/dist/client/use-db-sync.js.map +1 -1
- package/dist/client/use-dev-mode.d.ts.map +1 -1
- package/dist/client/use-dev-mode.js +16 -1
- package/dist/client/use-dev-mode.js.map +1 -1
- package/dist/db/client.d.ts +12 -0
- package/dist/db/client.d.ts.map +1 -1
- package/dist/db/client.js +89 -2
- package/dist/db/client.js.map +1 -1
- package/dist/db/create-get-db.d.ts +11 -0
- package/dist/db/create-get-db.d.ts.map +1 -1
- package/dist/db/create-get-db.js +47 -3
- package/dist/db/create-get-db.js.map +1 -1
- package/dist/db/migrations.d.ts.map +1 -1
- package/dist/db/migrations.js +62 -5
- package/dist/db/migrations.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/jobs/scheduler.d.ts.map +1 -1
- package/dist/jobs/scheduler.js +7 -2
- package/dist/jobs/scheduler.js.map +1 -1
- package/dist/oauth-tokens/google-refresh.d.ts +31 -0
- package/dist/oauth-tokens/google-refresh.d.ts.map +1 -0
- package/dist/oauth-tokens/google-refresh.js +115 -0
- package/dist/oauth-tokens/google-refresh.js.map +1 -0
- package/dist/oauth-tokens/index.d.ts +1 -0
- package/dist/oauth-tokens/index.d.ts.map +1 -1
- package/dist/oauth-tokens/index.js +1 -0
- package/dist/oauth-tokens/index.js.map +1 -1
- package/dist/onboarding/default-steps.d.ts.map +1 -1
- package/dist/onboarding/default-steps.js +57 -18
- package/dist/onboarding/default-steps.js.map +1 -1
- package/dist/org/context.js +1 -1
- package/dist/org/handlers.d.ts.map +1 -1
- package/dist/org/handlers.js +35 -10
- package/dist/org/handlers.js.map +1 -1
- package/dist/org/plugin.d.ts.map +1 -1
- package/dist/org/plugin.js +37 -22
- package/dist/org/plugin.js.map +1 -1
- package/dist/resources/handlers.js +1 -1
- package/dist/resources/handlers.js.map +1 -1
- package/dist/resources/metadata.d.ts.map +1 -1
- package/dist/resources/metadata.js +2 -2
- package/dist/resources/metadata.js.map +1 -1
- package/dist/resources/store.d.ts.map +1 -1
- package/dist/resources/store.js +27 -1
- package/dist/resources/store.js.map +1 -1
- package/dist/scripts/db/patch.d.ts.map +1 -1
- package/dist/scripts/db/patch.js +273 -11
- package/dist/scripts/db/patch.js.map +1 -1
- package/dist/server/action-discovery.d.ts.map +1 -1
- package/dist/server/action-discovery.js +2 -0
- package/dist/server/action-discovery.js.map +1 -1
- package/dist/server/action-routes.d.ts.map +1 -1
- package/dist/server/action-routes.js +26 -0
- package/dist/server/action-routes.js.map +1 -1
- package/dist/server/agent-chat-plugin.d.ts +12 -0
- package/dist/server/agent-chat-plugin.d.ts.map +1 -1
- package/dist/server/agent-chat-plugin.js +495 -48
- package/dist/server/agent-chat-plugin.js.map +1 -1
- package/dist/server/agent-discovery.js +2 -2
- package/dist/server/agent-discovery.js.map +1 -1
- package/dist/server/agent-teams.d.ts.map +1 -1
- package/dist/server/agent-teams.js +21 -58
- package/dist/server/agent-teams.js.map +1 -1
- package/dist/server/auth.d.ts +6 -0
- package/dist/server/auth.d.ts.map +1 -1
- package/dist/server/auth.js +284 -41
- package/dist/server/auth.js.map +1 -1
- package/dist/server/better-auth-instance.d.ts +1 -1
- package/dist/server/better-auth-instance.d.ts.map +1 -1
- package/dist/server/better-auth-instance.js +70 -4
- package/dist/server/better-auth-instance.js.map +1 -1
- package/dist/server/builder-browser.d.ts +21 -0
- package/dist/server/builder-browser.d.ts.map +1 -1
- package/dist/server/builder-browser.js +67 -4
- package/dist/server/builder-browser.js.map +1 -1
- package/dist/server/core-routes-plugin.d.ts.map +1 -1
- package/dist/server/core-routes-plugin.js +122 -4
- package/dist/server/core-routes-plugin.js.map +1 -1
- package/dist/server/desktop-sso.d.ts +30 -0
- package/dist/server/desktop-sso.d.ts.map +1 -0
- package/dist/server/desktop-sso.js +74 -0
- package/dist/server/desktop-sso.js.map +1 -0
- package/dist/server/email.d.ts +23 -0
- package/dist/server/email.d.ts.map +1 -0
- package/dist/server/email.js +105 -0
- package/dist/server/email.js.map +1 -0
- package/dist/server/framework-request-handler.d.ts.map +1 -1
- package/dist/server/framework-request-handler.js +29 -0
- package/dist/server/framework-request-handler.js.map +1 -1
- package/dist/server/google-oauth.d.ts.map +1 -1
- package/dist/server/google-oauth.js +19 -3
- package/dist/server/google-oauth.js.map +1 -1
- package/dist/server/local-migration.d.ts +9 -0
- package/dist/server/local-migration.d.ts.map +1 -1
- package/dist/server/local-migration.js +44 -14
- package/dist/server/local-migration.js.map +1 -1
- package/dist/server/oauth-helpers.d.ts +2 -0
- package/dist/server/oauth-helpers.d.ts.map +1 -1
- package/dist/server/oauth-helpers.js +2 -0
- package/dist/server/oauth-helpers.js.map +1 -1
- package/dist/server/onboarding-html.d.ts +6 -0
- package/dist/server/onboarding-html.d.ts.map +1 -1
- package/dist/server/onboarding-html.js +229 -25
- package/dist/server/onboarding-html.js.map +1 -1
- package/dist/server/poll.d.ts.map +1 -1
- package/dist/server/poll.js +48 -0
- package/dist/server/poll.js.map +1 -1
- package/dist/templates/default/.agents/skills/inline-embeds/SKILL.md +88 -0
- package/dist/usage/store.d.ts +74 -12
- package/dist/usage/store.d.ts.map +1 -1
- package/dist/usage/store.js +210 -44
- package/dist/usage/store.js.map +1 -1
- package/dist/vite/client.d.ts.map +1 -1
- package/dist/vite/client.js +55 -0
- package/dist/vite/client.js.map +1 -1
- package/docs/content/deployment.md +59 -2
- package/docs/content/resources.md +9 -9
- package/docs/content/workspace-management.md +2 -2
- package/package.json +3 -3
- package/src/templates/default/.agents/skills/inline-embeds/SKILL.md +88 -0
- /package/dist/templates/workspace-core/{skills → .agents/skills}/company-policies/SKILL.md +0 -0
- /package/src/templates/workspace-core/{skills → .agents/skills}/company-policies/SKILL.md +0 -0
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: inline-embeds
|
|
3
|
+
description: >-
|
|
4
|
+
How to render interactive previews of app screens inline in agent chat via
|
|
5
|
+
sandboxed iframes. Covers the `embed` fence syntax, the `postNavigate` pop-out
|
|
6
|
+
helper, and when to prefer an embed over prose / a static image.
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
# Inline Embeds
|
|
10
|
+
|
|
11
|
+
The chat renderer lets you embed a sandboxed iframe pointing at any same-origin
|
|
12
|
+
route of this app, rendered inline with your reply. Use this when a live,
|
|
13
|
+
interactive preview communicates more than prose or a static screenshot — a
|
|
14
|
+
chart, an email thread, a slide, a form, a ticket.
|
|
15
|
+
|
|
16
|
+
## The `embed` fence
|
|
17
|
+
|
|
18
|
+
Emit a fenced code block with the language `embed`:
|
|
19
|
+
|
|
20
|
+
````
|
|
21
|
+
```embed
|
|
22
|
+
src: /email?id=msg_123
|
|
23
|
+
aspect: 4/3
|
|
24
|
+
title: Re: Q4 planning
|
|
25
|
+
```
|
|
26
|
+
````
|
|
27
|
+
|
|
28
|
+
Keys:
|
|
29
|
+
|
|
30
|
+
| Key | Required | Notes |
|
|
31
|
+
| -------- | -------- | ------------------------------------------------------------------ |
|
|
32
|
+
| `src` | yes | Same-origin path beginning with `/`. Cross-origin URLs are blocked |
|
|
33
|
+
| `aspect` | no | `16/9` (default), `4/3`, `3/2`, `2/1`, `21/9`, `1/1` |
|
|
34
|
+
| `title` | no | Accessible label + hover tooltip |
|
|
35
|
+
| `height` | no | Fixed pixel height when aspect ratio doesn't fit |
|
|
36
|
+
|
|
37
|
+
The rendered iframe is sandboxed (`allow-scripts allow-same-origin allow-forms
|
|
38
|
+
allow-popups`) and `referrerpolicy="same-origin"`. The browser enforces that
|
|
39
|
+
the iframe can't navigate the parent window.
|
|
40
|
+
|
|
41
|
+
## When to reach for an embed
|
|
42
|
+
|
|
43
|
+
- A chart or visualization that benefits from tooltips / hover.
|
|
44
|
+
- A detail view the user might want to scan (email, ticket, event, slide).
|
|
45
|
+
- Anything where "here's a link to it" would force an extra click.
|
|
46
|
+
|
|
47
|
+
**Don't** embed when plain prose, a bulleted list, or a small table is enough.
|
|
48
|
+
**Don't** embed external sites — the renderer blocks cross-origin URLs.
|
|
49
|
+
|
|
50
|
+
## "Open in main window" button — `postNavigate`
|
|
51
|
+
|
|
52
|
+
Every embed route should include a small "Open" button so the user can pop the
|
|
53
|
+
view out of the chat and into the full app. Import the helper from
|
|
54
|
+
`@agent-native/core/client`:
|
|
55
|
+
|
|
56
|
+
```tsx
|
|
57
|
+
import { postNavigate, isInAgentEmbed } from "@agent-native/core/client";
|
|
58
|
+
|
|
59
|
+
export function OpenButton({ path }: { path: string }) {
|
|
60
|
+
if (!isInAgentEmbed()) return null;
|
|
61
|
+
return (
|
|
62
|
+
<button onClick={() => postNavigate(path)}>Open</button>
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
`postNavigate` sends a `postMessage` to the parent chat window. The chat
|
|
68
|
+
renderer validates the message is same-origin, same-iframe, and the path is
|
|
69
|
+
relative, then updates the parent URL via `history.pushState` so react-router
|
|
70
|
+
navigates without a page reload.
|
|
71
|
+
|
|
72
|
+
When the page is loaded directly (not in an iframe), `postNavigate` falls back
|
|
73
|
+
to a same-window navigation, so the button works both ways.
|
|
74
|
+
|
|
75
|
+
## Adding an embed route to a template
|
|
76
|
+
|
|
77
|
+
1. Create a chromeless route (e.g. `app/routes/email.tsx`) that renders the
|
|
78
|
+
detail view without the app shell.
|
|
79
|
+
2. Mark the route path as bare in `app/components/layout/Layout.tsx` so the
|
|
80
|
+
sidebar / header don't render inside the iframe.
|
|
81
|
+
3. Render the existing detail component with a transparent background so it
|
|
82
|
+
blends into the chat theme.
|
|
83
|
+
4. Include an `<OpenButton>` that calls `postNavigate("/path/to/detail")`.
|
|
84
|
+
5. Document the embed URL in this template's `AGENTS.md` so the agent knows
|
|
85
|
+
what's embeddable.
|
|
86
|
+
|
|
87
|
+
The framework-level fence renderer and security enforcement apply
|
|
88
|
+
automatically — no per-template wiring beyond the route and layout bypass.
|
package/dist/usage/store.d.ts
CHANGED
|
@@ -1,22 +1,33 @@
|
|
|
1
|
-
/** Default usage limit per user in cents ($1.00) */
|
|
1
|
+
/** Default usage limit per user in cents ($1.00) for hosted prod mode */
|
|
2
2
|
export declare const DEFAULT_USAGE_LIMIT_CENTS = 100;
|
|
3
|
+
export interface UsageRecord {
|
|
4
|
+
ownerEmail: string;
|
|
5
|
+
inputTokens: number;
|
|
6
|
+
outputTokens: number;
|
|
7
|
+
cacheReadTokens?: number;
|
|
8
|
+
cacheWriteTokens?: number;
|
|
9
|
+
model: string;
|
|
10
|
+
/** Category for this call — e.g. "chat", "automation", "job", "custom-agent". */
|
|
11
|
+
label?: string;
|
|
12
|
+
/** Optional template/app name (e.g. "mail"). Falls back to AGENT_APP env. */
|
|
13
|
+
app?: string;
|
|
14
|
+
}
|
|
3
15
|
/**
|
|
4
|
-
* Calculate cost in
|
|
5
|
-
*
|
|
16
|
+
* Calculate cost in centicents (1/100th of a cent).
|
|
17
|
+
* Accepts cache tokens so callers that use prompt caching are priced
|
|
18
|
+
* correctly. Non-cache-aware callers can pass 0 for the cache fields.
|
|
6
19
|
*/
|
|
7
|
-
export declare function calculateCost(inputTokens: number, outputTokens: number, model: string): number;
|
|
20
|
+
export declare function calculateCost(inputTokens: number, outputTokens: number, model: string, cacheReadTokens?: number, cacheWriteTokens?: number): number;
|
|
8
21
|
/**
|
|
9
|
-
* Record token usage
|
|
22
|
+
* Record token usage from an LLM call.
|
|
23
|
+
*
|
|
24
|
+
* Accepts an object with the full set of fields. A positional overload
|
|
25
|
+
* remains for backward compatibility with the older 4-arg signature.
|
|
10
26
|
*/
|
|
27
|
+
export declare function recordUsage(record: UsageRecord): Promise<void>;
|
|
11
28
|
export declare function recordUsage(ownerEmail: string, inputTokens: number, outputTokens: number, model: string): Promise<void>;
|
|
12
|
-
/**
|
|
13
|
-
* Get total usage cost for a user in cents.
|
|
14
|
-
*/
|
|
29
|
+
/** Total cost (in cents) charged against a user, across all time. */
|
|
15
30
|
export declare function getUserUsageCents(ownerEmail: string): Promise<number>;
|
|
16
|
-
/**
|
|
17
|
-
* Check if a user has exceeded their usage limit.
|
|
18
|
-
* Returns { allowed: true } or { allowed: false, usageCents, limitCents }.
|
|
19
|
-
*/
|
|
20
31
|
export declare function checkUsageLimit(ownerEmail: string, limitCents?: number): Promise<{
|
|
21
32
|
allowed: true;
|
|
22
33
|
usageCents: number;
|
|
@@ -26,4 +37,55 @@ export declare function checkUsageLimit(ownerEmail: string, limitCents?: number)
|
|
|
26
37
|
usageCents: number;
|
|
27
38
|
limitCents: number;
|
|
28
39
|
}>;
|
|
40
|
+
export interface UsageSummaryOptions {
|
|
41
|
+
ownerEmail: string;
|
|
42
|
+
/** Inclusive lower bound (ms since epoch). Defaults to 30 days ago. */
|
|
43
|
+
sinceMs?: number;
|
|
44
|
+
}
|
|
45
|
+
export interface UsageBucket {
|
|
46
|
+
key: string;
|
|
47
|
+
inputTokens: number;
|
|
48
|
+
outputTokens: number;
|
|
49
|
+
cacheReadTokens: number;
|
|
50
|
+
cacheWriteTokens: number;
|
|
51
|
+
cents: number;
|
|
52
|
+
calls: number;
|
|
53
|
+
}
|
|
54
|
+
export interface DailyBucket {
|
|
55
|
+
/** YYYY-MM-DD (UTC) */
|
|
56
|
+
date: string;
|
|
57
|
+
cents: number;
|
|
58
|
+
calls: number;
|
|
59
|
+
}
|
|
60
|
+
export interface UsageRecentEntry {
|
|
61
|
+
id: number;
|
|
62
|
+
createdAt: number;
|
|
63
|
+
label: string;
|
|
64
|
+
app: string;
|
|
65
|
+
model: string;
|
|
66
|
+
inputTokens: number;
|
|
67
|
+
outputTokens: number;
|
|
68
|
+
cacheReadTokens: number;
|
|
69
|
+
cacheWriteTokens: number;
|
|
70
|
+
cents: number;
|
|
71
|
+
}
|
|
72
|
+
export interface UsageSummary {
|
|
73
|
+
totalCents: number;
|
|
74
|
+
totalCalls: number;
|
|
75
|
+
totalInputTokens: number;
|
|
76
|
+
totalOutputTokens: number;
|
|
77
|
+
totalCacheReadTokens: number;
|
|
78
|
+
totalCacheWriteTokens: number;
|
|
79
|
+
sinceMs: number;
|
|
80
|
+
byLabel: UsageBucket[];
|
|
81
|
+
byModel: UsageBucket[];
|
|
82
|
+
byApp: UsageBucket[];
|
|
83
|
+
byDay: DailyBucket[];
|
|
84
|
+
recent: UsageRecentEntry[];
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Produce an aggregated spend view for the Usage admin panel.
|
|
88
|
+
* Scoped to the passed owner email; the UI always passes the session user.
|
|
89
|
+
*/
|
|
90
|
+
export declare function getUsageSummary(options: UsageSummaryOptions): Promise<UsageSummary>;
|
|
29
91
|
//# sourceMappingURL=store.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../../src/usage/store.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../../src/usage/store.ts"],"names":[],"mappings":"AAWA,yEAAyE;AACzE,eAAO,MAAM,yBAAyB,MAAM,CAAC;AAqC7C,MAAM,WAAW,WAAW;IAC1B,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,KAAK,EAAE,MAAM,CAAC;IACd,iFAAiF;IACjF,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,6EAA6E;IAC7E,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AA2DD;;;;GAIG;AACH,wBAAgB,aAAa,CAC3B,WAAW,EAAE,MAAM,EACnB,YAAY,EAAE,MAAM,EACpB,KAAK,EAAE,MAAM,EACb,eAAe,SAAI,EACnB,gBAAgB,SAAI,GACnB,MAAM,CAUR;AAED;;;;;GAKG;AACH,wBAAsB,WAAW,CAAC,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AACtE,wBAAsB,WAAW,CAC/B,UAAU,EAAE,MAAM,EAClB,WAAW,EAAE,MAAM,E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;IACxB,gBAAgB,EAAE,MAAM,CAAC;IACzB,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,YAAY;IAC3B,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,gBAAgB,EAAE,MAAM,CAAC;IACzB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,oBAAoB,EAAE,MAAM,CAAC;IAC7B,qBAAqB,EAAE,MAAM,CAAC;IAC9B,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,WAAW,EAAE,CAAC;IACvB,OAAO,EAAE,WAAW,EAAE,CAAC;IACvB,KAAK,EAAE,WAAW,EAAE,CAAC;IACrB,KAAK,EAAE,WAAW,EAAE,CAAC;IACrB,MAAM,EAAE,gBAAgB,EAAE,CAAC;CAC5B;AAID;;;GAGG;AACH,wBAAsB,eAAe,CACnC,OAAO,EAAE,mBAAmB,GAC3B,OAAO,CAAC,YAAY,CAAC,CAoHvB"}
|
package/dist/usage/store.js
CHANGED
|
@@ -1,17 +1,37 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Token usage tracking and cost
|
|
3
|
-
*
|
|
4
|
-
*
|
|
2
|
+
* Token usage tracking and cost monitoring.
|
|
3
|
+
*
|
|
4
|
+
* Every LLM call made by the framework records a row here so users can
|
|
5
|
+
* see where their spend is going — chat vs automations vs background jobs
|
|
6
|
+
* vs whatever else a template labels its prompts as.
|
|
7
|
+
*
|
|
8
|
+
* Cost is stored as "centicents" (1/100th of a cent) for integer precision.
|
|
5
9
|
*/
|
|
6
|
-
import { getDbExec, intType } from "../db/client.js";
|
|
7
|
-
/** Default usage limit per user in cents ($1.00) */
|
|
10
|
+
import { getDbExec, intType, isPostgres } from "../db/client.js";
|
|
11
|
+
/** Default usage limit per user in cents ($1.00) for hosted prod mode */
|
|
8
12
|
export const DEFAULT_USAGE_LIMIT_CENTS = 100;
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
const PRICING = [
|
|
14
|
+
{
|
|
15
|
+
match: /opus/i,
|
|
16
|
+
pricing: { input: 1500, output: 7500, cacheRead: 150, cacheWrite: 1875 },
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
match: /haiku/i,
|
|
20
|
+
pricing: { input: 100, output: 500, cacheRead: 10, cacheWrite: 125 },
|
|
21
|
+
},
|
|
22
|
+
// default → sonnet pricing
|
|
23
|
+
{
|
|
24
|
+
match: /.*/,
|
|
25
|
+
pricing: { input: 300, output: 1500, cacheRead: 30, cacheWrite: 375 },
|
|
26
|
+
},
|
|
27
|
+
];
|
|
28
|
+
function pricingFor(model) {
|
|
29
|
+
for (const entry of PRICING) {
|
|
30
|
+
if (entry.match.test(model))
|
|
31
|
+
return entry.pricing;
|
|
32
|
+
}
|
|
33
|
+
return PRICING[PRICING.length - 1].pricing;
|
|
34
|
+
}
|
|
15
35
|
let _initPromise;
|
|
16
36
|
async function ensureUsageTable() {
|
|
17
37
|
if (!_initPromise) {
|
|
@@ -23,58 +43,97 @@ async function ensureUsageTable() {
|
|
|
23
43
|
owner_email TEXT NOT NULL,
|
|
24
44
|
input_tokens ${intType()} NOT NULL DEFAULT 0,
|
|
25
45
|
output_tokens ${intType()} NOT NULL DEFAULT 0,
|
|
46
|
+
cache_read_tokens ${intType()} NOT NULL DEFAULT 0,
|
|
47
|
+
cache_write_tokens ${intType()} NOT NULL DEFAULT 0,
|
|
26
48
|
cost_cents_x100 ${intType()} NOT NULL DEFAULT 0,
|
|
27
49
|
model TEXT NOT NULL DEFAULT '',
|
|
50
|
+
label TEXT NOT NULL DEFAULT 'chat',
|
|
51
|
+
app TEXT NOT NULL DEFAULT '',
|
|
28
52
|
created_at ${intType()} NOT NULL
|
|
29
53
|
)
|
|
30
54
|
`);
|
|
31
|
-
//
|
|
32
|
-
//
|
|
55
|
+
// Add columns on older deployments that pre-date the label/cache
|
|
56
|
+
// fields. Each ALTER is wrapped so a dialect without IF NOT EXISTS
|
|
57
|
+
// (SQLite) still makes progress if only some columns are missing.
|
|
58
|
+
const additions = [
|
|
59
|
+
["cache_read_tokens", `${intType()} NOT NULL DEFAULT 0`],
|
|
60
|
+
["cache_write_tokens", `${intType()} NOT NULL DEFAULT 0`],
|
|
61
|
+
["label", `TEXT NOT NULL DEFAULT 'chat'`],
|
|
62
|
+
["app", `TEXT NOT NULL DEFAULT ''`],
|
|
63
|
+
];
|
|
64
|
+
for (const [col, def] of additions) {
|
|
65
|
+
try {
|
|
66
|
+
if (isPostgres()) {
|
|
67
|
+
await client.execute(`ALTER TABLE token_usage ADD COLUMN IF NOT EXISTS ${col} ${def}`);
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
await client.execute(`ALTER TABLE token_usage ADD COLUMN ${col} ${def}`);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
catch {
|
|
74
|
+
// Column already exists — ignore
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
try {
|
|
78
|
+
await client.execute(`CREATE INDEX IF NOT EXISTS idx_token_usage_owner_created ON token_usage (owner_email, created_at)`);
|
|
79
|
+
}
|
|
80
|
+
catch { }
|
|
33
81
|
})();
|
|
34
82
|
}
|
|
35
83
|
return _initPromise;
|
|
36
84
|
}
|
|
37
85
|
/**
|
|
38
|
-
* Calculate cost in
|
|
39
|
-
*
|
|
86
|
+
* Calculate cost in centicents (1/100th of a cent).
|
|
87
|
+
* Accepts cache tokens so callers that use prompt caching are priced
|
|
88
|
+
* correctly. Non-cache-aware callers can pass 0 for the cache fields.
|
|
40
89
|
*/
|
|
41
|
-
export function calculateCost(inputTokens, outputTokens, model) {
|
|
42
|
-
const
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
: SONNET_OUTPUT_COST_PER_MTOK;
|
|
49
|
-
// cost_cents_x100 = (tokens / 1_000_000) * cost_per_mtok * 100
|
|
50
|
-
const inputCostX100 = Math.round((inputTokens / 1_000_000) * inputCost * 100);
|
|
51
|
-
const outputCostX100 = Math.round((outputTokens / 1_000_000) * outputCost * 100);
|
|
52
|
-
return inputCostX100 + outputCostX100;
|
|
90
|
+
export function calculateCost(inputTokens, outputTokens, model, cacheReadTokens = 0, cacheWriteTokens = 0) {
|
|
91
|
+
const p = pricingFor(model);
|
|
92
|
+
const toX100 = (tokens, costPerM) => Math.round((tokens / 1_000_000) * costPerM * 100);
|
|
93
|
+
return (toX100(inputTokens, p.input) +
|
|
94
|
+
toX100(outputTokens, p.output) +
|
|
95
|
+
toX100(cacheReadTokens, p.cacheRead) +
|
|
96
|
+
toX100(cacheWriteTokens, p.cacheWrite));
|
|
53
97
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
98
|
+
export async function recordUsage(recordOrOwner, inputTokens, outputTokens, model) {
|
|
99
|
+
const record = typeof recordOrOwner === "string"
|
|
100
|
+
? {
|
|
101
|
+
ownerEmail: recordOrOwner,
|
|
102
|
+
inputTokens: inputTokens ?? 0,
|
|
103
|
+
outputTokens: outputTokens ?? 0,
|
|
104
|
+
model: model ?? "",
|
|
105
|
+
}
|
|
106
|
+
: recordOrOwner;
|
|
107
|
+
const { ownerEmail, inputTokens: inTok, outputTokens: outTok, cacheReadTokens = 0, cacheWriteTokens = 0, model: modelName, label, app, } = record;
|
|
108
|
+
// Skip no-op writes (e.g. a stream aborted before any tokens flowed)
|
|
109
|
+
if (!inTok && !outTok && !cacheReadTokens && !cacheWriteTokens)
|
|
110
|
+
return;
|
|
58
111
|
await ensureUsageTable();
|
|
59
112
|
const client = getDbExec();
|
|
60
|
-
const costX100 = calculateCost(
|
|
113
|
+
const costX100 = calculateCost(inTok, outTok, modelName, cacheReadTokens, cacheWriteTokens);
|
|
61
114
|
const id = Date.now() * 1000 + Math.floor(Math.random() * 1000);
|
|
115
|
+
const resolvedApp = app ?? process.env.AGENT_APP ?? "";
|
|
116
|
+
const resolvedLabel = label ?? "chat";
|
|
62
117
|
await client.execute({
|
|
63
|
-
sql: `INSERT INTO token_usage
|
|
118
|
+
sql: `INSERT INTO token_usage
|
|
119
|
+
(id, owner_email, input_tokens, output_tokens, cache_read_tokens, cache_write_tokens, cost_cents_x100, model, label, app, created_at)
|
|
120
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
|
|
64
121
|
args: [
|
|
65
122
|
id,
|
|
66
123
|
ownerEmail,
|
|
67
|
-
|
|
68
|
-
|
|
124
|
+
inTok,
|
|
125
|
+
outTok,
|
|
126
|
+
cacheReadTokens,
|
|
127
|
+
cacheWriteTokens,
|
|
69
128
|
costX100,
|
|
70
|
-
|
|
129
|
+
modelName,
|
|
130
|
+
resolvedLabel,
|
|
131
|
+
resolvedApp,
|
|
71
132
|
Date.now(),
|
|
72
133
|
],
|
|
73
134
|
});
|
|
74
135
|
}
|
|
75
|
-
/**
|
|
76
|
-
* Get total usage cost for a user in cents.
|
|
77
|
-
*/
|
|
136
|
+
/** Total cost (in cents) charged against a user, across all time. */
|
|
78
137
|
export async function getUserUsageCents(ownerEmail) {
|
|
79
138
|
await ensureUsageTable();
|
|
80
139
|
const client = getDbExec();
|
|
@@ -83,13 +142,8 @@ export async function getUserUsageCents(ownerEmail) {
|
|
|
83
142
|
args: [ownerEmail],
|
|
84
143
|
});
|
|
85
144
|
const total = Number(rows[0]?.total ?? 0);
|
|
86
|
-
// Convert from centicents to cents
|
|
87
145
|
return total / 100;
|
|
88
146
|
}
|
|
89
|
-
/**
|
|
90
|
-
* Check if a user has exceeded their usage limit.
|
|
91
|
-
* Returns { allowed: true } or { allowed: false, usageCents, limitCents }.
|
|
92
|
-
*/
|
|
93
147
|
export async function checkUsageLimit(ownerEmail, limitCents) {
|
|
94
148
|
const limit = limitCents ?? DEFAULT_USAGE_LIMIT_CENTS;
|
|
95
149
|
const usageCents = await getUserUsageCents(ownerEmail);
|
|
@@ -99,4 +153,116 @@ export async function checkUsageLimit(ownerEmail, limitCents) {
|
|
|
99
153
|
limitCents: limit,
|
|
100
154
|
};
|
|
101
155
|
}
|
|
156
|
+
const DAY_MS = 86_400_000;
|
|
157
|
+
/**
|
|
158
|
+
* Produce an aggregated spend view for the Usage admin panel.
|
|
159
|
+
* Scoped to the passed owner email; the UI always passes the session user.
|
|
160
|
+
*/
|
|
161
|
+
export async function getUsageSummary(options) {
|
|
162
|
+
await ensureUsageTable();
|
|
163
|
+
const client = getDbExec();
|
|
164
|
+
const sinceMs = options.sinceMs ?? Date.now() - 30 * DAY_MS;
|
|
165
|
+
const totalRow = await client.execute({
|
|
166
|
+
sql: `SELECT
|
|
167
|
+
COALESCE(SUM(cost_cents_x100), 0) AS cents,
|
|
168
|
+
COUNT(*) AS calls,
|
|
169
|
+
COALESCE(SUM(input_tokens), 0) AS in_tok,
|
|
170
|
+
COALESCE(SUM(output_tokens), 0) AS out_tok,
|
|
171
|
+
COALESCE(SUM(cache_read_tokens), 0) AS cr_tok,
|
|
172
|
+
COALESCE(SUM(cache_write_tokens), 0) AS cw_tok
|
|
173
|
+
FROM token_usage WHERE owner_email = ? AND created_at >= ?`,
|
|
174
|
+
args: [options.ownerEmail, sinceMs],
|
|
175
|
+
});
|
|
176
|
+
const t = (totalRow.rows[0] ?? {});
|
|
177
|
+
const bucketSql = (col) => ({
|
|
178
|
+
sql: `SELECT ${col} AS k,
|
|
179
|
+
COALESCE(SUM(cost_cents_x100), 0) AS cents,
|
|
180
|
+
COUNT(*) AS calls,
|
|
181
|
+
COALESCE(SUM(input_tokens), 0) AS in_tok,
|
|
182
|
+
COALESCE(SUM(output_tokens), 0) AS out_tok,
|
|
183
|
+
COALESCE(SUM(cache_read_tokens), 0) AS cr_tok,
|
|
184
|
+
COALESCE(SUM(cache_write_tokens), 0) AS cw_tok
|
|
185
|
+
FROM token_usage
|
|
186
|
+
WHERE owner_email = ? AND created_at >= ?
|
|
187
|
+
GROUP BY ${col}
|
|
188
|
+
ORDER BY cents DESC`,
|
|
189
|
+
args: [options.ownerEmail, sinceMs],
|
|
190
|
+
});
|
|
191
|
+
const mapBuckets = (rows) => rows.map((r) => {
|
|
192
|
+
const row = r;
|
|
193
|
+
return {
|
|
194
|
+
key: String(row.k ?? ""),
|
|
195
|
+
cents: Number(row.cents ?? 0) / 100,
|
|
196
|
+
calls: Number(row.calls ?? 0),
|
|
197
|
+
inputTokens: Number(row.in_tok ?? 0),
|
|
198
|
+
outputTokens: Number(row.out_tok ?? 0),
|
|
199
|
+
cacheReadTokens: Number(row.cr_tok ?? 0),
|
|
200
|
+
cacheWriteTokens: Number(row.cw_tok ?? 0),
|
|
201
|
+
};
|
|
202
|
+
});
|
|
203
|
+
const [byLabelR, byModelR, byAppR] = await Promise.all([
|
|
204
|
+
client.execute(bucketSql("label")),
|
|
205
|
+
client.execute(bucketSql("model")),
|
|
206
|
+
client.execute(bucketSql("app")),
|
|
207
|
+
]);
|
|
208
|
+
// By-day aggregation — done in JS so we don't depend on dialect-specific
|
|
209
|
+
// date functions (SQLite `strftime`, Postgres `to_char`). Cheap enough
|
|
210
|
+
// for a 30-day window; if this grows, swap for a dialect-aware query.
|
|
211
|
+
const dayRows = await client.execute({
|
|
212
|
+
sql: `SELECT created_at, cost_cents_x100 FROM token_usage
|
|
213
|
+
WHERE owner_email = ? AND created_at >= ?`,
|
|
214
|
+
args: [options.ownerEmail, sinceMs],
|
|
215
|
+
});
|
|
216
|
+
const dayMap = new Map();
|
|
217
|
+
for (const row of dayRows.rows) {
|
|
218
|
+
const date = new Date(Number(row.created_at)).toISOString().slice(0, 10);
|
|
219
|
+
const prev = dayMap.get(date) ?? { cents: 0, calls: 0 };
|
|
220
|
+
prev.cents += Number(row.cost_cents_x100 ?? 0);
|
|
221
|
+
prev.calls += 1;
|
|
222
|
+
dayMap.set(date, prev);
|
|
223
|
+
}
|
|
224
|
+
const byDay = [...dayMap.entries()]
|
|
225
|
+
.map(([date, v]) => ({
|
|
226
|
+
date,
|
|
227
|
+
cents: v.cents / 100,
|
|
228
|
+
calls: v.calls,
|
|
229
|
+
}))
|
|
230
|
+
.sort((a, b) => a.date.localeCompare(b.date));
|
|
231
|
+
const recentRows = await client.execute({
|
|
232
|
+
sql: `SELECT id, created_at, label, app, model,
|
|
233
|
+
input_tokens, output_tokens, cache_read_tokens, cache_write_tokens,
|
|
234
|
+
cost_cents_x100
|
|
235
|
+
FROM token_usage
|
|
236
|
+
WHERE owner_email = ?
|
|
237
|
+
ORDER BY created_at DESC
|
|
238
|
+
LIMIT 50`,
|
|
239
|
+
args: [options.ownerEmail],
|
|
240
|
+
});
|
|
241
|
+
const recent = recentRows.rows.map((row) => ({
|
|
242
|
+
id: Number(row.id),
|
|
243
|
+
createdAt: Number(row.created_at),
|
|
244
|
+
label: String(row.label ?? "chat"),
|
|
245
|
+
app: String(row.app ?? ""),
|
|
246
|
+
model: String(row.model ?? ""),
|
|
247
|
+
inputTokens: Number(row.input_tokens ?? 0),
|
|
248
|
+
outputTokens: Number(row.output_tokens ?? 0),
|
|
249
|
+
cacheReadTokens: Number(row.cache_read_tokens ?? 0),
|
|
250
|
+
cacheWriteTokens: Number(row.cache_write_tokens ?? 0),
|
|
251
|
+
cents: Number(row.cost_cents_x100 ?? 0) / 100,
|
|
252
|
+
}));
|
|
253
|
+
return {
|
|
254
|
+
totalCents: Number(t.cents ?? 0) / 100,
|
|
255
|
+
totalCalls: Number(t.calls ?? 0),
|
|
256
|
+
totalInputTokens: Number(t.in_tok ?? 0),
|
|
257
|
+
totalOutputTokens: Number(t.out_tok ?? 0),
|
|
258
|
+
totalCacheReadTokens: Number(t.cr_tok ?? 0),
|
|
259
|
+
totalCacheWriteTokens: Number(t.cw_tok ?? 0),
|
|
260
|
+
sinceMs,
|
|
261
|
+
byLabel: mapBuckets(byLabelR.rows),
|
|
262
|
+
byModel: mapBuckets(byModelR.rows),
|
|
263
|
+
byApp: mapBuckets(byAppR.rows),
|
|
264
|
+
byDay,
|
|
265
|
+
recent,
|
|
266
|
+
};
|
|
267
|
+
}
|
|
102
268
|
//# sourceMappingURL=store.js.map
|
package/dist/usage/store.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"store.js","sourceRoot":"","sources":["../../src/usage/store.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"store.js","sourceRoot":"","sources":["../../src/usage/store.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAEjE,yEAAyE;AACzE,MAAM,CAAC,MAAM,yBAAyB,GAAG,GAAG,CAAC;AAc7C,MAAM,OAAO,GAAoD;IAC/D;QACE,KAAK,EAAE,OAAO;QACd,OAAO,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,GAAG,EAAE,UAAU,EAAE,IAAI,EAAE;KACzE;IACD;QACE,KAAK,EAAE,QAAQ;QACf,OAAO,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,SAAS,EAAE,EAAE,EAAE,UAAU,EAAE,GAAG,EAAE;KACrE;IACD,2BAA2B;IAC3B;QACE,KAAK,EAAE,IAAI;QACX,OAAO,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,EAAE,EAAE,UAAU,EAAE,GAAG,EAAE;KACtE;CACF,CAAC;AAEF,SAAS,UAAU,CAAC,KAAa;IAC/B,KAAK,MAAM,KAAK,IAAI,OAAO,EAAE,CAAC;QAC5B,IAAI,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC;YAAE,OAAO,KAAK,CAAC,OAAO,CAAC;IACpD,CAAC;IACD,OAAO,OAAO,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAE,CAAC,OAAO,CAAC;AAC9C,CAAC;AAeD,IAAI,YAAuC,CAAC;AAE5C,KAAK,UAAU,gBAAgB;IAC7B,I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IAAI,CAAC,EAAE,MAAM,CAAC;IACd,8BAA8B;IAC9B,OAAO,CAAC,EAAE,GAAG,EAAE,CAAC;IAChB,iDAAiD;IACjD,KAAK,CAAC,EAAE,YAAY,CAAC;IACrB,+BAA+B;IAC/B,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,iDAAiD;IACjD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,gCAAgC;IAChC,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,kCAAkC;IAClC,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB,iDAAiD;IACjD,YAAY,CAAC,EAAE;QAAE,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,EAAE,CAAA;KAAE,CAAC;IAC1D;;;;;;;;;;;;;;OAcG;IACH,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB;;;;;;;;OAQG;IACH,WAAW,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACjD;AA6UD;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAAC,OAAO,GAAE,mBAAwB,GAAG,UAAU,CAmJ1E"}
|
package/dist/vite/client.js
CHANGED
|
@@ -353,6 +353,47 @@ function portExposer() {
|
|
|
353
353
|
},
|
|
354
354
|
};
|
|
355
355
|
}
|
|
356
|
+
/**
|
|
357
|
+
* Silence benign `read ECONNRESET` noise from Vite's dev middleware.
|
|
358
|
+
* Fires when a browser closes/reloads/navigates mid-request — the peer has
|
|
359
|
+
* already gone away, there's nothing to fix, and Vite's error middleware
|
|
360
|
+
* spams the terminal with "Internal server error: read ECONNRESET". Our H3
|
|
361
|
+
* server layer already swallows this (create-server.ts onError); this plugin
|
|
362
|
+
* does the same for Vite's own connect pipeline.
|
|
363
|
+
*/
|
|
364
|
+
function silenceConnectionResets() {
|
|
365
|
+
const isBenign = (err) => {
|
|
366
|
+
const e = err;
|
|
367
|
+
const code = e?.code || e?.cause?.code;
|
|
368
|
+
return (code === "ECONNRESET" ||
|
|
369
|
+
code === "ECONNABORTED" ||
|
|
370
|
+
code === "EPIPE" ||
|
|
371
|
+
e?.message === "aborted");
|
|
372
|
+
};
|
|
373
|
+
return {
|
|
374
|
+
name: "agent-native-silence-connection-resets",
|
|
375
|
+
apply: "serve",
|
|
376
|
+
configureServer(server) {
|
|
377
|
+
// Swallow socket-level resets so Node doesn't surface them as uncaught.
|
|
378
|
+
server.httpServer?.on("connection", (socket) => {
|
|
379
|
+
socket.on("error", (err) => {
|
|
380
|
+
if (!isBenign(err))
|
|
381
|
+
throw err;
|
|
382
|
+
});
|
|
383
|
+
});
|
|
384
|
+
// Drop Vite's "Internal server error: read ECONNRESET" log lines.
|
|
385
|
+
const origError = server.config.logger.error.bind(server.config.logger);
|
|
386
|
+
server.config.logger.error = (msg, opts) => {
|
|
387
|
+
const text = typeof msg === "string" ? msg : String(msg ?? "");
|
|
388
|
+
if ((opts?.error && isBenign(opts.error)) ||
|
|
389
|
+
/Internal server error:\s*(read ECONNRESET|aborted|EPIPE)/i.test(text)) {
|
|
390
|
+
return;
|
|
391
|
+
}
|
|
392
|
+
origError(msg, opts);
|
|
393
|
+
};
|
|
394
|
+
},
|
|
395
|
+
};
|
|
396
|
+
}
|
|
356
397
|
/**
|
|
357
398
|
* Create the client Vite config with sensible agent-native defaults.
|
|
358
399
|
* Supports two modes:
|
|
@@ -442,6 +483,7 @@ export function defineConfig(options = {}) {
|
|
|
442
483
|
autoReloadOnOptimizeDep(),
|
|
443
484
|
baseRedirectGuard(),
|
|
444
485
|
portExposer(),
|
|
486
|
+
silenceConnectionResets(),
|
|
445
487
|
rolldownInputFix(),
|
|
446
488
|
// Nitro Vite plugin for dev-mode API route serving and HMR.
|
|
447
489
|
// Disabled during build — React Router's build handles production.
|
|
@@ -469,6 +511,19 @@ export function defineConfig(options = {}) {
|
|
|
469
511
|
: {}),
|
|
470
512
|
},
|
|
471
513
|
resolve: {
|
|
514
|
+
// Dedupe React and Radix — without this, a second copy of React can get
|
|
515
|
+
// loaded from `packages/core`'s own node_modules (via pnpm symlinks),
|
|
516
|
+
// which breaks hooks-based libraries like Radix Select with "Invalid
|
|
517
|
+
// hook call" / "Cannot read properties of null (reading 'useMemo')".
|
|
518
|
+
dedupe: [
|
|
519
|
+
"react",
|
|
520
|
+
"react-dom",
|
|
521
|
+
"react-dom/client",
|
|
522
|
+
"@radix-ui/react-select",
|
|
523
|
+
"@radix-ui/react-popover",
|
|
524
|
+
"@radix-ui/react-tooltip",
|
|
525
|
+
"@radix-ui/react-dialog",
|
|
526
|
+
],
|
|
472
527
|
alias: [
|
|
473
528
|
// In monorepo dev: resolve @agent-native/core to source for HMR.
|
|
474
529
|
// Uses regex with $ anchor for exact matching to prevent
|