@elevasis/core 0.21.0 → 0.22.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 (59) hide show
  1. package/dist/index.d.ts +416 -6
  2. package/dist/index.js +240 -15
  3. package/dist/knowledge/index.d.ts +97 -1
  4. package/dist/organization-model/index.d.ts +416 -6
  5. package/dist/organization-model/index.js +240 -15
  6. package/dist/test-utils/index.d.ts +216 -1
  7. package/dist/test-utils/index.js +230 -14
  8. package/package.json +3 -3
  9. package/src/_gen/__tests__/__snapshots__/contracts.md.snap +495 -302
  10. package/src/auth/multi-tenancy/permissions.ts +20 -8
  11. package/src/business/README.md +2 -2
  12. package/src/business/acquisition/api-schemas.test.ts +173 -0
  13. package/src/business/acquisition/api-schemas.ts +125 -7
  14. package/src/business/acquisition/index.ts +12 -0
  15. package/src/business/clients/api-schemas.test.ts +115 -0
  16. package/src/business/clients/api-schemas.ts +158 -0
  17. package/src/business/clients/index.ts +1 -0
  18. package/src/business/deals/api-schemas.ts +8 -0
  19. package/src/business/index.ts +5 -2
  20. package/src/business/projects/types.ts +19 -0
  21. package/src/execution/engine/__tests__/fixtures/test-agents.ts +10 -8
  22. package/src/execution/engine/agent/core/__tests__/agent.test.ts +16 -12
  23. package/src/execution/engine/agent/core/__tests__/error-passthrough.test.ts +4 -3
  24. package/src/execution/engine/agent/core/types.ts +25 -15
  25. package/src/execution/engine/agent/index.ts +6 -4
  26. package/src/execution/engine/agent/reasoning/__tests__/request-builder.test.ts +24 -18
  27. package/src/execution/engine/index.ts +3 -0
  28. package/src/execution/engine/workflow/types.ts +7 -0
  29. package/src/organization-model/README.md +10 -3
  30. package/src/organization-model/__tests__/defaults.test.ts +6 -0
  31. package/src/organization-model/__tests__/domains/resources.test.ts +188 -0
  32. package/src/organization-model/__tests__/domains/roles.test.ts +402 -347
  33. package/src/organization-model/__tests__/domains/systems.test.ts +193 -0
  34. package/src/organization-model/__tests__/knowledge.test.ts +39 -0
  35. package/src/organization-model/__tests__/resolve.test.ts +1 -1
  36. package/src/organization-model/defaults.ts +24 -3
  37. package/src/organization-model/domains/knowledge.ts +3 -2
  38. package/src/organization-model/domains/resources.ts +88 -0
  39. package/src/organization-model/domains/roles.ts +93 -55
  40. package/src/organization-model/domains/systems.ts +46 -0
  41. package/src/organization-model/icons.ts +1 -0
  42. package/src/organization-model/index.ts +2 -0
  43. package/src/organization-model/organization-model.mdx +33 -14
  44. package/src/organization-model/published.ts +52 -1
  45. package/src/organization-model/schema.ts +121 -0
  46. package/src/organization-model/types.ts +46 -1
  47. package/src/platform/api/types.ts +38 -35
  48. package/src/platform/registry/__tests__/resource-registry.test.ts +2051 -2005
  49. package/src/platform/registry/__tests__/validation.test.ts +1343 -1086
  50. package/src/platform/registry/index.ts +14 -0
  51. package/src/platform/registry/resource-registry.ts +40 -2
  52. package/src/platform/registry/serialization.ts +241 -202
  53. package/src/platform/registry/serialized-types.ts +1 -0
  54. package/src/platform/registry/types.ts +411 -361
  55. package/src/platform/registry/validation.ts +743 -513
  56. package/src/projects/api-schemas.ts +290 -267
  57. package/src/reference/_generated/contracts.md +495 -302
  58. package/src/reference/glossary.md +8 -3
  59. package/src/supabase/database.types.ts +121 -0
