@builder.io/ai-utils 0.18.0 → 0.18.2

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/src/projects.js CHANGED
@@ -1,50 +1,49 @@
1
1
  export const EXAMPLE_REPOS = [
2
- "steve8708/mui-vite",
3
- "steve8708/carbon-vite",
4
- "steve8708/vite-react-shopify-polaris",
5
- "steve8708/cloudscape-demos",
6
- "BuilderIO/fusion-angular-tailwind-starter",
7
- "BuilderIO/fusion-svelte-tailwind-starter",
8
- "BuilderIO/fusion-vue-tailwind-starter",
2
+ "steve8708/mui-vite",
3
+ "steve8708/carbon-vite",
4
+ "steve8708/vite-react-shopify-polaris",
5
+ "steve8708/cloudscape-demos",
6
+ "BuilderIO/fusion-angular-tailwind-starter",
7
+ "BuilderIO/fusion-svelte-tailwind-starter",
8
+ "BuilderIO/fusion-vue-tailwind-starter",
9
9
  ];
10
10
  export const STARTER_REPO = "BuilderIO/fusion-starter";
11
11
  export const EXAMPLE_OR_STARTER_REPOS = [...EXAMPLE_REPOS, STARTER_REPO];
12
- export const EXAMPLE_OR_STARTER_REPOS_URLS = EXAMPLE_OR_STARTER_REPOS.map(
13
- (repo) => `https://github.com/${repo}`,
14
- );
12
+ export const EXAMPLE_OR_STARTER_REPOS_URLS = EXAMPLE_OR_STARTER_REPOS.map((repo) => `https://github.com/${repo}`);
15
13
  export const checkIsNewBranch = (branch) => {
16
- return "projectId" in branch;
14
+ return "projectId" in branch;
17
15
  };
18
16
  /**
19
17
  * Get the state of a branch, checking `state` first and falling back to `deleted` for backwards compatibility.
20
18
  */
21
19
  export const getBranchState = (branch) => {
22
- if (branch.state) return branch.state;
23
- return branch.deleted ? "deleted" : "active";
20
+ if (branch.state)
21
+ return branch.state;
22
+ return branch.deleted ? "deleted" : "active";
24
23
  };
25
24
  /**
26
25
  * Get the state of a project, checking `state` first and falling back to `deleted` for backwards compatibility.
27
26
  */
28
27
  export const getProjectState = (project) => {
29
- var _a;
30
- return (_a = project.state) !== null && _a !== void 0 ? _a : "active";
28
+ var _a;
29
+ return (_a = project.state) !== null && _a !== void 0 ? _a : "active";
31
30
  };
32
31
  /**
33
32
  * Check if a branch is deleted, supporting both `state` and legacy `deleted` fields.
34
33
  * Note: Archived branches are NOT considered deleted.
35
34
  */
36
35
  export const isBranchDeleted = (branch) => {
37
- return getBranchState(branch) === "deleted";
36
+ return getBranchState(branch) === "deleted";
38
37
  };
39
38
  /**
40
39
  * Check if a branch is archived.
41
40
  */
42
41
  export const isBranchArchived = (branch) => {
43
- return getBranchState(branch) === "archived";
42
+ return getBranchState(branch) === "archived";
44
43
  };
45
44
  /**
46
45
  * Check if a project is deleted, supporting both `state` and legacy `deleted` fields.
47
46
  */
48
47
  export const isProjectDeleted = (project) => {
49
- return getProjectState(project) === "deleted";
48
+ return getProjectState(project) === "deleted";
50
49
  };
@@ -1,150 +1,132 @@
1
- export type StoreComponentDocsInput =
2
- | StoreComponentDocsInputV1
3
- | StoreComponentDocsInputV2
4
- | IndexDocumentV1;
1
+ export type StoreComponentDocsInput = StoreComponentDocsInputV1 | StoreComponentDocsInputV2 | IndexDocumentV1;
5
2
  export interface ManualDocumentV1 {
6
- document: IndexDocumentV1;
7
- filePath: string;
8
- frontmatter: Record<string, any>;
9
- body: string;
3
+ document: IndexDocumentV1;
4
+ filePath: string;
5
+ frontmatter: Record<string, any>;
6
+ body: string;
10
7
  }
