@wps365/openclaw-wpsxiezuo 1.10.2-beta.0 → 1.10.2

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.
@@ -1,28 +1,49 @@
1
1
  /**
2
- * 延迟初始化的 WpsClient 存储。
2
+ * accountId 索引的 WpsClient 存储。
3
3
  *
4
4
  * 工具在 register() 阶段注册(此时无凭据),
5
- * 凭据在 startAccount() 阶段设置,
6
- * 工具执行时通过 getClient() 获取已初始化的 client。
5
+ * 凭据在 startAccount() 阶段按 accountId 设置,
6
+ * 工具执行时通过 getLazyClient(accountId?) 获取对应 account 的 client。
7
+ *
8
+ * 多账号场景下每个 account 维护独立的 client/creds/wpsCfg/delegatedScopes,
9
+ * 避免全局单例被后启动的 account 覆盖。
7
10
  */
8
11
  import type { WpsClient } from "./wps-client.js";
9
12
  import type { WpsConfig } from "./config.js";
10
13
  import type { AppCredentials } from "./token-store.js";
11
- declare let _log: {
14
+ export type LogFacade = {
12
15
  info?: (...args: unknown[]) => void;
13
16
  error?: (...args: unknown[]) => void;
14
17
  warn?: (...args: unknown[]) => void;
15
- } | null;
16
- export declare function setLazyClient(client: WpsClient, log?: typeof _log, wpsCfg?: WpsConfig, creds?: AppCredentials): void;
17
- export declare function getLazyClient(): WpsClient;
18
- export declare function getLazyLog(): typeof _log;
19
- export declare function getLazyWpsCfg(): WpsConfig;
20
- export declare function getLazyCreds(): AppCredentials;
18
+ };
21
19
  export type DelegatedScope = {
22
20
  name: string;
23
21
  description: string;
24
22
  };
23
+ export type AccountContext = {
24
+ client: WpsClient;
25
+ log: LogFacade | null;
26
+ wpsCfg: WpsConfig;
27
+ creds: AppCredentials;
28
+ delegatedScopes: DelegatedScope[];
29
+ };
30
+ /** 在异步上下文中执行回调,期间 currentAccountId() 返回指定 accountId */
31
+ export declare function runWithAccountId<T>(accountId: string, fn: () => T): T;
32
+ /** 获取当前异步上下文绑定的 accountId(由 runWithAccountId 设置) */
33
+ export declare function currentAccountId(): string | undefined;
34
+ export declare function setAccountContext(accountId: string, ctx: Omit<AccountContext, "delegatedScopes"> & {
35
+ delegatedScopes?: DelegatedScope[];
36
+ }): void;
37
+ export declare function setDefaultAccountId(accountId: string): void;
38
+ export declare function getDefaultAccountId(): string | null;
39
+ export declare function getLazyClient(accountId?: string): WpsClient;
40
+ export declare function getLazyLog(accountId?: string): LogFacade | null;
41
+ export declare function getLazyWpsCfg(accountId?: string): WpsConfig;
42
+ export declare function getLazyCreds(accountId?: string): AppCredentials;
43
+ export declare function updateDelegatedScopes(accountId: string, scopes: DelegatedScope[]): void;
44
+ export declare function getDelegatedScopes(accountId?: string): DelegatedScope[];
45
+ /** @deprecated Use setAccountContext instead */
46
+ export declare function setLazyClient(client: WpsClient, log?: LogFacade | null, wpsCfg?: WpsConfig, creds?: AppCredentials): void;
47
+ /** @deprecated Use updateDelegatedScopes instead */
25
48
  export declare function setDelegatedScopes(scopes: DelegatedScope[]): void;
26
- export declare function getDelegatedScopes(): DelegatedScope[];
27
- export {};
28
49
  //# sourceMappingURL=lazy-client-store.d.ts.map
@@ -1,9 +1,10 @@
1
1
  /**
2
2
  * 用户级 OAuth Token 管理 — 内存存储 + 定时刷新。
3
3
  *
4
+ * - 按 accountId:wpsUserId 隔离 token,不同 account 下同一用户 token 互不干扰
4
5
  * - 授权回调拿到 access_token / refresh_token / expires_in 后存入
5
6
  * - 工具取 token 时不删除,可重复使用
6
- * - 过期前自动用 refresh_token 续期
7
+ * - 过期前自动用 refresh_token 续期(使用对应 account 的凭证)
7
8
  * - refresh_token 失败则清除,下次使用时触发重新授权
8
9
  */
9
10
  export type UserTokenEntry = {
@@ -24,12 +25,11 @@ export type RefreshContext = {
24
25
  appSecret: string;
25
26
  baseUrl: string;
26
27
  };
27
- /** 设置 refresh 所需的应用凭证(启动时调一次) */
28
- export declare function setRefreshContext(ctx: RefreshContext): void;
29
- export declare function putUserToken(wpsUserId: string, entry: UserTokenEntry): void;
30
- export declare function getUserToken(wpsUserId: string): string | null;
28
+ export declare function setRefreshContext(accountId: string, ctx: RefreshContext): void;
29
+ export declare function putUserToken(accountId: string, wpsUserId: string, entry: UserTokenEntry): void;
30
+ export declare function getUserToken(accountId: string, wpsUserId: string): string | null;
31
31
  /** 兼容旧调用方 — 行为改为不删除 */
32
- export declare function takeUserToken(wpsUserId: string): string | null;
33
- export declare function hasUserToken(wpsUserId: string): boolean;
32
+ export declare function takeUserToken(accountId: string, wpsUserId: string): string | null;
33
+ export declare function hasUserToken(accountId: string, wpsUserId: string): boolean;
34
34
  export declare function exchangeCodeForToken(params: OAuthCodeExchangeParams): Promise<UserTokenEntry>;
35
35
  //# sourceMappingURL=user-token-store.d.ts.map