@agirails/sdk 3.3.0 → 3.5.3
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/dist/api/agirailsApp.d.ts +21 -1
- package/dist/api/agirailsApp.d.ts.map +1 -1
- package/dist/api/agirailsApp.js.map +1 -1
- package/dist/builders/CounterAcceptBuilder.d.ts +96 -0
- package/dist/builders/CounterAcceptBuilder.d.ts.map +1 -0
- package/dist/builders/CounterAcceptBuilder.js +226 -0
- package/dist/builders/CounterAcceptBuilder.js.map +1 -0
- package/dist/builders/CounterOfferBuilder.d.ts +143 -0
- package/dist/builders/CounterOfferBuilder.d.ts.map +1 -0
- package/dist/builders/CounterOfferBuilder.js +329 -0
- package/dist/builders/CounterOfferBuilder.js.map +1 -0
- package/dist/builders/QuoteBuilder.d.ts +9 -3
- package/dist/builders/QuoteBuilder.d.ts.map +1 -1
- package/dist/builders/QuoteBuilder.js +22 -6
- package/dist/builders/QuoteBuilder.js.map +1 -1
- package/dist/builders/index.d.ts +2 -0
- package/dist/builders/index.d.ts.map +1 -1
- package/dist/builders/index.js +7 -1
- package/dist/builders/index.js.map +1 -1
- package/dist/cli/agirails.js +22 -2
- package/dist/cli/agirails.js.map +1 -1
- package/dist/cli/commands/agent.d.ts +22 -0
- package/dist/cli/commands/agent.d.ts.map +1 -0
- package/dist/cli/commands/agent.js +209 -0
- package/dist/cli/commands/agent.js.map +1 -0
- package/dist/cli/commands/health.js +21 -5
- package/dist/cli/commands/health.js.map +1 -1
- package/dist/cli/commands/init.d.ts.map +1 -1
- package/dist/cli/commands/init.js +25 -5
- package/dist/cli/commands/init.js.map +1 -1
- package/dist/cli/commands/publish.d.ts +34 -0
- package/dist/cli/commands/publish.d.ts.map +1 -1
- package/dist/cli/commands/publish.js +256 -80
- package/dist/cli/commands/publish.js.map +1 -1
- package/dist/cli/commands/repair.d.ts +23 -0
- package/dist/cli/commands/repair.d.ts.map +1 -0
- package/dist/cli/commands/repair.js +210 -0
- package/dist/cli/commands/repair.js.map +1 -0
- package/dist/cli/commands/serve.d.ts +38 -0
- package/dist/cli/commands/serve.d.ts.map +1 -0
- package/dist/cli/commands/serve.js +308 -0
- package/dist/cli/commands/serve.js.map +1 -0
- package/dist/cli/commands/test.js +2 -2
- package/dist/cli/commands/test.js.map +1 -1
- package/dist/cli/index.js +10 -0
- package/dist/cli/index.js.map +1 -1
- package/dist/config/agirailsmdV4.d.ts +46 -1
- package/dist/config/agirailsmdV4.d.ts.map +1 -1
- package/dist/config/agirailsmdV4.js +65 -8
- package/dist/config/agirailsmdV4.js.map +1 -1
- package/dist/config/defaults.d.ts +10 -0
- package/dist/config/defaults.d.ts.map +1 -1
- package/dist/config/defaults.js +10 -0
- package/dist/config/defaults.js.map +1 -1
- package/dist/config/networks.d.ts.map +1 -1
- package/dist/config/networks.js +7 -1
- package/dist/config/networks.js.map +1 -1
- package/dist/config/publishPipeline.d.ts +23 -1
- package/dist/config/publishPipeline.d.ts.map +1 -1
- package/dist/config/publishPipeline.js +70 -15
- package/dist/config/publishPipeline.js.map +1 -1
- package/dist/index.d.ts +26 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +39 -3
- package/dist/index.js.map +1 -1
- package/dist/level1/Agent.d.ts +27 -0
- package/dist/level1/Agent.d.ts.map +1 -1
- package/dist/level1/Agent.js +77 -6
- package/dist/level1/Agent.js.map +1 -1
- package/dist/negotiation/BuyerOrchestrator.d.ts +115 -1
- package/dist/negotiation/BuyerOrchestrator.d.ts.map +1 -1
- package/dist/negotiation/BuyerOrchestrator.js +530 -4
- package/dist/negotiation/BuyerOrchestrator.js.map +1 -1
- package/dist/negotiation/DecisionEngine.d.ts +69 -1
- package/dist/negotiation/DecisionEngine.d.ts.map +1 -1
- package/dist/negotiation/DecisionEngine.js +140 -1
- package/dist/negotiation/DecisionEngine.js.map +1 -1
- package/dist/negotiation/MockChannel.d.ts +63 -0
- package/dist/negotiation/MockChannel.d.ts.map +1 -0
- package/dist/negotiation/MockChannel.js +175 -0
- package/dist/negotiation/MockChannel.js.map +1 -0
- package/dist/negotiation/NegotiationChannel.d.ts +142 -0
- package/dist/negotiation/NegotiationChannel.d.ts.map +1 -0
- package/dist/negotiation/NegotiationChannel.js +59 -0
- package/dist/negotiation/NegotiationChannel.js.map +1 -0
- package/dist/negotiation/PolicyEngine.d.ts +32 -0
- package/dist/negotiation/PolicyEngine.d.ts.map +1 -1
- package/dist/negotiation/PolicyEngine.js.map +1 -1
- package/dist/negotiation/ProviderOrchestrator.d.ts +158 -0
- package/dist/negotiation/ProviderOrchestrator.d.ts.map +1 -0
- package/dist/negotiation/ProviderOrchestrator.js +286 -0
- package/dist/negotiation/ProviderOrchestrator.js.map +1 -0
- package/dist/negotiation/ProviderPolicy.d.ts +188 -0
- package/dist/negotiation/ProviderPolicy.d.ts.map +1 -0
- package/dist/negotiation/ProviderPolicy.js +259 -0
- package/dist/negotiation/ProviderPolicy.js.map +1 -0
- package/dist/negotiation/RelayChannel.d.ts +59 -0
- package/dist/negotiation/RelayChannel.d.ts.map +1 -0
- package/dist/negotiation/RelayChannel.js +208 -0
- package/dist/negotiation/RelayChannel.js.map +1 -0
- package/dist/negotiation/index.d.ts +8 -1
- package/dist/negotiation/index.d.ts.map +1 -1
- package/dist/negotiation/index.js +8 -1
- package/dist/negotiation/index.js.map +1 -1
- package/dist/negotiation/verifyQuoteOnChain.d.ts +58 -0
- package/dist/negotiation/verifyQuoteOnChain.d.ts.map +1 -0
- package/dist/negotiation/verifyQuoteOnChain.js +83 -0
- package/dist/negotiation/verifyQuoteOnChain.js.map +1 -0
- package/dist/protocol/ACTPKernel.d.ts.map +1 -1
- package/dist/protocol/ACTPKernel.js +51 -1
- package/dist/protocol/ACTPKernel.js.map +1 -1
- package/dist/runtime/BlockchainRuntime.d.ts +13 -0
- package/dist/runtime/BlockchainRuntime.d.ts.map +1 -1
- package/dist/runtime/BlockchainRuntime.js +33 -2
- package/dist/runtime/BlockchainRuntime.js.map +1 -1
- package/dist/runtime/IACTPRuntime.d.ts +35 -0
- package/dist/runtime/IACTPRuntime.d.ts.map +1 -1
- package/dist/runtime/MockRuntime.d.ts +11 -0
- package/dist/runtime/MockRuntime.d.ts.map +1 -1
- package/dist/runtime/MockRuntime.js +39 -0
- package/dist/runtime/MockRuntime.js.map +1 -1
- package/dist/runtime/types/MockState.d.ts +10 -0
- package/dist/runtime/types/MockState.d.ts.map +1 -1
- package/dist/runtime/types/MockState.js.map +1 -1
- package/dist/transport/QuoteChannel.d.ts +201 -0
- package/dist/transport/QuoteChannel.d.ts.map +1 -0
- package/dist/transport/QuoteChannel.js +358 -0
- package/dist/transport/QuoteChannel.js.map +1 -0
- package/dist/types/adapter.d.ts +24 -24
- package/package.json +16 -1
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* NegotiationChannel — single transport abstraction for AIP-2.1 messages.
|
|
3
|
+
*
|
|
4
|
+
* Replaces the leaky `setReceivedQuote` / `setCounterAccepted` / direct
|
|
5
|
+
* HTTP `QuoteChannelClient.sendCounter` patchwork from 3.4.x. All
|
|
6
|
+
* negotiation message flow — buyer↔provider, both directions, all
|
|
7
|
+
* message types — funnels through ONE interface so:
|
|
8
|
+
*
|
|
9
|
+
* 1. Verification + binding live in ONE place (closes the entire
|
|
10
|
+
* class of injection bugs the 3.4.1 audit caught: every signed
|
|
11
|
+
* message is verified at the channel boundary; orchestrators
|
|
12
|
+
* never see unverified payloads.)
|
|
13
|
+
*
|
|
14
|
+
* 2. Transport is pluggable. v1 ships RelayChannel (default;
|
|
15
|
+
* polls agirails.app — works for buyers without endpoints).
|
|
16
|
+
* Future: HttpChannel (peer-to-peer fast path), IpfsChannel
|
|
17
|
+
* (pubsub), OnChainEventChannel (zero-trust). Orchestrators
|
|
18
|
+
* don't care.
|
|
19
|
+
*
|
|
20
|
+
* 3. Test surface collapses. MockChannel in-memory = no HTTP
|
|
21
|
+
* mocks, no fake servers. One swap, full coverage.
|
|
22
|
+
*
|
|
23
|
+
* @module negotiation/NegotiationChannel
|
|
24
|
+
* @see Protocol/aips/AIP-2.1.md §6 (Negotiation Relay Protocol)
|
|
25
|
+
*/
|
|
26
|
+
import type { QuoteMessage } from '../builders/QuoteBuilder';
|
|
27
|
+
import type { CounterOfferMessage } from '../builders/CounterOfferBuilder';
|
|
28
|
+
import type { CounterAcceptMessage } from '../builders/CounterAcceptBuilder';
|
|
29
|
+
/**
|
|
30
|
+
* Discriminated union of every signed message type that can flow over
|
|
31
|
+
* a NegotiationChannel. The channel's `post` accepts any of these; the
|
|
32
|
+
* channel's verify-on-receive ensures only well-formed signed messages
|
|
33
|
+
* reach the subscriber callback.
|
|
34
|
+
*/
|
|
35
|
+
export type NegotiationMessage = {
|
|
36
|
+
type: 'agirails.quote.v1';
|
|
37
|
+
message: QuoteMessage;
|
|
38
|
+
} | {
|
|
39
|
+
type: 'agirails.counteroffer.v1';
|
|
40
|
+
message: CounterOfferMessage;
|
|
41
|
+
} | {
|
|
42
|
+
type: 'agirails.counteraccept.v1';
|
|
43
|
+
message: CounterAcceptMessage;
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* Unsubscribe handle. `unsubscribe()` MUST be idempotent — callers
|
|
47
|
+
* should call it exactly once but the impl tolerates double-unsubscribe
|
|
48
|
+
* to keep cleanup paths simple.
|
|
49
|
+
*/
|
|
50
|
+
export interface Subscription {
|
|
51
|
+
unsubscribe(): void;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Per-message metadata the channel attaches when delivering.
|
|
55
|
+
*
|
|
56
|
+
* `cursor` lets a subscriber persist resume-point across restarts.
|
|
57
|
+
* `receivedAt` is the channel's perspective of when it learned about
|
|
58
|
+
* the message (NOT the message's signed `quotedAt` / `counteredAt` —
|
|
59
|
+
* those live inside `message`).
|
|
60
|
+
*/
|
|
61
|
+
export interface DeliveredMessage {
|
|
62
|
+
cursor: string;
|
|
63
|
+
receivedAt: number;
|
|
64
|
+
envelope: NegotiationMessage;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Transport-agnostic AIP-2.1 message bus.
|
|
68
|
+
*
|
|
69
|
+
* Implementations are responsible for:
|
|
70
|
+
* - EIP-712 signature verification BEFORE invoking subscriber callback
|
|
71
|
+
* - dedup (the same signed message MUST NOT be delivered twice to the
|
|
72
|
+
* same subscription, even on poll-loop overlap)
|
|
73
|
+
* - liveness (subscribe must keep delivering until unsubscribe)
|
|
74
|
+
* - error isolation (a throw in one subscriber callback MUST NOT kill
|
|
75
|
+
* siblings on the same channel)
|
|
76
|
+
*
|
|
77
|
+
* Implementations are NOT responsible for:
|
|
78
|
+
* - business-logic verification (orchestrator decides accept/reject)
|
|
79
|
+
* - retry of orchestrator failures (channel delivers once, orchestrator
|
|
80
|
+
* is in charge of state)
|
|
81
|
+
*/
|
|
82
|
+
export interface NegotiationChannel {
|
|
83
|
+
/**
|
|
84
|
+
* Send a signed message into the channel for `txId`. The message
|
|
85
|
+
* MUST be already signed; the channel does not modify it.
|
|
86
|
+
*
|
|
87
|
+
* @throws Error on transport failure (network, auth) — caller decides retry policy.
|
|
88
|
+
*/
|
|
89
|
+
post(txId: string, envelope: NegotiationMessage): Promise<void>;
|
|
90
|
+
/**
|
|
91
|
+
* Subscribe to all messages for a specific transaction.
|
|
92
|
+
* Buyer use case: knows the txId from `createTransaction`, wants
|
|
93
|
+
* every quote / counter-accept that arrives for it.
|
|
94
|
+
*
|
|
95
|
+
* Callback is invoked once per unique message (dedup'd by message hash
|
|
96
|
+
* within the subscription's lifetime). Throws inside the callback do
|
|
97
|
+
* NOT cancel the subscription — the channel logs and continues.
|
|
98
|
+
*/
|
|
99
|
+
subscribeTxId(txId: string, onMessage: (delivered: DeliveredMessage) => void | Promise<void>): Subscription;
|
|
100
|
+
/**
|
|
101
|
+
* Subscribe to all messages addressed to an agent DID (by virtue of
|
|
102
|
+
* being listed as `provider` or `consumer` in the message body),
|
|
103
|
+
* across ALL txIds.
|
|
104
|
+
*
|
|
105
|
+
* Provider use case: doesn't know future txIds in advance — wants
|
|
106
|
+
* a firehose of incoming counter-offers for any tx where they're
|
|
107
|
+
* listed as the provider.
|
|
108
|
+
*
|
|
109
|
+
* Implementations may filter server-side or client-side; either
|
|
110
|
+
* way the subscriber sees only messages where `agentDid` matches
|
|
111
|
+
* the relevant role on the inner message.
|
|
112
|
+
*/
|
|
113
|
+
subscribeAgent(agentDid: string, onMessage: (txId: string, delivered: DeliveredMessage) => void | Promise<void>): Subscription;
|
|
114
|
+
/**
|
|
115
|
+
* Best-effort cleanup. Implementations should release polling timers,
|
|
116
|
+
* close keep-alive connections, etc. Optional — process exit handles
|
|
117
|
+
* cleanup for short-lived clients.
|
|
118
|
+
*/
|
|
119
|
+
close?(): Promise<void>;
|
|
120
|
+
}
|
|
121
|
+
export declare function isQuoteEnvelope(e: NegotiationMessage): e is {
|
|
122
|
+
type: 'agirails.quote.v1';
|
|
123
|
+
message: QuoteMessage;
|
|
124
|
+
};
|
|
125
|
+
export declare function isCounterOfferEnvelope(e: NegotiationMessage): e is {
|
|
126
|
+
type: 'agirails.counteroffer.v1';
|
|
127
|
+
message: CounterOfferMessage;
|
|
128
|
+
};
|
|
129
|
+
export declare function isCounterAcceptEnvelope(e: NegotiationMessage): e is {
|
|
130
|
+
type: 'agirails.counteraccept.v1';
|
|
131
|
+
message: CounterAcceptMessage;
|
|
132
|
+
};
|
|
133
|
+
/**
|
|
134
|
+
* Extract the txId carried inside the envelope's signed message.
|
|
135
|
+
* Useful for impls that need to dispatch by txId without parsing.
|
|
136
|
+
*/
|
|
137
|
+
export declare function envelopeTxId(e: NegotiationMessage): string;
|
|
138
|
+
/**
|
|
139
|
+
* Extract the chainId carried inside the envelope's signed message.
|
|
140
|
+
*/
|
|
141
|
+
export declare function envelopeChainId(e: NegotiationMessage): number;
|
|
142
|
+
//# sourceMappingURL=NegotiationChannel.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NegotiationChannel.d.ts","sourceRoot":"","s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AI,GAAG,OAAO,CAAC,IAAI,CAAC,GAC7E,YAAY,CAAC;IAEhB;;;;OAIG;IACH,KAAK,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACzB;AAMD,wBAAgB,eAAe,CAC7B,CAAC,EAAE,kBAAkB,GACpB,CAAC,IAAI;IAAE,IAAI,EAAE,mBAAmB,CAAC;IAAC,OAAO,EAAE,YAAY,CAAA;CAAE,CAE3D;AAED,wBAAgB,sBAAsB,CACpC,CAAC,EAAE,kBAAkB,GACpB,CAAC,IAAI;IAAE,IAAI,EAAE,0BAA0B,CAAC;IAAC,OAAO,EAAE,mBAAmB,CAAA;CAAE,CAEzE;AAED,wBAAgB,uBAAuB,CACrC,CAAC,EAAE,kBAAkB,GACpB,CAAC,IAAI;IAAE,IAAI,EAAE,2BAA2B,CAAC;IAAC,OAAO,EAAE,oBAAoB,CAAA;CAAE,CAE3E;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,kBAAkB,GAAG,MAAM,CAE1D;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,CAAC,EAAE,kBAAkB,GAAG,MAAM,CAE7D"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* NegotiationChannel — single transport abstraction for AIP-2.1 messages.
|
|
4
|
+
*
|
|
5
|
+
* Replaces the leaky `setReceivedQuote` / `setCounterAccepted` / direct
|
|
6
|
+
* HTTP `QuoteChannelClient.sendCounter` patchwork from 3.4.x. All
|
|
7
|
+
* negotiation message flow — buyer↔provider, both directions, all
|
|
8
|
+
* message types — funnels through ONE interface so:
|
|
9
|
+
*
|
|
10
|
+
* 1. Verification + binding live in ONE place (closes the entire
|
|
11
|
+
* class of injection bugs the 3.4.1 audit caught: every signed
|
|
12
|
+
* message is verified at the channel boundary; orchestrators
|
|
13
|
+
* never see unverified payloads.)
|
|
14
|
+
*
|
|
15
|
+
* 2. Transport is pluggable. v1 ships RelayChannel (default;
|
|
16
|
+
* polls agirails.app — works for buyers without endpoints).
|
|
17
|
+
* Future: HttpChannel (peer-to-peer fast path), IpfsChannel
|
|
18
|
+
* (pubsub), OnChainEventChannel (zero-trust). Orchestrators
|
|
19
|
+
* don't care.
|
|
20
|
+
*
|
|
21
|
+
* 3. Test surface collapses. MockChannel in-memory = no HTTP
|
|
22
|
+
* mocks, no fake servers. One swap, full coverage.
|
|
23
|
+
*
|
|
24
|
+
* @module negotiation/NegotiationChannel
|
|
25
|
+
* @see Protocol/aips/AIP-2.1.md §6 (Negotiation Relay Protocol)
|
|
26
|
+
*/
|
|
27
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
28
|
+
exports.envelopeChainId = exports.envelopeTxId = exports.isCounterAcceptEnvelope = exports.isCounterOfferEnvelope = exports.isQuoteEnvelope = void 0;
|
|
29
|
+
// ============================================================================
|
|
30
|
+
// Type guards (for impl + test convenience)
|
|
31
|
+
// ============================================================================
|
|
32
|
+
function isQuoteEnvelope(e) {
|
|
33
|
+
return e.type === 'agirails.quote.v1';
|
|
34
|
+
}
|
|
35
|
+
exports.isQuoteEnvelope = isQuoteEnvelope;
|
|
36
|
+
function isCounterOfferEnvelope(e) {
|
|
37
|
+
return e.type === 'agirails.counteroffer.v1';
|
|
38
|
+
}
|
|
39
|
+
exports.isCounterOfferEnvelope = isCounterOfferEnvelope;
|
|
40
|
+
function isCounterAcceptEnvelope(e) {
|
|
41
|
+
return e.type === 'agirails.counteraccept.v1';
|
|
42
|
+
}
|
|
43
|
+
exports.isCounterAcceptEnvelope = isCounterAcceptEnvelope;
|
|
44
|
+
/**
|
|
45
|
+
* Extract the txId carried inside the envelope's signed message.
|
|
46
|
+
* Useful for impls that need to dispatch by txId without parsing.
|
|
47
|
+
*/
|
|
48
|
+
function envelopeTxId(e) {
|
|
49
|
+
return e.message.txId;
|
|
50
|
+
}
|
|
51
|
+
exports.envelopeTxId = envelopeTxId;
|
|
52
|
+
/**
|
|
53
|
+
* Extract the chainId carried inside the envelope's signed message.
|
|
54
|
+
*/
|
|
55
|
+
function envelopeChainId(e) {
|
|
56
|
+
return e.message.chainId;
|
|
57
|
+
}
|
|
58
|
+
exports.envelopeChainId = envelopeChainId;
|
|
59
|
+
//# sourceMappingURL=NegotiationChannel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NegotiationChannel.js","sourceRoot":"","sources":["../../src/negotiation/NegotiationChannel.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;;;AAiHH,+EAA+E;AAC/E,4CAA4C;AAC5C,+EAA+E;AAE/E,SAAgB,eAAe,CAC7B,CAAqB;IAErB,OAAO,CAAC,CAAC,IAAI,KAAK,mBAAmB,CAAC;AACxC,CAAC;AAJD,0CAIC;AAED,SAAgB,sBAAsB,CACpC,CAAqB;IAErB,OAAO,CAAC,CAAC,IAAI,KAAK,0BAA0B,CAAC;AAC/C,CAAC;AAJD,wDAIC;AAED,SAAgB,uBAAuB,CACrC,CAAqB;IAErB,OAAO,CAAC,CAAC,IAAI,KAAK,2BAA2B,CAAC;AAChD,CAAC;AAJD,0DAIC;AAED;;;GAGG;AACH,SAAgB,YAAY,CAAC,CAAqB;IAChD,OAAO,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC;AACxB,CAAC;AAFD,oCAEC;AAED;;GAEG;AACH,SAAgB,eAAe,CAAC,CAAqB;IACnD,OAAO,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC;AAC3B,CAAC;AAFD,0CAEC"}
|
|
@@ -28,6 +28,27 @@ export interface BuyerPolicy {
|
|
|
28
28
|
negotiation: {
|
|
29
29
|
rounds_max: number;
|
|
30
30
|
quote_ttl: string;
|
|
31
|
+
/**
|
|
32
|
+
* Maximum back-and-forth rounds with ONE provider before walking
|
|
33
|
+
* away. 1 = take the provider's first quote or reject (no counter).
|
|
34
|
+
* 2+ = send counter-offer(s) within this budget. Defaults to 1.
|
|
35
|
+
*/
|
|
36
|
+
rounds_per_provider?: number;
|
|
37
|
+
/**
|
|
38
|
+
* How to compute counter-offer amounts when policy decides to
|
|
39
|
+
* negotiate rather than accept:
|
|
40
|
+
* 'midpoint' — (quote + target) / 2. Balanced.
|
|
41
|
+
* 'undercut' — target (our ideal). Aggressive.
|
|
42
|
+
* 'walk' — no counter; reject. Default for rounds_per_provider=1.
|
|
43
|
+
*/
|
|
44
|
+
counter_strategy?: 'midpoint' | 'undercut' | 'walk';
|
|
45
|
+
/**
|
|
46
|
+
* Seconds to wait for provider's explicit off-chain acceptance
|
|
47
|
+
* of a counter-offer before we give up and cancel. Defaults to
|
|
48
|
+
* the quote_ttl value (provider has as long to respond as their
|
|
49
|
+
* original quote was valid for).
|
|
50
|
+
*/
|
|
51
|
+
counter_response_ttl_seconds?: number;
|
|
31
52
|
};
|
|
32
53
|
selection: {
|
|
33
54
|
min_reputation?: number;
|
|
@@ -39,6 +60,17 @@ export interface BuyerPolicy {
|
|
|
39
60
|
reliability?: number;
|
|
40
61
|
};
|
|
41
62
|
};
|
|
63
|
+
/**
|
|
64
|
+
* Target unit price buyer would prefer to pay (separate from the hard
|
|
65
|
+
* maxUnit ceiling above). Used by DecisionEngine.evaluateQuote to
|
|
66
|
+
* decide accept-vs-counter: if provider quote ≤ target → accept.
|
|
67
|
+
* Defaults to 50% of max_unit_price.
|
|
68
|
+
*/
|
|
69
|
+
target_unit_price?: {
|
|
70
|
+
amount: number;
|
|
71
|
+
currency: string;
|
|
72
|
+
unit: string;
|
|
73
|
+
};
|
|
42
74
|
}
|
|
43
75
|
export interface QuoteOffer {
|
|
44
76
|
provider: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PolicyEngine.d.ts","sourceRoot":"","sources":["../../src/negotiation/PolicyEngine.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AASH,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE;QACX,cAAc,EAAE;YAA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IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,UAAU,GAAG,WAAW,GAAG,UAAU,CAAC;IAC9C,UAAU,EAAE,MAAM,CAAC;CACpB;AAaD,qBAAa,YAAY;IACvB,OAAO,CAAC,MAAM,CAAc;IAC5B,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,MAAM,CAAmB;gBAErB,MAAM,EAAE,WAAW,EAAE,OAAO,CAAC,EAAE,MAAM;IAMjD;;OAEG;IACH,QAAQ,CAAC,KAAK,EAAE,UAAU,GAAG,YAAY;IA0FzC;;;OAGG;IACH,OAAO,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI;IAkClE;;OAEG;IACH,MAAM,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI;IAWjD;;OAEG;IACH,OAAO,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI;IAUhC;;OAEG;IACH,iBAAiB,IAAI,MAAM;IAO3B;;OAEG;IACH,MAAM,CAAC,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM;IAYpC;;OAEG;IACH,gBAAgB,IAAI,MAAM;IAS1B,OAAO,CAAC,aAAa;IAIrB,OAAO,CAAC,WAAW;IAKnB,OAAO,CAAC,mBAAmB;IAQ3B,OAAO,CAAC,UAAU;IAkBlB,OAAO,CAAC,SAAS;IAWjB,OAAO,CAAC,UAAU;CA2BnB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PolicyEngine.js","sourceRoot":"","sources":["../../src/negotiation/PolicyEngine.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;GAaG;;;AAEH,2BAA+F;AAC/F,+BAA4B;
|
|
1
|
+
{"version":3,"file":"PolicyEngine.js","sourceRoot":"","sources":["../../src/negotiation/PolicyEngine.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;GAaG;;;AAEH,2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ElC,yCAAyC;QACzC,IAAI,IAAA,eAAU,EAAC,OAAO,CAAC,EAAE,CAAC;YACxB,MAAM,OAAO,GAAG,IAAA,cAAS,EAAC,OAAO,CAAC,CAAC;YACnC,IAAI,OAAO,CAAC,cAAc,EAAE,EAAE,CAAC;gBAC7B,MAAM,IAAI,KAAK,CAAC,aAAa,OAAO,mCAAmC,CAAC,CAAC;YAC3E,CAAC;QACH,CAAC;QAED,eAAe;QACf,IAAA,kBAAa,EAAC,OAAO,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;QAC9E,IAAA,eAAU,EAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;IAChC,CAAC;CACF;AAvRD,oCAuRC"}
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ProviderOrchestrator — autonomous provider-side negotiation flow.
|
|
3
|
+
*
|
|
4
|
+
* Two responsibilities:
|
|
5
|
+
*
|
|
6
|
+
* 1. Accept an incoming request → decide whether to quote → if yes,
|
|
7
|
+
* build + sign a QuoteMessage, anchor on-chain via submitQuote,
|
|
8
|
+
* post it on the NegotiationChannel for the buyer.
|
|
9
|
+
*
|
|
10
|
+
* 2. (3.5.0) Run a long-lived `start()` listener on the channel:
|
|
11
|
+
* every counter that arrives is evaluated against ProviderPolicy;
|
|
12
|
+
* based on `counter_strategy` we either auto-accept (build + post
|
|
13
|
+
* CounterAcceptMessage), auto-requote (build + post a new
|
|
14
|
+
* QuoteMessage with the conceded amount), or walk (log + drop).
|
|
15
|
+
*
|
|
16
|
+
* Symmetric to BuyerOrchestrator's channel-driven multi-round loop —
|
|
17
|
+
* together they implement the full AIP-2.1 §6 negotiation protocol
|
|
18
|
+
* without either party needing to host an HTTP endpoint.
|
|
19
|
+
*
|
|
20
|
+
* @module negotiation/ProviderOrchestrator
|
|
21
|
+
* @see Protocol/aips/AIP-2.1.md §5.2 (provider quote flow)
|
|
22
|
+
* @see Protocol/aips/AIP-2.1.md §6 (NegotiationChannel)
|
|
23
|
+
*/
|
|
24
|
+
import { Signer } from 'ethers';
|
|
25
|
+
import { IACTPRuntime } from '../runtime/IACTPRuntime';
|
|
26
|
+
import { QuoteMessage } from '../builders/QuoteBuilder';
|
|
27
|
+
import { CounterOfferMessage } from '../builders/CounterOfferBuilder';
|
|
28
|
+
import { NonceManager } from '../utils/NonceManager';
|
|
29
|
+
import { NegotiationChannel, Subscription } from './NegotiationChannel';
|
|
30
|
+
import { ProviderPolicy, IncomingRequest } from './ProviderPolicy';
|
|
31
|
+
export interface ProviderOrchestratorConfig {
|
|
32
|
+
policy: ProviderPolicy;
|
|
33
|
+
runtime: IACTPRuntime;
|
|
34
|
+
/** Provider's EOA signer — signs QuoteMessages + CounterAcceptMessages. */
|
|
35
|
+
signer: Signer;
|
|
36
|
+
/** Kernel address for EIP-712 domain. */
|
|
37
|
+
kernelAddress: string;
|
|
38
|
+
/** Chain id (84532 or 8453). */
|
|
39
|
+
chainId: number;
|
|
40
|
+
/**
|
|
41
|
+
* Provider's DID — used for `subscribeAgent` filter on the channel
|
|
42
|
+
* AND as the `provider` field on outbound QuoteMessage /
|
|
43
|
+
* CounterAcceptMessage. Required for `start()`.
|
|
44
|
+
*/
|
|
45
|
+
providerDID?: string;
|
|
46
|
+
/**
|
|
47
|
+
* Persistent nonce manager. Defaults to in-memory (fine for dev;
|
|
48
|
+
* production should pass a FileBased one so restarts don't replay).
|
|
49
|
+
*/
|
|
50
|
+
nonceManager?: NonceManager;
|
|
51
|
+
/**
|
|
52
|
+
* Negotiation channel. Required for `start()` long-running mode.
|
|
53
|
+
* Optional for the one-shot `quote()` method (caller may handle
|
|
54
|
+
* delivery via direct HTTP / IPFS / etc).
|
|
55
|
+
*/
|
|
56
|
+
negotiationChannel?: NegotiationChannel;
|
|
57
|
+
/**
|
|
58
|
+
* Logger for observability. Default: noop. `actp agent` wires this
|
|
59
|
+
* to its terminal Output.
|
|
60
|
+
*/
|
|
61
|
+
log?: (level: 'info' | 'warn' | 'error', msg: string) => void;
|
|
62
|
+
}
|
|
63
|
+
export type QuoteDecision = {
|
|
64
|
+
action: 'quote';
|
|
65
|
+
/** Quote amount in base units (bigint-as-string) to avoid float drift. */
|
|
66
|
+
amountBaseUnits: string;
|
|
67
|
+
reason: string;
|
|
68
|
+
} | {
|
|
69
|
+
action: 'skip';
|
|
70
|
+
reason: string;
|
|
71
|
+
violations: ReadonlyArray<{
|
|
72
|
+
rule: string;
|
|
73
|
+
detail: string;
|
|
74
|
+
}>;
|
|
75
|
+
};
|
|
76
|
+
export interface QuoteResult {
|
|
77
|
+
decision: QuoteDecision;
|
|
78
|
+
/** Set when action === 'quote' and on-chain anchoring succeeded. */
|
|
79
|
+
quote?: QuoteMessage;
|
|
80
|
+
/** Set when channel post failed (on-chain still succeeded). */
|
|
81
|
+
channelError?: string;
|
|
82
|
+
}
|
|
83
|
+
export type CounterDecision = {
|
|
84
|
+
action: 'accept';
|
|
85
|
+
reason: string;
|
|
86
|
+
} | {
|
|
87
|
+
action: 'reject';
|
|
88
|
+
reason: string;
|
|
89
|
+
} | {
|
|
90
|
+
action: 'requote';
|
|
91
|
+
amountBaseUnits: string;
|
|
92
|
+
reason: string;
|
|
93
|
+
};
|
|
94
|
+
export declare class ProviderOrchestrator {
|
|
95
|
+
private readonly policy;
|
|
96
|
+
private readonly policyEngine;
|
|
97
|
+
private readonly runtime;
|
|
98
|
+
private readonly signer;
|
|
99
|
+
private readonly kernelAddress;
|
|
100
|
+
private readonly chainId;
|
|
101
|
+
private readonly providerDID?;
|
|
102
|
+
private readonly nonceManager;
|
|
103
|
+
private readonly negotiationChannel?;
|
|
104
|
+
private readonly quoteBuilder;
|
|
105
|
+
private readonly counterVerifier;
|
|
106
|
+
private readonly counterAcceptBuilder;
|
|
107
|
+
private readonly log;
|
|
108
|
+
/** Per-tx state for the multi-round counter listener. */
|
|
109
|
+
private readonly txStates;
|
|
110
|
+
/** Active channel subscription opened by `start()`. */
|
|
111
|
+
private channelSubscription?;
|
|
112
|
+
constructor(cfg: ProviderOrchestratorConfig);
|
|
113
|
+
/**
|
|
114
|
+
* Decide whether to quote. Pure policy — no chain, no channel.
|
|
115
|
+
*/
|
|
116
|
+
evaluateRequest(req: IncomingRequest): QuoteDecision;
|
|
117
|
+
/**
|
|
118
|
+
* Full quote flow: evaluate → build signed QuoteMessage → submit
|
|
119
|
+
* on-chain → post on negotiationChannel.
|
|
120
|
+
*
|
|
121
|
+
* Channel post failure is non-fatal: on-chain anchor succeeded so
|
|
122
|
+
* buyer can still observe the quote, just won't see the off-chain
|
|
123
|
+
* signed body. Caller can retry channel post separately.
|
|
124
|
+
*/
|
|
125
|
+
quote(req: IncomingRequest, providerDID: string): Promise<QuoteResult>;
|
|
126
|
+
/**
|
|
127
|
+
* Subscribe to the negotiation channel and auto-respond to incoming
|
|
128
|
+
* counter-offers per `counter_strategy`. Idempotent — calling start()
|
|
129
|
+
* twice replaces the previous subscription.
|
|
130
|
+
*
|
|
131
|
+
* Returns a Subscription so the caller can stop the daemon cleanly.
|
|
132
|
+
*
|
|
133
|
+
* @throws if `negotiationChannel` or `providerDID` was not set in config.
|
|
134
|
+
*/
|
|
135
|
+
start(): Promise<Subscription>;
|
|
136
|
+
/**
|
|
137
|
+
* Stop the active channel subscription if any. Idempotent.
|
|
138
|
+
*/
|
|
139
|
+
stop(): void;
|
|
140
|
+
/**
|
|
141
|
+
* Verify + evaluate a buyer counter-offer. Returns the decision
|
|
142
|
+
* (accept / reject / requote with concession amount). Does NOT send
|
|
143
|
+
* any response — caller drives the next step. Use `start()` for
|
|
144
|
+
* autonomous operation.
|
|
145
|
+
*
|
|
146
|
+
* `lastQuoteAmountBaseUnits` — provider's most recent quote amount
|
|
147
|
+
* for this tx. On the first counter pass `counter.quoteAmount`.
|
|
148
|
+
*
|
|
149
|
+
* `requotesUsed` — defaults to 0; pass the real count for multi-round.
|
|
150
|
+
*
|
|
151
|
+
* @throws if the counter signature / band / expiry fails verify.
|
|
152
|
+
*/
|
|
153
|
+
evaluateCounter(counter: CounterOfferMessage, lastQuoteAmountBaseUnits?: string, requotesUsed?: number): Promise<CounterDecision>;
|
|
154
|
+
/** Read-only policy accessor for UIs and tests. */
|
|
155
|
+
getPolicy(): ProviderPolicy;
|
|
156
|
+
private _handleIncomingCounter;
|
|
157
|
+
}
|
|
158
|
+
//# sourceMappingURL=ProviderOrchestrator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ProviderOrchestrator.d.ts","sourceRoot":"","sources":["../../src/negotiation/ProviderOrchestrator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAgB,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACtE,OAAO,EAEL,mBAAmB,EACpB,MAAM,iCAAiC,CAAC;AAIzC,OAAO,EAAE,YAAY,EAAwB,MAAM,uBAAuB,CAAC;AAC3E,OAAO,EACL,kBAAkB,EAClB,YAAY,EAEb,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACL,cAAc,EAEd,eAAe,EAChB,MAAM,kBAAkB,CAAC;AAM1B,MAAM,WAAW,0BAA0B;IACzC,MAAM,EAAE,cAAc,CAAC;IACvB,OAAO,EAAE,YAAY,CAAC;IACtB,2EAA2E;IAC3E,MAAM,EAAE,MAAM,CAAC;IACf,yCAAyC;IACzC,aAAa,EAAE,MAAM,CAAC;IACtB,gCAAgC;IAChC,OAAO,EAAE,MAAM,CAAC;IAChB;;;;OAIG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;;OAGG;IACH,YAAY,CAAC,EAAE,YAAY,CAAC;IAC5B;;;;OAIG;IACH,kBAAkB,CAAC,EAAE,kBAAkB,CAAC;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