@elevasis/sdk 1.55.0 → 1.57.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 (50) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +32 -0
  3. package/dist/{chunk-72ZGICTR.js → chunk-3XEHBMWM.js} +1 -1
  4. package/dist/{chunk-R3J6BEPO.js → chunk-HDMMMDIR.js} +225 -67
  5. package/dist/cli.cjs +209 -109
  6. package/dist/index.d.ts +82 -20
  7. package/dist/index.js +1 -1
  8. package/dist/node/index.d.ts +1 -8
  9. package/dist/node/index.js +3 -14
  10. package/dist/test-utils/index.js +2 -2
  11. package/dist/worker/index.js +2 -2
  12. package/package.json +2 -2
  13. package/reference/_navigation.md +4 -4
  14. package/reference/_reference-manifest.json +3 -3
  15. package/reference/index.mdx +1 -1
  16. package/reference/packages/ui/src/knowledge/README.md +32 -32
  17. package/reference/rules/agent-start-here.md +1 -1
  18. package/reference/rules/error-handling.md +50 -1
  19. package/reference/rules/execution.md +63 -7
  20. package/reference/rules/organization-model.md +3 -2
  21. package/reference/scaffold/recipes/customize-crm-actions.md +231 -223
  22. package/reference/scaffold/recipes/customize-organization-model.md +3 -1
  23. package/reference/scaffold/recipes/extend-crm.md +4 -2
  24. package/reference/scaffold/recipes/extend-lead-gen.md +2 -2
  25. package/reference/scaffold/recipes/index.md +2 -2
  26. package/reference/scaffold/reference/contracts.md +49 -12
  27. package/reference/scaffold/reference/system-interface-capabilities.md +4 -4
  28. package/reference/sdk/cli-management.mdx +0 -4
  29. package/reference/sdk/cli.mdx +0 -4
  30. package/reference/sdk/concepts.mdx +0 -4
  31. package/reference/sdk/deployment/command-center.mdx +0 -4
  32. package/reference/sdk/framework/agent.mdx +0 -4
  33. package/reference/sdk/framework/index.mdx +0 -4
  34. package/reference/sdk/framework/project-structure.mdx +1 -7
  35. package/reference/sdk/getting-started.mdx +0 -4
  36. package/reference/sdk/index.mdx +4 -8
  37. package/reference/sdk/platform-tools/index.mdx +0 -4
  38. package/reference/sdk/resources/index.mdx +0 -4
  39. package/reference/sdk/resources/patterns.mdx +0 -4
  40. package/reference/sdk/runtime.mdx +0 -4
  41. package/reference/sdk/templates/data-enrichment.mdx +0 -4
  42. package/reference/sdk/templates/email-sender.mdx +0 -4
  43. package/reference/sdk/templates/index.mdx +0 -4
  44. package/reference/sdk/templates/lead-scorer.mdx +0 -4
  45. package/reference/sdk/templates/pdf-generator.mdx +0 -4
  46. package/reference/sdk/templates/recurring-job.mdx +0 -4
  47. package/reference/sdk/templates/text-classifier.mdx +0 -4
  48. package/reference/sdk/templates/web-scraper.mdx +0 -4
  49. package/reference/sdk/troubleshooting.mdx +0 -4
  50. package/reference/ui/exports.mdx +1 -1
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Elevasis
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,32 @@
1
+ # @elevasis/sdk
2
+
3
+ SDK for building Elevasis organization resources — agents, workflows, and the CLI that deploys them.
4
+
5
+ ## Install
6
+
7
+ ```sh
8
+ pnpm add @elevasis/sdk
9
+ ```
10
+
11
+ ## Published surface
12
+
13
+ | Subpath | Contains |
14
+ | ---------------------------- | ------------------------------------------------------------------------- |
15
+ | `@elevasis/sdk` | Resource definitions, the registry, and its validators |
16
+ | `@elevasis/sdk/worker` | The worker-thread authoring surface: `Agent`, `Workflow`, collectors |
17
+ | `@elevasis/sdk/node` | Node-only helpers |
18
+ | `@elevasis/sdk/test-utils` | Test helpers for resource authors |
19
+
20
+ The package also installs an `elevasis-sdk` binary. Run `elevasis-sdk --help` for the command set;
21
+ every authenticated command accepts `--prod` to target production rather than a local API.
22
+
23
+ ## Relationship to `@elevasis/core`
24
+
25
+ The SDK inlines the `@repo/core` types it re-exports, so no `@elevasis/core` specifier survives in
26
+ the shipped declarations. That makes the SDK a second sanctioned route onto capabilities core does
27
+ not publish directly — import them from here rather than reaching for a core subpath that does not
28
+ resolve.
29
+
30
+ ## License
31
+
32
+ MIT — see [LICENSE](./LICENSE).
@@ -1,4 +1,4 @@
1
- import { ProcessingStageStatusSchema, ListBuilderStageKeySchema, LLMResponseParseError, errorToString, getErrorDetails, ExecutionError2, validateEntryPoint, validateTerminalSteps, validateStepReferences, WorkflowTimeoutError, WorkflowStalledError, WorkflowCancellationError, WorkflowStepTimeoutError, logWorkflowStart, detectCycle, WorkflowStepError, logStepStart, validateTerminalOutput, logStepSuccess, determineNextStep, logStepFailure, logExecutionPath, logWorkflowSuccess, logWorkflowFailure, estimateTokens, allSettledWithConcurrency, calculateCost, truncationCharBudget, buildIterationResponseSchema } from './chunk-R3J6BEPO.js';
1
+ import { ProcessingStageStatusSchema, ListBuilderStageKeySchema, LLMResponseParseError, errorToString, getErrorDetails, ExecutionError2, validateEntryPoint, validateTerminalSteps, validateStepReferences, WorkflowTimeoutError, WorkflowStalledError, WorkflowCancellationError, WorkflowStepTimeoutError, logWorkflowStart, detectCycle, WorkflowStepError, logStepStart, validateTerminalOutput, logStepSuccess, determineNextStep, logStepFailure, logExecutionPath, logWorkflowSuccess, logWorkflowFailure, estimateTokens, allSettledWithConcurrency, calculateCost, truncationCharBudget, buildIterationResponseSchema } from './chunk-HDMMMDIR.js';
2
2
  import { workerData, parentPort } from 'worker_threads';
