@opengeni/worker-bundle 0.20.3 → 0.22.1-canary.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/activities/agent-turn/admission.d.ts +52 -0
- package/dist/activities/agent-turn/agent-build.d.ts +89 -0
- package/dist/activities/agent-turn/claim.d.ts +67 -0
- package/dist/activities/agent-turn/codex-capacity.d.ts +40 -0
- package/dist/activities/agent-turn/codex.d.ts +32 -0
- package/dist/activities/agent-turn/compaction-prep.d.ts +88 -0
- package/dist/activities/agent-turn/credential-leases.d.ts +56 -0
- package/dist/activities/agent-turn/errors.d.ts +253 -0
- package/dist/activities/agent-turn/failure-settlement.d.ts +33 -0
- package/dist/activities/agent-turn/file-resources.d.ts +37 -0
- package/dist/activities/agent-turn/finalization.d.ts +42 -0
- package/dist/activities/agent-turn/github-repository-bindings.d.ts +105 -0
- package/dist/activities/agent-turn/governance-model.d.ts +66 -0
- package/dist/activities/agent-turn/history-sink.d.ts +52 -0
- package/dist/activities/agent-turn/history.d.ts +63 -0
- package/dist/activities/agent-turn/media-artifacts.d.ts +145 -0
- package/dist/activities/agent-turn/model-usage.d.ts +218 -0
- package/dist/activities/agent-turn/quiescence.d.ts +135 -0
- package/dist/activities/agent-turn/run-credentials.d.ts +84 -0
- package/dist/activities/agent-turn/run.d.ts +3 -0
- package/dist/activities/agent-turn/sandbox-establish.d.ts +93 -0
- package/dist/activities/agent-turn/sandbox-provision.d.ts +89 -0
- package/dist/activities/agent-turn/sandbox-route.d.ts +151 -0
- package/dist/activities/agent-turn/sandbox-runtime.d.ts +44 -0
- package/dist/activities/agent-turn/stream-attempt.d.ts +107 -0
- package/dist/activities/agent-turn/tool-environment.d.ts +142 -0
- package/dist/activities/agent-turn/tool-policy.d.ts +127 -0
- package/dist/activities/agent-turn/tool-result-spill.d.ts +59 -0
- package/dist/activities/agent-turn/turn-context.d.ts +144 -0
- package/dist/activities/agent-turn/xai-capacity.d.ts +2 -0
- package/dist/activities/agent-turn.d.ts +12 -954
- package/dist/activities/automations.d.ts +16 -0
- package/dist/activities/common.d.ts +1 -1
- package/dist/activities/connector-attachments.d.ts +13 -0
- package/dist/activities/documents.d.ts +1 -0
- package/dist/activities/environment.d.ts +26 -15
- package/dist/activities/generated-images.d.ts +1 -1
- package/dist/activities/git-credential-renewal.d.ts +3 -1
- package/dist/activities/goals.d.ts +4 -1
- package/dist/activities/google-drive-provider.d.ts +29 -0
- package/dist/activities/google-drive-publication.d.ts +17 -4
- package/dist/activities/incident-telemetry-authority.d.ts +52 -0
- package/dist/activities/incident-telemetry-preflight.d.ts +71 -0
- package/dist/activities/knowledge-source-sync.d.ts +4 -0
- package/dist/activities/mcp-credentials.d.ts +9 -3
- package/dist/activities/open-suffix-resume.d.ts +77 -0
- package/dist/activities/packs.d.ts +3 -11
- package/dist/activities/parent-wake.d.ts +19 -0
- package/dist/activities/retained-screenshot-reaper.d.ts +1 -1
- package/dist/activities/retained-screenshots.d.ts +1 -1
- package/dist/activities/rig-verification.d.ts +1 -1
- package/dist/activities/run-input.d.ts +9 -10
- package/dist/activities/sandbox-images.d.ts +1 -14
- package/dist/activities/sandbox-lease.d.ts +21 -3
- package/dist/activities/scheduled-tasks.d.ts +47 -0
- package/dist/activities/types.d.ts +23 -2
- package/dist/activities/video-media-validation.d.ts +1 -1
- package/dist/activities/video-output-retention.d.ts +1 -2
- package/dist/activities/xai-auth.d.ts +3 -0
- package/dist/{activities-control-BJSDRSIP.js → activities-control-DKG22ONJ.js} +2646 -551
- package/dist/activities-control-DKG22ONJ.js.map +1 -0
- package/dist/activities-control.d.ts +6 -2
- package/dist/activities-turn-4IMC3MAA.js +21326 -0
- package/dist/activities-turn-4IMC3MAA.js.map +1 -0
- package/dist/activities.d.ts +7 -3
- package/dist/artifact-materializer-entry.js +41 -22
- package/dist/artifact-materializer-entry.js.map +1 -1
- package/dist/{chunk-N5TJIFCE.js → chunk-CE7TPKBS.js} +468 -1
- package/dist/chunk-CE7TPKBS.js.map +1 -0
- package/dist/chunk-CNYGVRKF.js +4698 -0
- package/dist/chunk-CNYGVRKF.js.map +1 -0
- package/dist/connection-provider-use.d.ts +18 -0
- package/dist/editable-artifact-materializer.d.ts +4 -3
- package/dist/github-rest-mcp.d.ts +26 -0
- package/dist/index.d.ts +10 -2
- package/dist/index.js +58 -14
- package/dist/index.js.map +1 -1
- package/dist/knowledge-source-sync-activity-policy.d.ts +2 -0
- package/dist/model-context-contributions.d.ts +8 -4
- package/dist/observability-metrics.d.ts +63 -4
- package/dist/opensandbox-kubernetes-inventory.d.ts +21 -0
- package/dist/personal-github-git-credentials.d.ts +9 -0
- package/dist/pr-review-credentials.d.ts +6 -0
- package/dist/sandbox-archive-storage.d.ts +45 -0
- package/dist/sandbox-resume.d.ts +65 -6
- package/dist/sandbox-routing.d.ts +38 -2
- package/dist/scheduled-alert-occurrence.d.ts +33 -0
- package/dist/workflow-bundle.js +87 -28
- package/dist/workflows/activities.d.ts +1 -0
- package/dist/workflows/automations.d.ts +6 -0
- package/dist/workflows/document-index.d.ts +1 -0
- package/dist/workflows.d.ts +1 -0
- package/package.json +17 -17
- package/src/activities/agent-turn/admission.ts +292 -0
- package/src/activities/agent-turn/agent-build.ts +802 -0
- package/src/activities/agent-turn/claim.ts +590 -0
- package/src/activities/agent-turn/codex-capacity.ts +720 -0
- package/src/activities/agent-turn/codex.ts +94 -0
- package/src/activities/agent-turn/compaction-prep.ts +722 -0
- package/src/activities/agent-turn/credential-leases.ts +240 -0
- package/src/activities/agent-turn/errors.ts +1068 -0
- package/src/activities/agent-turn/failure-settlement.ts +1436 -0
- package/src/activities/agent-turn/file-resources.ts +227 -0
- package/src/activities/agent-turn/finalization.ts +754 -0
- package/src/activities/agent-turn/github-repository-bindings.ts +300 -0
- package/src/activities/agent-turn/governance-model.ts +465 -0
- package/src/activities/agent-turn/history-sink.ts +139 -0
- package/src/activities/agent-turn/history.ts +200 -0
- package/src/activities/agent-turn/media-artifacts.ts +359 -0
- package/src/activities/agent-turn/model-usage.ts +823 -0
- package/src/activities/agent-turn/quiescence.ts +353 -0
- package/src/activities/agent-turn/run-credentials.ts +761 -0
- package/src/activities/agent-turn/run.ts +1530 -0
- package/src/activities/agent-turn/sandbox-establish.ts +1207 -0
- package/src/activities/agent-turn/sandbox-provision.ts +569 -0
- package/src/activities/agent-turn/sandbox-route.ts +358 -0
- package/src/activities/agent-turn/sandbox-runtime.ts +731 -0
- package/src/activities/agent-turn/stream-attempt.ts +1670 -0
- package/src/activities/agent-turn/tool-environment.ts +729 -0
- package/src/activities/agent-turn/tool-policy.ts +216 -0
- package/src/activities/agent-turn/tool-result-spill.ts +265 -0
- package/src/activities/agent-turn/turn-context.ts +281 -0
- package/src/activities/agent-turn/xai-capacity.ts +229 -0
- package/src/activities/agent-turn.ts +12 -12701
- package/src/activities/api-integrations.ts +3 -0
- package/src/activities/automations.ts +214 -0
- package/src/activities/codemode-dispatcher.ts +12 -1
- package/src/activities/common.ts +1 -5
- package/src/activities/connector-attachments.ts +168 -0
- package/src/activities/context-compaction.ts +18 -0
- package/src/activities/environment.ts +151 -55
- package/src/activities/generated-images.ts +26 -11
- package/src/activities/git-credential-renewal.ts +13 -3
- package/src/activities/goals.ts +85 -19
- package/src/activities/google-drive-provider.ts +178 -0
- package/src/activities/google-drive-publication.ts +147 -49
- package/src/activities/incident-telemetry-authority.ts +327 -0
- package/src/activities/incident-telemetry-preflight.ts +317 -0
- package/src/activities/knowledge-source-sync.ts +178 -37
- package/src/activities/mcp-credentials.ts +191 -17
- package/src/activities/open-suffix-resume.ts +422 -0
- package/src/activities/packs.ts +12 -60
- package/src/activities/parent-wake.ts +64 -14
- package/src/activities/retained-screenshot-reaper.ts +6 -3
- package/src/activities/retained-screenshots.ts +15 -47
- package/src/activities/rig-verification.ts +1 -1
- package/src/activities/run-input.ts +102 -142
- package/src/activities/sandbox-images.ts +7 -166
- package/src/activities/sandbox-lease.ts +406 -15
- package/src/activities/scheduled-tasks.ts +2103 -411
- package/src/activities/session-state.ts +10 -2
- package/src/activities/types.ts +32 -2
- package/src/activities/video-media-validation.ts +3 -3
- package/src/activities/video-output-retention.ts +2 -57
- package/src/activities/xai-auth.ts +8 -0
- package/src/activities-control.ts +2 -0
- package/src/activities.ts +3 -0
- package/src/activity-services.ts +13 -4
- package/src/connection-provider-use.ts +36 -0
- package/src/editable-artifact-materializer-subprocess.ts +25 -14
- package/src/editable-artifact-materializer.ts +29 -18
- package/src/github-rest-mcp.ts +713 -0
- package/src/http.ts +16 -6
- package/src/index.ts +40 -5
- package/src/knowledge-source-sync-activity-policy.ts +2 -0
- package/src/model-context-contributions.ts +33 -10
- package/src/observability-metrics.ts +357 -0
- package/src/opensandbox-kubernetes-inventory.ts +292 -0
- package/src/personal-github-git-credentials.ts +331 -0
- package/src/pr-review-credentials.ts +163 -0
- package/src/sandbox-archive-storage.ts +159 -0
- package/src/sandbox-resume.ts +449 -63
- package/src/sandbox-routing.ts +314 -16
- package/src/scheduled-alert-occurrence.ts +176 -0
- package/src/workflows/activities.ts +18 -2
- package/src/workflows/automations.ts +11 -0
- package/src/workflows/session.ts +13 -3
- package/src/workflows.ts +1 -0
- package/dist/activities-control-BJSDRSIP.js.map +0 -1
- package/dist/activities-turn-J5YO7XXX.js +0 -17243
- package/dist/activities-turn-J5YO7XXX.js.map +0 -1
- package/dist/chunk-N5TJIFCE.js.map +0 -1
- package/dist/chunk-P6Z2SLAA.js +0 -3092
- package/dist/chunk-P6Z2SLAA.js.map +0 -1
|
@@ -0,0 +1,327 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DEFAULT_FIRST_PARTY_MCP_PERMISSIONS,
|
|
3
|
+
type McpPersonalConnectionDelegation,
|
|
4
|
+
type ScheduledTask,
|
|
5
|
+
type ScheduledTaskRunAcceptedExecution,
|
|
6
|
+
type Session,
|
|
7
|
+
type SessionSystemUpdate,
|
|
8
|
+
} from "@opengeni/contracts";
|
|
9
|
+
import { defaultSessionMcpServerIds, resolveSessionToolPolicy } from "@opengeni/core";
|
|
10
|
+
import {
|
|
11
|
+
getRig,
|
|
12
|
+
getScheduledScopedRigVersionMetadata,
|
|
13
|
+
getScheduledTaskRunAcceptedExecution,
|
|
14
|
+
getVariableSet,
|
|
15
|
+
listEnabledMcpCapabilityServerIds,
|
|
16
|
+
listInstalledApiIntegrationServerIdsForDelegations,
|
|
17
|
+
markScheduledTaskRunAuthorityRejectedInTransaction,
|
|
18
|
+
requireSession,
|
|
19
|
+
type Database,
|
|
20
|
+
} from "@opengeni/db";
|
|
21
|
+
import {
|
|
22
|
+
allowedFirstPartyMcpToolsForSession,
|
|
23
|
+
resolveFirstPartyMcpToolPolicy,
|
|
24
|
+
type Settings,
|
|
25
|
+
} from "@opengeni/config";
|
|
26
|
+
import { withFirstPartyTools } from "./goals";
|
|
27
|
+
import {
|
|
28
|
+
INCIDENT_TELEMETRY_AUTHORITY_FENCE_LINEAGE_KEY,
|
|
29
|
+
incidentTelemetryAuthorityFence,
|
|
30
|
+
parseIncidentTelemetryAuthorityFence,
|
|
31
|
+
evaluateIncidentTelemetryPreflight,
|
|
32
|
+
type IncidentTelemetryResponderMetadata,
|
|
33
|
+
} from "./incident-telemetry-preflight";
|
|
34
|
+
|
|
35
|
+
/** Resolve only exact selected responder metadata; never read/decrypt values or call providers. */
|
|
36
|
+
export async function resolveIncidentTelemetryResponderMetadata(input: {
|
|
37
|
+
db: Database;
|
|
38
|
+
settings: Settings;
|
|
39
|
+
task: ScheduledTask;
|
|
40
|
+
session: Session | null;
|
|
41
|
+
personalConnectionDelegations: readonly McpPersonalConnectionDelegation[];
|
|
42
|
+
personalResourceAuthoritySubjectId?: string | null;
|
|
43
|
+
executionPolicy?: {
|
|
44
|
+
tools: ScheduledTaskRunAcceptedExecution["resolvedTools"];
|
|
45
|
+
firstPartyMcpTools: ScheduledTaskRunAcceptedExecution["resolvedFirstPartyMcpTools"];
|
|
46
|
+
firstPartyMcpPermissions:
|
|
47
|
+
| ScheduledTaskRunAcceptedExecution["resolvedFirstPartyMcpPermissions"]
|
|
48
|
+
| null;
|
|
49
|
+
variableSetId: string | null;
|
|
50
|
+
rigId: string | null;
|
|
51
|
+
rigVersionId: string | null;
|
|
52
|
+
toolPolicy: Session["toolPolicy"];
|
|
53
|
+
mcpServerIds: readonly string[];
|
|
54
|
+
toolPolicyVersion: number | null;
|
|
55
|
+
};
|
|
56
|
+
}): Promise<IncidentTelemetryResponderMetadata> {
|
|
57
|
+
const [capabilityServerIds, apiIntegrationServerIds] = await Promise.all([
|
|
58
|
+
listEnabledMcpCapabilityServerIds(input.db, input.task.workspaceId),
|
|
59
|
+
listInstalledApiIntegrationServerIdsForDelegations(
|
|
60
|
+
input.db,
|
|
61
|
+
input.task.workspaceId,
|
|
62
|
+
input.personalConnectionDelegations,
|
|
63
|
+
),
|
|
64
|
+
]);
|
|
65
|
+
const sessionTools = input.executionPolicy
|
|
66
|
+
? input.executionPolicy.tools
|
|
67
|
+
: input.session
|
|
68
|
+
? input.session.tools
|
|
69
|
+
: withFirstPartyTools(input.settings, input.task.agentConfig.tools);
|
|
70
|
+
const resolvedToolPolicy = resolveIncidentTelemetryResponderToolPolicy({
|
|
71
|
+
settingsMcpServerIds: input.settings.mcpServers.map((server) => server.id),
|
|
72
|
+
capabilityServerIds,
|
|
73
|
+
apiIntegrationServerIds,
|
|
74
|
+
...(input.executionPolicy
|
|
75
|
+
? { acceptedSessionMcpServerIds: input.executionPolicy.mcpServerIds }
|
|
76
|
+
: {}),
|
|
77
|
+
session: input.executionPolicy
|
|
78
|
+
? {
|
|
79
|
+
mcpServers: input.executionPolicy.mcpServerIds.map((id) => ({ id })),
|
|
80
|
+
tools: input.executionPolicy.tools,
|
|
81
|
+
toolPolicy: input.executionPolicy.toolPolicy,
|
|
82
|
+
}
|
|
83
|
+
: input.session,
|
|
84
|
+
plannedTools: sessionTools,
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
let metadataComplete = true;
|
|
88
|
+
let rig: IncidentTelemetryResponderMetadata["rig"] = null;
|
|
89
|
+
const variableSetIds = new Set<string>();
|
|
90
|
+
if (input.executionPolicy ?? input.session) {
|
|
91
|
+
const variableSetId = input.executionPolicy?.variableSetId ?? input.session?.variableSetId;
|
|
92
|
+
const rigId = input.executionPolicy?.rigId ?? input.session?.rigId ?? null;
|
|
93
|
+
const rigVersionId = input.executionPolicy?.rigVersionId ?? input.session?.rigVersionId ?? null;
|
|
94
|
+
if (variableSetId) variableSetIds.add(variableSetId);
|
|
95
|
+
if ((rigId === null) !== (rigVersionId === null)) {
|
|
96
|
+
metadataComplete = false;
|
|
97
|
+
} else if (rigId && rigVersionId) {
|
|
98
|
+
const selected = await getScheduledScopedRigVersionMetadata(
|
|
99
|
+
input.db,
|
|
100
|
+
{
|
|
101
|
+
accountId: input.task.accountId,
|
|
102
|
+
workspaceId: input.task.workspaceId,
|
|
103
|
+
subjectId: input.personalResourceAuthoritySubjectId ?? input.task.createdBy.subjectId,
|
|
104
|
+
},
|
|
105
|
+
rigId,
|
|
106
|
+
rigVersionId,
|
|
107
|
+
);
|
|
108
|
+
if (!selected) {
|
|
109
|
+
metadataComplete = false;
|
|
110
|
+
} else {
|
|
111
|
+
rig = {
|
|
112
|
+
name: selected.name,
|
|
113
|
+
credentialHooks: selected.version.credentialHooks,
|
|
114
|
+
checkHealth: selected.health.checkHealth,
|
|
115
|
+
};
|
|
116
|
+
for (const id of selected.version.defaultVariableSetIds) variableSetIds.add(id);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
} else {
|
|
120
|
+
if (input.task.variableSetId) variableSetIds.add(input.task.variableSetId);
|
|
121
|
+
if (input.task.rigId) {
|
|
122
|
+
const selectedRig = await getRig(
|
|
123
|
+
input.db,
|
|
124
|
+
{
|
|
125
|
+
accountId: input.task.accountId,
|
|
126
|
+
workspaceId: input.task.workspaceId,
|
|
127
|
+
subjectId: input.personalResourceAuthoritySubjectId ?? input.task.createdBy.subjectId,
|
|
128
|
+
},
|
|
129
|
+
input.task.rigId,
|
|
130
|
+
);
|
|
131
|
+
if (!selectedRig?.activeVersion || !selectedRig.activeVersionHealth) {
|
|
132
|
+
metadataComplete = false;
|
|
133
|
+
} else {
|
|
134
|
+
rig = {
|
|
135
|
+
name: selectedRig.name,
|
|
136
|
+
credentialHooks: selectedRig.activeVersion.credentialHooks,
|
|
137
|
+
checkHealth: selectedRig.activeVersionHealth.checkHealth,
|
|
138
|
+
};
|
|
139
|
+
for (const id of selectedRig.activeVersion.defaultVariableSetIds) variableSetIds.add(id);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
const variableSets = await Promise.all(
|
|
145
|
+
[...variableSetIds].map(
|
|
146
|
+
async (id) =>
|
|
147
|
+
await getVariableSet(
|
|
148
|
+
input.db,
|
|
149
|
+
{
|
|
150
|
+
accountId: input.task.accountId,
|
|
151
|
+
workspaceId: input.task.workspaceId,
|
|
152
|
+
subjectId: input.personalResourceAuthoritySubjectId ?? input.task.createdBy.subjectId,
|
|
153
|
+
},
|
|
154
|
+
id,
|
|
155
|
+
),
|
|
156
|
+
),
|
|
157
|
+
);
|
|
158
|
+
if (variableSets.some((variableSet) => variableSet === null)) {
|
|
159
|
+
metadataComplete = false;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
return {
|
|
163
|
+
metadataComplete,
|
|
164
|
+
resources: input.executionPolicy
|
|
165
|
+
? input.task.agentConfig.resources
|
|
166
|
+
: (input.session?.resources ?? input.task.agentConfig.resources),
|
|
167
|
+
mcpServerIds: resolvedToolPolicy.toolRefs.map((tool) => tool.id),
|
|
168
|
+
firstPartyMcpTools: input.executionPolicy
|
|
169
|
+
? input.executionPolicy.firstPartyMcpTools
|
|
170
|
+
: input.session
|
|
171
|
+
? allowedFirstPartyMcpToolsForSession(input.settings, input.session.firstPartyMcpTools)
|
|
172
|
+
: resolveFirstPartyMcpToolPolicy(input.settings).default,
|
|
173
|
+
firstPartyMcpPermissions: input.executionPolicy
|
|
174
|
+
? (input.executionPolicy.firstPartyMcpPermissions ?? DEFAULT_FIRST_PARTY_MCP_PERMISSIONS)
|
|
175
|
+
: (input.session?.firstPartyMcpPermissions ?? DEFAULT_FIRST_PARTY_MCP_PERMISSIONS),
|
|
176
|
+
rig,
|
|
177
|
+
variableSets: variableSets.flatMap((variableSet) =>
|
|
178
|
+
variableSet
|
|
179
|
+
? [
|
|
180
|
+
{
|
|
181
|
+
name: variableSet.name,
|
|
182
|
+
variables: variableSet.variables.map((variable) => ({
|
|
183
|
+
name: variable.name,
|
|
184
|
+
})),
|
|
185
|
+
},
|
|
186
|
+
]
|
|
187
|
+
: [],
|
|
188
|
+
),
|
|
189
|
+
toolPolicyVersion:
|
|
190
|
+
input.executionPolicy?.toolPolicyVersion ?? input.session?.toolPolicyVersion ?? null,
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/** Resolve the responder's current ID-only MCP policy without materializing runtime secrets. */
|
|
195
|
+
export function resolveIncidentTelemetryResponderToolPolicy(input: {
|
|
196
|
+
settingsMcpServerIds: readonly string[];
|
|
197
|
+
capabilityServerIds: readonly string[];
|
|
198
|
+
apiIntegrationServerIds: readonly string[];
|
|
199
|
+
acceptedSessionMcpServerIds?: readonly string[];
|
|
200
|
+
session: {
|
|
201
|
+
mcpServers: readonly { id: string }[];
|
|
202
|
+
tools: Session["tools"];
|
|
203
|
+
toolPolicy: Session["toolPolicy"];
|
|
204
|
+
} | null;
|
|
205
|
+
plannedTools: Session["tools"];
|
|
206
|
+
}) {
|
|
207
|
+
const workspaceDefaultMcpServerIds = new Set(input.settingsMcpServerIds);
|
|
208
|
+
for (const id of input.capabilityServerIds) workspaceDefaultMcpServerIds.add(id);
|
|
209
|
+
for (const id of input.apiIntegrationServerIds) workspaceDefaultMcpServerIds.add(id);
|
|
210
|
+
for (const id of input.acceptedSessionMcpServerIds ?? []) {
|
|
211
|
+
workspaceDefaultMcpServerIds.add(id);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
const availableMcpServerIds = new Set(workspaceDefaultMcpServerIds);
|
|
215
|
+
for (const server of input.session?.mcpServers ?? []) {
|
|
216
|
+
availableMcpServerIds.add(server.id);
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
return resolveSessionToolPolicy({
|
|
220
|
+
toolPolicy: input.session?.toolPolicy ?? {
|
|
221
|
+
mode: "explicit",
|
|
222
|
+
inheritedFromSessionId: null,
|
|
223
|
+
},
|
|
224
|
+
sessionTools: input.plannedTools,
|
|
225
|
+
availableMcpServerIds,
|
|
226
|
+
defaultMcpServerIds: defaultSessionMcpServerIds(
|
|
227
|
+
[...workspaceDefaultMcpServerIds].map((id) => ({ id })),
|
|
228
|
+
),
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/** Revalidate a source-frozen incident responder fence before a turn can claim it. */
|
|
233
|
+
export async function validateIncidentTelemetrySystemUpdateAuthority(input: {
|
|
234
|
+
db: Database;
|
|
235
|
+
settings: Settings;
|
|
236
|
+
workspaceId: string;
|
|
237
|
+
sessionId: string;
|
|
238
|
+
update: SessionSystemUpdate;
|
|
239
|
+
}): Promise<{ action: "accept" } | { action: "reject"; reason: string }> {
|
|
240
|
+
if (!(INCIDENT_TELEMETRY_AUTHORITY_FENCE_LINEAGE_KEY in input.update.lineage)) {
|
|
241
|
+
return { action: "accept" };
|
|
242
|
+
}
|
|
243
|
+
const fence = parseIncidentTelemetryAuthorityFence(input.update.lineage);
|
|
244
|
+
const payload = input.update.payload;
|
|
245
|
+
const taskId = input.update.lineage.scheduledTaskId;
|
|
246
|
+
const runId = payload.type === "scheduled_occurrence" ? payload.scheduledTaskRunId : null;
|
|
247
|
+
const reject = async () => {
|
|
248
|
+
if (runId) {
|
|
249
|
+
await markScheduledTaskRunAuthorityRejectedInTransaction(input.db, {
|
|
250
|
+
workspaceId: input.workspaceId,
|
|
251
|
+
sessionId: input.sessionId,
|
|
252
|
+
runId,
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
return {
|
|
256
|
+
action: "reject",
|
|
257
|
+
reason: "incident_responder_under_capable",
|
|
258
|
+
} as const;
|
|
259
|
+
};
|
|
260
|
+
if (!fence || typeof taskId !== "string" || !runId) return await reject();
|
|
261
|
+
|
|
262
|
+
const session = await requireSession(input.db, input.workspaceId, input.sessionId);
|
|
263
|
+
const acceptedExecution = await getScheduledTaskRunAcceptedExecution(input.db, {
|
|
264
|
+
workspaceId: input.workspaceId,
|
|
265
|
+
runId,
|
|
266
|
+
});
|
|
267
|
+
if (
|
|
268
|
+
!acceptedExecution ||
|
|
269
|
+
acceptedExecution.task.id !== taskId ||
|
|
270
|
+
!acceptedExecution.incidentPreflightRequired
|
|
271
|
+
) {
|
|
272
|
+
return await reject();
|
|
273
|
+
}
|
|
274
|
+
const task = acceptedExecution.task;
|
|
275
|
+
const personalConnectionDelegations = acceptedExecution.personalConnectionDelegations;
|
|
276
|
+
const responder = await resolveIncidentTelemetryResponderMetadata({
|
|
277
|
+
db: input.db,
|
|
278
|
+
settings: input.settings,
|
|
279
|
+
task,
|
|
280
|
+
session,
|
|
281
|
+
personalConnectionDelegations,
|
|
282
|
+
personalResourceAuthoritySubjectId: acceptedExecution.personalResourceAuthoritySubjectId,
|
|
283
|
+
executionPolicy: acceptedExecution.targetSessionExecution
|
|
284
|
+
? {
|
|
285
|
+
tools: acceptedExecution.targetSessionExecution.tools,
|
|
286
|
+
firstPartyMcpTools: acceptedExecution.targetSessionExecution.firstPartyMcpTools,
|
|
287
|
+
firstPartyMcpPermissions:
|
|
288
|
+
acceptedExecution.targetSessionExecution.firstPartyMcpPermissions,
|
|
289
|
+
variableSetId: acceptedExecution.targetSessionExecution.variableSetId,
|
|
290
|
+
rigId: acceptedExecution.targetSessionExecution.rigId,
|
|
291
|
+
rigVersionId: acceptedExecution.targetSessionExecution.rigVersionId,
|
|
292
|
+
toolPolicy: acceptedExecution.targetSessionExecution.toolPolicy,
|
|
293
|
+
mcpServerIds: acceptedExecution.targetSessionExecution.mcpServerIds,
|
|
294
|
+
toolPolicyVersion: acceptedExecution.targetSessionExecution.toolPolicyVersion,
|
|
295
|
+
}
|
|
296
|
+
: {
|
|
297
|
+
tools: acceptedExecution.resolvedTools,
|
|
298
|
+
firstPartyMcpTools: acceptedExecution.resolvedFirstPartyMcpTools,
|
|
299
|
+
firstPartyMcpPermissions: acceptedExecution.resolvedFirstPartyMcpPermissions,
|
|
300
|
+
variableSetId: acceptedExecution.resolvedVariableSet?.id ?? null,
|
|
301
|
+
rigId: acceptedExecution.resolvedRig?.id ?? null,
|
|
302
|
+
rigVersionId: acceptedExecution.resolvedRig?.versionId ?? null,
|
|
303
|
+
toolPolicy: session.toolPolicy,
|
|
304
|
+
mcpServerIds: [],
|
|
305
|
+
toolPolicyVersion: session.toolPolicyVersion,
|
|
306
|
+
},
|
|
307
|
+
});
|
|
308
|
+
const preflight = evaluateIncidentTelemetryPreflight({
|
|
309
|
+
agentConfig: task.agentConfig,
|
|
310
|
+
incidentTriggered: acceptedExecution.alertOccurrenceLabels !== null,
|
|
311
|
+
alertOccurrenceLabels: acceptedExecution.alertOccurrenceLabels,
|
|
312
|
+
responder,
|
|
313
|
+
});
|
|
314
|
+
if (preflight.action !== "ready") return await reject();
|
|
315
|
+
const current = incidentTelemetryAuthorityFence({
|
|
316
|
+
task,
|
|
317
|
+
responder,
|
|
318
|
+
alertOccurrenceLabels: acceptedExecution.alertOccurrenceLabels,
|
|
319
|
+
});
|
|
320
|
+
return current &&
|
|
321
|
+
current.toolPolicyVersion === fence.toolPolicyVersion &&
|
|
322
|
+
current.responderDigest === fence.responderDigest &&
|
|
323
|
+
current.taskDigest === fence.taskDigest &&
|
|
324
|
+
current.alertSelectorDigest === fence.alertSelectorDigest
|
|
325
|
+
? { action: "accept" }
|
|
326
|
+
: await reject();
|
|
327
|
+
}
|
|
@@ -0,0 +1,317 @@
|
|
|
1
|
+
import {
|
|
2
|
+
IncidentTelemetryPreflight,
|
|
3
|
+
stableJson,
|
|
4
|
+
type FirstPartyMcpToolName,
|
|
5
|
+
type Permission,
|
|
6
|
+
type ResourceRef,
|
|
7
|
+
type ScheduledTask,
|
|
8
|
+
type ScheduledTaskAgentConfig,
|
|
9
|
+
} from "@opengeni/contracts";
|
|
10
|
+
import { createHash } from "node:crypto";
|
|
11
|
+
import { isDeepStrictEqual } from "node:util";
|
|
12
|
+
|
|
13
|
+
export type IncidentTelemetryPreflightBlockReason =
|
|
14
|
+
| "incident_preflight_metadata_missing"
|
|
15
|
+
| "incident_responder_under_capable"
|
|
16
|
+
| "incident_data_source_unsuitable";
|
|
17
|
+
|
|
18
|
+
export type IncidentTelemetryPreflightResult =
|
|
19
|
+
| { action: "not_required" }
|
|
20
|
+
| { action: "ready" }
|
|
21
|
+
| { action: "blocked"; reason: IncidentTelemetryPreflightBlockReason };
|
|
22
|
+
|
|
23
|
+
export type IncidentTelemetryRigMetadata = {
|
|
24
|
+
name: string;
|
|
25
|
+
credentialHooks: readonly string[];
|
|
26
|
+
checkHealth: "passing" | "failing" | "unknown";
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export type IncidentTelemetryVariableSetMetadata = {
|
|
30
|
+
name: string;
|
|
31
|
+
variables: readonly { name: string }[];
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export type IncidentTelemetryResponderMetadata = {
|
|
35
|
+
/** False when an exact selected attachment could not be projected safely. */
|
|
36
|
+
metadataComplete: boolean;
|
|
37
|
+
resources: readonly ResourceRef[];
|
|
38
|
+
mcpServerIds: readonly string[];
|
|
39
|
+
firstPartyMcpTools: readonly FirstPartyMcpToolName[];
|
|
40
|
+
firstPartyMcpPermissions: readonly Permission[];
|
|
41
|
+
rig: IncidentTelemetryRigMetadata | null;
|
|
42
|
+
variableSets: readonly IncidentTelemetryVariableSetMetadata[];
|
|
43
|
+
/** Exact durable session policy version, or null for a not-yet-created session. */
|
|
44
|
+
toolPolicyVersion: number | null;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export type IncidentTelemetryPreflightInput = {
|
|
48
|
+
agentConfig: ScheduledTaskAgentConfig;
|
|
49
|
+
/** A valid structured alert occurrence also makes a legacy task incident-triggered. */
|
|
50
|
+
incidentTriggered: boolean;
|
|
51
|
+
/** Exact bounded labels from that validated occurrence; values are never rendered in blockers. */
|
|
52
|
+
alertOccurrenceLabels: Readonly<Record<string, string>> | null;
|
|
53
|
+
responder: IncidentTelemetryResponderMetadata;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
export const INCIDENT_TELEMETRY_AUTHORITY_FENCE_LINEAGE_KEY = "incidentTelemetryAuthorityFence";
|
|
57
|
+
|
|
58
|
+
export type IncidentTelemetryAuthorityFence = {
|
|
59
|
+
version: 2;
|
|
60
|
+
toolPolicyVersion: number;
|
|
61
|
+
responderDigest: string;
|
|
62
|
+
taskDigest: string;
|
|
63
|
+
alertSelectorDigest: string;
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
export type IncidentTelemetryPreflightDeclaration =
|
|
67
|
+
| { action: "not_required" }
|
|
68
|
+
| {
|
|
69
|
+
action: "blocked";
|
|
70
|
+
reason: "incident_preflight_metadata_missing" | "incident_data_source_unsuitable";
|
|
71
|
+
}
|
|
72
|
+
| { action: "required"; preflight: IncidentTelemetryPreflight };
|
|
73
|
+
|
|
74
|
+
export function incidentTelemetryPreflightDeclaration(
|
|
75
|
+
agentConfig: ScheduledTaskAgentConfig,
|
|
76
|
+
incidentTriggered: boolean,
|
|
77
|
+
): IncidentTelemetryPreflightDeclaration {
|
|
78
|
+
const rawConfig = agentConfig as ScheduledTaskAgentConfig & Record<string, unknown>;
|
|
79
|
+
const executionClass = rawConfig.executionClass;
|
|
80
|
+
const rawPreflight = rawConfig.incidentTelemetryPreflight;
|
|
81
|
+
if (executionClass === undefined && rawPreflight === undefined && !incidentTriggered) {
|
|
82
|
+
return { action: "not_required" };
|
|
83
|
+
}
|
|
84
|
+
if (executionClass !== "incident_telemetry" || rawPreflight === undefined) {
|
|
85
|
+
return { action: "blocked", reason: "incident_preflight_metadata_missing" };
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const parsed = IncidentTelemetryPreflight.safeParse(rawPreflight);
|
|
89
|
+
if (!parsed.success) {
|
|
90
|
+
const dataSourceInvalid = parsed.error.issues.some((issue) => issue.path[0] === "dataSource");
|
|
91
|
+
return {
|
|
92
|
+
action: "blocked",
|
|
93
|
+
reason: dataSourceInvalid
|
|
94
|
+
? "incident_data_source_unsuitable"
|
|
95
|
+
: "incident_preflight_metadata_missing",
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
return { action: "required", preflight: parsed.data };
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Pure, metadata-only incident admission. No provider request, public endpoint
|
|
103
|
+
* fetch, secret read/decrypt, session creation, or ambient credential lookup is
|
|
104
|
+
* reachable from this evaluator.
|
|
105
|
+
*/
|
|
106
|
+
export function evaluateIncidentTelemetryPreflight(
|
|
107
|
+
input: IncidentTelemetryPreflightInput,
|
|
108
|
+
): IncidentTelemetryPreflightResult {
|
|
109
|
+
const declaration = incidentTelemetryPreflightDeclaration(
|
|
110
|
+
input.agentConfig,
|
|
111
|
+
input.incidentTriggered,
|
|
112
|
+
);
|
|
113
|
+
if (declaration.action !== "required") return declaration;
|
|
114
|
+
const preflight = declaration.preflight;
|
|
115
|
+
|
|
116
|
+
if (!input.responder.metadataComplete) {
|
|
117
|
+
return blocked("incident_preflight_metadata_missing");
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
if (
|
|
121
|
+
preflight.requiredResources.some(
|
|
122
|
+
(required) =>
|
|
123
|
+
!input.responder.resources.some((selected) => isDeepStrictEqual(selected, required)),
|
|
124
|
+
)
|
|
125
|
+
) {
|
|
126
|
+
return blocked("incident_responder_under_capable");
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
const selectedMcpServerIds = new Set(input.responder.mcpServerIds);
|
|
130
|
+
if (preflight.requiredMcpServerIds.some((id) => !selectedMcpServerIds.has(id))) {
|
|
131
|
+
return blocked("incident_responder_under_capable");
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
const selectedFirstPartyTools = new Set(input.responder.firstPartyMcpTools);
|
|
135
|
+
if (preflight.requiredFirstPartyMcpTools.some((tool) => !selectedFirstPartyTools.has(tool))) {
|
|
136
|
+
return blocked("incident_responder_under_capable");
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
const selectedFirstPartyPermissions = new Set(input.responder.firstPartyMcpPermissions);
|
|
140
|
+
if (
|
|
141
|
+
preflight.requiredFirstPartyMcpPermissions.some(
|
|
142
|
+
(permission) => !selectedFirstPartyPermissions.has(permission),
|
|
143
|
+
)
|
|
144
|
+
) {
|
|
145
|
+
return blocked("incident_responder_under_capable");
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
if (preflight.requiredRig && !rigSatisfies(input.responder.rig, preflight.requiredRig)) {
|
|
149
|
+
return blocked("incident_responder_under_capable");
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
const variableSetsByName = new Map(input.responder.variableSets.map((set) => [set.name, set]));
|
|
153
|
+
if (preflight.requiredVariableSetNames.some((name) => !variableSetsByName.has(name))) {
|
|
154
|
+
return blocked("incident_responder_under_capable");
|
|
155
|
+
}
|
|
156
|
+
const attachedVariableNames = new Set(
|
|
157
|
+
input.responder.variableSets.flatMap((set) => set.variables.map((variable) => variable.name)),
|
|
158
|
+
);
|
|
159
|
+
if (preflight.requiredVariableNames.some((name) => !attachedVariableNames.has(name))) {
|
|
160
|
+
return blocked("incident_responder_under_capable");
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
const route = preflight.dataSource.route;
|
|
164
|
+
if (route.kind === "mcp" && !selectedMcpServerIds.has(route.serverId)) {
|
|
165
|
+
return blocked("incident_responder_under_capable");
|
|
166
|
+
}
|
|
167
|
+
if (route.kind === "first_party" && !selectedFirstPartyTools.has(route.tool)) {
|
|
168
|
+
return blocked("incident_responder_under_capable");
|
|
169
|
+
}
|
|
170
|
+
if (route.kind === "variable_set") {
|
|
171
|
+
const selected = variableSetsByName.get(route.variableSetName);
|
|
172
|
+
const names = new Set(selected?.variables.map((variable) => variable.name) ?? []);
|
|
173
|
+
if (!selected || route.variableNames.some((name) => !names.has(name))) {
|
|
174
|
+
return blocked("incident_responder_under_capable");
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
if (
|
|
178
|
+
route.kind === "rig_credential_hook" &&
|
|
179
|
+
!rigSatisfies(input.responder.rig, {
|
|
180
|
+
name: preflight.requiredRig?.name ?? "",
|
|
181
|
+
credentialHookIds: [route.credentialHookId],
|
|
182
|
+
})
|
|
183
|
+
) {
|
|
184
|
+
return blocked("incident_responder_under_capable");
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
if (!seriesMetadataSatisfies(preflight.dataSource)) {
|
|
188
|
+
return blocked("incident_data_source_unsuitable");
|
|
189
|
+
}
|
|
190
|
+
if (!alertSelectorsSatisfy(preflight.dataSource, input.alertOccurrenceLabels)) {
|
|
191
|
+
return blocked("incident_data_source_unsuitable");
|
|
192
|
+
}
|
|
193
|
+
return { action: "ready" };
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
export function incidentTelemetryAuthorityFence(input: {
|
|
197
|
+
task: ScheduledTask;
|
|
198
|
+
responder: IncidentTelemetryResponderMetadata;
|
|
199
|
+
alertOccurrenceLabels: Readonly<Record<string, string>> | null;
|
|
200
|
+
}): IncidentTelemetryAuthorityFence | null {
|
|
201
|
+
const { task, responder } = input;
|
|
202
|
+
if (responder.toolPolicyVersion === null) return null;
|
|
203
|
+
const declaration = incidentTelemetryPreflightDeclaration(
|
|
204
|
+
task.agentConfig,
|
|
205
|
+
input.alertOccurrenceLabels !== null,
|
|
206
|
+
);
|
|
207
|
+
if (declaration.action !== "required" || !input.alertOccurrenceLabels) return null;
|
|
208
|
+
const selectorEntries = declaration.preflight.dataSource.alertSelectorLabels
|
|
209
|
+
.map((label) => [label, input.alertOccurrenceLabels?.[label]] as const)
|
|
210
|
+
.sort(([left], [right]) => left.localeCompare(right));
|
|
211
|
+
if (selectorEntries.some(([, value]) => typeof value !== "string" || value.length === 0)) {
|
|
212
|
+
return null;
|
|
213
|
+
}
|
|
214
|
+
const normalized = {
|
|
215
|
+
metadataComplete: responder.metadataComplete,
|
|
216
|
+
resources: [...responder.resources].map((resource) => stableJson(resource)).sort(),
|
|
217
|
+
mcpServerIds: [...responder.mcpServerIds].sort(),
|
|
218
|
+
firstPartyMcpTools: [...responder.firstPartyMcpTools].sort(),
|
|
219
|
+
firstPartyMcpPermissions: [...responder.firstPartyMcpPermissions].sort(),
|
|
220
|
+
rig: responder.rig
|
|
221
|
+
? {
|
|
222
|
+
name: responder.rig.name,
|
|
223
|
+
credentialHooks: [...responder.rig.credentialHooks].sort(),
|
|
224
|
+
checkHealth: responder.rig.checkHealth,
|
|
225
|
+
}
|
|
226
|
+
: null,
|
|
227
|
+
variableSets: [...responder.variableSets]
|
|
228
|
+
.map((set) => ({
|
|
229
|
+
name: set.name,
|
|
230
|
+
variables: set.variables.map((variable) => variable.name).sort(),
|
|
231
|
+
}))
|
|
232
|
+
.sort((left, right) => left.name.localeCompare(right.name)),
|
|
233
|
+
};
|
|
234
|
+
return {
|
|
235
|
+
version: 2,
|
|
236
|
+
toolPolicyVersion: responder.toolPolicyVersion,
|
|
237
|
+
responderDigest: createHash("sha256").update(stableJson(normalized)).digest("hex"),
|
|
238
|
+
taskDigest: createHash("sha256").update(stableJson(task)).digest("hex"),
|
|
239
|
+
alertSelectorDigest: createHash("sha256").update(stableJson(selectorEntries)).digest("hex"),
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
export function parseIncidentTelemetryAuthorityFence(
|
|
244
|
+
lineage: Record<string, unknown>,
|
|
245
|
+
): IncidentTelemetryAuthorityFence | null {
|
|
246
|
+
const raw = lineage[INCIDENT_TELEMETRY_AUTHORITY_FENCE_LINEAGE_KEY];
|
|
247
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw)) return null;
|
|
248
|
+
const value = raw as Record<string, unknown>;
|
|
249
|
+
return value.version === 2 &&
|
|
250
|
+
typeof value.toolPolicyVersion === "number" &&
|
|
251
|
+
Number.isInteger(value.toolPolicyVersion) &&
|
|
252
|
+
value.toolPolicyVersion > 0 &&
|
|
253
|
+
typeof value.responderDigest === "string" &&
|
|
254
|
+
/^[0-9a-f]{64}$/.test(value.responderDigest) &&
|
|
255
|
+
typeof value.taskDigest === "string" &&
|
|
256
|
+
/^[0-9a-f]{64}$/.test(value.taskDigest) &&
|
|
257
|
+
typeof value.alertSelectorDigest === "string" &&
|
|
258
|
+
/^[0-9a-f]{64}$/.test(value.alertSelectorDigest)
|
|
259
|
+
? {
|
|
260
|
+
version: 2,
|
|
261
|
+
toolPolicyVersion: value.toolPolicyVersion,
|
|
262
|
+
responderDigest: value.responderDigest,
|
|
263
|
+
taskDigest: value.taskDigest,
|
|
264
|
+
alertSelectorDigest: value.alertSelectorDigest,
|
|
265
|
+
}
|
|
266
|
+
: null;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
function blocked(reason: IncidentTelemetryPreflightBlockReason): IncidentTelemetryPreflightResult {
|
|
270
|
+
return { action: "blocked", reason };
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
function rigSatisfies(
|
|
274
|
+
rig: IncidentTelemetryRigMetadata | null,
|
|
275
|
+
required: { name: string; credentialHookIds: readonly string[] },
|
|
276
|
+
): boolean {
|
|
277
|
+
if (!rig || rig.name !== required.name || rig.checkHealth !== "passing") {
|
|
278
|
+
return false;
|
|
279
|
+
}
|
|
280
|
+
const hookIds = new Set(rig.credentialHooks);
|
|
281
|
+
return required.credentialHookIds.every((hookId) => hookIds.has(hookId));
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
function seriesMetadataSatisfies(dataSource: IncidentTelemetryPreflight["dataSource"]): boolean {
|
|
285
|
+
if (dataSource.queryPath !== "/api/v1/query" && dataSource.queryPath !== "/api/v1/query_range") {
|
|
286
|
+
return false;
|
|
287
|
+
}
|
|
288
|
+
return dataSource.requiredSeries.every((required) =>
|
|
289
|
+
dataSource.availableSeries.some((available) => {
|
|
290
|
+
if (available.metric !== required.metric) return false;
|
|
291
|
+
const labels = new Set(available.labels);
|
|
292
|
+
return (
|
|
293
|
+
labels.has(dataSource.workspaceLabel) && required.labels.every((label) => labels.has(label))
|
|
294
|
+
);
|
|
295
|
+
}),
|
|
296
|
+
);
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
function alertSelectorsSatisfy(
|
|
300
|
+
dataSource: IncidentTelemetryPreflight["dataSource"],
|
|
301
|
+
occurrenceLabels: Readonly<Record<string, string>> | null,
|
|
302
|
+
): boolean {
|
|
303
|
+
if (!occurrenceLabels) return false;
|
|
304
|
+
return dataSource.alertSelectorLabels.every(
|
|
305
|
+
(label) =>
|
|
306
|
+
label !== dataSource.workspaceLabel &&
|
|
307
|
+
typeof occurrenceLabels[label] === "string" &&
|
|
308
|
+
occurrenceLabels[label]!.length > 0 &&
|
|
309
|
+
dataSource.requiredSeries.every((series) => series.labels.includes(label)) &&
|
|
310
|
+
dataSource.availableSeries.some(
|
|
311
|
+
(series) =>
|
|
312
|
+
dataSource.requiredSeries.some((required) => required.metric === series.metric) &&
|
|
313
|
+
series.labels.includes(dataSource.workspaceLabel) &&
|
|
314
|
+
series.labels.includes(label),
|
|
315
|
+
),
|
|
316
|
+
);
|
|
317
|
+
}
|