Skip to content

The Open Standard for Generative UI

fix: derive observability-cloud SDK_VERSION from package.json at build time (#1070)

abhithesys2fac47a8274d
diff --git a/.changeset/observability-cloud-sdk-version.md b/.changeset/observability-cloud-sdk-version.md
new file mode 100644
index 000000000..e61c1622a
--- /dev/null
+++ b/.changeset/observability-cloud-sdk-version.md
@@ -0,0 +1,7 @@
+---
+"@openuidev/observability-cloud": patch
+---
+
+`SDK_VERSION` is now derived from package.json at build time instead of a
+hardcoded constant that had drifted (wire envelopes previously reported
+`0.0.1` regardless of the released version).
diff --git a/packages/observability-cloud/src/core/wire.ts b/packages/observability-cloud/src/core/wire.ts
index e43beb6f7..80fd362df 100644
--- a/packages/observability-cloud/src/core/wire.ts
+++ b/packages/observability-cloud/src/core/wire.ts
@@ -1,8 +1,10 @@
import type { ObservabilityLevel } from "@openuidev/observability";
import type { StreamWireEvent } from "../events/stream";
-/** Must be kept in sync with packages/observability-cloud/package.json on release. */
-export const SDK_VERSION = "0.0.1";
+declare const __SDK_VERSION__: string;
+
+/** Injected from package.json at build time (tsdown define; vitest.config.ts mirrors it for tests). */
+export const SDK_VERSION = __SDK_VERSION__;
export interface WireEventBase {
id: string;
diff --git a/packages/observability-cloud/tsdown.config.ts b/packages/observability-cloud/tsdown.config.ts
index bd5f1a3e1..cb0f812e6 100644
--- a/packages/observability-cloud/tsdown.config.ts
+++ b/packages/observability-cloud/tsdown.config.ts
@@ -1,7 +1,15 @@
+import { readFileSync } from "node:fs";
import { defineConfig } from "tsdown";
+const { version } = JSON.parse(readFileSync(new URL("./package.json", import.meta.url), "utf8")) as {
+ version: string;
+};
+
export default defineConfig({
entry: ["src/index.ts"],
+ define: {
+ __SDK_VERSION__: JSON.stringify(version),
+ },
format: ["esm", "cjs"],
dts: true,
sourcemap: true,
diff --git a/packages/observability-cloud/vitest.config.ts b/packages/observability-cloud/vitest.config.ts
new file mode 100644
index 000000000..008cd2ae6
--- /dev/null
+++ b/packages/observability-cloud/vitest.config.ts
@@ -0,0 +1,13 @@
+import { readFileSync } from "node:fs";
+import { defineConfig } from "vitest/config";
+
+const { version } = JSON.parse(readFileSync(new URL("./package.json", import.meta.url), "utf8")) as {
+ version: string;
+};
+
+export default defineConfig({
+ define: {
+ // Mirrors the tsdown define so src imports resolve SDK_VERSION in tests.
+ __SDK_VERSION__: JSON.stringify(version),
+ },
+});