11
- export type IndexDocumentV1 =
12
- | ComponentDocument
13
- | TokenDocument
14
- | IconDocument
15
- | AgentDocument
16
- | InstallationDocument;
8
+ export type IndexDocumentV1 = ComponentDocument | TokenDocument | IconDocument | AgentDocument | InstallationDocument;
17
9
  export interface ComponentDocument extends DocumentBase {
18
- type: "component";
19
- relatedComponents: string[];
20
- relevantFiles: string[];
21
- hash: string;
10
+ type: "component";
11
+ relatedComponents: string[];
12
+ relevantFiles: string[];
13
+ hash: string;
22
14
  }
23
15
  export interface TokenDocument extends DocumentBase {
24
- type: "token";
25
- hash: string;
26
- relevantFiles: string[];
16
+ type: "token";
17
+ hash: string;
18
+ relevantFiles: string[];
27
19
  }
28
20
  export interface IconDocument extends DocumentBase {
29
- type: "icon";
30
- hash: string;
21
+ type: "icon";
22
+ hash: string;
31
23
  }
32
24
  export interface AgentDocument extends DocumentBase {
33
- type: "agent";
25
+ type: "agent";
34
26
  }
35
27
  export interface InstallationDocument extends DocumentBase {
36
- type: "installation";
37
- hash: string;
28
+ type: "installation";
29
+ hash: string;
38
30
  }
39
31
  export interface DocumentBase {
40
- id?: string;
41
- name: string;
42
- description: string;
43
- content: string;
44
- designSystemId: string;
45
- designSystemPackage?: string;
46
- designSystemVersion?: string;
47
- tokens?: number;
48
- sessionId?: string;
32
+ id?: string;
33
+ name: string;
34
+ description: string;
35
+ content: string;
36
+ designSystemId: string;
37
+ designSystemPackage?: string;
38
+ designSystemVersion?: string;
39
+ tokens?: number;
40
+ sessionId?: string;
49
41
  }
50
- export declare const isAgentDocument: (
51
- doc: IndexDocumentV1,
52
- ) => doc is AgentDocument;
53
- export declare const isIconDocument: (
54
- doc: IndexDocumentV1,
55
- ) => doc is IconDocument;
56
- export declare const isTokenDocument: (
57
- doc: IndexDocumentV1,
58
- ) => doc is TokenDocument;
59
- export declare const isComponentDocument: (
60
- doc: IndexDocumentV1,
61
- ) => doc is ComponentDocument;
62
- export declare const isInstallationDocument: (
63
- doc: IndexDocumentV1,
64
- ) => doc is InstallationDocument;
42
+ export declare const isAgentDocument: (doc: IndexDocumentV1) => doc is AgentDocument;
43
+ export declare const isIconDocument: (doc: IndexDocumentV1) => doc is IconDocument;
44
+ export declare const isTokenDocument: (doc: IndexDocumentV1) => doc is TokenDocument;
45
+ export declare const isComponentDocument: (doc: IndexDocumentV1) => doc is ComponentDocument;
46
+ export declare const isInstallationDocument: (doc: IndexDocumentV1) => doc is InstallationDocument;
65
47
  /**
66
48
  * @deprecated
67
49
  * While some documents may still use this format, new documents should use the
68
50
  * latest interface.
69
51
  */
70
52
  interface StoreComponentDocsInputV1 {
71
- id?: string;
72
- ownerId?: string;
73
- userId?: string;
74
- createdDate?: Date;
75
- deprecated?: boolean;
76
- description: string;
77
- name: string;
78
- relatedComponents: string[];
79
- relevantFiles: string[];
80
- content: string;
81
- sessionId: string;
82
- designSystemPackage?: string;
83
- designSystemVersion?: string;
84
- hash?: string;
85
- designSystemId?: string;
53
+ id?: string;
54
+ ownerId?: string;
55
+ userId?: string;
56
+ createdDate?: Date;
57
+ deprecated?: boolean;
58
+ description: string;
59
+ name: string;
60
+ relatedComponents: string[];
61
+ relevantFiles: string[];
62
+ content: string;
63
+ sessionId: string;
64
+ designSystemPackage?: string;
65
+ designSystemVersion?: string;
66
+ hash?: string;
67
+ designSystemId?: string;
86
68
  }
