@runtypelabs/cloudflare-agents 0.1.7 → 0.1.9

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.7";
5
+ var version = "0.1.9";
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,4 +1,4 @@
1
- import { a as AdapterToolStartedObservation, m as RunIdentity, n as AdapterModelStepObservation, r as AdapterObservation, t as AdapterModelInputObservation } from "./observer-BVnmkz4i.cjs";
1
+ import { a as AdapterToolStartedObservation, l as RunIdentity, n as AdapterModelStepObservation, r as AdapterObservation, t as AdapterModelInputObservation } from "./observer-CECV5VJd.cjs";
2
2
  import { DurableObject } from "cloudflare:workers";
3
3
  interface AdapterSpan {
4
4
  traceId: string;
@@ -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.7";
4
+ var version = "0.1.9";
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/dist/index.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { _ as operationSpanId, c as observeStreamTextOptions, d as ContentKind, f as ContentPolicy, g as createRunIdentity, h as SubmissionIdentity, i as AdapterObserver, l as CapturedJson, m as RunIdentity, o as AdapterTurn, p as captureContent, r as AdapterObservation, s as ObserveStreamTextOptions, u as ContentDiagnostic } from "./observer-BVnmkz4i.cjs";
1
+ import { _ as captureContent, c as observeStreamTextOptions, d as createRunIdentity, f as operationSpanId, g as ContentPolicy, h as ContentKind, i as AdapterObserver, l as RunIdentity, m as ContentDiagnostic, o as AdapterTurn, p as CapturedJson, r as AdapterObservation, s as ObserveStreamTextOptions, u as SubmissionIdentity } from "./observer-CECV5VJd.cjs";
2
2
  interface DurableObservationSink {
3
3
  observe(observation: AdapterObservation): Promise<{
4
4
  accepted: boolean;
@@ -1,17 +1,4 @@
1
1
  import { streamText } from "ai";
2
- interface SubmissionIdentity {
3
- agentId: string;
4
- submissionId: string;
5
- conversationId: string;
6
- }
7
- interface RunIdentity extends SubmissionIdentity {
8
- traceId: string;
9
- rootSpanId: string;
10
- }
11
- /** Stable producer identity, independent of native traces and export partitioning. */
12
- declare function createRunIdentity(input: SubmissionIdentity): Promise<RunIdentity>;
13
- /** The same operation is encoded with the same span ID on every delivery attempt. */
14
- declare function operationSpanId(traceId: string, operationId: string): Promise<string>;
15
2
  type ContentKind = 'messages' | 'instructions' | 'tools' | 'error';
16
3
  type CapturedJson = null | boolean | number | string | CapturedJson[] | {
17
4
  [key: string]: CapturedJson;
@@ -31,6 +18,19 @@ interface ContentPolicy {
31
18
  }
32
19
  /** Applies privacy policy before a content value can enter telemetry storage. */
33
20
  declare function captureContent(policy: ContentPolicy, kind: ContentKind, value: unknown): CapturedJson | undefined;
21
+ interface SubmissionIdentity {
22
+ agentId: string;
23
+ submissionId: string;
24
+ conversationId: string;
25
+ }
26
+ interface RunIdentity extends SubmissionIdentity {
27
+ traceId: string;
28
+ rootSpanId: string;
29
+ }
30
+ /** Stable producer identity, independent of native traces and export partitioning. */
31
+ declare function createRunIdentity(input: SubmissionIdentity): Promise<RunIdentity>;
32
+ /** The same operation is encoded with the same span ID on every delivery attempt. */
33
+ declare function operationSpanId(traceId: string, operationId: string): Promise<string>;
34
34
  interface AdapterTurn {
35
35
  submissionId: string;
36
36
  conversationId: string;
@@ -111,5 +111,5 @@ interface ObserveStreamTextOptions {
111
111
  }
112
112
  /** Adds bounded observation callbacks without reading or replacing the response stream. */
113
113
  declare function observeStreamTextOptions<Options extends StreamTextOptions>(options: Options, observation: ObserveStreamTextOptions): Promise<Options>;
114
- export { operationSpanId as _, AdapterToolStartedObservation as a, observeStreamTextOptions as c, ContentKind as d, ContentPolicy as f, createRunIdentity as g, SubmissionIdentity as h, AdapterObserver as i, CapturedJson as l, RunIdentity as m, AdapterModelStepObservation as n, AdapterTurn as o, captureContent as p, AdapterObservation as r, ObserveStreamTextOptions as s, AdapterModelInputObservation as t, ContentDiagnostic as u };
114
+ export { captureContent as _, AdapterToolStartedObservation as a, observeStreamTextOptions as c, createRunIdentity as d, operationSpanId as f, ContentPolicy as g, ContentKind as h, AdapterObserver as i, RunIdentity as l, ContentDiagnostic as m, AdapterModelStepObservation as n, AdapterTurn as o, CapturedJson as p, AdapterObservation as r, ObserveStreamTextOptions as s, AdapterModelInputObservation as t, SubmissionIdentity as u };
115
115
  export {}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@runtypelabs/cloudflare-agents",
3
- "version": "0.1.7",
3
+ "version": "0.1.9",
4
4
  "description": "Durable application telemetry for Cloudflare Agents SDK runs in Runtype.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -30,9 +30,9 @@
30
30
  "devDependencies": {
31
31
  "@cloudflare/workers-types": "^5.20261101.1",
32
32
  "ai": "6.0.277",
33
- "tsdown": "^0.23.2",
33
+ "tsdown": "^0.23.7",
34
34
  "typescript": "^6.0.3",
35
- "vitest": "^5.0.5"
35
+ "vitest": "^5.1.0"
36
36
  },
37
37
  "peerDependencies": {
38
38
  "ai": "6.0.277"
@@ -50,7 +50,7 @@
50
50
  "scripts": {
51
51
  "build": "tsdown",
52
52
  "typecheck": "tsrs --noEmit && tsrs -p tsconfig.tests.json --noEmit",
53
- "test": "vitest run",
53
+ "test": "vitest run --passWithNoTests",
54
54
  "lint": "oxlint . --max-warnings 0"
55
55
  }
56
56
  }