@aws-amplify/data-schema 1.9.0 → 1.9.2

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.
@@ -300,13 +300,23 @@ function customOperationToGql(typeName, typeDef, authorization, isCustom = false
300
300
  throw new Error(`Invalid Generation Route definition. A Generation Route must include a valid input. ${typeName} has an invalid or no input defined.`);
301
301
  }
302
302
  const { aiModel, systemPrompt, inferenceConfiguration } = typeDef.data.input;
303
+ // This is done to escape newlines in potentially multi-line system prompts
304
+ // e.g.
305
+ // generateStuff: a.generation({
306
+ // aiModel: a.ai.model('Claude 3 Haiku'),
307
+ // systemPrompt: `Generate a haiku
308
+ // make it multiline`,
309
+ // }),
310
+ //
311
+ // It doesn't affect non multi-line string inputs for system prompts
312
+ const escapedSystemPrompt = systemPrompt.replace(/\r?\n/g, '\\n');
303
313
  const inferenceConfigurationEntries = Object.entries(inferenceConfiguration ?? {});
304
314
  const inferenceConfigurationGql = inferenceConfigurationEntries.length > 0
305
315
  ? `, inferenceConfiguration: { ${inferenceConfigurationEntries
306
316
  .map(([key, value]) => `${key}: ${value}`)
307
317
  .join(', ')} }`
308
318
  : '';
309
- gqlHandlerContent += `@generation(aiModel: "${aiModel.resourcePath}", systemPrompt: "${systemPrompt}"${inferenceConfigurationGql}) `;
319
+ gqlHandlerContent += `@generation(aiModel: "${aiModel.resourcePath}", systemPrompt: "${escapedSystemPrompt}"${inferenceConfigurationGql}) `;
310
320
  }
311
321
  const gqlField = `${callSignature}: ${returnTypeName} ${gqlHandlerContent}${authString}`;
312
322
  return {
@@ -907,7 +917,9 @@ const schemaPreprocessor = (schema) => {
907
917
  }
908
918
  else if (isConversationRoute(typeDef)) {
909
919
  // TODO: add inferenceConfiguration values to directive.
910
- customMutations.push((0, ConversationSchemaTypes_1.createConversationField)(typeDef, typeName));
920
+ const { field, functionHandler } = (0, ConversationSchemaTypes_1.createConversationField)(typeDef, typeName);
921
+ customMutations.push(field);
922
+ Object.assign(lambdaFunctions, functionHandler);
911
923
  shouldAddConversationTypes = true;
912
924
  }
913
925
  }