87
69
  /**
88
70
  * @deprecated
89
71
  */
90
72
  interface StoreComponentDocsInputV2 {
91
- id?: string;
92
- ownerId?: string;
93
- userId?: string;
94
- createdDate?: Date;
95
- deprecated?: boolean;
96
- description: string;
97
- name: string;
98
- relatedComponents: string[];
99
- relevantFiles: string[];
100
- content: string;
101
- sessionId: string;
102
- hash?: string;
103
- designSystemId?: string;
104
- tokens?: number;
73
+ id?: string;
74
+ ownerId?: string;
75
+ userId?: string;
76
+ createdDate?: Date;
77
+ deprecated?: boolean;
78
+ description: string;
79
+ name: string;
80
+ relatedComponents: string[];
81
+ relevantFiles: string[];
82
+ content: string;
83
+ sessionId: string;
84
+ hash?: string;
85
+ designSystemId?: string;
86
+ tokens?: number;
105
87
  }
106
88
  export type DesignSystemScope = "space" | "organization" | "global";
107
89
  export interface AddDesignSystemInput {
108
- designSystemName: string;
109
- designSystemPackage?: string;
110
- designSystemVersion?: string;
111
- status: string;
112
- spaceId: string;
113
- rootOrgId: string;
114
- scope: DesignSystemScope;
115
- gitOriginUrl: string | undefined;
116
- gitRelativePath: string | undefined;
117
- cliArgs: string[];
90
+ designSystemName: string;
91
+ designSystemPackage?: string;
92
+ designSystemVersion?: string;
93
+ status: string;
94
+ spaceId: string;
95
+ rootOrgId: string;
96
+ scope: DesignSystemScope;
97
+ gitOriginUrl: string | undefined;
98
+ gitRelativePath: string | undefined;
99
+ cliArgs: string[];
118
100
  }
119
101
  export interface UpdateDesignSystemInput {
120
- id: string;
121
- designSystemName?: string;
122
- scope?: DesignSystemScope;
123
- designSystemPackage?: string;
124
- designSystemVersion?: string;
125
- status?: "in-progress" | "completed" | "failed";
126
- source?: "auto" | "custom";
102
+ id: string;
103
+ designSystemName?: string;
104
+ scope?: DesignSystemScope;
105
+ designSystemPackage?: string;
106
+ designSystemVersion?: string;
107
+ status?: "in-progress" | "completed" | "failed";
108
+ source?: "auto" | "custom";
127
109
  }
128
110
  export interface DesignSystem {
129
- id: string;
130
- spaceId: string;
131
- rootOrgId: string;
132
- createdDate: Date;
133
- createdByUserId: string;
134
- lastUpdatedDate?: string;
135
- lastUpdatedByUserId?: string;
136
- designSystemName: string;
137
- designSystemVersion?: string;
138
- designSystemPackage?: string;
139
- status: "in-progress" | "completed" | "failed";
140
- scope: DesignSystemScope;
141
- deprecated: boolean;
142
- gitOriginUrl: string | undefined;
143
- gitRelativePath: string | undefined;
144
- cliArgs: string[];
145
- source: "custom" | "auto";
111
+ id: string;
112
+ spaceId: string;
113
+ rootOrgId: string;
114
+ createdDate: Date;
115
+ createdByUserId: string;
116
+ lastUpdatedDate?: string;
117
+ lastUpdatedByUserId?: string;
118
+ designSystemName: string;
119
+ designSystemVersion?: string;
120
+ designSystemPackage?: string;
121
+ status: "in-progress" | "completed" | "failed";
122
+ scope: DesignSystemScope;
123
+ deprecated: boolean;
124
+ gitOriginUrl: string | undefined;
125
+ gitRelativePath: string | undefined;
126
+ cliArgs: string[];
127
+ source: "custom" | "auto";
146
128
  }
