@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,188 @@
|
|
|
1
|
+
import type { BuyerSideReference, ChargeKind, ChargePauseCause, ComputeOffer, ComputeOffers, DeliveryResult, GpuReservationTerms, JobOffer, OrderScenario, OrderState, PinnedBlock, QuoteRequest, RailState, ReasonCode, RefusalAmounts, RefusalLayer, TestCustomerProfile } from '@avow-finance/spec';
|
|
2
|
+
import type { Hex } from 'viem';
|
|
3
|
+
import type { JobAcceptance } from '../job/accept.js';
|
|
4
|
+
import type { ReservedJob } from './service.js';
|
|
5
|
+
import type { ChainSnapshot } from './service-check.js';
|
|
6
|
+
/**
|
|
7
|
+
* Everything the agent session does to the outside world, behind one seam. The live sandbox
|
|
8
|
+
* implements it with the SDK, Avow's API, the test customer and Tempo's testnet. The fixture world
|
|
9
|
+
* implements it in memory with the same rules for tests and the eval, and anything it draws says
|
|
10
|
+
* so. The tool layer, the executor and the session run the same code against either. Nothing here
|
|
11
|
+
* hands out a key, and every result is public data.
|
|
12
|
+
*/
|
|
13
|
+
export interface JobWorld {
|
|
14
|
+
/** `live` on testnet, or `fixture` in memory for tests and the eval. */
|
|
15
|
+
readonly kind: 'live' | 'fixture';
|
|
16
|
+
/** Avow's test customer, as its profile names it. */
|
|
17
|
+
readonly customer: TestCustomerProfile;
|
|
18
|
+
/** The supplier the agent books compute from. */
|
|
19
|
+
readonly computeSupplier: string;
|
|
20
|
+
/** The business as the job's supplier, which the customer's lock has to name. */
|
|
21
|
+
readonly supplier: ReservedJob['supplier'];
|
|
22
|
+
/** The token the business's and the customer's locks hold. */
|
|
23
|
+
readonly token: ReservedJob['token'];
|
|
24
|
+
/**
|
|
25
|
+
* Asks the test customer for a new order. With a scenario, the customer plays it out, as when it
|
|
26
|
+
* cancels the job after its start.
|
|
27
|
+
*/
|
|
28
|
+
pullOrder(scenario?: OrderScenario): Promise<JobOffer>;
|
|
29
|
+
/** The compute supplier's offers for an order's window. */
|
|
30
|
+
offers(order: JobOffer): Promise<ComputeOffers>;
|
|
31
|
+
/**
|
|
32
|
+
* Books `gpus` of an offer through the SDK, which checks the mandate, has Avow approve, funds the
|
|
33
|
+
* reserve and waits for the supplier's acceptance. A refusal names its layer, and no money moved.
|
|
34
|
+
*/
|
|
35
|
+
book(offer: ComputeOffer, gpus: number): Promise<BookOutcome>;
|
|
36
|
+
/** The agent's authority now, from the lock and the account's keychain. */
|
|
37
|
+
authority(): Promise<AuthorityNow>;
|
|
38
|
+
/** Reads a commitment on its lock at the latest finalized block. */
|
|
39
|
+
read(reference: BuyerSideReference): Promise<LockRead | null>;
|
|
40
|
+
/**
|
|
41
|
+
* Quotes an order with terms naming the booking, or none, signed by the supplier signing key. A
|
|
42
|
+
* refusal is the customer's, before it started checking.
|
|
43
|
+
*/
|
|
44
|
+
quote(order: JobOffer, booking: WorldBooking | null): Promise<QuoteOutcome>;
|
|
45
|
+
/** Where an order stands now, as the test customer reports it. */
|
|
46
|
+
orderState(orderId: string): Promise<OrderState>;
|
|
47
|
+
/**
|
|
48
|
+
* Checks the customer's commitment again with Avow's authorization and accepts it on the
|
|
49
|
+
* customer's lock, as `acceptJob` does. A send whose outcome is unknown throws.
|
|
50
|
+
*/
|
|
51
|
+
accept(order: JobOffer, quote: QuoteRequest): Promise<JobAcceptance>;
|
|
52
|
+
/** Which of these transactions landed and succeeded, with its block, or null for none. */
|
|
53
|
+
landed(hashes: readonly Hex[]): Promise<{
|
|
54
|
+
transactionHash: Hex;
|
|
55
|
+
blockNumber: bigint;
|
|
56
|
+
} | null>;
|
|
57
|
+
/** Reports delivery, handing over the result. */
|
|
58
|
+
deliver(orderId: string, result: DeliveryResult): Promise<void>;
|
|
59
|
+
/**
|
|
60
|
+
* Reports a charge of one kind on the customer's reserve for an order, for the most the job's
|
|
61
|
+
* terms allow, signed by the supplier signing key. The verifier builds the report only when the
|
|
62
|
+
* lock would take it. A send whose outcome is unknown throws.
|
|
63
|
+
*/
|
|
64
|
+
reportCharge(order: JobOffer, kind: ChargeKind): Promise<ChargeReport>;
|
|
65
|
+
/** Where a report stands on the customer's lock now. */
|
|
66
|
+
charge(order: JobOffer, report: ReportedCharge): Promise<ChargeStanding>;
|
|
67
|
+
/**
|
|
68
|
+
* Cancels a booking on the lock, which needs the business's root key, or says why it can't here.
|
|
69
|
+
*/
|
|
70
|
+
cancel(booking: WorldBooking): Promise<CancelOutcome>;
|
|
71
|
+
/** Where `checkBeforeWork` reads the chain from, in its own process. */
|
|
72
|
+
chainFor(job: ReservedJob): Promise<ChildChain>;
|
|
73
|
+
/** The clock, in unix seconds. */
|
|
74
|
+
now(): bigint;
|
|
75
|
+
/** Waits, so a fixture world can run its clock instead. */
|
|
76
|
+
sleep(ms: number): Promise<void>;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Where the process that runs `checkBeforeWork` reads the chain. A live run gives it Tempo's RPC
|
|
80
|
+
* to read for itself. The fixture world's chain lives in memory, so it hands over what it holds at
|
|
81
|
+
* one block, which the checks read through the same interfaces.
|
|
82
|
+
*/
|
|
83
|
+
export type ChildChain = {
|
|
84
|
+
kind: 'rpc';
|
|
85
|
+
url: string;
|
|
86
|
+
chainId: number;
|
|
87
|
+
factory: Hex;
|
|
88
|
+
} | {
|
|
89
|
+
kind: 'snapshot';
|
|
90
|
+
snapshot: ChainSnapshot;
|
|
91
|
+
};
|
|
92
|
+
/** A compute booking the session made, with what anyone can check about it. */
|
|
93
|
+
export interface WorldBooking {
|
|
94
|
+
/** The session's own name for it, which the model uses. */
|
|
95
|
+
id: string;
|
|
96
|
+
offer: ComputeOffer;
|
|
97
|
+
gpus: number;
|
|
98
|
+
reference: BuyerSideReference;
|
|
99
|
+
terms: GpuReservationTerms;
|
|
100
|
+
salt: Hex;
|
|
101
|
+
/** The reserve, in micros. */
|
|
102
|
+
reserve: bigint;
|
|
103
|
+
/** The usage price for the whole window, in micros, paid apart from the reserve. */
|
|
104
|
+
price: bigint;
|
|
105
|
+
/** The transaction that funded the reserve, when the chain showed it. */
|
|
106
|
+
reservedIn: Hex | null;
|
|
107
|
+
/** The booking on its lock once the supplier accepted, as read then. */
|
|
108
|
+
read: LockRead;
|
|
109
|
+
}
|
|
110
|
+
/** A commitment as its lock held it at one block. */
|
|
111
|
+
export interface LockRead {
|
|
112
|
+
state: RailState;
|
|
113
|
+
block: PinnedBlock;
|
|
114
|
+
freeCancelBy: bigint;
|
|
115
|
+
releaseDate: bigint;
|
|
116
|
+
}
|
|
117
|
+
export type BookOutcome = {
|
|
118
|
+
ok: true;
|
|
119
|
+
booking: Omit<WorldBooking, 'id'>;
|
|
120
|
+
} | {
|
|
121
|
+
ok: false;
|
|
122
|
+
code: ReasonCode;
|
|
123
|
+
layer: RefusalLayer;
|
|
124
|
+
amounts: RefusalAmounts;
|
|
125
|
+
};
|
|
126
|
+
export type QuoteOutcome = {
|
|
127
|
+
ok: true;
|
|
128
|
+
quote: QuoteRequest;
|
|
129
|
+
} | {
|
|
130
|
+
ok: false;
|
|
131
|
+
code: ReasonCode;
|
|
132
|
+
layer: 'customer' | 'service';
|
|
133
|
+
};
|
|
134
|
+
/** A report the customer's lock took. */
|
|
135
|
+
export interface ReportedCharge {
|
|
136
|
+
/** The charge reported, in micros. */
|
|
137
|
+
amount: bigint;
|
|
138
|
+
/** Which of the commitment's reports it is, 1 or 2. */
|
|
139
|
+
reportNumber: number;
|
|
140
|
+
transactionHash: Hex;
|
|
141
|
+
/** The time of the block the report landed in, which Avow's deadline to answer counts from. */
|
|
142
|
+
reportedAt: bigint;
|
|
143
|
+
}
|
|
144
|
+
export type ChargeReport = ({
|
|
145
|
+
ok: true;
|
|
146
|
+
} & ReportedCharge) | {
|
|
147
|
+
ok: false;
|
|
148
|
+
code: ReasonCode;
|
|
149
|
+
layer: 'service' | 'lock';
|
|
150
|
+
};
|
|
151
|
+
/**
|
|
152
|
+
* Where a reported charge stands. `waiting` is a report Avow hasn't answered. `confirmed` is one
|
|
153
|
+
* Avow confirmed, which the customer can contest until `contestableUntil` and which is payable
|
|
154
|
+
* then. `paused` waits for a ruling. `paid` reached the business, and `ended` is a report withdrawn
|
|
155
|
+
* or a commitment that ended another way.
|
|
156
|
+
*/
|
|
157
|
+
export type ChargeStanding = {
|
|
158
|
+
state: 'waiting';
|
|
159
|
+
} | {
|
|
160
|
+
state: 'confirmed';
|
|
161
|
+
contestableUntil: bigint;
|
|
162
|
+
} | {
|
|
163
|
+
state: 'paused';
|
|
164
|
+
cause: ChargePauseCause;
|
|
165
|
+
} | {
|
|
166
|
+
state: 'paid';
|
|
167
|
+
} | {
|
|
168
|
+
state: 'ended';
|
|
169
|
+
};
|
|
170
|
+
export type CancelOutcome = {
|
|
171
|
+
ok: true;
|
|
172
|
+
transactionHash: Hex;
|
|
173
|
+
} | {
|
|
174
|
+
ok: false;
|
|
175
|
+
code: ReasonCode;
|
|
176
|
+
layer: RefusalLayer;
|
|
177
|
+
why: string;
|
|
178
|
+
};
|
|
179
|
+
/** The agent's limits now, in micros. */
|
|
180
|
+
export interface AuthorityNow {
|
|
181
|
+
capPerCommitment: bigint;
|
|
182
|
+
capOpenReserves: bigint;
|
|
183
|
+
openReservesLeft: bigint;
|
|
184
|
+
dailyLimit: bigint | null;
|
|
185
|
+
dailyLeft: bigint | null;
|
|
186
|
+
suppliers: readonly string[];
|
|
187
|
+
}
|
|
188
|
+
//# sourceMappingURL=world.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"world.d.ts","sourceRoot":"","sources":["../../src/session/world.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,kBAAkB,EAClB,UAAU,EACV,gBAAgB,EAChB,YAAY,EACZ,aAAa,EACb,cAAc,EACd,mBAAmB,EACnB,QAAQ,EACR,aAAa,EACb,UAAU,EACV,WAAW,EACX,YAAY,EACZ,SAAS,EACT,UAAU,EACV,cAAc,EACd,YAAY,EACZ,mBAAmB,EACpB,MAAM,oBAAoB,CAAA;AAC3B,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,MAAM,CAAA;AAC/B,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAA;AACrD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AAC/C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAEvD;;;;;;GAMG;AACH,MAAM,WAAW,QAAQ;IACvB,wEAAwE;IACxE,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,CAAA;IACjC,qDAAqD;IACrD,QAAQ,CAAC,QAAQ,EAAE,mBAAmB,CAAA;IACtC,iDAAiD;IACjD,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAA;IAChC,iFAAiF;IACjF,QAAQ,CAAC,QAAQ,EAAE,WAAW,CAAC,UAAU,CAAC,CAAA;IAC1C,8D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;CAAE,GACjB;IAAE,KAAK,EAAE,OAAO,CAAA;CAAE,CAAA;AAEtB,MAAM,MAAM,aAAa,GACrB;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,eAAe,EAAE,GAAG,CAAA;CAAE,GAClC;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,IAAI,EAAE,UAAU,CAAC;IAAC,KAAK,EAAE,YAAY,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,CAAA;AAErE,yCAAyC;AACzC,MAAM,WAAW,YAAY;IAC3B,gBAAgB,EAAE,MAAM,CAAA;IACxB,eAAe,EAAE,MAAM,CAAA;IACvB,gBAAgB,EAAE,MAAM,CAAA;IACxB,UAAU,EAAE,MAAM,GAAG,IAAI,CAAA;IACzB,SAAS,EAAE,MAAM,GAAG,IAAI,CAAA;IACxB,SAAS,EAAE,SAAS,MAAM,EAAE,CAAA;CAC7B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"world.js","sourceRoot":"","sources":["../../src/session/world.ts"],"names":[],"mappings":""}
|
package/dist/sign.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type AvowDomain, type HashSigner, type HumanApproval, type Mandate, type Signed } from '@avow-finance/spec';
|
|
2
|
+
import { type Address, type Hex, type TypedData, type TypedDataDefinition } from 'viem';
|
|
3
|
+
/**
|
|
4
|
+
* Signs for a business account with its root key or an admin key. Every signature comes out in
|
|
5
|
+
* Tempo's keychain V2 envelope, which the lock's `verifyKeychainAdmin` check and Avow's API need.
|
|
6
|
+
* A browser passkey from viem's `Account.fromWebAuthnP256` signs bare, so pass it here as `key`
|
|
7
|
+
* and the envelope is added for it.
|
|
8
|
+
*/
|
|
9
|
+
export interface AccountSigner {
|
|
10
|
+
readonly account: Address;
|
|
11
|
+
signDigest(digest: Hex): Promise<Hex>;
|
|
12
|
+
signTypedData<const T extends TypedData | Record<string, unknown>, P extends keyof T | 'EIP712Domain'>(typedData: TypedDataDefinition<T, P>): Promise<Hex>;
|
|
13
|
+
}
|
|
14
|
+
export declare function accountSigner(account: Address, key: HashSigner): AccountSigner;
|
|
15
|
+
/** The administrator signs a mandate for one agent, as the business account. */
|
|
16
|
+
export declare function signMandate(mandate: Mandate, d: AvowDomain, signer: AccountSigner): Promise<Signed<Mandate>>;
|
|
17
|
+
/** The administrator approves one reserve in person, as the business account. */
|
|
18
|
+
export declare function signHumanApproval(approval: HumanApproval, d: AvowDomain, signer: AccountSigner): Promise<Signed<HumanApproval>>;
|
|
19
|
+
//# sourceMappingURL=sign.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sign.d.ts","sourceRoot":"","sources":["../src/sign.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,UAAU,EACf,KAAK,UAAU,EACf,KAAK,aAAa,EAElB,KAAK,OAAO,EAGZ,KAAK,MAAM,EAEZ,MAAM,oBAAoB,CAAA;AAC3B,OAAO,EACL,KAAK,OAAO,EACZ,KAAK,GAAG,EAGR,KAAK,SAAS,EACd,KAAK,mBAAmB,EACzB,MAAM,MAAM,CAAA;AAEb;;;;;GAKG;AACH,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAA;IACzB,UAAU,CAAC,MAAM,EAAE,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,CAAA;IACrC,aAAa,CACX,KAAK,CAAC,CAAC,SAAS,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACnD,CAAC,SAAS,MAAM,CAAC,GAAG,cAAc,EAClC,SAAS,EAAE,mBAAmB,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,OAAO,CAAC,GAAG,CAAC,CAAA;CACtD;AAED,wBAAgB,aAAa,CAAC,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,UAAU,GAAG,aAAa,CAM9E;AAkBD,gFAAgF;AAChF,wBAAsB,WAAW,CAC/B,OAAO,EAAE,OAAO,EAChB,CAAC,EAAE,UAAU,EACb,MAAM,EAAE,aAAa,GACpB,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAM1B;AAED,iFAAiF;AACjF,wBAAsB,iBAAiB,CACrC,QAAQ,EAAE,aAAa,EACvB,CAAC,EAAE,UAAU,EACb,MAAM,EAAE,aAAa,GACpB,OAAO,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC,CAGhC"}
|
package/dist/sign.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { humanApprovalTypedData, MESSAGE_VERSIONS, mandateTypedData, signForAccount, } from '@avow-finance/spec';
|
|
2
|
+
import { hashTypedData, isAddressEqual, } from 'viem';
|
|
3
|
+
export function accountSigner(account, key) {
|
|
4
|
+
return {
|
|
5
|
+
account,
|
|
6
|
+
signDigest: (digest) => signForAccount(account, digest, key),
|
|
7
|
+
signTypedData: (typedData) => signForAccount(account, hashTypedData(typedData), key),
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
function envelope(type, d, message, signature) {
|
|
11
|
+
return {
|
|
12
|
+
type,
|
|
13
|
+
schemaVersion: MESSAGE_VERSIONS[type],
|
|
14
|
+
chainId: d.chainId,
|
|
15
|
+
lock: d.verifyingContract,
|
|
16
|
+
message,
|
|
17
|
+
signature,
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
/** The administrator signs a mandate for one agent, as the business account. */
|
|
21
|
+
export async function signMandate(mandate, d, signer) {
|
|
22
|
+
if (!isAddressEqual(mandate.account, signer.account)) {
|
|
23
|
+
throw new Error("The mandate names another account than the signer's");
|
|
24
|
+
}
|
|
25
|
+
const signature = await signer.signTypedData(mandateTypedData(mandate, d));
|
|
26
|
+
return envelope('Mandate', d, mandate, signature);
|
|
27
|
+
}
|
|
28
|
+
/** The administrator approves one reserve in person, as the business account. */
|
|
29
|
+
export async function signHumanApproval(approval, d, signer) {
|
|
30
|
+
const signature = await signer.signTypedData(humanApprovalTypedData(approval, d));
|
|
31
|
+
return envelope('HumanApproval', d, approval, signature);
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=sign.js.map
|
package/dist/sign.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sign.js","sourceRoot":"","sources":["../src/sign.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,sBAAsB,EAEtB,gBAAgB,EAChB,gBAAgB,EAEhB,cAAc,GACf,MAAM,oBAAoB,CAAA;AAC3B,OAAO,EAGL,aAAa,EACb,cAAc,GAGf,MAAM,MAAM,CAAA;AAiBb,MAAM,UAAU,aAAa,CAAC,OAAgB,EAAE,GAAe;IAC7D,OAAO;QACL,OAAO;QACP,UAAU,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,cAAc,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,CAAC;QAC5D,aAAa,EAAE,CAAC,SAAS,EAAE,EAAE,CAAC,cAAc,CAAC,OAAO,EAAE,aAAa,CAAC,SAAS,CAAC,EAAE,GAAG,CAAC;KACrF,CAAA;AACH,CAAC;AAED,SAAS,QAAQ,CACf,IAAuB,EACvB,CAAa,EACb,OAAU,EACV,SAAc;IAEd,OAAO;QACL,IAAI;QACJ,aAAa,EAAE,gBAAgB,CAAC,IAAI,CAAC;QACrC,OAAO,EAAE,CAAC,CAAC,OAAO;QAClB,IAAI,EAAE,CAAC,CAAC,iBAAiB;QACzB,OAAO;QACP,SAAS;KACV,CAAA;AACH,CAAC;AAED,gFAAgF;AAChF,MAAM,CAAC,KAAK,UAAU,WAAW,CAC/B,OAAgB,EAChB,CAAa,EACb,MAAqB;IAErB,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,OAAO,EAAE,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC;QACrD,MAAM,IAAI,KAAK,CAAC,qDAAqD,CAAC,CAAA;IACxE,CAAC;IACD,MAAM,SAAS,GAAG,MAAM,MAAM,CAAC,aAAa,CAAC,gBAAgB,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,CAAA;IAC1E,OAAO,QAAQ,CAAC,SAAS,EAAE,CAAC,EAAE,OAAO,EAAE,SAAS,CAAC,CAAA;AACnD,CAAC;AAED,iFAAiF;AACjF,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,QAAuB,EACvB,CAAa,EACb,MAAqB;IAErB,MAAM,SAAS,GAAG,MAAM,MAAM,CAAC,aAAa,CAAC,sBAAsB,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,CAAA;IACjF,OAAO,QAAQ,CAAC,eAAe,EAAE,CAAC,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAA;AAC1D,CAAC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { type AgreementOffer, type Signed, type StartReceipt, type SupplierProfile } from '@avow-finance/spec';
|
|
2
|
+
import type { Hex } from 'viem';
|
|
3
|
+
/**
|
|
4
|
+
* The agent's channel to one supplier. The supplier's own integration implements it, and a
|
|
5
|
+
* scripted supplier implements it for a demo or a test. Over HTTP, a supplier's adapter serves
|
|
6
|
+
* the profile and the agreement at the routes `SUPPLIER_ADAPTER_PATHS` names, with the bodies the
|
|
7
|
+
* spec's `parseSupplierProfile`, `parseAgreementOffer` and `parseAgreementSignature` read.
|
|
8
|
+
*/
|
|
9
|
+
export interface SupplierConnection {
|
|
10
|
+
/** The supplier's business id, account, signing key and payout address. */
|
|
11
|
+
readonly profile: SupplierProfile;
|
|
12
|
+
/**
|
|
13
|
+
* Asks the supplier to sign the terms agreement. The supplier checks that the terms and salt
|
|
14
|
+
* give the agreement's terms hash and that the terms are ones it offers, then signs the
|
|
15
|
+
* agreement with its signing key and returns the signature.
|
|
16
|
+
*/
|
|
17
|
+
signAgreement(offer: AgreementOffer): Promise<Hex>;
|
|
18
|
+
/** Asks the supplier to start the job, which returns its signed start receipt. */
|
|
19
|
+
startJob(request: {
|
|
20
|
+
commitmentId: Hex;
|
|
21
|
+
startRequestHash: Hex;
|
|
22
|
+
requestedAt: bigint;
|
|
23
|
+
}): Promise<Signed<StartReceipt>>;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* A supplier declining to sign an agreement, with the status it answered, such as over its most
|
|
27
|
+
* for one booking or past its limit of open bookings. Nothing was reserved.
|
|
28
|
+
*/
|
|
29
|
+
export declare class SupplierDeclined extends Error {
|
|
30
|
+
readonly status: number;
|
|
31
|
+
constructor(message: string, status: number);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* The agent's channel to a supplier's adapter, over the routes and bodies the spec fixes for
|
|
35
|
+
* every adapter. The profile comes from the supplier, and the agent checks every signature it gets
|
|
36
|
+
* back against the signing key in that profile before it relies on it. The SDK refuses a booking
|
|
37
|
+
* whose agreement another key signed, and Avow's API checks the profile against what it recorded
|
|
38
|
+
* for the supplier.
|
|
39
|
+
*/
|
|
40
|
+
export declare function httpSupplier(url: string, send?: typeof fetch): Promise<SupplierConnection>;
|
|
41
|
+
//# sourceMappingURL=supplier.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"supplier.d.ts","sourceRoot":"","sources":["../src/supplier.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,cAAc,EAInB,KAAK,MAAM,EACX,KAAK,YAAY,EAEjB,KAAK,eAAe,EAErB,MAAM,oBAAoB,CAAA;AAC3B,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,MAAM,CAAA;AAE/B;;;;;GAKG;AACH,MAAM,WAAW,kBAAkB;IACjC,2EAA2E;IAC3E,QAAQ,CAAC,OAAO,EAAE,eAAe,CAAA;IACjC;;;;OAIG;IACH,aAAa,CAAC,KAAK,EAAE,cAAc,GAAG,OAAO,CAAC,GAAG,CAAC,CAAA;IAClD,kFAAkF;IAClF,QAAQ,CAAC,OAAO,EAAE;QAChB,YAAY,EAAE,GAAG,CAAA;QACjB,gBAAgB,EAAE,GAAG,CAAA;QACrB,WAAW,EAAE,MAAM,CAAA;KACpB,GAAG,OAAO,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,CAAA;CAClC;AAED;;;GAGG;AACH,qBAAa,gBAAiB,SAAQ,KAAK;IAGvC,QAAQ,CAAC,MAAM,EAAE,MAAM;IAFzB,YACE,OAAO,EAAE,MAAM,EACN,MAAM,EAAE,MAAM,EAIxB;CACF;AAED;;;;;;GAMG;AACH,wBAAsB,YAAY,CAChC,GAAG,EAAE,MAAM,EACX,IAAI,GAAE,OAAO,KAAa,GACzB,OAAO,CAAC,kBAAkB,CAAC,CAiC7B"}
|
package/dist/supplier.js
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { parseAgreementSignature, parseSupplierProfile, parseSupplierRefusal, SUPPLIER_ADAPTER_PATHS, toWire, } from '@avow-finance/spec';
|
|
2
|
+
/**
|
|
3
|
+
* A supplier declining to sign an agreement, with the status it answered, such as over its most
|
|
4
|
+
* for one booking or past its limit of open bookings. Nothing was reserved.
|
|
5
|
+
*/
|
|
6
|
+
export class SupplierDeclined extends Error {
|
|
7
|
+
status;
|
|
8
|
+
constructor(message, status) {
|
|
9
|
+
super(message);
|
|
10
|
+
this.status = status;
|
|
11
|
+
this.name = 'SupplierDeclined';
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* The agent's channel to a supplier's adapter, over the routes and bodies the spec fixes for
|
|
16
|
+
* every adapter. The profile comes from the supplier, and the agent checks every signature it gets
|
|
17
|
+
* back against the signing key in that profile before it relies on it. The SDK refuses a booking
|
|
18
|
+
* whose agreement another key signed, and Avow's API checks the profile against what it recorded
|
|
19
|
+
* for the supplier.
|
|
20
|
+
*/
|
|
21
|
+
export async function httpSupplier(url, send = fetch) {
|
|
22
|
+
const base = url.replace(/\/+$/, '');
|
|
23
|
+
const answer = await send(`${base}${SUPPLIER_ADAPTER_PATHS.profile}`, {
|
|
24
|
+
signal: AbortSignal.timeout(15_000),
|
|
25
|
+
});
|
|
26
|
+
const profile = parseSupplierProfile(await answer.json().catch(() => null));
|
|
27
|
+
if (!answer.ok || !profile.ok)
|
|
28
|
+
throw new Error(`${base} gave no supplier profile`);
|
|
29
|
+
return {
|
|
30
|
+
profile: profile.value,
|
|
31
|
+
async signAgreement(offer) {
|
|
32
|
+
const signed = await send(`${base}${SUPPLIER_ADAPTER_PATHS.agreements}`, {
|
|
33
|
+
method: 'POST',
|
|
34
|
+
headers: { 'content-type': 'application/json' },
|
|
35
|
+
body: JSON.stringify(toWire(offer)),
|
|
36
|
+
signal: AbortSignal.timeout(30_000),
|
|
37
|
+
});
|
|
38
|
+
const body = await signed.json().catch(() => null);
|
|
39
|
+
if (!signed.ok) {
|
|
40
|
+
const why = parseSupplierRefusal(body)?.error ?? String(signed.status);
|
|
41
|
+
// A 4xx is the supplier's answer, and anything else is a supplier that couldn't answer.
|
|
42
|
+
if (signed.status < 500) {
|
|
43
|
+
throw new SupplierDeclined(`The supplier refused the agreement: ${why}`, signed.status);
|
|
44
|
+
}
|
|
45
|
+
throw new Error(`The supplier couldn't answer the agreement: ${why}`);
|
|
46
|
+
}
|
|
47
|
+
const parsed = parseAgreementSignature(body);
|
|
48
|
+
if (!parsed.ok)
|
|
49
|
+
throw new Error(`The supplier answered with no signature (${parsed.reason})`);
|
|
50
|
+
return parsed.value.signature;
|
|
51
|
+
},
|
|
52
|
+
async startJob() {
|
|
53
|
+
throw new Error("The supplier adapter's routes don't start a job yet");
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=supplier.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"supplier.js","sourceRoot":"","sources":["../src/supplier.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,uBAAuB,EACvB,oBAAoB,EACpB,oBAAoB,EAGpB,sBAAsB,EAEtB,MAAM,GACP,MAAM,oBAAoB,CAAA;AA0B3B;;;GAGG;AACH,MAAM,OAAO,gBAAiB,SAAQ,KAAK;IAG9B,MAAM;IAFjB,YACE,OAAe,EACN,MAAc;QAEvB,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EAAE,EAAE,CAAC;gBACf,MAAM,GAAG,GAAG,oBAAoB,CAAC,IAAI,CAAC,EAAE,KAAK,IAAI,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAA;gBACtE,wFAAwF;gBACxF,IAAI,MAAM,CAAC,MAAM,GAAG,GAAG,EAAE,CAAC;oBACxB,MAAM,IAAI,gBAAgB,CAAC,uCAAuC,GAAG,EAAE,EAAE,MAAM,CAAC,MAAM,CAAC,CAAA;gBACzF,CAAC;gBACD,MAAM,IAAI,KAAK,CAAC,+CAA+C,GAAG,EAAE,CAAC,CAAA;YACvE,CAAC;YACD,MAAM,MAAM,GAAG,uBAAuB,CAAC,IAAI,CAAC,CAAA;YAC5C,IAAI,CAAC,MAAM,CAAC,EAAE;gBAAE,MAAM,IAAI,KAAK,CAAC,4CAA4C,MAAM,CAAC,MAAM,GAAG,CAAC,CAAA;YAC7F,OAAO,MAAM,CAAC,KAAK,CAAC,SAAS,CAAA;QAC/B,CAAC;QACD,KAAK,CAAC,QAAQ;YACZ,MAAM,IAAI,KAAK,CAAC,qDAAqD,CAAC,CAAA;QACxE,CAAC;KACF,CAAA;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,59 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@avow-finance/sdk",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "TypeScript SDK for agents making commitments backed by Avow reserves",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"engines": {
|
|
8
|
+
"node": ">=22.12"
|
|
9
|
+
},
|
|
10
|
+
"publishConfig": {
|
|
11
|
+
"access": "public",
|
|
12
|
+
"provenance": true
|
|
13
|
+
},
|
|
14
|
+
"exports": {
|
|
15
|
+
".": {
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"node": "./dist/node.js",
|
|
18
|
+
"default": "./dist/index.js"
|
|
19
|
+
},
|
|
20
|
+
"./agent": {
|
|
21
|
+
"types": "./dist/agent-entry.d.ts",
|
|
22
|
+
"node": "./dist/node-agent.js",
|
|
23
|
+
"default": "./dist/agent-entry.js"
|
|
24
|
+
},
|
|
25
|
+
"./service": {
|
|
26
|
+
"types": "./dist/service-entry.d.ts",
|
|
27
|
+
"default": "./dist/service-entry.js"
|
|
28
|
+
},
|
|
29
|
+
"./cli": "./dist/node/cli.js"
|
|
30
|
+
},
|
|
31
|
+
"bin": {
|
|
32
|
+
"avow-sandbox": "./dist/node/cli.js",
|
|
33
|
+
"avow-sandbox-mcp": "./dist/node/mcp.js"
|
|
34
|
+
},
|
|
35
|
+
"files": [
|
|
36
|
+
"dist"
|
|
37
|
+
],
|
|
38
|
+
"repository": {
|
|
39
|
+
"type": "git",
|
|
40
|
+
"url": "git+https://github.com/Avow-Finance/avow.git",
|
|
41
|
+
"directory": "packages/sdk"
|
|
42
|
+
},
|
|
43
|
+
"dependencies": {
|
|
44
|
+
"ox": "0.14.57",
|
|
45
|
+
"uqr": "0.1.3",
|
|
46
|
+
"viem": "2.57.11",
|
|
47
|
+
"@avow-finance/spec": "0.2.0",
|
|
48
|
+
"@avow-finance/terminal": "0.2.0",
|
|
49
|
+
"@avow-finance/verifier": "0.2.0"
|
|
50
|
+
},
|
|
51
|
+
"devDependencies": {
|
|
52
|
+
"@modelcontextprotocol/sdk": "1.32.1"
|
|
53
|
+
},
|
|
54
|
+
"scripts": {
|
|
55
|
+
"build": "tsc -p tsconfig.build.json",
|
|
56
|
+
"test": "vitest run",
|
|
57
|
+
"typecheck": "tsc -p tsconfig.json --noEmit"
|
|
58
|
+
}
|
|
6
59
|
}
|