@compose-market/sdk 0.1.1 → 0.3.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 (74) hide show
  1. package/CHANGELOG.md +64 -0
  2. package/LICENSE +21 -0
  3. package/README.md +158 -35
  4. package/dist/errors.d.ts +145 -0
  5. package/dist/errors.d.ts.map +1 -0
  6. package/dist/errors.js +152 -0
  7. package/dist/errors.js.map +1 -0
  8. package/dist/events.d.ts +75 -0
  9. package/dist/events.d.ts.map +1 -0
  10. package/dist/events.js +68 -0
  11. package/dist/events.js.map +1 -0
  12. package/dist/http.d.ts +98 -0
  13. package/dist/http.d.ts.map +1 -0
  14. package/dist/http.js +350 -0
  15. package/dist/http.js.map +1 -0
  16. package/dist/index.d.ts +206 -0
  17. package/dist/index.d.ts.map +1 -0
  18. package/dist/index.js +340 -0
  19. package/dist/index.js.map +1 -0
  20. package/dist/resources/inference.d.ts +175 -0
  21. package/dist/resources/inference.d.ts.map +1 -0
  22. package/dist/resources/inference.js +740 -0
  23. package/dist/resources/inference.js.map +1 -0
  24. package/dist/resources/instrumentation.d.ts +28 -0
  25. package/dist/resources/instrumentation.d.ts.map +1 -0
  26. package/dist/resources/instrumentation.js +43 -0
  27. package/dist/resources/instrumentation.js.map +1 -0
  28. package/dist/resources/keys.d.ts +54 -0
  29. package/dist/resources/keys.d.ts.map +1 -0
  30. package/dist/resources/keys.js +164 -0
  31. package/dist/resources/keys.js.map +1 -0
  32. package/dist/resources/models.d.ts +26 -0
  33. package/dist/resources/models.d.ts.map +1 -0
  34. package/dist/resources/models.js +52 -0
  35. package/dist/resources/models.js.map +1 -0
  36. package/dist/resources/session-events.d.ts +46 -0
  37. package/dist/resources/session-events.d.ts.map +1 -0
  38. package/dist/resources/session-events.js +199 -0
  39. package/dist/resources/session-events.js.map +1 -0
  40. package/dist/resources/webhooks.d.ts +27 -0
  41. package/dist/resources/webhooks.d.ts.map +1 -0
  42. package/dist/resources/webhooks.js +78 -0
  43. package/dist/resources/webhooks.js.map +1 -0
  44. package/dist/resources/x402.d.ts +37 -0
  45. package/dist/resources/x402.d.ts.map +1 -0
  46. package/dist/resources/x402.js +72 -0
  47. package/dist/resources/x402.js.map +1 -0
  48. package/dist/storage.d.ts +27 -0
  49. package/dist/storage.d.ts.map +1 -0
  50. package/dist/storage.js +46 -0
  51. package/dist/storage.js.map +1 -0
  52. package/dist/streaming/budget.d.ts +22 -0
  53. package/dist/streaming/budget.d.ts.map +1 -0
  54. package/dist/streaming/budget.js +40 -0
  55. package/dist/streaming/budget.js.map +1 -0
  56. package/dist/streaming/receipt.d.ts +25 -0
  57. package/dist/streaming/receipt.d.ts.map +1 -0
  58. package/dist/streaming/receipt.js +92 -0
  59. package/dist/streaming/receipt.js.map +1 -0
  60. package/dist/streaming/sse.d.ts +29 -0
  61. package/dist/streaming/sse.d.ts.map +1 -0
  62. package/dist/streaming/sse.js +125 -0
  63. package/dist/streaming/sse.js.map +1 -0
  64. package/dist/types/index.d.ts +540 -0
  65. package/dist/types/index.d.ts.map +1 -0
  66. package/dist/types/index.js +10 -0
  67. package/dist/types/index.js.map +1 -0
  68. package/dist/version.d.ts +9 -0
  69. package/dist/version.d.ts.map +1 -0
  70. package/dist/version.js +9 -0
  71. package/dist/version.js.map +1 -0
  72. package/package.json +32 -21
  73. package/index.d.ts +0 -244
  74. package/index.js +0 -397
