@sriinnu/fiche 0.0.0-stage → 0.19.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 (196) hide show
  1. package/CHANGELOG.md +134 -0
  2. package/LICENSE +22 -0
  3. package/NOTICE +13 -0
  4. package/PRIVACY.md +41 -0
  5. package/README.md +288 -2
  6. package/SECURITY.md +53 -0
  7. package/assets/JETBRAINS_MONO_LICENSE.txt +89 -0
  8. package/assets/SPLEEN_LICENSE.txt +24 -0
  9. package/assets/UNIFONT_LICENSE.txt +476 -0
  10. package/assets/fiche-logo-dark.svg +61 -0
  11. package/assets/fiche-logo-light.svg +61 -0
  12. package/assets/fiche-logo.svg +71 -0
  13. package/assets/fiche-mark.svg +48 -0
  14. package/bin/cli.js +7 -0
  15. package/bin/mcp.js +8 -0
  16. package/dist/calibrate.d.ts +30 -0
  17. package/dist/calibrate.js +588 -0
  18. package/dist/core/anthropic-vision.d.ts +28 -0
  19. package/dist/core/anthropic-vision.js +34 -0
  20. package/dist/core/applicability.d.ts +63 -0
  21. package/dist/core/applicability.js +151 -0
  22. package/dist/core/atlas-gray-jbmono10.d.ts +26 -0
  23. package/dist/core/atlas-gray-jbmono10.js +64 -0
  24. package/dist/core/atlas-gray-jbmono12.d.ts +26 -0
  25. package/dist/core/atlas-gray-jbmono12.js +64 -0
  26. package/dist/core/atlas-gray-jbmono14.d.ts +26 -0
  27. package/dist/core/atlas-gray-jbmono14.js +64 -0
  28. package/dist/core/atlas-gray.d.ts +26 -0
  29. package/dist/core/atlas-gray.js +64 -0
  30. package/dist/core/atlas-jbmono10.d.ts +34 -0
  31. package/dist/core/atlas-jbmono10.js +71 -0
  32. package/dist/core/atlas-jbmono12.d.ts +34 -0
  33. package/dist/core/atlas-jbmono12.js +71 -0
  34. package/dist/core/atlas-jbmono14.d.ts +34 -0
  35. package/dist/core/atlas-jbmono14.js +71 -0
  36. package/dist/core/atlas.d.ts +34 -0
  37. package/dist/core/atlas.js +71 -0
  38. package/dist/core/baseline.d.ts +121 -0
  39. package/dist/core/baseline.js +200 -0
  40. package/dist/core/calibration.d.ts +86 -0
  41. package/dist/core/calibration.js +547 -0
  42. package/dist/core/casi-delta.d.ts +63 -0
  43. package/dist/core/casi-delta.js +1271 -0
  44. package/dist/core/claude-model-profiles.d.ts +53 -0
  45. package/dist/core/claude-model-profiles.js +160 -0
  46. package/dist/core/client-tool-round.d.ts +31 -0
  47. package/dist/core/client-tool-round.js +58 -0
  48. package/dist/core/codex-cache.d.ts +20 -0
  49. package/dist/core/codex-cache.js +59 -0
  50. package/dist/core/context-mmu.d.ts +350 -0
  51. package/dist/core/context-mmu.js +3028 -0
  52. package/dist/core/cpt-fit.d.ts +70 -0
  53. package/dist/core/cpt-fit.js +197 -0
  54. package/dist/core/env.d.ts +8 -0
  55. package/dist/core/env.js +15 -0
  56. package/dist/core/export.d.ts +127 -0
  57. package/dist/core/export.js +385 -0
  58. package/dist/core/factsheet.d.ts +77 -0
  59. package/dist/core/factsheet.js +494 -0
  60. package/dist/core/gemini-model-profiles.d.ts +20 -0
  61. package/dist/core/gemini-model-profiles.js +134 -0
  62. package/dist/core/google.d.ts +76 -0
  63. package/dist/core/google.js +1380 -0
  64. package/dist/core/gpt-model-profiles.d.ts +218 -0
  65. package/dist/core/gpt-model-profiles.js +570 -0
  66. package/dist/core/gpt-tokens.d.ts +14 -0
  67. package/dist/core/gpt-tokens.js +165 -0
  68. package/dist/core/history.d.ts +197 -0
  69. package/dist/core/history.js +1003 -0
  70. package/dist/core/index.d.ts +16 -0
  71. package/dist/core/index.js +16 -0
  72. package/dist/core/library.d.ts +80 -0
  73. package/dist/core/library.js +131 -0
  74. package/dist/core/measurement.d.ts +34 -0
  75. package/dist/core/measurement.js +280 -0
  76. package/dist/core/messages-chat-bridge.d.ts +23 -0
  77. package/dist/core/messages-chat-bridge.js +747 -0
  78. package/dist/core/messages-responses-bridge.d.ts +11 -0
  79. package/dist/core/messages-responses-bridge.js +893 -0
  80. package/dist/core/openai-history.d.ts +184 -0
  81. package/dist/core/openai-history.js +1279 -0
  82. package/dist/core/openai-savings.d.ts +57 -0
  83. package/dist/core/openai-savings.js +116 -0
  84. package/dist/core/openai.d.ts +68 -0
  85. package/dist/core/openai.js +2523 -0
  86. package/dist/core/pin.d.ts +199 -0
  87. package/dist/core/pin.js +1353 -0
  88. package/dist/core/png.d.ts +14 -0
  89. package/dist/core/png.js +188 -0
  90. package/dist/core/prefix-tape.d.ts +102 -0
  91. package/dist/core/prefix-tape.js +315 -0
  92. package/dist/core/price-id.d.ts +10 -0
  93. package/dist/core/price-id.js +26 -0
  94. package/dist/core/prices.generated.d.ts +36 -0
  95. package/dist/core/prices.generated.js +369 -0
  96. package/dist/core/pricing.d.ts +134 -0
  97. package/dist/core/pricing.js +335 -0
  98. package/dist/core/profile-base.d.ts +30 -0
  99. package/dist/core/profile-base.js +67 -0
  100. package/dist/core/provider-router.d.ts +51 -0
  101. package/dist/core/provider-router.js +121 -0
  102. package/dist/core/proxy.d.ts +252 -0
  103. package/dist/core/proxy.js +2929 -0
  104. package/dist/core/reader-tier.d.ts +24 -0
  105. package/dist/core/reader-tier.js +118 -0
  106. package/dist/core/render.d.ts +280 -0
  107. package/dist/core/render.js +1302 -0
  108. package/dist/core/request-guard.d.ts +31 -0
  109. package/dist/core/request-guard.js +126 -0
  110. package/dist/core/request-transform.d.ts +43 -0
  111. package/dist/core/request-transform.js +173 -0
  112. package/dist/core/schema-compiler.d.ts +64 -0
  113. package/dist/core/schema-compiler.js +1696 -0
  114. package/dist/core/schema-strip.d.ts +29 -0
  115. package/dist/core/schema-strip.js +173 -0
  116. package/dist/core/session-state.d.ts +219 -0
  117. package/dist/core/session-state.js +929 -0
  118. package/dist/core/stage-plugins.d.ts +45 -0
  119. package/dist/core/stage-plugins.js +205 -0
  120. package/dist/core/text-history.d.ts +74 -0
  121. package/dist/core/text-history.js +612 -0
  122. package/dist/core/text-hygiene.d.ts +160 -0
  123. package/dist/core/text-hygiene.js +2259 -0
  124. package/dist/core/toon.d.ts +29 -0
  125. package/dist/core/toon.js +425 -0
  126. package/dist/core/tracker.d.ts +223 -0
  127. package/dist/core/tracker.js +290 -0
  128. package/dist/core/transform.d.ts +589 -0
  129. package/dist/core/transform.js +3153 -0
  130. package/dist/core/types.d.ts +87 -0
  131. package/dist/core/types.js +8 -0
  132. package/dist/core/upstream-hosts.d.ts +127 -0
  133. package/dist/core/upstream-hosts.js +398 -0
  134. package/dist/core/vision-cost.d.ts +63 -0
  135. package/dist/core/vision-cost.js +137 -0
  136. package/dist/dashboard/fragments.d.ts +87 -0
  137. package/dist/dashboard/fragments.js +1515 -0
  138. package/dist/dashboard/types.d.ts +217 -0
  139. package/dist/dashboard/types.js +3 -0
  140. package/dist/dashboard/vendor.d.ts +3 -0
  141. package/dist/dashboard/vendor.js +6 -0
  142. package/dist/dashboard.d.ts +372 -0
  143. package/dist/dashboard.js +2731 -0
  144. package/dist/export-collect.d.ts +36 -0
  145. package/dist/export-collect.js +59 -0
  146. package/dist/file-tracker.d.ts +42 -0
  147. package/dist/file-tracker.js +234 -0
  148. package/dist/kosha-sync.d.ts +74 -0
  149. package/dist/kosha-sync.js +272 -0
  150. package/dist/launchd-socket.d.ts +22 -0
  151. package/dist/launchd-socket.js +210 -0
  152. package/dist/mcp/cli.d.ts +2 -0
  153. package/dist/mcp/cli.js +55 -0
  154. package/dist/mcp/server.d.ts +48 -0
  155. package/dist/mcp/server.js +987 -0
  156. package/dist/mmu-store.d.ts +31 -0
  157. package/dist/mmu-store.js +179 -0
  158. package/dist/node-fetch.d.ts +22 -0
  159. package/dist/node-fetch.js +489 -0
  160. package/dist/node.d.ts +9 -0
  161. package/dist/node.js +244396 -0
  162. package/dist/request-decoding.d.ts +30 -0
  163. package/dist/request-decoding.js +85 -0
  164. package/dist/sessions.d.ts +179 -0
  165. package/dist/sessions.js +837 -0
  166. package/dist/stats.d.ts +114 -0
  167. package/dist/stats.js +439 -0
  168. package/dist/turn-report.d.ts +65 -0
  169. package/dist/turn-report.js +724 -0
  170. package/dist/warp/app-launch.d.ts +26 -0
  171. package/dist/warp/app-launch.js +155 -0
  172. package/dist/warp/ca.d.ts +74 -0
  173. package/dist/warp/ca.js +416 -0
  174. package/dist/warp/connect.d.ts +42 -0
  175. package/dist/warp/connect.js +686 -0
  176. package/dist/warp/der.d.ts +57 -0
  177. package/dist/warp/der.js +151 -0
  178. package/dist/warp/index.d.ts +79 -0
  179. package/dist/warp/index.js +650 -0
  180. package/dist/warp/resolve.d.ts +12 -0
  181. package/dist/warp/resolve.js +49 -0
  182. package/dist/warp/route.d.ts +71 -0
  183. package/dist/warp/route.js +134 -0
  184. package/dist/worker.d.ts +71 -0
  185. package/dist/worker.js +174 -0
  186. package/docs/SECURITY_MODEL.md +84 -0
  187. package/package.json +122 -4
  188. package/plugins/fiche-companion/README.md +42 -0
  189. package/plugins/fiche-companion/assets/logo.svg +48 -0
  190. package/plugins/fiche-companion/hooks.json +11 -0
  191. package/plugins/fiche-companion/mcp_config.json +8 -0
  192. package/plugins/fiche-companion/plugin.json +18 -0
  193. package/plugins/fiche-companion/scripts/claude-statusline.mjs +35 -0
  194. package/plugins/fiche-companion/scripts/post-invocation.mjs +122 -0
  195. package/plugins/fiche-companion/scripts/resolve-turn-report.mjs +132 -0
  196. package/plugins/fiche-companion/skills/fiche/SKILL.md +61 -0
