@collective-intelligence/external-apps-client-sdk-react 0.1.9 → 0.1.11
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-h3ff4vxf.js → index-cqm78sj8.js} +3 -3
- package/dist/index.d.ts +173 -55
- package/dist/index.js +1 -1
- package/dist/resources.d.ts +62 -3
- package/dist/resources.js +1 -1
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -7,11 +7,22 @@ declare class FederatedAuthError extends Error {
|
|
|
7
7
|
readonly code: FederatedAuthErrorCode;
|
|
8
8
|
constructor(code: FederatedAuthErrorCode, message: string);
|
|
9
9
|
}
|
|
10
|
+
/**
|
|
11
|
+
* The signed-in CI user as the application's BFF reports it: the fields of
|
|
12
|
+
* CI's `/oauth/identity`, read live by the server, plus email and name.
|
|
13
|
+
*/
|
|
10
14
|
export type FederatedSessionIdentity = Readonly<{
|
|
15
|
+
appId: string;
|
|
16
|
+
/** The App Permissions of the user's effective roles. */
|
|
17
|
+
appPermissions: readonly string[];
|
|
11
18
|
email: string | null;
|
|
12
|
-
|
|
19
|
+
/** A person is a member or an External App User of one Organization, never both. */
|
|
20
|
+
kind: "member" | "external_app_user";
|
|
13
21
|
name: string | null;
|
|
14
22
|
organizationId: string;
|
|
23
|
+
/** The user's effective roles on the app. */
|
|
24
|
+
roles: readonly string[];
|
|
25
|
+
userId: string;
|
|
15
26
|
}>;
|
|
16
27
|
export type FederatedAuthState = Readonly<{
|
|
17
28
|
status: "anonymous";
|
|
@@ -43,6 +54,87 @@ export type FederatedAuth = Readonly<{
|
|
|
43
54
|
subscribe: (listener: (state: FederatedAuthState) => void) => () => void;
|
|
44
55
|
}>;
|
|
45
56
|
export type ClientFetch = (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
|
|
57
|
+
export type ExternalApplicationsListAppUsersResponses = {
|
|
58
|
+
/**
|
|
59
|
+
* Success
|
|
60
|
+
*/
|
|
61
|
+
200: {
|
|
62
|
+
correlationId: string;
|
|
63
|
+
result: {
|
|
64
|
+
items: Array<{
|
|
65
|
+
email: string | null;
|
|
66
|
+
name: string | null;
|
|
67
|
+
userId: string;
|
|
68
|
+
}>;
|
|
69
|
+
};
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
export type ExternalApplicationsListAppUsersResponse = ExternalApplicationsListAppUsersResponses[keyof ExternalApplicationsListAppUsersResponses];
|
|
73
|
+
export type ExternalApplicationsCreateOrGetAppUserData = {
|
|
74
|
+
body: {
|
|
75
|
+
email: string;
|
|
76
|
+
name: string;
|
|
77
|
+
roles: Array<string>;
|
|
78
|
+
};
|
|
79
|
+
headers: {
|
|
80
|
+
authorization?: string;
|
|
81
|
+
"x-organization-id": string;
|
|
82
|
+
"x-correlation-id"?: string;
|
|
83
|
+
"x-external-audit-issuer"?: string;
|
|
84
|
+
"x-external-audit-subject"?: string;
|
|
85
|
+
"x-external-caller-kind"?: "anonymous_visitor";
|
|
86
|
+
"x-external-ci-user-id"?: string;
|
|
87
|
+
"x-external-server-role"?: string;
|
|
88
|
+
};
|
|
89
|
+
path?: never;
|
|
90
|
+
query?: never;
|
|
91
|
+
url: "/application/v1/users";
|
|
92
|
+
};
|
|
93
|
+
export type ExternalApplicationsCreateOrGetAppUserResponses = {
|
|
94
|
+
/**
|
|
95
|
+
* Success
|
|
96
|
+
*/
|
|
97
|
+
200: {
|
|
98
|
+
correlationId: string;
|
|
99
|
+
result: {
|
|
100
|
+
email: string | null;
|
|
101
|
+
name: string | null;
|
|
102
|
+
userId: string;
|
|
103
|
+
created: boolean;
|
|
104
|
+
kind: "member" | "external_app_user";
|
|
105
|
+
};
|
|
106
|
+
};
|
|
107
|
+
};
|
|
108
|
+
export type ExternalApplicationsCreateOrGetAppUserResponse = ExternalApplicationsCreateOrGetAppUserResponses[keyof ExternalApplicationsCreateOrGetAppUserResponses];
|
|
109
|
+
export type ExternalApplicationsGetAppUserResponses = {
|
|
110
|
+
/**
|
|
111
|
+
* Success
|
|
112
|
+
*/
|
|
113
|
+
200: {
|
|
114
|
+
correlationId: string;
|
|
115
|
+
result: {
|
|
116
|
+
email: string | null;
|
|
117
|
+
name: string | null;
|
|
118
|
+
userId: string;
|
|
119
|
+
};
|
|
120
|
+
};
|
|
121
|
+
};
|
|
122
|
+
export type ExternalApplicationsGetAppUserResponse = ExternalApplicationsGetAppUserResponses[keyof ExternalApplicationsGetAppUserResponses];
|
|
123
|
+
export type ExternalApplicationsListAppRolesResponses = {
|
|
124
|
+
/**
|
|
125
|
+
* Success
|
|
126
|
+
*/
|
|
127
|
+
200: {
|
|
128
|
+
correlationId: string;
|
|
129
|
+
result: {
|
|
130
|
+
items: Array<{
|
|
131
|
+
id: string;
|
|
132
|
+
key: string;
|
|
133
|
+
}>;
|
|
134
|
+
};
|
|
135
|
+
};
|
|
136
|
+
};
|
|
137
|
+
export type ExternalApplicationsListAppRolesResponse = ExternalApplicationsListAppRolesResponses[keyof ExternalApplicationsListAppRolesResponses];
|
|
46
138
|
export type JsonValue$1 = boolean | null | number | readonly JsonValue$1[] | Readonly<{
|
|
47
139
|
readonly [key: string]: JsonValue$1;
|
|
48
140
|
}> | string;
|
|
@@ -127,6 +219,40 @@ export type KnowledgeQuery = {
|
|
|
127
219
|
op: "autocomplete";
|
|
128
220
|
});
|
|
129
221
|
export type ExternalApplicationOperationRequest = {
|
|
222
|
+
input: {
|
|
223
|
+
userId: string;
|
|
224
|
+
};
|
|
225
|
+
operationId: "users_get";
|
|
226
|
+
} | {
|
|
227
|
+
input: {
|
|
228
|
+
page?: number;
|
|
229
|
+
pageSize?: number;
|
|
230
|
+
};
|
|
231
|
+
operationId: "users_list";
|
|
232
|
+
} | {
|
|
233
|
+
input: {
|
|
234
|
+
userId: string;
|
|
235
|
+
};
|
|
236
|
+
operationId: "users_deactivate";
|
|
237
|
+
} | {
|
|
238
|
+
input: Record<string, never>;
|
|
239
|
+
operationId: "roles_list";
|
|
240
|
+
} | {
|
|
241
|
+
input: {
|
|
242
|
+
userId: string;
|
|
243
|
+
roles: string[];
|
|
244
|
+
};
|
|
245
|
+
operationId: "roles_assign";
|
|
246
|
+
} | {
|
|
247
|
+
input: {
|
|
248
|
+
userId: string;
|
|
249
|
+
roles: string[];
|
|
250
|
+
};
|
|
251
|
+
operationId: "roles_revoke";
|
|
252
|
+
} | {
|
|
253
|
+
input: ExternalApplicationsCreateOrGetAppUserData["body"];
|
|
254
|
+
operationId: "users_create_or_get";
|
|
255
|
+
} | {
|
|
130
256
|
input: JsonObject | unknown[];
|
|
131
257
|
operationId: "context_get";
|
|
132
258
|
} | {
|
|
@@ -328,7 +454,15 @@ export interface EnvelopeSuccess<Id extends string, Result> {
|
|
|
328
454
|
operationId: Id;
|
|
329
455
|
result: Result;
|
|
330
456
|
}
|
|
331
|
-
export type ExternalApplicationOperationSuccess = EnvelopeSuccess<"
|
|
457
|
+
export type ExternalApplicationOperationSuccess = EnvelopeSuccess<"users_get", ApplicationUser> | EnvelopeSuccess<"users_list", ApplicationUserPage> | EnvelopeSuccess<"users_deactivate", {
|
|
458
|
+
userId: string;
|
|
459
|
+
}> | EnvelopeSuccess<"roles_list", {
|
|
460
|
+
items: ApplicationRole[];
|
|
461
|
+
}> | EnvelopeSuccess<"roles_assign", {
|
|
462
|
+
userId: string;
|
|
463
|
+
}> | EnvelopeSuccess<"roles_revoke", {
|
|
464
|
+
userId: string;
|
|
465
|
+
}> | EnvelopeSuccess<"users_create_or_get", ApplicationUserResolution> | EnvelopeSuccess<"context_get", JsonObject> | EnvelopeSuccess<"knowledge_query", JsonObject> | EnvelopeSuccess<"knowledge_get_entity_schema_snapshot", JsonObject> | EnvelopeSuccess<"knowledge_search_entities", JsonObject> | EnvelopeSuccess<"knowledge_facets", JsonObject> | EnvelopeSuccess<"knowledge_get_schema_query_context", JsonObject> | EnvelopeSuccess<"knowledge_autocomplete", JsonObject> | EnvelopeSuccess<"knowledge_get_entity", JsonObject> | EnvelopeSuccess<"knowledge_create_entity", JsonObject> | EnvelopeSuccess<"knowledge_update_entity", JsonObject> | EnvelopeSuccess<"knowledge_upsert_entity", JsonObject> | EnvelopeSuccess<"knowledge_delete_entity", JsonObject> | EnvelopeSuccess<"knowledge_traverse", JsonObject> | EnvelopeSuccess<"knowledge_create_relation", JsonObject> | EnvelopeSuccess<"knowledge_update_relation", JsonObject> | EnvelopeSuccess<"knowledge_delete_relation", JsonObject> | EnvelopeSuccess<"agents_list", JsonObject> | EnvelopeSuccess<"agents_invoke", {
|
|
332
466
|
runId: string;
|
|
333
467
|
}> | EnvelopeSuccess<"skills_list", JsonObject> | EnvelopeSuccess<"skills_invoke", {
|
|
334
468
|
runId: string;
|
|
@@ -346,28 +480,11 @@ export type ExternalApplicationOperationSuccess = EnvelopeSuccess<"context_get",
|
|
|
346
480
|
conversationId: string;
|
|
347
481
|
runId: string;
|
|
348
482
|
}> | EnvelopeSuccess<"conversations_history", ConversationHistory>;
|
|
349
|
-
/**
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
/** A person whose only role in the application's Organization is `member`. */
|
|
355
|
-
export interface MemberUser {
|
|
356
|
-
email: string | null;
|
|
357
|
-
name: string | null;
|
|
358
|
-
userId: string;
|
|
359
|
-
}
|
|
360
|
-
/**
|
|
361
|
-
* How create-or-get resolved the email: a new user, an existing CI user who
|
|
362
|
-
* joined the Organization as a member, or a user who already was one.
|
|
363
|
-
*/
|
|
364
|
-
export type MemberUserResolution = "created" | "existing" | "linked";
|
|
365
|
-
export interface MemberUserPage {
|
|
366
|
-
items: MemberUser[];
|
|
367
|
-
page: number;
|
|
368
|
-
pageSize: number;
|
|
369
|
-
totalItems: number;
|
|
370
|
-
}
|
|
483
|
+
/** User details returned by the application's user-management gateway. */
|
|
484
|
+
export type ApplicationUser = ExternalApplicationsGetAppUserResponse["result"];
|
|
485
|
+
export type ApplicationUserResolution = ExternalApplicationsCreateOrGetAppUserResponse["result"];
|
|
486
|
+
export type ApplicationUserPage = ExternalApplicationsListAppUsersResponse["result"];
|
|
487
|
+
export type ApplicationRole = ExternalApplicationsListAppRolesResponse["result"]["items"][number];
|
|
371
488
|
declare const storageFileIdBrand: unique symbol;
|
|
372
489
|
/** A durable private file of the application's Organization. */
|
|
373
490
|
export type StorageFileId = string & Readonly<{
|
|
@@ -388,32 +505,9 @@ export type ExternalApplicationServiceOperationRequest = {
|
|
|
388
505
|
operationId: "files_upload";
|
|
389
506
|
} | {
|
|
390
507
|
input: {
|
|
391
|
-
|
|
392
|
-
name: string;
|
|
508
|
+
origin: string;
|
|
393
509
|
};
|
|
394
|
-
operationId: "
|
|
395
|
-
} | {
|
|
396
|
-
input: {
|
|
397
|
-
userId: string;
|
|
398
|
-
};
|
|
399
|
-
operationId: "members_get";
|
|
400
|
-
} | {
|
|
401
|
-
input: {
|
|
402
|
-
page?: number;
|
|
403
|
-
pageSize?: number;
|
|
404
|
-
};
|
|
405
|
-
operationId: "members_list";
|
|
406
|
-
} | {
|
|
407
|
-
input: {
|
|
408
|
-
name: string;
|
|
409
|
-
userId: string;
|
|
410
|
-
};
|
|
411
|
-
operationId: "members_update";
|
|
412
|
-
} | {
|
|
413
|
-
input: {
|
|
414
|
-
userId: string;
|
|
415
|
-
};
|
|
416
|
-
operationId: "members_remove";
|
|
510
|
+
operationId: "origins_set_runtime";
|
|
417
511
|
} | {
|
|
418
512
|
input: {
|
|
419
513
|
userId: string;
|
|
@@ -432,10 +526,8 @@ export interface UserCompanyLinks {
|
|
|
432
526
|
}
|
|
433
527
|
export type ExternalApplicationServiceOperationSuccess = EnvelopeSuccess<"files_upload", {
|
|
434
528
|
storageFileId: StorageFileId;
|
|
435
|
-
}> | EnvelopeSuccess<"
|
|
436
|
-
|
|
437
|
-
}> | EnvelopeSuccess<"members_get", MemberUser> | EnvelopeSuccess<"members_list", MemberUserPage> | EnvelopeSuccess<"members_update", MemberUser> | EnvelopeSuccess<"members_remove", {
|
|
438
|
-
userId: string;
|
|
529
|
+
}> | EnvelopeSuccess<"origins_set_runtime", {
|
|
530
|
+
origin: string;
|
|
439
531
|
}> | EnvelopeSuccess<"users_list_company_links", UserCompanyLinks> | EnvelopeSuccess<"users_link_companies", UserCompanyLinks>;
|
|
440
532
|
/** Every operation a confidential server client may invoke. */
|
|
441
533
|
export type ExternalApplicationServerOperationRequest = ExternalApplicationOperationRequest | ExternalApplicationServiceOperationRequest;
|
|
@@ -548,13 +640,21 @@ export type ResourceDefinition<Entity, Create = Entity, Update = Partial<Entity>
|
|
|
548
640
|
}>;
|
|
549
641
|
}>;
|
|
550
642
|
export type FilterValue = ResourceJsonValue | readonly ResourceJsonValue[];
|
|
643
|
+
/**
|
|
644
|
+
* A filter predicate. `field` names a declared filterable field, or a path
|
|
645
|
+
* through at most three fields that hold Entity References to a field of
|
|
646
|
+
* the last target, such as `company.industry` or
|
|
647
|
+
* `contacts.company.parent.industry`. On a field that holds Entity
|
|
648
|
+
* References, `is_empty` means no reference, and `contains_any` and
|
|
649
|
+
* `contains_all` compare the ids of a field that holds many.
|
|
650
|
+
*/
|
|
551
651
|
export type ResourceFilter = Readonly<{
|
|
552
652
|
field: string;
|
|
553
|
-
operator: "contains" | "ends_with" | "eq" | "gt" | "gte" | "in" | "lt" | "lte" | "ne" | "not_in" | "starts_with";
|
|
653
|
+
operator: "contains" | "contains_all" | "contains_any" | "ends_with" | "eq" | "gt" | "gte" | "in" | "lt" | "lte" | "ne" | "not_in" | "starts_with";
|
|
554
654
|
value: FilterValue;
|
|
555
655
|
}> | Readonly<{
|
|
556
656
|
field: string;
|
|
557
|
-
operator: "is_not_null" | "is_null";
|
|
657
|
+
operator: "is_empty" | "is_not_null" | "is_null";
|
|
558
658
|
}> | Readonly<{
|
|
559
659
|
filters: readonly ResourceFilter[];
|
|
560
660
|
operator: "and" | "or";
|
|
@@ -577,6 +677,11 @@ export type ResourcePagination = Readonly<{
|
|
|
577
677
|
}>;
|
|
578
678
|
export type ResourceListQuery = Readonly<{
|
|
579
679
|
filter?: ResourceFilter;
|
|
680
|
+
/**
|
|
681
|
+
* Include Paths, such as `["company", "contacts.company"]`: relation
|
|
682
|
+
* fields whose records each item carries in `included`.
|
|
683
|
+
*/
|
|
684
|
+
include?: readonly string[];
|
|
580
685
|
includeDeleted?: boolean;
|
|
581
686
|
pagination: ResourcePagination;
|
|
582
687
|
sort?: readonly ResourceSort[];
|
|
@@ -585,7 +690,15 @@ export type ResourceListQuery = Readonly<{
|
|
|
585
690
|
export type ResourceRecord<Entity> = Readonly<{
|
|
586
691
|
deletedAt?: string;
|
|
587
692
|
id: ResourceRecordId;
|
|
693
|
+
/**
|
|
694
|
+
* The records of the read's Include Paths by relation field key: one
|
|
695
|
+
* record, or the records of a `many` field in reference order. Untyped:
|
|
696
|
+
* the target schemas are CI's.
|
|
697
|
+
*/
|
|
698
|
+
included?: Readonly<Record<string, ResourceJsonValue>>;
|
|
588
699
|
revision: ResourceRevision;
|
|
700
|
+
/** The keys whose included records were cut to the first 100. */
|
|
701
|
+
truncated?: readonly string[];
|
|
589
702
|
value: Entity;
|
|
590
703
|
}>;
|
|
591
704
|
export type ResourceListResult<Entity> = Readonly<{
|
|
@@ -646,6 +759,8 @@ export type EntityListQuery = Omit<ResourceListQuery, "pagination" | "includeDel
|
|
|
646
759
|
export type EntityPage<Value> = Extract<ResourceListResult<Value>, {
|
|
647
760
|
pagination: "page";
|
|
648
761
|
}>;
|
|
762
|
+
/** Member schemas are resolved by CI, independently of the parent resource. */
|
|
763
|
+
export type EntityMemberValue = Readonly<Record<string, ResourceJsonValue>>;
|
|
649
764
|
export type EntityCreateInput<Value> = ResourceCreateInput<Value>;
|
|
650
765
|
export type EntityUpdateInput<Patch> = ResourceMutationInput<Patch> & Readonly<{
|
|
651
766
|
idempotencyKey: IdempotencyKey;
|
|
@@ -668,10 +783,13 @@ export type EntityUploadSlot = Readonly<{
|
|
|
668
783
|
}>;
|
|
669
784
|
/** A logical write retains its key, payload and edited revision on explicit resubmission. */
|
|
670
785
|
export interface EntityClient<Value, Create = Value, Patch = Partial<Value>> {
|
|
786
|
+
/** Filter, sort and page the resolved member schema; includes remain bounded. */
|
|
787
|
+
readonly listMembers: (parentId: ResourceRecordId, field: string, query: EntityListQuery, options?: ResourceRequestOptions) => Promise<ResourceResult<EntityPage<EntityMemberValue>>>;
|
|
671
788
|
readonly definition: ResourceDefinition<Value, Create, Patch>;
|
|
672
789
|
readonly list: (query: EntityListQuery, options?: ResourceRequestOptions) => Promise<ResourceResult<EntityPage<Value>>>;
|
|
673
790
|
readonly get: (input: Readonly<{
|
|
674
791
|
id: ResourceRecordId;
|
|
792
|
+
include?: readonly string[];
|
|
675
793
|
}>, options?: ResourceRequestOptions) => Promise<ResourceResult<ResourceRecord<Value>>>;
|
|
676
794
|
readonly create: (input: EntityCreateInput<Create>) => Promise<ResourceResult<ResourceRecord<Value>>>;
|
|
677
795
|
readonly update: (input: EntityUpdateInput<Patch>) => Promise<ResourceResult<ResourceRecord<Value>>>;
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import{__export,FederatedAuthError,EntityRuntimeProvider,createDelegatedEntitySource,defineEntity2,useEntityViewState2,useMemoryEntityViewState2,EntityTable2,EntityList2,EntityForm2}from"./index-h3ff4vxf.js";var exports_src={};__export(exports_src,{AgentPrompt:()=>AgentPrompt,AgentPromptPrimitive:()=>AgentPromptPrimitive,CollectiveIntelligenceLoginProvider:()=>CollectiveIntelligenceLoginProvider,CollectiveIntelligenceProvider:()=>CollectiveIntelligenceProvider,EntityForm:()=>EntityForm2,EntityList:()=>EntityList2,EntityTable:()=>EntityTable2,LoginButton:()=>LoginButton,LoginCallback:()=>LoginCallback,LoginCallbackPrimitive:()=>LoginCallbackPrimitive,SessionGate:()=>SessionGate,clientSdkReactEntrypoint:()=>clientSdkReactEntrypoint,createDelegatedEntitySource:()=>createDelegatedEntitySource,createPromptKeyHandler:()=>createPromptKeyHandler,defineEntity:()=>defineEntity2,useAgentInvocation:()=>useAgentInvocation,useAgents:()=>useAgents,useAttachments:()=>useAttachments,useClientContext:()=>useClientContext,useCollectiveIntelligenceAuth:()=>useCollectiveIntelligenceAuth,useCollectiveIntelligenceClient:()=>useCollectiveIntelligenceClient,useEntityViewState:()=>useEntityViewState2,useKnowledge:()=>useKnowledge,useMemoryEntityViewState:()=>useMemoryEntityViewState2,useOrganizationClient:()=>useOrganizationClient,useRuns:()=>useRuns,useSession:()=>useSession,useSkills:()=>useSkills,useWorkflows:()=>useWorkflows});import{useCallback,useId,useState as useState2}from"react";import{QueryClient,QueryClientProvider}from"@tanstack/react-query";import{createContext,useContext,useMemo,useState}from"react";import{jsx}from"react/jsx-runtime";var ClientContext=createContext(null);var CollectiveIntelligenceProvider=(props)=>{const{clientFactory}=props;const[queryClient]=useState(()=>new QueryClient({defaultOptions:{mutations:{retry:false},queries:{retry:false}}}));const ownedClient=useMemo(()=>clientFactory===undefined?undefined:clientFactory(),[clientFactory]);const client=props.client??ownedClient;if(client===undefined){throw new TypeError("A client or clientFactory is required")}return jsx(ClientContext.Provider,{value:client,children:jsx(QueryClientProvider,{client:queryClient,children:props.entitySource===undefined?props.children:jsx(EntityRuntimeProvider,{source:props.entitySource,children:props.children})})})};var useCollectiveIntelligenceClient=()=>{const client=useContext(ClientContext);if(client===null){throw new Error("CollectiveIntelligenceProvider must wrap Collective Intelligence hooks")}return client};var useOrganizationClient=(organizationId)=>{const client=useCollectiveIntelligenceClient();return useMemo(()=>client.forOrganization(organizationId),[client,organizationId])};var useKnowledge=(organizationId)=>useOrganizationClient(organizationId).knowledge;var useAgents=(organizationId)=>useOrganizationClient(organizationId).agents;var useSkills=(organizationId)=>useOrganizationClient(organizationId).skills;var useWorkflows=(organizationId)=>useOrganizationClient(organizationId).workflows;var useRuns=(organizationId)=>useOrganizationClient(organizationId).runs;var useAttachments=(organizationId)=>useOrganizationClient(organizationId).attachments;var useClientContext=(organizationId)=>useOrganizationClient(organizationId).context;import{jsx as jsx2,jsxs}from"react/jsx-runtime";var ignoreSubmit=()=>false;var createPromptKeyHandler=(onSubmit)=>(event)=>{if(event.key==="Enter"&&!event.shiftKey&&!event.isComposing){event.preventDefault();onSubmit()}};var AgentPromptPrimitive=({autoFocus=false,className,components,id,label,onChange,onSubmit,pending,status,style,submitLabel="Send",value})=>{const Form=components?.Form??"form";const Label=components?.Label??"label";const Textarea=components?.Textarea??"textarea";const Button=components?.Button??"button";const Status=components?.Status??"div";const statusId=`${id}-status`;const submit=(event)=>{event.preventDefault();if(!pending){onSubmit()}};const onKeyDown=(event)=>{createPromptKeyHandler(pending?ignoreSubmit:onSubmit)({isComposing:event.nativeEvent.isComposing,key:event.key,preventDefault:()=>{event.preventDefault()},shiftKey:event.shiftKey})};return jsxs(Form,{className:["ci-agent-prompt",className].filter(Boolean).join(" "),onSubmit:submit,style,children:[jsx2(Label,{className:"ci-agent-prompt__label",htmlFor:id,children:label}),jsx2(Textarea,{"aria-describedby":statusId,autoFocus,className:"ci-agent-prompt__input",disabled:pending,id,onChange:(event)=>{onChange(event.currentTarget.value)},onKeyDown,value}),jsx2(Button,{className:"ci-agent-prompt__submit",disabled:pending||value.trim().length===0,type:"submit",children:submitLabel}),jsx2(Status,{"aria-live":"polite",className:"ci-agent-prompt__status",id:statusId,children:status})]})};var useAgentInvocation=(organizationId)=>{const{agents}=useOrganizationClient(organizationId);const[state,setState]=useState2({status:"idle"});const invoke=useCallback(async(input)=>{setState({status:"submitting"});try{const result=await agents.invoke(input);setState(result.ok?{result,status:"success"}:{result,status:"failure"});return result}catch(error){setState({error,status:"error"});throw error}},[agents]);return{invoke,reset:()=>{setState({status:"idle"})},state}};var invocationStatus=(state)=>{switch(state.status){case"submitting":{return"Sending"}case"success":{return"Request started"}case"failure":{return state.result.error.message}case"error":{return"Request failed"}case"idle":{return null}default:{return null}}};var EMPTY_AGENT_PROMPT_COMPONENTS={};var EMPTY_AGENT_PROMPT_STYLE={};var createDefaultIdempotencyKey=()=>globalThis.crypto.randomUUID();var AgentPrompt=({agentId,autoFocus=false,className="",components=EMPTY_AGENT_PROMPT_COMPONENTS,createIdempotencyKey=createDefaultIdempotencyKey,label="Message",onResult,organizationId,style=EMPTY_AGENT_PROMPT_STYLE,submitLabel="Send"})=>{const id=`ci-agent-prompt-${useId().replaceAll(":","")}`;const[value,setValue]=useState2("");const invocation=useAgentInvocation(organizationId);const submit=()=>{const prompt=value.trim();if(prompt.length===0||invocation.state.status==="submitting"){return}const submitInvocation=async()=>{try{const result=await invocation.invoke({agentId,idempotencyKey:createIdempotencyKey(),input:{prompt}});if(result.ok){setValue("")}onResult?.(result)}catch{}};submitInvocation()};return jsx2(AgentPromptPrimitive,{autoFocus,className,components,id,label,onChange:setValue,onSubmit:submit,pending:invocation.state.status==="submitting",status:invocationStatus(invocation.state),style,submitLabel,value})};import{createContext as createContext2,useCallback as useCallback2,useContext as useContext2,useEffect,useMemo as useMemo2,useSyncExternalStore}from"react";import{jsx as jsx3}from"react/jsx-runtime";var AuthContext=createContext2(null);var toFederatedAuthError=(error)=>new FederatedAuthError("authorization_failed",error.message);var unknownAuthError=()=>new FederatedAuthError("authorization_failed","Sign in failed");var CollectiveIntelligenceLoginProvider=(props)=>{const state=useSyncExternalStore(props.auth.subscribe,props.auth.getState,props.auth.getState);const contextValue=useMemo2(()=>({auth:props.auth,state}),[props.auth,state]);return jsx3(AuthContext.Provider,{value:contextValue,children:props.clientFactory===undefined?jsx3(CollectiveIntelligenceProvider,{client:props.client,entitySource:props.entitySource,children:props.children}):jsx3(CollectiveIntelligenceProvider,{clientFactory:props.clientFactory,entitySource:props.entitySource,children:props.children})})};var useCollectiveIntelligenceAuth=()=>{const value=useContext2(AuthContext);if(value===null){throw new Error("CollectiveIntelligenceLoginProvider must wrap authentication bindings")}return{...value,beginLogin:value.auth.beginLogin,completeLogin:value.auth.completeLogin,logout:value.auth.logout,reauthorize:value.auth.reauthorize}};var LoginButton=({children="Sign in with Collective Intelligence",className,components,disabled=false,onError,returnTo,style})=>{const{auth,state}=useCollectiveIntelligenceAuth();const Button=components?.Button??"button";const redirecting=state.status==="redirecting";const onClick=useCallback2((event)=>{event.preventDefault();const target=returnTo??globalThis.location.href;const begin=async()=>{try{await auth.beginLogin({returnTo:target})}catch(error){onError?.(error instanceof Error?toFederatedAuthError(error):unknownAuthError())}};begin()},[auth,onError,returnTo]);return jsx3(Button,{"aria-busy":redirecting,className:["ci-login-button",className].filter(Boolean).join(" "),disabled:disabled||redirecting,onClick,style,type:"button",children})};var callbackMessage=(state)=>{switch(state.status){case"authenticated":{return"Sign in complete"}case"error":{return state.error.message}case"expired":{return"Sign in expired"}case"anonymous":case"redirecting":{return"Completing sign in"}default:{return"Completing sign in"}}};var LoginCallbackPrimitive=({className,components,state,style})=>{const Status=components?.Status??"div";return jsx3(Status,{"aria-live":"polite",className:["ci-login-callback",className].filter(Boolean).join(" "),style,children:callbackMessage(state)})};var LoginCallback=({callbackUrl,onComplete,onError,...primitiveProps})=>{const{auth,state}=useCollectiveIntelligenceAuth();useEffect(()=>{const url=callbackUrl??globalThis.location.href;const complete=async()=>{try{const{returnTo}=await auth.completeLogin(url);onComplete?.(returnTo)}catch(error){onError?.(error instanceof Error?toFederatedAuthError(error):unknownAuthError())}};complete()},[auth,callbackUrl,onComplete,onError]);return jsx3(LoginCallbackPrimitive,{...primitiveProps,state})};var useSession=()=>{const{state}=useCollectiveIntelligenceAuth();return state};var SessionGate=({children,fallback=null})=>{const session=useSession();if(session.status!=="authenticated"){return fallback}return children};"use client";var clientSdkReactEntrypoint="react";"use client";var{AgentPrompt:AgentPrompt2,AgentPromptPrimitive:AgentPromptPrimitive2,CollectiveIntelligenceLoginProvider:CollectiveIntelligenceLoginProvider2,CollectiveIntelligenceProvider:CollectiveIntelligenceProvider2,LoginButton:LoginButton2,LoginCallback:LoginCallback2,LoginCallbackPrimitive:LoginCallbackPrimitive2,SessionGate:SessionGate2,clientSdkReactEntrypoint:clientSdkReactEntrypoint2,createPromptKeyHandler:createPromptKeyHandler2,useAgents:useAgents2,useAttachments:useAttachments2,useClientContext:useClientContext2,useCollectiveIntelligenceAuth:useCollectiveIntelligenceAuth2,useCollectiveIntelligenceClient:useCollectiveIntelligenceClient2,useKnowledge:useKnowledge2,useOrganizationClient:useOrganizationClient2,useRuns:useRuns2,useSession:useSession2,useSkills:useSkills2,useWorkflows:useWorkflows2,useAgentInvocation:useAgentInvocation2}=exports_src;export{AgentPrompt2 as AgentPrompt,AgentPromptPrimitive2 as AgentPromptPrimitive,CollectiveIntelligenceLoginProvider2 as CollectiveIntelligenceLoginProvider,CollectiveIntelligenceProvider2 as CollectiveIntelligenceProvider,LoginButton2 as LoginButton,LoginCallback2 as LoginCallback,LoginCallbackPrimitive2 as LoginCallbackPrimitive,SessionGate2 as SessionGate,clientSdkReactEntrypoint2 as clientSdkReactEntrypoint,createPromptKeyHandler2 as createPromptKeyHandler,useAgentInvocation2 as useAgentInvocation,useAgents2 as useAgents,useAttachments2 as useAttachments,useClientContext2 as useClientContext,useCollectiveIntelligenceAuth2 as useCollectiveIntelligenceAuth,useCollectiveIntelligenceClient2 as useCollectiveIntelligenceClient,useKnowledge2 as useKnowledge,useOrganizationClient2 as useOrganizationClient,useRuns2 as useRuns,useSession2 as useSession,useSkills2 as useSkills,useWorkflows2 as useWorkflows};
|
|
2
|
+
import{__export,FederatedAuthError,EntityRuntimeProvider,createDelegatedEntitySource,defineEntity2,useEntityViewState2,useMemoryEntityViewState2,EntityTable2,EntityList2,EntityForm2}from"./index-cqm78sj8.js";var exports_src={};__export(exports_src,{AgentPrompt:()=>AgentPrompt,AgentPromptPrimitive:()=>AgentPromptPrimitive,CollectiveIntelligenceLoginProvider:()=>CollectiveIntelligenceLoginProvider,CollectiveIntelligenceProvider:()=>CollectiveIntelligenceProvider,EntityForm:()=>EntityForm2,EntityList:()=>EntityList2,EntityTable:()=>EntityTable2,LoginButton:()=>LoginButton,LoginCallback:()=>LoginCallback,LoginCallbackPrimitive:()=>LoginCallbackPrimitive,SessionGate:()=>SessionGate,clientSdkReactEntrypoint:()=>clientSdkReactEntrypoint,createDelegatedEntitySource:()=>createDelegatedEntitySource,createPromptKeyHandler:()=>createPromptKeyHandler,defineEntity:()=>defineEntity2,useAgentInvocation:()=>useAgentInvocation,useAgents:()=>useAgents,useAttachments:()=>useAttachments,useClientContext:()=>useClientContext,useCollectiveIntelligenceAuth:()=>useCollectiveIntelligenceAuth,useCollectiveIntelligenceClient:()=>useCollectiveIntelligenceClient,useEntityViewState:()=>useEntityViewState2,useKnowledge:()=>useKnowledge,useMemoryEntityViewState:()=>useMemoryEntityViewState2,useOrganizationClient:()=>useOrganizationClient,useRuns:()=>useRuns,useSession:()=>useSession,useSkills:()=>useSkills,useWorkflows:()=>useWorkflows});import{useCallback,useId,useState as useState2}from"react";import{QueryClient,QueryClientProvider}from"@tanstack/react-query";import{createContext,useContext,useMemo,useState}from"react";import{jsx}from"react/jsx-runtime";var ClientContext=createContext(null);var CollectiveIntelligenceProvider=(props)=>{const{clientFactory}=props;const[queryClient]=useState(()=>new QueryClient({defaultOptions:{mutations:{retry:false},queries:{retry:false}}}));const ownedClient=useMemo(()=>clientFactory===undefined?undefined:clientFactory(),[clientFactory]);const client=props.client??ownedClient;if(client===undefined){throw new TypeError("A client or clientFactory is required")}return jsx(ClientContext.Provider,{value:client,children:jsx(QueryClientProvider,{client:queryClient,children:props.entitySource===undefined?props.children:jsx(EntityRuntimeProvider,{source:props.entitySource,children:props.children})})})};var useCollectiveIntelligenceClient=()=>{const client=useContext(ClientContext);if(client===null){throw new Error("CollectiveIntelligenceProvider must wrap Collective Intelligence hooks")}return client};var useOrganizationClient=(organizationId)=>{const client=useCollectiveIntelligenceClient();return useMemo(()=>client.forOrganization(organizationId),[client,organizationId])};var useKnowledge=(organizationId)=>useOrganizationClient(organizationId).knowledge;var useAgents=(organizationId)=>useOrganizationClient(organizationId).agents;var useSkills=(organizationId)=>useOrganizationClient(organizationId).skills;var useWorkflows=(organizationId)=>useOrganizationClient(organizationId).workflows;var useRuns=(organizationId)=>useOrganizationClient(organizationId).runs;var useAttachments=(organizationId)=>useOrganizationClient(organizationId).attachments;var useClientContext=(organizationId)=>useOrganizationClient(organizationId).context;import{jsx as jsx2,jsxs}from"react/jsx-runtime";var ignoreSubmit=()=>false;var createPromptKeyHandler=(onSubmit)=>(event)=>{if(event.key==="Enter"&&!event.shiftKey&&!event.isComposing){event.preventDefault();onSubmit()}};var AgentPromptPrimitive=({autoFocus=false,className,components,id,label,onChange,onSubmit,pending,status,style,submitLabel="Send",value})=>{const Form=components?.Form??"form";const Label=components?.Label??"label";const Textarea=components?.Textarea??"textarea";const Button=components?.Button??"button";const Status=components?.Status??"div";const statusId=`${id}-status`;const submit=(event)=>{event.preventDefault();if(!pending){onSubmit()}};const onKeyDown=(event)=>{createPromptKeyHandler(pending?ignoreSubmit:onSubmit)({isComposing:event.nativeEvent.isComposing,key:event.key,preventDefault:()=>{event.preventDefault()},shiftKey:event.shiftKey})};return jsxs(Form,{className:["ci-agent-prompt",className].filter(Boolean).join(" "),onSubmit:submit,style,children:[jsx2(Label,{className:"ci-agent-prompt__label",htmlFor:id,children:label}),jsx2(Textarea,{"aria-describedby":statusId,autoFocus,className:"ci-agent-prompt__input",disabled:pending,id,onChange:(event)=>{onChange(event.currentTarget.value)},onKeyDown,value}),jsx2(Button,{className:"ci-agent-prompt__submit",disabled:pending||value.trim().length===0,type:"submit",children:submitLabel}),jsx2(Status,{"aria-live":"polite",className:"ci-agent-prompt__status",id:statusId,children:status})]})};var useAgentInvocation=(organizationId)=>{const{agents}=useOrganizationClient(organizationId);const[state,setState]=useState2({status:"idle"});const invoke=useCallback(async(input)=>{setState({status:"submitting"});try{const result=await agents.invoke(input);setState(result.ok?{result,status:"success"}:{result,status:"failure"});return result}catch(error){setState({error,status:"error"});throw error}},[agents]);return{invoke,reset:()=>{setState({status:"idle"})},state}};var invocationStatus=(state)=>{switch(state.status){case"submitting":{return"Sending"}case"success":{return"Request started"}case"failure":{return state.result.error.message}case"error":{return"Request failed"}case"idle":{return null}default:{return null}}};var EMPTY_AGENT_PROMPT_COMPONENTS={};var EMPTY_AGENT_PROMPT_STYLE={};var createDefaultIdempotencyKey=()=>globalThis.crypto.randomUUID();var AgentPrompt=({agentId,autoFocus=false,className="",components=EMPTY_AGENT_PROMPT_COMPONENTS,createIdempotencyKey=createDefaultIdempotencyKey,label="Message",onResult,organizationId,style=EMPTY_AGENT_PROMPT_STYLE,submitLabel="Send"})=>{const id=`ci-agent-prompt-${useId().replaceAll(":","")}`;const[value,setValue]=useState2("");const invocation=useAgentInvocation(organizationId);const submit=()=>{const prompt=value.trim();if(prompt.length===0||invocation.state.status==="submitting"){return}const submitInvocation=async()=>{try{const result=await invocation.invoke({agentId,idempotencyKey:createIdempotencyKey(),input:{prompt}});if(result.ok){setValue("")}onResult?.(result)}catch{}};submitInvocation()};return jsx2(AgentPromptPrimitive,{autoFocus,className,components,id,label,onChange:setValue,onSubmit:submit,pending:invocation.state.status==="submitting",status:invocationStatus(invocation.state),style,submitLabel,value})};import{createContext as createContext2,useCallback as useCallback2,useContext as useContext2,useEffect,useMemo as useMemo2,useSyncExternalStore}from"react";import{jsx as jsx3}from"react/jsx-runtime";var AuthContext=createContext2(null);var toFederatedAuthError=(error)=>new FederatedAuthError("authorization_failed",error.message);var unknownAuthError=()=>new FederatedAuthError("authorization_failed","Sign in failed");var CollectiveIntelligenceLoginProvider=(props)=>{const state=useSyncExternalStore(props.auth.subscribe,props.auth.getState,props.auth.getState);const contextValue=useMemo2(()=>({auth:props.auth,state}),[props.auth,state]);return jsx3(AuthContext.Provider,{value:contextValue,children:props.clientFactory===undefined?jsx3(CollectiveIntelligenceProvider,{client:props.client,entitySource:props.entitySource,children:props.children}):jsx3(CollectiveIntelligenceProvider,{clientFactory:props.clientFactory,entitySource:props.entitySource,children:props.children})})};var useCollectiveIntelligenceAuth=()=>{const value=useContext2(AuthContext);if(value===null){throw new Error("CollectiveIntelligenceLoginProvider must wrap authentication bindings")}return{...value,beginLogin:value.auth.beginLogin,completeLogin:value.auth.completeLogin,logout:value.auth.logout,reauthorize:value.auth.reauthorize}};var LoginButton=({children="Sign in with Collective Intelligence",className,components,disabled=false,onError,returnTo,style})=>{const{auth,state}=useCollectiveIntelligenceAuth();const Button=components?.Button??"button";const redirecting=state.status==="redirecting";const onClick=useCallback2((event)=>{event.preventDefault();const target=returnTo??globalThis.location.href;const begin=async()=>{try{await auth.beginLogin({returnTo:target})}catch(error){onError?.(error instanceof Error?toFederatedAuthError(error):unknownAuthError())}};begin()},[auth,onError,returnTo]);return jsx3(Button,{"aria-busy":redirecting,className:["ci-login-button",className].filter(Boolean).join(" "),disabled:disabled||redirecting,onClick,style,type:"button",children})};var callbackMessage=(state)=>{switch(state.status){case"authenticated":{return"Sign in complete"}case"error":{return state.error.message}case"expired":{return"Sign in expired"}case"anonymous":case"redirecting":{return"Completing sign in"}default:{return"Completing sign in"}}};var LoginCallbackPrimitive=({className,components,state,style})=>{const Status=components?.Status??"div";return jsx3(Status,{"aria-live":"polite",className:["ci-login-callback",className].filter(Boolean).join(" "),style,children:callbackMessage(state)})};var LoginCallback=({callbackUrl,onComplete,onError,...primitiveProps})=>{const{auth,state}=useCollectiveIntelligenceAuth();useEffect(()=>{const url=callbackUrl??globalThis.location.href;const complete=async()=>{try{const{returnTo}=await auth.completeLogin(url);onComplete?.(returnTo)}catch(error){onError?.(error instanceof Error?toFederatedAuthError(error):unknownAuthError())}};complete()},[auth,callbackUrl,onComplete,onError]);return jsx3(LoginCallbackPrimitive,{...primitiveProps,state})};var useSession=()=>{const{state}=useCollectiveIntelligenceAuth();return state};var SessionGate=({children,fallback=null})=>{const session=useSession();if(session.status!=="authenticated"){return fallback}return children};"use client";var clientSdkReactEntrypoint="react";"use client";var{AgentPrompt:AgentPrompt2,AgentPromptPrimitive:AgentPromptPrimitive2,CollectiveIntelligenceLoginProvider:CollectiveIntelligenceLoginProvider2,CollectiveIntelligenceProvider:CollectiveIntelligenceProvider2,LoginButton:LoginButton2,LoginCallback:LoginCallback2,LoginCallbackPrimitive:LoginCallbackPrimitive2,SessionGate:SessionGate2,clientSdkReactEntrypoint:clientSdkReactEntrypoint2,createPromptKeyHandler:createPromptKeyHandler2,useAgents:useAgents2,useAttachments:useAttachments2,useClientContext:useClientContext2,useCollectiveIntelligenceAuth:useCollectiveIntelligenceAuth2,useCollectiveIntelligenceClient:useCollectiveIntelligenceClient2,useKnowledge:useKnowledge2,useOrganizationClient:useOrganizationClient2,useRuns:useRuns2,useSession:useSession2,useSkills:useSkills2,useWorkflows:useWorkflows2,useAgentInvocation:useAgentInvocation2}=exports_src;export{AgentPrompt2 as AgentPrompt,AgentPromptPrimitive2 as AgentPromptPrimitive,CollectiveIntelligenceLoginProvider2 as CollectiveIntelligenceLoginProvider,CollectiveIntelligenceProvider2 as CollectiveIntelligenceProvider,LoginButton2 as LoginButton,LoginCallback2 as LoginCallback,LoginCallbackPrimitive2 as LoginCallbackPrimitive,SessionGate2 as SessionGate,clientSdkReactEntrypoint2 as clientSdkReactEntrypoint,createPromptKeyHandler2 as createPromptKeyHandler,useAgentInvocation2 as useAgentInvocation,useAgents2 as useAgents,useAttachments2 as useAttachments,useClientContext2 as useClientContext,useCollectiveIntelligenceAuth2 as useCollectiveIntelligenceAuth,useCollectiveIntelligenceClient2 as useCollectiveIntelligenceClient,useKnowledge2 as useKnowledge,useOrganizationClient2 as useOrganizationClient,useRuns2 as useRuns,useSession2 as useSession,useSkills2 as useSkills,useWorkflows2 as useWorkflows};
|
package/dist/resources.d.ts
CHANGED
|
@@ -7,11 +7,22 @@ declare class FederatedAuthError extends Error {
|
|
|
7
7
|
readonly code: FederatedAuthErrorCode;
|
|
8
8
|
constructor(code: FederatedAuthErrorCode, message: string);
|
|
9
9
|
}
|
|
10
|
+
/**
|
|
11
|
+
* The signed-in CI user as the application's BFF reports it: the fields of
|
|
12
|
+
* CI's `/oauth/identity`, read live by the server, plus email and name.
|
|
13
|
+
*/
|
|
10
14
|
export type FederatedSessionIdentity = Readonly<{
|
|
15
|
+
appId: string;
|
|
16
|
+
/** The App Permissions of the user's effective roles. */
|
|
17
|
+
appPermissions: readonly string[];
|
|
11
18
|
email: string | null;
|
|
12
|
-
|
|
19
|
+
/** A person is a member or an External App User of one Organization, never both. */
|
|
20
|
+
kind: "member" | "external_app_user";
|
|
13
21
|
name: string | null;
|
|
14
22
|
organizationId: string;
|
|
23
|
+
/** The user's effective roles on the app. */
|
|
24
|
+
roles: readonly string[];
|
|
25
|
+
userId: string;
|
|
15
26
|
}>;
|
|
16
27
|
export type FederatedAuthState = Readonly<{
|
|
17
28
|
status: "anonymous";
|
|
@@ -93,13 +104,21 @@ export type ResourceDefinition<Entity, Create = Entity, Update = Partial<Entity>
|
|
|
93
104
|
}>;
|
|
94
105
|
}>;
|
|
95
106
|
export type FilterValue = ResourceJsonValue | readonly ResourceJsonValue[];
|
|
107
|
+
/**
|
|
108
|
+
* A filter predicate. `field` names a declared filterable field, or a path
|
|
109
|
+
* through at most three fields that hold Entity References to a field of
|
|
110
|
+
* the last target, such as `company.industry` or
|
|
111
|
+
* `contacts.company.parent.industry`. On a field that holds Entity
|
|
112
|
+
* References, `is_empty` means no reference, and `contains_any` and
|
|
113
|
+
* `contains_all` compare the ids of a field that holds many.
|
|
114
|
+
*/
|
|
96
115
|
export type ResourceFilter = Readonly<{
|
|
97
116
|
field: string;
|
|
98
|
-
operator: "contains" | "ends_with" | "eq" | "gt" | "gte" | "in" | "lt" | "lte" | "ne" | "not_in" | "starts_with";
|
|
117
|
+
operator: "contains" | "contains_all" | "contains_any" | "ends_with" | "eq" | "gt" | "gte" | "in" | "lt" | "lte" | "ne" | "not_in" | "starts_with";
|
|
99
118
|
value: FilterValue;
|
|
100
119
|
}> | Readonly<{
|
|
101
120
|
field: string;
|
|
102
|
-
operator: "is_not_null" | "is_null";
|
|
121
|
+
operator: "is_empty" | "is_not_null" | "is_null";
|
|
103
122
|
}> | Readonly<{
|
|
104
123
|
filters: readonly ResourceFilter[];
|
|
105
124
|
operator: "and" | "or";
|
|
@@ -122,6 +141,11 @@ export type ResourcePagination = Readonly<{
|
|
|
122
141
|
}>;
|
|
123
142
|
export type ResourceListQuery = Readonly<{
|
|
124
143
|
filter?: ResourceFilter;
|
|
144
|
+
/**
|
|
145
|
+
* Include Paths, such as `["company", "contacts.company"]`: relation
|
|
146
|
+
* fields whose records each item carries in `included`.
|
|
147
|
+
*/
|
|
148
|
+
include?: readonly string[];
|
|
125
149
|
includeDeleted?: boolean;
|
|
126
150
|
pagination: ResourcePagination;
|
|
127
151
|
sort?: readonly ResourceSort[];
|
|
@@ -130,7 +154,15 @@ export type ResourceListQuery = Readonly<{
|
|
|
130
154
|
export type ResourceRecord<Entity> = Readonly<{
|
|
131
155
|
deletedAt?: string;
|
|
132
156
|
id: ResourceRecordId;
|
|
157
|
+
/**
|
|
158
|
+
* The records of the read's Include Paths by relation field key: one
|
|
159
|
+
* record, or the records of a `many` field in reference order. Untyped:
|
|
160
|
+
* the target schemas are CI's.
|
|
161
|
+
*/
|
|
162
|
+
included?: Readonly<Record<string, ResourceJsonValue>>;
|
|
133
163
|
revision: ResourceRevision;
|
|
164
|
+
/** The keys whose included records were cut to the first 100. */
|
|
165
|
+
truncated?: readonly string[];
|
|
134
166
|
value: Entity;
|
|
135
167
|
}>;
|
|
136
168
|
export type ResourceListResult<Entity> = Readonly<{
|
|
@@ -205,6 +237,8 @@ export type EntityListQuery = Omit<ResourceListQuery, "pagination" | "includeDel
|
|
|
205
237
|
export type EntityPage<Value> = Extract<ResourceListResult<Value>, {
|
|
206
238
|
pagination: "page";
|
|
207
239
|
}>;
|
|
240
|
+
/** Member schemas are resolved by CI, independently of the parent resource. */
|
|
241
|
+
export type EntityMemberValue = Readonly<Record<string, ResourceJsonValue>>;
|
|
208
242
|
export type EntityCreateInput<Value> = ResourceCreateInput<Value>;
|
|
209
243
|
export type EntityUpdateInput<Patch> = ResourceMutationInput<Patch> & Readonly<{
|
|
210
244
|
idempotencyKey: IdempotencyKey;
|
|
@@ -227,10 +261,13 @@ export type EntityUploadSlot = Readonly<{
|
|
|
227
261
|
}>;
|
|
228
262
|
/** A logical write retains its key, payload and edited revision on explicit resubmission. */
|
|
229
263
|
export interface EntityClient<Value, Create = Value, Patch = Partial<Value>> {
|
|
264
|
+
/** Filter, sort and page the resolved member schema; includes remain bounded. */
|
|
265
|
+
readonly listMembers: (parentId: ResourceRecordId, field: string, query: EntityListQuery, options?: ResourceRequestOptions) => Promise<ResourceResult<EntityPage<EntityMemberValue>>>;
|
|
230
266
|
readonly definition: ResourceDefinition<Value, Create, Patch>;
|
|
231
267
|
readonly list: (query: EntityListQuery, options?: ResourceRequestOptions) => Promise<ResourceResult<EntityPage<Value>>>;
|
|
232
268
|
readonly get: (input: Readonly<{
|
|
233
269
|
id: ResourceRecordId;
|
|
270
|
+
include?: readonly string[];
|
|
234
271
|
}>, options?: ResourceRequestOptions) => Promise<ResourceResult<ResourceRecord<Value>>>;
|
|
235
272
|
readonly create: (input: EntityCreateInput<Create>) => Promise<ResourceResult<ResourceRecord<Value>>>;
|
|
236
273
|
readonly update: (input: EntityUpdateInput<Patch>) => Promise<ResourceResult<ResourceRecord<Value>>>;
|
|
@@ -421,7 +458,9 @@ export declare const useEntityList: <Value, Create, Patch>(contract: ResourceDef
|
|
|
421
458
|
items: readonly Readonly<{
|
|
422
459
|
deletedAt?: string;
|
|
423
460
|
id: ResourceRecordId;
|
|
461
|
+
included?: Readonly<Record<string, ResourceJsonValue>>;
|
|
424
462
|
revision: ResourceRevision;
|
|
463
|
+
truncated?: readonly string[];
|
|
425
464
|
value: Value;
|
|
426
465
|
}>[];
|
|
427
466
|
page: number;
|
|
@@ -455,7 +494,9 @@ export declare const useEntityRecord: <Value, Create, Patch>(contract: ResourceD
|
|
|
455
494
|
data: NoInfer<Readonly<{
|
|
456
495
|
deletedAt?: string;
|
|
457
496
|
id: ResourceRecordId;
|
|
497
|
+
included?: Readonly<Record<string, ResourceJsonValue>>;
|
|
458
498
|
revision: ResourceRevision;
|
|
499
|
+
truncated?: readonly string[];
|
|
459
500
|
value: Value;
|
|
460
501
|
}>> | undefined;
|
|
461
502
|
error: Error | null;
|
|
@@ -470,7 +511,9 @@ export declare const useEntityUpdate: <Value, Create, Patch>(contract: ResourceD
|
|
|
470
511
|
data: Readonly<{
|
|
471
512
|
deletedAt?: string;
|
|
472
513
|
id: ResourceRecordId;
|
|
514
|
+
included?: Readonly<Record<string, ResourceJsonValue>>;
|
|
473
515
|
revision: ResourceRevision;
|
|
516
|
+
truncated?: readonly string[];
|
|
474
517
|
value: Value;
|
|
475
518
|
}> | undefined;
|
|
476
519
|
error: ResourceQueryError | null;
|
|
@@ -478,14 +521,18 @@ export declare const useEntityUpdate: <Value, Create, Patch>(contract: ResourceD
|
|
|
478
521
|
resubmit: () => Promise<ResourceResult<Readonly<{
|
|
479
522
|
deletedAt?: string;
|
|
480
523
|
id: ResourceRecordId;
|
|
524
|
+
included?: Readonly<Record<string, ResourceJsonValue>>;
|
|
481
525
|
revision: ResourceRevision;
|
|
526
|
+
truncated?: readonly string[];
|
|
482
527
|
value: Value;
|
|
483
528
|
}>>>;
|
|
484
529
|
status: "pending" | "success" | "idle" | "conflict" | "uncertain" | "rejected";
|
|
485
530
|
submit: (input: Omit<EntityUpdateInput<Patch>, "id" | "idempotencyKey">) => Promise<ResourceResult<Readonly<{
|
|
486
531
|
deletedAt?: string;
|
|
487
532
|
id: ResourceRecordId;
|
|
533
|
+
included?: Readonly<Record<string, ResourceJsonValue>>;
|
|
488
534
|
revision: ResourceRevision;
|
|
535
|
+
truncated?: readonly string[];
|
|
489
536
|
value: Value;
|
|
490
537
|
}>>>;
|
|
491
538
|
submitted: EntityUpdateInput<Patch> | undefined;
|
|
@@ -495,7 +542,9 @@ export declare const useEntityCreate: <Value, Create, Patch>(contract: ResourceD
|
|
|
495
542
|
data: Readonly<{
|
|
496
543
|
deletedAt?: string;
|
|
497
544
|
id: ResourceRecordId;
|
|
545
|
+
included?: Readonly<Record<string, ResourceJsonValue>>;
|
|
498
546
|
revision: ResourceRevision;
|
|
547
|
+
truncated?: readonly string[];
|
|
499
548
|
value: Value;
|
|
500
549
|
}> | undefined;
|
|
501
550
|
error: ResourceQueryError | null;
|
|
@@ -503,7 +552,9 @@ export declare const useEntityCreate: <Value, Create, Patch>(contract: ResourceD
|
|
|
503
552
|
resubmit: () => Promise<ResourceResult<Readonly<{
|
|
504
553
|
deletedAt?: string;
|
|
505
554
|
id: ResourceRecordId;
|
|
555
|
+
included?: Readonly<Record<string, ResourceJsonValue>>;
|
|
506
556
|
revision: ResourceRevision;
|
|
557
|
+
truncated?: readonly string[];
|
|
507
558
|
value: Value;
|
|
508
559
|
}>>>;
|
|
509
560
|
status: "pending" | "success" | "idle" | "conflict" | "uncertain" | "rejected";
|
|
@@ -513,7 +564,9 @@ export declare const useEntityCreate: <Value, Create, Patch>(contract: ResourceD
|
|
|
513
564
|
}>, "idempotencyKey">) => Promise<ResourceResult<Readonly<{
|
|
514
565
|
deletedAt?: string;
|
|
515
566
|
id: ResourceRecordId;
|
|
567
|
+
included?: Readonly<Record<string, ResourceJsonValue>>;
|
|
516
568
|
revision: ResourceRevision;
|
|
569
|
+
truncated?: readonly string[];
|
|
517
570
|
value: Value;
|
|
518
571
|
}>>>;
|
|
519
572
|
submitted: Readonly<{
|
|
@@ -528,7 +581,9 @@ export declare const useEntityDelete: <Value, Create, Patch>(contract: ResourceD
|
|
|
528
581
|
data: Readonly<{
|
|
529
582
|
deletedAt?: string;
|
|
530
583
|
id: ResourceRecordId;
|
|
584
|
+
included?: Readonly<Record<string, ResourceJsonValue>>;
|
|
531
585
|
revision: ResourceRevision;
|
|
586
|
+
truncated?: readonly string[];
|
|
532
587
|
value: Value;
|
|
533
588
|
}> | undefined;
|
|
534
589
|
error: ResourceQueryError | null;
|
|
@@ -536,14 +591,18 @@ export declare const useEntityDelete: <Value, Create, Patch>(contract: ResourceD
|
|
|
536
591
|
resubmit: () => Promise<ResourceResult<Readonly<{
|
|
537
592
|
deletedAt?: string;
|
|
538
593
|
id: ResourceRecordId;
|
|
594
|
+
included?: Readonly<Record<string, ResourceJsonValue>>;
|
|
539
595
|
revision: ResourceRevision;
|
|
596
|
+
truncated?: readonly string[];
|
|
540
597
|
value: Value;
|
|
541
598
|
}>>>;
|
|
542
599
|
status: "pending" | "success" | "idle" | "conflict" | "uncertain" | "rejected";
|
|
543
600
|
submit: (input: Omit<EntityDeleteInput, "id" | "idempotencyKey">) => Promise<ResourceResult<Readonly<{
|
|
544
601
|
deletedAt?: string;
|
|
545
602
|
id: ResourceRecordId;
|
|
603
|
+
included?: Readonly<Record<string, ResourceJsonValue>>;
|
|
546
604
|
revision: ResourceRevision;
|
|
605
|
+
truncated?: readonly string[];
|
|
547
606
|
value: Value;
|
|
548
607
|
}>>>;
|
|
549
608
|
submitted: EntityDeleteInput | undefined;
|
package/dist/resources.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import{__export,resourceKeys,ResourceQueryError2,unwrapResourceResult2,createResourceListQueryOptions,mapResourceAuthState2,hasResourceCapability2,clearProtectedResourceQueries,createDelegatedEntitySource,defineEntity2,useEntityUpdate2,useEntityCreate2,useEntityDelete2,useEntityList2,useEntityRecord2,useEntityViewState2,useMemoryEntityViewState2,EntityTable2,EntityList2,EntityForm2}from"./index-
|
|
2
|
+
import{__export,resourceKeys,ResourceQueryError2,unwrapResourceResult2,createResourceListQueryOptions,mapResourceAuthState2,hasResourceCapability2,clearProtectedResourceQueries,createDelegatedEntitySource,defineEntity2,useEntityUpdate2,useEntityCreate2,useEntityDelete2,useEntityList2,useEntityRecord2,useEntityViewState2,useMemoryEntityViewState2,EntityTable2,EntityList2,EntityForm2}from"./index-cqm78sj8.js";var exports_resources={};__export(exports_resources,{EntityForm:()=>EntityForm2,EntityList:()=>EntityList2,EntityTable:()=>EntityTable2,ResourceCapabilityAction:()=>ResourceCapabilityAction,ResourceFilter:()=>ResourceFilter,ResourceLifecycleAction:()=>ResourceLifecycleAction,ResourceList:()=>ResourceList,ResourcePagination:()=>ResourcePagination,ResourceProvider:()=>ResourceProvider,ResourceQueryError:()=>ResourceQueryError2,ResourceTable:()=>ResourceTable,createDelegatedEntitySource:()=>createDelegatedEntitySource,defineEntity:()=>defineEntity2,hasResourceCapability:()=>hasResourceCapability2,mapResourceAuthState:()=>mapResourceAuthState2,unwrapResourceResult:()=>unwrapResourceResult2,useEntityCreate:()=>useEntityCreate2,useEntityDelete:()=>useEntityDelete2,useEntityList:()=>useEntityList2,useEntityRecord:()=>useEntityRecord2,useEntityUpdate:()=>useEntityUpdate2,useEntityViewState:()=>useEntityViewState2,useMemoryEntityViewState:()=>useMemoryEntityViewState2});import{useMutation,useQuery,useQueryClient as useQueryClient2}from"@tanstack/react-query";import{mutationOptions}from"@tanstack/react-query";var invalidateResource=async(options)=>{await options.queryClient.invalidateQueries({queryKey:resourceKeys.resource(options.organizationId,options.client.definition.id,options.client.definition.version)})};var createResourceMutationOptions=(options)=>mutationOptions({mutationFn:async(input)=>{let result;switch(options.operation){case"hard_delete":{unwrapResourceResult2(await options.client.hardDelete(input));break}case"restore":{result=unwrapResourceResult2(await options.client.restore(input));break}case"soft_delete":{result=unwrapResourceResult2(await options.client.softDelete(input));break}default:{throw new TypeError(`Unknown resource operation: ${String(options.operation)}`)}}return result},mutationKey:[...resourceKeys.resource(options.organizationId,options.client.definition.id,options.client.definition.version),"mutations",options.operation],onSuccess:async()=>{await invalidateResource(options)}});import{useQueryClient}from"@tanstack/react-query";import{createContext,useContext,useEffect,useMemo,useRef}from"react";import{jsx}from"react/jsx-runtime";var useResourceQueryCleanup=(queryClient,authStatus,organizationId)=>{const previousOrganizationId=useRef(null);const input=useMemo(()=>({authStatus,organizationId}),[authStatus,organizationId]);useEffect(()=>{const previous=previousOrganizationId.current;previousOrganizationId.current=input.organizationId;if(input.authStatus!=="authenticated"){clearProtectedResourceQueries(queryClient);return}if(previous!==null&&previous!==input.organizationId){clearProtectedResourceQueries(queryClient,previous)}},[input,queryClient])};var ResourceContext=createContext(null);var ResourceProvider=({authState,capabilities,children,organizationId})=>{const queryClient=useQueryClient();useResourceQueryCleanup(queryClient,authState.status,organizationId);const value=useMemo(()=>({authState,capabilities,organizationId}),[authState,capabilities,organizationId]);return jsx(ResourceContext.Provider,{value,children})};var useResourceContext=()=>{const value=useContext(ResourceContext);if(value===null){throw new Error("ResourceProvider must wrap resource bindings")}return value};var authStateForError=(error,fallback)=>error instanceof ResourceQueryError2?mapResourceAuthState2({correlationId:error.correlationId,error:error.resourceError,ok:false}):fallback;var useResourceList=(client,query)=>{const context=useResourceContext();const result=useQuery({...createResourceListQueryOptions({client,organizationId:context.organizationId,query}),enabled:context.authState.status==="authenticated"});return{...result,authState:authStateForError(result.error,context.authState)}};var useResourceLifecycleMutation=(client,operation)=>{const{capabilities,organizationId}=useResourceContext();const queryClient=useQueryClient2();const mutation=useMutation(createResourceMutationOptions({client,operation,organizationId,queryClient}));let capability;if(operation==="hard_delete"){capability="hardDelete"}else if(operation==="soft_delete"){capability="softDelete"}else{capability=operation}return{...mutation,available:capabilities[capability]===true}};import{jsx as jsx2,jsxs,Fragment}from"react/jsx-runtime";var nextQuery=(query,result)=>{if(result.pagination==="cursor"){return result.nextCursor===undefined?undefined:{...query,pagination:{cursor:result.nextCursor,limit:query.pagination.mode==="cursor"?query.pagination.limit:25,mode:"cursor"}}}return result.page>=result.totalPages?undefined:{...query,pagination:{mode:"page",page:result.page+1,pageSize:result.pageSize}}};var previousQuery=(query,result)=>result.pagination==="page"&&result.page>1?{...query,pagination:{mode:"page",page:result.page-1,pageSize:result.pageSize}}:undefined;var DefaultStatus=({authState,error,pending})=>{let message=authState.status;if(authState.status==="authenticated"){message=pending?"Loading resources":error?.message??""}return jsx2("output",{"aria-live":"polite",children:message})};var ResourceList=({client,components,onQueryChange,query,renderItem})=>{const resourceQuery=useResourceList(client,query);const Status=components.Status??DefaultStatus;if(resourceQuery.authState.status!=="authenticated"||resourceQuery.isPending||resourceQuery.error!==null){return jsx2(Status,{authState:resourceQuery.authState,pending:resourceQuery.isPending,...resourceQuery.error===null?{}:{error:resourceQuery.error}})}const{List}=components;const{Pagination}=components;const result=resourceQuery.data;const next=nextQuery(query,result);const previous=previousQuery(query,result);return jsxs(Fragment,{children:[jsx2(List,{getItemKey:(item)=>item.id,items:result.items,renderItem}),Pagination===undefined?null:jsx2(Pagination,{hasNextPage:next!==undefined,hasPreviousPage:previous!==undefined,isPending:resourceQuery.isFetching,onNext:()=>{if(next!==undefined){onQueryChange?.(next)}},onPrevious:()=>{if(previous!==undefined){onQueryChange?.(previous)}},...result.pagination==="page"?{currentPage:result.page}:{}})]})};var ResourceCapabilityAction=({capability,children,components,unsupported="disable"})=>{const{capabilities}=useResourceContext();const supported=capabilities[capability]===true;if(!supported&&unsupported==="hide"){return null}const{Action}=components;return jsx2(Action,{disabled:!supported,children})};var ResourceFilter=({components,label="Search resources",onQueryChange,query})=>{const{Filter}=components;const{textSearch:_textSearch,...queryWithoutTextSearch}=query;return jsx2(Filter,{label,onChange:(value)=>{onQueryChange(value===""?queryWithoutTextSearch:{...query,textSearch:value})},value:query.textSearch??""})};var ResourcePagination=({components,isPending=false,onQueryChange,query,result})=>{const{Pagination}=components;const next=nextQuery(query,result);const previous=previousQuery(query,result);return jsx2(Pagination,{hasNextPage:next!==undefined,hasPreviousPage:previous!==undefined,isPending,onNext:()=>{if(next!==undefined){onQueryChange(next)}},onPrevious:()=>{if(previous!==undefined){onQueryChange(previous)}},...result.pagination==="page"?{currentPage:result.page}:{}})};var ResourceTable=({caption,client,columns,components,query})=>{const resourceQuery=useResourceList(client,query);const Status=components.Status??DefaultStatus;if(resourceQuery.authState.status!=="authenticated"||resourceQuery.isPending||resourceQuery.error!==null){return jsx2(Status,{authState:resourceQuery.authState,pending:resourceQuery.isPending,...resourceQuery.error===null?{}:{error:resourceQuery.error}})}const{Table}=components;return jsx2(Table,{caption,columns,getRowKey:(row)=>row.id,renderCell:(row,column)=>column.render(row),rows:resourceQuery.data.items})};var ResourceLifecycleAction=({children,client,components,input,operation,unsupported="disable"})=>{const mutation=useResourceLifecycleMutation(client,operation);if(!mutation.available&&unsupported==="hide"){return null}const{Action}=components;return jsx2(Action,{disabled:!mutation.available,onClick:()=>{mutation.mutate(input)},pending:mutation.isPending,children})};var{defineEntity,EntityForm,EntityList,EntityTable,ResourceCapabilityAction:ResourceCapabilityAction2,ResourceFilter:ResourceFilter2,ResourceLifecycleAction:ResourceLifecycleAction2,ResourceList:ResourceList2,ResourcePagination:ResourcePagination2,ResourceProvider:ResourceProvider2,ResourceQueryError,ResourceTable:ResourceTable2,hasResourceCapability,mapResourceAuthState,unwrapResourceResult,useEntityCreate,useEntityDelete,useEntityList,useEntityRecord,useEntityUpdate,useEntityViewState,useMemoryEntityViewState}=exports_resources;export{EntityForm,EntityList,EntityTable,ResourceCapabilityAction2 as ResourceCapabilityAction,ResourceFilter2 as ResourceFilter,ResourceLifecycleAction2 as ResourceLifecycleAction,ResourceList2 as ResourceList,ResourcePagination2 as ResourcePagination,ResourceProvider2 as ResourceProvider,ResourceQueryError,ResourceTable2 as ResourceTable,defineEntity,hasResourceCapability,mapResourceAuthState,unwrapResourceResult,useEntityCreate,useEntityDelete,useEntityList,useEntityRecord,useEntityUpdate,useEntityViewState,useMemoryEntityViewState};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@collective-intelligence/external-apps-client-sdk-react",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.11",
|
|
4
4
|
"description": "React bindings for Collective Intelligence external applications.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -48,8 +48,8 @@
|
|
|
48
48
|
"access": "public"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
|
-
"@collective-intelligence/external-apps-client-sdk": "
|
|
52
|
-
"@collective-intelligence/ui-react": "
|
|
51
|
+
"@collective-intelligence/external-apps-client-sdk": "0.1.11",
|
|
52
|
+
"@collective-intelligence/ui-react": "0.1.11",
|
|
53
53
|
"@oxlint/plugins": "1.85.0",
|
|
54
54
|
"@tanstack/react-router": "1.170.30",
|
|
55
55
|
"@tanstack/react-start": "1.168.47",
|