@paddockai/react 0.0.0-stage → 0.0.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.
package/dist/index.cjs ADDED
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ PaddockProvider: () => PaddockProvider,
24
+ useSession: () => useSession
25
+ });
26
+ module.exports = __toCommonJS(index_exports);
27
+ var import_react = require("react");
28
+ var import_client = require("@paddockai/client");
29
+ var Defaults = (0, import_react.createContext)({});
30
+ function PaddockProvider({ baseUrl, children }) {
31
+ const value = (0, import_react.useMemo)(() => ({ baseUrl }), [baseUrl]);
32
+ return (0, import_react.createElement)(Defaults.Provider, { value }, children);
33
+ }
34
+ var clients = /* @__PURE__ */ new Map();
35
+ function sharedHandle(baseUrl, token, sessionId) {
36
+ const key = `${baseUrl ?? ""}
37
+ ${token}`;
38
+ let client = clients.get(key);
39
+ if (!client) {
40
+ client = new import_client.PaddockClient(baseUrl === void 0 ? { token } : { token, baseUrl });
41
+ clients.set(key, client);
42
+ }
43
+ return client.session(sessionId);
44
+ }
45
+ var serverSnapshot = () => import_client.initialState;
46
+ function useSession(sessionId, options) {
47
+ const defaults = (0, import_react.useContext)(Defaults);
48
+ const baseUrl = options.baseUrl ?? defaults.baseUrl;
49
+ const handle = (0, import_react.useMemo)(() => sharedHandle(baseUrl, options.token, sessionId), [baseUrl, options.token, sessionId]);
50
+ const subscribe = (0, import_react.useCallback)((onChange) => handle.subscribe(onChange), [handle]);
51
+ const state = (0, import_react.useSyncExternalStore)(subscribe, () => handle.state, serverSnapshot);
52
+ const send = (0, import_react.useCallback)((text) => handle.send(text), [handle]);
53
+ const stop = (0, import_react.useCallback)(() => handle.stop(), [handle]);
54
+ return (0, import_react.useMemo)(() => ({ ...state, send, stop }), [state, send, stop]);
55
+ }
56
+ // Annotate the CommonJS export names for ESM import in node:
57
+ 0 && (module.exports = {
58
+ PaddockProvider,
59
+ useSession
60
+ });
@@ -0,0 +1,25 @@
1
+ import { ReactNode } from 'react';
2
+ import { SessionState, Event } from '@paddockai/client';
3
+ export { ClientMessage, ConnectionState, SessionState } from '@paddockai/client';
4
+
5
+ type PaddockProviderProps = {
6
+ /** The base URL every useSession below uses unless its options name one. */
7
+ baseUrl?: string;
8
+ children?: ReactNode;
9
+ };
10
+ /** Supplies defaults, such as the base URL, to every useSession below it. */
11
+ declare function PaddockProvider({ baseUrl, children }: PaddockProviderProps): ReactNode;
12
+ type UseSessionOptions = {
13
+ /** The session token, sent only in the Authorization header. */
14
+ token: string;
15
+ baseUrl?: string;
16
+ };
17
+ type UseSessionResult = SessionState & {
18
+ send(text: string): Promise<Event>;
19
+ stop(): Promise<Event>;
20
+ };
21
+ /** A session's live state, with send and stop. During server rendering it is the empty state and makes no request. */
22
+ declare function useSession(sessionId: string, options: UseSessionOptions): UseSessionResult;
23
+
24
+ export { PaddockProvider, useSession };
25
+ export type { PaddockProviderProps, UseSessionOptions, UseSessionResult };
@@ -0,0 +1,25 @@
1
+ import { ReactNode } from 'react';
2
+ import { SessionState, Event } from '@paddockai/client';
3
+ export { ClientMessage, ConnectionState, SessionState } from '@paddockai/client';
4
+
5
+ type PaddockProviderProps = {
6
+ /** The base URL every useSession below uses unless its options name one. */
7
+ baseUrl?: string;
8
+ children?: ReactNode;
9
+ };
10
+ /** Supplies defaults, such as the base URL, to every useSession below it. */
11
+ declare function PaddockProvider({ baseUrl, children }: PaddockProviderProps): ReactNode;
12
+ type UseSessionOptions = {
13
+ /** The session token, sent only in the Authorization header. */
14
+ token: string;
15
+ baseUrl?: string;
16
+ };
17
+ type UseSessionResult = SessionState & {
18
+ send(text: string): Promise<Event>;
19
+ stop(): Promise<Event>;
20
+ };
21
+ /** A session's live state, with send and stop. During server rendering it is the empty state and makes no request. */
22
+ declare function useSession(sessionId: string, options: UseSessionOptions): UseSessionResult;
23
+
24
+ export { PaddockProvider, useSession };
25
+ export type { PaddockProviderProps, UseSessionOptions, UseSessionResult };
package/dist/index.js ADDED
@@ -0,0 +1,41 @@
1
+ // src/index.ts
2
+ import {
3
+ createContext,
4
+ createElement,
5
+ useCallback,
6
+ useContext,
7
+ useMemo,
8
+ useSyncExternalStore
9
+ } from "react";
10
+ import { PaddockClient, initialState } from "@paddockai/client";
11
+ var Defaults = createContext({});
12
+ function PaddockProvider({ baseUrl, children }) {
13
+ const value = useMemo(() => ({ baseUrl }), [baseUrl]);
14
+ return createElement(Defaults.Provider, { value }, children);
15
+ }
16
+ var clients = /* @__PURE__ */ new Map();
17
+ function sharedHandle(baseUrl, token, sessionId) {
18
+ const key = `${baseUrl ?? ""}
19
+ ${token}`;
20
+ let client = clients.get(key);
21
+ if (!client) {
22
+ client = new PaddockClient(baseUrl === void 0 ? { token } : { token, baseUrl });
23
+ clients.set(key, client);
24
+ }
25
+ return client.session(sessionId);
26
+ }
27
+ var serverSnapshot = () => initialState;
28
+ function useSession(sessionId, options) {
29
+ const defaults = useContext(Defaults);
30
+ const baseUrl = options.baseUrl ?? defaults.baseUrl;
31
+ const handle = useMemo(() => sharedHandle(baseUrl, options.token, sessionId), [baseUrl, options.token, sessionId]);
32
+ const subscribe = useCallback((onChange) => handle.subscribe(onChange), [handle]);
33
+ const state = useSyncExternalStore(subscribe, () => handle.state, serverSnapshot);
34
+ const send = useCallback((text) => handle.send(text), [handle]);
35
+ const stop = useCallback(() => handle.stop(), [handle]);
36
+ return useMemo(() => ({ ...state, send, stop }), [state, send, stop]);
37
+ }
38
+ export {
39
+ PaddockProvider,
40
+ useSession
41
+ };
package/package.json CHANGED
@@ -1,6 +1,49 @@
1
1
  {
2
2
  "name": "@paddockai/react",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.0.1",
4
+ "description": "React bindings of the paddock client SDK: PaddockProvider and useSession.",
5
+ "license": "Apache-2.0",
6
+ "type": "module",
7
+ "main": "./dist/index.cjs",
8
+ "module": "./dist/index.js",
9
+ "types": "./dist/index.d.ts",
10
+ "exports": {
11
+ ".": {
12
+ "import": {
13
+ "types": "./dist/index.d.ts",
14
+ "default": "./dist/index.js"
15
+ },
16
+ "require": {
17
+ "types": "./dist/index.d.cts",
18
+ "default": "./dist/index.cjs"
19
+ }
20
+ }
21
+ },
22
+ "files": [
23
+ "dist"
24
+ ],
25
+ "dependencies": {
26
+ "@paddockai/client": "0.0.1"
27
+ },
28
+ "peerDependencies": {
29
+ "react": "^18.0.0 || ^19.0.0"
30
+ },
31
+ "devDependencies": {
32
+ "@testing-library/react": "16.3.3",
33
+ "@types/react": "19.3.0",
34
+ "@types/react-dom": "19.3.0",
35
+ "jsdom": "31.0.1",
36
+ "react": "19.3.1",
37
+ "react-dom": "19.3.1"
38
+ },
39
+ "repository": {
40
+ "type": "git",
41
+ "url": "git+https://github.com/wenfengwang/paddock.git",
42
+ "directory": "sdk/js/packages/react"
43
+ },
44
+ "scripts": {
45
+ "build": "tsup",
46
+ "test": "vitest run",
47
+ "lint": "eslint . && tsc -p tsconfig.json"
48
+ }
6
49
  }
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.