@elevasis/core 0.24.1 → 0.26.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (82) hide show
  1. package/dist/index.d.ts +239 -86
  2. package/dist/index.js +474 -1346
  3. package/dist/knowledge/index.d.ts +57 -39
  4. package/dist/knowledge/index.js +1 -1
  5. package/dist/organization-model/index.d.ts +239 -86
  6. package/dist/organization-model/index.js +474 -1346
  7. package/dist/test-utils/index.d.ts +24 -31
  8. package/dist/test-utils/index.js +76 -1238
  9. package/package.json +1 -1
  10. package/src/_gen/__tests__/__snapshots__/contracts.md.snap +108 -96
  11. package/src/business/acquisition/api-schemas.test.ts +70 -77
  12. package/src/business/acquisition/api-schemas.ts +21 -42
  13. package/src/business/acquisition/derive-actions.test.ts +11 -21
  14. package/src/business/acquisition/derive-actions.ts +61 -14
  15. package/src/business/acquisition/ontology-validation.ts +4 -4
  16. package/src/business/acquisition/types.ts +7 -8
  17. package/src/execution/engine/llm/adapters/__tests__/openrouter.integration.test.ts +10 -10
  18. package/src/knowledge/__tests__/queries.test.ts +960 -546
  19. package/src/knowledge/format.ts +322 -100
  20. package/src/knowledge/index.ts +18 -5
  21. package/src/knowledge/queries.ts +1004 -240
  22. package/src/organization-model/__tests__/content-kinds-registry.test.ts +35 -210
  23. package/src/organization-model/__tests__/defaults.test.ts +4 -4
  24. package/src/organization-model/__tests__/deprecate-helpers.test.ts +71 -0
  25. package/src/organization-model/__tests__/domains/actions.test.ts +12 -36
  26. package/src/organization-model/__tests__/domains/offerings.test.ts +13 -6
  27. package/src/organization-model/__tests__/domains/resources.test.ts +497 -350
  28. package/src/organization-model/__tests__/domains/systems.test.ts +6 -7
  29. package/src/organization-model/__tests__/flatten-additive-merge.test.ts +68 -80
  30. package/src/organization-model/__tests__/foundation.test.ts +81 -14
  31. package/src/organization-model/__tests__/graph.test.ts +662 -694
  32. package/src/organization-model/__tests__/knowledge.test.ts +31 -17
  33. package/src/organization-model/__tests__/lookup-helpers.test.ts +128 -438
  34. package/src/organization-model/__tests__/migration-helpers.test.ts +362 -591
  35. package/src/organization-model/__tests__/prospecting-ssot.test.ts +68 -103
  36. package/src/organization-model/__tests__/published-zero-leak.test.ts +17 -0
  37. package/src/organization-model/__tests__/recursive-system-schema.test.ts +159 -532
  38. package/src/organization-model/__tests__/resolve.test.ts +88 -49
  39. package/src/organization-model/__tests__/scaffolders.test.ts +93 -0
  40. package/src/organization-model/__tests__/schema.test.ts +65 -56
  41. package/src/organization-model/catalogs/lead-gen.ts +0 -103
  42. package/src/organization-model/defaults.ts +17 -702
  43. package/src/organization-model/domains/actions.ts +116 -333
  44. package/src/organization-model/domains/knowledge.ts +15 -7
  45. package/src/organization-model/domains/projects.ts +4 -4
  46. package/src/organization-model/domains/prospecting.ts +405 -395
  47. package/src/organization-model/domains/resources.ts +206 -135
  48. package/src/organization-model/domains/sales.ts +5 -5
  49. package/src/organization-model/domains/systems.ts +8 -23
  50. package/src/organization-model/graph/build.ts +223 -294
  51. package/src/organization-model/graph/schema.ts +2 -3
  52. package/src/organization-model/graph/types.ts +12 -14
  53. package/src/organization-model/helpers.ts +120 -141
  54. package/src/organization-model/icons.ts +1 -0
  55. package/src/organization-model/index.ts +107 -126
  56. package/src/organization-model/migration-helpers.ts +211 -249
  57. package/src/organization-model/ontology.ts +0 -60
  58. package/src/organization-model/organization-graph.mdx +4 -5
  59. package/src/organization-model/organization-model.mdx +1 -1
  60. package/src/organization-model/published.ts +251 -228
  61. package/src/organization-model/resolve.ts +4 -5
  62. package/src/organization-model/scaffolders/helpers.ts +84 -0
  63. package/src/organization-model/scaffolders/index.ts +19 -0
  64. package/src/organization-model/scaffolders/scaffoldKnowledgeNode.ts +48 -0
  65. package/src/organization-model/scaffolders/scaffoldOntologyRecord.ts +38 -0
  66. package/src/organization-model/scaffolders/scaffoldResource.ts +59 -0
  67. package/src/organization-model/scaffolders/scaffoldSystem.ts +110 -0
  68. package/src/organization-model/scaffolders/types.ts +81 -0
  69. package/src/organization-model/schema.ts +610 -704
  70. package/src/organization-model/types.ts +167 -161
  71. package/src/platform/constants/versions.ts +1 -1
  72. package/src/platform/registry/__tests__/validation.test.ts +23 -0
  73. package/src/platform/registry/validation.ts +13 -2
  74. package/src/reference/_generated/contracts.md +108 -96
  75. package/src/reference/glossary.md +71 -69
  76. package/src/organization-model/content-kinds/config.ts +0 -36
  77. package/src/organization-model/content-kinds/index.ts +0 -78
  78. package/src/organization-model/content-kinds/pipeline.ts +0 -68
  79. package/src/organization-model/content-kinds/registry.ts +0 -44
  80. package/src/organization-model/content-kinds/status.ts +0 -71
  81. package/src/organization-model/content-kinds/template.ts +0 -83
  82. package/src/organization-model/content-kinds/types.ts +0 -117
