@volter/supercode-frontend-vscode 0.1.18 → 0.1.20

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/NOTICE.md CHANGED
@@ -1,6 +1,10 @@
1
1
  # Third-party notice
2
2
 
3
- This optional frontend has **no runtime npm dependency**. It builds against `@types/vscode`
3
+ This optional frontend needs **no runtime npm installation**. Its form-schema validator
4
+ bundles Ajv 8.17.1, ajv-formats 3.0.1 and their dependencies; their license texts ship in
5
+ `dist/request-schema.LICENSE.txt`. esbuild bundles that one module during the build.
6
+ The validator does not fetch external schema references or change answer values.
7
+ It builds against `@types/vscode`
4
8
  (Copyright (c) Microsoft Corporation, MIT) as an exact devDependency for types only; `vscode` itself
5
9
  is supplied by the editor at runtime and is never bundled or redistributed here.
6
10
 
package/dist/extension.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { adaptRequestSchema, fieldControl, objectValue, requestValidator } from './request-schema.js';
1
2
  import { resolveSessionBinding } from './bindings.js';
2
3
  import { withTextContext } from './context.js';
3
4
  import { randomUUID } from 'node:crypto';
@@ -748,16 +749,25 @@ export async function activate(context) {
748
749
  return;
749
750
  }
750
751
  await controls.refresh();
751
- // The host supplies startable agents, including installation/authentication checks.
752
- // An absent choice is not permission to guess a harness or start another runtime.
753
- const choices = controls.state.harnesses;
752
+ // Sign-in choices stay visible alongside agents that can be explicitly started.
753
+ const login = controls.state.setup?.actions.filter(action => action.kind === 'login') ?? [];
754
+ const choices = [
755
+ ...login.map(action => ({ label: action.name, id: action.harness, description: 'Sign in…', login: true, autoStart: false })),
756
+ ...controls.state.harnesses.filter(h => !login.some(action => action.harness === h.id))
757
+ .map(h => ({ label: h.name, id: h.id, description: h.description, login: false, autoStart: h.autoStart === true })),
758
+ ];
754
759
  if (!choices.length) {
755
760
  await revealSetup();
756
761
  return;
757
762
  }
758
- const harness = choices.length === 1 ? choices[0] : await vscode.window.showQuickPick(choices.map(h => ({ label: h.name, id: h.id })), { title: 'New chat · Agent', placeHolder: 'Choose your coding agent. Model and reasoning use its defaults.' });
763
+ // A sole sign-in option still requires a deliberate click before opening its terminal.
764
+ const harness = choices.length === 1 && choices[0].autoStart ? choices[0] : await vscode.window.showQuickPick(choices, { title: 'New chat · Agent', placeHolder: 'Choose your coding agent. Model and reasoning use its defaults.' });
759
765
  if (!harness)
760
766
  return;
767
+ if (harness.login) {
768
+ await vscode.commands.executeCommand('supercode.frontend.setup', 'login', harness.id);
769
+ return;
770
+ }
761
771
  await enqueueSelection({ harness: harness.id, model: '', effort: '' });
762
772
  }));
