@dvmkit/sdk 0.0.0 → 0.1.0-rc.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/NOTICE +2 -0
- package/README.md +38 -2
- package/dist/chunk-27V2ILSR.js +291 -0
- package/dist/chunk-5GFED3GJ.js +955 -0
- package/dist/chunk-6JZIX5WW.js +1155 -0
- package/dist/chunk-7IH5SG2A.js +1038 -0
- package/dist/chunk-AT6V3SY7.js +102 -0
- package/dist/chunk-DCNT4PJS.js +733 -0
- package/dist/chunk-DMNLFNTW.js +135 -0
- package/dist/chunk-FROTD5XQ.js +70 -0
- package/dist/chunk-H25M54MI.js +149 -0
- package/dist/chunk-KQAJVVZT.js +712 -0
- package/dist/chunk-KXWROQGK.js +74 -0
- package/dist/chunk-L4OYF4DQ.js +67 -0
- package/dist/chunk-NTK5DJ6R.js +1256 -0
- package/dist/chunk-RPXHKMYE.js +3808 -0
- package/dist/chunk-S3XAHZQY.js +63 -0
- package/dist/chunk-YG7G4DPZ.js +25 -0
- package/dist/credit-ledger-EDMEZSA2.js +28 -0
- package/dist/index.d.ts +144 -0
- package/dist/index.js +303 -0
- package/dist/job-store-C5n6bhap.d.ts +5090 -0
- package/dist/memory-credit-ledger-7TTZDSRS.js +9 -0
- package/dist/mpp-secret-state-WNAQQ6K4.js +127 -0
- package/dist/mpp-setup-MOBWGTWJ.js +30 -0
- package/dist/postgres-consumed-credential-store-VHBT4KEA.js +72 -0
- package/dist/postgres-job-store-J5F4GUWU.js +7 -0
- package/dist/postgres-kv-store-JFBDP5IP.js +7 -0
- package/dist/postgres-replay-store-UJXRT6VO.js +7 -0
- package/dist/pricing-4CEB34RM.js +48 -0
- package/dist/processed-payment-store-HAA4SFNK.js +11 -0
- package/dist/revenue-reporter-M35KP6V7.js +435 -0
- package/dist/server/index.d.ts +4108 -0
- package/dist/server/index.js +22538 -0
- package/dist/ssrf-BdHsrrIb.d.ts +325 -0
- package/dist/tempo-charge-store-6GJEMNUU.js +130 -0
- package/dist/tempo-session-store-FTEEGZXA.js +467 -0
- package/dist/testing/index.d.ts +135 -0
- package/dist/testing/index.js +151 -0
- package/dist/x402-35VLYFKZ.js +1272 -0
- package/package.json +89 -6
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import {
|
|
2
|
+
JobCancelledError,
|
|
3
|
+
MemoryJobStore,
|
|
4
|
+
MemoryKVStore,
|
|
5
|
+
createInstrumentedFetch,
|
|
6
|
+
createNoopLogger
|
|
7
|
+
} from "../chunk-7IH5SG2A.js";
|
|
8
|
+
import "../chunk-KXWROQGK.js";
|
|
9
|
+
|
|
10
|
+
// src/sdk/testing/test-context.ts
|
|
11
|
+
function createTestContext(opts) {
|
|
12
|
+
const messages = [];
|
|
13
|
+
const abort = new AbortController();
|
|
14
|
+
let cancelled = false;
|
|
15
|
+
let completed = false;
|
|
16
|
+
let failed = false;
|
|
17
|
+
let refundRequested = false;
|
|
18
|
+
let summary;
|
|
19
|
+
let failError;
|
|
20
|
+
const state = opts?.state !== void 0 ? structuredClone(opts.state) : {};
|
|
21
|
+
const store = opts?.store ?? new MemoryKVStore();
|
|
22
|
+
const env = opts?.env ?? {};
|
|
23
|
+
const log = opts?.log ?? createNoopLogger();
|
|
24
|
+
const input = opts?.input ?? "";
|
|
25
|
+
const ctx = {
|
|
26
|
+
// --- Identity ---
|
|
27
|
+
jobId: opts?.jobId ?? "test-job-1",
|
|
28
|
+
tags: opts?.tags ?? [],
|
|
29
|
+
input,
|
|
30
|
+
params: opts?.params ?? {},
|
|
31
|
+
requesterId: opts?.requesterId ?? "test-requester",
|
|
32
|
+
paidMsats: opts?.paidMsats ?? 0,
|
|
33
|
+
// --- Test inspection ---
|
|
34
|
+
get messages() {
|
|
35
|
+
return messages;
|
|
36
|
+
},
|
|
37
|
+
get completed() {
|
|
38
|
+
return completed;
|
|
39
|
+
},
|
|
40
|
+
get failed() {
|
|
41
|
+
return failed;
|
|
42
|
+
},
|
|
43
|
+
get refundRequested() {
|
|
44
|
+
return refundRequested;
|
|
45
|
+
},
|
|
46
|
+
get summary() {
|
|
47
|
+
return summary;
|
|
48
|
+
},
|
|
49
|
+
get failError() {
|
|
50
|
+
return failError;
|
|
51
|
+
},
|
|
52
|
+
// --- Messaging ---
|
|
53
|
+
text(message) {
|
|
54
|
+
if (cancelled) return;
|
|
55
|
+
messages.push({ type: "text", content: { text: message } });
|
|
56
|
+
},
|
|
57
|
+
artifact(content) {
|
|
58
|
+
if (cancelled) return;
|
|
59
|
+
messages.push({
|
|
60
|
+
type: "artifact",
|
|
61
|
+
content
|
|
62
|
+
});
|
|
63
|
+
},
|
|
64
|
+
sendMessage(type, content) {
|
|
65
|
+
if (cancelled) return;
|
|
66
|
+
messages.push({ type, content });
|
|
67
|
+
},
|
|
68
|
+
// --- Flow control ---
|
|
69
|
+
prompt(id, text, promptOpts) {
|
|
70
|
+
if (cancelled) return Promise.reject(new JobCancelledError());
|
|
71
|
+
messages.push({
|
|
72
|
+
type: "prompt",
|
|
73
|
+
content: { id, text, ...promptOpts }
|
|
74
|
+
});
|
|
75
|
+
const response = opts?.responses?.[id];
|
|
76
|
+
if (!response) {
|
|
77
|
+
return Promise.reject(
|
|
78
|
+
new Error(
|
|
79
|
+
`TestContext: no pre-programmed response for prompt "${id}". Pass responses: { "${id}": { prompt_id: "${id}", text: "..." } } to createTestContext.`
|
|
80
|
+
)
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
return Promise.resolve(response);
|
|
84
|
+
},
|
|
85
|
+
requestPayment(amount, reason, payOpts) {
|
|
86
|
+
if (cancelled) return Promise.reject(new JobCancelledError());
|
|
87
|
+
messages.push({
|
|
88
|
+
type: "payment-request",
|
|
89
|
+
content: { amount, reason, ...payOpts }
|
|
90
|
+
});
|
|
91
|
+
const payment = opts?.payment;
|
|
92
|
+
if (!payment) {
|
|
93
|
+
return Promise.reject(
|
|
94
|
+
new Error(
|
|
95
|
+
"TestContext: no pre-programmed payment. Pass payment: { amount_msats: ... } to createTestContext."
|
|
96
|
+
)
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
return Promise.resolve(payment);
|
|
100
|
+
},
|
|
101
|
+
working(estimateSeconds, hint) {
|
|
102
|
+
if (cancelled) return;
|
|
103
|
+
messages.push({
|
|
104
|
+
type: "working",
|
|
105
|
+
content: { estimate_seconds: estimateSeconds, hint }
|
|
106
|
+
});
|
|
107
|
+
},
|
|
108
|
+
progress(percentComplete, phase, hint) {
|
|
109
|
+
if (cancelled) return;
|
|
110
|
+
const pct = Math.max(0, Math.min(100, percentComplete));
|
|
111
|
+
const content = { percent_complete: pct };
|
|
112
|
+
if (phase) content.current_phase = phase;
|
|
113
|
+
if (hint) content.hint = hint;
|
|
114
|
+
messages.push({ type: "progress", content });
|
|
115
|
+
},
|
|
116
|
+
complete(s) {
|
|
117
|
+
if (cancelled) return;
|
|
118
|
+
completed = true;
|
|
119
|
+
summary = s;
|
|
120
|
+
messages.push({ type: "complete", content: { summary: s } });
|
|
121
|
+
},
|
|
122
|
+
fail(error, failOpts) {
|
|
123
|
+
if (cancelled) return;
|
|
124
|
+
failed = true;
|
|
125
|
+
failError = error;
|
|
126
|
+
if (failOpts?.refund) refundRequested = true;
|
|
127
|
+
messages.push({ type: "cancel", content: { reason: error } });
|
|
128
|
+
},
|
|
129
|
+
cancel(reason = "Job cancelled") {
|
|
130
|
+
if (cancelled) return;
|
|
131
|
+
cancelled = true;
|
|
132
|
+
abort.abort(new JobCancelledError(reason));
|
|
133
|
+
},
|
|
134
|
+
// --- Durable execution ---
|
|
135
|
+
async step(_id, fn) {
|
|
136
|
+
return fn();
|
|
137
|
+
},
|
|
138
|
+
// --- Platform services ---
|
|
139
|
+
state,
|
|
140
|
+
store,
|
|
141
|
+
fetch: createInstrumentedFetch(abort.signal),
|
|
142
|
+
signal: abort.signal,
|
|
143
|
+
env,
|
|
144
|
+
log
|
|
145
|
+
};
|
|
146
|
+
return ctx;
|
|
147
|
+
}
|
|
148
|
+
export {
|
|
149
|
+
MemoryJobStore,
|
|
150
|
+
createTestContext
|
|
151
|
+
};
|