@makaio/framework 1.0.0-dev-1790348008233 → 1.0.0-dev-1790535947927

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 (93) hide show
  1. package/dist/.makaio-build.json +2 -2
  2. package/dist/adapters/claude/index.d.mts +24 -24
  3. package/dist/artifact-C4J_FDq8.mjs +1 -0
  4. package/dist/bus/index.mjs +1 -1
  5. package/dist/bus-DzEgIHGt.mjs +9 -0
  6. package/dist/clients/index.d.mts +5 -5
  7. package/dist/contracts/adapter/index.d.mts +2 -2
  8. package/dist/contracts/adapter/schemas/session-lineage.d.mts +1 -1
  9. package/dist/contracts/artifact/index.d.mts +3 -3
  10. package/dist/contracts/artifact/index.mjs +1 -1
  11. package/dist/contracts/automation-trigger/index.d.mts +1 -1
  12. package/dist/contracts/capabilities/index.d.mts +1 -1
  13. package/dist/contracts/client/index.d.mts +2 -2
  14. package/dist/contracts/extension/index.d.mts +5 -5
  15. package/dist/contracts/extension/index.mjs +1 -1
  16. package/dist/contracts/harness/index.d.mts +1 -1
  17. package/dist/contracts/index.d.mts +39 -39
  18. package/dist/contracts/index.mjs +1 -1
  19. package/dist/contracts/materialization/index.d.mts +2 -2
  20. package/dist/contracts/materialization/index.mjs +1 -1
  21. package/dist/contracts/native-session-supervisor/index.d.mts +1 -1
  22. package/dist/contracts/reaction/index.d.mts +1 -1
  23. package/dist/contracts/session/index.d.mts +2 -2
  24. package/dist/contracts/shared/index.d.mts +1 -1
  25. package/dist/contracts/variant/index.d.mts +1 -1
  26. package/dist/contracts/worker/index.d.mts +1 -1
  27. package/dist/contracts/worker/index.mjs +1 -1
  28. package/dist/contracts/workflow/index.d.mts +2 -2
  29. package/dist/contracts/workflow/index.mjs +1 -1
  30. package/dist/{contribution-kpR61mnG.d.mts → contribution-DTb65rRN.d.mts} +1 -1
  31. package/dist/{extension-C6ANjR33.mjs → extension-BOMfXdko.mjs} +1 -1
  32. package/dist/{extension-context-CmhBCbbq.d.mts → extension-context-DH84KOm9.d.mts} +3 -3
  33. package/dist/{hook-responses-C3nUIm-6.d.mts → hook-responses-OETFKaAL.d.mts} +1 -1
  34. package/dist/{index-C9Dz8UoK2.d.mts → index-2YW8DTb62.d.mts} +6 -6
  35. package/dist/{index-D5Lw1UsO.d.mts → index-B1iXL1pW.d.mts} +8 -8
  36. package/dist/{index-BMGkU3IM.d.mts → index-BRXETFym.d.mts} +1 -1
  37. package/dist/{index-DDCixELI.d.mts → index-BUxs65tf.d.mts} +1 -1
  38. package/dist/{index-HN4m0hiI.d.mts → index-BVN64wQx.d.mts} +28 -28
  39. package/dist/{index-D5ihXDAA.d.mts → index-Bc4u4rD8.d.mts} +5 -5
  40. package/dist/{index-Cuz4nfUz.d.mts → index-Bgz81LHZ.d.mts} +1 -1
  41. package/dist/{index-DifOjlJ5.d.mts → index-CEy4pCZ0.d.mts} +45 -45
  42. package/dist/{index-DMBxHEQ_.d.mts → index-CMsQnCAu.d.mts} +44 -44
  43. package/dist/{index-BM53WQaQ.d.mts → index-CVRQS5jk.d.mts} +1 -1
  44. package/dist/{index-wiATEDG_.d.mts → index-CWry0rks.d.mts} +394 -310
  45. package/dist/{index-6UlianLY2.d.mts → index-CnQw9he92.d.mts} +8 -8
  46. package/dist/{index-CydQ1dLS2.d.mts → index-DIOmmpkx2.d.mts} +6 -3
  47. package/dist/{index-DYnahvOm.d.mts → index-DPc-Lstu.d.mts} +96 -78
  48. package/dist/{index-D5BLD2Pw.d.mts → index-DqN1u0Y2.d.mts} +6 -6
  49. package/dist/{index-CCTrhWEB2.d.mts → index-DzOTNzZv2.d.mts} +6 -6
  50. package/dist/{index-wGlFWRXg.d.mts → index-aAo9ugCm.d.mts} +4 -4
  51. package/dist/{index-CRk46fit.d.mts → index-lSpH5lvV.d.mts} +9 -9
  52. package/dist/kernel/extension/index.d.mts +2 -2
  53. package/dist/kernel/index.d.mts +2 -2
  54. package/dist/kernel/observability/index.d.mts +1 -1
  55. package/dist/kind-registration-DdbhhvaT.mjs +1 -0
  56. package/dist/{materialization-CIrHHspa.mjs → materialization-CxV6fpuB.mjs} +1 -1
  57. package/dist/{namespace-C5tKjqgb.d.mts → namespace-B9iQN3FQ.d.mts} +4 -4
  58. package/dist/{namespace-D6W4Erwp.d.mts → namespace-DAzOxaux.d.mts} +2 -2
  59. package/dist/{package-BswWlFSn.d.mts → package-DT1Jaweg.d.mts} +2 -1
  60. package/dist/package.json +1 -1
  61. package/dist/{schemas-rliUGyrt.d.mts → schemas-B-2yBaGk.d.mts} +12 -8
  62. package/dist/{schemas-Cb9OJ9va.d.mts → schemas-CBDNnyz4.d.mts} +1 -1
  63. package/dist/{schemas-CYjPZwlQ.d.mts → schemas-Dec5VtBU.d.mts} +4 -4
  64. package/dist/schemas-W3nT06vH.mjs +1 -0
  65. package/dist/services/adapter-runtime/index.d.mts +3 -3
  66. package/dist/services/adapter-runtime/namespace.d.mts +1 -1
  67. package/dist/services/adapter-runtime/schemas.d.mts +1 -1
  68. package/dist/services/context-rules/index.d.mts +3 -3
  69. package/dist/services/filesystem/namespace.d.mts +12 -12
  70. package/dist/services/filesystem/schemas.d.mts +6 -6
  71. package/dist/services/git/namespace.d.mts +2 -2
  72. package/dist/services/git/schemas.d.mts +2 -2
  73. package/dist/services/harness/index.d.mts +3 -3
  74. package/dist/services/index.d.mts +19 -19
  75. package/dist/services/session/index.d.mts +2 -2
  76. package/dist/services/session/messages/namespace.d.mts +1 -1
  77. package/dist/services/settings/namespace.d.mts +4 -4
  78. package/dist/services/settings/storage/extension-configs/namespace.d.mts +3 -3
  79. package/dist/services/subagent-template/index.d.mts +1 -1
  80. package/dist/services/subagent-template/schemas.d.mts +1 -1
  81. package/dist/{session-lineage-CmP7L5g2.d.mts → session-lineage-BQ9NWlt6.d.mts} +1 -1
  82. package/dist/{transition-B0qsutdE.d.mts → transition-DH313MFE.d.mts} +1 -1
  83. package/dist/{types-DfbdwLQ6.d.mts → types-qna5Bcs8.d.mts} +4 -4
  84. package/dist/{view-builder-Zw-TCgSp.d.mts → view-builder-D6W7fBUv.d.mts} +7 -7
  85. package/dist/{worker-DyyO9DCO.mjs → worker-zHq43Iyk.mjs} +1 -1
  86. package/dist/{workflow-B0ZGun4r.mjs → workflow-BFAraH3Y.mjs} +1 -1
  87. package/dist/workflow-engine/index.d.mts +33 -33
  88. package/dist/workflow-engine/package.d.mts +1 -1
  89. package/package.json +1 -1
  90. package/dist/artifact-eleyznpA.mjs +0 -1
  91. package/dist/bus-DgpPEPoM.mjs +0 -9
  92. package/dist/kind-registration-Dzfo6kyb.mjs +0 -1
  93. package/dist/schemas-CHM0wMq4.mjs +0 -1
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 1,
3
- "fingerprint": "8ea93b37dcbf14e96e9387ea030f60915416a78a60cb7bc143c9cb54bdcc8b12",
4
- "builtAt": "2026-09-25T14:54:37.684Z",
3
+ "fingerprint": "998dbff5cb2be19989f0dbeedde8c3aa24d3e5252263c89a396781b27c840b26",
4
+ "builtAt": "2026-09-27T19:06:52.328Z",
5
5
  "declarations": true,
6
6
  "declarationBackend": "tsc"
7
7
  }
