@vibeiao/sdk 0.1.0
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 +165 -0
- package/dist/chunk-43XG274S.js +206 -0
- package/dist/chunk-BFAMXH2X.js +162 -0
- package/dist/chunk-CJAFFQLN.js +220 -0
- package/dist/chunk-OUGOOS3F.js +1416 -0
- package/dist/chunk-TA22XXY4.js +224 -0
- package/dist/chunk-YON7O6R5.js +146 -0
- package/dist/index.d.ts +929 -0
- package/dist/index.js +465 -0
- package/dist/memory.d.ts +140 -0
- package/dist/memory.js +527 -0
- package/dist/selfReliance.d.ts +89 -0
- package/dist/selfReliance.js +16 -0
- package/dist/solana-3VMnBZH6.d.ts +189 -0
- package/dist/solana.d.ts +3 -0
- package/dist/solana.js +22 -0
- package/package.json +32 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,465 @@
|
|
|
1
|
+
import {
|
|
2
|
+
SelfReliance,
|
|
3
|
+
createAutoSelfReliance,
|
|
4
|
+
createSelfRelianceMonitor,
|
|
5
|
+
createSelfReliancePolicy,
|
|
6
|
+
createSurvivalMiddleware,
|
|
7
|
+
withSurvival
|
|
8
|
+
} from "./chunk-BFAMXH2X.js";
|
|
9
|
+
import {
|
|
10
|
+
VIBEIAO_IDL,
|
|
11
|
+
fetchSolBalance,
|
|
12
|
+
fetchTokenBalance,
|
|
13
|
+
fetchTokenBalances
|
|
14
|
+
} from "./chunk-OUGOOS3F.js";
|
|
15
|
+
|
|
16
|
+
// src/index.ts
|
|
17
|
+
var pickFinite = (...values) => {
|
|
18
|
+
for (const value of values) {
|
|
19
|
+
const num = typeof value === "number" ? value : Number(value);
|
|
20
|
+
if (Number.isFinite(num)) return num;
|
|
21
|
+
}
|
|
22
|
+
return NaN;
|
|
23
|
+
};
|
|
24
|
+
var buildClaimMessage = (nonce) => `VIBEIAO-CLAIM:${nonce}`;
|
|
25
|
+
var buildOwnerTransferMessage = (listingId, newOwnerWallet, nonce) => `VIBEIAO-OWNER-TRANSFER:${listingId}:${newOwnerWallet}:${nonce}`;
|
|
26
|
+
var buildMemoryPingMessage = (listingId, timestamp) => `VIBEIAO-MEMORY-PING:${listingId}:${timestamp}`;
|
|
27
|
+
var buildListingVersionMessage = (listingId, version, timestamp) => `VIBEIAO-LISTING-VERSION:${listingId}:${version}:${timestamp}`;
|
|
28
|
+
var buildReviewResponseMessage = (reviewId, status, timestamp) => `VIBEIAO-REVIEW-RESPONSE:${reviewId}:${status}:${timestamp}`;
|
|
29
|
+
var buildReviewPrompt = () => "After using this tool once, provide a 1-5 star rating and a short comment (what worked, what failed, what to improve).";
|
|
30
|
+
var buildReviewRequired = (listingId, redeemSignature, appVersion, options = {}) => {
|
|
31
|
+
const base = withTrailingSlash(options.baseUrl || DEFAULT_API_BASE);
|
|
32
|
+
return {
|
|
33
|
+
listingId,
|
|
34
|
+
redeemSignature,
|
|
35
|
+
appVersion,
|
|
36
|
+
reviewUrl: `${base}/v1/listings/${listingId}/reviews`
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
var ReviewGate = class {
|
|
40
|
+
pending = /* @__PURE__ */ new Map();
|
|
41
|
+
key(listingId, wallet) {
|
|
42
|
+
return `${listingId}:${wallet}`;
|
|
43
|
+
}
|
|
44
|
+
require(record) {
|
|
45
|
+
this.pending.set(this.key(record.listingId, record.wallet), record);
|
|
46
|
+
return record;
|
|
47
|
+
}
|
|
48
|
+
get(listingId, wallet) {
|
|
49
|
+
return this.pending.get(this.key(listingId, wallet));
|
|
50
|
+
}
|
|
51
|
+
clear(listingId, wallet) {
|
|
52
|
+
this.pending.delete(this.key(listingId, wallet));
|
|
53
|
+
}
|
|
54
|
+
assertClear(listingId, wallet) {
|
|
55
|
+
if (this.pending.has(this.key(listingId, wallet))) {
|
|
56
|
+
throw new Error("review_pending");
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
var DEFAULT_API_BASE = "https://api.vibeiao.com";
|
|
61
|
+
var DEFAULT_WEB_BASE = "https://vibeiao.com";
|
|
62
|
+
var withTrailingSlash = (value) => value.endsWith("/") ? value.slice(0, -1) : value;
|
|
63
|
+
var readJson = async (response) => {
|
|
64
|
+
const text = await response.text();
|
|
65
|
+
if (!text) return null;
|
|
66
|
+
try {
|
|
67
|
+
return JSON.parse(text);
|
|
68
|
+
} catch {
|
|
69
|
+
const snippet = text.trim().slice(0, 160);
|
|
70
|
+
const err = new Error("invalid_json_response");
|
|
71
|
+
err.details = { status: response.status, snippet };
|
|
72
|
+
throw err;
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
var unwrap = (response) => {
|
|
76
|
+
if (response.error) {
|
|
77
|
+
throw new Error(response.error);
|
|
78
|
+
}
|
|
79
|
+
return response.data;
|
|
80
|
+
};
|
|
81
|
+
var generateRef = () => {
|
|
82
|
+
const cryptoObj = globalThis.crypto;
|
|
83
|
+
if (cryptoObj?.randomUUID) {
|
|
84
|
+
return cryptoObj.randomUUID();
|
|
85
|
+
}
|
|
86
|
+
return Math.random().toString(36).slice(2, 10);
|
|
87
|
+
};
|
|
88
|
+
var buildQuery = (params) => {
|
|
89
|
+
const query = new URLSearchParams();
|
|
90
|
+
Object.entries(params).forEach(([key, value]) => {
|
|
91
|
+
if (value === void 0 || value === null || value === "") return;
|
|
92
|
+
query.set(key, String(value));
|
|
93
|
+
});
|
|
94
|
+
const queryString = query.toString();
|
|
95
|
+
return queryString ? `?${queryString}` : "";
|
|
96
|
+
};
|
|
97
|
+
var VibeClient = class {
|
|
98
|
+
baseUrl;
|
|
99
|
+
fetcher;
|
|
100
|
+
constructor(options = {}) {
|
|
101
|
+
this.baseUrl = withTrailingSlash(options.baseUrl || DEFAULT_API_BASE);
|
|
102
|
+
this.fetcher = options.fetcher || fetch;
|
|
103
|
+
}
|
|
104
|
+
async createClaim(wallet, purpose) {
|
|
105
|
+
return this.post("/v1/claims", { wallet, purpose });
|
|
106
|
+
}
|
|
107
|
+
async verifyClaim(claimId, signature) {
|
|
108
|
+
return this.post(`/v1/claims/${claimId}/verify`, { signature });
|
|
109
|
+
}
|
|
110
|
+
async createListing(claimId, listing, ownerClaimId) {
|
|
111
|
+
return this.post("/v1/listings", { claimId, ownerClaimId, listing });
|
|
112
|
+
}
|
|
113
|
+
async registerAgent(claimId, listing, ownerClaimId) {
|
|
114
|
+
return this.post("/v1/agents/register", { claimId, ownerClaimId, listing });
|
|
115
|
+
}
|
|
116
|
+
async updateListingStatus(listingId, claimId, status) {
|
|
117
|
+
return this.post(`/v1/listings/${listingId}/status`, { claimId, status });
|
|
118
|
+
}
|
|
119
|
+
async updateListingPrice(listingId, claimId, priceUsdc) {
|
|
120
|
+
return this.post(`/v1/listings/${listingId}/price`, { claimId, priceUsdc });
|
|
121
|
+
}
|
|
122
|
+
async transferOwner(listingId, claimId, signature) {
|
|
123
|
+
return this.post(
|
|
124
|
+
`/v1/listings/${listingId}/owner-transfer`,
|
|
125
|
+
{ claimId, signature }
|
|
126
|
+
);
|
|
127
|
+
}
|
|
128
|
+
async reportMemory(listingId, payload) {
|
|
129
|
+
return this.post(
|
|
130
|
+
`/v1/agents/${listingId}/memory`,
|
|
131
|
+
payload
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
async listListings(filters = {}) {
|
|
135
|
+
const query = buildQuery({
|
|
136
|
+
type: filters.type,
|
|
137
|
+
status: filters.status,
|
|
138
|
+
category: filters.category,
|
|
139
|
+
q: filters.q,
|
|
140
|
+
llmRequired: filters.llmRequired,
|
|
141
|
+
sort: filters.sort,
|
|
142
|
+
limit: filters.limit,
|
|
143
|
+
offset: filters.offset
|
|
144
|
+
});
|
|
145
|
+
return this.get(`/v1/listings${query}`);
|
|
146
|
+
}
|
|
147
|
+
async getListing(id) {
|
|
148
|
+
return this.get(`/v1/listings/${id}`);
|
|
149
|
+
}
|
|
150
|
+
async getListingReviews(listingId, options) {
|
|
151
|
+
const query = buildQuery({ limit: options?.limit, offset: options?.offset });
|
|
152
|
+
return this.get(`/v1/listings/${listingId}/reviews${query}`);
|
|
153
|
+
}
|
|
154
|
+
async createListingReview(listingId, payload) {
|
|
155
|
+
return this.post(`/v1/listings/${listingId}/reviews`, payload);
|
|
156
|
+
}
|
|
157
|
+
async respondToListingReview(listingId, reviewId, payload) {
|
|
158
|
+
return this.post(
|
|
159
|
+
`/v1/listings/${listingId}/reviews/${reviewId}/response`,
|
|
160
|
+
payload
|
|
161
|
+
);
|
|
162
|
+
}
|
|
163
|
+
async updateListingVersion(listingId, payload) {
|
|
164
|
+
return this.post(
|
|
165
|
+
`/v1/listings/${listingId}/version`,
|
|
166
|
+
payload
|
|
167
|
+
);
|
|
168
|
+
}
|
|
169
|
+
async getLeaderboard(filters = {}) {
|
|
170
|
+
const query = buildQuery({
|
|
171
|
+
type: filters.type,
|
|
172
|
+
window: filters.window,
|
|
173
|
+
limit: filters.limit
|
|
174
|
+
});
|
|
175
|
+
return this.get(`/v1/leaderboard${query}`);
|
|
176
|
+
}
|
|
177
|
+
async getListingAnalytics(listingId, window = "7d") {
|
|
178
|
+
const query = buildQuery({ window });
|
|
179
|
+
return this.get(`/v1/listings/${listingId}/analytics${query}`);
|
|
180
|
+
}
|
|
181
|
+
async getListingBuybacks(listingId, limit = 20) {
|
|
182
|
+
const query = buildQuery({ limit });
|
|
183
|
+
return this.get(`/v1/listings/${listingId}/buybacks${query}`);
|
|
184
|
+
}
|
|
185
|
+
async getOpenRouterCredits(apiKey) {
|
|
186
|
+
return this.post("/v1/openrouter/credits", { apiKey });
|
|
187
|
+
}
|
|
188
|
+
async getOpenRouterCreditsValue(apiKey) {
|
|
189
|
+
const result = await this.getOpenRouterCredits(apiKey);
|
|
190
|
+
if (result.error) return { error: result.error, details: result.details };
|
|
191
|
+
const data = result.data;
|
|
192
|
+
let credits = pickFinite(
|
|
193
|
+
data?.credits,
|
|
194
|
+
data?.remaining_credits,
|
|
195
|
+
data?.remainingCredits,
|
|
196
|
+
data?.total_credits,
|
|
197
|
+
data?.totalCredits
|
|
198
|
+
);
|
|
199
|
+
if (!Number.isFinite(credits)) {
|
|
200
|
+
const nested = data?.data;
|
|
201
|
+
credits = pickFinite(
|
|
202
|
+
nested?.credits,
|
|
203
|
+
nested?.remaining_credits,
|
|
204
|
+
nested?.remainingCredits,
|
|
205
|
+
nested?.total_credits,
|
|
206
|
+
nested?.totalCredits
|
|
207
|
+
);
|
|
208
|
+
}
|
|
209
|
+
if (!Number.isFinite(credits)) {
|
|
210
|
+
const total = pickFinite(
|
|
211
|
+
data?.total_credits,
|
|
212
|
+
data?.totalCredits,
|
|
213
|
+
data?.data?.total_credits,
|
|
214
|
+
data?.data?.totalCredits
|
|
215
|
+
);
|
|
216
|
+
const spent = pickFinite(
|
|
217
|
+
data?.total_spent,
|
|
218
|
+
data?.totalSpent,
|
|
219
|
+
data?.data?.total_spent,
|
|
220
|
+
data?.data?.totalSpent
|
|
221
|
+
);
|
|
222
|
+
if (Number.isFinite(total) && Number.isFinite(spent)) {
|
|
223
|
+
credits = Math.max(0, total - spent);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
if (!Number.isFinite(credits)) {
|
|
227
|
+
return { error: "credits_unavailable" };
|
|
228
|
+
}
|
|
229
|
+
return { data: credits };
|
|
230
|
+
}
|
|
231
|
+
async getSolUsdPrice() {
|
|
232
|
+
return this.get("/v1/prices/sol");
|
|
233
|
+
}
|
|
234
|
+
async verifyTicket(token, options) {
|
|
235
|
+
const params = new URLSearchParams({ token });
|
|
236
|
+
if (options?.listingAccount) params.set("listing", options.listingAccount);
|
|
237
|
+
if (options?.wallet) params.set("wallet", options.wallet);
|
|
238
|
+
const response = await this.fetcher(`${this.baseUrl}/v1/verify?${params.toString()}`);
|
|
239
|
+
try {
|
|
240
|
+
const payload = await readJson(response);
|
|
241
|
+
return payload;
|
|
242
|
+
} catch (error) {
|
|
243
|
+
return {
|
|
244
|
+
isValid: false,
|
|
245
|
+
error: error instanceof Error ? error.message : "invalid_json_response"
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
async verifyRedeem(signature, options) {
|
|
250
|
+
const params = new URLSearchParams({ token: signature, mode: "redeem" });
|
|
251
|
+
if (options?.listingAccount) params.set("listing", options.listingAccount);
|
|
252
|
+
if (options?.wallet) params.set("wallet", options.wallet);
|
|
253
|
+
const maxAge = options?.maxAgeSec ?? options?.maxAge;
|
|
254
|
+
if (maxAge) params.set("maxAgeSec", String(maxAge));
|
|
255
|
+
if (options?.requireReview) params.set("requireReview", "true");
|
|
256
|
+
const response = await this.fetcher(`${this.baseUrl}/v1/verify?${params.toString()}`);
|
|
257
|
+
try {
|
|
258
|
+
const payload = await readJson(response);
|
|
259
|
+
return payload;
|
|
260
|
+
} catch (error) {
|
|
261
|
+
return {
|
|
262
|
+
isValid: false,
|
|
263
|
+
error: error instanceof Error ? error.message : "invalid_json_response"
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
async verifyReceipt(listingAccount, wallet, options) {
|
|
268
|
+
const params = new URLSearchParams({ listing: listingAccount, wallet, mode: "receipt" });
|
|
269
|
+
if (options?.minCount) params.set("minCount", String(options.minCount));
|
|
270
|
+
const maxAge = options?.maxAgeSec ?? options?.maxAge;
|
|
271
|
+
if (maxAge) params.set("maxAgeSec", String(maxAge));
|
|
272
|
+
const response = await this.fetcher(`${this.baseUrl}/v1/verify?${params.toString()}`);
|
|
273
|
+
try {
|
|
274
|
+
const payload = await readJson(response);
|
|
275
|
+
return payload;
|
|
276
|
+
} catch (error) {
|
|
277
|
+
return {
|
|
278
|
+
isValid: false,
|
|
279
|
+
error: error instanceof Error ? error.message : "invalid_json_response"
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
async get(path) {
|
|
284
|
+
const response = await this.fetcher(`${this.baseUrl}${path}`);
|
|
285
|
+
let payload = null;
|
|
286
|
+
try {
|
|
287
|
+
payload = await readJson(response);
|
|
288
|
+
} catch (error) {
|
|
289
|
+
const details = error instanceof Error && "details" in error ? error.details : void 0;
|
|
290
|
+
return { error: "invalid_json_response", details };
|
|
291
|
+
}
|
|
292
|
+
if (!response.ok) {
|
|
293
|
+
return { error: payload?.error || "request_failed", details: payload?.details };
|
|
294
|
+
}
|
|
295
|
+
if (!payload) {
|
|
296
|
+
return { error: "empty_response" };
|
|
297
|
+
}
|
|
298
|
+
return payload;
|
|
299
|
+
}
|
|
300
|
+
async post(path, body) {
|
|
301
|
+
const response = await this.fetcher(`${this.baseUrl}${path}`, {
|
|
302
|
+
method: "POST",
|
|
303
|
+
headers: { "Content-Type": "application/json" },
|
|
304
|
+
body: JSON.stringify(body)
|
|
305
|
+
});
|
|
306
|
+
let payload = null;
|
|
307
|
+
try {
|
|
308
|
+
payload = await readJson(response);
|
|
309
|
+
} catch (error) {
|
|
310
|
+
const details = error instanceof Error && "details" in error ? error.details : void 0;
|
|
311
|
+
return { error: "invalid_json_response", details };
|
|
312
|
+
}
|
|
313
|
+
if (!response.ok) {
|
|
314
|
+
return { error: payload?.error || "request_failed", details: payload?.details };
|
|
315
|
+
}
|
|
316
|
+
if (!payload) {
|
|
317
|
+
return { error: "empty_response" };
|
|
318
|
+
}
|
|
319
|
+
return payload;
|
|
320
|
+
}
|
|
321
|
+
};
|
|
322
|
+
var VibeRegistry = class {
|
|
323
|
+
client;
|
|
324
|
+
constructor(options = {}) {
|
|
325
|
+
this.client = new VibeClient(options);
|
|
326
|
+
}
|
|
327
|
+
async listListings(filters = {}) {
|
|
328
|
+
return unwrap(await this.client.listListings(filters));
|
|
329
|
+
}
|
|
330
|
+
async listAgents(filters = {}) {
|
|
331
|
+
return unwrap(await this.client.listListings({ ...filters, type: "agent" }));
|
|
332
|
+
}
|
|
333
|
+
async listHumans(filters = {}) {
|
|
334
|
+
return unwrap(await this.client.listListings({ ...filters, type: "human" }));
|
|
335
|
+
}
|
|
336
|
+
async getListing(id) {
|
|
337
|
+
return unwrap(await this.client.getListing(id));
|
|
338
|
+
}
|
|
339
|
+
async getListingReviews(listingId, options) {
|
|
340
|
+
return unwrap(await this.client.getListingReviews(listingId, options));
|
|
341
|
+
}
|
|
342
|
+
async createListingReview(listingId, payload) {
|
|
343
|
+
return unwrap(await this.client.createListingReview(listingId, payload));
|
|
344
|
+
}
|
|
345
|
+
async respondToListingReview(listingId, reviewId, payload) {
|
|
346
|
+
return unwrap(await this.client.respondToListingReview(listingId, reviewId, payload));
|
|
347
|
+
}
|
|
348
|
+
async updateListingVersion(listingId, payload) {
|
|
349
|
+
return unwrap(await this.client.updateListingVersion(listingId, payload));
|
|
350
|
+
}
|
|
351
|
+
async getLeaderboard(filters = {}) {
|
|
352
|
+
return unwrap(await this.client.getLeaderboard(filters));
|
|
353
|
+
}
|
|
354
|
+
async getListingAnalytics(listingId, window = "7d") {
|
|
355
|
+
return unwrap(await this.client.getListingAnalytics(listingId, window));
|
|
356
|
+
}
|
|
357
|
+
async getListingBuybacks(listingId, limit = 20) {
|
|
358
|
+
return unwrap(await this.client.getListingBuybacks(listingId, limit));
|
|
359
|
+
}
|
|
360
|
+
async getOpenRouterCredits(apiKey) {
|
|
361
|
+
return unwrap(await this.client.getOpenRouterCredits(apiKey));
|
|
362
|
+
}
|
|
363
|
+
async getOpenRouterCreditsValue(apiKey) {
|
|
364
|
+
const result = await this.client.getOpenRouterCreditsValue(apiKey);
|
|
365
|
+
return unwrap(result);
|
|
366
|
+
}
|
|
367
|
+
async getSolUsdPrice() {
|
|
368
|
+
return unwrap(await this.client.getSolUsdPrice());
|
|
369
|
+
}
|
|
370
|
+
async verifyReceipt(listingAccount, wallet, options) {
|
|
371
|
+
const result = await this.client.verifyReceipt(listingAccount, wallet, options);
|
|
372
|
+
if (result.error) {
|
|
373
|
+
throw new Error(result.error);
|
|
374
|
+
}
|
|
375
|
+
return result;
|
|
376
|
+
}
|
|
377
|
+
async verifyRedeem(signature, options) {
|
|
378
|
+
const result = await this.client.verifyRedeem(signature, options);
|
|
379
|
+
if (result.error) {
|
|
380
|
+
throw new Error(result.error);
|
|
381
|
+
}
|
|
382
|
+
return result;
|
|
383
|
+
}
|
|
384
|
+
};
|
|
385
|
+
var buildShareLink = (listingId, options = {}) => {
|
|
386
|
+
const base = withTrailingSlash(options.webBaseUrl || DEFAULT_WEB_BASE);
|
|
387
|
+
const ref = options.ref || generateRef();
|
|
388
|
+
const params = new URLSearchParams({ listing: listingId, ref });
|
|
389
|
+
if (options.source) params.set("utm_source", options.source);
|
|
390
|
+
if (options.medium) params.set("utm_medium", options.medium);
|
|
391
|
+
if (options.campaign) params.set("utm_campaign", options.campaign);
|
|
392
|
+
if (options.content) params.set("utm_content", options.content);
|
|
393
|
+
return `${base}/?${params.toString()}`;
|
|
394
|
+
};
|
|
395
|
+
var buildShareCopy = (listing, options = {}) => {
|
|
396
|
+
const link = buildShareLink(listing.id, options);
|
|
397
|
+
return `${listing.name} \u2014 ${listing.tagline}. Try it on VIBEIAO: ${link}`;
|
|
398
|
+
};
|
|
399
|
+
var buildBadgeMarkdown = (listing, options = {}) => {
|
|
400
|
+
const link = buildShareLink(listing.id, options);
|
|
401
|
+
const label = `VIBEIAO \u2022 ${listing.name}`;
|
|
402
|
+
return `[${label}](${link})`;
|
|
403
|
+
};
|
|
404
|
+
var createCampaign = (listingId, options = {}) => {
|
|
405
|
+
const id = options.ref || generateRef();
|
|
406
|
+
const url = buildShareLink(listingId, { ...options, ref: id });
|
|
407
|
+
return {
|
|
408
|
+
id,
|
|
409
|
+
url,
|
|
410
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
411
|
+
};
|
|
412
|
+
};
|
|
413
|
+
var buildRaydiumSwapUrl = (tokenMint) => `https://raydium.io/swap/?inputCurrency=sol&outputCurrency=${tokenMint}`;
|
|
414
|
+
var buildJupiterSwapUrl = (tokenMint) => `https://jup.ag/swap/SOL-${tokenMint}`;
|
|
415
|
+
var buildTradeLinks = (tokenMint) => ({
|
|
416
|
+
raydium: buildRaydiumSwapUrl(tokenMint),
|
|
417
|
+
jupiter: buildJupiterSwapUrl(tokenMint)
|
|
418
|
+
});
|
|
419
|
+
var getResourceSnapshot = async (options) => {
|
|
420
|
+
const { connection, wallet, tokenMints, openRouterApiKey, apiBase } = options;
|
|
421
|
+
const snapshot = { updatedAt: Date.now() };
|
|
422
|
+
snapshot.solBalance = await fetchSolBalance(connection, wallet);
|
|
423
|
+
if (tokenMints?.length) {
|
|
424
|
+
snapshot.tokenBalances = await fetchTokenBalances(connection, wallet, tokenMints);
|
|
425
|
+
}
|
|
426
|
+
if (openRouterApiKey) {
|
|
427
|
+
const client = new VibeClient({ baseUrl: apiBase });
|
|
428
|
+
const credits = await client.getOpenRouterCreditsValue(openRouterApiKey);
|
|
429
|
+
if (credits.error) {
|
|
430
|
+
throw new Error(credits.error);
|
|
431
|
+
}
|
|
432
|
+
snapshot.openRouterCredits = credits.data;
|
|
433
|
+
}
|
|
434
|
+
return snapshot;
|
|
435
|
+
};
|
|
436
|
+
export {
|
|
437
|
+
ReviewGate,
|
|
438
|
+
SelfReliance,
|
|
439
|
+
VIBEIAO_IDL,
|
|
440
|
+
VibeClient,
|
|
441
|
+
VibeRegistry,
|
|
442
|
+
buildBadgeMarkdown,
|
|
443
|
+
buildClaimMessage,
|
|
444
|
+
buildJupiterSwapUrl,
|
|
445
|
+
buildListingVersionMessage,
|
|
446
|
+
buildMemoryPingMessage,
|
|
447
|
+
buildOwnerTransferMessage,
|
|
448
|
+
buildRaydiumSwapUrl,
|
|
449
|
+
buildReviewPrompt,
|
|
450
|
+
buildReviewRequired,
|
|
451
|
+
buildReviewResponseMessage,
|
|
452
|
+
buildShareCopy,
|
|
453
|
+
buildShareLink,
|
|
454
|
+
buildTradeLinks,
|
|
455
|
+
createAutoSelfReliance,
|
|
456
|
+
createCampaign,
|
|
457
|
+
createSelfRelianceMonitor,
|
|
458
|
+
createSelfReliancePolicy,
|
|
459
|
+
createSurvivalMiddleware,
|
|
460
|
+
fetchSolBalance,
|
|
461
|
+
fetchTokenBalance,
|
|
462
|
+
fetchTokenBalances,
|
|
463
|
+
getResourceSnapshot,
|
|
464
|
+
withSurvival
|
|
465
|
+
};
|
package/dist/memory.d.ts
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
type MemorySectionKey = 'Survival Priority' | 'Project Status' | 'Lessons Learned' | 'User Archetype' | 'Key Secrets' | 'Active Goals';
|
|
2
|
+
type MemorySections = Partial<Record<MemorySectionKey, string>>;
|
|
3
|
+
type MemorySearchResult = {
|
|
4
|
+
file: string;
|
|
5
|
+
score: number;
|
|
6
|
+
snippet: string;
|
|
7
|
+
};
|
|
8
|
+
type RecallSnippet = {
|
|
9
|
+
file: string;
|
|
10
|
+
snippet: string;
|
|
11
|
+
};
|
|
12
|
+
type RecallPayload = {
|
|
13
|
+
query: string;
|
|
14
|
+
snippets: RecallSnippet[];
|
|
15
|
+
createdAt: number;
|
|
16
|
+
};
|
|
17
|
+
type MemorySearchOptions = {
|
|
18
|
+
maxResults?: number;
|
|
19
|
+
includeDaily?: boolean;
|
|
20
|
+
includeCore?: boolean;
|
|
21
|
+
};
|
|
22
|
+
type MemoryBackupOptions = {
|
|
23
|
+
root?: string;
|
|
24
|
+
backupDir?: string;
|
|
25
|
+
key?: string;
|
|
26
|
+
keyFile?: string;
|
|
27
|
+
retention?: number;
|
|
28
|
+
encrypt?: boolean;
|
|
29
|
+
};
|
|
30
|
+
type MemoryBackupResult = {
|
|
31
|
+
path: string;
|
|
32
|
+
createdAt: string;
|
|
33
|
+
sizeBytes: number;
|
|
34
|
+
encrypted: boolean;
|
|
35
|
+
};
|
|
36
|
+
type MemoryBackupSchedulerOptions = MemoryBackupOptions & {
|
|
37
|
+
intervalMs?: number;
|
|
38
|
+
onSuccess?: (result: MemoryBackupResult) => void;
|
|
39
|
+
onError?: (error: Error) => void;
|
|
40
|
+
};
|
|
41
|
+
type MemoryRecallOptions = MemorySearchOptions & {
|
|
42
|
+
query: string;
|
|
43
|
+
root?: string;
|
|
44
|
+
maxChars?: number;
|
|
45
|
+
prefix?: string;
|
|
46
|
+
};
|
|
47
|
+
type MemoryRecallResult = {
|
|
48
|
+
prompt: string;
|
|
49
|
+
snippets: RecallSnippet[];
|
|
50
|
+
createdAt: number;
|
|
51
|
+
};
|
|
52
|
+
type MemoryDistillSchedulerOptions = {
|
|
53
|
+
root?: string;
|
|
54
|
+
intervalMs?: number;
|
|
55
|
+
ledgers?: number;
|
|
56
|
+
buildSummary: (inputs: {
|
|
57
|
+
ledgers: Array<{
|
|
58
|
+
file: string;
|
|
59
|
+
content: string;
|
|
60
|
+
}>;
|
|
61
|
+
memory: string;
|
|
62
|
+
}) => MemorySections | Promise<MemorySections>;
|
|
63
|
+
onSuccess?: (summary: MemorySections) => void;
|
|
64
|
+
onError?: (error: Error) => void;
|
|
65
|
+
};
|
|
66
|
+
declare const MEMORY_SCHEMA_VERSION = 1;
|
|
67
|
+
declare const resolveMemoryRoot: (root?: string) => string;
|
|
68
|
+
declare const getDailyLedgerPath: (root?: string, date?: Date) => string;
|
|
69
|
+
declare const readMemoryVersion: (root?: string) => Promise<number>;
|
|
70
|
+
declare const writeMemoryVersion: (root?: string, version?: number) => Promise<{
|
|
71
|
+
version: number;
|
|
72
|
+
updatedAt: string;
|
|
73
|
+
}>;
|
|
74
|
+
declare const ensureSurvivalDirective: (root?: string) => Promise<string>;
|
|
75
|
+
declare const ensureMemoryLayout: (root?: string) => Promise<string>;
|
|
76
|
+
declare const upgradeMemoryLayout: (root?: string, targetVersion?: number) => Promise<{
|
|
77
|
+
root: string;
|
|
78
|
+
from: number;
|
|
79
|
+
to: number;
|
|
80
|
+
}>;
|
|
81
|
+
declare const appendDailyLog: (entry: string, options?: {
|
|
82
|
+
root?: string;
|
|
83
|
+
date?: Date;
|
|
84
|
+
}) => Promise<string>;
|
|
85
|
+
declare const readMemorySummary: (root?: string) => Promise<string>;
|
|
86
|
+
declare const readIdentityStack: (root?: string) => Promise<{
|
|
87
|
+
identity: string;
|
|
88
|
+
soul: string;
|
|
89
|
+
user: string;
|
|
90
|
+
}>;
|
|
91
|
+
declare const updateMemorySummary: (sections: MemorySections, root?: string) => Promise<string>;
|
|
92
|
+
declare const searchMemory: (query: string, options?: MemorySearchOptions, root?: string) => Promise<MemorySearchResult[]>;
|
|
93
|
+
declare const buildRecallContext: (options: MemoryRecallOptions) => Promise<MemoryRecallResult>;
|
|
94
|
+
declare const readRecentLedgers: (count?: number, root?: string) => Promise<{
|
|
95
|
+
file: string;
|
|
96
|
+
content: string;
|
|
97
|
+
}[]>;
|
|
98
|
+
declare const distillMemory: (summary: MemorySections, root?: string) => Promise<string>;
|
|
99
|
+
declare const createMemoryDistillScheduler: (options: MemoryDistillSchedulerOptions) => {
|
|
100
|
+
start: () => Promise<void>;
|
|
101
|
+
stop: () => void;
|
|
102
|
+
runOnce: () => Promise<void>;
|
|
103
|
+
};
|
|
104
|
+
declare const createMemoryBackup: (options?: MemoryBackupOptions) => Promise<MemoryBackupResult>;
|
|
105
|
+
declare const createMemoryBackupScheduler: (options?: MemoryBackupSchedulerOptions) => {
|
|
106
|
+
start: () => Promise<void>;
|
|
107
|
+
stop: () => void;
|
|
108
|
+
runOnce: () => Promise<void>;
|
|
109
|
+
};
|
|
110
|
+
declare const getMemoryLastUpdatedAt: (root?: string) => Promise<string>;
|
|
111
|
+
declare const getMemoryFreshness: (root?: string, staleHours?: number) => Promise<{
|
|
112
|
+
status: "unknown";
|
|
113
|
+
lastUpdatedAt: any;
|
|
114
|
+
} | {
|
|
115
|
+
status: "fresh" | "stale";
|
|
116
|
+
lastUpdatedAt: string;
|
|
117
|
+
}>;
|
|
118
|
+
declare const memoryCompliance: (root?: string, staleHours?: number) => Promise<{
|
|
119
|
+
ok: boolean;
|
|
120
|
+
status: "missing_survival";
|
|
121
|
+
lastUpdatedAt: any;
|
|
122
|
+
warning: string;
|
|
123
|
+
} | {
|
|
124
|
+
ok: boolean;
|
|
125
|
+
status: "fresh";
|
|
126
|
+
lastUpdatedAt: string;
|
|
127
|
+
warning: any;
|
|
128
|
+
} | {
|
|
129
|
+
ok: boolean;
|
|
130
|
+
status: "stale";
|
|
131
|
+
lastUpdatedAt: string;
|
|
132
|
+
warning: string;
|
|
133
|
+
} | {
|
|
134
|
+
ok: boolean;
|
|
135
|
+
status: "unknown";
|
|
136
|
+
lastUpdatedAt: any;
|
|
137
|
+
warning: string;
|
|
138
|
+
}>;
|
|
139
|
+
|
|
140
|
+
export { MEMORY_SCHEMA_VERSION, type MemoryBackupOptions, type MemoryBackupResult, type MemoryBackupSchedulerOptions, type MemoryDistillSchedulerOptions, type MemoryRecallOptions, type MemoryRecallResult, type MemorySearchOptions, type MemorySearchResult, type MemorySectionKey, type MemorySections, type RecallPayload, type RecallSnippet, appendDailyLog, buildRecallContext, createMemoryBackup, createMemoryBackupScheduler, createMemoryDistillScheduler, distillMemory, ensureMemoryLayout, ensureSurvivalDirective, getDailyLedgerPath, getMemoryFreshness, getMemoryLastUpdatedAt, memoryCompliance, readIdentityStack, readMemorySummary, readMemoryVersion, readRecentLedgers, resolveMemoryRoot, searchMemory, updateMemorySummary, upgradeMemoryLayout, writeMemoryVersion };
|