@aws-amplify/data-schema 1.12.2 → 1.13.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.
Files changed (48) hide show
  1. package/dist/cjs/ai/ConversationSchemaTypes.js +19 -0
  2. package/dist/cjs/ai/ConversationSchemaTypes.js.map +1 -1
  3. package/dist/cjs/ai/types/ConversationStreamEvent.js +6 -0
  4. package/dist/cjs/ai/types/ConversationStreamEvent.js.map +1 -0
  5. package/dist/cjs/runtime/internals/ai/conversationStreamEventDeserializers.js +41 -0
  6. package/dist/cjs/runtime/internals/ai/conversationStreamEventDeserializers.js.map +1 -0
  7. package/dist/cjs/runtime/internals/ai/convertItemToConversation.js +2 -2
  8. package/dist/cjs/runtime/internals/ai/convertItemToConversation.js.map +1 -1
  9. package/dist/cjs/runtime/internals/ai/convertItemToConversationMessage.js +1 -1
  10. package/dist/cjs/runtime/internals/ai/convertItemToConversationMessage.js.map +1 -1
  11. package/dist/cjs/runtime/internals/ai/{createOnMessageFunction.js → createOnStreamEventFunction.js} +11 -7
  12. package/dist/cjs/runtime/internals/ai/createOnStreamEventFunction.js.map +1 -0
  13. package/dist/cjs/runtime/internals/ai/getCustomUserAgentDetails.js +1 -1
  14. package/dist/cjs/runtime/internals/ai/getCustomUserAgentDetails.js.map +1 -1
  15. package/dist/esm/ClientSchema/ai/ClientConversation.d.ts +2 -1
  16. package/dist/esm/ai/ConversationSchemaTypes.mjs +19 -0
  17. package/dist/esm/ai/ConversationSchemaTypes.mjs.map +1 -1
  18. package/dist/esm/ai/ConversationType.d.ts +9 -4
  19. package/dist/esm/ai/types/ConversationStreamEvent.d.ts +56 -0
  20. package/dist/esm/ai/types/ConversationStreamEvent.mjs +2 -0
  21. package/dist/esm/ai/types/ConversationStreamEvent.mjs.map +1 -0
  22. package/dist/esm/runtime/internals/ai/conversationStreamEventDeserializers.d.ts +6 -0
  23. package/dist/esm/runtime/internals/ai/conversationStreamEventDeserializers.mjs +38 -0
  24. package/dist/esm/runtime/internals/ai/conversationStreamEventDeserializers.mjs.map +1 -0
  25. package/dist/esm/runtime/internals/ai/convertItemToConversation.mjs +2 -2
  26. package/dist/esm/runtime/internals/ai/convertItemToConversation.mjs.map +1 -1
  27. package/dist/esm/runtime/internals/ai/convertItemToConversationMessage.mjs +1 -1
  28. package/dist/esm/runtime/internals/ai/convertItemToConversationMessage.mjs.map +1 -1
  29. package/dist/esm/runtime/internals/ai/createOnStreamEventFunction.d.ts +3 -0
  30. package/dist/esm/runtime/internals/ai/{createOnMessageFunction.mjs → createOnStreamEventFunction.mjs} +10 -6
  31. package/dist/esm/runtime/internals/ai/createOnStreamEventFunction.mjs.map +1 -0
  32. package/dist/esm/runtime/internals/ai/getCustomUserAgentDetails.d.ts +1 -1
  33. package/dist/esm/runtime/internals/ai/getCustomUserAgentDetails.mjs +1 -1
  34. package/dist/esm/runtime/internals/ai/getCustomUserAgentDetails.mjs.map +1 -1
  35. package/dist/meta/cjs.tsbuildinfo +1 -1
  36. package/package.json +1 -1
  37. package/src/ClientSchema/ai/ClientConversation.ts +2 -0
  38. package/src/ai/ConversationSchemaTypes.ts +21 -0
  39. package/src/ai/ConversationType.ts +10 -3
  40. package/src/ai/types/ConversationStreamEvent.ts +70 -0
  41. package/src/runtime/internals/ai/conversationStreamEventDeserializers.ts +62 -0
  42. package/src/runtime/internals/ai/convertItemToConversation.ts +2 -2
  43. package/src/runtime/internals/ai/convertItemToConversationMessage.ts +1 -1
  44. package/src/runtime/internals/ai/{createOnMessageFunction.ts → createOnStreamEventFunction.ts} +7 -5
  45. package/src/runtime/internals/ai/getCustomUserAgentDetails.ts +1 -1
  46. package/dist/cjs/runtime/internals/ai/createOnMessageFunction.js.map +0 -1
  47. package/dist/esm/runtime/internals/ai/createOnMessageFunction.d.ts +0 -3
  48. package/dist/esm/runtime/internals/ai/createOnMessageFunction.mjs.map +0 -1
@@ -184,6 +184,23 @@ const ToolSpecification = `type ToolSpecification {
184
184
  const ToolInputSchema = `type ToolInputSchema {
185
185
  json: AWSJSON
186
186
  }`;
187
+ const ConversationMessageStreamEvent = `type ConversationMessageStreamPart @aws_cognito_user_pools {
188
+ id: ID!
189
+ owner: String
190
+ conversationId: ID!
191
+ associatedUserMessageId: ID!
192
+ contentBlockIndex: Int!
193
+ contentBlockText: String
194
+ contentBlockDeltaIndex: Int
195
+ contentBlockToolUse: ToolUseBlock
196
+ contentBlockDoneAtIndex: Int
197
+ stopReason: String
198
+ errors: [ConversationTurnError]
199
+ }`;
200
+ const ConversationTurnError = `type ConversationTurnError @aws_cognito_user_pools {
201
+ message: String!
202
+ errorType: String!
203
+ }`;
187
204
  exports.conversationTypes = [
188
205
  ConversationParticipantRole,
189
206
  ConversationMessage,
@@ -216,5 +233,7 @@ exports.conversationTypes = [
216
233
  Tool,
217
234
  ToolSpecification,
218
235
  ToolInputSchema,
236
+ ConversationMessageStreamEvent,
237
+ ConversationTurnError,
219
238
  ];
220
239
  //# sourceMappingURL=ConversationSchemaTypes.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"ConversationSchemaTypes.js","sources":["../../../src/ai/ConversationSchemaTypes.ts"],"sourcesContent":["\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.conversationTypes = exports.createConversationField = void 0;\nconst utils_1 = require(\"../runtime/utils\");\nconst createConversationField = (typeDef, typeName) => {\n const { aiModel, systemPrompt, handler, tools } = typeDef;\n const args = {\n aiModel: aiModel.resourcePath,\n // This is done to escape newlines in potentially multi-line system prompts\n // e.g.\n // realtorChat: a.conversation({\n // aiModel: a.ai.model('Claude 3 Haiku'),\n // systemPrompt: `You are a helpful real estate assistant\n // Respond in the poetic form of haiku.`,\n // }),\n //\n // It doesn't affect non multi-line string inputs for system prompts\n systemPrompt: systemPrompt.replace(/\\r?\\n/g, '\\\\n'),\n };\n const argsString = Object.entries(args)\n .map(([key, value]) => `${key}: \"${value}\"`)\n .join(', ');\n const functionHandler = {};\n let handlerString = '';\n if (handler) {\n const functionName = `Fn${(0, utils_1.capitalize)(typeName)}`;\n const eventVersion = handler.eventVersion;\n handlerString = `, handler: { functionName: \"${functionName}\", eventVersion: \"${eventVersion}\" }`;\n functionHandler[functionName] = handler;\n }\n const toolsString = tools?.length\n ? `, tools: [${getConversationToolsString(tools)}]`\n : '';\n const conversationDirective = `@conversation(${argsString}${handlerString}${toolsString})`;\n const field = `${typeName}(conversationId: ID!, content: [ContentBlockInput], aiContext: AWSJSON, toolConfiguration: ToolConfigurationInput): ConversationMessage ${conversationDirective} @aws_cognito_user_pools`;\n return { field, functionHandler };\n};\nexports.createConversationField = createConversationField;\nconst isRef = (query) => query?.data?.type === 'ref';\nconst getConversationToolsString = (tools) => tools\n .map((tool) => {\n const { query, description } = tool;\n if (!isRef(query)) {\n throw new Error(`Unexpected query was found in tool ${tool}.`);\n }\n // TODO: add validation for query / auth (cup) / etc\n const queryName = query.data.link;\n return `{ name: \"${queryName}\", description: \"${description}\" }`;\n})\n .join(', ');\nconst ConversationParticipantRole = `enum ConversationParticipantRole {\n user\n assistant\n}`;\nconst ConversationMessage = `interface ConversationMessage {\n id: ID!\n conversationId: ID!\n role: ConversationParticipantRole\n content: [ContentBlock]\n aiContext: AWSJSON\n toolConfiguration: ToolConfiguration\n createdAt: AWSDateTime\n updatedAt: AWSDateTime\n owner: String\n}`;\nconst DocumentBlockSourceInput = `input DocumentBlockSourceInput {\n bytes: String\n}`;\nconst DocumentBlockInput = `input DocumentBlockInput {\n format: String!\n name: String!\n source: DocumentBlockSourceInput!\n}`;\nconst ImageBlockSourceInput = `input ImageBlockSourceInput {\n bytes: String\n}`;\nconst ImageBlockInput = `input ImageBlockInput {\n format: String!\n source: ImageBlockSourceInput!\n}`;\nconst ToolResultContentBlockInput = `input ToolResultContentBlockInput {\n document: DocumentBlockInput\n image: ImageBlockInput\n json: AWSJSON\n text: String\n}`;\nconst ToolResultBlockInput = `input ToolResultBlockInput {\n content: [ToolResultContentBlockInput!]!\n toolUseId: String!\n status: String\n}`;\nconst DocumentBlockSource = `type DocumentBlockSource {\n bytes: String\n}\n`;\nconst DocumentBlock = `type DocumentBlock {\n format: String!\n name: String!\n source: DocumentBlockSource!\n}`;\nconst ImageBlock = `type ImageBlock {\n format: String!\n source: ImageBlockSource!\n}`;\nconst ImageBlockSource = `type ImageBlockSource {\n bytes: String\n}`;\nconst ToolUseBlockInput = `input ToolUseBlockInput {\n toolUseId: String!\n name: String!\n input: AWSJSON!\n}`;\nconst ToolUseBlock = `type ToolUseBlock {\n toolUseId: String!\n name: String!\n input: AWSJSON!\n}`;\nconst ToolResultContentBlock = `type ToolResultContentBlock {\n document: DocumentBlock\n image: ImageBlock\n json: AWSJSON\n text: String\n}`;\nconst ToolResultBlock = `type ToolResultBlock {\n content: [ToolResultContentBlock!]!\n toolUseId: String!\n status: String\n}`;\nconst ContentBlockText = `type ContentBlockText {\n text: String\n}`;\nconst ContentBlockImage = `type ContentBlockImage {\n image: ImageBlock\n}`;\nconst ContentBlockDocument = `type ContentBlockDocument {\n document: DocumentBlock\n}`;\nconst ContentBlockToolUse = `type ContentBlockToolUse {\n toolUse: ToolUseBlock\n}`;\nconst ContentBlockToolResult = `type ContentBlockToolResult {\n toolResult: ToolResultBlock\n}`;\nconst ContentBlockInput = `input ContentBlockInput {\n text: String\n document: DocumentBlockInput\n image: ImageBlockInput\n toolResult: ToolResultBlockInput\n toolUse: ToolUseBlockInput\n}`;\nconst ContentBlock = `type ContentBlock {\n text: String\n document: DocumentBlock\n image: ImageBlock\n toolResult: ToolResultBlock\n toolUse: ToolUseBlock\n}`;\nconst ToolConfigurationInput = `input ToolConfigurationInput {\n tools: [ToolInput]\n}`;\nconst ToolInput = `input ToolInput {\n toolSpec: ToolSpecificationInput\n}`;\nconst ToolSpecificationInput = `input ToolSpecificationInput {\n name: String!\n description: String\n inputSchema: ToolInputSchemaInput!\n}`;\nconst ToolInputSchemaInput = `input ToolInputSchemaInput {\n json: AWSJSON\n}`;\nconst ToolConfiguration = `type ToolConfiguration {\n tools: [Tool]\n}`;\nconst Tool = `type Tool {\n toolSpec: ToolSpecification\n}`;\nconst ToolSpecification = `type ToolSpecification {\n name: String!\n description: String\n inputSchema: ToolInputSchema!\n}`;\nconst ToolInputSchema = `type ToolInputSchema {\n json: AWSJSON\n}`;\nexports.conversationTypes = [\n ConversationParticipantRole,\n ConversationMessage,\n DocumentBlockSourceInput,\n DocumentBlockInput,\n ImageBlockSourceInput,\n ImageBlockInput,\n ToolUseBlockInput,\n ToolResultContentBlockInput,\n ToolResultBlockInput,\n DocumentBlockSource,\n DocumentBlock,\n ImageBlock,\n ImageBlockSource,\n ToolUseBlock,\n ToolResultContentBlock,\n ToolResultBlock,\n ContentBlockText,\n ContentBlockImage,\n ContentBlockDocument,\n ContentBlockToolUse,\n ContentBlockToolResult,\n ContentBlockInput,\n ContentBlock,\n ToolConfigurationInput,\n ToolInput,\n ToolSpecificationInput,\n ToolInputSchemaInput,\n ToolConfiguration,\n Tool,\n ToolSpecification,\n ToolInputSchema,\n];\n"],"names":[],"mappings":";;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,iBAAiB,GAAG,OAAO,CAAC,uBAAuB,GAAG,KAAK,CAAC,CAAC;AACrE,MAAM,OAAO,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAC;AAC5C,MAAM,uBAAuB,GAAG,CAAC,OAAO,EAAE,QAAQ,KAAK;AACvD,IAAI,MAAM,EAAE,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,KAAK,EAAE,GAAG,OAAO,CAAC;AAC9D,IAAI,MAAM,IAAI,GAAG;AACjB,QAAQ,OAAO,EAAE,OAAO,CAAC,YAAY;AACrC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,QAAQ,YAAY,EAAE,YAAY,CAAC,OAAO,CAAC,QAAQ,EAAE,KAAK,CAAC;AAC3D,KAAK,CAAC;AACN,IAAI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,CAAC;AACd;AACA,CAAC,CAAC,CAAC;AACH,MAAM,iBAAiB,GAAG,CAAC;AAC3B;AACA;AACA;AACA,CAAC,CAAC,CAAC;AACH,MAAM,eAAe,GAAG,CAAC;AACzB;AACA,CAAC,CAAC,CAAC;AACH,OAAO,CAAC,iBAAiB,GAAG;AAC5B,IAAI,2BAA2B;AAC/B,IAAI,mBAAmB;AACvB,IAAI,wBAAwB;AAC5B,IAAI,kBAAkB;AACtB,IAAI,qBAAqB;AACzB,IAAI,eAAe;AACnB,IAAI,iBAAiB;AACrB,IAAI,2BAA2B;AAC/B,IAAI,oBAAoB;AACxB,IAAI,mBAAmB;AACvB,IAAI,aAAa;AACjB,IAAI,UAAU;AACd,IAAI,gBAAgB;AACpB,IAAI,YAAY;AAChB,IAAI,sBAAsB;AAC1B,IAAI,eAAe;AACnB,IAAI,gBAAgB;AACpB,IAAI,iBAAiB;AACrB,IAAI,oBAAoB;AACxB,IAAI,mBAAmB;AACvB,IAAI,sBAAsB;AAC1B,IAAI,iBAAiB;AACrB,IAAI,YAAY;AAChB,IAAI,sBAAsB;AAC1B,IAAI,SAAS;AACb,IAAI,sBAAsB;AAC1B,IAAI,oBAAoB;AACxB,IAAI,iBAAiB;AACrB,IAAI,IAAI;AACR,IAAI,iBAAiB;AACrB,IAAI,eAAe;AACnB,CAAC;;"}
