@dremio/js-sdk 0.59.0 → 0.60.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 +9 -0
- package/dist/cloud/ai/AIResource.d.ts +93 -13
- package/dist/enterprise/ai/AIResource.d.ts +93 -13
- package/dist/enterprise/ai/chat/chatEventSchema.d.ts +26 -3
- package/dist/enterprise/ai/chat/chatEventSchema.js +61 -11
- package/dist/enterprise/ai/chat/chatEventSchema.js.map +1 -1
- package/dist/enterprise/ai/conversations/AgentConversation.d.ts +30 -4
- package/dist/enterprise/ai/conversations/createConversationMachine.d.ts +97 -13
- package/dist/enterprise/ai/conversations/createConversationMachine.js +80 -11
- package/dist/enterprise/ai/conversations/createConversationMachine.js.map +1 -1
- package/dist/enterprise/ai/conversations/methods/retrieveConversationHistory.d.ts +15 -2
- package/dist/enterprise/ai/conversations/reduceChatEvents.d.ts +1 -1
- package/dist/enterprise/ai/conversations/reduceChatEvents.js +4 -1
- package/dist/enterprise/ai/conversations/reduceChatEvents.js.map +1 -1
- package/dist-iife/cloud.js +146 -28
- package/dist-iife/enterprise.js +146 -28
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chatEventSchema.js","sourceRoot":"","sources":["../../../../src/enterprise/ai/chat/chatEventSchema.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,KAAK,CAAC,MAAM,UAAU,CAAC;AAE9B;;;GAGG;AACH,MAAM,uBAAuB,GAAG;IAC9B,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC;IAC7C,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,SAAS,CAAC,C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-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 { Temporal } from \"temporal-polyfill\";\nimport * as z from \"zod/mini\";\n\n/**\n * Shared chat event fields for all responses (except error response)\n * @deprecated\n */\nconst chatEventV1SharedSchema = {\n createdAt: z.string().check(z.iso.datetime()),\n modelName: z.string().check(z.trim(), z.minLength(1)),\n modelProviderId: z.string().check(z.trim(), z.minLength(1)),\n sessionId: z.string().check(z.trim(), z.minLength(1)),\n};\n\n/**\n * Shared chat event fields for all responses (except error response)\n */\nconst chatEventSharedSchema = {\n conversationId: z.string(),\n createdAt: z.string().check(z.iso.datetime()),\n messageId: z.string(),\n modelName: z.string(),\n modelProviderId: z.string(),\n runId: z.string(),\n};\n\nconst errorChunkSchema = z.object({\n chunkType: z.literal(\"error\"),\n /**\n * If the message is not present or very short, it won't be useful to show\n * anyways, so the parser should throw to the generic response error handler.\n */\n message: z.string().check(z.trim(), z.minLength(2)),\n});\n\nconst errorChunkV2Schema = z.object({\n chunkType: z.literal(\"error\"),\n message: z.string().check(z.trim(), z.minLength(2)),\n type: z.string(),\n});\n\nconst conversationUpdateChunkSchema = z.object({\n chunkType: z.literal(\"conversationUpdate\"),\n summary: z.optional(z.string()),\n title: z.optional(z.string()),\n});\n\nconst endOfStreamChunkSchema = z.object({\n chunkType: z.literal(\"endOfStream\"),\n});\n\nconst interruptChunkSchema = z.object({\n chunkType: z.literal(\"interrupt\"),\n});\n\nconst modelChunkSchema = z.object({\n chunkType: z.literal(\"model\"),\n name: z.string().check(z.trim(), z.minLength(1)),\n /**\n * It's useful to indicate (to the type system) that the result contents\n * at this stage can only be data (de)serializable from JSON. Because\n * model responses can vary depending on runtime flags and edition, we can\n * leave this field generic and refine it more precisely in later stages.\n */\n result: z.record(z.string(), z.unknown()),\n});\n\nconst sandboxProgressChunkSchema = z.object({\n chunkType: z.literal(\"sandboxProgress\"),\n stepName: z.string(),\n text: z.string(),\n});\nconst toolPlanSchema = z.record(z.string(), z.unknown());\n\nconst toolRequestChunkSchema = z.object({\n arguments: z.record(z.string(), z.unknown()),\n callId: z.string().check(z.trim(), z.minLength(1)),\n chunkType: z.literal(\"toolRequest\"),\n commentary: z.optional(z.string()),\n name: z.string(),\n replacePlan: z.optional(toolPlanSchema),\n summarizedTitle: z.optional(z.string()),\n updatePlan: z.optional(toolPlanSchema),\n});\n\nconst toolResponseChunkSchema = z.object({\n callId: z.string(),\n chunkType: z.literal(\"toolResponse\"),\n commentary: z.optional(z.string()),\n name: z.string(),\n result: z.record(z.string(), z.unknown()),\n});\n\nconst jobUpdateChunkSchema = z.object({\n chunkType: z.literal(\"jobUpdate\"),\n jobId: z.string(),\n jobState: z.string(),\n toolExecutionId: z.string(),\n toolName: z.string(),\n});\n\nconst userMessageChunkSchema = z.object({\n chunkType: z.literal(\"userMessage\"),\n text: z.string(),\n});\n\n/**\n * Captures all of the possible chunks of data that the Agent can reply\n * with. We're lenient to extra/unexpected fields being present (`z.object`\n * instead of `z.strictObject`), but for the fields that are expected,\n * we validate that they match the most general type category they belong in.\n * For example, it's good enough to validate that the `callId` is a string\n * for type safety -- we don't need to verify that it's also a `z.uuid()`.\n * @deprecated\n */\nexport const chatEventV1Schema = z.discriminatedUnion(\"chunkType\", [\n errorChunkSchema,\n z.extend(modelChunkSchema, chatEventV1SharedSchema),\n z.extend(toolRequestChunkSchema, chatEventV1SharedSchema),\n z.extend(toolResponseChunkSchema, chatEventV1SharedSchema),\n]);\n\n/**\n * @deprecated\n */\nexport type ChatEventV1 = z.infer<typeof chatEventV1Schema>;\n\nconst chatEventInputSchema = z.discriminatedUnion(\"chunkType\", [\n z.extend(errorChunkV2Schema, chatEventSharedSchema),\n z.extend(endOfStreamChunkSchema, chatEventSharedSchema),\n z.extend(interruptChunkSchema, chatEventSharedSchema),\n z.extend(conversationUpdateChunkSchema, chatEventSharedSchema),\n z.extend(jobUpdateChunkSchema, chatEventSharedSchema),\n z.extend(modelChunkSchema, chatEventSharedSchema),\n z.extend(sandboxProgressChunkSchema, chatEventSharedSchema),\n z.extend(toolRequestChunkSchema, chatEventSharedSchema),\n z.extend(toolResponseChunkSchema, chatEventSharedSchema),\n z.extend(userMessageChunkSchema, chatEventSharedSchema),\n]);\n\nconst chatEventOutputSharedSchema = z.extend(\n z.omit(z.strictObject(chatEventSharedSchema), { createdAt: true, messageId: true }),\n {\n createdAt: z.instanceof(Temporal.Instant),\n id: z.string(),\n },\n);\n\nconst chatEventOutputSchema = z.union([\n z.extend(chatEventOutputSharedSchema, {\n content: conversationUpdateChunkSchema,\n role: z.literal(\"agent\"),\n }),\n z.extend(chatEventOutputSharedSchema, { content: errorChunkV2Schema, role: z.literal(\"agent\") }),\n z.extend(chatEventOutputSharedSchema, {\n content: endOfStreamChunkSchema,\n role: z.literal(\"agent\"),\n }),\n z.extend(chatEventOutputSharedSchema, {\n content: interruptChunkSchema,\n role: z.literal(\"agent\"),\n }),\n z.extend(chatEventOutputSharedSchema, {\n content: jobUpdateChunkSchema,\n role: z.literal(\"agent\"),\n }),\n z.extend(chatEventOutputSharedSchema, { content: modelChunkSchema, role: z.literal(\"agent\") }),\n z.extend(chatEventOutputSharedSchema, {\n content: sandboxProgressChunkSchema,\n role: z.literal(\"agent\"),\n }),\n z.extend(chatEventOutputSharedSchema, {\n content: toolRequestChunkSchema,\n role: z.literal(\"agent\"),\n }),\n z.extend(chatEventOutputSharedSchema, {\n content: toolResponseChunkSchema,\n role: z.literal(\"agent\"),\n }),\n z.extend(chatEventOutputSharedSchema, {\n content: userMessageChunkSchema,\n role: z.literal(\"user\"),\n }),\n]);\n\nexport const chatEventCodec = z.codec(chatEventInputSchema, chatEventOutputSchema, {\n decode(v) {\n const sharedProperties = {\n conversationId: v.conversationId,\n createdAt: Temporal.Instant.from(v.createdAt),\n id: v.messageId,\n modelName: v.modelName,\n modelProviderId: v.modelProviderId,\n runId: v.runId,\n } as const satisfies Omit<z.output<typeof chatEventOutputSchema>, \"content\" | \"role\">;\n\n switch (v.chunkType) {\n case \"conversationUpdate\":\n return {\n ...sharedProperties,\n content: {\n chunkType: \"conversationUpdate\",\n summary: v.summary,\n title: v.title,\n },\n role: \"agent\",\n } as const satisfies z.output<typeof chatEventOutputSchema>;\n case \"error\":\n return {\n ...sharedProperties,\n content: {\n chunkType: \"error\",\n message: v.message,\n type: v.type,\n },\n role: \"agent\",\n } as const satisfies z.output<typeof chatEventOutputSchema>;\n case \"endOfStream\":\n return {\n ...sharedProperties,\n content: {\n chunkType: \"endOfStream\",\n },\n role: \"agent\",\n } as const satisfies z.output<typeof chatEventOutputSchema>;\n case \"interrupt\":\n return {\n ...sharedProperties,\n content: {\n chunkType: \"interrupt\",\n },\n role: \"agent\",\n } as const satisfies z.output<typeof chatEventOutputSchema>;\n case \"jobUpdate\":\n return {\n ...sharedProperties,\n content: {\n chunkType: \"jobUpdate\",\n jobId: v.jobId,\n jobState: v.jobState,\n toolExecutionId: v.toolExecutionId,\n toolName: v.toolName,\n },\n role: \"agent\",\n } as const satisfies z.output<typeof chatEventOutputSchema>;\n case \"model\":\n return {\n ...sharedProperties,\n content: {\n chunkType: \"model\",\n name: v.name,\n result: v.result,\n },\n role: \"agent\",\n } as const satisfies z.output<typeof chatEventOutputSchema>;\n case \"sandboxProgress\":\n return {\n ...sharedProperties,\n content: {\n chunkType: \"sandboxProgress\",\n stepName: v.stepName,\n text: v.text,\n },\n role: \"agent\",\n } as const satisfies z.output<typeof chatEventOutputSchema>;\n case \"toolRequest\":\n return {\n ...sharedProperties,\n content: {\n arguments: v.arguments,\n callId: v.callId,\n chunkType: \"toolRequest\",\n commentary: v.commentary,\n name: v.name,\n replacePlan: v.replacePlan,\n summarizedTitle: v.summarizedTitle,\n updatePlan: v.updatePlan,\n },\n role: \"agent\",\n } as const satisfies z.output<typeof chatEventOutputSchema>;\n case \"toolResponse\":\n return {\n ...sharedProperties,\n content: {\n callId: v.callId,\n chunkType: \"toolResponse\",\n commentary: v.commentary,\n name: v.name,\n result: v.result,\n },\n role: \"agent\",\n } as const satisfies z.output<typeof chatEventOutputSchema>;\n case \"userMessage\":\n return {\n ...sharedProperties,\n content: { chunkType: \"userMessage\", text: v.text },\n role: \"user\",\n } as const satisfies z.output<typeof chatEventOutputSchema>;\n }\n },\n encode(v) {\n return {\n conversationId: v.conversationId,\n createdAt: v.createdAt.toString(),\n messageId: v.id,\n modelName: v.modelName,\n modelProviderId: v.modelProviderId,\n runId: v.runId,\n ...v.content,\n } as const satisfies z.infer<typeof chatEventInputSchema>;\n },\n});\n\nexport type ChatEvent = z.output<typeof chatEventCodec>;\nexport type ChatEventWithChunkType<T extends z.input<typeof chatEventCodec>[\"chunkType\"]> = Extract<\n ChatEvent,\n { content: { chunkType: T } }\n>;\n"]}
|
|
1
|
+
{"version":3,"file":"chatEventSchema.js","sourceRoot":"","sources":["../../../../src/enterprise/ai/chat/chatEventSchema.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,KAAK,CAAC,MAAM,UAAU,CAAC;AAE9B;;;GAGG;AACH,MAAM,uBAAuB,GAAG;IAC9B,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC;IAC7C,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;IACrD,eAAe,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,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,EAAE,CAAC;YAC1C,OAAO;gBACL,SAAS,EAAE,aAAa;gBACxB,cAAc,EAAE,CAAC,CAAC,cAAc;gBAChC,SAAS,EAAE,CAAC,CAAC,SAAS,CAAC,QAAQ,EAAE;gBACjC,SAAS,EAAE,CAAC,CAAC,SAAS;gBACtB,eAAe,EAAE,CAAC,CAAC,eAAe;gBAClC,KAAK,EAAE,CAAC,CAAC,KAAK;aACyC,CAAC;QAC5D,CAAC;QACD,uFAAuF;QACvF,MAAM,EAAE,GAAI,CAAqE,CAAC,EAAE,CAAC;QACrF,OAAO;YACL,cAAc,EAAE,CAAC,CAAC,cAAc;YAChC,SAAS,EAAE,CAAC,CAAC,SAAS,CAAC,QAAQ,EAAE;YACjC,SAAS,EAAE,EAAE;YACb,SAAS,EAAE,CAAC,CAAC,SAAS;YACtB,eAAe,EAAE,CAAC,CAAC,eAAe;YAClC,KAAK,EAAE,CAAC,CAAC,KAAK;YACd,GAAG,CAAC,CAAC,OAAO;SAC2C,CAAC;IAC5D,CAAC;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 { Temporal } from \"temporal-polyfill\";\nimport * as z from \"zod/mini\";\n\n/**\n * Shared chat event fields for all responses (except error response)\n * @deprecated\n */\nconst chatEventV1SharedSchema = {\n createdAt: z.string().check(z.iso.datetime()),\n modelName: z.string().check(z.trim(), z.minLength(1)),\n modelProviderId: z.string().check(z.trim(), z.minLength(1)),\n sessionId: z.string().check(z.trim(), z.minLength(1)),\n};\n\n/**\n * Shared chat event fields for all responses (except error response)\n */\nconst chatEventSharedSchema = {\n conversationId: z.string(),\n createdAt: z.string().check(z.iso.datetime()),\n messageId: z.string(),\n modelName: z.string(),\n modelProviderId: z.string(),\n runId: z.string(),\n};\n\nconst errorChunkSchema = z.object({\n chunkType: z.literal(\"error\"),\n /**\n * If the message is not present or very short, it won't be useful to show\n * anyways, so the parser should throw to the generic response error handler.\n */\n message: z.string().check(z.trim(), z.minLength(2)),\n});\n\nconst errorChunkV2Schema = z.object({\n chunkType: z.literal(\"error\"),\n message: z.string().check(z.trim(), z.minLength(2)),\n type: z.string(),\n});\n\nconst conversationUpdateChunkSchema = z.object({\n chunkType: z.literal(\"conversationUpdate\"),\n summary: z.optional(z.string()),\n title: z.optional(z.string()),\n});\n\nconst endOfStreamChunkSchema = z.object({\n chunkType: z.literal(\"endOfStream\"),\n});\n\n// endOfStream omits messageId: the backend sends it absent or as \"\", neither maps to a meaningful id\nconst endOfStreamInputSchema = z.object({\n chunkType: z.literal(\"endOfStream\"),\n conversationId: z.string(),\n createdAt: z.string().check(z.iso.datetime()),\n modelName: z.string(),\n modelProviderId: z.string(),\n runId: z.string(),\n});\n\nconst interruptChunkSchema = z.object({\n chunkType: z.literal(\"interrupt\"),\n});\n\nconst modelChunkSchema = z.object({\n chunkType: z.literal(\"model\"),\n name: z.string().check(z.trim(), z.minLength(1)),\n /**\n * It's useful to indicate (to the type system) that the result contents\n * at this stage can only be data (de)serializable from JSON. Because\n * model responses can vary depending on runtime flags and edition, we can\n * leave this field generic and refine it more precisely in later stages.\n */\n result: z.record(z.string(), z.unknown()),\n});\n\nconst sandboxProgressChunkSchema = z.object({\n chunkType: z.literal(\"sandboxProgress\"),\n stepName: z.string(),\n text: z.string(),\n});\n\nconst sandboxStdoutChunkSchema = z.object({\n callId: z.string().check(z.trim(), z.minLength(1)),\n chunkType: z.literal(\"sandboxStdout\"),\n isFinal: z.boolean(),\n text: z.string(),\n});\nconst sandboxStdoutContentSchema = sandboxStdoutChunkSchema;\nconst sandboxStdoutChatEventSchema = z.extend(sandboxStdoutChunkSchema, chatEventSharedSchema);\nconst toolPlanSchema = z.record(z.string(), z.unknown());\n\nconst toolRequestChunkSchema = z.object({\n arguments: z.record(z.string(), z.unknown()),\n callId: z.string().check(z.trim(), z.minLength(1)),\n chunkType: z.literal(\"toolRequest\"),\n commentary: z.optional(z.string()),\n name: z.string(),\n replacePlan: z.optional(toolPlanSchema),\n summarizedTitle: z.optional(z.string()),\n updatePlan: z.optional(toolPlanSchema),\n});\n\nconst toolResponseChunkSchema = z.object({\n callId: z.string(),\n chunkType: z.literal(\"toolResponse\"),\n commentary: z.optional(z.string()),\n name: z.string(),\n result: z.record(z.string(), z.unknown()),\n});\n\nconst jobUpdateChunkSchema = z.object({\n chunkType: z.literal(\"jobUpdate\"),\n jobId: z.string(),\n jobState: z.string(),\n toolExecutionId: z.string(),\n toolName: z.string(),\n});\n\nconst userMessageChunkSchema = z.object({\n chunkType: z.literal(\"userMessage\"),\n text: z.string(),\n});\n\n/**\n * Captures all of the possible chunks of data that the Agent can reply\n * with. We're lenient to extra/unexpected fields being present (`z.object`\n * instead of `z.strictObject`), but for the fields that are expected,\n * we validate that they match the most general type category they belong in.\n * For example, it's good enough to validate that the `callId` is a string\n * for type safety -- we don't need to verify that it's also a `z.uuid()`.\n * @deprecated\n */\nexport const chatEventV1Schema = z.discriminatedUnion(\"chunkType\", [\n errorChunkSchema,\n z.extend(modelChunkSchema, chatEventV1SharedSchema),\n z.extend(toolRequestChunkSchema, chatEventV1SharedSchema),\n z.extend(toolResponseChunkSchema, chatEventV1SharedSchema),\n]);\n\n/**\n * @deprecated\n */\nexport type ChatEventV1 = z.infer<typeof chatEventV1Schema>;\n\nconst chatEventInputSchema = z.discriminatedUnion(\"chunkType\", [\n z.extend(errorChunkV2Schema, chatEventSharedSchema),\n endOfStreamInputSchema,\n z.extend(interruptChunkSchema, chatEventSharedSchema),\n z.extend(conversationUpdateChunkSchema, chatEventSharedSchema),\n z.extend(jobUpdateChunkSchema, chatEventSharedSchema),\n z.extend(modelChunkSchema, chatEventSharedSchema),\n z.extend(sandboxProgressChunkSchema, chatEventSharedSchema),\n sandboxStdoutChatEventSchema,\n z.extend(toolRequestChunkSchema, chatEventSharedSchema),\n z.extend(toolResponseChunkSchema, chatEventSharedSchema),\n z.extend(userMessageChunkSchema, chatEventSharedSchema),\n]);\n\nconst chatEventOutputSharedSchema = z.extend(\n z.omit(z.strictObject(chatEventSharedSchema), { createdAt: true, messageId: true }),\n {\n createdAt: z.instanceof(Temporal.Instant),\n id: z.string(),\n },\n);\n\n// endOfStream has no meaningful messageId on input, so no id on output\nconst endOfStreamOutputSchema = z.omit(chatEventOutputSharedSchema, { id: true });\n\nconst chatEventOutputSchema = z.union([\n z.extend(chatEventOutputSharedSchema, {\n content: conversationUpdateChunkSchema,\n role: z.literal(\"agent\"),\n }),\n z.extend(chatEventOutputSharedSchema, { content: errorChunkV2Schema, role: z.literal(\"agent\") }),\n z.extend(endOfStreamOutputSchema, {\n content: endOfStreamChunkSchema,\n role: z.literal(\"agent\"),\n }),\n z.extend(chatEventOutputSharedSchema, {\n content: interruptChunkSchema,\n role: z.literal(\"agent\"),\n }),\n z.extend(chatEventOutputSharedSchema, {\n content: jobUpdateChunkSchema,\n role: z.literal(\"agent\"),\n }),\n z.extend(chatEventOutputSharedSchema, { content: modelChunkSchema, role: z.literal(\"agent\") }),\n z.extend(chatEventOutputSharedSchema, {\n content: sandboxProgressChunkSchema,\n role: z.literal(\"agent\"),\n }),\n z.extend(chatEventOutputSharedSchema, {\n content: sandboxStdoutContentSchema,\n role: z.literal(\"agent\"),\n }),\n z.extend(chatEventOutputSharedSchema, {\n content: toolRequestChunkSchema,\n role: z.literal(\"agent\"),\n }),\n z.extend(chatEventOutputSharedSchema, {\n content: toolResponseChunkSchema,\n role: z.literal(\"agent\"),\n }),\n z.extend(chatEventOutputSharedSchema, {\n content: userMessageChunkSchema,\n role: z.literal(\"user\"),\n }),\n]);\n\nexport const chatEventCodec = z.codec(chatEventInputSchema, chatEventOutputSchema, {\n decode(v) {\n if (v.chunkType === \"endOfStream\") {\n return {\n content: { chunkType: \"endOfStream\" },\n conversationId: v.conversationId,\n createdAt: Temporal.Instant.from(v.createdAt),\n modelName: v.modelName,\n modelProviderId: v.modelProviderId,\n role: \"agent\",\n runId: v.runId,\n } as const satisfies z.output<typeof chatEventOutputSchema>;\n }\n\n const sharedProperties = {\n conversationId: v.conversationId,\n createdAt: Temporal.Instant.from(v.createdAt),\n id: v.messageId,\n modelName: v.modelName,\n modelProviderId: v.modelProviderId,\n runId: v.runId,\n };\n\n switch (v.chunkType) {\n case \"conversationUpdate\":\n return {\n ...sharedProperties,\n content: {\n chunkType: \"conversationUpdate\",\n summary: v.summary,\n title: v.title,\n },\n role: \"agent\",\n } as const satisfies z.output<typeof chatEventOutputSchema>;\n case \"error\":\n return {\n ...sharedProperties,\n content: {\n chunkType: \"error\",\n message: v.message,\n type: v.type,\n },\n role: \"agent\",\n } as const satisfies z.output<typeof chatEventOutputSchema>;\n case \"interrupt\":\n return {\n ...sharedProperties,\n content: {\n chunkType: \"interrupt\",\n },\n role: \"agent\",\n } as const satisfies z.output<typeof chatEventOutputSchema>;\n case \"jobUpdate\":\n return {\n ...sharedProperties,\n content: {\n chunkType: \"jobUpdate\",\n jobId: v.jobId,\n jobState: v.jobState,\n toolExecutionId: v.toolExecutionId,\n toolName: v.toolName,\n },\n role: \"agent\",\n } as const satisfies z.output<typeof chatEventOutputSchema>;\n case \"model\":\n return {\n ...sharedProperties,\n content: {\n chunkType: \"model\",\n name: v.name,\n result: v.result,\n },\n role: \"agent\",\n } as const satisfies z.output<typeof chatEventOutputSchema>;\n case \"sandboxProgress\":\n return {\n ...sharedProperties,\n content: {\n chunkType: \"sandboxProgress\",\n stepName: v.stepName,\n text: v.text,\n },\n role: \"agent\",\n } as const satisfies z.output<typeof chatEventOutputSchema>;\n case \"sandboxStdout\":\n return {\n ...sharedProperties,\n content: {\n callId: v.callId,\n chunkType: \"sandboxStdout\",\n isFinal: v.isFinal,\n text: v.text,\n },\n role: \"agent\",\n } as const satisfies z.output<typeof chatEventOutputSchema>;\n case \"toolRequest\":\n return {\n ...sharedProperties,\n content: {\n arguments: v.arguments,\n callId: v.callId,\n chunkType: \"toolRequest\",\n commentary: v.commentary,\n name: v.name,\n replacePlan: v.replacePlan,\n summarizedTitle: v.summarizedTitle,\n updatePlan: v.updatePlan,\n },\n role: \"agent\",\n } as const satisfies z.output<typeof chatEventOutputSchema>;\n case \"toolResponse\":\n return {\n ...sharedProperties,\n content: {\n callId: v.callId,\n chunkType: \"toolResponse\",\n commentary: v.commentary,\n name: v.name,\n result: v.result,\n },\n role: \"agent\",\n } as const satisfies z.output<typeof chatEventOutputSchema>;\n case \"userMessage\":\n return {\n ...sharedProperties,\n content: { chunkType: \"userMessage\", text: v.text },\n role: \"user\",\n } as const satisfies z.output<typeof chatEventOutputSchema>;\n }\n },\n encode(v) {\n if (v.content.chunkType === \"endOfStream\") {\n return {\n chunkType: \"endOfStream\",\n conversationId: v.conversationId,\n createdAt: v.createdAt.toString(),\n modelName: v.modelName,\n modelProviderId: v.modelProviderId,\n runId: v.runId,\n } as const satisfies z.infer<typeof chatEventInputSchema>;\n }\n // Safe: endOfStream (the only variant without id) is handled by the early return above\n const id = (v as Extract<z.output<typeof chatEventOutputSchema>, { id: string }>).id;\n return {\n conversationId: v.conversationId,\n createdAt: v.createdAt.toString(),\n messageId: id,\n modelName: v.modelName,\n modelProviderId: v.modelProviderId,\n runId: v.runId,\n ...v.content,\n } as const satisfies z.infer<typeof chatEventInputSchema>;\n },\n});\n\nexport type ChatEvent = z.output<typeof chatEventCodec>;\nexport type ChatEventWithChunkType<T extends z.input<typeof chatEventCodec>[\"chunkType\"]> = Extract<\n ChatEvent,\n { content: { chunkType: T } }\n>;\n"]}
|
|
@@ -60,12 +60,11 @@ export declare class AgentConversation implements AgentConversationProperties {
|
|
|
60
60
|
};
|
|
61
61
|
role: "agent";
|
|
62
62
|
} | {
|
|
63
|
+
createdAt: import("temporal-polyfill").Temporal.Instant;
|
|
63
64
|
conversationId: string;
|
|
64
65
|
modelName: string;
|
|
65
66
|
modelProviderId: string;
|
|
66
67
|
runId: string;
|
|
67
|
-
createdAt: import("temporal-polyfill").Temporal.Instant;
|
|
68
|
-
id: string;
|
|
69
68
|
content: {
|
|
70
69
|
chunkType: "endOfStream";
|
|
71
70
|
};
|
|
@@ -122,6 +121,20 @@ export declare class AgentConversation implements AgentConversationProperties {
|
|
|
122
121
|
text: string;
|
|
123
122
|
};
|
|
124
123
|
role: "agent";
|
|
124
|
+
} | {
|
|
125
|
+
conversationId: string;
|
|
126
|
+
modelName: string;
|
|
127
|
+
modelProviderId: string;
|
|
128
|
+
runId: string;
|
|
129
|
+
createdAt: import("temporal-polyfill").Temporal.Instant;
|
|
130
|
+
id: string;
|
|
131
|
+
content: {
|
|
132
|
+
callId: string;
|
|
133
|
+
chunkType: "sandboxStdout";
|
|
134
|
+
isFinal: boolean;
|
|
135
|
+
text: string;
|
|
136
|
+
};
|
|
137
|
+
role: "agent";
|
|
125
138
|
} | {
|
|
126
139
|
conversationId: string;
|
|
127
140
|
modelName: string;
|
|
@@ -195,12 +208,11 @@ export declare class AgentConversation implements AgentConversationProperties {
|
|
|
195
208
|
};
|
|
196
209
|
role: "agent";
|
|
197
210
|
} | {
|
|
211
|
+
createdAt: import("temporal-polyfill").Temporal.Instant;
|
|
198
212
|
conversationId: string;
|
|
199
213
|
modelName: string;
|
|
200
214
|
modelProviderId: string;
|
|
201
215
|
runId: string;
|
|
202
|
-
createdAt: import("temporal-polyfill").Temporal.Instant;
|
|
203
|
-
id: string;
|
|
204
216
|
content: {
|
|
205
217
|
chunkType: "endOfStream";
|
|
206
218
|
};
|
|
@@ -257,6 +269,20 @@ export declare class AgentConversation implements AgentConversationProperties {
|
|
|
257
269
|
text: string;
|
|
258
270
|
};
|
|
259
271
|
role: "agent";
|
|
272
|
+
} | {
|
|
273
|
+
conversationId: string;
|
|
274
|
+
modelName: string;
|
|
275
|
+
modelProviderId: string;
|
|
276
|
+
runId: string;
|
|
277
|
+
createdAt: import("temporal-polyfill").Temporal.Instant;
|
|
278
|
+
id: string;
|
|
279
|
+
content: {
|
|
280
|
+
callId: string;
|
|
281
|
+
chunkType: "sandboxStdout";
|
|
282
|
+
isFinal: boolean;
|
|
283
|
+
text: string;
|
|
284
|
+
};
|
|
285
|
+
role: "agent";
|
|
260
286
|
} | {
|
|
261
287
|
conversationId: string;
|
|
262
288
|
modelName: string;
|
|
@@ -12,6 +12,9 @@ export type ConversationMachineContext = {
|
|
|
12
12
|
currentRunId?: string | null;
|
|
13
13
|
lastError?: unknown;
|
|
14
14
|
messageAttempt?: UserChatMessage;
|
|
15
|
+
receivedEndOfStream: boolean;
|
|
16
|
+
streamRetryCount: number;
|
|
17
|
+
userRequestedStop: boolean;
|
|
15
18
|
};
|
|
16
19
|
export type ConversationMachineEvents = {
|
|
17
20
|
type: "STOP_RUN";
|
|
@@ -33,6 +36,7 @@ export type ConversationMachineEmitted = {
|
|
|
33
36
|
type: "conversationCreated";
|
|
34
37
|
id: string;
|
|
35
38
|
};
|
|
39
|
+
export declare const MAX_STREAM_RETRIES = 5;
|
|
36
40
|
export declare const createConversationMachine: (config: SonarV4Config) => import("xstate").StateMachine<ConversationMachineContext, {
|
|
37
41
|
type: "STOP_RUN";
|
|
38
42
|
} | {
|
|
@@ -95,12 +99,11 @@ export declare const createConversationMachine: (config: SonarV4Config) => impor
|
|
|
95
99
|
};
|
|
96
100
|
role: "agent";
|
|
97
101
|
} | {
|
|
102
|
+
createdAt: import("temporal-polyfill").Temporal.Instant;
|
|
98
103
|
conversationId: string;
|
|
99
104
|
modelName: string;
|
|
100
105
|
modelProviderId: string;
|
|
101
106
|
runId: string;
|
|
102
|
-
createdAt: import("temporal-polyfill").Temporal.Instant;
|
|
103
|
-
id: string;
|
|
104
107
|
content: {
|
|
105
108
|
chunkType: "endOfStream";
|
|
106
109
|
};
|
|
@@ -157,6 +160,20 @@ export declare const createConversationMachine: (config: SonarV4Config) => impor
|
|
|
157
160
|
text: string;
|
|
158
161
|
};
|
|
159
162
|
role: "agent";
|
|
163
|
+
} | {
|
|
164
|
+
conversationId: string;
|
|
165
|
+
modelName: string;
|
|
166
|
+
modelProviderId: string;
|
|
167
|
+
runId: string;
|
|
168
|
+
createdAt: import("temporal-polyfill").Temporal.Instant;
|
|
169
|
+
id: string;
|
|
170
|
+
content: {
|
|
171
|
+
callId: string;
|
|
172
|
+
chunkType: "sandboxStdout";
|
|
173
|
+
isFinal: boolean;
|
|
174
|
+
text: string;
|
|
175
|
+
};
|
|
176
|
+
role: "agent";
|
|
160
177
|
} | {
|
|
161
178
|
conversationId: string;
|
|
162
179
|
modelName: string;
|
|
@@ -244,12 +261,11 @@ export declare const createConversationMachine: (config: SonarV4Config) => impor
|
|
|
244
261
|
};
|
|
245
262
|
role: "agent";
|
|
246
263
|
} | {
|
|
264
|
+
createdAt: import("temporal-polyfill").Temporal.Instant;
|
|
247
265
|
conversationId: string;
|
|
248
266
|
modelName: string;
|
|
249
267
|
modelProviderId: string;
|
|
250
268
|
runId: string;
|
|
251
|
-
createdAt: import("temporal-polyfill").Temporal.Instant;
|
|
252
|
-
id: string;
|
|
253
269
|
content: {
|
|
254
270
|
chunkType: "endOfStream";
|
|
255
271
|
};
|
|
@@ -306,6 +322,20 @@ export declare const createConversationMachine: (config: SonarV4Config) => impor
|
|
|
306
322
|
text: string;
|
|
307
323
|
};
|
|
308
324
|
role: "agent";
|
|
325
|
+
} | {
|
|
326
|
+
conversationId: string;
|
|
327
|
+
modelName: string;
|
|
328
|
+
modelProviderId: string;
|
|
329
|
+
runId: string;
|
|
330
|
+
createdAt: import("temporal-polyfill").Temporal.Instant;
|
|
331
|
+
id: string;
|
|
332
|
+
content: {
|
|
333
|
+
callId: string;
|
|
334
|
+
chunkType: "sandboxStdout";
|
|
335
|
+
isFinal: boolean;
|
|
336
|
+
text: string;
|
|
337
|
+
};
|
|
338
|
+
role: "agent";
|
|
309
339
|
} | {
|
|
310
340
|
conversationId: string;
|
|
311
341
|
modelName: string;
|
|
@@ -400,12 +430,11 @@ export declare const createConversationMachine: (config: SonarV4Config) => impor
|
|
|
400
430
|
};
|
|
401
431
|
role: "agent";
|
|
402
432
|
} | {
|
|
433
|
+
createdAt: import("temporal-polyfill").Temporal.Instant;
|
|
403
434
|
conversationId: string;
|
|
404
435
|
modelName: string;
|
|
405
436
|
modelProviderId: string;
|
|
406
437
|
runId: string;
|
|
407
|
-
createdAt: import("temporal-polyfill").Temporal.Instant;
|
|
408
|
-
id: string;
|
|
409
438
|
content: {
|
|
410
439
|
chunkType: "endOfStream";
|
|
411
440
|
};
|
|
@@ -462,6 +491,20 @@ export declare const createConversationMachine: (config: SonarV4Config) => impor
|
|
|
462
491
|
text: string;
|
|
463
492
|
};
|
|
464
493
|
role: "agent";
|
|
494
|
+
} | {
|
|
495
|
+
conversationId: string;
|
|
496
|
+
modelName: string;
|
|
497
|
+
modelProviderId: string;
|
|
498
|
+
runId: string;
|
|
499
|
+
createdAt: import("temporal-polyfill").Temporal.Instant;
|
|
500
|
+
id: string;
|
|
501
|
+
content: {
|
|
502
|
+
callId: string;
|
|
503
|
+
chunkType: "sandboxStdout";
|
|
504
|
+
isFinal: boolean;
|
|
505
|
+
text: string;
|
|
506
|
+
};
|
|
507
|
+
role: "agent";
|
|
465
508
|
} | {
|
|
466
509
|
conversationId: string;
|
|
467
510
|
modelName: string;
|
|
@@ -573,12 +616,11 @@ export declare const createConversationMachine: (config: SonarV4Config) => impor
|
|
|
573
616
|
};
|
|
574
617
|
role: "agent";
|
|
575
618
|
} | {
|
|
619
|
+
createdAt: import("temporal-polyfill").Temporal.Instant;
|
|
576
620
|
conversationId: string;
|
|
577
621
|
modelName: string;
|
|
578
622
|
modelProviderId: string;
|
|
579
623
|
runId: string;
|
|
580
|
-
createdAt: import("temporal-polyfill").Temporal.Instant;
|
|
581
|
-
id: string;
|
|
582
624
|
content: {
|
|
583
625
|
chunkType: "endOfStream";
|
|
584
626
|
};
|
|
@@ -635,6 +677,20 @@ export declare const createConversationMachine: (config: SonarV4Config) => impor
|
|
|
635
677
|
text: string;
|
|
636
678
|
};
|
|
637
679
|
role: "agent";
|
|
680
|
+
} | {
|
|
681
|
+
conversationId: string;
|
|
682
|
+
modelName: string;
|
|
683
|
+
modelProviderId: string;
|
|
684
|
+
runId: string;
|
|
685
|
+
createdAt: import("temporal-polyfill").Temporal.Instant;
|
|
686
|
+
id: string;
|
|
687
|
+
content: {
|
|
688
|
+
callId: string;
|
|
689
|
+
chunkType: "sandboxStdout";
|
|
690
|
+
isFinal: boolean;
|
|
691
|
+
text: string;
|
|
692
|
+
};
|
|
693
|
+
role: "agent";
|
|
638
694
|
} | {
|
|
639
695
|
conversationId: string;
|
|
640
696
|
modelName: string;
|
|
@@ -726,12 +782,11 @@ export declare const createConversationMachine: (config: SonarV4Config) => impor
|
|
|
726
782
|
};
|
|
727
783
|
role: "agent";
|
|
728
784
|
} | {
|
|
785
|
+
createdAt: import("temporal-polyfill").Temporal.Instant;
|
|
729
786
|
conversationId: string;
|
|
730
787
|
modelName: string;
|
|
731
788
|
modelProviderId: string;
|
|
732
789
|
runId: string;
|
|
733
|
-
createdAt: import("temporal-polyfill").Temporal.Instant;
|
|
734
|
-
id: string;
|
|
735
790
|
content: {
|
|
736
791
|
chunkType: "endOfStream";
|
|
737
792
|
};
|
|
@@ -788,6 +843,20 @@ export declare const createConversationMachine: (config: SonarV4Config) => impor
|
|
|
788
843
|
text: string;
|
|
789
844
|
};
|
|
790
845
|
role: "agent";
|
|
846
|
+
} | {
|
|
847
|
+
conversationId: string;
|
|
848
|
+
modelName: string;
|
|
849
|
+
modelProviderId: string;
|
|
850
|
+
runId: string;
|
|
851
|
+
createdAt: import("temporal-polyfill").Temporal.Instant;
|
|
852
|
+
id: string;
|
|
853
|
+
content: {
|
|
854
|
+
callId: string;
|
|
855
|
+
chunkType: "sandboxStdout";
|
|
856
|
+
isFinal: boolean;
|
|
857
|
+
text: string;
|
|
858
|
+
};
|
|
859
|
+
role: "agent";
|
|
791
860
|
} | {
|
|
792
861
|
conversationId: string;
|
|
793
862
|
modelName: string;
|
|
@@ -894,12 +963,11 @@ export declare const createConversationMachine: (config: SonarV4Config) => impor
|
|
|
894
963
|
};
|
|
895
964
|
role: "agent";
|
|
896
965
|
} | {
|
|
966
|
+
createdAt: import("temporal-polyfill").Temporal.Instant;
|
|
897
967
|
conversationId: string;
|
|
898
968
|
modelName: string;
|
|
899
969
|
modelProviderId: string;
|
|
900
970
|
runId: string;
|
|
901
|
-
createdAt: import("temporal-polyfill").Temporal.Instant;
|
|
902
|
-
id: string;
|
|
903
971
|
content: {
|
|
904
972
|
chunkType: "endOfStream";
|
|
905
973
|
};
|
|
@@ -956,6 +1024,20 @@ export declare const createConversationMachine: (config: SonarV4Config) => impor
|
|
|
956
1024
|
text: string;
|
|
957
1025
|
};
|
|
958
1026
|
role: "agent";
|
|
1027
|
+
} | {
|
|
1028
|
+
conversationId: string;
|
|
1029
|
+
modelName: string;
|
|
1030
|
+
modelProviderId: string;
|
|
1031
|
+
runId: string;
|
|
1032
|
+
createdAt: import("temporal-polyfill").Temporal.Instant;
|
|
1033
|
+
id: string;
|
|
1034
|
+
content: {
|
|
1035
|
+
callId: string;
|
|
1036
|
+
chunkType: "sandboxStdout";
|
|
1037
|
+
isFinal: boolean;
|
|
1038
|
+
text: string;
|
|
1039
|
+
};
|
|
1040
|
+
role: "agent";
|
|
959
1041
|
} | {
|
|
960
1042
|
conversationId: string;
|
|
961
1043
|
modelName: string;
|
|
@@ -1006,7 +1088,7 @@ export declare const createConversationMachine: (config: SonarV4Config) => impor
|
|
|
1006
1088
|
runId: string;
|
|
1007
1089
|
}, import("xstate").EventObject>;
|
|
1008
1090
|
id: string | undefined;
|
|
1009
|
-
}, never, never,
|
|
1091
|
+
}, never, never, "STREAM_RETRY_DELAY", "uninitialized" | "creating_conversation" | "retrieving_history" | "idle" | "submitting_message" | "retrieve_history_failed" | "stream_interrupted" | "stream_recovery_failed" | "submitting_message_failed" | {
|
|
1010
1092
|
streaming: "monitoring_replies" | "stopping";
|
|
1011
1093
|
}, string, ConversationMachineInput, import("xstate").NonReducibleUnknown, {
|
|
1012
1094
|
type: "apiError";
|
|
@@ -1024,6 +1106,8 @@ export declare const createConversationMachine: (config: SonarV4Config) => impor
|
|
|
1024
1106
|
readonly idle: {};
|
|
1025
1107
|
readonly retrieve_history_failed: {};
|
|
1026
1108
|
readonly retrieving_history: {};
|
|
1109
|
+
readonly stream_interrupted: {};
|
|
1110
|
+
readonly stream_recovery_failed: {};
|
|
1027
1111
|
readonly streaming: {
|
|
1028
1112
|
states: {
|
|
1029
1113
|
readonly monitoring_replies: {};
|
|
@@ -25,6 +25,14 @@ import { streamRunEvents } from "./methods/streamRunEvents.js";
|
|
|
25
25
|
import { fromTextEventStream } from "../../../common/fromTextEventStream.js";
|
|
26
26
|
import { map } from "rxjs";
|
|
27
27
|
import { chatEventCodec } from "../chat/chatEventSchema.js";
|
|
28
|
+
const RETRIEVE_STATE_TIMEOUT_MS = 10_000;
|
|
29
|
+
const STREAM_RETRY_DELAY_MS = 2500;
|
|
30
|
+
export const MAX_STREAM_RETRIES = 5;
|
|
31
|
+
const STREAM_STATE_RESET = {
|
|
32
|
+
receivedEndOfStream: false,
|
|
33
|
+
streamRetryCount: 0,
|
|
34
|
+
userRequestedStop: false,
|
|
35
|
+
};
|
|
28
36
|
export const createConversationMachine = (config) => setup({
|
|
29
37
|
actors: {
|
|
30
38
|
createConversation: fromPromise(({ input }) => createConversation(config)(input).then((result) => {
|
|
@@ -46,9 +54,13 @@ export const createConversationMachine = (config) => setup({
|
|
|
46
54
|
return result.value;
|
|
47
55
|
})),
|
|
48
56
|
retrieveState: fromPromise(async ({ input, signal }) => {
|
|
57
|
+
const timeoutSignal = AbortSignal.any([
|
|
58
|
+
signal,
|
|
59
|
+
AbortSignal.timeout(RETRIEVE_STATE_TIMEOUT_MS),
|
|
60
|
+
]);
|
|
49
61
|
const [conversationResult, historyResult] = await Promise.all([
|
|
50
|
-
retrieveConversation(config)(input.conversationId, { signal }),
|
|
51
|
-
retrieveConversationHistory(config)(input.conversationId, { signal }),
|
|
62
|
+
retrieveConversation(config)(input.conversationId, { signal: timeoutSignal }),
|
|
63
|
+
retrieveConversationHistory(config)(input.conversationId, { signal: timeoutSignal }),
|
|
52
64
|
]);
|
|
53
65
|
if (conversationResult.isErr()) {
|
|
54
66
|
throw conversationResult.error;
|
|
@@ -75,6 +87,9 @@ export const createConversationMachine = (config) => setup({
|
|
|
75
87
|
})),
|
|
76
88
|
streamRun: fromObservable(({ input }) => fromTextEventStream(({ signal }) => streamRunEvents(config)({ conversationId: input.conversationId, runId: input.runId }, { signal })).pipe(map((event) => z.decode(chatEventCodec, JSON.parse(event.data))))),
|
|
77
89
|
},
|
|
90
|
+
delays: {
|
|
91
|
+
STREAM_RETRY_DELAY: STREAM_RETRY_DELAY_MS,
|
|
92
|
+
},
|
|
78
93
|
types: {
|
|
79
94
|
context: {},
|
|
80
95
|
emitted: {},
|
|
@@ -87,6 +102,7 @@ export const createConversationMachine = (config) => setup({
|
|
|
87
102
|
conversationSnapshot: undefined,
|
|
88
103
|
currentRunId: undefined,
|
|
89
104
|
messageAttempt: undefined,
|
|
105
|
+
...STREAM_STATE_RESET,
|
|
90
106
|
}),
|
|
91
107
|
id: "agentConversation",
|
|
92
108
|
initial: "uninitialized",
|
|
@@ -114,6 +130,7 @@ export const createConversationMachine = (config) => setup({
|
|
|
114
130
|
],
|
|
115
131
|
currentRunId: ({ event }) => event.output.currentRunId,
|
|
116
132
|
messageAttempt: undefined,
|
|
133
|
+
...STREAM_STATE_RESET,
|
|
117
134
|
}),
|
|
118
135
|
emit(({ event }) => ({
|
|
119
136
|
id: event.output.id,
|
|
@@ -177,6 +194,7 @@ export const createConversationMachine = (config) => setup({
|
|
|
177
194
|
actions: assign({
|
|
178
195
|
conversationSnapshot: ({ context, event }) => AgentConversation.reduceChatEvents(context.conversationSnapshot, event.output.history.data),
|
|
179
196
|
currentRunId: ({ event }) => event.output.conversation.currentRunId,
|
|
197
|
+
receivedEndOfStream: false,
|
|
180
198
|
}),
|
|
181
199
|
guard: ({ event }) => !!event.output.conversation.currentRunId,
|
|
182
200
|
target: "streaming",
|
|
@@ -185,6 +203,7 @@ export const createConversationMachine = (config) => setup({
|
|
|
185
203
|
actions: assign({
|
|
186
204
|
conversationSnapshot: ({ context, event }) => AgentConversation.reduceChatEvents(context.conversationSnapshot, event.output.history.data),
|
|
187
205
|
currentRunId: ({ event }) => event.output.conversation.currentRunId,
|
|
206
|
+
...STREAM_STATE_RESET,
|
|
188
207
|
}),
|
|
189
208
|
target: "idle",
|
|
190
209
|
},
|
|
@@ -193,12 +212,18 @@ export const createConversationMachine = (config) => setup({
|
|
|
193
212
|
{
|
|
194
213
|
guard: ({ event }) => {
|
|
195
214
|
const e = event.error;
|
|
215
|
+
if (e?.name === "TimeoutError")
|
|
216
|
+
return false;
|
|
196
217
|
return (e?.name === "AbortError" ||
|
|
197
218
|
e?.message?.includes("aborted") ||
|
|
198
219
|
e?.code === "ABORT_ERR");
|
|
199
220
|
},
|
|
200
221
|
target: "uninitialized",
|
|
201
222
|
},
|
|
223
|
+
{
|
|
224
|
+
guard: ({ context }) => context.streamRetryCount > 0,
|
|
225
|
+
target: "stream_interrupted",
|
|
226
|
+
},
|
|
202
227
|
{
|
|
203
228
|
actions: [
|
|
204
229
|
assign({
|
|
@@ -215,6 +240,30 @@ export const createConversationMachine = (config) => setup({
|
|
|
215
240
|
src: "retrieveState",
|
|
216
241
|
},
|
|
217
242
|
},
|
|
243
|
+
stream_interrupted: {
|
|
244
|
+
after: {
|
|
245
|
+
STREAM_RETRY_DELAY: [
|
|
246
|
+
{
|
|
247
|
+
actions: assign({
|
|
248
|
+
streamRetryCount: ({ context }) => context.streamRetryCount + 1,
|
|
249
|
+
}),
|
|
250
|
+
guard: ({ context }) => context.streamRetryCount < MAX_STREAM_RETRIES,
|
|
251
|
+
target: "retrieving_history",
|
|
252
|
+
},
|
|
253
|
+
{
|
|
254
|
+
target: "stream_recovery_failed",
|
|
255
|
+
},
|
|
256
|
+
],
|
|
257
|
+
},
|
|
258
|
+
},
|
|
259
|
+
stream_recovery_failed: {
|
|
260
|
+
on: {
|
|
261
|
+
REFRESH_HISTORY: {
|
|
262
|
+
actions: assign({ lastError: undefined, streamRetryCount: 0 }),
|
|
263
|
+
target: "retrieving_history",
|
|
264
|
+
},
|
|
265
|
+
},
|
|
266
|
+
},
|
|
218
267
|
streaming: {
|
|
219
268
|
description: "Manages monitoring and canceling the current run",
|
|
220
269
|
initial: "monitoring_replies",
|
|
@@ -228,20 +277,37 @@ export const createConversationMachine = (config) => setup({
|
|
|
228
277
|
runId: context.currentRunId,
|
|
229
278
|
};
|
|
230
279
|
},
|
|
231
|
-
onDone:
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
280
|
+
onDone: [
|
|
281
|
+
{
|
|
282
|
+
actions: assign({ currentRunId: null, userRequestedStop: false }),
|
|
283
|
+
guard: ({ context }) => !!context.receivedEndOfStream || !!context.userRequestedStop,
|
|
284
|
+
target: "idle",
|
|
285
|
+
},
|
|
286
|
+
{
|
|
287
|
+
actions: assign({ currentRunId: null }),
|
|
288
|
+
target: "stream_interrupted",
|
|
289
|
+
},
|
|
290
|
+
],
|
|
291
|
+
onError: [
|
|
292
|
+
{
|
|
293
|
+
actions: assign({ currentRunId: null, userRequestedStop: false }),
|
|
294
|
+
guard: ({ context }) => !!context.receivedEndOfStream || !!context.userRequestedStop,
|
|
295
|
+
target: "idle",
|
|
296
|
+
},
|
|
297
|
+
{
|
|
298
|
+
actions: assign({ currentRunId: null }),
|
|
299
|
+
target: "stream_interrupted",
|
|
300
|
+
},
|
|
301
|
+
],
|
|
239
302
|
onSnapshot: {
|
|
240
303
|
actions: enqueueActions(({ context, enqueue, event }) => {
|
|
241
304
|
const chatEvent = event.snapshot.context;
|
|
242
305
|
if (!chatEvent) {
|
|
243
306
|
return;
|
|
244
307
|
}
|
|
308
|
+
if (chatEvent.content.chunkType === "endOfStream" && !context.receivedEndOfStream) {
|
|
309
|
+
enqueue.assign({ receivedEndOfStream: true });
|
|
310
|
+
}
|
|
245
311
|
const nextSnapshot = AgentConversation.reduceChatEvents(context.conversationSnapshot, [chatEvent]);
|
|
246
312
|
enqueue.assign({
|
|
247
313
|
conversationSnapshot: nextSnapshot,
|
|
@@ -259,6 +325,7 @@ export const createConversationMachine = (config) => setup({
|
|
|
259
325
|
description: "Attached to the run event stream",
|
|
260
326
|
on: {
|
|
261
327
|
STOP_RUN: {
|
|
328
|
+
actions: assign({ userRequestedStop: true }),
|
|
262
329
|
target: "stopping",
|
|
263
330
|
},
|
|
264
331
|
},
|
|
@@ -271,10 +338,11 @@ export const createConversationMachine = (config) => setup({
|
|
|
271
338
|
runId: context.currentRunId,
|
|
272
339
|
}),
|
|
273
340
|
onDone: {
|
|
274
|
-
actions: assign({ currentRunId: undefined }),
|
|
341
|
+
actions: assign({ currentRunId: undefined, userRequestedStop: false }),
|
|
275
342
|
target: "#agentConversation.idle",
|
|
276
343
|
},
|
|
277
344
|
onError: {
|
|
345
|
+
actions: assign({ userRequestedStop: false }),
|
|
278
346
|
target: "#agentConversation.retrieving_history",
|
|
279
347
|
},
|
|
280
348
|
src: "stopRun",
|
|
@@ -317,6 +385,7 @@ export const createConversationMachine = (config) => setup({
|
|
|
317
385
|
],
|
|
318
386
|
currentRunId: ({ event }) => event.output.currentRunId,
|
|
319
387
|
messageAttempt: undefined,
|
|
388
|
+
...STREAM_STATE_RESET,
|
|
320
389
|
}),
|
|
321
390
|
target: "streaming",
|
|
322
391
|
},
|