@kindgi/agents 0.0.0-bootstrap.0 → 0.1.1

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 (240) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +131 -2
  3. package/dist/agent-turn-flow.d.ts +57 -0
  4. package/dist/agent-turn-flow.d.ts.map +1 -0
  5. package/dist/agent-turn-flow.js +172 -0
  6. package/dist/agent-turn-flow.js.map +1 -0
  7. package/dist/conversation-binding.d.ts +111 -0
  8. package/dist/conversation-binding.d.ts.map +1 -0
  9. package/dist/conversation-binding.js +4 -0
  10. package/dist/conversation-binding.js.map +1 -0
  11. package/dist/define.d.ts +180 -0
  12. package/dist/define.d.ts.map +1 -0
  13. package/dist/define.js +361 -0
  14. package/dist/define.js.map +1 -0
  15. package/dist/errors.d.ts +62 -0
  16. package/dist/errors.d.ts.map +1 -0
  17. package/dist/errors.js +4 -0
  18. package/dist/errors.js.map +1 -0
  19. package/dist/guardrails-gate.d.ts +169 -0
  20. package/dist/guardrails-gate.d.ts.map +1 -0
  21. package/dist/guardrails-gate.js +202 -0
  22. package/dist/guardrails-gate.js.map +1 -0
  23. package/dist/handlers/budget-check.d.ts +22 -0
  24. package/dist/handlers/budget-check.d.ts.map +1 -0
  25. package/dist/handlers/budget-check.js +109 -0
  26. package/dist/handlers/budget-check.js.map +1 -0
  27. package/dist/handlers/build-initial-messages.d.ts +17 -0
  28. package/dist/handlers/build-initial-messages.d.ts.map +1 -0
  29. package/dist/handlers/build-initial-messages.js +86 -0
  30. package/dist/handlers/build-initial-messages.js.map +1 -0
  31. package/dist/handlers/compose-result.d.ts +10 -0
  32. package/dist/handlers/compose-result.d.ts.map +1 -0
  33. package/dist/handlers/compose-result.js +79 -0
  34. package/dist/handlers/compose-result.js.map +1 -0
  35. package/dist/handlers/constants.d.ts +8 -0
  36. package/dist/handlers/constants.d.ts.map +1 -0
  37. package/dist/handlers/constants.js +10 -0
  38. package/dist/handlers/constants.js.map +1 -0
  39. package/dist/handlers/context.d.ts +210 -0
  40. package/dist/handlers/context.d.ts.map +1 -0
  41. package/dist/handlers/context.js +4 -0
  42. package/dist/handlers/context.js.map +1 -0
  43. package/dist/handlers/dispatch-tools.d.ts +15 -0
  44. package/dist/handlers/dispatch-tools.d.ts.map +1 -0
  45. package/dist/handlers/dispatch-tools.js +511 -0
  46. package/dist/handlers/dispatch-tools.js.map +1 -0
  47. package/dist/handlers/errors.d.ts +133 -0
  48. package/dist/handlers/errors.d.ts.map +1 -0
  49. package/dist/handlers/errors.js +134 -0
  50. package/dist/handlers/errors.js.map +1 -0
  51. package/dist/handlers/evaluate-guardrails.d.ts +14 -0
  52. package/dist/handlers/evaluate-guardrails.d.ts.map +1 -0
  53. package/dist/handlers/evaluate-guardrails.js +128 -0
  54. package/dist/handlers/evaluate-guardrails.js.map +1 -0
  55. package/dist/handlers/final-iteration.d.ts +7 -0
  56. package/dist/handlers/final-iteration.d.ts.map +1 -0
  57. package/dist/handlers/final-iteration.js +26 -0
  58. package/dist/handlers/final-iteration.js.map +1 -0
  59. package/dist/handlers/index.d.ts +5 -0
  60. package/dist/handlers/index.d.ts.map +1 -0
  61. package/dist/handlers/index.js +41 -0
  62. package/dist/handlers/index.js.map +1 -0
  63. package/dist/handlers/model-call.d.ts +13 -0
  64. package/dist/handlers/model-call.d.ts.map +1 -0
  65. package/dist/handlers/model-call.js +136 -0
  66. package/dist/handlers/model-call.js.map +1 -0
  67. package/dist/handlers/persist-final-message.d.ts +14 -0
  68. package/dist/handlers/persist-final-message.d.ts.map +1 -0
  69. package/dist/handlers/persist-final-message.js +54 -0
  70. package/dist/handlers/persist-final-message.js.map +1 -0
  71. package/dist/handlers/persist-provenance.d.ts +12 -0
  72. package/dist/handlers/persist-provenance.d.ts.map +1 -0
  73. package/dist/handlers/persist-provenance.js +34 -0
  74. package/dist/handlers/persist-provenance.js.map +1 -0
  75. package/dist/handlers/persist-user-message.d.ts +15 -0
  76. package/dist/handlers/persist-user-message.d.ts.map +1 -0
  77. package/dist/handlers/persist-user-message.js +59 -0
  78. package/dist/handlers/persist-user-message.js.map +1 -0
  79. package/dist/handlers/public-types.d.ts +201 -0
  80. package/dist/handlers/public-types.d.ts.map +1 -0
  81. package/dist/handlers/public-types.js +4 -0
  82. package/dist/handlers/public-types.js.map +1 -0
  83. package/dist/handlers/rehydrate.d.ts +8 -0
  84. package/dist/handlers/rehydrate.d.ts.map +1 -0
  85. package/dist/handlers/rehydrate.js +94 -0
  86. package/dist/handlers/rehydrate.js.map +1 -0
  87. package/dist/handlers/render-prompt.d.ts +12 -0
  88. package/dist/handlers/render-prompt.d.ts.map +1 -0
  89. package/dist/handlers/render-prompt.js +41 -0
  90. package/dist/handlers/render-prompt.js.map +1 -0
  91. package/dist/handlers/resolve-tools.d.ts +10 -0
  92. package/dist/handlers/resolve-tools.d.ts.map +1 -0
  93. package/dist/handlers/resolve-tools.js +55 -0
  94. package/dist/handlers/resolve-tools.js.map +1 -0
  95. package/dist/handlers/result-shape.d.ts +94 -0
  96. package/dist/handlers/result-shape.d.ts.map +1 -0
  97. package/dist/handlers/result-shape.js +19 -0
  98. package/dist/handlers/result-shape.js.map +1 -0
  99. package/dist/handlers/run-retrievals.d.ts +10 -0
  100. package/dist/handlers/run-retrievals.d.ts.map +1 -0
  101. package/dist/handlers/run-retrievals.js +64 -0
  102. package/dist/handlers/run-retrievals.js.map +1 -0
  103. package/dist/handlers/run-snapshot.d.ts +4 -0
  104. package/dist/handlers/run-snapshot.d.ts.map +1 -0
  105. package/dist/handlers/run-snapshot.js +26 -0
  106. package/dist/handlers/run-snapshot.js.map +1 -0
  107. package/dist/handlers/setup.d.ts +25 -0
  108. package/dist/handlers/setup.d.ts.map +1 -0
  109. package/dist/handlers/setup.js +231 -0
  110. package/dist/handlers/setup.js.map +1 -0
  111. package/dist/handlers/structured-output.d.ts +38 -0
  112. package/dist/handlers/structured-output.d.ts.map +1 -0
  113. package/dist/handlers/structured-output.js +89 -0
  114. package/dist/handlers/structured-output.js.map +1 -0
  115. package/dist/handlers/tool-errors.d.ts +56 -0
  116. package/dist/handlers/tool-errors.d.ts.map +1 -0
  117. package/dist/handlers/tool-errors.js +73 -0
  118. package/dist/handlers/tool-errors.js.map +1 -0
  119. package/dist/handlers/tool-hitl.d.ts +45 -0
  120. package/dist/handlers/tool-hitl.d.ts.map +1 -0
  121. package/dist/handlers/tool-hitl.js +81 -0
  122. package/dist/handlers/tool-hitl.js.map +1 -0
  123. package/dist/handlers/turn-environment.d.ts +26 -0
  124. package/dist/handlers/turn-environment.d.ts.map +1 -0
  125. package/dist/handlers/turn-environment.js +154 -0
  126. package/dist/handlers/turn-environment.js.map +1 -0
  127. package/dist/hitl-policy.d.ts +45 -0
  128. package/dist/hitl-policy.d.ts.map +1 -0
  129. package/dist/hitl-policy.js +74 -0
  130. package/dist/hitl-policy.js.map +1 -0
  131. package/dist/index.d.ts +31 -0
  132. package/dist/index.d.ts.map +1 -0
  133. package/dist/index.js +19 -0
  134. package/dist/index.js.map +1 -0
  135. package/dist/invoke.d.ts +36 -0
  136. package/dist/invoke.d.ts.map +1 -0
  137. package/dist/invoke.js +228 -0
  138. package/dist/invoke.js.map +1 -0
  139. package/dist/migrations-dir.d.ts +11 -0
  140. package/dist/migrations-dir.d.ts.map +1 -0
  141. package/dist/migrations-dir.js +14 -0
  142. package/dist/migrations-dir.js.map +1 -0
  143. package/dist/project-run-result.d.ts +23 -0
  144. package/dist/project-run-result.d.ts.map +1 -0
  145. package/dist/project-run-result.js +116 -0
  146. package/dist/project-run-result.js.map +1 -0
  147. package/dist/prompt.d.ts +83 -0
  148. package/dist/prompt.d.ts.map +1 -0
  149. package/dist/prompt.js +119 -0
  150. package/dist/prompt.js.map +1 -0
  151. package/dist/provenance-emit.d.ts +44 -0
  152. package/dist/provenance-emit.d.ts.map +1 -0
  153. package/dist/provenance-emit.js +51 -0
  154. package/dist/provenance-emit.js.map +1 -0
  155. package/dist/registry.d.ts +38 -0
  156. package/dist/registry.d.ts.map +1 -0
  157. package/dist/registry.js +125 -0
  158. package/dist/registry.js.map +1 -0
  159. package/dist/retrieval.d.ts +47 -0
  160. package/dist/retrieval.d.ts.map +1 -0
  161. package/dist/retrieval.js +155 -0
  162. package/dist/retrieval.js.map +1 -0
  163. package/dist/run-snapshot-binding.d.ts +77 -0
  164. package/dist/run-snapshot-binding.d.ts.map +1 -0
  165. package/dist/run-snapshot-binding.js +4 -0
  166. package/dist/run-snapshot-binding.js.map +1 -0
  167. package/dist/schema.d.ts +497 -0
  168. package/dist/schema.d.ts.map +1 -0
  169. package/dist/schema.js +133 -0
  170. package/dist/schema.js.map +1 -0
  171. package/dist/streaming.d.ts +118 -0
  172. package/dist/streaming.d.ts.map +1 -0
  173. package/dist/streaming.js +17 -0
  174. package/dist/streaming.js.map +1 -0
  175. package/dist/tenant-policy.d.ts +16 -0
  176. package/dist/tenant-policy.d.ts.map +1 -0
  177. package/dist/tenant-policy.js +77 -0
  178. package/dist/tenant-policy.js.map +1 -0
  179. package/dist/types.d.ts +435 -0
  180. package/dist/types.d.ts.map +1 -0
  181. package/dist/types.js +4 -0
  182. package/dist/types.js.map +1 -0
  183. package/dist/versioning.d.ts +29 -0
  184. package/dist/versioning.d.ts.map +1 -0
  185. package/dist/versioning.js +58 -0
  186. package/dist/versioning.js.map +1 -0
  187. package/migrations/0000_sparkling_talkback.sql +18 -0
  188. package/migrations/0001_tired_warhawk.sql +16 -0
  189. package/migrations/0002_violet_ezekiel.sql +2 -0
  190. package/migrations/meta/0000_snapshot.json +172 -0
  191. package/migrations/meta/0001_snapshot.json +275 -0
  192. package/migrations/meta/0002_snapshot.json +287 -0
  193. package/migrations/meta/_journal.json +27 -0
  194. package/package.json +76 -4
  195. package/src/agent-turn-flow.ts +183 -0
  196. package/src/conversation-binding.ts +147 -0
  197. package/src/define.ts +572 -0
  198. package/src/errors.ts +80 -0
  199. package/src/guardrails-gate.ts +342 -0
  200. package/src/handlers/budget-check.ts +143 -0
  201. package/src/handlers/build-initial-messages.ts +103 -0
  202. package/src/handlers/compose-result.ts +90 -0
  203. package/src/handlers/constants.ts +10 -0
  204. package/src/handlers/context.ts +226 -0
  205. package/src/handlers/dispatch-tools.ts +633 -0
  206. package/src/handlers/errors.ts +282 -0
  207. package/src/handlers/evaluate-guardrails.ts +153 -0
  208. package/src/handlers/final-iteration.ts +30 -0
  209. package/src/handlers/index.ts +63 -0
  210. package/src/handlers/model-call.ts +151 -0
  211. package/src/handlers/persist-final-message.ts +67 -0
  212. package/src/handlers/persist-provenance.ts +39 -0
  213. package/src/handlers/persist-user-message.ts +70 -0
  214. package/src/handlers/public-types.ts +209 -0
  215. package/src/handlers/rehydrate.ts +161 -0
  216. package/src/handlers/render-prompt.ts +46 -0
  217. package/src/handlers/resolve-tools.ts +68 -0
  218. package/src/handlers/result-shape.ts +113 -0
  219. package/src/handlers/run-retrievals.ts +77 -0
  220. package/src/handlers/run-snapshot.ts +44 -0
  221. package/src/handlers/setup.ts +269 -0
  222. package/src/handlers/structured-output.ts +117 -0
  223. package/src/handlers/tool-errors.ts +122 -0
  224. package/src/handlers/tool-hitl.ts +126 -0
  225. package/src/handlers/turn-environment.ts +191 -0
  226. package/src/hitl-policy.ts +128 -0
  227. package/src/index.ts +154 -0
  228. package/src/invoke.ts +299 -0
  229. package/src/migrations-dir.ts +17 -0
  230. package/src/project-run-result.ts +131 -0
  231. package/src/prompt.ts +185 -0
  232. package/src/provenance-emit.ts +100 -0
  233. package/src/registry.ts +164 -0
  234. package/src/retrieval.ts +219 -0
  235. package/src/run-snapshot-binding.ts +87 -0
  236. package/src/schema.ts +154 -0
  237. package/src/streaming.ts +153 -0
  238. package/src/tenant-policy.ts +78 -0
  239. package/src/types.ts +453 -0
  240. package/src/versioning.ts +77 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"persist-final-message.js","sourceRoot":"","sources":["../../src/handlers/persist-final-message.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,iCAAiC;AAKjC,OAAO,EAAE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,CAAC;YACjE,YAAY,GAAG,OAAO,CAAC,KAAK,CAAC;QAC/B,CAAC;QAED,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;QAChC,GAAG,CAAC,YAAY,GAAG,YAAY,CAAC;QAEhC,MAAM,aAAa,CAAC,GAAG,CAAC,QAAQ,CAAC,OAAO,EAAE;YACxC,IAAI,EAAE,eAAe;YACrB,IAAI,EAAE,GAAG,CAAC,KAAK,CAAC,KAAK;YACrB,OAAO,EAAE,IAAI;YACb,OAAO,EAAE,YAAY;SACtB,CAAC,CAAC;QAEH,OAAO,EAAE,QAAQ,EAAE,YAAY,CAAC,QAAQ,EAAE,CAAC;IAC7C,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,12 @@
1
+ import type { NodeHandler } from '@kindgi/handler';
2
+ import type { TurnContext } from './context.js';
3
+ /**
4
+ * Persist the completed provenance DAG. Best-effort: a persistence
5
+ * failure here does NOT fail the run (the turn already succeeded and
6
+ * the DAG was built in memory); the result then carries no
7
+ * `provenance`.
8
+ *
9
+ * Skipped entirely when no provenance builder was wired.
10
+ */
11
+ export declare function buildPersistProvenanceHandler(ctx: TurnContext): NodeHandler;
12
+ //# sourceMappingURL=persist-provenance.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"persist-provenance.d.ts","sourceRoot":"","sources":["../../src/handlers/persist-provenance.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAInD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAEhD;;;;;;;GAOG;AACH,wBAAgB,6BAA6B,CAAC,GAAG,EAAE,WAAW,GAAG,WAAW,CAqB3E"}
@@ -0,0 +1,34 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ // Copyright (C) 2026 Kindgi Inc.
3
+ import { persistProvenance } from '../provenance-emit.js';
4
+ /**
5
+ * Persist the completed provenance DAG. Best-effort: a persistence
6
+ * failure here does NOT fail the run (the turn already succeeded and
7
+ * the DAG was built in memory); the result then carries no
8
+ * `provenance`.
9
+ *
10
+ * Skipped entirely when no provenance builder was wired.
11
+ */
12
+ export function buildPersistProvenanceHandler(ctx) {
13
+ return async (_input, kctx) => {
14
+ if (ctx.provenance === undefined || ctx.provenanceBindings === undefined) {
15
+ return { persisted: false };
16
+ }
17
+ if (kctx.dryRun) {
18
+ // Dry-run: DAG was built in-memory; skip the write. The
19
+ // returned `AgentTurnResult.provenance` is left undefined
20
+ // (unpersisted provenance is not surfaced on the result —
21
+ // callers can inspect the in-memory builder via bindings if they
22
+ // want).
23
+ return { persisted: false };
24
+ }
25
+ const persisted = await persistProvenance(ctx.provenance, ctx.provenanceBindings);
26
+ if (persisted.kind === 'ok') {
27
+ ctx.persistedProvenance = persisted.value;
28
+ return { persisted: true };
29
+ }
30
+ // Silently swallow — persistence is best-effort (see above).
31
+ return { persisted: false };
32
+ };
33
+ }
34
+ //# sourceMappingURL=persist-provenance.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"persist-provenance.js","sourceRoot":"","sources":["../../src/handlers/persist-provenance.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,iCAAiC;AAIjC,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAI1D;;;;;;;GAOG;AACH,MAAM,UAAU,6BAA6B,CAAC,GAAgB;IAC5D,OAAO,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE;QAC5B,IAAI,GAAG,CAAC,UAAU,KAAK,SAAS,IAAI,GAAG,CAAC,kBAAkB,KAAK,SAAS,EAAE,CAAC;YACzE,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;QAC9B,CAAC;QACD,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;YAChB,wDAAwD;YACxD,0DAA0D;YAC1D,0DAA0D;YAC1D,iEAAiE;YACjE,SAAS;YACT,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;QAC9B,CAAC;QACD,MAAM,SAAS,GAAG,MAAM,iBAAiB,CAAC,GAAG,CAAC,UAAU,EAAE,GAAG,CAAC,kBAAkB,CAAC,CAAC;QAClF,IAAI,SAAS,CAAC,IAAI,KAAK,IAAI,EAAE,CAAC;YAC5B,GAAG,CAAC,mBAAmB,GAAG,SAAS,CAAC,KAAK,CAAC;YAC1C,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;QAC7B,CAAC;QACD,6DAA6D;QAC7D,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;IAC9B,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,15 @@
1
+ import type { NodeHandler } from '@kindgi/handler';
2
+ import type { TurnContext } from './context.js';
3
+ /**
4
+ * Persist the caller's user message BEFORE the model is called. A
5
+ * crash mid-turn leaves the question intact for a later replay. Also
6
+ * seeds the provenance DAG with the `input:<sequence>` node — every
7
+ * subsequent model/tool node ties back through that root.
8
+ *
9
+ * Dry-run branch: skips the DB write; builds a synthetic
10
+ * `ConversationMessage` with `sequence: -1` (sentinel — real sequences
11
+ * are always ≥ 0). Provenance node is still seeded so downstream
12
+ * dry-run handlers can build a plausible plan DAG.
13
+ */
14
+ export declare function buildPersistUserMessageHandler(ctx: TurnContext): NodeHandler;
15
+ //# sourceMappingURL=persist-user-message.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"persist-user-message.d.ts","sourceRoot":"","sources":["../../src/handlers/persist-user-message.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAKnD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAGhD;;;;;;;;;;GAUG;AACH,wBAAgB,8BAA8B,CAAC,GAAG,EAAE,WAAW,GAAG,WAAW,CA+C5E"}
@@ -0,0 +1,59 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ // Copyright (C) 2026 Kindgi Inc.
3
+ import { throwAgentTurnFailure } from './errors.js';
4
+ /**
5
+ * Persist the caller's user message BEFORE the model is called. A
6
+ * crash mid-turn leaves the question intact for a later replay. Also
7
+ * seeds the provenance DAG with the `input:<sequence>` node — every
8
+ * subsequent model/tool node ties back through that root.
9
+ *
10
+ * Dry-run branch: skips the DB write; builds a synthetic
11
+ * `ConversationMessage` with `sequence: -1` (sentinel — real sequences
12
+ * are always ≥ 0). Provenance node is still seeded so downstream
13
+ * dry-run handlers can build a plausible plan DAG.
14
+ */
15
+ export function buildPersistUserMessageHandler(ctx) {
16
+ return async (_input, kctx) => {
17
+ if (kctx.dryRun) {
18
+ const synthetic = {
19
+ sequence: -1,
20
+ role: 'user',
21
+ content: ctx.input.userMessage,
22
+ createdAt: new Date().toISOString(),
23
+ ...(ctx.input.participantId !== undefined && { actor: ctx.input.participantId }),
24
+ };
25
+ ctx.userMessage = synthetic;
26
+ ctx.appended.push(synthetic);
27
+ if (ctx.provenance !== undefined) {
28
+ ctx.provenance.addNode({
29
+ id: `input:${synthetic.sequence}`,
30
+ kind: 'input',
31
+ timestamp: synthetic.createdAt,
32
+ ...(synthetic.actor !== undefined && { actor: synthetic.actor }),
33
+ });
34
+ }
35
+ return { sequence: synthetic.sequence };
36
+ }
37
+ const persisted = await ctx.bindings.conversationBinding.appendMessage({
38
+ tenantId: ctx.input.tenantId,
39
+ conversationId: ctx.input.conversationId,
40
+ role: 'user',
41
+ content: ctx.input.userMessage,
42
+ ...(ctx.input.participantId !== undefined && { actor: ctx.input.participantId }),
43
+ });
44
+ if (persisted.kind === 'err')
45
+ throwAgentTurnFailure(persisted.error);
46
+ ctx.userMessage = persisted.value;
47
+ ctx.appended.push(persisted.value);
48
+ if (ctx.provenance !== undefined) {
49
+ ctx.provenance.addNode({
50
+ id: `input:${persisted.value.sequence}`,
51
+ kind: 'input',
52
+ timestamp: persisted.value.createdAt,
53
+ ...(persisted.value.actor !== undefined && { actor: persisted.value.actor }),
54
+ });
55
+ }
56
+ return { sequence: persisted.value.sequence };
57
+ };
58
+ }
59
+ //# sourceMappingURL=persist-user-message.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"persist-user-message.js","sourceRoot":"","sources":["../../src/handlers/persist-user-message.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,iCAAiC;AAQjC,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAEpD;;;;;;;;;;GAUG;AACH,MAAM,UAAU,8BAA8B,CAAC,GAAgB;IAC7D,OAAO,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE;QAC5B,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;YAChB,MAAM,SAAS,GAAwB;gBACrC,QAAQ,EAAE,CAAC,CAAC;gBACZ,IAAI,EAAE,MAAM;gBACZ,OAAO,EAAE,GAAG,CAAC,KAAK,CAAC,WAAW;gBAC9B,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAe;gBAChD,GAAG,CAAC,GAAG,CAAC,KAAK,CAAC,aAAa,KAAK,SAAS,IAAI,EAAE,KAAK,EAAE,GAAG,CAAC,KAAK,CAAC,aAAa,EAAE,CAAC;aACjF,CAAC;YACF,GAAG,CAAC,WAAW,GAAG,SAAS,CAAC;YAC5B,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;YAE7B,IAAI,GAAG,CAAC,UAAU,KAAK,SAAS,EAAE,CAAC;gBACjC,GAAG,CAAC,UAAU,CAAC,OAAO,CAAC;oBACrB,EAAE,EAAE,SAAS,SAAS,CAAC,QAAQ,EAAE;oBACjC,IAAI,EAAE,OAAO;oBACb,SAAS,EAAE,SAAS,CAAC,SAAS;oBAC9B,GAAG,CAAC,SAAS,CAAC,KAAK,KAAK,SAAS,IAAI,EAAE,KAAK,EAAE,SAAS,CAAC,KAAK,EAAE,CAAC;iBACjE,CAAC,CAAC;YACL,CAAC;YACD,OAAO,EAAE,QAAQ,EAAE,SAAS,CAAC,QAAQ,EAAE,CAAC;QAC1C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derRegistry } from '@kindgi/embedding';
4
+ import type { MemoryQueryBinding } from '@kindgi/memory';
5
+ import type { PolicyRegistry } from '@kindgi/policy-contract';
6
+ import type { ParentRunRef, RunBinding } from '@kindgi/runtime';
7
+ import type { ToolRegistry, ToolSecretRef } from '@kindgi/tools';
8
+ import type { ProjectId, ProvenanceId, RunId, TenantId, Timestamp } from '@kindgi/types';
9
+ import type { ConversationBinding } from '../conversation-binding.js';
10
+ import type { GuardrailsBindings } from '../guardrails-gate.js';
11
+ import type { ProvenanceBindings } from '../provenance-emit.js';
12
+ import type { RunSnapshotBinding } from '../run-snapshot-binding.js';
13
+ import type { OnTurnEvent } from '../streaming.js';
14
+ import type { Agent, ConversationId } from '../types.js';
15
+ /**
16
+ * The user-facing input to `invokeAgent`. Split out from `invoke.ts` so
17
+ * the handler modules can depend on the shape without pulling in the
18
+ * orchestration entrypoint (would cause a circular import).
19
+ */
20
+ export interface InvokeAgentInput {
21
+ readonly tenantId: TenantId;
22
+ /**
23
+ * Content-scope anchor. REQUIRED — every
24
+ * agent turn is a run bound to exactly one project inside the
25
+ * tenant. Callers without a natural project id resolve to the tenant's
26
+ * Default via `projectBinding.getDefault(tenantId)` (`@kindgi/api`)
27
+ * at the caller layer.
28
+ */
29
+ readonly projectId: ProjectId;
30
+ readonly agent: Agent;
31
+ readonly conversationId: ConversationId;
32
+ readonly userMessage: string;
33
+ readonly parameters?: Readonly<Record<string, string | number | boolean>>;
34
+ /**
35
+ * Structured input for this turn — what a flow step hands its agent.
36
+ * Available to the instructions as `{{ input.* }}`, kept in the run
37
+ * snapshot for resume, and passed to guardrails as
38
+ * `trace.attributes.stepInput`.
39
+ */
40
+ readonly input?: unknown;
41
+ /**
42
+ * The flow run and node that started this turn, when it is a flow
43
+ * step. Recorded on the turn's run, so the flow can find its child.
44
+ */
45
+ readonly parent?: ParentRunRef;
46
+ readonly participantId?: string;
47
+ readonly abortSignal?: AbortSignal;
48
+ /**
49
+ * When `true`, executes the turn as a plan preview: no side effects
50
+ * to the conversation, memory, or provenance. Retrievals + guardrails
51
+ * still run for real (pure reads); the model call is skipped and
52
+ * returns a fixed mock response with no tool calls, so no tools run;
53
+ * every `persist-*` node skips its write. The returned
54
+ * `AgentTurnResult` carries `dryRun: true`, and the underlying run is
55
+ * journaled as a dry run.
56
+ */
57
+ readonly dryRun?: boolean;
58
+ /**
59
+ * Authorization — the Principal on whose authority this agent turn
60
+ * runs. When set together with `authz`, the underlying run checks
61
+ * every tool invocation (and subgraph dispatch, if any) against this
62
+ * principal at its enforcement point.
63
+ *
64
+ * Typical caller construction:
65
+ * principal = delegate(
66
+ * { kind: 'agent', id: input.agent.id, tenantId },
67
+ * userPrincipalFromSession
68
+ * )
69
+ * — establishes the confused-deputy-safe intersection semantic.
70
+ *
71
+ * Absent = tool invocations are not authorization-checked.
72
+ */
73
+ readonly principal?: Principal;
74
+ readonly authz?: {
75
+ readonly fgaApiUrl: string;
76
+ };
77
+ }
78
+ export interface InvokeAgentBindings extends GuardrailsBindings {
79
+ /**
80
+ * Model providers. Setup hydrates the tenant's providers (when the
81
+ * registry supports it) and routes the agent's first capability over
82
+ * `list(tenantId)` under the merged tenant policy; llm-judge
83
+ * guardrails route through it too.
84
+ */
85
+ readonly providerRegistry: ProviderRegistry;
86
+ /**
87
+ * Tools. Setup calls `forTenant(tenantId)` and resolves the agent's
88
+ * tool refs on the returned tenant-bound registry, so a turn never
89
+ * sees another tenant's tools.
90
+ */
91
+ readonly toolRegistry: ToolRegistry;
92
+ /**
93
+ * Caller-plugged data-access surface for memory reads.
94
+ * The Kindgi runtime supplies a Postgres-backed implementation;
95
+ * any object satisfying the interface works (tests, custom stores).
96
+ * Retrieval (listFacts / searchByKeyword / searchBySemantic) inside
97
+ * the agent runtime routes through this binding — the runtime never
98
+ * touches a database client directly for memory operations.
99
+ */
100
+ readonly memoryBinding: MemoryQueryBinding;
101
+ /**
102
+ * Caller-plugged conversation store. Every open / get / list /
103
+ * close / delete / appendMessage / readMessages inside the agent
104
+ * runtime routes through this binding — the runtime never touches
105
+ * a database client directly for conversation ops. The Kindgi runtime
106
+ * supplies a Postgres-backed implementation; any conforming object
107
+ * works. Required.
108
+ */
109
+ readonly conversationBinding: ConversationBinding;
110
+ /**
111
+ * Caller-plugged run-snapshot store. Writes the reconstruction
112
+ * envelope on run-start (idempotent under replay); reads it
113
+ * on `resumeAgentTurn` to rebuild the suspended TurnContext.
114
+ * The Kindgi runtime supplies a
115
+ * Postgres-backed implementation; any conforming object works. Required.
116
+ */
117
+ readonly runSnapshotBinding: RunSnapshotBinding;
118
+ /**
119
+ * Run-lifecycle binding (`RunBinding` from `@kindgi/runtime`). Every
120
+ * agent turn spawns a `runGraph` (or `resumeRun`) through it. The
121
+ * Kindgi runtime supplies an implementation; a bespoke one can be
122
+ * plugged in.
123
+ *
124
+ * Optional in the type, but `invokeAgent` and `resumeAgentTurn`
125
+ * throw when it is missing — every caller MUST supply it.
126
+ */
127
+ readonly runBinding?: RunBinding;
128
+ /**
129
+ * Statically-injected tenant policy for model routing. When a
130
+ * `policyRegistry` also yields a policy, the two are MERGED so the
131
+ * result is at least as strict as each: allow lists intersect, deny
132
+ * lists union, cost/token caps take the smaller value.
133
+ *
134
+ * Absent-and-registry-absent = router runs without any tenant policy.
135
+ */
136
+ readonly tenantPolicy?: TenantPolicy;
137
+ /**
138
+ * Optional policy registry. When present, the agent setup step calls
139
+ * `policyRegistry.evaluate('model-routing', {tenantId})` and merges
140
+ * the result with `tenantPolicy` before routing. Without a registry
141
+ * (or without an executor for that kind), `tenantPolicy` applies
142
+ * alone.
143
+ */
144
+ readonly policyRegistry?: PolicyRegistry;
145
+ readonly embeddingRegistry?: EmbeddingProviderRegistry;
146
+ readonly embeddingModel?: string;
147
+ readonly onEvent?: OnTurnEvent;
148
+ readonly provenance?: ProvenanceBindings;
149
+ readonly hitl?: HitlBindings;
150
+ /**
151
+ * Declarative HTTP tools: optional secret resolver populated
152
+ * from the deployment's tenant-scoped `SecretBinding`. When present,
153
+ * `dispatch-tools` threads it into every `ToolContext` so
154
+ * declarative HTTP tools (spec kind 'http') can resolve declared `secret_ref`s at
155
+ * invoke time. Absent → HTTP tools that declare `authorization`
156
+ * throw a clear "resolveSecret is not wired" error; native tools
157
+ * unaffected.
158
+ */
159
+ readonly resolveSecret?: (ref: ToolSecretRef) => Promise<string>;
160
+ }
161
+ export interface HitlBindings {
162
+ readonly enqueue: (input: HitlEnqueueInput) => Promise<HitlEnqueueResult>;
163
+ }
164
+ export interface HitlEnqueueInput {
165
+ readonly tenantId: TenantId;
166
+ readonly subjectKind: string;
167
+ readonly subjectRef: Readonly<Record<string, unknown>>;
168
+ readonly requiredRole?: 'standard' | 'senior' | 'admin';
169
+ readonly title?: string;
170
+ readonly description?: string;
171
+ readonly context?: Readonly<Record<string, unknown>>;
172
+ /**
173
+ * Waitpoint token this approval resolves on approve/reject
174
+ * (park-and-resume). The session gate (setup handler) and the tool
175
+ * gate (dispatch-tools handler) compute it as a deterministic hash —
176
+ * of (runId, gate scope, turnCount) and of (runId, callId, argsHash)
177
+ * respectively. Enqueue is idempotent on this — handler replay is
178
+ * safe.
179
+ */
180
+ readonly waitTokenId?: string;
181
+ /**
182
+ * Provenance reference for the parent run. Required for the
183
+ * approvals-complete route to invoke `completeToken(runId, ...)` +
184
+ * `resumeRun(runId)` on decision. Absent = the approval decides in
185
+ * place, no waitpoint resolution.
186
+ */
187
+ readonly provenanceRef?: {
188
+ readonly runId: RunId;
189
+ readonly provenanceId?: ProvenanceId;
190
+ };
191
+ /**
192
+ * Absolute deadline surfaced to reviewers; an approval still pending
193
+ * after it can be expired. Materialized at enqueue time from the
194
+ * effective HITL policy's `timeoutMs`.
195
+ */
196
+ readonly expiresAt?: Timestamp;
197
+ }
198
+ export interface HitlEnqueueResult {
199
+ readonly approvalId: string;
200
+ }
201
+ //# sourceMappingURL=public-types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"public-types.d.ts","sourceRoot":"","sources":["../../src/handlers/public-types.ts"],"names":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AM,CAAC;CAC7B"}
@@ -0,0 +1,4 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ // Copyright (C) 2026 Kindgi Inc.
3
+ export {};
4
+ //# sourceMappingURL=public-types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"public-types.js","sourceRoot":"","sources":["../../src/handlers/public-types.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,iCAAiC"}
@@ -0,0 +1,8 @@
1
+ import { type JournalEntry } from '@kindgi/runtime';
2
+ import type { TurnContext } from './context.js';
3
+ /**
4
+ * Restore `ctx` for a turn being resumed. Returns `false` when `setup`
5
+ * hasn't completed (it will run, and resolve everything itself).
6
+ */
7
+ export declare function rehydrateTurnContext(ctx: TurnContext, runId: string, journal: readonly JournalEntry[]): Promise<boolean>;
8
+ //# sourceMappingURL=rehydrate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rehydrate.d.ts","sourceRoot":"","sources":["../../src/handlers/rehydrate.ts"],"names":[],"mappings":"AAkCA,OAAO,EAAE,KAAK,YAAY,EAAe,MAAM,iBAAiB,CAAC;AAGjE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AA0ChD;;;GAGG;AACH,wBAAsB,oBAAoB,CACxC,GAAG,EAAE,WAAW,EAChB,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,SAAS,YAAY,EAAE,GAC/B,OAAO,CAAC,OAAO,CAAC,CA6ClB"}
@@ -0,0 +1,94 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ // Copyright (C) 2026 Kindgi Inc.
3
+ import { bodyStepKey } from '@kindgi/runtime';
4
+ import { throwAgentTurnFailure } from './errors.js';
5
+ import { loadTurnConversation, resolveTurnEnvironment, resolveTurnHitlPolicy, } from './turn-environment.js';
6
+ /** Each step's last completion — a step at one loop iteration counts once. */
7
+ function completedSteps(journal) {
8
+ const byStep = new Map();
9
+ for (const e of journal) {
10
+ if (e.kind !== 'step.completed' || e.nodeId === undefined)
11
+ continue;
12
+ const payload = (e.payload ?? {});
13
+ const key = payload.loopContext === undefined
14
+ ? e.nodeId
15
+ : bodyStepKey(e.nodeId, payload.loopContext);
16
+ byStep.delete(key);
17
+ byStep.set(key, {
18
+ nodeId: e.nodeId,
19
+ output: payload.output,
20
+ inLoop: payload.loopContext !== undefined,
21
+ });
22
+ }
23
+ return [...byStep.values()];
24
+ }
25
+ /** The output of an outer step that completed, if it did. */
26
+ function outputOf(steps, nodeId) {
27
+ return steps.find((s) => s.nodeId === nodeId && !s.inLoop)?.output;
28
+ }
29
+ /**
30
+ * Restore `ctx` for a turn being resumed. Returns `false` when `setup`
31
+ * hasn't completed (it will run, and resolve everything itself).
32
+ */
33
+ export async function rehydrateTurnContext(ctx, runId, journal) {
34
+ const steps = completedSteps(journal);
35
+ const setup = outputOf(steps, 'setup');
36
+ if (setup === undefined)
37
+ return false;
38
+ if (ctx.bindings.provenance?.newBuilder !== undefined) {
39
+ ctx.provenance = ctx.bindings.provenance.newBuilder({ runId, tenantId: ctx.input.tenantId });
40
+ ctx.provenanceBindings = ctx.bindings.provenance;
41
+ }
42
+ await loadTurnConversation(ctx);
43
+ ctx.hitlPolicy = await resolveTurnHitlPolicy(ctx);
44
+ await resolveTurnEnvironment(ctx, { providerId: setup.providerId, model: setup.providerModel });
45
+ const userMessage = outputOf(steps, 'persist-user-message');
46
+ if (userMessage !== undefined) {
47
+ await restoreAppended(ctx, userMessage.sequence);
48
+ ctx.storedBeforePark = storedBeforePark(ctx, steps);
49
+ }
50
+ const retrievals = outputOf(steps, 'run-retrievals');
51
+ if (retrievals?.retrieved !== undefined)
52
+ ctx.retrieved = retrievals.retrieved;
53
+ for (const s of steps.filter((s) => s.nodeId === 'model-call' && s.inLoop)) {
54
+ const out = s.output;
55
+ ctx.usage.steps = Math.max(ctx.usage.steps, out.step ?? 0);
56
+ ctx.usage.promptTokens += out.iterationUsage?.promptTokens ?? 0;
57
+ ctx.usage.completionTokens += out.iterationUsage?.completionTokens ?? 0;
58
+ ctx.usage.totalCostUsd += out.iterationUsage?.costUsd ?? 0;
59
+ if (out.provider !== undefined)
60
+ ctx.lastProvider = out.provider;
61
+ }
62
+ return true;
63
+ }
64
+ /**
65
+ * The messages no completed step accounts for: those the step the turn
66
+ * parked in stored before it parked.
67
+ */
68
+ function storedBeforePark(ctx, steps) {
69
+ const accounted = new Set();
70
+ if (ctx.userMessage !== undefined)
71
+ accounted.add(ctx.userMessage.sequence);
72
+ for (const s of steps.filter((s) => s.nodeId === 'dispatch-tools' && s.inLoop)) {
73
+ const out = s.output;
74
+ for (const m of out.iterationAppended ?? [])
75
+ accounted.add(m.sequence);
76
+ }
77
+ return ctx.appended.filter((m) => !accounted.has(m.sequence));
78
+ }
79
+ /** The messages the turn stored before the park, from its user message on. */
80
+ async function restoreAppended(ctx, fromSequence) {
81
+ const read = await ctx.bindings.conversationBinding.readMessages({
82
+ tenantId: ctx.input.tenantId,
83
+ conversationId: ctx.input.conversationId,
84
+ sinceSequence: fromSequence - 1,
85
+ });
86
+ if (read.kind === 'err')
87
+ throwAgentTurnFailure(read.error);
88
+ const turnMessages = read.value.filter((m) => m.sequence >= fromSequence);
89
+ ctx.appended.push(...turnMessages);
90
+ const user = turnMessages.find((m) => m.sequence === fromSequence && m.role === 'user');
91
+ if (user !== undefined)
92
+ ctx.userMessage = user;
93
+ }
94
+ //# sourceMappingURL=rehydrate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rehydrate.js","sourceRoot":"","sources":["../../src/handlers/rehydrate.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,iCAAiC;AAiCjC,OAAO,EAAqB,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAIjE,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EACL,oBAAoB,EACpB,sBAAsB,EACtB,qBAAqB,GACtB,MAAM,uBAAuB,CAAC;AAQ/B,8EAA8E;AAC9E,SAAS,cAAc,CAAC,OAAgC;IACtD,MA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,CAAC,CAAC,CAAC;AAChE,CAAC;AAED,8EAA8E;AAC9E,KAAK,UAAU,eAAe,CAAC,GAAgB,EAAE,YAAoB;IACnE,MAAM,IAAI,GAAG,MAAM,GAAG,CAAC,QAAQ,CAAC,mBAAmB,CAAC,YAAY,CAAC;QAC/D,QAAQ,EAAE,GAAG,CAAC,KAAK,CAAC,QAAQ;QAC5B,cAAc,EAAE,GAAG,CAAC,KAAK,CAAC,cAAc;QACxC,aAAa,EAAE,YAAY,GAAG,CAAC;KAChC,CAAC,CAAC;IACH,IAAI,IAAI,CAAC,IAAI,KAAK,KAAK;QAAE,qBAAqB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAC3D,MAAM,YAAY,GAA0B,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,IAAI,YAAY,CAAC,CAAC;IACjG,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,YAAY,CAAC,CAAC;IACnC,MAAM,IAAI,GAAG,YAAY,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,KAAK,YAAY,IAAI,CAAC,CAAC,IAAI,KAAK,MAAM,CAAC,CAAC;IACxF,IAAI,IAAI,KAAK,SAAS;QAAE,GAAG,CAAC,WAAW,GAAG,IAAI,CAAC;AACjD,CAAC"}
@@ -0,0 +1,12 @@
1
+ import type { NodeHandler } from '@kindgi/handler';
2
+ import type { TurnContext } from './context.js';
3
+ /**
4
+ * Render the agent's instructions template with caller-supplied
5
+ * parameters + framework auto-vars. Fails the run with a
6
+ * `model-invocation-failed` (surfaced through `AgentTurnFailure`) if
7
+ * required parameters are missing or the template throws.
8
+ *
9
+ * Setup must have run first — `ctx.conversation` is required.
10
+ */
11
+ export declare function buildRenderPromptHandler(ctx: TurnContext): NodeHandler;
12
+ //# sourceMappingURL=render-prompt.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"render-prompt.d.ts","sourceRoot":"","sources":["../../src/handlers/render-prompt.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAInD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAGhD;;;;;;;GAOG;AACH,wBAAgB,wBAAwB,CAAC,GAAG,EAAE,WAAW,GAAG,WAAW,CA2BtE"}
@@ -0,0 +1,41 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ // Copyright (C) 2026 Kindgi Inc.
3
+ import { renderInstructions } from '../prompt.js';
4
+ import { throwAgentTurnFailure } from './errors.js';
5
+ /**
6
+ * Render the agent's instructions template with caller-supplied
7
+ * parameters + framework auto-vars. Fails the run with a
8
+ * `model-invocation-failed` (surfaced through `AgentTurnFailure`) if
9
+ * required parameters are missing or the template throws.
10
+ *
11
+ * Setup must have run first — `ctx.conversation` is required.
12
+ */
13
+ export function buildRenderPromptHandler(ctx) {
14
+ return async () => {
15
+ if (ctx.conversation === undefined) {
16
+ throwAgentTurnFailure({
17
+ code: 'model-invocation-failed',
18
+ message: 'render-prompt invoked before setup completed',
19
+ cause: null,
20
+ });
21
+ }
22
+ const rendered = renderInstructions(ctx.input.agent, {
23
+ parameters: ctx.input.parameters ?? {},
24
+ ...(ctx.input.input !== undefined && { input: ctx.input.input }),
25
+ conversation: {
26
+ id: ctx.input.conversationId,
27
+ turn: ctx.conversation.turnCount + 1,
28
+ },
29
+ });
30
+ if (!rendered.ok) {
31
+ throwAgentTurnFailure({
32
+ code: 'model-invocation-failed',
33
+ message: `Prompt render failed: ${rendered.error.message}`,
34
+ cause: rendered.error,
35
+ });
36
+ }
37
+ ctx.renderedPrompt = rendered.value.rendered;
38
+ return { rendered: rendered.value.rendered };
39
+ };
40
+ }
41
+ //# sourceMappingURL=render-prompt.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"render-prompt.js","sourceRoot":"","sources":["../../src/handlers/render-prompt.ts"],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,CAAC"}
@@ -0,0 +1,10 @@
1
+ import type { ToolRegistry } from '@kindgi/tools';
2
+ import type { Agent } from '../types.js';
3
+ import type { TurnContext } from './context.js';
4
+ /**
5
+ * Resolve the agent's tool references against one tenant's registry
6
+ * (`ToolRegistry.forTenant`). Throws the turn failure for an unknown
7
+ * tool or an unsatisfiable version range.
8
+ */
9
+ export declare function resolveTurnTools(registry: ToolRegistry, agent: Agent): NonNullable<TurnContext['tools']>;
10
+ //# sourceMappingURL=resolve-tools.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolve-tools.d.ts","sourceRoot":"","sources":["../../src/handlers/resolve-tools.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAQ,YAAY,EAAE,MAAM,eAAe,CAAC;AAExD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAEzC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAGhD;;;;GAIG;AACH,wBAAgB,gBAAgB,CAC9B,QAAQ,EAAE,YAAY,EACtB,KAAK,EAAE,KAAK,GACX,WAAW,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,CAgDnC"}
@@ -0,0 +1,55 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ // Copyright (C) 2026 Kindgi Inc.
3
+ import { throwAgentTurnFailure } from './errors.js';
4
+ /**
5
+ * Resolve the agent's tool references against one tenant's registry
6
+ * (`ToolRegistry.forTenant`). Throws the turn failure for an unknown
7
+ * tool or an unsatisfiable version range.
8
+ */
9
+ export function resolveTurnTools(registry, agent) {
10
+ const definitions = [];
11
+ const byName = new Map();
12
+ for (const ref of agent.tools) {
13
+ // Agent references tools by (id, range).
14
+ // Resolve at run start via `resolve` on the tenant-bound registry
15
+ // (npm-compatible semver, backed by `maxSatisfying`); capture `resolvedVersion` in
16
+ // the byName map so `dispatch-tools` can emit it in provenance +
17
+ // telemetry — a replay can then pin against the same version.
18
+ const resolved = registry.resolve(ref.id, ref.version);
19
+ if (resolved.kind === 'err') {
20
+ const err = resolved.error;
21
+ if (err.code === 'tool-not-found') {
22
+ throwAgentTurnFailure({
23
+ code: 'unresolved-tool',
24
+ message: `Tool "${ref.id}" declared by agent "${agent.id}" is not registered`,
25
+ toolId: ref.id,
26
+ });
27
+ }
28
+ if (err.code === 'invalid-version-range' || err.code === 'tool-version-unresolvable') {
29
+ throwAgentTurnFailure({
30
+ code: 'tool-version-unresolvable',
31
+ message: err.message,
32
+ toolId: ref.id,
33
+ requestedRange: ref.version,
34
+ ...(err.code === 'tool-version-unresolvable' && {
35
+ availableVersions: err.availableVersions,
36
+ }),
37
+ });
38
+ }
39
+ throwAgentTurnFailure({
40
+ code: 'unresolved-tool',
41
+ message: err.message,
42
+ toolId: ref.id,
43
+ });
44
+ }
45
+ const { tool, resolvedVersion } = resolved.value;
46
+ definitions.push({
47
+ name: tool.id,
48
+ description: tool.description,
49
+ inputSchema: tool.input,
50
+ });
51
+ byName.set(tool.id, { tool, resolvedVersion, requestedRange: ref.version });
52
+ }
53
+ return { definitions, byName };
54
+ }
55
+ //# sourceMappingURL=resolve-tools.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolve-tools.js","sourceRoot":"","sources":["../../src/handlers/resolve-tools.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,iCAAiC;AAQjC,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAEpD;;;;GAIG;AACH,MAAM,UAAU,gBAAgB,CAC9B,QAAsB,EACtB,KAAY;IAEZ,MAAM,WAAW,GAA0B,EAAE,CAAC;IAC9C,MAAM,MAAM,GAAG,IAAI,GAAG,EAGnB,CAAC;IACJ,KAAK,MAAM,GAAG,IAAI,KAAK,CAAC,KAAK,EAAE,CAAC;QAC9B,yCAAyC;QACzC,kEAAkE;QAClE,mFAAmF;QACnF,iEAAiE;QACjE,8DAA8D;QAC9D,MAAM,QAAQ,GAAG,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,E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