@builder.io/ai-utils 0.0.14 → 0.0.16

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.
@@ -1,5 +1,5 @@
1
1
  import type { BuilderContent, BuilderElement, Component } from "@builder.io/sdk";
2
- import type { MessageParam } from "./messages";
2
+ import type { MessageParam, SnippetParams } from "./messages";
3
3
  import type { BuilderModel } from "./events";
4
4
  export type BuilderContentData = BuilderContent["data"];
5
5
  export type { BuilderContent, BuilderElement, Component };
@@ -70,3 +70,8 @@ export interface CompletionOptions {
70
70
  */
71
71
  debug?: boolean;
72
72
  }
73
+ export type OnPromptSubmit = (opts: {
74
+ prompt?: string;
75
+ snippetId?: string;
76
+ snippetParams?: SnippetParams;
77
+ }) => void;
package/dist/events.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import type { BuilderContent, BuilderElement, Component } from "@builder.io/sdk";
2
2
  import type { Thread } from "./thread";
3
3
  import type { AssistantMessage } from "./messages";
4
+ import { AssistantSettings } from "./settings";
4
5
  export type BuilderAssistantEventHandler = (ev: BuilderAssistantEvent) => void;
5
6
  export type BuilderAssistantEvent = AppCloseEvent | AppMessagesClickEvent | AppMessagesGenerationEvent | AppPromptAbortEvent | AppPromptFocusEvent | AppPromptTextEvent | AppReadyEvent | AppSettingsResetEvent | AppSettingsSetEvent | AppThreadNewEvent | BuiderEditorStateEvent | ContentCreateEvent | ContentUpdateEvent | ContentApplySnapshotEvent | ContentCompleteEvent | ModelCreateEvent | ModelUpdateEvent | ResultEvent | ThreadCreatedEvent | ThreadMessageDeltaEvent | ThreadMessageCompletedEvent | ThreadMessageFeedbackEvent | ThreadRunRequiresActionEvent | ThreadRunStepCreatedEvent | ThreadRunStepDeltaEvent;
6
7
  export interface AppCloseEvent {
@@ -39,9 +40,9 @@ export interface AppReadyEvent {
39
40
  export interface AppSettingsResetEvent {
40
41
  type: "assistant.app.settings.reset";
41
42
  }
42
- export interface AppSettingsSetEvent<T = any> {
43
+ export interface AppSettingsSetEvent {
43
44
  type: "assistant.app.settings.set";
44
- data: DeepPartial<T>;
45
+ data: Partial<AssistantSettings>;
45
46
  }
46
47
  export interface AppThreadNewEvent {
47
48
  type: "assistant.app.thread.new";
@@ -1,25 +1,51 @@
1
1
  import type { SnippetParams } from "./messages";
2
2
  export interface AssistantSettings {
3
3
  assistantType?: string;
4
- requestState?: boolean;
4
+ cssOverrides?: string;
5
+ headingText: string;
5
6
  hideFrameworkPicker?: boolean;
6
- messagePlaceholder: string;
7
7
  hideHeader?: boolean;
8
- headingText: string;
9
- cssOverrides?: string;
8
+ messagePlaceholder: string;
9
+ requestState?: boolean;
10
+ showAiCanMakeMistakes?: boolean;
10
11
  showCloseButton?: boolean;
12
+ showHeaderButton?: boolean;
13
+ showPrompt?: boolean;
11
14
  showSparklesInInputBar?: boolean;
12
- suggestedItems: {
13
- text: string;
14
- prompt: string;
15
- icon: any;
16
- iconColor?: string;
17
- snippetId?: string;
18
- snippetParams?: SnippetParams;
19
- }[];
20
- }
21
- export declare function getAssistantUrl(opts?: {
15
+ suggestedItems: Snippet[];
22
16
  theme?: "dark" | "light";
23
- assistantType?: string;
17
+ transparentBackground?: boolean;
18
+ }
19
+ export interface Snippet {
20
+ /**
21
+ * The text that will be displayed in the chat snippet button.
22
+ */
23
+ text: string;
24
+ /**
25
+ * The icon that will be displayed in the chat snippet button.
26
+ */
27
+ icon?: string;
28
+ /**
29
+ * The color of the icon that will be displayed in the chat snippet button.
30
+ */
31
+ iconColor?: string;
32
+ /**
33
+ * The prompt text that will be sent to the assistant when the user clicks the chat snippet button.
34
+ * This prompt is also what's added to the chat conversation from the user.
35
+ */
36
+ prompt?: string;
37
+ /**
38
+ * The ID of the snippet that will be sent to the assistant when the user clicks the chat snippet button.
39
+ */
40
+ snippetId?: string;
41
+ /**
42
+ * The parameters that will be sent to the assistant when the user clicks the chat snippet button.
43
+ */
44
+ snippetParams?: SnippetParams;
45
+ }
46
+ interface IframeSettings extends Partial<AssistantSettings> {
24
47
  local?: boolean;
25
- }): string;
48
+ }
49
+ export declare function getAssistantUrl(opts?: IframeSettings): string;
50
+ export declare function parseAssistantUrlSettings(url: string): Partial<AssistantSettings>;
51
+ export {};
package/dist/settings.js CHANGED
@@ -1,12 +1,39 @@
1
+ const urlParamSettings = [
2
+ "assistantType",
3
+ "hideFrameworkPicker",
4
+ "hideHeader",
5
+ "showAiCanMakeMistakes",
6
+ "showCloseButton",
7
+ "showHeaderButton",
8
+ "showPrompt",
9
+ "showSparklesInInputBar",
10
+ "requestState",
11
+ "theme",
12
+ "transparentBackground",
13
+ ];
1
14
  export function getAssistantUrl(opts = {}) {
2
15
  const url = new URL(opts.local
3
16
  ? "http://localhost:7242"
4
17
  : "https://ai-assistant-tk43uighdq-uc.a.run.app");
5
- if (opts.assistantType) {
6
- url.searchParams.set("assistantType", opts.assistantType);
7
- }
8
- if (opts.theme) {
9
- url.searchParams.set("theme", opts.theme);
10
- }
18
+ urlParamSettings.forEach((key) => {
19
+ const value = opts[key];
20
+ if (typeof value === "string" || typeof value === "boolean") {
21
+ url.searchParams.set(key, String(value));
22
+ }
23
+ });
11
24
  return url.href;
12
25
  }
26
+ export function parseAssistantUrlSettings(url) {
27
+ const parsed = new URL(url);
28
+ const settings = {};
29
+ urlParamSettings.forEach((key) => {
30
+ const value = parsed.searchParams.get(key);
31
+ if (value === "true" || value === "false") {
32
+ settings[key] = value === "true";
33
+ }
34
+ else if (value) {
35
+ settings[key] = value;
36
+ }
37
+ });
38
+ return settings;
39
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@builder.io/ai-utils",
3
- "version": "0.0.14",
3
+ "version": "0.0.16",
4
4
  "description": "Builder.io AI utils",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",