@vibeiao/sdk 0.1.41 → 0.1.43
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 +17 -0
- package/dist/chunk-YJ7FO5ZB.js +479 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -2
- package/dist/reflection.d.ts +33 -1
- package/dist/reflection.js +1 -1
- package/dist/treasuryGuardian.d.ts +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -279,6 +279,23 @@ const result = await registry.runReflectionCycle({
|
|
|
279
279
|
console.log(result);
|
|
280
280
|
```
|
|
281
281
|
|
|
282
|
+
You can also enable revenue-movement reflection in the same loop:
|
|
283
|
+
|
|
284
|
+
```ts
|
|
285
|
+
const result = await registry.runReflectionCycle({
|
|
286
|
+
// ...review reflection options
|
|
287
|
+
revenueReflection: {
|
|
288
|
+
enabled: true,
|
|
289
|
+
minAbsoluteDelta: 1, // trigger at >= +1/-1 revenue move
|
|
290
|
+
minRelativeDelta: 0.05, // or >= 5% move
|
|
291
|
+
minRelativeBaselineRevenue: 1, // disable % trigger below baseline to avoid tiny-denominator noise
|
|
292
|
+
onSignal: async (signal) => {
|
|
293
|
+
console.log('Revenue movement signal:', signal);
|
|
294
|
+
},
|
|
295
|
+
},
|
|
296
|
+
});
|
|
297
|
+
```
|
|
298
|
+
|
|
282
299
|
### Example: create a campaign + post
|
|
283
300
|
|
|
284
301
|
```ts
|
|
@@ -0,0 +1,479 @@
|
|
|
1
|
+
// src/reflection.ts
|
|
2
|
+
var clamp01 = (value) => Math.max(0, Math.min(1, value));
|
|
3
|
+
var toLower = (value) => String(value || "").toLowerCase();
|
|
4
|
+
var hasAny = (text, patterns) => patterns.some((pattern) => text.includes(pattern));
|
|
5
|
+
var buildCategoryRules = () => ({
|
|
6
|
+
bug: [
|
|
7
|
+
"bug",
|
|
8
|
+
"broken",
|
|
9
|
+
"error",
|
|
10
|
+
"wrong",
|
|
11
|
+
"not work",
|
|
12
|
+
"doesnt work",
|
|
13
|
+
"doesn't work",
|
|
14
|
+
"failed",
|
|
15
|
+
"fail",
|
|
16
|
+
"crash",
|
|
17
|
+
"exception",
|
|
18
|
+
"stack trace"
|
|
19
|
+
],
|
|
20
|
+
reliability: [
|
|
21
|
+
"downtime",
|
|
22
|
+
"unstable",
|
|
23
|
+
"timeout",
|
|
24
|
+
"rate limit",
|
|
25
|
+
"unavailable",
|
|
26
|
+
"503",
|
|
27
|
+
"502",
|
|
28
|
+
"500",
|
|
29
|
+
"disconnect",
|
|
30
|
+
"latency spike"
|
|
31
|
+
],
|
|
32
|
+
ux: [
|
|
33
|
+
"confusing",
|
|
34
|
+
"hard to use",
|
|
35
|
+
"difficult",
|
|
36
|
+
"unclear",
|
|
37
|
+
"friction",
|
|
38
|
+
"ui",
|
|
39
|
+
"ux",
|
|
40
|
+
"layout",
|
|
41
|
+
"discoverability"
|
|
42
|
+
],
|
|
43
|
+
pricing: [
|
|
44
|
+
"price",
|
|
45
|
+
"pricing",
|
|
46
|
+
"expensive",
|
|
47
|
+
"cost",
|
|
48
|
+
"overpriced",
|
|
49
|
+
"cheap",
|
|
50
|
+
"value",
|
|
51
|
+
"too much"
|
|
52
|
+
],
|
|
53
|
+
feature: [
|
|
54
|
+
"feature",
|
|
55
|
+
"please add",
|
|
56
|
+
"can you add",
|
|
57
|
+
"would like",
|
|
58
|
+
"request",
|
|
59
|
+
"support for",
|
|
60
|
+
"need support",
|
|
61
|
+
"enhancement"
|
|
62
|
+
],
|
|
63
|
+
praise: [
|
|
64
|
+
"great",
|
|
65
|
+
"excellent",
|
|
66
|
+
"love",
|
|
67
|
+
"awesome",
|
|
68
|
+
"perfect",
|
|
69
|
+
"helpful",
|
|
70
|
+
"works well"
|
|
71
|
+
]
|
|
72
|
+
});
|
|
73
|
+
var categoryPriorityWeight = {
|
|
74
|
+
bug: 0.38,
|
|
75
|
+
reliability: 0.34,
|
|
76
|
+
ux: 0.22,
|
|
77
|
+
pricing: 0.16,
|
|
78
|
+
feature: 0.14,
|
|
79
|
+
praise: 0.04,
|
|
80
|
+
noise: -0.18
|
|
81
|
+
};
|
|
82
|
+
var defaultStatusByCategory = {
|
|
83
|
+
bug: "accepted",
|
|
84
|
+
reliability: "accepted",
|
|
85
|
+
ux: "planned",
|
|
86
|
+
pricing: "planned",
|
|
87
|
+
feature: "planned",
|
|
88
|
+
praise: "addressed",
|
|
89
|
+
noise: "wont_fix"
|
|
90
|
+
};
|
|
91
|
+
var defaultCommentByCategory = (category, review) => {
|
|
92
|
+
if (category === "bug" || category === "reliability") {
|
|
93
|
+
return `Acknowledged. This issue is now in our fix queue with priority. Thanks for the precise signal.`;
|
|
94
|
+
}
|
|
95
|
+
if (category === "ux") {
|
|
96
|
+
return `Acknowledged. We will improve usability/clarity in the next iteration.`;
|
|
97
|
+
}
|
|
98
|
+
if (category === "pricing") {
|
|
99
|
+
return `Acknowledged. We are reviewing pricing against value and usage outcomes.`;
|
|
100
|
+
}
|
|
101
|
+
if (category === "feature") {
|
|
102
|
+
return `Acknowledged. Feature request recorded and prioritized with current roadmap constraints.`;
|
|
103
|
+
}
|
|
104
|
+
if (category === "praise") {
|
|
105
|
+
return `Thanks for the feedback. We'll continue shipping improvements on top of this version (${review.app_version}).`;
|
|
106
|
+
}
|
|
107
|
+
return `Reviewed. No concrete or reproducible issue found from this report.`;
|
|
108
|
+
};
|
|
109
|
+
var inferCategory = (review) => {
|
|
110
|
+
const text = `${toLower(review.comment)} ${toLower(review.agent_response_comment)}`.trim();
|
|
111
|
+
const rating = Number(review.rating);
|
|
112
|
+
const rules = buildCategoryRules();
|
|
113
|
+
if (hasAny(text, rules.bug)) return "bug";
|
|
114
|
+
if (hasAny(text, rules.reliability)) return "reliability";
|
|
115
|
+
if (hasAny(text, rules.ux)) return "ux";
|
|
116
|
+
if (hasAny(text, rules.pricing)) return "pricing";
|
|
117
|
+
if (hasAny(text, rules.feature)) return "feature";
|
|
118
|
+
if (hasAny(text, rules.praise) || rating >= 4.5) return "praise";
|
|
119
|
+
if (!text || text.length < 12) return "noise";
|
|
120
|
+
if (rating <= 2) return "bug";
|
|
121
|
+
if (rating >= 4) return "praise";
|
|
122
|
+
return "feature";
|
|
123
|
+
};
|
|
124
|
+
var ratingWeight = (rating) => {
|
|
125
|
+
if (rating <= 1) return 1;
|
|
126
|
+
if (rating <= 2) return 0.82;
|
|
127
|
+
if (rating <= 3) return 0.55;
|
|
128
|
+
if (rating <= 4) return 0.3;
|
|
129
|
+
return 0.18;
|
|
130
|
+
};
|
|
131
|
+
var recencyWeight = (createdAt, nowMs) => {
|
|
132
|
+
const createdMs = new Date(createdAt).getTime();
|
|
133
|
+
if (!Number.isFinite(createdMs)) return 0;
|
|
134
|
+
const ageDays = (nowMs - createdMs) / (1e3 * 60 * 60 * 24);
|
|
135
|
+
if (ageDays <= 1) return 0.1;
|
|
136
|
+
if (ageDays <= 7) return 0.05;
|
|
137
|
+
if (ageDays <= 30) return 0.02;
|
|
138
|
+
return 0;
|
|
139
|
+
};
|
|
140
|
+
var classifyReview = (review) => inferCategory(review);
|
|
141
|
+
var scoreReviewPriority = (review, options = {}) => {
|
|
142
|
+
const category = classifyReview(review);
|
|
143
|
+
const nowMs = options.nowMs ?? Date.now();
|
|
144
|
+
const ratingScore = ratingWeight(Number(review.rating));
|
|
145
|
+
const categoryScore = categoryPriorityWeight[category];
|
|
146
|
+
const unresolvedBonus = review.agent_response_status ? 0 : 0.12;
|
|
147
|
+
const recency = recencyWeight(review.created_at, nowMs);
|
|
148
|
+
return clamp01(ratingScore + categoryScore + unresolvedBonus + recency);
|
|
149
|
+
};
|
|
150
|
+
var buildReflectionCandidate = (review, options = {}) => {
|
|
151
|
+
const category = classifyReview(review);
|
|
152
|
+
const priority = scoreReviewPriority(review, options);
|
|
153
|
+
const suggestedStatus = defaultStatusByCategory[category];
|
|
154
|
+
const rationale = [
|
|
155
|
+
`category:${category}`,
|
|
156
|
+
`rating:${Number(review.rating).toFixed(1)}`,
|
|
157
|
+
review.agent_response_status ? "already_responded" : "pending_response"
|
|
158
|
+
];
|
|
159
|
+
if (!review.redeem_signature) rationale.push("offchain_review_signal");
|
|
160
|
+
return {
|
|
161
|
+
review,
|
|
162
|
+
category,
|
|
163
|
+
priority,
|
|
164
|
+
suggestedStatus,
|
|
165
|
+
suggestedComment: defaultCommentByCategory(category, review),
|
|
166
|
+
rationale
|
|
167
|
+
};
|
|
168
|
+
};
|
|
169
|
+
var emptySummary = () => ({
|
|
170
|
+
total: 0,
|
|
171
|
+
byCategory: {
|
|
172
|
+
bug: 0,
|
|
173
|
+
reliability: 0,
|
|
174
|
+
ux: 0,
|
|
175
|
+
pricing: 0,
|
|
176
|
+
feature: 0,
|
|
177
|
+
praise: 0,
|
|
178
|
+
noise: 0
|
|
179
|
+
},
|
|
180
|
+
averagePriority: 0,
|
|
181
|
+
topPriority: 0
|
|
182
|
+
});
|
|
183
|
+
var buildReflectionBacklog = (reviews, options = {}) => {
|
|
184
|
+
const nowMs = options.nowMs ?? Date.now();
|
|
185
|
+
const source = options.includeResponded ? reviews : reviews.filter((review) => !review.agent_response_status);
|
|
186
|
+
const candidates = source.map((review) => buildReflectionCandidate(review, { nowMs })).sort((a, b) => b.priority - a.priority);
|
|
187
|
+
const summary = emptySummary();
|
|
188
|
+
summary.total = candidates.length;
|
|
189
|
+
if (!candidates.length) {
|
|
190
|
+
return {
|
|
191
|
+
listingId: reviews[0]?.listing_id || "",
|
|
192
|
+
generatedAt: new Date(nowMs).toISOString(),
|
|
193
|
+
candidates,
|
|
194
|
+
summary
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
let totalPriority = 0;
|
|
198
|
+
candidates.forEach((candidate) => {
|
|
199
|
+
summary.byCategory[candidate.category] += 1;
|
|
200
|
+
totalPriority += candidate.priority;
|
|
201
|
+
summary.topPriority = Math.max(summary.topPriority, candidate.priority);
|
|
202
|
+
});
|
|
203
|
+
summary.averagePriority = totalPriority / candidates.length;
|
|
204
|
+
return {
|
|
205
|
+
listingId: candidates[0].review.listing_id,
|
|
206
|
+
generatedAt: new Date(nowMs).toISOString(),
|
|
207
|
+
candidates,
|
|
208
|
+
summary
|
|
209
|
+
};
|
|
210
|
+
};
|
|
211
|
+
var reflectionResponseMessage = (reviewId, status, timestamp) => `VIBEIAO-REVIEW-RESPONSE:${reviewId}:${status}:${timestamp}`;
|
|
212
|
+
var reflectionVersionMessage = (listingId, version, timestamp) => `VIBEIAO-LISTING-VERSION:${listingId}:${version}:${timestamp}`;
|
|
213
|
+
var parseVersion = (value) => {
|
|
214
|
+
const match = String(value || "").trim().match(/^(\d+)\.(\d+)\.(\d+)$/);
|
|
215
|
+
if (!match) return null;
|
|
216
|
+
return {
|
|
217
|
+
major: Number(match[1]),
|
|
218
|
+
minor: Number(match[2]),
|
|
219
|
+
patch: Number(match[3])
|
|
220
|
+
};
|
|
221
|
+
};
|
|
222
|
+
var bumpSemver = (currentVersion, bump = "patch") => {
|
|
223
|
+
const parsed = parseVersion(currentVersion);
|
|
224
|
+
if (!parsed) return null;
|
|
225
|
+
if (bump === "major") return `${parsed.major + 1}.0.0`;
|
|
226
|
+
if (bump === "minor") return `${parsed.major}.${parsed.minor + 1}.0`;
|
|
227
|
+
return `${parsed.major}.${parsed.minor}.${parsed.patch + 1}`;
|
|
228
|
+
};
|
|
229
|
+
var toFiniteNumber = (value) => {
|
|
230
|
+
const n = typeof value === "number" ? value : Number(value);
|
|
231
|
+
return Number.isFinite(n) ? n : null;
|
|
232
|
+
};
|
|
233
|
+
var buildRevenueSnapshot = (listing, nowMs) => {
|
|
234
|
+
const revenue = toFiniteNumber(listing.revenue);
|
|
235
|
+
if (revenue === null) return null;
|
|
236
|
+
const targetRevenue = toFiniteNumber(listing.target_revenue ?? listing.targetRevenue) ?? void 0;
|
|
237
|
+
const tickets = toFiniteNumber(listing.tickets) ?? void 0;
|
|
238
|
+
return {
|
|
239
|
+
revenue,
|
|
240
|
+
targetRevenue,
|
|
241
|
+
tickets,
|
|
242
|
+
capturedAt: new Date(nowMs).toISOString()
|
|
243
|
+
};
|
|
244
|
+
};
|
|
245
|
+
var evaluateRevenueMovement = (previous, current, options) => {
|
|
246
|
+
const minAbsoluteDelta = Math.max(0, options?.minAbsoluteDelta ?? 0.5);
|
|
247
|
+
const minRelativeDelta = Math.max(0, options?.minRelativeDelta ?? 0.03);
|
|
248
|
+
const minRelativeBaselineRevenue = Math.max(0, options?.minRelativeBaselineRevenue ?? 1);
|
|
249
|
+
const flatBand = Math.max(0, options?.flatBand ?? 5e-3);
|
|
250
|
+
const deltaAbsolute = current.revenue - previous.revenue;
|
|
251
|
+
const baseline = Math.max(Math.abs(previous.revenue), 1e-9);
|
|
252
|
+
const allowRelative = baseline >= minRelativeBaselineRevenue;
|
|
253
|
+
const deltaRelativeRaw = allowRelative ? deltaAbsolute / baseline : null;
|
|
254
|
+
const deltaRelative = deltaRelativeRaw !== null && Number.isFinite(deltaRelativeRaw) ? deltaRelativeRaw : null;
|
|
255
|
+
let direction = "flat";
|
|
256
|
+
if (Math.abs(deltaAbsolute) > flatBand) direction = deltaAbsolute > 0 ? "up" : "down";
|
|
257
|
+
const absTriggered = Math.abs(deltaAbsolute) >= minAbsoluteDelta;
|
|
258
|
+
const relTriggered = deltaRelative !== null && Math.abs(deltaRelative) >= minRelativeDelta;
|
|
259
|
+
const thresholdTriggered = absTriggered || relTriggered;
|
|
260
|
+
const reasonParts = [
|
|
261
|
+
`delta=${deltaAbsolute.toFixed(4)}`,
|
|
262
|
+
deltaRelative === null ? "deltaPct=n/a" : `deltaPct=${(deltaRelative * 100).toFixed(2)}%`,
|
|
263
|
+
`thresholdAbs>=${minAbsoluteDelta}`,
|
|
264
|
+
`thresholdPct>=${(minRelativeDelta * 100).toFixed(2)}%`,
|
|
265
|
+
`relativeBaseline>=${minRelativeBaselineRevenue}`
|
|
266
|
+
];
|
|
267
|
+
return {
|
|
268
|
+
direction,
|
|
269
|
+
deltaAbsolute,
|
|
270
|
+
deltaRelative,
|
|
271
|
+
previousRevenue: previous.revenue,
|
|
272
|
+
currentRevenue: current.revenue,
|
|
273
|
+
thresholdTriggered,
|
|
274
|
+
reason: reasonParts.join(", "),
|
|
275
|
+
capturedAt: current.capturedAt
|
|
276
|
+
};
|
|
277
|
+
};
|
|
278
|
+
var dedupe = (values, max = 500) => {
|
|
279
|
+
const seen = /* @__PURE__ */ new Set();
|
|
280
|
+
const result = [];
|
|
281
|
+
for (const value of values) {
|
|
282
|
+
const key = String(value || "").trim();
|
|
283
|
+
if (!key || seen.has(key)) continue;
|
|
284
|
+
seen.add(key);
|
|
285
|
+
result.push(key);
|
|
286
|
+
}
|
|
287
|
+
return result.slice(-max);
|
|
288
|
+
};
|
|
289
|
+
var unwrap = (response) => {
|
|
290
|
+
if (response.error) {
|
|
291
|
+
throw new Error(response.error);
|
|
292
|
+
}
|
|
293
|
+
return response.data;
|
|
294
|
+
};
|
|
295
|
+
var buildMemoryMarkdown = (listingId, plan, acted, updatedVersion, revenueSignal) => {
|
|
296
|
+
const lines = [
|
|
297
|
+
`## Reflection Cycle (${(/* @__PURE__ */ new Date()).toISOString()})`,
|
|
298
|
+
`- Listing: ${listingId}`,
|
|
299
|
+
`- Candidates: ${plan.summary.total}`,
|
|
300
|
+
`- Actions: ${acted.length}`,
|
|
301
|
+
`- Top priority: ${plan.summary.topPriority.toFixed(2)}`
|
|
302
|
+
];
|
|
303
|
+
if (updatedVersion) {
|
|
304
|
+
lines.push(`- Version bumped to: ${updatedVersion}`);
|
|
305
|
+
}
|
|
306
|
+
if (revenueSignal) {
|
|
307
|
+
const pct = revenueSignal.deltaRelative === null ? "n/a" : `${(revenueSignal.deltaRelative * 100).toFixed(2)}%`;
|
|
308
|
+
lines.push(
|
|
309
|
+
`- Revenue movement: ${revenueSignal.direction} (\u0394 ${revenueSignal.deltaAbsolute.toFixed(4)}, ${pct}) [triggered=${revenueSignal.thresholdTriggered}]`
|
|
310
|
+
);
|
|
311
|
+
}
|
|
312
|
+
acted.slice(0, 5).forEach((action) => {
|
|
313
|
+
lines.push(
|
|
314
|
+
`- Action ${action.reviewId}: ${action.category} (${action.priority.toFixed(2)}) -> ${action.status}`
|
|
315
|
+
);
|
|
316
|
+
});
|
|
317
|
+
return lines.join("\n");
|
|
318
|
+
};
|
|
319
|
+
var runReflectionCycle = async (options) => {
|
|
320
|
+
const now = options.now || Date.now;
|
|
321
|
+
const nowMs = now();
|
|
322
|
+
const maxReviews = Math.max(1, options.maxReviews ?? 100);
|
|
323
|
+
const maxActions = Math.max(1, options.maxActions ?? 3);
|
|
324
|
+
const minPriority = clamp01(options.minPriority ?? 0.35);
|
|
325
|
+
const loadedCheckpoint = options.store ? await options.store.load() : null;
|
|
326
|
+
const checkpoint = loadedCheckpoint || {};
|
|
327
|
+
const seenIds = new Set(checkpoint.processedReviewIds || []);
|
|
328
|
+
const revenueReflectionEnabled = options.revenueReflection?.enabled ?? false;
|
|
329
|
+
let revenueSnapshot;
|
|
330
|
+
let revenueSignal;
|
|
331
|
+
let revenueObserved = false;
|
|
332
|
+
let revenueTriggered = false;
|
|
333
|
+
const reviews = unwrap(
|
|
334
|
+
await options.client.getListingReviews(options.listingId, { limit: maxReviews, offset: 0 })
|
|
335
|
+
);
|
|
336
|
+
const filtered = reviews.filter((review) => {
|
|
337
|
+
if (!review?.id) return false;
|
|
338
|
+
if (seenIds.has(review.id)) return false;
|
|
339
|
+
if (review.agent_response_status) return false;
|
|
340
|
+
return true;
|
|
341
|
+
});
|
|
342
|
+
const plan = buildReflectionBacklog(filtered, { nowMs, includeResponded: false });
|
|
343
|
+
const candidates = plan.candidates.filter((candidate) => candidate.priority >= minPriority);
|
|
344
|
+
const selected = candidates.slice(0, maxActions);
|
|
345
|
+
if (revenueReflectionEnabled && options.client.getListing) {
|
|
346
|
+
try {
|
|
347
|
+
const listingResponse = await options.client.getListing(options.listingId);
|
|
348
|
+
const listing = unwrap(listingResponse);
|
|
349
|
+
const snapshot = buildRevenueSnapshot(listing, nowMs);
|
|
350
|
+
if (snapshot) {
|
|
351
|
+
revenueObserved = true;
|
|
352
|
+
revenueSnapshot = snapshot;
|
|
353
|
+
if (checkpoint.lastRevenueSnapshot) {
|
|
354
|
+
const signal = evaluateRevenueMovement(
|
|
355
|
+
checkpoint.lastRevenueSnapshot,
|
|
356
|
+
snapshot,
|
|
357
|
+
options.revenueReflection
|
|
358
|
+
);
|
|
359
|
+
revenueSignal = signal;
|
|
360
|
+
revenueTriggered = signal.thresholdTriggered;
|
|
361
|
+
if (signal.thresholdTriggered && options.revenueReflection?.onSignal) {
|
|
362
|
+
await options.revenueReflection.onSignal(signal);
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
} catch {
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
const actions = [];
|
|
370
|
+
for (const candidate of selected) {
|
|
371
|
+
const timestamp = now();
|
|
372
|
+
const message = reflectionResponseMessage(
|
|
373
|
+
candidate.review.id,
|
|
374
|
+
candidate.suggestedStatus,
|
|
375
|
+
timestamp
|
|
376
|
+
);
|
|
377
|
+
const signature = await options.signMessage(message);
|
|
378
|
+
await unwrap(
|
|
379
|
+
await options.client.respondToListingReview(options.listingId, candidate.review.id, {
|
|
380
|
+
wallet: options.wallet,
|
|
381
|
+
signature,
|
|
382
|
+
status: candidate.suggestedStatus,
|
|
383
|
+
comment: candidate.suggestedComment,
|
|
384
|
+
timestamp
|
|
385
|
+
})
|
|
386
|
+
);
|
|
387
|
+
actions.push({
|
|
388
|
+
reviewId: candidate.review.id,
|
|
389
|
+
category: candidate.category,
|
|
390
|
+
priority: candidate.priority,
|
|
391
|
+
status: candidate.suggestedStatus
|
|
392
|
+
});
|
|
393
|
+
}
|
|
394
|
+
let updatedVersion;
|
|
395
|
+
const versionUpdate = options.versionUpdate;
|
|
396
|
+
const allowVersionUpdate = Boolean(versionUpdate?.enabled);
|
|
397
|
+
if (allowVersionUpdate && options.client.updateListingVersion && actions.length > 0 && plan.summary.topPriority >= (versionUpdate?.minTopPriority ?? 0.6)) {
|
|
398
|
+
const listingResponse = options.client.getListing ? await options.client.getListing(options.listingId) : null;
|
|
399
|
+
const currentVersion = listingResponse?.data?.app_version || checkpoint.lastVersion || "1.0.0";
|
|
400
|
+
const nextVersion = versionUpdate?.nextVersion || bumpSemver(String(currentVersion), versionUpdate?.bump || "patch");
|
|
401
|
+
if (nextVersion) {
|
|
402
|
+
const timestamp = now();
|
|
403
|
+
const message = reflectionVersionMessage(options.listingId, nextVersion, timestamp);
|
|
404
|
+
const signature = await options.signMessage(message);
|
|
405
|
+
await unwrap(
|
|
406
|
+
await options.client.updateListingVersion(options.listingId, {
|
|
407
|
+
wallet: options.wallet,
|
|
408
|
+
signature,
|
|
409
|
+
version: nextVersion,
|
|
410
|
+
timestamp
|
|
411
|
+
})
|
|
412
|
+
);
|
|
413
|
+
updatedVersion = nextVersion;
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
const processedReviewIds = dedupe([
|
|
417
|
+
...checkpoint.processedReviewIds || [],
|
|
418
|
+
...filtered.map((review) => review.id)
|
|
419
|
+
]);
|
|
420
|
+
const lastReviewAt = reviews.map((review) => review.created_at).filter(Boolean).sort().at(-1);
|
|
421
|
+
const nextCheckpoint = {
|
|
422
|
+
...checkpoint,
|
|
423
|
+
processedReviewIds,
|
|
424
|
+
lastReviewAt: lastReviewAt || checkpoint.lastReviewAt,
|
|
425
|
+
lastVersion: updatedVersion || checkpoint.lastVersion,
|
|
426
|
+
lastRevenueSnapshot: revenueSnapshot || checkpoint.lastRevenueSnapshot,
|
|
427
|
+
updatedAt: new Date(nowMs).toISOString()
|
|
428
|
+
};
|
|
429
|
+
if (options.store) {
|
|
430
|
+
await options.store.save(nextCheckpoint);
|
|
431
|
+
}
|
|
432
|
+
if (options.appendMemoryLog) {
|
|
433
|
+
const includeRevenue = options.revenueReflection?.includeInMemoryLog ?? true;
|
|
434
|
+
const markdown = buildMemoryMarkdown(
|
|
435
|
+
options.listingId,
|
|
436
|
+
plan,
|
|
437
|
+
actions,
|
|
438
|
+
updatedVersion,
|
|
439
|
+
includeRevenue ? revenueSignal : void 0
|
|
440
|
+
);
|
|
441
|
+
await options.appendMemoryLog(markdown);
|
|
442
|
+
}
|
|
443
|
+
return {
|
|
444
|
+
listingId: options.listingId,
|
|
445
|
+
fetched: reviews.length,
|
|
446
|
+
considered: filtered.length,
|
|
447
|
+
acted: actions.length,
|
|
448
|
+
generatedAt: new Date(nowMs).toISOString(),
|
|
449
|
+
updatedVersion,
|
|
450
|
+
checkpoint: nextCheckpoint,
|
|
451
|
+
actions,
|
|
452
|
+
summary: plan.summary,
|
|
453
|
+
revenueReflection: {
|
|
454
|
+
observed: revenueObserved,
|
|
455
|
+
triggered: revenueTriggered,
|
|
456
|
+
signal: revenueSignal,
|
|
457
|
+
snapshot: revenueSnapshot
|
|
458
|
+
}
|
|
459
|
+
};
|
|
460
|
+
};
|
|
461
|
+
var createInMemoryReflectionStore = (initial = null) => {
|
|
462
|
+
let checkpoint = initial;
|
|
463
|
+
return {
|
|
464
|
+
load: async () => checkpoint,
|
|
465
|
+
save: async (next) => {
|
|
466
|
+
checkpoint = { ...next };
|
|
467
|
+
}
|
|
468
|
+
};
|
|
469
|
+
};
|
|
470
|
+
|
|
471
|
+
export {
|
|
472
|
+
classifyReview,
|
|
473
|
+
scoreReviewPriority,
|
|
474
|
+
buildReflectionCandidate,
|
|
475
|
+
buildReflectionBacklog,
|
|
476
|
+
bumpSemver,
|
|
477
|
+
runReflectionCycle,
|
|
478
|
+
createInMemoryReflectionStore
|
|
479
|
+
};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import '@solana/web3.js';
|
|
2
2
|
export { C as ClaimPurpose, c as ClaimResponse, H as HumanAppCategory, d as ListingInput, L as ListingRecord, e as ListingReviewRecord, b as ListingStatus, a as ListingType, T as TicketVerifyResponse, V as VerifiedClaimResponse } from './shared-djjMij1F.js';
|
|
3
3
|
export { SelfReliance, createAutoSelfReliance, createSelfRelianceMonitor, createSelfReliancePolicy, createSurvivalMiddleware, withSurvival } from './selfReliance.js';
|
|
4
|
-
export { ReflectionActionStatus, ReflectionCandidate, ReflectionCategory, ReflectionCheckpoint, ReflectionClient, ReflectionCycleOptions, ReflectionCycleResult, ReflectionPlan, ReflectionStore, buildReflectionBacklog, buildReflectionCandidate, bumpSemver, classifyReview, createInMemoryReflectionStore, runReflectionCycle, scoreReviewPriority } from './reflection.js';
|
|
4
|
+
export { ReflectionActionStatus, ReflectionCandidate, ReflectionCategory, ReflectionCheckpoint, ReflectionClient, ReflectionCycleOptions, ReflectionCycleResult, ReflectionPlan, ReflectionStore, RevenueMovementSignal, RevenueSnapshot, buildReflectionBacklog, buildReflectionCandidate, bumpSemver, classifyReview, createInMemoryReflectionStore, runReflectionCycle, scoreReviewPriority } from './reflection.js';
|
|
5
5
|
export { SurvivalMode, SurvivalRecommendation, classifySurvivalMode, formatSurvivalRecommendation, getSurvivalRecommendation } from './survivalPlaybook.js';
|
|
6
6
|
export { SurvivalIntegrationDecision, getSurvivalPlaybookDecision, getSurvivalPlaybookDecisionFromSelfReliance } from './survivalIntegration.js';
|
|
7
7
|
export { EscapeHatchDecision, EscapeHatchPolicy, EscapeHatchSnapshot, evaluateEscapeHatch, formatEscapeHatchDecision } from './survivalEscapeHatch.js';
|
package/dist/index.js
CHANGED
|
@@ -63,7 +63,7 @@ import {
|
|
|
63
63
|
createInMemoryReflectionStore,
|
|
64
64
|
runReflectionCycle,
|
|
65
65
|
scoreReviewPriority
|
|
66
|
-
} from "./chunk-
|
|
66
|
+
} from "./chunk-YJ7FO5ZB.js";
|
|
67
67
|
|
|
68
68
|
// src/contextPack.ts
|
|
69
69
|
var SECTION_ORDER = [
|
|
@@ -362,7 +362,7 @@ var ReviewGate = class {
|
|
|
362
362
|
var DEFAULT_API_BASE = "https://api.vibeiao.com";
|
|
363
363
|
var DEFAULT_WEB_BASE = "https://vibeiao.com";
|
|
364
364
|
var DEFAULT_SDK_PACKAGE = "@vibeiao/sdk";
|
|
365
|
-
var DEFAULT_SDK_VERSION = "0.1.
|
|
365
|
+
var DEFAULT_SDK_VERSION = "0.1.42" ? "0.1.42" : "0.1.4";
|
|
366
366
|
var DEFAULT_SDK_REGISTRY = "https://registry.npmjs.org";
|
|
367
367
|
var DEFAULT_SDK_POLICY_PATH = "/v1/sdk/policy";
|
|
368
368
|
var DEFAULT_SDK_CHECK_INTERVAL_MS = 1e3 * 60 * 30;
|
package/dist/reflection.d.ts
CHANGED
|
@@ -35,6 +35,7 @@ interface ReflectionCheckpoint {
|
|
|
35
35
|
processedReviewIds?: string[];
|
|
36
36
|
lastVersion?: string;
|
|
37
37
|
updatedAt?: string;
|
|
38
|
+
lastRevenueSnapshot?: RevenueSnapshot;
|
|
38
39
|
}
|
|
39
40
|
interface ReflectionStore {
|
|
40
41
|
load: () => Promise<ReflectionCheckpoint | null> | ReflectionCheckpoint | null;
|
|
@@ -59,6 +60,22 @@ interface ReflectionPlan {
|
|
|
59
60
|
topPriority: number;
|
|
60
61
|
};
|
|
61
62
|
}
|
|
63
|
+
interface RevenueSnapshot {
|
|
64
|
+
revenue: number;
|
|
65
|
+
targetRevenue?: number;
|
|
66
|
+
tickets?: number;
|
|
67
|
+
capturedAt: string;
|
|
68
|
+
}
|
|
69
|
+
interface RevenueMovementSignal {
|
|
70
|
+
direction: 'up' | 'down' | 'flat';
|
|
71
|
+
deltaAbsolute: number;
|
|
72
|
+
deltaRelative: number | null;
|
|
73
|
+
previousRevenue: number;
|
|
74
|
+
currentRevenue: number;
|
|
75
|
+
thresholdTriggered: boolean;
|
|
76
|
+
reason: string;
|
|
77
|
+
capturedAt: string;
|
|
78
|
+
}
|
|
62
79
|
interface ReflectionCycleOptions {
|
|
63
80
|
client: ReflectionClient;
|
|
64
81
|
listingId: string;
|
|
@@ -75,6 +92,15 @@ interface ReflectionCycleOptions {
|
|
|
75
92
|
bump?: 'patch' | 'minor' | 'major';
|
|
76
93
|
minTopPriority?: number;
|
|
77
94
|
};
|
|
95
|
+
revenueReflection?: {
|
|
96
|
+
enabled?: boolean;
|
|
97
|
+
minAbsoluteDelta?: number;
|
|
98
|
+
minRelativeDelta?: number;
|
|
99
|
+
minRelativeBaselineRevenue?: number;
|
|
100
|
+
flatBand?: number;
|
|
101
|
+
includeInMemoryLog?: boolean;
|
|
102
|
+
onSignal?: (signal: RevenueMovementSignal) => Promise<void> | void;
|
|
103
|
+
};
|
|
78
104
|
now?: () => number;
|
|
79
105
|
}
|
|
80
106
|
interface ReflectionCycleResult {
|
|
@@ -92,6 +118,12 @@ interface ReflectionCycleResult {
|
|
|
92
118
|
status: ReflectionActionStatus;
|
|
93
119
|
}>;
|
|
94
120
|
summary: ReflectionPlan['summary'];
|
|
121
|
+
revenueReflection?: {
|
|
122
|
+
observed: boolean;
|
|
123
|
+
triggered: boolean;
|
|
124
|
+
signal?: RevenueMovementSignal;
|
|
125
|
+
snapshot?: RevenueSnapshot;
|
|
126
|
+
};
|
|
95
127
|
}
|
|
96
128
|
declare const classifyReview: (review: ListingReviewRecord) => ReflectionCategory;
|
|
97
129
|
declare const scoreReviewPriority: (review: ListingReviewRecord, options?: {
|
|
@@ -108,4 +140,4 @@ declare const bumpSemver: (currentVersion: string, bump?: "patch" | "minor" | "m
|
|
|
108
140
|
declare const runReflectionCycle: (options: ReflectionCycleOptions) => Promise<ReflectionCycleResult>;
|
|
109
141
|
declare const createInMemoryReflectionStore: (initial?: ReflectionCheckpoint | null) => ReflectionStore;
|
|
110
142
|
|
|
111
|
-
export { type ReflectionActionStatus, type ReflectionCandidate, type ReflectionCategory, type ReflectionCheckpoint, type ReflectionClient, type ReflectionCycleOptions, type ReflectionCycleResult, type ReflectionPlan, type ReflectionStore, buildReflectionBacklog, buildReflectionCandidate, bumpSemver, classifyReview, createInMemoryReflectionStore, runReflectionCycle, scoreReviewPriority };
|
|
143
|
+
export { type ReflectionActionStatus, type ReflectionCandidate, type ReflectionCategory, type ReflectionCheckpoint, type ReflectionClient, type ReflectionCycleOptions, type ReflectionCycleResult, type ReflectionPlan, type ReflectionStore, type RevenueMovementSignal, type RevenueSnapshot, buildReflectionBacklog, buildReflectionCandidate, bumpSemver, classifyReview, createInMemoryReflectionStore, runReflectionCycle, scoreReviewPriority };
|
package/dist/reflection.js
CHANGED
|
@@ -1105,7 +1105,7 @@ declare class ReviewGate {
|
|
|
1105
1105
|
assertClear(listingId: string, wallet: string): void;
|
|
1106
1106
|
}
|
|
1107
1107
|
|
|
1108
|
-
declare const compareVersions: (currentVersion: string, latestVersion: string) =>
|
|
1108
|
+
declare const compareVersions: (currentVersion: string, latestVersion: string) => 1 | 0 | -1;
|
|
1109
1109
|
declare const buildSdkUpdateCommand: (packageName?: string) => string;
|
|
1110
1110
|
declare const checkForSdkUpdate: (options?: SdkUpdateCheckOptions) => Promise<SdkUpdateStatus>;
|
|
1111
1111
|
declare const checkForSdkUpdatePolicy: (options: SdkUpdatePolicyCheckOptions) => Promise<SdkUpdateStatus>;
|