@t54-labs/clawcredit-sdk 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/README.md CHANGED
@@ -23,6 +23,12 @@ Install the SDK:
23
23
  npm install @t54-labs/clawcredit-sdk
24
24
  ```
25
25
 
26
+ Configure token via CLI (recommended for humans, not agents):
27
+
28
+ ```bash
29
+ clawcredit configure --token YOUR_API_TOKEN --service-url https://api.claw.credit
30
+ ```
31
+
26
32
  Initialize and register:
27
33
 
28
34
  ```javascript
package/SKILL.md CHANGED
@@ -1,8 +1,13 @@
1
+ ---
2
+ name: clawcredit
3
+ description: ClawCredit integration for Open Claw Agents (registration, trace, and payments).
4
+ ---
5
+
1
6
  # ClawCredit Integration Skill
2
7
 
3
8
  ## 1. Overview
4
9
  This skill allows Open Claw Agents to access **ClawCredit**, a decentralized credit service.
5
- By integrating the `@clawcredit/sdk`, agents can:
10
+ By integrating the `@t54-labs/clawcredit-sdk`, agents can:
6
11
  1. **Get a Credit Line**: Prove your worth (code, prompt, environment) and get funded.
7
12
  2. **Pay for Services**: Use your credit to pay other agents/merchants via x402.
8
13
  3. **Build Credit**: Good repayment and low-risk behavior increases your limit.
@@ -0,0 +1,74 @@
1
+ #!/usr/bin/env node
2
+ const { loadConfig, saveConfig, DEFAULT_SERVICE_URL } = require('../lib/config');
3
+
4
+ function printHelp() {
5
+ console.log(`
6
+ ClawCredit CLI
7
+
8
+ Usage:
9
+ clawcredit configure --token <API_TOKEN> [--service-url <URL>] [--agent <id>]
10
+ clawcredit show [--agent <id>]
11
+
12
+ Notes:
13
+ - Config is stored at: ~/.openclaw/agents/<agent>/agent/clawcredit.json
14
+ - You can override the config path with CLAWCREDIT_CONFIG
15
+ `);
16
+ }
17
+
18
+ function parseArgs(argv) {
19
+ const args = {};
20
+ for (let i = 0; i < argv.length; i += 1) {
21
+ const key = argv[i];
22
+ if (!key.startsWith('--')) continue;
23
+ const value = argv[i + 1];
24
+ args[key.slice(2)] = value;
25
+ i += 1;
26
+ }
27
+ return args;
28
+ }
29
+
30
+ async function main() {
31
+ const [,, command, ...rest] = process.argv;
32
+ const args = parseArgs(rest);
33
+ const agent = args.agent || 'default';
34
+
35
+ if (!command || command === 'help' || command === '--help' || command === '-h') {
36
+ printHelp();
37
+ return;
38
+ }
39
+
40
+ if (command === 'configure' || command === 'set-token') {
41
+ const token = args.token;
42
+ const serviceUrl = args['service-url'] || DEFAULT_SERVICE_URL;
43
+
44
+ if (!token) {
45
+ console.error('Missing --token');
46
+ process.exit(1);
47
+ }
48
+
49
+ const configPath = saveConfig({ agent, token, serviceUrl });
50
+ console.log(`Saved: ${configPath}`);
51
+ return;
52
+ }
53
+
54
+ if (command === 'show') {
55
+ const { configPath, data, error } = loadConfig(agent);
56
+ if (error) {
57
+ console.error(`Failed to read ${configPath}: ${error.message}`);
58
+ process.exit(1);
59
+ }
60
+ if (!data) {
61
+ console.log(`No config found at: ${configPath}`);
62
+ process.exit(0);
63
+ }
64
+ console.log(JSON.stringify(data, null, 2));
65
+ return;
66
+ }
67
+
68
+ console.error(`Unknown command: ${command}`);
69
+ printHelp();
70
+ process.exit(1);
71
+ }
72
+
73
+ main();
74
+
package/index.js CHANGED
@@ -2,12 +2,19 @@ const axios = require('axios');
2
2
  const { v4: uuidv4 } = require('uuid');
3
3
  const { audit, getAuditedSnapshot } = require('./lib/audit');
4
4
  const { wrapOpenAI, withTrace, getTraceContext } = require('./lib/monitor');
5
+ const { loadConfig, DEFAULT_SERVICE_URL } = require('./lib/config');
5
6
 
6
7
  class ClawCredit {
7
8
  constructor(config = {}) {
8
- this.serviceUrl = config.serviceUrl || 'https://api.clawcredit.com'; // Default production URL
9
+ const agent = config.agent || 'default';
10
+ const loaded = loadConfig(agent);
11
+ const loadedData = loaded.data || {};
12
+
13
+ this.serviceUrl = config.serviceUrl
14
+ || loadedData.serviceUrl
15
+ || DEFAULT_SERVICE_URL;
9
16
  this.agentName = config.agentName;
10
- this.apiToken = config.apiToken; // Token stored after registration
17
+ this.apiToken = config.apiToken || loadedData.apiToken; // Token stored after registration
11
18
  this.agentId = config.agentId;
12
19
  }
13
20
 
package/lib/config.js ADDED
@@ -0,0 +1,50 @@
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+ const os = require('os');
4
+
5
+ const DEFAULT_SERVICE_URL = 'https://api.claw.credit';
6
+
7
+ function getDefaultConfigPath(agent = 'default') {
8
+ const home = os.homedir();
9
+ return path.join(home, '.openclaw', 'agents', agent, 'agent', 'clawcredit.json');
10
+ }
11
+
12
+ function loadConfig(agent = 'default') {
13
+ const overridePath = process.env.CLAWCREDIT_CONFIG;
14
+ const configPath = overridePath || getDefaultConfigPath(agent);
15
+
16
+ if (!fs.existsSync(configPath)) {
17
+ return { configPath, data: null };
18
+ }
19
+
20
+ try {
21
+ const raw = fs.readFileSync(configPath, 'utf-8');
22
+ const data = JSON.parse(raw);
23
+ return { configPath, data };
24
+ } catch (err) {
25
+ return { configPath, data: null, error: err };
26
+ }
27
+ }
28
+
29
+ function saveConfig({ agent = 'default', token, serviceUrl }) {
30
+ const configPath = getDefaultConfigPath(agent);
31
+ const dir = path.dirname(configPath);
32
+ fs.mkdirSync(dir, { recursive: true });
33
+
34
+ const payload = {
35
+ apiToken: token,
36
+ serviceUrl: serviceUrl || DEFAULT_SERVICE_URL,
37
+ updatedAt: new Date().toISOString()
38
+ };
39
+
40
+ fs.writeFileSync(configPath, JSON.stringify(payload, null, 2));
41
+ return configPath;
42
+ }
43
+
44
+ module.exports = {
45
+ DEFAULT_SERVICE_URL,
46
+ getDefaultConfigPath,
47
+ loadConfig,
48
+ saveConfig
49
+ };
50
+
package/package.json CHANGED
@@ -1,8 +1,18 @@
1
1
  {
2
2
  "name": "@t54-labs/clawcredit-sdk",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "Integration SDK for Open Claw Agents to access ClawCredit",
5
5
  "main": "index.js",
6
+ "bin": {
7
+ "clawcredit": "bin/clawcredit.js"
8
+ },
9
+ "files": [
10
+ "index.js",
11
+ "lib",
12
+ "bin",
13
+ "README.md",
14
+ "SKILL.md"
15
+ ],
6
16
  "dependencies": {
7
17
  "axios": "^1.6.0",
8
18
  "uuid": "^9.0.0"
Binary file