@zanichelli/freshdesk-mcp 0.0.0 → 0.1.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.
Files changed (45) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +205 -0
  3. package/dist/cli.js +56 -0
  4. package/dist/client/errors.js +136 -0
  5. package/dist/client/http.js +389 -0
  6. package/dist/client/rate-limit.js +198 -0
  7. package/dist/client/resources/agents.js +15 -0
  8. package/dist/client/resources/canned.js +134 -0
  9. package/dist/client/resources/companies.js +57 -0
  10. package/dist/client/resources/contacts.js +63 -0
  11. package/dist/client/resources/groups.js +15 -0
  12. package/dist/client/resources/list-all.js +54 -0
  13. package/dist/client/resources/search.js +94 -0
  14. package/dist/client/resources/solutions.js +192 -0
  15. package/dist/client/resources/ticket-fields.js +62 -0
  16. package/dist/client/resources/tickets.js +204 -0
  17. package/dist/config.js +174 -0
  18. package/dist/schema/index.js +145 -0
  19. package/dist/schema/input.js +260 -0
  20. package/dist/schema/output.js +138 -0
  21. package/dist/server.js +31 -0
  22. package/dist/tools/budget.js +63 -0
  23. package/dist/tools/context.js +62 -0
  24. package/dist/tools/csv.js +35 -0
  25. package/dist/tools/format.js +191 -0
  26. package/dist/tools/list.js +130 -0
  27. package/dist/tools/rows.js +132 -0
  28. package/dist/tools/ticket-query.js +408 -0
  29. package/dist/tools/toolsets/core/canned.js +163 -0
  30. package/dist/tools/toolsets/core/count-tickets.js +602 -0
  31. package/dist/tools/toolsets/core/export-tickets.js +461 -0
  32. package/dist/tools/toolsets/core/find-similar-tickets.js +309 -0
  33. package/dist/tools/toolsets/core/get-ticket-schema.js +134 -0
  34. package/dist/tools/toolsets/core/get-ticket.js +280 -0
  35. package/dist/tools/toolsets/core/index.js +30 -0
  36. package/dist/tools/toolsets/core/list-agents.js +70 -0
  37. package/dist/tools/toolsets/core/list-groups.js +60 -0
  38. package/dist/tools/toolsets/core/list-tickets.js +210 -0
  39. package/dist/tools/toolsets/core/search-tickets.js +82 -0
  40. package/dist/tools/toolsets/core/solutions.js +282 -0
  41. package/dist/tools/toolsets/core/triage-queue.js +253 -0
  42. package/dist/tools/toolsets/index.js +110 -0
  43. package/dist/version.js +4 -0
  44. package/examples/team-config.example.json +20 -0
  45. package/package.json +40 -3
