Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:

strategy:
matrix:
os: [macos-14]
os: [macos-26]
node-version: [24.x]

runs-on: ${{ matrix.os }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-wtih-vscode-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:

strategy:
matrix:
os: [macos-14]
os: [macos-26]
node-version: [24.x]

runs-on: ${{ matrix.os }}
Expand Down
5 changes: 3 additions & 2 deletions docs/ai.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,9 @@ The model and MCP services receive the data sent to them under their own service
### Manage saved data

- **Delete one conversation:** open **Show History**, use its delete action, and confirm **Delete**.
- **Export conversations:** in AI Settings, open **General → Export history → Export**. The JSON contains conversation data for the current workspace, including stored message and tool content.
- **Reset AI data:** in **General**, select **Clear all data** and confirm. This removes local AI conversations across all workspaces, model settings and API keys, MCP settings, and prompt settings.
- **Export history:** in **AI Settings → General**, select **Export history** to download all workspaces as JSON, including messages, tool results, and attachments.
- **Import history:** in **General**, select **Import history** and choose a JSON export. The default **Merge + Keep** preserves local conversations with matching IDs in the same workspace. **Overwrite** uses imported conversations; **Replace** replaces all workspace history with the file.
- **Clear all data:** in **General**, select **Clear all data** to delete all workspace history, model settings and API keys, MCP settings, and prompts.

## Troubleshooting

Expand Down
101 changes: 101 additions & 0 deletions extensions/github1s-ai/assets/chat.css
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,107 @@ summary:focus-visible,
border: 1px solid currentColor;
}

.history-import-dialog {
box-sizing: border-box;
width: calc(100% - 24px);
max-width: 300px;
max-height: calc(88vh - 12px);
margin: 12vh auto 12px;
padding: 16px;
color: var(--vscode-foreground);
background: var(--vscode-editorWidget-background, var(--vscode-sideBar-background));
border: 1px solid var(--vscode-widget-border, var(--vscode-input-border));
border-radius: 6px;
box-shadow: 0 2px 12px var(--vscode-widget-shadow, rgba(0, 0, 0, 0.3));
}

.history-import-dialog::backdrop {
background: rgba(0, 0, 0, 0.35);
}

.history-import-content {
display: grid;
min-width: 0;
gap: 16px;
}

.history-import-content h3 {
margin: 0;
font-size: 14px;
}

.history-import-summary {
min-width: 0;
color: var(--vscode-descriptionForeground);
font-size: 12px;
line-height: 1.5;
}

.history-import-summary p {
margin: 0;
}

.history-import-filename {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}

.history-import-field {
min-width: 0;
margin: 0;
padding: 0;
border: 0;
}

.history-import-field legend {
margin-bottom: 6px;
padding: 0;
font-size: 12px;
font-weight: 600;
}

.history-import-label,
.history-import-options,
.history-import-options label {
display: flex;
align-items: center;
gap: 6px;
}

.history-import-label .icon-button {
width: 20px;
height: 20px;
color: var(--vscode-descriptionForeground);
}

.history-import-options {
flex-wrap: wrap;
gap: 8px 20px;
}

.history-import-options input {
margin: 0;
accent-color: var(--vscode-focusBorder);
color-scheme: light;
}

.vscode-dark .history-import-options input,
.vscode-high-contrast .history-import-options input {
color-scheme: dark;
}

.history-import-warning {
margin: 0;
color: var(--vscode-errorForeground);
font-size: 12px;
line-height: 1.5;
}

.history-import-actions {
justify-content: flex-end;
}

/* History */

.history-list {
Expand Down
112 changes: 112 additions & 0 deletions extensions/github1s-ai/src/common/conversation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,58 @@ export interface Conversation extends ConversationSummary {
messages: ConversationMessage[];
}

export interface WorkspaceConversationHistory {
workspaceKey: string;
conversations: Conversation[];
}

export interface ConversationHistory {
exportedAt: string;
workspaces: WorkspaceConversationHistory[];
}

export type HistoryImportOptions = { mode: 'merge'; conflicts: 'keep' | 'overwrite' } | { mode: 'replace' };

export const isConversationSummary = (value: unknown): value is ConversationSummary => {
if (!isPlainObject(value)) return false;
const summary = value as Record<string, unknown>;
return (
typeof summary.id === 'string' &&
summary.id.length > 0 &&
typeof summary.title === 'string' &&
typeof summary.createdAt === 'number' &&
Number.isFinite(summary.createdAt) &&
summary.createdAt >= 0 &&
typeof summary.updatedAt === 'number' &&
Number.isFinite(summary.updatedAt) &&
summary.updatedAt >= summary.createdAt &&
(summary.usage === undefined || isLanguageModelUsage(summary.usage))
);
};

const isLanguageModelUsage = (value: unknown): value is LanguageModelUsage => {
if (!isPlainObject(value)) return false;
const usage = value as Record<string, unknown>;
const inputTokenDetails = usage.inputTokenDetails;
const outputTokenDetails = usage.outputTokenDetails;
if (!isPlainObject(inputTokenDetails) || !isPlainObject(outputTokenDetails)) return false;
const input = inputTokenDetails as Record<string, unknown>;
const output = outputTokenDetails as Record<string, unknown>;
return (
isTokenCount(usage.inputTokens) &&
isTokenCount(input.noCacheTokens) &&
isTokenCount(input.cacheReadTokens) &&
isTokenCount(input.cacheWriteTokens) &&
isTokenCount(usage.outputTokens) &&
isTokenCount(output.textTokens) &&
isTokenCount(output.reasoningTokens) &&
isTokenCount(usage.totalTokens)
);
};

const isTokenCount = (value: unknown): value is number | undefined =>
value === undefined || (typeof value === 'number' && Number.isFinite(value) && value >= 0);

export const isInterruptedMessage = (message: ConversationMessage): boolean =>
message.metadata.status === 'failed' ||
message.metadata.status === 'aborted' ||
Expand Down Expand Up @@ -175,3 +227,63 @@ const isConversationMessageMetadata = (value: unknown): value is ConversationMes
(metadata.error === undefined || typeof metadata.error === 'string')
);
};

