@arke-institute/rhiza 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (230) hide show
  1. package/README.md +106 -0
  2. package/dist/__tests__/fixtures/index.d.ts +9 -0
  3. package/dist/__tests__/fixtures/index.d.ts.map +1 -0
  4. package/dist/__tests__/fixtures/index.js +12 -0
  5. package/dist/__tests__/fixtures/index.js.map +1 -0
  6. package/dist/__tests__/fixtures/kladoi/index.d.ts +165 -0
  7. package/dist/__tests__/fixtures/kladoi/index.d.ts.map +1 -0
  8. package/dist/__tests__/fixtures/kladoi/index.js +270 -0
  9. package/dist/__tests__/fixtures/kladoi/index.js.map +1 -0
  10. package/dist/__tests__/fixtures/logs/index.d.ts +19 -0
  11. package/dist/__tests__/fixtures/logs/index.d.ts.map +1 -0
  12. package/dist/__tests__/fixtures/logs/index.js +545 -0
  13. package/dist/__tests__/fixtures/logs/index.js.map +1 -0
  14. package/dist/__tests__/fixtures/mock-client.d.ts +127 -0
  15. package/dist/__tests__/fixtures/mock-client.d.ts.map +1 -0
  16. package/dist/__tests__/fixtures/mock-client.js +415 -0
  17. package/dist/__tests__/fixtures/mock-client.js.map +1 -0
  18. package/dist/__tests__/fixtures/rhizai/index.d.ts +54 -0
  19. package/dist/__tests__/fixtures/rhizai/index.d.ts.map +1 -0
  20. package/dist/__tests__/fixtures/rhizai/index.js +283 -0
  21. package/dist/__tests__/fixtures/rhizai/index.js.map +1 -0
  22. package/dist/__tests__/unit/fixtures.test.d.ts +10 -0
  23. package/dist/__tests__/unit/fixtures.test.d.ts.map +1 -0
  24. package/dist/__tests__/unit/fixtures.test.js +275 -0
  25. package/dist/__tests__/unit/fixtures.test.js.map +1 -0
  26. package/dist/__tests__/unit/handoff/gather.test.d.ts +8 -0
  27. package/dist/__tests__/unit/handoff/gather.test.d.ts.map +1 -0
  28. package/dist/__tests__/unit/handoff/gather.test.js +176 -0
  29. package/dist/__tests__/unit/handoff/gather.test.js.map +1 -0
  30. package/dist/__tests__/unit/handoff/interpret.test.d.ts +9 -0
  31. package/dist/__tests__/unit/handoff/interpret.test.d.ts.map +1 -0
  32. package/dist/__tests__/unit/handoff/interpret.test.js +370 -0
  33. package/dist/__tests__/unit/handoff/interpret.test.js.map +1 -0
  34. package/dist/__tests__/unit/handoff/route.test.d.ts +8 -0
  35. package/dist/__tests__/unit/handoff/route.test.d.ts.map +1 -0
  36. package/dist/__tests__/unit/handoff/route.test.js +271 -0
  37. package/dist/__tests__/unit/handoff/route.test.js.map +1 -0
  38. package/dist/__tests__/unit/handoff/scatter.test.d.ts +7 -0
  39. package/dist/__tests__/unit/handoff/scatter.test.d.ts.map +1 -0
  40. package/dist/__tests__/unit/handoff/scatter.test.js +54 -0
  41. package/dist/__tests__/unit/handoff/scatter.test.js.map +1 -0
  42. package/dist/__tests__/unit/resume.test.d.ts +8 -0
  43. package/dist/__tests__/unit/resume.test.d.ts.map +1 -0
  44. package/dist/__tests__/unit/resume.test.js +134 -0
  45. package/dist/__tests__/unit/resume.test.js.map +1 -0
  46. package/dist/__tests__/unit/status.test.d.ts +8 -0
  47. package/dist/__tests__/unit/status.test.d.ts.map +1 -0
  48. package/dist/__tests__/unit/status.test.js +164 -0
  49. package/dist/__tests__/unit/status.test.js.map +1 -0
  50. package/dist/__tests__/unit/target.test.d.ts +8 -0
  51. package/dist/__tests__/unit/target.test.d.ts.map +1 -0
  52. package/dist/__tests__/unit/target.test.js +116 -0
  53. package/dist/__tests__/unit/target.test.js.map +1 -0
  54. package/dist/__tests__/unit/traverse.test.d.ts +8 -0
  55. package/dist/__tests__/unit/traverse.test.d.ts.map +1 -0
  56. package/dist/__tests__/unit/traverse.test.js +143 -0
  57. package/dist/__tests__/unit/traverse.test.js.map +1 -0
  58. package/dist/__tests__/unit/validation/klados.test.d.ts +16 -0
  59. package/dist/__tests__/unit/validation/klados.test.d.ts.map +1 -0
  60. package/dist/__tests__/unit/validation/klados.test.js +275 -0
  61. package/dist/__tests__/unit/validation/klados.test.js.map +1 -0
  62. package/dist/__tests__/unit/validation/rhiza.test.d.ts +16 -0
  63. package/dist/__tests__/unit/validation/rhiza.test.d.ts.map +1 -0
  64. package/dist/__tests__/unit/validation/rhiza.test.js +612 -0
  65. package/dist/__tests__/unit/validation/rhiza.test.js.map +1 -0
  66. package/dist/__tests__/unit/validation/runtime.test.d.ts +11 -0
  67. package/dist/__tests__/unit/validation/runtime.test.d.ts.map +1 -0
  68. package/dist/__tests__/unit/validation/runtime.test.js +553 -0
  69. package/dist/__tests__/unit/validation/runtime.test.js.map +1 -0
  70. package/dist/__tests__/unit/worker/errors.test.d.ts +2 -0
  71. package/dist/__tests__/unit/worker/errors.test.d.ts.map +1 -0
  72. package/dist/__tests__/unit/worker/errors.test.js +226 -0
  73. package/dist/__tests__/unit/worker/errors.test.js.map +1 -0
  74. package/dist/__tests__/unit/worker/job.test.d.ts +2 -0
  75. package/dist/__tests__/unit/worker/job.test.d.ts.map +1 -0
  76. package/dist/__tests__/unit/worker/job.test.js +233 -0
  77. package/dist/__tests__/unit/worker/job.test.js.map +1 -0
  78. package/dist/client/index.d.ts +10 -0
  79. package/dist/client/index.d.ts.map +1 -0
  80. package/dist/client/index.js +8 -0
  81. package/dist/client/index.js.map +1 -0
  82. package/dist/client/interface.d.ts +142 -0
  83. package/dist/client/interface.d.ts.map +1 -0
  84. package/dist/client/interface.js +8 -0
  85. package/dist/client/interface.js.map +1 -0
  86. package/dist/client/mock.d.ts +95 -0
  87. package/dist/client/mock.d.ts.map +1 -0
  88. package/dist/client/mock.js +795 -0
  89. package/dist/client/mock.js.map +1 -0
  90. package/dist/client/types.d.ts +344 -0
  91. package/dist/client/types.d.ts.map +1 -0
  92. package/dist/client/types.js +8 -0
  93. package/dist/client/types.js.map +1 -0
  94. package/dist/handoff/gather-api.d.ts +60 -0
  95. package/dist/handoff/gather-api.d.ts.map +1 -0
  96. package/dist/handoff/gather-api.js +130 -0
  97. package/dist/handoff/gather-api.js.map +1 -0
  98. package/dist/handoff/gather.d.ts +59 -0
  99. package/dist/handoff/gather.d.ts.map +1 -0
  100. package/dist/handoff/gather.js +134 -0
  101. package/dist/handoff/gather.js.map +1 -0
  102. package/dist/handoff/index.d.ts +19 -0
  103. package/dist/handoff/index.d.ts.map +1 -0
  104. package/dist/handoff/index.js +25 -0
  105. package/dist/handoff/index.js.map +1 -0
  106. package/dist/handoff/interpret.d.ts +79 -0
  107. package/dist/handoff/interpret.d.ts.map +1 -0
  108. package/dist/handoff/interpret.js +197 -0
  109. package/dist/handoff/interpret.js.map +1 -0
  110. package/dist/handoff/invoke.d.ts +82 -0
  111. package/dist/handoff/invoke.d.ts.map +1 -0
  112. package/dist/handoff/invoke.js +196 -0
  113. package/dist/handoff/invoke.js.map +1 -0
  114. package/dist/handoff/route.d.ts +25 -0
  115. package/dist/handoff/route.d.ts.map +1 -0
  116. package/dist/handoff/route.js +65 -0
  117. package/dist/handoff/route.js.map +1 -0
  118. package/dist/handoff/scatter-api.d.ts +62 -0
  119. package/dist/handoff/scatter-api.d.ts.map +1 -0
  120. package/dist/handoff/scatter-api.js +81 -0
  121. package/dist/handoff/scatter-api.js.map +1 -0
  122. package/dist/handoff/scatter.d.ts +19 -0
  123. package/dist/handoff/scatter.d.ts.map +1 -0
  124. package/dist/handoff/scatter.js +27 -0
  125. package/dist/handoff/scatter.js.map +1 -0
  126. package/dist/handoff/target.d.ts +16 -0
  127. package/dist/handoff/target.d.ts.map +1 -0
  128. package/dist/handoff/target.js +51 -0
  129. package/dist/handoff/target.js.map +1 -0
  130. package/dist/index.d.ts +42 -0
  131. package/dist/index.d.ts.map +1 -0
  132. package/dist/index.js +52 -0
  133. package/dist/index.js.map +1 -0
  134. package/dist/logging/index.d.ts +4 -0
  135. package/dist/logging/index.d.ts.map +1 -0
  136. package/dist/logging/index.js +3 -0
  137. package/dist/logging/index.js.map +1 -0
  138. package/dist/logging/logger.d.ts +52 -0
  139. package/dist/logging/logger.d.ts.map +1 -0
  140. package/dist/logging/logger.js +70 -0
  141. package/dist/logging/logger.js.map +1 -0
  142. package/dist/logging/writer.d.ts +63 -0
  143. package/dist/logging/writer.d.ts.map +1 -0
  144. package/dist/logging/writer.js +160 -0
  145. package/dist/logging/writer.js.map +1 -0
  146. package/dist/resume/index.d.ts +77 -0
  147. package/dist/resume/index.d.ts.map +1 -0
  148. package/dist/resume/index.js +110 -0
  149. package/dist/resume/index.js.map +1 -0
  150. package/dist/status/index.d.ts +54 -0
  151. package/dist/status/index.d.ts.map +1 -0
  152. package/dist/status/index.js +107 -0
  153. package/dist/status/index.js.map +1 -0
  154. package/dist/traverse/index.d.ts +53 -0
  155. package/dist/traverse/index.d.ts.map +1 -0
  156. package/dist/traverse/index.js +142 -0
  157. package/dist/traverse/index.js.map +1 -0
  158. package/dist/types/batch.d.ts +53 -0
  159. package/dist/types/batch.d.ts.map +1 -0
  160. package/dist/types/batch.js +2 -0
  161. package/dist/types/batch.js.map +1 -0
  162. package/dist/types/index.d.ts +10 -0
  163. package/dist/types/index.d.ts.map +1 -0
  164. package/dist/types/index.js +2 -0
  165. package/dist/types/index.js.map +1 -0
  166. package/dist/types/klados.d.ts +63 -0
  167. package/dist/types/klados.d.ts.map +1 -0
  168. package/dist/types/klados.js +2 -0
  169. package/dist/types/klados.js.map +1 -0
  170. package/dist/types/log.d.ts +107 -0
  171. package/dist/types/log.d.ts.map +1 -0
  172. package/dist/types/log.js +2 -0
  173. package/dist/types/log.js.map +1 -0
  174. package/dist/types/refs.d.ts +58 -0
  175. package/dist/types/refs.d.ts.map +1 -0
  176. package/dist/types/refs.js +43 -0
  177. package/dist/types/refs.js.map +1 -0
  178. package/dist/types/request.d.ts +69 -0
  179. package/dist/types/request.d.ts.map +1 -0
  180. package/dist/types/request.js +2 -0
  181. package/dist/types/request.js.map +1 -0
  182. package/dist/types/response.d.ts +31 -0
  183. package/dist/types/response.d.ts.map +1 -0
  184. package/dist/types/response.js +2 -0
  185. package/dist/types/response.js.map +1 -0
  186. package/dist/types/rhiza.d.ts +100 -0
  187. package/dist/types/rhiza.d.ts.map +1 -0
  188. package/dist/types/rhiza.js +2 -0
  189. package/dist/types/rhiza.js.map +1 -0
  190. package/dist/types/status.d.ts +84 -0
  191. package/dist/types/status.d.ts.map +1 -0
  192. package/dist/types/status.js +2 -0
  193. package/dist/types/status.js.map +1 -0
  194. package/dist/utils/id.d.ts +15 -0
  195. package/dist/utils/id.d.ts.map +1 -0
  196. package/dist/utils/id.js +25 -0
  197. package/dist/utils/id.js.map +1 -0
  198. package/dist/utils/index.d.ts +2 -0
  199. package/dist/utils/index.d.ts.map +1 -0
  200. package/dist/utils/index.js +2 -0
  201. package/dist/utils/index.js.map +1 -0
  202. package/dist/validation/index.d.ts +9 -0
  203. package/dist/validation/index.d.ts.map +1 -0
  204. package/dist/validation/index.js +9 -0
  205. package/dist/validation/index.js.map +1 -0
  206. package/dist/validation/validate-klados.d.ts +38 -0
  207. package/dist/validation/validate-klados.d.ts.map +1 -0
  208. package/dist/validation/validate-klados.js +139 -0
  209. package/dist/validation/validate-klados.js.map +1 -0
  210. package/dist/validation/validate-rhiza.d.ts +29 -0
  211. package/dist/validation/validate-rhiza.d.ts.map +1 -0
  212. package/dist/validation/validate-rhiza.js +382 -0
  213. package/dist/validation/validate-rhiza.js.map +1 -0
  214. package/dist/validation/validate-runtime.d.ts +28 -0
  215. package/dist/validation/validate-runtime.d.ts.map +1 -0
  216. package/dist/validation/validate-runtime.js +212 -0
  217. package/dist/validation/validate-runtime.js.map +1 -0
  218. package/dist/worker/errors.d.ts +77 -0
  219. package/dist/worker/errors.d.ts.map +1 -0
  220. package/dist/worker/errors.js +143 -0
  221. package/dist/worker/errors.js.map +1 -0
  222. package/dist/worker/index.d.ts +8 -0
  223. package/dist/worker/index.d.ts.map +1 -0
  224. package/dist/worker/index.js +8 -0
  225. package/dist/worker/index.js.map +1 -0
  226. package/dist/worker/job.d.ts +150 -0
  227. package/dist/worker/job.d.ts.map +1 -0
  228. package/dist/worker/job.js +280 -0
  229. package/dist/worker/job.js.map +1 -0
  230. package/package.json +48 -0
