@molecule/app-ide-panel-logic 0.0.0-stage → 0.0.1-stage

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 (147) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +2925 -2
  3. package/dist/chatTimelineOrdering.d.ts +50 -0
  4. package/dist/chatTimelineOrdering.d.ts.map +1 -0
  5. package/dist/chatTimelineOrdering.js +46 -0
  6. package/dist/chatTimelineOrdering.js.map +1 -0
  7. package/dist/command-metadata.d.ts +117 -0
  8. package/dist/command-metadata.d.ts.map +1 -0
  9. package/dist/command-metadata.js +271 -0
  10. package/dist/command-metadata.js.map +1 -0
  11. package/dist/components/activity-utilities.d.ts +107 -0
  12. package/dist/components/activity-utilities.d.ts.map +1 -0
  13. package/dist/components/activity-utilities.js +154 -0
  14. package/dist/components/activity-utilities.js.map +1 -0
  15. package/dist/components/chat-autocommit-utilities.d.ts +172 -0
  16. package/dist/components/chat-autocommit-utilities.d.ts.map +1 -0
  17. package/dist/components/chat-autocommit-utilities.js +185 -0
  18. package/dist/components/chat-autocommit-utilities.js.map +1 -0
  19. package/dist/components/chat-card-style.d.ts +81 -0
  20. package/dist/components/chat-card-style.d.ts.map +1 -0
  21. package/dist/components/chat-card-style.js +78 -0
  22. package/dist/components/chat-card-style.js.map +1 -0
  23. package/dist/components/chat-commands.d.ts +17 -0
  24. package/dist/components/chat-commands.d.ts.map +1 -0
  25. package/dist/components/chat-commands.js +17 -0
  26. package/dist/components/chat-commands.js.map +1 -0
  27. package/dist/components/chat-commit-utilities.d.ts +29 -0
  28. package/dist/components/chat-commit-utilities.d.ts.map +1 -0
  29. package/dist/components/chat-commit-utilities.js +31 -0
  30. package/dist/components/chat-commit-utilities.js.map +1 -0
  31. package/dist/components/chat-cost-utilities.d.ts +62 -0
  32. package/dist/components/chat-cost-utilities.d.ts.map +1 -0
  33. package/dist/components/chat-cost-utilities.js +66 -0
  34. package/dist/components/chat-cost-utilities.js.map +1 -0
  35. package/dist/components/chat-effort-utilities.d.ts +104 -0
  36. package/dist/components/chat-effort-utilities.d.ts.map +1 -0
  37. package/dist/components/chat-effort-utilities.js +99 -0
  38. package/dist/components/chat-effort-utilities.js.map +1 -0
  39. package/dist/components/chat-help-utilities.d.ts +89 -0
  40. package/dist/components/chat-help-utilities.d.ts.map +1 -0
  41. package/dist/components/chat-help-utilities.js +131 -0
  42. package/dist/components/chat-help-utilities.js.map +1 -0
  43. package/dist/components/chat-model-mode-utilities.d.ts +169 -0
  44. package/dist/components/chat-model-mode-utilities.d.ts.map +1 -0
  45. package/dist/components/chat-model-mode-utilities.js +221 -0
  46. package/dist/components/chat-model-mode-utilities.js.map +1 -0
  47. package/dist/components/chat-models-utilities.d.ts +162 -0
  48. package/dist/components/chat-models-utilities.d.ts.map +1 -0
  49. package/dist/components/chat-models-utilities.js +302 -0
  50. package/dist/components/chat-models-utilities.js.map +1 -0
  51. package/dist/components/chat-report-utilities.d.ts +149 -0
  52. package/dist/components/chat-report-utilities.d.ts.map +1 -0
  53. package/dist/components/chat-report-utilities.js +151 -0
  54. package/dist/components/chat-report-utilities.js.map +1 -0
  55. package/dist/components/chat-scripts-utilities.d.ts +185 -0
  56. package/dist/components/chat-scripts-utilities.d.ts.map +1 -0
  57. package/dist/components/chat-scripts-utilities.js +199 -0
  58. package/dist/components/chat-scripts-utilities.js.map +1 -0
  59. package/dist/components/chat-settings-utilities.d.ts +72 -0
  60. package/dist/components/chat-settings-utilities.d.ts.map +1 -0
  61. package/dist/components/chat-settings-utilities.js +56 -0
  62. package/dist/components/chat-settings-utilities.js.map +1 -0
  63. package/dist/components/chat-share-utilities.d.ts +110 -0
  64. package/dist/components/chat-share-utilities.d.ts.map +1 -0
  65. package/dist/components/chat-share-utilities.js +90 -0
  66. package/dist/components/chat-share-utilities.js.map +1 -0
  67. package/dist/components/chat-skills-utilities.d.ts +242 -0
  68. package/dist/components/chat-skills-utilities.d.ts.map +1 -0
  69. package/dist/components/chat-skills-utilities.js +433 -0
  70. package/dist/components/chat-skills-utilities.js.map +1 -0
  71. package/dist/components/chat-stream-utilities.d.ts +74 -0
  72. package/dist/components/chat-stream-utilities.d.ts.map +1 -0
  73. package/dist/components/chat-stream-utilities.js +103 -0
  74. package/dist/components/chat-stream-utilities.js.map +1 -0
  75. package/dist/components/chat-timestamps-utilities.d.ts +123 -0
  76. package/dist/components/chat-timestamps-utilities.d.ts.map +1 -0
  77. package/dist/components/chat-timestamps-utilities.js +177 -0
  78. package/dist/components/chat-timestamps-utilities.js.map +1 -0
  79. package/dist/components/chat-tips-utilities.d.ts +108 -0
  80. package/dist/components/chat-tips-utilities.d.ts.map +1 -0
  81. package/dist/components/chat-tips-utilities.js +137 -0
  82. package/dist/components/chat-tips-utilities.js.map +1 -0
  83. package/dist/components/device-cycle.d.ts +84 -0
  84. package/dist/components/device-cycle.d.ts.map +1 -0
  85. package/dist/components/device-cycle.js +77 -0
  86. package/dist/components/device-cycle.js.map +1 -0
  87. package/dist/components/fileExplorerPersistence.d.ts +50 -0
  88. package/dist/components/fileExplorerPersistence.d.ts.map +1 -0
  89. package/dist/components/fileExplorerPersistence.js +63 -0
  90. package/dist/components/fileExplorerPersistence.js.map +1 -0
  91. package/dist/components/search-utilities.d.ts +15 -0
  92. package/dist/components/search-utilities.d.ts.map +1 -0
  93. package/dist/components/search-utilities.js +26 -0
  94. package/dist/components/search-utilities.js.map +1 -0
  95. package/dist/components/tests-bar-utilities.d.ts +106 -0
  96. package/dist/components/tests-bar-utilities.d.ts.map +1 -0
  97. package/dist/components/tests-bar-utilities.js +167 -0
  98. package/dist/components/tests-bar-utilities.js.map +1 -0
  99. package/dist/components/tests-card-utilities.d.ts +280 -0
  100. package/dist/components/tests-card-utilities.d.ts.map +1 -0
  101. package/dist/components/tests-card-utilities.js +591 -0
  102. package/dist/components/tests-card-utilities.js.map +1 -0
  103. package/dist/components/tool-call-utilities.d.ts +256 -0
  104. package/dist/components/tool-call-utilities.d.ts.map +1 -0
  105. package/dist/components/tool-call-utilities.js +1004 -0
  106. package/dist/components/tool-call-utilities.js.map +1 -0
  107. package/dist/components/user-avatar-utilities.d.ts +41 -0
  108. package/dist/components/user-avatar-utilities.d.ts.map +1 -0
  109. package/dist/components/user-avatar-utilities.js +56 -0
  110. package/dist/components/user-avatar-utilities.js.map +1 -0
  111. package/dist/components/workspace-layout-utilities.d.ts +37 -0
  112. package/dist/components/workspace-layout-utilities.d.ts.map +1 -0
  113. package/dist/components/workspace-layout-utilities.js +58 -0
  114. package/dist/components/workspace-layout-utilities.js.map +1 -0
  115. package/dist/customEventCards.d.ts +147 -0
  116. package/dist/customEventCards.d.ts.map +1 -0
  117. package/dist/customEventCards.js +36 -0
  118. package/dist/customEventCards.js.map +1 -0
  119. package/dist/icon-names.d.ts +26 -0
  120. package/dist/icon-names.d.ts.map +1 -0
  121. package/dist/icon-names.js +14 -0
  122. package/dist/icon-names.js.map +1 -0
  123. package/dist/index.d.ts +51 -0
  124. package/dist/index.d.ts.map +1 -0
  125. package/dist/index.js +51 -0
  126. package/dist/index.js.map +1 -0
  127. package/dist/keyboard-shortcut-utilities.d.ts +63 -0
  128. package/dist/keyboard-shortcut-utilities.d.ts.map +1 -0
  129. package/dist/keyboard-shortcut-utilities.js +100 -0
  130. package/dist/keyboard-shortcut-utilities.js.map +1 -0
  131. package/dist/panels.d.ts +26 -0
  132. package/dist/panels.d.ts.map +1 -0
  133. package/dist/panels.js +26 -0
  134. package/dist/panels.js.map +1 -0
  135. package/dist/settings-metadata.d.ts +78 -0
  136. package/dist/settings-metadata.d.ts.map +1 -0
  137. package/dist/settings-metadata.js +137 -0
  138. package/dist/settings-metadata.js.map +1 -0
  139. package/dist/types.d.ts +588 -0
  140. package/dist/types.d.ts.map +1 -0
  141. package/dist/types.js +9 -0
  142. package/dist/types.js.map +1 -0
  143. package/dist/viewport-queries.d.ts +19 -0
  144. package/dist/viewport-queries.d.ts.map +1 -0
  145. package/dist/viewport-queries.js +19 -0
  146. package/dist/viewport-queries.js.map +1 -0
  147. package/package.json +74 -4
