@joai/sdk 0.5.0 → 0.6.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 +102 -1
- package/dist/index.mjs +143 -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,52 @@ 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/swarm/types.d.ts
|
|
750
|
+
//#endregion
|
|
702
751
|
//#region src/resources/agents.d.ts
|
|
703
752
|
declare class AgentsResource {
|
|
704
753
|
private readonly http;
|
|
@@ -927,6 +976,26 @@ declare class TeamsResource {
|
|
|
927
976
|
}): Promise<IAppResponse<unknown>>;
|
|
928
977
|
}
|
|
929
978
|
//#endregion
|
|
979
|
+
//#region src/resources/stores.d.ts
|
|
980
|
+
declare class StoresResource {
|
|
981
|
+
private readonly http;
|
|
982
|
+
constructor(http: IHttpService);
|
|
983
|
+
list(): Promise<IAppResponse<{
|
|
984
|
+
data: Store[];
|
|
985
|
+
}>>;
|
|
986
|
+
create(payload: StoreCreatePayload): Promise<IAppResponse<Store>>;
|
|
987
|
+
entries(params?: {
|
|
988
|
+
storeName?: string;
|
|
989
|
+
since?: string;
|
|
990
|
+
until?: string;
|
|
991
|
+
last?: number;
|
|
992
|
+
}): Promise<IAppResponse<StoreWithEntries>>;
|
|
993
|
+
setEntry(payload: StoreEntryPayload): Promise<IAppResponse<StoreEntryResult>>;
|
|
994
|
+
appendEntry(payload: StoreEntryPayload): Promise<IAppResponse<StoreEntryResult>>;
|
|
995
|
+
toggle(storeName?: string): Promise<IAppResponse<StoreToggleResult>>;
|
|
996
|
+
delete(storeName: string): Promise<IAppResponse<unknown>>;
|
|
997
|
+
}
|
|
998
|
+
//#endregion
|
|
930
999
|
//#region src/resources/warps.d.ts
|
|
931
1000
|
type WarpResponseData = {
|
|
932
1001
|
id: string;
|
|
@@ -954,12 +1023,20 @@ declare class WarpsResource {
|
|
|
954
1023
|
destroy(identifier: string): Promise<IAppResponse<unknown>>;
|
|
955
1024
|
}
|
|
956
1025
|
//#endregion
|
|
1026
|
+
//#region src/cache/types.d.ts
|
|
1027
|
+
interface CacheConfig {
|
|
1028
|
+
enabled?: boolean;
|
|
1029
|
+
defaultTtl?: number;
|
|
1030
|
+
overrides?: Record<string, number>;
|
|
1031
|
+
}
|
|
1032
|
+
//#endregion
|
|
957
1033
|
//#region src/client.d.ts
|
|
958
1034
|
interface JoAiClientConfig {
|
|
959
1035
|
apiToken?: string;
|
|
960
1036
|
team?: string;
|
|
961
1037
|
env?: AppEnv;
|
|
962
1038
|
agentAuthKey?: string;
|
|
1039
|
+
cache?: CacheConfig;
|
|
963
1040
|
}
|
|
964
1041
|
declare class JoAiClient {
|
|
965
1042
|
readonly http: IHttpService;
|
|
@@ -982,16 +1059,40 @@ declare class JoAiClient {
|
|
|
982
1059
|
readonly sites: SitesResource;
|
|
983
1060
|
readonly documents: DocumentsResource;
|
|
984
1061
|
readonly meetings: MeetingsResource;
|
|
1062
|
+
readonly stores: StoresResource;
|
|
985
1063
|
readonly privateWarps: WarpsResource;
|
|
986
1064
|
constructor(config: JoAiClientConfig);
|
|
1065
|
+
clearCache(): void;
|
|
987
1066
|
warps(locale?: WarpLocale): WarpClient;
|
|
988
1067
|
}
|
|
989
1068
|
declare function createClient(config: JoAiClientConfig): JoAiClient;
|
|
990
1069
|
//#endregion
|
|
1070
|
+
//#region src/cache/cached-http.d.ts
|
|
1071
|
+
type TtlMap = Record<string, number>;
|
|
1072
|
+
declare class CachedHttpService implements IHttpService {
|
|
1073
|
+
private inner;
|
|
1074
|
+
readonly baseUrl: string;
|
|
1075
|
+
readonly authToken: string | null;
|
|
1076
|
+
private cache;
|
|
1077
|
+
private ttlMap;
|
|
1078
|
+
private defaultTtl;
|
|
1079
|
+
onNetworkError: (error: Error) => void;
|
|
1080
|
+
onUnauthorized: (response: IAppResponse<any>) => void;
|
|
1081
|
+
onSuccessfulResponse: (response: IAppResponse<any>) => void;
|
|
1082
|
+
onMaintenanceMode: (response: IAppResponse<any>) => void;
|
|
1083
|
+
onTooManyRequests: (response: IAppResponse<any>) => void;
|
|
1084
|
+
constructor(inner: IHttpService, overrides?: TtlMap, defaultTtl?: number);
|
|
1085
|
+
clearCache(): void;
|
|
1086
|
+
get<T>(url: string, options?: IRequestOptions): Promise<IAppResponse<T>>;
|
|
1087
|
+
post<T>(url: string, data?: any, options?: IRequestOptions): Promise<IAppResponse<T>>;
|
|
1088
|
+
put<T>(url: string, data?: any, options?: IRequestOptions): Promise<IAppResponse<T>>;
|
|
1089
|
+
delete<T>(url: string, options?: IRequestOptions): Promise<IAppResponse<T>>;
|
|
1090
|
+
}
|
|
1091
|
+
//#endregion
|
|
991
1092
|
//#region src/resources/distribution.d.ts
|
|
992
1093
|
declare class DistributionResource {
|
|
993
1094
|
getBrandSiteConfig(env: AppEnv, brandSlug: string): Promise<BrandSiteConfig | null>;
|
|
994
1095
|
private fetchDistribution;
|
|
995
1096
|
}
|
|
996
1097
|
//#endregion
|
|
997
|
-
export { BlueprintsResource, DistributionResource, FlowsResource, IngestionsResource, JoAiClient, type JoAiClientConfig, MarketplaceResource, MeetingsResource, ServicesResource, SitesResource, SkillsResource, createClient };
|
|
1098
|
+
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,40 @@ 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
|
|
461
495
|
//#region src/resources/warps.ts
|
|
462
496
|
var WarpsResource = class {
|
|
463
497
|
constructor(http) {
|
|
@@ -478,6 +512,107 @@ var WarpsResource = class {
|
|
|
478
512
|
}
|
|
479
513
|
};
|
|
480
514
|
//#endregion
|
|
515
|
+
//#region src/cache/memory-cache.ts
|
|
516
|
+
var MemoryCache = class {
|
|
517
|
+
constructor() {
|
|
518
|
+
this.store = /* @__PURE__ */ new Map();
|
|
519
|
+
}
|
|
520
|
+
get(key) {
|
|
521
|
+
const entry = this.store.get(key);
|
|
522
|
+
if (!entry) return void 0;
|
|
523
|
+
if (Date.now() > entry.expiresAt) {
|
|
524
|
+
this.store.delete(key);
|
|
525
|
+
return;
|
|
526
|
+
}
|
|
527
|
+
return entry.data;
|
|
528
|
+
}
|
|
529
|
+
set(key, data, ttl) {
|
|
530
|
+
this.store.set(key, {
|
|
531
|
+
data,
|
|
532
|
+
expiresAt: Date.now() + ttl
|
|
533
|
+
});
|
|
534
|
+
}
|
|
535
|
+
clear() {
|
|
536
|
+
this.store.clear();
|
|
537
|
+
}
|
|
538
|
+
bust(prefix) {
|
|
539
|
+
for (const key of this.store.keys()) if (key.startsWith(prefix)) this.store.delete(key);
|
|
540
|
+
}
|
|
541
|
+
};
|
|
542
|
+
//#endregion
|
|
543
|
+
//#region src/cache/cached-http.ts
|
|
544
|
+
const DEFAULT_TTL = 15e3;
|
|
545
|
+
const DEFAULTS = {
|
|
546
|
+
blueprints: 3e5,
|
|
547
|
+
flows: 3e5,
|
|
548
|
+
marketplace: 3e5,
|
|
549
|
+
skills: 3e5,
|
|
550
|
+
sites: 3e5,
|
|
551
|
+
stores: 3e4,
|
|
552
|
+
contacts: 3e4,
|
|
553
|
+
items: 3e4,
|
|
554
|
+
goals: 3e4,
|
|
555
|
+
memories: 3e4,
|
|
556
|
+
reminders: 3e4,
|
|
557
|
+
services: 3e4,
|
|
558
|
+
documents: 3e4,
|
|
559
|
+
ingestions: 3e4,
|
|
560
|
+
agents: 1e4,
|
|
561
|
+
rooms: 1e4
|
|
562
|
+
};
|
|
563
|
+
function getTtl(url, ttlMap, defaultTtl) {
|
|
564
|
+
for (const [prefix, ttl] of Object.entries(ttlMap)) if (url.startsWith(prefix) || url.startsWith(`/${prefix}`)) return ttl;
|
|
565
|
+
return defaultTtl;
|
|
566
|
+
}
|
|
567
|
+
function getUrlPrefix(url) {
|
|
568
|
+
const clean = url.startsWith("/") ? url.slice(1) : url;
|
|
569
|
+
const slash = clean.indexOf("/");
|
|
570
|
+
return slash > 0 ? clean.slice(0, slash) : clean;
|
|
571
|
+
}
|
|
572
|
+
var CachedHttpService = class {
|
|
573
|
+
constructor(inner, overrides, defaultTtl) {
|
|
574
|
+
this.inner = inner;
|
|
575
|
+
this.cache = new MemoryCache();
|
|
576
|
+
this.onNetworkError = () => {};
|
|
577
|
+
this.onUnauthorized = () => {};
|
|
578
|
+
this.onSuccessfulResponse = () => {};
|
|
579
|
+
this.onMaintenanceMode = () => {};
|
|
580
|
+
this.onTooManyRequests = () => {};
|
|
581
|
+
this.baseUrl = inner.baseUrl;
|
|
582
|
+
this.authToken = inner.authToken;
|
|
583
|
+
this.ttlMap = {
|
|
584
|
+
...DEFAULTS,
|
|
585
|
+
...overrides
|
|
586
|
+
};
|
|
587
|
+
this.defaultTtl = defaultTtl ?? DEFAULT_TTL;
|
|
588
|
+
}
|
|
589
|
+
clearCache() {
|
|
590
|
+
this.cache.clear();
|
|
591
|
+
}
|
|
592
|
+
async get(url, options) {
|
|
593
|
+
const cached = this.cache.get(url);
|
|
594
|
+
if (cached !== void 0) return cached;
|
|
595
|
+
const response = await this.inner.get(url, options);
|
|
596
|
+
if (response.ok) this.cache.set(url, response, getTtl(url, this.ttlMap, this.defaultTtl));
|
|
597
|
+
return response;
|
|
598
|
+
}
|
|
599
|
+
async post(url, data, options) {
|
|
600
|
+
const response = await this.inner.post(url, data, options);
|
|
601
|
+
this.cache.bust(getUrlPrefix(url));
|
|
602
|
+
return response;
|
|
603
|
+
}
|
|
604
|
+
async put(url, data, options) {
|
|
605
|
+
const response = await this.inner.put(url, data, options);
|
|
606
|
+
this.cache.bust(getUrlPrefix(url));
|
|
607
|
+
return response;
|
|
608
|
+
}
|
|
609
|
+
async delete(url, options) {
|
|
610
|
+
const response = await this.inner.delete(url, options);
|
|
611
|
+
this.cache.bust(getUrlPrefix(url));
|
|
612
|
+
return response;
|
|
613
|
+
}
|
|
614
|
+
};
|
|
615
|
+
//#endregion
|
|
481
616
|
//#region src/client.ts
|
|
482
617
|
function toWarpEnv(env) {
|
|
483
618
|
if (env === "devnet") return "devnet";
|
|
@@ -490,7 +625,9 @@ var JoAiClient = class {
|
|
|
490
625
|
const headers = {};
|
|
491
626
|
if (config.team) headers["X-Team"] = config.team;
|
|
492
627
|
if (config.agentAuthKey) headers["X-Agent-Auth-Key"] = config.agentAuthKey;
|
|
493
|
-
|
|
628
|
+
const http = new HttpService(`${getApiBaseUrl(config.env ?? "mainnet")}/v1`, void 0, config.apiToken, { headers });
|
|
629
|
+
const cache = config.cache;
|
|
630
|
+
this.http = cache?.enabled !== false ? new CachedHttpService(http, cache?.overrides, cache?.defaultTtl) : http;
|
|
494
631
|
this.hub = new HubResource(this.http);
|
|
495
632
|
this.teams = new TeamsResource(this.http);
|
|
496
633
|
this.agents = new AgentsResource(this.http);
|
|
@@ -509,8 +646,12 @@ var JoAiClient = class {
|
|
|
509
646
|
this.sites = new SitesResource(this.http);
|
|
510
647
|
this.documents = new DocumentsResource(this.http);
|
|
511
648
|
this.meetings = new MeetingsResource(this.http);
|
|
649
|
+
this.stores = new StoresResource(this.http);
|
|
512
650
|
this.privateWarps = new WarpsResource(this.http);
|
|
513
651
|
}
|
|
652
|
+
clearCache() {
|
|
653
|
+
if (this.http instanceof CachedHttpService) this.http.clearCache();
|
|
654
|
+
}
|
|
514
655
|
warps(locale = "en") {
|
|
515
656
|
return new WarpClient({
|
|
516
657
|
env: toWarpEnv(this.env),
|
|
@@ -550,4 +691,4 @@ var DistributionResource = class {
|
|
|
550
691
|
}
|
|
551
692
|
};
|
|
552
693
|
//#endregion
|
|
553
|
-
export { BlueprintsResource, DistributionResource, FlowsResource, IngestionsResource, JoAiClient, MarketplaceResource, MeetingsResource, ServicesResource, SitesResource, SkillsResource, createClient };
|
|
694
|
+
export { BlueprintsResource, CachedHttpService, DistributionResource, FlowsResource, IngestionsResource, JoAiClient, MarketplaceResource, MeetingsResource, ServicesResource, SitesResource, SkillsResource, StoresResource, createClient };
|