openany-cli-dev 0.1.6 → 0.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -63,12 +63,23 @@ openany-dev run --id API_ID --query '{"limit":"10"}' -j
63
63
 
64
64
  Use the API ID and parameters from the live catalog. `status` checks local configuration and reports `configured/missing` without testing network access or key validity. Configure a key before proceeding with authenticated discovery or inspection. Use `discover --public` when the user explicitly requests public catalog browsing only.
65
65
 
66
- `run --headers` accepts `Accept` and `Accept-Language` even when they are absent from the published inputs. Header names are case-insensitive. Published constraints still apply when these headers are declared; other unknown headers and reserved headers remain rejected.
66
+ `run --headers` accepts `Accept`, `Accept-Language`, and `x-openany-partner-id` even when they are absent from the published inputs. Header names are case-insensitive. Published constraints still apply when these headers are declared; other unknown headers and reserved headers remain rejected.
67
67
 
68
68
  ```bash
69
69
  openany-dev run --id API_ID --headers '{"Accept":"application/json;version=20230203","Accept-Language":"zh-CN"}' -j
70
+ openany-dev run --id API_ID --headers '{"x-openany-partner-id":"PARTNER_ID"}' -j
70
71
  ```
71
72
 
73
+ Save a default partner ID once to automatically include `x-openany-partner-id` on API and model gateway requests:
74
+
75
+ ```bash
76
+ openany config set partner-id PARTNER_ID
77
+ openany config get partner-id
78
+ openany config unset partner-id
79
+ ```
80
+
81
+ These local commands do not require an API key or access the network. The ID is stored in the existing restricted credentials file and survives later CLI invocations. Explicit `run --headers` values override the saved ID case-insensitively for that call; published API input constraints still apply. Backend requests do not receive the saved header. `config unset partner-id` removes the default, and `logout` clears it along with other local account configuration. Model calls use the saved default; `models run --headers` remains unsupported.
82
+
72
83
  Balance checks use `GET /api/v1/agent-api-account` with a Bearer API key. This works with both wallet and email account keys. `run` reads the API contract, validates parameters, checks the balance, and calls the gateway. `calls list/get` retrieves model, data, and tool API usage records for the current key and requires a backend version that includes this fix. Status filters accept only `--status success` or `--status failed`. Passing `--review-required` produces a local error.
73
84
 
74
85
  ## Retrieving asynchronous API results
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "openany-cli-dev",
3
- "version": "0.1.6",
3
+ "version": "0.1.7",
4
4
  "description": "OpenAny command-line client for internal dev testing",
5
5
  "type": "module",
