@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
package/dist/agent.d.ts
ADDED
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
import { type Approval, type AvowDomain, type ChainedTerms, type CheckedDependency, type Mandate, type RailToken, type ReasonCode, type RefusalLayer, type Signed, type SignedAgreement, type StartReceipt, type SupplierProfile, type Terms, type TermsAgreement, type TermsProfile } from '@avow-finance/spec';
|
|
2
|
+
import { type DependencyDeps, type DependencyRefusal, type LockedBacking } from '@avow-finance/verifier';
|
|
3
|
+
import { type Address, type Chain, type Client, type Hex, type Transport } from 'viem';
|
|
4
|
+
import type { Account as TempoAccount } from 'viem/tempo';
|
|
5
|
+
import type { AvowApi, AvowRecords } from './avow-api.js';
|
|
6
|
+
import { type Call } from './lock.js';
|
|
7
|
+
import { type SendLimits } from './send.js';
|
|
8
|
+
import type { SupplierConnection } from './supplier.js';
|
|
9
|
+
/** An agent's access key on its business account, as Tempo signs with it. */
|
|
10
|
+
export type AgentKey = TempoAccount.AccessKeyAccount;
|
|
11
|
+
/** Where the transaction that funded a reserve landed. */
|
|
12
|
+
export interface Landed {
|
|
13
|
+
transactionHash: Hex;
|
|
14
|
+
blockNumber: bigint;
|
|
15
|
+
}
|
|
16
|
+
export interface AgentConfig<A extends AvowApi = AvowApi> {
|
|
17
|
+
/** A client for the chain the business's lock is on, with the chain's fee token set. */
|
|
18
|
+
client: Client<Transport, Chain>;
|
|
19
|
+
/**
|
|
20
|
+
* The agent's access key on the business account. Its own address is the mandate's agent key.
|
|
21
|
+
* It signs transactions for the account, and Avow's messages with its bare signature.
|
|
22
|
+
*/
|
|
23
|
+
key: AgentKey;
|
|
24
|
+
/** The mandate the business's administrator signed for this agent. It names the chain and lock. */
|
|
25
|
+
mandate: Signed<Mandate>;
|
|
26
|
+
/** The token the business's lock holds reserves in, on the mandate's chain. */
|
|
27
|
+
token: RailToken;
|
|
28
|
+
/** The rules the terms have to meet, the profile Avow and the supplier check them under. */
|
|
29
|
+
profile: TermsProfile;
|
|
30
|
+
/**
|
|
31
|
+
* Avow's side of the commitments. The agent has `cancel` and `start` only when it has `records`,
|
|
32
|
+
* which `httpAvowApi` serves.
|
|
33
|
+
*/
|
|
34
|
+
avow: A;
|
|
35
|
+
/** How long, in seconds, an offer stays open for the supplier and Avow. Ten minutes by default. */
|
|
36
|
+
offerValidity?: bigint;
|
|
37
|
+
/**
|
|
38
|
+
* The longest, in seconds, Avow's approval may stay valid. A failed funding is settled once the
|
|
39
|
+
* approval stops working, so a long one would leave it unsettled. Five minutes by default.
|
|
40
|
+
*/
|
|
41
|
+
maxApprovalValidity?: bigint;
|
|
42
|
+
/** The clock, in unix seconds. The system clock by default. */
|
|
43
|
+
now?: () => bigint;
|
|
44
|
+
/**
|
|
45
|
+
* Sends the transaction that funds a reserve and returns where it landed. By default the key
|
|
46
|
+
* signs it and Avow's relay pays its fee, through `sendSponsored`. An agent whose wallet pays
|
|
47
|
+
* its own fees, or a test, passes its own, and throws a `SendError` when it fails.
|
|
48
|
+
*/
|
|
49
|
+
send?: (calls: Call[]) => Promise<Landed>;
|
|
50
|
+
limits?: SendLimits;
|
|
51
|
+
/**
|
|
52
|
+
* The chain and factory pairs whose locks a booking relied on may sit in, each with its reader,
|
|
53
|
+
* such as `tempoLockReader`. `commitToQuote` refuses version 3 terms with
|
|
54
|
+
* `dependency.lock_unknown` when this is left out.
|
|
55
|
+
*/
|
|
56
|
+
dependencies?: DependencyDeps;
|
|
57
|
+
}
|
|
58
|
+
/** One booking the agent makes with one supplier. */
|
|
59
|
+
export interface Booking {
|
|
60
|
+
supplier: SupplierConnection;
|
|
61
|
+
/**
|
|
62
|
+
* The commitment's version 2 terms, built with the template the booking falls under, such as
|
|
63
|
+
* `gpuReservationTerms` for a GPU reservation. The agent checks them against their template's
|
|
64
|
+
* rules and the profile before anyone sees them.
|
|
65
|
+
*/
|
|
66
|
+
terms: Terms;
|
|
67
|
+
/** The mandate category the booking falls under, such as `compute`. */
|
|
68
|
+
category: string;
|
|
69
|
+
}
|
|
70
|
+
/** Terms a commitment can be made under: version 2, or version 3 through `commitToQuote`. */
|
|
71
|
+
export type CommittedTerms = Terms | ChainedTerms;
|
|
72
|
+
/** A commitment the agent agreed and Avow approved, before any money moved. */
|
|
73
|
+
export interface ApprovedCommitment<T extends CommittedTerms = Terms> {
|
|
74
|
+
commitmentId: Hex;
|
|
75
|
+
supplier: SupplierProfile;
|
|
76
|
+
terms: T;
|
|
77
|
+
/**
|
|
78
|
+
* The commitment's salt, which keeps the terms hash from revealing standard terms. Keep it
|
|
79
|
+
* private, since showing a section of the terms or checking the commitment later needs it.
|
|
80
|
+
*/
|
|
81
|
+
salt: Hex;
|
|
82
|
+
termsHash: Hex;
|
|
83
|
+
agreement: SignedAgreement;
|
|
84
|
+
approval: Signed<Approval>;
|
|
85
|
+
}
|
|
86
|
+
/** A commitment the agent made and funded. */
|
|
87
|
+
export interface Commitment<T extends CommittedTerms = Terms> extends ApprovedCommitment<T> {
|
|
88
|
+
/**
|
|
89
|
+
* The transaction that funded the reserve. It's null when the reserve landed in a transaction
|
|
90
|
+
* the agent didn't send, or when the receipt of the agent's own couldn't be read.
|
|
91
|
+
*/
|
|
92
|
+
reservedIn: Hex | null;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* What the lock says about an approved commitment once Avow's approval can no longer land:
|
|
96
|
+
* `funded` when it holds the reserve under the approval, `failed` when it doesn't, and `unknown`
|
|
97
|
+
* when the chain didn't show it in time.
|
|
98
|
+
*/
|
|
99
|
+
export type Reconciled = {
|
|
100
|
+
outcome: 'funded';
|
|
101
|
+
reservedIn: Hex | null;
|
|
102
|
+
} | {
|
|
103
|
+
outcome: 'failed' | 'unknown';
|
|
104
|
+
};
|
|
105
|
+
/** A booking's outcome. A refusal carries the reason code, and Avow's decision id once it decided. */
|
|
106
|
+
export type BookResult<T extends CommittedTerms = Terms> = {
|
|
107
|
+
ok: true;
|
|
108
|
+
commitment: Commitment<T>;
|
|
109
|
+
} | {
|
|
110
|
+
ok: false;
|
|
111
|
+
reason: ReasonCode;
|
|
112
|
+
decisionId?: string;
|
|
113
|
+
};
|
|
114
|
+
/**
|
|
115
|
+
* Who refused a quote: `avow` is Avow's API declining to approve the reserve, and `sdk` is the
|
|
116
|
+
* agent's own check, before Avow is asked or of what Avow approved. Either way no money moved.
|
|
117
|
+
*/
|
|
118
|
+
export type QuoteRefusalLayer = Extract<RefusalLayer, 'sdk' | 'avow'>;
|
|
119
|
+
/**
|
|
120
|
+
* A quote's outcome. Once funded it lists each booking version 3 terms rely on with the block the
|
|
121
|
+
* agent read it at, just before it funded. A refusal names who refused, and a refusal by that check
|
|
122
|
+
* says which booking failed and the block it was read at.
|
|
123
|
+
*/
|
|
124
|
+
export type QuoteResult = {
|
|
125
|
+
ok: true;
|
|
126
|
+
commitment: Commitment<CommittedTerms>;
|
|
127
|
+
dependencies: readonly CheckedDependency[];
|
|
128
|
+
} | {
|
|
129
|
+
ok: false;
|
|
130
|
+
reason: ReasonCode;
|
|
131
|
+
layer: QuoteRefusalLayer;
|
|
132
|
+
decisionId?: string;
|
|
133
|
+
} | (DependencyRefusal & {
|
|
134
|
+
layer: 'sdk';
|
|
135
|
+
decisionId?: string;
|
|
136
|
+
});
|
|
137
|
+
/** A quote a supplier already signed, which the agent commits to as the buyer. */
|
|
138
|
+
export interface SignedQuote {
|
|
139
|
+
/** The supplier as Avow registered it. Its signing key has to have signed the agreement. */
|
|
140
|
+
supplier: SupplierProfile;
|
|
141
|
+
/** Version 2 terms, or version 3 terms in full. */
|
|
142
|
+
terms: CommittedTerms;
|
|
143
|
+
salt: Hex;
|
|
144
|
+
/**
|
|
145
|
+
* The terms agreement the supplier signed. It names this agent's business as the buyer, the
|
|
146
|
+
* agent's mandate, the supplier and the terms hash of these terms under this salt.
|
|
147
|
+
*/
|
|
148
|
+
agreement: TermsAgreement;
|
|
149
|
+
supplierSignature: Hex;
|
|
150
|
+
/**
|
|
151
|
+
* For version 3 terms, the section of each booking they rely on that the supplier shows, as
|
|
152
|
+
* JSON, in the terms' order.
|
|
153
|
+
*/
|
|
154
|
+
disclosed?: readonly unknown[];
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* A booking whose funding failed after Avow approved it. The agent has already read the lock
|
|
158
|
+
* after the approval stopped working, so `failed` means no reserve was funded and none can be.
|
|
159
|
+
* `unknown` means the chain didn't show the outcome in time. It carries the commitment and every
|
|
160
|
+
* transaction hash sent, so the agent can `reconcile` this booking later instead of making
|
|
161
|
+
* another one.
|
|
162
|
+
*/
|
|
163
|
+
export declare class BookingError extends Error {
|
|
164
|
+
readonly outcome: 'failed' | 'unknown';
|
|
165
|
+
/** The commitment, whose terms are version 3 only when `commitToQuote` made it. */
|
|
166
|
+
readonly commitment: ApprovedCommitment<CommittedTerms>;
|
|
167
|
+
readonly hashes: readonly Hex[];
|
|
168
|
+
constructor(message: string, outcome: 'failed' | 'unknown', commitment: ApprovedCommitment<CommittedTerms>, hashes: readonly Hex[], options?: {
|
|
169
|
+
cause?: unknown;
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
/** What every agent does, whatever its `AvowApi` serves. */
|
|
173
|
+
export interface AgentCalls {
|
|
174
|
+
/** The business account the agent acts for. */
|
|
175
|
+
account: Address;
|
|
176
|
+
/** The business's lock, where its reserves sit. */
|
|
177
|
+
lock: Address;
|
|
178
|
+
/** The chain and the business's lock, which every message the agent signs is signed under. */
|
|
179
|
+
domain: AvowDomain;
|
|
180
|
+
/** The mandate's hash under the business's lock. */
|
|
181
|
+
mandateHash: Hex;
|
|
182
|
+
/**
|
|
183
|
+
* Books with a supplier under the booking's terms and funds the reserve. Before any money
|
|
184
|
+
* moves it refuses, with a reason code, terms of another version than 2, terms or a booking
|
|
185
|
+
* the mandate doesn't allow, a reserve the mandate sends to the administrator, a supplier
|
|
186
|
+
* signature from another key, Avow's refusal, and an approval that differs from the terms or
|
|
187
|
+
* the mandate or that the lock would refuse as late. Once the reserve is funded it checks the
|
|
188
|
+
* lock holds it under Avow's approval. When funding fails it reads the lock after the approval
|
|
189
|
+
* stops working, and returns the commitment if the reserve landed anyway. Otherwise it throws
|
|
190
|
+
* a `BookingError`.
|
|
191
|
+
*/
|
|
192
|
+
book(b: Booking): Promise<BookResult>;
|
|
193
|
+
/**
|
|
194
|
+
* Commits as the buyer to a quote the supplier already signed, and funds the reserve. Before
|
|
195
|
+
* anything is signed it refuses terms that don't hash to the agreement's terms hash, an
|
|
196
|
+
* agreement naming another buyer, mandate or supplier, or one expired or valid too long, and a
|
|
197
|
+
* supplier signature from another key. Version 2 terms then go through the mandate check, as
|
|
198
|
+
* `book` runs it. It signs as the buyer, asks Avow, and checks the approval as `book` does. For
|
|
199
|
+
* version 3 terms it then checks every booking they rely on with `verifyDependencies`, taking
|
|
200
|
+
* the owner from Avow's approval, and runs the mandate check on the checked terms. Only then does
|
|
201
|
+
* it fund, settling a failed funding as `book` does.
|
|
202
|
+
*
|
|
203
|
+
* So for version 3 terms Avow is asked before the agent's own mandate check runs. Avow's API runs
|
|
204
|
+
* the same check first, so a version 3 quote over the mandate's caps comes back as Avow's refusal,
|
|
205
|
+
* with the layer `avow`. Every other refusal is the SDK's, and no money moves before any of them.
|
|
206
|
+
*/
|
|
207
|
+
commitToQuote(q: SignedQuote): Promise<QuoteResult>;
|
|
208
|
+
/**
|
|
209
|
+
* Reads the lock for a commitment `book` or `commitToQuote` approved but couldn't settle, once
|
|
210
|
+
* Avow's approval can no longer land, so the agent learns whether that same booking was funded.
|
|
211
|
+
* It takes what a `BookingError` carries.
|
|
212
|
+
*/
|
|
213
|
+
reconcile(approved: ApprovedCommitment<CommittedTerms>, hashes?: readonly Hex[]): Promise<Reconciled>;
|
|
214
|
+
/** What the lock holds for one of the business's commitments, or null when it holds nothing. */
|
|
215
|
+
commitment(commitmentId: Hex): Promise<LockedBacking | null>;
|
|
216
|
+
}
|
|
217
|
+
/** What an agent does once its `AvowApi` serves Avow's records of cancellations and job starts. */
|
|
218
|
+
export interface AgentRecordCalls {
|
|
219
|
+
/**
|
|
220
|
+
* Tells Avow the business cancels a commitment, which Avow timestamps. Before free
|
|
221
|
+
* cancellation ends the reserve can go back in full, and after it a late cancellation charge
|
|
222
|
+
* can apply.
|
|
223
|
+
*/
|
|
224
|
+
cancel(commitmentId: Hex): Promise<{
|
|
225
|
+
ok: true;
|
|
226
|
+
cancelledAt: bigint;
|
|
227
|
+
} | {
|
|
228
|
+
ok: false;
|
|
229
|
+
reason: ReasonCode;
|
|
230
|
+
}>;
|
|
231
|
+
/**
|
|
232
|
+
* Starts the job with the supplier. The lock has to hold the commitment with this supplier's
|
|
233
|
+
* signing key. Avow timestamps the request, the supplier returns its signed start receipt,
|
|
234
|
+
* which the agent checks answers the request and comes from that key, and Avow records the
|
|
235
|
+
* start the kept booking rests on.
|
|
236
|
+
*/
|
|
237
|
+
start(commitmentId: Hex, supplier: SupplierConnection): Promise<{
|
|
238
|
+
ok: true;
|
|
239
|
+
receipt: Signed<StartReceipt>;
|
|
240
|
+
} | {
|
|
241
|
+
ok: false;
|
|
242
|
+
reason: ReasonCode;
|
|
243
|
+
}>;
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* An agent that makes commitments under its mandate, as `createAgent` returns it for an `AvowApi`
|
|
247
|
+
* of type `A`. It has `cancel` and `start` only when `A` has `records`, Avow's records of
|
|
248
|
+
* cancellations and job starts, so code that calls one on an `AvowApi` without them doesn't
|
|
249
|
+
* compile. An agent made with `httpAvowApi` has both.
|
|
250
|
+
*/
|
|
251
|
+
export type Agent<A extends AvowApi = AvowApi> = AgentCalls & (A extends {
|
|
252
|
+
records: AvowRecords;
|
|
253
|
+
} ? AgentRecordCalls : unknown);
|
|
254
|
+
/**
|
|
255
|
+
* An agent that makes commitments under its mandate. It agrees terms with a supplier, asks Avow to
|
|
256
|
+
* approve the reserve, checks Avow's approval against the terms and the mandate before any money
|
|
257
|
+
* moves, and funds the reserve from the business's account with its own key while Avow's relay
|
|
258
|
+
* pays the fee. It cancels and starts jobs only through an `AvowApi` that has `records`.
|
|
259
|
+
*/
|
|
260
|
+
export declare function createAgent<A extends AvowApi>(config: AgentConfig<A>): Agent<A>;
|
|
261
|
+
//# sourceMappingURL=agent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../src/agent.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,QAAQ,EACb,KAAK,UAAU,EAOf,KAAK,YAAY,EACjB,KAAK,iBAAiB,EAStB,KAAK,OAAO,EAKZ,KAAK,SAAS,EACd,KAAK,UAAU,EACf,KAAK,YAAY,EACjB,KAAK,MAAM,EACX,KAAK,eAAe,EACpB,KAAK,YAAY,EACjB,KAAK,eAAe,EAEpB,KAAK,KAAK,EACV,KAAK,cAAc,EACnB,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