@elevasis/core 0.23.0 → 0.24.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 (241) hide show
  1. package/dist/index.d.ts +1326 -552
  2. package/dist/index.js +869 -154
  3. package/dist/knowledge/index.d.ts +487 -209
  4. package/dist/knowledge/index.js +104 -1
  5. package/dist/organization-model/index.d.ts +1326 -552
  6. package/dist/organization-model/index.js +869 -154
  7. package/dist/test-utils/index.d.ts +357 -72
  8. package/dist/test-utils/index.js +795 -142
  9. package/package.json +5 -5
  10. package/src/README.md +14 -14
  11. package/src/__tests__/publish.test.ts +24 -24
  12. package/src/__tests__/template-core-compatibility.test.ts +9 -12
  13. package/src/_gen/__tests__/__snapshots__/contracts.md.snap +2102 -2096
  14. package/src/_gen/__tests__/scaffold-contracts.test.ts +30 -30
  15. package/src/auth/multi-tenancy/credentials/__tests__/encryption.test.ts +217 -217
  16. package/src/auth/multi-tenancy/credentials/server/encryption.ts +69 -69
  17. package/src/auth/multi-tenancy/credentials/server/kek-loader.ts +37 -37
  18. package/src/auth/multi-tenancy/index.ts +26 -26
  19. package/src/auth/multi-tenancy/invitations/api-schemas.ts +104 -104
  20. package/src/auth/multi-tenancy/memberships/api-schemas.ts +143 -143
  21. package/src/auth/multi-tenancy/memberships/index.ts +26 -26
  22. package/src/auth/multi-tenancy/memberships/membership.ts +130 -130
  23. package/src/auth/multi-tenancy/organizations/__tests__/api-schemas.test.ts +194 -194
  24. package/src/auth/multi-tenancy/organizations/api-schemas.ts +136 -136
  25. package/src/auth/multi-tenancy/permissions.test.ts +42 -42
  26. package/src/auth/multi-tenancy/permissions.ts +123 -123
  27. package/src/auth/multi-tenancy/role-management/api-schemas.ts +78 -78
  28. package/src/auth/multi-tenancy/role-management/index.ts +16 -16
  29. package/src/auth/multi-tenancy/theme-presets.ts +45 -45
  30. package/src/auth/multi-tenancy/types.ts +57 -57
  31. package/src/auth/multi-tenancy/users/api-schemas.ts +165 -165
  32. package/src/business/README.md +2 -2
  33. package/src/business/acquisition/activity-events.test.ts +250 -250
  34. package/src/business/acquisition/activity-events.ts +93 -93
  35. package/src/business/acquisition/api-schemas.test.ts +1883 -1843
  36. package/src/business/acquisition/api-schemas.ts +1492 -1497
  37. package/src/business/acquisition/build-templates.test.ts +240 -240
  38. package/src/business/acquisition/build-templates.ts +98 -98
  39. package/src/business/acquisition/crm-next-action.test.ts +262 -262
  40. package/src/business/acquisition/crm-next-action.ts +220 -220
  41. package/src/business/acquisition/crm-priority.test.ts +216 -216
  42. package/src/business/acquisition/crm-priority.ts +349 -349
  43. package/src/business/acquisition/crm-state-actions.test.ts +153 -153
  44. package/src/business/acquisition/deal-ownership.test.ts +351 -351
  45. package/src/business/acquisition/deal-ownership.ts +120 -120
  46. package/src/business/acquisition/derive-actions.test.ts +129 -104
  47. package/src/business/acquisition/derive-actions.ts +74 -84
  48. package/src/business/acquisition/index.ts +171 -170
  49. package/src/business/acquisition/ontology-validation.ts +309 -0
  50. package/src/business/acquisition/stateful.ts +30 -30
  51. package/src/business/acquisition/types.ts +396 -396
  52. package/src/business/clients/api-schemas.test.ts +115 -115
  53. package/src/business/clients/api-schemas.ts +158 -158
  54. package/src/business/clients/index.ts +1 -1
  55. package/src/business/crm/api-schemas.ts +40 -40
  56. package/src/business/crm/index.ts +1 -1
  57. package/src/business/deals/api-schemas.ts +87 -87
  58. package/src/business/deals/index.ts +1 -1
  59. package/src/business/index.ts +5 -5
  60. package/src/business/projects/types.ts +144 -144
  61. package/src/commands/queue/types/task.ts +15 -15
  62. package/src/execution/core/runner-types.ts +61 -61
  63. package/src/execution/core/sse-executions.ts +7 -7
  64. package/src/execution/engine/__tests__/fixtures/test-agents.ts +10 -10
  65. package/src/execution/engine/agent/core/__tests__/agent.test.ts +16 -16
  66. package/src/execution/engine/agent/core/__tests__/error-passthrough.test.ts +4 -4
  67. package/src/execution/engine/agent/core/types.ts +25 -25
  68. package/src/execution/engine/agent/index.ts +6 -6
  69. package/src/execution/engine/agent/reasoning/__tests__/request-builder.test.ts +24 -24
  70. package/src/execution/engine/index.ts +443 -443
  71. package/src/execution/engine/tools/integration/server/adapters/apify/__tests__/apify-run-actor.integration.test.ts +298 -298
  72. package/src/execution/engine/tools/integration/server/adapters/apify/apify-adapter.test.ts +55 -55
  73. package/src/execution/engine/tools/integration/server/adapters/apify/apify-adapter.ts +107 -107
  74. package/src/execution/engine/tools/integration/server/adapters/apollo/apollo-adapter.test.ts +48 -48
  75. package/src/execution/engine/tools/integration/server/adapters/apollo/apollo-adapter.ts +99 -99
  76. package/src/execution/engine/tools/integration/server/adapters/apollo/index.ts +1 -1
  77. package/src/execution/engine/tools/integration/server/adapters/attio/__tests__/attio-crud.integration.test.ts +363 -363
  78. package/src/execution/engine/tools/integration/server/adapters/attio/fetch/get-record/index.test.ts +162 -162
  79. package/src/execution/engine/tools/integration/server/adapters/attio/fetch/list-records/index.test.ts +316 -316
  80. package/src/execution/engine/tools/integration/server/adapters/clickup/clickup-adapter.test.ts +18 -18
  81. package/src/execution/engine/tools/integration/server/adapters/clickup/clickup-adapter.ts +194 -194
  82. package/src/execution/engine/tools/integration/server/adapters/clickup/index.ts +7 -7
  83. package/src/execution/engine/tools/integration/server/adapters/gmail/gmail-adapter.ts +204 -204
  84. package/src/execution/engine/tools/integration/server/adapters/gmail/gmail-tools.ts +105 -105
  85. package/src/execution/engine/tools/integration/server/adapters/google-calendar/google-calendar-adapter.ts +428 -428
  86. package/src/execution/engine/tools/integration/server/adapters/google-calendar/index.ts +2 -2
  87. package/src/execution/engine/tools/integration/server/adapters/google-sheets/__tests__/google-sheets.integration.test.ts +261 -261
  88. package/src/execution/engine/tools/integration/server/adapters/instantly/instantly-tools.ts +1474 -1474
  89. package/src/execution/engine/tools/integration/server/adapters/millionverifier/millionverifier-tools.ts +103 -103
  90. package/src/execution/engine/tools/integration/server/adapters/resend/fetch/send-email/index.test.ts +88 -88
  91. package/src/execution/engine/tools/integration/server/adapters/resend/fetch/send-email/index.ts +141 -141
  92. package/src/execution/engine/tools/integration/server/adapters/resend/fetch/utils/types.ts +76 -76
  93. package/src/execution/engine/tools/integration/server/adapters/signature-api/signature-api-tools.ts +182 -182
  94. package/src/execution/engine/tools/integration/server/adapters/stripe/stripe-tools.ts +310 -310
  95. package/src/execution/engine/tools/integration/service.test.ts +239 -239
  96. package/src/execution/engine/tools/integration/service.ts +172 -172
  97. package/src/execution/engine/tools/integration/tool.ts +255 -255
  98. package/src/execution/engine/tools/lead-service-types.ts +1005 -1005
  99. package/src/execution/engine/tools/messages.ts +43 -43
  100. package/src/execution/engine/tools/platform/acquisition/company-tools.ts +7 -7
  101. package/src/execution/engine/tools/platform/acquisition/contact-tools.ts +6 -6
  102. package/src/execution/engine/tools/platform/acquisition/list-tools.ts +6 -6
  103. package/src/execution/engine/tools/platform/acquisition/types.ts +280 -280
  104. package/src/execution/engine/tools/platform/email/types.ts +97 -97
  105. package/src/execution/engine/tools/registry.ts +704 -704
  106. package/src/execution/engine/tools/tool-maps.ts +831 -831
  107. package/src/execution/engine/tools/types.ts +234 -234
  108. package/src/execution/engine/workflow/types.ts +202 -202
  109. package/src/execution/external/__tests__/api-schemas.test.ts +127 -127
  110. package/src/execution/external/api-schemas.ts +40 -40
  111. package/src/execution/external/index.ts +1 -1
  112. package/src/index.ts +18 -18
  113. package/src/integrations/credentials/__tests__/api-schemas.test.ts +420 -420
  114. package/src/integrations/credentials/api-schemas.ts +146 -146
  115. package/src/integrations/credentials/schemas.ts +200 -200
  116. package/src/integrations/oauth/__tests__/provider-registry.test.ts +7 -7
  117. package/src/integrations/oauth/provider-registry.ts +74 -74
  118. package/src/integrations/oauth/server/credentials.ts +43 -43
  119. package/src/integrations/webhook-endpoints/__tests__/api-schemas.test.ts +327 -327
  120. package/src/integrations/webhook-endpoints/api-schemas.ts +103 -103
  121. package/src/integrations/webhook-endpoints/types.ts +58 -58
  122. package/src/knowledge/README.md +32 -32
  123. package/src/knowledge/__tests__/queries.test.ts +626 -535
  124. package/src/knowledge/format.ts +99 -99
  125. package/src/knowledge/index.ts +5 -5
  126. package/src/knowledge/published.ts +5 -5
  127. package/src/knowledge/queries.ts +269 -218
  128. package/src/operations/activities/api-schemas.ts +80 -80
  129. package/src/operations/activities/types.ts +64 -64
  130. package/src/organization-model/README.md +149 -149
  131. package/src/organization-model/__tests__/content-kinds-registry.test.ts +210 -210
  132. package/src/organization-model/__tests__/defaults.test.ts +168 -168
  133. package/src/organization-model/__tests__/domains/actions.test.ts +78 -56
  134. package/src/organization-model/__tests__/domains/customers.test.ts +299 -299
  135. package/src/organization-model/__tests__/domains/entities.test.ts +56 -56
  136. package/src/organization-model/__tests__/domains/goals.test.ts +493 -493
  137. package/src/organization-model/__tests__/domains/identity.test.ts +280 -280
  138. package/src/organization-model/__tests__/domains/navigation.test.ts +268 -268
  139. package/src/organization-model/__tests__/domains/offerings.test.ts +414 -414
  140. package/src/organization-model/__tests__/domains/policies.test.ts +323 -323
  141. package/src/organization-model/__tests__/domains/resource-mappings.test.ts +293 -293
  142. package/src/organization-model/__tests__/domains/resources.test.ts +382 -283
  143. package/src/organization-model/__tests__/domains/roles.test.ts +463 -463
  144. package/src/organization-model/__tests__/domains/statuses.test.ts +246 -246
  145. package/src/organization-model/__tests__/domains/systems.test.ts +209 -209
  146. package/src/organization-model/__tests__/flatten-additive-merge.test.ts +362 -361
  147. package/src/organization-model/__tests__/foundation.test.ts +77 -77
  148. package/src/organization-model/__tests__/get-resources-for-system.test.ts +144 -144
  149. package/src/organization-model/__tests__/graph.test.ts +1246 -887
  150. package/src/organization-model/__tests__/icons.test.ts +10 -1
  151. package/src/organization-model/__tests__/knowledge.test.ts +251 -15
  152. package/src/organization-model/__tests__/lookup-helpers.test.ts +438 -438
  153. package/src/organization-model/__tests__/migration-helpers.test.ts +591 -591
  154. package/src/organization-model/__tests__/prospecting-ssot.test.ts +103 -103
  155. package/src/organization-model/__tests__/recursive-system-schema.test.ts +535 -506
  156. package/src/organization-model/__tests__/resolve.test.ts +274 -164
  157. package/src/organization-model/__tests__/schema.test.ts +834 -301
  158. package/src/organization-model/__tests__/surface-projection.test.ts +284 -284
  159. package/src/organization-model/catalogs/lead-gen.ts +144 -144
  160. package/src/organization-model/content-kinds/config.ts +36 -36
  161. package/src/organization-model/content-kinds/index.ts +76 -72
  162. package/src/organization-model/content-kinds/pipeline.ts +68 -68
  163. package/src/organization-model/content-kinds/registry.ts +44 -44
  164. package/src/organization-model/content-kinds/status.ts +71 -71
  165. package/src/organization-model/content-kinds/template.ts +83 -83
  166. package/src/organization-model/content-kinds/types.ts +117 -117
  167. package/src/organization-model/contracts.ts +27 -27
  168. package/src/organization-model/defaults.ts +40 -50
  169. package/src/organization-model/domains/actions.ts +333 -239
  170. package/src/organization-model/domains/customers.ts +78 -78
  171. package/src/organization-model/domains/entities.ts +144 -144
  172. package/src/organization-model/domains/goals.ts +83 -83
  173. package/src/organization-model/domains/knowledge.ts +117 -101
  174. package/src/organization-model/domains/navigation.ts +139 -139
  175. package/src/organization-model/domains/offerings.ts +71 -71
  176. package/src/organization-model/domains/policies.ts +102 -102
  177. package/src/organization-model/domains/projects.ts +14 -14
  178. package/src/organization-model/domains/prospecting.ts +395 -395
  179. package/src/organization-model/domains/resources.ts +167 -132
  180. package/src/organization-model/domains/roles.ts +96 -96
  181. package/src/organization-model/domains/sales.test.ts +218 -218
  182. package/src/organization-model/domains/sales.ts +380 -380
  183. package/src/organization-model/domains/shared.ts +63 -63
  184. package/src/organization-model/domains/statuses.ts +339 -339
  185. package/src/organization-model/domains/systems.ts +217 -172
  186. package/src/organization-model/foundation.ts +75 -75
  187. package/src/organization-model/graph/build.ts +1016 -888
  188. package/src/organization-model/graph/index.ts +4 -4
  189. package/src/organization-model/graph/link.ts +10 -10
  190. package/src/organization-model/graph/schema.ts +76 -70
  191. package/src/organization-model/graph/types.ts +73 -67
  192. package/src/organization-model/helpers.ts +289 -241
  193. package/src/organization-model/icons.ts +78 -66
  194. package/src/organization-model/index.ts +130 -128
  195. package/src/organization-model/migration-helpers.ts +247 -244
  196. package/src/organization-model/ontology.ts +661 -0
  197. package/src/organization-model/organization-graph.mdx +110 -90
  198. package/src/organization-model/organization-model.mdx +226 -219
  199. package/src/organization-model/published.ts +289 -235
  200. package/src/organization-model/resolve.ts +146 -91
  201. package/src/organization-model/schema.ts +790 -671
  202. package/src/organization-model/surface-projection.ts +212 -212
  203. package/src/organization-model/types.ts +177 -167
  204. package/src/platform/api/types.ts +38 -38
  205. package/src/platform/constants/versions.ts +3 -3
  206. package/src/platform/index.ts +23 -23
  207. package/src/platform/registry/__tests__/command-view.test.ts +10 -10
  208. package/src/platform/registry/__tests__/resource-link.test.ts +35 -35
  209. package/src/platform/registry/__tests__/resource-registry.integration.test.ts +20 -20
  210. package/src/platform/registry/__tests__/resource-registry.nested-systems.test.ts +245 -245
  211. package/src/platform/registry/__tests__/resource-registry.test.ts +2053 -2053
  212. package/src/platform/registry/__tests__/validation.test.ts +1347 -1347
  213. package/src/platform/registry/command-view.ts +10 -10
  214. package/src/platform/registry/index.ts +103 -103
  215. package/src/platform/registry/resource-link.ts +32 -32
  216. package/src/platform/registry/resource-registry.ts +890 -890
  217. package/src/platform/registry/serialization.ts +295 -295
  218. package/src/platform/registry/serialized-types.ts +166 -166
  219. package/src/platform/registry/stats-types.ts +68 -68
  220. package/src/platform/registry/types.ts +425 -425
  221. package/src/platform/registry/validation.ts +745 -745
  222. package/src/platform/utils/__tests__/validation.test.ts +1084 -1084
  223. package/src/platform/utils/validation.ts +425 -425
  224. package/src/projects/api-schemas.test.ts +39 -39
  225. package/src/projects/api-schemas.ts +291 -291
  226. package/src/reference/_generated/contracts.md +2101 -2096
  227. package/src/reference/glossary.md +76 -76
  228. package/src/scaffold-registry/__tests__/index.test.ts +206 -206
  229. package/src/scaffold-registry/__tests__/schema.test.ts +166 -166
  230. package/src/scaffold-registry/index.ts +392 -392
  231. package/src/scaffold-registry/schema.ts +243 -243
  232. package/src/server.ts +289 -289
  233. package/src/supabase/database.types.ts +3153 -3153
  234. package/src/test-utils/README.md +37 -37
  235. package/src/test-utils/entities.ts +108 -108
  236. package/src/test-utils/fixtures/memberships.ts +82 -82
  237. package/src/test-utils/index.ts +12 -12
  238. package/src/test-utils/organization-model.ts +65 -65
  239. package/src/test-utils/published.ts +6 -6
  240. package/src/test-utils/rls/RLSTestContext.ts +588 -588
  241. package/src/test-utils/test-utils.test.ts +44 -44
