@sixb/server 0.2.1 → 0.2.3
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 +3 -3
- package/dist/artifacts/frame.d.ts.map +1 -1
- package/dist/auth/scope.d.ts +3 -0
- package/dist/auth/scope.d.ts.map +1 -1
- package/dist/auth/shared-access.d.ts +23 -0
- package/dist/auth/shared-access.d.ts.map +1 -1
- package/dist/connectors/http.d.ts +6 -1
- package/dist/connectors/http.d.ts.map +1 -1
- package/dist/index.js +2876 -667
- package/dist/index.js.map +43 -36
- package/dist/live/awareness.d.ts +48 -0
- package/dist/live/awareness.d.ts.map +1 -0
- package/dist/live/room.d.ts +198 -0
- package/dist/live/room.d.ts.map +1 -0
- package/dist/live/rooms.d.ts +67 -0
- package/dist/live/rooms.d.ts.map +1 -0
- package/dist/registerRoutes.d.ts.map +1 -1
- package/dist/routes/actions.d.ts +3 -3
- package/dist/routes/agent-approvals.d.ts +21 -11
- package/dist/routes/agent-approvals.d.ts.map +1 -1
- package/dist/routes/agent-children.d.ts +4 -4
- package/dist/routes/agent-computers.d.ts +146 -1
- package/dist/routes/agent-computers.d.ts.map +1 -1
- package/dist/routes/agent-runners.d.ts.map +1 -1
- package/dist/routes/agents.d.ts +152 -60
- package/dist/routes/agents.d.ts.map +1 -1
- package/dist/routes/artifact-frames.d.ts +2 -1
- package/dist/routes/artifact-frames.d.ts.map +1 -1
- package/dist/routes/artifacts.d.ts +1713 -178
- package/dist/routes/artifacts.d.ts.map +1 -1
- package/dist/routes/auth.d.ts +21 -21
- package/dist/routes/connector-connection-runs.d.ts +124 -5
- package/dist/routes/connector-connection-runs.d.ts.map +1 -1
- package/dist/routes/connector-connections.d.ts +9 -1
- package/dist/routes/connector-connections.d.ts.map +1 -1
- package/dist/routes/datasets.d.ts +5 -5
- package/dist/routes/events.d.ts +4 -4
- package/dist/routes/lake.d.ts +91 -0
- package/dist/routes/lake.d.ts.map +1 -0
- package/dist/routes/links.d.ts +6 -6
- package/dist/routes/logs.d.ts +2 -2
- package/dist/routes/model-generations.d.ts +2 -2
- package/dist/routes/objects.d.ts +6 -6
- package/dist/routes/objects.d.ts.map +1 -1
- package/dist/routes/observed-agent-threads.d.ts +21 -11
- package/dist/routes/observed-agent-threads.d.ts.map +1 -1
- package/dist/routes/ontology.d.ts +6 -6
- package/dist/routes/pipelines.d.ts +13 -9
- package/dist/routes/pipelines.d.ts.map +1 -1
- package/dist/routes/projections.d.ts +27 -27
- package/dist/routes/share-grants.d.ts +9 -9
- package/dist/routes/shared-access.d.ts +57 -2
- package/dist/routes/shared-access.d.ts.map +1 -1
- package/dist/routes/status.d.ts +11 -15
- package/dist/routes/status.d.ts.map +1 -1
- package/dist/routes/syncs.d.ts +9 -6
- package/dist/routes/syncs.d.ts.map +1 -1
- package/dist/routes/telemetry.d.ts +7 -7
- package/dist/routes/webhooks.d.ts.map +1 -1
- package/dist/routes/workflows.d.ts +14 -14
- package/dist/routes/ws/artifacts.d.ts +57 -0
- package/dist/routes/ws/artifacts.d.ts.map +1 -0
- package/dist/routes/ws/events.d.ts +8 -7
- package/dist/routes/ws/events.d.ts.map +1 -1
- package/dist/routes/ws/index.d.ts +2 -1
- package/dist/routes/ws/index.d.ts.map +1 -1
- package/dist/routes/ws/logs.d.ts +10 -10
- package/dist/routes/ws/shared-sockets.d.ts +52 -0
- package/dist/routes/ws/shared-sockets.d.ts.map +1 -0
- package/dist/schemas/actions.d.ts +7 -7
- package/dist/schemas/activity.d.ts +16 -16
- package/dist/schemas/agent-approvals.d.ts +27 -27
- package/dist/schemas/agents.d.ts +642 -196
- package/dist/schemas/agents.d.ts.map +1 -1
- package/dist/schemas/ai-accounting.d.ts +41 -41
- package/dist/schemas/ai-accounting.d.ts.map +1 -1
- package/dist/schemas/artifacts.d.ts +2106 -127
- package/dist/schemas/artifacts.d.ts.map +1 -1
- package/dist/schemas/auth.d.ts +63 -63
- package/dist/schemas/connectors.d.ts +180 -20
- package/dist/schemas/connectors.d.ts.map +1 -1
- package/dist/schemas/datasets.d.ts +44 -44
- package/dist/schemas/event-payloads.d.ts +2 -2
- package/dist/schemas/events.d.ts +26 -26
- package/dist/schemas/events.d.ts.map +1 -1
- package/dist/schemas/files.d.ts +12 -0
- package/dist/schemas/files.d.ts.map +1 -1
- package/dist/schemas/lake.d.ts +251 -0
- package/dist/schemas/lake.d.ts.map +1 -0
- package/dist/schemas/lineage.d.ts +56 -56
- package/dist/schemas/logs.d.ts +18 -18
- package/dist/schemas/models.d.ts +4 -4
- package/dist/schemas/objects.d.ts.map +1 -1
- package/dist/schemas/ontology.d.ts +14 -14
- package/dist/schemas/pipelines.d.ts +86 -64
- package/dist/schemas/pipelines.d.ts.map +1 -1
- package/dist/schemas/projections.d.ts +160 -160
- package/dist/schemas/projections.d.ts.map +1 -1
- package/dist/schemas/share-grants.d.ts +30 -30
- package/dist/schemas/shared-access.d.ts +17 -4
- package/dist/schemas/shared-access.d.ts.map +1 -1
- package/dist/schemas/status.d.ts +59 -79
- package/dist/schemas/status.d.ts.map +1 -1
- package/dist/schemas/syncs.d.ts +38 -22
- package/dist/schemas/syncs.d.ts.map +1 -1
- package/dist/schemas/telemetry.d.ts +26 -26
- package/dist/schemas/workflows.d.ts +71 -71
- package/dist/server.d.ts +13 -0
- package/dist/server.d.ts.map +1 -1
- package/dist/utils/ws.d.ts +3 -0
- package/dist/utils/ws.d.ts.map +1 -1
- package/package.json +11 -7
- package/src/artifacts/frame.ts +4 -13
- package/src/auth/scope.ts +10 -1
- package/src/auth/shared-access.ts +108 -12
- package/src/connectors/http.ts +35 -1
- package/src/live/README.md +136 -0
- package/src/live/awareness.ts +141 -0
- package/src/live/room.ts +933 -0
- package/src/live/rooms.ts +288 -0
- package/src/registerRoutes.ts +2 -0
- package/src/routes/agent-computers.ts +208 -14
- package/src/routes/agent-runners.ts +1 -0
- package/src/routes/agents.ts +52 -7
- package/src/routes/artifact-frames.ts +40 -12
- package/src/routes/artifacts.ts +713 -28
- package/src/routes/connector-connection-runs.ts +7 -12
- package/src/routes/connector-connections.ts +10 -7
- package/src/routes/lake.ts +73 -0
- package/src/routes/objects.ts +3 -9
- package/src/routes/pipelines.ts +1 -0
- package/src/routes/shared-access.ts +53 -1
- package/src/routes/status.ts +9 -4
- package/src/routes/syncs.ts +1 -0
- package/src/routes/webhooks.ts +44 -3
- package/src/routes/ws/artifacts.ts +138 -0
- package/src/routes/ws/events.ts +7 -2
- package/src/routes/ws/index.ts +13 -2
- package/src/routes/ws/shared-sockets.ts +152 -0
- package/src/schemas/agents.ts +71 -1
- package/src/schemas/ai-accounting.ts +1 -0
- package/src/schemas/artifacts.ts +255 -18
- package/src/schemas/connectors.ts +17 -2
- package/src/schemas/files.ts +12 -0
- package/src/schemas/lake.ts +53 -0
- package/src/schemas/objects.ts +1 -0
- package/src/schemas/pipelines.ts +2 -0
- package/src/schemas/projections.ts +2 -2
- package/src/schemas/shared-access.ts +16 -0
- package/src/schemas/status.ts +16 -22
- package/src/schemas/syncs.ts +2 -0
- package/src/server.ts +35 -4
- package/src/utils/ws.ts +7 -0
package/dist/server.d.ts
CHANGED
|
@@ -22,6 +22,16 @@ export interface SixbServerOptions {
|
|
|
22
22
|
trustedProxies?: readonly string[];
|
|
23
23
|
/** Where requests spend their time: a `Server-Timing` header and a log of slow requests. */
|
|
24
24
|
timing?: SixbRequestTimingOptions;
|
|
25
|
+
/**
|
|
26
|
+
* Whether this server delivers the events a commit left undelivered and purges expired records,
|
|
27
|
+
* every minute. Defaults to true; set it to false when an orchestrator runs for the project.
|
|
28
|
+
*/
|
|
29
|
+
ontologyMaintenance?: boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Whether `sixb.datasets.ingest` in this server writes what it stored before it returns, as no
|
|
32
|
+
* worker will. Defaults to true; set it to false when a lake worker runs for the project.
|
|
33
|
+
*/
|
|
34
|
+
ingestFlush?: boolean;
|
|
25
35
|
}
|
|
26
36
|
export declare function createSixbServer(options: SixbServerOptions): SixbServer;
|
|
27
37
|
export declare class SixbServer {
|
|
@@ -38,6 +48,8 @@ export declare class SixbServer {
|
|
|
38
48
|
private readonly timing;
|
|
39
49
|
private app;
|
|
40
50
|
private bunServer;
|
|
51
|
+
private readonly hostsOntologyMaintenance;
|
|
52
|
+
private readonly flushesIngestion;
|
|
41
53
|
private maintenance;
|
|
42
54
|
private stopSweeper;
|
|
43
55
|
constructor(options: SixbServerOptions);
|
|
@@ -52,6 +64,7 @@ export declare class SixbServer {
|
|
|
52
64
|
getAuthExperience(): SixbAuthExperienceOptions | undefined;
|
|
53
65
|
getSharedAccessOptions(): SixbSharedAccessOptions;
|
|
54
66
|
start(): Promise<void>;
|
|
67
|
+
private setIngestFlush;
|
|
55
68
|
stop(): Promise<void>;
|
|
56
69
|
}
|
|
57
70
|
export declare function createSixbApi(server: SixbServer): Elysia<"", {
|
package/dist/server.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAA6B,YAAY,EAAE,MAAM,YAAY,CAAA;AAQzE,OAAO,EAAE,MAAM,EAAc,MAAM,QAAQ,CAAA;AAE3C,OAAO,EACL,KAAK,6BAA6B,EAClC,KAAK,2BAA2B,EAIhC,KAAK,kBAAkB,EACvB,KAAK,0BAA0B,EAC/B,KAAK,4BAA4B,EAKjC,KAAK,oBAAoB,EAC1B,MAAM,uBAAuB,CAAA;AAO9B,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,mBAAmB,CAAA;AAKlE,OAAO,EAGL,KAAK,uBAAuB,EAC7B,MAAM,sBAAsB,CAAA;AAsB7B,OAAO,EAEL,KAAK,wBAAwB,EAE9B,MAAM,wBAAwB,CAAA;AAG/B,eAAO,MAAM,2BAA2B,QAAY,CAAA;AAEpD,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,YAAY,CAAA;IAClB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,OAAO,EAAE,oBAAoB,CAAA;IAC7B,8EAA8E;IAC9E,cAAc,CAAC,EAAE,yBAAyB,CAAA;IAC1C,qEAAqE;IACrE,YAAY,CAAC,EAAE,uBAAuB,CAAA;IACtC;;;OAGG;IACH,cAAc,CAAC,EAAE,SAAS,MAAM,EAAE,CAAA;IAClC,4FAA4F;IAC5F,MAAM,CAAC,EAAE,wBAAwB,CAAA;
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"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"}
|
package/dist/utils/ws.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Sixb } from "@sixb/core/internal/request-execution";
|
|
2
|
+
import type { SharedSessionContext } from "@sixb/core/internal/shares";
|
|
2
3
|
export declare function safeSend(target: {
|
|
3
4
|
send: (message: string) => void;
|
|
4
5
|
}, payload: unknown): void;
|
|
@@ -6,5 +7,7 @@ export declare function safeSend(target: {
|
|
|
6
7
|
export declare function wsStateKey(ws: object): object;
|
|
7
8
|
/** The execution SDK attached once when the WebSocket request crosses the auth boundary. */
|
|
8
9
|
export declare function wsRequestSixb(ws: object): Sixb | null;
|
|
10
|
+
/** The shared link's session the WebSocket request was opened under, if one was. */
|
|
11
|
+
export declare function wsSharedSession(ws: object): SharedSessionContext | null;
|
|
9
12
|
export declare function decodeWsMessage(message: unknown): Promise<unknown>;
|
|
10
13
|
//# sourceMappingURL=ws.d.ts.map
|
package/dist/utils/ws.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ws.d.ts","sourceRoot":"","sources":["../../src/utils/ws.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,uCAAuC,CAAA;
|
|
1
|
+
{"version":3,"file":"ws.d.ts","sourceRoot":"","sources":["../../src/utils/ws.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,uCAAuC,CAAA;AACjE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAA;AAEtE,wBAAgB,QAAQ,CAAC,MAAM,EAAE;IAAE,IAAI,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAA;CAAE,EAAE,OAAO,EAAE,OAAO,GAAG,IAAI,CAM5F;AAED,wGAAwG;AACxG,wBAAgB,UAAU,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAG7C;AAED,4FAA4F;AAC5F,wBAAgB,aAAa,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,CAOrD;AAED,oFAAoF;AACpF,wBAAgB,eAAe,CAAC,EAAE,EAAE,MAAM,GAAG,oBAAoB,GAAG,IAAI,CAGvE;AAUD,wBAAsB,eAAe,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CA4BxE"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sixb/server",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.3",
|
|
4
4
|
"description": "HTTP and WebSocket API server for Sixb",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sixb",
|
|
@@ -34,20 +34,24 @@
|
|
|
34
34
|
"@elysiajs/cors": "^1.2.0",
|
|
35
35
|
"@elysiajs/openapi": "^1.4.16",
|
|
36
36
|
"elysia": "^1.2.0",
|
|
37
|
+
"lib0": "0.2.119",
|
|
38
|
+
"y-protocols": "1.0.7",
|
|
37
39
|
"zod": "^3.24.0",
|
|
38
40
|
"zod-to-json-schema": "^3.24.0"
|
|
39
41
|
},
|
|
40
42
|
"peerDependencies": {
|
|
41
|
-
"@sixb/core": "0.2.
|
|
43
|
+
"@sixb/core": "0.2.3",
|
|
44
|
+
"yjs": "^13.6.33"
|
|
42
45
|
},
|
|
43
46
|
"devDependencies": {
|
|
44
47
|
"@sixb/auth-magic-link": "0.2.0",
|
|
45
|
-
"@sixb/auth-oidc": "0.2.
|
|
46
|
-
"@sixb/cli-core": "0.2.
|
|
47
|
-
"@sixb/core": "0.2.
|
|
48
|
-
"@sixb/sqlite": "0.2.
|
|
48
|
+
"@sixb/auth-oidc": "0.2.3",
|
|
49
|
+
"@sixb/cli-core": "0.2.3",
|
|
50
|
+
"@sixb/core": "0.2.3",
|
|
51
|
+
"@sixb/sqlite": "0.2.3",
|
|
49
52
|
"@types/bun": "latest",
|
|
50
|
-
"typescript": "^5.7.0"
|
|
53
|
+
"typescript": "^5.7.0",
|
|
54
|
+
"yjs": "13.6.33"
|
|
51
55
|
},
|
|
52
56
|
"license": "MIT",
|
|
53
57
|
"engines": {
|
package/src/artifacts/frame.ts
CHANGED
|
@@ -1,21 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
ARTIFACT_FRAME_ROUTE_PREFIX,
|
|
3
|
+
FRAME_CDN_ALLOWLIST,
|
|
4
|
+
} from "@sixb/core/internal/artifacts/frames"
|
|
2
5
|
import {
|
|
3
6
|
type ResolvedSixbApiBrowserPolicy,
|
|
4
7
|
resolveApiBrowserPublicOrigin,
|
|
5
8
|
} from "../auth/browser-origin"
|
|
6
9
|
|
|
7
|
-
/**
|
|
8
|
-
* Hosts a frame may load from besides its own files: CSS and script libraries and web fonts. Each
|
|
9
|
-
* is a public CDN; a frame that uses one contacts it when it opens.
|
|
10
|
-
*/
|
|
11
|
-
const FRAME_CDN_ALLOWLIST = [
|
|
12
|
-
"https://cdn.jsdelivr.net",
|
|
13
|
-
"https://cdnjs.cloudflare.com",
|
|
14
|
-
"https://unpkg.com",
|
|
15
|
-
"https://fonts.googleapis.com",
|
|
16
|
-
"https://fonts.gstatic.com",
|
|
17
|
-
] as const
|
|
18
|
-
|
|
19
10
|
/**
|
|
20
11
|
* The policy every frame response carries, 404s included. The frame is sandboxed without
|
|
21
12
|
* `allow-same-origin`, so its page cannot read the app's cookies or call the API as the reader;
|
package/src/auth/scope.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { type Principal, SYSTEM_PRINCIPAL } from "@sixb/core"
|
|
|
2
2
|
import { type AgentExecutionAuthorization, agentServiceAccountId } from "@sixb/core/internal/agents"
|
|
3
3
|
import type { AuthenticatedRequestAuthSession } from "@sixb/core/internal/auth"
|
|
4
4
|
import type { Sixb } from "@sixb/core/internal/request-execution"
|
|
5
|
+
import type { SharedSessionContext } from "@sixb/core/internal/shares"
|
|
5
6
|
import type { ConversationAgentRunRecord, ExecutionRecord } from "@sixb/core/storage"
|
|
6
7
|
import type { ServerAuthGuardDecision } from "./guard"
|
|
7
8
|
|
|
@@ -13,6 +14,8 @@ import type { ServerAuthGuardDecision } from "./guard"
|
|
|
13
14
|
*/
|
|
14
15
|
export interface RequestAuthState {
|
|
15
16
|
readonly sixb: Sixb | null
|
|
17
|
+
/** The shared link's session a request speaks for: a guest, without an account. */
|
|
18
|
+
readonly sharedSession?: SharedSessionContext | null
|
|
16
19
|
/** Present for a conversation run's run-token requests. */
|
|
17
20
|
readonly agentRun?: ConversationAgentRunRecord
|
|
18
21
|
/**
|
|
@@ -47,9 +50,15 @@ export interface AgentRunRequestExecution {
|
|
|
47
50
|
* point until route registration carries the derived context type.
|
|
48
51
|
*/
|
|
49
52
|
export function requestAuthState(context: unknown): RequestAuthState {
|
|
50
|
-
const {
|
|
53
|
+
const {
|
|
54
|
+
sixb = null,
|
|
55
|
+
sharedSession,
|
|
56
|
+
agentRun,
|
|
57
|
+
agentExecution,
|
|
58
|
+
} = context as Partial<RequestAuthState>
|
|
51
59
|
return {
|
|
52
60
|
sixb,
|
|
61
|
+
...(sharedSession ? { sharedSession } : {}),
|
|
53
62
|
...(agentRun === undefined ? {} : { agentRun }),
|
|
54
63
|
...(agentExecution === undefined ? {} : { agentExecution }),
|
|
55
64
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { createHash } from "node:crypto"
|
|
2
2
|
import type { SixbHostView } from "@sixb/core"
|
|
3
|
+
import { ARTIFACT_LIVE_ROUTE } from "@sixb/core/artifacts/live"
|
|
3
4
|
import {
|
|
4
5
|
generateCsrfToken,
|
|
5
6
|
getCookie,
|
|
@@ -7,7 +8,11 @@ import {
|
|
|
7
8
|
verifyDoubleSubmitCsrf,
|
|
8
9
|
} from "@sixb/core/internal/auth"
|
|
9
10
|
import { matchesPathPattern, normalizeRoutePath, SIXB_API_ROUTES } from "@sixb/core/internal/http"
|
|
10
|
-
import {
|
|
11
|
+
import {
|
|
12
|
+
guestName,
|
|
13
|
+
type SharedSessionContext,
|
|
14
|
+
SharedSessionProtocol,
|
|
15
|
+
} from "@sixb/core/internal/shares"
|
|
11
16
|
import { hasForegroundSessionActivity } from "./session-activity"
|
|
12
17
|
|
|
13
18
|
export const SHARED_ACCESS_GRANT_HEADER_NAME = "x-sixb-share-grant"
|
|
@@ -15,14 +20,38 @@ const SHARED_ACCESS_GRANT_QUERY_PARAM = "shareGrant"
|
|
|
15
20
|
|
|
16
21
|
const SHARED_SESSION_COOKIE_PREFIX = "sixb_share_session_"
|
|
17
22
|
const SHARED_CSRF_COOKIE_PREFIX = "sixb_share_csrf_"
|
|
18
|
-
|
|
23
|
+
/**
|
|
24
|
+
* The session cookie reaches the API and its sockets, whose upgrade a browser sends with cookies
|
|
25
|
+
* but no header of ours. It stays `SameSite=Strict` and `HttpOnly`, and every request, an upgrade
|
|
26
|
+
* included, must come from an allowed origin: another site's page cannot ride it. The CSRF cookie
|
|
27
|
+
* is only ever needed beside a mutation, so it stays under `/api`.
|
|
28
|
+
*/
|
|
29
|
+
const SHARED_SESSION_COOKIE_PATH = "/"
|
|
30
|
+
const SHARED_CSRF_COOKIE_PATH = "/api"
|
|
31
|
+
/** Where session cookies were set before they reached sockets: cleared with the current ones. */
|
|
32
|
+
const LEGACY_SHARED_SESSION_COOKIE_PATH = "/api"
|
|
19
33
|
const STORED_IDENTIFIER_MAX_LENGTH = 128
|
|
20
34
|
|
|
21
35
|
const SHARED_SESSION_ROUTES = SIXB_API_ROUTES.filter((route) => route.sharedSession)
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* The sockets a shared link's session may open: the live artifacts it reads, which it watches,
|
|
39
|
+
* and the event stream, which passes it only those artifacts' events.
|
|
40
|
+
*/
|
|
41
|
+
const SHARED_SESSION_SOCKETS: readonly string[] = [ARTIFACT_LIVE_ROUTE, "/ws/events"]
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Where the grant may be named in the query: what `<img>`, `<video>` and download links load, and
|
|
45
|
+
* the sockets, none of which can send a header.
|
|
46
|
+
*/
|
|
47
|
+
const SHARED_QUERY_SELECTOR_ROUTES = [
|
|
48
|
+
...SHARED_SESSION_ROUTES.filter(
|
|
49
|
+
(route) =>
|
|
50
|
+
(route.method === "GET" || route.method === "HEAD") &&
|
|
51
|
+
(route.path.endsWith("/content") || route.path.endsWith("/preview"))
|
|
52
|
+
),
|
|
53
|
+
...SHARED_SESSION_SOCKETS.map((path) => ({ method: "GET", path })),
|
|
54
|
+
]
|
|
26
55
|
|
|
27
56
|
export interface SixbSharedAccessOptions {
|
|
28
57
|
/** Sliding inactivity window, always bounded by the grant's absolute expiration. */
|
|
@@ -54,6 +83,12 @@ export type SharedAccessSignOutResult =
|
|
|
54
83
|
| { readonly kind: "csrf" }
|
|
55
84
|
| { readonly kind: "signedOut"; readonly setCookies: readonly string[] }
|
|
56
85
|
|
|
86
|
+
export type SharedAccessGuestNameResult =
|
|
87
|
+
| { readonly kind: "invalid"; readonly setCookies: readonly string[] }
|
|
88
|
+
| { readonly kind: "csrf" }
|
|
89
|
+
| { readonly kind: "unnamed" }
|
|
90
|
+
| ({ readonly kind: "named" } & ResolvedSharedAccess)
|
|
91
|
+
|
|
57
92
|
/**
|
|
58
93
|
* Selects shared authority before ambient browser or bearer authentication.
|
|
59
94
|
*
|
|
@@ -64,6 +99,7 @@ export class SharedAccessBoundary {
|
|
|
64
99
|
private readonly host: SixbHostView
|
|
65
100
|
private readonly options: SixbSharedAccessOptions
|
|
66
101
|
private protocol: SharedSessionProtocol | undefined
|
|
102
|
+
private readonly guestNamed = new Set<(sessionId: string) => void>()
|
|
67
103
|
|
|
68
104
|
constructor(host: SixbHostView, options: SixbSharedAccessOptions = {}) {
|
|
69
105
|
this.host = host
|
|
@@ -176,6 +212,7 @@ export class SharedAccessBoundary {
|
|
|
176
212
|
serializeSharedCookie({
|
|
177
213
|
request,
|
|
178
214
|
name: names.csrf,
|
|
215
|
+
path: SHARED_CSRF_COOKIE_PATH,
|
|
179
216
|
value: csrfToken,
|
|
180
217
|
expiresAt: context.expiresAt,
|
|
181
218
|
maxAge: cookieMaxAge(context.expiresAt),
|
|
@@ -208,6 +245,47 @@ export class SharedAccessBoundary {
|
|
|
208
245
|
return { kind: "signedOut", setCookies: clearCookies }
|
|
209
246
|
}
|
|
210
247
|
|
|
248
|
+
/**
|
|
249
|
+
* Keeps the name the session's visitor gives, which their comments and presence carry. Like
|
|
250
|
+
* sign-out, it needs the session and its CSRF token; `unnamed` for a name that will not do.
|
|
251
|
+
*/
|
|
252
|
+
async setGuestName(
|
|
253
|
+
request: Request,
|
|
254
|
+
grantId: string,
|
|
255
|
+
name: string
|
|
256
|
+
): Promise<SharedAccessGuestNameResult> {
|
|
257
|
+
if (!isStoredIdentifier(grantId)) return { kind: "invalid", setCookies: [] }
|
|
258
|
+
|
|
259
|
+
const resolved = await this.resolveSession(request, grantId)
|
|
260
|
+
if (!resolved) return { kind: "invalid", setCookies: this.clearCookieHeaders(request, grantId) }
|
|
261
|
+
|
|
262
|
+
if (!verifyDoubleSubmitCsrf(request, { cookieName: sharedCookieNames(grantId).csrf })) {
|
|
263
|
+
return { kind: "csrf" }
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
const kept = guestName(name)
|
|
267
|
+
if (kept === null) return { kind: "unnamed" }
|
|
268
|
+
|
|
269
|
+
const context = await this.getProtocol().setGuestName(resolved.context, kept)
|
|
270
|
+
if (!context) return { kind: "invalid", setCookies: this.clearCookieHeaders(request, grantId) }
|
|
271
|
+
|
|
272
|
+
for (const listener of this.guestNamed) listener(context.sessionId)
|
|
273
|
+
return { kind: "named", context, cookies: resolved.cookies }
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
/** Hears each session whose visitor gave a name through this server. */
|
|
277
|
+
onGuestNamed(listener: (sessionId: string) => void): void {
|
|
278
|
+
this.guestNamed.add(listener)
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
* The session a socket authenticated when it opened, as it is now: null once it is revoked or
|
|
283
|
+
* expired, or its grant is. Reading it renews nothing.
|
|
284
|
+
*/
|
|
285
|
+
current(context: Pick<SharedSessionContext, "grantId" | "sessionId">) {
|
|
286
|
+
return this.getProtocol().current(context)
|
|
287
|
+
}
|
|
288
|
+
|
|
211
289
|
clearCookieHeaders(request: Request, grantId: string): readonly string[] {
|
|
212
290
|
if (!isStoredIdentifier(grantId)) return []
|
|
213
291
|
const names = sharedCookieNames(grantId)
|
|
@@ -215,6 +293,16 @@ export class SharedAccessBoundary {
|
|
|
215
293
|
serializeSharedCookie({
|
|
216
294
|
request,
|
|
217
295
|
name: names.session,
|
|
296
|
+
path: SHARED_SESSION_COOKIE_PATH,
|
|
297
|
+
value: "",
|
|
298
|
+
expiresAt: new Date(0),
|
|
299
|
+
maxAge: 0,
|
|
300
|
+
httpOnly: true,
|
|
301
|
+
}),
|
|
302
|
+
serializeSharedCookie({
|
|
303
|
+
request,
|
|
304
|
+
name: names.session,
|
|
305
|
+
path: LEGACY_SHARED_SESSION_COOKIE_PATH,
|
|
218
306
|
value: "",
|
|
219
307
|
expiresAt: new Date(0),
|
|
220
308
|
maxAge: 0,
|
|
@@ -223,6 +311,7 @@ export class SharedAccessBoundary {
|
|
|
223
311
|
serializeSharedCookie({
|
|
224
312
|
request,
|
|
225
313
|
name: names.csrf,
|
|
314
|
+
path: SHARED_CSRF_COOKIE_PATH,
|
|
226
315
|
value: "",
|
|
227
316
|
expiresAt: new Date(0),
|
|
228
317
|
maxAge: 0,
|
|
@@ -245,6 +334,7 @@ export class SharedAccessBoundary {
|
|
|
245
334
|
serializeSharedCookie({
|
|
246
335
|
request: input.request,
|
|
247
336
|
name: names.session,
|
|
337
|
+
path: SHARED_SESSION_COOKIE_PATH,
|
|
248
338
|
value: input.sessionValue,
|
|
249
339
|
expiresAt: input.expiresAt,
|
|
250
340
|
maxAge,
|
|
@@ -253,6 +343,7 @@ export class SharedAccessBoundary {
|
|
|
253
343
|
serializeSharedCookie({
|
|
254
344
|
request: input.request,
|
|
255
345
|
name: names.csrf,
|
|
346
|
+
path: SHARED_CSRF_COOKIE_PATH,
|
|
256
347
|
value: input.csrfToken,
|
|
257
348
|
expiresAt: input.expiresAt,
|
|
258
349
|
maxAge,
|
|
@@ -291,22 +382,24 @@ export function isSharedAccessPublicPath(pathname: string, requestMethod: string
|
|
|
291
382
|
? "session"
|
|
292
383
|
: method === "POST" && normalizedPathname.endsWith("/sign-out")
|
|
293
384
|
? "sign-out"
|
|
294
|
-
:
|
|
385
|
+
: method === "PUT" && normalizedPathname.endsWith("/name")
|
|
386
|
+
? "name"
|
|
387
|
+
: null
|
|
295
388
|
if (!suffix) return false
|
|
296
389
|
return matchesPathPattern(normalizedPathname, `/api/shared-access/:grantId/${suffix}`)
|
|
297
390
|
}
|
|
298
391
|
|
|
299
392
|
/**
|
|
300
|
-
* The header selects the grant. File GET/HEAD routes also accept the selector in
|
|
301
|
-
* `<img>`, `<video>`,
|
|
302
|
-
* grant cookie to read; the HttpOnly cookie remains the credential.
|
|
393
|
+
* The header selects the grant. File GET/HEAD routes and the sockets also accept the selector in
|
|
394
|
+
* the query, because `<img>`, `<video>`, download links and WebSockets cannot send headers. Either
|
|
395
|
+
* way it only names which grant cookie to read; the HttpOnly cookie remains the credential.
|
|
303
396
|
*/
|
|
304
397
|
function selectSharedAccessGrant(request: Request): SharedAccessGrantSelection {
|
|
305
398
|
const header = request.headers.get(SHARED_ACCESS_GRANT_HEADER_NAME)
|
|
306
399
|
const url = new URL(request.url)
|
|
307
400
|
const method = request.method.toUpperCase()
|
|
308
401
|
const pathname = normalizeRoutePath(url.pathname)
|
|
309
|
-
const queryValues =
|
|
402
|
+
const queryValues = SHARED_QUERY_SELECTOR_ROUTES.some(
|
|
310
403
|
(route) => route.method === method && matchesPathPattern(pathname, route.path)
|
|
311
404
|
)
|
|
312
405
|
? url.searchParams.getAll(SHARED_ACCESS_GRANT_QUERY_PARAM)
|
|
@@ -323,6 +416,8 @@ function selectSharedAccessGrant(request: Request): SharedAccessGrantSelection {
|
|
|
323
416
|
export function isSharedSessionRoute(request: Request): boolean {
|
|
324
417
|
const method = request.method.toUpperCase()
|
|
325
418
|
const pathname = normalizeRoutePath(new URL(request.url).pathname)
|
|
419
|
+
if (method === "GET" && SHARED_SESSION_SOCKETS.includes(pathname)) return true
|
|
420
|
+
|
|
326
421
|
return SHARED_SESSION_ROUTES.some(
|
|
327
422
|
(route) => route.method === method && matchesPathPattern(pathname, route.path)
|
|
328
423
|
)
|
|
@@ -376,6 +471,7 @@ function sharedCookieNames(grantId: string): { readonly session: string; readonl
|
|
|
376
471
|
function serializeSharedCookie(input: {
|
|
377
472
|
readonly request: Request
|
|
378
473
|
readonly name: string
|
|
474
|
+
readonly path: string
|
|
379
475
|
readonly value: string
|
|
380
476
|
readonly expiresAt: Date
|
|
381
477
|
readonly maxAge: number
|
|
@@ -383,7 +479,7 @@ function serializeSharedCookie(input: {
|
|
|
383
479
|
}): string {
|
|
384
480
|
const parts = [
|
|
385
481
|
`${input.name}=${input.value}`,
|
|
386
|
-
`Path=${
|
|
482
|
+
`Path=${input.path}`,
|
|
387
483
|
"SameSite=Strict",
|
|
388
484
|
`Max-Age=${Math.trunc(input.maxAge)}`,
|
|
389
485
|
`Expires=${input.expiresAt.toUTCString()}`,
|
package/src/connectors/http.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { AuthorizationError, type ConnectorConnectionOwner, type SixbHostView } from "@sixb/core"
|
|
2
2
|
import type {
|
|
3
3
|
ConnectorConnectionRunView,
|
|
4
4
|
ConnectorConnectionsRuntime,
|
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
isOAuthConnectorDefinition,
|
|
10
10
|
} from "@sixb/core/internal/connector-connections"
|
|
11
11
|
import { createSixbError } from "@sixb/core/internal/errors"
|
|
12
|
+
import type { Sixb } from "@sixb/core/internal/request-execution"
|
|
12
13
|
import type { z } from "zod"
|
|
13
14
|
import {
|
|
14
15
|
CONNECTOR_HTTP_ERROR_CODES,
|
|
@@ -36,6 +37,39 @@ export function connectorRouteRuntime(
|
|
|
36
37
|
return getConnectorConnectionsRuntime(owner)
|
|
37
38
|
}
|
|
38
39
|
|
|
40
|
+
/** The owner a route's `owner` choice names: the project, or the signed-in caller. */
|
|
41
|
+
export function connectorConnectionOwner(
|
|
42
|
+
sixb: Pick<Sixb, "execution">,
|
|
43
|
+
connectorId: string,
|
|
44
|
+
choice: "project" | "me"
|
|
45
|
+
): ConnectorConnectionOwner {
|
|
46
|
+
if (choice === "project") return { type: "project" }
|
|
47
|
+
const requester = sixb.execution.requestedBy
|
|
48
|
+
if (requester?.type !== "user") {
|
|
49
|
+
throw new AuthorizationError(
|
|
50
|
+
`connection:connector:${connectorId}`,
|
|
51
|
+
"[Sixb] Only a signed-in user can connect their own account."
|
|
52
|
+
)
|
|
53
|
+
}
|
|
54
|
+
return { type: "user", id: requester.id }
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** Whether a connection matches a list route's `owner` filter. */
|
|
58
|
+
export function matchesConnectorConnectionOwner(
|
|
59
|
+
sixb: Pick<Sixb, "execution">,
|
|
60
|
+
connection: ConnectorConnectionView,
|
|
61
|
+
choice: "project" | "me" | undefined
|
|
62
|
+
): boolean {
|
|
63
|
+
if (choice === undefined) return true
|
|
64
|
+
if (choice === "project") return connection.owner.type === "project"
|
|
65
|
+
const requester = sixb.execution.requestedBy
|
|
66
|
+
return (
|
|
67
|
+
connection.owner.type === "user" &&
|
|
68
|
+
requester?.type === "user" &&
|
|
69
|
+
connection.owner.id === requester.id
|
|
70
|
+
)
|
|
71
|
+
}
|
|
72
|
+
|
|
39
73
|
export function serializeConnectorConnection(
|
|
40
74
|
connection: ConnectorConnectionView
|
|
41
75
|
): z.infer<typeof ConnectorConnectionSchema> {
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
# Live artifacts
|
|
2
|
+
|
|
3
|
+
`/ws/artifacts` lets several people edit a canvas at once. Every connected client holds the
|
|
4
|
+
artifact's open version as a Yjs document (`@sixb/core/artifacts/live`). Each server holding the
|
|
5
|
+
artifact keeps one copy, and writes it back into storage as an ordinary artifact write.
|
|
6
|
+
|
|
7
|
+
| File | Role |
|
|
8
|
+
| --- | --- |
|
|
9
|
+
| `routes/ws/artifacts.ts` | The socket: auth as `/ws/agents`, message parsing, one `LiveRooms` per server |
|
|
10
|
+
| `rooms.ts` | Which artifacts this server holds, joins and leaves, who each connection is, the `artifact.updated` feed |
|
|
11
|
+
| `room.ts` | One artifact: its document, its members, write-back, the live stream, presence |
|
|
12
|
+
| `awareness.ts` | What a connection may say of itself in awareness |
|
|
13
|
+
|
|
14
|
+
## One history
|
|
15
|
+
|
|
16
|
+
Yjs merges only documents that share a history. Two documents built separately from the same
|
|
17
|
+
files each own their `canvas.json`, and syncing them keeps one by client id. So storage keeps the
|
|
18
|
+
document itself: `ArtifactRecord.document`, the whole encoded state in a blob and the revision
|
|
19
|
+
whose content it holds, replaced with every content write (see
|
|
20
|
+
`packages/core/src/artifacts/live/state.ts`).
|
|
21
|
+
|
|
22
|
+
- Every server loads a room from that state, and every client's document comes from a room. Any
|
|
23
|
+
copy, on any server and after any reload, continues the same history.
|
|
24
|
+
- Every write to a canvas is made into that document, whoever makes it
|
|
25
|
+
(`packages/core/src/artifacts/publish/merge.ts`):
|
|
26
|
+
- A live write-back carries the room's state, which is applied to the stored one.
|
|
27
|
+
- A write of files (the Agent, HTTP) is applied as the change from the files it was made from.
|
|
28
|
+
- A restore, or a retried turn's undo, is applied as the change back to the restored files.
|
|
29
|
+
- A document whose revision is not the artifact's was left behind by a write that stored none: a
|
|
30
|
+
server from before documents were kept, during a rolling deploy, or a repair by hand. Whoever
|
|
31
|
+
loads it, a room or a write, brings it up to the content as the change from the files it holds.
|
|
32
|
+
An artifact that keeps none yet is built from its files.
|
|
33
|
+
- Both are made under a client id derived from what they are made from, so every server makes the
|
|
34
|
+
same document, and the next write stores it again.
|
|
35
|
+
|
|
36
|
+
## Joining
|
|
37
|
+
|
|
38
|
+
- On `join`, the server reads the person's access to the artifact. `owner` and `update` edit,
|
|
39
|
+
`read` watches, and anything else is refused with `left`.
|
|
40
|
+
- The first join opens the room from the stored document. Other kinds are refused as `not_live`.
|
|
41
|
+
- `joined` says who the connection is (`user`: id, name and color, read once per connection). A
|
|
42
|
+
shared link's guest is read at each join instead, from its session: `guest:<sessionId>`, the
|
|
43
|
+
name they gave, and `guest: true`. Once they give a name, their socket reads it from the session
|
|
44
|
+
(`LiveRooms.refreshUser`): their awareness states take it, and the room shares them again. A name is never an email or an id, since every connection,
|
|
45
|
+
a guest's included, sees the same state: someone who gave none has an empty name.
|
|
46
|
+
- A shared link's socket reads its session again every `SHARED_SOCKET_RECHECK_MS`, and on its next
|
|
47
|
+
message past that (`routes/ws/shared-sockets.ts`): its SDK keeps the authority the upgrade
|
|
48
|
+
proved, so revocation is seen only there. One that ended is closed with 4401.
|
|
49
|
+
- A socket message is at most 64 KiB. A larger sync message is sent in parts (`more: true`, see
|
|
50
|
+
`liveSync`), each its own base64, and assembled per connection and artifact up to
|
|
51
|
+
`MAX_LIVE_SYNC_BYTES`.
|
|
52
|
+
- A watcher may send sync step 1 (to receive the document) and awareness, never an update. An
|
|
53
|
+
editor's access is read again at most every `ACCESS_RECHECK_MS` while it writes, and every
|
|
54
|
+
member's on each write to the artifact and every `MEMBERS_RECHECK_MS`. Losing `update`
|
|
55
|
+
demotes it to a watcher (`access`), and losing `read` removes it (`left`).
|
|
56
|
+
|
|
57
|
+
## Presence
|
|
58
|
+
|
|
59
|
+
The server vouches for every awareness state it shares:
|
|
60
|
+
|
|
61
|
+
- A connection may speak for awareness clients that nobody else speaks for, up to
|
|
62
|
+
`MAX_AWARENESS_CLIENTS`. It may not speak for another connection's client, another server's, or
|
|
63
|
+
the room's own.
|
|
64
|
+
- Each state it sets is stored with `user` replaced by who the server knows the person to be, and
|
|
65
|
+
without `sixbAgent`.
|
|
66
|
+
- `sixbAgent` is only the server's own state: the boards each Agent turn changed, read from the
|
|
67
|
+
live stream.
|
|
68
|
+
|
|
69
|
+
## Write-back
|
|
70
|
+
|
|
71
|
+
- An editor's change marks the room dirty. It is written `SAVE_IDLE_MS` after the last change, at
|
|
72
|
+
most `SAVE_MAX_MS` after the first, and at once when the last editor leaves.
|
|
73
|
+
- `flush` writes the room's state through `writeLiveArtifact`, with the SDK of the last editor:
|
|
74
|
+
the public `update` takes files only, and this server-only entry makes the same write from the
|
|
75
|
+
document. The write is authored by that person, bumps the revision, and emits
|
|
76
|
+
`artifact.updated`. If someone
|
|
77
|
+
wrote meanwhile, storage merges both. The room then takes the stored state back under the
|
|
78
|
+
`MERGED` origin, which is never written back again. The document holds no title: the write
|
|
79
|
+
passes the title it last read as `baseTitle`, so a title given since stays.
|
|
80
|
+
- A write-back that changes a board asks for its pictures like any write: in the artifact's one
|
|
81
|
+
preview job, which it replaces, due `BOARD_PREVIEW_JOB.settleMs` later. That is longer than
|
|
82
|
+
`SAVE_MAX_MS`, so a board being typed in is pictured once, after its editors pause.
|
|
83
|
+
- A client's change is tried first on a shadow copy of the document. One that leaves it unreadable
|
|
84
|
+
(`documentFiles` throws) is refused with an `error` before anyone gets it, so a poisoned history
|
|
85
|
+
never spreads or wedges the write-back.
|
|
86
|
+
- A failure leaves the room dirty, reports `status: failed` with the error, and retries:
|
|
87
|
+
- `artifact_not_found`: the room closes and every member gets `left`.
|
|
88
|
+
- An access error: the author is demoted, and another editor is tried at once.
|
|
89
|
+
- `invalid_artifact`: waits for the next change while someone is connected.
|
|
90
|
+
- Anything else: retries with backoff from 2 s doubling to 30 s, for as long as the server runs,
|
|
91
|
+
whether or not anyone still holds the room.
|
|
92
|
+
- Changes are lost only when nobody can write them: the server stops first, or storage refuses
|
|
93
|
+
them (an access error, `invalid_artifact`) once nobody is left who could change that. The room
|
|
94
|
+
then reports `artifact.live_write.failed` to the project's `onError`, through
|
|
95
|
+
`LiveRoomHost.errorReporterHost`, and drops them.
|
|
96
|
+
|
|
97
|
+
## Writes made elsewhere
|
|
98
|
+
|
|
99
|
+
Every `artifact.updated` for a held artifact queues a `reconcile`, whoever made the write. The
|
|
100
|
+
room applies the stored document, brought up to the content if it was left behind, so unsaved
|
|
101
|
+
edits stay. An artifact that keeps none at all takes the change from the files the room last took
|
|
102
|
+
in. The room's work (flush, reconcile) runs on one queue, one task at a
|
|
103
|
+
time.
|
|
104
|
+
|
|
105
|
+
## Several servers
|
|
106
|
+
|
|
107
|
+
Two broker streams carry what reaches every server at once. Each record is tagged with the server
|
|
108
|
+
that heard it, so it is not taken back.
|
|
109
|
+
|
|
110
|
+
`artifacts.live.<artifactId>` (10 minutes, 5,000 records):
|
|
111
|
+
|
|
112
|
+
- `update`: a Yjs update an editor made. Other servers apply it under the `REMOTE` origin and show
|
|
113
|
+
it to their members. The server that heard it writes it back. Each other server marks it
|
|
114
|
+
unwritten, and writes it back too `HEARD_SAVE_MS` later, or when its last editor leaves. By then
|
|
115
|
+
that write is normally in storage, and a write that changes nothing is skipped; if the server
|
|
116
|
+
that heard it died, the edit is not lost.
|
|
117
|
+
- Applying an update twice changes nothing, so a room that opens replays the stream from its start,
|
|
118
|
+
to get what was changed since the last write-back.
|
|
119
|
+
- `agent` / `agent-ended`: the boards an Agent turn changed, appended by `run-artifacts` after each
|
|
120
|
+
canvas write and at the turn's end. Each server drops one after `AGENT_PRESENCE_MS` if the turn
|
|
121
|
+
never ends.
|
|
122
|
+
|
|
123
|
+
`artifacts.presence.<artifactId>` (1 minute, 1,000 records) carries `awareness`: what people point
|
|
124
|
+
at, as their server vouched for it. A server shares its people's states at most every
|
|
125
|
+
`AWARENESS_SHARE_MS`, each as it is by then, so moving cursors never push an update out of the
|
|
126
|
+
document's stream.
|
|
127
|
+
|
|
128
|
+
An update the stream no longer holds reaches storage with a write-back, so a server that missed it
|
|
129
|
+
gets it then.
|
|
130
|
+
|
|
131
|
+
## Lifetime
|
|
132
|
+
|
|
133
|
+
Once the last connection leaves and nothing waits to be written, the room closes and frees its
|
|
134
|
+
document. A client that reconnects later gets a room loaded from storage, with the same history, so
|
|
135
|
+
plain sync brings back what it changed while away. A connection holds at most
|
|
136
|
+
`MAX_LIVE_ARTIFACTS_PER_CONNECTION` artifacts. On server stop, every room writes back first.
|