@ophirai/sdk 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. package/README.md +139 -0
  2. package/dist/__tests__/buyer.test.d.ts +1 -0
  3. package/dist/__tests__/buyer.test.js +664 -0
  4. package/dist/__tests__/discovery.test.d.ts +1 -0
  5. package/dist/__tests__/discovery.test.js +188 -0
  6. package/dist/__tests__/escrow.test.d.ts +1 -0
  7. package/dist/__tests__/escrow.test.js +385 -0
  8. package/dist/__tests__/identity.test.d.ts +1 -0
  9. package/dist/__tests__/identity.test.js +222 -0
  10. package/dist/__tests__/integration.test.d.ts +1 -0
  11. package/dist/__tests__/integration.test.js +681 -0
  12. package/dist/__tests__/lockstep.test.d.ts +1 -0
  13. package/dist/__tests__/lockstep.test.js +320 -0
  14. package/dist/__tests__/messages.test.d.ts +1 -0
  15. package/dist/__tests__/messages.test.js +976 -0
  16. package/dist/__tests__/negotiation.test.d.ts +1 -0
  17. package/dist/__tests__/negotiation.test.js +667 -0
  18. package/dist/__tests__/seller.test.d.ts +1 -0
  19. package/dist/__tests__/seller.test.js +767 -0
  20. package/dist/__tests__/server.test.d.ts +1 -0
  21. package/dist/__tests__/server.test.js +239 -0
  22. package/dist/__tests__/signing.test.d.ts +1 -0
  23. package/dist/__tests__/signing.test.js +713 -0
  24. package/dist/__tests__/sla.test.d.ts +1 -0
  25. package/dist/__tests__/sla.test.js +342 -0
  26. package/dist/__tests__/transport.test.d.ts +1 -0
  27. package/dist/__tests__/transport.test.js +197 -0
  28. package/dist/__tests__/x402.test.d.ts +1 -0
  29. package/dist/__tests__/x402.test.js +141 -0
  30. package/dist/buyer.d.ts +190 -0
  31. package/dist/buyer.js +555 -0
  32. package/dist/discovery.d.ts +47 -0
  33. package/dist/discovery.js +51 -0
  34. package/dist/escrow.d.ts +177 -0
  35. package/dist/escrow.js +434 -0
  36. package/dist/identity.d.ts +60 -0
  37. package/dist/identity.js +108 -0
  38. package/dist/index.d.ts +122 -0
  39. package/dist/index.js +43 -0
  40. package/dist/lockstep.d.ts +94 -0
  41. package/dist/lockstep.js +127 -0
  42. package/dist/messages.d.ts +172 -0
  43. package/dist/messages.js +262 -0
  44. package/dist/negotiation.d.ts +113 -0
  45. package/dist/negotiation.js +214 -0
  46. package/dist/seller.d.ts +127 -0
  47. package/dist/seller.js +395 -0
  48. package/dist/server.d.ts +52 -0
  49. package/dist/server.js +149 -0
  50. package/dist/signing.d.ts +98 -0
  51. package/dist/signing.js +165 -0
  52. package/dist/sla.d.ts +95 -0
  53. package/dist/sla.js +187 -0
  54. package/dist/transport.d.ts +41 -0
  55. package/dist/transport.js +127 -0
  56. package/dist/types.d.ts +86 -0
  57. package/dist/types.js +1 -0
  58. package/dist/x402.d.ts +25 -0
  59. package/dist/x402.js +54 -0
  60. package/package.json +40 -0
