@elevasis/ui 2.34.0 → 2.36.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.
Files changed (116) hide show
  1. package/dist/api/index.js +3 -3
  2. package/dist/app/index.d.ts +37 -30
  3. package/dist/app/index.js +25 -23
  4. package/dist/charts/index.js +3 -5
  5. package/dist/{chunk-ND5TDV2J.js → chunk-57OZ3AEG.js} +1 -1
  6. package/dist/{chunk-E4WQGJNS.js → chunk-7FPLLSHN.js} +14 -1
  7. package/dist/{chunk-RQA2EVN3.js → chunk-AKW7KISS.js} +39 -3
  8. package/dist/chunk-AUDNF2Q7.js +2050 -0
  9. package/dist/chunk-F6EFC2MJ.js +41101 -0
  10. package/dist/{chunk-TYRUKGGD.js → chunk-GX6XBRRF.js} +1 -2
  11. package/dist/{chunk-RIAXZ6AH.js → chunk-K4UZU3TU.js} +2 -2
  12. package/dist/{chunk-V6SZ4ECN.js → chunk-LUYVRATI.js} +257 -6
  13. package/dist/{chunk-DTFKWZ7A.js → chunk-O2Q4VMRN.js} +589 -932
  14. package/dist/{chunk-X4WBGKJQ.js → chunk-R3VCBZDC.js} +50 -3
  15. package/dist/chunk-SIQ3P4OR.js +1764 -0
  16. package/dist/{chunk-3FV6HBXS.js → chunk-WF7CONXF.js} +23 -23
  17. package/dist/{chunk-3QXJK5IY.js → chunk-YYX7OPZQ.js} +1 -1
  18. package/dist/components/index.d.ts +74 -71
  19. package/dist/components/index.js +20 -2795
  20. package/dist/components/navigation/index.js +25 -5
  21. package/dist/execution/index.d.ts +11 -11
  22. package/dist/execution/index.js +1 -2
  23. package/dist/features/auth/index.d.ts +3 -0
  24. package/dist/features/auth/index.js +23 -2
  25. package/dist/features/clients/index.js +20 -26
  26. package/dist/features/crm/index.d.ts +3 -0
  27. package/dist/features/crm/index.js +20 -30
  28. package/dist/features/dashboard/index.d.ts +69 -69
  29. package/dist/features/dashboard/index.js +20 -28
  30. package/dist/features/delivery/index.d.ts +3 -0
  31. package/dist/features/delivery/index.js +20 -30
  32. package/dist/features/knowledge/index.js +25 -9
  33. package/dist/features/lead-gen/index.d.ts +295 -57
  34. package/dist/features/lead-gen/index.js +20 -31
  35. package/dist/features/monitoring/index.js +20 -30
  36. package/dist/features/monitoring/requests/index.js +20 -25
  37. package/dist/features/operations/index.d.ts +183 -183
  38. package/dist/features/operations/index.js +18 -37
  39. package/dist/features/seo/index.js +3 -4
  40. package/dist/features/settings/index.d.ts +3 -0
  41. package/dist/features/settings/index.js +20 -27
  42. package/dist/graph/index.js +1 -1
  43. package/dist/hooks/delivery/index.d.ts +3 -0
  44. package/dist/hooks/delivery/index.js +30 -2
  45. package/dist/hooks/index.d.ts +112 -99
  46. package/dist/hooks/index.js +20 -21
  47. package/dist/hooks/operations/command-view/utils/transformCommandViewData.d.ts +46 -46
  48. package/dist/hooks/published.d.ts +112 -99
  49. package/dist/hooks/published.js +20 -20
  50. package/dist/index.css +532 -532
  51. package/dist/index.d.ts +9385 -5915
  52. package/dist/index.js +22 -26
  53. package/dist/initialization/index.d.ts +3 -0
  54. package/dist/knowledge/index.d.ts +42 -42
  55. package/dist/knowledge/index.js +10 -17
  56. package/dist/{knowledge-search-index-ORIJCEZX.js → knowledge-search-index-NBCTFIOH.js} +2 -2
  57. package/dist/layout/index.js +4 -10
  58. package/dist/organization/index.js +27 -1
  59. package/dist/profile/index.d.ts +3 -0
  60. package/dist/provider/index.d.ts +72 -39
  61. package/dist/provider/index.js +20 -15
  62. package/dist/provider/published.d.ts +40 -34
  63. package/dist/provider/published.js +20 -11
  64. package/dist/sse/index.js +26 -5
  65. package/dist/supabase/index.d.ts +6 -0
  66. package/dist/test-utils/index.js +3 -3
  67. package/dist/theme/index.js +2 -3
  68. package/dist/theme/presets/index.d.ts +28 -3
  69. package/dist/theme/presets/index.js +1 -1
  70. package/dist/typeform/index.js +1 -2049
  71. package/dist/types/index.d.ts +82 -79
  72. package/dist/utils/index.d.ts +47 -47
  73. package/dist/utils/index.js +1 -1
  74. package/dist/zustand/index.d.ts +6 -6
  75. package/dist/zustand/index.js +0 -3
  76. package/package.json +5 -5
  77. package/dist/chunk-3AJVNMY5.js +0 -4769
  78. package/dist/chunk-3MEXPLWT.js +0 -265
  79. package/dist/chunk-3ZMAGTWF.js +0 -18
  80. package/dist/chunk-4O4MII5S.js +0 -4716
  81. package/dist/chunk-5EYJ2GIN.js +0 -122
  82. package/dist/chunk-7M2VOCYN.js +0 -1
  83. package/dist/chunk-BPQVTIUP.js +0 -105
  84. package/dist/chunk-BZZCNLT6.js +0 -12
  85. package/dist/chunk-CLDCYJQT.js +0 -1
  86. package/dist/chunk-E565XMTQ.js +0 -17
  87. package/dist/chunk-HRWLKKWM.js +0 -758
  88. package/dist/chunk-IGDYWFNE.js +0 -5198
  89. package/dist/chunk-IIMU5YAJ.js +0 -53
  90. package/dist/chunk-IVGI4GDL.js +0 -1593
  91. package/dist/chunk-JFL3GRD4.js +0 -39
  92. package/dist/chunk-LAWLB6CT.js +0 -951
  93. package/dist/chunk-LGKLC5MG.js +0 -44
  94. package/dist/chunk-LRWTWOGP.js +0 -1778
  95. package/dist/chunk-MP3GPBPX.js +0 -1874
  96. package/dist/chunk-N55DVMAG.js +0 -14
  97. package/dist/chunk-NLBQTDOW.js +0 -12051
  98. package/dist/chunk-O6JXQ6UQ.js +0 -468
  99. package/dist/chunk-OBBQ2JCM.js +0 -68
  100. package/dist/chunk-PDHTXPSF.js +0 -12
  101. package/dist/chunk-PLP3NYPL.js +0 -356
  102. package/dist/chunk-R2XR4FCV.js +0 -48
  103. package/dist/chunk-R66W5UDG.js +0 -26
  104. package/dist/chunk-RYTEQBAO.js +0 -37
  105. package/dist/chunk-SDXSB3HN.js +0 -425
  106. package/dist/chunk-TKAYX2SP.js +0 -204
  107. package/dist/chunk-TUMSNGTX.js +0 -35
  108. package/dist/chunk-VNAZTCHA.js +0 -65
  109. package/dist/chunk-VNFR57DF.js +0 -87
  110. package/dist/chunk-VTXTZXAU.js +0 -539
  111. package/dist/chunk-W73ZABT6.js +0 -85
  112. package/dist/chunk-WU4FNWCW.js +0 -2281
  113. package/dist/chunk-XZGSCABI.js +0 -383
  114. package/dist/chunk-YNWZIWJL.js +0 -1863
  115. /package/dist/{chunk-2RJMVWFJ.js → chunk-GEFWMU26.js} +0 -0
  116. /package/dist/{chunk-22UVE3RA.js → chunk-HENXLGVD.js} +0 -0
@@ -143,6 +143,120 @@ function SemanticIcon({
143
143
  }
144
144
  );
145
145
  }