package/package.json CHANGED
@@ -1,13 +1,18 @@
1
1
  {
2
2
  "name": "@compose-market/sdk",
3
- "version": "0.1.1",
4
- "description": "Official Compose.Market SDK for Compose keys, x402 facilitator access, model discovery, and inference APIs.",
3
+ "version": "0.3.0",
4
+ "description": "Official Compose.Market SDK: Compose Keys, x402 facilitator, 45k+ model catalog, OpenAI-shaped streaming inference with typed receipts, live session events, and wallet-scoped persistence.",
5
5
  "keywords": [
6
+ "compose",
7
+ "compose-market",
6
8
  "x402",
9
+ "x402-v2",
7
10
  "facilitator",
8
- "a2a",
11
+ "inference",
12
+ "openai-compatible",
9
13
  "agentic-economy",
10
- "decentralized-inference"
14
+ "decentralized-inference",
15
+ "a2a"
11
16
  ],
12
17
  "homepage": "https://github.com/compose-market/sdk#readme",
13
18
  "bugs": {
@@ -18,40 +23,46 @@
18
23
  "url": "git+https://github.com/compose-market/sdk.git"
19
24
  },
20
25
  "license": "MIT",
21
- "author": "jabyl",
26
+ "author": "Compose.Market",
22
27
  "type": "module",
23
28
  "exports": {
24
29
  ".": {
25
- "types": "./index.d.ts",
26
- "import": "./index.js",
27
- "default": "./index.js"
30
+ "types": "./dist/index.d.ts",
31
+ "import": "./dist/index.js",
32
+ "default": "./dist/index.js"
28
33
  }
29
34
  },
30
- "main": "./index.js",
31
- "types": "./index.d.ts",
35
+ "main": "./dist/index.js",
36
+ "types": "./dist/index.d.ts",
37
+ "module": "./dist/index.js",
32
38
  "directories": {
33
39
  "test": "tests"
34
40
  },
35
41
  "files": [
36
- "index.js",
37
- "index.d.ts"
42
+ "dist",
43
+ "README.md",
44
+ "LICENSE",
45
+ "CHANGELOG.md"
38
46
  ],
39
47
  "sideEffects": false,
48
+ "engines": {
49
+ "node": ">=20.6"
50
+ },
40
51
  "scripts": {
41
- "clean": "rm -f index.js index.d.ts",
42
- "build": "npm run clean && tsc -p tsconfig.json",
43
- "test": "npm run build && node --import tsx --test tests/**/*.test.ts",
44
- "typecheck": "tsc --noEmit -p tsconfig.json"
52
+ "clean": "rm -rf dist",
53
+ "sync-version": "node scripts/sync-version.mjs",
54
+ "build": "npm run sync-version && npm run clean && tsc -p tsconfig.json",
55
+ "test": "npm run sync-version && node --import tsx --test tests/sdk.unit.test.ts tests/sdk.streaming.test.ts tests/sdk.contract.test.ts tests/sdk.session-events.test.ts tests/sdk.events.test.ts",
56
+ "test:build": "npm run build && npm test",
57
+ "typecheck": "npm run sync-version && tsc --noEmit -p tsconfig.json",
58
+ "prepublishOnly": "npm run test:build"
45
59
  },
46
60
  "devDependencies": {
47
- "@types/express": "^5.0.6",
48
61
  "@types/node": "^25.6.0",
49
- "express": "^5.2.1",
50
62
  "tsx": "^4.21.0",
51
63
  "typescript": "^6.0.3"
52
64
  },
53
65
  "publishConfig": {
54
66
  "access": "public"
55
- },
56
- "module": "./index.js"
57
- }
67
+ }
68
+ }
package/index.d.ts DELETED
@@ -1,244 +0,0 @@
1
- type FetchLike = typeof fetch;
2
- export interface ComposeSDKOptions {
3
- baseUrl?: string;
4
- fetch?: FetchLike;
5
- walletAddress?: string;
6
- chainId?: number;
7
- composeKey?: string;
8
- }
9
- export interface ComposeRequestOptions {
10
- walletAddress?: string;
11
- chainId?: number;
12
- composeKey?: string | null;
13
- paymentSignature?: string;
14
- x402MaxAmountWei?: string;
15
- headers?: HeadersInit;
16
- }
17
- export interface PaymentRequirement {
18
- scheme: string;
19
- network: string;
20
- amount: string;
21
- asset: string;
22
- payTo: string;
23
- maxTimeoutSeconds: number;
24
- extra?: Record<string, unknown> | null;
25
- }
26
- export interface PaymentRequired {
27
- x402Version: 2;
28
- error?: string;
29
- resource: {
30
- url: string;
31
- description?: string;
32
- mimeType?: string;
33
- };
34
- accepts: PaymentRequirement[];
35
- extensions?: Record<string, unknown> | null;
36
- }
37
- export interface ModelParamDefinition {
38
- type: "string" | "integer" | "number" | "boolean" | "array";
39
- required: boolean;
40
- default?: string | number | boolean;
41
- options?: Array<string | number>;
42
- description?: string;
43
- }
44
- export interface ModelParamsResponse {
45
- modelId: string;
46
- type: "video" | "image" | null;
47
- provider: string | null;
48
- params: Record<string, ModelParamDefinition>;
49
- defaults: Record<string, unknown>;
50
- }
51
- export interface FacilitatorSupportedResponse {
52
- kinds: Array<{
53
- x402Version: number;
54
- scheme: string;
55
- network: string;
56
- extra?: Record<string, unknown>;
57
- }>;
58
- extensions: string[];
59
- signers?: Record<string, string[]>;
60
- }
61
- export interface ComposeKeyResponse {
62
- keyId: string;
63
- token: string;
64
- purpose: "session" | "api";
65
- budgetLimit: string;
66
- budgetUsed: string;
67
- budgetRemaining: string;
68
- createdAt: number;
69
- expiresAt: number;
70
- chainId: number;
71
- name?: string;
72
- }
73
- export interface ActiveComposeKeyResponse {
74
- hasSession: boolean;
75
- reason?: string;
76
- keyId?: string;
77
- token?: string;
78
- budgetLimit?: string;
79
- budgetUsed?: string;
80
- budgetLocked?: string;
81
- budgetRemaining?: string;
82
- expiresAt?: number;
83
- chainId?: number;
84
- name?: string;
85
- status?: {
86
- isActive: boolean;
87
- isExpired: boolean;
88
- expiresInSeconds: number;
89
- budgetPercentRemaining: number;
90
- warnings: {
91
- budgetDepleted: boolean;
92
- budgetLow: boolean;
93
- expiringSoon: boolean;
94
- expired: boolean;
95
- };
96
- };
97
- }
98
- export interface ComposeKeyListItem {
99
- keyId: string;
100
- purpose: "session" | "api";
101
- budgetLimit: number;
102
- budgetUsed: number;
103
- budgetRemaining: number;
104
- createdAt: number;
105
- expiresAt: number;
106
- revokedAt?: number;
107
- name?: string;
108
- lastUsedAt?: number;
109
- }
110
- export interface WalletAttachment {
111
- address: string;
112
- chainId: number;
113
- activeKey: ActiveComposeKeyResponse;
114
- }
115
- export declare class ComposeApiError extends Error {
116
- readonly status: number;
117
- readonly body: unknown;
118
- readonly headers: Record<string, string>;
119
- constructor(input: {
120
- message: string;
121
- status: number;
122
- body: unknown;
123
- headers: Record<string, string>;
124
- });
125
- }
126
- export declare class ComposePaymentRequiredError extends ComposeApiError {
127
- readonly paymentRequired: PaymentRequired;
128
- readonly paymentRequiredHeader: string | null;
129
- constructor(input: {
130
- message: string;
131
- status: number;
132
- body: unknown;
133
- headers: Record<string, string>;
134
- paymentRequired: PaymentRequired;
135
- paymentRequiredHeader: string | null;
136
- });
137
- }
138
- export declare class ComposeSDK {
139
- private readonly baseUrl;
140
- private readonly fetchImpl;
141
- private walletAddress;
142
- private chainId;
143
- private composeKey;
144
- readonly wallets: {
145
- attach: (input: {
146
- address: string;
147
- chainId: number;
148
- }) => Promise<WalletAttachment>;
149
- current: () => {
150
- address: string | null;
151
- chainId: number | null;
152
- };
153
- clear: () => void;
154
- };
155
- readonly keys: {
156
- create: (input: {
157
- purpose: "session" | "api";
158
- budgetUsd?: number;
159
- budgetWei?: number | string;
160
- durationHours?: number;
161
- expiresAt?: number;
162
- chainId?: number;
163
- name?: string;
164
- }) => Promise<ComposeKeyResponse>;
165
- getActive: (input?: {
166
- chainId?: number;
167
- }) => Promise<ActiveComposeKeyResponse>;
168
- list: () => Promise<ComposeKeyListItem[]>;
169
- revoke: (keyId: string) => Promise<{
170
- success: boolean;
171
- keyId: string;
172
- }>;
173
- use: (token: string) => void;
174
- currentToken: () => string | null;
175
- clearToken: () => void;
176
- };
177
- readonly models: {
178
- list: () => Promise<{
179
- object: "list";
180
- data: Array<Record<string, unknown>>;
181
- }>;
182
- listAll: () => Promise<{
183
- object: "list";
184
- data: Array<Record<string, unknown>>;
185
- }>;
186
- get: (modelId: string) => Promise<Record<string, unknown>>;
187
- getParams: (modelId: string) => Promise<ModelParamsResponse>;
188
- };
189
- readonly pricing: {
190
- list: () => Promise<{
191
- models: Array<Record<string, unknown>>;
192
- [key: string]: unknown;
193
- }>;
194
- };
195
- readonly inference: {
196
- responses: {
197
- create: (body: Record<string, unknown>, options?: ComposeRequestOptions) => Promise<Record<string, unknown>>;
198
- get: (responseId: string, options?: ComposeRequestOptions) => Promise<Record<string, unknown>>;
199
- inputItems: (responseId: string, options?: ComposeRequestOptions) => Promise<Record<string, unknown>>;
200
- cancel: (responseId: string, options?: ComposeRequestOptions) => Promise<Record<string, unknown>>;
201
- };
202
- chat: {
203
- completions: {
204
- create: (body: Record<string, unknown>, options?: ComposeRequestOptions) => Promise<Record<string, unknown>>;
205
- };
206
- };
207
- images: {
208
- generate: (body: Record<string, unknown>, options?: ComposeRequestOptions) => Promise<Record<string, unknown>>;
209
- edit: (body: Record<string, unknown>, options?: ComposeRequestOptions) => Promise<Record<string, unknown>>;
210
- };
211
- audio: {
212
- speech: (body: Record<string, unknown>, options?: ComposeRequestOptions) => Promise<Record<string, unknown>>;
213
- transcriptions: (body: Record<string, unknown>, options?: ComposeRequestOptions) => Promise<Record<string, unknown>>;
214
- };
215
- embeddings: {
216
- create: (body: Record<string, unknown>, options?: ComposeRequestOptions) => Promise<Record<string, unknown>>;
217
- };
218
- videos: {
219
- generate: (body: Record<string, unknown>, options?: ComposeRequestOptions) => Promise<Record<string, unknown>>;
220
- get: (videoId: string, options?: ComposeRequestOptions) => Promise<Record<string, unknown>>;
221
- };
222
- };
223
- readonly x402: {
224
- facilitator: {
225
- getSupported: () => Promise<FacilitatorSupportedResponse>;
226
- verify: (body: Record<string, unknown>) => Promise<Record<string, unknown>>;
227
- settle: (body: Record<string, unknown>) => Promise<Record<string, unknown>>;
228
- };
229
- decodePaymentRequired: (headerValue: string) => PaymentRequired;
230
- };
231
- constructor(options?: ComposeSDKOptions);
232
- private resolveWalletContext;
233
- private resolveComposeKeyToken;
234
- private attachWallet;
235
- private createKey;
236
- private getActiveKey;
237
- private listKeys;
238
- private revokeKey;
239
- private buildHeaders;
240
- private requestJson;
241
- private buildError;
242
- private extractPaymentRequired;
243
- }
244
- export {};