Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@aws-amplify/data-schema

Package Overview
Dependencies
Maintainers
9
Versions
176
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@aws-amplify/data-schema - npm Package Compare versions

Comparing version 0.0.0-ai-20240806185636 to 0.0.0-ai-20240807194534

dist/cjs/ai/ConversationSchemaTypes.js

17

dist/cjs/runtime/internals/ai/convertItemToConversation.js

@@ -10,9 +10,14 @@ 'use strict';

const createSendMessageFunction_1 = require("./createSendMessageFunction");
const convertItemToConversation = (conversation, client, modelIntrospection, conversationRouteName, conversationMessageModel, getInternals) => ({
id: conversation.id,
onMessage: (0, createOnMessageFunction_1.createOnMessageFunction)(client, modelIntrospection, conversation.id, conversationRouteName, getInternals),
sendMessage: (0, createSendMessageFunction_1.createSendMessageFunction)(conversation, client, modelIntrospection, conversationRouteName, getInternals),
listMessages: (0, createListMessagesFunction_1.createListMessagesFunction)(client, modelIntrospection, conversation.id, conversationMessageModel, getInternals),
});
const convertItemToConversation = (client, modelIntrospection, conversationId, conversationRouteName, conversationMessageModel, getInternals) => {
if (!conversationId) {
throw new Error(`An error occurred converting a ${conversationRouteName} conversation: Missing ID`);
}
return {
id: conversationId,
onMessage: (0, createOnMessageFunction_1.createOnMessageFunction)(client, modelIntrospection, conversationId, conversationRouteName, getInternals),
sendMessage: (0, createSendMessageFunction_1.createSendMessageFunction)(client, modelIntrospection, conversationId, conversationRouteName, getInternals),
listMessages: (0, createListMessagesFunction_1.createListMessagesFunction)(client, modelIntrospection, conversationId, conversationMessageModel, getInternals),
};
};
exports.convertItemToConversation = convertItemToConversation;
//# sourceMappingURL=convertItemToConversation.js.map

@@ -13,3 +13,3 @@ 'use strict';

return {
data: (0, convertItemToConversation_1.convertItemToConversation)(data, client, modelIntrospection, conversationRouteName, conversationMessageModel, getInternals),
data: (0, convertItemToConversation_1.convertItemToConversation)(client, modelIntrospection, data?.id, conversationRouteName, conversationMessageModel, getInternals),
errors,

@@ -16,0 +16,0 @@ };

@@ -14,3 +14,3 @@ 'use strict';

data: data
? (0, convertItemToConversation_1.convertItemToConversation)(data, client, modelIntrospection, conversationRouteName, conversationMessageModel, getInternals)
? (0, convertItemToConversation_1.convertItemToConversation)(client, modelIntrospection, data.id, conversationRouteName, conversationMessageModel, getInternals)
: data,

@@ -17,0 +17,0 @@ errors,

@@ -13,3 +13,5 @@ 'use strict';

