@nextclaw/ncp-http-agent-client 0.3.10 → 0.3.12

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/index.d.ts CHANGED
@@ -29,6 +29,7 @@ declare class NcpHttpAgentClientEndpoint implements NcpAgentClientEndpoint {
29
29
  private ensureStarted;
30
30
  private publish;
31
31
  private resolveUrl;
32
+ private jsonRequest;
32
33
  private streamRequest;
33
34
  private handleSseFrame;
34
35
  }
package/dist/index.js CHANGED
@@ -290,7 +290,7 @@ var NcpHttpAgentClientEndpoint = class {
290
290
  }
291
291
  async send(envelope) {
292
292
  await this.ensureStarted();
293
- await this.streamRequest({
293
+ await this.jsonRequest({
294
294
  path: "/send",
295
295
  method: "POST",
296
296
  body: envelope
@@ -350,6 +350,39 @@ var NcpHttpAgentClientEndpoint = class {
350
350
  resolveUrl(path) {
351
351
  return new URL(`${this.basePath}${path}`, this.baseUrl);
352
352
  }
353
+ async jsonRequest(options) {
354
+ const controller = new AbortController();
355
+ this.activeControllers.add(controller);
356
+ try {
357
+ const response = await this.fetchImpl(this.resolveUrl(options.path), {
358
+ method: options.method,
359
+ headers: {
360
+ ...this.defaultHeaders,
361
+ "content-type": "application/json",
362
+ accept: "application/json"
363
+ },
364
+ body: options.body === void 0 ? void 0 : JSON.stringify(options.body),
365
+ signal: controller.signal
366
+ });
367
+ if (!response.ok) {
368
+ throw new Error(
369
+ `NCP request failed with HTTP ${response.status}: ${await safeReadText(response)}`
370
+ );
371
+ }
372
+ } catch (error) {
373
+ if (controller.signal.aborted) {
374
+ return;
375
+ }
376
+ if (isNcpHttpAgentClientError(error)) {
377
+ throw error;
378
+ }
379
+ const ncpError = toNcpError(error);
380
+ this.publish({ type: NcpEventType.EndpointError, payload: ncpError });
381
+ throw ncpErrorToError(ncpError);
382
+ } finally {
383
+ this.activeControllers.delete(controller);
384
+ }
385
+ }
353
386
  async streamRequest(options) {
354
387
  const controller = new AbortController();
355
388
  this.activeControllers.add(controller);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nextclaw/ncp-http-agent-client",
3
- "version": "0.3.10",
3
+ "version": "0.3.12",
4
4
  "private": false,
5
5
  "description": "HTTP/SSE client transport adapter for NCP agent endpoints.",
6
6
  "type": "module",
@@ -15,7 +15,7 @@
15
15
  "dist"
16
16
  ],
17
17
  "dependencies": {
18
- "@nextclaw/ncp": "0.4.6"
18
+ "@nextclaw/ncp": "0.5.0"
19
19
  },
20
20
  "devDependencies": {
21
21
  "@types/node": "^20.17.6",