Skip to content

Commit 08b335a

Browse files
committed
dev-demo: agent images AdminForth/1955/implement-ability-for-agent-pl
attachments column of the turns with the Upload plugin on it (local or S3 storage with strictContentType), attachmentsField of the agent, and read-only turns and checkpoints.
1 parent 0f7b452 commit 08b335a

5 files changed

Lines changed: 56 additions & 0 deletions

File tree

‎dev-demo/globalPlugins.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ export const globalPlugins = [
107107
responseField: 'response',
108108
debugField: 'dubbug',
109109
checkpointIdField: 'checkpoint_id',
110+
attachmentsField: 'attachments',
110111
},
111112
checkpointResource: {
112113
resourceId: 'agent_checkpoints',
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ALTER TABLE "turns" ADD COLUMN "attachments" TEXT;

‎dev-demo/migrations/prisma/sqlite/schema.prisma‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ model turns {
164164
response String?
165165
dubbug String?
166166
checkpoint_id String?
167+
attachments String?
167168
}
168169

169170
model agent_checkpoints {

‎dev-demo/resources/agent_resources/checkpoints.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@ export default {
88
table: 'agent_checkpoints',
99
resourceId: 'agent_checkpoints',
1010
label: 'Agent Checkpoints',
11+
// written by the agent only; edits here would bypass its checks and its file bookkeeping
12+
options: {
13+
allowedActions: {
14+
create: false,
15+
edit: false,
16+
delete: false,
17+
},
18+
},
1119
columns: [
1220
{ name: 'id', primaryKey: true, type: AdminForthDataTypes.STRING },
1321
{ name: 'thread_id', type: AdminForthDataTypes.STRING },

‎dev-demo/resources/agent_resources/turns.ts‎

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,23 @@
11
import AdminForth, { AdminForthDataTypes } from 'adminforth';
22
import type { AdminForthResourceInput, AdminUser } from 'adminforth';
33
import { randomUUID } from 'crypto';
4+
import UploadPlugin from '../../../plugins/adminforth-upload/index.js';
5+
import AdminForthStorageAdapterLocalFilesystem from '../../../adapters/adminforth-storage-adapter-local/index.js';
6+
import AdminForthAdapterS3Storage from '../../../adapters/adminforth-storage-adapter-amazon-s3/index.js';
47

58
export default {
69
dataSource: 'sqlite',
710
table: 'turns',
811
resourceId: 'turns',
912
label: 'Turns',
13+
// written by the agent only; edits here would bypass its checks and its file bookkeeping
14+
options: {
15+
allowedActions: {
16+
create: false,
17+
edit: false,
18+
delete: false,
19+
},
20+
},
1021
columns: [
1122
{
1223
name: 'id',
@@ -70,5 +81,39 @@ export default {
7081
filter: false,
7182
},
7283
},
84+
{
85+
name: 'attachments',
86+
type: AdminForthDataTypes.JSON,
87+
isArray: {
88+
enabled: true,
89+
itemType: AdminForthDataTypes.STRING,
90+
},
91+
showIn: {
92+
list: false,
93+
show: true,
94+
edit: false,
95+
create: false,
96+
filter: false,
97+
},
98+
},
99+
],
100+
plugins: [
101+
new UploadPlugin({
102+
pathColumnName: 'attachments',
103+
storageAdapter: process.env.USE_S3 !== 'true' ? new AdminForthStorageAdapterLocalFilesystem({
104+
fileSystemFolder: './db/uploads_agent_attachments',
105+
mode: 'private',
106+
signingSecret: '1241245',
107+
}) : new AdminForthAdapterS3Storage({
108+
bucket: process.env.AWS_BUCKET_NAME as string,
109+
region: process.env.AWS_REGION as string,
110+
accessKeyId: process.env.AWS_ACCESS_KEY_ID as string,
111+
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY as string,
112+
strictContentType: true,
113+
}),
114+
allowedFileExtensions: ['png', 'jpg', 'jpeg', 'webp'],
115+
maxFileSize: 1024 * 1024 * 5,
116+
filePath: ({ originalExtension }) => `agent_attachments/${randomUUID()}.${originalExtension}`,
117+
}),
73118
],
74119
} as AdminForthResourceInput;

0 commit comments

Comments
 (0)