export const isConversationWorkspaceKey = (value: unknown): value is string =>
typeof value === 'string' && (value === 'empty-workspace' || /^[a-f0-9]{40}$/.test(value));

export const parseConversationHistory = async (json: string): Promise<ConversationHistory> => {
let value: unknown;
try {
value = JSON.parse(json);
} catch {
throw new Error('Invalid JSON file.');
}
if (!isPlainObject(value)) throw new Error('Invalid history file.');
const history = value as Record<string, unknown>;
if (
typeof history.exportedAt !== 'string' ||
!Number.isFinite(Date.parse(history.exportedAt)) ||
!Array.isArray(history.workspaces)
) {
throw new Error('Invalid history file.');
}

const workspaceKeys = new Set<string>();
const workspaces: WorkspaceConversationHistory[] = [];
for (const value of history.workspaces) {
if (!isPlainObject(value)) throw new Error('Invalid workspace history.');
const workspace = value as Record<string, unknown>;
if (!isConversationWorkspaceKey(workspace.workspaceKey) || !Array.isArray(workspace.conversations)) {
throw new Error('Invalid workspace history.');
}
if (workspaceKeys.has(workspace.workspaceKey)) throw new Error('Duplicate workspace.');
workspaceKeys.add(workspace.workspaceKey);

const ids = new Set<string>();
const conversations: Conversation[] = [];
for (const value of workspace.conversations) {
if (!isConversationSummary(value) || !/^[a-zA-Z0-9_-]+$/.test(value.id)) {
throw new Error('Invalid conversation.');
}
if (ids.has(value.id)) throw new Error(`Duplicate conversation ID: ${value.id}.`);
ids.add(value.id);
const conversation = value as Conversation;
let messages: Conversation['messages'];
try {
messages = await validateConversationMessages(conversation.messages);
} catch {
throw new Error(`Invalid messages in conversation: ${conversation.id}.`);
}
conversations.push({
id: conversation.id,
title: conversation.title,
createdAt: conversation.createdAt,
updatedAt: conversation.updatedAt,
...(conversation.usage === undefined ? {} : { usage: conversation.usage }),
messages,
});
}
workspaces.push({ workspaceKey: workspace.workspaceKey, conversations });
}
return { exportedAt: history.exportedAt, workspaces };
};
20 changes: 19 additions & 1 deletion extensions/github1s-ai/src/common/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
type ContextAttachmentAction,
type ContextAttachmentDescriptor,
} from './context';
import type { ConversationSummary } from './conversation';
import type { ConversationSummary, HistoryImportOptions } from './conversation';
import type { SyntaxHighlightingData } from './highlighting';
import type { McpConfig } from './mcp-config';
import { isModelConfigInput, type ModelConfigInput, type ModelConfigSummary } from './model-config';
Expand Down Expand Up @@ -60,6 +60,7 @@ type AllViewEvents =
| { type: 'settings.selectModelConfig'; id: string }
| { type: 'settings.clearFeedback' }
| { type: 'settings.exportHistory' }
| { type: 'settings.importHistory'; content: string; options: HistoryImportOptions }
| { type: 'settings.clearAllData' }
| { type: 'settings.saveModelConfig'; config: ModelConfigInput }
| { type: 'settings.savePromptsConfig'; config: PromptsConfig }
Expand Down Expand Up @@ -161,6 +162,23 @@ export const parseViewEvent = (value: unknown): ViewEvent | undefined => {
: undefined;
case 'settings.saveMcpConfig':
return exactString(event, 'json') ? { type: event.type, json: event.json } : undefined;
case 'settings.importHistory': {
if (
!hasExactKeys(event, ['type', 'content', 'options']) ||
typeof event.content !== 'string' ||
!isPlainObject(event.options)
)
return undefined;
const options = event.options as Record<string, unknown>;
if (hasExactKeys(options, ['mode']) && options.mode === 'replace') {
return { type: event.type, content: event.content, options: { mode: 'replace' } };
}
return hasExactKeys(options, ['mode', 'conflicts']) &&
options.mode === 'merge' &&
(options.conflicts === 'keep' || options.conflicts === 'overwrite')
? { type: event.type, content: event.content, options: { mode: 'merge', conflicts: options.conflicts } }
: undefined;
}
default:
return undefined;
}
Expand Down
2 changes: 1 addition & 1 deletion extensions/github1s-ai/src/controllers/history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export class HistoryController extends Controller {
if (selected) await this.runner.cancelPreparation();
await this.runner.cancelConversation(event.id);
try {
await this.stores.conversations.delete(event.id);
await this.stores.conversations.delete([event.id]);
} catch (error) {
const detail = error instanceof Error ? error.message : 'Unknown error.';
await this.stores.runtime.setIn('history.notice', {
Expand Down
6 changes: 6 additions & 0 deletions extensions/github1s-ai/src/controllers/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,12 @@ export class ConversationRunner {
return conversationId !== undefined && this.requests.has(conversationId);
}

// True while preparing a request or generating a response in any conversation.
isBusy(): boolean {
return this.preparation !== undefined || this.requests.size > 0;
}

// Returns the given conversation's phase; preparation is shared across conversations.
getPhase(conversationId: string | undefined): ChatPhase {
if (this.preparation) return 'preparing';
return this.isRequestActive(conversationId) ? 'generating' : 'idle';
Expand Down
Loading
Loading