@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
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { createHash } from "node:crypto"
|
|
2
|
+
import {
|
|
3
|
+
AGENT_AWARENESS_FIELD,
|
|
4
|
+
type ArtifactLiveUser,
|
|
5
|
+
USER_AWARENESS_FIELD,
|
|
6
|
+
} from "@sixb/core/artifacts/live"
|
|
7
|
+
import type { Storage } from "@sixb/core/storage"
|
|
8
|
+
import * as decoding from "lib0/decoding"
|
|
9
|
+
import * as encoding from "lib0/encoding"
|
|
10
|
+
|
|
11
|
+
// What a connection says of itself in awareness, as the server lets others see it: only its own
|
|
12
|
+
// clients' states, each naming the person the server knows it to be, and never the Agent's field,
|
|
13
|
+
// which only servers set.
|
|
14
|
+
|
|
15
|
+
/** The most awareness clients one connection may speak for: a browser tab holds one. */
|
|
16
|
+
export const MAX_AWARENESS_CLIENTS = 4
|
|
17
|
+
/** The most a client's awareness state may weigh, as JSON. */
|
|
18
|
+
export const MAX_AWARENESS_STATE_BYTES = 4 * 1024
|
|
19
|
+
|
|
20
|
+
/** Colors a person's cursor may take: one per person, the same wherever they connect. */
|
|
21
|
+
const COLORS = [
|
|
22
|
+
"#e5484d",
|
|
23
|
+
"#f76b15",
|
|
24
|
+
"#ffc53d",
|
|
25
|
+
"#46a758",
|
|
26
|
+
"#12a594",
|
|
27
|
+
"#0090ff",
|
|
28
|
+
"#8e4ec6",
|
|
29
|
+
"#d6409f",
|
|
30
|
+
] as const
|
|
31
|
+
|
|
32
|
+
/** What the project's own code, and everyone where nobody signs in, is called. */
|
|
33
|
+
export const PROJECT_NAME = "Project"
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* The name others see for someone: a member's profile name, else their email, and the project's
|
|
37
|
+
* for its own code. Null for anyone else, or a member the project no longer knows. Without
|
|
38
|
+
* `email`, for a reader outside the project such as a shared link's guest, a member who gave no
|
|
39
|
+
* name stays unnamed.
|
|
40
|
+
*/
|
|
41
|
+
export async function principalName(
|
|
42
|
+
storage: Pick<Storage, "auth">,
|
|
43
|
+
projectId: string,
|
|
44
|
+
principal: { readonly type: string; readonly id: string },
|
|
45
|
+
options: { readonly email?: boolean } = {}
|
|
46
|
+
): Promise<string | null> {
|
|
47
|
+
if (principal.type === "system") return PROJECT_NAME
|
|
48
|
+
if (principal.type !== "user") return null
|
|
49
|
+
|
|
50
|
+
const record = await storage.auth?.users.getById({ projectId, id: principal.id })
|
|
51
|
+
if (options.email === false) return record?.displayName ?? null
|
|
52
|
+
return record?.displayName ?? record?.email ?? null
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Who a connection is: the member it signed in as, by their profile's name, or the service
|
|
57
|
+
* account or project code it runs as.
|
|
58
|
+
*
|
|
59
|
+
* Everyone in the room sees it, a shared link's guest included, and the server shares one state
|
|
60
|
+
* with all: so it is never an email, nor an id. Someone without a profile name has none, which the
|
|
61
|
+
* app names in the reader's language.
|
|
62
|
+
*/
|
|
63
|
+
export async function liveUserOf(
|
|
64
|
+
storage: Pick<Storage, "auth">,
|
|
65
|
+
projectId: string,
|
|
66
|
+
principal: { readonly type: string; readonly id: string } | undefined
|
|
67
|
+
): Promise<ArtifactLiveUser> {
|
|
68
|
+
if (!principal) return { id: "system", name: PROJECT_NAME, color: colorOf("system") }
|
|
69
|
+
|
|
70
|
+
const id = `${principal.type}:${principal.id}`
|
|
71
|
+
const name = (await principalName(storage, projectId, principal, { email: false })) ?? ""
|
|
72
|
+
return { id, name, color: colorOf(id) }
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Who a shared link's guest is: one per session, by the name they gave, or none yet, marked as a
|
|
77
|
+
* guest so nobody takes them for a member of the same name.
|
|
78
|
+
*/
|
|
79
|
+
export function guestLiveUser(sessionId: string, name: string | undefined): ArtifactLiveUser {
|
|
80
|
+
const id = `guest:${sessionId}`
|
|
81
|
+
return { id, name: name ?? "", color: colorOf(id), guest: true }
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* An awareness update from a connection, as the server takes it: only the clients it may speak
|
|
86
|
+
* for, each state naming `user`, without the Agent's field, and within its size. Null when none is
|
|
87
|
+
* left, or the update does not read.
|
|
88
|
+
*/
|
|
89
|
+
export function vouchedAwareness(
|
|
90
|
+
update: Uint8Array,
|
|
91
|
+
input: {
|
|
92
|
+
readonly user: ArtifactLiveUser
|
|
93
|
+
/** Whether the connection may speak for this awareness client. */
|
|
94
|
+
readonly mayUse: (clientID: number) => boolean
|
|
95
|
+
}
|
|
96
|
+
): Uint8Array | null {
|
|
97
|
+
const entries: { clientID: number; clock: number; state: string }[] = []
|
|
98
|
+
try {
|
|
99
|
+
const decoder = decoding.createDecoder(update)
|
|
100
|
+
const length = decoding.readVarUint(decoder)
|
|
101
|
+
for (let index = 0; index < length; index += 1) {
|
|
102
|
+
const clientID = decoding.readVarUint(decoder)
|
|
103
|
+
const clock = decoding.readVarUint(decoder)
|
|
104
|
+
const state = vouchedState(decoding.readVarString(decoder), input.user)
|
|
105
|
+
if (state !== undefined && input.mayUse(clientID)) entries.push({ clientID, clock, state })
|
|
106
|
+
}
|
|
107
|
+
} catch {
|
|
108
|
+
return null
|
|
109
|
+
}
|
|
110
|
+
if (entries.length === 0) return null
|
|
111
|
+
|
|
112
|
+
const encoder = encoding.createEncoder()
|
|
113
|
+
encoding.writeVarUint(encoder, entries.length)
|
|
114
|
+
for (const entry of entries) {
|
|
115
|
+
encoding.writeVarUint(encoder, entry.clientID)
|
|
116
|
+
encoding.writeVarUint(encoder, entry.clock)
|
|
117
|
+
encoding.writeVarString(encoder, entry.state)
|
|
118
|
+
}
|
|
119
|
+
return encoding.toUint8Array(encoder)
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/** A client's state as JSON, naming `user`; `null` stays, for a client that goes. */
|
|
123
|
+
function vouchedState(json: string, user: ArtifactLiveUser): string | undefined {
|
|
124
|
+
if (json.length > MAX_AWARENESS_STATE_BYTES) return undefined
|
|
125
|
+
|
|
126
|
+
const state: unknown = JSON.parse(json)
|
|
127
|
+
if (state === null) return "null"
|
|
128
|
+
if (typeof state !== "object" || Array.isArray(state)) return undefined
|
|
129
|
+
|
|
130
|
+
const {
|
|
131
|
+
[AGENT_AWARENESS_FIELD]: _agent,
|
|
132
|
+
[USER_AWARENESS_FIELD]: _user,
|
|
133
|
+
...own
|
|
134
|
+
} = state as Record<string, unknown>
|
|
135
|
+
return JSON.stringify({ ...own, [USER_AWARENESS_FIELD]: user })
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function colorOf(id: string): string {
|
|
139
|
+
const index = createHash("sha256").update(id).digest()[0] ?? 0
|
|
140
|
+
return COLORS[index % COLORS.length] as string
|
|
141
|
+
}
|