@clipform/mcp-server 5.10.1 → 5.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api-client.js +1 -1
- package/dist/{chunk-LCTBXXYI.js → chunk-25QWATF4.js} +275 -24
- package/dist/chunk-25QWATF4.js.map +1 -0
- package/dist/{chunk-4RHYPCK5.js → chunk-CKZC6CD4.js} +2 -2
- package/dist/{chunk-IMRQG5GI.js → chunk-CLU27DSP.js} +3 -3
- package/dist/{chunk-QHIVMOLB.js → chunk-SXQZLNRW.js} +3 -3
- package/dist/{chunk-Z2DXO3RN.js → chunk-TTFSP6U6.js} +139 -1
- package/dist/chunk-TTFSP6U6.js.map +1 -0
- package/dist/index.js +5 -5
- package/dist/prompts.js +3 -3
- package/dist/resources.js +3 -3
- package/dist/server.d.ts +8 -0
- package/dist/server.js +5 -5
- package/package.json +3 -3
- package/server.json +2 -2
- package/dist/chunk-LCTBXXYI.js.map +0 -1
- package/dist/chunk-Z2DXO3RN.js.map +0 -1
- /package/dist/{chunk-4RHYPCK5.js.map → chunk-CKZC6CD4.js.map} +0 -0
- /package/dist/{chunk-IMRQG5GI.js.map → chunk-CLU27DSP.js.map} +0 -0
- /package/dist/{chunk-QHIVMOLB.js.map → chunk-SXQZLNRW.js.map} +0 -0
package/dist/api-client.js
CHANGED
|
@@ -31,7 +31,7 @@ import {
|
|
|
31
31
|
union,
|
|
32
32
|
unknown,
|
|
33
33
|
url
|
|
34
|
-
} from "./chunk-
|
|
34
|
+
} from "./chunk-CLU27DSP.js";
|
|
35
35
|
import {
|
|
36
36
|
GUIDE_TYPES,
|
|
37
37
|
QUIZ_VARIANTS,
|
|
@@ -40,7 +40,7 @@ import {
|
|
|
40
40
|
getGuideUri,
|
|
41
41
|
guideFallbackText,
|
|
42
42
|
registerResources
|
|
43
|
-
} from "./chunk-
|
|
43
|
+
} from "./chunk-SXQZLNRW.js";
|
|
44
44
|
import {
|
|
45
45
|
ANON_PREVIEW_LINK_LABEL,
|
|
46
46
|
ANON_PREVIEW_NOTICE,
|
|
@@ -54,7 +54,7 @@ import {
|
|
|
54
54
|
isPreviewViewerUrl,
|
|
55
55
|
previewOnlyNotice,
|
|
56
56
|
withAdoptedNotice
|
|
57
|
-
} from "./chunk-
|
|
57
|
+
} from "./chunk-CKZC6CD4.js";
|
|
58
58
|
import {
|
|
59
59
|
ACTIVE_NODE_TYPES,
|
|
60
60
|
ANON_MCP_BLOCKED_NODE_TYPES,
|
|
@@ -66,6 +66,7 @@ import {
|
|
|
66
66
|
FEATURE_FLAGS,
|
|
67
67
|
FORM_TYPES_LIST,
|
|
68
68
|
FORM_TYPE_ALIASES,
|
|
69
|
+
LINK_VARIABLE_PRESETS,
|
|
69
70
|
LOGIC_TARGET_TYPES,
|
|
70
71
|
MAX_CLIP_SECONDS,
|
|
71
72
|
MAX_NARRATION_CHARS,
|
|
@@ -75,14 +76,21 @@ import {
|
|
|
75
76
|
NODE_TYPES,
|
|
76
77
|
NON_COUNTABLE_TYPES,
|
|
77
78
|
PII_NODE_TYPES,
|
|
79
|
+
VARIABLE_LABEL_MAX_LENGTH,
|
|
80
|
+
VARIABLE_MAX_CUSTOM_PER_FORM,
|
|
81
|
+
VARIABLE_MAX_LINK_PER_FORM,
|
|
82
|
+
VARIABLE_TYPES,
|
|
78
83
|
apiErrorResult,
|
|
79
84
|
authChallengeMeta,
|
|
80
85
|
bfsOrder,
|
|
86
|
+
buildVariableLink,
|
|
81
87
|
callApi,
|
|
88
|
+
coerceVariableValue,
|
|
82
89
|
consentItemNotes,
|
|
83
90
|
contactFieldNotes,
|
|
84
91
|
defaultTarget,
|
|
85
92
|
errorResult,
|
|
93
|
+
findScoreVariable,
|
|
86
94
|
gatedConfigKeys,
|
|
87
95
|
gatedEnumValues,
|
|
88
96
|
isAnonMcpLockedNode,
|
|
@@ -90,8 +98,12 @@ import {
|
|
|
90
98
|
isInactiveOptionEdge,
|
|
91
99
|
isNodeLevelAction,
|
|
92
100
|
isOptionEdge,
|
|
101
|
+
isPersonalLinkKey,
|
|
102
|
+
isRefusedStatus,
|
|
103
|
+
isReservedVariableKey,
|
|
93
104
|
isTerminalType,
|
|
94
105
|
lettersCapError,
|
|
106
|
+
linkVariablePreset,
|
|
95
107
|
normalizeConsentItems,
|
|
96
108
|
normalizeContactFields,
|
|
97
109
|
recallDisplayText,
|
|
@@ -99,8 +111,10 @@ import {
|
|
|
99
111
|
resolveFormType,
|
|
100
112
|
stripGatedConfigKeys,
|
|
101
113
|
structuredResult,
|
|
102
|
-
textResult
|
|
103
|
-
|
|
114
|
+
textResult,
|
|
115
|
+
validateVariableKey,
|
|
116
|
+
viewerUrl
|
|
117
|
+
} from "./chunk-TTFSP6U6.js";
|
|
104
118
|
import {
|
|
105
119
|
getMcpAuth,
|
|
106
120
|
runWithMcpAuth,
|
|
@@ -16969,7 +16983,7 @@ function registerImportFormTool(server) {
|
|
|
16969
16983
|
const data = importResult.data;
|
|
16970
16984
|
const summary = data.import_summary;
|
|
16971
16985
|
const formId = data.form_id;
|
|
16972
|
-
const
|
|
16986
|
+
const viewerUrl2 = data.url;
|
|
16973
16987
|
const isLive = data.is_live ?? null;
|
|
16974
16988
|
const previewUrl = data.preview_url ?? null;
|
|
16975
16989
|
const builderUrl = data.builder_url ?? null;
|
|
@@ -16997,11 +17011,11 @@ function registerImportFormTool(server) {
|
|
|
16997
17011
|
if (formId) {
|
|
16998
17012
|
lines.push(``, `Form ID: ${formId}`);
|
|
16999
17013
|
if (isLive === true) {
|
|
17000
|
-
lines.push(`Live at: ${
|
|
17014
|
+
lines.push(`Live at: ${viewerUrl2}`);
|
|
17001
17015
|
} else {
|
|
17002
17016
|
if (previewUrl) lines.push(`Preview the draft now: ${previewUrl}`);
|
|
17003
17017
|
lines.push(
|
|
17004
|
-
`FUTURE LIVE URL (not viewable yet - the form is a draft; opening this now shows a maintenance screen): ${
|
|
17018
|
+
`FUTURE LIVE URL (not viewable yet - the form is a draft; opening this now shows a maintenance screen): ${viewerUrl2}`,
|
|
17005
17019
|
`This form is a DRAFT. Review it, then publish with clipform_update_form (is_live: true) - only then does the URL above start serving the form to respondents.`
|
|
17006
17020
|
);
|
|
17007
17021
|
if (liveRefusedReason) lines.push(`Not live because: ${liveRefusedReason}`);
|
|
@@ -17013,7 +17027,7 @@ function registerImportFormTool(server) {
|
|
|
17013
17027
|
return structuredResult(lines.join("\n"), {
|
|
17014
17028
|
...workspaceName ? { workspace_name: workspaceName } : {},
|
|
17015
17029
|
form_id: formId,
|
|
17016
|
-
viewer_url:
|
|
17030
|
+
viewer_url: viewerUrl2,
|
|
17017
17031
|
is_live: isLive,
|
|
17018
17032
|
preview_url: previewUrl,
|
|
17019
17033
|
builder_url: builderUrl,
|
|
@@ -17306,7 +17320,19 @@ function formatFormState(data) {
|
|
|
17306
17320
|
|
|
17307
17321
|
// src/tools/get-form.ts
|
|
17308
17322
|
var TargetTypeSchema = external_exports.enum(LOGIC_TARGET_TYPES);
|
|
17309
|
-
function
|
|
17323
|
+
function linkVariablesText(data) {
|
|
17324
|
+
const rows = Array.isArray(data.variables) ? data.variables : [];
|
|
17325
|
+
const links = rows.filter((v) => v && v.kind === "custom" && v.url_settable === true && typeof v.key === "string" && !isReservedVariableKey(v.key));
|
|
17326
|
+
if (links.length === 0) return "";
|
|
17327
|
+
const lines = ["", "Variables filled from the link (change with clipform_set_link_variables):"];
|
|
17328
|
+
for (const v of links) {
|
|
17329
|
+
lines.push(` ${v.key} (${v.type ?? "text"}, after ${isPersonalLinkKey(v.key) ? "#" : "?"} in the link)`);
|
|
17330
|
+
}
|
|
17331
|
+
const viewer = data.urls?.viewer;
|
|
17332
|
+
if (viewer) lines.push(` Your link: ${buildVariableLink(viewer, links, (v) => v.example)}`);
|
|
17333
|
+
return lines.join("\n");
|
|
17334
|
+
}
|
|
17335
|
+
function registerGetFormTool(server, opts = {}) {
|
|
17310
17336
|
server.registerTool(
|
|
17311
17337
|
"clipform_get_form",
|
|
17312
17338
|
{
|
|
@@ -17369,7 +17395,8 @@ function registerGetFormTool(server) {
|
|
|
17369
17395
|
if (!result.ok) {
|
|
17370
17396
|
return apiErrorResult(result);
|
|
17371
17397
|
}
|
|
17372
|
-
|
|
17398
|
+
const text = formatFormState(result.data) + (opts.variables ? linkVariablesText(result.data) : "");
|
|
17399
|
+
return structuredResult(text, projectFormState(result.data));
|
|
17373
17400
|
}
|
|
17374
17401
|
);
|
|
17375
17402
|
}
|
|
@@ -17542,12 +17569,12 @@ ${others ? "The other changes in this call were saved to the draft, but the form
|
|
|
17542
17569
|
if (is_live === true) {
|
|
17543
17570
|
const meta = await callApi(`/forms/${form_id}`, { timeoutMs: 5e3 });
|
|
17544
17571
|
const urls = meta.ok ? meta.data.urls : void 0;
|
|
17545
|
-
const
|
|
17572
|
+
const viewerUrl2 = urls?.viewer;
|
|
17546
17573
|
const responsesUrl = urls?.responses;
|
|
17547
|
-
if (
|
|
17574
|
+
if (viewerUrl2) {
|
|
17548
17575
|
resultText += `
|
|
17549
17576
|
|
|
17550
|
-
Your form is live at: ${mdLink(LINK_LABELS.share,
|
|
17577
|
+
Your form is live at: ${mdLink(LINK_LABELS.share, viewerUrl2)}
|
|
17551
17578
|
Share this URL with respondents. View responses any time with clipform_get_results (form_id: ${form_id})${responsesUrl ? `, or in the dashboard: ${mdLink(LINK_LABELS.responses, responsesUrl)}` : ""}`;
|
|
17552
17579
|
}
|
|
17553
17580
|
}
|
|
@@ -17840,7 +17867,7 @@ function paymentSummary(value) {
|
|
|
17840
17867
|
if (amount === null || !currency) return null;
|
|
17841
17868
|
return `${(amount / 100).toFixed(2)} ${currency.toUpperCase()} - ${status}`;
|
|
17842
17869
|
}
|
|
17843
|
-
function registerGetResponsesTool(server) {
|
|
17870
|
+
function registerGetResponsesTool(server, opts = {}) {
|
|
17844
17871
|
server.registerTool(
|
|
17845
17872
|
"clipform_get_responses",
|
|
17846
17873
|
{
|
|
@@ -17881,7 +17908,7 @@ function registerGetResponsesTool(server) {
|
|
|
17881
17908
|
},
|
|
17882
17909
|
async ({ form_id, since, until, query, sort, limit }) => {
|
|
17883
17910
|
const [subsResult, formResult] = await Promise.all([
|
|
17884
|
-
callApi(`/forms/${form_id}/submissions`),
|
|
17911
|
+
opts.variables ? callApi(`/forms/${form_id}/submissions`, { params: { include: "variables" } }) : callApi(`/forms/${form_id}/submissions`),
|
|
17885
17912
|
callApi(`/forms/${form_id}`)
|
|
17886
17913
|
]);
|
|
17887
17914
|
if (!subsResult.ok) {
|
|
@@ -17895,7 +17922,10 @@ function registerGetResponsesTool(server) {
|
|
|
17895
17922
|
nodeList = nodes;
|
|
17896
17923
|
for (const n of nodes) nodeById.set(n.id, n);
|
|
17897
17924
|
}
|
|
17898
|
-
const
|
|
17925
|
+
const rawData = subsResult.data;
|
|
17926
|
+
const envelope = !Array.isArray(rawData) && rawData && typeof rawData === "object" ? rawData : void 0;
|
|
17927
|
+
const rows = (envelope ? envelope.rows : rawData) ?? [];
|
|
17928
|
+
const linkVars = (envelope?.variables ?? []).filter((v) => v.url_settable === true);
|
|
17899
17929
|
const sinceMs = since ? Date.parse(since) : null;
|
|
17900
17930
|
const untilMs = until ? Date.parse(until) : null;
|
|
17901
17931
|
const needle = query?.toLowerCase() ?? null;
|
|
@@ -17942,18 +17972,30 @@ function registerGetResponsesTool(server) {
|
|
|
17942
17972
|
const haystack = answers.map((a) => a.answer.toLowerCase()).join("\n");
|
|
17943
17973
|
if (!haystack.includes(needle)) continue;
|
|
17944
17974
|
}
|
|
17975
|
+
let linkValues = [];
|
|
17976
|
+
if (linkVars.length > 0 && row.variable_values) {
|
|
17977
|
+
const lv = [];
|
|
17978
|
+
for (const v of linkVars) {
|
|
17979
|
+
const val = row.variable_values[v.id];
|
|
17980
|
+
if (val === null || val === void 0 || val === "") continue;
|
|
17981
|
+
lv.push(`${v.key}=${isPersonalLinkKey(v.key) ? "[from the link]" : truncate(String(val), 100)}`);
|
|
17982
|
+
}
|
|
17983
|
+
linkValues = lv;
|
|
17984
|
+
}
|
|
17945
17985
|
projected.push({
|
|
17946
17986
|
submitted_at: submittedAt,
|
|
17947
17987
|
submitted_ms: ms,
|
|
17948
17988
|
status: row.status ?? "unknown",
|
|
17949
|
-
answers
|
|
17989
|
+
answers,
|
|
17990
|
+
links: linkValues
|
|
17950
17991
|
});
|
|
17951
17992
|
}
|
|
17952
17993
|
projected.sort(
|
|
17953
17994
|
(a, b) => sort === "oldest" ? a.submitted_ms - b.submitted_ms : b.submitted_ms - a.submitted_ms
|
|
17954
17995
|
);
|
|
17955
17996
|
const totalMatching = projected.length;
|
|
17956
|
-
const
|
|
17997
|
+
const cappedFull = projected.slice(0, limit ?? DEFAULT_LIMIT);
|
|
17998
|
+
const capped = cappedFull.map(({ submitted_ms: _ms, links: _links, ...rest }) => rest);
|
|
17957
17999
|
const filterBits = [
|
|
17958
18000
|
since ? `since ${since}` : null,
|
|
17959
18001
|
until ? `until ${until}` : null,
|
|
@@ -17962,9 +18004,10 @@ function registerGetResponsesTool(server) {
|
|
|
17962
18004
|
const lines = [
|
|
17963
18005
|
`${totalMatching} response(s)${filterBits.length ? ` ${filterBits.join(", ")}` : ""}${lockedCount > 0 ? ` (+${lockedCount} over the plan's response limit - not shown; upgrade or view counts in clipform_get_results)` : ""}. Showing ${capped.length}, ${sort === "oldest" ? "oldest" : "newest"} first.`,
|
|
17964
18006
|
``,
|
|
17965
|
-
...
|
|
18007
|
+
...cappedFull.flatMap((r) => [
|
|
17966
18008
|
`\u2014 ${r.submitted_at} [${r.status}]`,
|
|
17967
|
-
...r.answers.map((a) => ` ${a.question}: ${a.answer}`)
|
|
18009
|
+
...r.answers.map((a) => ` ${a.question}: ${a.answer}`),
|
|
18010
|
+
...r.links.length > 0 ? [` From the link: ${r.links.join(", ")}`] : []
|
|
17968
18011
|
]),
|
|
17969
18012
|
``,
|
|
17970
18013
|
REDACTION_FOOTER
|
|
@@ -18885,6 +18928,213 @@ Routes by answer are set. Call clipform_get_form to check each answer's route; i
|
|
|
18885
18928
|
);
|
|
18886
18929
|
}
|
|
18887
18930
|
|
|
18931
|
+
// src/tools/set-link-variables.ts
|
|
18932
|
+
var NOT_AVAILABLE = "Variables filled from the link are not available on this workspace.";
|
|
18933
|
+
var PasteSchema = external_exports.object({
|
|
18934
|
+
tool: external_exports.string().describe("The email/chat tool this key is the merge tag for"),
|
|
18935
|
+
snippet: external_exports.string().nullable().describe("Text to paste after the form link in that tool, or null when the tool adds it itself"),
|
|
18936
|
+
note: external_exports.string()
|
|
18937
|
+
});
|
|
18938
|
+
function pasteFor(key) {
|
|
18939
|
+
const preset = linkVariablePreset(key);
|
|
18940
|
+
return preset ? { tool: preset.tool, snippet: preset.snippet, note: preset.note } : void 0;
|
|
18941
|
+
}
|
|
18942
|
+
function normExample(type, raw) {
|
|
18943
|
+
if (raw === "" || raw === null) return null;
|
|
18944
|
+
return coerceVariableValue(type, raw);
|
|
18945
|
+
}
|
|
18946
|
+
function registerSetLinkVariablesTool(server) {
|
|
18947
|
+
server.registerTool(
|
|
18948
|
+
"clipform_set_link_variables",
|
|
18949
|
+
{
|
|
18950
|
+
title: "Set link variables",
|
|
18951
|
+
description: `Declare which variables a form fills from its link (also called hidden fields or URL parameters), and get back the form's "Your link" to paste into an email or chat tool. A link variable is a value like a subscriber id that the link carries into the response, so you can tell who replied. Send the full list: variables you leave out are switched off (never deleted, so earlier answers keep working), and an unchanged list makes no changes. Use an opaque id as the value (e.g. the tool's subscriber id), not an email. Keys are lowercase letters, digits and underscores (e.g. mailchimp_id); a key that looks personal (email, phone, name) goes after # in the link so it never reaches a server log. Known keys come with the exact merge tag to paste: ${LINK_VARIABLE_PRESETS.map((p) => `${p.key} (${p.tool})`).join(", ")}. At most ${VARIABLE_MAX_LINK_PER_FORM} link variables per form. Read the values back with clipform_get_responses.`,
|
|
18952
|
+
inputSchema: external_exports.object({
|
|
18953
|
+
form_id: external_exports.string().uuid().describe("The form UUID (returned by clipform_create_form, not the short share_id from the URL)"),
|
|
18954
|
+
variables: external_exports.array(
|
|
18955
|
+
external_exports.object({
|
|
18956
|
+
key: external_exports.string().describe("Lowercase key the link carries, e.g. mailchimp_id"),
|
|
18957
|
+
label: external_exports.string().optional().describe("Name shown in the dashboard (defaults to the key)"),
|
|
18958
|
+
type: external_exports.enum(VARIABLE_TYPES).optional().describe("text (default) or number. Cannot change once the variable exists."),
|
|
18959
|
+
example: external_exports.union([external_exports.string(), external_exports.number()]).optional().describe("Sample value shown in the link")
|
|
18960
|
+
})
|
|
18961
|
+
).max(VARIABLE_MAX_LINK_PER_FORM).describe("The complete list of variables this form fills from its link")
|
|
18962
|
+
}),
|
|
18963
|
+
outputSchema: external_exports.object({
|
|
18964
|
+
form_id: external_exports.string(),
|
|
18965
|
+
link: external_exports.string().optional().describe("Your link: the form link with every link variable on it. Not viewable until the form is published (see live)."),
|
|
18966
|
+
live: external_exports.boolean().optional().describe("Whether the form is published, i.e. the link works for respondents now"),
|
|
18967
|
+
variables: external_exports.array(
|
|
18968
|
+
external_exports.object({
|
|
18969
|
+
key: external_exports.string(),
|
|
18970
|
+
type: external_exports.string(),
|
|
18971
|
+
in: external_exports.enum(["query", "hash"]).describe("hash for a personal key (after #), else query (after ?)"),
|
|
18972
|
+
paste: PasteSchema.optional().describe("Present when the key is a known tool's merge tag")
|
|
18973
|
+
})
|
|
18974
|
+
),
|
|
18975
|
+
switched_off: external_exports.array(external_exports.string()).describe("Link variables that were on and are now off (kept, not deleted)"),
|
|
18976
|
+
changed: external_exports.boolean().describe("False when the list already matched and nothing was written")
|
|
18977
|
+
}),
|
|
18978
|
+
annotations: {
|
|
18979
|
+
readOnlyHint: false,
|
|
18980
|
+
destructiveHint: false,
|
|
18981
|
+
idempotentHint: true,
|
|
18982
|
+
openWorldHint: false
|
|
18983
|
+
}
|
|
18984
|
+
},
|
|
18985
|
+
async ({ form_id, variables }) => {
|
|
18986
|
+
const input = variables;
|
|
18987
|
+
const seen = /* @__PURE__ */ new Set();
|
|
18988
|
+
for (const f of input) {
|
|
18989
|
+
const keyError = validateVariableKey(f.key);
|
|
18990
|
+
if (keyError) return refusedResult(`${f.key}: ${keyError}`);
|
|
18991
|
+
if (seen.has(f.key)) return refusedResult(`${f.key} is listed twice.`);
|
|
18992
|
+
seen.add(f.key);
|
|
18993
|
+
if (f.label !== void 0 && (f.label.trim().length === 0 || f.label.length > VARIABLE_LABEL_MAX_LENGTH)) {
|
|
18994
|
+
return refusedResult(`${f.key}: label must be 1 to ${VARIABLE_LABEL_MAX_LENGTH} characters.`);
|
|
18995
|
+
}
|
|
18996
|
+
}
|
|
18997
|
+
if (input.length > VARIABLE_MAX_LINK_PER_FORM) {
|
|
18998
|
+
return refusedResult(`A form can fill ${VARIABLE_MAX_LINK_PER_FORM} variables from the link at most (got ${input.length}).`);
|
|
18999
|
+
}
|
|
19000
|
+
const listed = await callApi(`/forms/${form_id}/variables`);
|
|
19001
|
+
if (!listed.ok) return apiErrorResult(listed);
|
|
19002
|
+
const existing = listed.data?.variables ?? [];
|
|
19003
|
+
const byKey = new Map(existing.map((v) => [v.key, v]));
|
|
19004
|
+
const score = findScoreVariable(existing);
|
|
19005
|
+
const plans = [];
|
|
19006
|
+
let newCustom = 0;
|
|
19007
|
+
for (const f of input) {
|
|
19008
|
+
const row = byKey.get(f.key);
|
|
19009
|
+
if (!row) {
|
|
19010
|
+
const type = f.type ?? "text";
|
|
19011
|
+
if (f.example !== void 0 && normExample(type, f.example) === void 0) {
|
|
19012
|
+
return refusedResult(`${f.key}: example must be ${type === "number" ? "a number" : "text of 500 characters or fewer"}.`);
|
|
19013
|
+
}
|
|
19014
|
+
newCustom++;
|
|
19015
|
+
plans.push({ op: "create", field: f, type });
|
|
19016
|
+
continue;
|
|
19017
|
+
}
|
|
19018
|
+
if (row.kind !== "custom" || score && row.id === score.id) {
|
|
19019
|
+
return refusedResult(`${f.key} is a built-in or Score variable, which the link cannot fill. Pick another key.`);
|
|
19020
|
+
}
|
|
19021
|
+
if (f.type !== void 0 && f.type !== row.type) {
|
|
19022
|
+
return refusedResult(`${f.key} already exists as ${row.type} and a variable's type cannot change. Use another key, or delete it in the dashboard first.`);
|
|
19023
|
+
}
|
|
19024
|
+
const wantExample = f.example === void 0 ? void 0 : normExample(row.type, f.example);
|
|
19025
|
+
if (f.example !== void 0 && wantExample === void 0) {
|
|
19026
|
+
return refusedResult(`${f.key}: example must be ${row.type === "number" ? "a number" : "text of 500 characters or fewer"}.`);
|
|
19027
|
+
}
|
|
19028
|
+
const body = {};
|
|
19029
|
+
if (row.url_settable !== true) body.url_settable = true;
|
|
19030
|
+
if (f.label !== void 0 && f.label.trim() !== row.label) body.label = f.label.trim();
|
|
19031
|
+
if (wantExample !== void 0 && wantExample !== (normExample(row.type, row.example) ?? null)) body.example = wantExample;
|
|
19032
|
+
if (Object.keys(body).length > 0) plans.push({ op: "patch", field: f, row, body });
|
|
19033
|
+
}
|
|
19034
|
+
const customCount = existing.filter((v) => v.kind === "custom").length;
|
|
19035
|
+
if (customCount + newCustom > VARIABLE_MAX_CUSTOM_PER_FORM) {
|
|
19036
|
+
return refusedResult(`A form can have ${VARIABLE_MAX_CUSTOM_PER_FORM} custom variables at most; this would make ${customCount + newCustom}.`);
|
|
19037
|
+
}
|
|
19038
|
+
const switchOff = existing.filter(
|
|
19039
|
+
(v) => v.kind === "custom" && v.url_settable === true && !seen.has(v.key) && !(score && v.id === score.id)
|
|
19040
|
+
);
|
|
19041
|
+
const applied = [];
|
|
19042
|
+
const failed = [];
|
|
19043
|
+
const failedStatuses = [];
|
|
19044
|
+
const switchedOff = [];
|
|
19045
|
+
const finalRows = new Map(existing.map((v) => [v.key, { ...v }]));
|
|
19046
|
+
const unavailable = () => applied.length === 0 && failed.length === 0 ? refusedResult(NOT_AVAILABLE) : null;
|
|
19047
|
+
for (const row of switchOff) {
|
|
19048
|
+
const res = await callApi(`/forms/${form_id}/variables/${row.id}`, { method: "PATCH", body: { url_settable: false } });
|
|
19049
|
+
if (res.ok) {
|
|
19050
|
+
switchedOff.push(row.key);
|
|
19051
|
+
applied.push(`switched off ${row.key}`);
|
|
19052
|
+
finalRows.get(row.key).url_settable = false;
|
|
19053
|
+
} else if (res.status === 404 && unavailable()) {
|
|
19054
|
+
return refusedResult(NOT_AVAILABLE);
|
|
19055
|
+
} else {
|
|
19056
|
+
failed.push(`switch off ${row.key}: ${res.error}`);
|
|
19057
|
+
failedStatuses.push(res);
|
|
19058
|
+
}
|
|
19059
|
+
}
|
|
19060
|
+
for (const plan of plans) {
|
|
19061
|
+
const key = plan.field.key;
|
|
19062
|
+
const res = plan.op === "create" ? await callApi(`/forms/${form_id}/variables`, {
|
|
19063
|
+
method: "POST",
|
|
19064
|
+
body: {
|
|
19065
|
+
key,
|
|
19066
|
+
label: plan.field.label?.trim() ?? key,
|
|
19067
|
+
type: plan.type,
|
|
19068
|
+
url_settable: true,
|
|
19069
|
+
...plan.field.example !== void 0 && normExample(plan.type, plan.field.example) !== null ? { example: normExample(plan.type, plan.field.example) } : {}
|
|
19070
|
+
}
|
|
19071
|
+
}) : await callApi(`/forms/${form_id}/variables/${plan.row.id}`, { method: "PATCH", body: plan.body });
|
|
19072
|
+
if (res.ok) {
|
|
19073
|
+
applied.push(`${plan.op === "create" ? "added" : "updated"} ${key}`);
|
|
19074
|
+
const returned = res.data?.variable;
|
|
19075
|
+
finalRows.set(key, returned ?? { ...finalRows.get(key) ?? { id: "", key, type: plan.op === "create" ? plan.type : plan.row.type, kind: "custom" }, url_settable: true });
|
|
19076
|
+
} else if (res.status === 404 && unavailable()) {
|
|
19077
|
+
return refusedResult(NOT_AVAILABLE);
|
|
19078
|
+
} else {
|
|
19079
|
+
failed.push(`${key}: ${res.error}`);
|
|
19080
|
+
failedStatuses.push(res);
|
|
19081
|
+
}
|
|
19082
|
+
}
|
|
19083
|
+
if (failed.length > 0) {
|
|
19084
|
+
const allRefused = failedStatuses.every((f) => isRefusedStatus(f.status, f.code));
|
|
19085
|
+
return (allRefused ? refusedResult : errorResult)(
|
|
19086
|
+
`Some link variables were not saved. Done: ${applied.length ? applied.join(", ") : "nothing"}. Failed: ${failed.join("; ")}. Call clipform_set_link_variables again with the same list to finish - it only retries what is missing.`
|
|
19087
|
+
);
|
|
19088
|
+
}
|
|
19089
|
+
const live = input.map((f) => finalRows.get(f.key)).filter((v) => !!v);
|
|
19090
|
+
const formResult = await callApi(`/forms/${form_id}`, { params: { include: "logic" } });
|
|
19091
|
+
const formData = formResult.ok ? formResult.data : void 0;
|
|
19092
|
+
const shareUrl = formData?.urls?.viewer ?? (formData?.share_id ? viewerUrl(formData.share_id) : void 0);
|
|
19093
|
+
const isLive = formData?.is_live === true;
|
|
19094
|
+
const link = shareUrl ? buildVariableLink(shareUrl, live, (v) => v.example) : void 0;
|
|
19095
|
+
const outFields = live.map((v) => {
|
|
19096
|
+
const paste = pasteFor(v.key);
|
|
19097
|
+
return {
|
|
19098
|
+
key: v.key,
|
|
19099
|
+
type: v.type,
|
|
19100
|
+
in: isPersonalLinkKey(v.key) ? "hash" : "query",
|
|
19101
|
+
...paste ? { paste } : {}
|
|
19102
|
+
};
|
|
19103
|
+
});
|
|
19104
|
+
const changed = applied.length > 0;
|
|
19105
|
+
const lines = [
|
|
19106
|
+
changed ? `Variables filled from the link saved on form ${form_id}.` : `Variables filled from the link already match - nothing changed on form ${form_id}.`
|
|
19107
|
+
];
|
|
19108
|
+
if (outFields.length === 0) lines.push("No variables are filled from the link. The form link carries no values.");
|
|
19109
|
+
for (const f of outFields) {
|
|
19110
|
+
lines.push(`- ${f.key} (${f.type}, after ${f.in === "hash" ? "#" : "?"} in the link)${f.paste ? ` - ${f.paste.tool}: ${f.paste.snippet ?? f.paste.note}` : ""}`);
|
|
19111
|
+
}
|
|
19112
|
+
if (switchedOff.length > 0) lines.push(`Switched off (kept, not deleted): ${switchedOff.join(", ")}.`);
|
|
19113
|
+
if (link && outFields.length > 0) {
|
|
19114
|
+
lines.push(
|
|
19115
|
+
"",
|
|
19116
|
+
isLive ? `Your link: ${link}` : `Your link (FUTURE LIVE URL - not viewable yet, the form is a draft; it starts working once you publish with clipform_update_form is_live: true): ${link}`
|
|
19117
|
+
);
|
|
19118
|
+
lines.push("Replace each empty or sample value with the tool's own merge tag for the subscriber id.");
|
|
19119
|
+
} else if (outFields.length > 0) {
|
|
19120
|
+
lines.push("", "The form link could not be read just now. Call clipform_get_form to get the form's link, then add each variable after ? (or # for a personal key).");
|
|
19121
|
+
}
|
|
19122
|
+
if (outFields.some((f) => f.in === "hash")) {
|
|
19123
|
+
lines.push("A personal key (email, phone, name) goes after # so it stays out of server logs. Prefer an opaque id over an email where the tool offers one.");
|
|
19124
|
+
} else if (outFields.length > 0) {
|
|
19125
|
+
lines.push("Use an opaque id (the tool's subscriber id), not an email address.");
|
|
19126
|
+
}
|
|
19127
|
+
return structuredResult(lines.join("\n"), {
|
|
19128
|
+
form_id,
|
|
19129
|
+
...link && outFields.length > 0 ? { link, live: isLive } : {},
|
|
19130
|
+
variables: outFields,
|
|
19131
|
+
switched_off: switchedOff,
|
|
19132
|
+
changed
|
|
19133
|
+
});
|
|
19134
|
+
}
|
|
19135
|
+
);
|
|
19136
|
+
}
|
|
19137
|
+
|
|
18888
19138
|
// src/tools/log-generation.ts
|
|
18889
19139
|
function registerLogGenerationTool(server) {
|
|
18890
19140
|
server.registerTool(
|
|
@@ -20585,11 +20835,11 @@ function createServer(options) {
|
|
|
20585
20835
|
registerImportFormTool(server);
|
|
20586
20836
|
registerListFormsTool(server, caps);
|
|
20587
20837
|
registerWhoamiTool(server);
|
|
20588
|
-
registerGetFormTool(server);
|
|
20838
|
+
registerGetFormTool(server, { variables: options?.variables === true });
|
|
20589
20839
|
registerUpdateFormTool(server);
|
|
20590
20840
|
registerDeleteFormTool(server);
|
|
20591
20841
|
registerGetResultsTool(server);
|
|
20592
|
-
registerGetResponsesTool(server);
|
|
20842
|
+
registerGetResponsesTool(server, { variables: options?.variables === true });
|
|
20593
20843
|
registerAddNodeTool(server);
|
|
20594
20844
|
registerUpdateNodeTool(server);
|
|
20595
20845
|
registerDeleteNodeTool(server);
|
|
@@ -20599,6 +20849,7 @@ function createServer(options) {
|
|
|
20599
20849
|
registerGetNodeMediaTool(server);
|
|
20600
20850
|
registerDeleteNodeMediaTool(server);
|
|
20601
20851
|
registerSetNodeLogicTool(server);
|
|
20852
|
+
if (options?.variables === true) registerSetLinkVariablesTool(server);
|
|
20602
20853
|
registerLogGenerationTool(server);
|
|
20603
20854
|
registerSearchNewsTool(server);
|
|
20604
20855
|
registerGenerateTtsTool(server);
|
|
@@ -20685,4 +20936,4 @@ export {
|
|
|
20685
20936
|
* MIT Licensed
|
|
20686
20937
|
*)
|
|
20687
20938
|
*/
|
|
20688
|
-
//# sourceMappingURL=chunk-
|
|
20939
|
+
//# sourceMappingURL=chunk-25QWATF4.js.map
|