@@ -1,9 +1,7 @@
1
- import { describe, expect, it } from 'vitest'
2
- import { CRM_ACTION_ENTRIES } from '@repo/core/organization-model'
1
+ import { describe, expect, it } from 'vitest'
3
2
  import type { AcqDealRow } from './types'
4
3
  import type { Action, ActionDef } from './derive-actions'
5
4
  import { DEFAULT_CRM_ACTIONS, SendReplyActionPayloadSchema, deriveActions } from './derive-actions'
6
- import { getCrmActionMetadata } from './ontology-validation'
7
5
 
8
6
  // ---------------------------------------------------------------------------
9
7
  // Fixture builder
@@ -96,28 +94,20 @@ describe('DEFAULT_CRM_ACTIONS static contract', () => {
96
94
  expect(unique.size).toBe(keys.length)
97
95
  })
98
96
 
99
- it('derives promoted CRM runtime metadata from CRM_ACTION_ENTRIES', () => {
97
+ it('derives promoted CRM runtime metadata from the local runtime contract', () => {
100
98
  const sendReply = DEFAULT_CRM_ACTIONS.find((a) => a.key === 'send_reply')
101
- const metadata = CRM_ACTION_ENTRIES['send_reply']
102
- const ontologyMetadata = getCrmActionMetadata('send_reply')
103
99
 
104
100
  expect(sendReply).toBeDefined()
105
- expect(sendReply?.key).toBe(metadata.id)
106
- expect(sendReply?.label).toBe(metadata.label)
107
- expect(sendReply?.workflowId).toBe(metadata.resourceId)
108
- expect(ontologyMetadata).toMatchObject({
109
- id: metadata.id,
110
- label: metadata.label,
111
- resourceId: metadata.resourceId
112
- })
101
+ expect(sendReply?.label).toBe('Send Reply')
102
+ expect(sendReply?.workflowId).toBe('crm-send-reply-workflow')
103
+ })
104
+
105
+ it('keeps mark_no_show as a runtime-only CRM action', () => {
106
+ const markNoShow = DEFAULT_CRM_ACTIONS.find((a) => a.key === 'mark_no_show')
107
+
108
+ expect(markNoShow).toBeDefined()
109
+ expect(markNoShow?.workflowId).toBe('mark_no_show-workflow')
113
110
  })
114
-
115
- it('keeps mark_no_show as a runtime-only CRM action', () => {
116
- const markNoShow = DEFAULT_CRM_ACTIONS.find((a) => a.key === 'mark_no_show')
117
-
118
- expect(markNoShow).toBeDefined()
119
- expect(CRM_ACTION_ENTRIES['mark_no_show']).toBeUndefined()
120
- })
121
111
  })
122
112
 
123
113
  // ---------------------------------------------------------------------------
@@ -4,9 +4,8 @@ import {
4
4
  CRM_DISCOVERY_LINK_SENT_STATE,
5
5
  CRM_DISCOVERY_NUDGING_STATE,
6
6
  CRM_DISCOVERY_REPLIED_STATE
7
- } from '@repo/core/organization-model'
7
+ } from '../../organization-model/domains/sales'
8
8
  import { getDealOwnership, type DealOwnership } from './deal-ownership'
