promptarchitect 0.6.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/.vscodeignore +7 -0
- package/CHANGELOG.md +28 -0
- package/LICENSE +44 -0
- package/README.md +200 -0
- package/docs/CHAT_UI_REDESIGN_PLAN.md +371 -0
- package/images/hub-icon.svg +6 -0
- package/images/prompt-lab-icon.svg +11 -0
- package/package.json +519 -0
- package/src/agentPrompts.ts +278 -0
- package/src/agentService.ts +630 -0
- package/src/api.ts +223 -0
- package/src/authService.ts +556 -0
- package/src/chatPanel.ts +979 -0
- package/src/extension.ts +822 -0
- package/src/providers/aiChatViewProvider.ts +1023 -0
- package/src/providers/environmentTreeProvider.ts +311 -0
- package/src/providers/index.ts +9 -0
- package/src/providers/notesTreeProvider.ts +301 -0
- package/src/providers/quickAccessTreeProvider.ts +328 -0
- package/src/providers/scriptsTreeProvider.ts +324 -0
- package/src/refinerPanel.ts +620 -0
- package/src/templates.ts +61 -0
- package/src/workspaceIndexer.ts +766 -0
- package/tsconfig.json +16 -0
package/src/api.ts
ADDED
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PromptArchitect API Client
|
|
3
|
+
*
|
|
4
|
+
* Connects to the hosted PromptArchitect API.
|
|
5
|
+
* Requires authentication for all requests.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
interface GeneratePromptRequest {
|
|
9
|
+
idea: string;
|
|
10
|
+
template?: string;
|
|
11
|
+
context?: string;
|
|
12
|
+
targetModel?: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
interface GeneratePromptResponse {
|
|
16
|
+
prompt: string;
|
|
17
|
+
template: string;
|
|
18
|
+
metadata: {
|
|
19
|
+
wordCount: number;
|
|
20
|
+
targetModel: string;
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
interface RefinePromptRequest {
|
|
25
|
+
prompt: string;
|
|
26
|
+
feedback: string;
|
|
27
|
+
preserveStructure?: boolean;
|
|
28
|
+
targetModel?: string;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
interface RefinePromptResponse {
|
|
32
|
+
refinedPrompt: string;
|
|
33
|
+
changes: string[];
|
|
34
|
+
metadata: {
|
|
35
|
+
originalWordCount: number;
|
|
36
|
+
refinedWordCount: number;
|
|
37
|
+
structurePreserved: boolean;
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
interface AnalyzePromptRequest {
|
|
42
|
+
prompt: string;
|
|
43
|
+
evaluationCriteria?: string[];
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
interface AnalyzePromptResponse {
|
|
47
|
+
overallScore: number;
|
|
48
|
+
scores: {
|
|
49
|
+
clarity: number;
|
|
50
|
+
specificity: number;
|
|
51
|
+
structure: number;
|
|
52
|
+
actionability: number;
|
|
53
|
+
};
|
|
54
|
+
strengths: string[];
|
|
55
|
+
weaknesses: string[];
|
|
56
|
+
suggestions: string[];
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
interface ChatRequest {
|
|
60
|
+
message: string;
|
|
61
|
+
history?: Array<{ role: string; content: string }>;
|
|
62
|
+
context?: string;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
interface ChatResponse {
|
|
66
|
+
reply: string;
|
|
67
|
+
usage?: {
|
|
68
|
+
promptTokens: number;
|
|
69
|
+
completionTokens: number;
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export class PromptArchitectAPI {
|
|
74
|
+
private baseUrl: string;
|
|
75
|
+
private timeout = 30000;
|
|
76
|
+
private accessToken: string | null = null;
|
|
77
|
+
|
|
78
|
+
constructor(baseUrl: string) {
|
|
79
|
+
this.baseUrl = baseUrl.replace(/\/$/, ''); // Remove trailing slash
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Set the access token for authenticated requests
|
|
84
|
+
*/
|
|
85
|
+
setAccessToken(token: string | null): void {
|
|
86
|
+
this.accessToken = token;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Get current access token
|
|
91
|
+
*/
|
|
92
|
+
getAccessToken(): string | null {
|
|
93
|
+
return this.accessToken;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Generate a prompt from an idea
|
|
98
|
+
*/
|
|
99
|
+
async generatePrompt(request: GeneratePromptRequest): Promise<GeneratePromptResponse> {
|
|
100
|
+
return this.post<GeneratePromptResponse>('/vscode/generate', request);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Refine an existing prompt
|
|
105
|
+
*/
|
|
106
|
+
async refinePrompt(request: RefinePromptRequest): Promise<RefinePromptResponse> {
|
|
107
|
+
return this.post<RefinePromptResponse>('/vscode/refine', request);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Analyze prompt quality
|
|
112
|
+
*/
|
|
113
|
+
async analyzePrompt(request: AnalyzePromptRequest): Promise<AnalyzePromptResponse> {
|
|
114
|
+
return this.post<AnalyzePromptResponse>('/vscode/analyze', request);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Chat with AI - send a message and get a response
|
|
119
|
+
*/
|
|
120
|
+
async chat(request: ChatRequest): Promise<ChatResponse> {
|
|
121
|
+
return this.post<ChatResponse>('/vscode/chat', request);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Check API health/availability
|
|
126
|
+
*/
|
|
127
|
+
async healthCheck(): Promise<{ status: string; service: string }> {
|
|
128
|
+
return this.get<{ status: string; service: string }>('/vscode/health');
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* HTTP GET request
|
|
133
|
+
*/
|
|
134
|
+
private async get<T>(path: string): Promise<T> {
|
|
135
|
+
const controller = new AbortController();
|
|
136
|
+
const timeoutId = setTimeout(() => controller.abort(), this.timeout);
|
|
137
|
+
|
|
138
|
+
const headers: Record<string, string> = {
|
|
139
|
+
'Content-Type': 'application/json',
|
|
140
|
+
'X-Client': 'vscode-extension',
|
|
141
|
+
'X-Client-Version': '0.5.0',
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
// Add auth token if available
|
|
145
|
+
if (this.accessToken) {
|
|
146
|
+
headers['Authorization'] = `Bearer ${this.accessToken}`;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
try {
|
|
150
|
+
const response = await fetch(`${this.baseUrl}${path}`, {
|
|
151
|
+
method: 'GET',
|
|
152
|
+
headers,
|
|
153
|
+
signal: controller.signal,
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
clearTimeout(timeoutId);
|
|
157
|
+
|
|
158
|
+
if (response.status === 401) {
|
|
159
|
+
throw new Error('Authentication required. Please sign in.');
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
if (!response.ok) {
|
|
163
|
+
const error = await response.text();
|
|
164
|
+
throw new Error(`API error (${response.status}): ${error}`);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
return response.json() as T;
|
|
168
|
+
} catch (error) {
|
|
169
|
+
clearTimeout(timeoutId);
|
|
170
|
+
if (error instanceof Error && error.name === 'AbortError') {
|
|
171
|
+
throw new Error('Request timed out. Please try again.');
|
|
172
|
+
}
|
|
173
|
+
throw error;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* HTTP POST request
|
|
179
|
+
*/
|
|
180
|
+
private async post<T>(path: string, body: unknown): Promise<T> {
|
|
181
|
+
const controller = new AbortController();
|
|
182
|
+
const timeoutId = setTimeout(() => controller.abort(), this.timeout);
|
|
183
|
+
|
|
184
|
+
const headers: Record<string, string> = {
|
|
185
|
+
'Content-Type': 'application/json',
|
|
186
|
+
'X-Client': 'vscode-extension',
|
|
187
|
+
'X-Client-Version': '0.5.0',
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
// Add auth token if available
|
|
191
|
+
if (this.accessToken) {
|
|
192
|
+
headers['Authorization'] = `Bearer ${this.accessToken}`;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
try {
|
|
196
|
+
const response = await fetch(`${this.baseUrl}${path}`, {
|
|
197
|
+
method: 'POST',
|
|
198
|
+
headers,
|
|
199
|
+
body: JSON.stringify(body),
|
|
200
|
+
signal: controller.signal,
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
clearTimeout(timeoutId);
|
|
204
|
+
|
|
205
|
+
if (response.status === 401) {
|
|
206
|
+
throw new Error('Authentication required. Please sign in.');
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
if (!response.ok) {
|
|
210
|
+
const error = await response.text();
|
|
211
|
+
throw new Error(`API error (${response.status}): ${error}`);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
return response.json() as T;
|
|
215
|
+
} catch (error) {
|
|
216
|
+
clearTimeout(timeoutId);
|
|
217
|
+
if (error instanceof Error && error.name === 'AbortError') {
|
|
218
|
+
throw new Error('Request timed out. Please try again.');
|
|
219
|
+
}
|
|
220
|
+
throw error;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
}
|