ns-omp-provider 0.6.0 → 0.6.1

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 +160 -127
  2. package/package.json +3 -3
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- // ns-omp-provider 0.6.0 — bundles @ngosangns/ns-pi-provider@0.5.0 (MIT). See NOTICE.
1
+ // ns-omp-provider 0.6.1 — bundles @ngosangns/ns-pi-provider@0.5.1 (MIT). See NOTICE.
2
2
  import { createRequire as __nsOmpCreateRequire } from 'node:module';
3
3
  const require = __nsOmpCreateRequire(import.meta.url);
4
4
  var __create = Object.create;
@@ -5348,12 +5348,17 @@ function readKiroEventStream(body, options) {
5348
5348
  iterResult = await iterator.next();
5349
5349
  }
5350
5350
  } catch (e) {
5351
+ if (callerSignal?.aborted)
5352
+ throw callerSignal.reason ?? e;
5351
5353
  const kiroError = e?.kiroError;
5352
5354
  if (kiroError)
5353
5355
  outcome.errorData = kiroError;
5354
5356
  outcome.error = e instanceof Error ? e.message : (typeof e === "object" && e !== null ? JSON.stringify(e) : String(e)) || "Unknown stream error";
5355
5357
  return;
5356
5358
  }
5359
+ if (callerSignal?.aborted) {
5360
+ throw callerSignal.reason ?? new Error("Request aborted");
5361
+ }
5357
5362
  const { done, value } = iterResult;
5358
5363
  if (done)
5359
5364
  return;
@@ -9106,6 +9111,8 @@ function streamDevin(request) {
9106
9111
  return streamDevinInProcess(request);
9107
9112
  }