9
- import { getCrmActionMetadata } from './ontology-validation'
10
9
  import type { AcqDealRow } from './types'
11
10
 
12
11
  export interface Action {
@@ -34,21 +33,69 @@ export const SendReplyActionPayloadSchema = z
34
33
  })
35
34
  .strict()
36
35
 
37
- type CrmActionRuntimeDef = Pick<ActionDef, 'isAvailableFor' | 'payloadSchema'>
38
-
36
+ type CrmActionRuntimeDef = Pick<ActionDef, 'isAvailableFor' | 'payloadSchema'>
37
+
38
+ const CRM_RUNTIME_ACTION_METADATA: Record<string, Pick<ActionDef, 'key' | 'label' | 'workflowId'>> = {
39
+ move_to_proposal: {
40
+ key: 'move_to_proposal',
41
+ label: 'Move to Proposal',
42
+ workflowId: 'move_to_proposal-workflow'
43
+ },
44
+ move_to_closing: {
45
+ key: 'move_to_closing',
46
+ label: 'Move to Closing',
47
+ workflowId: 'move_to_closing-workflow'
48
+ },
49
+ move_to_closed_won: {
50
+ key: 'move_to_closed_won',
51
+ label: 'Close Won',
52
+ workflowId: 'move_to_closed_won-workflow'
53
+ },
54
+ move_to_closed_lost: {
55
+ key: 'move_to_closed_lost',
56
+ label: 'Close Lost',
57
+ workflowId: 'move_to_closed_lost-workflow'
58
+ },
59
+ move_to_nurturing: {
60
+ key: 'move_to_nurturing',
61
+ label: 'Move to Nurturing',
62
+ workflowId: 'move_to_nurturing-workflow'
63
+ },
64
+ send_reply: {
65
+ key: 'send_reply',
66
+ label: 'Send Reply',
67
+ workflowId: 'crm-send-reply-workflow'
68
+ },
69
+ send_link: {
70
+ key: 'send_link',
71
+ label: 'Send Booking Link',
72
+ workflowId: 'crm-send-booking-link-workflow'
73
+ },
74
+ send_nudge: {
75
+ key: 'send_nudge',
76
+ label: 'Send Nudge',
77
+ workflowId: 'crm-send-nudge-workflow'
78
+ },
79
+ rebook: {
80
+ key: 'rebook',
81
+ label: 'Rebook',
82
+ workflowId: 'crm-rebook-workflow'
83
+ }
84
+ }
85
+
39
86
  function crmAction(actionId: string, runtime: CrmActionRuntimeDef): ActionDef {
40
- const metadata = getCrmActionMetadata(actionId)
41
- if (!metadata?.resourceId) {
87
+ const metadata = CRM_RUNTIME_ACTION_METADATA[actionId]
88
+ if (!metadata?.workflowId) {
42
89
  throw new Error(`CRM action metadata for "${actionId}" must define resourceId`)
43
90
  }
44
-
45
- return {
46
- key: metadata.id,
47
- label: metadata.label,
48
- workflowId: metadata.resourceId,
49
- ...runtime
50
- }
51
- }
91
+
92
+ return {
93
+ key: metadata.key,
94
+ label: metadata.label,
95
+ workflowId: metadata.workflowId,
96
+ ...runtime
97
+ }
98
+ }
52
99
 
