@nextclaw/ncp-http-agent-client 0.1.0 → 0.2.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 CHANGED
@@ -5,7 +5,7 @@ HTTP/SSE transport adapter implementing `NcpAgentClientEndpoint` for agent scena
5
5
  ## Build
6
6
 
7
7
  ```bash
8
- pnpm -C packages/nextclaw-ncp-http-agent-client build
8
+ pnpm -C packages/ncp-packages/nextclaw-ncp-http-agent-client build
9
9
  ```
10
10
 
11
11
  ## API
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { NcpAgentClientEndpoint, NcpEndpointManifest, NcpEndpointEvent, NcpEndpointSubscriber, NcpRequestEnvelope, NcpResumeRequestPayload, NcpMessageAbortPayload } from '@nextclaw/ncp';
1
+ import { NcpAgentClientEndpoint, NcpEndpointManifest, NcpEndpointEvent, NcpEndpointSubscriber, NcpRequestEnvelope, NcpStreamRequestPayload, NcpMessageAbortPayload } from '@nextclaw/ncp';
2
2
 
3
3
  type FetchLike = (input: URL | string | Request, init?: RequestInit) => Promise<Response>;
4
4
 
@@ -24,8 +24,8 @@ declare class NcpHttpAgentClientEndpoint implements NcpAgentClientEndpoint {
24
24
  emit(event: NcpEndpointEvent): Promise<void>;
25
25
  subscribe(listener: NcpEndpointSubscriber): () => void;
26
26
  send(envelope: NcpRequestEnvelope): Promise<void>;
27
- resume(payload: NcpResumeRequestPayload): Promise<void>;
28
- abort(payload?: NcpMessageAbortPayload): Promise<void>;
27
+ stream(payload: NcpStreamRequestPayload): Promise<void>;
28
+ abort(payload: NcpMessageAbortPayload): Promise<void>;
29
29
  private ensureStarted;
30
30
  private publish;
31
31
  private resolveUrl;
package/dist/index.js CHANGED
@@ -1,3 +1,8 @@
1
+ // src/client.ts
2
+ import {
3
+ NcpEventType
4
+ } from "@nextclaw/ncp";
5
+
1
6
  // src/sse.ts
2
7
  function parseSseFrame(frameText) {
3
8
  const lines = frameText.split(/\r?\n/);
@@ -238,7 +243,7 @@ var NcpHttpAgentClientEndpoint = class {
238
243
  supportsStreaming: true,
239
244
  supportsAbort: true,
240
245
  supportsProactiveMessages: false,
241
- supportsSessionResume: true,
246
+ supportsLiveSessionStream: true,
242
247
  supportedPartTypes: SUPPORTED_PART_TYPES,
243
248
  expectedLatency: "seconds",
244
249
  metadata: { transport: "http+sse", scope: "agent" }
@@ -249,7 +254,7 @@ var NcpHttpAgentClientEndpoint = class {
249
254
  return;
250
255
  }
251
256
  this.started = true;
252
- this.publish({ type: "endpoint.ready" });
257
+ this.publish({ type: NcpEventType.EndpointReady });
253
258
  }
254
259
  async stop() {
255
260
  if (!this.started) {
@@ -266,8 +271,8 @@ var NcpHttpAgentClientEndpoint = class {
266
271
  case "message.request":
267
272
  await this.send(event.payload);
268
273
  return;
269
- case "message.resume-request":
270
- await this.resume(event.payload);
274
+ case "message.stream-request":
275
+ await this.stream(event.payload);
271
276
  return;
272
277
  case "message.abort":
273
278
  await this.abort(event.payload);
@@ -291,21 +296,17 @@ var NcpHttpAgentClientEndpoint = class {
291
296
  body: envelope
292
297
  });
293
298
  }
294
- async resume(payload) {
299
+ async stream(payload) {
295
300
  await this.ensureStarted();
296
301
  const query = new URLSearchParams({
297
- sessionId: payload.sessionId,
298
- remoteRunId: payload.remoteRunId
302
+ sessionId: payload.sessionId
299
303
  });
300
- if (typeof payload.fromEventIndex === "number" && Number.isFinite(payload.fromEventIndex)) {
301
- query.set("fromEventIndex", String(Math.max(0, Math.trunc(payload.fromEventIndex))));
302
- }
303
304
  await this.streamRequest({
304
- path: `/reconnect?${query.toString()}`,
305
+ path: `/stream?${query.toString()}`,
305
306
  method: "GET"
306
307
  });
307
308
  }
308
- async abort(payload = {}) {
309
+ async abort(payload) {
309
310
  await this.ensureStarted();
310
311
  const controller = new AbortController();
311
312
  this.activeControllers.add(controller);
@@ -330,7 +331,7 @@ var NcpHttpAgentClientEndpoint = class {
330
331
  return;
331
332
  }
332
333
  const ncpError = toNcpError(error);
333
- this.publish({ type: "endpoint.error", payload: ncpError });
334
+ this.publish({ type: NcpEventType.EndpointError, payload: ncpError });
334
335
  throw ncpErrorToError(ncpError);
335
336
  } finally {
336
337
  this.activeControllers.delete(controller);
@@ -385,7 +386,7 @@ var NcpHttpAgentClientEndpoint = class {
385
386
  throw error;
386
387
  }
387
388
  const ncpError = toNcpError(error);
388
- this.publish({ type: "endpoint.error", payload: ncpError });
389
+ this.publish({ type: NcpEventType.EndpointError, payload: ncpError });
389
390
  throw ncpErrorToError(ncpError);
390
391
  } finally {
391
392
  this.activeControllers.delete(controller);
@@ -396,7 +397,7 @@ var NcpHttpAgentClientEndpoint = class {
396
397
  const event = parseNcpEvent(frame.data);
397
398
  if (!event) {
398
399
  this.publish({
399
- type: "endpoint.error",
400
+ type: NcpEventType.EndpointError,
400
401
  payload: {
401
402
  code: "runtime-error",
402
403
  message: "Received malformed ncp-event frame."
@@ -409,7 +410,7 @@ var NcpHttpAgentClientEndpoint = class {
409
410
  }
410
411
  if (frame.event === "error") {
411
412
  const ncpError = parseNcpError(frame.data);
412
- this.publish({ type: "endpoint.error", payload: ncpError });
413
+ this.publish({ type: NcpEventType.EndpointError, payload: ncpError });
413
414
  throw ncpErrorToError(ncpError, { alreadyPublished: true });
414
415
  }
415
416
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nextclaw/ncp-http-agent-client",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "private": false,
5
5
  "description": "HTTP/SSE client transport adapter for NCP agent endpoints.",
6
6
  "type": "module",
@@ -15,14 +15,10 @@
15
15
  "dist"
16
16
  ],
17
17
  "dependencies": {
18
- "@nextclaw/ncp": "0.1.0"
18
+ "@nextclaw/ncp": "0.2.0"
19
19
  },
20
20
  "devDependencies": {
21
21
  "@types/node": "^20.17.6",
22
- "@typescript-eslint/eslint-plugin": "^7.18.0",
23
- "@typescript-eslint/parser": "^7.18.0",
24
- "eslint": "^8.57.1",
25
- "eslint-config-prettier": "^9.1.0",
26
22
  "prettier": "^3.3.3",
27
23
  "tsup": "^8.3.5",
28
24
  "typescript": "^5.6.3",