9108
9113
  async function* streamDevinInProcess(request) {
9114
+ if (request.signal?.aborted)
9115
+ throw request.signal.reason ?? new Error("Request aborted");
9109
9116
  const model = request.model;
9110
9117
  const fetchImpl = request.fetch ?? fetch;
9111
9118
  const baseUrl = (model.baseUrl || DEVIN_DEFAULT_BASE_URL).replace(/\/+$/, "");
@@ -9184,143 +9191,169 @@ async function* streamDevinInProcess(request) {
9184
9191
  };
9185
9192
  const reader = new ConnectFrameReader();
9186
9193
  const body = response.body.getReader();
9187
- for (; ; ) {
9188
- const { done, value } = await body.read();
9189
- if (value && value.length > 0)
9190
- reader.push(value);
9194
+ const signal = request.signal;
9195
+ const onAbort = () => {
9196
+ void body.cancel(signal?.reason).catch(() => {
9197
+ });
9198
+ };
9199
+ if (signal?.aborted)
9200
+ onAbort();
9201
+ else
9202
+ signal?.addEventListener("abort", onAbort, { once: true });
9203
+ const abortReason = () => signal?.reason ?? new Error("Request aborted");
9204
+ try {
9191
9205
  for (; ; ) {
9192
- const envelope = reader.next();
9193
- if (envelope === null)
9194
- break;
9195
- if (envelope.endStream) {
9196
- const trailerError = readConnectTrailerError(new TextDecoder().decode(envelope.payload).trim());
9197
- if (trailerError === null)
9198
- continue;
9199
- logger.warn("stream rejected via Connect trailer", {
9200
- model: model.id,
9201
- code: trailerError.code,
9202
- message: trailerError.message,
9203
- ...trailerError.detail ? { detail: trailerError.detail } : {},
9204
- rawTrailer: trailerError.raw,
9205
- requestBytes: requestBytes.byteLength,
9206
- messages: request.messages.length,
9207
- hadOutput: sawAnyToken
9208
- });
9209
- let contextOverflow = false;
9210
- if (!sawAnyToken && trailerError.code.toLowerCase() === "invalid_argument" && /\binternal error\b/i.test(trailerError.message)) {
9211
- const historyBytes = toBinary(GetChatMessageRequestSchema, create(GetChatMessageRequestSchema, {
9212
- chatMessagePrompts: buildChatMessagePrompts(request.messages, turn.cascadeId)
9213
- })).byteLength;
9214
- contextOverflow = historyBytes >= LARGE_HISTORY_RECOVERY_BYTES;
9215
- if (contextOverflow) {
9216
- logger.warn("treating large-history invalid_argument as context overflow", {
9217
- model: model.id,
9218
- historyBytes
9219
- });
9206
+ if (signal?.aborted)
9207
+ throw abortReason();
9208
+ let read;
9209
+ try {
9210
+ read = await body.read();
9211
+ } catch (error2) {
9212
+ if (signal?.aborted)
9213
+ throw abortReason();
9214
+ throw error2;
9215
+ }
9216
+ if (signal?.aborted)
9217
+ throw abortReason();
9218
+ const { done, value } = read;
9219
+ if (value && value.length > 0)
9220
+ reader.push(value);
9221
+ for (; ; ) {
9222
+ const envelope = reader.next();
9223
+ if (envelope === null)
9224
+ break;
9225
+ if (envelope.endStream) {
9226
+ const trailerError = readConnectTrailerError(new TextDecoder().decode(envelope.payload).trim());
9227
+ if (trailerError === null)
9228
+ continue;
9229
+ logger.warn("stream rejected via Connect trailer", {
9230
+ model: model.id,
9231
+ code: trailerError.code,
9232
+ message: trailerError.message,
9233
+ ...trailerError.detail ? { detail: trailerError.detail } : {},
9234
+ rawTrailer: trailerError.raw,
9235
+ requestBytes: requestBytes.byteLength,
9236
+ messages: request.messages.length,
9237
+ hadOutput: sawAnyToken
9238
+ });
9239
+ let contextOverflow = false;
9240
+ if (!sawAnyToken && trailerError.code.toLowerCase() === "invalid_argument" && /\binternal error\b/i.test(trailerError.message)) {
9241
+ const historyBytes = toBinary(GetChatMessageRequestSchema, create(GetChatMessageRequestSchema, {
9242
+ chatMessagePrompts: buildChatMessagePrompts(request.messages, turn.cascadeId)
9243
+ })).byteLength;
9244
+ contextOverflow = historyBytes >= LARGE_HISTORY_RECOVERY_BYTES;
9245
+ if (contextOverflow) {
9246
+ logger.warn("treating large-history invalid_argument as context overflow", {
9247
+ model: model.id,
9248
+ historyBytes
9249
+ });
9250
+ }
9220
9251
  }
9252
+ throw new DevinStreamError(trailerError.formatted, trailerError.code, contextOverflow);
9221
9253
  }
9222
- throw new DevinStreamError(trailerError.formatted, trailerError.code, contextOverflow);
9223
- }
9224
- const msg = fromBinary(GetChatMessageResponseSchema, envelope.payload);
9225
- if (msg.messageId && !responseId)
9226
- responseId = msg.messageId;
9227
- if (msg.actualModelUid)
9228
- upstreamModel = msg.actualModelUid;
9229
- if (msg.deltaThinking) {
9230
- markToken();
9231
- if (openThinking === void 0) {
9232
- openThinking = { index: nextIndex++, text: "" };
9233
- yield { type: "thinking_start", index: openThinking.index };
9234
- }
9235
- openThinking.text += msg.deltaThinking;
9236
- yield { type: "thinking_delta", index: openThinking.index, delta: msg.deltaThinking };
9237
- }
9238
- if (msg.deltaSignature && openThinking !== void 0)
9239
- openThinking.signature = msg.deltaSignature;
9240
- if (msg.deltaText) {
9241
- markToken();
9242
- if (openThinking !== void 0) {
9243
- yield {
9244
- type: "thinking_end",
9245
- index: openThinking.index,
9246
- thinking: openThinking.text,
9247
- ...openThinking.signature ? { signature: openThinking.signature } : {}
9248
- };
9249
- openThinking = void 0;
9254
+ const msg = fromBinary(GetChatMessageResponseSchema, envelope.payload);
9255
+ if (msg.messageId && !responseId)
9256
+ responseId = msg.messageId;
9257
+ if (msg.actualModelUid)
9258
+ upstreamModel = msg.actualModelUid;
9259
+ if (msg.deltaThinking) {
9260
+ markToken();
9261
+ if (openThinking === void 0) {
9262
+ openThinking = { index: nextIndex++, text: "" };
9263
+ yield { type: "thinking_start", index: openThinking.index };
9264
+ }
9265
+ openThinking.text += msg.deltaThinking;
9266
+ yield { type: "thinking_delta", index: openThinking.index, delta: msg.deltaThinking };
9250
9267
  }
9251
- if (openText === void 0) {
9252
- openText = { index: nextIndex++, text: "" };
9253
- yield { type: "text_start", index: openText.index };
9268
+ if (msg.deltaSignature && openThinking !== void 0)
9269
+ openThinking.signature = msg.deltaSignature;
9270
+ if (msg.deltaText) {
9271
+ markToken();
9272
+ if (openThinking !== void 0) {
9273
+ yield {
9274
+ type: "thinking_end",
9275
+ index: openThinking.index,
9276
+ thinking: openThinking.text,
9277
+ ...openThinking.signature ? { signature: openThinking.signature } : {}
9278
+ };
9279
+ openThinking = void 0;
9280
+ }
9281
+ if (openText === void 0) {
9282
+ openText = { index: nextIndex++, text: "" };
9283
+ yield { type: "text_start", index: openText.index };
9284
+ }
9285
+ openText.text += msg.deltaText;
9286
+ yield { type: "text_delta", index: openText.index, delta: msg.deltaText };
9254
9287
  }
9255
- openText.text += msg.deltaText;
9256
- yield { type: "text_delta", index: openText.index, delta: msg.deltaText };
9257
- }
9258
- if (msg.deltaToolCalls.length > 0) {
9259
- markToken();
9260
- if (openText !== void 0) {
9261
- yield { type: "text_end", index: openText.index, text: openText.text };
9262
- openText = void 0;
9288
+ if (msg.deltaToolCalls.length > 0) {
9289
+ markToken();
9290
+ if (openText !== void 0) {
9291
+ yield { type: "text_end", index: openText.index, text: openText.text };
9292
+ openText = void 0;
9293
+ }
9294
+ if (openThinking !== void 0) {
9295
+ yield {
9296
+ type: "thinking_end",
9297
+ index: openThinking.index,
9298
+ thinking: openThinking.text,
9299
+ ...openThinking.signature ? { signature: openThinking.signature } : {}
9300
+ };
9301
+ openThinking = void 0;
9302
+ }
9303
+ for (const call of msg.deltaToolCalls) {
9304
+ const toolCallId = call.id || activeToolCallId;
9305
+ if (!toolCallId)
9306
+ continue;
9307
+ let block = toolBlocks.get(toolCallId);
9308
+ if (block === void 0) {
9309
+ block = { index: nextIndex++, name: call.name };
9310
+ toolBlocks.set(toolCallId, block);
9311
+ toolPartialJson.set(toolCallId, "");
9312
+ yield { type: "tool_call_start", index: block.index, id: toolCallId, name: call.name };
9313
+ }
9314
+ if (call.name)
9315
+ block.name = call.name;
9316
+ activeToolCallId = toolCallId;
9317
+ if (!call.argumentsJson)
9318
+ continue;
9319
+ const previousJson = toolPartialJson.get(toolCallId) ?? "";
9320
+ const accumulated = call.argumentsJson.startsWith(previousJson) ? call.argumentsJson : previousJson + call.argumentsJson;
9321
+ const delta = accumulated.slice(previousJson.length);
9322
+ toolPartialJson.set(toolCallId, accumulated);
9323
+ const throttled = parseStreamingJsonThrottled(accumulated, toolLastParseLen.get(toolCallId) ?? 0);
9324
+ if (throttled)
9325
+ toolLastParseLen.set(toolCallId, throttled.parsedLen);
9326
+ yield { type: "tool_call_delta", index: block.index, id: toolCallId, argumentsDelta: delta };
9327
+ }
9263
9328
  }
9264
- if (openThinking !== void 0) {
9265
- yield {
9266
- type: "thinking_end",
9267
- index: openThinking.index,
9268
- thinking: openThinking.text,
9269
- ...openThinking.signature ? { signature: openThinking.signature } : {}
9329
+ if (msg.stopReason !== StopReason.UNSPECIFIED)
9330
+ latestStopReason = msg.stopReason;
9331
+ if (msg.usage || msg.creditCost || msg.committedCreditCost || msg.committedAcuCost) {
9332
+ const usage = {
9333
+ input: Number(msg.usage?.inputTokens ?? 0n),
9334
+ output: Number(msg.usage?.outputTokens ?? 0n),
9335
+ cacheRead: Number(msg.usage?.cacheReadTokens ?? 0n),
9336
+ cacheWrite: Number(msg.usage?.cacheWriteTokens ?? 0n)
9270
9337
  };
9271
- openThinking = void 0;
9272
- }
9273
- for (const call of msg.deltaToolCalls) {
9274
- const toolCallId = call.id || activeToolCallId;
9275
- if (!toolCallId)
9338
+ const totalTokens = usage.input + usage.output + usage.cacheRead + usage.cacheWrite;
9339
+ const credits = msg.creditCost || msg.committedCreditCost || msg.committedAcuCost;
9340
+ const moved = responseUsage === void 0 ? totalTokens > 0 || credits !== 0 : totalTokens !== responseUsage.totalTokens || credits !== (responseUsage.credits ?? 0);
9341
+ if (!moved)
9276
9342
  continue;
9277
- let block = toolBlocks.get(toolCallId);
9278
- if (block === void 0) {
9279
- block = { index: nextIndex++, name: call.name };
9280
- toolBlocks.set(toolCallId, block);
9281
- toolPartialJson.set(toolCallId, "");
9282
- yield { type: "tool_call_start", index: block.index, id: toolCallId, name: call.name };
9283
- }
9284
- if (call.name)
9285
- block.name = call.name;
9286
- activeToolCallId = toolCallId;
9287
- if (!call.argumentsJson)
9288
- continue;
9289
- const previousJson = toolPartialJson.get(toolCallId) ?? "";
9290
- const accumulated = call.argumentsJson.startsWith(previousJson) ? call.argumentsJson : previousJson + call.argumentsJson;
9291
- const delta = accumulated.slice(previousJson.length);
9292
- toolPartialJson.set(toolCallId, accumulated);
9293
- const throttled = parseStreamingJsonThrottled(accumulated, toolLastParseLen.get(toolCallId) ?? 0);
9294
- if (throttled)
9295
- toolLastParseLen.set(toolCallId, throttled.parsedLen);
9296
- yield { type: "tool_call_delta", index: block.index, id: toolCallId, argumentsDelta: delta };
9343
+ responseUsage = {
9344
+ ...usage,
9345
+ totalTokens,
9346
+ ...credits ? { credits } : {},
9347
+ cost: calculateDevinCost(model.cost, usage)
9348
+ };
9349
+ yield { type: "usage", usage: responseUsage };
9297
9350
  }
9298
9351
  }
9299
- if (msg.stopReason !== StopReason.UNSPECIFIED)
9300
- latestStopReason = msg.stopReason;
9301
- if (msg.usage || msg.creditCost || msg.committedCreditCost || msg.committedAcuCost) {
9302
- const usage = {
9303
- input: Number(msg.usage?.inputTokens ?? 0n),
9304
- output: Number(msg.usage?.outputTokens ?? 0n),
9305
- cacheRead: Number(msg.usage?.cacheReadTokens ?? 0n),
9306
- cacheWrite: Number(msg.usage?.cacheWriteTokens ?? 0n)
9307
- };
9308
- const totalTokens = usage.input + usage.output + usage.cacheRead + usage.cacheWrite;
9309
- const credits = msg.creditCost || msg.committedCreditCost || msg.committedAcuCost;
9310
- const moved = responseUsage === void 0 ? totalTokens > 0 || credits !== 0 : totalTokens !== responseUsage.totalTokens || credits !== (responseUsage.credits ?? 0);
9311
- if (!moved)
9312
- continue;
9313
- responseUsage = {
9314
- ...usage,
9315
- totalTokens,
9316
- ...credits ? { credits } : {},
9317
- cost: calculateDevinCost(model.cost, usage)
9318
- };
9319
- yield { type: "usage", usage: responseUsage };
9320
- }
9352
+ if (done)
9353
+ break;
9321
9354
  }
9322
- if (done)
9323
- break;
9355
+ } finally {
9356
+ signal?.removeEventListener("abort", onAbort);
9324
9357
  }
9325
9358
  if (openText !== void 0) {
9326
9359
  yield { type: "text_end", index: openText.index, text: openText.text };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ns-omp-provider",
3
- "version": "0.6.0",
3
+ "version": "0.6.1",
4
4
  "description": "OMP (oh-my-pi) plugin: Kiro, Devin, and Grok providers from @ngosangns/ns-pi-provider, wrapped for OMP's provider/extension API.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -63,12 +63,12 @@
63
63
  }
64
64
  },
65
65
  "devDependencies": {
66
- "@ngosangns/ns-pi-provider": "0.5.0",
66
+ "@ngosangns/ns-pi-provider": "0.5.1",
67
67
  "@types/node": "^22.18.6",
68
68
  "esbuild": "^0.28.2",
69
69
  "typescript": "^5.9.2",
70
70
  "vitest": "^3.2.4",
71
- "ns-bridge-core": "0.3.0"
71
+ "ns-bridge-core": "0.3.1"
72
72
  },
73
73
  "publishConfig": {
74
74
  "access": "public",