@nextclaw/ncp-http-agent-server 0.3.9 → 0.3.11

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 (2) hide show
  1. package/dist/index.js +31 -41
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -100,18 +100,6 @@ function matchesScope(scope, event) {
100
100
  }
101
101
  return true;
102
102
  }
103
- function isTerminalEvent(event) {
104
- switch (event.type) {
105
- case "message.completed":
106
- case "message.failed":
107
- case "run.finished":
108
- case "run.error":
109
- case "message.abort":
110
- return true;
111
- default:
112
- return false;
113
- }
114
- }
115
103
  function readPayload(event) {
116
104
  if (!("payload" in event)) {
117
105
  return null;
@@ -275,7 +263,6 @@ async function* createForwardSseEvents(options) {
275
263
  let timeoutId = null;
276
264
  let unsubscribe = null;
277
265
  let stopped = false;
278
- let terminalStopScheduled = false;
279
266
  const push = (frame) => {
280
267
  if (!stopped) {
281
268
  queue.push(frame);
@@ -300,7 +287,12 @@ async function* createForwardSseEvents(options) {
300
287
  requestSignal.addEventListener("abort", stop, { once: true });
301
288
  if (timeoutMs !== null) {
302
289
  timeoutId = setTimeout(() => {
303
- push(toErrorFrame("TIMEOUT", "NCP HTTP stream timed out before terminal event."));
290
+ push(
291
+ toErrorFrame(
292
+ "TIMEOUT",
293
+ "NCP HTTP stream timed out before terminal event."
294
+ )
295
+ );
304
296
  stop();
305
297
  }, timeoutMs);
306
298
  }
@@ -309,18 +301,12 @@ async function* createForwardSseEvents(options) {
309
301
  return;
310
302
  }
311
303
  push(toNcpEventFrame(event));
312
- if (isTerminalEvent(event)) {
313
- if (!terminalStopScheduled) {
314
- terminalStopScheduled = true;
315
- queueMicrotask(stop);
316
- }
317
- }
318
304
  });
319
305
  void endpoint.emit(requestEvent).catch((error) => {
320
306
  push(toErrorFrame("EMIT_FAILED", errorMessage(error)));
321
307
  stop();
322
308
  }).finally(() => {
323
- if (!terminalStopScheduled) {
309
+ if (!requestSignal.aborted) {
324
310
  queueMicrotask(stop);
325
311
  }
326
312
  });
@@ -346,9 +332,6 @@ async function* createLiveStreamSseEvents(options) {
346
332
  break;
347
333
  }
348
334
  yield toNcpEventFrame(event);
349
- if (isTerminalEvent(event)) {
350
- break;
351
- }
352
335
  }
353
336
  } catch (error) {
354
337
  yield toErrorFrame("STREAM_SOURCE_FAILED", errorMessage(error));
@@ -361,31 +344,32 @@ var NcpHttpAgentController = class {
361
344
  this.options = options;
362
345
  }
363
346
  async handleSend(request) {
364
- const { agentClientEndpoint, timeoutMs } = this.options;
347
+ const { agentClientEndpoint } = this.options;
365
348
  const envelope = await parseRequestEnvelope(request);
366
349
  if (!envelope) {
367
350
  return jsonResponse(
368
- { ok: false, error: { code: "INVALID_BODY", message: "Invalid NCP request envelope." } },
351
+ {
352
+ ok: false,
353
+ error: {
354
+ code: "INVALID_BODY",
355
+ message: "Invalid NCP request envelope."
356
+ }
357
+ },
369
358
  400
370
359
  );
371
360
  }
372
- return createForwardResponse({
373
- endpoint: agentClientEndpoint,
374
- requestEvent: { type: NcpEventType.MessageRequest, payload: envelope },
375
- requestSignal: request.signal,
376
- timeoutMs,
377
- scope: {
378
- sessionId: envelope.sessionId,
379
- correlationId: envelope.correlationId
380
- }
381
- });
361
+ await agentClientEndpoint.send(envelope);
362
+ return jsonResponse({ ok: true });
382
363
  }
383
364
  async handleStream(request) {
384
- const { agentClientEndpoint, streamProvider, timeoutMs } = this.options;
365
+ const { agentClientEndpoint, streamProvider } = this.options;
385
366
  const streamPayload = parseStreamPayloadFromUrl(request.url);
386
367
  if (!streamPayload) {
387
368
  return jsonResponse(
388
- { ok: false, error: { code: "INVALID_QUERY", message: "sessionId is required." } },
369
+ {
370
+ ok: false,
371
+ error: { code: "INVALID_QUERY", message: "sessionId is required." }
372
+ },
389
373
  400
390
374
  );
391
375
  }
@@ -398,9 +382,12 @@ var NcpHttpAgentController = class {
398
382
  }
399
383
  return createForwardResponse({
400
384
  endpoint: agentClientEndpoint,
401
- requestEvent: { type: NcpEventType.MessageStreamRequest, payload: streamPayload },
385
+ requestEvent: {
386
+ type: NcpEventType.MessageStreamRequest,
387
+ payload: streamPayload
388
+ },
402
389
  requestSignal: request.signal,
403
- timeoutMs,
390
+ timeoutMs: null,
404
391
  scope: {
405
392
  sessionId: streamPayload.sessionId
406
393
  }
@@ -411,7 +398,10 @@ var NcpHttpAgentController = class {
411
398
  const payload = await parseAbortPayload(request);
412
399
  if (!payload) {
413
400
  return jsonResponse(
414
- { ok: false, error: { code: "INVALID_BODY", message: "sessionId is required." } },
401
+ {
402
+ ok: false,
403
+ error: { code: "INVALID_BODY", message: "sessionId is required." }
404
+ },
415
405
  400
416
406
  );
417
407
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nextclaw/ncp-http-agent-server",
3
- "version": "0.3.9",
3
+ "version": "0.3.11",
4
4
  "private": false,
5
5
  "description": "HTTP/SSE server transport adapter for NCP agent endpoints.",
6
6
  "type": "module",
@@ -16,7 +16,7 @@
16
16
  ],
17
17
  "dependencies": {
18
18
  "hono": "^4.9.8",
19
- "@nextclaw/ncp": "0.4.5"
19
+ "@nextclaw/ncp": "0.4.6"
20
20
  },
21
21
  "devDependencies": {
22
22
  "@types/node": "^20.17.6",