@kortix/ui 0.14.16 → 0.14.19
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 +2 -2
- package/dist/_vendor/kortix-shared.js +38 -2
- package/dist/_vendor/shared/artifact-annotations.d.ts +126 -1
- package/dist/_vendor/shared/artifact-comments.d.ts +30 -1
- package/dist/_vendor/shared/channel-descriptors.d.ts +20 -1
- package/dist/_vendor/shared/channel-message.d.ts +1 -1
- package/dist/_vendor/shared/my-kortix-agent.d.ts +1 -1
- package/dist/_vendor/shared/space-slug.d.ts +3 -4
- package/dist/_vendor/shared/utils/ambiguous-write.d.ts +3 -3
- package/dist/customize/agents/agent-instructions.d.ts +8 -0
- package/dist/customize/agents/agent-instructions.js +38 -12
- package/dist/customize/agents/agent-overview.d.ts +6 -3
- package/dist/customize/agents/agent-overview.js +8 -2
- package/dist/customize/agents/agent-page-chrome.d.ts +45 -27
- package/dist/customize/agents/agent-page-chrome.js +60 -37
- package/dist/customize/agents/agent-page.js +88 -99
- package/dist/customize/agents/agent-tabs.d.ts +15 -14
- package/dist/customize/agents/agent-tabs.js +19 -16
- package/dist/customize/agents/agents-page.js +8 -6
- package/dist/customize/connectors/detail/account-info.js +1 -1
- package/dist/customize/project-settings/project-admin-sections.d.ts +6 -2
- package/dist/customize/project-settings/project-admin-sections.js +5 -3
- package/dist/customize/project-settings/project-settings-sections.js +1 -1
- package/dist/customize/sections/component/channel-access-panel.js +16 -0
- package/dist/customize/sections/component/channel-mocks.d.ts +5 -0
- package/dist/customize/sections/component/channel-mocks.js +14 -2
- package/dist/customize/sections/component/discord-channel-row.d.ts +6 -0
- package/dist/customize/sections/component/discord-channel-row.js +48 -0
- package/dist/customize/sections/gateway-access-tab.js +1 -1
- package/dist/customize/sections/view/channels-view.js +18 -1
- package/dist/customize/sections/view/git-view.js +2 -2
- package/dist/customize/sections/view/secret-delivery.js +1 -1
- package/dist/customize/sections/view/secrets-view.js +1 -1
- package/dist/customize/settings/rail.js +2 -2
- package/dist/customize/settings/tabs/experimental-tab.d.ts +2 -2
- package/dist/customize/settings/tabs/experimental-tab.js +3 -6
- package/dist/customize/settings/tabs/general-tab.js +5 -4
- package/dist/customize/shared/capability-library.js +19 -22
- package/dist/customize/shared/channels-switch-dialog.d.ts +4 -8
- package/dist/customize/shared/channels-switch-dialog.js +5 -16
- package/dist/customize/shared/customize-tab-bar.d.ts +1 -2
- package/dist/customize/shared/customize-tab-bar.js +10 -11
- package/dist/customize/shared/feature-gate-screen.js +5 -7
- package/dist/files/drives/drive-path-param.d.ts +4 -0
- package/dist/files/drives/drive-path-param.js +50 -0
- package/dist/files/index.d.ts +1 -0
- package/dist/files/index.js +1 -0
- package/dist/files/project/components/drive-create-dialog.js +3 -3
- package/dist/i18n/en.d.ts +99 -18
- package/dist/i18n/en.js +125 -44
- package/dist/i18n/ui-catalog/remaining-ui-translation-keys.generated.js +1 -1
- package/dist/internal/branding/branding-provider.d.ts +15 -4
- package/dist/internal/branding/branding-provider.js +12 -7
- package/dist/internal/connector-logo/connector-logo.js +2 -0
- package/dist/internal/connector-logo/connector-mark-files.js +1 -0
- package/dist/internal/hooks/channels/use-channels-installations.d.ts +7 -2
- package/dist/internal/hooks/channels/use-channels-installations.js +31 -1
- package/dist/internal/hooks/projects/use-new-project-session.d.ts +6 -14
- package/dist/internal/hooks/projects/use-new-project-session.js +12 -97
- package/dist/internal/hooks/use-notification-center.d.ts +11 -8
- package/dist/internal/hooks/use-notification-center.js +22 -10
- package/dist/internal/icons/discord.d.ts +9 -0
- package/dist/internal/icons/discord.js +9 -0
- package/dist/internal/layout/connect-mcp-modal.js +1 -1
- package/dist/internal/lib/browser-noise/rules/expected-states.js +1 -1
- package/dist/internal/lib/error-handler.js +1 -1
- package/dist/internal/lib/use-project-feature-flags.js +5 -3
- package/dist/markdown/doc-editor/doc-menus.d.ts +6 -0
- package/dist/markdown/doc-editor/doc-menus.js +74 -9
- package/dist/markdown/markdown-frontmatter.d.ts +0 -3
- package/dist/markdown/markdown-frontmatter.js +45 -5
- package/dist/session/actions/project-session-list-helpers.d.ts +4 -14
- package/dist/session/actions/project-session-list-helpers.js +5 -16
- package/dist/session/actions/session-label.d.ts +5 -9
- package/dist/session/actions/session-label.js +6 -10
- package/dist/session/participants/session-participants.d.ts +7 -5
- package/dist/session/participants/session-participants.js +11 -7
- package/dist/session/status/provisioning-failure.d.ts +26 -6
- package/dist/session/status/provisioning-failure.js +39 -12
- package/dist/session/thread/optimistic-turn.js +11 -2
- package/dist/session/thread/session-chat.js +73 -25
- package/dist/session/thread/transcript.d.ts +9 -0
- package/dist/session/thread/transcript.js +44 -5
- package/dist/session/tool/tools/channel-send-card.js +1 -0
- package/dist/session/turn/channel-brand.js +4 -0
- package/dist/session/turn/message-author.d.ts +13 -8
- package/dist/session/turn/message-author.js +34 -16
- package/dist/session/turn/peer-message-row.js +24 -6
- package/dist/session/turn/user-message.js +1 -1
- package/dist/session/voice/call-audio.d.ts +32 -0
- package/dist/session/voice/call-audio.js +146 -0
- package/dist/session/voice/screen-share.d.ts +24 -0
- package/dist/session/voice/screen-share.js +75 -0
- package/dist/session/voice/use-voice-call.d.ts +15 -0
- package/dist/session/voice/use-voice-call.js +220 -0
- package/dist/session/voice/voice-call-bar.d.ts +4 -0
- package/dist/session/voice/voice-call-bar.js +39 -0
- package/dist/session/voice/voice-call-state.d.ts +96 -0
- package/dist/session/voice/voice-call-state.js +103 -0
- package/dist/session/voice/voice-call-store.d.ts +12 -0
- package/dist/session/voice/voice-call-store.js +10 -0
- package/dist/session/voice/voice-call-url.d.ts +24 -0
- package/dist/session/voice/voice-call-url.js +33 -0
- package/dist/session/voice/voice-call.d.ts +15 -0
- package/dist/session/voice/voice-call.js +54 -0
- package/dist/styles.css +1 -1
- package/dist/workspace/admin/project-admin-dashboard.js +9 -4
- package/dist/workspace/layout/project-home.js +13 -14
- package/dist/workspace/sidebar/footer/project-manifest-issues-alert.d.ts +1 -1
- package/dist/workspace/sidebar/footer/project-manifest-issues-alert.js +4 -3
- package/dist/workspace/sidebar/project-session-list.js +14 -26
- package/dist/workspace/sidebar/session-brief-hover-card.d.ts +0 -3
- package/dist/workspace/sidebar/session-brief-hover-card.js +0 -3
- package/dist/workspace/sidebar/session-filter-menu.js +1 -0
- package/dist/workspace/sidebar/session-grouping.d.ts +4 -0
- package/dist/workspace/sidebar/session-grouping.js +2 -0
- package/dist/workspace/sidebar/session-source-icons.js +2 -0
- package/dist/workspace/space/space-page.js +2 -2
- package/package.json +9 -9
- package/skills/kortix-ui/SKILL.md +2 -2
- package/skills/kortix-ui/references/custom-dashboard.md +1 -1
- package/skills/kortix-ui/references/modules.md +1 -1
- package/dist/customize/agents/agent-section-rail.d.ts +0 -21
- package/dist/customize/agents/agent-section-rail.js +0 -23
- package/dist/internal/hooks/projects/use-warm-project-session.d.ts +0 -270
- package/dist/internal/hooks/projects/use-warm-project-session.js +0 -362
- package/dist/internal/hooks/projects/warm-session-seed.d.ts +0 -66
- package/dist/internal/hooks/projects/warm-session-seed.js +0 -80
- package/dist/internal/hooks/projects/warm-session-taken-registry.d.ts +0 -61
- package/dist/internal/hooks/projects/warm-session-taken-registry.js +0 -141
|
@@ -1,270 +0,0 @@
|
|
|
1
|
-
/** @internal Kortix apps only. No semver: it may change in any release. */
|
|
2
|
-
import { claimWarmProjectSession, getProjectSession, type PendingSessionPrompt, type ProjectSession, type SessionConnectorBindingsInput } from '@kortix/sdk';
|
|
3
|
-
import { type WarmTakenRegistry } from './warm-session-taken-registry.js';
|
|
4
|
-
/**
|
|
5
|
-
* Warm sessions — presence-driven.
|
|
6
|
-
*
|
|
7
|
-
* A session started from a project pays the whole sandbox boot AFTER the user
|
|
8
|
-
* presses Enter. So while a logged-in user is present on a project — a project
|
|
9
|
-
* route mounted AND the tab visible — keep one session already created for them.
|
|
10
|
-
*
|
|
11
|
-
* A warm session is NOT a species of session. It is an ORDINARY session, created
|
|
12
|
-
* by the same server path the New Session button uses, that the user has not
|
|
13
|
-
* typed into yet. The send path therefore does not "claim" anything: it navigates
|
|
14
|
-
* to the session it already has and prompts it. No claim call, no 409
|
|
15
|
-
* vocabulary, no claim PROTOCOL state — `WarmSession` caches the server row
|
|
16
|
-
* itself (JAY-599/T21) purely so the taker can seed a cache with it, not as
|
|
17
|
-
* negotiation state of any kind.
|
|
18
|
-
*
|
|
19
|
-
* CREATES at exactly three moments, no timers: on mount (or project change), on
|
|
20
|
-
* regaining visibility, and to replenish after one is used. Holding an id
|
|
21
|
-
* short-circuits all three, so refocusing a tab costs nothing, and a hidden tab
|
|
22
|
-
* never starts billed compute.
|
|
23
|
-
*
|
|
24
|
-
* ABANDON, NEVER ADAPT. A warm session is born with the project's default agent
|
|
25
|
-
* and sandbox. If the user picks something else before sending, the client drops
|
|
26
|
-
* it and the ordinary create path runs; the abandoned box is hidden and reaped
|
|
27
|
-
* like any other idle session. One wasted box, bounded — in exchange for deleting
|
|
28
|
-
* every line of compatibility matching the alternative needs.
|
|
29
|
-
*
|
|
30
|
-
* `metadata.warm` hides the row from the `visible` session list until its first
|
|
31
|
-
* prompt lands (`apps/api/src/projects/lib/session-inventory.ts`).
|
|
32
|
-
*
|
|
33
|
-
* COST. Gated by the `warm_sessions` project flag; the server enforces it (403
|
|
34
|
-
* `feature_disabled`) and `enabled` is only the client short-circuit.
|
|
35
|
-
*
|
|
36
|
-
* ARCHITECTURE RULE: the browser
|
|
37
|
-
* must never hand-roll speculative session creation. `ensureWarmProjectSession`
|
|
38
|
-
* may be referenced from THIS FILE ONLY.
|
|
39
|
-
*/
|
|
40
|
-
/**
|
|
41
|
-
* The create-time overrides a send can carry. Structurally the same object as
|
|
42
|
-
* `NewProjectSessionOpts['create']`; declared here so the warm module does not
|
|
43
|
-
* import from its own caller.
|
|
44
|
-
*/
|
|
45
|
-
export interface WarmSendCreateInput {
|
|
46
|
-
sandbox_slug?: string;
|
|
47
|
-
agent_name?: string;
|
|
48
|
-
connector_bindings?: SessionConnectorBindingsInput;
|
|
49
|
-
provider_secret_pools?: Record<string, string[]>;
|
|
50
|
-
inherit_unbound?: boolean;
|
|
51
|
-
}
|
|
52
|
-
/** What was actually created, so a send can tell whether it fits. */
|
|
53
|
-
export interface WarmSession {
|
|
54
|
-
sessionId: string;
|
|
55
|
-
/** RESOLVED, as the server stored it — never the `default` sentinel. */
|
|
56
|
-
agentName: string | null;
|
|
57
|
-
sandboxSlug: string;
|
|
58
|
-
/**
|
|
59
|
-
* The full server row `ensureWarmProjectSession` returned when this session
|
|
60
|
-
* was created. Carried so `takeWarmSessionEntry`'s caller (`use-new-project-
|
|
61
|
-
* session.ts`) can seed the sessions-list cache with it at adoption time,
|
|
62
|
-
* without a second fetch — see `warm-session-seed.ts`. Still shows
|
|
63
|
-
* `metadata.warm: true` at this point; the server only drops that once
|
|
64
|
-
* THIS take's own `/start` call lands (`apps/api/.../routes/session-runtime.ts`).
|
|
65
|
-
*/
|
|
66
|
-
session: ProjectSession;
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* Can this warm session serve this send?
|
|
70
|
-
*
|
|
71
|
-
* It was created with the project's defaults and nothing else, so a send naming a
|
|
72
|
-
* different agent or sandbox, or carrying per-session connector wiring, needs a
|
|
73
|
-
* session that does not exist yet.
|
|
74
|
-
*
|
|
75
|
-
* Both sides carry RESOLVED names — the server resolves the warm session's agent
|
|
76
|
-
* against the project manifest and the composer sends the name it displays — so
|
|
77
|
-
* they are directly comparable. An undefined override means "the project
|
|
78
|
-
* default", which is exactly what the warm session has.
|
|
79
|
-
*/
|
|
80
|
-
export declare function warmSessionFitsSend(warm: WarmSession, create: WarmSendCreateInput | undefined): boolean;
|
|
81
|
-
interface WarmSessionState {
|
|
82
|
-
/** Projects whose create POST is in flight. */
|
|
83
|
-
creating: Record<string, true>;
|
|
84
|
-
/** The created, still-unused session per project. */
|
|
85
|
-
ready: Record<string, WarmSession>;
|
|
86
|
-
/**
|
|
87
|
-
* Every session id THIS TAB has taken via `takeReady`. Defense in depth for
|
|
88
|
-
* JAY-596 / T20: the server's own warm marker only drops on the first
|
|
89
|
-
* prompt, seconds after a take, so a replenish racing that window can get
|
|
90
|
-
* the just-taken session back. `excludeSessionId` (see `createWarmSession`)
|
|
91
|
-
* stops a FIXED server from offering it; this set stops a server WITHOUT
|
|
92
|
-
* the fix (or any other race) from ever landing it back in `ready`, no
|
|
93
|
-
* matter how it got produced.
|
|
94
|
-
*/
|
|
95
|
-
takenSessionIds: Record<string, true>;
|
|
96
|
-
/** Reserve the create slot. False when one is in flight or one is ready. */
|
|
97
|
-
beginCreate: (projectId: string) => boolean;
|
|
98
|
-
/**
|
|
99
|
-
* Release the create slot, recording the session it produced — UNLESS that
|
|
100
|
-
* session id was already taken this tab, in which case it is dropped on the
|
|
101
|
-
* floor. Returns whether the session was actually filed as ready, so the
|
|
102
|
-
* caller (`createWarmSession`) knows whether to retry.
|
|
103
|
-
*/
|
|
104
|
-
settleCreate: (projectId: string, session: WarmSession | null) => boolean;
|
|
105
|
-
/** Read AND consume the ready session, so it is handed out once. */
|
|
106
|
-
takeReady: (projectId: string) => WarmSession | null;
|
|
107
|
-
/**
|
|
108
|
-
* Drop a held ready entry by SESSION id, marking it taken. Fired when the
|
|
109
|
-
* cross-tab registry reports another tab took the session this tab holds
|
|
110
|
-
* (`subscribeToExternalWarmTakes`). Returns the project that lost its
|
|
111
|
-
* entry — the caller replenishes exactly that project — or null.
|
|
112
|
-
*/
|
|
113
|
-
dropReadyBySessionId: (sessionId: string) => string | null;
|
|
114
|
-
}
|
|
115
|
-
/**
|
|
116
|
-
* Module state, not a ref: the project shell mounts hooks more than once and
|
|
117
|
-
* React Strict Mode double-invokes effects in development. All of them must
|
|
118
|
-
* share ONE in-flight create per project — same reasoning as
|
|
119
|
-
* `new-session-guard.ts`.
|
|
120
|
-
*/
|
|
121
|
-
export declare const useWarmSessionStore: import("zustand").UseBoundStore<import("zustand").StoreApi<WarmSessionState>>;
|
|
122
|
-
/**
|
|
123
|
-
* The one network call this module makes, injectable so its orchestration is
|
|
124
|
-
* unit-tested with a plain fake instead of `mock.module('@kortix/sdk', ...)`,
|
|
125
|
-
* which is process-wide in this monorepo and a hazard for sibling suites.
|
|
126
|
-
*/
|
|
127
|
-
export type WarmSessionClient = {
|
|
128
|
-
create: (projectId: string, excludeSessionId?: string) => Promise<WarmSession>;
|
|
129
|
-
};
|
|
130
|
-
export interface CreateWarmSessionOptions {
|
|
131
|
-
/** Forwarded to the client — see `ensureWarmProjectSession`'s option of the
|
|
132
|
-
* same name. Set by a take's replenish to the id it just took. */
|
|
133
|
-
excludeSessionId?: string;
|
|
134
|
-
/**
|
|
135
|
-
* Retries left after the store rejects a produced session as already-taken
|
|
136
|
-
* (see `WarmSessionState.settleCreate`). Internal — callers never set this;
|
|
137
|
-
* it bounds the loop to exactly one retry per take so a server that keeps
|
|
138
|
-
* echoing the excluded id cannot spin forever.
|
|
139
|
-
*/
|
|
140
|
-
retriesLeft?: number;
|
|
141
|
-
/** Cross-tab taken registry — injectable for tests, the shared app-wide
|
|
142
|
-
* instance otherwise. See `warm-session-taken-registry.ts`. */
|
|
143
|
-
registry?: WarmTakenRegistry;
|
|
144
|
-
}
|
|
145
|
-
/**
|
|
146
|
-
* Create this project's warm session unless it already has one.
|
|
147
|
-
*
|
|
148
|
-
* Non-blocking and failure-silent by contract: nothing about the composer waits
|
|
149
|
-
* on it, and a failure leaves the user on the ordinary create path with no
|
|
150
|
-
* visible difference.
|
|
151
|
-
*
|
|
152
|
-
* If the produced session is one this tab already took (the store's
|
|
153
|
-
* `settleCreate` refuses to file it), this retries EXACTLY ONCE — a server
|
|
154
|
-
* without the exclusion fix, or a race, can otherwise echo the same id back
|
|
155
|
-
* forever and this must not become a busy loop.
|
|
156
|
-
*/
|
|
157
|
-
export declare function createWarmSession(projectId: string, client?: WarmSessionClient, options?: CreateWarmSessionOptions): Promise<void>;
|
|
158
|
-
export interface TakeWarmSessionOptions {
|
|
159
|
-
create?: WarmSendCreateInput;
|
|
160
|
-
/**
|
|
161
|
-
* Create a replacement, so a second "New session" is instant too. Defaults to
|
|
162
|
-
* true; still subject to the tab being visible.
|
|
163
|
-
*/
|
|
164
|
-
replenish?: boolean;
|
|
165
|
-
/**
|
|
166
|
-
* The presence check for the replenish above. Injectable so tests never have
|
|
167
|
-
* to install a process-wide `document` — bun runs one process for the whole
|
|
168
|
-
* suite, and a fake global there breaks unrelated files that expect a real
|
|
169
|
-
* DOM.
|
|
170
|
-
*/
|
|
171
|
-
isPresent?: () => boolean;
|
|
172
|
-
client?: WarmSessionClient;
|
|
173
|
-
/** Cross-tab taken registry — injectable for tests, the shared app-wide
|
|
174
|
-
* instance otherwise. See `warm-session-taken-registry.ts`. */
|
|
175
|
-
registry?: WarmTakenRegistry;
|
|
176
|
-
}
|
|
177
|
-
/**
|
|
178
|
-
* Take this project's warm session for a send, or null to create normally —
|
|
179
|
-
* the FULL entry (id, agent, sandbox, and the server row itself). Synchronous
|
|
180
|
-
* and network-free — the session already exists. Null covers both "none ready",
|
|
181
|
-
* "the one we have cannot serve this send" and "another tab took it already";
|
|
182
|
-
* either way the caller falls back to the ordinary create path, which
|
|
183
|
-
* re-evaluates every gate and surfaces the same outcome the user would have
|
|
184
|
-
* seen regardless.
|
|
185
|
-
*
|
|
186
|
-
* A warm session that does not fit is CONSUMED, not kept: the user changed
|
|
187
|
-
* their mind about the agent, so it will not fit the next send either.
|
|
188
|
-
*
|
|
189
|
-
* `use-new-project-session.ts` calls this one so it can seed the sessions-list
|
|
190
|
-
* cache with `.session` at adoption time (`warm-session-seed.ts`) — see
|
|
191
|
-
* JAY-599 / T21.
|
|
192
|
-
*/
|
|
193
|
-
export declare function takeWarmSessionEntry(projectId: string, options?: TakeWarmSessionOptions): WarmSession | null;
|
|
194
|
-
/**
|
|
195
|
-
* A session this browser NAVIGATES TO is a session in use. Publish every
|
|
196
|
-
* visited session id to the cross-tab registry and drop any held warm entry
|
|
197
|
-
* that matches, returning the project that lost its hold (so the caller can
|
|
198
|
-
* replenish). This closes the adoption paths that never go through
|
|
199
|
-
* `takeWarmSessionEntry`: the manager inventory lists warm rows without a
|
|
200
|
-
* badge, and a direct URL opens one — either way the FIRST `/start` adopts it
|
|
201
|
-
* server-side while every holding tab still files it as ready. Recording ids
|
|
202
|
-
* that were never warm costs one idempotent registry write and protects
|
|
203
|
-
* nothing less: an id this browser has opened must never be a warm candidate.
|
|
204
|
-
*/
|
|
205
|
-
export declare function recordSessionNavigation(sessionId: string | null | undefined, registry?: WarmTakenRegistry): string | null;
|
|
206
|
-
/** The one session read revalidation makes, injectable for tests. */
|
|
207
|
-
export type WarmSessionRowFetch = (projectId: string, sessionId: string) => Promise<{
|
|
208
|
-
metadata?: unknown;
|
|
209
|
-
} | null>;
|
|
210
|
-
/**
|
|
211
|
-
* Re-check a HELD warm entry against the server, dropping it when its warm
|
|
212
|
-
* marker is gone — i.e. someone adopted it from a scope this browser's
|
|
213
|
-
* registry cannot see (another browser, profile, incognito window, or
|
|
214
|
-
* device; localStorage does not cross any of those). Fired on visibility
|
|
215
|
-
* regain, the moment a parked surface becomes able to send again.
|
|
216
|
-
*
|
|
217
|
-
* Fail-open on a fetch error: a network blip must not discard a good warm
|
|
218
|
-
* session. Take-safe: the drop only lands if the SAME session is still held
|
|
219
|
-
* after the fetch — a take that raced the fetch already consumed (and
|
|
220
|
-
* published) it, and its own send is protected by the take-time checks.
|
|
221
|
-
* Returns whether a stale hold was dropped, so the caller replenishes.
|
|
222
|
-
*/
|
|
223
|
-
export declare function revalidateHeldWarmSession(projectId: string, options?: {
|
|
224
|
-
registry?: WarmTakenRegistry;
|
|
225
|
-
fetchSession?: WarmSessionRowFetch;
|
|
226
|
-
}): Promise<boolean>;
|
|
227
|
-
/** Is the user actually looking at this tab right now? */
|
|
228
|
-
export declare function tabIsVisible(): boolean;
|
|
229
|
-
/**
|
|
230
|
-
* Keep one warm session ready while the user is present on this project.
|
|
231
|
-
*
|
|
232
|
-
* `enabled` carries the two reasons never to spend a box: the `warm_sessions`
|
|
233
|
-
* flag is off for the project, or the account cannot run at all.
|
|
234
|
-
*
|
|
235
|
-
* `activeSessionId` is the session the current route shows (the shell's
|
|
236
|
-
* `params.sessionId`). Navigating to a session is USING it, whatever surface
|
|
237
|
-
* navigated — see `recordSessionNavigation`.
|
|
238
|
-
*/
|
|
239
|
-
export declare function useWarmProjectSession(projectId: string | undefined, enabled: boolean, activeSessionId?: string | null): void;
|
|
240
|
-
/**
|
|
241
|
-
* Hand a TAKEN warm session its first prompt, durably, before navigating.
|
|
242
|
-
*
|
|
243
|
-
* The first prompt of a session is a server-side inbox row, never a
|
|
244
|
-
* client-side replay. The ordinary path gets that row from
|
|
245
|
-
* `create.pending_prompt` inside the create transaction; a warm session was
|
|
246
|
-
* created seconds ago with an EMPTY body, so the local `takeWarmSessionEntry`
|
|
247
|
-
* alone navigates into a session that has never heard the prompt — the "my
|
|
248
|
-
* first message disappears" bug, on the warm path. The server's claim route
|
|
249
|
-
* is the one call that does the whole hand-off in one transaction: inserts
|
|
250
|
-
* the row (`convertPendingPromptToInboxRow`, re-minted at delivery), drops the
|
|
251
|
-
* warm marker, and kicks the drain so the box answers now.
|
|
252
|
-
*
|
|
253
|
-
* Returns false when the claim was REFUSED (another tab took the session, the
|
|
254
|
-
* marker is already gone) — the caller falls back to the ordinary create,
|
|
255
|
-
* which carries the same prompt. Never throws.
|
|
256
|
-
*
|
|
257
|
-
* This is the ONE place in `apps/web` that calls the SDK's claim.
|
|
258
|
-
*/
|
|
259
|
-
export declare function primeTakenWarmSession(projectId: string, warm: WarmSession, input: {
|
|
260
|
-
pending_prompt: PendingSessionPrompt;
|
|
261
|
-
agent_name?: string;
|
|
262
|
-
sandbox_slug?: string;
|
|
263
|
-
},
|
|
264
|
-
/** Injected in tests; the SDK's claim otherwise. */
|
|
265
|
-
claim?: typeof claimWarmProjectSession,
|
|
266
|
-
/** Injected in tests; the SDK's session read otherwise. */
|
|
267
|
-
read?: typeof getProjectSession,
|
|
268
|
-
/** Injected in tests; a real timer otherwise. */
|
|
269
|
-
sleep?: (ms: number) => Promise<void>): Promise<boolean>;
|
|
270
|
-
export {};
|
|
@@ -1,362 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
import { useEffect } from 'react';
|
|
3
|
-
import { create as createStore } from 'zustand';
|
|
4
|
-
import { claimWarmProjectSession, ensureWarmProjectSession, getProjectSession, } from '@kortix/sdk';
|
|
5
|
-
import { confirmCommitted, errorCode, isAmbiguousCreateFailure } from './new-session-failure.js';
|
|
6
|
-
import { subscribeToExternalWarmTakes, warmTakenRegistry, } from './warm-session-taken-registry.js';
|
|
7
|
-
/**
|
|
8
|
-
* Can this warm session serve this send?
|
|
9
|
-
*
|
|
10
|
-
* It was created with the project's defaults and nothing else, so a send naming a
|
|
11
|
-
* different agent or sandbox, or carrying per-session connector wiring, needs a
|
|
12
|
-
* session that does not exist yet.
|
|
13
|
-
*
|
|
14
|
-
* Both sides carry RESOLVED names — the server resolves the warm session's agent
|
|
15
|
-
* against the project manifest and the composer sends the name it displays — so
|
|
16
|
-
* they are directly comparable. An undefined override means "the project
|
|
17
|
-
* default", which is exactly what the warm session has.
|
|
18
|
-
*/
|
|
19
|
-
export function warmSessionFitsSend(warm, create) {
|
|
20
|
-
if (!create)
|
|
21
|
-
return true;
|
|
22
|
-
if (create.connector_bindings !== undefined)
|
|
23
|
-
return false;
|
|
24
|
-
if (create.provider_secret_pools !== undefined)
|
|
25
|
-
return false;
|
|
26
|
-
if (create.inherit_unbound !== undefined)
|
|
27
|
-
return false;
|
|
28
|
-
if (create.agent_name !== undefined && create.agent_name !== warm.agentName)
|
|
29
|
-
return false;
|
|
30
|
-
if (create.sandbox_slug !== undefined && create.sandbox_slug !== warm.sandboxSlug)
|
|
31
|
-
return false;
|
|
32
|
-
return true;
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Module state, not a ref: the project shell mounts hooks more than once and
|
|
36
|
-
* React Strict Mode double-invokes effects in development. All of them must
|
|
37
|
-
* share ONE in-flight create per project — same reasoning as
|
|
38
|
-
* `new-session-guard.ts`.
|
|
39
|
-
*/
|
|
40
|
-
export const useWarmSessionStore = createStore((set, get) => ({
|
|
41
|
-
creating: {},
|
|
42
|
-
ready: {},
|
|
43
|
-
takenSessionIds: {},
|
|
44
|
-
beginCreate: (projectId) => {
|
|
45
|
-
const state = get();
|
|
46
|
-
if (state.creating[projectId] || state.ready[projectId])
|
|
47
|
-
return false;
|
|
48
|
-
set((current) => ({ creating: { ...current.creating, [projectId]: true } }));
|
|
49
|
-
return true;
|
|
50
|
-
},
|
|
51
|
-
settleCreate: (projectId, session) => {
|
|
52
|
-
const state = get();
|
|
53
|
-
const creating = { ...state.creating };
|
|
54
|
-
delete creating[projectId];
|
|
55
|
-
if (!session || state.takenSessionIds[session.sessionId]) {
|
|
56
|
-
set({ creating });
|
|
57
|
-
return false;
|
|
58
|
-
}
|
|
59
|
-
set({ creating, ready: { ...state.ready, [projectId]: session } });
|
|
60
|
-
return true;
|
|
61
|
-
},
|
|
62
|
-
takeReady: (projectId) => {
|
|
63
|
-
const session = get().ready[projectId];
|
|
64
|
-
if (!session)
|
|
65
|
-
return null;
|
|
66
|
-
set((state) => {
|
|
67
|
-
const ready = { ...state.ready };
|
|
68
|
-
delete ready[projectId];
|
|
69
|
-
return {
|
|
70
|
-
ready,
|
|
71
|
-
takenSessionIds: { ...state.takenSessionIds, [session.sessionId]: true },
|
|
72
|
-
};
|
|
73
|
-
});
|
|
74
|
-
return session;
|
|
75
|
-
},
|
|
76
|
-
dropReadyBySessionId: (sessionId) => {
|
|
77
|
-
const entry = Object.entries(get().ready).find(([, session]) => session.sessionId === sessionId);
|
|
78
|
-
if (!entry)
|
|
79
|
-
return null;
|
|
80
|
-
const [projectId] = entry;
|
|
81
|
-
set((state) => {
|
|
82
|
-
const ready = { ...state.ready };
|
|
83
|
-
delete ready[projectId];
|
|
84
|
-
return {
|
|
85
|
-
ready,
|
|
86
|
-
takenSessionIds: { ...state.takenSessionIds, [sessionId]: true },
|
|
87
|
-
};
|
|
88
|
-
});
|
|
89
|
-
return projectId;
|
|
90
|
-
},
|
|
91
|
-
}));
|
|
92
|
-
const defaultClient = {
|
|
93
|
-
create: async (projectId, excludeSessionId) => {
|
|
94
|
-
const { session } = await ensureWarmProjectSession(projectId, excludeSessionId ? { excludeSessionId } : undefined);
|
|
95
|
-
return {
|
|
96
|
-
sessionId: session.session_id,
|
|
97
|
-
agentName: session.agent_name,
|
|
98
|
-
sandboxSlug: typeof session.metadata?.sandbox_slug === 'string' ? session.metadata.sandbox_slug : '',
|
|
99
|
-
session,
|
|
100
|
-
};
|
|
101
|
-
},
|
|
102
|
-
};
|
|
103
|
-
/**
|
|
104
|
-
* Create this project's warm session unless it already has one.
|
|
105
|
-
*
|
|
106
|
-
* Non-blocking and failure-silent by contract: nothing about the composer waits
|
|
107
|
-
* on it, and a failure leaves the user on the ordinary create path with no
|
|
108
|
-
* visible difference.
|
|
109
|
-
*
|
|
110
|
-
* If the produced session is one this tab already took (the store's
|
|
111
|
-
* `settleCreate` refuses to file it), this retries EXACTLY ONCE — a server
|
|
112
|
-
* without the exclusion fix, or a race, can otherwise echo the same id back
|
|
113
|
-
* forever and this must not become a busy loop.
|
|
114
|
-
*/
|
|
115
|
-
export async function createWarmSession(projectId, client = defaultClient, options = {}) {
|
|
116
|
-
if (!useWarmSessionStore.getState().beginCreate(projectId))
|
|
117
|
-
return;
|
|
118
|
-
const retriesLeft = options.retriesLeft ?? 1;
|
|
119
|
-
const registry = options.registry ?? warmTakenRegistry;
|
|
120
|
-
try {
|
|
121
|
-
const session = await client.create(projectId, options.excludeSessionId);
|
|
122
|
-
// A session ANY tab of this browser already took is stale the moment it
|
|
123
|
-
// arrives — the server can echo one while its warm marker has not dropped
|
|
124
|
-
// yet. Refuse it exactly like the store refuses this tab's own takens.
|
|
125
|
-
const candidate = registry.has(session.sessionId) ? null : session;
|
|
126
|
-
const accepted = useWarmSessionStore.getState().settleCreate(projectId, candidate);
|
|
127
|
-
if (!accepted && retriesLeft > 0) {
|
|
128
|
-
void createWarmSession(projectId, client, {
|
|
129
|
-
// Exclude the id that was just refused — the ORIGINAL exclusion (if
|
|
130
|
-
// any) already failed to keep it away, so repeating it verbatim made
|
|
131
|
-
// the one retry a guaranteed second refusal.
|
|
132
|
-
excludeSessionId: session.sessionId,
|
|
133
|
-
retriesLeft: retriesLeft - 1,
|
|
134
|
-
registry,
|
|
135
|
-
});
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
catch {
|
|
139
|
-
// Invisible on purpose. A warm session is an optimization; the create path
|
|
140
|
-
// is unchanged and still the authority on every gate.
|
|
141
|
-
useWarmSessionStore.getState().settleCreate(projectId, null);
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
/**
|
|
145
|
-
* Take this project's warm session for a send, or null to create normally —
|
|
146
|
-
* the FULL entry (id, agent, sandbox, and the server row itself). Synchronous
|
|
147
|
-
* and network-free — the session already exists. Null covers both "none ready",
|
|
148
|
-
* "the one we have cannot serve this send" and "another tab took it already";
|
|
149
|
-
* either way the caller falls back to the ordinary create path, which
|
|
150
|
-
* re-evaluates every gate and surfaces the same outcome the user would have
|
|
151
|
-
* seen regardless.
|
|
152
|
-
*
|
|
153
|
-
* A warm session that does not fit is CONSUMED, not kept: the user changed
|
|
154
|
-
* their mind about the agent, so it will not fit the next send either.
|
|
155
|
-
*
|
|
156
|
-
* `use-new-project-session.ts` calls this one so it can seed the sessions-list
|
|
157
|
-
* cache with `.session` at adoption time (`warm-session-seed.ts`) — see
|
|
158
|
-
* JAY-599 / T21.
|
|
159
|
-
*/
|
|
160
|
-
export function takeWarmSessionEntry(projectId, options = {}) {
|
|
161
|
-
const warm = useWarmSessionStore.getState().takeReady(projectId);
|
|
162
|
-
if (!warm)
|
|
163
|
-
return null;
|
|
164
|
-
const registry = options.registry ?? warmTakenRegistry;
|
|
165
|
-
// Stale-held check: the server reuses ONE warm session per user, so another
|
|
166
|
-
// tab of this browser may have taken — and prompted — the exact session this
|
|
167
|
-
// tab still holds. Handing it out would land this send inside that tab's
|
|
168
|
-
// conversation. The registry is the synchronous cross-tab record of every
|
|
169
|
-
// take; a hit means fall back to the ordinary create path, which is always
|
|
170
|
-
// correct. Consumed either way (takeReady above), so it cannot come back.
|
|
171
|
-
const stale = registry.has(warm.sessionId);
|
|
172
|
-
if (!stale)
|
|
173
|
-
registry.record(warm.sessionId);
|
|
174
|
-
// Replenish, so "New session" right after this one is instant too. Only while
|
|
175
|
-
// the user is still present: a send made in a tab the user then hides must not
|
|
176
|
-
// leave a fresh billed box behind. The navigation this triggers stays on a
|
|
177
|
-
// project route, so tab visibility is the live signal here.
|
|
178
|
-
// Fire-and-forget — the caller is mid-navigation and must not wait on it.
|
|
179
|
-
//
|
|
180
|
-
// excludeSessionId: warm.sessionId — see JAY-596 / T20. Without it, the
|
|
181
|
-
// server's reuse lookup can find THIS session (its warm marker only drops on
|
|
182
|
-
// the first prompt, seconds from now) and hand it straight back.
|
|
183
|
-
if (options.replenish !== false && (options.isPresent ?? tabIsVisible)()) {
|
|
184
|
-
void createWarmSession(projectId, options.client, {
|
|
185
|
-
excludeSessionId: warm.sessionId,
|
|
186
|
-
registry,
|
|
187
|
-
});
|
|
188
|
-
}
|
|
189
|
-
if (stale)
|
|
190
|
-
return null;
|
|
191
|
-
return warmSessionFitsSend(warm, options.create) ? warm : null;
|
|
192
|
-
}
|
|
193
|
-
/**
|
|
194
|
-
* A session this browser NAVIGATES TO is a session in use. Publish every
|
|
195
|
-
* visited session id to the cross-tab registry and drop any held warm entry
|
|
196
|
-
* that matches, returning the project that lost its hold (so the caller can
|
|
197
|
-
* replenish). This closes the adoption paths that never go through
|
|
198
|
-
* `takeWarmSessionEntry`: the manager inventory lists warm rows without a
|
|
199
|
-
* badge, and a direct URL opens one — either way the FIRST `/start` adopts it
|
|
200
|
-
* server-side while every holding tab still files it as ready. Recording ids
|
|
201
|
-
* that were never warm costs one idempotent registry write and protects
|
|
202
|
-
* nothing less: an id this browser has opened must never be a warm candidate.
|
|
203
|
-
*/
|
|
204
|
-
export function recordSessionNavigation(sessionId, registry = warmTakenRegistry) {
|
|
205
|
-
if (!sessionId)
|
|
206
|
-
return null;
|
|
207
|
-
registry.record(sessionId);
|
|
208
|
-
return useWarmSessionStore.getState().dropReadyBySessionId(sessionId);
|
|
209
|
-
}
|
|
210
|
-
const defaultRowFetch = (projectId, sessionId) => getProjectSession(projectId, sessionId, { showErrors: false });
|
|
211
|
-
/**
|
|
212
|
-
* Re-check a HELD warm entry against the server, dropping it when its warm
|
|
213
|
-
* marker is gone — i.e. someone adopted it from a scope this browser's
|
|
214
|
-
* registry cannot see (another browser, profile, incognito window, or
|
|
215
|
-
* device; localStorage does not cross any of those). Fired on visibility
|
|
216
|
-
* regain, the moment a parked surface becomes able to send again.
|
|
217
|
-
*
|
|
218
|
-
* Fail-open on a fetch error: a network blip must not discard a good warm
|
|
219
|
-
* session. Take-safe: the drop only lands if the SAME session is still held
|
|
220
|
-
* after the fetch — a take that raced the fetch already consumed (and
|
|
221
|
-
* published) it, and its own send is protected by the take-time checks.
|
|
222
|
-
* Returns whether a stale hold was dropped, so the caller replenishes.
|
|
223
|
-
*/
|
|
224
|
-
export async function revalidateHeldWarmSession(projectId, options = {}) {
|
|
225
|
-
const held = useWarmSessionStore.getState().ready[projectId];
|
|
226
|
-
if (!held)
|
|
227
|
-
return false;
|
|
228
|
-
const registry = options.registry ?? warmTakenRegistry;
|
|
229
|
-
try {
|
|
230
|
-
const row = await (options.fetchSession ?? defaultRowFetch)(projectId, held.sessionId);
|
|
231
|
-
const stillWarm = !!row &&
|
|
232
|
-
!!row.metadata &&
|
|
233
|
-
typeof row.metadata === 'object' &&
|
|
234
|
-
row.metadata.warm === true;
|
|
235
|
-
if (stillWarm)
|
|
236
|
-
return false;
|
|
237
|
-
}
|
|
238
|
-
catch {
|
|
239
|
-
return false;
|
|
240
|
-
}
|
|
241
|
-
const stillHeld = useWarmSessionStore.getState().ready[projectId]?.sessionId === held.sessionId;
|
|
242
|
-
if (!stillHeld)
|
|
243
|
-
return false;
|
|
244
|
-
registry.record(held.sessionId);
|
|
245
|
-
useWarmSessionStore.getState().dropReadyBySessionId(held.sessionId);
|
|
246
|
-
return true;
|
|
247
|
-
}
|
|
248
|
-
/** Is the user actually looking at this tab right now? */
|
|
249
|
-
export function tabIsVisible() {
|
|
250
|
-
if (typeof document === 'undefined')
|
|
251
|
-
return false;
|
|
252
|
-
return document.visibilityState === 'visible';
|
|
253
|
-
}
|
|
254
|
-
/**
|
|
255
|
-
* Keep one warm session ready while the user is present on this project.
|
|
256
|
-
*
|
|
257
|
-
* `enabled` carries the two reasons never to spend a box: the `warm_sessions`
|
|
258
|
-
* flag is off for the project, or the account cannot run at all.
|
|
259
|
-
*
|
|
260
|
-
* `activeSessionId` is the session the current route shows (the shell's
|
|
261
|
-
* `params.sessionId`). Navigating to a session is USING it, whatever surface
|
|
262
|
-
* navigated — see `recordSessionNavigation`.
|
|
263
|
-
*/
|
|
264
|
-
export function useWarmProjectSession(projectId, enabled, activeSessionId) {
|
|
265
|
-
useEffect(() => {
|
|
266
|
-
if (!projectId || !enabled)
|
|
267
|
-
return;
|
|
268
|
-
const createIfPresent = () => {
|
|
269
|
-
if (!tabIsVisible())
|
|
270
|
-
return;
|
|
271
|
-
void createWarmSession(projectId);
|
|
272
|
-
};
|
|
273
|
-
// On becoming visible again, first re-check any held entry against the
|
|
274
|
-
// server (a browser scope the registry cannot see may have adopted it),
|
|
275
|
-
// THEN ensure — a dropped stale hold is replenished by the same tick.
|
|
276
|
-
const revalidateThenCreate = () => {
|
|
277
|
-
if (!tabIsVisible())
|
|
278
|
-
return;
|
|
279
|
-
void revalidateHeldWarmSession(projectId).then(() => {
|
|
280
|
-
if (tabIsVisible())
|
|
281
|
-
void createWarmSession(projectId);
|
|
282
|
-
});
|
|
283
|
-
};
|
|
284
|
-
createIfPresent();
|
|
285
|
-
document.addEventListener('visibilitychange', revalidateThenCreate);
|
|
286
|
-
// Another tab took a warm session. If it is the one THIS tab holds, the
|
|
287
|
-
// held entry now points at a session someone is prompting — drop it and,
|
|
288
|
-
// while the user is present here, replenish (excluding the taken id, which
|
|
289
|
-
// may still carry its warm marker for a second). Without this, the next
|
|
290
|
-
// send from this tab would only be saved by the take-time registry check
|
|
291
|
-
// and would lose its warm fast-path.
|
|
292
|
-
const unsubscribe = subscribeToExternalWarmTakes((takenSessionId) => {
|
|
293
|
-
const dropped = useWarmSessionStore.getState().dropReadyBySessionId(takenSessionId);
|
|
294
|
-
if (dropped && tabIsVisible()) {
|
|
295
|
-
void createWarmSession(dropped, undefined, { excludeSessionId: takenSessionId });
|
|
296
|
-
}
|
|
297
|
-
});
|
|
298
|
-
return () => {
|
|
299
|
-
document.removeEventListener('visibilitychange', revalidateThenCreate);
|
|
300
|
-
unsubscribe();
|
|
301
|
-
};
|
|
302
|
-
}, [projectId, enabled]);
|
|
303
|
-
// Publish every session this tab navigates to, and drop a matching held
|
|
304
|
-
// entry (adoption-outside-the-take: manager inventory, direct URL). The
|
|
305
|
-
// registry write propagates to sibling tabs via their storage subscription.
|
|
306
|
-
useEffect(() => {
|
|
307
|
-
if (!activeSessionId)
|
|
308
|
-
return;
|
|
309
|
-
const droppedProject = recordSessionNavigation(activeSessionId);
|
|
310
|
-
if (droppedProject && tabIsVisible()) {
|
|
311
|
-
void createWarmSession(droppedProject, undefined, { excludeSessionId: activeSessionId });
|
|
312
|
-
}
|
|
313
|
-
}, [activeSessionId]);
|
|
314
|
-
}
|
|
315
|
-
/**
|
|
316
|
-
* Hand a TAKEN warm session its first prompt, durably, before navigating.
|
|
317
|
-
*
|
|
318
|
-
* The first prompt of a session is a server-side inbox row, never a
|
|
319
|
-
* client-side replay. The ordinary path gets that row from
|
|
320
|
-
* `create.pending_prompt` inside the create transaction; a warm session was
|
|
321
|
-
* created seconds ago with an EMPTY body, so the local `takeWarmSessionEntry`
|
|
322
|
-
* alone navigates into a session that has never heard the prompt — the "my
|
|
323
|
-
* first message disappears" bug, on the warm path. The server's claim route
|
|
324
|
-
* is the one call that does the whole hand-off in one transaction: inserts
|
|
325
|
-
* the row (`convertPendingPromptToInboxRow`, re-minted at delivery), drops the
|
|
326
|
-
* warm marker, and kicks the drain so the box answers now.
|
|
327
|
-
*
|
|
328
|
-
* Returns false when the claim was REFUSED (another tab took the session, the
|
|
329
|
-
* marker is already gone) — the caller falls back to the ordinary create,
|
|
330
|
-
* which carries the same prompt. Never throws.
|
|
331
|
-
*
|
|
332
|
-
* This is the ONE place in `apps/web` that calls the SDK's claim.
|
|
333
|
-
*/
|
|
334
|
-
export async function primeTakenWarmSession(projectId, warm, input,
|
|
335
|
-
/** Injected in tests; the SDK's claim otherwise. */
|
|
336
|
-
claim = claimWarmProjectSession,
|
|
337
|
-
/** Injected in tests; the SDK's session read otherwise. */
|
|
338
|
-
read = getProjectSession,
|
|
339
|
-
/** Injected in tests; a real timer otherwise. */
|
|
340
|
-
sleep) {
|
|
341
|
-
try {
|
|
342
|
-
await claim(projectId, {
|
|
343
|
-
session_id: warm.sessionId,
|
|
344
|
-
...(input.agent_name ? { agent_name: input.agent_name } : {}),
|
|
345
|
-
...(input.sandbox_slug ? { sandbox_slug: input.sandbox_slug } : {}),
|
|
346
|
-
pending_prompt: input.pending_prompt,
|
|
347
|
-
});
|
|
348
|
-
return true;
|
|
349
|
-
}
|
|
350
|
-
catch (error) {
|
|
351
|
-
if (!isAmbiguousCreateFailure(errorCode(error)))
|
|
352
|
-
return false;
|
|
353
|
-
// A timed-out claim can still commit. The claim's CAS drops the `warm`
|
|
354
|
-
// marker in the same transaction that inserts the prompt row, so a session
|
|
355
|
-
// without the marker already holds this prompt. Answering false here sent
|
|
356
|
-
// the same prompt through a second create — two sessions, two turns.
|
|
357
|
-
return confirmCommitted(async () => {
|
|
358
|
-
const row = await read(projectId, warm.sessionId, { showErrors: false });
|
|
359
|
-
return !row?.metadata?.warm;
|
|
360
|
-
}, sleep ? { sleep } : {});
|
|
361
|
-
}
|
|
362
|
-
}
|