@runtypelabs/cloudflare-agents 0.1.6 → 0.1.8

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.
@@ -2,7 +2,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_identity = require("./chunk-C3x60FnC.cjs");
3
3
  let cloudflare_workers = require("cloudflare:workers");
4
4
  // package.json
5
- var version = "0.1.6";
5
+ var version = "0.1.8";
6
6
  // src/otlp.ts
7
7
  function otlpValue(value) {
8
8
  if (typeof value === "string") return { stringValue: value };
@@ -466,6 +466,7 @@ var DurableOtlpOutbox = class {
466
466
  bodyHash: entry.bodyHash,
467
467
  expiresAt: now + OUTBOX_RETENTION_MS
468
468
  });
469
+ if ((result.rejected ?? 0) > 0) await recordFailure(transaction, "partial_success");
469
470
  return;
470
471
  }
471
472
  if (result.kind === "reject" || entry.expiresAt <= now) {
@@ -558,6 +559,11 @@ async function boundedResponseText(response) {
558
559
  }
559
560
  return new TextDecoder().decode(joined);
560
561
  }
562
+ /** An OTLP JSON int64 count: a non-negative safe integer, as a number or a decimal string. */
563
+ function otlpCount(value) {
564
+ const count = typeof value === "string" && /^[0-9]+$/.test(value) ? Number(value) : value;
565
+ return typeof count === "number" && Number.isSafeInteger(count) && count >= 0 ? count : void 0;
566
+ }
561
567
  async function classifyDeliveryResponse(response) {
562
568
  if (response.status !== 200) {
563
569
  if (response.status >= 300 && response.status < 400 || response.status === 401 || response.status === 403 || response.status === 408 || response.status === 429 || response.status >= 500) return {
@@ -592,11 +598,19 @@ async function classifyDeliveryResponse(response) {
592
598
  kind: "retry",
593
599
  code: "invalid_success_response"
594
600
  };
595
- const entries = Object.entries(partial);
596
- if (entries.every(([key, value]) => key.startsWith("rejected") && typeof value === "number" && value === 0)) return { kind: "success" };
597
- return entries.some(([key, value]) => key.startsWith("rejected") && typeof value === "number" && value > 0) || entries.length > 0 ? {
598
- kind: "retry",
599
- code: "partial_success"
601
+ let rejected = 0;
602
+ for (const [key, value] of Object.entries(partial)) {
603
+ if (key === "errorMessage" && typeof value === "string") continue;
604
+ const count = key.startsWith("rejected") ? otlpCount(value) : void 0;
605
+ if (count === void 0) return {
606
+ kind: "retry",
607
+ code: "invalid_success_response"
608
+ };
609
+ rejected += count;
610
+ }
611
+ return rejected > 0 ? {
612
+ kind: "success",
613
+ rejected
600
614
  } : { kind: "success" };
601
615
  } catch {
602
616
  return {
@@ -1,7 +1,7 @@
1
1
  import { n as operationSpanId, t as createRunIdentity } from "./chunk-CRTW4njP.mjs";
2
2
  import { DurableObject } from "cloudflare:workers";
3
3
  // package.json
4
- var version = "0.1.6";
4
+ var version = "0.1.8";
5
5
  // src/otlp.ts
6
6
  function otlpValue(value) {
7
7
  if (typeof value === "string") return { stringValue: value };
@@ -465,6 +465,7 @@ var DurableOtlpOutbox = class {
465
465
  bodyHash: entry.bodyHash,
466
466
  expiresAt: now + OUTBOX_RETENTION_MS
467
467
  });
468
+ if ((result.rejected ?? 0) > 0) await recordFailure(transaction, "partial_success");
468
469
  return;
469
470
  }
470
471
  if (result.kind === "reject" || entry.expiresAt <= now) {
@@ -557,6 +558,11 @@ async function boundedResponseText(response) {
557
558
  }
558
559
  return new TextDecoder().decode(joined);
559
560
  }
561
+ /** An OTLP JSON int64 count: a non-negative safe integer, as a number or a decimal string. */
562
+ function otlpCount(value) {
563
+ const count = typeof value === "string" && /^[0-9]+$/.test(value) ? Number(value) : value;
564
+ return typeof count === "number" && Number.isSafeInteger(count) && count >= 0 ? count : void 0;
565
+ }
560
566
  async function classifyDeliveryResponse(response) {
561
567
  if (response.status !== 200) {
562
568
  if (response.status >= 300 && response.status < 400 || response.status === 401 || response.status === 403 || response.status === 408 || response.status === 429 || response.status >= 500) return {
@@ -591,11 +597,19 @@ async function classifyDeliveryResponse(response) {
591
597
  kind: "retry",
592
598
  code: "invalid_success_response"
593
599
  };
594
- const entries = Object.entries(partial);
595
- if (entries.every(([key, value]) => key.startsWith("rejected") && typeof value === "number" && value === 0)) return { kind: "success" };
596
- return entries.some(([key, value]) => key.startsWith("rejected") && typeof value === "number" && value > 0) || entries.length > 0 ? {
597
- kind: "retry",
598
- code: "partial_success"
600
+ let rejected = 0;
601
+ for (const [key, value] of Object.entries(partial)) {
602
+ if (key === "errorMessage" && typeof value === "string") continue;
603
+ const count = key.startsWith("rejected") ? otlpCount(value) : void 0;
604
+ if (count === void 0) return {
605
+ kind: "retry",
606
+ code: "invalid_success_response"
607
+ };
608
+ rejected += count;
609
+ }
610
+ return rejected > 0 ? {
611
+ kind: "success",
612
+ rejected
599
613
  } : { kind: "success" };
600
614
  } catch {
601
615
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@runtypelabs/cloudflare-agents",
3
- "version": "0.1.6",
3
+ "version": "0.1.8",
4
4
  "description": "Durable application telemetry for Cloudflare Agents SDK runs in Runtype.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -28,7 +28,7 @@
28
28
  "LICENSE"
29
29
  ],
30
30
  "devDependencies": {
31
- "@cloudflare/workers-types": "^5.20260804.1",
31
+ "@cloudflare/workers-types": "^5.20261101.1",
32
32
  "ai": "6.0.277",
33
33
  "tsdown": "^0.23.2",
34
34
  "typescript": "^6.0.3",