146
+
147
+ // ../core/src/organization-model/helpers.ts
148
+ function defineDomainRecord(schema, entries) {
149
+ return Object.fromEntries(
150
+ entries.map((entry) => {
151
+ const parsed = schema.parse(entry);
152
+ return [parsed.id, parsed];
153
+ })
154
+ );
155
+ }
156
+ function childSystemsOf(system) {
157
+ return system.systems ?? system.subsystems ?? {};
158
+ }
159
+ function defaultPathFor(id) {
160
+ return `/${id.replaceAll(".", "/")}`;
161
+ }
162
+ function parentIdOf(id) {
163
+ const index = id.lastIndexOf(".");
164
+ return index === -1 ? void 0 : id.slice(0, index);
165
+ }
166
+ function findById(systems, id) {
167
+ return systems[id];
168
+ }
169
+ function findByPath(systems, path) {
170
+ return Object.values(systems).find((system) => (system.path ?? system.ui?.path ?? defaultPathFor(system.id)) === path);
171
+ }
172
+ function childrenOf(systems, id) {
173
+ const prefix = `${id}.`;
174
+ return Object.values(systems).filter(
175
+ (system) => system.id.startsWith(prefix) && !system.id.slice(prefix.length).includes(".")
176
+ );
177
+ }
178
+ function topLevel(systems) {
179
+ return Object.values(systems).filter((system) => !system.id.includes("."));
180
+ }
181
+ function ancestorsOf(systems, id) {
182
+ const segments = id.split(".");
183
+ const ids = segments.map((_, index) => segments.slice(0, index + 1).join("."));
184
+ return ids.map((ancestorId) => findById(systems, ancestorId)).filter((system) => Boolean(system));
185
+ }
186
+ function parentOf(systems, id) {
187
+ const parentId = parentIdOf(id);
188
+ return parentId ? findById(systems, parentId) : void 0;
189
+ }
190
+ function inheritedValue(systems, id, getValue) {
191
+ return ancestorsOf(systems, id).slice().reverse().map(getValue).find((value) => value !== void 0);
192
+ }
193
+ function requiresAdminFor(systems, id) {
194
+ return inheritedValue(systems, id, (system) => system.requiresAdmin) ?? false;
195
+ }
196
+ function devOnlyFor(systems, id) {
197
+ return inheritedValue(systems, id, (system) => system.devOnly || system.lifecycle === "beta" || void 0) ?? false;
198
+ }
199
+ function getSystem(model, path) {
200
+ const segments = path.split(".");
201
+ let current = model.systems;
202
+ let node;
203
+ for (const seg of segments) {
204
+ node = current[seg];
205
+ if (node === void 0) return void 0;
206
+ current = childSystemsOf(node);
207
+ }
208
+ return node;
209
+ }
210
+ function getSystemAncestors(model, path) {
211
+ const segments = path.split(".");
212
+ const result = [];
213
+ let current = model.systems;
214
+ for (const seg of segments) {
215
+ const node = current[seg];
216
+ if (node === void 0) return [];
217
+ result.push(node);
218
+ current = childSystemsOf(node);
219
+ }
220
+ return result;
221
+ }
222
+ function listAllSystems(model) {
223
+ const results = [];
224
+ function walk(map, prefix) {
225
+ for (const [localId2, system] of Object.entries(map)) {
226
+ const fullPath = prefix ? `${prefix}.${localId2}` : localId2;
227
+ results.push({ path: fullPath, system });
228
+ const childSystems = childSystemsOf(system);
229
+ if (Object.keys(childSystems).length > 0) {
230
+ walk(childSystems, fullPath);
231
+ }
232
+ }
233
+ }
234
+ walk(model.systems, "");
235
+ return results;
236
+ }
237
+ function isPlainJsonObject(value) {
238
+ return typeof value === "object" && value !== null && !Array.isArray(value);
239
+ }
240
+ function mergeJsonConfig(base, override) {
241
+ const result = { ...base };
242
+ for (const [key, value] of Object.entries(override)) {
243
+ const existing = result[key];
244
+ result[key] = isPlainJsonObject(existing) && isPlainJsonObject(value) ? mergeJsonConfig(existing, value) : value;
245
+ }
246
+ return result;
247
+ }
248
+ function resolveSystemConfig(model, path) {
249
+ const system = getSystem(model, path);
250
+ if (system === void 0) return {};
251
+ return mergeJsonConfig({}, system.config ?? {});
252
+ }
253
+ function getResourcesForSystem(model, systemPath, options = {}) {
254
+ const { includeDescendants = false } = options;
255
+ const prefix = systemPath + ".";
256
+ return Object.values(model.resources ?? {}).filter(
257
+ (r) => r.systemPath === systemPath || includeDescendants && r.systemPath.startsWith(prefix)
258
+ );
259
+ }
146
260
  var OntologyKindSchema = z.enum([
147
261
  "object",
148
262
  "link",
@@ -325,7 +439,7 @@ function sortResolvedOntologyIndex(index) {
325
439
  }
326
440
  return sorted;
327
441
  }
328
- function childSystemsOf(system) {
442
+ function childSystemsOf2(system) {
329
443
  return system.systems ?? system.subsystems ?? {};
330
444
  }
331
445
  function addRecord(index, diagnostics, sourcesById, scopeKey, record, context) {
@@ -482,7 +596,7 @@ function addSystemScopes(index, diagnostics, sourcesById, systems, prefix, schem
482
596
  ...currentPath,
483
597
  "ontology"
484
598
  ]);
485
- addSystemScopes(index, diagnostics, sourcesById, childSystemsOf(system), systemPath, [
599
+ addSystemScopes(index, diagnostics, sourcesById, childSystemsOf2(system), systemPath, [
486
600
  ...currentPath,
487
601
  system.systems !== void 0 ? "systems" : "subsystems"
488
602
  ]);
@@ -807,6 +921,9 @@ var ActionsDomainSchema = z.record(z.string(), ActionSchema).refine((record) =>
807
921
  message: "Each action entry id must match its map key"
808
922
  }).default({});
809
923
  var DEFAULT_ORGANIZATION_MODEL_ACTIONS = {};
924
+ function defineActions(entries) {
925
+ return defineDomainRecord(ActionSchema, entries);
926
+ }
810
927
 
811
928
  // ../core/src/organization-model/domains/systems.ts
812
929
  var SystemKindSchema = z.enum(["product", "operational", "platform", "diagnostic"]).meta({ label: "System kind", color: "blue" });
@@ -1114,112 +1231,6 @@ function defineResources(resources) {
1114
1231
  );
1115
1232
  }
1116
1233
 
1117
- // ../core/src/organization-model/helpers.ts
1118
- function childSystemsOf2(system) {
1119
- return system.systems ?? system.subsystems ?? {};
1120
- }
1121
- function defaultPathFor(id) {
1122
- return `/${id.replaceAll(".", "/")}`;
1123
- }
1124
- function parentIdOf(id) {
1125
- const index = id.lastIndexOf(".");
1126
- return index === -1 ? void 0 : id.slice(0, index);
1127
- }
1128
- function findById(systems, id) {
1129
- return systems[id];
1130
- }
1131
- function findByPath(systems, path) {
1132
- return Object.values(systems).find((system) => (system.path ?? system.ui?.path ?? defaultPathFor(system.id)) === path);
1133
- }
1134
- function childrenOf(systems, id) {
1135
- const prefix = `${id}.`;
1136
- return Object.values(systems).filter(
1137
- (system) => system.id.startsWith(prefix) && !system.id.slice(prefix.length).includes(".")
1138
- );
1139
- }
1140
- function topLevel(systems) {
1141
- return Object.values(systems).filter((system) => !system.id.includes("."));
1142
- }
1143
- function ancestorsOf(systems, id) {
1144
- const segments = id.split(".");
1145
- const ids = segments.map((_, index) => segments.slice(0, index + 1).join("."));
1146
- return ids.map((ancestorId) => findById(systems, ancestorId)).filter((system) => Boolean(system));
1147
- }
1148
- function parentOf(systems, id) {
1149
- const parentId = parentIdOf(id);
1150
- return parentId ? findById(systems, parentId) : void 0;
1151
- }
1152
- function inheritedValue(systems, id, getValue) {
1153
- return ancestorsOf(systems, id).slice().reverse().map(getValue).find((value) => value !== void 0);
1154
- }
1155
- function requiresAdminFor(systems, id) {
1156
- return inheritedValue(systems, id, (system) => system.requiresAdmin) ?? false;
1157
- }
1158
- function devOnlyFor(systems, id) {
1159
- return inheritedValue(systems, id, (system) => system.devOnly || system.lifecycle === "beta" || void 0) ?? false;
1160
- }
1161
- function getSystem(model, path) {
1162
- const segments = path.split(".");
1163
- let current = model.systems;
1164
- let node;
1165
- for (const seg of segments) {
1166
- node = current[seg];
1167
- if (node === void 0) return void 0;
1168
- current = childSystemsOf2(node);
1169
- }
1170
- return node;
1171
- }
1172
- function getSystemAncestors(model, path) {
1173
- const segments = path.split(".");
1174
- const result = [];
1175
- let current = model.systems;
1176
- for (const seg of segments) {
1177
- const node = current[seg];
1178
- if (node === void 0) return [];
1179
- result.push(node);
1180
- current = childSystemsOf2(node);
1181
- }
1182
- return result;
1183
- }
1184
- function listAllSystems(model) {
1185
- const results = [];
1186
- function walk(map, prefix) {
1187
- for (const [localId2, system] of Object.entries(map)) {
1188
- const fullPath = prefix ? `${prefix}.${localId2}` : localId2;
1189
- results.push({ path: fullPath, system });
1190
- const childSystems = childSystemsOf2(system);
1191
- if (Object.keys(childSystems).length > 0) {
1192
- walk(childSystems, fullPath);
1193
- }
1194
- }
1195
- }
1196
- walk(model.systems, "");
1197
- return results;
1198
- }
1199
- function isPlainJsonObject(value) {
1200
- return typeof value === "object" && value !== null && !Array.isArray(value);
1201
- }
1202
- function mergeJsonConfig(base, override) {
1203
- const result = { ...base };
1204
- for (const [key, value] of Object.entries(override)) {
1205
- const existing = result[key];
1206
- result[key] = isPlainJsonObject(existing) && isPlainJsonObject(value) ? mergeJsonConfig(existing, value) : value;
1207
- }
1208
- return result;
1209
- }
1210
- function resolveSystemConfig(model, path) {
1211
- const system = getSystem(model, path);
1212
- if (system === void 0) return {};
1213
- return mergeJsonConfig({}, system.config ?? {});
1214
- }
1215
- function getResourcesForSystem(model, systemPath, options = {}) {
1216
- const { includeDescendants = false } = options;
1217
- const prefix = systemPath + ".";
1218
- return Object.values(model.resources ?? {}).filter(
1219
- (r) => r.systemPath === systemPath || includeDescendants && r.systemPath.startsWith(prefix)
1220
- );
1221
- }
1222
-
1223
1234
  // ../core/src/organization-model/migration-helpers.ts
1224
1235
  function catalogRecords(model) {
1225
1236
  return Object.values(compileOrganizationOntology(model).ontology.catalogTypes);
@@ -1290,19 +1301,22 @@ function getAllBuildTemplates(model) {
1290
1301
  const stepCatalog = stepCatalogId !== void 0 ? stepCatalogs.get(stepCatalogId) : void 0;
1291
1302
  const steps = stepCatalog === void 0 ? [] : entriesOf(stepCatalog);
1292
1303
  return {
1293
- id: templateId,
1294
- label: stringValue(templateEntry.label) ?? templateId,
1295
- ...stringValue(templateEntry.description) ? { description: stringValue(templateEntry.description) } : {},
1296
- ...stringValue(templateEntry.color) ? { color: stringValue(templateEntry.color) } : {},
1297
- steps: steps.map(([stepId, step]) => ({
1298
- id: stepId,
1299
- label: stringValue(step.label) ?? stepId,
1300
- ...stringValue(step.description) ? { description: stringValue(step.description) } : {},
1301
- ...step
1302
- }))
1304
+ order: numberValue(templateEntry.order, Number.MAX_SAFE_INTEGER),
1305
+ template: {
1306
+ id: templateId,
1307
+ label: stringValue(templateEntry.label) ?? templateId,
1308
+ ...stringValue(templateEntry.description) ? { description: stringValue(templateEntry.description) } : {},
1309
+ ...stringValue(templateEntry.color) ? { color: stringValue(templateEntry.color) } : {},
1310
+ steps: steps.map(([stepId, step]) => ({
1311
+ id: stepId,
1312
+ label: stringValue(step.label) ?? stepId,
1313
+ ...stringValue(step.description) ? { description: stringValue(step.description) } : {},
1314
+ ...step
1315
+ }))
1316
+ }
1303
1317
  };
1304
1318
  })
1305
- ).sort((a, b) => a.id.localeCompare(b.id));
1319
+ ).sort((a, b) => a.order - b.order || a.template.id.localeCompare(b.template.id)).map(({ template }) => template);
1306
1320
  }
