@builder.io/ai-utils 0.1.5 → 0.3.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/README.md +3 -0
- package/package.json +1 -1
- package/src/codegen.ts +517 -0
- package/src/completion.ts +174 -0
- package/src/events.ts +469 -0
- package/src/mapping.ts +98 -0
- package/src/messages.ts +240 -0
- package/src/settings.ts +59 -0
- package/src/codegen.d.ts +0 -354
- package/src/codegen.js +0 -1
- package/src/complete-json.d.ts +0 -4
- package/src/complete-json.js +0 -52
- package/src/completion.d.ts +0 -154
- package/src/completion.js +0 -1
- package/src/events.d.ts +0 -354
- package/src/events.js +0 -1
- package/src/fetch.d.ts +0 -1
- package/src/fetch.js +0 -83
- package/src/index.js +0 -6
- package/src/mapping.d.ts +0 -86
- package/src/mapping.js +0 -1
- package/src/messages.d.ts +0 -165
- package/src/messages.js +0 -16
- package/src/settings.d.ts +0 -20
- package/src/settings.js +0 -30
- package/src/thread.d.ts +0 -27
- package/src/thread.js +0 -1
- package/src/vcp.d.ts +0 -32
- package/src/vcp.js +0 -1
- /package/src/{index.d.ts → index.ts} +0 -0
package/src/messages.ts
ADDED
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
import type { ContentUpdatePatch } from "./events.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Message param does not know the id of the message.
|
|
5
|
+
* This is an input message.
|
|
6
|
+
*/
|
|
7
|
+
export type MessageParam =
|
|
8
|
+
| SystemMessageParam
|
|
9
|
+
| UserMessageParam
|
|
10
|
+
| AssistantMessageParam;
|
|
11
|
+
|
|
12
|
+
export interface ContentMessageItemText {
|
|
13
|
+
type: "text";
|
|
14
|
+
text: string;
|
|
15
|
+
cache?: boolean;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface ContentMessageItemImage {
|
|
19
|
+
type: "image";
|
|
20
|
+
source: ImageBase64Source | ImageUrlSource;
|
|
21
|
+
cache?: boolean;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface ContentMessageItemDocument {
|
|
25
|
+
type: "document";
|
|
26
|
+
source: DocumentBase64Source | DocumentUrlSource;
|
|
27
|
+
cache?: boolean;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface DocumentBase64Source {
|
|
31
|
+
type: "base64";
|
|
32
|
+
media_type: "application/pdf";
|
|
33
|
+
data: string;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface DocumentUrlSource {
|
|
37
|
+
type: "url";
|
|
38
|
+
url: string;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface ContentMessageItemToolResult {
|
|
42
|
+
type: "tool_result";
|
|
43
|
+
tool_use_id: string;
|
|
44
|
+
tool_name?: string;
|
|
45
|
+
tool_input?: string;
|
|
46
|
+
title?: string;
|
|
47
|
+
content: string;
|
|
48
|
+
is_error: boolean;
|
|
49
|
+
cache?: boolean;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export interface ImageBase64Source {
|
|
53
|
+
type: "base64";
|
|
54
|
+
media_type: "image/webp" | "image/png" | "image/jpeg";
|
|
55
|
+
data: string;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export interface ImageUrlSource {
|
|
59
|
+
type: "url";
|
|
60
|
+
url: string;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export interface ContentMessageItemThinking {
|
|
64
|
+
type: "thinking";
|
|
65
|
+
thinking: string;
|
|
66
|
+
signature: string;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export interface ContentMessageItemRedactedThinking {
|
|
70
|
+
type: "redacted_thinking";
|
|
71
|
+
data: string;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export interface ContentMessageItemToolUse {
|
|
75
|
+
type: "tool_use";
|
|
76
|
+
id: string;
|
|
77
|
+
input: unknown;
|
|
78
|
+
completion?: string;
|
|
79
|
+
name: string;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export type ContentMessageItem =
|
|
83
|
+
| ContentMessageItemText
|
|
84
|
+
| ContentMessageItemImage
|
|
85
|
+
| ContentMessageItemDocument
|
|
86
|
+
| ContentMessageItemThinking
|
|
87
|
+
| ContentMessageItemRedactedThinking
|
|
88
|
+
| ContentMessageItemToolUse
|
|
89
|
+
| ContentMessageItemToolResult;
|
|
90
|
+
|
|
91
|
+
export type ContentMessage = ContentMessageItem[];
|
|
92
|
+
|
|
93
|
+
export interface SystemMessageParam {
|
|
94
|
+
/**
|
|
95
|
+
* The contents of the system message.
|
|
96
|
+
*/
|
|
97
|
+
content: string | ContentMessageItemText[];
|
|
98
|
+
|
|
99
|
+
// an id to track messages across a response including multiple retries
|
|
100
|
+
responseId?: string;
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* The role of the messages author, in this case `system`.
|
|
104
|
+
*/
|
|
105
|
+
role: "system";
|
|
106
|
+
|
|
107
|
+
id?: string;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export interface UserMessageParam {
|
|
111
|
+
/**
|
|
112
|
+
* The contents of the user message.
|
|
113
|
+
*/
|
|
114
|
+
content:
|
|
115
|
+
| string
|
|
116
|
+
| (
|
|
117
|
+
| ContentMessageItemText
|
|
118
|
+
| ContentMessageItemImage
|
|
119
|
+
| ContentMessageItemDocument
|
|
120
|
+
| ContentMessageItemToolResult
|
|
121
|
+
)[];
|
|
122
|
+
|
|
123
|
+
// an id to track messages across a response including multiple retries
|
|
124
|
+
responseId?: string;
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* The role of the messages author, in this case `user`.
|
|
128
|
+
*/
|
|
129
|
+
role: "user";
|
|
130
|
+
id?: string;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export interface AssistantMessageParam {
|
|
134
|
+
/**
|
|
135
|
+
* The contents of the assistant message.
|
|
136
|
+
*/
|
|
137
|
+
content: string | ContentMessageItem[];
|
|
138
|
+
/**
|
|
139
|
+
* The role of the messages author, in this case `assistant`.
|
|
140
|
+
*/
|
|
141
|
+
role: "assistant";
|
|
142
|
+
|
|
143
|
+
// an id to track messages across a response including multiple retries
|
|
144
|
+
responseId?: string;
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* The function call name and arguments
|
|
148
|
+
*/
|
|
149
|
+
action?: {
|
|
150
|
+
/**
|
|
151
|
+
* The specific function name
|
|
152
|
+
*/
|
|
153
|
+
name: string;
|
|
154
|
+
/** This is arbitrary JSON */
|
|
155
|
+
arguments: any;
|
|
156
|
+
};
|
|
157
|
+
id?: string;
|
|
158
|
+
skipDelta?: boolean;
|
|
159
|
+
/**
|
|
160
|
+
* A summary of the patches which the assistant has made.
|
|
161
|
+
* Useful for genai.
|
|
162
|
+
*/
|
|
163
|
+
patches?: ContentUpdatePatch[];
|
|
164
|
+
state?: "error";
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
export interface SystemMessage extends SystemMessageParam {
|
|
168
|
+
id: string;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
export interface UserMessage extends UserMessageParam {
|
|
172
|
+
id: string;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
export interface AssistantMessage extends AssistantMessageParam {
|
|
176
|
+
id: string;
|
|
177
|
+
status?: "accepted" | "rejected" | "aborted";
|
|
178
|
+
// Optional summary from the LLM that explains why it did
|
|
179
|
+
summary?: string;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
export interface AssistantActionMessage {
|
|
183
|
+
/**
|
|
184
|
+
* The role of the messages author, in this case `assistant`.
|
|
185
|
+
*/
|
|
186
|
+
role: "assistant";
|
|
187
|
+
|
|
188
|
+
id: string;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Message DOES know the id of the message.
|
|
193
|
+
* This message is after an id has been assigned
|
|
194
|
+
* and is the output message.
|
|
195
|
+
*/
|
|
196
|
+
export type Message = SystemMessage | UserMessage | AssistantMessage;
|
|
197
|
+
|
|
198
|
+
export type GeneratingMessage = null | Partial<
|
|
199
|
+
AssistantActionMessage | AssistantMessage
|
|
200
|
+
>;
|
|
201
|
+
|
|
202
|
+
export function getContentText(message: string | ContentMessage) {
|
|
203
|
+
if (typeof message === "string") {
|
|
204
|
+
return message;
|
|
205
|
+
}
|
|
206
|
+
return message
|
|
207
|
+
.map((item) => (item.type === "text" ? item.text : ""))
|
|
208
|
+
.join("");
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
export function getContentAttachments(message: string | ContentMessage) {
|
|
212
|
+
if (typeof message === "string") {
|
|
213
|
+
return [];
|
|
214
|
+
}
|
|
215
|
+
return message
|
|
216
|
+
.filter((item) => item.type === "image")
|
|
217
|
+
.map((item) => item.source);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
export type Attachment = FileUpload | Template | URL;
|
|
221
|
+
|
|
222
|
+
export interface URL {
|
|
223
|
+
type: "url";
|
|
224
|
+
value: string;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
export interface FileUpload {
|
|
228
|
+
type: "upload";
|
|
229
|
+
contentType: string;
|
|
230
|
+
name: string;
|
|
231
|
+
dataUrl: string;
|
|
232
|
+
size: number;
|
|
233
|
+
id: string;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
export interface Template {
|
|
237
|
+
type: "template";
|
|
238
|
+
name: string;
|
|
239
|
+
id: number;
|
|
240
|
+
}
|
package/src/settings.ts
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
export interface AssistantSettings {
|
|
2
|
+
assistantType?: string;
|
|
3
|
+
viewId?: string;
|
|
4
|
+
theme?: "dark" | "light";
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
interface IframeSettings extends Partial<AssistantSettings> {
|
|
8
|
+
local?: boolean;
|
|
9
|
+
/**
|
|
10
|
+
* The URL of the assistant.
|
|
11
|
+
*/
|
|
12
|
+
baseUrl?: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
type AssistantSettingsKeys = keyof AssistantSettings;
|
|
16
|
+
|
|
17
|
+
const urlParamSettings: AssistantSettingsKeys[] = [
|
|
18
|
+
"assistantType",
|
|
19
|
+
"theme",
|
|
20
|
+
"viewId",
|
|
21
|
+
];
|
|
22
|
+
|
|
23
|
+
export function getAssistantUrl(opts: IframeSettings = {}) {
|
|
24
|
+
const url = new URL(
|
|
25
|
+
opts.baseUrl ??
|
|
26
|
+
(opts.local ? "http://localhost:7242" : "https://assistant.builder.io"),
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
urlParamSettings.forEach((key) => {
|
|
30
|
+
const value = opts[key];
|
|
31
|
+
if (typeof value === "string" || typeof value === "boolean") {
|
|
32
|
+
url.searchParams.set(key, String(value));
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
return url.href;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function parseAssistantUrlSettings(url: string) {
|
|
40
|
+
const parsed = new URL(url);
|
|
41
|
+
const settings: Record<string, string | boolean> = {};
|
|
42
|
+
|
|
43
|
+
urlParamSettings.forEach((key) => {
|
|
44
|
+
const value = parsed.searchParams.get(key);
|
|
45
|
+
if (value === "true" || value === "false") {
|
|
46
|
+
settings[key] = value === "true";
|
|
47
|
+
} else if (value) {
|
|
48
|
+
settings[key] = value;
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
return settings as Partial<AssistantSettings>;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export interface BuilderEditorAuth {
|
|
56
|
+
spaceId: string;
|
|
57
|
+
userId: string;
|
|
58
|
+
authToken: string;
|
|
59
|
+
}
|
package/src/codegen.d.ts
DELETED
|
@@ -1,354 +0,0 @@
|
|
|
1
|
-
import type { Attachment, ContentMessageItemToolResult, UserMessageParam } from "./messages";
|
|
2
|
-
import type { BuilderContent } from "./completion";
|
|
3
|
-
import type { Options as PrettierOptions } from "prettier";
|
|
4
|
-
import type { UserContext } from "./mapping";
|
|
5
|
-
import type { AssistantMessageParam } from "./messages";
|
|
6
|
-
export type ImportType = "named" | "default";
|
|
7
|
-
export interface ESMImport {
|
|
8
|
-
importName: string;
|
|
9
|
-
importPath: string;
|
|
10
|
-
importType: ImportType;
|
|
11
|
-
}
|
|
12
|
-
export interface ProjectFile {
|
|
13
|
-
filePath: string;
|
|
14
|
-
content?: string;
|
|
15
|
-
importance?: number;
|
|
16
|
-
dropReason?: string;
|
|
17
|
-
wasIncluded?: boolean;
|
|
18
|
-
}
|
|
19
|
-
export interface CustomInstruction {
|
|
20
|
-
id: string;
|
|
21
|
-
name: string;
|
|
22
|
-
content: string;
|
|
23
|
-
type?: "always" | "agent-mode" | string;
|
|
24
|
-
glob?: string;
|
|
25
|
-
description?: string;
|
|
26
|
-
}
|
|
27
|
-
export type CodeGenFramework = "react" | "html" | "mitosis" | "react-native" | "angular" | "vue" | "svelte" | "qwik" | "solid" | "marko" | "swiftui" | "jetpack-compose" | "flutter";
|
|
28
|
-
export type CodeGenStyleLibrary = "tailwind" | "tailwind-precise" | "emotion" | "styled-components" | "styled-jsx" | "react-native" | undefined;
|
|
29
|
-
export type CompletionStopReason = "max_tokens" | "stop_sequence" | "tool_use" | "end_turn" | "content_filter" | null;
|
|
30
|
-
export interface ViewPathToolInput {
|
|
31
|
-
filePath: string;
|
|
32
|
-
viewRange?: [number, number];
|
|
33
|
-
}
|
|
34
|
-
export interface GlobSearchToolInput {
|
|
35
|
-
pattern: string;
|
|
36
|
-
}
|
|
37
|
-
export interface GrepSearchToolInput {
|
|
38
|
-
query: string;
|
|
39
|
-
includeGlob?: string;
|
|
40
|
-
excludeGlob?: string;
|
|
41
|
-
}
|
|
42
|
-
export interface GetRuleToolInput {
|
|
43
|
-
name: string;
|
|
44
|
-
type?: "always" | "agent-mode" | string;
|
|
45
|
-
glob?: string;
|
|
46
|
-
description?: string;
|
|
47
|
-
}
|
|
48
|
-
export interface CodeGenToolMap {
|
|
49
|
-
view_path: ViewPathToolInput;
|
|
50
|
-
glob_search: GlobSearchToolInput;
|
|
51
|
-
grep_search: GrepSearchToolInput;
|
|
52
|
-
get_rule: GetRuleToolInput;
|
|
53
|
-
}
|
|
54
|
-
export type CodeGenTools = keyof CodeGenToolMap;
|
|
55
|
-
export type CodeGenMode = "exact" | "precise" | "precise_vision" | "creative" | "creative_vision" | "creative_only_vision";
|
|
56
|
-
export interface CodeGenInputOptions {
|
|
57
|
-
position: string;
|
|
58
|
-
eventName?: string;
|
|
59
|
-
sessionId: string;
|
|
60
|
-
codeGenMode?: "fast" | "quality" | "quality-v3";
|
|
61
|
-
url?: string;
|
|
62
|
-
diffActions?: boolean;
|
|
63
|
-
planningPrompt?: boolean;
|
|
64
|
-
customInstructions?: CustomInstruction[];
|
|
65
|
-
userPrompt?: string;
|
|
66
|
-
displayUserPrompt?: string;
|
|
67
|
-
files?: ProjectFile[];
|
|
68
|
-
rerankFiles?: number;
|
|
69
|
-
toolResults?: ContentMessageItemToolResult[];
|
|
70
|
-
attachments?: Attachment[];
|
|
71
|
-
beforeCommit?: string;
|
|
72
|
-
builderContent?: BuilderContent;
|
|
73
|
-
framework?: CodeGenFramework;
|
|
74
|
-
styleLibrary?: CodeGenStyleLibrary;
|
|
75
|
-
typescript?: boolean;
|
|
76
|
-
userContext?: UserContext;
|
|
77
|
-
enabledTools?: CodeGenTools[];
|
|
78
|
-
maxTokens?: number;
|
|
79
|
-
maxPages?: number;
|
|
80
|
-
autoContinue?: number;
|
|
81
|
-
promptCaching?: boolean;
|
|
82
|
-
isAutoContinue?: boolean;
|
|
83
|
-
llmSuggestions?: boolean;
|
|
84
|
-
conclusionText?: boolean;
|
|
85
|
-
searchResponse?: any | null;
|
|
86
|
-
prettierConfig?: PrettierOptions;
|
|
87
|
-
/** @deprecated */
|
|
88
|
-
history?: (UserMessageParam | AssistantMessageParam)[];
|
|
89
|
-
/** @deprecated */
|
|
90
|
-
prevId?: string;
|
|
91
|
-
/** @deprecated */
|
|
92
|
-
nextPage?: boolean;
|
|
93
|
-
/** @deprecated */
|
|
94
|
-
vcpId?: string;
|
|
95
|
-
}
|
|
96
|
-
export type Feature = "component-mapping";
|
|
97
|
-
export interface CodegenUsage {
|
|
98
|
-
total: number;
|
|
99
|
-
fast: number;
|
|
100
|
-
quality: number;
|
|
101
|
-
features: Feature[];
|
|
102
|
-
limits: {
|
|
103
|
-
aiGeneration: number;
|
|
104
|
-
aiGenerationContextWindow: number;
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
|
-
export interface PromptSuggestion {
|
|
108
|
-
type: "missing-imports" | "lazy-code" | "syntax-error" | "llm-suggested" | "diff-apply";
|
|
109
|
-
filePath?: string;
|
|
110
|
-
line?: number;
|
|
111
|
-
importance: "high" | "medium" | "low";
|
|
112
|
-
column?: number;
|
|
113
|
-
summary: string;
|
|
114
|
-
prompt: string;
|
|
115
|
-
}
|
|
116
|
-
export interface ActionItem {
|
|
117
|
-
type: "file" | "text" | "diff" | "thinking" | "tool" | "suggestion" | "tool_result";
|
|
118
|
-
id?: string;
|
|
119
|
-
content: string;
|
|
120
|
-
filePath?: string;
|
|
121
|
-
artifactTitle?: string;
|
|
122
|
-
actionTitle?: string;
|
|
123
|
-
synthetic?: boolean;
|
|
124
|
-
incomplete?: boolean;
|
|
125
|
-
suggestions?: PromptSuggestion[];
|
|
126
|
-
errors?: string[];
|
|
127
|
-
}
|
|
128
|
-
export interface RepoInfo {
|
|
129
|
-
remoteUrl: string;
|
|
130
|
-
defaultBranch: string;
|
|
131
|
-
currentBranch: string;
|
|
132
|
-
commit: string;
|
|
133
|
-
}
|
|
134
|
-
export interface CodebaseSearchOptions {
|
|
135
|
-
repoInfo?: RepoInfo;
|
|
136
|
-
query: string;
|
|
137
|
-
selectedFiles?: string[];
|
|
138
|
-
sessionId: string;
|
|
139
|
-
files?: string[];
|
|
140
|
-
packageJson?: string;
|
|
141
|
-
limit?: number;
|
|
142
|
-
includeContent?: boolean;
|
|
143
|
-
}
|
|
144
|
-
export interface CodebaseSearchResponse {
|
|
145
|
-
id: string;
|
|
146
|
-
relevantPaths: string[];
|
|
147
|
-
grepQueries: string[];
|
|
148
|
-
streamMeta: any;
|
|
149
|
-
ranked: RankedResult[];
|
|
150
|
-
}
|
|
151
|
-
export interface RankedResult {
|
|
152
|
-
index: number;
|
|
153
|
-
filePath: string;
|
|
154
|
-
startIndex: number;
|
|
155
|
-
endIndex: number;
|
|
156
|
-
score: number;
|
|
157
|
-
id: string;
|
|
158
|
-
content?: string;
|
|
159
|
-
}
|
|
160
|
-
export interface GenerateCompletionStepThinking {
|
|
161
|
-
type: "thinking";
|
|
162
|
-
}
|
|
163
|
-
export interface FileInfo {
|
|
164
|
-
filePath: string;
|
|
165
|
-
size: number;
|
|
166
|
-
}
|
|
167
|
-
export interface GenerateCompletionStepUserInput {
|
|
168
|
-
type: "user-input";
|
|
169
|
-
prompt: string;
|
|
170
|
-
files: FileInfo[];
|
|
171
|
-
}
|
|
172
|
-
export interface GenerateCompletionStepToolResult {
|
|
173
|
-
type: "agent-input";
|
|
174
|
-
toolResults: ContentMessageItemToolResult[];
|
|
175
|
-
}
|
|
176
|
-
export interface GenerateCompletionStepPlanning {
|
|
177
|
-
type: "planning";
|
|
178
|
-
content: string;
|
|
179
|
-
}
|
|
180
|
-
export interface GenerateCompletionStepUser {
|
|
181
|
-
type: "user";
|
|
182
|
-
displayPrompt: string | undefined;
|
|
183
|
-
id: string;
|
|
184
|
-
role: "user" | "agent";
|
|
185
|
-
}
|
|
186
|
-
export interface GenerateCompletionStepFile {
|
|
187
|
-
type: "file";
|
|
188
|
-
filePath: string;
|
|
189
|
-
content: string;
|
|
190
|
-
title: string;
|
|
191
|
-
id: string;
|
|
192
|
-
}
|
|
193
|
-
export interface GenerateCompletionStepDiff {
|
|
194
|
-
type: "diff";
|
|
195
|
-
filePath: string;
|
|
196
|
-
content: string;
|
|
197
|
-
title: string;
|
|
198
|
-
id: string;
|
|
199
|
-
}
|
|
200
|
-
export interface GenerateCompletionStepTool {
|
|
201
|
-
type: "tool";
|
|
202
|
-
name: string;
|
|
203
|
-
id: string;
|
|
204
|
-
content: string;
|
|
205
|
-
}
|
|
206
|
-
export interface GenerateCompletionStepText {
|
|
207
|
-
type: "text";
|
|
208
|
-
content: string;
|
|
209
|
-
}
|
|
210
|
-
export interface GenerateCompletionStepDone {
|
|
211
|
-
type: "done";
|
|
212
|
-
id: string;
|
|
213
|
-
applyResults: ApplyActionsResult[];
|
|
214
|
-
actions: ActionItem[];
|
|
215
|
-
usage: CodegenUsage | undefined;
|
|
216
|
-
url?: string;
|
|
217
|
-
stopReason: CompletionStopReason;
|
|
218
|
-
}
|
|
219
|
-
export interface GenerateCompletionStepStart {
|
|
220
|
-
type: "start";
|
|
221
|
-
name: string;
|
|
222
|
-
id: string | undefined;
|
|
223
|
-
title: string;
|
|
224
|
-
content: string;
|
|
225
|
-
}
|
|
226
|
-
export interface GenerateCompletionStepDelta {
|
|
227
|
-
type: "delta";
|
|
228
|
-
name: string;
|
|
229
|
-
delta: string;
|
|
230
|
-
}
|
|
231
|
-
export interface GenerateCompletionStepError {
|
|
232
|
-
type: "error";
|
|
233
|
-
id?: string;
|
|
234
|
-
stopReason?: "error" | "limit";
|
|
235
|
-
metadata?: any;
|
|
236
|
-
message: string;
|
|
237
|
-
usage?: CodegenUsage;
|
|
238
|
-
}
|
|
239
|
-
export interface GenerateCompletionStepContinue {
|
|
240
|
-
type: "continue";
|
|
241
|
-
id: string;
|
|
242
|
-
url: string;
|
|
243
|
-
}
|
|
244
|
-
export interface GenerateCompletionStepWaitForInput {
|
|
245
|
-
type: "wait-for-input";
|
|
246
|
-
}
|
|
247
|
-
export interface GenerateCompletionStepAbort {
|
|
248
|
-
type: "user-abort";
|
|
249
|
-
}
|
|
250
|
-
export interface GenerateCompletionStepRestore {
|
|
251
|
-
type: "restore";
|
|
252
|
-
location: "before" | "after";
|
|
253
|
-
files: string[];
|
|
254
|
-
targetCompletionId: string;
|
|
255
|
-
lastCompletionId: string;
|
|
256
|
-
commitHash: string | undefined;
|
|
257
|
-
}
|
|
258
|
-
export type GenerateCompletionStep = {
|
|
259
|
-
timestamp?: number;
|
|
260
|
-
} & (GenerateCompletionStepPlanning | GenerateCompletionStepStart | GenerateCompletionStepDelta | GenerateCompletionStepUser | GenerateCompletionStepFile | GenerateCompletionStepDiff | GenerateCompletionStepTool | GenerateCompletionStepError | GenerateCompletionStepContinue | GenerateCompletionStepWaitForInput | GenerateCompletionStepAbort | GenerateCompletionStepDone | GenerateCompletionStepUserInput | GenerateCompletionStepText | GenerateCompletionStepRestore | GenerateCompletionStepToolResult);
|
|
261
|
-
export interface ApplyActionsResult {
|
|
262
|
-
filePath: string;
|
|
263
|
-
addedLines: number;
|
|
264
|
-
removedLines: number;
|
|
265
|
-
action: "create" | "update" | "delete";
|
|
266
|
-
content?: string;
|
|
267
|
-
oldContent?: string;
|
|
268
|
-
}
|
|
269
|
-
export interface GenerateUserMessage {
|
|
270
|
-
userPrompt: string;
|
|
271
|
-
displayPrompt?: string;
|
|
272
|
-
files?: string[];
|
|
273
|
-
includeBaseFiles?: boolean;
|
|
274
|
-
skipSearch?: boolean;
|
|
275
|
-
attachments?: Attachment[];
|
|
276
|
-
}
|
|
277
|
-
export interface UserInput {
|
|
278
|
-
userMessage: GenerateUserMessage | undefined;
|
|
279
|
-
userPrompt: string;
|
|
280
|
-
attachments: Attachment[];
|
|
281
|
-
files: ProjectFile[];
|
|
282
|
-
searchResponse: CodebaseSearchResponse | null;
|
|
283
|
-
rerankFiles?: number;
|
|
284
|
-
mostRelevantFile: string | null;
|
|
285
|
-
toolResults: ContentMessageItemToolResult[];
|
|
286
|
-
role: "user" | "agent";
|
|
287
|
-
}
|
|
288
|
-
export interface CodegenTurn {
|
|
289
|
-
state: "running" | "done" | "error" | "aborted" | "reverted";
|
|
290
|
-
unixTime: number;
|
|
291
|
-
completionId: string;
|
|
292
|
-
title: string;
|
|
293
|
-
nextUrl: string | undefined;
|
|
294
|
-
role: "user" | "agent";
|
|
295
|
-
actions: ActionItem[];
|
|
296
|
-
sentiment: "positive" | "negative" | "undo" | undefined;
|
|
297
|
-
applyResults: ApplyActionsResult[];
|
|
298
|
-
userMessage: GenerateUserMessage | undefined;
|
|
299
|
-
beforeCommit: string | undefined;
|
|
300
|
-
afterCommit: string | undefined;
|
|
301
|
-
}
|
|
302
|
-
export interface CodegenFeedback {
|
|
303
|
-
id: string;
|
|
304
|
-
feedbackText?: string;
|
|
305
|
-
feedbackSentiment?: string;
|
|
306
|
-
framework?: string;
|
|
307
|
-
acceptedLines?: number;
|
|
308
|
-
afterCommit?: string;
|
|
309
|
-
}
|
|
310
|
-
export interface GenerateCodeEventDone {
|
|
311
|
-
type: "done";
|
|
312
|
-
unixTime: number;
|
|
313
|
-
stopReason: CompletionStopReason;
|
|
314
|
-
id: string;
|
|
315
|
-
actionTitle: string;
|
|
316
|
-
content?: string;
|
|
317
|
-
needsPagination: boolean;
|
|
318
|
-
actions?: ActionItem[];
|
|
319
|
-
promptSuggestions: PromptSuggestion[];
|
|
320
|
-
usage?: CodegenUsage;
|
|
321
|
-
messageIndex: number;
|
|
322
|
-
willAutoContinue: boolean;
|
|
323
|
-
sessionUsage: number;
|
|
324
|
-
nextUrl: string;
|
|
325
|
-
}
|
|
326
|
-
export interface GenerateCodeEventError {
|
|
327
|
-
type: "error";
|
|
328
|
-
stopReason: "error" | "limit";
|
|
329
|
-
id: string;
|
|
330
|
-
message: string;
|
|
331
|
-
usage?: CodegenUsage;
|
|
332
|
-
}
|
|
333
|
-
export interface GenerateCodeEventPagination {
|
|
334
|
-
type: "pagination";
|
|
335
|
-
pop: number;
|
|
336
|
-
page: number;
|
|
337
|
-
id: string;
|
|
338
|
-
}
|
|
339
|
-
export interface GenerateCodeEventContinue {
|
|
340
|
-
type: "continue";
|
|
341
|
-
id: string;
|
|
342
|
-
nextUrl: string;
|
|
343
|
-
}
|
|
344
|
-
export interface GenerateCodeEventDelta {
|
|
345
|
-
type: "delta";
|
|
346
|
-
content: string;
|
|
347
|
-
}
|
|
348
|
-
export interface GenerateCodeEventUser {
|
|
349
|
-
type: "user";
|
|
350
|
-
id: string;
|
|
351
|
-
displayPrompt: string | undefined;
|
|
352
|
-
role: "user" | "agent";
|
|
353
|
-
}
|
|
354
|
-
export type GenerateCodeEvent = ActionItem | GenerateCodeEventDone | GenerateCodeEventContinue | GenerateCodeEventPagination | GenerateCodeEventDelta | GenerateCodeEventError | GenerateCodeEventUser;
|
package/src/codegen.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/src/complete-json.d.ts
DELETED
package/src/complete-json.js
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Complete a partial JSON string with the necessary closing brackets and braces
|
|
3
|
-
*/
|
|
4
|
-
export function completeJson(input) {
|
|
5
|
-
const stack = [];
|
|
6
|
-
let isInString = false;
|
|
7
|
-
let lastQuote = "";
|
|
8
|
-
// Scan the string to determine the necessary closures
|
|
9
|
-
for (const char of input) {
|
|
10
|
-
switch (char) {
|
|
11
|
-
case '"':
|
|
12
|
-
case "'":
|
|
13
|
-
if (isInString && char === lastQuote) {
|
|
14
|
-
// Check for escaping
|
|
15
|
-
if (input.charAt(input.indexOf(char) - 1) !== "\\") {
|
|
16
|
-
isInString = false;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
else if (!isInString) {
|
|
20
|
-
isInString = true;
|
|
21
|
-
lastQuote = char;
|
|
22
|
-
}
|
|
23
|
-
break;
|
|
24
|
-
case "{":
|
|
25
|
-
case "[":
|
|
26
|
-
if (!isInString) {
|
|
27
|
-
stack.push(char === "{" ? "}" : "]");
|
|
28
|
-
}
|
|
29
|
-
break;
|
|
30
|
-
case "}":
|
|
31
|
-
case "]":
|
|
32
|
-
if (!isInString) {
|
|
33
|
-
if (stack.length > 0 && stack[stack.length - 1] === char) {
|
|
34
|
-
stack.pop();
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
break;
|
|
38
|
-
default:
|
|
39
|
-
break;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
// Close any unclosed string
|
|
43
|
-
if (isInString) {
|
|
44
|
-
input += lastQuote;
|
|
45
|
-
}
|
|
46
|
-
// Close all remaining open brackets and braces
|
|
47
|
-
while (stack.length > 0) {
|
|
48
|
-
const charToClose = stack.pop();
|
|
49
|
-
input += charToClose;
|
|
50
|
-
}
|
|
51
|
-
return input;
|
|
52
|
-
}
|