Skip to content

Commit 62a5917

Browse files
committed
chore: add agent header
1 parent 29d0de7 commit 62a5917

19 files changed

Lines changed: 86 additions & 8 deletions

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"name": "replanejs",
33
"private": true,
4+
"type": "module",
45
"description": "Replane JavaScript SDKs monorepo",
56
"scripts": {
67
"build": "pnpm -r build",

packages/next/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
],
1919
"sideEffects": false,
2020
"scripts": {
21+
"prebuild": "node ../../scripts/update-version.js .",
2122
"build": "tsdown",
2223
"dev": "tsdown --watch",
2324
"typecheck": "tsc --noEmit",

packages/next/src/root.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import type { ReactNode } from "react";
77
import { getReplaneSnapshot, type ReplaneClientOptions } from "@replanejs/sdk";
88
import { ReplaneProvider } from "@replanejs/react";
9+
import { DEFAULT_AGENT } from "./version";
910

1011
/**
1112
* Props for ReplaneRoot server component
@@ -50,10 +51,14 @@ export interface ReplaneRootProps<T extends object> {
5051
* ```
5152
*/
5253
export async function ReplaneRoot<T extends object>({ options, children }: ReplaneRootProps<T>) {
53-
const snapshot = await getReplaneSnapshot(options);
54+
const optionsWithAgent = {
55+
...options,
56+
agent: options.agent ?? DEFAULT_AGENT,
57+
};
58+
const snapshot = await getReplaneSnapshot(optionsWithAgent);
5459

5560
return (
56-
<ReplaneProvider options={options} snapshot={snapshot}>
61+
<ReplaneProvider options={optionsWithAgent} snapshot={snapshot}>
5762
{children}
5863
</ReplaneProvider>
5964
);

packages/next/src/version.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// Auto-generated - do not edit manually
2+
export const VERSION = "0.8.8";
3+
export const DEFAULT_AGENT = `replane-next/${VERSION}`;

packages/react/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
],
1919
"sideEffects": false,
2020
"scripts": {
21+
"prebuild": "node ../../scripts/update-version.js .",
2122
"build": "tsdown",
2223
"dev": "tsdown --watch",
2324
"typecheck": "tsc --noEmit",

packages/react/src/provider.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import type {
1212
ReplaneContextValue,
1313
} from "./types";
1414
import { hasClient } from "./types";
15+
import { DEFAULT_AGENT } from "./version";
1516

1617
/**
1718
* Internal provider component for pre-created client.
@@ -47,6 +48,7 @@ function ReplaneProviderWithSnapshot<T extends object>({
4748
retryDelayMs: options.retryDelayMs,
4849
inactivityTimeoutMs: options.inactivityTimeoutMs,
4950
logger: options.logger,
51+
agent: options.agent ?? DEFAULT_AGENT,
5052
},
5153
context: options.context,
5254
}),

packages/react/src/useReplaneClient.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import { useEffect, useRef, useState } from "react";
44
import { createReplaneClient } from "@replanejs/sdk";
55
import type { ReplaneClient, ReplaneClientOptions } from "@replanejs/sdk";
6+
import { DEFAULT_AGENT } from "./version";
67

78
type ClientState<T extends object> =
89
| { status: "loading"; client: null; error: null }
@@ -48,7 +49,10 @@ export function useReplaneClientInternal<T extends object = any>(
4849

4950
async function initClient() {
5051
try {
51-
const client = await createReplaneClient<T>(optionsRef.current);
52+
const client = await createReplaneClient<T>({
53+
...optionsRef.current,
54+
agent: optionsRef.current.agent ?? DEFAULT_AGENT,
55+
});
5256
if (cancelled) {
5357
client.close();
5458
return;
@@ -100,7 +104,10 @@ export function useReplaneClientSuspense<T extends object = any>(
100104
}
101105

102106
// First time - create the promise
103-
const promise = createReplaneClient<T>(options)
107+
const promise = createReplaneClient<T>({
108+
...options,
109+
agent: options.agent ?? DEFAULT_AGENT,
110+
})
104111
.then((client) => {
105112
const entry = suspenseCache.get(cacheKey);
106113
if (entry) {

packages/react/src/version.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// Auto-generated - do not edit manually
2+
export const VERSION = "0.8.8";
3+
export const DEFAULT_AGENT = `replane-react/${VERSION}`;

packages/react/tests/index.spec.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,11 @@ describe("ReplaneProvider with options prop - Client Lifecycle", () => {
409409
);
410410

411411
await waitFor(() => {
412-
expect(mockCreateClient).toHaveBeenCalledWith(defaultTestOptions);
412+
expect(mockCreateClient).toHaveBeenCalledWith(
413+
expect.objectContaining(defaultTestOptions)
414+
);
415+
// Should include the agent property
416+
expect(mockCreateClient.mock.calls[0][0]).toHaveProperty("agent");
413417
});
414418
});
415419

packages/sdk/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
],
4242
"sideEffects": false,
4343
"scripts": {
44+
"prebuild": "node ../../scripts/update-version.js .",
4445
"build": "tsdown",
4546
"dev": "tsdown --watch",
4647
"test": "vitest run",

0 commit comments

Comments
 (0)