@@ -19416,6 +19416,396 @@ function makeTask(overrides = {}) {
19416
19416
  ...overrides
19417
19417
  });
19418
19418
  }
19419
+ var OntologyKindSchema = z.enum([
19420
+ "object",
19421
+ "link",
19422
+ "action",
19423
+ "catalog",
19424
+ "event",
19425
+ "interface",
19426
+ "value-type",
19427
+ "property",
19428
+ "group",
19429
+ "surface"
19430
+ ]);
19431
+ var SYSTEM_PATH_PATTERN = "[a-z0-9][a-z0-9-]*(?:\\.[a-z0-9][a-z0-9-]*)*";
19432
+ var LOCAL_ID_PATTERN = "[a-z0-9][a-z0-9._-]*";
19433
+ var ONTOLOGY_ID_PATTERN = `^(global|${SYSTEM_PATH_PATTERN}):(${OntologyKindSchema.options.join("|")})\\/(${LOCAL_ID_PATTERN})$`;
19434
+ var ONTOLOGY_ID_REGEX = new RegExp(ONTOLOGY_ID_PATTERN);
19435
+ var OntologyIdSchema = z.string().trim().min(1).max(300).regex(
19436
+ ONTOLOGY_ID_REGEX,
19437
+ "Ontology IDs must use <system-path>:<kind>/<local-id> or global:<kind>/<local-id>"
19438
+ );
19439
+ function parseOntologyId(id) {
19440
+ const normalized = OntologyIdSchema.parse(id);
19441
+ const match = ONTOLOGY_ID_REGEX.exec(normalized);
19442
+ if (match === null) {
19443
+ throw new Error(`Invalid ontology ID "${id}"`);
19444
+ }
19445
+ return {
19446
+ id: normalized,
19447
+ scope: match[1],
19448
+ kind: match[2],
19449
+ localId: match[3],
19450
+ isGlobal: match[1] === "global"
19451
+ };
19452
+ }
19453
+ function formatOntologyId(input) {
19454
+ return OntologyIdSchema.parse(`${input.scope}:${input.kind}/${input.localId}`);
19455
+ }
19456
+ var OntologyReferenceListSchema = z.array(OntologyIdSchema).default([]).optional();
19457
+ var OntologyRecordBaseSchema = z.object({
19458
+ id: OntologyIdSchema,
19459
+ label: z.string().trim().min(1).max(160).optional(),
19460
+ description: z.string().trim().min(1).max(2e3).optional(),
19461
+ ownerSystemId: z.string().trim().min(1).max(200).optional(),
19462
+ aliases: z.array(OntologyIdSchema).optional()
19463
+ }).passthrough();
19464
+ var OntologyObjectTypeSchema = OntologyRecordBaseSchema.extend({
19465
+ properties: z.record(z.string().trim().min(1).max(200), z.unknown()).optional(),
19466
+ storage: z.record(z.string(), z.unknown()).optional()
19467
+ });
19468
+ var OntologyLinkTypeSchema = OntologyRecordBaseSchema.extend({
19469
+ from: OntologyIdSchema,
19470
+ to: OntologyIdSchema,
19471
+ cardinality: z.string().trim().min(1).max(80).optional(),
19472
+ via: z.string().trim().min(1).max(255).optional()
19473
+ });
19474
+ var OntologyActionTypeSchema = OntologyRecordBaseSchema.extend({
19475
+ actsOn: OntologyReferenceListSchema,
19476
+ input: z.record(z.string().trim().min(1).max(200), z.unknown()).optional(),
19477
+ effects: z.array(z.record(z.string(), z.unknown())).optional()
19478
+ });
19479
+ var OntologyCatalogTypeSchema = OntologyRecordBaseSchema.extend({
19480
+ kind: z.string().trim().min(1).max(120).optional(),
19481
+ appliesTo: OntologyIdSchema.optional(),
19482
+ entries: z.record(z.string().trim().min(1).max(200), z.unknown()).optional()
19483
+ });
19484
+ var OntologyEventTypeSchema = OntologyRecordBaseSchema.extend({
19485
+ payload: z.record(z.string().trim().min(1).max(200), z.unknown()).optional()
19486
+ });
19487
+ var OntologyInterfaceTypeSchema = OntologyRecordBaseSchema.extend({
19488
+ properties: z.record(z.string().trim().min(1).max(200), z.unknown()).optional()
19489
+ });
19490
+ var OntologyValueTypeSchema = OntologyRecordBaseSchema.extend({
19491
+ primitive: z.string().trim().min(1).max(120).optional()
19492
+ });
19493
+ var OntologySharedPropertySchema = OntologyRecordBaseSchema.extend({
19494
+ valueType: OntologyIdSchema.optional(),
19495
+ searchable: z.boolean().optional(),
19496
+ pii: z.boolean().optional()
19497
+ });
19498
+ var OntologyGroupSchema = OntologyRecordBaseSchema.extend({
19499
+ members: OntologyReferenceListSchema
19500
+ });
19501
+ var OntologySurfaceTypeSchema = OntologyRecordBaseSchema.extend({
19502
+ route: z.string().trim().min(1).max(500).optional()
19503
+ });
19504
+ var OntologyScopeSchema = z.object({
19505
+ objectTypes: z.record(OntologyIdSchema, OntologyObjectTypeSchema).default({}).optional(),
19506
+ linkTypes: z.record(OntologyIdSchema, OntologyLinkTypeSchema).default({}).optional(),
19507
+ actionTypes: z.record(OntologyIdSchema, OntologyActionTypeSchema).default({}).optional(),
19508
+ catalogTypes: z.record(OntologyIdSchema, OntologyCatalogTypeSchema).default({}).optional(),
19509
+ eventTypes: z.record(OntologyIdSchema, OntologyEventTypeSchema).default({}).optional(),
19510
+ interfaceTypes: z.record(OntologyIdSchema, OntologyInterfaceTypeSchema).default({}).optional(),
19511
+ valueTypes: z.record(OntologyIdSchema, OntologyValueTypeSchema).default({}).optional(),
19512
+ sharedProperties: z.record(OntologyIdSchema, OntologySharedPropertySchema).default({}).optional(),
19513
+ groups: z.record(OntologyIdSchema, OntologyGroupSchema).default({}).optional(),
19514
+ surfaces: z.record(OntologyIdSchema, OntologySurfaceTypeSchema).default({}).optional()
19515
+ }).default({});
19516
+ var DEFAULT_ONTOLOGY_SCOPE = {
19517
+ valueTypes: {
19518
+ "global:value-type/uuid": {
19519
+ id: "global:value-type/uuid",
19520
+ label: "UUID",
19521
+ primitive: "string"
19522
+ },
19523
+ "global:value-type/text": {
19524
+ id: "global:value-type/text",
19525
+ label: "Text",
19526
+ primitive: "string"
19527
+ },
19528
+ "global:value-type/url": {
19529
+ id: "global:value-type/url",
19530
+ label: "URL",
19531
+ primitive: "string"
19532
+ },
19533
+ "global:value-type/email": {
19534
+ id: "global:value-type/email",
19535
+ label: "Email",
19536
+ primitive: "string"
19537
+ }
19538
+ }
19539
+ };
19540
+ var SCOPE_KIND = {
19541
+ objectTypes: "object",
19542
+ linkTypes: "link",
19543
+ actionTypes: "action",
19544
+ catalogTypes: "catalog",
19545
+ eventTypes: "event",
19546
+ interfaceTypes: "interface",
19547
+ valueTypes: "value-type",
19548
+ sharedProperties: "property",
19549
+ groups: "group",
19550
+ surfaces: "surface"
19551
+ };
19552
+ var SCOPE_KEYS = Object.keys(SCOPE_KIND);
19553
+ function listResolvedOntologyRecords(index2) {
19554
+ return SCOPE_KEYS.flatMap((scopeKey) => {
19555
+ const kind = SCOPE_KIND[scopeKey];
19556
+ return Object.entries(index2[scopeKey]).sort(([leftId], [rightId]) => leftId.localeCompare(rightId)).map(([id, record]) => ({
19557
+ id,
19558
+ kind,
19559
+ record
19560
+ }));
19561
+ });
19562
+ }
19563
+ function originFromContext(context) {
19564
+ return {
19565
+ kind: context.kind,
19566
+ source: context.source,
19567
+ path: context.path,
19568
+ ...context.systemPath !== void 0 ? { systemPath: context.systemPath } : {},
19569
+ ...context.legacyId !== void 0 ? { legacyId: context.legacyId } : {}
19570
+ };
19571
+ }
19572
+ function createEmptyIndex() {
19573
+ return {
19574
+ objectTypes: {},
19575
+ linkTypes: {},
19576
+ actionTypes: {},
19577
+ catalogTypes: {},
19578
+ eventTypes: {},
19579
+ interfaceTypes: {},
19580
+ valueTypes: {},
19581
+ sharedProperties: {},
19582
+ groups: {},
19583
+ surfaces: {}
19584
+ };
19585
+ }
19586
+ function sortResolvedOntologyIndex(index2) {
19587
+ const sorted = createEmptyIndex();
19588
+ for (const scopeKey of SCOPE_KEYS) {
19589
+ const target = sorted[scopeKey];
19590
+ for (const [id, record] of Object.entries(index2[scopeKey]).sort(
19591
+ ([leftId], [rightId]) => leftId.localeCompare(rightId)
19592
+ )) {
19593
+ target[id] = record;
19594
+ }
19595
+ }
19596
+ return sorted;
19597
+ }
19598
+ function childSystemsOf(system) {
19599
+ return system.systems ?? system.subsystems ?? {};
19600
+ }
19601
+ function addRecord(index2, diagnostics, sourcesById, scopeKey, record, context) {
19602
+ let parsed;
19603
+ try {
19604
+ parsed = parseOntologyId(record.id);
19605
+ } catch {
19606
+ diagnostics.push({
19607
+ code: "invalid_ontology_id",
19608
+ message: `Invalid ontology ID "${record.id}" from ${context.source} at ${context.path.join(".")}`,
19609
+ id: record.id,
19610
+ path: context.path,
19611
+ source: context.source,
19612
+ origin: originFromContext(context)
19613
+ });
19614
+ return;
19615
+ }
19616
+ const expectedKind = SCOPE_KIND[scopeKey];
19617
+ if (parsed.kind !== expectedKind) {
19618
+ diagnostics.push({
19619
+ code: "ontology_kind_mismatch",
19620
+ message: `Ontology ID "${record.id}" has kind "${parsed.kind}" but was authored in ${scopeKey} (${expectedKind}) at ${context.path.join(".")}`,
19621
+ id: record.id,
19622
+ path: context.path,
19623
+ source: context.source,
19624
+ origin: originFromContext(context)
19625
+ });
19626
+ return;
19627
+ }
19628
+ const existing = sourcesById.get(parsed.id);
19629
+ if (existing !== void 0) {
19630
+ diagnostics.push({
19631
+ code: "duplicate_ontology_id",
19632
+ message: `Duplicate ontology ID "${parsed.id}" from ${context.source} at ${context.path.join(".")} conflicts with ${existing.source} at ${existing.path.join(".")}`,
19633
+ id: parsed.id,
19634
+ path: context.path,
19635
+ source: context.source,
19636
+ origin: originFromContext(context),
19637
+ existingSource: existing.source,
19638
+ existingOrigin: originFromContext(existing)
19639
+ });
19640
+ return;
19641
+ }
19642
+ sourcesById.set(parsed.id, context);
19643
+ index2[scopeKey][parsed.id] = {
19644
+ ...record,
19645
+ origin: originFromContext(context)
19646
+ };
19647
+ }
19648
+ function addScope(index2, diagnostics, sourcesById, scope, source, path) {
19649
+ if (scope === void 0) return;
19650
+ for (const scopeKey of SCOPE_KEYS) {
19651
+ const records = scope[scopeKey] ?? {};
19652
+ for (const [key, record] of Object.entries(records)) {
19653
+ addRecord(index2, diagnostics, sourcesById, scopeKey, record, {
19654
+ source,
19655
+ path: [...path, scopeKey, key],
19656
+ kind: "authored",
19657
+ systemPath: source.startsWith("system:") ? source.slice("system:".length, -".ontology".length) : void 0
19658
+ });
19659
+ }
19660
+ }
19661
+ }
19662
+ function legacyObjectId(entity) {
19663
+ return formatOntologyId({ scope: entity.ownedBySystemId, kind: "object", localId: entity.id });
19664
+ }
19665
+ function legacyActionOwner(action, entities) {
19666
+ const firstAffectedEntityId = action.affects?.find((entityId) => entities[entityId] !== void 0);
19667
+ if (firstAffectedEntityId !== void 0) {
19668
+ return entities[firstAffectedEntityId].ownedBySystemId;
19669
+ }
19670
+ if (typeof action.scope === "object") {
19671
+ return action.scope.domain;
19672
+ }
19673
+ return "global";
19674
+ }
19675
+ function addLegacyEntityProjections(index2, diagnostics, sourcesById, entities) {
19676
+ for (const entity of Object.values(entities)) {
19677
+ const objectType = {
19678
+ id: legacyObjectId(entity),
19679
+ label: entity.label,
19680
+ description: entity.description,
19681
+ ownerSystemId: entity.ownedBySystemId,
19682
+ ...entity.table !== void 0 ? {
19683
+ storage: {
19684
+ kind: "table",
19685
+ table: entity.table
19686
+ }
19687
+ } : {},
19688
+ legacyEntityId: entity.id,
19689
+ ...entity.rowSchema !== void 0 ? { rowSchema: entity.rowSchema } : {},
19690
+ ...entity.stateCatalogId !== void 0 ? { stateCatalogId: entity.stateCatalogId } : {}
19691
+ };
19692
+ addRecord(index2, diagnostics, sourcesById, "objectTypes", objectType, {
19693
+ source: "legacy.entities",
19694
+ path: ["entities", entity.id],
19695
+ kind: "projected",
19696
+ systemPath: entity.ownedBySystemId,
19697
+ legacyId: entity.id
19698
+ });
19699
+ entity.links?.forEach((link, linkIndex) => {
19700
+ const targetEntity = entities[link.toEntity];
19701
+ if (targetEntity === void 0) return;
19702
+ const linkType = {
19703
+ id: formatOntologyId({
19704
+ scope: entity.ownedBySystemId,
19705
+ kind: "link",
19706
+ localId: `${entity.id}-${link.toEntity}-${linkIndex}`
19707
+ }),
19708
+ label: link.label ?? link.kind,
19709
+ ownerSystemId: entity.ownedBySystemId,
19710
+ from: legacyObjectId(entity),
19711
+ to: legacyObjectId(targetEntity),
19712
+ cardinality: link.kind,
19713
+ ...link.via !== void 0 ? { via: link.via } : {},
19714
+ legacyEntityId: entity.id
19715
+ };
19716
+ addRecord(index2, diagnostics, sourcesById, "linkTypes", linkType, {
19717
+ source: "legacy.entities.links",
19718
+ path: ["entities", entity.id, "links", linkIndex],
19719
+ kind: "projected",
19720
+ systemPath: entity.ownedBySystemId,
19721
+ legacyId: `${entity.id}.links.${linkIndex}`
19722
+ });
19723
+ });
19724
+ }
19725
+ }
19726
+ function addLegacyActionProjections(index2, diagnostics, sourcesById, actions, entities) {
19727
+ for (const action of Object.values(actions)) {
19728
+ const ownerSystemId = legacyActionOwner(action, entities);
19729
+ const actionType = {
19730
+ id: formatOntologyId({ scope: ownerSystemId, kind: "action", localId: action.id }),
19731
+ label: action.label,
19732
+ description: action.description,
19733
+ ownerSystemId,
19734
+ actsOn: action.affects?.map((entityId) => entities[entityId] ? legacyObjectId(entities[entityId]) : void 0).filter((id) => id !== void 0),
19735
+ ...action.resourceId !== void 0 ? { resourceId: action.resourceId } : {},
19736
+ ...action.invocations !== void 0 ? { invocations: action.invocations } : {},
19737
+ ...action.lifecycle !== void 0 ? { lifecycle: action.lifecycle } : {},
19738
+ legacyActionId: action.id
19739
+ };
19740
+ addRecord(index2, diagnostics, sourcesById, "actionTypes", actionType, {
19741
+ source: "legacy.actions",
19742
+ path: ["actions", action.id],
19743
+ kind: "projected",
19744
+ systemPath: ownerSystemId,
19745
+ legacyId: action.id
19746
+ });
19747
+ }
19748
+ }
19749
+ function addSystemContentProjections(index2, diagnostics, sourcesById, systemPath, system, schemaPath) {
19750
+ const content = system.content ?? {};
19751
+ for (const [localId, node] of Object.entries(content)) {
19752
+ if (node.kind !== "schema") continue;
19753
+ const entries = Object.fromEntries(
19754
+ Object.entries(content).filter(([, candidate]) => candidate.parentContentId === localId).map(([entryId, candidate]) => [
19755
+ entryId,
19756
+ {
19757
+ label: candidate.label ?? entryId,
19758
+ type: candidate.type,
19759
+ ...candidate.description !== void 0 ? { description: candidate.description } : {},
19760
+ ...candidate.data !== void 0 ? candidate.data : {}
19761
+ }
19762
+ ])
19763
+ );
19764
+ const catalogType = {
19765
+ id: formatOntologyId({ scope: systemPath, kind: "catalog", localId }),
19766
+ label: node.label ?? localId,
19767
+ description: node.description,
19768
+ ownerSystemId: systemPath,
19769
+ kind: node.type,
19770
+ ...typeof node.data?.["entityId"] === "string" ? { appliesTo: formatOntologyId({ scope: systemPath, kind: "object", localId: node.data["entityId"] }) } : {},
19771
+ ...Object.keys(entries).length > 0 ? { entries } : {},
19772
+ ...node.data !== void 0 ? { data: node.data } : {},
19773
+ legacyContentId: `${systemPath}:${localId}`
19774
+ };
19775
+ addRecord(index2, diagnostics, sourcesById, "catalogTypes", catalogType, {
19776
+ source: "legacy.system.content",
19777
+ path: [...schemaPath, "content", localId],
19778
+ kind: "projected",
19779
+ systemPath,
19780
+ legacyId: `${systemPath}:${localId}`
19781
+ });
19782
+ }
19783
+ }
19784
+ function addSystemScopes(index2, diagnostics, sourcesById, systems, prefix, schemaPath) {
19785
+ for (const [key, system] of Object.entries(systems)) {
19786
+ const systemPath = prefix ? `${prefix}.${key}` : key;
19787
+ const currentPath = [...schemaPath, key];
19788
+ addScope(index2, diagnostics, sourcesById, system.ontology, `system:${systemPath}.ontology`, [
19789
+ ...currentPath,
19790
+ "ontology"
19791
+ ]);
19792
+ addSystemContentProjections(index2, diagnostics, sourcesById, systemPath, system, currentPath);
19793
+ addSystemScopes(index2, diagnostics, sourcesById, childSystemsOf(system), systemPath, [
19794
+ ...currentPath,
19795
+ system.systems !== void 0 ? "systems" : "subsystems"
19796
+ ]);
19797
+ }
19798
+ }
19799
+ function compileOrganizationOntology(model) {
19800
+ const ontology = createEmptyIndex();
19801
+ const diagnostics = [];
19802
+ const sourcesById = /* @__PURE__ */ new Map();
19803
+ addScope(ontology, diagnostics, sourcesById, model.ontology, "organization.ontology", ["ontology"]);
19804
+ addSystemScopes(ontology, diagnostics, sourcesById, model.systems ?? {}, "", ["systems"]);
19805
+ addLegacyEntityProjections(ontology, diagnostics, sourcesById, model.entities ?? {});
19806
+ addLegacyActionProjections(ontology, diagnostics, sourcesById, model.actions ?? {}, model.entities ?? {});
19807
+ return { ontology: sortResolvedOntologyIndex(ontology), diagnostics };
19808
+ }
19419
19809
 
