rivet-design 0.20.0 → 0.21.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agent-variants/SessionStore.d.ts +10 -0
- package/dist/agent-variants/SessionStore.d.ts.map +1 -1
- package/dist/agent-variants/SessionStore.js +24 -4
- package/dist/agent-variants/SessionStore.js.map +1 -1
- package/dist/agent-variants/WorkerExecutorService.d.ts.map +1 -1
- package/dist/agent-variants/WorkerExecutorService.js +24 -7
- package/dist/agent-variants/WorkerExecutorService.js.map +1 -1
- package/dist/agent-variants/WorktreeOrchestrator.d.ts +8 -23
- package/dist/agent-variants/WorktreeOrchestrator.d.ts.map +1 -1
- package/dist/agent-variants/WorktreeOrchestrator.js +27 -117
- package/dist/agent-variants/WorktreeOrchestrator.js.map +1 -1
- package/dist/agent-variants/contracts.d.ts +2 -0
- package/dist/agent-variants/contracts.d.ts.map +1 -1
- package/dist/agent-variants/contracts.js.map +1 -1
- package/dist/agent-variants/directionAuthoring.d.ts +2 -0
- package/dist/agent-variants/directionAuthoring.d.ts.map +1 -1
- package/dist/agent-variants/directionAuthoring.js +51 -8
- package/dist/agent-variants/directionAuthoring.js.map +1 -1
- package/dist/agent-variants/generationCapacity.d.ts +9 -0
- package/dist/agent-variants/generationCapacity.d.ts.map +1 -0
- package/dist/agent-variants/generationCapacity.js +70 -0
- package/dist/agent-variants/generationCapacity.js.map +1 -0
- package/dist/agent-variants/guidancePrompt.d.ts +3 -0
- package/dist/agent-variants/guidancePrompt.d.ts.map +1 -0
- package/dist/agent-variants/guidancePrompt.js +18 -0
- package/dist/agent-variants/guidancePrompt.js.map +1 -0
- package/dist/agent-variants/staticPreviewRefinements.d.ts +39 -0
- package/dist/agent-variants/staticPreviewRefinements.d.ts.map +1 -0
- package/dist/agent-variants/staticPreviewRefinements.js +158 -0
- package/dist/agent-variants/staticPreviewRefinements.js.map +1 -0
- package/dist/agent-variants/workItemBriefing.d.ts.map +1 -1
- package/dist/agent-variants/workItemBriefing.js +3 -0
- package/dist/agent-variants/workItemBriefing.js.map +1 -1
- package/dist/agent-variants/workerRuntime.d.ts +2 -0
- package/dist/agent-variants/workerRuntime.d.ts.map +1 -1
- package/dist/agent-variants/workerRuntime.js +35 -12
- package/dist/agent-variants/workerRuntime.js.map +1 -1
- package/dist/cli/client.d.ts +1 -0
- package/dist/cli/client.d.ts.map +1 -1
- package/dist/cli/client.js +3 -0
- package/dist/cli/client.js.map +1 -1
- package/dist/cli/commandNames.d.ts.map +1 -1
- package/dist/cli/commandNames.js +1 -0
- package/dist/cli/commandNames.js.map +1 -1
- package/dist/cli/commands/context.d.ts +3 -0
- package/dist/cli/commands/context.d.ts.map +1 -0
- package/dist/cli/commands/context.js +68 -0
- package/dist/cli/commands/context.js.map +1 -0
- package/dist/cli/commands/contextRequest.d.ts +12 -0
- package/dist/cli/commands/contextRequest.d.ts.map +1 -0
- package/dist/cli/commands/contextRequest.js +141 -0
- package/dist/cli/commands/contextRequest.js.map +1 -0
- package/dist/cli/commands/libraryOpen.d.ts.map +1 -1
- package/dist/cli/commands/libraryOpen.js +44 -0
- package/dist/cli/commands/libraryOpen.js.map +1 -1
- package/dist/cli/commands/mcpServe.d.ts.map +1 -1
- package/dist/cli/commands/mcpServe.js +91 -2
- package/dist/cli/commands/mcpServe.js.map +1 -1
- package/dist/cli/commands/variants.d.ts.map +1 -1
- package/dist/cli/commands/variants.js +28 -0
- package/dist/cli/commands/variants.js.map +1 -1
- package/dist/cli/guidance.d.ts +12 -0
- package/dist/cli/guidance.d.ts.map +1 -0
- package/dist/cli/guidance.js +34 -0
- package/dist/cli/guidance.js.map +1 -0
- package/dist/cli/router.d.ts.map +1 -1
- package/dist/cli/router.js +9 -0
- package/dist/cli/router.js.map +1 -1
- package/dist/library/HubClient.d.ts +11 -1
- package/dist/library/HubClient.d.ts.map +1 -1
- package/dist/library/HubClient.js +19 -3
- package/dist/library/HubClient.js.map +1 -1
- package/dist/routes/agentVariants.d.ts.map +1 -1
- package/dist/routes/agentVariants.js +99 -109
- package/dist/routes/agentVariants.js.map +1 -1
- package/dist/routes/library/guidance.d.ts +5 -0
- package/dist/routes/library/guidance.d.ts.map +1 -0
- package/dist/routes/library/guidance.js +99 -0
- package/dist/routes/library/guidance.js.map +1 -0
- package/dist/routes/library/index.d.ts.map +1 -1
- package/dist/routes/library/index.js +19 -0
- package/dist/routes/library/index.js.map +1 -1
- package/dist/routes/library/profiles.d.ts.map +1 -1
- package/dist/routes/library/profiles.js +2 -0
- package/dist/routes/library/profiles.js.map +1 -1
- package/dist/routes/variantRequestSchema.d.ts +176 -0
- package/dist/routes/variantRequestSchema.d.ts.map +1 -0
- package/dist/routes/variantRequestSchema.js +91 -0
- package/dist/routes/variantRequestSchema.js.map +1 -0
- package/dist/services/TelemetryService.d.ts +11 -0
- package/dist/services/TelemetryService.d.ts.map +1 -1
- package/dist/services/TelemetryService.js +11 -0
- package/dist/services/TelemetryService.js.map +1 -1
- package/dist/services/VariantGenerationService.d.ts +8 -0
- package/dist/services/VariantGenerationService.d.ts.map +1 -1
- package/dist/services/VariantGenerationService.js +23 -17
- package/dist/services/VariantGenerationService.js.map +1 -1
- package/dist/services/VariantHistoryService.d.ts +16 -0
- package/dist/services/VariantHistoryService.d.ts.map +1 -1
- package/dist/services/VariantHistoryService.js +51 -0
- package/dist/services/VariantHistoryService.js.map +1 -1
- package/dist/services/VariantRunService.d.ts +9 -0
- package/dist/services/VariantRunService.d.ts.map +1 -1
- package/dist/services/VariantRunService.js +74 -15
- package/dist/services/VariantRunService.js.map +1 -1
- package/dist/services/VariantsRuntime.d.ts.map +1 -1
- package/dist/services/VariantsRuntime.js +3 -0
- package/dist/services/VariantsRuntime.js.map +1 -1
- package/dist/services/generationGuidance.d.ts +5 -0
- package/dist/services/generationGuidance.d.ts.map +1 -0
- package/dist/services/generationGuidance.js +76 -0
- package/dist/services/generationGuidance.js.map +1 -0
- package/dist/services/profiles/DesignProfiles.d.ts +56 -0
- package/dist/services/profiles/DesignProfiles.d.ts.map +1 -1
- package/dist/services/profiles/DesignProfiles.js +63 -0
- package/dist/services/profiles/DesignProfiles.js.map +1 -1
- package/dist/storage/profiles/ProfileRecords.d.ts +9 -0
- package/dist/storage/profiles/ProfileRecords.d.ts.map +1 -1
- package/dist/storage/profiles/ProfileRecords.js +52 -0
- package/dist/storage/profiles/ProfileRecords.js.map +1 -1
- package/dist/storage/profiles/migrations.d.ts +2 -2
- package/dist/storage/profiles/migrations.d.ts.map +1 -1
- package/dist/storage/profiles/migrations.js +3 -0
- package/dist/storage/profiles/migrations.js.map +1 -1
- package/dist/storage/profiles/schema.d.ts +71 -0
- package/dist/storage/profiles/schema.d.ts.map +1 -1
- package/dist/storage/profiles/schema.js +7 -1
- package/dist/storage/profiles/schema.js.map +1 -1
- package/dist/types/change-request-types.d.ts +5 -0
- package/dist/types/change-request-types.d.ts.map +1 -1
- package/dist/types/guidance.d.ts +113 -0
- package/dist/types/guidance.d.ts.map +1 -0
- package/dist/types/guidance.js +68 -0
- package/dist/types/guidance.js.map +1 -0
- package/dist/utils/skills/cli-guidance.d.ts +1 -1
- package/dist/utils/skills/cli-guidance.d.ts.map +1 -1
- package/dist/utils/skills/cli-guidance.js +11 -1
- package/dist/utils/skills/cli-guidance.js.map +1 -1
- package/dist/utils/skills/codex-skill.d.ts +1 -1
- package/dist/utils/skills/codex-skill.d.ts.map +1 -1
- package/dist/utils/skills/codex-skill.js +2 -0
- package/dist/utils/skills/codex-skill.js.map +1 -1
- package/package.json +1 -1
- package/src/ui/dist/assets/{LibraryEntry-Db0yQPRU.js → LibraryEntry-BmQyIG74.js} +3 -3
- package/src/ui/dist/assets/main-C-Pki9j3.js +435 -0
- package/src/ui/dist/index.html +1 -1
- package/src/ui/dist/assets/main-BAQFukSb.js +0 -435
|
@@ -4,6 +4,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.createAgentVariantsRouter = exports.stampWatcherLiveness = exports.nestedFreshSessionWorkdirs = void 0;
|
|
7
|
+
const variantRequestSchema_1 = require("./variantRequestSchema");
|
|
8
|
+
const generationGuidance_1 = require("../services/generationGuidance");
|
|
7
9
|
const RuntimeAdmission_1 = require("../services/RuntimeAdmission");
|
|
8
10
|
const telemetry_1 = require("../config/telemetry");
|
|
9
11
|
const runtimeAdmission_1 = require("./runtimeAdmission");
|
|
@@ -20,9 +22,10 @@ const express_1 = require("express");
|
|
|
20
22
|
const v3_1 = require("zod/v3");
|
|
21
23
|
const logger_1 = require("../utils/logger");
|
|
22
24
|
const agent_variants_1 = require("../agent-variants");
|
|
23
|
-
const contracts_2 = require("../agent-variants/contracts");
|
|
24
25
|
const changeBatchClassification_1 = require("../mcp/changeBatchClassification");
|
|
25
26
|
const createAgentVariantsOrchestrator_1 = require("../services/createAgentVariantsOrchestrator");
|
|
27
|
+
const ConfigManager_1 = require("../services/ConfigManager");
|
|
28
|
+
const guidance_1 = require("../types/guidance");
|
|
26
29
|
const VariantHistoryService_1 = require("../services/VariantHistoryService");
|
|
27
30
|
const PrototypeDeployService_1 = require("../services/PrototypeDeployService");
|
|
28
31
|
const HistoryReplayService_1 = require("../services/HistoryReplayService");
|
|
@@ -36,8 +39,6 @@ const preview_bridge_1 = require("../proxy-middleware/preview-bridge");
|
|
|
36
39
|
const displayLocale_1 = require("../utils/displayLocale");
|
|
37
40
|
const htmlDocument_1 = require("../utils/htmlDocument");
|
|
38
41
|
const log = (0, logger_1.createLogger)('AgentVariantsRouter');
|
|
39
|
-
const DIRECTION_TITLE_MAX_WORDS = 5;
|
|
40
|
-
const DIRECTION_SUBTITLE_MAX_WORDS = 10;
|
|
41
42
|
const PREVIEW_CDN_HOSTS = [
|
|
42
43
|
'https://unpkg.com',
|
|
43
44
|
'https://cdn.jsdelivr.net',
|
|
@@ -121,77 +122,6 @@ const inlineStaticPreviewTargetSchema = v3_1.z.object({
|
|
|
121
122
|
sessionId: v3_1.z.string().min(1),
|
|
122
123
|
variantId: v3_1.z.string().min(1),
|
|
123
124
|
});
|
|
124
|
-
const inlineVariantBriefSchema = contracts_2.startVariantsBriefContent.superRefine((brief, context) => {
|
|
125
|
-
const titleWordCount = brief.label.trim().split(/\s+/).length;
|
|
126
|
-
const subtitleWordCount = brief.body.trim().split(/\s+/).length;
|
|
127
|
-
if (titleWordCount > DIRECTION_TITLE_MAX_WORDS) {
|
|
128
|
-
context.addIssue({
|
|
129
|
-
code: v3_1.z.ZodIssueCode.custom,
|
|
130
|
-
path: ['label'],
|
|
131
|
-
message: 'direction titles must contain at most 5 words',
|
|
132
|
-
});
|
|
133
|
-
}
|
|
134
|
-
if (subtitleWordCount > DIRECTION_SUBTITLE_MAX_WORDS) {
|
|
135
|
-
context.addIssue({
|
|
136
|
-
code: v3_1.z.ZodIssueCode.custom,
|
|
137
|
-
path: ['body'],
|
|
138
|
-
message: 'direction subtitles must contain at most 10 words',
|
|
139
|
-
});
|
|
140
|
-
}
|
|
141
|
-
});
|
|
142
|
-
const inlineVariantRequestSchema = v3_1.z
|
|
143
|
-
.object({
|
|
144
|
-
count: v3_1.z.number().int().min(contracts_2.VARIANT_COUNT_MIN).max(contracts_2.VARIANT_COUNT_MAX),
|
|
145
|
-
mode: v3_1.z.enum(['existing', 'zero_to_one']).optional(),
|
|
146
|
-
profile: v3_1.z.enum(['auto', 'off']).optional(),
|
|
147
|
-
runLabel: contracts_2.runLabelSchema,
|
|
148
|
-
fidelity: v3_1.z.enum(['low', 'medium', 'high']).optional(),
|
|
149
|
-
briefs: v3_1.z
|
|
150
|
-
.array(inlineVariantBriefSchema)
|
|
151
|
-
.min(contracts_2.VARIANT_COUNT_MIN)
|
|
152
|
-
.max(contracts_2.VARIANT_COUNT_MAX)
|
|
153
|
-
.optional(),
|
|
154
|
-
contextAssets: v3_1.z
|
|
155
|
-
.array(contracts_2.contextAssetInputSchema)
|
|
156
|
-
.min(1)
|
|
157
|
-
.max(contracts_2.CONTEXT_ASSET_MAX_ITEMS)
|
|
158
|
-
.optional(),
|
|
159
|
-
referencePages: v3_1.z
|
|
160
|
-
.array(v3_1.z.object({
|
|
161
|
-
url: v3_1.z.string().url().max(2048),
|
|
162
|
-
note: v3_1.z.string().min(1).max(500).optional(),
|
|
163
|
-
}))
|
|
164
|
-
.min(1)
|
|
165
|
-
.max(3)
|
|
166
|
-
.optional(),
|
|
167
|
-
referenceVideos: v3_1.z
|
|
168
|
-
.array(v3_1.z.object({
|
|
169
|
-
path: v3_1.z.string().min(1).max(2048),
|
|
170
|
-
note: v3_1.z.string().min(1).max(500).optional(),
|
|
171
|
-
}))
|
|
172
|
-
.min(1)
|
|
173
|
-
.max(2)
|
|
174
|
-
.optional(),
|
|
175
|
-
})
|
|
176
|
-
.superRefine((request, context) => {
|
|
177
|
-
if (request.briefs && request.briefs.length !== request.count) {
|
|
178
|
-
context.addIssue({
|
|
179
|
-
code: v3_1.z.ZodIssueCode.custom,
|
|
180
|
-
path: ['briefs'],
|
|
181
|
-
message: 'briefs length must match count',
|
|
182
|
-
});
|
|
183
|
-
}
|
|
184
|
-
if (request.briefs) {
|
|
185
|
-
const labels = request.briefs.map((brief) => brief.label.trim().toLowerCase().replace(/\s+/g, ' '));
|
|
186
|
-
if (new Set(labels).size !== labels.length) {
|
|
187
|
-
context.addIssue({
|
|
188
|
-
code: v3_1.z.ZodIssueCode.custom,
|
|
189
|
-
path: ['briefs'],
|
|
190
|
-
message: 'brief labels must be distinct',
|
|
191
|
-
});
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
});
|
|
195
125
|
const inlineInitiatorSchema = v3_1.z
|
|
196
126
|
.discriminatedUnion('kind', [
|
|
197
127
|
v3_1.z.object({ kind: v3_1.z.literal('human') }),
|
|
@@ -212,7 +142,7 @@ const inlineVariantBody = v3_1.z.object({
|
|
|
212
142
|
instruction: v3_1.z.string().min(1),
|
|
213
143
|
images: v3_1.z.array(v3_1.z.string()).optional(),
|
|
214
144
|
references: v3_1.z.array(commentReferenceItemSchema).max(8).optional(),
|
|
215
|
-
variantRequest: inlineVariantRequestSchema,
|
|
145
|
+
variantRequest: variantRequestSchema_1.inlineVariantRequestSchema,
|
|
216
146
|
})
|
|
217
147
|
.passthrough())
|
|
218
148
|
.min(1),
|
|
@@ -805,6 +735,8 @@ const createAgentVariantsRouter = (orchestrator, bridge, telemetry, variantHisto
|
|
|
805
735
|
acceptedLanguages: req.acceptsLanguages(),
|
|
806
736
|
});
|
|
807
737
|
let request = {
|
|
738
|
+
guidanceAccountId: req.header('X-Rivet-Account-Id'),
|
|
739
|
+
guidanceSelection: parsed.data.changes[0]?.variantRequest.guidanceSelection,
|
|
808
740
|
changes: parsed.data.changes,
|
|
809
741
|
sourceFiles: parsed.data.sourceFiles ?? [],
|
|
810
742
|
displayLocale,
|
|
@@ -816,39 +748,41 @@ const createAgentVariantsRouter = (orchestrator, bridge, telemetry, variantHisto
|
|
|
816
748
|
initiator: parsed.data.initiator,
|
|
817
749
|
workerSelection: parsed.data.workerSelection,
|
|
818
750
|
};
|
|
819
|
-
bridge?.updateTelemetryContext(request.telemetryContext);
|
|
820
|
-
if ((0, changeBatchClassification_1.isMixedVariantBatch)(request) || !(0, changeBatchClassification_1.isSingleVariantRequestBatch)(request)) {
|
|
821
|
-
res.status(400).json({
|
|
822
|
-
error: 'Invalid inline variants batch',
|
|
823
|
-
details: 'Inline variants require exactly one comment with a variantRequest.',
|
|
824
|
-
reason: 'mixed_batch',
|
|
825
|
-
});
|
|
826
|
-
return;
|
|
827
|
-
}
|
|
828
|
-
const activeVariantsSession = orchestrator.buildActiveSnapshot();
|
|
829
|
-
let effectiveTarget = batchTarget ?? staticPreviewTarget;
|
|
830
|
-
const isPersistedTargetRequest = Boolean(effectiveTarget &&
|
|
831
|
-
(activeVariantsSession.active !== true ||
|
|
832
|
-
effectiveTarget.sessionId !== activeVariantsSession.sessionId));
|
|
833
|
-
if ((isPersistedTargetRequest || !effectiveTarget) &&
|
|
834
|
-
rejectBlockedVariantSession(res, activeVariantsSession)) {
|
|
835
|
-
return;
|
|
836
|
-
}
|
|
837
|
-
if ((isPersistedTargetRequest || !effectiveTarget) &&
|
|
838
|
-
inlineStartTracker.isStarting()) {
|
|
839
|
-
res.status(400).json({
|
|
840
|
-
error: 'Variants start already in progress',
|
|
841
|
-
details: 'A variants start for this project is still being processed (provisioning can take a while) — status reports it as `variants.starting`. Poll status until the session registers or the start settles, then retry. Do not cancel anything.',
|
|
842
|
-
reason: 'start_in_flight',
|
|
843
|
-
});
|
|
844
|
-
return;
|
|
845
|
-
}
|
|
846
751
|
let trackedStart = false;
|
|
847
|
-
if (isPersistedTargetRequest || !effectiveTarget) {
|
|
848
|
-
inlineStartTracker.begin();
|
|
849
|
-
trackedStart = true;
|
|
850
|
-
}
|
|
851
752
|
try {
|
|
753
|
+
(0, generationGuidance_1.assertGenerationGuidance)(request);
|
|
754
|
+
bridge?.updateTelemetryContext(request.telemetryContext);
|
|
755
|
+
if ((0, changeBatchClassification_1.isMixedVariantBatch)(request) ||
|
|
756
|
+
!(0, changeBatchClassification_1.isSingleVariantRequestBatch)(request)) {
|
|
757
|
+
res.status(400).json({
|
|
758
|
+
error: 'Invalid inline variants batch',
|
|
759
|
+
details: 'Inline variants require exactly one comment with a variantRequest.',
|
|
760
|
+
reason: 'mixed_batch',
|
|
761
|
+
});
|
|
762
|
+
return;
|
|
763
|
+
}
|
|
764
|
+
const activeVariantsSession = orchestrator.buildActiveSnapshot();
|
|
765
|
+
let effectiveTarget = batchTarget ?? staticPreviewTarget;
|
|
766
|
+
const isPersistedTargetRequest = Boolean(effectiveTarget &&
|
|
767
|
+
(activeVariantsSession.active !== true ||
|
|
768
|
+
effectiveTarget.sessionId !== activeVariantsSession.sessionId));
|
|
769
|
+
if ((isPersistedTargetRequest || !effectiveTarget) &&
|
|
770
|
+
rejectBlockedVariantSession(res, activeVariantsSession)) {
|
|
771
|
+
return;
|
|
772
|
+
}
|
|
773
|
+
if ((isPersistedTargetRequest || !effectiveTarget) &&
|
|
774
|
+
inlineStartTracker.isStarting()) {
|
|
775
|
+
res.status(400).json({
|
|
776
|
+
error: 'Variants start already in progress',
|
|
777
|
+
details: 'A variants start for this project is still being processed (provisioning can take a while) — status reports it as `variants.starting`. Poll status until the session registers or the start settles, then retry. Do not cancel anything.',
|
|
778
|
+
reason: 'start_in_flight',
|
|
779
|
+
});
|
|
780
|
+
return;
|
|
781
|
+
}
|
|
782
|
+
if (isPersistedTargetRequest || !effectiveTarget) {
|
|
783
|
+
inlineStartTracker.begin();
|
|
784
|
+
trackedStart = true;
|
|
785
|
+
}
|
|
852
786
|
if (isPersistedTargetRequest && effectiveTarget) {
|
|
853
787
|
const staleTarget = effectiveTarget;
|
|
854
788
|
let adoption;
|
|
@@ -938,14 +872,20 @@ const createAgentVariantsRouter = (orchestrator, bridge, telemetry, variantHisto
|
|
|
938
872
|
});
|
|
939
873
|
return;
|
|
940
874
|
}
|
|
875
|
+
const { profileContext, guidance = [], guidanceWarning } = result;
|
|
941
876
|
res.status(200).json({
|
|
942
877
|
success: true,
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
878
|
+
guidance,
|
|
879
|
+
...(guidanceWarning ? { guidanceWarning } : {}),
|
|
880
|
+
...(profileContext ? { profileContext } : {}),
|
|
946
881
|
});
|
|
947
882
|
}
|
|
948
883
|
catch (err) {
|
|
884
|
+
if (err instanceof guidance_1.GuidanceError &&
|
|
885
|
+
err.code === 'guidance_account_changed') {
|
|
886
|
+
res.status(409).json({ error: err.message, code: err.code });
|
|
887
|
+
return;
|
|
888
|
+
}
|
|
949
889
|
log.error('Inline variants run failed:', err);
|
|
950
890
|
res.status(500).json({
|
|
951
891
|
error: err instanceof Error ? err.message : 'Inline variants run failed',
|
|
@@ -1002,6 +942,56 @@ const createAgentVariantsRouter = (orchestrator, bridge, telemetry, variantHisto
|
|
|
1002
942
|
});
|
|
1003
943
|
}
|
|
1004
944
|
});
|
|
945
|
+
router.get('/variants/guidance/:workId', async (req, res) => {
|
|
946
|
+
if (rejectNonLocalRequest(req, res))
|
|
947
|
+
return;
|
|
948
|
+
const projectPath = resolveProjectPath(req.query.projectPath);
|
|
949
|
+
const workId = req.params.workId;
|
|
950
|
+
if (!projectPath ||
|
|
951
|
+
typeof workId !== 'string' ||
|
|
952
|
+
!/^[A-Za-z0-9_-]+$/.test(workId)) {
|
|
953
|
+
res.status(400).json({
|
|
954
|
+
error: 'A project and valid work ID are required to inspect saved context.',
|
|
955
|
+
});
|
|
956
|
+
return;
|
|
957
|
+
}
|
|
958
|
+
const config = (0, ConfigManager_1.getConfigManager)();
|
|
959
|
+
const accountId = config.isAuthenticated() ? config.getUserId() : undefined;
|
|
960
|
+
const assertAccount = () => {
|
|
961
|
+
const currentAccountId = config.isAuthenticated()
|
|
962
|
+
? config.getUserId()
|
|
963
|
+
: undefined;
|
|
964
|
+
if (currentAccountId !== accountId ||
|
|
965
|
+
(req.query.accountId !== undefined &&
|
|
966
|
+
req.query.accountId !== currentAccountId))
|
|
967
|
+
throw new guidance_1.GuidanceError('guidance_account_changed', 'The saved context account changed; retry inspection.');
|
|
968
|
+
};
|
|
969
|
+
try {
|
|
970
|
+
assertAccount();
|
|
971
|
+
for (const candidate of resolveHistoryProjectPaths({ projectPath })) {
|
|
972
|
+
const result = await variantHistory.inspectGuidance({
|
|
973
|
+
projectPath: candidate,
|
|
974
|
+
workId,
|
|
975
|
+
accountId: accountId ?? undefined,
|
|
976
|
+
});
|
|
977
|
+
if (result.isRecorded) {
|
|
978
|
+
assertAccount();
|
|
979
|
+
res.json(result);
|
|
980
|
+
return;
|
|
981
|
+
}
|
|
982
|
+
}
|
|
983
|
+
assertAccount();
|
|
984
|
+
res.json({ isRecorded: false, guidance: [] });
|
|
985
|
+
}
|
|
986
|
+
catch (error) {
|
|
987
|
+
res.status(error instanceof guidance_1.GuidanceError ? 409 : 500).json({
|
|
988
|
+
...(error instanceof guidance_1.GuidanceError ? { code: error.code } : {}),
|
|
989
|
+
error: error instanceof Error
|
|
990
|
+
? error.message
|
|
991
|
+
: 'Could not inspect saved context.',
|
|
992
|
+
});
|
|
993
|
+
}
|
|
994
|
+
});
|
|
1005
995
|
router.get('/variants/active', (req, res) => {
|
|
1006
996
|
if (rejectNonLocalRequest(req, res))
|
|
1007
997
|
return;
|