Skip to content

Commit

Permalink
fix: map 2 function
Browse files Browse the repository at this point in the history
Signed-off-by: dev-callgent <[email protected]>
  • Loading branch information
dev-callgent committed Aug 28, 2024
1 parent 8d7951e commit aeba935
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 13 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"@nestjs/swagger": "^7.3.0",
"@nodeteam/nestjs-prisma-pagination": "^1.0.6",
"@prisma/client": "5.18.0",
"axios": "^1.6.7",
"axios": "^1.7.5",
"bcrypt": "^5.1.1",
"class-transformer": "^0.5.1",
"class-validator": "^0.14.1",
Expand Down
16 changes: 8 additions & 8 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 27 additions & 0 deletions prisma/migrations/20240828045122_event_listener_desc/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
-- AlterTable
ALTER TABLE "Callgent" ALTER COLUMN "tenantPk" SET DEFAULT (current_setting('tenancy.tenantPk')::int);

-- AlterTable
ALTER TABLE "CallgentFunction" ALTER COLUMN "tenantPk" SET DEFAULT (current_setting('tenancy.tenantPk')::int);

-- AlterTable
ALTER TABLE "Endpoint" ALTER COLUMN "tenantPk" SET DEFAULT (current_setting('tenancy.tenantPk')::int);

-- AlterTable
ALTER TABLE "EndpointAuth" ALTER COLUMN "tenantPk" SET DEFAULT (current_setting('tenancy.tenantPk')::int);

-- AlterTable
ALTER TABLE "EventListener" ADD COLUMN "description" VARCHAR(2000) NOT NULL DEFAULT '',
ALTER COLUMN "tenantPk" SET DEFAULT (current_setting('tenancy.tenantPk')::int);

-- AlterTable
ALTER TABLE "Task" ALTER COLUMN "tenantPk" SET DEFAULT (current_setting('tenancy.tenantPk')::int);

-- AlterTable
ALTER TABLE "TaskAction" ALTER COLUMN "tenantPk" SET DEFAULT (current_setting('tenancy.tenantPk')::int);

-- AlterTable
ALTER TABLE "User" ALTER COLUMN "tenantPk" SET DEFAULT (current_setting('tenancy.tenantPk')::int);

-- AlterTable
ALTER TABLE "UserIdentity" ALTER COLUMN "tenantPk" SET DEFAULT (current_setting('tenancy.tenantPk')::int);
5 changes: 3 additions & 2 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,7 @@ model EventListener {
serviceType ServiceType // callgent, service
serviceName String @db.VarChar(255)
funName String @db.VarChar(255)
description String @default("") @db.VarChar(2000)
// TODO add the listener's input/output props in event.context, for automatic checking
/// @DtoReadOnly
Expand All @@ -491,11 +492,11 @@ enum EventCallbackType {

model EventStore {
/// @DtoEntityHidden
pk BigInt @id @default(autoincrement())
pk BigInt @id @default(autoincrement())
/// @DtoCreateApiResponse
/// @DtoUpdateApiResponse
/// @DtoPlainApiResponse
id String @unique @db.VarChar(36)
id String @unique @db.VarChar(36)
/// @Description src entity id which bind to the listener
srcId String @db.VarChar(36)
Expand Down
8 changes: 8 additions & 0 deletions prisma/seed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ function initEventListeners() {
serviceType: 'SERVICE',
serviceName: 'EndpointsService',
funName: 'preprocessClientRequest',
description: 'Find the CEP, then preprocess the request',
createdBy: 'GLOBAL',
priority: (priority += 100),
},
Expand All @@ -50,6 +51,8 @@ function initEventListeners() {
serviceType: 'SERVICE',
serviceName: 'CallgentFunctionsService',
funName: 'loadFunctions',
description:
'Load all entries of the callgent into event.context.functions',
createdBy: 'GLOBAL',
priority: (priority += 100),
},
Expand All @@ -63,6 +66,8 @@ function initEventListeners() {
serviceType: 'SERVICE',
serviceName: 'EventStoresService',
funName: 'loadTargetEvents',
description:
'Load all events of same targetId into event.context.tgtEvents',
createdBy: 'GLOBAL',
priority: (priority += 100),
},
Expand All @@ -76,6 +81,8 @@ function initEventListeners() {
serviceType: 'SERVICE',
serviceName: 'AgentsService',
funName: 'map2Function',
description:
'Map the request event to a endpoint function, put into event.context.map2Function and event.context.functions[0]',
createdBy: 'GLOBAL',
priority: (priority += 100),
},
Expand All @@ -89,6 +96,7 @@ function initEventListeners() {
serviceType: 'SERVICE',
serviceName: 'SandBoxService',
funName: 'map2Args',
description: 'Map the request event to the function arguments',
createdBy: 'GLOBAL',
priority: (priority += 100),
},
Expand Down
9 changes: 8 additions & 1 deletion src/agents/agents.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export class AgentsService {
},
{ funName: '', mapping: '', question: '' },
); // TODO check `funName` exists in callgentFunctions, validating `mapping`
reqEvent.context.function = mapped;
reqEvent.context.map2Function = mapped;

if (mapped.question) {
if (!progressive)
Expand All @@ -81,6 +81,13 @@ export class AgentsService {
if (statusCode == 1)
return { event: reqEvent, callbackName: 'map2FunctionProgressive' };
throw new HttpException(prEvent.message, statusCode);
} else {
const functions = reqEvent.context.functions.filter(
(f) => f.name == mapped.funName,
);
if (functions?.length != 1)
throw new BadRequestException('Failed to map to function: ' + mapped);
reqEvent.context.functions = functions;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/event-listeners/event-object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class EventObject {
}
public readonly id: string;
public statusCode = -1; // for response only
public readonly context: { [key: string]: JsonValue } = {};
public readonly context: { [key: string]: any } = {};
public message: string;
public stopPropagation = false;
public defaultPrevented = false;
Expand Down

0 comments on commit aeba935

Please sign in to comment.