package/README.md ADDED
@@ -0,0 +1,139 @@
1
+ # @ophir/sdk
2
+
3
+ TypeScript SDK for the Ophir Agent Negotiation Protocol. Provides `BuyerAgent` and `SellerAgent` classes with built-in cryptographic signing, identity management, escrow integration, SLA tooling, and JSON-RPC transport.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @ophir/sdk @ophir/protocol
9
+ ```
10
+
11
+ ## Quick start
12
+
13
+ ### Buyer
14
+
15
+ ```typescript
16
+ import { BuyerAgent } from '@ophir/sdk';
17
+
18
+ const buyer = new BuyerAgent({ endpoint: 'http://localhost:3002' });
19
+ await buyer.listen();
20
+
21
+ // 1. Request quotes
22
+ const session = await buyer.requestQuotes({
23
+ sellers: ['http://localhost:3001'],
24
+ service: { category: 'inference', requirements: { model: 'vision' } },
25
+ budget: { max_price_per_unit: '0.01', currency: 'USDC', unit: 'request' },
26
+ sla: { metrics: [{ name: 'p99_latency_ms', target: 500, comparison: 'lte' }] },
27
+ });
28
+
29
+ // 2. Collect and rank quotes
30
+ const quotes = await buyer.waitForQuotes(session, { minQuotes: 1, timeout: 30_000 });
31
+ const ranked = buyer.rankQuotes(quotes, 'cheapest');
32
+
33
+ // 3. Accept the best quote
34
+ const agreement = await buyer.acceptQuote(ranked[0]);
35
+ console.log(agreement.agreement_hash);
36
+ ```
37
+
38
+ ### Seller
39
+
40
+ ```typescript
41
+ import { SellerAgent } from '@ophir/sdk';
42
+
43
+ const seller = new SellerAgent({
44
+ endpoint: 'http://localhost:3001',
45
+ services: [{
46
+ category: 'inference',
47
+ description: 'GPU inference for vision models',
48
+ base_price: '0.005',
49
+ currency: 'USDC',
50
+ unit: 'request',
51
+ }],
52
+ });
53
+
54
+ await seller.listen();
55
+ // Seller is now accepting RFQs and auto-generating signed quotes
56
+ ```
57
+
58
+ ### Custom handlers
59
+
60
+ ```typescript
61
+ // Custom RFQ handler
62
+ seller.onRFQ(async (rfq) => {
63
+ if (rfq.service.category !== 'inference') return null;
64
+ return { /* QuoteParams */ };
65
+ });
66
+
67
+ // Custom counter-offer handler
68
+ seller.onCounter(async (counter, session) => {
69
+ const price = parseFloat(counter.modifications.price_per_unit);
70
+ if (price >= 0.004) return 'accept';
71
+ if (price < 0.002) return 'reject';
72
+ return { /* new QuoteParams */ };
73
+ });
74
+ ```
75
+
76
+ ## API reference
77
+
78
+ ### Agents
79
+
80
+ | Export | Description |
81
+ |---|---|
82
+ | `BuyerAgent` | Buy-side agent: send RFQs, collect quotes, rank, accept, counter, dispute |
83
+ | `SellerAgent` | Sell-side agent: receive RFQs, generate quotes, handle counters |
84
+
85
+ See the full API reference for [BuyerAgent](../docs/sdk/buyer.md) and [SellerAgent](../docs/sdk/seller.md).
86
+
87
+ ### Cryptography and identity
88
+
89
+ | Export | Description |
90
+ |---|---|
91
+ | `generateKeyPair()` | Generate an Ed25519 keypair |
92
+ | `generateAgentIdentity()` | Generate a keypair and derive the `did:key` identifier |
93
+ | `publicKeyToDid(publicKey)` | Convert an Ed25519 public key to a `did:key` URI |
94
+ | `didToPublicKey(did)` | Convert a `did:key` URI back to an Ed25519 public key |
95
+ | `signMessage(params, secretKey)` | JCS-canonicalize params, then Ed25519 sign; returns base64 |
96
+ | `verifyMessage(params, signature, publicKey)` | Verify a base64 Ed25519 signature against canonicalized params |
97
+ | `canonicalize(obj)` | JCS (RFC 8785) canonicalization via `json-stable-stringify` |
98
+ | `agreementHash(finalTerms)` | `SHA-256(JCS(finalTerms))` returned as a hex string |
99
+
100
+ ### Escrow
101
+
102
+ | Export | Description |
103
+ |---|---|
104
+ | `EscrowManager` | Derive Solana escrow PDAs and interact with the escrow program |
105
+
106
+ ### SLA utilities
107
+
108
+ | Export | Description |
109
+ |---|---|
110
+ | `SLA_TEMPLATES` | Pre-built SLA templates for common service categories |
111
+ | `compareSLAs(offered, required)` | Compare an SLA offer against requirements |
112
+ | `meetsSLARequirements(offered, required)` | Check if an offer meets all required SLA metrics |
113
+ | `slaToLockstepSpec(sla, agreement)` | Convert SLA definition to a Lockstep behavioral specification |
114
+
115
+ ### Transport
116
+
117
+ | Export | Description |
118
+ |---|---|
119
+ | `JsonRpcClient` | HTTP JSON-RPC 2.0 client for sending protocol messages |
120
+ | `NegotiationServer` | HTTP JSON-RPC 2.0 server for receiving protocol messages |
121
+ | `NegotiationSession` | State machine for tracking a single negotiation lifecycle |
122
+
123
+ ### Integrations
124
+
125
+ | Export | Description |
126
+ |---|---|
127
+ | `discoverAgents(endpoints)` | Discover seller agents via A2A Agent Card endpoints |
128
+ | `parseAgentCard(card)` | Parse and validate an A2A Agent Card |
129
+ | `LockstepMonitor` | Monitor SLA compliance via the Lockstep verification service |
130
+ | `agreementToX402Headers(agreement)` | Convert an Ophir agreement to x402 payment headers |
131
+ | `parseX402Response(response)` | Parse x402 payment response into Ophir types |
132
+
133
+ ## Documentation
134
+
135
+ - [BuyerAgent API reference](../docs/sdk/buyer.md)
136
+ - [SellerAgent API reference](../docs/sdk/seller.md)
137
+ - [Message types](../docs/sdk/messages.md)
138
+ - [Protocol specification](../docs/protocol/specification.md)
139
+ - [State machine](../docs/protocol/state-machine.md)
@@ -0,0 +1 @@
1
+ export {};