763
773
  context.subscriptions.push(vscode.commands.registerCommand('supercode.frontend.configureModel', async (resource, sessionId) => {
@@ -874,9 +884,14 @@ export async function activate(context) {
874
884
  // and an elicitation's free-text content).
875
885
  const pending = pendingRequestOf(connection);
876
886
  if (pending) {
877
- const answer = typedAnswer(pending, request.prompt);
878
- await connection.session.respond(answer);
879
- stream.markdown(`_answered request #${pending.id}: ${opaqueText(answer, 256)}_`);
887
+ try {
888
+ const answer = typedAnswer(pending, request.prompt);
889
+ await connection.session.respond(answer);
890
+ stream.markdown(`_answered request #${pending.id}: ${opaqueText(answer, 256)}_`);
891
+ }
892
+ catch (error) {
893
+ stream.markdown(`Could not answer request #${pending.id}: ${opaqueText(String(error.message), 512)}`);
894
+ }
880
895
  return {};
881
896
  }
882
897
  if (request.prompt.trim().length === 0) {
@@ -971,17 +986,13 @@ export async function activate(context) {
971
986
  return;
972
987
  }
973
988
  let response = answer.response;
974
- if (answer.promptForContent) {
975
- const content = await vscode.window.showInputBox({
976
- title: 'Volter Harness runtime request',
977
- prompt: 'The runtime asked for a value; a button cannot carry one.',
978
- ignoreFocusOut: true,
979
- });
980
- if (content === undefined)
981
- return;
982
- response = { ...response, content };
983
- }
984
989
  try {
990
+ if (answer.promptForContent) {
991
+ const content = await requestContent(request);
992
+ if (content === undefined)
993
+ return;
994
+ response = { ...response, content };
995
+ }
985
996
  await connection.session.respond(response);
986
997
  void vscode.window.setStatusBarMessage(`Volter Harness: ${resolutionSentence(response, request, answer.requestId)}`, 4000);
987
998
  }
@@ -1495,3 +1506,155 @@ function registerSessions(context, frontends, participant, granted, handler, con
1495
1506
  },
1496
1507
  }, participant, { supportsInterruptions: true }));
1497
1508
  }
1509
+ /** Collect each question through the existing Chat answer button, preserving ids and secrets. */
1510
+ async function requestContent(request) {
1511
+ const payload = request.payload;
1512
+ if (Array.isArray(payload?.questions)) {
1513
+ const answers = Object.create(null);
1514
+ for (const value of payload.questions) {
1515
+ if (!value || typeof value !== 'object' || Array.isArray(value) || typeof value.id !== 'string')
1516
+ continue;
1517
+ const question = value;
1518
+ const options = Array.isArray(question.options) ? question.options.flatMap(option => {
1519
+ if (!option || typeof option !== 'object' || Array.isArray(option) || typeof option.label !== 'string')
1520
+ return [];
1521
+ return [{ label: option.label, description: typeof option.description === 'string' ? option.description : undefined, custom: false }];
1522
+ }) : [];
1523
+ let answer;
1524
+ if (options.length) {
1525
+ if (question.isOther === true)
1526
+ options.push({ label: 'Write an answer…', description: undefined, custom: true });
1527
+ const chosen = await vscode.window.showQuickPick(options, { title: String(question.header ?? 'Codex question'), placeHolder: String(question.question ?? ''), ignoreFocusOut: true });
1528
+ if (!chosen)
1529
+ return undefined;
1530
+ if (!chosen.custom)
1531
+ answer = chosen.label;
1532
+ }
1533
+ if (answer === undefined) {
1534
+ answer = await vscode.window.showInputBox({ title: String(question.header ?? 'Codex question'), prompt: String(question.question ?? ''), password: question.isSecret === true, ignoreFocusOut: true });
1535
+ }
1536
+ if (answer === undefined)
1537
+ return undefined;
1538
+ answers[value.id] = answer;
1539
+ }
1540
+ return answers;
1541
+ }
1542
+ const schema = payload?.requested_schema;
1543
+ if (schema === undefined || schema === null) {
1544
+ return vscode.window.showInputBox({ title: 'Runtime request', prompt: 'Enter your answer.', ignoreFocusOut: true });
1545
+ }
1546
+ const showSchema = async () => {
1547
+ const document = await vscode.workspace.openTextDocument({ language: 'json', content: JSON.stringify(schema, null, 2) });
1548
+ await vscode.window.showTextDocument(document, { preview: true, preserveFocus: true });
1549
+ };
1550
+ const adaptedSchema = adaptRequestSchema(schema, payload?.mode);
1551
+ let validate;
1552
+ const structuredFallback = async (initial) => {
1553
+ await showSchema();
1554
+ const typed = await vscode.window.showInputBox({ title: 'Runtime request', prompt: 'Enter an answer matching the displayed JSON schema.', value: initial === undefined ? undefined : JSON.stringify(initial), ignoreFocusOut: true, validateInput: value => {
1555
+ try {
1556
+ const parsed = JSON.parse(value);
1557
+ return objectValue(parsed) ? validate(parsed) : 'Enter a JSON object';
1558
+ }
1559
+ catch {
1560
+ return 'Enter valid JSON';
1561
+ }
1562
+ } });
1563
+ return typed === undefined ? undefined : JSON.parse(typed);
1564
+ };
1565
+ try {
1566
+ validate = requestValidator(adaptedSchema);
1567
+ }
1568
+ catch (error) {
1569
+ // Keep the structured-input path available with the original schema in
1570
+ // view. Never accept an answer whose constraints cannot be validated.
1571
+ const message = `Cannot validate this request schema: ${String(error.message)}`;
1572
+ validate = () => message;
1573
+ return structuredFallback();
1574
+ }
1575
+ const form = objectValue(adaptedSchema);
1576
+ const properties = objectValue(form?.properties);
1577
+ // Cross-field conditions, refs and nested schemas use the complete validated
1578
+ // JSON fallback rather than controls that would erase their semantics.
1579
+ const simpleForm = form?.type === 'object' && properties && Object.keys(form).every(key => ['$schema', 'type', 'title', 'description', 'properties', 'required', 'additionalProperties'].includes(key));
1580
+ if (!simpleForm || !properties)
1581
+ return structuredFallback();
1582
+ const fields = Object.entries(properties).map(([name, spec]) => ({ name, spec: objectValue(spec), control: objectValue(spec) ? fieldControl(objectValue(spec)) : undefined }));
1583
+ if (fields.some(field => !field.spec || !field.control))
1584
+ return structuredFallback();
1585
+ const content = Object.create(null);
1586
+ const required = Array.isArray(form.required) ? form.required : [];
1587
+ for (const { name, spec, control } of fields) {
1588
+ const field = spec;
1589
+ const title = typeof field.title === 'string' ? field.title : name;
1590
+ if (!required.includes(name)) {
1591
+ const choice = await vscode.window.showQuickPick(['Provide a value', 'Omit this field'], { title: `${title} (optional)`, ignoreFocusOut: true });
1592
+ if (!choice)
1593
+ return undefined;
1594
+ if (choice === 'Omit this field')
1595
+ continue;
1596
+ }
1597
+ let validateField;
1598
+ try {
1599
+ validateField = requestValidator(field);
1600
+ }
1601
+ catch {
1602
+ // A field can require the root's dialect or references. The full-form
1603
+ // validator already compiled, so the JSON fallback retains them.
1604
+ return structuredFallback(content);
1605
+ }
1606
+ if (control.kind === 'select') {
1607
+ const select = control;
1608
+ while (true) {
1609
+ const options = select.choices.map(choice => ({ ...choice }));
1610
+ let answer;
1611
+ if (select.multiple) {
1612
+ const selected = await vscode.window.showQuickPick(options, { title, placeHolder: typeof field.description === 'string' ? field.description : undefined, canPickMany: true, ignoreFocusOut: true });
1613
+ if (!selected)
1614
+ return undefined;
1615
+ answer = selected.map(choice => choice.value);
1616
+ }
1617
+ else {
1618
+ const selected = await vscode.window.showQuickPick(options, { title, placeHolder: typeof field.description === 'string' ? field.description : undefined, ignoreFocusOut: true });
1619
+ if (!selected)
1620
+ return undefined;
1621
+ answer = selected.value;
1622
+ }
1623
+ const error = validateField(answer);
1624
+ if (error) {
1625
+ await vscode.window.showWarningMessage(error);
1626
+ continue;
1627
+ }
1628
+ content[name] = answer;
1629
+ break;
1630
+ }
1631
+ }
1632
+ else {
1633
+ const text = control;
1634
+ const parse = (value) => {
1635
+ if (text.type === 'string')
1636
+ return value;
1637
+ if (!value.trim() || !Number.isFinite(Number(value)))
1638
+ throw new Error('Enter a valid number');
1639
+ return Number(value);
1640
+ };
1641
+ const typed = await vscode.window.showInputBox({ title, prompt: typeof field.description === 'string' ? field.description : undefined, ignoreFocusOut: true, validateInput: value => {
1642
+ try {
1643
+ return validateField(parse(value));
1644
+ }
1645
+ catch (error) {
1646
+ return error.message;
1647
+ }
1648
+ } });
1649
+ if (typed === undefined)
1650
+ return undefined;
1651
+ content[name] = parse(typed);
1652
+ }
1653
+ }
1654
+ const error = validate(content);
1655
+ if (error) {
1656
+ await vscode.window.showWarningMessage(error);
1657
+ return structuredFallback(content);
1658
+ }
1659
+ return content;
1660
+ }
@@ -9,6 +9,7 @@ export interface ChatChoice {
9
9
  id: string;
10
10
  name: string;
11
11
  description?: string;
12
+ autoStart?: boolean;
12
13
  }
13
14
  export interface ChatStarterPrompt {
14
15
  label: string;
@@ -0,0 +1,157 @@
1
+ ajv
2
+
3
+ The MIT License (MIT)
4
+
5
+ Copyright (c) 2015-2021 Evgeny Poberezkin
6
+
7
+ Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ of this software and associated documentation files (the "Software"), to deal
9
+ in the Software without restriction, including without limitation the rights
10
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ copies of the Software, and to permit persons to whom the Software is
12
+ furnished to do so, subject to the following conditions:
13
+
14
+ The above copyright notice and this permission notice shall be included in all
15
+ copies or substantial portions of the Software.
16
+
17
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ SOFTWARE.
24
+
25
+
26
+
27
+ ajv-formats
28
+
29
+ MIT License
30
+
31
+ Copyright (c) 2020 Evgeny Poberezkin
32
+
33
+ Permission is hereby granted, free of charge, to any person obtaining a copy
34
+ of this software and associated documentation files (the "Software"), to deal
35
+ in the Software without restriction, including without limitation the rights
36
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
37
+ copies of the Software, and to permit persons to whom the Software is
38
+ furnished to do so, subject to the following conditions:
39
+
40
+ The above copyright notice and this permission notice shall be included in all
41
+ copies or substantial portions of the Software.
42
+
43
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
44
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
45
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
46
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
47
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
48
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
49
+ SOFTWARE.
50
+
51
+
52
+ fast-deep-equal
53
+
54
+ MIT License
55
+
56
+ Copyright (c) 2017 Evgeny Poberezkin
57
+
58
+ Permission is hereby granted, free of charge, to any person obtaining a copy
59
+ of this software and associated documentation files (the "Software"), to deal
60
+ in the Software without restriction, including without limitation the rights
61
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
62
+ copies of the Software, and to permit persons to whom the Software is
63
+ furnished to do so, subject to the following conditions:
64
+
65
+ The above copyright notice and this permission notice shall be included in all
66
+ copies or substantial portions of the Software.
67
+
68
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
69
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
70
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
71
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
72
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
73
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
74
+ SOFTWARE.
75
+
76
+
77
+ fast-uri
78
+
79
+ Copyright (c) 2011-2021, Gary Court until https://github.com/garycourt/uri-js/commit/a1acf730b4bba3f1097c9f52e7d9d3aba8cdcaae
80
+ Copyright (c) 2021-present The Fastify team <https://github.com/fastify/fastify#team>
81
+ All rights reserved.
82
+
83
+ Redistribution and use in source and binary forms, with or without
84
+ modification, are permitted provided that the following conditions are met:
85
+ * Redistributions of source code must retain the above copyright
86
+ notice, this list of conditions and the following disclaimer.
87
+ * Redistributions in binary form must reproduce the above copyright
88
+ notice, this list of conditions and the following disclaimer in the
89
+ documentation and/or other materials provided with the distribution.
90
+ * The names of any contributors may not be used to endorse or promote
91
+ products derived from this software without specific prior written
92
+ permission.
93
+
94
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
95
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
96
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
97
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS AND CONTRIBUTORS BE LIABLE FOR ANY
98
+ DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
99
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
100
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
101
+ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
102
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
103
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
104
+
105
+ * * *
106
+
107
+ The complete list of contributors can be found at:
108
+ - https://github.com/garycourt/uri-js/graphs/contributors
109
+
110
+ json-schema-traverse
111
+
112
+ MIT License
113
+
114
+ Copyright (c) 2017 Evgeny Poberezkin
115
+
116
+ Permission is hereby granted, free of charge, to any person obtaining a copy
117
+ of this software and associated documentation files (the "Software"), to deal
118
+ in the Software without restriction, including without limitation the rights
119
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
120
+ copies of the Software, and to permit persons to whom the Software is
121
+ furnished to do so, subject to the following conditions:
122
+
123
+ The above copyright notice and this permission notice shall be included in all
124
+ copies or substantial portions of the Software.
125
+
126
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
127
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
128
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
129
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
130
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
131
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
132
+ SOFTWARE.
133
+
134
+
135
+ require-from-string
136
+
137
+ The MIT License (MIT)
138
+
139
+ Copyright (c) Vsevolod Strukchinsky <floatdrop@gmail.com> (github.com/floatdrop)
140
+
141
+ Permission is hereby granted, free of charge, to any person obtaining a copy
142
+ of this software and associated documentation files (the "Software"), to deal
143
+ in the Software without restriction, including without limitation the rights
144
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
145
+ copies of the Software, and to permit persons to whom the Software is
146
+ furnished to do so, subject to the following conditions:
147
+
148
+ The above copyright notice and this permission notice shall be included in
149
+ all copies or substantial portions of the Software.
150
+
151
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
152
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
153
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
154
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
155
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
156
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
157
+ THE SOFTWARE.
@@ -0,0 +1,22 @@
1
+ import type { FrontendRequest, JsonValue } from '../vendor/supercode-frontend/generated.mjs';
2
+ export declare function objectValue(value: JsonValue | undefined): Record<string, JsonValue> | undefined;
3
+ /** Adapt only Codex's typed MCP form schema. Other modes carry arbitrary JSON Schema. */
4
+ export declare function adaptRequestSchema(schema: JsonValue, mode: JsonValue | undefined): JsonValue;
5
+ /** Validate without changing answers, filling defaults, or fetching external refs. */
6
+ export declare function requestValidator(schema: JsonValue): (value: JsonValue) => string | undefined;
7
+ /** Plain-text and single-question responses retain their exact text. */
8
+ export declare function typedRequestContent(request: FrontendRequest, reply: string): JsonValue;
9
+ export interface FieldChoice {
10
+ label: string;
11
+ value: JsonValue;
12
+ }
13
+ export type FieldControl = {
14
+ kind: 'select';
15
+ choices: FieldChoice[];
16
+ multiple: boolean;
17
+ } | {
18
+ kind: 'text';
19
+ type: 'string' | 'number' | 'integer';
20
+ };
21
+ /** Only known shapes get native controls; everything else keeps its full schema. */
22
+ export declare function fieldControl(field: Record<string, JsonValue>): FieldControl | undefined;