1307
1321
  function getAllProspectingStages(model, kind) {
1308
1322
  return catalogRecords(model).filter((catalog) => catalog.kind === "stage" && appliesToEntityKind(catalog) === kind).flatMap(
@@ -1371,89 +1385,23 @@ var OrganizationModelBrandingSchema = z.object({
1371
1385
  });
1372
1386
  var DEFAULT_ORGANIZATION_MODEL_BRANDING = {
1373
1387
  organizationName: "Default Organization",
1374
- productName: "Elevasis",
1375
- shortName: "Elevasis",
1388
+ productName: "Organization OS",
1389
+ shortName: "Org OS",
1376
1390
  logos: {}
1377
1391
  };
1378
- var SurfaceTypeSchema = z.enum(["page", "dashboard", "graph", "detail", "list", "settings"]).meta({ label: "Surface type", color: "blue" });
1379
- var SurfaceDefinitionSchema = z.object({
1380
- id: ModelIdSchema,
1381
- label: LabelSchema,
1382
- path: PathSchema,
1383
- surfaceType: SurfaceTypeSchema,
1384
- description: DescriptionSchema.optional(),
1385
- enabled: z.boolean().default(true),
1386
- devOnly: z.boolean().optional(),
1387
- icon: IconNameSchema.optional(),
1388
- systemIds: z.array(ModelIdSchema.meta({ ref: "system" })).default([]),
1389
- entityIds: z.array(ModelIdSchema.meta({ ref: "entity" })).default([]),
1390
- resourceIds: z.array(ModelIdSchema.meta({ ref: "resource" })).default([]),
1391
- actionIds: z.array(ModelIdSchema.meta({ ref: "action" })).default([]),
1392
- parentId: ModelIdSchema.meta({ ref: "surface" }).optional()
1393
- });
1394
- var SidebarSurfaceTargetsSchema = z.object({
1395
- systems: z.array(ModelIdSchema.meta({ ref: "system" })).default([]).optional(),
1396
- entities: z.array(ModelIdSchema.meta({ ref: "entity" })).default([]).optional(),
1397
- resources: z.array(ModelIdSchema.meta({ ref: "resource" })).default([]).optional(),
1398
- actions: z.array(ModelIdSchema.meta({ ref: "action" })).default([]).optional()
1399
- }).default({});
1400
- var SidebarNodeSchema = z.lazy(
1401
- () => z.discriminatedUnion("type", [
1402
- z.object({
1403
- type: z.literal("group"),
1404
- label: LabelSchema,
1405
- description: DescriptionSchema.optional(),
1406
- icon: IconNameSchema.optional(),
1407
- order: z.number().int().optional(),
1408
- children: z.record(z.string(), SidebarNodeSchema).default({})
1409
- }),
1410
- z.object({
1411
- type: z.literal("surface"),
1412
- label: LabelSchema,
1413
- path: PathSchema,
1414
- surfaceType: SurfaceTypeSchema,
1415
- description: DescriptionSchema.optional(),
1416
- icon: IconNameSchema.optional(),
1417
- order: z.number().int().optional(),
1418
- targets: SidebarSurfaceTargetsSchema.optional(),
1419
- devOnly: z.boolean().optional(),
1420
- requiresAdmin: z.boolean().optional()
1421
- })
1422
- ])
1423
- );
1424
- var SidebarSectionSchema = z.record(z.string(), SidebarNodeSchema).default({});
1425
- var SidebarNavigationSchema = z.object({
1426
- primary: SidebarSectionSchema,
1427
- bottom: SidebarSectionSchema
1428
- }).default({ primary: {}, bottom: {} });
1429
- var OrganizationModelNavigationSchema = z.object({
1430
- sidebar: SidebarNavigationSchema
1431
- }).default({ sidebar: { primary: {}, bottom: {} } });
1432
- function getSortedSidebarEntries(nodes) {
1433
- return Object.entries(nodes).sort(([leftId, left], [rightId, right]) => {
1434
- const orderDelta = (left.order ?? Number.MAX_SAFE_INTEGER) - (right.order ?? Number.MAX_SAFE_INTEGER);
1435
- return orderDelta === 0 ? leftId.localeCompare(rightId) : orderDelta;
1436
- });
1437
- }
1438
- z.object({
1439
- id: ModelIdSchema,
1440
- label: LabelSchema,
1441
- placement: z.string().trim().min(1).max(50),
1442
- surfaceIds: z.array(ModelIdSchema.meta({ ref: "surface" })).default([])
1443
- });
1444
- var FirmographicsSchema = z.object({
1445
- /** Industry vertical (e.g. "Marketing Agency", "Legal", "Real Estate"). */
1446
- industry: z.string().trim().max(200).optional(),
1447
- /**
1448
- * Company headcount band (e.g. "1–10", "11–50", "51–200", "200+").
1449
- * Free-form string to accommodate any band notation.
1450
- */
1451
- companySize: z.string().trim().max(100).optional(),
1452
- /**
1453
- * Primary geographic region the segment operates in or is targeted from
1454
- * (e.g. "North America", "Europe", "Global").
1455
- */
1456
- region: z.string().trim().max(200).optional()
1392
+ var FirmographicsSchema = z.object({
1393
+ /** Industry vertical (e.g. "Marketing Agency", "Legal", "Real Estate"). */
1394
+ industry: z.string().trim().max(200).optional(),
1395
+ /**
1396
+ * Company headcount band (e.g. "1–10", "11–50", "51–200", "200+").
1397
+ * Free-form string to accommodate any band notation.
1398
+ */
1399
+ companySize: z.string().trim().max(100).optional(),
1400
+ /**
1401
+ * Primary geographic region the segment operates in or is targeted from
1402
+ * (e.g. "North America", "Europe", "Global").
1403
+ */
1404
+ region: z.string().trim().max(200).optional()
1457
1405
  });
1458
1406
  var CustomerSegmentSchema = z.object({
1459
1407
  /** Stable unique identifier for the segment (e.g. "segment-smb-agencies"). */
@@ -1633,90 +1581,6 @@ var GoalsDomainSchema = z.record(z.string(), ObjectiveSchema).refine((record) =>
1633
1581
  message: "Each objective entry id must match its map key"
1634
1582
  }).default({});
1635
1583
  var DEFAULT_ORGANIZATION_MODEL_GOALS = {};
1636
- var KnowledgeTargetKindSchema = z.enum([
1637
- "system",
1638
- "resource",
1639
- "knowledge",
1640
- "stage",
1641
- "action",
1642
- "role",
1643
- "goal",
1644
- "customer-segment",
1645
- "offering",
1646
- "ontology"
1647
- ]).meta({ label: "Target kind" });
1648
- var KnowledgeTargetRefSchema = z.object({
1649
- kind: KnowledgeTargetKindSchema,
1650
- // Ontology targets use the canonical '<scope>:<kind>/<local-id>' ontology id format.
1651
- // Business-logic validation of target existence is done in OrganizationModelSchema.superRefine.
1652
- id: z.string().trim().min(1).max(300)
1653
- }).superRefine((target, ctx) => {
1654
- if (target.kind !== "ontology") return;
1655
- const result = OntologyIdSchema.safeParse(target.id);
1656
- if (!result.success) {
1657
- ctx.addIssue({
1658
- code: z.ZodIssueCode.custom,
1659
- path: ["id"],
1660
- message: "Ontology knowledge targets must use <system-path>:<kind>/<local-id> or global:<kind>/<local-id>"
1661
- });
1662
- }
1663
- });
1664
- var LegacyKnowledgeLinkSchema = z.object({
1665
- nodeId: z.union([NodeIdStringSchema, z.templateLiteral(["ontology:", OntologyIdSchema])])
1666
- }).superRefine((link, ctx) => {
1667
- const [kind] = link.nodeId.split(":");
1668
- if (!KnowledgeTargetKindSchema.safeParse(kind).success) {
1669
- ctx.addIssue({
1670
- code: z.ZodIssueCode.custom,
1671
- path: ["nodeId"],
1672
- message: `Unknown knowledge target kind "${kind}"`
1673
- });
1674
- }
1675
- });
1676
- var CanonicalKnowledgeLinkSchema = z.object({
1677
- target: KnowledgeTargetRefSchema
1678
- });
1679
- function nodeIdFromTarget(target) {
1680
- return `${target.kind}:${target.id}`;
1681
- }
1682
- function targetFromNodeId(nodeId2) {
1683
- const [kind, ...idParts] = nodeId2.split(":");
1684
- return {
1685
- kind: KnowledgeTargetKindSchema.parse(kind),
1686
- id: idParts.join(":")
1687
- };
1688
- }
1689
- var KnowledgeLinkSchema = z.union([CanonicalKnowledgeLinkSchema, LegacyKnowledgeLinkSchema]).transform((link) => {
1690
- const target = "target" in link ? link.target : targetFromNodeId(link.nodeId);
1691
- return {
1692
- target,
1693
- nodeId: nodeIdFromTarget(target)
1694
- };
1695
- });
1696
- var OrgKnowledgeKindSchema = z.enum(["playbook", "strategy", "reference"]).meta({ label: "Knowledge kind", color: "grape" });
1697
- var OrgKnowledgeNodeSchema = z.object({
1698
- id: ModelIdSchema,
1699
- kind: OrgKnowledgeKindSchema,
1700
- title: z.string().trim().min(1).max(200),
1701
- summary: z.string().trim().min(1).max(1e3),
1702
- icon: IconNameSchema.optional(),
1703
- /** Canonical documentation URL when body content is a local summary. */
1704
- externalUrl: z.string().trim().url().max(500).optional(),
1705
- /** Optional generated source file path for local MDX-backed knowledge nodes. */
1706
- sourceFilePath: z.string().trim().min(1).max(500).optional(),
1707
- /** Raw MDX string. Phase 2 will introduce a structured block format. */
1708
- body: z.string().trim().min(1),
1709
- /**
1710
- * Graph links to other OM nodes this knowledge node governs.
1711
- * Each link emits a `governs` edge: knowledge-node -> target node.
1712
- */
1713
- links: z.array(KnowledgeLinkSchema).default([]),
1714
- /** Role identifiers that own this knowledge node. */
1715
- ownerIds: z.array(RoleIdSchema.meta({ ref: "role" })).default([]),
1716
- /** ISO date string (YYYY-MM-DD or full ISO 8601) of last meaningful update. */
1717
- updatedAt: z.string().trim().min(1).max(50)
1718
- });
1719
- var KnowledgeDomainSchema = z.record(ModelIdSchema, OrgKnowledgeNodeSchema).default({});
1720
1584
  var SecretLikeMetadataKeySchema = /(?:secret|password|passwd|token|api[-_]?key|credential|private[-_]?key)/i;
1721
1585
  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-----)/;
1722
1586
  z.enum([
@@ -1945,80 +1809,237 @@ var PoliciesDomainSchema = z.record(z.string(), PolicySchema).refine((record) =>
1945
1809
  message: "Each policy entry id must match its map key"
1946
1810
  }).default({});
1947
1811
  var DEFAULT_ORGANIZATION_MODEL_POLICIES = {};
1948
-
1949
- // ../core/src/organization-model/schema.ts
1950
- z.enum([
1951
- "branding",
1952
- "identity",
1953
- "customers",
1954
- "offerings",
1955
- "roles",
1956
- "goals",
1957
- "systems",
1958
- "ontology",
1959
- "resources",
1960
- "topology",
1961
- "actions",
1962
- "entities",
1963
- "policies",
1964
- "knowledge"
1965
- ]);
1966
- var OrganizationModelDomainMetadataSchema = z.object({
1967
- version: z.literal(1).default(1),
1968
- lastModified: z.string().regex(/^\d{4}-\d{2}-\d{2}$/, "lastModified must be an ISO date string (YYYY-MM-DD)")
1812
+ var SurfaceTypeSchema = z.enum(["page", "dashboard", "graph", "detail", "list", "settings"]).meta({ label: "Surface type", color: "blue" });
1813
+ var SurfaceDefinitionSchema = z.object({
1814
+ id: ModelIdSchema,
1815
+ label: LabelSchema,
1816
+ path: PathSchema,
1817
+ surfaceType: SurfaceTypeSchema,
1818
+ description: DescriptionSchema.optional(),
1819
+ enabled: z.boolean().default(true),
1820
+ devOnly: z.boolean().optional(),
1821
+ icon: IconNameSchema.optional(),
1822
+ systemIds: z.array(ModelIdSchema.meta({ ref: "system" })).default([]),
1823
+ entityIds: z.array(ModelIdSchema.meta({ ref: "entity" })).default([]),
1824
+ resourceIds: z.array(ModelIdSchema.meta({ ref: "resource" })).default([]),
1825
+ actionIds: z.array(ModelIdSchema.meta({ ref: "action" })).default([]),
1826
+ parentId: ModelIdSchema.meta({ ref: "surface" }).optional()
1827
+ });
1828
+ var SidebarSurfaceTargetsSchema = z.object({
1829
+ systems: z.array(ModelIdSchema.meta({ ref: "system" })).default([]).optional(),
1830
+ entities: z.array(ModelIdSchema.meta({ ref: "entity" })).default([]).optional(),
1831
+ resources: z.array(ModelIdSchema.meta({ ref: "resource" })).default([]).optional(),
1832
+ actions: z.array(ModelIdSchema.meta({ ref: "action" })).default([]).optional()
1833
+ }).default({});
1834
+ var SidebarNodeSchema = z.lazy(
1835
+ () => z.discriminatedUnion("type", [
1836
+ z.object({
1837
+ type: z.literal("group"),
1838
+ label: LabelSchema,
1839
+ description: DescriptionSchema.optional(),
1840
+ icon: IconNameSchema.optional(),
1841
+ order: z.number().int().optional(),
1842
+ children: z.record(z.string(), SidebarNodeSchema).default({})
1843
+ }),
1844
+ z.object({
1845
+ type: z.literal("surface"),
1846
+ label: LabelSchema,
1847
+ path: PathSchema,
1848
+ surfaceType: SurfaceTypeSchema,
1849
+ description: DescriptionSchema.optional(),
1850
+ icon: IconNameSchema.optional(),
1851
+ order: z.number().int().optional(),
1852
+ targets: SidebarSurfaceTargetsSchema.optional(),
1853
+ devOnly: z.boolean().optional(),
1854
+ requiresAdmin: z.boolean().optional()
1855
+ })
1856
+ ])
1857
+ );
1858
+ var SidebarSectionSchema = z.record(z.string(), SidebarNodeSchema).default({});
1859
+ var SidebarNavigationSchema = z.object({
1860
+ primary: SidebarSectionSchema,
1861
+ bottom: SidebarSectionSchema
1862
+ }).default({ primary: {}, bottom: {} });
1863
+ var OrganizationModelNavigationSchema = z.object({
1864
+ sidebar: SidebarNavigationSchema
1865
+ }).default({ sidebar: { primary: {}, bottom: {} } });
1866
+ function getSortedSidebarEntries(nodes) {
1867
+ return Object.entries(nodes).sort(([leftId, left], [rightId, right]) => {
1868
+ const orderDelta = (left.order ?? Number.MAX_SAFE_INTEGER) - (right.order ?? Number.MAX_SAFE_INTEGER);
1869
+ return orderDelta === 0 ? leftId.localeCompare(rightId) : orderDelta;
1870
+ });
1871
+ }
1872
+ z.object({
1873
+ id: ModelIdSchema,
1874
+ label: LabelSchema,
1875
+ placement: z.string().trim().min(1).max(50),
1876
+ surfaceIds: z.array(ModelIdSchema.meta({ ref: "surface" })).default([])
1877
+ });
1878
+ var KnowledgeTargetKindSchema = z.enum([
1879
+ "system",
1880
+ "resource",
1881
+ "knowledge",
1882
+ "stage",
1883
+ "action",
1884
+ "role",
1885
+ "goal",
1886
+ "customer-segment",
1887
+ "offering",
1888
+ "ontology"
1889
+ ]).meta({ label: "Target kind" });
1890
+ var KnowledgeTargetRefSchema = z.object({
1891
+ kind: KnowledgeTargetKindSchema,
1892
+ // Ontology targets use the canonical '<scope>:<kind>/<local-id>' ontology id format.
1893
+ // Business-logic validation of target existence is done in OrganizationModelSchema.superRefine.
1894
+ id: z.string().trim().min(1).max(300)
1895
+ }).superRefine((target, ctx) => {
1896
+ if (target.kind !== "ontology") return;
1897
+ const result = OntologyIdSchema.safeParse(target.id);
1898
+ if (!result.success) {
1899
+ ctx.addIssue({
1900
+ code: z.ZodIssueCode.custom,
1901
+ path: ["id"],
1902
+ message: "Ontology knowledge targets must use <system-path>:<kind>/<local-id> or global:<kind>/<local-id>"
1903
+ });
1904
+ }
1905
+ });
1906
+ var LegacyKnowledgeLinkSchema = z.object({
1907
+ nodeId: z.union([NodeIdStringSchema, z.templateLiteral(["ontology:", OntologyIdSchema])])
1908
+ }).superRefine((link, ctx) => {
1909
+ const [kind] = link.nodeId.split(":");
1910
+ if (!KnowledgeTargetKindSchema.safeParse(kind).success) {
1911
+ ctx.addIssue({
1912
+ code: z.ZodIssueCode.custom,
1913
+ path: ["nodeId"],
1914
+ message: `Unknown knowledge target kind "${kind}"`
1915
+ });
1916
+ }
1917
+ });
1918
+ var CanonicalKnowledgeLinkSchema = z.object({
1919
+ target: KnowledgeTargetRefSchema
1920
+ });
1921
+ function nodeIdFromTarget(target) {
1922
+ return `${target.kind}:${target.id}`;
1923
+ }
1924
+ function targetFromNodeId(nodeId2) {
1925
+ const [kind, ...idParts] = nodeId2.split(":");
1926
+ return {
1927
+ kind: KnowledgeTargetKindSchema.parse(kind),
1928
+ id: idParts.join(":")
1929
+ };
1930
+ }
1931
+ var KnowledgeLinkSchema = z.union([CanonicalKnowledgeLinkSchema, LegacyKnowledgeLinkSchema]).transform((link) => {
1932
+ const target = "target" in link ? link.target : targetFromNodeId(link.nodeId);
1933
+ return {
1934
+ target,
1935
+ nodeId: nodeIdFromTarget(target)
1936
+ };
1937
+ });
1938
+ var OrgKnowledgeKindSchema = z.enum(["playbook", "strategy", "reference"]).meta({ label: "Knowledge kind", color: "grape" });
1939
+ var OrgKnowledgeNodeSchema = z.object({
1940
+ id: ModelIdSchema,
1941
+ kind: OrgKnowledgeKindSchema,
1942
+ title: z.string().trim().min(1).max(200),
1943
+ summary: z.string().trim().min(1).max(1e3),
1944
+ icon: IconNameSchema.optional(),
1945
+ /** Canonical documentation URL when body content is a local summary. */
1946
+ externalUrl: z.string().trim().url().max(500).optional(),
1947
+ /** Optional generated source file path for local MDX-backed knowledge nodes. */
1948
+ sourceFilePath: z.string().trim().min(1).max(500).optional(),
1949
+ /** Raw MDX string. Phase 2 will introduce a structured block format. */
1950
+ body: z.string().trim().min(1),
1951
+ /**
1952
+ * Graph links to other OM nodes this knowledge node governs.
1953
+ * Each link emits a `governs` edge: knowledge-node -> target node.
1954
+ */
1955
+ links: z.array(KnowledgeLinkSchema).default([]),
1956
+ /** Role identifiers that own this knowledge node. */
1957
+ ownerIds: z.array(RoleIdSchema.meta({ ref: "role" })).default([]),
1958
+ /** ISO date string (YYYY-MM-DD or full ISO 8601) of last meaningful update. */
1959
+ updatedAt: z.string().trim().min(1).max(50)
1969
1960
  });
1970
- var DEFAULT_ORGANIZATION_MODEL_DOMAIN_METADATA = {
1971
- branding: { version: 1, lastModified: "2026-05-10" },
1972
- identity: { version: 1, lastModified: "2026-05-10" },
1973
- customers: { version: 1, lastModified: "2026-05-10" },
1974
- offerings: { version: 1, lastModified: "2026-05-10" },
1975
- roles: { version: 1, lastModified: "2026-05-10" },
1976
- goals: { version: 1, lastModified: "2026-05-10" },
1977
- systems: { version: 1, lastModified: "2026-05-10" },
1978
- ontology: { version: 1, lastModified: "2026-05-14" },
1979
- resources: { version: 1, lastModified: "2026-05-10" },
1980
- topology: { version: 1, lastModified: "2026-05-14" },
1981
- actions: { version: 1, lastModified: "2026-05-10" },
1982
- entities: { version: 1, lastModified: "2026-05-10" },
1983
- policies: { version: 1, lastModified: "2026-05-10" },
1984
- knowledge: { version: 1, lastModified: "2026-05-10" }
1961
+ var KnowledgeDomainSchema = z.record(ModelIdSchema, OrgKnowledgeNodeSchema).default({});
1962
+
1963
+ // ../core/src/organization-model/cross-ref.ts
1964
+ var ONTOLOGY_REFERENCE_KEY_KINDS = {
1965
+ valueType: "value-type",
1966
+ catalogType: "catalog",
1967
+ objectType: "object",
1968
+ eventType: "event",
1969
+ actionType: "action",
1970
+ linkType: "link",
1971
+ interfaceType: "interface",
1972
+ propertyType: "property",
1973
+ groupType: "group",
1974
+ surfaceType: "surface",
1975
+ stepCatalog: "catalog"
1985
1976
  };
1986
- var OrganizationModelDomainMetadataByDomainSchema = z.object({
1987
- branding: OrganizationModelDomainMetadataSchema,
1988
- identity: OrganizationModelDomainMetadataSchema,
1989
- customers: OrganizationModelDomainMetadataSchema,
1990
- offerings: OrganizationModelDomainMetadataSchema,
1991
- roles: OrganizationModelDomainMetadataSchema,
1992
- goals: OrganizationModelDomainMetadataSchema,
1993
- systems: OrganizationModelDomainMetadataSchema,
1994
- ontology: OrganizationModelDomainMetadataSchema,
1995
- resources: OrganizationModelDomainMetadataSchema,
1996
- topology: OrganizationModelDomainMetadataSchema,
1997
- actions: OrganizationModelDomainMetadataSchema,
1998
- entities: OrganizationModelDomainMetadataSchema,
1999
- policies: OrganizationModelDomainMetadataSchema,
2000
- knowledge: OrganizationModelDomainMetadataSchema
2001
- }).partial().default(DEFAULT_ORGANIZATION_MODEL_DOMAIN_METADATA).transform((metadata) => ({ ...DEFAULT_ORGANIZATION_MODEL_DOMAIN_METADATA, ...metadata }));
2002
- var OrganizationModelSchemaBase = z.object({
2003
- version: z.literal(1).default(1),
2004
- domainMetadata: OrganizationModelDomainMetadataByDomainSchema,
2005
- branding: OrganizationModelBrandingSchema,
2006
- navigation: OrganizationModelNavigationSchema,
2007
- identity: IdentityDomainSchema.default(DEFAULT_ORGANIZATION_MODEL_IDENTITY),
2008
- customers: CustomersDomainSchema.default(DEFAULT_ORGANIZATION_MODEL_CUSTOMERS),
2009
- offerings: OfferingsDomainSchema.default(DEFAULT_ORGANIZATION_MODEL_OFFERINGS),
2010
- roles: RolesDomainSchema.default(DEFAULT_ORGANIZATION_MODEL_ROLES),
2011
- goals: GoalsDomainSchema.default(DEFAULT_ORGANIZATION_MODEL_GOALS),
2012
- systems: SystemsDomainSchema.default(DEFAULT_ORGANIZATION_MODEL_SYSTEMS),
2013
- ontology: OntologyScopeSchema.default(DEFAULT_ONTOLOGY_SCOPE),
2014
- resources: ResourcesDomainSchema.default(DEFAULT_ORGANIZATION_MODEL_RESOURCES),
2015
- topology: OmTopologyDomainSchema.default(DEFAULT_ORGANIZATION_MODEL_TOPOLOGY),
2016
- actions: ActionsDomainSchema.default(DEFAULT_ORGANIZATION_MODEL_ACTIONS),
2017
- entities: EntitiesDomainSchema.default(DEFAULT_ORGANIZATION_MODEL_ENTITIES),
2018
- policies: PoliciesDomainSchema.default(DEFAULT_ORGANIZATION_MODEL_POLICIES),
2019
- // D3: flat Record<id, OrgKnowledgeNode> — no wrapper object
2020
- knowledge: KnowledgeDomainSchema.default({})
2021
- });
1977
+ function buildOmCrossRefIndex(model) {
1978
+ const systemsById = /* @__PURE__ */ new Map();
1979
+ for (const { path, system } of listAllSystems(model)) {
1980
+ systemsById.set(path, system);
1981
+ systemsById.set(system.id, system);
1982
+ }
1983
+ const resourceIds = new Set(Object.keys(model.resources ?? {}));
1984
+ const knowledgeIds = new Set(Object.keys(model.knowledge ?? {}));
1985
+ const roleIds = new Set(Object.keys(model.roles ?? {}));
1986
+ const goalIds = new Set(Object.keys(model.goals ?? {}));
1987
+ const actionIds = new Set(Object.keys(model.actions ?? {}));
1988
+ const customerSegmentIds = new Set(Object.keys(model.customers ?? {}));
1989
+ const offeringIds = new Set(Object.keys(model.offerings ?? {}));
1990
+ const ontologyCompilation = compileOrganizationOntology(model);
1991
+ const ontologyIndexByKind = {
1992
+ object: ontologyCompilation.ontology.objectTypes,
1993
+ link: ontologyCompilation.ontology.linkTypes,
1994
+ action: ontologyCompilation.ontology.actionTypes,
1995
+ catalog: ontologyCompilation.ontology.catalogTypes,
1996
+ event: ontologyCompilation.ontology.eventTypes,
1997
+ interface: ontologyCompilation.ontology.interfaceTypes,
1998
+ "value-type": ontologyCompilation.ontology.valueTypes,
1999
+ property: ontologyCompilation.ontology.sharedProperties,
2000
+ group: ontologyCompilation.ontology.groups,
2001
+ surface: ontologyCompilation.ontology.surfaces
2002
+ };
2003
+ const ontologyIds = new Set(Object.values(ontologyIndexByKind).flatMap((index) => Object.keys(index)));
2004
+ const stageIds = /* @__PURE__ */ new Set();
2005
+ for (const catalog of Object.values(ontologyCompilation.ontology.catalogTypes)) {
2006
+ if (catalog.kind !== "stage") continue;
2007
+ const entries = catalog.entries;
2008
+ if (entries !== void 0) {
2009
+ for (const stageId of Object.keys(entries)) {
2010
+ stageIds.add(stageId);
2011
+ }
2012
+ }
2013
+ }
2014
+ return {
2015
+ systemsById,
2016
+ resourceIds,
2017
+ knowledgeIds,
2018
+ roleIds,
2019
+ goalIds,
2020
+ actionIds,
2021
+ customerSegmentIds,
2022
+ offeringIds,
2023
+ ontologyIds,
2024
+ ontologyIndexByKind,
2025
+ stageIds
2026
+ };
2027
+ }
2028
+ function knowledgeTargetExists(index, kind, id) {
2029
+ if (kind === "system") return index.systemsById.has(id);
2030
+ if (kind === "resource") return index.resourceIds.has(id);
2031
+ if (kind === "knowledge") return index.knowledgeIds.has(id);
2032
+ if (kind === "stage") return index.stageIds.has(id);
2033
+ if (kind === "action") return index.actionIds.has(id);
2034
+ if (kind === "role") return index.roleIds.has(id);
2035
+ if (kind === "goal") return index.goalIds.has(id);
2036
+ if (kind === "customer-segment") return index.customerSegmentIds.has(id);
2037
+ if (kind === "offering") return index.offeringIds.has(id);
2038
+ if (kind === "ontology") return index.ontologyIds.has(id);
2039
+ return false;
2040
+ }
2041
+
2042
+ // ../core/src/organization-model/schema-refinements.ts
2022
2043
  function addIssue(ctx, path, message) {
2023
2044
  ctx.addIssue({
2024
2045
  code: z.ZodIssueCode.custom,
@@ -2049,7 +2070,7 @@ function isKnowledgeKindCompatibleWithTarget(knowledgeKind, targetKind) {
2049
2070
  function isRecord(value) {
2050
2071
  return typeof value === "object" && value !== null && !Array.isArray(value);
2051
2072
  }
2052
- var OrganizationModelSchema = OrganizationModelSchemaBase.superRefine((model, ctx) => {
2073
+ function refineOrganizationModel(model, ctx) {
2053
2074
  function collectAllSystems(systems, prefix = "", schemaPath = ["systems"]) {
2054
2075
  const result = [];
2055
2076
  for (const [key, system] of Object.entries(systems)) {
@@ -2221,7 +2242,7 @@ var OrganizationModelSchema = OrganizationModelSchemaBase.superRefine((model, ct
2221
2242
  });
2222
2243
  });
2223
2244
  Object.values(model.entities).forEach((entity) => {
2224
- if (!systemsById.has(entity.ownedBySystemId)) {
2245
+ if (systemsById.size > 0 && !systemsById.has(entity.ownedBySystemId)) {
2225
2246
  addIssue(
2226
2247
  ctx,
2227
2248
  ["entities", entity.id, "ownedBySystemId"],
@@ -2339,29 +2360,9 @@ var OrganizationModelSchema = OrganizationModelSchemaBase.superRefine((model, ct
2339
2360
  }
2340
2361
  });
2341
2362
  });
2342
- const actionIds = new Set(Object.keys(model.actions));
2343
- const offeringsById = new Map(Object.entries(model.offerings));
2363
+ const idx = buildOmCrossRefIndex(model);
2364
+ const { ontologyIndexByKind, ontologyIds } = idx;
2344
2365
  const ontologyCompilation = compileOrganizationOntology(model);
2345
- const stageIds = /* @__PURE__ */ new Set();
2346
- for (const catalog of Object.values(ontologyCompilation.ontology.catalogTypes)) {
2347
- if (catalog.kind !== "stage") continue;
2348
- for (const stageId of Object.keys(catalog.entries ?? {})) {
2349
- stageIds.add(stageId);
2350
- }
2351
- }
2352
- const ontologyIndexByKind = {
2353
- object: ontologyCompilation.ontology.objectTypes,
2354
- link: ontologyCompilation.ontology.linkTypes,
2355
- action: ontologyCompilation.ontology.actionTypes,
2356
- catalog: ontologyCompilation.ontology.catalogTypes,
2357
- event: ontologyCompilation.ontology.eventTypes,
2358
- interface: ontologyCompilation.ontology.interfaceTypes,
2359
- "value-type": ontologyCompilation.ontology.valueTypes,
2360
- property: ontologyCompilation.ontology.sharedProperties,
2361
- group: ontologyCompilation.ontology.groups,
2362
- surface: ontologyCompilation.ontology.surfaces
2363
- };
2364
- const ontologyIds = new Set(Object.values(ontologyIndexByKind).flatMap((index) => Object.keys(index)));
2365
2366
  function topologyTargetExists(ref) {
2366
2367
  if (ref.kind === "system") return systemsById.has(ref.id);
2367
2368
  if (ref.kind === "resource") return resourcesById.has(ref.id);
@@ -2381,19 +2382,6 @@ var OrganizationModelSchema = OrganizationModelSchemaBase.superRefine((model, ct
2381
2382
  );
2382
2383
  });
2383
2384
  });
2384
- const ontologyReferenceKeyKinds = {
2385
- valueType: "value-type",
2386
- catalogType: "catalog",
2387
- objectType: "object",
2388
- eventType: "event",
2389
- actionType: "action",
2390
- linkType: "link",
2391
- interfaceType: "interface",
2392
- propertyType: "property",
2393
- groupType: "group",
2394
- surfaceType: "surface",
2395
- stepCatalog: "catalog"
2396
- };
2397
2385
  function validateKnownOntologyReferences(ownerId, value, path, seen = /* @__PURE__ */ new WeakSet()) {
2398
2386
  if (Array.isArray(value)) {
2399
2387
  value.forEach((entry, index) => validateKnownOntologyReferences(ownerId, entry, [...path, index], seen));
@@ -2403,7 +2391,7 @@ var OrganizationModelSchema = OrganizationModelSchemaBase.superRefine((model, ct
2403
2391
  if (seen.has(value)) return;
2404
2392
  seen.add(value);
2405
2393
  Object.entries(value).forEach(([key, entry]) => {
2406
- const expectedKind = ontologyReferenceKeyKinds[key];
2394
+ const expectedKind = ONTOLOGY_REFERENCE_KEY_KINDS[key];
2407
2395
  if (expectedKind !== void 0) {
2408
2396
  if (typeof entry !== "string") {
2409
2397
  addIssue(ctx, [...path, key], `Ontology record "${ownerId}" ${key} must be an ontology ID string`);
@@ -2464,22 +2452,9 @@ var OrganizationModelSchema = OrganizationModelSchemaBase.superRefine((model, ct
2464
2452
  );
2465
2453
  }
2466
2454
  });
2467
- function knowledgeTargetExists(kind, id) {
2468
- if (kind === "system") return systemsById.has(id);
2469
- if (kind === "resource") return resourcesById.has(id);
2470
- if (kind === "knowledge") return knowledgeById.has(id);
2471
- if (kind === "stage") return stageIds.has(id);
2472
- if (kind === "action") return actionIds.has(id);
2473
- if (kind === "role") return rolesById.has(id);
2474
- if (kind === "goal") return goalsById.has(id);
2475
- if (kind === "customer-segment") return segmentsById.has(id);
2476
- if (kind === "offering") return offeringsById.has(id);
2477
- if (kind === "ontology") return ontologyIds.has(id);
2478
- return false;
2479
- }
2480
2455
  Object.entries(model.knowledge).forEach(([nodeId2, node]) => {
2481
2456
  node.links.forEach((link, linkIndex) => {
2482
- if (!knowledgeTargetExists(link.target.kind, link.target.id)) {
2457
+ if (!knowledgeTargetExists(idx, link.target.kind, link.target.id)) {
2483
2458
  addIssue(
2484
2459
  ctx,
2485
2460
  ["knowledge", nodeId2, "links", linkIndex, "target"],
@@ -2556,46 +2531,212 @@ var OrganizationModelSchema = OrganizationModelSchemaBase.superRefine((model, ct
2556
2531
  }
2557
2532
  }
2558
2533
  }
2559
- });
2560
- Object.values(model.roles).forEach((role) => {
2561
- if (role.heldBy === void 0) return;
2562
- asRoleHolderArray(role.heldBy).forEach((holder, holderIndex) => {
2563
- if (holder.kind !== "agent") return;
2564
- const resource = resourcesById.get(holder.agentId);
2565
- if (resource === void 0) {
2566
- addIssue(
2567
- ctx,
2568
- ["roles", role.id, "heldBy", Array.isArray(role.heldBy) ? holderIndex : "agentId"],
2569
- `Role "${role.id}" references unknown agent holder resource "${holder.agentId}"`
2570
- );
2571
- return;
2572
- }
2573
- if (resource.kind !== "agent") {
2574
- addIssue(
2575
- ctx,
2576
- ["roles", role.id, "heldBy", Array.isArray(role.heldBy) ? holderIndex : "agentId"],
2577
- `Role "${role.id}" agent holder "${holder.agentId}" must reference an agent resource`
2578
- );
2579
- }
2580
- });
2581
- });
2582
- Object.entries(model.knowledge).forEach(([nodeId2, node]) => {
2583
- node.ownerIds.forEach((roleId, ownerIndex) => {
2584
- if (!rolesById.has(roleId)) {
2585
- addIssue(
2586
- ctx,
2587
- ["knowledge", nodeId2, "ownerIds", ownerIndex],
2588
- `Knowledge node "${node.id}" references unknown owner role "${roleId}"`
2589
- );
2590
- }
2591
- });
2592
- });
2593
- for (const diagnostic of ontologyCompilation.diagnostics) {
2594
- addIssue(ctx, diagnostic.path, diagnostic.message);
2534
+ });
2535
+ Object.values(model.roles).forEach((role) => {
2536
+ if (role.heldBy === void 0) return;
2537
+ asRoleHolderArray(role.heldBy).forEach((holder, holderIndex) => {
2538
+ if (holder.kind !== "agent") return;
2539
+ const resource = resourcesById.get(holder.agentId);
2540
+ if (resource === void 0) {
2541
+ addIssue(
2542
+ ctx,
2543
+ ["roles", role.id, "heldBy", Array.isArray(role.heldBy) ? holderIndex : "agentId"],
2544
+ `Role "${role.id}" references unknown agent holder resource "${holder.agentId}"`
2545
+ );
2546
+ return;
2547
+ }
2548
+ if (resource.kind !== "agent") {
2549
+ addIssue(
2550
+ ctx,
2551
+ ["roles", role.id, "heldBy", Array.isArray(role.heldBy) ? holderIndex : "agentId"],
2552
+ `Role "${role.id}" agent holder "${holder.agentId}" must reference an agent resource`
2553
+ );
2554
+ }
2555
+ });
2556
+ });
2557
+ Object.entries(model.knowledge).forEach(([nodeId2, node]) => {
2558
+ node.ownerIds.forEach((roleId, ownerIndex) => {
2559
+ if (!rolesById.has(roleId)) {
2560
+ addIssue(
2561
+ ctx,
2562
+ ["knowledge", nodeId2, "ownerIds", ownerIndex],
2563
+ `Knowledge node "${node.id}" references unknown owner role "${roleId}"`
2564
+ );
2565
+ }
2566
+ });
2567
+ });
2568
+ for (const diagnostic of ontologyCompilation.diagnostics) {
2569
+ addIssue(ctx, diagnostic.path, diagnostic.message);
2570
+ }
2571
+ }
2572
+
2573
+ // ../core/src/organization-model/schema.ts
2574
+ z.enum([
2575
+ "branding",
2576
+ "identity",
2577
+ "customers",
2578
+ "offerings",
2579
+ "roles",
2580
+ "goals",
2581
+ "systems",
2582
+ "ontology",
2583
+ "resources",
2584
+ "topology",
2585
+ "actions",
2586
+ "entities",
2587
+ "policies",
2588
+ "knowledge"
2589
+ ]);
2590
+ var OrganizationModelDomainMetadataSchema = z.object({
2591
+ version: z.literal(1).default(1),
2592
+ lastModified: z.string().regex(/^\d{4}-\d{2}-\d{2}$/, "lastModified must be an ISO date string (YYYY-MM-DD)")
2593
+ });
2594
+ var DEFAULT_ORGANIZATION_MODEL_DOMAIN_METADATA = {
2595
+ branding: { version: 1, lastModified: "2026-05-10" },
2596
+ identity: { version: 1, lastModified: "2026-05-10" },
2597
+ customers: { version: 1, lastModified: "2026-05-10" },
2598
+ offerings: { version: 1, lastModified: "2026-05-10" },
2599
+ roles: { version: 1, lastModified: "2026-05-10" },
2600
+ goals: { version: 1, lastModified: "2026-05-10" },
2601
+ systems: { version: 1, lastModified: "2026-05-10" },
2602
+ ontology: { version: 1, lastModified: "2026-05-14" },
2603
+ resources: { version: 1, lastModified: "2026-05-10" },
2604
+ topology: { version: 1, lastModified: "2026-05-14" },
2605
+ actions: { version: 1, lastModified: "2026-05-10" },
2606
+ entities: { version: 1, lastModified: "2026-05-10" },
2607
+ policies: { version: 1, lastModified: "2026-05-10" },
2608
+ knowledge: { version: 1, lastModified: "2026-05-10" }
2609
+ };
2610
+ var OrganizationModelDomainMetadataByDomainSchema = z.object({
2611
+ branding: OrganizationModelDomainMetadataSchema,
2612
+ identity: OrganizationModelDomainMetadataSchema,
2613
+ customers: OrganizationModelDomainMetadataSchema,
2614
+ offerings: OrganizationModelDomainMetadataSchema,
2615
+ roles: OrganizationModelDomainMetadataSchema,
2616
+ goals: OrganizationModelDomainMetadataSchema,
2617
+ systems: OrganizationModelDomainMetadataSchema,
2618
+ ontology: OrganizationModelDomainMetadataSchema,
2619
+ resources: OrganizationModelDomainMetadataSchema,
2620
+ topology: OrganizationModelDomainMetadataSchema,
2621
+ actions: OrganizationModelDomainMetadataSchema,
2622
+ entities: OrganizationModelDomainMetadataSchema,
2623
+ policies: OrganizationModelDomainMetadataSchema,
2624
+ knowledge: OrganizationModelDomainMetadataSchema
2625
+ }).partial().default(DEFAULT_ORGANIZATION_MODEL_DOMAIN_METADATA).transform((metadata) => ({ ...DEFAULT_ORGANIZATION_MODEL_DOMAIN_METADATA, ...metadata }));
2626
+ var OrganizationModelSchemaBase = z.object({
2627
+ version: z.literal(1).default(1),
2628
+ domainMetadata: OrganizationModelDomainMetadataByDomainSchema,
2629
+ branding: OrganizationModelBrandingSchema.default(DEFAULT_ORGANIZATION_MODEL_BRANDING),
2630
+ navigation: OrganizationModelNavigationSchema,
2631
+ identity: IdentityDomainSchema.default(DEFAULT_ORGANIZATION_MODEL_IDENTITY),
2632
+ customers: CustomersDomainSchema.default(DEFAULT_ORGANIZATION_MODEL_CUSTOMERS),
2633
+ offerings: OfferingsDomainSchema.default(DEFAULT_ORGANIZATION_MODEL_OFFERINGS),
2634
+ roles: RolesDomainSchema.default(DEFAULT_ORGANIZATION_MODEL_ROLES),
2635
+ goals: GoalsDomainSchema.default(DEFAULT_ORGANIZATION_MODEL_GOALS),
2636
+ systems: SystemsDomainSchema.default(DEFAULT_ORGANIZATION_MODEL_SYSTEMS),
2637
+ ontology: OntologyScopeSchema.default(DEFAULT_ONTOLOGY_SCOPE),
2638
+ resources: ResourcesDomainSchema.default(DEFAULT_ORGANIZATION_MODEL_RESOURCES),
2639
+ topology: OmTopologyDomainSchema.default(DEFAULT_ORGANIZATION_MODEL_TOPOLOGY),
2640
+ actions: ActionsDomainSchema.default(DEFAULT_ORGANIZATION_MODEL_ACTIONS),
2641
+ entities: EntitiesDomainSchema.default(DEFAULT_ORGANIZATION_MODEL_ENTITIES),
2642
+ policies: PoliciesDomainSchema.default(DEFAULT_ORGANIZATION_MODEL_POLICIES),
2643
+ // D3: flat Record<id, OrgKnowledgeNode> — no wrapper object
2644
+ knowledge: KnowledgeDomainSchema.default({})
2645
+ });
2646
+ var OrganizationModelSchema = OrganizationModelSchemaBase.superRefine(refineOrganizationModel);
2647
+
2648
+ // ../core/src/organization-model/defaults.ts
2649
+ var DEFAULT_ORGANIZATION_MODEL_KNOWLEDGE = {};
2650
+ var DEFAULT_ORGANIZATION_MODEL_ENTITIES2 = {};
2651
+ var DEFAULT_ORGANIZATION_MODEL_NAVIGATION = {
2652
+ sidebar: {
2653
+ primary: {},
2654
+ bottom: {}
2655
+ }
2656
+ };
2657
+ var DEFAULT_ORGANIZATION_MODEL = {
2658
+ version: 1,
2659
+ domainMetadata: DEFAULT_ORGANIZATION_MODEL_DOMAIN_METADATA,
2660
+ branding: DEFAULT_ORGANIZATION_MODEL_BRANDING,
2661
+ navigation: DEFAULT_ORGANIZATION_MODEL_NAVIGATION,
2662
+ identity: DEFAULT_ORGANIZATION_MODEL_IDENTITY,
2663
+ customers: DEFAULT_ORGANIZATION_MODEL_CUSTOMERS,
2664
+ offerings: DEFAULT_ORGANIZATION_MODEL_OFFERINGS,
2665
+ roles: DEFAULT_ORGANIZATION_MODEL_ROLES,
2666
+ goals: DEFAULT_ORGANIZATION_MODEL_GOALS,
2667
+ // Generic empty systems map. Elevasis-specific systems (platform, sales, sales.crm,
2668
+ // sales.lead-gen, monitoring, settings, admin, etc.) have been relocated to
2669
+ // `@repo/elevasis-core/src/organization-model/systems.ts` via `canonicalOrganizationModel`.
2670
+ // Tenant OM configs supply their own systems via `resolveOrganizationModel`.
2671
+ systems: {},
2672
+ ontology: DEFAULT_ONTOLOGY_SCOPE,
2673
+ resources: DEFAULT_ORGANIZATION_MODEL_RESOURCES,
2674
+ topology: DEFAULT_ORGANIZATION_MODEL_TOPOLOGY,
2675
+ // Generic empty actions map. Elevasis-specific action entries have been relocated to
2676
+ // `@repo/elevasis-core/src/organization-model/actions.ts`.
2677
+ actions: {},
2678
+ entities: DEFAULT_ORGANIZATION_MODEL_ENTITIES2,
2679
+ policies: DEFAULT_ORGANIZATION_MODEL_POLICIES,
2680
+ knowledge: DEFAULT_ORGANIZATION_MODEL_KNOWLEDGE
2681
+ };
2682
+
2683
+ // ../core/src/organization-model/resolve.ts
2684
+ function isPlainObject(value) {
2685
+ return typeof value === "object" && value !== null && !Array.isArray(value);
2686
+ }
2687
+ function collectNestedSystemPaths(systems, prefix = "") {
2688
+ const paths = /* @__PURE__ */ new Set();
2689
+ for (const [key, value] of Object.entries(systems)) {
2690
+ if (!isPlainObject(value)) continue;
2691
+ const path = prefix ? `${prefix}.${key}` : key;
2692
+ for (const childKey of ["systems", "subsystems"]) {
2693
+ const childSystems = value[childKey];
2694
+ if (!isPlainObject(childSystems)) continue;
2695
+ for (const childPath of collectNestedSystemPaths(childSystems, path)) {
2696
+ paths.add(childPath);
2697
+ }
2698
+ }
2699
+ if (prefix !== "") {
2700
+ paths.add(path);
2701
+ }
2595
2702
  }
2596
- });
2597
-
2598
- // ../core/src/organization-model/graph/schema.ts
2703
+ return paths;
2704
+ }
2705
+ function pruneFlatSystemDescendantCollisions(base, override) {
2706
+ const result = { ...base };
2707
+ for (const nestedPath of collectNestedSystemPaths(override)) {
2708
+ delete result[nestedPath];
2709
+ }
2710
+ return result;
2711
+ }
2712
+ function deepMerge(base, override) {
2713
+ if (override === void 0) {
2714
+ return base;
2715
+ }
2716
+ if (Array.isArray(base)) {
2717
+ return override ?? base;
2718
+ }
2719
+ if (!isPlainObject(base) || !isPlainObject(override)) {
2720
+ return override ?? base;
2721
+ }
2722
+ const result = { ...base };
2723
+ for (const [key, value] of Object.entries(override)) {
2724
+ if (value === void 0) continue;
2725
+ const existing = result[key];
2726
+ if (key === "systems" && isPlainObject(existing) && isPlainObject(value)) {
2727
+ result[key] = deepMerge(pruneFlatSystemDescendantCollisions(existing, value), value);
2728
+ continue;
2729
+ }
2730
+ result[key] = isPlainObject(existing) && isPlainObject(value) ? deepMerge(existing, value) : value;
2731
+ }
2732
+ return result;
2733
+ }
2734
+ function resolveOrganizationModel(override, organizationIdOrOptions, options) {
2735
+ const resolvedOptions = typeof organizationIdOrOptions === "object" ? organizationIdOrOptions : options;
2736
+ const mergeDefaults = resolvedOptions?.mergeDefaults ?? true;
2737
+ const merged = mergeDefaults ? deepMerge(DEFAULT_ORGANIZATION_MODEL, override) : override ?? {};
2738
+ return OrganizationModelSchema.parse(merged);
2739
+ }
2599
2740
  var OrganizationGraphNodeKindSchema = z.enum([
2600
2741
  "organization",
2601
2742
  "system",
@@ -3523,99 +3664,6 @@ function buildOrganizationGraph(input) {
3523
3664
  return OrganizationGraphSchema.parse(graph);
3524
3665
  }
3525
3666
 
3526
- // ../core/src/organization-model/defaults.ts
3527
- var DEFAULT_ORGANIZATION_MODEL_KNOWLEDGE = {};
3528
- var DEFAULT_ORGANIZATION_MODEL_ENTITIES2 = {};
3529
- var DEFAULT_ORGANIZATION_MODEL_NAVIGATION = {
3530
- sidebar: {
3531
- primary: {},
3532
- bottom: {}
3533
- }
3534
- };
3535
- var DEFAULT_ORGANIZATION_MODEL = {
3536
- version: 1,
3537
- domainMetadata: DEFAULT_ORGANIZATION_MODEL_DOMAIN_METADATA,
3538
- branding: DEFAULT_ORGANIZATION_MODEL_BRANDING,
3539
- navigation: DEFAULT_ORGANIZATION_MODEL_NAVIGATION,
3540
- identity: DEFAULT_ORGANIZATION_MODEL_IDENTITY,
3541
- customers: DEFAULT_ORGANIZATION_MODEL_CUSTOMERS,
3542
- offerings: DEFAULT_ORGANIZATION_MODEL_OFFERINGS,
3543
- roles: DEFAULT_ORGANIZATION_MODEL_ROLES,
3544
- goals: DEFAULT_ORGANIZATION_MODEL_GOALS,
3545
- // Generic empty systems map. Elevasis-specific systems (platform, sales, sales.crm,
3546
- // sales.lead-gen, monitoring, settings, admin, etc.) have been relocated to
3547
- // `@repo/elevasis-core/src/organization-model/systems.ts` via `canonicalOrganizationModel`.
3548
- // Tenant OM configs supply their own systems via `resolveOrganizationModel`.
3549
- systems: {},
3550
- ontology: DEFAULT_ONTOLOGY_SCOPE,
3551
- resources: DEFAULT_ORGANIZATION_MODEL_RESOURCES,
3552
- topology: DEFAULT_ORGANIZATION_MODEL_TOPOLOGY,
3553
- // Generic empty actions map. Elevasis-specific action entries have been relocated to
3554
- // `@repo/elevasis-core/src/organization-model/actions.ts`.
3555
- actions: {},
3556
- entities: DEFAULT_ORGANIZATION_MODEL_ENTITIES2,
3557
- policies: DEFAULT_ORGANIZATION_MODEL_POLICIES,
3558
- knowledge: DEFAULT_ORGANIZATION_MODEL_KNOWLEDGE
3559
- };
3560
-
3561
- // ../core/src/organization-model/resolve.ts
3562
- function isPlainObject(value) {
3563
- return typeof value === "object" && value !== null && !Array.isArray(value);
3564
- }
3565
- function collectNestedSystemPaths(systems, prefix = "") {
3566
- const paths = /* @__PURE__ */ new Set();
3567
- for (const [key, value] of Object.entries(systems)) {
3568
- if (!isPlainObject(value)) continue;
3569
- const path = prefix ? `${prefix}.${key}` : key;
3570
- for (const childKey of ["systems", "subsystems"]) {
3571
- const childSystems = value[childKey];
3572
- if (!isPlainObject(childSystems)) continue;
3573
- for (const childPath of collectNestedSystemPaths(childSystems, path)) {
3574
- paths.add(childPath);
3575
- }
3576
- }
3577
- if (prefix !== "") {
3578
- paths.add(path);
3579
- }
3580
- }
3581
- return paths;
3582
- }
3583
- function pruneFlatSystemDescendantCollisions(base, override) {
3584
- const result = { ...base };
3585
- for (const nestedPath of collectNestedSystemPaths(override)) {
3586
- delete result[nestedPath];
3587
- }
3588
- return result;
3589
- }
3590
- function deepMerge(base, override) {
3591
- if (override === void 0) {
3592
- return base;
3593
- }
3594
- if (Array.isArray(base)) {
3595
- return override ?? base;
3596
- }
3597
- if (!isPlainObject(base) || !isPlainObject(override)) {
3598
- return override ?? base;
3599
- }
3600
- const result = { ...base };
3601
- for (const [key, value] of Object.entries(override)) {
3602
- if (value === void 0) continue;
3603
- const existing = result[key];
3604
- if (key === "systems" && isPlainObject(existing) && isPlainObject(value)) {
3605
- result[key] = deepMerge(pruneFlatSystemDescendantCollisions(existing, value), value);
3606
- continue;
3607
- }
3608
- result[key] = isPlainObject(existing) && isPlainObject(value) ? deepMerge(existing, value) : value;
3609
- }
3610
- return result;
3611
- }
3612
- function resolveOrganizationModel(override, organizationIdOrOptions, options) {
3613
- const resolvedOptions = typeof organizationIdOrOptions === "object" ? organizationIdOrOptions : options;
3614
- const mergeDefaults = resolvedOptions?.mergeDefaults ?? true;
3615
- const merged = mergeDefaults ? deepMerge(DEFAULT_ORGANIZATION_MODEL, override) : override ?? {};
3616
- return OrganizationModelSchema.parse(merged);
3617
- }
3618
-
3619
3667
  // ../core/src/organization-model/surface-projection.ts
3620
3668
  function collectSystemsById(model) {
3621
3669
  const systemsById = /* @__PURE__ */ new Map();
@@ -3696,396 +3744,5 @@ function projectOrganizationSurfaces(model) {
3696
3744
  };
3697
3745
  });
3698
3746
  }
3699
- var SalesStageSemanticClassSchema = z.enum(["open", "active", "nurturing", "closed_won", "closed_lost"]);
3700
- var SalesStageSchema = DisplayMetadataSchema.extend({
3701
- id: ModelIdSchema,
3702
- order: z.number().int().min(0),
3703
- semanticClass: SalesStageSemanticClassSchema,
3704
- surfaceIds: ReferenceIdsSchema,
3705
- resourceIds: ReferenceIdsSchema
3706
- });
3707
- z.object({
3708
- id: ModelIdSchema,
3709
- label: z.string().trim().min(1).max(120),
3710
- description: DescriptionSchema.optional(),
3711
- entityId: ModelIdSchema,
3712
- stages: z.array(SalesStageSchema).min(1)
3713
- });
3714
- function findPipeline(definitions, pipelineKey) {
3715
- return definitions.find((def) => def.pipelineKey === pipelineKey);
3716
- }
3717
- var CRM_DISCOVERY_REPLIED_STATE = {
3718
- stateKey: "discovery_replied",
3719
- label: "Discovery Replied"
3720
- };
3721
- var CRM_DISCOVERY_LINK_SENT_STATE = {
3722
- stateKey: "discovery_link_sent",
3723
- label: "Discovery Link Sent"
3724
- };
3725
- var CRM_DISCOVERY_NUDGING_STATE = {
3726
- stateKey: "discovery_nudging",
3727
- label: "Discovery Nudging"
3728
- };
3729
- var CRM_DISCOVERY_BOOKING_CANCELLED_STATE = {
3730
- stateKey: "discovery_booking_cancelled",
3731
- label: "Discovery Booking Cancelled"
3732
- };
3733
- DisplayMetadataSchema.extend({
3734
- id: ModelIdSchema,
3735
- order: z.number().min(0)
3736
- });
3737
- var RecordColumnConfigSchema = z.object({
3738
- key: ModelIdSchema,
3739
- label: z.string().trim().min(1).max(120),
3740
- path: z.string().trim().min(1).max(500),
3741
- width: z.union([z.number().positive(), z.string().trim().min(1).max(100)]).optional(),
3742
- renderType: z.enum(["text", "badge", "datetime", "count", "json"]).optional(),
3743
- badgeColor: z.string().trim().min(1).max(40).optional()
3744
- });
3745
- var RecordColumnsConfigSchema = z.object({
3746
- company: z.array(RecordColumnConfigSchema).optional(),
3747
- contact: z.array(RecordColumnConfigSchema).optional()
3748
- }).refine((columns) => Boolean(columns.company?.length || columns.contact?.length), {
3749
- message: "recordColumns must include at least one entity column set"
3750
- });
3751
- var CredentialRequirementSchema = z.object({
3752
- key: ModelIdSchema,
3753
- provider: ModelIdSchema,
3754
- credentialType: z.enum(["api-key", "api-key-secret", "oauth", "webhook-secret"]),
3755
- label: z.string().trim().min(1).max(120),
3756
- required: z.boolean(),
3757
- selectionMode: z.enum(["single", "multiple"]).optional(),
3758
- inputPath: z.string().trim().min(1).max(500),
3759
- verifyOnRun: z.boolean().optional()
3760
- });
3761
- var ProspectingBuildTemplateStepSchema = DisplayMetadataSchema.extend({
3762
- id: ModelIdSchema,
3763
- primaryEntity: z.enum(["company", "contact"]),
3764
- outputs: z.array(z.enum(["company", "contact", "export"])).min(1),
3765
- stageKey: ModelIdSchema,
3766
- recordEntity: z.enum(["company", "contact"]).optional(),
3767
- recordsStageKey: ModelIdSchema.optional(),
3768
- recordSourceStageKey: ModelIdSchema.optional(),
3769
- dependsOn: z.array(ModelIdSchema).optional(),
3770
- dependencyMode: z.literal("per-record-eligibility"),
3771
- actionKey: ModelIdSchema,
3772
- defaultBatchSize: z.number().int().positive(),
3773
- maxBatchSize: z.number().int().positive(),
3774
- recordColumns: RecordColumnsConfigSchema.optional(),
3775
- credentialRequirements: z.array(CredentialRequirementSchema).optional()
3776
- }).refine((step) => step.defaultBatchSize <= step.maxBatchSize, {
3777
- message: "defaultBatchSize must be less than or equal to maxBatchSize",
3778
- path: ["defaultBatchSize"]
3779
- });
3780
- DisplayMetadataSchema.extend({
3781
- id: ModelIdSchema,
3782
- steps: z.array(ProspectingBuildTemplateStepSchema).min(1)
3783
- });
3784
- var DTC_RECORD_COLUMNS = {
3785
- populated: {
3786
- company: [
3787
- { key: "name", label: "Company", path: "company.name" },
3788
- { key: "domain", label: "Domain", path: "company.domain" },
3789
- { key: "employee-count", label: "Employees", path: "company.numEmployees", renderType: "count" },
3790
- { key: "apollo-industry", label: "Apollo industry", path: "company.category" },
3791
- { key: "location", label: "Location", path: "company.locationState" }
3792
- ]
3793
- },
3794
- crawled: {
3795
- company: [
3796
- { key: "name", label: "Company", path: "company.name" },
3797
- { key: "domain", label: "Domain", path: "company.domain" },
3798
- { key: "page-count", label: "Pages", path: "company.enrichmentData.websiteCrawl.pageCount", renderType: "count" },
3799
- { key: "crawl-status", label: "Crawl status", path: "processingState.crawled.status", renderType: "badge" }
3800
- ]
3801
- },
3802
- extracted: {
3803
- company: [
3804
- { key: "name", label: "Company", path: "company.name" },
3805
- { key: "domain", label: "Domain", path: "company.domain" },
3806
- { key: "description", label: "Description", path: "company.enrichmentData.websiteCrawl.companyDescription" },
3807
- { key: "services", label: "Services", path: "company.enrichmentData.websiteCrawl.services", renderType: "json" },
3808
- {
3809
- key: "automation-gaps",
3810
- label: "Automation gaps",
3811
- path: "company.enrichmentData.websiteCrawl.automationGaps",
3812
- renderType: "json"
3813
- },
3814
- {
3815
- key: "contact-count",
3816
- label: "Contacts",
3817
- path: "company.enrichmentData.websiteCrawl.emailCount",
3818
- renderType: "count"
3819
- }
3820
- ]
3821
- },
3822
- qualified: {
3823
- company: [
3824
- { key: "name", label: "Company", path: "company.name" },
3825
- { key: "domain", label: "Domain", path: "company.domain" },
3826
- { key: "score", label: "Score", path: "company.qualificationScore", renderType: "badge", badgeColor: "green" },
3827
- { key: "signals", label: "Signals", path: "company.qualificationSignals", renderType: "json" },
3828
- {
3829
- key: "disqualified-reason",
3830
- label: "Disqualified reason",
3831
- path: "processingState.qualified.data.disqualifiedReason"
3832
- }
3833
- ]
3834
- },
3835
- decisionMakers: {
3836
- contact: [
3837
- { key: "name", label: "Name", path: "contact.name" },
3838
- { key: "title", label: "Title", path: "contact.title" },
3839
- { key: "email", label: "Email", path: "contact.email" },
3840
- { key: "linkedin", label: "LinkedIn", path: "contact.linkedinUrl" },
3841
- {
3842
- key: "priority-score",
3843
- label: "Priority",
3844
- path: "contact.enrichmentData.apollo.priorityScore",
3845
- renderType: "badge"
3846
- }
3847
- ]
3848
- },
3849
- uploaded: {
3850
- company: [
3851
- { key: "name", label: "Company", path: "company.name" },
3852
- { key: "domain", label: "Domain", path: "company.domain" },
3853
- {
3854
- key: "contacts",
3855
- label: "Contacts",
3856
- path: "company.enrichmentData.approvedLeadListExport.contacts",
3857
- renderType: "json"
3858
- },
3859
- { key: "score", label: "Score", path: "company.qualificationScore", renderType: "badge", badgeColor: "green" },
3860
- {
3861
- key: "approval",
3862
- label: "Approval",
3863
- path: "company.enrichmentData.approvedLeadListExport.approvalStatus",
3864
- renderType: "badge"
3865
- }
3866
- ]
3867
- }
3868
- };
3869
- var PROSPECTING_STEPS = {
3870
- localServices: {
3871
- sourceCompanies: {
3872
- id: "source-companies",
3873
- label: "Companies found",
3874
- primaryEntity: "company",
3875
- outputs: ["company"],
3876
- stageKey: "populated",
3877
- dependencyMode: "per-record-eligibility",
3878
- actionKey: "lead-gen.company.source",
3879
- defaultBatchSize: 100,
3880
- maxBatchSize: 250
3881
- },
3882
- analyzeWebsites: {
3883
- id: "analyze-websites",
3884
- label: "Websites analyzed",
3885
- primaryEntity: "company",
3886
- outputs: ["company"],
3887
- stageKey: "extracted",
3888
- dependsOn: ["source-companies"],
3889
- dependencyMode: "per-record-eligibility",
3890
- actionKey: "lead-gen.company.website-extract",
3891
- defaultBatchSize: 50,
3892
- maxBatchSize: 100
3893
- },
3894
- qualifyCompanies: {
3895
- id: "qualify-companies",
3896
- label: "Companies qualified",
3897
- primaryEntity: "company",
3898
- outputs: ["company"],
3899
- stageKey: "qualified",
3900
- dependsOn: ["analyze-websites"],
3901
- dependencyMode: "per-record-eligibility",
3902
- actionKey: "lead-gen.company.qualify",
3903
- defaultBatchSize: 100,
3904
- maxBatchSize: 250
3905
- },
3906
- findContacts: {
3907
- id: "find-contacts",
3908
- label: "Decision-makers found",
3909
- primaryEntity: "contact",
3910
- outputs: ["contact"],
3911
- stageKey: "discovered",
3912
- dependsOn: ["qualify-companies"],
3913
- dependencyMode: "per-record-eligibility",
3914
- actionKey: "lead-gen.contact.discover",
3915
- defaultBatchSize: 50,
3916
- maxBatchSize: 100
3917
- },
3918
- verifyEmails: {
3919
- id: "verify-emails",
3920
- label: "Emails verified",
3921
- primaryEntity: "contact",
3922
- outputs: ["contact"],
3923
- stageKey: "verified",
3924
- dependsOn: ["find-contacts"],
3925
- dependencyMode: "per-record-eligibility",
3926
- actionKey: "lead-gen.contact.verify-email",
3927
- defaultBatchSize: 100,
3928
- maxBatchSize: 500
3929
- },
3930
- personalize: {
3931
- id: "personalize",
3932
- label: "Personalize",
3933
- primaryEntity: "contact",
3934
- outputs: ["contact"],
3935
- stageKey: "personalized",
3936
- dependsOn: ["verify-emails"],
3937
- dependencyMode: "per-record-eligibility",
3938
- actionKey: "lead-gen.contact.personalize",
3939
- defaultBatchSize: 25,
3940
- maxBatchSize: 100
3941
- },
3942
- review: {
3943
- id: "review",
3944
- label: "Reviewed and exported",
3945
- primaryEntity: "contact",
3946
- outputs: ["export"],
3947
- stageKey: "uploaded",
3948
- dependsOn: ["personalize"],
3949
- dependencyMode: "per-record-eligibility",
3950
- actionKey: "lead-gen.review.outreach-ready",
3951
- defaultBatchSize: 25,
3952
- maxBatchSize: 100
3953
- }
3954
- },
3955
- dtcApolloClickup: {
3956
- importApolloSearch: {
3957
- id: "import-apollo-search",
3958
- label: "Companies found",
3959
- description: "Pull companies and seed contact data from a predefined Apollo search or list.",
3960
- primaryEntity: "company",
3961
- outputs: ["company", "contact"],
3962
- stageKey: "populated",
3963
- dependencyMode: "per-record-eligibility",
3964
- actionKey: "lead-gen.company.apollo-import",
3965
- defaultBatchSize: 250,
3966
- maxBatchSize: 1e3,
3967
- recordColumns: DTC_RECORD_COLUMNS.populated,
3968
- credentialRequirements: [
3969
- {
3970
- key: "apollo",
3971
- provider: "apollo",
3972
- credentialType: "api-key-secret",
3973
- label: "Apollo API key",
3974
- required: true,
3975
- selectionMode: "single",
3976
- inputPath: "credential"
3977
- }
3978
- ]
3979
- },
3980
- apifyCrawl: {
3981
- id: "apify-crawl",
3982
- label: "Websites crawled",
3983
- 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.",
3984
- primaryEntity: "company",
3985
- outputs: ["company"],
3986
- stageKey: "crawled",
3987
- dependsOn: ["import-apollo-search"],
3988
- dependencyMode: "per-record-eligibility",
3989
- actionKey: "lead-gen.company.apify-crawl",
3990
- defaultBatchSize: 50,
3991
- maxBatchSize: 100,
3992
- recordColumns: DTC_RECORD_COLUMNS.crawled,
3993
- credentialRequirements: [
3994
- {
3995
- key: "apify",
3996
- provider: "apify",
3997
- credentialType: "api-key-secret",
3998
- label: "Apify API token",
3999
- required: true,
4000
- selectionMode: "single",
4001
- inputPath: "credential",
4002
- verifyOnRun: true
4003
- }
4004
- ]
4005
- },
4006
- analyzeWebsites: {
4007
- id: "analyze-websites",
4008
- label: "Websites analyzed",
4009
- description: "Extract subscription, product, retention, and tech-stack signals from each brand website.",
4010
- primaryEntity: "company",
4011
- outputs: ["company"],
4012
- stageKey: "extracted",
4013
- dependsOn: ["apify-crawl"],
4014
- dependencyMode: "per-record-eligibility",
4015
- actionKey: "lead-gen.company.website-extract",
4016
- defaultBatchSize: 50,
4017
- maxBatchSize: 100,
4018
- recordColumns: DTC_RECORD_COLUMNS.extracted
4019
- },
4020
- scoreDtcFit: {
4021
- id: "score-dtc-fit",
4022
- label: "Companies qualified",
4023
- description: "Classify subscription potential, consumable-product fit, retention maturity, and disqualifiers.",
4024
- primaryEntity: "company",
4025
- outputs: ["company"],
4026
- stageKey: "qualified",
4027
- dependsOn: ["analyze-websites"],
4028
- dependencyMode: "per-record-eligibility",
4029
- actionKey: "lead-gen.company.dtc-subscription-qualify",
4030
- defaultBatchSize: 100,
4031
- maxBatchSize: 250,
4032
- recordColumns: DTC_RECORD_COLUMNS.qualified
4033
- },
4034
- enrichDecisionMakers: {
4035
- id: "enrich-decision-makers",
4036
- label: "Decision-makers found",
4037
- description: "Use Apollo to find qualified contacts at qualified companies - founders, retention leads, lifecycle leads, and marketing owners.",
4038
- primaryEntity: "company",
4039
- outputs: ["contact"],
4040
- stageKey: "decision-makers-enriched",
4041
- recordEntity: "contact",
4042
- dependsOn: ["score-dtc-fit"],
4043
- dependencyMode: "per-record-eligibility",
4044
- actionKey: "lead-gen.contact.apollo-decision-maker-enrich",
4045
- defaultBatchSize: 100,
4046
- maxBatchSize: 250,
4047
- recordColumns: DTC_RECORD_COLUMNS.decisionMakers,
4048
- credentialRequirements: [
4049
- {
4050
- key: "apollo",
4051
- provider: "apollo",
4052
- credentialType: "api-key-secret",
4053
- label: "Apollo API key",
4054
- required: true,
4055
- selectionMode: "single",
4056
- inputPath: "credential"
4057
- }
4058
- ]
4059
- },
4060
- reviewAndExport: {
4061
- id: "review-and-export",
4062
- label: "Reviewed and exported",
4063
- description: "Operator QC approves or rejects qualified companies, then approved records are exported as a lead list with unverified emails.",
4064
- primaryEntity: "company",
4065
- outputs: ["export"],
4066
- stageKey: "uploaded",
4067
- recordsStageKey: "uploaded",
4068
- recordSourceStageKey: "qualified",
4069
- dependsOn: ["enrich-decision-makers"],
4070
- dependencyMode: "per-record-eligibility",
4071
- actionKey: "lead-gen.export.list",
4072
- defaultBatchSize: 100,
4073
- maxBatchSize: 250,
4074
- recordColumns: DTC_RECORD_COLUMNS.uploaded,
4075
- credentialRequirements: [
4076
- {
4077
- key: "clickup",
4078
- provider: "clickup",
4079
- credentialType: "api-key-secret",
4080
- label: "ClickUp API token",
4081
- required: true,
4082
- selectionMode: "single",
4083
- inputPath: "clickupCredential",
4084
- verifyOnRun: true
4085
- }
4086
- ]
4087
- }
4088
- }
4089
- };
4090
3747
 
4091
- export { ActionSchema, AgentResourceEntrySchema, CRM_DISCOVERY_BOOKING_CANCELLED_STATE, CRM_DISCOVERY_LINK_SENT_STATE, CRM_DISCOVERY_NUDGING_STATE, CRM_DISCOVERY_REPLIED_STATE, EntitySchema, IdentityDomainSchema, IntegrationResourceEntrySchema, OntologyIdSchema, OrgKnowledgeNodeSchema, PROJECTS_VIEW_ACTION_ID, PROSPECTING_STEPS, PolicySchema, RoleSchema, ScriptResourceEntrySchema, SemanticIcon, SurfaceDefinitionSchema, SystemEntrySchema, WorkflowResourceEntrySchema, ancestorsOf, buildOrganizationGraph, childrenOf, compileOrganizationOntology, defaultPathFor, defineResources, defineTopology, devOnlyFor, extendSemanticIconRegistry, findById, findByPath, findPipeline, getLeadGenStageCatalog, getResourcesForSystem, getSemanticIconComponent, getSortedSidebarEntries, getSystem, getSystemAncestors, listAllSystems, ontologyGraphNodeId, parentOf, parseOntologyId, projectOrganizationSurfaces, requiresAdminFor, resolveOrganizationModel, resolveSemanticIconComponent, resolveSystemConfig, topLevel, topologyRef, topologyRelationship };
3748
+ export { ActionSchema, AgentResourceEntrySchema, DEFAULT_SEMANTIC_ICON_REGISTRY, EntitySchema, IdentityDomainSchema, IntegrationResourceEntrySchema, OntologyIdSchema, OrgKnowledgeNodeSchema, PROJECTS_VIEW_ACTION_ID, PolicySchema, RoleSchema, ScriptResourceEntrySchema, SemanticIcon, SurfaceDefinitionSchema, SystemEntrySchema, WorkflowResourceEntrySchema, ancestorsOf, buildOrganizationGraph, childrenOf, compileOrganizationOntology, defaultPathFor, defineActions, defineResources, defineTopology, devOnlyFor, extendSemanticIconRegistry, findById, findByPath, getAllBuildTemplates, getLeadGenStageCatalog, getResourcesForSystem, getSemanticIconComponent, getSortedSidebarEntries, getSystem, getSystemAncestors, listAllSystems, ontologyGraphNodeId, parentOf, parseOntologyId, projectOrganizationSurfaces, requiresAdminFor, resolveOrganizationModel, resolveSemanticIconComponent, resolveSystemConfig, topLevel, topologyRef, topologyRelationship };