1
+ {"version":3,"file":"ConversationSchemaTypes.js","sources":["../../../src/ai/ConversationSchemaTypes.ts"],"sourcesContent":["\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.conversationTypes = exports.createConversationField = void 0;\nconst utils_1 = require(\"../runtime/utils\");\nconst createConversationField = (typeDef, typeName) => {\n const { aiModel, systemPrompt, handler, tools } = typeDef;\n const args = {\n aiModel: aiModel.resourcePath,\n // This is done to escape newlines in potentially multi-line system prompts\n // e.g.\n // realtorChat: a.conversation({\n // aiModel: a.ai.model('Claude 3 Haiku'),\n // systemPrompt: `You are a helpful real estate assistant\n // Respond in the poetic form of haiku.`,\n // }),\n //\n // It doesn't affect non multi-line string inputs for system prompts\n systemPrompt: systemPrompt.replace(/\\r?\\n/g, '\\\\n'),\n };\n const argsString = Object.entries(args)\n .map(([key, value]) => `${key}: \"${value}\"`)\n .join(', ');\n const functionHandler = {};\n let handlerString = '';\n if (handler) {\n const functionName = `Fn${(0, utils_1.capitalize)(typeName)}`;\n const eventVersion = handler.eventVersion;\n handlerString = `, handler: { functionName: \"${functionName}\", eventVersion: \"${eventVersion}\" }`;\n functionHandler[functionName] = handler;\n }\n const toolsString = tools?.length\n ? `, tools: [${getConversationToolsString(tools)}]`\n : '';\n const conversationDirective = `@conversation(${argsString}${handlerString}${toolsString})`;\n const field = `${typeName}(conversationId: ID!, content: [ContentBlockInput], aiContext: AWSJSON, toolConfiguration: ToolConfigurationInput): ConversationMessage ${conversationDirective} @aws_cognito_user_pools`;\n return { field, functionHandler };\n};\nexports.createConversationField = createConversationField;\nconst isRef = (query) => query?.data?.type === 'ref';\nconst getConversationToolsString = (tools) => tools\n .map((tool) => {\n const { query, description } = tool;\n if (!isRef(query)) {\n throw new Error(`Unexpected query was found in tool ${tool}.`);\n }\n // TODO: add validation for query / auth (cup) / etc\n const queryName = query.data.link;\n return `{ name: \"${queryName}\", description: \"${description}\" }`;\n})\n .join(', ');\nconst ConversationParticipantRole = `enum ConversationParticipantRole {\n user\n assistant\n}`;\nconst ConversationMessage = `interface ConversationMessage {\n id: ID!\n conversationId: ID!\n role: ConversationParticipantRole\n content: [ContentBlock]\n aiContext: AWSJSON\n toolConfiguration: ToolConfiguration\n createdAt: AWSDateTime\n updatedAt: AWSDateTime\n owner: String\n}`;\nconst DocumentBlockSourceInput = `input DocumentBlockSourceInput {\n bytes: String\n}`;\nconst DocumentBlockInput = `input DocumentBlockInput {\n format: String!\n name: String!\n source: DocumentBlockSourceInput!\n}`;\nconst ImageBlockSourceInput = `input ImageBlockSourceInput {\n bytes: String\n}`;\nconst ImageBlockInput = `input ImageBlockInput {\n format: String!\n source: ImageBlockSourceInput!\n}`;\nconst ToolResultContentBlockInput = `input ToolResultContentBlockInput {\n document: DocumentBlockInput\n image: ImageBlockInput\n json: AWSJSON\n text: String\n}`;\nconst ToolResultBlockInput = `input ToolResultBlockInput {\n content: [ToolResultContentBlockInput!]!\n toolUseId: String!\n status: String\n}`;\nconst DocumentBlockSource = `type DocumentBlockSource {\n bytes: String\n}\n`;\nconst DocumentBlock = `type DocumentBlock {\n format: String!\n name: String!\n source: DocumentBlockSource!\n}`;\nconst ImageBlock = `type ImageBlock {\n format: String!\n source: ImageBlockSource!\n}`;\nconst ImageBlockSource = `type ImageBlockSource {\n bytes: String\n}`;\nconst ToolUseBlockInput = `input ToolUseBlockInput {\n toolUseId: String!\n name: String!\n input: AWSJSON!\n}`;\nconst ToolUseBlock = `type ToolUseBlock {\n toolUseId: String!\n name: String!\n input: AWSJSON!\n}`;\nconst ToolResultContentBlock = `type ToolResultContentBlock {\n document: DocumentBlock\n image: ImageBlock\n json: AWSJSON\n text: String\n}`;\nconst ToolResultBlock = `type ToolResultBlock {\n content: [ToolResultContentBlock!]!\n toolUseId: String!\n status: String\n}`;\nconst ContentBlockText = `type ContentBlockText {\n text: String\n}`;\nconst ContentBlockImage = `type ContentBlockImage {\n image: ImageBlock\n}`;\nconst ContentBlockDocument = `type ContentBlockDocument {\n document: DocumentBlock\n}`;\nconst ContentBlockToolUse = `type ContentBlockToolUse {\n toolUse: ToolUseBlock\n}`;\nconst ContentBlockToolResult = `type ContentBlockToolResult {\n toolResult: ToolResultBlock\n}`;\nconst ContentBlockInput = `input ContentBlockInput {\n text: String\n document: DocumentBlockInput\n image: ImageBlockInput\n toolResult: ToolResultBlockInput\n toolUse: ToolUseBlockInput\n}`;\nconst ContentBlock = `type ContentBlock {\n text: String\n document: DocumentBlock\n image: ImageBlock\n toolResult: ToolResultBlock\n toolUse: ToolUseBlock\n}`;\nconst ToolConfigurationInput = `input ToolConfigurationInput {\n tools: [ToolInput]\n}`;\nconst ToolInput = `input ToolInput {\n toolSpec: ToolSpecificationInput\n}`;\nconst ToolSpecificationInput = `input ToolSpecificationInput {\n name: String!\n description: String\n inputSchema: ToolInputSchemaInput!\n}`;\nconst ToolInputSchemaInput = `input ToolInputSchemaInput {\n json: AWSJSON\n}`;\nconst ToolConfiguration = `type ToolConfiguration {\n tools: [Tool]\n}`;\nconst Tool = `type Tool {\n toolSpec: ToolSpecification\n}`;\nconst ToolSpecification = `type ToolSpecification {\n name: String!\n description: String\n inputSchema: ToolInputSchema!\n}`;\nconst ToolInputSchema = `type ToolInputSchema {\n json: AWSJSON\n}`;\nconst ConversationMessageStreamEvent = `type ConversationMessageStreamPart @aws_cognito_user_pools {\n id: ID!\n owner: String\n conversationId: ID!\n associatedUserMessageId: ID!\n contentBlockIndex: Int!\n contentBlockText: String\n contentBlockDeltaIndex: Int\n contentBlockToolUse: ToolUseBlock\n contentBlockDoneAtIndex: Int\n stopReason: String\n errors: [ConversationTurnError]\n}`;\nconst ConversationTurnError = `type ConversationTurnError @aws_cognito_user_pools {\n message: String!\n errorType: String!\n}`;\nexports.conversationTypes = [\n ConversationParticipantRole,\n ConversationMessage,\n DocumentBlockSourceInput,\n DocumentBlockInput,\n ImageBlockSourceInput,\n ImageBlockInput,\n ToolUseBlockInput,\n ToolResultContentBlockInput,\n ToolResultBlockInput,\n DocumentBlockSource,\n DocumentBlock,\n ImageBlock,\n ImageBlockSource,\n ToolUseBlock,\n ToolResultContentBlock,\n ToolResultBlock,\n ContentBlockText,\n ContentBlockImage,\n ContentBlockDocument,\n ContentBlockToolUse,\n ContentBlockToolResult,\n ContentBlockInput,\n ContentBlock,\n ToolConfigurationInput,\n ToolInput,\n ToolSpecificationInput,\n ToolInputSchemaInput,\n ToolConfiguration,\n Tool,\n ToolSpecification,\n ToolInputSchema,\n ConversationMessageStreamEvent,\n ConversationTurnError,\n];\n"],"names":[],"mappings":";;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,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;AACpB,IAAI,iBAAiB;AACrB,IAAI,oBAAoB;AACxB,IAAI,mBAAmB;AACvB,IAAI,sBAAsB;AAC1B,IAAI,iBAAiB;AACrB,IAAI,YAAY;AAChB,IAAI,sBAAsB;AAC1B,IAAI,SAAS;AACb,IAAI,sBAAsB;AAC1B,IAAI,oBAAoB;AACxB,IAAI,iBAAiB;AACrB,IAAI,IAAI;AACR,IAAI,iBAAiB;AACrB,IAAI,eAAe;AACnB,IAAI,8BAA8B;AAClC,IAAI,qBAAqB;AACzB,CAAC;;"}
@@ -0,0 +1,6 @@
1
+ 'use strict';
2
+
3
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
4
+ // SPDX-License-Identifier: Apache-2.0
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ //# sourceMappingURL=ConversationStreamEvent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ConversationStreamEvent.js","sources":["../../../../src/ai/types/ConversationStreamEvent.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;;"}
@@ -0,0 +1,41 @@
1
+ 'use strict';
2
+
3
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
4
+ // SPDX-License-Identifier: Apache-2.0
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.convertItemToConversationStreamEvent = void 0;
7
+ const convertItemToConversationStreamEvent = ({ id, conversationId, associatedUserMessageId, contentBlockIndex, contentBlockDoneAtIndex, contentBlockDeltaIndex, contentBlockText, contentBlockToolUse, stopReason, errors, }) => {
8
+ if (errors) {
9
+ const error = {
10
+ id,
11
+ conversationId,
12
+ associatedUserMessageId,
13
+ errors,
14
+ };
15
+ return { error };
16
+ }
17
+ const next = removeNullsFromConversationStreamEvent({
18
+ id,
19
+ conversationId,
20
+ associatedUserMessageId,
21
+ contentBlockIndex,
22
+ contentBlockDoneAtIndex,
23
+ contentBlockDeltaIndex,
24
+ text: contentBlockText,
25
+ toolUse: deserializeToolUseBlock(contentBlockToolUse),
26
+ stopReason,
27
+ });
28
+ return { next };
29
+ };
30
+ exports.convertItemToConversationStreamEvent = convertItemToConversationStreamEvent;
31
+ const deserializeToolUseBlock = (contentBlockToolUse) => {
32
+ if (contentBlockToolUse) {
33
+ const toolUseBlock = {
34
+ ...contentBlockToolUse,
35
+ input: JSON.parse(contentBlockToolUse.input),
36
+ };
37
+ return toolUseBlock;
38
+ }
39
+ };
40
+ const removeNullsFromConversationStreamEvent = (block) => Object.fromEntries(Object.entries(block).filter(([_, v]) => v !== null));
41
+ //# sourceMappingURL=conversationStreamEventDeserializers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"conversationStreamEventDeserializers.js","sources":["../../../../../src/runtime/internals/ai/conversationStreamEventDeserializers.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.convertItemToConversationStreamEvent = void 0;\nconst convertItemToConversationStreamEvent = ({ id, conversationId, associatedUserMessageId, contentBlockIndex, contentBlockDoneAtIndex, contentBlockDeltaIndex, contentBlockText, contentBlockToolUse, stopReason, errors, }) => {\n if (errors) {\n const error = {\n id,\n conversationId,\n associatedUserMessageId,\n errors,\n };\n return { error };\n }\n const next = removeNullsFromConversationStreamEvent({\n id,\n conversationId,\n associatedUserMessageId,\n contentBlockIndex,\n contentBlockDoneAtIndex,\n contentBlockDeltaIndex,\n text: contentBlockText,\n toolUse: deserializeToolUseBlock(contentBlockToolUse),\n stopReason,\n });\n return { next };\n};\nexports.convertItemToConversationStreamEvent = convertItemToConversationStreamEvent;\nconst deserializeToolUseBlock = (contentBlockToolUse) => {\n if (contentBlockToolUse) {\n const toolUseBlock = {\n ...contentBlockToolUse,\n input: JSON.parse(contentBlockToolUse.input),\n };\n return toolUseBlock;\n }\n};\nconst removeNullsFromConversationStreamEvent = (block) => Object.fromEntries(Object.entries(block).filter(([_, v]) => v !== null));\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,oCAAoC,GAAG,KAAK,CAAC,CAAC;AACtD,MAAM,oCAAoC,GAAG,CAAC,EAAE,EAAE,EAAE,cAAc,EAAE,uBAAuB,EAAE,iBAAiB,EAAE,uBAAuB,EAAE,sBAAsB,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,UAAU,EAAE,MAAM,GAAG,KAAK;AAClO,IAAI,IAAI,MAAM,EAAE;AAChB,QAAQ,MAAM,KAAK,GAAG;AACtB,YAAY,EAAE;AACd,YAAY,cAAc;AAC1B,YAAY,uBAAuB;AACnC,YAAY,MAAM;AAClB,SAAS,CAAC;AACV,QAAQ,OAAO,EAAE,KAAK,EAAE,CAAC;AACzB,KAAK;AACL,IAAI,MAAM,IAAI,GAAG,sCAAsC,CAAC;AACxD,QAAQ,EAAE;AACV,QAAQ,cAAc;AACtB,QAAQ,uBAAuB;AAC/B,QAAQ,iBAAiB;AACzB,QAAQ,uBAAuB;AAC/B,QAAQ,sBAAsB;AAC9B,QAAQ,IAAI,EAAE,gBAAgB;AAC9B,QAAQ,OAAO,EAAE,uBAAuB,CAAC,mBAAmB,CAAC;AAC7D,QAAQ,UAAU;AAClB,KAAK,CAAC,CAAC;AACP,IAAI,OAAO,EAAE,IAAI,EAAE,CAAC;AACpB,CAAC,CAAC;AACF,OAAO,CAAC,oCAAoC,GAAG,oCAAoC,CAAC;AACpF,MAAM,uBAAuB,GAAG,CAAC,mBAAmB,KAAK;AACzD,IAAI,IAAI,mBAAmB,EAAE;AAC7B,QAAQ,MAAM,YAAY,GAAG;AAC7B,YAAY,GAAG,mBAAmB;AAClC,YAAY,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,mBAAmB,CAAC,KAAK,CAAC;AACxD,SAAS,CAAC;AACV,QAAQ,OAAO,YAAY,CAAC;AAC5B,KAAK;AACL,CAAC,CAAC;AACF,MAAM,sCAAsC,GAAG,CAAC,KAAK,KAAK,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,KAAK,IAAI,CAAC,CAAC;;"}
@@ -5,7 +5,7 @@
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.convertItemToConversation = void 0;
7
7
  const createListMessagesFunction_1 = require("./createListMessagesFunction");
