@joai/sdk 0.5.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +145 -1
- package/dist/index.mjs +167 -2
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -490,6 +490,7 @@ type Contact = {
|
|
|
490
490
|
socials: Record<string, string> | null;
|
|
491
491
|
notes: string | null;
|
|
492
492
|
tags: string[] | null;
|
|
493
|
+
userId: string | null;
|
|
493
494
|
props?: Record<string, string> | null;
|
|
494
495
|
};
|
|
495
496
|
type ContactActivity = {
|
|
@@ -612,6 +613,8 @@ type Memory = {
|
|
|
612
613
|
name: string;
|
|
613
614
|
content: string;
|
|
614
615
|
createdAt: string;
|
|
616
|
+
contactId: string | null;
|
|
617
|
+
roomId: string | null;
|
|
615
618
|
}; //#endregion
|
|
616
619
|
//#region src/peerme/types.d.ts
|
|
617
620
|
type ChatClientAction = 'AGENT_DELEGATE' | 'WARP_EXECUTE' | 'WARP_VIEW' | 'WARP_CREATE' | 'WARP_TEST' | 'WARP_INPUT' | 'WARP_APPROVE' | 'WARP_SELECT' | 'WARP_BATCH' | 'WARP_BULK' | 'ENTITY_PROPOSE' | 'ENTITY_SIGN' | 'SECRET_SET' | 'SECRET_AUTHORIZE' | 'HEALTH_QUERY' | 'HEALTH_WRITE' | 'ITEM_VIEW' | 'BOARD_SUMMARY' | 'GOAL_PROGRESS' | 'CONTACT_VIEW' | 'MARKETPLACE_PURCHASE' | 'WARP_CLOUD_EXECUTE' | 'MISSION_VIEW' | 'ACTIVITY' | 'PERSONA_QUESTION' | 'NFC_WRITE' | 'twilio.sms';
|
|
@@ -699,6 +702,79 @@ type BrandSiteConfig = {
|
|
|
699
702
|
logoUrl?: string | null;
|
|
700
703
|
};
|
|
701
704
|
//#endregion
|
|
705
|
+
//#region src/store/types.d.ts
|
|
706
|
+
type StoreVisibility = 'private' | 'team' | 'public';
|
|
707
|
+
type StoreEntry = {
|
|
708
|
+
value: number | string | boolean;
|
|
709
|
+
label?: string;
|
|
710
|
+
at: string;
|
|
711
|
+
};
|
|
712
|
+
type Store = {
|
|
713
|
+
name: string;
|
|
714
|
+
description: string;
|
|
715
|
+
valueType: 'scalar' | 'series';
|
|
716
|
+
unit?: string;
|
|
717
|
+
visibility: StoreVisibility;
|
|
718
|
+
entryCount: number;
|
|
719
|
+
lastValue?: number | string | boolean;
|
|
720
|
+
lastAt?: string;
|
|
721
|
+
};
|
|
722
|
+
type StoreWithEntries = {
|
|
723
|
+
name: string;
|
|
724
|
+
description: string;
|
|
725
|
+
unit?: string;
|
|
726
|
+
entries: StoreEntry[];
|
|
727
|
+
};
|
|
728
|
+
type StoreCreatePayload = {
|
|
729
|
+
name: string;
|
|
730
|
+
description?: string;
|
|
731
|
+
valueType?: 'scalar' | 'series';
|
|
732
|
+
unit?: string;
|
|
733
|
+
visibility?: StoreVisibility;
|
|
734
|
+
};
|
|
735
|
+
type StoreEntryPayload = {
|
|
736
|
+
storeName?: string;
|
|
737
|
+
value: number | string | boolean;
|
|
738
|
+
label?: string;
|
|
739
|
+
};
|
|
740
|
+
type StoreEntryResult = {
|
|
741
|
+
name: string;
|
|
742
|
+
entryCount: number;
|
|
743
|
+
};
|
|
744
|
+
type StoreToggleResult = {
|
|
745
|
+
name: string;
|
|
746
|
+
value: number | string | boolean;
|
|
747
|
+
previous: number | string | boolean;
|
|
748
|
+
}; //#endregion
|
|
749
|
+
//#region src/update/types.d.ts
|
|
750
|
+
type UpdateType = 'deal' | 'event' | 'update';
|
|
751
|
+
type UpdateStatus = 'draft' | 'published' | 'archived';
|
|
752
|
+
type Update = {
|
|
753
|
+
id: string;
|
|
754
|
+
type: UpdateType;
|
|
755
|
+
status: UpdateStatus;
|
|
756
|
+
title: string;
|
|
757
|
+
body: string | null;
|
|
758
|
+
imageUrl: string | null;
|
|
759
|
+
linkUrl: string | null;
|
|
760
|
+
startsAt: string | null;
|
|
761
|
+
endsAt: string | null;
|
|
762
|
+
createdAt: string;
|
|
763
|
+
updatedAt: string;
|
|
764
|
+
};
|
|
765
|
+
type UpdateCreatePayload = {
|
|
766
|
+
title: string;
|
|
767
|
+
type: UpdateType;
|
|
768
|
+
body?: string;
|
|
769
|
+
imageUrl?: string;
|
|
770
|
+
linkUrl?: string;
|
|
771
|
+
startsAt?: string;
|
|
772
|
+
endsAt?: string;
|
|
773
|
+
status?: UpdateStatus;
|
|
774
|
+
};
|
|
775
|
+
type UpdateUpdatePayload = Partial<UpdateCreatePayload>; //#endregion
|
|
776
|
+
//#region src/swarm/types.d.ts
|
|
777
|
+
//#endregion
|
|
702
778
|
//#region src/resources/agents.d.ts
|
|
703
779
|
declare class AgentsResource {
|
|
704
780
|
private readonly http;
|
|
@@ -927,6 +1003,41 @@ declare class TeamsResource {
|
|
|
927
1003
|
}): Promise<IAppResponse<unknown>>;
|
|
928
1004
|
}
|
|
929
1005
|
//#endregion
|
|
1006
|
+
//#region src/resources/stores.d.ts
|
|
1007
|
+
declare class StoresResource {
|
|
1008
|
+
private readonly http;
|
|
1009
|
+
constructor(http: IHttpService);
|
|
1010
|
+
list(): Promise<IAppResponse<{
|
|
1011
|
+
data: Store[];
|
|
1012
|
+
}>>;
|
|
1013
|
+
create(payload: StoreCreatePayload): Promise<IAppResponse<Store>>;
|
|
1014
|
+
entries(params?: {
|
|
1015
|
+
storeName?: string;
|
|
1016
|
+
since?: string;
|
|
1017
|
+
until?: string;
|
|
1018
|
+
last?: number;
|
|
1019
|
+
}): Promise<IAppResponse<StoreWithEntries>>;
|
|
1020
|
+
setEntry(payload: StoreEntryPayload): Promise<IAppResponse<StoreEntryResult>>;
|
|
1021
|
+
appendEntry(payload: StoreEntryPayload): Promise<IAppResponse<StoreEntryResult>>;
|
|
1022
|
+
toggle(storeName?: string): Promise<IAppResponse<StoreToggleResult>>;
|
|
1023
|
+
delete(storeName: string): Promise<IAppResponse<unknown>>;
|
|
1024
|
+
}
|
|
1025
|
+
//#endregion
|
|
1026
|
+
//#region src/resources/updates.d.ts
|
|
1027
|
+
declare class UpdatesResource {
|
|
1028
|
+
private readonly http;
|
|
1029
|
+
constructor(http: IHttpService);
|
|
1030
|
+
list(params?: {
|
|
1031
|
+
type?: UpdateType;
|
|
1032
|
+
active?: boolean;
|
|
1033
|
+
}): Promise<IAppResponse<{
|
|
1034
|
+
data: Update[];
|
|
1035
|
+
}>>;
|
|
1036
|
+
create(payload: UpdateCreatePayload): Promise<IAppResponse<Update>>;
|
|
1037
|
+
update(id: string, payload: UpdateUpdatePayload): any;
|
|
1038
|
+
delete(id: string): Promise<IAppResponse<unknown>>;
|
|
1039
|
+
}
|
|
1040
|
+
//#endregion
|
|
930
1041
|
//#region src/resources/warps.d.ts
|
|
931
1042
|
type WarpResponseData = {
|
|
932
1043
|
id: string;
|
|
@@ -954,12 +1065,20 @@ declare class WarpsResource {
|
|
|
954
1065
|
destroy(identifier: string): Promise<IAppResponse<unknown>>;
|
|
955
1066
|
}
|
|
956
1067
|
//#endregion
|
|
1068
|
+
//#region src/cache/types.d.ts
|
|
1069
|
+
interface CacheConfig {
|
|
1070
|
+
enabled?: boolean;
|
|
1071
|
+
defaultTtl?: number;
|
|
1072
|
+
overrides?: Record<string, number>;
|
|
1073
|
+
}
|
|
1074
|
+
//#endregion
|
|
957
1075
|
//#region src/client.d.ts
|
|
958
1076
|
interface JoAiClientConfig {
|
|
959
1077
|
apiToken?: string;
|
|
960
1078
|
team?: string;
|
|
961
1079
|
env?: AppEnv;
|
|
962
1080
|
agentAuthKey?: string;
|
|
1081
|
+
cache?: CacheConfig;
|
|
963
1082
|
}
|
|
964
1083
|
declare class JoAiClient {
|
|
965
1084
|
readonly http: IHttpService;
|
|
@@ -982,16 +1101,41 @@ declare class JoAiClient {
|
|
|
982
1101
|
readonly sites: SitesResource;
|
|
983
1102
|
readonly documents: DocumentsResource;
|
|
984
1103
|
readonly meetings: MeetingsResource;
|
|
1104
|
+
readonly stores: StoresResource;
|
|
1105
|
+
readonly updates: UpdatesResource;
|
|
985
1106
|
readonly privateWarps: WarpsResource;
|
|
986
1107
|
constructor(config: JoAiClientConfig);
|
|
1108
|
+
clearCache(): void;
|
|
987
1109
|
warps(locale?: WarpLocale): WarpClient;
|
|
988
1110
|
}
|
|
989
1111
|
declare function createClient(config: JoAiClientConfig): JoAiClient;
|
|
990
1112
|
//#endregion
|
|
1113
|
+
//#region src/cache/cached-http.d.ts
|
|
1114
|
+
type TtlMap = Record<string, number>;
|
|
1115
|
+
declare class CachedHttpService implements IHttpService {
|
|
1116
|
+
private inner;
|
|
1117
|
+
readonly baseUrl: string;
|
|
1118
|
+
readonly authToken: string | null;
|
|
1119
|
+
private cache;
|
|
1120
|
+
private ttlMap;
|
|
1121
|
+
private defaultTtl;
|
|
1122
|
+
onNetworkError: (error: Error) => void;
|
|
1123
|
+
onUnauthorized: (response: IAppResponse<any>) => void;
|
|
1124
|
+
onSuccessfulResponse: (response: IAppResponse<any>) => void;
|
|
1125
|
+
onMaintenanceMode: (response: IAppResponse<any>) => void;
|
|
1126
|
+
onTooManyRequests: (response: IAppResponse<any>) => void;
|
|
1127
|
+
constructor(inner: IHttpService, overrides?: TtlMap, defaultTtl?: number);
|
|
1128
|
+
clearCache(): void;
|
|
1129
|
+
get<T>(url: string, options?: IRequestOptions): Promise<IAppResponse<T>>;
|
|
1130
|
+
post<T>(url: string, data?: any, options?: IRequestOptions): Promise<IAppResponse<T>>;
|
|
1131
|
+
put<T>(url: string, data?: any, options?: IRequestOptions): Promise<IAppResponse<T>>;
|
|
1132
|
+
delete<T>(url: string, options?: IRequestOptions): Promise<IAppResponse<T>>;
|
|
1133
|
+
}
|
|
1134
|
+
//#endregion
|
|
991
1135
|
//#region src/resources/distribution.d.ts
|
|
992
1136
|
declare class DistributionResource {
|
|
993
1137
|
getBrandSiteConfig(env: AppEnv, brandSlug: string): Promise<BrandSiteConfig | null>;
|
|
994
1138
|
private fetchDistribution;
|
|
995
1139
|
}
|
|
996
1140
|
//#endregion
|
|
997
|
-
export { BlueprintsResource, DistributionResource, FlowsResource, IngestionsResource, JoAiClient, type JoAiClientConfig, MarketplaceResource, MeetingsResource, ServicesResource, SitesResource, SkillsResource, createClient };
|
|
1141
|
+
export { BlueprintsResource, type CacheConfig, CachedHttpService, DistributionResource, FlowsResource, IngestionsResource, JoAiClient, type JoAiClientConfig, MarketplaceResource, MeetingsResource, ServicesResource, SitesResource, SkillsResource, StoresResource, createClient };
|
package/dist/index.mjs
CHANGED
|
@@ -458,6 +458,63 @@ var TeamsResource = class {
|
|
|
458
458
|
}
|
|
459
459
|
};
|
|
460
460
|
//#endregion
|
|
461
|
+
//#region src/resources/stores.ts
|
|
462
|
+
var StoresResource = class {
|
|
463
|
+
constructor(http) {
|
|
464
|
+
this.http = http;
|
|
465
|
+
}
|
|
466
|
+
list() {
|
|
467
|
+
return this.http.get("stores");
|
|
468
|
+
}
|
|
469
|
+
create(payload) {
|
|
470
|
+
return this.http.post("stores", payload);
|
|
471
|
+
}
|
|
472
|
+
entries(params) {
|
|
473
|
+
const query = new URLSearchParams();
|
|
474
|
+
if (params?.storeName) query.set("storeName", params.storeName);
|
|
475
|
+
if (params?.since) query.set("since", params.since);
|
|
476
|
+
if (params?.until) query.set("until", params.until);
|
|
477
|
+
if (params?.last != null) query.set("last", String(params.last));
|
|
478
|
+
const qs = query.toString();
|
|
479
|
+
return this.http.get(`stores/entries${qs ? "?" + qs : ""}`);
|
|
480
|
+
}
|
|
481
|
+
setEntry(payload) {
|
|
482
|
+
return this.http.post("stores/entries", payload);
|
|
483
|
+
}
|
|
484
|
+
appendEntry(payload) {
|
|
485
|
+
return this.http.post("stores/entries/append", payload);
|
|
486
|
+
}
|
|
487
|
+
toggle(storeName) {
|
|
488
|
+
return this.http.post("stores/toggle", { storeName });
|
|
489
|
+
}
|
|
490
|
+
delete(storeName) {
|
|
491
|
+
return this.http.delete(`stores/${storeName}`);
|
|
492
|
+
}
|
|
493
|
+
};
|
|
494
|
+
//#endregion
|
|
495
|
+
//#region src/resources/updates.ts
|
|
496
|
+
var UpdatesResource = class {
|
|
497
|
+
constructor(http) {
|
|
498
|
+
this.http = http;
|
|
499
|
+
}
|
|
500
|
+
list(params) {
|
|
501
|
+
const query = new URLSearchParams();
|
|
502
|
+
if (params?.type) query.set("type", params.type);
|
|
503
|
+
if (params?.active != null) query.set("active", String(params.active));
|
|
504
|
+
const qs = query.toString();
|
|
505
|
+
return this.http.get(`updates${qs ? "?" + qs : ""}`);
|
|
506
|
+
}
|
|
507
|
+
create(payload) {
|
|
508
|
+
return this.http.post("updates", payload);
|
|
509
|
+
}
|
|
510
|
+
update(id, payload) {
|
|
511
|
+
return this.http.patch(`updates/${id}`, payload);
|
|
512
|
+
}
|
|
513
|
+
delete(id) {
|
|
514
|
+
return this.http.delete(`updates/${id}`);
|
|
515
|
+
}
|
|
516
|
+
};
|
|
517
|
+
//#endregion
|
|
461
518
|
//#region src/resources/warps.ts
|
|
462
519
|
var WarpsResource = class {
|
|
463
520
|
constructor(http) {
|
|
@@ -478,6 +535,107 @@ var WarpsResource = class {
|
|
|
478
535
|
}
|
|
479
536
|
};
|
|
480
537
|
//#endregion
|
|
538
|
+
//#region src/cache/memory-cache.ts
|
|
539
|
+
var MemoryCache = class {
|
|
540
|
+
constructor() {
|
|
541
|
+
this.store = /* @__PURE__ */ new Map();
|
|
542
|
+
}
|
|
543
|
+
get(key) {
|
|
544
|
+
const entry = this.store.get(key);
|
|
545
|
+
if (!entry) return void 0;
|
|
546
|
+
if (Date.now() > entry.expiresAt) {
|
|
547
|
+
this.store.delete(key);
|
|
548
|
+
return;
|
|
549
|
+
}
|
|
550
|
+
return entry.data;
|
|
551
|
+
}
|
|
552
|
+
set(key, data, ttl) {
|
|
553
|
+
this.store.set(key, {
|
|
554
|
+
data,
|
|
555
|
+
expiresAt: Date.now() + ttl
|
|
556
|
+
});
|
|
557
|
+
}
|
|
558
|
+
clear() {
|
|
559
|
+
this.store.clear();
|
|
560
|
+
}
|
|
561
|
+
bust(prefix) {
|
|
562
|
+
for (const key of this.store.keys()) if (key.startsWith(prefix)) this.store.delete(key);
|
|
563
|
+
}
|
|
564
|
+
};
|
|
565
|
+
//#endregion
|
|
566
|
+
//#region src/cache/cached-http.ts
|
|
567
|
+
const DEFAULT_TTL = 15e3;
|
|
568
|
+
const DEFAULTS = {
|
|
569
|
+
blueprints: 3e5,
|
|
570
|
+
flows: 3e5,
|
|
571
|
+
marketplace: 3e5,
|
|
572
|
+
skills: 3e5,
|
|
573
|
+
sites: 3e5,
|
|
574
|
+
stores: 3e4,
|
|
575
|
+
contacts: 3e4,
|
|
576
|
+
items: 3e4,
|
|
577
|
+
goals: 3e4,
|
|
578
|
+
memories: 3e4,
|
|
579
|
+
reminders: 3e4,
|
|
580
|
+
services: 3e4,
|
|
581
|
+
documents: 3e4,
|
|
582
|
+
ingestions: 3e4,
|
|
583
|
+
agents: 1e4,
|
|
584
|
+
rooms: 1e4
|
|
585
|
+
};
|
|
586
|
+
function getTtl(url, ttlMap, defaultTtl) {
|
|
587
|
+
for (const [prefix, ttl] of Object.entries(ttlMap)) if (url.startsWith(prefix) || url.startsWith(`/${prefix}`)) return ttl;
|
|
588
|
+
return defaultTtl;
|
|
589
|
+
}
|
|
590
|
+
function getUrlPrefix(url) {
|
|
591
|
+
const clean = url.startsWith("/") ? url.slice(1) : url;
|
|
592
|
+
const slash = clean.indexOf("/");
|
|
593
|
+
return slash > 0 ? clean.slice(0, slash) : clean;
|
|
594
|
+
}
|
|
595
|
+
var CachedHttpService = class {
|
|
596
|
+
constructor(inner, overrides, defaultTtl) {
|
|
597
|
+
this.inner = inner;
|
|
598
|
+
this.cache = new MemoryCache();
|
|
599
|
+
this.onNetworkError = () => {};
|
|
600
|
+
this.onUnauthorized = () => {};
|
|
601
|
+
this.onSuccessfulResponse = () => {};
|
|
602
|
+
this.onMaintenanceMode = () => {};
|
|
603
|
+
this.onTooManyRequests = () => {};
|
|
604
|
+
this.baseUrl = inner.baseUrl;
|
|
605
|
+
this.authToken = inner.authToken;
|
|
606
|
+
this.ttlMap = {
|
|
607
|
+
...DEFAULTS,
|
|
608
|
+
...overrides
|
|
609
|
+
};
|
|
610
|
+
this.defaultTtl = defaultTtl ?? DEFAULT_TTL;
|
|
611
|
+
}
|
|
612
|
+
clearCache() {
|
|
613
|
+
this.cache.clear();
|
|
614
|
+
}
|
|
615
|
+
async get(url, options) {
|
|
616
|
+
const cached = this.cache.get(url);
|
|
617
|
+
if (cached !== void 0) return cached;
|
|
618
|
+
const response = await this.inner.get(url, options);
|
|
619
|
+
if (response.ok) this.cache.set(url, response, getTtl(url, this.ttlMap, this.defaultTtl));
|
|
620
|
+
return response;
|
|
621
|
+
}
|
|
622
|
+
async post(url, data, options) {
|
|
623
|
+
const response = await this.inner.post(url, data, options);
|
|
624
|
+
this.cache.bust(getUrlPrefix(url));
|
|
625
|
+
return response;
|
|
626
|
+
}
|
|
627
|
+
async put(url, data, options) {
|
|
628
|
+
const response = await this.inner.put(url, data, options);
|
|
629
|
+
this.cache.bust(getUrlPrefix(url));
|
|
630
|
+
return response;
|
|
631
|
+
}
|
|
632
|
+
async delete(url, options) {
|
|
633
|
+
const response = await this.inner.delete(url, options);
|
|
634
|
+
this.cache.bust(getUrlPrefix(url));
|
|
635
|
+
return response;
|
|
636
|
+
}
|
|
637
|
+
};
|
|
638
|
+
//#endregion
|
|
481
639
|
//#region src/client.ts
|
|
482
640
|
function toWarpEnv(env) {
|
|
483
641
|
if (env === "devnet") return "devnet";
|
|
@@ -490,7 +648,9 @@ var JoAiClient = class {
|
|
|
490
648
|
const headers = {};
|
|
491
649
|
if (config.team) headers["X-Team"] = config.team;
|
|
492
650
|
if (config.agentAuthKey) headers["X-Agent-Auth-Key"] = config.agentAuthKey;
|
|
493
|
-
|
|
651
|
+
const http = new HttpService(`${getApiBaseUrl(config.env ?? "mainnet")}/v1`, void 0, config.apiToken, { headers });
|
|
652
|
+
const cache = config.cache;
|
|
653
|
+
this.http = cache?.enabled !== false ? new CachedHttpService(http, cache?.overrides, cache?.defaultTtl) : http;
|
|
494
654
|
this.hub = new HubResource(this.http);
|
|
495
655
|
this.teams = new TeamsResource(this.http);
|
|
496
656
|
this.agents = new AgentsResource(this.http);
|
|
@@ -509,8 +669,13 @@ var JoAiClient = class {
|
|
|
509
669
|
this.sites = new SitesResource(this.http);
|
|
510
670
|
this.documents = new DocumentsResource(this.http);
|
|
511
671
|
this.meetings = new MeetingsResource(this.http);
|
|
672
|
+
this.stores = new StoresResource(this.http);
|
|
673
|
+
this.updates = new UpdatesResource(this.http);
|
|
512
674
|
this.privateWarps = new WarpsResource(this.http);
|
|
513
675
|
}
|
|
676
|
+
clearCache() {
|
|
677
|
+
if (this.http instanceof CachedHttpService) this.http.clearCache();
|
|
678
|
+
}
|
|
514
679
|
warps(locale = "en") {
|
|
515
680
|
return new WarpClient({
|
|
516
681
|
env: toWarpEnv(this.env),
|
|
@@ -550,4 +715,4 @@ var DistributionResource = class {
|
|
|
550
715
|
}
|
|
551
716
|
};
|
|
552
717
|
//#endregion
|
|
553
|
-
export { BlueprintsResource, DistributionResource, FlowsResource, IngestionsResource, JoAiClient, MarketplaceResource, MeetingsResource, ServicesResource, SitesResource, SkillsResource, createClient };
|
|
718
|
+
export { BlueprintsResource, CachedHttpService, DistributionResource, FlowsResource, IngestionsResource, JoAiClient, MarketplaceResource, MeetingsResource, ServicesResource, SitesResource, SkillsResource, StoresResource, createClient };
|