100milionseek 0.1.1 → 0.1.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "100milionseek",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "main": "./opencode.mjs",
package/src/index.mjs CHANGED
@@ -157,6 +157,23 @@ export async function HundredMilionSeekPlugin(input, options = {}) {
157
157
  type: "api",
158
158
  label: "100milionseek API key",
159
159
  placeholder: "hms-…",
160
+ // The key is collected through a prompt, so magpie hands it to
161
+ // `authorize` as `inputs.key`. Without `prompts`, older hosts draw
162
+ // their own key box and call `authorize` with no key at all, and
163
+ // newer ones have nowhere to ask for one.
164
+ prompts: [
165
+ {
166
+ type: "password",
167
+ key: "key",
168
+ message: "100milionseek API key",
169
+ placeholder: "hms-…",
170
+ validate: (value) => {
171
+ if (typeof value !== "string" || !value.trim()) return "An API key is required.";
172
+ if (/[\r\n]/.test(value)) return "The key must not contain line breaks.";
173
+ return undefined;
174
+ },
175
+ },
176
+ ],
160
177
  // Checked before it is stored, so a typo fails at sign-in instead of
161
178
  // as a 401 in the middle of a chat. A network failure is not the
162
179
  // key's fault and must not refuse it.
@@ -66,6 +66,21 @@ test("auth names the provider, its five slots and its icon", async () => {
66
66
  assert.equal(plugin.auth.checkin, undefined);
67
67
  });
68
68
 
69
+ test("the key is asked for through a prompt, so magpie hands it to authorize", async () => {
70
+ // Without `prompts` the host draws its own key box and calls authorize with
71
+ // no key, which is what produced "An API key is required" at sign-in.
72
+ const plugin = await HundredMilionSeekPlugin({}, { fetchImpl: async () => json({}) });
73
+ const [method] = plugin.auth.methods;
74
+ assert.ok(Array.isArray(method.prompts) && method.prompts.length >= 1);
75
+ const keyPrompt = method.prompts.find((p) => p.key === "key");
76
+ assert.ok(keyPrompt, "there is a prompt that submits `key`");
77
+ assert.equal(typeof keyPrompt.validate, "function");
78
+ // The prompt's own validation rejects an empty or multi-line key.
79
+ assert.match(keyPrompt.validate(" "), /required/i);
80
+ assert.match(keyPrompt.validate("hms-a\r\nb"), /line break/i);
81
+ assert.equal(keyPrompt.validate("hms-ok"), undefined);
82
+ });
83
+
69
84
  test("the sign-in check accepts a working key and remembers the allowance it saw", async () => {
70
85
  const { calls, fetchImpl } = recorder(json({ object: "list", data: [] }, 200, QUOTA));
71
86
  const plugin = await HundredMilionSeekPlugin({}, { fetchImpl });