147
129
  export interface DisplayDesignSystem extends DesignSystem {
148
- docCount: number;
130
+ docCount: number;
149
131
  }
150
132
  export {};
@@ -1,15 +1,15 @@
1
1
  export const isAgentDocument = (doc) => {
2
- return doc.type === "agent";
2
+ return doc.type === "agent";
3
3
  };
4
4
  export const isIconDocument = (doc) => {
5
- return doc.type === "icon";
5
+ return doc.type === "icon";
6
6
  };
7
7
  export const isTokenDocument = (doc) => {
8
- return doc.type === "token";
8
+ return doc.type === "token";
9
9
  };
10
10
  export const isComponentDocument = (doc) => {
11
- return doc.type === "component";
11
+ return doc.type === "component";
12
12
  };
13
13
  export const isInstallationDocument = (doc) => {
14
- return doc.type === "installation";
14
+ return doc.type === "installation";
15
15
  };
package/src/settings.d.ts CHANGED
@@ -1,23 +1,21 @@
1
1
  export interface AssistantSettings {
2
- assistantType?: string;
3
- viewId?: string;
4
- theme?: "dark" | "light";
5
- allowNoStyleInspiration?: boolean;
2
+ assistantType?: string;
3
+ viewId?: string;
4
+ theme?: "dark" | "light";
5
+ allowNoStyleInspiration?: boolean;
6
6
  }
7
7
  interface IframeSettings extends Partial<AssistantSettings> {
8
- local?: boolean;
9
- /**
10
- * The URL of the assistant.
11
- */
12
- baseUrl?: string;
8
+ local?: boolean;
9
+ /**
10
+ * The URL of the assistant.
11
+ */
12
+ baseUrl?: string;
13
13
  }
14
14
  export declare function getAssistantUrl(opts?: IframeSettings): string;
15
- export declare function parseAssistantUrlSettings(
16
- url: string,
17
- ): Partial<AssistantSettings>;
15
+ export declare function parseAssistantUrlSettings(url: string): Partial<AssistantSettings>;
18
16
  export interface BuilderEditorAuth {
19
- spaceId: string;
20
- userId: string;
21
- authToken: string;
17
+ spaceId: string;
18
+ userId: string;
19
+ authToken: string;
22
20
  }
23
21
  export {};
package/src/settings.js CHANGED
@@ -1,31 +1,30 @@
1
- const urlParamSettings = ["assistantType", "theme", "viewId"];
1
+ const urlParamSettings = [
2
+ "assistantType",
3
+ "theme",
4
+ "viewId",
5
+ ];
2
6
  export function getAssistantUrl(opts = {}) {
3
- var _a;
4
- const url = new URL(
5
- (_a = opts.baseUrl) !== null && _a !== void 0
6
- ? _a
7
- : opts.local
8
- ? "http://localhost:7242"
9
- : "https://assistant.builder.io",
10
- );
11
- urlParamSettings.forEach((key) => {
12
- const value = opts[key];
13
- if (typeof value === "string" || typeof value === "boolean") {
14
- url.searchParams.set(key, String(value));
15
- }
16
- });
17
- return url.href;
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;
18
16
  }
19
17
  export function parseAssistantUrlSettings(url) {
20
- const parsed = new URL(url);
21
- const settings = {};
22
- urlParamSettings.forEach((key) => {
23
- const value = parsed.searchParams.get(key);
24
- if (value === "true" || value === "false") {
25
- settings[key] = value === "true";
26
- } else if (value) {
27
- settings[key] = value;
28
- }
29
- });
30
- return settings;
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;
31
30
  }
@@ -19,10 +19,7 @@ export declare const DEFAULT_WORKSPACE_PATH = "/root/app/code";
19
19
  * generateVSCodeDeepLink("my-project-main")
20
20
  * // Returns: "vscode://vscode-remote/tunnel+my-project-main/root/app/code"
