@builder.io/ai-utils 0.1.5 → 0.2.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 +495 -0
- package/src/completion.ts +174 -0
- package/src/events.ts +458 -0
- package/src/mapping.ts +98 -0
- package/src/messages.ts +238 -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.d.ts
DELETED
|
@@ -1,165 +0,0 @@
|
|
|
1
|
-
import type { ContentUpdatePatch } from "./events.js";
|
|
2
|
-
/**
|
|
3
|
-
* Message param does not know the id of the message.
|
|
4
|
-
* This is an input message.
|
|
5
|
-
*/
|
|
6
|
-
export type MessageParam = SystemMessageParam | UserMessageParam | AssistantMessageParam;
|
|
7
|
-
export interface ContentMessageItemText {
|
|
8
|
-
type: "text";
|
|
9
|
-
text: string;
|
|
10
|
-
cache?: boolean;
|
|
11
|
-
}
|
|
12
|
-
export interface ContentMessageItemImage {
|
|
13
|
-
type: "image";
|
|
14
|
-
source: ImageBase64Source | ImageUrlSource;
|
|
15
|
-
cache?: boolean;
|
|
16
|
-
}
|
|
17
|
-
export interface ContentMessageItemDocument {
|
|
18
|
-
type: "document";
|
|
19
|
-
source: DocumentBase64Source | DocumentUrlSource;
|
|
20
|
-
cache?: boolean;
|
|
21
|
-
}
|
|
22
|
-
export interface DocumentBase64Source {
|
|
23
|
-
type: "base64";
|
|
24
|
-
media_type: "application/pdf";
|
|
25
|
-
data: string;
|
|
26
|
-
}
|
|
27
|
-
export interface DocumentUrlSource {
|
|
28
|
-
type: "url";
|
|
29
|
-
url: string;
|
|
30
|
-
}
|
|
31
|
-
export interface ContentMessageItemToolResult {
|
|
32
|
-
type: "tool_result";
|
|
33
|
-
tool_use_id: string;
|
|
34
|
-
tool_name?: string;
|
|
35
|
-
tool_input?: string;
|
|
36
|
-
title?: string;
|
|
37
|
-
content: string;
|
|
38
|
-
is_error: boolean;
|
|
39
|
-
cache?: boolean;
|
|
40
|
-
}
|
|
41
|
-
export interface ImageBase64Source {
|
|
42
|
-
type: "base64";
|
|
43
|
-
media_type: "image/webp" | "image/png" | "image/jpeg";
|
|
44
|
-
data: string;
|
|
45
|
-
}
|
|
46
|
-
export interface ImageUrlSource {
|
|
47
|
-
type: "url";
|
|
48
|
-
url: string;
|
|
49
|
-
}
|
|
50
|
-
export interface ContentMessageItemThinking {
|
|
51
|
-
type: "thinking";
|
|
52
|
-
thinking: string;
|
|
53
|
-
signature: string;
|
|
54
|
-
}
|
|
55
|
-
export interface ContentMessageItemRedactedThinking {
|
|
56
|
-
type: "redacted_thinking";
|
|
57
|
-
data: string;
|
|
58
|
-
}
|
|
59
|
-
export interface ContentMessageItemToolUse {
|
|
60
|
-
type: "tool_use";
|
|
61
|
-
id: string;
|
|
62
|
-
input: unknown;
|
|
63
|
-
completion?: string;
|
|
64
|
-
name: string;
|
|
65
|
-
}
|
|
66
|
-
export type ContentMessageItem = ContentMessageItemText | ContentMessageItemImage | ContentMessageItemDocument | ContentMessageItemThinking | ContentMessageItemRedactedThinking | ContentMessageItemToolUse | ContentMessageItemToolResult;
|
|
67
|
-
export type ContentMessage = ContentMessageItem[];
|
|
68
|
-
export interface SystemMessageParam {
|
|
69
|
-
/**
|
|
70
|
-
* The contents of the system message.
|
|
71
|
-
*/
|
|
72
|
-
content: string | ContentMessageItemText[];
|
|
73
|
-
responseId?: string;
|
|
74
|
-
/**
|
|
75
|
-
* The role of the messages author, in this case `system`.
|
|
76
|
-
*/
|
|
77
|
-
role: "system";
|
|
78
|
-
id?: string;
|
|
79
|
-
}
|
|
80
|
-
export interface UserMessageParam {
|
|
81
|
-
/**
|
|
82
|
-
* The contents of the user message.
|
|
83
|
-
*/
|
|
84
|
-
content: string | (ContentMessageItemText | ContentMessageItemImage | ContentMessageItemDocument | ContentMessageItemToolResult)[];
|
|
85
|
-
responseId?: string;
|
|
86
|
-
/**
|
|
87
|
-
* The role of the messages author, in this case `user`.
|
|
88
|
-
*/
|
|
89
|
-
role: "user";
|
|
90
|
-
id?: string;
|
|
91
|
-
}
|
|
92
|
-
export interface AssistantMessageParam {
|
|
93
|
-
/**
|
|
94
|
-
* The contents of the assistant message.
|
|
95
|
-
*/
|
|
96
|
-
content: string | ContentMessageItem[];
|
|
97
|
-
/**
|
|
98
|
-
* The role of the messages author, in this case `assistant`.
|
|
99
|
-
*/
|
|
100
|
-
role: "assistant";
|
|
101
|
-
responseId?: string;
|
|
102
|
-
/**
|
|
103
|
-
* The function call name and arguments
|
|
104
|
-
*/
|
|
105
|
-
action?: {
|
|
106
|
-
/**
|
|
107
|
-
* The specific function name
|
|
108
|
-
*/
|
|
109
|
-
name: string;
|
|
110
|
-
/** This is arbitrary JSON */
|
|
111
|
-
arguments: any;
|
|
112
|
-
};
|
|
113
|
-
id?: string;
|
|
114
|
-
skipDelta?: boolean;
|
|
115
|
-
/**
|
|
116
|
-
* A summary of the patches which the assistant has made.
|
|
117
|
-
* Useful for genai.
|
|
118
|
-
*/
|
|
119
|
-
patches?: ContentUpdatePatch[];
|
|
120
|
-
state?: "error";
|
|
121
|
-
}
|
|
122
|
-
export interface SystemMessage extends SystemMessageParam {
|
|
123
|
-
id: string;
|
|
124
|
-
}
|
|
125
|
-
export interface UserMessage extends UserMessageParam {
|
|
126
|
-
id: string;
|
|
127
|
-
}
|
|
128
|
-
export interface AssistantMessage extends AssistantMessageParam {
|
|
129
|
-
id: string;
|
|
130
|
-
status?: "accepted" | "rejected" | "aborted";
|
|
131
|
-
}
|
|
132
|
-
export interface AssistantActionMessage {
|
|
133
|
-
/**
|
|
134
|
-
* The role of the messages author, in this case `assistant`.
|
|
135
|
-
*/
|
|
136
|
-
role: "assistant";
|
|
137
|
-
id: string;
|
|
138
|
-
}
|
|
139
|
-
/**
|
|
140
|
-
* Message DOES know the id of the message.
|
|
141
|
-
* This message is after an id has been assigned
|
|
142
|
-
* and is the output message.
|
|
143
|
-
*/
|
|
144
|
-
export type Message = SystemMessage | UserMessage | AssistantMessage;
|
|
145
|
-
export type GeneratingMessage = null | Partial<AssistantActionMessage | AssistantMessage>;
|
|
146
|
-
export declare function getContentText(message: string | ContentMessage): string;
|
|
147
|
-
export declare function getContentAttachments(message: string | ContentMessage): (ImageBase64Source | ImageUrlSource)[];
|
|
148
|
-
export type Attachment = FileUpload | Template | URL;
|
|
149
|
-
export interface URL {
|
|
150
|
-
type: "url";
|
|
151
|
-
value: string;
|
|
152
|
-
}
|
|
153
|
-
export interface FileUpload {
|
|
154
|
-
type: "upload";
|
|
155
|
-
contentType: string;
|
|
156
|
-
name: string;
|
|
157
|
-
dataUrl: string;
|
|
158
|
-
size: number;
|
|
159
|
-
id: string;
|
|
160
|
-
}
|
|
161
|
-
export interface Template {
|
|
162
|
-
type: "template";
|
|
163
|
-
name: string;
|
|
164
|
-
id: number;
|
|
165
|
-
}
|
package/src/messages.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
export function getContentText(message) {
|
|
2
|
-
if (typeof message === "string") {
|
|
3
|
-
return message;
|
|
4
|
-
}
|
|
5
|
-
return message
|
|
6
|
-
.map((item) => (item.type === "text" ? item.text : ""))
|
|
7
|
-
.join("");
|
|
8
|
-
}
|
|
9
|
-
export function getContentAttachments(message) {
|
|
10
|
-
if (typeof message === "string") {
|
|
11
|
-
return [];
|
|
12
|
-
}
|
|
13
|
-
return message
|
|
14
|
-
.filter((item) => item.type === "image")
|
|
15
|
-
.map((item) => item.source);
|
|
16
|
-
}
|
package/src/settings.d.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
export interface AssistantSettings {
|
|
2
|
-
assistantType?: string;
|
|
3
|
-
viewId?: string;
|
|
4
|
-
theme?: "dark" | "light";
|
|
5
|
-
}
|
|
6
|
-
interface IframeSettings extends Partial<AssistantSettings> {
|
|
7
|
-
local?: boolean;
|
|
8
|
-
/**
|
|
9
|
-
* The URL of the assistant.
|
|
10
|
-
*/
|
|
11
|
-
baseUrl?: string;
|
|
12
|
-
}
|
|
13
|
-
export declare function getAssistantUrl(opts?: IframeSettings): string;
|
|
14
|
-
export declare function parseAssistantUrlSettings(url: string): Partial<AssistantSettings>;
|
|
15
|
-
export interface BuilderEditorAuth {
|
|
16
|
-
spaceId: string;
|
|
17
|
-
userId: string;
|
|
18
|
-
authToken: string;
|
|
19
|
-
}
|
|
20
|
-
export {};
|
package/src/settings.js
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
const urlParamSettings = [
|
|
2
|
-
"assistantType",
|
|
3
|
-
"theme",
|
|
4
|
-
"viewId",
|
|
5
|
-
];
|
|
6
|
-
export function getAssistantUrl(opts = {}) {
|
|
7
|
-
var _a;
|
|
8
|
-
const url = new URL((_a = opts.baseUrl) !== null && _a !== void 0 ? _a : (opts.local ? "http://localhost:7242" : "https://assistant.builder.io"));
|
|
9
|
-
urlParamSettings.forEach((key) => {
|
|
10
|
-
const value = opts[key];
|
|
11
|
-
if (typeof value === "string" || typeof value === "boolean") {
|
|
12
|
-
url.searchParams.set(key, String(value));
|
|
13
|
-
}
|
|
14
|
-
});
|
|
15
|
-
return url.href;
|
|
16
|
-
}
|
|
17
|
-
export function parseAssistantUrlSettings(url) {
|
|
18
|
-
const parsed = new URL(url);
|
|
19
|
-
const settings = {};
|
|
20
|
-
urlParamSettings.forEach((key) => {
|
|
21
|
-
const value = parsed.searchParams.get(key);
|
|
22
|
-
if (value === "true" || value === "false") {
|
|
23
|
-
settings[key] = value === "true";
|
|
24
|
-
}
|
|
25
|
-
else if (value) {
|
|
26
|
-
settings[key] = value;
|
|
27
|
-
}
|
|
28
|
-
});
|
|
29
|
-
return settings;
|
|
30
|
-
}
|
package/src/thread.d.ts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import type { Message } from "./messages.js";
|
|
2
|
-
export interface Thread {
|
|
3
|
-
/**
|
|
4
|
-
* The unique LOCAL identifier of the thread.
|
|
5
|
-
*/
|
|
6
|
-
id: string;
|
|
7
|
-
/**
|
|
8
|
-
* The unique OPENAI identifier of the thread. This is only
|
|
9
|
-
* set after openai creates the thread.
|
|
10
|
-
*/
|
|
11
|
-
threadId?: string;
|
|
12
|
-
platformId?: string;
|
|
13
|
-
title?: string;
|
|
14
|
-
/**
|
|
15
|
-
* The type of assistant that the thread is associated with.
|
|
16
|
-
* For example, "content-editor" or "docs".
|
|
17
|
-
*/
|
|
18
|
-
assistantType?: string;
|
|
19
|
-
/**
|
|
20
|
-
* The unique identifier of the view that the thread is associated with.
|
|
21
|
-
* For example, the "content-editor" assistant would use the
|
|
22
|
-
* builder content id as the viewId.
|
|
23
|
-
*/
|
|
24
|
-
viewId?: string;
|
|
25
|
-
created: number;
|
|
26
|
-
messages: Message[];
|
|
27
|
-
}
|
package/src/thread.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/src/vcp.d.ts
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import type { ESMImport } from "./codegen";
|
|
2
|
-
export interface BuilderComponentInfo {
|
|
3
|
-
name: string;
|
|
4
|
-
inputs?: BuilderComponentInput[];
|
|
5
|
-
path: string;
|
|
6
|
-
imports: {
|
|
7
|
-
[key: string]: string | undefined;
|
|
8
|
-
};
|
|
9
|
-
esmImports?: ESMImport[];
|
|
10
|
-
options?: any;
|
|
11
|
-
}
|
|
12
|
-
export interface BuilderComponentInput {
|
|
13
|
-
name: string;
|
|
14
|
-
type: string;
|
|
15
|
-
value: any;
|
|
16
|
-
}
|
|
17
|
-
export interface BuilderComponentSlot {
|
|
18
|
-
figmaId: string;
|
|
19
|
-
builderName: string;
|
|
20
|
-
}
|
|
21
|
-
export interface JSXNode {
|
|
22
|
-
"@type": "jsx";
|
|
23
|
-
name: string;
|
|
24
|
-
props: Record<string, any>;
|
|
25
|
-
tagName?: string;
|
|
26
|
-
includeAirLayoutStyles?: boolean;
|
|
27
|
-
path?: string;
|
|
28
|
-
imports?: {
|
|
29
|
-
[key: string]: string | undefined;
|
|
30
|
-
};
|
|
31
|
-
esmImports?: ESMImport[];
|
|
32
|
-
}
|
package/src/vcp.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
File without changes
|