6
6
  "engines": {
package/src/catalog.js CHANGED
@@ -144,7 +144,7 @@ export function prepareApiRequest(
144
144
  for (const [location, values] of Object.entries(groups))
145
145
  for (const name of Object.keys(values))
146
146
  if (
147
- !(location === "header" && /^(accept|accept-language)$/i.test(name)) &&
147
+ !(location === "header" && /^(accept|accept-language|x-openany-partner-id)$/i.test(name)) &&
148
148
  !definition.inputs.some(
149
149
  (f) =>
150
150
  f.location === location &&
@@ -276,10 +276,14 @@ export async function runApi(options, ctx) {
276
276
  const definition = unwrap(
277
277
  await ctx.http.backend(`/api/v1/agent-apis/${encodeURIComponent(id)}`),
278
278
  );
279
+ let headers = ctx.jsonOption("headers", {});
280
+ if (ctx.http.partnerId && isObject(headers) &&
281
+ !Object.keys(headers).some(name => name.toLowerCase() === "x-openany-partner-id"))
282
+ headers = { ...headers, "x-openany-partner-id": ctx.http.partnerId };
279
283
  const prepared = prepareApiRequest(definition, {
280
284
  path: ctx.jsonOption("path", {}),
281
285
  query: ctx.jsonOption("query", {}),
282
- headers: ctx.jsonOption("headers", {}),
286
+ headers,
283
287
  body: await ctx.input(),
284
288
  });
285
289
  const account = unwrap(
package/src/cli.js CHANGED
@@ -3,7 +3,7 @@ import packageInfo from "../package.json" with { type: "json" };
3
3
  import { tmpdir } from "node:os";
4
4
  import { join } from "node:path";
5
5
  import { readFile, writeFile, lstat, mkdtemp } from "node:fs/promises";
6
- import { ConfigStore, configurationStatus } from "./config.js";
6
+ import { ConfigStore, configurationStatus, runConfig } from "./config.js";
7
7
  import { CLIError, errorRecord, redact, requireValue } from "./errors.js";
8
8
  import { HttpClient, unwrap } from "./http.js";
9
9
  import { listQuery, runApi, formatMicroUsd } from "./catalog.js";
@@ -17,6 +17,9 @@ Model execution uses the OpenAny gateway with the path and query from curlExampl
17
17
  setup --api_key api_key --gui [-j] (native API key dialog)
18
18
  setup --wallet_connect wallet --gui [-j] (native wallet dialog)
19
19
  logout [-j] (back up and remove all local account configuration)
20
+ config set partner-id VALUE [-j] (save the default gateway partner ID)
21
+ config get partner-id [-j]
22
+ config unset partner-id [-j]
20
23
  status_check wallet|email|api_key|payment [-j]
21
24
  Legacy syntax (still supported):
22
25
  setup [--scenario call|wallet|email] (interactive terminal setup)
@@ -408,6 +411,7 @@ export async function runCommand(args, ctx) {
408
411
  return runSetup(ctx);
409
412
  }
410
413
  if (command === "status") return configurationStatus(store, options);
414
+ if (command === "config") return runConfig(args, ctx);
411
415
  if (
412
416
  command === "keys" &&
413
417
  !["remote", "create", "rotate", "revoke"].includes(args[1])
@@ -552,7 +556,9 @@ export async function main(
552
556
  env = await store.getEnvironment();
553
557
  const apiKey = await store.getApiKey();
554
558
  if (apiKey) secrets.push(apiKey);
555
- const http = new HttpClient({ fetch, apiKey });
559
+ const partnerId = args[0] === "config" || args[0] === "logout"
560
+ ? null : await store.getPartnerId();
561
+ const http = new HttpClient({ fetch, apiKey, partnerId });
556
562
  const ctx = {
557
563
  args,
558
564
  options,
package/src/config.js CHANGED
@@ -151,6 +151,11 @@ export class ConfigStore {
151
151
  const state = await this.read();
152
152
  return state.keys.find((k) => k.label === state.activeKey)?.key || null;
153
153
  }
154
+ async getPartnerId() {
155
+ const state = await this.read();
156
+ const value = state.settings?.partnerId;
157
+ return value === undefined ? null : validatePartnerId(value, "CONFIG_INVALID");
158
+ }
154
159
  async getEnvironment() {
155
160
  const { settings = {} } = await this.read();
156
161
  if (!settings || typeof settings !== "object" || Array.isArray(settings))
@@ -170,6 +175,28 @@ export class ConfigStore {
170
175
  }
171
176
  }
172
177
 
178
+ function validatePartnerId(value, code = "INVALID_INPUT") {
179
+ if (typeof value !== "string" || !value.trim() || !/^[\x20-\x7e]+$/.test(value))
180
+ throw new CLIError(code, "Partner ID must be a non-empty printable ASCII header value");
181
+ return value.trim();
182
+ }
183
+
184
+ export async function runConfig(args, { store, options }) {
185
+ const [, action, name, value] = args;
186
+ if (name !== "partner-id" || !["set", "get", "unset"].includes(action) ||
187
+ args.length !== (action === "set" ? 4 : 3) ||
188
+ Object.keys(options).some(key => !["json", "output"].includes(key)))
189
+ throw new CLIError("INVALID_INPUT", "Use config set partner-id VALUE, config get partner-id, or config unset partner-id");
190
+ if (action === "get") return { partnerId: await store.getPartnerId() };
191
+ const partnerId = action === "set" ? validatePartnerId(value) : null;
192
+ return store.update(state => {
193
+ state.settings = { ...state.settings };
194
+ if (partnerId === null) delete state.settings.partnerId;
195
+ else state.settings.partnerId = partnerId;
196
+ return { partnerId, saved: true };
197
+ });
198
+ }
199
+
173
200
  export async function configurationStatus(store, options = {}) {
174
201
  const env = await store.getEnvironment();
175
202
  const state = await store.read();
package/src/http.js CHANGED
@@ -58,10 +58,12 @@ export class HttpClient {
58
58
  constructor({
59
59
  fetch: fetcher = globalThis.fetch,
60
60
  apiKey,
61
+ partnerId,
61
62
  timeoutMs = 120000,
62
63
  } = {}) {
63
64
  this.fetch = fetcher;
64
65
  this.apiKey = apiKey;
66
+ this.partnerId = partnerId;
65
67
  this.timeoutMs = timeoutMs;
66
68
  }
67
69
  backend(path, options = {}) {
@@ -127,6 +129,8 @@ export class HttpClient {
127
129
  for (const item of Array.isArray(value) ? value : [value])
128
130
  url.searchParams.append(key, String(item));
129
131
  const headers = new Headers(extra);
132
+ if (origin === GATEWAY_ORIGIN && this.partnerId && !headers.has("x-openany-partner-id"))
133
+ headers.set("x-openany-partner-id", this.partnerId);
130
134
  for (const name of [
131
135
  "authorization",
132
136
  "cookie",