@@ -0,0 +1,59 @@
1
+ /**
2
+ * Gather Operations
3
+ *
4
+ * Pure functions for fan-in (gather) operations that collect scattered outputs
5
+ * and determine when all slots are complete for aggregation.
6
+ */
7
+ import type { BatchEntity } from '../types/batch';
8
+ /**
9
+ * Error information for a failed slot
10
+ */
11
+ export interface SlotError {
12
+ code: string;
13
+ message: string;
14
+ retryable?: boolean;
15
+ }
16
+ /**
17
+ * Result of completing a batch slot
18
+ */
19
+ export interface BatchSlotResult {
20
+ batch: BatchEntity;
21
+ isLast: boolean;
22
+ allOutputs?: string[][];
23
+ }
24
+ /**
25
+ * Result of erroring a batch slot
26
+ */
27
+ export interface BatchSlotErrorResult {
28
+ batch: BatchEntity;
29
+ isTerminal: boolean;
30
+ errors?: Array<{
31
+ slotIndex: number;
32
+ error: SlotError;
33
+ }>;
34
+ }
35
+ /**
36
+ * Complete a batch slot with its outputs
37
+ *
38
+ * Updates the slot status and tracks completion. If this is the last slot,
39
+ * collects all outputs in slot order for the gather target.
40
+ *
41
+ * @param batch - The batch entity
42
+ * @param slotIndex - The slot index to complete
43
+ * @param outputIds - The output entity IDs produced by this slot
44
+ * @returns Updated batch and whether this was the last slot
45
+ */
46
+ export declare function completeBatchSlot(batch: BatchEntity, slotIndex: number, outputIds: string[]): BatchSlotResult;
47
+ /**
48
+ * Mark a batch slot as errored
49
+ *
50
+ * Updates the slot status with error information. If all slots become terminal
51
+ * (complete or error), marks the batch as terminal with error status.
52
+ *
53
+ * @param batch - The batch entity
54
+ * @param slotIndex - The slot index that errored
55
+ * @param error - The error information
56
+ * @returns Updated batch and terminal status
57
+ */
58
+ export declare function errorBatchSlot(batch: BatchEntity, slotIndex: number, error: SlotError): BatchSlotErrorResult;
59
+ //# sourceMappingURL=gather.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gather.d.ts","sourceRoot":"","sources":["../../src/handoff/gather.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,WAAW,EAA8B,MAAM,gBAAgB,CAAC;AAE9E;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,KAAK,EAAE,WAAW,CAAC;IACnB,MAAM,EAAE,OAAO,CAAC;IAChB,UAAU,CAAC,EAAE,MAAM,EAAE,EAAE,CAAC;CACzB;AAED;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,KAAK,EAAE,WAAW,CAAC;IACnB,UAAU,EAAE,OAAO,CAAC;IACpB,MAAM,CAAC,EAAE,KAAK,CAAC;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,SAAS,CAAA;KAAE,CAAC,CAAC;CACzD;AAgCD;;;;;;;;;;GAUG;AACH,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,WAAW,EAClB,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,MAAM,EAAE,GAClB,eAAe,CA8CjB;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,cAAc,CAC5B,KAAK,EAAE,WAAW,EAClB,SAAS,EAAE,MAAM,EACjB,KAAK,EAAE,SAAS,GACf,oBAAoB,CA6CtB"}
@@ -0,0 +1,134 @@
1
+ /**
2
+ * Gather Operations
3
+ *
4
+ * Pure functions for fan-in (gather) operations that collect scattered outputs
5
+ * and determine when all slots are complete for aggregation.
6
+ */
7
+ /**
8
+ * Check if all slots are terminal (complete or error)
9
+ */
10
+ function allSlotsTerminal(slots) {
11
+ return slots.every((s) => s.status === 'complete' || s.status === 'error');
12
+ }
13
+ /**
14
+ * Check if any slot has an error
15
+ */
16
+ function hasErrors(slots) {
17
+ return slots.some((s) => s.status === 'error');
18
+ }
19
+ /**
20
+ * Collect all errors from slots
21
+ */
22
+ function collectErrors(slots) {
23
+ const errors = [];
24
+ for (let i = 0; i < slots.length; i++) {
25
+ if (slots[i].status === 'error' && slots[i].error) {
26
+ errors.push({
27
+ slotIndex: i,
28
+ error: slots[i].error,
29
+ });
30
+ }
31
+ }
32
+ return errors;
33
+ }
34
+ /**
35
+ * Complete a batch slot with its outputs
36
+ *
37
+ * Updates the slot status and tracks completion. If this is the last slot,
38
+ * collects all outputs in slot order for the gather target.
39
+ *
40
+ * @param batch - The batch entity
41
+ * @param slotIndex - The slot index to complete
42
+ * @param outputIds - The output entity IDs produced by this slot
43
+ * @returns Updated batch and whether this was the last slot
44
+ */
45
+ export function completeBatchSlot(batch, slotIndex, outputIds) {
46
+ const props = batch.properties;
47
+ // Clone slots array
48
+ const updatedSlots = [...props.slots];
49
+ // Update the slot
50
+ updatedSlots[slotIndex] = {
51
+ ...updatedSlots[slotIndex],
52
+ status: 'complete',
53
+ output_ids: outputIds,
54
+ completed_at: new Date().toISOString(),
55
+ };
56
+ // Check if all slots are terminal
57
+ const allTerminal = allSlotsTerminal(updatedSlots);
58
+ const hasAnyErrors = hasErrors(updatedSlots);
59
+ // Build updated properties
60
+ const updatedProperties = {
61
+ ...props,
62
+ slots: updatedSlots,
63
+ completed: props.completed + 1,
64
+ status: allTerminal ? (hasAnyErrors ? 'error' : 'complete') : props.status,
65
+ completed_at: allTerminal ? new Date().toISOString() : undefined,
66
+ };
67
+ // Build updated batch
68
+ const updatedBatch = {
69
+ ...batch,
70
+ properties: updatedProperties,
71
+ };
72
+ // If this is the last slot (all complete, no errors), collect all outputs in order
73
+ const isLast = allTerminal && !hasAnyErrors;
74
+ let allOutputs;
75
+ if (isLast) {
76
+ allOutputs = updatedSlots.map((slot) => slot.output_ids ?? []);
77
+ }
78
+ return {
79
+ batch: updatedBatch,
80
+ isLast,
81
+ allOutputs,
82
+ };
83
+ }
84
+ /**
85
+ * Mark a batch slot as errored
86
+ *
87
+ * Updates the slot status with error information. If all slots become terminal
88
+ * (complete or error), marks the batch as terminal with error status.
89
+ *
90
+ * @param batch - The batch entity
91
+ * @param slotIndex - The slot index that errored
92
+ * @param error - The error information
93
+ * @returns Updated batch and terminal status
94
+ */
95
+ export function errorBatchSlot(batch, slotIndex, error) {
96
+ const props = batch.properties;
97
+ // Clone slots array
98
+ const updatedSlots = [...props.slots];
99
+ // Update the slot with error
100
+ updatedSlots[slotIndex] = {
101
+ ...updatedSlots[slotIndex],
102
+ status: 'error',
103
+ error: {
104
+ code: error.code,
105
+ message: error.message,
106
+ },
107
+ completed_at: new Date().toISOString(),
108
+ };
109
+ // Check if all slots are terminal
110
+ const allTerminal = allSlotsTerminal(updatedSlots);
111
+ // Build updated properties
112
+ const updatedProperties = {
113
+ ...props,
114
+ slots: updatedSlots,
115
+ status: allTerminal ? 'error' : props.status,
116
+ completed_at: allTerminal ? new Date().toISOString() : undefined,
117
+ };
118
+ // Build updated batch
119
+ const updatedBatch = {
120
+ ...batch,
121
+ properties: updatedProperties,
122
+ };
123
+ // Collect errors if terminal
124
+ let errors;
125
+ if (allTerminal) {
126
+ errors = collectErrors(updatedSlots);
127
+ }
128
+ return {
129
+ batch: updatedBatch,
130
+ isTerminal: allTerminal,
131
+ errors,
132
+ };
133
+ }
134
+ //# sourceMappingURL=gather.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gather.js","sourceRoot":"","sources":["../../src/handoff/gather.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AA+BH;;GAEG;AACH,SAAS,gBAAgB,CAAC,KAAkB;IAC1C,OAAO,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,KAAK,UAAU,IAAI,CAAC,CAAC,MAAM,KAAK,OAAO,CAAC,CAAC;AAC7E,CAAC;AAED;;GAEG;AACH,SAAS,SAAS,CAAC,KAAkB;IACnC,OAAO,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,KAAK,OAAO,CAAC,CAAC;AACjD,CAAC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,GAAG,KAAK;QACR,KAAK,EAAE,YAAY;QACnB,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM;QAC5C,YAAY,EAAE,WAAW,CAAC,CAAC,CAAC,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,SAAS;KACjE,CAAC;IAEF,sBAAsB;IACtB,MAAM,YAAY,GAAgB;QAChC,GAAG,KAAK;QACR,UAAU,EAAE,iBAAiB;KAC9B,CAAC;IAEF,6BAA6B;IAC7B,IAAI,MAAkE,CAAC;IACvE,IAAI,WAAW,EAAE,CAAC;QAChB,MAAM,GAAG,aAAa,CAAC,YAAY,CAAC,CAAC;IACvC,CAAC;IAED,OAAO;QACL,KAAK,EAAE,YAAY;QACnB,UAAU,EAAE,WAAW;QACvB,MAAM;KACP,CAAC;AACJ,CAAC"}
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Handoff Module
3
+ *
4
+ * Combines pure functions for routing and target resolution with
5
+ * SDK utilities for executing handoffs.
6
+ */
7
+ export { evaluateWhere, matchRoute } from './route';
8
+ export { resolveTarget } from './target';
9
+ export { findGatherTarget } from './scatter';
10
+ export { completeBatchSlot, errorBatchSlot, type SlotError, type BatchSlotResult, type BatchSlotErrorResult, } from './gather';
11
+ export { discoverTargetType, invokeTarget, invokeKlados, invokeRhiza, } from './invoke';
12
+ export type { InvokeOptions, InvokeResult } from './invoke';
13
+ export { createScatterBatch } from './scatter-api';
14
+ export type { CreateScatterOptions, ScatterResult } from './scatter-api';
15
+ export { completeBatchSlotWithCAS, errorBatchSlotWithCAS } from './gather-api';
16
+ export type { GatherSlotResult, GatherSlotErrorResult } from './gather-api';
17
+ export { interpretThen } from './interpret';
18
+ export type { HandoffAction, InterpretContext, InterpretResult, } from './interpret';
19
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/handoff/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAMH,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAC7C,OAAO,EACL,iBAAiB,EACjB,cAAc,EACd,KAAK,SAAS,EACd,KAAK,eAAe,EACpB,KAAK,oBAAoB,GAC1B,MAAM,UAAU,CAAC;AAOlB,OAAO,EACL,kBAAkB,EAClB,YAAY,EACZ,YAAY,EACZ,WAAW,GACZ,MAAM,UAAU,CAAC;AAClB,YAAY,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAG5D,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACnD,YAAY,EAAE,oBAAoB,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAGzE,OAAO,EAAE,wBAAwB,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AAC/E,YAAY,EAAE,gBAAgB,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AAG5E,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,YAAY,EACV,aAAa,EACb,gBAAgB,EAChB,eAAe,GAChB,MAAM,aAAa,CAAC"}
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Handoff Module
3
+ *
4
+ * Combines pure functions for routing and target resolution with
5
+ * SDK utilities for executing handoffs.
6
+ */
7
+ // ============================================================================
8
+ // Pure functions (no SDK dependency)
9
+ // ============================================================================
10
+ export { evaluateWhere, matchRoute } from './route';
11
+ export { resolveTarget } from './target';
12
+ export { findGatherTarget } from './scatter';
13
+ export { completeBatchSlot, errorBatchSlot, } from './gather';
14
+ // ============================================================================
15
+ // SDK utilities (require @arke-institute/sdk)
16
+ // ============================================================================
17
+ // Invocation
18
+ export { discoverTargetType, invokeTarget, invokeKlados, invokeRhiza, } from './invoke';
19
+ // Scatter API
20
+ export { createScatterBatch } from './scatter-api';
21
+ // Gather API
22
+ export { completeBatchSlotWithCAS, errorBatchSlotWithCAS } from './gather-api';
23
+ // Orchestration
24
+ export { interpretThen } from './interpret';
25
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/handoff/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,+EAA+E;AAC/E,qCAAqC;AACrC,+EAA+E;AAE/E,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAC7C,OAAO,EACL,iBAAiB,EACjB,cAAc,GAIf,MAAM,UAAU,CAAC;AAElB,+EAA+E;AAC/E,8CAA8C;AAC9C,+EAA+E;AAE/E,aAAa;AACb,OAAO,EACL,kBAAkB,EAClB,YAAY,EACZ,YAAY,EACZ,WAAW,GACZ,MAAM,UAAU,CAAC;AAGlB,cAAc;AACd,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAGnD,aAAa;AACb,OAAO,EAAE,wBAAwB,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AAG/E,gBAAgB;AAChB,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC"}
@@ -0,0 +1,79 @@
1
+ /**
2
+ * Handoff Interpretation
3
+ *
4
+ * The main orchestrator that interprets ThenSpec and executes handoffs.
5
+ * Combines pure logic (routing, target resolution) with SDK utilities (invocation).
6
+ */
7
+ import type { ArkeClient } from '@arke-institute/sdk';
8
+ import type { ThenSpec, FlowStep, BatchContext, BatchEntity, HandoffRecord, InvocationRecord } from '../types';
9
+ /**
10
+ * Handoff action types
11
+ */
12
+ export type HandoffAction = 'done' | 'pass' | 'scatter' | 'gather_wait' | 'gather_trigger';
13
+ /**
14
+ * Context for interpreting a handoff
15
+ */
16
+ export interface InterpretContext {
17
+ /** Arke client */
18
+ client: ArkeClient;
19
+ /** Rhiza entity ID */
20
+ rhizaId: string;
21
+ /** Current klados ID */
22
+ kladosId: string;
23
+ /** Job ID */
24
+ jobId: string;
25
+ /** Job collection ID */
26
+ jobCollectionId: string;
27
+ /** The rhiza flow definition */
28
+ flow: Record<string, FlowStep>;
29
+ /** Output entity IDs from current klados */
30
+ outputs: string[];
31
+ /** Properties of the primary output (for routing) */
32
+ outputProperties?: Record<string, unknown>;
33
+ /** Current log entry ID (for chain building) */
34
+ fromLogId: string;
35
+ /** Current path in workflow */
36
+ path: string[];
37
+ /** API base URL */
38
+ apiBase: string;
39
+ /** Permission duration in seconds (default: 3600) */
40
+ expiresIn?: number;
41
+ /** Network (test/main) */
42
+ network: 'test' | 'main';
43
+ /** Batch context if part of scatter/gather */
44
+ batchContext?: BatchContext;
45
+ }
46
+ /**
47
+ * Result of interpreting a handoff
48
+ */
49
+ export interface InterpretResult {
50
+ /** What action was taken */
51
+ action: HandoffAction;
52
+ /** Target ID that was invoked (if any) */
53
+ target?: string;
54
+ /** Whether target is klados or rhiza (discovered at runtime) */
55
+ targetType?: 'klados' | 'rhiza';
56
+ /** Invocation records for logging */
57
+ invocations?: InvocationRecord[];
58
+ /** Batch info (for scatter/gather) */
59
+ batch?: BatchEntity;
60
+ /** All outputs collected in slot order (only for gather_trigger) */
61
+ allOutputs?: string[][];
62
+ /** Handoff record for logging */
63
+ handoffRecord?: HandoffRecord;
64
+ }
65
+ /**
66
+ * Interpret and execute a ThenSpec
67
+ *
68
+ * This is the core handoff logic. It:
69
+ * 1. Examines the ThenSpec from the flow
70
+ * 2. Resolves routing if present
71
+ * 3. Executes the appropriate handoff operation
72
+ * 4. Returns info for logging and status tracking
73
+ *
74
+ * @param then - The ThenSpec to interpret
75
+ * @param context - The interpretation context
76
+ * @returns The interpretation result
77
+ */
78
+ export declare function interpretThen(then: ThenSpec, context: InterpretContext): Promise<InterpretResult>;
79
+ //# sourceMappingURL=interpret.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"interpret.d.ts","sourceRoot":"","sources":["../../src/handoff/interpret.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,KAAK,EACV,QAAQ,EACR,QAAQ,EAER,YAAY,EACZ,WAAW,EACX,aAAa,EACb,gBAAgB,EACjB,MAAM,UAAU,CAAC;AAOlB;;GAEG;AACH,MAAM,MAAM,aAAa,GACrB,MAAM,GACN,MAAM,GACN,SAAS,GACT,aAAa,GACb,gBAAgB,CAAC;AAErB;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,kBAAkB;IAClB,MAAM,EAAE,UAAU,CAAC;IAEnB,sBAAsB;IACtB,OAAO,EAAE,MAAM,CAAC;IAEhB,wBAAwB;IACxB,QAAQ,EAAE,MAAM,CAAC;IAEjB,aAAa;IACb,KAAK,EAAE,MAAM,CAAC;IAEd,wBAAwB;IACxB,eAAe,EAAE,MAAM,CAAC;IAExB,gCAAgC;IAChC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;IAE/B,4CAA4C;IAC5C,OAAO,EAAE,MAAM,EAAE,CAAC;IAElB,qDAAqD;IACrD,gBAAgB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAE3C,gDAAgD;IAChD,SAAS,EAAE,MAAM,CAAC;IAElB,+BAA+B;IAC/B,IAAI,EAAE,MAAM,EAAE,CAAC;IAEf,mBAAmB;IACnB,OAAO,EAAE,MAAM,CAAC;IAEhB,qDAAqD;IACrD,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB,0BAA0B;IAC1B,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC;IAEzB,8CAA8C;IAC9C,YAAY,CAAC,EAAE,YAAY,CAAC;CAC7B;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,4BAA4B;IAC5B,MAAM,EAAE,aAAa,CAAC;IAEtB,0CAA0C;IAC1C,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB,gEAAgE;IAChE,UAAU,CAAC,EAAE,QAAQ,GAAG,OAAO,CAAC;IAEhC,qCAAqC;IACrC,WAAW,CAAC,EAAE,gBAAgB,EAAE,CAAC;IAEjC,sCAAsC;IACtC,KAAK,CAAC,EAAE,WAAW,CAAC;IAEpB,oEAAoE;IACpE,UAAU,CAAC,EAAE,MAAM,EAAE,EAAE,CAAC;IAExB,iCAAiC;IACjC,aAAa,CAAC,EAAE,aAAa,CAAC;CAC/B;AAED;;;;;;;;;;;;GAYG;AACH,wBAAsB,aAAa,CACjC,IAAI,EAAE,QAAQ,EACd,OAAO,EAAE,gBAAgB,GACxB,OAAO,CAAC,eAAe,CAAC,CA8B1B"}
@@ -0,0 +1,197 @@
1
+ /**
2
+ * Handoff Interpretation
3
+ *
4
+ * The main orchestrator that interprets ThenSpec and executes handoffs.
5
+ * Combines pure logic (routing, target resolution) with SDK utilities (invocation).
6
+ */
7
+ import { resolveTarget } from './target';
8
+ import { findGatherTarget } from './scatter';
9
+ import { discoverTargetType, invokeTarget } from './invoke';
10
+ import { createScatterBatch } from './scatter-api';
11
+ import { completeBatchSlotWithCAS } from './gather-api';
12
+ /**
13
+ * Interpret and execute a ThenSpec
14
+ *
15
+ * This is the core handoff logic. It:
16
+ * 1. Examines the ThenSpec from the flow
17
+ * 2. Resolves routing if present
18
+ * 3. Executes the appropriate handoff operation
19
+ * 4. Returns info for logging and status tracking
20
+ *
21
+ * @param then - The ThenSpec to interpret
22
+ * @param context - The interpretation context
23
+ * @returns The interpretation result
24
+ */
25
+ export async function interpretThen(then, context) {
26
+ // ═══════════════════════════════════════════════════════════════
27
+ // Terminal: workflow ends here
28
+ // ═══════════════════════════════════════════════════════════════
29
+ if ('done' in then && then.done) {
30
+ return { action: 'done' };
31
+ }
32
+ // ═══════════════════════════════════════════════════════════════
33
+ // Pass: 1:1 direct handoff
34
+ // ═══════════════════════════════════════════════════════════════
35
+ if ('pass' in then) {
36
+ return handlePass(then, context);
37
+ }
38
+ // ═══════════════════════════════════════════════════════════════
39
+ // Scatter: 1:N fan-out
40
+ // ═══════════════════════════════════════════════════════════════
41
+ if ('scatter' in then) {
42
+ return handleScatter(then, context);
43
+ }
44
+ // ═══════════════════════════════════════════════════════════════
45
+ // Gather: N:1 fan-in
46
+ // ═══════════════════════════════════════════════════════════════
47
+ if ('gather' in then) {
48
+ return handleGather(then, context);
49
+ }
50
+ throw new Error(`Unknown ThenSpec type: ${JSON.stringify(then)}`);
51
+ }
52
+ /**
53
+ * Handle a pass handoff (1:1 direct)
54
+ */
55
+ async function handlePass(then, context) {
56
+ const { client, outputs, outputProperties } = context;
57
+ // Resolve target (may be overridden by route)
58
+ const targetRef = resolveTarget(then, outputProperties ?? {});
59
+ if (!targetRef) {
60
+ throw new Error('Failed to resolve target for pass handoff');
61
+ }
62
+ // Discover target type (or use type hint)
63
+ const targetType = targetRef.type || await discoverTargetType(client, targetRef.pi);
64
+ // Build invoke options
65
+ const invokeOptions = buildInvokeOptions(context);
66
+ // Invoke the target
67
+ const result = await invokeTarget(client, targetRef.pi, targetType, outputs, invokeOptions);
68
+ return {
69
+ action: 'pass',
70
+ target: targetRef.pi,
71
+ targetType,
72
+ invocations: [result.invocation],
73
+ handoffRecord: {
74
+ type: 'pass',
75
+ target: targetRef.pi,
76
+ target_type: targetType,
77
+ invocations: [result.invocation],
78
+ },
79
+ };
80
+ }
81
+ /**
82
+ * Handle a scatter handoff (1:N fan-out)
83
+ */
84
+ async function handleScatter(then, context) {
85
+ const { client, rhizaId, kladosId, jobId, jobCollectionId, flow, outputs, outputProperties, fromLogId, apiBase, expiresIn, network, path, } = context;
86
+ // Resolve target (may be overridden by route)
87
+ const targetRef = resolveTarget(then, outputProperties ?? {});
88
+ if (!targetRef) {
89
+ throw new Error('Failed to resolve target for scatter handoff');
90
+ }
91
+ // Discover target type
92
+ const targetType = targetRef.type || await discoverTargetType(client, targetRef.pi);
93
+ // Find the gather target from the scatter target's flow step
94
+ const gatherTargetRef = findGatherTarget(flow, targetRef.pi);
95
+ if (!gatherTargetRef) {
96
+ throw new Error(`Scatter target '${targetRef.pi}' does not have a gather handoff`);
97
+ }
98
+ // Create scatter batch and invoke targets
99
+ const scatterResult = await createScatterBatch({
100
+ client,
101
+ rhizaId,
102
+ jobId,
103
+ jobCollectionId,
104
+ sourceKladosId: kladosId,
105
+ targetId: targetRef.pi,
106
+ targetType,
107
+ gatherTargetId: gatherTargetRef.pi,
108
+ outputs,
109
+ fromLogId,
110
+ apiBase,
111
+ expiresIn,
112
+ network,
113
+ path,
114
+ });
115
+ return {
116
+ action: 'scatter',
117
+ target: targetRef.pi,
118
+ targetType,
119
+ invocations: scatterResult.invocations,
120
+ batch: scatterResult.batch,
121
+ handoffRecord: {
122
+ type: 'scatter',
123
+ target: targetRef.pi,
124
+ target_type: targetType,
125
+ batch_id: scatterResult.batchId,
126
+ invocations: scatterResult.invocations,
127
+ },
128
+ };
129
+ }
130
+ /**
131
+ * Handle a gather handoff (N:1 fan-in)
132
+ */
133
+ async function handleGather(then, context) {
134
+ const { client, outputs, outputProperties, batchContext } = context;
135
+ // Gather requires batch context
136
+ if (!batchContext) {
137
+ throw new Error('Gather handoff requires batch context');
138
+ }
139
+ // Complete this slot (CAS retry)
140
+ const slotResult = await completeBatchSlotWithCAS(client, batchContext.id, batchContext.index, outputs);
141
+ if (!slotResult.isLast) {
142
+ // Not the last slot - just waiting for others
143
+ return {
144
+ action: 'gather_wait',
145
+ batch: slotResult.batch,
146
+ };
147
+ }
148
+ // This is the last slot - trigger gather target
149
+ // Resolve target (may be overridden by route)
150
+ const targetRef = resolveTarget(then, outputProperties ?? {});
151
+ if (!targetRef) {
152
+ throw new Error('Failed to resolve target for gather handoff');
153
+ }
154
+ // Discover target type
155
+ const targetType = targetRef.type || await discoverTargetType(client, targetRef.pi);
156
+ // Flatten all outputs from all slots
157
+ const allOutputsFlat = slotResult.allOutputs?.flat() ?? [];
158
+ // Build invoke options
159
+ const invokeOptions = buildInvokeOptions(context);
160
+ // Remove batch context - the gather target doesn't get batch context
161
+ delete invokeOptions.batch;
162
+ // Invoke the gather target with all outputs
163
+ const result = await invokeTarget(client, targetRef.pi, targetType, allOutputsFlat, invokeOptions);
164
+ return {
165
+ action: 'gather_trigger',
166
+ target: targetRef.pi,
167
+ targetType,
168
+ invocations: [result.invocation],
169
+ batch: slotResult.batch,
170
+ allOutputs: slotResult.allOutputs,
171
+ handoffRecord: {
172
+ type: 'gather',
173
+ target: targetRef.pi,
174
+ target_type: targetType,
175
+ batch_id: batchContext.id,
176
+ invocations: [result.invocation],
177
+ },
178
+ };
179
+ }
180
+ /**
181
+ * Build invoke options from context
182
+ */
183
+ function buildInvokeOptions(context) {
184
+ return {
185
+ jobCollectionId: context.jobCollectionId,
186
+ apiBase: context.apiBase,
187
+ expiresIn: context.expiresIn,
188
+ network: context.network,
189
+ parentLogs: [context.fromLogId],
190
+ batch: context.batchContext,
191
+ rhiza: {
192
+ id: context.rhizaId,
193
+ path: context.path,
194
+ },
195
+ };
196
+ }
197
+ //# sourceMappingURL=interpret.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"interpret.js","sourceRoot":"","sources":["../../src/handoff/interpret.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAYH,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAC7C,OAAO,EAAE,kBAAkB,EAAE,YAAY,EAAsB,MAAM,UAAU,CAAC;AAChF,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,EAAE,wBAAwB,EAAE,MAAM,cAAc,CAAC;AAqFxD;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,IAAc,EACd,OAAyB;IAEzB,kEAAkE;IAClE,+BAA+B;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AC,SAAS;QAC5B,OAAO,EAAE,OAAO,CAAC,OAAO;QACxB,UAAU,EAAE,CAAC,OAAO,CAAC,SAAS,CAAC;QAC/B,KAAK,EAAE,OAAO,CAAC,YAAY;QAC3B,KAAK,EAAE;YACL,EAAE,EAAE,OAAO,CAAC,OAAO;YACnB,IAAI,EAAE,OAAO,CAAC,IAAI;SACnB;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,82 @@
1
+ /**
2
+ * Invocation Utilities
3
+ *
4
+ * SDK utilities for invoking kladoi and rhizai.
5
+ * Fire-and-forget model: we invoke and record what we sent.
6
+ */
7
+ import type { ArkeClient } from '@arke-institute/sdk';
8
+ import type { BatchContext, InvocationRecord } from '../types';
9
+ /**
10
+ * Options for invoking a target
11
+ */
12
+ export interface InvokeOptions {
13
+ /** Job collection ID */
14
+ jobCollectionId: string;
15
+ /** API base URL */
16
+ apiBase: string;
17
+ /** Permission duration in seconds (default: 3600) */
18
+ expiresIn?: number;
19
+ /** Network (test/main) */
20
+ network: 'test' | 'main';
21
+ /** Parent log IDs for chain building */
22
+ parentLogs: string[];
23
+ /** Optional input data */
24
+ input?: Record<string, unknown>;
25
+ /** Batch context if part of scatter */
26
+ batch?: BatchContext;
27
+ /** Rhiza context (if part of workflow) */
28
+ rhiza?: {
29
+ id: string;
30
+ path: string[];
31
+ };
32
+ }
33
+ /**
34
+ * Result of an invocation
35
+ */
36
+ export interface InvokeResult {
37
+ /** Job ID for the invoked target */
38
+ jobId: string;
39
+ /** Whether invocation was accepted */
40
+ accepted: boolean;
41
+ /** Error message if not accepted */
42
+ error?: string;
43
+ /** The invocation record for logging */
44
+ invocation: InvocationRecord;
45
+ }
46
+ /**
47
+ * Discover target type by fetching the entity
48
+ *
49
+ * @param client - Arke client
50
+ * @param targetId - Target entity ID
51
+ * @returns 'klados' or 'rhiza'
52
+ */
53
+ export declare function discoverTargetType(client: ArkeClient, targetId: string): Promise<'klados' | 'rhiza'>;
54
+ /**
55
+ * Invoke a target (klados or rhiza) based on its type
56
+ *
57
+ * @param client - Arke client
58
+ * @param targetId - Target klados or rhiza ID
59
+ * @param targetType - Whether target is klados or rhiza
60
+ * @param entityTarget - Entity ID(s) to process
61
+ * @param options - Invocation options
62
+ * @returns Invocation result
63
+ */
64
+ export declare function invokeTarget(client: ArkeClient, targetId: string, targetType: 'klados' | 'rhiza', entityTarget: string | string[], options: InvokeOptions): Promise<InvokeResult>;
65
+ /**
66
+ * Invoke a klados via POST /kladoi/:id/invoke
67
+ *
68
+ * Fire-and-forget: we invoke and record what we sent.
69
+ * The invoked klados creates its own log entry pointing back to us.
70
+ */
71
+ export declare function invokeKlados(client: ArkeClient, kladosId: string, entityTarget: string | string[], options: InvokeOptions): Promise<InvokeResult>;
72
+ /**
73
+ * Invoke a sub-rhiza via POST /rhizai/:id/invoke
74
+ *
75
+ * Fire-and-forget: the sub-rhiza creates log entries pointing back to parent.
76
+ * Parent does not track children.
77
+ *
78
+ * Note: The current API doesn't support passing parent_logs directly.
79
+ * Sub-rhiza invocations with parent tracking would need API extension.
80
+ */
81
+ export declare function invokeRhiza(client: ArkeClient, rhizaId: string, entityTarget: string | string[], options: InvokeOptions): Promise<InvokeResult>;
82
+ //# sourceMappingURL=invoke.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"invoke.d.ts","sourceRoot":"","sources":["../../src/handoff/invoke.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,KAAK,EAEV,YAAY,EACZ,gBAAgB,EACjB,MAAM,UAAU,CAAC;AAGlB;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,wBAAwB;IACxB,eAAe,EAAE,MAAM,CAAC;IAExB,mBAAmB;IACnB,OAAO,EAAE,MAAM,CAAC;IAEhB,qDAAqD;IACrD,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB,0BAA0B;IAC1B,OAAO,EAAE,MAAM,GAAG,MAA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