@getcliqio/cliq-sdk 0.0.0-stage → 1.15.33

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 (338) hide show
  1. package/README.md +28 -2
  2. package/dist/agent_api.d.ts +39 -0
  3. package/dist/agent_api.d.ts.map +1 -0
  4. package/dist/agent_api.js +105 -0
  5. package/dist/agent_api.js.map +1 -0
  6. package/dist/agent_manifest.d.ts +162 -0
  7. package/dist/agent_manifest.d.ts.map +1 -0
  8. package/dist/agent_manifest.js +242 -0
  9. package/dist/agent_manifest.js.map +1 -0
  10. package/dist/agent_payloads.d.ts +103 -0
  11. package/dist/agent_payloads.d.ts.map +1 -0
  12. package/dist/agent_payloads.js +56 -0
  13. package/dist/agent_payloads.js.map +1 -0
  14. package/dist/agents/base_agent.d.ts +113 -0
  15. package/dist/agents/base_agent.d.ts.map +1 -0
  16. package/dist/agents/base_agent.js +413 -0
  17. package/dist/agents/base_agent.js.map +1 -0
  18. package/dist/agents/cli_agent.d.ts +98 -0
  19. package/dist/agents/cli_agent.d.ts.map +1 -0
  20. package/dist/agents/cli_agent.js +303 -0
  21. package/dist/agents/cli_agent.js.map +1 -0
  22. package/dist/agents/cli_rehydrate.d.ts +29 -0
  23. package/dist/agents/cli_rehydrate.d.ts.map +1 -0
  24. package/dist/agents/cli_rehydrate.js +32 -0
  25. package/dist/agents/cli_rehydrate.js.map +1 -0
  26. package/dist/agents/connector_agent.d.ts +20 -0
  27. package/dist/agents/connector_agent.d.ts.map +1 -0
  28. package/dist/agents/connector_agent.js +110 -0
  29. package/dist/agents/connector_agent.js.map +1 -0
  30. package/dist/agents/event_artifacts.d.ts +33 -0
  31. package/dist/agents/event_artifacts.d.ts.map +1 -0
  32. package/dist/agents/event_artifacts.js +73 -0
  33. package/dist/agents/event_artifacts.js.map +1 -0
  34. package/dist/agents/gate_agent.d.ts +40 -0
  35. package/dist/agents/gate_agent.d.ts.map +1 -0
  36. package/dist/agents/gate_agent.js +121 -0
  37. package/dist/agents/gate_agent.js.map +1 -0
  38. package/dist/agents/index.d.ts +32 -0
  39. package/dist/agents/index.d.ts.map +1 -0
  40. package/dist/agents/index.js +26 -0
  41. package/dist/agents/index.js.map +1 -0
  42. package/dist/agents/llm_agent.d.ts +109 -0
  43. package/dist/agents/llm_agent.d.ts.map +1 -0
  44. package/dist/agents/llm_agent.js +285 -0
  45. package/dist/agents/llm_agent.js.map +1 -0
  46. package/dist/agents/llm_contract.d.ts +7 -0
  47. package/dist/agents/llm_contract.d.ts.map +1 -0
  48. package/dist/agents/llm_contract.js +7 -0
  49. package/dist/agents/llm_contract.js.map +1 -0
  50. package/dist/agents/standard_agent.d.ts +15 -0
  51. package/dist/agents/standard_agent.d.ts.map +1 -0
  52. package/dist/agents/standard_agent.js +34 -0
  53. package/dist/agents/standard_agent.js.map +1 -0
  54. package/dist/agents/turn_result.d.ts +67 -0
  55. package/dist/agents/turn_result.d.ts.map +1 -0
  56. package/dist/agents/turn_result.js +81 -0
  57. package/dist/agents/turn_result.js.map +1 -0
  58. package/dist/agents/types.d.ts +314 -0
  59. package/dist/agents/types.d.ts.map +1 -0
  60. package/dist/agents/types.js +20 -0
  61. package/dist/agents/types.js.map +1 -0
  62. package/dist/builtin_teams/hello_hug.d.ts +9 -0
  63. package/dist/builtin_teams/hello_hug.d.ts.map +1 -0
  64. package/dist/builtin_teams/hello_hug.js +68 -0
  65. package/dist/builtin_teams/hello_hug.js.map +1 -0
  66. package/dist/builtin_teams/hello_world.d.ts +8 -0
  67. package/dist/builtin_teams/hello_world.d.ts.map +1 -0
  68. package/dist/builtin_teams/hello_world.js +65 -0
  69. package/dist/builtin_teams/hello_world.js.map +1 -0
  70. package/dist/builtin_teams/hug_example.d.ts +10 -0
  71. package/dist/builtin_teams/hug_example.d.ts.map +1 -0
  72. package/dist/builtin_teams/hug_example.js +94 -0
  73. package/dist/builtin_teams/hug_example.js.map +1 -0
  74. package/dist/builtin_teams/index.d.ts +12 -0
  75. package/dist/builtin_teams/index.d.ts.map +1 -0
  76. package/dist/builtin_teams/index.js +18 -0
  77. package/dist/builtin_teams/index.js.map +1 -0
  78. package/dist/builtin_teams/types.d.ts +29 -0
  79. package/dist/builtin_teams/types.d.ts.map +1 -0
  80. package/dist/builtin_teams/types.js +3 -0
  81. package/dist/builtin_teams/types.js.map +1 -0
  82. package/dist/core_api_client.d.ts +48 -0
  83. package/dist/core_api_client.d.ts.map +1 -0
  84. package/dist/core_api_client.js +132 -0
  85. package/dist/core_api_client.js.map +1 -0
  86. package/dist/daemon_wire.d.ts +122 -0
  87. package/dist/daemon_wire.d.ts.map +1 -0
  88. package/dist/daemon_wire.js +105 -0
  89. package/dist/daemon_wire.js.map +1 -0
  90. package/dist/events/catalog.d.ts +40 -0
  91. package/dist/events/catalog.d.ts.map +1 -0
  92. package/dist/events/catalog.js +76 -0
  93. package/dist/events/catalog.js.map +1 -0
  94. package/dist/http_daemon_client.d.ts +136 -0
  95. package/dist/http_daemon_client.d.ts.map +1 -0
  96. package/dist/http_daemon_client.js +192 -0
  97. package/dist/http_daemon_client.js.map +1 -0
  98. package/dist/hug/ask.d.ts +160 -0
  99. package/dist/hug/ask.d.ts.map +1 -0
  100. package/dist/hug/ask.js +318 -0
  101. package/dist/hug/ask.js.map +1 -0
  102. package/dist/hug/attach.d.ts +60 -0
  103. package/dist/hug/attach.d.ts.map +1 -0
  104. package/dist/hug/attach.js +103 -0
  105. package/dist/hug/attach.js.map +1 -0
  106. package/dist/hug/bridge/index.d.ts +16 -0
  107. package/dist/hug/bridge/index.d.ts.map +1 -0
  108. package/dist/hug/bridge/index.js +13 -0
  109. package/dist/hug/bridge/index.js.map +1 -0
  110. package/dist/hug/bridge/messages.d.ts +559 -0
  111. package/dist/hug/bridge/messages.d.ts.map +1 -0
  112. package/dist/hug/bridge/messages.js +165 -0
  113. package/dist/hug/bridge/messages.js.map +1 -0
  114. package/dist/hug/client.d.ts +70 -0
  115. package/dist/hug/client.d.ts.map +1 -0
  116. package/dist/hug/client.js +144 -0
  117. package/dist/hug/client.js.map +1 -0
  118. package/dist/hug/context.d.ts +54 -0
  119. package/dist/hug/context.d.ts.map +1 -0
  120. package/dist/hug/context.js +27 -0
  121. package/dist/hug/context.js.map +1 -0
  122. package/dist/hug/define.d.ts +116 -0
  123. package/dist/hug/define.d.ts.map +1 -0
  124. package/dist/hug/define.js +119 -0
  125. package/dist/hug/define.js.map +1 -0
  126. package/dist/hug/definitions/approval.d.ts +216 -0
  127. package/dist/hug/definitions/approval.d.ts.map +1 -0
  128. package/dist/hug/definitions/approval.js +50 -0
  129. package/dist/hug/definitions/approval.js.map +1 -0
  130. package/dist/hug/definitions/common.d.ts +122 -0
  131. package/dist/hug/definitions/common.d.ts.map +1 -0
  132. package/dist/hug/definitions/common.js +70 -0
  133. package/dist/hug/definitions/common.js.map +1 -0
  134. package/dist/hug/definitions/form.d.ts +197 -0
  135. package/dist/hug/definitions/form.d.ts.map +1 -0
  136. package/dist/hug/definitions/form.js +29 -0
  137. package/dist/hug/definitions/form.js.map +1 -0
  138. package/dist/hug/definitions/index.d.ts +10 -0
  139. package/dist/hug/definitions/index.d.ts.map +1 -0
  140. package/dist/hug/definitions/index.js +8 -0
  141. package/dist/hug/definitions/index.js.map +1 -0
  142. package/dist/hug/errors.d.ts +30 -0
  143. package/dist/hug/errors.d.ts.map +1 -0
  144. package/dist/hug/errors.js +46 -0
  145. package/dist/hug/errors.js.map +1 -0
  146. package/dist/hug/file_checks.d.ts +41 -0
  147. package/dist/hug/file_checks.d.ts.map +1 -0
  148. package/dist/hug/file_checks.js +105 -0
  149. package/dist/hug/file_checks.js.map +1 -0
  150. package/dist/hug/files.d.ts +137 -0
  151. package/dist/hug/files.d.ts.map +1 -0
  152. package/dist/hug/files.js +283 -0
  153. package/dist/hug/files.js.map +1 -0
  154. package/dist/hug/hug_bundle.d.ts +70 -0
  155. package/dist/hug/hug_bundle.d.ts.map +1 -0
  156. package/dist/hug/hug_bundle.js +299 -0
  157. package/dist/hug/hug_bundle.js.map +1 -0
  158. package/dist/hug/hug_catalog.d.ts +38 -0
  159. package/dist/hug/hug_catalog.d.ts.map +1 -0
  160. package/dist/hug/hug_catalog.js +67 -0
  161. package/dist/hug/hug_catalog.js.map +1 -0
  162. package/dist/hug/hug_definitions.d.ts +32 -0
  163. package/dist/hug/hug_definitions.d.ts.map +1 -0
  164. package/dist/hug/hug_definitions.js +74 -0
  165. package/dist/hug/hug_definitions.js.map +1 -0
  166. package/dist/hug/index.d.ts +37 -0
  167. package/dist/hug/index.d.ts.map +1 -0
  168. package/dist/hug/index.js +23 -0
  169. package/dist/hug/index.js.map +1 -0
  170. package/dist/hug/llm.d.ts +106 -0
  171. package/dist/hug/llm.d.ts.map +1 -0
  172. package/dist/hug/llm.js +250 -0
  173. package/dist/hug/llm.js.map +1 -0
  174. package/dist/hug/policies.d.ts +65 -0
  175. package/dist/hug/policies.d.ts.map +1 -0
  176. package/dist/hug/policies.js +80 -0
  177. package/dist/hug/policies.js.map +1 -0
  178. package/dist/hug/problems.d.ts +35 -0
  179. package/dist/hug/problems.d.ts.map +1 -0
  180. package/dist/hug/problems.js +53 -0
  181. package/dist/hug/problems.js.map +1 -0
  182. package/dist/hug/requested_inputs.d.ts +190 -0
  183. package/dist/hug/requested_inputs.d.ts.map +1 -0
  184. package/dist/hug/requested_inputs.js +220 -0
  185. package/dist/hug/requested_inputs.js.map +1 -0
  186. package/dist/hug/schema_for_inputs.d.ts +20 -0
  187. package/dist/hug/schema_for_inputs.d.ts.map +1 -0
  188. package/dist/hug/schema_for_inputs.js +95 -0
  189. package/dist/hug/schema_for_inputs.js.map +1 -0
  190. package/dist/hug/session.d.ts +113 -0
  191. package/dist/hug/session.d.ts.map +1 -0
  192. package/dist/hug/session.js +210 -0
  193. package/dist/hug/session.js.map +1 -0
  194. package/dist/hug/types.d.ts +141 -0
  195. package/dist/hug/types.d.ts.map +1 -0
  196. package/dist/hug/types.js +80 -0
  197. package/dist/hug/types.js.map +1 -0
  198. package/dist/index.d.ts +72 -0
  199. package/dist/index.d.ts.map +1 -0
  200. package/dist/index.js +54 -0
  201. package/dist/index.js.map +1 -0
  202. package/dist/logging.d.ts +172 -0
  203. package/dist/logging.d.ts.map +1 -0
  204. package/dist/logging.js +306 -0
  205. package/dist/logging.js.map +1 -0
  206. package/dist/mcp.d.ts +119 -0
  207. package/dist/mcp.d.ts.map +1 -0
  208. package/dist/mcp.js +259 -0
  209. package/dist/mcp.js.map +1 -0
  210. package/dist/mcp_client.d.ts +145 -0
  211. package/dist/mcp_client.d.ts.map +1 -0
  212. package/dist/mcp_client.js +374 -0
  213. package/dist/mcp_client.js.map +1 -0
  214. package/dist/paths.d.ts +20 -0
  215. package/dist/paths.d.ts.map +1 -0
  216. package/dist/paths.js +20 -0
  217. package/dist/paths.js.map +1 -0
  218. package/dist/protocol/factory.d.ts +32 -0
  219. package/dist/protocol/factory.d.ts.map +1 -0
  220. package/dist/protocol/factory.js +31 -0
  221. package/dist/protocol/factory.js.map +1 -0
  222. package/dist/protocol/framing.d.ts +35 -0
  223. package/dist/protocol/framing.d.ts.map +1 -0
  224. package/dist/protocol/framing.js +73 -0
  225. package/dist/protocol/framing.js.map +1 -0
  226. package/dist/protocol/index.d.ts +13 -0
  227. package/dist/protocol/index.d.ts.map +1 -0
  228. package/dist/protocol/index.js +13 -0
  229. package/dist/protocol/index.js.map +1 -0
  230. package/dist/protocol/types/agent.d.ts +42 -0
  231. package/dist/protocol/types/agent.d.ts.map +1 -0
  232. package/dist/protocol/types/agent.js +9 -0
  233. package/dist/protocol/types/agent.js.map +1 -0
  234. package/dist/protocol/types/cliq_core.d.ts +79 -0
  235. package/dist/protocol/types/cliq_core.d.ts.map +1 -0
  236. package/dist/protocol/types/cliq_core.js +17 -0
  237. package/dist/protocol/types/cliq_core.js.map +1 -0
  238. package/dist/protocol/types/foundations.d.ts +41 -0
  239. package/dist/protocol/types/foundations.d.ts.map +1 -0
  240. package/dist/protocol/types/foundations.js +10 -0
  241. package/dist/protocol/types/foundations.js.map +1 -0
  242. package/dist/protocol/types/index.d.ts +32 -0
  243. package/dist/protocol/types/index.d.ts.map +1 -0
  244. package/dist/protocol/types/index.js +27 -0
  245. package/dist/protocol/types/index.js.map +1 -0
  246. package/dist/protocol/types/messages.d.ts +827 -0
  247. package/dist/protocol/types/messages.d.ts.map +1 -0
  248. package/dist/protocol/types/messages.js +117 -0
  249. package/dist/protocol/types/messages.js.map +1 -0
  250. package/dist/protocol/types/pipeline.d.ts +122 -0
  251. package/dist/protocol/types/pipeline.d.ts.map +1 -0
  252. package/dist/protocol/types/pipeline.js +16 -0
  253. package/dist/protocol/types/pipeline.js.map +1 -0
  254. package/dist/protocol/types/schemas.d.ts +814 -0
  255. package/dist/protocol/types/schemas.d.ts.map +1 -0
  256. package/dist/protocol/types/schemas.js +772 -0
  257. package/dist/protocol/types/schemas.js.map +1 -0
  258. package/dist/protocol/types/team.d.ts +42 -0
  259. package/dist/protocol/types/team.d.ts.map +1 -0
  260. package/dist/protocol/types/team.js +15 -0
  261. package/dist/protocol/types/team.js.map +1 -0
  262. package/dist/protocol/types/workspace.d.ts +46 -0
  263. package/dist/protocol/types/workspace.d.ts.map +1 -0
  264. package/dist/protocol/types/workspace.js +9 -0
  265. package/dist/protocol/types/workspace.js.map +1 -0
  266. package/dist/settings_keys.d.ts +12 -0
  267. package/dist/settings_keys.d.ts.map +1 -0
  268. package/dist/settings_keys.js +35 -0
  269. package/dist/settings_keys.js.map +1 -0
  270. package/dist/tcp/client.d.ts +15 -0
  271. package/dist/tcp/client.d.ts.map +1 -0
  272. package/dist/tcp/client.js +28 -0
  273. package/dist/tcp/client.js.map +1 -0
  274. package/dist/tcp/connection.d.ts +79 -0
  275. package/dist/tcp/connection.d.ts.map +1 -0
  276. package/dist/tcp/connection.js +153 -0
  277. package/dist/tcp/connection.js.map +1 -0
  278. package/dist/tcp/index.d.ts +10 -0
  279. package/dist/tcp/index.d.ts.map +1 -0
  280. package/dist/tcp/index.js +7 -0
  281. package/dist/tcp/index.js.map +1 -0
  282. package/dist/tcp/server.d.ts +31 -0
  283. package/dist/tcp/server.d.ts.map +1 -0
  284. package/dist/tcp/server.js +54 -0
  285. package/dist/tcp/server.js.map +1 -0
  286. package/dist/team/bundle.d.ts +88 -0
  287. package/dist/team/bundle.d.ts.map +1 -0
  288. package/dist/team/bundle.js +214 -0
  289. package/dist/team/bundle.js.map +1 -0
  290. package/dist/team/identity.d.ts +31 -0
  291. package/dist/team/identity.d.ts.map +1 -0
  292. package/dist/team/identity.js +83 -0
  293. package/dist/team/identity.js.map +1 -0
  294. package/dist/team/index.d.ts +13 -0
  295. package/dist/team/index.d.ts.map +1 -0
  296. package/dist/team/index.js +8 -0
  297. package/dist/team/index.js.map +1 -0
  298. package/dist/team/lint_bundle.d.ts +16 -0
  299. package/dist/team/lint_bundle.d.ts.map +1 -0
  300. package/dist/team/lint_bundle.js +35 -0
  301. package/dist/team/lint_bundle.js.map +1 -0
  302. package/dist/team/ref.d.ts +48 -0
  303. package/dist/team/ref.d.ts.map +1 -0
  304. package/dist/team/ref.js +70 -0
  305. package/dist/team/ref.js.map +1 -0
  306. package/dist/team/roles.d.ts +22 -0
  307. package/dist/team/roles.d.ts.map +1 -0
  308. package/dist/team/roles.js +33 -0
  309. package/dist/team/roles.js.map +1 -0
  310. package/dist/team/tree.d.ts +101 -0
  311. package/dist/team/tree.d.ts.map +1 -0
  312. package/dist/team/tree.js +125 -0
  313. package/dist/team/tree.js.map +1 -0
  314. package/dist/team_lint.d.ts +57 -0
  315. package/dist/team_lint.d.ts.map +1 -0
  316. package/dist/team_lint.js +277 -0
  317. package/dist/team_lint.js.map +1 -0
  318. package/dist/telemetry/stream_json_usage.d.ts +39 -0
  319. package/dist/telemetry/stream_json_usage.d.ts.map +1 -0
  320. package/dist/telemetry/stream_json_usage.js +139 -0
  321. package/dist/telemetry/stream_json_usage.js.map +1 -0
  322. package/dist/telemetry/usage.d.ts +288 -0
  323. package/dist/telemetry/usage.d.ts.map +1 -0
  324. package/dist/telemetry/usage.js +421 -0
  325. package/dist/telemetry/usage.js.map +1 -0
  326. package/dist/utils/duration.d.ts +11 -0
  327. package/dist/utils/duration.d.ts.map +1 -0
  328. package/dist/utils/duration.js +22 -0
  329. package/dist/utils/duration.js.map +1 -0
  330. package/dist/utils/redact.d.ts +26 -0
  331. package/dist/utils/redact.d.ts.map +1 -0
  332. package/dist/utils/redact.js +52 -0
  333. package/dist/utils/redact.js.map +1 -0
  334. package/dist/utils/url.d.ts +6 -0
  335. package/dist/utils/url.d.ts.map +1 -0
  336. package/dist/utils/url.js +11 -0
  337. package/dist/utils/url.js.map +1 -0
  338. package/package.json +72 -5
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/hug/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EACH,mBAAmB,EACnB,oBAAoB,EACpB,eAAe,EACf,oBAAoB,EACpB,qBAAqB,EACrB,yBAAyB,EACzB,eAAe,GAClB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,YAAY,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAC/H,OAAO,EACH,gBAAgB,EAChB,kBAAkB,EAClB,mBAAmB,EACnB,cAAc,EACd,kBAAkB,EAClB,aAAa,EACb,eAAe,EACf,iBAAiB,EACjB,cAAc,EACd,sBAAsB,EACtB,gBAAgB,EAChB,eAAe,EACf,eAAe,EACf,eAAe,EACf,wBAAwB,GAC3B,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,iBAAiB,EAAE,QAAQ,EAAE,eAAe,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC9G,OAAO,EAAE,SAAS,EAAE,qBAAqB,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAElF,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C,OAAO,EAAE,GAAG,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AC9I,MAAM,YAAY,CAAC"}
@@ -0,0 +1,106 @@
1
+ /**
2
+ * How a model asks people (PLAN-hug-requests §10.5, PLAN-hug-widgets §9.4): the `cliq_hug` fence that ends a turn,
3
+ * and a closing `QUESTION:` line. A generic agent (LLM or CLI) asks with **its phase's hug** (`hug.name`, else `form`):
4
+ *
5
+ * - `form` — the fence holds `{ title?, prompt, requested_inputs }`, as before.
6
+ * - any other hug — the turn instruction describes it from its definition (title, description, the params as JSON
7
+ * Schema) and the fence holds `{ title, params }`; the params are checked against the definition, and a problem
8
+ * goes back to the model to fix (the same resend loop as a bad form block).
9
+ *
10
+ * A `QUESTION:` line is always a one-answer `form`. None of them choose channels, expiry or reminders: those always
11
+ * come from the phase (`hug:`), so text injected into the model's context can't steer a question to other people or
12
+ * change how long they have.
13
+ */
14
+ import type { HugDefinition } from './define.js';
15
+ import { HugDefinitions } from './hug_definitions.js';
16
+ import { type RequestedInput } from './requested_inputs.js';
17
+ import type { ContextBlock, HugResponse } from './types.js';
18
+ /** Fence language tag of a turn-ending ask in model text. */
19
+ export declare const CLIQ_HUG_FENCE = "cliq_hug";
20
+ /** A `form` ask: the Hug's content without where it goes or how long it lasts. */
21
+ export interface FormAsk {
22
+ readonly title: string;
23
+ readonly prompt: string;
24
+ readonly requested_inputs: RequestedInput[];
25
+ readonly context?: ContextBlock[];
26
+ /** From a closing `QUESTION:` line (a one-answer form, in any phase). */
27
+ readonly question?: true;
28
+ }
29
+ /** An ask with the phase's own hug: a title and the hug's params (checked against its definition before sending). */
30
+ export interface HugParamsAsk {
31
+ readonly title: string;
32
+ readonly params: Record<string, unknown>;
33
+ }
34
+ /** What a model may ask. */
35
+ export type LlmAsk = FormAsk | HugParamsAsk;
36
+ /** The hug a generic agent's phase asks with, when it isn't `form` (null means `form`). */
37
+ export interface PhaseHug {
38
+ readonly name: string;
39
+ readonly definition: HugDefinition<unknown, unknown>;
40
+ }
41
+ /**
42
+ * The phase's hug (`CLIQ_HUG_NAME`), loaded from its bundle; null for `form` (the default).
43
+ *
44
+ * @throws HugRefusedError (`hug_unknown`) when this phase can't see it
45
+ */
46
+ export declare function load_phase_hug(definitions?: HugDefinitions, name?: string): Promise<PhaseHug | null>;
47
+ /**
48
+ * Text appended to every LLM / CLI turn in a `form` phase: the only ways the model may end a turn besides finishing
49
+ * the work. Unsupported shapes are ignored by the runtime. (Another hug: {@link allowed_response_instruction}.)
50
+ */
51
+ export declare const CLIQ_ALLOWED_RESPONSE_INSTRUCTION: string;
52
+ /**
53
+ * The allowed endings for a turn in this phase: {@link CLIQ_ALLOWED_RESPONSE_INSTRUCTION} for `form`; for another
54
+ * hug, the same choices with the fence described from the hug's definition.
55
+ */
56
+ export declare function allowed_response_instruction(hug: PhaseHug | null): string;
57
+ /** The ask a model made, checked against its phase's hug: what to call `ctx.ask` with, or the problems to send back. */
58
+ export type CheckedAsk = {
59
+ readonly ok: true;
60
+ readonly definition: HugDefinition<unknown, unknown>;
61
+ readonly options: {
62
+ title: string;
63
+ params: Record<string, unknown>;
64
+ };
65
+ } | {
66
+ readonly ok: false;
67
+ readonly problems: string[];
68
+ };
69
+ /**
70
+ * Check a model's ask against the phase's hug: a `form` phase takes a form block; another hug takes `{ title,
71
+ * params }` with params its definition accepts. A `QUESTION:` line is a form ask in any phase.
72
+ */
73
+ export declare function check_llm_ask(ask: LlmAsk, hug: PhaseHug | null): CheckedAsk;
74
+ /** An ask written back as the fence the model sent (for the transcript when it must be fixed). */
75
+ export declare function ask_as_fence(ask: LlmAsk): string;
76
+ /** What a reply's last `cliq_hug` fence is: none, a valid ask, or a block that fails the check (and why). */
77
+ export type CliqHugParse = {
78
+ readonly kind: 'none';
79
+ } | {
80
+ readonly kind: 'ask';
81
+ readonly ask: LlmAsk;
82
+ } | {
83
+ readonly kind: 'invalid';
84
+ readonly problems: string[];
85
+ };
86
+ /** The last `cliq_hug` fence in model / CLI output: an ask, or the problems that keep it from being one. */
87
+ export declare function parse_cliq_hug(text: string): CliqHugParse;
88
+ /** The last `cliq_hug` fence in model / CLI output as an ask, or null when absent or invalid. */
89
+ export declare function extract_cliq_hug(text: string): LlmAsk | null;
90
+ /** What the model is told when its `cliq_hug` block fails the check: the problems, and to send it again. */
91
+ export declare function invalid_hug_message(problems: readonly string[]): string;
92
+ /** A closing `QUESTION:` as an ask: one required text answer, with the turn's narrative as context. */
93
+ export declare function question_hug(question: string, narrative: string): FormAsk;
94
+ /** A form ask as the options for `ctx.ask(form, …)` (channels, expiry and reminders come from the phase). */
95
+ export declare function form_ask(ask: FormAsk): {
96
+ title: string;
97
+ params: Record<string, unknown>;
98
+ };
99
+ /** The line under the answers when files people sent were saved for the model. */
100
+ export declare const SAVED_FILES_NOTE = "Files people sent are saved at the paths shown; read them with your file tools.";
101
+ /**
102
+ * The user turn that hands the model the answers on resume; a person who couldn't answer says why.
103
+ * With `files_saved`, the answers' files are paths in the workspace and a line says so.
104
+ */
105
+ export declare function answers_message(responses: readonly HugResponse[], files_saved?: boolean): string;
106
+ //# sourceMappingURL=llm.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"llm.d.ts","sourceRoot":"","sources":["../../src/hug/llm.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAEjD,OAAO,EAAe,cAAc,EAAkB,MAAM,sBAAsB,CAAC;AAEnF,OAAO,EAA6B,KAAK,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvF,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE5D,6DAA6D;AAC7D,eAAO,MAAM,cAAc,aAAa,CAAC;AAEzC,kFAAkF;AAClF,MAAM,WAAW,OAAO;IACpB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,gBAAgB,EAAE,cAAc,EAAE,CAAC;IAC5C,QAAQ,CAAC,O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hug-widgets §9.4): the `cliq_hug` fence that ends a turn,
3
+ * and a closing `QUESTION:` line. A generic agent (LLM or CLI) asks with **its phase's hug** (`hug.name`, else `form`):
4
+ *
5
+ * - `form` — the fence holds `{ title?, prompt, requested_inputs }`, as before.
6
+ * - any other hug — the turn instruction describes it from its definition (title, description, the params as JSON
7
+ * Schema) and the fence holds `{ title, params }`; the params are checked against the definition, and a problem
8
+ * goes back to the model to fix (the same resend loop as a bad form block).
9
+ *
10
+ * A `QUESTION:` line is always a one-answer `form`. None of them choose channels, expiry or reminders: those always
11
+ * come from the phase (`hug:`), so text injected into the model's context can't steer a question to other people or
12
+ * change how long they have.
13
+ */
14
+ import { form } from './definitions/index.js';
15
+ import { DEFAULT_HUG, HugDefinitions, phase_hug_name } from './hug_definitions.js';
16
+ import { problems_text } from './problems.js';
17
+ import { validate_requested_inputs } from './requested_inputs.js';
18
+ /** Fence language tag of a turn-ending ask in model text. */
19
+ export const CLIQ_HUG_FENCE = 'cliq_hug';
20
+ /**
21
+ * The phase's hug (`CLIQ_HUG_NAME`), loaded from its bundle; null for `form` (the default).
22
+ *
23
+ * @throws HugRefusedError (`hug_unknown`) when this phase can't see it
24
+ */
25
+ export async function load_phase_hug(definitions = new HugDefinitions(), name = phase_hug_name()) {
26
+ if (name === DEFAULT_HUG)
27
+ return null;
28
+ return { name, definition: await definitions.get(name) };
29
+ }
30
+ /**
31
+ * Text appended to every LLM / CLI turn in a `form` phase: the only ways the model may end a turn besides finishing
32
+ * the work. Unsupported shapes are ignored by the runtime. (Another hug: {@link allowed_response_instruction}.)
33
+ */
34
+ export const CLIQ_ALLOWED_RESPONSE_INSTRUCTION = [
35
+ '## Allowed ways to finish this turn',
36
+ '',
37
+ 'You may do exactly one of:',
38
+ '1. Continue/complete the work in normal assistant text (no special fence), OR',
39
+ '2. Ask the person running this a question you cannot answer yourself: end your',
40
+ ' reply with one line `QUESTION: <your question>`, then stop. The run pauses and',
41
+ ' resumes with their answer. Ask only when you are blocked, OR',
42
+ '3. Ask for several structured answers by printing exactly one fenced JSON block with',
43
+ ` language \`${CLIQ_HUG_FENCE}\`, then stop. Do not call tools after it.`,
44
+ '',
45
+ 'Do NOT invent other event names, APIs, or XML tags (no need_human, no',
46
+ 'phase.*, no custom event types). Unsupported shapes are ignored.',
47
+ '',
48
+ 'Requested input types: `text`, `number`, `boolean`, `enum` (with `choices`), `file`.',
49
+ 'Names are lowercase identifiers. Shape:',
50
+ '',
51
+ '```' + CLIQ_HUG_FENCE,
52
+ '{',
53
+ ' "title": "one-line ask",',
54
+ ' "prompt": "what you need and why",',
55
+ ' "requested_inputs": [',
56
+ ' { "name": "environment", "type": "enum", "choices": [{ "value": "staging" }, { "value": "prod" }] },',
57
+ ' { "name": "logs", "type": "file", "accept": [".log", "text/plain"], "required": false },',
58
+ ' { "name": "notes", "type": "text", "required": false }',
59
+ ' ]',
60
+ '}',
61
+ '```',
62
+ ].join('\n');
63
+ /**
64
+ * The allowed endings for a turn in this phase: {@link CLIQ_ALLOWED_RESPONSE_INSTRUCTION} for `form`; for another
65
+ * hug, the same choices with the fence described from the hug's definition.
66
+ */
67
+ export function allowed_response_instruction(hug) {
68
+ if (!hug)
69
+ return CLIQ_ALLOWED_RESPONSE_INSTRUCTION;
70
+ const d = hug.definition.describe();
71
+ return [
72
+ '## Allowed ways to finish this turn',
73
+ '',
74
+ 'You may do exactly one of:',
75
+ '1. Continue/complete the work in normal assistant text (no special fence), OR',
76
+ '2. Ask the person running this a question you cannot answer yourself: end your',
77
+ ' reply with one line `QUESTION: <your question>`, then stop. The run pauses and',
78
+ ' resumes with their answer. Ask only when you are blocked, OR',
79
+ `3. Ask people with this phase's hug, \`${d.name}\` (${d.title}): print exactly one fenced JSON`,
80
+ ` block with language \`${CLIQ_HUG_FENCE}\`, then stop. Do not call tools after it.`,
81
+ '',
82
+ `About \`${d.name}\`: ${d.description || d.title}`,
83
+ '',
84
+ 'Do NOT invent other event names, APIs, or XML tags (no need_human, no',
85
+ 'phase.*, no custom event types). Unsupported shapes are ignored.',
86
+ '',
87
+ `Shape — \`params\` is what \`${d.name}\` takes, as this JSON Schema describes:`,
88
+ '',
89
+ '```' + CLIQ_HUG_FENCE,
90
+ '{ "title": "one-line ask", "params": { … } }',
91
+ '```',
92
+ '',
93
+ '```json',
94
+ JSON.stringify(d.params_schema, null, 2),
95
+ '```',
96
+ '',
97
+ 'The answers come back as JSON values, checked against the hug\'s answer rules.',
98
+ ].join('\n');
99
+ }
100
+ /**
101
+ * Check a model's ask against the phase's hug: a `form` phase takes a form block; another hug takes `{ title,
102
+ * params }` with params its definition accepts. A `QUESTION:` line is a form ask in any phase.
103
+ */
104
+ export function check_llm_ask(ask, hug) {
105
+ const is_form = 'requested_inputs' in ask;
106
+ if (!hug || (is_form && ask.question)) {
107
+ if (!is_form)
108
+ return { ok: false, problems: ['this phase asks with the form hug: write { "title", "prompt", "requested_inputs" } (no "params")'] };
109
+ return { ok: true, definition: form, options: form_ask(ask) };
110
+ }
111
+ if (is_form)
112
+ return { ok: false, problems: [`this phase asks with the \`${hug.name}\` hug: write { "title", "params" } with params as its schema says (not prompt / requested_inputs)`] };
113
+ const checked = hug.definition.check_params(ask.params);
114
+ if (!checked.ok)
115
+ return { ok: false, problems: problems_text(checked.problems).map((p) => `params.${p}`) };
116
+ return { ok: true, definition: hug.definition, options: { title: ask.title, params: checked.value } };
117
+ }
118
+ /** An ask written back as the fence the model sent (for the transcript when it must be fixed). */
119
+ export function ask_as_fence(ask) {
120
+ const body = { ...ask };
121
+ delete body['question'];
122
+ return '```' + CLIQ_HUG_FENCE + '\n' + JSON.stringify(body, null, 2) + '\n```';
123
+ }
124
+ /** The last `cliq_hug` fence in model / CLI output: an ask, or the problems that keep it from being one. */
125
+ export function parse_cliq_hug(text) {
126
+ const block = last_fence(text ?? '');
127
+ if (!block)
128
+ return { kind: 'none' };
129
+ let parsed;
130
+ try {
131
+ parsed = JSON.parse(block.body);
132
+ }
133
+ catch (err) {
134
+ return { kind: 'invalid', problems: [`the block is not valid JSON (${err instanceof Error ? err.message : String(err)})`] };
135
+ }
136
+ if (is_hug_shape(parsed))
137
+ return to_hug_ask(parsed);
138
+ const result = to_ask(parsed);
139
+ if (!result.ok)
140
+ return { kind: 'invalid', problems: result.problems };
141
+ const narrative = text.slice(0, block.start).trim();
142
+ const ask = narrative ? { ...result.ask, context: [{ type: 'transcript', turns: [{ role: 'assistant', content: narrative }] }] } : result.ask;
143
+ return { kind: 'ask', ask };
144
+ }
145
+ /** The last `cliq_hug` fence in model / CLI output as an ask, or null when absent or invalid. */
146
+ export function extract_cliq_hug(text) {
147
+ const parsed = parse_cliq_hug(text);
148
+ return parsed.kind === 'ask' ? parsed.ask : null;
149
+ }
150
+ /** What the model is told when its `cliq_hug` block fails the check: the problems, and to send it again. */
151
+ export function invalid_hug_message(problems) {
152
+ return [
153
+ `Your \`${CLIQ_HUG_FENCE}\` block was not sent — nobody was asked, because it has these problems:`,
154
+ ...problems.map((p) => `- ${p}`),
155
+ '',
156
+ `Reply with the corrected \`${CLIQ_HUG_FENCE}\` block (the whole block), then stop.`,
157
+ ].join('\n');
158
+ }
159
+ /** A closing `QUESTION:` as an ask: one required text answer, with the turn's narrative as context. */
160
+ export function question_hug(question, narrative) {
161
+ const q = question.trim();
162
+ const story = narrative.trim();
163
+ return {
164
+ title: q.length > 200 ? `${q.slice(0, 197)}…` : q,
165
+ prompt: q,
166
+ requested_inputs: [{ name: 'answer', type: 'text', label: 'Your answer', required: true, multiline: true }],
167
+ ...(story ? { context: [{ type: 'transcript', turns: [{ role: 'assistant', content: story }] }] } : {}),
168
+ question: true,
169
+ };
170
+ }
171
+ /** A form ask as the options for `ctx.ask(form, …)` (channels, expiry and reminders come from the phase). */
172
+ export function form_ask(ask) {
173
+ return {
174
+ title: ask.title,
175
+ params: { prompt: ask.prompt, inputs: ask.requested_inputs, ...(ask.context ? { context: ask.context } : {}) },
176
+ };
177
+ }
178
+ /** The line under the answers when files people sent were saved for the model. */
179
+ export const SAVED_FILES_NOTE = 'Files people sent are saved at the paths shown; read them with your file tools.';
180
+ /**
181
+ * The user turn that hands the model the answers on resume; a person who couldn't answer says why.
182
+ * With `files_saved`, the answers' files are paths in the workspace and a line says so.
183
+ */
184
+ export function answers_message(responses, files_saved = false) {
185
+ if (responses.length === 0)
186
+ return 'No one answered.';
187
+ const text = responses.map((r) => {
188
+ const declined = r.values['declined'];
189
+ if (typeof declined === 'string')
190
+ return `${r.responder.name} couldn't answer: ${declined}`;
191
+ return `Answers from ${r.responder.name}:\n\`\`\`json\n${JSON.stringify(r.values, null, 2)}\n\`\`\``;
192
+ }).join('\n\n');
193
+ return files_saved ? `${text}\n\n${SAVED_FILES_NOTE}` : text;
194
+ }
195
+ /** Whether a fence's body is a hug ask (`params`, without `prompt` / `requested_inputs`). */
196
+ function is_hug_shape(raw) {
197
+ if (!raw || typeof raw !== 'object' || Array.isArray(raw))
198
+ return false;
199
+ const r = raw;
200
+ return 'params' in r && !('prompt' in r) && !('requested_inputs' in r);
201
+ }
202
+ /** `{ title, params }` → a hug ask (the params are checked later, against the phase's hug). */
203
+ function to_hug_ask(raw) {
204
+ const title = typeof raw['title'] === 'string' ? raw['title'].trim() : '';
205
+ const params = raw['params'];
206
+ const problems = [];
207
+ if (!title)
208
+ problems.push('title is required');
209
+ if (!params || typeof params !== 'object' || Array.isArray(params))
210
+ problems.push('params must be an object');
211
+ if (problems.length)
212
+ return { kind: 'invalid', problems };
213
+ return { kind: 'ask', ask: { title: title.slice(0, 200), params: params } };
214
+ }
215
+ /** Raw `{ title?, prompt, requested_inputs }` (a `cliq_hug` fence's body) → an ask, checked with the shared schema. */
216
+ function to_ask(raw) {
217
+ if (!raw || typeof raw !== 'object' || Array.isArray(raw))
218
+ return { ok: false, problems: ['expected an object'] };
219
+ const r = raw;
220
+ const prompt = typeof r['prompt'] === 'string' ? r['prompt'].trim() : '';
221
+ if (!prompt)
222
+ return { ok: false, problems: ['prompt is required'] };
223
+ const inputs = validate_requested_inputs(r['requested_inputs'] ?? []);
224
+ if (!inputs.ok)
225
+ return { ok: false, problems: inputs.problems };
226
+ if (inputs.value.length === 0)
227
+ return { ok: false, problems: ['requested_inputs: ask for at least one answer'] };
228
+ const title = typeof r['title'] === 'string' && r['title'].trim() ? r['title'].trim().slice(0, 200) : first_line(prompt);
229
+ return { ok: true, ask: { title, prompt, requested_inputs: inputs.value } };
230
+ }
231
+ /** The last complete `cliq_hug` fence: where it starts and its body (no regex: model text is unbounded). */
232
+ function last_fence(text) {
233
+ const open = '```' + CLIQ_HUG_FENCE;
234
+ const start = text.toLowerCase().lastIndexOf(open);
235
+ if (start < 0)
236
+ return null;
237
+ const line_end = text.indexOf('\n', start + open.length);
238
+ if (line_end < 0 || text.slice(start + open.length, line_end).trim() !== '')
239
+ return null;
240
+ const close = text.indexOf('```', line_end + 1);
241
+ if (close < 0)
242
+ return null;
243
+ return { start, body: text.slice(line_end + 1, close).trim() };
244
+ }
245
+ /** The prompt's first line, at most 200 characters. */
246
+ function first_line(text) {
247
+ const line = text.split('\n')[0].trim();
248
+ return line.length > 200 ? `${line.slice(0, 197)}…` : line;
249
+ }
250
+ //# sourceMappingURL=llm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"llm.js","sourceRoot":"","sources":["../../src/hug/llm.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAGH,OAAO,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACnF,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,EAAE,yBAAyB,EAAuB,MAAM,uBAAuB,CAAC;AAGvF,6DAA6D;AAC7D,MAAM,CAAC,MAAM,cAAc,GAAG,UAAU,CAAC;AA2BzC;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,cAA8B,IAAI,cAAc,EAAE,EAAE,OAAe,cAAc,EAAE;IACpH,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AC,IAAI,EAAE,CAAC;IACzC,OAAO,IAAI,CAAC,MAAM,GAAG,GAAG,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC;AAC/D,CAAC"}
@@ -0,0 +1,65 @@
1
+ /**
2
+ * Hug policies (PLAN-hug-requests §10.2) — when the requester has heard enough. A policy belongs to
3
+ * the requester, never to Core: it looks at the responses so far and the latest event and says
4
+ * wait, done or failed.
5
+ *
6
+ * A policy without code (`any()`, or `groups` with no `accept` / `reject`) is stored with the Hug,
7
+ * so on resume the SDK re-runs it without calling the agent (§10.4). One with functions is re-run
8
+ * by the agent's own `ctx.ask` when the SDK runs the agent's code again.
9
+ */
10
+ import type { HugEvent, HugResponse, HugSpec } from './types.js';
11
+ /** What a policy decides after an event. */
12
+ export type PolicyResult<T> = {
13
+ readonly kind: 'wait';
14
+ readonly status?: string;
15
+ } | {
16
+ readonly kind: 'done';
17
+ readonly outcome: string;
18
+ readonly value: T;
19
+ } | {
20
+ readonly kind: 'failed';
21
+ readonly reason: string;
22
+ readonly response?: HugResponse;
23
+ };
24
+ /** A requester's rule for when it has heard enough. */
25
+ export type PolicyFn<T> = (spec: HugSpec, responses: readonly HugResponse[], event: HugEvent) => PolicyResult<T>;
26
+ /** A stateless test of one response's values (only what the reviewer submitted). */
27
+ export type ValuesTest = (values: Readonly<Record<string, unknown>>) => boolean;
28
+ /** One reviewer group, the shape of a gate's `review.reviewers` entry. */
29
+ export interface ReviewerGroup {
30
+ readonly policy: 'any' | 'all';
31
+ readonly channels: readonly string[];
32
+ }
33
+ /** A policy without code, as stored with a Hug. */
34
+ export type PolicyDescriptor = {
35
+ readonly name: 'any';
36
+ } | {
37
+ readonly name: 'groups';
38
+ readonly groups: readonly ReviewerGroup[];
39
+ };
40
+ /** A policy: its rule, and its descriptor when it has no code (null otherwise). */
41
+ export interface Policy<T> {
42
+ readonly evaluate: PolicyFn<T>;
43
+ readonly descriptor: PolicyDescriptor | null;
44
+ }
45
+ /** A custom policy. */
46
+ export declare function custom<T>(evaluate: PolicyFn<T>): Policy<T>;
47
+ /** Done on the first response (its values); failed when the Hug expires or is cancelled. */
48
+ export declare function any(): Policy<Readonly<Record<string, unknown>>>;
49
+ /**
50
+ * Done when every group is satisfied; failed on a rejecting response (the first non-approval
51
+ * decides), or when the Hug expires or is cancelled. The value is every response so far.
52
+ *
53
+ * - A response counts for a channel when the channel is in its `via`.
54
+ * - `policy: 'any'` — one accepting response through any of the group's channels.
55
+ * - `policy: 'all'` — one accepting response through each of the group's channels.
56
+ * - `accept` defaults to any response; `reject` to never. Both are stateless tests of a response's
57
+ * values.
58
+ */
59
+ export declare function groups(reviewer_groups: readonly ReviewerGroup[], opts?: {
60
+ accept?: ValuesTest;
61
+ reject?: ValuesTest;
62
+ }): Policy<readonly HugResponse[]>;
63
+ /** The policy a descriptor stands for. */
64
+ export declare function policy_from(descriptor: PolicyDescriptor): Policy<unknown>;
65
+ //# sourceMappingURL=policies.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"policies.d.ts","sourceRoot":"","sources":["../../src/hug/policies.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAEjE,4CAA4C;AAC5C,MAAM,MAAM,YAAY,CAAC,CAAC,IACpB;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,GACnD;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAA;CAAE,GACtE;IAAE,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,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B,eAAe,EAAE,SAAS,aAAa,EAAE,EACzC,IAAI,GAAE;IAAE,MAAM,CAAC,EAAE,UAAU,CAAC;IAAC,MAAM,CAAC,EAAE,UAAU,CAAA;CAAO,GACxD,MAAM,CAAC,SAAS,WAAW,EAAE,CAAC,CAoBhC;AAED,0CAA0C;AAC1C,wBAAgB,WAAW,CAAC,UAAU,EAAE,gBAAgB,GAAG,MAAM,CAAC,OAAO,CAAC,CAEzE"}
@@ -0,0 +1,80 @@
1
+ /**
2
+ * Hug policies (PLAN-hug-requests §10.2) — when the requester has heard enough. A policy belongs to
3
+ * the requester, never to Core: it looks at the responses so far and the latest event and says
4
+ * wait, done or failed.
5
+ *
6
+ * A policy without code (`any()`, or `groups` with no `accept` / `reject`) is stored with the Hug,
7
+ * so on resume the SDK re-runs it without calling the agent (§10.4). One with functions is re-run
8
+ * by the agent's own `ctx.ask` when the SDK runs the agent's code again.
9
+ */
10
+ /** A custom policy. */
11
+ export function custom(evaluate) {
12
+ return { evaluate, descriptor: null };
13
+ }
14
+ /** Done on the first response (its values); failed when the Hug expires or is cancelled. */
15
+ export function any() {
16
+ return {
17
+ descriptor: { name: 'any' },
18
+ evaluate: (_spec, _responses, event) => {
19
+ const ended = ending(event);
20
+ if (ended)
21
+ return ended;
22
+ if (event.type === 'response')
23
+ return { kind: 'done', outcome: `Answered by ${event.response.responder.name}`, value: event.response.values };
24
+ return { kind: 'wait' };
25
+ },
26
+ };
27
+ }
28
+ /**
29
+ * Done when every group is satisfied; failed on a rejecting response (the first non-approval
30
+ * decides), or when the Hug expires or is cancelled. The value is every response so far.
31
+ *
32
+ * - A response counts for a channel when the channel is in its `via`.
33
+ * - `policy: 'any'` — one accepting response through any of the group's channels.
34
+ * - `policy: 'all'` — one accepting response through each of the group's channels.
35
+ * - `accept` defaults to any response; `reject` to never. Both are stateless tests of a response's
36
+ * values.
37
+ */
38
+ export function groups(reviewer_groups, opts = {}) {
39
+ const accept = opts.accept ?? (() => true);
40
+ const reject = opts.reject ?? (() => false);
41
+ return {
42
+ descriptor: opts.accept || opts.reject
43
+ ? null
44
+ : { name: 'groups', groups: reviewer_groups.map((g) => ({ policy: g.policy, channels: [...g.channels] })) },
45
+ evaluate: (_spec, responses, event) => {
46
+ const ended = ending(event);
47
+ if (ended)
48
+ return ended;
49
+ if (event.type === 'response' && reject(event.response.values)) {
50
+ return { kind: 'failed', reason: `Rejected by ${event.response.responder.name}`, response: event.response };
51
+ }
52
+ const accepting = responses.filter((r) => accept(r.values));
53
+ const pending = reviewer_groups.filter((g) => !group_satisfied(g, accepting));
54
+ if (pending.length === 0)
55
+ return { kind: 'done', outcome: 'Approved', value: responses };
56
+ const done = reviewer_groups.length - pending.length;
57
+ return { kind: 'wait', status: `${done} of ${reviewer_groups.length} reviewer group(s) satisfied` };
58
+ },
59
+ };
60
+ }
61
+ /** The policy a descriptor stands for. */
62
+ export function policy_from(descriptor) {
63
+ return descriptor.name === 'any' ? any() : groups(descriptor.groups);
64
+ }
65
+ /** `expired` / `cancelled` fail every built-in policy. */
66
+ function ending(event) {
67
+ if (event.type === 'expired')
68
+ return { kind: 'failed', reason: 'expired' };
69
+ if (event.type === 'cancelled')
70
+ return { kind: 'failed', reason: event.reason ? `cancelled: ${event.reason}` : 'cancelled' };
71
+ return null;
72
+ }
73
+ /** Whether a group has the accepting responses it needs. */
74
+ function group_satisfied(group, accepting) {
75
+ const via = (channel) => accepting.some((r) => r.via.includes(channel));
76
+ if (group.channels.length === 0)
77
+ return false;
78
+ return group.policy === 'all' ? group.channels.every(via) : group.channels.some(via);
79
+ }
80
+ //# sourceMappingURL=policies.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"policies.js","sourceRoot":"","sources":["../../src/hug/policies.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAiCH,uBAAuB;AACvB,MAAM,UAAU,MAAM,CAAI,QAAqB;IAC3C,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC;AAC1C,CAAC;AA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C3B,IAAI,KAAK,CAAC,IAAI,KAAK,SAAS;QAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC;IAC3E,IAAI,KAAK,CAAC,IAAI,KAAK,WAAW;QAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,cAAc,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC;IAC7H,OAAO,IAAI,CAAC;AAChB,CAAC;AAED,4DAA4D;AAC5D,SAAS,eAAe,CAAC,KAAoB,EAAE,SAAiC;IAC5E,MAAM,GAAG,GAAG,CAAC,OAAe,EAAE,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC;IAChF,IAAI,KAAK,CAAC,QAAQ,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IAC9C,OAAO,KAAK,CAAC,MAAM,KAAK,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AACzF,CAAC"}
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Problems with an answer or params (PLAN-hug-widgets §9.2): a message and, when it is about one field, the path to it
3
+ * (`severity`, `verdicts[2].note`). Shared by `define_hug` checks, the frontend SDK and the agent SDK.
4
+ *
5
+ * Browser-safe: imports only `zod`.
6
+ */
7
+ import type { z } from 'zod';
8
+ /** One problem: what is wrong, and where (a field path like `rows[3].total`; absent for the whole answer). */
9
+ export interface Problem {
10
+ readonly path?: string;
11
+ readonly message: string;
12
+ }
13
+ /** A checked value, or the problems that stopped it. */
14
+ export type Checked<T> = {
15
+ readonly ok: true;
16
+ readonly value: T;
17
+ } | {
18
+ readonly ok: false;
19
+ readonly problems: Problem[];
20
+ };
21
+ /** `verdicts[2].note` for the Zod path `['verdicts', 2, 'note']`; undefined for the root. */
22
+ export declare function path_of(path: readonly PropertyKey[]): string | undefined;
23
+ /**
24
+ * The problems in a failed Zod parse.
25
+ *
26
+ * A union that matched no branch reports the branch that came closest (the fewest issues), so the person sees "reason:
27
+ * required" rather than "doesn't match any of 2 shapes". Each unrecognized key counts as an issue: an answer with four
28
+ * filled fields is far from `form`'s `{ declined }` branch, however Zod groups them.
29
+ *
30
+ * @param error - The `error` of a failed `safeParse`.
31
+ */
32
+ export declare function problems_from_zod(error: z.ZodError): Problem[];
33
+ /** Problems as one line each (`verdicts[2].note: required`), for logs and LLM resends. */
34
+ export declare function problems_text(problems: readonly Problem[]): string[];
35
+ //# sourceMappingURL=problems.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"problems.d.ts","sourceRoot":"","sources":["../../src/hug/problems.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAE7B,8GAA8G;AAC9G,MAAM,WAAW,OAAO;IACpB,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CAC5B;AAED,wDAAwD;AACxD,MAAM,MAAM,OAAO,CAAC,CAAC,IACf;IAAE,QAAQ,CAAC,EAAE,EAAE,IAAI,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAA;CAAE,GACxC;IAAE,QAAQ,CAAC,EAAE,EAAE,KAAK,CAAC;IAAC,QAAQ,CAAC,QAAQ,EAAE,OAAO,EAAE,CAAA;CAAE,CAAC;AAE3D,6FAA6F;AAC7F,wBAAgB,OAAO,CAAC,IAAI,EAAE,SAAS,WAAW,EAAE,GAAG,MAAM,GAAG,SAAS,CAQxE;AAKD;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,CAAC,CAAC,QAAQ,GAAG,OAAO,EAAE,CAe9D;AAOD,0FAA0F;AAC1F,wBAAgB,aAAa,CAAC,QAAQ,EAAE,SAAS,OAAO,EAAE,GAAG,MAAM,EAAE,CAEpE"}
@@ -0,0 +1,53 @@
1
+ /**
2
+ * Problems with an answer or params (PLAN-hug-widgets §9.2): a message and, when it is about one field, the path to it
3
+ * (`severity`, `verdicts[2].note`). Shared by `define_hug` checks, the frontend SDK and the agent SDK.
4
+ *
5
+ * Browser-safe: imports only `zod`.
6
+ */
7
+ /** `verdicts[2].note` for the Zod path `['verdicts', 2, 'note']`; undefined for the root. */
8
+ export function path_of(path) {
9
+ let out = '';
10
+ for (const part of path) {
11
+ if (typeof part === 'number')
12
+ out += `[${part}]`;
13
+ else if (out === '')
14
+ out = String(part);
15
+ else
16
+ out += `.${String(part)}`;
17
+ }
18
+ return out === '' ? undefined : out;
19
+ }
20
+ /**
21
+ * The problems in a failed Zod parse.
22
+ *
23
+ * A union that matched no branch reports the branch that came closest (the fewest issues), so the person sees "reason:
24
+ * required" rather than "doesn't match any of 2 shapes". Each unrecognized key counts as an issue: an answer with four
25
+ * filled fields is far from `form`'s `{ declined }` branch, however Zod groups them.
26
+ *
27
+ * @param error - The `error` of a failed `safeParse`.
28
+ */
29
+ export function problems_from_zod(error) {
30
+ const out = [];
31
+ const walk = (issues, prefix) => {
32
+ for (const issue of issues) {
33
+ const path = [...prefix, ...issue.path];
34
+ if (issue.code === 'invalid_union' && issue.errors.length > 0) {
35
+ const best = [...issue.errors].sort((a, b) => distance(a) - distance(b))[0];
36
+ walk(best, path);
37
+ continue;
38
+ }
39
+ out.push({ ...(path_of(path) ? { path: path_of(path) } : {}), message: issue.message });
40
+ }
41
+ };
42
+ walk(error.issues, []);
43
+ return out;
44
+ }
45
+ /** How far a union branch was from matching: its issues, counting each unrecognized key as one. */
46
+ function distance(issues) {
47
+ return issues.reduce((n, i) => n + (i.code === 'unrecognized_keys' ? Math.max(1, i.keys.length) : 1), 0);
48
+ }
49
+ /** Problems as one line each (`verdicts[2].note: required`), for logs and LLM resends. */
50
+ export function problems_text(problems) {
51
+ return problems.map((p) => (p.path ? `${p.path}: ${p.message}` : p.message));
52
+ }
53
+ //# sourceMappingURL=problems.js.map