@kontourai/survey 8.0.0 → 8.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +2 -1
- package/dist/example-data/public-directory-review-resource.d.ts +3 -3
- package/dist/src/console/review-console-server.d.ts +20 -0
- package/dist/src/console/review-console-server.js +90 -6
- package/dist/src/mcp/review-mcp.js +9 -3
- package/dist/src/review-session-file.d.ts +6 -0
- package/dist/src/review-session-file.js +2 -0
- package/dist/src/review-workbench/review-workbench-css.generated.d.ts +9 -0
- package/dist/src/review-workbench/review-workbench-css.generated.js +421 -43
- package/dist/src/review-workbench/review-workbench-element.js +68 -212
- package/dist/src/review-workbench/review-workbench.css +354 -42
- package/dist/src/review-workbench/review-workbench.standalone.css +5 -23
- package/dist/src/review-workbench/vendor/kontourai-ui/tokens/themes.css +189 -10
- package/dist/src/review-workbench/vendor/kontourai-ui/tokens/tokens.css +156 -5
- package/package.json +13 -8
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 [yyyy] [name of copyright owner]
|
|
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
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
[](https://www.npmjs.com/package/@kontourai/survey)
|
|
8
8
|
[](https://github.com/kontourai/survey/actions/workflows/ci.yml)
|
|
9
|
+
[](https://kontourai.github.io/survey/)
|
|
9
10
|
[](LICENSE)
|
|
10
11
|
|
|
11
12
|
[Documentation](https://kontourai.github.io/survey/) · [Record Contracts](docs/record-contracts.md) · [Consumer Guide](docs/consumer-integration-guide.md) · [kontourai.io/survey](https://kontourai.io/survey)
|
|
@@ -30,7 +31,7 @@ Survey does not decide whether a real-world value is true. It preserves the prod
|
|
|
30
31
|
|
|
31
32
|
## See it
|
|
32
33
|
|
|
33
|
-
The Review Workbench rendering a real example queue — current vs proposed values, source evidence, decision effect, and the Surface projection preview
|
|
34
|
+
The Review Workbench rendering a real example queue — current vs proposed values, source evidence, decision effect, and the Surface projection preview. [Open the live demo](https://kontourai.github.io/survey/demo/).
|
|
34
35
|
|
|
35
36
|

|
|
36
37
|
|
|
@@ -35,12 +35,12 @@ export declare const publicDirectoryReviewItemExample: {
|
|
|
35
35
|
excerpt: string;
|
|
36
36
|
};
|
|
37
37
|
extraction: {
|
|
38
|
-
model?: undefined;
|
|
39
38
|
extractionId: string;
|
|
40
39
|
target: string;
|
|
41
40
|
confidence: number;
|
|
42
41
|
extractor: string;
|
|
43
42
|
extractedAt: string;
|
|
43
|
+
model?: undefined;
|
|
44
44
|
};
|
|
45
45
|
claimTarget: {
|
|
46
46
|
claimId: string;
|
|
@@ -61,13 +61,13 @@ export declare const publicDirectoryReviewItemExample: {
|
|
|
61
61
|
claimId: string;
|
|
62
62
|
};
|
|
63
63
|
producer: {
|
|
64
|
-
proposalId?: undefined;
|
|
65
|
-
oldValue?: undefined;
|
|
66
64
|
sourceAuthority: {
|
|
67
65
|
authorityClass: string;
|
|
68
66
|
declaredBy: string;
|
|
69
67
|
scope: string;
|
|
70
68
|
};
|
|
69
|
+
proposalId?: undefined;
|
|
70
|
+
oldValue?: undefined;
|
|
71
71
|
};
|
|
72
72
|
} | {
|
|
73
73
|
id: string;
|
|
@@ -12,6 +12,10 @@
|
|
|
12
12
|
* GET /api/health Health check
|
|
13
13
|
* GET /dist/* Compiled assets served from the dist tree (traversal-safe)
|
|
14
14
|
*/
|
|
15
|
+
import { type ServerReviewSessionRecord } from "../review-workbench/server-review-session.js";
|
|
16
|
+
import { type ReviewQueueBinding } from "../review-workbench/queue-binding.js";
|
|
17
|
+
import type { ReviewWorkbenchResult } from "../review-workbench/review-workbench.js";
|
|
18
|
+
import type { ReviewSessionEvent } from "../review-resource.js";
|
|
15
19
|
export interface ReviewConsoleServerOptions {
|
|
16
20
|
/** Absolute path to the session JSON file. */
|
|
17
21
|
readonly sessionPath: string;
|
|
@@ -19,6 +23,22 @@ export interface ReviewConsoleServerOptions {
|
|
|
19
23
|
readonly port?: number;
|
|
20
24
|
/** Host to bind on. Must be a loopback address. Defaults to 127.0.0.1. */
|
|
21
25
|
readonly host?: string;
|
|
26
|
+
/** Producer-owned application. The binding must come from queue construction. */
|
|
27
|
+
readonly producerApply?: {
|
|
28
|
+
readonly binding: ReviewQueueBinding;
|
|
29
|
+
/** Revalidate domain currency/authentication and apply idempotently under the producer's lock. */
|
|
30
|
+
readonly apply: (input: ReviewConsoleApplyInput) => Promise<ReviewConsoleApplication>;
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
export interface ReviewConsoleApplyInput {
|
|
34
|
+
readonly record: ServerReviewSessionRecord;
|
|
35
|
+
readonly events: readonly ReviewSessionEvent[];
|
|
36
|
+
readonly results: readonly ReviewWorkbenchResult[];
|
|
37
|
+
readonly revision: string;
|
|
38
|
+
}
|
|
39
|
+
export interface ReviewConsoleApplication {
|
|
40
|
+
readonly reference: string;
|
|
41
|
+
readonly summary: string;
|
|
22
42
|
}
|
|
23
43
|
export interface ReviewConsoleServerHandle {
|
|
24
44
|
readonly url: string;
|
|
@@ -65,7 +65,12 @@ async function readSession(path) {
|
|
|
65
65
|
// ---------------------------------------------------------------------------
|
|
66
66
|
function createSseBroadcaster() {
|
|
67
67
|
const clients = new Set();
|
|
68
|
+
let closed = false;
|
|
68
69
|
function add(res) {
|
|
70
|
+
if (closed) {
|
|
71
|
+
res.end();
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
69
74
|
clients.add(res);
|
|
70
75
|
res.on("close", () => clients.delete(res));
|
|
71
76
|
}
|
|
@@ -80,7 +85,13 @@ function createSseBroadcaster() {
|
|
|
80
85
|
}
|
|
81
86
|
}
|
|
82
87
|
}
|
|
83
|
-
|
|
88
|
+
function close() {
|
|
89
|
+
closed = true;
|
|
90
|
+
for (const res of clients)
|
|
91
|
+
res.end();
|
|
92
|
+
clients.clear();
|
|
93
|
+
}
|
|
94
|
+
return { add, broadcast, close };
|
|
84
95
|
}
|
|
85
96
|
// ---------------------------------------------------------------------------
|
|
86
97
|
// File watcher with debounce + polling fallback
|
|
@@ -163,7 +174,7 @@ async function serveDistFile(distDir, pathname, res) {
|
|
|
163
174
|
// ---------------------------------------------------------------------------
|
|
164
175
|
// HTML shell
|
|
165
176
|
// ---------------------------------------------------------------------------
|
|
166
|
-
function buildConsoleHtml(sessionPath) {
|
|
177
|
+
function buildConsoleHtml(sessionPath, canApply) {
|
|
167
178
|
const escapedPath = sessionPath.replace(/\\/g, "\\\\").replace(/"/g, '\\"').replace(/'/g, "\\'");
|
|
168
179
|
// workbench.js lives at dist/src/review-workbench/review-workbench.js relative to distRoot
|
|
169
180
|
const workbenchJsPath = "/dist/src/review-workbench/review-workbench.js";
|
|
@@ -253,7 +264,7 @@ body {
|
|
|
253
264
|
gap: 5px;
|
|
254
265
|
font-family: var(--k-font-mono, monospace);
|
|
255
266
|
font-size: 10px;
|
|
256
|
-
color: var(--k-text-faint, #
|
|
267
|
+
color: var(--k-text-faint, #75889d);
|
|
257
268
|
padding: 3px 8px;
|
|
258
269
|
border: 1px solid var(--k-line, rgba(150,180,210,0.12));
|
|
259
270
|
border-radius: 999px;
|
|
@@ -314,6 +325,7 @@ body {
|
|
|
314
325
|
</button>
|
|
315
326
|
</div>
|
|
316
327
|
</header>
|
|
328
|
+
${canApply ? '<div style="display:flex;justify-content:flex-end;padding:8px 16px"><button type="button" id="apply-review" class="theme-toggle">Send review to workflow</button></div>' : ''}
|
|
317
329
|
<div id="console-save-status" class="console-save-status" role="alert" data-testid="console-save-status" hidden></div>
|
|
318
330
|
<main id="review-workbench" class="workbench survey-workbench-embed" data-testid="review-workbench"></main>
|
|
319
331
|
<script type="module">
|
|
@@ -376,7 +388,7 @@ function createConsoleEventStore(baseRevision) {
|
|
|
376
388
|
}
|
|
377
389
|
if (res.ok) {
|
|
378
390
|
const body = await res.json().catch(() => ({}));
|
|
379
|
-
if (typeof body.revision === "string") revision = body.revision;
|
|
391
|
+
if (typeof body.revision === "string") { revision = body.revision; currentRevision = revision; }
|
|
380
392
|
persistedCount = localEvents.length;
|
|
381
393
|
showSaveStatus("");
|
|
382
394
|
return;
|
|
@@ -395,12 +407,34 @@ function createConsoleEventStore(baseRevision) {
|
|
|
395
407
|
save: (_session, events) => {
|
|
396
408
|
const localEvents = [...events];
|
|
397
409
|
saveChain = saveChain.then(() => persist(localEvents));
|
|
410
|
+
pendingSave = saveChain;
|
|
398
411
|
return saveChain;
|
|
399
412
|
},
|
|
400
413
|
};
|
|
401
414
|
}
|
|
402
415
|
|
|
403
416
|
let activeItemName = null;
|
|
417
|
+
let currentRevision = null;
|
|
418
|
+
let applying = false;
|
|
419
|
+
let wasApplied = false;
|
|
420
|
+
let pendingSave = Promise.resolve();
|
|
421
|
+
const applyButton = document.getElementById("apply-review");
|
|
422
|
+
applyButton?.addEventListener("click", async () => {
|
|
423
|
+
if (applying || !currentRevision) return;
|
|
424
|
+
applying = true;
|
|
425
|
+
applyButton.disabled = true;
|
|
426
|
+
try {
|
|
427
|
+
await pendingSave;
|
|
428
|
+
const response = await fetch("/api/apply", {
|
|
429
|
+
method: "POST", headers: { "Content-Type": "application/json" },
|
|
430
|
+
body: JSON.stringify({ baseRevision: currentRevision }),
|
|
431
|
+
});
|
|
432
|
+
const body = await response.json();
|
|
433
|
+
showSaveStatus(response.ok ? body.application.summary : body.error);
|
|
434
|
+
await fetchAndMount();
|
|
435
|
+
} catch { showSaveStatus("The review could not reach the workflow. Reload before trying again."); }
|
|
436
|
+
finally { applying = false; applyButton.disabled = wasApplied || !currentRevision; }
|
|
437
|
+
});
|
|
404
438
|
|
|
405
439
|
async function fetchAndMount() {
|
|
406
440
|
try {
|
|
@@ -414,6 +448,9 @@ async function fetchAndMount() {
|
|
|
414
448
|
}
|
|
415
449
|
const data = await res.json();
|
|
416
450
|
const { snapshot, events, revision, extractionImport } = data;
|
|
451
|
+
currentRevision = revision;
|
|
452
|
+
wasApplied = Boolean(data.producerApplication);
|
|
453
|
+
if (applyButton) applyButton.disabled = applying || wasApplied;
|
|
417
454
|
const state = events && events.length > 0
|
|
418
455
|
? replayReviewSessionEvents(snapshot, events)
|
|
419
456
|
: snapshot;
|
|
@@ -574,6 +611,10 @@ export async function startReviewConsoleServer(options) {
|
|
|
574
611
|
throw new Error("survey-review-console only serves loopback addresses");
|
|
575
612
|
}
|
|
576
613
|
const sessionPath = resolve(options.sessionPath);
|
|
614
|
+
const producerApply = options.producerApply ? {
|
|
615
|
+
binding: structuredClone(options.producerApply.binding),
|
|
616
|
+
apply: options.producerApply.apply,
|
|
617
|
+
} : undefined;
|
|
577
618
|
const distDir = distRoot();
|
|
578
619
|
const broadcaster = createSseBroadcaster();
|
|
579
620
|
const stopWatcher = watchSessionFile(sessionPath, () => {
|
|
@@ -624,6 +665,7 @@ export async function startReviewConsoleServer(options) {
|
|
|
624
665
|
revision: reviewSessionRevision(content.events),
|
|
625
666
|
state: currentSessionState(content.snapshot, content.events),
|
|
626
667
|
queueAttestation: attestation.state,
|
|
668
|
+
...(content.producerApplication ? { producerApplication: content.producerApplication } : {}),
|
|
627
669
|
...(content.extractionImport !== undefined ? { extractionImport: content.extractionImport } : {}),
|
|
628
670
|
});
|
|
629
671
|
return;
|
|
@@ -650,6 +692,8 @@ export async function startReviewConsoleServer(options) {
|
|
|
650
692
|
const outcome = await updateReviewSessionFile(sessionPath, (content) => {
|
|
651
693
|
const { snapshot, events: existingEvents } = content;
|
|
652
694
|
const revision = reviewSessionRevision(existingEvents);
|
|
695
|
+
if (content.producerApplication !== undefined)
|
|
696
|
+
return { result: { status: 409, body: { error: "This review was sent to its workflow; open a new review session", revision } } };
|
|
653
697
|
// Compare-and-swap: the appended events express decisions made on
|
|
654
698
|
// the reviewer's view of the log, so they are only safe to append
|
|
655
699
|
// when that view is the log that is stored right now.
|
|
@@ -700,6 +744,44 @@ export async function startReviewConsoleServer(options) {
|
|
|
700
744
|
sendJson(res, outcome.status, outcome.body);
|
|
701
745
|
return;
|
|
702
746
|
}
|
|
747
|
+
// ---- Producer-owned workflow application ----
|
|
748
|
+
if (pathname === "/api/apply" && req.method === "POST") {
|
|
749
|
+
if (!producerApply) {
|
|
750
|
+
sendJson(res, 404, { error: "No workflow application is configured" });
|
|
751
|
+
return;
|
|
752
|
+
}
|
|
753
|
+
const guardError = originGuard(req, listenPort) ?? contentTypeGuard(req);
|
|
754
|
+
if (guardError) {
|
|
755
|
+
sendJson(res, 403, { error: guardError });
|
|
756
|
+
return;
|
|
757
|
+
}
|
|
758
|
+
const body = await readJsonBody(req);
|
|
759
|
+
const outcome = await updateReviewSessionFile(sessionPath, async (content) => {
|
|
760
|
+
const revision = reviewSessionRevision(content.events);
|
|
761
|
+
if (typeof body.baseRevision !== "string")
|
|
762
|
+
return { result: { status: 428, body: { error: "baseRevision is required" } } };
|
|
763
|
+
if (body.baseRevision !== revision)
|
|
764
|
+
return { result: { status: 409, body: { error: "Session changed since it was read; reload before sending it" } } };
|
|
765
|
+
if (content.producerApplication !== undefined)
|
|
766
|
+
return { result: { status: 409, body: { error: "This review was already sent to its workflow" } } };
|
|
767
|
+
const record = createServerReviewSessionRecord({ sessionName: storedReviewSessionName(content), snapshot: content.snapshot, eventCount: content.events.length });
|
|
768
|
+
try {
|
|
769
|
+
const derived = deriveServerReviewSessionApplyResult({ record, events: content.events, binding: producerApply.binding, extractionImport: content.extractionImport, requiredResolvedItems: "all" });
|
|
770
|
+
if (!derived.ok)
|
|
771
|
+
return { result: { status: 422, body: { error: "Resolve every review item before sending it to the workflow" } } };
|
|
772
|
+
const application = await producerApply.apply(structuredClone({ record, events: content.events, results: derived.results, revision }));
|
|
773
|
+
if (!application || typeof application.reference !== "string" || !application.reference.trim() || application.reference.length > 2048 || typeof application.summary !== "string" || !application.summary.trim() || application.summary.length > 4096)
|
|
774
|
+
throw new Error("Workflow returned an invalid application receipt");
|
|
775
|
+
const stored = { reference: application.reference, summary: application.summary, revision };
|
|
776
|
+
return { next: { ...content, producerApplication: stored }, result: { status: 200, body: { application: stored } } };
|
|
777
|
+
}
|
|
778
|
+
catch (error) {
|
|
779
|
+
return { result: { status: 409, body: { error: error instanceof Error ? error.message : "Workflow refused this review" } } };
|
|
780
|
+
}
|
|
781
|
+
});
|
|
782
|
+
sendJson(res, outcome.status, outcome.body);
|
|
783
|
+
return;
|
|
784
|
+
}
|
|
703
785
|
// ---- Health ----
|
|
704
786
|
if (pathname === "/health" && req.method === "GET") {
|
|
705
787
|
sendJson(res, 200, { ok: true });
|
|
@@ -707,7 +789,7 @@ export async function startReviewConsoleServer(options) {
|
|
|
707
789
|
}
|
|
708
790
|
// ---- HTML shell (catch-all for GET) ----
|
|
709
791
|
if (req.method === "GET" || req.method === "HEAD") {
|
|
710
|
-
const html = buildConsoleHtml(sessionPath);
|
|
792
|
+
const html = buildConsoleHtml(sessionPath, Boolean(producerApply));
|
|
711
793
|
send(res, 200, html, "text/html; charset=utf-8");
|
|
712
794
|
return;
|
|
713
795
|
}
|
|
@@ -731,12 +813,14 @@ export async function startReviewConsoleServer(options) {
|
|
|
731
813
|
listenPort = address.port;
|
|
732
814
|
const normalizedHost = host === "::1" ? "[::1]" : host;
|
|
733
815
|
const url = `http://${normalizedHost}:${address.port}/`;
|
|
816
|
+
let closing;
|
|
734
817
|
return {
|
|
735
818
|
url,
|
|
736
819
|
port: address.port,
|
|
737
820
|
host,
|
|
738
|
-
close: () => new Promise((resolveClosed, reject) => {
|
|
821
|
+
close: () => closing ??= new Promise((resolveClosed, reject) => {
|
|
739
822
|
stopWatcher();
|
|
823
|
+
broadcaster.close();
|
|
740
824
|
server.close((err) => (err ? reject(err) : resolveClosed()));
|
|
741
825
|
}),
|
|
742
826
|
};
|
|
@@ -228,7 +228,7 @@ function buildReviewCardHtml(item, snapshot, events, attestation) {
|
|
|
228
228
|
--k-line-strong: rgba(150,180,210,0.22);
|
|
229
229
|
--k-text: #eef3f8;
|
|
230
230
|
--k-text-muted: #aebccb;
|
|
231
|
-
--k-text-faint: #
|
|
231
|
+
--k-text-faint: #75889d;
|
|
232
232
|
--k-brand: #5ce0c6;
|
|
233
233
|
--k-positive: #34d399;
|
|
234
234
|
--k-caution: #f3b14b;
|
|
@@ -236,7 +236,7 @@ function buildReviewCardHtml(item, snapshot, events, attestation) {
|
|
|
236
236
|
--k-active: #7aa2ff;
|
|
237
237
|
--k-radius-sm: 9px;
|
|
238
238
|
--k-radius-md: 14px;
|
|
239
|
-
--k-font-ui: "Hanken Grotesk",ui-sans-serif,system-ui,-apple-system,sans-serif;
|
|
239
|
+
--k-font-ui: "Hanken Grotesk",ui-sans-serif,system-ui,-apple-system,"Segoe UI",sans-serif;
|
|
240
240
|
--k-font-mono: "IBM Plex Mono",ui-monospace,SFMono-Regular,Menlo,monospace;
|
|
241
241
|
}
|
|
242
242
|
@media (prefers-color-scheme: light) {
|
|
@@ -249,7 +249,11 @@ function buildReviewCardHtml(item, snapshot, events, attestation) {
|
|
|
249
249
|
--k-line-strong: rgba(36,40,46,0.20);
|
|
250
250
|
--k-text: #202124;
|
|
251
251
|
--k-text-muted: #5b626b;
|
|
252
|
-
--k-text-faint: #
|
|
252
|
+
--k-text-faint: #6a707b;
|
|
253
|
+
/* The dark brand (#5ce0c6) reads at ~1.6:1 on the light canvas; the eyebrow
|
|
254
|
+
and source link use --k-brand as text, so light mode takes @kontourai/ui's
|
|
255
|
+
survey light brand, retinted in 1.18 to clear 4.5:1. */
|
|
256
|
+
--k-brand: #107e6d;
|
|
253
257
|
--k-positive: #168257;
|
|
254
258
|
--k-caution: #8a5a00;
|
|
255
259
|
--k-negative: #c83b3b;
|
|
@@ -491,6 +495,8 @@ async function toolDecide(itemName, mcpDecision, note, attemptEvidenceIds, optio
|
|
|
491
495
|
// Read, validate and write inside the shared session lock so a concurrent
|
|
492
496
|
// decide or console save cannot interleave and drop this decision (#281).
|
|
493
497
|
const { snapshot, sessionWithDecision, newEvents, attestation } = await updateReviewSessionFile(options.sessionPath, (file) => {
|
|
498
|
+
if (file.producerApplication !== undefined)
|
|
499
|
+
throw new DomainError("This review was already sent to its workflow; open a new review session");
|
|
494
500
|
const { snapshot, events } = file;
|
|
495
501
|
const attestation = attestedQueue(file);
|
|
496
502
|
const current = currentSessionState(snapshot, events);
|
|
@@ -21,6 +21,12 @@ export interface ReviewSessionFileContent {
|
|
|
21
21
|
* from an import is presented as an unverified queue.
|
|
22
22
|
*/
|
|
23
23
|
readonly extractionImport?: unknown;
|
|
24
|
+
/** Presentation receipt after a producer consumed this session; further appends refuse. */
|
|
25
|
+
readonly producerApplication?: {
|
|
26
|
+
readonly reference: string;
|
|
27
|
+
readonly summary: string;
|
|
28
|
+
readonly revision: string;
|
|
29
|
+
};
|
|
24
30
|
}
|
|
25
31
|
export interface ReviewSessionFileLockOptions {
|
|
26
32
|
/** How long to wait for a busy lock before failing. Defaults to 10s. */
|
|
@@ -304,6 +304,8 @@ export function storedReviewSessionName(content, fallback = defaultReviewSession
|
|
|
304
304
|
* rewritten, so decision reversals and note changes stay on record.
|
|
305
305
|
*/
|
|
306
306
|
export function appendReviewSessionEvents(content, appended) {
|
|
307
|
+
if (content.producerApplication !== undefined)
|
|
308
|
+
throw new Error("This review was already sent to its workflow; open a new review session");
|
|
307
309
|
const sessionName = storedReviewSessionName(content);
|
|
308
310
|
const start = content.events.length;
|
|
309
311
|
const renumbered = [...appended]
|
|
@@ -1,2 +1,11 @@
|
|
|
1
1
|
export declare const REVIEW_WORKBENCH_CSS: string;
|
|
2
|
+
/** Literal dark token defaults for the element's :host, from @kontourai/ui tokens.css :root. */
|
|
3
|
+
export declare const REVIEW_WORKBENCH_DARK_TOKEN_DECLARATIONS: string;
|
|
4
|
+
/** Literal light token values for the element's color-scheme="light", from @kontourai/ui tokens.css [data-theme="light"]. */
|
|
5
|
+
export declare const REVIEW_WORKBENCH_LIGHT_TOKEN_DECLARATIONS: string;
|
|
6
|
+
/** Each built-in preset's dark and light values, from @kontourai/ui themes.css. */
|
|
7
|
+
export declare const REVIEW_WORKBENCH_THEME_TOKEN_DECLARATIONS: Readonly<Record<string, {
|
|
8
|
+
readonly dark: string;
|
|
9
|
+
readonly light: string;
|
|
10
|
+
}>>;
|
|
2
11
|
export default REVIEW_WORKBENCH_CSS;
|