@builder.io/ai-utils 0.0.34 → 0.0.36

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, SnippetParams } from "./messages";
2
+ import type { Message, 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 };
@@ -30,7 +30,7 @@ export interface CompletionOptions {
30
30
  * The messages are ordered from oldest to newest. The last message in the array
31
31
  * is the message that the user has just sent.
32
32
  */
33
- messages: MessageParam[];
33
+ messages: (MessageParam | Message)[];
34
34
  /**
35
35
  * Which platform (framework) the the user has choosen to get help with.
36
36
  */
package/dist/events.d.ts CHANGED
@@ -3,7 +3,7 @@ import type { Thread } from "./thread";
3
3
  import type { AssistantMessage } from "./messages";
4
4
  import { AssistantSettings } from "./settings";
5
5
  export type BuilderAssistantEventHandler = (ev: BuilderAssistantEvent) => void;
6
- export type BuilderAssistantEvent = AssistantErrorEvent | AppCloseEvent | AppMessagesClickEvent | AppMessagesGenerationEvent | AppPromptAbortEvent | AppPromptFocusEvent | AppPromptTextEvent | AppReadyEvent | AppSettingsResetEvent | AppSettingsSetEvent | AppThreadNewEvent | BuilderEditorStateEvent | ContentUpdateEvent | ContentApplySnapshotEvent | ContentCompleteEvent | ModelCreateEvent | ModelUpdateEvent | ModelUndoEvent | ResultEvent | ThreadCreatedEvent | ThreadMessageDeltaEvent | ThreadMessageCompletedEvent | ThreadMessageFeedbackEvent | ThreadRunRequiresActionEvent | ThreadRunStepCreatedEvent | ThreadRunStepDeltaEvent;
6
+ export type BuilderAssistantEvent = AssistantErrorEvent | AppCloseEvent | AppMessagesClickEvent | AppMessagesGenerationEvent | AppPromptAbortEvent | AppPromptFocusEvent | AppPromptTextEvent | AppReadyEvent | AppSettingsResetEvent | AppSettingsSetEvent | AppThreadNewEvent | AssistantStatsEvent | BuilderEditorStateEvent | ContentUpdateEvent | ContentApplySnapshotEvent | ModelCreateEvent | ModelUpdateEvent | ModelUndoEvent | ResultEvent | ThreadCreatedEvent | ThreadMessageDeltaEvent | ThreadMessageCompletedEvent | ThreadMessageFeedbackEvent | ThreadRunRequiresActionEvent | ThreadRunStepCreatedEvent | ThreadRunStepDeltaEvent;
7
7
  export interface AssistantError {
8
8
  message: string;
9
9
  status?: number;
@@ -97,7 +97,7 @@ export interface ContentUpdateEvent {
97
97
  type: "assistant.content.update";
98
98
  data: ContentUpdatePatch[];
99
99
  }
100
- export type ContentUpdatePatch = ContentInsertBeforePatch | ContentInsertAfterPatch | ContentPropsUpdatePatch | ContentSetChildrenPatch | ContentStyleUpdatePatch | ContentDeletePatch | ContentSetStorePatch | ContentSetMountPatch;
100
+ export type ContentUpdatePatch = ContentInsertBeforePatch | ContentInsertAfterPatch | ContentPropsUpdatePatch | ContentSetChildrenPatch | ContentStyleUpdatePatch | ContentDeletePatch | ContentSetStorePatch | ContentSetMountPatch | ContentMovePatch | ContentMoveAfterPatch | ContentMoveBeforePatch;
101
101
  export interface NodeData {
102
102
  /**
103
103
  * When dealing with column nodes we need to store the column index so
@@ -144,16 +144,78 @@ export interface ContentSetStorePatch extends ContentPatchBase {
144
144
  export interface ContentSetMountPatch extends ContentPatchBase {
145
145
  type: "mount";
146
146
  }
147
- export interface ContentCompleteEvent {
148
- type: "assistant.content.complete";
149
- data: ContentComplete;
147
+ export interface ContentMovePatch extends ContentPatchBase {
148
+ type: "move";
150
149
  }
151
- export interface ContentComplete {
150
+ export interface ContentMoveAfterPatch extends ContentPatchBase {
151
+ type: "move_after";
152
+ }
153
+ export interface ContentMoveBeforePatch extends ContentPatchBase {
154
+ type: "move_before";
155
+ }
156
+ export interface AssistantStatsEvent {
157
+ type: "assistant.stats";
158
+ data: AssistantStats;
159
+ }
160
+ export interface AssistantStats {
161
+ /**
162
+ * The unique id of the thread (not the openai threadId)
163
+ */
152
164
  threadId: string;
165
+ /**
166
+ * The unique id of the completion, which is a combination of the user's prompt and assistant's response.
167
+ */
153
168
  completionId: string;
169
+ /**
170
+ * The model id used to generate this completion.
171
+ */
154
172
  modelId: string;
155
- message: AssistantMessage;
156
- ts: number;
173
+ /**
174
+ * The assistant's response message.
175
+ */
176
+ assistantMessage: string;
177
+ /**
178
+ * The user's prompt message.
179
+ */
180
+ userMessage: string;
181
+ /**
182
+ * The index within the thread the assistant message is.
183
+ * For a first assistant message, the index will be 1 (the user message is index 0).
184
+ * For a second assistant message, the index will be 3 (the user message is index 2), and so on.
185
+ */
186
+ assistantMessageIndex: number;
187
+ /**
188
+ * The timestamp (Date.now()) of when the user first submitted their prompt.
189
+ */
190
+ userPromptMs: number;
191
+ /**
192
+ * The timestamp of the first assistant chunk in the response.
193
+ */
194
+ firstChunkMs: number;
195
+ /**
196
+ * The timestamp of the last assistant chunk in the response.
197
+ */
198
+ lastChunkMs: number;
199
+ /**
200
+ * The total number of chunks in the assistant's streamed response.
201
+ */
202
+ chunkCount: number;
203
+ /**
204
+ * The total number of characters in the generated prompt sent to the LLM.
205
+ */
206
+ promptLength: number;
207
+ /**
208
+ * The total number of characters in the assistant's response.
209
+ */
210
+ completionLength: number;
211
+ /**
212
+ * If the user provided custom instructions for the prompt.
213
+ */
214
+ hasCustomInstructions: boolean;
215
+ /**
216
+ * Error message if there was one.
217
+ */
218
+ errorMessage?: string;
157
219
  }
158
220
  export interface ModelCreateEvent {
159
221
  type: "assistant.model.create";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@builder.io/ai-utils",
3
- "version": "0.0.34",
3
+ "version": "0.0.36",
4
4
  "description": "Builder.io AI utils",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",