@jangts/agent-core 0.1.0 → 0.2.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 (527) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/README.md +59 -0
  3. package/development/docs/api/reference.md +1907 -1874
  4. package/development/docs/api/support.md +27 -0
  5. package/development/docs/assets/agent-core-icon.png +0 -0
  6. package/development/docs/assets/agent-core-logo.png +0 -0
  7. package/development/docs/assets/character-agent-core.png +0 -0
  8. package/development/skills/agent-core-app/scripts/create-app.mjs +267 -70
  9. package/development/skills/agent-core-app/scripts/lib/knowledge.mjs +40 -15
  10. package/development/skills/agent-core-app/scripts/lib/source.mjs +30 -2
  11. package/development/skills/agent-core-app/scripts/plan.mjs +37 -12
  12. package/development/skills/agent-core-app/scripts/prepare-source.mjs +61 -10
  13. package/development/skills/agent-core-app/scripts/resources.mjs +45 -17
  14. package/development/skills/agent-core-app/scripts/validate-knowledge.mjs +18 -1
  15. package/development/skills/agent-core-app/templates/catalog.json +36 -22
  16. package/dist/cjs/capabilities/index.js +13 -0
  17. package/dist/cjs/capabilities/invocation.js +80 -10
  18. package/dist/cjs/capabilities/model.js +126 -13
  19. package/dist/cjs/capabilities/tool-runtime.js +64 -12
  20. package/dist/cjs/capabilities/tools.js +266 -31
  21. package/dist/cjs/context/assembly.js +46 -5
  22. package/dist/cjs/context/audit.js +31 -6
  23. package/dist/cjs/context/fragments.js +54 -11
  24. package/dist/cjs/context/index.js +12 -0
  25. package/dist/cjs/context/journal.js +84 -7
  26. package/dist/cjs/context/plan.js +30 -2
  27. package/dist/cjs/diagnostics/catalog.js +11 -3
  28. package/dist/cjs/diagnostics/index.js +149 -29
  29. package/dist/cjs/diagnostics/sub-flow.js +240 -40
  30. package/dist/cjs/errors.js +99 -17
  31. package/dist/cjs/execution/branch.js +20 -4
  32. package/dist/cjs/execution/engine.js +470 -56
  33. package/dist/cjs/execution/events.js +136 -18
  34. package/dist/cjs/execution/index.js +7 -0
  35. package/dist/cjs/execution/reporting.js +75 -6
  36. package/dist/cjs/execution/state.js +161 -22
  37. package/dist/cjs/execution/workflow.js +224 -32
  38. package/dist/cjs/index.js +18 -0
  39. package/dist/cjs/kits/aggregation.js +45 -3
  40. package/dist/cjs/kits/answering/batch.js +23 -4
  41. package/dist/cjs/kits/answering/check-result.js +31 -8
  42. package/dist/cjs/kits/answering/checks.js +24 -3
  43. package/dist/cjs/kits/answering/flow.js +192 -36
  44. package/dist/cjs/kits/answering/index.js +19 -1
  45. package/dist/cjs/kits/answering/tasks.js +88 -13
  46. package/dist/cjs/kits/artifacts.js +36 -4
  47. package/dist/cjs/kits/candidates.js +47 -5
  48. package/dist/cjs/kits/delivery.js +40 -5
  49. package/dist/cjs/kits/durable.js +155 -31
  50. package/dist/cjs/kits/evidence.js +66 -15
  51. package/dist/cjs/kits/family.js +152 -22
  52. package/dist/cjs/kits/index.js +12 -1
  53. package/dist/cjs/kits/inference.js +104 -16
  54. package/dist/cjs/kits/intents/catalog.js +67 -16
  55. package/dist/cjs/kits/intents/index.js +11 -0
  56. package/dist/cjs/kits/intents/registry.js +188 -43
  57. package/dist/cjs/kits/intents/scopes.js +215 -46
  58. package/dist/cjs/kits/interaction/command.js +140 -36
  59. package/dist/cjs/kits/interaction/commands.js +86 -11
  60. package/dist/cjs/kits/interaction/handlers.js +27 -10
  61. package/dist/cjs/kits/interaction/index.js +10 -0
  62. package/dist/cjs/kits/interaction/transfer.js +80 -14
  63. package/dist/cjs/kits/knowledge/catalog.js +62 -11
  64. package/dist/cjs/kits/knowledge/index.js +16 -1
  65. package/dist/cjs/kits/knowledge/publication.js +99 -23
  66. package/dist/cjs/kits/knowledge/sections.js +33 -4
  67. package/dist/cjs/kits/normalization.js +51 -7
  68. package/dist/cjs/kits/policies.js +79 -15
  69. package/dist/cjs/kits/presentation/events.js +54 -10
  70. package/dist/cjs/kits/presentation/index.js +24 -1
  71. package/dist/cjs/kits/presentation/outputs.js +176 -38
  72. package/dist/cjs/kits/presentation/templates.js +33 -5
  73. package/dist/cjs/kits/presentation/variants.js +31 -2
  74. package/dist/cjs/kits/projection.js +63 -8
  75. package/dist/cjs/kits/rank-fusion.js +27 -4
  76. package/dist/cjs/kits/reflection-log-source.js +89 -16
  77. package/dist/cjs/kits/reflection.js +234 -60
  78. package/dist/cjs/kits/retrieval.js +98 -18
  79. package/dist/cjs/kits/search.js +180 -27
  80. package/dist/cjs/kits/text-skills.js +104 -19
  81. package/dist/cjs/kits/tools.js +415 -74
  82. package/dist/cjs/kits/vector-search.js +50 -16
  83. package/dist/cjs/mock/node.js +7 -1
  84. package/dist/cjs/mock/web.js +7 -1
  85. package/dist/cjs/mock.js +7 -1
  86. package/dist/cjs/model/binding.js +68 -17
  87. package/dist/cjs/model/call-budget.js +45 -4
  88. package/dist/cjs/model/decision-retry.js +19 -1
  89. package/dist/cjs/model/defaults.js +27 -4
  90. package/dist/cjs/model/index.js +7 -0
  91. package/dist/cjs/model/interactions/arguments.js +36 -1
  92. package/dist/cjs/model/interactions/json-object.js +48 -12
  93. package/dist/cjs/model/interactions/native-functions.js +52 -10
  94. package/dist/cjs/model/message-diagnostics.js +17 -4
  95. package/dist/cjs/model/options.js +9 -1
  96. package/dist/cjs/model/preparation.js +86 -12
  97. package/dist/cjs/model/runner.js +413 -79
  98. package/dist/cjs/model/selection-transport.js +48 -8
  99. package/dist/cjs/model/settings.js +67 -13
  100. package/dist/cjs/model/token-budget.js +69 -11
  101. package/dist/cjs/model/transports.js +59 -6
  102. package/dist/cjs/structs/common.js +11 -0
  103. package/dist/cjs/structs/debug.js +34 -5
  104. package/dist/cjs/structs/errors.js +26 -1
  105. package/dist/cjs/structs/index.js +11 -1
  106. package/dist/cjs/structs/kits/durable.js +7 -0
  107. package/dist/cjs/structs/kits/family.js +1 -0
  108. package/dist/cjs/structs/kits/interaction.js +8 -1
  109. package/dist/cjs/structs/kits/knowledge-publication.js +1 -0
  110. package/dist/cjs/structs/kits/reflection.js +18 -3
  111. package/dist/cjs/structs/model/chat-provider.js +6 -0
  112. package/dist/cjs/structs/support/model/completion.js +2 -0
  113. package/dist/cjs/structs/support/model/messages.js +2 -0
  114. package/dist/cjs/support/capabilities.js +43 -6
  115. package/dist/cjs/support/context/assembly.js +88 -16
  116. package/dist/cjs/support/context/compression.js +48 -6
  117. package/dist/cjs/support/context/fragments.js +6 -0
  118. package/dist/cjs/support/context/history.js +36 -1
  119. package/dist/cjs/support/context/index.js +11 -0
  120. package/dist/cjs/support/context/nodes.js +164 -35
  121. package/dist/cjs/support/context/processing.js +319 -61
  122. package/dist/cjs/support/context/selection-policy.js +98 -21
  123. package/dist/cjs/support/context/selection.js +61 -10
  124. package/dist/cjs/support/context/snapshot.js +29 -7
  125. package/dist/cjs/support/context/strategies.js +120 -28
  126. package/dist/cjs/support/index.js +9 -1
  127. package/dist/cjs/support/model/capabilities.js +20 -1
  128. package/dist/cjs/support/model/chat-completions.js +92 -20
  129. package/dist/cjs/support/model/children.js +34 -6
  130. package/dist/cjs/support/model/compatible-provider.js +189 -59
  131. package/dist/cjs/support/model/completion/calls.js +61 -0
  132. package/dist/cjs/support/model/completion/default.js +32 -0
  133. package/dist/cjs/support/model/completion/index.js +28 -0
  134. package/dist/cjs/support/model/completion/session.js +102 -0
  135. package/dist/cjs/support/model/index.js +12 -0
  136. package/dist/cjs/support/model/interactions/index.js +12 -1
  137. package/dist/cjs/support/model/interactions/json-object.js +6 -0
  138. package/dist/cjs/support/model/interactions/native-functions.js +6 -0
  139. package/dist/cjs/support/model/observer.js +32 -6
  140. package/dist/cjs/support/model/preview-rules.js +66 -16
  141. package/dist/cjs/support/model/reply-preview.js +77 -17
  142. package/dist/cjs/support/model/stage-transport.js +33 -7
  143. package/dist/cjs/support/model/strategies.js +75 -14
  144. package/dist/cjs/support/model/transports.js +53 -11
  145. package/dist/cjs/support/registration.js +49 -7
  146. package/dist/cjs/support/schema.js +46 -4
  147. package/dist/cjs/support/stream-events.js +60 -8
  148. package/dist/cjs/support/tool-runtime.js +6 -0
  149. package/dist/cjs/support/tools.js +79 -10
  150. package/dist/cjs/support/transport/index.js +7 -0
  151. package/dist/cjs/support/transport/json.js +28 -4
  152. package/dist/cjs/support/transport/sse.js +25 -2
  153. package/dist/cjs/utils/break-observer.js +20 -2
  154. package/dist/cjs/utils/cancellation.js +77 -9
  155. package/dist/cjs/utils/catalog.js +19 -4
  156. package/dist/cjs/utils/debug.js +14 -2
  157. package/dist/cjs/utils/index.js +8 -0
  158. package/dist/cjs/utils/interaction-definition.js +26 -6
  159. package/dist/cjs/utils/invocation.js +42 -4
  160. package/dist/cjs/utils/model-protocol.js +20 -1
  161. package/dist/cjs/utils/object.js +16 -0
  162. package/dist/cjs/utils/observer.js +22 -2
  163. package/dist/cjs/utils/protocol-registry.js +47 -4
  164. package/dist/cjs/utils/query-key.js +21 -2
  165. package/dist/cjs/utils/registration.js +18 -2
  166. package/dist/cjs/utils/rules.js +39 -11
  167. package/dist/cjs/utils/schema-adapter.js +25 -2
  168. package/dist/cjs/utils/synchronous.js +64 -7
  169. package/dist/cjs/utils/text.js +15 -1
  170. package/dist/esm/capabilities/index.d.ts +13 -0
  171. package/dist/esm/capabilities/index.js +13 -0
  172. package/dist/esm/capabilities/invocation.d.ts +16 -2
  173. package/dist/esm/capabilities/invocation.js +80 -10
  174. package/dist/esm/capabilities/model.d.ts +68 -1
  175. package/dist/esm/capabilities/model.js +126 -13
  176. package/dist/esm/capabilities/tool-runtime.d.ts +11 -0
  177. package/dist/esm/capabilities/tool-runtime.js +64 -12
  178. package/dist/esm/capabilities/tools.d.ts +96 -3
  179. package/dist/esm/capabilities/tools.js +267 -32
  180. package/dist/esm/context/assembly.d.ts +13 -2
  181. package/dist/esm/context/assembly.js +46 -5
  182. package/dist/esm/context/audit.d.ts +23 -1
  183. package/dist/esm/context/audit.js +31 -6
  184. package/dist/esm/context/fragments.d.ts +37 -3
  185. package/dist/esm/context/fragments.js +54 -11
  186. package/dist/esm/context/index.d.ts +12 -0
  187. package/dist/esm/context/index.js +12 -0
  188. package/dist/esm/context/journal.d.ts +32 -1
  189. package/dist/esm/context/journal.js +84 -7
  190. package/dist/esm/context/plan.d.ts +11 -1
  191. package/dist/esm/context/plan.js +30 -2
  192. package/dist/esm/diagnostics/catalog.js +11 -3
  193. package/dist/esm/diagnostics/index.d.ts +30 -2
  194. package/dist/esm/diagnostics/index.js +149 -29
  195. package/dist/esm/diagnostics/sub-flow.d.ts +41 -3
  196. package/dist/esm/diagnostics/sub-flow.js +240 -40
  197. package/dist/esm/errors.d.ts +22 -2
  198. package/dist/esm/errors.js +99 -17
  199. package/dist/esm/execution/branch.d.ts +19 -1
  200. package/dist/esm/execution/branch.js +20 -4
  201. package/dist/esm/execution/engine.d.ts +291 -5
  202. package/dist/esm/execution/engine.js +471 -57
  203. package/dist/esm/execution/events.d.ts +16 -2
  204. package/dist/esm/execution/events.js +136 -18
  205. package/dist/esm/execution/index.d.ts +7 -0
  206. package/dist/esm/execution/index.js +7 -0
  207. package/dist/esm/execution/reporting.d.ts +49 -1
  208. package/dist/esm/execution/reporting.js +75 -6
  209. package/dist/esm/execution/state.d.ts +126 -10
  210. package/dist/esm/execution/state.js +161 -22
  211. package/dist/esm/execution/workflow.d.ts +121 -3
  212. package/dist/esm/execution/workflow.js +224 -32
  213. package/dist/esm/index.d.ts +17 -1
  214. package/dist/esm/index.js +18 -0
  215. package/dist/esm/kits/aggregation.d.ts +34 -2
  216. package/dist/esm/kits/aggregation.js +45 -3
  217. package/dist/esm/kits/answering/batch.d.ts +17 -0
  218. package/dist/esm/kits/answering/batch.js +23 -4
  219. package/dist/esm/kits/answering/check-result.d.ts +18 -1
  220. package/dist/esm/kits/answering/check-result.js +31 -8
  221. package/dist/esm/kits/answering/checks.d.ts +11 -0
  222. package/dist/esm/kits/answering/checks.js +24 -3
  223. package/dist/esm/kits/answering/flow.d.ts +25 -2
  224. package/dist/esm/kits/answering/flow.js +192 -36
  225. package/dist/esm/kits/answering/index.d.ts +12 -0
  226. package/dist/esm/kits/answering/index.js +19 -1
  227. package/dist/esm/kits/answering/tasks.d.ts +32 -1
  228. package/dist/esm/kits/answering/tasks.js +88 -13
  229. package/dist/esm/kits/artifacts.d.ts +11 -0
  230. package/dist/esm/kits/artifacts.js +36 -4
  231. package/dist/esm/kits/candidates.d.ts +23 -1
  232. package/dist/esm/kits/candidates.js +47 -5
  233. package/dist/esm/kits/delivery.d.ts +34 -0
  234. package/dist/esm/kits/delivery.js +40 -5
  235. package/dist/esm/kits/durable.d.ts +19 -0
  236. package/dist/esm/kits/durable.js +155 -31
  237. package/dist/esm/kits/evidence.d.ts +28 -5
  238. package/dist/esm/kits/evidence.js +66 -15
  239. package/dist/esm/kits/family.d.ts +17 -1
  240. package/dist/esm/kits/family.js +152 -22
  241. package/dist/esm/kits/index.d.ts +12 -1
  242. package/dist/esm/kits/index.js +12 -1
  243. package/dist/esm/kits/inference.d.ts +64 -0
  244. package/dist/esm/kits/inference.js +104 -16
  245. package/dist/esm/kits/intents/catalog.d.ts +13 -1
  246. package/dist/esm/kits/intents/catalog.js +67 -16
  247. package/dist/esm/kits/intents/index.d.ts +11 -0
  248. package/dist/esm/kits/intents/index.js +11 -0
  249. package/dist/esm/kits/intents/registry.d.ts +61 -3
  250. package/dist/esm/kits/intents/registry.js +188 -43
  251. package/dist/esm/kits/intents/scopes.d.ts +73 -3
  252. package/dist/esm/kits/intents/scopes.js +215 -46
  253. package/dist/esm/kits/interaction/command.d.ts +38 -4
  254. package/dist/esm/kits/interaction/command.js +140 -36
  255. package/dist/esm/kits/interaction/commands.d.ts +66 -2
  256. package/dist/esm/kits/interaction/commands.js +86 -11
  257. package/dist/esm/kits/interaction/handlers.d.ts +19 -2
  258. package/dist/esm/kits/interaction/handlers.js +27 -10
  259. package/dist/esm/kits/interaction/index.d.ts +10 -0
  260. package/dist/esm/kits/interaction/index.js +10 -0
  261. package/dist/esm/kits/interaction/transfer.d.ts +39 -2
  262. package/dist/esm/kits/interaction/transfer.js +80 -14
  263. package/dist/esm/kits/knowledge/catalog.d.ts +13 -0
  264. package/dist/esm/kits/knowledge/catalog.js +62 -11
  265. package/dist/esm/kits/knowledge/index.d.ts +11 -0
  266. package/dist/esm/kits/knowledge/index.js +16 -1
  267. package/dist/esm/kits/knowledge/publication.d.ts +15 -1
  268. package/dist/esm/kits/knowledge/publication.js +99 -23
  269. package/dist/esm/kits/knowledge/sections.d.ts +31 -1
  270. package/dist/esm/kits/knowledge/sections.js +33 -4
  271. package/dist/esm/kits/normalization.d.ts +25 -2
  272. package/dist/esm/kits/normalization.js +51 -7
  273. package/dist/esm/kits/policies.d.ts +26 -3
  274. package/dist/esm/kits/policies.js +79 -15
  275. package/dist/esm/kits/presentation/events.d.ts +51 -4
  276. package/dist/esm/kits/presentation/events.js +54 -10
  277. package/dist/esm/kits/presentation/index.d.ts +12 -0
  278. package/dist/esm/kits/presentation/index.js +25 -2
  279. package/dist/esm/kits/presentation/outputs.d.ts +30 -1
  280. package/dist/esm/kits/presentation/outputs.js +176 -38
  281. package/dist/esm/kits/presentation/templates.d.ts +32 -3
  282. package/dist/esm/kits/presentation/templates.js +33 -5
  283. package/dist/esm/kits/presentation/variants.d.ts +29 -0
  284. package/dist/esm/kits/presentation/variants.js +31 -2
  285. package/dist/esm/kits/projection.d.ts +42 -5
  286. package/dist/esm/kits/projection.js +63 -8
  287. package/dist/esm/kits/rank-fusion.d.ts +21 -1
  288. package/dist/esm/kits/rank-fusion.js +28 -5
  289. package/dist/esm/kits/reflection-log-source.d.ts +28 -1
  290. package/dist/esm/kits/reflection-log-source.js +89 -16
  291. package/dist/esm/kits/reflection.d.ts +17 -1
  292. package/dist/esm/kits/reflection.js +235 -61
  293. package/dist/esm/kits/retrieval.d.ts +18 -2
  294. package/dist/esm/kits/retrieval.js +98 -18
  295. package/dist/esm/kits/search.d.ts +56 -3
  296. package/dist/esm/kits/search.js +180 -27
  297. package/dist/esm/kits/text-skills.d.ts +16 -2
  298. package/dist/esm/kits/text-skills.js +104 -19
  299. package/dist/esm/kits/tools.d.ts +122 -2
  300. package/dist/esm/kits/tools.js +416 -74
  301. package/dist/esm/kits/vector-search.d.ts +47 -1
  302. package/dist/esm/kits/vector-search.js +51 -17
  303. package/dist/esm/mock/node.d.ts +7 -0
  304. package/dist/esm/mock/node.js +7 -1
  305. package/dist/esm/mock/web.d.ts +7 -0
  306. package/dist/esm/mock/web.js +7 -1
  307. package/dist/esm/mock.d.ts +7 -0
  308. package/dist/esm/mock.js +7 -1
  309. package/dist/esm/model/binding.d.ts +32 -3
  310. package/dist/esm/model/binding.js +68 -17
  311. package/dist/esm/model/call-budget.d.ts +30 -2
  312. package/dist/esm/model/call-budget.js +45 -4
  313. package/dist/esm/model/decision-retry.d.ts +10 -1
  314. package/dist/esm/model/decision-retry.js +19 -1
  315. package/dist/esm/model/defaults.d.ts +13 -2
  316. package/dist/esm/model/defaults.js +27 -4
  317. package/dist/esm/model/index.d.ts +7 -0
  318. package/dist/esm/model/index.js +7 -0
  319. package/dist/esm/model/interactions/arguments.d.ts +27 -0
  320. package/dist/esm/model/interactions/arguments.js +36 -1
  321. package/dist/esm/model/interactions/json-object.d.ts +7 -1
  322. package/dist/esm/model/interactions/json-object.js +48 -12
  323. package/dist/esm/model/interactions/native-functions.d.ts +6 -0
  324. package/dist/esm/model/interactions/native-functions.js +52 -10
  325. package/dist/esm/model/message-diagnostics.d.ts +17 -1
  326. package/dist/esm/model/message-diagnostics.js +17 -4
  327. package/dist/esm/model/options.d.ts +18 -1
  328. package/dist/esm/model/options.js +9 -1
  329. package/dist/esm/model/preparation.d.ts +30 -2
  330. package/dist/esm/model/preparation.js +86 -12
  331. package/dist/esm/model/runner.d.ts +129 -5
  332. package/dist/esm/model/runner.js +414 -80
  333. package/dist/esm/model/selection-transport.d.ts +14 -1
  334. package/dist/esm/model/selection-transport.js +48 -8
  335. package/dist/esm/model/settings.d.ts +11 -0
  336. package/dist/esm/model/settings.js +67 -13
  337. package/dist/esm/model/token-budget.d.ts +59 -1
  338. package/dist/esm/model/token-budget.js +69 -11
  339. package/dist/esm/model/transports.d.ts +20 -2
  340. package/dist/esm/model/transports.js +59 -6
  341. package/dist/esm/structs/capabilities/invocation.d.ts +36 -0
  342. package/dist/esm/structs/capabilities/model.d.ts +27 -0
  343. package/dist/esm/structs/capabilities/tools.d.ts +38 -0
  344. package/dist/esm/structs/common.d.ts +62 -2
  345. package/dist/esm/structs/common.js +11 -0
  346. package/dist/esm/structs/context/fragments.d.ts +28 -0
  347. package/dist/esm/structs/context/journal.d.ts +28 -3
  348. package/dist/esm/structs/context/processing.d.ts +11 -0
  349. package/dist/esm/structs/debug.d.ts +58 -1
  350. package/dist/esm/structs/debug.js +34 -5
  351. package/dist/esm/structs/diagnostics.d.ts +119 -1
  352. package/dist/esm/structs/errors.d.ts +42 -1
  353. package/dist/esm/structs/errors.js +26 -1
  354. package/dist/esm/structs/execution/engine.d.ts +24 -1
  355. package/dist/esm/structs/execution/events.d.ts +12 -0
  356. package/dist/esm/structs/execution/workflow.d.ts +71 -0
  357. package/dist/esm/structs/index.d.ts +11 -1
  358. package/dist/esm/structs/index.js +11 -1
  359. package/dist/esm/structs/invocation.d.ts +30 -0
  360. package/dist/esm/structs/kits/aggregation.d.ts +12 -0
  361. package/dist/esm/structs/kits/answering/checks.d.ts +11 -0
  362. package/dist/esm/structs/kits/answering/flow.d.ts +35 -1
  363. package/dist/esm/structs/kits/answering/state.d.ts +21 -0
  364. package/dist/esm/structs/kits/answering/tasks.d.ts +21 -0
  365. package/dist/esm/structs/kits/artifacts.d.ts +14 -0
  366. package/dist/esm/structs/kits/candidates.d.ts +19 -0
  367. package/dist/esm/structs/kits/delivery.d.ts +22 -0
  368. package/dist/esm/structs/kits/durable.d.ts +56 -3
  369. package/dist/esm/structs/kits/durable.js +7 -0
  370. package/dist/esm/structs/kits/evidence.d.ts +23 -0
  371. package/dist/esm/structs/kits/family.d.ts +49 -1
  372. package/dist/esm/structs/kits/family.js +1 -0
  373. package/dist/esm/structs/kits/intents/catalog.d.ts +26 -0
  374. package/dist/esm/structs/kits/intents/registry.d.ts +34 -0
  375. package/dist/esm/structs/kits/intents/scopes.d.ts +36 -1
  376. package/dist/esm/structs/kits/interaction.d.ts +64 -0
  377. package/dist/esm/structs/kits/interaction.js +8 -1
  378. package/dist/esm/structs/kits/knowledge-publication.d.ts +43 -1
  379. package/dist/esm/structs/kits/knowledge-publication.js +1 -0
  380. package/dist/esm/structs/kits/knowledge.d.ts +39 -2
  381. package/dist/esm/structs/kits/normalization.d.ts +15 -0
  382. package/dist/esm/structs/kits/policies.d.ts +25 -1
  383. package/dist/esm/structs/kits/presentation/events.d.ts +28 -4
  384. package/dist/esm/structs/kits/presentation/outputs.d.ts +38 -1
  385. package/dist/esm/structs/kits/presentation/templates.d.ts +15 -0
  386. package/dist/esm/structs/kits/projection.d.ts +21 -0
  387. package/dist/esm/structs/kits/reflection.d.ts +61 -2
  388. package/dist/esm/structs/kits/reflection.js +18 -3
  389. package/dist/esm/structs/kits/retrieval.d.ts +38 -0
  390. package/dist/esm/structs/kits/search.d.ts +22 -0
  391. package/dist/esm/structs/kits/text-skills.d.ts +36 -0
  392. package/dist/esm/structs/kits/tools.d.ts +87 -0
  393. package/dist/esm/structs/model/chat-provider.d.ts +24 -1
  394. package/dist/esm/structs/model/chat-provider.js +6 -0
  395. package/dist/esm/structs/model/interactions.d.ts +38 -0
  396. package/dist/esm/structs/model/messages.d.ts +30 -0
  397. package/dist/esm/structs/model/runtime.d.ts +104 -6
  398. package/dist/esm/structs/support/capabilities.d.ts +19 -2
  399. package/dist/esm/structs/support/context-processing.d.ts +88 -9
  400. package/dist/esm/structs/support/context.d.ts +29 -1
  401. package/dist/esm/structs/support/model/completion.d.ts +50 -0
  402. package/dist/esm/structs/support/model/completion.js +1 -0
  403. package/dist/esm/structs/support/model/interactions.d.ts +13 -1
  404. package/dist/esm/structs/support/model/messages.d.ts +52 -0
  405. package/dist/esm/structs/support/model/messages.js +1 -0
  406. package/dist/esm/structs/support/model/provider-observer.d.ts +22 -1
  407. package/dist/esm/structs/support/model/provider.d.ts +71 -6
  408. package/dist/esm/structs/support/registration.d.ts +13 -0
  409. package/dist/esm/structs/support/schema.d.ts +14 -0
  410. package/dist/esm/structs/support/tools.d.ts +28 -0
  411. package/dist/esm/structs/support/transport/json.d.ts +16 -0
  412. package/dist/esm/structs/support/transport/sse.d.ts +15 -0
  413. package/dist/esm/structs/utils/rules.d.ts +19 -0
  414. package/dist/esm/support/capabilities.d.ts +25 -2
  415. package/dist/esm/support/capabilities.js +43 -6
  416. package/dist/esm/support/context/assembly.d.ts +35 -4
  417. package/dist/esm/support/context/assembly.js +88 -16
  418. package/dist/esm/support/context/compression.d.ts +17 -1
  419. package/dist/esm/support/context/compression.js +48 -6
  420. package/dist/esm/support/context/fragments.d.ts +6 -0
  421. package/dist/esm/support/context/fragments.js +6 -0
  422. package/dist/esm/support/context/history.d.ts +43 -0
  423. package/dist/esm/support/context/history.js +36 -1
  424. package/dist/esm/support/context/index.d.ts +13 -2
  425. package/dist/esm/support/context/index.js +12 -1
  426. package/dist/esm/support/context/nodes.d.ts +49 -3
  427. package/dist/esm/support/context/nodes.js +165 -36
  428. package/dist/esm/support/context/processing.d.ts +145 -1
  429. package/dist/esm/support/context/processing.js +320 -62
  430. package/dist/esm/support/context/selection-policy.d.ts +42 -2
  431. package/dist/esm/support/context/selection-policy.js +98 -21
  432. package/dist/esm/support/context/selection.d.ts +14 -1
  433. package/dist/esm/support/context/selection.js +61 -10
  434. package/dist/esm/support/context/snapshot.d.ts +23 -1
  435. package/dist/esm/support/context/snapshot.js +29 -7
  436. package/dist/esm/support/context/strategies.d.ts +35 -2
  437. package/dist/esm/support/context/strategies.js +120 -28
  438. package/dist/esm/support/index.d.ts +9 -1
  439. package/dist/esm/support/index.js +9 -1
  440. package/dist/esm/support/model/capabilities.d.ts +10 -0
  441. package/dist/esm/support/model/capabilities.js +20 -1
  442. package/dist/esm/support/model/chat-completions.d.ts +44 -15
  443. package/dist/esm/support/model/chat-completions.js +92 -20
  444. package/dist/esm/support/model/children.d.ts +32 -2
  445. package/dist/esm/support/model/children.js +34 -6
  446. package/dist/esm/support/model/compatible-provider.d.ts +29 -3
  447. package/dist/esm/support/model/compatible-provider.js +190 -60
  448. package/dist/esm/support/model/completion/calls.d.ts +40 -0
  449. package/dist/esm/support/model/completion/calls.js +58 -0
  450. package/dist/esm/support/model/completion/default.d.ts +10 -0
  451. package/dist/esm/support/model/completion/default.js +29 -0
  452. package/dist/esm/support/model/completion/index.d.ts +10 -0
  453. package/dist/esm/support/model/completion/index.js +22 -0
  454. package/dist/esm/support/model/completion/session.d.ts +11 -0
  455. package/dist/esm/support/model/completion/session.js +99 -0
  456. package/dist/esm/support/model/index.d.ts +14 -0
  457. package/dist/esm/support/model/index.js +12 -0
  458. package/dist/esm/support/model/interactions/index.d.ts +1 -1
  459. package/dist/esm/support/model/interactions/index.js +12 -1
  460. package/dist/esm/support/model/interactions/json-object.d.ts +6 -0
  461. package/dist/esm/support/model/interactions/json-object.js +6 -0
  462. package/dist/esm/support/model/interactions/native-functions.d.ts +6 -0
  463. package/dist/esm/support/model/interactions/native-functions.js +6 -0
  464. package/dist/esm/support/model/observer.d.ts +25 -2
  465. package/dist/esm/support/model/observer.js +32 -6
  466. package/dist/esm/support/model/preview-rules.d.ts +20 -2
  467. package/dist/esm/support/model/preview-rules.js +66 -16
  468. package/dist/esm/support/model/reply-preview.d.ts +15 -1
  469. package/dist/esm/support/model/reply-preview.js +77 -17
  470. package/dist/esm/support/model/stage-transport.d.ts +9 -1
  471. package/dist/esm/support/model/stage-transport.js +33 -7
  472. package/dist/esm/support/model/strategies.d.ts +24 -2
  473. package/dist/esm/support/model/strategies.js +75 -14
  474. package/dist/esm/support/model/transports.d.ts +17 -1
  475. package/dist/esm/support/model/transports.js +53 -11
  476. package/dist/esm/support/registration.d.ts +20 -1
  477. package/dist/esm/support/registration.js +49 -7
  478. package/dist/esm/support/schema.d.ts +31 -1
  479. package/dist/esm/support/schema.js +46 -4
  480. package/dist/esm/support/stream-events.d.ts +22 -1
  481. package/dist/esm/support/stream-events.js +60 -8
  482. package/dist/esm/support/tool-runtime.d.ts +6 -0
  483. package/dist/esm/support/tool-runtime.js +6 -0
  484. package/dist/esm/support/tools.d.ts +22 -0
  485. package/dist/esm/support/tools.js +79 -10
  486. package/dist/esm/support/transport/index.d.ts +7 -0
  487. package/dist/esm/support/transport/index.js +7 -0
  488. package/dist/esm/support/transport/json.d.ts +29 -2
  489. package/dist/esm/support/transport/json.js +28 -4
  490. package/dist/esm/support/transport/sse.d.ts +31 -1
  491. package/dist/esm/support/transport/sse.js +25 -2
  492. package/dist/esm/types.d.ts +9 -1
  493. package/dist/esm/utils/break-observer.d.ts +27 -2
  494. package/dist/esm/utils/break-observer.js +20 -2
  495. package/dist/esm/utils/cancellation.d.ts +56 -5
  496. package/dist/esm/utils/cancellation.js +77 -9
  497. package/dist/esm/utils/catalog.d.ts +20 -1
  498. package/dist/esm/utils/catalog.js +19 -4
  499. package/dist/esm/utils/debug.d.ts +20 -1
  500. package/dist/esm/utils/debug.js +14 -2
  501. package/dist/esm/utils/index.d.ts +8 -0
  502. package/dist/esm/utils/index.js +8 -0
  503. package/dist/esm/utils/interaction-definition.d.ts +18 -1
  504. package/dist/esm/utils/interaction-definition.js +26 -6
  505. package/dist/esm/utils/invocation.d.ts +36 -1
  506. package/dist/esm/utils/invocation.js +42 -4
  507. package/dist/esm/utils/model-protocol.d.ts +8 -0
  508. package/dist/esm/utils/model-protocol.js +20 -1
  509. package/dist/esm/utils/object.d.ts +16 -0
  510. package/dist/esm/utils/object.js +16 -0
  511. package/dist/esm/utils/observer.d.ts +19 -1
  512. package/dist/esm/utils/observer.js +22 -2
  513. package/dist/esm/utils/protocol-registry.d.ts +38 -1
  514. package/dist/esm/utils/protocol-registry.js +47 -4
  515. package/dist/esm/utils/query-key.d.ts +11 -1
  516. package/dist/esm/utils/query-key.js +21 -2
  517. package/dist/esm/utils/registration.d.ts +34 -2
  518. package/dist/esm/utils/registration.js +18 -2
  519. package/dist/esm/utils/rules.d.ts +81 -4
  520. package/dist/esm/utils/rules.js +39 -11
  521. package/dist/esm/utils/schema-adapter.d.ts +12 -1
  522. package/dist/esm/utils/schema-adapter.js +25 -2
  523. package/dist/esm/utils/synchronous.d.ts +60 -4
  524. package/dist/esm/utils/synchronous.js +64 -7
  525. package/dist/esm/utils/text.d.ts +15 -1
  526. package/dist/esm/utils/text.js +15 -1
  527. package/package.json +23 -3
