@blocksdiy/blocks-client-sdk 1.19.0 → 1.21.0
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/ClientSdk.d.ts +2 -0
- package/dist/ClientSdk.d.ts.map +1 -1
- package/dist/ClientSdk.js +11 -2
- package/dist/ReactClientSdk.d.ts +39 -0
- package/dist/ReactClientSdk.d.ts.map +1 -1
- package/dist/ReactClientSdk.jsx +77 -9
- package/package.json +4 -4
package/dist/ClientSdk.d.ts
CHANGED
|
@@ -17,6 +17,7 @@ import { Page, type PageConfig } from "./Page.js";
|
|
|
17
17
|
* @property {string} [permission] - The user's permission level: 'build' (can modify app) or 'use' (read-only) (optional)
|
|
18
18
|
* @property {number} [accountId] - The id of the account the user belongs to (optional, must exist if user is authenticated)
|
|
19
19
|
* @property {boolean} [isAuthenticated] - Whether the user is authenticated
|
|
20
|
+
* @property {string} [timeZone] - The viewer's IANA time zone from the browser, e.g. "Asia/Jerusalem" (optional: unset where the browser can't tell)
|
|
20
21
|
*/
|
|
21
22
|
export interface User {
|
|
22
23
|
id?: string;
|
|
@@ -29,6 +30,7 @@ export interface User {
|
|
|
29
30
|
permission?: "build" | "use";
|
|
30
31
|
accountId?: number;
|
|
31
32
|
isAuthenticated: boolean;
|
|
33
|
+
timeZone?: string;
|
|
32
34
|
}
|
|
33
35
|
export interface UpdateUserOptions {
|
|
34
36
|
clientOnly?: boolean;
|
package/dist/ClientSdk.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ClientSdk.d.ts","sourceRoot":"","sources":["../src/ClientSdk.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,MAAM,EAAE,KAAK,YAAY,EAAE,MAAM,UAAU,CAAC;AACrD,OAAO,EAAE,KAAK,EAAE,KAAK,WAAW,EAAE,MAAM,SAAS,CAAC;AAClD,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAEzD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,KAAK,CAAC,EAAE,CAAC;IAGxD;;;;;OAKG;IACH,mBAAmB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAK7D;;;;;;;;;;;;;;;;OAgBG;IACH,SAAS,CAAC,GAAG,SAAS,eAAe,GAAG,eAAe,EAAE,eAAe,EAAE,GAAG,GAQhB,SAAS,CAAC,GAAG,CAAC;YAG7D,YAAY;IAiCpB,MAAM,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE,UAAU,EAAE,EAAE;QAAE,UAAU,EAAE,CAAC,UAAU,EAAE,MAAM,KAAK,IAAI,CAAA;KAAE,GAAG,OAAO,CAAC,MAAM,CAAC;IAyCvG;;;;;;;;;;;;;OAaG;IACH,OAAO;IAIP;;;;;;;;;;;;;;;OAeG;IACH,IAAI,YAAY,IAAI,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,WAAW,GAAG,SAAS,CAAC,CAAC,CAEpE;IAED;;;;;;;;;OASG;IACH,gBAAgB,IAAI,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,WAAW,GAAG,SAAS,CAAC,CAAC,CAAC;YAOhE,iBAAiB;IAyB/B;;;;;;;;;;OAUG;IACG,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,iBAAsB;IAoBlF;;;;;;;;;;;;;;;;;;;;;;;;;;;OA2BG;IACG,aAAa,CAAC,EAAE,KAAK,EAAE,EAAE;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE;IAmBhD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAiCG;IACH,iBAAiB;CAGlB"}
|
package/dist/ClientSdk.js
CHANGED
|
@@ -9,6 +9,15 @@ import { resolveAgentBlockId } from "./AgentRef.js";
|
|
|
9
9
|
import { Entity } from "./Entity.js";
|
|
10
10
|
import { Integration } from "./Integration.js";
|
|
11
11
|
import { Page } from "./Page.js";
|
|
12
|
+
/** The viewer's IANA time zone, from the browser (where the user is now); undefined where it can't be read. */
|
|
13
|
+
const viewerTimeZone = () => {
|
|
14
|
+
try {
|
|
15
|
+
return Intl.DateTimeFormat().resolvedOptions().timeZone || undefined;
|
|
16
|
+
}
|
|
17
|
+
catch {
|
|
18
|
+
return undefined;
|
|
19
|
+
}
|
|
20
|
+
};
|
|
12
21
|
/**
|
|
13
22
|
* Main client SDK for interacting with entities, actions, and pages
|
|
14
23
|
*
|
|
@@ -64,7 +73,7 @@ export class ClientSdk {
|
|
|
64
73
|
headers,
|
|
65
74
|
});
|
|
66
75
|
const { user } = await response.json();
|
|
67
|
-
this.user = { ...(user || {}), isAuthenticated: !!user };
|
|
76
|
+
this.user = { ...(user || {}), isAuthenticated: !!user, timeZone: viewerTimeZone() };
|
|
68
77
|
}
|
|
69
78
|
/**
|
|
70
79
|
* Takes the current user as already known — the `safe-users/current` answer `authenticate()`
|
|
@@ -73,7 +82,7 @@ export class ClientSdk {
|
|
|
73
82
|
* @internal
|
|
74
83
|
*/
|
|
75
84
|
setAuthenticatedUser(user) {
|
|
76
|
-
this.user = { ...user, isAuthenticated: true };
|
|
85
|
+
this.user = { ...user, isAuthenticated: true, timeZone: viewerTimeZone() };
|
|
77
86
|
}
|
|
78
87
|
/**
|
|
79
88
|
* Gets or creates an Entity instance for the specified entity configuration
|
package/dist/ReactClientSdk.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type AgentContext, type AgentContextShare, type AgentScreenRead } from "@blocksdiy/react-common/agent-threads";
|
|
1
2
|
import type { ActionConfig } from "./Action.js";
|
|
2
3
|
import type { AgentConfig } from "./Agent.js";
|
|
3
4
|
import type { AgentChatConfig } from "./AgentChat.js";
|
|
@@ -594,6 +595,44 @@ export declare const useAgentChat: <ACC extends AgentChatConfig = AgentChatConfi
|
|
|
594
595
|
* ```
|
|
595
596
|
*/
|
|
596
597
|
export declare const useAgent: <AC extends AgentConfig = AgentConfig>(agentConfig: AC) => import("./Agent.js").Agent<AC>;
|
|
598
|
+
export type { AgentContext, AgentContextShare, AgentScreenRead };
|
|
599
|
+
/**
|
|
600
|
+
* Hook to share a component's state with the floating agent chat while it is mounted.
|
|
601
|
+
*
|
|
602
|
+
* Every floating agent chat turn carries it under the component's name:
|
|
603
|
+
* `useAgentContext('RevenueChart', { total })` shows the agent `RevenueChart: [{ total }]`, one
|
|
604
|
+
* entry per mounted instance. Those turns carry the URL and every mounted `useEntityGetAll` /
|
|
605
|
+
* `useEntityGetOne` already, so share only what they don't: a computed total, the selection
|
|
606
|
+
* (ids), a dialog's step, a draft. A few keys, as the user sees them; never per list row. The
|
|
607
|
+
* share follows its content (an inline literal is fine) and goes away on unmount; a value that is
|
|
608
|
+
* not JSON-serializable is left out.
|
|
609
|
+
*
|
|
610
|
+
* @param {string} name - The component's name, as the agent will see it
|
|
611
|
+
* @param {AgentContext} context - What it shares: a small JSON-serializable object
|
|
612
|
+
* @example
|
|
613
|
+
* ```tsx
|
|
614
|
+
* import { useAgentContext } from '@blocksdiy/blocks-client-sdk/reactSdk';
|
|
615
|
+
*
|
|
616
|
+
* function RevenueChart({ invoices }) {
|
|
617
|
+
* const total = invoices.reduce((sum, invoice) => sum + invoice.amount, 0);
|
|
618
|
+
* useAgentContext('RevenueChart', { total, invoices: invoices.length });
|
|
619
|
+
* // ...
|
|
620
|
+
* }
|
|
621
|
+
* ```
|
|
622
|
+
*/
|
|
623
|
+
export declare const useAgentContext: (name: string, context: AgentContext) => void;
|
|
624
|
+
/**
|
|
625
|
+
* Hook to read what the app's pages tell its agents, live — for a chat surface that sends it with
|
|
626
|
+
* every turn (the floating agent chat does): `shared`, what components share through
|
|
627
|
+
* {@link useAgentContext}, and `onScreen`, what the page's entity reads have on screen, each in
|
|
628
|
+
* mount order. Pages never need this.
|
|
629
|
+
*
|
|
630
|
+
* @returns {{ shared: readonly AgentContextShare[], onScreen: readonly AgentScreenRead[] }} Each array the same until one of its entries changes
|
|
631
|
+
*/
|
|
632
|
+
export declare const useAgentContextEntries: () => {
|
|
633
|
+
shared: readonly AgentContextShare[];
|
|
634
|
+
onScreen: readonly AgentScreenRead[];
|
|
635
|
+
};
|
|
597
636
|
/**
|
|
598
637
|
* Hook to tell whether an agent id recorded by the platform is a given agent.
|
|
599
638
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ReactClientSdk.d.ts","sourceRoot":"","sources":["../src/ReactClientSdk.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ReactClientSdk.d.ts","sourceRoot":"","sources":["../src/ReactClientSdk.tsx"],"names":[],"mappings":"AAIA,OAAO,EACL,KAAK,YAAY,EACjB,KAAK,iBAAiB,EAEtB,KAAK,eAAe,EAIrB,MAAM,uCAAuC,CAAC;AAY/C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAC7C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAC3C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAEnD,OAAO,EAAE,SAAS,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAC3D,OAAO,KAAK,EAAE,iBAAiB,EAAE,YAAY,EAAE,UAAU,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AAenG,OAAO,EAAmB,KAAK,WAAW,EAAiB,MAAM,eAAe,CAAC;AACjF,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAEzC,qBAAa,cAAe,SAAQ,SAAS;CAAG;AA6EhD,oBAAY,iBAAiB;IAC3B,eAAe,oBAAoB;IACnC,eAAe,oBAAoB;IACnC,eAAe,oBAAoB;CACpC;AA+ID;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,eAAO,MAAM,cAAc,GAAI,gDAK5B;IACD,MAAM,EAAE,cAAc,CAAC;IACvB,QAA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IhE,CAAC;AACF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuDG;AACH,eAAO,MAAM,iBAAiB,GAAI,cAAa;IAAE,OAAO,CAAC,EAAE,iBAAiB,CAAA;CAAO;;gBAWtC,MAAM;cAAQ,MAAM;;;;;CAwBhE,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6CG;AACH,eAAO,MAAM,gBAAgB;+BAOP;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE;;;;CAmBtC,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,eAAO,MAAM,cAAc,cAG1B,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,aAAa,GAAI,EAAE,SAAS,UAAU,GAAG,UAAU,EAAE,YAAY,EAAE,2BAS/E,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,UAAU,GAAI,EAAE,SAAS,UAAU,GAAG,UAAU,EAAE,YAAY,EAAE,WAI5E,CAAC"}
|
package/dist/ReactClientSdk.jsx
CHANGED
|
@@ -2,6 +2,7 @@ import { AppVersionService } from "@blocksdiy/blocks-client-api/appVersionServic
|
|
|
2
2
|
import { FatalAppError } from "@blocksdiy/blocks-client-api/errors";
|
|
3
3
|
import { useWebsockets, useWebsocketsAppSubscribe } from "@blocksdiy/blocks-client-api/websocketService";
|
|
4
4
|
import { websocketsService } from "@blocksdiy/blocks-client-api/websocketService";
|
|
5
|
+
import { createAgentContextStore, useAgentContextRegistration, useAgentContextValues, } from "@blocksdiy/react-common/agent-threads";
|
|
5
6
|
import { useAiStreamChunks } from "@blocksdiy/react-common/useAiStreamChunks";
|
|
6
7
|
import { QueryClient, QueryClientProvider, useInfiniteQuery, useMutation, useQuery, useQueryClient, } from "@tanstack/react-query";
|
|
7
8
|
import { createContext, useCallback, useContext, useEffect, useMemo, useState } from "react";
|
|
@@ -20,6 +21,21 @@ const INTEGRATIONS_STALE_TIME = 30_000;
|
|
|
20
21
|
// Avoids redundant refetches on quick remounts and window focus flaps without meaningfully delaying anything.
|
|
21
22
|
const ENTITIES_STALE_TIME = 5_000;
|
|
22
23
|
const ClientContext = createContext(null);
|
|
24
|
+
const AgentContextStoresContext = createContext(null);
|
|
25
|
+
const useAgentContextStores = () => {
|
|
26
|
+
const stores = useContext(AgentContextStoresContext);
|
|
27
|
+
if (!stores) {
|
|
28
|
+
throw new Error("Client not found");
|
|
29
|
+
}
|
|
30
|
+
return stores;
|
|
31
|
+
};
|
|
32
|
+
// What a read has on screen, for the app's agents, while it is on screen: replaced in place as
|
|
33
|
+
// the query changes, withdrawn with this read alone when it is disabled or unmounts.
|
|
34
|
+
const useOnScreenRead = (table, query, isOnScreen) => {
|
|
35
|
+
const { onScreen } = useAgentContextStores();
|
|
36
|
+
const read = useMemo(() => (isOnScreen ? { table, query } : null), [table, query, isOnScreen]);
|
|
37
|
+
useAgentContextRegistration(onScreen, read);
|
|
38
|
+
};
|
|
23
39
|
const ThemeModeContext = createContext({
|
|
24
40
|
themeMode: "system",
|
|
25
41
|
setThemeMode: () => { },
|
|
@@ -178,6 +194,10 @@ export const ClientProvider = ({ client, children, themeMode, setThemeMode, }) =
|
|
|
178
194
|
},
|
|
179
195
|
},
|
|
180
196
|
}));
|
|
197
|
+
const [agentContextStores] = useState(() => ({
|
|
198
|
+
shared: createAgentContextStore(),
|
|
199
|
+
onScreen: createAgentContextStore(),
|
|
200
|
+
}));
|
|
181
201
|
const user = client.getUser();
|
|
182
202
|
const userIdInNumber = useMemo(() => {
|
|
183
203
|
if (user?.id) {
|
|
@@ -211,15 +231,17 @@ export const ClientProvider = ({ client, children, themeMode, setThemeMode, }) =
|
|
|
211
231
|
};
|
|
212
232
|
}, [queryClient, client]);
|
|
213
233
|
return (<ClientContext value={client}>
|
|
214
|
-
<
|
|
215
|
-
|
|
216
|
-
{
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
234
|
+
<AgentContextStoresContext value={agentContextStores}>
|
|
235
|
+
<ThemeModeContext value={{ themeMode, setThemeMode }}>
|
|
236
|
+
{/* <QueryClientProvider client={queryClient}>
|
|
237
|
+
{children}
|
|
238
|
+
{user.id !== undefined || client.token ? (
|
|
239
|
+
<WebsocketsSync userId={user.id} token={client.token} appId={client.appId} />
|
|
240
|
+
) : null}
|
|
241
|
+
</QueryClientProvider> */}
|
|
242
|
+
<QueryClientProvider client={queryClient}>{children}</QueryClientProvider>
|
|
243
|
+
</ThemeModeContext>
|
|
244
|
+
</AgentContextStoresContext>
|
|
223
245
|
</ClientContext>);
|
|
224
246
|
};
|
|
225
247
|
/**
|
|
@@ -325,6 +347,8 @@ export const useEntityGetAll = (entityConfig, query, queryOptions = {}) => {
|
|
|
325
347
|
const active = pagedQuery ? pages : list;
|
|
326
348
|
const data = (pagedQuery ? pagedData : list.data);
|
|
327
349
|
const { isLoading, error, isError, isFetched, isFetching, isSuccess, status } = active;
|
|
350
|
+
// On screen for the app's agents once its rows are here; a disabled read shows nothing.
|
|
351
|
+
useOnScreenRead(entityConfig.tableBlockId, query, enabled && data !== undefined);
|
|
328
352
|
const hasNextPage = !!pagedQuery && pages.hasNextPage;
|
|
329
353
|
const { fetchNextPage: fetchNextPageQuery, isFetchingNextPage } = pages;
|
|
330
354
|
const fetchNextPage = useCallback(() => {
|
|
@@ -401,6 +425,8 @@ export const useEntityGetOne = (entityConfig, filters, queryOptions = {}) => {
|
|
|
401
425
|
enabled,
|
|
402
426
|
initialData,
|
|
403
427
|
});
|
|
428
|
+
// On screen for the app's agents once the record is found; a disabled read shows nothing.
|
|
429
|
+
useOnScreenRead(entityConfig.tableBlockId, finalFilters, enabled !== false && !!data);
|
|
404
430
|
return {
|
|
405
431
|
data,
|
|
406
432
|
isLoading,
|
|
@@ -973,6 +999,48 @@ export const useAgent = (agentConfig) => {
|
|
|
973
999
|
const client = useClient();
|
|
974
1000
|
return client.agent(agentConfig);
|
|
975
1001
|
};
|
|
1002
|
+
/**
|
|
1003
|
+
* Hook to share a component's state with the floating agent chat while it is mounted.
|
|
1004
|
+
*
|
|
1005
|
+
* Every floating agent chat turn carries it under the component's name:
|
|
1006
|
+
* `useAgentContext('RevenueChart', { total })` shows the agent `RevenueChart: [{ total }]`, one
|
|
1007
|
+
* entry per mounted instance. Those turns carry the URL and every mounted `useEntityGetAll` /
|
|
1008
|
+
* `useEntityGetOne` already, so share only what they don't: a computed total, the selection
|
|
1009
|
+
* (ids), a dialog's step, a draft. A few keys, as the user sees them; never per list row. The
|
|
1010
|
+
* share follows its content (an inline literal is fine) and goes away on unmount; a value that is
|
|
1011
|
+
* not JSON-serializable is left out.
|
|
1012
|
+
*
|
|
1013
|
+
* @param {string} name - The component's name, as the agent will see it
|
|
1014
|
+
* @param {AgentContext} context - What it shares: a small JSON-serializable object
|
|
1015
|
+
* @example
|
|
1016
|
+
* ```tsx
|
|
1017
|
+
* import { useAgentContext } from '@blocksdiy/blocks-client-sdk/reactSdk';
|
|
1018
|
+
*
|
|
1019
|
+
* function RevenueChart({ invoices }) {
|
|
1020
|
+
* const total = invoices.reduce((sum, invoice) => sum + invoice.amount, 0);
|
|
1021
|
+
* useAgentContext('RevenueChart', { total, invoices: invoices.length });
|
|
1022
|
+
* // ...
|
|
1023
|
+
* }
|
|
1024
|
+
* ```
|
|
1025
|
+
*/
|
|
1026
|
+
export const useAgentContext = (name, context) => {
|
|
1027
|
+
const share = useMemo(() => ({ name, context }), [name, context]);
|
|
1028
|
+
useAgentContextRegistration(useAgentContextStores().shared, share);
|
|
1029
|
+
};
|
|
1030
|
+
/**
|
|
1031
|
+
* Hook to read what the app's pages tell its agents, live — for a chat surface that sends it with
|
|
1032
|
+
* every turn (the floating agent chat does): `shared`, what components share through
|
|
1033
|
+
* {@link useAgentContext}, and `onScreen`, what the page's entity reads have on screen, each in
|
|
1034
|
+
* mount order. Pages never need this.
|
|
1035
|
+
*
|
|
1036
|
+
* @returns {{ shared: readonly AgentContextShare[], onScreen: readonly AgentScreenRead[] }} Each array the same until one of its entries changes
|
|
1037
|
+
*/
|
|
1038
|
+
export const useAgentContextEntries = () => {
|
|
1039
|
+
const stores = useAgentContextStores();
|
|
1040
|
+
const shared = useAgentContextValues(stores.shared);
|
|
1041
|
+
const onScreen = useAgentContextValues(stores.onScreen);
|
|
1042
|
+
return useMemo(() => ({ shared, onScreen }), [shared, onScreen]);
|
|
1043
|
+
};
|
|
976
1044
|
const AGENT_BLOCK_ID_QUERY_KEY = "agentBlockId";
|
|
977
1045
|
/**
|
|
978
1046
|
* Hook to tell whether an agent id recorded by the platform is a given agent.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blocksdiy/blocks-client-sdk",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.21.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Blocks client sdk",
|
|
6
6
|
"keywords": [],
|
|
@@ -46,8 +46,8 @@
|
|
|
46
46
|
]
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
|
-
"@blocksdiy/blocks-client-api": "1.
|
|
50
|
-
"@blocksdiy/react-common": "1.
|
|
49
|
+
"@blocksdiy/blocks-client-api": "1.27.0",
|
|
50
|
+
"@blocksdiy/react-common": "1.60.0",
|
|
51
51
|
"@tanstack/react-query": "^5.101.0"
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
"typescript": "^5.9.3"
|
|
57
57
|
},
|
|
58
58
|
"engines": {
|
|
59
|
-
"node": ">=24.
|
|
59
|
+
"node": ">=24.22.1"
|
|
60
60
|
},
|
|
61
61
|
"peerDependencies": {
|
|
62
62
|
"react": ">=18"
|