@hightop/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.
package/README.md ADDED
@@ -0,0 +1,114 @@
1
+ # @hightop/sdk
2
+
3
+ TypeScript SDK for the Hightop Agent API.
4
+
5
+ The SDK ships generated Agent API types and endpoint metadata plus a small hand-written client for auth, fetch transport, idempotency enforcement, errors, timeouts, raw requests, and operation polling.
6
+
7
+ ## Configuration
8
+
9
+ Header-key auth:
10
+
11
+ ```ts
12
+ import { HightopAgentClient } from '@hightop/sdk'
13
+
14
+ const client = new HightopAgentClient({
15
+ baseUrl: process.env.HIGHTOP_BASE_URL,
16
+ agentId: process.env.HIGHTOP_AGENT_ID,
17
+ apiKey: process.env.HIGHTOP_API_KEY,
18
+ })
19
+ ```
20
+
21
+ Bearer-token auth:
22
+
23
+ ```ts
24
+ const client = new HightopAgentClient({
25
+ baseUrl: process.env.HIGHTOP_BASE_URL,
26
+ bearerToken: process.env.HIGHTOP_BEARER_TOKEN,
27
+ })
28
+ ```
29
+
30
+ `baseUrl` defaults to `https://api.hightop.com` in the SDK. Auth may be omitted at construction time so public routes can be fetched, but protected endpoint calls throw until `agentId`/`apiKey` or `bearerToken` is configured.
31
+
32
+ ## Typed Helpers
33
+
34
+ Common helpers are exposed as domain methods:
35
+
36
+ ```ts
37
+ import { HightopAgentClient, createIdempotencyKey } from '@hightop/sdk'
38
+
39
+ const client = new HightopAgentClient({
40
+ baseUrl: process.env.HIGHTOP_BASE_URL,
41
+ agentId: process.env.HIGHTOP_AGENT_ID,
42
+ apiKey: process.env.HIGHTOP_API_KEY,
43
+ })
44
+
45
+ const self = await client.self.get()
46
+ const repay = await client.borrow.repay(
47
+ { asset: 'GREEN', amount_usd: '10' },
48
+ { idempotencyKey: createIdempotencyKey() },
49
+ )
50
+ const final = await client.operations.wait(repay.operation_id)
51
+ ```
52
+
53
+ Public no-auth helpers:
54
+
55
+ ```ts
56
+ const openapi = await new HightopAgentClient({ baseUrl: 'https://api.hightop.com' }).openapi.get()
57
+ const capabilities = await new HightopAgentClient({ baseUrl: 'https://api.hightop.com' }).capabilities.json()
58
+ ```
59
+
60
+ ## Generated Endpoint Surface
61
+
62
+ Every catalogued `/v1/agent/*` endpoint is available through the generated typed request map:
63
+
64
+ ```ts
65
+ const oneOff = await client.request(
66
+ 'POST /v1/agent/one-off-payments',
67
+ {
68
+ to: '0x...',
69
+ asset: 'USDC',
70
+ amount_usd: '25',
71
+ },
72
+ {
73
+ idempotencyKey: createIdempotencyKey(),
74
+ },
75
+ )
76
+ ```
77
+
78
+ The generated package artifact exports:
79
+
80
+ ```ts
81
+ import type { AgentApiRequestFor, AgentApiResponseFor, AgentApiEndpointKey } from '@hightop/sdk'
82
+ ```
83
+
84
+ These types are regenerated from the Agent API contract and validated by `npm run validate:agent-api-generated`.
85
+
86
+ ## Raw Requests
87
+
88
+ `rawRequest` is available for support workflows and newly reviewed integration cases. It only allows known `/v1/agent/*` routes, plus public OpenAPI/capabilities JSON routes.
89
+
90
+ ```ts
91
+ const operation = await client.rawRequest({
92
+ method: 'GET',
93
+ path: '/v1/agent/operations/operation-id',
94
+ query: { include: 'onchain' },
95
+ })
96
+ ```
97
+
98
+ For routes that require idempotency, `rawRequest` requires an explicit `idempotencyKey`.
99
+
100
+ ## Errors And Timeouts
101
+
102
+ Non-2xx responses throw `HightopAgentSDKError`. The original response body, normalized Agent API error, HTTP status, and response headers are preserved.
103
+
104
+ ```ts
105
+ try {
106
+ await client.borrow.repay({ asset: 'GREEN', amount_usd: '10' }, { idempotencyKey: createIdempotencyKey() })
107
+ } catch (error) {
108
+ if (error instanceof HightopAgentSDKError && error.code === 'asset_not_allowed') {
109
+ console.log(error.agentError?.details)
110
+ }
111
+ }
112
+ ```
113
+
114
+ Request timeouts are synthesized by the SDK with code `request_timeout`. These errors are client-side and are not idempotency-cached by the server if the request was never received.
@@ -0,0 +1,100 @@
1
+ import { type AgentApiAccountResponse, type AgentApiBalancesResponse, type AgentApiBorrowRepayRequest, type AgentApiBorrowResponse, type AgentApiCapabilitiesResponse, type AgentApiConversionExecuteRequest, type AgentApiConversionQuoteRequest, type AgentApiConversionQuoteResponse, type AgentApiDeleverageRequest, type AgentApiEndpointKey, type AgentApiError, type AgentApiHttpMethod, type AgentApiOperationDetailQuery, type AgentApiOperationResponse, type AgentApiOperationsQuery, type AgentApiOperationsResponse, type AgentApiPathParamValue, type AgentApiRequestFor, type AgentApiResponseFor, type AgentApiSelfResponse, type AgentApiSelfUsageResponse, type AgentApiSimulateRequest, type AgentApiSimulateResponse, type AgentApiWriteResponse, type AgentApiX402PurchaseRequest, type AgentApiX402PurchaseResponse, type AgentApiX402QuoteRequest, type AgentApiX402QuoteResponse, type AgentApiX402SignRequest, type AgentApiX402SignResponse } from './generated/agent-api.js';
2
+ type FetchLike = typeof fetch;
3
+ export type HightopAgentClientConfig = {
4
+ baseUrl?: string;
5
+ agentId?: string;
6
+ apiKey?: string;
7
+ bearerToken?: string;
8
+ fetch?: FetchLike;
9
+ timeoutMs?: number;
10
+ };
11
+ export type HightopAgentRequestOptions = {
12
+ headers?: Record<string, string>;
13
+ idempotencyKey?: string;
14
+ pathParams?: Record<string, AgentApiPathParamValue>;
15
+ signal?: AbortSignal;
16
+ timeoutMs?: number;
17
+ };
18
+ export type HightopAgentRawRequest = HightopAgentRequestOptions & {
19
+ body?: unknown;
20
+ method: AgentApiHttpMethod;
21
+ path: string;
22
+ query?: Record<string, unknown>;
23
+ };
24
+ export declare function createIdempotencyKey(prefix?: string): string;
25
+ export declare class HightopAgentSDKError extends Error {
26
+ readonly agentError?: AgentApiError;
27
+ readonly code?: string;
28
+ readonly headers: Record<string, string>;
29
+ readonly requestId?: string;
30
+ readonly response: unknown;
31
+ readonly status: number;
32
+ constructor(status: number, response: unknown, headers?: Record<string, string>);
33
+ }
34
+ export declare class HightopAgentOperationWaitTimeoutError extends Error {
35
+ readonly operation?: AgentApiOperationResponse['operation'];
36
+ constructor(operation: AgentApiOperationResponse['operation'] | undefined, timeoutMs: number);
37
+ }
38
+ export type WaitForOperationOptions = HightopAgentRequestOptions & {
39
+ pollIntervalMs?: number;
40
+ terminalStatuses?: readonly string[];
41
+ };
42
+ export declare class HightopAgentClient {
43
+ private readonly auth;
44
+ private readonly baseUrl;
45
+ private readonly fetchImpl;
46
+ private readonly timeoutMs;
47
+ constructor(config: HightopAgentClientConfig);
48
+ readonly self: {
49
+ get: (options?: HightopAgentRequestOptions) => Promise<AgentApiSelfResponse>;
50
+ usage: (options?: HightopAgentRequestOptions) => Promise<AgentApiSelfUsageResponse>;
51
+ };
52
+ readonly capabilities: {
53
+ get: (options?: HightopAgentRequestOptions) => Promise<AgentApiCapabilitiesResponse>;
54
+ json: (options?: HightopAgentRequestOptions) => Promise<AgentApiCapabilitiesResponse>;
55
+ };
56
+ readonly openapi: {
57
+ get: (options?: HightopAgentRequestOptions) => Promise<Record<string, unknown>>;
58
+ };
59
+ readonly account: {
60
+ get: (options?: HightopAgentRequestOptions) => Promise<AgentApiAccountResponse>;
61
+ };
62
+ readonly balances: {
63
+ list: (query?: Record<string, unknown>, options?: HightopAgentRequestOptions) => Promise<AgentApiBalancesResponse>;
64
+ cash: (query?: Record<string, unknown>, options?: HightopAgentRequestOptions) => Promise<AgentApiBalancesResponse>;
65
+ };
66
+ readonly operations: {
67
+ list: (query?: AgentApiOperationsQuery, options?: HightopAgentRequestOptions) => Promise<AgentApiOperationsResponse>;
68
+ get: (id: string, query?: Omit<AgentApiOperationDetailQuery, "id">, options?: HightopAgentRequestOptions) => Promise<AgentApiOperationResponse>;
69
+ wait: (id: string, options?: WaitForOperationOptions) => Promise<AgentApiOperationResponse>;
70
+ };
71
+ readonly borrow: {
72
+ get: (options?: HightopAgentRequestOptions) => Promise<AgentApiBorrowResponse>;
73
+ repay: (body: AgentApiBorrowRepayRequest, options: HightopAgentRequestOptions) => Promise<AgentApiWriteResponse>;
74
+ deleverage: (body: AgentApiDeleverageRequest, options: HightopAgentRequestOptions) => Promise<AgentApiWriteResponse>;
75
+ };
76
+ readonly conversions: {
77
+ quote: (body: AgentApiConversionQuoteRequest, options: HightopAgentRequestOptions) => Promise<AgentApiConversionQuoteResponse>;
78
+ execute: (body: AgentApiConversionExecuteRequest, options: HightopAgentRequestOptions) => Promise<AgentApiWriteResponse>;
79
+ };
80
+ readonly simulate: {
81
+ request: (body: AgentApiSimulateRequest, options?: HightopAgentRequestOptions) => Promise<AgentApiSimulateResponse>;
82
+ };
83
+ readonly x402: {
84
+ sign: (body: AgentApiX402SignRequest, options: HightopAgentRequestOptions) => Promise<AgentApiX402SignResponse>;
85
+ quote: (body: AgentApiX402QuoteRequest, options?: HightopAgentRequestOptions) => Promise<AgentApiX402QuoteResponse>;
86
+ purchase: (body: AgentApiX402PurchaseRequest, options: HightopAgentRequestOptions) => Promise<AgentApiX402PurchaseResponse>;
87
+ };
88
+ request<Key extends AgentApiEndpointKey>(key: Key, payload?: AgentApiRequestFor<Key>, options?: HightopAgentRequestOptions): Promise<AgentApiResponseFor<Key>>;
89
+ rawRequest<Response = unknown>(request: HightopAgentRawRequest): Promise<Response>;
90
+ waitForOperation(id: string, options?: WaitForOperationOptions): Promise<AgentApiOperationResponse>;
91
+ requestEndpoint<Response>(key: AgentApiEndpointKey, payload?: unknown, options?: HightopAgentRequestOptions): Promise<Response>;
92
+ private buildHeaders;
93
+ private send;
94
+ private parseResponse;
95
+ private requiresAuth;
96
+ private assertAuthConfigured;
97
+ private sleep;
98
+ }
99
+ export {};
100
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,KAAK,uBAAuB,EAC5B,KAAK,wBAAwB,EAC7B,KAAK,0BAA0B,EAC/B,KAAK,sBAAsB,EAC3B,KAAK,4BAA4B,EACjC,KAAK,gCAAgC,EACrC,KAAK,8BAA8B,EACnC,KAAK,+BAA+B,EACpC,KAAK,y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AAQ,EAC5B,GAAG,EAAE,mBAAmB,EACxB,OAAO,CAAC,EAAE,OAAO,EACjB,OAAO,GAAE,0BAA+B,GACvC,OAAO,CAAC,QAAQ,CAAC;IAiCpB,OAAO,CAAC,YAAY;YAsBN,IAAI;YA6CJ,aAAa;IAsB3B,OAAO,CAAC,YAAY;IAIpB,OAAO,CAAC,oBAAoB;IAQ5B,OAAO,CAAC,KAAK;CAwBd"}
package/dist/client.js ADDED
@@ -0,0 +1,388 @@
1
+ import { agentApiEndpoints, buildAgentApiPath, getAgentApiEndpoint, getAgentApiError, } from './generated/agent-api.js';
2
+ const DEFAULT_BASE_URL = 'https://api.hightop.com';
3
+ const DEFAULT_TIMEOUT_MS = 30_000;
4
+ const DEFAULT_WAIT_TIMEOUT_MS = 60_000;
5
+ const DEFAULT_WAIT_POLL_INTERVAL_MS = 1_000;
6
+ const TERMINAL_OPERATION_STATUSES = new Set(['executed', 'execution_failed', 'policy_rejected', 'cancelled']);
7
+ const PUBLIC_NO_AUTH_ENDPOINT_KEYS = new Set(['GET /v1/agent/capabilities.json']);
8
+ const PUBLIC_NO_AUTH_RAW_ENDPOINTS = new Set(['GET /v1/agent/openapi.json', 'GET /v1/agent/capabilities.json']);
9
+ function normalizeBaseUrl(baseUrl) {
10
+ return baseUrl.replace(/\/+$/, '');
11
+ }
12
+ function normalizeAuth(config) {
13
+ const hasHeaderKeyAuth = Boolean(config.agentId || config.apiKey);
14
+ const hasBearerAuth = Boolean(config.bearerToken);
15
+ if (hasHeaderKeyAuth && hasBearerAuth) {
16
+ throw new Error('Configure either agentId/apiKey auth or bearerToken auth, not both.');
17
+ }
18
+ if (hasHeaderKeyAuth) {
19
+ if (!config.agentId || !config.apiKey) {
20
+ throw new Error('Both agentId and apiKey are required for header-key auth.');
21
+ }
22
+ return { kind: 'header_key', agentId: config.agentId, apiKey: config.apiKey };
23
+ }
24
+ if (hasBearerAuth) {
25
+ return { kind: 'bearer', bearerToken: config.bearerToken };
26
+ }
27
+ return null;
28
+ }
29
+ function isRecord(value) {
30
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
31
+ }
32
+ function pickDefined(source, keys) {
33
+ if (!isRecord(source)) {
34
+ return {};
35
+ }
36
+ const result = {};
37
+ for (const key of keys) {
38
+ const value = source[key];
39
+ if (value !== undefined) {
40
+ result[key] = value;
41
+ }
42
+ }
43
+ return result;
44
+ }
45
+ function appendQuery(url, query) {
46
+ if (!query) {
47
+ return;
48
+ }
49
+ for (const [key, value] of Object.entries(query)) {
50
+ if (value === undefined || value === null) {
51
+ continue;
52
+ }
53
+ if (Array.isArray(value)) {
54
+ for (const item of value) {
55
+ if (item !== undefined && item !== null) {
56
+ url.searchParams.append(key, String(item));
57
+ }
58
+ }
59
+ continue;
60
+ }
61
+ url.searchParams.set(key, String(value));
62
+ }
63
+ }
64
+ function headersToRecord(headers) {
65
+ const record = {};
66
+ headers.forEach((value, key) => {
67
+ record[key] = value;
68
+ });
69
+ return record;
70
+ }
71
+ function endpointPathPattern(pathTemplate) {
72
+ const escaped = pathTemplate.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
73
+ return new RegExp(`^${escaped.replace(/\\\{[^}]+\\\}/g, '[^/]+')}$`);
74
+ }
75
+ function findEndpoint(method, path) {
76
+ return (agentApiEndpoints.find((endpoint) => endpoint.method === method && (endpoint.path === path || endpointPathPattern(endpoint.path).test(path))) ?? null);
77
+ }
78
+ function assertSafeAgentApiPath(path) {
79
+ const segments = path.split('/');
80
+ for (const segment of segments) {
81
+ if (!segment) {
82
+ continue;
83
+ }
84
+ let decodedSegment;
85
+ try {
86
+ decodedSegment = decodeURIComponent(segment);
87
+ }
88
+ catch {
89
+ throw new Error(`Unsafe Agent API path: ${path}`);
90
+ }
91
+ if (decodedSegment === '.' ||
92
+ decodedSegment === '..' ||
93
+ decodedSegment.includes('/') ||
94
+ decodedSegment.includes('\\')) {
95
+ throw new Error(`Unsafe Agent API path: ${path}`);
96
+ }
97
+ }
98
+ }
99
+ function createTimeoutResponse(message) {
100
+ return {
101
+ ok: false,
102
+ error: {
103
+ code: 'request_timeout',
104
+ message,
105
+ },
106
+ };
107
+ }
108
+ export function createIdempotencyKey(prefix = 'hightop') {
109
+ const crypto = globalThis.crypto;
110
+ const randomUUID = crypto?.randomUUID?.();
111
+ if (randomUUID) {
112
+ return `${prefix}_${randomUUID}`;
113
+ }
114
+ if (!crypto?.getRandomValues) {
115
+ throw new Error('crypto is not available; createIdempotencyKey requires Node 18+ or a polyfilled global crypto');
116
+ }
117
+ const bytes = new Uint8Array(16);
118
+ crypto.getRandomValues(bytes);
119
+ const fallback = [...bytes].map((byte) => byte.toString(16).padStart(2, '0')).join('');
120
+ return `${prefix}_${fallback}`;
121
+ }
122
+ export class HightopAgentSDKError extends Error {
123
+ agentError;
124
+ code;
125
+ headers;
126
+ requestId;
127
+ response;
128
+ status;
129
+ constructor(status, response, headers = {}) {
130
+ const agentError = getAgentApiError(response);
131
+ super(agentError?.message ?? `Agent API request failed (${status})`);
132
+ this.name = 'HightopAgentSDKError';
133
+ this.status = status;
134
+ this.response = response;
135
+ this.headers = headers;
136
+ this.requestId = headers['x-request-id'];
137
+ this.agentError = agentError ?? undefined;
138
+ this.code = agentError?.code;
139
+ }
140
+ }
141
+ export class HightopAgentOperationWaitTimeoutError extends Error {
142
+ operation;
143
+ constructor(operation, timeoutMs) {
144
+ super(`Timed out waiting for Agent API operation after ${timeoutMs}ms`);
145
+ this.name = 'HightopAgentOperationWaitTimeoutError';
146
+ this.operation = operation;
147
+ }
148
+ }
149
+ export class HightopAgentClient {
150
+ auth;
151
+ baseUrl;
152
+ fetchImpl;
153
+ timeoutMs;
154
+ constructor(config) {
155
+ this.auth = normalizeAuth(config);
156
+ this.baseUrl = normalizeBaseUrl(config.baseUrl ?? DEFAULT_BASE_URL);
157
+ this.fetchImpl = config.fetch ?? fetch;
158
+ this.timeoutMs = config.timeoutMs ?? DEFAULT_TIMEOUT_MS;
159
+ }
160
+ self = {
161
+ get: (options) => this.requestEndpoint('GET /v1/agent/self', undefined, options),
162
+ usage: (options) => this.requestEndpoint('GET /v1/agent/self/usage', undefined, options),
163
+ };
164
+ capabilities = {
165
+ get: (options) => this.requestEndpoint('GET /v1/agent/capabilities', undefined, options),
166
+ json: (options) => this.requestEndpoint('GET /v1/agent/capabilities.json', undefined, options),
167
+ };
168
+ openapi = {
169
+ get: (options) => this.send({
170
+ headers: options?.headers,
171
+ method: 'GET',
172
+ path: '/v1/agent/openapi.json',
173
+ signal: options?.signal,
174
+ timeoutMs: options?.timeoutMs,
175
+ }),
176
+ };
177
+ account = {
178
+ get: (options) => this.requestEndpoint('GET /v1/agent/account', undefined, options),
179
+ };
180
+ balances = {
181
+ list: (query = {}, options) => this.requestEndpoint('GET /v1/agent/balances', query, options),
182
+ cash: (query = {}, options) => this.requestEndpoint('GET /v1/agent/balances/cash', query, options),
183
+ };
184
+ operations = {
185
+ list: (query = {}, options) => this.requestEndpoint('GET /v1/agent/operations', query, options),
186
+ get: (id, query = {}, options) => this.requestEndpoint('GET /v1/agent/operations/{id}', { ...query, id }, options),
187
+ wait: (id, options) => this.waitForOperation(id, options),
188
+ };
189
+ borrow = {
190
+ get: (options) => this.requestEndpoint('GET /v1/agent/borrow', undefined, options),
191
+ repay: (body, options) => this.requestEndpoint('POST /v1/agent/borrow/repay', body, options),
192
+ deleverage: (body, options) => this.requestEndpoint('POST /v1/agent/borrow/deleverage', body, options),
193
+ };
194
+ conversions = {
195
+ quote: (body, options) => this.requestEndpoint('POST /v1/agent/conversions/quote', body, options),
196
+ execute: (body, options) => this.requestEndpoint('POST /v1/agent/conversions', body, options),
197
+ };
198
+ simulate = {
199
+ request: (body, options) => this.requestEndpoint('POST /v1/agent/simulate', body, options),
200
+ };
201
+ x402 = {
202
+ sign: (body, options) => this.requestEndpoint('POST /v1/agent/x402/sign', body, options),
203
+ quote: (body, options) => this.requestEndpoint('POST /v1/agent/x402/quote', body, options),
204
+ purchase: (body, options) => this.requestEndpoint('POST /v1/agent/x402/purchase', body, options),
205
+ };
206
+ request(key, payload, options = {}) {
207
+ return this.requestEndpoint(key, payload, options);
208
+ }
209
+ async rawRequest(request) {
210
+ assertSafeAgentApiPath(request.path);
211
+ const endpoint = findEndpoint(request.method, request.path);
212
+ const rawKey = `${request.method} ${request.path}`;
213
+ if (!endpoint && !PUBLIC_NO_AUTH_RAW_ENDPOINTS.has(rawKey)) {
214
+ throw new Error(`Raw Agent API requests must target a known /v1/agent endpoint: ${request.method} ${request.path}`);
215
+ }
216
+ if (endpoint && this.requiresAuth(endpoint.key)) {
217
+ this.assertAuthConfigured(endpoint.key);
218
+ }
219
+ if (endpoint?.idempotencyRequired && !request.idempotencyKey) {
220
+ throw new Error(`Idempotency-Key is required for ${endpoint.key}`);
221
+ }
222
+ return this.send(request);
223
+ }
224
+ async waitForOperation(id, options = {}) {
225
+ const timeoutMs = options.timeoutMs ?? DEFAULT_WAIT_TIMEOUT_MS;
226
+ const pollIntervalMs = options.pollIntervalMs ?? DEFAULT_WAIT_POLL_INTERVAL_MS;
227
+ const terminalStatuses = new Set(options.terminalStatuses ?? TERMINAL_OPERATION_STATUSES);
228
+ const deadline = Date.now() + timeoutMs;
229
+ let lastOperation;
230
+ while (Date.now() <= deadline) {
231
+ const response = await this.operations.get(id, undefined, {
232
+ headers: options.headers,
233
+ signal: options.signal,
234
+ timeoutMs: options.timeoutMs,
235
+ });
236
+ lastOperation = response.operation;
237
+ if (terminalStatuses.has(response.operation.status)) {
238
+ return response;
239
+ }
240
+ await this.sleep(Math.min(pollIntervalMs, Math.max(0, deadline - Date.now())), options.signal);
241
+ }
242
+ throw new HightopAgentOperationWaitTimeoutError(lastOperation, timeoutMs);
243
+ }
244
+ async requestEndpoint(key, payload, options = {}) {
245
+ const endpoint = getAgentApiEndpoint(key);
246
+ if (this.requiresAuth(endpoint.key)) {
247
+ this.assertAuthConfigured(endpoint.key);
248
+ }
249
+ if (endpoint.idempotencyRequired && !options.idempotencyKey) {
250
+ throw new Error(`Idempotency-Key is required for ${endpoint.key}`);
251
+ }
252
+ const pathParams = {
253
+ ...pickDefined(payload, endpoint.pathParams),
254
+ ...(options.pathParams ?? {}),
255
+ };
256
+ const path = buildAgentApiPath(endpoint.path, pathParams);
257
+ const query = endpoint.queryParams.length > 0 ? pickDefined(payload, endpoint.queryParams) : undefined;
258
+ const body = endpoint.bodySchema
259
+ ? endpoint.bodyParams.length > 0
260
+ ? pickDefined(payload, endpoint.bodyParams)
261
+ : {}
262
+ : undefined;
263
+ return this.send({
264
+ body,
265
+ headers: options.headers,
266
+ idempotencyKey: options.idempotencyKey,
267
+ method: endpoint.method,
268
+ path,
269
+ query,
270
+ signal: options.signal,
271
+ timeoutMs: options.timeoutMs,
272
+ });
273
+ }
274
+ buildHeaders(body, options) {
275
+ const headers = new Headers(options.headers);
276
+ headers.set('Accept', 'application/json');
277
+ if (body !== undefined) {
278
+ headers.set('Content-Type', 'application/json');
279
+ }
280
+ if (this.auth?.kind === 'header_key') {
281
+ headers.set('x-agent-id', this.auth.agentId);
282
+ headers.set('x-api-key', this.auth.apiKey);
283
+ }
284
+ else if (this.auth?.kind === 'bearer') {
285
+ headers.set('Authorization', `Bearer ${this.auth.bearerToken}`);
286
+ }
287
+ if (options.idempotencyKey) {
288
+ headers.set('Idempotency-Key', options.idempotencyKey);
289
+ }
290
+ return headers;
291
+ }
292
+ async send(parts) {
293
+ assertSafeAgentApiPath(parts.path);
294
+ const url = new URL(`${this.baseUrl}${parts.path}`);
295
+ appendQuery(url, parts.query);
296
+ const headers = this.buildHeaders(parts.body, parts);
297
+ const timeoutMs = parts.timeoutMs ?? this.timeoutMs;
298
+ const controller = new AbortController();
299
+ let didTimeout = false;
300
+ const timeout = setTimeout(() => {
301
+ didTimeout = true;
302
+ controller.abort();
303
+ }, timeoutMs);
304
+ const abort = () => controller.abort();
305
+ if (parts.signal?.aborted) {
306
+ controller.abort();
307
+ }
308
+ else {
309
+ parts.signal?.addEventListener('abort', abort, { once: true });
310
+ }
311
+ try {
312
+ const response = await this.fetchImpl(url.toString(), {
313
+ body: parts.body === undefined ? undefined : JSON.stringify(parts.body),
314
+ headers,
315
+ method: parts.method,
316
+ signal: controller.signal,
317
+ });
318
+ const parsed = await this.parseResponse(response);
319
+ if (!response.ok) {
320
+ throw new HightopAgentSDKError(response.status, parsed, headersToRecord(response.headers));
321
+ }
322
+ return parsed;
323
+ }
324
+ catch (error) {
325
+ if (didTimeout) {
326
+ throw new HightopAgentSDKError(0, createTimeoutResponse(`Agent API request timed out after ${timeoutMs}ms`));
327
+ }
328
+ throw error;
329
+ }
330
+ finally {
331
+ clearTimeout(timeout);
332
+ parts.signal?.removeEventListener('abort', abort);
333
+ }
334
+ }
335
+ async parseResponse(response) {
336
+ const text = await response.text();
337
+ if (!text) {
338
+ return undefined;
339
+ }
340
+ const contentType = response.headers.get('content-type') ?? '';
341
+ if (contentType.includes('application/json')) {
342
+ try {
343
+ return JSON.parse(text);
344
+ }
345
+ catch {
346
+ return text;
347
+ }
348
+ }
349
+ try {
350
+ return JSON.parse(text);
351
+ }
352
+ catch {
353
+ return text;
354
+ }
355
+ }
356
+ requiresAuth(endpointKey) {
357
+ return !PUBLIC_NO_AUTH_ENDPOINT_KEYS.has(endpointKey);
358
+ }
359
+ assertAuthConfigured(endpointKey) {
360
+ if (!this.auth) {
361
+ throw new Error(`Authentication is required for ${endpointKey}. Configure agentId/apiKey auth or bearerToken auth.`);
362
+ }
363
+ }
364
+ sleep(ms, signal) {
365
+ if (ms <= 0) {
366
+ return Promise.resolve();
367
+ }
368
+ if (signal?.aborted) {
369
+ return Promise.reject(new DOMException('The operation was aborted.', 'AbortError'));
370
+ }
371
+ return new Promise((resolve, reject) => {
372
+ const cleanup = () => {
373
+ clearTimeout(timeout);
374
+ signal?.removeEventListener('abort', abort);
375
+ };
376
+ const timeout = setTimeout(() => {
377
+ cleanup();
378
+ resolve();
379
+ }, ms);
380
+ const abort = () => {
381
+ cleanup();
382
+ reject(new DOMException('The operation was aborted.', 'AbortError'));
383
+ };
384
+ signal?.addEventListener('abort', abort, { once: true });
385
+ });
386
+ }
387
+ }
388
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EACjB,iBAAiB,EACjB,mBAAmB,EACnB,gBAAgB,GAgCjB,MAAM,0BAA0B,CAAA;AAmDjC,MAAM,gBAAgB,GAAG,yBAAyB,CAAA;AAClD,MAAM,kBAAkB,GAAG,MAAM,CAAA;AACjC,MAAM,uBAAuB,GAAG,MAAM,CAAA;AACtC,MAAM,6BAA6B,GAAG,KAAK,CAAA;AAC3C,MAAM,2BAA2B,GAAG,IAAI,GAAG,CAAC,CAAC,UAAU,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,WAAW,CAAC,CAAC,CAAA;AAC7G,MAAM,4BAA4B,GAAG,IAAI,GAAG,CAAsB,CAAC,iCAAiC,CAAC,CAAC,CAAA;AACtG,MAAM,4BAA4B,GAAG,IAAI,GAAG,CAAC,CAAC,4BAA4B,EAAE,iCAAiC,CAAC,CAAC,CAAA;AAE/G,SAAS,gBAAgB,CAAC,OAAe;IACvC,OAAO,OAAO,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAA;AACpC,CAAC;AAED,SAAS,aAAa,CAAC,MAAgC;IACrD,MAAM,gBAAgB,GAAG,OAAO,CAAC,MAAM,CAAC,OAAO,IAAI,MAAM,CAAC,MAAM,CAAC,CAAA;IACjE,MAAM,aAAa,GAAG,OAAO,CAAC,MAAM,CAAC,WAAW,CAAC,CAAA;IAEjD,IAAI,gBAAgB,IAAI,aAAa,EAAE,CAAC;QACtC,MAAM,IAAI,KAAK,CAAC,qEAAqE,CAAC,CAAA;IACxF,CAAC;IAED,IAAI,gBAAgB,EAAE,CAAC;QACrB,IAAI,CAAC,MAAM,CAAC,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC;YACtC,MAAM,IAAI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