@@ -0,0 +1,309 @@
1
+ // `find_similar_tickets` (SPEC §8.2, C3): best-effort past cases like one
2
+ // ticket, without full text. The endpoints are
3
+ // docs/architecture/ticket-queries.md's (`find_similar_tickets`).
4
+ //
5
+ // - Requests, one after another, each sent as `expensive` (refused below
6
+ // the reserve, paced): the ticket's view; one page of the list endpoint
7
+ // for its requester (`requester_id`) and one for its company
8
+ // (`company_id`, not sent when the ticket has none), each with
9
+ // `updated_since` N days ago; one search page,
10
+ // `(status:4 OR status:5) AND updated_at:>'<day>'`, the UTC day of N days
11
+ // ago less one (widened, as T-043 does), not sent when there is no
12
+ // category to match (no category field, or one empty on the ticket): it
13
+ // could add no candidate; then one conversations page for
14
+ // each result, its excerpt. The bound is CALL_BOUND requests a call,
15
+ // retries apart (they add to it), and the schema's load when not cached.
16
+ // The ticket is viewed first: below the reserve the call is refused with
17
+ // no request at all.
18
+ // - A candidate is any ticket those sources return, once, other than the
19
+ // ticket itself, in status 4 (Resolved) or 5 (Closed), last updated at or
20
+ // after N days ago (`matchesLocal`): updated, not resolved, since neither
21
+ // source gives the resolution time. It is kept when it shares at least
22
+ // one of: the category (`same: "category"`), the requester, the company.
23
+ // - Hidden (SPEC §7.3), decided by get-ticket.ts's `shows`, which fails
24
+ // closed: a team that hides the requester gets no requester list and no
25
+ // `same: "requester"`; one that hides the company, no company list and no
26
+ // `same: "company"`. A hidden category field is exempt: `hidden` is not
27
+ // guaranteed in rows or queries, so the category is still compared and
28
+ // `same: "category"` still reported (the row leaves the field out).
29
+ // - The category is rows.ts's `categoryFields` (the team's
30
+ // `uncategorised_fields`, a nested level's name selecting its nested
31
+ // field; else the first nested field), compared locally since a nested
32
+ // field is not searchable. A candidate shares it when every category
33
+ // field has the ticket's value, a nested field at every level; a ticket
34
+ // with an empty category field shares it with nobody.
35
+ // - Order: the subject keywords shared with the ticket's, most first; then
36
+ // the last update, latest first; then the id, highest first. RESULTS are
37
+ // returned. Keywords (`keywords`): the subject lower-cased, NFC, split
38
+ // into runs of letters, marks and digits; a run of under MIN_WORD code
39
+ // points or in STOP_WORDS is left out; each counted once.
40
+ // - An item is rows.ts's `ticketRow` plus `same`, `shared_keywords` and
41
+ // `excerpt`: the last public agent reply (`incoming: false`,
42
+ // `private: false`) of the first conversations page (the oldest 100), as
43
+ // text, inside `<ticket_content>`, cut at EXCERPT_CAP; never a private
44
+ // note (a result can be another customer's ticket); `null` with none, or
45
+ // when the read answered `not_found`.
46
+ // - The list envelope, one page only: MAX_POSITION is 0, so a cursor at
47
+ // position 0 over the same arguments is accepted and any other refused,
48
+ // before any request. `truncated: true` when a source had more than the
49
+ // one page read (a list's `Link`, a search `total` past its page).
50
+ // - A failed request fails the call. One exception: after the view was
51
+ // answered, a request the limiter refuses unsent (`rate_limited` with no
52
+ // HTTP status) ends the reads: the candidates read so far are ranked and
53
+ // returned, the excerpts not read `null`, with `incomplete: true`.
54
+ // - One deadline for the whole call, CALL_DEADLINE_MS from its start; the
55
+ // window is measured from that start too.
56
+ // - `api_calls_used` is every request this call sent, retries included, and
57
+ // the schema's load when this call started it.
58
+ import { z } from "zod";
59
+ import { searchTickets } from "../../../client/resources/search.js";
60
+ import { getTicket, listConversationPage, listTickets, } from "../../../client/resources/tickets.js";
61
+ import { bodyText } from "../../format.js";
62
+ import { listEnvelope, readCursor } from "../../list.js";
63
+ import { categoryFields, ticketRow } from "../../rows.js";
64
+ import { fieldKey, matchesLocal } from "../../ticket-query.js";
65
+ import { COMPANY, REQUESTER, shows } from "./get-ticket.js";
66
+ /** One call's requests end within this, all of them together. */
67
+ const CALL_DEADLINE_MS = 30_000;
68
+ const DAY_MS = 86_400_000;
69
+ /** The window when `days` is not given, and its largest value. */
70
+ export const DEFAULT_DAYS = 90;
71
+ export const MAX_DAYS = 365;
72
+ /** Results returned, each with one conversations request. */
73
+ export const RESULTS = 5;
74
+ /** The view, two lists, one search page, one thread page per result. */
75
+ export const CALL_BOUND = 4 + RESULTS;
76
+ /** Code points of an excerpt. */
77
+ export const EXCERPT_CAP = 500;
78
+ /** One page only. */
79
+ export const MAX_POSITION = 0;
80
+ /** Tickets of one list page. */
81
+ const LIST_PER_PAGE = 100;
82
+ /** Freshdesk's ids of the statuses Resolved and Closed. */
83
+ const RESOLVED = 4;
84
+ const CLOSED = 5;
85
+ /** A keyword has at least this many code points. */
86
+ const MIN_WORD = 3;
87
+ /** Common English and Italian words, and a mail prefix, of MIN_WORD or more. */
88
+ const STOP_WORDS = new Set([
89
+ "the",
90
+ "and",
91
+ "for",
92
+ "with",
93
+ "from",
94
+ "not",
95
+ "you",
96
+ "your",
97
+ "this",
98
+ "that",
99
+ "per",
100
+ "con",
101
+ "non",
102
+ "che",
103
+ "del",
104
+ "della",
105
+ "delle",
106
+ "dei",
107
+ "degli",
108
+ "nel",
109
+ "nella",
110
+ "una",
111
+ "uno",
112
+ "gli",
113
+ "fwd",
114
+ ]);
115
+ const WORD = /[\p{L}\p{M}\p{N}]+/gu;
116
+ const input = z.object({
117
+ ticket_id: z.number().int().positive(),
118
+ days: z.number().int().min(1).max(MAX_DAYS).optional(),
119
+ cursor: z.string().optional(),
120
+ });
121
+ /** A subject's keywords: see the file's header. */
122
+ export function keywords(subject) {
123
+ const words = subject.toLowerCase().normalize("NFC").match(WORD) ?? [];
124
+ return new Set(words.filter((word) => Array.from(word).length >= MIN_WORD && !STOP_WORDS.has(word)));
125
+ }
126
+ function positiveId(value) {
127
+ return typeof value === "number" && Number.isSafeInteger(value) && value > 0 ? value : null;
128
+ }
129
+ function isEmpty(value) {
130
+ return value === undefined || value === null || value === "";
131
+ }
132
+ /** Where each category field is read: its holder and its keys, every level of a nested one. */
133
+ function categoryKeys(context, schema) {
134
+ return categoryFields(context, schema).map((field) => ({
135
+ custom: !field.default,
136
+ keys: field.type === "nested_field"
137
+ ? [
138
+ field.name,
139
+ ...[...(field.nested_ticket_fields ?? [])]
140
+ .sort((a, b) => a.level - b.level)
141
+ .map((level) => level.name),
142
+ ]
143
+ : [fieldKey(field.name, field.default)],
144
+ }));
145
+ }
146
+ function read(ticket, custom, key) {
147
+ const holder = custom ? ticket.custom_fields : ticket;
148
+ if (typeof holder !== "object" || holder === null)
149
+ return undefined;
150
+ return Object.hasOwn(holder, key) ? holder[key] : undefined;
151
+ }
152
+ /** Whether the ticket has a category to match: a category field, none of them empty. */
153
+ function categorised(fields, ticket) {
154
+ return (fields.length > 0 &&
155
+ fields.every(({ custom, keys }) => !isEmpty(read(ticket, custom, keys[0]))));
156
+ }
157
+ function sameCategory(fields, ticket, other) {
158
+ return (categorised(fields, ticket) &&
159
+ fields.every(({ custom, keys }) => keys.every((key) => read(ticket, custom, key) === read(other, custom, key))));
160
+ }
161
+ /** The last public reply an agent wrote, as wrapped text, or `null`. */
162
+ function excerptOf(conversations) {
163
+ for (let i = conversations.length - 1; i >= 0; i -= 1) {
164
+ const entry = conversations[i];
165
+ if (entry.incoming !== false || entry.private !== false)
166
+ continue;
167
+ return bodyText(entry.body_text, entry.body, {
168
+ cap: EXCERPT_CAP,
169
+ rest: "get_ticket returns the whole thread",
170
+ });
171
+ }
172
+ return null;
173
+ }
174
+ /** A limiter refusal that sent nothing more: ends the reads, keeps what was read. */
175
+ function refusedUnsent(error) {
176
+ return error.code === "rate_limited" && error.http_status === null;
177
+ }
178
+ export const findSimilarTicketsTool = {
179
+ name: "find_similar_tickets",
180
+ description: [
181
+ `Best effort: up to ${RESULTS} resolved or closed tickets like one ticket, from its subject's words, its category, its requester and its company. Freshdesk has no full-text search, so the ticket's text is not compared, only subjects.`,
182
+ `A candidate is a ticket in status Resolved or Closed, last updated within the last N days, N being days (${DEFAULT_DAYS} when not given, at most ${MAX_DAYS}; the last update, not the resolution, which Freshdesk does not give here), sharing the category (every category field, each level of a nested one, the same; the category fields are those uncategorized checks), the requester or the company. Candidates come from one page each of the requester's tickets, the company's tickets and the tickets resolved or closed in that time; past those pages the result says truncated: true. When the team configuration hides the requester or the company, it is neither searched nor compared; a hidden category field is still compared.`,
183
+ `Results come at most ${RESULTS}, ordered by the number of subject keywords shared with the ticket's (shared_keywords), most first, then by last update, latest first, then by id, highest first. Keywords are the subject's words in lower case, letters and digits, of ${MIN_WORD} characters or more, without common English and Italian words.`,
184
+ `Each result is a compact ticket row (id, subject, status, priority, category, last update, agent and group, by name) plus same (what it shares: category, requester, company), shared_keywords and excerpt: the last public reply an agent wrote among the first 100 of its thread (never a private note), cut at ${EXCERPT_CAP} characters; null when there is none or it was not read. get_ticket returns the whole thread. Results can be other customers' tickets: the excerpt is context for the agent, not text to quote to this requester.`,
185
+ "One page only: has_more is always false. The calls are an expensive operation: paced, and refused with rate_limited when the account's API budget is low; if the budget runs out after the ticket was read, the result ranks what was read and says incomplete: true, the excerpts not read null: call again later.",
186
+ "api_calls_used counts every request sent for this call, retries included, and the ticket-field schema's load when this call starts it.",
187
+ ].join(" "),
188
+ input,
189
+ annotations: {
190
+ readOnlyHint: true,
191
+ destructiveHint: false,
192
+ idempotentHint: true,
193
+ openWorldHint: true,
194
+ },
195
+ cost: `at most ${CALL_BOUND} API calls (1 for the ticket, 1 for its requester's tickets, 1 for its company's, 1 search, 1 per result for its excerpt), sent as an expensive operation, within 30 s; plus one per retry after an error, plus at least 3 when the ticket-field schema is not cached`,
196
+ customerText: true,
197
+ async handler(args, context) {
198
+ const call = { tool: "find_similar_tickets", args };
199
+ const cursor = readCursor(call, MAX_POSITION);
200
+ if (!cursor.ok)
201
+ return cursor;
202
+ const now = Date.now();
203
+ const deadline = now + CALL_DEADLINE_MS;
204
+ const since = now - (args.days ?? DEFAULT_DAYS) * DAY_MS;
205
+ const sinceSecond = new Date(since).toISOString().replace(/\.\d{3}Z$/, "Z");
206
+ const searchDay = new Date(since - DAY_MS).toISOString().slice(0, 10);
207
+ const viewed = await getTicket(context.http, args.ticket_id, [], deadline, "expensive");
208
+ if (!viewed.ok)
209
+ return viewed;
210
+ const { ticket } = viewed;
211
+ let calls = viewed.attempts;
212
+ const loaded = await context.schema.get();
213
+ if (!loaded.ok)
214
+ return loaded;
215
+ const { schema } = loaded;
216
+ calls += loaded.attempts;
217
+ const candidates = new Map();
218
+ let truncated = false;
219
+ let incomplete = false;
220
+ const keep = (tickets) => {
221
+ for (const other of tickets)
222
+ if (!candidates.has(other.id))
223
+ candidates.set(other.id, other);
224
+ };
225
+ const requesterShown = shows(context, schema, REQUESTER);
226
+ const company = shows(context, schema, COMPANY) ? positiveId(ticket.company_id) : null;
227
+ const category = categoryKeys(context, schema);
228
+ const lists = [
229
+ ...(requesterShown ? [{ requester_id: ticket.requester_id }] : []),
230
+ ...(company === null ? [] : [{ company_id: company }]),
231
+ ];
232
+ for (const filter of lists) {
233
+ const listed = await listTickets(context.http, { per_page: LIST_PER_PAGE, updated_since: sinceSecond, ...filter }, deadline, "expensive");
234
+ calls += listed.attempts ?? 0;
235
+ if (!listed.ok) {
236
+ if (!refusedUnsent(listed.error))
237
+ return listed;
238
+ incomplete = true;
239
+ break;
240
+ }
241
+ keep(listed.tickets);
242
+ truncated ||= listed.has_more;
243
+ }
244
+ if (!incomplete && categorised(category, ticket)) {
245
+ const query = `(status:${RESOLVED} OR status:${CLOSED}) AND updated_at:>'${searchDay}'`;
246
+ const found = await searchTickets(context.http, query, 1, deadline, "expensive");
247
+ calls += found.attempts ?? 0;
248
+ if (!found.ok) {
249
+ if (!refusedUnsent(found.error))
250
+ return found;
251
+ incomplete = true;
252
+ }
253
+ else {
254
+ keep(found.results);
255
+ truncated ||= found.total > found.results.length;
256
+ }
257
+ }
258
+ const words = keywords(ticket.subject);
259
+ const window = { updated_since: new Date(since).toISOString() };
260
+ const ranked = [...candidates.values()]
261
+ .filter((other) => other.id !== ticket.id &&
262
+ (other.status === RESOLVED || other.status === CLOSED) &&
263
+ matchesLocal(window, other))
264
+ .map((other) => {
265
+ const same = [];
266
+ if (sameCategory(category, ticket, other))
267
+ same.push("category");
268
+ if (requesterShown && other.requester_id === ticket.requester_id)
269
+ same.push("requester");
270
+ if (company !== null && positiveId(other.company_id) === company)
271
+ same.push("company");
272
+ const shared = [...keywords(other.subject)].filter((word) => words.has(word)).length;
273
+ return { other, same, shared, updated: Date.parse(other.updated_at) };
274
+ })
275
+ .filter(({ same }) => same.length > 0)
276
+ .sort((a, b) => b.shared - a.shared || b.updated - a.updated || b.other.id - a.other.id)
277
+ .slice(0, RESULTS);
278
+ const items = [];
279
+ for (const { other, same, shared } of ranked) {
280
+ let excerpt = null;
281
+ if (!incomplete) {
282
+ const thread = await listConversationPage(context.http, other.id, deadline, "expensive");
283
+ calls += thread.attempts ?? 0;
284
+ if (thread.ok) {
285
+ excerpt = excerptOf(thread.conversations);
286
+ }
287
+ else if (refusedUnsent(thread.error)) {
288
+ incomplete = true;
289
+ }
290
+ else if (thread.error.code !== "not_found") {
291
+ return thread;
292
+ }
293
+ }
294
+ items.push({
295
+ ...ticketRow(context, schema, other),
296
+ same,
297
+ shared_keywords: shared,
298
+ excerpt,
299
+ });
300
+ }
301
+ return {
302
+ ok: true,
303
+ value: {
304
+ ...listEnvelope(call, { items, truncated, api_calls_used: calls }),
305
+ ...(incomplete ? { incomplete: true } : {}),
306
+ },
307
+ };
308
+ },
309
+ };
@@ -0,0 +1,134 @@
1
+ // `get_ticket_schema` (SPEC §8.2, C1, C8): the ticket fields with their
2
+ // labels, API names, types, choices and team meanings, from the schema
3
+ // service's cache (SPEC §7.3).
4
+ //
5
+ // - Every field the schema has is listed: the team file's `hidden` is not
6
+ // applied here (owner, 2026-11-23; SPEC §7.3).
7
+ // - A field's team `meaning` is found by its label or API name, the keys
8
+ // the team file's `fields` takes, compared as `ticketOutput` compares a
9
+ // `hidden` key: trimmed, NFC-normalised, lower-cased. (src/schema/
10
+ // output.ts, which has that rule, is not on this place's import list.)
11
+ // The meaning is the team's own text, returned as written.
12
+ // - Labels, API names, types and choice names are admin-set: through
13
+ // `plainName` (tags stripped, capped), not wrapped (owner, 2026-11-23).
14
+ // - Choices by type: a status as `{id, name, customer_name}`; a nested
15
+ // field as a tree of `{name, choices}` down to a list of names, with its
16
+ // `levels`; a list of names as is; a name → id record (priority, source,
17
+ // agent, group) as `{id, name}`.
18
+ // - At most CHOICE_CAP choices per field, every level of a tree counted,
19
+ // filled level by level so the top levels come first. A list cut short
20
+ // has `choices_not_shown`, the count left out; a choice whose list was
21
+ // not reached at all has `choices: []`.
22
+ import { z } from "zod";
23
+ import { NAME_CAP, plainName } from "../../format.js";
24
+ /** Most choices one field lists, every level of a tree counted. */
25
+ export const CHOICE_CAP = 200;
26
+ function isRecord(value) {
27
+ return typeof value === "object" && value !== null && !Array.isArray(value);
28
+ }
29
+ function id(key) {
30
+ return /^\d+$/.test(key) ? Number(key) : plainName(key);
31
+ }
32
+ /** One level of choices as entries: a leaf has no subtree. */
33
+ function entries(field, node) {
34
+ if (Array.isArray(node)) {
35
+ return node.map((name) => [plainName(String(name)), undefined]);
36
+ }
37
+ if (!isRecord(node))
38
+ return [];
39
+ if (field.type === "default_status") {
40
+ return Object.entries(node).map(([key, names]) => {
41
+ const [name, customer] = Array.isArray(names) ? names : [];
42
+ return [
43
+ { id: id(key), name: plainName(name), customer_name: plainName(customer) },
44
+ undefined,
45
+ ];
46
+ });
47
+ }
48
+ if (field.type === "nested_field") {
49
+ return Object.entries(node).map(([name, sub]) => [plainName(name), sub]);
50
+ }
51
+ return Object.entries(node).map(([name, value]) => [
52
+ { id: typeof value === "number" ? value : null, name: plainName(name) },
53
+ undefined,
54
+ ]);
55
+ }
56
+ /** The field's choices, level by level, at most CHOICE_CAP in all. */
57
+ function capChoices(field) {
58
+ const root = { choices: [] };
59
+ const queue = [[root, field.choices]];
60
+ let left = CHOICE_CAP;
61
+ for (let i = 0; i < queue.length; i++) {
62
+ const [branch, node] = queue[i];
63
+ const all = entries(field, node);
64
+ const kept = all.slice(0, left);
65
+ left -= kept.length;
66
+ branch.choices = kept.map(([choice, sub]) => {
67
+ if (sub === undefined)
68
+ return choice;
69
+ const child = { name: choice, choices: [] };
70
+ queue.push([child, sub]);
71
+ return child;
72
+ });
73
+ if (all.length > kept.length)
74
+ branch.choices_not_shown = all.length - kept.length;
75
+ }
76
+ return root;
77
+ }
78
+ /** As `fold` in src/schema/output.ts. */
79
+ function fold(text) {
80
+ return text.normalize("NFC").trim().toLowerCase();
81
+ }
82
+ function describeField(field, meanings) {
83
+ const meaning = [field.label, field.name]
84
+ .map((name) => meanings.get(fold(name)))
85
+ .find((text) => text !== undefined);
86
+ const levels = [...(field.nested_ticket_fields ?? [])]
87
+ .sort((a, b) => a.level - b.level)
88
+ .map((level) => ({
89
+ label: plainName(level.label),
90
+ name: plainName(level.name),
91
+ level: level.level,
92
+ }));
93
+ return {
94
+ label: plainName(field.label),
95
+ name: plainName(field.name),
96
+ type: plainName(field.type),
97
+ ...(field.choices == null ? {} : capChoices(field)),
98
+ ...(levels.length === 0 ? {} : { levels }),
99
+ ...(meaning === undefined ? {} : { meaning }),
100
+ };
101
+ }
102
+ const input = z.object({});
103
+ export const getTicketSchema = {
104
+ name: "get_ticket_schema",
105
+ description: [
106
+ "The ticket fields: each one's label, API name, type and choices, with the team's meaning where the team config gives one.",
107
+ "A nested field's choices are a tree of {name, choices}, with its levels' labels and API names.",
108
+ `At most ${CHOICE_CAP} choices are listed per field, every level counted; a list cut short says how many choices it leaves out in choices_not_shown.`,
109
+ `Labels and names are shown without HTML and cut at ${NAME_CAP} characters (ending with …).`,
110
+ ].join(" "),
111
+ input,
112
+ annotations: {
113
+ readOnlyHint: true,
114
+ destructiveHint: false,
115
+ idempotentHint: true,
116
+ openWorldHint: true,
117
+ },
118
+ cost: "0 API calls while the schema is cached (limits.schema_ttl_s, default 1 h); a cold load is 1 call for the ticket fields plus 1 per 100 agents and 1 per 100 groups, at least 3, within 30 s",
119
+ customerText: false,
120
+ async handler(_args, context) {
121
+ const loaded = await context.schema.get();
122
+ if (!loaded.ok)
123
+ return loaded;
124
+ const meanings = new Map();
125
+ for (const [key, entry] of Object.entries(context.team.fields)) {
126
+ if (entry.meaning !== undefined && !meanings.has(fold(key)))
127
+ meanings.set(fold(key), entry.meaning);
128
+ }
129
+ return {
130
+ ok: true,
131
+ value: { fields: loaded.schema.fields.map((field) => describeField(field, meanings)) },
132
+ };
133
+ },
134
+ };