@opengeni/sdk 0.46.0 → 0.52.1
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 +94 -2
- package/dist/artifact-client.d.ts +20 -2
- package/dist/artifacts.d.ts +4 -0
- package/dist/artifacts.js +11 -0
- package/dist/artifacts.js.map +1 -0
- package/dist/chunk-FHI4DFIG.js +128 -0
- package/dist/chunk-FHI4DFIG.js.map +1 -0
- package/dist/chunk-FRJFNDIR.js +218 -0
- package/dist/chunk-FRJFNDIR.js.map +1 -0
- package/dist/{chunk-QKV5OCLJ.js → chunk-ILQZR5N6.js} +1380 -595
- package/dist/chunk-ILQZR5N6.js.map +1 -0
- package/dist/chunk-MZWTWOX6.js +661 -0
- package/dist/chunk-MZWTWOX6.js.map +1 -0
- package/dist/chunk-VWE2QIVO.js +1162 -0
- package/dist/chunk-VWE2QIVO.js.map +1 -0
- package/dist/chunk-VYCTL62C.js +230 -0
- package/dist/chunk-VYCTL62C.js.map +1 -0
- package/dist/client.d.ts +176 -20
- package/dist/codex-realtime-controller.d.ts +6 -6
- package/dist/codex-realtime-lifecycle.d.ts +1 -1
- package/dist/codex-realtime-v3.d.ts +3 -3
- package/dist/codex-realtime.d.ts +1 -1
- package/dist/company-profile.d.ts +100 -0
- package/dist/core.d.ts +5 -5
- package/dist/core.js +9 -4
- package/dist/desktop.d.ts +1 -1
- package/dist/editable-artifact-resources.d.ts +96 -0
- package/dist/editable-artifacts/browser-session.d.ts +35 -0
- package/dist/editable-artifacts/controller.d.ts +60 -0
- package/dist/editable-artifacts/errors.d.ts +23 -0
- package/dist/editable-artifacts/http-live-transport.d.ts +46 -0
- package/dist/editable-artifacts/index.d.ts +19 -0
- package/dist/editable-artifacts/pool.d.ts +15 -0
- package/dist/editable-artifacts/session.d.ts +96 -0
- package/dist/editable-artifacts/storage.d.ts +72 -0
- package/dist/editable-artifacts/types.d.ts +416 -0
- package/dist/editable-artifacts/worker/browser-client.d.ts +80 -0
- package/dist/editable-artifacts/worker/browser-entry.d.ts +6 -0
- package/dist/editable-artifacts/worker/kernel-adapter.d.ts +45 -0
- package/dist/editable-artifacts/worker/rpc-protocol.d.ts +92 -0
- package/dist/editable-artifacts/worker/runtime.d.ts +66 -0
- package/dist/editable-artifacts/worker/wire-codec.d.ts +52 -0
- package/dist/editable-artifacts-worker.d.ts +8 -0
- package/dist/editable-artifacts-worker.js +1708 -0
- package/dist/editable-artifacts-worker.js.map +1 -0
- package/dist/editable-artifacts.d.ts +6 -0
- package/dist/editable-artifacts.js +5954 -0
- package/dist/editable-artifacts.js.map +1 -0
- package/dist/gateway-realtime-transport.d.ts +1 -1
- package/dist/index.d.ts +41 -35
- package/dist/index.js +104 -68
- package/dist/index.js.map +1 -1
- package/dist/interaction.d.ts +885 -0
- package/dist/interaction.js +55 -0
- package/dist/interaction.js.map +1 -0
- package/dist/memory-slack-client.d.ts +13 -0
- package/dist/memory-slack-delivery.d.ts +99 -0
- package/dist/memory-slack.d.ts +4 -0
- package/dist/memory-slack.js +44 -0
- package/dist/memory-slack.js.map +1 -0
- package/dist/proxy.d.ts +3 -3
- package/dist/realtime.d.ts +12 -12
- package/dist/retained-artifacts.d.ts +12 -0
- package/dist/stream.d.ts +16 -1
- package/dist/terminal.d.ts +1 -1
- package/dist/transcription.d.ts +2 -2
- package/dist/types.d.ts +1203 -23
- package/dist/workspace-control-stream.d.ts +2 -2
- package/dist/workspace-state.d.ts +1 -1
- package/package.json +29 -3
- package/src/artifact-client.ts +129 -0
- package/src/artifacts.ts +17 -0
- package/src/client.ts +1801 -206
- package/src/company-profile.ts +92 -0
- package/src/editable-artifact-resources.ts +119 -0
- package/src/editable-artifacts/browser-session.ts +176 -0
- package/src/editable-artifacts/controller.ts +2632 -0
- package/src/editable-artifacts/errors.ts +52 -0
- package/src/editable-artifacts/http-live-transport.ts +1449 -0
- package/src/editable-artifacts/index.ts +175 -0
- package/src/editable-artifacts/pool.ts +81 -0
- package/src/editable-artifacts/session.ts +778 -0
- package/src/editable-artifacts/storage.ts +1718 -0
- package/src/editable-artifacts/types.ts +499 -0
- package/src/editable-artifacts/worker/browser-client.ts +1167 -0
- package/src/editable-artifacts/worker/browser-entry.ts +57 -0
- package/src/editable-artifacts/worker/kernel-adapter.ts +1039 -0
- package/src/editable-artifacts/worker/rpc-protocol.ts +622 -0
- package/src/editable-artifacts/worker/runtime.ts +1204 -0
- package/src/editable-artifacts/worker/wire-codec.ts +852 -0
- package/src/editable-artifacts-worker.ts +8 -0
- package/src/editable-artifacts.ts +6 -0
- package/src/index.ts +194 -0
- package/src/interaction.ts +1830 -0
- package/src/memory-slack-client.ts +71 -0
- package/src/memory-slack-delivery.ts +128 -0
- package/src/memory-slack.ts +19 -0
- package/src/retained-artifacts.ts +326 -0
- package/src/stream.ts +102 -4
- package/src/transcription.ts +2 -2
- package/src/types.ts +1430 -33
- package/src/workspace-control-stream.ts +15 -5
- package/dist/chunk-QKV5OCLJ.js.map +0 -1
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
export const COMPANY_PROFILE_SCALAR_MAX_CHARS = 2_048;
|
|
2
|
+
export const COMPANY_PROFILE_ENTRY_MAX_CHARS = 1_024;
|
|
3
|
+
export const COMPANY_PROFILE_ENTRY_MAX_COUNT = 16;
|
|
4
|
+
|
|
5
|
+
export type CompanyProfileEntry = { key: string; content: string };
|
|
6
|
+
export type CompanyProfileContent = {
|
|
7
|
+
identity: string | null;
|
|
8
|
+
mission: string | null;
|
|
9
|
+
products: CompanyProfileEntry[];
|
|
10
|
+
customers: CompanyProfileEntry[];
|
|
11
|
+
goals: CompanyProfileEntry[];
|
|
12
|
+
constraints: CompanyProfileEntry[];
|
|
13
|
+
};
|
|
14
|
+
export type CompanyProfileRevisionIdentity = {
|
|
15
|
+
id: string;
|
|
16
|
+
revision: number;
|
|
17
|
+
contentHash: string;
|
|
18
|
+
};
|
|
19
|
+
export type CompanyProfileRevision = CompanyProfileRevisionIdentity & {
|
|
20
|
+
operationId: string;
|
|
21
|
+
accountId: string;
|
|
22
|
+
intent: "active" | "proposal";
|
|
23
|
+
profile: CompanyProfileContent;
|
|
24
|
+
provenance: { source: "human" | "durable_learning" | "migration"; sourceId: string | null };
|
|
25
|
+
supersedesRevisionId: string | null;
|
|
26
|
+
createdBySubjectId: string;
|
|
27
|
+
createdAt: string;
|
|
28
|
+
};
|
|
29
|
+
export type CompanyProfileHead = {
|
|
30
|
+
accountId: string;
|
|
31
|
+
revisionId: string;
|
|
32
|
+
revision: number;
|
|
33
|
+
contentHash: string;
|
|
34
|
+
activationVersion: number;
|
|
35
|
+
activatedAt: string;
|
|
36
|
+
};
|
|
37
|
+
export type CompanyProfileActivationEvent = {
|
|
38
|
+
id: string;
|
|
39
|
+
operationId: string;
|
|
40
|
+
accountId: string;
|
|
41
|
+
type: "activate" | "rollback";
|
|
42
|
+
activationVersion: number;
|
|
43
|
+
oldRevision: CompanyProfileRevisionIdentity | null;
|
|
44
|
+
newRevision: CompanyProfileRevisionIdentity | null;
|
|
45
|
+
actorSubjectId: string;
|
|
46
|
+
reason: string;
|
|
47
|
+
createdAt: string;
|
|
48
|
+
};
|
|
49
|
+
export type CompanyProfileListOptions = { afterRevision?: number; limit?: number };
|
|
50
|
+
export type CompanyProfileListResponse = {
|
|
51
|
+
current: CompanyProfileHead | null;
|
|
52
|
+
activeRevision: CompanyProfileRevision | null;
|
|
53
|
+
revisions: CompanyProfileRevision[];
|
|
54
|
+
activationEvents: CompanyProfileActivationEvent[];
|
|
55
|
+
nextAfterRevision: number | null;
|
|
56
|
+
};
|
|
57
|
+
export type UpdateCompanyProfileRequest = {
|
|
58
|
+
operationId?: string;
|
|
59
|
+
profile: CompanyProfileContent;
|
|
60
|
+
expectedCurrentRevisionId: string | null;
|
|
61
|
+
expectedActivationVersion: number;
|
|
62
|
+
reason: string;
|
|
63
|
+
};
|
|
64
|
+
export type ActivateCompanyProfileRevisionRequest = {
|
|
65
|
+
operationId?: string;
|
|
66
|
+
expectedCurrentRevisionId: string | null;
|
|
67
|
+
expectedActivationVersion: number;
|
|
68
|
+
reason: string;
|
|
69
|
+
};
|
|
70
|
+
export type RollbackCompanyProfileRequest = {
|
|
71
|
+
operationId?: string;
|
|
72
|
+
targetRevisionId: string;
|
|
73
|
+
expectedCurrentRevisionId: string;
|
|
74
|
+
expectedActivationVersion: number;
|
|
75
|
+
reason: string;
|
|
76
|
+
};
|
|
77
|
+
export type CompanyProfileMutationResponse = {
|
|
78
|
+
revision: CompanyProfileRevision | null;
|
|
79
|
+
head: CompanyProfileHead | null;
|
|
80
|
+
event: CompanyProfileActivationEvent | null;
|
|
81
|
+
};
|
|
82
|
+
export type CompanyProfileDiffRequest = { fromRevisionId: string; toRevisionId: string };
|
|
83
|
+
export type CompanyProfileDiffResponse = {
|
|
84
|
+
from: CompanyProfileRevision;
|
|
85
|
+
to: CompanyProfileRevision;
|
|
86
|
+
format: "unified_json";
|
|
87
|
+
diff: string;
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
export function normalizeCompanyProfileStableKey(value: string): string {
|
|
91
|
+
return value.normalize("NFKC").trim().toLowerCase().replace(/\s+/gu, "-").replace(/-+/g, "-");
|
|
92
|
+
}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import type { OpenGeniRequestOptions } from "./client";
|
|
2
|
+
import type { EditableArtifactModality } from "./editable-artifacts/types";
|
|
3
|
+
|
|
4
|
+
/** Durable metadata returned by the editable-artifact product API. */
|
|
5
|
+
export type EditableArtifactResource = Readonly<{
|
|
6
|
+
id: string;
|
|
7
|
+
modality: EditableArtifactModality;
|
|
8
|
+
title: string;
|
|
9
|
+
lifecycle: "active" | "archived";
|
|
10
|
+
headSequence: number;
|
|
11
|
+
stateHash: string;
|
|
12
|
+
createdAt: string;
|
|
13
|
+
updatedAt: string;
|
|
14
|
+
}>;
|
|
15
|
+
|
|
16
|
+
export type EditableArtifactListResource = Readonly<{
|
|
17
|
+
artifacts: readonly EditableArtifactResource[];
|
|
18
|
+
}>;
|
|
19
|
+
|
|
20
|
+
export type CreateEditableArtifactResourceRequest = Readonly<{
|
|
21
|
+
/** Stable across transport retries; conflicting reuse is rejected. */
|
|
22
|
+
idempotencyKey: string;
|
|
23
|
+
/** Exact writer replica that will open the first live editing session. */
|
|
24
|
+
replicaId: string;
|
|
25
|
+
modality: EditableArtifactModality;
|
|
26
|
+
title: string;
|
|
27
|
+
}>;
|
|
28
|
+
|
|
29
|
+
export type ImportEditableArtifactResourceRequest = Readonly<{
|
|
30
|
+
idempotencyKey: string;
|
|
31
|
+
replicaId: string;
|
|
32
|
+
modality: EditableArtifactModality;
|
|
33
|
+
title: string;
|
|
34
|
+
sourceFileId: string;
|
|
35
|
+
}>;
|
|
36
|
+
|
|
37
|
+
export type ReadEditableArtifactResourceOptions = OpenGeniRequestOptions &
|
|
38
|
+
Readonly<{
|
|
39
|
+
/** Writer/read replica used to mint artifact-scoped authority. */
|
|
40
|
+
replicaId: string;
|
|
41
|
+
}>;
|
|
42
|
+
|
|
43
|
+
export type ListSessionEditableArtifactResourcesOptions = OpenGeniRequestOptions &
|
|
44
|
+
Readonly<{
|
|
45
|
+
replicaId: string;
|
|
46
|
+
}>;
|
|
47
|
+
|
|
48
|
+
export type EditableArtifactMaterializationFormat =
|
|
49
|
+
| "xlsx"
|
|
50
|
+
| "pptx"
|
|
51
|
+
| "docx"
|
|
52
|
+
| "pdf"
|
|
53
|
+
| "png"
|
|
54
|
+
| "webp";
|
|
55
|
+
|
|
56
|
+
export type EditableArtifactPinnedVersionResource = Readonly<{
|
|
57
|
+
id: string;
|
|
58
|
+
artifactId: string;
|
|
59
|
+
modality: EditableArtifactModality;
|
|
60
|
+
snapshotId: string;
|
|
61
|
+
headSequence: number;
|
|
62
|
+
causalFrontier: readonly Readonly<{ replicaId: string; counter: number }>[] | null;
|
|
63
|
+
nativeRevision: number | null;
|
|
64
|
+
stateHash: string;
|
|
65
|
+
name: string;
|
|
66
|
+
pinned: true;
|
|
67
|
+
createdAt: string;
|
|
68
|
+
replayed: boolean;
|
|
69
|
+
}>;
|
|
70
|
+
|
|
71
|
+
export type PinEditableArtifactVersionRequest = Readonly<{
|
|
72
|
+
replicaId: string;
|
|
73
|
+
idempotencyKey: string;
|
|
74
|
+
name: string;
|
|
75
|
+
}>;
|
|
76
|
+
|
|
77
|
+
export type EditableArtifactMaterializationResultResource = Readonly<{
|
|
78
|
+
id: string;
|
|
79
|
+
byteSize: number;
|
|
80
|
+
contentHash: string;
|
|
81
|
+
mimeType:
|
|
82
|
+
| "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
|
|
83
|
+
| "application/vnd.openxmlformats-officedocument.presentationml.presentation"
|
|
84
|
+
| "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
|
|
85
|
+
| "application/pdf"
|
|
86
|
+
| "image/png"
|
|
87
|
+
| "image/webp";
|
|
88
|
+
verifiedAt: string;
|
|
89
|
+
createdAt: string;
|
|
90
|
+
}>;
|
|
91
|
+
|
|
92
|
+
export type EditableArtifactMaterializationJobResource = Readonly<{
|
|
93
|
+
id: string;
|
|
94
|
+
artifactId: string;
|
|
95
|
+
versionId: string;
|
|
96
|
+
inputSnapshotId: string;
|
|
97
|
+
targetHeadSequence: number;
|
|
98
|
+
stateHash: string;
|
|
99
|
+
format: EditableArtifactMaterializationFormat;
|
|
100
|
+
state: "pending" | "running" | "succeeded" | "failed";
|
|
101
|
+
attemptCount: number;
|
|
102
|
+
errorCode: string | null;
|
|
103
|
+
createdAt: string;
|
|
104
|
+
startedAt: string | null;
|
|
105
|
+
completedAt: string | null;
|
|
106
|
+
result: EditableArtifactMaterializationResultResource | null;
|
|
107
|
+
replayed?: boolean;
|
|
108
|
+
}>;
|
|
109
|
+
|
|
110
|
+
export type CreateEditableArtifactMaterializationRequest = Readonly<{
|
|
111
|
+
replicaId: string;
|
|
112
|
+
idempotencyKey: string;
|
|
113
|
+
versionId: string;
|
|
114
|
+
format: EditableArtifactMaterializationFormat;
|
|
115
|
+
options?: Readonly<Record<string, unknown>>;
|
|
116
|
+
}>;
|
|
117
|
+
|
|
118
|
+
export type ReadEditableArtifactMaterializationOptions = OpenGeniRequestOptions &
|
|
119
|
+
Readonly<{ replicaId: string }>;
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import { DOCUMENT_ARTIFACT_COMMAND_VERSION } from "@opengeni/contracts/document-artifact-commands";
|
|
2
|
+
import { PRESENTATION_ARTIFACT_COMMAND_VERSION } from "@opengeni/contracts/presentation-artifact-commands";
|
|
3
|
+
import { SPREADSHEET_ARTIFACT_COMMAND_VERSION } from "@opengeni/contracts/spreadsheet-artifact-commands";
|
|
4
|
+
|
|
5
|
+
import type { EditableArtifactCacheAuthority } from "./controller";
|
|
6
|
+
import {
|
|
7
|
+
createEditableArtifactHttpLiveTransport,
|
|
8
|
+
type CreateEditableArtifactHttpLiveTransportOptions,
|
|
9
|
+
} from "./http-live-transport";
|
|
10
|
+
import { createEditableArtifactSession, type EditableArtifactSession } from "./session";
|
|
11
|
+
import type { EditableArtifactStoragePort } from "./storage";
|
|
12
|
+
import type { EditableArtifactModality } from "./types";
|
|
13
|
+
import {
|
|
14
|
+
createBrowserEditableArtifactWorkerKernel,
|
|
15
|
+
type CreateBrowserEditableArtifactWorkerKernelOptions,
|
|
16
|
+
} from "./worker/browser-client";
|
|
17
|
+
|
|
18
|
+
export type EditableArtifactBrowserRuntime = Omit<
|
|
19
|
+
CreateBrowserEditableArtifactWorkerKernelOptions,
|
|
20
|
+
"modality" | "kernelVersion" | "protocolVersion" | "modelSchemaVersion" | "commandVersion"
|
|
21
|
+
> &
|
|
22
|
+
Readonly<{
|
|
23
|
+
/** Exact native/WASM build identity admitted by the API. */
|
|
24
|
+
kernelVersion: string;
|
|
25
|
+
modelSchemaVersion: number;
|
|
26
|
+
protocolVersion?: number;
|
|
27
|
+
commandVersion: number;
|
|
28
|
+
}>;
|
|
29
|
+
|
|
30
|
+
export type CreateBrowserEditableArtifactSessionOptions = Readonly<{
|
|
31
|
+
baseUrl: string | URL;
|
|
32
|
+
workspaceId: string;
|
|
33
|
+
artifact: Readonly<{ id: string; modality: EditableArtifactModality }>;
|
|
34
|
+
/** Exact login/grant partition; rotate authorizationEpoch on authority changes. */
|
|
35
|
+
storageAuthority: EditableArtifactCacheAuthority;
|
|
36
|
+
runtime: EditableArtifactBrowserRuntime;
|
|
37
|
+
transport?: Omit<
|
|
38
|
+
CreateEditableArtifactHttpLiveTransportOptions,
|
|
39
|
+
"baseUrl" | "workspaceId" | "protocolVersion" | "kernelVersion" | "modelSchemaVersion"
|
|
40
|
+
>;
|
|
41
|
+
storage?: EditableArtifactStoragePort;
|
|
42
|
+
/** Reuse the replica used to create the artifact when opening it immediately. */
|
|
43
|
+
replicaId?: string;
|
|
44
|
+
}>;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* One production browser composition point: verified WASM Worker, durable WAL,
|
|
48
|
+
* authenticated HTTP/WebSocket transport, replay, and modality projections.
|
|
49
|
+
*/
|
|
50
|
+
export function createBrowserEditableArtifactSession(
|
|
51
|
+
options: CreateBrowserEditableArtifactSessionOptions,
|
|
52
|
+
): EditableArtifactSession {
|
|
53
|
+
const baseUrl = canonicalBaseUrl(options.baseUrl);
|
|
54
|
+
const workspaceId = boundedIdentity(options.workspaceId, "workspaceId");
|
|
55
|
+
assertCacheAuthority(options.storageAuthority, baseUrl, workspaceId);
|
|
56
|
+
const protocolVersion = positiveVersion(options.runtime.protocolVersion ?? 1, "protocolVersion");
|
|
57
|
+
const modelSchemaVersion = positiveVersion(
|
|
58
|
+
options.runtime.modelSchemaVersion,
|
|
59
|
+
"modelSchemaVersion",
|
|
60
|
+
);
|
|
61
|
+
const kernelVersion = boundedIdentity(options.runtime.kernelVersion, "kernelVersion", 512);
|
|
62
|
+
const commandVersion = positiveVersion(options.runtime.commandVersion, "commandVersion");
|
|
63
|
+
const expectedCommandVersion = commandVersionFor(options.artifact.modality);
|
|
64
|
+
if (commandVersion !== expectedCommandVersion) {
|
|
65
|
+
throw new TypeError(
|
|
66
|
+
`commandVersion ${commandVersion} is incompatible with ${options.artifact.modality} ${expectedCommandVersion}`,
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
const {
|
|
70
|
+
kernelVersion: _kernelVersion,
|
|
71
|
+
modelSchemaVersion: _modelSchemaVersion,
|
|
72
|
+
protocolVersion: _protocolVersion,
|
|
73
|
+
commandVersion: _commandVersion,
|
|
74
|
+
...workerOptions
|
|
75
|
+
} = options.runtime;
|
|
76
|
+
const worker = createBrowserEditableArtifactWorkerKernel({
|
|
77
|
+
...workerOptions,
|
|
78
|
+
modality: options.artifact.modality,
|
|
79
|
+
kernelVersion,
|
|
80
|
+
protocolVersion,
|
|
81
|
+
modelSchemaVersion,
|
|
82
|
+
commandVersion,
|
|
83
|
+
});
|
|
84
|
+
const replicaId = options.replicaId;
|
|
85
|
+
try {
|
|
86
|
+
const transport = createEditableArtifactHttpLiveTransport({
|
|
87
|
+
...options.transport,
|
|
88
|
+
baseUrl,
|
|
89
|
+
workspaceId,
|
|
90
|
+
protocolVersion,
|
|
91
|
+
kernelVersion,
|
|
92
|
+
modelSchemaVersion,
|
|
93
|
+
});
|
|
94
|
+
return createEditableArtifactSession({
|
|
95
|
+
artifactId: options.artifact.id,
|
|
96
|
+
modality: options.artifact.modality,
|
|
97
|
+
storageAuthority: options.storageAuthority,
|
|
98
|
+
transport,
|
|
99
|
+
worker,
|
|
100
|
+
...(options.storage ? { storage: options.storage } : {}),
|
|
101
|
+
kernelVersion,
|
|
102
|
+
modelSchemaVersion,
|
|
103
|
+
commandVersion,
|
|
104
|
+
protocolVersion,
|
|
105
|
+
...(replicaId ? { writerReplicaIdFactory: () => replicaId } : {}),
|
|
106
|
+
ownsWorker: true,
|
|
107
|
+
});
|
|
108
|
+
} catch (error) {
|
|
109
|
+
void worker.dispose().catch(() => undefined);
|
|
110
|
+
throw error;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** Generates the portable 64-bit nonzero replica identity used by create/open. */
|
|
115
|
+
export function createEditableArtifactReplicaId(): string {
|
|
116
|
+
for (;;) {
|
|
117
|
+
const value = [...crypto.getRandomValues(new Uint8Array(8))]
|
|
118
|
+
.map((byte) => byte.toString(16).padStart(2, "0"))
|
|
119
|
+
.join("");
|
|
120
|
+
if (value !== "0000000000000000") return value;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function commandVersionFor(modality: EditableArtifactModality): number {
|
|
125
|
+
switch (modality) {
|
|
126
|
+
case "spreadsheet":
|
|
127
|
+
return SPREADSHEET_ARTIFACT_COMMAND_VERSION;
|
|
128
|
+
case "document":
|
|
129
|
+
return DOCUMENT_ARTIFACT_COMMAND_VERSION;
|
|
130
|
+
case "presentation":
|
|
131
|
+
return PRESENTATION_ARTIFACT_COMMAND_VERSION;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function canonicalBaseUrl(value: string | URL): URL {
|
|
136
|
+
const url = new URL(value);
|
|
137
|
+
if (url.username || url.password || url.search || url.hash) {
|
|
138
|
+
throw new TypeError("baseUrl must not contain credentials, query, or fragment");
|
|
139
|
+
}
|
|
140
|
+
if (url.protocol !== "https:" && url.protocol !== "http:") {
|
|
141
|
+
throw new TypeError("baseUrl must use HTTP or HTTPS");
|
|
142
|
+
}
|
|
143
|
+
return url;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function assertCacheAuthority(
|
|
147
|
+
authority: EditableArtifactCacheAuthority,
|
|
148
|
+
baseUrl: URL,
|
|
149
|
+
workspaceId: string,
|
|
150
|
+
): void {
|
|
151
|
+
if (new URL(authority.deploymentOrigin).origin !== baseUrl.origin) {
|
|
152
|
+
throw new TypeError("storageAuthority deployment origin does not match baseUrl");
|
|
153
|
+
}
|
|
154
|
+
if (authority.workspaceId !== workspaceId) {
|
|
155
|
+
throw new TypeError("storageAuthority workspace does not match workspaceId");
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
function boundedIdentity(value: string, label: string, maximum = 256): string {
|
|
160
|
+
if (
|
|
161
|
+
typeof value !== "string" ||
|
|
162
|
+
value.length === 0 ||
|
|
163
|
+
value.trim() !== value ||
|
|
164
|
+
new TextEncoder().encode(value).byteLength > maximum
|
|
165
|
+
) {
|
|
166
|
+
throw new TypeError(`${label} is malformed`);
|
|
167
|
+
}
|
|
168
|
+
return value;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
function positiveVersion(value: number, label: string): number {
|
|
172
|
+
if (!Number.isSafeInteger(value) || value < 1 || value > 65_535) {
|
|
173
|
+
throw new TypeError(`${label} must be a positive 16-bit integer`);
|
|
174
|
+
}
|
|
175
|
+
return value;
|
|
176
|
+
}
|