Skip to content

Commit a2add2f

Browse files
author
Marvin Zhang
committed
feat: Refactor AI chat processing models and types for improved structure and clarity
1 parent adc04a5 commit a2add2f

File tree

13 files changed

+269
-578
lines changed

13 files changed

+269
-578
lines changed

packages/ai/src/__tests__/models.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*/
44

55
import { describe, it, expect } from 'vitest';
6-
import { ChatMessageData, ChatSessionData, WorkspaceDataContainer } from '../models/index.js';
6+
import { ChatMessageData, ChatSessionData, WorkspaceDataContainer } from '../types/index.js';
77

88
describe('MessageData', () => {
99
it('should create a message with required fields', () => {
@@ -78,11 +78,11 @@ describe('ChatSessionData', () => {
7878
const session = new ChatSessionData({
7979
agent: 'GitHub Copilot',
8080
messages,
81-
session_id: 'session-1',
81+
id: 'session-1',
8282
});
8383

8484
expect(session.messages).toHaveLength(2);
85-
expect(session.session_id).toBe('session-1');
85+
expect(session.id).toBe('session-1');
8686
});
8787
});
8888

@@ -99,8 +99,8 @@ describe('WorkspaceDataContainer', () => {
9999

100100
it('should handle chat sessions correctly', () => {
101101
const sessions = [
102-
new ChatSessionData({ agent: 'GitHub Copilot', session_id: 'session-1' }),
103-
new ChatSessionData({ agent: 'GitHub Copilot', session_id: 'session-2' }),
102+
new ChatSessionData({ agent: 'GitHub Copilot', id: 'session-1' }),
103+
new ChatSessionData({ agent: 'GitHub Copilot', id: 'session-2' }),
104104
];
105105

106106
const workspace = new WorkspaceDataContainer({

packages/ai/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
* Main entry point for the TypeScript implementation
55
*/
66

7-
// Export all models
8-
export * from './models/index.js';
7+
// Export all types
8+
export * from './types/index.js';
99

1010
// Export all parsers
1111
export * from './parsers/index.js';

packages/ai/src/models/application.ts

Lines changed: 0 additions & 52 deletions
This file was deleted.

packages/ai/src/models/chat-session.ts

Lines changed: 0 additions & 55 deletions
This file was deleted.

packages/ai/src/models/workspace.ts

Lines changed: 0 additions & 45 deletions
This file was deleted.

packages/ai/src/parsers/base.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
*
44
* Provides a common interface for parsing chat history from various AI coding assistants
55
* like GitHub Copilot, Cursor, Claude Code, etc.
6-
*
6+
*
77
* Supports three-level hierarchy: Application -> Workspace -> Session
88
*/
99

10-
import type { ChatSession, ApplicationInfo, WorkspaceInfo } from '../models/index.js';
10+
import type { ChatSession, Application, Workspace, ParserType } from '../types/index.js';
1111
import { Logger, ConsoleLogger } from './utils.js';
1212

1313
/**
@@ -20,17 +20,23 @@ export abstract class BaseParser {
2020
this.logger = logger || new ConsoleLogger();
2121
}
2222

23+
/**
24+
* Get the parser type (e.g. 'github-copilot', 'cursor', etc.)
25+
* Used for metadata and identification
26+
*/
27+
abstract getParserType(): ParserType;
28+
2329
/**
2430
* Get all available applications (VS Code installations) for this AI assistant
2531
* Returns lightweight application info without workspaces or sessions
2632
*/
27-
abstract getApplications(): Promise<ApplicationInfo[]>;
33+
abstract getApplications(): Promise<Application[]>;
2834

2935
/**
3036
* Get all workspaces from a specific application
3137
* Returns lightweight workspace info without sessions
3238
*/
33-
abstract getWorkspaces(applicationId: string): Promise<WorkspaceInfo[]>;
39+
abstract getWorkspaces(applicationId: string): Promise<Workspace[]>;
3440

3541
/**
3642
* Get all chat sessions from a specific workspace within an application
@@ -40,5 +46,9 @@ export abstract class BaseParser {
4046
/**
4147
* Parse a single chat session by session ID
4248
*/
43-
protected abstract parseChatSession(applicationId: string, workspaceId: string, sessionId: string): Promise<ChatSession | null>;
49+
protected abstract parseChatSession(
50+
applicationId: string,
51+
workspaceId: string,
52+
sessionId: string,
53+
): Promise<ChatSession | null>;
4454
}

0 commit comments

Comments
 (0)