agl 1.0.17 → 21.0.2
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/.smartconfig.json +55 -0
- package/changelog.md +1026 -0
- package/cli.js +14 -0
- package/dist_serve/bundle.js +44778 -0
- package/dist_serve/index.html +13 -0
- package/dist_ts/00_commitinfo_data.d.ts +8 -0
- package/dist_ts/00_commitinfo_data.js +9 -0
- package/dist_ts/classes.authmodels.d.ts +126 -0
- package/dist_ts/classes.authmodels.js +1422 -0
- package/dist_ts/classes.authstore.d.ts +160 -0
- package/dist_ts/classes.authstore.js +2483 -0
- package/dist_ts/classes.browserresourcehost.d.ts +85 -0
- package/dist_ts/classes.browserresourcehost.js +912 -0
- package/dist_ts/classes.cli.d.ts +21 -0
- package/dist_ts/classes.cli.js +1082 -0
- package/dist_ts/classes.config.d.ts +23 -0
- package/dist_ts/classes.config.js +267 -0
- package/dist_ts/classes.controller.d.ts +523 -0
- package/dist_ts/classes.controller.js +10611 -0
- package/dist_ts/classes.controllermanagement.d.ts +32 -0
- package/dist_ts/classes.controllermanagement.js +222 -0
- package/dist_ts/classes.draftmanager.d.ts +30 -0
- package/dist_ts/classes.draftmanager.js +179 -0
- package/dist_ts/classes.embeddeddb.d.ts +30 -0
- package/dist_ts/classes.embeddeddb.js +159 -0
- package/dist_ts/classes.flexframedtransport.d.ts +56 -0
- package/dist_ts/classes.flexframedtransport.js +275 -0
- package/dist_ts/classes.flexmodels.private.d.ts +231 -0
- package/dist_ts/classes.flexmodels.private.js +985 -0
- package/dist_ts/classes.flexmodels.public.d.ts +207 -0
- package/dist_ts/classes.flexmodels.public.js +885 -0
- package/dist_ts/classes.flexprojectionreader.d.ts +89 -0
- package/dist_ts/classes.flexprojectionreader.js +580 -0
- package/dist_ts/classes.flexservice.d.ts +196 -0
- package/dist_ts/classes.flexservice.js +3704 -0
- package/dist_ts/classes.flexstore.d.ts +174 -0
- package/dist_ts/classes.flexstore.js +3400 -0
- package/dist_ts/classes.flexsupervisor.d.ts +105 -0
- package/dist_ts/classes.flexsupervisor.js +1191 -0
- package/dist_ts/classes.gitreversion.d.ts +431 -0
- package/dist_ts/classes.gitreversion.js +10592 -0
- package/dist_ts/classes.harnessoperationmanager.d.ts +113 -0
- package/dist_ts/classes.harnessoperationmanager.js +602 -0
- package/dist_ts/classes.opencodeclient.d.ts +146 -0
- package/dist_ts/classes.opencodeclient.js +3003 -0
- package/dist_ts/classes.opencodesupervisor.d.ts +60 -0
- package/dist_ts/classes.opencodesupervisor.js +1003 -0
- package/dist_ts/classes.passkeymanager.d.ts +34 -0
- package/dist_ts/classes.passkeymanager.js +456 -0
- package/dist_ts/classes.processinspection.d.ts +50 -0
- package/dist_ts/classes.processinspection.js +484 -0
- package/dist_ts/classes.resourcecoordinator.d.ts +64 -0
- package/dist_ts/classes.resourcecoordinator.js +294 -0
- package/dist_ts/classes.sessionintelligencereader.d.ts +13 -0
- package/dist_ts/classes.sessionintelligencereader.js +40 -0
- package/dist_ts/classes.systemmetricssampler.d.ts +53 -0
- package/dist_ts/classes.systemmetricssampler.js +168 -0
- package/dist_ts/classes.terminalmanager.d.ts +95 -0
- package/dist_ts/classes.terminalmanager.js +981 -0
- package/dist_ts/classes.terminalresourcehost.d.ts +20 -0
- package/dist_ts/classes.terminalresourcehost.js +84 -0
- package/dist_ts/classes.upgradecoordinator.d.ts +244 -0
- package/dist_ts/classes.upgradecoordinator.js +2155 -0
- package/dist_ts/classes.upgradetransaction.d.ts +92 -0
- package/dist_ts/classes.upgradetransaction.js +2125 -0
- package/dist_ts/classes.uploadmanager.d.ts +24 -0
- package/dist_ts/classes.uploadmanager.js +210 -0
- package/dist_ts/classes.validation.d.ts +91 -0
- package/dist_ts/classes.validation.js +1087 -0
- package/dist_ts/flexharness.child.d.ts +1 -0
- package/dist_ts/flexharness.child.js +28 -0
- package/dist_ts/functions.canonicaldirectory.d.ts +21 -0
- package/dist_ts/functions.canonicaldirectory.js +144 -0
- package/dist_ts/functions.controllerdataroot.d.ts +15 -0
- package/dist_ts/functions.controllerdataroot.js +76 -0
- package/dist_ts/functions.embeddeddb.d.ts +2 -0
- package/dist_ts/functions.embeddeddb.js +21 -0
- package/dist_ts/functions.flexcredentialstore.d.ts +16 -0
- package/dist_ts/functions.flexcredentialstore.js +93 -0
- package/dist_ts/functions.opencodeauth.d.ts +3 -0
- package/dist_ts/functions.opencodeauth.js +31 -0
- package/dist_ts/functions.runtimeenvironment.d.ts +2 -0
- package/dist_ts/functions.runtimeenvironment.js +79 -0
- package/dist_ts/functions.upgradefollower.d.ts +3 -0
- package/dist_ts/functions.upgradefollower.js +95 -0
- package/dist_ts/index.d.ts +24 -0
- package/dist_ts/index.js +25 -0
- package/dist_ts/interfaces.auth.d.ts +181 -0
- package/dist_ts/interfaces.auth.js +82 -0
- package/dist_ts/interfaces.config.d.ts +34 -0
- package/dist_ts/interfaces.config.js +2 -0
- package/dist_ts/interfaces.flexipc.d.ts +939 -0
- package/dist_ts/interfaces.flexipc.js +1492 -0
- package/dist_ts/interfaces.gitreversion.d.ts +246 -0
- package/dist_ts/interfaces.gitreversion.js +2 -0
- package/dist_ts/interfaces.lifecycle.d.ts +37 -0
- package/dist_ts/interfaces.lifecycle.js +2 -0
- package/dist_ts/interfaces.opencode.d.ts +101 -0
- package/dist_ts/interfaces.opencode.js +3 -0
- package/dist_ts/interfaces.projects.d.ts +156 -0
- package/dist_ts/interfaces.projects.js +5 -0
- package/dist_ts/plugins.d.ts +36 -0
- package/dist_ts/plugins.js +40 -0
- package/dist_ts_interfaces/index.d.ts +2 -0
- package/dist_ts_interfaces/index.js +3 -0
- package/dist_ts_interfaces/interfaces.d.ts +747 -0
- package/dist_ts_interfaces/interfaces.js +47 -0
- package/dist_ts_interfaces/plugins.d.ts +4 -0
- package/dist_ts_interfaces/plugins.js +3 -0
- package/dist_ts_interfaces/requests.d.ts +806 -0
- package/dist_ts_interfaces/requests.js +2 -0
- package/dist_ts_migration/classes.documentmigrationrunner.d.ts +8 -0
- package/dist_ts_migration/classes.documentmigrationrunner.js +24 -0
- package/dist_ts_migration/classes.flexmigrationrunner.d.ts +11 -0
- package/dist_ts_migration/classes.flexmigrationrunner.js +25 -0
- package/dist_ts_migration/classes.flexpostharnessmigrationrunner.d.ts +10 -0
- package/dist_ts_migration/classes.flexpostharnessmigrationrunner.js +15 -0
- package/dist_ts_migration/classes.migrationrunner.d.ts +8 -0
- package/dist_ts_migration/classes.migrationrunner.js +34 -0
- package/dist_ts_migration/index.d.ts +12 -0
- package/dist_ts_migration/index.js +13 -0
- package/dist_ts_migration/v10_flexharnessv3migration.d.ts +11 -0
- package/dist_ts_migration/v10_flexharnessv3migration.js +23 -0
- package/dist_ts_migration/v13_flexprojectionorder.d.ts +11 -0
- package/dist_ts_migration/v13_flexprojectionorder.js +23 -0
- package/dist_ts_migration/v16_flexprovidercredentials.d.ts +22 -0
- package/dist_ts_migration/v16_flexprovidercredentials.js +149 -0
- package/dist_ts_migration/v18_resourcelayout.d.ts +22 -0
- package/dist_ts_migration/v18_resourcelayout.js +23 -0
- package/dist_ts_migration/v18_resourcelayoutmigration.d.ts +6 -0
- package/dist_ts_migration/v18_resourcelayoutmigration.js +61 -0
- package/dist_ts_migration/v19_flexprojectmanagement.d.ts +11 -0
- package/dist_ts_migration/v19_flexprojectmanagement.js +21 -0
- package/dist_ts_migration/v1_embeddeddatabaselocation.d.ts +28 -0
- package/dist_ts_migration/v1_embeddeddatabaselocation.js +415 -0
- package/dist_ts_migration/v22_projectfilesystemidentitymigration.d.ts +7 -0
- package/dist_ts_migration/v22_projectfilesystemidentitymigration.js +105 -0
- package/dist_ts_migration/v2_controllerdataroot.d.ts +130 -0
- package/dist_ts_migration/v2_controllerdataroot.js +1887 -0
- package/dist_ts_migration/v6_protocoldocumentmigration.d.ts +7 -0
- package/dist_ts_migration/v6_protocoldocumentmigration.js +100 -0
- package/dist_ts_migration/v6_protocoldocuments.d.ts +7 -0
- package/dist_ts_migration/v6_protocoldocuments.js +138 -0
- package/html/index.html +13 -0
- package/{LICENSE → license.md} +2 -2
- package/package.json +86 -48
- package/readme.md +480 -0
- package/readme.plan.md +188 -0
- package/ts/00_commitinfo_data.ts +8 -0
- package/ts/classes.authmodels.ts +1245 -0
- package/ts/classes.authstore.ts +3274 -0
- package/ts/classes.browserresourcehost.ts +1205 -0
- package/ts/classes.cli.ts +1254 -0
- package/ts/classes.config.ts +351 -0
- package/ts/classes.controller.ts +14426 -0
- package/ts/classes.controllermanagement.ts +330 -0
- package/ts/classes.draftmanager.ts +232 -0
- package/ts/classes.embeddeddb.ts +166 -0
- package/ts/classes.flexframedtransport.ts +283 -0
- package/ts/classes.flexmodels.private.ts +823 -0
- package/ts/classes.flexmodels.public.ts +732 -0
- package/ts/classes.flexprojectionreader.ts +816 -0
- package/ts/classes.flexservice.ts +4302 -0
- package/ts/classes.flexstore.ts +4565 -0
- package/ts/classes.flexsupervisor.ts +1453 -0
- package/ts/classes.gitreversion.ts +13353 -0
- package/ts/classes.harnessoperationmanager.ts +870 -0
- package/ts/classes.opencodeclient.ts +4110 -0
- package/ts/classes.opencodesupervisor.ts +1280 -0
- package/ts/classes.passkeymanager.ts +570 -0
- package/ts/classes.processinspection.ts +623 -0
- package/ts/classes.resourcecoordinator.ts +436 -0
- package/ts/classes.sessionintelligencereader.ts +52 -0
- package/ts/classes.systemmetricssampler.ts +215 -0
- package/ts/classes.terminalmanager.ts +1207 -0
- package/ts/classes.terminalresourcehost.ts +122 -0
- package/ts/classes.upgradecoordinator.ts +2675 -0
- package/ts/classes.upgradetransaction.ts +2900 -0
- package/ts/classes.uploadmanager.ts +240 -0
- package/ts/classes.validation.ts +1409 -0
- package/ts/flexharness.child.ts +35 -0
- package/ts/functions.canonicaldirectory.ts +213 -0
- package/ts/functions.controllerdataroot.ts +107 -0
- package/ts/functions.embeddeddb.ts +22 -0
- package/ts/functions.flexcredentialstore.ts +128 -0
- package/ts/functions.opencodeauth.ts +34 -0
- package/ts/functions.runtimeenvironment.ts +90 -0
- package/ts/functions.upgradefollower.ts +115 -0
- package/ts/index.ts +36 -6
- package/ts/interfaces.auth.ts +316 -0
- package/ts/interfaces.config.ts +37 -0
- package/ts/interfaces.flexipc.ts +2586 -0
- package/ts/interfaces.gitreversion.ts +336 -0
- package/ts/interfaces.lifecycle.ts +46 -0
- package/ts/interfaces.opencode.ts +153 -0
- package/ts/interfaces.projects.ts +182 -0
- package/ts/plugins.ts +64 -0
- package/ts_interfaces/index.ts +2 -0
- package/ts_interfaces/interfaces.ts +827 -0
- package/ts_interfaces/plugins.ts +15 -0
- package/ts_interfaces/requests.ts +1186 -0
- package/ts_migration/classes.documentmigrationrunner.ts +32 -0
- package/ts_migration/classes.flexmigrationrunner.ts +33 -0
- package/ts_migration/classes.flexpostharnessmigrationrunner.ts +22 -0
- package/ts_migration/classes.migrationrunner.ts +40 -0
- package/ts_migration/index.ts +12 -0
- package/ts_migration/v10_flexharnessv3migration.ts +35 -0
- package/ts_migration/v13_flexprojectionorder.ts +33 -0
- package/ts_migration/v16_flexprovidercredentials.ts +196 -0
- package/ts_migration/v18_resourcelayout.ts +55 -0
- package/ts_migration/v18_resourcelayoutmigration.ts +68 -0
- package/ts_migration/v19_flexprojectmanagement.ts +28 -0
- package/ts_migration/v1_embeddeddatabaselocation.ts +560 -0
- package/ts_migration/v22_projectfilesystemidentitymigration.ts +121 -0
- package/ts_migration/v2_controllerdataroot.ts +2349 -0
- package/ts_migration/v6_protocoldocumentmigration.ts +144 -0
- package/ts_migration/v6_protocoldocuments.ts +198 -0
- package/ts_web/00_commitinfo_data.ts +8 -0
- package/ts_web/classes.controllersocketclient.ts +517 -0
- package/ts_web/classes.sessiondraftsync.ts +390 -0
- package/ts_web/elements.harnesscontrollerapp.ts +11494 -0
- package/ts_web/index.ts +2 -0
- package/ts_web/plugins.ts +31 -0
- package/.gitlab-ci.yml +0 -71
- package/.npmignore +0 -5
- package/README.md +0 -40
- package/dist/cli.js +0 -2
- package/dist/index.d.ts +0 -0
- package/dist/index.js +0 -9
- package/dist/mod_bundle/index.d.ts +0 -1
- package/dist/mod_bundle/index.js +0 -18
- package/dist/mod_bundle/mod.plugins.d.ts +0 -4
- package/dist/mod_bundle/mod.plugins.js +0 -11
- package/dist/mod_install/index.d.ts +0 -4
- package/dist/mod_install/index.js +0 -21
- package/dist/mod_install/mod.plugins.d.ts +0 -1
- package/dist/mod_install/mod.plugins.js +0 -7
- package/dist/mod_standard/index.d.ts +0 -4
- package/dist/mod_standard/index.js +0 -21
- package/dist/mod_standard/mod.browser.d.ts +0 -6
- package/dist/mod_standard/mod.browser.js +0 -14
- package/dist/mod_standard/mod.clean.d.ts +0 -4
- package/dist/mod_standard/mod.clean.js +0 -12
- package/dist/mod_standard/mod.compile.d.ts +0 -4
- package/dist/mod_standard/mod.compile.js +0 -21
- package/dist/mod_standard/mod.plugins.d.ts +0 -8
- package/dist/mod_standard/mod.plugins.js +0 -19
- package/dist/mod_standard/mod.test.d.ts +0 -4
- package/dist/mod_standard/mod.test.js +0 -12
- package/dist/plr.cli.d.ts +0 -3
- package/dist/plr.cli.js +0 -57
- package/dist/plr.config.d.ts +0 -11
- package/dist/plr.config.js +0 -26
- package/dist/plr.mods.d.ts +0 -17
- package/dist/plr.mods.js +0 -17
- package/dist/plr.paths.d.ts +0 -19
- package/dist/plr.paths.js +0 -26
- package/dist/plr.plugins.d.ts +0 -8
- package/dist/plr.plugins.js +0 -16
- package/npmextra.json +0 -10
- package/ts/mod_bundle/index.ts +0 -20
- package/ts/mod_bundle/mod.plugins.ts +0 -9
- package/ts/mod_install/index.ts +0 -20
- package/ts/mod_install/mod.plugins.ts +0 -1
- package/ts/mod_standard/index.ts +0 -23
- package/ts/mod_standard/mod.browser.ts +0 -17
- package/ts/mod_standard/mod.clean.ts +0 -13
- package/ts/mod_standard/mod.compile.ts +0 -23
- package/ts/mod_standard/mod.plugins.ts +0 -17
- package/ts/mod_standard/mod.test.ts +0 -13
- package/ts/plr.cli.ts +0 -60
- package/ts/plr.config.ts +0 -36
- package/ts/plr.mods.ts +0 -25
- package/ts/plr.paths.ts +0 -29
- package/ts/plr.plugins.ts +0 -17
- package/tslint.json +0 -3
- package/yarn.lock +0 -3464
|
@@ -0,0 +1,823 @@
|
|
|
1
|
+
import * as plugins from './plugins.js';
|
|
2
|
+
import {
|
|
3
|
+
type IFlexModelChoice,
|
|
4
|
+
type IFlexPublicAccountSummary,
|
|
5
|
+
hasFlexExactKeys,
|
|
6
|
+
isFlexPlainObject,
|
|
7
|
+
isFlexPublicProviderConnection,
|
|
8
|
+
} from './interfaces.flexipc.js';
|
|
9
|
+
import {
|
|
10
|
+
type IFlexProjectionSourceManifest,
|
|
11
|
+
isFlexProjectionSourceManifest,
|
|
12
|
+
} from './classes.flexmodels.public.js';
|
|
13
|
+
|
|
14
|
+
export const flexPrivateChunkBytes = 384 * 1024;
|
|
15
|
+
|
|
16
|
+
export type TFlexDomainKind =
|
|
17
|
+
| 'scope'
|
|
18
|
+
| 'projection'
|
|
19
|
+
| 'permission'
|
|
20
|
+
| 'agentEvents'
|
|
21
|
+
| 'agentArchive'
|
|
22
|
+
| 'jobs';
|
|
23
|
+
|
|
24
|
+
export interface IFlexPrivateChunkManifest {
|
|
25
|
+
id: string;
|
|
26
|
+
index: number;
|
|
27
|
+
sha256: string;
|
|
28
|
+
bytes: number;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface IFlexPrivateCandidateManifest {
|
|
32
|
+
candidateId: string;
|
|
33
|
+
revision: number;
|
|
34
|
+
sha256: string;
|
|
35
|
+
bytes: number;
|
|
36
|
+
chunks: IFlexPrivateChunkManifest[];
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface IFlexPrivateChunkDocument extends IFlexPrivateChunkManifest {
|
|
40
|
+
controllerId: string;
|
|
41
|
+
scopeId: string;
|
|
42
|
+
candidateId: string;
|
|
43
|
+
revision: number;
|
|
44
|
+
data: string;
|
|
45
|
+
createdAt: string;
|
|
46
|
+
domain?: TFlexDomainKind;
|
|
47
|
+
incarnationId?: string;
|
|
48
|
+
sessionId?: string;
|
|
49
|
+
archiveId?: string;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export interface IFlexPrivateCandidateDocument extends IFlexPrivateCandidateManifest {
|
|
53
|
+
id: string;
|
|
54
|
+
controllerId: string;
|
|
55
|
+
scopeId: string;
|
|
56
|
+
createdAt: string;
|
|
57
|
+
domain?: TFlexDomainKind;
|
|
58
|
+
incarnationId?: string;
|
|
59
|
+
sessionId?: string;
|
|
60
|
+
archiveId?: string;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export interface IFlexDomainHeadDocument {
|
|
64
|
+
id: string;
|
|
65
|
+
controllerId: string;
|
|
66
|
+
storageKey: string;
|
|
67
|
+
domain: TFlexDomainKind;
|
|
68
|
+
incarnationId: string;
|
|
69
|
+
revision: number;
|
|
70
|
+
currentPrivateCandidateId: string;
|
|
71
|
+
privateCandidate: IFlexPrivateCandidateManifest;
|
|
72
|
+
projectionSource?: IFlexProjectionSourceManifest;
|
|
73
|
+
sessionId?: string;
|
|
74
|
+
archiveId?: string;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export interface IFlexWriterLeaseDocument {
|
|
78
|
+
id: string;
|
|
79
|
+
controllerId: string;
|
|
80
|
+
storageKey: string;
|
|
81
|
+
ownerToken: string;
|
|
82
|
+
epoch: number;
|
|
83
|
+
state: 'active' | 'released';
|
|
84
|
+
expiresAt: number;
|
|
85
|
+
updatedAt: string;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export interface IFlexMigrationDocument {
|
|
89
|
+
id: string;
|
|
90
|
+
controllerId: string;
|
|
91
|
+
storageKey: string;
|
|
92
|
+
migration: 'flexharness-v3';
|
|
93
|
+
legacyRevision: number;
|
|
94
|
+
legacyCandidateId: string;
|
|
95
|
+
completedAt: string;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export interface IFlexLegacyPublicCandidateManifest {
|
|
99
|
+
candidateId: string;
|
|
100
|
+
revision: number;
|
|
101
|
+
sha256: string;
|
|
102
|
+
bytes: number;
|
|
103
|
+
sessionRecords: Array<{ id: string; sha256: string; bytes: number }>;
|
|
104
|
+
messageRecords: Array<{ id: string; sha256: string; bytes: number }>;
|
|
105
|
+
sessionsTruncated: boolean;
|
|
106
|
+
messagesTruncated: boolean;
|
|
107
|
+
messageBytesTruncated: boolean;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export interface IFlexHeadDocument {
|
|
111
|
+
id: string;
|
|
112
|
+
controllerId: string;
|
|
113
|
+
storageKey: string;
|
|
114
|
+
revision: number;
|
|
115
|
+
currentPrivateCandidateId: string;
|
|
116
|
+
currentPublicCandidateId: string;
|
|
117
|
+
privateCandidates: IFlexPrivateCandidateManifest[];
|
|
118
|
+
publicCandidates: IFlexLegacyPublicCandidateManifest[];
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export interface IFlexProviderConnectionDocument {
|
|
122
|
+
id: string;
|
|
123
|
+
controllerId: string;
|
|
124
|
+
providerId: 'openai';
|
|
125
|
+
state: 'pending' | 'active' | 'deleting' | 'reauthRequired';
|
|
126
|
+
generation: number;
|
|
127
|
+
createdAt: string;
|
|
128
|
+
updatedAt: string;
|
|
129
|
+
account?: IFlexPublicAccountSummary;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export interface IFlexModelChoiceDocument {
|
|
133
|
+
id: string;
|
|
134
|
+
controllerId: string;
|
|
135
|
+
projectId: string;
|
|
136
|
+
generation: number;
|
|
137
|
+
choice: IFlexModelChoice;
|
|
138
|
+
updatedAt: string;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
const digestPattern = /^[a-f0-9]{64}$/u;
|
|
142
|
+
const candidateIdPattern = /^[A-Za-z0-9_-]{22}$/u;
|
|
143
|
+
const ownerTokenPattern = /^[A-Za-z0-9_-]{43}$/u;
|
|
144
|
+
const qualifiedConnectionIdPattern = /^flex:provider:openai:[A-Za-z0-9_-]{22}$/u;
|
|
145
|
+
|
|
146
|
+
const isBoundedString = (valueArg: unknown, maximumBytesArg: number): valueArg is string =>
|
|
147
|
+
typeof valueArg === 'string'
|
|
148
|
+
&& valueArg.length > 0
|
|
149
|
+
&& Buffer.byteLength(valueArg, 'utf8') <= maximumBytesArg;
|
|
150
|
+
|
|
151
|
+
const isNonNegativeInteger = (valueArg: unknown): valueArg is number =>
|
|
152
|
+
Number.isSafeInteger(valueArg) && (valueArg as number) >= 0;
|
|
153
|
+
|
|
154
|
+
const isIsoDate = (valueArg: unknown): valueArg is string =>
|
|
155
|
+
typeof valueArg === 'string'
|
|
156
|
+
&& Number.isFinite(Date.parse(valueArg))
|
|
157
|
+
&& new Date(valueArg).toISOString() === valueArg;
|
|
158
|
+
|
|
159
|
+
const hasValidOptionalDomainIdentity = (valueArg: Record<string, unknown>): boolean => {
|
|
160
|
+
if (valueArg.domain === undefined) {
|
|
161
|
+
return valueArg.incarnationId === undefined
|
|
162
|
+
&& valueArg.sessionId === undefined
|
|
163
|
+
&& valueArg.archiveId === undefined;
|
|
164
|
+
}
|
|
165
|
+
const sessionDomain = valueArg.domain === 'projection'
|
|
166
|
+
|| valueArg.domain === 'permission'
|
|
167
|
+
|| valueArg.domain === 'agentEvents'
|
|
168
|
+
|| valueArg.domain === 'agentArchive'
|
|
169
|
+
|| valueArg.domain === 'jobs';
|
|
170
|
+
const archiveDomain = valueArg.domain === 'agentArchive';
|
|
171
|
+
return ['scope', 'projection', 'permission', 'agentEvents', 'agentArchive', 'jobs']
|
|
172
|
+
.includes(String(valueArg.domain))
|
|
173
|
+
&& typeof valueArg.incarnationId === 'string'
|
|
174
|
+
&& candidateIdPattern.test(valueArg.incarnationId)
|
|
175
|
+
&& (sessionDomain
|
|
176
|
+
? isBoundedString(valueArg.sessionId, 512)
|
|
177
|
+
: valueArg.sessionId === undefined)
|
|
178
|
+
&& (archiveDomain
|
|
179
|
+
? isBoundedString(valueArg.archiveId, 512)
|
|
180
|
+
: valueArg.archiveId === undefined);
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
export const isFlexPrivateChunkManifest = (
|
|
184
|
+
valueArg: unknown,
|
|
185
|
+
): valueArg is IFlexPrivateChunkManifest => isFlexPlainObject(valueArg)
|
|
186
|
+
&& hasFlexExactKeys(valueArg, ['id', 'index', 'sha256', 'bytes'])
|
|
187
|
+
&& isBoundedString(valueArg.id, 1024)
|
|
188
|
+
&& isNonNegativeInteger(valueArg.index)
|
|
189
|
+
&& typeof valueArg.sha256 === 'string'
|
|
190
|
+
&& digestPattern.test(valueArg.sha256)
|
|
191
|
+
&& isNonNegativeInteger(valueArg.bytes)
|
|
192
|
+
&& valueArg.bytes <= flexPrivateChunkBytes;
|
|
193
|
+
|
|
194
|
+
export const isFlexPrivateCandidateManifest = (
|
|
195
|
+
valueArg: unknown,
|
|
196
|
+
): valueArg is IFlexPrivateCandidateManifest => isFlexPlainObject(valueArg)
|
|
197
|
+
&& hasFlexExactKeys(valueArg, ['candidateId', 'revision', 'sha256', 'bytes', 'chunks'])
|
|
198
|
+
&& typeof valueArg.candidateId === 'string'
|
|
199
|
+
&& candidateIdPattern.test(valueArg.candidateId)
|
|
200
|
+
&& isNonNegativeInteger(valueArg.revision)
|
|
201
|
+
&& typeof valueArg.sha256 === 'string'
|
|
202
|
+
&& digestPattern.test(valueArg.sha256)
|
|
203
|
+
&& isNonNegativeInteger(valueArg.bytes)
|
|
204
|
+
&& Array.isArray(valueArg.chunks)
|
|
205
|
+
&& valueArg.chunks.length >= 1
|
|
206
|
+
&& valueArg.chunks.every(isFlexPrivateChunkManifest)
|
|
207
|
+
&& valueArg.chunks.every((chunk, index) => chunk.index === index)
|
|
208
|
+
&& valueArg.chunks.reduce((total, chunk) => total + chunk.bytes, 0) === valueArg.bytes;
|
|
209
|
+
|
|
210
|
+
const isFlexLegacyRecordManifest = (valueArg: unknown): boolean => isFlexPlainObject(valueArg)
|
|
211
|
+
&& hasFlexExactKeys(valueArg, ['id', 'sha256', 'bytes'])
|
|
212
|
+
&& isBoundedString(valueArg.id, 1024)
|
|
213
|
+
&& typeof valueArg.sha256 === 'string'
|
|
214
|
+
&& digestPattern.test(valueArg.sha256)
|
|
215
|
+
&& isNonNegativeInteger(valueArg.bytes);
|
|
216
|
+
|
|
217
|
+
const isFlexLegacyPublicCandidateManifest = (
|
|
218
|
+
valueArg: unknown,
|
|
219
|
+
): valueArg is IFlexLegacyPublicCandidateManifest => isFlexPlainObject(valueArg)
|
|
220
|
+
&& hasFlexExactKeys(valueArg, [
|
|
221
|
+
'candidateId', 'revision', 'sha256', 'bytes',
|
|
222
|
+
'sessionRecords', 'messageRecords', 'sessionsTruncated',
|
|
223
|
+
'messagesTruncated', 'messageBytesTruncated',
|
|
224
|
+
])
|
|
225
|
+
&& typeof valueArg.candidateId === 'string'
|
|
226
|
+
&& candidateIdPattern.test(valueArg.candidateId)
|
|
227
|
+
&& isNonNegativeInteger(valueArg.revision)
|
|
228
|
+
&& typeof valueArg.sha256 === 'string'
|
|
229
|
+
&& digestPattern.test(valueArg.sha256)
|
|
230
|
+
&& isNonNegativeInteger(valueArg.bytes)
|
|
231
|
+
&& Array.isArray(valueArg.sessionRecords)
|
|
232
|
+
&& valueArg.sessionRecords.every(isFlexLegacyRecordManifest)
|
|
233
|
+
&& Array.isArray(valueArg.messageRecords)
|
|
234
|
+
&& valueArg.messageRecords.every(isFlexLegacyRecordManifest)
|
|
235
|
+
&& typeof valueArg.sessionsTruncated === 'boolean'
|
|
236
|
+
&& typeof valueArg.messagesTruncated === 'boolean'
|
|
237
|
+
&& typeof valueArg.messageBytesTruncated === 'boolean';
|
|
238
|
+
|
|
239
|
+
export function assertFlexPrivateChunkDocument(
|
|
240
|
+
valueArg: unknown,
|
|
241
|
+
): asserts valueArg is IFlexPrivateChunkDocument {
|
|
242
|
+
if (
|
|
243
|
+
!isFlexPlainObject(valueArg)
|
|
244
|
+
|| !hasFlexExactKeys(valueArg, [
|
|
245
|
+
'id', 'controllerId', 'scopeId', 'candidateId', 'revision',
|
|
246
|
+
'index', 'sha256', 'bytes', 'data', 'createdAt',
|
|
247
|
+
], ['domain', 'incarnationId', 'sessionId', 'archiveId'])
|
|
248
|
+
|| !isBoundedString(valueArg.controllerId, 512)
|
|
249
|
+
|| !isBoundedString(valueArg.scopeId, 512)
|
|
250
|
+
|| typeof valueArg.candidateId !== 'string'
|
|
251
|
+
|| !candidateIdPattern.test(valueArg.candidateId)
|
|
252
|
+
|| !isNonNegativeInteger(valueArg.revision)
|
|
253
|
+
|| !isIsoDate(valueArg.createdAt)
|
|
254
|
+
|| !isFlexPrivateChunkManifest({
|
|
255
|
+
id: valueArg.id,
|
|
256
|
+
index: valueArg.index,
|
|
257
|
+
sha256: valueArg.sha256,
|
|
258
|
+
bytes: valueArg.bytes,
|
|
259
|
+
})
|
|
260
|
+
|| !isBoundedString(valueArg.data, Math.ceil(flexPrivateChunkBytes / 3) * 4 + 4)
|
|
261
|
+
|| !hasValidOptionalDomainIdentity(valueArg)
|
|
262
|
+
) throw new Error('Invalid Flex private chunk document.');
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
export function assertFlexPrivateCandidateDocument(
|
|
266
|
+
valueArg: unknown,
|
|
267
|
+
): asserts valueArg is IFlexPrivateCandidateDocument {
|
|
268
|
+
if (
|
|
269
|
+
!isFlexPlainObject(valueArg)
|
|
270
|
+
|| !hasFlexExactKeys(valueArg, [
|
|
271
|
+
'id', 'controllerId', 'scopeId', 'candidateId', 'revision',
|
|
272
|
+
'sha256', 'bytes', 'chunks', 'createdAt',
|
|
273
|
+
], ['domain', 'incarnationId', 'sessionId', 'archiveId'])
|
|
274
|
+
|| !isBoundedString(valueArg.id, 1024)
|
|
275
|
+
|| !isBoundedString(valueArg.controllerId, 512)
|
|
276
|
+
|| !isBoundedString(valueArg.scopeId, 512)
|
|
277
|
+
|| !isIsoDate(valueArg.createdAt)
|
|
278
|
+
|| !isFlexPrivateCandidateManifest({
|
|
279
|
+
candidateId: valueArg.candidateId,
|
|
280
|
+
revision: valueArg.revision,
|
|
281
|
+
sha256: valueArg.sha256,
|
|
282
|
+
bytes: valueArg.bytes,
|
|
283
|
+
chunks: valueArg.chunks,
|
|
284
|
+
})
|
|
285
|
+
|| !hasValidOptionalDomainIdentity(valueArg)
|
|
286
|
+
) throw new Error('Invalid Flex private candidate document.');
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
export function assertFlexHeadDocument(
|
|
290
|
+
valueArg: unknown,
|
|
291
|
+
): asserts valueArg is IFlexHeadDocument {
|
|
292
|
+
if (
|
|
293
|
+
!isFlexPlainObject(valueArg)
|
|
294
|
+
|| !hasFlexExactKeys(valueArg, [
|
|
295
|
+
'id', 'controllerId', 'storageKey', 'revision',
|
|
296
|
+
'currentPrivateCandidateId', 'currentPublicCandidateId',
|
|
297
|
+
'privateCandidates', 'publicCandidates',
|
|
298
|
+
])
|
|
299
|
+
|| !isBoundedString(valueArg.id, 1024)
|
|
300
|
+
|| !isBoundedString(valueArg.controllerId, 512)
|
|
301
|
+
|| !isBoundedString(valueArg.storageKey, 512)
|
|
302
|
+
|| !isNonNegativeInteger(valueArg.revision)
|
|
303
|
+
|| typeof valueArg.currentPrivateCandidateId !== 'string'
|
|
304
|
+
|| !candidateIdPattern.test(valueArg.currentPrivateCandidateId)
|
|
305
|
+
|| typeof valueArg.currentPublicCandidateId !== 'string'
|
|
306
|
+
|| !candidateIdPattern.test(valueArg.currentPublicCandidateId)
|
|
307
|
+
|| !Array.isArray(valueArg.privateCandidates)
|
|
308
|
+
|| valueArg.privateCandidates.length !== 1
|
|
309
|
+
|| !valueArg.privateCandidates.every(isFlexPrivateCandidateManifest)
|
|
310
|
+
|| !Array.isArray(valueArg.publicCandidates)
|
|
311
|
+
|| valueArg.publicCandidates.length < 1
|
|
312
|
+
|| valueArg.publicCandidates.length > 4
|
|
313
|
+
|| !valueArg.publicCandidates.every(isFlexLegacyPublicCandidateManifest)
|
|
314
|
+
|| valueArg.privateCandidates[0]?.candidateId !== valueArg.currentPrivateCandidateId
|
|
315
|
+
|| valueArg.publicCandidates[0]?.candidateId !== valueArg.currentPublicCandidateId
|
|
316
|
+
|| valueArg.privateCandidates[0]?.revision !== valueArg.revision
|
|
317
|
+
|| valueArg.publicCandidates[0]?.revision !== valueArg.revision
|
|
318
|
+
|| valueArg.publicCandidates.some((candidate, index, candidates) => (
|
|
319
|
+
index > 0 && candidate.revision >= candidates[index - 1]!.revision
|
|
320
|
+
))
|
|
321
|
+
) throw new Error('Invalid Flex head document.');
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
export function assertFlexDomainHeadDocument(
|
|
325
|
+
valueArg: unknown,
|
|
326
|
+
): asserts valueArg is IFlexDomainHeadDocument {
|
|
327
|
+
if (!isFlexPlainObject(valueArg)) throw new Error('Invalid Flex domain head document.');
|
|
328
|
+
const domain = valueArg.domain;
|
|
329
|
+
const sessionDomain = domain === 'projection'
|
|
330
|
+
|| domain === 'permission'
|
|
331
|
+
|| domain === 'agentEvents'
|
|
332
|
+
|| domain === 'agentArchive'
|
|
333
|
+
|| domain === 'jobs';
|
|
334
|
+
const archiveDomain = domain === 'agentArchive';
|
|
335
|
+
if (
|
|
336
|
+
!hasFlexExactKeys(valueArg, [
|
|
337
|
+
'id', 'controllerId', 'storageKey', 'domain', 'incarnationId', 'revision',
|
|
338
|
+
'currentPrivateCandidateId', 'privateCandidate',
|
|
339
|
+
], ['projectionSource', 'sessionId', 'archiveId'])
|
|
340
|
+
|| !isBoundedString(valueArg.id, 1024)
|
|
341
|
+
|| !isBoundedString(valueArg.controllerId, 512)
|
|
342
|
+
|| !isBoundedString(valueArg.storageKey, 512)
|
|
343
|
+
|| !['scope', 'projection', 'permission', 'agentEvents', 'agentArchive', 'jobs']
|
|
344
|
+
.includes(String(domain))
|
|
345
|
+
|| typeof valueArg.incarnationId !== 'string'
|
|
346
|
+
|| !candidateIdPattern.test(valueArg.incarnationId)
|
|
347
|
+
|| !isNonNegativeInteger(valueArg.revision)
|
|
348
|
+
|| valueArg.revision < 1
|
|
349
|
+
|| typeof valueArg.currentPrivateCandidateId !== 'string'
|
|
350
|
+
|| !candidateIdPattern.test(valueArg.currentPrivateCandidateId)
|
|
351
|
+
|| !isFlexPrivateCandidateManifest(valueArg.privateCandidate)
|
|
352
|
+
|| valueArg.privateCandidate.candidateId !== valueArg.currentPrivateCandidateId
|
|
353
|
+
|| valueArg.privateCandidate.revision !== valueArg.revision
|
|
354
|
+
|| (domain === 'projection'
|
|
355
|
+
? !isFlexProjectionSourceManifest(valueArg.projectionSource)
|
|
356
|
+
: valueArg.projectionSource !== undefined)
|
|
357
|
+
|| (sessionDomain
|
|
358
|
+
? !isBoundedString(valueArg.sessionId, 512)
|
|
359
|
+
: valueArg.sessionId !== undefined)
|
|
360
|
+
|| (archiveDomain
|
|
361
|
+
? !isBoundedString(valueArg.archiveId, 512)
|
|
362
|
+
: valueArg.archiveId !== undefined)
|
|
363
|
+
) throw new Error('Invalid Flex domain head document.');
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
export function assertFlexWriterLeaseDocument(
|
|
367
|
+
valueArg: unknown,
|
|
368
|
+
): asserts valueArg is IFlexWriterLeaseDocument {
|
|
369
|
+
if (
|
|
370
|
+
!isFlexPlainObject(valueArg)
|
|
371
|
+
|| !hasFlexExactKeys(valueArg, [
|
|
372
|
+
'id', 'controllerId', 'storageKey', 'ownerToken', 'epoch',
|
|
373
|
+
'state', 'expiresAt', 'updatedAt',
|
|
374
|
+
])
|
|
375
|
+
|| !isBoundedString(valueArg.id, 1024)
|
|
376
|
+
|| !isBoundedString(valueArg.controllerId, 512)
|
|
377
|
+
|| !isBoundedString(valueArg.storageKey, 512)
|
|
378
|
+
|| typeof valueArg.ownerToken !== 'string'
|
|
379
|
+
|| !ownerTokenPattern.test(valueArg.ownerToken)
|
|
380
|
+
|| !isNonNegativeInteger(valueArg.epoch)
|
|
381
|
+
|| valueArg.epoch < 1
|
|
382
|
+
|| (valueArg.state !== 'active' && valueArg.state !== 'released')
|
|
383
|
+
|| !isNonNegativeInteger(valueArg.expiresAt)
|
|
384
|
+
|| valueArg.expiresAt < 0
|
|
385
|
+
|| !isIsoDate(valueArg.updatedAt)
|
|
386
|
+
) throw new Error('Invalid Flex writer lease document.');
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
export function assertFlexMigrationDocument(
|
|
390
|
+
valueArg: unknown,
|
|
391
|
+
): asserts valueArg is IFlexMigrationDocument {
|
|
392
|
+
if (
|
|
393
|
+
!isFlexPlainObject(valueArg)
|
|
394
|
+
|| !hasFlexExactKeys(valueArg, [
|
|
395
|
+
'id', 'controllerId', 'storageKey', 'migration',
|
|
396
|
+
'legacyRevision', 'legacyCandidateId', 'completedAt',
|
|
397
|
+
])
|
|
398
|
+
|| !isBoundedString(valueArg.id, 1024)
|
|
399
|
+
|| !isBoundedString(valueArg.controllerId, 512)
|
|
400
|
+
|| !isBoundedString(valueArg.storageKey, 512)
|
|
401
|
+
|| valueArg.migration !== 'flexharness-v3'
|
|
402
|
+
|| !isNonNegativeInteger(valueArg.legacyRevision)
|
|
403
|
+
|| typeof valueArg.legacyCandidateId !== 'string'
|
|
404
|
+
|| !candidateIdPattern.test(valueArg.legacyCandidateId)
|
|
405
|
+
|| !isIsoDate(valueArg.completedAt)
|
|
406
|
+
) throw new Error('Invalid Flex migration document.');
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
export function assertFlexProviderConnectionDocument(
|
|
410
|
+
valueArg: unknown,
|
|
411
|
+
): asserts valueArg is IFlexProviderConnectionDocument {
|
|
412
|
+
if (
|
|
413
|
+
!isFlexPlainObject(valueArg)
|
|
414
|
+
|| !hasFlexExactKeys(valueArg, [
|
|
415
|
+
'id', 'controllerId', 'providerId', 'state', 'generation', 'createdAt', 'updatedAt',
|
|
416
|
+
], ['account'])
|
|
417
|
+
|| typeof valueArg.id !== 'string'
|
|
418
|
+
|| !qualifiedConnectionIdPattern.test(valueArg.id)
|
|
419
|
+
|| !isBoundedString(valueArg.controllerId, 512)
|
|
420
|
+
|| valueArg.providerId !== 'openai'
|
|
421
|
+
|| !['pending', 'active', 'deleting', 'reauthRequired'].includes(String(valueArg.state))
|
|
422
|
+
|| !isNonNegativeInteger(valueArg.generation)
|
|
423
|
+
|| !isIsoDate(valueArg.createdAt)
|
|
424
|
+
|| !isIsoDate(valueArg.updatedAt)
|
|
425
|
+
|| (valueArg.account !== undefined && !isFlexPublicProviderConnection({
|
|
426
|
+
loginId: valueArg.id,
|
|
427
|
+
providerId: valueArg.providerId,
|
|
428
|
+
status: valueArg.state,
|
|
429
|
+
account: valueArg.account,
|
|
430
|
+
}))
|
|
431
|
+
) throw new Error('Invalid Flex provider connection document.');
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
export function assertFlexModelChoiceDocument(
|
|
435
|
+
valueArg: unknown,
|
|
436
|
+
): asserts valueArg is IFlexModelChoiceDocument {
|
|
437
|
+
if (
|
|
438
|
+
!isFlexPlainObject(valueArg)
|
|
439
|
+
|| !hasFlexExactKeys(valueArg, [
|
|
440
|
+
'id', 'controllerId', 'projectId', 'generation', 'choice', 'updatedAt',
|
|
441
|
+
])
|
|
442
|
+
|| !isBoundedString(valueArg.id, 1024)
|
|
443
|
+
|| !isBoundedString(valueArg.controllerId, 512)
|
|
444
|
+
|| !isBoundedString(valueArg.projectId, 128)
|
|
445
|
+
|| !isNonNegativeInteger(valueArg.generation)
|
|
446
|
+
|| !isIsoDate(valueArg.updatedAt)
|
|
447
|
+
|| !isFlexPlainObject(valueArg.choice)
|
|
448
|
+
|| !hasFlexExactKeys(valueArg.choice, ['providerConnectionId', 'modelId'], ['variant'])
|
|
449
|
+
|| typeof valueArg.choice.providerConnectionId !== 'string'
|
|
450
|
+
|| !qualifiedConnectionIdPattern.test(valueArg.choice.providerConnectionId)
|
|
451
|
+
|| !isBoundedString(valueArg.choice.modelId, 256)
|
|
452
|
+
|| (valueArg.choice.variant !== undefined && !isBoundedString(valueArg.choice.variant, 128))
|
|
453
|
+
) throw new Error('Invalid Flex model choice document.');
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
@plugins.smartdata.managed({ collectionName: 'flex_private_chunks' })
|
|
457
|
+
export class FlexPrivateChunkModel extends plugins.smartdata.SmartDataDbDoc<
|
|
458
|
+
FlexPrivateChunkModel,
|
|
459
|
+
IFlexPrivateChunkDocument
|
|
460
|
+
> {
|
|
461
|
+
@plugins.smartdata.unI()
|
|
462
|
+
public id!: string;
|
|
463
|
+
|
|
464
|
+
@plugins.smartdata.svDb()
|
|
465
|
+
public controllerId!: string;
|
|
466
|
+
|
|
467
|
+
@plugins.smartdata.index()
|
|
468
|
+
public scopeId!: string;
|
|
469
|
+
|
|
470
|
+
@plugins.smartdata.index()
|
|
471
|
+
public candidateId!: string;
|
|
472
|
+
|
|
473
|
+
@plugins.smartdata.svDb()
|
|
474
|
+
public revision!: number;
|
|
475
|
+
|
|
476
|
+
@plugins.smartdata.svDb()
|
|
477
|
+
public index!: number;
|
|
478
|
+
|
|
479
|
+
@plugins.smartdata.svDb()
|
|
480
|
+
public sha256!: string;
|
|
481
|
+
|
|
482
|
+
@plugins.smartdata.svDb()
|
|
483
|
+
public bytes!: number;
|
|
484
|
+
|
|
485
|
+
@plugins.smartdata.svDb()
|
|
486
|
+
public data!: string;
|
|
487
|
+
|
|
488
|
+
@plugins.smartdata.index()
|
|
489
|
+
public createdAt!: string;
|
|
490
|
+
|
|
491
|
+
@plugins.smartdata.index()
|
|
492
|
+
public domain?: TFlexDomainKind;
|
|
493
|
+
|
|
494
|
+
@plugins.smartdata.svDb()
|
|
495
|
+
public incarnationId?: string;
|
|
496
|
+
|
|
497
|
+
@plugins.smartdata.index()
|
|
498
|
+
public sessionId?: string;
|
|
499
|
+
|
|
500
|
+
@plugins.smartdata.index()
|
|
501
|
+
public archiveId?: string;
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
@plugins.smartdata.compoundIndex({
|
|
505
|
+
name: 'flex_private_candidate_orphans',
|
|
506
|
+
key: { controllerId: 1, createdAt: 1, _id: 1 },
|
|
507
|
+
})
|
|
508
|
+
@plugins.smartdata.managed({ collectionName: 'flex_private_candidates' })
|
|
509
|
+
export class FlexPrivateCandidateModel extends plugins.smartdata.SmartDataDbDoc<
|
|
510
|
+
FlexPrivateCandidateModel,
|
|
511
|
+
IFlexPrivateCandidateDocument
|
|
512
|
+
> {
|
|
513
|
+
@plugins.smartdata.unI()
|
|
514
|
+
public id!: string;
|
|
515
|
+
|
|
516
|
+
@plugins.smartdata.svDb()
|
|
517
|
+
public controllerId!: string;
|
|
518
|
+
|
|
519
|
+
@plugins.smartdata.index()
|
|
520
|
+
public scopeId!: string;
|
|
521
|
+
|
|
522
|
+
@plugins.smartdata.index()
|
|
523
|
+
public candidateId!: string;
|
|
524
|
+
|
|
525
|
+
@plugins.smartdata.svDb()
|
|
526
|
+
public revision!: number;
|
|
527
|
+
|
|
528
|
+
@plugins.smartdata.svDb()
|
|
529
|
+
public sha256!: string;
|
|
530
|
+
|
|
531
|
+
@plugins.smartdata.svDb()
|
|
532
|
+
public bytes!: number;
|
|
533
|
+
|
|
534
|
+
@plugins.smartdata.svDb()
|
|
535
|
+
public chunks!: IFlexPrivateChunkManifest[];
|
|
536
|
+
|
|
537
|
+
@plugins.smartdata.index()
|
|
538
|
+
public createdAt!: string;
|
|
539
|
+
|
|
540
|
+
@plugins.smartdata.index()
|
|
541
|
+
public domain?: TFlexDomainKind;
|
|
542
|
+
|
|
543
|
+
@plugins.smartdata.svDb()
|
|
544
|
+
public incarnationId?: string;
|
|
545
|
+
|
|
546
|
+
@plugins.smartdata.index()
|
|
547
|
+
public sessionId?: string;
|
|
548
|
+
|
|
549
|
+
@plugins.smartdata.index()
|
|
550
|
+
public archiveId?: string;
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
@plugins.smartdata.compoundIndex({
|
|
554
|
+
name: 'flex_head_public_owner',
|
|
555
|
+
key: { controllerId: 1, 'publicCandidates.candidateId': 1 },
|
|
556
|
+
})
|
|
557
|
+
@plugins.smartdata.compoundIndex({
|
|
558
|
+
name: 'flex_head_private_owner',
|
|
559
|
+
key: { controllerId: 1, currentPrivateCandidateId: 1 },
|
|
560
|
+
})
|
|
561
|
+
@plugins.smartdata.managed({ collectionName: 'flex_heads' })
|
|
562
|
+
@plugins.smartdata.exactPersistence({ assertDocument: assertFlexHeadDocument })
|
|
563
|
+
export class FlexHeadModel extends plugins.smartdata.SmartDataDbDoc<
|
|
564
|
+
FlexHeadModel,
|
|
565
|
+
IFlexHeadDocument
|
|
566
|
+
> {
|
|
567
|
+
declare static exact: plugins.smartdata.TExact<FlexHeadModel>;
|
|
568
|
+
|
|
569
|
+
@plugins.smartdata.unI()
|
|
570
|
+
public id!: string;
|
|
571
|
+
|
|
572
|
+
@plugins.smartdata.svDb()
|
|
573
|
+
public controllerId!: string;
|
|
574
|
+
|
|
575
|
+
@plugins.smartdata.svDb()
|
|
576
|
+
public storageKey!: string;
|
|
577
|
+
|
|
578
|
+
@plugins.smartdata.svDb()
|
|
579
|
+
public revision!: number;
|
|
580
|
+
|
|
581
|
+
@plugins.smartdata.svDb()
|
|
582
|
+
public currentPrivateCandidateId!: string;
|
|
583
|
+
|
|
584
|
+
@plugins.smartdata.svDb()
|
|
585
|
+
public currentPublicCandidateId!: string;
|
|
586
|
+
|
|
587
|
+
@plugins.smartdata.svDb()
|
|
588
|
+
public privateCandidates!: IFlexPrivateCandidateManifest[];
|
|
589
|
+
|
|
590
|
+
@plugins.smartdata.svDb()
|
|
591
|
+
public publicCandidates!: IFlexLegacyPublicCandidateManifest[];
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
@plugins.smartdata.compoundIndex({
|
|
595
|
+
name: 'flex_domain_projection_source_owner',
|
|
596
|
+
key: { controllerId: 1, domain: 1, 'projectionSource.candidateId': 1 },
|
|
597
|
+
})
|
|
598
|
+
@plugins.smartdata.compoundIndex({
|
|
599
|
+
name: 'flex_domain_private_owner',
|
|
600
|
+
key: { controllerId: 1, currentPrivateCandidateId: 1 },
|
|
601
|
+
})
|
|
602
|
+
@plugins.smartdata.managed({ collectionName: 'flex_domain_heads' })
|
|
603
|
+
@plugins.smartdata.exactPersistence({ assertDocument: assertFlexDomainHeadDocument })
|
|
604
|
+
export class FlexDomainHeadModel extends plugins.smartdata.SmartDataDbDoc<
|
|
605
|
+
FlexDomainHeadModel,
|
|
606
|
+
IFlexDomainHeadDocument
|
|
607
|
+
> {
|
|
608
|
+
declare static exact: plugins.smartdata.TExact<FlexDomainHeadModel>;
|
|
609
|
+
|
|
610
|
+
@plugins.smartdata.unI()
|
|
611
|
+
public id!: string;
|
|
612
|
+
|
|
613
|
+
@plugins.smartdata.index()
|
|
614
|
+
public controllerId!: string;
|
|
615
|
+
|
|
616
|
+
@plugins.smartdata.index()
|
|
617
|
+
public storageKey!: string;
|
|
618
|
+
|
|
619
|
+
@plugins.smartdata.index()
|
|
620
|
+
public domain!: TFlexDomainKind;
|
|
621
|
+
|
|
622
|
+
@plugins.smartdata.svDb()
|
|
623
|
+
public incarnationId!: string;
|
|
624
|
+
|
|
625
|
+
@plugins.smartdata.svDb()
|
|
626
|
+
public revision!: number;
|
|
627
|
+
|
|
628
|
+
@plugins.smartdata.svDb()
|
|
629
|
+
public currentPrivateCandidateId!: string;
|
|
630
|
+
|
|
631
|
+
@plugins.smartdata.svDb()
|
|
632
|
+
public privateCandidate!: IFlexPrivateCandidateManifest;
|
|
633
|
+
|
|
634
|
+
@plugins.smartdata.svDb()
|
|
635
|
+
public projectionSource?: IFlexProjectionSourceManifest;
|
|
636
|
+
|
|
637
|
+
@plugins.smartdata.index()
|
|
638
|
+
public sessionId?: string;
|
|
639
|
+
|
|
640
|
+
@plugins.smartdata.index()
|
|
641
|
+
public archiveId?: string;
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
@plugins.smartdata.compoundIndex({
|
|
645
|
+
name: 'flex_writer_released_scan',
|
|
646
|
+
key: { controllerId: 1, state: 1, _id: 1 },
|
|
647
|
+
})
|
|
648
|
+
@plugins.smartdata.managed({ collectionName: 'flex_writer_leases' })
|
|
649
|
+
@plugins.smartdata.exactPersistence({ assertDocument: assertFlexWriterLeaseDocument })
|
|
650
|
+
export class FlexWriterLeaseModel extends plugins.smartdata.SmartDataDbDoc<
|
|
651
|
+
FlexWriterLeaseModel,
|
|
652
|
+
IFlexWriterLeaseDocument
|
|
653
|
+
> {
|
|
654
|
+
declare static exact: plugins.smartdata.TExact<FlexWriterLeaseModel>;
|
|
655
|
+
|
|
656
|
+
@plugins.smartdata.unI()
|
|
657
|
+
public id!: string;
|
|
658
|
+
|
|
659
|
+
@plugins.smartdata.index()
|
|
660
|
+
public controllerId!: string;
|
|
661
|
+
|
|
662
|
+
@plugins.smartdata.index()
|
|
663
|
+
public storageKey!: string;
|
|
664
|
+
|
|
665
|
+
@plugins.smartdata.svDb()
|
|
666
|
+
public ownerToken!: string;
|
|
667
|
+
|
|
668
|
+
@plugins.smartdata.svDb()
|
|
669
|
+
public epoch!: number;
|
|
670
|
+
|
|
671
|
+
@plugins.smartdata.index()
|
|
672
|
+
public state!: 'active' | 'released';
|
|
673
|
+
|
|
674
|
+
@plugins.smartdata.index()
|
|
675
|
+
public expiresAt!: number;
|
|
676
|
+
|
|
677
|
+
@plugins.smartdata.svDb()
|
|
678
|
+
public updatedAt!: string;
|
|
679
|
+
}
|
|
680
|
+
|
|
681
|
+
@plugins.smartdata.managed({ collectionName: 'flex_migrations' })
|
|
682
|
+
@plugins.smartdata.exactPersistence({ assertDocument: assertFlexMigrationDocument })
|
|
683
|
+
export class FlexMigrationModel extends plugins.smartdata.SmartDataDbDoc<
|
|
684
|
+
FlexMigrationModel,
|
|
685
|
+
IFlexMigrationDocument
|
|
686
|
+
> {
|
|
687
|
+
declare static exact: plugins.smartdata.TExact<FlexMigrationModel>;
|
|
688
|
+
|
|
689
|
+
@plugins.smartdata.unI()
|
|
690
|
+
public id!: string;
|
|
691
|
+
|
|
692
|
+
@plugins.smartdata.index()
|
|
693
|
+
public controllerId!: string;
|
|
694
|
+
|
|
695
|
+
@plugins.smartdata.index()
|
|
696
|
+
public storageKey!: string;
|
|
697
|
+
|
|
698
|
+
@plugins.smartdata.index()
|
|
699
|
+
public migration!: 'flexharness-v3';
|
|
700
|
+
|
|
701
|
+
@plugins.smartdata.svDb()
|
|
702
|
+
public legacyRevision!: number;
|
|
703
|
+
|
|
704
|
+
@plugins.smartdata.svDb()
|
|
705
|
+
public legacyCandidateId!: string;
|
|
706
|
+
|
|
707
|
+
@plugins.smartdata.svDb()
|
|
708
|
+
public completedAt!: string;
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
const scopedIdentityHash = (
|
|
712
|
+
controllerIdArg: string,
|
|
713
|
+
storageKeyArg: string,
|
|
714
|
+
...partsArg: string[]
|
|
715
|
+
): string => plugins.crypto.createHash('sha256')
|
|
716
|
+
.update(controllerIdArg, 'utf8')
|
|
717
|
+
.update('\0', 'utf8')
|
|
718
|
+
.update(storageKeyArg, 'utf8')
|
|
719
|
+
.update('\0', 'utf8')
|
|
720
|
+
.update(partsArg.join('\0'), 'utf8')
|
|
721
|
+
.digest('hex');
|
|
722
|
+
|
|
723
|
+
export const flexDomainHeadId = (
|
|
724
|
+
controllerIdArg: string,
|
|
725
|
+
storageKeyArg: string,
|
|
726
|
+
domainArg: TFlexDomainKind,
|
|
727
|
+
sessionIdArg?: string,
|
|
728
|
+
archiveIdArg?: string,
|
|
729
|
+
): string => `flex-domain-head:${scopedIdentityHash(
|
|
730
|
+
controllerIdArg,
|
|
731
|
+
storageKeyArg,
|
|
732
|
+
domainArg,
|
|
733
|
+
sessionIdArg ?? '',
|
|
734
|
+
archiveIdArg ?? '',
|
|
735
|
+
)}`;
|
|
736
|
+
|
|
737
|
+
export const flexWriterLeaseId = (
|
|
738
|
+
controllerIdArg: string,
|
|
739
|
+
storageKeyArg: string,
|
|
740
|
+
): string => `flex-writer-lease:${scopedIdentityHash(controllerIdArg, storageKeyArg, 'writer')}`;
|
|
741
|
+
|
|
742
|
+
export const flexMigrationId = (
|
|
743
|
+
controllerIdArg: string,
|
|
744
|
+
storageKeyArg: string,
|
|
745
|
+
): string => `flex-migration:${scopedIdentityHash(controllerIdArg, storageKeyArg, 'flexharness-v3')}`;
|
|
746
|
+
|
|
747
|
+
@plugins.smartdata.managed({ collectionName: 'flex_provider_connections' })
|
|
748
|
+
export class FlexProviderConnectionModel extends plugins.smartdata.SmartDataDbDoc<
|
|
749
|
+
FlexProviderConnectionModel,
|
|
750
|
+
IFlexProviderConnectionDocument
|
|
751
|
+
> {
|
|
752
|
+
@plugins.smartdata.unI()
|
|
753
|
+
public id!: string;
|
|
754
|
+
|
|
755
|
+
@plugins.smartdata.index()
|
|
756
|
+
public controllerId!: string;
|
|
757
|
+
|
|
758
|
+
@plugins.smartdata.svDb()
|
|
759
|
+
public providerId!: 'openai';
|
|
760
|
+
|
|
761
|
+
@plugins.smartdata.index()
|
|
762
|
+
public state!: IFlexProviderConnectionDocument['state'];
|
|
763
|
+
|
|
764
|
+
@plugins.smartdata.svDb()
|
|
765
|
+
public generation!: number;
|
|
766
|
+
|
|
767
|
+
@plugins.smartdata.svDb()
|
|
768
|
+
public createdAt!: string;
|
|
769
|
+
|
|
770
|
+
@plugins.smartdata.svDb()
|
|
771
|
+
public updatedAt!: string;
|
|
772
|
+
|
|
773
|
+
@plugins.smartdata.svDb()
|
|
774
|
+
public account?: IFlexPublicAccountSummary;
|
|
775
|
+
}
|
|
776
|
+
|
|
777
|
+
@plugins.smartdata.managed({ collectionName: 'flex_model_choices' })
|
|
778
|
+
export class FlexModelChoiceModel extends plugins.smartdata.SmartDataDbDoc<
|
|
779
|
+
FlexModelChoiceModel,
|
|
780
|
+
IFlexModelChoiceDocument
|
|
781
|
+
> {
|
|
782
|
+
@plugins.smartdata.unI()
|
|
783
|
+
public id!: string;
|
|
784
|
+
|
|
785
|
+
@plugins.smartdata.index()
|
|
786
|
+
public controllerId!: string;
|
|
787
|
+
|
|
788
|
+
@plugins.smartdata.index()
|
|
789
|
+
public projectId!: string;
|
|
790
|
+
|
|
791
|
+
@plugins.smartdata.svDb()
|
|
792
|
+
public generation!: number;
|
|
793
|
+
|
|
794
|
+
@plugins.smartdata.svDb()
|
|
795
|
+
public choice!: IFlexModelChoice;
|
|
796
|
+
|
|
797
|
+
@plugins.smartdata.svDb()
|
|
798
|
+
public updatedAt!: string;
|
|
799
|
+
}
|
|
800
|
+
|
|
801
|
+
export const registerFlexPrivateModels = (
|
|
802
|
+
managerArg: { db: plugins.smartdata.SmartdataDb },
|
|
803
|
+
): void => {
|
|
804
|
+
plugins.smartdata.setDefaultManagerForDoc(managerArg, FlexPrivateChunkModel);
|
|
805
|
+
plugins.smartdata.setDefaultManagerForDoc(managerArg, FlexPrivateCandidateModel);
|
|
806
|
+
plugins.smartdata.setDefaultManagerForDoc(managerArg, FlexHeadModel);
|
|
807
|
+
plugins.smartdata.setDefaultManagerForDoc(managerArg, FlexDomainHeadModel);
|
|
808
|
+
plugins.smartdata.setDefaultManagerForDoc(managerArg, FlexWriterLeaseModel);
|
|
809
|
+
plugins.smartdata.setDefaultManagerForDoc(managerArg, FlexMigrationModel);
|
|
810
|
+
plugins.smartdata.setDefaultManagerForDoc(managerArg, FlexProviderConnectionModel);
|
|
811
|
+
plugins.smartdata.setDefaultManagerForDoc(managerArg, FlexModelChoiceModel);
|
|
812
|
+
};
|
|
813
|
+
|
|
814
|
+
export const initFlexPrivateModels = async (): Promise<void> => {
|
|
815
|
+
await FlexPrivateChunkModel.init();
|
|
816
|
+
await FlexPrivateCandidateModel.init();
|
|
817
|
+
await FlexHeadModel.init();
|
|
818
|
+
await FlexDomainHeadModel.init();
|
|
819
|
+
await FlexWriterLeaseModel.init();
|
|
820
|
+
await FlexMigrationModel.init();
|
|
821
|
+
await FlexProviderConnectionModel.init();
|
|
822
|
+
await FlexModelChoiceModel.init();
|
|
823
|
+
};
|