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"] +}