@@ -0,0 +1,162 @@
1
+ /**
2
+ * Pure helpers backing the `/models` comparison table.
3
+ *
4
+ * Sorting is split out from the React component so the comparator can be unit
5
+ * tested without rendering. All functions are deterministic and side-effect
6
+ * free.
7
+ *
8
+ * @module
9
+ */
10
+ import type { AppModelDefinition } from '@molecule/app-ai-models';
11
+ /**
12
+ * Sortable columns in the `/models` table.
13
+ *
14
+ * `cutoff` (knowledge-cutoff date) replaced a former `tier` column that was
15
+ * fabricated from input price: it duplicated the `cost` axis and was sometimes
16
+ * factually wrong (a slow reasoning model could read "Balanced"). The catalog
17
+ * has no latency field, so rather than invent one we expose `knowledgeCutoff` —
18
+ * a real, factual axis that is genuinely independent of price, context, and
19
+ * output size.
20
+ */
21
+ export type ModelSortColumn = 'name' | 'context' | 'cost' | 'cutoff' | 'free' | 'region';
22
+ /** Sort direction. */
23
+ export type SortDirection = 'asc' | 'desc';
24
+ /**
25
+ * Processing region of a model, as an arbitrary region code (`'us'`, `'cn'`,
26
+ * potentially `'eu'` etc. later). `'us'` is the platform default; deliberately
27
+ * NOT a closed union so adding a region never changes this contract.
28
+ */
29
+ export type ModelProcessingRegion = string;
30
+ /**
31
+ * Resolve a model's effective processing region: the requested region when the
32
+ * model's `regions` list offers it, else the model's DEFAULT region (the first
33
+ * listed; `'us'` when the catalog omits regions). A single-entry list pins the
34
+ * model regardless of the request. Mirrors the server-side
35
+ * `effectiveModelRegion` in `@molecule/api-resource-ai-models`.
36
+ *
37
+ * @param model - The model metadata.
38
+ * @param requested - The user's per-model region choice, if any.
39
+ * @returns The effective region code.
40
+ */
41
+ export declare function effectiveModelRegion(model: AppModelDefinition, requested?: string): ModelProcessingRegion;
42
+ /**
43
+ * The peak-hour multiplier in force for a model at an instant, in a region.
44
+ *
45
+ * Mirrors the server's `priceMultiplierAt`, including its `daysOfWeekUtc` and
46
+ * `excludedDatesUtc` (public holidays) handling and the rule that matters
47
+ * most: peak belongs to the NATIVE provider, so a region with a `regionPricing`
48
+ * override — a different host, billing its own flat card — never takes it.
49
+ * Showing a 2× on a re-host the user is actually routed to would be a lie in
50
+ * the expensive direction.
51
+ *
52
+ * @param model - The model metadata.
53
+ * @param region - The user's per-model region choice, if any.
54
+ * @param at - The instant to evaluate (defaults to now).
55
+ * @returns The multiplier, or `1` when no peak window applies.
56
+ */
57
+ export declare function modelPeakMultiplier(model: AppModelDefinition, region?: string, at?: Date): number;
58
+ /**
59
+ * Whether a model can EVER cost more at some hours than others, in a region.
60
+ *
61
+ * Distinct from {@link modelPeakMultiplier}, which answers "right now". The
62
+ * picker needs both: one to price the current moment, one to decide whether the
63
+ * model deserves a "costs more at some hours" explanation at all — a model in
64
+ * its off-peak hours still surprises the user later if nothing says so.
65
+ *
66
+ * @param model - The model metadata.
67
+ * @param region - The user's per-model region choice, if any.
68
+ * @returns True when the model has peak windows that apply in this region.
69
+ */
70
+ export declare function modelHasPeakPricing(model: AppModelDefinition, region?: string): boolean;
71
+ /**
72
+ * The peak windows as local-time `HH:MM–HH:MM` ranges, for display, prefixed
73
+ * with the weekdays they apply on when they do not apply every day.
74
+ *
75
+ * Local, not UTC: a user reasons about "is it expensive right now" in their own
76
+ * clock, and the windows are only actionable if they can be compared to it. A
77
+ * weekday-qualified window that renders as bare hours overstates the cost for
78
+ * two days a week — the provider is not charging peak on a Saturday.
79
+ *
80
+ * @param model - The model metadata.
81
+ * @returns Formatted local ranges, empty when the model has no peak windows.
82
+ */
83
+ export declare function modelPeakWindowLabels(model: AppModelDefinition): string[];
84
+ /**
85
+ * What a representative agentic turn costs on a model, in USD — the single
86
+ * "cost" figure, at the rates of the model's effective region (`regionPricing`
87
+ * override when the region has one, else the base rates).
88
+ *
89
+ * This weighted `AGENTIC_TOKEN_MIX` replaced a plain `input + output` sum on
90
+ * 2026-08-14. That sum ignored cache reads, which is the term that actually
91
+ * dominates the bill, and the error was not small: it showed Claude Haiku at
92
+ * ×23 the cheapest model when the real figure is ×10, and gemini-3.7-flash at
93
+ * ×35 against a true ×15 — systematically scaring users off cache-friendly
94
+ * models while making a couple of others look cheaper than they bill. The sum
95
+ * was a fine proxy while every provider's cache read was a fixed fraction of
96
+ * input; it stopped being one once hosts started pricing cache reads
97
+ * independently (DeepSeek's absolute cache-hit rates, DeepInfra's 0.2x).
98
+ *
99
+ * Not currency: callers surface this only as a RELATIVE multiplier
100
+ * ({@link modelUsageRate}), never as a price.
101
+ *
102
+ * @param model - The model metadata.
103
+ * @param region - The user's per-model region choice, if any (omitted → the
104
+ * model's default region).
105
+ * @returns The blended cost of one representative turn in USD.
106
+ */
107
+ export declare function modelTotalCost(model: AppModelDefinition, region?: string): number;
108
+ /**
109
+ * Relative usage rate: how much faster this model consumes the user's AI
110
+ * allowance than the cheapest available model (a unitless `×N` multiplier,
111
+ * `1` for the cheapest). Derived from {@link modelTotalCost}, a blended agentic
112
+ * turn. This is the ONLY per-model "cost" figure user-facing surfaces show — AI
113
+ * usage is never presented as currency.
114
+ *
115
+ * The base is every model's DEFAULT-region cost (stable regardless of the
116
+ * user's per-model region choices); the rated model itself is priced at the
117
+ * given region so the figure tracks what a region switch actually changes.
118
+ *
119
+ * PEAK PRICING IS INCLUDED, at `at`. A model inside a provider's peak window
120
+ * genuinely drains the allowance at its multiplier, so the figure has to move
121
+ * with it — a single all-day number is wrong twice a day. Only the RATED model
122
+ * takes its multiplier: the base stays each model's off-peak default-region
123
+ * cost, so the anchor does not wobble as unrelated models enter their windows.
124
+ * Pair it with {@link modelHasPeakPricing} / {@link modelPeakWindowLabels} so a
125
+ * changing number reads as explained rather than erratic.
126
+ *
127
+ * @param model - The model to rate.
128
+ * @param models - The full available-model list (supplies the cheapest base).
129
+ * @param region - The rated model's region choice, if any (omitted → its
130
+ * default region).
131
+ * @param at - The instant to price at (defaults to now).
132
+ * @returns The multiplier, rounded to 1 decimal below 10 and whole above.
133
+ */
134
+ export declare function modelUsageRate(model: AppModelDefinition, models: readonly AppModelDefinition[], region?: string, at?: Date): number;
135
+ /**
136
+ * Ascending comparator for two models by the given column. Returns a negative,
137
+ * zero, or positive number suitable for `Array.prototype.sort`. Ties fall back
138
+ * to label order so the sort is stable and deterministic.
139
+ *
140
+ * @param a - First model.
141
+ * @param b - Second model.
142
+ * @param column - Column to compare by.
143
+ * @param regionOf - Resolves a model's effective processing region (used by
144
+ * the `'region'` and `'cost'` columns; omitting it treats every model as its
145
+ * default region). The caller supplies this because the effective region
146
+ * depends on per-project settings the pure helper cannot know.
147
+ * @returns Negative if `a` sorts before `b`, positive if after, zero if equal.
148
+ */
149
+ export declare function compareModels(a: AppModelDefinition, b: AppModelDefinition, column: ModelSortColumn, regionOf?: (model: AppModelDefinition) => ModelProcessingRegion): number;
150
+ /**
151
+ * Returns a new array of models sorted by the given column and direction.
152
+ * Does not mutate the input.
153
+ *
154
+ * @param models - Models to sort.
155
+ * @param column - Column to sort by.
156
+ * @param direction - `'asc'` or `'desc'`.
157
+ * @param regionOf - Resolves a model's effective processing region (used by
158
+ * the `'region'` and `'cost'` columns). See {@link compareModels}.
159
+ * @returns A new, sorted array.
160
+ */
161
+ export declare function sortModels(models: readonly AppModelDefinition[], column: ModelSortColumn, direction: SortDirection, regionOf?: (model: AppModelDefinition) => ModelProcessingRegion): AppModelDefinition[];
162
+ //# sourceMappingURL=chat-models-utilities.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chat-models-utilities.d.ts","sourceRoot":"","sources":["../../src/components/chat-models-utilities.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAA;AAEjE;;;;;;;;;GASG;AACH,MAAM,MAAM,eAAe,GAAG,MAAM,GAAG,SAAS,GAAG,MAAM,GAAG,QAAQ,GAAG,MAAM,GAAG,QAAQ,CAAA;AAExF,sBAAsB;AACtB,MAAM,MAAM,aAAa,GAAG,KAAK,GAAG,MAAM,CAAA;AAE1C;;;;GAIG;AACH,MAAM,MAAM,qBAAqB,GAAG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AAqB,GAC9D,kBAAkB,EAAE,CAQtB"}
@@ -0,0 +1,302 @@
1
+ /**
2
+ * Pure helpers backing the `/models` comparison table.
3
+ *
4
+ * Sorting is split out from the React component so the comparator can be unit
5
+ * tested without rendering. All functions are deterministic and side-effect
6
+ * free.
7
+ *
8
+ * @module
9
+ */
10
+ /**
11
+ * Resolve a model's effective processing region: the requested region when the
12
+ * model's `regions` list offers it, else the model's DEFAULT region (the first
13
+ * listed; `'us'` when the catalog omits regions). A single-entry list pins the
14
+ * model regardless of the request. Mirrors the server-side
15
+ * `effectiveModelRegion` in `@molecule/api-resource-ai-models`.
16
+ *
17
+ * @param model - The model metadata.
18
+ * @param requested - The user's per-model region choice, if any.
19
+ * @returns The effective region code.
20
+ */
21
+ export function effectiveModelRegion(model, requested) {
22
+ const regions = model.regions ?? ['us'];
23
+ return requested && regions.includes(requested) ? requested : regions[0];
24
+ }
25
+ /**
26
+ * The peak-hour multiplier in force for a model at an instant, in a region.
27
+ *
28
+ * Mirrors the server's `priceMultiplierAt`, including its `daysOfWeekUtc` and
29
+ * `excludedDatesUtc` (public holidays) handling and the rule that matters
30
+ * most: peak belongs to the NATIVE provider, so a region with a `regionPricing`
31
+ * override — a different host, billing its own flat card — never takes it.
32
+ * Showing a 2× on a re-host the user is actually routed to would be a lie in
33
+ * the expensive direction.
34
+ *
35
+ * @param model - The model metadata.
36
+ * @param region - The user's per-model region choice, if any.
37
+ * @param at - The instant to evaluate (defaults to now).
38
+ * @returns The multiplier, or `1` when no peak window applies.
39
+ */
40
+ export function modelPeakMultiplier(model, region, at = new Date()) {
41
+ if (model.regionPricing?.[effectiveModelRegion(model, region)])
42
+ return 1;
43
+ const peak = model.peakPricing;
44
+ if (!peak || peak.windows.length === 0)
45
+ return 1;
46
+ const minute = at.getUTCHours() * 60 + at.getUTCMinutes();
47
+ for (const w of peak.windows) {
48
+ const wraps = w.startMinuteUtc > w.endMinuteUtc;
49
+ const inWindow = wraps
50
+ ? minute >= w.startMinuteUtc || minute < w.endMinuteUtc
51
+ : minute >= w.startMinuteUtc && minute < w.endMinuteUtc;
52
+ if (!inWindow)
53
+ continue;
54
+ // A wrapping window belongs to the day it STARTED on, so its
55
+ // post-midnight tail is matched against the previous UTC day.
56
+ const startedYesterday = wraps && minute < w.endMinuteUtc;
57
+ if (w.daysOfWeekUtc && w.daysOfWeekUtc.length > 0) {
58
+ const day = startedYesterday ? (at.getUTCDay() + 6) % 7 : at.getUTCDay();
59
+ if (!w.daysOfWeekUtc.includes(day))
60
+ continue;
61
+ }
62
+ if (peak.excludedDatesUtc && peak.excludedDatesUtc.length > 0) {
63
+ const started = new Date(at.getTime() - (startedYesterday ? 86_400_000 : 0));
64
+ if (peak.excludedDatesUtc.includes(started.toISOString().slice(0, 10)))
65
+ continue;
66
+ }
67
+ return peak.multiplier;
68
+ }
69
+ return 1;
70
+ }
71
+ /**
72
+ * Whether a model can EVER cost more at some hours than others, in a region.
73
+ *
74
+ * Distinct from {@link modelPeakMultiplier}, which answers "right now". The
75
+ * picker needs both: one to price the current moment, one to decide whether the
76
+ * model deserves a "costs more at some hours" explanation at all — a model in
77
+ * its off-peak hours still surprises the user later if nothing says so.
78
+ *
79
+ * @param model - The model metadata.
80
+ * @param region - The user's per-model region choice, if any.
81
+ * @returns True when the model has peak windows that apply in this region.
82
+ */
83
+ export function modelHasPeakPricing(model, region) {
84
+ if (model.regionPricing?.[effectiveModelRegion(model, region)])
85
+ return false;
86
+ return (model.peakPricing?.windows.length ?? 0) > 0 && model.peakPricing.multiplier !== 1;
87
+ }
88
+ /**
89
+ * A window's `daysOfWeekUtc` as a localized weekday label, for display.
90
+ *
91
+ * The days are UTC but the times are shown in the user's clock, and the two can
92
+ * disagree — a Monday 01:00 UTC window starts on Sunday evening in UTC-8. So
93
+ * each UTC day is resolved through the window's own START instant and read back
94
+ * in local time, which is the same day the `HH:MM` beside it belongs to.
95
+ * Contiguous runs collapse to a range (`Mon–Fri`), including runs that wrap the
96
+ * week; anything else lists the days.
97
+ *
98
+ * @param window - The peak window.
99
+ * @returns The localized weekday label, empty when the window applies every day.
100
+ */
101
+ function peakWindowDayLabel(window) {
102
+ const days = window.daysOfWeekUtc;
103
+ if (!days || days.length === 0 || days.length >= 7)
104
+ return '';
105
+ // 2026-08-30 is a Sunday in UTC, so `+ d` lands on UTC weekday `d`.
106
+ const byLocalDay = new Map();
107
+ for (const d of days) {
108
+ const at = new Date(Date.UTC(2026, 7, 30 + d, 0, window.startMinuteUtc));
109
+ byLocalDay.set(at.getDay(), at.toLocaleDateString(undefined, { weekday: 'short' }));
110
+ }
111
+ const present = [...byLocalDay.keys()].sort((a, b) => a - b);
112
+ if (present.length === 1)
113
+ return byLocalDay.get(present[0]);
114
+ const start = present.find((d) => !byLocalDay.has((d + 6) % 7));
115
+ if (start !== undefined) {
116
+ let end = start;
117
+ let length = 1;
118
+ while (byLocalDay.has((end + 1) % 7) && length < present.length) {
119
+ end = (end + 1) % 7;
120
+ length += 1;
121
+ }
122
+ if (length === present.length)
123
+ return `${byLocalDay.get(start)}–${byLocalDay.get(end)}`;
124
+ }
125
+ return present.map((d) => byLocalDay.get(d)).join(', ');
126
+ }
127
+ /**
128
+ * The peak windows as local-time `HH:MM–HH:MM` ranges, for display, prefixed
129
+ * with the weekdays they apply on when they do not apply every day.
130
+ *
131
+ * Local, not UTC: a user reasons about "is it expensive right now" in their own
132
+ * clock, and the windows are only actionable if they can be compared to it. A
133
+ * weekday-qualified window that renders as bare hours overstates the cost for
134
+ * two days a week — the provider is not charging peak on a Saturday.
135
+ *
136
+ * @param model - The model metadata.
137
+ * @returns Formatted local ranges, empty when the model has no peak windows.
138
+ */
139
+ export function modelPeakWindowLabels(model) {
140
+ const windows = model.peakPricing?.windows ?? [];
141
+ const fmt = (minuteUtc) => {
142
+ const d = new Date();
143
+ d.setUTCHours(Math.floor(minuteUtc / 60), minuteUtc % 60, 0, 0);
144
+ return d.toLocaleTimeString(undefined, { hour: '2-digit', minute: '2-digit' });
145
+ };
146
+ return windows.map((w) => {
147
+ const hours = `${fmt(w.startMinuteUtc)}–${fmt(w.endMinuteUtc)}`;
148
+ const days = peakWindowDayLabel(w);
149
+ return days ? `${days} ${hours}` : hours;
150
+ });
151
+ }
152
+ /**
153
+ * The token mix a real agentic turn bills at, used to weight the cost figure.
154
+ *
155
+ * Agentic conversations re-send a growing prefix every turn, so prompt-cache
156
+ * HITS dominate: measured traffic runs ~94% cache reads (deepseek, 2026-08-01).
157
+ * Weighting matters more than the exact numbers — what breaks is ignoring cache
158
+ * reads entirely, not being a few points off the ratio.
159
+ */
160
+ const AGENTIC_TOKEN_MIX = { cacheRead: 47_000, input: 3_000, output: 800 };
161
+ /**
162
+ * What a representative agentic turn costs on a model, in USD — the single
163
+ * "cost" figure, at the rates of the model's effective region (`regionPricing`
164
+ * override when the region has one, else the base rates).
165
+ *
166
+ * This weighted `AGENTIC_TOKEN_MIX` replaced a plain `input + output` sum on
167
+ * 2026-08-14. That sum ignored cache reads, which is the term that actually
168
+ * dominates the bill, and the error was not small: it showed Claude Haiku at
169
+ * ×23 the cheapest model when the real figure is ×10, and gemini-3.7-flash at
170
+ * ×35 against a true ×15 — systematically scaring users off cache-friendly
171
+ * models while making a couple of others look cheaper than they bill. The sum
172
+ * was a fine proxy while every provider's cache read was a fixed fraction of
173
+ * input; it stopped being one once hosts started pricing cache reads
174
+ * independently (DeepSeek's absolute cache-hit rates, DeepInfra's 0.2x).
175
+ *
176
+ * Not currency: callers surface this only as a RELATIVE multiplier
177
+ * ({@link modelUsageRate}), never as a price.
178
+ *
179
+ * @param model - The model metadata.
180
+ * @param region - The user's per-model region choice, if any (omitted → the
181
+ * model's default region).
182
+ * @returns The blended cost of one representative turn in USD.
183
+ */
184
+ export function modelTotalCost(model, region) {
185
+ const override = model.regionPricing?.[effectiveModelRegion(model, region)];
186
+ const input = override?.inputPricePerMTok ?? model.inputPricePerMTok;
187
+ const output = override?.outputPricePerMTok ?? model.outputPricePerMTok;
188
+ // An override with no cache fields bills cache reads at its input rate — the
189
+ // same fallback `modelRegionRates` applies server-side for metering.
190
+ const cacheRead = override
191
+ ? (override.cacheReadPricePerMTok ?? override.inputPricePerMTok)
192
+ : model.cacheReadPricePerMTok;
193
+ return ((AGENTIC_TOKEN_MIX.cacheRead * cacheRead +
194
+ AGENTIC_TOKEN_MIX.input * input +
195
+ AGENTIC_TOKEN_MIX.output * output) /
196
+ 1_000_000);
197
+ }
198
+ /**
199
+ * Relative usage rate: how much faster this model consumes the user's AI
200
+ * allowance than the cheapest available model (a unitless `×N` multiplier,
201
+ * `1` for the cheapest). Derived from {@link modelTotalCost}, a blended agentic
202
+ * turn. This is the ONLY per-model "cost" figure user-facing surfaces show — AI
203
+ * usage is never presented as currency.
204
+ *
205
+ * The base is every model's DEFAULT-region cost (stable regardless of the
206
+ * user's per-model region choices); the rated model itself is priced at the
207
+ * given region so the figure tracks what a region switch actually changes.
208
+ *
209
+ * PEAK PRICING IS INCLUDED, at `at`. A model inside a provider's peak window
210
+ * genuinely drains the allowance at its multiplier, so the figure has to move
211
+ * with it — a single all-day number is wrong twice a day. Only the RATED model
212
+ * takes its multiplier: the base stays each model's off-peak default-region
213
+ * cost, so the anchor does not wobble as unrelated models enter their windows.
214
+ * Pair it with {@link modelHasPeakPricing} / {@link modelPeakWindowLabels} so a
215
+ * changing number reads as explained rather than erratic.
216
+ *
217
+ * @param model - The model to rate.
218
+ * @param models - The full available-model list (supplies the cheapest base).
219
+ * @param region - The rated model's region choice, if any (omitted → its
220
+ * default region).
221
+ * @param at - The instant to price at (defaults to now).
222
+ * @returns The multiplier, rounded to 1 decimal below 10 and whole above.
223
+ */
224
+ export function modelUsageRate(model, models, region, at = new Date()) {
225
+ const costs = models.map((m) => modelTotalCost(m)).filter((c) => c > 0);
226
+ const base = costs.length > 0 ? Math.min(...costs) : 0;
227
+ if (!Number.isFinite(base) || base <= 0)
228
+ return 1;
229
+ const rate = (modelTotalCost(model, region) * modelPeakMultiplier(model, region, at)) / base;
230
+ return rate >= 10 ? Math.round(rate) : Math.max(1, Math.round(rate * 10) / 10);
231
+ }
232
+ /**
233
+ * Ascending comparator for two models by the given column. Returns a negative,
234
+ * zero, or positive number suitable for `Array.prototype.sort`. Ties fall back
235
+ * to label order so the sort is stable and deterministic.
236
+ *
237
+ * @param a - First model.
238
+ * @param b - Second model.
239
+ * @param column - Column to compare by.
240
+ * @param regionOf - Resolves a model's effective processing region (used by
241
+ * the `'region'` and `'cost'` columns; omitting it treats every model as its
242
+ * default region). The caller supplies this because the effective region
243
+ * depends on per-project settings the pure helper cannot know.
244
+ * @returns Negative if `a` sorts before `b`, positive if after, zero if equal.
245
+ */
246
+ export function compareModels(a, b, column, regionOf) {
247
+ let primary;
248
+ switch (column) {
249
+ case 'name':
250
+ primary = a.label.localeCompare(b.label);
251
+ break;
252
+ case 'context':
253
+ primary = a.contextWindow - b.contextWindow;
254
+ break;
255
+ case 'cost':
256
+ // Region-aware: a model flipped to a differently-priced region sorts by
257
+ // the cost it actually bills at.
258
+ primary = modelTotalCost(a, regionOf?.(a)) - modelTotalCost(b, regionOf?.(b));
259
+ break;
260
+ case 'cutoff':
261
+ // Knowledge-cutoff dates are YYYY-MM-DD strings, which sort
262
+ // lexicographically as dates. Ascending puts the oldest training data
263
+ // first.
264
+ primary = a.knowledgeCutoff.localeCompare(b.knowledgeCutoff);
265
+ break;
266
+ case 'free':
267
+ // Free-tier models sort first in ascending order.
268
+ primary = (b.freeTier ? 1 : 0) - (a.freeTier ? 1 : 0);
269
+ break;
270
+ case 'region': {
271
+ // US-processed (platform-default) models sort first ascending; other
272
+ // regions follow alphabetically by region code.
273
+ const ra = regionOf?.(a) ?? 'us';
274
+ const rb = regionOf?.(b) ?? 'us';
275
+ primary = ra === rb ? 0 : ra === 'us' ? -1 : rb === 'us' ? 1 : ra.localeCompare(rb);
276
+ break;
277
+ }
278
+ }
279
+ if (primary !== 0)
280
+ return primary;
281
+ // Stable tiebreak by label so equal rows keep a deterministic order.
282
+ return a.label.localeCompare(b.label);
283
+ }
284
+ /**
285
+ * Returns a new array of models sorted by the given column and direction.
286
+ * Does not mutate the input.
287
+ *
288
+ * @param models - Models to sort.
289
+ * @param column - Column to sort by.
290
+ * @param direction - `'asc'` or `'desc'`.
291
+ * @param regionOf - Resolves a model's effective processing region (used by
292
+ * the `'region'` and `'cost'` columns). See {@link compareModels}.
293
+ * @returns A new, sorted array.
294
+ */
295
+ export function sortModels(models, column, direction, regionOf) {
296
+ // Swapping the comparator arguments for `'desc'` fully reverses the order
297
+ // (including the label tiebreak) without relying on Array#sort stability.
298
+ return [...models].sort((a, b) => direction === 'desc'
299
+ ? compareModels(b, a, column, regionOf)
300
+ : compareModels(a, b, column, regionOf));
301
+ }
302
+ //# sourceMappingURL=chat-models-utilities.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chat-models-utilities.js","sourceRoot":"","sources":["../../src/components/chat-models-utilities.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AA0BH;;;;;;;;;;GAUG;AACH,MAAM,UAAU,oBAAoB,CAClC,KAAyB,EACzB,SAAkB;IAElB,MAAM,OAAO,GAAG,KAAK,CAAC,OAAO,IAAI,CAAC,IAAI,CAAC,CAAA;IACvC,OAAO,SAAS,IAAI,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAA;AAC1E,CAAC;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,mBAAmB,CACjC,KAAyB,EACzB,MAAe,EACf,KAAW,IAAI,IAAI,EAAE;IAErB,IAAI,KAAK,CAAC,aAAa,EAAE,CAAC,oBAAoB,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;QAAE,OAAO,CAAC,CAAA;IACxE,MAAM,IAAI,GAAG,KAAK,CAAC,WAAW,CAAA;IAC9B,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,OAAO,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,CAAC,C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AC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,KAAK,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,KAAK,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,aAAa,CAAC,EAAE,CAAC,CAAA;YACnF,MAAK;QACP,CAAC;IACH,CAAC;IACD,IAAI,OAAO,KAAK,CAAC;QAAE,OAAO,OAAO,CAAA;IACjC,qEAAqE;IACrE,OAAO,CAAC,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC,CAAC,KAAK,CAAC,CAAA;AACvC,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,UAAU,UAAU,CACxB,MAAqC,EACrC,MAAuB,EACvB,SAAwB,EACxB,QAA+D;IAE/D,0EAA0E;IAC1E,0EAA0E;IAC1E,OAAO,CAAC,GAAG,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAC/B,SAAS,KAAK,MAAM;QAClB,CAAC,CAAC,aAAa,CAAC,CAAC,EAAE,CAAC,EAAE,MAAM,EAAE,QAAQ,CAAC;QACvC,CAAC,CAAC,aAAa,CAAC,CAAC,EAAE,CAAC,EAAE,MAAM,EAAE,QAAQ,CAAC,CAC1C,CAAA;AACH,CAAC"}
@@ -0,0 +1,149 @@
1
+ /**
2
+ * Pure helpers backing the `/report` (and `/bug` alias) command and the header
3
+ * bug-report button.
4
+ *
5
+ * The report modal collects a title, description, optional reproduction steps,
6
+ * and an "include recent chat" toggle, then POSTs to
7
+ * `POST /projects/:id/report { title, description, steps?, includeChat, clientInfo? }`.
8
+ * The backend files a GitHub issue when a report repo + token are configured
9
+ * (else records a DB row) and always persists a DB row tagged with
10
+ * projectId+userId, returning `{ ok, url?, id }`.
11
+ *
12
+ * The payload also carries an optional `clientInfo` block of client-side
13
+ * diagnostics — app version, browser/OS (user agent + platform), language,
14
+ * viewport + screen size, theme, and the current URL — collected by
15
+ * {@link collectClientInfo}. Every field is read defensively (each guarded for
16
+ * SSR / missing globals) so the report attaches whatever it can without ever
17
+ * throwing, giving triage real context without the user having to type it.
18
+ *
19
+ * These helpers parse the command, build the exact POST payload (omitting empty
20
+ * optional fields), validate the form, and produce a confirmation message. They
21
+ * are deterministic and side-effect free so they can be unit tested without
22
+ * rendering or a real backend. The confirmation/link rendering uses these values
23
+ * with `t()` in the component — the only translatable strings here are the
24
+ * confirmation defaults, kept i18n-ready by the caller.
25
+ *
26
+ * @module
27
+ */
28
+ /** The report modal's form state. */
29
+ export interface ReportFormState {
30
+ /** Short summary / issue title. */
31
+ title: string;
32
+ /** Detailed description of the problem or request. */
33
+ description: string;
34
+ /** Optional reproduction steps (free text). */
35
+ steps: string;
36
+ /** Whether to attach the recent conversation to the report. */
37
+ includeChat: boolean;
38
+ }
39
+ /**
40
+ * Client-side diagnostics attached to a report so triage can see the running
41
+ * environment without asking the user. Every field is optional — only what
42
+ * could be read in the current environment is present (see
43
+ * {@link collectClientInfo}).
44
+ */
45
+ export interface ClientInfo {
46
+ /** The running build version. */
47
+ appVersion?: string;
48
+ /** `navigator.userAgent` (browser + OS). */
49
+ userAgent?: string;
50
+ /** `navigator.platform`. */
51
+ platform?: string;
52
+ /** `navigator.language`. */
53
+ language?: string;
54
+ /** Inner viewport size, `${innerWidth}×${innerHeight}`. */
55
+ viewport?: string;
56
+ /** Physical screen size, `${screen.width}×${screen.height}`. */
57
+ screen?: string;
58
+ /** Active theme — `'light'` or `'dark'`. */
59
+ theme?: string;
60
+ /** The current page URL (`window.location.href`). */
61
+ url?: string;
62
+ }
63
+ /** The `POST /projects/:id/report` request body. */
64
+ export interface ReportPayload {
65
+ /** Short summary / issue title. */
66
+ title: string;
67
+ /** Detailed description. */
68
+ description: string;
69
+ /** Reproduction steps — omitted entirely when blank. */
70
+ steps?: string;
71
+ /** Whether the backend should attach the recent conversation. */
72
+ includeChat: boolean;
73
+ /** Client diagnostics — omitted entirely when none could be collected. */
74
+ clientInfo?: ClientInfo;
75
+ }
76
+ /** The `POST /projects/:id/report` response. */
77
+ export interface ReportResult {
78
+ /** Whether the report was recorded. */
79
+ ok: boolean;
80
+ /** Link to the created issue, when one was filed. */
81
+ url?: string;
82
+ /** The persisted DB row id. */
83
+ id?: string;
84
+ }
85
+ /** An empty report form (the modal's initial state). */
86
+ export declare const EMPTY_REPORT_FORM: ReportFormState;
87
+ /**
88
+ * Parses a `/report [title]` or `/bug [title]` command. Returns the (possibly
89
+ * empty) trimmed title used to seed the modal when the input is one of those
90
+ * commands, else `null`.
91
+ *
92
+ * @param input - The raw chat input.
93
+ * @returns `{ title }` when it's a `/report` or `/bug` command, else `null`.
94
+ */
95
+ export declare function parseReportCommand(input: string): {
96
+ title: string;
97
+ } | null;
98
+ /**
99
+ * Collects client-side diagnostics for a report. Reads `navigator`
100
+ * (userAgent/platform/language), `window` (inner viewport size, screen size,
101
+ * location href), plus the caller-supplied app version and theme. Every access
102
+ * is guarded (`typeof window/navigator !== 'undefined'` and per-property
103
+ * presence) so it is SSR-safe and never throws — it returns only the fields it
104
+ * could actually read, so the result may be partial or (in a headless
105
+ * environment) empty.
106
+ *
107
+ * @param opts - Caller-supplied context.
108
+ * @param opts.appVersion - The running build version, if known.
109
+ * @param opts.theme - The active theme (`'light'` | `'dark'`), if known.
110
+ * @returns The populated subset of {@link ClientInfo}.
111
+ */
112
+ export declare function collectClientInfo(opts?: {
113
+ appVersion?: string;
114
+ theme?: string;
115
+ }): ClientInfo;
116
+ /**
117
+ * Builds the `POST /projects/:id/report` body from the form state, trimming all
118
+ * text fields and omitting `steps` entirely when it is blank. When `clientInfo`
119
+ * is supplied and non-empty, it is attached; an `undefined` or empty diagnostics
120
+ * object is omitted from the payload.
121
+ *
122
+ * @param form - The report form state.
123
+ * @param clientInfo - Optional client diagnostics from {@link collectClientInfo}.
124
+ * @returns The normalized report payload.
125
+ */
126
+ export declare function buildReportPayload(form: ReportFormState, clientInfo?: ClientInfo): ReportPayload;
127
+ /**
128
+ * Whether the report form has the minimum required fields: a non-empty title
129
+ * and a non-empty description.
130
+ *
131
+ * @param form - The report form state.
132
+ * @returns `true` when the form can be submitted.
133
+ */
134
+ export declare function isReportFormValid(form: ReportFormState): boolean;
135
+ /**
136
+ * Builds the confirmation message shown after a report is submitted. Returns the
137
+ * English defaults; the component passes these through `t()` at render. The
138
+ * success `defaultValue` may contain the `{{productName}}` interpolation token,
139
+ * which the caller fills in from the host's product identity (neutral default:
140
+ * "the IDE"). When the result is not `ok`, returns the failure message.
141
+ *
142
+ * @param result - The `POST /projects/:id/report` response.
143
+ * @returns `{ key, defaultValue }` for the confirmation/failure message.
144
+ */
145
+ export declare function formatReportConfirmation(result: ReportResult): {
146
+ key: string;
147
+ defaultValue: string;
148
+ };
149
+ //# sourceMappingURL=chat-report-utilities.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chat-report-utilities.d.ts","sourceRoot":"","sources":["../../src/components/chat-report-utilities.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH,qCAAqC;AACrC,MAAM,WAAW,eAAe;IAC9B,mCAAmC;IACnC,KAAK,EAAE,MAAM,CAAA;IACb,sDAAsD;IACtD,WAAW,EAAE,MAAM,CAAA;IACnB,+CAA+C;IAC/C,KAAK,EAAE,MAAM,CAAA;IACb,+DAA+D;IAC/D,WAAW,EAAE,OAAO,CAAA;CACrB;AAED;;;;;GAKG;AACH,MAAM,WAAW,UAAU;IACzB,iCAAiC;IACjC,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,4CAA4C;IAC5C,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,4BAA4B;IAC5B,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,4BAA4B;IAC5B,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,2DAA2D;IAC3D,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,gEAAgE;IAChE,MAAM,CAAC,EAAE,MAAM,CA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