diff --git a/README.md b/README.md index 108dd4b..b561f8c 100644 --- a/README.md +++ b/README.md @@ -19,9 +19,9 @@ openclaw plugins install npm:@ssntpl/openclaw-otper ## Configure -Two ways — either works, plugin config takes precedence: +Generate a personal access token at **https://otper.com/settings/tokens**, then provide it via any one of these (resolved in order): -**1. Plugin config** (preferred): +**1. Plugin config**: ```json { @@ -34,14 +34,21 @@ Two ways — either works, plugin config takes precedence: } ``` -**2. Environment variables** (handy for CI / one-off runs): +**2. Environment variables**: ```sh export OTPER_TOKEN="238|..." export OTPER_BASE_URL="https://otper.com" # optional, defaults to https://otper.com ``` -Generate a token from your Otper account settings. +**3. Reuse [`otper-cli`](https://github.com/ssntpl/otper-cli)'s saved login**: + +```sh +npm install -g @ssntpl/otper-cli +otper auth:login # writes ~/.otper-cli/default/config.json +``` + +If you already use `otper-cli`, no extra setup is needed — the plugin reads the same config file. ## Tools diff --git a/package-lock.json b/package-lock.json index 49e80fd..8473005 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@ssntpl/openclaw-otper", - "version": "0.1.1", + "version": "0.1.2", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@ssntpl/openclaw-otper", - "version": "0.1.1", + "version": "0.1.2", "license": "MIT", "dependencies": { "@ssntpl/otper-cli": "^0.1.5" diff --git a/package.json b/package.json index 5e799f2..fd6d3a8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@ssntpl/openclaw-otper", - "version": "0.1.1", + "version": "0.1.2", "description": "OpenClaw plugin for Otper boards (https://otper.com) — exposes Otper boards, lists, cards, labels, comments, and today's priorities as agent tools.", "author": "SSNTPL ", "license": "MIT", diff --git a/tools/shared.ts b/tools/shared.ts index 7296c53..e4fa9e9 100644 --- a/tools/shared.ts +++ b/tools/shared.ts @@ -1,4 +1,4 @@ -import { OtperClient, DEFAULT_BASE_URL } from "@ssntpl/otper-cli"; +import { OtperClient, resolveConfig } from "@ssntpl/otper-cli"; export interface PluginConfig { token?: string; @@ -6,19 +6,31 @@ export interface PluginConfig { } /** - * Build an OtperClient from the openclaw plugin config, falling back to - * the same env vars the otper-cli uses (OTPER_TOKEN, OTPER_BASE_URL). - * Throws a clear, agent-readable error if no token can be resolved. + * Build an OtperClient using otper-cli's standard resolution chain: + * 1. Plugin config (token / baseUrl from openclaw plugin settings) + * 2. Environment vars (OTPER_TOKEN / OTPER_BASE_URL) + * 3. otper-cli's saved credentials at ~/.otper-cli//config.json + * (created by `otper auth:login`) + * + * Sharing the resolution with otper-cli means a single login serves + * both the CLI and this plugin. */ export function clientFor(config: PluginConfig | undefined): OtperClient { - const token = config?.token ?? process.env.OTPER_TOKEN; - const baseUrl = config?.baseUrl ?? process.env.OTPER_BASE_URL ?? DEFAULT_BASE_URL; - if (!token) { + try { + const cfg = resolveConfig({ + token: config?.token, + baseUrl: config?.baseUrl, + }); + return OtperClient.fromConfig(cfg); + } catch { throw new Error( - "Otper is not configured. Set the plugin's `token` config or the OTPER_TOKEN environment variable.", + "Otper is not configured. Provide a token via the openclaw plugin " + + "config, the OTPER_TOKEN environment variable, or by running " + + "`otper auth:login` to save credentials at " + + "~/.otper-cli//config.json. Generate a personal access " + + "token at https://otper.com/settings/tokens.", ); } - return new OtperClient({ baseUrl, token }); } export type TextContent = { type: "text"; text: string };