Skip to content

Commit 510d373

Browse files
committed
Support for payload object as function argument
1 parent 8787871 commit 510d373

File tree

11 files changed

+87
-68
lines changed

11 files changed

+87
-68
lines changed

packages/client/package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/client/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "polyapi",
3-
"version": "0.1.16",
3+
"version": "0.1.17",
44
"description": "Poly is a CLI tool to help you create and manage your Poly definitions.",
55
"license": "MIT",
66
"repository": {

packages/client/src/commands/generate.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,10 +174,14 @@ const generateTSContextDeclarationFile = async (
174174

175175
const toFunctionData = (func: FunctionDefinitionDto) => ({
176176
...func,
177-
arguments: func.arguments.map((arg) => ({
178-
...arg,
179-
name: toCamelCase(arg.name),
180-
})),
177+
arguments: func.arguments
178+
.filter((arg) => !arg.payload)
179+
.map((arg) => ({
180+
...arg,
181+
name: toCamelCase(arg.name),
182+
})),
183+
payloadArguments: func.arguments.filter((arg) => arg.payload),
184+
hasPayloadArguments: func.arguments.some((arg) => arg.payload),
181185
returnType: func.customCode
182186
? func.returnType
183187
: func.returnType

packages/client/templates/{{context}}.d.ts.hbs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,15 @@ declare module "./index" {
1010
{{name}}: {{interfaceName}};
1111
{{/each}}
1212
{{#each functions}}
13-
{{name}}({{#each arguments}}{{name}}: {{type}}{{#unless @last}}, {{/unless}}{{/each}}): {{{returnType}}};
13+
{{#if hasPayloadArguments}}
14+
{{name}}({{#each arguments}}{{name}}: {{type}}{{#unless @last}}, {{/unless}}{{/each}}, payload: {
15+
{{#each payloadArguments}}
16+
{{name}}: {{type}},
17+
{{/each}}
18+
}): {{{returnType}}};
19+
{{else}}
20+
{{name}}({{#each arguments}}{{name}}: {{type}}{{#unless @last}}, {{/unless}}{{/each}}): {{{returnType}}};
21+
{{/if}}
1422
{{/each}}
1523
{{#each webhookHandles}}
1624
{{name}}(callback: (event: {{{eventType}}}) => any): UnregisterWebhookEventListenerType;

packages/common/src/dto/function/function.dto.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { ArgumentType } from '../..';
33
export interface FunctionArgument {
44
name: string;
55
type: ArgumentType;
6+
payload?: boolean;
67
}
78

89
export interface FunctionDto {
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { ArgumentTypes } from '../../function';
1+
import { ArgumentsMetadata } from '../../function';
22

33
export interface UpdateFunctionDto {
44
name?: string;
55
context?: string;
66
description?: string;
7-
argumentTypes?: ArgumentTypes;
7+
arguments?: ArgumentsMetadata;
88
}

packages/common/src/function.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ export type Method = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'HEAD';
2929

3030
export type ArgumentType = string;
3131

32-
export type ArgumentTypes = {
33-
[key: string]: ArgumentType;
32+
export type ArgumentsMetadata = {
33+
[key: string]: {
34+
type: ArgumentType;
35+
payload: boolean;
36+
};
3437
};
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
-- AlterTable
2+
ALTER TABLE "url_function" ADD COLUMN "arguments_metadata" TEXT;
3+
ALTER TABLE "url_function" DROP COLUMN "argument_types";

prisma/schema.prisma

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -22,26 +22,26 @@ model User {
2222
}
2323

2424
model UrlFunction {
25-
id Int @id @default(autoincrement())
26-
createdAt DateTime @map("created_at")
27-
user User @relation(fields: [userId], references: [id])
28-
userId Int @map("user_id")
29-
name String
30-
context String
31-
description String @default("")
32-
payload String?
33-
method String
34-
url String
35-
headers String?
36-
body String?
37-
auth String?
38-
response String?
39-
responseType String? @map("response_type")
40-
argumentTypes String? @map("argument_types")
41-
trained Boolean @default(false)
42-
publicId String @unique @default(uuid()) @map("public_id")
43-
webhookHandle WebhookHandle? @relation(fields: [webhookHandleId], references: [id])
44-
webhookHandleId String? @unique @map("webhook_handle_id")
25+
id Int @id @default(autoincrement())
26+
createdAt DateTime @map("created_at")
27+
user User @relation(fields: [userId], references: [id])
28+
userId Int @map("user_id")
29+
name String
30+
context String
31+
description String @default("")
32+
payload String?
33+
method String
34+
url String
35+
headers String?
36+
body String?
37+
auth String?
38+
response String?
39+
responseType String? @map("response_type")
40+
argumentsMetadata String? @map("arguments_metadata")
41+
trained Boolean @default(false)
42+
publicId String @unique @default(uuid()) @map("public_id")
43+
webhookHandle WebhookHandle? @relation(fields: [webhookHandleId], references: [id])
44+
webhookHandleId String? @unique @map("webhook_handle_id")
4545
4646
@@map("url_function")
4747
}
@@ -78,24 +78,24 @@ model WebhookHandle {
7878

7979
// store all the messages in a conversation
8080
model ConversationMessage {
81-
id String @id @default(uuid())
81+
id String @id @default(uuid())
8282
createdAt DateTime @default(now())
83-
user User @relation(fields: [userId], references: [id])
84-
userId Int @map("user_id")
85-
name String @default("") // not used for now. in future, will allow the user to have multiple conversations
86-
role String // assistant or user
87-
content String
83+
user User @relation(fields: [userId], references: [id])
84+
userId Int @map("user_id")
85+
name String @default("") // not used for now. in future, will allow the user to have multiple conversations
86+
role String // assistant or user
87+
content String
8888
8989
@@map("conversation_message")
9090
}
9191

9292
// customizable prompt per user
9393
model SystemPrompt {
94-
id String @id @default(uuid())
94+
id String @id @default(uuid())
9595
createdAt DateTime @default(now())
96-
user User @relation(fields: [userId], references: [id])
97-
userId Int @map("user_id")
98-
content String
96+
user User @relation(fields: [userId], references: [id])
97+
userId Int @map("user_id")
98+
content String
9999
100100
@@map("system_prompt")
101-
}
101+
}

science/schema.prisma

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -24,26 +24,26 @@ model User {
2424
}
2525

2626
model UrlFunction {
27-
id Int @id @default(autoincrement())
28-
createdAt DateTime @map("created_at")
29-
user User @relation(fields: [userId], references: [id])
30-
userId Int @map("user_id")
31-
name String
32-
context String
33-
description String @default("")
34-
payload String?
35-
method String
36-
url String
37-
headers String?
38-
body String?
39-
auth String?
40-
response String?
41-
responseType String? @map("response_type")
42-
argumentTypes String? @map("argument_types")
43-
trained Boolean @default(false)
44-
publicId String @unique @default(uuid()) @map("public_id")
45-
webhookHandle WebhookHandle? @relation(fields: [webhookHandleId], references: [id])
46-
webhookHandleId String? @unique @map("webhook_handle_id")
27+
id Int @id @default(autoincrement())
28+
createdAt DateTime @map("created_at")
29+
user User @relation(fields: [userId], references: [id])
30+
userId Int @map("user_id")
31+
name String
32+
context String
33+
description String @default("")
34+
payload String?
35+
method String
36+
url String
37+
headers String?
38+
body String?
39+
auth String?
40+
response String?
41+
responseType String? @map("response_type")
42+
argumentsMetadata String? @map("arguments_metadata")
43+
trained Boolean @default(false)
44+
publicId String @unique @default(uuid()) @map("public_id")
45+
webhookHandle WebhookHandle? @relation(fields: [webhookHandleId], references: [id])
46+
webhookHandleId String? @unique @map("webhook_handle_id")
4747
4848
@@map("url_function")
4949
}
@@ -100,4 +100,4 @@ model SystemPrompt {
100100
content String
101101
102102
@@map("system_prompt")
103-
}
103+
}

0 commit comments

Comments
 (0)