@collective-intelligence/external-apps-client-sdk-react 0.1.8 → 0.1.10
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-yhe7hpfh.js → index-cehy1gv3.js} +19 -19
- package/dist/index.d.ts +72 -4
- package/dist/index.js +1 -1
- package/dist/resources.d.ts +68 -3
- package/dist/resources.js +1 -1
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -368,7 +368,25 @@ export interface MemberUserPage {
|
|
|
368
368
|
pageSize: number;
|
|
369
369
|
totalItems: number;
|
|
370
370
|
}
|
|
371
|
+
declare const storageFileIdBrand: unique symbol;
|
|
372
|
+
/** A durable private file of the application's Organization. */
|
|
373
|
+
export type StorageFileId = string & Readonly<{
|
|
374
|
+
[storageFileIdBrand]: "StorageFileId";
|
|
375
|
+
}>;
|
|
376
|
+
/**
|
|
377
|
+
* One file of up to 10 MiB, base64-encoded. CI accepts the content types
|
|
378
|
+
* `application/pdf`, `image/jpeg` and `image/png`.
|
|
379
|
+
*/
|
|
380
|
+
export interface DurableFileUpload {
|
|
381
|
+
contentBase64: string;
|
|
382
|
+
contentType: string;
|
|
383
|
+
fileName: string;
|
|
384
|
+
sizeBytes: number;
|
|
385
|
+
}
|
|
371
386
|
export type ExternalApplicationServiceOperationRequest = {
|
|
387
|
+
input: DurableFileUpload;
|
|
388
|
+
operationId: "files_upload";
|
|
389
|
+
} | {
|
|
372
390
|
input: {
|
|
373
391
|
email: string;
|
|
374
392
|
name: string;
|
|
@@ -396,6 +414,11 @@ export type ExternalApplicationServiceOperationRequest = {
|
|
|
396
414
|
userId: string;
|
|
397
415
|
};
|
|
398
416
|
operationId: "members_remove";
|
|
417
|
+
} | {
|
|
418
|
+
input: {
|
|
419
|
+
origin: string;
|
|
420
|
+
};
|
|
421
|
+
operationId: "origins_set_runtime";
|
|
399
422
|
} | {
|
|
400
423
|
input: {
|
|
401
424
|
userId: string;
|
|
@@ -412,10 +435,14 @@ export type ExternalApplicationServiceOperationRequest = {
|
|
|
412
435
|
export interface UserCompanyLinks {
|
|
413
436
|
entityIds: string[];
|
|
414
437
|
}
|
|
415
|
-
export type ExternalApplicationServiceOperationSuccess = EnvelopeSuccess<"
|
|
438
|
+
export type ExternalApplicationServiceOperationSuccess = EnvelopeSuccess<"files_upload", {
|
|
439
|
+
storageFileId: StorageFileId;
|
|
440
|
+
}> | EnvelopeSuccess<"members_create_or_get", MemberUser & {
|
|
416
441
|
outcome: MemberUserResolution;
|
|
417
442
|
}> | EnvelopeSuccess<"members_get", MemberUser> | EnvelopeSuccess<"members_list", MemberUserPage> | EnvelopeSuccess<"members_update", MemberUser> | EnvelopeSuccess<"members_remove", {
|
|
418
443
|
userId: string;
|
|
444
|
+
}> | EnvelopeSuccess<"origins_set_runtime", {
|
|
445
|
+
origin: string;
|
|
419
446
|
}> | EnvelopeSuccess<"users_list_company_links", UserCompanyLinks> | EnvelopeSuccess<"users_link_companies", UserCompanyLinks>;
|
|
420
447
|
/** Every operation a confidential server client may invoke. */
|
|
421
448
|
export type ExternalApplicationServerOperationRequest = ExternalApplicationOperationRequest | ExternalApplicationServiceOperationRequest;
|
|
@@ -489,6 +516,8 @@ export type ResourceCapabilities = Readonly<{
|
|
|
489
516
|
search: true;
|
|
490
517
|
softDelete?: boolean;
|
|
491
518
|
update?: boolean;
|
|
519
|
+
/** File uploads for the File fields of a common entity resource. */
|
|
520
|
+
upload?: boolean;
|
|
492
521
|
}>;
|
|
493
522
|
export type ResourcePaginationMode = "cursor" | "page";
|
|
494
523
|
export type PortableResourceSchema = Readonly<Record<string, ResourceJsonValue>>;
|
|
@@ -526,13 +555,21 @@ export type ResourceDefinition<Entity, Create = Entity, Update = Partial<Entity>
|
|
|
526
555
|
}>;
|
|
527
556
|
}>;
|
|
528
557
|
export type FilterValue = ResourceJsonValue | readonly ResourceJsonValue[];
|
|
558
|
+
/**
|
|
559
|
+
* A filter predicate. `field` names a declared filterable field, or a path
|
|
560
|
+
* through at most three fields that hold Entity References to a field of
|
|
561
|
+
* the last target, such as `company.industry` or
|
|
562
|
+
* `contacts.company.parent.industry`. On a field that holds Entity
|
|
563
|
+
* References, `is_empty` means no reference, and `contains_any` and
|
|
564
|
+
* `contains_all` compare the ids of a field that holds many.
|
|
565
|
+
*/
|
|
529
566
|
export type ResourceFilter = Readonly<{
|
|
530
567
|
field: string;
|
|
531
|
-
operator: "contains" | "ends_with" | "eq" | "gt" | "gte" | "in" | "lt" | "lte" | "ne" | "not_in" | "starts_with";
|
|
568
|
+
operator: "contains" | "contains_all" | "contains_any" | "ends_with" | "eq" | "gt" | "gte" | "in" | "lt" | "lte" | "ne" | "not_in" | "starts_with";
|
|
532
569
|
value: FilterValue;
|
|
533
570
|
}> | Readonly<{
|
|
534
571
|
field: string;
|
|
535
|
-
operator: "is_not_null" | "is_null";
|
|
572
|
+
operator: "is_empty" | "is_not_null" | "is_null";
|
|
536
573
|
}> | Readonly<{
|
|
537
574
|
filters: readonly ResourceFilter[];
|
|
538
575
|
operator: "and" | "or";
|
|
@@ -555,6 +592,11 @@ export type ResourcePagination = Readonly<{
|
|
|
555
592
|
}>;
|
|
556
593
|
export type ResourceListQuery = Readonly<{
|
|
557
594
|
filter?: ResourceFilter;
|
|
595
|
+
/**
|
|
596
|
+
* Include Paths, such as `["company", "contacts.company"]`: relation
|
|
597
|
+
* fields whose records each item carries in `included`.
|
|
598
|
+
*/
|
|
599
|
+
include?: readonly string[];
|
|
558
600
|
includeDeleted?: boolean;
|
|
559
601
|
pagination: ResourcePagination;
|
|
560
602
|
sort?: readonly ResourceSort[];
|
|
@@ -563,7 +605,15 @@ export type ResourceListQuery = Readonly<{
|
|
|
563
605
|
export type ResourceRecord<Entity> = Readonly<{
|
|
564
606
|
deletedAt?: string;
|
|
565
607
|
id: ResourceRecordId;
|
|
608
|
+
/**
|
|
609
|
+
* The records of the read's Include Paths by relation field key: one
|
|
610
|
+
* record, or the records of a `many` field in reference order. Untyped:
|
|
611
|
+
* the target schemas are CI's.
|
|
612
|
+
*/
|
|
613
|
+
included?: Readonly<Record<string, ResourceJsonValue>>;
|
|
566
614
|
revision: ResourceRevision;
|
|
615
|
+
/** The keys whose included records were cut to the first 100. */
|
|
616
|
+
truncated?: readonly string[];
|
|
567
617
|
value: Entity;
|
|
568
618
|
}>;
|
|
569
619
|
export type ResourceListResult<Entity> = Readonly<{
|
|
@@ -578,7 +628,9 @@ export type ResourceListResult<Entity> = Readonly<{
|
|
|
578
628
|
totalItems: number;
|
|
579
629
|
totalPages: number;
|
|
580
630
|
}>;
|
|
581
|
-
export type ResourceErrorCode = "capability_not_supported" | "conflict" | "forbidden" | "internal" | "invalid_request" | "not_found" | "rate_limited" | "transport_error" | "unauthenticated" | "unavailable"
|
|
631
|
+
export type ResourceErrorCode = "capability_not_supported" | "conflict" | "forbidden" | "internal" | "invalid_request" | "not_found" | "rate_limited" | "transport_error" | "unauthenticated" | "unavailable" |
|
|
632
|
+
/** The CI Organization storage can not take a presigned File upload. */
|
|
633
|
+
"upload_not_supported";
|
|
582
634
|
export type ResourceError = Readonly<{
|
|
583
635
|
code: ResourceErrorCode;
|
|
584
636
|
/** Client-observed dispatch outcome; uncertainty never proves rollback. */
|
|
@@ -629,16 +681,32 @@ export type EntityUpdateInput<Patch> = ResourceMutationInput<Patch> & Readonly<{
|
|
|
629
681
|
export type EntityDeleteInput = ResourceLifecycleInput & Readonly<{
|
|
630
682
|
idempotencyKey: IdempotencyKey;
|
|
631
683
|
}>;
|
|
684
|
+
/** A File upload request for one File field of the entity schema. */
|
|
685
|
+
export type EntityUploadInput = Readonly<{
|
|
686
|
+
field: string;
|
|
687
|
+
filename: string;
|
|
688
|
+
mimeType: string;
|
|
689
|
+
}>;
|
|
690
|
+
/** PUT the file bytes to `url` with `headers`; then write `{ upload: uploadId }`. */
|
|
691
|
+
export type EntityUploadSlot = Readonly<{
|
|
692
|
+
headers: Readonly<Record<string, string>>;
|
|
693
|
+
method: "PUT";
|
|
694
|
+
uploadId: string;
|
|
695
|
+
url: string;
|
|
696
|
+
}>;
|
|
632
697
|
/** A logical write retains its key, payload and edited revision on explicit resubmission. */
|
|
633
698
|
export interface EntityClient<Value, Create = Value, Patch = Partial<Value>> {
|
|
634
699
|
readonly definition: ResourceDefinition<Value, Create, Patch>;
|
|
635
700
|
readonly list: (query: EntityListQuery, options?: ResourceRequestOptions) => Promise<ResourceResult<EntityPage<Value>>>;
|
|
636
701
|
readonly get: (input: Readonly<{
|
|
637
702
|
id: ResourceRecordId;
|
|
703
|
+
include?: readonly string[];
|
|
638
704
|
}>, options?: ResourceRequestOptions) => Promise<ResourceResult<ResourceRecord<Value>>>;
|
|
639
705
|
readonly create: (input: EntityCreateInput<Create>) => Promise<ResourceResult<ResourceRecord<Value>>>;
|
|
640
706
|
readonly update: (input: EntityUpdateInput<Patch>) => Promise<ResourceResult<ResourceRecord<Value>>>;
|
|
641
707
|
readonly delete: (input: EntityDeleteInput) => Promise<ResourceResult<ResourceRecord<Value>>>;
|
|
708
|
+
/** A single-use File upload slot; requires the `upload` capability. */
|
|
709
|
+
readonly upload: (input: EntityUploadInput, options?: ResourceRequestOptions) => Promise<ResourceResult<EntityUploadSlot>>;
|
|
642
710
|
}
|
|
643
711
|
export type CiStreamPage = ClientOperationOutput<ClientOperationMap, "runs_stream">;
|
|
644
712
|
export type FollowRunOptions = Readonly<{
|
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-yhe7hpfh.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-cehy1gv3.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
|
@@ -54,6 +54,8 @@ export type ResourceCapabilities = Readonly<{
|
|
|
54
54
|
search: true;
|
|
55
55
|
softDelete?: boolean;
|
|
56
56
|
update?: boolean;
|
|
57
|
+
/** File uploads for the File fields of a common entity resource. */
|
|
58
|
+
upload?: boolean;
|
|
57
59
|
}>;
|
|
58
60
|
export type ResourcePaginationMode = "cursor" | "page";
|
|
59
61
|
export type PortableResourceSchema = Readonly<Record<string, ResourceJsonValue>>;
|
|
@@ -91,13 +93,21 @@ export type ResourceDefinition<Entity, Create = Entity, Update = Partial<Entity>
|
|
|
91
93
|
}>;
|
|
92
94
|
}>;
|
|
93
95
|
export type FilterValue = ResourceJsonValue | readonly ResourceJsonValue[];
|
|
96
|
+
/**
|
|
97
|
+
* A filter predicate. `field` names a declared filterable field, or a path
|
|
98
|
+
* through at most three fields that hold Entity References to a field of
|
|
99
|
+
* the last target, such as `company.industry` or
|
|
100
|
+
* `contacts.company.parent.industry`. On a field that holds Entity
|
|
101
|
+
* References, `is_empty` means no reference, and `contains_any` and
|
|
102
|
+
* `contains_all` compare the ids of a field that holds many.
|
|
103
|
+
*/
|
|
94
104
|
export type ResourceFilter = Readonly<{
|
|
95
105
|
field: string;
|
|
96
|
-
operator: "contains" | "ends_with" | "eq" | "gt" | "gte" | "in" | "lt" | "lte" | "ne" | "not_in" | "starts_with";
|
|
106
|
+
operator: "contains" | "contains_all" | "contains_any" | "ends_with" | "eq" | "gt" | "gte" | "in" | "lt" | "lte" | "ne" | "not_in" | "starts_with";
|
|
97
107
|
value: FilterValue;
|
|
98
108
|
}> | Readonly<{
|
|
99
109
|
field: string;
|
|
100
|
-
operator: "is_not_null" | "is_null";
|
|
110
|
+
operator: "is_empty" | "is_not_null" | "is_null";
|
|
101
111
|
}> | Readonly<{
|
|
102
112
|
filters: readonly ResourceFilter[];
|
|
103
113
|
operator: "and" | "or";
|
|
@@ -120,6 +130,11 @@ export type ResourcePagination = Readonly<{
|
|
|
120
130
|
}>;
|
|
121
131
|
export type ResourceListQuery = Readonly<{
|
|
122
132
|
filter?: ResourceFilter;
|
|
133
|
+
/**
|
|
134
|
+
* Include Paths, such as `["company", "contacts.company"]`: relation
|
|
135
|
+
* fields whose records each item carries in `included`.
|
|
136
|
+
*/
|
|
137
|
+
include?: readonly string[];
|
|
123
138
|
includeDeleted?: boolean;
|
|
124
139
|
pagination: ResourcePagination;
|
|
125
140
|
sort?: readonly ResourceSort[];
|
|
@@ -128,7 +143,15 @@ export type ResourceListQuery = Readonly<{
|
|
|
128
143
|
export type ResourceRecord<Entity> = Readonly<{
|
|
129
144
|
deletedAt?: string;
|
|
130
145
|
id: ResourceRecordId;
|
|
146
|
+
/**
|
|
147
|
+
* The records of the read's Include Paths by relation field key: one
|
|
148
|
+
* record, or the records of a `many` field in reference order. Untyped:
|
|
149
|
+
* the target schemas are CI's.
|
|
150
|
+
*/
|
|
151
|
+
included?: Readonly<Record<string, ResourceJsonValue>>;
|
|
131
152
|
revision: ResourceRevision;
|
|
153
|
+
/** The keys whose included records were cut to the first 100. */
|
|
154
|
+
truncated?: readonly string[];
|
|
132
155
|
value: Entity;
|
|
133
156
|
}>;
|
|
134
157
|
export type ResourceListResult<Entity> = Readonly<{
|
|
@@ -143,7 +166,9 @@ export type ResourceListResult<Entity> = Readonly<{
|
|
|
143
166
|
totalItems: number;
|
|
144
167
|
totalPages: number;
|
|
145
168
|
}>;
|
|
146
|
-
export type ResourceErrorCode = "capability_not_supported" | "conflict" | "forbidden" | "internal" | "invalid_request" | "not_found" | "rate_limited" | "transport_error" | "unauthenticated" | "unavailable"
|
|
169
|
+
export type ResourceErrorCode = "capability_not_supported" | "conflict" | "forbidden" | "internal" | "invalid_request" | "not_found" | "rate_limited" | "transport_error" | "unauthenticated" | "unavailable" |
|
|
170
|
+
/** The CI Organization storage can not take a presigned File upload. */
|
|
171
|
+
"upload_not_supported";
|
|
147
172
|
export type ResourceError = Readonly<{
|
|
148
173
|
code: ResourceErrorCode;
|
|
149
174
|
/** Client-observed dispatch outcome; uncertainty never proves rollback. */
|
|
@@ -208,16 +233,32 @@ export type EntityUpdateInput<Patch> = ResourceMutationInput<Patch> & Readonly<{
|
|
|
208
233
|
export type EntityDeleteInput = ResourceLifecycleInput & Readonly<{
|
|
209
234
|
idempotencyKey: IdempotencyKey;
|
|
210
235
|
}>;
|
|
236
|
+
/** A File upload request for one File field of the entity schema. */
|
|
237
|
+
export type EntityUploadInput = Readonly<{
|
|
238
|
+
field: string;
|
|
239
|
+
filename: string;
|
|
240
|
+
mimeType: string;
|
|
241
|
+
}>;
|
|
242
|
+
/** PUT the file bytes to `url` with `headers`; then write `{ upload: uploadId }`. */
|
|
243
|
+
export type EntityUploadSlot = Readonly<{
|
|
244
|
+
headers: Readonly<Record<string, string>>;
|
|
245
|
+
method: "PUT";
|
|
246
|
+
uploadId: string;
|
|
247
|
+
url: string;
|
|
248
|
+
}>;
|
|
211
249
|
/** A logical write retains its key, payload and edited revision on explicit resubmission. */
|
|
212
250
|
export interface EntityClient<Value, Create = Value, Patch = Partial<Value>> {
|
|
213
251
|
readonly definition: ResourceDefinition<Value, Create, Patch>;
|
|
214
252
|
readonly list: (query: EntityListQuery, options?: ResourceRequestOptions) => Promise<ResourceResult<EntityPage<Value>>>;
|
|
215
253
|
readonly get: (input: Readonly<{
|
|
216
254
|
id: ResourceRecordId;
|
|
255
|
+
include?: readonly string[];
|
|
217
256
|
}>, options?: ResourceRequestOptions) => Promise<ResourceResult<ResourceRecord<Value>>>;
|
|
218
257
|
readonly create: (input: EntityCreateInput<Create>) => Promise<ResourceResult<ResourceRecord<Value>>>;
|
|
219
258
|
readonly update: (input: EntityUpdateInput<Patch>) => Promise<ResourceResult<ResourceRecord<Value>>>;
|
|
220
259
|
readonly delete: (input: EntityDeleteInput) => Promise<ResourceResult<ResourceRecord<Value>>>;
|
|
260
|
+
/** A single-use File upload slot; requires the `upload` capability. */
|
|
261
|
+
readonly upload: (input: EntityUploadInput, options?: ResourceRequestOptions) => Promise<ResourceResult<EntityUploadSlot>>;
|
|
221
262
|
}
|
|
222
263
|
export declare class ResourceQueryError extends Error {
|
|
223
264
|
readonly correlationId: string;
|
|
@@ -396,12 +437,15 @@ export declare const useEntityList: <Value, Create, Patch>(contract: ResourceDef
|
|
|
396
437
|
search: true;
|
|
397
438
|
softDelete?: boolean;
|
|
398
439
|
update?: boolean;
|
|
440
|
+
upload?: boolean;
|
|
399
441
|
}>;
|
|
400
442
|
data: NoInfer<Readonly<{
|
|
401
443
|
items: readonly Readonly<{
|
|
402
444
|
deletedAt?: string;
|
|
403
445
|
id: ResourceRecordId;
|
|
446
|
+
included?: Readonly<Record<string, ResourceJsonValue>>;
|
|
404
447
|
revision: ResourceRevision;
|
|
448
|
+
truncated?: readonly string[];
|
|
405
449
|
value: Value;
|
|
406
450
|
}>[];
|
|
407
451
|
page: number;
|
|
@@ -430,11 +474,14 @@ export declare const useEntityRecord: <Value, Create, Patch>(contract: ResourceD
|
|
|
430
474
|
search: true;
|
|
431
475
|
softDelete?: boolean;
|
|
432
476
|
update?: boolean;
|
|
477
|
+
upload?: boolean;
|
|
433
478
|
}>;
|
|
434
479
|
data: NoInfer<Readonly<{
|
|
435
480
|
deletedAt?: string;
|
|
436
481
|
id: ResourceRecordId;
|
|
482
|
+
included?: Readonly<Record<string, ResourceJsonValue>>;
|
|
437
483
|
revision: ResourceRevision;
|
|
484
|
+
truncated?: readonly string[];
|
|
438
485
|
value: Value;
|
|
439
486
|
}>> | undefined;
|
|
440
487
|
error: Error | null;
|
|
@@ -449,7 +496,9 @@ export declare const useEntityUpdate: <Value, Create, Patch>(contract: ResourceD
|
|
|
449
496
|
data: Readonly<{
|
|
450
497
|
deletedAt?: string;
|
|
451
498
|
id: ResourceRecordId;
|
|
499
|
+
included?: Readonly<Record<string, ResourceJsonValue>>;
|
|
452
500
|
revision: ResourceRevision;
|
|
501
|
+
truncated?: readonly string[];
|
|
453
502
|
value: Value;
|
|
454
503
|
}> | undefined;
|
|
455
504
|
error: ResourceQueryError | null;
|
|
@@ -457,14 +506,18 @@ export declare const useEntityUpdate: <Value, Create, Patch>(contract: ResourceD
|
|
|
457
506
|
resubmit: () => Promise<ResourceResult<Readonly<{
|
|
458
507
|
deletedAt?: string;
|
|
459
508
|
id: ResourceRecordId;
|
|
509
|
+
included?: Readonly<Record<string, ResourceJsonValue>>;
|
|
460
510
|
revision: ResourceRevision;
|
|
511
|
+
truncated?: readonly string[];
|
|
461
512
|
value: Value;
|
|
462
513
|
}>>>;
|
|
463
514
|
status: "pending" | "success" | "idle" | "conflict" | "uncertain" | "rejected";
|
|
464
515
|
submit: (input: Omit<EntityUpdateInput<Patch>, "id" | "idempotencyKey">) => Promise<ResourceResult<Readonly<{
|
|
465
516
|
deletedAt?: string;
|
|
466
517
|
id: ResourceRecordId;
|
|
518
|
+
included?: Readonly<Record<string, ResourceJsonValue>>;
|
|
467
519
|
revision: ResourceRevision;
|
|
520
|
+
truncated?: readonly string[];
|
|
468
521
|
value: Value;
|
|
469
522
|
}>>>;
|
|
470
523
|
submitted: EntityUpdateInput<Patch> | undefined;
|
|
@@ -474,7 +527,9 @@ export declare const useEntityCreate: <Value, Create, Patch>(contract: ResourceD
|
|
|
474
527
|
data: Readonly<{
|
|
475
528
|
deletedAt?: string;
|
|
476
529
|
id: ResourceRecordId;
|
|
530
|
+
included?: Readonly<Record<string, ResourceJsonValue>>;
|
|
477
531
|
revision: ResourceRevision;
|
|
532
|
+
truncated?: readonly string[];
|
|
478
533
|
value: Value;
|
|
479
534
|
}> | undefined;
|
|
480
535
|
error: ResourceQueryError | null;
|
|
@@ -482,7 +537,9 @@ export declare const useEntityCreate: <Value, Create, Patch>(contract: ResourceD
|
|
|
482
537
|
resubmit: () => Promise<ResourceResult<Readonly<{
|
|
483
538
|
deletedAt?: string;
|
|
484
539
|
id: ResourceRecordId;
|
|
540
|
+
included?: Readonly<Record<string, ResourceJsonValue>>;
|
|
485
541
|
revision: ResourceRevision;
|
|
542
|
+
truncated?: readonly string[];
|
|
486
543
|
value: Value;
|
|
487
544
|
}>>>;
|
|
488
545
|
status: "pending" | "success" | "idle" | "conflict" | "uncertain" | "rejected";
|
|
@@ -492,7 +549,9 @@ export declare const useEntityCreate: <Value, Create, Patch>(contract: ResourceD
|
|
|
492
549
|
}>, "idempotencyKey">) => Promise<ResourceResult<Readonly<{
|
|
493
550
|
deletedAt?: string;
|
|
494
551
|
id: ResourceRecordId;
|
|
552
|
+
included?: Readonly<Record<string, ResourceJsonValue>>;
|
|
495
553
|
revision: ResourceRevision;
|
|
554
|
+
truncated?: readonly string[];
|
|
496
555
|
value: Value;
|
|
497
556
|
}>>>;
|
|
498
557
|
submitted: Readonly<{
|
|
@@ -507,7 +566,9 @@ export declare const useEntityDelete: <Value, Create, Patch>(contract: ResourceD
|
|
|
507
566
|
data: Readonly<{
|
|
508
567
|
deletedAt?: string;
|
|
509
568
|
id: ResourceRecordId;
|
|
569
|
+
included?: Readonly<Record<string, ResourceJsonValue>>;
|
|
510
570
|
revision: ResourceRevision;
|
|
571
|
+
truncated?: readonly string[];
|
|
511
572
|
value: Value;
|
|
512
573
|
}> | undefined;
|
|
513
574
|
error: ResourceQueryError | null;
|
|
@@ -515,14 +576,18 @@ export declare const useEntityDelete: <Value, Create, Patch>(contract: ResourceD
|
|
|
515
576
|
resubmit: () => Promise<ResourceResult<Readonly<{
|
|
516
577
|
deletedAt?: string;
|
|
517
578
|
id: ResourceRecordId;
|
|
579
|
+
included?: Readonly<Record<string, ResourceJsonValue>>;
|
|
518
580
|
revision: ResourceRevision;
|
|
581
|
+
truncated?: readonly string[];
|
|
519
582
|
value: Value;
|
|
520
583
|
}>>>;
|
|
521
584
|
status: "pending" | "success" | "idle" | "conflict" | "uncertain" | "rejected";
|
|
522
585
|
submit: (input: Omit<EntityDeleteInput, "id" | "idempotencyKey">) => Promise<ResourceResult<Readonly<{
|
|
523
586
|
deletedAt?: string;
|
|
524
587
|
id: ResourceRecordId;
|
|
588
|
+
included?: Readonly<Record<string, ResourceJsonValue>>;
|
|
525
589
|
revision: ResourceRevision;
|
|
590
|
+
truncated?: readonly string[];
|
|
526
591
|
value: Value;
|
|
527
592
|
}>>>;
|
|
528
593
|
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-cehy1gv3.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.10",
|
|
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.10",
|
|
52
|
+
"@collective-intelligence/ui-react": "0.1.10",
|
|
53
53
|
"@oxlint/plugins": "1.85.0",
|
|
54
54
|
"@tanstack/react-router": "1.170.30",
|
|
55
55
|
"@tanstack/react-start": "1.168.47",
|