@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,84 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const CollectionsValidateSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
3
|
+
action: z.ZodLiteral<"create">;
|
|
4
|
+
data: z.ZodArray<z.ZodObject<{
|
|
5
|
+
collection: z.ZodString;
|
|
6
|
+
fields: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
7
|
+
field: z.ZodString;
|
|
8
|
+
type: z.ZodString;
|
|
9
|
+
name: z.ZodOptional<z.ZodString>;
|
|
10
|
+
children: z.ZodOptional<z.ZodUnion<readonly [z.ZodArray<z.ZodRecord<z.ZodString, z.ZodAny>>, z.ZodNull]>>;
|
|
11
|
+
collection: z.ZodOptional<z.ZodString>;
|
|
12
|
+
schema: z.ZodOptional<z.ZodUnion<readonly [z.ZodRecord<z.ZodString, z.ZodAny>, z.ZodNull]>>;
|
|
13
|
+
meta: z.ZodOptional<z.ZodUnion<readonly [z.ZodRecord<z.ZodString, z.ZodAny>, z.ZodNull]>>;
|
|
14
|
+
}, z.core.$strip>>>;
|
|
15
|
+
meta: z.ZodOptional<z.ZodUnion<readonly [z.ZodRecord<z.ZodString, z.ZodAny>, z.ZodNull]>>;
|
|
16
|
+
schema: z.ZodOptional<z.ZodUnion<readonly [z.ZodObject<{}, z.core.$strip>, z.ZodNull]>>;
|
|
17
|
+
}, z.core.$strip>>;
|
|
18
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
19
|
+
action: z.ZodLiteral<"read">;
|
|
20
|
+
keys: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
21
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
22
|
+
action: z.ZodLiteral<"update">;
|
|
23
|
+
data: z.ZodArray<z.ZodObject<{
|
|
24
|
+
collection: z.ZodString;
|
|
25
|
+
meta: z.ZodOptional<z.ZodUnion<readonly [z.ZodRecord<z.ZodString, z.ZodAny>, z.ZodNull]>>;
|
|
26
|
+
schema: z.ZodOptional<z.ZodUnion<readonly [z.ZodRecord<z.ZodString, z.ZodAny>, z.ZodNull]>>;
|
|
27
|
+
}, z.core.$strip>>;
|
|
28
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
29
|
+
action: z.ZodLiteral<"delete">;
|
|
30
|
+
keys: z.ZodArray<z.ZodString>;
|
|
31
|
+
}, z.core.$strict>]>;
|
|
32
|
+
export declare const CollectionsInputSchema: z.ZodObject<{
|
|
33
|
+
action: z.ZodEnum<{
|
|
34
|
+
delete: "delete";
|
|
35
|
+
update: "update";
|
|
36
|
+
create: "create";
|
|
37
|
+
read: "read";
|
|
38
|
+
}>;
|
|
39
|
+
keys: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
40
|
+
data: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
41
|
+
collection: z.ZodString;
|
|
42
|
+
fields: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
43
|
+
field: z.ZodString;
|
|
44
|
+
type: z.ZodString;
|
|
45
|
+
name: z.ZodOptional<z.ZodString>;
|
|
46
|
+
children: z.ZodOptional<z.ZodUnion<readonly [z.ZodArray<z.ZodRecord<z.ZodString, z.ZodAny>>, z.ZodNull]>>;
|
|
47
|
+
collection: z.ZodOptional<z.ZodString>;
|
|
48
|
+
schema: z.ZodOptional<z.ZodUnion<readonly [z.ZodRecord<z.ZodString, z.ZodAny>, z.ZodNull]>>;
|
|
49
|
+
meta: z.ZodOptional<z.ZodUnion<readonly [z.ZodRecord<z.ZodString, z.ZodAny>, z.ZodNull]>>;
|
|
50
|
+
}, z.core.$strip>>>;
|
|
51
|
+
meta: z.ZodOptional<z.ZodUnion<readonly [z.ZodRecord<z.ZodString, z.ZodAny>, z.ZodNull]>>;
|
|
52
|
+
schema: z.ZodOptional<z.ZodUnion<readonly [z.ZodObject<{}, z.core.$strip>, z.ZodNull]>>;
|
|
53
|
+
}, z.core.$strip>>>;
|
|
54
|
+
}, z.core.$strip>;
|
|
55
|
+
export declare const collections: import("../types.js").ToolConfig<{
|
|
56
|
+
action: "create";
|
|
57
|
+
data: {
|
|
58
|
+
collection: string;
|
|
59
|
+
fields?: {
|
|
60
|
+
field: string;
|
|
61
|
+
type: string;
|
|
62
|
+
name?: string | undefined;
|
|
63
|
+
children?: Record<string, any>[] | null | undefined;
|
|
64
|
+
collection?: string | undefined;
|
|
65
|
+
schema?: Record<string, any> | null | undefined;
|
|
66
|
+
meta?: Record<string, any> | null | undefined;
|
|
67
|
+
}[] | undefined;
|
|
68
|
+
meta?: Record<string, any> | null | undefined;
|
|
69
|
+
schema?: Record<string, never> | null | undefined;
|
|
70
|
+
}[];
|
|
71
|
+
} | {
|
|
72
|
+
action: "read";
|
|
73
|
+
keys?: string[] | undefined;
|
|
74
|
+
} | {
|
|
75
|
+
action: "update";
|
|
76
|
+
data: {
|
|
77
|
+
collection: string;
|
|
78
|
+
meta?: Record<string, any> | null | undefined;
|
|
79
|
+
schema?: Record<string, any> | null | undefined;
|
|
80
|
+
}[];
|
|
81
|
+
} | {
|
|
82
|
+
action: "delete";
|
|
83
|
+
keys: string[];
|
|
84
|
+
}>;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { InvalidPayloadError } from '@directus/errors';
|
|
2
|
+
import { isObject, toArray } from '@directus/utils';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
import { CollectionsService } from '../../services/collections.js';
|
|
5
|
+
import { defineTool } from '../define.js';
|
|
6
|
+
import { CollectionItemInputSchema, CollectionItemValidateCreateSchema, CollectionItemValidateUpdateSchema, } from '../schema.js';
|
|
7
|
+
import prompts from './prompts/index.js';
|
|
8
|
+
export const CollectionsValidateSchema = z.discriminatedUnion('action', [
|
|
9
|
+
z.strictObject({
|
|
10
|
+
action: z.literal('create'),
|
|
11
|
+
data: z.array(CollectionItemValidateCreateSchema),
|
|
12
|
+
}),
|
|
13
|
+
z.strictObject({
|
|
14
|
+
action: z.literal('read'),
|
|
15
|
+
keys: z.array(z.string()).optional(),
|
|
16
|
+
}),
|
|
17
|
+
z.strictObject({
|
|
18
|
+
action: z.literal('update'),
|
|
19
|
+
data: z.array(CollectionItemValidateUpdateSchema),
|
|
20
|
+
}),
|
|
21
|
+
z.strictObject({
|
|
22
|
+
action: z.literal('delete'),
|
|
23
|
+
keys: z.array(z.string()),
|
|
24
|
+
}),
|
|
25
|
+
]);
|
|
26
|
+
export const CollectionsInputSchema = z.object({
|
|
27
|
+
action: z.enum(['create', 'read', 'update', 'delete']).describe('The operation to perform'),
|
|
28
|
+
keys: z.array(z.string()).optional(),
|
|
29
|
+
data: z.array(CollectionItemInputSchema).optional(),
|
|
30
|
+
});
|
|
31
|
+
export const collections = defineTool({
|
|
32
|
+
name: 'collections',
|
|
33
|
+
admin: true,
|
|
34
|
+
description: prompts.collections,
|
|
35
|
+
annotations: {
|
|
36
|
+
title: 'Directus - Collections',
|
|
37
|
+
},
|
|
38
|
+
inputSchema: CollectionsInputSchema,
|
|
39
|
+
validateSchema: CollectionsValidateSchema,
|
|
40
|
+
endpoint({ data }) {
|
|
41
|
+
if (!isObject(data) || !('collection' in data)) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
return ['content', data['collection']];
|
|
45
|
+
},
|
|
46
|
+
async handler({ args, schema, accountability }) {
|
|
47
|
+
const service = new CollectionsService({
|
|
48
|
+
schema,
|
|
49
|
+
accountability,
|
|
50
|
+
});
|
|
51
|
+
if (args.action === 'create') {
|
|
52
|
+
const data = toArray(args.data);
|
|
53
|
+
const savedKeys = await service.createMany(data);
|
|
54
|
+
const result = await service.readMany(savedKeys);
|
|
55
|
+
return {
|
|
56
|
+
type: 'text',
|
|
57
|
+
data: result || null,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
if (args.action === 'read') {
|
|
61
|
+
let result = null;
|
|
62
|
+
if (args.keys) {
|
|
63
|
+
result = await service.readMany(args.keys);
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
result = await service.readByQuery();
|
|
67
|
+
}
|
|
68
|
+
return {
|
|
69
|
+
type: 'text',
|
|
70
|
+
data: result || null,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
if (args.action === 'update') {
|
|
74
|
+
const updatedKeys = await service.updateBatch(toArray(args.data));
|
|
75
|
+
const result = await service.readMany(updatedKeys);
|
|
76
|
+
return {
|
|
77
|
+
type: 'text',
|
|
78
|
+
data: result || null,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
if (args.action === 'delete') {
|
|
82
|
+
const deletedKeys = await service.deleteMany(args.keys);
|
|
83
|
+
return {
|
|
84
|
+
type: 'text',
|
|
85
|
+
data: deletedKeys,
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
throw new InvalidPayloadError({ reason: 'Invalid action' });
|
|
89
|
+
},
|
|
90
|
+
});
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const FieldsBaseValidateSchema: z.ZodObject<{
|
|
3
|
+
collection: z.ZodString;
|
|
4
|
+
}, z.core.$strict>;
|
|
5
|
+
export declare const FieldsValidateSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
6
|
+
collection: z.ZodString;
|
|
7
|
+
action: z.ZodLiteral<"create">;
|
|
8
|
+
data: z.ZodUnion<readonly [z.ZodArray<z.ZodObject<{
|
|
9
|
+
field: z.ZodString;
|
|
10
|
+
type: z.ZodNullable<z.ZodString>;
|
|
11
|
+
name: z.ZodOptional<z.ZodString>;
|
|
12
|
+
collection: z.ZodOptional<z.ZodString>;
|
|
13
|
+
schema: z.ZodOptional<z.ZodUnion<readonly [z.ZodRecord<z.ZodString, z.ZodAny>, z.ZodNull]>>;
|
|
14
|
+
meta: z.ZodOptional<z.ZodUnion<readonly [z.ZodRecord<z.ZodString, z.ZodAny>, z.ZodNull]>>;
|
|
15
|
+
}, z.core.$strip>>, z.ZodObject<{
|
|
16
|
+
field: z.ZodString;
|
|
17
|
+
type: z.ZodNullable<z.ZodString>;
|
|
18
|
+
name: z.ZodOptional<z.ZodString>;
|
|
19
|
+
collection: z.ZodOptional<z.ZodString>;
|
|
20
|
+
schema: z.ZodOptional<z.ZodUnion<readonly [z.ZodRecord<z.ZodString, z.ZodAny>, z.ZodNull]>>;
|
|
21
|
+
meta: z.ZodOptional<z.ZodUnion<readonly [z.ZodRecord<z.ZodString, z.ZodAny>, z.ZodNull]>>;
|
|
22
|
+
}, z.core.$strip>]>;
|
|
23
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
24
|
+
action: z.ZodLiteral<"read">;
|
|
25
|
+
collection: z.ZodOptional<z.ZodString>;
|
|
26
|
+
field: z.ZodOptional<z.ZodString>;
|
|
27
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
28
|
+
collection: z.ZodString;
|
|
29
|
+
action: z.ZodLiteral<"update">;
|
|
30
|
+
data: z.ZodArray<z.ZodObject<{
|
|
31
|
+
field: z.ZodString;
|
|
32
|
+
type: z.ZodString;
|
|
33
|
+
name: z.ZodOptional<z.ZodString>;
|
|
34
|
+
children: z.ZodOptional<z.ZodUnion<readonly [z.ZodArray<z.ZodRecord<z.ZodString, z.ZodAny>>, z.ZodNull]>>;
|
|
35
|
+
collection: z.ZodOptional<z.ZodString>;
|
|
36
|
+
schema: z.ZodOptional<z.ZodUnion<readonly [z.ZodRecord<z.ZodString, z.ZodAny>, z.ZodNull]>>;
|
|
37
|
+
meta: z.ZodOptional<z.ZodUnion<readonly [z.ZodRecord<z.ZodString, z.ZodAny>, z.ZodNull]>>;
|
|
38
|
+
}, z.core.$strip>>;
|
|
39
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
40
|
+
collection: z.ZodString;
|
|
41
|
+
action: z.ZodLiteral<"delete">;
|
|
42
|
+
field: z.ZodString;
|
|
43
|
+
}, z.core.$strict>]>;
|
|
44
|
+
export declare const FieldsInputSchema: z.ZodObject<{
|
|
45
|
+
action: z.ZodEnum<{
|
|
46
|
+
delete: "delete";
|
|
47
|
+
update: "update";
|
|
48
|
+
create: "create";
|
|
49
|
+
read: "read";
|
|
50
|
+
}>;
|
|
51
|
+
collection: z.ZodOptional<z.ZodString>;
|
|
52
|
+
field: z.ZodOptional<z.ZodString>;
|
|
53
|
+
data: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
54
|
+
field: z.ZodOptional<z.ZodString>;
|
|
55
|
+
type: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
56
|
+
name: z.ZodOptional<z.ZodOptional<z.ZodString>>;
|
|
57
|
+
collection: z.ZodOptional<z.ZodOptional<z.ZodString>>;
|
|
58
|
+
schema: z.ZodOptional<z.ZodOptional<z.ZodUnion<readonly [z.ZodRecord<z.ZodString, z.ZodAny>, z.ZodNull]>>>;
|
|
59
|
+
meta: z.ZodOptional<z.ZodOptional<z.ZodUnion<readonly [z.ZodRecord<z.ZodString, z.ZodAny>, z.ZodNull]>>>;
|
|
60
|
+
children: z.ZodOptional<z.ZodOptional<z.ZodUnion<readonly [z.ZodArray<z.ZodRecord<z.ZodString, z.ZodAny>>, z.ZodNull]>>>;
|
|
61
|
+
}, z.core.$strip>>>;
|
|
62
|
+
}, z.core.$strip>;
|
|
63
|
+
export declare const fields: import("../types.js").ToolConfig<{
|
|
64
|
+
collection: string;
|
|
65
|
+
action: "create";
|
|
66
|
+
data: {
|
|
67
|
+
field: string;
|
|
68
|
+
type: string | null;
|
|
69
|
+
name?: string | undefined;
|
|
70
|
+
collection?: string | undefined;
|
|
71
|
+
schema?: Record<string, any> | null | undefined;
|
|
72
|
+
meta?: Record<string, any> | null | undefined;
|
|
73
|
+
} | {
|
|
74
|
+
field: string;
|
|
75
|
+
type: string | null;
|
|
76
|
+
name?: string | undefined;
|
|
77
|
+
collection?: string | undefined;
|
|
78
|
+
schema?: Record<string, any> | null | undefined;
|
|
79
|
+
meta?: Record<string, any> | null | undefined;
|
|
80
|
+
}[];
|
|
81
|
+
} | {
|
|
82
|
+
action: "read";
|
|
83
|
+
collection?: string | undefined;
|
|
84
|
+
field?: string | undefined;
|
|
85
|
+
} | {
|
|
86
|
+
collection: string;
|
|
87
|
+
action: "update";
|
|
88
|
+
data: {
|
|
89
|
+
field: string;
|
|
90
|
+
type: string;
|
|
91
|
+
name?: string | undefined;
|
|
92
|
+
children?: Record<string, any>[] | null | undefined;
|
|
93
|
+
collection?: string | undefined;
|
|
94
|
+
schema?: Record<string, any> | null | undefined;
|
|
95
|
+
meta?: Record<string, any> | null | undefined;
|
|
96
|
+
}[];
|
|
97
|
+
} | {
|
|
98
|
+
collection: string;
|
|
99
|
+
action: "delete";
|
|
100
|
+
field: string;
|
|
101
|
+
}>;
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { InvalidPayloadError } from '@directus/errors';
|
|
2
|
+
import { toArray } from '@directus/utils';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
import { clearSystemCache } from '../../cache.js';
|
|
5
|
+
import getDatabase from '../../database/index.js';
|
|
6
|
+
import { FieldsService } from '../../services/fields.js';
|
|
7
|
+
import { getSchema } from '../../utils/get-schema.js';
|
|
8
|
+
import { shouldClearCache } from '../../utils/should-clear-cache.js';
|
|
9
|
+
import { transaction } from '../../utils/transaction.js';
|
|
10
|
+
import { defineTool } from '../define.js';
|
|
11
|
+
import { FieldItemInputSchema, FieldItemValidateSchema, RawFieldItemInputSchema, RawFieldItemValidateSchema, } from '../schema.js';
|
|
12
|
+
import prompts from './prompts/index.js';
|
|
13
|
+
export const FieldsBaseValidateSchema = z.strictObject({
|
|
14
|
+
collection: z.string(),
|
|
15
|
+
});
|
|
16
|
+
export const FieldsValidateSchema = z.discriminatedUnion('action', [
|
|
17
|
+
FieldsBaseValidateSchema.extend({
|
|
18
|
+
action: z.literal('create'),
|
|
19
|
+
data: z.union([z.array(FieldItemValidateSchema), FieldItemValidateSchema]),
|
|
20
|
+
}),
|
|
21
|
+
z.object({
|
|
22
|
+
action: z.literal('read'),
|
|
23
|
+
collection: z.string().optional(),
|
|
24
|
+
field: z.string().optional(),
|
|
25
|
+
}),
|
|
26
|
+
FieldsBaseValidateSchema.extend({
|
|
27
|
+
action: z.literal('update'),
|
|
28
|
+
data: z.array(RawFieldItemValidateSchema),
|
|
29
|
+
}),
|
|
30
|
+
FieldsBaseValidateSchema.extend({
|
|
31
|
+
action: z.literal('delete'),
|
|
32
|
+
field: z.string(),
|
|
33
|
+
}),
|
|
34
|
+
]);
|
|
35
|
+
export const FieldsInputSchema = z.object({
|
|
36
|
+
action: z.enum(['read', 'create', 'update', 'delete']).describe('The operation to perform'),
|
|
37
|
+
collection: z.string().describe('The name of the collection').optional(),
|
|
38
|
+
field: z.string().optional(),
|
|
39
|
+
data: z
|
|
40
|
+
.array(FieldItemInputSchema.extend({
|
|
41
|
+
children: RawFieldItemInputSchema.shape.children,
|
|
42
|
+
}).partial())
|
|
43
|
+
.optional(),
|
|
44
|
+
});
|
|
45
|
+
export const fields = defineTool({
|
|
46
|
+
name: 'fields',
|
|
47
|
+
admin: true,
|
|
48
|
+
description: prompts.fields,
|
|
49
|
+
annotations: {
|
|
50
|
+
title: 'Directus - Fields',
|
|
51
|
+
},
|
|
52
|
+
inputSchema: FieldsInputSchema,
|
|
53
|
+
validateSchema: FieldsValidateSchema,
|
|
54
|
+
async handler({ args, schema, accountability }) {
|
|
55
|
+
let service = new FieldsService({
|
|
56
|
+
schema,
|
|
57
|
+
accountability,
|
|
58
|
+
});
|
|
59
|
+
if (args.action === 'create') {
|
|
60
|
+
const fields = toArray(args.data);
|
|
61
|
+
const knex = getDatabase();
|
|
62
|
+
const result = [];
|
|
63
|
+
await transaction(knex, async (trx) => {
|
|
64
|
+
service = new FieldsService({
|
|
65
|
+
schema,
|
|
66
|
+
accountability,
|
|
67
|
+
knex: trx,
|
|
68
|
+
});
|
|
69
|
+
for (const field of fields) {
|
|
70
|
+
await service.createField(args.collection, field, undefined, {
|
|
71
|
+
autoPurgeCache: false,
|
|
72
|
+
autoPurgeSystemCache: false,
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
// manually clear cache
|
|
77
|
+
if (shouldClearCache(service.cache)) {
|
|
78
|
+
await service.cache.clear();
|
|
79
|
+
}
|
|
80
|
+
await clearSystemCache();
|
|
81
|
+
service = new FieldsService({
|
|
82
|
+
schema: await getSchema(),
|
|
83
|
+
accountability,
|
|
84
|
+
});
|
|
85
|
+
for (const field of fields) {
|
|
86
|
+
const createdField = await service.readOne(args.collection, field.field);
|
|
87
|
+
result.push(createdField);
|
|
88
|
+
}
|
|
89
|
+
return {
|
|
90
|
+
type: 'text',
|
|
91
|
+
data: result || null,
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
if (args.action === 'read') {
|
|
95
|
+
let result = null;
|
|
96
|
+
if (args.collection) {
|
|
97
|
+
if (args.field) {
|
|
98
|
+
result = await service.readOne(args.collection, args.field);
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
result = await service.readAll(args.collection);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
result = await service.readAll();
|
|
106
|
+
}
|
|
107
|
+
return {
|
|
108
|
+
type: 'text',
|
|
109
|
+
data: result || null,
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
if (args.action === 'update') {
|
|
113
|
+
const fields = toArray(args.data);
|
|
114
|
+
const knex = getDatabase();
|
|
115
|
+
const result = [];
|
|
116
|
+
await transaction(knex, async (trx) => {
|
|
117
|
+
service = new FieldsService({
|
|
118
|
+
schema,
|
|
119
|
+
accountability,
|
|
120
|
+
knex: trx,
|
|
121
|
+
});
|
|
122
|
+
for (const field of fields) {
|
|
123
|
+
await service.updateField(args.collection, field, {
|
|
124
|
+
autoPurgeCache: false,
|
|
125
|
+
autoPurgeSystemCache: false,
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
// manually clear cache
|
|
130
|
+
if (shouldClearCache(service.cache)) {
|
|
131
|
+
await service.cache.clear();
|
|
132
|
+
}
|
|
133
|
+
await clearSystemCache();
|
|
134
|
+
service = new FieldsService({
|
|
135
|
+
schema: await getSchema(),
|
|
136
|
+
accountability,
|
|
137
|
+
});
|
|
138
|
+
for (const field of fields) {
|
|
139
|
+
const updatedField = await service.readOne(args.collection, field.field);
|
|
140
|
+
result.push(updatedField);
|
|
141
|
+
}
|
|
142
|
+
return {
|
|
143
|
+
type: 'text',
|
|
144
|
+
data: result || null,
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
if (args.action === 'delete') {
|
|
148
|
+
const { collection, field } = args;
|
|
149
|
+
await service.deleteField(collection, field);
|
|
150
|
+
return {
|
|
151
|
+
type: 'text',
|
|
152
|
+
data: { collection, field },
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
throw new InvalidPayloadError({ reason: 'Invalid action' });
|
|
156
|
+
},
|
|
157
|
+
});
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const FilesValidateSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
3
|
+
action: z.ZodLiteral<"read">;
|
|
4
|
+
keys: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodNumber, z.ZodString]>>>;
|
|
5
|
+
query: z.ZodOptional<z.ZodObject<{
|
|
6
|
+
fields: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
7
|
+
sort: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
8
|
+
filter: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
9
|
+
limit: z.ZodOptional<z.ZodNumber>;
|
|
10
|
+
offset: z.ZodOptional<z.ZodNumber>;
|
|
11
|
+
page: z.ZodOptional<z.ZodNumber>;
|
|
12
|
+
search: z.ZodOptional<z.ZodString>;
|
|
13
|
+
deep: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
14
|
+
alias: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
15
|
+
aggregate: z.ZodOptional<z.ZodObject<{
|
|
16
|
+
count: z.ZodArray<z.ZodString>;
|
|
17
|
+
sum: z.ZodArray<z.ZodString>;
|
|
18
|
+
avg: z.ZodArray<z.ZodString>;
|
|
19
|
+
min: z.ZodArray<z.ZodString>;
|
|
20
|
+
max: z.ZodArray<z.ZodString>;
|
|
21
|
+
}, z.core.$strip>>;
|
|
22
|
+
backlink: z.ZodOptional<z.ZodBoolean>;
|
|
23
|
+
version: z.ZodOptional<z.ZodString>;
|
|
24
|
+
versionRaw: z.ZodOptional<z.ZodBoolean>;
|
|
25
|
+
export: z.ZodOptional<z.ZodString>;
|
|
26
|
+
group: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
27
|
+
}, z.core.$strip>>;
|
|
28
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
29
|
+
action: z.ZodLiteral<"update">;
|
|
30
|
+
data: z.ZodObject<{
|
|
31
|
+
id: z.ZodOptional<z.ZodString>;
|
|
32
|
+
storage: z.ZodOptional<z.ZodString>;
|
|
33
|
+
filename_disk: z.ZodOptional<z.ZodString>;
|
|
34
|
+
filename_download: z.ZodOptional<z.ZodString>;
|
|
35
|
+
title: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNull]>>;
|
|
36
|
+
type: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNull]>>;
|
|
37
|
+
folder: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNull]>>;
|
|
38
|
+
created_on: z.ZodOptional<z.ZodString>;
|
|
39
|
+
uploaded_by: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNull]>>;
|
|
40
|
+
uploaded_on: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNull]>>;
|
|
41
|
+
modified_by: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNull]>>;
|
|
42
|
+
modified_on: z.ZodOptional<z.ZodString>;
|
|
43
|
+
charset: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNull]>>;
|
|
44
|
+
filesize: z.ZodOptional<z.ZodNumber>;
|
|
45
|
+
width: z.ZodOptional<z.ZodUnion<readonly [z.ZodNumber, z.ZodNull]>>;
|
|
46
|
+
height: z.ZodOptional<z.ZodUnion<readonly [z.ZodNumber, z.ZodNull]>>;
|
|
47
|
+
duration: z.ZodOptional<z.ZodUnion<readonly [z.ZodNumber, z.ZodNull]>>;
|
|
48
|
+
embed: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNull]>>;
|
|
49
|
+
description: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNull]>>;
|
|
50
|
+
location: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNull]>>;
|
|
51
|
+
tags: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNull]>>;
|
|
52
|
+
metadata: z.ZodOptional<z.ZodUnion<readonly [z.ZodRecord<z.ZodString, z.ZodAny>, z.ZodNull]>>;
|
|
53
|
+
focal_point_x: z.ZodOptional<z.ZodUnion<readonly [z.ZodNumber, z.ZodNull]>>;
|
|
54
|
+
focal_point_y: z.ZodOptional<z.ZodUnion<readonly [z.ZodNumber, z.ZodNull]>>;
|
|
55
|
+
tus_id: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNull]>>;
|
|
56
|
+
tus_data: z.ZodOptional<z.ZodUnion<readonly [z.ZodRecord<z.ZodString, z.ZodAny>, z.ZodNull]>>;
|
|
57
|
+
}, z.core.$strip>;
|
|
58
|
+
keys: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodNumber, z.ZodString]>>>;
|
|
59
|
+
query: z.ZodOptional<z.ZodObject<{
|
|
60
|
+
fields: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
61
|
+
sort: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
62
|
+
filter: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
63
|
+
limit: z.ZodOptional<z.ZodNumber>;
|
|
64
|
+
offset: z.ZodOptional<z.ZodNumber>;
|
|
65
|
+
page: z.ZodOptional<z.ZodNumber>;
|
|
66
|
+
search: z.ZodOptional<z.ZodString>;
|
|
67
|
+
deep: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
68
|
+
alias: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
69
|
+
aggregate: z.ZodOptional<z.ZodObject<{
|
|
70
|
+
count: z.ZodArray<z.ZodString>;
|
|
71
|
+
sum: z.ZodArray<z.ZodString>;
|
|
72
|
+
avg: z.ZodArray<z.ZodString>;
|
|
73
|
+
min: z.ZodArray<z.ZodString>;
|
|
74
|
+
max: z.ZodArray<z.ZodString>;
|
|
75
|
+
}, z.core.$strip>>;
|
|
76
|
+
backlink: z.ZodOptional<z.ZodBoolean>;
|
|
77
|
+
version: z.ZodOptional<z.ZodString>;
|
|
78
|
+
versionRaw: z.ZodOptional<z.ZodBoolean>;
|
|
79
|
+
export: z.ZodOptional<z.ZodString>;
|
|
80
|
+
group: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
81
|
+
}, z.core.$strip>>;
|
|
82
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
83
|
+
action: z.ZodLiteral<"delete">;
|
|
84
|
+
keys: z.ZodArray<z.ZodUnion<readonly [z.ZodNumber, z.ZodString]>>;
|
|
85
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
86
|
+
action: z.ZodLiteral<"import">;
|
|
87
|
+
data: z.ZodArray<z.ZodObject<{
|
|
88
|
+
url: z.ZodString;
|
|
89
|
+
file: z.ZodObject<{
|
|
90
|
+
id: z.ZodOptional<z.ZodString>;
|
|
91
|
+
storage: z.ZodOptional<z.ZodString>;
|
|
92
|
+
filename_disk: z.ZodOptional<z.ZodString>;
|
|
93
|
+
filename_download: z.ZodOptional<z.ZodString>;
|
|
94
|
+
title: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNull]>>;
|
|
95
|
+
type: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNull]>>;
|
|
96
|
+
folder: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNull]>>;
|
|
97
|
+
created_on: z.ZodOptional<z.ZodString>;
|
|
98
|
+
uploaded_by: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNull]>>;
|
|
99
|
+
uploaded_on: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNull]>>;
|
|
100
|
+
modified_by: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNull]>>;
|
|
101
|
+
modified_on: z.ZodOptional<z.ZodString>;
|
|
102
|
+
charset: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNull]>>;
|
|
103
|
+
filesize: z.ZodOptional<z.ZodNumber>;
|
|
104
|
+
width: z.ZodOptional<z.ZodUnion<readonly [z.ZodNumber, z.ZodNull]>>;
|
|
105
|
+
height: z.ZodOptional<z.ZodUnion<readonly [z.ZodNumber, z.ZodNull]>>;
|
|
106
|
+
duration: z.ZodOptional<z.ZodUnion<readonly [z.ZodNumber, z.ZodNull]>>;
|
|
107
|
+
embed: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNull]>>;
|
|
108
|
+
description: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNull]>>;
|
|
109
|
+
location: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNull]>>;
|
|
110
|
+
tags: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNull]>>;
|
|
111
|
+
metadata: z.ZodOptional<z.ZodUnion<readonly [z.ZodRecord<z.ZodString, z.ZodAny>, z.ZodNull]>>;
|
|
112
|
+
focal_point_x: z.ZodOptional<z.ZodUnion<readonly [z.ZodNumber, z.ZodNull]>>;
|
|
113
|
+
focal_point_y: z.ZodOptional<z.ZodUnion<readonly [z.ZodNumber, z.ZodNull]>>;
|
|
114
|
+
tus_id: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNull]>>;
|
|
115
|
+
tus_data: z.ZodOptional<z.ZodUnion<readonly [z.ZodRecord<z.ZodString, z.ZodAny>, z.ZodNull]>>;
|
|
116
|
+
}, z.core.$strip>;
|
|
117
|
+
}, z.core.$strip>>;
|
|
118
|
+
}, z.core.$strict>]>;
|
|
119
|
+
export declare const files: import("../types.js").ToolConfig<{
|
|
120
|
+
action: "read";
|
|
121
|
+
keys?: (string | number)[] | undefined;
|
|
122
|
+
query?: {
|
|
123
|
+
fields?: string[] | undefined;
|
|
124
|
+
sort?: string[] | undefined;
|
|
125
|
+
filter?: Record<string, any> | undefined;
|
|
126
|
+
limit?: number | undefined;
|
|
127
|
+
offset?: number | undefined;
|
|
128
|
+
page?: number | undefined;
|
|
129
|
+
search?: string | undefined;
|
|
130
|
+
deep?: Record<string, any> | undefined;
|
|
131
|
+
alias?: Record<string, string> | undefined;
|
|
132
|
+
aggregate?: {
|
|
133
|
+
count: string[];
|
|
134
|
+
sum: string[];
|
|
135
|
+
avg: string[];
|
|
136
|
+
min: string[];
|
|
137
|
+
max: string[];
|
|
138
|
+
} | undefined;
|
|
139
|
+
backlink?: boolean | undefined;
|
|
140
|
+
version?: string | undefined;
|
|
141
|
+
versionRaw?: boolean | undefined;
|
|
142
|
+
export?: string | undefined;
|
|
143
|
+
group?: string[] | undefined;
|
|
144
|
+
} | undefined;
|
|
145
|
+
} | {
|
|
146
|
+
action: "update";
|
|
147
|
+
data: {
|
|
148
|
+
id?: string | undefined;
|
|
149
|
+
storage?: string | undefined;
|
|
150
|
+
filename_disk?: string | undefined;
|
|
151
|
+
filename_download?: string | undefined;
|
|
152
|
+
title?: string | null | undefined;
|
|
153
|
+
type?: string | null | undefined;
|
|
154
|
+
folder?: string | null | undefined;
|
|
155
|
+
created_on?: string | undefined;
|
|
156
|
+
uploaded_by?: string | null | undefined;
|
|
157
|
+
uploaded_on?: string | null | undefined;
|
|
158
|
+
modified_by?: string | null | undefined;
|
|
159
|
+
modified_on?: string | undefined;
|
|
160
|
+
charset?: string | null | undefined;
|
|
161
|
+
filesize?: number | undefined;
|
|
162
|
+
width?: number | null | undefined;
|
|
163
|
+
height?: number | null | undefined;
|
|
164
|
+
duration?: number | null | undefined;
|
|
165
|
+
embed?: string | null | undefined;
|
|
166
|
+
description?: string | null | undefined;
|
|
167
|
+
location?: string | null | undefined;
|
|
168
|
+
tags?: string | null | undefined;
|
|
169
|
+
metadata?: Record<string, any> | null | undefined;
|
|
170
|
+
focal_point_x?: number | null | undefined;
|
|
171
|
+
focal_point_y?: number | null | undefined;
|
|
172
|
+
tus_id?: string | null | undefined;
|
|
173
|
+
tus_data?: Record<string, any> | null | undefined;
|
|
174
|
+
};
|
|
175
|
+
keys?: (string | number)[] | undefined;
|
|
176
|
+
query?: {
|
|
177
|
+
fields?: string[] | undefined;
|
|
178
|
+
sort?: string[] | undefined;
|
|
179
|
+
filter?: Record<string, any> | undefined;
|
|
180
|
+
limit?: number | undefined;
|
|
181
|
+
offset?: number | undefined;
|
|
182
|
+
page?: number | undefined;
|
|
183
|
+
search?: string | undefined;
|
|
184
|
+
deep?: Record<string, any> | undefined;
|
|
185
|
+
alias?: Record<string, string> | undefined;
|
|
186
|
+
aggregate?: {
|
|
187
|
+
count: string[];
|
|
188
|
+
sum: string[];
|
|
189
|
+
avg: string[];
|
|
190
|
+
min: string[];
|
|
191
|
+
max: string[];
|
|
192
|
+
} | undefined;
|
|
193
|
+
backlink?: boolean | undefined;
|
|
194
|
+
version?: string | undefined;
|
|
195
|
+
versionRaw?: boolean | undefined;
|
|
196
|
+
export?: string | undefined;
|
|
197
|
+
group?: string[] | undefined;
|
|
198
|
+
} | undefined;
|
|
199
|
+
} | {
|
|
200
|
+
action: "delete";
|
|
201
|
+
keys: (string | number)[];
|
|
202
|
+
} | {
|
|
203
|
+
action: "import";
|
|
204
|
+
data: {
|
|
205
|
+
url: string;
|
|
206
|
+
file: {
|
|
207
|
+
id?: string | undefined;
|
|
208
|
+
storage?: string | undefined;
|
|
209
|
+
filename_disk?: string | undefined;
|
|
210
|
+
filename_download?: string | undefined;
|
|
211
|
+
title?: string | null | undefined;
|
|
212
|
+
type?: string | null | undefined;
|
|
213
|
+
folder?: string | null | undefined;
|
|
214
|
+
created_on?: string | undefined;
|
|
215
|
+
uploaded_by?: string | null | undefined;
|
|
216
|
+
uploaded_on?: string | null | undefined;
|
|
217
|
+
modified_by?: string | null | undefined;
|
|
218
|
+
modified_on?: string | undefined;
|
|
219
|
+
charset?: string | null | undefined;
|
|
220
|
+
filesize?: number | undefined;
|
|
221
|
+
width?: number | null | undefined;
|
|
222
|
+
height?: number | null | undefined;
|
|
223
|
+
duration?: number | null | undefined;
|
|
224
|
+
embed?: string | null | undefined;
|
|
225
|
+
description?: string | null | undefined;
|
|
226
|
+
location?: string | null | undefined;
|
|
227
|
+
tags?: string | null | undefined;
|
|
228
|
+
metadata?: Record<string, any> | null | undefined;
|
|
229
|
+
focal_point_x?: number | null | undefined;
|
|
230
|
+
focal_point_y?: number | null | undefined;
|
|
231
|
+
tus_id?: string | null | undefined;
|
|
232
|
+
tus_data?: Record<string, any> | null | undefined;
|
|
233
|
+
};
|
|
234
|
+
}[];
|
|
235
|
+
}>;
|