@contractspec/lib.surface-runtime 0.3.0 → 0.3.3
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/adapters/ai-sdk-stub.js +1 -6
- package/dist/adapters/blocknote-stub.js +3 -8
- package/dist/adapters/dnd-kit-adapter.js +6 -11
- package/dist/adapters/dnd-kit-stub.js +1 -6
- package/dist/adapters/floating-ui-stub.js +4 -9
- package/dist/adapters/index.js +7 -176
- package/dist/adapters/interfaces.js +0 -1
- package/dist/adapters/motion-stub.js +2 -7
- package/dist/adapters/resizable-panels-stub.js +7 -12
- package/dist/browser/adapters/ai-sdk-stub.js +1 -5
- package/dist/browser/adapters/blocknote-stub.js +3 -7
- package/dist/browser/adapters/dnd-kit-adapter.js +6 -10
- package/dist/browser/adapters/dnd-kit-stub.js +1 -5
- package/dist/browser/adapters/floating-ui-stub.js +4 -8
- package/dist/browser/adapters/index.js +7 -175
- package/dist/browser/adapters/motion-stub.js +2 -6
- package/dist/browser/adapters/resizable-panels-stub.js +5 -9
- package/dist/browser/evals/golden-harness.js +4 -825
- package/dist/browser/examples/pm-workbench.bundle.js +2 -316
- package/dist/browser/i18n/catalogs/en.js +1 -5
- package/dist/browser/i18n/catalogs/es.js +1 -5
- package/dist/browser/i18n/catalogs/fr.js +1 -5
- package/dist/browser/i18n/catalogs/index.js +3 -133
- package/dist/browser/i18n/index.js +3 -168
- package/dist/browser/i18n/keys.js +1 -5
- package/dist/browser/i18n/messages.js +6 -137
- package/dist/browser/index.js +4 -2470
- package/dist/browser/react/BundleProvider.js +12 -19
- package/dist/browser/react/BundleRenderer.js +15 -662
- package/dist/browser/react/OverlayConflictResolver.js +12 -180
- package/dist/browser/react/PatchProposalCard.js +9 -177
- package/dist/browser/react/RegionRenderer.js +14 -60
- package/dist/browser/react/SlotRenderer.js +15 -58
- package/dist/browser/react/WidgetPalette.js +6 -10
- package/dist/browser/react/index.js +14 -794
- package/dist/browser/runtime/apply-surface-patch.js +3 -208
- package/dist/browser/runtime/audit-events.js +8 -19
- package/dist/browser/runtime/build-context.js +2 -6
- package/dist/browser/runtime/extension-registry.js +3 -9
- package/dist/browser/runtime/field-renderer-registry.js +5 -11
- package/dist/browser/runtime/index.js +54 -1487
- package/dist/browser/runtime/overlay-alignment.js +8 -19
- package/dist/browser/runtime/overlay-signer.js +2 -7
- package/dist/browser/runtime/override-store.js +3 -9
- package/dist/browser/runtime/planner-prompt.js +2 -6
- package/dist/browser/runtime/planner-tools.js +3 -9
- package/dist/browser/runtime/policy-eval.js +3 -135
- package/dist/browser/runtime/preference-adapter.js +2 -62
- package/dist/browser/runtime/resolve-bundle.js +10 -447
- package/dist/browser/runtime/resolve-preferences.js +3 -7
- package/dist/browser/runtime/rollback.js +2 -325
- package/dist/browser/runtime/widget-registry.js +1 -5
- package/dist/browser/spec/define-module-bundle.js +2 -67
- package/dist/browser/spec/index.js +9 -317
- package/dist/browser/spec/validate-bundle.js +3 -8
- package/dist/browser/spec/validate-surface-patch.js +5 -11
- package/dist/browser/telemetry/index.js +4 -16
- package/dist/browser/telemetry/surface-metrics.js +7 -16
- package/dist/evals/golden-context.js +0 -1
- package/dist/evals/golden-harness.js +4 -826
- package/dist/examples/pm-workbench.bundle.js +2 -317
- package/dist/i18n/catalogs/en.js +1 -6
- package/dist/i18n/catalogs/es.js +1 -6
- package/dist/i18n/catalogs/fr.js +1 -6
- package/dist/i18n/catalogs/index.js +3 -134
- package/dist/i18n/index.js +3 -169
- package/dist/i18n/keys.js +1 -6
- package/dist/i18n/messages.js +6 -138
- package/dist/index.js +4 -2471
- package/dist/node/adapters/ai-sdk-stub.js +1 -5
- package/dist/node/adapters/blocknote-stub.js +3 -7
- package/dist/node/adapters/dnd-kit-adapter.js +6 -10
- package/dist/node/adapters/dnd-kit-stub.js +1 -5
- package/dist/node/adapters/floating-ui-stub.js +4 -8
- package/dist/node/adapters/index.js +7 -175
- package/dist/node/adapters/motion-stub.js +2 -6
- package/dist/node/adapters/resizable-panels-stub.js +5 -9
- package/dist/node/evals/golden-harness.js +4 -825
- package/dist/node/examples/pm-workbench.bundle.js +2 -316
- package/dist/node/i18n/catalogs/en.js +1 -5
- package/dist/node/i18n/catalogs/es.js +1 -5
- package/dist/node/i18n/catalogs/fr.js +1 -5
- package/dist/node/i18n/catalogs/index.js +3 -133
- package/dist/node/i18n/index.js +3 -168
- package/dist/node/i18n/keys.js +1 -5
- package/dist/node/i18n/messages.js +6 -137
- package/dist/node/index.js +4 -2470
- package/dist/node/react/BundleProvider.js +12 -19
- package/dist/node/react/BundleRenderer.js +15 -662
- package/dist/node/react/OverlayConflictResolver.js +12 -180
- package/dist/node/react/PatchProposalCard.js +9 -177
- package/dist/node/react/RegionRenderer.js +14 -60
- package/dist/node/react/SlotRenderer.js +15 -58
- package/dist/node/react/WidgetPalette.js +6 -10
- package/dist/node/react/index.js +14 -794
- package/dist/node/runtime/apply-surface-patch.js +3 -208
- package/dist/node/runtime/audit-events.js +8 -19
- package/dist/node/runtime/build-context.js +2 -6
- package/dist/node/runtime/extension-registry.js +3 -9
- package/dist/node/runtime/field-renderer-registry.js +5 -11
- package/dist/node/runtime/index.js +54 -1487
- package/dist/node/runtime/overlay-alignment.js +8 -19
- package/dist/node/runtime/overlay-signer.js +2 -7
- package/dist/node/runtime/override-store.js +3 -9
- package/dist/node/runtime/planner-prompt.js +2 -6
- package/dist/node/runtime/planner-tools.js +3 -9
- package/dist/node/runtime/policy-eval.js +3 -135
- package/dist/node/runtime/preference-adapter.js +2 -62
- package/dist/node/runtime/resolve-bundle.js +10 -447
- package/dist/node/runtime/resolve-preferences.js +3 -7
- package/dist/node/runtime/rollback.js +2 -325
- package/dist/node/runtime/widget-registry.js +1 -5
- package/dist/node/spec/define-module-bundle.js +2 -67
- package/dist/node/spec/index.js +9 -317
- package/dist/node/spec/validate-bundle.js +3 -8
- package/dist/node/spec/validate-surface-patch.js +5 -11
- package/dist/node/telemetry/index.js +4 -16
- package/dist/node/telemetry/surface-metrics.js +7 -16
- package/dist/react/BundleProvider.js +12 -20
- package/dist/react/BundleRenderer.js +15 -663
- package/dist/react/OverlayConflictResolver.js +12 -181
- package/dist/react/PatchProposalCard.js +9 -178
- package/dist/react/RegionRenderer.js +14 -61
- package/dist/react/SlotRenderer.js +15 -59
- package/dist/react/WidgetPalette.js +6 -11
- package/dist/react/index.js +14 -795
- package/dist/runtime/apply-surface-patch.js +3 -209
- package/dist/runtime/audit-events.js +8 -20
- package/dist/runtime/build-context.js +2 -7
- package/dist/runtime/extension-registry.js +3 -10
- package/dist/runtime/field-renderer-registry.js +9 -16
- package/dist/runtime/index.js +54 -1488
- package/dist/runtime/overlay-alignment.js +8 -20
- package/dist/runtime/overlay-signer.js +2 -8
- package/dist/runtime/override-store.js +3 -10
- package/dist/runtime/planner-prompt.js +11 -9
- package/dist/runtime/planner-tools.js +4 -11
- package/dist/runtime/policy-eval.js +3 -136
- package/dist/runtime/preference-adapter.js +2 -63
- package/dist/runtime/resolve-bundle.js +10 -448
- package/dist/runtime/resolve-preferences.js +3 -8
- package/dist/runtime/rollback.js +2 -326
- package/dist/runtime/widget-registry.js +1 -6
- package/dist/spec/define-module-bundle.js +2 -68
- package/dist/spec/index.js +9 -318
- package/dist/spec/types.js +0 -1
- package/dist/spec/validate-bundle.js +3 -9
- package/dist/spec/validate-surface-patch.js +5 -12
- package/dist/spec/verification-snapshot-types.js +0 -1
- package/dist/telemetry/index.js +4 -17
- package/dist/telemetry/surface-metrics.js +7 -17
- package/package.json +7 -7
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
// src/runtime/overlay-alignment.ts
|
|
2
1
|
import { applyOverlayModifications } from "@contractspec/lib.overlay-engine/merger";
|
|
3
|
-
function toOverlayScopeContext(ctx) {
|
|
2
|
+
export function toOverlayScopeContext(ctx) {
|
|
4
3
|
return {
|
|
5
4
|
tenantId: ctx.tenantId,
|
|
6
5
|
userId: ctx.actorId,
|
|
@@ -8,7 +7,7 @@ function toOverlayScopeContext(ctx) {
|
|
|
8
7
|
tags: ctx.featureFlags
|
|
9
8
|
};
|
|
10
9
|
}
|
|
11
|
-
function toOverlayTargetRef(_ctx, target) {
|
|
10
|
+
export function toOverlayTargetRef(_ctx, target) {
|
|
12
11
|
return {
|
|
13
12
|
presentation: target.surfaceId ?? target.routeId,
|
|
14
13
|
bundleKey: target.bundleKey,
|
|
@@ -17,7 +16,7 @@ function toOverlayTargetRef(_ctx, target) {
|
|
|
17
16
|
entityType: target.entityType
|
|
18
17
|
};
|
|
19
18
|
}
|
|
20
|
-
function toOverlayAppliesTo(ctx, target, scope) {
|
|
19
|
+
export function toOverlayAppliesTo(ctx, target, scope) {
|
|
21
20
|
const scopeCtx = toOverlayScopeContext(ctx);
|
|
22
21
|
return {
|
|
23
22
|
...scopeCtx,
|
|
@@ -26,7 +25,7 @@ function toOverlayAppliesTo(ctx, target, scope) {
|
|
|
26
25
|
...scope === "workspace" && ctx.workspaceId ? { tags: [...scopeCtx.tags ?? [], `workspace:${ctx.workspaceId}`] } : {}
|
|
27
26
|
};
|
|
28
27
|
}
|
|
29
|
-
function toOverlayRenderableField(field) {
|
|
28
|
+
export function toOverlayRenderableField(field) {
|
|
30
29
|
return {
|
|
31
30
|
key: field.fieldId,
|
|
32
31
|
label: field.title,
|
|
@@ -35,7 +34,7 @@ function toOverlayRenderableField(field) {
|
|
|
35
34
|
order: 0
|
|
36
35
|
};
|
|
37
36
|
}
|
|
38
|
-
function fromOverlayRenderableField(overlay) {
|
|
37
|
+
export function fromOverlayRenderableField(overlay) {
|
|
39
38
|
return {
|
|
40
39
|
fieldId: overlay.key,
|
|
41
40
|
title: overlay.label ?? overlay.key,
|
|
@@ -43,12 +42,12 @@ function fromOverlayRenderableField(overlay) {
|
|
|
43
42
|
required: overlay.required ?? false
|
|
44
43
|
};
|
|
45
44
|
}
|
|
46
|
-
function toOverlayRenderable(fields) {
|
|
45
|
+
export function toOverlayRenderable(fields) {
|
|
47
46
|
return {
|
|
48
47
|
fields: fields.map(toOverlayRenderableField)
|
|
49
48
|
};
|
|
50
49
|
}
|
|
51
|
-
function mergeOverlayResultIntoFields(fields, merged) {
|
|
50
|
+
export function mergeOverlayResultIntoFields(fields, merged) {
|
|
52
51
|
const fieldMap = new Map(fields.map((f) => [f.fieldId, { ...f }]));
|
|
53
52
|
const result = [];
|
|
54
53
|
for (const overlay of merged.fields) {
|
|
@@ -64,20 +63,10 @@ function mergeOverlayResultIntoFields(fields, merged) {
|
|
|
64
63
|
}
|
|
65
64
|
return result;
|
|
66
65
|
}
|
|
67
|
-
function applyEntityFieldOverlays(fields, overlays, options) {
|
|
66
|
+
export function applyEntityFieldOverlays(fields, overlays, options) {
|
|
68
67
|
if (!overlays.length)
|
|
69
68
|
return fields;
|
|
70
69
|
const target = toOverlayRenderable(fields);
|
|
71
70
|
const merged = applyOverlayModifications(target, overlays, options);
|
|
72
71
|
return mergeOverlayResultIntoFields(fields, merged);
|
|
73
72
|
}
|
|
74
|
-
export {
|
|
75
|
-
toOverlayTargetRef,
|
|
76
|
-
toOverlayScopeContext,
|
|
77
|
-
toOverlayRenderableField,
|
|
78
|
-
toOverlayRenderable,
|
|
79
|
-
toOverlayAppliesTo,
|
|
80
|
-
mergeOverlayResultIntoFields,
|
|
81
|
-
fromOverlayRenderableField,
|
|
82
|
-
applyEntityFieldOverlays
|
|
83
|
-
};
|
|
@@ -1,15 +1,10 @@
|
|
|
1
|
-
// src/runtime/overlay-signer.ts
|
|
2
1
|
import {
|
|
3
2
|
signOverlay,
|
|
4
3
|
verifyOverlaySignature
|
|
5
4
|
} from "@contractspec/lib.overlay-engine/signer";
|
|
6
|
-
function signWorkspaceOverlay(spec, privateKey, options) {
|
|
5
|
+
export function signWorkspaceOverlay(spec, privateKey, options) {
|
|
7
6
|
return signOverlay(spec, privateKey, options);
|
|
8
7
|
}
|
|
9
|
-
function verifyWorkspaceOverlay(overlay) {
|
|
8
|
+
export function verifyWorkspaceOverlay(overlay) {
|
|
10
9
|
return verifyOverlaySignature(overlay);
|
|
11
10
|
}
|
|
12
|
-
export {
|
|
13
|
-
verifyWorkspaceOverlay,
|
|
14
|
-
signWorkspaceOverlay
|
|
15
|
-
};
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
function buildOverrideTargetKey(bundleKey, surfaceId, routeId) {
|
|
1
|
+
export function buildOverrideTargetKey(bundleKey, surfaceId, routeId) {
|
|
3
2
|
return routeId ? `${bundleKey}:${routeId}:${surfaceId}` : `${bundleKey}:${surfaceId}`;
|
|
4
3
|
}
|
|
5
|
-
function createOverrideStoreWithApprovalGate(store, options) {
|
|
4
|
+
export function createOverrideStoreWithApprovalGate(store, options) {
|
|
6
5
|
const { requireApprovalForWorkspacePatches = false, requestApproval } = options;
|
|
7
6
|
return {
|
|
8
7
|
list: store.list.bind(store),
|
|
@@ -18,7 +17,7 @@ function createOverrideStoreWithApprovalGate(store, options) {
|
|
|
18
17
|
remove: store.remove.bind(store)
|
|
19
18
|
};
|
|
20
19
|
}
|
|
21
|
-
function createInMemoryOverrideStore() {
|
|
20
|
+
export function createInMemoryOverrideStore() {
|
|
22
21
|
const overrides = new Map;
|
|
23
22
|
function nextId() {
|
|
24
23
|
return `ov_${Date.now().toString(36)}_${Math.random().toString(36).slice(2, 10)}`;
|
|
@@ -45,8 +44,3 @@ function createInMemoryOverrideStore() {
|
|
|
45
44
|
}
|
|
46
45
|
};
|
|
47
46
|
}
|
|
48
|
-
export {
|
|
49
|
-
createOverrideStoreWithApprovalGate,
|
|
50
|
-
createInMemoryOverrideStore,
|
|
51
|
-
buildOverrideTargetKey
|
|
52
|
-
};
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
var SAFETY_INSTRUCTIONS = `
|
|
1
|
+
const SAFETY_INSTRUCTIONS = `
|
|
3
2
|
## Safety instructions (mandatory)
|
|
4
3
|
- Do NOT emit JSX, HTML, or raw markup.
|
|
5
4
|
- Do NOT invent node kinds; use only the allowed kinds listed above.
|
|
@@ -7,7 +6,7 @@ var SAFETY_INSTRUCTIONS = `
|
|
|
7
6
|
- Prefer fewer high-confidence patches over many speculative ones.
|
|
8
7
|
- Explain why a patch helps the user.
|
|
9
8
|
`;
|
|
10
|
-
function compilePlannerPrompt(input) {
|
|
9
|
+
export function compilePlannerPrompt(input) {
|
|
11
10
|
const {
|
|
12
11
|
bundleMeta,
|
|
13
12
|
surfaceId,
|
|
@@ -62,6 +61,3 @@ function compilePlannerPrompt(input) {
|
|
|
62
61
|
return parts.join(`
|
|
63
62
|
`);
|
|
64
63
|
}
|
|
65
|
-
export {
|
|
66
|
-
compilePlannerPrompt
|
|
67
|
-
};
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
var PROPOSE_PATCH_TOOL_SCHEMA = {
|
|
1
|
+
export const PROPOSE_PATCH_TOOL_SCHEMA = {
|
|
3
2
|
type: "object",
|
|
4
3
|
properties: {
|
|
5
4
|
proposalId: { type: "string", description: "Unique proposal identifier" },
|
|
@@ -55,14 +54,14 @@ var PROPOSE_PATCH_TOOL_SCHEMA = {
|
|
|
55
54
|
},
|
|
56
55
|
required: ["proposalId", "ops"]
|
|
57
56
|
};
|
|
58
|
-
|
|
57
|
+
export const proposePatchToolConfig = {
|
|
59
58
|
name: "propose-patch",
|
|
60
59
|
description: "Propose surface patches (layout changes, node insertions, etc.) for user approval. " + "Only use allowed ops, slots, and node kinds from the planner context.",
|
|
61
60
|
schema: PROPOSE_PATCH_TOOL_SCHEMA,
|
|
62
61
|
automationSafe: false,
|
|
63
62
|
requiresApproval: true
|
|
64
63
|
};
|
|
65
|
-
function buildSurfacePatchProposal(proposalId, ops) {
|
|
64
|
+
export function buildSurfacePatchProposal(proposalId, ops) {
|
|
66
65
|
return {
|
|
67
66
|
proposalId,
|
|
68
67
|
source: "assistant",
|
|
@@ -70,8 +69,3 @@ function buildSurfacePatchProposal(proposalId, ops) {
|
|
|
70
69
|
approvalState: "proposed"
|
|
71
70
|
};
|
|
72
71
|
}
|
|
73
|
-
export {
|
|
74
|
-
proposePatchToolConfig,
|
|
75
|
-
buildSurfacePatchProposal,
|
|
76
|
-
PROPOSE_PATCH_TOOL_SCHEMA
|
|
77
|
-
};
|
|
@@ -1,139 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
function
|
|
3
|
-
return `evt_${Date.now().toString(36)}_${Math.random().toString(36).slice(2, 10)}`;
|
|
4
|
-
}
|
|
5
|
-
function emitPatchProposed(audit, args) {
|
|
6
|
-
audit.emit({
|
|
7
|
-
eventId: generateEventId(),
|
|
8
|
-
at: new Date().toISOString(),
|
|
9
|
-
actorId: args.actorId,
|
|
10
|
-
source: args.proposal.source === "assistant" ? "assistant" : "user",
|
|
11
|
-
bundleKey: args.bundleKey,
|
|
12
|
-
surfaceId: args.surfaceId,
|
|
13
|
-
eventType: "patch.proposed",
|
|
14
|
-
payload: {
|
|
15
|
-
proposalId: args.proposal.proposalId,
|
|
16
|
-
source: args.proposal.source,
|
|
17
|
-
opsCount: args.proposal.ops.length
|
|
18
|
-
}
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
function emitPatchApproved(audit, args) {
|
|
22
|
-
audit.emit({
|
|
23
|
-
eventId: generateEventId(),
|
|
24
|
-
at: new Date().toISOString(),
|
|
25
|
-
actorId: args.actorId,
|
|
26
|
-
source: "user",
|
|
27
|
-
bundleKey: args.bundleKey,
|
|
28
|
-
surfaceId: args.surfaceId,
|
|
29
|
-
eventType: "patch.approved",
|
|
30
|
-
payload: {
|
|
31
|
-
proposalId: args.proposalId,
|
|
32
|
-
source: args.source,
|
|
33
|
-
opsCount: args.opsCount,
|
|
34
|
-
reason: args.reason
|
|
35
|
-
}
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
function emitPatchRejected(audit, args) {
|
|
39
|
-
audit.emit({
|
|
40
|
-
eventId: generateEventId(),
|
|
41
|
-
at: new Date().toISOString(),
|
|
42
|
-
actorId: args.actorId,
|
|
43
|
-
source: "user",
|
|
44
|
-
bundleKey: args.bundleKey,
|
|
45
|
-
surfaceId: args.surfaceId,
|
|
46
|
-
eventType: "patch.rejected",
|
|
47
|
-
payload: {
|
|
48
|
-
proposalId: args.proposalId,
|
|
49
|
-
source: args.source,
|
|
50
|
-
opsCount: args.opsCount,
|
|
51
|
-
reason: args.reason
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
function emitOverlaySaved(audit, args) {
|
|
56
|
-
audit.emit({
|
|
57
|
-
eventId: generateEventId(),
|
|
58
|
-
at: new Date().toISOString(),
|
|
59
|
-
actorId: args.actorId,
|
|
60
|
-
source: "user",
|
|
61
|
-
bundleKey: args.bundleKey,
|
|
62
|
-
eventType: "overlay.saved",
|
|
63
|
-
payload: {
|
|
64
|
-
overlayId: args.overlayId,
|
|
65
|
-
scope: args.scope,
|
|
66
|
-
opsCount: args.opsCount
|
|
67
|
-
}
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
function emitOverlayApplied(audit, args) {
|
|
71
|
-
audit.emit({
|
|
72
|
-
eventId: generateEventId(),
|
|
73
|
-
at: new Date().toISOString(),
|
|
74
|
-
source: "system",
|
|
75
|
-
bundleKey: args.bundleKey,
|
|
76
|
-
surfaceId: args.surfaceId,
|
|
77
|
-
eventType: "overlay.applied",
|
|
78
|
-
payload: {
|
|
79
|
-
overlayId: args.overlayId,
|
|
80
|
-
opsCount: args.opsCount
|
|
81
|
-
}
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
function emitOverlayFailed(audit, args) {
|
|
85
|
-
audit.emit({
|
|
86
|
-
eventId: generateEventId(),
|
|
87
|
-
at: new Date().toISOString(),
|
|
88
|
-
source: "system",
|
|
89
|
-
bundleKey: args.bundleKey,
|
|
90
|
-
surfaceId: args.surfaceId,
|
|
91
|
-
eventType: "overlay.failed",
|
|
92
|
-
payload: {
|
|
93
|
-
overlayId: args.overlayId,
|
|
94
|
-
error: args.error
|
|
95
|
-
}
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
function emitPolicyDenied(audit, args) {
|
|
99
|
-
audit.emit({
|
|
100
|
-
eventId: generateEventId(),
|
|
101
|
-
at: new Date().toISOString(),
|
|
102
|
-
actorId: args.actorId,
|
|
103
|
-
source: "policy",
|
|
104
|
-
bundleKey: args.bundleKey,
|
|
105
|
-
surfaceId: args.surfaceId,
|
|
106
|
-
eventType: "policy.denied",
|
|
107
|
-
payload: {
|
|
108
|
-
targetId: args.targetId,
|
|
109
|
-
reason: args.reason
|
|
110
|
-
}
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
function emitPolicyRedacted(audit, args) {
|
|
114
|
-
audit.emit({
|
|
115
|
-
eventId: generateEventId(),
|
|
116
|
-
at: new Date().toISOString(),
|
|
117
|
-
actorId: args.actorId,
|
|
118
|
-
source: "policy",
|
|
119
|
-
bundleKey: args.bundleKey,
|
|
120
|
-
surfaceId: args.surfaceId,
|
|
121
|
-
eventType: "policy.redacted",
|
|
122
|
-
payload: {
|
|
123
|
-
targetId: args.targetId,
|
|
124
|
-
redactions: args.redactions
|
|
125
|
-
}
|
|
126
|
-
});
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
// src/runtime/policy-eval.ts
|
|
130
|
-
function evaluatePatchProposalPolicy(ops, ctx, policy) {
|
|
1
|
+
import { emitPolicyDenied } from "./audit-events";
|
|
2
|
+
export function evaluatePatchProposalPolicy(ops, ctx, policy) {
|
|
131
3
|
const evaluate = policy?.evaluatePatchProposal;
|
|
132
4
|
if (!evaluate)
|
|
133
5
|
return "allow";
|
|
134
6
|
return evaluate(ops, ctx);
|
|
135
7
|
}
|
|
136
|
-
function evaluateAndEmitPatchPolicy(ops, ctx, args) {
|
|
8
|
+
export function evaluateAndEmitPatchPolicy(ops, ctx, args) {
|
|
137
9
|
const effect = evaluatePatchProposalPolicy(ops, ctx, args.policy);
|
|
138
10
|
if (effect === "deny") {
|
|
139
11
|
if (args.audit) {
|
|
@@ -149,7 +21,3 @@ function evaluateAndEmitPatchPolicy(ops, ctx, args) {
|
|
|
149
21
|
}
|
|
150
22
|
return true;
|
|
151
23
|
}
|
|
152
|
-
export {
|
|
153
|
-
evaluatePatchProposalPolicy,
|
|
154
|
-
evaluateAndEmitPatchPolicy
|
|
155
|
-
};
|
|
@@ -1,67 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
"guidance",
|
|
4
|
-
"density",
|
|
5
|
-
"dataDepth",
|
|
6
|
-
"control",
|
|
7
|
-
"media",
|
|
8
|
-
"pace",
|
|
9
|
-
"narrative"
|
|
10
|
-
];
|
|
11
|
-
var SCOPE_ORDER = [
|
|
12
|
-
"user",
|
|
13
|
-
"workspace-user",
|
|
14
|
-
"bundle",
|
|
15
|
-
"surface",
|
|
16
|
-
"entity",
|
|
17
|
-
"session"
|
|
18
|
-
];
|
|
19
|
-
function mergeByScope(layers, ctx) {
|
|
20
|
-
const merged = { ...ctx.preferences };
|
|
21
|
-
const sourceByDimension = {};
|
|
22
|
-
for (const scope of SCOPE_ORDER) {
|
|
23
|
-
const layer = layers[scope];
|
|
24
|
-
if (!layer)
|
|
25
|
-
continue;
|
|
26
|
-
for (const dim of DIMENSION_KEYS) {
|
|
27
|
-
const val = layer[dim];
|
|
28
|
-
if (val !== undefined) {
|
|
29
|
-
merged[dim] = val;
|
|
30
|
-
sourceByDimension[dim] = scope;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
for (const dim of DIMENSION_KEYS) {
|
|
35
|
-
if (sourceByDimension[dim] === undefined) {
|
|
36
|
-
sourceByDimension[dim] = "session";
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
return { canonical: merged, sourceByDimension };
|
|
40
|
-
}
|
|
41
|
-
function resolveConstraints(_canonical, _ctx) {
|
|
42
|
-
return { constrained: {}, notes: [] };
|
|
43
|
-
}
|
|
44
|
-
function resolvePreferenceProfile(ctx) {
|
|
45
|
-
const layers = {
|
|
46
|
-
session: ctx.preferences
|
|
47
|
-
};
|
|
48
|
-
const { canonical, sourceByDimension } = mergeByScope(layers, ctx);
|
|
49
|
-
const { constrained, notes } = resolveConstraints(canonical, ctx);
|
|
50
|
-
return {
|
|
51
|
-
canonical,
|
|
52
|
-
sourceByDimension,
|
|
53
|
-
constrained,
|
|
54
|
-
notes
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
// src/runtime/preference-adapter.ts
|
|
59
|
-
var defaultPreferenceAdapter = {
|
|
1
|
+
import { resolvePreferenceProfile } from "./resolve-preferences";
|
|
2
|
+
export const defaultPreferenceAdapter = {
|
|
60
3
|
async resolve(ctx) {
|
|
61
4
|
return resolvePreferenceProfile(ctx);
|
|
62
5
|
},
|
|
63
6
|
async savePreferencePatch(_args) {}
|
|
64
7
|
};
|
|
65
|
-
export {
|
|
66
|
-
defaultPreferenceAdapter
|
|
67
|
-
};
|