@lucern/contracts 0.1.2-alpha.1 → 0.1.2-alpha.3

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.
@@ -12,7 +12,7 @@
12
12
  declare const FORK_REASONS: readonly ["refinement", "contradiction_response", "scope_change", "confidence_collapse", "manual"];
13
13
  type ForkReason = (typeof FORK_REASONS)[number];
14
14
  /** Confidence modulation triggers — what caused a confidence change */
15
- declare const CONFIDENCE_TRIGGERS: readonly ["evidence_added", "contradiction_detected", "merge_outcome", "manual", "decay"];
15
+ declare const CONFIDENCE_TRIGGERS: readonly ["evidence_added", "evidence_removed", "contradiction_detected", "contradiction_resolved", "manual", "decay", "agent_assessment", "worktree_outcome", "worktree_completed", "fusion", "discount", "deduction"];
16
16
  type ConfidenceTrigger = (typeof CONFIDENCE_TRIGGERS)[number];
17
17
  /** Belief status — lifecycle state */
18
18
  declare const BELIEF_STATUSES: readonly ["unscored", "scored", "archived"];
@@ -14,14 +14,28 @@ var FORK_REASONS = [
14
14
  var CONFIDENCE_TRIGGERS = [
15
15
  "evidence_added",
16
16
  // New evidence bore on the belief
17
+ "evidence_removed",
18
+ // Evidence was removed or invalidated
17
19
  "contradiction_detected",
18
20
  // A contradiction was flagged involving this belief
19
- "merge_outcome",
20
- // Merge scoring determined this confidence
21
+ "contradiction_resolved",
22
+ // A contradiction was resolved
21
23
  "manual",
22
24
  // User manually adjusted confidence
23
- "decay"
25
+ "decay",
24
26
  // Time-based confidence erosion
27
+ "agent_assessment",
28
+ // An agent provided a structured assessment
29
+ "worktree_outcome",
30
+ // Worktree outcome determined this confidence
31
+ "worktree_completed",
32
+ // Worktree completed and closed this scoring loop
33
+ "fusion",
34
+ // Confidence came from subjective-logic fusion
35
+ "discount",
36
+ // Confidence came from trust discounting
37
+ "deduction"
38
+ // Confidence came from conditional deduction
25
39
  ];
26
40
  var BELIEF_STATUSES = [
27
41
  "unscored",
@@ -1 +1 @@
1
- {"version":3,"sources":["../src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AA;AAAA;AAAA,EACA,mBAAA;AAAA;AAAA,EACA,UAAA;AAAA;AAAA,EACA;AAAA;AACF;AAQO,IAAM,gBAAA,GAAmB;AAAA,EAC9B,IAAA;AAAA;AAAA,EACA,IAAA;AAAA;AAAA,EACA,IAAA;AAAA;AAAA,EACA;AAAA;AACF;AAcO,IAAM,cAAA,GAAiB;AAAA,EAC5B,mBAAA;AAAA;AAAA,EACA,iBAAA;AAAA;AAAA,EACA,sBAAA;AAAA;AAAA,EACA,qBAAA;AAAA;AAAA,EACA;AAAA;AACF;AAQO,IAAM,sBAAA,GAAyB;AAAA;AAAA,EAEpC,SAAA;AAAA;AAAA,EACA,SAAA;AAAA;AAAA,EACA,SAAA;AAAA;AAAA;AAAA,EAEA,aAAA;AAAA;AAAA,EACA,UAAA;AAAA;AAAA;AAAA,EAEA,YAAA;AAAA;AAAA,EACA,cAAA;AAAA;AAAA,EACA,UAAA;AAAA;AAAA,EACA,YAAA;AAAA;AAAA,EACA;AAAA;AACF","file":"api-enums.contract.js","sourcesContent":["/**\n * API Enum Contract Definitions\n *\n * Canonical enum values for all API-facing enumerations.\n * These are co-equal with MCP contracts as external contracts.\n * SDK types are DERIVED from these — not independently authored.\n *\n * CONTRACT SURFACE: Adding a new enum value is additive (non-breaking).\n * Removing or renaming an existing value is a BREAKING CHANGE.\n */\n\n// =============================================================================\n// BELIEF ENUMS\n// =============================================================================\n\n/** Fork reasons — why a scored belief was branched */\nexport const FORK_REASONS = [\n \"refinement\", // Belief text evolved based on new understanding\n \"contradiction_response\", // Created in response to a detected contradiction\n \"scope_change\", // Belief scope narrowed or broadened\n \"confidence_collapse\", // Confidence dropped below viability threshold\n \"manual\", // User-initiated fork without specific trigger\n] as const;\nexport type ForkReason = (typeof FORK_REASONS)[number];\n\n/** Confidence modulation triggers — what caused a confidence change */\nexport const CONFIDENCE_TRIGGERS = [\n \"evidence_added\", // New evidence bore on the belief\n \"contradiction_detected\", // A contradiction was flagged involving this belief\n \"merge_outcome\", // Merge scoring determined this confidence\n \"manual\", // User manually adjusted confidence\n \"decay\", // Time-based confidence erosion\n] as const;\nexport type ConfidenceTrigger = (typeof CONFIDENCE_TRIGGERS)[number];\n\n/** Belief status — lifecycle state */\nexport const BELIEF_STATUSES = [\n \"unscored\", // Draft — editable in worktree (on feature branch, pre-merge)\n \"scored\", // Merged — formulation frozen (merged to main)\n \"archived\", // Soft-deleted — preserved in history (git rm)\n] as const;\nexport type BeliefStatus = (typeof BELIEF_STATUSES)[number];\n\n// =============================================================================\n// EDGE ENUMS\n// =============================================================================\n\n/** Reasoning methods — how an edge relationship was determined */\nexport const REASONING_METHODS = [\n \"deductive\", // Logically entailed\n \"inductive\", // Generalized from instances\n \"abductive\", // Best explanation inference\n \"analogical\", // Reasoning by analogy\n \"empirical\", // Direct observation/measurement\n] as const;\nexport type ReasoningMethod = (typeof REASONING_METHODS)[number];\n\n/** Defeat types (Pollock taxonomy) — how a contradiction operates */\nexport const DEFEAT_TYPES = [\n \"rebuts\", // Direct contradiction — reasons for the negation\n \"undercuts\", // Breaks the inference link between evidence and belief\n \"undermines\", // Attacks a premise the belief depends on\n] as const;\nexport type DefeatType = (typeof DEFEAT_TYPES)[number];\n\n/** Contradiction severity levels */\nexport const CONTRADICTION_SEVERITIES = [\n \"low\", // Minor tension, may not require action\n \"medium\", // Moderate conflict, should be investigated\n \"high\", // Significant contradiction, likely needs resolution\n \"critical\", // Blocks progress — must be addressed before judgment\n] as const;\nexport type ContradictionSeverity = (typeof CONTRADICTION_SEVERITIES)[number];\n\n/** Contradiction resolution status */\nexport const CONTRADICTION_STATUSES = [\n \"unresolved\", // Open conflict — may persist indefinitely\n \"resolved\", // Conflict addressed (one belief forked, archived, or confidence adjusted)\n \"accepted\", // Explicitly accepted as irreconcilable — both beliefs maintained\n] as const;\nexport type ContradictionStatus = (typeof CONTRADICTION_STATUSES)[number];\n\n// =============================================================================\n// WORKTREE ENUMS (git worktree lifecycle)\n// =============================================================================\n\n/** Merge outcome types — how a worktree merge resolved */\nexport const MERGE_OUTCOMES = [\n \"validated\", // Beliefs confirmed — clean merge to main\n \"invalidated\", // Defeat recorded — confidence collapsed (merge with revert)\n \"forked\", // Beliefs split into competing versions (fork from merge point)\n \"inconclusive\", // Insufficient evidence — stashed (git stash)\n] as const;\nexport type MergeOutcome = (typeof MERGE_OUTCOMES)[number];\n\n/** Worktree phases — investigation lifecycle within a checked-out worktree */\nexport const WORKTREE_PHASES = [\n \"hypothesis\", // Form testable claims (write the code — commits)\n \"investigation\", // Collect evidence (run the tests — more commits)\n \"evaluation\", // Update credences (review the results — amend as needed)\n \"resolution\", // Determine outcome (merge to main, fork, or stash)\n] as const;\nexport type WorktreePhase = (typeof WORKTREE_PHASES)[number];\n\n// =============================================================================\n// BRANCH ENUMS (git branch lifecycle)\n// =============================================================================\n\n/** Branch status — thematic branch lifecycle */\nexport const BRANCH_STATUSES = [\n \"dormant\", // Branch exists but no active worktree (no one investigating)\n \"active\", // At least one worktree is investigating this branch\n \"archived\", // Branch retired — no longer a relevant thematic container\n] as const;\nexport type BranchStatus = (typeof BRANCH_STATUSES)[number];\n\n// =============================================================================\n// PULL REQUEST ENUMS (git pull request lifecycle)\n// =============================================================================\n\n/** Pull request status — review lifecycle before merge */\nexport const PULL_REQUEST_STATUSES = [\n \"pending_review\", // PR opened — awaiting reviewer feedback\n \"changes_requested\", // Reviewer requests changes before merge\n \"approved\", // Approved — ready to merge\n \"blocked\", // Blocked — cannot merge until contradiction is resolved\n] as const;\nexport type PullRequestStatus = (typeof PULL_REQUEST_STATUSES)[number];\n\n// =============================================================================\n// LAYER ENUMS\n// =============================================================================\n\n/** Epistemic layers — the hierarchy of knowledge */\nexport const EPISTEMIC_LAYERS = [\n \"L1\", // Source — the given (vendored deps)\n \"L2\", // Evidence — the interpreted (test suite)\n \"L3\", // Belief — the structural (source files)\n \"L4\", // Judgment — the committed (release tags)\n] as const;\nexport type EpistemicLayer = (typeof EPISTEMIC_LAYERS)[number];\n\n// =============================================================================\n// JUDGMENT ENUMS (Phase 1: new vocabulary)\n// =============================================================================\n\n/**\n * Judgment type — classification of the determination.\n *\n * Phase 1: These are new enum values for the Judgment (L4) vocabulary.\n * The existing code uses \"Decision\" — these are the forward-looking terms\n * that will eventually replace the Decision vocabulary (Phase 2-3).\n */\nexport const JUDGMENT_TYPES = [\n \"investment_thesis\", // Judgment on an investment opportunity\n \"thesis_maturity\", // Judgment that a thesis is ready for IC presentation\n \"contradiction_ruling\", // Judgment on how to handle an irreconcilable contradiction\n \"scope_determination\", // Judgment that defines or redefines investigation scope\n \"confidence_ruling\", // Judgment that overrides automated confidence for policy reasons\n] as const;\nexport type JudgmentType = (typeof JUDGMENT_TYPES)[number];\n\n// =============================================================================\n// SUPPORT RELATION ENUMS\n// =============================================================================\n\n/** Core edge types used in the Integration Surfaces */\nexport const INTEGRATION_EDGE_TYPES = [\n // Support relations\n \"informs\", // Evidence bears on a belief (weight = direction/strength)\n \"grounds\", // Source provides raw basis for evidence\n \"answers\", // Evidence or belief resolves a question\n // Defeat relations (Pollock) — weight carries direction\n \"contradicts\", // Rebuts — direct contradiction\n \"supports\", // Weight carries valence (negative = weakens/undercuts)\n // Structural relations\n \"depends_on\", // Belief B requires Belief A\n \"derived_from\", // Provenance lineage\n \"contains\", // Hierarchical containment\n \"supersedes\", // New version replaces old (lineage)\n \"tests\", // Question tests a belief\n] as const;\nexport type IntegrationEdgeType = (typeof INTEGRATION_EDGE_TYPES)[number];\n"]}
1
+ {"version":3,"sources":["../src/api-enums.contract.ts"],"names":[],"mappings":";AAgBO,IAAM,YAAA,GAAe;AAAA,EAC1B,YAAA;AAAA;AAAA,EACA,wBAAA;AAAA;AAAA,EACA,cAAA;AAAA;AAAA,EACA,qBAAA;AAAA;AAAA,EACA;AAAA;AACF;AAIO,IAAM,mBAAA,GAAsB;AAAA,EACjC,gBAAA;AAAA;AAAA,EACA,kBAAA;AAAA;AAAA,EACA,wBAAA;AAAA;AAAA,EACA,wBAAA;AAAA;AAAA,EACA,QAA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A;AAAA;AAAA,EACA,IAAA;AAAA;AAAA,EACA;AAAA;AACF;AAcO,IAAM,cAAA,GAAiB;AAAA,EAC5B,mBAAA;AAAA;AAAA,EACA,iBAAA;AAAA;AAAA,EACA,sBAAA;AAAA;AAAA,EACA,qBAAA;AAAA;AAAA,EACA;AAAA;AACF;AAQO,IAAM,sBAAA,GAAyB;AAAA;AAAA,EAEpC,SAAA;AAAA;AAAA,EACA,SAAA;AAAA;AAAA,EACA,SAAA;AAAA;AAAA;AAAA,EAEA,aAAA;AAAA;AAAA,EACA,UAAA;AAAA;AAAA;AAAA,EAEA,YAAA;AAAA;AAAA,EACA,cAAA;AAAA;AAAA,EACA,UAAA;AAAA;AAAA,EACA,YAAA;AAAA;AAAA,EACA;AAAA;AACF","file":"api-enums.contract.js","sourcesContent":["/**\n * API Enum Contract Definitions\n *\n * Canonical enum values for all API-facing enumerations.\n * These are co-equal with MCP contracts as external contracts.\n * SDK types are DERIVED from these — not independently authored.\n *\n * CONTRACT SURFACE: Adding a new enum value is additive (non-breaking).\n * Removing or renaming an existing value is a BREAKING CHANGE.\n */\n\n// =============================================================================\n// BELIEF ENUMS\n// =============================================================================\n\n/** Fork reasons — why a scored belief was branched */\nexport const FORK_REASONS = [\n \"refinement\", // Belief text evolved based on new understanding\n \"contradiction_response\", // Created in response to a detected contradiction\n \"scope_change\", // Belief scope narrowed or broadened\n \"confidence_collapse\", // Confidence dropped below viability threshold\n \"manual\", // User-initiated fork without specific trigger\n] as const;\nexport type ForkReason = (typeof FORK_REASONS)[number];\n\n/** Confidence modulation triggers — what caused a confidence change */\nexport const CONFIDENCE_TRIGGERS = [\n \"evidence_added\", // New evidence bore on the belief\n \"evidence_removed\", // Evidence was removed or invalidated\n \"contradiction_detected\", // A contradiction was flagged involving this belief\n \"contradiction_resolved\", // A contradiction was resolved\n \"manual\", // User manually adjusted confidence\n \"decay\", // Time-based confidence erosion\n \"agent_assessment\", // An agent provided a structured assessment\n \"worktree_outcome\", // Worktree outcome determined this confidence\n \"worktree_completed\", // Worktree completed and closed this scoring loop\n \"fusion\", // Confidence came from subjective-logic fusion\n \"discount\", // Confidence came from trust discounting\n \"deduction\", // Confidence came from conditional deduction\n] as const;\nexport type ConfidenceTrigger = (typeof CONFIDENCE_TRIGGERS)[number];\n\n/** Belief status — lifecycle state */\nexport const BELIEF_STATUSES = [\n \"unscored\", // Draft — editable in worktree (on feature branch, pre-merge)\n \"scored\", // Merged — formulation frozen (merged to main)\n \"archived\", // Soft-deleted — preserved in history (git rm)\n] as const;\nexport type BeliefStatus = (typeof BELIEF_STATUSES)[number];\n\n// =============================================================================\n// EDGE ENUMS\n// =============================================================================\n\n/** Reasoning methods — how an edge relationship was determined */\nexport const REASONING_METHODS = [\n \"deductive\", // Logically entailed\n \"inductive\", // Generalized from instances\n \"abductive\", // Best explanation inference\n \"analogical\", // Reasoning by analogy\n \"empirical\", // Direct observation/measurement\n] as const;\nexport type ReasoningMethod = (typeof REASONING_METHODS)[number];\n\n/** Defeat types (Pollock taxonomy) — how a contradiction operates */\nexport const DEFEAT_TYPES = [\n \"rebuts\", // Direct contradiction — reasons for the negation\n \"undercuts\", // Breaks the inference link between evidence and belief\n \"undermines\", // Attacks a premise the belief depends on\n] as const;\nexport type DefeatType = (typeof DEFEAT_TYPES)[number];\n\n/** Contradiction severity levels */\nexport const CONTRADICTION_SEVERITIES = [\n \"low\", // Minor tension, may not require action\n \"medium\", // Moderate conflict, should be investigated\n \"high\", // Significant contradiction, likely needs resolution\n \"critical\", // Blocks progress — must be addressed before judgment\n] as const;\nexport type ContradictionSeverity = (typeof CONTRADICTION_SEVERITIES)[number];\n\n/** Contradiction resolution status */\nexport const CONTRADICTION_STATUSES = [\n \"unresolved\", // Open conflict — may persist indefinitely\n \"resolved\", // Conflict addressed (one belief forked, archived, or confidence adjusted)\n \"accepted\", // Explicitly accepted as irreconcilable — both beliefs maintained\n] as const;\nexport type ContradictionStatus = (typeof CONTRADICTION_STATUSES)[number];\n\n// =============================================================================\n// WORKTREE ENUMS (git worktree lifecycle)\n// =============================================================================\n\n/** Merge outcome types — how a worktree merge resolved */\nexport const MERGE_OUTCOMES = [\n \"validated\", // Beliefs confirmed — clean merge to main\n \"invalidated\", // Defeat recorded — confidence collapsed (merge with revert)\n \"forked\", // Beliefs split into competing versions (fork from merge point)\n \"inconclusive\", // Insufficient evidence — stashed (git stash)\n] as const;\nexport type MergeOutcome = (typeof MERGE_OUTCOMES)[number];\n\n/** Worktree phases — investigation lifecycle within a checked-out worktree */\nexport const WORKTREE_PHASES = [\n \"hypothesis\", // Form testable claims (write the code — commits)\n \"investigation\", // Collect evidence (run the tests — more commits)\n \"evaluation\", // Update credences (review the results — amend as needed)\n \"resolution\", // Determine outcome (merge to main, fork, or stash)\n] as const;\nexport type WorktreePhase = (typeof WORKTREE_PHASES)[number];\n\n// =============================================================================\n// BRANCH ENUMS (git branch lifecycle)\n// =============================================================================\n\n/** Branch status — thematic branch lifecycle */\nexport const BRANCH_STATUSES = [\n \"dormant\", // Branch exists but no active worktree (no one investigating)\n \"active\", // At least one worktree is investigating this branch\n \"archived\", // Branch retired — no longer a relevant thematic container\n] as const;\nexport type BranchStatus = (typeof BRANCH_STATUSES)[number];\n\n// =============================================================================\n// PULL REQUEST ENUMS (git pull request lifecycle)\n// =============================================================================\n\n/** Pull request status — review lifecycle before merge */\nexport const PULL_REQUEST_STATUSES = [\n \"pending_review\", // PR opened — awaiting reviewer feedback\n \"changes_requested\", // Reviewer requests changes before merge\n \"approved\", // Approved — ready to merge\n \"blocked\", // Blocked — cannot merge until contradiction is resolved\n] as const;\nexport type PullRequestStatus = (typeof PULL_REQUEST_STATUSES)[number];\n\n// =============================================================================\n// LAYER ENUMS\n// =============================================================================\n\n/** Epistemic layers — the hierarchy of knowledge */\nexport const EPISTEMIC_LAYERS = [\n \"L1\", // Source — the given (vendored deps)\n \"L2\", // Evidence — the interpreted (test suite)\n \"L3\", // Belief — the structural (source files)\n \"L4\", // Judgment — the committed (release tags)\n] as const;\nexport type EpistemicLayer = (typeof EPISTEMIC_LAYERS)[number];\n\n// =============================================================================\n// JUDGMENT ENUMS (Phase 1: new vocabulary)\n// =============================================================================\n\n/**\n * Judgment type — classification of the determination.\n *\n * Phase 1: These are new enum values for the Judgment (L4) vocabulary.\n * The existing code uses \"Decision\" — these are the forward-looking terms\n * that will eventually replace the Decision vocabulary (Phase 2-3).\n */\nexport const JUDGMENT_TYPES = [\n \"investment_thesis\", // Judgment on an investment opportunity\n \"thesis_maturity\", // Judgment that a thesis is ready for IC presentation\n \"contradiction_ruling\", // Judgment on how to handle an irreconcilable contradiction\n \"scope_determination\", // Judgment that defines or redefines investigation scope\n \"confidence_ruling\", // Judgment that overrides automated confidence for policy reasons\n] as const;\nexport type JudgmentType = (typeof JUDGMENT_TYPES)[number];\n\n// =============================================================================\n// SUPPORT RELATION ENUMS\n// =============================================================================\n\n/** Core edge types used in the Integration Surfaces */\nexport const INTEGRATION_EDGE_TYPES = [\n // Support relations\n \"informs\", // Evidence bears on a belief (weight = direction/strength)\n \"grounds\", // Source provides raw basis for evidence\n \"answers\", // Evidence or belief resolves a question\n // Defeat relations (Pollock) — weight carries direction\n \"contradicts\", // Rebuts — direct contradiction\n \"supports\", // Weight carries valence (negative = weakens/undercuts)\n // Structural relations\n \"depends_on\", // Belief B requires Belief A\n \"derived_from\", // Provenance lineage\n \"contains\", // Hierarchical containment\n \"supersedes\", // New version replaces old (lineage)\n \"tests\", // Question tests a belief\n] as const;\nexport type IntegrationEdgeType = (typeof INTEGRATION_EDGE_TYPES)[number];\n"]}
@@ -40,15 +40,16 @@ var DOMAIN_EVENT_TYPES = [
40
40
  "identity.key_revoked",
41
41
  "webhook.test"
42
42
  ];
43
+ var RUNTIME_BUFFER = globalThis.Buffer;
43
44
  function toBase64(value) {
44
- if (typeof Buffer !== "undefined") {
45
- return Buffer.from(value, "utf8").toString("base64url");
45
+ if (typeof RUNTIME_BUFFER !== "undefined") {
46
+ return RUNTIME_BUFFER.from(value, "utf8").toString("base64url");
46
47
  }
47
48
  return btoa(unescape(encodeURIComponent(value))).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/g, "");
48
49
  }
49
50
  function fromBase64(value) {
50
- if (typeof Buffer !== "undefined") {
51
- return Buffer.from(value, "base64url").toString("utf8");
51
+ if (typeof RUNTIME_BUFFER !== "undefined") {
52
+ return RUNTIME_BUFFER.from(value, "base64url").toString("utf8");
52
53
  }
53
54
  const normalized = value.replace(/-/g, "+").replace(/_/g, "/");
54
55
  return decodeURIComponent(escape(atob(normalized)));
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/events.contract.ts"],"names":[],"mappings":";AAiBO,IAAM,oBAAA,GAAuB;AAC7B,IAAM,4BAAA,GAA+B;AACrC,IAAM,oBAAA,GAAuB;AAC7B,IAAM,uBAAA,GAA0B,CAAC,GAAA,EAAO,GAAA,EAAO,KAAQ,GAAO;AAE9D,IAAM,kBAAA,GAAqB;AAAA,EAChC,gBAAA;AAAA,EACA,eAAA;AAAA,EACA,2BAAA;AAAA,EACA,iBAAA;AAAA,EACA,gBAAA;AAAA,EACA,yBAAA;AAAA,EACA,2BAAA;AAAA,EACA,wBAAA;AAAA,EACA,kBAAA;AAAA,EACA,iBAAA;AAAA,EACA,0BAAA;AAAA,EACA,kBAAA;AAAA,EACA,mBAAA;AAAA,EACA,kBAAA;AAAA,EACA,yBAAA;AAAA,EACA,mBAAA;AAAA,EACA,cAAA;AAAA,EACA,uBAAA;AAAA,EACA,kBAAA;AAAA,EACA,oBAAA;AAAA,EACA,iBAAA;AAAA,EACA,0BAAA;AAAA,EACA,2BAAA;AAAA,EACA,eAAA;AAAA,EACA,eAAA;AAAA,EACA,gBAAA;AAAA,EACA,cAAA;AAAA,EACA,gBAAA;AAAA,EACA,cAAA;AAAA,EACA,gBAAA;AAAA,EACA,kBAAA;AAAA,EACA,sBAAA;AAAA,EACA,sBAAA;AAAA,EACA,sBAAA;AAAA,EACA;AACF;AAiMA,SAAS,SAAS,KAAA,EAAuB;AACv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,IACE,IAAA,CAAK,aAAa,mBAAA,IAClB,IAAA,CAAK,aAAa,gBAAA,IAClB,IAAA,CAAK,kBAAkB,SAAA,EACvB;AACA,IAAA,OAAO,SAAA;AAAA,EACT;AACA,EAAA,OAAO,OAAA;AACT;AAEA,eAAsB,eAAA,CACpB,gBACA,KAAA,EACkB;AAClB,EAAA,OAAO,MAAM,cAAA,CAAe,oBAAA,EAA6B,KAAK,CAAA;AAChE","file":"events-types.contract.js","sourcesContent":["/**\n * @lucern/contracts — events (canonical support contract)\n *\n * Consolidated flat support surface for Lucern's domain event stream:\n * - Event type definitions, constants, and shared enums\n * - Event construction + cursor helpers\n *\n * Consolidated from the former split type-definition module\n * and the prior src/events.contract.ts (helpers) in EK-16 T1 PR 3b.\n * Compat shim remains at the old events-types path until Lucern 1.0.0 (D12).\n */\n\n// =============================================================================\n// EVENT TYPE DEFINITIONS & CONSTANTS\n// (Formerly the split events type-definition module)\n// =============================================================================\n\nexport const DOMAIN_EVENT_VERSION = \"1.0\" as const;\nexport const EVENT_RETENTION_DEFAULT_DAYS = 30;\nexport const WEBHOOK_MAX_ATTEMPTS = 5;\nexport const WEBHOOK_RETRY_DELAYS_MS = [1_000, 5_000, 30_000, 300_000] as const;\n\nexport const DOMAIN_EVENT_TYPES = [\n \"belief.created\",\n \"belief.forked\",\n \"belief.confidence_updated\",\n \"belief.archived\",\n \"belief.refined\",\n \"belief.contract_created\",\n \"belief.contract_evaluated\",\n \"belief.lineage_queried\",\n \"evidence.created\",\n \"evidence.linked\",\n \"evidence.search_executed\",\n \"question.created\",\n \"question.answered\",\n \"question.refined\",\n \"question.status_updated\",\n \"question.archived\",\n \"edge.created\",\n \"contradiction.flagged\",\n \"worktree.created\",\n \"worktree.activated\",\n \"worktree.merged\",\n \"worktree.targets_updated\",\n \"worktree.metadata_updated\",\n \"topic.created\",\n \"topic.updated\",\n \"topic.archived\",\n \"task.created\",\n \"task.completed\",\n \"task.updated\",\n \"ontology.bound\",\n \"context.compiled\",\n \"identity.key_created\",\n \"identity.key_rotated\",\n \"identity.key_revoked\",\n \"webhook.test\",\n] as const;\n\nexport type DomainEventType = (typeof DOMAIN_EVENT_TYPES)[number];\n\nexport type DomainResourceType =\n | \"belief\"\n | \"evidence\"\n | \"question\"\n | \"edge\"\n | \"contradiction\"\n | \"worktree\"\n | \"topic\"\n | \"task\"\n | \"ontology\"\n | \"context\"\n | \"identity\"\n | \"webhook\";\n\nexport type DomainActorType = \"human\" | \"agent\" | \"service\";\n\nexport type DomainEventData = Record<string, unknown>;\n\nexport type DomainEvent = {\n eventId: string;\n type: DomainEventType | string;\n version: typeof DOMAIN_EVENT_VERSION;\n timestamp: number;\n tenantId?: string;\n workspaceId?: string;\n topicId: string;\n resourceId: string;\n resourceType: DomainResourceType | string;\n actorId: string;\n actorType: DomainActorType;\n data: DomainEventData;\n correlationId?: string;\n expiresAt: number;\n};\n\nexport type CreateDomainEventInput = {\n eventId?: string;\n timestamp?: number;\n tenantId?: string;\n workspaceId?: string;\n topicId: string;\n type: DomainEventType | string;\n resourceId: string;\n resourceType: DomainResourceType | string;\n actorId: string;\n actorType: DomainActorType;\n data?: DomainEventData;\n correlationId?: string;\n retentionDays?: number;\n};\n\nexport type EventCursor = {\n timestamp: number;\n eventId: string;\n};\n\nexport type EventListQuery = {\n topicId?: string;\n after?: string;\n types?: string[];\n startTime?: number;\n endTime?: number;\n limit?: number;\n};\n\nexport type EventListResult = {\n events: DomainEvent[];\n nextCursor: string | null;\n};\n\nexport type WebhookSecretMode = \"configured\";\n\nexport type WebhookRecord = {\n id: string;\n webhookId: string;\n tenantId?: string;\n workspaceId?: string;\n topicId?: string;\n url: string;\n events: string[];\n active: boolean;\n secretConfigured: boolean;\n createdAt: number;\n updatedAt: number;\n createdBy: string;\n updatedBy: string;\n lastDeliveryAt?: number;\n lastSuccessfulDeliveryAt?: number;\n};\n\nexport type WebhookCreateInput = {\n url: string;\n events: string[];\n secret: string;\n topicId?: string;\n active?: boolean;\n};\n\nexport type WebhookUpdateInput = {\n url?: string;\n events?: string[];\n secret?: string;\n topicId?: string | null;\n active?: boolean;\n};\n\nexport type WebhookDeliveryStatus =\n | \"pending\"\n | \"delivering\"\n | \"succeeded\"\n | \"failed\"\n | \"dead_letter\";\n\nexport type WebhookDeliveryRecord = {\n id: string;\n deliveryId: string;\n webhookId: string;\n eventId: string;\n eventType: string;\n topicId: string;\n status: WebhookDeliveryStatus;\n attemptCount: number;\n maxAttempts: number;\n nextAttemptAt?: number;\n lastAttemptAt?: number;\n lastStatusCode?: number;\n lastError?: string;\n deliveredAt?: number;\n createdAt: number;\n updatedAt: number;\n};\n\nexport type WebhookDeliveryAttemptRecord = {\n id: string;\n attemptId: string;\n deliveryId: string;\n webhookId: string;\n eventId: string;\n eventType: string;\n attemptNumber: number;\n status: \"succeeded\" | \"failed\";\n statusCode?: number;\n error?: string;\n responseBody?: string;\n durationMs?: number;\n createdAt: number;\n};\n\nexport type WebhookDeliveriesResult = {\n deliveries: Array<\n WebhookDeliveryRecord & {\n attempts?: WebhookDeliveryAttemptRecord[];\n }\n >;\n};\n\nexport type WebhookHealthResult = {\n webhookId: string;\n totalAttempts: number;\n successfulAttempts: number;\n failedAttempts: number;\n successRate: number;\n pendingDeliveries: number;\n deadLetterDeliveries: number;\n lastDeliveryAt?: number;\n lastSuccessfulDeliveryAt?: number;\n};\n\nexport type WebhookTestResult = {\n webhookId: string;\n deliveryId: string;\n status: WebhookDeliveryStatus;\n attempts: number;\n};\n\nexport type ReplayEventsInput = EventListQuery & {\n webhookId?: string;\n};\n\nexport type ReplayEventsResult = EventListResult & {\n replayedDeliveries?: number;\n replayedWebhookId?: string;\n};\n\n// =============================================================================\n// EVENT HELPERS\n// (Formerly the body of src/events.contract.ts)\n// =============================================================================\n\nfunction toBase64(value: string): string {\n if (typeof Buffer !== \"undefined\") {\n return Buffer.from(value, \"utf8\").toString(\"base64url\");\n }\n return btoa(unescape(encodeURIComponent(value)))\n .replace(/\\+/g, \"-\")\n .replace(/\\//g, \"_\")\n .replace(/=+$/g, \"\");\n}\n\nfunction fromBase64(value: string): string {\n if (typeof Buffer !== \"undefined\") {\n return Buffer.from(value, \"base64url\").toString(\"utf8\");\n }\n const normalized = value.replace(/-/g, \"+\").replace(/_/g, \"/\");\n return decodeURIComponent(escape(atob(normalized)));\n}\n\nexport function createEventId(): string {\n const random = crypto.randomUUID().replace(/-/g, \"\");\n return `evt_${random}`;\n}\n\nexport function normalizeRetentionDays(value: number | undefined): number {\n if (!Number.isFinite(value) || typeof value !== \"number\" || value <= 0) {\n return EVENT_RETENTION_DEFAULT_DAYS;\n }\n return Math.max(1, Math.trunc(value));\n}\n\nexport function buildDomainEvent(input: CreateDomainEventInput): DomainEvent {\n const timestamp = input.timestamp ?? Date.now();\n const retentionDays = normalizeRetentionDays(input.retentionDays);\n return {\n eventId: input.eventId?.trim() || createEventId(),\n type: input.type.trim(),\n version: DOMAIN_EVENT_VERSION,\n timestamp,\n tenantId: input.tenantId?.trim() || undefined,\n workspaceId: input.workspaceId?.trim() || undefined,\n topicId: input.topicId.trim(),\n resourceId: input.resourceId.trim(),\n resourceType: input.resourceType.trim(),\n actorId: input.actorId.trim(),\n actorType: input.actorType,\n data: input.data ?? {},\n correlationId: input.correlationId?.trim() || undefined,\n expiresAt: timestamp + retentionDays * 24 * 60 * 60 * 1000,\n };\n}\n\nexport function compareEventCursor(left: EventCursor, right: EventCursor): number {\n if (left.timestamp !== right.timestamp) {\n return left.timestamp - right.timestamp;\n }\n return left.eventId.localeCompare(right.eventId);\n}\n\nexport function encodeEventCursor(cursor: EventCursor): string {\n return toBase64(JSON.stringify(cursor));\n}\n\nexport function decodeEventCursor(cursor: string | undefined): EventCursor | null {\n if (!cursor || cursor.trim().length === 0) {\n return null;\n }\n try {\n const parsed = JSON.parse(fromBase64(cursor.trim())) as Partial<EventCursor>;\n if (\n typeof parsed.timestamp !== \"number\" ||\n !Number.isFinite(parsed.timestamp) ||\n typeof parsed.eventId !== \"string\" ||\n parsed.eventId.trim().length === 0\n ) {\n return null;\n }\n return {\n timestamp: parsed.timestamp,\n eventId: parsed.eventId.trim(),\n };\n } catch {\n return null;\n }\n}\n\nexport function isAfterCursor(\n event: Pick<DomainEvent, \"timestamp\" | \"eventId\">,\n cursor: EventCursor | null\n): boolean {\n if (!cursor) {\n return true;\n }\n return compareEventCursor(event, cursor) > 0;\n}\n\nexport function sortEventsByCursor<T extends Pick<DomainEvent, \"timestamp\" | \"eventId\">>(\n events: readonly T[]\n): T[] {\n return [...events].sort((left, right) => compareEventCursor(left, right));\n}\n\nexport function inferActorType(args: {\n sessionType?: \"agent\" | \"user\";\n authMode?: string;\n principalType?: string;\n}): DomainActorType {\n if (args.sessionType === \"agent\") {\n return \"agent\";\n }\n if (\n args.authMode === \"service_principal\" ||\n args.authMode === \"tenant_api_key\" ||\n args.principalType === \"service\"\n ) {\n return \"service\";\n }\n return \"human\";\n}\n\nexport async function emitDomainEvent(\n invokeMutation: (reference: any, args: CreateDomainEventInput) => Promise<unknown>,\n input: CreateDomainEventInput\n): Promise<unknown> {\n return await invokeMutation(\"events:recordEvent\" as any, input);\n}\n"]}
1
+ {"version":3,"sources":["../src/events.contract.ts"],"names":[],"mappings":";AAiBO,IAAM,oBAAA,GAAuB;AAC7B,IAAM,4BAAA,GAA+B;AACrC,IAAM,oBAAA,GAAuB;AAC7B,IAAM,uBAAA,GAA0B,CAAC,GAAA,EAAO,GAAA,EAAO,KAAQ,GAAO;AAE9D,IAAM,kBAAA,GAAqB;AAAA,EAChC,gBAAA;AAAA,EACA,eAAA;AAAA,EACA,2BAAA;AAAA,EACA,iBAAA;AAAA,EACA,gBAAA;AAAA,EACA,yBAAA;AAAA,EACA,2BAAA;AAAA,EACA,wBAAA;AAAA,EACA,kBAAA;AAAA,EACA,iBAAA;AAAA,EACA,0BAAA;AAAA,EACA,kBAAA;AAAA,EACA,mBAAA;AAAA,EACA,kBAAA;AAAA,EACA,yBAAA;AAAA,EACA,mBAAA;AAAA,EACA,cAAA;AAAA,EAC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,IAAA;AAAA,EACT;AACA,EAAA,OAAO,kBAAA,CAAmB,KAAA,EAAO,MAAM,CAAA,GAAI,CAAA;AAC7C;AAEO,SAAS,mBACd,MAAA,EACK;AACL,EAAA,OAAO,CAAC,GAAG,MAAM,CAAA,CAAE,IAAA,CAAK,CAAC,IAAA,EAAM,KAAA,KAAU,kBAAA,CAAmB,IAAA,EAAM,KAAK,CAAC,CAAA;AAC1E;AAEO,SAAS,eAAe,IAAA,EAIX;AAClB,EAAA,IAAI,IAAA,CAAK,gBAAgB,OAAA,EAAS;AAChC,IAAA,OAAO,OAAA;AAAA,EACT;AACA,EAAA,IACE,IAAA,CAAK,aAAa,mBAAA,IAClB,IAAA,CAAK,aAAa,gBAAA,IAClB,IAAA,CAAK,kBAAkB,SAAA,EACvB;AACA,IAAA,OAAO,SAAA;AAAA,EACT;AACA,EAAA,OAAO,OAAA;AACT;AAEA,eAAsB,eAAA,CACpB,gBACA,KAAA,EACkB;AAClB,EAAA,OAAO,MAAM,cAAA,CAAe,oBAAA,EAA6B,KAAK,CAAA;AAChE","file":"events-types.contract.js","sourcesContent":["/**\n * @lucern/contracts — events (canonical support contract)\n *\n * Consolidated flat support surface for Lucern's domain event stream:\n * - Event type definitions, constants, and shared enums\n * - Event construction + cursor helpers\n *\n * Consolidated from the former split type-definition module\n * and the prior src/events.contract.ts (helpers) in EK-16 T1 PR 3b.\n * Compat shim remains at the old events-types path until Lucern 1.0.0 (D12).\n */\n\n// =============================================================================\n// EVENT TYPE DEFINITIONS & CONSTANTS\n// (Formerly the split events type-definition module)\n// =============================================================================\n\nexport const DOMAIN_EVENT_VERSION = \"1.0\" as const;\nexport const EVENT_RETENTION_DEFAULT_DAYS = 30;\nexport const WEBHOOK_MAX_ATTEMPTS = 5;\nexport const WEBHOOK_RETRY_DELAYS_MS = [1_000, 5_000, 30_000, 300_000] as const;\n\nexport const DOMAIN_EVENT_TYPES = [\n \"belief.created\",\n \"belief.forked\",\n \"belief.confidence_updated\",\n \"belief.archived\",\n \"belief.refined\",\n \"belief.contract_created\",\n \"belief.contract_evaluated\",\n \"belief.lineage_queried\",\n \"evidence.created\",\n \"evidence.linked\",\n \"evidence.search_executed\",\n \"question.created\",\n \"question.answered\",\n \"question.refined\",\n \"question.status_updated\",\n \"question.archived\",\n \"edge.created\",\n \"contradiction.flagged\",\n \"worktree.created\",\n \"worktree.activated\",\n \"worktree.merged\",\n \"worktree.targets_updated\",\n \"worktree.metadata_updated\",\n \"topic.created\",\n \"topic.updated\",\n \"topic.archived\",\n \"task.created\",\n \"task.completed\",\n \"task.updated\",\n \"ontology.bound\",\n \"context.compiled\",\n \"identity.key_created\",\n \"identity.key_rotated\",\n \"identity.key_revoked\",\n \"webhook.test\",\n] as const;\n\nexport type DomainEventType = (typeof DOMAIN_EVENT_TYPES)[number];\n\nexport type DomainResourceType =\n | \"belief\"\n | \"evidence\"\n | \"question\"\n | \"edge\"\n | \"contradiction\"\n | \"worktree\"\n | \"topic\"\n | \"task\"\n | \"ontology\"\n | \"context\"\n | \"identity\"\n | \"webhook\";\n\nexport type DomainActorType = \"human\" | \"agent\" | \"service\";\n\nexport type DomainEventData = Record<string, unknown>;\n\nexport type DomainEvent = {\n eventId: string;\n type: DomainEventType | string;\n version: typeof DOMAIN_EVENT_VERSION;\n timestamp: number;\n tenantId?: string;\n workspaceId?: string;\n topicId: string;\n resourceId: string;\n resourceType: DomainResourceType | string;\n actorId: string;\n actorType: DomainActorType;\n data: DomainEventData;\n correlationId?: string;\n expiresAt: number;\n};\n\nexport type CreateDomainEventInput = {\n eventId?: string;\n timestamp?: number;\n tenantId?: string;\n workspaceId?: string;\n topicId: string;\n type: DomainEventType | string;\n resourceId: string;\n resourceType: DomainResourceType | string;\n actorId: string;\n actorType: DomainActorType;\n data?: DomainEventData;\n correlationId?: string;\n retentionDays?: number;\n};\n\nexport type EventCursor = {\n timestamp: number;\n eventId: string;\n};\n\nexport type EventListQuery = {\n topicId?: string;\n after?: string;\n types?: string[];\n startTime?: number;\n endTime?: number;\n limit?: number;\n};\n\nexport type EventListResult = {\n events: DomainEvent[];\n nextCursor: string | null;\n};\n\nexport type WebhookSecretMode = \"configured\";\n\nexport type WebhookRecord = {\n id: string;\n webhookId: string;\n tenantId?: string;\n workspaceId?: string;\n topicId?: string;\n url: string;\n events: string[];\n active: boolean;\n secretConfigured: boolean;\n createdAt: number;\n updatedAt: number;\n createdBy: string;\n updatedBy: string;\n lastDeliveryAt?: number;\n lastSuccessfulDeliveryAt?: number;\n};\n\nexport type WebhookCreateInput = {\n url: string;\n events: string[];\n secret: string;\n topicId?: string;\n active?: boolean;\n};\n\nexport type WebhookUpdateInput = {\n url?: string;\n events?: string[];\n secret?: string;\n topicId?: string | null;\n active?: boolean;\n};\n\nexport type WebhookDeliveryStatus =\n | \"pending\"\n | \"delivering\"\n | \"succeeded\"\n | \"failed\"\n | \"dead_letter\";\n\nexport type WebhookDeliveryRecord = {\n id: string;\n deliveryId: string;\n webhookId: string;\n eventId: string;\n eventType: string;\n topicId: string;\n status: WebhookDeliveryStatus;\n attemptCount: number;\n maxAttempts: number;\n nextAttemptAt?: number;\n lastAttemptAt?: number;\n lastStatusCode?: number;\n lastError?: string;\n deliveredAt?: number;\n createdAt: number;\n updatedAt: number;\n};\n\nexport type WebhookDeliveryAttemptRecord = {\n id: string;\n attemptId: string;\n deliveryId: string;\n webhookId: string;\n eventId: string;\n eventType: string;\n attemptNumber: number;\n status: \"succeeded\" | \"failed\";\n statusCode?: number;\n error?: string;\n responseBody?: string;\n durationMs?: number;\n createdAt: number;\n};\n\nexport type WebhookDeliveriesResult = {\n deliveries: Array<\n WebhookDeliveryRecord & {\n attempts?: WebhookDeliveryAttemptRecord[];\n }\n >;\n};\n\nexport type WebhookHealthResult = {\n webhookId: string;\n totalAttempts: number;\n successfulAttempts: number;\n failedAttempts: number;\n successRate: number;\n pendingDeliveries: number;\n deadLetterDeliveries: number;\n lastDeliveryAt?: number;\n lastSuccessfulDeliveryAt?: number;\n};\n\nexport type WebhookTestResult = {\n webhookId: string;\n deliveryId: string;\n status: WebhookDeliveryStatus;\n attempts: number;\n};\n\nexport type ReplayEventsInput = EventListQuery & {\n webhookId?: string;\n};\n\nexport type ReplayEventsResult = EventListResult & {\n replayedDeliveries?: number;\n replayedWebhookId?: string;\n};\n\nconst RUNTIME_BUFFER = (\n globalThis as typeof globalThis & {\n Buffer?: {\n from(\n value: string,\n encoding: \"utf8\" | \"base64url\"\n ): {\n toString(encoding: \"utf8\" | \"base64url\"): string;\n };\n };\n }\n).Buffer;\n\n// =============================================================================\n// EVENT HELPERS\n// (Formerly the body of src/events.contract.ts)\n// =============================================================================\n\nfunction toBase64(value: string): string {\n if (typeof RUNTIME_BUFFER !== \"undefined\") {\n return RUNTIME_BUFFER.from(value, \"utf8\").toString(\"base64url\");\n }\n return btoa(unescape(encodeURIComponent(value)))\n .replace(/\\+/g, \"-\")\n .replace(/\\//g, \"_\")\n .replace(/=+$/g, \"\");\n}\n\nfunction fromBase64(value: string): string {\n if (typeof RUNTIME_BUFFER !== \"undefined\") {\n return RUNTIME_BUFFER.from(value, \"base64url\").toString(\"utf8\");\n }\n const normalized = value.replace(/-/g, \"+\").replace(/_/g, \"/\");\n return decodeURIComponent(escape(atob(normalized)));\n}\n\nexport function createEventId(): string {\n const random = crypto.randomUUID().replace(/-/g, \"\");\n return `evt_${random}`;\n}\n\nexport function normalizeRetentionDays(value: number | undefined): number {\n if (!Number.isFinite(value) || typeof value !== \"number\" || value <= 0) {\n return EVENT_RETENTION_DEFAULT_DAYS;\n }\n return Math.max(1, Math.trunc(value));\n}\n\nexport function buildDomainEvent(input: CreateDomainEventInput): DomainEvent {\n const timestamp = input.timestamp ?? Date.now();\n const retentionDays = normalizeRetentionDays(input.retentionDays);\n return {\n eventId: input.eventId?.trim() || createEventId(),\n type: input.type.trim(),\n version: DOMAIN_EVENT_VERSION,\n timestamp,\n tenantId: input.tenantId?.trim() || undefined,\n workspaceId: input.workspaceId?.trim() || undefined,\n topicId: input.topicId.trim(),\n resourceId: input.resourceId.trim(),\n resourceType: input.resourceType.trim(),\n actorId: input.actorId.trim(),\n actorType: input.actorType,\n data: input.data ?? {},\n correlationId: input.correlationId?.trim() || undefined,\n expiresAt: timestamp + retentionDays * 24 * 60 * 60 * 1000,\n };\n}\n\nexport function compareEventCursor(left: EventCursor, right: EventCursor): number {\n if (left.timestamp !== right.timestamp) {\n return left.timestamp - right.timestamp;\n }\n return left.eventId.localeCompare(right.eventId);\n}\n\nexport function encodeEventCursor(cursor: EventCursor): string {\n return toBase64(JSON.stringify(cursor));\n}\n\nexport function decodeEventCursor(cursor: string | undefined): EventCursor | null {\n if (!cursor || cursor.trim().length === 0) {\n return null;\n }\n try {\n const parsed = JSON.parse(fromBase64(cursor.trim())) as Partial<EventCursor>;\n if (\n typeof parsed.timestamp !== \"number\" ||\n !Number.isFinite(parsed.timestamp) ||\n typeof parsed.eventId !== \"string\" ||\n parsed.eventId.trim().length === 0\n ) {\n return null;\n }\n return {\n timestamp: parsed.timestamp,\n eventId: parsed.eventId.trim(),\n };\n } catch {\n return null;\n }\n}\n\nexport function isAfterCursor(\n event: Pick<DomainEvent, \"timestamp\" | \"eventId\">,\n cursor: EventCursor | null\n): boolean {\n if (!cursor) {\n return true;\n }\n return compareEventCursor(event, cursor) > 0;\n}\n\nexport function sortEventsByCursor<T extends Pick<DomainEvent, \"timestamp\" | \"eventId\">>(\n events: readonly T[]\n): T[] {\n return [...events].sort((left, right) => compareEventCursor(left, right));\n}\n\nexport function inferActorType(args: {\n sessionType?: \"agent\" | \"user\";\n authMode?: string;\n principalType?: string;\n}): DomainActorType {\n if (args.sessionType === \"agent\") {\n return \"agent\";\n }\n if (\n args.authMode === \"service_principal\" ||\n args.authMode === \"tenant_api_key\" ||\n args.principalType === \"service\"\n ) {\n return \"service\";\n }\n return \"human\";\n}\n\nexport async function emitDomainEvent(\n invokeMutation: (reference: any, args: CreateDomainEventInput) => Promise<unknown>,\n input: CreateDomainEventInput\n): Promise<unknown> {\n return await invokeMutation(\"events:recordEvent\" as any, input);\n}\n"]}
@@ -40,15 +40,16 @@ var DOMAIN_EVENT_TYPES = [
40
40
  "identity.key_revoked",
41
41
  "webhook.test"
42
42
  ];
43
+ var RUNTIME_BUFFER = globalThis.Buffer;
43
44
  function toBase64(value) {
44
- if (typeof Buffer !== "undefined") {
45
- return Buffer.from(value, "utf8").toString("base64url");
45
+ if (typeof RUNTIME_BUFFER !== "undefined") {
46
+ return RUNTIME_BUFFER.from(value, "utf8").toString("base64url");
46
47
  }
47
48
  return btoa(unescape(encodeURIComponent(value))).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/g, "");
48
49
  }
49
50
  function fromBase64(value) {
50
- if (typeof Buffer !== "undefined") {
51
- return Buffer.from(value, "base64url").toString("utf8");
51
+ if (typeof RUNTIME_BUFFER !== "undefined") {
52
+ return RUNTIME_BUFFER.from(value, "base64url").toString("utf8");
52
53
  }
53
54
  const normalized = value.replace(/-/g, "+").replace(/_/g, "/");
54
55
  return decodeURIComponent(escape(atob(normalized)));
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/events.contract.ts"],"names":[],"mappings":";AAiBO,IAAM,oBAAA,GAAuB;AAC7B,IAAM,4BAAA,GAA+B;AACrC,IAAM,oBAAA,GAAuB;AAC7B,IAAM,uBAAA,GAA0B,CAAC,GAAA,EAAO,GAAA,EAAO,KAAQ,GAAO;AAE9D,IAAM,kBAAA,GAAqB;AAAA,EAChC,gBAAA;AAAA,EACA,eAAA;AAAA,EACA,2BAAA;AAAA,EACA,iBAAA;AAAA,EACA,gBAAA;AAAA,EACA,yBAAA;AAAA,EACA,2BAAA;AAAA,EACA,wBAAA;AAAA,EACA,kBAAA;AAAA,EACA,iBAAA;AAAA,EACA,0BAAA;AAAA,EACA,kBAAA;AAAA,EACA,mBAAA;AAAA,EACA,kBAAA;AAAA,EACA,yBAAA;AAAA,EACA,mBAAA;AAAA,EACA,cAAA;AAAA,EACA,uBAAA;AAAA,EACA,kBAAA;AAAA,EACA,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AAA;AAC7C;AAEO,SAAS,mBACd,MAAA,EACK;AACL,EAAA,OAAO,CAAC,GAAG,MAAM,CAAA,CAAE,IAAA,CAAK,CAAC,IAAA,EAAM,KAAA,KAAU,kBAAA,CAAmB,IAAA,EAAM,KAAK,CAAC,CAAA;AAC1E;AAEO,SAAS,eAAe,IAAA,EAIX;AAClB,EAAA,IAAI,IAAA,CAAK,gBAAgB,OAAA,EAAS;AAChC,IAAA,OAAO,OAAA;AAAA,EACT;AACA,EAAA,IACE,IAAA,CAAK,aAAa,mBAAA,IAClB,IAAA,CAAK,aAAa,gBAAA,IAClB,IAAA,CAAK,kBAAkB,SAAA,EACvB;AACA,IAAA,OAAO,SAAA;AAAA,EACT;AACA,EAAA,OAAO,OAAA;AACT;AAEA,eAAsB,eAAA,CACpB,gBACA,KAAA,EACkB;AAClB,EAAA,OAAO,MAAM,cAAA,CAAe,oBAAA,EAA6B,KAAK,CAAA;AAChE","file":"events.contract.js","sourcesContent":["/**\n * @lucern/contracts — events (canonical support contract)\n *\n * Consolidated flat support surface for Lucern's domain event stream:\n * - Event type definitions, constants, and shared enums\n * - Event construction + cursor helpers\n *\n * Consolidated from the former split type-definition module\n * and the prior src/events.contract.ts (helpers) in EK-16 T1 PR 3b.\n * Compat shim remains at the old events-types path until Lucern 1.0.0 (D12).\n */\n\n// =============================================================================\n// EVENT TYPE DEFINITIONS & CONSTANTS\n// (Formerly the split events type-definition module)\n// =============================================================================\n\nexport const DOMAIN_EVENT_VERSION = \"1.0\" as const;\nexport const EVENT_RETENTION_DEFAULT_DAYS = 30;\nexport const WEBHOOK_MAX_ATTEMPTS = 5;\nexport const WEBHOOK_RETRY_DELAYS_MS = [1_000, 5_000, 30_000, 300_000] as const;\n\nexport const DOMAIN_EVENT_TYPES = [\n \"belief.created\",\n \"belief.forked\",\n \"belief.confidence_updated\",\n \"belief.archived\",\n \"belief.refined\",\n \"belief.contract_created\",\n \"belief.contract_evaluated\",\n \"belief.lineage_queried\",\n \"evidence.created\",\n \"evidence.linked\",\n \"evidence.search_executed\",\n \"question.created\",\n \"question.answered\",\n \"question.refined\",\n \"question.status_updated\",\n \"question.archived\",\n \"edge.created\",\n \"contradiction.flagged\",\n \"worktree.created\",\n \"worktree.activated\",\n \"worktree.merged\",\n \"worktree.targets_updated\",\n \"worktree.metadata_updated\",\n \"topic.created\",\n \"topic.updated\",\n \"topic.archived\",\n \"task.created\",\n \"task.completed\",\n \"task.updated\",\n \"ontology.bound\",\n \"context.compiled\",\n \"identity.key_created\",\n \"identity.key_rotated\",\n \"identity.key_revoked\",\n \"webhook.test\",\n] as const;\n\nexport type DomainEventType = (typeof DOMAIN_EVENT_TYPES)[number];\n\nexport type DomainResourceType =\n | \"belief\"\n | \"evidence\"\n | \"question\"\n | \"edge\"\n | \"contradiction\"\n | \"worktree\"\n | \"topic\"\n | \"task\"\n | \"ontology\"\n | \"context\"\n | \"identity\"\n | \"webhook\";\n\nexport type DomainActorType = \"human\" | \"agent\" | \"service\";\n\nexport type DomainEventData = Record<string, unknown>;\n\nexport type DomainEvent = {\n eventId: string;\n type: DomainEventType | string;\n version: typeof DOMAIN_EVENT_VERSION;\n timestamp: number;\n tenantId?: string;\n workspaceId?: string;\n topicId: string;\n resourceId: string;\n resourceType: DomainResourceType | string;\n actorId: string;\n actorType: DomainActorType;\n data: DomainEventData;\n correlationId?: string;\n expiresAt: number;\n};\n\nexport type CreateDomainEventInput = {\n eventId?: string;\n timestamp?: number;\n tenantId?: string;\n workspaceId?: string;\n topicId: string;\n type: DomainEventType | string;\n resourceId: string;\n resourceType: DomainResourceType | string;\n actorId: string;\n actorType: DomainActorType;\n data?: DomainEventData;\n correlationId?: string;\n retentionDays?: number;\n};\n\nexport type EventCursor = {\n timestamp: number;\n eventId: string;\n};\n\nexport type EventListQuery = {\n topicId?: string;\n after?: string;\n types?: string[];\n startTime?: number;\n endTime?: number;\n limit?: number;\n};\n\nexport type EventListResult = {\n events: DomainEvent[];\n nextCursor: string | null;\n};\n\nexport type WebhookSecretMode = \"configured\";\n\nexport type WebhookRecord = {\n id: string;\n webhookId: string;\n tenantId?: string;\n workspaceId?: string;\n topicId?: string;\n url: string;\n events: string[];\n active: boolean;\n secretConfigured: boolean;\n createdAt: number;\n updatedAt: number;\n createdBy: string;\n updatedBy: string;\n lastDeliveryAt?: number;\n lastSuccessfulDeliveryAt?: number;\n};\n\nexport type WebhookCreateInput = {\n url: string;\n events: string[];\n secret: string;\n topicId?: string;\n active?: boolean;\n};\n\nexport type WebhookUpdateInput = {\n url?: string;\n events?: string[];\n secret?: string;\n topicId?: string | null;\n active?: boolean;\n};\n\nexport type WebhookDeliveryStatus =\n | \"pending\"\n | \"delivering\"\n | \"succeeded\"\n | \"failed\"\n | \"dead_letter\";\n\nexport type WebhookDeliveryRecord = {\n id: string;\n deliveryId: string;\n webhookId: string;\n eventId: string;\n eventType: string;\n topicId: string;\n status: WebhookDeliveryStatus;\n attemptCount: number;\n maxAttempts: number;\n nextAttemptAt?: number;\n lastAttemptAt?: number;\n lastStatusCode?: number;\n lastError?: string;\n deliveredAt?: number;\n createdAt: number;\n updatedAt: number;\n};\n\nexport type WebhookDeliveryAttemptRecord = {\n id: string;\n attemptId: string;\n deliveryId: string;\n webhookId: string;\n eventId: string;\n eventType: string;\n attemptNumber: number;\n status: \"succeeded\" | \"failed\";\n statusCode?: number;\n error?: string;\n responseBody?: string;\n durationMs?: number;\n createdAt: number;\n};\n\nexport type WebhookDeliveriesResult = {\n deliveries: Array<\n WebhookDeliveryRecord & {\n attempts?: WebhookDeliveryAttemptRecord[];\n }\n >;\n};\n\nexport type WebhookHealthResult = {\n webhookId: string;\n totalAttempts: number;\n successfulAttempts: number;\n failedAttempts: number;\n successRate: number;\n pendingDeliveries: number;\n deadLetterDeliveries: number;\n lastDeliveryAt?: number;\n lastSuccessfulDeliveryAt?: number;\n};\n\nexport type WebhookTestResult = {\n webhookId: string;\n deliveryId: string;\n status: WebhookDeliveryStatus;\n attempts: number;\n};\n\nexport type ReplayEventsInput = EventListQuery & {\n webhookId?: string;\n};\n\nexport type ReplayEventsResult = EventListResult & {\n replayedDeliveries?: number;\n replayedWebhookId?: string;\n};\n\n// =============================================================================\n// EVENT HELPERS\n// (Formerly the body of src/events.contract.ts)\n// =============================================================================\n\nfunction toBase64(value: string): string {\n if (typeof Buffer !== \"undefined\") {\n return Buffer.from(value, \"utf8\").toString(\"base64url\");\n }\n return btoa(unescape(encodeURIComponent(value)))\n .replace(/\\+/g, \"-\")\n .replace(/\\//g, \"_\")\n .replace(/=+$/g, \"\");\n}\n\nfunction fromBase64(value: string): string {\n if (typeof Buffer !== \"undefined\") {\n return Buffer.from(value, \"base64url\").toString(\"utf8\");\n }\n const normalized = value.replace(/-/g, \"+\").replace(/_/g, \"/\");\n return decodeURIComponent(escape(atob(normalized)));\n}\n\nexport function createEventId(): string {\n const random = crypto.randomUUID().replace(/-/g, \"\");\n return `evt_${random}`;\n}\n\nexport function normalizeRetentionDays(value: number | undefined): number {\n if (!Number.isFinite(value) || typeof value !== \"number\" || value <= 0) {\n return EVENT_RETENTION_DEFAULT_DAYS;\n }\n return Math.max(1, Math.trunc(value));\n}\n\nexport function buildDomainEvent(input: CreateDomainEventInput): DomainEvent {\n const timestamp = input.timestamp ?? Date.now();\n const retentionDays = normalizeRetentionDays(input.retentionDays);\n return {\n eventId: input.eventId?.trim() || createEventId(),\n type: input.type.trim(),\n version: DOMAIN_EVENT_VERSION,\n timestamp,\n tenantId: input.tenantId?.trim() || undefined,\n workspaceId: input.workspaceId?.trim() || undefined,\n topicId: input.topicId.trim(),\n resourceId: input.resourceId.trim(),\n resourceType: input.resourceType.trim(),\n actorId: input.actorId.trim(),\n actorType: input.actorType,\n data: input.data ?? {},\n correlationId: input.correlationId?.trim() || undefined,\n expiresAt: timestamp + retentionDays * 24 * 60 * 60 * 1000,\n };\n}\n\nexport function compareEventCursor(left: EventCursor, right: EventCursor): number {\n if (left.timestamp !== right.timestamp) {\n return left.timestamp - right.timestamp;\n }\n return left.eventId.localeCompare(right.eventId);\n}\n\nexport function encodeEventCursor(cursor: EventCursor): string {\n return toBase64(JSON.stringify(cursor));\n}\n\nexport function decodeEventCursor(cursor: string | undefined): EventCursor | null {\n if (!cursor || cursor.trim().length === 0) {\n return null;\n }\n try {\n const parsed = JSON.parse(fromBase64(cursor.trim())) as Partial<EventCursor>;\n if (\n typeof parsed.timestamp !== \"number\" ||\n !Number.isFinite(parsed.timestamp) ||\n typeof parsed.eventId !== \"string\" ||\n parsed.eventId.trim().length === 0\n ) {\n return null;\n }\n return {\n timestamp: parsed.timestamp,\n eventId: parsed.eventId.trim(),\n };\n } catch {\n return null;\n }\n}\n\nexport function isAfterCursor(\n event: Pick<DomainEvent, \"timestamp\" | \"eventId\">,\n cursor: EventCursor | null\n): boolean {\n if (!cursor) {\n return true;\n }\n return compareEventCursor(event, cursor) > 0;\n}\n\nexport function sortEventsByCursor<T extends Pick<DomainEvent, \"timestamp\" | \"eventId\">>(\n events: readonly T[]\n): T[] {\n return [...events].sort((left, right) => compareEventCursor(left, right));\n}\n\nexport function inferActorType(args: {\n sessionType?: \"agent\" | \"user\";\n authMode?: string;\n principalType?: string;\n}): DomainActorType {\n if (args.sessionType === \"agent\") {\n return \"agent\";\n }\n if (\n args.authMode === \"service_principal\" ||\n args.authMode === \"tenant_api_key\" ||\n args.principalType === \"service\"\n ) {\n return \"service\";\n }\n return \"human\";\n}\n\nexport async function emitDomainEvent(\n invokeMutation: (reference: any, args: CreateDomainEventInput) => Promise<unknown>,\n input: CreateDomainEventInput\n): Promise<unknown> {\n return await invokeMutation(\"events:recordEvent\" as any, input);\n}\n"]}
1
+ {"version":3,"sources":["../src/events.contract.ts"],"names":[],"mappings":";AAiBO,IAAM,oBAAA,GAAuB;AAC7B,IAAM,4BAAA,GAA+B;AACrC,IAAM,oBAAA,GAAuB;AAC7B,IAAM,uBAAA,GAA0B,CAAC,GAAA,EAAO,GAAA,EAAO,KAAQ,GAAO;AAE9D,IAAM,kBAAA,GAAqB;AAAA,EACh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A,OAAO,IAAA;AAAA,IACT;AACA,IAAA,OAAO;AAAA,MACL,WAAW,MAAA,CAAO,SAAA;AAAA,MAClB,OAAA,EAAS,MAAA,CAAO,OAAA,CAAQ,IAAA;AAAK,KAC/B;AAAA,EACF,CAAA,CAAA,MAAQ;AACN,IAAA,OAAO,IAAA;AAAA,EACT;AACF;AAEO,SAAS,aAAA,CACd,OACA,MAAA,EACS;AACT,EAAA,IAAI,CAAC,MAAA,EAAQ;AACX,IAAA,OAAO,IAAA;AAAA,EACT;AACA,EAAA,OAAO,kBAAA,CAAmB,KAAA,EAAO,MAAM,CAAA,GAAI,CAAA;AAC7C;AAEO,SAAS,mBACd,MAAA,EACK;AACL,EAAA,OAAO,CAAC,GAAG,MAAM,CAAA,CAAE,IAAA,CAAK,CAAC,IAAA,EAAM,KAAA,KAAU,kBAAA,CAAmB,IAAA,EAAM,KAAK,CAAC,CAAA;AAC1E;AAEO,SAAS,eAAe,IAAA,EAIX;AAClB,EAAA,IAAI,IAAA,CAAK,gBAAgB,OAAA,EAAS;AAChC,IAAA,OAAO,OAAA;AAAA,EACT;AACA,EAAA,IACE,IAAA,CAAK,aAAa,mBAAA,IAClB,IAAA,CAAK,aAAa,gBAAA,IAClB,IAAA,CAAK,kBAAkB,SAAA,EACvB;AACA,IAAA,OAAO,SAAA;AAAA,EACT;AACA,EAAA,OAAO,OAAA;AACT;AAEA,eAAsB,eAAA,CACpB,gBACA,KAAA,EACkB;AAClB,EAAA,OAAO,MAAM,cAAA,CAAe,oBAAA,EAA6B,KAAK,CAAA;AAChE","file":"events.contract.js","sourcesContent":["/**\n * @lucern/contracts — events (canonical support contract)\n *\n * Consolidated flat support surface for Lucern's domain event stream:\n * - Event type definitions, constants, and shared enums\n * - Event construction + cursor helpers\n *\n * Consolidated from the former split type-definition module\n * and the prior src/events.contract.ts (helpers) in EK-16 T1 PR 3b.\n * Compat shim remains at the old events-types path until Lucern 1.0.0 (D12).\n */\n\n// =============================================================================\n// EVENT TYPE DEFINITIONS & CONSTANTS\n// (Formerly the split events type-definition module)\n// =============================================================================\n\nexport const DOMAIN_EVENT_VERSION = \"1.0\" as const;\nexport const EVENT_RETENTION_DEFAULT_DAYS = 30;\nexport const WEBHOOK_MAX_ATTEMPTS = 5;\nexport const WEBHOOK_RETRY_DELAYS_MS = [1_000, 5_000, 30_000, 300_000] as const;\n\nexport const DOMAIN_EVENT_TYPES = [\n \"belief.created\",\n \"belief.forked\",\n \"belief.confidence_updated\",\n \"belief.archived\",\n \"belief.refined\",\n \"belief.contract_created\",\n \"belief.contract_evaluated\",\n \"belief.lineage_queried\",\n \"evidence.created\",\n \"evidence.linked\",\n \"evidence.search_executed\",\n \"question.created\",\n \"question.answered\",\n \"question.refined\",\n \"question.status_updated\",\n \"question.archived\",\n \"edge.created\",\n \"contradiction.flagged\",\n \"worktree.created\",\n \"worktree.activated\",\n \"worktree.merged\",\n \"worktree.targets_updated\",\n \"worktree.metadata_updated\",\n \"topic.created\",\n \"topic.updated\",\n \"topic.archived\",\n \"task.created\",\n \"task.completed\",\n \"task.updated\",\n \"ontology.bound\",\n \"context.compiled\",\n \"identity.key_created\",\n \"identity.key_rotated\",\n \"identity.key_revoked\",\n \"webhook.test\",\n] as const;\n\nexport type DomainEventType = (typeof DOMAIN_EVENT_TYPES)[number];\n\nexport type DomainResourceType =\n | \"belief\"\n | \"evidence\"\n | \"question\"\n | \"edge\"\n | \"contradiction\"\n | \"worktree\"\n | \"topic\"\n | \"task\"\n | \"ontology\"\n | \"context\"\n | \"identity\"\n | \"webhook\";\n\nexport type DomainActorType = \"human\" | \"agent\" | \"service\";\n\nexport type DomainEventData = Record<string, unknown>;\n\nexport type DomainEvent = {\n eventId: string;\n type: DomainEventType | string;\n version: typeof DOMAIN_EVENT_VERSION;\n timestamp: number;\n tenantId?: string;\n workspaceId?: string;\n topicId: string;\n resourceId: string;\n resourceType: DomainResourceType | string;\n actorId: string;\n actorType: DomainActorType;\n data: DomainEventData;\n correlationId?: string;\n expiresAt: number;\n};\n\nexport type CreateDomainEventInput = {\n eventId?: string;\n timestamp?: number;\n tenantId?: string;\n workspaceId?: string;\n topicId: string;\n type: DomainEventType | string;\n resourceId: string;\n resourceType: DomainResourceType | string;\n actorId: string;\n actorType: DomainActorType;\n data?: DomainEventData;\n correlationId?: string;\n retentionDays?: number;\n};\n\nexport type EventCursor = {\n timestamp: number;\n eventId: string;\n};\n\nexport type EventListQuery = {\n topicId?: string;\n after?: string;\n types?: string[];\n startTime?: number;\n endTime?: number;\n limit?: number;\n};\n\nexport type EventListResult = {\n events: DomainEvent[];\n nextCursor: string | null;\n};\n\nexport type WebhookSecretMode = \"configured\";\n\nexport type WebhookRecord = {\n id: string;\n webhookId: string;\n tenantId?: string;\n workspaceId?: string;\n topicId?: string;\n url: string;\n events: string[];\n active: boolean;\n secretConfigured: boolean;\n createdAt: number;\n updatedAt: number;\n createdBy: string;\n updatedBy: string;\n lastDeliveryAt?: number;\n lastSuccessfulDeliveryAt?: number;\n};\n\nexport type WebhookCreateInput = {\n url: string;\n events: string[];\n secret: string;\n topicId?: string;\n active?: boolean;\n};\n\nexport type WebhookUpdateInput = {\n url?: string;\n events?: string[];\n secret?: string;\n topicId?: string | null;\n active?: boolean;\n};\n\nexport type WebhookDeliveryStatus =\n | \"pending\"\n | \"delivering\"\n | \"succeeded\"\n | \"failed\"\n | \"dead_letter\";\n\nexport type WebhookDeliveryRecord = {\n id: string;\n deliveryId: string;\n webhookId: string;\n eventId: string;\n eventType: string;\n topicId: string;\n status: WebhookDeliveryStatus;\n attemptCount: number;\n maxAttempts: number;\n nextAttemptAt?: number;\n lastAttemptAt?: number;\n lastStatusCode?: number;\n lastError?: string;\n deliveredAt?: number;\n createdAt: number;\n updatedAt: number;\n};\n\nexport type WebhookDeliveryAttemptRecord = {\n id: string;\n attemptId: string;\n deliveryId: string;\n webhookId: string;\n eventId: string;\n eventType: string;\n attemptNumber: number;\n status: \"succeeded\" | \"failed\";\n statusCode?: number;\n error?: string;\n responseBody?: string;\n durationMs?: number;\n createdAt: number;\n};\n\nexport type WebhookDeliveriesResult = {\n deliveries: Array<\n WebhookDeliveryRecord & {\n attempts?: WebhookDeliveryAttemptRecord[];\n }\n >;\n};\n\nexport type WebhookHealthResult = {\n webhookId: string;\n totalAttempts: number;\n successfulAttempts: number;\n failedAttempts: number;\n successRate: number;\n pendingDeliveries: number;\n deadLetterDeliveries: number;\n lastDeliveryAt?: number;\n lastSuccessfulDeliveryAt?: number;\n};\n\nexport type WebhookTestResult = {\n webhookId: string;\n deliveryId: string;\n status: WebhookDeliveryStatus;\n attempts: number;\n};\n\nexport type ReplayEventsInput = EventListQuery & {\n webhookId?: string;\n};\n\nexport type ReplayEventsResult = EventListResult & {\n replayedDeliveries?: number;\n replayedWebhookId?: string;\n};\n\nconst RUNTIME_BUFFER = (\n globalThis as typeof globalThis & {\n Buffer?: {\n from(\n value: string,\n encoding: \"utf8\" | \"base64url\"\n ): {\n toString(encoding: \"utf8\" | \"base64url\"): string;\n };\n };\n }\n).Buffer;\n\n// =============================================================================\n// EVENT HELPERS\n// (Formerly the body of src/events.contract.ts)\n// =============================================================================\n\nfunction toBase64(value: string): string {\n if (typeof RUNTIME_BUFFER !== \"undefined\") {\n return RUNTIME_BUFFER.from(value, \"utf8\").toString(\"base64url\");\n }\n return btoa(unescape(encodeURIComponent(value)))\n .replace(/\\+/g, \"-\")\n .replace(/\\//g, \"_\")\n .replace(/=+$/g, \"\");\n}\n\nfunction fromBase64(value: string): string {\n if (typeof RUNTIME_BUFFER !== \"undefined\") {\n return RUNTIME_BUFFER.from(value, \"base64url\").toString(\"utf8\");\n }\n const normalized = value.replace(/-/g, \"+\").replace(/_/g, \"/\");\n return decodeURIComponent(escape(atob(normalized)));\n}\n\nexport function createEventId(): string {\n const random = crypto.randomUUID().replace(/-/g, \"\");\n return `evt_${random}`;\n}\n\nexport function normalizeRetentionDays(value: number | undefined): number {\n if (!Number.isFinite(value) || typeof value !== \"number\" || value <= 0) {\n return EVENT_RETENTION_DEFAULT_DAYS;\n }\n return Math.max(1, Math.trunc(value));\n}\n\nexport function buildDomainEvent(input: CreateDomainEventInput): DomainEvent {\n const timestamp = input.timestamp ?? Date.now();\n const retentionDays = normalizeRetentionDays(input.retentionDays);\n return {\n eventId: input.eventId?.trim() || createEventId(),\n type: input.type.trim(),\n version: DOMAIN_EVENT_VERSION,\n timestamp,\n tenantId: input.tenantId?.trim() || undefined,\n workspaceId: input.workspaceId?.trim() || undefined,\n topicId: input.topicId.trim(),\n resourceId: input.resourceId.trim(),\n resourceType: input.resourceType.trim(),\n actorId: input.actorId.trim(),\n actorType: input.actorType,\n data: input.data ?? {},\n correlationId: input.correlationId?.trim() || undefined,\n expiresAt: timestamp + retentionDays * 24 * 60 * 60 * 1000,\n };\n}\n\nexport function compareEventCursor(left: EventCursor, right: EventCursor): number {\n if (left.timestamp !== right.timestamp) {\n return left.timestamp - right.timestamp;\n }\n return left.eventId.localeCompare(right.eventId);\n}\n\nexport function encodeEventCursor(cursor: EventCursor): string {\n return toBase64(JSON.stringify(cursor));\n}\n\nexport function decodeEventCursor(cursor: string | undefined): EventCursor | null {\n if (!cursor || cursor.trim().length === 0) {\n return null;\n }\n try {\n const parsed = JSON.parse(fromBase64(cursor.trim())) as Partial<EventCursor>;\n if (\n typeof parsed.timestamp !== \"number\" ||\n !Number.isFinite(parsed.timestamp) ||\n typeof parsed.eventId !== \"string\" ||\n parsed.eventId.trim().length === 0\n ) {\n return null;\n }\n return {\n timestamp: parsed.timestamp,\n eventId: parsed.eventId.trim(),\n };\n } catch {\n return null;\n }\n}\n\nexport function isAfterCursor(\n event: Pick<DomainEvent, \"timestamp\" | \"eventId\">,\n cursor: EventCursor | null\n): boolean {\n if (!cursor) {\n return true;\n }\n return compareEventCursor(event, cursor) > 0;\n}\n\nexport function sortEventsByCursor<T extends Pick<DomainEvent, \"timestamp\" | \"eventId\">>(\n events: readonly T[]\n): T[] {\n return [...events].sort((left, right) => compareEventCursor(left, right));\n}\n\nexport function inferActorType(args: {\n sessionType?: \"agent\" | \"user\";\n authMode?: string;\n principalType?: string;\n}): DomainActorType {\n if (args.sessionType === \"agent\") {\n return \"agent\";\n }\n if (\n args.authMode === \"service_principal\" ||\n args.authMode === \"tenant_api_key\" ||\n args.principalType === \"service\"\n ) {\n return \"service\";\n }\n return \"human\";\n}\n\nexport async function emitDomainEvent(\n invokeMutation: (reference: any, args: CreateDomainEventInput) => Promise<unknown>,\n input: CreateDomainEventInput\n): Promise<unknown> {\n return await invokeMutation(\"events:recordEvent\" as any, input);\n}\n"]}
@@ -0,0 +1,9 @@
1
+ type EpistemicLayer = "L4" | "L3" | "L2" | "L1" | "ontological" | "organizational";
2
+ declare const NODE_TYPE_TO_LABEL: Record<string, string>;
3
+ declare const EDGE_TYPE_TO_REL: Record<string, string>;
4
+ declare function getNodeLayer(nodeType: string): EpistemicLayer;
5
+ declare function getNeo4jLabel(nodeType: string): string;
6
+ declare function getNeo4jRelType(edgeType: string): string;
7
+ declare function isDeprecatedEdgeType(edgeType: string): boolean;
8
+
9
+ export { EDGE_TYPE_TO_REL, type EpistemicLayer, NODE_TYPE_TO_LABEL, getNeo4jLabel, getNeo4jRelType, getNodeLayer, isDeprecatedEdgeType };
@@ -0,0 +1,160 @@
1
+ // src/graph-types/index.ts
2
+ var NODE_TYPE_TO_LABEL = {
3
+ decision: "Decision",
4
+ belief: "Belief",
5
+ question: "Question",
6
+ theme: "Theme",
7
+ deal: "Deal",
8
+ topic: "Topic",
9
+ claim: "Claim",
10
+ evidence: "Evidence",
11
+ synthesis: "Synthesis",
12
+ answer: "Answer",
13
+ atomic_fact: "AtomicFact",
14
+ excerpt: "Excerpt",
15
+ source: "Source",
16
+ company: "Company",
17
+ person: "Person",
18
+ investor: "Investor",
19
+ function: "Function",
20
+ value_chain: "ValueChain"
21
+ };
22
+ var EDGE_TYPE_TO_REL = {
23
+ based_on_belief: "BASED_ON_BELIEF",
24
+ based_on_question: "BASED_ON_QUESTION",
25
+ blocked_by_contradiction: "BLOCKED_BY_CONTRADICTION",
26
+ informed_by_theme: "INFORMED_BY_THEME",
27
+ extracted_from: "EXTRACTED_FROM",
28
+ answers: "ANSWERS",
29
+ responds_to: "RESPONDS_TO",
30
+ informs: "INFORMS",
31
+ tests: "TESTS",
32
+ explores: "EXPLORES",
33
+ qualifies: "QUALIFIES",
34
+ based_on: "BASED_ON",
35
+ relates_to_thesis: "RELATES_TO_THESIS",
36
+ belongs_to: "BELONGS_TO",
37
+ plays_theme: "PLAYS_THEME",
38
+ scoped_by: "SCOPED_BY",
39
+ evaluates: "EVALUATES",
40
+ perspective_on: "PERSPECTIVE_ON",
41
+ works_at: "WORKS_AT",
42
+ participates_in: "PARTICIPATES_IN",
43
+ performs: "PERFORMS",
44
+ function_in: "FUNCTION_IN",
45
+ impacts: "IMPACTS",
46
+ invested_in: "INVESTED_IN",
47
+ raised_from: "RAISED_FROM",
48
+ founded_by: "FOUNDED_BY",
49
+ mentioned_in: "MENTIONED_IN",
50
+ supersedes: "SUPERSEDES",
51
+ same_as: "SAME_AS",
52
+ depends_on: "DEPENDS_ON",
53
+ reinforces: "REINFORCES",
54
+ parent_of: "PARENT_OF",
55
+ child_of: "CHILD_OF",
56
+ counterfactual_of: "COUNTERFACTUAL_OF",
57
+ cascade_to: "CASCADE_TO",
58
+ mutually_exclusive: "MUTUALLY_EXCLUSIVE",
59
+ correlates_with: "CORRELATES_WITH",
60
+ amplifies: "AMPLIFIES",
61
+ precondition_for: "PRECONDITION_FOR",
62
+ in_tension_with: "IN_TENSION_WITH",
63
+ falsified_by: "FALSIFIED_BY",
64
+ exclusive_with: "EXCLUSIVE_WITH",
65
+ collapses_if: "COLLAPSES_IF",
66
+ cascade_from: "CASCADE_FROM",
67
+ strengthened_by: "STRENGTHENED_BY",
68
+ weakened_by: "WEAKENED_BY",
69
+ alternative_to: "ALTERNATIVE_TO",
70
+ subsumes: "SUBSUMES",
71
+ validated_by: "VALIDATED_BY",
72
+ required_for: "REQUIRED_FOR",
73
+ blocks: "BLOCKS",
74
+ prerequisite_for: "PREREQUISITE_FOR",
75
+ parallel_to: "PARALLEL_TO",
76
+ corroborates: "CORROBORATES",
77
+ extends: "EXTENDS",
78
+ same_source_as: "SAME_SOURCE_AS",
79
+ same_theme_as: "SAME_THEME_AS",
80
+ assumes: "ASSUMES",
81
+ would_predict: "WOULD_PREDICT",
82
+ analogous_to: "ANALOGOUS_TO",
83
+ independent_of: "INDEPENDENT_OF",
84
+ about_entity: "ABOUT_ENTITY",
85
+ entity_referenced_in: "ENTITY_REFERENCED_IN",
86
+ competes_with: "COMPETES_WITH",
87
+ contains: "CONTAINS",
88
+ implements: "IMPLEMENTS",
89
+ violates: "VIOLATES",
90
+ co_changes_with: "CO_CHANGES_WITH",
91
+ migrating_from: "MIGRATING_FROM",
92
+ migrating_to: "MIGRATING_TO",
93
+ supports: "SUPPORTS",
94
+ contradicts: "CONTRADICTS",
95
+ derived_from: "DERIVED_FROM",
96
+ cites: "CITES",
97
+ summarizes: "SUMMARIZES",
98
+ related_to: "RELATED_TO",
99
+ partially_answers: "PARTIALLY_ANSWERS",
100
+ refines: "REFINES",
101
+ branches_from: "BRANCHES_FROM"
102
+ };
103
+ function getNodeLayer(nodeType) {
104
+ const L4_TYPES = ["decision"];
105
+ const L3_TYPES = ["belief", "question", "theme", "deal"];
106
+ const L2_TYPES = ["claim", "evidence", "synthesis", "answer"];
107
+ const L1_TYPES = ["atomic_fact", "excerpt", "source"];
108
+ const ONTOLOGICAL_TYPES = [
109
+ "company",
110
+ "person",
111
+ "investor",
112
+ "function",
113
+ "value_chain"
114
+ ];
115
+ const ORGANIZATIONAL_TYPES = ["topic"];
116
+ if (L4_TYPES.includes(nodeType)) {
117
+ return "L4";
118
+ }
119
+ if (L3_TYPES.includes(nodeType)) {
120
+ return "L3";
121
+ }
122
+ if (L2_TYPES.includes(nodeType)) {
123
+ return "L2";
124
+ }
125
+ if (L1_TYPES.includes(nodeType)) {
126
+ return "L1";
127
+ }
128
+ if (ONTOLOGICAL_TYPES.includes(nodeType)) {
129
+ return "ontological";
130
+ }
131
+ if (ORGANIZATIONAL_TYPES.includes(nodeType)) {
132
+ return "organizational";
133
+ }
134
+ console.warn(`[GraphTypes] Unknown nodeType "${nodeType}", defaulting to L2`);
135
+ return "L2";
136
+ }
137
+ function getNeo4jLabel(nodeType) {
138
+ return NODE_TYPE_TO_LABEL[nodeType] || nodeType.charAt(0).toUpperCase() + nodeType.slice(1);
139
+ }
140
+ function getNeo4jRelType(edgeType) {
141
+ return EDGE_TYPE_TO_REL[edgeType] || edgeType.toUpperCase();
142
+ }
143
+ function isDeprecatedEdgeType(edgeType) {
144
+ const DEPRECATED = [
145
+ "supports",
146
+ "contradicts",
147
+ "derived_from",
148
+ "cites",
149
+ "summarizes",
150
+ "related_to",
151
+ "partially_answers",
152
+ "refines",
153
+ "branches_from"
154
+ ];
155
+ return DEPRECATED.includes(edgeType);
156
+ }
157
+
158
+ export { EDGE_TYPE_TO_REL, NODE_TYPE_TO_LABEL, getNeo4jLabel, getNeo4jRelType, getNodeLayer, isDeprecatedEdgeType };
159
+ //# sourceMappingURL=index.js.map
160
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/graph-types/index.ts"],"names":[],"mappings":";AAQO,IAAM,kBAAA,GAA6C;AAAA,EACxD,QAAA,EAAU,UAAA;AAAA,EACV,MAAA,EAAQ,QAAA;AAAA,EACR,QAAA,EAAU,UAAA;AAAA,EACV,KAAA,EAAO,OAAA;AAAA,EACP,IAAA,EAAM,MAAA;AAAA,EACN,KAAA,EAAO,OAAA;AAAA,EACP,KAAA,EAAO,OAAA;AAAA,EACP,QAAA,EAAU,UAAA;AAAA,EACV,SAAA,EAAW,WAAA;AAAA,EACX,MAAA,EAAQ,QAAA;AAAA,EACR,WAAA,EAAa,YAAA;AAAA,EACb,OAAA,EAAS,SAAA;AAAA,EACT,MAAA,EAAQ,QAAA;AAAA,EACR,OAAA,EAAS,SAAA;AAAA,EACT,MAAA,E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AAA;AACT;AAEO,SAAS,cAAc,QAAA,EAA0B;AACtD,EAAA,OACE,kBAAA,CAAmB,QAAQ,CAAA,IAC3B,QAAA,CAAS,MAAA,CAAO,CAAC,CAAA,CAAE,WAAA,EAAY,GAAI,QAAA,CAAS,KAAA,CAAM,CAAC,CAAA;AAEvD;AAEO,SAAS,gBAAgB,QAAA,EAA0B;AACxD,EAAA,OAAO,gBAAA,CAAiB,QAAQ,CAAA,IAAK,QAAA,CAAS,WAAA,EAAY;AAC5D;AAEO,SAAS,qBAAqB,QAAA,EAA2B;AAC9D,EAAA,MAAM,UAAA,GAAa;AAAA,IACjB,UAAA;AAAA,IACA,aAAA;AAAA,IACA,cAAA;AAAA,IACA,OAAA;AAAA,IACA,YAAA;AAAA,IACA,YAAA;AAAA,IACA,mBAAA;AAAA,IACA,SAAA;AAAA,IACA;AAAA,GACF;AACA,EAAA,OAAO,UAAA,CAAW,SAAS,QAAQ,CAAA;AACrC","file":"index.js","sourcesContent":["export type EpistemicLayer =\n | \"L4\"\n | \"L3\"\n | \"L2\"\n | \"L1\"\n | \"ontological\"\n | \"organizational\";\n\nexport const NODE_TYPE_TO_LABEL: Record<string, string> = {\n decision: \"Decision\",\n belief: \"Belief\",\n question: \"Question\",\n theme: \"Theme\",\n deal: \"Deal\",\n topic: \"Topic\",\n claim: \"Claim\",\n evidence: \"Evidence\",\n synthesis: \"Synthesis\",\n answer: \"Answer\",\n atomic_fact: \"AtomicFact\",\n excerpt: \"Excerpt\",\n source: \"Source\",\n company: \"Company\",\n person: \"Person\",\n investor: \"Investor\",\n function: \"Function\",\n value_chain: \"ValueChain\",\n};\n\nexport const EDGE_TYPE_TO_REL: Record<string, string> = {\n based_on_belief: \"BASED_ON_BELIEF\",\n based_on_question: \"BASED_ON_QUESTION\",\n blocked_by_contradiction: \"BLOCKED_BY_CONTRADICTION\",\n informed_by_theme: \"INFORMED_BY_THEME\",\n extracted_from: \"EXTRACTED_FROM\",\n answers: \"ANSWERS\",\n responds_to: \"RESPONDS_TO\",\n informs: \"INFORMS\",\n tests: \"TESTS\",\n explores: \"EXPLORES\",\n qualifies: \"QUALIFIES\",\n based_on: \"BASED_ON\",\n relates_to_thesis: \"RELATES_TO_THESIS\",\n belongs_to: \"BELONGS_TO\",\n plays_theme: \"PLAYS_THEME\",\n scoped_by: \"SCOPED_BY\",\n evaluates: \"EVALUATES\",\n perspective_on: \"PERSPECTIVE_ON\",\n works_at: \"WORKS_AT\",\n participates_in: \"PARTICIPATES_IN\",\n performs: \"PERFORMS\",\n function_in: \"FUNCTION_IN\",\n impacts: \"IMPACTS\",\n invested_in: \"INVESTED_IN\",\n raised_from: \"RAISED_FROM\",\n founded_by: \"FOUNDED_BY\",\n mentioned_in: \"MENTIONED_IN\",\n supersedes: \"SUPERSEDES\",\n same_as: \"SAME_AS\",\n depends_on: \"DEPENDS_ON\",\n reinforces: \"REINFORCES\",\n parent_of: \"PARENT_OF\",\n child_of: \"CHILD_OF\",\n counterfactual_of: \"COUNTERFACTUAL_OF\",\n cascade_to: \"CASCADE_TO\",\n mutually_exclusive: \"MUTUALLY_EXCLUSIVE\",\n correlates_with: \"CORRELATES_WITH\",\n amplifies: \"AMPLIFIES\",\n precondition_for: \"PRECONDITION_FOR\",\n in_tension_with: \"IN_TENSION_WITH\",\n falsified_by: \"FALSIFIED_BY\",\n exclusive_with: \"EXCLUSIVE_WITH\",\n collapses_if: \"COLLAPSES_IF\",\n cascade_from: \"CASCADE_FROM\",\n strengthened_by: \"STRENGTHENED_BY\",\n weakened_by: \"WEAKENED_BY\",\n alternative_to: \"ALTERNATIVE_TO\",\n subsumes: \"SUBSUMES\",\n validated_by: \"VALIDATED_BY\",\n required_for: \"REQUIRED_FOR\",\n blocks: \"BLOCKS\",\n prerequisite_for: \"PREREQUISITE_FOR\",\n parallel_to: \"PARALLEL_TO\",\n corroborates: \"CORROBORATES\",\n extends: \"EXTENDS\",\n same_source_as: \"SAME_SOURCE_AS\",\n same_theme_as: \"SAME_THEME_AS\",\n assumes: \"ASSUMES\",\n would_predict: \"WOULD_PREDICT\",\n analogous_to: \"ANALOGOUS_TO\",\n independent_of: \"INDEPENDENT_OF\",\n about_entity: \"ABOUT_ENTITY\",\n entity_referenced_in: \"ENTITY_REFERENCED_IN\",\n competes_with: \"COMPETES_WITH\",\n contains: \"CONTAINS\",\n implements: \"IMPLEMENTS\",\n violates: \"VIOLATES\",\n co_changes_with: \"CO_CHANGES_WITH\",\n migrating_from: \"MIGRATING_FROM\",\n migrating_to: \"MIGRATING_TO\",\n supports: \"SUPPORTS\",\n contradicts: \"CONTRADICTS\",\n derived_from: \"DERIVED_FROM\",\n cites: \"CITES\",\n summarizes: \"SUMMARIZES\",\n related_to: \"RELATED_TO\",\n partially_answers: \"PARTIALLY_ANSWERS\",\n refines: \"REFINES\",\n branches_from: \"BRANCHES_FROM\",\n};\n\nexport function getNodeLayer(nodeType: string): EpistemicLayer {\n const L4_TYPES = [\"decision\"];\n const L3_TYPES = [\"belief\", \"question\", \"theme\", \"deal\"];\n const L2_TYPES = [\"claim\", \"evidence\", \"synthesis\", \"answer\"];\n const L1_TYPES = [\"atomic_fact\", \"excerpt\", \"source\"];\n const ONTOLOGICAL_TYPES = [\n \"company\",\n \"person\",\n \"investor\",\n \"function\",\n \"value_chain\",\n ];\n const ORGANIZATIONAL_TYPES = [\"topic\"];\n\n if (L4_TYPES.includes(nodeType)) {\n return \"L4\";\n }\n if (L3_TYPES.includes(nodeType)) {\n return \"L3\";\n }\n if (L2_TYPES.includes(nodeType)) {\n return \"L2\";\n }\n if (L1_TYPES.includes(nodeType)) {\n return \"L1\";\n }\n if (ONTOLOGICAL_TYPES.includes(nodeType)) {\n return \"ontological\";\n }\n if (ORGANIZATIONAL_TYPES.includes(nodeType)) {\n return \"organizational\";\n }\n\n console.warn(`[GraphTypes] Unknown nodeType \"${nodeType}\", defaulting to L2`);\n return \"L2\";\n}\n\nexport function getNeo4jLabel(nodeType: string): string {\n return (\n NODE_TYPE_TO_LABEL[nodeType] ||\n nodeType.charAt(0).toUpperCase() + nodeType.slice(1)\n );\n}\n\nexport function getNeo4jRelType(edgeType: string): string {\n return EDGE_TYPE_TO_REL[edgeType] || edgeType.toUpperCase();\n}\n\nexport function isDeprecatedEdgeType(edgeType: string): boolean {\n const DEPRECATED = [\n \"supports\",\n \"contradicts\",\n \"derived_from\",\n \"cites\",\n \"summarizes\",\n \"related_to\",\n \"partially_answers\",\n \"refines\",\n \"branches_from\",\n ];\n return DEPRECATED.includes(edgeType);\n}\n"]}
@@ -0,0 +1,3 @@
1
+ declare function generateGlobalId(): string;
2
+
3
+ export { generateGlobalId };
@@ -0,0 +1,15 @@
1
+ // src/ids/index.ts
2
+ function generateGlobalId() {
3
+ const bytes = new Uint8Array(16);
4
+ crypto.getRandomValues(bytes);
5
+ bytes[6] = bytes[6] & 15 | 64;
6
+ bytes[8] = bytes[8] & 63 | 128;
7
+ const hex = Array.from(bytes, (b) => b.toString(16).padStart(2, "0")).join(
8
+ ""
9
+ );
10
+ return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
11
+ }
12
+
13
+ export { generateGlobalId };
14
+ //# sourceMappingURL=index.js.map
15
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/ids/index.ts"],"names":[],"mappings":";AAAO,SAAS,gBAAA,GAA2B;AACzC,EAAA,MAAM,KAAA,GAAQ,IAAI,UAAA,CAAW,EAAE,CAAA;AAC/B,EAAA,MAAA,CAAO,gBAAgB,KAAK,CAAA;AAC5B,EAAA,KAAA,CAAM,CAAC,CAAA,GAAK,KAAA,CAAM,CAAC,IAAI,EAAA,GAAQ,EAAA;AAC/B,EAAA,KAAA,CAAM,CAAC,CAAA,GAAK,KAAA,CAAM,CAAC,IAAI,EAAA,GAAQ,GAAA;AAC/B,EAAA,MAAM,GAAA,GAAM,KAAA,CAAM,IAAA,CAAK,KAAA,EAAO,CAAC,CAAA,KAAM,CAAA,CAAE,QAAA,CAAS,EAAE,CAAA,CAAE,QAAA,CAAS,CAAA,EAAG,GAAG,CAAC,CAAA,CAAE,IAAA;AAAA,IACpE;AAAA,GACF;AACA,EAAA,OAAO,CAAA,EAAG,GAAA,CAAI,KAAA,CAAM,CAAA,EAAG,CAAC,CAAC,CAAA,CAAA,EAAI,GAAA,CAAI,KAAA,CAAM,CAAA,EAAG,EAAE,CAAC,CAAA,CAAA,EAAI,GAAA,CAAI,KAAA,CAAM,EAAA,EAAI,EAAE,CAAC,CAAA,CAAA,EAAI,GAAA,CAAI,KAAA,CAAM,EAAA,EAAI,EAAE,CAAC,CAAA,CAAA,EAAI,GAAA,CAAI,KAAA,CAAM,EAAE,CAAC,CAAA,CAAA;AAC1G","file":"index.js","sourcesContent":["export function generateGlobalId(): string {\n const bytes = new Uint8Array(16);\n crypto.getRandomValues(bytes);\n bytes[6] = (bytes[6] & 0x0f) | 0x40;\n bytes[8] = (bytes[8] & 0x3f) | 0x80;\n const hex = Array.from(bytes, (b) => b.toString(16).padStart(2, \"0\")).join(\n \"\"\n );\n return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;\n}\n"]}