@aws-amplify/data-schema 1.4.0 → 1.5.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 (174) hide show
  1. package/dist/cjs/ClientSchema/ai/ClientConversation.js +6 -0
  2. package/dist/cjs/ClientSchema/ai/ClientConversation.js.map +1 -0
  3. package/dist/cjs/CustomOperation.js +22 -2
  4. package/dist/cjs/CustomOperation.js.map +1 -1
  5. package/dist/cjs/SchemaProcessor.js +41 -5
  6. package/dist/cjs/SchemaProcessor.js.map +1 -1
  7. package/dist/cjs/a.js +9 -1
  8. package/dist/cjs/a.js.map +1 -1
  9. package/dist/cjs/ai/ConversationSchemaTypes.js +210 -0
  10. package/dist/cjs/ai/ConversationSchemaTypes.js.map +1 -0
  11. package/dist/cjs/ai/ConversationType.js +27 -0
  12. package/dist/cjs/ai/ConversationType.js.map +1 -0
  13. package/dist/cjs/ai/ModelType.js +37 -0
  14. package/dist/cjs/ai/ModelType.js.map +1 -0
  15. package/dist/cjs/ai/types/ConversationMessageContent.js +6 -0
  16. package/dist/cjs/ai/types/ConversationMessageContent.js.map +1 -0
  17. package/dist/cjs/ai/types/ToolConfiguration.js +6 -0
  18. package/dist/cjs/ai/types/ToolConfiguration.js.map +1 -0
  19. package/dist/cjs/ai/types/ToolResultContent.js +6 -0
  20. package/dist/cjs/ai/types/ToolResultContent.js.map +1 -0
  21. package/dist/cjs/ai/types/contentBlocks.js +6 -0
  22. package/dist/cjs/ai/types/contentBlocks.js.map +1 -0
  23. package/dist/cjs/runtime/addSchemaToClient.js +2 -0
  24. package/dist/cjs/runtime/addSchemaToClient.js.map +1 -1
  25. package/dist/cjs/runtime/internals/APIClient.js +3 -3
  26. package/dist/cjs/runtime/internals/APIClient.js.map +1 -1
  27. package/dist/cjs/runtime/internals/ai/conversationMessageDeserializers.js +54 -0
  28. package/dist/cjs/runtime/internals/ai/conversationMessageDeserializers.js.map +1 -0
  29. package/dist/cjs/runtime/internals/ai/conversationMessageSerializers.js +58 -0
  30. package/dist/cjs/runtime/internals/ai/conversationMessageSerializers.js.map +1 -0
  31. package/dist/cjs/runtime/internals/ai/convertItemToConversation.js +22 -0
  32. package/dist/cjs/runtime/internals/ai/convertItemToConversation.js.map +1 -0
  33. package/dist/cjs/runtime/internals/ai/convertItemToConversationMessage.js +16 -0
  34. package/dist/cjs/runtime/internals/ai/convertItemToConversationMessage.js.map +1 -0
  35. package/dist/cjs/runtime/internals/ai/createCreateConversationFunction.js +18 -0
  36. package/dist/cjs/runtime/internals/ai/createCreateConversationFunction.js.map +1 -0
  37. package/dist/cjs/runtime/internals/ai/createGetConversationFunction.js +20 -0
  38. package/dist/cjs/runtime/internals/ai/createGetConversationFunction.js.map +1 -0
  39. package/dist/cjs/runtime/internals/ai/createListConversationsFunction.js +21 -0
  40. package/dist/cjs/runtime/internals/ai/createListConversationsFunction.js.map +1 -0
  41. package/dist/cjs/runtime/internals/ai/createListMessagesFunction.js +22 -0
  42. package/dist/cjs/runtime/internals/ai/createListMessagesFunction.js.map +1 -0
  43. package/dist/cjs/runtime/internals/ai/createOnMessageFunction.js +22 -0
  44. package/dist/cjs/runtime/internals/ai/createOnMessageFunction.js.map +1 -0
  45. package/dist/cjs/runtime/internals/ai/createSendMessageFunction.js +32 -0
  46. package/dist/cjs/runtime/internals/ai/createSendMessageFunction.js.map +1 -0
  47. package/dist/cjs/runtime/internals/index.js +5 -1
  48. package/dist/cjs/runtime/internals/index.js.map +1 -1
  49. package/dist/cjs/runtime/internals/operations/custom.js +17 -10
  50. package/dist/cjs/runtime/internals/operations/custom.js.map +1 -1
  51. package/dist/cjs/runtime/internals/utils/clientProperties/generateConversationsProperty.js +48 -0
  52. package/dist/cjs/runtime/internals/utils/clientProperties/generateConversationsProperty.js.map +1 -0
  53. package/dist/cjs/runtime/internals/utils/clientProperties/generateGenerationsProperty.js +22 -0
  54. package/dist/cjs/runtime/internals/utils/clientProperties/generateGenerationsProperty.js.map +1 -0
  55. package/dist/esm/ClientSchema/Core/ClientSchemaProperty.d.ts +1 -1
  56. package/dist/esm/ClientSchema/ai/ClientConversation.d.ts +7 -0
  57. package/dist/esm/ClientSchema/ai/ClientConversation.mjs +2 -0
  58. package/dist/esm/ClientSchema/ai/ClientConversation.mjs.map +1 -0
  59. package/dist/esm/ClientSchema/index.d.ts +12 -2
  60. package/dist/esm/CustomOperation.d.ts +33 -2
  61. package/dist/esm/CustomOperation.mjs +21 -2
  62. package/dist/esm/CustomOperation.mjs.map +1 -1
  63. package/dist/esm/ModelSchema.d.ts +3 -1
  64. package/dist/esm/SchemaProcessor.d.ts +1 -1
  65. package/dist/esm/SchemaProcessor.mjs +41 -5
  66. package/dist/esm/SchemaProcessor.mjs.map +1 -1
  67. package/dist/esm/a.d.ts +7 -2
  68. package/dist/esm/a.mjs +9 -1
  69. package/dist/esm/a.mjs.map +1 -1
  70. package/dist/esm/ai/ConversationSchemaTypes.d.ts +3 -0
  71. package/dist/esm/ai/ConversationSchemaTypes.mjs +208 -0
  72. package/dist/esm/ai/ConversationSchemaTypes.mjs.map +1 -0
  73. package/dist/esm/ai/ConversationType.d.ts +102 -0
  74. package/dist/esm/ai/ConversationType.mjs +25 -0
  75. package/dist/esm/ai/ConversationType.mjs.map +1 -0
  76. package/dist/esm/ai/ModelType.d.ts +30 -0
  77. package/dist/esm/ai/ModelType.mjs +34 -0
  78. package/dist/esm/ai/ModelType.mjs.map +1 -0
  79. package/dist/esm/ai/types/ConversationMessageContent.d.ts +27 -0
  80. package/dist/esm/ai/types/ConversationMessageContent.mjs +2 -0
  81. package/dist/esm/ai/types/ConversationMessageContent.mjs.map +1 -0
  82. package/dist/esm/ai/types/ToolConfiguration.d.ts +18 -0
  83. package/dist/esm/ai/types/ToolConfiguration.mjs +2 -0
  84. package/dist/esm/ai/types/ToolConfiguration.mjs.map +1 -0
  85. package/dist/esm/ai/types/ToolResultContent.d.ts +18 -0
  86. package/dist/esm/ai/types/ToolResultContent.mjs +2 -0
  87. package/dist/esm/ai/types/ToolResultContent.mjs.map +1 -0
  88. package/dist/esm/ai/types/contentBlocks.d.ts +19 -0
  89. package/dist/esm/ai/types/contentBlocks.mjs +2 -0
  90. package/dist/esm/ai/types/contentBlocks.mjs.map +1 -0
  91. package/dist/esm/runtime/addSchemaToClient.mjs +4 -0
  92. package/dist/esm/runtime/addSchemaToClient.mjs.map +1 -1
  93. package/dist/esm/runtime/addSchemaToClientWithInstance.mjs +2 -1
  94. package/dist/esm/runtime/addSchemaToClientWithInstance.mjs.map +1 -1
  95. package/dist/esm/runtime/bridge-types.d.ts +29 -3
  96. package/dist/esm/runtime/client/index.d.ts +35 -19
  97. package/dist/esm/runtime/internals/APIClient.mjs +3 -3
  98. package/dist/esm/runtime/internals/APIClient.mjs.map +1 -1
  99. package/dist/esm/runtime/internals/ai/conversationMessageDeserializers.d.ts +2 -0
  100. package/dist/esm/runtime/internals/ai/conversationMessageDeserializers.mjs +52 -0
  101. package/dist/esm/runtime/internals/ai/conversationMessageDeserializers.mjs.map +1 -0
  102. package/dist/esm/runtime/internals/ai/conversationMessageSerializers.d.ts +37 -0
  103. package/dist/esm/runtime/internals/ai/conversationMessageSerializers.mjs +54 -0
  104. package/dist/esm/runtime/internals/ai/conversationMessageSerializers.mjs.map +1 -0
  105. package/dist/esm/runtime/internals/ai/convertItemToConversation.d.ts +3 -0
  106. package/dist/esm/runtime/internals/ai/convertItemToConversation.mjs +20 -0
  107. package/dist/esm/runtime/internals/ai/convertItemToConversation.mjs.map +1 -0
  108. package/dist/esm/runtime/internals/ai/convertItemToConversationMessage.d.ts +7 -0
  109. package/dist/esm/runtime/internals/ai/convertItemToConversationMessage.mjs +14 -0
  110. package/dist/esm/runtime/internals/ai/convertItemToConversationMessage.mjs.map +1 -0
  111. package/dist/esm/runtime/internals/ai/createCreateConversationFunction.d.ts +3 -0
  112. package/dist/esm/runtime/internals/ai/createCreateConversationFunction.mjs +16 -0
  113. package/dist/esm/runtime/internals/ai/createCreateConversationFunction.mjs.map +1 -0
  114. package/dist/esm/runtime/internals/ai/createGetConversationFunction.d.ts +3 -0
  115. package/dist/esm/runtime/internals/ai/createGetConversationFunction.mjs +18 -0
  116. package/dist/esm/runtime/internals/ai/createGetConversationFunction.mjs.map +1 -0
  117. package/dist/esm/runtime/internals/ai/createListConversationsFunction.d.ts +3 -0
  118. package/dist/esm/runtime/internals/ai/createListConversationsFunction.mjs +19 -0
  119. package/dist/esm/runtime/internals/ai/createListConversationsFunction.mjs.map +1 -0
  120. package/dist/esm/runtime/internals/ai/createListMessagesFunction.d.ts +3 -0
  121. package/dist/esm/runtime/internals/ai/createListMessagesFunction.mjs +20 -0
  122. package/dist/esm/runtime/internals/ai/createListMessagesFunction.mjs.map +1 -0
  123. package/dist/esm/runtime/internals/ai/createOnMessageFunction.d.ts +3 -0
  124. package/dist/esm/runtime/internals/ai/createOnMessageFunction.mjs +20 -0
  125. package/dist/esm/runtime/internals/ai/createOnMessageFunction.mjs.map +1 -0
  126. package/dist/esm/runtime/internals/ai/createSendMessageFunction.d.ts +3 -0
  127. package/dist/esm/runtime/internals/ai/createSendMessageFunction.mjs +30 -0
  128. package/dist/esm/runtime/internals/ai/createSendMessageFunction.mjs.map +1 -0
  129. package/dist/esm/runtime/internals/index.d.ts +2 -0
  130. package/dist/esm/runtime/internals/index.mjs +2 -0
  131. package/dist/esm/runtime/internals/index.mjs.map +1 -1
  132. package/dist/esm/runtime/internals/operations/custom.d.ts +1 -1
  133. package/dist/esm/runtime/internals/operations/custom.mjs +17 -10
  134. package/dist/esm/runtime/internals/operations/custom.mjs.map +1 -1
  135. package/dist/esm/runtime/internals/utils/clientProperties/generateConversationsProperty.d.ts +3 -0
  136. package/dist/esm/runtime/internals/utils/clientProperties/generateConversationsProperty.mjs +46 -0
  137. package/dist/esm/runtime/internals/utils/clientProperties/generateConversationsProperty.mjs.map +1 -0
  138. package/dist/esm/runtime/internals/utils/clientProperties/generateGenerationsProperty.d.ts +3 -0
  139. package/dist/esm/runtime/internals/utils/clientProperties/generateGenerationsProperty.mjs +20 -0
  140. package/dist/esm/runtime/internals/utils/clientProperties/generateGenerationsProperty.mjs.map +1 -0
  141. package/dist/meta/cjs.tsbuildinfo +1 -1
  142. package/package.json +3 -1
  143. package/src/ClientSchema/Core/ClientSchemaProperty.ts +3 -1
  144. package/src/ClientSchema/ai/ClientConversation.ts +15 -0
  145. package/src/ClientSchema/index.ts +15 -1
  146. package/src/CustomOperation.ts +48 -5
  147. package/src/ModelSchema.ts +4 -1
  148. package/src/SchemaProcessor.ts +73 -8
  149. package/src/a.ts +10 -1
  150. package/src/ai/ConversationSchemaTypes.ts +253 -0
  151. package/src/ai/ConversationType.ts +135 -0
  152. package/src/ai/ModelType.ts +43 -0
  153. package/src/ai/types/ConversationMessageContent.ts +43 -0
  154. package/src/ai/types/ToolConfiguration.ts +24 -0
  155. package/src/ai/types/ToolResultContent.ts +28 -0
  156. package/src/ai/types/contentBlocks.ts +26 -0
  157. package/src/runtime/addSchemaToClient.ts +12 -0
  158. package/src/runtime/bridge-types.ts +41 -4
  159. package/src/runtime/client/index.ts +82 -23
  160. package/src/runtime/internals/APIClient.ts +3 -4
  161. package/src/runtime/internals/ai/conversationMessageDeserializers.ts +62 -0
  162. package/src/runtime/internals/ai/conversationMessageSerializers.ts +68 -0
  163. package/src/runtime/internals/ai/convertItemToConversation.ts +53 -0
  164. package/src/runtime/internals/ai/convertItemToConversationMessage.ts +18 -0
  165. package/src/runtime/internals/ai/createCreateConversationFunction.ts +44 -0
  166. package/src/runtime/internals/ai/createGetConversationFunction.ts +48 -0
  167. package/src/runtime/internals/ai/createListConversationsFunction.ts +46 -0
  168. package/src/runtime/internals/ai/createListMessagesFunction.ts +42 -0
  169. package/src/runtime/internals/ai/createOnMessageFunction.ts +41 -0
  170. package/src/runtime/internals/ai/createSendMessageFunction.ts +60 -0
  171. package/src/runtime/internals/index.ts +2 -0
  172. package/src/runtime/internals/operations/custom.ts +24 -12
  173. package/src/runtime/internals/utils/clientProperties/generateConversationsProperty.ts +91 -0
  174. package/src/runtime/internals/utils/clientProperties/generateGenerationsProperty.ts +41 -0