19420
19810
  // src/organization-model/content-kinds/registry.ts
19421
19811
  function defineContentType(def) {
@@ -19601,73 +19991,78 @@ function lookupContentType(kind, type3) {
19601
19991
  return CONTENT_KIND_REGISTRY[key];
19602
19992
  }
19603
19993
  var ORGANIZATION_MODEL_ICON_TOKENS = [
19604
- "nav.dashboard",
19605
- "nav.calendar",
19606
- "nav.sales",
19607
- "nav.crm",
19608
- "nav.lead-gen",
19609
- "nav.projects",
19610
- "nav.operations",
19611
- "nav.monitoring",
19612
- "nav.knowledge",
19613
- "nav.settings",
19614
- "nav.admin",
19615
- "nav.archive",
19616
- "knowledge.playbook",
19617
- "knowledge.strategy",
19618
- "knowledge.reference",
19619
- "feature.dashboard",
19620
- "feature.calendar",
19621
- "feature.business",
19622
- "feature.sales",
19623
- "feature.crm",
19624
- "feature.finance",
19625
- "feature.lead-gen",
19626
- "feature.platform",
19627
- "feature.projects",
19628
- "feature.operations",
19629
- "feature.knowledge",
19630
- "feature.monitoring",
19631
- "feature.settings",
19632
- "feature.admin",
19633
- "feature.archive",
19634
- "feature.seo",
19635
- "resource.agent",
19636
- "resource.workflow",
19637
- "resource.integration",
19638
- "resource.database",
19639
- "resource.user",
19640
- "resource.team",
19641
- "integration.gmail",
19642
- "integration.google-sheets",
19643
- "integration.attio",
19644
- "surface.dashboard",
19645
- "surface.calendar",
19646
- "surface.overview",
19647
- "surface.command-view",
19648
- "surface.command-queue",
19649
- "surface.pipeline",
19650
- "surface.lists",
19651
- "surface.resources",
19652
- "surface.settings",
19653
- "status.success",
19654
- "status.error",
19655
- "status.warning",
19656
- "status.info",
19657
- "status.pending",
19658
- "action.approve",
19659
- "action.reject",
19660
- "action.retry",
19661
- "action.edit",
19662
- "action.view",
19663
- "action.launch",
19664
- "action.message",
19665
- "action.escalate",
19666
- "action.promote",
19667
- "action.submit",
19668
- "action.email"
19994
+ // Navigation / app areas
19995
+ "dashboard",
19996
+ "calendar",
19997
+ "sales",
19998
+ "crm",
19999
+ "lead-gen",
20000
+ "projects",
20001
+ "operations",
20002
+ "monitoring",
20003
+ "knowledge",
20004
+ "settings",
20005
+ "admin",
20006
+ "archive",
20007
+ "business",
20008
+ "finance",
20009
+ "platform",
20010
+ "seo",
20011
+ // Knowledge kinds
20012
+ "playbook",
20013
+ "strategy",
20014
+ "reference",
20015
+ // Resource kinds
20016
+ "agent",
20017
+ "workflow",
20018
+ "integration",
20019
+ "database",
20020
+ "user",
20021
+ "team",
20022
+ // Integration specifics
20023
+ "gmail",
20024
+ "google-sheets",
20025
+ "attio",
20026
+ // Surface / UI views
20027
+ "overview",
20028
+ "command-view",
20029
+ "command-queue",
20030
+ "pipeline",
20031
+ "lists",
20032
+ "resources",
20033
+ // Actions
20034
+ "approve",
20035
+ "reject",
20036
+ "retry",
20037
+ "edit",
20038
+ "view",
20039
+ "launch",
20040
+ "message",
20041
+ "escalate",
20042
+ "promote",
20043
+ "submit",
20044
+ "email",
20045
+ // Status
20046
+ "success",
20047
+ "error",
20048
+ "warning",
20049
+ "info",
20050
+ "pending",
20051
+ // OM / UI group icons
20052
+ "bolt",
20053
+ "building",
20054
+ "briefcase",
20055
+ "apps",
20056
+ "graph",
20057
+ "shield",
20058
+ "users",
20059
+ "chart-bar",
20060
+ "search"
19669
20061
  ];
19670
- var CustomIconTokenSchema = z.string().trim().max(80).regex(/^custom\.[a-z0-9]+(?:[-._][a-z0-9]+)*$/, "Custom icon tokens must start with custom.");
20062
+ var CustomIconTokenSchema = z.string().trim().max(80).regex(
20063
+ /^custom\.[a-z0-9]+(?:[-._][a-z0-9]+)*$/,
20064
+ 'Custom icon tokens must start with "custom." followed by lowercase alphanumeric segments'
20065
+ );
19671
20066
  var OrganizationModelBuiltinIconTokenSchema = z.enum(ORGANIZATION_MODEL_ICON_TOKENS);
19672
20067
  var OrganizationModelIconTokenSchema = z.union([
19673
20068
  OrganizationModelBuiltinIconTokenSchema,
@@ -20263,7 +20658,99 @@ var LEAD_GEN_ACTION_ENTRIES = Object.fromEntries(
20263
20658
  return [parsed.id, parsed];
20264
20659
  })
20265
20660
  );
20266
- var DEFAULT_ORGANIZATION_MODEL_ACTIONS = LEAD_GEN_ACTION_ENTRIES;
20661
+ var CRM_ACTION_ENTRY_INPUTS = [
20662
+ {
20663
+ id: "send_reply",
20664
+ order: 210,
20665
+ label: "Send Reply",
20666
+ description: "Send a contextual reply for an active CRM deal.",
20667
+ scope: { domain: "sales" },
20668
+ resourceId: "crm-send-reply-workflow",
20669
+ affects: ["crm.deal"]
20670
+ },
20671
+ {
20672
+ id: "send_link",
20673
+ order: 220,
20674
+ label: "Send Booking Link",
20675
+ description: "Send a booking link to move a deal toward a scheduled call.",
20676
+ scope: { domain: "sales" },
20677
+ resourceId: "crm-send-booking-link-workflow",
20678
+ affects: ["crm.deal"]
20679
+ },
20680
+ {
20681
+ id: "send_nudge",
20682
+ order: 230,
20683
+ label: "Send Nudge",
20684
+ description: "Send a follow-up nudge for a stalled CRM deal.",
20685
+ scope: { domain: "sales" },
20686
+ resourceId: "crm-send-nudge-workflow",
20687
+ affects: ["crm.deal"]
20688
+ },
20689
+ {
20690
+ id: "rebook",
20691
+ order: 240,
20692
+ label: "Rebook",
20693
+ description: "Rebook a missed or rescheduled CRM appointment.",
20694
+ scope: { domain: "sales" },
20695
+ resourceId: "crm-rebook-workflow",
20696
+ affects: ["crm.deal"]
20697
+ },
20698
+ {
20699
+ id: "move_to_proposal",
20700
+ order: 250,
20701
+ label: "Move to Proposal",
20702
+ description: "Advance a qualified CRM deal into the proposal stage.",
20703
+ scope: { domain: "sales" },
20704
+ resourceId: "move_to_proposal-workflow",
20705
+ affects: ["crm.deal"]
20706
+ },
20707
+ {
20708
+ id: "move_to_closing",
20709
+ order: 260,
20710
+ label: "Move to Closing",
20711
+ description: "Advance a proposal-stage CRM deal into closing.",
20712
+ scope: { domain: "sales" },
20713
+ resourceId: "move_to_closing-workflow",
20714
+ affects: ["crm.deal"]
20715
+ },
20716
+ {
20717
+ id: "move_to_closed_won",
20718
+ order: 270,
20719
+ label: "Close Won",
20720
+ description: "Mark a CRM deal as closed won.",
20721
+ scope: { domain: "sales" },
20722
+ resourceId: "move_to_closed_won-workflow",
20723
+ affects: ["crm.deal"]
20724
+ },
20725
+ {
20726
+ id: "move_to_closed_lost",
20727
+ order: 280,
20728
+ label: "Close Lost",
20729
+ description: "Mark a CRM deal as closed lost.",
20730
+ scope: { domain: "sales" },
20731
+ resourceId: "move_to_closed_lost-workflow",
20732
+ affects: ["crm.deal"]
20733
+ },
20734
+ {
20735
+ id: "move_to_nurturing",
20736
+ order: 290,
20737
+ label: "Move to Nurturing",
20738
+ description: "Move a CRM deal into nurturing for future follow-up.",
20739
+ scope: { domain: "sales" },
20740
+ resourceId: "move_to_nurturing-workflow",
20741
+ affects: ["crm.deal"]
20742
+ }
20743
+ ];
20744
+ var CRM_ACTION_ENTRIES = Object.fromEntries(
20745
+ CRM_ACTION_ENTRY_INPUTS.map((action) => {
20746
+ const parsed = ActionSchema.parse(action);
20747
+ return [parsed.id, parsed];
20748
+ })
20749
+ );
20750
+ var DEFAULT_ORGANIZATION_MODEL_ACTIONS = {
20751
+ ...LEAD_GEN_ACTION_ENTRIES,
20752
+ ...CRM_ACTION_ENTRIES
20753
+ };
20267
20754
 
20268
20755
  // src/organization-model/domains/systems.ts
20269
20756
  var SystemKindSchema = z.enum(["product", "operational", "platform", "diagnostic"]).meta({ label: "System kind", color: "blue" });
@@ -20285,6 +20772,17 @@ var SystemUiSchema = z.object({
20285
20772
  icon: IconNameSchema.optional(),
20286
20773
  order: z.number().int().optional()
20287
20774
  });
20775
+ var JsonValueSchema = z.lazy(
20776
+ () => z.union([
20777
+ z.string(),
20778
+ z.number(),
20779
+ z.boolean(),
20780
+ z.null(),
20781
+ z.array(JsonValueSchema),
20782
+ z.record(z.string(), JsonValueSchema)
20783
+ ])
20784
+ );
20785
+ var SystemConfigSchema = z.record(z.string().trim().min(1).max(200), JsonValueSchema).default({}).optional();
20288
20786
  var SystemEntrySchema = z.object({
20289
20787
  /** Stable tenant-defined system id (e.g. "sys.lead-gen" or "sales.crm"). */
20290
20788
  id: SystemIdSchema,
@@ -20330,11 +20828,21 @@ var SystemEntrySchema = z.object({
20330
20828
  /** Domain-map iteration order. Convention: multiples of 10 (10, 20, 30, ...) to allow easy insertion. */
20331
20829
  order: z.number(),
20332
20830
  /**
20333
- * System-scoped operational data, co-located with the owning system.
20334
- * Per L1, L3, L13: keyed by local NodeId (the key is the local id; qualified
20335
- * id is `<system-path>:<local-id>`, computed by graph projection).
20336
- * Per L14: every ContentNode carries both `kind` and `type`.
20337
- * Per D2: unregistered (kind, type) pairs parse successfully.
20831
+ * System-local JSON settings and defaults. Strongly typed OM fields,
20832
+ * secrets, credentials, and runtime state stay outside this bucket.
20833
+ */
20834
+ config: SystemConfigSchema,
20835
+ /**
20836
+ * System-owned ontology declarations. `systems` is now the canonical child
20837
+ * key; this scope holds the object, action, catalog, link, event, and
20838
+ * shared contract records owned by this system.
20839
+ */
20840
+ ontology: OntologyScopeSchema.optional(),
20841
+ /**
20842
+ * @deprecated Compatibility-only bridge for old tenant content nodes and
20843
+ * migration readers. New schema/catalog authoring belongs in ontology;
20844
+ * new system-local settings belong in config. Bridge nodes are keyed by
20845
+ * local NodeId and may still project to content-node:* graph IDs.
20338
20846
  */
20339
20847
  content: z.record(z.string().trim().min(1).max(200), ContentNodeSchema).optional(),
20340
20848
  /**
@@ -20344,14 +20852,17 @@ var SystemEntrySchema = z.object({
20344
20852
  * Per Phase 4: `id` and `parentSystemId` fields will be removed in favour of
20345
20853
  * position-derived paths. Both still exist on this schema for backward compat.
20346
20854
  */
20855
+ systems: z.lazy(() => z.record(z.string().trim().min(1).max(100), SystemEntrySchema)).optional(),
20856
+ /** @deprecated Use systems. Accepted as a compatibility alias during the ontology bridge. */
20347
20857
  subsystems: z.lazy(() => z.record(z.string().trim().min(1).max(100), SystemEntrySchema)).optional()
20348
20858
  }).refine((system) => system.label !== void 0 || system.title !== void 0, {
20349
20859
  path: ["label"],
20350
20860
  message: "System must provide label or title"
20351
20861
  }).transform((system) => {
20352
- if (system.status === void 0) return system;
20862
+ const normalizedSystem = system.systems !== void 0 && system.subsystems === void 0 ? { ...system, subsystems: system.systems } : system;
20863
+ if (normalizedSystem.status === void 0) return normalizedSystem;
20353
20864
  console.warn("[organization-model] System.status is deprecated; use System.lifecycle instead.");
20354
- return system.lifecycle === void 0 ? { ...system, lifecycle: system.status } : system;
20865
+ return normalizedSystem.lifecycle === void 0 ? { ...normalizedSystem, lifecycle: normalizedSystem.status } : normalizedSystem;
20355
20866
  });
20356
20867
  var SystemsDomainSchema = z.record(z.string(), SystemEntrySchema).refine((record) => Object.entries(record).every(([key, entry]) => entry.id === key), {
20357
20868
  message: "Each system entry id must match its map key"
@@ -20363,6 +20874,7 @@ z.enum(["workflow", "agent", "integration", "script"]).meta({ label: "Resource k
20363
20874
  var ResourceGovernanceStatusSchema = z.enum(["active", "deprecated", "archived"]).meta({ label: "Governance status", color: "teal" });
20364
20875
  var AgentKindSchema = z.enum(["orchestrator", "specialist", "utility", "platform"]).meta({ label: "Agent kind", color: "violet" });
20365
20876
  var ScriptResourceLanguageSchema = z.enum(["shell", "sql", "typescript", "python"]).meta({ label: "Language" });
20877
+ var CodeReferenceRoleSchema = z.enum(["entrypoint", "handler", "schema", "test", "docs", "config"]).meta({ label: "Code reference role", color: "blue" });
20366
20878
  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");
20367
20879
  var EventIdSchema = z.string().trim().min(1).max(300).regex(
20368
20880
  /^[A-Za-z0-9]+(?:[-._][A-Za-z0-9]+)*:[a-z0-9]+(?:[-._][a-z0-9]+)*$/,
@@ -20380,6 +20892,19 @@ EventEmissionDescriptorSchema.extend({
20380
20892
  ownerId: z.union([ResourceIdSchema, ModelIdSchema]),
20381
20893
  ownerKind: z.enum(["resource", "entity"]).meta({ label: "Owner kind" })
20382
20894
  });
20895
+ var ResourceOntologyBindingSchema = z.object({
20896
+ implements: z.array(OntologyIdSchema).optional(),
20897
+ reads: z.array(OntologyIdSchema).optional(),
20898
+ writes: z.array(OntologyIdSchema).optional(),
20899
+ usesCatalogs: z.array(OntologyIdSchema).optional(),
20900
+ emits: z.array(OntologyIdSchema).optional()
20901
+ });
20902
+ var CodeReferenceSchema = z.object({
20903
+ path: z.string().trim().min(1).max(500).regex(/^[A-Za-z0-9_./$@()[\] -]+$/, "Code reference paths must be repo-relative paths"),
20904
+ role: CodeReferenceRoleSchema,
20905
+ symbol: z.string().trim().min(1).max(200).optional(),
20906
+ description: z.string().trim().min(1).max(300).optional()
20907
+ });
20383
20908
  var ResourceEntryBaseSchema = z.object({
20384
20909
  /** Canonical resource id; runtime resourceId derives from this value. */
20385
20910
  id: ResourceIdSchema,
@@ -20389,7 +20914,15 @@ var ResourceEntryBaseSchema = z.object({
20389
20914
  systemPath: SystemPathSchema.meta({ ref: "system" }),
20390
20915
  /** Optional role responsible for maintaining this resource. */
20391
20916
  ownerRoleId: ModelIdSchema.meta({ ref: "role" }).optional(),
20392
- status: ResourceGovernanceStatusSchema
20917
+ status: ResourceGovernanceStatusSchema,
20918
+ /**
20919
+ * Ontology contract bindings for the semantic work this resource performs.
20920
+ * `emits` stays nested here so top-level resource emits descriptors remain
20921
+ * compatible with graph event projection during the bridge.
20922
+ */
20923
+ ontology: ResourceOntologyBindingSchema.optional(),
20924
+ /** Repo-relative implementation breadcrumbs for agents and operators. */
20925
+ codeRefs: z.array(CodeReferenceSchema).default([])
20393
20926
  });
20394
20927
  var WorkflowResourceEntrySchema = ResourceEntryBaseSchema.extend({
20395
20928
  kind: z.literal("workflow"),
@@ -20546,19 +21079,29 @@ var KnowledgeTargetKindSchema = z.enum([
20546
21079
  "goal",
20547
21080
  "customer-segment",
20548
21081
  "offering",
21082
+ "ontology",
20549
21083
  // D4: content nodes are a valid knowledge target after compound-domain data moved into system.content
20550
21084
  "content-node"
20551
21085
  ]).meta({ label: "Target kind" });
20552
21086
  var KnowledgeTargetRefSchema = z.object({
20553
21087
  kind: KnowledgeTargetKindSchema,
20554
- // D4: content-node targets use a qualified id format '<system-path>:<local-content-id>'
20555
- // which contains a colon separator and cannot satisfy ModelIdSchema. Use a permissive
20556
- // string schema here; business-logic validation of target existence is done in
20557
- // OrganizationModelSchema.superRefine (knowledgeTargetExists).
21088
+ // D4: content-node targets use a qualified id format '<system-path>:<local-content-id>'.
21089
+ // Ontology targets use the canonical '<scope>:<kind>/<local-id>' ontology id format.
21090
+ // Business-logic validation of target existence is done in OrganizationModelSchema.superRefine.
20558
21091
  id: z.string().trim().min(1).max(300)
21092
+ }).superRefine((target, ctx) => {
21093
+ if (target.kind !== "ontology") return;
21094
+ const result = OntologyIdSchema.safeParse(target.id);
21095
+ if (!result.success) {
21096
+ ctx.addIssue({
21097
+ code: z.ZodIssueCode.custom,
21098
+ path: ["id"],
21099
+ message: "Ontology knowledge targets must use <system-path>:<kind>/<local-id> or global:<kind>/<local-id>"
21100
+ });
21101
+ }
20559
21102
  });
20560
21103
  var LegacyKnowledgeLinkSchema = z.object({
20561
- nodeId: NodeIdStringSchema
21104
+ nodeId: z.union([NodeIdStringSchema, z.templateLiteral(["ontology:", OntologyIdSchema])])
20562
21105
  });
20563
21106
  var CanonicalKnowledgeLinkSchema = z.object({
20564
21107
  target: KnowledgeTargetRefSchema
@@ -20589,6 +21132,8 @@ var OrgKnowledgeNodeSchema = z.object({
20589
21132
  icon: IconNameSchema.optional(),
20590
21133
  /** Canonical documentation URL when body content is a local summary. */
20591
21134
  externalUrl: z.string().trim().url().max(500).optional(),
21135
+ /** Optional generated source file path for local MDX-backed knowledge nodes. */
21136
+ sourceFilePath: z.string().trim().min(1).max(500).optional(),
20592
21137
  /** Raw MDX string. Phase 2 will introduce a structured block format. */
20593
21138
  body: z.string().trim().min(1),
20594
21139
  /**
@@ -20689,6 +21234,7 @@ z.enum([
20689
21234
  "roles",
20690
21235
  "goals",
20691
21236
  "systems",
21237
+ "ontology",
20692
21238
  "resources",
20693
21239
  "actions",
20694
21240
  "entities",
@@ -20707,6 +21253,7 @@ var DEFAULT_ORGANIZATION_MODEL_DOMAIN_METADATA = {
20707
21253
  roles: { version: 1, lastModified: "2026-05-10" },
20708
21254
  goals: { version: 1, lastModified: "2026-05-10" },
20709
21255
  systems: { version: 1, lastModified: "2026-05-10" },
21256
+ ontology: { version: 1, lastModified: "2026-05-14" },
20710
21257
  resources: { version: 1, lastModified: "2026-05-10" },
20711
21258
  actions: { version: 1, lastModified: "2026-05-10" },
20712
21259
  entities: { version: 1, lastModified: "2026-05-10" },
@@ -20721,6 +21268,7 @@ var OrganizationModelDomainMetadataByDomainSchema = z.object({
20721
21268
  roles: OrganizationModelDomainMetadataSchema,
20722
21269
  goals: OrganizationModelDomainMetadataSchema,
20723
21270
  systems: OrganizationModelDomainMetadataSchema,
21271
+ ontology: OrganizationModelDomainMetadataSchema,
20724
21272
  resources: OrganizationModelDomainMetadataSchema,
20725
21273
  actions: OrganizationModelDomainMetadataSchema,
20726
21274
  entities: OrganizationModelDomainMetadataSchema,
@@ -20738,6 +21286,7 @@ var OrganizationModelSchemaBase = z.object({
20738
21286
  roles: RolesDomainSchema.default(DEFAULT_ORGANIZATION_MODEL_ROLES),
20739
21287
  goals: GoalsDomainSchema.default(DEFAULT_ORGANIZATION_MODEL_GOALS),
20740
21288
  systems: SystemsDomainSchema.default(DEFAULT_ORGANIZATION_MODEL_SYSTEMS),
21289
+ ontology: OntologyScopeSchema.default(DEFAULT_ONTOLOGY_SCOPE),
20741
21290
  resources: ResourcesDomainSchema.default(DEFAULT_ORGANIZATION_MODEL_RESOURCES),
20742
21291
  actions: ActionsDomainSchema.default(DEFAULT_ORGANIZATION_MODEL_ACTIONS),
20743
21292
  entities: EntitiesDomainSchema.default(DEFAULT_ORGANIZATION_MODEL_ENTITIES),
@@ -20765,13 +21314,16 @@ function asRoleHolderArray(heldBy) {
20765
21314
  function isKnowledgeKindCompatibleWithTarget(knowledgeKind, targetKind) {
20766
21315
  if (knowledgeKind === "reference") return true;
20767
21316
  if (knowledgeKind === "playbook") {
20768
- return ["system", "resource", "stage", "action"].includes(targetKind);
21317
+ return ["system", "resource", "stage", "action", "ontology"].includes(targetKind);
20769
21318
  }
20770
21319
  if (knowledgeKind === "strategy") {
20771
- return ["system", "goal", "offering", "customer-segment"].includes(targetKind);
21320
+ return ["system", "goal", "offering", "customer-segment", "ontology"].includes(targetKind);
20772
21321
  }
20773
21322
  return false;
20774
21323
  }
21324
+ function isRecord(value) {
21325
+ return typeof value === "object" && value !== null && !Array.isArray(value);
21326
+ }
20775
21327
  var OrganizationModelSchema = OrganizationModelSchemaBase.superRefine((model, ctx) => {
20776
21328
  function collectAllSystems(systems, prefix = "", schemaPath = ["systems"]) {
20777
21329
  const result = [];
@@ -20779,8 +21331,11 @@ var OrganizationModelSchema = OrganizationModelSchemaBase.superRefine((model, ct
20779
21331
  const path = prefix ? `${prefix}.${key}` : key;
20780
21332
  const currentSchemaPath = [...schemaPath, key];
20781
21333
  result.push({ path, schemaPath: currentSchemaPath, system });
20782
- if (system.subsystems !== void 0) {
20783
- result.push(...collectAllSystems(system.subsystems, path, [...currentSchemaPath, "subsystems"]));
21334
+ const childSystems = system.systems ?? system.subsystems;
21335
+ if (childSystems !== void 0) {
21336
+ result.push(
21337
+ ...collectAllSystems(childSystems, path, [...currentSchemaPath, system.systems !== void 0 ? "systems" : "subsystems"])
21338
+ );
20784
21339
  }
20785
21340
  }
20786
21341
  return result;
@@ -20800,7 +21355,7 @@ var OrganizationModelSchema = OrganizationModelSchemaBase.superRefine((model, ct
20800
21355
  `System "${system.id}" references unknown parent "${system.parentSystemId}"`
20801
21356
  );
20802
21357
  }
20803
- const hasChildren = Object.keys(system.subsystems ?? {}).length > 0 || allSystems.some((candidate) => candidate.path.startsWith(`${path}.`) && !candidate.path.slice(path.length + 1).includes("."));
21358
+ const hasChildren = Object.keys(system.systems ?? system.subsystems ?? {}).length > 0 || allSystems.some((candidate) => candidate.path.startsWith(`${path}.`) && !candidate.path.slice(path.length + 1).includes("."));
20804
21359
  const contributesRoutePath = system.ui?.path !== void 0 || system.path !== void 0 || !hasChildren;
20805
21360
  if (contributesRoutePath) {
20806
21361
  const effectivePath = system.ui?.path ?? system.path ?? defaultSystemPathFor(path);
@@ -20816,7 +21371,7 @@ var OrganizationModelSchema = OrganizationModelSchemaBase.superRefine((model, ct
20816
21371
  }
20817
21372
  }
20818
21373
  if (hasChildren && isLifecycleEnabled(system.lifecycle, system.enabled)) {
20819
- const hasEnabledDescendant = Object.values(system.subsystems ?? {}).some(
21374
+ const hasEnabledDescendant = Object.values(system.systems ?? system.subsystems ?? {}).some(
20820
21375
  (candidate) => isLifecycleEnabled(candidate.lifecycle, candidate.enabled)
20821
21376
  ) || allSystems.some(
20822
21377
  (candidate) => candidate.path.startsWith(`${path}.`) && !candidate.path.slice(path.length + 1).includes(".") && isLifecycleEnabled(candidate.system.lifecycle, candidate.system.enabled)
@@ -21061,6 +21616,60 @@ var OrganizationModelSchema = OrganizationModelSchemaBase.superRefine((model, ct
21061
21616
  const stageIds = /* @__PURE__ */ new Set();
21062
21617
  const actionIds = new Set(Object.keys(model.actions));
21063
21618
  const offeringsById = new Map(Object.entries(model.offerings));
21619
+ const ontologyCompilation = compileOrganizationOntology(model);
21620
+ const ontologyIndexByKind = {
21621
+ object: ontologyCompilation.ontology.objectTypes,
21622
+ link: ontologyCompilation.ontology.linkTypes,
21623
+ action: ontologyCompilation.ontology.actionTypes,
21624
+ catalog: ontologyCompilation.ontology.catalogTypes,
21625
+ event: ontologyCompilation.ontology.eventTypes,
21626
+ interface: ontologyCompilation.ontology.interfaceTypes,
21627
+ "value-type": ontologyCompilation.ontology.valueTypes,
21628
+ property: ontologyCompilation.ontology.sharedProperties,
21629
+ group: ontologyCompilation.ontology.groups,
21630
+ surface: ontologyCompilation.ontology.surfaces
21631
+ };
21632
+ const ontologyIds = new Set(Object.values(ontologyIndexByKind).flatMap((index2) => Object.keys(index2)));
21633
+ const ontologyReferenceKeyKinds = {
21634
+ valueType: "value-type",
21635
+ catalogType: "catalog",
21636
+ objectType: "object",
21637
+ eventType: "event",
21638
+ actionType: "action",
21639
+ linkType: "link",
21640
+ interfaceType: "interface",
21641
+ propertyType: "property",
21642
+ groupType: "group",
21643
+ surfaceType: "surface",
21644
+ stepCatalog: "catalog"
21645
+ };
21646
+ function validateKnownOntologyReferences(ownerId, value, path, seen = /* @__PURE__ */ new WeakSet()) {
21647
+ if (Array.isArray(value)) {
21648
+ value.forEach((entry, index2) => validateKnownOntologyReferences(ownerId, entry, [...path, index2], seen));
21649
+ return;
21650
+ }
21651
+ if (!isRecord(value)) return;
21652
+ if (seen.has(value)) return;
21653
+ seen.add(value);
21654
+ Object.entries(value).forEach(([key, entry]) => {
21655
+ const expectedKind = ontologyReferenceKeyKinds[key];
21656
+ if (expectedKind !== void 0) {
21657
+ if (typeof entry !== "string") {
21658
+ addIssue(ctx, [...path, key], `Ontology record "${ownerId}" ${key} must be an ontology ID string`);
21659
+ } else if (ontologyIndexByKind[expectedKind][entry] === void 0) {
21660
+ addIssue(
21661
+ ctx,
21662
+ [...path, key],
21663
+ `Ontology record "${ownerId}" ${key} references unknown ${expectedKind} ontology ID "${entry}"`
21664
+ );
21665
+ }
21666
+ }
21667
+ validateKnownOntologyReferences(ownerId, entry, [...path, key], seen);
21668
+ });
21669
+ }
21670
+ for (const { id, record } of listResolvedOntologyRecords(ontologyCompilation.ontology)) {
21671
+ validateKnownOntologyReferences(id, record, record.origin.path);
21672
+ }
21064
21673
  Object.values(model.policies).forEach((policy) => {
21065
21674
  policy.appliesTo.systemIds.forEach((systemId, systemIndex) => {
21066
21675
  if (!systemsById.has(systemId)) {
@@ -21114,6 +21723,7 @@ var OrganizationModelSchema = OrganizationModelSchemaBase.superRefine((model, ct
21114
21723
  if (kind === "goal") return goalsById.has(id);
21115
21724
  if (kind === "customer-segment") return segmentsById.has(id);
21116
21725
  if (kind === "offering") return offeringsById.has(id);
21726
+ if (kind === "ontology") return ontologyIds.has(id);
21117
21727
  return false;
21118
21728
  }
21119
21729
  Object.entries(model.knowledge).forEach(([nodeId, node]) => {
@@ -21157,6 +21767,26 @@ var OrganizationModelSchema = OrganizationModelSchemaBase.superRefine((model, ct
21157
21767
  );
21158
21768
  }
21159
21769
  });
21770
+ function validateResourceOntologyBinding(resourceId, bindingKey, expectedKind, ids) {
21771
+ ids?.forEach((ontologyId, ontologyIndex) => {
21772
+ if (ontologyIndexByKind[expectedKind][ontologyId] === void 0) {
21773
+ addIssue(
21774
+ ctx,
21775
+ ["resources", resourceId, "ontology", bindingKey, ontologyIndex],
21776
+ `Resource "${resourceId}" ontology binding "${bindingKey}" references unknown ${expectedKind} ontology ID "${ontologyId}"`
21777
+ );
21778
+ }
21779
+ });
21780
+ }
21781
+ Object.values(model.resources).forEach((resource) => {
21782
+ const binding = resource.ontology;
21783
+ if (binding === void 0) return;
21784
+ validateResourceOntologyBinding(resource.id, "implements", "action", binding.implements);
21785
+ validateResourceOntologyBinding(resource.id, "reads", "object", binding.reads);
21786
+ validateResourceOntologyBinding(resource.id, "writes", "object", binding.writes);
21787
+ validateResourceOntologyBinding(resource.id, "usesCatalogs", "catalog", binding.usesCatalogs);
21788
+ validateResourceOntologyBinding(resource.id, "emits", "event", binding.emits);
21789
+ });
21160
21790
  Object.values(model.roles).forEach((role) => {
21161
21791
  if (role.heldBy === void 0) return;
21162
21792
  asRoleHolderArray(role.heldBy).forEach((holder, holderIndex) => {
@@ -21191,11 +21821,13 @@ var OrganizationModelSchema = OrganizationModelSchemaBase.superRefine((model, ct
21191
21821
  });
21192
21822
  });
21193
21823
  function validateSystemContent(system, systemPath) {
21824
+ const childSystems = system.systems ?? system.subsystems;
21825
+ const childKey = system.systems !== void 0 ? "systems" : "subsystems";
21194
21826
  const content = system.content;
21195
21827
  if (content === void 0 || Object.keys(content).length === 0) {
21196
- if (system.subsystems !== void 0) {
21197
- Object.entries(system.subsystems).forEach(([childKey, child]) => {
21198
- validateSystemContent(child, [...systemPath, "subsystems", childKey]);
21828
+ if (childSystems !== void 0) {
21829
+ Object.entries(childSystems).forEach(([childLocalId, child]) => {
21830
+ validateSystemContent(child, [...systemPath, childKey, childLocalId]);
21199
21831
  });
21200
21832
  }
21201
21833
  return;
@@ -21251,15 +21883,18 @@ var OrganizationModelSchema = OrganizationModelSchemaBase.superRefine((model, ct
21251
21883
  }
21252
21884
  }
21253
21885
  });
21254
- if (system.subsystems !== void 0) {
21255
- Object.entries(system.subsystems).forEach(([childKey, child]) => {
21256
- validateSystemContent(child, [...systemPath, "subsystems", childKey]);
21886
+ if (childSystems !== void 0) {
21887
+ Object.entries(childSystems).forEach(([childLocalId, child]) => {
21888
+ validateSystemContent(child, [...systemPath, childKey, childLocalId]);
21257
21889
  });
21258
21890
  }
21259
21891
  }
21260
21892
  Object.entries(model.systems).forEach(([systemKey, system]) => {
21261
21893
  validateSystemContent(system, ["systems", systemKey]);
21262
21894
  });
21895
+ for (const diagnostic of ontologyCompilation.diagnostics) {
21896
+ addIssue(ctx, diagnostic.path, diagnostic.message);
21897
+ }
21263
21898
  });
21264
21899
 
21265
21900
  // src/organization-model/defaults.ts
@@ -21273,14 +21908,14 @@ var DEFAULT_ORGANIZATION_MODEL_NAVIGATION = {
21273
21908
  label: "Dashboard",
21274
21909
  path: "/",
21275
21910
  surfaceType: "dashboard",
21276
- icon: "feature.dashboard",
21911
+ icon: "dashboard",
21277
21912
  order: 10,
21278
21913
  targets: { systems: ["dashboard"] }
21279
21914
  },
21280
21915
  business: {
21281
21916
  type: "group",
21282
21917
  label: "Business",
21283
- icon: "feature.business",
21918
+ icon: "business",
21284
21919
  order: 20,
21285
21920
  children: {
21286
21921
  sales: {
@@ -21288,7 +21923,7 @@ var DEFAULT_ORGANIZATION_MODEL_NAVIGATION = {
21288
21923
  label: "Sales",
21289
21924
  path: "/sales",
21290
21925
  surfaceType: "page",
21291
- icon: "feature.sales",
21926
+ icon: "sales",
21292
21927
  order: 10,
21293
21928
  targets: { systems: ["sales"] }
21294
21929
  },
@@ -21297,7 +21932,7 @@ var DEFAULT_ORGANIZATION_MODEL_NAVIGATION = {
21297
21932
  label: "Clients",
21298
21933
  path: "/clients",
21299
21934
  surfaceType: "list",
21300
- icon: "feature.projects",
21935
+ icon: "projects",
21301
21936
  order: 20,
21302
21937
  targets: { systems: ["clients"] }
21303
21938
  },
@@ -21306,7 +21941,7 @@ var DEFAULT_ORGANIZATION_MODEL_NAVIGATION = {
21306
21941
  label: "Projects",
21307
21942
  path: "/projects",
21308
21943
  surfaceType: "page",
21309
- icon: "feature.projects",
21944
+ icon: "projects",
21310
21945
  order: 30,
21311
21946
  targets: { systems: ["projects"] }
21312
21947
  }
@@ -21315,7 +21950,7 @@ var DEFAULT_ORGANIZATION_MODEL_NAVIGATION = {
21315
21950
  operations: {
21316
21951
  type: "group",
21317
21952
  label: "Operations",
21318
- icon: "feature.operations",
21953
+ icon: "operations",
21319
21954
  order: 30,
21320
21955
  children: {
21321
21956
  "operations-overview": {
@@ -21363,7 +21998,7 @@ var DEFAULT_ORGANIZATION_MODEL_NAVIGATION = {
21363
21998
  monitoring: {
21364
21999
  type: "group",
21365
22000
  label: "Monitoring",
21366
- icon: "feature.monitoring",
22001
+ icon: "monitoring",
21367
22002
  order: 40,
21368
22003
  children: {
21369
22004
  "monitoring-overview": {
@@ -21425,36 +22060,19 @@ var DEFAULT_ORGANIZATION_MODEL_NAVIGATION = {
21425
22060
  }
21426
22061
  },
21427
22062
  knowledge: {
21428
- type: "group",
21429
- label: "Knowledge",
21430
- icon: "feature.knowledge",
21431
- order: 50,
21432
- children: {
21433
- "knowledge-base": {
21434
- type: "surface",
21435
- label: "Knowledge Base",
21436
- path: "/knowledge",
21437
- surfaceType: "page",
21438
- order: 10,
21439
- targets: { systems: ["knowledge.base"] }
21440
- },
21441
- "knowledge-command-view": {
21442
- type: "surface",
21443
- label: "Command View",
21444
- path: "/knowledge/command-view",
21445
- surfaceType: "graph",
21446
- order: 20,
21447
- targets: { systems: ["knowledge.command-view"] },
21448
- devOnly: true
21449
- }
21450
- }
22063
+ type: "surface",
22064
+ label: "Knowledge Base",
22065
+ path: "/knowledge",
22066
+ surfaceType: "page",
22067
+ icon: "knowledge",
22068
+ order: 50
21451
22069
  }
21452
22070
  },
21453
22071
  bottom: {
21454
22072
  settings: {
21455
22073
  type: "group",
21456
22074
  label: "Settings",
21457
- icon: "feature.settings",
22075
+ icon: "settings",
21458
22076
  order: 10,
21459
22077
  children: {
21460
22078
  "settings-account": {
@@ -21526,7 +22144,7 @@ var DEFAULT_ORGANIZATION_MODEL_NAVIGATION = {
21526
22144
  admin: {
21527
22145
  type: "group",
21528
22146
  label: "Admin",
21529
- icon: "feature.admin",
22147
+ icon: "admin",
21530
22148
  order: 20,
21531
22149
  children: {
21532
22150
  "admin-dashboard": {
@@ -21606,7 +22224,7 @@ var DEFAULT_ORGANIZATION_MODEL = {
21606
22224
  enabled: true,
21607
22225
  lifecycle: "active",
21608
22226
  path: "/",
21609
- icon: "feature.dashboard"
22227
+ icon: "dashboard"
21610
22228
  },
21611
22229
  platform: {
21612
22230
  id: "platform",
@@ -21616,7 +22234,7 @@ var DEFAULT_ORGANIZATION_MODEL = {
21616
22234
  enabled: true,
21617
22235
  lifecycle: "active",
21618
22236
  color: "cyan",
21619
- icon: "feature.platform"
22237
+ icon: "platform"
21620
22238
  },
21621
22239
  finance: {
21622
22240
  id: "finance",
@@ -21626,7 +22244,7 @@ var DEFAULT_ORGANIZATION_MODEL = {
21626
22244
  enabled: true,
21627
22245
  lifecycle: "active",
21628
22246
  color: "green",
21629
- icon: "feature.finance"
22247
+ icon: "finance"
21630
22248
  },
21631
22249
  sales: {
21632
22250
  id: "sales",
@@ -21636,7 +22254,7 @@ var DEFAULT_ORGANIZATION_MODEL = {
21636
22254
  enabled: true,
21637
22255
  lifecycle: "active",
21638
22256
  color: "blue",
21639
- icon: "feature.sales",
22257
+ icon: "sales",
21640
22258
  path: "/sales"
21641
22259
  },
21642
22260
  "sales.crm": {
@@ -21646,8 +22264,12 @@ var DEFAULT_ORGANIZATION_MODEL = {
21646
22264
  description: "Relationship pipeline and deal management",
21647
22265
  enabled: true,
21648
22266
  lifecycle: "active",
22267
+ actions: Object.values(CRM_ACTION_ENTRIES).map((action) => ({
22268
+ actionId: action.id,
22269
+ intent: "exposes"
22270
+ })),
21649
22271
  color: "blue",
21650
- icon: "feature.crm",
22272
+ icon: "crm",
21651
22273
  path: "/crm"
21652
22274
  },
21653
22275
  "sales.lead-gen": {
@@ -21657,12 +22279,12 @@ var DEFAULT_ORGANIZATION_MODEL = {
21657
22279
  description: "Prospecting, qualification, and outreach preparation",
21658
22280
  enabled: true,
21659
22281
  lifecycle: "active",
21660
- actions: Object.values(DEFAULT_ORGANIZATION_MODEL_ACTIONS).map((action) => ({
22282
+ actions: Object.values(LEAD_GEN_ACTION_ENTRIES).map((action) => ({
21661
22283
  actionId: action.id,
21662
22284
  intent: "exposes"
21663
22285
  })),
21664
22286
  color: "cyan",
21665
- icon: "feature.lead-gen",
22287
+ icon: "lead-gen",
21666
22288
  path: "/lead-gen"
21667
22289
  },
21668
22290
  projects: {
@@ -21673,7 +22295,7 @@ var DEFAULT_ORGANIZATION_MODEL = {
21673
22295
  enabled: true,
21674
22296
  lifecycle: "active",
21675
22297
  color: "orange",
21676
- icon: "feature.projects",
22298
+ icon: "projects",
21677
22299
  path: "/projects"
21678
22300
  },
21679
22301
  clients: {
@@ -21684,7 +22306,7 @@ var DEFAULT_ORGANIZATION_MODEL = {
21684
22306
  enabled: true,
21685
22307
  lifecycle: "active",
21686
22308
  color: "orange",
21687
- icon: "feature.projects",
22309
+ icon: "projects",
21688
22310
  path: "/clients"
21689
22311
  },
21690
22312
  operations: {
@@ -21695,7 +22317,7 @@ var DEFAULT_ORGANIZATION_MODEL = {
21695
22317
  enabled: true,
21696
22318
  lifecycle: "active",
21697
22319
  color: "violet",
21698
- icon: "feature.operations"
22320
+ icon: "operations"
21699
22321
  },
21700
22322
  "knowledge.command-view": {
21701
22323
  id: "knowledge.command-view",
@@ -21761,7 +22383,7 @@ var DEFAULT_ORGANIZATION_MODEL = {
21761
22383
  enabled: true,
21762
22384
  lifecycle: "active",
21763
22385
  path: "/monitoring/calendar",
21764
- icon: "feature.calendar"
22386
+ icon: "calendar"
21765
22387
  },
21766
22388
  "monitoring.activity-log": {
21767
22389
  id: "monitoring.activity-log",
@@ -21817,7 +22439,7 @@ var DEFAULT_ORGANIZATION_MODEL = {
21817
22439
  label: "Settings",
21818
22440
  enabled: true,
21819
22441
  lifecycle: "active",
21820
- icon: "feature.settings"
22442
+ icon: "settings"
21821
22443
  },
21822
22444
  "settings.account": {
21823
22445
  id: "settings.account",
@@ -21890,7 +22512,7 @@ var DEFAULT_ORGANIZATION_MODEL = {
21890
22512
  enabled: true,
21891
22513
  lifecycle: "active",
21892
22514
  path: "/admin",
21893
- icon: "feature.admin",
22515
+ icon: "admin",
21894
22516
  requiresAdmin: true
21895
22517
  },
21896
22518
  "admin.system-health": {
@@ -21940,7 +22562,7 @@ var DEFAULT_ORGANIZATION_MODEL = {
21940
22562
  enabled: true,
21941
22563
  lifecycle: "active",
21942
22564
  path: "/archive",
21943
- icon: "feature.archive",
22565
+ icon: "archive",
21944
22566
  devOnly: true
21945
22567
  },
21946
22568
  "archive.agent-chat": {
@@ -21975,7 +22597,7 @@ var DEFAULT_ORGANIZATION_MODEL = {
21975
22597
  enabled: true,
21976
22598
  lifecycle: "active",
21977
22599
  color: "teal",
21978
- icon: "feature.knowledge"
22600
+ icon: "knowledge"
21979
22601
  },
21980
22602
  "knowledge.base": {
21981
22603
  id: "knowledge.base",
@@ -21986,11 +22608,13 @@ var DEFAULT_ORGANIZATION_MODEL = {
21986
22608
  path: "/knowledge"
21987
22609
  }
21988
22610
  },
22611
+ ontology: DEFAULT_ONTOLOGY_SCOPE,
21989
22612
  resources: DEFAULT_ORGANIZATION_MODEL_RESOURCES,
21990
22613
  actions: DEFAULT_ORGANIZATION_MODEL_ACTIONS,
21991
22614
  entities: DEFAULT_ORGANIZATION_MODEL_ENTITIES2,
21992
22615
  policies: DEFAULT_ORGANIZATION_MODEL_POLICIES,
21993
- // Phase 4 (D1): statuses top-level field removed; status data lives in system.content.
22616
+ // Phase 4 (D1): statuses top-level field removed; bridge status mirrors may
22617
+ // still project from System.content, but primary authoring belongs in ontology.
21994
22618
  knowledge: DEFAULT_ORGANIZATION_MODEL_KNOWLEDGE
21995
22619
  };
21996
22620
 
@@ -21998,6 +22622,31 @@ var DEFAULT_ORGANIZATION_MODEL = {
21998
22622
  function isPlainObject(value) {
21999
22623
  return typeof value === "object" && value !== null && !Array.isArray(value);
22000
22624
  }
22625
+ function collectNestedSystemPaths(systems, prefix = "") {
22626
+ const paths = /* @__PURE__ */ new Set();
22627
+ for (const [key, value] of Object.entries(systems)) {
22628
+ if (!isPlainObject(value)) continue;
22629
+ const path = prefix ? `${prefix}.${key}` : key;
22630
+ for (const childKey of ["systems", "subsystems"]) {
22631
+ const childSystems = value[childKey];
22632
+ if (!isPlainObject(childSystems)) continue;
22633
+ for (const childPath of collectNestedSystemPaths(childSystems, path)) {
22634
+ paths.add(childPath);
22635
+ }
22636
+ }
22637
+ if (prefix !== "") {
22638
+ paths.add(path);
22639
+ }
22640
+ }
22641
+ return paths;
22642
+ }
22643
+ function pruneFlatSystemDescendantCollisions(base, override) {
22644
+ const result = { ...base };
22645
+ for (const nestedPath of collectNestedSystemPaths(override)) {
22646
+ delete result[nestedPath];
22647
+ }
22648
+ return result;
22649
+ }
22001
22650
  function deepMerge2(base, override) {
22002
22651
  if (override === void 0) {
22003
22652
  return base;
@@ -22012,12 +22661,16 @@ function deepMerge2(base, override) {
22012
22661
  for (const [key, value] of Object.entries(override)) {
22013
22662
  if (value === void 0) continue;
22014
22663
  const existing = result[key];
22664
+ if (key === "systems" && isPlainObject(existing) && isPlainObject(value)) {
22665
+ result[key] = deepMerge2(pruneFlatSystemDescendantCollisions(existing, value), value);
22666
+ continue;
22667
+ }
22015
22668
  result[key] = isPlainObject(existing) && isPlainObject(value) ? deepMerge2(existing, value) : value;
22016
22669
  }
22017
22670
  return result;
22018
22671
  }
22019
- function resolveOrganizationModel(override, organizationId) {
22020
- const merged = deepMerge2(DEFAULT_ORGANIZATION_MODEL, override);
22672
+ function resolveOrganizationModel(override, organizationIdOrOptions, options) {
22673
+ const merged = deepMerge2(DEFAULT_ORGANIZATION_MODEL, override) ;
22021
22674
  return OrganizationModelSchema.parse(merged);
22022
22675
  }
22023
22676