@tangle-network/agent-app 0.60.60 → 0.60.62

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.
@@ -0,0 +1,69 @@
1
+ /**
2
+ * Better Auth `account`-table store for first-party Tangle identity sign-in
3
+ * (`protocol: 'identity'`) on D1 / SQLite.
4
+ *
5
+ * The platform link is Better Auth's own external-identity row:
6
+ * `account(providerId = 'tangle', accountId = <platform user id>, userId)`.
7
+ * Run {@link TANGLE_IDENTITY_ACCOUNT_INDEXES_SQL} in a product migration; its
8
+ * two partial unique indexes make the link one-per-user and
9
+ * one-per-platform-user, which the write path relies on.
10
+ *
11
+ * Schema expectations are Better Auth's default SQLite model with camelCase
12
+ * columns: `user(id, name, email, emailVerified, createdAt, updatedAt)`,
13
+ * `session(id, userId, token, expiresAt, ipAddress, userAgent, createdAt,
14
+ * updatedAt)` and `account(id, userId, accountId, providerId, createdAt,
15
+ * updatedAt)`, with unix-second integer timestamps (Drizzle `mode:
16
+ * 'timestamp'`). D1 is structural: Cloudflare `D1Database` satisfies
17
+ * {@link TangleIdentityD1Like}.
18
+ */
19
+ import { type TangleIdentitySsoAccountStore } from './sso';
20
+ /** Better Auth `account.providerId` for the Tangle platform link. */
21
+ export declare const TANGLE_IDENTITY_PROVIDER_ID = "tangle";
22
+ /** Partial unique indexes the store requires on Better Auth's `account` table. */
23
+ export declare const TANGLE_IDENTITY_ACCOUNT_INDEXES_SQL: readonly ["CREATE UNIQUE INDEX IF NOT EXISTS account_tangle_platform_user ON account(accountId) WHERE providerId = 'tangle'", "CREATE UNIQUE INDEX IF NOT EXISTS account_tangle_user ON account(userId) WHERE providerId = 'tangle'"];
24
+ /** A prepared D1 statement; Cloudflare `D1PreparedStatement` satisfies it. */
25
+ export interface TangleIdentityD1Statement {
26
+ bind(...values: unknown[]): TangleIdentityD1Statement;
27
+ first<T = Record<string, unknown>>(): Promise<T | null>;
28
+ all<T = Record<string, unknown>>(): Promise<{
29
+ results: T[];
30
+ }>;
31
+ run(): Promise<unknown>;
32
+ }
33
+ /** The D1 surface the store needs. `batch` must be atomic, as D1's is. */
34
+ export interface TangleIdentityD1Like {
35
+ prepare(query: string): TangleIdentityD1Statement;
36
+ batch(statements: TangleIdentityD1Statement[]): Promise<Array<{
37
+ meta?: {
38
+ changes?: number;
39
+ };
40
+ }>>;
41
+ }
42
+ /**
43
+ * A link table the product used before this store. During migration the store
44
+ * reads it after `account` and mirrors new links into it, so a link that
45
+ * exists in either place still signs in and a rollback still finds new links.
46
+ * Remove the option once a reconcile query proves every legacy row has an
47
+ * equal `account` row.
48
+ */
49
+ export interface TangleIdentityLegacyLinkTable {
50
+ table: string;
51
+ /** Column holding the local `user.id`; must be unique. */
52
+ userIdColumn: string;
53
+ /** Column holding the platform user id; must be unique. */
54
+ platformUserIdColumn: string;
55
+ }
56
+ export interface D1TangleIdentityStoreOptions {
57
+ db: TangleIdentityD1Like;
58
+ /**
59
+ * The signed-in local user for an explicit "connect Tangle" flow. A live
60
+ * local session plus a verified platform exchange jointly authorize linking
61
+ * that user, even when its local email is unverified or differs. The host
62
+ * must prove the session started this flow (for example with a signed,
63
+ * session-bound cookie).
64
+ */
65
+ linkingUserId?: string;
66
+ legacyLinkTable?: TangleIdentityLegacyLinkTable;
67
+ }
68
+ /** Create the identity-protocol account store for one request. */
69
+ export declare function createD1TangleIdentityStore(options: D1TangleIdentityStoreOptions): TangleIdentitySsoAccountStore;
@@ -102,8 +102,8 @@ interface GatewayConsultationContext {
102
102
  /** Compose gateway admission, scoped knowledge and the maintained persisted chat route. */
103
103
  export declare function createPublicConsultation(options: PublicConsultationOptions): {
104
104
  authorizeConsumer(agent: ConsultationAgent, consumer: ConsultationConsumer): Promise<{
105
- reason?: undefined;
106
105
  allow: true;
106
+ reason?: undefined;
107
107
  code?: undefined;
108
108
  } | {
109
109
  allow: false;
@@ -121,9 +121,9 @@ export declare function createPublicConsultation(options: PublicConsultationOpti
121
121
  executionBudget?: ChatTurnExecutionLimits;
122
122
  maxOutputTokens?: number;
123
123
  }) => Promise<{
124
- start?: undefined;
125
124
  status: 'unsupported';
126
125
  reason: string;
126
+ start?: undefined;
127
127
  } | {
128
128
  reason?: undefined;
129
129
  status: 'prepared';
@@ -278,6 +278,10 @@ export interface EnsureWorkspaceSandboxOptions {
278
278
  onProgress?: (event: ProvisionEvent) => void;
279
279
  billingOwnerId?: string;
280
280
  spend?: SandboxSpendHooks;
281
+ /** Optional stage timing for the steps of an ensure (`sandbox.ensure.*`), so a
282
+ * product can see which round trip a slow acquisition spent its time in.
283
+ * Omitted, nothing is measured. */
284
+ measure?: <T>(stage: string, operation: () => Promise<T>) => Promise<T>;
281
285
  }
282
286
  /** What `/sandbox` reports once a box is provisioned, reused, or resumed. */
283
287
  export interface SandboxProvisionedObservation {
@@ -871,4 +875,5 @@ export * from './workspace-sandbox-manager';
871
875
  export * from './terminal-connection';
872
876
  export * from './prewarm';
873
877
  export * from './prewarm-claim-d1';
878
+ export * from './prewarm-route';
874
879
  export * from './foreground-single-flight';
@@ -33,6 +33,7 @@ import {
33
33
  createD1PrewarmClaimStore,
34
34
  createSandboxPrewarmer,
35
35
  createSandboxTerminalConnectionRoute,
36
+ createWorkspacePrewarmRoute,
36
37
  createWorkspaceSandboxManager,
37
38
  deferredCorpusHash,
38
39
  deleteSecret,
@@ -42,6 +43,7 @@ import {
42
43
  ensureWorkspaceSandbox,
43
44
  flattenHistory,
44
45
  getClient,
46
+ isAutomatedPrewarmRequest,
45
47
  isTerminalPromptEvent,
46
48
  mergeExtraMcp,
47
49
  mergeHistoryIntoParts,
@@ -71,7 +73,7 @@ import {
71
73
  syncSandboxMemberRemove,
72
74
  syncSandboxMemberRole,
73
75
  writeProfileFilesToBox
74
- } from "../chunk-WMCROSA4.js";
76
+ } from "../chunk-7DG6GGRN.js";
75
77
  import {
76
78
  EGRESS_PROXY_RECOVERY_PHASE,
77
79
  EGRESS_PROXY_RECOVERY_REQUIRED,
@@ -169,6 +171,7 @@ export {
169
171
  createD1PrewarmClaimStore,
170
172
  createSandboxPrewarmer,
171
173
  createSandboxTerminalConnectionRoute,
174
+ createWorkspacePrewarmRoute,
172
175
  createWorkspaceSandboxManager,
173
176
  createWorkspaceSandboxRecoveryManager,
174
177
  deferredCorpusHash,
@@ -181,6 +184,7 @@ export {
181
184
  formatSandboxProvisioningSupportDetails,
182
185
  formatSandboxProvisioningUserMessage,
183
186
  getClient,
187
+ isAutomatedPrewarmRequest,
184
188
  isEgressProxyRecoveryRequiredError,
185
189
  isSandboxApiBearerAuthFailure,
186
190
  isSandboxApiSandboxMissingFailure,
@@ -0,0 +1,100 @@
1
+ /**
2
+ * `createWorkspacePrewarmRoute`: the HTTP face of prewarm-on-open, so every
3
+ * agent-app product warms the same way. The browser half is
4
+ * `useWorkspacePrewarm` in `/web-react`: it POSTs here when a member opens a
5
+ * workspace page in a visible tab, and again when they focus the composer.
6
+ *
7
+ * WHAT THE PRODUCT SUPPLIES. Only `authorize`. It authenticates the member
8
+ * from the request exactly as the product's other routes do and returns the
9
+ * warm to run: a box resume, a profile preparation, or `createSandboxPrewarmer`
10
+ * from this subpath. The route owns everything shared: bot and prefetch
11
+ * refusal, per-key single-flight, a short success memory, timing, and the rule
12
+ * that a warm never reaches the member as an error.
13
+ *
14
+ * WHY THE WARM RUNS INSIDE THE REQUEST. A suspended box takes ~31 s to resume
15
+ * (Hospitality production, 2026-10-10), past the 30 s that Cloudflare's
16
+ * `waitUntil` grants after a response. Awaiting the warm keeps the request
17
+ * open for as long as the member's tab is, which is exactly as long as a warm
18
+ * is useful. The browser never awaits it for UI.
19
+ *
20
+ * IDEMPOTENCE. The in-process map only collapses concurrent calls within one
21
+ * isolate. Two isolates can both run the warm, so the product's warm must be
22
+ * safe to repeat: a resume of a running box is a no-op, and a creation needs a
23
+ * claim store (see `createSandboxPrewarmer`).
24
+ *
25
+ * FAILURE. A thrown warm answers 200 `{ outcome: 'failed' }` without the error
26
+ * text, which can name internal hosts. `onEvent` receives the error so the
27
+ * product can log it. The next real turn takes its normal placement path.
28
+ */
29
+ /** What the product decided for this request. */
30
+ export type WorkspacePrewarmAuthorization =
31
+ /** Not signed in, not a member, or a foreign origin: return this response. */
32
+ {
33
+ status: 'denied';
34
+ response: Response;
35
+ }
36
+ /** A signed-in member the product does not warm for (a role that cannot
37
+ * chat, a box mid-upgrade). Answers 200 so the browser stays quiet. */
38
+ | {
39
+ status: 'declined';
40
+ reason: string;
41
+ }
42
+ /**
43
+ * Run `warm` once per `key` at a time. `key` names what is warmed, such as
44
+ * the box; members who share a box share a key. `warm` may return a small
45
+ * JSON-safe report for the response and `onEvent`.
46
+ */
47
+ | {
48
+ status: 'allowed';
49
+ key: string;
50
+ warm: () => Promise<WorkspacePrewarmReport | void>;
51
+ };
52
+ export type WorkspacePrewarmReport = Record<string, string | number | boolean | null>;
53
+ export type WorkspacePrewarmOutcome =
54
+ /** This request ran the warm to completion. */
55
+ 'warmed'
56
+ /** Another request in this isolate was already running it; this one waited for it. */
57
+ | 'joined'
58
+ /** The same key warmed successfully within `recentMs`; nothing ran. */
59
+ | 'recent' | 'declined'
60
+ /** A crawler, link preview, or speculative prefetch; nothing ran. */
61
+ | 'automated' | 'failed';
62
+ export interface WorkspacePrewarmResponse {
63
+ outcome: WorkspacePrewarmOutcome;
64
+ /** Time this request spent, including any warm it ran or joined. */
65
+ ms: number;
66
+ reason?: string;
67
+ report?: WorkspacePrewarmReport;
68
+ }
69
+ export type WorkspacePrewarmEvent = {
70
+ type: 'warmed';
71
+ key: string;
72
+ ms: number;
73
+ report?: WorkspacePrewarmReport;
74
+ } | {
75
+ type: 'failed';
76
+ key: string;
77
+ ms: number;
78
+ error: string;
79
+ };
80
+ export interface CreateWorkspacePrewarmRouteOptions<Context = void> {
81
+ /** `context` is whatever the caller passed beside the request, such as a
82
+ * Hono context carrying the Worker's bindings. */
83
+ authorize(input: {
84
+ request: Request;
85
+ context: Context;
86
+ }): Promise<WorkspacePrewarmAuthorization>;
87
+ /** After a successful warm, answer `recent` for this long. Default 30 000 ms. */
88
+ recentMs?: number;
89
+ /** Observability for warms this route ran. Errors thrown here are ignored. */
90
+ onEvent?(event: WorkspacePrewarmEvent): void;
91
+ /** Clock seam for tests. */
92
+ now?(): number;
93
+ }
94
+ /** True for crawler user agents and browser speculative prefetch or prerender. */
95
+ export declare function isAutomatedPrewarmRequest(request: Request): boolean;
96
+ /**
97
+ * Build the handler once per isolate, not per request: its single-flight and
98
+ * success memory live in the returned closure.
99
+ */
100
+ export declare function createWorkspacePrewarmRoute<Context = void>(options: CreateWorkspacePrewarmRouteOptions<Context>): (request: Request, context: Context) => Promise<Response>;
@@ -313,6 +313,10 @@ export interface ChatComposerProps {
313
313
  onDictateError?: (message: string) => void;
314
314
  /** Cmd/Ctrl+L focuses the input and shows the hint. Default true. */
315
315
  focusShortcut?: boolean;
316
+ /** Called when focus enters the composer: the input or any of its controls.
317
+ * Pass `useWorkspacePrewarm().reassert` so a box that suspended while the
318
+ * tab sat open starts resuming before the member sends. */
319
+ onFocusWithin?: () => void;
316
320
  /** Float the card on a soft two-layer foreground-tinted shadow (opt-in).
317
321
  * Elevation only — radius, ring, and control layout are unchanged. */
318
322
  floating?: boolean;
@@ -329,4 +333,4 @@ export interface ChatComposerProps {
329
333
  sendTone?: 'contrast' | 'primary';
330
334
  className?: string;
331
335
  }
332
- export declare function ChatComposer({ onSend, onSendParts, onSendFailed, sendFailureMessage, onCancel, isStreaming, disabled, sendDisabled, placeholder, value, onValueChange, initialValue, seed, onSeedApplied, controls, controlsPlacement, onAttach, onAttachFolder, pendingFiles, onRemoveFile, onRetryFile, accept, onRejectFiles, dropTitle, dropDescription, contextItems, canSubmitAttachmentsOnly, attachmentsNotReadyMessage, canSubmitWhileBusy, autoFocus, minRows, maxHeight, trailing, mention, slashCommands, eligibleSkills, selectedSkillId, onSelectedSkillChange, onDictate, onDictateError, focusShortcut, floating, sendLabel, sendVariant, sendTone, className, }: ChatComposerProps): import("react").JSX.Element;
336
+ export declare function ChatComposer({ onSend, onSendParts, onSendFailed, sendFailureMessage, onCancel, isStreaming, disabled, sendDisabled, placeholder, value, onValueChange, initialValue, seed, onSeedApplied, controls, controlsPlacement, onAttach, onAttachFolder, pendingFiles, onRemoveFile, onRetryFile, accept, onRejectFiles, dropTitle, dropDescription, contextItems, canSubmitAttachmentsOnly, attachmentsNotReadyMessage, canSubmitWhileBusy, autoFocus, minRows, maxHeight, trailing, mention, slashCommands, eligibleSkills, selectedSkillId, onSelectedSkillChange, onDictate, onDictateError, focusShortcut, onFocusWithin, floating, sendLabel, sendVariant, sendTone, className, }: ChatComposerProps): import("react").JSX.Element;
@@ -8,8 +8,8 @@
8
8
  * ownership"): the panel PORTALS to `document.body` and positions in viewport
9
9
  * coordinates (`fixed`), so no host markup — a scroll rail, a `transform`, a
10
10
  * stacking context — can clip or trap it. Unlike the pickers it is CENTERED,
11
- * not trigger-anchored: a palette has no trigger, so it does not reuse
12
- * `PopoverSurface` itself, but it carries the same grammar — `bg-popover`,
11
+ * not trigger-anchored: the shared Dialog owns focus, dismissal and nested
12
+ * modal layers, while the palette carries the same grammar — `bg-popover`,
13
13
  * `border-card-edge`, `OVERLAY_SHADOW`, the stamped surface attribute.
14
14
  *
15
15
  * The keyboard model is the ARIA combobox pattern: focus stays in the input,
@@ -30,6 +30,9 @@ export interface CommandPaletteProps {
30
30
  onOpenChange?: (open: boolean) => void;
31
31
  /** Register the Cmd/Ctrl+K toggle. Default true. */
32
32
  hotkey?: boolean;
33
+ /** Stable return target when opening from a transient surface such as a menu
34
+ * item. Omit to restore the element focused before the palette opened. */
35
+ returnFocusTo?: () => HTMLElement | null;
33
36
  /** Async source is still resolving — the input stays live, the list shows
34
37
  * the loading row instead of a premature empty state. */
35
38
  loading?: boolean;
@@ -45,4 +48,4 @@ export interface CommandPaletteProps {
45
48
  /** Accessible name for the dialog. Default "Command palette". */
46
49
  label?: string;
47
50
  }
48
- export declare function CommandPalette({ items, onSelect, open: controlledOpen, onOpenChange, hotkey, loading, initialQuery, onQueryChange, placeholder, emptyMessage, label, }: CommandPaletteProps): import("react").ReactPortal | null;
51
+ export declare function CommandPalette({ items, onSelect, open: controlledOpen, onOpenChange, hotkey, returnFocusTo, loading, initialQuery, onQueryChange, placeholder, emptyMessage, label, }: CommandPaletteProps): import("react").JSX.Element;
@@ -32,6 +32,7 @@ export * from './chat-stream';
32
32
  export { TurnProgress, type TurnProgressProps } from './turn-progress';
33
33
  export * from './chat-interactions';
34
34
  export * from './chat-composer';
35
+ export * from './workspace-prewarm';
35
36
  export { getChatFundingRecovery, type ChatFundingFailure, type ChatFundingRecovery } from './turn-funding-recovery';
36
37
  export { RouteChunkBoundary, type RouteChunkBoundaryProps } from './lazy-load-boundary';
37
38
  export * from './agent-profile-editor';
@@ -103,6 +103,7 @@ import {
103
103
  recordGridFail,
104
104
  recordGridOk,
105
105
  recordGridRowLabel,
106
+ requestWorkspacePrewarm,
106
107
  resolveChatInteraction,
107
108
  resolveProvenanceStanding,
108
109
  responseErrorMessage,
@@ -126,6 +127,7 @@ import {
126
127
  useFileMentions,
127
128
  useSmoothText,
128
129
  useThinkingSeconds,
130
+ useWorkspacePrewarm,
129
131
  validateRecordGridCell,
130
132
  validateRecordGridRow,
131
133
  waterfallLayout,
@@ -137,7 +139,7 @@ import {
137
139
  withoutRecordGridCreated,
138
140
  withoutRecordGridRemoved,
139
141
  withoutRecordGridUpdate
140
- } from "../chunk-6LPQRKH7.js";
142
+ } from "../chunk-4WJREKXX.js";
141
143
  import {
142
144
  SessionHistoryPanel,
143
145
  formatSessionTimestamp,
@@ -183,7 +185,7 @@ import {
183
185
  renamePastedImages,
184
186
  useComposerAttachments,
185
187
  useDictation
186
- } from "../chunk-EQ6CGOZK.js";
188
+ } from "../chunk-GNA5I5NM.js";
187
189
  import "../chunk-L7MB2LLM.js";
188
190
  import {
189
191
  WorkspaceInitial,
@@ -481,6 +483,7 @@ export {
481
483
  recordGridOk,
482
484
  recordGridRowLabel,
483
485
  renamePastedImages,
486
+ requestWorkspacePrewarm,
484
487
  resolveChatInteraction,
485
488
  resolveProvenanceStanding,
486
489
  responseErrorMessage,
@@ -515,6 +518,7 @@ export {
515
518
  useSessionHistory,
516
519
  useSmoothText,
517
520
  useThinkingSeconds,
521
+ useWorkspacePrewarm,
518
522
  validateRecordGridCell,
519
523
  validateRecordGridRow,
520
524
  waterfallLayout,
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Prewarm on open: when a member opens a workspace page, ask the product to
3
+ * warm that workspace (resume its box, prepare its profile) so the first turn
4
+ * does not pay for it. The server half is `createWorkspacePrewarmRoute` in
5
+ * `/sandbox`.
6
+ *
7
+ * Fires only from a visible, non-prerendered document. A tab opened in the
8
+ * background fires when it first becomes visible. Requests for the same URL
9
+ * are spaced by `minIntervalMs` across every mount in the tab, so navigating
10
+ * between pages of one workspace sends one request, not one per page. Call
11
+ * `reassert()` on composer focus: a box can suspend while a tab sits open.
12
+ *
13
+ * Failures are silent by design. A warm is an optimization; the turn itself
14
+ * still places the box, so nothing here may surface to the member.
15
+ */
16
+ export interface WorkspacePrewarmRequestOptions {
17
+ /** Minimum gap between requests for the same URL in this tab. Default 60 000 ms. */
18
+ minIntervalMs?: number;
19
+ }
20
+ export interface UseWorkspacePrewarmOptions extends WorkspacePrewarmRequestOptions {
21
+ /** The product's prewarm route for this workspace. Empty disables. */
22
+ url: string | null | undefined;
23
+ /** False until the member is known to be signed in and allowed to chat. Default true. */
24
+ enabled?: boolean;
25
+ }
26
+ export interface WorkspacePrewarmHandle {
27
+ /** Ask again, subject to the same visibility and spacing rules. */
28
+ reassert(): void;
29
+ }
30
+ /**
31
+ * Send one prewarm request for `url` unless the tab is hidden, a request for it
32
+ * is in flight, or one was sent within `minIntervalMs`. Returns whether it sent.
33
+ */
34
+ export declare function requestWorkspacePrewarm(url: string, options?: WorkspacePrewarmRequestOptions): boolean;
35
+ /** Prewarm `url` when the page opens or becomes visible; `reassert` on composer focus. */
36
+ export declare function useWorkspacePrewarm(options: UseWorkspacePrewarmOptions): WorkspacePrewarmHandle;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tangle-network/agent-app",
3
- "version": "0.60.60",
3
+ "version": "0.60.62",
4
4
  "packageManager": "pnpm@11.24.0",
5
5
  "description": "Build agent applications with typed chat, tools, sandboxes, integrations, billing, and evaluation.",
6
6
  "keywords": [