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
89 changes: 78 additions & 11 deletions extensions/github1s-ai/assets/chat.css
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,7 @@ summary:focus-visible,
}

.message {
padding: 10px 0;
padding: 8px 0;
}

.message-user {
Expand Down Expand Up @@ -746,6 +746,67 @@ summary:focus-visible,
margin-top: 0.75em;
}

.message-footer {
display: flex;
min-height: 20px;
align-items: center;
gap: 12px;
margin-top: 8px;
opacity: 0;
pointer-events: none;
}

.message-meta {
display: flex;
min-width: 0;
flex: 1;
justify-content: flex-end;
flex-wrap: wrap;
gap: 2px 8px;
color: var(--vscode-descriptionForeground);
font-size: 0.8em;
line-height: 1.4;
text-align: right;
}

.message-model,
.message-meta time {
max-width: 100%;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}

.message-actions {
display: flex;
flex: none;
gap: 2px;
}

.message-actions .icon-button {
width: 20px;
height: 20px;
border-radius: 3px;
}

.message-actions .icon {
width: 13px;
height: 13px;
}

.message-assistant:hover .message-footer,
.message-assistant:focus-within .message-footer {
opacity: 1;
pointer-events: auto;
}

@media (hover: none) {
.message-footer {
opacity: 1;
pointer-events: auto;
}
}

/* Markdown */

.markdown {
Expand Down Expand Up @@ -1186,16 +1247,6 @@ summary:focus-visible,
font: inherit;
}

.message-retry {
gap: 4px;
margin-top: 6px;
}

.message-retry .icon {
width: 12px;
height: 12px;
}

.message-status {
margin: 5px 0 0;
color: var(--vscode-descriptionForeground);
Expand Down Expand Up @@ -1249,6 +1300,22 @@ summary:focus-visible,
line-height: 1.4;
}

.notice-success {
display: flex;
flex: none;
align-items: flex-start;
gap: 6px;
padding: 8px 0;
color: var(--vscode-testing-iconPassed, var(--vscode-foreground));
}

.notice-success .icon {
width: 14px;
height: 14px;
flex: none;
margin-top: 1px;
}

