@byteplus-iga-pages/agent 0.0.0-stage → 1.0.3

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.
Files changed (105) hide show
  1. package/LICENSE +20 -0
  2. package/README.md +84 -2
  3. package/dist/cjs/261.js +77 -0
  4. package/dist/cjs/341.js +43 -0
  5. package/dist/cjs/401.js +3632 -0
  6. package/dist/cjs/419.js +854 -0
  7. package/dist/cjs/504.js +760 -0
  8. package/dist/cjs/521.js +242 -0
  9. package/dist/cjs/594.js +79 -0
  10. package/dist/cjs/647.js +1367 -0
  11. package/dist/cjs/808.js +322 -0
  12. package/dist/cjs/82.js +10089 -0
  13. package/dist/cjs/893.js +17720 -0
  14. package/dist/cjs/893.js.LICENSE.txt +13 -0
  15. package/dist/cjs/951.js +59 -0
  16. package/dist/cjs/package.json +3 -0
  17. package/dist/cjs/runtime.js +79 -0
  18. package/dist/cjs/sandbox/host.js +125 -0
  19. package/dist/cjs/sandbox/index.js +286 -0
  20. package/dist/cjs/store/claude.js +209 -0
  21. package/dist/cjs/store/host.js +92 -0
  22. package/dist/cjs/store/index.js +43 -0
  23. package/dist/cjs/store/langgraph.js +581 -0
  24. package/dist/cjs/store/openai.js +118 -0
  25. package/dist/cjs/tools/claude.js +59 -0
  26. package/dist/cjs/tools/index.js +37 -0
  27. package/dist/cjs/tools/langchain.js +52 -0
  28. package/dist/cjs/tools/openai-agents.js +43 -0
  29. package/dist/cjs/tools/openai.js +43 -0
  30. package/dist/esm/128.js +10381 -0
  31. package/dist/esm/261.js +67 -0
  32. package/dist/esm/341.js +30 -0
  33. package/dist/esm/392.js +4453 -0
  34. package/dist/esm/417.js +704 -0
  35. package/dist/esm/521.js +230 -0
  36. package/dist/esm/594.js +67 -0
  37. package/dist/esm/613.js +19042 -0
  38. package/dist/esm/613.js.LICENSE.txt +13 -0
  39. package/dist/esm/951.js +44 -0
  40. package/dist/esm/package.json +3 -0
  41. package/dist/esm/runtime.js +39 -0
  42. package/dist/esm/sandbox/host.js +1 -0
  43. package/dist/esm/sandbox/index.js +183 -0
  44. package/dist/esm/store/claude.js +172 -0
  45. package/dist/esm/store/host.js +46 -0
  46. package/dist/esm/store/index.js +2 -0
  47. package/dist/esm/store/langgraph.js +542 -0
  48. package/dist/esm/store/openai.js +81 -0
  49. package/dist/esm/tools/claude.js +22 -0
  50. package/dist/esm/tools/index.js +1 -0
  51. package/dist/esm/tools/langchain.js +16 -0
  52. package/dist/esm/tools/openai-agents.js +6 -0
  53. package/dist/esm/tools/openai.js +6 -0
  54. package/dist/types/_internal/data-plane/control-plane-request.d.ts +12 -0
  55. package/dist/types/_internal/data-plane/control-plane.d.ts +3 -0
  56. package/dist/types/_internal/data-plane/credential-provider.d.ts +25 -0
  57. package/dist/types/_internal/data-plane/errors.d.ts +19 -0
  58. package/dist/types/_internal/data-plane/index.d.ts +11 -0
  59. package/dist/types/_internal/data-plane/supabase-client.d.ts +12 -0
  60. package/dist/types/_internal/data-plane/token-client.d.ts +23 -0
  61. package/dist/types/sandbox/api-client.d.ts +37 -0
  62. package/dist/types/sandbox/api-types.d.ts +81 -0
  63. package/dist/types/sandbox/binding-repository.d.ts +62 -0
  64. package/dist/types/sandbox/error.d.ts +22 -0
  65. package/dist/types/sandbox/expiry.d.ts +11 -0
  66. package/dist/types/sandbox/host.d.ts +6 -0
  67. package/dist/types/sandbox/iga-sandbox.d.ts +208 -0
  68. package/dist/types/sandbox/index.d.ts +8 -0
  69. package/dist/types/sandbox/public-surface.d.ts +19 -0
  70. package/dist/types/sandbox/runtime-sandbox.d.ts +32 -0
  71. package/dist/types/sandbox/types.d.ts +238 -0
  72. package/dist/types/store/append.d.ts +41 -0
  73. package/dist/types/store/claude-repository.d.ts +36 -0
  74. package/dist/types/store/claude.d.ts +3 -0
  75. package/dist/types/store/control-plane-request.d.ts +2 -0
  76. package/dist/types/store/credential-error.d.ts +2 -0
  77. package/dist/types/store/credential-provider.d.ts +29 -0
  78. package/dist/types/store/errors.d.ts +29 -0
  79. package/dist/types/store/factory.d.ts +31 -0
  80. package/dist/types/store/host.d.ts +5 -0
  81. package/dist/types/store/index.d.ts +6 -0
  82. package/dist/types/store/json.d.ts +7 -0
  83. package/dist/types/store/langgraph-repository.d.ts +98 -0
  84. package/dist/types/store/langgraph.d.ts +43 -0
  85. package/dist/types/store/openai.d.ts +12 -0
  86. package/dist/types/store/pagination.d.ts +27 -0
  87. package/dist/types/store/runtime-data-plane.d.ts +8 -0
  88. package/dist/types/store/runtime-provider.d.ts +1 -0
  89. package/dist/types/store/runtime-store.d.ts +20 -0
  90. package/dist/types/store/store.d.ts +240 -0
  91. package/dist/types/store/supabase-transport.d.ts +43 -0
  92. package/dist/types/store/token-client.d.ts +7 -0
  93. package/dist/types/tools/adapters.d.ts +5 -0
  94. package/dist/types/tools/claude.d.ts +4 -0
  95. package/dist/types/tools/index.d.ts +2 -0
  96. package/dist/types/tools/langchain.d.ts +16 -0
  97. package/dist/types/tools/model-output.d.ts +8 -0
  98. package/dist/types/tools/openai-agents.d.ts +4 -0
  99. package/dist/types/tools/openai.d.ts +5 -0
  100. package/dist/types/tools/registry.d.ts +16 -0
  101. package/dist/types/tools/result.d.ts +17 -0
  102. package/dist/types/tools/sandbox-result-mappers.d.ts +10 -0
  103. package/dist/types/tools/sandbox-tools.d.ts +17 -0
  104. package/dist/types/tools/types.d.ts +307 -0
  105. package/package.json +136 -4
