@kabmo-labs/kabmo 0.53.2 → 0.54.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client/index.html +1 -1
- package/dist/client/index.js +529 -518
- package/dist/client/static/js/{Body-vaa10tcd.js → Body-x5grdps8.js} +1 -1
- package/dist/client/static/js/{CsvGrid-wabx4e6w.js → CsvGrid-248v9yzf.js} +1 -1
- package/dist/client/static/js/{DocxView-22b3mhh5.js → DocxView-5we92k2h.js} +1 -1
- package/dist/client/static/js/{DrawioView-e02qhkp2.js → DrawioView-c6xmw4qq.js} +1 -1
- package/dist/client/static/js/{HtmlPreview-q7hwcf4s.js → HtmlPreview-r3qxgqg6.js} +1 -1
- package/dist/client/static/js/{ImageView-fxb60ge7.js → ImageView-cr4fea18.js} +1 -1
- package/dist/client/static/js/{LayoutWrapper-cey5agsf.js → LayoutWrapper-j12z0djx.js} +2 -2
- package/dist/client/static/js/MergeDiffView-y0we0194.js +1 -0
- package/dist/client/static/js/{Modal-e4yq7p5f.js → Modal-cqceypcn.js} +11 -11
- package/dist/client/static/js/{PdfView-pf3angsq.js → PdfView-xdgn31cm.js} +1 -1
- package/dist/client/static/js/{SessionsView-mcvhpx0b.js → SessionsView-ms6z44e2.js} +1 -1
- package/dist/client/static/js/{SheetView-5ha5vvsr.js → SheetView-peqm9vft.js} +1 -1
- package/dist/client/static/js/{SvgPreview-45wqjw0b.js → SvgPreview-rdf4wbzr.js} +1 -1
- package/dist/client/static/js/{abnfDiagram-O67JEVCF-gnf6krbs.js → abnfDiagram-O67JEVCF-48z2x5vg.js} +1 -1
- package/dist/client/static/js/{architectureDiagram-NJMV4G6O-00fd0wsg.js → architectureDiagram-NJMV4G6O-n1pr5s6j.js} +1 -1
- package/dist/client/static/js/{blockDiagram-BEXU5L5S-9c2sm96a.js → blockDiagram-BEXU5L5S-p19shaft.js} +1 -1
- package/dist/client/static/js/{c4Diagram-YGBWAQC7-pemygn0s.js → c4Diagram-YGBWAQC7-qcd46ts2.js} +1 -1
- package/dist/client/static/js/{classDiagram-v2-NBCMYWYE-h7r3sx3s.js → classDiagram-v2-NBCMYWYE-scyhe133.js} +1 -1
- package/dist/client/static/js/{cose-bilkent-JH36ORCC-krx9crwv.js → cose-bilkent-JH36ORCC-srnnj3f7.js} +1 -1
- package/dist/client/static/js/{cynefinDiagram-VND7K2PF-5rp2btew.js → cynefinDiagram-VND7K2PF-1zfrnyay.js} +1 -1
- package/dist/client/static/js/{dagre-6A5THRUB-q57cnz52.js → dagre-6A5THRUB-hepk25pz.js} +1 -1
- package/dist/client/static/js/{diagram-22UHCM2B-0bptn06k.js → diagram-22UHCM2B-wy2y0323.js} +1 -1
- package/dist/client/static/js/{diagram-3UASUU5V-60snxawz.js → diagram-3UASUU5V-j904f93p.js} +1 -1
- package/dist/client/static/js/{diagram-ATOU4E4O-bb0kewfp.js → diagram-ATOU4E4O-2mmxccm2.js} +2 -2
- package/dist/client/static/js/{diagram-CDSNMT55-3cdkns0z.js → diagram-CDSNMT55-cfhk73ty.js} +3 -3
- package/dist/client/static/js/{diagram-MLGK6HIB-03mbhzeq.js → diagram-MLGK6HIB-ryf8j6hf.js} +1 -1
- package/dist/client/static/js/{diagram-MPIPVDR6-bcvzqqf4.js → diagram-MPIPVDR6-8k5e36sd.js} +2 -2
- package/dist/client/static/js/{dockerfile-7kqkk4tz.js → dockerfile-1e7deann.js} +1 -1
- package/dist/client/static/js/{ebnfDiagram-ZINNZB2B-sg6kwnbx.js → ebnfDiagram-ZINNZB2B-5kkbbbhv.js} +1 -1
- package/dist/client/static/js/{elk-276RUBZZ-5b8v0sdv.js → elk-276RUBZZ-jqc4mzvc.js} +1 -1
- package/dist/client/static/js/{erDiagram-OPXOYQCR-xbs156j5.js → erDiagram-OPXOYQCR-kx15t6f0.js} +1 -1
- package/dist/client/static/js/flowDiagram-KWPJA3E3-dpjz82p8.js +1 -0
- package/dist/client/static/js/{ganttDiagram-FUAMR5RP-4p7pfk6c.js → ganttDiagram-FUAMR5RP-3hv8pej4.js} +1 -1
- package/dist/client/static/js/{gitGraphDiagram-X574FWY7-3xqwr9pf.js → gitGraphDiagram-X574FWY7-a4mq8vwz.js} +2 -2
- package/dist/client/static/js/{index-1regq9wd.js → index-01rdknec.js} +1 -1
- package/dist/client/static/js/{index-e2esj214.js → index-0j5ng1qc.js} +1 -1
- package/dist/client/static/js/{index-yf5a6t3p.js → index-0z7kerp1.js} +1 -1
- package/dist/client/static/js/{index-p75b7phb.js → index-1ye834yz.js} +1 -1
- package/dist/client/static/js/{index-1d8ff4t7.js → index-317v49ey.js} +2 -2
- package/dist/client/static/js/{index-x0y2c61e.js → index-3kenmzbe.js} +1 -1
- package/dist/client/static/js/{index-26a4afcr.js → index-40fdtqvw.js} +1 -1
- package/dist/client/static/js/{index-cj8v7b50.js → index-40ydm28n.js} +1 -1
- package/dist/client/static/js/{index-3bmn5cc5.js → index-51wzt3ma.js} +1 -1
- package/dist/client/static/js/{index-trrmbq0h.js → index-8hnem33f.js} +1 -1
- package/dist/client/static/js/{index-pak6t03c.js → index-937bn0d2.js} +1 -1
- package/dist/client/static/js/{index-nnhs52db.js → index-9cr6p86f.js} +1 -1
- package/dist/client/static/js/{index-rtpg4t84.js → index-9gddw5qy.js} +1 -1
- package/dist/client/static/js/{index-ryww3xxj.js → index-bf54x0w8.js} +1 -1
- package/dist/client/static/js/{index-hwq7zgqd.js → index-br27jz2t.js} +1 -1
- package/dist/client/static/js/{index-ayx3q8t9.js → index-demg0p74.js} +1 -1
- package/dist/client/static/js/{index-0btbxkxf.js → index-e2y4hkps.js} +1 -1
- package/dist/client/static/js/{index-vwxt5ss9.js → index-eb43hnd3.js} +1 -1
- package/dist/client/static/js/{index-mtjbp5ga.js → index-exyg9sna.js} +1 -1
- package/dist/client/static/js/{index-xqkcx4az.js → index-fanhvjk8.js} +1 -1
- package/dist/client/static/js/{index-ng3e6k6x.js → index-g3x4w48f.js} +1 -1
- package/dist/client/static/js/{index-c8ta3k4g.js → index-jvn2xfpt.js} +135 -135
- package/dist/client/static/js/{index-5qtnmn76.js → index-k4kwrze2.js} +1 -1
- package/dist/client/static/js/{index-cysdvwqw.js → index-kevqayd9.js} +1 -1
- package/dist/client/static/js/{index-hp3s5r3g.js → index-kvker1ps.js} +1 -1
- package/dist/client/static/js/{index-nmhwjwmt.js → index-kz5d00m5.js} +1 -1
- package/dist/client/static/js/{index-pdkt3r4r.js → index-m85c740p.js} +1 -1
- package/dist/client/static/js/{index-z7gd7nvb.js → index-n3cts2j1.js} +1 -1
- package/dist/client/static/js/{index-jf8zcg99.js → index-n4pm0hrh.js} +4 -4
- package/dist/client/static/js/{index-3amzzsdk.js → index-n5194pe6.js} +11 -11
- package/dist/client/static/js/{index-qj9tcz44.js → index-p8bta9ae.js} +1 -1
- package/dist/client/static/js/{index-45vcpqp9.js → index-pszsxhjr.js} +1 -1
- package/dist/client/static/js/{index-mgs5nscx.js → index-rtfw07hy.js} +1 -1
- package/dist/client/static/js/{index-cy6ceab8.js → index-v90zd3sq.js} +1 -1
- package/dist/client/static/js/{index-zc3snsr9.js → index-vxe4e903.js} +1 -1
- package/dist/client/static/js/{index-gzz6snng.js → index-w4dep7k6.js} +1 -1
- package/dist/client/static/js/{index-j9t5xc3y.js → index-x5c5yxhj.js} +1 -1
- package/dist/client/static/js/{index-jg6ecfc7.js → index-xhcbaaga.js} +2 -2
- package/dist/client/static/js/{infoDiagram-VRGFBTTK-c362sv3t.js → infoDiagram-VRGFBTTK-wtnqb06v.js} +1 -1
- package/dist/client/static/js/{ishikawaDiagram-OU5B5YK6-yc8ts8wj.js → ishikawaDiagram-OU5B5YK6-eta0jnvr.js} +1 -1
- package/dist/client/static/js/{journeyDiagram-ZHPQQLJL-178c75fy.js → journeyDiagram-ZHPQQLJL-4e572kkp.js} +1 -1
- package/dist/client/static/js/{kanban-definition-PNTS6WVX-w6g3n001.js → kanban-definition-PNTS6WVX-yrtnn4zy.js} +1 -1
- package/dist/client/static/js/{mermaid.core-vcdgn378.js → mermaid.core-195b0fb6.js} +3 -3
- package/dist/client/static/js/{mindmap-definition-NLK3R4M7-t9e8arca.js → mindmap-definition-NLK3R4M7-pphjnkvt.js} +1 -1
- package/dist/client/static/js/one-dark-pro-asy2qj2p.js +1 -0
- package/dist/client/static/js/one-light-fya1pbbx.js +1 -0
- package/dist/client/static/js/{pegDiagram-GJSIUBJH-nehn0x9n.js → pegDiagram-GJSIUBJH-kgffb9p3.js} +1 -1
- package/dist/client/static/js/{pieDiagram-5QR66LMP-p1t3ctd4.js → pieDiagram-5QR66LMP-efech3mm.js} +2 -2
- package/dist/client/static/js/{quadrantDiagram-O4NWA36T-614rtbfe.js → quadrantDiagram-O4NWA36T-khf9cv3t.js} +1 -1
- package/dist/client/static/js/{railroadDiagram-XR7U4H2S-2vpr6pw8.js → railroadDiagram-XR7U4H2S-ye68kdx2.js} +1 -1
- package/dist/client/static/js/{requirementDiagram-PLB6GJNP-b91s5q3p.js → requirementDiagram-PLB6GJNP-3s4smnme.js} +1 -1
- package/dist/client/static/js/{rust-jj206pb7.js → rust-tdrnaxp3.js} +1 -1
- package/dist/client/static/js/{sankeyDiagram-IPEJSGJF-4101kt9r.js → sankeyDiagram-IPEJSGJF-9pqd25mc.js} +1 -1
- package/dist/client/static/js/{sequenceDiagram-PO4LG4MO-yq0cxg8c.js → sequenceDiagram-PO4LG4MO-rka8ct43.js} +1 -1
- package/dist/client/static/js/{sizeCapture-INFHLROL-jkvq39vz.js → sizeCapture-INFHLROL-g5wkzry8.js} +1 -1
- package/dist/client/static/js/{stateDiagram-v2-GCMORJYK-y0h7w5rw.js → stateDiagram-v2-GCMORJYK-gy1zab2j.js} +1 -1
- package/dist/client/static/js/{swimlanes-2SLR337P-1y073wzx.js → swimlanes-2SLR337P-kr35nmd2.js} +1 -1
- package/dist/client/static/js/{swimlanesDiagram-TC7HE7FX-8ahz3c68.js → swimlanesDiagram-TC7HE7FX-qnhxxmjr.js} +1 -1
- package/dist/client/static/js/{timeline-definition-EJHVYXUP-yjb0g0ys.js → timeline-definition-EJHVYXUP-sg151mkc.js} +1 -1
- package/dist/client/static/js/{usecaseDiagram-POWQR4AR-8xjkxrkv.js → usecaseDiagram-POWQR4AR-f91g61p3.js} +1 -1
- package/dist/client/static/js/{vennDiagram-UO4OBE2U-18wjbwtg.js → vennDiagram-UO4OBE2U-zbhr4eqf.js} +2 -2
- package/dist/client/static/js/{wardleyDiagram-VNRHLVJA-xqrfsrwp.js → wardleyDiagram-VNRHLVJA-6302414n.js} +2 -2
- package/dist/client/static/js/{xychartDiagram-PMCCYNJV-azygghkz.js → xychartDiagram-PMCCYNJV-0a47th65.js} +2 -2
- package/package.json +1 -1
- package/src/client/App.tsx +4 -0
- package/src/client/bootstrap.d.ts +11 -0
- package/src/client/data/settings/omp-schema.json +11 -1
- package/src/client/hooks/shell/last-opened-session.test.ts +166 -0
- package/src/client/hooks/shell/last-opened-session.ts +74 -0
- package/src/client/lib/router/open-session.test.ts +8 -0
- package/src/client/lib/router/open-session.ts +9 -4
- package/src/client/main.tsx +7 -0
- package/src/server/lib/db/schema.ts +10 -0
- package/src/server/lib/sessions/last-opened-client.server.ts +86 -0
- package/src/server/lib/sessions/last-opened-client.test.ts +91 -0
- package/src/server/lib/sessions/last-opened.server.test.ts +127 -0
- package/src/server/lib/sessions/last-opened.server.ts +129 -0
- package/src/server/plugins/ssr.ts +40 -17
- package/src/server/routes/sessions/index.ts +14 -0
- package/src/server/routes/sessions/last-opened.test.ts +139 -0
- package/src/server/routes/sessions/last-opened.ts +66 -0
- package/src/shared/lib/omp/config/schema-releases.test.ts +15 -0
- package/dist/client/static/js/MergeDiffView-1z9mwf73.js +0 -1
- package/dist/client/static/js/flowDiagram-KWPJA3E3-sasgvf55.js +0 -1
- package/dist/client/static/js/one-dark-pro-17hh3q12.js +0 -1
- package/dist/client/static/js/one-light-cntgvscy.js +0 -1
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The opaque client id that keeps "last opened session" PER INSTALL.
|
|
8
|
+
*
|
|
9
|
+
* A console is one database, but it is not one device: a phone shell, a desktop
|
|
10
|
+
* shell and a browser can all point at the same server, and a single shared
|
|
11
|
+
* pointer made them overwrite each other. Cookie jars are per WebView data
|
|
12
|
+
* store, which is exactly the grain the feature wants — so a random id lives in
|
|
13
|
+
* one cookie and keys the record.
|
|
14
|
+
*
|
|
15
|
+
* The id is not a credential: it names a row in `last_opened_sessions` and
|
|
16
|
+
* nothing else. It is `HttpOnly` because no script needs to read it, and
|
|
17
|
+
* `SameSite=Lax` for the same reason the session cookie uses it — the page's own
|
|
18
|
+
* document navigations must carry it while a cross-site POST must not.
|
|
19
|
+
*
|
|
20
|
+
* The cookie lifetime is deliberately long and independent of the auth session:
|
|
21
|
+
* a device that signs in again is the same install, and "last opened" is about
|
|
22
|
+
* the device, not the login.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
import { randomUUID } from 'node:crypto';
|
|
26
|
+
import { isSecureRequest } from '@/server/lib/auth/token';
|
|
27
|
+
|
|
28
|
+
export const CLIENT_COOKIE = 'kabmo_client';
|
|
29
|
+
|
|
30
|
+
/** One year. A shell that is not opened for longer gets a fresh pointer. */
|
|
31
|
+
const CLIENT_COOKIE_TTL_SECONDS = 365 * 24 * 60 * 60;
|
|
32
|
+
|
|
33
|
+
/** Generated ids are UUIDs; the cap also bounds a forged cookie's DB key. */
|
|
34
|
+
const CLIENT_ID_PATTERN = /^[A-Za-z0-9_-]{16,64}$/;
|
|
35
|
+
|
|
36
|
+
/** Whether an untrusted cookie value is an id this server minted the shape of. */
|
|
37
|
+
export function isClientId(value: string | null | undefined): value is string {
|
|
38
|
+
return typeof value === 'string' && CLIENT_ID_PATTERN.test(value);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** The client id this request carries, or null when it has none/invalid. */
|
|
42
|
+
export function readClientId(request: Request): string | null {
|
|
43
|
+
const header = request.headers.get('cookie');
|
|
44
|
+
if (!header) return null;
|
|
45
|
+
for (const segment of header.split(';')) {
|
|
46
|
+
const index = segment.indexOf('=');
|
|
47
|
+
if (index === -1) continue;
|
|
48
|
+
if (segment.slice(0, index).trim() !== CLIENT_COOKIE) continue;
|
|
49
|
+
const raw = segment.slice(index + 1).trim();
|
|
50
|
+
if (!raw) return null;
|
|
51
|
+
let value = raw;
|
|
52
|
+
try {
|
|
53
|
+
value = decodeURIComponent(raw);
|
|
54
|
+
} catch {
|
|
55
|
+
// A malformed escape is still a value; the pattern decides.
|
|
56
|
+
}
|
|
57
|
+
return isClientId(value) ? value : null;
|
|
58
|
+
}
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** `Set-Cookie` for a client id, `Secure` only when the request came over TLS. */
|
|
63
|
+
export function clientCookieHeader(clientId: string, request: Request): string {
|
|
64
|
+
const attributes = [
|
|
65
|
+
`${CLIENT_COOKIE}=${encodeURIComponent(clientId)}`,
|
|
66
|
+
'Path=/',
|
|
67
|
+
'HttpOnly',
|
|
68
|
+
'SameSite=Lax',
|
|
69
|
+
`Max-Age=${CLIENT_COOKIE_TTL_SECONDS}`,
|
|
70
|
+
];
|
|
71
|
+
if (isSecureRequest(request)) attributes.push('Secure');
|
|
72
|
+
return attributes.join('; ');
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* The id to use for this request, and the cookie to send back when it is new.
|
|
77
|
+
*
|
|
78
|
+
* `setCookie` is null when the request already carried a valid id, so a normal
|
|
79
|
+
* navigation never rewrites a year-long cookie.
|
|
80
|
+
*/
|
|
81
|
+
export function resolveClientIdentity(request: Request): { clientId: string; setCookie: string | null } {
|
|
82
|
+
const existing = readClientId(request);
|
|
83
|
+
if (existing) return { clientId: existing, setCookie: null };
|
|
84
|
+
const clientId = randomUUID();
|
|
85
|
+
return { clientId, setCookie: clientCookieHeader(clientId, request) };
|
|
86
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The client identity behind "last opened session", and why each rule exists.
|
|
8
|
+
*
|
|
9
|
+
* A cookie is the one channel a WebView already persists per app install, so it
|
|
10
|
+
* carries an opaque id rather than a client-supplied key: a caller that could
|
|
11
|
+
* name its own id could read — or overwrite — another install's pointer. The
|
|
12
|
+
* cases below pin the parse (surrounded by other cookies, malformed escapes),
|
|
13
|
+
* the shape guard, and the one response that mints a new identity.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import { describe, expect, test } from 'bun:test';
|
|
17
|
+
import {
|
|
18
|
+
CLIENT_COOKIE,
|
|
19
|
+
clientCookieHeader,
|
|
20
|
+
isClientId,
|
|
21
|
+
readClientId,
|
|
22
|
+
resolveClientIdentity,
|
|
23
|
+
} from '@/server/lib/sessions/last-opened-client.server';
|
|
24
|
+
|
|
25
|
+
const ID = '11111111-2222-4333-8444-555555555555';
|
|
26
|
+
|
|
27
|
+
function requestWithCookie(cookie: string, url = 'http://localhost/'): Request {
|
|
28
|
+
return new Request(url, { headers: { cookie } });
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
describe('readClientId', () => {
|
|
32
|
+
test('finds the id among the other cookies the page sends', () => {
|
|
33
|
+
const request = requestWithCookie(`omp_session_7801=abc; ${CLIENT_COOKIE}=${ID}; theme=dark`);
|
|
34
|
+
expect(readClientId(request)).toBe(ID);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
test('no cookie header, or an empty value, is no identity', () => {
|
|
38
|
+
expect(readClientId(new Request('http://localhost/'))).toBeNull();
|
|
39
|
+
expect(readClientId(requestWithCookie(`${CLIENT_COOKIE}=`))).toBeNull();
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
test('a value this server would not mint is refused', () => {
|
|
43
|
+
for (const value of ['short', 'has spaces', 'a'.repeat(65), '../escape']) {
|
|
44
|
+
expect(readClientId(requestWithCookie(`${CLIENT_COOKIE}=${encodeURIComponent(value)}`))).toBeNull();
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
test('a malformed escape still answers a decodable value or null', () => {
|
|
49
|
+
expect(readClientId(requestWithCookie(`${CLIENT_COOKIE}=%E0%A4%A`))).toBeNull();
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
describe('isClientId', () => {
|
|
54
|
+
test('accepts the UUID shape it generates and length bounds the rest', () => {
|
|
55
|
+
expect(isClientId(ID)).toBe(true);
|
|
56
|
+
expect(isClientId('a'.repeat(16))).toBe(true);
|
|
57
|
+
expect(isClientId('a'.repeat(15))).toBe(false);
|
|
58
|
+
expect(isClientId('a'.repeat(65))).toBe(false);
|
|
59
|
+
expect(isClientId(undefined)).toBe(false);
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
describe('resolveClientIdentity', () => {
|
|
64
|
+
test('an existing id is reused and no cookie is rewritten', () => {
|
|
65
|
+
const identity = resolveClientIdentity(requestWithCookie(`${CLIENT_COOKIE}=${ID}`));
|
|
66
|
+
expect(identity.clientId).toBe(ID);
|
|
67
|
+
expect(identity.setCookie).toBeNull();
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
test('a missing id mints one and returns its cookie', () => {
|
|
71
|
+
const identity = resolveClientIdentity(new Request('http://localhost/'));
|
|
72
|
+
expect(isClientId(identity.clientId)).toBe(true);
|
|
73
|
+
expect(identity.setCookie).toContain(`${CLIENT_COOKIE}=${identity.clientId}`);
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
describe('clientCookieHeader', () => {
|
|
78
|
+
test('is a long-lived, script-invisible cookie scoped to the whole app', () => {
|
|
79
|
+
const header = clientCookieHeader(ID, new Request('http://localhost/'));
|
|
80
|
+
expect(header).toContain(`${CLIENT_COOKIE}=${ID}`);
|
|
81
|
+
expect(header).toContain('Path=/');
|
|
82
|
+
expect(header).toContain('HttpOnly');
|
|
83
|
+
expect(header).toContain('SameSite=Lax');
|
|
84
|
+
expect(header).toContain('Max-Age=31536000');
|
|
85
|
+
expect(header).not.toContain('Secure');
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
test('Secure rides only on a TLS request', () => {
|
|
89
|
+
expect(clientCookieHeader(ID, new Request('https://localhost/'))).toContain('Secure');
|
|
90
|
+
});
|
|
91
|
+
});
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The last-opened record: what a native shell is allowed to restore.
|
|
8
|
+
*
|
|
9
|
+
* Every case is a reason a cold start could land somewhere wrong — a pending
|
|
10
|
+
* placeholder, a path-shaped id, a session the user archived or deleted — and
|
|
11
|
+
* the assertion is always the same pair: the read refuses, AND the stale row is
|
|
12
|
+
* gone, because a record that survives its session makes every later launch pay
|
|
13
|
+
* the same failure again.
|
|
14
|
+
*
|
|
15
|
+
* The first case is the feature's whole reason for a client key: two installs
|
|
16
|
+
* pointing at one console must not share a pointer.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, test } from 'bun:test';
|
|
20
|
+
import { getDb } from '@/server/db.server';
|
|
21
|
+
import type { DbClient } from '@kabmo-labs/kabmo-db/client';
|
|
22
|
+
import { isolateDb, releaseDb } from '@/test-support/isolated-db';
|
|
23
|
+
import {
|
|
24
|
+
clearLastOpenedSession,
|
|
25
|
+
lastOpenedSession,
|
|
26
|
+
readLastOpenedSessionId,
|
|
27
|
+
recordLastOpenedSession,
|
|
28
|
+
} from '@/server/lib/sessions/last-opened.server';
|
|
29
|
+
|
|
30
|
+
const SESSION_ID = '42';
|
|
31
|
+
const CLIENT = '11111111-2222-4333-8444-555555555555';
|
|
32
|
+
const OTHER_CLIENT = '99999999-8888-4777-8666-555555555555';
|
|
33
|
+
let db: DbClient;
|
|
34
|
+
let priorMock: string | undefined;
|
|
35
|
+
|
|
36
|
+
beforeAll(() => {
|
|
37
|
+
priorMock = Bun.env.MOCK;
|
|
38
|
+
Bun.env.MOCK = 'true';
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
beforeEach(async () => {
|
|
42
|
+
await isolateDb();
|
|
43
|
+
db = await getDb();
|
|
44
|
+
// A mock session outside the seeded demo rows, so nothing else can answer
|
|
45
|
+
// for it.
|
|
46
|
+
await db.run("INSERT OR IGNORE INTO workspace_folders (id, name) VALUES (7, 'test')");
|
|
47
|
+
await db.run('INSERT INTO sessions (id, folder_id, title) VALUES (?, 7, ?)', [SESSION_ID, 'Probe']);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
afterEach(async () => {
|
|
51
|
+
await releaseDb();
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
afterAll(() => {
|
|
55
|
+
if (priorMock === undefined) delete Bun.env.MOCK;
|
|
56
|
+
else Bun.env.MOCK = priorMock;
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
describe('lastOpenedSession', () => {
|
|
60
|
+
test('no record yet means no session to restore', async () => {
|
|
61
|
+
expect(await lastOpenedSession(CLIENT)).toBeNull();
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
test('a recorded session that still exists is restored', async () => {
|
|
65
|
+
expect(await recordLastOpenedSession(CLIENT, SESSION_ID)).toBe(true);
|
|
66
|
+
expect(await readLastOpenedSessionId(CLIENT)).toBe(SESSION_ID);
|
|
67
|
+
expect(await lastOpenedSession(CLIENT)).toBe(SESSION_ID);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
test('two clients keep separate pointers at one console', async () => {
|
|
71
|
+
await recordLastOpenedSession(CLIENT, SESSION_ID);
|
|
72
|
+
|
|
73
|
+
// The second install never opened anything, so it restores the landing even
|
|
74
|
+
// though the first install has a record.
|
|
75
|
+
expect(await lastOpenedSession(OTHER_CLIENT)).toBeNull();
|
|
76
|
+
expect(await readLastOpenedSessionId(OTHER_CLIENT)).toBeNull();
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
test('an archived session is refused and its record cleared', async () => {
|
|
80
|
+
await recordLastOpenedSession(CLIENT, SESSION_ID);
|
|
81
|
+
await db.run('INSERT OR IGNORE INTO archived_sessions (session_id) VALUES (?)', [SESSION_ID]);
|
|
82
|
+
|
|
83
|
+
expect(await lastOpenedSession(CLIENT)).toBeNull();
|
|
84
|
+
expect(await readLastOpenedSessionId(CLIENT)).toBeNull();
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
test('a tombstoned session is refused and its record cleared', async () => {
|
|
88
|
+
await recordLastOpenedSession(CLIENT, SESSION_ID);
|
|
89
|
+
await db.run('INSERT OR IGNORE INTO deleted_sessions (session_id) VALUES (?)', [SESSION_ID]);
|
|
90
|
+
|
|
91
|
+
expect(await lastOpenedSession(CLIENT)).toBeNull();
|
|
92
|
+
expect(await readLastOpenedSessionId(CLIENT)).toBeNull();
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
test('an id that no longer exists is refused and its record cleared', async () => {
|
|
96
|
+
await recordLastOpenedSession(CLIENT, SESSION_ID);
|
|
97
|
+
await db.run('DELETE FROM sessions WHERE id = ?', [SESSION_ID]);
|
|
98
|
+
|
|
99
|
+
expect(await lastOpenedSession(CLIENT)).toBeNull();
|
|
100
|
+
expect(await readLastOpenedSessionId(CLIENT)).toBeNull();
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
test('clearing leaves the next launch on the empty workspace', async () => {
|
|
104
|
+
await recordLastOpenedSession(CLIENT, SESSION_ID);
|
|
105
|
+
await clearLastOpenedSession(CLIENT);
|
|
106
|
+
expect(await lastOpenedSession(CLIENT)).toBeNull();
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
describe('recordLastOpenedSession', () => {
|
|
111
|
+
test('a pending chat is not a session to reopen', async () => {
|
|
112
|
+
expect(await recordLastOpenedSession(CLIENT, 'new-1761000000000')).toBe(false);
|
|
113
|
+
expect(await recordLastOpenedSession(CLIENT, '__new__01a0ff3d-0000-7000-8000-000000000000')).toBe(false);
|
|
114
|
+
expect(await readLastOpenedSessionId(CLIENT)).toBeNull();
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
test('a value that is not one path segment is refused', async () => {
|
|
118
|
+
for (const id of ['', '.', '..', 'a/b', 'a\\b']) {
|
|
119
|
+
expect(await recordLastOpenedSession(CLIENT, id)).toBe(false);
|
|
120
|
+
}
|
|
121
|
+
expect(await readLastOpenedSessionId(CLIENT)).toBeNull();
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
test('a request with no client id records nothing', async () => {
|
|
125
|
+
expect(await recordLastOpenedSession('', SESSION_ID)).toBe(false);
|
|
126
|
+
});
|
|
127
|
+
});
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The session a native shell resumes on a cold start — PER CLIENT.
|
|
8
|
+
*
|
|
9
|
+
* The shells load the console's origin with no query, and the console used to
|
|
10
|
+
* answer that with its empty workspace. "The session I had open" is a fact the
|
|
11
|
+
* URL cannot carry across a relaunch — the shell stores no session id of its
|
|
12
|
+
* own — so the server keeps it.
|
|
13
|
+
*
|
|
14
|
+
* The grain is the CLIENT, not the server. A console is one database but not
|
|
15
|
+
* one device: the phone shell, the desktop shell and a browser tab can all
|
|
16
|
+
* point at the same instance, and a single shared row made each of them
|
|
17
|
+
* overwrite the others (open a chat on the desktop, and the phone restored it on
|
|
18
|
+
* its next launch). `client_id` comes from the `kabmo_client` cookie
|
|
19
|
+
* (`last-opened-client.server.ts`), whose jar is per WebView data store — the
|
|
20
|
+
* same boundary the user sees as "this app".
|
|
21
|
+
*
|
|
22
|
+
* ## What is recorded
|
|
23
|
+
*
|
|
24
|
+
* Every session a shell's URL selects. A browser records too (its cookie names
|
|
25
|
+
* its own row), but only a shell restores: the record is the fact a relaunch
|
|
26
|
+
* needs, not a browser navigation rule.
|
|
27
|
+
*
|
|
28
|
+
* ## What is NOT recorded
|
|
29
|
+
*
|
|
30
|
+
* Pending ids (`new-…`, `__new__…`). They name a chat that has not been spawned
|
|
31
|
+
* and may never be; restoring one would relaunch into a placeholder that no
|
|
32
|
+
* longer exists. The spawn adoption writes the real id through the same path,
|
|
33
|
+
* so the open is not lost — only deferred until it is a real session.
|
|
34
|
+
*
|
|
35
|
+
* ## Why the record is validated on read
|
|
36
|
+
*
|
|
37
|
+
* A shell restores before anyone can press anything, so a stale id is a launch
|
|
38
|
+
* into a 404. The read therefore answers `null` — and clears the row — for an
|
|
39
|
+
* id that is deleted, archived, or no longer present. Already-deleted sessions
|
|
40
|
+
* also lose their record at delete time; this check is the backstop for the
|
|
41
|
+
* paths that remove a session without going through that route (an omp
|
|
42
|
+
* transcript removed by hand, another instance, a restored backup).
|
|
43
|
+
*/
|
|
44
|
+
|
|
45
|
+
import { isMockMode } from '@kabmo-labs/kabmo-runtime-flags';
|
|
46
|
+
import { isSinglePathSegment } from '@kabmo-labs/kabmo-paths/path-segment';
|
|
47
|
+
import { getDb } from '@/server/db.server';
|
|
48
|
+
import { isSessionArchived, sessionExists } from '@/server/lib/sessions/resolve.server';
|
|
49
|
+
|
|
50
|
+
/** The stored id for one client, or null when there is none. */
|
|
51
|
+
export async function readLastOpenedSessionId(clientId: string): Promise<string | null> {
|
|
52
|
+
if (!clientId) return null;
|
|
53
|
+
const db = await getDb();
|
|
54
|
+
const row = await db.get<{ session_id?: string }>(
|
|
55
|
+
'SELECT session_id FROM last_opened_sessions WHERE client_id = ?',
|
|
56
|
+
[clientId],
|
|
57
|
+
);
|
|
58
|
+
const value = row?.session_id?.trim();
|
|
59
|
+
return value ? value : null;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Persist `sessionId` as this client's last opened session.
|
|
64
|
+
*
|
|
65
|
+
* Returns false for an id that is not a recordable session: a placeholder, a
|
|
66
|
+
* value that is not one path segment, or a no-op rewrite of the current row. A
|
|
67
|
+
* caller reports the refusal rather than pretending the write happened.
|
|
68
|
+
*/
|
|
69
|
+
export async function recordLastOpenedSession(clientId: string, sessionId: string): Promise<boolean> {
|
|
70
|
+
if (!clientId) return false;
|
|
71
|
+
if (!isSinglePathSegment(sessionId)) return false;
|
|
72
|
+
// A pending chat (`new-…`, `__new__…`) has no session to reopen yet; the
|
|
73
|
+
// spawn adoption sends the real id through this same call.
|
|
74
|
+
if (sessionId.startsWith('new-') || sessionId.startsWith('__new__')) return false;
|
|
75
|
+
if ((await readLastOpenedSessionId(clientId)) === sessionId) return true;
|
|
76
|
+
|
|
77
|
+
const db = await getDb();
|
|
78
|
+
await db.run(
|
|
79
|
+
`INSERT OR REPLACE INTO last_opened_sessions (client_id, session_id, updated_at)
|
|
80
|
+
VALUES (?, ?, CURRENT_TIMESTAMP)`,
|
|
81
|
+
[clientId, sessionId],
|
|
82
|
+
);
|
|
83
|
+
return true;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** Drop this client's record, so its next cold start lands on the empty workspace. */
|
|
87
|
+
export async function clearLastOpenedSession(clientId: string): Promise<void> {
|
|
88
|
+
if (!clientId) return;
|
|
89
|
+
const db = await getDb();
|
|
90
|
+
await db.run('DELETE FROM last_opened_sessions WHERE client_id = ?', [clientId]);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Whether a session id can still be opened: present, not archived, not
|
|
95
|
+
* tombstoned. Mock rows live in `sessions`; a real session is live, recorded in
|
|
96
|
+
* `harness_sessions`, or has a transcript on disk.
|
|
97
|
+
*/
|
|
98
|
+
async function sessionCanOpen(sessionId: string): Promise<boolean> {
|
|
99
|
+
const db = await getDb();
|
|
100
|
+
const deleted = await db.get(
|
|
101
|
+
'SELECT 1 AS present FROM deleted_sessions WHERE session_id = ?',
|
|
102
|
+
[sessionId],
|
|
103
|
+
);
|
|
104
|
+
if (deleted) return false;
|
|
105
|
+
if (await isSessionArchived(sessionId)) return false;
|
|
106
|
+
|
|
107
|
+
if (isMockMode()) {
|
|
108
|
+
const row = await db.get('SELECT 1 AS present FROM sessions WHERE CAST(id AS TEXT) = ?', [
|
|
109
|
+
sessionId,
|
|
110
|
+
]);
|
|
111
|
+
return row != null;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
return sessionExists(sessionId);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* The session this client should restore, or null.
|
|
119
|
+
*
|
|
120
|
+
* A stale record is DELETED, not merely skipped: every later launch would
|
|
121
|
+
* otherwise repeat the same check for a session that can never come back.
|
|
122
|
+
*/
|
|
123
|
+
export async function lastOpenedSession(clientId: string): Promise<string | null> {
|
|
124
|
+
const sessionId = await readLastOpenedSessionId(clientId);
|
|
125
|
+
if (!sessionId) return null;
|
|
126
|
+
if (await sessionCanOpen(sessionId)) return sessionId;
|
|
127
|
+
await clearLastOpenedSession(clientId);
|
|
128
|
+
return null;
|
|
129
|
+
}
|
|
@@ -31,6 +31,8 @@ import { windowChromeColor } from '@/shared/lib/theme/chrome';
|
|
|
31
31
|
import { THEME_CSS_ROUTE, serveThemeCss } from '@/server/lib/assets/theme-css.server';
|
|
32
32
|
import { THEME_CSS_LINK_ATTRIBUTE } from '@/shared/lib/theme/css';
|
|
33
33
|
import { isAndroidDevice, shellVersion } from '@/shared/lib/updates/shell-ua';
|
|
34
|
+
import { lastOpenedSession } from '@/server/lib/sessions/last-opened.server';
|
|
35
|
+
import { resolveClientIdentity } from '@/server/lib/sessions/last-opened-client.server';
|
|
34
36
|
|
|
35
37
|
/** HTML-escape a string for interpolation into the failure page's `<pre>`. */
|
|
36
38
|
function escapeHtmlText(value: string): string {
|
|
@@ -223,6 +225,21 @@ export const ssrRoutes = new Elysia({ name: 'ssr' }).get('*', async ({ request }
|
|
|
223
225
|
const androidVersion = shellVersion(userAgent, 'android');
|
|
224
226
|
const iosVersion = shellVersion(userAgent, 'ios');
|
|
225
227
|
const isAndroid = isAndroidDevice(userAgent);
|
|
228
|
+
// The session THIS install would restore, resolved BEFORE the page exists so
|
|
229
|
+
// the client can select it in its first render. The id is per WebView/app
|
|
230
|
+
// cookie jar, so a phone and a desktop never overwrite each other. Validated
|
|
231
|
+
// here rather than by the page: a stale id must not become a launch into a
|
|
232
|
+
// 404. Skipped for an unauthenticated request — the client shows the login
|
|
233
|
+
// screen and has no workspace to restore into.
|
|
234
|
+
const clientIdentity = resolveClientIdentity(request);
|
|
235
|
+
const lastOpenedSessionId = authenticated
|
|
236
|
+
? await lastOpenedSession(clientIdentity.clientId).catch((error: unknown) => {
|
|
237
|
+
// The record is what makes a relaunch resume; failing to read it must
|
|
238
|
+
// leave the landing, never take the whole document down.
|
|
239
|
+
console.warn('[ssr] last-opened session read failed:', error);
|
|
240
|
+
return null;
|
|
241
|
+
})
|
|
242
|
+
: null;
|
|
226
243
|
|
|
227
244
|
const rendered = await renderShell();
|
|
228
245
|
if (!rendered.ok) return shellUnavailableResponse(rendered.reason);
|
|
@@ -234,7 +251,7 @@ export const ssrRoutes = new Elysia({ name: 'ssr' }).get('*', async ({ request }
|
|
|
234
251
|
// questions: "this browser has a session" versus "there is a session to have".
|
|
235
252
|
// A Kabmo running open answers `authenticated: true` for every visitor, so
|
|
236
253
|
// the navbar cannot use it to decide whether a sign-out control applies.
|
|
237
|
-
const bootstrap = JSON.stringify({ initialIsMobile, shellVersion: androidVersion, iosShellVersion: iosVersion, isAndroid, authenticated, authEnabled: isAuthEnabled(), production: !DEV_ASSETS_ENABLED, appSettings: publishedSettings }).replace(/</g, '\\u003c');
|
|
254
|
+
const bootstrap = JSON.stringify({ initialIsMobile, shellVersion: androidVersion, iosShellVersion: iosVersion, isAndroid, authenticated, authEnabled: isAuthEnabled(), production: !DEV_ASSETS_ENABLED, lastOpenedSessionId, appSettings: publishedSettings }).replace(/</g, '\\u003c');
|
|
238
255
|
// The template's own `<meta name="theme-color">` is REWRITTEN, not joined by
|
|
239
256
|
// a second tag: with both present Chrome reads the first one, so an appended
|
|
240
257
|
// tag would leave a dark theme painting light browser chrome.
|
|
@@ -269,23 +286,29 @@ export const ssrRoutes = new Elysia({ name: 'ssr' }).get('*', async ({ request }
|
|
|
269
286
|
// bundled copy (which no route can vary) is replaced by the themed route.
|
|
270
287
|
const shellHtml = rewriteManifestLink(served);
|
|
271
288
|
|
|
289
|
+
const document = new Response(
|
|
290
|
+
applyShellDocumentFacts(shellHtml, {
|
|
291
|
+
palette: theme,
|
|
292
|
+
// The presentation styles are read from the same blob as the palette,
|
|
293
|
+
// so the FIRST frame is already the material, the hairline set and the
|
|
294
|
+
// paint the user chose: without this a glass install paints one opaque
|
|
295
|
+
// frame and swaps, and a borderless one paints every separator first.
|
|
296
|
+
surfaceStyle: readSettingsBlob(settings)[SURFACE_STYLE_SETTING_KEY],
|
|
297
|
+
borderStyle: readSettingsBlob(settings)[BORDER_STYLE_SETTING_KEY],
|
|
298
|
+
iconStyle: readSettingsBlob(settings)[ICON_STYLE_SETTING_KEY],
|
|
299
|
+
chromeColor: chrome,
|
|
300
|
+
})
|
|
301
|
+
.replace('<!--app-head-->', firstFrame + themeLink + fontLink)
|
|
302
|
+
.replace(SHELL_MARKER, `<script>window.__OMP_BOOTSTRAP__=${bootstrap}</script>`),
|
|
303
|
+
{ headers: HTML_HEADERS },
|
|
304
|
+
);
|
|
305
|
+
// The FIRST document a shell/webview ever loads is where its client id is
|
|
306
|
+
// minted. Every later request (the recorder's POST included) carries it, so
|
|
307
|
+
// the last-opened row belongs to this install and not to the server.
|
|
308
|
+
if (clientIdentity.setCookie) document.headers.append('set-cookie', clientIdentity.setCookie);
|
|
309
|
+
|
|
272
310
|
return maybeCompress(
|
|
273
|
-
|
|
274
|
-
applyShellDocumentFacts(shellHtml, {
|
|
275
|
-
palette: theme,
|
|
276
|
-
// The presentation styles are read from the same blob as the palette,
|
|
277
|
-
// so the FIRST frame is already the material, the hairline set and the
|
|
278
|
-
// paint the user chose: without this a glass install paints one opaque
|
|
279
|
-
// frame and swaps, and a borderless one paints every separator first.
|
|
280
|
-
surfaceStyle: readSettingsBlob(settings)[SURFACE_STYLE_SETTING_KEY],
|
|
281
|
-
borderStyle: readSettingsBlob(settings)[BORDER_STYLE_SETTING_KEY],
|
|
282
|
-
iconStyle: readSettingsBlob(settings)[ICON_STYLE_SETTING_KEY],
|
|
283
|
-
chromeColor: chrome,
|
|
284
|
-
})
|
|
285
|
-
.replace('<!--app-head-->', firstFrame + themeLink + fontLink)
|
|
286
|
-
.replace(SHELL_MARKER, `<script>window.__OMP_BOOTSTRAP__=${bootstrap}</script>`),
|
|
287
|
-
{ headers: HTML_HEADERS },
|
|
288
|
-
),
|
|
311
|
+
document,
|
|
289
312
|
// 24 KB of markup the browser can never store (`no-store`), so every
|
|
290
313
|
// navigation pays for it again — compressed, it is about a fifth of that.
|
|
291
314
|
// `maybeCompress` adds the `Vary` this response needs for the same reason
|
|
@@ -24,6 +24,10 @@ import { serveSessionImage } from '@/server/routes/sessions/local-image';
|
|
|
24
24
|
import { exportSessionMarkdown } from '@/server/routes/sessions/export';
|
|
25
25
|
import { getSessionMcp, probeSessionMcp, setSessionMcp } from '@/server/routes/sessions/mcp';
|
|
26
26
|
import { getSessionChangeDiff, getSessionChanges, getSessionChangeStats } from '@/server/routes/sessions/changes';
|
|
27
|
+
import {
|
|
28
|
+
getLastOpenedSession,
|
|
29
|
+
markSessionOpened,
|
|
30
|
+
} from '@/server/routes/sessions/last-opened';
|
|
27
31
|
|
|
28
32
|
export const sessionsBindings: HandlerBinding[] = [
|
|
29
33
|
...bindingsFor(sessionsList, '/api/sessions/list'),
|
|
@@ -37,6 +41,10 @@ export const sessionsBindings: HandlerBinding[] = [
|
|
|
37
41
|
// The archive batch is static too, and must be registered before the
|
|
38
42
|
// `:sessionId` routes for the same reason as batch-delete.
|
|
39
43
|
{ method: 'POST', path: '/api/sessions/batch-archive', handler: batchArchiveSessions },
|
|
44
|
+
// The static segment must be registered BEFORE the `:sessionId` folder
|
|
45
|
+
// loader: Elysia matches in registration order, and a parameter route winning
|
|
46
|
+
// would answer this path as a session named "last-opened".
|
|
47
|
+
{ method: 'GET', path: '/api/sessions/last-opened', handler: getLastOpenedSession },
|
|
40
48
|
...bindingsFor(sessionsFolder, '/api/sessions/:sessionId'),
|
|
41
49
|
// The tree around one session. Both are static suffixes under the same
|
|
42
50
|
// `:sessionId` position, whose name must stay `sessionId` — Elysia requires
|
|
@@ -82,6 +90,12 @@ export const sessionsBindings: HandlerBinding[] = [
|
|
|
82
90
|
...actionBindings(renameSession, '/api/sessions/:sessionId/rename'),
|
|
83
91
|
...actionBindings(renameWithAi, '/api/sessions/:sessionId/rename-with-ai'),
|
|
84
92
|
...actionBindings(putSessionState, '/api/sessions/:sessionId/state', getSessionState),
|
|
93
|
+
// What a native shell restores on its next launch. POST-only: the write is a
|
|
94
|
+
// side effect of opening, and a GET on the path is the ported route shape's
|
|
95
|
+
// 405 rather than a 404 that hides its existence.
|
|
96
|
+
...bindingsFor({ action: markSessionOpened }, '/api/sessions/:sessionId/opened', {
|
|
97
|
+
mutating: ['POST'],
|
|
98
|
+
}),
|
|
85
99
|
{ method: 'GET', path: '/api/sessions/:sessionId/modes', handler: getSessionModes },
|
|
86
100
|
...actionBindings(markSeen, '/api/sessions/:sessionId/stream-seen'),
|
|
87
101
|
{ method: 'GET', path: '/api/sessions/:sessionId/subagents', handler: listSubagents },
|