@kortix/ui 0.14.17 → 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/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 +2 -2
- package/dist/customize/settings/tabs/general-tab.js +5 -4
- package/dist/customize/shared/capability-library.js +19 -22
- package/dist/customize/shared/customize-tab-bar.d.ts +1 -2
- package/dist/customize/shared/customize-tab-bar.js +10 -11
- package/dist/files/project/components/drive-create-dialog.js +3 -3
- package/dist/i18n/en.d.ts +51 -4
- package/dist/i18n/en.js +66 -19
- 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/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 +4 -5
- package/dist/session/status/provisioning-failure.js +4 -5
- 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 +1 -0
- 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/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,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
|
-
}
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
/** @internal Kortix apps only. No semver: it may change in any release. */
|
|
2
|
-
import type { ProjectSession } from '@kortix/sdk';
|
|
3
|
-
/**
|
|
4
|
-
* JAY-599 / T21 — an adopted warm session must appear in the session list
|
|
5
|
-
* immediately, not seconds later when the sandbox wakes.
|
|
6
|
-
*
|
|
7
|
-
* Root cause: a warm session is hidden from the `visible` list scope by
|
|
8
|
-
* `metadata.warm` (`apps/api/src/projects/lib/session-inventory.ts`) until the
|
|
9
|
-
* marker drops. The
|
|
10
|
-
* server drops that marker at adoption time — the first `POST .../start`
|
|
11
|
-
* call, `apps/api/src/projects/routes/session-runtime.ts` — instead of waiting for the
|
|
12
|
-
* first accepted TURN, seconds later, behind the whole sandbox boot window.
|
|
13
|
-
* That closes the gap for everyone ELSE reading the list, but the adopting
|
|
14
|
-
* tab itself still has to wait for its own `invalidateQueries` refetch to
|
|
15
|
-
* round-trip. This function is the zero-latency half: insert the row the
|
|
16
|
-
* warm ensure already returned (`WarmSession.session`,
|
|
17
|
-
* `use-warm-project-session.ts`) directly into the cache the instant the send
|
|
18
|
-
* happens, so THIS tab never waits on the network at all.
|
|
19
|
-
*
|
|
20
|
-
* Idempotent and order-preserving: a session id already in the list is
|
|
21
|
-
* replaced in place (never duplicated), so a retried seed for the same id
|
|
22
|
-
* cannot create two rows. `undefined` (nothing cached yet) becomes a fresh
|
|
23
|
-
* one-row list rather than a throw — `use-new-project-session.ts` calls this
|
|
24
|
-
* from a project the sidebar may not have fetched yet (e.g. a background tab).
|
|
25
|
-
*
|
|
26
|
-
* Placed FIRST when new: a just-adopted session is the most recently active
|
|
27
|
-
* one, which is where every other creation path (the ordinary create POST)
|
|
28
|
-
* already expects to see it once the list refetches.
|
|
29
|
-
*
|
|
30
|
-
* The seeded copy is the row AS THE SERVER WILL REPORT IT once adoption
|
|
31
|
-
* lands: `metadata.warm` removed and `last_activity_at` stamped — the same
|
|
32
|
-
* two writes `/start`'s `dropWarmSessionMarkerOnAdopt` makes in one statement
|
|
33
|
-
* (`apps/api/src/projects/routes/warm-sessions.ts`). Seeding the raw
|
|
34
|
-
* create-time row instead carried `warm: true` and no activity stamp, so the
|
|
35
|
-
* sidebar's activity sort (`project-session-list-helpers.ts`) placed the
|
|
36
|
-
* just-started session at its CREATE time — the start of the user's dwell on
|
|
37
|
-
* the project home — burying it below sessions that were active more
|
|
38
|
-
* recently. `adoptedAtIso` is injected (never read from a clock here) so the
|
|
39
|
-
* transform stays pure and the caller's timestamp is the single truth.
|
|
40
|
-
*
|
|
41
|
-
* The reconcile that follows this seed no longer races the marker-drop:
|
|
42
|
-
* `use-new-project-session.ts` defers its sessions invalidate until the
|
|
43
|
-
* `/start` prefetch settles, by which point the drop is durable server-side.
|
|
44
|
-
*/
|
|
45
|
-
/**
|
|
46
|
-
* When to reconcile the sessions-list cache with the server after a create.
|
|
47
|
-
*
|
|
48
|
-
* Ordinary create: the row is visible server-side the moment the POST returns,
|
|
49
|
-
* so invalidate immediately.
|
|
50
|
-
*
|
|
51
|
-
* Warm adoption: the row only becomes visible when `/start` drops
|
|
52
|
-
* `metadata.warm`. An invalidate issued alongside the `/start` prefetch races
|
|
53
|
-
* it — when the list GET wins, the server response (row still hidden)
|
|
54
|
-
* overwrites the optimistic seed above and, with `refetchOnWindowFocus`
|
|
55
|
-
* disabled, the just-started session stays missing from the sidebar for up to
|
|
56
|
-
* the 60s open-session poll. Deferring the invalidate until the prefetch
|
|
57
|
-
* settles makes the refetch observe the drop. `started` is
|
|
58
|
-
* `prefetchSessionStart`'s return, which never rejects; the rejection arm is
|
|
59
|
-
* belt-and-braces so a future caller cannot wedge the reconcile.
|
|
60
|
-
*/
|
|
61
|
-
export declare function reconcileSessionsAfterCreate(input: {
|
|
62
|
-
adoptedWarm: boolean;
|
|
63
|
-
started: Promise<unknown>;
|
|
64
|
-
invalidate: () => void;
|
|
65
|
-
}): void;
|
|
66
|
-
export declare function seedAdoptedWarmSession(sessions: ProjectSession[] | undefined, session: ProjectSession, adoptedAtIso: string): ProjectSession[];
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* JAY-599 / T21 — an adopted warm session must appear in the session list
|
|
3
|
-
* immediately, not seconds later when the sandbox wakes.
|
|
4
|
-
*
|
|
5
|
-
* Root cause: a warm session is hidden from the `visible` list scope by
|
|
6
|
-
* `metadata.warm` (`apps/api/src/projects/lib/session-inventory.ts`) until the
|
|
7
|
-
* marker drops. The
|
|
8
|
-
* server drops that marker at adoption time — the first `POST .../start`
|
|
9
|
-
* call, `apps/api/src/projects/routes/session-runtime.ts` — instead of waiting for the
|
|
10
|
-
* first accepted TURN, seconds later, behind the whole sandbox boot window.
|
|
11
|
-
* That closes the gap for everyone ELSE reading the list, but the adopting
|
|
12
|
-
* tab itself still has to wait for its own `invalidateQueries` refetch to
|
|
13
|
-
* round-trip. This function is the zero-latency half: insert the row the
|
|
14
|
-
* warm ensure already returned (`WarmSession.session`,
|
|
15
|
-
* `use-warm-project-session.ts`) directly into the cache the instant the send
|
|
16
|
-
* happens, so THIS tab never waits on the network at all.
|
|
17
|
-
*
|
|
18
|
-
* Idempotent and order-preserving: a session id already in the list is
|
|
19
|
-
* replaced in place (never duplicated), so a retried seed for the same id
|
|
20
|
-
* cannot create two rows. `undefined` (nothing cached yet) becomes a fresh
|
|
21
|
-
* one-row list rather than a throw — `use-new-project-session.ts` calls this
|
|
22
|
-
* from a project the sidebar may not have fetched yet (e.g. a background tab).
|
|
23
|
-
*
|
|
24
|
-
* Placed FIRST when new: a just-adopted session is the most recently active
|
|
25
|
-
* one, which is where every other creation path (the ordinary create POST)
|
|
26
|
-
* already expects to see it once the list refetches.
|
|
27
|
-
*
|
|
28
|
-
* The seeded copy is the row AS THE SERVER WILL REPORT IT once adoption
|
|
29
|
-
* lands: `metadata.warm` removed and `last_activity_at` stamped — the same
|
|
30
|
-
* two writes `/start`'s `dropWarmSessionMarkerOnAdopt` makes in one statement
|
|
31
|
-
* (`apps/api/src/projects/routes/warm-sessions.ts`). Seeding the raw
|
|
32
|
-
* create-time row instead carried `warm: true` and no activity stamp, so the
|
|
33
|
-
* sidebar's activity sort (`project-session-list-helpers.ts`) placed the
|
|
34
|
-
* just-started session at its CREATE time — the start of the user's dwell on
|
|
35
|
-
* the project home — burying it below sessions that were active more
|
|
36
|
-
* recently. `adoptedAtIso` is injected (never read from a clock here) so the
|
|
37
|
-
* transform stays pure and the caller's timestamp is the single truth.
|
|
38
|
-
*
|
|
39
|
-
* The reconcile that follows this seed no longer races the marker-drop:
|
|
40
|
-
* `use-new-project-session.ts` defers its sessions invalidate until the
|
|
41
|
-
* `/start` prefetch settles, by which point the drop is durable server-side.
|
|
42
|
-
*/
|
|
43
|
-
/**
|
|
44
|
-
* When to reconcile the sessions-list cache with the server after a create.
|
|
45
|
-
*
|
|
46
|
-
* Ordinary create: the row is visible server-side the moment the POST returns,
|
|
47
|
-
* so invalidate immediately.
|
|
48
|
-
*
|
|
49
|
-
* Warm adoption: the row only becomes visible when `/start` drops
|
|
50
|
-
* `metadata.warm`. An invalidate issued alongside the `/start` prefetch races
|
|
51
|
-
* it — when the list GET wins, the server response (row still hidden)
|
|
52
|
-
* overwrites the optimistic seed above and, with `refetchOnWindowFocus`
|
|
53
|
-
* disabled, the just-started session stays missing from the sidebar for up to
|
|
54
|
-
* the 60s open-session poll. Deferring the invalidate until the prefetch
|
|
55
|
-
* settles makes the refetch observe the drop. `started` is
|
|
56
|
-
* `prefetchSessionStart`'s return, which never rejects; the rejection arm is
|
|
57
|
-
* belt-and-braces so a future caller cannot wedge the reconcile.
|
|
58
|
-
*/
|
|
59
|
-
export function reconcileSessionsAfterCreate(input) {
|
|
60
|
-
if (!input.adoptedWarm) {
|
|
61
|
-
input.invalidate();
|
|
62
|
-
return;
|
|
63
|
-
}
|
|
64
|
-
void input.started.then(input.invalidate, input.invalidate);
|
|
65
|
-
}
|
|
66
|
-
export function seedAdoptedWarmSession(sessions, session, adoptedAtIso) {
|
|
67
|
-
const { warm: _warm, ...metadata } = (session.metadata ?? {});
|
|
68
|
-
const adopted = {
|
|
69
|
-
...session,
|
|
70
|
-
metadata: { ...metadata, last_activity_at: adoptedAtIso },
|
|
71
|
-
};
|
|
72
|
-
if (!sessions)
|
|
73
|
-
return [adopted];
|
|
74
|
-
const index = sessions.findIndex((existing) => existing.session_id === adopted.session_id);
|
|
75
|
-
if (index === -1)
|
|
76
|
-
return [adopted, ...sessions];
|
|
77
|
-
const next = sessions.slice();
|
|
78
|
-
next[index] = adopted;
|
|
79
|
-
return next;
|
|
80
|
-
}
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
/** @internal Kortix apps only. No semver: it may change in any release. */
|
|
2
|
-
/**
|
|
3
|
-
* Cross-tab registry of warm-session ids this BROWSER has already taken.
|
|
4
|
-
*
|
|
5
|
-
* Why it exists: the server deliberately reuses one warm session per user per
|
|
6
|
-
* project (`apps/api/src/projects/routes/warm-sessions.ts`), so every tab the
|
|
7
|
-
* user has open on a project holds the SAME session id in its in-memory ready
|
|
8
|
-
* store (`use-warm-project-session.ts`). The moment one tab takes it for a
|
|
9
|
-
* send, every other tab's held copy silently points at a session that now has
|
|
10
|
-
* a conversation in it — and a later send from one of those tabs would land a
|
|
11
|
-
* new prompt inside that old conversation. The in-memory `takenSessionIds`
|
|
12
|
-
* defense (JAY-596/T20) cannot see across tabs; this registry is the shared
|
|
13
|
-
* half of it.
|
|
14
|
-
*
|
|
15
|
-
* localStorage is the medium because it is the only synchronous cross-tab
|
|
16
|
-
* channel: `takeWarmSessionEntry` must stay network-free and synchronous, so
|
|
17
|
-
* the staleness check has to be a sync read. The `storage` event doubles as
|
|
18
|
-
* the push channel — it fires in every OTHER tab on write, letting them drop
|
|
19
|
-
* a now-stale ready entry and replenish while the user is still present.
|
|
20
|
-
*
|
|
21
|
-
* Scope and limits: per-browser only. Two different browsers/devices of the
|
|
22
|
-
* same user can still race a take; that window is the seconds between one
|
|
23
|
-
* device's take and the server's own marker drop at `/start`, versus the
|
|
24
|
-
* minutes-to-hours a stale tab used to hold. Entries are pruned by age and
|
|
25
|
-
* count because the server never re-offers a session once its warm marker
|
|
26
|
-
* drops (~1s after a take), so old entries protect nothing.
|
|
27
|
-
*/
|
|
28
|
-
export interface WarmTakenStorage {
|
|
29
|
-
getItem(key: string): string | null;
|
|
30
|
-
setItem(key: string, value: string): void;
|
|
31
|
-
}
|
|
32
|
-
export interface WarmTakenRegistry {
|
|
33
|
-
has(sessionId: string): boolean;
|
|
34
|
-
record(sessionId: string): void;
|
|
35
|
-
}
|
|
36
|
-
export declare const WARM_TAKEN_STORAGE_KEY = "kortix:warm-session-taken:v1";
|
|
37
|
-
export declare function createWarmTakenRegistry(storage: WarmTakenStorage | null, now?: () => number): WarmTakenRegistry;
|
|
38
|
-
/**
|
|
39
|
-
* The ids a `storage` event ADDED to the registry — i.e. the takes some OTHER
|
|
40
|
-
* tab just made. Pure so the event wiring stays a one-liner and this logic is
|
|
41
|
-
* testable without a window.
|
|
42
|
-
*/
|
|
43
|
-
export declare function takenIdsAddedByStorageEvent(event: {
|
|
44
|
-
key: string | null;
|
|
45
|
-
oldValue: string | null;
|
|
46
|
-
newValue: string | null;
|
|
47
|
-
}): string[];
|
|
48
|
-
/** The app-wide registry every real caller shares. */
|
|
49
|
-
export declare const warmTakenRegistry: WarmTakenRegistry;
|
|
50
|
-
/**
|
|
51
|
-
* Test hook: drop the app-wide registry's in-memory mirror. bun runs every
|
|
52
|
-
* suite in one process, so without this a take recorded by one test leaks
|
|
53
|
-
* into the next — the same reason the warm-session store is reset in
|
|
54
|
-
* `beforeEach`. Production code never calls it.
|
|
55
|
-
*/
|
|
56
|
-
export declare function resetWarmTakenRegistry(): void;
|
|
57
|
-
/**
|
|
58
|
-
* Notify `listener` of every warm-session take made by ANOTHER tab. Returns an
|
|
59
|
-
* unsubscribe. A no-op outside a browser (SSR, tests).
|
|
60
|
-
*/
|
|
61
|
-
export declare function subscribeToExternalWarmTakes(listener: (sessionId: string) => void): () => void;
|