@mupt-ai/dari-gateway 0.1.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (369) hide show
  1. package/README.md +8 -1
  2. package/dist/bun.d.ts +2 -0
  3. package/dist/bun.js +4 -0
  4. package/dist/context/eval_catalog.d.ts +3 -0
  5. package/dist/context/eval_catalog.js +7 -0
  6. package/dist/context/interaction_fingerprint.d.ts +27 -0
  7. package/dist/context/interaction_fingerprint.js +519 -0
  8. package/dist/context/interaction_fingerprint_format.d.ts +42 -0
  9. package/dist/context/interaction_fingerprint_format.js +113 -0
  10. package/dist/context/interaction_lease_depth.d.ts +2 -0
  11. package/dist/context/interaction_lease_depth.js +110 -0
  12. package/dist/context/lease_history.d.ts +7 -0
  13. package/dist/context/lease_history.js +158 -0
  14. package/dist/context/pricing.d.ts +4 -0
  15. package/dist/context/pricing.js +23 -0
  16. package/dist/context/provider_prompt_accounting.d.ts +14 -0
  17. package/dist/context/provider_prompt_accounting.js +187 -0
  18. package/dist/context/routing_context.d.ts +40 -0
  19. package/dist/context/routing_context.js +211 -0
  20. package/dist/http/auth.d.ts +2 -0
  21. package/dist/http/auth.js +35 -0
  22. package/dist/http/errors.d.ts +19 -0
  23. package/dist/http/errors.js +89 -0
  24. package/dist/http/handler.d.ts +12 -0
  25. package/dist/http/handler.js +81 -0
  26. package/dist/http/http2_server.d.ts +6 -0
  27. package/dist/http/http2_server.js +103 -0
  28. package/dist/http/serve.d.ts +20 -0
  29. package/dist/http/serve.js +78 -0
  30. package/dist/index.d.ts +6 -0
  31. package/dist/index.js +8 -0
  32. package/dist/ingress/anthropic_messages.d.ts +3 -0
  33. package/dist/ingress/anthropic_messages.js +122 -0
  34. package/dist/ingress/anthropic_models.d.ts +1 -0
  35. package/dist/ingress/anthropic_models.js +23 -0
  36. package/dist/ingress/chat_completions.d.ts +2 -0
  37. package/dist/ingress/chat_completions.js +37 -0
  38. package/dist/ingress/claude_code/request_context.d.ts +2 -0
  39. package/dist/ingress/claude_code/request_context.js +31 -0
  40. package/dist/ingress/codex.d.ts +3 -0
  41. package/dist/ingress/codex.js +65 -0
  42. package/dist/ingress/codex_models.d.ts +2 -0
  43. package/dist/ingress/codex_models.js +89 -0
  44. package/dist/ingress/json.d.ts +1 -0
  45. package/dist/ingress/json.js +95 -0
  46. package/dist/ingress/models.d.ts +1 -0
  47. package/dist/ingress/models.js +53 -0
  48. package/dist/interaction/capabilities.d.ts +3 -0
  49. package/dist/interaction/capabilities.js +24 -0
  50. package/dist/interaction/image.d.ts +4 -0
  51. package/dist/interaction/image.js +13 -0
  52. package/dist/interaction/portable_reasoning_state.d.ts +4 -0
  53. package/dist/interaction/portable_reasoning_state.js +18 -0
  54. package/dist/interaction/provider_continuation_state.d.ts +6 -0
  55. package/dist/interaction/provider_continuation_state.js +27 -0
  56. package/dist/interaction/tool_identity.d.ts +10 -0
  57. package/dist/interaction/tool_identity.js +41 -0
  58. package/dist/interaction/types.d.ts +203 -0
  59. package/dist/interaction/types.js +5 -0
  60. package/dist/models/context_limits.d.ts +2 -0
  61. package/dist/models/context_limits.js +7 -0
  62. package/dist/models/execution_provider.d.ts +8 -0
  63. package/dist/models/execution_provider.js +13 -0
  64. package/dist/models/gateways.d.ts +11 -0
  65. package/dist/models/gateways.js +45 -0
  66. package/dist/models/ids.d.ts +1 -0
  67. package/dist/models/ids.js +15 -0
  68. package/dist/models/provider_defaults.d.ts +4 -0
  69. package/dist/models/provider_defaults.js +41 -0
  70. package/dist/models/runtime_overrides.d.ts +4 -0
  71. package/dist/models/runtime_overrides.js +209 -0
  72. package/dist/observability/errors.d.ts +8 -0
  73. package/dist/observability/errors.js +11 -0
  74. package/dist/platform/platform.d.ts +152 -0
  75. package/dist/platform/platform.js +11 -0
  76. package/dist/platform/routing_contract.d.ts +2 -0
  77. package/dist/platform/routing_contract.js +5 -0
  78. package/dist/protocol/input/anthropic_messages.d.ts +2 -0
  79. package/dist/protocol/input/anthropic_messages.js +494 -0
  80. package/dist/protocol/input/chat_completions.d.ts +4 -0
  81. package/dist/protocol/input/chat_completions.js +212 -0
  82. package/dist/protocol/input/chat_completions_validation.d.ts +2 -0
  83. package/dist/protocol/input/chat_completions_validation.js +257 -0
  84. package/dist/protocol/input/openai_responses.d.ts +2 -0
  85. package/dist/protocol/input/openai_responses.js +666 -0
  86. package/dist/protocol/input/router_model.d.ts +7 -0
  87. package/dist/protocol/input/router_model.js +43 -0
  88. package/dist/protocol/output/anthropic_messages.d.ts +10 -0
  89. package/dist/protocol/output/anthropic_messages.js +15 -0
  90. package/dist/protocol/output/anthropic_messages_output.d.ts +10 -0
  91. package/dist/protocol/output/anthropic_messages_output.js +124 -0
  92. package/dist/protocol/output/anthropic_messages_stream.d.ts +16 -0
  93. package/dist/protocol/output/anthropic_messages_stream.js +267 -0
  94. package/dist/protocol/output/chat_completions.d.ts +29 -0
  95. package/dist/protocol/output/chat_completions.js +406 -0
  96. package/dist/protocol/output/chat_reasoning_detail.d.ts +2 -0
  97. package/dist/protocol/output/chat_reasoning_detail.js +13 -0
  98. package/dist/protocol/output/delivered_stream_snapshot.d.ts +10 -0
  99. package/dist/protocol/output/delivered_stream_snapshot.js +31 -0
  100. package/dist/protocol/output/openai_responses.d.ts +10 -0
  101. package/dist/protocol/output/openai_responses.js +14 -0
  102. package/dist/protocol/output/openai_responses_output.d.ts +14 -0
  103. package/dist/protocol/output/openai_responses_output.js +125 -0
  104. package/dist/protocol/output/openai_responses_stream.d.ts +18 -0
  105. package/dist/protocol/output/openai_responses_stream.js +546 -0
  106. package/dist/protocol/output/sse_stream.d.ts +31 -0
  107. package/dist/protocol/output/sse_stream.js +67 -0
  108. package/dist/providers/anthropic_safeguards.d.ts +11 -0
  109. package/dist/providers/anthropic_safeguards.js +81 -0
  110. package/dist/providers/aws_assume_role.d.ts +17 -0
  111. package/dist/providers/aws_assume_role.js +107 -0
  112. package/dist/providers/cancel_estimate.d.ts +43 -0
  113. package/dist/providers/cancel_estimate.js +89 -0
  114. package/dist/providers/execution.d.ts +72 -0
  115. package/dist/providers/execution.js +491 -0
  116. package/dist/providers/model_capabilities.d.ts +11 -0
  117. package/dist/providers/model_capabilities.js +29 -0
  118. package/dist/providers/pi.d.ts +65 -0
  119. package/dist/providers/pi.js +319 -0
  120. package/dist/providers/pi_context.d.ts +7 -0
  121. package/dist/providers/pi_context.js +405 -0
  122. package/dist/providers/pi_options.d.ts +11 -0
  123. package/dist/providers/pi_options.js +398 -0
  124. package/dist/providers/pi_output.d.ts +2 -0
  125. package/dist/providers/pi_output.js +453 -0
  126. package/dist/providers/provider_attempt_runner.d.ts +55 -0
  127. package/dist/providers/provider_attempt_runner.js +90 -0
  128. package/dist/providers/provider_call.d.ts +77 -0
  129. package/dist/providers/provider_call.js +292 -0
  130. package/dist/providers/provider_reported_cost.d.ts +10 -0
  131. package/dist/providers/provider_reported_cost.js +123 -0
  132. package/dist/providers/reasoning.d.ts +12 -0
  133. package/dist/providers/reasoning.js +30 -0
  134. package/dist/providers/response_capture.d.ts +23 -0
  135. package/dist/providers/response_capture.js +47 -0
  136. package/dist/providers/stream_finalization.d.ts +46 -0
  137. package/dist/providers/stream_finalization.js +165 -0
  138. package/dist/providers/subscription_limits.d.ts +31 -0
  139. package/dist/providers/subscription_limits.js +163 -0
  140. package/dist/providers/subscription_usage.d.ts +10 -0
  141. package/dist/providers/subscription_usage.js +79 -0
  142. package/dist/runtime/claude_code/auxiliary_routing.d.ts +3 -0
  143. package/dist/runtime/claude_code/auxiliary_routing.js +60 -0
  144. package/dist/runtime/customer_disconnect.d.ts +20 -0
  145. package/dist/runtime/customer_disconnect.js +49 -0
  146. package/dist/runtime/explicit_model.d.ts +4 -0
  147. package/dist/runtime/explicit_model.js +53 -0
  148. package/dist/runtime/harness_identity/conversation.d.ts +33 -0
  149. package/dist/runtime/harness_identity/conversation.js +39 -0
  150. package/dist/runtime/harness_identity/extract.d.ts +8 -0
  151. package/dist/runtime/harness_identity/extract.js +214 -0
  152. package/dist/runtime/harness_identity/index.d.ts +2 -0
  153. package/dist/runtime/harness_identity/index.js +2 -0
  154. package/dist/runtime/prepare_routed_completion.d.ts +33 -0
  155. package/dist/runtime/prepare_routed_completion.js +167 -0
  156. package/dist/runtime/provider_stream_lifecycle.d.ts +31 -0
  157. package/dist/runtime/provider_stream_lifecycle.js +88 -0
  158. package/dist/runtime/provider_stream_outcome.d.ts +23 -0
  159. package/dist/runtime/provider_stream_outcome.js +55 -0
  160. package/dist/runtime/request_tags.d.ts +7 -0
  161. package/dist/runtime/request_tags.js +33 -0
  162. package/dist/runtime/routed_completion.d.ts +17 -0
  163. package/dist/runtime/routed_completion.js +80 -0
  164. package/dist/runtime/routed_protocol.d.ts +30 -0
  165. package/dist/runtime/routed_protocol.js +1 -0
  166. package/dist/runtime/routed_runtime.d.ts +40 -0
  167. package/dist/runtime/routed_runtime.js +535 -0
  168. package/dist/runtime/routing_lease.d.ts +26 -0
  169. package/dist/runtime/routing_lease.js +210 -0
  170. package/dist/runtime/runtime_reporter.d.ts +71 -0
  171. package/dist/runtime/runtime_reporter.js +35 -0
  172. package/dist/self_host/config.d.ts +46 -0
  173. package/dist/self_host/config.js +105 -0
  174. package/dist/self_host/main.d.ts +16 -0
  175. package/dist/self_host/main.js +95 -0
  176. package/dist/self_host/platform.d.ts +13 -0
  177. package/dist/self_host/platform.js +50 -0
  178. package/dist/self_host/prefix_store.d.ts +46 -0
  179. package/dist/self_host/prefix_store.js +261 -0
  180. package/dist/self_host/resolve.d.ts +28 -0
  181. package/dist/self_host/resolve.js +171 -0
  182. package/dist/self_host/subscriptions/access.d.ts +10 -0
  183. package/dist/self_host/subscriptions/access.js +37 -0
  184. package/dist/self_host/subscriptions/http.d.ts +15 -0
  185. package/dist/self_host/subscriptions/http.js +187 -0
  186. package/dist/self_host/subscriptions/index.d.ts +24 -0
  187. package/dist/self_host/subscriptions/index.js +24 -0
  188. package/dist/self_host/subscriptions/oauth.d.ts +55 -0
  189. package/dist/self_host/subscriptions/oauth.js +281 -0
  190. package/dist/self_host/subscriptions/store.d.ts +78 -0
  191. package/dist/self_host/subscriptions/store.js +235 -0
  192. package/dist/strategies/auto_routing_selector.d.ts +12 -0
  193. package/dist/strategies/auto_routing_selector.js +61 -0
  194. package/dist/strategies/eval_relevance.d.ts +17 -0
  195. package/dist/strategies/eval_relevance.js +32 -0
  196. package/dist/strategies/fallback_decision.d.ts +8 -0
  197. package/dist/strategies/fallback_decision.js +17 -0
  198. package/dist/strategies/priority_selector.d.ts +7 -0
  199. package/dist/strategies/priority_selector.js +37 -0
  200. package/dist/strategies/route_decision.d.ts +22 -0
  201. package/dist/strategies/route_decision.js +65 -0
  202. package/dist/strategies/routing.d.ts +74 -0
  203. package/dist/strategies/routing.js +280 -0
  204. package/dist/strategies/selector_projection.d.ts +15 -0
  205. package/dist/strategies/selector_projection.js +161 -0
  206. package/dist/telemetry/background.d.ts +7 -0
  207. package/dist/telemetry/background.js +33 -0
  208. package/dist/telemetry/benchmark_replay.d.ts +37 -0
  209. package/dist/telemetry/benchmark_replay.js +108 -0
  210. package/dist/telemetry/billing_finalization.d.ts +64 -0
  211. package/dist/telemetry/billing_finalization.js +96 -0
  212. package/dist/telemetry/ingest_values.d.ts +4 -0
  213. package/dist/telemetry/ingest_values.js +12 -0
  214. package/dist/telemetry/model_cost.d.ts +3 -0
  215. package/dist/telemetry/model_cost.js +15 -0
  216. package/dist/telemetry/prefix_state.d.ts +47 -0
  217. package/dist/telemetry/prefix_state.js +116 -0
  218. package/dist/telemetry/report.d.ts +88 -0
  219. package/dist/telemetry/report.js +621 -0
  220. package/dist/telemetry/requests/interaction_observability.d.ts +45 -0
  221. package/dist/telemetry/requests/interaction_observability.js +180 -0
  222. package/dist/telemetry/requests/retained_interaction_request.d.ts +8 -0
  223. package/dist/telemetry/requests/retained_interaction_request.js +10 -0
  224. package/dist/telemetry/scrub.d.ts +2 -0
  225. package/dist/telemetry/scrub.js +31 -0
  226. package/dist/telemetry/skills/claude/catalog.d.ts +6 -0
  227. package/dist/telemetry/skills/claude/catalog.js +99 -0
  228. package/dist/telemetry/skills/claude/file_reads.d.ts +4 -0
  229. package/dist/telemetry/skills/claude/file_reads.js +110 -0
  230. package/dist/telemetry/skills/claude/observations.d.ts +3 -0
  231. package/dist/telemetry/skills/claude/observations.js +366 -0
  232. package/dist/telemetry/skills/codex/catalog.d.ts +11 -0
  233. package/dist/telemetry/skills/codex/catalog.js +138 -0
  234. package/dist/telemetry/skills/codex/exec_file_reads.d.ts +9 -0
  235. package/dist/telemetry/skills/codex/exec_file_reads.js +36 -0
  236. package/dist/telemetry/skills/codex/explicit.d.ts +3 -0
  237. package/dist/telemetry/skills/codex/explicit.js +90 -0
  238. package/dist/telemetry/skills/codex/file_reads.d.ts +4 -0
  239. package/dist/telemetry/skills/codex/file_reads.js +37 -0
  240. package/dist/telemetry/skills/codex/identity.d.ts +2 -0
  241. package/dist/telemetry/skills/codex/identity.js +20 -0
  242. package/dist/telemetry/skills/observations.d.ts +21 -0
  243. package/dist/telemetry/skills/observations.js +41 -0
  244. package/dist/telemetry/skills/paths.d.ts +11 -0
  245. package/dist/telemetry/skills/paths.js +61 -0
  246. package/dist/telemetry/skills/pi.d.ts +6 -0
  247. package/dist/telemetry/skills/pi.js +223 -0
  248. package/dist/telemetry/skills/shell_file_reads.d.ts +7 -0
  249. package/dist/telemetry/skills/shell_file_reads.js +226 -0
  250. package/dist/telemetry/skills/shell_words.d.ts +13 -0
  251. package/dist/telemetry/skills/shell_words.js +189 -0
  252. package/dist/telemetry/tools/input.d.ts +2 -0
  253. package/dist/telemetry/tools/input.js +14 -0
  254. package/dist/telemetry/tools/observations.d.ts +29 -0
  255. package/dist/telemetry/tools/observations.js +247 -0
  256. package/dist/telemetry/usage.d.ts +57 -0
  257. package/dist/telemetry/usage.js +136 -0
  258. package/dist/types.d.ts +94 -0
  259. package/dist/types.js +1 -0
  260. package/package.json +22 -5
  261. package/src/bun.ts +4 -0
  262. package/src/context/eval_catalog.ts +1 -1
  263. package/src/context/interaction_fingerprint.ts +9 -9
  264. package/src/context/interaction_fingerprint_format.ts +1 -1
  265. package/src/context/interaction_lease_depth.ts +1 -1
  266. package/src/context/pricing.ts +1 -1
  267. package/src/context/provider_prompt_accounting.ts +5 -5
  268. package/src/context/routing_context.ts +17 -17
  269. package/src/http/auth.ts +1 -1
  270. package/src/http/handler.ts +8 -8
  271. package/src/http/serve.ts +3 -3
  272. package/src/index.ts +10 -9
  273. package/src/ingress/anthropic_messages.ts +12 -12
  274. package/src/ingress/anthropic_models.ts +1 -1
  275. package/src/ingress/chat_completions.ts +9 -9
  276. package/src/ingress/claude_code/request_context.ts +2 -2
  277. package/src/ingress/codex.ts +10 -10
  278. package/src/ingress/codex_models.ts +4 -4
  279. package/src/ingress/json.ts +1 -1
  280. package/src/ingress/models.ts +10 -10
  281. package/src/interaction/capabilities.ts +1 -1
  282. package/src/interaction/portable_reasoning_state.ts +1 -1
  283. package/src/interaction/provider_continuation_state.ts +1 -1
  284. package/src/interaction/tool_identity.ts +2 -2
  285. package/src/interaction/types.ts +3 -0
  286. package/src/models/context_limits.ts +1 -1
  287. package/src/models/execution_provider.ts +1 -1
  288. package/src/models/ids.ts +1 -1
  289. package/src/models/provider_defaults.ts +1 -1
  290. package/src/models/runtime_overrides.ts +1 -1
  291. package/src/observability/errors.ts +2 -2
  292. package/src/platform/platform.ts +36 -4
  293. package/src/protocol/input/anthropic_messages.ts +7 -7
  294. package/src/protocol/input/chat_completions.ts +5 -5
  295. package/src/protocol/input/chat_completions_validation.ts +4 -4
  296. package/src/protocol/input/openai_responses.ts +6 -6
  297. package/src/protocol/output/anthropic_messages.ts +3 -3
  298. package/src/protocol/output/anthropic_messages_output.ts +6 -4
  299. package/src/protocol/output/anthropic_messages_stream.ts +7 -7
  300. package/src/protocol/output/chat_completions.ts +13 -13
  301. package/src/protocol/output/chat_reasoning_detail.ts +1 -1
  302. package/src/protocol/output/openai_responses.ts +3 -3
  303. package/src/protocol/output/openai_responses_output.ts +4 -2
  304. package/src/protocol/output/openai_responses_stream.ts +6 -6
  305. package/src/protocol/output/sse_stream.ts +3 -3
  306. package/src/providers/anthropic_safeguards.ts +2 -2
  307. package/src/providers/aws_assume_role.ts +2 -2
  308. package/src/providers/cancel_estimate.ts +1 -1
  309. package/src/providers/execution.ts +17 -17
  310. package/src/providers/pi.ts +115 -41
  311. package/src/providers/pi_context.ts +6 -6
  312. package/src/providers/pi_options.ts +283 -453
  313. package/src/providers/pi_output.ts +6 -5
  314. package/src/providers/provider_attempt_runner.ts +1 -1
  315. package/src/providers/provider_call.ts +37 -18
  316. package/src/providers/provider_reported_cost.ts +138 -0
  317. package/src/providers/reasoning.ts +2 -2
  318. package/src/providers/stream_finalization.ts +10 -10
  319. package/src/providers/subscription_limits.ts +3 -3
  320. package/src/runtime/claude_code/auxiliary_routing.ts +5 -5
  321. package/src/runtime/customer_disconnect.ts +1 -1
  322. package/src/runtime/explicit_model.ts +31 -4
  323. package/src/runtime/harness_identity/conversation.ts +1 -1
  324. package/src/runtime/harness_identity/extract.ts +3 -3
  325. package/src/runtime/harness_identity/index.ts +2 -2
  326. package/src/runtime/prepare_routed_completion.ts +46 -10
  327. package/src/runtime/provider_stream_lifecycle.ts +1 -1
  328. package/src/runtime/provider_stream_outcome.ts +2 -2
  329. package/src/runtime/request_tags.ts +34 -0
  330. package/src/runtime/routed_completion.ts +13 -11
  331. package/src/runtime/routed_protocol.ts +2 -2
  332. package/src/runtime/routed_runtime.ts +38 -20
  333. package/src/runtime/routing_lease.ts +7 -7
  334. package/src/runtime/runtime_reporter.ts +3 -3
  335. package/src/self_host/main.ts +19 -14
  336. package/src/self_host/platform.ts +5 -5
  337. package/src/self_host/prefix_store.ts +2 -2
  338. package/src/self_host/resolve.ts +11 -11
  339. package/src/self_host/subscriptions/access.ts +2 -2
  340. package/src/self_host/subscriptions/http.ts +2 -2
  341. package/src/self_host/subscriptions/index.ts +4 -4
  342. package/src/self_host/subscriptions/store.ts +1 -1
  343. package/src/strategies/auto_routing_selector.ts +2 -2
  344. package/src/strategies/eval_relevance.ts +3 -3
  345. package/src/strategies/priority_selector.ts +1 -1
  346. package/src/strategies/route_decision.ts +7 -7
  347. package/src/strategies/routing.ts +11 -11
  348. package/src/strategies/selector_projection.ts +2 -2
  349. package/src/telemetry/billing_finalization.ts +3 -3
  350. package/src/telemetry/model_cost.ts +1 -1
  351. package/src/telemetry/prefix_state.ts +4 -4
  352. package/src/telemetry/report.ts +30 -25
  353. package/src/telemetry/requests/interaction_observability.ts +1 -1
  354. package/src/telemetry/requests/retained_interaction_request.ts +1 -1
  355. package/src/telemetry/skills/claude/catalog.ts +1 -1
  356. package/src/telemetry/skills/claude/file_reads.ts +6 -6
  357. package/src/telemetry/skills/claude/observations.ts +3 -3
  358. package/src/telemetry/skills/codex/catalog.ts +3 -3
  359. package/src/telemetry/skills/codex/exec_file_reads.ts +4 -4
  360. package/src/telemetry/skills/codex/explicit.ts +3 -3
  361. package/src/telemetry/skills/codex/file_reads.ts +5 -5
  362. package/src/telemetry/skills/observations.ts +7 -7
  363. package/src/telemetry/skills/pi.ts +3 -3
  364. package/src/telemetry/skills/shell_file_reads.ts +2 -2
  365. package/src/telemetry/skills/shell_words.ts +1 -1
  366. package/src/telemetry/tools/input.ts +1 -1
  367. package/src/telemetry/tools/observations.ts +9 -9
  368. package/src/telemetry/usage.ts +9 -5
  369. package/src/types.ts +15 -0
