@blocksdiy/blocks-client-sdk 1.7.0 → 1.8.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/Action.d.ts +6 -43
- package/dist/Action.d.ts.map +1 -1
- package/dist/Action.js +6 -43
- package/dist/Agent.d.ts +43 -0
- package/dist/Agent.d.ts.map +1 -0
- package/dist/Agent.js +37 -0
- package/dist/ClientSdk.d.ts +17 -59
- package/dist/ClientSdk.d.ts.map +1 -1
- package/dist/ClientSdk.js +23 -59
- package/dist/Entity.d.ts +14 -79
- package/dist/Entity.d.ts.map +1 -1
- package/dist/Entity.js +14 -79
- package/dist/ReactClientSdk.d.ts +43 -99
- package/dist/ReactClientSdk.d.ts.map +1 -1
- package/dist/ReactClientSdk.jsx +45 -99
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/package.json +2 -2
package/dist/ReactClientSdk.jsx
CHANGED
|
@@ -252,17 +252,10 @@ export const useClient = () => {
|
|
|
252
252
|
* @returns {string} returns.status - Current status of the query: 'idle', 'loading', 'success', 'error', or 'pending'
|
|
253
253
|
* @example
|
|
254
254
|
* ```tsx
|
|
255
|
-
*
|
|
256
|
-
* const itemConfig = {
|
|
257
|
-
* tableBlockId: 'items-table',
|
|
258
|
-
* instanceType: {} as {
|
|
259
|
-
* name: string;
|
|
260
|
-
* price: number;
|
|
261
|
-
* }
|
|
262
|
-
* };
|
|
255
|
+
* import { ItemEntity } from '@/product-types';
|
|
263
256
|
*
|
|
264
257
|
* function ItemsList() {
|
|
265
|
-
* const { data: items, isLoading } = useEntityGetAll(
|
|
258
|
+
* const { data: items, isLoading } = useEntityGetAll(ItemEntity);
|
|
266
259
|
*
|
|
267
260
|
* if (isLoading) return <div>Loading...</div>;
|
|
268
261
|
* return (
|
|
@@ -319,14 +312,7 @@ export const useEntityGetAll = (entityConfig, filters, queryOptions = {}) => {
|
|
|
319
312
|
* @returns {string} returns.status - Current status of the query: 'idle', 'loading', 'success', 'error', or 'pending'
|
|
320
313
|
* @example
|
|
321
314
|
* ```tsx
|
|
322
|
-
*
|
|
323
|
-
* const userConfig = {
|
|
324
|
-
* tableBlockId: 'users-table',
|
|
325
|
-
* instanceType: {} as {
|
|
326
|
-
* name: string;
|
|
327
|
-
* email: string;
|
|
328
|
-
* }
|
|
329
|
-
* };
|
|
315
|
+
* import { UserEntity } from '@/product-types';
|
|
330
316
|
*
|
|
331
317
|
* function UserProfile({ userEmail }) {
|
|
332
318
|
* const { data: user, isLoading } = useEntityGetOne(UserEntity, { email: userEmail });
|
|
@@ -377,17 +363,10 @@ export const useEntityGetOne = (entityConfig, filters, queryOptions = {}) => {
|
|
|
377
363
|
* @returns {Object} Mutation object with create function, loading state, and error
|
|
378
364
|
* @example
|
|
379
365
|
* ```tsx
|
|
380
|
-
*
|
|
381
|
-
* const userConfig = {
|
|
382
|
-
* tableBlockId: 'users-table',
|
|
383
|
-
* instanceType: {} as {
|
|
384
|
-
* name: string;
|
|
385
|
-
* email: string;
|
|
386
|
-
* }
|
|
387
|
-
* };
|
|
366
|
+
* import { UserEntity } from '@/product-types';
|
|
388
367
|
*
|
|
389
368
|
* function CreateUserForm() {
|
|
390
|
-
* const { createFunction, isLoading } = useEntityCreate(
|
|
369
|
+
* const { createFunction, isLoading } = useEntityCreate(UserEntity);
|
|
391
370
|
* const [name, setName] = useState('');
|
|
392
371
|
* const [email, setEmail] = useState('');
|
|
393
372
|
*
|
|
@@ -445,18 +424,10 @@ export const useEntityCreate = (entityConfig) => {
|
|
|
445
424
|
* @returns {Object} Mutation object with createMany function, loading state, and error
|
|
446
425
|
* @example
|
|
447
426
|
* ```tsx
|
|
448
|
-
*
|
|
449
|
-
* const taskConfig = {
|
|
450
|
-
* tableBlockId: 'tasks-table',
|
|
451
|
-
* instanceType: {} as {
|
|
452
|
-
* title: string;
|
|
453
|
-
* status: 'todo' | 'in_progress' | 'done';
|
|
454
|
-
* assigneeId: string;
|
|
455
|
-
* }
|
|
456
|
-
* };
|
|
427
|
+
* import { TaskEntity } from '@/product-types';
|
|
457
428
|
*
|
|
458
429
|
* function ImportTasksButton() {
|
|
459
|
-
* const { createManyFunction, isLoading } = useEntityCreateMany(
|
|
430
|
+
* const { createManyFunction, isLoading } = useEntityCreateMany(TaskEntity);
|
|
460
431
|
*
|
|
461
432
|
* const handleImport = async () => {
|
|
462
433
|
* const tasksToCreate = [
|
|
@@ -507,17 +478,10 @@ export const useEntityCreateMany = (entityConfig) => {
|
|
|
507
478
|
* @returns {Object} Mutation object with update function, loading state, and error
|
|
508
479
|
* @example
|
|
509
480
|
* ```tsx
|
|
510
|
-
*
|
|
511
|
-
* const userConfig = {
|
|
512
|
-
* tableBlockId: 'users-table',
|
|
513
|
-
* instanceType: {} as {
|
|
514
|
-
* name: string;
|
|
515
|
-
* email: string;
|
|
516
|
-
* }
|
|
517
|
-
* };
|
|
481
|
+
* import { UserEntity } from '@/product-types';
|
|
518
482
|
*
|
|
519
483
|
* function EditUserForm({ user }) {
|
|
520
|
-
* const { updateFunction, isLoading } = useEntityUpdate(
|
|
484
|
+
* const { updateFunction, isLoading } = useEntityUpdate(UserEntity);
|
|
521
485
|
* const [name, setName] = useState(user.name);
|
|
522
486
|
*
|
|
523
487
|
* const handleSubmit = async (e) => {
|
|
@@ -568,17 +532,10 @@ export const useEntityUpdate = (entityConfig) => {
|
|
|
568
532
|
* @returns {Object} Mutation object with delete function, loading state, and error
|
|
569
533
|
* @example
|
|
570
534
|
* ```tsx
|
|
571
|
-
*
|
|
572
|
-
* const userConfig = {
|
|
573
|
-
* tableBlockId: 'users-table',
|
|
574
|
-
* instanceType: {} as {
|
|
575
|
-
* name: string;
|
|
576
|
-
* email: string;
|
|
577
|
-
* }
|
|
578
|
-
* };
|
|
535
|
+
* import { UserEntity } from '@/product-types';
|
|
579
536
|
*
|
|
580
537
|
* function DeleteUserButton({ userId }) {
|
|
581
|
-
* const { deleteFunction, isLoading } = useEntityDelete(
|
|
538
|
+
* const { deleteFunction, isLoading } = useEntityDelete(UserEntity);
|
|
582
539
|
*
|
|
583
540
|
* const handleDelete = async () => {
|
|
584
541
|
* if (confirm('Are you sure?')) {
|
|
@@ -625,17 +582,10 @@ export const useEntityDelete = (entityConfig) => {
|
|
|
625
582
|
* @returns {Object} Mutation object with delete many function, loading state, and error
|
|
626
583
|
* @example
|
|
627
584
|
* ```tsx
|
|
628
|
-
*
|
|
629
|
-
* const userConfig = {
|
|
630
|
-
* tableBlockId: 'users-table',
|
|
631
|
-
* instanceType: {} as {
|
|
632
|
-
* name: string;
|
|
633
|
-
* email: string;
|
|
634
|
-
* }
|
|
635
|
-
* };
|
|
585
|
+
* import { UserEntity } from '@/product-types';
|
|
636
586
|
*
|
|
637
587
|
* function DeleteSelectedUsersButton({ selectedUserIds }) {
|
|
638
|
-
* const { deleteManyFunction, isLoading } = useEntityDeleteMany(
|
|
588
|
+
* const { deleteManyFunction, isLoading } = useEntityDeleteMany(UserEntity);
|
|
639
589
|
*
|
|
640
590
|
* const handleDeleteSelected = async () => {
|
|
641
591
|
* if (confirm(`Delete ${selectedUserIds.length} users?`)) {
|
|
@@ -706,24 +656,10 @@ export const useEntityDeleteMany = (entityConfig) => {
|
|
|
706
656
|
* @returns {Function} returns.clear - Function to clear result and streamResult values
|
|
707
657
|
* @example
|
|
708
658
|
* ```tsx
|
|
709
|
-
*
|
|
710
|
-
* const processPaymentConfig = {
|
|
711
|
-
* actionBlockId: 'process-payment',
|
|
712
|
-
* inputInstanceType: {} as {
|
|
713
|
-
* amount: number;
|
|
714
|
-
* paymentMethod: string;
|
|
715
|
-
* currency: string;
|
|
716
|
-
* },
|
|
717
|
-
* outputInstanceType: {} as {
|
|
718
|
-
* success: boolean;
|
|
719
|
-
* transactionId: string;
|
|
720
|
-
* receiptUrl?: string;
|
|
721
|
-
* error?: string;
|
|
722
|
-
* }
|
|
723
|
-
* };
|
|
659
|
+
* import { ExportDataAction, ProcessPaymentAction } from '@/product-types';
|
|
724
660
|
*
|
|
725
661
|
* function PaymentForm() {
|
|
726
|
-
* const { executeFunction, result, isLoading, error } = useExecuteAction(
|
|
662
|
+
* const { executeFunction, result, isLoading, error } = useExecuteAction(ProcessPaymentAction);
|
|
727
663
|
* const [amount, setAmount] = useState('');
|
|
728
664
|
* const [paymentMethod, setPaymentMethod] = useState('credit_card');
|
|
729
665
|
*
|
|
@@ -761,22 +697,8 @@ export const useEntityDeleteMany = (entityConfig) => {
|
|
|
761
697
|
* );
|
|
762
698
|
* }
|
|
763
699
|
*
|
|
764
|
-
* // Example 2: Data export action (with streaming)
|
|
765
|
-
* const exportDataConfig = {
|
|
766
|
-
* actionBlockId: 'export-data',
|
|
767
|
-
* inputInstanceType: {} as {
|
|
768
|
-
* format: 'csv' | 'json';
|
|
769
|
-
* filters: Record<string, any>;
|
|
770
|
-
* },
|
|
771
|
-
* outputInstanceType: {} as {
|
|
772
|
-
* progress: number;
|
|
773
|
-
* downloadUrl?: string;
|
|
774
|
-
* status: string;
|
|
775
|
-
* }
|
|
776
|
-
* };
|
|
777
|
-
*
|
|
778
700
|
* function DataExportTool() {
|
|
779
|
-
* const { executeFunction, result, isLoading, isDone } = useExecuteAction(
|
|
701
|
+
* const { executeFunction, result, isLoading, isDone } = useExecuteAction(ExportDataAction);
|
|
780
702
|
* const [format, setFormat] = useState<'csv' | 'json'>('csv');
|
|
781
703
|
*
|
|
782
704
|
* const handleExport = async () => {
|
|
@@ -870,13 +792,10 @@ export const useExecuteAction = (actionConfig) => {
|
|
|
870
792
|
* @returns {AgentChat<ACC>} An AgentChat instance for the given configuration
|
|
871
793
|
* @example
|
|
872
794
|
* ```tsx
|
|
873
|
-
*
|
|
874
|
-
* const agentChatConfig = {
|
|
875
|
-
* agentChatId: 'agent-chat-id'
|
|
876
|
-
* };
|
|
795
|
+
* import { CustomerSupportChatAgent } from '@/product-types';
|
|
877
796
|
*
|
|
878
797
|
* function AgentChatComponent() {
|
|
879
|
-
* const agentChat = useAgentChat(
|
|
798
|
+
* const agentChat = useAgentChat(CustomerSupportChatAgent);
|
|
880
799
|
* return <AgentChat agentChat={agentChat} />;
|
|
881
800
|
* }
|
|
882
801
|
* ```
|
|
@@ -885,6 +804,33 @@ export const useAgentChat = (agentChatConfig) => {
|
|
|
885
804
|
const client = useClient();
|
|
886
805
|
return client.agentChat(agentChatConfig);
|
|
887
806
|
};
|
|
807
|
+
/**
|
|
808
|
+
* Hook to get an Agent instance from a generated agent configuration.
|
|
809
|
+
*
|
|
810
|
+
* Import generated agent configs from `@/product-types`, then pass one to
|
|
811
|
+
* `useAgent()` to read typed agent metadata such as name, title, avatarUrl,
|
|
812
|
+
* photoUrl, and harness.
|
|
813
|
+
*
|
|
814
|
+
* @template AC - Agent configuration type
|
|
815
|
+
* @param {AC} agentConfig - Generated agent configuration from product-types
|
|
816
|
+
* @returns {Agent<AC>} An Agent instance for the given configuration
|
|
817
|
+
* @example
|
|
818
|
+
* ```tsx
|
|
819
|
+
* import { useAgent } from '@blocksdiy/blocks-client-sdk/reactSdk';
|
|
820
|
+
* import { CustomerSupportAgent } from '@/product-types';
|
|
821
|
+
*
|
|
822
|
+
* function AgentHeader() {
|
|
823
|
+
* const agent = useAgent(CustomerSupportAgent);
|
|
824
|
+
* const { name, title, avatarUrl, photoUrl } = agent.getAgentProps();
|
|
825
|
+
*
|
|
826
|
+
* return <img src={avatarUrl ?? photoUrl} alt={name} />;
|
|
827
|
+
* }
|
|
828
|
+
* ```
|
|
829
|
+
*/
|
|
830
|
+
export const useAgent = (agentConfig) => {
|
|
831
|
+
const client = useClient();
|
|
832
|
+
return client.agent(agentConfig);
|
|
833
|
+
};
|
|
888
834
|
/**
|
|
889
835
|
* Hook to handle file uploads
|
|
890
836
|
*
|
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC;AACvB,cAAc,kBAAkB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC;AACvB,cAAc,kBAAkB,CAAC"}
|
package/dist/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blocksdiy/blocks-client-sdk",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.8.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Blocks client sdk",
|
|
6
6
|
"keywords": [],
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
"dependencies": {
|
|
49
49
|
"@tanstack/react-query": "^5.90.21",
|
|
50
50
|
"@blocksdiy/blocks-client-api": "1.5.0",
|
|
51
|
-
"@blocksdiy/react-common": "1.
|
|
51
|
+
"@blocksdiy/react-common": "1.5.2"
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
54
54
|
"tsc-alias": "^1.8.10",
|