@nextclaw/ncp-http-agent-client 0.3.22 → 0.3.24

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
@@ -1,4 +1,4 @@
1
- import { NcpAgentClientEndpoint, NcpAgentSendEnvelope, NcpEndpointEvent, NcpEndpointManifest, NcpEndpointSubscriber, NcpMessageAbortPayload, NcpStreamRequestPayload } from "@nextclaw/ncp";
1
+ import { NcpAgentClientEndpoint, NcpAgentSendEnvelope, NcpEndpointEvent, NcpEndpointManifest, NcpEndpointSubscriber, NcpMessageAbortPayload, NcpRunHandle, NcpStreamRequestPayload } from "@nextclaw/ncp";
2
2
 
3
3
  //#region src/utils.d.ts
4
4
  type FetchLike = (input: URL | string | Request, init?: RequestInit) => Promise<Response>;
@@ -25,7 +25,7 @@ declare class NcpHttpAgentClientEndpoint implements NcpAgentClientEndpoint {
25
25
  stop(): Promise<void>;
26
26
  emit(event: NcpEndpointEvent): Promise<void>;
27
27
  subscribe(listener: NcpEndpointSubscriber): () => void;
28
- send(envelope: NcpAgentSendEnvelope): Promise<void>;
28
+ send(envelope: NcpAgentSendEnvelope): Promise<NcpRunHandle>;
29
29
  stream(payload: NcpStreamRequestPayload): Promise<void>;
30
30
  abort(payload: NcpMessageAbortPayload): Promise<void>;
31
31
  private ensureStarted;
package/dist/index.js CHANGED
@@ -247,11 +247,35 @@ var NcpHttpAgentClientEndpoint = class {
247
247
  }
248
248
  async send(envelope) {
249
249
  await this.ensureStarted();
250
- await this.streamRequest({
251
- path: "/send",
252
- method: "POST",
253
- body: envelope
254
- });
250
+ const controller = new AbortController();
251
+ this.activeControllers.add(controller);
252
+ try {
253
+ const response = await this.fetchImpl(this.resolveUrl("/send"), {
254
+ method: "POST",
255
+ headers: {
256
+ ...this.defaultHeaders,
257
+ accept: "application/json",
258
+ "content-type": "application/json"
259
+ },
260
+ body: JSON.stringify(envelope),
261
+ signal: controller.signal
262
+ });
263
+ if (!response.ok) throw new Error(`NCP send command failed with HTTP ${response.status}: ${await safeReadText(response)}`);
264
+ const payload = await response.json();
265
+ if (!payload.ok || !payload.data) throw new Error(payload.error?.message ?? "NCP send command returned an invalid handle.");
266
+ return payload.data;
267
+ } catch (error) {
268
+ if (controller.signal.aborted) throw new Error("NCP send command was cancelled.");
269
+ if (isNcpHttpAgentClientError(error)) throw error;
270
+ const ncpError = toNcpError(error);
271
+ this.publish({
272
+ type: NcpEventType.EndpointError,
273
+ payload: ncpError
274
+ });
275
+ throw ncpErrorToError(ncpError);
276
+ } finally {
277
+ this.activeControllers.delete(controller);
278
+ }
255
279
  }
256
280
  async stream(payload) {
257
281
  await this.ensureStarted();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nextclaw/ncp-http-agent-client",
3
- "version": "0.3.22",
3
+ "version": "0.3.24",
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.5.10"
18
+ "@nextclaw/ncp": "0.5.12"
19
19
  },
20
20
  "devDependencies": {
21
21
  "@types/node": "^20.17.6",