@routedock/routedock 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/PUBLISH_CHECKLIST.md +70 -0
- package/README.md +88 -0
- package/dist/SessionStore-CCVO0PHM.d.cts +152 -0
- package/dist/SessionStore-CCVO0PHM.d.ts +152 -0
- package/dist/client.cjs +618 -0
- package/dist/client.d.cts +98 -0
- package/dist/client.d.ts +98 -0
- package/dist/client.js +601 -0
- package/dist/index.cjs +932 -0
- package/dist/index.d.cts +6 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +914 -0
- package/dist/provider.cjs +425 -0
- package/dist/provider.d.cts +44 -0
- package/dist/provider.d.ts +44 -0
- package/dist/provider.js +414 -0
- package/dist/routedockMiddleware-Beqan6QS.d.cts +49 -0
- package/dist/routedockMiddleware-CqnyHjhO.d.ts +49 -0
- package/package.json +61 -0
- package/src/client/ModeRouter.ts +104 -0
- package/src/client/MppChargeClient.ts +44 -0
- package/src/client/MppSessionClient.ts +144 -0
- package/src/client/RouteDockClient.ts +124 -0
- package/src/client/index.ts +8 -0
- package/src/client/x402Client.ts +84 -0
- package/src/index.ts +9 -0
- package/src/provider/MppChargeHandler.ts +90 -0
- package/src/provider/MppSessionHandler.ts +136 -0
- package/src/provider/index.ts +7 -0
- package/src/provider/routedockMiddleware.ts +148 -0
- package/src/provider/x402Handler.ts +112 -0
- package/src/schemas/routedock.schema.json +159 -0
- package/src/store/SessionStore.ts +90 -0
- package/src/tests/smoke.test.ts +228 -0
- package/src/types.ts +165 -0
- package/tsconfig.json +14 -0
- package/tsup.config.ts +15 -0
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { P as PaymentMode, c as RouteDockManifest, a as PaymentResult, h as SessionHandle } from './SessionStore-CCVO0PHM.cjs';
|
|
2
|
+
export { b as PricingConfig, R as RouteDockError, d as RouteDockManifestError, e as RouteDockNoSupportedModeError, f as RouteDockPolicyRejectedError, g as RouteDockSessionError, S as SessionCloseResult, i as SessionPricingConfig, j as SessionState, k as SessionStore, l as SupabaseSessionStore } from './SessionStore-CCVO0PHM.cjs';
|
|
3
|
+
import { Keypair } from '@stellar/stellar-sdk';
|
|
4
|
+
import '@supabase/supabase-js';
|
|
5
|
+
|
|
6
|
+
interface ModeSelectOptions {
|
|
7
|
+
/** Force mpp-session if the provider supports it */
|
|
8
|
+
sustained?: boolean;
|
|
9
|
+
session?: boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Override mode selection and use this specific mode.
|
|
12
|
+
* Throws RouteDockNoSupportedModeError if the provider does not support it.
|
|
13
|
+
*/
|
|
14
|
+
forceMode?: PaymentMode;
|
|
15
|
+
}
|
|
16
|
+
/** Fetch, validate, and cache a RouteDock manifest from `baseUrl`. */
|
|
17
|
+
declare function fetchManifest(baseUrl: string): Promise<RouteDockManifest>;
|
|
18
|
+
/**
|
|
19
|
+
* Deterministic mode selection per Section 6.3 of ROUTEDOCK_MASTER.md:
|
|
20
|
+
* 1. If { sustained | session } AND manifest supports mpp-session → mpp-session
|
|
21
|
+
* 2. Else if manifest supports mpp-charge AND network is Stellar → mpp-charge
|
|
22
|
+
* 3. Else if manifest supports x402 → x402
|
|
23
|
+
* 4. Else throw RouteDockNoSupportedModeError
|
|
24
|
+
*/
|
|
25
|
+
declare function selectMode(manifest: RouteDockManifest, options?: ModeSelectOptions): PaymentMode;
|
|
26
|
+
|
|
27
|
+
interface SpendCap {
|
|
28
|
+
/** Maximum total USDC spend per day (decimal string, e.g. "1.00") */
|
|
29
|
+
daily: string;
|
|
30
|
+
asset: 'USDC';
|
|
31
|
+
}
|
|
32
|
+
interface RouteDockClientConfig {
|
|
33
|
+
/** Stellar keypair or raw secret key (S...) */
|
|
34
|
+
wallet: Keypair | string;
|
|
35
|
+
network: 'testnet' | 'mainnet';
|
|
36
|
+
/** Optional local daily spend cap — checked before every payment */
|
|
37
|
+
spendCap?: SpendCap;
|
|
38
|
+
/** Ed25519 secret key (S...) for signing channel commitments. Required for mpp-session. */
|
|
39
|
+
commitmentSecret?: string | undefined;
|
|
40
|
+
}
|
|
41
|
+
declare class RouteDockClient {
|
|
42
|
+
private readonly keypair;
|
|
43
|
+
private readonly network;
|
|
44
|
+
private readonly spendCap;
|
|
45
|
+
private readonly commitmentSecret;
|
|
46
|
+
/** Local daily accumulator keyed by YYYY-MM-DD */
|
|
47
|
+
private dailySpend;
|
|
48
|
+
private readonly x402;
|
|
49
|
+
private readonly charge;
|
|
50
|
+
private readonly session;
|
|
51
|
+
constructor(config: RouteDockClientConfig);
|
|
52
|
+
/**
|
|
53
|
+
* Pay for one request at `url`. Fetches manifest, selects payment mode,
|
|
54
|
+
* checks local spend cap, executes payment, returns result.
|
|
55
|
+
*/
|
|
56
|
+
pay(url: string, options?: ModeSelectOptions): Promise<PaymentResult>;
|
|
57
|
+
/**
|
|
58
|
+
* Open a sustained MPP session at `url`. Verifies mpp-session is supported
|
|
59
|
+
* before opening a channel. Returns a SessionHandle for streaming + closing.
|
|
60
|
+
*/
|
|
61
|
+
openSession(url: string): Promise<SessionHandle>;
|
|
62
|
+
/** Check local daily cap and record the spend. Throws if cap exceeded. */
|
|
63
|
+
private _checkAndRecordSpend;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
type Network = 'testnet' | 'mainnet';
|
|
67
|
+
declare class X402Client {
|
|
68
|
+
private readonly secretKey;
|
|
69
|
+
private readonly network;
|
|
70
|
+
private readonly httpClient;
|
|
71
|
+
constructor(secretKey: string, network: Network);
|
|
72
|
+
pay(url: string, manifest: RouteDockManifest): Promise<PaymentResult>;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
declare class MppChargeClient {
|
|
76
|
+
private readonly keypair;
|
|
77
|
+
private readonly network;
|
|
78
|
+
constructor(keypair: Keypair, network: 'testnet' | 'mainnet');
|
|
79
|
+
pay(url: string, manifest: RouteDockManifest): Promise<PaymentResult>;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* MppSessionClient — uses @stellar/mpp channel/client for off-chain
|
|
84
|
+
* cumulative commitments against a pre-deployed one-way-channel contract.
|
|
85
|
+
*
|
|
86
|
+
* The channel is deployed and funded before the agent runs. The client
|
|
87
|
+
* signs ed25519 commitments per the one-way-channel protocol — the
|
|
88
|
+
* @stellar/mpp library handles the 402 challenge-response cycle.
|
|
89
|
+
*/
|
|
90
|
+
|
|
91
|
+
declare class MppSessionClient {
|
|
92
|
+
private readonly keypair;
|
|
93
|
+
private readonly network;
|
|
94
|
+
constructor(keypair: Keypair, network: 'testnet' | 'mainnet');
|
|
95
|
+
openSession(url: string, manifest: RouteDockManifest, commitmentSecret: string): Promise<SessionHandle>;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export { type ModeSelectOptions, MppChargeClient, MppSessionClient, PaymentMode, PaymentResult, RouteDockClient, type RouteDockClientConfig, RouteDockManifest, SessionHandle, type SpendCap, X402Client, fetchManifest, selectMode };
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { P as PaymentMode, c as RouteDockManifest, a as PaymentResult, h as SessionHandle } from './SessionStore-CCVO0PHM.js';
|
|
2
|
+
export { b as PricingConfig, R as RouteDockError, d as RouteDockManifestError, e as RouteDockNoSupportedModeError, f as RouteDockPolicyRejectedError, g as RouteDockSessionError, S as SessionCloseResult, i as SessionPricingConfig, j as SessionState, k as SessionStore, l as SupabaseSessionStore } from './SessionStore-CCVO0PHM.js';
|
|
3
|
+
import { Keypair } from '@stellar/stellar-sdk';
|
|
4
|
+
import '@supabase/supabase-js';
|
|
5
|
+
|
|
6
|
+
interface ModeSelectOptions {
|
|
7
|
+
/** Force mpp-session if the provider supports it */
|
|
8
|
+
sustained?: boolean;
|
|
9
|
+
session?: boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Override mode selection and use this specific mode.
|
|
12
|
+
* Throws RouteDockNoSupportedModeError if the provider does not support it.
|
|
13
|
+
*/
|
|
14
|
+
forceMode?: PaymentMode;
|
|
15
|
+
}
|
|
16
|
+
/** Fetch, validate, and cache a RouteDock manifest from `baseUrl`. */
|
|
17
|
+
declare function fetchManifest(baseUrl: string): Promise<RouteDockManifest>;
|
|
18
|
+
/**
|
|
19
|
+
* Deterministic mode selection per Section 6.3 of ROUTEDOCK_MASTER.md:
|
|
20
|
+
* 1. If { sustained | session } AND manifest supports mpp-session → mpp-session
|
|
21
|
+
* 2. Else if manifest supports mpp-charge AND network is Stellar → mpp-charge
|
|
22
|
+
* 3. Else if manifest supports x402 → x402
|
|
23
|
+
* 4. Else throw RouteDockNoSupportedModeError
|
|
24
|
+
*/
|
|
25
|
+
declare function selectMode(manifest: RouteDockManifest, options?: ModeSelectOptions): PaymentMode;
|
|
26
|
+
|
|
27
|
+
interface SpendCap {
|
|
28
|
+
/** Maximum total USDC spend per day (decimal string, e.g. "1.00") */
|
|
29
|
+
daily: string;
|
|
30
|
+
asset: 'USDC';
|
|
31
|
+
}
|
|
32
|
+
interface RouteDockClientConfig {
|
|
33
|
+
/** Stellar keypair or raw secret key (S...) */
|
|
34
|
+
wallet: Keypair | string;
|
|
35
|
+
network: 'testnet' | 'mainnet';
|
|
36
|
+
/** Optional local daily spend cap — checked before every payment */
|
|
37
|
+
spendCap?: SpendCap;
|
|
38
|
+
/** Ed25519 secret key (S...) for signing channel commitments. Required for mpp-session. */
|
|
39
|
+
commitmentSecret?: string | undefined;
|
|
40
|
+
}
|
|
41
|
+
declare class RouteDockClient {
|
|
42
|
+
private readonly keypair;
|
|
43
|
+
private readonly network;
|
|
44
|
+
private readonly spendCap;
|
|
45
|
+
private readonly commitmentSecret;
|
|
46
|
+
/** Local daily accumulator keyed by YYYY-MM-DD */
|
|
47
|
+
private dailySpend;
|
|
48
|
+
private readonly x402;
|
|
49
|
+
private readonly charge;
|
|
50
|
+
private readonly session;
|
|
51
|
+
constructor(config: RouteDockClientConfig);
|
|
52
|
+
/**
|
|
53
|
+
* Pay for one request at `url`. Fetches manifest, selects payment mode,
|
|
54
|
+
* checks local spend cap, executes payment, returns result.
|
|
55
|
+
*/
|
|
56
|
+
pay(url: string, options?: ModeSelectOptions): Promise<PaymentResult>;
|
|
57
|
+
/**
|
|
58
|
+
* Open a sustained MPP session at `url`. Verifies mpp-session is supported
|
|
59
|
+
* before opening a channel. Returns a SessionHandle for streaming + closing.
|
|
60
|
+
*/
|
|
61
|
+
openSession(url: string): Promise<SessionHandle>;
|
|
62
|
+
/** Check local daily cap and record the spend. Throws if cap exceeded. */
|
|
63
|
+
private _checkAndRecordSpend;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
type Network = 'testnet' | 'mainnet';
|
|
67
|
+
declare class X402Client {
|
|
68
|
+
private readonly secretKey;
|
|
69
|
+
private readonly network;
|
|
70
|
+
private readonly httpClient;
|
|
71
|
+
constructor(secretKey: string, network: Network);
|
|
72
|
+
pay(url: string, manifest: RouteDockManifest): Promise<PaymentResult>;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
declare class MppChargeClient {
|
|
76
|
+
private readonly keypair;
|
|
77
|
+
private readonly network;
|
|
78
|
+
constructor(keypair: Keypair, network: 'testnet' | 'mainnet');
|
|
79
|
+
pay(url: string, manifest: RouteDockManifest): Promise<PaymentResult>;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* MppSessionClient — uses @stellar/mpp channel/client for off-chain
|
|
84
|
+
* cumulative commitments against a pre-deployed one-way-channel contract.
|
|
85
|
+
*
|
|
86
|
+
* The channel is deployed and funded before the agent runs. The client
|
|
87
|
+
* signs ed25519 commitments per the one-way-channel protocol — the
|
|
88
|
+
* @stellar/mpp library handles the 402 challenge-response cycle.
|
|
89
|
+
*/
|
|
90
|
+
|
|
91
|
+
declare class MppSessionClient {
|
|
92
|
+
private readonly keypair;
|
|
93
|
+
private readonly network;
|
|
94
|
+
constructor(keypair: Keypair, network: 'testnet' | 'mainnet');
|
|
95
|
+
openSession(url: string, manifest: RouteDockManifest, commitmentSecret: string): Promise<SessionHandle>;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export { type ModeSelectOptions, MppChargeClient, MppSessionClient, PaymentMode, PaymentResult, RouteDockClient, type RouteDockClientConfig, RouteDockManifest, SessionHandle, type SpendCap, X402Client, fetchManifest, selectMode };
|