@@ -19434,6 +19434,7 @@ var ORGANIZATION_MODEL_ICON_TOKENS = [
19434
19434
  "knowledge.reference",
19435
19435
  "feature.dashboard",
19436
19436
  "feature.calendar",
19437
+ "feature.business",
19437
19438
  "feature.sales",
19438
19439
  "feature.crm",
19439
19440
  "feature.finance",
@@ -20366,13 +20367,104 @@ var OfferingsDomainSchema = z.object({
20366
20367
  var DEFAULT_ORGANIZATION_MODEL_OFFERINGS = {
20367
20368
  products: []
20368
20369
  };
20370
+ var SystemKindSchema = z.enum(["product", "operational", "platform", "diagnostic"]);
20371
+ var SystemStatusSchema = z.enum(["active", "deprecated", "archived"]);
20372
+ var SystemIdSchema = ModelIdSchema;
20373
+ var SystemEntrySchema = z.object({
20374
+ /** Stable tenant-defined system id (e.g. "sys.lead-gen"). */
20375
+ id: SystemIdSchema,
20376
+ /** Human-readable system title shown in governance and operations UI. */
20377
+ title: LabelSchema,
20378
+ /** One-paragraph purpose statement for the bounded context. */
20379
+ description: DescriptionSchema,
20380
+ /** Closed system shape enum; catalog values remain tenant-defined. */
20381
+ kind: SystemKindSchema,
20382
+ /** Optional role responsible for this system. */
20383
+ responsibleRoleId: ModelIdSchema.optional(),
20384
+ /** Optional knowledge nodes that govern this system. */
20385
+ governedByKnowledge: ReferenceIdsSchema,
20386
+ /** Optional goals this system contributes to. */
20387
+ drivesGoals: ReferenceIdsSchema,
20388
+ status: SystemStatusSchema
20389
+ });
20390
+ var SystemsDomainSchema = z.object({
20391
+ systems: z.array(SystemEntrySchema).default([])
20392
+ });
20393
+ var DEFAULT_ORGANIZATION_MODEL_SYSTEMS = {
20394
+ systems: []
20395
+ };
20396
+
20397
+ // src/organization-model/domains/resources.ts
20398
+ z.enum(["workflow", "agent", "integration"]);
20399
+ var ResourceGovernanceStatusSchema = z.enum(["active", "deprecated", "archived"]);
20400
+ var AgentKindSchema = z.enum(["orchestrator", "specialist", "utility", "system"]);
20401
+ 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");
20402
+ var ResourceEntryBaseSchema = z.object({
20403
+ /** Canonical resource id; runtime resourceId derives from this value. */
20404
+ id: ResourceIdSchema,
20405
+ /** Required single System membership. */
20406
+ systemId: SystemIdSchema,
20407
+ /** Optional role responsible for maintaining this resource. */
20408
+ ownerRoleId: ModelIdSchema.optional(),
20409
+ status: ResourceGovernanceStatusSchema
20410
+ });
20411
+ var WorkflowResourceEntrySchema = ResourceEntryBaseSchema.extend({
20412
+ kind: z.literal("workflow"),
20413
+ /** Mirrors WorkflowConfig.capabilityKey when the runtime workflow has one. */
20414
+ capabilityKey: z.string().trim().min(1).max(255).optional()
20415
+ });
20416
+ var AgentResourceEntrySchema = ResourceEntryBaseSchema.extend({
20417
+ kind: z.literal("agent"),
20418
+ /** Mirrors code-side AgentConfig.kind. */
20419
+ agentKind: AgentKindSchema,
20420
+ /** Role this agent embodies, if any. */
20421
+ actsAsRoleId: ModelIdSchema.optional(),
20422
+ /** Mirrors AgentConfig.sessionCapable. */
20423
+ sessionCapable: z.boolean()
20424
+ });
20425
+ var IntegrationResourceEntrySchema = ResourceEntryBaseSchema.extend({
20426
+ kind: z.literal("integration"),
20427
+ provider: z.string().trim().min(1).max(100)
20428
+ });
20429
+ var ResourceEntrySchema = z.discriminatedUnion("kind", [
20430
+ WorkflowResourceEntrySchema,
20431
+ AgentResourceEntrySchema,
20432
+ IntegrationResourceEntrySchema
20433
+ ]);
20434
+ var ResourcesDomainSchema = z.object({
20435
+ entries: z.array(ResourceEntrySchema).default([])
20436
+ });
20437
+ var DEFAULT_ORGANIZATION_MODEL_RESOURCES = {
20438
+ entries: []
20439
+ };
20440
+
20441
+ // src/organization-model/domains/roles.ts
20442
+ var RoleIdSchema = ModelIdSchema;
20443
+ var HumanRoleHolderSchema = z.object({
20444
+ kind: z.literal("human"),
20445
+ userId: z.string().trim().min(1).max(200)
20446
+ });
20447
+ var AgentRoleHolderSchema = z.object({
20448
+ kind: z.literal("agent"),
20449
+ agentId: ResourceIdSchema
20450
+ });
20451
+ var TeamRoleHolderSchema = z.object({
20452
+ kind: z.literal("team"),
20453
+ memberIds: z.array(z.string().trim().min(1).max(200)).min(1)
20454
+ });
20455
+ var RoleHolderSchema = z.discriminatedUnion("kind", [
20456
+ HumanRoleHolderSchema,
20457
+ AgentRoleHolderSchema,
20458
+ TeamRoleHolderSchema
20459
+ ]);
20460
+ var RoleHoldersSchema = z.union([RoleHolderSchema, z.array(RoleHolderSchema).min(1)]);
20369
20461
  var RoleSchema = z.object({
20370
20462
  /** Stable unique identifier for the role (e.g. "role-ceo", "role-head-of-sales"). */
20371
- id: z.string().trim().min(1).max(100),
20463
+ id: RoleIdSchema,
20372
20464
  /** Human-readable title shown to agents and in UI (e.g. "CEO", "Head of Sales"). */
20373
20465
  title: z.string().trim().min(1).max(200),
20374
20466
  /**
20375
- * List of responsibilities this role owns plain-language descriptions of
20467
+ * List of responsibilities this role owns - plain-language descriptions of
20376
20468
  * what the person in this role is accountable for delivering.
20377
20469
  * Defaults to empty array so minimal role definitions stay concise.
20378
20470
  */
@@ -20380,16 +20472,18 @@ var RoleSchema = z.object({
20380
20472
  /**
20381
20473
  * Optional: ID of another role this role reports to.
20382
20474
  * When present, must reference another `roles[].id` in the same organization.
20383
- * Cross-reference enforced in `OrganizationModelSchema.superRefine()`.
20384
- * Absence indicates a top-level role (no reporting line).
20385
20475
  */
20386
- reportsToId: z.string().trim().min(1).max(100).optional(),
20476
+ reportsToId: RoleIdSchema.optional(),
20387
20477
  /**
20388
- * Optional: name or email of the person currently holding this role.
20389
- * Free-form string supports "Alice Johnson", "alice@example.com", or
20390
- * any human-readable identifier. Not validated against any user registry.
20478
+ * Optional: human, agent, or team holder currently filling this role.
20479
+ * Agent holders reference OM Resource IDs and are validated at the model level.
20391
20480
  */
20392
- heldBy: z.string().trim().max(200).optional()
20481
+ heldBy: RoleHoldersSchema.optional(),
20482
+ /**
20483
+ * Optional Systems this role is accountable for.
20484
+ * Cross-reference enforced in `OrganizationModelSchema.superRefine()`.
20485
+ */
20486
+ responsibleFor: z.array(SystemIdSchema).optional()
20393
20487
  });
20394
20488
  var RolesDomainSchema = z.object({
20395
20489
  roles: z.array(RoleSchema).default([])
@@ -20624,8 +20718,8 @@ var OrgKnowledgeNodeSchema = z.object({
20624
20718
  skills: z.array(KnowledgeSkillBindingSchema).optional(),
20625
20719
  /** Domain key used to derive fast graph->skill registries. */
20626
20720
  domain: KnowledgeDomainBindingSchema.optional(),
20627
- /** Identifiers of the roles or members who own this knowledge node. */
20628
- ownerIds: z.array(ModelIdSchema).default([]),
20721
+ /** Role identifiers that own this knowledge node. */
20722
+ ownerIds: z.array(RoleIdSchema).default([]),
20629
20723
  /** ISO date string (YYYY-MM-DD or full ISO 8601) of last meaningful update. */
20630
20724
  updatedAt: z.string().trim().min(1).max(50)
20631
20725
  });
@@ -20647,6 +20741,8 @@ var OrganizationModelSchemaBase = z.object({
20647
20741
  offerings: OfferingsDomainSchema.default(DEFAULT_ORGANIZATION_MODEL_OFFERINGS),
20648
20742
  roles: RolesDomainSchema.default(DEFAULT_ORGANIZATION_MODEL_ROLES),
20649
20743
  goals: GoalsDomainSchema.default(DEFAULT_ORGANIZATION_MODEL_GOALS),
20744
+ systems: SystemsDomainSchema.default(DEFAULT_ORGANIZATION_MODEL_SYSTEMS),
20745
+ resources: ResourcesDomainSchema.default(DEFAULT_ORGANIZATION_MODEL_RESOURCES),
20650
20746
  statuses: StatusesDomainSchema.default({ entries: [] }),
20651
20747
  operations: OperationsDomainSchema.default({ entries: [] }),
20652
20748
  knowledge: KnowledgeDomainSchema.default({ nodes: [] })
@@ -20680,6 +20776,9 @@ function hasFeature(featuresById, featureId) {
20680
20776
  function defaultFeaturePathFor(id) {
20681
20777
  return `/${id.replaceAll(".", "/")}`;
20682
20778
  }
20779
+ function asRoleHolderArray(heldBy) {
20780
+ return Array.isArray(heldBy) ? heldBy : [heldBy];
20781
+ }
20683
20782
  var OrganizationModelSchema = OrganizationModelSchemaBase.superRefine((model, ctx) => {
20684
20783
  const featuresById = collectIds(model.features, ctx, ["features"], "Feature");
20685
20784
  const featureIdsByEffectivePath = /* @__PURE__ */ new Map();
@@ -20790,6 +20889,8 @@ var OrganizationModelSchema = OrganizationModelSchemaBase.superRefine((model, ct
20790
20889
  );
20791
20890
  }
20792
20891
  });
20892
+ const goalsById = new Map(model.goals.objectives.map((objective) => [objective.id, objective]));
20893
+ const knowledgeById = new Map(model.knowledge.nodes.map((node) => [node.id, node]));
20793
20894
  const rolesById = new Map(model.roles.roles.map((role) => [role.id, role]));
20794
20895
  model.roles.roles.forEach((role, roleIndex) => {
20795
20896
  if (role.reportsToId !== void 0 && !rolesById.has(role.reportsToId)) {
@@ -20800,6 +20901,102 @@ var OrganizationModelSchema = OrganizationModelSchemaBase.superRefine((model, ct
20800
20901
  );
20801
20902
  }
20802
20903
  });
20904
+ const systemsById = collectIds(model.systems.systems, ctx, ["systems", "systems"], "System");
20905
+ model.roles.roles.forEach((role, roleIndex) => {
20906
+ role.responsibleFor?.forEach((systemId, systemIndex) => {
20907
+ if (!systemsById.has(systemId)) {
20908
+ addIssue(
20909
+ ctx,
20910
+ ["roles", "roles", roleIndex, "responsibleFor", systemIndex],
20911
+ `Role "${role.id}" references unknown responsibleFor system "${systemId}"`
20912
+ );
20913
+ }
20914
+ });
20915
+ });
20916
+ model.systems.systems.forEach((system, systemIndex) => {
20917
+ if (system.responsibleRoleId !== void 0 && !rolesById.has(system.responsibleRoleId)) {
20918
+ addIssue(
20919
+ ctx,
20920
+ ["systems", "systems", systemIndex, "responsibleRoleId"],
20921
+ `System "${system.id}" references unknown responsibleRoleId "${system.responsibleRoleId}"`
20922
+ );
20923
+ }
20924
+ system.governedByKnowledge.forEach((nodeId, nodeIndex) => {
20925
+ if (!knowledgeById.has(nodeId)) {
20926
+ addIssue(
20927
+ ctx,
20928
+ ["systems", "systems", systemIndex, "governedByKnowledge", nodeIndex],
20929
+ `System "${system.id}" references unknown knowledge node "${nodeId}"`
20930
+ );
20931
+ }
20932
+ });
20933
+ system.drivesGoals.forEach((goalId, goalIndex) => {
20934
+ if (!goalsById.has(goalId)) {
20935
+ addIssue(
20936
+ ctx,
20937
+ ["systems", "systems", systemIndex, "drivesGoals", goalIndex],
20938
+ `System "${system.id}" references unknown goal "${goalId}"`
20939
+ );
20940
+ }
20941
+ });
20942
+ });
20943
+ const resourcesById = collectIds(model.resources.entries, ctx, ["resources", "entries"], "Resource");
20944
+ model.resources.entries.forEach((resource, resourceIndex) => {
20945
+ if (!systemsById.has(resource.systemId)) {
20946
+ addIssue(
20947
+ ctx,
20948
+ ["resources", "entries", resourceIndex, "systemId"],
20949
+ `Resource "${resource.id}" references unknown systemId "${resource.systemId}"`
20950
+ );
20951
+ }
20952
+ if (resource.ownerRoleId !== void 0 && !rolesById.has(resource.ownerRoleId)) {
20953
+ addIssue(
20954
+ ctx,
20955
+ ["resources", "entries", resourceIndex, "ownerRoleId"],
20956
+ `Resource "${resource.id}" references unknown ownerRoleId "${resource.ownerRoleId}"`
20957
+ );
20958
+ }
20959
+ if (resource.kind === "agent" && resource.actsAsRoleId !== void 0 && !rolesById.has(resource.actsAsRoleId)) {
20960
+ addIssue(
20961
+ ctx,
20962
+ ["resources", "entries", resourceIndex, "actsAsRoleId"],
20963
+ `Agent resource "${resource.id}" references unknown actsAsRoleId "${resource.actsAsRoleId}"`
20964
+ );
20965
+ }
20966
+ });
20967
+ model.roles.roles.forEach((role, roleIndex) => {
20968
+ if (role.heldBy === void 0) return;
20969
+ asRoleHolderArray(role.heldBy).forEach((holder, holderIndex) => {
20970
+ if (holder.kind !== "agent") return;
20971
+ const resource = resourcesById.get(holder.agentId);
20972
+ if (resource === void 0) {
20973
+ addIssue(
20974
+ ctx,
20975
+ ["roles", "roles", roleIndex, "heldBy", Array.isArray(role.heldBy) ? holderIndex : "agentId"],
20976
+ `Role "${role.id}" references unknown agent holder resource "${holder.agentId}"`
20977
+ );
20978
+ return;
20979
+ }
20980
+ if (resource.kind !== "agent") {
20981
+ addIssue(
20982
+ ctx,
20983
+ ["roles", "roles", roleIndex, "heldBy", Array.isArray(role.heldBy) ? holderIndex : "agentId"],
20984
+ `Role "${role.id}" agent holder "${holder.agentId}" must reference an agent resource`
20985
+ );
20986
+ }
20987
+ });
20988
+ });
20989
+ model.knowledge.nodes.forEach((node, nodeIndex) => {
20990
+ node.ownerIds.forEach((roleId, ownerIndex) => {
20991
+ if (!rolesById.has(roleId)) {
20992
+ addIssue(
20993
+ ctx,
20994
+ ["knowledge", "nodes", nodeIndex, "ownerIds", ownerIndex],
20995
+ `Knowledge node "${node.id}" references unknown owner role "${roleId}"`
20996
+ );
20997
+ }
20998
+ });
20999
+ });
20803
21000
  });
20804
21001
 
20805
21002
  // src/organization-model/defaults.ts
@@ -20840,6 +21037,15 @@ var DEFAULT_ORGANIZATION_MODEL = {
20840
21037
  color: "green",
20841
21038
  icon: "feature.finance"
20842
21039
  },
21040
+ {
21041
+ id: "business",
21042
+ label: "Business",
21043
+ description: "Revenue, client relationships, and project delivery",
21044
+ enabled: true,
21045
+ color: "blue",
21046
+ icon: "feature.business",
21047
+ uiPosition: "sidebar-primary"
21048
+ },
20843
21049
  {
20844
21050
  id: "sales",
20845
21051
  label: "Sales",
@@ -20847,7 +21053,7 @@ var DEFAULT_ORGANIZATION_MODEL = {
20847
21053
  enabled: true,
20848
21054
  color: "blue",
20849
21055
  icon: "feature.sales",
20850
- uiPosition: "sidebar-primary"
21056
+ path: "/sales"
20851
21057
  },
20852
21058
  {
20853
21059
  id: "sales.crm",
@@ -20874,8 +21080,16 @@ var DEFAULT_ORGANIZATION_MODEL = {
20874
21080
  enabled: true,
20875
21081
  color: "orange",
20876
21082
  icon: "feature.projects",
20877
- path: "/projects",
20878
- uiPosition: "sidebar-primary"
21083
+ path: "/projects"
21084
+ },
21085
+ {
21086
+ id: "clients",
21087
+ label: "Clients",
21088
+ description: "Client relationships, accounts, and business context",
21089
+ enabled: true,
21090
+ color: "orange",
21091
+ icon: "feature.projects",
21092
+ path: "/business/clients"
20879
21093
  },
20880
21094
  {
20881
21095
  id: "operations",
@@ -21120,6 +21334,8 @@ var DEFAULT_ORGANIZATION_MODEL = {
21120
21334
  offerings: DEFAULT_ORGANIZATION_MODEL_OFFERINGS,
21121
21335
  roles: DEFAULT_ORGANIZATION_MODEL_ROLES,
21122
21336
  goals: DEFAULT_ORGANIZATION_MODEL_GOALS,
21337
+ systems: DEFAULT_ORGANIZATION_MODEL_SYSTEMS,
21338
+ resources: DEFAULT_ORGANIZATION_MODEL_RESOURCES,
21123
21339
  statuses: DEFAULT_ORGANIZATION_MODEL_STATUSES,
21124
21340
  operations: DEFAULT_ORGANIZATION_MODEL_OPERATIONS,
21125
21341
  knowledge: DEFAULT_ORGANIZATION_MODEL_KNOWLEDGE
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elevasis/core",
3
- "version": "0.21.0",
3
+ "version": "0.22.0",
4
4
  "license": "MIT",
5
5
  "description": "Minimal shared constants across Elevasis monorepo",
6
6
  "sideEffects": false,
@@ -9,8 +9,6 @@
9
9
  "dist"
10
10
  ],
11
11
  "type": "module",
12
- "main": "./dist/index.js",
13
- "types": "./dist/index.d.ts",
14
12
  "exports": {
15
13
  ".": {
16
14
  "types": "./dist/index.d.ts",
@@ -65,6 +63,8 @@
65
63
  "stripe": "^20.2.0",
66
64
  "zod": "^4.1.0"
67
65
  },
66
+ "main": "./dist/index.js",
67
+ "types": "./dist/index.d.ts",
68
68
  "scripts": {
69
69
  "build": "tsc --noEmit",
70
70
  "build:publish": "node -e \"require('fs').rmSync('dist',{recursive:true,force:true})\" && tsc -p tsconfig.build.json && pnpm exec tsup && pnpm exec rollup -c rollup.dts.config.mjs && node -e \"require('fs').rmSync('dist/_dts',{recursive:true,force:true})\"",