8
- const createOnMessageFunction_1 = require("./createOnMessageFunction");
8
+ const createOnStreamEventFunction_1 = require("./createOnStreamEventFunction");
9
9
  const createSendMessageFunction_1 = require("./createSendMessageFunction");
10
10
  const convertItemToConversation = (client, modelIntrospection, conversationId, conversationCreatedAt, conversationUpdatedAt, conversationRouteName, conversationMessageModel, getInternals, conversationMetadata, conversationName) => {
11
11
  if (!conversationId) {
@@ -17,7 +17,7 @@ const convertItemToConversation = (client, modelIntrospection, conversationId, c
17
17
  updatedAt: conversationUpdatedAt,
18
18
  metadata: conversationMetadata,
19
19
  name: conversationName,
20
- onMessage: (0, createOnMessageFunction_1.createOnMessageFunction)(client, modelIntrospection, conversationId, conversationRouteName, getInternals),
20
+ onStreamEvent: (0, createOnStreamEventFunction_1.createOnStreamEventFunction)(client, modelIntrospection, conversationId, conversationRouteName, getInternals),
21
21
  sendMessage: (0, createSendMessageFunction_1.createSendMessageFunction)(client, modelIntrospection, conversationId, conversationRouteName, getInternals),
22
22
  listMessages: (0, createListMessagesFunction_1.createListMessagesFunction)(client, modelIntrospection, conversationId, conversationMessageModel, getInternals),
23
23
  };
@@ -1 +1 @@
1
- {"version":3,"file":"convertItemToConversation.js","sources":["../../../../../src/runtime/internals/ai/convertItemToConversation.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.convertItemToConversation = void 0;\nconst createListMessagesFunction_1 = require(\"./createListMessagesFunction\");\nconst createOnMessageFunction_1 = require(\"./createOnMessageFunction\");\nconst createSendMessageFunction_1 = require(\"./createSendMessageFunction\");\nconst convertItemToConversation = (client, modelIntrospection, conversationId, conversationCreatedAt, conversationUpdatedAt, conversationRouteName, conversationMessageModel, getInternals, conversationMetadata, conversationName) => {\n if (!conversationId) {\n throw new Error(`An error occurred converting a ${conversationRouteName} conversation: Missing ID`);\n }\n return {\n id: conversationId,\n createdAt: conversationCreatedAt,\n updatedAt: conversationUpdatedAt,\n metadata: conversationMetadata,\n name: conversationName,\n onMessage: (0, createOnMessageFunction_1.createOnMessageFunction)(client, modelIntrospection, conversationId, conversationRouteName, getInternals),\n sendMessage: (0, createSendMessageFunction_1.createSendMessageFunction)(client, modelIntrospection, conversationId, conversationRouteName, getInternals),\n listMessages: (0, createListMessagesFunction_1.createListMessagesFunction)(client, modelIntrospection, conversationId, conversationMessageModel, getInternals),\n };\n};\nexports.convertItemToConversation = convertItemToConversation;\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,yBAAyB,GAAG,KAAK,CAAC,CAAC;AAC3C,MAAM,4BAA4B,GAAG,OAAO,CAAC,8BAA8B,CAAC,CAAC;AAC7E,MAAM,yBAAyB,GAAG,OAAO,CAAC,2BAA2B,CAAC,CAAC;AACvE,MAAM,2BAA2B,GAAG,OAAO,CAAC,6BAA6B,CAAC,CAAC;AAC3E,MAAM,yBAAyB,GAAG,CAAC,MAAM,EAAE,kBAAkB,EAAE,cAAc,EAAE,qBAAqB,EAAE,qBAAqB,EAAE,qBAAqB,EAAE,wBAAwB,EAAE,YAAY,EAAE,oBAAoB,EAAE,gBAAgB,KAAK;AACvO,IAAI,IAAI,CAAC,cAAc,EAAE;AACzB,QAAQ,MAAM,IAAI,KAAK,CAAC,CAAC,+BAA+B,EAAE,qBAAqB,CAAC,yBAAyB,CAAC,CAAC,CAAC;AAC5G,KAAK;AACL,IAAI,OAAO;AACX,QAAQ,EAAE,EAAE,cAAc;AAC1B,QAAQ,SAAS,EAAE,qBAAqB;AACxC,QAAQ,SAAS,EAAE,qBAAqB;AACxC,QAAQ,QAAQ,EAAE,oBAAoB;AACtC,QAAQ,IAAI,EAAE,gBAAgB;AAC9B,QAAQ,SAAS,EAAE,IAAI,yBAAyB,CAAC,uBAAuB,EAAE,MAAM,EAAE,kBAAkB,EAAE,cAAc,EAAE,qBAAqB,EAAE,YAAY,CAAC;AAC1J,QAAQ,WAAW,EAAE,IAAI,2BAA2B,CAAC,yBAAyB,EAAE,MAAM,EAAE,kBAAkB,EAAE,cAAc,EAAE,qBAAqB,EAAE,YAAY,CAAC;AAChK,QAAQ,YAAY,EAAE,IAAI,4BAA4B,CAAC,0BAA0B,EAAE,MAAM,EAAE,kBAAkB,EAAE,cAAc,EAAE,wBAAwB,EAAE,YAAY,CAAC;AACtK,KAAK,CAAC;AACN,CAAC,CAAC;AACF,OAAO,CAAC,yBAAyB,GAAG,yBAAyB;;"}
1
+ {"version":3,"file":"convertItemToConversation.js","sources":["../../../../../src/runtime/internals/ai/convertItemToConversation.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.convertItemToConversation = void 0;\nconst createListMessagesFunction_1 = require(\"./createListMessagesFunction\");\nconst createOnStreamEventFunction_1 = require(\"./createOnStreamEventFunction\");\nconst createSendMessageFunction_1 = require(\"./createSendMessageFunction\");\nconst convertItemToConversation = (client, modelIntrospection, conversationId, conversationCreatedAt, conversationUpdatedAt, conversationRouteName, conversationMessageModel, getInternals, conversationMetadata, conversationName) => {\n if (!conversationId) {\n throw new Error(`An error occurred converting a ${conversationRouteName} conversation: Missing ID`);\n }\n return {\n id: conversationId,\n createdAt: conversationCreatedAt,\n updatedAt: conversationUpdatedAt,\n metadata: conversationMetadata,\n name: conversationName,\n onStreamEvent: (0, createOnStreamEventFunction_1.createOnStreamEventFunction)(client, modelIntrospection, conversationId, conversationRouteName, getInternals),\n sendMessage: (0, createSendMessageFunction_1.createSendMessageFunction)(client, modelIntrospection, conversationId, conversationRouteName, getInternals),\n listMessages: (0, createListMessagesFunction_1.createListMessagesFunction)(client, modelIntrospection, conversationId, conversationMessageModel, getInternals),\n };\n};\nexports.convertItemToConversation = convertItemToConversation;\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,yBAAyB,GAAG,KAAK,CAAC,CAAC;AAC3C,MAAM,4BAA4B,GAAG,OAAO,CAAC,8BAA8B,CAAC,CAAC;AAC7E,MAAM,6BAA6B,GAAG,OAAO,CAAC,+BAA+B,CAAC,CAAC;AAC/E,MAAM,2BAA2B,GAAG,OAAO,CAAC,6BAA6B,CAAC,CAAC;AAC3E,MAAM,yBAAyB,GAAG,CAAC,MAAM,EAAE,kBAAkB,EAAE,cAAc,EAAE,qBAAqB,EAAE,qBAAqB,EAAE,qBAAqB,EAAE,wBAAwB,EAAE,YAAY,EAAE,oBAAoB,EAAE,gBAAgB,KAAK;AACvO,IAAI,IAAI,CAAC,cAAc,EAAE;AACzB,QAAQ,MAAM,IAAI,KAAK,CAAC,CAAC,+BAA+B,EAAE,qBAAqB,CAAC,yBAAyB,CAAC,CAAC,CAAC;AAC5G,KAAK;AACL,IAAI,OAAO;AACX,QAAQ,EAAE,EAAE,cAAc;AAC1B,QAAQ,SAAS,EAAE,qBAAqB;AACxC,QAAQ,SAAS,EAAE,qBAAqB;AACxC,QAAQ,QAAQ,EAAE,oBAAoB;AACtC,QAAQ,IAAI,EAAE,gBAAgB;AAC9B,QAAQ,aAAa,EAAE,IAAI,6BAA6B,CAAC,2BAA2B,EAAE,MAAM,EAAE,kBAAkB,EAAE,cAAc,EAAE,qBAAqB,EAAE,YAAY,CAAC;AACtK,QAAQ,WAAW,EAAE,IAAI,2BAA2B,CAAC,yBAAyB,EAAE,MAAM,EAAE,kBAAkB,EAAE,cAAc,EAAE,qBAAqB,EAAE,YAAY,CAAC;AAChK,QAAQ,YAAY,EAAE,IAAI,4BAA4B,CAAC,0BAA0B,EAAE,MAAM,EAAE,kBAAkB,EAAE,cAAc,EAAE,wBAAwB,EAAE,YAAY,CAAC;AACtK,KAAK,CAAC;AACN,CAAC,CAAC;AACF,OAAO,CAAC,yBAAyB,GAAG,yBAAyB;;"}
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.convertItemToConversationMessage = void 0;
7
7
  const conversationMessageDeserializers_1 = require("./conversationMessageDeserializers");
8
8
  const convertItemToConversationMessage = ({ content, createdAt, id, conversationId, role, }) => ({
9
- content: (0, conversationMessageDeserializers_1.deserializeContent)(content),
9
+ content: (0, conversationMessageDeserializers_1.deserializeContent)(content ?? []),
10
10
  conversationId,
11
11
  createdAt,
12
12
  id,
@@ -1 +1 @@
1
- {"version":3,"file":"convertItemToConversationMessage.js","sources":["../../../../../src/runtime/internals/ai/convertItemToConversationMessage.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.convertItemToConversationMessage = void 0;\nconst conversationMessageDeserializers_1 = require(\"./conversationMessageDeserializers\");\nconst convertItemToConversationMessage = ({ content, createdAt, id, conversationId, role, }) => ({\n content: (0, conversationMessageDeserializers_1.deserializeContent)(content),\n conversationId,\n createdAt,\n id,\n role,\n});\nexports.convertItemToConversationMessage = convertItemToConversationMessage;\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,gCAAgC,GAAG,KAAK,CAAC,CAAC;AAClD,MAAM,kCAAkC,GAAG,OAAO,CAAC,oCAAoC,CAAC,CAAC;AACzF,MAAM,gCAAgC,GAAG,CAAC,EAAE,OAAO,EAAE,SAAS,EAAE,EAAE,EAAE,cAAc,EAAE,IAAI,GAAG,MAAM;AACjG,IAAI,OAAO,EAAE,IAAI,kCAAkC,CAAC,kBAAkB,EAAE,OAAO,CAAC;AAChF,IAAI,cAAc;AAClB,IAAI,SAAS;AACb,IAAI,EAAE;AACN,IAAI,IAAI;AACR,CAAC,CAAC,CAAC;AACH,OAAO,CAAC,gCAAgC,GAAG,gCAAgC;;"}
1
+ {"version":3,"file":"convertItemToConversationMessage.js","sources":["../../../../../src/runtime/internals/ai/convertItemToConversationMessage.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.convertItemToConversationMessage = void 0;\nconst conversationMessageDeserializers_1 = require(\"./conversationMessageDeserializers\");\nconst convertItemToConversationMessage = ({ content, createdAt, id, conversationId, role, }) => ({\n content: (0, conversationMessageDeserializers_1.deserializeContent)(content ?? []),\n conversationId,\n createdAt,\n id,\n role,\n});\nexports.convertItemToConversationMessage = convertItemToConversationMessage;\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,gCAAgC,GAAG,KAAK,CAAC,CAAC;AAClD,MAAM,kCAAkC,GAAG,OAAO,CAAC,oCAAoC,CAAC,CAAC;AACzF,MAAM,gCAAgC,GAAG,CAAC,EAAE,OAAO,EAAE,SAAS,EAAE,EAAE,EAAE,cAAc,EAAE,IAAI,GAAG,MAAM;AACjG,IAAI,OAAO,EAAE,IAAI,kCAAkC,CAAC,kBAAkB,EAAE,OAAO,IAAI,EAAE,CAAC;AACtF,IAAI,cAAc;AAClB,IAAI,SAAS;AACb,IAAI,EAAE;AACN,IAAI,IAAI;AACR,CAAC,CAAC,CAAC;AACH,OAAO,CAAC,gCAAgC,GAAG,gCAAgC;;"}
@@ -3,21 +3,25 @@
3
3
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
4
4
  // SPDX-License-Identifier: Apache-2.0
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.createOnMessageFunction = void 0;
6
+ exports.createOnStreamEventFunction = void 0;
7
7
  const custom_1 = require("../operations/custom");
8
- const convertItemToConversationMessage_1 = require("./convertItemToConversationMessage");
9
8
  const getCustomUserAgentDetails_1 = require("./getCustomUserAgentDetails");
10
- const createOnMessageFunction = (client, modelIntrospection, conversationId, conversationRouteName, getInternals) => (handler) => {
9
+ const conversationStreamEventDeserializers_1 = require("./conversationStreamEventDeserializers");
10
+ const createOnStreamEventFunction = (client, modelIntrospection, conversationId, conversationRouteName, getInternals) => (handler) => {
11
11
  const { conversations } = modelIntrospection;
12
12
  // Safe guard for standalone function. When called as part of client generation, this should never be falsy.
13
13
  if (!conversations) {
14
14
  return {};
15
15
  }
16
16
  const subscribeSchema = conversations[conversationRouteName].message.subscribe;
17
- const subscribeOperation = (0, custom_1.customOpFactory)(client, modelIntrospection, 'subscription', subscribeSchema, false, getInternals, (0, getCustomUserAgentDetails_1.getCustomUserAgentDetails)(getCustomUserAgentDetails_1.AiAction.OnMessage));
17
+ const subscribeOperation = (0, custom_1.customOpFactory)(client, modelIntrospection, 'subscription', subscribeSchema, false, getInternals, (0, getCustomUserAgentDetails_1.getCustomUserAgentDetails)(getCustomUserAgentDetails_1.AiAction.OnStreamEvent));
18
18
  return subscribeOperation({ conversationId }).subscribe((data) => {
19
- handler((0, convertItemToConversationMessage_1.convertItemToConversationMessage)(data));
19
+ const { next, error } = (0, conversationStreamEventDeserializers_1.convertItemToConversationStreamEvent)(data);
20
+ if (error)
21
+ handler.error(error);
22
+ if (next)
23
+ handler.next(next);
20
24
  });
21
25
  };
22
- exports.createOnMessageFunction = createOnMessageFunction;
23
- //# sourceMappingURL=createOnMessageFunction.js.map
26
+ exports.createOnStreamEventFunction = createOnStreamEventFunction;
27
+ //# sourceMappingURL=createOnStreamEventFunction.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createOnStreamEventFunction.js","sources":["../../../../../src/runtime/internals/ai/createOnStreamEventFunction.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.createOnStreamEventFunction = void 0;\nconst custom_1 = require(\"../operations/custom\");\nconst getCustomUserAgentDetails_1 = require(\"./getCustomUserAgentDetails\");\nconst conversationStreamEventDeserializers_1 = require(\"./conversationStreamEventDeserializers\");\nconst createOnStreamEventFunction = (client, modelIntrospection, conversationId, conversationRouteName, getInternals) => (handler) => {\n const { conversations } = modelIntrospection;\n // Safe guard for standalone function. When called as part of client generation, this should never be falsy.\n if (!conversations) {\n return {};\n }\n const subscribeSchema = conversations[conversationRouteName].message.subscribe;\n const subscribeOperation = (0, custom_1.customOpFactory)(client, modelIntrospection, 'subscription', subscribeSchema, false, getInternals, (0, getCustomUserAgentDetails_1.getCustomUserAgentDetails)(getCustomUserAgentDetails_1.AiAction.OnStreamEvent));\n return subscribeOperation({ conversationId }).subscribe((data) => {\n const { next, error } = (0, conversationStreamEventDeserializers_1.convertItemToConversationStreamEvent)(data);\n if (error)\n handler.error(error);\n if (next)\n handler.next(next);\n });\n};\nexports.createOnStreamEventFunction = createOnStreamEventFunction;\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,2BAA2B,GAAG,KAAK,CAAC,CAAC;AAC7C,MAAM,QAAQ,GAAG,OAAO,CAAC,sBAAsB,CAAC,CAAC;AACjD,MAAM,2BAA2B,GAAG,OAAO,CAAC,6BAA6B,CAAC,CAAC;AAC3E,MAAM,sCAAsC,GAAG,OAAO,CAAC,wCAAwC,CAAC,CAAC;AACjG,MAAM,2BAA2B,GAAG,CAAC,MAAM,EAAE,kBAAkB,EAAE,cAAc,EAAE,qBAAqB,EAAE,YAAY,KAAK,CAAC,OAAO,KAAK;AACtI,IAAI,MAAM,EAAE,aAAa,EAAE,GAAG,kBAAkB,CAAC;AACjD;AACA,IAAI,IAAI,CAAC,aAAa,EAAE;AACxB,QAAQ,OAAO,EAAE,CAAC;AAClB,KAAK;AACL,IAAI,MAAM,eAAe,GAAG,aAAa,CAAC,qBAAqB,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC;AACnF,IAAI,MAAM,kBAAkB,GAAG,IAAI,QAAQ,CAAC,eAAe,EAAE,MAAM,EAAE,kBAAkB,EAAE,cAAc,EAAE,eAAe,EAAE,KAAK,EAAE,YAAY,EAAE,IAAI,2BAA2B,CAAC,yBAAyB,EAAE,2BAA2B,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC,CAAC;AAC/P,IAAI,OAAO,kBAAkB,CAAC,EAAE,cAAc,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,IAAI,KAAK;AACtE,QAAQ,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,IAAI,sCAAsC,CAAC,oCAAoC,EAAE,IAAI,CAAC,CAAC;AACvH,QAAQ,IAAI,KAAK;AACjB,YAAY,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;AACjC,QAAQ,IAAI,IAAI;AAChB,YAAY,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC/B,KAAK,CAAC,CAAC;AACP,CAAC,CAAC;AACF,OAAO,CAAC,2BAA2B,GAAG,2BAA2B;;"}
@@ -21,7 +21,7 @@ var AiAction;
21
21
  AiAction["DeleteConversation"] = "4";
22
22
  AiAction["SendMessage"] = "5";
23
23
  AiAction["ListMessages"] = "6";
24
- AiAction["OnMessage"] = "7";
24
+ AiAction["OnStreamEvent"] = "7";
25
25
  AiAction["Generation"] = "8";
26
26
  AiAction["UpdateConversation"] = "9";
27
27
  })(AiAction || (exports.AiAction = AiAction = {}));
@@ -1 +1 @@
1
- {"version":3,"file":"getCustomUserAgentDetails.js","sources":["../../../../../src/runtime/internals/ai/getCustomUserAgentDetails.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.createUserAgentOverride = exports.getCustomUserAgentDetails = exports.AiAction = exports.INTERNAL_USER_AGENT_OVERRIDE = void 0;\n/**\n * Symbol used for internal user agent overrides.\n *\n * @internal\n * This symbol is intended for internal use within the Amplify library.\n * It may change or be removed in future versions without notice.\n * External usage of this symbol is discouraged and may lead to unexpected behavior.\n */\nexports.INTERNAL_USER_AGENT_OVERRIDE = Symbol('INTERNAL_USER_AGENT_OVERRIDE');\nvar AiAction;\n(function (AiAction) {\n AiAction[\"CreateConversation\"] = \"1\";\n AiAction[\"GetConversation\"] = \"2\";\n AiAction[\"ListConversations\"] = \"3\";\n AiAction[\"DeleteConversation\"] = \"4\";\n AiAction[\"SendMessage\"] = \"5\";\n AiAction[\"ListMessages\"] = \"6\";\n AiAction[\"OnMessage\"] = \"7\";\n AiAction[\"Generation\"] = \"8\";\n AiAction[\"UpdateConversation\"] = \"9\";\n})(AiAction || (exports.AiAction = AiAction = {}));\nconst getCustomUserAgentDetails = (action) => ({\n category: 'ai',\n action,\n});\nexports.getCustomUserAgentDetails = getCustomUserAgentDetails;\n/**\n * Creates a user agent override object based on custom details.\n *\n * @internal\n * This function is intended for internal use within the Amplify library.\n * It may change or be removed in future versions without notice.\n *\n * @param customUserAgentDetails - Optional custom user agent details\n * @returns An object with INTERNAL_USER_AGENT_OVERRIDE symbol as key and customUserAgentDetails as value, or undefined if no details provided\n */\nfunction createUserAgentOverride(customUserAgentDetails) {\n return customUserAgentDetails\n ? { [exports.INTERNAL_USER_AGENT_OVERRIDE]: customUserAgentDetails }\n : undefined;\n}\nexports.createUserAgentOverride = createUserAgentOverride;\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,uBAAuB,GAAG,OAAO,CAAC,yBAAyB,GAAG,OAAO,CAAC,QAAQ,GAAG,OAAO,CAAC,4BAA4B,GAAG,KAAK,CAAC,CAAC;AACvI;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,CAAC,4BAA4B,GAAG,MAAM,CAAC,8BAA8B,CAAC,CAAC;AAC9E,IAAI,QAAQ,CAAC;AACb,CAAC,UAAU,QAAQ,EAAE;AACrB,IAAI,QAAQ,CAAC,oBAAoB,CAAC,GAAG,GAAG,CAAC;AACzC,IAAI,QAAQ,CAAC,iBAAiB,CAAC,GAAG,GAAG,CAAC;AACtC,IAAI,QAAQ,CAAC,mBAAmB,CAAC,GAAG,GAAG,CAAC;AACxC,IAAI,QAAQ,CAAC,oBAAoB,CAAC,GAAG,GAAG,CAAC;AACzC,IAAI,QAAQ,CAAC,aAAa,CAAC,GAAG,GAAG,CAAC;AAClC,IAAI,QAAQ,CAAC,cAAc,CAAC,GAAG,GAAG,CAAC;AACnC,IAAI,QAAQ,CAAC,WAAW,CAAC,GAAG,GAAG,CAAC;AAChC,IAAI,QAAQ,CAAC,YAAY,CAAC,GAAG,GAAG,CAAC;AACjC,IAAI,QAAQ,CAAC,oBAAoB,CAAC,GAAG,GAAG,CAAC;AACzC,CAAC,EAAE,QAAQ,KAAK,OAAO,CAAC,QAAQ,GAAG,QAAQ,GAAG,EAAE,CAAC,CAAC,CAAC;AACnD,MAAM,yBAAyB,GAAG,CAAC,MAAM,MAAM;AAC/C,IAAI,QAAQ,EAAE,IAAI;AAClB,IAAI,MAAM;AACV,CAAC,CAAC,CAAC;AACH,OAAO,CAAC,yBAAyB,GAAG,yBAAyB,CAAC;AAC9D;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS,uBAAuB,CAAC,sBAAsB,EAAE;AACzD,IAAI,OAAO,sBAAsB;AACjC,UAAU,EAAE,CAAC,OAAO,CAAC,4BAA4B,GAAG,sBAAsB,EAAE;AAC5E,UAAU,SAAS,CAAC;AACpB,CAAC;AACD,OAAO,CAAC,uBAAuB,GAAG,uBAAuB;;"}
1
+ {"version":3,"file":"getCustomUserAgentDetails.js","sources":["../../../../../src/runtime/internals/ai/getCustomUserAgentDetails.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.createUserAgentOverride = exports.getCustomUserAgentDetails = exports.AiAction = exports.INTERNAL_USER_AGENT_OVERRIDE = void 0;\n/**\n * Symbol used for internal user agent overrides.\n *\n * @internal\n * This symbol is intended for internal use within the Amplify library.\n * It may change or be removed in future versions without notice.\n * External usage of this symbol is discouraged and may lead to unexpected behavior.\n */\nexports.INTERNAL_USER_AGENT_OVERRIDE = Symbol('INTERNAL_USER_AGENT_OVERRIDE');\nvar AiAction;\n(function (AiAction) {\n AiAction[\"CreateConversation\"] = \"1\";\n AiAction[\"GetConversation\"] = \"2\";\n AiAction[\"ListConversations\"] = \"3\";\n AiAction[\"DeleteConversation\"] = \"4\";\n AiAction[\"SendMessage\"] = \"5\";\n AiAction[\"ListMessages\"] = \"6\";\n AiAction[\"OnStreamEvent\"] = \"7\";\n AiAction[\"Generation\"] = \"8\";\n AiAction[\"UpdateConversation\"] = \"9\";\n})(AiAction || (exports.AiAction = AiAction = {}));\nconst getCustomUserAgentDetails = (action) => ({\n category: 'ai',\n action,\n});\nexports.getCustomUserAgentDetails = getCustomUserAgentDetails;\n/**\n * Creates a user agent override object based on custom details.\n *\n * @internal\n * This function is intended for internal use within the Amplify library.\n * It may change or be removed in future versions without notice.\n *\n * @param customUserAgentDetails - Optional custom user agent details\n * @returns An object with INTERNAL_USER_AGENT_OVERRIDE symbol as key and customUserAgentDetails as value, or undefined if no details provided\n */\nfunction createUserAgentOverride(customUserAgentDetails) {\n return customUserAgentDetails\n ? { [exports.INTERNAL_USER_AGENT_OVERRIDE]: customUserAgentDetails }\n : undefined;\n}\nexports.createUserAgentOverride = createUserAgentOverride;\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,uBAAuB,GAAG,OAAO,CAAC,yBAAyB,GAAG,OAAO,CAAC,QAAQ,GAAG,OAAO,CAAC,4BAA4B,GAAG,KAAK,CAAC,CAAC;AACvI;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,CAAC,4BAA4B,GAAG,MAAM,CAAC,8BAA8B,CAAC,CAAC;AAC9E,IAAI,QAAQ,CAAC;AACb,CAAC,UAAU,QAAQ,EAAE;AACrB,IAAI,QAAQ,CAAC,oBAAoB,CAAC,GAAG,GAAG,CAAC;AACzC,IAAI,QAAQ,CAAC,iBAAiB,CAAC,GAAG,GAAG,CAAC;AACtC,IAAI,QAAQ,CAAC,mBAAmB,CAAC,GAAG,GAAG,CAAC;AACxC,IAAI,QAAQ,CAAC,oBAAoB,CAAC,GAAG,GAAG,CAAC;AACzC,IAAI,QAAQ,CAAC,aAAa,CAAC,GAAG,GAAG,CAAC;AAClC,IAAI,QAAQ,CAAC,cAAc,CAAC,GAAG,GAAG,CAAC;AACnC,IAAI,QAAQ,CAAC,eAAe,CAAC,GAAG,GAAG,CAAC;AACpC,IAAI,QAAQ,CAAC,YAAY,CAAC,GAAG,GAAG,CAAC;AACjC,IAAI,QAAQ,CAAC,oBAAoB,CAAC,GAAG,GAAG,CAAC;AACzC,CAAC,EAAE,QAAQ,KAAK,OAAO,CAAC,QAAQ,GAAG,QAAQ,GAAG,EAAE,CAAC,CAAC,CAAC;AACnD,MAAM,yBAAyB,GAAG,CAAC,MAAM,MAAM;AAC/C,IAAI,QAAQ,EAAE,IAAI;AAClB,IAAI,MAAM;AACV,CAAC,CAAC,CAAC;AACH,OAAO,CAAC,yBAAyB,GAAG,yBAAyB,CAAC;AAC9D;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS,uBAAuB,CAAC,sBAAsB,EAAE;AACzD,IAAI,OAAO,sBAAsB;AACjC,UAAU,EAAE,CAAC,OAAO,CAAC,4BAA4B,GAAG,sBAAsB,EAAE;AAC5E,UAAU,SAAS,CAAC;AACpB,CAAC;AACD,OAAO,CAAC,uBAAuB,GAAG,uBAAuB;;"}
@@ -1,7 +1,8 @@
1
- import type { Conversation, ConversationMessage } from '../../ai/ConversationType';
1
+ import type { Conversation, ConversationMessage, ConversationStreamEvent } from '../../ai/ConversationType';
2
2
  import type { ClientSchemaProperty } from '../Core';
3
3
  export interface ClientConversation extends Pick<ClientSchemaProperty, '__entityType'> {
4
4
  __entityType: 'customConversation';
5
5
  type: Conversation;
6
6
  messageType: ConversationMessage;
7
+ streamEventType: ConversationStreamEvent;
7
8
  }
@@ -180,6 +180,23 @@ const ToolSpecification = `type ToolSpecification {
180
180
  const ToolInputSchema = `type ToolInputSchema {
181
181
  json: AWSJSON
182
182
  }`;
183
+ const ConversationMessageStreamEvent = `type ConversationMessageStreamPart @aws_cognito_user_pools {
184
+ id: ID!
185
+ owner: String
186
+ conversationId: ID!
187
+ associatedUserMessageId: ID!
188
+ contentBlockIndex: Int!
189
+ contentBlockText: String
190
+ contentBlockDeltaIndex: Int
191
+ contentBlockToolUse: ToolUseBlock
192
+ contentBlockDoneAtIndex: Int
193
+ stopReason: String
194
+ errors: [ConversationTurnError]
195
+ }`;
196
+ const ConversationTurnError = `type ConversationTurnError @aws_cognito_user_pools {
197
+ message: String!
198
+ errorType: String!
199
+ }`;
183
200
  const conversationTypes = [
184
201
  ConversationParticipantRole,
185
202
  ConversationMessage,
@@ -212,6 +229,8 @@ const conversationTypes = [
212
229
  Tool,
213
230
  ToolSpecification,
214
231
  ToolInputSchema,
232
+ ConversationMessageStreamEvent,
233
+ ConversationTurnError,
215
234
  ];
216
235
 
217
236
  export { conversationTypes, createConversationField };
@@ -1 +1 @@
1
- {"version":3,"file":"ConversationSchemaTypes.mjs","sources":["../../../src/ai/ConversationSchemaTypes.ts"],"sourcesContent":["import { capitalize } from '../runtime/utils';\nexport const createConversationField = (typeDef, typeName) => {\n const { aiModel, systemPrompt, handler, tools } = typeDef;\n const args = {\n aiModel: aiModel.resourcePath,\n // This is done to escape newlines in potentially multi-line system prompts\n // e.g.\n // realtorChat: a.conversation({\n // aiModel: a.ai.model('Claude 3 Haiku'),\n // systemPrompt: `You are a helpful real estate assistant\n // Respond in the poetic form of haiku.`,\n // }),\n //\n // It doesn't affect non multi-line string inputs for system prompts\n systemPrompt: systemPrompt.replace(/\\r?\\n/g, '\\\\n'),\n };\n const argsString = Object.entries(args)\n .map(([key, value]) => `${key}: \"${value}\"`)\n .join(', ');\n const functionHandler = {};\n let handlerString = '';\n if (handler) {\n const functionName = `Fn${capitalize(typeName)}`;\n const eventVersion = handler.eventVersion;\n handlerString = `, handler: { functionName: \"${functionName}\", eventVersion: \"${eventVersion}\" }`;\n functionHandler[functionName] = handler;\n }\n const toolsString = tools?.length\n ? `, tools: [${getConversationToolsString(tools)}]`\n : '';\n const conversationDirective = `@conversation(${argsString}${handlerString}${toolsString})`;\n const field = `${typeName}(conversationId: ID!, content: [ContentBlockInput], aiContext: AWSJSON, toolConfiguration: ToolConfigurationInput): ConversationMessage ${conversationDirective} @aws_cognito_user_pools`;\n return { field, functionHandler };\n};\nconst isRef = (query) => query?.data?.type === 'ref';\nconst getConversationToolsString = (tools) => tools\n .map((tool) => {\n const { query, description } = tool;\n if (!isRef(query)) {\n throw new Error(`Unexpected query was found in tool ${tool}.`);\n }\n // TODO: add validation for query / auth (cup) / etc\n const queryName = query.data.link;\n return `{ name: \"${queryName}\", description: \"${description}\" }`;\n})\n .join(', ');\nconst ConversationParticipantRole = `enum ConversationParticipantRole {\n user\n assistant\n}`;\nconst ConversationMessage = `interface ConversationMessage {\n id: ID!\n conversationId: ID!\n role: ConversationParticipantRole\n content: [ContentBlock]\n aiContext: AWSJSON\n toolConfiguration: ToolConfiguration\n createdAt: AWSDateTime\n updatedAt: AWSDateTime\n owner: String\n}`;\nconst DocumentBlockSourceInput = `input DocumentBlockSourceInput {\n bytes: String\n}`;\nconst DocumentBlockInput = `input DocumentBlockInput {\n format: String!\n name: String!\n source: DocumentBlockSourceInput!\n}`;\nconst ImageBlockSourceInput = `input ImageBlockSourceInput {\n bytes: String\n}`;\nconst ImageBlockInput = `input ImageBlockInput {\n format: String!\n source: ImageBlockSourceInput!\n}`;\nconst ToolResultContentBlockInput = `input ToolResultContentBlockInput {\n document: DocumentBlockInput\n image: ImageBlockInput\n json: AWSJSON\n text: String\n}`;\nconst ToolResultBlockInput = `input ToolResultBlockInput {\n content: [ToolResultContentBlockInput!]!\n toolUseId: String!\n status: String\n}`;\nconst DocumentBlockSource = `type DocumentBlockSource {\n bytes: String\n}\n`;\nconst DocumentBlock = `type DocumentBlock {\n format: String!\n name: String!\n source: DocumentBlockSource!\n}`;\nconst ImageBlock = `type ImageBlock {\n format: String!\n source: ImageBlockSource!\n}`;\nconst ImageBlockSource = `type ImageBlockSource {\n bytes: String\n}`;\nconst ToolUseBlockInput = `input ToolUseBlockInput {\n toolUseId: String!\n name: String!\n input: AWSJSON!\n}`;\nconst ToolUseBlock = `type ToolUseBlock {\n toolUseId: String!\n name: String!\n input: AWSJSON!\n}`;\nconst ToolResultContentBlock = `type ToolResultContentBlock {\n document: DocumentBlock\n image: ImageBlock\n json: AWSJSON\n text: String\n}`;\nconst ToolResultBlock = `type ToolResultBlock {\n content: [ToolResultContentBlock!]!\n toolUseId: String!\n status: String\n}`;\nconst ContentBlockText = `type ContentBlockText {\n text: String\n}`;\nconst ContentBlockImage = `type ContentBlockImage {\n image: ImageBlock\n}`;\nconst ContentBlockDocument = `type ContentBlockDocument {\n document: DocumentBlock\n}`;\nconst ContentBlockToolUse = `type ContentBlockToolUse {\n toolUse: ToolUseBlock\n}`;\nconst ContentBlockToolResult = `type ContentBlockToolResult {\n toolResult: ToolResultBlock\n}`;\nconst ContentBlockInput = `input ContentBlockInput {\n text: String\n document: DocumentBlockInput\n image: ImageBlockInput\n toolResult: ToolResultBlockInput\n toolUse: ToolUseBlockInput\n}`;\nconst ContentBlock = `type ContentBlock {\n text: String\n document: DocumentBlock\n image: ImageBlock\n toolResult: ToolResultBlock\n toolUse: ToolUseBlock\n}`;\nconst ToolConfigurationInput = `input ToolConfigurationInput {\n tools: [ToolInput]\n}`;\nconst ToolInput = `input ToolInput {\n toolSpec: ToolSpecificationInput\n}`;\nconst ToolSpecificationInput = `input ToolSpecificationInput {\n name: String!\n description: String\n inputSchema: ToolInputSchemaInput!\n}`;\nconst ToolInputSchemaInput = `input ToolInputSchemaInput {\n json: AWSJSON\n}`;\nconst ToolConfiguration = `type ToolConfiguration {\n tools: [Tool]\n}`;\nconst Tool = `type Tool {\n toolSpec: ToolSpecification\n}`;\nconst ToolSpecification = `type ToolSpecification {\n name: String!\n description: String\n inputSchema: ToolInputSchema!\n}`;\nconst ToolInputSchema = `type ToolInputSchema {\n json: AWSJSON\n}`;\nexport const conversationTypes = [\n ConversationParticipantRole,\n ConversationMessage,\n DocumentBlockSourceInput,\n DocumentBlockInput,\n ImageBlockSourceInput,\n ImageBlockInput,\n ToolUseBlockInput,\n ToolResultContentBlockInput,\n ToolResultBlockInput,\n DocumentBlockSource,\n DocumentBlock,\n ImageBlock,\n ImageBlockSource,\n ToolUseBlock,\n ToolResultContentBlock,\n ToolResultBlock,\n ContentBlockText,\n ContentBlockImage,\n ContentBlockDocument,\n ContentBlockToolUse,\n ContentBlockToolResult,\n ContentBlockInput,\n ContentBlock,\n ToolConfigurationInput,\n ToolInput,\n ToolSpecificationInput,\n ToolInputSchemaInput,\n ToolConfiguration,\n Tool,\n ToolSpecification,\n ToolInputSchema,\n];\n"],"names":[],"mappings":";;AACY,MAAC,uBAAuB,GAAG,CAAC,OAAO,EAAE,QAAQ,KAAK;AAC9D,IAAI,MAAM,EAAE,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,KAAK,EAAE,GAAG,OAAO,CAAC;AAC9D,IAAI,MAAM,IAAI,GAAG;AACjB,QAAQ,OAAO,EAAE,OAAO,CAAC,YAAY;AACrC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,QAAQ,YAAY,EAAE,YAAY,CAAC,OAAO,CAAC,QAAQ,EAAE,KAAK,CAAC;AAC3D,KAAK,CAAC;AACN,IAAI,MAAM,UAAU,GAAG,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC;AAC3C,SAAS,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,KAAK,CAAC,EAAE,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC;AACpD,SAAS,IAAI,CAAC,IAAI,CAAC,CAAC;AACpB,IAAI,MAAM,eAAe,GAAG,EAAE,CAAC;AAC/B,IAAI,IAAI,aAAa,GAAG,EAAE,CAAC;AAC3B,IAAI,IAAI,OAAO,EAAE;AACjB,QAAQ,MAAM,YAAY,GAAG,CAAC,EAAE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YAAY;AAChB,IAAI,sBAAsB;AAC1B,IAAI,eAAe;AACnB,IAAI,gBAAgB;AACpB,IAAI,iBAAiB;AACrB,IAAI,oBAAoB;AACxB,IAAI,mBAAmB;AACvB,IAAI,sBAAsB;AAC1B,IAAI,iBAAiB;AACrB,IAAI,YAAY;AAChB,IAAI,sBAAsB;AAC1B,IAAI,SAAS;AACb,IAAI,sBAAsB;AAC1B,IAAI,oBAAoB;AACxB,IAAI,iBAAiB;AACrB,IAAI,IAAI;AACR,IAAI,iBAAiB;AACrB,IAAI,eAAe;AACnB;;;;"}
1
+ {"version":3,"file":"ConversationSchemaTypes.mjs","sources":["../../../src/ai/ConversationSchemaTypes.ts"],"sourcesContent":["import { capitalize } from '../runtime/utils';\nexport const createConversationField = (typeDef, typeName) => {\n const { aiModel, systemPrompt, handler, tools } = typeDef;\n const args = {\n aiModel: aiModel.resourcePath,\n // This is done to escape newlines in potentially multi-line system prompts\n // e.g.\n // realtorChat: a.conversation({\n // aiModel: a.ai.model('Claude 3 Haiku'),\n // systemPrompt: `You are a helpful real estate assistant\n // Respond in the poetic form of haiku.`,\n // }),\n //\n // It doesn't affect non multi-line string inputs for system prompts\n systemPrompt: systemPrompt.replace(/\\r?\\n/g, '\\\\n'),\n };\n const argsString = Object.entries(args)\n .map(([key, value]) => `${key}: \"${value}\"`)\n .join(', ');\n const functionHandler = {};\n let handlerString = '';\n if (handler) {\n const functionName = `Fn${capitalize(typeName)}`;\n const eventVersion = handler.eventVersion;\n handlerString = `, handler: { functionName: \"${functionName}\", eventVersion: \"${eventVersion}\" }`;\n functionHandler[functionName] = handler;\n }\n const toolsString = tools?.length\n ? `, tools: [${getConversationToolsString(tools)}]`\n : '';\n const conversationDirective = `@conversation(${argsString}${handlerString}${toolsString})`;\n const field = `${typeName}(conversationId: ID!, content: [ContentBlockInput], aiContext: AWSJSON, toolConfiguration: ToolConfigurationInput): ConversationMessage ${conversationDirective} @aws_cognito_user_pools`;\n return { field, functionHandler };\n};\nconst isRef = (query) => query?.data?.type === 'ref';\nconst getConversationToolsString = (tools) => tools\n .map((tool) => {\n const { query, description } = tool;\n if (!isRef(query)) {\n throw new Error(`Unexpected query was found in tool ${tool}.`);\n }\n // TODO: add validation for query / auth (cup) / etc\n const queryName = query.data.link;\n return `{ name: \"${queryName}\", description: \"${description}\" }`;\n})\n .join(', ');\nconst ConversationParticipantRole = `enum ConversationParticipantRole {\n user\n assistant\n}`;\nconst ConversationMessage = `interface ConversationMessage {\n id: ID!\n conversationId: ID!\n role: ConversationParticipantRole\n content: [ContentBlock]\n aiContext: AWSJSON\n toolConfiguration: ToolConfiguration\n createdAt: AWSDateTime\n updatedAt: AWSDateTime\n owner: String\n}`;\nconst DocumentBlockSourceInput = `input DocumentBlockSourceInput {\n bytes: String\n}`;\nconst DocumentBlockInput = `input DocumentBlockInput {\n format: String!\n name: String!\n source: DocumentBlockSourceInput!\n}`;\nconst ImageBlockSourceInput = `input ImageBlockSourceInput {\n bytes: String\n}`;\nconst ImageBlockInput = `input ImageBlockInput {\n format: String!\n source: ImageBlockSourceInput!\n}`;\nconst ToolResultContentBlockInput = `input ToolResultContentBlockInput {\n document: DocumentBlockInput\n image: ImageBlockInput\n json: AWSJSON\n text: String\n}`;\nconst ToolResultBlockInput = `input ToolResultBlockInput {\n content: [ToolResultContentBlockInput!]!\n toolUseId: String!\n status: String\n}`;\nconst DocumentBlockSource = `type DocumentBlockSource {\n bytes: String\n}\n`;\nconst DocumentBlock = `type DocumentBlock {\n format: String!\n name: String!\n source: DocumentBlockSource!\n}`;\nconst ImageBlock = `type ImageBlock {\n format: String!\n source: ImageBlockSource!\n}`;\nconst ImageBlockSource = `type ImageBlockSource {\n bytes: String\n}`;\nconst ToolUseBlockInput = `input ToolUseBlockInput {\n toolUseId: String!\n name: String!\n input: AWSJSON!\n}`;\nconst ToolUseBlock = `type ToolUseBlock {\n toolUseId: String!\n name: String!\n input: AWSJSON!\n}`;\nconst ToolResultContentBlock = `type ToolResultContentBlock {\n document: DocumentBlock\n image: ImageBlock\n json: AWSJSON\n text: String\n}`;\nconst ToolResultBlock = `type ToolResultBlock {\n content: [ToolResultContentBlock!]!\n toolUseId: String!\n status: String\n}`;\nconst ContentBlockText = `type ContentBlockText {\n text: String\n}`;\nconst ContentBlockImage = `type ContentBlockImage {\n image: ImageBlock\n}`;\nconst ContentBlockDocument = `type ContentBlockDocument {\n document: DocumentBlock\n}`;\nconst ContentBlockToolUse = `type ContentBlockToolUse {\n toolUse: ToolUseBlock\n}`;\nconst ContentBlockToolResult = `type ContentBlockToolResult {\n toolResult: ToolResultBlock\n}`;\nconst ContentBlockInput = `input ContentBlockInput {\n text: String\n document: DocumentBlockInput\n image: ImageBlockInput\n toolResult: ToolResultBlockInput\n toolUse: ToolUseBlockInput\n}`;\nconst ContentBlock = `type ContentBlock {\n text: String\n document: DocumentBlock\n image: ImageBlock\n toolResult: ToolResultBlock\n toolUse: ToolUseBlock\n}`;\nconst ToolConfigurationInput = `input ToolConfigurationInput {\n tools: [ToolInput]\n}`;\nconst ToolInput = `input ToolInput {\n toolSpec: ToolSpecificationInput\n}`;\nconst ToolSpecificationInput = `input ToolSpecificationInput {\n name: String!\n description: String\n inputSchema: ToolInputSchemaInput!\n}`;\nconst ToolInputSchemaInput = `input ToolInputSchemaInput {\n json: AWSJSON\n}`;\nconst ToolConfiguration = `type ToolConfiguration {\n tools: [Tool]\n}`;\nconst Tool = `type Tool {\n toolSpec: ToolSpecification\n}`;\nconst ToolSpecification = `type ToolSpecification {\n name: String!\n description: String\n inputSchema: ToolInputSchema!\n}`;\nconst ToolInputSchema = `type ToolInputSchema {\n json: AWSJSON\n}`;\nconst ConversationMessageStreamEvent = `type ConversationMessageStreamPart @aws_cognito_user_pools {\n id: ID!\n owner: String\n conversationId: ID!\n associatedUserMessageId: ID!\n contentBlockIndex: Int!\n contentBlockText: String\n contentBlockDeltaIndex: Int\n contentBlockToolUse: ToolUseBlock\n contentBlockDoneAtIndex: Int\n stopReason: String\n errors: [ConversationTurnError]\n}`;\nconst ConversationTurnError = `type ConversationTurnError @aws_cognito_user_pools {\n message: String!\n errorType: String!\n}`;\nexport const conversationTypes = [\n ConversationParticipantRole,\n ConversationMessage,\n DocumentBlockSourceInput,\n DocumentBlockInput,\n ImageBlockSourceInput,\n ImageBlockInput,\n ToolUseBlockInput,\n ToolResultContentBlockInput,\n ToolResultBlockInput,\n DocumentBlockSource,\n DocumentBlock,\n ImageBlock,\n ImageBlockSource,\n ToolUseBlock,\n ToolResultContentBlock,\n ToolResultBlock,\n ContentBlockText,\n ContentBlockImage,\n ContentBlockDocument,\n ContentBlockToolUse,\n ContentBlockToolResult,\n ContentBlockInput,\n ContentBlock,\n ToolConfigurationInput,\n ToolInput,\n ToolSpecificationInput,\n ToolInputSchemaInput,\n ToolConfiguration,\n Tool,\n ToolSpecification,\n ToolInputSchema,\n ConversationMessageStreamEvent,\n ConversationTurnError,\n];\n"],"names":[],"mappings":";;AACY,MAAC,uBAAuB,GAAG,CAAC,OAAO,EAAE,QAAQ,KAAK;AAC9D,IAAI,MAAM,EAAE,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,KAAK,EAAE,GAAG,OAAO,CAAC;AAC9D,IAAI,MAAM,IAAI,GAAG;AACjB,QAAQ,OAAO,EAAE,OAAO,CAAC,YAAY;AACrC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,QAAQ,YAAY,EAAE,YAAY,CAAC,OAAO,CAAC,QAAQ,EAAE,KAAK,CAAC;AAC3D,KAAK,CAAC;AACN,IAAI,MAAM,UAAU,GAAG,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC;AAC3C,SAAS,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,KAAK,CAAC,EAAE,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC;AACpD,SAAS,IAAI,CAAC,IAAI,CAAC,CAAC;AACpB,IAAI,MAAM,eAAe,GAAG,EAAE,CAAC;AAC/B,IAAI,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AAG;AACjC,IAAI,2BAA2B;AAC/B,IAAI,mBAAmB;AACvB,IAAI,wBAAwB;AAC5B,IAAI,kBAAkB;AACtB,IAAI,qBAAqB;AACzB,IAAI,eAAe;AACnB,IAAI,iBAAiB;AACrB,IAAI,2BAA2B;AAC/B,IAAI,oBAAoB;AACxB,IAAI,mBAAmB;AACvB,IAAI,aAAa;AACjB,IAAI,UAAU;AACd,IAAI,gBAAgB;AACpB,IAAI,YAAY;AAChB,IAAI,sBAAsB;AAC1B,IAAI,eAAe;AACnB,IAAI,gBAAgB;AACpB,IAAI,iBAAiB;AACrB,IAAI,oBAAoB;AACxB,IAAI,mBAAmB;AACvB,IAAI,sBAAsB;AAC1B,IAAI,iBAAiB;AACrB,IAAI,YAAY;AAChB,IAAI,sBAAsB;AAC1B,IAAI,SAAS;AACb,IAAI,sBAAsB;AAC1B,IAAI,oBAAoB;AACxB,IAAI,iBAAiB;AACrB,IAAI,IAAI;AACR,IAAI,iBAAiB;AACrB,IAAI,eAAe;AACnB,IAAI,8BAA8B;AAClC,IAAI,qBAAqB;AACzB;;;;"}
@@ -6,6 +6,7 @@ import { InferenceConfiguration } from './ModelType';
6
6
  import { ConversationMessageContent, ConversationSendMessageInputContent } from './types/ConversationMessageContent';
7
7
  import { ToolConfiguration } from './types/ToolConfiguration';
8
8
  import { AiModel } from '@aws-amplify/data-schema-types';
9
+ import { ConversationStreamErrorEvent, ConversationStreamEvent } from './types/ConversationStreamEvent';
9
10
  export declare const brandName = "conversationCustomOperation";
10
11
  export interface ConversationMessage {
11
12
  content: ConversationMessageContent[];
@@ -13,6 +14,7 @@ export interface ConversationMessage {
13
14
  createdAt: string;
14
15
  id: string;
15
16
  role: 'user' | 'assistant';
17
+ associatedUserMessageId?: string;
16
18
  }
17
19
  interface ConversationRouteGetInput {
18
20
  id: string;
@@ -75,7 +77,10 @@ interface ConversationListMessagesInput {
75
77
  limit?: number;
76
78
  nextToken?: string | null;
77
79
  }
78
- type ConversationOnMessageHandler = (message: ConversationMessage) => void;
80
+ type ConversationOnStreamEventHandler = {
81
+ next: (event: ConversationStreamEvent) => void;
82
+ error: (error: ConversationStreamErrorEvent) => void;
83
+ };
79
84
  export interface Conversation {
80
85
  id: string;
81
86
  createdAt: string;
@@ -97,9 +102,9 @@ export interface Conversation {
97
102
  /**
98
103
  * @experimental
99
104
  *
100
- * Subscribes to new messages on the current conversation.
105
+ * Subscribes to new stream events on the current conversation.
101
106
  */
102
- onMessage: (handler: ConversationOnMessageHandler) => Subscription;
107
+ onStreamEvent: (handler: ConversationOnStreamEventHandler) => Subscription;
103
108
  }
104
109
  export interface ToolDefinition {
105
110
  query: RefType<any>;
@@ -133,4 +138,4 @@ export interface ConversationType extends Brand<typeof brandName> {
133
138
  * @returns a conversation route definition
134
139
  */
135
140
  export declare function conversation(input: ConversationInput): ConversationType;
136
- export {};
141
+ export { ConversationStreamEvent };
@@ -0,0 +1,56 @@
1
+ import { ToolUseBlock } from "./contentBlocks";
2
+ export interface ConversationStreamTextEvent {
3
+ id: string;
4
+ conversationId: string;
5
+ associatedUserMessageId: string;
6
+ contentBlockIndex: number;
7
+ contentBlockDeltaIndex: number;
8
+ contentBlockDoneAtIndex?: never;
9
+ text: string;
10
+ toolUse?: never;
11
+ stopReason?: never;
12
+ }
13
+ export interface ConversationStreamToolUseEvent {
14
+ id: string;
15
+ conversationId: string;
16
+ associatedUserMessageId: string;
17
+ contentBlockIndex: number;
18
+ contentBlockDeltaIndex?: never;
19
+ contentBlockDoneAtIndex?: never;
20
+ text?: never;
21
+ toolUse: ToolUseBlock;
22
+ stopReason?: never;
23
+ }
24
+ export interface ConversationStreamDoneAtIndexEvent {
25
+ id: string;
26
+ conversationId: string;
27
+ associatedUserMessageId: string;
28
+ contentBlockIndex: number;
29
+ contentBlockDoneAtIndex: number;
30
+ contentBlockDeltaIndex?: never;
31
+ text?: never;
32
+ toolUse?: never;
33
+ stopReason?: never;
34
+ }
35
+ export interface ConversationStreamTurnDoneEvent {
36
+ id: string;
37
+ conversationId: string;
38
+ associatedUserMessageId: string;
39
+ contentBlockIndex: number;
40
+ contentBlockDoneAtIndex?: never;
41
+ contentBlockDeltaIndex?: never;
42
+ text?: never;
43
+ toolUse?: never;
44
+ stopReason: string;
45
+ }
46
+ export interface ConversationStreamErrorEvent {
47
+ id: string;
48
+ conversationId: string;
49
+ associatedUserMessageId: string;
50
+ errors: ConversationTurnError[];
51
+ }
52
+ export interface ConversationTurnError {
53
+ message: string;
54
+ errorType: string;
55
+ }
56
+ export type ConversationStreamEvent = ConversationStreamTextEvent | ConversationStreamToolUseEvent | ConversationStreamDoneAtIndexEvent | ConversationStreamTurnDoneEvent;
@@ -0,0 +1,2 @@
1
+
2
+ //# sourceMappingURL=ConversationStreamEvent.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ConversationStreamEvent.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":""}
@@ -0,0 +1,6 @@
1
+ import { ConversationStreamEvent } from "../../../ai/ConversationType";
2
+ import { ConversationStreamErrorEvent } from "../../../ai/types/ConversationStreamEvent";
3
+ export declare const convertItemToConversationStreamEvent: ({ id, conversationId, associatedUserMessageId, contentBlockIndex, contentBlockDoneAtIndex, contentBlockDeltaIndex, contentBlockText, contentBlockToolUse, stopReason, errors, }: any) => {
4
+ next?: ConversationStreamEvent;
5
+ error?: ConversationStreamErrorEvent;
6
+ };
@@ -0,0 +1,38 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ const convertItemToConversationStreamEvent = ({ id, conversationId, associatedUserMessageId, contentBlockIndex, contentBlockDoneAtIndex, contentBlockDeltaIndex, contentBlockText, contentBlockToolUse, stopReason, errors, }) => {
4
+ if (errors) {
5
+ const error = {
6
+ id,
7
+ conversationId,
8
+ associatedUserMessageId,
9
+ errors,
10
+ };
11
+ return { error };
12
+ }
13
+ const next = removeNullsFromConversationStreamEvent({
14
+ id,
15
+ conversationId,
16
+ associatedUserMessageId,
17
+ contentBlockIndex,
18
+ contentBlockDoneAtIndex,
19
+ contentBlockDeltaIndex,
20
+ text: contentBlockText,
21
+ toolUse: deserializeToolUseBlock(contentBlockToolUse),
22
+ stopReason,
23
+ });
24
+ return { next };
25
+ };
26
+ const deserializeToolUseBlock = (contentBlockToolUse) => {
27
+ if (contentBlockToolUse) {
28
+ const toolUseBlock = {
29
+ ...contentBlockToolUse,
30
+ input: JSON.parse(contentBlockToolUse.input),
31
+ };
32
+ return toolUseBlock;
33
+ }
34
+ };
35
+ const removeNullsFromConversationStreamEvent = (block) => Object.fromEntries(Object.entries(block).filter(([_, v]) => v !== null));
36
+
37
+ export { convertItemToConversationStreamEvent };
38
+ //# sourceMappingURL=conversationStreamEventDeserializers.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"conversationStreamEventDeserializers.mjs","sources":["../../../../../src/runtime/internals/ai/conversationStreamEventDeserializers.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nexport const convertItemToConversationStreamEvent = ({ id, conversationId, associatedUserMessageId, contentBlockIndex, contentBlockDoneAtIndex, contentBlockDeltaIndex, contentBlockText, contentBlockToolUse, stopReason, errors, }) => {\n if (errors) {\n const error = {\n id,\n conversationId,\n associatedUserMessageId,\n errors,\n };\n return { error };\n }\n const next = removeNullsFromConversationStreamEvent({\n id,\n conversationId,\n associatedUserMessageId,\n contentBlockIndex,\n contentBlockDoneAtIndex,\n contentBlockDeltaIndex,\n text: contentBlockText,\n toolUse: deserializeToolUseBlock(contentBlockToolUse),\n stopReason,\n });\n return { next };\n};\nconst deserializeToolUseBlock = (contentBlockToolUse) => {\n if (contentBlockToolUse) {\n const toolUseBlock = {\n ...contentBlockToolUse,\n input: JSON.parse(contentBlockToolUse.input),\n };\n return toolUseBlock;\n }\n};\nconst removeNullsFromConversationStreamEvent = (block) => Object.fromEntries(Object.entries(block).filter(([_, v]) => v !== null));\n"],"names":[],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I,CAAC,CAAC;;;;"}
@@ -1,5 +1,5 @@
1
1
  import { createListMessagesFunction } from './createListMessagesFunction.mjs';
2
- import { createOnMessageFunction } from './createOnMessageFunction.mjs';
2
+ import { createOnStreamEventFunction } from './createOnStreamEventFunction.mjs';
3
3
  import { createSendMessageFunction } from './createSendMessageFunction.mjs';
4
4
 
5
5
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
@@ -14,7 +14,7 @@ const convertItemToConversation = (client, modelIntrospection, conversationId, c
14
14
  updatedAt: conversationUpdatedAt,
15
15
  metadata: conversationMetadata,
16
16
  name: conversationName,
17
- onMessage: createOnMessageFunction(client, modelIntrospection, conversationId, conversationRouteName, getInternals),
17
+ onStreamEvent: createOnStreamEventFunction(client, modelIntrospection, conversationId, conversationRouteName, getInternals),
18
18
  sendMessage: createSendMessageFunction(client, modelIntrospection, conversationId, conversationRouteName, getInternals),
19
19
  listMessages: createListMessagesFunction(client, modelIntrospection, conversationId, conversationMessageModel, getInternals),
20
20
  };
@@ -1 +1 @@
1
- {"version":3,"file":"convertItemToConversation.mjs","sources":["../../../../../src/runtime/internals/ai/convertItemToConversation.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { createListMessagesFunction } from './createListMessagesFunction';\nimport { createOnMessageFunction } from './createOnMessageFunction';\nimport { createSendMessageFunction } from './createSendMessageFunction';\nexport const convertItemToConversation = (client, modelIntrospection, conversationId, conversationCreatedAt, conversationUpdatedAt, conversationRouteName, conversationMessageModel, getInternals, conversationMetadata, conversationName) => {\n if (!conversationId) {\n throw new Error(`An error occurred converting a ${conversationRouteName} conversation: Missing ID`);\n }\n return {\n id: conversationId,\n createdAt: conversationCreatedAt,\n updatedAt: conversationUpdatedAt,\n metadata: conversationMetadata,\n name: conversationName,\n onMessage: createOnMessageFunction(client, modelIntrospection, conversationId, conversationRouteName, getInternals),\n sendMessage: createSendMessageFunction(client, modelIntrospection, conversationId, conversationRouteName, getInternals),\n listMessages: createListMessagesFunction(client, modelIntrospection, conversationId, conversationMessageModel, getInternals),\n };\n};\n"],"names":[],"mappings":";;;;AAAA;AACA;AAIY,MAAC,yBAAyB,GAAG,CAAC,MAAM,EAAE,kBAAkB,EAAE,cAAc,EAAE,qBAAqB,EAAE,qBAAqB,EAAE,qBAAqB,EAAE,wBAAwB,EAAE,YAAY,EAAE,oBAAoB,EAAE,gBAAgB,KAAK;AAC9O,IAAI,IAAI,CAAC,cAAc,EAAE;AACzB,QAAQ,MAAM,IAAI,KAAK,CAAC,CAAC,+BAA+B,EAAE,qBAAqB,CAAC,yBAAyB,CAAC,CAAC,CAAC;AAC5G,KAAK;AACL,IAAI,OAAO;AACX,QAAQ,EAAE,EAAE,cAAc;AAC1B,QAAQ,SAAS,EAAE,qBAAqB;AACxC,QAAQ,SAAS,EAAE,qBAAqB;AACxC,QAAQ,QAAQ,EAAE,oBAAoB;AACtC,QAAQ,IAAI,EAAE,gBAAgB;AAC9B,QAAQ,SAAS,EAAE,uBAAuB,CAAC,MAAM,EAAE,kBAAkB,EAAE,cAAc,EAAE,qBAAqB,EAAE,YAAY,CAAC;AAC3H,QAAQ,WAAW,EAAE,yBAAyB,CAAC,MAAM,EAAE,kBAAkB,EAAE,cAAc,EAAE,qBAAqB,EAAE,YAAY,CAAC;AAC/H,QAAQ,YAAY,EAAE,0BAA0B,CAAC,MAAM,EAAE,kBAAkB,EAAE,cAAc,EAAE,wBAAwB,EAAE,YAAY,CAAC;AACpI,KAAK,CAAC;AACN;;;;"}
1
+ {"version":3,"file":"convertItemToConversation.mjs","sources":["../../../../../src/runtime/internals/ai/convertItemToConversation.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { createListMessagesFunction } from './createListMessagesFunction';\nimport { createOnStreamEventFunction } from './createOnStreamEventFunction';\nimport { createSendMessageFunction } from './createSendMessageFunction';\nexport const convertItemToConversation = (client, modelIntrospection, conversationId, conversationCreatedAt, conversationUpdatedAt, conversationRouteName, conversationMessageModel, getInternals, conversationMetadata, conversationName) => {\n if (!conversationId) {\n throw new Error(`An error occurred converting a ${conversationRouteName} conversation: Missing ID`);\n }\n return {\n id: conversationId,\n createdAt: conversationCreatedAt,\n updatedAt: conversationUpdatedAt,\n metadata: conversationMetadata,\n name: conversationName,\n onStreamEvent: createOnStreamEventFunction(client, modelIntrospection, conversationId, conversationRouteName, getInternals),\n sendMessage: createSendMessageFunction(client, modelIntrospection, conversationId, conversationRouteName, getInternals),\n listMessages: createListMessagesFunction(client, modelIntrospection, conversationId, conversationMessageModel, getInternals),\n };\n};\n"],"names":[],"mappings":";;;;AAAA;AACA;AAIY,MAAC,yBAAyB,GAAG,CAAC,MAAM,EAAE,kBAAkB,EAAE,cAAc,EAAE,qBAAqB,EAAE,qBAAqB,EAAE,qBAAqB,EAAE,wBAAwB,EAAE,YAAY,EAAE,oBAAoB,EAAE,gBAAgB,KAAK;AAC9O,IAAI,IAAI,CAAC,cAAc,EAAE;AACzB,QAAQ,MAAM,IAAI,KAAK,CAAC,CAAC,+BAA+B,EAAE,qBAAqB,CAAC,yBAAyB,CAAC,CAAC,CAAC;AAC5G,KAAK;AACL,IAAI,OAAO;AACX,QAAQ,EAAE,EAAE,cAAc;AAC1B,QAAQ,SAAS,EAAE,qBAAqB;AACxC,QAAQ,SAAS,EAAE,qBAAqB;AACxC,QAAQ,QAAQ,EAAE,oBAAoB;AACtC,QAAQ,IAAI,EAAE,gBAAgB;AAC9B,QAAQ,aAAa,EAAE,2BAA2B,CAAC,MAAM,EAAE,kBAAkB,EAAE,cAAc,EAAE,qBAAqB,EAAE,YAAY,CAAC;AACnI,QAAQ,WAAW,EAAE,yBAAyB,CAAC,MAAM,EAAE,kBAAkB,EAAE,cAAc,EAAE,qBAAqB,EAAE,YAAY,CAAC;AAC/H,QAAQ,YAAY,EAAE,0BAA0B,CAAC,MAAM,EAAE,kBAAkB,EAAE,cAAc,EAAE,wBAAwB,EAAE,YAAY,CAAC;AACpI,KAAK,CAAC;AACN;;;;"}
@@ -3,7 +3,7 @@ import { deserializeContent } from './conversationMessageDeserializers.mjs';
3
3
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
4
4
  // SPDX-License-Identifier: Apache-2.0
5
5
  const convertItemToConversationMessage = ({ content, createdAt, id, conversationId, role, }) => ({
6
- content: deserializeContent(content),
6
+ content: deserializeContent(content ?? []),
7
7
  conversationId,
8
8
  createdAt,
9
9
  id,
@@ -1 +1 @@
1
- {"version":3,"file":"convertItemToConversationMessage.mjs","sources":["../../../../../src/runtime/internals/ai/convertItemToConversationMessage.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { deserializeContent } from './conversationMessageDeserializers';\nexport const convertItemToConversationMessage = ({ content, createdAt, id, conversationId, role, }) => ({\n content: deserializeContent(content),\n conversationId,\n createdAt,\n id,\n role,\n});\n"],"names":[],"mappings":";;AAAA;AACA;AAEY,MAAC,gCAAgC,GAAG,CAAC,EAAE,OAAO,EAAE,SAAS,EAAE,EAAE,EAAE,cAAc,EAAE,IAAI,GAAG,MAAM;AACxG,IAAI,OAAO,EAAE,kBAAkB,CAAC,OAAO,CAAC;AACxC,IAAI,cAAc;AAClB,IAAI,SAAS;AACb,IAAI,EAAE;AACN,IAAI,IAAI;AACR,CAAC;;;;"}
1
+ {"version":3,"file":"convertItemToConversationMessage.mjs","sources":["../../../../../src/runtime/internals/ai/convertItemToConversationMessage.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { deserializeContent } from './conversationMessageDeserializers';\nexport const convertItemToConversationMessage = ({ content, createdAt, id, conversationId, role, }) => ({\n content: deserializeContent(content ?? []),\n conversationId,\n createdAt,\n id,\n role,\n});\n"],"names":[],"mappings":";;AAAA;AACA;AAEY,MAAC,gCAAgC,GAAG,CAAC,EAAE,OAAO,EAAE,SAAS,EAAE,EAAE,EAAE,cAAc,EAAE,IAAI,GAAG,MAAM;AACxG,IAAI,OAAO,EAAE,kBAAkB,CAAC,OAAO,IAAI,EAAE,CAAC;AAC9C,IAAI,cAAc;AAClB,IAAI,SAAS;AACb,IAAI,EAAE;AACN,IAAI,IAAI;AACR,CAAC;;;;"}
@@ -0,0 +1,3 @@
1
+ import type { Conversation } from '../../../ai/ConversationType';
2
+ import { BaseClient, ClientInternalsGetter, ModelIntrospectionSchema } from '../../bridge-types';
3
+ export declare const createOnStreamEventFunction: (client: BaseClient, modelIntrospection: ModelIntrospectionSchema, conversationId: string, conversationRouteName: string, getInternals: ClientInternalsGetter) => Conversation['onStreamEvent'];