routstrd 0.4.4 → 0.4.6
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 +14 -0
- package/dist/daemon/index.js +74735 -91633
- package/dist/index.js +203 -41
- package/package.json +9 -2
- package/src/cli.test.ts +138 -1
- package/src/cli.ts +289 -49
- package/src/daemon/http/index.ts +1862 -0
- package/src/daemon/index.ts +408 -0
- package/src/daemon/wallet/index.ts +360 -0
- package/src/index.ts +4 -0
- package/src/integrations/index.ts +159 -0
- package/src/tui/usage/index.ts +1 -0
- package/.claude/settings.local.json +0 -10
- package/.dockerignore +0 -12
- package/COCO-2.0.0-MIGRATION-PLAN.md +0 -1191
- package/Dockerfile +0 -11
- package/IMPLEMENTATION.md +0 -253
- package/SKILL.md +0 -324
- package/bun.lock +0 -494
- package/docker-compose.yml +0 -15
- package/refund.js +0 -33
- package/refund_new.js +0 -20
- package/routstr-cost-logging.md +0 -71
- package/test_box.ts +0 -15
- package/test_chat.sh +0 -29
- package/test_curl.sh +0 -11
- package/test_split_box.ts +0 -17
- package/test_split_box2.ts +0 -23
- package/tests/daemon/config-store.perms.test.ts +0 -55
- package/tests/daemon/config-store.scenario.ts +0 -113
- package/tests/integrations/hermes.test.ts +0 -134
- package/tests/utils/daemon-client.test.ts +0 -61
- package/tests/wallet/short-keyset-token.test.ts +0 -106
- package/tsconfig.json +0 -20
- package/v1-messages-format-report.md +0 -223
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it, mock } from "bun:test";
|
|
2
|
-
import {
|
|
3
|
-
Amount,
|
|
4
|
-
getDecodedToken,
|
|
5
|
-
getEncodedToken,
|
|
6
|
-
} from "@cashu/cashu-ts";
|
|
7
|
-
import {
|
|
8
|
-
createWalletAdapter,
|
|
9
|
-
decodeCashuTokenAmount,
|
|
10
|
-
} from "../../src/daemon/wallet";
|
|
11
|
-
import type { CocodClient } from "../../src/daemon/wallet/cocod-client";
|
|
12
|
-
|
|
13
|
-
// A full modern keyset ID with the same format as Minibits' post-migration
|
|
14
|
-
// active keyset. getEncodedToken stores only its first eight bytes in TokenV4.
|
|
15
|
-
const FULL_KEYSET_ID =
|
|
16
|
-
"01fc0ec0e59cd6fa01b7a88f8cd77fce81fd1e64bca67d752e984992b7a3c3a821";
|
|
17
|
-
const LEGACY_KEYSET_ID = "00107937db0cc865";
|
|
18
|
-
|
|
19
|
-
function makeToken({
|
|
20
|
-
amounts = [5],
|
|
21
|
-
keysetId = FULL_KEYSET_ID,
|
|
22
|
-
unit = "sat",
|
|
23
|
-
}: {
|
|
24
|
-
amounts?: number[];
|
|
25
|
-
keysetId?: string;
|
|
26
|
-
unit?: string;
|
|
27
|
-
} = {}): string {
|
|
28
|
-
return getEncodedToken({
|
|
29
|
-
mint: "https://mint.minibits.cash/Bitcoin",
|
|
30
|
-
unit,
|
|
31
|
-
proofs: amounts.map((amount, index) => ({
|
|
32
|
-
id: keysetId,
|
|
33
|
-
amount: Amount.from(amount),
|
|
34
|
-
secret: `short-keyset-regression-fixture-${index}`,
|
|
35
|
-
C: `02${(index + 1).toString(16).padStart(2, "0").repeat(32)}`,
|
|
36
|
-
})),
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
function makeWalletClient(
|
|
41
|
-
receiveCashu: CocodClient["receiveCashu"],
|
|
42
|
-
): CocodClient {
|
|
43
|
-
// createWalletAdapter is intentionally lazy; this receive-path test only
|
|
44
|
-
// needs the one capability exercised by receiveToken.
|
|
45
|
-
return { receiveCashu } as CocodClient;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
describe("short keyset TokenV4 compatibility", () => {
|
|
49
|
-
it("reads amount metadata without resolving the shortened proof keyset ID", () => {
|
|
50
|
-
const token = makeToken({ amounts: [1, 4] });
|
|
51
|
-
|
|
52
|
-
// Guard the fixture itself: a full proof decode with no mint keysets must
|
|
53
|
-
// exercise the same short-ID failure that triggered this regression.
|
|
54
|
-
expect(() => getDecodedToken(token, [])).toThrow(/short keyset ID/i);
|
|
55
|
-
expect(decodeCashuTokenAmount(token)).toEqual({
|
|
56
|
-
amount: 5,
|
|
57
|
-
unit: "sat",
|
|
58
|
-
});
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
for (const tokenCase of [
|
|
62
|
-
{
|
|
63
|
-
name: "modern keyset with msat unit",
|
|
64
|
-
input: { amounts: [500, 1000], unit: "msat" },
|
|
65
|
-
expected: { amount: 1500, unit: "msat" as const },
|
|
66
|
-
},
|
|
67
|
-
{
|
|
68
|
-
name: "legacy v0 keyset",
|
|
69
|
-
input: { amounts: [2, 8], keysetId: LEGACY_KEYSET_ID },
|
|
70
|
-
expected: { amount: 10, unit: "sat" as const },
|
|
71
|
-
},
|
|
72
|
-
]) {
|
|
73
|
-
it(`reads ${tokenCase.name} metadata`, () => {
|
|
74
|
-
expect(decodeCashuTokenAmount(makeToken(tokenCase.input))).toEqual(
|
|
75
|
-
tokenCase.expected,
|
|
76
|
-
);
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
it("reports success after cocod receives a short-keyset token", async () => {
|
|
81
|
-
const receiveCashu = mock(async () => "Received 5");
|
|
82
|
-
const walletClient = makeWalletClient(receiveCashu);
|
|
83
|
-
const adapter = await createWalletAdapter({ walletClient });
|
|
84
|
-
|
|
85
|
-
const result = await adapter.receiveToken(makeToken());
|
|
86
|
-
|
|
87
|
-
expect(receiveCashu).toHaveBeenCalledTimes(1);
|
|
88
|
-
expect(result).toEqual({
|
|
89
|
-
success: true,
|
|
90
|
-
amount: 5,
|
|
91
|
-
unit: "sat",
|
|
92
|
-
message: "Received 5",
|
|
93
|
-
});
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
it("does not call the wallet when token metadata is invalid", async () => {
|
|
97
|
-
const receiveCashu = mock(async () => "should not be called");
|
|
98
|
-
const walletClient = makeWalletClient(receiveCashu);
|
|
99
|
-
const adapter = await createWalletAdapter({ walletClient });
|
|
100
|
-
|
|
101
|
-
const result = await adapter.receiveToken("cashuBnot-a-valid-token");
|
|
102
|
-
|
|
103
|
-
expect(receiveCashu).not.toHaveBeenCalled();
|
|
104
|
-
expect(result.success).toBe(false);
|
|
105
|
-
});
|
|
106
|
-
});
|
package/tsconfig.json
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"lib": ["ESNext"],
|
|
4
|
-
"target": "ESNext",
|
|
5
|
-
"module": "ESNext",
|
|
6
|
-
"moduleResolution": "bundler",
|
|
7
|
-
"strict": true,
|
|
8
|
-
"noUncheckedIndexedAccess": true,
|
|
9
|
-
"esModuleInterop": true,
|
|
10
|
-
"skipLibCheck": true,
|
|
11
|
-
"forceConsistentCasingInFileNames": true,
|
|
12
|
-
"resolveJsonModule": true,
|
|
13
|
-
"isolatedModules": true,
|
|
14
|
-
"allowImportingTsExtensions": true,
|
|
15
|
-
"noEmit": true,
|
|
16
|
-
"types": ["bun-types"]
|
|
17
|
-
},
|
|
18
|
-
"include": ["src/**/*"],
|
|
19
|
-
"exclude": ["node_modules"]
|
|
20
|
-
}
|
|
@@ -1,223 +0,0 @@
|
|
|
1
|
-
# Report: why `POST /v1/messages` on port 8008 returns chat-completions chunks while port 8009 preserves Messages API format
|
|
2
|
-
|
|
3
|
-
Date: 2026-03-28
|
|
4
|
-
|
|
5
|
-
## Summary
|
|
6
|
-
|
|
7
|
-
I tested the same request against both local daemons using `scripts/test-direct-local.ts` semantics (`POST /v1/messages`, `stream: true`).
|
|
8
|
-
|
|
9
|
-
- `localhost:8009` preserves the Anthropic/OpenAI Messages-style stream as expected:
|
|
10
|
-
- `message_start`
|
|
11
|
-
- `content_block_start`
|
|
12
|
-
- `content_block_delta`
|
|
13
|
-
- `message_delta`
|
|
14
|
-
- `message_stop`
|
|
15
|
-
- `localhost:8008` returns OpenAI chat-completions streaming chunks instead:
|
|
16
|
-
- `object: "chat.completion.chunk"`
|
|
17
|
-
- `choices[].delta`
|
|
18
|
-
|
|
19
|
-
This is **not** because the SDK itself is incapable of preserving `/v1/messages`.
|
|
20
|
-
It happens because the two daemons call the SDK differently.
|
|
21
|
-
|
|
22
|
-
---
|
|
23
|
-
|
|
24
|
-
## What I tested
|
|
25
|
-
|
|
26
|
-
### 8008 (`../routstrd/`)
|
|
27
|
-
|
|
28
|
-
Listener:
|
|
29
|
-
- `../routstrd/src/daemon/index.ts`
|
|
30
|
-
- request handler in `../routstrd/src/daemon/http/index.ts`
|
|
31
|
-
|
|
32
|
-
Observed result for `POST http://localhost:8008/v1/messages`:
|
|
33
|
-
- response `content-type: text/event-stream`
|
|
34
|
-
- SSE payload is OpenAI chat-completions chunks (`chat.completion.chunk`)
|
|
35
|
-
|
|
36
|
-
### 8009 (`routstr-chat/scripts/routstr-daemon.ts`)
|
|
37
|
-
|
|
38
|
-
Listener:
|
|
39
|
-
- `scripts/routstr-daemon.ts`
|
|
40
|
-
|
|
41
|
-
Observed result for `POST http://localhost:8009/v1/messages`:
|
|
42
|
-
- response `content-type: text/event-stream`
|
|
43
|
-
- SSE payload preserves Messages API events (`message_start`, `content_block_delta`, etc.)
|
|
44
|
-
|
|
45
|
-
---
|
|
46
|
-
|
|
47
|
-
## Direct cause
|
|
48
|
-
|
|
49
|
-
### 8009 forwards the incoming path to the SDK
|
|
50
|
-
|
|
51
|
-
In `routstr-chat/scripts/routstr-daemon.ts`, the request is routed with:
|
|
52
|
-
|
|
53
|
-
```ts
|
|
54
|
-
await routeRequestsToNodeResponse({
|
|
55
|
-
modelId,
|
|
56
|
-
requestBody,
|
|
57
|
-
path: url.pathname,
|
|
58
|
-
headers: forwardedHeaders,
|
|
59
|
-
...
|
|
60
|
-
});
|
|
61
|
-
```
|
|
62
|
-
|
|
63
|
-
Because it passes:
|
|
64
|
-
|
|
65
|
-
```ts
|
|
66
|
-
path: url.pathname
|
|
67
|
-
```
|
|
68
|
-
|
|
69
|
-
an incoming request to `/v1/messages` stays `/v1/messages` all the way through the SDK and upstream provider routing.
|
|
70
|
-
|
|
71
|
-
### 8008 does **not** forward the incoming path
|
|
72
|
-
|
|
73
|
-
In `../routstrd/src/daemon/http/index.ts`, the request is routed with:
|
|
74
|
-
|
|
75
|
-
```ts
|
|
76
|
-
const response = await routeRequests({
|
|
77
|
-
modelId,
|
|
78
|
-
requestBody,
|
|
79
|
-
forcedProvider,
|
|
80
|
-
headers: incomingHeaders,
|
|
81
|
-
walletAdapter: deps.walletAdapter,
|
|
82
|
-
storageAdapter: deps.storageAdapter,
|
|
83
|
-
providerRegistry: deps.providerRegistry,
|
|
84
|
-
discoveryAdapter: deps.discoveryAdapter,
|
|
85
|
-
modelManager: deps.modelManager,
|
|
86
|
-
debugLevel: "DEBUG",
|
|
87
|
-
mode: deps.mode,
|
|
88
|
-
usageTrackingDriver: deps.usageTrackingDriver,
|
|
89
|
-
sdkStore: deps.store,
|
|
90
|
-
});
|
|
91
|
-
```
|
|
92
|
-
|
|
93
|
-
Notice: **no `path` is passed**.
|
|
94
|
-
|
|
95
|
-
In the SDK, `routeRequests()` defaults the path to:
|
|
96
|
-
|
|
97
|
-
```ts
|
|
98
|
-
path = "/v1/chat/completions"
|
|
99
|
-
```
|
|
100
|
-
|
|
101
|
-
from:
|
|
102
|
-
- `routstr-chat/sdk/routeRequests.ts`
|
|
103
|
-
|
|
104
|
-
So even when the client calls:
|
|
105
|
-
|
|
106
|
-
```http
|
|
107
|
-
POST /v1/messages
|
|
108
|
-
```
|
|
109
|
-
|
|
110
|
-
on port 8008, the daemon internally re-routes it as:
|
|
111
|
-
|
|
112
|
-
```http
|
|
113
|
-
POST /v1/chat/completions
|
|
114
|
-
```
|
|
115
|
-
|
|
116
|
-
That is why the upstream/provider response is converted into chat-completions format.
|
|
117
|
-
|
|
118
|
-
---
|
|
119
|
-
|
|
120
|
-
## Why the behavior differs even though both are built on the same SDK
|
|
121
|
-
|
|
122
|
-
Both daemons use the same SDK primitives, but:
|
|
123
|
-
|
|
124
|
-
- **8009** uses `routeRequestsToNodeResponse(...)` and explicitly passes `path: url.pathname`
|
|
125
|
-
- **8008** uses `routeRequests(...)` and relies on the SDK default path, which is `/v1/chat/completions`
|
|
126
|
-
|
|
127
|
-
So the format difference is caused by **daemon integration code**, not by a provider-specific quirk and not by an unavoidable SDK conversion.
|
|
128
|
-
|
|
129
|
-
---
|
|
130
|
-
|
|
131
|
-
## Important implementation detail
|
|
132
|
-
|
|
133
|
-
The SDK helper itself documents this default:
|
|
134
|
-
|
|
135
|
-
- `routstr-chat/sdk/routeRequests.ts`
|
|
136
|
-
|
|
137
|
-
```ts
|
|
138
|
-
/** Optional: API path (defaults to /v1/chat/completions) */
|
|
139
|
-
```
|
|
140
|
-
|
|
141
|
-
and in `resolveRouteRequestContext(...)`:
|
|
142
|
-
|
|
143
|
-
```ts
|
|
144
|
-
path = "/v1/chat/completions"
|
|
145
|
-
```
|
|
146
|
-
|
|
147
|
-
Therefore any caller that omits `path` will get chat-completions semantics by default.
|
|
148
|
-
|
|
149
|
-
---
|
|
150
|
-
|
|
151
|
-
## Evidence from runtime tests
|
|
152
|
-
|
|
153
|
-
### Port 8008
|
|
154
|
-
|
|
155
|
-
Observed streamed chunks included:
|
|
156
|
-
|
|
157
|
-
- `object: "chat.completion.chunk"`
|
|
158
|
-
- `choices[0].delta.content`
|
|
159
|
-
- final `[DONE]`
|
|
160
|
-
|
|
161
|
-
### Port 8009
|
|
162
|
-
|
|
163
|
-
Observed streamed events included:
|
|
164
|
-
|
|
165
|
-
- `event: message_start`
|
|
166
|
-
- `event: content_block_start`
|
|
167
|
-
- `event: content_block_delta`
|
|
168
|
-
- `event: message_delta`
|
|
169
|
-
- `event: message_stop`
|
|
170
|
-
- final `[DONE]`
|
|
171
|
-
|
|
172
|
-
This matches the code-path difference above.
|
|
173
|
-
|
|
174
|
-
---
|
|
175
|
-
|
|
176
|
-
## Recommended fix
|
|
177
|
-
|
|
178
|
-
In `../routstrd/src/daemon/http/index.ts`, pass the incoming path through to the SDK:
|
|
179
|
-
|
|
180
|
-
```ts
|
|
181
|
-
const response = await routeRequests({
|
|
182
|
-
modelId,
|
|
183
|
-
requestBody,
|
|
184
|
-
path: url.pathname,
|
|
185
|
-
forcedProvider,
|
|
186
|
-
headers: incomingHeaders,
|
|
187
|
-
walletAdapter: deps.walletAdapter,
|
|
188
|
-
storageAdapter: deps.storageAdapter,
|
|
189
|
-
providerRegistry: deps.providerRegistry,
|
|
190
|
-
discoveryAdapter: deps.discoveryAdapter,
|
|
191
|
-
modelManager: deps.modelManager,
|
|
192
|
-
debugLevel: "DEBUG",
|
|
193
|
-
mode: deps.mode,
|
|
194
|
-
usageTrackingDriver: deps.usageTrackingDriver,
|
|
195
|
-
sdkStore: deps.store,
|
|
196
|
-
});
|
|
197
|
-
```
|
|
198
|
-
|
|
199
|
-
This should make `POST /v1/messages` on port 8008 preserve the Messages API format, matching port 8009.
|
|
200
|
-
|
|
201
|
-
---
|
|
202
|
-
|
|
203
|
-
## Secondary note
|
|
204
|
-
|
|
205
|
-
Port 8008 currently uses `routeRequests(...)` and then manually streams the returned response body to `res`.
|
|
206
|
-
Port 8009 uses `routeRequestsToNodeResponse(...)` directly.
|
|
207
|
-
|
|
208
|
-
That difference is probably not the root cause here.
|
|
209
|
-
The root cause is specifically that **8008 drops the incoming request path and falls back to the SDK default of `/v1/chat/completions`**.
|
|
210
|
-
|
|
211
|
-
---
|
|
212
|
-
|
|
213
|
-
## Conclusion
|
|
214
|
-
|
|
215
|
-
The reason `localhost:8008/v1/messages` appears to "convert to chat completions" is:
|
|
216
|
-
|
|
217
|
-
1. `../routstrd` receives `/v1/messages`
|
|
218
|
-
2. its handler calls `routeRequests(...)` without `path`
|
|
219
|
-
3. the SDK defaults `path` to `/v1/chat/completions`
|
|
220
|
-
4. the upstream request is therefore made against chat completions
|
|
221
|
-
5. the stream returned is chat-completions SSE, not Messages API SSE
|
|
222
|
-
|
|
223
|
-
Port 8009 works because it explicitly forwards `url.pathname` into the SDK call.
|