@greenhelix/sdk 1.0.7

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/README.md ADDED
@@ -0,0 +1,97 @@
1
+ # @greenhelix/sdk
2
+
3
+ TypeScript SDK for the [A2A Commerce Platform](https://github.com/mirni/a2a) -- agent-to-agent payments, escrow, marketplace, identity, and trust scoring.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @greenhelix/sdk
9
+ ```
10
+
11
+ Requires Node.js 18+. Zero dependencies (uses built-in `fetch`).
12
+
13
+ ## Quick Start
14
+
15
+ ```typescript
16
+ import { A2AClient } from '@greenhelix/sdk';
17
+
18
+ const client = new A2AClient({
19
+ baseUrl: 'https://api.greenhelix.net',
20
+ apiKey: 'a2a_free_...',
21
+ });
22
+
23
+ // Health check
24
+ const health = await client.health();
25
+
26
+ // Get wallet balance
27
+ const balance = await client.getBalance('my-agent');
28
+
29
+ // Create and capture a payment
30
+ const intent = await client.createPaymentIntent({
31
+ payer: 'buyer-agent',
32
+ payee: 'seller-agent',
33
+ amount: 10.0,
34
+ });
35
+ const settlement = await client.capturePayment(intent.intent_id);
36
+
37
+ // Search marketplace
38
+ const services = await client.searchServices({ query: 'analytics' });
39
+ ```
40
+
41
+ ## Configuration
42
+
43
+ ```typescript
44
+ const client = new A2AClient({
45
+ baseUrl: 'https://api.greenhelix.net', // or http://localhost:8000
46
+ apiKey: 'a2a_free_...',
47
+ timeout: 30000, // request timeout (ms)
48
+ maxRetries: 3, // automatic retries with backoff
49
+ });
50
+ ```
51
+
52
+ ## Methods
53
+
54
+ | Method | Description |
55
+ |--------|-------------|
56
+ | `health()` | Health check |
57
+ | `getBalance(agentId)` | Wallet balance |
58
+ | `deposit(agentId, amount)` | Add credits |
59
+ | `createPaymentIntent({...})` | Authorize payment |
60
+ | `capturePayment(intentId)` | Settle payment |
61
+ | `createEscrow({...})` | Hold funds in escrow |
62
+ | `releaseEscrow(escrowId)` | Release escrow |
63
+ | `searchServices({query})` | Search marketplace |
64
+ | `bestMatch(query)` | Best service match |
65
+ | `getTrustScore(serverId)` | Trust score |
66
+ | `registerAgent(agentId)` | Create identity |
67
+ | `sendMessage({...})` | Encrypted messaging |
68
+ | `execute(tool, params)` | Generic tool call |
69
+ | `batchExecute(calls)` | Multi-tool batch |
70
+
71
+ ## Error Handling
72
+
73
+ ```typescript
74
+ import { A2AError } from '@greenhelix/sdk';
75
+
76
+ try {
77
+ await client.execute('deposit', { agent_id: 'x', amount: 100 });
78
+ } catch (error) {
79
+ if (error instanceof A2AError) {
80
+ console.error(`API error: ${error.code} - ${error.message}`);
81
+ if (error.status === 429) {
82
+ // Rate limited
83
+ }
84
+ }
85
+ }
86
+ ```
87
+
88
+ ## Links
89
+
90
+ - [API Documentation](https://api.greenhelix.net/docs)
91
+ - [Sandbox](https://sandbox.greenhelix.net)
92
+ - [GitHub](https://github.com/mirni/a2a)
93
+ - [SDK Guide](https://github.com/mirni/a2a/blob/main/docs/sdk-guide.md)
94
+
95
+ ## License
96
+
97
+ MIT
@@ -0,0 +1,195 @@
1
+ /**
2
+ * A2A Commerce Gateway — TypeScript SDK Client.
3
+ *
4
+ * Zero-dependency client using native fetch (Node 18+).
5
+ *
6
+ * @example
7
+ * ```ts
8
+ * const client = new A2AClient({ apiKey: "ak_pro_..." });
9
+ * const health = await client.health();
10
+ * const balance = await client.getBalance("my-agent");
11
+ * ```
12
+ */
13
+ import type { A2AClientOptions, AgentIdentityResponse, ApiKeyResponse, BalanceResponse, CheckoutResult, EscrowResponse, EventListResponse, EventPublishResponse, ExecuteResponse, HealthResponse, KeyRotationResponse, MessageListResponse, MetricsSubmissionResponse, NegotiationResponse, OrgDetailResponse, OrgMemberResponse, OrgResponse, PaymentHistoryResponse, PaymentIntent, RefundResponse, ServerSearchResponse, ServiceDetailResponse, ServiceRatingResponse, ServiceRegistrationResponse, SubscriptionDetailResponse, SubscriptionListResponse, SubscriptionResponse, ToolPricing, TrustScore, UsageSummaryResponse, VerifiedClaimsResponse, VerifyAgentResponse, WebhookDeleteResponse, WebhookListResponse, WebhookResponse } from "./types";
14
+ export declare class A2AClient {
15
+ private readonly baseUrl;
16
+ private readonly apiKey;
17
+ private readonly timeout;
18
+ private readonly maxRetries;
19
+ private readonly retryBaseDelay;
20
+ private readonly pricingCacheTtl;
21
+ private pricingCache;
22
+ private pricingCacheTime;
23
+ constructor(options?: A2AClientOptions);
24
+ private headers;
25
+ private request;
26
+ /**
27
+ * Internal helper for REST endpoint calls with auth and error handling.
28
+ */
29
+ private rest;
30
+ /** GET /v1/health */
31
+ health(): Promise<HealthResponse>;
32
+ /** GET /v1/pricing — full catalog (cached). */
33
+ pricing(useCache?: boolean): Promise<ToolPricing[]>;
34
+ /** GET /v1/pricing/:tool — single tool pricing. */
35
+ pricingTool(toolName: string): Promise<ToolPricing>;
36
+ /** POST /v1/execute — execute a tool. */
37
+ execute(tool: string, params?: Record<string, any>): Promise<ExecuteResponse>;
38
+ /** POST /v1/checkout — create a Stripe Checkout session. */
39
+ checkout(options: {
40
+ package?: string;
41
+ credits?: number;
42
+ successUrl?: string;
43
+ cancelUrl?: string;
44
+ }): Promise<CheckoutResult>;
45
+ /** Clear the pricing cache. */
46
+ invalidatePricingCache(): void;
47
+ /** Get wallet balance for an agent. */
48
+ getBalance(agentId: string): Promise<BalanceResponse>;
49
+ /** Deposit credits into a wallet. Returns new balance. */
50
+ deposit(agentId: string, amount: number, description?: string): Promise<number>;
51
+ /** Get usage summary for an agent. */
52
+ getUsageSummary(agentId: string, since?: number): Promise<UsageSummaryResponse>;
53
+ /** Create a payment intent. */
54
+ createPaymentIntent(payer: string, payee: string, amount: number, description?: string, idempotencyKey?: string): Promise<PaymentIntent>;
55
+ /** Capture a pending payment intent. */
56
+ capturePayment(intentId: string): Promise<PaymentIntent>;
57
+ /** Create an escrow. */
58
+ createEscrow(payer: string, payee: string, amount: number, description?: string, timeoutHours?: number): Promise<EscrowResponse>;
59
+ /** Release an escrow to the payee. */
60
+ releaseEscrow(escrowId: string): Promise<EscrowResponse>;
61
+ /** Search the marketplace. */
62
+ searchServices(options?: {
63
+ query?: string;
64
+ category?: string;
65
+ tags?: string[];
66
+ maxCost?: number;
67
+ limit?: number;
68
+ }): Promise<Record<string, any>[]>;
69
+ /** Find best matching services. */
70
+ bestMatch(query: string, options?: {
71
+ budget?: number;
72
+ minTrustScore?: number;
73
+ prefer?: string;
74
+ limit?: number;
75
+ }): Promise<Record<string, any>[]>;
76
+ /** Get trust score for a server. */
77
+ getTrustScore(serverId: string, window?: string, recompute?: boolean): Promise<TrustScore>;
78
+ /** Get payment history for an agent. */
79
+ getPaymentHistory(agentId: string, limit?: number, offset?: number): Promise<PaymentHistoryResponse>;
80
+ /** Register a new agent identity. */
81
+ registerAgent(agentId: string, displayName: string, capabilities?: string[]): Promise<Record<string, any>>;
82
+ /** Send a message between agents. */
83
+ sendMessage(sender: string, recipient: string, content: string, messageType?: string): Promise<Record<string, any>>;
84
+ /** Cancel a held escrow and refund the payer. */
85
+ cancelEscrow(escrowId: string): Promise<EscrowResponse>;
86
+ /** Refund a settled payment (full or partial). */
87
+ refundSettlement(settlementId: string, options?: {
88
+ amount?: number;
89
+ reason?: string;
90
+ }): Promise<RefundResponse>;
91
+ /** Refund a payment intent: voids if pending, reverse-transfers if settled. */
92
+ refundIntent(intentId: string): Promise<PaymentIntent>;
93
+ /** Void a pending payment (alias for refundIntent). */
94
+ voidPayment(intentId: string): Promise<PaymentIntent>;
95
+ /** Create a recurring payment subscription. */
96
+ createSubscription(payer: string, payee: string, amount: number, interval: string, options?: {
97
+ description?: string;
98
+ }): Promise<SubscriptionResponse>;
99
+ /** Cancel an active or suspended subscription. */
100
+ cancelSubscription(subscriptionId: string, options?: {
101
+ cancelledBy?: string;
102
+ }): Promise<{
103
+ id: string;
104
+ status: string;
105
+ }>;
106
+ /** Get subscription details by ID. */
107
+ getSubscription(subscriptionId: string): Promise<SubscriptionDetailResponse>;
108
+ /** List subscriptions for an agent. */
109
+ listSubscriptions(options?: {
110
+ agentId?: string;
111
+ status?: string;
112
+ limit?: number;
113
+ offset?: number;
114
+ }): Promise<SubscriptionListResponse>;
115
+ /** Register a new service in the marketplace. */
116
+ registerService(options: {
117
+ providerId: string;
118
+ name: string;
119
+ description: string;
120
+ category: string;
121
+ tools?: string[];
122
+ tags?: string[];
123
+ endpoint?: string;
124
+ pricing?: Record<string, any>;
125
+ }): Promise<ServiceRegistrationResponse>;
126
+ /** Get a marketplace service by ID. */
127
+ getService(serviceId: string): Promise<ServiceDetailResponse>;
128
+ /** Rate a marketplace service (1-5). */
129
+ rateService(serviceId: string, agentId: string, rating: number, options?: {
130
+ review?: string;
131
+ }): Promise<ServiceRatingResponse>;
132
+ /** Search for servers by name or minimum trust score. */
133
+ searchServers(options?: {
134
+ nameContains?: string;
135
+ minScore?: number;
136
+ limit?: number;
137
+ }): Promise<ServerSearchResponse>;
138
+ /** Get the cryptographic identity for an agent. */
139
+ getAgentIdentity(agentId: string): Promise<AgentIdentityResponse>;
140
+ /** Verify that a message was signed by the claimed agent. */
141
+ verifyAgent(agentId: string, message: string, signature: string): Promise<VerifyAgentResponse>;
142
+ /** Submit trading bot metrics for platform attestation. */
143
+ submitMetrics(agentId: string, metrics: Record<string, any>, options?: {
144
+ dataSource?: string;
145
+ }): Promise<MetricsSubmissionResponse>;
146
+ /** Get all verified metric claims for an agent. */
147
+ getVerifiedClaims(agentId: string): Promise<VerifiedClaimsResponse>;
148
+ /** Register a webhook endpoint. */
149
+ registerWebhook(options: {
150
+ agentId: string;
151
+ url: string;
152
+ eventTypes: string[];
153
+ secret?: string;
154
+ filterAgentIds?: string[];
155
+ }): Promise<WebhookResponse>;
156
+ /** List all registered webhooks for an agent. */
157
+ listWebhooks(agentId: string): Promise<WebhookListResponse>;
158
+ /** Delete (deactivate) a webhook by ID. */
159
+ deleteWebhook(webhookId: string): Promise<WebhookDeleteResponse>;
160
+ /** Create a new API key for an agent. */
161
+ createApiKey(agentId: string, options?: {
162
+ tier?: string;
163
+ }): Promise<ApiKeyResponse>;
164
+ /** Rotate an API key: revoke current and create new with same tier. */
165
+ rotateKey(currentKey: string): Promise<KeyRotationResponse>;
166
+ /** Publish an event to the cross-product event bus. */
167
+ publishEvent(eventType: string, source: string, payload?: Record<string, any>): Promise<EventPublishResponse>;
168
+ /** Query events from the event bus. */
169
+ getEvents(options?: {
170
+ eventType?: string;
171
+ sinceId?: number;
172
+ limit?: number;
173
+ }): Promise<EventListResponse>;
174
+ /** Create a new organization. */
175
+ createOrg(orgName: string): Promise<OrgResponse>;
176
+ /** Get organization details and members. */
177
+ getOrg(orgId: string): Promise<OrgDetailResponse>;
178
+ /** Add an agent to an organization. */
179
+ addAgentToOrg(orgId: string, agentId: string): Promise<OrgMemberResponse>;
180
+ /** Get organization members (convenience alias for getOrg). */
181
+ getOrgMembers(orgId: string): Promise<OrgDetailResponse>;
182
+ /** Start a price negotiation with another agent. */
183
+ negotiatePrice(options: {
184
+ initiator: string;
185
+ responder: string;
186
+ amount: number;
187
+ serviceId?: string;
188
+ expiresHours?: number;
189
+ }): Promise<NegotiationResponse>;
190
+ /** Get messages for an agent. */
191
+ getMessages(agentId: string, options?: {
192
+ threadId?: string;
193
+ limit?: number;
194
+ }): Promise<MessageListResponse>;
195
+ }