@@ -8,6 +8,7 @@ import {
8
8
  __modelMeta__,
9
9
  } from '@aws-amplify/data-schema-types';
10
10
  import type { Observable } from 'rxjs';
11
+ import type { ConversationRoute } from '../../ai/ConversationType';
11
12
  import type {
12
13
  ClientSchemaByEntityType,
13
14
  ClientSchemaByEntityTypeBaseShape,
@@ -511,31 +512,45 @@ type ModelTypesClient<
511
512
  // Omit any disabled operations
512
513
  Omit<
513
514
  {
514
- create: (
515
+ create<
516
+ SelectionSet extends ReadonlyArray<ModelPath<FlatModel>> = never[],
517
+ >(
515
518
  model: Model['createType'],
516
519
  options?: {
520
+ selectionSet?: SelectionSet;
517
521
  authMode?: AuthMode;
518
522
  authToken?: string;
519
523
  headers?: CustomHeaders;
520
524
  },
521
- ) => SingularReturnValue<Model['type']>;
522
- update: (
525
+ ): SingularReturnValue<
526
+ Prettify<ReturnValue<Model, FlatModel, SelectionSet>>
527
+ >;
528
+ update<
529
+ SelectionSet extends ReadonlyArray<ModelPath<FlatModel>> = never[],
530
+ >(
523
531
  model: Model['updateType'],
524
532
  options?: {
533
+ selectionSet?: SelectionSet;
525
534
  authMode?: AuthMode;
526
535
  authToken?: string;
527
536
  headers?: CustomHeaders;
528
537
  },
529
- ) => SingularReturnValue<Model['type']>;
530
- delete: (
538
+ ): SingularReturnValue<
539
+ Prettify<ReturnValue<Model, FlatModel, SelectionSet>>
540
+ >;
541
+ delete<
542
+ SelectionSet extends ReadonlyArray<ModelPath<FlatModel>> = never[],
543
+ >(
531
544
  identifier: Model['deleteType'],
532
545
  options?: {
546
+ selectionSet?: SelectionSet;
533
547
  authMode?: AuthMode;
534
548
  authToken?: string;
535
549
  headers?: CustomHeaders;
536
550
  },
537
- ) => SingularReturnValue<Model['type']>;
538
-
551
+ ): SingularReturnValue<
552
+ Prettify<ReturnValue<Model, FlatModel, SelectionSet>>
553
+ >;
539
554
  get<SelectionSet extends ReadonlyArray<ModelPath<FlatModel>> = never[]>(
540
555
  identifier: Model['identifier'],
541
556
  options?: {
@@ -558,7 +573,6 @@ type ModelTypesClient<
558
573
  headers?: CustomHeaders;
559
574
  },
560
575
  ): ListReturnValue<Prettify<ReturnValue<Model, FlatModel, SelectionSet>>>;
561
-
562
576
  onCreate<
563
577
  SelectionSet extends ReadonlyArray<ModelPath<FlatModel>> = never[],
564
578
  >(options?: {
@@ -610,33 +624,48 @@ type ModelTypesSSRCookies<
610
624
  Model extends ClientSchemaByEntityTypeBaseShape['models'][string],
611
625
  FlatModel extends Record<string, unknown> = ResolvedModel<Model['type']>,
612
626
  > = IndexQueryMethods<Model> &
627
+ // Omit any disabled operations
613
628
  Omit<
614
629
  {
615
- create: (
630
+ create<
631
+ SelectionSet extends ReadonlyArray<ModelPath<FlatModel>> = never[],
632
+ >(
616
633
  model: Model['createType'],
617
634
  options?: {
635
+ selectionSet?: SelectionSet;
618
636
  authMode?: AuthMode;
619
637
  authToken?: string;
620
638
  headers?: CustomHeaders;
621
639
  },
622
- ) => SingularReturnValue<Model['type']>;
623
- update: (
640
+ ): SingularReturnValue<
641
+ Prettify<ReturnValue<Model, FlatModel, SelectionSet>>
642
+ >;
643
+ update<
644
+ SelectionSet extends ReadonlyArray<ModelPath<FlatModel>> = never[],
645
+ >(
624
646
  model: Model['updateType'],
625
647
  options?: {
648
+ selectionSet?: SelectionSet;
626
649
  authMode?: AuthMode;
627
650
  authToken?: string;
628
651
  headers?: CustomHeaders;
629
652
  },
630
- ) => SingularReturnValue<Model['type']>;
631
- delete: (
653
+ ): SingularReturnValue<
654
+ Prettify<ReturnValue<Model, FlatModel, SelectionSet>>
655
+ >;
656
+ delete<
657
+ SelectionSet extends ReadonlyArray<ModelPath<FlatModel>> = never[],
658
+ >(
632
659
  identifier: Model['deleteType'],
633
660
  options?: {
661
+ selectionSet?: SelectionSet;
634
662
  authMode?: AuthMode;
635
663
  authToken?: string;
636
664
  headers?: CustomHeaders;
637
665
  },
638
- ) => SingularReturnValue<Model['type']>;
639
-
666
+ ): SingularReturnValue<
667
+ Prettify<ReturnValue<Model, FlatModel, SelectionSet>>
668
+ >;
640
669
  get<SelectionSet extends ReadonlyArray<ModelPath<FlatModel>> = never[]>(
641
670
  identifier: Model['identifier'],
642
671
  options?: {
@@ -668,36 +697,51 @@ type ModelTypesSSRRequest<
668
697
  Model extends ClientSchemaByEntityTypeBaseShape['models'][string],
669
698
  FlatModel extends Record<string, unknown> = ResolvedModel<Model['type']>,
670
699
  > = IndexQueryMethods<Model, 'REQUEST'> &
700
+ // Omit any disabled operations
671
701
  Omit<
672
702
  {
673
- create: (
703
+ create<
704
+ SelectionSet extends ReadonlyArray<ModelPath<FlatModel>> = never[],
705
+ >(
674
706
  contextSpec: AmplifyServer.ContextSpec,
675
707
  model: Model['createType'],
676
708
  options?: {
709
+ selectionSet?: SelectionSet;
677
710
  authMode?: AuthMode;
678
711
  authToken?: string;
679
712
  headers?: CustomHeaders;
680
713
  },
681
- ) => SingularReturnValue<Model['type']>;
682
- update: (
714
+ ): SingularReturnValue<
715
+ Prettify<ReturnValue<Model, FlatModel, SelectionSet>>
716
+ >;
717
+ update<
718
+ SelectionSet extends ReadonlyArray<ModelPath<FlatModel>> = never[],
719
+ >(
683
720
  contextSpec: AmplifyServer.ContextSpec,
684
721
  model: Model['updateType'],
685
722
  options?: {
723
+ selectionSet?: SelectionSet;
686
724
  authMode?: AuthMode;
687
725
  authToken?: string;
688
726
  headers?: CustomHeaders;
689
727
  },
690
- ) => SingularReturnValue<Model['type']>;
691
- delete: (
728
+ ): SingularReturnValue<
729
+ Prettify<ReturnValue<Model, FlatModel, SelectionSet>>
730
+ >;
731
+ delete<
732
+ SelectionSet extends ReadonlyArray<ModelPath<FlatModel>> = never[],
733
+ >(
692
734
  contextSpec: AmplifyServer.ContextSpec,
693
735
  identifier: Model['deleteType'],
694
736
  options?: {
737
+ selectionSet?: SelectionSet;
695
738
  authMode?: AuthMode;
696
739
  authToken?: string;
697
740
  headers?: CustomHeaders;
698
741
  },
699
- ) => SingularReturnValue<Model['type']>;
700
-
742
+ ): SingularReturnValue<
743
+ Prettify<ReturnValue<Model, FlatModel, SelectionSet>>
744
+ >;
701
745
  get<SelectionSet extends ReadonlyArray<ModelPath<FlatModel>> = never[]>(
702
746
  contextSpec: AmplifyServer.ContextSpec,
703
747
  identifier: Model['identifier'],
@@ -781,7 +825,8 @@ export type CustomOperations<
781
825
  OperationDefs extends ClientSchemaByEntityTypeBaseShape[
782
826
  | 'queries'
783
827
  | 'mutations'
784
- | 'subscriptions'],
828
+ | 'subscriptions'
829
+ | 'generations'],
785
830
  Context extends ContextType = 'CLIENT',
786
831
  > = {
787
832
  [OpName in keyof OperationDefs]: {
@@ -857,6 +902,8 @@ export type ClientExtensions<T extends Record<any, any> = never> = {
857
902
  queries: CustomQueries<T, 'CLIENT'>;
858
903
  mutations: CustomMutations<T, 'CLIENT'>;
859
904
  subscriptions: CustomSubscriptions<T, 'CLIENT'>;
905
+ conversations: ConversationRoutes<T>;
906
+ generations: Generations<T>;
860
907
  };
861
908
 
862
909
  export type ClientExtensionsSSRRequest<T extends Record<any, any> = never> = {
@@ -872,3 +919,15 @@ export type ClientExtensionsSSRCookies<T extends Record<any, any> = never> = {
872
919
  queries: CustomQueries<T, 'COOKIES'>;
873
920
  mutations: CustomMutations<T, 'COOKIES'>;
874
921
  };
922
+
923
+ export type ConversationRoutes<
924
+ T extends Record<any, any>,
925
+ Schema extends ClientSchemaByEntityType<T> = ClientSchemaByEntityType<T>,
926
+ > = {
927
+ [ConversationName in keyof Schema['conversations']]: ConversationRoute;
928
+ };
929
+
930
+ export type Generations<
931
+ T extends Record<any, any>,
932
+ Schema extends ClientSchemaByEntityType<T> = ClientSchemaByEntityType<T>,
933
+ > = CustomOperations<Schema['generations']>;
@@ -248,7 +248,7 @@ export function initializeModel(
248
248
  );
249
249
 
250
250
  // if get is disabled on the related model
251
- if ((client as any).models[relatedModelName].get === undefined) {
251
+ if ((client as any).models[relatedModelName]?.get === undefined) {
252
252
  break;
253
253
  }
254
254
 
@@ -340,7 +340,7 @@ export function initializeModel(
340
340
  );
341
341
 
342
342
  // if list is disabled on the related model
343
- if ((client as any).models[relatedModelName].list === undefined) {
343
+ if ((client as any).models[relatedModelName]?.list === undefined) {
344
344
  break;
345
345
  }
346
346
 
@@ -411,7 +411,7 @@ export function initializeModel(
411
411
  );
412
412
 
413
413
  // if list is disabled on the related model
414
- if ((client as any).models[relatedModelName].list === undefined) {
414
+ if ((client as any).models[relatedModelName]?.list === undefined) {
415
415
  break;
416
416
  }
417
417
 
@@ -1242,7 +1242,6 @@ export function buildGraphQLVariables(
1242
1242
  throw new Error(
1243
1243
  'Internal error: Attempted to build variables for observeQuery. Please report this error.',
1244
1244
  );
1245
- break;
1246
1245
  default: {
1247
1246
  const exhaustiveCheck: never = operation;
1248
1247
  throw new Error(`Unhandled operation case: ${exhaustiveCheck}`);
@@ -0,0 +1,62 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { fromBase64 } from '@smithy/util-base64';
5
+ import type { ConversationMessageContent } from '../../../ai/types/ConversationMessageContent';
6
+
7
+ export const deserializeContent = (
8
+ content: Record<string, any>[],
9
+ ): ConversationMessageContent[] =>
10
+ content.map((block) => {
11
+ if (block.image) {
12
+ return deserializeImageBlock(block);
13
+ }
14
+ if (block.toolUse) {
15
+ return deserializeToolUseBlock(block);
16
+ }
17
+ if (block.toolResult) {
18
+ return deserializeToolResultBlock(block);
19
+ }
20
+ return removeNullsFromBlock(block) as ConversationMessageContent;
21
+ });
22
+
23
+ const deserializeImageBlock = ({ image }: Record<'image', any>) => ({
24
+ image: {
25
+ ...image,
26
+ source: {
27
+ ...image.source,
28
+ bytes: fromBase64(image.source.bytes),
29
+ },
30
+ },
31
+ });
32
+
33
+ const deserializeJsonBlock = ({ json }: Record<'json', any>) => ({
34
+ json: JSON.parse(json),
35
+ });
36
+
37
+ const deserializeToolUseBlock = ({ toolUse }: Record<'toolUse', any>) => ({
38
+ toolUse: {
39
+ ...toolUse,
40
+ input: JSON.parse(toolUse.input),
41
+ },
42
+ });
43
+
44
+ const deserializeToolResultBlock = ({
45
+ toolResult,
46
+ }: Record<'toolResult', any>) => ({
47
+ toolResult: {
48
+ toolUseId: toolResult.toolUseId,
49
+ content: toolResult.content.map((toolResultBlock: Record<string, any>) => {
50
+ if (toolResultBlock.image) {
51
+ return deserializeImageBlock(toolResultBlock);
52
+ }
53
+ if (toolResultBlock.json) {
54
+ return deserializeJsonBlock(toolResultBlock);
55
+ }
56
+ return removeNullsFromBlock(toolResultBlock);
57
+ }),
58
+ },
59
+ });
60
+
61
+ const removeNullsFromBlock = (block: Record<string, any>) =>
62
+ Object.fromEntries(Object.entries(block).filter(([_, v]) => v !== null));
@@ -0,0 +1,68 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { toBase64 } from '@smithy/util-base64';
5
+ import type {
6
+ ConversationMessageContent,
7
+ ConversationMessageImageContent,
8
+ ConversationMessageToolResultContent,
9
+ } from '../../../ai/types/ConversationMessageContent';
10
+ import type { ToolConfiguration } from '../../../ai/types/ToolConfiguration';
11
+ import type { ToolResultJsonContent } from '../../../ai/types/ToolResultContent';
12
+
13
+ export const serializeAiContext = (aiContext: string | Record<string, any>) =>
14
+ JSON.stringify(aiContext);
15
+
16
+ export const serializeContent = (content: ConversationMessageContent[]) =>
17
+ content.map((block) => {
18
+ if (block.image) {
19
+ return serializeImageBlock(block);
20
+ }
21
+ if (block.toolResult) {
22
+ return serializeToolResultBlock(block);
23
+ }
24
+ return block;
25
+ });
26
+
27
+ export const serializeToolConfiguration = ({ tools }: ToolConfiguration) => ({
28
+ tools: Object.entries(tools).map(([name, tool]) => ({
29
+ toolSpec: {
30
+ name,
31
+ description: tool.description,
32
+ inputSchema: {
33
+ json: JSON.stringify(tool.inputSchema.json),
34
+ },
35
+ },
36
+ })),
37
+ });
38
+
39
+ const serializeImageBlock = ({ image }: ConversationMessageImageContent) => ({
40
+ image: {
41
+ ...image,
42
+ source: {
43
+ ...image.source,
44
+ bytes: toBase64(image.source.bytes),
45
+ },
46
+ },
47
+ });
48
+
49
+ const serializeJsonBlock = ({ json }: ToolResultJsonContent) => ({
50
+ json: JSON.stringify(json),
51
+ });
52
+
53
+ const serializeToolResultBlock = ({
54
+ toolResult,
55
+ }: ConversationMessageToolResultContent) => ({
56
+ toolResult: {
57
+ ...toolResult,
58
+ content: toolResult.content.map((toolResultBlock) => {
59
+ if (toolResultBlock.image) {
60
+ return serializeImageBlock(toolResultBlock);
61
+ }
62
+ if (toolResultBlock.json) {
63
+ return serializeJsonBlock(toolResultBlock);
64
+ }
65
+ return toolResultBlock;
66
+ }),
67
+ },
68
+ });
@@ -0,0 +1,53 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import type { Conversation } from '../../../ai/ConversationType';
5
+ import type {
6
+ BaseBrowserClient,
7
+ BaseClient,
8
+ ClientInternalsGetter,
9
+ ModelIntrospectionSchema,
10
+ SchemaModel,
11
+ } from '../../bridge-types';
12
+ import { createListMessagesFunction } from './createListMessagesFunction';
13
+ import { createOnMessageFunction } from './createOnMessageFunction';
14
+ import { createSendMessageFunction } from './createSendMessageFunction';
15
+
16
+ export const convertItemToConversation = (
17
+ client: BaseClient,
18
+ modelIntrospection: ModelIntrospectionSchema,
19
+ conversationId: string,
20
+ conversationRouteName: string,
21
+ conversationMessageModel: SchemaModel,
22
+ getInternals: ClientInternalsGetter,
23
+ ): Conversation => {
24
+ if (!conversationId) {
25
+ throw new Error(
26
+ `An error occurred converting a ${conversationRouteName} conversation: Missing ID`,
27
+ );
28
+ }
29
+ return {
30
+ id: conversationId,
31
+ onMessage: createOnMessageFunction(
32
+ client as BaseBrowserClient,
33
+ modelIntrospection,
34
+ conversationId,
35
+ conversationRouteName,
36
+ getInternals,
37
+ ),
38
+ sendMessage: createSendMessageFunction(
39
+ client,
40
+ modelIntrospection,
41
+ conversationId,
42
+ conversationRouteName,
43
+ getInternals,
44
+ ),
45
+ listMessages: createListMessagesFunction(
46
+ client,
47
+ modelIntrospection,
48
+ conversationId,
49
+ conversationMessageModel,
50
+ getInternals,
51
+ ),
52
+ };
53
+ };
@@ -0,0 +1,18 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { deserializeContent } from './conversationMessageDeserializers';
5
+
6
+ export const convertItemToConversationMessage = ({
7
+ content,
8
+ createdAt,
9
+ id,
10
+ conversationId,
11
+ role,
12
+ }: any) => ({
13
+ content: deserializeContent(content),
14
+ conversationId,
15
+ createdAt,
16
+ id,
17
+ role,
18
+ });
@@ -0,0 +1,44 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import type { ConversationRoute } from '../../../ai/ConversationType';
5
+ import type { SingularReturnValue } from '../../../runtime/client';
6
+ import type {
7
+ BaseClient,
8
+ ClientInternalsGetter,
9
+ ModelIntrospectionSchema,
10
+ SchemaModel,
11
+ } from '../../bridge-types';
12
+ import { getFactory } from '../operations/get';
13
+ import { convertItemToConversation } from './convertItemToConversation';
14
+
15
+ export const createCreateConversationFunction =
16
+ (
17
+ client: BaseClient,
18
+ modelIntrospection: ModelIntrospectionSchema,
19
+ conversationRouteName: string,
20
+ conversationModel: SchemaModel,
21
+ conversationMessageModel: SchemaModel,
22
+ getInternals: ClientInternalsGetter,
23
+ ): ConversationRoute['create'] =>
24
+ async () => {
25
+ const get = getFactory(
26
+ client,
27
+ modelIntrospection,
28
+ conversationModel,
29
+ 'CREATE',
30
+ getInternals,
31
+ ) as () => SingularReturnValue<Record<string, any>>;
32
+ const { data, errors } = await get();
33
+ return {
34
+ data: convertItemToConversation(
35
+ client,
36
+ modelIntrospection,
37
+ data?.id,
38
+ conversationRouteName,
39
+ conversationMessageModel,
40
+ getInternals,
41
+ ),
42
+ errors,
43
+ };
44
+ };
@@ -0,0 +1,48 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import type { ConversationRoute } from '../../../ai/ConversationType';
5
+ import type { SingularReturnValue } from '../../../runtime/client';
6
+ import type {
7
+ BaseClient,
8
+ ClientInternalsGetter,
9
+ ModelIntrospectionSchema,
10
+ SchemaModel,
11
+ } from '../../bridge-types';
12
+ import { getFactory } from '../operations/get';
13
+ import { convertItemToConversation } from './convertItemToConversation';
14
+
15
+ export const createGetConversationFunction =
16
+ (
17
+ client: BaseClient,
18
+ modelIntrospection: ModelIntrospectionSchema,
19
+ conversationRouteName: string,
20
+ conversationModel: SchemaModel,
21
+ conversationMessageModel: SchemaModel,
22
+ getInternals: ClientInternalsGetter,
23
+ ): ConversationRoute['get'] =>
24
+ async ({ id }) => {
25
+ const get = getFactory(
26
+ client,
27
+ modelIntrospection,
28
+ conversationModel,
29
+ 'GET',
30
+ getInternals,
31
+ ) as (
32
+ args?: Record<string, any>,
33
+ ) => SingularReturnValue<Record<string, any>>;
34
+ const { data, errors } = await get({ id });
35
+ return {
36
+ data: data
37
+ ? convertItemToConversation(
38
+ client,
39
+ modelIntrospection,
40
+ data.id,
41
+ conversationRouteName,
42
+ conversationMessageModel,
43
+ getInternals,
44
+ )
45
+ : data,
46
+ errors,
47
+ };
48
+ };
@@ -0,0 +1,46 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import type { ConversationRoute } from '../../../ai/ConversationType';
5
+ import type { ListReturnValue } from '../../../runtime/client';
6
+ import type {
7
+ BaseClient,
8
+ ClientInternalsGetter,
9
+ ModelIntrospectionSchema,
10
+ SchemaModel,
11
+ } from '../../bridge-types';
12
+ import { listFactory } from '../operations/list';
13
+ import { convertItemToConversation } from './convertItemToConversation';
14
+
15
+ export const createListConversationsFunction =
16
+ (
17
+ client: BaseClient,
18
+ modelIntrospection: ModelIntrospectionSchema,
19
+ conversationRouteName: string,
20
+ conversationModel: SchemaModel,
21
+ conversationMessageModel: SchemaModel,
22
+ getInternals: ClientInternalsGetter,
23
+ ): ConversationRoute['list'] =>
24
+ async (input) => {
25
+ const list = listFactory(
26
+ client,
27
+ modelIntrospection,
28
+ conversationModel,
29
+ getInternals,
30
+ ) as (args?: Record<string, any>) => ListReturnValue<Record<string, any>>;
31
+ const { data, nextToken, errors } = await list(input);
32
+ return {
33
+ data: data.map((datum: Record<string, any>) => {
34
+ return convertItemToConversation(
35
+ client,
36
+ modelIntrospection,
37
+ datum.id,
38
+ conversationRouteName,
39
+ conversationMessageModel,
40
+ getInternals,
41
+ );
42
+ }),
43
+ nextToken,
44
+ errors,
45
+ };
46
+ };
@@ -0,0 +1,42 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import type {
5
+ Conversation,
6
+ ConversationMessage,
7
+ } from '../../../ai/ConversationType';
8
+ import type { ListReturnValue } from '../../../runtime/client';
9
+ import type {
10
+ BaseClient,
11
+ ClientInternalsGetter,
12
+ ModelIntrospectionSchema,
13
+ SchemaModel,
14
+ } from '../../bridge-types';
15
+ import { listFactory } from '../operations/list';
16
+ import { convertItemToConversationMessage } from './convertItemToConversationMessage';
17
+
18
+ export const createListMessagesFunction =
19
+ (
20
+ client: BaseClient,
21
+ modelIntrospection: ModelIntrospectionSchema,
22
+ conversationId: string,
23
+ conversationMessageModel: SchemaModel,
24
+ getInternals: ClientInternalsGetter,
25
+ ): Conversation['listMessages'] =>
26
+ async (input) => {
27
+ const list = listFactory(
28
+ client,
29
+ modelIntrospection,
30
+ conversationMessageModel,
31
+ getInternals,
32
+ ) as (args?: Record<string, any>) => ListReturnValue<ConversationMessage>;
33
+ const { data, nextToken, errors } = await list({
34
+ ...input,
35
+ filter: { conversationId: { eq: conversationId } },
36
+ });
37
+ return {
38
+ data: data.map((item: any) => convertItemToConversationMessage(item)),
39
+ nextToken,
40
+ errors,
41
+ };
42
+ };
@@ -0,0 +1,41 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import type { Observable, Subscription } from 'rxjs';
5
+ import type { Conversation } from '../../../ai/ConversationType';
6
+ import type {
7
+ BaseClient,
8
+ ClientInternalsGetter,
9
+ ModelIntrospectionSchema,
10
+ } from '../../bridge-types';
11
+ import { customOpFactory } from '../operations/custom';
12
+ import { convertItemToConversationMessage } from './convertItemToConversationMessage';
13
+
14
+ export const createOnMessageFunction =
15
+ (
16
+ client: BaseClient,
17
+ modelIntrospection: ModelIntrospectionSchema,
18
+ conversationId: string,
19
+ conversationRouteName: string,
20
+ getInternals: ClientInternalsGetter,
21
+ ): Conversation['onMessage'] =>
22
+ (handler): Subscription => {
23
+ const { conversations } = modelIntrospection;
24
+ // Safe guard for standalone function. When called as part of client generation, this should never be falsy.
25
+ if (!conversations) {
26
+ return {} as Subscription;
27
+ }
28
+ const subscribeSchema =
29
+ conversations[conversationRouteName].message.subscribe;
30
+ const subscribeOperation = customOpFactory(
31
+ client,
32
+ modelIntrospection,
33
+ 'subscription',
34
+ subscribeSchema,
35
+ false,
36
+ getInternals,
37
+ ) as (args?: Record<string, any>) => Observable<any>;
38
+ return subscribeOperation({ conversationId }).subscribe((data) => {
39
+ handler(convertItemToConversationMessage(data));
40
+ });
41
+ };