From e17bf537fa8a7a3ca7f1c4a0dd6084b545fb0e76 Mon Sep 17 00:00:00 2001 From: Rufus Bot Date: Sun, 24 May 2026 15:56:08 +0000 Subject: [PATCH] chore: ship compiled dist/ + relax compat to 2026.4.27 Restructure the plugin for direct deployment under the OpenClaw 2026.5.x plugin loader, which requires compiled JavaScript output for installed plugins. A single build artefact now serves both old and new gateways. Build & packaging - Add tsconfig.build.json that emits to dist/ with declarations. - Add build, prepare, and prepublishOnly scripts so installing from a git URL produces dist/ automatically. - Set main to dist/index.js, types to dist/index.d.ts, and declare files so the published tarball ships only what is needed. - Add dist/ to .gitignore (CI builds and uploads it). Compatibility - Lower openclaw.compat.minGatewayVersion, openclaw.compat.pluginApi, openclaw.build.openclawVersion, openclaw.build.pluginSdkVersion, and peerDependencies.openclaw from 2026.5.24 to 2026.4.27. The provider hooks the plugin relies on (wrapStreamFn, hookAliases, resolveTransportTurnState) have been available since 2026.4.27. The requester-bridge code paths (lease, poll, results) already degrade gracefully when the gateway-side TaaS API does not expose those endpoints, so a single build supports the full range. CI - Add .github/workflows/ci.yml to typecheck, test, and build on PR and push, and to upload dist/ as a workflow artefact on main. - Add .github/workflows/release.yml to pack the tarball on tag and attach it to a GitHub Release. The npm publish step is staged but commented out until an NPM_TOKEN secret is configured. Docs - Rewrite Installation: cover the npm-install path and the from-source path (which now requires running install to trigger prepare). - Add a Compatibility table covering 2026.4.27+ behaviour and what degrades on older builds. Verification - npm run build produces dist/index.js and dist/index.d.ts. - npm test passes (9/9 including the bridge long-polling tests). Bump version to 0.5.1. --- .github/workflows/ci.yml | 32 +++++++++++++++++++++++++++++++ .github/workflows/release.yml | 36 +++++++++++++++++++++++++++++++++++ .gitignore | 3 +++ README.md | 31 +++++++++++++++++++----------- package.json | 30 +++++++++++++++++++---------- tsconfig.build.json | 12 ++++++++++++ 6 files changed, 123 insertions(+), 21 deletions(-) create mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/release.yml create mode 100644 tsconfig.build.json diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..582a35f --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,32 @@ +name: CI + +on: + push: + branches: [main] + pull_request: + branches: [main] + +jobs: + build-test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: '22' + cache: 'npm' + - run: npm ci + - run: npm run typecheck + - run: npm test + - run: npm run build + - name: Verify dist/ artefacts + run: | + test -f dist/index.js + test -f dist/index.d.ts + - name: Upload dist + if: github.event_name == 'push' && github.ref == 'refs/heads/main' + uses: actions/upload-artifact@v4 + with: + name: dist + path: dist/ + retention-days: 30 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..b2efe7d --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,36 @@ +name: Release + +on: + push: + tags: + - 'v*' + +permissions: + contents: write + +jobs: + release: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: '22' + cache: 'npm' + registry-url: 'https://registry.npmjs.org' + - run: npm ci + - run: npm test + - run: npm run build + - name: Pack tarball + run: npm pack + - name: Create GitHub Release + uses: softprops/action-gh-release@v2 + with: + files: | + *.tgz + generate_release_notes: true + # Uncomment once NPM_TOKEN secret is configured + # - name: Publish to npm + # run: npm publish --access public + # env: + # NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/.gitignore b/.gitignore index c2658d7..dd6e803 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,4 @@ node_modules/ +dist/ +*.log +.DS_Store diff --git a/README.md b/README.md index 9524055..54b4bc9 100644 --- a/README.md +++ b/README.md @@ -130,40 +130,49 @@ Older OpenClaw builds may fail to load the plugin or may load it without applyin ## Installation -### Option 1 — ClaWHub (coming soon) +### Option 1 - npm install (recommended) ```bash openclaw plugins install openclaw-token-cache-optimizer openclaw gateway restart ``` -### Option 2 — Manual +The published npm package ships pre-built JavaScript in `dist/` and works on OpenClaw `2026.4.27` and later (see [Compatibility](#compatibility)). + +### Option 2 - Manual install from source ```bash -# Clone into your OpenClaw extensions directory git clone https://github.com/cloudsigma/openclaw-token-cache-optimizer \ ~/.openclaw/extensions/openclaw-token-cache-optimizer - -# Restart the gateway to load the plugin +cd ~/.openclaw/extensions/openclaw-token-cache-optimizer +npm install # runs the `prepare` script which builds dist/ openclaw gateway restart ``` -That's it. No `openclaw.json` changes are required — the plugin auto-activates for all requests to the `cloudsigma` provider. +`npm install` triggers the `prepare` lifecycle script which compiles TypeScript to `dist/index.js`. OpenClaw `2026.5.x` and later require this compiled output for installed plugins; older gateways will still load it directly. + +That's it. No `openclaw.json` changes are required - the plugin auto-activates for all requests to the `cloudsigma` provider. ### Verify it loaded ```bash openclaw gateway status +openclaw plugins info openclaw-taas-affinity ``` -You should see the plugin listed in the startup log: - -``` -[plugins] openclaw-token-cache-optimizer: loaded -``` +You should see `Status: loaded` and the source pointing at `dist/index.js` (or `/index.ts` on legacy gateways). --- +## Compatibility + +| OpenClaw gateway | Status | Notes | +|---|---|---| +| >= 2026.5.x | Supported | Loads compiled `dist/index.js` | +| 2026.4.27 - 2026.4.x | Supported | Loads compiled `dist/index.js`; bridge polling endpoints may not exist on the gateway-side TaaS API yet - plugin falls back to advisory-only metadata | +| < 2026.4.27 | Not supported | Hooks the plugin relies on (`wrapStreamFn`, `hookAliases`, `resolveTransportTurnState`) are not exposed | + +The plugin is **forward and backward compatible** within this range from a single build artefact: bridge leasing, polling, and result submission all degrade gracefully when the corresponding TaaS endpoints are missing. ## Verification ### Local validation diff --git a/package.json b/package.json index c93df4f..4101a3a 100644 --- a/package.json +++ b/package.json @@ -1,27 +1,30 @@ { "name": "openclaw-taas-affinity", - "version": "0.5.0", - "description": "OpenClaw provider plugin \u2014 CloudSigma TaaS session affinity. Injects a stable X-Session-Id header per conversation so TaaS can pin the session to the same OAuth token / Bedrock region / Claude Code node, maximising prompt-cache hit rates.", + "version": "0.5.1", + "description": "OpenClaw provider plugin — CloudSigma TaaS session affinity. Injects a stable X-Session-Id header per conversation so TaaS can pin the session to the same OAuth token / Bedrock region / Claude Code node, maximising prompt-cache hit rates.", "type": "module", - "main": "index.ts", + "main": "dist/index.js", "openclaw": { "extensions": [ - "./index.ts" + "./dist/index.js" ], "providers": [ "cloudsigma", "cloudsigma-staging" ], "compat": { - "pluginApi": ">=2026.5.24", - "minGatewayVersion": "2026.5.24" + "pluginApi": ">=2026.4.27", + "minGatewayVersion": "2026.4.27" }, "build": { - "openclawVersion": "2026.5.24", - "pluginSdkVersion": "2026.5.24" + "openclawVersion": "2026.4.27", + "pluginSdkVersion": "2026.4.27" } }, "scripts": { + "build": "tsc -p tsconfig.build.json", + "prepare": "npm run build", + "prepublishOnly": "npm run build && npm test", "typecheck": "tsc --noEmit", "smoke": "node test/smoke.mjs", "unit": "node --import tsx --test test/*.test.ts", @@ -38,12 +41,19 @@ "author": "CloudSigma", "license": "MIT", "peerDependencies": { - "openclaw": ">=2026.5.24" + "openclaw": ">=2026.4.27" }, "devDependencies": { "@types/node": "^22.0.0", "openclaw": "^2026.5.18", "tsx": "^4.20.0", "typescript": "^5.0.0" - } + }, + "types": "dist/index.d.ts", + "files": [ + "dist/", + "openclaw.plugin.json", + "README.md", + "LICENSE" + ] } diff --git a/tsconfig.build.json b/tsconfig.build.json new file mode 100644 index 0000000..a5cf584 --- /dev/null +++ b/tsconfig.build.json @@ -0,0 +1,12 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "noEmit": false, + "outDir": "dist", + "declaration": true, + "declarationMap": false, + "sourceMap": false, + "removeComments": false + }, + "include": ["index.ts"] +}