@nocobase/plugin-data-source-manager 2.1.0-alpha.14 → 2.1.0-alpha.16
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/ai/common/common.js +4 -0
- package/dist/ai/skills/data-query/SKILLS.md +84 -70
- package/dist/ai/skills/data-query/tools/dataQuery.d.ts +10 -0
- package/dist/ai/skills/data-query/tools/dataQuery.js +268 -0
- package/dist/externalVersion.js +11 -11
- package/dist/locale/en-US.json +5 -3
- package/dist/locale/zh-CN.json +5 -3
- package/dist/node_modules/zod/package.json +1 -1
- package/package.json +2 -2
package/dist/ai/common/common.js
CHANGED
|
@@ -99,6 +99,10 @@ const example2: QueryObject = {
|
|
|
99
99
|
|
|
100
100
|
const example3: QueryObject = { age: { $lt: 50 } };
|
|
101
101
|
\`\`\`
|
|
102
|
+
|
|
103
|
+
// Datetime rule
|
|
104
|
+
// If you must provide explicit datetime literals in filters, use UTC ISO 8601 strings with a trailing \`Z\`.
|
|
105
|
+
// Example: \`2026-04-01T00:00:00.000Z\`
|
|
102
106
|
`),
|
|
103
107
|
sort: import_zod.z.array(import_zod.z.string()).describe(`{{t("ai.tools.dataQuery.args.sort", { ns: "${import_package.default.name}" })}}`),
|
|
104
108
|
offset: import_zod.z.number().optional().describe(`{{t("ai.tools.dataQuery.args.offset", { ns: "${import_package.default.name}" })}}`),
|
|
@@ -1,85 +1,102 @@
|
|
|
1
1
|
---
|
|
2
2
|
scope: GENERAL
|
|
3
3
|
name: data-query
|
|
4
|
-
description:
|
|
4
|
+
description: Inspect schemas, retrieve records, and run aggregate queries on specified datasources
|
|
5
|
+
tools:
|
|
6
|
+
- getDataSources
|
|
7
|
+
- getCollectionNames
|
|
8
|
+
- getCollectionMetadata
|
|
9
|
+
- searchFieldMetadata
|
|
5
10
|
introduction:
|
|
6
11
|
title: '{{t("ai.skills.dataQuery.title", { ns: "@nocobase/plugin-data-source-manager" })}}'
|
|
7
12
|
about: '{{t("ai.skills.dataQuery.about", { ns: "@nocobase/plugin-data-source-manager" })}}'
|
|
8
13
|
---
|
|
9
14
|
You are a professional data query assistant for NocoBase.
|
|
10
15
|
|
|
11
|
-
You help users
|
|
16
|
+
You help users inspect schemas, retrieve records, and run aggregate queries on NocoBase collections.
|
|
12
17
|
|
|
13
18
|
# Primary Workflows
|
|
14
19
|
|
|
15
|
-
This skill focuses on
|
|
20
|
+
This skill focuses on safe read-only data access.
|
|
16
21
|
|
|
17
|
-
##
|
|
22
|
+
## Schema-first Querying
|
|
18
23
|
|
|
19
|
-
When
|
|
24
|
+
When the user does not provide an exact collection or field name:
|
|
20
25
|
|
|
21
|
-
1.
|
|
22
|
-
|
|
23
|
-
|
|
26
|
+
1. Call `getDataSources` if the target data source is unclear.
|
|
27
|
+
2. If multiple data sources may contain relevant data, inspect each candidate before choosing the query scope.
|
|
28
|
+
3. Do not silently default to `main` when other relevant data sources are available.
|
|
29
|
+
4. If you intentionally limit the query to one data source, explain why that data source was chosen and why others were not used.
|
|
30
|
+
5. Call `getCollectionNames` to find the right collection.
|
|
31
|
+
6. Call `getCollectionMetadata` or `searchFieldMetadata` to confirm field names, relation paths, and data types.
|
|
32
|
+
7. Only then run a data tool.
|
|
24
33
|
|
|
25
|
-
|
|
26
|
-
- Identify which fields to return in the results
|
|
34
|
+
Do not guess collection names, measure aliases, or dotted relation paths.
|
|
27
35
|
|
|
28
|
-
|
|
29
|
-
- Call `dataSourceQuery` with appropriate parameters
|
|
30
|
-
- Default limit is 50, maximum is 1000
|
|
36
|
+
## Raw Record Query
|
|
31
37
|
|
|
32
|
-
|
|
33
|
-
- Format the returned data clearly
|
|
34
|
-
- Show pagination info if there are more records
|
|
38
|
+
Use `dataSourceQuery` when the user wants actual records rather than grouped statistics.
|
|
35
39
|
|
|
36
|
-
|
|
40
|
+
Typical cases:
|
|
37
41
|
|
|
38
|
-
|
|
42
|
+
- list rows
|
|
43
|
+
- inspect recent records
|
|
44
|
+
- fetch selected fields
|
|
45
|
+
- browse data with filter, sort, and pagination
|
|
39
46
|
|
|
40
|
-
|
|
41
|
-
- Determine which collection to count from
|
|
42
|
-
- Apply any filter conditions if specified
|
|
47
|
+
## Aggregate Query
|
|
43
48
|
|
|
44
|
-
|
|
45
|
-
- Call `dataSourceCounting` to get total count
|
|
49
|
+
Use `dataQuery` when the user wants:
|
|
46
50
|
|
|
47
|
-
|
|
48
|
-
|
|
51
|
+
- counts, sums, averages, min, max
|
|
52
|
+
- grouped statistics
|
|
53
|
+
- rankings
|
|
54
|
+
- trend buckets
|
|
55
|
+
- post-aggregation filtering with `having`
|
|
49
56
|
|
|
50
|
-
|
|
57
|
+
Prefer `dataQuery` over `dataSourceCounting` whenever the request can be expressed as a measure query, because it is closer to the repository `query` capability used by charts, actions, ACL, and MCP.
|
|
51
58
|
|
|
52
|
-
|
|
59
|
+
## Count Records
|
|
53
60
|
|
|
54
|
-
|
|
55
|
-
- Use the filter parameter to define query conditions
|
|
56
|
-
- Support operators: `$eq`, `$ne`, `$gt`, `$gte`, `$lt`, `$lte`, `$like`, `$in`, `$nin`, `$exists`, etc.
|
|
57
|
-
- Use `$and` and `$or` for complex conditions
|
|
61
|
+
Use `dataSourceCounting` only for a simple total when grouped output is unnecessary.
|
|
58
62
|
|
|
59
|
-
|
|
60
|
-
- Use the `sort` parameter to order results
|
|
61
|
-
- Format: `["field1", "-field2"]` (minus for descending)
|
|
63
|
+
## Query Construction Rules
|
|
62
64
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
+
1. `filter` is applied before aggregation.
|
|
66
|
+
2. `having` is applied after aggregation and should reference selected aliases or selected field paths.
|
|
67
|
+
3. For grouped results, put grouping fields in `dimensions`.
|
|
68
|
+
4. For metrics, put aggregate definitions in `measures`.
|
|
69
|
+
5. Use aliases when the user clearly needs stable output keys.
|
|
70
|
+
6. For dotted relation fields, prefer the exact field path confirmed from metadata, such as `createdBy.nickname`.
|
|
71
|
+
7. Default row limit is 50 and the tool caps the limit at 100.
|
|
72
|
+
8. When you must generate explicit datetime filter values yourself, generate them in UTC using ISO 8601 timestamps with a trailing `Z`.
|
|
73
|
+
9. Do not generate local offsets such as `+09:00` or `-05:00` in AI-authored datetime filter values.
|
|
74
|
+
10. Do not provide a timezone parameter yourself.
|
|
75
|
+
11. If a report depends on calendar boundaries such as "this month" or "April", state explicitly that the generated filter values are in UTC when it matters.
|
|
65
76
|
|
|
66
77
|
# Available Tools
|
|
67
78
|
|
|
79
|
+
- `getDataSources`: Lists all available data sources.
|
|
80
|
+
- `getCollectionNames`: Lists all collections in a data source.
|
|
81
|
+
- `getCollectionMetadata`: Returns field metadata for collections.
|
|
82
|
+
- `searchFieldMetadata`: Searches fields by keyword.
|
|
68
83
|
- `dataSourceQuery`: Query data from a specified collection in a data source. Supports filtering, sorting, field selection, and pagination. Returns paged results with total count.
|
|
84
|
+
- `dataQuery`: Run aggregate repository queries with measures, dimensions, orders, filter, and having.
|
|
69
85
|
- `dataSourceCounting`: Get the total count of records matching the specified filter conditions in a collection.
|
|
70
86
|
|
|
71
|
-
# Query Parameters
|
|
87
|
+
# Aggregate Query Parameters
|
|
72
88
|
|
|
73
89
|
| Parameter | Type | Description |
|
|
74
90
|
| ---------------- | -------- | ------------------------------------------------------------ |
|
|
75
|
-
| `
|
|
91
|
+
| `dataSource` | string | The data source key (default: `main`) |
|
|
76
92
|
| `collectionName` | string | The collection name to query |
|
|
77
|
-
| `
|
|
78
|
-
| `
|
|
79
|
-
| `
|
|
80
|
-
| `
|
|
81
|
-
| `
|
|
82
|
-
| `
|
|
93
|
+
| `measures` | array | Aggregate definitions, such as count / sum / avg |
|
|
94
|
+
| `dimensions` | array | Group-by field definitions |
|
|
95
|
+
| `orders` | array | Result ordering definitions |
|
|
96
|
+
| `filter` | object | Query conditions applied before aggregation |
|
|
97
|
+
| `having` | object | Query conditions applied after aggregation |
|
|
98
|
+
| `offset` | number | Number of rows to skip |
|
|
99
|
+
| `limit` | number | Maximum number of rows to return (default: 50, max: 100) |
|
|
83
100
|
|
|
84
101
|
# Filter Operators
|
|
85
102
|
|
|
@@ -141,28 +158,28 @@ User: "Show me all users"
|
|
|
141
158
|
Action: Call dataSourceQuery with collectionName="users"
|
|
142
159
|
```
|
|
143
160
|
|
|
144
|
-
##
|
|
161
|
+
## Aggregate Count
|
|
145
162
|
```
|
|
146
|
-
User: "
|
|
147
|
-
Action: Call
|
|
163
|
+
User: "How many active users are there?"
|
|
164
|
+
Action: Call dataQuery with collectionName="users", measures=[{ field: "id", aggregation: "count", alias: "count" }], filter={ status: { $eq: "active" } }
|
|
148
165
|
```
|
|
149
166
|
|
|
150
|
-
##
|
|
167
|
+
## Grouped Statistics
|
|
151
168
|
```
|
|
152
|
-
User: "
|
|
153
|
-
Action: Call
|
|
169
|
+
User: "Count orders by status"
|
|
170
|
+
Action: Call dataQuery with collectionName="orders", dimensions=[{ field: "status", alias: "status" }], measures=[{ field: "id", aggregation: "count", alias: "count" }]
|
|
154
171
|
```
|
|
155
172
|
|
|
156
|
-
##
|
|
173
|
+
## Having Query
|
|
157
174
|
```
|
|
158
|
-
User: "Show
|
|
159
|
-
Action: Call
|
|
175
|
+
User: "Show statuses with more than 10 orders"
|
|
176
|
+
Action: Call dataQuery with collectionName="orders", dimensions=[{ field: "status", alias: "status" }], measures=[{ field: "id", aggregation: "count", alias: "count" }], having={ count: { $gt: 10 } }
|
|
160
177
|
```
|
|
161
178
|
|
|
162
|
-
##
|
|
179
|
+
## Raw Record Query
|
|
163
180
|
```
|
|
164
|
-
User: "Show me
|
|
165
|
-
Action: Call dataSourceQuery with collectionName="
|
|
181
|
+
User: "Show me 20 latest paid orders"
|
|
182
|
+
Action: Call dataSourceQuery with collectionName="orders", filter={ status: { $eq: "paid" } }, sort=["-createdAt"], limit=20
|
|
166
183
|
```
|
|
167
184
|
|
|
168
185
|
## Count Records
|
|
@@ -171,22 +188,19 @@ User: "How many active users are there?"
|
|
|
171
188
|
Action: Call dataSourceCounting with collectionName="users", filter={ status: { $eq: 'active' } }
|
|
172
189
|
```
|
|
173
190
|
|
|
174
|
-
##
|
|
191
|
+
## Metadata First
|
|
175
192
|
```
|
|
176
|
-
User: "Show
|
|
177
|
-
Action:
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
]
|
|
182
|
-
}
|
|
193
|
+
User: "Show monthly revenue by salesperson"
|
|
194
|
+
Action:
|
|
195
|
+
1. Call getCollectionNames / searchFieldMetadata to locate the correct collection and amount field.
|
|
196
|
+
2. Call getCollectionMetadata if date or relation paths are unclear.
|
|
197
|
+
3. Call dataQuery with the confirmed fields.
|
|
183
198
|
```
|
|
184
199
|
|
|
185
200
|
# Notes
|
|
186
201
|
|
|
187
|
-
- Always validate
|
|
188
|
-
-
|
|
189
|
-
-
|
|
190
|
-
-
|
|
191
|
-
-
|
|
192
|
-
- Format results in a clear, readable manner
|
|
202
|
+
- Always validate collection and field names before querying.
|
|
203
|
+
- Prefer metadata tools first when the request is ambiguous.
|
|
204
|
+
- Prefer `dataQuery` for analysis and metrics.
|
|
205
|
+
- Use `dataSourceQuery` for raw rows and `dataSourceCounting` for the simplest count case.
|
|
206
|
+
- Respect user permissions; if the tool returns `No permissions`, explain that the current role cannot access the requested data.
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
declare const _default: import("@nocobase/ai").ToolsOptions;
|
|
10
|
+
export default _default;
|
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
var __create = Object.create;
|
|
11
|
+
var __defProp = Object.defineProperty;
|
|
12
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
13
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
14
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
15
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
16
|
+
var __export = (target, all) => {
|
|
17
|
+
for (var name in all)
|
|
18
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
19
|
+
};
|
|
20
|
+
var __copyProps = (to, from, except, desc) => {
|
|
21
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
22
|
+
for (let key of __getOwnPropNames(from))
|
|
23
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
24
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
25
|
+
}
|
|
26
|
+
return to;
|
|
27
|
+
};
|
|
28
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
29
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
30
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
31
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
32
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
33
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
34
|
+
mod
|
|
35
|
+
));
|
|
36
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
37
|
+
var dataQuery_exports = {};
|
|
38
|
+
__export(dataQuery_exports, {
|
|
39
|
+
default: () => dataQuery_default
|
|
40
|
+
});
|
|
41
|
+
module.exports = __toCommonJS(dataQuery_exports);
|
|
42
|
+
var import_acl = require("@nocobase/acl");
|
|
43
|
+
var import_ai = require("@nocobase/ai");
|
|
44
|
+
var import_plugin_acl = require("@nocobase/plugin-acl");
|
|
45
|
+
var import_utils = require("../../../common/utils");
|
|
46
|
+
var import_package = __toESM(require("../../../../../package.json"));
|
|
47
|
+
const queryFieldSchema = {
|
|
48
|
+
anyOf: [
|
|
49
|
+
{ type: "string" },
|
|
50
|
+
{
|
|
51
|
+
type: "array",
|
|
52
|
+
items: { type: "string" },
|
|
53
|
+
minItems: 1
|
|
54
|
+
}
|
|
55
|
+
]
|
|
56
|
+
};
|
|
57
|
+
const queryMeasureSchema = {
|
|
58
|
+
type: "object",
|
|
59
|
+
additionalProperties: true,
|
|
60
|
+
required: ["field"],
|
|
61
|
+
properties: {
|
|
62
|
+
field: queryFieldSchema,
|
|
63
|
+
type: {
|
|
64
|
+
type: "string",
|
|
65
|
+
description: "Optional field type hint."
|
|
66
|
+
},
|
|
67
|
+
aggregation: {
|
|
68
|
+
type: "string",
|
|
69
|
+
description: "Aggregation function, such as count, sum, avg, max, or min."
|
|
70
|
+
},
|
|
71
|
+
alias: {
|
|
72
|
+
type: "string",
|
|
73
|
+
description: "Output field alias."
|
|
74
|
+
},
|
|
75
|
+
distinct: {
|
|
76
|
+
type: "boolean",
|
|
77
|
+
description: "Whether to apply distinct before aggregation."
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
const queryDimensionSchema = {
|
|
82
|
+
type: "object",
|
|
83
|
+
additionalProperties: true,
|
|
84
|
+
required: ["field"],
|
|
85
|
+
properties: {
|
|
86
|
+
field: queryFieldSchema,
|
|
87
|
+
type: {
|
|
88
|
+
type: "string",
|
|
89
|
+
description: "Optional field type hint."
|
|
90
|
+
},
|
|
91
|
+
alias: {
|
|
92
|
+
type: "string",
|
|
93
|
+
description: "Output field alias."
|
|
94
|
+
},
|
|
95
|
+
format: {
|
|
96
|
+
type: "string",
|
|
97
|
+
description: "Optional output format, usually for date and time dimensions."
|
|
98
|
+
},
|
|
99
|
+
options: {
|
|
100
|
+
type: "object",
|
|
101
|
+
description: "Additional formatter options.",
|
|
102
|
+
additionalProperties: true
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
const queryOrderSchema = {
|
|
107
|
+
type: "object",
|
|
108
|
+
additionalProperties: true,
|
|
109
|
+
required: ["field"],
|
|
110
|
+
properties: {
|
|
111
|
+
field: queryFieldSchema,
|
|
112
|
+
alias: {
|
|
113
|
+
type: "string",
|
|
114
|
+
description: "Alias to sort by when the selected field is projected with an alias."
|
|
115
|
+
},
|
|
116
|
+
order: {
|
|
117
|
+
type: "string",
|
|
118
|
+
enum: ["asc", "desc"],
|
|
119
|
+
description: "Sort direction."
|
|
120
|
+
},
|
|
121
|
+
nulls: {
|
|
122
|
+
type: "string",
|
|
123
|
+
enum: ["default", "first", "last"],
|
|
124
|
+
description: "Null value ordering."
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
const AggregateQuerySchema = {
|
|
129
|
+
type: "object",
|
|
130
|
+
additionalProperties: false,
|
|
131
|
+
required: ["collectionName"],
|
|
132
|
+
properties: {
|
|
133
|
+
dataSource: {
|
|
134
|
+
type: "string",
|
|
135
|
+
description: "Data source key. Defaults to main."
|
|
136
|
+
},
|
|
137
|
+
datasource: {
|
|
138
|
+
type: "string",
|
|
139
|
+
description: "Legacy alias of dataSource. Defaults to main."
|
|
140
|
+
},
|
|
141
|
+
collectionName: {
|
|
142
|
+
type: "string",
|
|
143
|
+
description: "Collection name to query."
|
|
144
|
+
},
|
|
145
|
+
measures: {
|
|
146
|
+
type: "array",
|
|
147
|
+
description: "Measure definitions for aggregate query.",
|
|
148
|
+
items: queryMeasureSchema
|
|
149
|
+
},
|
|
150
|
+
dimensions: {
|
|
151
|
+
type: "array",
|
|
152
|
+
description: "Dimension definitions for grouped query.",
|
|
153
|
+
items: queryDimensionSchema
|
|
154
|
+
},
|
|
155
|
+
orders: {
|
|
156
|
+
type: "array",
|
|
157
|
+
description: "Order definitions for aggregate query.",
|
|
158
|
+
items: queryOrderSchema
|
|
159
|
+
},
|
|
160
|
+
filter: {
|
|
161
|
+
type: "object",
|
|
162
|
+
description: "Filter object applied before aggregation. If you must provide explicit datetime literals, use UTC ISO 8601 strings with a trailing Z.",
|
|
163
|
+
additionalProperties: true
|
|
164
|
+
},
|
|
165
|
+
having: {
|
|
166
|
+
type: "object",
|
|
167
|
+
description: "Having object applied after grouping.",
|
|
168
|
+
additionalProperties: true
|
|
169
|
+
},
|
|
170
|
+
offset: {
|
|
171
|
+
type: "number",
|
|
172
|
+
description: "Offset for query result rows."
|
|
173
|
+
},
|
|
174
|
+
limit: {
|
|
175
|
+
type: "number",
|
|
176
|
+
description: `Maximum number of rows to return. Defaults to 50 and is capped at ${import_utils.MAX_QUERY_LIMIT}.`
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
function getDataSourceKey(args) {
|
|
181
|
+
return args.dataSource || args.datasource || "main";
|
|
182
|
+
}
|
|
183
|
+
function getTimezone(ctx, args) {
|
|
184
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
185
|
+
const value = ((_a = ctx.get) == null ? void 0 : _a.call(ctx, "x-timezone")) || ((_c = (_b = ctx.request) == null ? void 0 : _b.get) == null ? void 0 : _c.call(_b, "x-timezone")) || ((_e = (_d = ctx.request) == null ? void 0 : _d.header) == null ? void 0 : _e["x-timezone"]) || ((_g = (_f = ctx.req) == null ? void 0 : _f.headers) == null ? void 0 : _g["x-timezone"]);
|
|
186
|
+
return Array.isArray(value) ? value[0] : value;
|
|
187
|
+
}
|
|
188
|
+
var dataQuery_default = (0, import_ai.defineTools)({
|
|
189
|
+
scope: "SPECIFIED",
|
|
190
|
+
defaultPermission: "ALLOW",
|
|
191
|
+
introduction: {
|
|
192
|
+
title: `{{t("ai.tools.dataQuery.title", { ns: "${import_package.default.name}" })}}`,
|
|
193
|
+
about: `{{t("ai.tools.dataQuery.about", { ns: "${import_package.default.name}" })}}`
|
|
194
|
+
},
|
|
195
|
+
definition: {
|
|
196
|
+
name: "dataQuery",
|
|
197
|
+
description: "Run the repository query action on a collection with measures, dimensions, orders, filter, and having.",
|
|
198
|
+
schema: AggregateQuerySchema
|
|
199
|
+
},
|
|
200
|
+
invoke: async (ctx, args) => {
|
|
201
|
+
var _a, _b, _c, _d, _e;
|
|
202
|
+
const dataSourceKey = getDataSourceKey(args);
|
|
203
|
+
const ds = ctx.app.dataSourceManager.get(dataSourceKey);
|
|
204
|
+
if (!ds) {
|
|
205
|
+
return {
|
|
206
|
+
status: "error",
|
|
207
|
+
content: `Data source "${dataSourceKey}" not found`
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
const collection = ds.collectionManager.getCollection(args.collectionName);
|
|
211
|
+
if (!collection) {
|
|
212
|
+
return {
|
|
213
|
+
status: "error",
|
|
214
|
+
content: `Collection "${args.collectionName}" not found in data source "${dataSourceKey}"`
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
const { limit, offset } = (0, import_utils.normalizeLimitOffset)(args, { defaultLimit: 50, maxLimit: import_utils.MAX_QUERY_LIMIT });
|
|
218
|
+
const timezone = getTimezone(ctx, args);
|
|
219
|
+
if (!((_a = args.measures) == null ? void 0 : _a.length) && !((_b = args.dimensions) == null ? void 0 : _b.length)) {
|
|
220
|
+
return {
|
|
221
|
+
status: "error",
|
|
222
|
+
content: "Aggregate query requires at least one measure or dimension"
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
try {
|
|
226
|
+
const db = ds.collectionManager.db || ctx.db;
|
|
227
|
+
const result = await (0, import_plugin_acl.applyQueryPermission)({
|
|
228
|
+
acl: ds.acl || ctx.app.acl,
|
|
229
|
+
db,
|
|
230
|
+
resourceName: args.collectionName,
|
|
231
|
+
query: {
|
|
232
|
+
measures: args.measures,
|
|
233
|
+
dimensions: args.dimensions,
|
|
234
|
+
orders: args.orders,
|
|
235
|
+
filter: args.filter,
|
|
236
|
+
having: args.having,
|
|
237
|
+
limit,
|
|
238
|
+
offset
|
|
239
|
+
},
|
|
240
|
+
currentUser: (_c = ctx.state) == null ? void 0 : _c.currentUser,
|
|
241
|
+
currentRole: (_d = ctx.state) == null ? void 0 : _d.currentRole,
|
|
242
|
+
currentRoles: (_e = ctx.state) == null ? void 0 : _e.currentRoles,
|
|
243
|
+
timezone,
|
|
244
|
+
state: ctx.state
|
|
245
|
+
});
|
|
246
|
+
const queryResult = await db.getRepository(args.collectionName).query({
|
|
247
|
+
...result.query,
|
|
248
|
+
context: ctx,
|
|
249
|
+
timezone
|
|
250
|
+
});
|
|
251
|
+
return {
|
|
252
|
+
status: "success",
|
|
253
|
+
content: JSON.stringify((0, import_utils.truncateLongStrings)(queryResult))
|
|
254
|
+
};
|
|
255
|
+
} catch (error) {
|
|
256
|
+
if (error instanceof import_acl.NoPermissionError) {
|
|
257
|
+
return {
|
|
258
|
+
status: "error",
|
|
259
|
+
content: "No permissions"
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
return {
|
|
263
|
+
status: "error",
|
|
264
|
+
content: (error == null ? void 0 : error.message) || "Aggregate query failed"
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
});
|
package/dist/externalVersion.js
CHANGED
|
@@ -8,27 +8,27 @@
|
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
module.exports = {
|
|
11
|
-
"@nocobase/client": "2.1.0-alpha.
|
|
11
|
+
"@nocobase/client": "2.1.0-alpha.16",
|
|
12
12
|
"react": "18.2.0",
|
|
13
|
-
"@nocobase/plugin-acl": "2.1.0-alpha.
|
|
14
|
-
"@nocobase/utils": "2.1.0-alpha.
|
|
15
|
-
"@nocobase/ai": "2.1.0-alpha.
|
|
16
|
-
"@nocobase/server": "2.1.0-alpha.
|
|
17
|
-
"@nocobase/data-source-manager": "2.1.0-alpha.
|
|
13
|
+
"@nocobase/plugin-acl": "2.1.0-alpha.16",
|
|
14
|
+
"@nocobase/utils": "2.1.0-alpha.16",
|
|
15
|
+
"@nocobase/ai": "2.1.0-alpha.16",
|
|
16
|
+
"@nocobase/server": "2.1.0-alpha.16",
|
|
17
|
+
"@nocobase/data-source-manager": "2.1.0-alpha.16",
|
|
18
18
|
"lodash": "4.17.21",
|
|
19
|
-
"@nocobase/acl": "2.1.0-alpha.
|
|
20
|
-
"@nocobase/database": "2.1.0-alpha.
|
|
19
|
+
"@nocobase/acl": "2.1.0-alpha.16",
|
|
20
|
+
"@nocobase/database": "2.1.0-alpha.16",
|
|
21
21
|
"@ant-design/icons": "5.6.1",
|
|
22
22
|
"antd": "5.24.2",
|
|
23
23
|
"react-router-dom": "6.30.1",
|
|
24
|
-
"@nocobase/flow-engine": "2.1.0-alpha.
|
|
24
|
+
"@nocobase/flow-engine": "2.1.0-alpha.16",
|
|
25
25
|
"@formily/shared": "2.3.7",
|
|
26
26
|
"@formily/react": "2.3.7",
|
|
27
27
|
"react-i18next": "11.18.6",
|
|
28
28
|
"@emotion/css": "11.13.0",
|
|
29
|
-
"@nocobase/actions": "2.1.0-alpha.
|
|
29
|
+
"@nocobase/actions": "2.1.0-alpha.16",
|
|
30
30
|
"sequelize": "6.35.2",
|
|
31
|
-
"@nocobase/test": "2.1.0-alpha.
|
|
31
|
+
"@nocobase/test": "2.1.0-alpha.16",
|
|
32
32
|
"@formily/antd-v5": "1.2.3",
|
|
33
33
|
"@formily/core": "2.3.7",
|
|
34
34
|
"@formily/reactive": "2.3.7",
|
package/dist/locale/en-US.json
CHANGED
|
@@ -57,8 +57,10 @@
|
|
|
57
57
|
"ai.tools.intentRouter.about": "Route intents to appropriate workflow",
|
|
58
58
|
"ai.tools.searchFieldMetadata.title": "Search field metadata",
|
|
59
59
|
"ai.tools.searchFieldMetadata.about": "Search fields in data models by keyword (english first). Returns either search results or a suggested query.",
|
|
60
|
-
"ai.tools.dataSourceQuery.title": "
|
|
61
|
-
"ai.tools.dataSourceQuery.about": "Use dataSource, collectionName,
|
|
60
|
+
"ai.tools.dataSourceQuery.title": "Get records",
|
|
61
|
+
"ai.tools.dataSourceQuery.about": "Use dataSource, collectionName, fields, filters, and sorting to get records",
|
|
62
|
+
"ai.tools.dataQuery.title": "Query data",
|
|
63
|
+
"ai.tools.dataQuery.about": "Run aggregate repository queries with measures, dimensions, orders, filter, and having",
|
|
62
64
|
"ai.tools.dataSourceCounting.title": "Data source records counting",
|
|
63
65
|
"ai.tools.dataSourceCounting.about": "Use dataSource, collectionName, and collection fields to query data from the database, get total count of records",
|
|
64
66
|
"ai.tools.dataQuery.args.datasource": "Data source key",
|
|
@@ -69,7 +71,7 @@
|
|
|
69
71
|
"ai.tools.dataQuery.args.offset": "Offset of records to be queried",
|
|
70
72
|
"ai.tools.dataQuery.args.limit": "Maximum number of records to be queried",
|
|
71
73
|
"ai.skills.dataQuery.title": "Data query",
|
|
72
|
-
"ai.skills.dataQuery.about": "
|
|
74
|
+
"ai.skills.dataQuery.about": "Use tools to inspect metadata, query records, and run aggregate analysis on specified data sources",
|
|
73
75
|
"ai.skills.dataModeling.title": "Data modeling",
|
|
74
76
|
"ai.skills.dataModeling.about": "helps translate business scenarios into normalized database schemas with table declarations and relationship diagrams.",
|
|
75
77
|
"ai.skills.dataMetadata.title": "Data metadata",
|
package/dist/locale/zh-CN.json
CHANGED
|
@@ -57,8 +57,10 @@
|
|
|
57
57
|
"ai.tools.intentRouter.about": "将意图路由到适当的工作流",
|
|
58
58
|
"ai.tools.searchFieldMetadata.title": "搜索字段元数据",
|
|
59
59
|
"ai.tools.searchFieldMetadata.about": "通过关键词搜索数据模型字段(优先英文)。返回搜索结果或建议的查询。",
|
|
60
|
-
"ai.tools.dataSourceQuery.title": "
|
|
61
|
-
"ai.tools.dataSourceQuery.about": "使用 dataSource、collectionName
|
|
60
|
+
"ai.tools.dataSourceQuery.title": "获取数据记录",
|
|
61
|
+
"ai.tools.dataSourceQuery.about": "使用 dataSource、collectionName、字段、筛选和排序条件获取数据记录",
|
|
62
|
+
"ai.tools.dataQuery.title": "查询数据",
|
|
63
|
+
"ai.tools.dataQuery.about": "使用 measures、dimensions、orders、filter 和 having 执行聚合查询",
|
|
62
64
|
"ai.tools.dataSourceCounting.title": "数据源记录数统计",
|
|
63
65
|
"ai.tools.dataSourceCounting.about": "使用 dataSource、collectionName 和 collection fields 从数据库中获取记录总数",
|
|
64
66
|
"ai.tools.dataQuery.args.datasource": "数据源标识",
|
|
@@ -69,7 +71,7 @@
|
|
|
69
71
|
"ai.tools.dataQuery.args.offset": "查询记录的偏移量",
|
|
70
72
|
"ai.tools.dataQuery.args.limit": "查询记录的最大数量",
|
|
71
73
|
"ai.skills.dataQuery.title": "数据查询",
|
|
72
|
-
"ai.skills.dataQuery.about": "
|
|
74
|
+
"ai.skills.dataQuery.about": "使用工具查看元数据、查询记录并对指定数据源执行聚合分析",
|
|
73
75
|
"ai.skills.dataModeling.title": "数据建模",
|
|
74
76
|
"ai.skills.dataModeling.about": "帮助将业务场景转换为带有表声明和关系图的规范化数据库模式。",
|
|
75
77
|
"ai.skills.dataMetadata.title": "获取数据模型元信息",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"zod","version":"4.3.5","type":"module","license":"MIT","author":"Colin McDonnell <zod@colinhacks.com>","description":"TypeScript-first schema declaration and validation library with static type inference","homepage":"https://zod.dev","llms":"https://zod.dev/llms.txt","llmsFull":"https://zod.dev/llms-full.txt","mcpServer":"https://mcp.inkeep.com/zod/mcp","funding":"https://github.com/sponsors/colinhacks","sideEffects":false,"files":["src","**/*.js","**/*.mjs","**/*.cjs","**/*.d.ts","**/*.d.mts","**/*.d.cts","**/package.json"],"keywords":["typescript","schema","validation","type","inference"],"main":"./index.cjs","types":"./index.d.cts","module":"./index.js","zshy":{"exports":{"./package.json":"./package.json",".":"./src/index.ts","./mini":"./src/mini/index.ts","./locales":"./src/locales/index.ts","./v3":"./src/v3/index.ts","./v4":"./src/v4/index.ts","./v4-mini":"./src/v4-mini/index.ts","./v4/mini":"./src/v4/mini/index.ts","./v4/core":"./src/v4/core/index.ts","./v4/locales":"./src/v4/locales/index.ts","./v4/locales/*":"./src/v4/locales/*"},"conditions":{"@zod/source":"src"}},"exports":{"./package.json":"./package.json",".":{"@zod/source":"./src/index.ts","types":"./index.d.cts","import":"./index.js","require":"./index.cjs"},"./mini":{"@zod/source":"./src/mini/index.ts","types":"./mini/index.d.cts","import":"./mini/index.js","require":"./mini/index.cjs"},"./locales":{"@zod/source":"./src/locales/index.ts","types":"./locales/index.d.cts","import":"./locales/index.js","require":"./locales/index.cjs"},"./v3":{"@zod/source":"./src/v3/index.ts","types":"./v3/index.d.cts","import":"./v3/index.js","require":"./v3/index.cjs"},"./v4":{"@zod/source":"./src/v4/index.ts","types":"./v4/index.d.cts","import":"./v4/index.js","require":"./v4/index.cjs"},"./v4-mini":{"@zod/source":"./src/v4-mini/index.ts","types":"./v4-mini/index.d.cts","import":"./v4-mini/index.js","require":"./v4-mini/index.cjs"},"./v4/mini":{"@zod/source":"./src/v4/mini/index.ts","types":"./v4/mini/index.d.cts","import":"./v4/mini/index.js","require":"./v4/mini/index.cjs"},"./v4/core":{"@zod/source":"./src/v4/core/index.ts","types":"./v4/core/index.d.cts","import":"./v4/core/index.js","require":"./v4/core/index.cjs"},"./v4/locales":{"@zod/source":"./src/v4/locales/index.ts","types":"./v4/locales/index.d.cts","import":"./v4/locales/index.js","require":"./v4/locales/index.cjs"},"./v4/locales/*":{"@zod/source":"./src/v4/locales/*","types":"./v4/locales/*","import":"./v4/locales/*","require":"./v4/locales/*"}},"repository":{"type":"git","url":"git+https://github.com/colinhacks/zod.git"},"bugs":{"url":"https://github.com/colinhacks/zod/issues"},"support":{"backing":{"npm-funding":true}},"scripts":{"clean":"git clean -xdf . -e node_modules","build":"zshy --project tsconfig.build.json","postbuild":"tsx ../../scripts/write-stub-package-jsons.ts && pnpm biome check --write .","test:watch":"pnpm vitest","test":"pnpm vitest run","prepublishOnly":"tsx ../../scripts/check-versions.ts"},"_lastModified":"2026-04-
|
|
1
|
+
{"name":"zod","version":"4.3.5","type":"module","license":"MIT","author":"Colin McDonnell <zod@colinhacks.com>","description":"TypeScript-first schema declaration and validation library with static type inference","homepage":"https://zod.dev","llms":"https://zod.dev/llms.txt","llmsFull":"https://zod.dev/llms-full.txt","mcpServer":"https://mcp.inkeep.com/zod/mcp","funding":"https://github.com/sponsors/colinhacks","sideEffects":false,"files":["src","**/*.js","**/*.mjs","**/*.cjs","**/*.d.ts","**/*.d.mts","**/*.d.cts","**/package.json"],"keywords":["typescript","schema","validation","type","inference"],"main":"./index.cjs","types":"./index.d.cts","module":"./index.js","zshy":{"exports":{"./package.json":"./package.json",".":"./src/index.ts","./mini":"./src/mini/index.ts","./locales":"./src/locales/index.ts","./v3":"./src/v3/index.ts","./v4":"./src/v4/index.ts","./v4-mini":"./src/v4-mini/index.ts","./v4/mini":"./src/v4/mini/index.ts","./v4/core":"./src/v4/core/index.ts","./v4/locales":"./src/v4/locales/index.ts","./v4/locales/*":"./src/v4/locales/*"},"conditions":{"@zod/source":"src"}},"exports":{"./package.json":"./package.json",".":{"@zod/source":"./src/index.ts","types":"./index.d.cts","import":"./index.js","require":"./index.cjs"},"./mini":{"@zod/source":"./src/mini/index.ts","types":"./mini/index.d.cts","import":"./mini/index.js","require":"./mini/index.cjs"},"./locales":{"@zod/source":"./src/locales/index.ts","types":"./locales/index.d.cts","import":"./locales/index.js","require":"./locales/index.cjs"},"./v3":{"@zod/source":"./src/v3/index.ts","types":"./v3/index.d.cts","import":"./v3/index.js","require":"./v3/index.cjs"},"./v4":{"@zod/source":"./src/v4/index.ts","types":"./v4/index.d.cts","import":"./v4/index.js","require":"./v4/index.cjs"},"./v4-mini":{"@zod/source":"./src/v4-mini/index.ts","types":"./v4-mini/index.d.cts","import":"./v4-mini/index.js","require":"./v4-mini/index.cjs"},"./v4/mini":{"@zod/source":"./src/v4/mini/index.ts","types":"./v4/mini/index.d.cts","import":"./v4/mini/index.js","require":"./v4/mini/index.cjs"},"./v4/core":{"@zod/source":"./src/v4/core/index.ts","types":"./v4/core/index.d.cts","import":"./v4/core/index.js","require":"./v4/core/index.cjs"},"./v4/locales":{"@zod/source":"./src/v4/locales/index.ts","types":"./v4/locales/index.d.cts","import":"./v4/locales/index.js","require":"./v4/locales/index.cjs"},"./v4/locales/*":{"@zod/source":"./src/v4/locales/*","types":"./v4/locales/*","import":"./v4/locales/*","require":"./v4/locales/*"}},"repository":{"type":"git","url":"git+https://github.com/colinhacks/zod.git"},"bugs":{"url":"https://github.com/colinhacks/zod/issues"},"support":{"backing":{"npm-funding":true}},"scripts":{"clean":"git clean -xdf . -e node_modules","build":"zshy --project tsconfig.build.json","postbuild":"tsx ../../scripts/write-stub-package-jsons.ts && pnpm biome check --write .","test:watch":"pnpm vitest","test":"pnpm vitest run","prepublishOnly":"tsx ../../scripts/check-versions.ts"},"_lastModified":"2026-04-14T00:04:38.783Z"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nocobase/plugin-data-source-manager",
|
|
3
|
-
"version": "2.1.0-alpha.
|
|
3
|
+
"version": "2.1.0-alpha.16",
|
|
4
4
|
"main": "dist/server/index.js",
|
|
5
5
|
"displayName": "Data source manager",
|
|
6
6
|
"displayName.ru-RU": "Менеджер управления источниками данных",
|
|
@@ -20,6 +20,6 @@
|
|
|
20
20
|
"keywords": [
|
|
21
21
|
"Data model tools"
|
|
22
22
|
],
|
|
23
|
-
"gitHead": "
|
|
23
|
+
"gitHead": "14cf3dbdb9f0a9669602de4ad21a9464fa27c105",
|
|
24
24
|
"license": "Apache-2.0"
|
|
25
25
|
}
|