@@ -0,0 +1,180 @@
1
+ import { isBackgroundRequest, } from "../../interaction/types.js";
2
+ const SCHEMA_VERSION = 1;
3
+ export function extractInteractionObservability(request) {
4
+ const metadata = interactionObservabilityMetadata(request);
5
+ return {
6
+ requestKind: interactionRequestKind(request),
7
+ messageCount: metadata.item_counts.message,
8
+ hasTools: metadata.declared_tool_counts.total > 0,
9
+ metadata,
10
+ };
11
+ }
12
+ function interactionObservabilityMetadata(request) {
13
+ const itemCounts = {
14
+ total: request.items.length,
15
+ message: 0,
16
+ reasoning: 0,
17
+ tool_call: 0,
18
+ tool_result: 0,
19
+ hosted_tool_call: 0,
20
+ hosted_tool_result: 0,
21
+ };
22
+ const messageRoleCounts = {
23
+ system: 0,
24
+ developer: 0,
25
+ user: 0,
26
+ assistant: 0,
27
+ };
28
+ const toolCallCounts = {
29
+ function: 0,
30
+ custom: 0,
31
+ hosted: 0,
32
+ };
33
+ const itemContentModalityCounts = {
34
+ text: 0,
35
+ image: 0,
36
+ };
37
+ const continuationStateCounts = {
38
+ total: 0,
39
+ openai_reasoning: 0,
40
+ anthropic_thinking: 0,
41
+ anthropic_redacted_thinking: 0,
42
+ };
43
+ for (const item of request.items) {
44
+ if (item.type === "message") {
45
+ itemCounts.message += 1;
46
+ messageRoleCounts[item.role] += 1;
47
+ addContentModalities(itemContentModalityCounts, item.content);
48
+ continue;
49
+ }
50
+ if (item.type === "reasoning") {
51
+ itemCounts.reasoning += 1;
52
+ if (item.continuation) {
53
+ continuationStateCounts.total += 1;
54
+ continuationStateCounts[item.continuation.kind] += 1;
55
+ }
56
+ continue;
57
+ }
58
+ if (item.type === "tool_call") {
59
+ itemCounts.tool_call += 1;
60
+ toolCallCounts[item.kind] += 1;
61
+ continue;
62
+ }
63
+ if (item.type === "tool_result") {
64
+ itemCounts.tool_result += 1;
65
+ addContentModalities(itemContentModalityCounts, item.output);
66
+ continue;
67
+ }
68
+ if (item.type === "reasoning_configuration") {
69
+ continue;
70
+ }
71
+ if (item.providerType === "tool_search_result") {
72
+ itemCounts.hosted_tool_result += 1;
73
+ }
74
+ else {
75
+ itemCounts.hosted_tool_call += 1;
76
+ toolCallCounts.hosted += 1;
77
+ }
78
+ }
79
+ const declaredToolCounts = {
80
+ total: request.tools.length,
81
+ function: 0,
82
+ custom: 0,
83
+ hosted: 0,
84
+ };
85
+ for (const tool of request.tools) {
86
+ const kind = tool.kind === "server_tool" ? "hosted" : tool.kind === "client_tool" ? "function" : tool.kind;
87
+ declaredToolCounts[kind] += 1;
88
+ }
89
+ const controls = {};
90
+ if (request.reasoning?.effort !== undefined) {
91
+ controls.reasoning_effort = request.reasoning.effort;
92
+ }
93
+ if (request.reasoning?.enabled !== undefined) {
94
+ controls.reasoning_enabled = request.reasoning.enabled;
95
+ }
96
+ if (request.responseFormat !== undefined) {
97
+ controls.response_format = request.responseFormat.type;
98
+ }
99
+ if (request.toolChoice !== undefined) {
100
+ controls.tool_choice = toolChoiceKind(request.toolChoice);
101
+ }
102
+ if (request.parallelToolCalls !== undefined) {
103
+ controls.parallel_tool_calls = request.parallelToolCalls;
104
+ }
105
+ return {
106
+ schema_version: SCHEMA_VERSION,
107
+ ...(request.agentContext === undefined ? {} : { agent_context: request.agentContext }),
108
+ item_counts: itemCounts,
109
+ message_role_counts: messageRoleCounts,
110
+ tool_call_counts: toolCallCounts,
111
+ declared_tool_counts: declaredToolCounts,
112
+ item_content_modality_counts: itemContentModalityCounts,
113
+ continuation_state_counts: continuationStateCounts,
114
+ instructions_present: request.instructions !== undefined
115
+ || messageRoleCounts.system > 0
116
+ || messageRoleCounts.developer > 0,
117
+ reasoning_history_present: itemCounts.reasoning > 0,
118
+ prompt_cache_key_present: request.promptCacheKey !== undefined,
119
+ user_present: request.user !== undefined,
120
+ controls,
121
+ };
122
+ }
123
+ function interactionRequestKind(request) {
124
+ if (isBackgroundRequest(request) ||
125
+ request.requestPurpose === "memory_extraction")
126
+ return "other";
127
+ if (request.requestPurpose === "tool_continuation") {
128
+ return "tool_continuation";
129
+ }
130
+ let hasTrailingToolResult = false;
131
+ for (let index = request.items.length - 1; index >= 0; index -= 1) {
132
+ const item = request.items[index];
133
+ if (item.type === "tool_result") {
134
+ hasTrailingToolResult = true;
135
+ continue;
136
+ }
137
+ if (item.type === "tool_call"
138
+ || item.type === "hosted_tool_call"
139
+ || item.type === "reasoning") {
140
+ return hasTrailingToolResult ? "tool_continuation" : "other";
141
+ }
142
+ if (item.type !== "message")
143
+ continue;
144
+ if (item.role === "system" || item.role === "developer")
145
+ continue;
146
+ if (item.role === "user") {
147
+ if (hasMeaningfulUserContent(item.content))
148
+ return "user_message";
149
+ continue;
150
+ }
151
+ return hasTrailingToolResult ? "tool_continuation" : "other";
152
+ }
153
+ return hasTrailingToolResult ? "tool_continuation" : "other";
154
+ }
155
+ export function hasMeaningfulUserContent(content) {
156
+ if (typeof content === "string")
157
+ return content.trim().length > 0;
158
+ if (!Array.isArray(content))
159
+ return false;
160
+ return content.some((part) => {
161
+ if (part.type === "text")
162
+ return part.text.trim().length > 0;
163
+ return true;
164
+ });
165
+ }
166
+ function addContentModalities(counts, content) {
167
+ if (typeof content === "string") {
168
+ counts.text += 1;
169
+ return;
170
+ }
171
+ if (!Array.isArray(content))
172
+ return;
173
+ for (const part of content) {
174
+ if (part.type === "text" || part.type === "image")
175
+ counts[part.type] += 1;
176
+ }
177
+ }
178
+ function toolChoiceKind(choice) {
179
+ return typeof choice === "string" ? choice : choice.kind;
180
+ }
@@ -0,0 +1,8 @@
1
+ import type { InteractionRequest } from "../../interaction/types.js";
2
+ export declare const RETAINED_INTERACTION_REQUEST_FORMAT: "interaction_request_v1";
3
+ type RetainedInteractionRequest = {
4
+ format: typeof RETAINED_INTERACTION_REQUEST_FORMAT;
5
+ json: string;
6
+ };
7
+ export declare function encodeRetainedInteractionRequest(request: InteractionRequest): RetainedInteractionRequest;
8
+ export {};
@@ -0,0 +1,10 @@
1
+ export const RETAINED_INTERACTION_REQUEST_FORMAT = "interaction_request_v1";
2
+ // This is a normalized InteractionRequest snapshot, not the original wire
3
+ // body. Compatible fields may be added in v1; semantic or structural changes
4
+ // require a new persisted format and a matching reader.
5
+ export function encodeRetainedInteractionRequest(request) {
6
+ return {
7
+ format: RETAINED_INTERACTION_REQUEST_FORMAT,
8
+ json: JSON.stringify(request),
9
+ };
10
+ }
@@ -0,0 +1,2 @@
1
+ export declare function scrubSecrets(text: string, secrets?: readonly string[]): string;
2
+ export declare function scrubSecretValues(value: unknown, secrets: readonly string[]): unknown;
@@ -0,0 +1,31 @@
1
+ // Error text can quote a credential the provider echoed back, so it gets the
2
+ // `sk-` heuristic on top of exact-secret replacement.
3
+ export function scrubSecrets(text, secrets = []) {
4
+ return replaceSecrets(text.replace(/sk-[A-Za-z0-9+/_=-]{8,}/g, "sk-…"), secrets);
5
+ }
6
+ // Provider payloads carry opaque base64 (OpenAI `encrypted_content`, image
7
+ // data, signatures) where `sk-` occurs by chance. The regex heuristic would
8
+ // truncate that ciphertext and poison every later turn of the conversation,
9
+ // so structured payloads only get exact-secret replacement; error text is
10
+ // scrubbed with the heuristic at the client and log boundaries.
11
+ export function scrubSecretValues(value, secrets) {
12
+ if (typeof value === "string")
13
+ return replaceSecrets(value, secrets);
14
+ if (Array.isArray(value)) {
15
+ return value.map((item) => scrubSecretValues(item, secrets));
16
+ }
17
+ if (typeof value !== "object" || value === null)
18
+ return value;
19
+ return Object.fromEntries(Object.entries(value).map(([key, item]) => [
20
+ key,
21
+ scrubSecretValues(item, secrets),
22
+ ]));
23
+ }
24
+ function replaceSecrets(text, secrets) {
25
+ const uniqueSecrets = [...new Set(secrets.filter(Boolean))].sort((left, right) => right.length - left.length);
26
+ let scrubbed = text;
27
+ for (const secret of uniqueSecrets) {
28
+ scrubbed = scrubbed.replaceAll(secret, "…");
29
+ }
30
+ return scrubbed;
31
+ }
@@ -0,0 +1,6 @@
1
+ import type { InteractionRequest } from "../../../interaction/types.js";
2
+ export declare function claudeAvailableSkillNames(request: InteractionRequest): Set<string>;
3
+ /** Read only harness-owned catalogs when attributing model-emitted file reads. */
4
+ export declare function claudeSystemSkillNames(request: InteractionRequest): Set<string>;
5
+ export declare function claudeSkillCapabilityId(name: string): string;
6
+ export declare function normalizedClaudeSkillName(value: unknown): string | undefined;
@@ -0,0 +1,99 @@
1
+ const MAX_CAPABILITY_ID_CHARS = 512;
2
+ const MAX_SKILL_NAME_CHARS = 512;
3
+ const CAPABILITY_PREFIX = "claude:name:";
4
+ const UNSAFE_DISPLAY_CHARACTERS = /[\u0000-\u001f\u007f-\u009f\u202a-\u202e\u2066-\u2069]/u;
5
+ const SKILL_NAME = new RegExp("^[A-Za-z0-9][A-Za-z0-9_.@-]*"
6
+ + "(?::[A-Za-z0-9][A-Za-z0-9_.@-]*"
7
+ + "|(?:/[A-Za-z0-9][A-Za-z0-9_.@-]*)+:[A-Za-z0-9][A-Za-z0-9_.@-]*)?$");
8
+ const AVAILABLE_SKILLS_HEADING = "The following skills are available for use with the Skill tool:";
9
+ const REMINDER_SKILLS_HEADER = `<system-reminder>\n${AVAILABLE_SKILLS_HEADING}\n`;
10
+ const BARE_SKILLS_HEADER = `${AVAILABLE_SKILLS_HEADING}\n`;
11
+ const SYSTEM_REMINDER_END = "\n</system-reminder>";
12
+ export function claudeAvailableSkillNames(request) {
13
+ return parsedAvailableSkillNames(request, true);
14
+ }
15
+ /** Read only harness-owned catalogs when attributing model-emitted file reads. */
16
+ export function claudeSystemSkillNames(request) {
17
+ return parsedAvailableSkillNames(request, false);
18
+ }
19
+ export function claudeSkillCapabilityId(name) {
20
+ return `${CAPABILITY_PREFIX}${name}`;
21
+ }
22
+ export function normalizedClaudeSkillName(value) {
23
+ if (typeof value !== "string")
24
+ return undefined;
25
+ const withoutLeadingSlash = value.startsWith("/") ? value.slice(1) : value;
26
+ const normalized = withoutLeadingSlash.normalize("NFC").trim();
27
+ return normalized.length > 0
28
+ && normalized.length <= MAX_SKILL_NAME_CHARS
29
+ && normalized.length <= MAX_CAPABILITY_ID_CHARS - CAPABILITY_PREFIX.length
30
+ && SKILL_NAME.test(normalized)
31
+ && !UNSAFE_DISPLAY_CHARACTERS.test(normalized)
32
+ ? normalized
33
+ : undefined;
34
+ }
35
+ function parsedAvailableSkillNames(request, includeUserMessages) {
36
+ let latestNames = new Set();
37
+ for (const item of request.items) {
38
+ if (item.type !== "message"
39
+ || (item.role !== "system"
40
+ && item.role !== "developer"
41
+ && (!includeUserMessages || item.role !== "user")))
42
+ continue;
43
+ for (const part of item.content) {
44
+ if (part.type !== "text")
45
+ continue;
46
+ for (const section of availableSkillsSections(part.text, item.role)) {
47
+ const names = new Set();
48
+ let foundSkill = false;
49
+ for (const line of section.split("\n")) {
50
+ if (line === "" && !foundSkill)
51
+ continue;
52
+ if (line === "")
53
+ break;
54
+ if (!line.startsWith("- "))
55
+ continue;
56
+ const name = availableSkillName(line);
57
+ if (name === undefined)
58
+ break;
59
+ names.add(name);
60
+ foundSkill = true;
61
+ }
62
+ latestNames = names;
63
+ }
64
+ }
65
+ }
66
+ return latestNames;
67
+ }
68
+ function availableSkillsSections(text, role) {
69
+ const sections = [];
70
+ let cursor = 0;
71
+ while (cursor < text.length) {
72
+ const start = text.indexOf(REMINDER_SKILLS_HEADER, cursor);
73
+ if (start < 0)
74
+ break;
75
+ const sectionStart = start + REMINDER_SKILLS_HEADER.length;
76
+ const sectionEnd = text.indexOf(SYSTEM_REMINDER_END, sectionStart);
77
+ if (sectionEnd < 0)
78
+ break;
79
+ sections.push(text.slice(sectionStart, sectionEnd));
80
+ cursor = sectionEnd + SYSTEM_REMINDER_END.length;
81
+ }
82
+ if (role !== "user") {
83
+ let bareCursor = 0;
84
+ while (bareCursor < text.length) {
85
+ const start = text.indexOf(BARE_SKILLS_HEADER, bareCursor);
86
+ if (start < 0)
87
+ break;
88
+ const sectionStart = start + BARE_SKILLS_HEADER.length;
89
+ sections.push(text.slice(sectionStart));
90
+ bareCursor = sectionStart;
91
+ }
92
+ }
93
+ return sections;
94
+ }
95
+ function availableSkillName(line) {
96
+ const entry = line.slice(2);
97
+ const description = entry.indexOf(": ");
98
+ return normalizedClaudeSkillName(description < 0 ? entry : entry.slice(0, description));
99
+ }
@@ -0,0 +1,4 @@
1
+ import type { InteractionOutput, InteractionRequest } from "../../../interaction/types.js";
2
+ import type { SkillObservation } from "../observations.js";
3
+ /** Match model-emitted Claude Code `Read` calls to its trusted skill catalog. */
4
+ export declare function claudeFileReadObservations(request: InteractionRequest, output: InteractionOutput, limit: number): SkillObservation[];
@@ -0,0 +1,110 @@
1
+ import { interactionToolInput } from "../../tools/input.js";
2
+ import { claudeSkillCapabilityId, claudeSystemSkillNames, } from "./catalog.js";
3
+ import { normalizedAbsoluteSkillPath, skillPathSegments, } from "../paths.js";
4
+ import { readPathsFromShellCommand } from "../shell_file_reads.js";
5
+ const MAX_COMMAND_CHARS = 64 * 1024;
6
+ const SKILL_FILE_NAME = "SKILL.md";
7
+ const SKILLS_DIRECTORY_NAME = "skills";
8
+ const PRIMARY_WORKING_DIRECTORY_PREFIX = " - Primary working directory: ";
9
+ const UNSAFE_COMMAND_CHARACTERS = /[\u0000-\u0008\u000b\u000c\u000e-\u001f\u007f-\u009f\u202a-\u202e\u2066-\u2069]/u;
10
+ /** Match model-emitted Claude Code `Read` calls to its trusted skill catalog. */
11
+ export function claudeFileReadObservations(request, output, limit) {
12
+ if (limit <= 0
13
+ || request.sourceProtocol !== "anthropic_messages")
14
+ return [];
15
+ const declaredTools = new Set(request.tools.flatMap((tool) => tool.kind === "function" && tool.namespace === undefined
16
+ ? [tool.name]
17
+ : []));
18
+ if (!declaredTools.has("Read") && !declaredTools.has("Bash"))
19
+ return [];
20
+ const availableSkills = claudeSystemSkillNames(request);
21
+ if (availableSkills.size === 0)
22
+ return [];
23
+ const workingDirectory = declaredTools.has("Bash")
24
+ ? claudePrimaryWorkingDirectory(request)
25
+ : undefined;
26
+ const observedCapabilities = new Set();
27
+ const observations = [];
28
+ for (const item of output.items) {
29
+ for (const read of claudeReadCalls(item, declaredTools, workingDirectory)) {
30
+ const name = skillNameForReadPath(read.path, availableSkills);
31
+ if (name === undefined)
32
+ continue;
33
+ const capabilityId = claudeSkillCapabilityId(name);
34
+ if (observedCapabilities.has(capabilityId))
35
+ continue;
36
+ observedCapabilities.add(capabilityId);
37
+ observations.push({
38
+ eventType: "skill_load",
39
+ toolCallId: read.callId,
40
+ capabilityId,
41
+ observedName: name,
42
+ evidenceSource: "skill_file_read",
43
+ });
44
+ if (observations.length === limit)
45
+ return observations;
46
+ }
47
+ }
48
+ return observations;
49
+ }
50
+ function claudeReadCalls(item, declaredTools, workingDirectory) {
51
+ if (item.type !== "tool_call"
52
+ || item.kind !== "function"
53
+ || item.namespace !== undefined
54
+ || !declaredTools.has(item.name))
55
+ return [];
56
+ const input = interactionToolInput(item);
57
+ if (item.name === "Read") {
58
+ const path = normalizedAbsoluteSkillPath(input?.file_path);
59
+ return path === undefined ? [] : [{ callId: item.callId, path }];
60
+ }
61
+ if (item.name !== "Bash" || workingDirectory === undefined)
62
+ return [];
63
+ const command = input?.command;
64
+ if (typeof command !== "string"
65
+ || command.length === 0
66
+ || command.length > MAX_COMMAND_CHARS
67
+ || UNSAFE_COMMAND_CHARACTERS.test(command))
68
+ return [];
69
+ return readPathsFromShellCommand({
70
+ command,
71
+ workdir: workingDirectory.value,
72
+ }, workingDirectory.platform).map((path) => ({ callId: item.callId, path }));
73
+ }
74
+ function claudePrimaryWorkingDirectory(request) {
75
+ if (request.instructions === undefined)
76
+ return undefined;
77
+ const matches = request.instructions.split("\n").flatMap((line) => line.startsWith(PRIMARY_WORKING_DIRECTORY_PREFIX)
78
+ ? [line.slice(PRIMARY_WORKING_DIRECTORY_PREFIX.length)]
79
+ : []);
80
+ if (matches.length !== 1)
81
+ return undefined;
82
+ return normalizedAbsoluteSkillPath(matches[0]);
83
+ }
84
+ function skillNameForReadPath(path, availableSkills) {
85
+ const segments = skillPathSegments(path);
86
+ const fileName = segments.at(-1);
87
+ const directoryName = segments.at(-2);
88
+ if (fileName === undefined
89
+ || directoryName === undefined
90
+ || normalizedPathPart(fileName, path) !== normalizedPathPart(SKILL_FILE_NAME, path)
91
+ || !segments.slice(0, -2).some((segment) => normalizedPathPart(segment, path)
92
+ === normalizedPathPart(SKILLS_DIRECTORY_NAME, path)))
93
+ return undefined;
94
+ let match;
95
+ for (const name of availableSkills) {
96
+ const separator = name.lastIndexOf(":");
97
+ const pathName = separator < 0 ? name : name.slice(separator + 1);
98
+ if (normalizedPathPart(pathName, path) !== normalizedPathPart(directoryName, path)) {
99
+ continue;
100
+ }
101
+ if (match !== undefined)
102
+ return undefined;
103
+ match = name;
104
+ }
105
+ return match;
106
+ }
107
+ function normalizedPathPart(value, path) {
108
+ const normalized = value.normalize("NFC");
109
+ return path.platform === "windows" ? normalized.toLowerCase() : normalized;
110
+ }
@@ -0,0 +1,3 @@
1
+ import type { InteractionRequest } from "../../../interaction/types.js";
2
+ import type { SkillObservation } from "../observations.js";
3
+ export declare function claudeSkillObservations(request: InteractionRequest, limit: number): SkillObservation[];