@@ -0,0 +1,238 @@
1
+ import type { SandboxClient } from "@agent-infra/sandbox";
2
+ import type { PublicSandboxBusiness } from "./public-surface.js";
3
+ import type { SandboxBindingRepository } from "./binding-repository.js";
4
+ /** IGA Sandbox 控制面成功响应使用的可选信封。 */
5
+ export interface SandboxControlPlaneEnvelope<T> {
6
+ code: string | number;
7
+ message?: string;
8
+ data?: T;
9
+ }
10
+ /** 控制面当前接受直接 payload,或 `{ code, message, data }` 信封。 */
11
+ export type SandboxControlPlaneResponse<T> = T | SandboxControlPlaneEnvelope<T>;
12
+ /** `pages/v1/api/sandbox-token` 的原始 payload。 */
13
+ export interface SandboxTokenResponsePayload {
14
+ SandboxAppID?: string;
15
+ ApiKey?: string;
16
+ Url?: string;
17
+ TokenType?: string;
18
+ TokenHeader?: string;
19
+ }
20
+ /** `pages/v1/api/sandbox/create` 的原始 payload。 */
21
+ export interface SandboxCreateResponsePayload {
22
+ SandboxId?: string;
23
+ }
24
+ /** `pages/v1/api/sandbox/destroy` 的原始 payload。 */
25
+ export type SandboxDestroyResponsePayload = Record<string, never>;
26
+ /** `sandbox/instance` 与 `sandbox/instance/update` 的原始 payload。 */
27
+ export interface SandboxInstanceResponsePayload {
28
+ SandboxID?: string;
29
+ ExpireAt?: string;
30
+ CreatedAt?: string;
31
+ Status?: string;
32
+ }
33
+ export interface CreateSandboxOptions {
34
+ /** BytePlus IGA Pages 项目 ID(后端用它定位沙箱应用 / 实例池)。 */
35
+ projectId: string;
36
+ /**
37
+ * 会话 ID。同一 projectId+conversationId 复用同一沙箱实例;
38
+ * 换一个就拉新实例(缓存键按 [projectId, conversationId] 二元组编码)。
39
+ */
40
+ conversationId: string;
41
+ /**
42
+ * 后端 base URL。公共入口固定该值;仅内部工厂和测试可传。
43
+ */
44
+ apiBaseUrl?: string;
45
+ /**
46
+ * 控制面下发的项目 Token。公共入口从运行时 env 读取;仅内部工厂和测试可传。
47
+ * 每次请求将 Token 与毫秒级 timestamp 一起放入 HTTPS query。
48
+ */
49
+ apiToken?: string;
50
+ /**
51
+ * 自定义 API client(测试注入用)。传了就忽略 apiBaseUrl / apiToken。
52
+ * 调用方一般不传。
53
+ */
54
+ api?: SandboxApiClient;
55
+ /** Internal persistence adapter. The public runtime always provides it. */
56
+ bindingRepository?: SandboxBindingRepository;
57
+ /** 默认单请求超时(秒),传给官方 SandboxClient。 */
58
+ timeoutInSeconds?: number;
59
+ }
60
+ /**
61
+ * 独立实例模式的选项——`createSandbox()`(公共)用。
62
+ *
63
+ * 不绑定 conversation:每次调用创建一个新的沙箱实例,实例身份由调用方自己保存
64
+ * (`getInfo().sandboxId`),之后想再操作它就 `connectSandbox(sandboxId)` 接回来。
65
+ * SDK 不在 sandboxId → 实例之间维护任何映射。
66
+ */
67
+ export interface CreateDetachedSandboxOptions {
68
+ /** 默认单请求超时(秒),传给官方 SandboxClient。 */
69
+ timeoutInSeconds?: number;
70
+ }
71
+ /**
72
+ * 接回已有实例模式的选项——`connectSandbox(sandboxId)`(公共)用。
73
+ *
74
+ * 不建新实例:getToken 换凭证后直接把数据面路由到目标 sandboxId。
75
+ */
76
+ export interface AttachSandboxOptions {
77
+ /** 默认单请求超时(秒),传给官方 SandboxClient。 */
78
+ timeoutInSeconds?: number;
79
+ }
80
+ /**
81
+ * 后端 pages/v1/api/sandbox-token 的返回。
82
+ * 一次返回建 SandboxClient 所需的全部信息:
83
+ * - url / apiKey / tokenHeader / tokenType:构造官方 SandboxClient 的鉴权头
84
+ * - sandboxAppId:沙箱应用 ID(functionId)
85
+ */
86
+ export interface SandboxTokenResult {
87
+ /** 沙箱应用 ID(functionId,用于 x-faas-instance-name 请求头)。 */
88
+ sandboxAppId?: string;
89
+ /** e2b_ 开头的沙箱数据面 token,作为 tokenType 头的值。 */
90
+ apiKey: string;
91
+ /** 沙箱实例的 HTTPS 域名(environment)。 */
92
+ url?: string;
93
+ /** token 类型,通常 "Bearer"。 */
94
+ tokenType?: string;
95
+ /** token 头名,通常 "Authorization"。 */
96
+ tokenHeader?: string;
97
+ /** 过期时间(ms epoch),后端可下发短期 token。undefined 表示长期有效。 */
98
+ expireAt?: number;
99
+ }
100
+ /** 后端 pages/v1/api/sandbox/create 的返回。 */
101
+ export interface SandboxCreateResult {
102
+ /** 沙箱实例 ID,destroy / getInfo / extendTimeout 时回传给后端。 */
103
+ sandboxId: string;
104
+ }
105
+ /** 后端 pages/v1/api/sandbox/destroy 的返回。 */
106
+ export interface SandboxDestroyResult {
107
+ ok: boolean;
108
+ }
109
+ /** 查询或续期后的实例信息(getInfo / extendTimeout)。 */
110
+ export interface SandboxInstanceInfo {
111
+ /**
112
+ * 实例 ID。历史控制面可用显式空字符串表达不存在;缺失字段不作为销毁证据。
113
+ * 当前 BOE 的不存在业务错误还需通过精确实例路由确认。
114
+ */
115
+ sandboxId: string;
116
+ /** 过期时间(RFC3339 字符串)。 */
117
+ expireAt?: string;
118
+ /** 创建时间(RFC3339 字符串)。 */
119
+ createdAt?: string;
120
+ /**
121
+ * 实例状态(2026-08-21 契约新增):
122
+ * `Starting`(启动中)/ `Ready`(可用)/ `Failed`(启动失败)/
123
+ * `Terminating`(终止中)。后端枚举直接透传。
124
+ */
125
+ status?: "Starting" | "Ready" | "Failed" | "Terminating";
126
+ }
127
+ /**
128
+ * Sandbox API client 抽象。调用方(含测试)都依赖这个接口,不感知具体实现。
129
+ */
130
+ export interface SandboxApiClient {
131
+ getToken(opts?: {
132
+ signal?: AbortSignal;
133
+ }): Promise<SandboxTokenResult>;
134
+ create(opts: SandboxApiCallOptions): Promise<SandboxCreateResult>;
135
+ destroy(opts: SandboxApiCallOptions & {
136
+ sandboxId: string;
137
+ }): Promise<SandboxDestroyResult>;
138
+ /** 查询实例信息(对应 pages/v1/api/sandbox/instance)。 */
139
+ getInstance(opts: SandboxApiCallOptions & {
140
+ sandboxId: string;
141
+ }): Promise<SandboxInstanceInfo>;
142
+ /**
143
+ * 定罪查询:实例确认已销毁时抛 内部实例丢失信号。
144
+ * 判定标准(详见 docs/backend-contracts/sandbox-lifecycle.md):
145
+ * - 实例接口 HTTP 404/410,或历史控制面显式返回空 SandboxID
146
+ * - Status 为 Failed / Terminating
147
+ * HTTP 200 业务失败通过只读数据面查询确认,仅识别结构化 instance_not_found。
148
+ * ExpireAt 不是实例不存在的证据。其它错误表示无法确认,调用方不得据此重建。
149
+ */
150
+ confirmInstanceExists(opts: SandboxApiCallOptions & {
151
+ sandboxId: string;
152
+ }): Promise<void>;
153
+ /** 延长实例超时时间(对应 pages/v1/api/sandbox/instance/update)。 */
154
+ updateInstanceTimeout(opts: SandboxApiCallOptions & {
155
+ sandboxId: string;
156
+ timeoutInMinutes: number;
157
+ }): Promise<SandboxInstanceInfo>;
158
+ }
159
+ export interface SandboxApiCallOptions {
160
+ projectId: string;
161
+ conversationId: string;
162
+ signal?: AbortSignal;
163
+ }
164
+ /** Cancellation options for one Sandbox lifecycle operation. */
165
+ export interface SandboxOperationOptions {
166
+ abortSignal?: AbortSignal;
167
+ }
168
+ /**
169
+ * 内部宿主句柄。内部工厂返回它——既是官方 SandboxClient(业务能力直接挂上),
170
+ * 又叠加管理能力。调用方零 getClient 样板代码:
171
+ *
172
+ * const sandbox = createSandbox({ projectId, conversationId });
173
+ *
174
+ * // 业务方法直接调,第一次访问自动触发懒加载
175
+ * await sandbox.code.executeCode({ language: "python", code: "print(1)" });
176
+ * await sandbox.shell.execCommand({ command: "ls" });
177
+ * const ctx = await sandbox.sandbox.getContext();
178
+ *
179
+ * // 管理方法
180
+ * const info = await sandbox.getInfo();
181
+ * await sandbox.extendTimeout(10);
182
+ * await sandbox.destroy();
183
+ * sandbox.projectId;
184
+ *
185
+ * 需要把原装 client 传给外部库时,getClient 还在:
186
+ * const client = await sandbox.getClient();
187
+ *
188
+ * 实现要点:抄官方 SandboxClient 的 `??=` 懒加载模式,访问 sandbox.code 时构造
189
+ * 一个懒代理并缓存。代理上的方法被调用时自动 await ensureInstance,然后转发到 raw。
190
+ */
191
+ export type SandboxInstance = SandboxClient & {
192
+ readonly projectId: string;
193
+ /**
194
+ * 会话 ID。绑定会话的实例才有;`createSandbox()`(独立实例)和
195
+ * `connectSandbox(sandboxId)`(接回)返回的句柄上没有。
196
+ */
197
+ readonly conversationId?: string;
198
+ /**
199
+ * 实例 ID。独立实例(createSandbox)和接回(connectSandbox(sandboxId))的句柄上
200
+ * 同步可读(公共 createSandbox 在 await 返回前已初始化,内部独立工厂仍懒加载);
201
+ * 绑定会话的实例要等首次懒加载后 `getInfo()` 才拿得到。
202
+ */
203
+ readonly sandboxId?: string;
204
+ /**
205
+ * 拿到底层官方 SandboxClient(原装)。
206
+ * 首次调用会触发懒加载,后续命中缓存。
207
+ *
208
+ * 调用方一般不需要显式调——业务方法(sandbox.code.executeCode 等)会自动触发。
209
+ * 这个方法给"我要把 client 传给外部库"的场景用:
210
+ *
211
+ * const client = await sandbox.getClient();
212
+ * externalLibrary.doSomething(client);
213
+ */
214
+ getClient(options?: SandboxOperationOptions): Promise<SandboxClient>;
215
+ /**
216
+ * 内部初始化方法,等待实例身份、凭证和客户端准备完成,不轮询远端 Ready 状态。
217
+ * 供公共 createSandbox 在返回前调用,不对 SDK 用户暴露。
218
+ */
219
+ ensureReady(options?: SandboxOperationOptions): Promise<void>;
220
+ /**
221
+ * 查询当前实例信息(过期时间 / 创建时间)。
222
+ * 触发懒加载:如果实例还没建过,会先建一个。
223
+ */
224
+ getInfo(options?: SandboxOperationOptions): Promise<SandboxInstanceInfo>;
225
+ /**
226
+ * 延长当前实例的超时时间。
227
+ * @param timeoutInMinutes 实例存活时长,单位分钟;原值透传后端 Time,由后端校验并更新 ExpireAt
228
+ * 触发懒加载:如果实例还没建过,会先建一个。
229
+ */
230
+ extendTimeout(timeoutInMinutes: number, options?: SandboxOperationOptions): Promise<SandboxInstanceInfo>;
231
+ /**
232
+ * 显式销毁实例。会调后端 destroy。
233
+ * destroy 后再调官方方法会重新走一遍懒加载。
234
+ */
235
+ destroy(options?: SandboxOperationOptions): Promise<void>;
236
+ };
237
+ /** Public server SDK handle: selected business modules and instance lifecycle. */
238
+ export type Sandbox = PublicSandboxBusiness & Pick<SandboxInstance, "conversationId" | "sandboxId" | "getInfo" | "extendTimeout" | "destroy">;
@@ -0,0 +1,41 @@
1
+ import { type JsonObject, type JsonValue } from "./json.js";
2
+ /** 待追加的单条消息内容;批量追加时由外层统一指定 conversationId。 */
3
+ export interface AppendMessageItemInput {
4
+ /**
5
+ * 当前项目内唯一的消息 ID,也是存活消息的幂等键;未传时由 SDK 生成 UUID。
6
+ * 自定义 ID 应为非空字符串,后续读取、更新和删除要求非空。
7
+ * 业务重试必须显式提供并复用原 ID、会话及内容;省略 ID 的再次调用会生成新 ID。
8
+ */
9
+ messageId?: string;
10
+ /**
11
+ * 消息角色,如 user、assistant、system、tool,也接受应用自定义字符串。
12
+ * @default null
13
+ */
14
+ role?: string | null;
15
+ /** 应用自定义的消息类型;省略时为 null,不从 payload 推断。 */
16
+ type?: string | null;
17
+ /**
18
+ * 必填的 JSON 消息内容,可为基础值、数组、普通对象或 null,不要求特定业务字段。
19
+ * 不接受 undefined、BigInt、函数、NaN、Infinity、循环引用、稀疏数组或类实例;
20
+ * 日期应先用 toISOString() 转成字符串。
21
+ */
22
+ payload: JsonValue;
23
+ /**
24
+ * 仅属于此消息的 JSON 元数据对象,不会写入会话 metadata;不能是数组或 null。
25
+ * 内容遵循与 payload 相同的 JSON 值约束。
26
+ * @default {}
27
+ */
28
+ metadata?: JsonObject;
29
+ }
30
+ export interface MaterializedAppendMessage {
31
+ messageId: string;
32
+ role: string | null;
33
+ type: string | null;
34
+ payload: JsonValue;
35
+ metadata: JsonObject;
36
+ }
37
+ /**
38
+ * 在任何网络请求前校验并克隆完整批次。
39
+ * 生成的 ID 在所有传输重试中保持稳定,使 append RPC 具备幂等性。
40
+ */
41
+ export declare function materializeAppendMessages(messages: AppendMessageItemInput[], generateUuid?: () => string): MaterializedAppendMessage[];
@@ -0,0 +1,36 @@
1
+ import type { SupabaseClient } from "@supabase/supabase-js";
2
+ import type { JsonObject } from "./json.js";
3
+ import type { SupabaseStoreOperationResult, SupabaseStoreResult } from "./supabase-transport.js";
4
+ export declare const CLAUDE_RPC_NAMES: {
5
+ readonly append: "claude_session_append";
6
+ readonly load: "claude_session_load";
7
+ readonly listSessions: "claude_session_list_sessions";
8
+ readonly delete: "claude_session_delete";
9
+ readonly listSubkeys: "claude_session_list_subkeys";
10
+ };
11
+ export interface ClaudeSessionKeyRecord {
12
+ projectKey: string;
13
+ sessionId: string;
14
+ subpath: string | null;
15
+ }
16
+ type RuntimeExecutor = <T>(options: {
17
+ operationName: string;
18
+ retryOnUnauthorized: boolean;
19
+ retryOnNetworkError?: boolean;
20
+ operation(client: SupabaseClient): PromiseLike<SupabaseStoreOperationResult<T>>;
21
+ }) => Promise<SupabaseStoreResult<T>>;
22
+ /** 包内 Claude RPC repository;project scope 只由 Store JWT 提供。 */
23
+ export declare class ClaudeSessionRepository {
24
+ private readonly execute;
25
+ constructor(execute?: RuntimeExecutor);
26
+ append(key: ClaudeSessionKeyRecord, entries: JsonObject[]): Promise<void>;
27
+ load(key: ClaudeSessionKeyRecord): Promise<unknown>;
28
+ listSessions(projectKey: string): Promise<unknown>;
29
+ delete(key: ClaudeSessionKeyRecord): Promise<void>;
30
+ listSubkeys(input: {
31
+ projectKey: string;
32
+ sessionId: string;
33
+ }): Promise<unknown>;
34
+ }
35
+ export declare const claudeSessionRepository: ClaudeSessionRepository;
36
+ export {};
@@ -0,0 +1,3 @@
1
+ import type { SessionStore } from "@anthropic-ai/claude-agent-sdk";
2
+ /** 创建绑定当前 IGA project Store 数据面的 Claude Agent SDK SessionStore。 */
3
+ export declare function createSessionStore(): SessionStore;
@@ -0,0 +1,2 @@
1
+ export { postStoreToken } from "../_internal/data-plane/index.js";
2
+ export type { ControlPlaneResponse, PostStoreTokenOptions, } from "../_internal/data-plane/index.js";
@@ -0,0 +1,2 @@
1
+ import { StoreError } from "./errors.js";
2
+ export declare function toStoreCredentialError(error: unknown): StoreError;
@@ -0,0 +1,29 @@
1
+ import { type JwtTiming } from "../_internal/data-plane/index.js";
2
+ import type { StoreCredentials } from "./token-client.js";
3
+ export type { JwtTiming };
4
+ export interface StoreCredentialProviderOptions {
5
+ fetchCredentials(): Promise<StoreCredentials>;
6
+ now?: () => number;
7
+ }
8
+ export interface StoreCredentialScope {
9
+ environment: string;
10
+ projectId: string;
11
+ }
12
+ export interface StoreCredentialProviderCacheOptions {
13
+ createProvider(scope: Readonly<StoreCredentialScope>): StoreCredentialProvider;
14
+ }
15
+ export declare function readJwtTiming(jwt: string): JwtTiming;
16
+ export declare class StoreCredentialProvider {
17
+ private readonly delegate;
18
+ constructor(options: StoreCredentialProviderOptions);
19
+ getValidCredentials(): Promise<StoreCredentials>;
20
+ getProjectId(): Promise<string>;
21
+ invalidate(jwt?: string): void;
22
+ }
23
+ export declare class StoreCredentialProviderCache {
24
+ private readonly providers;
25
+ private readonly createProvider;
26
+ constructor(options: StoreCredentialProviderCacheOptions);
27
+ get(scope: Readonly<StoreCredentialScope>): StoreCredentialProvider;
28
+ clear(scope?: Readonly<StoreCredentialScope>): void;
29
+ }
@@ -0,0 +1,29 @@
1
+ /** Supabase/PostgREST 原始错误字段;本地失败只提供可取得的字段。 */
2
+ export interface StoreUpstreamError {
3
+ readonly code?: string;
4
+ readonly message: string;
5
+ readonly details?: string | null;
6
+ readonly hint?: string | null;
7
+ }
8
+ export interface StoreErrorInfo {
9
+ /** 数据面取自 error.message;控制面使用换证错误说明。 */
10
+ readonly message: string;
11
+ /** HTTP 错误分类,例如 Conflict;无 HTTP 响应时使用本地错误码。 */
12
+ readonly code: string;
13
+ readonly status?: number;
14
+ readonly error?: StoreUpstreamError;
15
+ }
16
+ export interface StoreErrorOptions {
17
+ status?: number;
18
+ /** null 表示控制面错误,不附带内层 error。 */
19
+ error?: StoreUpstreamError | null;
20
+ }
21
+ export declare class StoreError extends Error implements StoreErrorInfo {
22
+ readonly code: string;
23
+ readonly status?: number;
24
+ readonly error?: StoreUpstreamError;
25
+ constructor(code: string, message: string, options?: StoreErrorOptions);
26
+ toJSON(): StoreErrorInfo;
27
+ }
28
+ /** 外层只描述 HTTP 分类,不重写内层 SQLSTATE 或 PostgREST 错误。 */
29
+ export declare function storeCodeForStatus(status: number): string;
@@ -0,0 +1,31 @@
1
+ import type { createClient } from "@supabase/supabase-js";
2
+ import { type StoreCredentialScope } from "./credential-provider.js";
3
+ import { type Store, type StoreRpcNames } from "./store.js";
4
+ import type { StoreCredentials } from "./token-client.js";
5
+ export interface StoreScope {
6
+ projectId: string;
7
+ }
8
+ export interface StoreFactoryOptions {
9
+ environment: string;
10
+ fetchCredentials(scope: Readonly<StoreCredentialScope>): Promise<StoreCredentials>;
11
+ fetch?: typeof globalThis.fetch;
12
+ createClient?: typeof createClient;
13
+ now?: () => number;
14
+ generateUuid?: () => string;
15
+ rpcNames?: Partial<StoreRpcNames>;
16
+ }
17
+ /**
18
+ * 进程作用域的 Store 工厂。创建项目 Store 实例是同步且无网络副作用的;
19
+ * 首次调用 Store API 时才延迟获取凭证。
20
+ */
21
+ export declare class StoreFactory {
22
+ private readonly options;
23
+ private readonly credentials;
24
+ private readonly transports;
25
+ constructor(options: StoreFactoryOptions);
26
+ create(scope: StoreScope): Store;
27
+ clear(scope?: {
28
+ projectId: string;
29
+ }): void;
30
+ }
31
+ export declare function createStoreFactory(options: StoreFactoryOptions): StoreFactory;
@@ -0,0 +1,5 @@
1
+ export { createStoreFactory, StoreFactory, } from "./factory.js";
2
+ export type { StoreFactoryOptions, StoreScope, } from "./factory.js";
3
+ export { fetchStoreCredentials, validateStoreRootUrl, } from "./token-client.js";
4
+ export type { FetchStoreCredentialsOptions, StoreCredentials, } from "./token-client.js";
5
+ export type { StoreCredentialScope } from "./credential-provider.js";
@@ -0,0 +1,6 @@
1
+ /** 面向 BytePlus IGA Pages Functions 和全栈服务端处理器的 Store SDK。 */
2
+ export { store } from "./runtime-store.js";
3
+ export { StoreError } from "./errors.js";
4
+ export type { StoreErrorInfo, StoreUpstreamError, } from "./errors.js";
5
+ export type { Store, AppendMessageInput, AppendMessagesInput, Conversation, CreateConversationInput, ListConversationsInput, ListMessagesInput, Message, Page, UpdateConversationInput, UpdateMessageInput, } from "./store.js";
6
+ export type { AppendMessageItemInput } from "./append.js";
@@ -0,0 +1,7 @@
1
+ export type JsonPrimitive = string | number | boolean | null;
2
+ export type JsonValue = JsonPrimitive | JsonValue[] | JsonObject;
3
+ export interface JsonObject {
4
+ [key: string]: JsonValue;
5
+ }
6
+ export declare function cloneJsonValue(value: unknown, field: string): JsonValue;
7
+ export declare function cloneJsonObject(value: unknown, field: string): JsonObject;
@@ -0,0 +1,98 @@
1
+ import type { SupabaseClient } from "@supabase/supabase-js";
2
+ import type { SupabaseStoreOperationResult, SupabaseStoreResult } from "./supabase-transport.js";
3
+ export declare const LANGGRAPH_RPC_NAMES: {
4
+ readonly putCheckpoint: "langgraph_put_checkpoint";
5
+ readonly getCheckpoint: "langgraph_get_checkpoint";
6
+ readonly listCheckpoints: "langgraph_list_checkpoints";
7
+ readonly putWrites: "langgraph_put_writes";
8
+ readonly getDeltaHistory: "langgraph_get_delta_history";
9
+ readonly deleteThread: "langgraph_delete_thread";
10
+ };
11
+ export interface LangGraphBlobRow {
12
+ channel: string;
13
+ version: string;
14
+ type: string;
15
+ blob_base64: string | null;
16
+ }
17
+ export interface LangGraphWriteRow {
18
+ task_id: string;
19
+ idx: number;
20
+ channel: string;
21
+ type: string;
22
+ blob_base64: string;
23
+ }
24
+ export interface LangGraphCheckpointRow {
25
+ thread_id: string;
26
+ checkpoint_ns: string;
27
+ checkpoint_id: string;
28
+ parent_checkpoint_id: string | null;
29
+ checkpoint: Record<string, unknown>;
30
+ metadata: Record<string, unknown>;
31
+ blobs: LangGraphBlobRow[];
32
+ writes: LangGraphWriteRow[];
33
+ pending_sends?: LangGraphWriteRow[];
34
+ }
35
+ export interface LangGraphDeltaHistoryRow {
36
+ depth: number;
37
+ checkpoint_id: string;
38
+ parent_checkpoint_id: string | null;
39
+ blobs: LangGraphBlobRow[];
40
+ writes: LangGraphWriteRow[];
41
+ }
42
+ export interface PutCheckpointRecord {
43
+ threadId: string;
44
+ checkpointNamespace: string;
45
+ checkpointId: string;
46
+ parentCheckpointId: string | null;
47
+ checkpoint: Record<string, unknown>;
48
+ metadata: Record<string, unknown>;
49
+ blobs: LangGraphBlobRow[];
50
+ }
51
+ export interface ListCheckpointQuery {
52
+ threadId: string | null;
53
+ checkpointNamespace: string | null;
54
+ checkpointId: string | null;
55
+ metadata: Record<string, unknown> | null;
56
+ beforeCheckpointId: string | null;
57
+ limit: number | null;
58
+ }
59
+ export interface PutWritesRecord {
60
+ threadId: string;
61
+ checkpointNamespace: string;
62
+ checkpointId: string;
63
+ taskId: string;
64
+ writes: Array<{
65
+ idx: number;
66
+ channel: string;
67
+ type: string;
68
+ blob_base64: string;
69
+ }>;
70
+ }
71
+ type RuntimeExecutor = <T>(options: {
72
+ operationName: string;
73
+ retryOnUnauthorized: boolean;
74
+ retryOnNetworkError?: boolean;
75
+ operation(client: SupabaseClient): PromiseLike<SupabaseStoreOperationResult<T>>;
76
+ }) => Promise<SupabaseStoreResult<T>>;
77
+ /** 包内 RPC repository;输入在 saver 层物化后,所有写操作都可安全重放。 */
78
+ export declare class LangGraphCheckpointRepository {
79
+ private readonly execute;
80
+ constructor(execute?: RuntimeExecutor);
81
+ putCheckpoint(record: PutCheckpointRecord): Promise<unknown>;
82
+ getCheckpoint(input: {
83
+ threadId: string;
84
+ checkpointNamespace: string;
85
+ checkpointId: string | null;
86
+ }): Promise<unknown>;
87
+ listCheckpoints(query: ListCheckpointQuery): Promise<unknown>;
88
+ putWrites(record: PutWritesRecord): Promise<unknown>;
89
+ getDeltaHistory(input: {
90
+ threadId: string;
91
+ checkpointNamespace: string;
92
+ checkpointId: string | null;
93
+ channels: string[];
94
+ }): Promise<unknown>;
95
+ deleteThread(threadId: string): Promise<unknown>;
96
+ }
97
+ export declare const langGraphCheckpointRepository: LangGraphCheckpointRepository;
98
+ export {};
@@ -0,0 +1,43 @@
1
+ import { BaseCheckpointSaver, type ChannelVersions, type Checkpoint, type CheckpointMetadata, type CheckpointPendingWrite, type DeltaChannelHistory, type PendingWrite, type SerializerProtocol } from "@langchain/langgraph-checkpoint";
2
+ /**
3
+ * 只描述 saver 实际读取和返回的 config 字段,避免 LangChain 双模式包在
4
+ * CommonJS/ESM 消费者之间泄漏两份带 protected 成员的 RunnableConfig 类型。
5
+ */
6
+ export interface LangGraphRunnableConfig {
7
+ configurable?: Record<string, any>;
8
+ [key: string]: any;
9
+ }
10
+ export interface IgaCheckpointTuple {
11
+ config: LangGraphRunnableConfig;
12
+ checkpoint: Checkpoint;
13
+ metadata?: CheckpointMetadata;
14
+ parentConfig?: LangGraphRunnableConfig;
15
+ pendingWrites?: CheckpointPendingWrite[];
16
+ }
17
+ export interface IgaCheckpointListOptions {
18
+ limit?: number;
19
+ before?: LangGraphRunnableConfig;
20
+ filter?: Record<string, any>;
21
+ }
22
+ /** IGA Store 数据面上的 LangGraph CheckpointSaver。 */
23
+ export declare class IgaCheckpointSaver extends BaseCheckpointSaver<string> {
24
+ constructor(serde?: SerializerProtocol);
25
+ get(config: LangGraphRunnableConfig): Promise<Checkpoint | undefined>;
26
+ getTuple(config: LangGraphRunnableConfig): Promise<IgaCheckpointTuple | undefined>;
27
+ list(config: LangGraphRunnableConfig, options?: IgaCheckpointListOptions): AsyncGenerator<IgaCheckpointTuple>;
28
+ put(config: LangGraphRunnableConfig, checkpoint: Checkpoint, metadata: CheckpointMetadata, newVersions: ChannelVersions): Promise<LangGraphRunnableConfig>;
29
+ putWrites(config: LangGraphRunnableConfig, writes: PendingWrite[], taskId: string): Promise<void>;
30
+ deleteThread(threadId: string): Promise<void>;
31
+ getDeltaChannelHistory(options: {
32
+ config: LangGraphRunnableConfig;
33
+ channels: string[];
34
+ }): Promise<Record<string, DeltaChannelHistory>>;
35
+ getNextVersion(current: any): any;
36
+ private dumpMetadata;
37
+ private loadMetadata;
38
+ private dumpValue;
39
+ private loadValue;
40
+ private materializeTuple;
41
+ }
42
+ /** 创建轻量 saver;直到首次 saver 方法调用才访问 IGA Store runtime。 */
43
+ export declare function createCheckpointer(serde?: SerializerProtocol): IgaCheckpointSaver;
@@ -0,0 +1,12 @@
1
+ /**
2
+ * 在结构上等价于 OpenAI Agents SDK 的 Session 合同。
3
+ * 采用结构化适配,避免核心 Store SDK 依赖特定版本的 OpenAI Agents SDK。
4
+ */
5
+ export interface OpenAISession<TItem = any> {
6
+ getSessionId(): Promise<string>;
7
+ getItems(limit?: number): Promise<TItem[]>;
8
+ addItems(items: TItem[]): Promise<void>;
9
+ popItem(): Promise<TItem | undefined>;
10
+ clearSession(): Promise<void>;
11
+ }
12
+ export declare function createSession<TItem = any>(conversationId: string): OpenAISession<TItem>;
@@ -0,0 +1,27 @@
1
+ export declare const DEFAULT_STORE_PAGE_LIMIT = 50;
2
+ export declare const MAX_STORE_PAGE_LIMIT = 100;
3
+ interface ConversationCursorV1 {
4
+ version: 1;
5
+ kind: "conversations";
6
+ updatedAt: string;
7
+ conversationId: string;
8
+ }
9
+ interface MessageCursorV1 {
10
+ version: 1;
11
+ kind: "messages";
12
+ conversationId: string;
13
+ order: "asc" | "desc";
14
+ snapshotSeq: string;
15
+ lastSeq: string;
16
+ }
17
+ export type ConversationCursor = Omit<ConversationCursorV1, "version" | "kind">;
18
+ export type MessageCursor = Omit<MessageCursorV1, "version" | "kind">;
19
+ export declare function normalizeStorePageLimit(limit?: number): number;
20
+ export declare function encodeConversationCursor(cursor: ConversationCursor): string;
21
+ export declare function decodeConversationCursor(value: string): ConversationCursor;
22
+ export declare function encodeMessageCursor(cursor: MessageCursor): string;
23
+ export declare function decodeMessageCursor(value: string, expected: {
24
+ conversationId: string;
25
+ order: "asc" | "desc";
26
+ }): MessageCursor;
27
+ export {};
@@ -0,0 +1,8 @@
1
+ import type { SupabaseClient } from "@supabase/supabase-js";
2
+ import { type Store } from "./store.js";
3
+ import { type ExecuteSupabaseStoreOperationOptions, type SupabaseStoreResult } from "./supabase-transport.js";
4
+ export declare function resolveRuntimeStore(): Promise<Store>;
5
+ /** 包内数据面入口;只接受操作闭包,不向公共 API 暴露 client 或凭证。 */
6
+ export declare function executeRuntimeStoreOperation<T>(options: ExecuteSupabaseStoreOperationOptions<T>): Promise<SupabaseStoreResult<T>>;
7
+ /** 仅供包内类型检查,防止 operation 的 client 类型被意外扩宽。 */
8
+ export type RuntimeStoreOperation<T> = (client: SupabaseClient) => ReturnType<ExecuteSupabaseStoreOperationOptions<T>["operation"]>;
@@ -0,0 +1 @@
1
+ export { store } from "./runtime-store.js";
@@ -0,0 +1,20 @@
1
+ import type { Store } from "./store.js";
2
+ /**
3
+ * 当前 BytePlus IGA Pages 项目的 Store 能力。仅在首次调用方法时读取运行时项目身份,
4
+ * 并在当前进程内复用创建出的 Store;业务代码不能传入项目身份或凭证。
5
+ * 在 Node.js 20+ 的 BytePlus IGA Pages 服务端使用;本地通过 `bp-iga pages link` 关联项目后运行
6
+ * `bp-iga pages dev`。应用负责终端用户身份和会话访问权限校验。
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * import { store } from "@byteplus-iga-pages/agent/store";
11
+ *
12
+ * const { conversationId } = await store.createConversation({
13
+ * metadata: { title: "新对话" },
14
+ * });
15
+ * await store.appendMessage({ conversationId, role: "user", payload: { text: "你好" } });
16
+ * const page = await store.listMessages({ conversationId, order: "desc", limit: 20 });
17
+ * // page.items 最新消息在前;page.nextCursor 为 null 时没有下一页。
18
+ * ```
19
+ */
20
+ export declare const store: Store;