@contractspec/module.ai-chat 1.44.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/LICENSE +21 -0
- package/README.md +169 -0
- package/dist/ai-chat.feature.d.ts +12 -0
- package/dist/ai-chat.feature.d.ts.map +1 -0
- package/dist/ai-chat.feature.js +95 -0
- package/dist/ai-chat.feature.js.map +1 -0
- package/dist/ai-chat.operations.d.ts +243 -0
- package/dist/ai-chat.operations.d.ts.map +1 -0
- package/dist/ai-chat.operations.js +174 -0
- package/dist/ai-chat.operations.js.map +1 -0
- package/dist/context/context-builder.d.ts +57 -0
- package/dist/context/context-builder.d.ts.map +1 -0
- package/dist/context/context-builder.js +148 -0
- package/dist/context/context-builder.js.map +1 -0
- package/dist/context/file-operations.d.ts +100 -0
- package/dist/context/file-operations.d.ts.map +1 -0
- package/dist/context/file-operations.js +175 -0
- package/dist/context/file-operations.js.map +1 -0
- package/dist/context/index.d.ts +4 -0
- package/dist/context/index.js +5 -0
- package/dist/context/workspace-context.d.ts +117 -0
- package/dist/context/workspace-context.d.ts.map +1 -0
- package/dist/context/workspace-context.js +124 -0
- package/dist/context/workspace-context.js.map +1 -0
- package/dist/core/chat-service.d.ts +73 -0
- package/dist/core/chat-service.d.ts.map +1 -0
- package/dist/core/chat-service.js +227 -0
- package/dist/core/chat-service.js.map +1 -0
- package/dist/core/conversation-store.d.ts +74 -0
- package/dist/core/conversation-store.d.ts.map +1 -0
- package/dist/core/conversation-store.js +109 -0
- package/dist/core/conversation-store.js.map +1 -0
- package/dist/core/index.d.ts +4 -0
- package/dist/core/index.js +4 -0
- package/dist/core/message-types.d.ts +150 -0
- package/dist/core/message-types.d.ts.map +1 -0
- package/dist/events.d.ts +115 -0
- package/dist/events.d.ts.map +1 -0
- package/dist/events.js +100 -0
- package/dist/events.js.map +1 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.js +23 -0
- package/dist/libs/schema/dist/EnumType.js +2 -0
- package/dist/libs/schema/dist/FieldType.js +50 -0
- package/dist/libs/schema/dist/FieldType.js.map +1 -0
- package/dist/libs/schema/dist/GraphQLSchemaType.js +1 -0
- package/dist/libs/schema/dist/JsonSchemaType.js +1 -0
- package/dist/libs/schema/dist/ScalarTypeEnum.js +237 -0
- package/dist/libs/schema/dist/ScalarTypeEnum.js.map +1 -0
- package/dist/libs/schema/dist/SchemaModel.js +40 -0
- package/dist/libs/schema/dist/SchemaModel.js.map +1 -0
- package/dist/libs/schema/dist/ZodSchemaType.js +1 -0
- package/dist/libs/schema/dist/entity/defineEntity.js +1 -0
- package/dist/libs/schema/dist/entity/index.js +2 -0
- package/dist/libs/schema/dist/entity/types.js +1 -0
- package/dist/libs/schema/dist/index.js +9 -0
- package/dist/presentation/components/ChatContainer.d.ts +21 -0
- package/dist/presentation/components/ChatContainer.d.ts.map +1 -0
- package/dist/presentation/components/ChatContainer.js +63 -0
- package/dist/presentation/components/ChatContainer.js.map +1 -0
- package/dist/presentation/components/ChatInput.d.ts +35 -0
- package/dist/presentation/components/ChatInput.d.ts.map +1 -0
- package/dist/presentation/components/ChatInput.js +149 -0
- package/dist/presentation/components/ChatInput.js.map +1 -0
- package/dist/presentation/components/ChatMessage.d.ts +24 -0
- package/dist/presentation/components/ChatMessage.d.ts.map +1 -0
- package/dist/presentation/components/ChatMessage.js +136 -0
- package/dist/presentation/components/ChatMessage.js.map +1 -0
- package/dist/presentation/components/CodePreview.d.ts +40 -0
- package/dist/presentation/components/CodePreview.d.ts.map +1 -0
- package/dist/presentation/components/CodePreview.js +127 -0
- package/dist/presentation/components/CodePreview.js.map +1 -0
- package/dist/presentation/components/ContextIndicator.d.ts +26 -0
- package/dist/presentation/components/ContextIndicator.d.ts.map +1 -0
- package/dist/presentation/components/ContextIndicator.js +97 -0
- package/dist/presentation/components/ContextIndicator.js.map +1 -0
- package/dist/presentation/components/ModelPicker.d.ts +39 -0
- package/dist/presentation/components/ModelPicker.d.ts.map +1 -0
- package/dist/presentation/components/ModelPicker.js +202 -0
- package/dist/presentation/components/ModelPicker.js.map +1 -0
- package/dist/presentation/components/index.d.ts +7 -0
- package/dist/presentation/components/index.js +8 -0
- package/dist/presentation/hooks/index.d.ts +3 -0
- package/dist/presentation/hooks/index.js +4 -0
- package/dist/presentation/hooks/useChat.d.ts +67 -0
- package/dist/presentation/hooks/useChat.d.ts.map +1 -0
- package/dist/presentation/hooks/useChat.js +172 -0
- package/dist/presentation/hooks/useChat.js.map +1 -0
- package/dist/presentation/hooks/useProviders.d.ts +38 -0
- package/dist/presentation/hooks/useProviders.d.ts.map +1 -0
- package/dist/presentation/hooks/useProviders.js +41 -0
- package/dist/presentation/hooks/useProviders.js.map +1 -0
- package/dist/presentation/index.d.ts +11 -0
- package/dist/presentation/index.js +12 -0
- package/dist/providers/chat-utilities.d.ts +15 -0
- package/dist/providers/chat-utilities.d.ts.map +1 -0
- package/dist/providers/chat-utilities.js +17 -0
- package/dist/providers/chat-utilities.js.map +1 -0
- package/dist/providers/index.d.ts +3 -0
- package/dist/providers/index.js +4 -0
- package/dist/schema.d.ts +222 -0
- package/dist/schema.d.ts.map +1 -0
- package/dist/schema.js +102 -0
- package/dist/schema.js.map +1 -0
- package/package.json +80 -0
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
//#region src/context/file-operations.ts
|
|
2
|
+
/**
|
|
3
|
+
* File operations executor
|
|
4
|
+
*/
|
|
5
|
+
var FileOperations = class {
|
|
6
|
+
constructor(fs, workspacePath, allowWrites = false) {
|
|
7
|
+
this.fs = fs;
|
|
8
|
+
this.workspacePath = workspacePath;
|
|
9
|
+
this.allowWrites = allowWrites;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Read a file
|
|
13
|
+
*/
|
|
14
|
+
async read(relativePath) {
|
|
15
|
+
const fullPath = this.resolvePath(relativePath);
|
|
16
|
+
try {
|
|
17
|
+
return {
|
|
18
|
+
success: true,
|
|
19
|
+
path: relativePath,
|
|
20
|
+
content: await this.fs.readFile(fullPath)
|
|
21
|
+
};
|
|
22
|
+
} catch (error) {
|
|
23
|
+
return {
|
|
24
|
+
success: false,
|
|
25
|
+
path: relativePath,
|
|
26
|
+
error: error instanceof Error ? error.message : String(error)
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Write to a file
|
|
32
|
+
*/
|
|
33
|
+
async write(relativePath, content) {
|
|
34
|
+
if (!this.allowWrites) return {
|
|
35
|
+
success: false,
|
|
36
|
+
path: relativePath,
|
|
37
|
+
error: "File writes are not enabled"
|
|
38
|
+
};
|
|
39
|
+
const fullPath = this.resolvePath(relativePath);
|
|
40
|
+
try {
|
|
41
|
+
await this.fs.writeFile(fullPath, content);
|
|
42
|
+
return {
|
|
43
|
+
success: true,
|
|
44
|
+
path: relativePath
|
|
45
|
+
};
|
|
46
|
+
} catch (error) {
|
|
47
|
+
return {
|
|
48
|
+
success: false,
|
|
49
|
+
path: relativePath,
|
|
50
|
+
error: error instanceof Error ? error.message : String(error)
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Execute multiple file operations
|
|
56
|
+
*/
|
|
57
|
+
async execute(operations) {
|
|
58
|
+
const results = [];
|
|
59
|
+
for (const operation of operations) {
|
|
60
|
+
let result;
|
|
61
|
+
switch (operation.type) {
|
|
62
|
+
case "read": {
|
|
63
|
+
const readResult = await this.read(operation.path);
|
|
64
|
+
result = {
|
|
65
|
+
operation,
|
|
66
|
+
success: readResult.success,
|
|
67
|
+
content: readResult.content,
|
|
68
|
+
error: readResult.error
|
|
69
|
+
};
|
|
70
|
+
break;
|
|
71
|
+
}
|
|
72
|
+
case "write":
|
|
73
|
+
case "create":
|
|
74
|
+
if (!operation.content) result = {
|
|
75
|
+
operation,
|
|
76
|
+
success: false,
|
|
77
|
+
error: "Content is required for write operations"
|
|
78
|
+
};
|
|
79
|
+
else {
|
|
80
|
+
const writeResult = await this.write(operation.path, operation.content);
|
|
81
|
+
result = {
|
|
82
|
+
operation,
|
|
83
|
+
success: writeResult.success,
|
|
84
|
+
error: writeResult.error
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
break;
|
|
88
|
+
case "delete":
|
|
89
|
+
if (!this.allowWrites) result = {
|
|
90
|
+
operation,
|
|
91
|
+
success: false,
|
|
92
|
+
error: "File writes are not enabled"
|
|
93
|
+
};
|
|
94
|
+
else try {
|
|
95
|
+
await this.fs.deleteFile(this.resolvePath(operation.path));
|
|
96
|
+
result = {
|
|
97
|
+
operation,
|
|
98
|
+
success: true
|
|
99
|
+
};
|
|
100
|
+
} catch (error) {
|
|
101
|
+
result = {
|
|
102
|
+
operation,
|
|
103
|
+
success: false,
|
|
104
|
+
error: error instanceof Error ? error.message : String(error)
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
break;
|
|
108
|
+
default: result = {
|
|
109
|
+
operation,
|
|
110
|
+
success: false,
|
|
111
|
+
error: `Unknown operation type: ${operation.type}`
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
results.push(result);
|
|
115
|
+
}
|
|
116
|
+
return results;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Resolve a relative path to an absolute path
|
|
120
|
+
*/
|
|
121
|
+
resolvePath(relativePath) {
|
|
122
|
+
const normalized = relativePath.replace(/\.\./g, "").replace(/^\//, "");
|
|
123
|
+
return `${this.workspacePath}/${normalized}`;
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
/**
|
|
127
|
+
* Create a file operations instance with Node.js fs
|
|
128
|
+
*/
|
|
129
|
+
function createNodeFileOperations(workspacePath, allowWrites = false) {
|
|
130
|
+
return new FileOperations({
|
|
131
|
+
async readFile(path) {
|
|
132
|
+
const { readFile } = await import("node:fs/promises");
|
|
133
|
+
return readFile(path, "utf-8");
|
|
134
|
+
},
|
|
135
|
+
async writeFile(path, content) {
|
|
136
|
+
const { writeFile, mkdir } = await import("node:fs/promises");
|
|
137
|
+
const { dirname } = await import("node:path");
|
|
138
|
+
await mkdir(dirname(path), { recursive: true });
|
|
139
|
+
await writeFile(path, content, "utf-8");
|
|
140
|
+
},
|
|
141
|
+
async exists(path) {
|
|
142
|
+
const { access } = await import("node:fs/promises");
|
|
143
|
+
try {
|
|
144
|
+
await access(path);
|
|
145
|
+
return true;
|
|
146
|
+
} catch {
|
|
147
|
+
return false;
|
|
148
|
+
}
|
|
149
|
+
},
|
|
150
|
+
async deleteFile(path) {
|
|
151
|
+
const { unlink } = await import("node:fs/promises");
|
|
152
|
+
await unlink(path);
|
|
153
|
+
},
|
|
154
|
+
async listFiles(directory, options) {
|
|
155
|
+
const { readdir } = await import("node:fs/promises");
|
|
156
|
+
const { join } = await import("node:path");
|
|
157
|
+
const files = [];
|
|
158
|
+
const entries = await readdir(directory, { withFileTypes: true });
|
|
159
|
+
for (const entry of entries) {
|
|
160
|
+
const fullPath = join(directory, entry.name);
|
|
161
|
+
if (entry.isDirectory() && options?.recursive) {
|
|
162
|
+
const subFiles = await this.listFiles(fullPath, options);
|
|
163
|
+
files.push(...subFiles);
|
|
164
|
+
} else if (entry.isFile()) {
|
|
165
|
+
if (!options?.pattern || entry.name.match(new RegExp(options.pattern))) files.push(fullPath);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
return files;
|
|
169
|
+
}
|
|
170
|
+
}, workspacePath, allowWrites);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
//#endregion
|
|
174
|
+
export { FileOperations, createNodeFileOperations };
|
|
175
|
+
//# sourceMappingURL=file-operations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file-operations.js","names":["fs: FileSystem","workspacePath: string","results: FileOperationResult[]","result: FileOperationResult","files: string[]"],"sources":["../../src/context/file-operations.ts"],"sourcesContent":["/**\n * File operations for workspace context\n *\n * Provides read/write operations for files in the workspace.\n */\n\n/**\n * Result of a file read operation\n */\nexport interface FileReadResult {\n success: boolean;\n path: string;\n content?: string;\n error?: string;\n}\n\n/**\n * Result of a file write operation\n */\nexport interface FileWriteResult {\n success: boolean;\n path: string;\n error?: string;\n}\n\n/**\n * File operation to perform\n */\nexport interface FileOperation {\n type: 'read' | 'write' | 'create' | 'delete';\n path: string;\n content?: string;\n}\n\n/**\n * Result of a file operation\n */\nexport interface FileOperationResult {\n operation: FileOperation;\n success: boolean;\n content?: string;\n error?: string;\n}\n\n/**\n * Interface for file system operations\n */\nexport interface FileSystem {\n /**\n * Read a file's contents\n */\n readFile(path: string): Promise<string>;\n\n /**\n * Write content to a file\n */\n writeFile(path: string, content: string): Promise<void>;\n\n /**\n * Check if a file exists\n */\n exists(path: string): Promise<boolean>;\n\n /**\n * Delete a file\n */\n deleteFile(path: string): Promise<void>;\n\n /**\n * List files in a directory\n */\n listFiles(\n directory: string,\n options?: { recursive?: boolean; pattern?: string }\n ): Promise<string[]>;\n}\n\n/**\n * File operations executor\n */\nexport class FileOperations {\n constructor(\n private readonly fs: FileSystem,\n private readonly workspacePath: string,\n private readonly allowWrites = false\n ) {}\n\n /**\n * Read a file\n */\n async read(relativePath: string): Promise<FileReadResult> {\n const fullPath = this.resolvePath(relativePath);\n\n try {\n const content = await this.fs.readFile(fullPath);\n return { success: true, path: relativePath, content };\n } catch (error) {\n return {\n success: false,\n path: relativePath,\n error: error instanceof Error ? error.message : String(error),\n };\n }\n }\n\n /**\n * Write to a file\n */\n async write(relativePath: string, content: string): Promise<FileWriteResult> {\n if (!this.allowWrites) {\n return {\n success: false,\n path: relativePath,\n error: 'File writes are not enabled',\n };\n }\n\n const fullPath = this.resolvePath(relativePath);\n\n try {\n await this.fs.writeFile(fullPath, content);\n return { success: true, path: relativePath };\n } catch (error) {\n return {\n success: false,\n path: relativePath,\n error: error instanceof Error ? error.message : String(error),\n };\n }\n }\n\n /**\n * Execute multiple file operations\n */\n async execute(operations: FileOperation[]): Promise<FileOperationResult[]> {\n const results: FileOperationResult[] = [];\n\n for (const operation of operations) {\n let result: FileOperationResult;\n\n switch (operation.type) {\n case 'read': {\n const readResult = await this.read(operation.path);\n result = {\n operation,\n success: readResult.success,\n content: readResult.content,\n error: readResult.error,\n };\n break;\n }\n\n case 'write':\n case 'create': {\n if (!operation.content) {\n result = {\n operation,\n success: false,\n error: 'Content is required for write operations',\n };\n } else {\n const writeResult = await this.write(\n operation.path,\n operation.content\n );\n result = {\n operation,\n success: writeResult.success,\n error: writeResult.error,\n };\n }\n break;\n }\n\n case 'delete': {\n if (!this.allowWrites) {\n result = {\n operation,\n success: false,\n error: 'File writes are not enabled',\n };\n } else {\n try {\n await this.fs.deleteFile(this.resolvePath(operation.path));\n result = { operation, success: true };\n } catch (error) {\n result = {\n operation,\n success: false,\n error: error instanceof Error ? error.message : String(error),\n };\n }\n }\n break;\n }\n\n default:\n result = {\n operation,\n success: false,\n error: `Unknown operation type: ${(operation as FileOperation).type}`,\n };\n }\n\n results.push(result);\n }\n\n return results;\n }\n\n /**\n * Resolve a relative path to an absolute path\n */\n private resolvePath(relativePath: string): string {\n // Prevent path traversal\n const normalized = relativePath.replace(/\\.\\./g, '').replace(/^\\//, '');\n return `${this.workspacePath}/${normalized}`;\n }\n}\n\n/**\n * Create a file operations instance with Node.js fs\n */\nexport function createNodeFileOperations(\n workspacePath: string,\n allowWrites = false\n): FileOperations {\n // Dynamic import to avoid issues in browser environments\n const fs: FileSystem = {\n async readFile(path: string): Promise<string> {\n const { readFile } = await import('node:fs/promises');\n return readFile(path, 'utf-8');\n },\n async writeFile(path: string, content: string): Promise<void> {\n const { writeFile, mkdir } = await import('node:fs/promises');\n const { dirname } = await import('node:path');\n await mkdir(dirname(path), { recursive: true });\n await writeFile(path, content, 'utf-8');\n },\n async exists(path: string): Promise<boolean> {\n const { access } = await import('node:fs/promises');\n try {\n await access(path);\n return true;\n } catch {\n return false;\n }\n },\n async deleteFile(path: string): Promise<void> {\n const { unlink } = await import('node:fs/promises');\n await unlink(path);\n },\n async listFiles(\n directory: string,\n options?: { recursive?: boolean; pattern?: string }\n ): Promise<string[]> {\n const { readdir } = await import('node:fs/promises');\n const { join } = await import('node:path');\n\n const files: string[] = [];\n const entries = await readdir(directory, { withFileTypes: true });\n\n for (const entry of entries) {\n const fullPath = join(directory, entry.name);\n if (entry.isDirectory() && options?.recursive) {\n const subFiles = await this.listFiles(fullPath, options);\n files.push(...subFiles);\n } else if (entry.isFile()) {\n if (\n !options?.pattern ||\n entry.name.match(new RegExp(options.pattern))\n ) {\n files.push(fullPath);\n }\n }\n }\n\n return files;\n },\n };\n\n return new FileOperations(fs, workspacePath, allowWrites);\n}\n"],"mappings":"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"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { FileInfo, SpecInfo, WorkspaceContext, WorkspaceContextConfig, WorkspaceSummary, createWorkspaceContext } from "./workspace-context.js";
|
|
2
|
+
import { BuiltContext, ContextBuilder, ContextBuilderOptions, ContextEntry, createContextBuilder } from "./context-builder.js";
|
|
3
|
+
import { FileOperation, FileOperationResult, FileOperations, FileReadResult, FileSystem, FileWriteResult, createNodeFileOperations } from "./file-operations.js";
|
|
4
|
+
export { BuiltContext, ContextBuilder, ContextBuilderOptions, ContextEntry, FileInfo, FileOperation, FileOperationResult, FileOperations, FileReadResult, FileSystem, FileWriteResult, SpecInfo, WorkspaceContext, WorkspaceContextConfig, WorkspaceSummary, createContextBuilder, createNodeFileOperations, createWorkspaceContext };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { WorkspaceContext, createWorkspaceContext } from "./workspace-context.js";
|
|
2
|
+
import { ContextBuilder, createContextBuilder } from "./context-builder.js";
|
|
3
|
+
import { FileOperations, createNodeFileOperations } from "./file-operations.js";
|
|
4
|
+
|
|
5
|
+
export { ContextBuilder, FileOperations, WorkspaceContext, createContextBuilder, createNodeFileOperations, createWorkspaceContext };
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
//#region src/context/workspace-context.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Workspace context management
|
|
4
|
+
*
|
|
5
|
+
* Provides access to specs, files, and codebase information
|
|
6
|
+
* for context-aware AI chat assistance.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Spec information for context
|
|
10
|
+
*/
|
|
11
|
+
interface SpecInfo {
|
|
12
|
+
name: string;
|
|
13
|
+
version: number;
|
|
14
|
+
type: 'command' | 'query' | 'event' | 'presentation';
|
|
15
|
+
path: string;
|
|
16
|
+
description?: string;
|
|
17
|
+
tags?: string[];
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* File information for context
|
|
21
|
+
*/
|
|
22
|
+
interface FileInfo {
|
|
23
|
+
path: string;
|
|
24
|
+
relativePath: string;
|
|
25
|
+
name: string;
|
|
26
|
+
extension: string;
|
|
27
|
+
size: number;
|
|
28
|
+
isSpec: boolean;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Workspace summary for context
|
|
32
|
+
*/
|
|
33
|
+
interface WorkspaceSummary {
|
|
34
|
+
name: string;
|
|
35
|
+
path: string;
|
|
36
|
+
specs: {
|
|
37
|
+
total: number;
|
|
38
|
+
commands: number;
|
|
39
|
+
queries: number;
|
|
40
|
+
events: number;
|
|
41
|
+
presentations: number;
|
|
42
|
+
};
|
|
43
|
+
files: {
|
|
44
|
+
total: number;
|
|
45
|
+
typescript: number;
|
|
46
|
+
specFiles: number;
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Configuration for workspace context
|
|
51
|
+
*/
|
|
52
|
+
interface WorkspaceContextConfig {
|
|
53
|
+
/** Root path of the workspace */
|
|
54
|
+
workspacePath: string;
|
|
55
|
+
/** File patterns to include */
|
|
56
|
+
includePatterns?: string[];
|
|
57
|
+
/** File patterns to exclude */
|
|
58
|
+
excludePatterns?: string[];
|
|
59
|
+
/** Maximum file size to read (bytes) */
|
|
60
|
+
maxFileSize?: number;
|
|
61
|
+
/** Whether to enable file writes */
|
|
62
|
+
allowWrites?: boolean;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Workspace context for AI chat
|
|
66
|
+
*/
|
|
67
|
+
declare class WorkspaceContext {
|
|
68
|
+
readonly workspacePath: string;
|
|
69
|
+
readonly allowWrites: boolean;
|
|
70
|
+
private specs;
|
|
71
|
+
private files;
|
|
72
|
+
private initialized;
|
|
73
|
+
constructor(config: WorkspaceContextConfig);
|
|
74
|
+
/**
|
|
75
|
+
* Initialize the workspace context by scanning files
|
|
76
|
+
*/
|
|
77
|
+
initialize(): Promise<void>;
|
|
78
|
+
/**
|
|
79
|
+
* Get all discovered specs
|
|
80
|
+
*/
|
|
81
|
+
getSpecs(): SpecInfo[];
|
|
82
|
+
/**
|
|
83
|
+
* Get all discovered files
|
|
84
|
+
*/
|
|
85
|
+
getFiles(): FileInfo[];
|
|
86
|
+
/**
|
|
87
|
+
* Add specs to the context
|
|
88
|
+
*/
|
|
89
|
+
addSpecs(specs: SpecInfo[]): void;
|
|
90
|
+
/**
|
|
91
|
+
* Add files to the context
|
|
92
|
+
*/
|
|
93
|
+
addFiles(files: FileInfo[]): void;
|
|
94
|
+
/**
|
|
95
|
+
* Get a summary of the workspace for context
|
|
96
|
+
*/
|
|
97
|
+
getSummary(): WorkspaceSummary;
|
|
98
|
+
/**
|
|
99
|
+
* Get a context summary for LLM prompts
|
|
100
|
+
*/
|
|
101
|
+
getContextSummary(): string;
|
|
102
|
+
/**
|
|
103
|
+
* Find specs matching a query
|
|
104
|
+
*/
|
|
105
|
+
findSpecs(query: string): SpecInfo[];
|
|
106
|
+
/**
|
|
107
|
+
* Find files matching a query
|
|
108
|
+
*/
|
|
109
|
+
findFiles(query: string): FileInfo[];
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Create a workspace context from a path
|
|
113
|
+
*/
|
|
114
|
+
declare function createWorkspaceContext(path: string, options?: Partial<WorkspaceContextConfig>): Promise<WorkspaceContext>;
|
|
115
|
+
//#endregion
|
|
116
|
+
export { FileInfo, SpecInfo, WorkspaceContext, WorkspaceContextConfig, WorkspaceSummary, createWorkspaceContext };
|
|
117
|
+
//# sourceMappingURL=workspace-context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workspace-context.d.ts","names":[],"sources":["../../src/context/workspace-context.ts"],"sourcesContent":[],"mappings":";;AAUA;AAYA;AAYA;AAoBA;AAgBA;;;;AAkCc,UA9FG,QAAA,CA8FH;EAOI,IAAA,EAAA,MAAA;EAOA,OAAA,EAAA,MAAA;EAOF,IAAA,EAAA,SAAA,GAAA,OAAA,GAAA,OAAA,GAAA,cAAA;EA8DY,IAAA,EAAA,MAAA;EAaA,WAAA,CAAA,EAAA,MAAA;EAAQ,IAAA,CAAA,EAAA,MAAA,EAAA;AAapC;;;;AAGG,UAlMc,QAAA,CAkMd;EAAO,IAAA,EAAA,MAAA;;;;;;;;;;UAtLO,gBAAA;;;;;;;;;;;;;;;;;;;UAoBA,sBAAA;;;;;;;;;;;;;;;cAgBJ,gBAAA;;;;;;sBAQS;;;;gBAQA;;;;cAWR;;;;cAOA;;;;kBAOI;;;;kBAOA;;;;gBAOF;;;;;;;;4BA8DY;;;;4BAaA;;;;;iBAaN,sBAAA,yBAEV,QAAQ,0BACjB,QAAQ"}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
//#region src/context/workspace-context.ts
|
|
2
|
+
/**
|
|
3
|
+
* Workspace context for AI chat
|
|
4
|
+
*/
|
|
5
|
+
var WorkspaceContext = class {
|
|
6
|
+
workspacePath;
|
|
7
|
+
allowWrites;
|
|
8
|
+
specs = [];
|
|
9
|
+
files = [];
|
|
10
|
+
initialized = false;
|
|
11
|
+
constructor(config) {
|
|
12
|
+
this.workspacePath = config.workspacePath;
|
|
13
|
+
this.allowWrites = config.allowWrites ?? false;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Initialize the workspace context by scanning files
|
|
17
|
+
*/
|
|
18
|
+
async initialize() {
|
|
19
|
+
if (this.initialized) return;
|
|
20
|
+
this.initialized = true;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Get all discovered specs
|
|
24
|
+
*/
|
|
25
|
+
getSpecs() {
|
|
26
|
+
return this.specs;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Get all discovered files
|
|
30
|
+
*/
|
|
31
|
+
getFiles() {
|
|
32
|
+
return this.files;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Add specs to the context
|
|
36
|
+
*/
|
|
37
|
+
addSpecs(specs) {
|
|
38
|
+
this.specs.push(...specs);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Add files to the context
|
|
42
|
+
*/
|
|
43
|
+
addFiles(files) {
|
|
44
|
+
this.files.push(...files);
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Get a summary of the workspace for context
|
|
48
|
+
*/
|
|
49
|
+
getSummary() {
|
|
50
|
+
const commands = this.specs.filter((s) => s.type === "command").length;
|
|
51
|
+
const queries = this.specs.filter((s) => s.type === "query").length;
|
|
52
|
+
const events = this.specs.filter((s) => s.type === "event").length;
|
|
53
|
+
const presentations = this.specs.filter((s) => s.type === "presentation").length;
|
|
54
|
+
const tsFiles = this.files.filter((f) => f.extension === ".ts").length;
|
|
55
|
+
const specFiles = this.files.filter((f) => f.isSpec).length;
|
|
56
|
+
return {
|
|
57
|
+
name: this.workspacePath.split("/").pop() ?? "workspace",
|
|
58
|
+
path: this.workspacePath,
|
|
59
|
+
specs: {
|
|
60
|
+
total: this.specs.length,
|
|
61
|
+
commands,
|
|
62
|
+
queries,
|
|
63
|
+
events,
|
|
64
|
+
presentations
|
|
65
|
+
},
|
|
66
|
+
files: {
|
|
67
|
+
total: this.files.length,
|
|
68
|
+
typescript: tsFiles,
|
|
69
|
+
specFiles
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Get a context summary for LLM prompts
|
|
75
|
+
*/
|
|
76
|
+
getContextSummary() {
|
|
77
|
+
const summary = this.getSummary();
|
|
78
|
+
const parts = [
|
|
79
|
+
`Workspace: ${summary.name}`,
|
|
80
|
+
`Path: ${summary.path}`,
|
|
81
|
+
"",
|
|
82
|
+
"### Specs",
|
|
83
|
+
`- Commands: ${summary.specs.commands}`,
|
|
84
|
+
`- Queries: ${summary.specs.queries}`,
|
|
85
|
+
`- Events: ${summary.specs.events}`,
|
|
86
|
+
`- Presentations: ${summary.specs.presentations}`
|
|
87
|
+
];
|
|
88
|
+
if (this.specs.length > 0) {
|
|
89
|
+
parts.push("", "### Available Specs");
|
|
90
|
+
for (const spec of this.specs.slice(0, 20)) parts.push(`- ${spec.name} (${spec.type})`);
|
|
91
|
+
if (this.specs.length > 20) parts.push(`- ... and ${this.specs.length - 20} more`);
|
|
92
|
+
}
|
|
93
|
+
return parts.join("\n");
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Find specs matching a query
|
|
97
|
+
*/
|
|
98
|
+
findSpecs(query) {
|
|
99
|
+
const lowerQuery = query.toLowerCase();
|
|
100
|
+
return this.specs.filter((s) => s.name.toLowerCase().includes(lowerQuery) || s.description?.toLowerCase().includes(lowerQuery) || s.tags?.some((t) => t.toLowerCase().includes(lowerQuery)));
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Find files matching a query
|
|
104
|
+
*/
|
|
105
|
+
findFiles(query) {
|
|
106
|
+
const lowerQuery = query.toLowerCase();
|
|
107
|
+
return this.files.filter((f) => f.path.toLowerCase().includes(lowerQuery) || f.name.toLowerCase().includes(lowerQuery));
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
/**
|
|
111
|
+
* Create a workspace context from a path
|
|
112
|
+
*/
|
|
113
|
+
async function createWorkspaceContext(path, options) {
|
|
114
|
+
const context = new WorkspaceContext({
|
|
115
|
+
workspacePath: path,
|
|
116
|
+
...options
|
|
117
|
+
});
|
|
118
|
+
await context.initialize();
|
|
119
|
+
return context;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
//#endregion
|
|
123
|
+
export { WorkspaceContext, createWorkspaceContext };
|
|
124
|
+
//# sourceMappingURL=workspace-context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workspace-context.js","names":["parts: string[]"],"sources":["../../src/context/workspace-context.ts"],"sourcesContent":["/**\n * Workspace context management\n *\n * Provides access to specs, files, and codebase information\n * for context-aware AI chat assistance.\n */\n\n/**\n * Spec information for context\n */\nexport interface SpecInfo {\n name: string;\n version: number;\n type: 'command' | 'query' | 'event' | 'presentation';\n path: string;\n description?: string;\n tags?: string[];\n}\n\n/**\n * File information for context\n */\nexport interface FileInfo {\n path: string;\n relativePath: string;\n name: string;\n extension: string;\n size: number;\n isSpec: boolean;\n}\n\n/**\n * Workspace summary for context\n */\nexport interface WorkspaceSummary {\n name: string;\n path: string;\n specs: {\n total: number;\n commands: number;\n queries: number;\n events: number;\n presentations: number;\n };\n files: {\n total: number;\n typescript: number;\n specFiles: number;\n };\n}\n\n/**\n * Configuration for workspace context\n */\nexport interface WorkspaceContextConfig {\n /** Root path of the workspace */\n workspacePath: string;\n /** File patterns to include */\n includePatterns?: string[];\n /** File patterns to exclude */\n excludePatterns?: string[];\n /** Maximum file size to read (bytes) */\n maxFileSize?: number;\n /** Whether to enable file writes */\n allowWrites?: boolean;\n}\n\n/**\n * Workspace context for AI chat\n */\nexport class WorkspaceContext {\n readonly workspacePath: string;\n readonly allowWrites: boolean;\n\n private specs: SpecInfo[] = [];\n private files: FileInfo[] = [];\n private initialized = false;\n\n constructor(config: WorkspaceContextConfig) {\n this.workspacePath = config.workspacePath;\n this.allowWrites = config.allowWrites ?? false;\n }\n\n /**\n * Initialize the workspace context by scanning files\n */\n async initialize(): Promise<void> {\n if (this.initialized) return;\n\n // This would scan the workspace for specs and files\n // For now, we just mark as initialized\n this.initialized = true;\n }\n\n /**\n * Get all discovered specs\n */\n getSpecs(): SpecInfo[] {\n return this.specs;\n }\n\n /**\n * Get all discovered files\n */\n getFiles(): FileInfo[] {\n return this.files;\n }\n\n /**\n * Add specs to the context\n */\n addSpecs(specs: SpecInfo[]): void {\n this.specs.push(...specs);\n }\n\n /**\n * Add files to the context\n */\n addFiles(files: FileInfo[]): void {\n this.files.push(...files);\n }\n\n /**\n * Get a summary of the workspace for context\n */\n getSummary(): WorkspaceSummary {\n const commands = this.specs.filter((s) => s.type === 'command').length;\n const queries = this.specs.filter((s) => s.type === 'query').length;\n const events = this.specs.filter((s) => s.type === 'event').length;\n const presentations = this.specs.filter(\n (s) => s.type === 'presentation'\n ).length;\n\n const tsFiles = this.files.filter((f) => f.extension === '.ts').length;\n const specFiles = this.files.filter((f) => f.isSpec).length;\n\n return {\n name: this.workspacePath.split('/').pop() ?? 'workspace',\n path: this.workspacePath,\n specs: {\n total: this.specs.length,\n commands,\n queries,\n events,\n presentations,\n },\n files: {\n total: this.files.length,\n typescript: tsFiles,\n specFiles,\n },\n };\n }\n\n /**\n * Get a context summary for LLM prompts\n */\n getContextSummary(): string {\n const summary = this.getSummary();\n\n const parts: string[] = [\n `Workspace: ${summary.name}`,\n `Path: ${summary.path}`,\n '',\n '### Specs',\n `- Commands: ${summary.specs.commands}`,\n `- Queries: ${summary.specs.queries}`,\n `- Events: ${summary.specs.events}`,\n `- Presentations: ${summary.specs.presentations}`,\n ];\n\n if (this.specs.length > 0) {\n parts.push('', '### Available Specs');\n for (const spec of this.specs.slice(0, 20)) {\n parts.push(`- ${spec.name} (${spec.type})`);\n }\n if (this.specs.length > 20) {\n parts.push(`- ... and ${this.specs.length - 20} more`);\n }\n }\n\n return parts.join('\\n');\n }\n\n /**\n * Find specs matching a query\n */\n findSpecs(query: string): SpecInfo[] {\n const lowerQuery = query.toLowerCase();\n return this.specs.filter(\n (s) =>\n s.name.toLowerCase().includes(lowerQuery) ||\n s.description?.toLowerCase().includes(lowerQuery) ||\n s.tags?.some((t) => t.toLowerCase().includes(lowerQuery))\n );\n }\n\n /**\n * Find files matching a query\n */\n findFiles(query: string): FileInfo[] {\n const lowerQuery = query.toLowerCase();\n return this.files.filter(\n (f) =>\n f.path.toLowerCase().includes(lowerQuery) ||\n f.name.toLowerCase().includes(lowerQuery)\n );\n }\n}\n\n/**\n * Create a workspace context from a path\n */\nexport async function createWorkspaceContext(\n path: string,\n options?: Partial<WorkspaceContextConfig>\n): Promise<WorkspaceContext> {\n const context = new WorkspaceContext({\n workspacePath: path,\n ...options,\n });\n await context.initialize();\n return context;\n}\n"],"mappings":";;;;AAsEA,IAAa,mBAAb,MAA8B;CAC5B,AAAS;CACT,AAAS;CAET,AAAQ,QAAoB,EAAE;CAC9B,AAAQ,QAAoB,EAAE;CAC9B,AAAQ,cAAc;CAEtB,YAAY,QAAgC;AAC1C,OAAK,gBAAgB,OAAO;AAC5B,OAAK,cAAc,OAAO,eAAe;;;;;CAM3C,MAAM,aAA4B;AAChC,MAAI,KAAK,YAAa;AAItB,OAAK,cAAc;;;;;CAMrB,WAAuB;AACrB,SAAO,KAAK;;;;;CAMd,WAAuB;AACrB,SAAO,KAAK;;;;;CAMd,SAAS,OAAyB;AAChC,OAAK,MAAM,KAAK,GAAG,MAAM;;;;;CAM3B,SAAS,OAAyB;AAChC,OAAK,MAAM,KAAK,GAAG,MAAM;;;;;CAM3B,aAA+B;EAC7B,MAAM,WAAW,KAAK,MAAM,QAAQ,MAAM,EAAE,SAAS,UAAU,CAAC;EAChE,MAAM,UAAU,KAAK,MAAM,QAAQ,MAAM,EAAE,SAAS,QAAQ,CAAC;EAC7D,MAAM,SAAS,KAAK,MAAM,QAAQ,MAAM,EAAE,SAAS,QAAQ,CAAC;EAC5D,MAAM,gBAAgB,KAAK,MAAM,QAC9B,MAAM,EAAE,SAAS,eACnB,CAAC;EAEF,MAAM,UAAU,KAAK,MAAM,QAAQ,MAAM,EAAE,cAAc,MAAM,CAAC;EAChE,MAAM,YAAY,KAAK,MAAM,QAAQ,MAAM,EAAE,OAAO,CAAC;AAErD,SAAO;GACL,MAAM,KAAK,cAAc,MAAM,IAAI,CAAC,KAAK,IAAI;GAC7C,MAAM,KAAK;GACX,OAAO;IACL,OAAO,KAAK,MAAM;IAClB;IACA;IACA;IACA;IACD;GACD,OAAO;IACL,OAAO,KAAK,MAAM;IAClB,YAAY;IACZ;IACD;GACF;;;;;CAMH,oBAA4B;EAC1B,MAAM,UAAU,KAAK,YAAY;EAEjC,MAAMA,QAAkB;GACtB,cAAc,QAAQ;GACtB,SAAS,QAAQ;GACjB;GACA;GACA,eAAe,QAAQ,MAAM;GAC7B,cAAc,QAAQ,MAAM;GAC5B,aAAa,QAAQ,MAAM;GAC3B,oBAAoB,QAAQ,MAAM;GACnC;AAED,MAAI,KAAK,MAAM,SAAS,GAAG;AACzB,SAAM,KAAK,IAAI,sBAAsB;AACrC,QAAK,MAAM,QAAQ,KAAK,MAAM,MAAM,GAAG,GAAG,CACxC,OAAM,KAAK,KAAK,KAAK,KAAK,IAAI,KAAK,KAAK,GAAG;AAE7C,OAAI,KAAK,MAAM,SAAS,GACtB,OAAM,KAAK,aAAa,KAAK,MAAM,SAAS,GAAG,OAAO;;AAI1D,SAAO,MAAM,KAAK,KAAK;;;;;CAMzB,UAAU,OAA2B;EACnC,MAAM,aAAa,MAAM,aAAa;AACtC,SAAO,KAAK,MAAM,QACf,MACC,EAAE,KAAK,aAAa,CAAC,SAAS,WAAW,IACzC,EAAE,aAAa,aAAa,CAAC,SAAS,WAAW,IACjD,EAAE,MAAM,MAAM,MAAM,EAAE,aAAa,CAAC,SAAS,WAAW,CAAC,CAC5D;;;;;CAMH,UAAU,OAA2B;EACnC,MAAM,aAAa,MAAM,aAAa;AACtC,SAAO,KAAK,MAAM,QACf,MACC,EAAE,KAAK,aAAa,CAAC,SAAS,WAAW,IACzC,EAAE,KAAK,aAAa,CAAC,SAAS,WAAW,CAC5C;;;;;;AAOL,eAAsB,uBACpB,MACA,SAC2B;CAC3B,MAAM,UAAU,IAAI,iBAAiB;EACnC,eAAe;EACf,GAAG;EACJ,CAAC;AACF,OAAM,QAAQ,YAAY;AAC1B,QAAO"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { WorkspaceContext } from "../context/workspace-context.js";
|
|
2
|
+
import { ChatConversation, SendMessageOptions, SendMessageResult, StreamMessageResult } from "./message-types.js";
|
|
3
|
+
import { ConversationStore } from "./conversation-store.js";
|
|
4
|
+
import { Provider } from "@contractspec/lib.ai-providers";
|
|
5
|
+
|
|
6
|
+
//#region src/core/chat-service.d.ts
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Configuration for ChatService
|
|
10
|
+
*/
|
|
11
|
+
interface ChatServiceConfig {
|
|
12
|
+
/** LLM provider to use */
|
|
13
|
+
provider: Provider;
|
|
14
|
+
/** Optional workspace context for code-aware chat */
|
|
15
|
+
context?: WorkspaceContext;
|
|
16
|
+
/** Optional conversation store (defaults to in-memory) */
|
|
17
|
+
store?: ConversationStore;
|
|
18
|
+
/** Default system prompt */
|
|
19
|
+
systemPrompt?: string;
|
|
20
|
+
/** Maximum conversation history to include */
|
|
21
|
+
maxHistoryMessages?: number;
|
|
22
|
+
/** Callback for usage tracking */
|
|
23
|
+
onUsage?: (usage: {
|
|
24
|
+
inputTokens: number;
|
|
25
|
+
outputTokens: number;
|
|
26
|
+
}) => void;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Main chat service for AI-powered conversations
|
|
30
|
+
*/
|
|
31
|
+
declare class ChatService {
|
|
32
|
+
private readonly provider;
|
|
33
|
+
private readonly context?;
|
|
34
|
+
private readonly store;
|
|
35
|
+
private readonly systemPrompt;
|
|
36
|
+
private readonly maxHistoryMessages;
|
|
37
|
+
private readonly onUsage?;
|
|
38
|
+
constructor(config: ChatServiceConfig);
|
|
39
|
+
/**
|
|
40
|
+
* Send a message and get a complete response
|
|
41
|
+
*/
|
|
42
|
+
send(options: SendMessageOptions): Promise<SendMessageResult>;
|
|
43
|
+
/**
|
|
44
|
+
* Send a message and get a streaming response
|
|
45
|
+
*/
|
|
46
|
+
stream(options: SendMessageOptions): Promise<StreamMessageResult>;
|
|
47
|
+
/**
|
|
48
|
+
* Get a conversation by ID
|
|
49
|
+
*/
|
|
50
|
+
getConversation(conversationId: string): Promise<ChatConversation | null>;
|
|
51
|
+
/**
|
|
52
|
+
* List conversations
|
|
53
|
+
*/
|
|
54
|
+
listConversations(options?: {
|
|
55
|
+
limit?: number;
|
|
56
|
+
offset?: number;
|
|
57
|
+
}): Promise<ChatConversation[]>;
|
|
58
|
+
/**
|
|
59
|
+
* Delete a conversation
|
|
60
|
+
*/
|
|
61
|
+
deleteConversation(conversationId: string): Promise<boolean>;
|
|
62
|
+
/**
|
|
63
|
+
* Build prompt string for LLM
|
|
64
|
+
*/
|
|
65
|
+
private buildPrompt;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Create a chat service with the given configuration
|
|
69
|
+
*/
|
|
70
|
+
declare function createChatService(config: ChatServiceConfig): ChatService;
|
|
71
|
+
//#endregion
|
|
72
|
+
export { ChatService, ChatServiceConfig, createChatService };
|
|
73
|
+
//# sourceMappingURL=chat-service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chat-service.d.ts","names":[],"sources":["../../src/core/chat-service.ts"],"sourcesContent":[],"mappings":";;;;;;;;;AAmBA;AAEY,UAFK,iBAAA,CAEL;EAEA;EAEF,QAAA,EAJE,QAIF;EAAiB;EA8Bd,OAAA,CAAA,EAhCD,gBAgCY;EAWF;EAYA,KAAA,CAAA,EArDZ,iBAqDY;EAA6B;EAAR,YAAA,CAAA,EAAA,MAAA;EA6EnB;EAA6B,kBAAA,CAAA,EAAA,MAAA;EAAR;EAqGhC,OAAA,CAAA,EAAA,CAAA,KAAA,EAAA;IAAR,WAAA,EAAA,MAAA;IAUS,YAAA,EAAA,MAAA;EAAR,CAAA,EAAA,GAAA,IAAA;;;AA2DN;;cA9Qa,WAAA;;;;;;;sBAWS;;;;gBAYA,qBAAqB,QAAQ;;;;kBA6E3B,qBAAqB,QAAQ;;;;2CAqGhD,QAAQ;;;;;;;MAUP,QAAQ;;;;8CAUsC;;;;;;;;;iBAiDpC,iBAAA,SAA0B,oBAAoB"}
|