@@ -0,0 +1,290 @@
1
+ /**
2
+ * Runtime-agnostic event sink for inkling.
3
+ * Per-request JSONL record — same shape on Node (file) and Workers (console.log).
4
+ * Never emits raw text; only sizes, counts, durations, env fields, and sha256 prefixes.
5
+ */
6
+ import { bytesToBase64 } from './png.js';
7
+ /** Max inline base64 body per JSONL row (32 KiB). Larger goes to sidecar (Node) or is dropped (Workers). */
8
+ export const TRACK_BODY_INLINE_MAX = 32 * 1024;
9
+ /** Redact Bearer and `sk-*` API tokens from error/telemetry snippets before persisting or logging. */
10
+ export function redactSecrets(text) {
11
+ return text
12
+ .replace(/(Bearer\s+)[A-Za-z0-9._~+/=-]{6,}/gi, '$1[REDACTED]')
13
+ .replace(/\bsk-(?:ant-[A-Za-z0-9._-]+|proj-[A-Za-z0-9._-]+|[A-Za-z0-9._-]{8,})/gi, '[REDACTED]');
14
+ }
15
+ /** Convert a ProxyEvent to its flat persisted shape. Shared in core so Node/Worker hosts stay in sync. */
16
+ export function toTrackEvent(ev) {
17
+ const info = ev.info;
18
+ const env = info?.env;
19
+ const u = ev.usage;
20
+ const out = {
21
+ ts: new Date().toISOString(),
22
+ method: ev.method,
23
+ path: ev.path,
24
+ status: ev.status,
25
+ duration_ms: ev.durationMs,
26
+ };
27
+ if (ev.model)
28
+ out.model = ev.model;
29
+ if (ev.accountingProvider)
30
+ out.accounting_provider = ev.accountingProvider;
31
+ if (ev.firstByteMs !== undefined)
32
+ out.first_byte_ms = ev.firstByteMs;
33
+ if (ev.transformMs !== undefined)
34
+ out.transform_ms = ev.transformMs;
35
+ if (ev.error)
36
+ out.error = redactSecrets(ev.error);
37
+ if (ev.errorBody)
38
+ out.error_body = redactSecrets(ev.errorBody);
39
+ if (ev.reqBodySha8)
40
+ out.req_body_sha8 = ev.reqBodySha8;
41
+ // Body sample: sidecar path (Node) > inline base64 if it fits > drop (Workers, oversized).
42
+ if (ev.reqBodySamplePath) {
43
+ out.req_body_sample_path = ev.reqBodySamplePath;
44
+ }
45
+ else if (ev.reqBodyGz && ev.reqBodyGz.byteLength > 0) {
46
+ const b64 = bytesToBase64(ev.reqBodyGz);
47
+ if (b64.length <= TRACK_BODY_INLINE_MAX) {
48
+ out.req_body_sample_b64 = b64;
49
+ }
50
+ }
51
+ if (info) {
52
+ if (info.compressed !== undefined)
53
+ out.compressed = info.compressed;
54
+ if (info.reason)
55
+ out.reason = info.reason;
56
+ if (info.origChars !== undefined)
57
+ out.orig_chars = info.origChars;
58
+ if (info.compressedChars !== undefined && info.compressedChars > 0) {
59
+ out.compressed_chars = info.compressedChars;
60
+ }
61
+ if (info.imageCount !== undefined)
62
+ out.image_count = info.imageCount;
63
+ // Only when nonzero: a wire without client images is the common case and
64
+ // should not pay a key per event.
65
+ if ((info.nativeImages ?? 0) > 0)
66
+ out.native_images = info.nativeImages;
67
+ if ((info.imageBudgetSkips ?? 0) > 0)
68
+ out.image_budget_skips = info.imageBudgetSkips;
69
+ // Emit only when it disagrees with the render counter: equality is the common
70
+ // case and a per-event key for "nothing to see" is noise.
71
+ if (info.wireImages !== undefined
72
+ && info.wireImages !== (info.imageCount ?? 0) + (info.nativeImages ?? 0)) {
73
+ out.wire_images = info.wireImages;
74
+ }
75
+ if (info.imageBytes !== undefined)
76
+ out.image_bytes = info.imageBytes;
77
+ if (info.imagePixels !== undefined && info.imagePixels > 0) {
78
+ out.image_pixels = info.imagePixels;
79
+ }
80
+ if (info.imageTokens !== undefined && info.imageTokens > 0) {
81
+ out.image_tokens = info.imageTokens;
82
+ }
83
+ if ((info.textHygieneSavedChars ?? 0) > 0) {
84
+ out.text_hygiene_saved_chars = info.textHygieneSavedChars;
85
+ }
86
+ if ((info.textHygieneSavedTokens ?? 0) > 0) {
87
+ out.text_hygiene_saved_tokens = info.textHygieneSavedTokens;
88
+ }
89
+ if ((info.textHygieneBlocks ?? 0) > 0) {
90
+ out.text_hygiene_blocks = info.textHygieneBlocks;
91
+ }
92
+ if (info.textHygieneStages && info.textHygieneStages.length > 0) {
93
+ out.text_hygiene_stages = [...info.textHygieneStages];
94
+ }
95
+ if (info.cliffAvoided && info.cliffAvoided.savedUsd > 0) {
96
+ out.cliff_avoided_at = info.cliffAvoided.at;
97
+ out.cliff_saved_usd = Math.round(info.cliffAvoided.savedUsd * 1e6) / 1e6;
98
+ }
99
+ if (info.baselineImagedTokens !== undefined && info.baselineImagedTokens > 0) {
100
+ out.baseline_imaged_tokens = info.baselineImagedTokens;
101
+ }
102
+ if (info.nativeInjectedTokens !== undefined && info.nativeInjectedTokens > 0) {
103
+ out.native_injected_tokens = info.nativeInjectedTokens;
104
+ }
105
+ if (info.outgoingTextChars !== undefined && info.outgoingTextChars > 0) {
106
+ out.outgoing_text_chars = info.outgoingTextChars;
107
+ }
108
+ if (info.pinChars !== undefined && info.pinChars > 0) {
109
+ out.pin_chars = info.pinChars;
110
+ }
111
+ if (info.responsesComposition) {
112
+ out.responses_composition = info.responsesComposition;
113
+ }
114
+ if (info.staticChars !== undefined)
115
+ out.static_chars = info.staticChars;
116
+ if (info.dynamicChars !== undefined)
117
+ out.dynamic_chars = info.dynamicChars;
118
+ if (info.dynamicBlockCount !== undefined)
119
+ out.dynamic_block_count = info.dynamicBlockCount;
120
+ if (info.toolResultImgs !== undefined)
121
+ out.tool_result_imgs = info.toolResultImgs;
122
+ if (info.toolDocsChars !== undefined)
123
+ out.tool_docs_chars = info.toolDocsChars;
124
+ if (info.truncatedToolResults !== undefined && info.truncatedToolResults > 0) {
125
+ out.truncated_tool_results = info.truncatedToolResults;
126
+ }
127
+ if (info.omittedChars !== undefined && info.omittedChars > 0) {
128
+ out.omitted_chars = info.omittedChars;
129
+ }
130
+ if (info.collapsedTurns !== undefined && info.collapsedTurns > 0) {
131
+ out.collapsed_turns = info.collapsedTurns;
132
+ }
133
+ if (info.collapsedChars !== undefined && info.collapsedChars > 0) {
134
+ out.collapsed_chars = info.collapsedChars;
135
+ }
136
+ if (info.collapsedImages !== undefined && info.collapsedImages > 0) {
137
+ out.collapsed_images = info.collapsedImages;
138
+ }
139
+ if (info.historyReason !== undefined) {
140
+ out.history_reason = info.historyReason;
141
+ }
142
+ if (info.historyFreezeStep !== undefined)
143
+ out.history_freeze_step = info.historyFreezeStep;
144
+ if (info.historyBudgetTrimmed)
145
+ out.history_budget_trimmed = true;
146
+ if (info.historyPackFill)
147
+ out.history_pack_fill = true;
148
+ if (info.historySplitAdjacentPairs)
149
+ out.history_split_adjacent_pairs = true;
150
+ if (info.droppedChars !== undefined && info.droppedChars > 0) {
151
+ out.dropped_chars = info.droppedChars;
152
+ }
153
+ if (info.droppedCodepointsTop && Object.keys(info.droppedCodepointsTop).length > 0) {
154
+ out.dropped_codepoints_top = info.droppedCodepointsTop;
155
+ }
156
+ if (info.passthroughReasons) {
157
+ const pr = info.passthroughReasons;
158
+ if (Object.values(pr).some((n) => (n ?? 0) > 0)) {
159
+ out.passthrough_reasons = pr;
160
+ }
161
+ }
162
+ if (info.bucketChars && Object.keys(info.bucketChars).length > 0) {
163
+ // Omit empty object so noop-pass requests stay lean; presence means at least one gate fired.
164
+ out.bucket_chars = info.bucketChars;
165
+ }
166
+ if (info.historyTextChars !== undefined && info.historyTextChars > 0) {
167
+ out.history_text_chars = info.historyTextChars;
168
+ }
169
+ if (info.historyImageSha) {
170
+ out.history_image_sha8 = info.historyImageSha;
171
+ }
172
+ if (info.cachePrefixSha8)
173
+ out.cache_prefix_sha8 = info.cachePrefixSha8;
174
+ if (info.cachePrefixBytes !== undefined)
175
+ out.cache_prefix_bytes = info.cachePrefixBytes;
176
+ if (info.cachePrefixToolsSha8)
177
+ out.cache_prefix_tools_sha8 = info.cachePrefixToolsSha8;
178
+ if (info.cachePrefixSystemSha8)
179
+ out.cache_prefix_system_sha8 = info.cachePrefixSystemSha8;
180
+ if (info.cachePrefixHeadSha8)
181
+ out.cache_prefix_head_sha8 = info.cachePrefixHeadSha8;
182
+ if (info.cachePrefixMarkedSha8)
183
+ out.cache_prefix_marked_sha8 = info.cachePrefixMarkedSha8;
184
+ if (info.cachePrefixMarkedBytes !== undefined)
185
+ out.cache_prefix_marked_bytes = info.cachePrefixMarkedBytes;
186
+ if (info.cachePrefixMarkerPos)
187
+ out.cache_prefix_marker_pos = info.cachePrefixMarkerPos;
188
+ if (info.unknownStaticTags && info.unknownStaticTags.length > 0)
189
+ out.unknown_static_tags = info.unknownStaticTags;
190
+ if (info.churningStaticTags && info.churningStaticTags.length > 0)
191
+ out.churning_static_tags = info.churningStaticTags;
192
+ if (info.systemSha8)
193
+ out.system_sha8 = info.systemSha8;
194
+ if (info.firstUserSha8)
195
+ out.first_user_sha8 = info.firstUserSha8;
196
+ if (info.sessionKey)
197
+ out.session_key = info.sessionKey;
198
+ if (info.sessionKeySource)
199
+ out.session_key_source = info.sessionKeySource;
200
+ if (info.baselineTokens !== undefined && info.baselineTokens > 0) {
201
+ out.baseline_tokens = info.baselineTokens;
202
+ }
203
+ if (info.baselineCacheableTokens !== undefined
204
+ && info.baselineCacheableTokens > 0) {
205
+ out.baseline_cacheable_tokens = info.baselineCacheableTokens;
206
+ }
207
+ if (info.baselineProbeStatus !== undefined) {
208
+ out.baseline_probe_status = info.baselineProbeStatus;
209
+ }
210
+ if (info.baselineProbeError !== undefined) {
211
+ out.baseline_probe_error = redactSecrets(info.baselineProbeError);
212
+ }
213
+ if (info.threadContinue)
214
+ out.thread_continue = true;
215
+ }
216
+ if (env) {
217
+ if (env.cwd)
218
+ out.cwd = env.cwd;
219
+ if (env.isGitRepo !== undefined)
220
+ out.is_git_repo = env.isGitRepo;
221
+ if (env.gitBranch)
222
+ out.git_branch = env.gitBranch;
223
+ if (env.platform)
224
+ out.platform = env.platform;
225
+ if (env.osVersion)
226
+ out.os_version = env.osVersion;
227
+ if (env.today)
228
+ out.today = env.today;
229
+ }
230
+ if (u) {
231
+ if (u.input_tokens !== undefined)
232
+ out.input_tokens = u.input_tokens;
233
+ if (u.output_tokens !== undefined)
234
+ out.output_tokens = u.output_tokens;
235
+ if (u.cache_creation_input_tokens !== undefined)
236
+ out.cache_create_tokens = u.cache_creation_input_tokens;
237
+ if (u.cache_read_input_tokens !== undefined)
238
+ out.cache_read_tokens = u.cache_read_input_tokens;
239
+ if (u.cached_tokens !== undefined)
240
+ out.cached_tokens = u.cached_tokens;
241
+ if (u.cache_write_tokens !== undefined)
242
+ out.cache_write_tokens = u.cache_write_tokens;
243
+ // cache_creation splits cache_creation_input_tokens across 5-min (1.25x) and 1-hour (2x) tiers.
244
+ if (u.cache_creation) {
245
+ if (u.cache_creation.ephemeral_5m_input_tokens !== undefined)
246
+ out.cache_create_5m_tokens = u.cache_creation.ephemeral_5m_input_tokens;
247
+ if (u.cache_creation.ephemeral_1h_input_tokens !== undefined)
248
+ out.cache_create_1h_tokens = u.cache_creation.ephemeral_1h_input_tokens;
249
+ }
250
+ if (u.server_tool_use?.web_search_requests !== undefined)
251
+ out.web_search_requests = u.server_tool_use.web_search_requests;
252
+ }
253
+ const m = ev.measurement;
254
+ if (m) {
255
+ if (m.textChars > 0)
256
+ out.text_chars_measured = m.textChars;
257
+ if (m.thinkingChars > 0)
258
+ out.thinking_chars_measured = m.thinkingChars;
259
+ if (m.toolUseChars > 0)
260
+ out.tool_use_chars_measured = m.toolUseChars;
261
+ if (m.redactedBlockCount > 0)
262
+ out.redacted_block_count_measured = m.redactedBlockCount;
263
+ }
264
+ if (ev.stopReason) {
265
+ out.stop_reason = ev.stopReason;
266
+ if (SAFETY_STOP_REASONS.has(ev.stopReason))
267
+ out.safety_flagged = true;
268
+ }
269
+ return out;
270
+ }
271
+ /** Stop reasons that mean a safety classifier fired (Anthropic / OpenAI spellings). */
272
+ const SAFETY_STOP_REASONS = new Set(['refusal', 'content_filter']);
273
+ /** Writes one JSON line per event. Worker host uses console.log; Node host uses a file-backed variant. */
274
+ export class JsonLogTracker {
275
+ sink;
276
+ constructor(sink = (s) => console.log(s)) {
277
+ this.sink = sink;
278
+ }
279
+ emit(ev) {
280
+ try {
281
+ this.sink(JSON.stringify(ev));
282
+ }
283
+ catch {
284
+ /* swallow — tracker must never break a request */
285
+ }
286
+ }
287
+ }
288
+ /** Tracker that drops everything. Used when INKLING_TRACK=0. */
289
+ export const noopTracker = { emit() { } };
290
+ //# sourceMappingURL=tracker.js.map