suppa-mcp-2 1.24.0 → 1.26.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/README.md +15 -8
- package/dist/httpClient.js +6 -2
- package/dist/readEconomy.js +200 -0
- package/dist/server.js +166 -144
- package/dist/tools/docs.js +46 -18
- package/dist/tools/entity.js +20 -2
- package/dist/tools/tasks.js +48 -7
- package/dist/toolsListEconomy.js +70 -0
- package/dist/utils.js +37 -0
- package/package.json +1 -1
- package/skills/suppa-entity-code/scripts/house-rules.mjs +8 -8
package/README.md
CHANGED
|
@@ -168,7 +168,7 @@ When an AI agent connects, the server provides built-in instructions describing
|
|
|
168
168
|
|
|
169
169
|
### What the server does not send back
|
|
170
170
|
|
|
171
|
-
A tool result is not paid once: the whole conversation is re-sent on every turn, so a long string returned early is charged again on every later turn and is still occupying the window when compaction fires.
|
|
171
|
+
A tool result is not paid once: the whole conversation is re-sent on every turn, so a long string returned early is charged again on every later turn and is still occupying the window when compaction fires. These bytes are therefore removed on the way out — each chosen because it carries nothing the reader does not already hold or is not told:
|
|
172
172
|
|
|
173
173
|
| Removed | Why it is safe |
|
|
174
174
|
|---|---|
|
|
@@ -176,8 +176,15 @@ A tool result is not paid once: the whole conversation is re-sent on every turn,
|
|
|
176
176
|
| Long values in a **confirmation preview** | `proposed_changes` was built by copying the tool's own arguments back out. The value is verbatim in the same tool call, so it is named and sized instead: `<4231 chars — unchanged from this call's arguments>`. Short values stay verbatim, and `target` — the half that says *what* is about to change — is never touched. |
|
|
177
177
|
| Long values a **write echoed back** | An insert with no `returning` projection answers with the whole stored record, so the HTML just uploaded returns with it. Replaced only when byte-identical to what was sent, and the marker says what was checked — `<4231 chars — identical to the value this call wrote>`, not a claim about what you typed (a task description passes through `wrapHtml()` on the way out). If the platform normalised the markup or filled a default, the stored value differs — that difference is real information and comes back in full. |
|
|
178
178
|
|
|
179
|
+
| **Schema reads** (`suppa_describe_entity`) | A field lists only what departs from the platform defaults: constraints that are `null`, flags that are `false`/`0` and options at their default (`canGroup`/`canSort`/`showInTable`/`editFromTable`/`canFilter` true, `readOnly`/`searchable` false) are omitted, and a title keeps its language keys only. The result leads with a `_legend` stating exactly that rule, and `full=true` returns the platform's raw schema. Measured on a live tenant: Tasks 43,316 → 16,687 characters, Users 14,829 → 4,858. `suppa_list_entities` reduces each title the same way (24,840 → 13,132 for 202 entities; `full=true` keeps it whole). |
|
|
180
|
+
| `deletedAt: null` **on expanded relations** | The platform adds `deletedAt` to every relation it expands — `null` on every live row, nine times per task. Dropped only inside relations named by a projection **this server wrote** (tasks, docs, forms, automations), never inside a `json` value and never where the projection asked for it; a non-null value — the related row *is* deleted — always comes back. A projection the caller supplied (`suppa_search_records`) is returned as sent. |
|
|
181
|
+
| **A stage's status object** | `suppa_list_workflows` / `suppa_list_stages` return `status` as its value (`"completed"`) instead of the expanded enum row; the value is the one word every stage decision reads. 68,565 → 41,119 characters for 162 workflows. |
|
|
182
|
+
| **A task's second description** | `suppa_get_task` drops `plainDescription` when it is exactly `htmlDescription` with the tags removed — the HTML is what an edit has to send back, and the text is one strip away. When the two differ, both come back. |
|
|
183
|
+
|
|
179
184
|
The key is always kept, so "the field was written" is never in doubt. A marker is not the stored text: quote the value to the user from your own arguments.
|
|
180
185
|
|
|
186
|
+
The same discipline applies to what every session pays before the first call. The `instructions` block is budgeted (`test/instructionsBudget.test.ts`), and `tools/list` goes out without the JSON-Schema boilerplate no model reads — the `$schema` URI on each tool, `"default": null` on optional parameters, the two-branch `anyOf` where a type array says the same — while every property, `required` list, enum, non-null default and description is kept and compared against the SDK's own output in `test/toolsListEconomy.test.ts` (103,058 → about 93,000 characters for 89 tools).
|
|
187
|
+
|
|
181
188
|
|
|
182
189
|
### Deletes are reversible — permanent delete is blocked
|
|
183
190
|
|
|
@@ -225,9 +232,9 @@ work normally. Erasing data for good is an admin action in the platform's own UI
|
|
|
225
232
|
|
|
226
233
|
| Tool | Description |
|
|
227
234
|
|---|---|
|
|
228
|
-
| `suppa_search_tasks` | Search tasks (my / active / overdue / due-today filters, paginated) |
|
|
235
|
+
| `suppa_search_tasks` | Search tasks (my / active / overdue / due-today filters, paginated); `task_ids` reads several known tasks in one call; `fields_json` narrows each row |
|
|
229
236
|
| `suppa_count_tasks` | Count tasks matching filters |
|
|
230
|
-
| `suppa_get_task` | Get a single task |
|
|
237
|
+
| `suppa_get_task` | Get a single task (full details, or only `fields_json`) |
|
|
231
238
|
| `suppa_create_task` | Create a task |
|
|
232
239
|
| `suppa_update_task` | Update a task (confirm-gated) |
|
|
233
240
|
| `suppa_delete_task` | Delete a task (confirm-gated) |
|
|
@@ -245,13 +252,13 @@ work normally. Erasing data for good is an admin action in the platform's own UI
|
|
|
245
252
|
|
|
246
253
|
| Tool | Description |
|
|
247
254
|
|---|---|
|
|
248
|
-
| `suppa_list_docs` | List docs |
|
|
249
|
-
| `suppa_get_doc` | Get a doc |
|
|
255
|
+
| `suppa_list_docs` | List docs (`fields_json` narrows each row) |
|
|
256
|
+
| `suppa_get_doc` | Get a doc (page tree included, or only `fields_json`) |
|
|
250
257
|
| `suppa_create_doc` | Create a doc |
|
|
251
258
|
| `suppa_update_doc` | Update a doc (confirm-gated) |
|
|
252
259
|
| `suppa_delete_doc` | Delete a doc (confirm-gated) |
|
|
253
|
-
| `suppa_list_pages` | List pages of a doc |
|
|
254
|
-
| `suppa_get_page` | Get a page |
|
|
260
|
+
| `suppa_list_pages` | List pages of a doc (`fields_json` narrows each row) |
|
|
261
|
+
| `suppa_get_page` | Get a page (metadata, or only `fields_json`) |
|
|
255
262
|
| `suppa_create_page` | Create a page |
|
|
256
263
|
| `suppa_update_page` | Update a page (confirm-gated) |
|
|
257
264
|
| `suppa_delete_page` | Delete a page (confirm-gated) |
|
|
@@ -268,7 +275,7 @@ work normally. Erasing data for good is an admin action in the platform's own UI
|
|
|
268
275
|
| Tool | Description |
|
|
269
276
|
|---|---|
|
|
270
277
|
| `suppa_list_entities` | List entities (tables) |
|
|
271
|
-
| `suppa_describe_entity` | Field definitions + types for an entity |
|
|
278
|
+
| `suppa_describe_entity` | Field definitions + types for an entity (compact by default; `full=true` for the raw schema) |
|
|
272
279
|
| `suppa_list_tabular_parts` | List tabular parts (ТЧ) of an entity |
|
|
273
280
|
| `suppa_search_records` | Search / filter records in any entity — nested AND/OR groups, auto-diagnoses an empty result (`deleted_scope` finds soft-deleted rows) |
|
|
274
281
|
| `suppa_validate_select` | Check a select/filter payload against the entity without running it — names the field that does not resolve |
|
package/dist/httpClient.js
CHANGED
|
@@ -9,6 +9,7 @@ import { assertMergeLists, elideEchoedResponse, stripAccessMetadata } from "./ut
|
|
|
9
9
|
import * as tenants from "./tenants.js";
|
|
10
10
|
import { lastRefreshError } from "./sessionDiag.js";
|
|
11
11
|
import { isOwnProjection, withoutPaths } from "./projection.js";
|
|
12
|
+
import { dropNullDeletedAt } from "./readEconomy.js";
|
|
12
13
|
// Re-exported so the transport stays the single import for entity reads.
|
|
13
14
|
export { ownProjection, isOwnProjection } from "./projection.js";
|
|
14
15
|
// HTTP statuses that signal a transient upstream problem worth one retry.
|
|
@@ -660,8 +661,11 @@ async function postEntityRead(entity, path, body, fields, opts = {}) {
|
|
|
660
661
|
payload = { ...body, fields: withoutPaths(fields, known) };
|
|
661
662
|
}
|
|
662
663
|
}
|
|
664
|
+
// A projection this server wrote also comes back without the platform's
|
|
665
|
+
// `deletedAt: null` on every relation it expanded — see dropNullDeletedAt.
|
|
666
|
+
const shaped = (result) => (own ? dropNullDeletedAt(result, fields) : result);
|
|
663
667
|
try {
|
|
664
|
-
return await makeRequest("POST", path, payload, opts);
|
|
668
|
+
return shaped(await makeRequest("POST", path, payload, opts));
|
|
665
669
|
}
|
|
666
670
|
catch (e) {
|
|
667
671
|
if (!own) {
|
|
@@ -682,7 +686,7 @@ async function postEntityRead(entity, path, body, fields, opts = {}) {
|
|
|
682
686
|
throw e; // the retry named the same fields — the problem is elsewhere
|
|
683
687
|
}
|
|
684
688
|
debug(`${entity}: this tenant has no ${bad.join(", ")} — retrying without them`);
|
|
685
|
-
return await makeRequest("POST", path, { ...body, fields: withoutPaths(fields, known) }, opts);
|
|
689
|
+
return shaped(await makeRequest("POST", path, { ...body, fields: withoutPaths(fields, known) }, opts));
|
|
686
690
|
}
|
|
687
691
|
}
|
|
688
692
|
export async function searchEntity(entity, filters = null, fields = null, limit = 50, offset = 0, orderBy = null, searchValue = "", operator = "and", deletedScope = DEFAULT_DELETED_SCOPE, includeDeletedRelations = DEFAULT_INCLUDE_DELETED_RELATIONS) {
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Read results, minus the bytes that carry no information.
|
|
3
|
+
*
|
|
4
|
+
* A read is re-sent on every later turn of the conversation, so a schema read
|
|
5
|
+
* of 43,000 characters is not paid once. Measured on a live tenant, one
|
|
6
|
+
* `describe_entity` on Tasks spent 339 keys on `null`, 69 copies of each of the
|
|
7
|
+
* seven field options at their platform default, and a 110-character
|
|
8
|
+
* localisation record per field of which the model reads one word.
|
|
9
|
+
*
|
|
10
|
+
* Every reduction here is reversible in the reader's head, and the reader is
|
|
11
|
+
* told the rule (the `_legend` key on a schema): an absent constraint is null,
|
|
12
|
+
* an absent flag is false, an absent option is at its default, an absent
|
|
13
|
+
* deletedAt on a relation is a live row. Nothing that DIFFERS from the default
|
|
14
|
+
* is ever removed, so no field is misdescribed — the compact form says exactly
|
|
15
|
+
* what the full one says. The full form stays one flag away (`full=true`).
|
|
16
|
+
*
|
|
17
|
+
* Only the server's OWN reads are shaped: the schema tools and the projections
|
|
18
|
+
* this server wrote (tasks, forms, automations). A projection the caller wrote
|
|
19
|
+
* is returned as the platform sent it — they asked for those keys.
|
|
20
|
+
*
|
|
21
|
+
* Dependency-light on purpose (utils only), so tool modules and the transport
|
|
22
|
+
* can both import it without a cycle.
|
|
23
|
+
*/
|
|
24
|
+
import { stripHtml } from "./utils.js";
|
|
25
|
+
const isObj = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
26
|
+
/**
|
|
27
|
+
* The field options the platform applies when none is given (verified on a live
|
|
28
|
+
* tenant 2026-08-17; the builder doc lists them as false, which the platform
|
|
29
|
+
* contradicts). House rule 3 says never to WRITE one of these; the same fact
|
|
30
|
+
* says there is nothing to READ in one either.
|
|
31
|
+
*/
|
|
32
|
+
export const PLATFORM_OPTION_DEFAULTS = Object.freeze({
|
|
33
|
+
canGroup: true,
|
|
34
|
+
canSort: true,
|
|
35
|
+
showInTable: true,
|
|
36
|
+
editFromTable: true,
|
|
37
|
+
canFilter: true,
|
|
38
|
+
readOnly: false,
|
|
39
|
+
searchable: false,
|
|
40
|
+
});
|
|
41
|
+
/** Field flags at the value the platform stores when nothing was asked for. */
|
|
42
|
+
const FIELD_FLAG_DEFAULTS = Object.freeze({
|
|
43
|
+
isArray: false,
|
|
44
|
+
isPrimary: false,
|
|
45
|
+
isOnlyPositive: false,
|
|
46
|
+
isCustom: false,
|
|
47
|
+
unique: false,
|
|
48
|
+
notNull: false,
|
|
49
|
+
decimalPlaces: 0,
|
|
50
|
+
});
|
|
51
|
+
/** The keys of a platform localisation record that are bookkeeping, not text. */
|
|
52
|
+
const I18N_BOOKKEEPING = new Set(["id", "key", "name"]);
|
|
53
|
+
export const SCHEMA_LEGEND = "Compact schema: a field omits constraints that are null, flags that are false/0 " +
|
|
54
|
+
"(isArray, isPrimary, isOnlyPositive, unique, notNull, decimalPlaces) and options at the " +
|
|
55
|
+
"platform defaults (canGroup/canSort/showInTable/editFromTable/canFilter true; " +
|
|
56
|
+
"readOnly/searchable false); titles keep language keys only. Absent means default, " +
|
|
57
|
+
"not unknown. full=true returns the platform's raw schema.";
|
|
58
|
+
/**
|
|
59
|
+
* A localisation record `{id, key, name, en, uk, …}` reduced to its language
|
|
60
|
+
* keys. The bookkeeping names the i18n row and the entity it was declared on —
|
|
61
|
+
* nothing a reader of the schema acts on, and 90 characters per field.
|
|
62
|
+
*/
|
|
63
|
+
export function slimTitle(title) {
|
|
64
|
+
if (!isObj(title))
|
|
65
|
+
return title;
|
|
66
|
+
const out = {};
|
|
67
|
+
for (const [k, v] of Object.entries(title)) {
|
|
68
|
+
if (I18N_BOOKKEEPING.has(k) || v === null || v === undefined)
|
|
69
|
+
continue;
|
|
70
|
+
out[k] = v;
|
|
71
|
+
}
|
|
72
|
+
return Object.keys(out).length > 0 ? out : title;
|
|
73
|
+
}
|
|
74
|
+
/** Field options with the platform defaults removed. */
|
|
75
|
+
export function compactOptions(options) {
|
|
76
|
+
const out = {};
|
|
77
|
+
for (const [k, v] of Object.entries(options)) {
|
|
78
|
+
if (v === null || v === undefined)
|
|
79
|
+
continue;
|
|
80
|
+
if (k in PLATFORM_OPTION_DEFAULTS && v === PLATFORM_OPTION_DEFAULTS[k])
|
|
81
|
+
continue;
|
|
82
|
+
out[k] = v;
|
|
83
|
+
}
|
|
84
|
+
return out;
|
|
85
|
+
}
|
|
86
|
+
/** One field of an entity schema in compact form (see SCHEMA_LEGEND). */
|
|
87
|
+
export function compactField(field) {
|
|
88
|
+
if (!isObj(field))
|
|
89
|
+
return field;
|
|
90
|
+
const out = {};
|
|
91
|
+
for (const [k, v] of Object.entries(field)) {
|
|
92
|
+
if (v === null || v === undefined)
|
|
93
|
+
continue;
|
|
94
|
+
if (k in FIELD_FLAG_DEFAULTS && v === FIELD_FLAG_DEFAULTS[k])
|
|
95
|
+
continue;
|
|
96
|
+
if (k === "options" && isObj(v)) {
|
|
97
|
+
const o = compactOptions(v);
|
|
98
|
+
if (Object.keys(o).length > 0)
|
|
99
|
+
out.options = o;
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
if (k === "title") {
|
|
103
|
+
out.title = slimTitle(v);
|
|
104
|
+
continue;
|
|
105
|
+
}
|
|
106
|
+
out[k] = v;
|
|
107
|
+
}
|
|
108
|
+
return out;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* An entity schema (GET /api/core/schema/<name>) in compact form. Every key the
|
|
112
|
+
* platform sent at the entity level is kept except nulls; `fields` and
|
|
113
|
+
* `customFields` are compacted per field; the legend goes first so it is read
|
|
114
|
+
* before the fields it explains.
|
|
115
|
+
*/
|
|
116
|
+
export function compactEntitySchema(raw) {
|
|
117
|
+
if (!isObj(raw))
|
|
118
|
+
return raw;
|
|
119
|
+
const out = { _legend: SCHEMA_LEGEND };
|
|
120
|
+
for (const [k, v] of Object.entries(raw)) {
|
|
121
|
+
if (v === null || v === undefined)
|
|
122
|
+
continue;
|
|
123
|
+
if ((k === "fields" || k === "customFields") && Array.isArray(v)) {
|
|
124
|
+
out[k] = v.map(compactField);
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
if (k === "title") {
|
|
128
|
+
out.title = slimTitle(v);
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
out[k] = v;
|
|
132
|
+
}
|
|
133
|
+
return out;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Relation expansions come back with the platform's own `deletedAt` on each —
|
|
137
|
+
* null on every live row, nine times per task, on every task. Removed where
|
|
138
|
+
* null, only inside the relation objects the PROJECTION itself names (so a
|
|
139
|
+
* `json` field's contents are never walked), and never where the projection
|
|
140
|
+
* asked for deletedAt. A non-null value — the related row IS deleted — is
|
|
141
|
+
* information and stays. The row's own top-level deletedAt is never touched.
|
|
142
|
+
*
|
|
143
|
+
* Mutates in place: the input is a response body this process just parsed.
|
|
144
|
+
*/
|
|
145
|
+
export function dropNullDeletedAt(result, projection) {
|
|
146
|
+
if (Array.isArray(result)) {
|
|
147
|
+
for (const row of result)
|
|
148
|
+
dropNullDeletedAt(row, projection);
|
|
149
|
+
return result;
|
|
150
|
+
}
|
|
151
|
+
if (!isObj(result))
|
|
152
|
+
return result;
|
|
153
|
+
for (const [key, sub] of Object.entries(projection)) {
|
|
154
|
+
if (!isObj(sub))
|
|
155
|
+
continue; // a leaf — never descend into a value
|
|
156
|
+
const value = result[key];
|
|
157
|
+
const related = Array.isArray(value) ? value : [value];
|
|
158
|
+
for (const row of related) {
|
|
159
|
+
if (!isObj(row))
|
|
160
|
+
continue;
|
|
161
|
+
if (row.deletedAt === null && sub.deletedAt !== true)
|
|
162
|
+
delete row.deletedAt;
|
|
163
|
+
dropNullDeletedAt(row, sub);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
return result;
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* A stage's status as the one word that matters. The platform expands the
|
|
170
|
+
* enum reference into `{id, value, title, deletedAt}`; `value` is what every
|
|
171
|
+
* stage decision in this server (active? completed?) reads, and `title` is its
|
|
172
|
+
* capitalised twin.
|
|
173
|
+
*/
|
|
174
|
+
export function statusValue(status) {
|
|
175
|
+
return isObj(status) && typeof status.value === "string" ? status.value : status;
|
|
176
|
+
}
|
|
177
|
+
const collapseWs = (s) => s.replace(/\s+/g, " ").trim();
|
|
178
|
+
/**
|
|
179
|
+
* A task carries its description twice — as HTML and as the platform's plain
|
|
180
|
+
* rendering of the same HTML — and on a real task that is the whole payload
|
|
181
|
+
* (51,000 characters, of which half is the other half without tags). When the
|
|
182
|
+
* plain text is exactly the HTML with its tags removed, it is dropped and the
|
|
183
|
+
* HTML kept: HTML is what an edit has to send back, and the text is one
|
|
184
|
+
* tag-strip away. When they differ — the platform rendered something the strip
|
|
185
|
+
* does not — both come back, because the difference is information.
|
|
186
|
+
*/
|
|
187
|
+
export function dropDerivablePlainDescription(row) {
|
|
188
|
+
if (Array.isArray(row))
|
|
189
|
+
return row.map(dropDerivablePlainDescription);
|
|
190
|
+
if (!isObj(row))
|
|
191
|
+
return row;
|
|
192
|
+
const html = row.htmlDescription;
|
|
193
|
+
const plain = row.plainDescription;
|
|
194
|
+
if (typeof html !== "string" || typeof plain !== "string" || !html || !plain)
|
|
195
|
+
return row;
|
|
196
|
+
if (collapseWs(stripHtml(html)) !== collapseWs(plain))
|
|
197
|
+
return row;
|
|
198
|
+
const { plainDescription: _derivable, ...rest } = row;
|
|
199
|
+
return rest;
|
|
200
|
+
}
|