@@ -4993,16 +4993,16 @@ declare function createClaudeConnectorNamespace<N extends string>(namespaceName:
4993
4993
  adapterId: z.ZodString;
4994
4994
  agentId: z.ZodString;
4995
4995
  oldState: z.ZodEnum<{
4996
- idle: "idle";
4997
4996
  paused: "paused";
4997
+ idle: "idle";
4998
4998
  turn_started: "turn_started";
4999
4999
  step_started: "step_started";
5000
5000
  step_finished: "step_finished";
5001
5001
  turn_finished: "turn_finished";
5002
5002
  }>;
5003
5003
  newState: z.ZodEnum<{
5004
- idle: "idle";
5005
5004
  paused: "paused";
5005
+ idle: "idle";
5006
5006
  turn_started: "turn_started";
5007
5007
  step_started: "step_started";
5008
5008
  step_finished: "step_finished";
@@ -5014,16 +5014,16 @@ declare function createClaudeConnectorNamespace<N extends string>(namespaceName:
5014
5014
  adapterId: z.ZodString;
5015
5015
  agentId: z.ZodString;
5016
5016
  oldState: z.ZodEnum<{
5017
- idle: "idle";
5018
5017
  paused: "paused";
5018
+ idle: "idle";
5019
5019
  turn_started: "turn_started";
5020
5020
  step_started: "step_started";
5021
5021
  step_finished: "step_finished";
5022
5022
  turn_finished: "turn_finished";
5023
5023
  }>;
5024
5024
  newState: z.ZodEnum<{
5025
- idle: "idle";
5026
5025
  paused: "paused";
5026
+ idle: "idle";
5027
5027
  turn_started: "turn_started";
5028
5028
  step_started: "step_started";
5029
5029
  step_finished: "step_finished";
@@ -5035,16 +5035,16 @@ declare function createClaudeConnectorNamespace<N extends string>(namespaceName:
5035
5035
  adapterId: z.ZodString;
5036
5036
  agentId: z.ZodString;
5037
5037
  oldState: z.ZodEnum<{
5038
- idle: "idle";
5039
5038
  paused: "paused";
5039
+ idle: "idle";
5040
5040
  turn_started: "turn_started";
5041
5041
  step_started: "step_started";
5042
5042
  step_finished: "step_finished";
5043
5043
  turn_finished: "turn_finished";
5044
5044
  }>;
5045
5045
  newState: z.ZodEnum<{
5046
- idle: "idle";
5047
5046
  paused: "paused";
5047
+ idle: "idle";
5048
5048
  turn_started: "turn_started";
5049
5049
  step_started: "step_started";
5050
5050
  step_finished: "step_finished";
@@ -5056,16 +5056,16 @@ declare function createClaudeConnectorNamespace<N extends string>(namespaceName:
5056
5056
  adapterId: z.ZodString;
5057
5057
  agentId: z.ZodString;
5058
5058
  oldState: z.ZodEnum<{
5059
- idle: "idle";
5060
5059
  paused: "paused";
5060
+ idle: "idle";
5061
5061
  turn_started: "turn_started";
5062
5062
  step_started: "step_started";
5063
5063
  step_finished: "step_finished";
5064
5064
  turn_finished: "turn_finished";
5065
5065
  }>;
5066
5066
  newState: z.ZodEnum<{
5067
- idle: "idle";
5068
5067
  paused: "paused";
5068
+ idle: "idle";
5069
5069
  turn_started: "turn_started";
5070
5070
  step_started: "step_started";
5071
5071
  step_finished: "step_finished";
@@ -5077,16 +5077,16 @@ declare function createClaudeConnectorNamespace<N extends string>(namespaceName:
5077
5077
  adapterId: z.ZodString;
5078
5078
  agentId: z.ZodString;
5079
5079
  oldState: z.ZodEnum<{
5080
- idle: "idle";
5081
5080
  paused: "paused";
5081
+ idle: "idle";
5082
5082
  turn_started: "turn_started";
5083
5083
  step_started: "step_started";
5084
5084
  step_finished: "step_finished";
5085
5085
  turn_finished: "turn_finished";
5086
5086
  }>;
5087
5087
  newState: z.ZodEnum<{
5088
- idle: "idle";
5089
5088
  paused: "paused";
5089
+ idle: "idle";
5090
5090
  turn_started: "turn_started";
5091
5091
  step_started: "step_started";
5092
5092
  step_finished: "step_finished";
@@ -5098,16 +5098,16 @@ declare function createClaudeConnectorNamespace<N extends string>(namespaceName:
5098
5098
  adapterId: z.ZodString;
5099
5099
  agentId: z.ZodString;
5100
5100
  oldState: z.ZodEnum<{
5101
- idle: "idle";
5102
5101
  paused: "paused";
5102
+ idle: "idle";
5103
5103
  turn_started: "turn_started";
5104
5104
  step_started: "step_started";
5105
5105
  step_finished: "step_finished";
5106
5106
  turn_finished: "turn_finished";
5107
5107
  }>;
5108
5108
  newState: z.ZodEnum<{
5109
- idle: "idle";
5110
5109
  paused: "paused";
5110
+ idle: "idle";
5111
5111
  turn_started: "turn_started";
5112
5112
  step_started: "step_started";
5113
5113
  step_finished: "step_finished";
@@ -7620,16 +7620,16 @@ declare function createClaudeConnectorNamespace<N extends string>(namespaceName:
7620
7620
  adapterId: z.ZodString;
7621
7621
  agentId: z.ZodString;
7622
7622
  oldState: z.ZodEnum<{
7623
- idle: "idle";
7624
7623
  paused: "paused";
7624
+ idle: "idle";
7625
7625
  turn_started: "turn_started";
7626
7626
  step_started: "step_started";
7627
7627
  step_finished: "step_finished";
7628
7628
  turn_finished: "turn_finished";
7629
7629
  }>;
7630
7630
  newState: z.ZodEnum<{
7631
- idle: "idle";
7632
7631
  paused: "paused";
7632
+ idle: "idle";
7633
7633
  turn_started: "turn_started";
7634
7634
  step_started: "step_started";
7635
7635
  step_finished: "step_finished";
@@ -7641,16 +7641,16 @@ declare function createClaudeConnectorNamespace<N extends string>(namespaceName:
7641
7641
  adapterId: z.ZodString;
7642
7642
  agentId: z.ZodString;
7643
7643
  oldState: z.ZodEnum<{
7644
- idle: "idle";
7645
7644
  paused: "paused";
7645
+ idle: "idle";
7646
7646
  turn_started: "turn_started";
7647
7647
  step_started: "step_started";
7648
7648
  step_finished: "step_finished";
7649
7649
  turn_finished: "turn_finished";
7650
7650
  }>;
7651
7651
  newState: z.ZodEnum<{
7652
- idle: "idle";
7653
7652
  paused: "paused";
7653
+ idle: "idle";
7654
7654
  turn_started: "turn_started";
7655
7655
  step_started: "step_started";
7656
7656
  step_finished: "step_finished";
@@ -7662,16 +7662,16 @@ declare function createClaudeConnectorNamespace<N extends string>(namespaceName:
7662
7662
  adapterId: z.ZodString;
7663
7663
  agentId: z.ZodString;
7664
7664
  oldState: z.ZodEnum<{
7665
- idle: "idle";
7666
7665
  paused: "paused";
7666
+ idle: "idle";
7667
7667
  turn_started: "turn_started";
7668
7668
  step_started: "step_started";
7669
7669
  step_finished: "step_finished";
7670
7670
  turn_finished: "turn_finished";
7671
7671
  }>;
7672
7672
  newState: z.ZodEnum<{
7673
- idle: "idle";
7674
7673
  paused: "paused";
7674
+ idle: "idle";
7675
7675
  turn_started: "turn_started";
7676
7676
  step_started: "step_started";
7677
7677
  step_finished: "step_finished";
@@ -7683,16 +7683,16 @@ declare function createClaudeConnectorNamespace<N extends string>(namespaceName:
7683
7683
  adapterId: z.ZodString;
7684
7684
  agentId: z.ZodString;
7685
7685
  oldState: z.ZodEnum<{
7686
- idle: "idle";
7687
7686
  paused: "paused";
7687
+ idle: "idle";
7688
7688
  turn_started: "turn_started";
7689
7689
  step_started: "step_started";
7690
7690
  step_finished: "step_finished";
7691
7691
  turn_finished: "turn_finished";
7692
7692
  }>;
7693
7693
  newState: z.ZodEnum<{
7694
- idle: "idle";
7695
7694
  paused: "paused";
7695
+ idle: "idle";
7696
7696
  turn_started: "turn_started";
7697
7697
  step_started: "step_started";
7698
7698
  step_finished: "step_finished";
@@ -7704,16 +7704,16 @@ declare function createClaudeConnectorNamespace<N extends string>(namespaceName:
7704
7704
  adapterId: z.ZodString;
7705
7705
  agentId: z.ZodString;
7706
7706
  oldState: z.ZodEnum<{
7707
- idle: "idle";
7708
7707
  paused: "paused";
7708
+ idle: "idle";
7709
7709
  turn_started: "turn_started";
7710
7710
  step_started: "step_started";
7711
7711
  step_finished: "step_finished";
7712
7712
  turn_finished: "turn_finished";
7713
7713
  }>;
7714
7714
  newState: z.ZodEnum<{
7715
- idle: "idle";
7716
7715
  paused: "paused";
7716
+ idle: "idle";
7717
7717
  turn_started: "turn_started";
7718
7718
  step_started: "step_started";
7719
7719
  step_finished: "step_finished";
@@ -7725,16 +7725,16 @@ declare function createClaudeConnectorNamespace<N extends string>(namespaceName:
7725
7725
  adapterId: z.ZodString;
7726
7726
  agentId: z.ZodString;
7727
7727
  oldState: z.ZodEnum<{
7728
- idle: "idle";
7729
7728
  paused: "paused";
7729
+ idle: "idle";
7730
7730
  turn_started: "turn_started";
7731
7731
  step_started: "step_started";
7732
7732
  step_finished: "step_finished";
7733
7733
  turn_finished: "turn_finished";
7734
7734
  }>;
7735
7735
  newState: z.ZodEnum<{
7736
- idle: "idle";
7737
7736
  paused: "paused";
7737
+ idle: "idle";
7738
7738
  turn_started: "turn_started";
7739
7739
  step_started: "step_started";
7740
7740
  step_finished: "step_finished";
@@ -0,0 +1 @@
1
+ import{o as e}from"./chunk-DTipWd-i.mjs";import{n as t,o as n,s as r}from"./json-value-DM-EjTC1.mjs";import{C as i,_ as a,a as o,b as s,c,d as l,i as u,l as d,n as ee,p as te,r as ne,t as re,u as ie,w as f,x as ae,y as oe}from"./schemas-W3nT06vH.mjs";import{A as se,D as ce,a as p,m as le,r as ue,s as m,t as h,u as g,x as de,y as fe}from"./kind-registration-DdbhhvaT.mjs";import{t as pe}from"./zod-json-schema-ZUmGtQhT.mjs";import{t as me}from"./ajv-Cvnmw2yn.mjs";import{t as he}from"./2020-CRfgqanb.mjs";import{t as ge}from"./dist-onY7e-pd.mjs";import{z as _}from"zod";import{createBusNamespace as _e}from"@makaio/framework/core";const ve=_.strictObject({evidence:i}),v=_.strictObject({kind:_.literal(`text`),text:_.string()}),[ye,be,xe]=i.options,Se=_.union([ye.pick({source:!0,location:!0}).extend({content:v}),be.pick({source:!0,location:!0}).extend({content:v}),xe.pick({source:!0,location:!0}).extend({content:v})]);function y(e){return typeof e==`object`&&e&&!Array.isArray(e)?e:void 0}function b(e){return e.replaceAll(`~`,`~0`).replaceAll(`/`,`~1`)}function Ce(e,t){if(t===`#`)return{node:e,pointer:``};if(!t.startsWith(`#/`))return;let n;try{n=decodeURIComponent(t.slice(1))}catch{return}let r=e;for(let e of n.slice(1).split(`/`)){let t=e.replaceAll(`~1`,`/`).replaceAll(`~0`,`~`);if(Array.isArray(r)){if(!/^(0|[1-9]\d*)$/.test(t)||Number(t)>=r.length)return;r=r[Number(t)]}else{let e=y(r);if(!e||!Object.hasOwn(e,t))return;r=e[t]}}let i=typeof r==`boolean`?r:y(r);return i===void 0?void 0:{node:i,pointer:n}}function x(e,t){if(t===``)return!1;let n=e;for(let e of t.slice(1).split(`/`)){let t=e.replaceAll(`~1`,`/`).replaceAll(`~0`,`~`);if(n=Array.isArray(n)?n[Number(t)]:y(n)?.[t],typeof y(n)?.$id==`string`)return!0}return!1}function we(e,t,n){if(e[`x-makaio-value-type`]!==`evidence/v1`)return;let r=i.safeParse(t);if(!r.success)throw Error(`Invalid schema-declared evidence at ${n}`);return{evidence:r.data,dataPath:n}}function Te(e,t,n,r){if(typeof t.$ref!=`string`)return!1;if(r)return!0;let i=Ce(e,t.$ref);return i===void 0?!0:typeof i.node!=`boolean`&&S(e,i.node,n,x(e,i.pointer))}function S(e,t,n=new WeakSet,r=!1){let i=y(t);if(!i||n.has(i))return!1;n.add(i);let a=r||i!==e&&typeof i.$id==`string`;if(i[`x-makaio-value-type`]===`evidence/v1`||typeof i.$dynamicRef==`string`||Te(e,i,n,a)||[`additionalItems`,`additionalProperties`,`contains`,`else`,`if`,`items`,`then`,`unevaluatedItems`,`unevaluatedProperties`].some(t=>S(e,i[t],n,a))||[`allOf`,`anyOf`,`oneOf`,`prefixItems`].some(t=>Array.isArray(i[t])&&i[t].some(t=>S(e,t,n,a)))||Array.isArray(i.items)&&i.items.some(t=>S(e,t,n,a)))return!0;for(let t of[`dependentSchemas`,`dependencies`,`patternProperties`,`properties`]){let r=y(i[t]);if(r&&Object.values(r).some(t=>S(e,t,n,a)))return!0}return!1}var Ee=class{dataSchema;matchesSchema;occurrences=new Map;visited=new WeakMap;constructor(e,t){this.dataSchema=e,this.matchesSchema=t}extract(e){return this.visit(this.dataSchema,e,`/data`),[...this.occurrences.values()]}visit(e,t,n,r=``){let i=this.visited.get(e)??new Set;if(i.has(n))return;if(i.add(n),this.visited.set(e,i),typeof e.$dynamicRef==`string`)throw Error(`Evidence discovery does not support active $dynamicRef at ${n}`);if(typeof e.$ref==`string`){if(x(this.dataSchema,r))throw Error(`Evidence discovery does not support local $ref inside nested $id resource at ${n}`);let i=Ce(this.dataSchema,e.$ref);if(i===void 0)throw Error(`Cannot resolve local schema reference ${e.$ref} at ${n}`);if(typeof i.node!=`boolean`&&this.visit(i.node,t,n,i.pointer),this.dataSchema.$schema!==`https://json-schema.org/draft/2020-12/schema`)return}let a=we(e,t,n);if(a){this.occurrences.set(n,a);return}this.visitCombiners(e,t,n,r),this.visitConditional(e,t,n,r),this.visitDependencies(e,t,n,r),this.assertSupportedApplicators(e,n,r),Array.isArray(t)?this.visitArray(e,t,n,r):typeof t==`object`&&t&&this.visitObject(e,t,n,r)}visitCombiners(e,t,n,r){for(let i of[`allOf`,`anyOf`,`oneOf`]){let a=e[i];if(Array.isArray(a))for(let[e,o]of a.entries()){let a=y(o),s=`${r}/${i}/${e}`;a&&(i===`allOf`||this.matchesSchema(this.dataSchema,s,t))&&this.visit(a,t,n,s)}}}visitConditional(e,t,n,r){let i=typeof e.if==`boolean`?e.if:y(e.if);if(i===void 0)return;let a=`${r}/if`,o=this.matchesSchema(this.dataSchema,a,t);o&&typeof i!=`boolean`&&this.visit(i,t,n,a);let s=o?`then`:`else`,c=y(e[s]);c&&this.visit(c,t,n,`${r}/${s}`)}visitDependencies(e,t,n,r){if(!(typeof t!=`object`||!t||Array.isArray(t)))for(let i of[`dependentSchemas`,`dependencies`]){let a=y(e[i]);if(a)for(let[e,o]of Object.entries(a)){let a=y(o);Object.hasOwn(t,e)&&a&&this.visit(a,t,n,`${r}/${i}/${b(e)}`)}}}assertSupportedApplicators(e,t,n){for(let r of[`unevaluatedProperties`,`unevaluatedItems`])if(S(this.dataSchema,e[r],void 0,x(this.dataSchema,n)))throw Error(`Evidence under unsupported ${r} applicator at ${t}`)}visitArray(e,t,n,r){let i=Array.isArray(e.prefixItems),a=i?e.prefixItems:Array.isArray(e.items)?e.items:[];a.forEach((e,a)=>{let o=y(e),s=i?`prefixItems`:`items`;o&&a<t.length&&this.visit(o,t[a],`${n}/${a}`,`${r}/${s}/${a}`)});let o=Array.isArray(e.items)?y(e.additionalItems):y(e.items);if(o){let i=Array.isArray(e.items)?`additionalItems`:`items`;t.slice(a.length).forEach((e,t)=>this.visit(o,e,`${n}/${a.length+t}`,`${r}/${i}`))}this.visitContains(e,t,n,r)}visitContains(e,t,n,r){let i=y(e.contains);if(!i)return;let a=`${r}/contains`;t.forEach((e,t)=>{this.matchesSchema(this.dataSchema,a,e)&&this.visit(i,e,`${n}/${t}`,a)})}visitObject(e,t,n,r){let i=y(e.properties),a=y(e.patternProperties);for(let[o,s]of Object.entries(t)){let t=b(o),c=i!==void 0&&Object.hasOwn(i,o),l=y(i?.[o]);l&&this.visit(l,s,`${n}/${t}`,`${r}/properties/${t}`);let u=this.visitPatterns(a,o,s,`${n}/${t}`,r),d=y(e.additionalProperties);!c&&!u&&d&&this.visit(d,s,`${n}/${t}`,`${r}/additionalProperties`)}}visitPatterns(e,t,n,r,i){let a=!1;for(let[o,s]of Object.entries(e??{})){if(!new RegExp(o,`u`).test(t))continue;a=!0;let e=y(s);e&&this.visit(e,n,r,`${i}/patternProperties/${b(o)}`)}return a}};function De(e,t,n){return new Ee(e,n.matchesSchema).extract(t)}function Oe(e){let{dataSchema:t,hooks:n,...r}=e,i={$schema:`https://json-schema.org/draft/2020-12/schema`,...pe(t)};ce(i);let a=p.parse({...r,dataSchema:i});if(a.kind!==e.kind)throw Error(`Artifact kind identifiers must not contain surrounding whitespace`);let o=_.fromJSONSchema(a.dataSchema),s=_.unknown().superRefine((e,t)=>{let n=o.safeParse(e);if(!n.success)for(let e of n.error.issues)t.addIssue({code:`custom`,path:e.path,message:e.message})}).pipe(t).superRefine((e,t)=>{Object.hasOwn(e,`slug`)&&t.addIssue({code:`custom`,path:[fe],message:de});try{se(e,a.titlePath)}catch(e){t.addIssue({code:`custom`,path:a.titlePath.split(`.`),message:e instanceof Error?e.message:`Artifact title must be a nonblank string`})}});return{...structuredClone(a),kind:e.kind,schemaVersion:e.schemaVersion,dataSchema:s,...n?{hooks:n}:{},toRegistration:()=>structuredClone(a)}}var ke=e(me(),1),Ae=e(he(),1),je=e(ge(),1);function C(e){let t={allErrors:!0,strict:!1,strictSchema:!0},n=e.dataSchema.$schema===`https://json-schema.org/draft/2020-12/schema`?new Ae.default(t):new ke.default(t);return(0,je.default)(n),n.addKeyword({keyword:ae,schemaType:`string`,valid:!0}),n.compile(e.dataSchema)}function Me(e){return e.replace(/~1/gu,`/`).replace(/~0/gu,`~`)}function Ne(e){let t=e.instancePath.split(`/`).slice(1).map(Me),n=e.keyword===`required`?e.params.missingProperty:e.params.additionalProperty;return typeof n==`string`&&(e.keyword===`required`||e.keyword===`additionalProperties`)&&t.push(n),t.join(`.`)}function Pe(e){if(e.keyword!==`type`)return;let t=e.params.type;if(typeof t==`string`)return t;if(Array.isArray(t)&&t.every(e=>typeof e==`string`))return t.join(` | `)}const Fe=n.array();function Ie(e){if(e.keyword!==`enum`)return;let t=Fe.safeParse(e.params.allowedValues);return t.success?t.data:void 0}function Le(e){return(e??[]).map(e=>{let t=Pe(e),n=Ie(e);return{path:Ne(e),reason:e.message??`violates ${e.keyword}`,...t===void 0?{}:{expectedType:t},...n===void 0?{}:{allowedValues:n}}})}function w(e){return typeof e==`object`&&!!e&&Object.hasOwn(e,`slug`)}const Re={path:fe,reason:de};function ze(e){let t=C(e);return e=>t(e)&&!w(e)}function Be(e){let t=C(e);return e=>{let n=t(e)?[]:Le(t.errors);return w(e)&&n.push(Re),n.length===0?{valid:!0}:{valid:!1,issues:n}}}function Ve(e){return{hooks:[...e.hooks]}}const He=[`inline`,`summary`,`link`,`omit`],T=[`outbound`,`inbound`],E=_.string().min(1),D=_.enum(T),Ue=_.object({kinds:_.array(_.string().min(1)).optional(),hint:E.optional(),depth:_.number().int().min(1).max(20).optional(),nested:_.lazy(()=>O).optional(),direction:D.optional()}),O=_.record(_.string().min(1),Ue);function k(e){return JSON.stringify([e.kind,e.id,e.revision])}const We=_.enum([`not-selected`,`not-found`,`depth-exceeded`,`unsupported-ref-class`,`cycle-detected`]),Ge=_.object({target:d,sourceRef:f,relationType:_.string().min(1),sourceLocalId:c.shape.sourceLocalId,direction:D.optional(),hint:E,status:_.enum([`resolved`,`unresolved`]),reason:We.optional()}).superRefine((e,t)=>{e.status===`unresolved`&&e.reason===void 0&&t.addIssue({code:_.ZodIssueCode.custom,path:[`reason`],message:`reason is required for unresolved artifact context refs`}),e.status===`resolved`&&e.reason!==void 0&&t.addIssue({code:_.ZodIssueCode.custom,path:[`reason`],message:`reason must be omitted for resolved artifact context refs`}),e.status===`resolved`&&e.target.refClass!==`artifact`&&t.addIssue({code:_.ZodIssueCode.custom,path:[`target`],message:`resolved artifact context refs must target an artifact revision`})}),A=_.object({rootRef:f,refs:_.array(Ge),resolved:_.array(l)}).superRefine((e,t)=>{let n=new Set(e.resolved.map(k));n.has(k(e.rootRef))||t.addIssue({code:_.ZodIssueCode.custom,path:[`resolved`],message:`resolved artifact context wire payloads must include the root artifact revision`}),e.refs.forEach((e,r)=>{n.has(k(e.sourceRef))||t.addIssue({code:_.ZodIssueCode.custom,path:[`refs`,r,`sourceRef`],message:`artifact context ref sources must have a matching revision in resolved`}),!(e.status!==`resolved`||e.target.refClass!==`artifact`)&&(n.has(k(e.target))||t.addIssue({code:_.ZodIssueCode.custom,path:[`refs`,r,`target`],message:`resolved artifact context refs must have a matching revision in resolved`}))})});function Ke(e){let t=A.parse(e),n=new Map(t.resolved.map(e=>[k(e),e])),r=new Map;for(let e of t.refs){let t=k(e.sourceRef),n=r.get(t);n||(n=[],r.set(t,n)),n.push(e)}let i=n.get(k(t.rootRef));if(!i)throw Error(`Resolved artifact context is missing root artifact '${k(t.rootRef)}'`);let a=qe(t.rootRef,i,`inline`,r,n);return{root:a,flatten(){let e=[];return Xe(a,e),e}}}function qe(e,t,n,r,i){return{status:`resolved`,ref:e,artifact:t,hint:n,children:Ye(e,r,i,new Set([k(e)]))}}function Je(e,t,n,r,i,a,o,s,c){let l=k(e),u=new Set(c);return u.add(l),{status:`resolved`,ref:e,artifact:t,relation:n,sourceLocalId:r,direction:i,hint:a,children:Ye(e,o,s,u)}}function Ye(e,t,n,r){return(t.get(k(e))??[]).map(e=>{if(e.status===`unresolved`)return{status:`unresolved`,target:e.target,relation:e.relationType,sourceLocalId:e.sourceLocalId,direction:e.direction,hint:e.hint,reason:e.reason};if(e.target.refClass!==`artifact`)throw Error(`Resolved artifact context refs must target an artifact revision`);let i=k(e.target),a=n.get(i);if(!a)throw Error(`Resolved artifact context is missing target artifact '${i}'`);return r.has(i)?{status:`unresolved`,target:e.target,relation:e.relationType,sourceLocalId:e.sourceLocalId,direction:e.direction,hint:e.hint,reason:`cycle-detected`}:Je(e.target,a,e.relationType,e.sourceLocalId,e.direction,e.hint,t,n,r)})}function Xe(e,t){if(e.status!==`unresolved`){t.push(e.artifact);for(let n of e.children)Xe(n,t)}}const j=[`$set`,`$unset`,`$push`,`$pull`],M=`[A-Za-z_$][A-Za-z0-9_$]*`,N=`[A-Za-z_$][A-Za-z0-9_$-]*`,Ze=`(?:0|[1-9][0-9]*)`,Qe=`(?:${`\\$\\[${M}\\]`}|${Ze}|${N})`,$e=RegExp(`^${N}(?:\\.${Qe})*$`),et=RegExp(`^${M}(?:\\.${N})*$`),tt=RegExp(`^${Ze}$`),nt=RegExp(`^\\$\\[(${M})\\]$`),P=_.string().regex($e,`Expected a data-relative path of object properties, array positions, or $[filter] placeholders`);function rt(e){let t=nt.exec(e);return t?.[1]===void 0?tt.test(e)?{kind:`index`,index:Number(e)}:{kind:`property`,name:e}:{kind:`filter`,placeholder:t[1]}}function it(e){return e.split(`.`).map(rt)}function at(e){return it(e).flatMap(e=>e.kind===`filter`?[e.placeholder]:[])}const ot=r(_.record(_.string().regex(et,`Expected a filter key of the form name or name.field.path`),n),{prototypeKey:`an array filter cannot compare a __proto__ key, which JSON transport drops`,nonPlainObject:`an array filter must be a plain object of comparison keys`,symbolKey:`an array filter cannot carry symbol-keyed comparisons`,nonEnumerableKey:`an array filter cannot carry non-enumerable comparison keys`,extraArrayKey:`an array filter must be a plain object, not an array`});function st(e){let t=new Set(Object.keys(e).map(e=>e.split(`.`)[0]));if(t.size!==1)return;let[n]=t;return n!==void 0&&n.length>0?n:void 0}function F(e,t){return r(_.record(P,t),{prototypeKey:`${e} cannot address __proto__, which JSON transport drops`,nonPlainObject:`${e} must be a plain object of path instructions`,symbolKey:`${e} cannot carry symbol-keyed instructions`,nonEnumerableKey:`${e} cannot carry non-enumerable instructions`,extraArrayKey:`${e} must be a plain object, not an array`})}const ct=_.literal(!0),lt=_.strictObject({$set:F(`$set`,n).optional(),$unset:F(`$unset`,ct).optional(),$push:F(`$push`,n).optional(),$pull:F(`$pull`,n).optional(),arrayFilters:_.array(ot).optional()});function I(e){return j.flatMap(t=>Object.entries(e[t]??{}).map(([e,n])=>({operator:t,path:e,value:n})))}function ut(e,t){let n=I(e),r=new Map;(e.arrayFilters??[]).forEach((e,n)=>{let i=st(e);if(i===void 0){t.addIssue({code:`custom`,path:[`arrayFilters`,n],message:`An array filter must bind exactly one placeholder name across all of its keys`});return}if(r.has(i)){t.addIssue({code:`custom`,path:[`arrayFilters`,n],message:`Array filter placeholder ${i} is already bound by another filter`});return}r.set(i,n)});let i=new Set;for(let{operator:e,path:a}of n)for(let n of at(a))i.add(n),r.has(n)||t.addIssue({code:`custom`,path:[e,a],message:`Path uses placeholder $[${n}] without a matching entry in arrayFilters`});for(let[e,n]of r)i.has(e)||t.addIssue({code:`custom`,path:[`arrayFilters`,n],message:`Array filter binds placeholder ${e}, which no path uses`})}const dt=lt.superRefine(ut).superRefine((e,t)=>{I(e).length===0&&t.addIssue({code:`custom`,message:`Declare at least one of ${j.join(`, `)}`})}),ft=lt.superRefine(ut),pt=_.strictObject({kind:f.shape.kind,id:f.shape.id}),mt=_.strictObject({ref:pt,baseRevision:f.shape.revision,patch:ft,dryRun:_.boolean().optional(),schemaVersion:g.optional().describe(`Target schema version for the patched revision; defaults to the base revision's. Use it to migrate an artifact left at an older version by a kind bump.`),statusPath:te.optional(),representations:ie.strict().nullable().optional().describe(`Rendering hints (markdown, summary, plaintext) for the new revision. Omit to keep the previous revision's hints. An object replaces all of them, it does not merge: send every hint you want to keep. null clears them.`)}).superRefine((e,t)=>{e.schemaVersion===void 0&&I(e.patch).length===0&&t.addIssue({code:`custom`,path:[`patch`],message:`Declare at least one of ${j.join(`, `)}, or name a schemaVersion to migrate a payload that already fits`})}),ht=[`ARTIFACT_NOT_FOUND`,`BASE_REVISION_CONFLICT`,`KIND_NOT_REGISTERED`,`SCHEMA_VERSION_MISMATCH`,`PATH_NOT_DECLARED`,`PATH_NOT_RESOLVABLE`,`TARGET_NOT_A_COLLECTION`,`UNSUPPORTED_TARGET`,`NO_MATCH`,`SCHEMA_VALIDATION_FAILED`,`PAYLOAD_INVARIANT_FAILED`,`NO_CHANGE`,`STORE_REJECTED`,`HOST_FAILED`],gt=_.strictObject({path:_.string(),reason:_.string().min(1),expectedType:_.string().min(1).optional(),allowedValues:_.array(n).optional()}),_t=_.strictObject({code:_.enum(ht),message:_.string().min(1),operator:_.enum(j).optional(),path:P.optional(),currentRevision:f.shape.revision.optional(),issues:_.array(gt).optional(),repair:_.string().min(1)}).superRefine((e,t)=>{e.code===`BASE_REVISION_CONFLICT`&&e.currentRevision===void 0&&t.addIssue({code:_.ZodIssueCode.custom,message:`A BASE_REVISION_CONFLICT must name the revision the artifact carries.`,path:[`currentRevision`]})}),vt=_.strictObject({operator:_.enum(j),path:P,matched:_.number().int().positive()}),yt=_.strictObject({from:g,to:g}).refine(e=>e.to>e.from,{path:[`to`],message:`A migration moves the artifact forward to a newer schema version`}),bt=_.strictObject({ok:_.literal(!0),base:f,operations:_.array(vt),migration:yt.optional()});function xt(e,t){e.operations.length===0&&e.migration===void 0&&t.addIssue({code:`custom`,path:[`operations`],message:`A success without a migration must report at least one applied instruction`})}const St=bt.extend({dryRun:_.literal(!0)}).superRefine(xt),Ct=bt.extend({dryRun:_.literal(!1),artifact:f}).superRefine(xt),wt=_.discriminatedUnion(`dryRun`,[St,Ct]),Tt=_.strictObject({ok:_.literal(!1),error:_t}),Et=_.union([wt,Tt]),Dt=_.object({ref:oe}),Ot=_.union([_.strictObject({ok:_.literal(!0),ref:oe,areaPath:ue,part:t}),_.strictObject({ok:_.literal(!1),error:le})]),L=f.pick({kind:!0,id:!0}),R=_.number().int().positive(),z=R,B={knowledge:`valid`,commitment:`proposed`,interaction:`open`},V=_.discriminatedUnion(`category`,[_.strictObject({category:_.literal(`knowledge`),state:_.enum(h.knowledge),version:z}),_.strictObject({category:_.literal(`commitment`),state:_.enum(h.commitment),version:z}),_.strictObject({category:_.literal(`interaction`),state:_.enum(h.interaction),version:z})]).superRefine((e,t)=>{e.version===1&&e.state!==B[e.category]&&t.addIssue({code:`custom`,path:[`state`],message:`Lifecycle version 1 is reserved for the category initial state`})}),H=_.union([V,_.strictObject({category:_.literal(`record`)})]),U=_.string().trim().min(1),kt=_.strictObject({kind:U,ref:U}),W=_.discriminatedUnion(`kind`,[_.strictObject({kind:_.literal(`revision-assessment`),assessedRevision:f.shape.revision,source:kt.optional()}),_.strictObject({kind:_.literal(`handover`),source:kt})]),At={artifact:L,expectedVersion:z,state:m,situation:W,reason:U.optional()},G=_.strictObject(At),jt=_.strictObject({...At,actor:re}),Mt={valid:[`retired`],retired:[`valid`],proposed:[`decided`],decided:[`fulfilled`,`revoked`],fulfilled:[],revoked:[],open:[`resolved`,`closed-without-resolution`],resolved:[],"closed-without-resolution":[]};function K(e,t){return Mt[e].includes(t)}const Nt={artifact:L,lifecycle:V,actor:re,timestamp:_.number().int().nonnegative(),observedRevision:f.shape.revision},Pt=_.strictObject({...Nt,operation:_.literal(`initialized`)}).superRefine((e,t)=>{(e.lifecycle.version!==1||e.lifecycle.state!==B[e.lifecycle.category])&&t.addIssue({code:`custom`,path:[`lifecycle`],message:`Initialization requires the category initial state and version 1`})});function Ft(e,t){return t===`retired`||e===`retired`&&t===`valid`}const It=`Retiring or reinstating knowledge requires a reason`,q=_.strictObject({...Nt,operation:_.literal(`transitioned`),previousState:m,situation:W,reason:G.shape.reason}).superRefine((e,t)=>{(!K(e.previousState,e.lifecycle.state)||e.lifecycle.version<=1)&&t.addIssue({code:`custom`,path:[`lifecycle`],message:`History requires a category-compatible transition after initialization`}),Ft(e.previousState,e.lifecycle.state)&&!e.reason&&t.addIssue({code:`custom`,path:[`reason`],message:It}),e.situation.kind===`revision-assessment`&&e.situation.assessedRevision!==e.observedRevision&&t.addIssue({code:`custom`,path:[`situation`],message:`An assessment cannot authorize a different observed content revision`})}),Lt=_.discriminatedUnion(`operation`,[Pt,q]),J=_.discriminatedUnion(`reason`,[_.strictObject({reason:_.literal(`lifecycle-version-conflict`),expectedVersion:z,current:V,requestedState:m}),_.strictObject({reason:_.literal(`content-basis-conflict`),assessedRevision:f.shape.revision,currentRevision:f.shape.revision}),_.strictObject({reason:_.literal(`invalid-transition`),current:H,requestedState:m}),_.strictObject({reason:_.literal(`precondition-failed`),current:V,requestedState:m})]),Y=`artifact-lifecycle-rejected`;var X=class extends Error{code=Y;data;constructor(e,t){super(e),this.name=`ArtifactLifecycleError`,this.data=J.parse(t)}};function Rt(e){return e===`record`?{category:`record`}:V.parse({category:e,state:B[e],version:1})}function zt(e){let t=H.parse(e.current),n=f.shape.revision.parse(e.currentRevision),r=jt.parse(e.command);if(t.category===`record`)throw new X(`Record artifacts do not have a lifecycle`,{reason:`invalid-transition`,current:t,requestedState:r.state});if(r.expectedVersion!==t.version)throw new X(`Artifact lifecycle changed since the supplied baseline`,{reason:`lifecycle-version-conflict`,expectedVersion:r.expectedVersion,current:t,requestedState:r.state});if(r.situation.kind===`revision-assessment`&&r.situation.assessedRevision!==n)throw new X(`Assessed content revision is no longer current`,{reason:`content-basis-conflict`,assessedRevision:r.situation.assessedRevision,currentRevision:n});if(!K(t.state,r.state))throw new X(`Artifact lifecycle transition is not allowed`,{reason:`invalid-transition`,current:t,requestedState:r.state});if(Ft(t.state,r.state)&&!r.reason)throw new X(It,{reason:`precondition-failed`,current:t,requestedState:r.state});return V.parse({...t,state:r.state,version:t.version+1})}const Bt=_.strictObject({artifact:L}),Vt=_.strictObject({lifecycle:H}),Ht=_.strictObject({artifact:L,afterVersion:R.optional(),limit:_.number().int().min(1).max(100).default(50)}),Ut=_.strictObject({entries:_.array(Lt).max(100),nextCursor:R.optional()}).superRefine(({entries:e,nextCursor:t},n)=>{let r=e[0],i;for(let[t,a]of e.entries()){let e=a.artifact.kind===r?.artifact.kind&&a.artifact.id===r?.artifact.id,o=i===void 0||a.lifecycle.version===i.lifecycle.version+1,s=i===void 0||a.operation===`transitioned`&&a.lifecycle.category===i.lifecycle.category&&a.previousState===i.lifecycle.state;if(!e||!o||!s){n.addIssue({code:`custom`,path:[`entries`,t],message:`History pages contain one artifact in contiguous ascending, state-linked order`});break}i=a}t!==void 0&&t!==i?.lifecycle.version&&n.addIssue({code:`custom`,path:[`nextCursor`],message:`nextCursor must equal the last returned lifecycle version`})}),Z=_.strictObject({entry:q}),Wt=Z,Gt=_.strictObject({code:_.literal(Y),message:_.string().min(1),data:J});function Kt(e){return{code:e.code,message:e.message,data:e.data}}function qt(e,t){switch(t.reason){case`content-basis-conflict`:return Yt(e,t);case`lifecycle-version-conflict`:return[...Q(e,t),...Jt(e,t)];case`invalid-transition`:case`precondition-failed`:return[...Q(e,t),...Xt(e,t)]}}function Q(e,t){return t.requestedState===e.state?[]:[{path:[`requestedState`],message:`Rejection requestedState must match the rejected transition`}]}function Jt(e,t){let n=[];return t.expectedVersion!==e.expectedVersion&&n.push({path:[`expectedVersion`],message:`Version conflict baseline must match the rejected transition`}),t.current.version===e.expectedVersion&&n.push({path:[`current`,`version`],message:`Version conflict requires a current version different from the supplied baseline`}),n}function Yt(e,t){let n=[];return(e.situation.kind!==`revision-assessment`||t.assessedRevision!==e.situation.assessedRevision)&&n.push({path:[`assessedRevision`],message:`Content conflict must identify the rejected revision assessment`}),t.currentRevision===t.assessedRevision&&n.push({path:[`currentRevision`],message:`Content conflict requires a current revision different from the assessed revision`}),n}function Xt(e,t){if(t.current.category===`record`)return[];let n=[];t.current.version!==e.expectedVersion&&n.push({path:[`current`,`version`],message:`A rejection after the version check must report the supplied baseline version`});let r=K(t.current.state,t.requestedState);return t.reason===`invalid-transition`&&r&&n.push({path:[`reason`],message:`invalid-transition requires a transition the lifecycle matrix disallows`}),t.reason===`precondition-failed`&&!r&&n.push({path:[`reason`],message:`precondition-failed requires a transition the lifecycle matrix allows`}),n}const Zt=_.strictObject({transition:G,error:Gt}).superRefine(({transition:e,error:t},n)=>{for(let r of qt(e,t.data))n.addIssue({code:`custom`,path:[`error`,`data`,...r.path],message:r.message})}),Qt={"lifecycle.get":{request:Bt,response:Vt},"lifecycle.history":{request:Ht,response:Ut},"lifecycle.transition":{request:G,response:Z},"lifecycle.committed":Wt,"lifecycle.rejected":Zt},$t=l.omit({id:!0,slug:!0,revision:!0,timestamp:!0}),en={...Qt,"kind.register":{request:p,response:_.object({registered:_.boolean()})},"kind.list":{request:_.object({kind:_.string().min(1).optional()}),response:_.object({kinds:_.array(p)})},"relation-type.register":{request:s,response:_.object({registered:_.boolean()})},"relation-type.list":{request:_.object({type:_.string().min(1).optional()}),response:_.object({relationTypes:_.array(s)})},create:{request:$t.extend({id:f.shape.id.optional(),slug:l.shape.slug.optional()}),response:_.object({artifact:l})},revise:{request:_.object({previous:f,statusPath:te.optional(),revision:$t}),response:_.object({artifact:l})},patch:{request:mt,response:Et},resolve:{request:_.object({ref:f}),response:_.object({artifact:l.nullable()})},resolvePart:{request:Dt,response:Ot},query:{request:o,response:_.object({artifacts:_.array(l)})},compare:{request:ee,response:ne},"evidence.resolve":{request:ve,response:Se},resolveContext:{request:_.object({ref:f,selectors:O.optional(),maxDepth:_.number().int().min(1).max(20).default(5)}),response:_.object({context:A})},created:_.object({artifact:l}),revised:_.object({previous:f,artifact:l}),"relation.added":_.object({artifact:f,relation:c}),"observation.added":_.object({artifact:f,observation:u}),"status.changed":_.object({artifact:f,path:_.string().min(1),previous:_.unknown().optional(),current:_.unknown().optional()}),"kind.changed":_.object({kind:_.string().min(1),schemaVersion:g})},tn=_e(`artifact`,en),nn=tn.subjects,rn=_.discriminatedUnion(`refClass`,[f.omit({revision:!0}),a]);function an(e){if(e.refClass===`artifact`)return{refClass:`artifact`,kind:e.kind,id:e.id};if(e.refClass===`entity`)return{refClass:`entity`,entityType:e.entityType,id:e.id}}function $(e){return e.refClass===`artifact`?JSON.stringify([`artifact`,e.kind,e.id]):JSON.stringify([`entity`,e.entityType,e.id])}function on(e){return e.refClass===`artifact`?`artifact:${e.kind}/${e.id}`:`entity:${e.entityType}/${e.id}`}const sn=[`relation-target`,`data`];function cn(e,t){if(!e||e.length===0)return{ok:!0,rules:[]};let n=[];for(let[r,i]of e.entries()){for(let[e,a]of i.by.entries())(!sn.includes(a.kind)||!t.includes(a.kind))&&n.push({ruleIndex:r,selectorIndex:e,capability:a.kind,message:`rule #${r}, selector #${e}: '${a.kind}' selectors are not supported`});i.lifecycleStates!==void 0&&!t.includes(`lifecycle-states`)&&n.push({ruleIndex:r,capability:`lifecycle-states`,message:`rule #${r}: lifecycleStates is declared but 'lifecycle-states' is not a supported capability`})}return n.length>0?{ok:!1,issues:n}:{ok:!0,rules:e}}function ln(e,t){let n=e;for(let e of t.split(`.`)){if(typeof n!=`object`||!n||Array.isArray(n)||!Object.hasOwn(n,e))return;n=Reflect.get(n,e)}return{value:n}}function un(e,t,n,r){let{path:i}=e,a=ln(t,i);if(a===void 0||a.value===null||a.value===void 0)return{ruleIndex:n,selectorIndex:r,reason:`missing-value`,dataPath:i,message:`rule #${n}, selector #${r}, data path '${i}': no value found`};let{value:o}=a;return typeof o!=`string`&&typeof o!=`number`&&typeof o!=`boolean`?{ruleIndex:n,selectorIndex:r,reason:`unsupported-value-type`,dataPath:i,message:`rule #${n}, selector #${r}, data path '${i}': value must be a scalar (string, number, or boolean)`}:{path:i,value:o}}function dn(e,t,n,r,i){if(e.kind===`data`)return un(e,n,r,i);let{relationType:a}=e,o=t.filter(e=>e.type===a&&e.sourceLocalId===void 0),s=new Set,c,l;for(let e of o){let t=an(e.target);if(t===void 0){l=e.target.refClass;break}s.add($(t)),c=t}return l===void 0?c===void 0?{ruleIndex:r,selectorIndex:i,reason:`missing-target`,relationType:a,message:`rule #${r}, selector #${i}, relation '${a}': no relations of this type found`}:s.size>1?{ruleIndex:r,selectorIndex:i,reason:`ambiguous-target`,relationType:a,message:`rule #${r}, selector #${i}, relation '${a}': ${s.size} distinct targets; expected exactly one`}:{type:a,target:c}:{ruleIndex:r,selectorIndex:i,reason:`unsupported-target`,relationType:a,message:`rule #${r}, selector #${i}, relation '${a}': found a relation with refClass '${l}'; only artifact and entity targets are supported`}}function fn(e){return`target`in e?[`relation-target`,e.type,$(e.target)]:[`data`,e.path,e.value]}function pn(e,t,n){let r=[],i=[];for(let[a,o]of e.entries()){let e=o.by.map((e,r)=>dn(e,t,n,a,r)),s=e.filter(e=>`reason`in e);if(s.length>0){i.push(...s);continue}let c=e.filter(e=>!(`reason`in e)),l=JSON.stringify(c.map(e=>fn(e)));r.push({rule:o,ruleIndex:a,parts:c,serialized:l})}return{keys:r,issues:i}}function mn(e){return e.parts.map(e=>`target`in e?`${e.type} → ${on(e.target)}`:`${e.path} → ${JSON.stringify(e.value)}`).join(`; `)}export{wt as $,jt as A,j as B,X as C,Se as Ct,J as D,Pt as E,Rt as F,Tt as G,dt as H,K as I,vt as J,gt as K,Dt as L,q as M,R as N,W as O,zt as P,Et as Q,Ot as R,H as S,ve as St,L as T,St as U,ot as V,_t as W,Ct as X,P as Y,mt as Z,Zt as _,Ve as _t,an as a,it as at,Kt as b,Oe as bt,tn as c,We as ct,Wt as d,T as dt,pt as et,Gt as f,He as ft,Ut as g,O as gt,Ht as h,E as ht,rn as i,rt as it,G as j,V as k,en as l,A as lt,Vt as m,Ue as mt,pn as n,I as nt,on as o,Ke as ot,Bt as p,D as pt,yt as q,mn as r,at as rt,$ as s,Ge as st,cn as t,st as tt,nn as u,k as ut,Qt as v,Be as vt,Lt as w,Y as x,De as xt,Z as y,ze as yt,ht as z};
@@ -1 +1 @@
1
- import{$ as e,A as t,B as n,C as r,D as i,E as a,F as o,G as s,H as c,I as l,J as u,K as d,L as ee,M as te,N as f,O as ne,P as re,Q as p,R as m,S as h,T as ie,U as ae,V as g,W as oe,X as se,Y as ce,Z as le,_ as ue,a as de,at as fe,b as pe,d as _,et as me,f as he,g as v,h as y,i as ge,it as b,j as x,k as S,l as C,m as w,nt as T,o as E,p as D,q as O,r as k,rt as A,s as j,t as M,tt as N,u as P,v as F,w as I,x as L,y as _e,z as ve}from"../bus-DgpPEPoM.mjs";import{z as R}from"zod";const z={"channel.open":{request:R.object({endpoint:R.string(),token:R.string(),clientPubKey:R.string(),transports:R.array(R.string())}),response:R.object({channelId:R.string(),endpointPubKey:R.string()})}};function B(e){let t=e instanceof Uint8Array?e:new Uint8Array(e),n=Array(t.length);for(let e=0;e<t.length;e++)n[e]=String.fromCharCode(t[e]);return btoa(n.join(``))}function V(e){let t=atob(e),n=new Uint8Array(t.length);for(let e=0;e<t.length;e++)n[e]=t.charCodeAt(e);return n.buffer}async function H(){return globalThis.crypto.subtle.generateKey({name:`ECDH`,namedCurve:`P-256`},!1,[`deriveKey`])}async function U(e){return B(await globalThis.crypto.subtle.exportKey(`raw`,e))}async function W(e){let t=V(e);return globalThis.crypto.subtle.importKey(`raw`,t,{name:`ECDH`,namedCurve:`P-256`},!1,[])}async function G(e,t){return globalThis.crypto.subtle.deriveKey({name:`ECDH`,public:t},e,{name:`AES-GCM`,length:256},!1,[`encrypt`,`decrypt`])}async function K(e,t,n){let r=globalThis.crypto.getRandomValues(new Uint8Array(12)),i=new TextEncoder().encode(t),a={name:`AES-GCM`,iv:r};n!==void 0&&(a.additionalData=new TextEncoder().encode(n));let o=await globalThis.crypto.subtle.encrypt(a,e,i);return{iv:B(r),data:B(o)}}async function q(e,t,n){let r=V(t.iv),i=V(t.data),a={name:`AES-GCM`,iv:r};n!==void 0&&(a.additionalData=new TextEncoder().encode(n));let o=await globalThis.crypto.subtle.decrypt(a,e,i);return new TextDecoder().decode(o)}function J(e,t){return{subject:t,$meta:{namespace:`channel:${e}`,isRequest:!1,payload:{},local:!1,channel:!1}}}function Y(e,t){return{subject:t,$meta:{namespace:`channel:${e}`,isRequest:!0,payload:{},local:!1,channel:!1}}}var X=class{channelId;sharedKey;context;transportNames;cleanups=[];pendingRequests=new Set;closed=!1;constructor(e,t,n,r){this.channelId=e,this.sharedKey=t,this.context=n,this.transportNames=r;let i=J(e,`$close`);this.cleanups.push(this.registerEventHandler(i,t,e=>{this.handlePeerClose()}))}on(e,t,n){this.assertOpen();let r=this.requireKey(),i=e.$meta.isRequest?this.registerRequestHandler(e,r,t,n):this.registerEventHandler(e,r,t,n);return this.cleanups.push(i),()=>{i();let e=this.cleanups.indexOf(i);e!==-1&&this.cleanups.splice(e,1)}}once(e,t){this.assertOpen();let n=this.requireKey(),r=null,i=(e=>{let n=r;if(r=null,n){let e=this.cleanups.indexOf(n);e!==-1&&this.cleanups.splice(e,1)}return n?.(),t(e)});return r=e.$meta.isRequest?this.registerRequestHandler(e,n,i):this.registerEventHandler(e,n,i),this.cleanups.push(r),()=>{if(r){let e=r;r=null;let t=this.cleanups.indexOf(e);t!==-1&&this.cleanups.splice(t,1),e()}}}async emit(e,t){this.assertOpen();let n=this.requireKey(),r=J(this.channelId,e.subject),i=await K(n,JSON.stringify(t),`${this.channelId}:${e.subject}:evt`);await w(this.context,r,i,{...this.transportNames?{transports:[...this.transportNames]}:{}})}async request(e,t,n){this.assertOpen();let r=this.requireKey(),i=new AbortController;this.pendingRequests.add(i);try{let a=Y(this.channelId,e.subject),o=await K(r,JSON.stringify(t),`${this.channelId}:${e.subject}:req`),s=await q(r,await _(this.context,a,o,{signal:i.signal,...n?.timeout===void 0?{}:{timeout:n.timeout},...this.transportNames?{transports:[...this.transportNames]}:{}}),`${this.channelId}:${e.subject}:res`);return JSON.parse(s)}finally{this.pendingRequests.delete(i)}}async requestOptional(e,t,n){try{return{handled:!0,data:await this.request(e,t,n)}}catch(e){if(e instanceof l)return{handled:!1};throw e}}close(){if(this.closed)return;this.closed=!0;let e=this.sharedKey;if(e){let t=J(this.channelId,`$close`);K(e,JSON.stringify({}),`${this.channelId}:$close:evt`).then(e=>w(this.context,t,e,{...this.transportNames?{transports:[...this.transportNames]}:{}})).catch(()=>{})}this.abortPendingRequests(),this.runCleanups(),this.sharedKey=null}assertOpen(){if(this.closed)throw new g(this.channelId)}requireKey(){return this.sharedKey}registerEventHandler(e,t,n,r){let i=J(this.channelId,e.subject),a=`${this.channelId}:${e.subject}:evt`;return v(this.context,i,async e=>{let r=await q(t,e.payload,a),i=JSON.parse(r);return n({...e,payload:i})},r)}registerRequestHandler(e,t,n,r){let i=Y(this.channelId,e.subject),a=`${this.channelId}:${e.subject}:req`,o=`${this.channelId}:${e.subject}:res`;return v(this.context,i,async e=>{let r=await q(t,e.payload,a),i=JSON.parse(r),s,c=e=>{s={value:e}},l=e=>{s={value:{...s?.value??{},...e}}},u=async()=>{let n=s;if(await e.next(),n!==void 0){s=n;return}let r=e.result;if(r!==void 0){let e=await q(t,r,o);s={value:JSON.parse(e)}}};if(await n({...e,payload:i,get result(){return s?.value},setResult:c,extendResult:l,next:u}),s!==void 0){let n=await K(t,JSON.stringify(s.value),o);e.setResult(n)}},r)}handlePeerClose(){this.closed||(this.closed=!0,this.abortPendingRequests(),this.runCleanups(),this.sharedKey=null)}abortPendingRequests(){let e=new g(this.channelId);for(let t of this.pendingRequests)t.abort(e);this.pendingRequests.clear()}runCleanups(){for(let e of this.cleanups)try{e()}catch{}this.cleanups.length=0}};function Z(e){return e.namespaceRegistry.registerNamespace(p(`system`,z)).subjects.channel.open}function ye(e,t,n,r){let i=v(e,Z(e),async i=>{if(i.payload.endpoint!==t){await i.next();return}if(i.payload.token!==r.token)throw new c(t);let{publicKey:a,privateKey:o}=await H(),s=await G(o,await W(i.payload.clientPubKey)),l=globalThis.crypto.randomUUID(),u=new Set(e.transportRegistry.names()),d=new X(l,s,e,(i.payload.transports??[]).filter(e=>u.has(e)));try{n(d),i.setResult({channelId:l,endpointPubKey:await U(a)})}catch(e){throw d.close(),e}});return{name:t,token:r.token,close:i}}async function be(e,t,n){let r=Z(e),{publicKey:i,privateKey:a}=await H(),o=await U(i),s=n.transports!==void 0,c=s?[...n.transports]:[...e.transportRegistry.names()],l=s?{transports:c}:void 0,u=await _(e,r,{endpoint:t,token:n.token,clientPubKey:o,transports:c},l),d=await G(a,await W(u.endpointPubKey));return new X(u.channelId,d,e,c)}var xe=class{pending;constructor(){this.pending=new Map}track(e,t,n){return new Promise((r,i)=>{if(n?.aborted){i(s(n.reason));return}let a=t===0?void 0:setTimeout(()=>{let n=this.pending.get(e);n!==void 0&&(clearTimeout(n.timeoutId),n.removeAbortListener?.(),this.pending.delete(e),n.reject(new f(e,t)))},t);if(this.pending.set(e,{resolve:r,reject:i,timeoutId:a,removeAbortListener:void 0}),n){let t=()=>{this.reject(e,s(n.reason))};n.addEventListener(`abort`,t,{once:!0});let r=()=>{n.removeEventListener(`abort`,t)},i=this.pending.get(e);i&&(i.removeAbortListener=r)}n?.aborted&&this.reject(e,s(n.reason))})}resolve(e,t){let n=this.pending.get(e);n&&(clearTimeout(n.timeoutId),n.removeAbortListener?.(),this.pending.delete(e),n.resolve(t))}reject(e,t){let n=this.pending.get(e);n&&(clearTimeout(n.timeoutId),n.removeAbortListener?.(),this.pending.delete(e),n.reject(t))}cancel(e,t){this.reject(e,t??s(void 0))}rejectAll(e){for(let[t,n]of this.pending.entries())clearTimeout(n.timeoutId),n.removeAbortListener?.(),n.reject(e);this.pending.clear()}cleanup(){this.rejectAll(Error(`Transport disconnected`))}};const Se=p(`bus:lifecycle`,de).subjects;function Ce(e,t){let n={},r={},i={};for(let[t,a]of e)n[t]=a.priorities,r[t]=a.deliveryClass??`relayable`,a.filter!==void 0&&(i[t]=a.filter);return{type:`subscribe`,...t===void 0?{}:{ackId:t},subjects:n,deliveryClasses:r,...Object.keys(i).length>0&&{filters:i}}}function we(e,t){return{type:`unsubscribe`,...t===void 0?{}:{ackId:t},subjects:e}}function Q(e,t){let n=e.trim();if(n.length===0||n.startsWith(`extension:`))throw Error(`Invalid extensionName: expected a non-empty extension name without the "extension:" prefix.`);let r=n;return{...p(`extension:${r}`,t.schemas),domain:r,extensions:t.extensions??{}}}function $(e,t){return`${e}.${t}`}function Te(){let e=new Map;return{register(t){let n=$(t.namespace,t.subject);return e.set(n,t),()=>{e.get(n)===t&&e.delete(n)}},get(t,n){return e.get($(t,n))}}}const Ee=x.fact.$meta.namespace,De=x.fact.subject;function Oe(e){return e.type===`event`||e.type===`request`||e.type===`broadcast`}async function ke(e,t,n,r,i,a){let o=y({message:t,direction:`outbound`,observedAt:a(),machineId:i,namespaceRegistry:n,projectorRegistry:r});for(let n of o)await e.send({type:`event`,namespace:Ee,subject:De,payload:n,messageId:`${t.messageId}:telemetry:${n.factId}`,correlationId:t.correlationId})}function Ae(e,t,n,r,i){return async function(a,o){if(!Oe(a))return!0;if(await ke(e,a,t,n,r,i),a.type===`request`)throw Error(`Projected telemetry transport cannot satisfy request responses; exclude it from request routing.`);return a.type===`broadcast`?[]:!0}}function je(e){let{inner:t,namespaceRegistry:n,projectorRegistry:r,machineId:i,now:a=Date.now}=e,o={name:e.name,send:Ae(t,n,r,i,a),onReceive(e){return t.onReceive(async()=>{})},connect(){return t.connect()},disconnect(){return t.disconnect()},subscribe(){return Promise.resolve()},unsubscribe(){return Promise.resolve()},get ready(){return t.ready},get onNewReadySession(){return t.onNewReadySession},set onNewReadySession(e){t.onNewReadySession=e},get onConnected(){return t.onConnected},set onConnected(e){t.onConnected=e},get onDisconnected(){return t.onDisconnected},set onDisconnected(e){t.onDisconnected=e},isReady(){return t.isReady?.()??!0},cancelRequest(e,n){t.cancelRequest?.(e,n)},onBroadcastResults(e,n,r){t.onBroadcastResults?.(e,n,r)}};return t.reconnect&&(o.reconnect=()=>t.reconnect()),o}export{ae as BusAbortError,d as BusError,Se as BusLifecycle,m as CONNECTION_LOST_ERROR_CODE,c as ChannelAuthError,g as ChannelClosedError,n as ChannelOnlyError,ve as ConnectionLostError,xe as CorrelationTracker,he as DEFAULT_READINESS_TIMEOUT_MS,D as DEFAULT_REQUEST_TIMEOUT_MS,pe as LOCAL_ORIGIN,ee as LocalSubjectError,M as MakaioBus,o as NO_HANDLER_ERROR_CODE,l as NoHandlerError,P as OnceAbortError,L as REMOTE_ORIGIN,re as RequestError,z as SystemChannelSchemas,f as TimeoutError,te as ValidationError,F as __resetWarnedSubjects,Ce as buildSubscribeMessage,we as buildUnsubscribeMessage,b as channelSubject,me as collectorOnlySubject,k as createBusContext,ge as createBusInstance,ye as createChannelEndpoint,Q as createExtensionNamespace,C as createFilteredBus,je as createProjectedTelemetryTransport,Te as createSubjectTelemetryProjectorRegistry,N as defaultTransports,E as defineSubjectExtension,a as deserializeTransportError,j as extendSubject,i as findInErrorChain,e as getFullSubjectForSubjectDefinition,O as getPath,ne as getSubjectFromBusMessage,h as handleCorrelationResponse,T as hostLocalRequest,S as isNoHandlerErrorForSubject,oe as isRequestCancellation,fe as isRequestSchema,A as localSubject,se as matchesAnySubscription,u as matchesFilter,le as matchesSubscription,ce as mergeFilters,be as openChannel,_e as parseBusUrl,y as projectSubjectTelemetryFacts,r as serializeTransportError,I as shouldReceiveMessage,ie as trackMessageCorrelation,t as transportErrorData,ue as waitForSubscriptionPropagation};
1
+ import{$ as e,A as t,B as n,C as r,D as i,E as a,F as o,G as s,H as c,I as l,J as u,K as d,L as ee,M as te,N as f,O as ne,P as re,Q as p,R as m,S as h,T as ie,U as ae,V as g,W as oe,X as se,Y as ce,Z as le,_ as ue,a as de,at as fe,b as pe,d as _,et as me,f as he,g as v,h as y,i as ge,it as b,j as x,k as S,l as C,m as w,nt as T,o as E,p as D,q as O,r as k,rt as A,s as j,t as M,tt as N,u as P,v as F,w as I,x as L,y as _e,z as ve}from"../bus-DzEgIHGt.mjs";import{z as R}from"zod";const z={"channel.open":{request:R.object({endpoint:R.string(),token:R.string(),clientPubKey:R.string(),transports:R.array(R.string())}),response:R.object({channelId:R.string(),endpointPubKey:R.string()})}};function B(e){let t=e instanceof Uint8Array?e:new Uint8Array(e),n=Array(t.length);for(let e=0;e<t.length;e++)n[e]=String.fromCharCode(t[e]);return btoa(n.join(``))}function V(e){let t=atob(e),n=new Uint8Array(t.length);for(let e=0;e<t.length;e++)n[e]=t.charCodeAt(e);return n.buffer}async function H(){return globalThis.crypto.subtle.generateKey({name:`ECDH`,namedCurve:`P-256`},!1,[`deriveKey`])}async function U(e){return B(await globalThis.crypto.subtle.exportKey(`raw`,e))}async function W(e){let t=V(e);return globalThis.crypto.subtle.importKey(`raw`,t,{name:`ECDH`,namedCurve:`P-256`},!1,[])}async function G(e,t){return globalThis.crypto.subtle.deriveKey({name:`ECDH`,public:t},e,{name:`AES-GCM`,length:256},!1,[`encrypt`,`decrypt`])}async function K(e,t,n){let r=globalThis.crypto.getRandomValues(new Uint8Array(12)),i=new TextEncoder().encode(t),a={name:`AES-GCM`,iv:r};n!==void 0&&(a.additionalData=new TextEncoder().encode(n));let o=await globalThis.crypto.subtle.encrypt(a,e,i);return{iv:B(r),data:B(o)}}async function q(e,t,n){let r=V(t.iv),i=V(t.data),a={name:`AES-GCM`,iv:r};n!==void 0&&(a.additionalData=new TextEncoder().encode(n));let o=await globalThis.crypto.subtle.decrypt(a,e,i);return new TextDecoder().decode(o)}function J(e,t){return{subject:t,$meta:{namespace:`channel:${e}`,isRequest:!1,payload:{},local:!1,channel:!1}}}function Y(e,t){return{subject:t,$meta:{namespace:`channel:${e}`,isRequest:!0,payload:{},local:!1,channel:!1}}}var X=class{channelId;sharedKey;context;transportNames;cleanups=[];pendingRequests=new Set;closed=!1;constructor(e,t,n,r){this.channelId=e,this.sharedKey=t,this.context=n,this.transportNames=r;let i=J(e,`$close`);this.cleanups.push(this.registerEventHandler(i,t,e=>{this.handlePeerClose()}))}on(e,t,n){this.assertOpen();let r=this.requireKey(),i=e.$meta.isRequest?this.registerRequestHandler(e,r,t,n):this.registerEventHandler(e,r,t,n);return this.cleanups.push(i),()=>{i();let e=this.cleanups.indexOf(i);e!==-1&&this.cleanups.splice(e,1)}}once(e,t){this.assertOpen();let n=this.requireKey(),r=null,i=(e=>{let n=r;if(r=null,n){let e=this.cleanups.indexOf(n);e!==-1&&this.cleanups.splice(e,1)}return n?.(),t(e)});return r=e.$meta.isRequest?this.registerRequestHandler(e,n,i):this.registerEventHandler(e,n,i),this.cleanups.push(r),()=>{if(r){let e=r;r=null;let t=this.cleanups.indexOf(e);t!==-1&&this.cleanups.splice(t,1),e()}}}async emit(e,t){this.assertOpen();let n=this.requireKey(),r=J(this.channelId,e.subject),i=await K(n,JSON.stringify(t),`${this.channelId}:${e.subject}:evt`);await w(this.context,r,i,{...this.transportNames?{transports:[...this.transportNames]}:{}})}async request(e,t,n){this.assertOpen();let r=this.requireKey(),i=new AbortController;this.pendingRequests.add(i);try{let a=Y(this.channelId,e.subject),o=await K(r,JSON.stringify(t),`${this.channelId}:${e.subject}:req`),s=await q(r,await _(this.context,a,o,{signal:i.signal,...n?.timeout===void 0?{}:{timeout:n.timeout},...this.transportNames?{transports:[...this.transportNames]}:{}}),`${this.channelId}:${e.subject}:res`);return JSON.parse(s)}finally{this.pendingRequests.delete(i)}}async requestOptional(e,t,n){try{return{handled:!0,data:await this.request(e,t,n)}}catch(e){if(e instanceof l)return{handled:!1};throw e}}close(){if(this.closed)return;this.closed=!0;let e=this.sharedKey;if(e){let t=J(this.channelId,`$close`);K(e,JSON.stringify({}),`${this.channelId}:$close:evt`).then(e=>w(this.context,t,e,{...this.transportNames?{transports:[...this.transportNames]}:{}})).catch(()=>{})}this.abortPendingRequests(),this.runCleanups(),this.sharedKey=null}assertOpen(){if(this.closed)throw new g(this.channelId)}requireKey(){return this.sharedKey}registerEventHandler(e,t,n,r){let i=J(this.channelId,e.subject),a=`${this.channelId}:${e.subject}:evt`;return v(this.context,i,async e=>{let r=await q(t,e.payload,a),i=JSON.parse(r);return n({...e,payload:i})},r)}registerRequestHandler(e,t,n,r){let i=Y(this.channelId,e.subject),a=`${this.channelId}:${e.subject}:req`,o=`${this.channelId}:${e.subject}:res`;return v(this.context,i,async e=>{let r=await q(t,e.payload,a),i=JSON.parse(r),s,c=e=>{s={value:e}},l=e=>{s={value:{...s?.value??{},...e}}},u=async()=>{let n=s;if(await e.next(),n!==void 0){s=n;return}let r=e.result;if(r!==void 0){let e=await q(t,r,o);s={value:JSON.parse(e)}}};if(await n({...e,payload:i,get result(){return s?.value},setResult:c,extendResult:l,next:u}),s!==void 0){let n=await K(t,JSON.stringify(s.value),o);e.setResult(n)}},r)}handlePeerClose(){this.closed||(this.closed=!0,this.abortPendingRequests(),this.runCleanups(),this.sharedKey=null)}abortPendingRequests(){let e=new g(this.channelId);for(let t of this.pendingRequests)t.abort(e);this.pendingRequests.clear()}runCleanups(){for(let e of this.cleanups)try{e()}catch{}this.cleanups.length=0}};function Z(e){return e.namespaceRegistry.registerNamespace(p(`system`,z)).subjects.channel.open}function ye(e,t,n,r){let i=v(e,Z(e),async i=>{if(i.payload.endpoint!==t){await i.next();return}if(i.payload.token!==r.token)throw new c(t);let{publicKey:a,privateKey:o}=await H(),s=await G(o,await W(i.payload.clientPubKey)),l=globalThis.crypto.randomUUID(),u=new Set(e.transportRegistry.names()),d=new X(l,s,e,(i.payload.transports??[]).filter(e=>u.has(e)));try{n(d),i.setResult({channelId:l,endpointPubKey:await U(a)})}catch(e){throw d.close(),e}});return{name:t,token:r.token,close:i}}async function be(e,t,n){let r=Z(e),{publicKey:i,privateKey:a}=await H(),o=await U(i),s=n.transports!==void 0,c=s?[...n.transports]:[...e.transportRegistry.names()],l=s?{transports:c}:void 0,u=await _(e,r,{endpoint:t,token:n.token,clientPubKey:o,transports:c},l),d=await G(a,await W(u.endpointPubKey));return new X(u.channelId,d,e,c)}var xe=class{pending;constructor(){this.pending=new Map}track(e,t,n){return new Promise((r,i)=>{if(n?.aborted){i(s(n.reason));return}let a=t===0?void 0:setTimeout(()=>{let n=this.pending.get(e);n!==void 0&&(clearTimeout(n.timeoutId),n.removeAbortListener?.(),this.pending.delete(e),n.reject(new f(e,t)))},t);if(this.pending.set(e,{resolve:r,reject:i,timeoutId:a,removeAbortListener:void 0}),n){let t=()=>{this.reject(e,s(n.reason))};n.addEventListener(`abort`,t,{once:!0});let r=()=>{n.removeEventListener(`abort`,t)},i=this.pending.get(e);i&&(i.removeAbortListener=r)}n?.aborted&&this.reject(e,s(n.reason))})}resolve(e,t){let n=this.pending.get(e);n&&(clearTimeout(n.timeoutId),n.removeAbortListener?.(),this.pending.delete(e),n.resolve(t))}reject(e,t){let n=this.pending.get(e);n&&(clearTimeout(n.timeoutId),n.removeAbortListener?.(),this.pending.delete(e),n.reject(t))}cancel(e,t){this.reject(e,t??s(void 0))}rejectAll(e){for(let[t,n]of this.pending.entries())clearTimeout(n.timeoutId),n.removeAbortListener?.(),n.reject(e);this.pending.clear()}cleanup(){this.rejectAll(Error(`Transport disconnected`))}};const Se=p(`bus:lifecycle`,de).subjects;function Ce(e,t){let n={},r={},i={};for(let[t,a]of e)n[t]=a.priorities,r[t]=a.deliveryClass??`relayable`,a.filter!==void 0&&(i[t]=a.filter);return{type:`subscribe`,...t===void 0?{}:{ackId:t},subjects:n,deliveryClasses:r,...Object.keys(i).length>0&&{filters:i}}}function we(e,t){return{type:`unsubscribe`,...t===void 0?{}:{ackId:t},subjects:e}}function Q(e,t){let n=e.trim();if(n.length===0||n.startsWith(`extension:`))throw Error(`Invalid extensionName: expected a non-empty extension name without the "extension:" prefix.`);let r=n;return{...p(`extension:${r}`,t.schemas),domain:r,extensions:t.extensions??{}}}function $(e,t){return`${e}.${t}`}function Te(){let e=new Map;return{register(t){let n=$(t.namespace,t.subject);return e.set(n,t),()=>{e.get(n)===t&&e.delete(n)}},get(t,n){return e.get($(t,n))}}}const Ee=x.fact.$meta.namespace,De=x.fact.subject;function Oe(e){return e.type===`event`||e.type===`request`||e.type===`broadcast`}async function ke(e,t,n,r,i,a){let o=y({message:t,direction:`outbound`,observedAt:a(),machineId:i,namespaceRegistry:n,projectorRegistry:r});for(let n of o)await e.send({type:`event`,namespace:Ee,subject:De,payload:n,messageId:`${t.messageId}:telemetry:${n.factId}`,correlationId:t.correlationId})}function Ae(e,t,n,r,i){return async function(a,o){if(!Oe(a))return!0;if(await ke(e,a,t,n,r,i),a.type===`request`)throw Error(`Projected telemetry transport cannot satisfy request responses; exclude it from request routing.`);return a.type===`broadcast`?[]:!0}}function je(e){let{inner:t,namespaceRegistry:n,projectorRegistry:r,machineId:i,now:a=Date.now}=e,o={name:e.name,send:Ae(t,n,r,i,a),onReceive(e){return t.onReceive(async()=>{})},connect(){return t.connect()},disconnect(){return t.disconnect()},subscribe(){return Promise.resolve()},unsubscribe(){return Promise.resolve()},get ready(){return t.ready},get onNewReadySession(){return t.onNewReadySession},set onNewReadySession(e){t.onNewReadySession=e},get onConnected(){return t.onConnected},set onConnected(e){t.onConnected=e},get onDisconnected(){return t.onDisconnected},set onDisconnected(e){t.onDisconnected=e},isReady(){return t.isReady?.()??!0},cancelRequest(e,n){t.cancelRequest?.(e,n)},onBroadcastResults(e,n,r){t.onBroadcastResults?.(e,n,r)}};return t.reconnect&&(o.reconnect=()=>t.reconnect()),o}export{ae as BusAbortError,d as BusError,Se as BusLifecycle,m as CONNECTION_LOST_ERROR_CODE,c as ChannelAuthError,g as ChannelClosedError,n as ChannelOnlyError,ve as ConnectionLostError,xe as CorrelationTracker,he as DEFAULT_READINESS_TIMEOUT_MS,D as DEFAULT_REQUEST_TIMEOUT_MS,pe as LOCAL_ORIGIN,ee as LocalSubjectError,M as MakaioBus,o as NO_HANDLER_ERROR_CODE,l as NoHandlerError,P as OnceAbortError,L as REMOTE_ORIGIN,re as RequestError,z as SystemChannelSchemas,f as TimeoutError,te as ValidationError,F as __resetWarnedSubjects,Ce as buildSubscribeMessage,we as buildUnsubscribeMessage,b as channelSubject,me as collectorOnlySubject,k as createBusContext,ge as createBusInstance,ye as createChannelEndpoint,Q as createExtensionNamespace,C as createFilteredBus,je as createProjectedTelemetryTransport,Te as createSubjectTelemetryProjectorRegistry,N as defaultTransports,E as defineSubjectExtension,a as deserializeTransportError,j as extendSubject,i as findInErrorChain,e as getFullSubjectForSubjectDefinition,O as getPath,ne as getSubjectFromBusMessage,h as handleCorrelationResponse,T as hostLocalRequest,S as isNoHandlerErrorForSubject,oe as isRequestCancellation,fe as isRequestSchema,A as localSubject,se as matchesAnySubscription,u as matchesFilter,le as matchesSubscription,ce as mergeFilters,be as openChannel,_e as parseBusUrl,y as projectSubjectTelemetryFacts,r as serializeTransportError,I as shouldReceiveMessage,ie as trackMessageCorrelation,t as transportErrorData,ue as waitForSubscriptionPropagation};