@avow-finance/sdk 0.0.0-stage → 0.2.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/LICENSE +201 -0
- package/README.md +122 -2
- package/dist/agent-entry.d.ts +15 -0
- package/dist/agent-entry.d.ts.map +1 -0
- package/dist/agent-entry.js +11 -0
- package/dist/agent-entry.js.map +1 -0
- package/dist/agent-key.d.ts +34 -0
- package/dist/agent-key.d.ts.map +1 -0
- package/dist/agent-key.js +33 -0
- package/dist/agent-key.js.map +1 -0
- package/dist/agent.d.ts +261 -0
- package/dist/agent.d.ts.map +1 -0
- package/dist/agent.js +493 -0
- package/dist/agent.js.map +1 -0
- package/dist/avow-api.d.ts +78 -0
- package/dist/avow-api.d.ts.map +1 -0
- package/dist/avow-api.js +2 -0
- package/dist/avow-api.js.map +1 -0
- package/dist/contest.d.ts +135 -0
- package/dist/contest.d.ts.map +1 -0
- package/dist/contest.js +186 -0
- package/dist/contest.js.map +1 -0
- package/dist/http.d.ts +161 -0
- package/dist/http.d.ts.map +1 -0
- package/dist/http.js +311 -0
- package/dist/http.js.map +1 -0
- package/dist/index.d.ts +38 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +38 -0
- package/dist/index.js.map +1 -0
- package/dist/job/accept.d.ts +84 -0
- package/dist/job/accept.d.ts.map +1 -0
- package/dist/job/accept.js +136 -0
- package/dist/job/accept.js.map +1 -0
- package/dist/job/customer.d.ts +43 -0
- package/dist/job/customer.d.ts.map +1 -0
- package/dist/job/customer.js +83 -0
- package/dist/job/customer.js.map +1 -0
- package/dist/job/quote.d.ts +34 -0
- package/dist/job/quote.d.ts.map +1 -0
- package/dist/job/quote.js +37 -0
- package/dist/job/quote.js.map +1 -0
- package/dist/lock.d.ts +269 -0
- package/dist/lock.d.ts.map +1 -0
- package/dist/lock.js +283 -0
- package/dist/lock.js.map +1 -0
- package/dist/moderato.d.ts +27 -0
- package/dist/moderato.d.ts.map +1 -0
- package/dist/moderato.js +34 -0
- package/dist/moderato.js.map +1 -0
- package/dist/node/cli.d.ts +3 -0
- package/dist/node/cli.d.ts.map +1 -0
- package/dist/node/cli.js +346 -0
- package/dist/node/cli.js.map +1 -0
- package/dist/node/connect.d.ts +15 -0
- package/dist/node/connect.d.ts.map +1 -0
- package/dist/node/connect.js +91 -0
- package/dist/node/connect.js.map +1 -0
- package/dist/node/eval.d.ts +3 -0
- package/dist/node/eval.d.ts.map +1 -0
- package/dist/node/eval.js +67 -0
- package/dist/node/eval.js.map +1 -0
- package/dist/node/first-run.d.ts +50 -0
- package/dist/node/first-run.d.ts.map +1 -0
- package/dist/node/first-run.js +149 -0
- package/dist/node/first-run.js.map +1 -0
- package/dist/node/job.d.ts +50 -0
- package/dist/node/job.d.ts.map +1 -0
- package/dist/node/job.js +176 -0
- package/dist/node/job.js.map +1 -0
- package/dist/node/mailbox.d.ts +19 -0
- package/dist/node/mailbox.d.ts.map +1 -0
- package/dist/node/mailbox.js +81 -0
- package/dist/node/mailbox.js.map +1 -0
- package/dist/node/mcp.d.ts +74 -0
- package/dist/node/mcp.d.ts.map +1 -0
- package/dist/node/mcp.js +367 -0
- package/dist/node/mcp.js.map +1 -0
- package/dist/node/platform.d.ts +35 -0
- package/dist/node/platform.d.ts.map +1 -0
- package/dist/node/platform.js +102 -0
- package/dist/node/platform.js.map +1 -0
- package/dist/node/runner-session.d.ts +41 -0
- package/dist/node/runner-session.d.ts.map +1 -0
- package/dist/node/runner-session.js +100 -0
- package/dist/node/runner-session.js.map +1 -0
- package/dist/node/runner.d.ts +63 -0
- package/dist/node/runner.d.ts.map +1 -0
- package/dist/node/runner.js +341 -0
- package/dist/node/runner.js.map +1 -0
- package/dist/node/service-child.d.ts +2 -0
- package/dist/node/service-child.d.ts.map +1 -0
- package/dist/node/service-child.js +40 -0
- package/dist/node/service-child.js.map +1 -0
- package/dist/node/service-excerpt.d.ts +21 -0
- package/dist/node/service-excerpt.d.ts.map +1 -0
- package/dist/node/service-excerpt.js +32 -0
- package/dist/node/service-excerpt.js.map +1 -0
- package/dist/node/service-process.d.ts +12 -0
- package/dist/node/service-process.d.ts.map +1 -0
- package/dist/node/service-process.js +132 -0
- package/dist/node/service-process.js.map +1 -0
- package/dist/node/session-input.d.ts +12 -0
- package/dist/node/session-input.d.ts.map +1 -0
- package/dist/node/session-input.js +42 -0
- package/dist/node/session-input.js.map +1 -0
- package/dist/node/session-view.d.ts +20 -0
- package/dist/node/session-view.d.ts.map +1 -0
- package/dist/node/session-view.js +198 -0
- package/dist/node/session-view.js.map +1 -0
- package/dist/node-agent.d.ts +2 -0
- package/dist/node-agent.d.ts.map +1 -0
- package/dist/node-agent.js +6 -0
- package/dist/node-agent.js.map +1 -0
- package/dist/node.d.ts +2 -0
- package/dist/node.d.ts.map +1 -0
- package/dist/node.js +9 -0
- package/dist/node.js.map +1 -0
- package/dist/sandbox/agent.d.ts +187 -0
- package/dist/sandbox/agent.d.ts.map +1 -0
- package/dist/sandbox/agent.js +468 -0
- package/dist/sandbox/agent.js.map +1 -0
- package/dist/sandbox/business-store.d.ts +19 -0
- package/dist/sandbox/business-store.d.ts.map +1 -0
- package/dist/sandbox/business-store.js +19 -0
- package/dist/sandbox/business-store.js.map +1 -0
- package/dist/sandbox/business.d.ts +70 -0
- package/dist/sandbox/business.d.ts.map +1 -0
- package/dist/sandbox/business.js +115 -0
- package/dist/sandbox/business.js.map +1 -0
- package/dist/sandbox/connect.d.ts +64 -0
- package/dist/sandbox/connect.d.ts.map +1 -0
- package/dist/sandbox/connect.js +182 -0
- package/dist/sandbox/connect.js.map +1 -0
- package/dist/sandbox/deployment.d.ts +14 -0
- package/dist/sandbox/deployment.d.ts.map +1 -0
- package/dist/sandbox/deployment.js +38 -0
- package/dist/sandbox/deployment.js.map +1 -0
- package/dist/sandbox/keys.d.ts +45 -0
- package/dist/sandbox/keys.d.ts.map +1 -0
- package/dist/sandbox/keys.js +132 -0
- package/dist/sandbox/keys.js.map +1 -0
- package/dist/sandbox/mailbox.d.ts +90 -0
- package/dist/sandbox/mailbox.d.ts.map +1 -0
- package/dist/sandbox/mailbox.js +400 -0
- package/dist/sandbox/mailbox.js.map +1 -0
- package/dist/sandbox/mandate.d.ts +84 -0
- package/dist/sandbox/mandate.d.ts.map +1 -0
- package/dist/sandbox/mandate.js +107 -0
- package/dist/sandbox/mandate.js.map +1 -0
- package/dist/sandbox/namespace.d.ts +16 -0
- package/dist/sandbox/namespace.d.ts.map +1 -0
- package/dist/sandbox/namespace.js +16 -0
- package/dist/sandbox/namespace.js.map +1 -0
- package/dist/sandbox/session.d.ts +60 -0
- package/dist/sandbox/session.d.ts.map +1 -0
- package/dist/sandbox/session.js +94 -0
- package/dist/sandbox/session.js.map +1 -0
- package/dist/sandbox/setup.d.ts +136 -0
- package/dist/sandbox/setup.d.ts.map +1 -0
- package/dist/sandbox/setup.js +490 -0
- package/dist/sandbox/setup.js.map +1 -0
- package/dist/sandbox/store.d.ts +69 -0
- package/dist/sandbox/store.d.ts.map +1 -0
- package/dist/sandbox/store.js +115 -0
- package/dist/sandbox/store.js.map +1 -0
- package/dist/sandbox/supplier-key.d.ts +73 -0
- package/dist/sandbox/supplier-key.d.ts.map +1 -0
- package/dist/sandbox/supplier-key.js +180 -0
- package/dist/sandbox/supplier-key.js.map +1 -0
- package/dist/sandbox/suppliers.d.ts +7 -0
- package/dist/sandbox/suppliers.d.ts.map +1 -0
- package/dist/sandbox/suppliers.js +29 -0
- package/dist/sandbox/suppliers.js.map +1 -0
- package/dist/sandbox/terms.d.ts +32 -0
- package/dist/sandbox/terms.d.ts.map +1 -0
- package/dist/sandbox/terms.js +58 -0
- package/dist/sandbox/terms.js.map +1 -0
- package/dist/sandbox/vault.d.ts +24 -0
- package/dist/sandbox/vault.d.ts.map +1 -0
- package/dist/sandbox/vault.js +54 -0
- package/dist/sandbox/vault.js.map +1 -0
- package/dist/send.d.ts +122 -0
- package/dist/send.d.ts.map +1 -0
- package/dist/send.js +328 -0
- package/dist/send.js.map +1 -0
- package/dist/service-entry.d.ts +6 -0
- package/dist/service-entry.d.ts.map +1 -0
- package/dist/service-entry.js +6 -0
- package/dist/service-entry.js.map +1 -0
- package/dist/session/anthropic.d.ts +17 -0
- package/dist/session/anthropic.d.ts.map +1 -0
- package/dist/session/anthropic.js +215 -0
- package/dist/session/anthropic.js.map +1 -0
- package/dist/session/charge.d.ts +13 -0
- package/dist/session/charge.d.ts.map +1 -0
- package/dist/session/charge.js +33 -0
- package/dist/session/charge.js.map +1 -0
- package/dist/session/data.d.ts +8 -0
- package/dist/session/data.d.ts.map +1 -0
- package/dist/session/data.js +20 -0
- package/dist/session/data.js.map +1 -0
- package/dist/session/eval.d.ts +41 -0
- package/dist/session/eval.d.ts.map +1 -0
- package/dist/session/eval.js +281 -0
- package/dist/session/eval.js.map +1 -0
- package/dist/session/executor.d.ts +80 -0
- package/dist/session/executor.d.ts.map +1 -0
- package/dist/session/executor.js +381 -0
- package/dist/session/executor.js.map +1 -0
- package/dist/session/fixture-world.d.ts +29 -0
- package/dist/session/fixture-world.d.ts.map +1 -0
- package/dist/session/fixture-world.js +708 -0
- package/dist/session/fixture-world.js.map +1 -0
- package/dist/session/live-world.d.ts +22 -0
- package/dist/session/live-world.d.ts.map +1 -0
- package/dist/session/live-world.js +329 -0
- package/dist/session/live-world.js.map +1 -0
- package/dist/session/ollama.d.ts +29 -0
- package/dist/session/ollama.d.ts.map +1 -0
- package/dist/session/ollama.js +177 -0
- package/dist/session/ollama.js.map +1 -0
- package/dist/session/provider.d.ts +79 -0
- package/dist/session/provider.d.ts.map +1 -0
- package/dist/session/provider.js +19 -0
- package/dist/session/provider.js.map +1 -0
- package/dist/session/scripted.d.ts +45 -0
- package/dist/session/scripted.d.ts.map +1 -0
- package/dist/session/scripted.js +236 -0
- package/dist/session/scripted.js.map +1 -0
- package/dist/session/selection.d.ts +37 -0
- package/dist/session/selection.d.ts.map +1 -0
- package/dist/session/selection.js +104 -0
- package/dist/session/selection.js.map +1 -0
- package/dist/session/service-check.d.ts +48 -0
- package/dist/session/service-check.d.ts.map +1 -0
- package/dist/session/service-check.js +86 -0
- package/dist/session/service-check.js.map +1 -0
- package/dist/session/service.d.ts +128 -0
- package/dist/session/service.d.ts.map +1 -0
- package/dist/session/service.js +150 -0
- package/dist/session/service.js.map +1 -0
- package/dist/session/session.d.ts +95 -0
- package/dist/session/session.d.ts.map +1 -0
- package/dist/session/session.js +312 -0
- package/dist/session/session.js.map +1 -0
- package/dist/session/toolbox.d.ts +69 -0
- package/dist/session/toolbox.d.ts.map +1 -0
- package/dist/session/toolbox.js +391 -0
- package/dist/session/toolbox.js.map +1 -0
- package/dist/session/tools.d.ts +45 -0
- package/dist/session/tools.d.ts.map +1 -0
- package/dist/session/tools.js +137 -0
- package/dist/session/tools.js.map +1 -0
- package/dist/session/world.d.ts +188 -0
- package/dist/session/world.d.ts.map +1 -0
- package/dist/session/world.js +2 -0
- package/dist/session/world.js.map +1 -0
- package/dist/sign.d.ts +19 -0
- package/dist/sign.d.ts.map +1 -0
- package/dist/sign.js +33 -0
- package/dist/sign.js.map +1 -0
- package/dist/supplier.d.ts +41 -0
- package/dist/supplier.d.ts.map +1 -0
- package/dist/supplier.js +57 -0
- package/dist/supplier.js.map +1 -0
- package/package.json +56 -3
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vault.js","sourceRoot":"","sources":["../../src/sandbox/vault.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,UAAU,EAAY,UAAU,EAAE,KAAK,EAAE,MAAM,MAAM,CAAA;AAiB5E,mDAAmD;AACnD,MAAM,CAAC,MAAM,cAAc,GAAG,EAAE,CAAA;AAEhC,mGAAmG;AACnG,MAAM,UAAU,GAAG,OAAO,CAAA;AAE1B,iGAAiG;AACjG,MAAM,OAAO,GAAG,CAAC,OAAgB,EAAE,EAAE,CACnC,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,6BAA6B,OAAO,CAAC,WAAW,EAAE,EAAE,CAAC,CAAA;AAEhF,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C,CAAC,CAAC,UAAU,CAAC;QAC9B,CAAC,CAAC,UAAU,IAAI,OAAO;QACvB,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,UAAU,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,QAAQ,IAAI,KAAK,CAAC,CAAC,CAAC,CAAC,CAC7E,CAAA;AACH,CAAC"}
|
package/dist/send.d.ts
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { type Account, type Chain, type Client, type Hex, type TransactionReceipt, type Transport } from 'viem';
|
|
2
|
+
import type { Call } from './lock.js';
|
|
3
|
+
/** How hard the sender tries before it gives up. */
|
|
4
|
+
export interface SendLimits {
|
|
5
|
+
/** How many times it prepares a transaction the node refuses, a few seconds apart. */
|
|
6
|
+
prepareTries: number;
|
|
7
|
+
/** How many times it sends the same signed bytes while the node answers with an error. */
|
|
8
|
+
sendTries: number;
|
|
9
|
+
/** How many times it signs, when each transaction before expired in no block. */
|
|
10
|
+
signings: number;
|
|
11
|
+
/** Milliseconds between tries and between reads of the chain. */
|
|
12
|
+
wait: number;
|
|
13
|
+
/** Milliseconds it waits for one transaction's outcome before it gives up, not knowing it. */
|
|
14
|
+
receiptTimeout: number;
|
|
15
|
+
}
|
|
16
|
+
export declare const SEND_LIMITS: SendLimits;
|
|
17
|
+
/**
|
|
18
|
+
* Why a send failed, with the hash of every transaction it sent and how many the key signed. Its
|
|
19
|
+
* outcome is `failed` when nothing it sent took effect or still can, and `unknown` when a
|
|
20
|
+
* transaction may have landed, so the caller has to read the chain before acting again. A `failed`
|
|
21
|
+
* after signing assumes nobody sent the signed transaction but the sender, which the relay's
|
|
22
|
+
* contract promises.
|
|
23
|
+
*/
|
|
24
|
+
export declare class SendError extends Error {
|
|
25
|
+
readonly outcome: 'failed' | 'unknown';
|
|
26
|
+
/** The hash of every transaction the sender sent, each of them one the key signed. */
|
|
27
|
+
readonly hashes: readonly Hex[];
|
|
28
|
+
readonly signings: number;
|
|
29
|
+
/** Another hash the node answered a send with, which may name any transaction. */
|
|
30
|
+
readonly answered: Hex | null;
|
|
31
|
+
/** Where the send stopped, or null when the thrower didn't say. */
|
|
32
|
+
readonly stage: SendStage | null;
|
|
33
|
+
constructor(message: string, outcome: 'failed' | 'unknown', sent: {
|
|
34
|
+
hashes: readonly Hex[];
|
|
35
|
+
signings: number;
|
|
36
|
+
answered?: Hex;
|
|
37
|
+
}, options?: {
|
|
38
|
+
cause?: unknown;
|
|
39
|
+
stage?: SendStage;
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Where a send stopped. `prepare` is the node refusing to prepare it, a revert there included.
|
|
44
|
+
* `head` is the node not giving its latest block, `relay` Avow's relay not co-signing, and
|
|
45
|
+
* `altered` the relay handing back other bytes than the transaction the key signed. `submit` is
|
|
46
|
+
* the node never taking it, and `expired` a transaction that expired in no block. `landed` is one
|
|
47
|
+
* that landed and reverted, or whose outcome after landing the chain didn't show in time.
|
|
48
|
+
*/
|
|
49
|
+
export type SendStage = 'prepare' | 'head' | 'relay' | 'altered' | 'submit' | 'expired' | 'landed';
|
|
50
|
+
/** The send error somewhere in an error's causes, such as inside a booking's error. */
|
|
51
|
+
export declare function sendErrorIn(error: unknown): SendError | null;
|
|
52
|
+
/** Whether a transaction a sender sent landed and reverted, somewhere in an error's causes. */
|
|
53
|
+
export declare function landedReverted(error: unknown): boolean;
|
|
54
|
+
/**
|
|
55
|
+
* Why the relay's bytes aren't the transaction the key signed with a fee payer's signature added,
|
|
56
|
+
* or null when they are. The payload the key signed has to be the same in both, which covers every
|
|
57
|
+
* call with its destination, data and value, the nonce, the validity window, the gas and fees, and
|
|
58
|
+
* any key authorization, and the key's signature has to be the same too. Only the fee token, which
|
|
59
|
+
* a sender doesn't sign, and the fee payer's signature may differ.
|
|
60
|
+
*/
|
|
61
|
+
export declare function cosignProblem(signed: Hex, cosigned: Hex): string | null;
|
|
62
|
+
/**
|
|
63
|
+
* How much gas a sponsored transaction asks for beyond the node's estimate, in percent. Tempo's
|
|
64
|
+
* estimate for a business's first reserve leaves little room, and the relay pays only up to the
|
|
65
|
+
* gas limit the key signed, so a little headroom lets a run that needs slightly more land.
|
|
66
|
+
*/
|
|
67
|
+
export declare const SPONSORED_GAS_HEADROOM_PERCENT = 15n;
|
|
68
|
+
/**
|
|
69
|
+
* A gas estimate with the sponsored headroom added, rounded up, and held to the relay's gas cap,
|
|
70
|
+
* so the headroom never turns a transaction the relay would pay for into one over its cap. An
|
|
71
|
+
* estimate already at or over the cap stays as it is, so the relay's refusal names the real need.
|
|
72
|
+
*/
|
|
73
|
+
export declare function withGasHeadroom(gas: bigint, cap?: bigint): bigint;
|
|
74
|
+
/** Called with each transaction's hash and `validBefore` before its bytes go to the node. */
|
|
75
|
+
export type OnSent = (hash: Hex, validBefore: bigint | null) => unknown;
|
|
76
|
+
/**
|
|
77
|
+
* Sends a transaction whose fee Avow's relay pays. The key signs it locally with `feePayer: true`
|
|
78
|
+
* and a gas limit 15% over the node's estimate, up to the relay's gas cap, the relay co-signs it, and the sender checks the relay's bytes are the transaction the key
|
|
79
|
+
* signed before sending them and tracking their hash from the start, since the public RPC can
|
|
80
|
+
* answer with an error after a transaction has landed. viem makes a sponsored transaction valid
|
|
81
|
+
* for under half a minute. The sender signs again only once it has read every finalized block,
|
|
82
|
+
* from before the key signed up to one later than that expiry, and found the transaction in none,
|
|
83
|
+
* up to the limit's number of signings. It throws a `SendError` when the transaction can't be
|
|
84
|
+
* prepared, lands reverted, never lands, or has an outcome the chain didn't show in time.
|
|
85
|
+
*/
|
|
86
|
+
export declare function sendSponsored(args: {
|
|
87
|
+
client: Client<Transport, Chain>;
|
|
88
|
+
account: Account;
|
|
89
|
+
calls: readonly Call[];
|
|
90
|
+
/**
|
|
91
|
+
* Has the relay co-sign the signed transaction and returns the co-signed bytes. It must never
|
|
92
|
+
* send the transaction itself or pass it on, since anyone holding it could land it until it
|
|
93
|
+
* expires, and the sender's outcomes assume only the sender sends it.
|
|
94
|
+
*/
|
|
95
|
+
sponsor: (transaction: Hex) => Promise<Hex>;
|
|
96
|
+
/** Called with each hash before its bytes go to the node, and awaited. */
|
|
97
|
+
onSent?: OnSent;
|
|
98
|
+
limits?: SendLimits;
|
|
99
|
+
/**
|
|
100
|
+
* The most gas the relay pays for in this transaction, which the headroom never goes past. A
|
|
101
|
+
* reserve's cap by default, for a deployment that sets a lower one.
|
|
102
|
+
*/
|
|
103
|
+
gasCap?: bigint;
|
|
104
|
+
}): Promise<TransactionReceipt>;
|
|
105
|
+
/**
|
|
106
|
+
* Sends a transaction the account pays its own fee for, as a business account's root key does to
|
|
107
|
+
* create its lock or approve a supplier, or a supplier does to send its acceptance. It's signed
|
|
108
|
+
* locally on an expiring nonce and tracked by hash from the start, with every outcome
|
|
109
|
+
* `sendSponsored` gives, and it can carry a key authorization that puts an agent's key on the
|
|
110
|
+
* account in the same transaction.
|
|
111
|
+
*/
|
|
112
|
+
export declare function sendOwn(args: {
|
|
113
|
+
client: Client<Transport, Chain>;
|
|
114
|
+
account: Account;
|
|
115
|
+
calls: readonly Call[];
|
|
116
|
+
/** A key authorization the account's root key signed, as `Account.signKeyAuthorization` gives. */
|
|
117
|
+
keyAuthorization?: unknown;
|
|
118
|
+
/** Called with each hash before its bytes go to the node, and awaited. */
|
|
119
|
+
onSent?: OnSent;
|
|
120
|
+
limits?: SendLimits;
|
|
121
|
+
}): Promise<TransactionReceipt>;
|
|
122
|
+
//# sourceMappingURL=send.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"send.d.ts","sourceRoot":"","sources":["../src/send.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,KAAK,OAAO,EACZ,KAAK,KAAK,EACV,KAAK,MAAM,EACX,KAAK,GAAG,EAER,KAAK,kBAAkB,EACvB,KAAK,SAAS,EACf,MAAM,MAAM,CAAA;AASb,OAAO,KAAK,EAAE,IAA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AE,MAAM,CAAA;IACf,MAAM,CAAC,EAAE,UAAU,CAAA;CACpB,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAS9B"}
|
package/dist/send.js
ADDED
|
@@ -0,0 +1,328 @@
|
|
|
1
|
+
import { SPONSORED_RESERVE_GAS_CAP } from '@avow-finance/spec';
|
|
2
|
+
import { TxEnvelopeTempo } from 'ox/tempo';
|
|
3
|
+
import { keccak256, } from 'viem';
|
|
4
|
+
import { getBlock, getBlockNumber, getTransaction, getTransactionReceipt, prepareTransactionRequest, signTransaction, } from 'viem/actions';
|
|
5
|
+
export const SEND_LIMITS = {
|
|
6
|
+
prepareTries: 4,
|
|
7
|
+
sendTries: 4,
|
|
8
|
+
signings: 3,
|
|
9
|
+
wait: 2000,
|
|
10
|
+
receiptTimeout: 180_000,
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Why a send failed, with the hash of every transaction it sent and how many the key signed. Its
|
|
14
|
+
* outcome is `failed` when nothing it sent took effect or still can, and `unknown` when a
|
|
15
|
+
* transaction may have landed, so the caller has to read the chain before acting again. A `failed`
|
|
16
|
+
* after signing assumes nobody sent the signed transaction but the sender, which the relay's
|
|
17
|
+
* contract promises.
|
|
18
|
+
*/
|
|
19
|
+
export class SendError extends Error {
|
|
20
|
+
outcome;
|
|
21
|
+
/** The hash of every transaction the sender sent, each of them one the key signed. */
|
|
22
|
+
hashes;
|
|
23
|
+
signings;
|
|
24
|
+
/** Another hash the node answered a send with, which may name any transaction. */
|
|
25
|
+
answered;
|
|
26
|
+
/** Where the send stopped, or null when the thrower didn't say. */
|
|
27
|
+
stage;
|
|
28
|
+
constructor(message, outcome, sent, options) {
|
|
29
|
+
super(message, options?.cause === undefined ? undefined : { cause: options.cause });
|
|
30
|
+
this.name = 'SendError';
|
|
31
|
+
this.outcome = outcome;
|
|
32
|
+
this.hashes = [...sent.hashes];
|
|
33
|
+
this.signings = sent.signings;
|
|
34
|
+
this.answered = sent.answered ?? null;
|
|
35
|
+
this.stage = options?.stage ?? null;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
/** The send error somewhere in an error's causes, such as inside a booking's error. */
|
|
39
|
+
export function sendErrorIn(error) {
|
|
40
|
+
let e = error;
|
|
41
|
+
for (let i = 0; i < 6 && e instanceof Error; i++) {
|
|
42
|
+
if (e instanceof SendError)
|
|
43
|
+
return e;
|
|
44
|
+
e = e.cause;
|
|
45
|
+
}
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
/** Whether a transaction a sender sent landed and reverted, somewhere in an error's causes. */
|
|
49
|
+
export function landedReverted(error) {
|
|
50
|
+
const stopped = sendErrorIn(error);
|
|
51
|
+
return stopped?.stage === 'landed' && stopped.outcome === 'failed';
|
|
52
|
+
}
|
|
53
|
+
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
54
|
+
const reason = (e) => (e instanceof Error ? e.message : String(e)).slice(0, 300);
|
|
55
|
+
function checked(limits) {
|
|
56
|
+
for (const [name, value] of Object.entries(limits)) {
|
|
57
|
+
if (!Number.isInteger(value) || value < 1) {
|
|
58
|
+
throw new RangeError(`The send limit ${name} has to be a whole number of at least 1`);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return limits;
|
|
62
|
+
}
|
|
63
|
+
async function prepare(client, account, calls, fields, limits, sent) {
|
|
64
|
+
for (let i = 1;; i++) {
|
|
65
|
+
try {
|
|
66
|
+
// `calls`, `feePayer`, `nonceKey` and `keyAuthorization` are Tempo's transaction fields,
|
|
67
|
+
// which viem's generic types omit.
|
|
68
|
+
return (await prepareTransactionRequest(client, {
|
|
69
|
+
account,
|
|
70
|
+
calls,
|
|
71
|
+
...fields,
|
|
72
|
+
}));
|
|
73
|
+
}
|
|
74
|
+
catch (error) {
|
|
75
|
+
// A node a block behind can see a step as not due yet, so a refusal counts once it holds.
|
|
76
|
+
if (i >= limits.prepareTries) {
|
|
77
|
+
throw new SendError(`The node refused to prepare the transaction: ${reason(error)}`, 'failed', sent, { cause: error, stage: 'prepare' });
|
|
78
|
+
}
|
|
79
|
+
await sleep(limits.wait);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
/** The fields a sender signs, named when the relay's bytes change one. */
|
|
84
|
+
const SIGNED_FIELDS = [
|
|
85
|
+
'chainId',
|
|
86
|
+
'calls',
|
|
87
|
+
'nonce',
|
|
88
|
+
'nonceKey',
|
|
89
|
+
'validBefore',
|
|
90
|
+
'validAfter',
|
|
91
|
+
'gas',
|
|
92
|
+
'maxFeePerGas',
|
|
93
|
+
'maxPriorityFeePerGas',
|
|
94
|
+
'accessList',
|
|
95
|
+
'authorizationList',
|
|
96
|
+
'keyAuthorization',
|
|
97
|
+
];
|
|
98
|
+
const same = (a, b) => JSON.stringify(a, (_, v) => (typeof v === 'bigint' ? v.toString() : v)) ===
|
|
99
|
+
JSON.stringify(b, (_, v) => (typeof v === 'bigint' ? v.toString() : v));
|
|
100
|
+
/**
|
|
101
|
+
* Why the relay's bytes aren't the transaction the key signed with a fee payer's signature added,
|
|
102
|
+
* or null when they are. The payload the key signed has to be the same in both, which covers every
|
|
103
|
+
* call with its destination, data and value, the nonce, the validity window, the gas and fees, and
|
|
104
|
+
* any key authorization, and the key's signature has to be the same too. Only the fee token, which
|
|
105
|
+
* a sender doesn't sign, and the fee payer's signature may differ.
|
|
106
|
+
*/
|
|
107
|
+
export function cosignProblem(signed, cosigned) {
|
|
108
|
+
let before;
|
|
109
|
+
let after;
|
|
110
|
+
try {
|
|
111
|
+
before = TxEnvelopeTempo.deserialize(signed);
|
|
112
|
+
after = TxEnvelopeTempo.deserialize(cosigned);
|
|
113
|
+
}
|
|
114
|
+
catch {
|
|
115
|
+
return "the bytes aren't a Tempo transaction";
|
|
116
|
+
}
|
|
117
|
+
if (!after.feePayerSignature)
|
|
118
|
+
return 'they carry no fee payer signature';
|
|
119
|
+
if (!before.signature || !same(before.signature, after.signature)) {
|
|
120
|
+
return "they change the key's signature";
|
|
121
|
+
}
|
|
122
|
+
if (TxEnvelopeTempo.getSignPayload(before) !== TxEnvelopeTempo.getSignPayload(after)) {
|
|
123
|
+
const changed = SIGNED_FIELDS.find((field) => !same(before[field], after[field]));
|
|
124
|
+
return `they change what the key signed${changed ? `, its ${changed} among it` : ''}`;
|
|
125
|
+
}
|
|
126
|
+
return null;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Sends the bytes, and returns null once the node has them, or the node's last error when it
|
|
130
|
+
* never took them. The public RPC can answer with an error after taking a transaction, so an
|
|
131
|
+
* error counts only while the node doesn't know the hash. The same bytes are the same
|
|
132
|
+
* transaction, so sending them again never sends a second one.
|
|
133
|
+
*/
|
|
134
|
+
async function submit(client, bytes, hash, limits, sent) {
|
|
135
|
+
let last = null;
|
|
136
|
+
for (let i = 0; i < limits.sendTries; i++) {
|
|
137
|
+
try {
|
|
138
|
+
const answer = await client.request({ method: 'eth_sendRawTransaction', params: [bytes] });
|
|
139
|
+
if (typeof answer === 'string' && answer.toLowerCase() !== hash.toLowerCase()) {
|
|
140
|
+
throw new SendError(`The node answered with the hash ${answer}, not ${hash}`, 'unknown', { ...sent, answered: answer }, { stage: 'submit' });
|
|
141
|
+
}
|
|
142
|
+
return null;
|
|
143
|
+
}
|
|
144
|
+
catch (error) {
|
|
145
|
+
if (error instanceof SendError)
|
|
146
|
+
throw error;
|
|
147
|
+
last = error;
|
|
148
|
+
}
|
|
149
|
+
await sleep(limits.wait);
|
|
150
|
+
if (await getTransaction(client, { hash }).catch(() => null))
|
|
151
|
+
return null;
|
|
152
|
+
}
|
|
153
|
+
return last ?? new Error('The node never took the transaction');
|
|
154
|
+
}
|
|
155
|
+
/** The latest block's number, read again while the node answers with an error. */
|
|
156
|
+
async function latestBlock(client, limits, sent) {
|
|
157
|
+
for (let i = 1;; i++) {
|
|
158
|
+
try {
|
|
159
|
+
return await getBlockNumber(client, { cacheTime: 0 });
|
|
160
|
+
}
|
|
161
|
+
catch (error) {
|
|
162
|
+
if (i >= limits.prepareTries) {
|
|
163
|
+
throw new SendError(`The node didn't give its latest block: ${reason(error)}`, 'failed', sent, {
|
|
164
|
+
cause: error,
|
|
165
|
+
stage: 'head',
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
await sleep(limits.wait);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Waits for a transaction's outcome. It looks for the receipt, and reads each block by number for
|
|
174
|
+
* the transaction's hash, from the block the node was at before the key signed. It reads only
|
|
175
|
+
* blocks at or below the chain's finalized block, which no later answer can change, and a block
|
|
176
|
+
* read by number comes whole or not at all, so a node that's behind can't hide a block. Each block
|
|
177
|
+
* has to name the one read before it as its parent, or the scan starts again. A failed or missing
|
|
178
|
+
* read stops the scan at that block until a later read gets it. Once the scan reads a block
|
|
179
|
+
* later than the transaction's expiry, and no block before it held the hash, the transaction never
|
|
180
|
+
* landed and no later block can include it. Tempo only includes a transaction in a block before its
|
|
181
|
+
* `validBefore`, and a block later than it counts here, one second more cautious than that rule.
|
|
182
|
+
*/
|
|
183
|
+
async function outcomeOf(client, hash, from, validBefore, limits, sent) {
|
|
184
|
+
const deadline = Date.now() + limits.receiptTimeout;
|
|
185
|
+
const late = () => Date.now() > deadline;
|
|
186
|
+
const wanted = hash.toLowerCase();
|
|
187
|
+
let next = from;
|
|
188
|
+
let parent = null;
|
|
189
|
+
let includedIn = null;
|
|
190
|
+
for (;;) {
|
|
191
|
+
const receipt = await getTransactionReceipt(client, { hash }).catch(() => null);
|
|
192
|
+
if (receipt)
|
|
193
|
+
return receipt;
|
|
194
|
+
if (validBefore !== undefined && includedIn === null) {
|
|
195
|
+
const final = await getBlock(client, { blockTag: 'finalized' }).catch(() => null);
|
|
196
|
+
while (final && next <= final.number && includedIn === null && !late()) {
|
|
197
|
+
const block = await getBlock(client, { blockNumber: next }).catch(() => null);
|
|
198
|
+
if (!block)
|
|
199
|
+
break;
|
|
200
|
+
// Each block has to follow the one read before it. One that doesn't means the blocks
|
|
201
|
+
// read so far weren't all one chain, so the scan starts again.
|
|
202
|
+
if (parent !== null && block.parentHash.toLowerCase() !== parent.toLowerCase()) {
|
|
203
|
+
next = from;
|
|
204
|
+
parent = null;
|
|
205
|
+
break;
|
|
206
|
+
}
|
|
207
|
+
if (block.transactions.some((t) => String(t).toLowerCase() === wanted))
|
|
208
|
+
includedIn = next;
|
|
209
|
+
else if (block.timestamp > BigInt(validBefore))
|
|
210
|
+
return 'expired';
|
|
211
|
+
else {
|
|
212
|
+
parent = block.hash;
|
|
213
|
+
next++;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
if (late()) {
|
|
218
|
+
throw new SendError(includedIn === null
|
|
219
|
+
? `No receipt for ${hash} after waiting, so whether it landed is unknown`
|
|
220
|
+
: `${hash} landed in block ${includedIn}, but its receipt never came, so its outcome is unknown`, 'unknown', sent, { stage: 'landed' });
|
|
221
|
+
}
|
|
222
|
+
await sleep(limits.wait);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* How much gas a sponsored transaction asks for beyond the node's estimate, in percent. Tempo's
|
|
227
|
+
* estimate for a business's first reserve leaves little room, and the relay pays only up to the
|
|
228
|
+
* gas limit the key signed, so a little headroom lets a run that needs slightly more land.
|
|
229
|
+
*/
|
|
230
|
+
export const SPONSORED_GAS_HEADROOM_PERCENT = 15n;
|
|
231
|
+
/**
|
|
232
|
+
* A gas estimate with the sponsored headroom added, rounded up, and held to the relay's gas cap,
|
|
233
|
+
* so the headroom never turns a transaction the relay would pay for into one over its cap. An
|
|
234
|
+
* estimate already at or over the cap stays as it is, so the relay's refusal names the real need.
|
|
235
|
+
*/
|
|
236
|
+
export function withGasHeadroom(gas, cap = SPONSORED_RESERVE_GAS_CAP) {
|
|
237
|
+
if (gas >= cap)
|
|
238
|
+
return gas;
|
|
239
|
+
const padded = (gas * (100n + SPONSORED_GAS_HEADROOM_PERCENT) + 99n) / 100n;
|
|
240
|
+
return padded < cap ? padded : cap;
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* Sends a transaction whose fee Avow's relay pays. The key signs it locally with `feePayer: true`
|
|
244
|
+
* and a gas limit 15% over the node's estimate, up to the relay's gas cap, the relay co-signs it, and the sender checks the relay's bytes are the transaction the key
|
|
245
|
+
* signed before sending them and tracking their hash from the start, since the public RPC can
|
|
246
|
+
* answer with an error after a transaction has landed. viem makes a sponsored transaction valid
|
|
247
|
+
* for under half a minute. The sender signs again only once it has read every finalized block,
|
|
248
|
+
* from before the key signed up to one later than that expiry, and found the transaction in none,
|
|
249
|
+
* up to the limit's number of signings. It throws a `SendError` when the transaction can't be
|
|
250
|
+
* prepared, lands reverted, never lands, or has an outcome the chain didn't show in time.
|
|
251
|
+
*/
|
|
252
|
+
export function sendSponsored(args) {
|
|
253
|
+
const cap = args.gasCap ?? SPONSORED_RESERVE_GAS_CAP;
|
|
254
|
+
if (cap < 1n)
|
|
255
|
+
throw new RangeError('The sponsored gas cap has to be at least 1');
|
|
256
|
+
return send(args, { feePayer: true }, (gas) => withGasHeadroom(gas, cap), async (signed, sent) => {
|
|
257
|
+
let bytes;
|
|
258
|
+
try {
|
|
259
|
+
bytes = await args.sponsor(signed);
|
|
260
|
+
}
|
|
261
|
+
catch (error) {
|
|
262
|
+
throw new SendError(`The relay didn't co-sign: ${reason(error)}`, 'failed', sent, {
|
|
263
|
+
cause: error,
|
|
264
|
+
stage: 'relay',
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
const problem = cosignProblem(signed, bytes);
|
|
268
|
+
if (problem) {
|
|
269
|
+
throw new SendError(`The relay's bytes aren't the transaction the key signed: ${problem}`, 'failed', sent, { stage: 'altered' });
|
|
270
|
+
}
|
|
271
|
+
return bytes;
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* Sends a transaction the account pays its own fee for, as a business account's root key does to
|
|
276
|
+
* create its lock or approve a supplier, or a supplier does to send its acceptance. It's signed
|
|
277
|
+
* locally on an expiring nonce and tracked by hash from the start, with every outcome
|
|
278
|
+
* `sendSponsored` gives, and it can carry a key authorization that puts an agent's key on the
|
|
279
|
+
* account in the same transaction.
|
|
280
|
+
*/
|
|
281
|
+
export function sendOwn(args) {
|
|
282
|
+
const fields = { nonceKey: 'expiring' };
|
|
283
|
+
if (args.keyAuthorization !== undefined)
|
|
284
|
+
fields.keyAuthorization = args.keyAuthorization;
|
|
285
|
+
return send(args, fields, (gas) => gas, async (signed) => signed);
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* The send both senders share. `gasFor` turns the node's gas estimate into the gas limit the key
|
|
289
|
+
* signs, and `finish` turns the bytes the key signed into the bytes that go to the node, and throws
|
|
290
|
+
* a `SendError` when it can't.
|
|
291
|
+
*/
|
|
292
|
+
async function send(args, fields, gasFor, finish) {
|
|
293
|
+
const limits = checked(args.limits ?? SEND_LIMITS);
|
|
294
|
+
const sent = { hashes: [], signings: 0 };
|
|
295
|
+
for (;;) {
|
|
296
|
+
const request = await prepare(args.client, args.account, args.calls, fields, limits, sent);
|
|
297
|
+
// Read before the key signs, so no block that could hold the transaction comes before it.
|
|
298
|
+
const from = await latestBlock(args.client, limits, sent);
|
|
299
|
+
const signed = await signTransaction(args.client, {
|
|
300
|
+
...request,
|
|
301
|
+
...(request.gas === undefined ? {} : { gas: gasFor(request.gas) }),
|
|
302
|
+
account: args.account,
|
|
303
|
+
});
|
|
304
|
+
sent.signings++;
|
|
305
|
+
const bytes = await finish(signed, sent);
|
|
306
|
+
const hash = keccak256(bytes);
|
|
307
|
+
sent.hashes.push(hash);
|
|
308
|
+
await args.onSent?.(hash, request.validBefore === undefined ? null : BigInt(request.validBefore));
|
|
309
|
+
const refused = await submit(args.client, bytes, hash, limits, sent);
|
|
310
|
+
const outcome = await outcomeOf(args.client, hash, from, request.validBefore, limits, sent);
|
|
311
|
+
if (outcome !== 'expired') {
|
|
312
|
+
if (outcome.status !== 'success') {
|
|
313
|
+
throw new SendError(`The transaction ${hash} reverted`, 'failed', sent, { stage: 'landed' });
|
|
314
|
+
}
|
|
315
|
+
return outcome;
|
|
316
|
+
}
|
|
317
|
+
if (refused !== null) {
|
|
318
|
+
throw new SendError(`The node never took the transaction: ${reason(refused)}`, 'failed', sent, {
|
|
319
|
+
cause: refused,
|
|
320
|
+
stage: 'submit',
|
|
321
|
+
});
|
|
322
|
+
}
|
|
323
|
+
if (sent.signings >= limits.signings) {
|
|
324
|
+
throw new SendError(`The transaction expired in no block, ${sent.signings} times`, 'failed', sent, { stage: 'expired' });
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
//# sourceMappingURL=send.js.map
|
package/dist/send.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"send.js","sourceRoot":"","sources":["../src/send.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,oBAAoB,CAAA;AAC9D,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAA;AAC1C,OAAO,EAKL,SAAS,GAGV,MAAM,MAAM,CAAA;AACb,OAAO,EACL,QAAQ,EACR,cAAc,EACd,cAAc,EACd,qBAAqB,EACrB,yBAAyB,EACzB,eAAe,GAChB,MAAM,cAAc,CAAA;AAiBrB,MAAM,CAAC,MAAM,WAAW,GAAe;IACrC,YAAY,EAAE,CAAC;IACf,SAAS,EAAE,CAAC;IACZ,QAAQ,EAAE,CAAC;IACX,IAAI,EAAE,IAAI;IACV,cAAc,EAAE,OAAO;CACxB,CAAA;AAED;;;;;;GAMG;AACH,MAAM,OAAO,SAAU,SAAQ,KAAK;IACzB,OAAO,CAAsB;IACtC,sFAAsF;IAC7E,MAAM,CAAgB;IACtB,QAAQ,CAAQ;IACzB,kFAAkF;IACzE,QAAQ,CAAY;IAC7B,mEAAmE;IAC1D,KAAK,CAAkB;IAEhC,YACE,OAAe,EACf,OAA6B,EAC7B,IAAkE,EAClE,OAAgD;QA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,MAAM,SAAS,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,CAAC,WAAW,EAAE,MAAM,EAAE,IAAI,CAAC,CAAA;QAC3F,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;YAC1B,IAAI,OAAO,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;gBACjC,MAAM,IAAI,SAAS,CAAC,mBAAmB,IAAI,WAAW,EAAE,QAAQ,EAAE,IAAI,EAAE,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC,CAAA;YAC9F,CAAC;YACD,OAAO,OAAO,CAAA;QAChB,CAAC;QACD,IAAI,OAAO,KAAK,IAAI,EAAE,CAAC;YACrB,MAAM,IAAI,SAAS,CACjB,wCAAwC,MAAM,CAAC,OAAO,CAAC,EAAE,EACzD,QAAQ,EACR,IAAI,EACJ;gBACE,KAAK,EAAE,OAAO;gBACd,KAAK,EAAE,QAAQ;aAChB,CACF,CAAA;QACH,CAAC;QACD,IAAI,IAAI,CAAC,QAAQ,IAAI,MAAM,CAAC,QAAQ,EAAE,CAAC;YACrC,MAAM,IAAI,SAAS,CACjB,wCAAwC,IAAI,CAAC,QAAQ,QAAQ,EAC7D,QAAQ,EACR,IAAI,EACJ,EAAE,KAAK,EAAE,SAAS,EAAE,CACrB,CAAA;QACH,CAAC;IACH,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a developer's `service.ts` imports: `defineService`, the verdicts `checkBeforeWork` returns,
|
|
3
|
+
* and their types. It holds nothing that signs or moves money.
|
|
4
|
+
*/
|
|
5
|
+
export { type CommitmentCheck, defineService, dontStart, type ReservedJob, type Service, type ServiceChecks, type ServiceFile, start, type Verdict, } from './session/service.js';
|
|
6
|
+
//# sourceMappingURL=service-entry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"service-entry.d.ts","sourceRoot":"","sources":["../src/service-entry.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EACL,KAAK,eAAe,EACpB,aAAa,EACb,SAAS,EACT,KAAK,WAAW,EAChB,KAAK,OAAO,EACZ,KAAK,aAAa,EAClB,KAAK,WAAW,EAChB,KAAK,EACL,KAAK,OAAO,GACb,MAAM,sBAAsB,CAAA"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a developer's `service.ts` imports: `defineService`, the verdicts `checkBeforeWork` returns,
|
|
3
|
+
* and their types. It holds nothing that signs or moves money.
|
|
4
|
+
*/
|
|
5
|
+
export { defineService, dontStart, start, } from './session/service.js';
|
|
6
|
+
//# sourceMappingURL=service-entry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"service-entry.js","sourceRoot":"","sources":["../src/service-entry.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAEL,aAAa,EACb,SAAS,EAKT,KAAK,GAEN,MAAM,sBAAsB,CAAA"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type ModelProvider } from './provider.js';
|
|
2
|
+
/**
|
|
3
|
+
* A Claude model through Anthropic's Messages API, with the developer's own key. Every call is
|
|
4
|
+
* billed to that key, so the session runs it only when the developer chose it.
|
|
5
|
+
*/
|
|
6
|
+
/** The model the session asks for when the developer names none. */
|
|
7
|
+
export declare const ANTHROPIC_MODEL = "claude-sonnet-5-5";
|
|
8
|
+
/**
|
|
9
|
+
* A Claude model, through the Messages API with tools and streaming. The key comes from the
|
|
10
|
+
* environment the session runs in and goes only to Anthropic, in the request's header.
|
|
11
|
+
*/
|
|
12
|
+
export declare function anthropicProvider(options: {
|
|
13
|
+
apiKey: string;
|
|
14
|
+
model?: string;
|
|
15
|
+
fetch?: typeof fetch;
|
|
16
|
+
}): ModelProvider;
|
|
17
|
+
//# sourceMappingURL=anthropic.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"anthropic.d.ts","sourceRoot":"","sources":["../../src/session/anthropic.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,aAAa,EAKnB,MAAM,eAAe,CAAA;AAEtB;;;GAGG;AAEH,oEAAoE;AACpE,eAAO,MAAM,eAAe,sBAAsB,CAAA;AAgGlD;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE;IACzC,MAAM,EAAE,MAAM,CAAA;IACd,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,KAAK,CAAC,EAAE,OAAO,KAAK,CAAA;CACrB,GAAG,aAAa,CAkIhB"}
|