21
21
  */
22
- export declare function generateVSCodeDeepLink(
23
- tunnelName: string,
24
- workspacePath?: string,
25
- ): string;
22
+ export declare function generateVSCodeDeepLink(tunnelName: string, workspacePath?: string): string;
26
23
  /**
27
24
  * Generate a Cursor deep link for a tunnel
28
25
  *
@@ -34,10 +31,7 @@ export declare function generateVSCodeDeepLink(
34
31
  * generateCursorDeepLink("my-project-main")
35
32
  * // Returns: "cursor://cursor-remote/tunnel+my-project-main/root/app/code"
36
33
  */
37
- export declare function generateCursorDeepLink(
38
- tunnelName: string,
39
- workspacePath?: string,
40
- ): string;
34
+ export declare function generateCursorDeepLink(tunnelName: string, workspacePath?: string): string;
41
35
  /**
42
36
  * Generate a web editor (vscode.dev) link for a tunnel
43
37
  *
@@ -49,10 +43,7 @@ export declare function generateCursorDeepLink(
49
43
  * generateWebEditorLink("my-project-main")
50
44
  * // Returns: "https://vscode.dev/tunnel/my-project-main/root/app/code"
51
45
  */
52
- export declare function generateWebEditorLink(
53
- tunnelName: string,
54
- workspacePath?: string,
55
- ): string;
46
+ export declare function generateWebEditorLink(tunnelName: string, workspacePath?: string): string;
56
47
  /**
57
48
  * Generate all deep links for a tunnel
58
49
  *
@@ -68,13 +59,10 @@ export declare function generateWebEditorLink(
68
59
  * // web: "https://vscode.dev/tunnel/my-project-main/root/app/code"
69
60
  * // }
70
61
  */