.composer-surface {
padding: 7px 7px 6px;
background: var(--vscode-input-background);
Expand Down
39 changes: 17 additions & 22 deletions extensions/github1s-ai/src/common/conversation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ export type ConversationMessageStatus = 'streaming' | 'completed' | 'failed' | '
export interface ConversationMessageMetadata {
turnId: string;
status: ConversationMessageStatus;
modelId?: string;
createdAt?: number;
error?: string;
}

Expand All @@ -39,17 +41,6 @@ export const isInterruptedMessage = (message: ConversationMessage): boolean =>
message.metadata.status === 'aborted' ||
message.metadata.status === 'unknown';

export const getRetryableMessage = (messages: readonly ConversationMessage[]): ConversationMessage | undefined => {
const assistant = messages.at(-1);
const user = messages.at(-2);
return assistant?.role === 'assistant' &&
isInterruptedMessage(assistant) &&
user?.role === 'user' &&
user.metadata.turnId === assistant.metadata.turnId
? assistant
: undefined;
};

export const createUserMessage = (
turnId: string,
text: string,
Expand All @@ -67,25 +58,24 @@ export const createUserMessage = (
return { id: turnId, role: 'user', metadata: { turnId, status: 'completed' }, parts };
};

export const createAssistantMessage = (id: string, turnId: string): ConversationMessage => ({
export const createAssistantMessage = (
id: string,
metadata: Omit<ConversationMessageMetadata, 'status' | 'error'>,
): ConversationMessage => ({
id,
role: 'assistant',
metadata: { turnId, status: 'streaming' },
metadata: { ...metadata, status: 'streaming' },
parts: [],
});

export const withMessageStatus = (
message: ConversationMessage,
status: ConversationMessageStatus,
error?: string,
): ConversationMessage => ({
...message,
metadata: {
turnId: message.metadata.turnId,
status,
...(error ? { error } : {}),
},
});
): ConversationMessage => {
const { error: _previousError, ...metadata } = message.metadata;
return { ...message, metadata: { ...metadata, status, ...(error ? { error } : {}) } };
};

export const markStreamingMessagesUnknown = (conversation: Conversation): Conversation => {
const messages = conversation.messages.map((message) =>
Expand All @@ -104,6 +94,8 @@ const metadataSchema = jsonSchema<ConversationMessageMetadata>(
properties: {
turnId: { type: 'string', minLength: 1 },
status: { enum: ['streaming', 'completed', 'failed', 'aborted', 'unknown'] },
modelId: { type: 'string' },
createdAt: { type: 'number' },
error: { type: 'string' },
},
},
Expand Down Expand Up @@ -169,14 +161,17 @@ const isConversationMessageMetadata = (value: unknown): value is ConversationMes
if (!isPlainObject(value)) return false;
const metadata = value as Record<string, unknown>;
return (
Object.keys(metadata).every((key) => key === 'turnId' || key === 'status' || key === 'error') &&
Object.keys(metadata).every((key) => ['turnId', 'status', 'modelId', 'createdAt', 'error'].includes(key)) &&
typeof metadata.turnId === 'string' &&
metadata.turnId.length > 0 &&
(metadata.status === 'streaming' ||
metadata.status === 'completed' ||
metadata.status === 'failed' ||
metadata.status === 'aborted' ||
metadata.status === 'unknown') &&
(metadata.modelId === undefined || typeof metadata.modelId === 'string') &&
(metadata.createdAt === undefined ||
(typeof metadata.createdAt === 'number' && Number.isFinite(metadata.createdAt))) &&
(metadata.error === undefined || typeof metadata.error === 'string')
);
};
5 changes: 5 additions & 0 deletions extensions/github1s-ai/src/common/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@ export type { Notice } from './state';

export const MAX_SYNTAX_HIGHLIGHT_SOURCE_LENGTH = 100_000;

export type ChatPhase = 'idle' | 'preparing' | 'generating';

export interface ViewState {
runtime: RuntimeState;
chatPhase: ChatPhase;
promptsConfig: PromptsConfig;
modelConfigs: {
selectedId?: string;
Expand All @@ -43,6 +46,7 @@ type AllViewEvents =
| { type: 'chat.send'; text: string }
| { type: 'chat.setEditingMessageId'; id?: string }
| { type: 'chat.retry'; id: string }
| { type: 'chat.fork'; id: string }
| { type: 'chat.runQuickAction'; action: ChatQuickAction }
| { type: 'chat.addContextAttachment'; action: ContextAttachmentAction }
| { type: 'chat.addContextAttachment'; action: 'descriptor'; descriptor: ContextAttachmentDescriptor }
Expand Down Expand Up @@ -103,6 +107,7 @@ export const parseViewEvent = (value: unknown): ViewEvent | undefined => {
: undefined;

case 'chat.retry':
case 'chat.fork':
case 'chat.removeContextAttachment':
case 'history.selectConversation':
case 'history.deleteConversation':
Expand Down
1 change: 0 additions & 1 deletion extensions/github1s-ai/src/common/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ export interface RuntimeState {
pendingAttachments: ContextAttachmentDescriptor[];
includeRecentFiles: boolean;
};
preparing?: boolean;
notice?: Notice;
};
history: {
Expand Down
1 change: 1 addition & 0 deletions extensions/github1s-ai/src/controllers/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export class AppController extends Controller {

@Controller.handler('app.newChat')
async handleNewChat(_event: ViewEvent<'app.newChat'>): Promise<void> {
await this.runner.cancelPreparation();
await this.stores.conversations.select(undefined);
await this.openPage('chat', true);
}
Expand Down
7 changes: 6 additions & 1 deletion extensions/github1s-ai/src/controllers/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class ChatController extends Controller {
@Controller.handler('chat.setEditingMessageId')
async handleSetEditingMessageId(event: ViewEvent<'chat.setEditingMessageId'>): Promise<void> {
const { chat } = await this.stores.runtime.get();
if (chat.preparing || this.runner.isRequestActive(chat.conversation?.id)) return;
if (this.runner.getPhase(chat.conversation?.id) !== 'idle') return;
if (event.id === undefined) {
await this.stores.runtime.setIn('chat', { ...chat, editing: undefined, notice: undefined });
return;
Expand All @@ -52,6 +52,11 @@ export class ChatController extends Controller {
await this.runner.retry(event.id);
}

@Controller.handler('chat.fork')
async handleFork(event: ViewEvent<'chat.fork'>): Promise<void> {
await this.runner.fork(event.id);
}

@Controller.handler('chat.cancel')
async handleCancel(_event: ViewEvent<'chat.cancel'>): Promise<void> {
await this.runner.cancelCurrent();
Expand Down
1 change: 1 addition & 0 deletions extensions/github1s-ai/src/controllers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ export class Controllers {
const mcpConfig = runtime.page === 'settings' ? await this.stores.mcpConfig.get() : undefined;
return {
runtime,
chatPhase: this.runner.getPhase(runtime.chat.conversation?.id),
promptsConfig,
modelConfigs: { configs, selectedId: selectedModel?.id },
conversations,
Expand Down
Loading
Loading