Skip to content

Commit b8767f0

Browse files
committed
Implement token count retrieval in prompt view
- hook should also ask for token count upon initialization
1 parent 15ba311 commit b8767f0

6 files changed

Lines changed: 37 additions & 2 deletions

File tree

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { PromptViewProvider } from '../prompt-view-provider'
2+
3+
export const handle_get_token_count = async (
4+
prompt_view_provider: PromptViewProvider
5+
) => {
6+
let context_token_count = 0
7+
8+
if (!prompt_view_provider.workspace_provider.is_no_context_mode) {
9+
const token_counts =
10+
await prompt_view_provider.workspace_provider.get_checked_files_token_count()
11+
context_token_count = prompt_view_provider.workspace_provider
12+
.use_shrink_token_count
13+
? token_counts.shrink
14+
: token_counts.total
15+
}
16+
17+
prompt_view_provider.send_message({
18+
command: 'TOKEN_COUNT_UPDATED',
19+
token_count: context_token_count
20+
})
21+
}

‎apps/editor/src/views/prompt/backend/message-handlers/index.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,5 @@ export * from './handle-save-find-relevant-files-shrink-source-code'
7070
export * from './handle-update-last-used-web-configuration-or-group'
7171
export * from './handle-return-home-and-switch-to-edit-files'
7272
export * from './handle-pick-tasks-workspace'
73+
74+
export * from './handle-get-token-count'

‎apps/editor/src/views/prompt/backend/prompt-view-provider.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@ import {
8383
handle_get_find_relevant_files_shrink_source_code,
8484
handle_save_find_relevant_files_shrink_source_code,
8585
handle_return_home_and_switch_to_edit_files,
86-
handle_pick_tasks_workspace
86+
handle_pick_tasks_workspace,
87+
handle_get_token_count
8788
} from './message-handlers'
8889
import { handle_update_api_configuration } from './message-handlers/handle-update-api-configuration'
8990
import { handle_pick_model_provider } from './message-handlers/handle-pick-model-provider'
@@ -934,6 +935,8 @@ export class PromptViewProvider implements vscode.WebviewViewProvider {
934935
this._send_is_modern_ui()
935936
} else if (message.command == 'PICK_TASKS_WORKSPACE') {
936937
await handle_pick_tasks_workspace(this, message)
938+
} else if (message.command == 'GET_TOKEN_COUNT') {
939+
await handle_get_token_count(this)
937940
}
938941
} catch (error: any) {
939942
Logger.error({

‎apps/editor/src/views/prompt/frontend/hooks/use-prompt/use-prompt.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,8 @@ export const use_prompt = (vscode: any) => {
175175
{ command: 'GET_SETUP_PROGRESS' },
176176
{ command: 'GET_FIND_RELEVANT_FILES_SHRINK_SOURCE_CODE' },
177177
{ command: 'GET_VOICE_INPUT_PUSH_TO_TALK' },
178-
{ command: 'GET_IS_MODERN_UI' }
178+
{ command: 'GET_IS_MODERN_UI' },
179+
{ command: 'GET_TOKEN_COUNT' }
179180
]
180181
initial_messages.forEach((message) => post_message(vscode, message))
181182

‎apps/editor/src/views/prompt/types/messages.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,10 @@ export interface GetIsModernUiMessage extends BaseMessage {
549549
command: 'GET_IS_MODERN_UI'
550550
}
551551

552+
export interface GetTokenCountMessage extends BaseMessage {
553+
command: 'GET_TOKEN_COUNT'
554+
}
555+
552556
export type FrontendMessage =
553557
| GetInstructionsMessage
554558
| SaveInstructionsMessage
@@ -641,6 +645,7 @@ export type FrontendMessage =
641645
| PickApiReasoningEffortMessage
642646
| PickTasksWorkspaceMessage
643647
| GetIsModernUiMessage
648+
| GetTokenCountMessage
644649

645650
// === FROM BACKEND TO FRONTEND ===
646651
export interface InstructionsMessage extends BaseMessage {

‎packages/ui/src/components/editor/prompt/prompts/PromptField/PromptField.module.scss‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,9 @@
214214
text-decoration: dotted;
215215
overflow: hidden;
216216
text-overflow: ellipsis;
217+
text-decoration: underline dotted;
218+
text-underline-offset: 4px;
219+
overflow: visible;
217220

218221
&:hover {
219222
opacity: 1;

0 commit comments

Comments
 (0)