@directus/api 30.0.0 → 31.0.0
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.
- package/dist/app.js +5 -0
- package/dist/auth/drivers/oauth2.js +17 -3
- package/dist/auth/drivers/openid.js +17 -3
- package/dist/controllers/mcp.d.ts +2 -0
- package/dist/controllers/mcp.js +33 -0
- package/dist/controllers/users.js +17 -7
- package/dist/controllers/versions.js +3 -2
- package/dist/database/errors/dialects/mssql.d.ts +1 -1
- package/dist/database/errors/dialects/mssql.js +18 -10
- package/dist/database/migrations/20250813A-add-mcp.d.ts +3 -0
- package/dist/database/migrations/20250813A-add-mcp.js +18 -0
- package/dist/database/run-ast/README.md +46 -0
- package/dist/mcp/define.d.ts +2 -0
- package/dist/mcp/define.js +3 -0
- package/dist/mcp/index.d.ts +1 -0
- package/dist/mcp/index.js +1 -0
- package/dist/mcp/schema.d.ts +485 -0
- package/dist/mcp/schema.js +219 -0
- package/dist/mcp/server.d.ts +97 -0
- package/dist/mcp/server.js +310 -0
- package/dist/mcp/tools/assets.d.ts +3 -0
- package/dist/mcp/tools/assets.js +54 -0
- package/dist/mcp/tools/collections.d.ts +84 -0
- package/dist/mcp/tools/collections.js +90 -0
- package/dist/mcp/tools/fields.d.ts +101 -0
- package/dist/mcp/tools/fields.js +157 -0
- package/dist/mcp/tools/files.d.ts +235 -0
- package/dist/mcp/tools/files.js +103 -0
- package/dist/mcp/tools/flows.d.ts +323 -0
- package/dist/mcp/tools/flows.js +85 -0
- package/dist/mcp/tools/folders.d.ts +95 -0
- package/dist/mcp/tools/folders.js +96 -0
- package/dist/mcp/tools/index.d.ts +15 -0
- package/dist/mcp/tools/index.js +29 -0
- package/dist/mcp/tools/items.d.ts +87 -0
- package/dist/mcp/tools/items.js +141 -0
- package/dist/mcp/tools/operations.d.ts +171 -0
- package/dist/mcp/tools/operations.js +77 -0
- package/dist/mcp/tools/prompts/assets.md +8 -0
- package/dist/mcp/tools/prompts/collections.md +336 -0
- package/dist/mcp/tools/prompts/fields.md +521 -0
- package/dist/mcp/tools/prompts/files.md +180 -0
- package/dist/mcp/tools/prompts/flows.md +495 -0
- package/dist/mcp/tools/prompts/folders.md +34 -0
- package/dist/mcp/tools/prompts/index.d.ts +16 -0
- package/dist/mcp/tools/prompts/index.js +19 -0
- package/dist/mcp/tools/prompts/items.md +317 -0
- package/dist/mcp/tools/prompts/operations.md +721 -0
- package/dist/mcp/tools/prompts/relations.md +386 -0
- package/dist/mcp/tools/prompts/schema.md +130 -0
- package/dist/mcp/tools/prompts/system-prompt-description.md +1 -0
- package/dist/mcp/tools/prompts/system-prompt.md +44 -0
- package/dist/mcp/tools/prompts/trigger-flow.md +214 -0
- package/dist/mcp/tools/relations.d.ts +73 -0
- package/dist/mcp/tools/relations.js +93 -0
- package/dist/mcp/tools/schema.d.ts +54 -0
- package/dist/mcp/tools/schema.js +317 -0
- package/dist/mcp/tools/system.d.ts +3 -0
- package/dist/mcp/tools/system.js +22 -0
- package/dist/mcp/tools/trigger-flow.d.ts +8 -0
- package/dist/mcp/tools/trigger-flow.js +48 -0
- package/dist/mcp/transport.d.ts +13 -0
- package/dist/mcp/transport.js +18 -0
- package/dist/mcp/types.d.ts +56 -0
- package/dist/mcp/types.js +1 -0
- package/dist/services/authentication.js +36 -0
- package/dist/services/fields.js +4 -4
- package/dist/services/items.js +14 -4
- package/dist/services/payload.d.ts +7 -3
- package/dist/services/payload.js +26 -12
- package/dist/services/server.js +1 -0
- package/dist/services/tfa.d.ts +1 -1
- package/dist/services/tfa.js +20 -5
- package/dist/services/versions.d.ts +6 -4
- package/dist/services/versions.js +84 -25
- package/dist/types/auth.d.ts +2 -1
- package/dist/utils/versioning/deep-map-with-schema.d.ts +23 -0
- package/dist/utils/versioning/deep-map-with-schema.js +81 -0
- package/dist/utils/versioning/handle-version.d.ts +2 -2
- package/dist/utils/versioning/handle-version.js +47 -43
- package/dist/utils/versioning/split-recursive.d.ts +4 -0
- package/dist/utils/versioning/split-recursive.js +27 -0
- package/package.json +30 -29
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { isObject } from '@directus/utils';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { FilesService } from '../../services/files.js';
|
|
4
|
+
import { defineTool } from '../define.js';
|
|
5
|
+
import { FileImportItemInputSchema, FileImportItemValidateSchema, FileItemInputSchema, FileItemValidateSchema, PrimaryKeyInputSchema, PrimaryKeyValidateSchema, QueryInputSchema, QueryValidateSchema, } from '../schema.js';
|
|
6
|
+
import prompts from './prompts/index.js';
|
|
7
|
+
export const FilesValidateSchema = z.discriminatedUnion('action', [
|
|
8
|
+
z.strictObject({
|
|
9
|
+
action: z.literal('read'),
|
|
10
|
+
keys: z.array(PrimaryKeyValidateSchema).optional(),
|
|
11
|
+
query: QueryValidateSchema.optional(),
|
|
12
|
+
}),
|
|
13
|
+
z.strictObject({
|
|
14
|
+
action: z.literal('update'),
|
|
15
|
+
data: FileItemValidateSchema,
|
|
16
|
+
keys: z.array(PrimaryKeyValidateSchema).optional(),
|
|
17
|
+
query: QueryValidateSchema.optional(),
|
|
18
|
+
}),
|
|
19
|
+
z.strictObject({
|
|
20
|
+
action: z.literal('delete'),
|
|
21
|
+
keys: z.array(PrimaryKeyValidateSchema),
|
|
22
|
+
}),
|
|
23
|
+
z.strictObject({
|
|
24
|
+
action: z.literal('import'),
|
|
25
|
+
data: z.array(FileImportItemValidateSchema),
|
|
26
|
+
}),
|
|
27
|
+
]);
|
|
28
|
+
const FilesInputSchema = z.object({
|
|
29
|
+
action: z.enum(['read', 'update', 'delete', 'import']).describe('The operation to perform'),
|
|
30
|
+
query: QueryInputSchema.optional(),
|
|
31
|
+
keys: z.array(PrimaryKeyInputSchema).optional(),
|
|
32
|
+
data: z.array(FileItemInputSchema.extend({ ...FileImportItemInputSchema.shape }).partial()).optional(),
|
|
33
|
+
});
|
|
34
|
+
export const files = defineTool({
|
|
35
|
+
name: 'files',
|
|
36
|
+
description: prompts.files,
|
|
37
|
+
annotations: {
|
|
38
|
+
title: 'Directus - Files',
|
|
39
|
+
},
|
|
40
|
+
inputSchema: FilesInputSchema,
|
|
41
|
+
validateSchema: FilesValidateSchema,
|
|
42
|
+
endpoint({ data }) {
|
|
43
|
+
if (!isObject(data) || !('id' in data)) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
return ['files', data['id']];
|
|
47
|
+
},
|
|
48
|
+
async handler({ args, schema, accountability, sanitizedQuery }) {
|
|
49
|
+
const service = new FilesService({
|
|
50
|
+
schema,
|
|
51
|
+
accountability,
|
|
52
|
+
});
|
|
53
|
+
if (args.action === 'read') {
|
|
54
|
+
let result = null;
|
|
55
|
+
if (args.keys) {
|
|
56
|
+
result = await service.readMany(args.keys, sanitizedQuery);
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
result = await service.readByQuery(sanitizedQuery);
|
|
60
|
+
}
|
|
61
|
+
return {
|
|
62
|
+
type: 'text',
|
|
63
|
+
data: result,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
if (args.action === 'update') {
|
|
67
|
+
let updatedKeys = [];
|
|
68
|
+
if (Array.isArray(args.data)) {
|
|
69
|
+
updatedKeys = await service.updateBatch(args.data);
|
|
70
|
+
}
|
|
71
|
+
else if (args.keys) {
|
|
72
|
+
updatedKeys = await service.updateMany(args.keys, args.data);
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
updatedKeys = await service.updateByQuery(sanitizedQuery, args.data);
|
|
76
|
+
}
|
|
77
|
+
const result = await service.readMany(updatedKeys, sanitizedQuery);
|
|
78
|
+
return {
|
|
79
|
+
type: 'text',
|
|
80
|
+
data: result,
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
if (args.action === 'delete') {
|
|
84
|
+
const deletedKeys = await service.deleteMany(args.keys);
|
|
85
|
+
return {
|
|
86
|
+
type: 'text',
|
|
87
|
+
data: deletedKeys,
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
if (args.action === 'import') {
|
|
91
|
+
const savedKeys = [];
|
|
92
|
+
for (const file of args.data) {
|
|
93
|
+
const savedKey = await service.importOne(file.url, file.file);
|
|
94
|
+
savedKeys.push(savedKey);
|
|
95
|
+
}
|
|
96
|
+
return {
|
|
97
|
+
type: 'text',
|
|
98
|
+
data: savedKeys,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
throw new Error('Invalid action.');
|
|
102
|
+
},
|
|
103
|
+
});
|
|
@@ -0,0 +1,323 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const FlowsValidateSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
3
|
+
action: z.ZodLiteral<"create">;
|
|
4
|
+
data: z.ZodObject<{
|
|
5
|
+
id: z.ZodOptional<z.ZodString>;
|
|
6
|
+
name: z.ZodOptional<z.ZodString>;
|
|
7
|
+
icon: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNull]>>;
|
|
8
|
+
color: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNull]>>;
|
|
9
|
+
description: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNull]>>;
|
|
10
|
+
status: z.ZodOptional<z.ZodEnum<{
|
|
11
|
+
active: "active";
|
|
12
|
+
inactive: "inactive";
|
|
13
|
+
}>>;
|
|
14
|
+
trigger: z.ZodOptional<z.ZodUnion<readonly [z.ZodEnum<{
|
|
15
|
+
schedule: "schedule";
|
|
16
|
+
operation: "operation";
|
|
17
|
+
event: "event";
|
|
18
|
+
webhook: "webhook";
|
|
19
|
+
manual: "manual";
|
|
20
|
+
}>, z.ZodNull]>>;
|
|
21
|
+
options: z.ZodOptional<z.ZodUnion<readonly [z.ZodRecord<z.ZodString, z.ZodAny>, z.ZodNull]>>;
|
|
22
|
+
operation: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNull]>>;
|
|
23
|
+
operations: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
24
|
+
id: z.ZodOptional<z.ZodString>;
|
|
25
|
+
name: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNull]>>;
|
|
26
|
+
key: z.ZodOptional<z.ZodString>;
|
|
27
|
+
type: z.ZodOptional<z.ZodString>;
|
|
28
|
+
position_x: z.ZodOptional<z.ZodNumber>;
|
|
29
|
+
position_y: z.ZodOptional<z.ZodNumber>;
|
|
30
|
+
options: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
31
|
+
resolve: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNull]>>;
|
|
32
|
+
reject: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNull]>>;
|
|
33
|
+
flow: z.ZodOptional<z.ZodString>;
|
|
34
|
+
date_created: z.ZodOptional<z.ZodString>;
|
|
35
|
+
user_created: z.ZodOptional<z.ZodString>;
|
|
36
|
+
}, z.core.$strip>>>;
|
|
37
|
+
date_created: z.ZodOptional<z.ZodString>;
|
|
38
|
+
user_created: z.ZodOptional<z.ZodString>;
|
|
39
|
+
accountability: z.ZodOptional<z.ZodUnion<readonly [z.ZodEnum<{
|
|
40
|
+
all: "all";
|
|
41
|
+
activity: "activity";
|
|
42
|
+
}>, z.ZodNull]>>;
|
|
43
|
+
}, z.core.$strip>;
|
|
44
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
45
|
+
action: z.ZodLiteral<"read">;
|
|
46
|
+
query: z.ZodOptional<z.ZodObject<{
|
|
47
|
+
fields: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
48
|
+
sort: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
49
|
+
filter: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
50
|
+
limit: z.ZodOptional<z.ZodNumber>;
|
|
51
|
+
offset: z.ZodOptional<z.ZodNumber>;
|
|
52
|
+
page: z.ZodOptional<z.ZodNumber>;
|
|
53
|
+
search: z.ZodOptional<z.ZodString>;
|
|
54
|
+
deep: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
55
|
+
alias: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
56
|
+
aggregate: z.ZodOptional<z.ZodObject<{
|
|
57
|
+
count: z.ZodArray<z.ZodString>;
|
|
58
|
+
sum: z.ZodArray<z.ZodString>;
|
|
59
|
+
avg: z.ZodArray<z.ZodString>;
|
|
60
|
+
min: z.ZodArray<z.ZodString>;
|
|
61
|
+
max: z.ZodArray<z.ZodString>;
|
|
62
|
+
}, z.core.$strip>>;
|
|
63
|
+
backlink: z.ZodOptional<z.ZodBoolean>;
|
|
64
|
+
version: z.ZodOptional<z.ZodString>;
|
|
65
|
+
versionRaw: z.ZodOptional<z.ZodBoolean>;
|
|
66
|
+
export: z.ZodOptional<z.ZodString>;
|
|
67
|
+
group: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
68
|
+
}, z.core.$strip>>;
|
|
69
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
70
|
+
action: z.ZodLiteral<"update">;
|
|
71
|
+
key: z.ZodString;
|
|
72
|
+
data: z.ZodObject<{
|
|
73
|
+
id: z.ZodOptional<z.ZodString>;
|
|
74
|
+
name: z.ZodOptional<z.ZodString>;
|
|
75
|
+
icon: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNull]>>;
|
|
76
|
+
color: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNull]>>;
|
|
77
|
+
description: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNull]>>;
|
|
78
|
+
status: z.ZodOptional<z.ZodEnum<{
|
|
79
|
+
active: "active";
|
|
80
|
+
inactive: "inactive";
|
|
81
|
+
}>>;
|
|
82
|
+
trigger: z.ZodOptional<z.ZodUnion<readonly [z.ZodEnum<{
|
|
83
|
+
schedule: "schedule";
|
|
84
|
+
operation: "operation";
|
|
85
|
+
event: "event";
|
|
86
|
+
webhook: "webhook";
|
|
87
|
+
manual: "manual";
|
|
88
|
+
}>, z.ZodNull]>>;
|
|
89
|
+
options: z.ZodOptional<z.ZodUnion<readonly [z.ZodRecord<z.ZodString, z.ZodAny>, z.ZodNull]>>;
|
|
90
|
+
operation: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNull]>>;
|
|
91
|
+
operations: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
92
|
+
id: z.ZodOptional<z.ZodString>;
|
|
93
|
+
name: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNull]>>;
|
|
94
|
+
key: z.ZodOptional<z.ZodString>;
|
|
95
|
+
type: z.ZodOptional<z.ZodString>;
|
|
96
|
+
position_x: z.ZodOptional<z.ZodNumber>;
|
|
97
|
+
position_y: z.ZodOptional<z.ZodNumber>;
|
|
98
|
+
options: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
99
|
+
resolve: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNull]>>;
|
|
100
|
+
reject: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNull]>>;
|
|
101
|
+
flow: z.ZodOptional<z.ZodString>;
|
|
102
|
+
date_created: z.ZodOptional<z.ZodString>;
|
|
103
|
+
user_created: z.ZodOptional<z.ZodString>;
|
|
104
|
+
}, z.core.$strip>>>;
|
|
105
|
+
date_created: z.ZodOptional<z.ZodString>;
|
|
106
|
+
user_created: z.ZodOptional<z.ZodString>;
|
|
107
|
+
accountability: z.ZodOptional<z.ZodUnion<readonly [z.ZodEnum<{
|
|
108
|
+
all: "all";
|
|
109
|
+
activity: "activity";
|
|
110
|
+
}>, z.ZodNull]>>;
|
|
111
|
+
}, z.core.$strip>;
|
|
112
|
+
query: z.ZodOptional<z.ZodObject<{
|
|
113
|
+
fields: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
114
|
+
sort: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
115
|
+
filter: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
116
|
+
limit: z.ZodOptional<z.ZodNumber>;
|
|
117
|
+
offset: z.ZodOptional<z.ZodNumber>;
|
|
118
|
+
page: z.ZodOptional<z.ZodNumber>;
|
|
119
|
+
search: z.ZodOptional<z.ZodString>;
|
|
120
|
+
deep: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
121
|
+
alias: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
122
|
+
aggregate: z.ZodOptional<z.ZodObject<{
|
|
123
|
+
count: z.ZodArray<z.ZodString>;
|
|
124
|
+
sum: z.ZodArray<z.ZodString>;
|
|
125
|
+
avg: z.ZodArray<z.ZodString>;
|
|
126
|
+
min: z.ZodArray<z.ZodString>;
|
|
127
|
+
max: z.ZodArray<z.ZodString>;
|
|
128
|
+
}, z.core.$strip>>;
|
|
129
|
+
backlink: z.ZodOptional<z.ZodBoolean>;
|
|
130
|
+
version: z.ZodOptional<z.ZodString>;
|
|
131
|
+
versionRaw: z.ZodOptional<z.ZodBoolean>;
|
|
132
|
+
export: z.ZodOptional<z.ZodString>;
|
|
133
|
+
group: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
134
|
+
}, z.core.$strip>>;
|
|
135
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
136
|
+
action: z.ZodLiteral<"delete">;
|
|
137
|
+
key: z.ZodString;
|
|
138
|
+
}, z.core.$strict>]>;
|
|
139
|
+
export declare const FlowsInputSchema: z.ZodObject<{
|
|
140
|
+
action: z.ZodEnum<{
|
|
141
|
+
delete: "delete";
|
|
142
|
+
update: "update";
|
|
143
|
+
create: "create";
|
|
144
|
+
read: "read";
|
|
145
|
+
}>;
|
|
146
|
+
query: z.ZodOptional<z.ZodObject<{
|
|
147
|
+
fields: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
148
|
+
sort: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
149
|
+
filter: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
150
|
+
limit: z.ZodOptional<z.ZodNumber>;
|
|
151
|
+
offset: z.ZodOptional<z.ZodNumber>;
|
|
152
|
+
page: z.ZodOptional<z.ZodNumber>;
|
|
153
|
+
search: z.ZodOptional<z.ZodString>;
|
|
154
|
+
deep: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
155
|
+
alias: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
156
|
+
aggregate: z.ZodOptional<z.ZodObject<{
|
|
157
|
+
count: z.ZodArray<z.ZodString>;
|
|
158
|
+
sum: z.ZodArray<z.ZodString>;
|
|
159
|
+
avg: z.ZodArray<z.ZodString>;
|
|
160
|
+
min: z.ZodArray<z.ZodString>;
|
|
161
|
+
max: z.ZodArray<z.ZodString>;
|
|
162
|
+
}, z.core.$strip>>;
|
|
163
|
+
backlink: z.ZodOptional<z.ZodBoolean>;
|
|
164
|
+
version: z.ZodOptional<z.ZodString>;
|
|
165
|
+
versionRaw: z.ZodOptional<z.ZodBoolean>;
|
|
166
|
+
export: z.ZodOptional<z.ZodString>;
|
|
167
|
+
group: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
168
|
+
}, z.core.$strip>>;
|
|
169
|
+
data: z.ZodOptional<z.ZodObject<{
|
|
170
|
+
id: z.ZodOptional<z.ZodString>;
|
|
171
|
+
name: z.ZodOptional<z.ZodString>;
|
|
172
|
+
icon: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNull]>>;
|
|
173
|
+
color: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNull]>>;
|
|
174
|
+
description: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNull]>>;
|
|
175
|
+
status: z.ZodOptional<z.ZodEnum<{
|
|
176
|
+
active: "active";
|
|
177
|
+
inactive: "inactive";
|
|
178
|
+
}>>;
|
|
179
|
+
trigger: z.ZodOptional<z.ZodUnion<readonly [z.ZodEnum<{
|
|
180
|
+
schedule: "schedule";
|
|
181
|
+
operation: "operation";
|
|
182
|
+
event: "event";
|
|
183
|
+
webhook: "webhook";
|
|
184
|
+
manual: "manual";
|
|
185
|
+
}>, z.ZodNull]>>;
|
|
186
|
+
options: z.ZodOptional<z.ZodUnion<readonly [z.ZodRecord<z.ZodString, z.ZodAny>, z.ZodNull]>>;
|
|
187
|
+
operation: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNull]>>;
|
|
188
|
+
operations: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
189
|
+
id: z.ZodOptional<z.ZodString>;
|
|
190
|
+
name: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNull]>>;
|
|
191
|
+
key: z.ZodOptional<z.ZodString>;
|
|
192
|
+
type: z.ZodOptional<z.ZodString>;
|
|
193
|
+
position_x: z.ZodOptional<z.ZodNumber>;
|
|
194
|
+
position_y: z.ZodOptional<z.ZodNumber>;
|
|
195
|
+
options: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
196
|
+
resolve: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNull]>>;
|
|
197
|
+
reject: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNull]>>;
|
|
198
|
+
flow: z.ZodOptional<z.ZodString>;
|
|
199
|
+
date_created: z.ZodOptional<z.ZodString>;
|
|
200
|
+
user_created: z.ZodOptional<z.ZodString>;
|
|
201
|
+
}, z.core.$strip>>>;
|
|
202
|
+
date_created: z.ZodOptional<z.ZodString>;
|
|
203
|
+
user_created: z.ZodOptional<z.ZodString>;
|
|
204
|
+
accountability: z.ZodOptional<z.ZodUnion<readonly [z.ZodEnum<{
|
|
205
|
+
all: "all";
|
|
206
|
+
activity: "activity";
|
|
207
|
+
}>, z.ZodNull]>>;
|
|
208
|
+
}, z.core.$strip>>;
|
|
209
|
+
key: z.ZodOptional<z.ZodString>;
|
|
210
|
+
}, z.core.$strip>;
|
|
211
|
+
export declare const flows: import("../types.js").ToolConfig<{
|
|
212
|
+
action: "create";
|
|
213
|
+
data: {
|
|
214
|
+
id?: string | undefined;
|
|
215
|
+
name?: string | undefined;
|
|
216
|
+
icon?: string | null | undefined;
|
|
217
|
+
color?: string | null | undefined;
|
|
218
|
+
description?: string | null | undefined;
|
|
219
|
+
status?: "active" | "inactive" | undefined;
|
|
220
|
+
trigger?: "schedule" | "operation" | "event" | "webhook" | "manual" | null | undefined;
|
|
221
|
+
options?: Record<string, any> | null | undefined;
|
|
222
|
+
operation?: string | null | undefined;
|
|
223
|
+
operations?: {
|
|
224
|
+
id?: string | undefined;
|
|
225
|
+
name?: string | null | undefined;
|
|
226
|
+
key?: string | undefined;
|
|
227
|
+
type?: string | undefined;
|
|
228
|
+
position_x?: number | undefined;
|
|
229
|
+
position_y?: number | undefined;
|
|
230
|
+
options?: Record<string, any> | undefined;
|
|
231
|
+
resolve?: string | null | undefined;
|
|
232
|
+
reject?: string | null | undefined;
|
|
233
|
+
flow?: string | undefined;
|
|
234
|
+
date_created?: string | undefined;
|
|
235
|
+
user_created?: string | undefined;
|
|
236
|
+
}[] | undefined;
|
|
237
|
+
date_created?: string | undefined;
|
|
238
|
+
user_created?: string | undefined;
|
|
239
|
+
accountability?: "all" | "activity" | null | undefined;
|
|
240
|
+
};
|
|
241
|
+
} | {
|
|
242
|
+
action: "read";
|
|
243
|
+
query?: {
|
|
244
|
+
fields?: string[] | undefined;
|
|
245
|
+
sort?: string[] | undefined;
|
|
246
|
+
filter?: Record<string, any> | undefined;
|
|
247
|
+
limit?: number | undefined;
|
|
248
|
+
offset?: number | undefined;
|
|
249
|
+
page?: number | undefined;
|
|
250
|
+
search?: string | undefined;
|
|
251
|
+
deep?: Record<string, any> | undefined;
|
|
252
|
+
alias?: Record<string, string> | undefined;
|
|
253
|
+
aggregate?: {
|
|
254
|
+
count: string[];
|
|
255
|
+
sum: string[];
|
|
256
|
+
avg: string[];
|
|
257
|
+
min: string[];
|
|
258
|
+
max: string[];
|
|
259
|
+
} | undefined;
|
|
260
|
+
backlink?: boolean | undefined;
|
|
261
|
+
version?: string | undefined;
|
|
262
|
+
versionRaw?: boolean | undefined;
|
|
263
|
+
export?: string | undefined;
|
|
264
|
+
group?: string[] | undefined;
|
|
265
|
+
} | undefined;
|
|
266
|
+
} | {
|
|
267
|
+
action: "update";
|
|
268
|
+
key: string;
|
|
269
|
+
data: {
|
|
270
|
+
id?: string | undefined;
|
|
271
|
+
name?: string | undefined;
|
|
272
|
+
icon?: string | null | undefined;
|
|
273
|
+
color?: string | null | undefined;
|
|
274
|
+
description?: string | null | undefined;
|
|
275
|
+
status?: "active" | "inactive" | undefined;
|
|
276
|
+
trigger?: "schedule" | "operation" | "event" | "webhook" | "manual" | null | undefined;
|
|
277
|
+
options?: Record<string, any> | null | undefined;
|
|
278
|
+
operation?: string | null | undefined;
|
|
279
|
+
operations?: {
|
|
280
|
+
id?: string | undefined;
|
|
281
|
+
name?: string | null | undefined;
|
|
282
|
+
key?: string | undefined;
|
|
283
|
+
type?: string | undefined;
|
|
284
|
+
position_x?: number | undefined;
|
|
285
|
+
position_y?: number | undefined;
|
|
286
|
+
options?: Record<string, any> | undefined;
|
|
287
|
+
resolve?: string | null | undefined;
|
|
288
|
+
reject?: string | null | undefined;
|
|
289
|
+
flow?: string | undefined;
|
|
290
|
+
date_created?: string | undefined;
|
|
291
|
+
user_created?: string | undefined;
|
|
292
|
+
}[] | undefined;
|
|
293
|
+
date_created?: string | undefined;
|
|
294
|
+
user_created?: string | undefined;
|
|
295
|
+
accountability?: "all" | "activity" | null | undefined;
|
|
296
|
+
};
|
|
297
|
+
query?: {
|
|
298
|
+
fields?: string[] | undefined;
|
|
299
|
+
sort?: string[] | undefined;
|
|
300
|
+
filter?: Record<string, any> | undefined;
|
|
301
|
+
limit?: number | undefined;
|
|
302
|
+
offset?: number | undefined;
|
|
303
|
+
page?: number | undefined;
|
|
304
|
+
search?: string | undefined;
|
|
305
|
+
deep?: Record<string, any> | undefined;
|
|
306
|
+
alias?: Record<string, string> | undefined;
|
|
307
|
+
aggregate?: {
|
|
308
|
+
count: string[];
|
|
309
|
+
sum: string[];
|
|
310
|
+
avg: string[];
|
|
311
|
+
min: string[];
|
|
312
|
+
max: string[];
|
|
313
|
+
} | undefined;
|
|
314
|
+
backlink?: boolean | undefined;
|
|
315
|
+
version?: string | undefined;
|
|
316
|
+
versionRaw?: boolean | undefined;
|
|
317
|
+
export?: string | undefined;
|
|
318
|
+
group?: string[] | undefined;
|
|
319
|
+
} | undefined;
|
|
320
|
+
} | {
|
|
321
|
+
action: "delete";
|
|
322
|
+
key: string;
|
|
323
|
+
}>;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { isObject } from '@directus/utils';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { FlowsService } from '../../services/flows.js';
|
|
4
|
+
import { defineTool } from '../define.js';
|
|
5
|
+
import { FlowItemInputSchema, FlowItemValidateSchema, QueryInputSchema, QueryValidateSchema } from '../schema.js';
|
|
6
|
+
import prompts from './prompts/index.js';
|
|
7
|
+
export const FlowsValidateSchema = z.discriminatedUnion('action', [
|
|
8
|
+
z.strictObject({
|
|
9
|
+
action: z.literal('create'),
|
|
10
|
+
data: FlowItemValidateSchema,
|
|
11
|
+
}),
|
|
12
|
+
z.strictObject({
|
|
13
|
+
action: z.literal('read'),
|
|
14
|
+
query: QueryValidateSchema.optional(),
|
|
15
|
+
}),
|
|
16
|
+
z.strictObject({
|
|
17
|
+
action: z.literal('update'),
|
|
18
|
+
key: z.string(),
|
|
19
|
+
data: FlowItemValidateSchema,
|
|
20
|
+
query: QueryValidateSchema.optional(),
|
|
21
|
+
}),
|
|
22
|
+
z.strictObject({
|
|
23
|
+
action: z.literal('delete'),
|
|
24
|
+
key: z.string(),
|
|
25
|
+
}),
|
|
26
|
+
]);
|
|
27
|
+
export const FlowsInputSchema = z.object({
|
|
28
|
+
action: z.enum(['create', 'read', 'update', 'delete']).describe('The operation to perform'),
|
|
29
|
+
query: QueryInputSchema.optional(),
|
|
30
|
+
data: FlowItemInputSchema.optional(),
|
|
31
|
+
key: z.string().optional(),
|
|
32
|
+
});
|
|
33
|
+
export const flows = defineTool({
|
|
34
|
+
name: 'flows',
|
|
35
|
+
admin: true,
|
|
36
|
+
description: prompts.flows,
|
|
37
|
+
annotations: {
|
|
38
|
+
title: 'Directus - Flows',
|
|
39
|
+
},
|
|
40
|
+
inputSchema: FlowsInputSchema,
|
|
41
|
+
validateSchema: FlowsValidateSchema,
|
|
42
|
+
endpoint({ data }) {
|
|
43
|
+
if (!isObject(data) || !('id' in data)) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
return ['settings', 'flows', data['id']];
|
|
47
|
+
},
|
|
48
|
+
async handler({ args, schema, accountability, sanitizedQuery }) {
|
|
49
|
+
const flowsService = new FlowsService({
|
|
50
|
+
schema,
|
|
51
|
+
accountability,
|
|
52
|
+
});
|
|
53
|
+
if (args.action === 'create') {
|
|
54
|
+
const savedKey = await flowsService.createOne(args.data);
|
|
55
|
+
const result = await flowsService.readOne(savedKey);
|
|
56
|
+
return {
|
|
57
|
+
type: 'text',
|
|
58
|
+
data: result || null,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
if (args.action === 'read') {
|
|
62
|
+
const result = await flowsService.readByQuery(sanitizedQuery);
|
|
63
|
+
return {
|
|
64
|
+
type: 'text',
|
|
65
|
+
data: result || null,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
if (args.action === 'update') {
|
|
69
|
+
const updatedKey = await flowsService.updateOne(args.key, args.data);
|
|
70
|
+
const result = await flowsService.readOne(updatedKey, sanitizedQuery);
|
|
71
|
+
return {
|
|
72
|
+
type: 'text',
|
|
73
|
+
data: result || null,
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
if (args.action === 'delete') {
|
|
77
|
+
const deletedKey = await flowsService.deleteOne(args.key);
|
|
78
|
+
return {
|
|
79
|
+
type: 'text',
|
|
80
|
+
data: deletedKey,
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
throw new Error('Invalid action.');
|
|
84
|
+
},
|
|
85
|
+
});
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
export declare const folders: import("../types.js").ToolConfig<{
|
|
2
|
+
action: "create";
|
|
3
|
+
data: {
|
|
4
|
+
name: string;
|
|
5
|
+
id?: string | number | undefined;
|
|
6
|
+
parent?: string | undefined;
|
|
7
|
+
} | {
|
|
8
|
+
name: string;
|
|
9
|
+
id?: string | number | undefined;
|
|
10
|
+
parent?: string | undefined;
|
|
11
|
+
}[];
|
|
12
|
+
query?: {
|
|
13
|
+
fields?: string[] | undefined;
|
|
14
|
+
sort?: string[] | undefined;
|
|
15
|
+
filter?: Record<string, any> | undefined;
|
|
16
|
+
limit?: number | undefined;
|
|
17
|
+
offset?: number | undefined;
|
|
18
|
+
page?: number | undefined;
|
|
19
|
+
search?: string | undefined;
|
|
20
|
+
deep?: Record<string, any> | undefined;
|
|
21
|
+
alias?: Record<string, string> | undefined;
|
|
22
|
+
aggregate?: {
|
|
23
|
+
count: string[];
|
|
24
|
+
sum: string[];
|
|
25
|
+
avg: string[];
|
|
26
|
+
min: string[];
|
|
27
|
+
max: string[];
|
|
28
|
+
} | undefined;
|
|
29
|
+
backlink?: boolean | undefined;
|
|
30
|
+
version?: string | undefined;
|
|
31
|
+
versionRaw?: boolean | undefined;
|
|
32
|
+
export?: string | undefined;
|
|
33
|
+
group?: string[] | undefined;
|
|
34
|
+
} | undefined;
|
|
35
|
+
} | {
|
|
36
|
+
action: "read";
|
|
37
|
+
keys?: (string | number)[] | undefined;
|
|
38
|
+
query?: {
|
|
39
|
+
fields?: string[] | undefined;
|
|
40
|
+
sort?: string[] | undefined;
|
|
41
|
+
filter?: Record<string, any> | undefined;
|
|
42
|
+
limit?: number | undefined;
|
|
43
|
+
offset?: number | undefined;
|
|
44
|
+
page?: number | undefined;
|
|
45
|
+
search?: string | undefined;
|
|
46
|
+
deep?: Record<string, any> | undefined;
|
|
47
|
+
alias?: Record<string, string> | undefined;
|
|
48
|
+
aggregate?: {
|
|
49
|
+
count: string[];
|
|
50
|
+
sum: string[];
|
|
51
|
+
avg: string[];
|
|
52
|
+
min: string[];
|
|
53
|
+
max: string[];
|
|
54
|
+
} | undefined;
|
|
55
|
+
backlink?: boolean | undefined;
|
|
56
|
+
version?: string | undefined;
|
|
57
|
+
versionRaw?: boolean | undefined;
|
|
58
|
+
export?: string | undefined;
|
|
59
|
+
group?: string[] | undefined;
|
|
60
|
+
} | undefined;
|
|
61
|
+
} | {
|
|
62
|
+
action: "update";
|
|
63
|
+
data: {
|
|
64
|
+
name: string;
|
|
65
|
+
id?: string | number | undefined;
|
|
66
|
+
parent?: string | undefined;
|
|
67
|
+
};
|
|
68
|
+
keys?: (string | number)[] | undefined;
|
|
69
|
+
query?: {
|
|
70
|
+
fields?: string[] | undefined;
|
|
71
|
+
sort?: string[] | undefined;
|
|
72
|
+
filter?: Record<string, any> | undefined;
|
|
73
|
+
limit?: number | undefined;
|
|
74
|
+
offset?: number | undefined;
|
|
75
|
+
page?: number | undefined;
|
|
76
|
+
search?: string | undefined;
|
|
77
|
+
deep?: Record<string, any> | undefined;
|
|
78
|
+
alias?: Record<string, string> | undefined;
|
|
79
|
+
aggregate?: {
|
|
80
|
+
count: string[];
|
|
81
|
+
sum: string[];
|
|
82
|
+
avg: string[];
|
|
83
|
+
min: string[];
|
|
84
|
+
max: string[];
|
|
85
|
+
} | undefined;
|
|
86
|
+
backlink?: boolean | undefined;
|
|
87
|
+
version?: string | undefined;
|
|
88
|
+
versionRaw?: boolean | undefined;
|
|
89
|
+
export?: string | undefined;
|
|
90
|
+
group?: string[] | undefined;
|
|
91
|
+
} | undefined;
|
|
92
|
+
} | {
|
|
93
|
+
action: "delete";
|
|
94
|
+
keys: (string | number)[];
|
|
95
|
+
}>;
|