53
100
  export const DEFAULT_CRM_ACTIONS: ActionDef[] = [
54
101
  crmAction('move_to_proposal', {
@@ -11,10 +11,10 @@ import {
11
11
  import type { OrganizationModel } from '../../organization-model/types'
12
12
  import {
13
13
  CRM_PIPELINE_DEFINITION,
14
- LEAD_GEN_STAGE_CATALOG,
15
14
  type LeadGenStageCatalogEntry,
16
15
  type StatefulStateDefinition
17
16
  } from '../../organization-model/domains/sales'
17
+ import { getLeadGenStageCatalog } from '../../organization-model/migration-helpers'
18
18
 
19
19
  export const CRM_PIPELINE_CATALOG_ONTOLOGY_ID = formatOntologyId({
20
20
  scope: 'sales.crm',
@@ -73,14 +73,14 @@ function createCrmPipelineCatalog(): OntologyCatalogType {
73
73
  }
74
74
  }
75
75
 
76
- function createLeadGenStageCatalog(): OntologyCatalogType {
76
+ function createLeadGenStageCatalog(model: OrganizationModel): OntologyCatalogType {
77
77
  return {
78
78
  id: LEAD_GEN_STAGE_CATALOG_ONTOLOGY_ID,
79
79
  label: 'Lead Gen Processing Stages',
80
80
  ownerSystemId: 'sales.lead-gen',
81
81
  kind: 'processing-stage-catalog',
82
82
  entries: Object.fromEntries(
83
- Object.entries(LEAD_GEN_STAGE_CATALOG).map(([key, entry]) => [
83
+ Object.entries(getLeadGenStageCatalog(model)).map(([key, entry]) => [
84
84
  key,
85
85
  {
86
86
  ...entry
@@ -103,7 +103,7 @@ function mergeBridgeCatalogs(model: OrganizationModel): OrganizationModel {
103
103
  bridgeCatalogTypes[CRM_PIPELINE_CATALOG_ONTOLOGY_ID] = createCrmPipelineCatalog()
104
104
  }
105
105
  if (baseCatalogTypes[LEAD_GEN_STAGE_CATALOG_ONTOLOGY_ID] === undefined) {
106
- bridgeCatalogTypes[LEAD_GEN_STAGE_CATALOG_ONTOLOGY_ID] = createLeadGenStageCatalog()
106
+ bridgeCatalogTypes[LEAD_GEN_STAGE_CATALOG_ONTOLOGY_ID] = createLeadGenStageCatalog(model)
107
107
  }
108
108
 
109
109
  if (Object.keys(bridgeCatalogTypes).length === 0) return model
@@ -1,11 +1,10 @@
1
1
  import type { Database } from '../../supabase/database.types'
2
- import type {
3
- ActionRegistry,
4
- CredentialRequirement,
5
- RecordColumnConfig
6
- } from '../../organization-model/domains/prospecting'
7
- import type { LEAD_GEN_STAGE_CATALOG } from '../../organization-model/domains/sales'
8
- import type { PipelineStage, ProcessingStageStatus } from './api-schemas'
2
+ import type {
3
+ ActionRegistry,
4
+ CredentialRequirement,
5
+ RecordColumnConfig
6
+ } from '../../organization-model/domains/prospecting'
7
+ import type { PipelineStage, ProcessingStageStatus } from './api-schemas'
9
8
 
10
9
  // =============================================================================
11
10
  // Supabase-Generated Types (Re-exported from database.types)
@@ -55,7 +54,7 @@ export interface WebPost {
55
54
  aiInsight?: string
56
55
  }
57
56
 
58
- export type LeadGenStageKey = (typeof LEAD_GEN_STAGE_CATALOG)[keyof typeof LEAD_GEN_STAGE_CATALOG]['key']
57
+ export type LeadGenStageKey = string
59
58
  export type LeadGenActionKey = ActionRegistry[number]['id']
60
59
 
61
60
  export interface ProcessingStateEntry {
@@ -20,8 +20,8 @@ import { createLLMAdapter } from '../server/adapter-factory'
20
20
  import type { ModelConfig } from '../../model-info'
21
21
  import type { LLMGenerateRequest } from '../../types'
22
22
 
23
- // Skip if OPENROUTER_API_KEY not available
24
- const SKIP_TESTS = !process.env.OPENROUTER_API_KEY
23
+ // Skip by default: real OpenRouter model behavior can change independently of this repo.
24
+ const SKIP_TESTS = process.env.RUN_OPENROUTER_INTEGRATION !== 'true' || !process.env.OPENROUTER_API_KEY
25
25
 
26
26
  describe.skipIf(SKIP_TESTS)('OpenRouter Adapter Integration', () => {
27
27
  let apiKey: string
@@ -47,14 +47,14 @@ describe.skipIf(SKIP_TESTS)('OpenRouter Adapter Integration', () => {
47
47
  maxOutputTokens: 500
48
48
  })
49
49
 
50
- describe('Grok via OpenRouter', () => {
51
- it('generates structured output with accurate token counts', async () => {
52
- const config: ModelConfig = {
53
- provider: 'openrouter',
54
- model: 'openrouter/x-ai/grok-4.1-fast',
55
- apiKey,
56
- temperature: 0.7,
57
- maxOutputTokens: 500
50
+ describe('OpenRouter hosted model', () => {
51
+ it('generates structured output with accurate token counts', async () => {
52
+ const config: ModelConfig = {
53
+ provider: 'openrouter',
54
+ model: 'openrouter/z-ai/glm-5',
55
+ apiKey,
56
+ temperature: 0.7,
57
+ maxOutputTokens: 500
58
58
  }
59
59
 
60
60
  const adapter = createLLMAdapter(config)