@openllmsh/sdk 0.0.0-stage → 2.10.12-alpha.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/ARCHITECTURE.md +43 -0
- package/LICENSE +202 -0
- package/README.md +142 -2
- package/assets/openllm-light.svg +18 -0
- package/assets/openllm.svg +18 -0
- package/client/chat.ts +140 -0
- package/client/devices.ts +269 -0
- package/client/http.ts +72 -0
- package/client/index.ts +129 -0
- package/client/relay-mux.ts +547 -0
- package/client/types.ts +51 -0
- package/client/vault.ts +239 -0
- package/connect/chat.ts +58 -0
- package/connect/client.ts +240 -0
- package/connect/config.ts +47 -0
- package/connect/errors.ts +121 -0
- package/connect/index.ts +23 -0
- package/connect/oauth.ts +265 -0
- package/connect/routes.ts +234 -0
- package/connect/store.ts +107 -0
- package/mcp/handle.ts +24 -0
- package/mcp/index.ts +76 -0
- package/mcp/server.ts +319 -0
- package/mcp/tools/marketplace.ts +439 -0
- package/mcp/tools/memory-client.ts +297 -0
- package/mcp/tools/memory-config.ts +32 -0
- package/mcp/tools/memory.ts +369 -0
- package/mcp/tools/model-priority.ts +88 -0
- package/mcp/tools/openllm.ts +883 -0
- package/mcp/types.ts +28 -0
- package/openapi/call.ts +90 -0
- package/openapi/index.ts +8 -0
- package/openapi/openapi.json +80213 -0
- package/openapi/operations.ts +2075 -0
- package/package.json +39 -4
- package/protocol/CONTRIBUTING.md +21 -0
- package/protocol/README.md +134 -0
- package/protocol/access.ts +186 -0
- package/protocol/agent-prompt-text.ts +32 -0
- package/protocol/agent.ts +991 -0
- package/protocol/api-key-syntax.ts +105 -0
- package/protocol/assets/openllm-light.svg +18 -0
- package/protocol/assets/openllm.svg +18 -0
- package/protocol/audio.ts +29 -0
- package/protocol/auth.ts +142 -0
- package/protocol/changelog.ts +155 -0
- package/protocol/chat.ts +458 -0
- package/protocol/client-registry.ts +356 -0
- package/protocol/config.ts +345 -0
- package/protocol/control-channel.ts +115 -0
- package/protocol/cooldown-reason.ts +78 -0
- package/protocol/cost.ts +10 -0
- package/protocol/daemon-port.ts +31 -0
- package/protocol/daemon.ts +1524 -0
- package/protocol/default-chains.ts +66 -0
- package/protocol/device-state.ts +85 -0
- package/protocol/doctor-report-local.ts +443 -0
- package/protocol/doctor-report-policy.ts +119 -0
- package/protocol/doctor-report.ts +947 -0
- package/protocol/errors.ts +14 -0
- package/protocol/execution-selection.ts +141 -0
- package/protocol/hop-grant.ts +33 -0
- package/protocol/image-edit-parse.ts +263 -0
- package/protocol/images.ts +298 -0
- package/protocol/index.ts +74 -0
- package/protocol/inference-headers.ts +3 -0
- package/protocol/keepalive.ts +69 -0
- package/protocol/local-auth.ts +300 -0
- package/protocol/local-device-control.ts +133 -0
- package/protocol/local-provider.ts +288 -0
- package/protocol/local-session.ts +118 -0
- package/protocol/marketplace.ts +187 -0
- package/protocol/media-attempt.ts +81 -0
- package/protocol/media-bytes.ts +28 -0
- package/protocol/media-default.ts +357 -0
- package/protocol/media-dimensions.ts +132 -0
- package/protocol/media-input.ts +61 -0
- package/protocol/media-model.ts +142 -0
- package/protocol/media-option-issue.ts +90 -0
- package/protocol/media-types.ts +70 -0
- package/protocol/model-match.ts +1051 -0
- package/protocol/model-settings.ts +327 -0
- package/protocol/models.ts +767 -0
- package/protocol/mux.ts +722 -0
- package/protocol/plan-surface.ts +59 -0
- package/protocol/provider-models.ts +16 -0
- package/protocol/provider-status.ts +206 -0
- package/protocol/provider-tier.ts +67 -0
- package/protocol/provider-usage.ts +263 -0
- package/protocol/providers.ts +901 -0
- package/protocol/public-usage-index.ts +354 -0
- package/protocol/realtime-generated.ts +31 -0
- package/protocol/realtime.ts +324 -0
- package/protocol/registry-pointer.ts +118 -0
- package/protocol/relay.ts +702 -0
- package/protocol/replay-session.ts +11 -0
- package/protocol/responses.ts +280 -0
- package/protocol/semver.ts +182 -0
- package/protocol/setup-mode.ts +22 -0
- package/protocol/sha256-hex.ts +98 -0
- package/protocol/stats.ts +406 -0
- package/protocol/streaming.ts +19 -0
- package/protocol/subscription-daemon-floors.ts +33 -0
- package/protocol/subscription-provider-compat.ts +104 -0
- package/protocol/subscription-provider.ts +32 -0
- package/protocol/team-grant.ts +17 -0
- package/protocol/team-shareable.ts +61 -0
- package/protocol/transcription-encoding.ts +76 -0
- package/protocol/url-locality-dns.ts +37 -0
- package/protocol/url-locality.ts +288 -0
- package/protocol/usage-snapshots.ts +9 -0
- package/protocol/vendor-cli-install.ts +29 -0
- package/protocol/video-job-plan.ts +50 -0
- package/protocol/videos.ts +227 -0
- package/tsconfig.json +14 -0
- package/tunnel/ARCHITECTURE.md +111 -0
- package/tunnel/LICENSE +33 -0
- package/tunnel/README.md +45 -0
- package/tunnel/assets/openllm-light.svg +18 -0
- package/tunnel/assets/openllm.svg +18 -0
- package/tunnel/channel-envelope.ts +139 -0
- package/tunnel/codec.ts +191 -0
- package/tunnel/device-anchor.ts +229 -0
- package/tunnel/device-control.ts +118 -0
- package/tunnel/device-grant.ts +173 -0
- package/tunnel/fleet.ts +77 -0
- package/tunnel/index.ts +22 -0
- package/tunnel/mux.ts +580 -0
- package/tunnel/peer-link.ts +390 -0
- package/tunnel/rtc-auth.ts +415 -0
- package/tunnel/rtc-duplex.ts +187 -0
- package/tunnel/rtc-ice.ts +136 -0
- package/tunnel/secure.ts +1298 -0
- package/tunnel/stream-reset-error.ts +14 -0
- package/tunnel/streams.ts +1430 -0
- package/tunnel/team-grant.ts +302 -0
- package/tunnel/wire-bytes.ts +102 -0
- package/vault/ARCHITECTURE.md +470 -0
- package/vault/LICENSE +33 -0
- package/vault/api-key.ts +190 -0
- package/vault/argon2.ts +106 -0
- package/vault/cli-auth-seal.ts +157 -0
- package/vault/cred-seal.ts +146 -0
- package/vault/credential.ts +55 -0
- package/vault/crypto.ts +210 -0
- package/vault/daemon-attest.ts +229 -0
- package/vault/derive.ts +113 -0
- package/vault/device-access.ts +87 -0
- package/vault/device-anchor.ts +185 -0
- package/vault/device-control.ts +174 -0
- package/vault/handoff.ts +396 -0
- package/vault/index.ts +21 -0
- package/vault/passkey.ts +243 -0
- package/vault/phrase.ts +65 -0
- package/vault/pin.ts +153 -0
- package/vault/public-key-seal.ts +131 -0
- package/vault/seed.ts +272 -0
- package/vault/team.ts +355 -0
- package/vault/vault-item.ts +131 -0
- package/vault/vault-migrate-digest.ts +29 -0
- package/vault/wrapped.ts +77 -0
- package/wire/ARCHITECTURE.md +90 -0
- package/wire/CONTRIBUTING.md +19 -0
- package/wire/LICENSE +33 -0
- package/wire/README.md +51 -0
- package/wire/adapters/messages/anthropic-map.ts +37 -0
- package/wire/adapters/messages/index.ts +7 -0
- package/wire/adapters/messages/reasoning-from-items.ts +38 -0
- package/wire/adapters/messages/reasoning-signature.ts +243 -0
- package/wire/adapters/messages/request.ts +574 -0
- package/wire/adapters/messages/response.ts +215 -0
- package/wire/adapters/messages/streaming.ts +1027 -0
- package/wire/adapters/messages/usage.ts +43 -0
- package/wire/adapters/responses/index.ts +3 -0
- package/wire/adapters/responses/request.ts +395 -0
- package/wire/adapters/responses/response.ts +88 -0
- package/wire/adapters/responses/streaming.ts +344 -0
- package/wire/assets/openllm-light.svg +18 -0
- package/wire/assets/openllm.svg +18 -0
- package/wire/features/account-rank.ts +166 -0
- package/wire/features/compaction/compact-request.ts +862 -0
- package/wire/features/compaction/compaction-text.ts +43 -0
- package/wire/features/context-demote.ts +47 -0
- package/wire/features/context-overflow-strategy.ts +26 -0
- package/wire/features/context-skip.ts +170 -0
- package/wire/features/conversation-affinity.ts +144 -0
- package/wire/features/max-tokens-backfill.ts +141 -0
- package/wire/features/model-caps.ts +53 -0
- package/wire/features/model-settings.ts +24 -0
- package/wire/features/output-limit-clamp.ts +64 -0
- package/wire/features/quota-gate.ts +85 -0
- package/wire/index.ts +44 -0
- package/wire/lib/attempt-outcome.ts +43 -0
- package/wire/lib/canonical/content-part.ts +38 -0
- package/wire/lib/canonical/count-tokens-capability.ts +138 -0
- package/wire/lib/canonical/encoding-select.ts +82 -0
- package/wire/lib/canonical/image-signature.ts +202 -0
- package/wire/lib/canonical/image-sse.ts +216 -0
- package/wire/lib/canonical/message.ts +43 -0
- package/wire/lib/canonical/token-estimate.ts +266 -0
- package/wire/lib/encrypted-content.ts +66 -0
- package/wire/lib/error-class.ts +154 -0
- package/wire/lib/error-envelope.ts +56 -0
- package/wire/lib/forwarded-headers.ts +180 -0
- package/wire/lib/provider-error-rules.ts +48 -0
- package/wire/lib/refusal.ts +38 -0
- package/wire/lib/responses-apply-patch.ts +104 -0
- package/wire/lib/responses-namespace.ts +53 -0
- package/wire/lib/secret-scrub.ts +101 -0
- package/wire/lib/streaming/accumulate.ts +221 -0
- package/wire/lib/streaming/finish-reason.ts +33 -0
- package/wire/lib/streaming/peek.ts +154 -0
- package/wire/lib/streaming/provider-decode.ts +259 -0
- package/wire/lib/streaming/response-stream.ts +71 -0
- package/wire/lib/streaming/sse.ts +699 -0
- package/wire/lib/streaming/strip-tool-calls.ts +95 -0
- package/wire/lib/streaming/upstream-error.ts +58 -0
- package/wire/lib/strip-subagent-isolation.ts +284 -0
- package/wire/lib/thinking-signature.ts +156 -0
- package/wire/lib/token-ruler/bpe-core.ts +426 -0
- package/wire/lib/token-ruler/index.ts +2 -0
- package/wire/lib/token-ruler/ruler.ts +79 -0
- package/wire/lib/token-ruler/vocab/claude-ranks.ts +16 -0
- package/wire/lib/token-ruler/vocab/claude.ts +22 -0
- package/wire/lib/token-ruler/vocab/o200k-ranks.ts +18 -0
- package/wire/lib/token-ruler/vocab/o200k.ts +19 -0
- package/wire/lib/tool-name-map.ts +271 -0
- package/wire/lib/tool-schema.ts +353 -0
- package/wire/lib/usage-observer.ts +125 -0
- package/wire/providers/anthropic/adaptive-thinking.ts +291 -0
- package/wire/providers/anthropic/beta-headers.ts +165 -0
- package/wire/providers/anthropic/index.ts +10 -0
- package/wire/providers/anthropic/request.ts +607 -0
- package/wire/providers/anthropic/response.ts +155 -0
- package/wire/providers/anthropic/streaming.ts +315 -0
- package/wire/providers/anthropic/web-search-domains.ts +49 -0
- package/wire/providers/chatgpt/common.ts +136 -0
- package/wire/providers/chatgpt/index.ts +9 -0
- package/wire/providers/chatgpt/request.ts +959 -0
- package/wire/providers/chatgpt/streaming.ts +1007 -0
- package/wire/providers/chatgpt/web-search.ts +63 -0
- package/wire/providers/grok/web-search.ts +87 -0
- package/wire/providers/kimi/web-search.ts +145 -0
- package/wire/providers/upstream-deny.ts +355 -0
- package/wire/providers/upstream-request.ts +619 -0
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
import { Schema as S } from "effect";
|
|
2
|
+
import { OptionalMediaModel } from "./media-input";
|
|
3
|
+
import { VideoInputMode, VideoReferenceInputs } from "./models";
|
|
4
|
+
|
|
5
|
+
export const VIDEO_INPUT_ERROR =
|
|
6
|
+
"Invalid video input. Use only canonical video fields; input_image is a starting frame, reference_images are subject references, and reference_voices are voice IDs. Unknown fields (including input_reference) are not supported.";
|
|
7
|
+
|
|
8
|
+
const ReferenceCount = S.Int.check(S.isGreaterThanOrEqualTo(0));
|
|
9
|
+
/** Metadata only: counts of inputs, never URLs, bytes, or browser media IDs. */
|
|
10
|
+
export const VideoInputReceipt = S.Struct({
|
|
11
|
+
mode: VideoInputMode,
|
|
12
|
+
starting_images: ReferenceCount,
|
|
13
|
+
subject_images: ReferenceCount,
|
|
14
|
+
voices: ReferenceCount,
|
|
15
|
+
});
|
|
16
|
+
export type TVideoInputReceipt = S.Schema.Type<typeof VideoInputReceipt>;
|
|
17
|
+
|
|
18
|
+
export const videoInputReceiptFromCounts = (
|
|
19
|
+
counts: Omit<TVideoInputReceipt, "mode">,
|
|
20
|
+
): TVideoInputReceipt => {
|
|
21
|
+
const {
|
|
22
|
+
starting_images: startingImages,
|
|
23
|
+
subject_images: subjectImages,
|
|
24
|
+
voices,
|
|
25
|
+
} = counts;
|
|
26
|
+
const mode = S.decodeUnknownSync(VideoInputMode)(
|
|
27
|
+
[
|
|
28
|
+
startingImages > 0 ? "starting_image" : "",
|
|
29
|
+
subjectImages > 0 ? "subject_images" : "",
|
|
30
|
+
voices > 0 ? "voices" : "",
|
|
31
|
+
]
|
|
32
|
+
.filter(Boolean)
|
|
33
|
+
.join("+") || "text",
|
|
34
|
+
);
|
|
35
|
+
return {
|
|
36
|
+
mode,
|
|
37
|
+
starting_images: startingImages,
|
|
38
|
+
subject_images: subjectImages,
|
|
39
|
+
voices,
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export const videoInputRequirements = (
|
|
44
|
+
body: Pick<
|
|
45
|
+
TVideoGenerationInput,
|
|
46
|
+
"input_image" | "reference_images" | "reference_voices"
|
|
47
|
+
>,
|
|
48
|
+
): TVideoInputReceipt =>
|
|
49
|
+
videoInputReceiptFromCounts({
|
|
50
|
+
starting_images: body.input_image === undefined ? 0 : 1,
|
|
51
|
+
subject_images: body.reference_images?.length ?? 0,
|
|
52
|
+
voices: body.reference_voices?.length ?? 0,
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
/** Clip duration in seconds. Providers validate unsupported values. */
|
|
56
|
+
export const VideoSeconds = S.String.pipe(
|
|
57
|
+
S.annotate({
|
|
58
|
+
description:
|
|
59
|
+
"Requested duration in seconds as a numeric string. Values are not clamped; the provider validates durations accepted by the selected model.",
|
|
60
|
+
}),
|
|
61
|
+
);
|
|
62
|
+
export type TVideoSeconds = S.Schema.Type<typeof VideoSeconds>;
|
|
63
|
+
|
|
64
|
+
/** Output resolution as "WIDTHxHEIGHT" (e.g. "720x1280"). */
|
|
65
|
+
export const VideoSize = S.String.pipe(
|
|
66
|
+
S.annotate({
|
|
67
|
+
description:
|
|
68
|
+
"Requested output dimensions as WIDTHxHEIGHT (for example 1280x720 or 720x1280). Adapters preserve aspect ratio and resolution intent; the provider validates model-specific sizes.",
|
|
69
|
+
}),
|
|
70
|
+
);
|
|
71
|
+
export type TVideoSize = S.Schema.Type<typeof VideoSize>;
|
|
72
|
+
|
|
73
|
+
/** Canonical reference semantics are preserved or rejected, never silently dropped. */
|
|
74
|
+
export const VideoGenerationRequest = S.Struct({
|
|
75
|
+
model: S.String,
|
|
76
|
+
prompt: S.String,
|
|
77
|
+
seconds: S.optionalKey(VideoSeconds),
|
|
78
|
+
size: S.optionalKey(VideoSize),
|
|
79
|
+
...VideoReferenceInputs.fields,
|
|
80
|
+
}).pipe(S.annotate({ parseOptions: { onExcessProperty: "error" } }));
|
|
81
|
+
export type TVideoGenerationRequest = S.Schema.Type<
|
|
82
|
+
typeof VideoGenerationRequest
|
|
83
|
+
>;
|
|
84
|
+
|
|
85
|
+
const { model: _videoGenerationModel, ...videoGenerationInputFields } =
|
|
86
|
+
VideoGenerationRequest.fields;
|
|
87
|
+
export const VideoGenerationInput = S.Struct({
|
|
88
|
+
...videoGenerationInputFields,
|
|
89
|
+
model: OptionalMediaModel,
|
|
90
|
+
}).pipe(
|
|
91
|
+
S.annotate({
|
|
92
|
+
description:
|
|
93
|
+
"Video creation input. Only prompt is required. Send only needed optional keys; omit unused model and reference arrays rather than filling dummy empty strings or arrays.",
|
|
94
|
+
parseOptions: { onExcessProperty: "error" },
|
|
95
|
+
}),
|
|
96
|
+
);
|
|
97
|
+
export type TVideoGenerationInput = S.Schema.Type<typeof VideoGenerationInput>;
|
|
98
|
+
|
|
99
|
+
const decodeVideoInput = S.decodeUnknownResult(VideoGenerationInput, {
|
|
100
|
+
onExcessProperty: "error",
|
|
101
|
+
});
|
|
102
|
+
/** Safe diagnostics intentionally never include Effect's raw actual values. */
|
|
103
|
+
/**
|
|
104
|
+
* Effect 3's `optional` accepted an explicit `undefined`; Effect 4's
|
|
105
|
+
* `optionalKey` does not. Treat an `undefined` key as absent, as before, so
|
|
106
|
+
* in-process callers that spread optional values keep working. `null` and
|
|
107
|
+
* every other wrong type still fail, and the wire schema stays exact.
|
|
108
|
+
*/
|
|
109
|
+
export const omitUndefinedKeys = (body: unknown): unknown => {
|
|
110
|
+
if (body === null || typeof body !== "object" || Array.isArray(body)) {
|
|
111
|
+
return body;
|
|
112
|
+
}
|
|
113
|
+
return Object.fromEntries(
|
|
114
|
+
Object.entries(body).filter(([, value]) => value !== undefined),
|
|
115
|
+
);
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
export const parseVideoGenerationInput = (
|
|
119
|
+
body: unknown,
|
|
120
|
+
): TVideoGenerationInput => {
|
|
121
|
+
const result = decodeVideoInput(omitUndefinedKeys(body));
|
|
122
|
+
if (result._tag === "Failure") throw new Error(VIDEO_INPUT_ERROR);
|
|
123
|
+
return result.success;
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
/** Privacy-safe provider diagnostics; preserve corrective text, never attachment material. */
|
|
127
|
+
export const redactVideoErrorText = (
|
|
128
|
+
message: string,
|
|
129
|
+
sensitive: ReadonlyArray<string>,
|
|
130
|
+
): string => {
|
|
131
|
+
let clean = message;
|
|
132
|
+
for (const secret of sensitive) {
|
|
133
|
+
if (secret.length === 0) continue;
|
|
134
|
+
clean = clean.split(secret).join("[redacted]");
|
|
135
|
+
const encoded = secret.match(/^data:[^,]+,(.*)$/s)?.[1];
|
|
136
|
+
if (encoded) clean = clean.split(encoded).join("[redacted]");
|
|
137
|
+
}
|
|
138
|
+
return clean
|
|
139
|
+
.replace(/https?:\/\/[^\s<>"']+/gi, "[redacted-url]")
|
|
140
|
+
.replace(/data:[^\s"']+/gi, "[redacted-image]")
|
|
141
|
+
.replace(/\b[A-Za-z0-9+/]{128,}={0,2}/g, "[redacted-bytes]");
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
export const VideoJobStatus = S.Literals([
|
|
145
|
+
"queued",
|
|
146
|
+
"in_progress",
|
|
147
|
+
"completed",
|
|
148
|
+
"failed",
|
|
149
|
+
]);
|
|
150
|
+
export type TVideoJobStatus = S.Schema.Type<typeof VideoJobStatus>;
|
|
151
|
+
|
|
152
|
+
const VideoJobError = S.Struct({
|
|
153
|
+
code: S.optional(S.String),
|
|
154
|
+
message: S.optional(S.String),
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
export const VideoDeleted = S.Struct({
|
|
158
|
+
id: S.String,
|
|
159
|
+
object: S.Literals(["video.deleted"]),
|
|
160
|
+
deleted: S.Boolean,
|
|
161
|
+
});
|
|
162
|
+
export type TVideoDeleted = S.Schema.Type<typeof VideoDeleted>;
|
|
163
|
+
|
|
164
|
+
export const VideoJob = S.Struct({
|
|
165
|
+
id: S.String,
|
|
166
|
+
object: S.Literals(["video"]),
|
|
167
|
+
created_at: S.Number,
|
|
168
|
+
status: VideoJobStatus,
|
|
169
|
+
model: S.String,
|
|
170
|
+
progress: S.optional(S.Number),
|
|
171
|
+
/** Inputs actually forwarded on accepted creation; absent means unknown. */
|
|
172
|
+
input_receipt: S.optional(VideoInputReceipt),
|
|
173
|
+
seconds: S.optional(VideoSeconds),
|
|
174
|
+
size: S.optional(VideoSize),
|
|
175
|
+
error: S.optional(S.NullOr(VideoJobError)),
|
|
176
|
+
});
|
|
177
|
+
export type TVideoJob = S.Schema.Type<typeof VideoJob>;
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Opaque video job id: provider, upstream job id, model, created-at, and the
|
|
181
|
+
* cloud's signature over all four (`s`). Only the cloud holds the signing
|
|
182
|
+
* key, so a client can't re-point a job at another model or upstream job; a
|
|
183
|
+
* daemon that creates a job asks the cloud to sign it.
|
|
184
|
+
*/
|
|
185
|
+
export type TVideoIdFields = {
|
|
186
|
+
readonly p: string;
|
|
187
|
+
readonly u: string;
|
|
188
|
+
readonly m: string;
|
|
189
|
+
readonly c: number;
|
|
190
|
+
};
|
|
191
|
+
export type TVideoIdPayload = TVideoIdFields & { readonly s: string };
|
|
192
|
+
|
|
193
|
+
export const encodeVideoId = (payload: TVideoIdPayload): string =>
|
|
194
|
+
`video_${Buffer.from(JSON.stringify(payload), "utf8").toString("base64url")}`;
|
|
195
|
+
|
|
196
|
+
export const decodeVideoId = (id: string): TVideoIdPayload | null => {
|
|
197
|
+
if (!id.startsWith("video_")) return null;
|
|
198
|
+
try {
|
|
199
|
+
const parsed: unknown = JSON.parse(
|
|
200
|
+
Buffer.from(id.slice("video_".length), "base64url").toString("utf8"),
|
|
201
|
+
);
|
|
202
|
+
if (parsed === null || typeof parsed !== "object") return null;
|
|
203
|
+
const o = parsed as Record<string, unknown>;
|
|
204
|
+
if (
|
|
205
|
+
typeof o.p !== "string" ||
|
|
206
|
+
typeof o.u !== "string" ||
|
|
207
|
+
typeof o.m !== "string" ||
|
|
208
|
+
typeof o.c !== "number" ||
|
|
209
|
+
typeof o.s !== "string" ||
|
|
210
|
+
!/^[a-f0-9]{64}$/.test(o.s)
|
|
211
|
+
) {
|
|
212
|
+
return null;
|
|
213
|
+
}
|
|
214
|
+
return { p: o.p, u: o.u, m: o.m, c: o.c, s: o.s };
|
|
215
|
+
} catch {
|
|
216
|
+
return null;
|
|
217
|
+
}
|
|
218
|
+
};
|
|
219
|
+
|
|
220
|
+
/** Body of `POST /api/daemon/video-id`: a daemon asks the cloud to sign a job it created. */
|
|
221
|
+
export const VideoIdSignRequest = S.Struct({
|
|
222
|
+
p: S.String.check(S.isMinLength(1), S.isMaxLength(64)),
|
|
223
|
+
u: S.String.check(S.isMinLength(1), S.isMaxLength(256)),
|
|
224
|
+
m: S.String.check(S.isMinLength(1), S.isMaxLength(128)),
|
|
225
|
+
c: S.Number.check(S.isInt()),
|
|
226
|
+
});
|
|
227
|
+
export const VideoIdSignResponse = S.Struct({ id: S.String });
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2022",
|
|
4
|
+
"lib": ["ES2022", "DOM"],
|
|
5
|
+
"module": "ESNext",
|
|
6
|
+
"moduleResolution": "bundler",
|
|
7
|
+
"strict": true,
|
|
8
|
+
"noEmit": true,
|
|
9
|
+
"skipLibCheck": true,
|
|
10
|
+
"isolatedModules": true,
|
|
11
|
+
"resolveJsonModule": true
|
|
12
|
+
},
|
|
13
|
+
"include": ["./**/*.ts", "./**/*.json"]
|
|
14
|
+
}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
# `packages/sdk/tunnel` Architecture
|
|
2
|
+
|
|
3
|
+
> `@openllmsh/sdk/tunnel` is the P1 sans-I/O binary mux used between a consumer,
|
|
4
|
+
> the blind relay, and a serving daemon. It depends directly only on
|
|
5
|
+
> `@openllmsh/sdk/protocol` (which owns the Effect Schema contract): no DOM,
|
|
6
|
+
> WebSocket implementation, Bun, timers, crypto transport, database, proxy
|
|
7
|
+
> pipeline, or framework.
|
|
8
|
+
|
|
9
|
+
| Layer | Responsibility | Must not know |
|
|
10
|
+
| --- | --- | --- |
|
|
11
|
+
| `codec.ts` | Frozen binary frame layout and bounded JSON/window helpers; codec-only relay subpath (`@openllmsh/sdk/tunnel/codec`) | Stream semantics or payload schemas |
|
|
12
|
+
| `channel-envelope.ts` | 16-byte channel-UUID wrapper around one whole relay-WS mux message (`mux2`), so one relay socket multiplexes several channels | Mux stream/flow semantics or payload schemas |
|
|
13
|
+
| `mux.ts` | Per-stream credits, lifecycle, parity, backpressure; optional sender-side `maxPayloadBytes` for SCTP-sized transports | Tunnel payload shape or host I/O |
|
|
14
|
+
| `peer-link.ts` | Sans-I/O RTC-first peer-link policy: selection, bounded probe budgets, negative-cache classification, pre-dispatch retry safety and idle retention | Browser, daemon, relay, WebSocket or RTC implementation details |
|
|
15
|
+
| `streams.ts` | OPEN/CTRL/RESET helpers and fetch-shaped tunnel stream APIs (`tunnelStream` / `serveStream`) | Relay routing and WebSocket mechanics |
|
|
16
|
+
| `stream-reset-error.ts` | Typed application-level reset error | Mux lifecycle or protocol parsing |
|
|
17
|
+
| `device-grant.ts` | Canonical device-grant envelope encode/decode + message bytes (no crypto) | Vault DEK, node:crypto, host I/O |
|
|
18
|
+
| `team-grant.ts` | Origin-signed team grant encode/decode + HMAC-SHA256 WebCrypto sign/verify (`v:2`) | Vault DEK, DB, host I/O |
|
|
19
|
+
| `rtc-duplex.ts` | ~20-line `TDuplex` over `RTCDataChannel` (DOM or werift) | Mux / payload schemas / auth |
|
|
20
|
+
| `rtc-auth.ts` | Pure fingerprint binding, ICE-server, and SCTP payload-cap helpers; hosts supply seal/open | Crypto implementations, signaling |
|
|
21
|
+
| `rtc-ice.ts` | Daemon-side mDNS ICE-candidate preflight for werift | RTC signaling, mux, or payload schemas |
|
|
22
|
+
|
|
23
|
+
## Wire contract
|
|
24
|
+
|
|
25
|
+
Every **bare mux message** is exactly one mux frame. The frozen header is nine
|
|
26
|
+
bytes, big-endian: `type(u8) | stream_id(u32) | length(u32)`, followed by
|
|
27
|
+
exactly `length` payload bytes. Relay-WebSocket messages prepend the 16-byte
|
|
28
|
+
`mux2` channel envelope; the relay validates the envelope and its one mux frame,
|
|
29
|
+
then forwards the original enveloped bytes. RTC carries the bare mux frame.
|
|
30
|
+
There is no byte-stream reassembly.
|
|
31
|
+
|
|
32
|
+
OPEN, CTRL, and RESET use UTF-8 JSON in P1. DATA is opaque bytes. END has an
|
|
33
|
+
empty payload. WINDOW is exactly one u32 big-endian delta. Numeric constants
|
|
34
|
+
have one home in `codec.ts`:
|
|
35
|
+
|
|
36
|
+
- maximum payload and implicit OPEN credit: 256 KiB (frozen — do not raise
|
|
37
|
+
unilaterally);
|
|
38
|
+
- post-OPEN WINDOW boost: +768 KiB (target receive window 1 MiB; skew-safe —
|
|
39
|
+
old peers just add the WINDOW delta);
|
|
40
|
+
- receiver replenishment threshold: 64 KiB;
|
|
41
|
+
- stream zero is channel CTRL; odd ids are consumer initiated and even ids are
|
|
42
|
+
daemon initiated.
|
|
43
|
+
|
|
44
|
+
## Relay blindness
|
|
45
|
+
|
|
46
|
+
The relay authorizes a channel at setup, then routes binary messages by the
|
|
47
|
+
16-byte envelope and nine-byte frame inspection only (the codec-only
|
|
48
|
+
`@openllmsh/sdk/tunnel/channel-envelope` and `@openllmsh/sdk/tunnel/codec` subpaths;
|
|
49
|
+
never `mux.ts`, JSON, stream kinds, or flow control). Application payloads and
|
|
50
|
+
stream state stay endpoint-private.
|
|
51
|
+
|
|
52
|
+
Every relay peer speaks `mux2` and prepends the **channel-id envelope**
|
|
53
|
+
(`channel-envelope.ts`) to every binary message, so a socket can hold several
|
|
54
|
+
channels at once. The relay demuxes by the tag only after verifying the sender
|
|
55
|
+
owns that channel; it forwards the enveloped message verbatim to the other
|
|
56
|
+
endpoint. The frozen mux codec is untouched — the envelope wraps one complete
|
|
57
|
+
mux WebSocket message, not a mux frame header. RTC data channels are never
|
|
58
|
+
enveloped (no relay hop — the data channel itself is the channel).
|
|
59
|
+
|
|
60
|
+
## Landed vs future modules
|
|
61
|
+
|
|
62
|
+
**Landed on this branch (beyond the frozen mux core):**
|
|
63
|
+
|
|
64
|
+
- `device-grant.ts` — seed-gated device-access grant wire format (signed by the
|
|
65
|
+
browser with the phrase-derived device-control key; verified by the daemon).
|
|
66
|
+
Capability negotiation uses `seedgate1` from `@openllmsh/sdk/protocol`. Every
|
|
67
|
+
grant that carries `dpk` also signs its `use` — `channel` (a relay-mux
|
|
68
|
+
`channel_open`, which the relay reads in plaintext), `rtc` (bound to the
|
|
69
|
+
offer's DTLS fingerprint) or `noise` (bound to the Noise initiator's static
|
|
70
|
+
key, `noiseGrantBinding`) — and the daemon refuses a grant of one use
|
|
71
|
+
presented as another, so a harvested `channel_open` grant cannot seed-gate
|
|
72
|
+
an RTC offer or authenticate a Noise initiator. Grants without `dpk` keep
|
|
73
|
+
the legacy bytes (no `use`/`bind`) for daemons that predate the fields.
|
|
74
|
+
- `team-grant.ts` — origin-signed team device grant (HMAC-SHA256 WebCrypto,
|
|
75
|
+
`v:2`). Short-lived `{v, team_id, share_id, consumer, device_user_id,
|
|
76
|
+
device_key_id, model, n, exp[, cap_tokens]}` envelope for cross-user relay
|
|
77
|
+
admission and contributor-daemon re-check. Signed under the per-contributor
|
|
78
|
+
key derived from `NEON_AUTH_COOKIE_SECRET`; daemons pin `team_grant_key` from
|
|
79
|
+
bootstrap. The relay does not verify — it only requires a non-empty grant for
|
|
80
|
+
cross-user opens and stamps `peer_user_id`. Unknown future envelope fields are
|
|
81
|
+
ignored on decode; v1 (Ed25519) is rejected.
|
|
82
|
+
- `device-control.ts` — device-control rotation v2 wire format
|
|
83
|
+
(`label || 0x00 || {v:2, old, new, cv}`, no timestamp, signed by `old`) and
|
|
84
|
+
the shared key fingerprint (`keyFingerprint` / `formatKeyFingerprint`).
|
|
85
|
+
- `rtc-auth.ts` / `rtc-duplex.ts` / `rtc-ice.ts` — WebRTC fingerprint-bound
|
|
86
|
+
offer/answer shapes, ICE-server and SCTP payload-cap helpers, a thin
|
|
87
|
+
data-channel duplex, and daemon-side mDNS-candidate preflight for werift.
|
|
88
|
+
Hosts own signaling and crypto: the browser and consuming fleet daemon are
|
|
89
|
+
offerers, while the serving daemon's `rtc-host` is the answerer. This is the
|
|
90
|
+
one direct-path stack for browser↔daemon and daemon↔daemon traffic; relay
|
|
91
|
+
binary mux is the fallback rung when RTC is unavailable (consumers do not use
|
|
92
|
+
a JSON splice — see `@packages/daemon-relay/ARCHITECTURE.md`).
|
|
93
|
+
|
|
94
|
+
**P2: agent-sessions E2E (in this release):**
|
|
95
|
+
|
|
96
|
+
- `secure.ts` — Noise_IK duplex wrapper (P2), with optional 32-byte PSK
|
|
97
|
+
selecting Noise_IKpsk2 and `deriveTeamTunnelPsk` for team-key HKDF. Secures the mux fallback for
|
|
98
|
+
agent streams (browser path when RTC unavailable or forced off).
|
|
99
|
+
`secureMuxStream` encrypts DATA (length-prefixed Noise records) and CTRL
|
|
100
|
+
(separate key pair); RESET / END / WINDOW stay plaintext. The frozen
|
|
101
|
+
nine-byte mux layout is unchanged.
|
|
102
|
+
- `streams.ts` — `agentStream` / `acceptAgentStream` plus the shared
|
|
103
|
+
`agentSecurePrologue` / `AGENT_SECURE_PROLOGUE_INFO` contract
|
|
104
|
+
(`openllm-agent-secure-v1|<channel_id>|<stream_id>`). Browser initiator and
|
|
105
|
+
daemon responder MUST import these from here (not duplicate the string).
|
|
106
|
+
`agentStream` accepts `secure` (initiator wrap) or a custom `prepareStream`.
|
|
107
|
+
|
|
108
|
+
**Still future (not present):**
|
|
109
|
+
|
|
110
|
+
- `paths.ts` — multi-path resolver (loopback → LAN → relay) for later direct-path
|
|
111
|
+
work (P3).
|
package/tunnel/LICENSE
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
Business Source License 1.1
|
|
2
|
+
|
|
3
|
+
Licensor: OpenLLM, INC
|
|
4
|
+
Licensed Work: OpenLLM Tunnel
|
|
5
|
+
The Licensed Work is (c) 2026 OpenLLM, INC.
|
|
6
|
+
Additional Use Grant: You may use the Licensed Work for internal business purposes, personal use, development, testing, evaluation, non-production deployments, and self-hosted production deployments that are not offered to third parties as a hosted, managed, or paid service that competes with OpenLLM or any substantially similar AI model gateway, proxy, credential-management, routing, memory, indexing, or inference orchestration product or service. In addition, further uses may be listed and defined at https://github.com/openllmsh/license-grants.
|
|
7
|
+
Change Date: The earlier of the fourth anniversary of the first publicly available distribution of a specific version of the Licensed Work, or a date specified at https://github.com/openllmsh/license-grants.
|
|
8
|
+
Change License: MIT License
|
|
9
|
+
|
|
10
|
+
Terms
|
|
11
|
+
|
|
12
|
+
The Licensor hereby grants you the right to copy, modify, create derivative works, redistribute, and make non-production use of the Licensed Work. The Licensor may make an Additional Use Grant, above, permitting limited production use.
|
|
13
|
+
|
|
14
|
+
Effective on the Change Date, or the fourth anniversary of the first publicly available distribution of a specific version of the Licensed Work under this License, whichever comes first, the Licensor hereby grants you rights under the Change License, and the rights granted in the paragraph above terminate.
|
|
15
|
+
|
|
16
|
+
If your use of the Licensed Work does not comply with the requirements currently in effect as described in this License, you must purchase a commercial license from the Licensor, its affiliated entities, or authorized resellers, or you must refrain from using the Licensed Work.
|
|
17
|
+
|
|
18
|
+
All copies of the original and modified Licensed Work, and derivative works of the Licensed Work, are subject to this License. This License applies separately for each version of the Licensed Work and the Change Date may vary for each version of the Licensed Work released by Licensor.
|
|
19
|
+
|
|
20
|
+
You must conspicuously display this License on each original or modified copy of the Licensed Work. If you receive the Licensed Work in original or modified form from any third party, you must retain all copyright, patent, trademark, and attribution notices contained in the Licensed Work.
|
|
21
|
+
|
|
22
|
+
Any use of the Licensed Work in violation of this License will automatically terminate your rights under this License for the current and all other versions of the Licensed Work.
|
|
23
|
+
|
|
24
|
+
This License does not grant you any right in any trademark or logo of Licensor or its affiliates.
|
|
25
|
+
|
|
26
|
+
TO THE EXTENT PERMITTED BY APPLICABLE LAW, THE LICENSED WORK IS PROVIDED ON AN "AS IS" BASIS. LICENSOR HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS, EXPRESS OR IMPLIED, INCLUDING WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND TITLE.
|
|
27
|
+
|
|
28
|
+
Business Source License 1.1 Parameters
|
|
29
|
+
|
|
30
|
+
Licensor: OpenLLM, INC
|
|
31
|
+
Licensed Work: OpenLLM Tunnel
|
|
32
|
+
Change Date: The earlier of the fourth anniversary of the first publicly available distribution of a specific version of the Licensed Work, or a date specified at https://github.com/openllmsh/license-grants.
|
|
33
|
+
Change License: MIT License
|
package/tunnel/README.md
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<picture>
|
|
3
|
+
<source media="(prefers-color-scheme: light)" srcset="./assets/openllm-light.svg">
|
|
4
|
+
<img alt="OpenLLM" src="./assets/openllm.svg" width="300">
|
|
5
|
+
</picture>
|
|
6
|
+
</p>
|
|
7
|
+
|
|
8
|
+
<p align="center"><b>tunnel</b> — the sans-I/O binary mux behind OpenLLM.</p>
|
|
9
|
+
|
|
10
|
+
<p align="center">
|
|
11
|
+
<a href="./LICENSE"><img alt="License: BUSL-1.1" src="https://img.shields.io/badge/license-BUSL--1.1-blue.svg"></a>
|
|
12
|
+
<img alt="source-available" src="https://img.shields.io/badge/source-available-informational.svg">
|
|
13
|
+
</p>
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
The frozen binary mux used between a consumer, the blind relay, and a
|
|
18
|
+
serving daemon — frame codec, per-stream flow control, tunnel stream
|
|
19
|
+
helpers, device-grant wire, and RTC auth/duplex. No DOM, no WebSocket
|
|
20
|
+
implementation, no timers, no crypto transport:
|
|
21
|
+
|
|
22
|
+
- nine-byte big-endian frame header (`type | stream_id | length`)
|
|
23
|
+
- channel-id envelope so one relay socket multiplexes several channels
|
|
24
|
+
- per-stream credits, lifecycle, parity, backpressure
|
|
25
|
+
- device-grant encode/decode and RTC fingerprint-binding shapes
|
|
26
|
+
|
|
27
|
+
Depends only on [`@openllmsh/sdk/protocol`](https://github.com/openllmsh/sdk).
|
|
28
|
+
|
|
29
|
+
## Install
|
|
30
|
+
|
|
31
|
+
```sh
|
|
32
|
+
bun install github:openllmsh/sdk#<tag>
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## License
|
|
36
|
+
|
|
37
|
+
**Source-available** under the [Business Source License 1.1](./LICENSE)
|
|
38
|
+
(© OpenLLM, INC) — use it freely except to run a competing hosted service;
|
|
39
|
+
converts to MIT on the Change Date. This is not OSI open-source.
|
|
40
|
+
|
|
41
|
+
---
|
|
42
|
+
|
|
43
|
+
> **Read-only mirror.** Regenerated from the OpenLLM monorepo each release.
|
|
44
|
+
> PRs welcome — ingested upstream with your authorship preserved. BUSL
|
|
45
|
+
> contributions require the CLA (the bot will prompt you).
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
<svg width="382" height="84" viewBox="0 0 382 84" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
2
|
+
<path d="M225.974 45.3375V63.4219H219.835V29.9968H225.974V39.653C227.596 33.074 232.144 29.0873 238.389 29.0873C245.999 29.0873 250.546 35.0295 250.546 44.7312V63.4219H244.407V44.7312C244.407 38.031 241.572 34.6354 235.827 34.6354C229.657 34.6354 225.974 38.5767 225.974 45.3375Z" fill="#0d1117"/>
|
|
3
|
+
<path d="M209.478 52.3409H215.617C213.889 59.8293 208.098 64.3315 200.276 64.3315C190.438 64.3315 183.844 57.2372 183.844 46.6563C183.844 36.1361 190.363 29.0873 200.079 29.0873C209.644 29.0873 215.769 35.9087 215.769 46.5654C215.769 47.3385 215.738 48.0509 215.663 48.9453H190.105C190.817 55.0694 194.637 58.7833 200.428 58.7833C204.854 58.7833 207.841 56.6005 209.478 52.3409ZM190.226 43.6397H209.417C208.599 37.8339 205.324 34.6354 200.11 34.6354C194.759 34.6354 191.151 38.0158 190.226 43.6397Z" fill="#0d1117"/>
|
|
4
|
+
<path d="M153.97 29.9968V40.2896C155.713 33.4379 160.306 29.0873 166.37 29.0873C174.616 29.0873 180.513 36.4393 180.513 46.7018C180.513 56.9643 174.616 64.3315 166.37 64.3315C160.306 64.3315 155.713 59.9809 153.97 53.114V74.8668H147.83V29.9968H153.97ZM153.97 46.7018C153.97 54.3267 157.85 58.9349 164.278 58.9349C170.826 58.9349 174.373 54.6298 174.373 46.7018C174.373 38.7737 170.826 34.4838 164.278 34.4838C157.85 34.4838 153.97 39.0769 153.97 46.7018Z" fill="#0d1117"/>
|
|
5
|
+
<path d="M102.347 41.7449C102.347 28.2991 110.639 19.1583 122.811 19.1583C134.984 19.1583 143.291 28.2991 143.291 41.7449C143.291 55.1756 134.984 64.3315 122.811 64.3315C110.639 64.3315 102.347 55.1756 102.347 41.7449ZM108.713 41.7449C108.713 52.159 114.004 58.4196 122.811 58.4196C131.618 58.4196 136.924 52.159 136.924 41.7449C136.924 31.3308 131.618 25.0703 122.811 25.0703C114.004 25.0703 108.713 31.3308 108.713 41.7449Z" fill="#0d1117"/>
|
|
6
|
+
<path d="M373.782 20.0679H381.453V63.422H376.784V24.373L360.018 63.422H353.56L336.977 24.3881V63.422H332.399V20.0679H340.084L356.85 59.6323L373.782 20.0679Z" fill="#0d1117"/>
|
|
7
|
+
<path d="M300.083 20.0679H304.752V59.0714H327.945V63.422H300.083V20.0679Z" fill="#0d1117"/>
|
|
8
|
+
<path d="M267.752 20.0677H272.421V59.0713H295.614V63.4219H267.752V20.0677Z" fill="#0d1117"/>
|
|
9
|
+
<path d="M31.3217 2.56513C31.3217 1.14844 32.4702 0 33.8869 0H42.1804C43.5971 0 44.7456 1.14844 44.7456 2.56513V10.8587C44.7456 12.2754 43.5971 13.4238 42.1804 13.4238H33.8869C32.4702 13.4238 31.3217 12.2754 31.3217 10.8587V2.56513Z" fill="#0d1117"/>
|
|
10
|
+
<path d="M0 6.14247C0 4.90684 1.00167 3.90516 2.2373 3.90516C3.47293 3.90516 4.47461 4.90684 4.47461 6.14247C4.47461 7.3781 3.47293 8.37977 2.2373 8.37977C1.00167 8.37977 0 7.3781 0 6.14247Z" fill="#0d1117"/>
|
|
11
|
+
<path d="M46.9829 52.8122C46.9829 51.3955 48.1313 50.247 49.548 50.247H61.6752C63.0918 50.247 64.2403 49.0986 64.2403 47.6819V35.4832C64.2403 34.0665 63.0918 32.9181 61.6752 32.9181H49.548C48.1313 32.9181 46.9829 31.7696 46.9829 30.3529V17.5848C46.9829 16.1681 48.1313 15.0196 49.548 15.0196H62.3162C63.7328 15.0196 64.8813 16.1681 64.8813 17.5848V29.7835C64.8813 31.2002 66.0297 32.3486 67.4464 32.3486H79.5731C80.9898 32.3486 82.1382 33.4971 82.1382 34.9137V47.6819C82.1382 49.0986 80.9898 50.247 79.5731 50.247H67.4464C66.0297 50.247 64.8813 51.3955 64.8813 52.8122V65.5804C64.8813 66.997 63.7328 68.1455 62.3162 68.1455H49.548C48.1313 68.1455 46.9829 66.997 46.9829 65.5804V52.8122Z" fill="#0d1117"/>
|
|
12
|
+
<path d="M15.6611 21.4899C15.6611 20.0732 16.8096 18.9248 18.2262 18.9248H22.0452C23.4619 18.9248 24.6103 20.0732 24.6103 21.4899V25.3089C24.6103 26.7256 23.4619 27.874 22.0452 27.874H18.2262C16.8096 27.874 15.6611 26.7256 15.6611 25.3089V21.4899Z" fill="#0d1117"/>
|
|
13
|
+
<path d="M31.3217 37.1511C31.3217 35.7344 32.4702 34.5859 33.8869 34.5859H42.1804C43.5971 34.5859 44.7456 35.7344 44.7456 37.1511V45.4446C44.7456 46.8613 43.5971 48.0097 42.1804 48.0097H33.8869C32.4702 48.0097 31.3217 46.8613 31.3217 45.4446V37.1511Z" fill="#0d1117"/>
|
|
14
|
+
<path d="M0 41.2978C0 40.0622 1.00167 39.0605 2.2373 39.0605C3.47293 39.0605 4.47461 40.0622 4.47461 41.2978C4.47461 42.5335 3.47293 43.5351 2.2373 43.5351C1.00167 43.5351 0 42.5335 0 41.2978Z" fill="#0d1117"/>
|
|
15
|
+
<path d="M15.6611 57.2868C15.6611 55.8701 16.8096 54.7217 18.2262 54.7217H22.0452C23.4619 54.7217 24.6103 55.8701 24.6103 57.2868V61.1057C24.6103 62.5224 23.4619 63.6709 22.0452 63.6709H18.2262C16.8096 63.6709 15.6611 62.5224 15.6611 61.1057V57.2868Z" fill="#0d1117"/>
|
|
16
|
+
<path d="M33.8869 83.1651C32.4702 83.1651 31.3217 82.0167 31.3217 80.6V72.3064C31.3217 70.8897 32.4702 69.7413 33.8869 69.7413H42.1804C43.5971 69.7413 44.7456 70.8897 44.7456 72.3064V80.6C44.7456 82.0167 43.5971 83.1651 42.1804 83.1651H33.8869Z" fill="#0d1117"/>
|
|
17
|
+
<path d="M0 76.4527C0 75.2171 1.00167 74.2154 2.2373 74.2154C3.47293 74.2154 4.47461 75.2171 4.47461 76.4527C4.47461 77.6883 3.47293 78.69 2.2373 78.69C1.00167 78.69 0 77.6883 0 76.4527Z" fill="#0d1117"/>
|
|
18
|
+
</svg>
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
<svg width="382" height="84" viewBox="0 0 382 84" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
2
|
+
<path d="M225.974 45.3375V63.4219H219.835V29.9968H225.974V39.653C227.596 33.074 232.144 29.0873 238.389 29.0873C245.999 29.0873 250.546 35.0295 250.546 44.7312V63.4219H244.407V44.7312C244.407 38.031 241.572 34.6354 235.827 34.6354C229.657 34.6354 225.974 38.5767 225.974 45.3375Z" fill="white"/>
|
|
3
|
+
<path d="M209.478 52.3409H215.617C213.889 59.8293 208.098 64.3315 200.276 64.3315C190.438 64.3315 183.844 57.2372 183.844 46.6563C183.844 36.1361 190.363 29.0873 200.079 29.0873C209.644 29.0873 215.769 35.9087 215.769 46.5654C215.769 47.3385 215.738 48.0509 215.663 48.9453H190.105C190.817 55.0694 194.637 58.7833 200.428 58.7833C204.854 58.7833 207.841 56.6005 209.478 52.3409ZM190.226 43.6397H209.417C208.599 37.8339 205.324 34.6354 200.11 34.6354C194.759 34.6354 191.151 38.0158 190.226 43.6397Z" fill="white"/>
|
|
4
|
+
<path d="M153.97 29.9968V40.2896C155.713 33.4379 160.306 29.0873 166.37 29.0873C174.616 29.0873 180.513 36.4393 180.513 46.7018C180.513 56.9643 174.616 64.3315 166.37 64.3315C160.306 64.3315 155.713 59.9809 153.97 53.114V74.8668H147.83V29.9968H153.97ZM153.97 46.7018C153.97 54.3267 157.85 58.9349 164.278 58.9349C170.826 58.9349 174.373 54.6298 174.373 46.7018C174.373 38.7737 170.826 34.4838 164.278 34.4838C157.85 34.4838 153.97 39.0769 153.97 46.7018Z" fill="white"/>
|
|
5
|
+
<path d="M102.347 41.7449C102.347 28.2991 110.639 19.1583 122.811 19.1583C134.984 19.1583 143.291 28.2991 143.291 41.7449C143.291 55.1756 134.984 64.3315 122.811 64.3315C110.639 64.3315 102.347 55.1756 102.347 41.7449ZM108.713 41.7449C108.713 52.159 114.004 58.4196 122.811 58.4196C131.618 58.4196 136.924 52.159 136.924 41.7449C136.924 31.3308 131.618 25.0703 122.811 25.0703C114.004 25.0703 108.713 31.3308 108.713 41.7449Z" fill="white"/>
|
|
6
|
+
<path d="M373.782 20.0679H381.453V63.422H376.784V24.373L360.018 63.422H353.56L336.977 24.3881V63.422H332.399V20.0679H340.084L356.85 59.6323L373.782 20.0679Z" fill="white"/>
|
|
7
|
+
<path d="M300.083 20.0679H304.752V59.0714H327.945V63.422H300.083V20.0679Z" fill="white"/>
|
|
8
|
+
<path d="M267.752 20.0677H272.421V59.0713H295.614V63.4219H267.752V20.0677Z" fill="white"/>
|
|
9
|
+
<path d="M31.3217 2.56513C31.3217 1.14844 32.4702 0 33.8869 0H42.1804C43.5971 0 44.7456 1.14844 44.7456 2.56513V10.8587C44.7456 12.2754 43.5971 13.4238 42.1804 13.4238H33.8869C32.4702 13.4238 31.3217 12.2754 31.3217 10.8587V2.56513Z" fill="white"/>
|
|
10
|
+
<path d="M0 6.14247C0 4.90684 1.00167 3.90516 2.2373 3.90516C3.47293 3.90516 4.47461 4.90684 4.47461 6.14247C4.47461 7.3781 3.47293 8.37977 2.2373 8.37977C1.00167 8.37977 0 7.3781 0 6.14247Z" fill="white"/>
|
|
11
|
+
<path d="M46.9829 52.8122C46.9829 51.3955 48.1313 50.247 49.548 50.247H61.6752C63.0918 50.247 64.2403 49.0986 64.2403 47.6819V35.4832C64.2403 34.0665 63.0918 32.9181 61.6752 32.9181H49.548C48.1313 32.9181 46.9829 31.7696 46.9829 30.3529V17.5848C46.9829 16.1681 48.1313 15.0196 49.548 15.0196H62.3162C63.7328 15.0196 64.8813 16.1681 64.8813 17.5848V29.7835C64.8813 31.2002 66.0297 32.3486 67.4464 32.3486H79.5731C80.9898 32.3486 82.1382 33.4971 82.1382 34.9137V47.6819C82.1382 49.0986 80.9898 50.247 79.5731 50.247H67.4464C66.0297 50.247 64.8813 51.3955 64.8813 52.8122V65.5804C64.8813 66.997 63.7328 68.1455 62.3162 68.1455H49.548C48.1313 68.1455 46.9829 66.997 46.9829 65.5804V52.8122Z" fill="white"/>
|
|
12
|
+
<path d="M15.6611 21.4899C15.6611 20.0732 16.8096 18.9248 18.2262 18.9248H22.0452C23.4619 18.9248 24.6103 20.0732 24.6103 21.4899V25.3089C24.6103 26.7256 23.4619 27.874 22.0452 27.874H18.2262C16.8096 27.874 15.6611 26.7256 15.6611 25.3089V21.4899Z" fill="white"/>
|
|
13
|
+
<path d="M31.3217 37.1511C31.3217 35.7344 32.4702 34.5859 33.8869 34.5859H42.1804C43.5971 34.5859 44.7456 35.7344 44.7456 37.1511V45.4446C44.7456 46.8613 43.5971 48.0097 42.1804 48.0097H33.8869C32.4702 48.0097 31.3217 46.8613 31.3217 45.4446V37.1511Z" fill="white"/>
|
|
14
|
+
<path d="M0 41.2978C0 40.0622 1.00167 39.0605 2.2373 39.0605C3.47293 39.0605 4.47461 40.0622 4.47461 41.2978C4.47461 42.5335 3.47293 43.5351 2.2373 43.5351C1.00167 43.5351 0 42.5335 0 41.2978Z" fill="white"/>
|
|
15
|
+
<path d="M15.6611 57.2868C15.6611 55.8701 16.8096 54.7217 18.2262 54.7217H22.0452C23.4619 54.7217 24.6103 55.8701 24.6103 57.2868V61.1057C24.6103 62.5224 23.4619 63.6709 22.0452 63.6709H18.2262C16.8096 63.6709 15.6611 62.5224 15.6611 61.1057V57.2868Z" fill="white"/>
|
|
16
|
+
<path d="M33.8869 83.1651C32.4702 83.1651 31.3217 82.0167 31.3217 80.6V72.3064C31.3217 70.8897 32.4702 69.7413 33.8869 69.7413H42.1804C43.5971 69.7413 44.7456 70.8897 44.7456 72.3064V80.6C44.7456 82.0167 43.5971 83.1651 42.1804 83.1651H33.8869Z" fill="white"/>
|
|
17
|
+
<path d="M0 76.4527C0 75.2171 1.00167 74.2154 2.2373 74.2154C3.47293 74.2154 4.47461 75.2171 4.47461 76.4527C4.47461 77.6883 3.47293 78.69 2.2373 78.69C1.00167 78.69 0 77.6883 0 76.4527Z" fill="white"/>
|
|
18
|
+
</svg>
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Channel-tagged binary envelope for the relay-mux WebSocket hop.
|
|
3
|
+
*
|
|
4
|
+
* The frozen mux codec (`codec.ts`) has no channel id in its nine-byte header,
|
|
5
|
+
* so a relay route by sender-socket identity alone caps every socket at one
|
|
6
|
+
* mux channel. The envelope fixes that WITHOUT touching the frozen codec: it
|
|
7
|
+
* wraps the WHOLE WebSocket message — the 16 raw bytes of the channel UUID
|
|
8
|
+
* prepended to the binary payload. The in-memory `channelId` is the RFC 4122
|
|
9
|
+
* text form (hyphenated lowercase, 36 chars):
|
|
10
|
+
*
|
|
11
|
+
* ```
|
|
12
|
+
* ┌───────────────────────────┬──────────────────────────┐
|
|
13
|
+
* │ channel UUID (16 bytes) │ mux frame(s) payload │
|
|
14
|
+
* └───────────────────────────┴──────────────────────────┘
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* Peers negotiate the envelope out-of-band with the `mux2` capability; it is
|
|
18
|
+
* applied only on channels where the relay recorded `enc`. RTC data channels
|
|
19
|
+
* never carry it (no relay hop — the data channel itself is the channel).
|
|
20
|
+
*
|
|
21
|
+
* This module is dependency-free, mirroring `codec.ts`'s posture: the relay
|
|
22
|
+
* can validate and unwrap a message without learning the payload shape.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
export const CHANNEL_ENVELOPE_TAG_BYTES = 16;
|
|
26
|
+
|
|
27
|
+
/** RFC 4122 text form: 8-4-4-4-12 lowercase hex, variant nibble `8|9|a|b`. */
|
|
28
|
+
const CHANNEL_ID_PATTERN =
|
|
29
|
+
/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/;
|
|
30
|
+
|
|
31
|
+
export const isChannelId = (value: string): boolean =>
|
|
32
|
+
CHANNEL_ID_PATTERN.test(value);
|
|
33
|
+
|
|
34
|
+
/** The 16 wire bytes of a canonical UUID. Throws RangeError on bad input. */
|
|
35
|
+
export const channelIdToBytes = (channelId: string): Uint8Array => {
|
|
36
|
+
if (!isChannelId(channelId)) {
|
|
37
|
+
throw new RangeError("channel id must be a canonical lowercase UUID");
|
|
38
|
+
}
|
|
39
|
+
const hex = channelId.replaceAll("-", "");
|
|
40
|
+
const bytes = new Uint8Array(CHANNEL_ENVELOPE_TAG_BYTES);
|
|
41
|
+
for (let index = 0; index < CHANNEL_ENVELOPE_TAG_BYTES; index += 1) {
|
|
42
|
+
bytes[index] = Number.parseInt(hex.slice(index * 2, index * 2 + 2), 16);
|
|
43
|
+
}
|
|
44
|
+
return bytes;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const HEX = "0123456789abcdef";
|
|
48
|
+
|
|
49
|
+
/** Canonical lowercase text form of 16 tag bytes. Never throws. */
|
|
50
|
+
export const channelIdFromBytes = (tag: Uint8Array): string | null => {
|
|
51
|
+
if (tag.byteLength !== CHANNEL_ENVELOPE_TAG_BYTES) return null;
|
|
52
|
+
let text = "";
|
|
53
|
+
for (let index = 0; index < CHANNEL_ENVELOPE_TAG_BYTES; index += 1) {
|
|
54
|
+
const byte = tag[index];
|
|
55
|
+
text += HEX[byte >> 4] + HEX[byte & 0x0f];
|
|
56
|
+
if (index === 3 || index === 5 || index === 7 || index === 9) text += "-";
|
|
57
|
+
}
|
|
58
|
+
return isChannelId(text) ? text : null;
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Derive a reconnect-stable UUID for one browser-device-to-device mux channel.
|
|
63
|
+
* Callers must allocate distinct slots for concurrent channels sharing userId,
|
|
64
|
+
* keyId, and browserDeviceId; slot is the disambiguating identity component.
|
|
65
|
+
* NUL delimiters make the UTF-8 identity encoding unambiguous.
|
|
66
|
+
*/
|
|
67
|
+
export const stableChannelId = async (
|
|
68
|
+
userId: string,
|
|
69
|
+
keyId: string,
|
|
70
|
+
browserDeviceId: string,
|
|
71
|
+
slot = 0,
|
|
72
|
+
): Promise<string> => {
|
|
73
|
+
const identity = `${userId}\0${keyId}\0${browserDeviceId}\0${slot}`;
|
|
74
|
+
const digest = await crypto.subtle.digest(
|
|
75
|
+
"SHA-256",
|
|
76
|
+
new TextEncoder().encode(identity),
|
|
77
|
+
);
|
|
78
|
+
const tag = new Uint8Array(digest.slice(0, CHANNEL_ENVELOPE_TAG_BYTES));
|
|
79
|
+
tag[6] = (tag[6] & 0x0f) | 0x40;
|
|
80
|
+
tag[8] = (tag[8] & 0x3f) | 0x80;
|
|
81
|
+
|
|
82
|
+
const channelId = channelIdFromBytes(tag);
|
|
83
|
+
if (channelId === null) {
|
|
84
|
+
throw new Error("derived channel id is not canonical");
|
|
85
|
+
}
|
|
86
|
+
return channelId;
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Wrap one whole WebSocket message using a precomputed 16-byte tag. Prefer this
|
|
91
|
+
* on hot paths that already cache {@link channelIdToBytes} beside the channel.
|
|
92
|
+
*/
|
|
93
|
+
export const encodeChannelEnvelopeWithTag = (
|
|
94
|
+
tag: Uint8Array,
|
|
95
|
+
payload: Uint8Array,
|
|
96
|
+
): Uint8Array => {
|
|
97
|
+
if (tag.byteLength !== CHANNEL_ENVELOPE_TAG_BYTES) {
|
|
98
|
+
throw new RangeError("channel tag must be 16 bytes");
|
|
99
|
+
}
|
|
100
|
+
const encoded = new Uint8Array(
|
|
101
|
+
CHANNEL_ENVELOPE_TAG_BYTES + payload.byteLength,
|
|
102
|
+
);
|
|
103
|
+
encoded.set(tag, 0);
|
|
104
|
+
encoded.set(payload, CHANNEL_ENVELOPE_TAG_BYTES);
|
|
105
|
+
return encoded;
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
/** Wrap one whole WebSocket message. Caller contract violations throw RangeError. */
|
|
109
|
+
export const encodeChannelEnvelope = (
|
|
110
|
+
channelId: string,
|
|
111
|
+
payload: Uint8Array,
|
|
112
|
+
): Uint8Array =>
|
|
113
|
+
encodeChannelEnvelopeWithTag(channelIdToBytes(channelId), payload);
|
|
114
|
+
|
|
115
|
+
export type TChannelEnvelopeDecodeResult =
|
|
116
|
+
| {
|
|
117
|
+
readonly ok: true;
|
|
118
|
+
readonly channelId: string;
|
|
119
|
+
readonly payload: Uint8Array;
|
|
120
|
+
}
|
|
121
|
+
| { readonly ok: false; readonly error: "truncated_envelope" | "bad_tag" };
|
|
122
|
+
|
|
123
|
+
/** Unwrap one whole message. Never throws; the payload is a view (no copy). */
|
|
124
|
+
export const decodeChannelEnvelope = (
|
|
125
|
+
bytes: Uint8Array,
|
|
126
|
+
): TChannelEnvelopeDecodeResult => {
|
|
127
|
+
if (bytes.byteLength < CHANNEL_ENVELOPE_TAG_BYTES) {
|
|
128
|
+
return { ok: false, error: "truncated_envelope" };
|
|
129
|
+
}
|
|
130
|
+
const channelId = channelIdFromBytes(
|
|
131
|
+
bytes.subarray(0, CHANNEL_ENVELOPE_TAG_BYTES),
|
|
132
|
+
);
|
|
133
|
+
if (channelId === null) return { ok: false, error: "bad_tag" };
|
|
134
|
+
return {
|
|
135
|
+
ok: true,
|
|
136
|
+
channelId,
|
|
137
|
+
payload: bytes.subarray(CHANNEL_ENVELOPE_TAG_BYTES),
|
|
138
|
+
};
|
|
139
|
+
};
|