@tutti-os/workbench-host 0.0.104
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/LICENSE +201 -0
- package/README.md +68 -0
- package/dist/chunk-KN7VKRMB.js +333 -0
- package/dist/chunk-KN7VKRMB.js.map +1 -0
- package/dist/conformance/index.d.ts +20 -0
- package/dist/conformance/index.js +310 -0
- package/dist/conformance/index.js.map +1 -0
- package/dist/index.d.ts +105 -0
- package/dist/index.js +15 -0
- package/dist/index.js.map +1 -0
- package/package.json +45 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2025-2026 The Tutti Authors
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# @tutti-os/workbench-host
|
|
2
|
+
|
|
3
|
+
Product-neutral Workbench coordinator and disposable session lifecycle for
|
|
4
|
+
renderer hosts.
|
|
5
|
+
|
|
6
|
+
The package owns renderer-local session indexing, immutable partition
|
|
7
|
+
replacement, lease disposal, stable host-input publication, surface attachment
|
|
8
|
+
handoff, and deterministic capability ownership checks. It does not own React,
|
|
9
|
+
Electron, product transport clients, authentication discovery, or product
|
|
10
|
+
business policy.
|
|
11
|
+
|
|
12
|
+
## Runtime API
|
|
13
|
+
|
|
14
|
+
```ts
|
|
15
|
+
import {
|
|
16
|
+
createWorkbenchHostSessionConfiguration,
|
|
17
|
+
WorkbenchHostCoordinator,
|
|
18
|
+
WorkbenchHostSession
|
|
19
|
+
} from "@tutti-os/workbench-host";
|
|
20
|
+
|
|
21
|
+
const configuration = createWorkbenchHostSessionConfiguration({
|
|
22
|
+
createSession: (partition) =>
|
|
23
|
+
new WorkbenchHostSession({
|
|
24
|
+
partition,
|
|
25
|
+
resolve: (update: string) => ({
|
|
26
|
+
hostInput: { value: update },
|
|
27
|
+
state: update
|
|
28
|
+
})
|
|
29
|
+
})
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
const coordinator = new WorkbenchHostCoordinator();
|
|
33
|
+
const lease = coordinator.open({
|
|
34
|
+
configuration,
|
|
35
|
+
partition: {
|
|
36
|
+
scope: { id: "workspace-1", kind: "workspace" }
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
lease.session.update("ready");
|
|
41
|
+
lease.release();
|
|
42
|
+
coordinator.dispose();
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Create one coordinator per renderer/window dependency-injection root. Product
|
|
46
|
+
DI tokens and registration stay in the product renderer. Separate renderer
|
|
47
|
+
coordinators never share sessions, and renderer isolation does not grant a
|
|
48
|
+
second durable snapshot writer.
|
|
49
|
+
|
|
50
|
+
## Conformance
|
|
51
|
+
|
|
52
|
+
The `@tutti-os/workbench-host/conformance` subpath exposes runner-neutral test
|
|
53
|
+
cases. Consumers can register the same cases in Node test, Vitest, or another
|
|
54
|
+
test runner and may supply their DI-resolved coordinator, partition mapping, and
|
|
55
|
+
capability profile fixture.
|
|
56
|
+
|
|
57
|
+
```ts
|
|
58
|
+
import { test } from "node:test";
|
|
59
|
+
import { createWorkbenchHostConformanceCases } from "@tutti-os/workbench-host/conformance";
|
|
60
|
+
|
|
61
|
+
for (const conformanceCase of createWorkbenchHostConformanceCases()) {
|
|
62
|
+
test(conformanceCase.name, conformanceCase.run);
|
|
63
|
+
}
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
The shared cases cover the public kernel contract. Product repositories and
|
|
67
|
+
composition roots must add their own durable-writer, metadata preservation,
|
|
68
|
+
snapshot restore, and transport isolation cases.
|
|
@@ -0,0 +1,333 @@
|
|
|
1
|
+
// src/session/workbenchHostSession.ts
|
|
2
|
+
var WorkbenchHostSession = class {
|
|
3
|
+
partition;
|
|
4
|
+
current = null;
|
|
5
|
+
disposed = false;
|
|
6
|
+
disposalCallbacks = [];
|
|
7
|
+
diagnostics;
|
|
8
|
+
listeners = /* @__PURE__ */ new Set();
|
|
9
|
+
resolve;
|
|
10
|
+
surfaceHandle = null;
|
|
11
|
+
surfaceOwner = null;
|
|
12
|
+
constructor(options) {
|
|
13
|
+
this.partition = freezeWorkbenchSnapshotPartition(options.partition);
|
|
14
|
+
this.diagnostics = options.diagnostics;
|
|
15
|
+
this.resolve = options.resolve;
|
|
16
|
+
}
|
|
17
|
+
get isDisposed() {
|
|
18
|
+
return this.disposed;
|
|
19
|
+
}
|
|
20
|
+
attachSurface(handle, owner) {
|
|
21
|
+
this.assertActive();
|
|
22
|
+
if (handle === null) {
|
|
23
|
+
if (this.surfaceOwner === owner) {
|
|
24
|
+
this.surfaceHandle = null;
|
|
25
|
+
this.surfaceOwner = null;
|
|
26
|
+
}
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
this.surfaceHandle = handle;
|
|
30
|
+
this.surfaceOwner = owner;
|
|
31
|
+
}
|
|
32
|
+
getAttachedSurface() {
|
|
33
|
+
return this.surfaceHandle;
|
|
34
|
+
}
|
|
35
|
+
getHostInput() {
|
|
36
|
+
this.assertActive();
|
|
37
|
+
if (!this.current) {
|
|
38
|
+
throw new Error("Workbench host session has not received an update.");
|
|
39
|
+
}
|
|
40
|
+
return this.current.hostInput;
|
|
41
|
+
}
|
|
42
|
+
registerDisposable(dispose) {
|
|
43
|
+
this.assertActive();
|
|
44
|
+
let registered = true;
|
|
45
|
+
this.disposalCallbacks.push(dispose);
|
|
46
|
+
return () => {
|
|
47
|
+
if (!registered || this.disposed) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
registered = false;
|
|
51
|
+
const index = this.disposalCallbacks.indexOf(dispose);
|
|
52
|
+
if (index >= 0) {
|
|
53
|
+
this.disposalCallbacks.splice(index, 1);
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
subscribe(listener) {
|
|
58
|
+
if (this.disposed) {
|
|
59
|
+
return noop;
|
|
60
|
+
}
|
|
61
|
+
this.listeners.add(listener);
|
|
62
|
+
return () => {
|
|
63
|
+
this.listeners.delete(listener);
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
update(update) {
|
|
67
|
+
this.assertActive();
|
|
68
|
+
const hadCurrent = this.current !== null;
|
|
69
|
+
const previousHostInput = this.current?.hostInput;
|
|
70
|
+
const next = this.resolve(update, this.current);
|
|
71
|
+
this.current = next;
|
|
72
|
+
if (!hadCurrent || previousHostInput !== next.hostInput) {
|
|
73
|
+
for (const listener of Array.from(this.listeners)) {
|
|
74
|
+
listener();
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return next.hostInput;
|
|
78
|
+
}
|
|
79
|
+
dispose() {
|
|
80
|
+
if (this.disposed) {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
this.disposed = true;
|
|
84
|
+
this.surfaceHandle = null;
|
|
85
|
+
this.surfaceOwner = null;
|
|
86
|
+
this.listeners.clear();
|
|
87
|
+
const disposalCallbacks = this.disposalCallbacks.splice(0);
|
|
88
|
+
this.disposalCallbacks.length = 0;
|
|
89
|
+
this.current = null;
|
|
90
|
+
for (let index = disposalCallbacks.length - 1; index >= 0; index -= 1) {
|
|
91
|
+
try {
|
|
92
|
+
disposalCallbacks[index]?.();
|
|
93
|
+
} catch (error) {
|
|
94
|
+
this.reportDisposalError(error);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
assertActive() {
|
|
99
|
+
if (this.disposed) {
|
|
100
|
+
throw new Error("Workbench host session is disposed.");
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
reportDisposalError(error) {
|
|
104
|
+
try {
|
|
105
|
+
const result = this.diagnostics?.report({
|
|
106
|
+
error,
|
|
107
|
+
event: "workbench.host.session.dispose_failed"
|
|
108
|
+
});
|
|
109
|
+
void result?.catch(() => void 0);
|
|
110
|
+
} catch {
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
function areWorkbenchSnapshotPartitionsEqual(left, right) {
|
|
115
|
+
return left.scope.kind === right.scope.kind && left.scope.id === right.scope.id && left.principal?.id === right.principal?.id;
|
|
116
|
+
}
|
|
117
|
+
function createWorkbenchScopeKey(scope) {
|
|
118
|
+
return `${scope.kind.length}:${scope.kind}${scope.id.length}:${scope.id}`;
|
|
119
|
+
}
|
|
120
|
+
function freezeWorkbenchSnapshotPartition(partition) {
|
|
121
|
+
return Object.freeze({
|
|
122
|
+
...partition.principal ? { principal: Object.freeze({ id: partition.principal.id }) } : {},
|
|
123
|
+
scope: Object.freeze({
|
|
124
|
+
id: partition.scope.id,
|
|
125
|
+
kind: partition.scope.kind
|
|
126
|
+
})
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
function noop() {
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// src/coordinator/workbenchHostCoordinator.ts
|
|
133
|
+
function createWorkbenchHostSessionConfiguration(input) {
|
|
134
|
+
return input;
|
|
135
|
+
}
|
|
136
|
+
var WorkbenchHostCoordinator = class {
|
|
137
|
+
disposed = false;
|
|
138
|
+
options;
|
|
139
|
+
sessionsByScope = /* @__PURE__ */ new Map();
|
|
140
|
+
constructor(options = {}) {
|
|
141
|
+
this.options = options;
|
|
142
|
+
}
|
|
143
|
+
open(input) {
|
|
144
|
+
this.assertActive();
|
|
145
|
+
const scopeKey = createWorkbenchScopeKey(input.partition.scope);
|
|
146
|
+
let entry = this.sessionsByScope.get(scopeKey);
|
|
147
|
+
if (entry && !areWorkbenchSnapshotPartitionsEqual(
|
|
148
|
+
entry.session.partition,
|
|
149
|
+
input.partition
|
|
150
|
+
)) {
|
|
151
|
+
this.sessionsByScope.delete(scopeKey);
|
|
152
|
+
this.disposeSession(entry.session);
|
|
153
|
+
entry = void 0;
|
|
154
|
+
}
|
|
155
|
+
if (entry && entry.configuration !== input.configuration) {
|
|
156
|
+
throw new Error(
|
|
157
|
+
"Workbench host session partition is already owned by another configuration."
|
|
158
|
+
);
|
|
159
|
+
}
|
|
160
|
+
if (!entry || entry.session.isDisposed) {
|
|
161
|
+
const session2 = input.configuration.createSession(input.partition);
|
|
162
|
+
if (!areWorkbenchSnapshotPartitionsEqual(session2.partition, input.partition)) {
|
|
163
|
+
this.disposeSession(session2);
|
|
164
|
+
throw new Error(
|
|
165
|
+
"Workbench host session partition does not match the open request."
|
|
166
|
+
);
|
|
167
|
+
}
|
|
168
|
+
entry = {
|
|
169
|
+
configuration: input.configuration,
|
|
170
|
+
leaseCount: 0,
|
|
171
|
+
session: session2
|
|
172
|
+
};
|
|
173
|
+
this.sessionsByScope.set(scopeKey, entry);
|
|
174
|
+
}
|
|
175
|
+
entry.leaseCount += 1;
|
|
176
|
+
const leasedEntry = entry;
|
|
177
|
+
const session = entry.session;
|
|
178
|
+
let released = false;
|
|
179
|
+
return {
|
|
180
|
+
release: () => {
|
|
181
|
+
if (released) {
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
released = true;
|
|
185
|
+
this.release(scopeKey, leasedEntry);
|
|
186
|
+
},
|
|
187
|
+
session
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
get(configuration, partition) {
|
|
191
|
+
if (this.disposed) {
|
|
192
|
+
return null;
|
|
193
|
+
}
|
|
194
|
+
const scopeKey = createWorkbenchScopeKey(partition.scope);
|
|
195
|
+
const entry = this.sessionsByScope.get(scopeKey);
|
|
196
|
+
if (!entry) {
|
|
197
|
+
return null;
|
|
198
|
+
}
|
|
199
|
+
if (entry.configuration !== configuration) {
|
|
200
|
+
return null;
|
|
201
|
+
}
|
|
202
|
+
if (entry.session.isDisposed) {
|
|
203
|
+
this.sessionsByScope.delete(scopeKey);
|
|
204
|
+
return null;
|
|
205
|
+
}
|
|
206
|
+
if (!areWorkbenchSnapshotPartitionsEqual(entry.session.partition, partition)) {
|
|
207
|
+
return null;
|
|
208
|
+
}
|
|
209
|
+
return entry.session;
|
|
210
|
+
}
|
|
211
|
+
dispose() {
|
|
212
|
+
if (this.disposed) {
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
this.disposed = true;
|
|
216
|
+
const entries = Array.from(this.sessionsByScope.values());
|
|
217
|
+
this.sessionsByScope.clear();
|
|
218
|
+
for (const entry of entries) {
|
|
219
|
+
this.disposeSession(entry.session);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
assertActive() {
|
|
223
|
+
if (this.disposed) {
|
|
224
|
+
throw new Error("Workbench host coordinator is disposed.");
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
release(scopeKey, leasedEntry) {
|
|
228
|
+
const currentEntry = this.sessionsByScope.get(scopeKey);
|
|
229
|
+
if (currentEntry !== leasedEntry) {
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
leasedEntry.leaseCount -= 1;
|
|
233
|
+
if (leasedEntry.leaseCount > 0) {
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
236
|
+
this.sessionsByScope.delete(scopeKey);
|
|
237
|
+
this.disposeSession(leasedEntry.session);
|
|
238
|
+
}
|
|
239
|
+
disposeSession(session) {
|
|
240
|
+
try {
|
|
241
|
+
session.dispose();
|
|
242
|
+
} catch (error) {
|
|
243
|
+
this.reportDisposalError(error);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
reportDisposalError(error) {
|
|
247
|
+
try {
|
|
248
|
+
const result = this.options.diagnostics?.report({
|
|
249
|
+
error,
|
|
250
|
+
event: "workbench.host.coordinator.dispose_failed"
|
|
251
|
+
});
|
|
252
|
+
void result?.catch(() => void 0);
|
|
253
|
+
} catch {
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
};
|
|
257
|
+
|
|
258
|
+
// src/capabilities/workbenchCapabilityRegistry.ts
|
|
259
|
+
function resolveWorkbenchCapabilityRegistry(input) {
|
|
260
|
+
const factories = [...input.capabilityFactories].sort(
|
|
261
|
+
compareWorkbenchCapabilityFactories
|
|
262
|
+
);
|
|
263
|
+
assertUniqueFactoryIds(factories);
|
|
264
|
+
const resolvedCapabilities = factories.flatMap((factory) => {
|
|
265
|
+
const contribution = factory.create();
|
|
266
|
+
return contribution ? [{ contribution, factoryId: factory.id }] : [];
|
|
267
|
+
});
|
|
268
|
+
assertUniqueContributionOwnership(resolvedCapabilities);
|
|
269
|
+
return {
|
|
270
|
+
contributions: resolvedCapabilities.map(({ contribution }) => contribution)
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
function compareWorkbenchCapabilityFactories(left, right) {
|
|
274
|
+
return left.order - right.order || left.id.localeCompare(right.id);
|
|
275
|
+
}
|
|
276
|
+
function assertUniqueFactoryIds(factories) {
|
|
277
|
+
const owners = /* @__PURE__ */ new Set();
|
|
278
|
+
for (const factory of factories) {
|
|
279
|
+
if (owners.has(factory.id)) {
|
|
280
|
+
throw new Error(
|
|
281
|
+
`Workbench capability factory id "${factory.id}" has multiple owners.`
|
|
282
|
+
);
|
|
283
|
+
}
|
|
284
|
+
owners.add(factory.id);
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
function assertUniqueContributionOwnership(resolvedCapabilities) {
|
|
288
|
+
const contributionOwners = /* @__PURE__ */ new Map();
|
|
289
|
+
const nodeOwners = /* @__PURE__ */ new Map();
|
|
290
|
+
const dockEntryOwners = /* @__PURE__ */ new Map();
|
|
291
|
+
for (const { contribution, factoryId } of resolvedCapabilities) {
|
|
292
|
+
assertUniqueOwner(
|
|
293
|
+
contributionOwners,
|
|
294
|
+
contribution.id,
|
|
295
|
+
factoryId,
|
|
296
|
+
"contribution id"
|
|
297
|
+
);
|
|
298
|
+
for (const node of contribution.nodes ?? []) {
|
|
299
|
+
assertUniqueOwner(
|
|
300
|
+
nodeOwners,
|
|
301
|
+
node.typeId,
|
|
302
|
+
contribution.id,
|
|
303
|
+
"node type id"
|
|
304
|
+
);
|
|
305
|
+
}
|
|
306
|
+
for (const dockEntry of contribution.dockEntries ?? []) {
|
|
307
|
+
assertUniqueOwner(
|
|
308
|
+
dockEntryOwners,
|
|
309
|
+
dockEntry.id,
|
|
310
|
+
contribution.id,
|
|
311
|
+
"dock entry id"
|
|
312
|
+
);
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
function assertUniqueOwner(owners, id, owner, kind) {
|
|
317
|
+
const existingOwner = owners.get(id);
|
|
318
|
+
if (existingOwner) {
|
|
319
|
+
throw new Error(
|
|
320
|
+
`Workbench ${kind} "${id}" is owned by both "${existingOwner}" and "${owner}".`
|
|
321
|
+
);
|
|
322
|
+
}
|
|
323
|
+
owners.set(id, owner);
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
export {
|
|
327
|
+
WorkbenchHostSession,
|
|
328
|
+
areWorkbenchSnapshotPartitionsEqual,
|
|
329
|
+
createWorkbenchHostSessionConfiguration,
|
|
330
|
+
WorkbenchHostCoordinator,
|
|
331
|
+
resolveWorkbenchCapabilityRegistry
|
|
332
|
+
};
|
|
333
|
+
//# sourceMappingURL=chunk-KN7VKRMB.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/session/workbenchHostSession.ts","../src/coordinator/workbenchHostCoordinator.ts","../src/capabilities/workbenchCapabilityRegistry.ts"],"sourcesContent":["import type { WorkbenchHostHandle } from \"@tutti-os/workbench-surface\";\n\nimport type { WorkbenchDiagnosticsPort } from \"../diagnostics/workbenchDiagnosticsPort.ts\";\n\nexport interface WorkbenchScope {\n readonly id: string;\n readonly kind: \"room\" | \"workspace\";\n}\n\nexport interface WorkbenchAuthenticatedPrincipalSnapshot {\n readonly id: string;\n}\n\nexport interface WorkbenchSnapshotPartition {\n readonly principal?: WorkbenchAuthenticatedPrincipalSnapshot;\n readonly scope: WorkbenchScope;\n}\n\nexport interface WorkbenchHostSessionResolution<THostInput, TState> {\n readonly hostInput: THostInput;\n readonly state: TState;\n}\n\nexport interface WorkbenchHostSessionOptions<TUpdate, THostInput, TState> {\n readonly diagnostics?: WorkbenchDiagnosticsPort;\n readonly partition: WorkbenchSnapshotPartition;\n readonly resolve: (\n update: TUpdate,\n current: WorkbenchHostSessionResolution<THostInput, TState> | null\n ) => WorkbenchHostSessionResolution<THostInput, TState>;\n}\n\nexport class WorkbenchHostSession<TUpdate, THostInput, TState> {\n readonly partition: WorkbenchSnapshotPartition;\n private current: WorkbenchHostSessionResolution<THostInput, TState> | null =\n null;\n private disposed = false;\n private readonly disposalCallbacks: Array<() => void> = [];\n private readonly diagnostics?: WorkbenchDiagnosticsPort;\n private readonly listeners = new Set<() => void>();\n private readonly resolve: WorkbenchHostSessionOptions<\n TUpdate,\n THostInput,\n TState\n >[\"resolve\"];\n private surfaceHandle: WorkbenchHostHandle | null = null;\n private surfaceOwner: object | null = null;\n\n constructor(\n options: WorkbenchHostSessionOptions<TUpdate, THostInput, TState>\n ) {\n this.partition = freezeWorkbenchSnapshotPartition(options.partition);\n this.diagnostics = options.diagnostics;\n this.resolve = options.resolve;\n }\n\n get isDisposed(): boolean {\n return this.disposed;\n }\n\n attachSurface(handle: WorkbenchHostHandle | null, owner: object): void {\n this.assertActive();\n if (handle === null) {\n if (this.surfaceOwner === owner) {\n this.surfaceHandle = null;\n this.surfaceOwner = null;\n }\n return;\n }\n this.surfaceHandle = handle;\n this.surfaceOwner = owner;\n }\n\n getAttachedSurface(): WorkbenchHostHandle | null {\n return this.surfaceHandle;\n }\n\n getHostInput(): THostInput {\n this.assertActive();\n if (!this.current) {\n throw new Error(\"Workbench host session has not received an update.\");\n }\n return this.current.hostInput;\n }\n\n registerDisposable(dispose: () => void): () => void {\n this.assertActive();\n let registered = true;\n this.disposalCallbacks.push(dispose);\n return () => {\n if (!registered || this.disposed) {\n return;\n }\n registered = false;\n const index = this.disposalCallbacks.indexOf(dispose);\n if (index >= 0) {\n this.disposalCallbacks.splice(index, 1);\n }\n };\n }\n\n subscribe(listener: () => void): () => void {\n if (this.disposed) {\n return noop;\n }\n this.listeners.add(listener);\n return () => {\n this.listeners.delete(listener);\n };\n }\n\n update(update: TUpdate): THostInput {\n this.assertActive();\n const hadCurrent = this.current !== null;\n const previousHostInput = this.current?.hostInput;\n const next = this.resolve(update, this.current);\n this.current = next;\n if (!hadCurrent || previousHostInput !== next.hostInput) {\n for (const listener of Array.from(this.listeners)) {\n listener();\n }\n }\n return next.hostInput;\n }\n\n dispose(): void {\n if (this.disposed) {\n return;\n }\n this.disposed = true;\n this.surfaceHandle = null;\n this.surfaceOwner = null;\n this.listeners.clear();\n const disposalCallbacks = this.disposalCallbacks.splice(0);\n this.disposalCallbacks.length = 0;\n this.current = null;\n for (let index = disposalCallbacks.length - 1; index >= 0; index -= 1) {\n try {\n disposalCallbacks[index]?.();\n } catch (error) {\n this.reportDisposalError(error);\n }\n }\n }\n\n private assertActive(): void {\n if (this.disposed) {\n throw new Error(\"Workbench host session is disposed.\");\n }\n }\n\n private reportDisposalError(error: unknown): void {\n try {\n const result = this.diagnostics?.report({\n error,\n event: \"workbench.host.session.dispose_failed\"\n });\n void result?.catch(() => undefined);\n } catch {\n // Disposal must continue even when diagnostics fail.\n }\n }\n}\n\nexport function areWorkbenchSnapshotPartitionsEqual(\n left: WorkbenchSnapshotPartition,\n right: WorkbenchSnapshotPartition\n): boolean {\n return (\n left.scope.kind === right.scope.kind &&\n left.scope.id === right.scope.id &&\n left.principal?.id === right.principal?.id\n );\n}\n\nexport function createWorkbenchScopeKey(scope: WorkbenchScope): string {\n return `${scope.kind.length}:${scope.kind}${scope.id.length}:${scope.id}`;\n}\n\nfunction freezeWorkbenchSnapshotPartition(\n partition: WorkbenchSnapshotPartition\n): WorkbenchSnapshotPartition {\n return Object.freeze({\n ...(partition.principal\n ? { principal: Object.freeze({ id: partition.principal.id }) }\n : {}),\n scope: Object.freeze({\n id: partition.scope.id,\n kind: partition.scope.kind\n })\n });\n}\n\nfunction noop(): void {}\n","import type { WorkbenchDiagnosticsPort } from \"../diagnostics/workbenchDiagnosticsPort.ts\";\nimport {\n areWorkbenchSnapshotPartitionsEqual,\n createWorkbenchScopeKey,\n WorkbenchHostSession,\n type WorkbenchSnapshotPartition\n} from \"../session/workbenchHostSession.ts\";\n\ndeclare const workbenchHostSessionConfigurationBrand: unique symbol;\n\nexport interface WorkbenchHostSessionConfiguration<\n TUpdate,\n THostInput,\n TState\n> {\n readonly [workbenchHostSessionConfigurationBrand]: {\n readonly hostInput: THostInput;\n readonly state: TState;\n readonly update: TUpdate;\n };\n readonly createSession: (\n partition: WorkbenchSnapshotPartition\n ) => WorkbenchHostSession<TUpdate, THostInput, TState>;\n}\n\nexport interface WorkbenchHostSessionOpenInput<TUpdate, THostInput, TState> {\n readonly configuration: WorkbenchHostSessionConfiguration<\n TUpdate,\n THostInput,\n TState\n >;\n readonly partition: WorkbenchSnapshotPartition;\n}\n\nexport interface WorkbenchHostSessionLease<TUpdate, THostInput, TState> {\n readonly release: () => void;\n readonly session: WorkbenchHostSession<TUpdate, THostInput, TState>;\n}\n\ninterface WorkbenchHostCoordinatorEntry {\n readonly configuration: object;\n leaseCount: number;\n readonly session: WorkbenchHostSession<unknown, unknown, unknown>;\n}\n\nexport interface WorkbenchHostCoordinatorOptions {\n readonly diagnostics?: WorkbenchDiagnosticsPort;\n}\n\nexport function createWorkbenchHostSessionConfiguration<\n TUpdate,\n THostInput,\n TState\n>(input: {\n readonly createSession: (\n partition: WorkbenchSnapshotPartition\n ) => WorkbenchHostSession<TUpdate, THostInput, TState>;\n}): WorkbenchHostSessionConfiguration<TUpdate, THostInput, TState> {\n return input as WorkbenchHostSessionConfiguration<\n TUpdate,\n THostInput,\n TState\n >;\n}\n\nexport class WorkbenchHostCoordinator {\n private disposed = false;\n private readonly options: WorkbenchHostCoordinatorOptions;\n private readonly sessionsByScope = new Map<\n string,\n WorkbenchHostCoordinatorEntry\n >();\n\n constructor(options: WorkbenchHostCoordinatorOptions = {}) {\n this.options = options;\n }\n\n open<TUpdate, THostInput, TState>(\n input: WorkbenchHostSessionOpenInput<TUpdate, THostInput, TState>\n ): WorkbenchHostSessionLease<TUpdate, THostInput, TState> {\n this.assertActive();\n const scopeKey = createWorkbenchScopeKey(input.partition.scope);\n let entry = this.sessionsByScope.get(scopeKey);\n if (\n entry &&\n !areWorkbenchSnapshotPartitionsEqual(\n entry.session.partition,\n input.partition\n )\n ) {\n this.sessionsByScope.delete(scopeKey);\n this.disposeSession(entry.session);\n entry = undefined;\n }\n\n if (entry && entry.configuration !== input.configuration) {\n throw new Error(\n \"Workbench host session partition is already owned by another configuration.\"\n );\n }\n\n if (!entry || entry.session.isDisposed) {\n const session = input.configuration.createSession(input.partition);\n if (\n !areWorkbenchSnapshotPartitionsEqual(session.partition, input.partition)\n ) {\n this.disposeSession(session);\n throw new Error(\n \"Workbench host session partition does not match the open request.\"\n );\n }\n entry = {\n configuration: input.configuration,\n leaseCount: 0,\n session: session as WorkbenchHostSession<unknown, unknown, unknown>\n };\n this.sessionsByScope.set(scopeKey, entry);\n }\n\n entry.leaseCount += 1;\n const leasedEntry = entry;\n const session = entry.session as WorkbenchHostSession<\n TUpdate,\n THostInput,\n TState\n >;\n let released = false;\n return {\n release: () => {\n if (released) {\n return;\n }\n released = true;\n this.release(scopeKey, leasedEntry);\n },\n session\n };\n }\n\n get<TUpdate, THostInput, TState>(\n configuration: WorkbenchHostSessionConfiguration<\n TUpdate,\n THostInput,\n TState\n >,\n partition: WorkbenchSnapshotPartition\n ): WorkbenchHostSession<TUpdate, THostInput, TState> | null {\n if (this.disposed) {\n return null;\n }\n const scopeKey = createWorkbenchScopeKey(partition.scope);\n const entry = this.sessionsByScope.get(scopeKey);\n if (!entry) {\n return null;\n }\n if (entry.configuration !== configuration) {\n return null;\n }\n if (entry.session.isDisposed) {\n this.sessionsByScope.delete(scopeKey);\n return null;\n }\n if (\n !areWorkbenchSnapshotPartitionsEqual(entry.session.partition, partition)\n ) {\n return null;\n }\n return entry.session as WorkbenchHostSession<TUpdate, THostInput, TState>;\n }\n\n dispose(): void {\n if (this.disposed) {\n return;\n }\n this.disposed = true;\n const entries = Array.from(this.sessionsByScope.values());\n this.sessionsByScope.clear();\n for (const entry of entries) {\n this.disposeSession(entry.session);\n }\n }\n\n private assertActive(): void {\n if (this.disposed) {\n throw new Error(\"Workbench host coordinator is disposed.\");\n }\n }\n\n private release(\n scopeKey: string,\n leasedEntry: WorkbenchHostCoordinatorEntry\n ): void {\n const currentEntry = this.sessionsByScope.get(scopeKey);\n if (currentEntry !== leasedEntry) {\n return;\n }\n leasedEntry.leaseCount -= 1;\n if (leasedEntry.leaseCount > 0) {\n return;\n }\n this.sessionsByScope.delete(scopeKey);\n this.disposeSession(leasedEntry.session);\n }\n\n private disposeSession<TUpdate, THostInput, TState>(\n session: WorkbenchHostSession<TUpdate, THostInput, TState>\n ): void {\n try {\n session.dispose();\n } catch (error) {\n this.reportDisposalError(error);\n }\n }\n\n private reportDisposalError(error: unknown): void {\n try {\n const result = this.options.diagnostics?.report({\n error,\n event: \"workbench.host.coordinator.dispose_failed\"\n });\n void result?.catch(() => undefined);\n } catch {\n // Disposal must continue even when diagnostics fail.\n }\n }\n}\n","import type { WorkbenchContribution } from \"@tutti-os/workbench-surface\";\n\nexport interface WorkbenchCapabilityFactoryDescriptor {\n readonly id: string;\n readonly order: number;\n readonly create: () => WorkbenchContribution | null;\n}\n\nexport interface WorkbenchCapabilityRegistryInput {\n readonly capabilityFactories: readonly WorkbenchCapabilityFactoryDescriptor[];\n}\n\nexport interface WorkbenchCapabilityRegistryResult {\n readonly contributions: readonly WorkbenchContribution[];\n}\n\ninterface ResolvedWorkbenchCapability {\n readonly contribution: WorkbenchContribution;\n readonly factoryId: string;\n}\n\nexport function resolveWorkbenchCapabilityRegistry(\n input: WorkbenchCapabilityRegistryInput\n): WorkbenchCapabilityRegistryResult {\n const factories = [...input.capabilityFactories].sort(\n compareWorkbenchCapabilityFactories\n );\n assertUniqueFactoryIds(factories);\n\n const resolvedCapabilities = factories.flatMap((factory) => {\n const contribution = factory.create();\n return contribution ? [{ contribution, factoryId: factory.id }] : [];\n });\n assertUniqueContributionOwnership(resolvedCapabilities);\n\n return {\n contributions: resolvedCapabilities.map(({ contribution }) => contribution)\n };\n}\n\nfunction compareWorkbenchCapabilityFactories(\n left: WorkbenchCapabilityFactoryDescriptor,\n right: WorkbenchCapabilityFactoryDescriptor\n): number {\n return left.order - right.order || left.id.localeCompare(right.id);\n}\n\nfunction assertUniqueFactoryIds(\n factories: readonly WorkbenchCapabilityFactoryDescriptor[]\n): void {\n const owners = new Set<string>();\n for (const factory of factories) {\n if (owners.has(factory.id)) {\n throw new Error(\n `Workbench capability factory id \"${factory.id}\" has multiple owners.`\n );\n }\n owners.add(factory.id);\n }\n}\n\nfunction assertUniqueContributionOwnership(\n resolvedCapabilities: readonly ResolvedWorkbenchCapability[]\n): void {\n const contributionOwners = new Map<string, string>();\n const nodeOwners = new Map<string, string>();\n const dockEntryOwners = new Map<string, string>();\n\n for (const { contribution, factoryId } of resolvedCapabilities) {\n assertUniqueOwner(\n contributionOwners,\n contribution.id,\n factoryId,\n \"contribution id\"\n );\n for (const node of contribution.nodes ?? []) {\n assertUniqueOwner(\n nodeOwners,\n node.typeId,\n contribution.id,\n \"node type id\"\n );\n }\n for (const dockEntry of contribution.dockEntries ?? []) {\n assertUniqueOwner(\n dockEntryOwners,\n dockEntry.id,\n contribution.id,\n \"dock entry id\"\n );\n }\n }\n}\n\nfunction assertUniqueOwner(\n owners: Map<string, string>,\n id: string,\n owner: string,\n kind: string\n): void {\n const existingOwner = owners.get(id);\n if (existingOwner) {\n throw new Error(\n `Workbench ${kind} \"${id}\" is owned by both \"${existingOwner}\" and \"${owner}\".`\n );\n }\n owners.set(id, owner);\n}\n"],"mappings":";AAgCO,IAAM,uBAAN,MAAwD;AAAA,EACpD;AAAA,EACD,UACN;AAAA,EACM,WAAW;AAAA,EACF,oBAAuC,CAAC;A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ACF;AAEA,SAAS,kCACP,sBACM;AACN,QAAM,qBAAqB,oBAAI,IAAoB;AACnD,QAAM,aAAa,oBAAI,IAAoB;AAC3C,QAAM,kBAAkB,oBAAI,IAAoB;AAEhD,aAAW,EAAE,cAAc,UAAU,KAAK,sBAAsB;AAC9D;AAAA,MACE;AAAA,MACA,aAAa;AAAA,MACb;AAAA,MACA;AAAA,IACF;AACA,eAAW,QAAQ,aAAa,SAAS,CAAC,GAAG;AAC3C;AAAA,QACE;AAAA,QACA,KAAK;AAAA,QACL,aAAa;AAAA,QACb;AAAA,MACF;AAAA,IACF;AACA,eAAW,aAAa,aAAa,eAAe,CAAC,GAAG;AACtD;AAAA,QACE;AAAA,QACA,UAAU;AAAA,QACV,aAAa;AAAA,QACb;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;AAEA,SAAS,kBACP,QACA,IACA,OACA,MACM;AACN,QAAM,gBAAgB,OAAO,IAAI,EAAE;AACnC,MAAI,eAAe;AACjB,UAAM,IAAI;AAAA,MACR,aAAa,IAAI,KAAK,EAAE,uBAAuB,aAAa,UAAU,KAAK;AAAA,IAC7E;AAAA,EACF;AACA,SAAO,IAAI,IAAI,KAAK;AACtB;","names":["session"]}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { WorkbenchCapabilityRegistryInput, WorkbenchHostCoordinator, WorkbenchSnapshotPartition } from '../index.js';
|
|
2
|
+
import '@tutti-os/workbench-surface';
|
|
3
|
+
|
|
4
|
+
interface WorkbenchHostConformanceCase {
|
|
5
|
+
readonly name: string;
|
|
6
|
+
readonly run: () => Promise<void> | void;
|
|
7
|
+
}
|
|
8
|
+
interface WorkbenchHostConformancePartitionInput {
|
|
9
|
+
readonly principalId?: string;
|
|
10
|
+
readonly scopeId: string;
|
|
11
|
+
}
|
|
12
|
+
interface WorkbenchHostConformanceOptions {
|
|
13
|
+
readonly capabilityProfile?: WorkbenchCapabilityRegistryInput;
|
|
14
|
+
readonly createCoordinator?: () => WorkbenchHostCoordinator;
|
|
15
|
+
readonly createPartition?: (input: WorkbenchHostConformancePartitionInput) => WorkbenchSnapshotPartition;
|
|
16
|
+
readonly expectedContributionIds?: readonly string[];
|
|
17
|
+
}
|
|
18
|
+
declare function createWorkbenchHostConformanceCases(options?: WorkbenchHostConformanceOptions): readonly WorkbenchHostConformanceCase[];
|
|
19
|
+
|
|
20
|
+
export { type WorkbenchHostConformanceCase, type WorkbenchHostConformanceOptions, type WorkbenchHostConformancePartitionInput, createWorkbenchHostConformanceCases };
|
|
@@ -0,0 +1,310 @@
|
|
|
1
|
+
import {
|
|
2
|
+
WorkbenchHostCoordinator,
|
|
3
|
+
WorkbenchHostSession,
|
|
4
|
+
createWorkbenchHostSessionConfiguration,
|
|
5
|
+
resolveWorkbenchCapabilityRegistry
|
|
6
|
+
} from "../chunk-KN7VKRMB.js";
|
|
7
|
+
|
|
8
|
+
// src/conformance/workbenchHostConformance.ts
|
|
9
|
+
function createWorkbenchHostConformanceCases(options = {}) {
|
|
10
|
+
const createCoordinator = options.createCoordinator ?? (() => new WorkbenchHostCoordinator());
|
|
11
|
+
const createPartition = options.createPartition ?? createDefaultPartition;
|
|
12
|
+
const capabilityProfile = options.capabilityProfile ?? createDefaultCapabilityProfile();
|
|
13
|
+
const expectedContributionIds = options.expectedContributionIds ?? [
|
|
14
|
+
"capability-a",
|
|
15
|
+
"capability-b"
|
|
16
|
+
];
|
|
17
|
+
if (options.capabilityProfile && options.expectedContributionIds === void 0) {
|
|
18
|
+
throw new Error(
|
|
19
|
+
"Workbench host conformance requires expected contribution ids for a custom capability profile."
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
return [
|
|
23
|
+
{
|
|
24
|
+
name: "reuses one live session for repeated opens in one coordinator",
|
|
25
|
+
run: () => {
|
|
26
|
+
const coordinator = createCoordinator();
|
|
27
|
+
let disposeCount = 0;
|
|
28
|
+
const configuration = createFixtureConfiguration(() => {
|
|
29
|
+
disposeCount += 1;
|
|
30
|
+
});
|
|
31
|
+
const partition = createPartition({ scopeId: "scope-a" });
|
|
32
|
+
const firstLease = coordinator.open({ configuration, partition });
|
|
33
|
+
const secondLease = coordinator.open({ configuration, partition });
|
|
34
|
+
assertSame(firstLease.session, secondLease.session, "session reuse");
|
|
35
|
+
firstLease.release();
|
|
36
|
+
assertFalse(firstLease.session.isDisposed, "first lease release");
|
|
37
|
+
secondLease.release();
|
|
38
|
+
assertTrue(firstLease.session.isDisposed, "last lease release");
|
|
39
|
+
assertEqual(disposeCount, 1, "session disposal count");
|
|
40
|
+
coordinator.dispose();
|
|
41
|
+
assertEqual(disposeCount, 1, "coordinator idempotent disposal");
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
name: "keeps the same partition isolated across renderer coordinators",
|
|
46
|
+
run: () => {
|
|
47
|
+
const firstCoordinator = createCoordinator();
|
|
48
|
+
const secondCoordinator = createCoordinator();
|
|
49
|
+
const configuration = createFixtureConfiguration();
|
|
50
|
+
const partition = createPartition({ scopeId: "scope-a" });
|
|
51
|
+
const firstLease = firstCoordinator.open({ configuration, partition });
|
|
52
|
+
const secondLease = secondCoordinator.open({
|
|
53
|
+
configuration,
|
|
54
|
+
partition
|
|
55
|
+
});
|
|
56
|
+
assertNotSame(
|
|
57
|
+
firstLease.session,
|
|
58
|
+
secondLease.session,
|
|
59
|
+
"renderer-local sessions"
|
|
60
|
+
);
|
|
61
|
+
firstLease.release();
|
|
62
|
+
secondLease.release();
|
|
63
|
+
firstCoordinator.dispose();
|
|
64
|
+
secondCoordinator.dispose();
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
name: "keeps concurrent distinct scope partitions independent",
|
|
69
|
+
run: () => {
|
|
70
|
+
const coordinator = createCoordinator();
|
|
71
|
+
const configuration = createFixtureConfiguration();
|
|
72
|
+
const firstLease = coordinator.open({
|
|
73
|
+
configuration,
|
|
74
|
+
partition: createPartition({ scopeId: "scope-a" })
|
|
75
|
+
});
|
|
76
|
+
const secondLease = coordinator.open({
|
|
77
|
+
configuration,
|
|
78
|
+
partition: createPartition({ scopeId: "scope-b" })
|
|
79
|
+
});
|
|
80
|
+
assertNotSame(
|
|
81
|
+
firstLease.session,
|
|
82
|
+
secondLease.session,
|
|
83
|
+
"scope sessions"
|
|
84
|
+
);
|
|
85
|
+
firstLease.release();
|
|
86
|
+
assertFalse(
|
|
87
|
+
secondLease.session.isDisposed,
|
|
88
|
+
"independent scope session"
|
|
89
|
+
);
|
|
90
|
+
secondLease.release();
|
|
91
|
+
coordinator.dispose();
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
name: "replaces a scope session when its principal partition changes",
|
|
96
|
+
run: () => {
|
|
97
|
+
const coordinator = createCoordinator();
|
|
98
|
+
const configuration = createFixtureConfiguration();
|
|
99
|
+
const firstLease = coordinator.open({
|
|
100
|
+
configuration,
|
|
101
|
+
partition: createPartition({
|
|
102
|
+
principalId: "principal-a",
|
|
103
|
+
scopeId: "scope-a"
|
|
104
|
+
})
|
|
105
|
+
});
|
|
106
|
+
const replacementLease = coordinator.open({
|
|
107
|
+
configuration,
|
|
108
|
+
partition: createPartition({
|
|
109
|
+
principalId: "principal-b",
|
|
110
|
+
scopeId: "scope-a"
|
|
111
|
+
})
|
|
112
|
+
});
|
|
113
|
+
assertTrue(firstLease.session.isDisposed, "replaced session disposal");
|
|
114
|
+
assertNotSame(
|
|
115
|
+
firstLease.session,
|
|
116
|
+
replacementLease.session,
|
|
117
|
+
"principal replacement"
|
|
118
|
+
);
|
|
119
|
+
firstLease.release();
|
|
120
|
+
replacementLease.release();
|
|
121
|
+
coordinator.dispose();
|
|
122
|
+
}
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
name: "preserves replacement surface ownership across stale detach",
|
|
126
|
+
run: () => {
|
|
127
|
+
const coordinator = createCoordinator();
|
|
128
|
+
const configuration = createFixtureConfiguration();
|
|
129
|
+
const lease = coordinator.open({
|
|
130
|
+
configuration,
|
|
131
|
+
partition: createPartition({ scopeId: "scope-a" })
|
|
132
|
+
});
|
|
133
|
+
const firstHandle = {};
|
|
134
|
+
const replacementHandle = {};
|
|
135
|
+
const firstOwner = {};
|
|
136
|
+
const replacementOwner = {};
|
|
137
|
+
lease.session.attachSurface(firstHandle, firstOwner);
|
|
138
|
+
lease.session.attachSurface(replacementHandle, replacementOwner);
|
|
139
|
+
lease.session.attachSurface(null, firstOwner);
|
|
140
|
+
assertSame(
|
|
141
|
+
lease.session.getAttachedSurface(),
|
|
142
|
+
replacementHandle,
|
|
143
|
+
"stale surface detach"
|
|
144
|
+
);
|
|
145
|
+
lease.session.attachSurface(null, replacementOwner);
|
|
146
|
+
assertEqual(
|
|
147
|
+
lease.session.getAttachedSurface(),
|
|
148
|
+
null,
|
|
149
|
+
"replacement surface detach"
|
|
150
|
+
);
|
|
151
|
+
lease.release();
|
|
152
|
+
coordinator.dispose();
|
|
153
|
+
}
|
|
154
|
+
},
|
|
155
|
+
{
|
|
156
|
+
name: "publishes stable host input and rejects work after disposal",
|
|
157
|
+
run: () => {
|
|
158
|
+
const coordinator = createCoordinator();
|
|
159
|
+
const configuration = createFixtureConfiguration();
|
|
160
|
+
const lease = coordinator.open({
|
|
161
|
+
configuration,
|
|
162
|
+
partition: createPartition({ scopeId: "scope-a" })
|
|
163
|
+
});
|
|
164
|
+
let publicationCount = 0;
|
|
165
|
+
lease.session.subscribe(() => {
|
|
166
|
+
publicationCount += 1;
|
|
167
|
+
});
|
|
168
|
+
const first = lease.session.update({ value: "first" });
|
|
169
|
+
const reused = lease.session.update({
|
|
170
|
+
reuseCurrent: true,
|
|
171
|
+
value: "ignored"
|
|
172
|
+
});
|
|
173
|
+
const second = lease.session.update({ value: "second" });
|
|
174
|
+
assertSame(first, reused, "stable host input identity");
|
|
175
|
+
assertNotSame(first, second, "changed host input identity");
|
|
176
|
+
assertEqual(publicationCount, 2, "host input publications");
|
|
177
|
+
lease.release();
|
|
178
|
+
assertThrows(
|
|
179
|
+
() => lease.session.update({ value: "late" }),
|
|
180
|
+
"disposed",
|
|
181
|
+
"late update"
|
|
182
|
+
);
|
|
183
|
+
assertThrows(
|
|
184
|
+
() => lease.session.attachSurface({}, {}),
|
|
185
|
+
"disposed",
|
|
186
|
+
"late surface attachment"
|
|
187
|
+
);
|
|
188
|
+
coordinator.dispose();
|
|
189
|
+
}
|
|
190
|
+
},
|
|
191
|
+
{
|
|
192
|
+
name: "resolves capability ownership in deterministic order",
|
|
193
|
+
run: () => {
|
|
194
|
+
const result = resolveWorkbenchCapabilityRegistry(capabilityProfile);
|
|
195
|
+
assertArrayEqual(
|
|
196
|
+
result.contributions.map(({ id }) => id),
|
|
197
|
+
expectedContributionIds,
|
|
198
|
+
"contribution order"
|
|
199
|
+
);
|
|
200
|
+
}
|
|
201
|
+
},
|
|
202
|
+
{
|
|
203
|
+
name: "rejects duplicate capability ownership before publication",
|
|
204
|
+
run: () => {
|
|
205
|
+
assertThrows(
|
|
206
|
+
() => resolveWorkbenchCapabilityRegistry({
|
|
207
|
+
capabilityFactories: [
|
|
208
|
+
createCapabilityFactory("factory-a", 10, "duplicate"),
|
|
209
|
+
createCapabilityFactory("factory-b", 20, "duplicate")
|
|
210
|
+
]
|
|
211
|
+
}),
|
|
212
|
+
"owned by both",
|
|
213
|
+
"duplicate contribution ownership"
|
|
214
|
+
);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
];
|
|
218
|
+
}
|
|
219
|
+
function createDefaultPartition(input) {
|
|
220
|
+
return {
|
|
221
|
+
...input.principalId ? { principal: { id: input.principalId } } : {},
|
|
222
|
+
scope: { id: input.scopeId, kind: "workspace" }
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
function createDefaultCapabilityProfile() {
|
|
226
|
+
return {
|
|
227
|
+
capabilityFactories: [
|
|
228
|
+
createCapabilityFactory("factory-b", 20, "capability-b"),
|
|
229
|
+
createCapabilityFactory("factory-a", 10, "capability-a"),
|
|
230
|
+
{
|
|
231
|
+
create: () => null,
|
|
232
|
+
id: "unavailable",
|
|
233
|
+
order: 0
|
|
234
|
+
}
|
|
235
|
+
]
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
function createCapabilityFactory(id, order, contributionId) {
|
|
239
|
+
return {
|
|
240
|
+
create: () => ({ id: contributionId }),
|
|
241
|
+
id,
|
|
242
|
+
order
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
function createFixtureConfiguration(onDispose = noop) {
|
|
246
|
+
return createWorkbenchHostSessionConfiguration({
|
|
247
|
+
createSession: (partition) => {
|
|
248
|
+
const session = new WorkbenchHostSession({
|
|
249
|
+
partition,
|
|
250
|
+
resolve: resolveFixtureHostInput
|
|
251
|
+
});
|
|
252
|
+
session.registerDisposable(onDispose);
|
|
253
|
+
return session;
|
|
254
|
+
}
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
function resolveFixtureHostInput(update, current) {
|
|
258
|
+
if (update.reuseCurrent && current) {
|
|
259
|
+
return current;
|
|
260
|
+
}
|
|
261
|
+
return {
|
|
262
|
+
hostInput: { value: update.value },
|
|
263
|
+
state: update.value
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
function assertArrayEqual(actual, expected, label) {
|
|
267
|
+
if (actual.length !== expected.length || actual.some((value, index) => value !== expected[index])) {
|
|
268
|
+
throw new Error(
|
|
269
|
+
`${label}: expected ${JSON.stringify(expected)}, received ${JSON.stringify(actual)}`
|
|
270
|
+
);
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
function assertEqual(actual, expected, label) {
|
|
274
|
+
if (actual !== expected) {
|
|
275
|
+
throw new Error(`${label}: values are not equal`);
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
function assertFalse(value, label) {
|
|
279
|
+
assertEqual(value, false, label);
|
|
280
|
+
}
|
|
281
|
+
function assertNotSame(actual, expected, label) {
|
|
282
|
+
if (actual === expected) {
|
|
283
|
+
throw new Error(`${label}: values unexpectedly share identity`);
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
function assertSame(actual, expected, label) {
|
|
287
|
+
if (actual !== expected) {
|
|
288
|
+
throw new Error(`${label}: values do not share identity`);
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
function assertThrows(run, expectedMessage, label) {
|
|
292
|
+
try {
|
|
293
|
+
run();
|
|
294
|
+
} catch (error) {
|
|
295
|
+
if (error instanceof Error && error.message.toLowerCase().includes(expectedMessage.toLowerCase())) {
|
|
296
|
+
return;
|
|
297
|
+
}
|
|
298
|
+
throw error;
|
|
299
|
+
}
|
|
300
|
+
throw new Error(`${label}: expected an error containing ${expectedMessage}`);
|
|
301
|
+
}
|
|
302
|
+
function assertTrue(value, label) {
|
|
303
|
+
assertEqual(value, true, label);
|
|
304
|
+
}
|
|
305
|
+
function noop() {
|
|
306
|
+
}
|
|
307
|
+
export {
|
|
308
|
+
createWorkbenchHostConformanceCases
|
|
309
|
+
};
|
|
310
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/conformance/workbenchHostConformance.ts"],"sourcesContent":["import type {\n WorkbenchContribution,\n WorkbenchHostHandle\n} from \"@tutti-os/workbench-surface\";\n\nimport type { WorkbenchCapabilityRegistryInput } from \"../capabilities/workbenchCapabilityRegistry.ts\";\nimport { resolveWorkbenchCapabilityRegistry } from \"../capabilities/workbenchCapabilityRegistry.ts\";\nimport {\n createWorkbenchHostSessionConfiguration,\n WorkbenchHostCoordinator\n} from \"../coordinator/workbenchHostCoordinator.ts\";\nimport {\n WorkbenchHostSession,\n type WorkbenchHostSessionResolution,\n type WorkbenchSnapshotPartition\n} from \"../session/workbenchHostSession.ts\";\n\nexport interface WorkbenchHostConformanceCase {\n readonly name: string;\n readonly run: () => Promise<void> | void;\n}\n\nexport interface WorkbenchHostConformancePartitionInput {\n readonly principalId?: string;\n readonly scopeId: string;\n}\n\nexport interface WorkbenchHostConformanceOptions {\n readonly capabilityProfile?: WorkbenchCapabilityRegistryInput;\n readonly createCoordinator?: () => WorkbenchHostCoordinator;\n readonly createPartition?: (\n input: WorkbenchHostConformancePartitionInput\n ) => WorkbenchSnapshotPartition;\n readonly expectedContributionIds?: readonly string[];\n}\n\ninterface FixtureUpdate {\n readonly reuseCurrent?: boolean;\n readonly value: string;\n}\n\ninterface FixtureHostInput {\n readonly value: string;\n}\n\nexport function createWorkbenchHostConformanceCases(\n options: WorkbenchHostConformanceOptions = {}\n): readonly WorkbenchHostConformanceCase[] {\n const createCoordinator =\n options.createCoordinator ?? (() => new WorkbenchHostCoordinator());\n const createPartition = options.createPartition ?? createDefaultPartition;\n const capabilityProfile =\n options.capabilityProfile ?? createDefaultCapabilityProfile();\n const expectedContributionIds = options.expectedContributionIds ?? [\n \"capability-a\",\n \"capability-b\"\n ];\n\n if (\n options.capabilityProfile &&\n options.expectedContributionIds === undefined\n ) {\n throw new Error(\n \"Workbench host conformance requires expected contribution ids for a custom capability profile.\"\n );\n }\n\n return [\n {\n name: \"reuses one live session for repeated opens in one coordinator\",\n run: () => {\n const coordinator = createCoordinator();\n let disposeCount = 0;\n const configuration = createFixtureConfiguration(() => {\n disposeCount += 1;\n });\n const partition = createPartition({ scopeId: \"scope-a\" });\n const firstLease = coordinator.open({ configuration, partition });\n const secondLease = coordinator.open({ configuration, partition });\n\n assertSame(firstLease.session, secondLease.session, \"session reuse\");\n firstLease.release();\n assertFalse(firstLease.session.isDisposed, \"first lease release\");\n secondLease.release();\n assertTrue(firstLease.session.isDisposed, \"last lease release\");\n assertEqual(disposeCount, 1, \"session disposal count\");\n coordinator.dispose();\n assertEqual(disposeCount, 1, \"coordinator idempotent disposal\");\n }\n },\n {\n name: \"keeps the same partition isolated across renderer coordinators\",\n run: () => {\n const firstCoordinator = createCoordinator();\n const secondCoordinator = createCoordinator();\n const configuration = createFixtureConfiguration();\n const partition = createPartition({ scopeId: \"scope-a\" });\n const firstLease = firstCoordinator.open({ configuration, partition });\n const secondLease = secondCoordinator.open({\n configuration,\n partition\n });\n\n assertNotSame(\n firstLease.session,\n secondLease.session,\n \"renderer-local sessions\"\n );\n firstLease.release();\n secondLease.release();\n firstCoordinator.dispose();\n secondCoordinator.dispose();\n }\n },\n {\n name: \"keeps concurrent distinct scope partitions independent\",\n run: () => {\n const coordinator = createCoordinator();\n const configuration = createFixtureConfiguration();\n const firstLease = coordinator.open({\n configuration,\n partition: createPartition({ scopeId: \"scope-a\" })\n });\n const secondLease = coordinator.open({\n configuration,\n partition: createPartition({ scopeId: \"scope-b\" })\n });\n\n assertNotSame(\n firstLease.session,\n secondLease.session,\n \"scope sessions\"\n );\n firstLease.release();\n assertFalse(\n secondLease.session.isDisposed,\n \"independent scope session\"\n );\n secondLease.release();\n coordinator.dispose();\n }\n },\n {\n name: \"replaces a scope session when its principal partition changes\",\n run: () => {\n const coordinator = createCoordinator();\n const configuration = createFixtureConfiguration();\n const firstLease = coordinator.open({\n configuration,\n partition: createPartition({\n principalId: \"principal-a\",\n scopeId: \"scope-a\"\n })\n });\n const replacementLease = coordinator.open({\n configuration,\n partition: createPartition({\n principalId: \"principal-b\",\n scopeId: \"scope-a\"\n })\n });\n\n assertTrue(firstLease.session.isDisposed, \"replaced session disposal\");\n assertNotSame(\n firstLease.session,\n replacementLease.session,\n \"principal replacement\"\n );\n firstLease.release();\n replacementLease.release();\n coordinator.dispose();\n }\n },\n {\n name: \"preserves replacement surface ownership across stale detach\",\n run: () => {\n const coordinator = createCoordinator();\n const configuration = createFixtureConfiguration();\n const lease = coordinator.open({\n configuration,\n partition: createPartition({ scopeId: \"scope-a\" })\n });\n const firstHandle = {} as WorkbenchHostHandle;\n const replacementHandle = {} as WorkbenchHostHandle;\n const firstOwner = {};\n const replacementOwner = {};\n\n lease.session.attachSurface(firstHandle, firstOwner);\n lease.session.attachSurface(replacementHandle, replacementOwner);\n lease.session.attachSurface(null, firstOwner);\n assertSame(\n lease.session.getAttachedSurface(),\n replacementHandle,\n \"stale surface detach\"\n );\n lease.session.attachSurface(null, replacementOwner);\n assertEqual(\n lease.session.getAttachedSurface(),\n null,\n \"replacement surface detach\"\n );\n lease.release();\n coordinator.dispose();\n }\n },\n {\n name: \"publishes stable host input and rejects work after disposal\",\n run: () => {\n const coordinator = createCoordinator();\n const configuration = createFixtureConfiguration();\n const lease = coordinator.open({\n configuration,\n partition: createPartition({ scopeId: \"scope-a\" })\n });\n let publicationCount = 0;\n lease.session.subscribe(() => {\n publicationCount += 1;\n });\n\n const first = lease.session.update({ value: \"first\" });\n const reused = lease.session.update({\n reuseCurrent: true,\n value: \"ignored\"\n });\n const second = lease.session.update({ value: \"second\" });\n\n assertSame(first, reused, \"stable host input identity\");\n assertNotSame(first, second, \"changed host input identity\");\n assertEqual(publicationCount, 2, \"host input publications\");\n lease.release();\n assertThrows(\n () => lease.session.update({ value: \"late\" }),\n \"disposed\",\n \"late update\"\n );\n assertThrows(\n () => lease.session.attachSurface({} as WorkbenchHostHandle, {}),\n \"disposed\",\n \"late surface attachment\"\n );\n coordinator.dispose();\n }\n },\n {\n name: \"resolves capability ownership in deterministic order\",\n run: () => {\n const result = resolveWorkbenchCapabilityRegistry(capabilityProfile);\n assertArrayEqual(\n result.contributions.map(({ id }) => id),\n expectedContributionIds,\n \"contribution order\"\n );\n }\n },\n {\n name: \"rejects duplicate capability ownership before publication\",\n run: () => {\n assertThrows(\n () =>\n resolveWorkbenchCapabilityRegistry({\n capabilityFactories: [\n createCapabilityFactory(\"factory-a\", 10, \"duplicate\"),\n createCapabilityFactory(\"factory-b\", 20, \"duplicate\")\n ]\n }),\n \"owned by both\",\n \"duplicate contribution ownership\"\n );\n }\n }\n ];\n}\n\nfunction createDefaultPartition(\n input: WorkbenchHostConformancePartitionInput\n): WorkbenchSnapshotPartition {\n return {\n ...(input.principalId ? { principal: { id: input.principalId } } : {}),\n scope: { id: input.scopeId, kind: \"workspace\" }\n };\n}\n\nfunction createDefaultCapabilityProfile(): WorkbenchCapabilityRegistryInput {\n return {\n capabilityFactories: [\n createCapabilityFactory(\"factory-b\", 20, \"capability-b\"),\n createCapabilityFactory(\"factory-a\", 10, \"capability-a\"),\n {\n create: () => null,\n id: \"unavailable\",\n order: 0\n }\n ]\n };\n}\n\nfunction createCapabilityFactory(\n id: string,\n order: number,\n contributionId: string\n) {\n return {\n create: (): WorkbenchContribution => ({ id: contributionId }),\n id,\n order\n };\n}\n\nfunction createFixtureConfiguration(onDispose: () => void = noop) {\n return createWorkbenchHostSessionConfiguration<\n FixtureUpdate,\n FixtureHostInput,\n string\n >({\n createSession: (partition) => {\n const session = new WorkbenchHostSession<\n FixtureUpdate,\n FixtureHostInput,\n string\n >({\n partition,\n resolve: resolveFixtureHostInput\n });\n session.registerDisposable(onDispose);\n return session;\n }\n });\n}\n\nfunction resolveFixtureHostInput(\n update: FixtureUpdate,\n current: WorkbenchHostSessionResolution<FixtureHostInput, string> | null\n): WorkbenchHostSessionResolution<FixtureHostInput, string> {\n if (update.reuseCurrent && current) {\n return current;\n }\n return {\n hostInput: { value: update.value },\n state: update.value\n };\n}\n\nfunction assertArrayEqual(\n actual: readonly string[],\n expected: readonly string[],\n label: string\n): void {\n if (\n actual.length !== expected.length ||\n actual.some((value, index) => value !== expected[index])\n ) {\n throw new Error(\n `${label}: expected ${JSON.stringify(expected)}, received ${JSON.stringify(actual)}`\n );\n }\n}\n\nfunction assertEqual<T>(actual: T, expected: T, label: string): void {\n if (actual !== expected) {\n throw new Error(`${label}: values are not equal`);\n }\n}\n\nfunction assertFalse(value: boolean, label: string): void {\n assertEqual(value, false, label);\n}\n\nfunction assertNotSame<T>(actual: T, expected: T, label: string): void {\n if (actual === expected) {\n throw new Error(`${label}: values unexpectedly share identity`);\n }\n}\n\nfunction assertSame<T>(actual: T, expected: T, label: string): void {\n if (actual !== expected) {\n throw new Error(`${label}: values do not share identity`);\n }\n}\n\nfunction assertThrows(\n run: () => void,\n expectedMessage: string,\n label: string\n): void {\n try {\n run();\n } catch (error) {\n if (\n error instanceof Error &&\n error.message.toLowerCase().includes(expectedMessage.toLowerCase())\n ) {\n return;\n }\n throw error;\n }\n throw new Error(`${label}: expected an error containing ${expectedMessage}`);\n}\n\nfunction assertTrue(value: boolean, label: string): void {\n assertEqual(value, true, label);\n}\n\nfunction noop(): void {}\n"],"mappings":";;;;;;;;AA6CO,SAAS,oCACd,UAA2C,CAAC,GACH;AACzC,QAAM,oBACJ,QAAQ,sBAAsB,MAAM,IAAI,yBAAyB;AACnE,QAAM,kBAAkB,QAAQ,mBAAmB;AACnD,QAAM,oBACJ,QAAQ,qBAAqB,+BAA+B;AAC9D,QAAM,0BAA0B,QAAQ,2BAA2B;AAAA,IACjE;AAAA,IACA;AAAA,EACF;AAEA,MACE,QAAQ,qBACR,QAAQ,4BAA4B,QACpC;AACA,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AAAA,IACL;AAAA,MACE,MAAM;AAAA,MACN,KAAK,MAAM;AACT,cAAM,cAAc,kBAAkB;AACtC,YAAI,eAAe;AACnB,cAAM,gBAAgB,2BAA2B,MAAM;AACrD,0BAAgB;AAAA,QAClB,CAAC;AACD,cAAM,YAAY,gBAAgB,EAAE,SAAS,UAAU,CAAC;AACxD,cAAM,aAAa,YAAY,KAAK,EAAE,eAAe,UAAU,CAAC;AAChE,cAAM,cAAc,YAAY,KAAK,EAAE,eAAe,UAAU,CAAC;AAEjE,mBAAW,WAAW,SAAS,YAAY,SAAS,eAAe;AACnE,mBAAW,QAAQ;AACnB,oBAAY,WAAW,QAAQ,YAAY,qBAAqB;AAChE,oBAAY,QAAQ;AACpB,mBAAW,WAAW,QAAQ,YAAY,oBAAoB;AAC9D,oBAAY,cAAc,GAAG,wBAAwB;AACrD,oBAAY,QAAQ;AACpB,oBAAY,cAAc,GAAG,iCAAiC;AAAA,MAChE;AAAA,IACF;AAAA,IACA;AAAA,MACE,MAAM;AAAA,MACN,KAAK,MAAM;AACT,cAAM,mBAAmB,kBAAkB;AAC3C,cAAM,oBAAoB,kBAAkB;AAC5C,cAA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AiB,QAAW,UAAa,OAAqB;AACrE,MAAI,WAAW,UAAU;AACvB,UAAM,IAAI,MAAM,GAAG,KAAK,sCAAsC;AAAA,EAChE;AACF;AAEA,SAAS,WAAc,QAAW,UAAa,OAAqB;AAClE,MAAI,WAAW,UAAU;AACvB,UAAM,IAAI,MAAM,GAAG,KAAK,gCAAgC;AAAA,EAC1D;AACF;AAEA,SAAS,aACP,KACA,iBACA,OACM;AACN,MAAI;AACF,QAAI;AAAA,EACN,SAAS,OAAO;AACd,QACE,iBAAiB,SACjB,MAAM,QAAQ,YAAY,EAAE,SAAS,gBAAgB,YAAY,CAAC,GAClE;AACA;AAAA,IACF;AACA,UAAM;AAAA,EACR;AACA,QAAM,IAAI,MAAM,GAAG,KAAK,kCAAkC,eAAe,EAAE;AAC7E;AAEA,SAAS,WAAW,OAAgB,OAAqB;AACvD,cAAY,OAAO,MAAM,KAAK;AAChC;AAEA,SAAS,OAAa;AAAC;","names":[]}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { WorkbenchHostHandle, WorkbenchContribution } from '@tutti-os/workbench-surface';
|
|
2
|
+
|
|
3
|
+
type WorkbenchHostDiagnosticEvent = "workbench.host.coordinator.dispose_failed" | "workbench.host.session.dispose_failed";
|
|
4
|
+
interface WorkbenchDiagnosticsPort {
|
|
5
|
+
report(input: {
|
|
6
|
+
readonly error: unknown;
|
|
7
|
+
readonly event: WorkbenchHostDiagnosticEvent;
|
|
8
|
+
}): Promise<void> | void;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
interface WorkbenchScope {
|
|
12
|
+
readonly id: string;
|
|
13
|
+
readonly kind: "room" | "workspace";
|
|
14
|
+
}
|
|
15
|
+
interface WorkbenchAuthenticatedPrincipalSnapshot {
|
|
16
|
+
readonly id: string;
|
|
17
|
+
}
|
|
18
|
+
interface WorkbenchSnapshotPartition {
|
|
19
|
+
readonly principal?: WorkbenchAuthenticatedPrincipalSnapshot;
|
|
20
|
+
readonly scope: WorkbenchScope;
|
|
21
|
+
}
|
|
22
|
+
interface WorkbenchHostSessionResolution<THostInput, TState> {
|
|
23
|
+
readonly hostInput: THostInput;
|
|
24
|
+
readonly state: TState;
|
|
25
|
+
}
|
|
26
|
+
interface WorkbenchHostSessionOptions<TUpdate, THostInput, TState> {
|
|
27
|
+
readonly diagnostics?: WorkbenchDiagnosticsPort;
|
|
28
|
+
readonly partition: WorkbenchSnapshotPartition;
|
|
29
|
+
readonly resolve: (update: TUpdate, current: WorkbenchHostSessionResolution<THostInput, TState> | null) => WorkbenchHostSessionResolution<THostInput, TState>;
|
|
30
|
+
}
|
|
31
|
+
declare class WorkbenchHostSession<TUpdate, THostInput, TState> {
|
|
32
|
+
readonly partition: WorkbenchSnapshotPartition;
|
|
33
|
+
private current;
|
|
34
|
+
private disposed;
|
|
35
|
+
private readonly disposalCallbacks;
|
|
36
|
+
private readonly diagnostics?;
|
|
37
|
+
private readonly listeners;
|
|
38
|
+
private readonly resolve;
|
|
39
|
+
private surfaceHandle;
|
|
40
|
+
private surfaceOwner;
|
|
41
|
+
constructor(options: WorkbenchHostSessionOptions<TUpdate, THostInput, TState>);
|
|
42
|
+
get isDisposed(): boolean;
|
|
43
|
+
attachSurface(handle: WorkbenchHostHandle | null, owner: object): void;
|
|
44
|
+
getAttachedSurface(): WorkbenchHostHandle | null;
|
|
45
|
+
getHostInput(): THostInput;
|
|
46
|
+
registerDisposable(dispose: () => void): () => void;
|
|
47
|
+
subscribe(listener: () => void): () => void;
|
|
48
|
+
update(update: TUpdate): THostInput;
|
|
49
|
+
dispose(): void;
|
|
50
|
+
private assertActive;
|
|
51
|
+
private reportDisposalError;
|
|
52
|
+
}
|
|
53
|
+
declare function areWorkbenchSnapshotPartitionsEqual(left: WorkbenchSnapshotPartition, right: WorkbenchSnapshotPartition): boolean;
|
|
54
|
+
|
|
55
|
+
declare const workbenchHostSessionConfigurationBrand: unique symbol;
|
|
56
|
+
interface WorkbenchHostSessionConfiguration<TUpdate, THostInput, TState> {
|
|
57
|
+
readonly [workbenchHostSessionConfigurationBrand]: {
|
|
58
|
+
readonly hostInput: THostInput;
|
|
59
|
+
readonly state: TState;
|
|
60
|
+
readonly update: TUpdate;
|
|
61
|
+
};
|
|
62
|
+
readonly createSession: (partition: WorkbenchSnapshotPartition) => WorkbenchHostSession<TUpdate, THostInput, TState>;
|
|
63
|
+
}
|
|
64
|
+
interface WorkbenchHostSessionOpenInput<TUpdate, THostInput, TState> {
|
|
65
|
+
readonly configuration: WorkbenchHostSessionConfiguration<TUpdate, THostInput, TState>;
|
|
66
|
+
readonly partition: WorkbenchSnapshotPartition;
|
|
67
|
+
}
|
|
68
|
+
interface WorkbenchHostSessionLease<TUpdate, THostInput, TState> {
|
|
69
|
+
readonly release: () => void;
|
|
70
|
+
readonly session: WorkbenchHostSession<TUpdate, THostInput, TState>;
|
|
71
|
+
}
|
|
72
|
+
interface WorkbenchHostCoordinatorOptions {
|
|
73
|
+
readonly diagnostics?: WorkbenchDiagnosticsPort;
|
|
74
|
+
}
|
|
75
|
+
declare function createWorkbenchHostSessionConfiguration<TUpdate, THostInput, TState>(input: {
|
|
76
|
+
readonly createSession: (partition: WorkbenchSnapshotPartition) => WorkbenchHostSession<TUpdate, THostInput, TState>;
|
|
77
|
+
}): WorkbenchHostSessionConfiguration<TUpdate, THostInput, TState>;
|
|
78
|
+
declare class WorkbenchHostCoordinator {
|
|
79
|
+
private disposed;
|
|
80
|
+
private readonly options;
|
|
81
|
+
private readonly sessionsByScope;
|
|
82
|
+
constructor(options?: WorkbenchHostCoordinatorOptions);
|
|
83
|
+
open<TUpdate, THostInput, TState>(input: WorkbenchHostSessionOpenInput<TUpdate, THostInput, TState>): WorkbenchHostSessionLease<TUpdate, THostInput, TState>;
|
|
84
|
+
get<TUpdate, THostInput, TState>(configuration: WorkbenchHostSessionConfiguration<TUpdate, THostInput, TState>, partition: WorkbenchSnapshotPartition): WorkbenchHostSession<TUpdate, THostInput, TState> | null;
|
|
85
|
+
dispose(): void;
|
|
86
|
+
private assertActive;
|
|
87
|
+
private release;
|
|
88
|
+
private disposeSession;
|
|
89
|
+
private reportDisposalError;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
interface WorkbenchCapabilityFactoryDescriptor {
|
|
93
|
+
readonly id: string;
|
|
94
|
+
readonly order: number;
|
|
95
|
+
readonly create: () => WorkbenchContribution | null;
|
|
96
|
+
}
|
|
97
|
+
interface WorkbenchCapabilityRegistryInput {
|
|
98
|
+
readonly capabilityFactories: readonly WorkbenchCapabilityFactoryDescriptor[];
|
|
99
|
+
}
|
|
100
|
+
interface WorkbenchCapabilityRegistryResult {
|
|
101
|
+
readonly contributions: readonly WorkbenchContribution[];
|
|
102
|
+
}
|
|
103
|
+
declare function resolveWorkbenchCapabilityRegistry(input: WorkbenchCapabilityRegistryInput): WorkbenchCapabilityRegistryResult;
|
|
104
|
+
|
|
105
|
+
export { type WorkbenchAuthenticatedPrincipalSnapshot, type WorkbenchCapabilityFactoryDescriptor, type WorkbenchCapabilityRegistryInput, type WorkbenchCapabilityRegistryResult, type WorkbenchDiagnosticsPort, WorkbenchHostCoordinator, type WorkbenchHostCoordinatorOptions, type WorkbenchHostDiagnosticEvent, WorkbenchHostSession, type WorkbenchHostSessionConfiguration, type WorkbenchHostSessionLease, type WorkbenchHostSessionOpenInput, type WorkbenchHostSessionOptions, type WorkbenchHostSessionResolution, type WorkbenchScope, type WorkbenchSnapshotPartition, areWorkbenchSnapshotPartitionsEqual, createWorkbenchHostSessionConfiguration, resolveWorkbenchCapabilityRegistry };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import {
|
|
2
|
+
WorkbenchHostCoordinator,
|
|
3
|
+
WorkbenchHostSession,
|
|
4
|
+
areWorkbenchSnapshotPartitionsEqual,
|
|
5
|
+
createWorkbenchHostSessionConfiguration,
|
|
6
|
+
resolveWorkbenchCapabilityRegistry
|
|
7
|
+
} from "./chunk-KN7VKRMB.js";
|
|
8
|
+
export {
|
|
9
|
+
WorkbenchHostCoordinator,
|
|
10
|
+
WorkbenchHostSession,
|
|
11
|
+
areWorkbenchSnapshotPartitionsEqual,
|
|
12
|
+
createWorkbenchHostSessionConfiguration,
|
|
13
|
+
resolveWorkbenchCapabilityRegistry
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tutti-os/workbench-host",
|
|
3
|
+
"version": "0.0.104",
|
|
4
|
+
"private": false,
|
|
5
|
+
"type": "module",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"import": "./dist/index.js"
|
|
11
|
+
},
|
|
12
|
+
"./conformance": {
|
|
13
|
+
"types": "./dist/conformance/index.d.ts",
|
|
14
|
+
"import": "./dist/conformance/index.js"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"dist",
|
|
19
|
+
"README.md"
|
|
20
|
+
],
|
|
21
|
+
"repository": {
|
|
22
|
+
"type": "git",
|
|
23
|
+
"url": "git+https://github.com/tutti-os/tutti.git",
|
|
24
|
+
"directory": "packages/workbench/host"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@tutti-os/workbench-surface": "0.0.104",
|
|
28
|
+
"@types/node": "^24.0.1",
|
|
29
|
+
"@types/react": "^19.1.6",
|
|
30
|
+
"@types/react-dom": "^19.1.5",
|
|
31
|
+
"typescript": "^5.8.3",
|
|
32
|
+
"@tutti-os/config-tsconfig": "0.0.0"
|
|
33
|
+
},
|
|
34
|
+
"peerDependencies": {
|
|
35
|
+
"@tutti-os/workbench-surface": "0.0.104"
|
|
36
|
+
},
|
|
37
|
+
"publishConfig": {
|
|
38
|
+
"access": "public"
|
|
39
|
+
},
|
|
40
|
+
"scripts": {
|
|
41
|
+
"build": "tsup --config tsup.config.ts && node ./scripts/check-built-boundaries.mjs",
|
|
42
|
+
"test": "node --test --experimental-strip-types ./src/*.test.ts",
|
|
43
|
+
"typecheck": "node ../../../tools/scripts/run-tsgo-typecheck.mjs"
|
|
44
|
+
}
|
|
45
|
+
}
|