3
3
  import { zodToJsonSchema } from '@alcyone-labs/zod-to-json-schema';
4
4
  import { z, ZodError } from 'zod';
@@ -85,8 +85,18 @@ var OntologyLinkTypeSchema = OntologyRecordBaseSchema.extend({
85
85
  cardinality: z.string().trim().min(1).max(80).optional(),
86
86
  via: z.string().trim().min(1).max(255).optional()
87
87
  }).strict();
88
+ var OntologyActionAvailabilityConditionSchema = z.object({
89
+ stageKeys: z.array(z.string().trim().min(1).max(200)).min(1),
90
+ stateKeys: z.array(z.string().trim().min(1).max(200)).optional(),
91
+ nextActionKeys: z.array(z.string().trim().min(1).max(200)).optional()
92
+ }).strict();
88
93
  var OntologyActionTypeSchema = OntologyRecordBaseSchema.extend({
89
94
  actsOn: OntologyReferenceListSchema,
95
+ // Presentation order for surfaces that list actions (the CRM deal action
96
+ // bar). Same meaning as the legacy `ActionSchema.order` it replaces; without
97
+ // it a compiled catalog falls back to the index's alphabetical id sort,
98
+ // which silently reorders the buttons.
99
+ order: z.number().optional(),
90
100
  input: z.record(z.string().trim().min(1).max(200), z.unknown()).optional(),
91
101
  effects: z.array(z.record(z.string(), z.unknown())).optional(),
92
102
  resourceId: z.string().trim().min(1).optional(),
@@ -94,7 +104,14 @@ var OntologyActionTypeSchema = OntologyRecordBaseSchema.extend({
94
104
  lifecycle: z.string().trim().min(1).optional(),
95
105
  // Carried by the legacy action projection (`addLegacyActionProjections`); not
96
106
  // authored directly, but a real key an authored record must not collide with.
97
- legacyActionId: z.string().trim().min(1).optional()
107
+ legacyActionId: z.string().trim().min(1).optional(),
108
+ // Lets a tenant author which deal stage/state/next-action combination makes
109
+ // this action selectable, instead of hardcoding the predicate in TypeScript.
110
+ // `compileCrmActionCatalog` reads it; paired with `resourceId` above,
111
+ // `resourceId` says what to dispatch and `availableFrom` says when.
112
+ // Absent entirely for action records that are not deal actions — the
113
+ // compiler skips those rather than erroring.
114
+ availableFrom: OntologyActionAvailabilityConditionSchema.optional()
98
115
  }).strict();
99
116
  var OntologyCatalogTypeSchema = OntologyRecordBaseSchema.extend({
100
117
  kind: z.string().trim().min(1).max(120).optional(),
@@ -679,6 +696,18 @@ var SYSTEM_INTERFACE_PROFILES = [
679
696
  SYSTEM_INTERFACE_PROFILES.map(
680
697
  (profile) => profile.readinessProfile
681
698
  );
699
+ function requireSystemInterfaceProfile(readinessProfile) {
700
+ const profile = SYSTEM_INTERFACE_PROFILES.find(
701
+ (candidate) => candidate.readinessProfile === readinessProfile
702
+ );
703
+ if (profile === void 0) {
704
+ throw new Error(
705
+ `"${readinessProfile}" is not a member of SYSTEM_INTERFACE_PROFILES. Adoptable ids: ${SYSTEM_INTERFACE_PROFILES.map((candidate) => `"${candidate.readinessProfile}"`).join(", ")}.`
706
+ );
707
+ }
708
+ return profile;
709
+ }
710
+ requireSystemInterfaceProfile("content.api");
682
711
  var BUILT_IN_VALIDATED_PROFILE_IDS = SYSTEM_INTERFACE_PROFILES.filter(
683
712
  (profile) => profile.validation === "built-in"
684
713
  ).map((profile) => profile.readinessProfile);
@@ -1236,6 +1265,64 @@ function getLeadGenStageCatalog(model) {
1236
1265
  Object.entries(results).sort(([, a], [, b]) => a.order - b.order || a.key.localeCompare(b.key))
1237
1266
  );
1238
1267
  }
1268
+
1269
+ // ../core/src/organization-model/catalogs/define-system-api-interface.ts
1270
+ var LEAD_GEN_LIST_OBJECT_ONTOLOGY_ID = formatOntologyId({
1271
+ scope: "sales.lead-gen",
1272
+ kind: "object",
1273
+ localId: "list"
1274
+ });
1275
+ var LEAD_GEN_COMPANY_OBJECT_ONTOLOGY_ID = formatOntologyId({
1276
+ scope: "sales.lead-gen",
1277
+ kind: "object",
1278
+ localId: "company"
1279
+ });
1280
+ var LEAD_GEN_CONTACT_OBJECT_ONTOLOGY_ID = formatOntologyId({
1281
+ scope: "sales.lead-gen",
1282
+ kind: "object",
1283
+ localId: "contact"
1284
+ });
1285
+ var LEAD_GEN_BUILD_TEMPLATE_CATALOG_ONTOLOGY_ID = formatOntologyId({
1286
+ scope: "sales.lead-gen",
1287
+ kind: "catalog",
1288
+ localId: "build-template"
1289
+ });
1290
+ var LEAD_GEN_COMPANY_STAGE_CATALOG_ONTOLOGY_ID = formatOntologyId({
1291
+ scope: "sales.lead-gen",
1292
+ kind: "catalog",
1293
+ localId: "company-stage"
1294
+ });
1295
+ var LEAD_GEN_CONTACT_STAGE_CATALOG_ONTOLOGY_ID = formatOntologyId({
1296
+ scope: "sales.lead-gen",
1297
+ kind: "catalog",
1298
+ localId: "contact-stage"
1299
+ });
1300
+ var CRM_PIPELINE_CATALOG_ONTOLOGY_ID = formatOntologyId({
1301
+ scope: "sales.crm",
1302
+ kind: "catalog",
1303
+ localId: "crm.pipeline"
1304
+ });
1305
+ var LEAD_GEN_STAGE_CATALOG_ONTOLOGY_ID = formatOntologyId({
1306
+ scope: "sales.lead-gen",
1307
+ kind: "catalog",
1308
+ localId: "lead-gen.stage-catalog"
1309
+ });
1310
+ var LEAD_GEN_API_READINESS_CONTRACT = {
1311
+ requiredObjects: [
1312
+ LEAD_GEN_LIST_OBJECT_ONTOLOGY_ID,
1313
+ LEAD_GEN_COMPANY_OBJECT_ONTOLOGY_ID,
1314
+ LEAD_GEN_CONTACT_OBJECT_ONTOLOGY_ID
1315
+ ],
1316
+ requiredCatalogs: [
1317
+ LEAD_GEN_BUILD_TEMPLATE_CATALOG_ONTOLOGY_ID,
1318
+ LEAD_GEN_COMPANY_STAGE_CATALOG_ONTOLOGY_ID,
1319
+ LEAD_GEN_CONTACT_STAGE_CATALOG_ONTOLOGY_ID
1320
+ ]
1321
+ };
1322
+ var CRM_API_READINESS_CONTRACT = {
1323
+ requiredObjects: [],
1324
+ requiredCatalogs: [CRM_PIPELINE_CATALOG_ONTOLOGY_ID]
1325
+ };
1239
1326
  DisplayMetadataSchema.extend({
1240
1327
  id: ModelIdSchema,
1241
1328
  order: z.number().min(0)
@@ -5681,76 +5768,36 @@ var ActivityEventSchema = z.discriminatedUnion("type", [
5681
5768
  DealCreatedEventSchema,
5682
5769
  ActionFailedEventSchema
5683
5770
  ]);
5684
- z.object({
5771
+ var SendReplyActionPayloadSchema = z.object({
5685
5772
  replyBody: z.string().trim().min(1).max(1e4)
5686
5773
  }).strict();
5687
- function deriveActions(deal, actions = []) {
5688
- return actions.filter((a) => a.isAvailableFor(deal)).map(({ key, label, payloadSchema }) => ({ key, label, payloadSchema }));
5774
+ var CRM_ACTION_PAYLOAD_SCHEMAS = {
5775
+ send_reply: SendReplyActionPayloadSchema
5776
+ };
5777
+ function resolveCrmActionPayloadSchema(actionKey) {
5778
+ return Object.hasOwn(CRM_ACTION_PAYLOAD_SCHEMAS, actionKey) ? CRM_ACTION_PAYLOAD_SCHEMAS[actionKey] : void 0;
5779
+ }
5780
+ function getDealNextActionKey(deal) {
5781
+ return "nextAction" in deal && typeof deal.nextAction === "string" ? deal.nextAction : null;
5782
+ }
5783
+ function isCompiledCrmActionAvailable(deal, action) {
5784
+ const { stageKeys, stateKeys, nextActionKeys } = action.availableFrom;
5785
+ if (deal.stage_key === null || !stageKeys.includes(deal.stage_key)) return false;
5786
+ if (stateKeys !== void 0 && (deal.state_key === null || !stateKeys.includes(deal.state_key))) return false;
5787
+ if (nextActionKeys !== void 0) {
5788
+ const nextAction = getDealNextActionKey(deal);
5789
+ if (nextAction === null || !nextActionKeys.includes(nextAction)) return false;
5790
+ }
5791
+ return true;
5689
5792
  }
5690
5793
 
5691
5794
  // ../core/src/business/acquisition/ontology-validation.ts
5692
- var LEAD_GEN_API_INTERFACE = SYSTEM_INTERFACE_PROFILES[0];
5693
- var CRM_API_INTERFACE = SYSTEM_INTERFACE_PROFILES[1];
5694
- var LEAD_GEN_CRM_HANDOFF_INTERFACE = SYSTEM_INTERFACE_PROFILES[2];
5795
+ var LEAD_GEN_API_INTERFACE = requireSystemInterfaceProfile("sales.lead-gen.api");
5796
+ var CRM_API_INTERFACE = requireSystemInterfaceProfile("sales.crm.api");
5797
+ var LEAD_GEN_CRM_HANDOFF_INTERFACE = requireSystemInterfaceProfile("sales.lead-gen.crm-handoff");
5695
5798
  LEAD_GEN_API_INTERFACE.readinessProfile;
5696
- CRM_API_INTERFACE.readinessProfile;
5799
+ var CRM_API_READINESS_LABEL = CRM_API_INTERFACE.readinessProfile;
5697
5800
  LEAD_GEN_CRM_HANDOFF_INTERFACE.readinessProfile;
5698
- var LEAD_GEN_LIST_OBJECT_ONTOLOGY_ID = formatOntologyId({
5699
- scope: "sales.lead-gen",
5700
- kind: "object",
5701
- localId: "list"
5702
- });
5703
- var LEAD_GEN_COMPANY_OBJECT_ONTOLOGY_ID = formatOntologyId({
5704
- scope: "sales.lead-gen",
5705
- kind: "object",
5706
- localId: "company"
5707
- });
5708
- var LEAD_GEN_CONTACT_OBJECT_ONTOLOGY_ID = formatOntologyId({
5709
- scope: "sales.lead-gen",
5710
- kind: "object",
5711
- localId: "contact"
5712
- });
5713
- var LEAD_GEN_BUILD_TEMPLATE_CATALOG_ONTOLOGY_ID = formatOntologyId({
5714
- scope: "sales.lead-gen",
5715
- kind: "catalog",
5716
- localId: "build-template"
5717
- });
5718
- var LEAD_GEN_COMPANY_STAGE_CATALOG_ONTOLOGY_ID = formatOntologyId({
5719
- scope: "sales.lead-gen",
5720
- kind: "catalog",
5721
- localId: "company-stage"
5722
- });
5723
- var LEAD_GEN_CONTACT_STAGE_CATALOG_ONTOLOGY_ID = formatOntologyId({
5724
- scope: "sales.lead-gen",
5725
- kind: "catalog",
5726
- localId: "contact-stage"
5727
- });
5728
- var CRM_PIPELINE_CATALOG_ONTOLOGY_ID = formatOntologyId({
5729
- scope: "sales.crm",
5730
- kind: "catalog",
5731
- localId: "crm.pipeline"
5732
- });
5733
- var LEAD_GEN_STAGE_CATALOG_ONTOLOGY_ID = formatOntologyId({
5734
- scope: "sales.lead-gen",
5735
- kind: "catalog",
5736
- localId: "lead-gen.stage-catalog"
5737
- });
5738
- var LEAD_GEN_API_READINESS_CONTRACT = {
5739
- requiredObjects: [
5740
- LEAD_GEN_LIST_OBJECT_ONTOLOGY_ID,
5741
- LEAD_GEN_COMPANY_OBJECT_ONTOLOGY_ID,
5742
- LEAD_GEN_CONTACT_OBJECT_ONTOLOGY_ID
5743
- ],
5744
- requiredCatalogs: [
5745
- LEAD_GEN_BUILD_TEMPLATE_CATALOG_ONTOLOGY_ID,
5746
- LEAD_GEN_COMPANY_STAGE_CATALOG_ONTOLOGY_ID,
5747
- LEAD_GEN_CONTACT_STAGE_CATALOG_ONTOLOGY_ID
5748
- ]
5749
- };
5750
- var CRM_API_READINESS_CONTRACT = {
5751
- requiredObjects: [],
5752
- requiredCatalogs: [CRM_PIPELINE_CATALOG_ONTOLOGY_ID]
5753
- };
5754
5801
  function isPlainRecord2(value) {
5755
5802
  return Boolean(value) && typeof value === "object" && !Array.isArray(value);
5756
5803
  }
@@ -5856,7 +5903,7 @@ function mergeLeadGenDerivedCatalogs(model) {
5856
5903
  };
5857
5904
  }
5858
5905
  function compileBusinessOntology(model, contractId, includeLeadGenDerivedCatalogs) {
5859
- const preparedModel = mergeLeadGenDerivedCatalogs(model) ;
5906
+ const preparedModel = includeLeadGenDerivedCatalogs ? mergeLeadGenDerivedCatalogs(model) : model;
5860
5907
  const compilation = compileOrganizationOntology(preparedModel);
5861
5908
  if (compilation.diagnostics.length > 0) {
5862
5909
  const summary = compilation.diagnostics.map((diagnostic) => diagnostic.message).join("; ");
@@ -5908,10 +5955,18 @@ function requireReadyCatalog(index, catalogId, readinessLabel) {
5908
5955
  }
5909
5956
  return catalog;
5910
5957
  }
5958
+ function compileCrmApiOntologyValidationIndex(model) {
5959
+ throwIfInterfaceNotReady(computeInterfaceReadiness(model, CRM_API_INTERFACE));
5960
+ const index = compileBusinessOntology(model, CRM_API_READINESS_LABEL, false);
5961
+ return {
5962
+ ...index,
5963
+ crmPipelineCatalog: requireReadyCatalog(index, CRM_PIPELINE_CATALOG_ONTOLOGY_ID, CRM_API_READINESS_LABEL)
5964
+ };
5965
+ }
5911
5966
  function compileBusinessOntologyValidationIndex(model) {
5912
5967
  throwIfInterfaceNotReady(computeInterfaceReadiness(model, LEAD_GEN_API_INTERFACE));
5913
5968
  throwIfInterfaceNotReady(computeInterfaceReadiness(model, CRM_API_INTERFACE));
5914
- const index = compileBusinessOntology(model, "legacy acquisition business ontology");
5969
+ const index = compileBusinessOntology(model, "legacy acquisition business ontology", true);
5915
5970
  return {
5916
5971
  ...index,
5917
5972
  leadGenStageCatalog: requireReadyCatalog(
@@ -5939,6 +5994,15 @@ function indexActionTypesByLegacyId(actionTypes) {
5939
5994
  function getCatalogEntries2(catalog) {
5940
5995
  return isPlainRecord2(catalog.entries) ? catalog.entries : {};
5941
5996
  }
5997
+ function asStatefulStateDefinition(value) {
5998
+ if (!isPlainRecord2(value) || typeof value.stateKey !== "string" || typeof value.label !== "string") {
5999
+ return void 0;
6000
+ }
6001
+ return {
6002
+ stateKey: value.stateKey,
6003
+ label: value.label
6004
+ };
6005
+ }
5942
6006
  function asLeadGenStageEntry(key, value) {
5943
6007
  const record = isPlainRecord2(value) ? value : {};
5944
6008
  const entity = record.entity === "contact" ? "contact" : "company";
@@ -5958,6 +6022,14 @@ function asLeadGenStageEntry(key, value) {
5958
6022
  ...recordStageKey !== void 0 ? { recordStageKey } : {}
5959
6023
  };
5960
6024
  }
6025
+ function getCrmStatesForStage(index, stageKey) {
6026
+ const stage = getCatalogEntries2(index.crmPipelineCatalog)[stageKey];
6027
+ const states = isPlainRecord2(stage) && Array.isArray(stage.states) ? stage.states : [];
6028
+ return states.flatMap((state) => {
6029
+ const parsed = asStatefulStateDefinition(state);
6030
+ return parsed ? [parsed] : [];
6031
+ });
6032
+ }
5961
6033
  function createLeadGenStageValidators(index) {
5962
6034
  const getCatalog = () => Object.fromEntries(
5963
6035
  Object.entries(getCatalogEntries2(index.leadGenStageCatalog)).map(([key, value]) => [
@@ -5985,6 +6057,92 @@ function createLeadGenStageValidators(index) {
5985
6057
  };
5986
6058
  }
5987
6059
 
6060
+ // ../core/src/business/acquisition/compile-action-catalog.ts
6061
+ function isCrmOwnedActionTypeId(id) {
6062
+ return parseOntologyId(id).scope === CRM_API_INTERFACE.systemPath;
6063
+ }
6064
+ function compileCrmActionCatalog(index) {
6065
+ const issues = [];
6066
+ const compiled = [];
6067
+ const stageKeysInCatalog = new Set(Object.keys(index.crmPipelineCatalog.entries ?? {}));
6068
+ for (const [id, actionType] of Object.entries(index.ontology.actionTypes)) {
6069
+ if (!isCrmOwnedActionTypeId(id)) continue;
6070
+ const availableFrom = actionType.availableFrom;
6071
+ if (availableFrom === void 0) continue;
6072
+ const key = parseOntologyId(id).localId;
6073
+ for (const stageKey of availableFrom.stageKeys) {
6074
+ if (!stageKeysInCatalog.has(stageKey)) {
6075
+ addReadinessIssue(
6076
+ issues,
6077
+ "SYSTEM_INTERFACE_INVALID",
6078
+ "crm-action-unknown-stage-key",
6079
+ `CRM action "${id}" declares availableFrom.stageKeys entry "${stageKey}", which is not a member of the CRM pipeline catalog.`,
6080
+ { ref: id }
6081
+ );
6082
+ }
6083
+ }
6084
+ if (availableFrom.stateKeys !== void 0) {
6085
+ const validStateKeys = new Set(
6086
+ availableFrom.stageKeys.flatMap(
6087
+ (stageKey) => getCrmStatesForStage(index, stageKey).map((state) => state.stateKey)
6088
+ )
6089
+ );
6090
+ for (const stateKey of availableFrom.stateKeys) {
6091
+ if (!validStateKeys.has(stateKey)) {
6092
+ addReadinessIssue(
6093
+ issues,
6094
+ "SYSTEM_INTERFACE_INVALID",
6095
+ "crm-action-unknown-state-key",
6096
+ `CRM action "${id}" declares availableFrom.stateKeys entry "${stateKey}", which is not a valid state for any of its declared stageKeys.`,
6097
+ { ref: id }
6098
+ );
6099
+ }
6100
+ }
6101
+ }
6102
+ if (actionType.resourceId === void 0 || actionType.resourceId.trim().length === 0) {
6103
+ addReadinessIssue(
6104
+ issues,
6105
+ "SYSTEM_INTERFACE_INVALID",
6106
+ "crm-action-missing-resource-id",
6107
+ `CRM action "${id}" declares availableFrom but no resourceId to dispatch to.`,
6108
+ { ref: id }
6109
+ );
6110
+ continue;
6111
+ }
6112
+ const payloadSchema = resolveCrmActionPayloadSchema(key);
6113
+ compiled.push({
6114
+ // Authored `order` places the action in the deal action bar. Records
6115
+ // without one sort after every ordered record, in id order.
6116
+ order: actionType.order ?? Number.MAX_SAFE_INTEGER,
6117
+ action: {
6118
+ key,
6119
+ label: actionType.label ?? key,
6120
+ availableFrom: {
6121
+ stageKeys: availableFrom.stageKeys,
6122
+ ...availableFrom.stateKeys !== void 0 ? { stateKeys: availableFrom.stateKeys } : {},
6123
+ ...availableFrom.nextActionKeys !== void 0 ? { nextActionKeys: availableFrom.nextActionKeys } : {}
6124
+ },
6125
+ resourceId: actionType.resourceId,
6126
+ ...payloadSchema !== void 0 ? { payloadSchema } : {}
6127
+ }
6128
+ });
6129
+ }
6130
+ if (issues.length > 0) {
6131
+ throw new SystemInterfaceReadinessError({
6132
+ ready: false,
6133
+ systemPath: CRM_API_INTERFACE.systemPath,
6134
+ interfaceKey: CRM_API_INTERFACE.interfaceKey,
6135
+ readinessProfile: CRM_API_INTERFACE.readinessProfile,
6136
+ scopedResourceIds: [],
6137
+ issues
6138
+ });
6139
+ }
6140
+ return compiled.sort((a, b) => a.order - b.order).map((entry) => entry.action);
6141
+ }
6142
+ function deriveCompiledCrmActions(deal, catalog) {
6143
+ return catalog.filter((action) => isCompiledCrmActionAvailable(deal, action));
6144
+ }
6145
+
5988
6146
  // src/workflow-config.ts
5989
6147
  function defineWorkflowConfig(resourceId, descriptors, actionRegistry = []) {
5990
6148
  const descriptor = descriptors[resourceId];
@@ -6011,4 +6169,4 @@ function defineWorkflowConfig(resourceId, descriptors, actionRegistry = []) {
6011
6169
  }
6012
6170
  var ListBuilderStageKeySchema = z.string().min(1);
6013
6171
 
6014
- export { ActivityEventSchema, BuildPlanSnapshotStepSchema, ContractRefResolutionError, CrmStageKeySchema, CrmStateKeySchema, EmailSchema, ExecutionError, ExecutionError2, LLMResponseParseError, ListBuilderStageKeySchema, ProcessingStageStatusSchema, ProspectingBuildTemplateSchema, RegistryValidationError, ResourceRegistry, StepType, ToolingError, WorkflowCancellationError, WorkflowStalledError, WorkflowStepError, WorkflowStepTimeoutError, WorkflowTimeoutError, allSettledWithConcurrency, bindResourceDescriptor, buildIterationResponseSchema, calculateCost, compileBusinessOntologyValidationIndex, concurrentPool, createLeadGenStageValidators, defineContract, defineResource, defineResourceOntology, defineResources, defineSingleStepWorkflow, defineTopology, defineTopologyRelationship, defineWorkflowConfig, deriveActions, detectCycle, determineNextStep, diagnosticOutput, errorToString, estimateTokens, getErrorDetails, integrationInput, isBuiltInReadinessProfile, isZodType, logExecutionPath, logStepFailure, logStepStart, logStepSuccess, logWorkflowFailure, logWorkflowStart, logWorkflowSuccess, lookupReadinessProfile, parseTopologyNodeRef, registerReadinessProfile, resolveContractRef, runDiagnostic, splitName, topologyRef, topologyRelationship, truncationCharBudget, validateDeclaredSystemInterfaceReadiness, validateDeploymentSpec, validateEntryPoint, validateRelationships, validateResourceGovernance, validateStepReferences, validateTerminalOutput, validateTerminalSteps };
6172
+ export { ActivityEventSchema, BuildPlanSnapshotStepSchema, ContractRefResolutionError, CrmStageKeySchema, CrmStateKeySchema, EmailSchema, ExecutionError, ExecutionError2, LLMResponseParseError, ListBuilderStageKeySchema, ProcessingStageStatusSchema, ProspectingBuildTemplateSchema, RegistryValidationError, ResourceRegistry, StepType, ToolingError, WorkflowCancellationError, WorkflowStalledError, WorkflowStepError, WorkflowStepTimeoutError, WorkflowTimeoutError, allSettledWithConcurrency, bindResourceDescriptor, buildIterationResponseSchema, calculateCost, compileBusinessOntologyValidationIndex, compileCrmActionCatalog, compileCrmApiOntologyValidationIndex, concurrentPool, createLeadGenStageValidators, defineContract, defineResource, defineResourceOntology, defineResources, defineSingleStepWorkflow, defineTopology, defineTopologyRelationship, defineWorkflowConfig, deriveCompiledCrmActions, detectCycle, determineNextStep, diagnosticOutput, errorToString, estimateTokens, getErrorDetails, integrationInput, isBuiltInReadinessProfile, isCompiledCrmActionAvailable, isZodType, logExecutionPath, logStepFailure, logStepStart, logStepSuccess, logWorkflowFailure, logWorkflowStart, logWorkflowSuccess, lookupReadinessProfile, parseTopologyNodeRef, registerReadinessProfile, resolveContractRef, runDiagnostic, splitName, topologyRef, topologyRelationship, truncationCharBudget, validateDeclaredSystemInterfaceReadiness, validateDeploymentSpec, validateEntryPoint, validateRelationships, validateResourceGovernance, validateStepReferences, validateTerminalOutput, validateTerminalSteps };