return {
data: data.map((conversation) => (0, convertItemToConversation_1.convertItemToConversation)(conversation, client, modelIntrospection, conversationRouteName, conversationMessageModel, getInternals)),
data: data.map((datum) => {
return (0, convertItemToConversation_1.convertItemToConversation)(client, modelIntrospection, datum.id, conversationRouteName, conversationMessageModel, getInternals);
}),
nextToken,

@@ -16,0 +18,0 @@ errors,

@@ -8,3 +8,3 @@ 'use strict';

const list_1 = require("../operations/list");
const convertItemToConversationMessage_1 = require("./convertItemToConversationMessage");
const pickConversationMessageProperties_1 = require("./pickConversationMessageProperties");
const createListMessagesFunction = (client, modelIntrospection, conversationId, conversationMessageModel, getInternals) => async (input) => {

@@ -14,6 +14,6 @@ const list = (0, list_1.listFactory)(client, modelIntrospection, conversationMessageModel, getInternals);

...input,
filter: { sessionId: { eq: conversationId } },
filter: { conversationId: { eq: conversationId } },
});
return {
data: data.map((item) => (0, convertItemToConversationMessage_1.convertItemToConversationMessage)(item)),
data: data.map((item) => (0, pickConversationMessageProperties_1.pickConversationMessageProperties)(item)),
nextToken,

@@ -20,0 +20,0 @@ errors,

@@ -8,2 +8,3 @@ 'use strict';

const custom_1 = require("../operations/custom");
const pickConversationMessageProperties_1 = require("./pickConversationMessageProperties");
const createOnMessageFunction = (client, modelIntrospection, conversationId, conversationRouteName, getInternals) => (handler) => {

@@ -17,10 +18,4 @@ const { conversations } = modelIntrospection;

const subscribeOperation = (0, custom_1.customOpFactory)(client, modelIntrospection, 'subscription', subscribeSchema, false, getInternals);
return subscribeOperation({ sessionId: conversationId }).subscribe(({ content, sessionId, createdAt, id, sender }) => {
handler({
content: JSON.parse(content),
conversationId: sessionId,
createdAt,
id,
role: sender,
});
return subscribeOperation({ conversationId }).subscribe((data) => {
handler((0, pickConversationMessageProperties_1.pickConversationMessageProperties)(data));
});

@@ -27,0 +22,0 @@ };

@@ -8,4 +8,4 @@ 'use strict';

const custom_1 = require("../operations/custom");
const convertItemToConversationMessage_1 = require("./convertItemToConversationMessage");
const createSendMessageFunction = (conversation, client, modelIntrospection, conversationRouteName, getInternals) => async ({ aiContext, content, toolConfiguration }) => {
const pickConversationMessageProperties_1 = require("./pickConversationMessageProperties");
const createSendMessageFunction = (client, modelIntrospection, conversationId, conversationRouteName, getInternals) => async ({ aiContext, content, toolConfiguration }) => {
const { conversations } = modelIntrospection;

@@ -20,8 +20,8 @@ // Safe guard for standalone function. When called as part of client generation, this should never be falsy.

aiContext: JSON.stringify(aiContext),
content: JSON.stringify(content),
sessionId: conversation.id,
content,
conversationId,
toolConfiguration,
});
return {
data: data ? (0, convertItemToConversationMessage_1.convertItemToConversationMessage)(data) : data,
data: data ? (0, pickConversationMessageProperties_1.pickConversationMessageProperties)(data) : data,
errors,

@@ -28,0 +28,0 @@ };

@@ -122,2 +122,8 @@ 'use strict';

}
function isEnumType(type) {
return type instanceof Object && 'enum' in type;
}
function isInputType(type) {
return type instanceof Object && 'input' in type;
}
/**

@@ -127,10 +133,11 @@ * @param argDef A single argument definition from a custom operation

*/
function argumentBaseTypeString(argDef) {
const requiredFlag = argDef.isRequired ? '!' : '';
if (argDef.type instanceof Object && 'enum' in argDef.type) {
return argDef.type.enum + requiredFlag;
function argumentBaseTypeString({ type, isRequired }) {
const requiredFlag = isRequired ? '!' : '';
if (isEnumType(type)) {
return `${type.enum}${requiredFlag}`;
}
else {
return argDef.type + requiredFlag;
if (isInputType(type)) {
return `${type.input}${requiredFlag}`;
}
return `${type}${requiredFlag}`;
}

@@ -161,6 +168,6 @@ /**

const args = Object.entries(operation.arguments)
.map(([k, v]) => {
const baseType = argumentBaseTypeString(v);
const finalType = v.isArray
? `[${baseType}]${v.isArrayNullable ? '' : '!'}`
.map(([k, argument]) => {
const baseType = argumentBaseTypeString(argument);
const finalType = argument.isArray
? `[${baseType}]${argument.isArrayNullable ? '' : '!'}`
: baseType;

@@ -167,0 +174,0 @@ return `$${k}: ${finalType}`;

@@ -142,3 +142,3 @@ /**

name: string;
type: FieldType;
type: InputFieldType;
isArray: boolean;

@@ -172,5 +172,11 @@ isRequired: boolean;

}
export type FieldType = 'ID' | 'String' | 'Int' | 'Float' | 'AWSDate' | 'AWSTime' | 'AWSDateTime' | 'AWSTimestamp' | 'AWSEmail' | 'AWSURL' | 'AWSIPAddress' | 'Boolean' | 'AWSJSON' | 'AWSPhone' | {
export interface EnumType {
enum: string;
} | ModelFieldType | NonModelFieldType;
}
export interface InputType {
input: string;
}
type ScalarType = 'ID' | 'String' | 'Int' | 'Float' | 'AWSDate' | 'AWSTime' | 'AWSDateTime' | 'AWSTimestamp' | 'AWSEmail' | 'AWSURL' | 'AWSIPAddress' | 'Boolean' | 'AWSJSON' | 'AWSPhone';
export type FieldType = ScalarType | EnumType | ModelFieldType | NonModelFieldType;
export type InputFieldType = ScalarType | EnumType | InputType;
export type FieldAttribute = ModelAttribute;

@@ -177,0 +183,0 @@ /**

import type { Conversation } from '../../../ai/ConversationType';
import type { BaseClient, ClientInternalsGetter, ModelIntrospectionSchema, SchemaModel } from '../../bridge-types';
export declare const convertItemToConversation: (conversation: any, client: BaseClient, modelIntrospection: ModelIntrospectionSchema, conversationRouteName: string, conversationMessageModel: SchemaModel, getInternals: ClientInternalsGetter) => Conversation;
export declare const convertItemToConversation: (client: BaseClient, modelIntrospection: ModelIntrospectionSchema, conversationId: string, conversationRouteName: string, conversationMessageModel: SchemaModel, getInternals: ClientInternalsGetter) => Conversation;
import type { Conversation } from '../../../ai/ConversationType';
import type { BaseClient, ClientInternalsGetter, ModelIntrospectionSchema } from '../../bridge-types';
export declare const createSendMessageFunction: (conversation: any, client: BaseClient, modelIntrospection: ModelIntrospectionSchema, conversationRouteName: string, getInternals: ClientInternalsGetter) => Conversation['sendMessage'];
export declare const createSendMessageFunction: (client: BaseClient, modelIntrospection: ModelIntrospectionSchema, conversationId: string, conversationRouteName: string, getInternals: ClientInternalsGetter) => Conversation['sendMessage'];
{
"name": "@aws-amplify/data-schema",
"version": "0.0.0-ai-20240806185636",
"version": "0.0.0-ai-20240807194534",
"license": "Apache-2.0",

@@ -5,0 +5,0 @@ "repository": {

@@ -166,3 +166,3 @@ /* eslint-disable @typescript-eslint/no-namespace */

name: string;
type: FieldType;
type: InputFieldType;
isArray: boolean;

@@ -212,3 +212,11 @@ isRequired: boolean;

export type FieldType =
export interface EnumType {
enum: string;
}
export interface InputType {
input: string;
}
type ScalarType =
| 'ID'

@@ -227,6 +235,12 @@ | 'String'

| 'AWSJSON'
| 'AWSPhone'
| { enum: string }
| 'AWSPhone';
export type FieldType =
| ScalarType
| EnumType
| ModelFieldType
| NonModelFieldType;
export type InputFieldType = ScalarType | EnumType | InputType;
export type FieldAttribute = ModelAttribute;

@@ -233,0 +247,0 @@

@@ -17,31 +17,38 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.

export const convertItemToConversation = (
conversation: any,
client: BaseClient,
modelIntrospection: ModelIntrospectionSchema,
conversationId: string,
conversationRouteName: string,
conversationMessageModel: SchemaModel,
getInternals: ClientInternalsGetter,
): Conversation => ({
id: conversation.id,
onMessage: createOnMessageFunction(
client as BaseBrowserClient,
modelIntrospection,
conversation.id,
conversationRouteName,
getInternals,
),
sendMessage: createSendMessageFunction(
conversation,
client,
modelIntrospection,
conversationRouteName,
getInternals,
),
listMessages: createListMessagesFunction(
client,
modelIntrospection,
conversation.id,
conversationMessageModel,
getInternals,
),
});
): Conversation => {
if (!conversationId) {
throw new Error(
`An error occurred converting a ${conversationRouteName} conversation: Missing ID`,
);
}
return {
id: conversationId,
onMessage: createOnMessageFunction(
client as BaseBrowserClient,
modelIntrospection,
conversationId,
conversationRouteName,
getInternals,
),
sendMessage: createSendMessageFunction(
client,
modelIntrospection,
conversationId,
conversationRouteName,
getInternals,
),
listMessages: createListMessagesFunction(
client,
modelIntrospection,
conversationId,
conversationMessageModel,
getInternals,
),
};
};
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
import type {
Conversation,
ConversationRoute,
} from '../../../ai/ConversationType';
import type { ConversationRoute } from '../../../ai/ConversationType';
import type { SingularReturnValue } from '../../../runtime/client';

@@ -34,9 +31,9 @@ import type {

getInternals,
) as () => SingularReturnValue<Conversation>;
) as () => SingularReturnValue<Record<string, any>>;
const { data, errors } = await get();
return {
data: convertItemToConversation(
data,
client,
modelIntrospection,
data?.id,
conversationRouteName,

@@ -43,0 +40,0 @@ conversationMessageModel,

// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
import type {
Conversation,
ConversationRoute,
} from '../../../ai/ConversationType';
import type { ConversationRoute } from '../../../ai/ConversationType';
import type { SingularReturnValue } from '../../../runtime/client';

@@ -34,3 +31,5 @@ import type {

getInternals,
) as (args?: Record<string, any>) => SingularReturnValue<Conversation>;
) as (
args?: Record<string, any>,
) => SingularReturnValue<Record<string, any>>;
const { data, errors } = await get({ id });

@@ -40,5 +39,5 @@ return {

? convertItemToConversation(
data,
client,
modelIntrospection,
data.id,
conversationRouteName,

@@ -45,0 +44,0 @@ conversationMessageModel,

// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
import type {
Conversation,
ConversationRoute,
} from '../../../ai/ConversationType';
import type { ConversationRoute } from '../../../ai/ConversationType';
import type { ListReturnValue } from '../../../runtime/client';

@@ -33,15 +30,15 @@ import type {

getInternals,
) as (args?: Record<string, any>) => ListReturnValue<Conversation>;
) as (args?: Record<string, any>) => ListReturnValue<Record<string, any>>;
const { data, nextToken, errors } = await list(input);
return {
data: data.map((conversation: any) =>
convertItemToConversation(
conversation,
data: data.map((datum: Record<string, any>) => {
return convertItemToConversation(
client,
modelIntrospection,
datum.id,
conversationRouteName,
conversationMessageModel,
getInternals,
),
),
);
}),
nextToken,

@@ -48,0 +45,0 @@ errors,

@@ -16,3 +16,3 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.

import { listFactory } from '../operations/list';
import { convertItemToConversationMessage } from './convertItemToConversationMessage';
import { pickConversationMessageProperties } from './pickConversationMessageProperties';

@@ -36,6 +36,6 @@ export const createListMessagesFunction =

...input,
filter: { sessionId: { eq: conversationId } },
filter: { conversationId: { eq: conversationId } },
});
return {
data: data.map((item: any) => convertItemToConversationMessage(item)),
data: data.map((item: any) => pickConversationMessageProperties(item)),
nextToken,

@@ -42,0 +42,0 @@ errors,

@@ -12,2 +12,3 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.

import { customOpFactory } from '../operations/custom';
import { pickConversationMessageProperties } from './pickConversationMessageProperties';

@@ -38,13 +39,5 @@ export const createOnMessageFunction =

) as (args?: Record<string, any>) => Observable<any>;
return subscribeOperation({ sessionId: conversationId }).subscribe(
({ content, sessionId, createdAt, id, sender }: any) => {
handler({
content: JSON.parse(content),
conversationId: sessionId,
createdAt,
id,
role: sender,
});
},
);
return subscribeOperation({ conversationId }).subscribe((data) => {
handler(pickConversationMessageProperties(data));
});
};

@@ -15,9 +15,9 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.

import { customOpFactory } from '../operations/custom';
import { convertItemToConversationMessage } from './convertItemToConversationMessage';
import { pickConversationMessageProperties } from './pickConversationMessageProperties';
export const createSendMessageFunction =
(
conversation: any,
client: BaseClient,
modelIntrospection: ModelIntrospectionSchema,
conversationId: string,
conversationRouteName: string,

@@ -45,10 +45,10 @@ getInternals: ClientInternalsGetter,

aiContext: JSON.stringify(aiContext),
content: JSON.stringify(content),
sessionId: conversation.id,
content,
conversationId,
toolConfiguration,
});
return {
data: data ? convertItemToConversationMessage(data) : data,
data: data ? pickConversationMessageProperties(data) : data,
errors,
};
};

@@ -16,2 +16,6 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.

ModelIntrospectionSchema,
CustomOperationArgument,
InputFieldType,
EnumType,
InputType,
} from '../../bridge-types';

