agentlink-sdk 1.0.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.
@@ -0,0 +1,117 @@
1
+ import * as localforage from 'localforage';
2
+ import { IOriginStorageClient, IChangeData } from '@agentlink/core';
3
+ export { OriginStorage } from '@agentlink/core';
4
+
5
+ interface AgentLinkClientOptions {
6
+ /**
7
+ * 服务端存储页面的 URL
8
+ * 例如: 'https://storage.example.com/storage'
9
+ */
10
+ serverUrl: string;
11
+ /**
12
+ * localforage 存储配置(可选)
13
+ */
14
+ storageOptions?: Parameters<typeof localforage.createInstance>[0];
15
+ }
16
+ interface WhitelistInfo {
17
+ domain: string;
18
+ description?: string | null;
19
+ }
20
+ interface WhitelistResponse {
21
+ whitelist: WhitelistInfo | WhitelistInfo[] | null;
22
+ origin: string | null;
23
+ }
24
+ /**
25
+ * AgentLink 客户端 SDK
26
+ * 用于跨域访问存储服务
27
+ */
28
+ declare class AgentLinkClient implements IOriginStorageClient {
29
+ private client;
30
+ private serverUrl;
31
+ constructor(options: AgentLinkClientOptions);
32
+ /**
33
+ * 获取当前 origin 的 hostname
34
+ */
35
+ private getCurrentHostname;
36
+ /**
37
+ * 连接成功回调
38
+ */
39
+ onConnect(callback: () => void): () => void;
40
+ /**
41
+ * 监听存储变更
42
+ */
43
+ onChange(callback: (data: IChangeData) => void): Promise<{
44
+ off: () => void;
45
+ broadcastChanges: boolean;
46
+ }>;
47
+ /**
48
+ * 获取指定 key 的值
49
+ * @param key 数据键
50
+ * @param options 选项
51
+ * @param options.filterOrigin 指定要读取的域名(默认:当前域名)
52
+ * @param options.includeMetadata 是否包含元数据(origin 和 timestamp)
53
+ */
54
+ getItem(key: string, options?: {
55
+ filterOrigin?: string;
56
+ includeMetadata?: boolean;
57
+ }): Promise<any>;
58
+ /**
59
+ * 设置指定 key 的值
60
+ */
61
+ setItem(key: string, value: any): Promise<void>;
62
+ /**
63
+ * 删除指定 key
64
+ */
65
+ removeItem(key: string): Promise<void>;
66
+ /**
67
+ * 清空所有数据
68
+ * @param filterOrigin 指定要清除的域名(默认:当前域名)
69
+ */
70
+ clear(filterOrigin?: string): Promise<void>;
71
+ /**
72
+ * 获取存储项数量
73
+ * @param filterOrigin 指定要统计的域名(默认:当前域名)
74
+ */
75
+ length(filterOrigin?: string): Promise<number>;
76
+ /**
77
+ * 获取指定索引的 key 名称
78
+ * @param index 索引
79
+ * @param filterOrigin 指定要查询的域名(默认:当前域名)
80
+ */
81
+ key(index: number, filterOrigin?: string): Promise<string | null>;
82
+ /**
83
+ * 获取所有 key 的数组
84
+ * @param filterOrigin 指定要查询的域名(默认:当前域名)
85
+ */
86
+ keys(filterOrigin?: string): Promise<string[]>;
87
+ /**
88
+ * 获取包含元数据的数据项
89
+ * @param key 数据键
90
+ * @param filterOrigin 指定要读取的域名(默认:当前域名)
91
+ * @returns 包含 value、origin 和 timestamp 的对象
92
+ */
93
+ getItemWithMetadata(key: string, filterOrigin?: string): Promise<{
94
+ value: any;
95
+ origin: string;
96
+ timestamp: number;
97
+ }>;
98
+ /**
99
+ * 获取所有数据项(支持过滤)
100
+ * @param filterOrigin 指定要读取的域名(默认:当前域名)
101
+ * @returns 包含所有数据的对象,key 为数据键,value 为包含 value、origin 和 timestamp 的对象
102
+ */
103
+ getAllItems(filterOrigin?: string): Promise<{
104
+ [key: string]: {
105
+ value: any;
106
+ origin: string;
107
+ timestamp: number;
108
+ };
109
+ }>;
110
+ /**
111
+ * 获取白名单信息
112
+ * @param includeAll 如果为true,返回所有白名单;如果为false,只返回当前域名的白名单信息
113
+ */
114
+ getWhitelistInfo(includeAll?: boolean): Promise<WhitelistResponse>;
115
+ }
116
+
117
+ export { AgentLinkClient, type AgentLinkClientOptions, type WhitelistInfo, type WhitelistResponse };
@@ -0,0 +1,117 @@
1
+ import * as localforage from 'localforage';
2
+ import { IOriginStorageClient, IChangeData } from '@agentlink/core';
3
+ export { OriginStorage } from '@agentlink/core';
4
+
5
+ interface AgentLinkClientOptions {
6
+ /**
7
+ * 服务端存储页面的 URL
8
+ * 例如: 'https://storage.example.com/storage'
9
+ */
10
+ serverUrl: string;
11
+ /**
12
+ * localforage 存储配置(可选)
13
+ */
14
+ storageOptions?: Parameters<typeof localforage.createInstance>[0];
15
+ }
16
+ interface WhitelistInfo {
17
+ domain: string;
18
+ description?: string | null;
19
+ }
20
+ interface WhitelistResponse {
21
+ whitelist: WhitelistInfo | WhitelistInfo[] | null;
22
+ origin: string | null;
23
+ }
24
+ /**
25
+ * AgentLink 客户端 SDK
26
+ * 用于跨域访问存储服务
27
+ */
28
+ declare class AgentLinkClient implements IOriginStorageClient {
29
+ private client;
30
+ private serverUrl;
31
+ constructor(options: AgentLinkClientOptions);
32
+ /**
33
+ * 获取当前 origin 的 hostname
34
+ */
35
+ private getCurrentHostname;
36
+ /**
37
+ * 连接成功回调
38
+ */
39
+ onConnect(callback: () => void): () => void;
40
+ /**
41
+ * 监听存储变更
42
+ */
43
+ onChange(callback: (data: IChangeData) => void): Promise<{
44
+ off: () => void;
45
+ broadcastChanges: boolean;
46
+ }>;
47
+ /**
48
+ * 获取指定 key 的值
49
+ * @param key 数据键
50
+ * @param options 选项
51
+ * @param options.filterOrigin 指定要读取的域名(默认:当前域名)
52
+ * @param options.includeMetadata 是否包含元数据(origin 和 timestamp)
53
+ */
54
+ getItem(key: string, options?: {
55
+ filterOrigin?: string;
56
+ includeMetadata?: boolean;
57
+ }): Promise<any>;
58
+ /**
59
+ * 设置指定 key 的值
60
+ */
61
+ setItem(key: string, value: any): Promise<void>;
62
+ /**
63
+ * 删除指定 key
64
+ */
65
+ removeItem(key: string): Promise<void>;
66
+ /**
67
+ * 清空所有数据
68
+ * @param filterOrigin 指定要清除的域名(默认:当前域名)
69
+ */
70
+ clear(filterOrigin?: string): Promise<void>;
71
+ /**
72
+ * 获取存储项数量
73
+ * @param filterOrigin 指定要统计的域名(默认:当前域名)
74
+ */
75
+ length(filterOrigin?: string): Promise<number>;
76
+ /**
77
+ * 获取指定索引的 key 名称
78
+ * @param index 索引
79
+ * @param filterOrigin 指定要查询的域名(默认:当前域名)
80
+ */
81
+ key(index: number, filterOrigin?: string): Promise<string | null>;
82
+ /**
83
+ * 获取所有 key 的数组
84
+ * @param filterOrigin 指定要查询的域名(默认:当前域名)
85
+ */
86
+ keys(filterOrigin?: string): Promise<string[]>;
87
+ /**
88
+ * 获取包含元数据的数据项
89
+ * @param key 数据键
90
+ * @param filterOrigin 指定要读取的域名(默认:当前域名)
91
+ * @returns 包含 value、origin 和 timestamp 的对象
92
+ */
93
+ getItemWithMetadata(key: string, filterOrigin?: string): Promise<{
94
+ value: any;
95
+ origin: string;
96
+ timestamp: number;
97
+ }>;
98
+ /**
99
+ * 获取所有数据项(支持过滤)
100
+ * @param filterOrigin 指定要读取的域名(默认:当前域名)
101
+ * @returns 包含所有数据的对象,key 为数据键,value 为包含 value、origin 和 timestamp 的对象
102
+ */
103
+ getAllItems(filterOrigin?: string): Promise<{
104
+ [key: string]: {
105
+ value: any;
106
+ origin: string;
107
+ timestamp: number;
108
+ };
109
+ }>;
110
+ /**
111
+ * 获取白名单信息
112
+ * @param includeAll 如果为true,返回所有白名单;如果为false,只返回当前域名的白名单信息
113
+ */
114
+ getWhitelistInfo(includeAll?: boolean): Promise<WhitelistResponse>;
115
+ }
116
+
117
+ export { AgentLinkClient, type AgentLinkClientOptions, type WhitelistInfo, type WhitelistResponse };