@dremio/js-sdk 0.44.0 → 0.45.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/dist/cloud/ai/AIResource.d.ts +3 -0
- package/dist/enterprise/ai/AIResource.d.ts +3 -0
- package/dist/enterprise/ai/conversations/createConversationMachine.d.ts +7 -0
- package/dist/enterprise/ai/conversations/createConversationMachine.js +23 -7
- package/dist/enterprise/ai/conversations/createConversationMachine.js.map +1 -1
- package/dist-iife/cloud.js +23 -7
- package/dist-iife/enterprise.js +23 -7
- package/package.json +1 -1
|
@@ -780,6 +780,9 @@ export declare class AIResource {
|
|
|
780
780
|
}, never, never, never, "uninitialized" | "creating_conversation" | "retrieving_history" | "idle" | "submitting_message" | "retrieve_history_failed" | "submitting_message_failed" | {
|
|
781
781
|
streaming: "monitoring_replies" | "stopping";
|
|
782
782
|
}, string, import("../../enterprise/ai/conversations/createConversationMachine.ts").ConversationMachineInput, import("xstate").NonReducibleUnknown, {
|
|
783
|
+
type: "apiError";
|
|
784
|
+
error: HttpError;
|
|
785
|
+
} | {
|
|
783
786
|
type: "chatEventReceived";
|
|
784
787
|
chatEvent: ChatEvent;
|
|
785
788
|
} | {
|
|
@@ -722,6 +722,9 @@ export declare class AIResource {
|
|
|
722
722
|
}, never, never, never, "uninitialized" | "creating_conversation" | "retrieving_history" | "idle" | "submitting_message" | "retrieve_history_failed" | "submitting_message_failed" | {
|
|
723
723
|
streaming: "monitoring_replies" | "stopping";
|
|
724
724
|
}, string, import("./conversations/createConversationMachine.ts").ConversationMachineInput, import("xstate").NonReducibleUnknown, {
|
|
725
|
+
type: "apiError";
|
|
726
|
+
error: HttpError;
|
|
727
|
+
} | {
|
|
725
728
|
type: "chatEventReceived";
|
|
726
729
|
chatEvent: ChatEvent;
|
|
727
730
|
} | {
|
|
@@ -3,6 +3,7 @@ import { AgentConversation } from "./AgentConversation.ts";
|
|
|
3
3
|
import type { ConversationExchange } from "./reduceChatEvents.ts";
|
|
4
4
|
import type { SonarV4Config } from "../../../common/Config.ts";
|
|
5
5
|
import { type ChatEvent } from "../chat/chatEventSchema.ts";
|
|
6
|
+
import type { HttpError } from "../../../common/HttpError.ts";
|
|
6
7
|
export type ConversationMachineInput = {
|
|
7
8
|
conversationId: string | null;
|
|
8
9
|
};
|
|
@@ -24,6 +25,9 @@ export type ConversationMachineEvents = {
|
|
|
24
25
|
type: "REFRESH_HISTORY";
|
|
25
26
|
};
|
|
26
27
|
export type ConversationMachineEmitted = {
|
|
28
|
+
type: "apiError";
|
|
29
|
+
error: HttpError;
|
|
30
|
+
} | {
|
|
27
31
|
type: "chatEventReceived";
|
|
28
32
|
chatEvent: ChatEvent;
|
|
29
33
|
} | {
|
|
@@ -736,6 +740,9 @@ export declare const createConversationMachine: (config: SonarV4Config) => impor
|
|
|
736
740
|
}, never, never, never, "uninitialized" | "creating_conversation" | "retrieving_history" | "idle" | "submitting_message" | "retrieve_history_failed" | "submitting_message_failed" | {
|
|
737
741
|
streaming: "monitoring_replies" | "stopping";
|
|
738
742
|
}, string, ConversationMachineInput, import("xstate").NonReducibleUnknown, {
|
|
743
|
+
type: "apiError";
|
|
744
|
+
error: HttpError;
|
|
745
|
+
} | {
|
|
739
746
|
type: "chatEventReceived";
|
|
740
747
|
chatEvent: ChatEvent;
|
|
741
748
|
} | {
|
|
@@ -141,6 +141,10 @@ export const createConversationMachine = (config) => setup({
|
|
|
141
141
|
},
|
|
142
142
|
],
|
|
143
143
|
onError: {
|
|
144
|
+
actions: emit(({ event }) => ({
|
|
145
|
+
error: event.error,
|
|
146
|
+
type: "apiError",
|
|
147
|
+
})),
|
|
144
148
|
target: "uninitialized",
|
|
145
149
|
},
|
|
146
150
|
src: "createConversation",
|
|
@@ -200,9 +204,15 @@ export const createConversationMachine = (config) => setup({
|
|
|
200
204
|
target: "uninitialized",
|
|
201
205
|
},
|
|
202
206
|
{
|
|
203
|
-
actions:
|
|
204
|
-
|
|
205
|
-
|
|
207
|
+
actions: [
|
|
208
|
+
assign({
|
|
209
|
+
lastError: ({ event }) => event.error,
|
|
210
|
+
}),
|
|
211
|
+
emit(({ event }) => ({
|
|
212
|
+
error: event.error,
|
|
213
|
+
type: "apiError",
|
|
214
|
+
})),
|
|
215
|
+
],
|
|
206
216
|
target: "retrieve_history_failed",
|
|
207
217
|
},
|
|
208
218
|
],
|
|
@@ -315,10 +325,16 @@ export const createConversationMachine = (config) => setup({
|
|
|
315
325
|
target: "streaming",
|
|
316
326
|
},
|
|
317
327
|
onError: {
|
|
318
|
-
actions:
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
328
|
+
actions: [
|
|
329
|
+
assign({
|
|
330
|
+
currentRunId: () => null,
|
|
331
|
+
lastError: ({ event }) => event.error,
|
|
332
|
+
}),
|
|
333
|
+
emit(({ event }) => ({
|
|
334
|
+
error: event.error,
|
|
335
|
+
type: "apiError",
|
|
336
|
+
})),
|
|
337
|
+
],
|
|
322
338
|
target: "submitting_message_failed",
|
|
323
339
|
},
|
|
324
340
|
src: "startRun",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createConversationMachine.js","sourceRoot":"","sources":["../../../../src/enterprise/ai/conversations/createConversationMachine.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,EAAE,cAAc,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAE1F,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAG3D,OAAO,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,MAAM,iCAAiC,CAAC;AAC9F,OAAO,KAAK,CAAC,MAAM,UAAU,CAAC;AAC9B,OAAO,EAAE,oBAAoB,EAAE,MAAM,mCAAmC,CAAC;AACzE,OAAO,EAAE,2BAA2B,EAAE,MAAM,0CAA0C,CAAC;AACvF,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAA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D,aAAa,EAAE;YACb,MAAM,EAAE;gBACN,KAAK,EAAE,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,cAAc;gBAChD,MAAM,EAAE,oBAAoB;aAC7B;YACD,WAAW,EACT,gFAAgF;YAClF,EAAE,EAAE;gBACF,mBAAmB,EAAE;oBACnB,OAAO,EAAE,MAAM,CAAC;wBACd,cAAc,EAAE,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,KAAK,CAAC,OAAO;qBAC7C,CAAC;oBACF,MAAM,EAAE,uBAAuB;iBAChC;aACF;SACF;KACF;CACF,CAAC,CAAC","sourcesContent":["/*\n * Copyright (C) 2024-2025 Dremio Corporation\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { setup, fromObservable, fromPromise, assign, enqueueActions, emit } from \"xstate\";\nimport type { UserChatMessage } from \"../chat/UserChatMessage.ts\";\nimport { AgentConversation } from \"./AgentConversation.ts\";\nimport type { ConversationExchange } from \"./reduceChatEvents.ts\";\nimport type { SonarV4Config } from \"../../../common/Config.ts\";\nimport { createConversation, createConversationCodec } from \"./methods/createConversation.ts\";\nimport * as z from \"zod/mini\";\nimport { retrieveConversation } from \"./methods/retrieveConversation.ts\";\nimport { retrieveConversationHistory } from \"./methods/retrieveConversationHistory.ts\";\nimport { createExchangeRun } from \"./methods/createExchangeRun.ts\";\nimport { stopExchangeRun } from \"./methods/stopExchangeRun.ts\";\nimport { streamRunEvents } from \"./methods/streamRunEvents.ts\";\nimport { fromTextEventStream } from \"../../../common/fromTextEventStream.ts\";\nimport { map } from \"rxjs\";\nimport { chatEventCodec, type ChatEvent } from \"../chat/chatEventSchema.ts\";\n\nexport type ConversationMachineInput = {\n conversationId: string | null;\n};\n\nexport type ConversationMachineContext = {\n conversationId: string | null;\n conversationSnapshot?: ConversationExchange[];\n currentRunId?: string | null;\n lastError?: unknown;\n messageAttempt?: UserChatMessage;\n};\nexport type ConversationMachineEvents =\n | { type: \"STOP_RUN\" }\n | { type: \"SUBMIT_USER_MESSAGE\"; message: UserChatMessage }\n | { type: \"RETRY_MESSAGE\" }\n | { type: \"REFRESH_HISTORY\" };\n\nexport type ConversationMachineEmitted =\n | {\n type: \"chatEventReceived\";\n chatEvent: ChatEvent;\n }\n | {\n type: \"conversationCreated\";\n id: string;\n };\n\nexport const createConversationMachine = (config: SonarV4Config) =>\n setup({\n actors: {\n createConversation: fromPromise(\n ({ input }: { input: z.input<typeof createConversationCodec> }) =>\n createConversation(config)(input).then((result) => {\n if (result.isErr()) {\n throw result.error;\n }\n return result.value;\n }),\n ),\n retrieveConversation: fromPromise(\n ({ input, signal }: { input: { conversationId: string }; signal: AbortSignal }) =>\n retrieveConversation(config)(input.conversationId, { signal }).then((result) => {\n if (result.isErr()) {\n throw result.error;\n }\n return result.value;\n }),\n ),\n retrieveHistory: fromPromise(\n ({ input, signal }: { input: { conversationId: string }; signal: AbortSignal }) =>\n retrieveConversationHistory(config)(input.conversationId, { signal }).then((result) => {\n if (result.isErr()) {\n throw result.error;\n }\n return result.value;\n }),\n ),\n retrieveState: fromPromise(\n async ({ input, signal }: { input: { conversationId: string }; signal: AbortSignal }) => {\n const [conversation, history] = await Promise.all([\n retrieveConversation(config)(input.conversationId, { signal }).then((result) => {\n if (result.isErr()) {\n throw result.error;\n }\n return result.value;\n }),\n retrieveConversationHistory(config)(input.conversationId, { signal }).then((result) => {\n if (result.isErr()) {\n throw result.error;\n }\n return result.value;\n }),\n ]);\n return {\n conversation,\n history,\n };\n },\n ),\n startRun: fromPromise(\n ({ input }: { input: { conversationId: string; message: UserChatMessage } }) =>\n createExchangeRun(config)(input.conversationId, { message: input.message }).then(\n (result) => {\n if (result.isErr()) {\n throw result.error;\n }\n return result.value;\n },\n ),\n ),\n stopRun: fromPromise(({ input }: { input: { conversationId: string; runId: string } }) =>\n stopExchangeRun(config)(input.conversationId, input.runId).then((result) => {\n if (result.isErr()) {\n throw result.error;\n }\n return result.value;\n }),\n ),\n streamRun: fromObservable(({ input }: { input: { conversationId: string; runId: string } }) =>\n fromTextEventStream(({ signal }) =>\n streamRunEvents(config)(\n { conversationId: input.conversationId, runId: input.runId },\n { signal },\n ),\n ).pipe(\n map((event) =>\n z.decode(chatEventCodec, JSON.parse(event.data) as z.input<typeof chatEventCodec>),\n ),\n ),\n ),\n },\n types: {\n context: {} as ConversationMachineContext,\n emitted: {} as ConversationMachineEmitted,\n events: {} as ConversationMachineEvents,\n input: {} as ConversationMachineInput,\n },\n }).createMachine({\n context: ({ input }) => ({\n conversationId: input.conversationId,\n conversationSnapshot: undefined,\n currentRunId: undefined,\n messageAttempt: undefined,\n }),\n id: \"agentConversation\",\n initial: \"uninitialized\",\n states: {\n creating_conversation: {\n description: \"Creating a new conversation object\",\n invoke: {\n input: ({ context }) => ({\n message: context.messageAttempt!,\n }),\n onDone: [\n {\n actions: [\n assign({\n conversationId: ({ event }) => event.output.id,\n // Add the message attempt into the snapshot manually\n conversationSnapshot: ({ context, event }) => [\n ...(context.conversationSnapshot ?? []),\n {\n id: event.output.currentRunId!,\n messages: new Map(),\n submittedUserMessage: context.messageAttempt,\n toolCalls: new Map(),\n } satisfies ConversationExchange,\n ],\n currentRunId: ({ event }) => event.output.currentRunId,\n messageAttempt: undefined,\n }),\n emit(({ event }) => ({\n id: event.output.id,\n type: \"conversationCreated\",\n })),\n ],\n // Don't transition to streaming in a situation where we didn't receive a currentRunId\n guard: ({ event }) => !!event.output.currentRunId,\n target: \"streaming\",\n },\n /**\n * Fall back to the retrieving_history state if we didn't receive a currentRunId\n */\n {\n actions: assign({\n conversationId: ({ event }) => event.output.id,\n currentRunId: ({ event }) => event.output.currentRunId,\n messageAttempt: undefined,\n }),\n target: \"retrieving_history\",\n },\n ],\n onError: {\n target: \"uninitialized\",\n },\n src: \"createConversation\",\n },\n },\n idle: {\n description: \"Waiting for user input to start the next reply stream\",\n on: {\n REFRESH_HISTORY: {\n target: \"retrieving_history\",\n },\n SUBMIT_USER_MESSAGE: {\n actions: assign({\n messageAttempt: ({ event }) => event.message,\n }),\n target: \"submitting_message\",\n },\n },\n },\n retrieve_history_failed: {\n on: {\n REFRESH_HISTORY: {\n actions: assign({ lastError: undefined }),\n target: \"retrieving_history\",\n },\n },\n },\n retrieving_history: {\n description: \"Retrieving latest copy of conversation history\",\n invoke: {\n input: ({ context }) => ({ conversationId: context.conversationId! }),\n onDone: [\n {\n actions: assign({\n conversationSnapshot: ({ context, event }) =>\n AgentConversation.reduceChatEvents(\n context.conversationSnapshot,\n event.output.history.data,\n ),\n currentRunId: ({ event }) => event.output.conversation.currentRunId,\n }),\n guard: ({ event }) => !!event.output.conversation.currentRunId,\n target: \"streaming\",\n },\n {\n actions: assign({\n conversationSnapshot: ({ context, event }) =>\n AgentConversation.reduceChatEvents(\n context.conversationSnapshot,\n event.output.history.data,\n ),\n currentRunId: ({ event }) => event.output.conversation.currentRunId,\n }),\n target: \"idle\",\n },\n ],\n onError: [\n {\n guard: ({ event }) => {\n const e = event.error as Error & { code?: string };\n return (\n e?.name === \"AbortError\" ||\n e?.message?.includes(\"aborted\") ||\n e?.code === \"ABORT_ERR\"\n );\n },\n target: \"uninitialized\",\n },\n {\n actions: assign({\n lastError: ({ event }) => event.error,\n }),\n target: \"retrieve_history_failed\",\n },\n ],\n src: \"retrieveState\",\n },\n },\n streaming: {\n description: \"Manages monitoring and canceling the current run\",\n initial: \"monitoring_replies\",\n invoke: {\n input: ({ context }) => {\n if (!context.currentRunId) {\n throw new Error(\"Attempted to stream without a runId\");\n }\n return {\n conversationId: context.conversationId!,\n runId: context.currentRunId,\n };\n },\n onDone: {\n actions: assign({ currentRunId: null }),\n target: \"idle\",\n },\n onError: {\n actions: assign({ currentRunId: null }),\n target: \"idle\",\n },\n onSnapshot: {\n actions: enqueueActions(({ context, enqueue, event }) => {\n const chatEvent = event.snapshot.context;\n if (!chatEvent) {\n return;\n }\n\n const nextSnapshot = AgentConversation.reduceChatEvents(\n context.conversationSnapshot,\n [chatEvent],\n );\n\n enqueue.assign({\n conversationSnapshot: nextSnapshot,\n });\n enqueue.emit({\n chatEvent,\n type: \"chatEventReceived\",\n });\n }),\n },\n src: \"streamRun\",\n },\n states: {\n monitoring_replies: {\n description: \"Attached to the run event stream\",\n on: {\n STOP_RUN: {\n target: \"stopping\",\n },\n },\n },\n stopping: {\n description: \"Background cancelation of the run stream\",\n invoke: {\n input: ({ context }) => ({\n conversationId: context.conversationId!,\n runId: context.currentRunId!,\n }),\n onDone: {\n actions: assign({ currentRunId: undefined }),\n target: \"#agentConversation.idle\",\n },\n onError: {\n target: \"#agentConversation.retrieving_history\",\n },\n src: \"stopRun\",\n },\n },\n },\n },\n submitting_message: {\n description: \"Submitting message to start a new reply stream\",\n invoke: {\n input: ({ context, event }) => {\n switch (event.type) {\n case \"RETRY_MESSAGE\":\n if (!context.messageAttempt) {\n throw new Error(\"Tried to resubmit nonexistent message\");\n }\n return {\n conversationId: context.conversationId!,\n message: context.messageAttempt,\n };\n case \"SUBMIT_USER_MESSAGE\":\n return {\n conversationId: context.conversationId!,\n message: event.message,\n };\n }\n throw new Error(`Unexpected event type received in submitting_message: ${event.type}`);\n },\n onDone: {\n actions: assign({\n // Add the message attempt into the snapshot manually\n conversationSnapshot: ({ context, event }) => [\n ...(context.conversationSnapshot ?? []),\n {\n id: event.output.currentRunId,\n messages: new Map(),\n submittedUserMessage: context.messageAttempt || undefined,\n toolCalls: new Map(),\n } satisfies ConversationExchange,\n ],\n currentRunId: ({ event }) => event.output.currentRunId,\n messageAttempt: undefined,\n }),\n target: \"streaming\",\n },\n onError: {\n actions: assign({\n currentRunId: () => null,\n lastError: ({ event }) => event.error,\n }),\n target: \"submitting_message_failed\",\n },\n src: \"startRun\",\n },\n },\n submitting_message_failed: {\n description: \"Failed to submit message\",\n on: {\n REFRESH_HISTORY: {\n actions: assign({ lastError: undefined }),\n target: \"retrieving_history\",\n },\n RETRY_MESSAGE: {\n actions: assign({ lastError: undefined }),\n target: \"submitting_message\",\n },\n SUBMIT_USER_MESSAGE: {\n actions: assign({\n lastError: undefined,\n messageAttempt: ({ event }) => event.message,\n }),\n target: \"submitting_message\",\n },\n },\n },\n uninitialized: {\n always: {\n guard: ({ context }) => !!context.conversationId,\n target: \"retrieving_history\",\n },\n description:\n \"Entry state that the machine remains in when no conversation has been provided\",\n on: {\n SUBMIT_USER_MESSAGE: {\n actions: assign({\n messageAttempt: ({ event }) => event.message,\n }),\n target: \"creating_conversation\",\n },\n },\n },\n },\n });\n\nexport type AgentConversationMachine = ReturnType<typeof createConversationMachine>;\n"]}
|
|
1
|
+
{"version":3,"file":"createConversationMachine.js","sourceRoot":"","sources":["../../../../src/enterprise/ai/conversations/createConversationMachine.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,EAAE,cAAc,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAE1F,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAG3D,OAAO,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,MAAM,iCAAiC,CAAC;AAC9F,OAAO,KAAK,CAAC,MAAM,UAAU,CAAC;AAC9B,OAAO,EAAE,oBAAoB,EAAE,MAAM,mCAAmC,CAAC;AACzE,OAAO,EAAE,2BAA2B,EAAE,MAAM,0CAA0C,CAAC;AACvF,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AACnE,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAC/D,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;A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EAAE,CAAC;oBACzC,MAAM,EAAE,oBAAoB;iBAC7B;gBACD,aAAa,EAAE;oBACb,OAAO,EAAE,MAAM,CAAC,EAAE,SAAS,EAAE,SAAS,EAAE,CAAC;oBACzC,MAAM,EAAE,oBAAoB;iBAC7B;gBACD,mBAAmB,EAAE;oBACnB,OAAO,EAAE,MAAM,CAAC;wBACd,SAAS,EAAE,SAAS;wBACpB,cAAc,EAAE,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,KAAK,CAAC,OAAO;qBAC7C,CAAC;oBACF,MAAM,EAAE,oBAAoB;iBAC7B;aACF;SACF;QACD,aAAa,EAAE;YACb,MAAM,EAAE;gBACN,KAAK,EAAE,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,cAAc;gBAChD,MAAM,EAAE,oBAAoB;aAC7B;YACD,WAAW,EACT,gFAAgF;YAClF,EAAE,EAAE;gBACF,mBAAmB,EAAE;oBACnB,OAAO,EAAE,MAAM,CAAC;wBACd,cAAc,EAAE,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,KAAK,CAAC,OAAO;qBAC7C,CAAC;oBACF,MAAM,EAAE,uBAAuB;iBAChC;aACF;SACF;KACF;CACF,CAAC,CAAC","sourcesContent":["/*\n * Copyright (C) 2024-2025 Dremio Corporation\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { setup, fromObservable, fromPromise, assign, enqueueActions, emit } from \"xstate\";\nimport type { UserChatMessage } from \"../chat/UserChatMessage.ts\";\nimport { AgentConversation } from \"./AgentConversation.ts\";\nimport type { ConversationExchange } from \"./reduceChatEvents.ts\";\nimport type { SonarV4Config } from \"../../../common/Config.ts\";\nimport { createConversation, createConversationCodec } from \"./methods/createConversation.ts\";\nimport * as z from \"zod/mini\";\nimport { retrieveConversation } from \"./methods/retrieveConversation.ts\";\nimport { retrieveConversationHistory } from \"./methods/retrieveConversationHistory.ts\";\nimport { createExchangeRun } from \"./methods/createExchangeRun.ts\";\nimport { stopExchangeRun } from \"./methods/stopExchangeRun.ts\";\nimport { streamRunEvents } from \"./methods/streamRunEvents.ts\";\nimport { fromTextEventStream } from \"../../../common/fromTextEventStream.ts\";\nimport { map } from \"rxjs\";\nimport { chatEventCodec, type ChatEvent } from \"../chat/chatEventSchema.ts\";\nimport type { HttpError } from \"../../../common/HttpError.ts\";\n\nexport type ConversationMachineInput = {\n conversationId: string | null;\n};\n\nexport type ConversationMachineContext = {\n conversationId: string | null;\n conversationSnapshot?: ConversationExchange[];\n currentRunId?: string | null;\n lastError?: unknown;\n messageAttempt?: UserChatMessage;\n};\nexport type ConversationMachineEvents =\n | { type: \"STOP_RUN\" }\n | { type: \"SUBMIT_USER_MESSAGE\"; message: UserChatMessage }\n | { type: \"RETRY_MESSAGE\" }\n | { type: \"REFRESH_HISTORY\" };\n\nexport type ConversationMachineEmitted =\n | {\n type: \"apiError\";\n error: HttpError;\n }\n | {\n type: \"chatEventReceived\";\n chatEvent: ChatEvent;\n }\n | {\n type: \"conversationCreated\";\n id: string;\n };\n\nexport const createConversationMachine = (config: SonarV4Config) =>\n setup({\n actors: {\n createConversation: fromPromise(\n ({ input }: { input: z.input<typeof createConversationCodec> }) =>\n createConversation(config)(input).then((result) => {\n if (result.isErr()) {\n throw result.error;\n }\n return result.value;\n }),\n ),\n retrieveConversation: fromPromise(\n ({ input, signal }: { input: { conversationId: string }; signal: AbortSignal }) =>\n retrieveConversation(config)(input.conversationId, { signal }).then((result) => {\n if (result.isErr()) {\n throw result.error;\n }\n return result.value;\n }),\n ),\n retrieveHistory: fromPromise(\n ({ input, signal }: { input: { conversationId: string }; signal: AbortSignal }) =>\n retrieveConversationHistory(config)(input.conversationId, { signal }).then((result) => {\n if (result.isErr()) {\n throw result.error;\n }\n return result.value;\n }),\n ),\n retrieveState: fromPromise(\n async ({ input, signal }: { input: { conversationId: string }; signal: AbortSignal }) => {\n const [conversation, history] = await Promise.all([\n retrieveConversation(config)(input.conversationId, { signal }).then((result) => {\n if (result.isErr()) {\n throw result.error;\n }\n return result.value;\n }),\n retrieveConversationHistory(config)(input.conversationId, { signal }).then((result) => {\n if (result.isErr()) {\n throw result.error;\n }\n return result.value;\n }),\n ]);\n return {\n conversation,\n history,\n };\n },\n ),\n startRun: fromPromise(\n ({ input }: { input: { conversationId: string; message: UserChatMessage } }) =>\n createExchangeRun(config)(input.conversationId, { message: input.message }).then(\n (result) => {\n if (result.isErr()) {\n throw result.error;\n }\n return result.value;\n },\n ),\n ),\n stopRun: fromPromise(({ input }: { input: { conversationId: string; runId: string } }) =>\n stopExchangeRun(config)(input.conversationId, input.runId).then((result) => {\n if (result.isErr()) {\n throw result.error;\n }\n return result.value;\n }),\n ),\n streamRun: fromObservable(({ input }: { input: { conversationId: string; runId: string } }) =>\n fromTextEventStream(({ signal }) =>\n streamRunEvents(config)(\n { conversationId: input.conversationId, runId: input.runId },\n { signal },\n ),\n ).pipe(\n map((event) =>\n z.decode(chatEventCodec, JSON.parse(event.data) as z.input<typeof chatEventCodec>),\n ),\n ),\n ),\n },\n types: {\n context: {} as ConversationMachineContext,\n emitted: {} as ConversationMachineEmitted,\n events: {} as ConversationMachineEvents,\n input: {} as ConversationMachineInput,\n },\n }).createMachine({\n context: ({ input }) => ({\n conversationId: input.conversationId,\n conversationSnapshot: undefined,\n currentRunId: undefined,\n messageAttempt: undefined,\n }),\n id: \"agentConversation\",\n initial: \"uninitialized\",\n states: {\n creating_conversation: {\n description: \"Creating a new conversation object\",\n invoke: {\n input: ({ context }) => ({\n message: context.messageAttempt!,\n }),\n onDone: [\n {\n actions: [\n assign({\n conversationId: ({ event }) => event.output.id,\n // Add the message attempt into the snapshot manually\n conversationSnapshot: ({ context, event }) => [\n ...(context.conversationSnapshot ?? []),\n {\n id: event.output.currentRunId!,\n messages: new Map(),\n submittedUserMessage: context.messageAttempt,\n toolCalls: new Map(),\n } satisfies ConversationExchange,\n ],\n currentRunId: ({ event }) => event.output.currentRunId,\n messageAttempt: undefined,\n }),\n emit(({ event }) => ({\n id: event.output.id,\n type: \"conversationCreated\",\n })),\n ],\n // Don't transition to streaming in a situation where we didn't receive a currentRunId\n guard: ({ event }) => !!event.output.currentRunId,\n target: \"streaming\",\n },\n /**\n * Fall back to the retrieving_history state if we didn't receive a currentRunId\n */\n {\n actions: assign({\n conversationId: ({ event }) => event.output.id,\n currentRunId: ({ event }) => event.output.currentRunId,\n messageAttempt: undefined,\n }),\n target: \"retrieving_history\",\n },\n ],\n onError: {\n actions: emit(({ event }) => ({\n error: event.error as HttpError,\n type: \"apiError\",\n })),\n target: \"uninitialized\",\n },\n src: \"createConversation\",\n },\n },\n idle: {\n description: \"Waiting for user input to start the next reply stream\",\n on: {\n REFRESH_HISTORY: {\n target: \"retrieving_history\",\n },\n SUBMIT_USER_MESSAGE: {\n actions: assign({\n messageAttempt: ({ event }) => event.message,\n }),\n target: \"submitting_message\",\n },\n },\n },\n retrieve_history_failed: {\n on: {\n REFRESH_HISTORY: {\n actions: assign({ lastError: undefined }),\n target: \"retrieving_history\",\n },\n },\n },\n retrieving_history: {\n description: \"Retrieving latest copy of conversation history\",\n invoke: {\n input: ({ context }) => ({ conversationId: context.conversationId! }),\n onDone: [\n {\n actions: assign({\n conversationSnapshot: ({ context, event }) =>\n AgentConversation.reduceChatEvents(\n context.conversationSnapshot,\n event.output.history.data,\n ),\n currentRunId: ({ event }) => event.output.conversation.currentRunId,\n }),\n guard: ({ event }) => !!event.output.conversation.currentRunId,\n target: \"streaming\",\n },\n {\n actions: assign({\n conversationSnapshot: ({ context, event }) =>\n AgentConversation.reduceChatEvents(\n context.conversationSnapshot,\n event.output.history.data,\n ),\n currentRunId: ({ event }) => event.output.conversation.currentRunId,\n }),\n target: \"idle\",\n },\n ],\n onError: [\n {\n guard: ({ event }) => {\n const e = event.error as Error & { code?: string };\n return (\n e?.name === \"AbortError\" ||\n e?.message?.includes(\"aborted\") ||\n e?.code === \"ABORT_ERR\"\n );\n },\n target: \"uninitialized\",\n },\n {\n actions: [\n assign({\n lastError: ({ event }) => event.error,\n }),\n emit(({ event }) => ({\n error: event.error as HttpError,\n type: \"apiError\",\n })),\n ],\n target: \"retrieve_history_failed\",\n },\n ],\n src: \"retrieveState\",\n },\n },\n streaming: {\n description: \"Manages monitoring and canceling the current run\",\n initial: \"monitoring_replies\",\n invoke: {\n input: ({ context }) => {\n if (!context.currentRunId) {\n throw new Error(\"Attempted to stream without a runId\");\n }\n return {\n conversationId: context.conversationId!,\n runId: context.currentRunId,\n };\n },\n onDone: {\n actions: assign({ currentRunId: null }),\n target: \"idle\",\n },\n onError: {\n actions: assign({ currentRunId: null }),\n target: \"idle\",\n },\n onSnapshot: {\n actions: enqueueActions(({ context, enqueue, event }) => {\n const chatEvent = event.snapshot.context;\n if (!chatEvent) {\n return;\n }\n\n const nextSnapshot = AgentConversation.reduceChatEvents(\n context.conversationSnapshot,\n [chatEvent],\n );\n\n enqueue.assign({\n conversationSnapshot: nextSnapshot,\n });\n enqueue.emit({\n chatEvent,\n type: \"chatEventReceived\",\n });\n }),\n },\n src: \"streamRun\",\n },\n states: {\n monitoring_replies: {\n description: \"Attached to the run event stream\",\n on: {\n STOP_RUN: {\n target: \"stopping\",\n },\n },\n },\n stopping: {\n description: \"Background cancelation of the run stream\",\n invoke: {\n input: ({ context }) => ({\n conversationId: context.conversationId!,\n runId: context.currentRunId!,\n }),\n onDone: {\n actions: assign({ currentRunId: undefined }),\n target: \"#agentConversation.idle\",\n },\n onError: {\n target: \"#agentConversation.retrieving_history\",\n },\n src: \"stopRun\",\n },\n },\n },\n },\n submitting_message: {\n description: \"Submitting message to start a new reply stream\",\n invoke: {\n input: ({ context, event }) => {\n switch (event.type) {\n case \"RETRY_MESSAGE\":\n if (!context.messageAttempt) {\n throw new Error(\"Tried to resubmit nonexistent message\");\n }\n return {\n conversationId: context.conversationId!,\n message: context.messageAttempt,\n };\n case \"SUBMIT_USER_MESSAGE\":\n return {\n conversationId: context.conversationId!,\n message: event.message,\n };\n }\n throw new Error(`Unexpected event type received in submitting_message: ${event.type}`);\n },\n onDone: {\n actions: assign({\n // Add the message attempt into the snapshot manually\n conversationSnapshot: ({ context, event }) => [\n ...(context.conversationSnapshot ?? []),\n {\n id: event.output.currentRunId,\n messages: new Map(),\n submittedUserMessage: context.messageAttempt || undefined,\n toolCalls: new Map(),\n } satisfies ConversationExchange,\n ],\n currentRunId: ({ event }) => event.output.currentRunId,\n messageAttempt: undefined,\n }),\n target: \"streaming\",\n },\n onError: {\n actions: [\n assign({\n currentRunId: () => null,\n lastError: ({ event }) => event.error,\n }),\n emit(({ event }) => ({\n error: event.error as HttpError,\n type: \"apiError\",\n })),\n ],\n target: \"submitting_message_failed\",\n },\n src: \"startRun\",\n },\n },\n submitting_message_failed: {\n description: \"Failed to submit message\",\n on: {\n REFRESH_HISTORY: {\n actions: assign({ lastError: undefined }),\n target: \"retrieving_history\",\n },\n RETRY_MESSAGE: {\n actions: assign({ lastError: undefined }),\n target: \"submitting_message\",\n },\n SUBMIT_USER_MESSAGE: {\n actions: assign({\n lastError: undefined,\n messageAttempt: ({ event }) => event.message,\n }),\n target: \"submitting_message\",\n },\n },\n },\n uninitialized: {\n always: {\n guard: ({ context }) => !!context.conversationId,\n target: \"retrieving_history\",\n },\n description:\n \"Entry state that the machine remains in when no conversation has been provided\",\n on: {\n SUBMIT_USER_MESSAGE: {\n actions: assign({\n messageAttempt: ({ event }) => event.message,\n }),\n target: \"creating_conversation\",\n },\n },\n },\n },\n });\n\nexport type AgentConversationMachine = ReturnType<typeof createConversationMachine>;\n"]}
|
package/dist-iife/cloud.js
CHANGED
|
@@ -31034,6 +31034,10 @@ ${err.message}`);
|
|
|
31034
31034
|
}
|
|
31035
31035
|
],
|
|
31036
31036
|
onError: {
|
|
31037
|
+
actions: emit(({ event }) => ({
|
|
31038
|
+
error: event.error,
|
|
31039
|
+
type: "apiError"
|
|
31040
|
+
})),
|
|
31037
31041
|
target: "uninitialized"
|
|
31038
31042
|
},
|
|
31039
31043
|
src: "createConversation"
|
|
@@ -31091,9 +31095,15 @@ ${err.message}`);
|
|
|
31091
31095
|
target: "uninitialized"
|
|
31092
31096
|
},
|
|
31093
31097
|
{
|
|
31094
|
-
actions:
|
|
31095
|
-
|
|
31096
|
-
|
|
31098
|
+
actions: [
|
|
31099
|
+
assign({
|
|
31100
|
+
lastError: ({ event }) => event.error
|
|
31101
|
+
}),
|
|
31102
|
+
emit(({ event }) => ({
|
|
31103
|
+
error: event.error,
|
|
31104
|
+
type: "apiError"
|
|
31105
|
+
}))
|
|
31106
|
+
],
|
|
31097
31107
|
target: "retrieve_history_failed"
|
|
31098
31108
|
}
|
|
31099
31109
|
],
|
|
@@ -31206,10 +31216,16 @@ ${err.message}`);
|
|
|
31206
31216
|
target: "streaming"
|
|
31207
31217
|
},
|
|
31208
31218
|
onError: {
|
|
31209
|
-
actions:
|
|
31210
|
-
|
|
31211
|
-
|
|
31212
|
-
|
|
31219
|
+
actions: [
|
|
31220
|
+
assign({
|
|
31221
|
+
currentRunId: () => null,
|
|
31222
|
+
lastError: ({ event }) => event.error
|
|
31223
|
+
}),
|
|
31224
|
+
emit(({ event }) => ({
|
|
31225
|
+
error: event.error,
|
|
31226
|
+
type: "apiError"
|
|
31227
|
+
}))
|
|
31228
|
+
],
|
|
31213
31229
|
target: "submitting_message_failed"
|
|
31214
31230
|
},
|
|
31215
31231
|
src: "startRun"
|
package/dist-iife/enterprise.js
CHANGED
|
@@ -31740,6 +31740,10 @@ ${err.message}`);
|
|
|
31740
31740
|
}
|
|
31741
31741
|
],
|
|
31742
31742
|
onError: {
|
|
31743
|
+
actions: emit(({ event }) => ({
|
|
31744
|
+
error: event.error,
|
|
31745
|
+
type: "apiError"
|
|
31746
|
+
})),
|
|
31743
31747
|
target: "uninitialized"
|
|
31744
31748
|
},
|
|
31745
31749
|
src: "createConversation"
|
|
@@ -31797,9 +31801,15 @@ ${err.message}`);
|
|
|
31797
31801
|
target: "uninitialized"
|
|
31798
31802
|
},
|
|
31799
31803
|
{
|
|
31800
|
-
actions:
|
|
31801
|
-
|
|
31802
|
-
|
|
31804
|
+
actions: [
|
|
31805
|
+
assign({
|
|
31806
|
+
lastError: ({ event }) => event.error
|
|
31807
|
+
}),
|
|
31808
|
+
emit(({ event }) => ({
|
|
31809
|
+
error: event.error,
|
|
31810
|
+
type: "apiError"
|
|
31811
|
+
}))
|
|
31812
|
+
],
|
|
31803
31813
|
target: "retrieve_history_failed"
|
|
31804
31814
|
}
|
|
31805
31815
|
],
|
|
@@ -31912,10 +31922,16 @@ ${err.message}`);
|
|
|
31912
31922
|
target: "streaming"
|
|
31913
31923
|
},
|
|
31914
31924
|
onError: {
|
|
31915
|
-
actions:
|
|
31916
|
-
|
|
31917
|
-
|
|
31918
|
-
|
|
31925
|
+
actions: [
|
|
31926
|
+
assign({
|
|
31927
|
+
currentRunId: () => null,
|
|
31928
|
+
lastError: ({ event }) => event.error
|
|
31929
|
+
}),
|
|
31930
|
+
emit(({ event }) => ({
|
|
31931
|
+
error: event.error,
|
|
31932
|
+
type: "apiError"
|
|
31933
|
+
}))
|
|
31934
|
+
],
|
|
31919
31935
|
target: "submitting_message_failed"
|
|
31920
31936
|
},
|
|
31921
31937
|
src: "startRun"
|