@@ -1,23 +1,47 @@
1
- export type AgentOutputEvent = {
1
+ /**
2
+ * Presentation event contract for the Presentation Kit.
3
+ *
4
+ * Place in the package: an optional App-side output protocol between a validated reply and the
5
+ * transport that displays it. Events describe already-validated text; they never represent
6
+ * upstream model generation or an unvalidated draft.
7
+ *
8
+ * Exports: `AgentOutputEvent`, `ReplyBubbleInput`, `ReplyDeliveryOptions`.
9
+ */
10
+ /** One output event of a delivered reply. */
11
+ export type AgentOutputEvent =
12
+ /** Visible text chunk to append. */
13
+ {
2
14
  type: 'text';
3
15
  text: string;
4
- } | {
16
+ }
17
+ /** Preview of the bubbles to be delivered, emitted before any text. */
18
+ | {
5
19
  type: 'preview';
6
20
  bubbles: string[];
7
- } | {
21
+ }
22
+ /** Replaces everything delivered so far with `text`. */
23
+ | {
8
24
  type: 'replace';
9
25
  text: string;
10
- } | {
26
+ }
27
+ /** Separates the next text chunk into a new bubble. */
28
+ | {
11
29
  type: 'bubble';
12
30
  };
31
+ /** Reply pieces accepted by the bubble helpers; non-string entries are ignored. */
13
32
  export interface ReplyBubbleInput {
33
+ /** Primary reply text. */
14
34
  text?: unknown;
35
+ /** Additional bubbles appended after `text`, when the value is an array. */
15
36
  bubbles?: unknown;
16
37
  }
17
38
  /** Host-controlled delivery of already validated text; not upstream model generation. */
18
39
  export interface ReplyDeliveryOptions {
40
+ /** Characters per emitted text event; defaults to 240 and must be a positive integer. */
19
41
  chunkSize?: number;
42
+ /** Delay between chunks in milliseconds; defaults to 0. */
20
43
  intervalMs?: number;
44
+ /** Delay between bubbles in milliseconds; defaults to 0. */
21
45
  bubblePauseMs?: number;
22
46
  /** Upper bound on intentional pacing time; backpressure and network time are independent. */
23
47
  maxDurationMs?: number;
@@ -1,45 +1,82 @@
1
+ /**
2
+ * Structured output contract for the Presentation Kit.
3
+ *
4
+ * Place in the package: an optional App-side catalog that turns a generated record into a typed
5
+ * output. Ownership decides where each field value comes from; the catalog validates references
6
+ * and renders the model-visible schema, while the meaning of every output stays with the App.
7
+ *
8
+ * Exports: `OutputField`, `OutputDefinition`, `OutputProvider`, `OutputIssue`,
9
+ * `OutputComposeInput`, `OutputResult`, `OutputCatalogOptions`.
10
+ */
1
11
  import type { SchemaAdapter, OperationContext, Issue } from '../../common.js';
12
+ /** One field of an output definition. */
2
13
  export interface OutputField {
14
+ /** Field id, used as the property name and as a master-template slot name. */
3
15
  readonly id: string;
16
+ /**
17
+ * Where the value comes from: `generated` (model writes it), `bound` (provider resolves it),
18
+ * `constant` (fixed `constantValue`) or `semantic` (model picks one of `semanticKeys`).
19
+ */
4
20
  readonly owner: 'generated' | 'bound' | 'constant' | 'semantic';
21
+ /** Whether the model must provide the field; defaults to true. */
5
22
  readonly required?: boolean;
6
- /** Defaults to a string parser when omitted. */
23
+ /** Value parser and schema. Defaults to a string parser when omitted. */
7
24
  readonly valueSchema?: SchemaAdapter<unknown>;
25
+ /** Provider that resolves `bound` and `semantic` fields; required for those owners. */
8
26
  readonly providerId?: string;
27
+ /** Fixed value for `constant` fields; snapshotted at registration. */
9
28
  readonly constantValue?: unknown;
29
+ /** Allowlist for `semantic` fields; must be non-empty and unique. */
10
30
  readonly semanticKeys?: readonly string[];
11
31
  }
32
+ /** One output shape. */
12
33
  export interface OutputDefinition {
34
+ /** Output id; duplicate ids are rejected. */
13
35
  readonly id: string;
36
+ /** Shape family. `text` holds one required field; `group` holds program-assigned items. */
14
37
  readonly kind: 'text' | 'master' | 'record' | 'group';
38
+ /** Fields of `text`, `master` and `record` outputs; forbidden for groups. */
15
39
  readonly fields?: readonly OutputField[];
40
+ /** Master template for `master` outputs; its slots must match the field ids exactly. */
16
41
  readonly master?: string;
42
+ /** Output ids a group may contain; required and unique for groups. */
17
43
  readonly allowedOutputIds?: readonly string[];
44
+ /** Maximum group members; required for groups and at least 1. */
18
45
  readonly maxItems?: number;
19
46
  }
47
+ /** App-owned value provider for `bound` and `semantic` fields. */
20
48
  export interface OutputProvider<App> {
21
49
  readonly id: string;
50
+ /** Produces the value; `key` carries the selected semantic key, when there is one. */
22
51
  resolve(request: {
23
52
  readonly key?: string;
24
53
  }, context: OperationContext<App>): unknown;
25
54
  }
55
+ /** Output problem with a guaranteed field path. */
26
56
  export interface OutputIssue extends Issue {
27
57
  readonly path: readonly (string | number)[];
28
58
  }
59
+ /** Input for composing one output: model values plus program-assigned group members. */
29
60
  export interface OutputComposeInput {
61
+ /** Values already produced for this output's fields, keyed by field id. */
30
62
  readonly generated?: Readonly<Record<string, unknown>>;
63
+ /** Group members supplied by the program, in order. */
31
64
  readonly items?: readonly {
32
65
  readonly id: string;
33
66
  readonly outputId: string;
34
67
  readonly input: OutputComposeInput;
35
68
  }[];
36
69
  }
70
+ /** Composed output value. */
37
71
  export interface OutputResult {
38
72
  readonly outputId: string;
39
73
  readonly kind: OutputDefinition['kind'];
40
74
  readonly value: unknown;
41
75
  }
76
+ /** Catalog construction options. */
42
77
  export interface OutputCatalogOptions<App = unknown> {
78
+ /** Providers referenced by `bound` and `semantic` fields. */
43
79
  readonly providers?: readonly OutputProvider<App>[];
80
+ /** Observer invoked with every composed result. */
44
81
  readonly observe?: (result: OutputResult) => void | Promise<void>;
45
82
  }
@@ -1,11 +1,26 @@
1
+ /**
2
+ * Template contract for the Presentation Kit.
3
+ *
4
+ * Place in the package: an optional App-side text master and a semantic-key allowlist. The program
5
+ * owns the master; inserted model text is only a value substituted into it, never a new template.
6
+ *
7
+ * Exports: `TextTemplateOptions`, `SemanticSlotDefinition`.
8
+ */
9
+ /** Text template construction options. */
1
10
  export interface TextTemplateOptions {
11
+ /** Observer invoked with every rendered text. */
2
12
  readonly observe?: (result: string) => void | Promise<void>;
13
+ /** Builds the error for a slot the caller did not supply; receives the slot name. */
3
14
  readonly errors?: {
4
15
  readonly missingField?: (key: string) => Error | string;
5
16
  };
6
17
  }
18
+ /** Declares the `{{namespace:key}}` slots a model may use, and how often. */
7
19
  export interface SemanticSlotDefinition {
20
+ /** Slot namespace; must match `^[a-z][a-z0-9-]*$`. */
8
21
  readonly namespace: string;
22
+ /** Allowed keys after the namespace; any other key makes the text invalid. */
9
23
  readonly keys: readonly string[];
24
+ /** Maximum total occurrences across the text; must be a non-negative integer. */
10
25
  readonly maxOccurrences: number;
11
26
  }
@@ -1,15 +1,36 @@
1
+ /**
2
+ * Projection contract for the Projection Kit.
3
+ *
4
+ * Place in the package: an optional App-side helper that fits structured values into a character
5
+ * budget while keeping valid JSON. Callers choose the budget, rendering strategy and fallback text;
6
+ * the Kit only shrinks values and verifies the result fits.
7
+ *
8
+ * Exports: `ContentProjection`, `ContentProjectionOptions`, `TreeProjectionOptions`.
9
+ */
10
+ /** Projection output. */
1
11
  export interface ContentProjection {
12
+ /** Rendered text that fits the requested budget. */
2
13
  readonly text: string;
14
+ /** True when anything was shortened or replaced by the fallback. */
3
15
  readonly truncated: boolean;
4
16
  }
17
+ /** Candidate strategy for content projection. */
5
18
  export interface ContentProjectionOptions {
19
+ /** Maximum array items to keep, tried in order before moving to the next length. */
6
20
  readonly counts: readonly number[];
21
+ /** Maximum characters per string, tried in order inside each count candidate. */
7
22
  readonly lengths: readonly number[];
23
+ /** Renders a shortened value; must be synchronous. */
8
24
  readonly render: (excerpt: unknown) => string;
25
+ /** Builds fallback text for a limit, used when no candidate fits; must be synchronous. */
9
26
  readonly fallback: (limit: number) => string;
10
27
  }
28
+ /** Depth- and record-level traversal options for tree projection. */
11
29
  export interface TreeProjectionOptions<Context> {
30
+ /** Maximum included depth; deeper values are omitted. Must be a non-negative integer. */
12
31
  readonly maxDepth: number;
32
+ /** Drops a value when it returns true; must be synchronous boolean. */
13
33
  readonly omit?: (value: unknown, depth: number, context: Context) => boolean;
34
+ /** Observes every retained record, for example to record which fields were kept. */
14
35
  readonly visitRecord?: (value: Record<string, unknown>, depth: number, context: Context) => void;
15
36
  }
@@ -1,75 +1,134 @@
1
+ /**
2
+ * Reflection contract for the Reflection Kit.
3
+ *
4
+ * Place in the package: an optional App-side diagnostic agent that inspects recorded execution
5
+ * evidence and answers a question about it. It reads metadata through an App-provided source, never
6
+ * the original event payloads, and reports what the evidence supports rather than asserting facts
7
+ * Core cannot prove. Reports are request-local and never persisted here.
8
+ *
9
+ * Exports: `reflectionIdentityFields`, `ReflectionEvidence`, `ReflectionQuery`, `ReflectionPage`,
10
+ * `ReflectionSource`, `reflectionFindingKinds`, `ReflectionFinding`, `ReflectionReport`,
11
+ * `ReflectionDefinition`, `ReflectionTask`.
12
+ */
1
13
  import type { ModelRunner } from '../../model/runner.js';
2
14
  import type { OperationContext, MaybePromise } from '../common.js';
3
15
  import type { ToolDefinition } from '../support/tools.js';
4
16
  import type { DiagnosticIdentity } from '../diagnostics.js';
17
+ /** Identity fields an evidence item may project from the original diagnostic identity. */
5
18
  export declare const reflectionIdentityFields: readonly ["spanId", "parentSpanId", "invocationId", "parentInvocationId", "agentId", "branchId", "agentVersionId", "parentBranchId", "parentAgentVersionId", "forkPointId", "workflowInvocationId", "workflowNodeId", "nodeRole", "definitionId"];
6
19
  /** Explicit metadata projection, not an arbitrary original event/payload. */
7
- export interface ReflectionEvidence extends Partial<Pick<DiagnosticIdentity, typeof reflectionIdentityFields[number]>> {
20
+ export interface ReflectionEvidence extends Partial<Pick<DiagnosticIdentity, (typeof reflectionIdentityFields)[number]>> {
21
+ /** Evidence id cited by findings when they rely on this item. */
8
22
  readonly id: string;
23
+ /** Run the item belongs to; queries are scoped by run. */
9
24
  readonly runId: string;
25
+ /** Evidence type, matched against `ReflectionQuery.types`. */
10
26
  readonly type: string;
11
27
  readonly occurredAtMs?: number;
28
+ /** Ordering key inside the source; ascending. */
12
29
  readonly sequence?: number;
13
30
  readonly stageId?: string;
14
31
  readonly status?: string;
32
+ /** Error or protocol code recorded on the item. */
15
33
  readonly code?: string;
34
+ /** Model or tool calls represented by the item. */
16
35
  readonly calls?: number;
17
36
  readonly durationMs?: number;
18
37
  readonly inputChars?: number;
19
38
  readonly outputChars?: number;
39
+ /** Instant after which the item is no longer retained by the source. */
20
40
  readonly expiresAtMs?: number;
21
41
  }
42
+ /** One evidence query. */
22
43
  export interface ReflectionQuery {
44
+ /** Run to inspect; omitted means the App chooses the scope. */
23
45
  readonly run?: string;
46
+ /** Evidence types to include; omitted means all types. */
24
47
  readonly types?: readonly string[];
48
+ /** Opaque continuation cursor from a previous page. */
25
49
  readonly cursor?: string;
50
+ /** Maximum items requested; at least 1, clamped to the remaining evidence budget. */
26
51
  readonly limit: number;
27
52
  }
53
+ /** One page of evidence plus an honest statement of its coverage. */
28
54
  export interface ReflectionPage {
55
+ /** Items in source order. */
29
56
  readonly items: readonly ReflectionEvidence[];
57
+ /** Continuation cursor; absent when the source has no further items. */
30
58
  readonly cursor?: string;
31
59
  readonly coverage: {
60
+ /** `best-effort` may miss items; `snapshot` reflects one consistent point in time. */
32
61
  readonly consistency: 'best-effort' | 'snapshot';
62
+ /** `true` complete, `false` known incomplete, `null` unknown. */
33
63
  readonly complete: boolean | null;
64
+ /** Human-readable descriptions of known gaps. */
34
65
  readonly gaps: readonly string[];
35
66
  };
36
67
  }
68
+ /** App-owned evidence source, including its own authorization. */
37
69
  export interface ReflectionSource<App> {
38
70
  readonly id: string;
39
71
  readonly description: string;
72
+ /** Guards one query; runs before any evidence is read. */
40
73
  authorize(query: ReflectionQuery, context: OperationContext<App>): MaybePromise<void>;
74
+ /** Returns one page; an invalid page shape aborts the reflection. */
41
75
  query(query: ReflectionQuery, context: OperationContext<App>): Promise<ReflectionPage>;
42
76
  }
77
+ /** Allowed finding kinds, from observed facts to advisory conclusions. */
43
78
  export declare const reflectionFindingKinds: readonly ["observed", "hypothesis", "recommendation"];
79
+ /** One finding, always tied to the evidence it rests on. */
44
80
  export interface ReflectionFinding {
45
- readonly kind: typeof reflectionFindingKinds[number];
81
+ /** `observed` must cite evidence; `hypothesis` and `recommendation` are advisory. */
82
+ readonly kind: (typeof reflectionFindingKinds)[number];
83
+ /** What the reflection claims. */
46
84
  readonly claim: string;
85
+ /** Evidence ids supporting the claim. */
47
86
  readonly evidenceIds: readonly string[];
48
87
  }
88
+ /** Request-local reflection result. */
49
89
  export interface ReflectionReport {
50
90
  readonly id: string;
91
+ /** `incomplete` when evidence, model budget or the timeout stopped the work early. */
51
92
  readonly status: 'completed' | 'incomplete';
93
+ /** Question as submitted; at most 2000 characters. */
52
94
  readonly question: string;
53
95
  readonly findings: readonly ReflectionFinding[];
96
+ /** Known limitations, for example exhausted budgets or incomplete coverage. */
54
97
  readonly limitations: readonly string[];
98
+ /** Evidence items the reflection actually saw. */
55
99
  readonly evidence: readonly ReflectionEvidence[];
100
+ /** Coverage statement of each page that was read. */
56
101
  readonly coverage: readonly ReflectionPage['coverage'][];
57
102
  readonly createdAtMs: number;
58
103
  readonly expiresAtMs?: number;
104
+ /** Marker: a report is returned to the caller and never stored by the Kit. */
59
105
  readonly persisted: false;
60
106
  }
107
+ /** Configuration for compiling a reflection task. */
61
108
  export interface ReflectionDefinition<App> {
109
+ /** Parent runner; the reflection creates a child and preserves the parent's reserve. */
62
110
  readonly model: Pick<ModelRunner, 'createChild' | 'remainingCalls'>;
111
+ /** Evidence source queried through the reflection tools. */
63
112
  readonly source: ReflectionSource<App>;
113
+ /** Additional tools exposed to the reflection model. */
64
114
  readonly tools?: readonly ToolDefinition<any, any, App>[];
115
+ /** Model calls the child may use; defaults to 4. */
65
116
  readonly maxCalls?: number;
117
+ /** Parent calls kept untouched; defaults to 1. */
66
118
  readonly reserveCalls?: number;
119
+ /** Wall-clock limit for the whole reflection in milliseconds; defaults to 30000. */
67
120
  readonly timeoutMs?: number;
121
+ /** Maximum evidence pages read; defaults to 4. */
68
122
  readonly maxPages?: number;
123
+ /** Maximum evidence items collected; defaults to 64. */
69
124
  readonly maxEvents?: number;
125
+ /** Maximum evidence characters placed in the model context; defaults to 12000. */
70
126
  readonly maxEvidenceChars?: number;
127
+ /** Guards one reflection request; runs before any model call. */
71
128
  authorize(question: string, context: OperationContext<App>): MaybePromise<void>;
72
129
  }
130
+ /** Compiled reflection task. */
73
131
  export interface ReflectionTask<App> {
132
+ /** Answers the question from evidence; never throws for incomplete evidence alone. */
74
133
  run(question: string, context: OperationContext<App>): Promise<ReflectionReport>;
75
134
  }
@@ -1,4 +1,19 @@
1
- export const reflectionIdentityFields = Object.freeze(['spanId', 'parentSpanId', 'invocationId', 'parentInvocationId',
2
- 'agentId', 'branchId', 'agentVersionId', 'parentBranchId', 'parentAgentVersionId', 'forkPointId',
3
- 'workflowInvocationId', 'workflowNodeId', 'nodeRole', 'definitionId']);
1
+ /** Identity fields an evidence item may project from the original diagnostic identity. */
2
+ export const reflectionIdentityFields = Object.freeze([
3
+ 'spanId',
4
+ 'parentSpanId',
5
+ 'invocationId',
6
+ 'parentInvocationId',
7
+ 'agentId',
8
+ 'branchId',
9
+ 'agentVersionId',
10
+ 'parentBranchId',
11
+ 'parentAgentVersionId',
12
+ 'forkPointId',
13
+ 'workflowInvocationId',
14
+ 'workflowNodeId',
15
+ 'nodeRole',
16
+ 'definitionId',
17
+ ]);
18
+ /** Allowed finding kinds, from observed facts to advisory conclusions. */
4
19
  export const reflectionFindingKinds = ['observed', 'hypothesis', 'recommendation'];
@@ -1,3 +1,14 @@
1
+ /**
2
+ * Retrieval contract for the Retrieval Kit.
3
+ *
4
+ * Place in the package: an optional App-side library for one query round-trip. Data access,
5
+ * authorization, state and result semantics are host ports; the Kit owns the fixed order — state,
6
+ * preparation, assertions, duplicate/budget checks, authorization, adapter call, result validation,
7
+ * source naming and declared effects.
8
+ *
9
+ * Exports: `RetrievalSource`, `RetrievalResult`, `RetrievalState`, `RetrievalReceipt`,
10
+ * `RetrievalReason`, `RetrievalEffect`, `RetrievalPorts`, `RetrievalRunner`, `RetrievalDefinition`.
11
+ */
1
12
  /** Request-local citation reference; the App may separately carry its content entity id. */
2
13
  export interface RetrievalSource {
3
14
  sourceId: string;
@@ -7,34 +18,53 @@ export interface RetrievalResult<Source extends RetrievalSource> {
7
18
  }
8
19
  /** Request-owned state. Clearing current evidence must not replenish spent budgets or seen keys. */
9
20
  export interface RetrievalState<Source extends RetrievalSource> {
21
+ /** Successful queries so far; compared against the current limit. */
10
22
  queryCount: number;
23
+ /** Query keys already attempted, including rejected ones, so retries count as duplicates. */
11
24
  readonly seen: Set<string>;
25
+ /** Sources from successful queries, in acceptance order. */
12
26
  readonly sources: Source[];
13
27
  }
28
+ /** Facts of one accepted query. */
14
29
  export interface RetrievalReceipt<Query, Source extends RetrievalSource, Result extends RetrievalResult<Source>> {
30
+ /** Query after `prepare`, exactly as executed. */
15
31
  readonly query: Query;
32
+ /** Deduplication key reserved before the adapter call. */
16
33
  readonly key: string;
34
+ /** One-based position of this query within the request. */
17
35
  readonly sequence: number;
36
+ /** Adapter start instant in epoch milliseconds. */
18
37
  readonly startedAtMs: number;
38
+ /** Adapter output before source naming; rejected results never produce a receipt. */
19
39
  readonly rawResult: Result;
40
+ /** Same result with every `sourceId` replaced by the Kit-assigned name. */
20
41
  readonly result: Result;
21
42
  /** Domain attachments are computed from real results, not model-supplied receipts. */
22
43
  readonly extensions: Record<string, unknown>;
23
44
  }
45
+ /** Lazy rejection wording: a fixed message, a pre-built error, or a factory bound to the query. */
24
46
  export type RetrievalReason<Query, Context> = Error | string | ((query: Query, context: Context) => Error | string);
47
+ /** One effect applied after a successful query, in declaration order. */
25
48
  export interface RetrievalEffect<Query, Source extends RetrievalSource, Result extends RetrievalResult<Source>, Context> {
26
49
  readonly id: string;
27
50
  readonly description: string;
51
+ /** Applies the effect synchronously; a throw stops later effects without rollback. */
28
52
  handle(receipt: RetrievalReceipt<Query, Source, Result>, context: Context): void;
29
53
  }
54
+ /** Host ports and policy for one retrieval kind. */
30
55
  export interface RetrievalPorts<Query, Source extends RetrievalSource, Result extends RetrievalResult<Source>, Context> {
31
56
  readonly id: string;
32
57
  readonly description: string;
33
58
  readonly tags?: readonly string[];
59
+ /** Normalizes the query before assertions run; must be synchronous. */
34
60
  readonly prepare?: (query: Query, context: Context) => Query;
61
+ /** Rejects a malformed query; must be synchronous and return void. */
35
62
  readonly assertInput: (query: Query, context: Context) => void;
63
+ /** Returns the request-owned state that holds counters and sources. */
36
64
  readonly state: (context: Context) => RetrievalState<Source>;
65
+ /** Maximum accepted queries for the current state. */
37
66
  readonly limit: (context: Context) => number;
67
+ /** Deduplication key; defaults to a canonical serialization of the query. */
38
68
  readonly key?: (query: Query) => string;
39
69
  readonly errors?: {
40
70
  readonly duplicate?: RetrievalReason<Query, Context>;
@@ -42,16 +72,24 @@ export interface RetrievalPorts<Query, Source extends RetrievalSource, Result ex
42
72
  };
43
73
  /** Resource authorization runs after duplicate/budget checks and before reserving a key. */
44
74
  readonly authorize?: (query: Query, context: Context) => void;
75
+ /** Performs the actual read; must be synchronous. Throwing does not refund the query key. */
45
76
  readonly execute: (query: Query, context: Context) => Result;
77
+ /** Validates the adapter result; a throw leaves the query counted as seen but not successful. */
46
78
  readonly assertResult?: (result: Result, query: Query, context: Context) => void;
79
+ /** Names a source; the assigned value replaces `sourceId` in the receipt result. */
47
80
  readonly sourceId?: (source: Source, query: Query, sequence: number, context: Context) => string;
48
81
  readonly effects?: readonly RetrievalEffect<Query, Source, Result, Context>[];
82
+ /** Clock override for receipt timestamps; defaults to `Date.now`. */
49
83
  readonly now?: () => number;
50
84
  }
85
+ /** Compiled retrieval runner. */
51
86
  export interface RetrievalRunner<Query, Source extends RetrievalSource, Result extends RetrievalResult<Source>, Context> {
52
87
  readonly id: string;
53
88
  readonly description: string;
89
+ /** Effects that run after every accepted query. */
54
90
  readonly effects: readonly RetrievalEffect<Query, Source, Result, Context>[];
91
+ /** Executes one query in the fixed lifecycle order and returns its receipt. */
55
92
  run(input: Query, context: Context): RetrievalReceipt<Query, Source, Result>;
56
93
  }
94
+ /** Retrieval ports specialized to an App operation context. */
57
95
  export type RetrievalDefinition<Query, Source extends RetrievalSource, Result extends RetrievalResult<Source>, App> = RetrievalPorts<Query, Source, Result, import('../common.js').OperationContext<App>>;
@@ -1,32 +1,54 @@
1
+ /**
2
+ * Text search contract for the Text Search Kit.
3
+ *
4
+ * Place in the package: an optional App-side full-text index. The Kit owns the index, declarative
5
+ * field validation and snapshot compatibility; the corpus, tokenization policy, storage, identity,
6
+ * filters and persistence stay with the App.
7
+ *
8
+ * Exports: `TextSearchOptions`, `TextSearchHit`, `TextSearchQuery`, `TextSearchSnapshot`.
9
+ */
1
10
  import type { SearchHit } from '../common.js';
2
11
  /** App supplies fields, tokenizer and its own schema/tokenizer revision. */
3
12
  export interface TextSearchOptions<Document extends {
4
13
  id: string;
5
14
  }> {
15
+ /** App-owned revision of the field/tokenizer configuration; a change invalidates snapshots. */
6
16
  readonly indexRevision: string;
17
+ /** Fields that are indexed and searchable. */
7
18
  readonly fields: readonly (keyof Document & string)[];
19
+ /** Fields returned in a hit; the indexed body is not implicitly returned. */
8
20
  readonly storedFields: readonly (keyof Document & string)[];
21
+ /** Tokenizer override; defaults to MiniSearch's default tokenizer. */
9
22
  readonly tokenize?: (text: string, fieldName?: string) => string[];
23
+ /** Per-field relevance multiplier; omitted fields keep the default weight. */
10
24
  readonly boost?: Readonly<Partial<Record<keyof Document & string, number>>>;
25
+ /** How multiple query terms combine; defaults to the engine default (OR). */
11
26
  readonly combineWith?: 'AND' | 'OR';
12
27
  }
13
28
  export interface TextSearchHit<Document extends {
14
29
  id: string;
15
30
  }> extends SearchHit<Partial<Document>> {
31
+ /** Matched terms, as reported by the engine after tokenization. */
16
32
  readonly terms: readonly string[];
17
33
  }
18
34
  export interface TextSearchQuery<Document extends {
19
35
  id: string;
20
36
  }> {
37
+ /** Maximum number of hits returned. */
21
38
  readonly limit: number;
22
39
  /** Required on every query; the application owns authorization and applicability. */
23
40
  readonly filter: (document: Readonly<Partial<Document>> & {
24
41
  id: string;
25
42
  }) => boolean;
26
43
  }
44
+ /** Serialized index; the revision pair proves the snapshot matches the current configuration. */
27
45
  export interface TextSearchSnapshot {
46
+ /** Snapshot format version; other versions are not loaded. */
28
47
  readonly version: 2;
48
+ /** Engine that produced the snapshot; a different engine cannot restore it. */
29
49
  readonly engine: 'minisearch-7';
50
+ /** Fingerprint of the field and tokenizer configuration that built the index. */
30
51
  readonly configurationFingerprint: string;
52
+ /** Serialized MiniSearch index. */
31
53
  readonly serializedIndex: string;
32
54
  }
@@ -1,25 +1,50 @@
1
+ /**
2
+ * Text skill contract for the Text Skills Kit.
3
+ *
4
+ * Place in the package: an optional App-side loader for text-only skill documents. A skill is
5
+ * metadata plus instructions read from a document; nothing here executes code, imports modules or
6
+ * calls tools. Ids, entry paths and header fields are validated against the declared limits.
7
+ *
8
+ * Exports: `TextSkillRegistration`, `TextSkill`, `TextSkillHeader`, `TextSkillLoaderDefinition`,
9
+ * `TextSkillReadPorts`, `TextSkillLoader`.
10
+ */
1
11
  import type { BreakReason } from '../utils/rules.js';
12
+ /** Catalog entry of one text skill, before its document is read. */
2
13
  export interface TextSkillRegistration {
14
+ /** Skill id, lowercase kebab case, bounded by `maxIdChars` (64 by default). */
3
15
  readonly id: string;
16
+ /** Document path; must equal the loader's `entryFor(id)` result. */
4
17
  readonly entry: string;
18
+ /** Only text workflow skills are supported. */
5
19
  readonly kind: 'text-workflow';
20
+ /** Tool ids the instructions may reference; validated by the caller, not executed here. */
6
21
  readonly toolIds: readonly string[];
7
22
  }
23
+ /** Loaded skill: registration plus the parsed document text. */
8
24
  export interface TextSkill extends TextSkillRegistration {
25
+ /** Description taken from the document header and matching the registration. */
9
26
  readonly description: string;
27
+ /** Instruction body without the header, bounded by `maxInstructionChars`. */
10
28
  readonly instructions: string;
11
29
  }
30
+ /** Header every skill document must carry. */
12
31
  export interface TextSkillHeader {
13
32
  readonly id: string;
14
33
  readonly description: string;
15
34
  }
35
+ /** Loader limits, parsing hooks and rejection wording. */
16
36
  export interface TextSkillLoaderDefinition {
37
+ /** Maximum characters of the instruction body; larger documents are rejected. */
17
38
  readonly maxInstructionChars: number;
39
+ /** Maximum characters of the description header. */
18
40
  readonly maxDescriptionChars: number;
41
+ /** Maximum id length; defaults to 64. */
19
42
  readonly maxIdChars?: number;
43
+ /** Maps an id to its expected document path; defaults to `<id>/SKILL.md`. */
20
44
  readonly entryFor?: (id: string) => string;
21
45
  /** Default parser accepts the strict name/description header; hosts can inject a YAML parser. */
22
46
  readonly parseHeader?: (instructions: string) => TextSkillHeader | undefined;
47
+ /** Diagnostic tags attached to loader rejections. */
23
48
  readonly tags?: readonly string[];
24
49
  readonly errors?: {
25
50
  readonly catalog?: BreakReason;
@@ -27,10 +52,21 @@ export interface TextSkillLoaderDefinition {
27
52
  readonly document?: BreakReason;
28
53
  };
29
54
  }
55
+ /** Host port that reads one skill document by path. */
30
56
  export interface TextSkillReadPorts {
57
+ /** Returns the document text; throwing aborts the load. */
31
58
  read(entry: string): string;
32
59
  }
60
+ /** Compiled loader. */
33
61
  export interface TextSkillLoader {
62
+ /**
63
+ * Reads and validates every registered skill.
64
+ *
65
+ * @param request - `entries` is the untrusted catalog array; shape is validated here.
66
+ * @param ports - Document reader supplied by the host.
67
+ * @returns Frozen skills in catalog order.
68
+ * @throws When the catalog, a registration, an entry path or a document is invalid.
69
+ */
34
70
  load(request: {
35
71
  readonly entries: unknown;
36
72
  }, ports: TextSkillReadPorts): readonly TextSkill[];