@workover/mcp 0.20.0 → 0.23.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 +2 -0
- package/contacts.mjs +1561 -0
- package/domains.mjs +417 -0
- package/email-studio.mjs +829 -0
- package/feedback-board.mjs +321 -0
- package/index.mjs +419 -5
- package/journeys.mjs +409 -0
- package/lib.mjs +638 -4
- package/package.json +20 -1
- package/support-agent-tests.mjs +424 -0
- package/support-config.mjs +302 -0
- package/support-email.mjs +458 -0
- package/support-fields.mjs +294 -0
- package/support-freshdesk.mjs +176 -0
- package/support-inbox.mjs +313 -0
- package/support-label-rules.mjs +136 -0
- package/support-labels.mjs +244 -0
- package/support-outcomes.mjs +276 -0
- package/support-outside-bot.mjs +145 -0
- package/support-setup.mjs +660 -0
- package/support-signatures.mjs +156 -0
- package/support-sources.mjs +233 -0
- package/support-walter.mjs +310 -0
package/lib.mjs
CHANGED
|
@@ -29,6 +29,89 @@ import {
|
|
|
29
29
|
unpublishSite,
|
|
30
30
|
renderUnpublish,
|
|
31
31
|
} from './site-setup.mjs';
|
|
32
|
+
import {
|
|
33
|
+
detectFramework,
|
|
34
|
+
FRAMEWORKS,
|
|
35
|
+
renderInstall,
|
|
36
|
+
renderSupportHome,
|
|
37
|
+
renderSupportSetup,
|
|
38
|
+
renderSupportNotifications,
|
|
39
|
+
renderSupportStatus,
|
|
40
|
+
renderSupportTest,
|
|
41
|
+
NOTIFY_CHANNELS,
|
|
42
|
+
NOTIFY_EVENTS,
|
|
43
|
+
renderSupportThread,
|
|
44
|
+
reportStep,
|
|
45
|
+
sendTest,
|
|
46
|
+
supportNotifications,
|
|
47
|
+
HOME_FIELDS,
|
|
48
|
+
supportHome,
|
|
49
|
+
supportScopeHelp,
|
|
50
|
+
supportSetup,
|
|
51
|
+
supportStatus,
|
|
52
|
+
supportThread,
|
|
53
|
+
writeIdentitySecret,
|
|
54
|
+
} from './support-setup.mjs';
|
|
55
|
+
import {
|
|
56
|
+
MAX_PDF_JSON_BYTES,
|
|
57
|
+
addPdf,
|
|
58
|
+
addSource,
|
|
59
|
+
listSources,
|
|
60
|
+
removeSource,
|
|
61
|
+
renderSourceAdded,
|
|
62
|
+
renderSourceLine,
|
|
63
|
+
renderSourceRemoved,
|
|
64
|
+
renderSources,
|
|
65
|
+
syncSource,
|
|
66
|
+
updateSource,
|
|
67
|
+
} from './support-sources.mjs';
|
|
68
|
+
import { AGENT_TEST_TOOLS, runAgentTestTool } from './support-agent-tests.mjs';
|
|
69
|
+
import { CONFIG_TOOLS, configTool } from './support-config.mjs';
|
|
70
|
+
import { WALTER_TOOLS, walterTool } from './support-walter.mjs';
|
|
71
|
+
import { LABEL_TOOLS, runLabelTool } from './support-labels.mjs';
|
|
72
|
+
import { FEEDBACK_BOARD_TOOLS, runFeedbackBoardTool } from './feedback-board.mjs';
|
|
73
|
+
import { CONTACTS_TOOLS, contactsScopeHelp, runContactsTool } from './contacts.mjs';
|
|
74
|
+
import { DOMAINS_TOOLS, runDomainsTool } from './domains.mjs';
|
|
75
|
+
import { JOURNEYS_TOOLS, runJourneysTool } from './journeys.mjs';
|
|
76
|
+
import { EMAIL_STUDIO_TOOLS, runEmailStudioTool } from './email-studio.mjs';
|
|
77
|
+
import { FIELD_TOOLS, runFieldTool } from './support-fields.mjs';
|
|
78
|
+
import { SIGNATURE_TOOLS, runSignatureTool } from './support-signatures.mjs';
|
|
79
|
+
import { EMAIL_TOOLS, runEmailTool } from './support-email.mjs';
|
|
80
|
+
import { INBOX_TOOLS, inboxToolLines } from './support-inbox.mjs';
|
|
81
|
+
import {
|
|
82
|
+
listLabelRules,
|
|
83
|
+
removeLabelRule,
|
|
84
|
+
renderLabelRuleRemoved,
|
|
85
|
+
renderLabelRules,
|
|
86
|
+
renderLabelRuleSet,
|
|
87
|
+
setLabelRule,
|
|
88
|
+
} from './support-label-rules.mjs';
|
|
89
|
+
import {
|
|
90
|
+
checkOutsideBot,
|
|
91
|
+
getOutsideBot,
|
|
92
|
+
renderOutsideBot,
|
|
93
|
+
renderOutsideBotCheck,
|
|
94
|
+
setOutsideBot,
|
|
95
|
+
} from './support-outside-bot.mjs';
|
|
96
|
+
import {
|
|
97
|
+
clearOutcome,
|
|
98
|
+
getOutcomeUsage,
|
|
99
|
+
listOutcomes,
|
|
100
|
+
markOutcome,
|
|
101
|
+
outcomesCsv,
|
|
102
|
+
renderOutcomeMark,
|
|
103
|
+
renderOutcomes,
|
|
104
|
+
renderOutcomeUsage,
|
|
105
|
+
} from './support-outcomes.mjs';
|
|
106
|
+
import {
|
|
107
|
+
checkFreshdesk,
|
|
108
|
+
getFreshdesk,
|
|
109
|
+
removeFreshdesk,
|
|
110
|
+
renderFreshdesk,
|
|
111
|
+
renderFreshdeskCheck,
|
|
112
|
+
renderFreshdeskRemoved,
|
|
113
|
+
setFreshdesk,
|
|
114
|
+
} from './support-freshdesk.mjs';
|
|
32
115
|
import {
|
|
33
116
|
addApiReference,
|
|
34
117
|
addRedirects,
|
|
@@ -295,6 +378,60 @@ export const SITE_TOOLS = new Set([
|
|
|
295
378
|
'workover_unpublish_site',
|
|
296
379
|
]);
|
|
297
380
|
|
|
381
|
+
/** The Support setup tools (support-setup.mjs), all behind the `support` scope (WO-1752, S43; thread S35b). */
|
|
382
|
+
export const SUPPORT_TOOLS = new Set([
|
|
383
|
+
'workover_support_status',
|
|
384
|
+
'workover_support_setup',
|
|
385
|
+
'workover_support_report_step',
|
|
386
|
+
'workover_support_install',
|
|
387
|
+
'workover_support_identity_secret',
|
|
388
|
+
'workover_support_test',
|
|
389
|
+
'workover_support_notifications',
|
|
390
|
+
'workover_support_home',
|
|
391
|
+
'workover_support_thread',
|
|
392
|
+
]);
|
|
393
|
+
|
|
394
|
+
/** Walter AI's source tools (support-sources.mjs), behind the same `support` scope (WO-1752, S06b). */
|
|
395
|
+
export const SOURCE_TOOLS = new Set([
|
|
396
|
+
'workover_support_sources',
|
|
397
|
+
'workover_support_add_source',
|
|
398
|
+
'workover_support_update_source',
|
|
399
|
+
'workover_support_sync_source',
|
|
400
|
+
'workover_support_remove_source',
|
|
401
|
+
]);
|
|
402
|
+
|
|
403
|
+
/** Walter AI's batch test and release tools, behind the same `support` scope (WO-1752, S06c). */
|
|
404
|
+
export { AGENT_TEST_TOOLS };
|
|
405
|
+
|
|
406
|
+
/** When the AI adds each label (support-label-rules.mjs), behind the same `support` scope (WO-1752, S09). */
|
|
407
|
+
export const LABEL_RULE_TOOLS = new Set([
|
|
408
|
+
'workover_support_label_rules',
|
|
409
|
+
'workover_support_set_label_rule',
|
|
410
|
+
'workover_support_remove_label_rule',
|
|
411
|
+
]);
|
|
412
|
+
|
|
413
|
+
/** Support's outside bot (support-outside-bot.mjs), behind the same `support` scope (WO-1752, S14). */
|
|
414
|
+
export const OUTSIDE_BOT_TOOLS = new Set([
|
|
415
|
+
'workover_support_outside_bot',
|
|
416
|
+
'workover_support_set_outside_bot',
|
|
417
|
+
'workover_support_check_outside_bot',
|
|
418
|
+
]);
|
|
419
|
+
|
|
420
|
+
/** Walter AI's outcome ledger (support-outcomes.mjs), behind the same `support` scope (WO-1752, S65). */
|
|
421
|
+
export const OUTCOME_TOOLS = new Set([
|
|
422
|
+
'workover_support_outcomes',
|
|
423
|
+
'workover_support_outcome_mark',
|
|
424
|
+
'workover_support_outcome_usage',
|
|
425
|
+
]);
|
|
426
|
+
|
|
427
|
+
/** Freshdesk escalation setup (support-freshdesk.mjs), behind the same `support` scope (WO-1752, S18). */
|
|
428
|
+
export const FRESHDESK_TOOLS = new Set([
|
|
429
|
+
'workover_support_freshdesk',
|
|
430
|
+
'workover_support_set_freshdesk',
|
|
431
|
+
'workover_support_check_freshdesk',
|
|
432
|
+
'workover_support_remove_freshdesk',
|
|
433
|
+
]);
|
|
434
|
+
|
|
298
435
|
/**
|
|
299
436
|
* A sentence when a document link is for a different Workover than the one signed in to, else null.
|
|
300
437
|
*
|
|
@@ -451,6 +588,61 @@ export const imagesInHtml = (html) => {
|
|
|
451
588
|
return out;
|
|
452
589
|
};
|
|
453
590
|
|
|
591
|
+
/** workover_list_media's filters, as the flags GET /project/:id/media takes. */
|
|
592
|
+
const MEDIA_FLAGS = {
|
|
593
|
+
attention: 'attention',
|
|
594
|
+
missing_alt: 'missingAlt',
|
|
595
|
+
oversized: 'oversized',
|
|
596
|
+
broken: 'broken',
|
|
597
|
+
stale: 'stale',
|
|
598
|
+
};
|
|
599
|
+
|
|
600
|
+
/** The query string for GET /project/:id/media, from workover_list_media's arguments. */
|
|
601
|
+
export function mediaListQuery(args = {}) {
|
|
602
|
+
const q = new URLSearchParams();
|
|
603
|
+
const filter = String(args.filter || 'all');
|
|
604
|
+
if (filter === 'in_use' || filter === 'unused' || filter === 'deleted') q.set('tab', filter);
|
|
605
|
+
if (MEDIA_FLAGS[filter]) q.set(MEDIA_FLAGS[filter], 'true');
|
|
606
|
+
if (args.source === 'workover' || args.source === 'wordpress') q.set('source', args.source);
|
|
607
|
+
const search = typeof args.search === 'string' ? args.search.trim() : '';
|
|
608
|
+
if (search) q.set('search', search);
|
|
609
|
+
const cursor = Number(args.cursor);
|
|
610
|
+
if (Number.isInteger(cursor) && cursor > 0) q.set('cursor', String(cursor));
|
|
611
|
+
q.set('limit', '50');
|
|
612
|
+
return q.toString();
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
/** workover_list_media's answer: the counts, one block per asset, then the next page. */
|
|
616
|
+
export function formatMediaList(projectId, res) {
|
|
617
|
+
const items = Array.isArray(res?.items) ? res.items : [];
|
|
618
|
+
const c = res?.counts || {};
|
|
619
|
+
const head =
|
|
620
|
+
`Media library of project #${projectId}: ${c.all ?? items.length} images, ` +
|
|
621
|
+
`${c.inUse ?? 0} in use, ${c.unused ?? 0} not found in imported content, ` +
|
|
622
|
+
`${c.attention ?? 0} need attention.`;
|
|
623
|
+
if (!items.length) return `${head}\n\nNothing matches.`;
|
|
624
|
+
const lines = items.map((a) => {
|
|
625
|
+
const problems = [];
|
|
626
|
+
// Alt text is an image's; a PDF in the WordPress library has none to miss.
|
|
627
|
+
if (!a.alt && (a.mime == null || String(a.mime).startsWith('image/')))
|
|
628
|
+
problems.push('no alt text');
|
|
629
|
+
if (a.oversized) problems.push(`oversized (${Math.round((a.bytes || 0) / 1024)} KB)`);
|
|
630
|
+
if (a.brokenAt) problems.push('broken');
|
|
631
|
+
if (a.staleAt) problems.push(`outdated: ${a.staleReason || 'the UI changed'}`);
|
|
632
|
+
if (a.deletedAt) problems.push('deleted');
|
|
633
|
+
const from = a.wpAttachmentId ? `WordPress #${a.wpAttachmentId}` : 'Workover';
|
|
634
|
+
const used = a.useCount
|
|
635
|
+
? `used in ${a.useCount} doc${a.useCount === 1 ? '' : 's'}`
|
|
636
|
+
: 'not found in imported content';
|
|
637
|
+
return (
|
|
638
|
+
`#${a.id} ${a.filename} (${from}, ${used})\n alt: ${a.alt || '(none)'}` +
|
|
639
|
+
(problems.length ? `\n problems: ${problems.join('; ')}` : '')
|
|
640
|
+
);
|
|
641
|
+
});
|
|
642
|
+
const more = res?.nextCursor ? `\n\nMore: pass cursor ${res.nextCursor} for the next page.` : '';
|
|
643
|
+
return `${head}\n\n${lines.join('\n')}${more}`;
|
|
644
|
+
}
|
|
645
|
+
|
|
454
646
|
/** The error shown when a tool is handed something that isn't a numeric id. */
|
|
455
647
|
export const badIdErr = (kind, got) =>
|
|
456
648
|
err(
|
|
@@ -524,14 +716,50 @@ export const vetImagePath = (p, { realpath = realpathSync, stat = statSync } = {
|
|
|
524
716
|
return { path: real, ext };
|
|
525
717
|
};
|
|
526
718
|
|
|
719
|
+
/**
|
|
720
|
+
* Decide whether `workover_support_add_source` may read a local path as a PDF for Walter AI. The
|
|
721
|
+
* same reasoning as `vetImagePath`, with more at stake: the PDF becomes something the agent answers
|
|
722
|
+
* ANONYMOUS visitors from, so a model talked into "adding" a statement kept in a dot directory would
|
|
723
|
+
* publish it, in effect. So: symlinks resolved first, nothing hidden, a `.pdf` name, a plain file,
|
|
724
|
+
* and the size checked against what the JSON route takes before a byte is read. Returns
|
|
725
|
+
* `{ path }` (the real path) or `{ error }`.
|
|
726
|
+
*/
|
|
727
|
+
export const vetPdfPath = (p, { realpath = realpathSync, stat = statSync } = {}) => {
|
|
728
|
+
let real;
|
|
729
|
+
try {
|
|
730
|
+
real = realpath(p);
|
|
731
|
+
} catch {
|
|
732
|
+
return { error: `Couldn't read a PDF at ${p}. Nothing was added.` };
|
|
733
|
+
}
|
|
734
|
+
if (real.split(/[\\/]/).some((part) => part.startsWith('.') && part !== '.' && part !== '..'))
|
|
735
|
+
return {
|
|
736
|
+
error: `Refusing to upload ${p}: it is a hidden file or inside a hidden directory. Save the PDF somewhere ordinary and pass that path. Nothing was added.`,
|
|
737
|
+
};
|
|
738
|
+
if (!/\.pdf$/i.test(basename(real)))
|
|
739
|
+
return { error: `Refusing to upload ${p}: only a .pdf file can be a source. Nothing was added.` };
|
|
740
|
+
let info;
|
|
741
|
+
try {
|
|
742
|
+
info = stat(real);
|
|
743
|
+
} catch {
|
|
744
|
+
return { error: `Couldn't read a PDF at ${p}. Nothing was added.` };
|
|
745
|
+
}
|
|
746
|
+
if (!info.isFile()) return { error: `${p} is not a file. Nothing was added.` };
|
|
747
|
+
if (info.size > MAX_PDF_JSON_BYTES)
|
|
748
|
+
return {
|
|
749
|
+
error: `${p} is ${Math.round(info.size / 1e5) / 10} MB. Files up to 3.5 MB upload from here; larger ones (up to 20 MB) upload in the app, under Support, AI answers, Sources. Nothing was added.`,
|
|
750
|
+
};
|
|
751
|
+
return { path: real };
|
|
752
|
+
};
|
|
753
|
+
|
|
527
754
|
/**
|
|
528
755
|
* Build the authenticated JSON API caller. `fetchImpl` is injectable for tests. The status→message
|
|
529
756
|
* mapping is the contract the tools rely on (401/403 are friendly, other non-2xx is generic).
|
|
530
757
|
*/
|
|
531
758
|
export function makeApi({ auth, fetchImpl = fetch }) {
|
|
532
759
|
async function api(path, init) {
|
|
760
|
+
const { raw, ...rest } = init ?? {};
|
|
533
761
|
const res = await fetchImpl(`${auth.api}${path}`, {
|
|
534
|
-
...
|
|
762
|
+
...rest,
|
|
535
763
|
headers: { authorization: `Bearer ${auth.token}`, ...(init?.headers || {}) },
|
|
536
764
|
});
|
|
537
765
|
if (res.status === 401)
|
|
@@ -558,7 +786,8 @@ export function makeApi({ auth, fetchImpl = fetch }) {
|
|
|
558
786
|
: '';
|
|
559
787
|
throw new Error(`Workover API error (${res.status})${detail ? `: ${detail}` : '.'}`);
|
|
560
788
|
}
|
|
561
|
-
|
|
789
|
+
// A CSV export comes back as text (`raw: true`; not passed on to fetch).
|
|
790
|
+
return raw ? res.text() : res.json();
|
|
562
791
|
}
|
|
563
792
|
const apiPost = (path, body) =>
|
|
564
793
|
api(path, {
|
|
@@ -574,11 +803,12 @@ export function makeApi({ auth, fetchImpl = fetch }) {
|
|
|
574
803
|
* short-circuits before any request; unknown tools and thrown errors become `err(...)`. `readFile`
|
|
575
804
|
* and `fetchImpl` are injected so the upload path is testable without touching the disk/network.
|
|
576
805
|
*/
|
|
577
|
-
export function makeDispatch({ auth, api, apiPost, fetchImpl = fetch, readFile, fsOps, siteWait, clientInfo }) {
|
|
806
|
+
export function makeDispatch({ auth, api, apiPost, fetchImpl = fetch, readFile, fsOps, siteWait, supportFiles, supportWait, clientInfo }) {
|
|
578
807
|
// The site tools' caller (site-setup.mjs): the same authenticated `api`, with a body as JSON.
|
|
579
|
-
const call = (path, { method, body } = {}) =>
|
|
808
|
+
const call = (path, { method, body, raw } = {}) =>
|
|
580
809
|
api(path, {
|
|
581
810
|
method: method || 'GET',
|
|
811
|
+
...(raw ? { raw: true } : {}),
|
|
582
812
|
...(body ? { headers: { 'content-type': 'application/json' }, body: JSON.stringify(body) } : {}),
|
|
583
813
|
});
|
|
584
814
|
// An MCP call should not hold the client for minutes: an import or publish still running after
|
|
@@ -749,6 +979,304 @@ export function makeDispatch({ auth, api, apiPost, fetchImpl = fetch, readFile,
|
|
|
749
979
|
return err(`Unknown tool: ${name}`);
|
|
750
980
|
}
|
|
751
981
|
|
|
982
|
+
/**
|
|
983
|
+
* The Support setup tools. Every one needs a token from `workover login --support`. `supportFiles`
|
|
984
|
+
* is `{ exists, read, write }`: the app's files for finding its framework, and the env file the
|
|
985
|
+
* identity secret is written into (it never comes back to the model).
|
|
986
|
+
*/
|
|
987
|
+
async function supportTool(name, args) {
|
|
988
|
+
const workspace = args.workspace === undefined || args.workspace === null ? undefined : String(args.workspace);
|
|
989
|
+
try {
|
|
990
|
+
if (name === 'workover_support_status') {
|
|
991
|
+
const res = await supportStatus(call, { workspace });
|
|
992
|
+
return lines(renderSupportStatus(res, { web }));
|
|
993
|
+
}
|
|
994
|
+
if (name === 'workover_support_setup') {
|
|
995
|
+
const pick = {};
|
|
996
|
+
for (const k of ['name', 'color', 'greeting', 'origins', 'topics', 'projectIds', 'hours', 'agentEnabled', 'enabled'])
|
|
997
|
+
if (args[k] !== undefined) pick[k] = args[k];
|
|
998
|
+
const res = await supportSetup(call, { workspace, ...pick });
|
|
999
|
+
return lines(renderSupportSetup(res, { web }));
|
|
1000
|
+
}
|
|
1001
|
+
if (name === 'workover_support_report_step') {
|
|
1002
|
+
const res = await reportStep(call, {
|
|
1003
|
+
workspace,
|
|
1004
|
+
step: args.step,
|
|
1005
|
+
state: args.failed === true ? 'failed' : 'done',
|
|
1006
|
+
detail: typeof args.detail === 'string' ? args.detail : undefined,
|
|
1007
|
+
});
|
|
1008
|
+
return lines(renderSupportStatus(res, { web }));
|
|
1009
|
+
}
|
|
1010
|
+
if (name === 'workover_support_install') {
|
|
1011
|
+
const framework = typeof args.framework === 'string' ? args.framework.toLowerCase() : null;
|
|
1012
|
+
if (framework && !FRAMEWORKS.includes(framework))
|
|
1013
|
+
return err(`No snippet for "${framework}". One of: ${FRAMEWORKS.join(', ')}.`);
|
|
1014
|
+
const status = await supportStatus(call, { workspace });
|
|
1015
|
+
const detected =
|
|
1016
|
+
!framework && typeof args.dir === 'string' && supportFiles ? detectFramework(supportFiles, args.dir) : null;
|
|
1017
|
+
return lines(renderInstall({ status, detected, framework }));
|
|
1018
|
+
}
|
|
1019
|
+
if (name === 'workover_support_identity_secret') {
|
|
1020
|
+
if (!supportFiles) return err('This server cannot write files here. Use `workover support secret --env-file <file>` in a terminal.');
|
|
1021
|
+
// The server's working directory is not necessarily the app's, so a relative path could put
|
|
1022
|
+
// the secret in some other folder's env file.
|
|
1023
|
+
if (typeof args.envFile === 'string' && !/^(\/|[A-Za-z]:[\\/])/.test(args.envFile))
|
|
1024
|
+
return err(`Give envFile as an absolute path, such as /path/to/app/.env.local ("${args.envFile}" is relative). Nothing was created.`);
|
|
1025
|
+
const res = await writeIdentitySecret(call, supportFiles, {
|
|
1026
|
+
workspace,
|
|
1027
|
+
envFile: args.envFile,
|
|
1028
|
+
varName: typeof args.varName === 'string' ? args.varName : undefined,
|
|
1029
|
+
rotate: args.rotate === true,
|
|
1030
|
+
});
|
|
1031
|
+
return text(
|
|
1032
|
+
`${res.rotated ? 'Rotated' : 'Created'} the identity secret and wrote it to ${res.envFile} as ${res.varName}. It is not shown here. Keep that file out of version control and out of the browser bundle.`,
|
|
1033
|
+
);
|
|
1034
|
+
}
|
|
1035
|
+
if (name === 'workover_support_notifications') {
|
|
1036
|
+
// Only the known switches, and only booleans: anything else is named back, nothing sent.
|
|
1037
|
+
const set = {};
|
|
1038
|
+
for (const [k, v] of Object.entries(args || {})) {
|
|
1039
|
+
if (k === 'workspace') continue;
|
|
1040
|
+
if (![...NOTIFY_CHANNELS, ...NOTIFY_EVENTS].includes(k))
|
|
1041
|
+
return err(`"${k}" is not a Support notification switch. One of: ${[...NOTIFY_CHANNELS, ...NOTIFY_EVENTS].join(', ')}. Nothing was changed.`);
|
|
1042
|
+
if (typeof v !== 'boolean') return err(`${k} is true or false. Nothing was changed.`);
|
|
1043
|
+
set[k] = v;
|
|
1044
|
+
}
|
|
1045
|
+
const res = await supportNotifications(call, { set });
|
|
1046
|
+
return lines(renderSupportNotifications(res));
|
|
1047
|
+
}
|
|
1048
|
+
if (name === 'workover_support_home') {
|
|
1049
|
+
const pick = {};
|
|
1050
|
+
for (const k of HOME_FIELDS) if (args[k] !== undefined) pick[k] = args[k];
|
|
1051
|
+
const res = await supportHome(call, { workspace, ...pick });
|
|
1052
|
+
return lines(renderSupportHome(res));
|
|
1053
|
+
}
|
|
1054
|
+
if (name === 'workover_support_test') {
|
|
1055
|
+
const res = await sendTest(call, { workspace, ...(supportWait || {}) });
|
|
1056
|
+
const out = lines(renderSupportTest(res, { web }));
|
|
1057
|
+
return res.confirmed ? out : err(out.content[0].text);
|
|
1058
|
+
}
|
|
1059
|
+
if (name === 'workover_support_thread') {
|
|
1060
|
+
if (args.closedStaysClosed !== undefined && typeof args.closedStaysClosed !== 'boolean')
|
|
1061
|
+
return err('closedStaysClosed is true or false. Nothing was changed.');
|
|
1062
|
+
const res = await supportThread(call, { workspace, closedStaysClosed: args.closedStaysClosed });
|
|
1063
|
+
return lines(renderSupportThread(res));
|
|
1064
|
+
}
|
|
1065
|
+
} catch (e) {
|
|
1066
|
+
const help = supportScopeHelp(e?.message);
|
|
1067
|
+
return err(`${e?.message || 'Something went wrong.'}${help ? `\n\n${help}` : ''}`);
|
|
1068
|
+
}
|
|
1069
|
+
return err(`Unknown tool: ${name}`);
|
|
1070
|
+
}
|
|
1071
|
+
|
|
1072
|
+
/** Support's email follow-ups (support-email.mjs, real widths M3), behind the same `support` scope. */
|
|
1073
|
+
async function emailTool(name, args) {
|
|
1074
|
+
try {
|
|
1075
|
+
return lines(await runEmailTool(call, name, args ?? {}));
|
|
1076
|
+
} catch (e) {
|
|
1077
|
+
const help = supportScopeHelp(e?.message);
|
|
1078
|
+
return err(`${e?.message || 'Something went wrong.'}${help ? `\n\n${help}` : ''}`);
|
|
1079
|
+
}
|
|
1080
|
+
}
|
|
1081
|
+
|
|
1082
|
+
/** Support's email signatures (support-signatures.mjs, S10b), behind the same `support` scope. */
|
|
1083
|
+
async function signatureTool(name, args) {
|
|
1084
|
+
try {
|
|
1085
|
+
return lines(await runSignatureTool(call, name, args ?? {}));
|
|
1086
|
+
} catch (e) {
|
|
1087
|
+
const help = supportScopeHelp(e?.message);
|
|
1088
|
+
return err(`${e?.message || 'Something went wrong.'}${help ? `\n\n${help}` : ''}`);
|
|
1089
|
+
}
|
|
1090
|
+
}
|
|
1091
|
+
|
|
1092
|
+
/** Support's conversation fields (support-fields.mjs, S38), behind the same `support` scope. */
|
|
1093
|
+
async function fieldTool(name, args) {
|
|
1094
|
+
try {
|
|
1095
|
+
return lines(await runFieldTool(call, name, args ?? {}));
|
|
1096
|
+
} catch (e) {
|
|
1097
|
+
const help = supportScopeHelp(e?.message);
|
|
1098
|
+
return err(`${e?.message || 'Something went wrong.'}${help ? `\n\n${help}` : ''}`);
|
|
1099
|
+
}
|
|
1100
|
+
}
|
|
1101
|
+
|
|
1102
|
+
/** Support's labels (support-labels.mjs, S63), behind the same `support` scope. */
|
|
1103
|
+
async function labelTool(name, args) {
|
|
1104
|
+
try {
|
|
1105
|
+
return lines(await runLabelTool(call, name, args ?? {}));
|
|
1106
|
+
} catch (e) {
|
|
1107
|
+
const help = supportScopeHelp(e?.message);
|
|
1108
|
+
return err(`${e?.message || 'Something went wrong.'}${help ? `\n\n${help}` : ''}`);
|
|
1109
|
+
}
|
|
1110
|
+
}
|
|
1111
|
+
|
|
1112
|
+
/**
|
|
1113
|
+
* Walter AI's sources (support-sources.mjs). `readFile` reads the PDF a path names; only an
|
|
1114
|
+
* absolute path is taken, since the server's working directory is not the person's.
|
|
1115
|
+
*/
|
|
1116
|
+
async function sourceTool(name, args) {
|
|
1117
|
+
const workspace = args.workspace === undefined || args.workspace === null ? undefined : String(args.workspace);
|
|
1118
|
+
try {
|
|
1119
|
+
if (name === 'workover_support_sources') return lines(renderSources(await listSources(call, { workspace })));
|
|
1120
|
+
if (name === 'workover_support_add_source') {
|
|
1121
|
+
if (String(args.kind ?? '').toLowerCase() === 'pdf') {
|
|
1122
|
+
if (typeof args.file !== 'string' || !/^(\/|[A-Za-z]:[\\/])/.test(args.file))
|
|
1123
|
+
return err('Give file as the absolute path of the PDF, such as /path/to/refunds.pdf. Nothing was added.');
|
|
1124
|
+
if (!readFile) return err('This server cannot read files here. Use `workover support sources pdf <file>` in a terminal.');
|
|
1125
|
+
const vetted = vetPdfPath(args.file, fsOps);
|
|
1126
|
+
if (vetted.error) return err(vetted.error);
|
|
1127
|
+
let bytes;
|
|
1128
|
+
try {
|
|
1129
|
+
bytes = readFile(vetted.path);
|
|
1130
|
+
} catch {
|
|
1131
|
+
return err(`Could not read ${args.file}. Nothing was added.`);
|
|
1132
|
+
}
|
|
1133
|
+
if (!bytes?.length || Buffer.from(bytes.subarray(0, 5)).toString('latin1') !== '%PDF-')
|
|
1134
|
+
return err(`${args.file} is not a PDF. Nothing was added.`);
|
|
1135
|
+
const fileName = basename(vetted.path);
|
|
1136
|
+
return lines(renderSourceAdded(await addPdf(call, { workspace, name: fileName, bytes })));
|
|
1137
|
+
}
|
|
1138
|
+
const res = await addSource(call, {
|
|
1139
|
+
workspace,
|
|
1140
|
+
kind: args.kind,
|
|
1141
|
+
url: args.url,
|
|
1142
|
+
projectId: args.projectId,
|
|
1143
|
+
resyncHours: args.resyncHours,
|
|
1144
|
+
});
|
|
1145
|
+
return lines(renderSourceAdded(res));
|
|
1146
|
+
}
|
|
1147
|
+
if (name === 'workover_support_update_source') {
|
|
1148
|
+
const res = await updateSource(call, {
|
|
1149
|
+
workspace,
|
|
1150
|
+
sourceId: args.sourceId,
|
|
1151
|
+
enabled: typeof args.enabled === 'boolean' ? args.enabled : undefined,
|
|
1152
|
+
resyncHours: args.resyncHours,
|
|
1153
|
+
});
|
|
1154
|
+
return lines(['Saved.', ...renderSourceLine(res.source)]);
|
|
1155
|
+
}
|
|
1156
|
+
if (name === 'workover_support_sync_source') {
|
|
1157
|
+
const res = await syncSource(call, { workspace, sourceId: args.sourceId });
|
|
1158
|
+
return lines(['Reading it again now. Call workover_support_sources for ready or failed.', ...renderSourceLine(res.source)]);
|
|
1159
|
+
}
|
|
1160
|
+
if (name === 'workover_support_remove_source')
|
|
1161
|
+
return lines(renderSourceRemoved(await removeSource(call, { workspace, sourceId: args.sourceId })));
|
|
1162
|
+
} catch (e) {
|
|
1163
|
+
const help = supportScopeHelp(e?.message);
|
|
1164
|
+
return err(`${e?.message || 'Something went wrong.'}${help ? `\n\n${help}` : ''}`);
|
|
1165
|
+
}
|
|
1166
|
+
return err(`Unknown tool: ${name}`);
|
|
1167
|
+
}
|
|
1168
|
+
|
|
1169
|
+
/** Walter AI's batch test and releases (support-agent-tests.mjs, S06c). */
|
|
1170
|
+
async function agentTestTool(name, args) {
|
|
1171
|
+
try {
|
|
1172
|
+
return lines(await runAgentTestTool(call, name, args ?? {}, supportWait || {}));
|
|
1173
|
+
} catch (e) {
|
|
1174
|
+
const help = supportScopeHelp(e?.message);
|
|
1175
|
+
return err(`${e?.message || 'Something went wrong.'}${help ? `\n\n${help}` : ''}`);
|
|
1176
|
+
}
|
|
1177
|
+
}
|
|
1178
|
+
|
|
1179
|
+
/** When the AI adds each label (support-label-rules.mjs). */
|
|
1180
|
+
async function labelRuleTool(name, args) {
|
|
1181
|
+
const workspace = args.workspace === undefined || args.workspace === null ? undefined : String(args.workspace);
|
|
1182
|
+
try {
|
|
1183
|
+
if (name === 'workover_support_label_rules') return lines(renderLabelRules(await listLabelRules(call, { workspace })));
|
|
1184
|
+
if (name === 'workover_support_set_label_rule')
|
|
1185
|
+
return lines(
|
|
1186
|
+
renderLabelRuleSet(
|
|
1187
|
+
await setLabelRule(call, {
|
|
1188
|
+
workspace,
|
|
1189
|
+
label: args.label,
|
|
1190
|
+
instruction: args.instruction,
|
|
1191
|
+
enabled: typeof args.enabled === 'boolean' ? args.enabled : undefined,
|
|
1192
|
+
}),
|
|
1193
|
+
),
|
|
1194
|
+
);
|
|
1195
|
+
if (name === 'workover_support_remove_label_rule')
|
|
1196
|
+
return lines(renderLabelRuleRemoved(await removeLabelRule(call, { workspace, label: args.label })));
|
|
1197
|
+
} catch (e) {
|
|
1198
|
+
const help = supportScopeHelp(e?.message);
|
|
1199
|
+
return err(`${e?.message || 'Something went wrong.'}${help ? `\n\n${help}` : ''}`);
|
|
1200
|
+
}
|
|
1201
|
+
return err(`Unknown tool: ${name}`);
|
|
1202
|
+
}
|
|
1203
|
+
|
|
1204
|
+
/** Support's outside bot (support-outside-bot.mjs). */
|
|
1205
|
+
async function outsideBotTool(name, args) {
|
|
1206
|
+
const workspace = args.workspace === undefined || args.workspace === null ? undefined : String(args.workspace);
|
|
1207
|
+
try {
|
|
1208
|
+
if (name === 'workover_support_outside_bot') return lines(renderOutsideBot(await getOutsideBot(call, { workspace })));
|
|
1209
|
+
if (name === 'workover_support_set_outside_bot') {
|
|
1210
|
+
const { workspace: _w, ...patch } = args;
|
|
1211
|
+
return lines(renderOutsideBot(await setOutsideBot(call, { workspace, ...patch })));
|
|
1212
|
+
}
|
|
1213
|
+
if (name === 'workover_support_check_outside_bot')
|
|
1214
|
+
return lines(renderOutsideBotCheck(await checkOutsideBot(call, { workspace })));
|
|
1215
|
+
} catch (e) {
|
|
1216
|
+
const help = supportScopeHelp(e?.message);
|
|
1217
|
+
return err(`${e?.message || 'Something went wrong.'}${help ? `\n\n${help}` : ''}`);
|
|
1218
|
+
}
|
|
1219
|
+
return err(`Unknown tool: ${name}`);
|
|
1220
|
+
}
|
|
1221
|
+
|
|
1222
|
+
/** Walter AI's outcome ledger (support-outcomes.mjs). */
|
|
1223
|
+
async function outcomeTool(name, args) {
|
|
1224
|
+
const workspace = args.workspace === undefined || args.workspace === null ? undefined : String(args.workspace);
|
|
1225
|
+
try {
|
|
1226
|
+
if (name === 'workover_support_outcomes') {
|
|
1227
|
+
const filters = { workspace, outcome: args.outcome, from: args.from, to: args.to };
|
|
1228
|
+
if (args.csv === true) {
|
|
1229
|
+
const res = await listOutcomes(call, { ...filters, all: true });
|
|
1230
|
+
return text(outcomesCsv(res.rows).replace(/^\uFEFF/, '') + (res.truncated ? '\n(only the first 10,000 rows)' : ''));
|
|
1231
|
+
}
|
|
1232
|
+
return lines(renderOutcomes(await listOutcomes(call, { ...filters, cursor: args.cursor })));
|
|
1233
|
+
}
|
|
1234
|
+
if (name === 'workover_support_outcome_mark') {
|
|
1235
|
+
const res =
|
|
1236
|
+
args.clear === true
|
|
1237
|
+
? await clearOutcome(call, { workspace, conversation: args.conversation })
|
|
1238
|
+
: await markOutcome(call, { workspace, conversation: args.conversation, reason: args.reason });
|
|
1239
|
+
return lines(renderOutcomeMark(res));
|
|
1240
|
+
}
|
|
1241
|
+
if (name === 'workover_support_outcome_usage') return lines(renderOutcomeUsage(await getOutcomeUsage(call, { workspace })));
|
|
1242
|
+
} catch (e) {
|
|
1243
|
+
const help = supportScopeHelp(e?.message);
|
|
1244
|
+
return err(`${e?.message || 'Something went wrong.'}${help ? `\n\n${help}` : ''}`);
|
|
1245
|
+
}
|
|
1246
|
+
return err(`Unknown tool: ${name}`);
|
|
1247
|
+
}
|
|
1248
|
+
|
|
1249
|
+
/** Freshdesk escalation setup (support-freshdesk.mjs). */
|
|
1250
|
+
async function freshdeskTool(name, args) {
|
|
1251
|
+
const workspace = args.workspace === undefined || args.workspace === null ? undefined : String(args.workspace);
|
|
1252
|
+
try {
|
|
1253
|
+
if (name === 'workover_support_freshdesk') return lines(renderFreshdesk(await getFreshdesk(call, { workspace })));
|
|
1254
|
+
if (name === 'workover_support_set_freshdesk')
|
|
1255
|
+
return lines(
|
|
1256
|
+
renderFreshdesk(
|
|
1257
|
+
await setFreshdesk(call, {
|
|
1258
|
+
workspace,
|
|
1259
|
+
domain: args.domain,
|
|
1260
|
+
apiKey: args.apiKey,
|
|
1261
|
+
mode: args.mode,
|
|
1262
|
+
priority: args.priority,
|
|
1263
|
+
groupId: args.groupId,
|
|
1264
|
+
tags: args.tags,
|
|
1265
|
+
closeAfter: typeof args.closeAfter === 'boolean' ? args.closeAfter : undefined,
|
|
1266
|
+
}),
|
|
1267
|
+
),
|
|
1268
|
+
);
|
|
1269
|
+
if (name === 'workover_support_check_freshdesk')
|
|
1270
|
+
return lines(renderFreshdeskCheck(await checkFreshdesk(call, { workspace })));
|
|
1271
|
+
if (name === 'workover_support_remove_freshdesk')
|
|
1272
|
+
return lines(renderFreshdeskRemoved(await removeFreshdesk(call, { workspace })));
|
|
1273
|
+
} catch (e) {
|
|
1274
|
+
const help = supportScopeHelp(e?.message);
|
|
1275
|
+
return err(`${e?.message || 'Something went wrong.'}${help ? `\n\n${help}` : ''}`);
|
|
1276
|
+
}
|
|
1277
|
+
return err(`Unknown tool: ${name}`);
|
|
1278
|
+
}
|
|
1279
|
+
|
|
752
1280
|
return async function dispatch(name, args = {}) {
|
|
753
1281
|
if (!auth)
|
|
754
1282
|
return err(
|
|
@@ -1081,6 +1609,30 @@ export function makeDispatch({ auth, api, apiPost, fetchImpl = fetch, readFile,
|
|
|
1081
1609
|
`Updated: file name "${res?.filename}", alt "${res?.alt || ''}".${inDoc} The file name is what WordPress gets on the next publish.`,
|
|
1082
1610
|
);
|
|
1083
1611
|
}
|
|
1612
|
+
if (name === 'workover_list_media') {
|
|
1613
|
+
const projectId = rowId(args.projectId);
|
|
1614
|
+
if (projectId === null) return badIdErr('project', args.projectId);
|
|
1615
|
+
const res = await api(`/project/${projectId}/media?${mediaListQuery(args)}`);
|
|
1616
|
+
return text(formatMediaList(projectId, res));
|
|
1617
|
+
}
|
|
1618
|
+
if (name === 'workover_replace_media') {
|
|
1619
|
+
const projectId = rowId(args.projectId);
|
|
1620
|
+
if (projectId === null) return badIdErr('project', args.projectId);
|
|
1621
|
+
const assetId = rowId(args.assetId);
|
|
1622
|
+
if (assetId === null) return badIdErr('asset', args.assetId);
|
|
1623
|
+
const replacementAssetId = rowId(args.replacementAssetId);
|
|
1624
|
+
if (replacementAssetId === null) return badIdErr('asset', args.replacementAssetId);
|
|
1625
|
+
if (assetId === replacementAssetId)
|
|
1626
|
+
return err('Choose a different image to replace it with.');
|
|
1627
|
+
const res = await api(`/project/${projectId}/media/${assetId}/replace`, {
|
|
1628
|
+
method: 'POST',
|
|
1629
|
+
headers: { 'content-type': 'application/json' },
|
|
1630
|
+
body: JSON.stringify({ replacementAssetId }),
|
|
1631
|
+
});
|
|
1632
|
+
return text(
|
|
1633
|
+
`Raised a fix to replace image #${assetId} with #${replacementAssetId} in every document that uses it${res?.suggestionId ? ` (fix #${res.suggestionId})` : ''}. Nothing has changed yet: a person reviews it in the project's Health page (Findings), and accepting it rewrites the documents. The old image stays in the library.`,
|
|
1634
|
+
);
|
|
1635
|
+
}
|
|
1084
1636
|
if (name === 'workover_edit_doc') {
|
|
1085
1637
|
const md = String(args.markdown || '').trim();
|
|
1086
1638
|
// A rename rides on the direct-edit tool: `title` alone renames without touching the body.
|
|
@@ -1206,6 +1758,88 @@ export function makeDispatch({ auth, api, apiPost, fetchImpl = fetch, readFile,
|
|
|
1206
1758
|
}
|
|
1207
1759
|
}
|
|
1208
1760
|
if (SITE_TOOLS.has(name)) return await siteTool(name, args);
|
|
1761
|
+
if (SUPPORT_TOOLS.has(name)) return await supportTool(name, args);
|
|
1762
|
+
if (SOURCE_TOOLS.has(name)) return await sourceTool(name, args);
|
|
1763
|
+
if (AGENT_TEST_TOOLS.has(name)) return await agentTestTool(name, args);
|
|
1764
|
+
// The Messenger's settings through the editor's draft (support-config.mjs, WO-1752, S46).
|
|
1765
|
+
if (CONFIG_TOOLS.has(name)) {
|
|
1766
|
+
try {
|
|
1767
|
+
return lines(await configTool(call, name, args));
|
|
1768
|
+
} catch (e) {
|
|
1769
|
+
const help = supportScopeHelp(e?.message);
|
|
1770
|
+
return err(`${e?.message || 'Something went wrong.'}${help ? `\n\n${help}` : ''}`);
|
|
1771
|
+
}
|
|
1772
|
+
}
|
|
1773
|
+
// Walter AI's Basics, draft, preview and Deploy checklist (support-walter.mjs, WO-1752, S57).
|
|
1774
|
+
if (WALTER_TOOLS.has(name)) {
|
|
1775
|
+
try {
|
|
1776
|
+
return lines(await walterTool(call, name, args));
|
|
1777
|
+
} catch (e) {
|
|
1778
|
+
const help = supportScopeHelp(e?.message);
|
|
1779
|
+
return err(`${e?.message || 'Something went wrong.'}${help ? `\n\n${help}` : ''}`);
|
|
1780
|
+
}
|
|
1781
|
+
}
|
|
1782
|
+
// Reply targets, auto-assignment and availability (support-inbox.mjs, WO-1752, S08).
|
|
1783
|
+
if (INBOX_TOOLS.has(name)) {
|
|
1784
|
+
try {
|
|
1785
|
+
return lines(await inboxToolLines(call, name, args));
|
|
1786
|
+
} catch (e) {
|
|
1787
|
+
const help = supportScopeHelp(e?.message);
|
|
1788
|
+
return err(`${e?.message || 'Something went wrong.'}${help ? `\n\n${help}` : ''}`);
|
|
1789
|
+
}
|
|
1790
|
+
}
|
|
1791
|
+
if (LABEL_TOOLS.has(name)) return await labelTool(name, args);
|
|
1792
|
+
// Feedback's posts (feedback-board.mjs, WO-1752 round 3): any `workover login` token.
|
|
1793
|
+
if (FEEDBACK_BOARD_TOOLS.has(name)) {
|
|
1794
|
+
try {
|
|
1795
|
+
return lines(await runFeedbackBoardTool(call, name, args ?? {}));
|
|
1796
|
+
} catch (e) {
|
|
1797
|
+
return err(e?.message || 'Something went wrong.');
|
|
1798
|
+
}
|
|
1799
|
+
}
|
|
1800
|
+
// Contacts (contacts.mjs, Contacts CRM step 1): the `contacts` token scope.
|
|
1801
|
+
if (CONTACTS_TOOLS.has(name)) {
|
|
1802
|
+
try {
|
|
1803
|
+
return lines(await runContactsTool(call, name, args ?? {}));
|
|
1804
|
+
} catch (e) {
|
|
1805
|
+
const help = contactsScopeHelp(e?.message);
|
|
1806
|
+
return err(`${e?.message || 'Something went wrong.'}${help ? `\n\n${help}` : ''}`);
|
|
1807
|
+
}
|
|
1808
|
+
}
|
|
1809
|
+
// Sending domains (domains.mjs, WO-1752): the `contacts` token scope too.
|
|
1810
|
+
if (DOMAINS_TOOLS.has(name)) {
|
|
1811
|
+
try {
|
|
1812
|
+
return lines(await runDomainsTool(call, name, args ?? {}));
|
|
1813
|
+
} catch (e) {
|
|
1814
|
+
const help = contactsScopeHelp(e?.message);
|
|
1815
|
+
return err(`${e?.message || 'Something went wrong.'}${help ? `\n\n${help}` : ''}`);
|
|
1816
|
+
}
|
|
1817
|
+
}
|
|
1818
|
+
// Emails designed in blocks (email-studio.mjs, WO-1752): the `contacts` token scope too.
|
|
1819
|
+
if (EMAIL_STUDIO_TOOLS.has(name)) {
|
|
1820
|
+
try {
|
|
1821
|
+
return lines(await runEmailStudioTool(call, name, args ?? {}));
|
|
1822
|
+
} catch (e) {
|
|
1823
|
+
const help = contactsScopeHelp(e?.message);
|
|
1824
|
+
return err(`${e?.message || 'Something went wrong.'}${help ? `\n\n${help}` : ''}`);
|
|
1825
|
+
}
|
|
1826
|
+
}
|
|
1827
|
+
// Contacts journeys (journeys.mjs, WO-1752): the `contacts` token scope too.
|
|
1828
|
+
if (JOURNEYS_TOOLS.has(name)) {
|
|
1829
|
+
try {
|
|
1830
|
+
return lines(await runJourneysTool(call, name, args ?? {}));
|
|
1831
|
+
} catch (e) {
|
|
1832
|
+
const help = contactsScopeHelp(e?.message);
|
|
1833
|
+
return err(`${e?.message || 'Something went wrong.'}${help ? `\n\n${help}` : ''}`);
|
|
1834
|
+
}
|
|
1835
|
+
}
|
|
1836
|
+
if (FIELD_TOOLS.has(name)) return await fieldTool(name, args);
|
|
1837
|
+
if (LABEL_RULE_TOOLS.has(name)) return await labelRuleTool(name, args);
|
|
1838
|
+
if (SIGNATURE_TOOLS.has(name)) return await signatureTool(name, args);
|
|
1839
|
+
if (EMAIL_TOOLS.has(name)) return await emailTool(name, args);
|
|
1840
|
+
if (OUTSIDE_BOT_TOOLS.has(name)) return await outsideBotTool(name, args);
|
|
1841
|
+
if (OUTCOME_TOOLS.has(name)) return await outcomeTool(name, args);
|
|
1842
|
+
if (FRESHDESK_TOOLS.has(name)) return await freshdeskTool(name, args);
|
|
1209
1843
|
return err(`Unknown tool: ${name}`);
|
|
1210
1844
|
} catch (e) {
|
|
1211
1845
|
return err(e?.message || 'Something went wrong.');
|