@t54-labs/clawcredit-sdk 0.1.2 → 0.1.3

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/SKILL.md CHANGED
@@ -1,16 +1,29 @@
1
1
  ---
2
2
  name: clawcredit
3
- description: ClawCredit integration for Open Claw Agents (registration, trace, and payments).
3
+ description: ClawCredit integration for Open Claw Agents (registration for credit, trace, and payments).
4
4
  ---
5
5
 
6
6
  # ClawCredit Integration Skill
7
7
 
8
8
  ## 1. Overview
9
- This skill allows Open Claw Agents to access **ClawCredit**, a decentralized credit service.
9
+ This skill allows Open Claw Agents to access **ClawCredit**, a credit service that
10
+ requires verifiable integration evidence. The goal is to prove real capability
11
+ and real usage, not placeholder functions.
12
+
13
+ **Do NOT call ClawCredit APIs directly.** All registration and payment calls
14
+ must go through the SDK. Direct API calls bypass audit and trace capture and
15
+ will be rejected or scored lower by the risk engine.
16
+
10
17
  By integrating the `@t54-labs/clawcredit-sdk`, agents can:
11
- 1. **Get a Credit Line**: Prove your worth (code, prompt, environment) and get funded.
12
- 2. **Pay for Services**: Use your credit to pay other agents/merchants via x402.
13
- 3. **Build Credit**: Good repayment and low-risk behavior increases your limit.
18
+ 1. **Get a Credit Line**: Submit real core logic + audit trace for initial credit.
19
+ 2. **Pay for Services**: Use your credit to pay other agents/merchants via x402.
20
+ 3. **Build Credit**: Good repayment and low-risk behavior increases your limit.
21
+
22
+ **Compliance affects limits**
23
+ - The more complete and truthful your context (core code, trace, reasoning, runtime),
24
+ the higher your credit limit can be.
25
+ - If you provide minimal or fabricated data, you may receive a very low limit
26
+ or no credit at all.
14
27
 
15
28
  ## 2. Prerequisites
16
29
  - **Node.js Environment** (The SDK is a Node.js package).
@@ -27,16 +40,33 @@ npm install @t54-labs/clawcredit-sdk
27
40
 
28
41
  ### Step 1: Initialization & Registration (with Code Audit)
29
42
  You must register to receive your initial Credit Line.
30
- **IMPORTANT**: Use the `audit()` wrapper on your core logic functions. This proves to the Risk Engine that your code is safe.
43
+ **IMPORTANT**: The audited function must be your REAL core logic, not a placeholder.
44
+ The audit materials are used by the risk engine and directly affect approval and credit size.
45
+
46
+ **What is "core logic"?**
47
+ - The function that handles your main task loop or tool orchestration.
48
+ - The function that decides when to call external services or spend credits.
49
+ - The function that processes user input and produces final outputs.
50
+
51
+ **What NOT to do**
52
+ - Do not use `function coreLogic(input) { return input; }`
53
+ - Do not upload a stub or empty function
54
+ - Do not rename a dummy function and pretend it is core logic
55
+
56
+ **What to do**
57
+ - Wrap the real function that contains your main decision flow
58
+ - Pass that audited function's code as `coreCode`
31
59
 
32
60
  ```javascript
33
61
  const { ClawCredit, audit } = require('@t54-labs/clawcredit-sdk');
34
62
 
35
- // 1. Audit your core functions (Optional but recommended for higher limit)
36
- function myCoreLogic(input) {
37
- // ... implementation ...
63
+ // 1. Audit your REAL core logic (required for credit approval)
64
+ function runAgentPipeline(task, tools) {
65
+ // Real routing, tool selection, and response generation
66
+ // Example: select tool, validate, call external API, post-process output
67
+ return tools.handle(task);
38
68
  }
39
- const safeLogic = audit(myCoreLogic);
69
+ const safeLogic = audit(runAgentPipeline);
40
70
 
41
71
  // 2. Initialize Client
42
72
  const credit = new ClawCredit({
@@ -46,7 +76,7 @@ const credit = new ClawCredit({
46
76
  // 3. Register
47
77
  await credit.register({
48
78
  inviteCode: "YOUR_INVITE_CODE",
49
- coreCode: "const agent = ...",
79
+ coreCode: safeLogic.toString(), // Must be the audited core logic above
50
80
  systemPrompt: "You are a helpful assistant...",
51
81
  runtimeEnv: "node-v22",
52
82
  model: "gpt-5.2" // Optional
package/index.js CHANGED
@@ -3,6 +3,7 @@ const { v4: uuidv4 } = require('uuid');
3
3
  const { audit, getAuditedSnapshot } = require('./lib/audit');
4
4
  const { wrapOpenAI, withTrace, getTraceContext } = require('./lib/monitor');
5
5
  const { loadConfig, DEFAULT_SERVICE_URL } = require('./lib/config');
6
+ const { getSdkMetadata } = require('./lib/sdk_meta');
6
7
 
7
8
  class ClawCredit {
8
9
  constructor(config = {}) {
@@ -27,17 +28,19 @@ class ClawCredit {
27
28
 
28
29
  // Include audited functions if available (via audit decorator)
29
30
  const auditedFunctions = getAuditedSnapshot();
31
+ const resolvedCoreCode = coreCode || (auditedFunctions[0] && auditedFunctions[0].function_code);
30
32
 
31
33
  try {
32
34
  const payload = {
33
35
  agent_name: this.agentName,
34
36
  invite_code: inviteCode,
35
37
  audit_material: {
36
- core_code: coreCode, // Main entry code provided manually
38
+ core_code: resolvedCoreCode, // Prefer audited function source
37
39
  audited_functions: auditedFunctions, // Auto-collected functions
38
40
  system_prompt: systemPrompt,
39
41
  runtime_env: runtimeEnv,
40
- model: model || null
42
+ model: model || null,
43
+ sdk_meta: getSdkMetadata()
41
44
  }
42
45
  };
43
46
 
@@ -49,7 +52,9 @@ class ClawCredit {
49
52
 
50
53
  return {
51
54
  agent_id: this.agentId,
55
+ api_token: res.data.api_token,
52
56
  credit_limit: res.data.credit_limit,
57
+ token_expires_at: res.data.token_expires_at || null,
53
58
  message: "Registration successful. Credit line issued."
54
59
  };
55
60
  } catch (error) {
@@ -0,0 +1,27 @@
1
+ const os = require('os');
2
+ const path = require('path');
3
+ const fs = require('fs');
4
+
5
+ function getSdkVersion() {
6
+ try {
7
+ const pkgPath = path.join(__dirname, '..', 'package.json');
8
+ const raw = fs.readFileSync(pkgPath, 'utf-8');
9
+ const pkg = JSON.parse(raw);
10
+ return pkg.version || 'unknown';
11
+ } catch (_) {
12
+ return 'unknown';
13
+ }
14
+ }
15
+
16
+ function getSdkMetadata() {
17
+ return {
18
+ sdk_name: '@t54-labs/clawcredit-sdk',
19
+ sdk_version: getSdkVersion(),
20
+ node_version: process.version,
21
+ platform: os.platform(),
22
+ arch: os.arch()
23
+ };
24
+ }
25
+
26
+ module.exports = { getSdkMetadata };
27
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@t54-labs/clawcredit-sdk",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "Integration SDK for Open Claw Agents to access ClawCredit",
5
5
  "main": "index.js",
6
6
  "bin": {