@elevasis/sdk 1.24.0 → 1.26.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/cli.cjs +875 -834
- package/dist/index.d.ts +4857 -4547
- package/dist/index.js +564 -2338
- package/dist/node/index.d.ts +693 -1356
- package/dist/node/index.js +1 -1
- package/dist/test-utils/index.d.ts +4186 -4139
- package/dist/test-utils/index.js +694 -2769
- package/dist/types/worker/adapters/clickup.d.ts +22 -0
- package/dist/types/worker/adapters/index.d.ts +1 -0
- package/dist/types/worker/index.d.ts +3 -2
- package/dist/types/worker/platform.d.ts +2 -2
- package/dist/worker/index.js +427 -2803
- package/package.json +2 -2
- package/reference/_navigation.md +11 -1
- package/reference/_reference-manifest.json +70 -0
- package/reference/claude-config/rules/organization-model.md +12 -1
- package/reference/claude-config/rules/organization-os.md +12 -1
- package/reference/claude-config/skills/om/SKILL.md +13 -5
- package/reference/claude-config/skills/om/operations/codify-level-a.md +109 -100
- package/reference/claude-config/skills/om/operations/customers.md +10 -6
- package/reference/claude-config/skills/om/operations/features.md +7 -3
- package/reference/claude-config/skills/om/operations/goals.md +10 -6
- package/reference/claude-config/skills/om/operations/identity.md +8 -5
- package/reference/claude-config/skills/om/operations/labels.md +17 -1
- package/reference/claude-config/skills/om/operations/offerings.md +11 -7
- package/reference/claude-config/skills/om/operations/roles.md +11 -7
- package/reference/claude-config/skills/om/operations/techStack.md +10 -2
- package/reference/claude-config/sync-notes/2026-05-20-om-define-helpers.md +32 -0
- package/reference/claude-config/sync-notes/2026-05-22-access-model-and-right-panel.md +43 -0
- package/reference/claude-config/sync-notes/2026-05-22-lead-gen-tenant-config.md +40 -0
- package/reference/claude-config/sync-notes/2026-05-22-org-model-multi-file-split.md +61 -0
- package/reference/cli-management.mdx +539 -0
- package/reference/cli.mdx +579 -808
- package/reference/concepts.mdx +134 -146
- package/reference/deployment/api.mdx +296 -297
- package/reference/deployment/command-center.mdx +208 -209
- package/reference/deployment/index.mdx +194 -195
- package/reference/deployment/provided-features.mdx +110 -107
- package/reference/deployment/ui-execution.mdx +249 -250
- package/reference/framework/index.mdx +111 -195
- package/reference/framework/resource-documentation.mdx +90 -0
- package/reference/framework/tutorial-system.mdx +135 -135
- package/reference/getting-started.mdx +141 -142
- package/reference/index.mdx +95 -106
- package/reference/packages/ui/src/auth/README.md +6 -6
- package/reference/platform-tools/adapters-integration.mdx +300 -301
- package/reference/platform-tools/adapters-platform.mdx +552 -553
- package/reference/platform-tools/index.mdx +216 -217
- package/reference/platform-tools/type-safety.mdx +82 -82
- package/reference/resources/index.mdx +348 -349
- package/reference/resources/patterns.mdx +446 -449
- package/reference/resources/types.mdx +115 -116
- package/reference/roadmap.mdx +164 -165
- package/reference/rules/organization-model.md +14 -0
- package/reference/runtime.mdx +172 -173
- package/reference/scaffold/operations/propagation-pipeline.md +1 -1
- package/reference/scaffold/recipes/customize-crm-actions.md +45 -46
- package/reference/scaffold/recipes/extend-crm.md +253 -255
- package/reference/scaffold/recipes/extend-lead-gen.md +130 -77
- package/reference/scaffold/recipes/index.md +43 -44
- package/reference/scaffold/reference/contracts.md +1275 -1432
- package/reference/scaffold/reference/glossary.md +8 -6
- package/reference/scaffold/ui/feature-flags-and-gating.md +59 -46
- package/reference/scaffold/ui/feature-shell.mdx +11 -11
- package/reference/scaffold/ui/recipes.md +24 -24
- package/reference/troubleshooting.mdx +222 -223
package/dist/worker/index.js
CHANGED
|
@@ -2060,6 +2060,12 @@ var zodToJsonSchema = (schema, options) => {
|
|
|
2060
2060
|
}
|
|
2061
2061
|
return combined;
|
|
2062
2062
|
};
|
|
2063
|
+
|
|
2064
|
+
// ../core/src/execution/engine/workflow/types.ts
|
|
2065
|
+
var StepType = {
|
|
2066
|
+
LINEAR: "linear",
|
|
2067
|
+
CONDITIONAL: "conditional"
|
|
2068
|
+
};
|
|
2063
2069
|
function errorToString(error) {
|
|
2064
2070
|
if (error instanceof ZodError) {
|
|
2065
2071
|
return JSON.stringify(error.issues, null, 2);
|
|
@@ -2081,6 +2087,26 @@ function getErrorDetails(error) {
|
|
|
2081
2087
|
return details;
|
|
2082
2088
|
}
|
|
2083
2089
|
|
|
2090
|
+
// ../core/src/execution/engine/workflow/log-truncate.ts
|
|
2091
|
+
var LOG_STRING_TRUNCATE_LIMIT = 200;
|
|
2092
|
+
function truncateForLogging(value) {
|
|
2093
|
+
if (value === null || value === void 0) return value;
|
|
2094
|
+
if (typeof value === "string") {
|
|
2095
|
+
return value.length > LOG_STRING_TRUNCATE_LIMIT ? value.slice(0, LOG_STRING_TRUNCATE_LIMIT) + `\u2026 [${value.length} chars]` : value;
|
|
2096
|
+
}
|
|
2097
|
+
if (Array.isArray(value)) {
|
|
2098
|
+
return value.map(truncateForLogging);
|
|
2099
|
+
}
|
|
2100
|
+
if (typeof value === "object") {
|
|
2101
|
+
const result = {};
|
|
2102
|
+
for (const [k, v] of Object.entries(value)) {
|
|
2103
|
+
result[k] = truncateForLogging(v);
|
|
2104
|
+
}
|
|
2105
|
+
return result;
|
|
2106
|
+
}
|
|
2107
|
+
return value;
|
|
2108
|
+
}
|
|
2109
|
+
|
|
2084
2110
|
// ../core/src/execution/engine/base/errors.ts
|
|
2085
2111
|
var ExecutionError = class extends Error {
|
|
2086
2112
|
/**
|
|
@@ -2121,6 +2147,305 @@ var ExecutionError = class extends Error {
|
|
|
2121
2147
|
}
|
|
2122
2148
|
};
|
|
2123
2149
|
|
|
2150
|
+
// ../core/src/execution/engine/workflow/errors.ts
|
|
2151
|
+
var WorkflowStepError = class extends ExecutionError {
|
|
2152
|
+
type = "workflow_step_error";
|
|
2153
|
+
severity = "critical";
|
|
2154
|
+
category = "workflow";
|
|
2155
|
+
constructor(message, context) {
|
|
2156
|
+
super(message, context);
|
|
2157
|
+
}
|
|
2158
|
+
};
|
|
2159
|
+
var WorkflowValidationError = class extends ExecutionError {
|
|
2160
|
+
type = "workflow_validation_error";
|
|
2161
|
+
severity = "info";
|
|
2162
|
+
category = "validation";
|
|
2163
|
+
constructor(message, context) {
|
|
2164
|
+
super(message, context);
|
|
2165
|
+
}
|
|
2166
|
+
};
|
|
2167
|
+
|
|
2168
|
+
// ../core/src/execution/engine/workflow/utils.ts
|
|
2169
|
+
function validateEntryPoint(steps, entryPoint) {
|
|
2170
|
+
if (!(entryPoint in steps)) {
|
|
2171
|
+
throw new WorkflowValidationError(`Entry point step '${entryPoint}' not found in workflow`, {
|
|
2172
|
+
entryPoint
|
|
2173
|
+
});
|
|
2174
|
+
}
|
|
2175
|
+
}
|
|
2176
|
+
function findTerminalSteps(steps) {
|
|
2177
|
+
return Object.values(steps).filter((step) => step.next === null);
|
|
2178
|
+
}
|
|
2179
|
+
function validateTerminalSteps(steps, workflowId) {
|
|
2180
|
+
const terminalSteps = findTerminalSteps(steps);
|
|
2181
|
+
if (terminalSteps.length === 0) {
|
|
2182
|
+
throw new WorkflowValidationError(`Workflow '${workflowId}' must have at least one terminal step (next: null)`, {
|
|
2183
|
+
workflowId
|
|
2184
|
+
});
|
|
2185
|
+
}
|
|
2186
|
+
}
|
|
2187
|
+
function validateStepReferences(steps) {
|
|
2188
|
+
for (const [id, step] of Object.entries(steps)) {
|
|
2189
|
+
if (step.next === null) {
|
|
2190
|
+
continue;
|
|
2191
|
+
}
|
|
2192
|
+
if (step.next.type === StepType.LINEAR) {
|
|
2193
|
+
if (!(step.next.target in steps)) {
|
|
2194
|
+
throw new WorkflowValidationError(`Step '${id}' references non-existent target '${step.next.target}'`, {
|
|
2195
|
+
stepId: id,
|
|
2196
|
+
target: step.next.target
|
|
2197
|
+
});
|
|
2198
|
+
}
|
|
2199
|
+
} else if (step.next.type === StepType.CONDITIONAL) {
|
|
2200
|
+
const targets = [...step.next.routes.map((r) => r.target), step.next.default];
|
|
2201
|
+
for (const target of targets) {
|
|
2202
|
+
if (!(target in steps)) {
|
|
2203
|
+
throw new WorkflowValidationError(`Step '${id}' references non-existent target '${target}'`, {
|
|
2204
|
+
stepId: id,
|
|
2205
|
+
target
|
|
2206
|
+
});
|
|
2207
|
+
}
|
|
2208
|
+
}
|
|
2209
|
+
}
|
|
2210
|
+
}
|
|
2211
|
+
}
|
|
2212
|
+
function detectCycle(visited, executionPath, currentStepId) {
|
|
2213
|
+
if (visited.has(currentStepId)) {
|
|
2214
|
+
const cycle = executionPath.slice(executionPath.indexOf(currentStepId));
|
|
2215
|
+
throw new WorkflowStepError(`Cycle detected in workflow: ${cycle.join(" -> ")} -> ${currentStepId}`, {
|
|
2216
|
+
stepId: currentStepId,
|
|
2217
|
+
cycle: [...cycle, currentStepId]
|
|
2218
|
+
});
|
|
2219
|
+
}
|
|
2220
|
+
}
|
|
2221
|
+
function validateTerminalOutput(stepId, output, outputSchema) {
|
|
2222
|
+
if (!outputSchema) {
|
|
2223
|
+
return;
|
|
2224
|
+
}
|
|
2225
|
+
try {
|
|
2226
|
+
outputSchema.parse(output);
|
|
2227
|
+
} catch (error) {
|
|
2228
|
+
throw new WorkflowValidationError(
|
|
2229
|
+
`Terminal step '${stepId}' produced invalid output: ${error instanceof Error ? error.message : String(error)}`,
|
|
2230
|
+
{ stepId, validationError: error instanceof Error ? error.message : String(error) }
|
|
2231
|
+
);
|
|
2232
|
+
}
|
|
2233
|
+
}
|
|
2234
|
+
async function determineNextStep(step, currentData, context) {
|
|
2235
|
+
const { next } = step;
|
|
2236
|
+
if (next === null) {
|
|
2237
|
+
return null;
|
|
2238
|
+
}
|
|
2239
|
+
if (next.type === StepType.LINEAR) {
|
|
2240
|
+
return next.target;
|
|
2241
|
+
}
|
|
2242
|
+
if (next.type === StepType.CONDITIONAL) {
|
|
2243
|
+
return evaluateConditionalRoutes(step.id, next, currentData, context);
|
|
2244
|
+
}
|
|
2245
|
+
throw new WorkflowStepError(`Unknown next configuration type in step ${step.id}`, {
|
|
2246
|
+
stepId: step.id
|
|
2247
|
+
});
|
|
2248
|
+
}
|
|
2249
|
+
async function evaluateConditionalRoutes(stepId, next, currentData, context) {
|
|
2250
|
+
for (const route of next.routes) {
|
|
2251
|
+
try {
|
|
2252
|
+
if (route.condition(currentData)) {
|
|
2253
|
+
context.logger.debug(`Conditional route taken: ${stepId} -> ${route.target}`, {
|
|
2254
|
+
type: "workflow",
|
|
2255
|
+
contextType: "conditional-route",
|
|
2256
|
+
stepId,
|
|
2257
|
+
target: route.target
|
|
2258
|
+
});
|
|
2259
|
+
return route.target;
|
|
2260
|
+
}
|
|
2261
|
+
} catch (error) {
|
|
2262
|
+
context.logger.warn(`Error evaluating condition in step ${stepId}: ${error}`, {
|
|
2263
|
+
type: "workflow",
|
|
2264
|
+
contextType: "conditional-route",
|
|
2265
|
+
stepId,
|
|
2266
|
+
target: "",
|
|
2267
|
+
error: errorToString(error)
|
|
2268
|
+
});
|
|
2269
|
+
}
|
|
2270
|
+
}
|
|
2271
|
+
context.logger.debug(`Using default route: ${stepId} -> ${next.default}`, {
|
|
2272
|
+
type: "workflow",
|
|
2273
|
+
contextType: "conditional-route",
|
|
2274
|
+
stepId,
|
|
2275
|
+
target: next.default
|
|
2276
|
+
});
|
|
2277
|
+
return next.default;
|
|
2278
|
+
}
|
|
2279
|
+
function logWorkflowStart(context, workflowId, workflowName) {
|
|
2280
|
+
context.logger.info(`Executing workflow: ${workflowId}`, {
|
|
2281
|
+
type: "workflow",
|
|
2282
|
+
contextType: "workflow-execution",
|
|
2283
|
+
executionId: context.executionId,
|
|
2284
|
+
workflowId,
|
|
2285
|
+
workflowName,
|
|
2286
|
+
organizationId: context.organizationId
|
|
2287
|
+
});
|
|
2288
|
+
}
|
|
2289
|
+
function logWorkflowSuccess(context, workflowId, executionPath) {
|
|
2290
|
+
context.logger.info(`Workflow completed successfully: ${workflowId}`, {
|
|
2291
|
+
type: "workflow",
|
|
2292
|
+
contextType: "workflow-execution",
|
|
2293
|
+
executionId: context.executionId,
|
|
2294
|
+
workflowId,
|
|
2295
|
+
organizationId: context.organizationId,
|
|
2296
|
+
executionPath
|
|
2297
|
+
});
|
|
2298
|
+
}
|
|
2299
|
+
function logWorkflowFailure(context, workflowId, error) {
|
|
2300
|
+
context.logger.error(`Execution failed: workflow/${workflowId}`, {
|
|
2301
|
+
type: "workflow",
|
|
2302
|
+
contextType: "workflow-failure",
|
|
2303
|
+
executionId: context.executionId,
|
|
2304
|
+
workflowId,
|
|
2305
|
+
error: errorToString(error)
|
|
2306
|
+
});
|
|
2307
|
+
}
|
|
2308
|
+
function logStepStart(context, stepId, stepName, input, startTime) {
|
|
2309
|
+
context.logger.info(`Step started: ${stepName}`, {
|
|
2310
|
+
type: "workflow",
|
|
2311
|
+
contextType: "step-started",
|
|
2312
|
+
stepId,
|
|
2313
|
+
stepStatus: "started",
|
|
2314
|
+
input: truncateForLogging(input),
|
|
2315
|
+
startTime
|
|
2316
|
+
});
|
|
2317
|
+
}
|
|
2318
|
+
function logStepSuccess(context, stepId, stepName, output, duration, isTerminal, startTime, endTime) {
|
|
2319
|
+
context.logger.info(`Step completed: ${stepName}`, {
|
|
2320
|
+
type: "workflow",
|
|
2321
|
+
contextType: "step-completed",
|
|
2322
|
+
stepId,
|
|
2323
|
+
stepStatus: "completed",
|
|
2324
|
+
output: truncateForLogging(output),
|
|
2325
|
+
duration,
|
|
2326
|
+
isTerminal,
|
|
2327
|
+
startTime,
|
|
2328
|
+
endTime
|
|
2329
|
+
});
|
|
2330
|
+
}
|
|
2331
|
+
function logStepFailure(context, stepId, stepName, error, duration, startTime, endTime) {
|
|
2332
|
+
context.logger.error(`Step failed: ${stepName}`, {
|
|
2333
|
+
type: "workflow",
|
|
2334
|
+
contextType: "step-failed",
|
|
2335
|
+
stepId,
|
|
2336
|
+
stepStatus: "failed",
|
|
2337
|
+
error: errorToString(error),
|
|
2338
|
+
duration,
|
|
2339
|
+
startTime,
|
|
2340
|
+
endTime
|
|
2341
|
+
});
|
|
2342
|
+
}
|
|
2343
|
+
function logExecutionPath(context, executionPath) {
|
|
2344
|
+
context.logger.info(`Workflow completed. Execution path: ${executionPath.join(" -> ")}`, {
|
|
2345
|
+
type: "workflow",
|
|
2346
|
+
contextType: "execution-path",
|
|
2347
|
+
executionPath
|
|
2348
|
+
});
|
|
2349
|
+
}
|
|
2350
|
+
|
|
2351
|
+
// ../core/src/execution/engine/workflow/workflow.ts
|
|
2352
|
+
var Workflow = class {
|
|
2353
|
+
config;
|
|
2354
|
+
contract;
|
|
2355
|
+
steps;
|
|
2356
|
+
entryPoint;
|
|
2357
|
+
// Derived properties (computed from definition)
|
|
2358
|
+
shouldGenerateOutput;
|
|
2359
|
+
/**
|
|
2360
|
+
* Create a new workflow instance from definition
|
|
2361
|
+
*
|
|
2362
|
+
* @param definition - Workflow definition with config, contract, steps, and entryPoint
|
|
2363
|
+
*/
|
|
2364
|
+
constructor(definition) {
|
|
2365
|
+
this.config = definition.config;
|
|
2366
|
+
this.contract = definition.contract;
|
|
2367
|
+
this.steps = definition.steps;
|
|
2368
|
+
this.entryPoint = definition.entryPoint;
|
|
2369
|
+
this.shouldGenerateOutput = !!definition.contract.outputSchema;
|
|
2370
|
+
validateEntryPoint(this.steps, this.entryPoint);
|
|
2371
|
+
validateTerminalSteps(this.steps, this.config.resourceId);
|
|
2372
|
+
validateStepReferences(this.steps);
|
|
2373
|
+
}
|
|
2374
|
+
/**
|
|
2375
|
+
* Execute the workflow with graph-based flow control
|
|
2376
|
+
* Context is required for execution tracking, logging, and organization isolation
|
|
2377
|
+
* @returns Validated output matching contract.outputSchema, or null if no output schema
|
|
2378
|
+
*/
|
|
2379
|
+
async execute(input, context) {
|
|
2380
|
+
logWorkflowStart(context, this.config.resourceId, this.config.name);
|
|
2381
|
+
try {
|
|
2382
|
+
const validated = this.contract.inputSchema.parse(input);
|
|
2383
|
+
const visited = /* @__PURE__ */ new Set();
|
|
2384
|
+
const executionPath = [];
|
|
2385
|
+
let currentData = validated;
|
|
2386
|
+
let currentStepId = this.entryPoint;
|
|
2387
|
+
while (currentStepId !== null) {
|
|
2388
|
+
detectCycle(visited, executionPath, currentStepId);
|
|
2389
|
+
visited.add(currentStepId);
|
|
2390
|
+
executionPath.push(currentStepId);
|
|
2391
|
+
const step = this.steps[currentStepId];
|
|
2392
|
+
if (!step) {
|
|
2393
|
+
throw new WorkflowStepError(`Step '${currentStepId}' not found in workflow`, {
|
|
2394
|
+
stepId: currentStepId,
|
|
2395
|
+
workflowId: this.config.resourceId,
|
|
2396
|
+
executionId: context.executionId,
|
|
2397
|
+
organizationId: context.organizationId,
|
|
2398
|
+
executionPath
|
|
2399
|
+
});
|
|
2400
|
+
}
|
|
2401
|
+
const stepStartTime = Date.now();
|
|
2402
|
+
logStepStart(context, step.id, step.name, currentData, stepStartTime);
|
|
2403
|
+
try {
|
|
2404
|
+
const validatedInput = step.inputSchema.parse(currentData);
|
|
2405
|
+
const rawOutput = await step.handler(validatedInput, context);
|
|
2406
|
+
currentData = step.outputSchema.parse(rawOutput);
|
|
2407
|
+
if (step.next === null && this.shouldGenerateOutput) {
|
|
2408
|
+
validateTerminalOutput(step.id, currentData, this.contract.outputSchema);
|
|
2409
|
+
}
|
|
2410
|
+
const stepEndTime = Date.now();
|
|
2411
|
+
const duration = stepEndTime - stepStartTime;
|
|
2412
|
+
logStepSuccess(
|
|
2413
|
+
context,
|
|
2414
|
+
step.id,
|
|
2415
|
+
step.name,
|
|
2416
|
+
currentData,
|
|
2417
|
+
duration,
|
|
2418
|
+
step.next === null,
|
|
2419
|
+
stepStartTime,
|
|
2420
|
+
stepEndTime
|
|
2421
|
+
);
|
|
2422
|
+
currentStepId = await determineNextStep(step, currentData, context);
|
|
2423
|
+
} catch (error) {
|
|
2424
|
+
const stepEndTime = Date.now();
|
|
2425
|
+
const duration = stepEndTime - stepStartTime;
|
|
2426
|
+
logStepFailure(context, step.id, step.name, error, duration, stepStartTime, stepEndTime);
|
|
2427
|
+
throw new WorkflowStepError(`Step failed [${step.id}:${step.name}]: ${errorToString(error)}`, {
|
|
2428
|
+
stepId: step.id,
|
|
2429
|
+
stepName: step.name,
|
|
2430
|
+
workflowId: this.config.resourceId,
|
|
2431
|
+
executionId: context.executionId,
|
|
2432
|
+
duration: stepEndTime - stepStartTime
|
|
2433
|
+
});
|
|
2434
|
+
}
|
|
2435
|
+
}
|
|
2436
|
+
logExecutionPath(context, executionPath);
|
|
2437
|
+
logWorkflowSuccess(context, this.config.resourceId, executionPath);
|
|
2438
|
+
if (!this.shouldGenerateOutput) {
|
|
2439
|
+
return null;
|
|
2440
|
+
}
|
|
2441
|
+
return currentData;
|
|
2442
|
+
} catch (error) {
|
|
2443
|
+
logWorkflowFailure(context, this.config.resourceId, error);
|
|
2444
|
+
throw error;
|
|
2445
|
+
}
|
|
2446
|
+
}
|
|
2447
|
+
};
|
|
2448
|
+
|
|
2124
2449
|
// ../core/src/execution/engine/agent/observability/logging.ts
|
|
2125
2450
|
function createAgentLogger(logger, agentId, sessionId) {
|
|
2126
2451
|
return {
|
|
@@ -3624,8 +3949,8 @@ async function processMemory(memoryManager, response, logger, iteration) {
|
|
|
3624
3949
|
continue;
|
|
3625
3950
|
}
|
|
3626
3951
|
const startTime = Date.now();
|
|
3627
|
-
const
|
|
3628
|
-
memoryManager.set(key,
|
|
3952
|
+
const stringValue = typeof content === "string" ? content : JSON.stringify(content);
|
|
3953
|
+
memoryManager.set(key, stringValue);
|
|
3629
3954
|
const endTime = Date.now();
|
|
3630
3955
|
logger.action("memory-set", `Set: ${key}`, iteration, startTime, endTime, endTime - startTime);
|
|
3631
3956
|
}
|
|
@@ -4690,7 +5015,7 @@ var LabelSchema = z.string().trim().min(1).max(120);
|
|
|
4690
5015
|
var DescriptionSchema = z.string().trim().min(1).max(2e3);
|
|
4691
5016
|
var ColorTokenSchema = z.string().trim().min(1).max(50);
|
|
4692
5017
|
var IconNameSchema = OrganizationModelIconTokenSchema;
|
|
4693
|
-
|
|
5018
|
+
z.string().trim().startsWith("/").max(300);
|
|
4694
5019
|
var ReferenceIdsSchema = z.array(ModelIdSchema).default([]);
|
|
4695
5020
|
var DisplayMetadataSchema = z.object({
|
|
4696
5021
|
label: LabelSchema,
|
|
@@ -4729,191 +5054,6 @@ DisplayMetadataSchema.extend({
|
|
|
4729
5054
|
techStack: TechStackEntrySchema.optional()
|
|
4730
5055
|
});
|
|
4731
5056
|
|
|
4732
|
-
// ../core/src/organization-model/domains/entities.ts
|
|
4733
|
-
var EntityIdSchema = ModelIdSchema;
|
|
4734
|
-
var EntityLinkKindSchema = z.enum(["belongs-to", "has-many", "has-one", "many-to-many"]).meta({ label: "Link kind" });
|
|
4735
|
-
var EntityLinkSchema = z.object({
|
|
4736
|
-
toEntity: EntityIdSchema.meta({ ref: "entity" }),
|
|
4737
|
-
kind: EntityLinkKindSchema,
|
|
4738
|
-
via: z.string().trim().min(1).max(255).optional(),
|
|
4739
|
-
label: LabelSchema.optional()
|
|
4740
|
-
});
|
|
4741
|
-
var EntitySchema = z.object({
|
|
4742
|
-
id: EntityIdSchema,
|
|
4743
|
-
/** Domain-map iteration order. Convention: multiples of 10 (10, 20, 30, ...) to allow easy insertion. */
|
|
4744
|
-
order: z.number(),
|
|
4745
|
-
label: LabelSchema,
|
|
4746
|
-
description: DescriptionSchema.optional(),
|
|
4747
|
-
ownedBySystemId: ModelIdSchema.meta({ ref: "system" }),
|
|
4748
|
-
table: z.string().trim().min(1).max(255).optional(),
|
|
4749
|
-
rowSchema: ModelIdSchema.optional(),
|
|
4750
|
-
stateCatalogId: ModelIdSchema.optional(),
|
|
4751
|
-
links: z.array(EntityLinkSchema).optional()
|
|
4752
|
-
});
|
|
4753
|
-
var EntitiesDomainSchema = z.record(z.string(), EntitySchema).refine((record) => Object.entries(record).every(([key, entry]) => entry.id === key), {
|
|
4754
|
-
message: "Each entity entry id must match its map key"
|
|
4755
|
-
}).default({});
|
|
4756
|
-
var ENTITY_ENTRY_INPUTS = [
|
|
4757
|
-
{
|
|
4758
|
-
id: "crm.deal",
|
|
4759
|
-
order: 10,
|
|
4760
|
-
label: "Deal",
|
|
4761
|
-
description: "A CRM opportunity or sales pipeline record.",
|
|
4762
|
-
ownedBySystemId: "sales.crm",
|
|
4763
|
-
table: "crm_deals",
|
|
4764
|
-
stateCatalogId: "crm.pipeline",
|
|
4765
|
-
links: [{ toEntity: "crm.contact", kind: "has-many", via: "deal_contacts", label: "contacts" }]
|
|
4766
|
-
},
|
|
4767
|
-
{
|
|
4768
|
-
id: "crm.contact",
|
|
4769
|
-
order: 20,
|
|
4770
|
-
label: "CRM Contact",
|
|
4771
|
-
description: "A person associated with a CRM relationship or deal.",
|
|
4772
|
-
ownedBySystemId: "sales.crm",
|
|
4773
|
-
table: "crm_contacts"
|
|
4774
|
-
},
|
|
4775
|
-
{
|
|
4776
|
-
id: "leadgen.list",
|
|
4777
|
-
order: 30,
|
|
4778
|
-
label: "Lead List",
|
|
4779
|
-
description: "A prospecting list that groups companies and contacts for acquisition workflows.",
|
|
4780
|
-
ownedBySystemId: "sales.lead-gen",
|
|
4781
|
-
table: "acq_lists",
|
|
4782
|
-
links: [
|
|
4783
|
-
{ toEntity: "leadgen.company", kind: "has-many", via: "acq_list_companies", label: "companies" },
|
|
4784
|
-
{ toEntity: "leadgen.contact", kind: "has-many", via: "acq_list_members", label: "contacts" }
|
|
4785
|
-
]
|
|
4786
|
-
},
|
|
4787
|
-
{
|
|
4788
|
-
id: "leadgen.company",
|
|
4789
|
-
order: 40,
|
|
4790
|
-
label: "Lead Company",
|
|
4791
|
-
description: "A company record sourced, enriched, and qualified during prospecting.",
|
|
4792
|
-
ownedBySystemId: "sales.lead-gen",
|
|
4793
|
-
table: "acq_list_companies",
|
|
4794
|
-
stateCatalogId: "lead-gen.company",
|
|
4795
|
-
links: [
|
|
4796
|
-
{ toEntity: "leadgen.list", kind: "belongs-to", via: "list_id", label: "list" },
|
|
4797
|
-
{ toEntity: "leadgen.contact", kind: "has-many", via: "company_id", label: "contacts" }
|
|
4798
|
-
]
|
|
4799
|
-
},
|
|
4800
|
-
{
|
|
4801
|
-
id: "leadgen.contact",
|
|
4802
|
-
order: 50,
|
|
4803
|
-
label: "Lead Contact",
|
|
4804
|
-
description: "A prospect contact discovered or enriched during lead generation.",
|
|
4805
|
-
ownedBySystemId: "sales.lead-gen",
|
|
4806
|
-
table: "acq_list_members",
|
|
4807
|
-
stateCatalogId: "lead-gen.contact",
|
|
4808
|
-
links: [
|
|
4809
|
-
{ toEntity: "leadgen.list", kind: "belongs-to", via: "list_id", label: "list" },
|
|
4810
|
-
{ toEntity: "leadgen.company", kind: "belongs-to", via: "company_id", label: "company" }
|
|
4811
|
-
]
|
|
4812
|
-
},
|
|
4813
|
-
{
|
|
4814
|
-
id: "delivery.project",
|
|
4815
|
-
order: 60,
|
|
4816
|
-
label: "Project",
|
|
4817
|
-
description: "A client delivery project.",
|
|
4818
|
-
ownedBySystemId: "projects",
|
|
4819
|
-
table: "projects",
|
|
4820
|
-
links: [
|
|
4821
|
-
{ toEntity: "delivery.milestone", kind: "has-many", via: "project_id", label: "milestones" },
|
|
4822
|
-
{ toEntity: "delivery.task", kind: "has-many", via: "project_id", label: "tasks" }
|
|
4823
|
-
]
|
|
4824
|
-
},
|
|
4825
|
-
{
|
|
4826
|
-
id: "delivery.milestone",
|
|
4827
|
-
order: 70,
|
|
4828
|
-
label: "Milestone",
|
|
4829
|
-
description: "A delivery checkpoint within a project.",
|
|
4830
|
-
ownedBySystemId: "projects",
|
|
4831
|
-
table: "project_milestones",
|
|
4832
|
-
links: [
|
|
4833
|
-
{ toEntity: "delivery.project", kind: "belongs-to", via: "project_id", label: "project" },
|
|
4834
|
-
{ toEntity: "delivery.task", kind: "has-many", via: "milestone_id", label: "tasks" }
|
|
4835
|
-
]
|
|
4836
|
-
},
|
|
4837
|
-
{
|
|
4838
|
-
id: "delivery.task",
|
|
4839
|
-
order: 80,
|
|
4840
|
-
label: "Task",
|
|
4841
|
-
description: "A delivery task that can move through the task status catalog.",
|
|
4842
|
-
ownedBySystemId: "projects",
|
|
4843
|
-
table: "project_tasks",
|
|
4844
|
-
stateCatalogId: "delivery.task",
|
|
4845
|
-
links: [
|
|
4846
|
-
{ toEntity: "delivery.project", kind: "belongs-to", via: "project_id", label: "project" },
|
|
4847
|
-
{ toEntity: "delivery.milestone", kind: "belongs-to", via: "milestone_id", label: "milestone" }
|
|
4848
|
-
]
|
|
4849
|
-
}
|
|
4850
|
-
];
|
|
4851
|
-
var DEFAULT_ORGANIZATION_MODEL_ENTITIES = Object.fromEntries(
|
|
4852
|
-
ENTITY_ENTRY_INPUTS.map((entity) => {
|
|
4853
|
-
const parsed = EntitySchema.parse(entity);
|
|
4854
|
-
return [parsed.id, parsed];
|
|
4855
|
-
})
|
|
4856
|
-
);
|
|
4857
|
-
|
|
4858
|
-
// ../core/src/organization-model/domains/actions.ts
|
|
4859
|
-
var ActionResourceIdSchema = z.string().trim().min(1).max(255).regex(/^[A-Za-z0-9]+(?:[-._][A-Za-z0-9]+)*$/, "Resource IDs must use letters, numbers, -, _, or . separators");
|
|
4860
|
-
z.enum(["slash-command", "mcp-tool", "api-endpoint", "script-execution"]).meta({ label: "Invocation kind" });
|
|
4861
|
-
var ActionIdSchema = ModelIdSchema;
|
|
4862
|
-
var ActionScopeSchema = z.union([
|
|
4863
|
-
z.literal("global"),
|
|
4864
|
-
z.object({
|
|
4865
|
-
domain: ModelIdSchema
|
|
4866
|
-
})
|
|
4867
|
-
]);
|
|
4868
|
-
var ActionRefSchema = z.object({
|
|
4869
|
-
actionId: ActionIdSchema.meta({ ref: "action" }),
|
|
4870
|
-
intent: z.enum(["exposes", "consumes"]).meta({ label: "Intent" })
|
|
4871
|
-
});
|
|
4872
|
-
var SlashCommandInvocationSchema = z.object({
|
|
4873
|
-
kind: z.literal("slash-command"),
|
|
4874
|
-
command: z.string().trim().min(1).max(200).regex(/^\/[^\s].*$/, "Slash commands must start with /"),
|
|
4875
|
-
toolFactory: ModelIdSchema.optional()
|
|
4876
|
-
});
|
|
4877
|
-
var McpToolInvocationSchema = z.object({
|
|
4878
|
-
kind: z.literal("mcp-tool"),
|
|
4879
|
-
server: ModelIdSchema,
|
|
4880
|
-
name: ModelIdSchema
|
|
4881
|
-
});
|
|
4882
|
-
var ApiEndpointInvocationSchema = z.object({
|
|
4883
|
-
kind: z.literal("api-endpoint"),
|
|
4884
|
-
method: z.enum(["GET", "POST", "PATCH", "DELETE"]).meta({ label: "HTTP method" }),
|
|
4885
|
-
path: z.string().trim().startsWith("/").max(500),
|
|
4886
|
-
requestSchema: ModelIdSchema.optional(),
|
|
4887
|
-
responseSchema: ModelIdSchema.optional()
|
|
4888
|
-
});
|
|
4889
|
-
var ScriptExecutionInvocationSchema = z.object({
|
|
4890
|
-
kind: z.literal("script-execution"),
|
|
4891
|
-
resourceId: ActionResourceIdSchema
|
|
4892
|
-
});
|
|
4893
|
-
var ActionInvocationSchema = z.discriminatedUnion("kind", [
|
|
4894
|
-
SlashCommandInvocationSchema,
|
|
4895
|
-
McpToolInvocationSchema,
|
|
4896
|
-
ApiEndpointInvocationSchema,
|
|
4897
|
-
ScriptExecutionInvocationSchema
|
|
4898
|
-
]);
|
|
4899
|
-
var ActionSchema = z.object({
|
|
4900
|
-
id: ActionIdSchema,
|
|
4901
|
-
/** Domain-map iteration order. Convention: multiples of 10 (10, 20, 30, ...) to allow easy insertion. */
|
|
4902
|
-
order: z.number(),
|
|
4903
|
-
label: LabelSchema,
|
|
4904
|
-
description: DescriptionSchema.optional(),
|
|
4905
|
-
scope: ActionScopeSchema.default("global"),
|
|
4906
|
-
resourceId: ActionResourceIdSchema.optional(),
|
|
4907
|
-
affects: z.array(EntityIdSchema.meta({ ref: "entity" })).optional(),
|
|
4908
|
-
invocations: z.array(ActionInvocationSchema).default([]),
|
|
4909
|
-
knowledge: z.array(ModelIdSchema.meta({ ref: "knowledge" })).default([]).optional(),
|
|
4910
|
-
lifecycle: z.enum(["draft", "beta", "active", "deprecated", "archived"]).meta({ label: "Lifecycle", color: "teal" }).default("active")
|
|
4911
|
-
});
|
|
4912
|
-
var ActionsDomainSchema = z.record(z.string(), ActionSchema).refine((record) => Object.entries(record).every(([key, entry]) => entry.id === key), {
|
|
4913
|
-
message: "Each action entry id must match its map key"
|
|
4914
|
-
}).default({});
|
|
4915
|
-
var DEFAULT_ORGANIZATION_MODEL_ACTIONS = {};
|
|
4916
|
-
|
|
4917
5057
|
// ../core/src/organization-model/domains/prospecting.ts
|
|
4918
5058
|
DisplayMetadataSchema.extend({
|
|
4919
5059
|
id: ModelIdSchema,
|
|
@@ -4966,2484 +5106,28 @@ DisplayMetadataSchema.extend({
|
|
|
4966
5106
|
id: ModelIdSchema,
|
|
4967
5107
|
steps: z.array(ProspectingBuildTemplateStepSchema).min(1)
|
|
4968
5108
|
});
|
|
4969
|
-
var DTC_RECORD_COLUMNS = {
|
|
4970
|
-
populated: {
|
|
4971
|
-
company: [
|
|
4972
|
-
{ key: "name", label: "Company", path: "company.name" },
|
|
4973
|
-
{ key: "domain", label: "Domain", path: "company.domain" },
|
|
4974
|
-
{ key: "employee-count", label: "Employees", path: "company.numEmployees", renderType: "count" },
|
|
4975
|
-
{ key: "apollo-industry", label: "Apollo industry", path: "company.category" },
|
|
4976
|
-
{ key: "location", label: "Location", path: "company.locationState" }
|
|
4977
|
-
]
|
|
4978
|
-
},
|
|
4979
|
-
crawled: {
|
|
4980
|
-
company: [
|
|
4981
|
-
{ key: "name", label: "Company", path: "company.name" },
|
|
4982
|
-
{ key: "domain", label: "Domain", path: "company.domain" },
|
|
4983
|
-
{ key: "page-count", label: "Pages", path: "company.enrichmentData.websiteCrawl.pageCount", renderType: "count" },
|
|
4984
|
-
{ key: "crawl-status", label: "Crawl status", path: "processingState.crawled.status", renderType: "badge" }
|
|
4985
|
-
]
|
|
4986
|
-
},
|
|
4987
|
-
extracted: {
|
|
4988
|
-
company: [
|
|
4989
|
-
{ key: "name", label: "Company", path: "company.name" },
|
|
4990
|
-
{ key: "domain", label: "Domain", path: "company.domain" },
|
|
4991
|
-
{ key: "description", label: "Description", path: "company.enrichmentData.websiteCrawl.companyDescription" },
|
|
4992
|
-
{ key: "services", label: "Services", path: "company.enrichmentData.websiteCrawl.services", renderType: "json" },
|
|
4993
|
-
{
|
|
4994
|
-
key: "automation-gaps",
|
|
4995
|
-
label: "Automation gaps",
|
|
4996
|
-
path: "company.enrichmentData.websiteCrawl.automationGaps",
|
|
4997
|
-
renderType: "json"
|
|
4998
|
-
},
|
|
4999
|
-
{
|
|
5000
|
-
key: "contact-count",
|
|
5001
|
-
label: "Contacts",
|
|
5002
|
-
path: "company.enrichmentData.websiteCrawl.emailCount",
|
|
5003
|
-
renderType: "count"
|
|
5004
|
-
}
|
|
5005
|
-
]
|
|
5006
|
-
},
|
|
5007
|
-
qualified: {
|
|
5008
|
-
company: [
|
|
5009
|
-
{ key: "name", label: "Company", path: "company.name" },
|
|
5010
|
-
{ key: "domain", label: "Domain", path: "company.domain" },
|
|
5011
|
-
{ key: "score", label: "Score", path: "company.qualificationScore", renderType: "badge", badgeColor: "green" },
|
|
5012
|
-
{ key: "signals", label: "Signals", path: "company.qualificationSignals", renderType: "json" },
|
|
5013
|
-
{
|
|
5014
|
-
key: "disqualified-reason",
|
|
5015
|
-
label: "Disqualified reason",
|
|
5016
|
-
path: "processingState.qualified.data.disqualifiedReason"
|
|
5017
|
-
}
|
|
5018
|
-
]
|
|
5019
|
-
},
|
|
5020
|
-
decisionMakers: {
|
|
5021
|
-
contact: [
|
|
5022
|
-
{ key: "name", label: "Name", path: "contact.name" },
|
|
5023
|
-
{ key: "title", label: "Title", path: "contact.title" },
|
|
5024
|
-
{ key: "email", label: "Email", path: "contact.email" },
|
|
5025
|
-
{ key: "linkedin", label: "LinkedIn", path: "contact.linkedinUrl" },
|
|
5026
|
-
{
|
|
5027
|
-
key: "priority-score",
|
|
5028
|
-
label: "Priority",
|
|
5029
|
-
path: "contact.enrichmentData.apollo.priorityScore",
|
|
5030
|
-
renderType: "badge"
|
|
5031
|
-
}
|
|
5032
|
-
]
|
|
5033
|
-
},
|
|
5034
|
-
uploaded: {
|
|
5035
|
-
company: [
|
|
5036
|
-
{ key: "name", label: "Company", path: "company.name" },
|
|
5037
|
-
{ key: "domain", label: "Domain", path: "company.domain" },
|
|
5038
|
-
{
|
|
5039
|
-
key: "contacts",
|
|
5040
|
-
label: "Contacts",
|
|
5041
|
-
path: "company.enrichmentData.approvedLeadListExport.contacts",
|
|
5042
|
-
renderType: "json"
|
|
5043
|
-
},
|
|
5044
|
-
{ key: "score", label: "Score", path: "company.qualificationScore", renderType: "badge", badgeColor: "green" },
|
|
5045
|
-
{
|
|
5046
|
-
key: "approval",
|
|
5047
|
-
label: "Approval",
|
|
5048
|
-
path: "company.enrichmentData.approvedLeadListExport.approvalStatus",
|
|
5049
|
-
renderType: "badge"
|
|
5050
|
-
}
|
|
5051
|
-
]
|
|
5052
|
-
}
|
|
5053
|
-
};
|
|
5054
|
-
var PROSPECTING_STEPS = {
|
|
5055
|
-
localServices: {
|
|
5056
|
-
sourceCompanies: {
|
|
5057
|
-
id: "source-companies",
|
|
5058
|
-
label: "Companies found",
|
|
5059
|
-
primaryEntity: "company",
|
|
5060
|
-
outputs: ["company"],
|
|
5061
|
-
stageKey: "populated",
|
|
5062
|
-
dependencyMode: "per-record-eligibility",
|
|
5063
|
-
actionKey: "lead-gen.company.source",
|
|
5064
|
-
defaultBatchSize: 100,
|
|
5065
|
-
maxBatchSize: 250
|
|
5066
|
-
},
|
|
5067
|
-
analyzeWebsites: {
|
|
5068
|
-
id: "analyze-websites",
|
|
5069
|
-
label: "Websites analyzed",
|
|
5070
|
-
primaryEntity: "company",
|
|
5071
|
-
outputs: ["company"],
|
|
5072
|
-
stageKey: "extracted",
|
|
5073
|
-
dependsOn: ["source-companies"],
|
|
5074
|
-
dependencyMode: "per-record-eligibility",
|
|
5075
|
-
actionKey: "lead-gen.company.website-extract",
|
|
5076
|
-
defaultBatchSize: 50,
|
|
5077
|
-
maxBatchSize: 100
|
|
5078
|
-
},
|
|
5079
|
-
qualifyCompanies: {
|
|
5080
|
-
id: "qualify-companies",
|
|
5081
|
-
label: "Companies qualified",
|
|
5082
|
-
primaryEntity: "company",
|
|
5083
|
-
outputs: ["company"],
|
|
5084
|
-
stageKey: "qualified",
|
|
5085
|
-
dependsOn: ["analyze-websites"],
|
|
5086
|
-
dependencyMode: "per-record-eligibility",
|
|
5087
|
-
actionKey: "lead-gen.company.qualify",
|
|
5088
|
-
defaultBatchSize: 100,
|
|
5089
|
-
maxBatchSize: 250
|
|
5090
|
-
},
|
|
5091
|
-
findContacts: {
|
|
5092
|
-
id: "find-contacts",
|
|
5093
|
-
label: "Decision-makers found",
|
|
5094
|
-
primaryEntity: "contact",
|
|
5095
|
-
outputs: ["contact"],
|
|
5096
|
-
stageKey: "discovered",
|
|
5097
|
-
dependsOn: ["qualify-companies"],
|
|
5098
|
-
dependencyMode: "per-record-eligibility",
|
|
5099
|
-
actionKey: "lead-gen.contact.discover",
|
|
5100
|
-
defaultBatchSize: 50,
|
|
5101
|
-
maxBatchSize: 100
|
|
5102
|
-
},
|
|
5103
|
-
verifyEmails: {
|
|
5104
|
-
id: "verify-emails",
|
|
5105
|
-
label: "Emails verified",
|
|
5106
|
-
primaryEntity: "contact",
|
|
5107
|
-
outputs: ["contact"],
|
|
5108
|
-
stageKey: "verified",
|
|
5109
|
-
dependsOn: ["find-contacts"],
|
|
5110
|
-
dependencyMode: "per-record-eligibility",
|
|
5111
|
-
actionKey: "lead-gen.contact.verify-email",
|
|
5112
|
-
defaultBatchSize: 100,
|
|
5113
|
-
maxBatchSize: 500
|
|
5114
|
-
},
|
|
5115
|
-
personalize: {
|
|
5116
|
-
id: "personalize",
|
|
5117
|
-
label: "Personalize",
|
|
5118
|
-
primaryEntity: "contact",
|
|
5119
|
-
outputs: ["contact"],
|
|
5120
|
-
stageKey: "personalized",
|
|
5121
|
-
dependsOn: ["verify-emails"],
|
|
5122
|
-
dependencyMode: "per-record-eligibility",
|
|
5123
|
-
actionKey: "lead-gen.contact.personalize",
|
|
5124
|
-
defaultBatchSize: 25,
|
|
5125
|
-
maxBatchSize: 100
|
|
5126
|
-
},
|
|
5127
|
-
review: {
|
|
5128
|
-
id: "review",
|
|
5129
|
-
label: "Reviewed and exported",
|
|
5130
|
-
primaryEntity: "contact",
|
|
5131
|
-
outputs: ["export"],
|
|
5132
|
-
stageKey: "uploaded",
|
|
5133
|
-
dependsOn: ["personalize"],
|
|
5134
|
-
dependencyMode: "per-record-eligibility",
|
|
5135
|
-
actionKey: "lead-gen.review.outreach-ready",
|
|
5136
|
-
defaultBatchSize: 25,
|
|
5137
|
-
maxBatchSize: 100
|
|
5138
|
-
}
|
|
5139
|
-
},
|
|
5140
|
-
dtcApolloClickup: {
|
|
5141
|
-
importApolloSearch: {
|
|
5142
|
-
id: "import-apollo-search",
|
|
5143
|
-
label: "Companies found",
|
|
5144
|
-
description: "Pull companies and seed contact data from a predefined Apollo search or list.",
|
|
5145
|
-
primaryEntity: "company",
|
|
5146
|
-
outputs: ["company", "contact"],
|
|
5147
|
-
stageKey: "populated",
|
|
5148
|
-
dependencyMode: "per-record-eligibility",
|
|
5149
|
-
actionKey: "lead-gen.company.apollo-import",
|
|
5150
|
-
defaultBatchSize: 250,
|
|
5151
|
-
maxBatchSize: 1e3,
|
|
5152
|
-
recordColumns: DTC_RECORD_COLUMNS.populated,
|
|
5153
|
-
credentialRequirements: [
|
|
5154
|
-
{
|
|
5155
|
-
key: "apollo",
|
|
5156
|
-
provider: "apollo",
|
|
5157
|
-
credentialType: "api-key-secret",
|
|
5158
|
-
label: "Apollo API key",
|
|
5159
|
-
required: true,
|
|
5160
|
-
selectionMode: "single",
|
|
5161
|
-
inputPath: "credential"
|
|
5162
|
-
}
|
|
5163
|
-
]
|
|
5164
|
-
},
|
|
5165
|
-
apifyCrawl: {
|
|
5166
|
-
id: "apify-crawl",
|
|
5167
|
-
label: "Websites crawled",
|
|
5168
|
-
description: "Crawl company websites via Apify and store raw page markdown in enrichmentData.websiteCrawl.pages for downstream LLM analysis. Overwrites the synthetic seed Apollo Import wrote with real page content.",
|
|
5169
|
-
primaryEntity: "company",
|
|
5170
|
-
outputs: ["company"],
|
|
5171
|
-
stageKey: "crawled",
|
|
5172
|
-
dependsOn: ["import-apollo-search"],
|
|
5173
|
-
dependencyMode: "per-record-eligibility",
|
|
5174
|
-
actionKey: "lead-gen.company.apify-crawl",
|
|
5175
|
-
defaultBatchSize: 50,
|
|
5176
|
-
maxBatchSize: 100,
|
|
5177
|
-
recordColumns: DTC_RECORD_COLUMNS.crawled,
|
|
5178
|
-
credentialRequirements: [
|
|
5179
|
-
{
|
|
5180
|
-
key: "apify",
|
|
5181
|
-
provider: "apify",
|
|
5182
|
-
credentialType: "api-key-secret",
|
|
5183
|
-
label: "Apify API token",
|
|
5184
|
-
required: true,
|
|
5185
|
-
selectionMode: "single",
|
|
5186
|
-
inputPath: "credential",
|
|
5187
|
-
verifyOnRun: true
|
|
5188
|
-
}
|
|
5189
|
-
]
|
|
5190
|
-
},
|
|
5191
|
-
analyzeWebsites: {
|
|
5192
|
-
id: "analyze-websites",
|
|
5193
|
-
label: "Websites analyzed",
|
|
5194
|
-
description: "Extract subscription, product, retention, and tech-stack signals from each brand website.",
|
|
5195
|
-
primaryEntity: "company",
|
|
5196
|
-
outputs: ["company"],
|
|
5197
|
-
stageKey: "extracted",
|
|
5198
|
-
dependsOn: ["apify-crawl"],
|
|
5199
|
-
dependencyMode: "per-record-eligibility",
|
|
5200
|
-
actionKey: "lead-gen.company.website-extract",
|
|
5201
|
-
defaultBatchSize: 50,
|
|
5202
|
-
maxBatchSize: 100,
|
|
5203
|
-
recordColumns: DTC_RECORD_COLUMNS.extracted
|
|
5204
|
-
},
|
|
5205
|
-
scoreDtcFit: {
|
|
5206
|
-
id: "score-dtc-fit",
|
|
5207
|
-
label: "Companies qualified",
|
|
5208
|
-
description: "Classify subscription potential, consumable-product fit, retention maturity, and disqualifiers.",
|
|
5209
|
-
primaryEntity: "company",
|
|
5210
|
-
outputs: ["company"],
|
|
5211
|
-
stageKey: "qualified",
|
|
5212
|
-
dependsOn: ["analyze-websites"],
|
|
5213
|
-
dependencyMode: "per-record-eligibility",
|
|
5214
|
-
actionKey: "lead-gen.company.dtc-subscription-qualify",
|
|
5215
|
-
defaultBatchSize: 100,
|
|
5216
|
-
maxBatchSize: 250,
|
|
5217
|
-
recordColumns: DTC_RECORD_COLUMNS.qualified
|
|
5218
|
-
},
|
|
5219
|
-
enrichDecisionMakers: {
|
|
5220
|
-
id: "enrich-decision-makers",
|
|
5221
|
-
label: "Decision-makers found",
|
|
5222
|
-
description: "Use Apollo to find qualified contacts at qualified companies - founders, retention leads, lifecycle leads, and marketing owners.",
|
|
5223
|
-
primaryEntity: "company",
|
|
5224
|
-
outputs: ["contact"],
|
|
5225
|
-
stageKey: "decision-makers-enriched",
|
|
5226
|
-
recordEntity: "contact",
|
|
5227
|
-
dependsOn: ["score-dtc-fit"],
|
|
5228
|
-
dependencyMode: "per-record-eligibility",
|
|
5229
|
-
actionKey: "lead-gen.contact.apollo-decision-maker-enrich",
|
|
5230
|
-
defaultBatchSize: 100,
|
|
5231
|
-
maxBatchSize: 250,
|
|
5232
|
-
recordColumns: DTC_RECORD_COLUMNS.decisionMakers,
|
|
5233
|
-
credentialRequirements: [
|
|
5234
|
-
{
|
|
5235
|
-
key: "apollo",
|
|
5236
|
-
provider: "apollo",
|
|
5237
|
-
credentialType: "api-key-secret",
|
|
5238
|
-
label: "Apollo API key",
|
|
5239
|
-
required: true,
|
|
5240
|
-
selectionMode: "single",
|
|
5241
|
-
inputPath: "credential"
|
|
5242
|
-
}
|
|
5243
|
-
]
|
|
5244
|
-
},
|
|
5245
|
-
reviewAndExport: {
|
|
5246
|
-
id: "review-and-export",
|
|
5247
|
-
label: "Reviewed and exported",
|
|
5248
|
-
description: "Operator QC approves or rejects qualified companies, then approved records are exported as a lead list with unverified emails.",
|
|
5249
|
-
primaryEntity: "company",
|
|
5250
|
-
outputs: ["export"],
|
|
5251
|
-
stageKey: "uploaded",
|
|
5252
|
-
recordsStageKey: "uploaded",
|
|
5253
|
-
recordSourceStageKey: "qualified",
|
|
5254
|
-
dependsOn: ["enrich-decision-makers"],
|
|
5255
|
-
dependencyMode: "per-record-eligibility",
|
|
5256
|
-
actionKey: "lead-gen.export.list",
|
|
5257
|
-
defaultBatchSize: 100,
|
|
5258
|
-
maxBatchSize: 250,
|
|
5259
|
-
recordColumns: DTC_RECORD_COLUMNS.uploaded,
|
|
5260
|
-
credentialRequirements: [
|
|
5261
|
-
{
|
|
5262
|
-
key: "clickup",
|
|
5263
|
-
provider: "clickup",
|
|
5264
|
-
credentialType: "api-key-secret",
|
|
5265
|
-
label: "ClickUp API token",
|
|
5266
|
-
required: true,
|
|
5267
|
-
selectionMode: "single",
|
|
5268
|
-
inputPath: "clickupCredential",
|
|
5269
|
-
verifyOnRun: true
|
|
5270
|
-
}
|
|
5271
|
-
]
|
|
5272
|
-
}
|
|
5273
|
-
}
|
|
5274
|
-
};
|
|
5275
5109
|
|
|
5276
|
-
// ../core/src/business/acquisition/
|
|
5277
|
-
var
|
|
5278
|
-
|
|
5279
|
-
|
|
5280
|
-
|
|
5281
|
-
|
|
5282
|
-
|
|
5283
|
-
|
|
5284
|
-
|
|
5285
|
-
|
|
5286
|
-
|
|
5287
|
-
|
|
5288
|
-
|
|
5289
|
-
|
|
5290
|
-
];
|
|
5291
|
-
|
|
5292
|
-
|
|
5293
|
-
label,
|
|
5294
|
-
description
|
|
5295
|
-
}));
|
|
5296
|
-
function isProspectingBuildTemplateId(value) {
|
|
5297
|
-
return PROSPECTING_BUILD_TEMPLATE_OPTIONS.some((template) => template.id === value);
|
|
5298
|
-
}
|
|
5299
|
-
var OrganizationModelBrandingSchema = z.object({
|
|
5300
|
-
organizationName: LabelSchema,
|
|
5301
|
-
productName: LabelSchema,
|
|
5302
|
-
shortName: z.string().trim().min(1).max(40),
|
|
5303
|
-
description: DescriptionSchema.optional(),
|
|
5304
|
-
logos: z.object({
|
|
5305
|
-
light: z.string().trim().min(1).max(2048).optional(),
|
|
5306
|
-
dark: z.string().trim().min(1).max(2048).optional()
|
|
5307
|
-
}).default({})
|
|
5110
|
+
// ../core/src/business/acquisition/api-schemas.ts
|
|
5111
|
+
var ProcessingStageStatusSchema = z.enum(["success", "no_result", "skipped", "error"]);
|
|
5112
|
+
var LeadGenStageKeySchema = z.string().trim().min(1);
|
|
5113
|
+
var LeadGenActionKeySchema = z.string().trim().min(1);
|
|
5114
|
+
var CrmStageKeySchema = z.string().trim().min(1);
|
|
5115
|
+
var CrmStateKeySchema = z.string().trim().min(1);
|
|
5116
|
+
var ProcessingStateEntrySchema = z.object({
|
|
5117
|
+
status: ProcessingStageStatusSchema,
|
|
5118
|
+
data: z.unknown().optional()
|
|
5119
|
+
}).passthrough();
|
|
5120
|
+
var ProcessingStateSchema = z.record(LeadGenStageKeySchema, ProcessingStateEntrySchema);
|
|
5121
|
+
var CompanyProcessingStateSchema = ProcessingStateSchema;
|
|
5122
|
+
var ContactProcessingStateSchema = ProcessingStateSchema;
|
|
5123
|
+
var DealStageSchema = CrmStageKeySchema;
|
|
5124
|
+
var AcqDealTaskKindSchema = z.enum(["call", "email", "meeting", "other"]);
|
|
5125
|
+
z.object({
|
|
5126
|
+
dealId: UuidSchema
|
|
5308
5127
|
});
|
|
5309
|
-
|
|
5310
|
-
|
|
5311
|
-
|
|
5312
|
-
shortName: "Elevasis",
|
|
5313
|
-
logos: {}
|
|
5314
|
-
};
|
|
5315
|
-
var BusinessHoursDaySchema = z.object({
|
|
5316
|
-
open: z.string().trim().regex(/^\d{2}:\d{2}$/, "Expected HH:MM format"),
|
|
5317
|
-
close: z.string().trim().regex(/^\d{2}:\d{2}$/, "Expected HH:MM format")
|
|
5318
|
-
});
|
|
5319
|
-
var BusinessHoursSchema = z.object({
|
|
5320
|
-
monday: BusinessHoursDaySchema.optional(),
|
|
5321
|
-
tuesday: BusinessHoursDaySchema.optional(),
|
|
5322
|
-
wednesday: BusinessHoursDaySchema.optional(),
|
|
5323
|
-
thursday: BusinessHoursDaySchema.optional(),
|
|
5324
|
-
friday: BusinessHoursDaySchema.optional(),
|
|
5325
|
-
saturday: BusinessHoursDaySchema.optional(),
|
|
5326
|
-
sunday: BusinessHoursDaySchema.optional()
|
|
5327
|
-
}).default({});
|
|
5328
|
-
var IdentityDomainSchema = z.object({
|
|
5329
|
-
/** Why the organization exists — one or two plain-language sentences. */
|
|
5330
|
-
mission: z.string().trim().max(1e3).default(""),
|
|
5331
|
-
/** Long-term direction the organization is moving toward. */
|
|
5332
|
-
vision: z.string().trim().max(1e3).default(""),
|
|
5333
|
-
/** Legal registered name of the entity. */
|
|
5334
|
-
legalName: z.string().trim().max(200).default(""),
|
|
5335
|
-
/**
|
|
5336
|
-
* Type of legal entity (e.g. "LLC", "Corporation", "Sole Proprietor",
|
|
5337
|
-
* "Non-profit"). Free-form string so it covers any jurisdiction.
|
|
5338
|
-
*/
|
|
5339
|
-
entityType: z.string().trim().max(100).default(""),
|
|
5340
|
-
/**
|
|
5341
|
-
* Primary jurisdiction of registration or operation
|
|
5342
|
-
* (e.g. "United States – Delaware", "Canada – Ontario").
|
|
5343
|
-
*/
|
|
5344
|
-
jurisdiction: z.string().trim().max(200).default(""),
|
|
5345
|
-
/**
|
|
5346
|
-
* Industry category — broad classification (e.g. "Marketing Agency",
|
|
5347
|
-
* "Software / SaaS", "Professional Services").
|
|
5348
|
-
*/
|
|
5349
|
-
industryCategory: z.string().trim().max(200).default(""),
|
|
5350
|
-
/**
|
|
5351
|
-
* Geographic focus — where the organization primarily operates or serves
|
|
5352
|
-
* (e.g. "North America", "Global", "Southeast Asia").
|
|
5353
|
-
*/
|
|
5354
|
-
geographicFocus: z.string().trim().max(200).default(""),
|
|
5355
|
-
/**
|
|
5356
|
-
* IANA timezone identifier for the organization's primary operating timezone
|
|
5357
|
-
* (e.g. "America/Los_Angeles", "Europe/London", "UTC").
|
|
5358
|
-
*/
|
|
5359
|
-
timeZone: z.string().trim().max(100).default("UTC"),
|
|
5360
|
-
/** Typical operating hours per day of week. Empty object means not configured. */
|
|
5361
|
-
businessHours: BusinessHoursSchema,
|
|
5362
|
-
/**
|
|
5363
|
-
* Long-form markdown capturing client context, problem narrative, and domain
|
|
5364
|
-
* background. Populated by /setup; surfaced to agents as organizational context.
|
|
5365
|
-
* Optional — many projects have no external client.
|
|
5366
|
-
*/
|
|
5367
|
-
clientBrief: z.string().trim().default("")
|
|
5368
|
-
});
|
|
5369
|
-
var DEFAULT_ORGANIZATION_MODEL_IDENTITY = {
|
|
5370
|
-
mission: "",
|
|
5371
|
-
vision: "",
|
|
5372
|
-
legalName: "",
|
|
5373
|
-
entityType: "",
|
|
5374
|
-
jurisdiction: "",
|
|
5375
|
-
industryCategory: "",
|
|
5376
|
-
geographicFocus: "",
|
|
5377
|
-
timeZone: "UTC",
|
|
5378
|
-
businessHours: {},
|
|
5379
|
-
clientBrief: ""
|
|
5380
|
-
};
|
|
5381
|
-
var FirmographicsSchema = z.object({
|
|
5382
|
-
/** Industry vertical (e.g. "Marketing Agency", "Legal", "Real Estate"). */
|
|
5383
|
-
industry: z.string().trim().max(200).optional(),
|
|
5384
|
-
/**
|
|
5385
|
-
* Company headcount band (e.g. "1–10", "11–50", "51–200", "200+").
|
|
5386
|
-
* Free-form string to accommodate any band notation.
|
|
5387
|
-
*/
|
|
5388
|
-
companySize: z.string().trim().max(100).optional(),
|
|
5389
|
-
/**
|
|
5390
|
-
* Primary geographic region the segment operates in or is targeted from
|
|
5391
|
-
* (e.g. "North America", "Europe", "Global").
|
|
5392
|
-
*/
|
|
5393
|
-
region: z.string().trim().max(200).optional()
|
|
5394
|
-
});
|
|
5395
|
-
var CustomerSegmentSchema = z.object({
|
|
5396
|
-
/** Stable unique identifier for the segment (e.g. "segment-smb-agencies"). */
|
|
5397
|
-
id: z.string().trim().min(1).max(100),
|
|
5398
|
-
/** Domain-map iteration order. Convention: multiples of 10 (10, 20, 30, ...) to allow easy insertion. */
|
|
5399
|
-
order: z.number(),
|
|
5400
|
-
/** Human-readable name shown to agents and in UI (e.g. "SMB Marketing Agencies"). */
|
|
5401
|
-
name: z.string().trim().max(200).default(""),
|
|
5402
|
-
/** One or two sentences describing who this segment is. */
|
|
5403
|
-
description: z.string().trim().max(2e3).default(""),
|
|
5404
|
-
/**
|
|
5405
|
-
* The primary job(s) this segment is trying to get done — the goal they hire
|
|
5406
|
-
* a product/service to accomplish. Plain-language narrative or bullet list.
|
|
5407
|
-
*/
|
|
5408
|
-
jobsToBeDone: z.string().trim().max(2e3).default(""),
|
|
5409
|
-
/**
|
|
5410
|
-
* Pains — frustrations, obstacles, and risks the segment experiences
|
|
5411
|
-
* when trying to accomplish their jobs-to-be-done.
|
|
5412
|
-
*/
|
|
5413
|
-
pains: z.array(z.string().trim().max(500)).default([]),
|
|
5414
|
-
/**
|
|
5415
|
-
* Gains — outcomes and benefits the segment desires; positive motivators
|
|
5416
|
-
* beyond merely resolving pains.
|
|
5417
|
-
*/
|
|
5418
|
-
gains: z.array(z.string().trim().max(500)).default([]),
|
|
5419
|
-
/** Firmographic profile for targeting and filtering. */
|
|
5420
|
-
firmographics: FirmographicsSchema.default({}),
|
|
5421
|
-
/**
|
|
5422
|
-
* Value proposition — one or two sentences stating why this organization's
|
|
5423
|
-
* offering is uniquely suited for this segment's needs.
|
|
5424
|
-
*/
|
|
5425
|
-
valueProp: z.string().trim().max(2e3).default("")
|
|
5426
|
-
});
|
|
5427
|
-
var CustomersDomainSchema = z.record(z.string(), CustomerSegmentSchema).refine((record) => Object.entries(record).every(([key, entry]) => entry.id === key), {
|
|
5428
|
-
message: "Each segment entry id must match its map key"
|
|
5429
|
-
}).default({});
|
|
5430
|
-
var DEFAULT_ORGANIZATION_MODEL_CUSTOMERS = {};
|
|
5431
|
-
var PricingModelSchema = z.enum(["one-time", "subscription", "usage-based", "custom"]).meta({ label: "Pricing model", color: "green" });
|
|
5432
|
-
var ProductSchema = z.object({
|
|
5433
|
-
/** Stable unique identifier for the product (e.g. "product-starter-plan"). */
|
|
5434
|
-
id: z.string().trim().min(1).max(100),
|
|
5435
|
-
/** Domain-map iteration order. Convention: multiples of 10 (10, 20, 30, ...) to allow easy insertion. */
|
|
5436
|
-
order: z.number(),
|
|
5437
|
-
/** Human-readable name shown to agents and in UI (e.g. "Starter Plan"). */
|
|
5438
|
-
name: z.string().trim().max(200).default(""),
|
|
5439
|
-
/** One or two sentences describing what this product/service delivers. */
|
|
5440
|
-
description: z.string().trim().max(2e3).default(""),
|
|
5441
|
-
/**
|
|
5442
|
-
* How this product is priced:
|
|
5443
|
-
* - "one-time" — single purchase (setup fee, project fee)
|
|
5444
|
-
* - "subscription" — recurring (monthly/annual SaaS, retainer)
|
|
5445
|
-
* - "usage-based" — metered by consumption (API calls, seats)
|
|
5446
|
-
* - "custom" — negotiated or bespoke pricing
|
|
5447
|
-
*/
|
|
5448
|
-
pricingModel: PricingModelSchema.default("custom"),
|
|
5449
|
-
/** Base price amount (≥ 0). Currency unit defined by `currency`. */
|
|
5450
|
-
price: z.number().min(0).default(0),
|
|
5451
|
-
/**
|
|
5452
|
-
* ISO 4217 currency code (e.g. "USD", "EUR", "GBP").
|
|
5453
|
-
* Free-form string to accommodate any currency; defaults to "USD".
|
|
5454
|
-
*/
|
|
5455
|
-
currency: z.string().trim().max(10).default("USD"),
|
|
5456
|
-
/**
|
|
5457
|
-
* IDs of customer segments this product targets.
|
|
5458
|
-
* Each id must reference a declared `customers.segments[].id`.
|
|
5459
|
-
* Cross-reference enforced in `OrganizationModelSchema.superRefine()`.
|
|
5460
|
-
*/
|
|
5461
|
-
targetSegmentIds: z.array(z.string().trim().min(1)).default([]),
|
|
5462
|
-
/**
|
|
5463
|
-
* Optional: ID of the platform system responsible for delivering this product.
|
|
5464
|
-
* When present, must reference a declared `systems.systems[].id`.
|
|
5465
|
-
* Cross-reference enforced in `OrganizationModelSchema.superRefine()`.
|
|
5466
|
-
*/
|
|
5467
|
-
deliveryFeatureId: z.string().trim().min(1).optional()
|
|
5468
|
-
});
|
|
5469
|
-
var OfferingsDomainSchema = z.record(z.string(), ProductSchema).refine((record) => Object.entries(record).every(([key, entry]) => entry.id === key), {
|
|
5470
|
-
message: "Each product entry id must match its map key"
|
|
5471
|
-
}).default({});
|
|
5472
|
-
var DEFAULT_ORGANIZATION_MODEL_OFFERINGS = {};
|
|
5473
|
-
var OntologyKindSchema = z.enum([
|
|
5474
|
-
"object",
|
|
5475
|
-
"link",
|
|
5476
|
-
"action",
|
|
5477
|
-
"catalog",
|
|
5478
|
-
"event",
|
|
5479
|
-
"interface",
|
|
5480
|
-
"value-type",
|
|
5481
|
-
"property",
|
|
5482
|
-
"group",
|
|
5483
|
-
"surface"
|
|
5484
|
-
]);
|
|
5485
|
-
var SYSTEM_PATH_PATTERN = "[a-z0-9][a-z0-9-]*(?:\\.[a-z0-9][a-z0-9-]*)*";
|
|
5486
|
-
var LOCAL_ID_PATTERN = "[a-z0-9][a-z0-9._-]*";
|
|
5487
|
-
var ONTOLOGY_ID_PATTERN = `^(global|${SYSTEM_PATH_PATTERN}):(${OntologyKindSchema.options.join("|")})\\/(${LOCAL_ID_PATTERN})$`;
|
|
5488
|
-
var ONTOLOGY_ID_REGEX = new RegExp(ONTOLOGY_ID_PATTERN);
|
|
5489
|
-
var OntologyIdSchema = z.string().trim().min(1).max(300).regex(
|
|
5490
|
-
ONTOLOGY_ID_REGEX,
|
|
5491
|
-
"Ontology IDs must use <system-path>:<kind>/<local-id> or global:<kind>/<local-id>"
|
|
5492
|
-
);
|
|
5493
|
-
function parseOntologyId(id) {
|
|
5494
|
-
const normalized = OntologyIdSchema.parse(id);
|
|
5495
|
-
const match = ONTOLOGY_ID_REGEX.exec(normalized);
|
|
5496
|
-
if (match === null) {
|
|
5497
|
-
throw new Error(`Invalid ontology ID "${id}"`);
|
|
5498
|
-
}
|
|
5499
|
-
return {
|
|
5500
|
-
id: normalized,
|
|
5501
|
-
scope: match[1],
|
|
5502
|
-
kind: match[2],
|
|
5503
|
-
localId: match[3],
|
|
5504
|
-
isGlobal: match[1] === "global"
|
|
5505
|
-
};
|
|
5506
|
-
}
|
|
5507
|
-
function formatOntologyId(input) {
|
|
5508
|
-
return OntologyIdSchema.parse(`${input.scope}:${input.kind}/${input.localId}`);
|
|
5509
|
-
}
|
|
5510
|
-
var OntologyReferenceListSchema = z.array(OntologyIdSchema).default([]).optional();
|
|
5511
|
-
var OntologyRecordBaseSchema = z.object({
|
|
5512
|
-
id: OntologyIdSchema,
|
|
5513
|
-
label: z.string().trim().min(1).max(160).optional(),
|
|
5514
|
-
description: z.string().trim().min(1).max(2e3).optional(),
|
|
5515
|
-
ownerSystemId: z.string().trim().min(1).max(200).optional(),
|
|
5516
|
-
aliases: z.array(OntologyIdSchema).optional()
|
|
5517
|
-
}).passthrough();
|
|
5518
|
-
var OntologyObjectTypeSchema = OntologyRecordBaseSchema.extend({
|
|
5519
|
-
properties: z.record(z.string().trim().min(1).max(200), z.unknown()).optional(),
|
|
5520
|
-
storage: z.record(z.string(), z.unknown()).optional()
|
|
5521
|
-
});
|
|
5522
|
-
var OntologyLinkTypeSchema = OntologyRecordBaseSchema.extend({
|
|
5523
|
-
from: OntologyIdSchema,
|
|
5524
|
-
to: OntologyIdSchema,
|
|
5525
|
-
cardinality: z.string().trim().min(1).max(80).optional(),
|
|
5526
|
-
via: z.string().trim().min(1).max(255).optional()
|
|
5527
|
-
});
|
|
5528
|
-
var OntologyActionTypeSchema = OntologyRecordBaseSchema.extend({
|
|
5529
|
-
actsOn: OntologyReferenceListSchema,
|
|
5530
|
-
input: z.record(z.string().trim().min(1).max(200), z.unknown()).optional(),
|
|
5531
|
-
effects: z.array(z.record(z.string(), z.unknown())).optional()
|
|
5532
|
-
});
|
|
5533
|
-
var OntologyCatalogTypeSchema = OntologyRecordBaseSchema.extend({
|
|
5534
|
-
kind: z.string().trim().min(1).max(120).optional(),
|
|
5535
|
-
appliesTo: OntologyIdSchema.optional(),
|
|
5536
|
-
entries: z.record(z.string().trim().min(1).max(200), z.unknown()).optional()
|
|
5537
|
-
});
|
|
5538
|
-
var OntologyEventTypeSchema = OntologyRecordBaseSchema.extend({
|
|
5539
|
-
payload: z.record(z.string().trim().min(1).max(200), z.unknown()).optional()
|
|
5540
|
-
});
|
|
5541
|
-
var OntologyInterfaceTypeSchema = OntologyRecordBaseSchema.extend({
|
|
5542
|
-
properties: z.record(z.string().trim().min(1).max(200), z.unknown()).optional()
|
|
5543
|
-
});
|
|
5544
|
-
var OntologyValueTypeSchema = OntologyRecordBaseSchema.extend({
|
|
5545
|
-
primitive: z.string().trim().min(1).max(120).optional()
|
|
5546
|
-
});
|
|
5547
|
-
var OntologySharedPropertySchema = OntologyRecordBaseSchema.extend({
|
|
5548
|
-
valueType: OntologyIdSchema.optional(),
|
|
5549
|
-
searchable: z.boolean().optional(),
|
|
5550
|
-
pii: z.boolean().optional()
|
|
5551
|
-
});
|
|
5552
|
-
var OntologyGroupSchema = OntologyRecordBaseSchema.extend({
|
|
5553
|
-
members: OntologyReferenceListSchema
|
|
5554
|
-
});
|
|
5555
|
-
var OntologySurfaceTypeSchema = OntologyRecordBaseSchema.extend({
|
|
5556
|
-
route: z.string().trim().min(1).max(500).optional()
|
|
5557
|
-
});
|
|
5558
|
-
var OntologyScopeSchema = z.object({
|
|
5559
|
-
objectTypes: z.record(OntologyIdSchema, OntologyObjectTypeSchema).default({}).optional(),
|
|
5560
|
-
linkTypes: z.record(OntologyIdSchema, OntologyLinkTypeSchema).default({}).optional(),
|
|
5561
|
-
actionTypes: z.record(OntologyIdSchema, OntologyActionTypeSchema).default({}).optional(),
|
|
5562
|
-
catalogTypes: z.record(OntologyIdSchema, OntologyCatalogTypeSchema).default({}).optional(),
|
|
5563
|
-
eventTypes: z.record(OntologyIdSchema, OntologyEventTypeSchema).default({}).optional(),
|
|
5564
|
-
interfaceTypes: z.record(OntologyIdSchema, OntologyInterfaceTypeSchema).default({}).optional(),
|
|
5565
|
-
valueTypes: z.record(OntologyIdSchema, OntologyValueTypeSchema).default({}).optional(),
|
|
5566
|
-
sharedProperties: z.record(OntologyIdSchema, OntologySharedPropertySchema).default({}).optional(),
|
|
5567
|
-
groups: z.record(OntologyIdSchema, OntologyGroupSchema).default({}).optional(),
|
|
5568
|
-
surfaces: z.record(OntologyIdSchema, OntologySurfaceTypeSchema).default({}).optional()
|
|
5569
|
-
}).default({});
|
|
5570
|
-
var DEFAULT_ONTOLOGY_SCOPE = {
|
|
5571
|
-
valueTypes: {
|
|
5572
|
-
"global:value-type/uuid": {
|
|
5573
|
-
id: "global:value-type/uuid",
|
|
5574
|
-
label: "UUID",
|
|
5575
|
-
primitive: "string"
|
|
5576
|
-
},
|
|
5577
|
-
"global:value-type/text": {
|
|
5578
|
-
id: "global:value-type/text",
|
|
5579
|
-
label: "Text",
|
|
5580
|
-
primitive: "string"
|
|
5581
|
-
},
|
|
5582
|
-
"global:value-type/url": {
|
|
5583
|
-
id: "global:value-type/url",
|
|
5584
|
-
label: "URL",
|
|
5585
|
-
primitive: "string"
|
|
5586
|
-
},
|
|
5587
|
-
"global:value-type/email": {
|
|
5588
|
-
id: "global:value-type/email",
|
|
5589
|
-
label: "Email",
|
|
5590
|
-
primitive: "string"
|
|
5591
|
-
}
|
|
5592
|
-
}
|
|
5593
|
-
};
|
|
5594
|
-
var SCOPE_KIND = {
|
|
5595
|
-
objectTypes: "object",
|
|
5596
|
-
linkTypes: "link",
|
|
5597
|
-
actionTypes: "action",
|
|
5598
|
-
catalogTypes: "catalog",
|
|
5599
|
-
eventTypes: "event",
|
|
5600
|
-
interfaceTypes: "interface",
|
|
5601
|
-
valueTypes: "value-type",
|
|
5602
|
-
sharedProperties: "property",
|
|
5603
|
-
groups: "group",
|
|
5604
|
-
surfaces: "surface"
|
|
5605
|
-
};
|
|
5606
|
-
var SCOPE_KEYS = Object.keys(SCOPE_KIND);
|
|
5607
|
-
function listResolvedOntologyRecords(index) {
|
|
5608
|
-
return SCOPE_KEYS.flatMap((scopeKey) => {
|
|
5609
|
-
const kind = SCOPE_KIND[scopeKey];
|
|
5610
|
-
return Object.entries(index[scopeKey]).sort(([leftId], [rightId]) => leftId.localeCompare(rightId)).map(([id, record]) => ({
|
|
5611
|
-
id,
|
|
5612
|
-
kind,
|
|
5613
|
-
record
|
|
5614
|
-
}));
|
|
5615
|
-
});
|
|
5616
|
-
}
|
|
5617
|
-
function originFromContext(context) {
|
|
5618
|
-
return {
|
|
5619
|
-
kind: context.kind,
|
|
5620
|
-
source: context.source,
|
|
5621
|
-
path: context.path,
|
|
5622
|
-
...context.systemPath !== void 0 ? { systemPath: context.systemPath } : {},
|
|
5623
|
-
...context.legacyId !== void 0 ? { legacyId: context.legacyId } : {}
|
|
5624
|
-
};
|
|
5625
|
-
}
|
|
5626
|
-
function createEmptyIndex() {
|
|
5627
|
-
return {
|
|
5628
|
-
objectTypes: {},
|
|
5629
|
-
linkTypes: {},
|
|
5630
|
-
actionTypes: {},
|
|
5631
|
-
catalogTypes: {},
|
|
5632
|
-
eventTypes: {},
|
|
5633
|
-
interfaceTypes: {},
|
|
5634
|
-
valueTypes: {},
|
|
5635
|
-
sharedProperties: {},
|
|
5636
|
-
groups: {},
|
|
5637
|
-
surfaces: {}
|
|
5638
|
-
};
|
|
5639
|
-
}
|
|
5640
|
-
function sortResolvedOntologyIndex(index) {
|
|
5641
|
-
const sorted = createEmptyIndex();
|
|
5642
|
-
for (const scopeKey of SCOPE_KEYS) {
|
|
5643
|
-
const target = sorted[scopeKey];
|
|
5644
|
-
for (const [id, record] of Object.entries(index[scopeKey]).sort(
|
|
5645
|
-
([leftId], [rightId]) => leftId.localeCompare(rightId)
|
|
5646
|
-
)) {
|
|
5647
|
-
target[id] = record;
|
|
5648
|
-
}
|
|
5649
|
-
}
|
|
5650
|
-
return sorted;
|
|
5651
|
-
}
|
|
5652
|
-
function childSystemsOf(system) {
|
|
5653
|
-
return system.systems ?? system.subsystems ?? {};
|
|
5654
|
-
}
|
|
5655
|
-
function addRecord(index, diagnostics, sourcesById, scopeKey, record, context) {
|
|
5656
|
-
let parsed;
|
|
5657
|
-
try {
|
|
5658
|
-
parsed = parseOntologyId(record.id);
|
|
5659
|
-
} catch {
|
|
5660
|
-
diagnostics.push({
|
|
5661
|
-
code: "invalid_ontology_id",
|
|
5662
|
-
message: `Invalid ontology ID "${record.id}" from ${context.source} at ${context.path.join(".")}`,
|
|
5663
|
-
id: record.id,
|
|
5664
|
-
path: context.path,
|
|
5665
|
-
source: context.source,
|
|
5666
|
-
origin: originFromContext(context)
|
|
5667
|
-
});
|
|
5668
|
-
return;
|
|
5669
|
-
}
|
|
5670
|
-
const expectedKind = SCOPE_KIND[scopeKey];
|
|
5671
|
-
if (parsed.kind !== expectedKind) {
|
|
5672
|
-
diagnostics.push({
|
|
5673
|
-
code: "ontology_kind_mismatch",
|
|
5674
|
-
message: `Ontology ID "${record.id}" has kind "${parsed.kind}" but was authored in ${scopeKey} (${expectedKind}) at ${context.path.join(".")}`,
|
|
5675
|
-
id: record.id,
|
|
5676
|
-
path: context.path,
|
|
5677
|
-
source: context.source,
|
|
5678
|
-
origin: originFromContext(context)
|
|
5679
|
-
});
|
|
5680
|
-
return;
|
|
5681
|
-
}
|
|
5682
|
-
const existing = sourcesById.get(parsed.id);
|
|
5683
|
-
if (existing !== void 0) {
|
|
5684
|
-
diagnostics.push({
|
|
5685
|
-
code: "duplicate_ontology_id",
|
|
5686
|
-
message: `Duplicate ontology ID "${parsed.id}" from ${context.source} at ${context.path.join(".")} conflicts with ${existing.source} at ${existing.path.join(".")}`,
|
|
5687
|
-
id: parsed.id,
|
|
5688
|
-
path: context.path,
|
|
5689
|
-
source: context.source,
|
|
5690
|
-
origin: originFromContext(context),
|
|
5691
|
-
existingSource: existing.source,
|
|
5692
|
-
existingOrigin: originFromContext(existing)
|
|
5693
|
-
});
|
|
5694
|
-
return;
|
|
5695
|
-
}
|
|
5696
|
-
sourcesById.set(parsed.id, context);
|
|
5697
|
-
index[scopeKey][parsed.id] = {
|
|
5698
|
-
...record,
|
|
5699
|
-
origin: originFromContext(context)
|
|
5700
|
-
};
|
|
5701
|
-
}
|
|
5702
|
-
function addScope(index, diagnostics, sourcesById, scope, source, path) {
|
|
5703
|
-
if (scope === void 0) return;
|
|
5704
|
-
for (const scopeKey of SCOPE_KEYS) {
|
|
5705
|
-
const records = scope[scopeKey] ?? {};
|
|
5706
|
-
for (const [key, record] of Object.entries(records)) {
|
|
5707
|
-
addRecord(index, diagnostics, sourcesById, scopeKey, record, {
|
|
5708
|
-
source,
|
|
5709
|
-
path: [...path, scopeKey, key],
|
|
5710
|
-
kind: "authored",
|
|
5711
|
-
systemPath: source.startsWith("system:") ? source.slice("system:".length, -".ontology".length) : void 0
|
|
5712
|
-
});
|
|
5713
|
-
}
|
|
5714
|
-
}
|
|
5715
|
-
}
|
|
5716
|
-
function legacyObjectId(entity) {
|
|
5717
|
-
return formatOntologyId({ scope: entity.ownedBySystemId, kind: "object", localId: entity.id });
|
|
5718
|
-
}
|
|
5719
|
-
function legacyActionOwner(action, entities) {
|
|
5720
|
-
const firstAffectedEntityId = action.affects?.find((entityId) => entities[entityId] !== void 0);
|
|
5721
|
-
if (firstAffectedEntityId !== void 0) {
|
|
5722
|
-
return entities[firstAffectedEntityId].ownedBySystemId;
|
|
5723
|
-
}
|
|
5724
|
-
if (typeof action.scope === "object") {
|
|
5725
|
-
return action.scope.domain;
|
|
5726
|
-
}
|
|
5727
|
-
return "global";
|
|
5728
|
-
}
|
|
5729
|
-
function addLegacyEntityProjections(index, diagnostics, sourcesById, entities) {
|
|
5730
|
-
for (const entity of Object.values(entities)) {
|
|
5731
|
-
const objectType = {
|
|
5732
|
-
id: legacyObjectId(entity),
|
|
5733
|
-
label: entity.label,
|
|
5734
|
-
description: entity.description,
|
|
5735
|
-
ownerSystemId: entity.ownedBySystemId,
|
|
5736
|
-
...entity.table !== void 0 ? {
|
|
5737
|
-
storage: {
|
|
5738
|
-
kind: "table",
|
|
5739
|
-
table: entity.table
|
|
5740
|
-
}
|
|
5741
|
-
} : {},
|
|
5742
|
-
...entity.rowSchema !== void 0 ? { rowSchema: entity.rowSchema } : {},
|
|
5743
|
-
...entity.stateCatalogId !== void 0 ? { stateCatalogId: entity.stateCatalogId } : {}
|
|
5744
|
-
};
|
|
5745
|
-
addRecord(index, diagnostics, sourcesById, "objectTypes", objectType, {
|
|
5746
|
-
source: "legacy.entities",
|
|
5747
|
-
path: ["entities", entity.id],
|
|
5748
|
-
kind: "projected",
|
|
5749
|
-
systemPath: entity.ownedBySystemId,
|
|
5750
|
-
legacyId: entity.id
|
|
5751
|
-
});
|
|
5752
|
-
entity.links?.forEach((link, linkIndex) => {
|
|
5753
|
-
const targetEntity = entities[link.toEntity];
|
|
5754
|
-
if (targetEntity === void 0) return;
|
|
5755
|
-
const linkType = {
|
|
5756
|
-
id: formatOntologyId({
|
|
5757
|
-
scope: entity.ownedBySystemId,
|
|
5758
|
-
kind: "link",
|
|
5759
|
-
localId: `${entity.id}-${link.toEntity}-${linkIndex}`
|
|
5760
|
-
}),
|
|
5761
|
-
label: link.label ?? link.kind,
|
|
5762
|
-
ownerSystemId: entity.ownedBySystemId,
|
|
5763
|
-
from: legacyObjectId(entity),
|
|
5764
|
-
to: legacyObjectId(targetEntity),
|
|
5765
|
-
cardinality: link.kind,
|
|
5766
|
-
...link.via !== void 0 ? { via: link.via } : {}
|
|
5767
|
-
};
|
|
5768
|
-
addRecord(index, diagnostics, sourcesById, "linkTypes", linkType, {
|
|
5769
|
-
source: "legacy.entities.links",
|
|
5770
|
-
path: ["entities", entity.id, "links", linkIndex],
|
|
5771
|
-
kind: "projected",
|
|
5772
|
-
systemPath: entity.ownedBySystemId,
|
|
5773
|
-
legacyId: `${entity.id}.links.${linkIndex}`
|
|
5774
|
-
});
|
|
5775
|
-
});
|
|
5776
|
-
}
|
|
5777
|
-
}
|
|
5778
|
-
function addLegacyActionProjections(index, diagnostics, sourcesById, actions, entities) {
|
|
5779
|
-
for (const action of Object.values(actions)) {
|
|
5780
|
-
const ownerSystemId = legacyActionOwner(action, entities);
|
|
5781
|
-
const actionType = {
|
|
5782
|
-
id: formatOntologyId({ scope: ownerSystemId, kind: "action", localId: action.id }),
|
|
5783
|
-
label: action.label,
|
|
5784
|
-
description: action.description,
|
|
5785
|
-
ownerSystemId,
|
|
5786
|
-
actsOn: action.affects?.map((entityId) => entities[entityId] ? legacyObjectId(entities[entityId]) : void 0).filter((id) => id !== void 0),
|
|
5787
|
-
...action.resourceId !== void 0 ? { resourceId: action.resourceId } : {},
|
|
5788
|
-
...action.invocations !== void 0 ? { invocations: action.invocations } : {},
|
|
5789
|
-
...action.lifecycle !== void 0 ? { lifecycle: action.lifecycle } : {},
|
|
5790
|
-
legacyActionId: action.id
|
|
5791
|
-
};
|
|
5792
|
-
addRecord(index, diagnostics, sourcesById, "actionTypes", actionType, {
|
|
5793
|
-
source: "legacy.actions",
|
|
5794
|
-
path: ["actions", action.id],
|
|
5795
|
-
kind: "projected",
|
|
5796
|
-
systemPath: ownerSystemId,
|
|
5797
|
-
legacyId: action.id
|
|
5798
|
-
});
|
|
5799
|
-
}
|
|
5800
|
-
}
|
|
5801
|
-
function addSystemScopes(index, diagnostics, sourcesById, systems, prefix, schemaPath) {
|
|
5802
|
-
for (const [key, system] of Object.entries(systems)) {
|
|
5803
|
-
const systemPath = prefix ? `${prefix}.${key}` : key;
|
|
5804
|
-
const currentPath = [...schemaPath, key];
|
|
5805
|
-
addScope(index, diagnostics, sourcesById, system.ontology, `system:${systemPath}.ontology`, [
|
|
5806
|
-
...currentPath,
|
|
5807
|
-
"ontology"
|
|
5808
|
-
]);
|
|
5809
|
-
addSystemScopes(index, diagnostics, sourcesById, childSystemsOf(system), systemPath, [
|
|
5810
|
-
...currentPath,
|
|
5811
|
-
system.systems !== void 0 ? "systems" : "subsystems"
|
|
5812
|
-
]);
|
|
5813
|
-
}
|
|
5814
|
-
}
|
|
5815
|
-
function compileOrganizationOntology(model) {
|
|
5816
|
-
const ontology = createEmptyIndex();
|
|
5817
|
-
const diagnostics = [];
|
|
5818
|
-
const sourcesById = /* @__PURE__ */ new Map();
|
|
5819
|
-
addScope(ontology, diagnostics, sourcesById, model.ontology, "organization.ontology", ["ontology"]);
|
|
5820
|
-
addSystemScopes(ontology, diagnostics, sourcesById, model.systems ?? {}, "", ["systems"]);
|
|
5821
|
-
addLegacyEntityProjections(ontology, diagnostics, sourcesById, model.entities ?? {});
|
|
5822
|
-
addLegacyActionProjections(ontology, diagnostics, sourcesById, model.actions ?? {}, model.entities ?? {});
|
|
5823
|
-
return { ontology: sortResolvedOntologyIndex(ontology), diagnostics };
|
|
5824
|
-
}
|
|
5825
|
-
|
|
5826
|
-
// ../core/src/organization-model/domains/systems.ts
|
|
5827
|
-
var SystemKindSchema = z.enum(["product", "operational", "platform", "diagnostic"]).meta({ label: "System kind", color: "blue" });
|
|
5828
|
-
var SystemLifecycleSchema = z.enum(["draft", "beta", "active", "deprecated", "archived"]).meta({ label: "Lifecycle", color: "teal" });
|
|
5829
|
-
var SystemStatusSchema = z.enum(["active", "deprecated", "archived"]).meta({ label: "Status", color: "teal" });
|
|
5830
|
-
var SystemIdSchema = ModelIdSchema;
|
|
5831
|
-
var SystemPathSchema = z.string().trim().min(1).regex(
|
|
5832
|
-
/^[a-z0-9][a-z0-9-]*(?:\.[a-z0-9][a-z0-9-]*)*$/,
|
|
5833
|
-
'must be a dotted lowercase path (e.g. "sales.lead-gen" or "sales.crm")'
|
|
5834
|
-
);
|
|
5835
|
-
var UiPositionSchema = z.enum(["sidebar-primary", "sidebar-bottom"]).meta({ label: "UI position" });
|
|
5836
|
-
var NodeIdStringSchema = z.string().trim().min(1).max(200).regex(
|
|
5837
|
-
/^[a-z][a-z-]*:([a-z0-9-]+)(\.[a-z0-9-]+)*(:[a-z0-9.-]+)*$/,
|
|
5838
|
-
"Node references must use kind:dotted-path (e.g. system:sales.crm or resource:lead-gen.company.qualify)"
|
|
5839
|
-
);
|
|
5840
|
-
var SystemUiSchema = z.object({
|
|
5841
|
-
path: PathSchema,
|
|
5842
|
-
surfaces: ReferenceIdsSchema,
|
|
5843
|
-
icon: IconNameSchema.optional(),
|
|
5844
|
-
order: z.number().int().optional()
|
|
5845
|
-
});
|
|
5846
|
-
var JsonValueSchema = z.lazy(
|
|
5847
|
-
() => z.union([
|
|
5848
|
-
z.string(),
|
|
5849
|
-
z.number(),
|
|
5850
|
-
z.boolean(),
|
|
5851
|
-
z.null(),
|
|
5852
|
-
z.array(JsonValueSchema),
|
|
5853
|
-
z.record(z.string(), JsonValueSchema)
|
|
5854
|
-
])
|
|
5855
|
-
);
|
|
5856
|
-
var SystemConfigSchema = z.record(z.string().trim().min(1).max(200), JsonValueSchema).default({}).optional();
|
|
5857
|
-
var SystemEntrySchema = z.object({
|
|
5858
|
-
/** Stable tenant-defined system id (e.g. "sys.lead-gen" or "sales.crm"). */
|
|
5859
|
-
id: SystemIdSchema,
|
|
5860
|
-
/** Human-readable system label shown in UI, governance, and operations surfaces. */
|
|
5861
|
-
label: LabelSchema.optional(),
|
|
5862
|
-
/** @deprecated Use label. Accepted for pre-consolidation System declarations. */
|
|
5863
|
-
title: LabelSchema.optional(),
|
|
5864
|
-
/** One-paragraph purpose statement for the bounded context. */
|
|
5865
|
-
description: DescriptionSchema.optional(),
|
|
5866
|
-
/** Closed system shape enum; catalog values remain tenant-defined. */
|
|
5867
|
-
kind: SystemKindSchema.optional(),
|
|
5868
|
-
/** Optional self-reference for System hierarchy. */
|
|
5869
|
-
parentSystemId: SystemIdSchema.optional(),
|
|
5870
|
-
/** Optional UI presence. Systems without UI omit this. */
|
|
5871
|
-
ui: SystemUiSchema.optional(),
|
|
5872
|
-
/** Canonical lifecycle state. Replaces Feature.enabled/devOnly and System.status. */
|
|
5873
|
-
lifecycle: SystemLifecycleSchema.optional(),
|
|
5874
|
-
/** Optional role responsible for this system. */
|
|
5875
|
-
responsibleRoleId: ModelIdSchema.meta({ ref: "role" }).optional(),
|
|
5876
|
-
/** Optional knowledge nodes that govern this system. */
|
|
5877
|
-
governedByKnowledge: z.array(ModelIdSchema.meta({ ref: "knowledge" })).default([]).optional(),
|
|
5878
|
-
/** Optional actions this system exposes or consumes. */
|
|
5879
|
-
actions: z.array(ActionRefSchema).optional(),
|
|
5880
|
-
/** Optional operational policies that apply to this system. */
|
|
5881
|
-
policies: z.array(ModelIdSchema.meta({ ref: "policy" })).default([]).optional(),
|
|
5882
|
-
/** Optional goals this system contributes to. */
|
|
5883
|
-
drivesGoals: z.array(ModelIdSchema.meta({ ref: "goal" })).default([]).optional(),
|
|
5884
|
-
/** @deprecated Use lifecycle. Accepted for one publish cycle. */
|
|
5885
|
-
status: SystemStatusSchema.optional(),
|
|
5886
|
-
/** @deprecated Use ui.path. Kept for one-cycle Feature compatibility. */
|
|
5887
|
-
path: PathSchema.optional(),
|
|
5888
|
-
/** @deprecated Use ui.icon. Kept for one-cycle Feature compatibility. */
|
|
5889
|
-
icon: IconNameSchema.optional(),
|
|
5890
|
-
/** @deprecated Feature color token, retained for one-cycle compatibility. */
|
|
5891
|
-
color: ColorTokenSchema.optional(),
|
|
5892
|
-
/** @deprecated UI placement hint, retained for one-cycle compatibility. */
|
|
5893
|
-
uiPosition: UiPositionSchema.optional(),
|
|
5894
|
-
/** @deprecated Use lifecycle. */
|
|
5895
|
-
enabled: z.boolean().optional(),
|
|
5896
|
-
/** @deprecated Use lifecycle: "beta". */
|
|
5897
|
-
devOnly: z.boolean().optional(),
|
|
5898
|
-
requiresAdmin: z.boolean().optional(),
|
|
5899
|
-
/** Domain-map iteration order. Convention: multiples of 10 (10, 20, 30, ...) to allow easy insertion. */
|
|
5900
|
-
order: z.number(),
|
|
5901
|
-
/**
|
|
5902
|
-
* System-local JSON settings and defaults. Strongly typed OM fields,
|
|
5903
|
-
* secrets, credentials, and runtime state stay outside this bucket.
|
|
5904
|
-
*/
|
|
5905
|
-
config: SystemConfigSchema,
|
|
5906
|
-
/**
|
|
5907
|
-
* System-owned ontology declarations. `systems` is now the canonical child
|
|
5908
|
-
* key; this scope holds the object, action, catalog, link, event, and
|
|
5909
|
-
* shared contract records owned by this system.
|
|
5910
|
-
*/
|
|
5911
|
-
ontology: OntologyScopeSchema.optional(),
|
|
5912
|
-
/**
|
|
5913
|
-
* Recursive child systems, authored via nesting (per L11).
|
|
5914
|
-
* The key is the local system id; the full path is computed by joining
|
|
5915
|
-
* ancestor keys with `.` (e.g. parent key `'sales'` + child key `'crm'` → `'sales.crm'`).
|
|
5916
|
-
* Per Phase 4: `id` and `parentSystemId` fields will be removed in favour of
|
|
5917
|
-
* position-derived paths. Both still exist on this schema for backward compat.
|
|
5918
|
-
*/
|
|
5919
|
-
systems: z.lazy(() => z.record(z.string().trim().min(1).max(100), SystemEntrySchema)).optional(),
|
|
5920
|
-
/** @deprecated Use systems. Accepted as a compatibility alias during the ontology bridge. */
|
|
5921
|
-
subsystems: z.lazy(() => z.record(z.string().trim().min(1).max(100), SystemEntrySchema)).optional()
|
|
5922
|
-
}).strict().refine((system) => system.label !== void 0 || system.title !== void 0, {
|
|
5923
|
-
path: ["label"],
|
|
5924
|
-
message: "System must provide label or title"
|
|
5925
|
-
}).transform((system) => {
|
|
5926
|
-
const normalizedSystem = system.systems !== void 0 && system.subsystems === void 0 ? { ...system, subsystems: system.systems } : system;
|
|
5927
|
-
if (normalizedSystem.status === void 0) return normalizedSystem;
|
|
5928
|
-
console.warn("[organization-model] System.status is deprecated; use System.lifecycle instead.");
|
|
5929
|
-
return normalizedSystem.lifecycle === void 0 ? { ...normalizedSystem, lifecycle: normalizedSystem.status } : normalizedSystem;
|
|
5930
|
-
});
|
|
5931
|
-
var SystemsDomainSchema = z.record(z.string(), SystemEntrySchema).refine((record) => Object.entries(record).every(([key, entry]) => entry.id === key), {
|
|
5932
|
-
message: "Each system entry id must match its map key"
|
|
5933
|
-
}).default({});
|
|
5934
|
-
var DEFAULT_ORGANIZATION_MODEL_SYSTEMS = {};
|
|
5935
|
-
|
|
5936
|
-
// ../core/src/organization-model/domains/resources.ts
|
|
5937
|
-
var ContractRefSchema = z.string().trim().min(1).max(500).regex(
|
|
5938
|
-
/^[A-Za-z0-9@](?:[A-Za-z0-9_./@-]*[A-Za-z0-9_])?\/?[A-Za-z0-9_./@-]*#[A-Za-z_$][A-Za-z0-9_$]*$/,
|
|
5939
|
-
"ContractRef must be in the format package/subpath#ExportName (e.g. @repo/elevasis-core/contracts/apollo-import#inputSchema)"
|
|
5940
|
-
);
|
|
5941
|
-
z.enum(["workflow", "agent", "integration", "script"]).meta({ label: "Resource kind", color: "orange" });
|
|
5942
|
-
var ResourceGovernanceStatusSchema = z.enum(["active", "deprecated", "archived"]).meta({ label: "Governance status", color: "teal" });
|
|
5943
|
-
var AgentKindSchema = z.enum(["orchestrator", "specialist", "utility", "platform"]).meta({ label: "Agent kind", color: "violet" });
|
|
5944
|
-
var ScriptResourceLanguageSchema = z.enum(["shell", "sql", "typescript", "python"]).meta({ label: "Language" });
|
|
5945
|
-
var CodeReferenceRoleSchema = z.enum(["entrypoint", "handler", "schema", "test", "docs", "config"]).meta({ label: "Code reference role", color: "blue" });
|
|
5946
|
-
var ResourceIdSchema = z.string().trim().min(1).max(255).regex(/^[A-Za-z0-9]+(?:[-._][A-Za-z0-9]+)*$/, "Resource IDs must use letters, numbers, -, _, or . separators");
|
|
5947
|
-
var EventIdSchema = z.string().trim().min(1).max(300).regex(
|
|
5948
|
-
/^[A-Za-z0-9]+(?:[-._][A-Za-z0-9]+)*:[a-z0-9]+(?:[-._][a-z0-9]+)*$/,
|
|
5949
|
-
"Event IDs must use <owner-id>:<event-key>"
|
|
5950
|
-
);
|
|
5951
|
-
var EventKeySchema = ModelIdSchema;
|
|
5952
|
-
var EventEmissionDescriptorSchema = z.object({
|
|
5953
|
-
eventKey: EventKeySchema,
|
|
5954
|
-
label: z.string().trim().min(1).max(120),
|
|
5955
|
-
payloadSchema: ModelIdSchema.optional(),
|
|
5956
|
-
lifecycle: SystemLifecycleSchema.optional()
|
|
5957
|
-
});
|
|
5958
|
-
EventEmissionDescriptorSchema.extend({
|
|
5959
|
-
id: EventIdSchema,
|
|
5960
|
-
ownerId: z.union([ResourceIdSchema, ModelIdSchema]),
|
|
5961
|
-
ownerKind: z.enum(["resource", "entity"]).meta({ label: "Owner kind" })
|
|
5962
|
-
});
|
|
5963
|
-
var ResourceOntologyBindingSchema = z.object({
|
|
5964
|
-
actions: z.array(OntologyIdSchema).optional(),
|
|
5965
|
-
primaryAction: OntologyIdSchema.optional(),
|
|
5966
|
-
reads: z.array(OntologyIdSchema).optional(),
|
|
5967
|
-
writes: z.array(OntologyIdSchema).optional(),
|
|
5968
|
-
usesCatalogs: z.array(OntologyIdSchema).optional(),
|
|
5969
|
-
emits: z.array(OntologyIdSchema).optional(),
|
|
5970
|
-
/**
|
|
5971
|
-
* Optional typed contract binding for this resource's workflow I/O.
|
|
5972
|
-
* Each ref is a `package/subpath#ExportName` string that resolves to a
|
|
5973
|
-
* Zod schema in `@repo/elevasis-core` (or the consumer's equivalent package).
|
|
5974
|
-
*
|
|
5975
|
-
* Absence of this field preserves all existing behavior — it is additive + optional.
|
|
5976
|
-
* Tier-1 validation (schema.ts): ref-string shape only (browser-safe, no imports).
|
|
5977
|
-
* Tier-2 validation (om:verify): intra-package typed-map resolution asserts ZodType.
|
|
5978
|
-
*/
|
|
5979
|
-
contract: z.object({
|
|
5980
|
-
input: ContractRefSchema.optional(),
|
|
5981
|
-
output: ContractRefSchema.optional()
|
|
5982
|
-
}).optional()
|
|
5983
|
-
}).superRefine((binding, ctx) => {
|
|
5984
|
-
if (binding.primaryAction === void 0) return;
|
|
5985
|
-
if (binding.actions?.includes(binding.primaryAction)) return;
|
|
5986
|
-
ctx.addIssue({
|
|
5987
|
-
code: z.ZodIssueCode.custom,
|
|
5988
|
-
path: ["primaryAction"],
|
|
5989
|
-
message: "Resource ontology primaryAction must be included in actions"
|
|
5990
|
-
});
|
|
5991
|
-
});
|
|
5992
|
-
var CodeReferenceSchema = z.object({
|
|
5993
|
-
path: z.string().trim().min(1).max(500).regex(/^[A-Za-z0-9_./$@()[\] -]+$/, "Code reference paths must be repo-relative paths"),
|
|
5994
|
-
role: CodeReferenceRoleSchema,
|
|
5995
|
-
symbol: z.string().trim().min(1).max(200).optional(),
|
|
5996
|
-
description: z.string().trim().min(1).max(300).optional()
|
|
5997
|
-
});
|
|
5998
|
-
var ResourceEntryBaseSchema = z.object({
|
|
5999
|
-
/** Canonical resource id; runtime resourceId derives from this value. */
|
|
6000
|
-
id: ResourceIdSchema,
|
|
6001
|
-
/** Domain-map iteration order. Convention: multiples of 10 (10, 20, 30, ...) to allow easy insertion. */
|
|
6002
|
-
order: z.number().default(0),
|
|
6003
|
-
/** Required single System membership — value is a dot-separated system path (e.g. "sales.lead-gen"). */
|
|
6004
|
-
systemPath: SystemPathSchema.meta({ ref: "system" }),
|
|
6005
|
-
/** Executable display title owned by the OM Resource descriptor. */
|
|
6006
|
-
title: LabelSchema.optional(),
|
|
6007
|
-
/** Executable display description owned by the OM Resource descriptor. */
|
|
6008
|
-
description: DescriptionSchema.optional(),
|
|
6009
|
-
/** Optional role responsible for maintaining this resource. */
|
|
6010
|
-
ownerRoleId: ModelIdSchema.meta({ ref: "role" }).optional(),
|
|
6011
|
-
status: ResourceGovernanceStatusSchema,
|
|
6012
|
-
/**
|
|
6013
|
-
* Ontology contract bindings for the semantic work this resource performs.
|
|
6014
|
-
* `emits` stays nested here so top-level resource emits descriptors remain
|
|
6015
|
-
* compatible with graph event projection during the bridge.
|
|
6016
|
-
*/
|
|
6017
|
-
ontology: ResourceOntologyBindingSchema.optional(),
|
|
6018
|
-
/** Repo-relative implementation breadcrumbs for agents and operators. */
|
|
6019
|
-
codeRefs: z.array(CodeReferenceSchema).default([])
|
|
6020
|
-
});
|
|
6021
|
-
var WorkflowResourceEntrySchema = ResourceEntryBaseSchema.extend({
|
|
6022
|
-
kind: z.literal("workflow"),
|
|
6023
|
-
emits: z.array(EventEmissionDescriptorSchema).optional()
|
|
6024
|
-
});
|
|
6025
|
-
var AgentResourceEntrySchema = ResourceEntryBaseSchema.extend({
|
|
6026
|
-
kind: z.literal("agent"),
|
|
6027
|
-
/** Mirrors code-side AgentConfig.kind. */
|
|
6028
|
-
agentKind: AgentKindSchema,
|
|
6029
|
-
/** Role this agent embodies, if any. */
|
|
6030
|
-
actsAsRoleId: ModelIdSchema.meta({ ref: "role" }).optional(),
|
|
6031
|
-
/** Mirrors AgentConfig.sessionCapable. */
|
|
6032
|
-
sessionCapable: z.boolean(),
|
|
6033
|
-
/** Broad/composite callable entry points orchestrated by this agent. */
|
|
6034
|
-
invocations: z.array(ActionInvocationSchema).default([]),
|
|
6035
|
-
emits: z.array(EventEmissionDescriptorSchema).optional()
|
|
6036
|
-
});
|
|
6037
|
-
var IntegrationResourceEntrySchema = ResourceEntryBaseSchema.extend({
|
|
6038
|
-
kind: z.literal("integration"),
|
|
6039
|
-
provider: z.string().trim().min(1).max(100)
|
|
6040
|
-
});
|
|
6041
|
-
var ScriptResourceSourceSchema = z.union([
|
|
6042
|
-
z.string().trim().min(1).max(5e4),
|
|
6043
|
-
z.object({
|
|
6044
|
-
file: z.string().trim().min(1).max(500)
|
|
6045
|
-
})
|
|
6046
|
-
]);
|
|
6047
|
-
var ScriptResourceEntrySchema = ResourceEntryBaseSchema.extend({
|
|
6048
|
-
kind: z.literal("script"),
|
|
6049
|
-
language: ScriptResourceLanguageSchema,
|
|
6050
|
-
source: ScriptResourceSourceSchema
|
|
6051
|
-
});
|
|
6052
|
-
var ResourceEntrySchema = z.discriminatedUnion("kind", [
|
|
6053
|
-
WorkflowResourceEntrySchema,
|
|
6054
|
-
AgentResourceEntrySchema,
|
|
6055
|
-
IntegrationResourceEntrySchema,
|
|
6056
|
-
ScriptResourceEntrySchema
|
|
6057
|
-
]);
|
|
6058
|
-
var ResourcesDomainSchema = z.record(z.string(), ResourceEntrySchema).refine((record) => Object.entries(record).every(([key, entry]) => entry.id === key), {
|
|
6059
|
-
message: "Each resource entry id must match its map key"
|
|
6060
|
-
}).default({});
|
|
6061
|
-
var DEFAULT_ORGANIZATION_MODEL_RESOURCES = {};
|
|
6062
|
-
|
|
6063
|
-
// ../core/src/organization-model/domains/roles.ts
|
|
6064
|
-
var RoleIdSchema = ModelIdSchema;
|
|
6065
|
-
var HumanRoleHolderSchema = z.object({
|
|
6066
|
-
kind: z.literal("human"),
|
|
6067
|
-
userId: z.string().trim().min(1).max(200)
|
|
6068
|
-
});
|
|
6069
|
-
var AgentRoleHolderSchema = z.object({
|
|
6070
|
-
kind: z.literal("agent"),
|
|
6071
|
-
agentId: ResourceIdSchema.meta({ ref: "resource" })
|
|
6072
|
-
});
|
|
6073
|
-
var TeamRoleHolderSchema = z.object({
|
|
6074
|
-
kind: z.literal("team"),
|
|
6075
|
-
memberIds: z.array(z.string().trim().min(1).max(200)).min(1)
|
|
6076
|
-
});
|
|
6077
|
-
var RoleHolderSchema = z.discriminatedUnion("kind", [
|
|
6078
|
-
HumanRoleHolderSchema,
|
|
6079
|
-
AgentRoleHolderSchema,
|
|
6080
|
-
TeamRoleHolderSchema
|
|
6081
|
-
]);
|
|
6082
|
-
var RoleHoldersSchema = z.union([RoleHolderSchema, z.array(RoleHolderSchema).min(1)]);
|
|
6083
|
-
var RoleSchema = z.object({
|
|
6084
|
-
/** Stable unique identifier for the role (e.g. "role-ceo", "role-head-of-sales"). */
|
|
6085
|
-
id: RoleIdSchema,
|
|
6086
|
-
/** Domain-map iteration order. Convention: multiples of 10 (10, 20, 30, ...) to allow easy insertion. */
|
|
6087
|
-
order: z.number(),
|
|
6088
|
-
/** Human-readable title shown to agents and in UI (e.g. "CEO", "Head of Sales"). */
|
|
6089
|
-
title: z.string().trim().min(1).max(200),
|
|
6090
|
-
/**
|
|
6091
|
-
* List of responsibilities this role owns - plain-language descriptions of
|
|
6092
|
-
* what the person in this role is accountable for delivering.
|
|
6093
|
-
* Defaults to empty array so minimal role definitions stay concise.
|
|
6094
|
-
*/
|
|
6095
|
-
responsibilities: z.array(z.string().trim().max(500)).default([]),
|
|
6096
|
-
/**
|
|
6097
|
-
* Optional: ID of another role this role reports to.
|
|
6098
|
-
* When present, must reference another `roles[].id` in the same organization.
|
|
6099
|
-
*/
|
|
6100
|
-
reportsToId: RoleIdSchema.meta({ ref: "role" }).optional(),
|
|
6101
|
-
/**
|
|
6102
|
-
* Optional: human, agent, or team holder currently filling this role.
|
|
6103
|
-
* Agent holders reference OM Resource IDs and are validated at the model level.
|
|
6104
|
-
*/
|
|
6105
|
-
heldBy: RoleHoldersSchema.optional(),
|
|
6106
|
-
/**
|
|
6107
|
-
* Optional Systems this role is accountable for.
|
|
6108
|
-
* Cross-reference enforced in `OrganizationModelSchema.superRefine()`.
|
|
6109
|
-
*/
|
|
6110
|
-
responsibleFor: z.array(SystemIdSchema.meta({ ref: "system" })).optional()
|
|
6111
|
-
});
|
|
6112
|
-
var RolesDomainSchema = z.record(z.string(), RoleSchema).refine((record) => Object.entries(record).every(([key, entry]) => entry.id === key), {
|
|
6113
|
-
message: "Each role entry id must match its map key"
|
|
6114
|
-
}).default({});
|
|
6115
|
-
var DEFAULT_ORGANIZATION_MODEL_ROLES = {};
|
|
6116
|
-
var KeyResultSchema = z.object({
|
|
6117
|
-
/** Stable unique identifier for the measurable outcome (e.g. "kr-revenue-q1"). */
|
|
6118
|
-
id: z.string().trim().min(1).max(100),
|
|
6119
|
-
/** Plain-language description of this measurable outcome (e.g. "Increase trial-to-paid conversion"). */
|
|
6120
|
-
description: z.string().trim().min(1).max(500),
|
|
6121
|
-
/**
|
|
6122
|
-
* What is being measured — the metric name (e.g. "monthly revenue", "NPS score",
|
|
6123
|
-
* "trial-to-paid conversion rate"). Free-form string.
|
|
6124
|
-
*/
|
|
6125
|
-
targetMetric: z.string().trim().min(1).max(200),
|
|
6126
|
-
/** Current measured value. Defaults to 0 when not yet tracked. */
|
|
6127
|
-
currentValue: z.number().default(0),
|
|
6128
|
-
/**
|
|
6129
|
-
* Target value to reach for this measurable outcome to be considered achieved.
|
|
6130
|
-
* Optional — omit if the outcome is directional (e.g. "reduce churn") without
|
|
6131
|
-
* a hard numeric target.
|
|
6132
|
-
*/
|
|
6133
|
-
targetValue: z.number().optional()
|
|
6134
|
-
});
|
|
6135
|
-
var ISO_DATE_REGEX = /^\d{4}-\d{2}-\d{2}$/;
|
|
6136
|
-
var ObjectiveSchema = z.object({
|
|
6137
|
-
/** Stable unique identifier for the goal (e.g. "goal-grow-arr-q1-2026"). */
|
|
6138
|
-
id: z.string().trim().min(1).max(100),
|
|
6139
|
-
/** Domain-map iteration order. Convention: multiples of 10 (10, 20, 30, ...) to allow easy insertion. */
|
|
6140
|
-
order: z.number(),
|
|
6141
|
-
/** Plain-language description of what the organization wants to achieve. */
|
|
6142
|
-
description: z.string().trim().min(1).max(1e3),
|
|
6143
|
-
/**
|
|
6144
|
-
* Start of the period this goal is active for — ISO 8601 date string (YYYY-MM-DD).
|
|
6145
|
-
* Must be strictly before `periodEnd`.
|
|
6146
|
-
*/
|
|
6147
|
-
periodStart: z.string().regex(ISO_DATE_REGEX, "periodStart must be an ISO date string (YYYY-MM-DD)"),
|
|
6148
|
-
/**
|
|
6149
|
-
* End of the period this goal is active for — ISO 8601 date string (YYYY-MM-DD).
|
|
6150
|
-
* Must be strictly after `periodStart`.
|
|
6151
|
-
* Enforced via `OrganizationModelSchema.superRefine()`.
|
|
6152
|
-
*/
|
|
6153
|
-
periodEnd: z.string().regex(ISO_DATE_REGEX, "periodEnd must be an ISO date string (YYYY-MM-DD)"),
|
|
6154
|
-
/**
|
|
6155
|
-
* List of measurable outcomes that define success for this goal.
|
|
6156
|
-
* Defaults to empty array so goals can be declared before outcomes are defined.
|
|
6157
|
-
*/
|
|
6158
|
-
keyResults: z.array(KeyResultSchema).default([])
|
|
6159
|
-
});
|
|
6160
|
-
var GoalsDomainSchema = z.record(z.string(), ObjectiveSchema).refine((record) => Object.entries(record).every(([key, entry]) => entry.id === key), {
|
|
6161
|
-
message: "Each objective entry id must match its map key"
|
|
6162
|
-
}).default({});
|
|
6163
|
-
var DEFAULT_ORGANIZATION_MODEL_GOALS = {};
|
|
6164
|
-
var SecretLikeMetadataKeySchema = /(?:secret|password|passwd|token|api[-_]?key|credential|private[-_]?key)/i;
|
|
6165
|
-
var SecretLikeMetadataValueSchema = /(?:sk-[A-Za-z0-9_-]{12,}|pk_live_[A-Za-z0-9_-]{12,}|eyJ[A-Za-z0-9_-]{20,}|-----BEGIN (?:RSA |OPENSSH |EC )?PRIVATE KEY-----)/;
|
|
6166
|
-
z.enum([
|
|
6167
|
-
"system",
|
|
6168
|
-
"resource",
|
|
6169
|
-
"ontology",
|
|
6170
|
-
"policy",
|
|
6171
|
-
"role",
|
|
6172
|
-
"trigger",
|
|
6173
|
-
"humanCheckpoint",
|
|
6174
|
-
"externalResource"
|
|
6175
|
-
]);
|
|
6176
|
-
var OmTopologyRelationshipKindSchema = z.enum(["triggers", "uses", "approval"]);
|
|
6177
|
-
var OmTopologyNodeRefSchema = z.discriminatedUnion("kind", [
|
|
6178
|
-
z.object({ kind: z.literal("system"), id: ModelIdSchema }),
|
|
6179
|
-
z.object({ kind: z.literal("resource"), id: ResourceIdSchema }),
|
|
6180
|
-
z.object({ kind: z.literal("ontology"), id: OntologyIdSchema }),
|
|
6181
|
-
z.object({ kind: z.literal("policy"), id: ModelIdSchema }),
|
|
6182
|
-
z.object({ kind: z.literal("role"), id: ModelIdSchema }),
|
|
6183
|
-
z.object({ kind: z.literal("trigger"), id: ResourceIdSchema }),
|
|
6184
|
-
z.object({ kind: z.literal("humanCheckpoint"), id: ResourceIdSchema }),
|
|
6185
|
-
z.object({ kind: z.literal("externalResource"), id: ResourceIdSchema })
|
|
6186
|
-
]);
|
|
6187
|
-
var OmTopologyMetadataSchema = z.record(z.string().trim().min(1).max(120), JsonValueSchema).superRefine((metadata, ctx) => {
|
|
6188
|
-
function visit(value, path) {
|
|
6189
|
-
if (typeof value === "string" && SecretLikeMetadataValueSchema.test(value)) {
|
|
6190
|
-
ctx.addIssue({
|
|
6191
|
-
code: z.ZodIssueCode.custom,
|
|
6192
|
-
path,
|
|
6193
|
-
message: "Topology metadata must not contain secret-like values"
|
|
6194
|
-
});
|
|
6195
|
-
return;
|
|
6196
|
-
}
|
|
6197
|
-
if (Array.isArray(value)) {
|
|
6198
|
-
value.forEach((entry, index) => visit(entry, [...path, index]));
|
|
6199
|
-
return;
|
|
6200
|
-
}
|
|
6201
|
-
if (typeof value !== "object" || value === null) return;
|
|
6202
|
-
Object.entries(value).forEach(([key, entry]) => {
|
|
6203
|
-
if (SecretLikeMetadataKeySchema.test(key)) {
|
|
6204
|
-
ctx.addIssue({
|
|
6205
|
-
code: z.ZodIssueCode.custom,
|
|
6206
|
-
path: [...path, key],
|
|
6207
|
-
message: `Topology metadata key "${key}" looks secret-like`
|
|
6208
|
-
});
|
|
6209
|
-
}
|
|
6210
|
-
visit(entry, [...path, key]);
|
|
6211
|
-
});
|
|
6212
|
-
}
|
|
6213
|
-
visit(metadata, []);
|
|
6214
|
-
});
|
|
6215
|
-
var OmTopologyRelationshipSchema = z.object({
|
|
6216
|
-
from: OmTopologyNodeRefSchema,
|
|
6217
|
-
kind: OmTopologyRelationshipKindSchema,
|
|
6218
|
-
to: OmTopologyNodeRefSchema,
|
|
6219
|
-
systemPath: SystemPathSchema.optional(),
|
|
6220
|
-
required: z.boolean().optional(),
|
|
6221
|
-
metadata: OmTopologyMetadataSchema.optional()
|
|
6222
|
-
});
|
|
6223
|
-
var OmTopologyDomainSchema = z.object({
|
|
6224
|
-
version: z.literal(1).default(1),
|
|
6225
|
-
relationships: z.record(z.string().trim().min(1).max(255), OmTopologyRelationshipSchema).default({})
|
|
6226
|
-
}).default({ version: 1, relationships: {} });
|
|
6227
|
-
var DEFAULT_ORGANIZATION_MODEL_TOPOLOGY = {
|
|
6228
|
-
version: 1,
|
|
6229
|
-
relationships: {}
|
|
6230
|
-
};
|
|
6231
|
-
var PolicyIdSchema = ModelIdSchema;
|
|
6232
|
-
var PolicyApplicabilitySchema = z.object({
|
|
6233
|
-
systemIds: z.array(ModelIdSchema.meta({ ref: "system" })).default([]),
|
|
6234
|
-
actionIds: z.array(ModelIdSchema.meta({ ref: "action" })).default([]),
|
|
6235
|
-
resourceIds: z.array(ModelIdSchema.meta({ ref: "resource" })).default([]),
|
|
6236
|
-
roleIds: z.array(ModelIdSchema.meta({ ref: "role" })).default([])
|
|
6237
|
-
});
|
|
6238
|
-
var PolicyTriggerSchema = z.discriminatedUnion("kind", [
|
|
6239
|
-
z.object({
|
|
6240
|
-
kind: z.literal("event"),
|
|
6241
|
-
eventId: EventIdSchema.meta({ ref: "event" })
|
|
6242
|
-
}),
|
|
6243
|
-
z.object({
|
|
6244
|
-
kind: z.literal("action-invocation"),
|
|
6245
|
-
actionId: ModelIdSchema.meta({ ref: "action" })
|
|
6246
|
-
}),
|
|
6247
|
-
z.object({
|
|
6248
|
-
kind: z.literal("schedule"),
|
|
6249
|
-
cron: z.string().trim().min(1).max(120)
|
|
6250
|
-
}),
|
|
6251
|
-
z.object({
|
|
6252
|
-
kind: z.literal("manual")
|
|
6253
|
-
})
|
|
6254
|
-
]);
|
|
6255
|
-
var PolicyPredicateSchema = z.discriminatedUnion("kind", [
|
|
6256
|
-
z.object({
|
|
6257
|
-
kind: z.literal("always")
|
|
6258
|
-
}),
|
|
6259
|
-
z.object({
|
|
6260
|
-
kind: z.literal("expression"),
|
|
6261
|
-
expression: z.string().trim().min(1).max(2e3)
|
|
6262
|
-
}),
|
|
6263
|
-
z.object({
|
|
6264
|
-
kind: z.literal("threshold"),
|
|
6265
|
-
metric: ModelIdSchema,
|
|
6266
|
-
operator: z.enum(["lt", "lte", "eq", "gte", "gt"]).meta({ label: "Operator" }),
|
|
6267
|
-
value: z.number()
|
|
6268
|
-
})
|
|
6269
|
-
]);
|
|
6270
|
-
var PolicyEffectSchema = z.discriminatedUnion("kind", [
|
|
6271
|
-
z.object({
|
|
6272
|
-
kind: z.literal("require-approval"),
|
|
6273
|
-
roleId: ModelIdSchema.meta({ ref: "role" }).optional()
|
|
6274
|
-
}),
|
|
6275
|
-
z.object({
|
|
6276
|
-
kind: z.literal("invoke-action"),
|
|
6277
|
-
actionId: ModelIdSchema.meta({ ref: "action" })
|
|
6278
|
-
}),
|
|
6279
|
-
z.object({
|
|
6280
|
-
kind: z.literal("notify-role"),
|
|
6281
|
-
roleId: ModelIdSchema.meta({ ref: "role" })
|
|
6282
|
-
}),
|
|
6283
|
-
z.object({
|
|
6284
|
-
kind: z.literal("block")
|
|
6285
|
-
})
|
|
6286
|
-
]);
|
|
6287
|
-
var PolicySchema = z.object({
|
|
6288
|
-
id: PolicyIdSchema,
|
|
6289
|
-
/** Domain-map iteration order. Convention: multiples of 10 (10, 20, 30, ...) to allow easy insertion. */
|
|
6290
|
-
order: z.number(),
|
|
6291
|
-
label: LabelSchema,
|
|
6292
|
-
description: DescriptionSchema.optional(),
|
|
6293
|
-
trigger: PolicyTriggerSchema,
|
|
6294
|
-
predicate: PolicyPredicateSchema.default({ kind: "always" }),
|
|
6295
|
-
actions: z.array(PolicyEffectSchema).min(1),
|
|
6296
|
-
appliesTo: PolicyApplicabilitySchema.default({
|
|
6297
|
-
systemIds: [],
|
|
6298
|
-
actionIds: [],
|
|
6299
|
-
resourceIds: [],
|
|
6300
|
-
roleIds: []
|
|
6301
|
-
}),
|
|
6302
|
-
lifecycle: z.enum(["draft", "beta", "active", "deprecated", "archived"]).meta({ label: "Lifecycle", color: "teal" }).default("active")
|
|
6303
|
-
});
|
|
6304
|
-
var PoliciesDomainSchema = z.record(z.string(), PolicySchema).refine((record) => Object.entries(record).every(([key, entry]) => entry.id === key), {
|
|
6305
|
-
message: "Each policy entry id must match its map key"
|
|
6306
|
-
}).default({});
|
|
6307
|
-
var DEFAULT_ORGANIZATION_MODEL_POLICIES = {};
|
|
6308
|
-
var SurfaceTypeSchema = z.enum(["page", "dashboard", "graph", "detail", "list", "settings"]).meta({ label: "Surface type", color: "blue" });
|
|
6309
|
-
z.object({
|
|
6310
|
-
id: ModelIdSchema,
|
|
6311
|
-
label: LabelSchema,
|
|
6312
|
-
path: PathSchema,
|
|
6313
|
-
surfaceType: SurfaceTypeSchema,
|
|
6314
|
-
description: DescriptionSchema.optional(),
|
|
6315
|
-
enabled: z.boolean().default(true),
|
|
6316
|
-
devOnly: z.boolean().optional(),
|
|
6317
|
-
icon: IconNameSchema.optional(),
|
|
6318
|
-
systemIds: z.array(ModelIdSchema.meta({ ref: "system" })).default([]),
|
|
6319
|
-
entityIds: z.array(ModelIdSchema.meta({ ref: "entity" })).default([]),
|
|
6320
|
-
resourceIds: z.array(ModelIdSchema.meta({ ref: "resource" })).default([]),
|
|
6321
|
-
actionIds: z.array(ModelIdSchema.meta({ ref: "action" })).default([]),
|
|
6322
|
-
parentId: ModelIdSchema.meta({ ref: "surface" }).optional()
|
|
6323
|
-
});
|
|
6324
|
-
var SidebarSurfaceTargetsSchema = z.object({
|
|
6325
|
-
systems: z.array(ModelIdSchema.meta({ ref: "system" })).default([]).optional(),
|
|
6326
|
-
entities: z.array(ModelIdSchema.meta({ ref: "entity" })).default([]).optional(),
|
|
6327
|
-
resources: z.array(ModelIdSchema.meta({ ref: "resource" })).default([]).optional(),
|
|
6328
|
-
actions: z.array(ModelIdSchema.meta({ ref: "action" })).default([]).optional()
|
|
6329
|
-
}).default({});
|
|
6330
|
-
var SidebarNodeSchema = z.lazy(
|
|
6331
|
-
() => z.discriminatedUnion("type", [
|
|
6332
|
-
z.object({
|
|
6333
|
-
type: z.literal("group"),
|
|
6334
|
-
label: LabelSchema,
|
|
6335
|
-
description: DescriptionSchema.optional(),
|
|
6336
|
-
icon: IconNameSchema.optional(),
|
|
6337
|
-
order: z.number().int().optional(),
|
|
6338
|
-
children: z.record(z.string(), SidebarNodeSchema).default({})
|
|
6339
|
-
}),
|
|
6340
|
-
z.object({
|
|
6341
|
-
type: z.literal("surface"),
|
|
6342
|
-
label: LabelSchema,
|
|
6343
|
-
path: PathSchema,
|
|
6344
|
-
surfaceType: SurfaceTypeSchema,
|
|
6345
|
-
description: DescriptionSchema.optional(),
|
|
6346
|
-
icon: IconNameSchema.optional(),
|
|
6347
|
-
order: z.number().int().optional(),
|
|
6348
|
-
targets: SidebarSurfaceTargetsSchema.optional(),
|
|
6349
|
-
devOnly: z.boolean().optional(),
|
|
6350
|
-
requiresAdmin: z.boolean().optional()
|
|
6351
|
-
})
|
|
6352
|
-
])
|
|
6353
|
-
);
|
|
6354
|
-
var SidebarSectionSchema = z.record(z.string(), SidebarNodeSchema).default({});
|
|
6355
|
-
var SidebarNavigationSchema = z.object({
|
|
6356
|
-
primary: SidebarSectionSchema,
|
|
6357
|
-
bottom: SidebarSectionSchema
|
|
6358
|
-
}).default({ primary: {}, bottom: {} });
|
|
6359
|
-
var OrganizationModelNavigationSchema = z.object({
|
|
6360
|
-
sidebar: SidebarNavigationSchema
|
|
6361
|
-
}).default({ sidebar: { primary: {}, bottom: {} } });
|
|
6362
|
-
z.object({
|
|
6363
|
-
id: ModelIdSchema,
|
|
6364
|
-
label: LabelSchema,
|
|
6365
|
-
placement: z.string().trim().min(1).max(50),
|
|
6366
|
-
surfaceIds: z.array(ModelIdSchema.meta({ ref: "surface" })).default([])
|
|
6367
|
-
});
|
|
6368
|
-
var KnowledgeTargetKindSchema = z.enum([
|
|
6369
|
-
"system",
|
|
6370
|
-
"resource",
|
|
6371
|
-
"knowledge",
|
|
6372
|
-
"stage",
|
|
6373
|
-
"action",
|
|
6374
|
-
"role",
|
|
6375
|
-
"goal",
|
|
6376
|
-
"customer-segment",
|
|
6377
|
-
"offering",
|
|
6378
|
-
"ontology"
|
|
6379
|
-
]).meta({ label: "Target kind" });
|
|
6380
|
-
var KnowledgeTargetRefSchema = z.object({
|
|
6381
|
-
kind: KnowledgeTargetKindSchema,
|
|
6382
|
-
// Ontology targets use the canonical '<scope>:<kind>/<local-id>' ontology id format.
|
|
6383
|
-
// Business-logic validation of target existence is done in OrganizationModelSchema.superRefine.
|
|
6384
|
-
id: z.string().trim().min(1).max(300)
|
|
6385
|
-
}).superRefine((target, ctx) => {
|
|
6386
|
-
if (target.kind !== "ontology") return;
|
|
6387
|
-
const result = OntologyIdSchema.safeParse(target.id);
|
|
6388
|
-
if (!result.success) {
|
|
6389
|
-
ctx.addIssue({
|
|
6390
|
-
code: z.ZodIssueCode.custom,
|
|
6391
|
-
path: ["id"],
|
|
6392
|
-
message: "Ontology knowledge targets must use <system-path>:<kind>/<local-id> or global:<kind>/<local-id>"
|
|
6393
|
-
});
|
|
6394
|
-
}
|
|
6395
|
-
});
|
|
6396
|
-
var LegacyKnowledgeLinkSchema = z.object({
|
|
6397
|
-
nodeId: z.union([NodeIdStringSchema, z.templateLiteral(["ontology:", OntologyIdSchema])])
|
|
6398
|
-
}).superRefine((link, ctx) => {
|
|
6399
|
-
const [kind] = link.nodeId.split(":");
|
|
6400
|
-
if (!KnowledgeTargetKindSchema.safeParse(kind).success) {
|
|
6401
|
-
ctx.addIssue({
|
|
6402
|
-
code: z.ZodIssueCode.custom,
|
|
6403
|
-
path: ["nodeId"],
|
|
6404
|
-
message: `Unknown knowledge target kind "${kind}"`
|
|
6405
|
-
});
|
|
6406
|
-
}
|
|
6407
|
-
});
|
|
6408
|
-
var CanonicalKnowledgeLinkSchema = z.object({
|
|
6409
|
-
target: KnowledgeTargetRefSchema
|
|
6410
|
-
});
|
|
6411
|
-
function nodeIdFromTarget(target) {
|
|
6412
|
-
return `${target.kind}:${target.id}`;
|
|
6413
|
-
}
|
|
6414
|
-
function targetFromNodeId(nodeId) {
|
|
6415
|
-
const [kind, ...idParts] = nodeId.split(":");
|
|
6416
|
-
return {
|
|
6417
|
-
kind: KnowledgeTargetKindSchema.parse(kind),
|
|
6418
|
-
id: idParts.join(":")
|
|
6419
|
-
};
|
|
6420
|
-
}
|
|
6421
|
-
var KnowledgeLinkSchema = z.union([CanonicalKnowledgeLinkSchema, LegacyKnowledgeLinkSchema]).transform((link) => {
|
|
6422
|
-
const target = "target" in link ? link.target : targetFromNodeId(link.nodeId);
|
|
6423
|
-
return {
|
|
6424
|
-
target,
|
|
6425
|
-
nodeId: nodeIdFromTarget(target)
|
|
6426
|
-
};
|
|
6427
|
-
});
|
|
6428
|
-
var OrgKnowledgeKindSchema = z.enum(["playbook", "strategy", "reference"]).meta({ label: "Knowledge kind", color: "grape" });
|
|
6429
|
-
var OrgKnowledgeNodeSchema = z.object({
|
|
6430
|
-
id: ModelIdSchema,
|
|
6431
|
-
kind: OrgKnowledgeKindSchema,
|
|
6432
|
-
title: z.string().trim().min(1).max(200),
|
|
6433
|
-
summary: z.string().trim().min(1).max(1e3),
|
|
6434
|
-
icon: IconNameSchema.optional(),
|
|
6435
|
-
/** Canonical documentation URL when body content is a local summary. */
|
|
6436
|
-
externalUrl: z.string().trim().url().max(500).optional(),
|
|
6437
|
-
/** Optional generated source file path for local MDX-backed knowledge nodes. */
|
|
6438
|
-
sourceFilePath: z.string().trim().min(1).max(500).optional(),
|
|
6439
|
-
/** Raw MDX string. Phase 2 will introduce a structured block format. */
|
|
6440
|
-
body: z.string().trim().min(1),
|
|
6441
|
-
/**
|
|
6442
|
-
* Graph links to other OM nodes this knowledge node governs.
|
|
6443
|
-
* Each link emits a `governs` edge: knowledge-node -> target node.
|
|
6444
|
-
*/
|
|
6445
|
-
links: z.array(KnowledgeLinkSchema).default([]),
|
|
6446
|
-
/** Role identifiers that own this knowledge node. */
|
|
6447
|
-
ownerIds: z.array(RoleIdSchema.meta({ ref: "role" })).default([]),
|
|
6448
|
-
/** ISO date string (YYYY-MM-DD or full ISO 8601) of last meaningful update. */
|
|
6449
|
-
updatedAt: z.string().trim().min(1).max(50)
|
|
6450
|
-
});
|
|
6451
|
-
var KnowledgeDomainSchema = z.record(ModelIdSchema, OrgKnowledgeNodeSchema).default({});
|
|
6452
|
-
|
|
6453
|
-
// ../core/src/organization-model/schema.ts
|
|
6454
|
-
z.enum([
|
|
6455
|
-
"branding",
|
|
6456
|
-
"identity",
|
|
6457
|
-
"customers",
|
|
6458
|
-
"offerings",
|
|
6459
|
-
"roles",
|
|
6460
|
-
"goals",
|
|
6461
|
-
"systems",
|
|
6462
|
-
"ontology",
|
|
6463
|
-
"resources",
|
|
6464
|
-
"topology",
|
|
6465
|
-
"actions",
|
|
6466
|
-
"entities",
|
|
6467
|
-
"policies",
|
|
6468
|
-
"knowledge"
|
|
6469
|
-
]);
|
|
6470
|
-
var OrganizationModelDomainMetadataSchema = z.object({
|
|
6471
|
-
version: z.literal(1).default(1),
|
|
6472
|
-
lastModified: z.string().regex(/^\d{4}-\d{2}-\d{2}$/, "lastModified must be an ISO date string (YYYY-MM-DD)")
|
|
6473
|
-
});
|
|
6474
|
-
var DEFAULT_ORGANIZATION_MODEL_DOMAIN_METADATA = {
|
|
6475
|
-
branding: { version: 1, lastModified: "2026-05-10" },
|
|
6476
|
-
identity: { version: 1, lastModified: "2026-05-10" },
|
|
6477
|
-
customers: { version: 1, lastModified: "2026-05-10" },
|
|
6478
|
-
offerings: { version: 1, lastModified: "2026-05-10" },
|
|
6479
|
-
roles: { version: 1, lastModified: "2026-05-10" },
|
|
6480
|
-
goals: { version: 1, lastModified: "2026-05-10" },
|
|
6481
|
-
systems: { version: 1, lastModified: "2026-05-10" },
|
|
6482
|
-
ontology: { version: 1, lastModified: "2026-05-14" },
|
|
6483
|
-
resources: { version: 1, lastModified: "2026-05-10" },
|
|
6484
|
-
topology: { version: 1, lastModified: "2026-05-14" },
|
|
6485
|
-
actions: { version: 1, lastModified: "2026-05-10" },
|
|
6486
|
-
entities: { version: 1, lastModified: "2026-05-10" },
|
|
6487
|
-
policies: { version: 1, lastModified: "2026-05-10" },
|
|
6488
|
-
knowledge: { version: 1, lastModified: "2026-05-10" }
|
|
6489
|
-
};
|
|
6490
|
-
var OrganizationModelDomainMetadataByDomainSchema = z.object({
|
|
6491
|
-
branding: OrganizationModelDomainMetadataSchema,
|
|
6492
|
-
identity: OrganizationModelDomainMetadataSchema,
|
|
6493
|
-
customers: OrganizationModelDomainMetadataSchema,
|
|
6494
|
-
offerings: OrganizationModelDomainMetadataSchema,
|
|
6495
|
-
roles: OrganizationModelDomainMetadataSchema,
|
|
6496
|
-
goals: OrganizationModelDomainMetadataSchema,
|
|
6497
|
-
systems: OrganizationModelDomainMetadataSchema,
|
|
6498
|
-
ontology: OrganizationModelDomainMetadataSchema,
|
|
6499
|
-
resources: OrganizationModelDomainMetadataSchema,
|
|
6500
|
-
topology: OrganizationModelDomainMetadataSchema,
|
|
6501
|
-
actions: OrganizationModelDomainMetadataSchema,
|
|
6502
|
-
entities: OrganizationModelDomainMetadataSchema,
|
|
6503
|
-
policies: OrganizationModelDomainMetadataSchema,
|
|
6504
|
-
knowledge: OrganizationModelDomainMetadataSchema
|
|
6505
|
-
}).partial().default(DEFAULT_ORGANIZATION_MODEL_DOMAIN_METADATA).transform((metadata) => ({ ...DEFAULT_ORGANIZATION_MODEL_DOMAIN_METADATA, ...metadata }));
|
|
6506
|
-
var OrganizationModelSchemaBase = z.object({
|
|
6507
|
-
version: z.literal(1).default(1),
|
|
6508
|
-
domainMetadata: OrganizationModelDomainMetadataByDomainSchema,
|
|
6509
|
-
branding: OrganizationModelBrandingSchema,
|
|
6510
|
-
navigation: OrganizationModelNavigationSchema,
|
|
6511
|
-
identity: IdentityDomainSchema.default(DEFAULT_ORGANIZATION_MODEL_IDENTITY),
|
|
6512
|
-
customers: CustomersDomainSchema.default(DEFAULT_ORGANIZATION_MODEL_CUSTOMERS),
|
|
6513
|
-
offerings: OfferingsDomainSchema.default(DEFAULT_ORGANIZATION_MODEL_OFFERINGS),
|
|
6514
|
-
roles: RolesDomainSchema.default(DEFAULT_ORGANIZATION_MODEL_ROLES),
|
|
6515
|
-
goals: GoalsDomainSchema.default(DEFAULT_ORGANIZATION_MODEL_GOALS),
|
|
6516
|
-
systems: SystemsDomainSchema.default(DEFAULT_ORGANIZATION_MODEL_SYSTEMS),
|
|
6517
|
-
ontology: OntologyScopeSchema.default(DEFAULT_ONTOLOGY_SCOPE),
|
|
6518
|
-
resources: ResourcesDomainSchema.default(DEFAULT_ORGANIZATION_MODEL_RESOURCES),
|
|
6519
|
-
topology: OmTopologyDomainSchema.default(DEFAULT_ORGANIZATION_MODEL_TOPOLOGY),
|
|
6520
|
-
actions: ActionsDomainSchema.default(DEFAULT_ORGANIZATION_MODEL_ACTIONS),
|
|
6521
|
-
entities: EntitiesDomainSchema.default(DEFAULT_ORGANIZATION_MODEL_ENTITIES),
|
|
6522
|
-
policies: PoliciesDomainSchema.default(DEFAULT_ORGANIZATION_MODEL_POLICIES),
|
|
6523
|
-
// D3: flat Record<id, OrgKnowledgeNode> — no wrapper object
|
|
6524
|
-
knowledge: KnowledgeDomainSchema.default({})
|
|
6525
|
-
});
|
|
6526
|
-
function addIssue(ctx, path, message) {
|
|
6527
|
-
ctx.addIssue({
|
|
6528
|
-
code: z.ZodIssueCode.custom,
|
|
6529
|
-
path,
|
|
6530
|
-
message
|
|
6531
|
-
});
|
|
6532
|
-
}
|
|
6533
|
-
function isLifecycleEnabled(lifecycle, enabled) {
|
|
6534
|
-
if (enabled === false) return false;
|
|
6535
|
-
return lifecycle !== "deprecated" && lifecycle !== "archived";
|
|
6536
|
-
}
|
|
6537
|
-
function defaultSystemPathFor(id) {
|
|
6538
|
-
return `/${id.replaceAll(".", "/")}`;
|
|
6539
|
-
}
|
|
6540
|
-
function asRoleHolderArray(heldBy) {
|
|
6541
|
-
return Array.isArray(heldBy) ? heldBy : [heldBy];
|
|
6542
|
-
}
|
|
6543
|
-
function isKnowledgeKindCompatibleWithTarget(knowledgeKind, targetKind) {
|
|
6544
|
-
if (knowledgeKind === "reference") return true;
|
|
6545
|
-
if (knowledgeKind === "playbook") {
|
|
6546
|
-
return ["system", "resource", "stage", "action", "ontology"].includes(targetKind);
|
|
6547
|
-
}
|
|
6548
|
-
if (knowledgeKind === "strategy") {
|
|
6549
|
-
return ["system", "goal", "offering", "customer-segment", "ontology"].includes(targetKind);
|
|
6550
|
-
}
|
|
6551
|
-
return false;
|
|
6552
|
-
}
|
|
6553
|
-
function isRecord(value) {
|
|
6554
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
6555
|
-
}
|
|
6556
|
-
OrganizationModelSchemaBase.superRefine((model, ctx) => {
|
|
6557
|
-
function collectAllSystems(systems, prefix = "", schemaPath = ["systems"]) {
|
|
6558
|
-
const result = [];
|
|
6559
|
-
for (const [key, system] of Object.entries(systems)) {
|
|
6560
|
-
const path = prefix ? `${prefix}.${key}` : key;
|
|
6561
|
-
const currentSchemaPath = [...schemaPath, key];
|
|
6562
|
-
result.push({ path, schemaPath: currentSchemaPath, system });
|
|
6563
|
-
const childSystems = system.systems ?? system.subsystems;
|
|
6564
|
-
if (childSystems !== void 0) {
|
|
6565
|
-
result.push(
|
|
6566
|
-
...collectAllSystems(childSystems, path, [
|
|
6567
|
-
...currentSchemaPath,
|
|
6568
|
-
system.systems !== void 0 ? "systems" : "subsystems"
|
|
6569
|
-
])
|
|
6570
|
-
);
|
|
6571
|
-
}
|
|
6572
|
-
}
|
|
6573
|
-
return result;
|
|
6574
|
-
}
|
|
6575
|
-
const allSystems = collectAllSystems(model.systems);
|
|
6576
|
-
const systemsById = /* @__PURE__ */ new Map();
|
|
6577
|
-
for (const { path, system } of allSystems) {
|
|
6578
|
-
systemsById.set(path, system);
|
|
6579
|
-
systemsById.set(system.id, system);
|
|
6580
|
-
}
|
|
6581
|
-
const systemIdsByEffectivePath = /* @__PURE__ */ new Map();
|
|
6582
|
-
allSystems.forEach(({ path, schemaPath, system }) => {
|
|
6583
|
-
if (system.parentSystemId !== void 0 && !systemsById.has(system.parentSystemId)) {
|
|
6584
|
-
addIssue(
|
|
6585
|
-
ctx,
|
|
6586
|
-
[...schemaPath, "parentSystemId"],
|
|
6587
|
-
`System "${system.id}" references unknown parent "${system.parentSystemId}"`
|
|
6588
|
-
);
|
|
6589
|
-
}
|
|
6590
|
-
const hasChildren = Object.keys(system.systems ?? system.subsystems ?? {}).length > 0 || allSystems.some(
|
|
6591
|
-
(candidate) => candidate.path.startsWith(`${path}.`) && !candidate.path.slice(path.length + 1).includes(".")
|
|
6592
|
-
);
|
|
6593
|
-
const contributesRoutePath = system.ui?.path !== void 0 || system.path !== void 0 || !hasChildren;
|
|
6594
|
-
if (contributesRoutePath) {
|
|
6595
|
-
const effectivePath = system.ui?.path ?? system.path ?? defaultSystemPathFor(path);
|
|
6596
|
-
const existingSystemId = systemIdsByEffectivePath.get(effectivePath);
|
|
6597
|
-
if (existingSystemId !== void 0) {
|
|
6598
|
-
addIssue(
|
|
6599
|
-
ctx,
|
|
6600
|
-
[...schemaPath, system.ui?.path !== void 0 ? "ui" : "path"],
|
|
6601
|
-
`System "${path}" effective path "${effectivePath}" duplicates system "${existingSystemId}"`
|
|
6602
|
-
);
|
|
6603
|
-
} else {
|
|
6604
|
-
systemIdsByEffectivePath.set(effectivePath, path);
|
|
6605
|
-
}
|
|
6606
|
-
}
|
|
6607
|
-
if (hasChildren && isLifecycleEnabled(system.lifecycle, system.enabled)) {
|
|
6608
|
-
const hasEnabledDescendant = Object.values(system.systems ?? system.subsystems ?? {}).some(
|
|
6609
|
-
(candidate) => isLifecycleEnabled(candidate.lifecycle, candidate.enabled)
|
|
6610
|
-
) || allSystems.some(
|
|
6611
|
-
(candidate) => candidate.path.startsWith(`${path}.`) && !candidate.path.slice(path.length + 1).includes(".") && isLifecycleEnabled(candidate.system.lifecycle, candidate.system.enabled)
|
|
6612
|
-
);
|
|
6613
|
-
if (!hasEnabledDescendant) {
|
|
6614
|
-
addIssue(ctx, [...schemaPath, "lifecycle"], `System "${path}" is active but has no active descendants`);
|
|
6615
|
-
}
|
|
6616
|
-
}
|
|
6617
|
-
});
|
|
6618
|
-
allSystems.forEach(({ schemaPath, system }) => {
|
|
6619
|
-
const visited = /* @__PURE__ */ new Set();
|
|
6620
|
-
let currentParentId = system.parentSystemId;
|
|
6621
|
-
while (currentParentId !== void 0) {
|
|
6622
|
-
if (currentParentId === system.id || visited.has(currentParentId)) {
|
|
6623
|
-
addIssue(ctx, [...schemaPath, "parentSystemId"], `System "${system.id}" has a parent cycle`);
|
|
6624
|
-
return;
|
|
6625
|
-
}
|
|
6626
|
-
visited.add(currentParentId);
|
|
6627
|
-
currentParentId = systemsById.get(currentParentId)?.parentSystemId;
|
|
6628
|
-
}
|
|
6629
|
-
});
|
|
6630
|
-
function normalizeRoutePath(path) {
|
|
6631
|
-
return path.length > 1 ? path.replace(/\/+$/, "") : path;
|
|
6632
|
-
}
|
|
6633
|
-
const sidebarNodeIds = /* @__PURE__ */ new Map();
|
|
6634
|
-
const sidebarSurfacePaths = /* @__PURE__ */ new Map();
|
|
6635
|
-
const sidebarSurfaces = [];
|
|
6636
|
-
function collectSidebarNodes(nodes, schemaPath) {
|
|
6637
|
-
Object.entries(nodes).forEach(([nodeId, node]) => {
|
|
6638
|
-
const nodePath = [...schemaPath, nodeId];
|
|
6639
|
-
const existingNodePath = sidebarNodeIds.get(nodeId);
|
|
6640
|
-
if (existingNodePath !== void 0) {
|
|
6641
|
-
addIssue(ctx, nodePath, `Sidebar node id "${nodeId}" duplicates another sidebar node`);
|
|
6642
|
-
} else {
|
|
6643
|
-
sidebarNodeIds.set(nodeId, nodePath);
|
|
6644
|
-
}
|
|
6645
|
-
if (node.type === "group") {
|
|
6646
|
-
collectSidebarNodes(node.children, [...nodePath, "children"]);
|
|
6647
|
-
return;
|
|
6648
|
-
}
|
|
6649
|
-
sidebarSurfaces.push({ id: nodeId, node, path: nodePath });
|
|
6650
|
-
const normalizedPath = normalizeRoutePath(node.path);
|
|
6651
|
-
const existingSurfaceId = sidebarSurfacePaths.get(normalizedPath);
|
|
6652
|
-
if (existingSurfaceId !== void 0) {
|
|
6653
|
-
addIssue(
|
|
6654
|
-
ctx,
|
|
6655
|
-
[...nodePath, "path"],
|
|
6656
|
-
`Sidebar surface path "${node.path}" duplicates surface "${existingSurfaceId}"`
|
|
6657
|
-
);
|
|
6658
|
-
} else {
|
|
6659
|
-
sidebarSurfacePaths.set(normalizedPath, nodeId);
|
|
6660
|
-
}
|
|
6661
|
-
node.targets?.systems?.forEach((systemId, systemIndex) => {
|
|
6662
|
-
if (!systemsById.has(systemId)) {
|
|
6663
|
-
addIssue(
|
|
6664
|
-
ctx,
|
|
6665
|
-
[...nodePath, "targets", "systems", systemIndex],
|
|
6666
|
-
`Sidebar surface "${nodeId}" references unknown system "${systemId}"`
|
|
6667
|
-
);
|
|
6668
|
-
}
|
|
6669
|
-
});
|
|
6670
|
-
});
|
|
6671
|
-
}
|
|
6672
|
-
collectSidebarNodes(model.navigation.sidebar.primary, ["navigation", "sidebar", "primary"]);
|
|
6673
|
-
collectSidebarNodes(model.navigation.sidebar.bottom, ["navigation", "sidebar", "bottom"]);
|
|
6674
|
-
const segmentsById = new Map(Object.entries(model.customers));
|
|
6675
|
-
Object.values(model.offerings).forEach((product) => {
|
|
6676
|
-
product.targetSegmentIds.forEach((segmentId, segmentIndex) => {
|
|
6677
|
-
if (!segmentsById.has(segmentId)) {
|
|
6678
|
-
addIssue(
|
|
6679
|
-
ctx,
|
|
6680
|
-
["offerings", product.id, "targetSegmentIds", segmentIndex],
|
|
6681
|
-
`Product "${product.id}" references unknown customer segment "${segmentId}"`
|
|
6682
|
-
);
|
|
6683
|
-
}
|
|
6684
|
-
});
|
|
6685
|
-
if (product.deliveryFeatureId !== void 0 && !systemsById.has(product.deliveryFeatureId)) {
|
|
6686
|
-
addIssue(
|
|
6687
|
-
ctx,
|
|
6688
|
-
["offerings", product.id, "deliveryFeatureId"],
|
|
6689
|
-
`Product "${product.id}" references unknown delivery system "${product.deliveryFeatureId}"`
|
|
6690
|
-
);
|
|
6691
|
-
}
|
|
6692
|
-
});
|
|
6693
|
-
Object.values(model.goals).forEach((objective) => {
|
|
6694
|
-
if (objective.periodEnd <= objective.periodStart) {
|
|
6695
|
-
addIssue(
|
|
6696
|
-
ctx,
|
|
6697
|
-
["goals", objective.id, "periodEnd"],
|
|
6698
|
-
`Goal "${objective.id}" has periodEnd "${objective.periodEnd}" which must be strictly after periodStart "${objective.periodStart}"`
|
|
6699
|
-
);
|
|
6700
|
-
}
|
|
6701
|
-
});
|
|
6702
|
-
const goalsById = new Map(Object.entries(model.goals));
|
|
6703
|
-
const knowledgeById = new Map(Object.entries(model.knowledge));
|
|
6704
|
-
const actionsById = new Map(Object.entries(model.actions));
|
|
6705
|
-
const entitiesById = new Map(Object.entries(model.entities));
|
|
6706
|
-
const policiesById = new Map(Object.entries(model.policies));
|
|
6707
|
-
sidebarSurfaces.forEach(({ id, node, path }) => {
|
|
6708
|
-
node.targets?.entities?.forEach((entityId, entityIndex) => {
|
|
6709
|
-
if (!entitiesById.has(entityId)) {
|
|
6710
|
-
addIssue(
|
|
6711
|
-
ctx,
|
|
6712
|
-
[...path, "targets", "entities", entityIndex],
|
|
6713
|
-
`Sidebar surface "${id}" references unknown entity "${entityId}"`
|
|
6714
|
-
);
|
|
6715
|
-
}
|
|
6716
|
-
});
|
|
6717
|
-
node.targets?.actions?.forEach((actionId, actionIndex) => {
|
|
6718
|
-
if (!actionsById.has(actionId)) {
|
|
6719
|
-
addIssue(
|
|
6720
|
-
ctx,
|
|
6721
|
-
[...path, "targets", "actions", actionIndex],
|
|
6722
|
-
`Sidebar surface "${id}" references unknown action "${actionId}"`
|
|
6723
|
-
);
|
|
6724
|
-
}
|
|
6725
|
-
});
|
|
6726
|
-
});
|
|
6727
|
-
Object.values(model.entities).forEach((entity) => {
|
|
6728
|
-
if (!systemsById.has(entity.ownedBySystemId)) {
|
|
6729
|
-
addIssue(
|
|
6730
|
-
ctx,
|
|
6731
|
-
["entities", entity.id, "ownedBySystemId"],
|
|
6732
|
-
`Entity "${entity.id}" references unknown ownedBySystemId "${entity.ownedBySystemId}"`
|
|
6733
|
-
);
|
|
6734
|
-
}
|
|
6735
|
-
entity.links?.forEach((link, linkIndex) => {
|
|
6736
|
-
if (!entitiesById.has(link.toEntity)) {
|
|
6737
|
-
addIssue(
|
|
6738
|
-
ctx,
|
|
6739
|
-
["entities", entity.id, "links", linkIndex, "toEntity"],
|
|
6740
|
-
`Entity "${entity.id}" links to unknown entity "${link.toEntity}"`
|
|
6741
|
-
);
|
|
6742
|
-
}
|
|
6743
|
-
});
|
|
6744
|
-
});
|
|
6745
|
-
const rolesById = new Map(Object.entries(model.roles));
|
|
6746
|
-
Object.values(model.roles).forEach((role) => {
|
|
6747
|
-
if (role.reportsToId !== void 0 && !rolesById.has(role.reportsToId)) {
|
|
6748
|
-
addIssue(
|
|
6749
|
-
ctx,
|
|
6750
|
-
["roles", role.id, "reportsToId"],
|
|
6751
|
-
`Role "${role.id}" references unknown reportsToId "${role.reportsToId}"`
|
|
6752
|
-
);
|
|
6753
|
-
}
|
|
6754
|
-
});
|
|
6755
|
-
Object.values(model.roles).forEach((role) => {
|
|
6756
|
-
const visited = /* @__PURE__ */ new Set();
|
|
6757
|
-
let currentReportsToId = role.reportsToId;
|
|
6758
|
-
while (currentReportsToId !== void 0) {
|
|
6759
|
-
if (currentReportsToId === role.id || visited.has(currentReportsToId)) {
|
|
6760
|
-
addIssue(ctx, ["roles", role.id, "reportsToId"], `Role "${role.id}" has a reportsToId cycle`);
|
|
6761
|
-
return;
|
|
6762
|
-
}
|
|
6763
|
-
visited.add(currentReportsToId);
|
|
6764
|
-
currentReportsToId = rolesById.get(currentReportsToId)?.reportsToId;
|
|
6765
|
-
}
|
|
6766
|
-
});
|
|
6767
|
-
Object.values(model.roles).forEach((role) => {
|
|
6768
|
-
role.responsibleFor?.forEach((systemId, systemIndex) => {
|
|
6769
|
-
if (!systemsById.has(systemId)) {
|
|
6770
|
-
addIssue(
|
|
6771
|
-
ctx,
|
|
6772
|
-
["roles", role.id, "responsibleFor", systemIndex],
|
|
6773
|
-
`Role "${role.id}" references unknown responsibleFor system "${systemId}"`
|
|
6774
|
-
);
|
|
6775
|
-
}
|
|
6776
|
-
});
|
|
6777
|
-
});
|
|
6778
|
-
allSystems.forEach(({ schemaPath, system }) => {
|
|
6779
|
-
if (system.responsibleRoleId !== void 0 && !rolesById.has(system.responsibleRoleId)) {
|
|
6780
|
-
addIssue(
|
|
6781
|
-
ctx,
|
|
6782
|
-
[...schemaPath, "responsibleRoleId"],
|
|
6783
|
-
`System "${system.id}" references unknown responsibleRoleId "${system.responsibleRoleId}"`
|
|
6784
|
-
);
|
|
6785
|
-
}
|
|
6786
|
-
system.governedByKnowledge?.forEach((nodeId, nodeIndex) => {
|
|
6787
|
-
if (!knowledgeById.has(nodeId)) {
|
|
6788
|
-
addIssue(
|
|
6789
|
-
ctx,
|
|
6790
|
-
[...schemaPath, "governedByKnowledge", nodeIndex],
|
|
6791
|
-
`System "${system.id}" references unknown knowledge node "${nodeId}"`
|
|
6792
|
-
);
|
|
6793
|
-
}
|
|
6794
|
-
});
|
|
6795
|
-
system.drivesGoals?.forEach((goalId, goalIndex) => {
|
|
6796
|
-
if (!goalsById.has(goalId)) {
|
|
6797
|
-
addIssue(
|
|
6798
|
-
ctx,
|
|
6799
|
-
[...schemaPath, "drivesGoals", goalIndex],
|
|
6800
|
-
`System "${system.id}" references unknown goal "${goalId}"`
|
|
6801
|
-
);
|
|
6802
|
-
}
|
|
6803
|
-
});
|
|
6804
|
-
system.actions?.forEach((actionRef, actionIndex) => {
|
|
6805
|
-
if (!actionsById.has(actionRef.actionId)) {
|
|
6806
|
-
addIssue(
|
|
6807
|
-
ctx,
|
|
6808
|
-
[...schemaPath, "actions", actionIndex, "actionId"],
|
|
6809
|
-
`System "${system.id}" references unknown action "${actionRef.actionId}"`
|
|
6810
|
-
);
|
|
6811
|
-
}
|
|
6812
|
-
});
|
|
6813
|
-
system.policies?.forEach((policyId, policyIndex) => {
|
|
6814
|
-
if (!policiesById.has(policyId)) {
|
|
6815
|
-
addIssue(
|
|
6816
|
-
ctx,
|
|
6817
|
-
[...schemaPath, "policies", policyIndex],
|
|
6818
|
-
`System "${system.id}" references unknown policy "${policyId}"`
|
|
6819
|
-
);
|
|
6820
|
-
}
|
|
6821
|
-
});
|
|
6822
|
-
});
|
|
6823
|
-
Object.values(model.actions).forEach((action) => {
|
|
6824
|
-
action.affects?.forEach((entityId, entityIndex) => {
|
|
6825
|
-
if (!entitiesById.has(entityId)) {
|
|
6826
|
-
addIssue(
|
|
6827
|
-
ctx,
|
|
6828
|
-
["actions", action.id, "affects", entityIndex],
|
|
6829
|
-
`Action "${action.id}" affects unknown entity "${entityId}"`
|
|
6830
|
-
);
|
|
6831
|
-
}
|
|
6832
|
-
});
|
|
6833
|
-
});
|
|
6834
|
-
const resourcesById = new Map(Object.entries(model.resources));
|
|
6835
|
-
sidebarSurfaces.forEach(({ id, node, path }) => {
|
|
6836
|
-
node.targets?.resources?.forEach((resourceId, resourceIndex) => {
|
|
6837
|
-
if (!resourcesById.has(resourceId)) {
|
|
6838
|
-
addIssue(
|
|
6839
|
-
ctx,
|
|
6840
|
-
[...path, "targets", "resources", resourceIndex],
|
|
6841
|
-
`Sidebar surface "${id}" references unknown resource "${resourceId}"`
|
|
6842
|
-
);
|
|
6843
|
-
}
|
|
6844
|
-
});
|
|
6845
|
-
});
|
|
6846
|
-
const actionIds = new Set(Object.keys(model.actions));
|
|
6847
|
-
const offeringsById = new Map(Object.entries(model.offerings));
|
|
6848
|
-
const ontologyCompilation = compileOrganizationOntology(model);
|
|
6849
|
-
const stageIds = /* @__PURE__ */ new Set();
|
|
6850
|
-
for (const catalog of Object.values(ontologyCompilation.ontology.catalogTypes)) {
|
|
6851
|
-
if (catalog.kind !== "stage") continue;
|
|
6852
|
-
for (const stageId of Object.keys(catalog.entries ?? {})) {
|
|
6853
|
-
stageIds.add(stageId);
|
|
6854
|
-
}
|
|
6855
|
-
}
|
|
6856
|
-
const ontologyIndexByKind = {
|
|
6857
|
-
object: ontologyCompilation.ontology.objectTypes,
|
|
6858
|
-
link: ontologyCompilation.ontology.linkTypes,
|
|
6859
|
-
action: ontologyCompilation.ontology.actionTypes,
|
|
6860
|
-
catalog: ontologyCompilation.ontology.catalogTypes,
|
|
6861
|
-
event: ontologyCompilation.ontology.eventTypes,
|
|
6862
|
-
interface: ontologyCompilation.ontology.interfaceTypes,
|
|
6863
|
-
"value-type": ontologyCompilation.ontology.valueTypes,
|
|
6864
|
-
property: ontologyCompilation.ontology.sharedProperties,
|
|
6865
|
-
group: ontologyCompilation.ontology.groups,
|
|
6866
|
-
surface: ontologyCompilation.ontology.surfaces
|
|
6867
|
-
};
|
|
6868
|
-
const ontologyIds = new Set(Object.values(ontologyIndexByKind).flatMap((index) => Object.keys(index)));
|
|
6869
|
-
function topologyTargetExists(ref) {
|
|
6870
|
-
if (ref.kind === "system") return systemsById.has(ref.id);
|
|
6871
|
-
if (ref.kind === "resource") return resourcesById.has(ref.id);
|
|
6872
|
-
if (ref.kind === "ontology") return ontologyIds.has(ref.id);
|
|
6873
|
-
if (ref.kind === "policy") return policiesById.has(ref.id);
|
|
6874
|
-
if (ref.kind === "role") return rolesById.has(ref.id);
|
|
6875
|
-
return true;
|
|
6876
|
-
}
|
|
6877
|
-
Object.entries(model.topology.relationships).forEach(([relationshipId, relationship]) => {
|
|
6878
|
-
["from", "to"].forEach((side) => {
|
|
6879
|
-
const ref = relationship[side];
|
|
6880
|
-
if (topologyTargetExists(ref)) return;
|
|
6881
|
-
addIssue(
|
|
6882
|
-
ctx,
|
|
6883
|
-
["topology", "relationships", relationshipId, side],
|
|
6884
|
-
`Topology relationship "${relationshipId}" ${side} references unknown ${ref.kind} "${ref.id}"`
|
|
6885
|
-
);
|
|
6886
|
-
});
|
|
6887
|
-
});
|
|
6888
|
-
const ontologyReferenceKeyKinds = {
|
|
6889
|
-
valueType: "value-type",
|
|
6890
|
-
catalogType: "catalog",
|
|
6891
|
-
objectType: "object",
|
|
6892
|
-
eventType: "event",
|
|
6893
|
-
actionType: "action",
|
|
6894
|
-
linkType: "link",
|
|
6895
|
-
interfaceType: "interface",
|
|
6896
|
-
propertyType: "property",
|
|
6897
|
-
groupType: "group",
|
|
6898
|
-
surfaceType: "surface",
|
|
6899
|
-
stepCatalog: "catalog"
|
|
6900
|
-
};
|
|
6901
|
-
function validateKnownOntologyReferences(ownerId, value, path, seen = /* @__PURE__ */ new WeakSet()) {
|
|
6902
|
-
if (Array.isArray(value)) {
|
|
6903
|
-
value.forEach((entry, index) => validateKnownOntologyReferences(ownerId, entry, [...path, index], seen));
|
|
6904
|
-
return;
|
|
6905
|
-
}
|
|
6906
|
-
if (!isRecord(value)) return;
|
|
6907
|
-
if (seen.has(value)) return;
|
|
6908
|
-
seen.add(value);
|
|
6909
|
-
Object.entries(value).forEach(([key, entry]) => {
|
|
6910
|
-
const expectedKind = ontologyReferenceKeyKinds[key];
|
|
6911
|
-
if (expectedKind !== void 0) {
|
|
6912
|
-
if (typeof entry !== "string") {
|
|
6913
|
-
addIssue(ctx, [...path, key], `Ontology record "${ownerId}" ${key} must be an ontology ID string`);
|
|
6914
|
-
} else if (ontologyIndexByKind[expectedKind][entry] === void 0) {
|
|
6915
|
-
addIssue(
|
|
6916
|
-
ctx,
|
|
6917
|
-
[...path, key],
|
|
6918
|
-
`Ontology record "${ownerId}" ${key} references unknown ${expectedKind} ontology ID "${entry}"`
|
|
6919
|
-
);
|
|
6920
|
-
}
|
|
6921
|
-
}
|
|
6922
|
-
validateKnownOntologyReferences(ownerId, entry, [...path, key], seen);
|
|
6923
|
-
});
|
|
6924
|
-
}
|
|
6925
|
-
for (const { id, record } of listResolvedOntologyRecords(ontologyCompilation.ontology)) {
|
|
6926
|
-
validateKnownOntologyReferences(id, record, record.origin.path);
|
|
6927
|
-
}
|
|
6928
|
-
Object.values(model.policies).forEach((policy) => {
|
|
6929
|
-
policy.appliesTo.systemIds.forEach((systemId, systemIndex) => {
|
|
6930
|
-
if (!systemsById.has(systemId)) {
|
|
6931
|
-
addIssue(
|
|
6932
|
-
ctx,
|
|
6933
|
-
["policies", policy.id, "appliesTo", "systemIds", systemIndex],
|
|
6934
|
-
`Policy "${policy.id}" applies to unknown system "${systemId}"`
|
|
6935
|
-
);
|
|
6936
|
-
}
|
|
6937
|
-
});
|
|
6938
|
-
policy.appliesTo.actionIds.forEach((actionId, actionIndex) => {
|
|
6939
|
-
if (!actionsById.has(actionId)) {
|
|
6940
|
-
addIssue(
|
|
6941
|
-
ctx,
|
|
6942
|
-
["policies", policy.id, "appliesTo", "actionIds", actionIndex],
|
|
6943
|
-
`Policy "${policy.id}" applies to unknown action "${actionId}"`
|
|
6944
|
-
);
|
|
6945
|
-
}
|
|
6946
|
-
});
|
|
6947
|
-
policy.actions.forEach((action, actionIndex) => {
|
|
6948
|
-
if (action.kind === "invoke-action" && !actionsById.has(action.actionId)) {
|
|
6949
|
-
addIssue(
|
|
6950
|
-
ctx,
|
|
6951
|
-
["policies", policy.id, "actions", actionIndex, "actionId"],
|
|
6952
|
-
`Policy "${policy.id}" invokes unknown action "${action.actionId}"`
|
|
6953
|
-
);
|
|
6954
|
-
}
|
|
6955
|
-
if ((action.kind === "notify-role" || action.kind === "require-approval") && action.roleId !== void 0 && !rolesById.has(action.roleId)) {
|
|
6956
|
-
addIssue(
|
|
6957
|
-
ctx,
|
|
6958
|
-
["policies", policy.id, "actions", actionIndex, "roleId"],
|
|
6959
|
-
`Policy "${policy.id}" references unknown role "${action.roleId}"`
|
|
6960
|
-
);
|
|
6961
|
-
}
|
|
6962
|
-
});
|
|
6963
|
-
if (policy.trigger.kind === "action-invocation" && !actionsById.has(policy.trigger.actionId)) {
|
|
6964
|
-
addIssue(
|
|
6965
|
-
ctx,
|
|
6966
|
-
["policies", policy.id, "trigger", "actionId"],
|
|
6967
|
-
`Policy "${policy.id}" references unknown trigger action "${policy.trigger.actionId}"`
|
|
6968
|
-
);
|
|
6969
|
-
}
|
|
6970
|
-
});
|
|
6971
|
-
function knowledgeTargetExists(kind, id) {
|
|
6972
|
-
if (kind === "system") return systemsById.has(id);
|
|
6973
|
-
if (kind === "resource") return resourcesById.has(id);
|
|
6974
|
-
if (kind === "knowledge") return knowledgeById.has(id);
|
|
6975
|
-
if (kind === "stage") return stageIds.has(id);
|
|
6976
|
-
if (kind === "action") return actionIds.has(id);
|
|
6977
|
-
if (kind === "role") return rolesById.has(id);
|
|
6978
|
-
if (kind === "goal") return goalsById.has(id);
|
|
6979
|
-
if (kind === "customer-segment") return segmentsById.has(id);
|
|
6980
|
-
if (kind === "offering") return offeringsById.has(id);
|
|
6981
|
-
if (kind === "ontology") return ontologyIds.has(id);
|
|
6982
|
-
return false;
|
|
6983
|
-
}
|
|
6984
|
-
Object.entries(model.knowledge).forEach(([nodeId, node]) => {
|
|
6985
|
-
node.links.forEach((link, linkIndex) => {
|
|
6986
|
-
if (!knowledgeTargetExists(link.target.kind, link.target.id)) {
|
|
6987
|
-
addIssue(
|
|
6988
|
-
ctx,
|
|
6989
|
-
["knowledge", nodeId, "links", linkIndex, "target"],
|
|
6990
|
-
`Knowledge node "${node.id}" references unknown ${link.target.kind} target "${link.target.id}"`
|
|
6991
|
-
);
|
|
6992
|
-
}
|
|
6993
|
-
if (!isKnowledgeKindCompatibleWithTarget(node.kind, link.target.kind)) {
|
|
6994
|
-
addIssue(
|
|
6995
|
-
ctx,
|
|
6996
|
-
["knowledge", nodeId, "links", linkIndex, "target", "kind"],
|
|
6997
|
-
`Knowledge node "${node.id}" kind "${node.kind}" cannot govern ${link.target.kind} targets`
|
|
6998
|
-
);
|
|
6999
|
-
}
|
|
7000
|
-
});
|
|
7001
|
-
});
|
|
7002
|
-
Object.values(model.resources).forEach((resource) => {
|
|
7003
|
-
if (!systemsById.has(resource.systemPath)) {
|
|
7004
|
-
addIssue(
|
|
7005
|
-
ctx,
|
|
7006
|
-
["resources", resource.id, "systemPath"],
|
|
7007
|
-
`Resource "${resource.id}" references unknown system path "${resource.systemPath}"`
|
|
7008
|
-
);
|
|
7009
|
-
}
|
|
7010
|
-
if (resource.ownerRoleId !== void 0 && !rolesById.has(resource.ownerRoleId)) {
|
|
7011
|
-
addIssue(
|
|
7012
|
-
ctx,
|
|
7013
|
-
["resources", resource.id, "ownerRoleId"],
|
|
7014
|
-
`Resource "${resource.id}" references unknown ownerRoleId "${resource.ownerRoleId}"`
|
|
7015
|
-
);
|
|
7016
|
-
}
|
|
7017
|
-
if (resource.kind === "agent" && resource.actsAsRoleId !== void 0 && !rolesById.has(resource.actsAsRoleId)) {
|
|
7018
|
-
addIssue(
|
|
7019
|
-
ctx,
|
|
7020
|
-
["resources", resource.id, "actsAsRoleId"],
|
|
7021
|
-
`Agent resource "${resource.id}" references unknown actsAsRoleId "${resource.actsAsRoleId}"`
|
|
7022
|
-
);
|
|
7023
|
-
}
|
|
7024
|
-
});
|
|
7025
|
-
function validateResourceOntologyBinding(resourceId, bindingKey, expectedKind, ids) {
|
|
7026
|
-
const ontologyIds2 = ids === void 0 ? [] : Array.isArray(ids) ? ids : [ids];
|
|
7027
|
-
ontologyIds2.forEach((ontologyId, ontologyIndex) => {
|
|
7028
|
-
if (ontologyIndexByKind[expectedKind][ontologyId] === void 0) {
|
|
7029
|
-
addIssue(
|
|
7030
|
-
ctx,
|
|
7031
|
-
["resources", resourceId, "ontology", bindingKey, ...Array.isArray(ids) ? [ontologyIndex] : []],
|
|
7032
|
-
`Resource "${resourceId}" ontology binding "${bindingKey}" references unknown ${expectedKind} ontology ID "${ontologyId}"`
|
|
7033
|
-
);
|
|
7034
|
-
}
|
|
7035
|
-
});
|
|
7036
|
-
}
|
|
7037
|
-
Object.values(model.resources).forEach((resource) => {
|
|
7038
|
-
const binding = resource.ontology;
|
|
7039
|
-
if (binding === void 0) return;
|
|
7040
|
-
validateResourceOntologyBinding(resource.id, "actions", "action", binding.actions);
|
|
7041
|
-
validateResourceOntologyBinding(resource.id, "primaryAction", "action", binding.primaryAction);
|
|
7042
|
-
validateResourceOntologyBinding(resource.id, "reads", "object", binding.reads);
|
|
7043
|
-
validateResourceOntologyBinding(resource.id, "writes", "object", binding.writes);
|
|
7044
|
-
validateResourceOntologyBinding(resource.id, "usesCatalogs", "catalog", binding.usesCatalogs);
|
|
7045
|
-
validateResourceOntologyBinding(resource.id, "emits", "event", binding.emits);
|
|
7046
|
-
if (binding.contract !== void 0) {
|
|
7047
|
-
const contractEntries = [
|
|
7048
|
-
["input", binding.contract.input],
|
|
7049
|
-
["output", binding.contract.output]
|
|
7050
|
-
];
|
|
7051
|
-
for (const [side, ref] of contractEntries) {
|
|
7052
|
-
if (ref === void 0) continue;
|
|
7053
|
-
const result = ContractRefSchema.safeParse(ref);
|
|
7054
|
-
if (!result.success) {
|
|
7055
|
-
addIssue(
|
|
7056
|
-
ctx,
|
|
7057
|
-
["resources", resource.id, "ontology", "contract", side],
|
|
7058
|
-
`Resource "${resource.id}" contract.${side} "${ref}" is not a valid ContractRef (expected "package/subpath#ExportName")`
|
|
7059
|
-
);
|
|
7060
|
-
}
|
|
7061
|
-
}
|
|
7062
|
-
}
|
|
7063
|
-
});
|
|
7064
|
-
Object.values(model.roles).forEach((role) => {
|
|
7065
|
-
if (role.heldBy === void 0) return;
|
|
7066
|
-
asRoleHolderArray(role.heldBy).forEach((holder, holderIndex) => {
|
|
7067
|
-
if (holder.kind !== "agent") return;
|
|
7068
|
-
const resource = resourcesById.get(holder.agentId);
|
|
7069
|
-
if (resource === void 0) {
|
|
7070
|
-
addIssue(
|
|
7071
|
-
ctx,
|
|
7072
|
-
["roles", role.id, "heldBy", Array.isArray(role.heldBy) ? holderIndex : "agentId"],
|
|
7073
|
-
`Role "${role.id}" references unknown agent holder resource "${holder.agentId}"`
|
|
7074
|
-
);
|
|
7075
|
-
return;
|
|
7076
|
-
}
|
|
7077
|
-
if (resource.kind !== "agent") {
|
|
7078
|
-
addIssue(
|
|
7079
|
-
ctx,
|
|
7080
|
-
["roles", role.id, "heldBy", Array.isArray(role.heldBy) ? holderIndex : "agentId"],
|
|
7081
|
-
`Role "${role.id}" agent holder "${holder.agentId}" must reference an agent resource`
|
|
7082
|
-
);
|
|
7083
|
-
}
|
|
7084
|
-
});
|
|
7085
|
-
});
|
|
7086
|
-
Object.entries(model.knowledge).forEach(([nodeId, node]) => {
|
|
7087
|
-
node.ownerIds.forEach((roleId, ownerIndex) => {
|
|
7088
|
-
if (!rolesById.has(roleId)) {
|
|
7089
|
-
addIssue(
|
|
7090
|
-
ctx,
|
|
7091
|
-
["knowledge", nodeId, "ownerIds", ownerIndex],
|
|
7092
|
-
`Knowledge node "${node.id}" references unknown owner role "${roleId}"`
|
|
7093
|
-
);
|
|
7094
|
-
}
|
|
7095
|
-
});
|
|
7096
|
-
});
|
|
7097
|
-
for (const diagnostic of ontologyCompilation.diagnostics) {
|
|
7098
|
-
addIssue(ctx, diagnostic.path, diagnostic.message);
|
|
7099
|
-
}
|
|
7100
|
-
});
|
|
7101
|
-
|
|
7102
|
-
// ../core/src/organization-model/defaults.ts
|
|
7103
|
-
var DEFAULT_ORGANIZATION_MODEL_KNOWLEDGE = {};
|
|
7104
|
-
var DEFAULT_ORGANIZATION_MODEL_ENTITIES2 = {};
|
|
7105
|
-
var DEFAULT_ORGANIZATION_MODEL_NAVIGATION = {
|
|
7106
|
-
sidebar: {
|
|
7107
|
-
primary: {},
|
|
7108
|
-
bottom: {}
|
|
7109
|
-
}
|
|
7110
|
-
};
|
|
7111
|
-
var DEFAULT_ORGANIZATION_MODEL = {
|
|
7112
|
-
version: 1,
|
|
7113
|
-
domainMetadata: DEFAULT_ORGANIZATION_MODEL_DOMAIN_METADATA,
|
|
7114
|
-
branding: DEFAULT_ORGANIZATION_MODEL_BRANDING,
|
|
7115
|
-
navigation: DEFAULT_ORGANIZATION_MODEL_NAVIGATION,
|
|
7116
|
-
identity: DEFAULT_ORGANIZATION_MODEL_IDENTITY,
|
|
7117
|
-
customers: DEFAULT_ORGANIZATION_MODEL_CUSTOMERS,
|
|
7118
|
-
offerings: DEFAULT_ORGANIZATION_MODEL_OFFERINGS,
|
|
7119
|
-
roles: DEFAULT_ORGANIZATION_MODEL_ROLES,
|
|
7120
|
-
goals: DEFAULT_ORGANIZATION_MODEL_GOALS,
|
|
7121
|
-
// Generic empty systems map. Elevasis-specific systems (platform, sales, sales.crm,
|
|
7122
|
-
// sales.lead-gen, monitoring, settings, admin, etc.) have been relocated to
|
|
7123
|
-
// `@repo/elevasis-core/src/organization-model/systems.ts` via `canonicalOrganizationModel`.
|
|
7124
|
-
// Tenant OM configs supply their own systems via `resolveOrganizationModel`.
|
|
7125
|
-
systems: {},
|
|
7126
|
-
ontology: DEFAULT_ONTOLOGY_SCOPE,
|
|
7127
|
-
resources: DEFAULT_ORGANIZATION_MODEL_RESOURCES,
|
|
7128
|
-
topology: DEFAULT_ORGANIZATION_MODEL_TOPOLOGY,
|
|
7129
|
-
// Generic empty actions map. Elevasis-specific action entries have been relocated to
|
|
7130
|
-
// `@repo/elevasis-core/src/organization-model/actions.ts`.
|
|
7131
|
-
actions: {},
|
|
7132
|
-
entities: DEFAULT_ORGANIZATION_MODEL_ENTITIES2,
|
|
7133
|
-
policies: DEFAULT_ORGANIZATION_MODEL_POLICIES,
|
|
7134
|
-
knowledge: DEFAULT_ORGANIZATION_MODEL_KNOWLEDGE
|
|
7135
|
-
};
|
|
7136
|
-
var SalesStageSemanticClassSchema = z.enum(["open", "active", "nurturing", "closed_won", "closed_lost"]);
|
|
7137
|
-
var SalesStageSchema = DisplayMetadataSchema.extend({
|
|
7138
|
-
id: ModelIdSchema,
|
|
7139
|
-
order: z.number().int().min(0),
|
|
7140
|
-
semanticClass: SalesStageSemanticClassSchema,
|
|
7141
|
-
surfaceIds: ReferenceIdsSchema,
|
|
7142
|
-
resourceIds: ReferenceIdsSchema
|
|
7143
|
-
});
|
|
7144
|
-
z.object({
|
|
7145
|
-
id: ModelIdSchema,
|
|
7146
|
-
label: z.string().trim().min(1).max(120),
|
|
7147
|
-
description: DescriptionSchema.optional(),
|
|
7148
|
-
entityId: ModelIdSchema,
|
|
7149
|
-
stages: z.array(SalesStageSchema).min(1)
|
|
7150
|
-
});
|
|
7151
|
-
var CRM_DISCOVERY_REPLIED_STATE = {
|
|
7152
|
-
stateKey: "discovery_replied",
|
|
7153
|
-
label: "Discovery Replied"
|
|
7154
|
-
};
|
|
7155
|
-
var CRM_DISCOVERY_LINK_SENT_STATE = {
|
|
7156
|
-
stateKey: "discovery_link_sent",
|
|
7157
|
-
label: "Discovery Link Sent"
|
|
7158
|
-
};
|
|
7159
|
-
var CRM_DISCOVERY_NUDGING_STATE = {
|
|
7160
|
-
stateKey: "discovery_nudging",
|
|
7161
|
-
label: "Discovery Nudging"
|
|
7162
|
-
};
|
|
7163
|
-
var CRM_DISCOVERY_BOOKING_CANCELLED_STATE = {
|
|
7164
|
-
stateKey: "discovery_booking_cancelled",
|
|
7165
|
-
label: "Discovery Booking Cancelled"
|
|
7166
|
-
};
|
|
7167
|
-
var CRM_REPLY_SENT_STATE = {
|
|
7168
|
-
stateKey: "reply_sent",
|
|
7169
|
-
label: "Reply Sent"
|
|
7170
|
-
};
|
|
7171
|
-
var CRM_FOLLOWUP_1_SENT_STATE = {
|
|
7172
|
-
stateKey: "followup_1_sent",
|
|
7173
|
-
label: "Follow-up 1 Sent"
|
|
7174
|
-
};
|
|
7175
|
-
var CRM_FOLLOWUP_2_SENT_STATE = {
|
|
7176
|
-
stateKey: "followup_2_sent",
|
|
7177
|
-
label: "Follow-up 2 Sent"
|
|
7178
|
-
};
|
|
7179
|
-
var CRM_FOLLOWUP_3_SENT_STATE = {
|
|
7180
|
-
stateKey: "followup_3_sent",
|
|
7181
|
-
label: "Follow-up 3 Sent"
|
|
7182
|
-
};
|
|
7183
|
-
var CRM_PIPELINE_DEFINITION = {
|
|
7184
|
-
pipelineKey: "crm",
|
|
7185
|
-
label: "CRM",
|
|
7186
|
-
entityKey: "crm.deal",
|
|
7187
|
-
stages: [
|
|
7188
|
-
{
|
|
7189
|
-
stageKey: "interested",
|
|
7190
|
-
label: "Interested",
|
|
7191
|
-
color: "blue",
|
|
7192
|
-
states: [
|
|
7193
|
-
CRM_DISCOVERY_REPLIED_STATE,
|
|
7194
|
-
CRM_DISCOVERY_LINK_SENT_STATE,
|
|
7195
|
-
CRM_DISCOVERY_NUDGING_STATE,
|
|
7196
|
-
CRM_DISCOVERY_BOOKING_CANCELLED_STATE,
|
|
7197
|
-
CRM_REPLY_SENT_STATE,
|
|
7198
|
-
CRM_FOLLOWUP_1_SENT_STATE,
|
|
7199
|
-
CRM_FOLLOWUP_2_SENT_STATE,
|
|
7200
|
-
CRM_FOLLOWUP_3_SENT_STATE
|
|
7201
|
-
]
|
|
7202
|
-
},
|
|
7203
|
-
{ stageKey: "proposal", label: "Proposal", color: "yellow", states: [] },
|
|
7204
|
-
{ stageKey: "closing", label: "Closing", color: "orange", states: [] },
|
|
7205
|
-
{ stageKey: "closed_won", label: "Closed Won", color: "green", states: [] },
|
|
7206
|
-
{ stageKey: "closed_lost", label: "Closed Lost", color: "red", states: [] },
|
|
7207
|
-
{ stageKey: "nurturing", label: "Nurturing", color: "grape", states: [] }
|
|
7208
|
-
]
|
|
7209
|
-
};
|
|
7210
|
-
|
|
7211
|
-
// ../core/src/organization-model/migration-helpers.ts
|
|
7212
|
-
function catalogRecords(model) {
|
|
7213
|
-
return Object.values(compileOrganizationOntology(model).ontology.catalogTypes);
|
|
7214
|
-
}
|
|
7215
|
-
function systemScope(id, fallback) {
|
|
7216
|
-
return parseOntologyId(id).scope || fallback || "";
|
|
7217
|
-
}
|
|
7218
|
-
function entriesOf(catalog) {
|
|
7219
|
-
return Object.entries(catalog.entries ?? {}).map(([id, value]) => [
|
|
7220
|
-
id,
|
|
7221
|
-
value && typeof value === "object" && !Array.isArray(value) ? value : {}
|
|
7222
|
-
]);
|
|
7223
|
-
}
|
|
7224
|
-
function stringValue(value) {
|
|
7225
|
-
return typeof value === "string" ? value : void 0;
|
|
7226
|
-
}
|
|
7227
|
-
function stringArray(value) {
|
|
7228
|
-
return Array.isArray(value) ? value.filter((item) => typeof item === "string") : [];
|
|
7229
|
-
}
|
|
7230
|
-
function numberValue(value, fallback = 0) {
|
|
7231
|
-
return typeof value === "number" ? value : fallback;
|
|
7232
|
-
}
|
|
7233
|
-
function appliesToLocalId(catalog) {
|
|
7234
|
-
const appliesTo = catalog.appliesTo;
|
|
7235
|
-
if (appliesTo === void 0) return void 0;
|
|
7236
|
-
return parseOntologyId(appliesTo).localId;
|
|
7237
|
-
}
|
|
7238
|
-
function appliesToEntityKind(catalog) {
|
|
7239
|
-
const id = appliesToLocalId(catalog);
|
|
7240
|
-
if (id === "company" || id === "contact" || id === "project" || id === "milestone" || id === "task") return id;
|
|
7241
|
-
if (id === "deal") return void 0;
|
|
7242
|
-
return void 0;
|
|
7243
|
-
}
|
|
7244
|
-
function getLeadGenStageCatalog(model) {
|
|
7245
|
-
const results = {};
|
|
7246
|
-
for (const catalog of catalogRecords(model).filter(
|
|
7247
|
-
(record) => record.kind === "stage" && (record.ownerSystemId ?? systemScope(record.id)) === "sales.lead-gen"
|
|
7248
|
-
)) {
|
|
7249
|
-
const catalogEntity = appliesToEntityKind(catalog);
|
|
7250
|
-
if (catalogEntity !== "company" && catalogEntity !== "contact") continue;
|
|
7251
|
-
for (const [entryId, entry] of entriesOf(catalog)) {
|
|
7252
|
-
const entity = entry.entity === "contact" ? "contact" : entry.entity === "company" ? "company" : catalogEntity;
|
|
7253
|
-
const additionalEntities = stringArray(entry.additionalEntities).filter(
|
|
7254
|
-
(item) => item === "company" || item === "contact"
|
|
7255
|
-
);
|
|
7256
|
-
const recordEntity = entry.recordEntity === "company" || entry.recordEntity === "contact" ? entry.recordEntity : void 0;
|
|
7257
|
-
const recordStageKey = stringValue(entry.recordStageKey);
|
|
7258
|
-
results[entryId] = {
|
|
7259
|
-
key: entryId,
|
|
7260
|
-
label: stringValue(entry.label) ?? entryId,
|
|
7261
|
-
description: stringValue(entry.description) ?? "",
|
|
7262
|
-
order: numberValue(entry.order),
|
|
7263
|
-
entity,
|
|
7264
|
-
...additionalEntities.length > 0 ? { additionalEntities } : {},
|
|
7265
|
-
...recordEntity ? { recordEntity } : {},
|
|
7266
|
-
...recordStageKey ? { recordStageKey } : {}
|
|
7267
|
-
};
|
|
7268
|
-
}
|
|
7269
|
-
}
|
|
7270
|
-
return Object.fromEntries(
|
|
7271
|
-
Object.entries(results).sort(([, a], [, b]) => a.order - b.order || a.key.localeCompare(b.key))
|
|
7272
|
-
);
|
|
7273
|
-
}
|
|
7274
|
-
|
|
7275
|
-
// ../core/src/business/acquisition/ontology-validation.ts
|
|
7276
|
-
var CRM_PIPELINE_CATALOG_ONTOLOGY_ID = formatOntologyId({
|
|
7277
|
-
scope: "sales.crm",
|
|
7278
|
-
kind: "catalog",
|
|
7279
|
-
localId: "crm.pipeline"
|
|
7280
|
-
});
|
|
7281
|
-
var LEAD_GEN_STAGE_CATALOG_ONTOLOGY_ID = formatOntologyId({
|
|
7282
|
-
scope: "sales.lead-gen",
|
|
7283
|
-
kind: "catalog",
|
|
7284
|
-
localId: "lead-gen.stage-catalog"
|
|
7285
|
-
});
|
|
7286
|
-
var CRM_DEAL_OBJECT_ONTOLOGY_ID = formatOntologyId({
|
|
7287
|
-
scope: "sales.crm",
|
|
7288
|
-
kind: "object",
|
|
7289
|
-
localId: "crm.deal"
|
|
7290
|
-
});
|
|
7291
|
-
function createCrmPipelineCatalog() {
|
|
7292
|
-
return {
|
|
7293
|
-
id: CRM_PIPELINE_CATALOG_ONTOLOGY_ID,
|
|
7294
|
-
label: CRM_PIPELINE_DEFINITION.label,
|
|
7295
|
-
ownerSystemId: "sales.crm",
|
|
7296
|
-
kind: "pipeline",
|
|
7297
|
-
appliesTo: CRM_DEAL_OBJECT_ONTOLOGY_ID,
|
|
7298
|
-
entries: Object.fromEntries(
|
|
7299
|
-
CRM_PIPELINE_DEFINITION.stages.map((stage, index) => [
|
|
7300
|
-
stage.stageKey,
|
|
7301
|
-
{
|
|
7302
|
-
key: stage.stageKey,
|
|
7303
|
-
label: stage.label,
|
|
7304
|
-
order: (index + 1) * 10,
|
|
7305
|
-
...stage.color !== void 0 ? { color: stage.color } : {},
|
|
7306
|
-
states: stage.states.map((state) => ({ ...state }))
|
|
7307
|
-
}
|
|
7308
|
-
])
|
|
7309
|
-
),
|
|
7310
|
-
legacyPipelineKey: CRM_PIPELINE_DEFINITION.pipelineKey,
|
|
7311
|
-
legacyEntityKey: CRM_PIPELINE_DEFINITION.entityKey
|
|
7312
|
-
};
|
|
7313
|
-
}
|
|
7314
|
-
function createLeadGenStageCatalog(model) {
|
|
7315
|
-
return {
|
|
7316
|
-
id: LEAD_GEN_STAGE_CATALOG_ONTOLOGY_ID,
|
|
7317
|
-
label: "Lead Gen Processing Stages",
|
|
7318
|
-
ownerSystemId: "sales.lead-gen",
|
|
7319
|
-
kind: "processing-stage-catalog",
|
|
7320
|
-
entries: Object.fromEntries(
|
|
7321
|
-
Object.entries(getLeadGenStageCatalog(model)).map(([key, entry]) => [
|
|
7322
|
-
key,
|
|
7323
|
-
{
|
|
7324
|
-
...entry
|
|
7325
|
-
}
|
|
7326
|
-
])
|
|
7327
|
-
),
|
|
7328
|
-
legacyCatalogKey: "LEAD_GEN_STAGE_CATALOG"
|
|
7329
|
-
};
|
|
7330
|
-
}
|
|
7331
|
-
function isPlainRecord(value) {
|
|
7332
|
-
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
7333
|
-
}
|
|
7334
|
-
function mergeBridgeCatalogs(model) {
|
|
7335
|
-
const baseCatalogTypes = model.ontology?.catalogTypes ?? {};
|
|
7336
|
-
const bridgeCatalogTypes = {};
|
|
7337
|
-
if (baseCatalogTypes[CRM_PIPELINE_CATALOG_ONTOLOGY_ID] === void 0) {
|
|
7338
|
-
bridgeCatalogTypes[CRM_PIPELINE_CATALOG_ONTOLOGY_ID] = createCrmPipelineCatalog();
|
|
7339
|
-
}
|
|
7340
|
-
if (baseCatalogTypes[LEAD_GEN_STAGE_CATALOG_ONTOLOGY_ID] === void 0) {
|
|
7341
|
-
bridgeCatalogTypes[LEAD_GEN_STAGE_CATALOG_ONTOLOGY_ID] = createLeadGenStageCatalog(model);
|
|
7342
|
-
}
|
|
7343
|
-
if (Object.keys(bridgeCatalogTypes).length === 0) return model;
|
|
7344
|
-
return {
|
|
7345
|
-
...model,
|
|
7346
|
-
ontology: {
|
|
7347
|
-
...model.ontology ?? {},
|
|
7348
|
-
catalogTypes: {
|
|
7349
|
-
...baseCatalogTypes,
|
|
7350
|
-
...bridgeCatalogTypes
|
|
7351
|
-
}
|
|
7352
|
-
}
|
|
7353
|
-
};
|
|
7354
|
-
}
|
|
7355
|
-
function compileBusinessOntologyValidationIndex(model = DEFAULT_ORGANIZATION_MODEL) {
|
|
7356
|
-
const compilation = compileOrganizationOntology(mergeBridgeCatalogs(model));
|
|
7357
|
-
if (compilation.diagnostics.length > 0) {
|
|
7358
|
-
const summary = compilation.diagnostics.map((diagnostic) => diagnostic.message).join("; ");
|
|
7359
|
-
throw new Error(`Business ontology validation index failed to compile: ${summary}`);
|
|
7360
|
-
}
|
|
7361
|
-
const crmPipelineCatalog = compilation.ontology.catalogTypes[CRM_PIPELINE_CATALOG_ONTOLOGY_ID];
|
|
7362
|
-
const leadGenStageCatalog = compilation.ontology.catalogTypes[LEAD_GEN_STAGE_CATALOG_ONTOLOGY_ID];
|
|
7363
|
-
if (crmPipelineCatalog === void 0 || leadGenStageCatalog === void 0) {
|
|
7364
|
-
throw new Error("Business ontology validation index is missing CRM or lead-gen catalog bridge records");
|
|
7365
|
-
}
|
|
7366
|
-
return {
|
|
7367
|
-
ontology: compilation.ontology,
|
|
7368
|
-
crmPipelineCatalog,
|
|
7369
|
-
leadGenStageCatalog,
|
|
7370
|
-
actionTypesByLegacyId: indexActionTypesByLegacyId(compilation.ontology.actionTypes)
|
|
7371
|
-
};
|
|
7372
|
-
}
|
|
7373
|
-
function indexActionTypesByLegacyId(actionTypes) {
|
|
7374
|
-
const byLegacyId = {};
|
|
7375
|
-
for (const actionType of Object.values(actionTypes)) {
|
|
7376
|
-
const legacyActionId = actionType["legacyActionId"];
|
|
7377
|
-
if (typeof legacyActionId === "string") {
|
|
7378
|
-
byLegacyId[legacyActionId] = actionType;
|
|
7379
|
-
}
|
|
7380
|
-
}
|
|
7381
|
-
return byLegacyId;
|
|
7382
|
-
}
|
|
7383
|
-
var BUSINESS_ONTOLOGY_VALIDATION_INDEX = compileBusinessOntologyValidationIndex();
|
|
7384
|
-
function getCatalogEntries(catalog) {
|
|
7385
|
-
return isPlainRecord(catalog.entries) ? catalog.entries : {};
|
|
7386
|
-
}
|
|
7387
|
-
function asCrmStageEntry(key, value) {
|
|
7388
|
-
const record = isPlainRecord(value) ? value : {};
|
|
7389
|
-
const label = typeof record.label === "string" ? record.label : key;
|
|
7390
|
-
const order = typeof record.order === "number" ? record.order : 0;
|
|
7391
|
-
const color = typeof record.color === "string" ? record.color : void 0;
|
|
7392
|
-
const rawStates = Array.isArray(record.states) ? record.states : [];
|
|
7393
|
-
const states = rawStates.flatMap((state) => {
|
|
7394
|
-
if (!isPlainRecord(state) || typeof state.stateKey !== "string") return [];
|
|
7395
|
-
return [
|
|
7396
|
-
{
|
|
7397
|
-
stateKey: state.stateKey,
|
|
7398
|
-
label: typeof state.label === "string" ? state.label : state.stateKey
|
|
7399
|
-
}
|
|
7400
|
-
];
|
|
7401
|
-
});
|
|
7402
|
-
return {
|
|
7403
|
-
key,
|
|
7404
|
-
label,
|
|
7405
|
-
order,
|
|
7406
|
-
...color !== void 0 ? { color } : {},
|
|
7407
|
-
states
|
|
7408
|
-
};
|
|
7409
|
-
}
|
|
7410
|
-
var CRM_STAGE_KEYS_FROM_ONTOLOGY = Object.keys(
|
|
7411
|
-
getCatalogEntries(BUSINESS_ONTOLOGY_VALIDATION_INDEX.crmPipelineCatalog)
|
|
7412
|
-
);
|
|
7413
|
-
var CRM_STATE_KEYS_FROM_ONTOLOGY = Object.values(
|
|
7414
|
-
getCatalogEntries(BUSINESS_ONTOLOGY_VALIDATION_INDEX.crmPipelineCatalog)
|
|
7415
|
-
).flatMap((entry, index) => {
|
|
7416
|
-
const stageKey = CRM_STAGE_KEYS_FROM_ONTOLOGY[index];
|
|
7417
|
-
if (stageKey === void 0) return [];
|
|
7418
|
-
return asCrmStageEntry(stageKey, entry).states.map((state) => state.stateKey);
|
|
7419
|
-
});
|
|
7420
|
-
Object.keys(
|
|
7421
|
-
getCatalogEntries(BUSINESS_ONTOLOGY_VALIDATION_INDEX.leadGenStageCatalog)
|
|
7422
|
-
);
|
|
7423
|
-
|
|
7424
|
-
// ../core/src/business/acquisition/api-schemas.ts
|
|
7425
|
-
var ProcessingStageStatusSchema = z.enum(["success", "no_result", "skipped", "error"]);
|
|
7426
|
-
var LeadGenStageKeySchema = z.string().trim().min(1);
|
|
7427
|
-
var LeadGenActionKeySchema = z.string().trim().min(1);
|
|
7428
|
-
var crmStageKeys = CRM_STAGE_KEYS_FROM_ONTOLOGY;
|
|
7429
|
-
var crmStateKeys = CRM_STATE_KEYS_FROM_ONTOLOGY;
|
|
7430
|
-
var CrmStageKeySchema = z.enum(crmStageKeys);
|
|
7431
|
-
var CrmStateKeySchema = z.enum(crmStateKeys);
|
|
7432
|
-
var ProcessingStateEntrySchema = z.object({
|
|
7433
|
-
status: ProcessingStageStatusSchema,
|
|
7434
|
-
data: z.unknown().optional()
|
|
7435
|
-
}).passthrough();
|
|
7436
|
-
var ProcessingStateSchema = z.record(LeadGenStageKeySchema, ProcessingStateEntrySchema);
|
|
7437
|
-
var CompanyProcessingStateSchema = ProcessingStateSchema;
|
|
7438
|
-
var ContactProcessingStateSchema = ProcessingStateSchema;
|
|
7439
|
-
var DealStageSchema = CrmStageKeySchema;
|
|
7440
|
-
var AcqDealTaskKindSchema = z.enum(["call", "email", "meeting", "other"]);
|
|
7441
|
-
z.object({
|
|
7442
|
-
dealId: UuidSchema
|
|
7443
|
-
});
|
|
7444
|
-
z.object({
|
|
7445
|
-
dealId: UuidSchema,
|
|
7446
|
-
taskId: UuidSchema
|
|
5128
|
+
z.object({
|
|
5129
|
+
dealId: UuidSchema,
|
|
5130
|
+
taskId: UuidSchema
|
|
7447
5131
|
});
|
|
7448
5132
|
z.object({
|
|
7449
5133
|
stage: DealStageSchema.optional(),
|
|
@@ -7686,8 +5370,10 @@ var PipelineStageSchema = z.object({
|
|
|
7686
5370
|
enabled: z.boolean().optional(),
|
|
7687
5371
|
order: z.number().int().optional()
|
|
7688
5372
|
});
|
|
5373
|
+
var DataModeSchema = z.enum(["mock", "live"]);
|
|
7689
5374
|
var PipelineConfigSchema = z.object({
|
|
7690
|
-
stages: z.array(PipelineStageSchema).optional()
|
|
5375
|
+
stages: z.array(PipelineStageSchema).optional(),
|
|
5376
|
+
dataMode: DataModeSchema.optional()
|
|
7691
5377
|
});
|
|
7692
5378
|
var BuildPlanSnapshotStepSchema = z.object({
|
|
7693
5379
|
id: z.string().trim().min(1).max(100),
|
|
@@ -7744,9 +5430,7 @@ var BuildPlanSnapshotSchema = z.object({
|
|
|
7744
5430
|
var AcqListMetadataSchema = z.object({
|
|
7745
5431
|
buildPlanSnapshot: BuildPlanSnapshotSchema.optional()
|
|
7746
5432
|
}).catchall(z.unknown());
|
|
7747
|
-
var ProspectingBuildTemplateIdSchema = z.string().trim().min(1).max(100)
|
|
7748
|
-
message: "buildTemplateId must match a known prospecting build template"
|
|
7749
|
-
});
|
|
5433
|
+
var ProspectingBuildTemplateIdSchema = z.string().trim().min(1).max(100);
|
|
7750
5434
|
var ListStageCountsSchema = z.object({
|
|
7751
5435
|
// Attempted counts by canonical lead-gen stage. The detailed status
|
|
7752
5436
|
// distribution lives on ListProgress; telemetry keeps the overview payload small.
|
|
@@ -8499,25 +6183,31 @@ function createApifyAdapter(credential) {
|
|
|
8499
6183
|
return createAdapter("apify", METHODS2, credential);
|
|
8500
6184
|
}
|
|
8501
6185
|
|
|
6186
|
+
// src/worker/adapters/clickup.ts
|
|
6187
|
+
var METHODS3 = ["verify", "createTask"];
|
|
6188
|
+
function createClickUpAdapter(credential) {
|
|
6189
|
+
return createAdapter("clickup", METHODS3, credential);
|
|
6190
|
+
}
|
|
6191
|
+
|
|
8502
6192
|
// src/worker/adapters/dropbox.ts
|
|
8503
|
-
var
|
|
6193
|
+
var METHODS4 = [
|
|
8504
6194
|
"uploadFile",
|
|
8505
6195
|
"createFolder"
|
|
8506
6196
|
];
|
|
8507
6197
|
function createDropboxAdapter(credential) {
|
|
8508
|
-
return createAdapter("dropbox",
|
|
6198
|
+
return createAdapter("dropbox", METHODS4, credential);
|
|
8509
6199
|
}
|
|
8510
6200
|
|
|
8511
6201
|
// src/worker/adapters/gmail.ts
|
|
8512
|
-
var
|
|
6202
|
+
var METHODS5 = [
|
|
8513
6203
|
"sendEmail"
|
|
8514
6204
|
];
|
|
8515
6205
|
function createGmailAdapter(credential) {
|
|
8516
|
-
return createAdapter("gmail",
|
|
6206
|
+
return createAdapter("gmail", METHODS5, credential);
|
|
8517
6207
|
}
|
|
8518
6208
|
|
|
8519
6209
|
// src/worker/adapters/google-sheets.ts
|
|
8520
|
-
var
|
|
6210
|
+
var METHODS6 = [
|
|
8521
6211
|
"readSheet",
|
|
8522
6212
|
"writeSheet",
|
|
8523
6213
|
"appendRows",
|
|
@@ -8533,11 +6223,11 @@ var METHODS5 = [
|
|
|
8533
6223
|
"deleteRowByValue"
|
|
8534
6224
|
];
|
|
8535
6225
|
function createGoogleSheetsAdapter(credential) {
|
|
8536
|
-
return createAdapter("google-sheets",
|
|
6226
|
+
return createAdapter("google-sheets", METHODS6, credential);
|
|
8537
6227
|
}
|
|
8538
6228
|
|
|
8539
6229
|
// src/worker/adapters/instantly.ts
|
|
8540
|
-
var
|
|
6230
|
+
var METHODS7 = [
|
|
8541
6231
|
"sendReply",
|
|
8542
6232
|
"removeFromSubsequence",
|
|
8543
6233
|
"getEmails",
|
|
@@ -8561,54 +6251,54 @@ var METHODS6 = [
|
|
|
8561
6251
|
"patchLead"
|
|
8562
6252
|
];
|
|
8563
6253
|
function createInstantlyAdapter(credential) {
|
|
8564
|
-
return createAdapter("instantly",
|
|
6254
|
+
return createAdapter("instantly", METHODS7, credential);
|
|
8565
6255
|
}
|
|
8566
6256
|
|
|
8567
6257
|
// src/worker/adapters/millionverifier.ts
|
|
8568
|
-
var
|
|
6258
|
+
var METHODS8 = ["verifyEmail", "checkCredits"];
|
|
8569
6259
|
function createMillionVerifierAdapter(credential) {
|
|
8570
|
-
return createAdapter("millionverifier",
|
|
6260
|
+
return createAdapter("millionverifier", METHODS8, credential);
|
|
8571
6261
|
}
|
|
8572
6262
|
|
|
8573
6263
|
// src/worker/adapters/anymailfinder.ts
|
|
8574
|
-
var
|
|
6264
|
+
var METHODS9 = [
|
|
8575
6265
|
"findCompanyEmail",
|
|
8576
6266
|
"findPersonEmail",
|
|
8577
6267
|
"findDecisionMakerEmail",
|
|
8578
6268
|
"verifyEmail"
|
|
8579
6269
|
];
|
|
8580
6270
|
function createAnymailfinderAdapter(credential) {
|
|
8581
|
-
return createAdapter("anymailfinder",
|
|
6271
|
+
return createAdapter("anymailfinder", METHODS9, credential);
|
|
8582
6272
|
}
|
|
8583
6273
|
|
|
8584
6274
|
// src/worker/adapters/tomba.ts
|
|
8585
|
-
var
|
|
6275
|
+
var METHODS10 = ["emailFinder", "domainSearch", "emailVerifier"];
|
|
8586
6276
|
function createTombaAdapter(credential) {
|
|
8587
|
-
return createAdapter("tomba",
|
|
6277
|
+
return createAdapter("tomba", METHODS10, credential);
|
|
8588
6278
|
}
|
|
8589
6279
|
|
|
8590
6280
|
// src/worker/adapters/resend.ts
|
|
8591
|
-
var
|
|
6281
|
+
var METHODS11 = [
|
|
8592
6282
|
"sendEmail",
|
|
8593
6283
|
"getEmail"
|
|
8594
6284
|
];
|
|
8595
6285
|
function createResendAdapter(credential) {
|
|
8596
|
-
return createAdapter("resend",
|
|
6286
|
+
return createAdapter("resend", METHODS11, credential);
|
|
8597
6287
|
}
|
|
8598
6288
|
|
|
8599
6289
|
// src/worker/adapters/signature-api.ts
|
|
8600
|
-
var
|
|
6290
|
+
var METHODS12 = [
|
|
8601
6291
|
"createEnvelope",
|
|
8602
6292
|
"voidEnvelope",
|
|
8603
6293
|
"downloadDocument",
|
|
8604
6294
|
"getEnvelope"
|
|
8605
6295
|
];
|
|
8606
6296
|
function createSignatureApiAdapter(credential) {
|
|
8607
|
-
return createAdapter("signature-api",
|
|
6297
|
+
return createAdapter("signature-api", METHODS12, credential);
|
|
8608
6298
|
}
|
|
8609
6299
|
|
|
8610
6300
|
// src/worker/adapters/stripe.ts
|
|
8611
|
-
var
|
|
6301
|
+
var METHODS13 = [
|
|
8612
6302
|
"createPaymentLink",
|
|
8613
6303
|
"getPaymentLink",
|
|
8614
6304
|
"updatePaymentLink",
|
|
@@ -8617,7 +6307,7 @@ var METHODS12 = [
|
|
|
8617
6307
|
"createCheckoutSession"
|
|
8618
6308
|
];
|
|
8619
6309
|
function createStripeAdapter(credential) {
|
|
8620
|
-
return createAdapter("stripe",
|
|
6310
|
+
return createAdapter("stripe", METHODS13, credential);
|
|
8621
6311
|
}
|
|
8622
6312
|
|
|
8623
6313
|
// src/worker/adapters/scheduler.ts
|
|
@@ -8819,7 +6509,9 @@ function assertNoReservedInputKeys(schema) {
|
|
|
8819
6509
|
}
|
|
8820
6510
|
const reservedKeys = ["params", "batch"].filter((key) => Object.prototype.hasOwnProperty.call(shape, key));
|
|
8821
6511
|
if (reservedKeys.length > 0) {
|
|
8822
|
-
throw new Error(
|
|
6512
|
+
throw new Error(
|
|
6513
|
+
`listBuilderWorkflow inputSchema cannot define reserved top-level key(s): ${reservedKeys.join(", ")}`
|
|
6514
|
+
);
|
|
8823
6515
|
}
|
|
8824
6516
|
}
|
|
8825
6517
|
function resolveListAdapter(context) {
|
|
@@ -8829,9 +6521,13 @@ function resolveListAdapter(context) {
|
|
|
8829
6521
|
function getRecordId(record) {
|
|
8830
6522
|
return record.id;
|
|
8831
6523
|
}
|
|
8832
|
-
function assertResultStageTarget(result, defaultStageKey) {
|
|
8833
|
-
|
|
8834
|
-
|
|
6524
|
+
function assertResultStageTarget(result, defaultStageKey, primaryEntity) {
|
|
6525
|
+
if (result.entity !== primaryEntity && result.stageKey === void 0) {
|
|
6526
|
+
throw new Error(
|
|
6527
|
+
`[list-builder] cross-entity result for "${result.id}" is a ${result.entity} but the step's primary entity is ${primaryEntity}; set result.stageKey to a ${result.entity} stage.`
|
|
6528
|
+
);
|
|
6529
|
+
}
|
|
6530
|
+
return result.stageKey ?? defaultStageKey;
|
|
8835
6531
|
}
|
|
8836
6532
|
async function filterPendingRecords(records, params, context, options) {
|
|
8837
6533
|
if (params.forceRefresh) {
|
|
@@ -8851,7 +6547,7 @@ async function filterPendingRecords(records, params, context, options) {
|
|
|
8851
6547
|
const pending = new Set(pendingIds);
|
|
8852
6548
|
return records.filter((record) => pending.has(getRecordId(record)));
|
|
8853
6549
|
}
|
|
8854
|
-
async function dispatchResults(envelope, context) {
|
|
6550
|
+
async function dispatchResults(envelope, context, primaryEntity) {
|
|
8855
6551
|
if (!envelope.batch.listId) {
|
|
8856
6552
|
if (envelope.results.length > 0) {
|
|
8857
6553
|
context.logger.warn(
|
|
@@ -8862,7 +6558,7 @@ async function dispatchResults(envelope, context) {
|
|
|
8862
6558
|
}
|
|
8863
6559
|
const listAdapter = resolveListAdapter(context);
|
|
8864
6560
|
for (const result of envelope.results) {
|
|
8865
|
-
const stage = assertResultStageTarget(result, envelope.batch.stageKey);
|
|
6561
|
+
const stage = assertResultStageTarget(result, envelope.batch.stageKey, primaryEntity);
|
|
8866
6562
|
if (result.entity === "company") {
|
|
8867
6563
|
await listAdapter.updateCompanyStage({
|
|
8868
6564
|
listId: envelope.batch.listId,
|
|
@@ -8887,6 +6583,11 @@ async function dispatchResults(envelope, context) {
|
|
|
8887
6583
|
}
|
|
8888
6584
|
function listBuilderWorkflow(options) {
|
|
8889
6585
|
const stageKey = ListBuilderStageKeySchema.parse(options.buildStep.stageKey);
|
|
6586
|
+
if (options.stageValidators && !options.stageValidators.isLeadGenStageKey(stageKey)) {
|
|
6587
|
+
throw new Error(
|
|
6588
|
+
`[list-builder] invalid buildStep.stageKey "${stageKey}" \u2014 not a known lead-gen stage in the injected stage catalog.`
|
|
6589
|
+
);
|
|
6590
|
+
}
|
|
8890
6591
|
assertNoReservedInputKeys(options.inputSchema);
|
|
8891
6592
|
const outputSchema = options.outputSchema ?? ListBuilderResultsSchema;
|
|
8892
6593
|
const batchSchema = z.object({
|
|
@@ -8960,7 +6661,7 @@ function listBuilderWorkflow(options) {
|
|
|
8960
6661
|
outputSchema,
|
|
8961
6662
|
handler: async (rawInput, context) => {
|
|
8962
6663
|
const envelope = envelopeSchema.parse(rawInput);
|
|
8963
|
-
const results = await dispatchResults(envelope, context);
|
|
6664
|
+
const results = await dispatchResults(envelope, context, options.buildStep.primaryEntity);
|
|
8964
6665
|
return outputSchema.parse(results);
|
|
8965
6666
|
},
|
|
8966
6667
|
next: null
|
|
@@ -9000,34 +6701,11 @@ function captureConsole(executionId, logs) {
|
|
|
9000
6701
|
postLog
|
|
9001
6702
|
};
|
|
9002
6703
|
}
|
|
9003
|
-
|
|
9004
|
-
|
|
9005
|
-
if (value === null || value === void 0) return value;
|
|
9006
|
-
if (typeof value === "string") {
|
|
9007
|
-
return value.length > LOG_STRING_TRUNCATE_LIMIT ? value.slice(0, LOG_STRING_TRUNCATE_LIMIT) + `\u2026 [${value.length} chars]` : value;
|
|
9008
|
-
}
|
|
9009
|
-
if (Array.isArray(value)) {
|
|
9010
|
-
return value.map(truncateForLogging);
|
|
9011
|
-
}
|
|
9012
|
-
if (typeof value === "object") {
|
|
9013
|
-
const result = {};
|
|
9014
|
-
for (const [k, v] of Object.entries(value)) {
|
|
9015
|
-
result[k] = truncateForLogging(v);
|
|
9016
|
-
}
|
|
9017
|
-
return result;
|
|
9018
|
-
}
|
|
9019
|
-
return value;
|
|
9020
|
-
}
|
|
9021
|
-
function resolveNext(next, data) {
|
|
9022
|
-
if (next === null) return null;
|
|
9023
|
-
if (next.type === "linear") return next.target;
|
|
9024
|
-
for (const route of next.routes) {
|
|
9025
|
-
if (route.condition(data)) return route.target;
|
|
9026
|
-
}
|
|
9027
|
-
return next.default;
|
|
6704
|
+
function isZodSchema(schema) {
|
|
6705
|
+
return typeof schema === "object" && schema !== null && "parse" in schema && "_def" in schema;
|
|
9028
6706
|
}
|
|
9029
6707
|
function safeZodToJsonSchema(schema) {
|
|
9030
|
-
if (!
|
|
6708
|
+
if (!isZodSchema(schema)) return void 0;
|
|
9031
6709
|
try {
|
|
9032
6710
|
const result = zodToJsonSchema(schema, { $refStrategy: "none", errorMessages: true });
|
|
9033
6711
|
if (result && typeof result === "object" && Object.keys(result).some((k) => k !== "$schema")) {
|
|
@@ -9046,84 +6724,28 @@ async function executeWorkflow(workflow, input, context) {
|
|
|
9046
6724
|
const logs = [];
|
|
9047
6725
|
const { restore, postLog } = captureConsole(context.executionId, logs);
|
|
9048
6726
|
try {
|
|
9049
|
-
|
|
9050
|
-
|
|
9051
|
-
|
|
9052
|
-
|
|
9053
|
-
|
|
9054
|
-
|
|
9055
|
-
|
|
9056
|
-
|
|
9057
|
-
|
|
9058
|
-
|
|
9059
|
-
|
|
9060
|
-
|
|
9061
|
-
|
|
9062
|
-
|
|
9063
|
-
|
|
9064
|
-
|
|
9065
|
-
|
|
9066
|
-
|
|
9067
|
-
const rawOutput = await step.handler(stepInput, {
|
|
9068
|
-
executionId: context.executionId,
|
|
9069
|
-
organizationId: context.organizationId,
|
|
9070
|
-
organizationName: context.organizationName,
|
|
9071
|
-
resourceId: workflow.config.resourceId,
|
|
9072
|
-
sessionId: context.sessionId,
|
|
9073
|
-
sessionTurnNumber: context.sessionTurnNumber,
|
|
9074
|
-
parentExecutionId: context.parentExecutionId,
|
|
9075
|
-
executionDepth: context.executionDepth,
|
|
9076
|
-
adapters: context.adapters,
|
|
9077
|
-
store: /* @__PURE__ */ new Map(),
|
|
9078
|
-
logger: {
|
|
9079
|
-
debug: (msg) => console.log(`[debug] ${msg}`),
|
|
9080
|
-
info: (msg) => console.log(`[info] ${msg}`),
|
|
9081
|
-
warn: (msg) => console.warn(`[warn] ${msg}`),
|
|
9082
|
-
error: (msg) => console.error(`[error] ${msg}`)
|
|
9083
|
-
}
|
|
9084
|
-
});
|
|
9085
|
-
currentData = step.outputSchema.parse(rawOutput);
|
|
9086
|
-
const stepEndTime = Date.now();
|
|
9087
|
-
const nextStepId = resolveNext(step.next, currentData);
|
|
9088
|
-
postLog("info", `Step '${step.name}' completed (${stepEndTime - stepStartTime}ms)`, {
|
|
9089
|
-
type: "workflow",
|
|
9090
|
-
contextType: "step-completed",
|
|
9091
|
-
stepId: step.id,
|
|
9092
|
-
stepStatus: "completed",
|
|
9093
|
-
output: truncateForLogging(currentData),
|
|
9094
|
-
duration: stepEndTime - stepStartTime,
|
|
9095
|
-
isTerminal: nextStepId === null,
|
|
9096
|
-
startTime: stepStartTime,
|
|
9097
|
-
endTime: stepEndTime
|
|
9098
|
-
});
|
|
9099
|
-
if (step.next?.type === "conditional" && nextStepId !== null) {
|
|
9100
|
-
postLog("info", `Routing from '${step.name}' to '${nextStepId}'`, {
|
|
9101
|
-
type: "workflow",
|
|
9102
|
-
contextType: "conditional-route",
|
|
9103
|
-
stepId: step.id,
|
|
9104
|
-
target: nextStepId
|
|
9105
|
-
});
|
|
9106
|
-
}
|
|
9107
|
-
stepId = nextStepId;
|
|
9108
|
-
} catch (err) {
|
|
9109
|
-
const stepEndTime = Date.now();
|
|
9110
|
-
postLog("error", `Step '${step.name}' failed: ${String(err)}`, {
|
|
9111
|
-
type: "workflow",
|
|
9112
|
-
contextType: "step-failed",
|
|
9113
|
-
stepId: step.id,
|
|
9114
|
-
stepStatus: "failed",
|
|
9115
|
-
error: String(err),
|
|
9116
|
-
duration: stepEndTime - stepStartTime,
|
|
9117
|
-
startTime: stepStartTime,
|
|
9118
|
-
endTime: stepEndTime
|
|
9119
|
-
});
|
|
9120
|
-
throw err;
|
|
6727
|
+
const workflowInstance = new Workflow(workflow);
|
|
6728
|
+
const workerContext = {
|
|
6729
|
+
executionId: context.executionId,
|
|
6730
|
+
organizationId: context.organizationId,
|
|
6731
|
+
organizationName: context.organizationName,
|
|
6732
|
+
resourceId: workflow.config.resourceId,
|
|
6733
|
+
sessionId: context.sessionId,
|
|
6734
|
+
sessionTurnNumber: context.sessionTurnNumber,
|
|
6735
|
+
parentExecutionId: context.parentExecutionId,
|
|
6736
|
+
executionDepth: context.executionDepth,
|
|
6737
|
+
signal: context.signal,
|
|
6738
|
+
adapters: context.adapters,
|
|
6739
|
+
store: /* @__PURE__ */ new Map(),
|
|
6740
|
+
logger: {
|
|
6741
|
+
debug: (message, logContext) => postLog("debug", message, logContext),
|
|
6742
|
+
info: (message, logContext) => postLog("info", message, logContext),
|
|
6743
|
+
warn: (message, logContext) => postLog("warn", message, logContext),
|
|
6744
|
+
error: (message, logContext) => postLog("error", message, logContext)
|
|
9121
6745
|
}
|
|
9122
|
-
}
|
|
9123
|
-
|
|
9124
|
-
|
|
9125
|
-
}
|
|
9126
|
-
return { output: currentData, logs };
|
|
6746
|
+
};
|
|
6747
|
+
const output = await workflowInstance.execute(input, workerContext);
|
|
6748
|
+
return { output, logs };
|
|
9127
6749
|
} finally {
|
|
9128
6750
|
restore();
|
|
9129
6751
|
}
|
|
@@ -9262,7 +6884,8 @@ function startWorker(org) {
|
|
|
9262
6884
|
sessionId,
|
|
9263
6885
|
sessionTurnNumber,
|
|
9264
6886
|
parentExecutionId,
|
|
9265
|
-
executionDepth: executionDepth ?? 0
|
|
6887
|
+
executionDepth: executionDepth ?? 0,
|
|
6888
|
+
signal: localAbortController.signal
|
|
9266
6889
|
});
|
|
9267
6890
|
const durationMs = Date.now() - startTime;
|
|
9268
6891
|
console.log(`[SDK-WORKER] Workflow '${resourceId}' completed (${durationMs}ms)`);
|
|
@@ -9306,9 +6929,10 @@ function startWorker(org) {
|
|
|
9306
6929
|
parentPort.postMessage({ type: "result", status: "completed", output, logs, metrics: { durationMs } });
|
|
9307
6930
|
} catch (err) {
|
|
9308
6931
|
const durationMs = Date.now() - startTime;
|
|
9309
|
-
const
|
|
9310
|
-
|
|
9311
|
-
|
|
6932
|
+
const errorRecord = err instanceof Error ? err : void 0;
|
|
6933
|
+
const errorMessage = errorRecord?.message ?? String(err);
|
|
6934
|
+
err !== null && typeof err === "object" && "code" in err ? String(err.code) : "unknown";
|
|
6935
|
+
const errorName = errorRecord?.name ?? (err !== null && typeof err === "object" && err.constructor?.name ? err.constructor.name : "Error");
|
|
9312
6936
|
console.error(`[SDK-WORKER] Agent '${resourceId}' failed (${durationMs}ms): [${errorName}] ${errorMessage}`);
|
|
9313
6937
|
parentPort.postMessage({
|
|
9314
6938
|
type: "result",
|
|
@@ -9340,4 +6964,4 @@ if (workerData != null && workerData.kind === "static") {
|
|
|
9340
6964
|
})();
|
|
9341
6965
|
}
|
|
9342
6966
|
|
|
9343
|
-
export { ListBuilderResultSchema, ListBuilderResultsSchema, PlatformToolError, acqDb, approval, classifyPlatformToolError, createAdapter, createAnymailfinderAdapter, createApifyAdapter, createAttioAdapter, createDropboxAdapter, createGmailAdapter, createGoogleSheetsAdapter, createInstantlyAdapter, createMillionVerifierAdapter, createResendAdapter, createSignatureApiAdapter, createStripeAdapter, createTombaAdapter, crm, email, executeWorkflow, execution, generateHmacToken, list, listBuilderWorkflow, llm, notifications, pdf, platform, projects, scheduler, startWorker, storage };
|
|
6967
|
+
export { ListBuilderResultSchema, ListBuilderResultsSchema, PlatformToolError, acqDb, approval, classifyPlatformToolError, createAdapter, createAnymailfinderAdapter, createApifyAdapter, createAttioAdapter, createClickUpAdapter, createDropboxAdapter, createGmailAdapter, createGoogleSheetsAdapter, createInstantlyAdapter, createMillionVerifierAdapter, createResendAdapter, createSignatureApiAdapter, createStripeAdapter, createTombaAdapter, crm, email, executeWorkflow, execution, generateHmacToken, list, listBuilderWorkflow, llm, notifications, pdf, platform, projects, scheduler, startWorker, storage };
|