@molecule/app-ide-panel-logic 1.3.1 → 1.4.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.
- package/README.md +277 -1
- package/dist/chatTimelineOrdering.d.ts +175 -1
- package/dist/chatTimelineOrdering.d.ts.map +1 -1
- package/dist/chatTimelineOrdering.js +192 -1
- package/dist/chatTimelineOrdering.js.map +1 -1
- package/dist/components/chat-card-event-utilities.d.ts +320 -0
- package/dist/components/chat-card-event-utilities.d.ts.map +1 -0
- package/dist/components/chat-card-event-utilities.js +198 -0
- package/dist/components/chat-card-event-utilities.js.map +1 -0
- package/dist/components/chat-composer-utilities.d.ts +472 -0
- package/dist/components/chat-composer-utilities.d.ts.map +1 -0
- package/dist/components/chat-composer-utilities.js +519 -0
- package/dist/components/chat-composer-utilities.js.map +1 -0
- package/dist/components/chat-dictation-controller.d.ts +376 -0
- package/dist/components/chat-dictation-controller.d.ts.map +1 -0
- package/dist/components/chat-dictation-controller.js +559 -0
- package/dist/components/chat-dictation-controller.js.map +1 -0
- package/dist/components/chat-effort-utilities.d.ts +24 -0
- package/dist/components/chat-effort-utilities.d.ts.map +1 -1
- package/dist/components/chat-effort-utilities.js +41 -0
- package/dist/components/chat-effort-utilities.js.map +1 -1
- package/dist/components/chat-format-utilities.d.ts +71 -0
- package/dist/components/chat-format-utilities.d.ts.map +1 -0
- package/dist/components/chat-format-utilities.js +192 -0
- package/dist/components/chat-format-utilities.js.map +1 -0
- package/dist/components/chat-models-utilities.d.ts +168 -0
- package/dist/components/chat-models-utilities.d.ts.map +1 -1
- package/dist/components/chat-models-utilities.js +253 -0
- package/dist/components/chat-models-utilities.js.map +1 -1
- package/dist/components/chat-settings-utilities.d.ts +153 -1
- package/dist/components/chat-settings-utilities.d.ts.map +1 -1
- package/dist/components/chat-settings-utilities.js +204 -1
- package/dist/components/chat-settings-utilities.js.map +1 -1
- package/dist/components/chat-stream-utilities.d.ts +165 -1
- package/dist/components/chat-stream-utilities.d.ts.map +1 -1
- package/dist/components/chat-stream-utilities.js +155 -1
- package/dist/components/chat-stream-utilities.js.map +1 -1
- package/dist/components/chat-tests-controller.d.ts +249 -0
- package/dist/components/chat-tests-controller.d.ts.map +1 -0
- package/dist/components/chat-tests-controller.js +504 -0
- package/dist/components/chat-tests-controller.js.map +1 -0
- package/dist/components/chat-timeline-utilities.d.ts +90 -0
- package/dist/components/chat-timeline-utilities.d.ts.map +1 -0
- package/dist/components/chat-timeline-utilities.js +71 -0
- package/dist/components/chat-timeline-utilities.js.map +1 -0
- package/dist/components/chat-ui-constants.d.ts +98 -0
- package/dist/components/chat-ui-constants.d.ts.map +1 -0
- package/dist/components/chat-ui-constants.js +146 -0
- package/dist/components/chat-ui-constants.js.map +1 -0
- package/dist/components/chat-undo-utilities.d.ts +47 -0
- package/dist/components/chat-undo-utilities.d.ts.map +1 -0
- package/dist/components/chat-undo-utilities.js +73 -0
- package/dist/components/chat-undo-utilities.js.map +1 -0
- package/dist/components/context-usage-utilities.d.ts +25 -3
- package/dist/components/context-usage-utilities.d.ts.map +1 -1
- package/dist/components/context-usage-utilities.js +42 -2
- package/dist/components/context-usage-utilities.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/panels.d.ts +6 -0
- package/dist/panels.d.ts.map +1 -1
- package/dist/panels.js +6 -0
- package/dist/panels.js.map +1 -1
- package/package.json +2 -2
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
*
|
|
23
23
|
* @module
|
|
24
24
|
*/
|
|
25
|
+
import { effortOptionsForModel, nativeEffortName } from '@molecule/app-ai-models';
|
|
25
26
|
export { defaultEffortForModel, effortOptionsForModel, nativeEffortName, } from '@molecule/app-ai-models';
|
|
26
27
|
/**
|
|
27
28
|
* Parses an `/effort [--plan|--execute] [arg]` command. Purely syntactic — the
|
|
@@ -96,4 +97,44 @@ export function modelsSupportingEffort(models) {
|
|
|
96
97
|
export function effortLevelsForModel(model) {
|
|
97
98
|
return model?.supportedEffortLevels ?? [];
|
|
98
99
|
}
|
|
100
|
+
/**
|
|
101
|
+
* The effort levels the open `/effort` picker lists, narrowed by any typed
|
|
102
|
+
* filter: the text after `/effort` (minus a mode flag) matches case-insensitively
|
|
103
|
+
* against each level's native value, so `/effort xh` narrows to `xhigh`. With no
|
|
104
|
+
* typed query every option is listed.
|
|
105
|
+
*
|
|
106
|
+
* @param text - The picker's raw input text.
|
|
107
|
+
* @param options - The scoped mode's model's options (see {@link effortOptionsForModel}).
|
|
108
|
+
* @returns The options matching the typed query (the whole list when empty).
|
|
109
|
+
*/
|
|
110
|
+
export function effortPickerVisibleOptions(text, options) {
|
|
111
|
+
const typed = parseEffortCommand(text);
|
|
112
|
+
const q = typed?.kind === 'set' ? typed.arg.toLowerCase() : '';
|
|
113
|
+
if (!q)
|
|
114
|
+
return [...options];
|
|
115
|
+
return options.filter((o) => o.value.toLowerCase().includes(q));
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* The localized one-line status of a mode's reasoning effort — the `/effort ?`
|
|
119
|
+
* view's per-mode line. States whether the mode's model is fixed (one reasoning
|
|
120
|
+
* mode) or lists its current level and every available one.
|
|
121
|
+
*
|
|
122
|
+
* @param t - The caller's translate function (React passes `useTranslation()`'s `t`).
|
|
123
|
+
* @param mode - The conversation mode to describe.
|
|
124
|
+
* @param model - The model the mode will actually run, or `undefined`.
|
|
125
|
+
* @param currentEffort - The persisted per-mode value (or the legacy fallback).
|
|
126
|
+
* @returns The localized status line.
|
|
127
|
+
*/
|
|
128
|
+
export function effortModeStatusLine(t, mode, model, currentEffort) {
|
|
129
|
+
const options = effortOptionsForModel(model);
|
|
130
|
+
const current = nativeEffortName(model, currentEffort);
|
|
131
|
+
return current === null || options.length === 0
|
|
132
|
+
? t('ide.chat.effort.modeFixed', { mode, model: model?.label ?? '?' }, { defaultValue: ' {{mode}} ({{model}}): fixed — this model has one reasoning mode' })
|
|
133
|
+
: t('ide.chat.effort.modeLine', {
|
|
134
|
+
mode,
|
|
135
|
+
model: model?.label ?? '?',
|
|
136
|
+
current,
|
|
137
|
+
levels: options.map((o) => o.value).join(', '),
|
|
138
|
+
}, { defaultValue: ' {{mode}} ({{model}}): {{current}} — available: {{levels}}' });
|
|
139
|
+
}
|
|
99
140
|
//# sourceMappingURL=chat-effort-utilities.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chat-effort-utilities.js","sourceRoot":"","sources":["../../src/components/chat-effort-utilities.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;
|
|
1
|
+
{"version":3,"file":"chat-effort-utilities.js","sourceRoot":"","sources":["../../src/components/chat-effort-utilities.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAGH,OAAO,EAAE,qBAAqB,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAA;AAIjF,OAAO,EACL,qBAAqB,EACrB,qBAAqB,EACrB,gBAAgB,GACjB,MAAM,yBAAyB,CAAA;AA6BhC;;;;;;;GAOG;AACH,MAAM,UAAU,kBAAkB,CAAC,KAAa;IAC9C,MAAM,KAAK,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,yBAAyB,CAAC,CAAA;IAC3D,IAAI,CAAC,KAAK;QAAE,OAAO,IAAI,CAAA;IACvB,MAAM,MAAM,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAA;IACnE,IAAI,IAA4B,CAAA;IAChC,MAAM,IAAI,GAAa,EAAE,CAAA;IACzB,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QAC3B,MAAM,KAAK,GAAG,KAAK,CAAC,WAAW,EAAE,CAAA;QACjC,IAAI,KAAK,KAAK,QAAQ;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,CAChF,CAAA;AACP,CAAC"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Framework-neutral formatting helpers for the IDE chat panel: relative
|
|
3
|
+
* timestamps, the AI-allowance reset countdown, file-attachment encoding, byte
|
|
4
|
+
* sizes, thinking-block durations, the closeable panel-overlay headings, and
|
|
5
|
+
* the live streaming-activity label. Shared verbatim by every framework's chat
|
|
6
|
+
* panel (React's `ChatPanel` re-exports them through `@molecule/app-ide-react`).
|
|
7
|
+
*
|
|
8
|
+
* @module
|
|
9
|
+
*/
|
|
10
|
+
import type { ChatMessage } from '@molecule/app-ai-chat';
|
|
11
|
+
import type { TranslateFunction } from '@molecule/app-i18n';
|
|
12
|
+
/**
|
|
13
|
+
* Formats an ISO timestamp as a relative time string (e.g. "5m ago", "2h ago").
|
|
14
|
+
* @param iso - The ISO 8601 timestamp string.
|
|
15
|
+
* @returns A human-readable relative time string.
|
|
16
|
+
*/
|
|
17
|
+
export declare function relativeTime(iso: string): string;
|
|
18
|
+
/**
|
|
19
|
+
* Format an AI-allowance window reset (epoch ms) as a short countdown phrase for
|
|
20
|
+
* the /cost used-up line ("refreshes in about 3 hours"). Under an hour reads "in
|
|
21
|
+
* under an hour"; ≥ 6h out on a later local calendar day reads "tomorrow"; a day
|
|
22
|
+
* or more out reads "in about N days".
|
|
23
|
+
*
|
|
24
|
+
* The day scale is what makes this usable on a BILLING-PERIOD allowance, which
|
|
25
|
+
* can be weeks out — an hours-only formatter capped at "tomorrow", so a window
|
|
26
|
+
* ending in 18 days told the user it came back in the morning.
|
|
27
|
+
*
|
|
28
|
+
* @param t - The translation function from `useTranslation()`.
|
|
29
|
+
* @param resetAt - Epoch ms of the window end (always in the future from the API).
|
|
30
|
+
* @returns A localized human countdown phrase.
|
|
31
|
+
*/
|
|
32
|
+
export declare function allowanceResetCountdown(t: TranslateFunction, resetAt: number): string;
|
|
33
|
+
/**
|
|
34
|
+
* Reads a File as base64 (without data-URL prefix).
|
|
35
|
+
* @param file - The file to encode.
|
|
36
|
+
* @returns Base64-encoded string.
|
|
37
|
+
*/
|
|
38
|
+
export declare function fileToBase64(file: File): Promise<string>;
|
|
39
|
+
/**
|
|
40
|
+
* Formats a byte count as a human-readable size string.
|
|
41
|
+
* @param bytes - The size in bytes.
|
|
42
|
+
* @returns Formatted string (e.g., "1.2MB").
|
|
43
|
+
*/
|
|
44
|
+
export declare function formatSize(bytes: number): string;
|
|
45
|
+
/**
|
|
46
|
+
* Format a duration in milliseconds as a human-readable string.
|
|
47
|
+
* @param t - The translation function from `useTranslation()`.
|
|
48
|
+
* @param ms - Duration in milliseconds.
|
|
49
|
+
* @returns Formatted string like "Thought for 5 seconds" or "Thought for 2 minutes".
|
|
50
|
+
*/
|
|
51
|
+
export declare function formatThinkingDuration(t: TranslateFunction, ms: number): string;
|
|
52
|
+
/** The heading of the closeable panel overlay (/skills, /scripts, /settings) above the composer. */
|
|
53
|
+
export declare function panelOverlayHeading(t: TranslateFunction, overlay: 'skills' | 'scripts' | 'settings' | 'tests'): string;
|
|
54
|
+
/**
|
|
55
|
+
* Derive a real current-activity label for the streaming indicator from the
|
|
56
|
+
* in-flight assistant message's latest block, so the user sees what's actually
|
|
57
|
+
* happening (e.g. "Reading App.tsx", "Writing the plan") instead of a generic
|
|
58
|
+
* spinner. Returns undefined when there's nothing specific to show (the
|
|
59
|
+
* indicator then falls back to its rotating generic messages).
|
|
60
|
+
*
|
|
61
|
+
* @param t - The translation function from `useTranslation()`.
|
|
62
|
+
* @param msg - The streaming assistant message.
|
|
63
|
+
* @param msg.blocks - The message's ordered blocks (a tool call is a `tool_call` block naming its id).
|
|
64
|
+
* @param msg.toolCalls - The message's tool calls, looked up by block id.
|
|
65
|
+
* @returns A short activity label, or undefined.
|
|
66
|
+
*/
|
|
67
|
+
export declare function streamingActivityLabel(t: TranslateFunction, msg: {
|
|
68
|
+
blocks?: ChatMessage['blocks'];
|
|
69
|
+
toolCalls?: Array<Pick<NonNullable<ChatMessage['toolCalls']>[number], 'id' | 'name' | 'input'>>;
|
|
70
|
+
}): string | undefined;
|
|
71
|
+
//# sourceMappingURL=chat-format-utilities.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chat-format-utilities.d.ts","sourceRoot":"","sources":["../../src/components/chat-format-utilities.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AACxD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAA;AAI3D;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAShD;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,uBAAuB,CAAC,CAAC,EAAE,iBAAiB,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CA0BrF;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,CAUxD;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAIhD;AAED;;;;;GAKG;AACH,wBAAgB,sBAAsB,CAAC,CAAC,EAAE,iBAAiB,EAAE,EAAE,EAAE,MAAM,GAAG,MAAM,CA4B/E;AAED,oGAAoG;AACpG,wBAAgB,mBAAmB,CACjC,CAAC,EAAE,iBAAiB,EACpB,OAAO,EAAE,QAAQ,GAAG,SAAS,GAAG,UAAU,GAAG,OAAO,GACnD,MAAM,CAQR;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,sBAAsB,CACpC,CAAC,EAAE,iBAAiB,EACpB,GAAG,EAAE;IACH,MAAM,CAAC,EAAE,WAAW,CAAC,QAAQ,CAAC,CAAA;IAC9B,SAAS,CAAC,EAAE,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,WAAW,CAAC,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,EAAE,IAAI,GAAG,MAAM,GAAG,OAAO,CAAC,CAAC,CAAA;CAChG,GACA,MAAM,GAAG,SAAS,CAgDpB"}
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Framework-neutral formatting helpers for the IDE chat panel: relative
|
|
3
|
+
* timestamps, the AI-allowance reset countdown, file-attachment encoding, byte
|
|
4
|
+
* sizes, thinking-block durations, the closeable panel-overlay headings, and
|
|
5
|
+
* the live streaming-activity label. Shared verbatim by every framework's chat
|
|
6
|
+
* panel (React's `ChatPanel` re-exports them through `@molecule/app-ide-react`).
|
|
7
|
+
*
|
|
8
|
+
* @module
|
|
9
|
+
*/
|
|
10
|
+
import { readFilePaths, str } from './tool-call-utilities.js';
|
|
11
|
+
/**
|
|
12
|
+
* Formats an ISO timestamp as a relative time string (e.g. "5m ago", "2h ago").
|
|
13
|
+
* @param iso - The ISO 8601 timestamp string.
|
|
14
|
+
* @returns A human-readable relative time string.
|
|
15
|
+
*/
|
|
16
|
+
export function relativeTime(iso) {
|
|
17
|
+
const ms = Date.now() - new Date(iso).getTime();
|
|
18
|
+
const min = Math.floor(ms / 60_000);
|
|
19
|
+
if (min < 1)
|
|
20
|
+
return 'just now';
|
|
21
|
+
if (min < 60)
|
|
22
|
+
return `${min}m ago`;
|
|
23
|
+
const h = Math.floor(min / 60);
|
|
24
|
+
if (h < 24)
|
|
25
|
+
return `${h}h ago`;
|
|
26
|
+
const d = Math.floor(h / 24);
|
|
27
|
+
return `${d}d ago`;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Format an AI-allowance window reset (epoch ms) as a short countdown phrase for
|
|
31
|
+
* the /cost used-up line ("refreshes in about 3 hours"). Under an hour reads "in
|
|
32
|
+
* under an hour"; ≥ 6h out on a later local calendar day reads "tomorrow"; a day
|
|
33
|
+
* or more out reads "in about N days".
|
|
34
|
+
*
|
|
35
|
+
* The day scale is what makes this usable on a BILLING-PERIOD allowance, which
|
|
36
|
+
* can be weeks out — an hours-only formatter capped at "tomorrow", so a window
|
|
37
|
+
* ending in 18 days told the user it came back in the morning.
|
|
38
|
+
*
|
|
39
|
+
* @param t - The translation function from `useTranslation()`.
|
|
40
|
+
* @param resetAt - Epoch ms of the window end (always in the future from the API).
|
|
41
|
+
* @returns A localized human countdown phrase.
|
|
42
|
+
*/
|
|
43
|
+
export function allowanceResetCountdown(t, resetAt) {
|
|
44
|
+
const diffMs = resetAt - Date.now();
|
|
45
|
+
if (!Number.isFinite(diffMs) || diffMs <= 0) {
|
|
46
|
+
return t('ide.chat.resetSoon', undefined, { defaultValue: 'soon' });
|
|
47
|
+
}
|
|
48
|
+
const hours = diffMs / 3_600_000;
|
|
49
|
+
if (hours < 1) {
|
|
50
|
+
return t('ide.chat.resetUnderHour', undefined, { defaultValue: 'in under an hour' });
|
|
51
|
+
}
|
|
52
|
+
if (hours >= 24) {
|
|
53
|
+
const days = Math.round(hours / 24);
|
|
54
|
+
if (days <= 1) {
|
|
55
|
+
return t('ide.chat.resetTomorrow', undefined, { defaultValue: 'tomorrow' });
|
|
56
|
+
}
|
|
57
|
+
return t('ide.chat.resetInDays', { days }, { defaultValue: 'in about {{days}} days' });
|
|
58
|
+
}
|
|
59
|
+
const rounded = Math.round(hours);
|
|
60
|
+
const laterLocalDay = new Date(resetAt).toDateString() !== new Date().toDateString();
|
|
61
|
+
if (laterLocalDay && rounded >= 6) {
|
|
62
|
+
return t('ide.chat.resetTomorrow', undefined, { defaultValue: 'tomorrow' });
|
|
63
|
+
}
|
|
64
|
+
return t('ide.chat.resetInHours', { hours: rounded }, { defaultValue: 'in about {{hours}} hours' });
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Reads a File as base64 (without data-URL prefix).
|
|
68
|
+
* @param file - The file to encode.
|
|
69
|
+
* @returns Base64-encoded string.
|
|
70
|
+
*/
|
|
71
|
+
export function fileToBase64(file) {
|
|
72
|
+
return new Promise((resolve, reject) => {
|
|
73
|
+
const reader = new FileReader();
|
|
74
|
+
reader.onload = () => {
|
|
75
|
+
const result = reader.result;
|
|
76
|
+
resolve(result.split(',')[1]);
|
|
77
|
+
};
|
|
78
|
+
reader.onerror = reject;
|
|
79
|
+
reader.readAsDataURL(file);
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Formats a byte count as a human-readable size string.
|
|
84
|
+
* @param bytes - The size in bytes.
|
|
85
|
+
* @returns Formatted string (e.g., "1.2MB").
|
|
86
|
+
*/
|
|
87
|
+
export function formatSize(bytes) {
|
|
88
|
+
if (bytes < 1024)
|
|
89
|
+
return `${bytes}B`;
|
|
90
|
+
if (bytes < 1048576)
|
|
91
|
+
return `${Math.round(bytes / 1024)}KB`;
|
|
92
|
+
return `${(bytes / 1048576).toFixed(1)}MB`;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Format a duration in milliseconds as a human-readable string.
|
|
96
|
+
* @param t - The translation function from `useTranslation()`.
|
|
97
|
+
* @param ms - Duration in milliseconds.
|
|
98
|
+
* @returns Formatted string like "Thought for 5 seconds" or "Thought for 2 minutes".
|
|
99
|
+
*/
|
|
100
|
+
export function formatThinkingDuration(t, ms) {
|
|
101
|
+
if (ms < 1000)
|
|
102
|
+
return t('ide.chat.thoughtBriefly', undefined, { defaultValue: 'Thought briefly' });
|
|
103
|
+
const seconds = Math.round(ms / 1000);
|
|
104
|
+
if (seconds < 60) {
|
|
105
|
+
// Singular/plural split (the codebase's pluralization convention, e.g.
|
|
106
|
+
// typeErrorCount/typeErrorsCount): each key is a clean i18n template so the
|
|
107
|
+
// bond value matches the inline default verbatim and interpolates {{count}}
|
|
108
|
+
// — never a JS `${}` literal, which a bond value would silently override.
|
|
109
|
+
return seconds === 1
|
|
110
|
+
? t('ide.chat.thoughtForSecond', { count: seconds }, { defaultValue: 'Thought for 1 second' })
|
|
111
|
+
: t('ide.chat.thoughtForSeconds', { count: seconds }, {
|
|
112
|
+
defaultValue: 'Thought for {{count}} seconds',
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
const minutes = Math.round(seconds / 60);
|
|
116
|
+
return minutes === 1
|
|
117
|
+
? t('ide.chat.thoughtForMinute', { count: minutes }, { defaultValue: 'Thought for 1 minute' })
|
|
118
|
+
: t('ide.chat.thoughtForMinutes', { count: minutes }, {
|
|
119
|
+
defaultValue: 'Thought for {{count}} minutes',
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
/** The heading of the closeable panel overlay (/skills, /scripts, /settings) above the composer. */
|
|
123
|
+
export function panelOverlayHeading(t, overlay) {
|
|
124
|
+
return overlay === 'skills'
|
|
125
|
+
? t('ide.chat.skills.heading', undefined, { defaultValue: 'Skills' })
|
|
126
|
+
: overlay === 'scripts'
|
|
127
|
+
? t('ide.chat.scripts.heading', undefined, { defaultValue: 'Scripts' })
|
|
128
|
+
: overlay === 'tests'
|
|
129
|
+
? t('ide.tests.heading', undefined, { defaultValue: 'Tests' })
|
|
130
|
+
: t('ide.chat.settings.heading', undefined, { defaultValue: 'Settings' });
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Derive a real current-activity label for the streaming indicator from the
|
|
134
|
+
* in-flight assistant message's latest block, so the user sees what's actually
|
|
135
|
+
* happening (e.g. "Reading App.tsx", "Writing the plan") instead of a generic
|
|
136
|
+
* spinner. Returns undefined when there's nothing specific to show (the
|
|
137
|
+
* indicator then falls back to its rotating generic messages).
|
|
138
|
+
*
|
|
139
|
+
* @param t - The translation function from `useTranslation()`.
|
|
140
|
+
* @param msg - The streaming assistant message.
|
|
141
|
+
* @param msg.blocks - The message's ordered blocks (a tool call is a `tool_call` block naming its id).
|
|
142
|
+
* @param msg.toolCalls - The message's tool calls, looked up by block id.
|
|
143
|
+
* @returns A short activity label, or undefined.
|
|
144
|
+
*/
|
|
145
|
+
export function streamingActivityLabel(t, msg) {
|
|
146
|
+
const blocks = msg.blocks;
|
|
147
|
+
if (!blocks || blocks.length === 0)
|
|
148
|
+
return undefined;
|
|
149
|
+
const last = blocks[blocks.length - 1];
|
|
150
|
+
if (last.type === 'thinking')
|
|
151
|
+
return t('ide.chat.activity.thinking', undefined, { defaultValue: 'Synthesizing' });
|
|
152
|
+
if (last.type !== 'tool_call')
|
|
153
|
+
return undefined;
|
|
154
|
+
const tc = msg.toolCalls?.find((c) => c.id === last.id);
|
|
155
|
+
if (!tc)
|
|
156
|
+
return undefined;
|
|
157
|
+
// `tc.input` is model-authored, so each field is read through `str()` rather
|
|
158
|
+
// than trusted from the cast: a field the schema declares `string` can arrive
|
|
159
|
+
// as a number or object (the shape that blanked production on 2026-08-14 —
|
|
160
|
+
// see `str()`'s docs), and `base()` calls `.split` on it, which throws a
|
|
161
|
+
// TypeError from inside this render — taking the whole IDE down, not one row.
|
|
162
|
+
const inp = (tc.input ?? {});
|
|
163
|
+
const base = (p) => (p ? (p.split('/').filter(Boolean).pop() ?? p) : '');
|
|
164
|
+
const clip = (s, n = 48) => (s && s.length > n ? `${s.slice(0, n)}…` : (s ?? ''));
|
|
165
|
+
switch (tc.name) {
|
|
166
|
+
case 'read_file': {
|
|
167
|
+
const files = readFilePaths(tc.input);
|
|
168
|
+
const more = files.length > 1 ? ` +${files.length - 1}` : '';
|
|
169
|
+
return `${t('ide.chat.activity.reading', undefined, { defaultValue: 'Reading' })} ${base(files[0])}${more}`;
|
|
170
|
+
}
|
|
171
|
+
case 'write_file':
|
|
172
|
+
return `${t('ide.chat.activity.writing', undefined, { defaultValue: 'Writing' })} ${base(str(inp.path))}`;
|
|
173
|
+
case 'edit_file':
|
|
174
|
+
return `${t('ide.chat.activity.editing', undefined, { defaultValue: 'Editing' })} ${base(str(inp.path))}`;
|
|
175
|
+
case 'search_files':
|
|
176
|
+
return `${t('ide.chat.activity.searching', undefined, { defaultValue: 'Searching' })} ${clip(str(inp.query))}`;
|
|
177
|
+
case 'list_files':
|
|
178
|
+
case 'find_files':
|
|
179
|
+
return t('ide.chat.activity.exploring', undefined, { defaultValue: 'Exploring files' });
|
|
180
|
+
case 'exec_command':
|
|
181
|
+
return `${t('ide.chat.activity.running', undefined, { defaultValue: 'Running' })} ${clip(str(inp.command))}`;
|
|
182
|
+
case 'save_plan':
|
|
183
|
+
return t('ide.chat.activity.writingPlan', undefined, { defaultValue: 'Writing the plan' });
|
|
184
|
+
case 'sandbox_fetch':
|
|
185
|
+
return `${t('ide.chat.activity.fetching', undefined, { defaultValue: 'Fetching' })} ${clip(str(inp.url))}`;
|
|
186
|
+
case 'set_mode':
|
|
187
|
+
return t('ide.chat.activity.switching', undefined, { defaultValue: 'Switching mode' });
|
|
188
|
+
default:
|
|
189
|
+
return undefined;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
//# sourceMappingURL=chat-format-utilities.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chat-format-utilities.js","sourceRoot":"","sources":["../../src/components/chat-format-utilities.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAKH,OAAO,EAAE,aAAa,EAAE,GAAG,EAAE,MAAM,0BAA0B,CAAA;AAE7D;;;;GAIG;AACH,MAAM,UAAU,YAAY,CAAC,GAAW;IACtC,MAAM,EAAE,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,IAAI,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,CAAA;IAC/C,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,EAAE,GAAG,MAAM,CAAC,CAAA;IACnC,IAAI,GAAG,GAAG,CAAC;QAAE,OAAO,UAAU,CAAA;IAC9B,IAAI,GAAG,GAAG,EAAE;QAAE,OAAO,GAAG,GAAG,OAAO,CAAA;IAClC,MAAM,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,GAAG,EAAE,CAAC,CAAA;IAC9B,IAAI,CAAC,GAAG,EAAE;QAAE,OAAO,GAAG,CAAC,OAAO,CAAA;IAC9B,MAAM,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,CAAC,CAAA;IAC5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AAC,EAAE,CAAA;QAChH,KAAK,YAAY,CAAC;QAClB,KAAK,YAAY;YACf,OAAO,CAAC,CAAC,6BAA6B,EAAE,SAAS,EAAE,EAAE,YAAY,EAAE,iBAAiB,EAAE,CAAC,CAAA;QACzF,KAAK,cAAc;YACjB,OAAO,GAAG,CAAC,CAAC,2BAA2B,EAAE,SAAS,EAAE,EAAE,YAAY,EAAE,SAAS,EAAE,CAAC,IAAI,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,EAAE,CAAA;QAC9G,KAAK,WAAW;YACd,OAAO,CAAC,CAAC,+BAA+B,EAAE,SAAS,EAAE,EAAE,YAAY,EAAE,kBAAkB,EAAE,CAAC,CAAA;QAC5F,KAAK,eAAe;YAClB,OAAO,GAAG,CAAC,CAAC,4BAA4B,EAAE,SAAS,EAAE,EAAE,YAAY,EAAE,UAAU,EAAE,CAAC,IAAI,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,EAAE,CAAA;QAC5G,KAAK,UAAU;YACb,OAAO,CAAC,CAAC,6BAA6B,EAAE,SAAS,EAAE,EAAE,YAAY,EAAE,gBAAgB,EAAE,CAAC,CAAA;QACxF;YACE,OAAO,SAAS,CAAA;IACpB,CAAC;AACH,CAAC"}
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
*/
|
|
10
10
|
import type { AppModelDefinition } from '@molecule/app-ai-models';
|
|
11
11
|
import type { TranslateFunction } from '@molecule/app-i18n';
|
|
12
|
+
import type { FreeTierLockReason, ModelMode, PerModeModelSettings, ServerModeDefaults } from './chat-model-mode-utilities.js';
|
|
12
13
|
/**
|
|
13
14
|
* Sortable columns in the `/models` table.
|
|
14
15
|
*
|
|
@@ -175,4 +176,171 @@ export declare function sortModels(models: readonly AppModelDefinition[], column
|
|
|
175
176
|
* @returns The localized region label.
|
|
176
177
|
*/
|
|
177
178
|
export declare function modelRegionLabel(t: TranslateFunction, region: ModelProcessingRegion): string;
|
|
179
|
+
/**
|
|
180
|
+
* Every region the picker can offer: the flag's country code (resolved via the
|
|
181
|
+
* bonded `@molecule/app-country-flags` set). The region's display NAME comes from
|
|
182
|
+
* {@link modelRegionLabel} (the literal `ide.chat.model.region.<code>` keys).
|
|
183
|
+
* Adding a region here (plus a server-side provider registration) is ALL the UI
|
|
184
|
+
* needs — the region control's menu lists whatever {@link availableModelRegions}
|
|
185
|
+
* returns.
|
|
186
|
+
*/
|
|
187
|
+
export declare const MODEL_REGION_FLAGS: Record<string, string>;
|
|
188
|
+
/**
|
|
189
|
+
* Regions a model can be processed in, first entry = its default — straight
|
|
190
|
+
* from the catalog (`AppModelDefinition.regions`; the server enforces the same
|
|
191
|
+
* list). A single-entry list is a pinned model (fixed, non-interactive flag);
|
|
192
|
+
* omission means the US-only platform default. The control/menu UI renders
|
|
193
|
+
* whatever this returns, so new regions only need catalog data + a
|
|
194
|
+
* `MODEL_REGION_FLAGS` entry.
|
|
195
|
+
* @param model - The model to resolve regions for.
|
|
196
|
+
* @returns Available region codes, default first.
|
|
197
|
+
*/
|
|
198
|
+
export declare function availableModelRegions(model: AppModelDefinition): ModelProcessingRegion[];
|
|
199
|
+
/**
|
|
200
|
+
* The replacement chosen when a saved model has left the catalog, plus the
|
|
201
|
+
* notice the chat panel shows the user about it.
|
|
202
|
+
*/
|
|
203
|
+
export interface RemovedModelFallback {
|
|
204
|
+
/** The model id to fall back to, or `null` when no replacement exists. */
|
|
205
|
+
fallback: string | null;
|
|
206
|
+
/** The already-localized notice to surface for the removal. */
|
|
207
|
+
notice: string;
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Decides what the removed-model effect does: which still-available model
|
|
211
|
+
* replaces a model that left the catalog, and the notice it shows. Prefers a
|
|
212
|
+
* still-available model from the SAME custom provider before a platform model,
|
|
213
|
+
* so a BYO provider's renamed model keeps the user on their own endpoint
|
|
214
|
+
* rather than bouncing them to a platform free model.
|
|
215
|
+
*
|
|
216
|
+
* @param removedId - The saved model id that is no longer in the catalog.
|
|
217
|
+
* @param models - The available models from the catalog.
|
|
218
|
+
* @param freeTierModel - The catalog's free-tier model id (may be empty).
|
|
219
|
+
* @param t - The caller's translate function (React passes `useTranslation()`'s `t`).
|
|
220
|
+
* @returns The fallback id (or `null`) and the localized notice to show.
|
|
221
|
+
*/
|
|
222
|
+
export declare function resolveRemovedModelFallback(removedId: string, models: readonly AppModelDefinition[], freeTierModel: string, t: TranslateFunction): RemovedModelFallback;
|
|
223
|
+
/**
|
|
224
|
+
* Filters the catalog for the `/model` picker's open query. For a mode-scoped
|
|
225
|
+
* command the filter is the text after the flag; otherwise it is the text after
|
|
226
|
+
* `/model `. Matches the model id or label case-insensitively; an empty query
|
|
227
|
+
* returns every model unchanged.
|
|
228
|
+
*
|
|
229
|
+
* @param text - The picker's raw input text.
|
|
230
|
+
* @param models - The available models from the catalog.
|
|
231
|
+
* @returns The models matching the query (the whole list when the query is empty).
|
|
232
|
+
*/
|
|
233
|
+
export declare function filterModelsByPickerQuery(text: string, models: AppModelDefinition[]): AppModelDefinition[];
|
|
234
|
+
/**
|
|
235
|
+
* Resolves a `/model <query>` argument to the closest catalog model: an exact
|
|
236
|
+
* id match first, then a case-insensitive id substring, then a label substring.
|
|
237
|
+
*
|
|
238
|
+
* @param query - The raw typed query (the text after `/model`).
|
|
239
|
+
* @param models - The available models from the catalog.
|
|
240
|
+
* @returns The resolved model, or `undefined` when nothing matches.
|
|
241
|
+
*/
|
|
242
|
+
export declare function resolveModelQuery(query: string, models: readonly AppModelDefinition[]): AppModelDefinition | undefined;
|
|
243
|
+
/**
|
|
244
|
+
* The row that gets the "current" pill in the `/model` picker — the model the
|
|
245
|
+
* selected picker mode actually uses (its per-mode value with the mode's REAL
|
|
246
|
+
* fallback chain), not unconditionally the legacy `chatModel`. The generic
|
|
247
|
+
* (no-mode) picker edits the default slot, so its pill is the SAVED default
|
|
248
|
+
* only — a seeded catalog default is not a choice and must not masquerade as
|
|
249
|
+
* one.
|
|
250
|
+
*
|
|
251
|
+
* @param picker - The open picker (`null` when closed).
|
|
252
|
+
* @param effectiveModelForMode - Resolves the model a conversation mode uses.
|
|
253
|
+
* @param settings - The project's persisted model settings.
|
|
254
|
+
* @param serverDefaults - Server-sent per-mode defaults (`GET /ai/models`).
|
|
255
|
+
* @returns The current model id, or `undefined` when none applies.
|
|
256
|
+
*/
|
|
257
|
+
export declare function pickerCurrentModelId(picker: {
|
|
258
|
+
mode?: ModelMode;
|
|
259
|
+
} | null, effectiveModelForMode: (mode: 'plan' | 'execute') => string, settings: PerModeModelSettings, serverDefaults: ServerModeDefaults): string | undefined;
|
|
260
|
+
/** One capability badge shown on a model picker row. */
|
|
261
|
+
export interface ModelPickerBadge {
|
|
262
|
+
/** The badge text (an untranslated capability name today). */
|
|
263
|
+
label: string;
|
|
264
|
+
/** Background tint. */
|
|
265
|
+
bg: string;
|
|
266
|
+
/** Text tint. */
|
|
267
|
+
fg: string;
|
|
268
|
+
}
|
|
269
|
+
/** The region pill's pre-rendered data (rendered only when {@link show}). */
|
|
270
|
+
export interface ModelPickerRegionPill {
|
|
271
|
+
/** Whether the row shows a region pill at all. */
|
|
272
|
+
show: boolean;
|
|
273
|
+
/** The regions the model can be processed in, default first. */
|
|
274
|
+
options: ModelProcessingRegion[];
|
|
275
|
+
/** The model's effective region. */
|
|
276
|
+
region: ModelProcessingRegion;
|
|
277
|
+
/** Whether the region is user-changeable (more than one option). */
|
|
278
|
+
interactive: boolean;
|
|
279
|
+
/** The localized region name. */
|
|
280
|
+
label: string;
|
|
281
|
+
/** The localized pill/menu hint. */
|
|
282
|
+
hint: string;
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* Everything a `/model` picker row computes before its JSX: its capability
|
|
286
|
+
* badges, the free-tier lock reason, the "free in <mode>" label, the relative
|
|
287
|
+
* usage rate and its price colour, and the processing-region pill.
|
|
288
|
+
*/
|
|
289
|
+
export interface ModelPickerRowView {
|
|
290
|
+
/** Capability badges in display order. */
|
|
291
|
+
badges: ModelPickerBadge[];
|
|
292
|
+
/** Why the row is locked for a free-tier user, or `null` when selectable. */
|
|
293
|
+
lockReason: FreeTierLockReason | null;
|
|
294
|
+
/** Convenience boolean view of {@link lockReason}. */
|
|
295
|
+
locked: boolean;
|
|
296
|
+
/** The mode a free-tier user can actually use this model in, if any. */
|
|
297
|
+
usableMode: ModelMode | null;
|
|
298
|
+
/** The localized "free in <mode>" label. */
|
|
299
|
+
freeInLabel: string;
|
|
300
|
+
/** Whether this is a bring-your-own-AI (custom provider) model. */
|
|
301
|
+
isCustom: boolean;
|
|
302
|
+
/** Relative allowance usage rate (`×N`). */
|
|
303
|
+
usageRate: number;
|
|
304
|
+
/** The peak multiplier in force right now. */
|
|
305
|
+
peakNow: number;
|
|
306
|
+
/** The colour the usage-rate figure renders in. */
|
|
307
|
+
priceColor: string;
|
|
308
|
+
/** The model's effective processing region. */
|
|
309
|
+
modelRegion: ModelProcessingRegion;
|
|
310
|
+
/** The region pill's data (rendered only when {@link ModelPickerRegionPill.show}). */
|
|
311
|
+
regionPill: ModelPickerRegionPill;
|
|
312
|
+
/** The provider brand accent colour. */
|
|
313
|
+
accent: string;
|
|
314
|
+
}
|
|
315
|
+
/** The inputs {@link modelPickerRowView} reads for one row. */
|
|
316
|
+
export interface ModelPickerRowInput {
|
|
317
|
+
/** The catalog model the row renders. */
|
|
318
|
+
model: AppModelDefinition;
|
|
319
|
+
/** Whether the app is in light theme (badge and price tints). */
|
|
320
|
+
isLight: boolean;
|
|
321
|
+
/** Whether the current user is on the free/anon tier. */
|
|
322
|
+
isFreeTier: boolean;
|
|
323
|
+
/** The picker's scoped mode, or undefined for the unscoped picker. */
|
|
324
|
+
mode?: ModelMode;
|
|
325
|
+
/** The full available-model catalog. */
|
|
326
|
+
models: readonly AppModelDefinition[];
|
|
327
|
+
/** Server-sent per-mode defaults (`GET /ai/models`). */
|
|
328
|
+
serverDefaults: ServerModeDefaults;
|
|
329
|
+
/** The catalog's free-tier model id. */
|
|
330
|
+
freeTierModel: string;
|
|
331
|
+
/** The row model's effective processing region. */
|
|
332
|
+
modelRegion: ModelProcessingRegion;
|
|
333
|
+
/** The caller's translate function. */
|
|
334
|
+
t: TranslateFunction;
|
|
335
|
+
}
|
|
336
|
+
/**
|
|
337
|
+
* Computes everything a `/model` picker row needs before rendering its JSX:
|
|
338
|
+
* capability badges, the free-tier lock reason, the "free in <mode>" label, the
|
|
339
|
+
* relative usage rate and price colour, and the processing-region pill.
|
|
340
|
+
*
|
|
341
|
+
* @param input - The row's model plus the render-time context (theme, tier,
|
|
342
|
+
* scoped mode, catalog, server defaults, effective region, translate function).
|
|
343
|
+
* @returns The pre-computed {@link ModelPickerRowView}.
|
|
344
|
+
*/
|
|
345
|
+
export declare function modelPickerRowView(input: ModelPickerRowInput): ModelPickerRowView;
|
|
178
346
|
//# sourceMappingURL=chat-models-utilities.d.ts.map
|
|
@@ -1 +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;
|
|
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,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAA;AAE3D,OAAO,KAAK,EACV,kBAAkB,EAClB,SAAS,EACT,oBAAoB,EACpB,kBAAkB,EACnB,MAAM,gCAAgC,CAAA;AAQvC;;;;;;;;;GASG;AACH,MAAM,MAAM,eAAe,GAAG,MAAM,GAAG,SAAS,GAAG,MAAM,GAAG,QAAQ,GAAG,MAAM,GAAG,QAAQ,CAAA;AAExF,sBAAsB;AACtB,MAAM,MAAM,aAAa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