agentbnb 3.0.0 → 3.1.1
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/dist/{card-P5C36VBD.js → card-EWIXC377.js} +1 -1
- package/dist/{chunk-V7M6GIJZ.js → chunk-2ETVQXP7.js} +13 -193
- package/dist/chunk-3Y36WQDV.js +70 -0
- package/dist/{chunk-TQMI73LL.js → chunk-7RU5INZI.js} +1 -0
- package/dist/chunk-MGHI67GR.js +257 -0
- package/dist/chunk-MZCNJ5PY.js +192 -0
- package/dist/{chunk-PJSYSVKN.js → chunk-QAY6XTT7.js} +4 -6
- package/dist/{chunk-EZB4RUIG.js → chunk-VCW7IDJM.js} +1 -1
- package/dist/cli/index.js +1176 -470
- package/dist/{conduct-JZJS2ZHA.js → conduct-5T3LGXMF.js} +10 -8
- package/dist/{conductor-mode-DJ3RIJ5T.js → conductor-mode-GPLAM2XO.js} +4 -3
- package/dist/execute-NZXTSSVV.js +9 -0
- package/dist/index.d.ts +1052 -10
- package/dist/index.js +1488 -249
- package/dist/websocket-client-5TIQDYQ4.js +275 -0
- package/package.json +16 -1
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AgentBnBError
|
|
3
|
+
} from "./chunk-7RU5INZI.js";
|
|
4
|
+
|
|
5
|
+
// src/credit/escrow.ts
|
|
6
|
+
import { randomUUID } from "crypto";
|
|
7
|
+
function holdEscrow(db, owner, amount, cardId) {
|
|
8
|
+
const escrowId = randomUUID();
|
|
9
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
10
|
+
const hold = db.transaction(() => {
|
|
11
|
+
const row = db.prepare("SELECT balance FROM credit_balances WHERE owner = ?").get(owner);
|
|
12
|
+
if (!row || row.balance < amount) {
|
|
13
|
+
throw new AgentBnBError("Insufficient credits", "INSUFFICIENT_CREDITS");
|
|
14
|
+
}
|
|
15
|
+
db.prepare(
|
|
16
|
+
"UPDATE credit_balances SET balance = balance - ?, updated_at = ? WHERE owner = ? AND balance >= ?"
|
|
17
|
+
).run(amount, now, owner, amount);
|
|
18
|
+
db.prepare(
|
|
19
|
+
"INSERT INTO credit_escrow (id, owner, amount, card_id, status, created_at) VALUES (?, ?, ?, ?, ?, ?)"
|
|
20
|
+
).run(escrowId, owner, amount, cardId, "held", now);
|
|
21
|
+
db.prepare(
|
|
22
|
+
"INSERT INTO credit_transactions (id, owner, amount, reason, reference_id, created_at) VALUES (?, ?, ?, ?, ?, ?)"
|
|
23
|
+
).run(randomUUID(), owner, -amount, "escrow_hold", escrowId, now);
|
|
24
|
+
});
|
|
25
|
+
hold();
|
|
26
|
+
return escrowId;
|
|
27
|
+
}
|
|
28
|
+
function settleEscrow(db, escrowId, recipientOwner) {
|
|
29
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
30
|
+
const settle = db.transaction(() => {
|
|
31
|
+
const escrow = db.prepare("SELECT id, owner, amount, status FROM credit_escrow WHERE id = ?").get(escrowId);
|
|
32
|
+
if (!escrow) {
|
|
33
|
+
throw new AgentBnBError(`Escrow not found: ${escrowId}`, "ESCROW_NOT_FOUND");
|
|
34
|
+
}
|
|
35
|
+
if (escrow.status !== "held") {
|
|
36
|
+
throw new AgentBnBError(
|
|
37
|
+
`Escrow ${escrowId} is already ${escrow.status}`,
|
|
38
|
+
"ESCROW_ALREADY_SETTLED"
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
db.prepare(
|
|
42
|
+
"INSERT OR IGNORE INTO credit_balances (owner, balance, updated_at) VALUES (?, 0, ?)"
|
|
43
|
+
).run(recipientOwner, now);
|
|
44
|
+
db.prepare(
|
|
45
|
+
"UPDATE credit_balances SET balance = balance + ?, updated_at = ? WHERE owner = ?"
|
|
46
|
+
).run(escrow.amount, now, recipientOwner);
|
|
47
|
+
db.prepare(
|
|
48
|
+
"UPDATE credit_escrow SET status = ?, settled_at = ? WHERE id = ?"
|
|
49
|
+
).run("settled", now, escrowId);
|
|
50
|
+
db.prepare(
|
|
51
|
+
"INSERT INTO credit_transactions (id, owner, amount, reason, reference_id, created_at) VALUES (?, ?, ?, ?, ?, ?)"
|
|
52
|
+
).run(randomUUID(), recipientOwner, escrow.amount, "settlement", escrowId, now);
|
|
53
|
+
});
|
|
54
|
+
settle();
|
|
55
|
+
}
|
|
56
|
+
function releaseEscrow(db, escrowId) {
|
|
57
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
58
|
+
const release = db.transaction(() => {
|
|
59
|
+
const escrow = db.prepare("SELECT id, owner, amount, status FROM credit_escrow WHERE id = ?").get(escrowId);
|
|
60
|
+
if (!escrow) {
|
|
61
|
+
throw new AgentBnBError(`Escrow not found: ${escrowId}`, "ESCROW_NOT_FOUND");
|
|
62
|
+
}
|
|
63
|
+
if (escrow.status !== "held") {
|
|
64
|
+
throw new AgentBnBError(
|
|
65
|
+
`Escrow ${escrowId} is already ${escrow.status}`,
|
|
66
|
+
"ESCROW_ALREADY_SETTLED"
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
db.prepare(
|
|
70
|
+
"UPDATE credit_balances SET balance = balance + ?, updated_at = ? WHERE owner = ?"
|
|
71
|
+
).run(escrow.amount, now, escrow.owner);
|
|
72
|
+
db.prepare(
|
|
73
|
+
"UPDATE credit_escrow SET status = ?, settled_at = ? WHERE id = ?"
|
|
74
|
+
).run("released", now, escrowId);
|
|
75
|
+
db.prepare(
|
|
76
|
+
"INSERT INTO credit_transactions (id, owner, amount, reason, reference_id, created_at) VALUES (?, ?, ?, ?, ?, ?)"
|
|
77
|
+
).run(randomUUID(), escrow.owner, escrow.amount, "refund", escrowId, now);
|
|
78
|
+
});
|
|
79
|
+
release();
|
|
80
|
+
}
|
|
81
|
+
function confirmEscrowDebit(db, escrowId) {
|
|
82
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
83
|
+
const confirm = db.transaction(() => {
|
|
84
|
+
const escrow = db.prepare("SELECT id, owner, amount, status FROM credit_escrow WHERE id = ?").get(escrowId);
|
|
85
|
+
if (!escrow) {
|
|
86
|
+
throw new AgentBnBError(`Escrow not found: ${escrowId}`, "ESCROW_NOT_FOUND");
|
|
87
|
+
}
|
|
88
|
+
if (escrow.status !== "held") {
|
|
89
|
+
throw new AgentBnBError(
|
|
90
|
+
`Escrow ${escrowId} is already ${escrow.status}`,
|
|
91
|
+
"ESCROW_ALREADY_SETTLED"
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
db.prepare(
|
|
95
|
+
"UPDATE credit_escrow SET status = ?, settled_at = ? WHERE id = ?"
|
|
96
|
+
).run("settled", now, escrowId);
|
|
97
|
+
db.prepare(
|
|
98
|
+
"INSERT INTO credit_transactions (id, owner, amount, reason, reference_id, created_at) VALUES (?, ?, ?, ?, ?, ?)"
|
|
99
|
+
).run(randomUUID(), escrow.owner, 0, "remote_settlement_confirmed", escrowId, now);
|
|
100
|
+
});
|
|
101
|
+
confirm();
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// src/credit/ledger.ts
|
|
105
|
+
import Database from "better-sqlite3";
|
|
106
|
+
import { randomUUID as randomUUID2 } from "crypto";
|
|
107
|
+
var CREDIT_SCHEMA = `
|
|
108
|
+
CREATE TABLE IF NOT EXISTS credit_balances (
|
|
109
|
+
owner TEXT PRIMARY KEY,
|
|
110
|
+
balance INTEGER NOT NULL DEFAULT 0,
|
|
111
|
+
updated_at TEXT NOT NULL
|
|
112
|
+
);
|
|
113
|
+
|
|
114
|
+
CREATE TABLE IF NOT EXISTS credit_transactions (
|
|
115
|
+
id TEXT PRIMARY KEY,
|
|
116
|
+
owner TEXT NOT NULL,
|
|
117
|
+
amount INTEGER NOT NULL,
|
|
118
|
+
reason TEXT NOT NULL,
|
|
119
|
+
reference_id TEXT,
|
|
120
|
+
created_at TEXT NOT NULL
|
|
121
|
+
);
|
|
122
|
+
|
|
123
|
+
CREATE TABLE IF NOT EXISTS credit_escrow (
|
|
124
|
+
id TEXT PRIMARY KEY,
|
|
125
|
+
owner TEXT NOT NULL,
|
|
126
|
+
amount INTEGER NOT NULL,
|
|
127
|
+
card_id TEXT NOT NULL,
|
|
128
|
+
status TEXT NOT NULL DEFAULT 'held',
|
|
129
|
+
created_at TEXT NOT NULL,
|
|
130
|
+
settled_at TEXT
|
|
131
|
+
);
|
|
132
|
+
|
|
133
|
+
CREATE INDEX IF NOT EXISTS idx_transactions_owner ON credit_transactions(owner, created_at);
|
|
134
|
+
CREATE INDEX IF NOT EXISTS idx_escrow_owner ON credit_escrow(owner);
|
|
135
|
+
`;
|
|
136
|
+
function openCreditDb(path = ":memory:") {
|
|
137
|
+
const db = new Database(path);
|
|
138
|
+
db.pragma("journal_mode = WAL");
|
|
139
|
+
db.pragma("foreign_keys = ON");
|
|
140
|
+
db.exec(CREDIT_SCHEMA);
|
|
141
|
+
return db;
|
|
142
|
+
}
|
|
143
|
+
function bootstrapAgent(db, owner, amount = 100) {
|
|
144
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
145
|
+
db.transaction(() => {
|
|
146
|
+
const result = db.prepare("INSERT OR IGNORE INTO credit_balances (owner, balance, updated_at) VALUES (?, ?, ?)").run(owner, amount, now);
|
|
147
|
+
if (result.changes > 0) {
|
|
148
|
+
db.prepare(
|
|
149
|
+
"INSERT INTO credit_transactions (id, owner, amount, reason, reference_id, created_at) VALUES (?, ?, ?, ?, ?, ?)"
|
|
150
|
+
).run(randomUUID2(), owner, amount, "bootstrap", null, now);
|
|
151
|
+
}
|
|
152
|
+
})();
|
|
153
|
+
}
|
|
154
|
+
function getBalance(db, owner) {
|
|
155
|
+
const row = db.prepare("SELECT balance FROM credit_balances WHERE owner = ?").get(owner);
|
|
156
|
+
return row?.balance ?? 0;
|
|
157
|
+
}
|
|
158
|
+
function getTransactions(db, owner, limit = 100) {
|
|
159
|
+
return db.prepare(
|
|
160
|
+
"SELECT id, owner, amount, reason, reference_id, created_at FROM credit_transactions WHERE owner = ? ORDER BY created_at DESC LIMIT ?"
|
|
161
|
+
).all(owner, limit);
|
|
162
|
+
}
|
|
163
|
+
function recordEarning(db, owner, amount, _cardId, receiptNonce) {
|
|
164
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
165
|
+
db.transaction(() => {
|
|
166
|
+
const existing = db.prepare(
|
|
167
|
+
"SELECT id FROM credit_transactions WHERE reference_id = ? AND reason = 'remote_earning'"
|
|
168
|
+
).get(receiptNonce);
|
|
169
|
+
if (existing) return;
|
|
170
|
+
db.prepare(
|
|
171
|
+
"INSERT OR IGNORE INTO credit_balances (owner, balance, updated_at) VALUES (?, 0, ?)"
|
|
172
|
+
).run(owner, now);
|
|
173
|
+
db.prepare(
|
|
174
|
+
"UPDATE credit_balances SET balance = balance + ?, updated_at = ? WHERE owner = ?"
|
|
175
|
+
).run(amount, now, owner);
|
|
176
|
+
db.prepare(
|
|
177
|
+
"INSERT INTO credit_transactions (id, owner, amount, reason, reference_id, created_at) VALUES (?, ?, ?, ?, ?, ?)"
|
|
178
|
+
).run(randomUUID2(), owner, amount, "remote_earning", receiptNonce, now);
|
|
179
|
+
})();
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
export {
|
|
183
|
+
holdEscrow,
|
|
184
|
+
settleEscrow,
|
|
185
|
+
releaseEscrow,
|
|
186
|
+
confirmEscrowDebit,
|
|
187
|
+
openCreditDb,
|
|
188
|
+
bootstrapAgent,
|
|
189
|
+
getBalance,
|
|
190
|
+
getTransactions,
|
|
191
|
+
recordEarning
|
|
192
|
+
};
|
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
AgentBnBError,
|
|
3
3
|
CapabilityCardSchema
|
|
4
|
-
} from "./chunk-
|
|
5
|
-
|
|
6
|
-
// src/registry/store.ts
|
|
7
|
-
import Database from "better-sqlite3";
|
|
4
|
+
} from "./chunk-7RU5INZI.js";
|
|
8
5
|
|
|
9
6
|
// src/registry/request-log.ts
|
|
10
7
|
var SINCE_MS = {
|
|
@@ -77,7 +74,7 @@ function getActivityFeed(db, limit = 20, since) {
|
|
|
77
74
|
r.status, r.credits_charged, r.latency_ms, r.created_at, r.action_type
|
|
78
75
|
FROM request_log r
|
|
79
76
|
LEFT JOIN capability_cards c ON r.card_id = c.id
|
|
80
|
-
WHERE (r.action_type IS NULL OR r.action_type
|
|
77
|
+
WHERE (r.action_type IS NULL OR r.action_type IN ('auto_share', 'agent_joined'))
|
|
81
78
|
AND r.created_at > ?
|
|
82
79
|
ORDER BY r.created_at DESC
|
|
83
80
|
LIMIT ?
|
|
@@ -89,7 +86,7 @@ function getActivityFeed(db, limit = 20, since) {
|
|
|
89
86
|
r.status, r.credits_charged, r.latency_ms, r.created_at, r.action_type
|
|
90
87
|
FROM request_log r
|
|
91
88
|
LEFT JOIN capability_cards c ON r.card_id = c.id
|
|
92
|
-
WHERE (r.action_type IS NULL OR r.action_type
|
|
89
|
+
WHERE (r.action_type IS NULL OR r.action_type IN ('auto_share', 'agent_joined'))
|
|
93
90
|
ORDER BY r.created_at DESC
|
|
94
91
|
LIMIT ?
|
|
95
92
|
`);
|
|
@@ -117,6 +114,7 @@ function getRequestLog(db, limit = 10, since) {
|
|
|
117
114
|
}
|
|
118
115
|
|
|
119
116
|
// src/registry/store.ts
|
|
117
|
+
import Database from "better-sqlite3";
|
|
120
118
|
var V2_FTS_TRIGGERS = `
|
|
121
119
|
DROP TRIGGER IF EXISTS cards_ai;
|
|
122
120
|
DROP TRIGGER IF EXISTS cards_au;
|