71
- export declare function generateAllEditorLinks(
72
- tunnelName: string,
73
- workspacePath?: string,
74
- ): {
75
- vscode: string;
76
- cursor: string;
77
- web: string;
62
+ export declare function generateAllEditorLinks(tunnelName: string, workspacePath?: string): {
63
+ vscode: string;
64
+ cursor: string;
65
+ web: string;
78
66
  };
79
67
  /**
80
68
  * Generate a sanitized tunnel name from project and branch identifiers
@@ -87,10 +75,7 @@ export declare function generateAllEditorLinks(
87
75
  * generateTunnelName("abc123", "feature/my-branch")
88
76
  * // Returns: "abc123-feature-my-branch"
89
77
  */
90
- export declare function generateTunnelName(
91
- projectId: string,
92
- branchName: string,
93
- ): string;
78
+ export declare function generateTunnelName(projectId: string, branchName: string): string;
94
79
  /**
95
80
  * Parse a tunnel URL to extract the tunnel name
96
81
  *
@@ -19,11 +19,8 @@ export const DEFAULT_WORKSPACE_PATH = "/root/app/code";
19
19
  * generateVSCodeDeepLink("my-project-main")
20
20
  * // Returns: "vscode://vscode-remote/tunnel+my-project-main/root/app/code"
21
21
  */
22
- export function generateVSCodeDeepLink(
23
- tunnelName,
24
- workspacePath = DEFAULT_WORKSPACE_PATH,
25
- ) {
26
- return `vscode://vscode-remote/tunnel+${tunnelName}${workspacePath}`;
22
+ export function generateVSCodeDeepLink(tunnelName, workspacePath = DEFAULT_WORKSPACE_PATH) {
23
+ return `vscode://vscode-remote/tunnel+${tunnelName}${workspacePath}`;
27
24
  }
28
25
  /**
29
26
  * Generate a Cursor deep link for a tunnel
@@ -36,11 +33,8 @@ export function generateVSCodeDeepLink(
36
33
  * generateCursorDeepLink("my-project-main")
37
34
  * // Returns: "cursor://cursor-remote/tunnel+my-project-main/root/app/code"
38
35
  */
39
- export function generateCursorDeepLink(
40
- tunnelName,
41
- workspacePath = DEFAULT_WORKSPACE_PATH,
42
- ) {
43
- return `cursor://cursor-remote/tunnel+${tunnelName}${workspacePath}`;
36
+ export function generateCursorDeepLink(tunnelName, workspacePath = DEFAULT_WORKSPACE_PATH) {
37
+ return `cursor://cursor-remote/tunnel+${tunnelName}${workspacePath}`;
44
38
  }
45
39
  /**
46
40
  * Generate a web editor (vscode.dev) link for a tunnel
@@ -53,11 +47,8 @@ export function generateCursorDeepLink(
53
47
  * generateWebEditorLink("my-project-main")
54
48
  * // Returns: "https://vscode.dev/tunnel/my-project-main/root/app/code"
55
49
  */
56
- export function generateWebEditorLink(
57
- tunnelName,
58
- workspacePath = DEFAULT_WORKSPACE_PATH,
59
- ) {
60
- return `https://vscode.dev/tunnel/${tunnelName}${workspacePath}`;
50
+ export function generateWebEditorLink(tunnelName, workspacePath = DEFAULT_WORKSPACE_PATH) {
51
+ return `https://vscode.dev/tunnel/${tunnelName}${workspacePath}`;
61
52
  }
62
53
  /**
63
54
  * Generate all deep links for a tunnel
@@ -74,15 +65,12 @@ export function generateWebEditorLink(
74
65
  * // web: "https://vscode.dev/tunnel/my-project-main/root/app/code"
75
66
  * // }
76
67
  */
77
- export function generateAllEditorLinks(
78
- tunnelName,
79
- workspacePath = DEFAULT_WORKSPACE_PATH,
80
- ) {
81
- return {
82
- vscode: generateVSCodeDeepLink(tunnelName, workspacePath),
83
- cursor: generateCursorDeepLink(tunnelName, workspacePath),
84
- web: generateWebEditorLink(tunnelName, workspacePath),
85
- };
68
+ export function generateAllEditorLinks(tunnelName, workspacePath = DEFAULT_WORKSPACE_PATH) {
69
+ return {
70
+ vscode: generateVSCodeDeepLink(tunnelName, workspacePath),
71
+ cursor: generateCursorDeepLink(tunnelName, workspacePath),
72
+ web: generateWebEditorLink(tunnelName, workspacePath),
73
+ };
86
74
  }
87
75
  /**
88
76
  * Generate a sanitized tunnel name from project and branch identifiers
@@ -96,14 +84,14 @@ export function generateAllEditorLinks(
96
84
  * // Returns: "abc123-feature-my-branch"
97
85
  */
98
86
  export function generateTunnelName(projectId, branchName) {
99
- const combined = `${projectId}-${branchName}`;
100
- const sanitized = combined
101
- .toLowerCase()
102
- .replace(/[^a-z0-9-]/g, "-")
103
- .replace(/-+/g, "-")
104
- .replace(/^-|-$/g, "")
105
- .substring(0, 63);
106
- return sanitized || "builder-tunnel";
87
+ const combined = `${projectId}-${branchName}`;
88
+ const sanitized = combined
89
+ .toLowerCase()
90
+ .replace(/[^a-z0-9-]/g, "-")
91
+ .replace(/-+/g, "-")
92
+ .replace(/^-|-$/g, "")
93
+ .substring(0, 63);
94
+ return sanitized || "builder-tunnel";
107
95
  }
108
96
  /**
109
97
  * Parse a tunnel URL to extract the tunnel name
@@ -116,8 +104,6 @@ export function generateTunnelName(projectId, branchName) {
116
104
  * // Returns: "my-project-main"
117
105
  */
118
106
  export function parseTunnelUrl(tunnelUrl) {
119
- const match = tunnelUrl.match(
120
- /(?:vscode\.dev\/tunnel\/|tunnel\+)([a-zA-Z0-9_-]+)/,
121
- );
122
- return match ? match[1] : null;
107
+ const match = tunnelUrl.match(/(?:vscode\.dev\/tunnel\/|tunnel\+)([a-zA-Z0-9_-]+)/);
108
+ return match ? match[1] : null;
123
109
  }