@clagentic/console 1.9.0 → 1.10.0-beta.2
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/LICENSE +117 -12
- package/LICENSES/MIT-legacy.txt +22 -0
- package/LICENSES/README.md +15 -0
- package/README.md +9 -3
- package/bin/cli.js +40 -5
- package/deploy/clagentic-console.service +10 -6
- package/lib/agent-dispatch-tool.js +20 -0
- package/lib/audit.js +3 -2
- package/lib/build-changes.js +79 -0
- package/lib/build-identity.js +192 -0
- package/lib/build-monitor.js +125 -0
- package/lib/build-sha.json +2 -2
- package/lib/build-update-check.js +138 -0
- package/lib/build-update-offer.js +141 -0
- package/lib/build-update-restart.js +142 -0
- package/lib/build-update-standing.js +184 -0
- package/lib/cli/daemon-launch.js +25 -22
- package/lib/cli/ipc-subcommands.js +6 -0
- package/lib/cli/session-subcommands.js +122 -0
- package/lib/cli-sessions.js +8 -1
- package/lib/codex-defaults.js +8 -2
- package/lib/config.js +32 -20
- package/lib/daemon-env-settings.js +84 -0
- package/lib/daemon-projects.js +57 -0
- package/lib/daemon.js +288 -205
- package/lib/drain.js +74 -17
- package/lib/env-compat.js +61 -0
- package/lib/extension-commands.js +45 -0
- package/lib/history-visibility.js +4 -0
- package/lib/idle-adapter-reaper.js +71 -0
- package/lib/link-trap.js +78 -0
- package/lib/mcp-local.js +8 -6
- package/lib/mcp-tool-input.js +116 -0
- package/lib/mcp-tool-schema.js +179 -0
- package/lib/memory-limits.js +61 -5
- package/lib/memory-setting-validate.js +65 -0
- package/lib/memory-shed.js +13 -32
- package/lib/new-work-gate.js +47 -0
- package/lib/os-users.js +5 -3
- package/lib/project-access.js +139 -0
- package/lib/project-connection.js +37 -22
- package/lib/project-external-trigger.js +166 -105
- package/lib/project-file-scope.js +172 -0
- package/lib/project-file-watch.js +86 -61
- package/lib/project-filesystem.js +144 -128
- package/lib/project-git.js +119 -0
- package/lib/project-http.js +44 -28
- package/lib/project-loop.js +17 -9
- package/lib/project-mcp.js +53 -72
- package/lib/project-message-gate.js +70 -0
- package/lib/project-notifications.js +31 -4
- package/lib/project-prompt-responses.js +217 -0
- package/lib/project-sessions.js +192 -355
- package/lib/project-user-message.js +27 -15
- package/lib/project.js +212 -147
- package/lib/projects-dir.js +90 -0
- package/lib/prompt-access.js +22 -0
- package/lib/prompt-kinds/answer-limits.js +15 -0
- package/lib/prompt-kinds/ask-user.js +58 -0
- package/lib/prompt-kinds/codecs.js +97 -0
- package/lib/prompt-kinds/elicitation.js +77 -0
- package/lib/prompt-kinds/extension.js +39 -0
- package/lib/prompt-kinds/index.js +68 -0
- package/lib/prompt-kinds/permission.js +114 -0
- package/lib/prompt-kinds/plan.js +79 -0
- package/lib/prompt-kinds/tool-call.js +38 -0
- package/lib/prompt-registry.js +680 -0
- package/lib/public/app.js +1 -1
- package/lib/public/css/diagnostics.css +80 -0
- package/lib/public/css/input.css +17 -3
- package/lib/public/css/menus.css +10 -0
- package/lib/public/css/messages.css +5 -0
- package/lib/public/css/rewind.css +22 -0
- package/lib/public/index.html +4 -12
- package/lib/public/modules/agent-dispatch-tool.js +9 -0
- package/lib/public/modules/app-connection.js +7 -0
- package/lib/public/modules/app-cursors.js +7 -5
- package/lib/public/modules/app-messages.js +52 -47
- package/lib/public/modules/app-notifications.js +47 -71
- package/lib/public/modules/app-panels.js +61 -59
- package/lib/public/modules/app-projects.js +2 -1
- package/lib/public/modules/app-rendering.js +4 -10
- package/lib/public/modules/build-update-detail.js +54 -0
- package/lib/public/modules/diagnostics.js +170 -20
- package/lib/public/modules/filebrowser.js +18 -16
- package/lib/public/modules/history-visibility.js +4 -0
- package/lib/public/modules/mention.js +3 -2
- package/lib/public/modules/mode-options.js +38 -0
- package/lib/public/modules/project-settings.js +19 -8
- package/lib/public/modules/prompt-banner.js +78 -0
- package/lib/public/modules/prompt-card.js +201 -0
- package/lib/public/modules/prompt-kinds/ask-user-codec.js +131 -0
- package/lib/public/modules/prompt-kinds/ask-user.js +213 -0
- package/lib/public/modules/prompt-kinds/elicitation-codec.js +343 -0
- package/lib/public/modules/prompt-kinds/elicitation.js +176 -0
- package/lib/public/modules/prompt-kinds/index.js +18 -0
- package/lib/public/modules/prompt-kinds/own-key.js +29 -0
- package/lib/public/modules/prompt-kinds/package.json +3 -0
- package/lib/public/modules/prompt-kinds/permission-choices.js +31 -0
- package/lib/public/modules/prompt-kinds/permission.js +209 -0
- package/lib/public/modules/prompt-kinds/plan.js +102 -0
- package/lib/public/modules/prompt-state.js +142 -0
- package/lib/public/modules/prompts.js +134 -0
- package/lib/public/modules/rewind.js +4 -1
- package/lib/public/modules/server-settings.js +2 -4
- package/lib/public/modules/sidebar-mobile.js +19 -9
- package/lib/public/modules/sidebar-sessions.js +21 -14
- package/lib/public/modules/sticky-notes.js +3 -2
- package/lib/public/modules/team-panel.js +5 -4
- package/lib/public/modules/tools.js +81 -906
- package/lib/public/modules/vendor-picker.js +53 -0
- package/lib/public/modules/vendor-registry.js +142 -0
- package/lib/public/sw.js +3 -1
- package/lib/rc-migrate.js +44 -0
- package/lib/runtime-env-keys.js +109 -0
- package/lib/runtime-env.js +236 -0
- package/lib/sdk-bridge.js +348 -284
- package/lib/sdk-message-processor.js +117 -146
- package/lib/sdk-skill-discovery.js +65 -60
- package/lib/server-hub-sessions.js +13 -10
- package/lib/server-palette.js +28 -19
- package/lib/server.js +156 -115
- package/lib/service-install.js +96 -0
- package/lib/session-capabilities.js +76 -0
- package/lib/session-id.js +33 -0
- package/lib/session-input-ipc.js +32 -0
- package/lib/session-input.js +379 -0
- package/lib/session-reclaim.js +284 -0
- package/lib/session-resume.js +172 -0
- package/lib/sessions.js +61 -30
- package/lib/supervisor.js +39 -0
- package/lib/turn-initiator.js +108 -0
- package/lib/users-permissions.js +9 -6
- package/lib/users.js +9 -0
- package/lib/utils.js +4 -2
- package/lib/vendor-auth.js +22 -0
- package/lib/vendor-registry-message.js +66 -0
- package/lib/ws-origin.js +99 -0
- package/lib/ws-schema.js +36 -23
- package/lib/yoke/adapters/claude-capabilities.js +38 -0
- package/lib/yoke/adapters/claude-vendor.js +34 -0
- package/lib/yoke/adapters/claude-worker.js +57 -87
- package/lib/yoke/adapters/claude.js +182 -88
- package/lib/yoke/adapters/codex-capabilities.js +40 -0
- package/lib/yoke/adapters/codex-vendor.js +46 -0
- package/lib/yoke/adapters/codex.js +462 -211
- package/lib/yoke/adapters/effort-control.js +34 -0
- package/lib/yoke/adapters/permission-relay.js +58 -0
- package/lib/yoke/adapters/worker-mcp-servers.js +81 -0
- package/lib/yoke/auth-checks.js +91 -0
- package/lib/yoke/capabilities.js +49 -0
- package/lib/yoke/codex-app-server.js +30 -56
- package/lib/yoke/codex-binary.js +254 -0
- package/lib/yoke/codex-command.js +122 -0
- package/lib/yoke/codex-protocol.js +96 -0
- package/lib/yoke/codex-version.js +135 -0
- package/lib/yoke/env-ownership.js +40 -0
- package/lib/yoke/index.js +84 -174
- package/lib/yoke/install-probe.js +136 -0
- package/lib/yoke/instructions.js +7 -11
- package/lib/yoke/interface.js +206 -4
- package/lib/yoke/package.json +1 -1
- package/lib/yoke/provider-credentials.js +96 -0
- package/lib/yoke/registry.js +377 -0
- package/package.json +12 -9
- package/scripts/check-sdk-lock-drift.js +160 -0
- package/scripts/check-test-count.js +76 -1
- package/scripts/postinstall.js +218 -136
- package/scripts/prompt-harness-history.js +202 -0
- package/scripts/verify-installed-build.js +59 -17
- package/scripts/verify-installed.js +67 -0
- package/lib/sdk-permission-ownership.js +0 -136
|
@@ -0,0 +1,343 @@
|
|
|
1
|
+
// elicitation-codec.js - the one definition of an MCP elicitation answer,
|
|
2
|
+
// shared by the card (this directory) and the server
|
|
3
|
+
// (lib/prompt-kinds/elicitation.js): which requested schemas a form is drawn
|
|
4
|
+
// for, which fields such a schema asks for, what value each may take, how a
|
|
5
|
+
// form control's text reads as that value, and when a URL request may be
|
|
6
|
+
// approved.
|
|
7
|
+
//
|
|
8
|
+
// This file is the only copy: the server imports it as is
|
|
9
|
+
// (lib/prompt-kinds/codecs.js).
|
|
10
|
+
|
|
11
|
+
// Bound on typed text (lib/prompt-kinds/answer-limits.js applies the same).
|
|
12
|
+
var MAX_ANSWER_CHARS = 10000;
|
|
13
|
+
// Only a web page may be opened from a prompt.
|
|
14
|
+
var OPENABLE_PROTOCOLS = ["http:", "https:"];
|
|
15
|
+
|
|
16
|
+
// The requested-schema subset MCP elicitation defines, and the only one a
|
|
17
|
+
// form is drawn for: a flat object whose every property is a string
|
|
18
|
+
// (minLength, maxLength, format), a number or integer (minimum, maximum), a
|
|
19
|
+
// boolean, or a string enum (enum, enumNames), each with an optional title,
|
|
20
|
+
// description and default. Every keyword of the subset is enforced. A schema
|
|
21
|
+
// that uses anything else is refused whole, never drawn in part: a form
|
|
22
|
+
// that checks only some of what was asked would pass answers on as valid
|
|
23
|
+
// that the server never accepted.
|
|
24
|
+
var SCHEMA_KEYWORDS = ["$schema", "type", "title", "description", "properties", "required", "additionalProperties"];
|
|
25
|
+
var ANNOTATIONS = ["type", "title", "description", "default"];
|
|
26
|
+
var PROPERTY_KEYWORDS = {
|
|
27
|
+
string: ANNOTATIONS.concat(["minLength", "maxLength", "format"]),
|
|
28
|
+
enum: ANNOTATIONS.concat(["enum", "enumNames"]),
|
|
29
|
+
number: ANNOTATIONS.concat(["minimum", "maximum"]),
|
|
30
|
+
integer: ANNOTATIONS.concat(["minimum", "maximum"]),
|
|
31
|
+
boolean: ANNOTATIONS,
|
|
32
|
+
};
|
|
33
|
+
var FORMATS = {
|
|
34
|
+
email: { test: isEmail, error: "is not an email address" },
|
|
35
|
+
uri: { test: isAbsoluteUri, error: "is not an absolute URI" },
|
|
36
|
+
date: { test: isDate, error: "is not a date (YYYY-MM-DD)" },
|
|
37
|
+
"date-time": { test: isDateTime, error: "is not a date and time (YYYY-MM-DDThh:mm:ssZ)" },
|
|
38
|
+
};
|
|
39
|
+
var DATE = /^(\d{4})-(\d{2})-(\d{2})$/;
|
|
40
|
+
var DATE_TIME = /^(\d{4})-(\d{2})-(\d{2})[Tt](\d{2}):(\d{2}):(\d{2})(\.\d+)?(?:[Zz]|[+-](\d{2}):(\d{2}))$/;
|
|
41
|
+
|
|
42
|
+
function isPlainObject(v) {
|
|
43
|
+
return !!v && typeof v === "object" && !Array.isArray(v);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function isString(v) {
|
|
47
|
+
return typeof v === "string";
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// Whether table holds name itself (a name from a schema may be anything).
|
|
51
|
+
function holds(table, name) {
|
|
52
|
+
return typeof name === "string" && Object.prototype.hasOwnProperty.call(table, name);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// Defined, not assigned, so a field named "__proto__" is a key.
|
|
56
|
+
function put(obj, key, value) {
|
|
57
|
+
Object.defineProperty(obj, key, { value: value, enumerable: true, writable: true, configurable: true });
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// A string's length as JSON Schema counts it: in characters, not UTF-16
|
|
61
|
+
// code units.
|
|
62
|
+
function textLength(s) {
|
|
63
|
+
return Array.from(s).length;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// The address pattern the WHATWG HTML standard gives for input type=email.
|
|
67
|
+
var EMAIL = /^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/;
|
|
68
|
+
|
|
69
|
+
function isEmail(v) {
|
|
70
|
+
return EMAIL.test(v);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function isAbsoluteUri(v) {
|
|
74
|
+
if (!/^[A-Za-z][A-Za-z0-9+.-]*:\S+$/.test(v)) return false;
|
|
75
|
+
try {
|
|
76
|
+
new URL(v);
|
|
77
|
+
return true;
|
|
78
|
+
} catch (e) {
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function isCalendarDate(y, m, d) {
|
|
84
|
+
var leap = y % 4 === 0 && (y % 100 !== 0 || y % 400 === 0);
|
|
85
|
+
var days = [31, leap ? 29 : 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
|
|
86
|
+
return m >= 1 && m <= 12 && d >= 1 && d <= days[m - 1];
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function isDate(v) {
|
|
90
|
+
var m = DATE.exec(v);
|
|
91
|
+
return !!m && isCalendarDate(Number(m[1]), Number(m[2]), Number(m[3]));
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function isDateTime(v) {
|
|
95
|
+
var m = DATE_TIME.exec(v);
|
|
96
|
+
if (!m || !isCalendarDate(Number(m[1]), Number(m[2]), Number(m[3]))) return false;
|
|
97
|
+
if (Number(m[4]) > 23 || Number(m[5]) > 59 || Number(m[6]) > 60) return false;
|
|
98
|
+
return m[8] === undefined || (Number(m[8]) <= 23 && Number(m[9]) <= 59);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// "url" when the server asks the operator to open a URL, else "form". A URL
|
|
102
|
+
// request is never treated as a form, whether or not its URL is usable.
|
|
103
|
+
function requestMode(request) {
|
|
104
|
+
return request && request.mode === "url" ? "url" : "form";
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// Whether url is an http(s) URL, the only kind a prompt may open.
|
|
108
|
+
function isOpenableUrl(url) {
|
|
109
|
+
if (typeof url !== "string" || !url) return false;
|
|
110
|
+
try {
|
|
111
|
+
return OPENABLE_PROTOCOLS.indexOf(new URL(url).protocol) !== -1;
|
|
112
|
+
} catch (e) {
|
|
113
|
+
return false;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function firstUnknown(obj, known) {
|
|
118
|
+
var keys = Object.keys(obj);
|
|
119
|
+
for (var i = 0; i < keys.length; i++) {
|
|
120
|
+
if (known.indexOf(keys[i]) === -1) return keys[i];
|
|
121
|
+
}
|
|
122
|
+
return null;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function isLength(v) {
|
|
126
|
+
return v === undefined || (Number.isInteger(v) && v >= 0);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function isBound(v) {
|
|
130
|
+
return v === undefined || (typeof v === "number" && Number.isFinite(v));
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// Which subset property prop is: "string", "enum", "number", "integer" or
|
|
134
|
+
// "boolean"; null when it is none of them.
|
|
135
|
+
function subsetShape(prop) {
|
|
136
|
+
if (!isPlainObject(prop)) return null;
|
|
137
|
+
if (prop.enum !== undefined) return prop.type === "string" ? "enum" : null;
|
|
138
|
+
return prop.type !== "enum" && holds(PROPERTY_KEYWORDS, prop.type) ? prop.type : null;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
function propertyProblem(name, prop) {
|
|
142
|
+
var shape = subsetShape(prop);
|
|
143
|
+
if (!shape) return name + ": only a string, number, integer, boolean or string-enum field is supported";
|
|
144
|
+
var unknown = firstUnknown(prop, PROPERTY_KEYWORDS[shape]);
|
|
145
|
+
if (unknown !== null) return name + ": \"" + unknown + "\" is not supported";
|
|
146
|
+
if (shape === "string") {
|
|
147
|
+
if (!isLength(prop.minLength) || !isLength(prop.maxLength)) return name + ": minLength and maxLength must be whole numbers of 0 or more";
|
|
148
|
+
if (prop.minLength > prop.maxLength) return name + ": minLength is above maxLength";
|
|
149
|
+
if (prop.format !== undefined && !holds(FORMATS, prop.format)) return name + ": format must be email, uri, date or date-time";
|
|
150
|
+
} else if (shape === "enum") {
|
|
151
|
+
if (!Array.isArray(prop.enum) || !prop.enum.length || !prop.enum.every(isString)) return name + ": enum must list one or more strings";
|
|
152
|
+
// An empty control reads as no answer, so "" could never be chosen.
|
|
153
|
+
if (prop.enum.indexOf("") !== -1) return name + ": enum must not list an empty string";
|
|
154
|
+
var names = prop.enumNames;
|
|
155
|
+
if (names !== undefined && !(Array.isArray(names) && names.length === prop.enum.length && names.every(isString))) {
|
|
156
|
+
return name + ": enumNames must name every enum value with a string";
|
|
157
|
+
}
|
|
158
|
+
} else if (shape === "number" || shape === "integer") {
|
|
159
|
+
if (!isBound(prop.minimum) || !isBound(prop.maximum)) return name + ": minimum and maximum must be numbers";
|
|
160
|
+
if (prop.minimum > prop.maximum) return name + ": minimum is above maximum";
|
|
161
|
+
}
|
|
162
|
+
return null;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// Why a form cannot be drawn for schema, or null when it can and every
|
|
166
|
+
// answer to it is checked in full. No schema asks for no fields.
|
|
167
|
+
function schemaProblem(schema) {
|
|
168
|
+
if (schema === null || schema === undefined) return null;
|
|
169
|
+
if (!isPlainObject(schema) || schema.type !== "object") return "the form is not an object schema";
|
|
170
|
+
var unknown = firstUnknown(schema, SCHEMA_KEYWORDS);
|
|
171
|
+
if (unknown !== null) return "\"" + unknown + "\" is not supported";
|
|
172
|
+
if (schema.additionalProperties !== undefined && typeof schema.additionalProperties !== "boolean") {
|
|
173
|
+
return "additionalProperties must be true or false";
|
|
174
|
+
}
|
|
175
|
+
if (schema.required !== undefined && !(Array.isArray(schema.required) && schema.required.every(isString))) {
|
|
176
|
+
return "required must list field names";
|
|
177
|
+
}
|
|
178
|
+
var required = schema.required || [];
|
|
179
|
+
if (schema.properties === undefined) return required.length ? "required names " + required[0] + ", which is not a property" : null;
|
|
180
|
+
if (!isPlainObject(schema.properties)) return "properties must be an object";
|
|
181
|
+
for (var r = 0; r < required.length; r++) {
|
|
182
|
+
if (!holds(schema.properties, required[r])) return "required names " + required[r] + ", which is not a property";
|
|
183
|
+
}
|
|
184
|
+
var names = Object.keys(schema.properties);
|
|
185
|
+
for (var i = 0; i < names.length; i++) {
|
|
186
|
+
var problem = propertyProblem(names[i], schema.properties[names[i]]);
|
|
187
|
+
if (problem) return problem;
|
|
188
|
+
// An empty control reads as no answer, so "" could never be given.
|
|
189
|
+
if (required.indexOf(names[i]) !== -1 && schema.properties[names[i]].maxLength === 0 && subsetShape(schema.properties[names[i]]) === "string") {
|
|
190
|
+
return names[i] + ": a required string cannot have a maxLength of 0";
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
return null;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
// The longest text a field takes: the schema's own maxLength when tighter.
|
|
197
|
+
function lengthLimit(prop) {
|
|
198
|
+
var max = prop.maxLength;
|
|
199
|
+
return (Number.isInteger(max) && max >= 0 && max < MAX_ANSWER_CHARS) ? max : MAX_ANSWER_CHARS;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
// What a property's value is: one of its enum values, or a boolean,
|
|
203
|
+
// integer, number or (anything else) string.
|
|
204
|
+
function fieldType(prop) {
|
|
205
|
+
if (Array.isArray(prop.enum)) return "enum";
|
|
206
|
+
if (prop.type === "boolean" || prop.type === "integer" || prop.type === "number") return prop.type;
|
|
207
|
+
return "string";
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
// The fields a requested schema asks for, in its order: name, property,
|
|
211
|
+
// type, whether required, and the values a choice field offers (null for a
|
|
212
|
+
// typed-in field). A boolean is a choice between true and false.
|
|
213
|
+
function schemaFields(schema) {
|
|
214
|
+
var props = schema && isPlainObject(schema.properties) ? schema.properties : {};
|
|
215
|
+
var required = schema && Array.isArray(schema.required) ? schema.required : [];
|
|
216
|
+
return Object.keys(props).map(function (name) {
|
|
217
|
+
var prop = isPlainObject(props[name]) ? props[name] : {};
|
|
218
|
+
var type = fieldType(prop);
|
|
219
|
+
var choices = type === "enum" ? prop.enum.slice() : type === "boolean" ? [true, false] : null;
|
|
220
|
+
return { name: name, prop: prop, type: type, required: required.indexOf(name) !== -1, choices: choices };
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
// No answer to a field: nothing, or nothing typed.
|
|
225
|
+
function isAbsent(value) {
|
|
226
|
+
return value === undefined || value === null || value === "";
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
// What keeps value, already of field's type, from answering field: the
|
|
230
|
+
// error to show, or null when nothing does.
|
|
231
|
+
function constraintError(field, value) {
|
|
232
|
+
var prop = field.prop;
|
|
233
|
+
if (field.type === "integer" || field.type === "number") {
|
|
234
|
+
if (typeof prop.minimum === "number" && value < prop.minimum) return "must be at least " + prop.minimum;
|
|
235
|
+
if (typeof prop.maximum === "number" && value > prop.maximum) return "must be at most " + prop.maximum;
|
|
236
|
+
return null;
|
|
237
|
+
}
|
|
238
|
+
if (field.type !== "string") return null;
|
|
239
|
+
if (value.length > MAX_ANSWER_CHARS || (Number.isInteger(prop.maxLength) && textLength(value) > prop.maxLength)) {
|
|
240
|
+
return "is too long";
|
|
241
|
+
}
|
|
242
|
+
if (Number.isInteger(prop.minLength) && textLength(value) < prop.minLength) return "is too short";
|
|
243
|
+
if (holds(FORMATS, prop.format) && !FORMATS[prop.format].test(value)) return FORMATS[prop.format].error;
|
|
244
|
+
return null;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
// Whether value is an answer to field: a value of its type that meets
|
|
248
|
+
// every constraint the field names.
|
|
249
|
+
function conforms(field, value) {
|
|
250
|
+
if (isAbsent(value)) return false;
|
|
251
|
+
if (field.choices) return field.choices.indexOf(value) !== -1;
|
|
252
|
+
if (field.type === "integer") {
|
|
253
|
+
if (!Number.isInteger(value)) return false;
|
|
254
|
+
} else if (field.type === "number") {
|
|
255
|
+
if (typeof value !== "number" || !Number.isFinite(value)) return false;
|
|
256
|
+
} else if (typeof value !== "string") {
|
|
257
|
+
return false;
|
|
258
|
+
}
|
|
259
|
+
return constraintError(field, value) === null;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
// The text a field's control shows for value; "" for none.
|
|
263
|
+
function controlText(field, value) {
|
|
264
|
+
return conforms(field, value) ? String(value) : "";
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
// The text a field's control starts with: the schema's default when it is
|
|
268
|
+
// a value of the field's type, else none. Nothing is preselected that the
|
|
269
|
+
// operator would not see and could not change.
|
|
270
|
+
function initialControlText(field) {
|
|
271
|
+
return controlText(field, field.prop.default);
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
// How a choice reads on its control: an enum value by its enumNames entry
|
|
275
|
+
// when the schema gives one.
|
|
276
|
+
function choiceLabel(field, choice) {
|
|
277
|
+
if (field.type === "boolean") return choice ? "Yes" : "No";
|
|
278
|
+
var names = field.prop.enumNames;
|
|
279
|
+
var at = field.choices ? field.choices.indexOf(choice) : -1;
|
|
280
|
+
if (Array.isArray(names) && at !== -1 && typeof names[at] === "string") return names[at];
|
|
281
|
+
return String(choice);
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
// A control's text read as its field's value: {absent: true} when nothing
|
|
285
|
+
// was given, {error} when the text is not a value of the type or misses a
|
|
286
|
+
// constraint, else {value}.
|
|
287
|
+
function readControl(field, text) {
|
|
288
|
+
var raw = text == null ? "" : String(text);
|
|
289
|
+
if (field.choices) {
|
|
290
|
+
if (raw === "") return { absent: true };
|
|
291
|
+
for (var i = 0; i < field.choices.length; i++) {
|
|
292
|
+
if (String(field.choices[i]) === raw) return { value: field.choices[i] };
|
|
293
|
+
}
|
|
294
|
+
return { error: "is not one of the choices" };
|
|
295
|
+
}
|
|
296
|
+
var value = raw;
|
|
297
|
+
if (field.type === "integer" || field.type === "number") {
|
|
298
|
+
if (raw.trim() === "") return { absent: true };
|
|
299
|
+
value = Number(raw);
|
|
300
|
+
if (!Number.isFinite(value)) return { error: "must be a number" };
|
|
301
|
+
if (field.type === "integer" && !Number.isInteger(value)) return { error: "must be a whole number" };
|
|
302
|
+
} else if (raw === "") {
|
|
303
|
+
return { absent: true };
|
|
304
|
+
}
|
|
305
|
+
var error = constraintError(field, value);
|
|
306
|
+
return error ? { error: error } : { value: value };
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
// The answer a form's controls stand for, and what keeps it from being
|
|
310
|
+
// sent. textOf(name) is the text of that field's control. A field left
|
|
311
|
+
// empty is absent from the content, never "", 0 or false.
|
|
312
|
+
function contentFromControls(schema, textOf) {
|
|
313
|
+
var content = {};
|
|
314
|
+
var errors = [];
|
|
315
|
+
schemaFields(schema).forEach(function (field) {
|
|
316
|
+
var got = readControl(field, textOf(field.name));
|
|
317
|
+
if (got.error) errors.push(field.name + " " + got.error);
|
|
318
|
+
else if (got.absent) { if (field.required) errors.push(field.name + " is required"); }
|
|
319
|
+
else put(content, field.name, got.value);
|
|
320
|
+
});
|
|
321
|
+
return { content: content, errors: errors };
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
// Submitted content held to the requested schema: only its fields, each
|
|
325
|
+
// only with a value that answers it. A value that does not is dropped,
|
|
326
|
+
// never coerced; a required field left without a value makes the answer
|
|
327
|
+
// unusable (errors), so an incomplete form is never passed on as accepted.
|
|
328
|
+
function contentForSchema(schema, submitted) {
|
|
329
|
+
var given = isPlainObject(submitted) ? submitted : {};
|
|
330
|
+
var content = {};
|
|
331
|
+
var errors = [];
|
|
332
|
+
schemaFields(schema).forEach(function (field) {
|
|
333
|
+
var value = Object.prototype.hasOwnProperty.call(given, field.name) ? given[field.name] : undefined;
|
|
334
|
+
if (conforms(field, value)) put(content, field.name, value);
|
|
335
|
+
else if (field.required) errors.push(field.name + " is required");
|
|
336
|
+
});
|
|
337
|
+
return { content: content, errors: errors };
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
export {
|
|
341
|
+
MAX_ANSWER_CHARS, requestMode, isOpenableUrl, schemaProblem, lengthLimit, schemaFields, conforms, controlText,
|
|
342
|
+
initialControlText, choiceLabel, readControl, contentFromControls, contentForSchema,
|
|
343
|
+
};
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
// MCP elicitation card: a server asks for form input (form mode) or for
|
|
2
|
+
// approval to open a URL (url mode). The shell (prompts.js, prompt-card.js)
|
|
3
|
+
// owns its state.
|
|
4
|
+
//
|
|
5
|
+
// What the form offers and submits is the shared codec's
|
|
6
|
+
// (./elicitation-codec.js, which the server holds answers to): a field left
|
|
7
|
+
// empty is absent (never "", 0 or false), a typed field takes only values of
|
|
8
|
+
// its type, a required field must be filled before Submit sends, and a URL
|
|
9
|
+
// request is approved only when its URL is a web page. A form whose schema
|
|
10
|
+
// is outside the subset the codec supports is not drawn at all: the card
|
|
11
|
+
// says why and can only be declined.
|
|
12
|
+
|
|
13
|
+
import { escapeHtml } from '../utils.js';
|
|
14
|
+
import { iconHtml } from '../icons.js';
|
|
15
|
+
import {
|
|
16
|
+
requestMode, isOpenableUrl, schemaProblem, lengthLimit, schemaFields, initialControlText, choiceLabel,
|
|
17
|
+
contentFromControls,
|
|
18
|
+
} from './elicitation-codec.js';
|
|
19
|
+
|
|
20
|
+
var FIELD_STYLE = "padding: 4px 8px; border-radius: 4px; border: 1px solid var(--border); background: var(--input-bg); color: var(--text-primary); font-size: 13px;";
|
|
21
|
+
var ERROR_CLASS = "elicitation-error";
|
|
22
|
+
|
|
23
|
+
function drawField(field) {
|
|
24
|
+
var wrapper = document.createElement("div");
|
|
25
|
+
wrapper.style.cssText = "display: flex; flex-direction: column; gap: 2px;";
|
|
26
|
+
var label = document.createElement("label");
|
|
27
|
+
label.style.cssText = "font-size: 12px; font-weight: 500; color: var(--text-secondary);";
|
|
28
|
+
label.textContent = field.name + (field.required ? " *" : "");
|
|
29
|
+
if (field.prop.description) label.title = field.prop.description;
|
|
30
|
+
|
|
31
|
+
var input;
|
|
32
|
+
if (field.choices) {
|
|
33
|
+
// A choice starts unmade unless the schema names a default: an answer
|
|
34
|
+
// the operator did not pick is never sent as theirs.
|
|
35
|
+
input = document.createElement("select");
|
|
36
|
+
input.style.cssText = FIELD_STYLE;
|
|
37
|
+
var none = document.createElement("option");
|
|
38
|
+
none.value = "";
|
|
39
|
+
none.textContent = "";
|
|
40
|
+
input.appendChild(none);
|
|
41
|
+
field.choices.forEach(function (choice) {
|
|
42
|
+
var opt = document.createElement("option");
|
|
43
|
+
opt.value = String(choice);
|
|
44
|
+
opt.textContent = choiceLabel(field, choice);
|
|
45
|
+
input.appendChild(opt);
|
|
46
|
+
});
|
|
47
|
+
} else {
|
|
48
|
+
var numeric = field.type === "number" || field.type === "integer";
|
|
49
|
+
input = document.createElement("input");
|
|
50
|
+
input.type = numeric ? "number" : "text";
|
|
51
|
+
if (numeric) input.step = field.type === "integer" ? "1" : "any";
|
|
52
|
+
else input.maxLength = lengthLimit(field.prop);
|
|
53
|
+
input.placeholder = field.prop.description || field.name;
|
|
54
|
+
input.style.cssText = FIELD_STYLE;
|
|
55
|
+
}
|
|
56
|
+
input.value = initialControlText(field);
|
|
57
|
+
input.dataset.propName = field.name;
|
|
58
|
+
if (field.required) input.dataset.required = "true";
|
|
59
|
+
wrapper.appendChild(label);
|
|
60
|
+
wrapper.appendChild(input);
|
|
61
|
+
return wrapper;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function controlTexts(container) {
|
|
65
|
+
var byName = Object.create(null);
|
|
66
|
+
var inputs = container.querySelectorAll("[data-prop-name]");
|
|
67
|
+
for (var i = 0; i < inputs.length; i++) byName[inputs[i].dataset.propName] = inputs[i].value;
|
|
68
|
+
return function (name) { return byName[name]; };
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function showErrors(container, errors) {
|
|
72
|
+
var old = container.querySelectorAll("." + ERROR_CLASS);
|
|
73
|
+
for (var i = 0; i < old.length; i++) old[i].remove();
|
|
74
|
+
if (!errors.length) return;
|
|
75
|
+
var note = document.createElement("div");
|
|
76
|
+
note.className = ERROR_CLASS + " permission-note-error";
|
|
77
|
+
note.textContent = errors.join("; ");
|
|
78
|
+
container.appendChild(note);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function urlNote(url) {
|
|
82
|
+
if (!url) return "No address was given, so there is nothing to open.";
|
|
83
|
+
if (!isOpenableUrl(url)) return "Not a web address, so it cannot be opened: " + url;
|
|
84
|
+
return "Opens: " + url;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export default {
|
|
88
|
+
kind: "elicitation",
|
|
89
|
+
|
|
90
|
+
draw: function (fields, requestId, host) {
|
|
91
|
+
var container = document.createElement("div");
|
|
92
|
+
container.className = "permission-container elicitation-container";
|
|
93
|
+
container.dataset.requestId = requestId;
|
|
94
|
+
|
|
95
|
+
var header = document.createElement("div");
|
|
96
|
+
header.className = "permission-header";
|
|
97
|
+
header.innerHTML =
|
|
98
|
+
'<span class="permission-icon">' + iconHtml("key") + '</span>' +
|
|
99
|
+
'<span class="permission-title">' + escapeHtml(fields.serverName || "MCP Server") + ' requests input</span>';
|
|
100
|
+
|
|
101
|
+
var body = document.createElement("div");
|
|
102
|
+
body.className = "permission-body";
|
|
103
|
+
if (fields.message) {
|
|
104
|
+
var messageEl = document.createElement("div");
|
|
105
|
+
messageEl.className = "permission-reason";
|
|
106
|
+
messageEl.textContent = fields.message;
|
|
107
|
+
body.appendChild(messageEl);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
var isUrl = requestMode(fields) === "url";
|
|
111
|
+
var schema = fields.requestedSchema || null;
|
|
112
|
+
var unsupported = isUrl ? null : schemaProblem(schema);
|
|
113
|
+
if (isUrl) {
|
|
114
|
+
var urlInfo = document.createElement("div");
|
|
115
|
+
urlInfo.className = "elicitation-url-info";
|
|
116
|
+
urlInfo.style.cssText = "margin-top: 8px; font-size: 12px; color: var(--text-muted);";
|
|
117
|
+
urlInfo.textContent = urlNote(fields.url);
|
|
118
|
+
body.appendChild(urlInfo);
|
|
119
|
+
} else if (unsupported) {
|
|
120
|
+
var refusal = document.createElement("div");
|
|
121
|
+
refusal.className = "elicitation-unsupported permission-note-error";
|
|
122
|
+
refusal.textContent = "This form cannot be shown: " + unsupported + ". It can only be declined.";
|
|
123
|
+
body.appendChild(refusal);
|
|
124
|
+
} else {
|
|
125
|
+
var formFields = schemaFields(schema);
|
|
126
|
+
if (formFields.length) {
|
|
127
|
+
var formEl = document.createElement("div");
|
|
128
|
+
formEl.className = "elicitation-form";
|
|
129
|
+
formEl.style.cssText = "margin-top: 8px; display: flex; flex-direction: column; gap: 8px;";
|
|
130
|
+
formFields.forEach(function (field) { formEl.appendChild(drawField(field)); });
|
|
131
|
+
body.appendChild(formEl);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
var actions = document.createElement("div");
|
|
136
|
+
actions.className = "permission-actions";
|
|
137
|
+
var acceptBtn = document.createElement("button");
|
|
138
|
+
acceptBtn.className = "permission-btn permission-allow";
|
|
139
|
+
var openable = isUrl && isOpenableUrl(fields.url);
|
|
140
|
+
acceptBtn.textContent = isUrl ? "Open & Approve" : "Submit";
|
|
141
|
+
// A URL that is not a web page is never opened, and a form outside the
|
|
142
|
+
// supported schema is never drawn, so neither can be approved.
|
|
143
|
+
if ((isUrl && !openable) || unsupported) acceptBtn.disabled = true;
|
|
144
|
+
acceptBtn.addEventListener("click", function () {
|
|
145
|
+
if (unsupported) return;
|
|
146
|
+
if (isUrl) {
|
|
147
|
+
if (!openable) return;
|
|
148
|
+
window.open(fields.url, "_blank", "noopener,noreferrer");
|
|
149
|
+
host.respond(container, { action: "accept", content: {} });
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
var form = contentFromControls(schema, controlTexts(container));
|
|
153
|
+
showErrors(container, form.errors);
|
|
154
|
+
if (form.errors.length) return;
|
|
155
|
+
host.respond(container, { action: "accept", content: form.content });
|
|
156
|
+
});
|
|
157
|
+
var denyBtn = document.createElement("button");
|
|
158
|
+
denyBtn.className = "permission-btn permission-deny";
|
|
159
|
+
denyBtn.textContent = "Deny";
|
|
160
|
+
denyBtn.addEventListener("click", function () {
|
|
161
|
+
host.respond(container, { action: "reject" });
|
|
162
|
+
});
|
|
163
|
+
actions.appendChild(acceptBtn);
|
|
164
|
+
actions.appendChild(denyBtn);
|
|
165
|
+
|
|
166
|
+
container.appendChild(header);
|
|
167
|
+
container.appendChild(body);
|
|
168
|
+
container.appendChild(actions);
|
|
169
|
+
return container;
|
|
170
|
+
},
|
|
171
|
+
|
|
172
|
+
outcome: function (state) {
|
|
173
|
+
if (state.action === "accept") return { text: "Submitted", tone: "allowed" };
|
|
174
|
+
return { text: "Denied", tone: "denied" };
|
|
175
|
+
},
|
|
176
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// Client renderers for every operator-prompt kind. A renderer draws the
|
|
2
|
+
// card body and its answer controls and names its outcome labels; the
|
|
3
|
+
// lifecycle (pending, sending, settled, server state) is the shell's
|
|
4
|
+
// (prompts.js, prompt-card.js).
|
|
5
|
+
|
|
6
|
+
import permission from './permission.js';
|
|
7
|
+
import plan from './plan.js';
|
|
8
|
+
import askUser from './ask-user.js';
|
|
9
|
+
import elicitation from './elicitation.js';
|
|
10
|
+
|
|
11
|
+
export var PROMPT_KINDS = {
|
|
12
|
+
permission: permission,
|
|
13
|
+
plan: plan,
|
|
14
|
+
ask_user: askUser,
|
|
15
|
+
elicitation: elicitation,
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export { askWording } from './permission.js';
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// own-key.js - keyed lookups on names that arrive from outside: a
|
|
2
|
+
// requestId, a decision, a cancel reason, a kind. A plain object answers a
|
|
3
|
+
// name it only inherits (constructor, toString, __proto__, ...) as if it
|
|
4
|
+
// held it, so prompt cards and the server's prompt path read every such map
|
|
5
|
+
// through ownValue() and write one through putOwn().
|
|
6
|
+
//
|
|
7
|
+
// This file is the only copy: the server imports it as is
|
|
8
|
+
// (lib/prompt-kinds/codecs.js).
|
|
9
|
+
|
|
10
|
+
var hasOwn = Object.prototype.hasOwnProperty;
|
|
11
|
+
|
|
12
|
+
// Whether map holds key itself. Only a string names an entry: any other
|
|
13
|
+
// value would be coerced, and an object can refuse coercion by throwing.
|
|
14
|
+
function hasOwnKey(map, key) {
|
|
15
|
+
return typeof key === "string" && map !== null && map !== undefined && hasOwn.call(map, key);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// map[key] when map holds key itself, else undefined.
|
|
19
|
+
function ownValue(map, key) {
|
|
20
|
+
return hasOwnKey(map, key) ? map[key] : undefined;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// Defined, not assigned, so a key named "__proto__" is an entry rather than
|
|
24
|
+
// a change of map's prototype.
|
|
25
|
+
function putOwn(map, key, value) {
|
|
26
|
+
Object.defineProperty(map, key, { value: value, enumerable: true, writable: true, configurable: true });
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export { hasOwnKey, ownValue, putOwn };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// permission-choices.js - which answers a tool-permission ask offers, and in
|
|
2
|
+
// what order. The card (permission.js) and the notification banner
|
|
3
|
+
// (../prompt-banner.js) both read it, so they cannot offer different answers
|
|
4
|
+
// to one ask.
|
|
5
|
+
//
|
|
6
|
+
// The Claude Agent SDK may attach presentation hints to an ask:
|
|
7
|
+
// suppressAlwaysAllowRule no persistent "allow for session" choice;
|
|
8
|
+
// defaultToNo the ask opens on its decline choice, so a stray
|
|
9
|
+
// keystroke or tap cannot approve it.
|
|
10
|
+
// The server refuses an Allow-for-session answer to a suppressed ask whatever
|
|
11
|
+
// a client sends (lib/prompt-kinds/permission.js); omitting the choice here is
|
|
12
|
+
// the presentation of that rule, not its enforcement.
|
|
13
|
+
//
|
|
14
|
+
// Deliberately free of imports so the banner can load it without the rest of
|
|
15
|
+
// the frontend module graph.
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @param {object} [hints] - the ask's request fields.
|
|
19
|
+
* @returns {string[]} decisions in the order they are shown; the first is the
|
|
20
|
+
* default choice when the ask is defaultToNo.
|
|
21
|
+
*/
|
|
22
|
+
export function permissionChoices(hints) {
|
|
23
|
+
var h = hints || {};
|
|
24
|
+
var approve = h.suppressAlwaysAllowRule === true ? ["allow"] : ["allow", "allow_always"];
|
|
25
|
+
return h.defaultToNo === true ? ["deny"].concat(approve) : approve.concat(["deny"]);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** Whether an ask must open on its decline choice. */
|
|
29
|
+
export function opensOnNo(hints) {
|
|
30
|
+
return !!hints && hints.defaultToNo === true;
|
|
31
|
+
}
|