@@ -195,2 +199,10 @@

function isEnumType(type: InputFieldType): type is EnumType {
return type instanceof Object && 'enum' in type;
}
function isInputType(type: InputFieldType): type is InputType {
return type instanceof Object && 'input' in type;
}
/**

@@ -200,11 +212,11 @@ * @param argDef A single argument definition from a custom operation

*/
function argumentBaseTypeString(
argDef: Exclude<CustomOperation['arguments'], undefined>[number],
) {
const requiredFlag = argDef.isRequired ? '!' : '';
if (argDef.type instanceof Object && 'enum' in argDef.type) {
return argDef.type.enum + requiredFlag;
} else {
return argDef.type + requiredFlag;
function argumentBaseTypeString({ type, isRequired }: CustomOperationArgument) {
const requiredFlag = isRequired ? '!' : '';
if (isEnumType(type)) {
return `${type.enum}${requiredFlag}`;
}
if (isInputType(type)) {
return `${type.input}${requiredFlag}`;
}
return `${type}${requiredFlag}`;
}

@@ -236,6 +248,6 @@

const args = Object.entries(operation.arguments)
.map(([k, v]) => {
const baseType = argumentBaseTypeString(v);
const finalType = v.isArray
? `[${baseType}]${v.isArrayNullable ? '' : '!'}`
.map(([k, argument]) => {
const baseType = argumentBaseTypeString(argument);
const finalType = argument.isArray
? `[${baseType}]${argument.isArrayNullable ? '' : '!'}`
: baseType;

@@ -242,0 +254,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc