@tencent-ai/cloud-agent-sdk 0.2.2 → 0.2.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.
@@ -1,11 +1,10 @@
1
- //#region rolldown:runtime
2
- var __commonJSMin = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
3
- var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, { get: (a, b) => (typeof require !== "undefined" ? require : a)[b] }) : x)(function(x) {
4
- if (typeof require !== "undefined") return require.apply(this, arguments);
5
- throw Error("Calling `require` for \"" + x + "\" in an environment that doesn't expose the `require` function. See https://rolldown.rs/in-depth/bundling-cjs#require-external-modules for more details.");
6
- });
1
+ import * as __external_zod from 'zod';
2
+ import * as __external_acp_sdk from '@agentclientprotocol/sdk';
3
+ import * as __external_connect from '@connectrpc/connect';
4
+ import * as __external_connect_web from '@connectrpc/connect-web';
5
+ import * as __external_protobuf from '@bufbuild/protobuf';
6
+ import * as __external_e2b from 'e2b';
7
7
 
8
- //#endregion
9
8
  //#region ../agent-provider/lib/common/_legacy/tool-schemas.js
10
9
  var require_tool_schemas = /* @__PURE__ */ __commonJSMin(((exports) => {
11
10
  /**
@@ -18,7 +17,7 @@ var require_tool_schemas = /* @__PURE__ */ __commonJSMin(((exports) => {
18
17
  exports.ToolOutputSchemas = exports.ToolInputSchemas = void 0;
19
18
  exports.validateToolInput = validateToolInput;
20
19
  exports.validateToolOutput = validateToolOutput;
21
- const zod_1 = __require("zod");
20
+ const zod_1 = __external_zod;
22
21
  /**
23
22
  * 工具输入 Schema 定义
24
23
  * 用于验证和约束 rawInput
@@ -3519,7 +3518,7 @@ var require_sdk = /* @__PURE__ */ __commonJSMin(((exports) => {
3519
3518
  */
3520
3519
  Object.defineProperty(exports, "__esModule", { value: true });
3521
3520
  exports.PROTOCOL_VERSION = void 0;
3522
- var sdk_1$2 = __require("@agentclientprotocol/sdk");
3521
+ var sdk_1$2 = __external_acp_sdk;
3523
3522
  Object.defineProperty(exports, "PROTOCOL_VERSION", {
3524
3523
  enumerable: true,
3525
3524
  get: function() {
@@ -10937,9 +10936,9 @@ var require_connectrpc_http = /* @__PURE__ */ __commonJSMin(((exports) => {
10937
10936
  */
10938
10937
  Object.defineProperty(exports, "__esModule", { value: true });
10939
10938
  exports.connectRpcHttp = connectRpcHttp;
10940
- const connect_1 = __require("@connectrpc/connect");
10941
- const connect_web_1 = __require("@connectrpc/connect-web");
10942
- const protobuf_1 = __require("@bufbuild/protobuf");
10939
+ const connect_1 = __external_connect;
10940
+ const connect_web_1 = __external_connect_web;
10941
+ const protobuf_1 = __external_protobuf;
10943
10942
  const acp_pb_1 = require_acp_pb();
10944
10943
  /**
10945
10944
  * Create a ConnectRPC HTTP transport for ACP.
@@ -11983,7 +11982,7 @@ var require_client$3 = /* @__PURE__ */ __commonJSMin(((exports) => {
11983
11982
  */
11984
11983
  Object.defineProperty(exports, "__esModule", { value: true });
11985
11984
  exports.StreamableHttpClient = void 0;
11986
- const sdk_1$1 = __require("@agentclientprotocol/sdk");
11985
+ const sdk_1$1 = __external_acp_sdk;
11987
11986
  const streamable_http_js_1 = require_streamable_http();
11988
11987
  const constants_js_1 = require_constants();
11989
11988
  const errors_js_1 = require_errors();
@@ -13003,7 +13002,7 @@ var require_e2b_filesystem = /* @__PURE__ */ __commonJSMin(((exports) => {
13003
13002
  */
13004
13003
  Object.defineProperty(exports, "__esModule", { value: true });
13005
13004
  exports.E2BFilesystem = void 0;
13006
- const e2b_1$1 = __require("e2b");
13005
+ const e2b_1$1 = __external_e2b;
13007
13006
  /**
13008
13007
  * E2B Filesystem Implementation
13009
13008
  *
@@ -13036,7 +13035,6 @@ var require_e2b_filesystem = /* @__PURE__ */ __commonJSMin(((exports) => {
13036
13035
  static async connect(info) {
13037
13036
  return new E2BFilesystem(await e2b_1$1.Sandbox.connect(info.sandboxId, {
13038
13037
  apiKey: info.apiKey,
13039
- accessToken: info.accessToken,
13040
13038
  domain: info.domain,
13041
13039
  apiUrl: info.apiUrl,
13042
13040
  requestTimeoutMs: info.requestTimeoutMs,
@@ -13082,6 +13080,152 @@ var require_e2b_filesystem = /* @__PURE__ */ __commonJSMin(((exports) => {
13082
13080
  exports.default = E2BFilesystem;
13083
13081
  }));
13084
13082
 
13083
+ //#endregion
13084
+ //#region ../agent-provider/lib/common/providers/cloud-agent-provider/cos-upload-service.js
13085
+ var require_cos_upload_service = /* @__PURE__ */ __commonJSMin(((exports) => {
13086
+ /**
13087
+ * COS Upload Service
13088
+ *
13089
+ * 负责通过预签名 URL 上传文件到腾讯云 COS
13090
+ *
13091
+ * 上传流程:
13092
+ * 1. 生成 objectKey (uploads/{timestamp}-{random}-{filename})
13093
+ * 2. 请求后端获取 PUT 预签名 URL
13094
+ * 3. 使用预签名 URL 直接上传文件到 COS
13095
+ * 4. 请求后端获取 GET 预签名 URL 作为访问地址
13096
+ */
13097
+ Object.defineProperty(exports, "__esModule", { value: true });
13098
+ exports.CosUploadService = void 0;
13099
+ /**
13100
+ * COS 上传服务
13101
+ *
13102
+ * @example
13103
+ * ```typescript
13104
+ * const service = new CosUploadService({
13105
+ * request: (method, path, body) => cloudProvider.request(method, path, body),
13106
+ * logger: console,
13107
+ * });
13108
+ *
13109
+ * const result = await service.uploadFile(file);
13110
+ * if (result.success) {
13111
+ * console.log('File URL:', result.url);
13112
+ * }
13113
+ * ```
13114
+ */
13115
+ var CosUploadService = class {
13116
+ constructor(options) {
13117
+ var _a;
13118
+ this.request = options.request;
13119
+ this.logger = options.logger;
13120
+ this.fetchImpl = (_a = options.fetch) !== null && _a !== void 0 ? _a : globalThis.fetch.bind(globalThis);
13121
+ }
13122
+ /**
13123
+ * 生成唯一的 objectKey
13124
+ *
13125
+ * 格式: uploads/{timestamp}-{randomId}-{encodedFilename}
13126
+ */
13127
+ generateObjectKey(filename) {
13128
+ return `uploads/${Date.now()}-${Math.random().toString(36).substring(2, 10)}-${encodeURIComponent(filename)}`;
13129
+ }
13130
+ /**
13131
+ * 获取预签名 URL
13132
+ *
13133
+ * POST /conversation/artifacts/presigned_url
13134
+ */
13135
+ async getPresignedUrl(params) {
13136
+ const response = await this.request("POST", "/conversation/artifacts/presigned_url", params);
13137
+ if (!response.ok) throw new Error(`Failed to get presigned URL: ${response.statusText}`);
13138
+ const apiResponse = await response.json();
13139
+ if (!apiResponse.data) throw new Error("No data in presigned URL response");
13140
+ return apiResponse.data;
13141
+ }
13142
+ /**
13143
+ * 上传单个文件到 COS
13144
+ *
13145
+ * @param file - 要上传的文件
13146
+ * @param expireSeconds - 预签名 URL 过期时间(秒),默认 3600
13147
+ * @returns 上传结果,包含访问 URL 或错误信息
13148
+ */
13149
+ async uploadFile(file, expireSeconds = 3600) {
13150
+ var _a, _b, _c, _d, _e, _f;
13151
+ const filename = file.name;
13152
+ (_a = this.logger) === null || _a === void 0 || _a.info(`[CosUploadService] Uploading file: ${filename}`);
13153
+ try {
13154
+ const objectKey = this.generateObjectKey(filename);
13155
+ (_b = this.logger) === null || _b === void 0 || _b.debug(`[CosUploadService] Generated objectKey: ${objectKey}`);
13156
+ const putPresigned = await this.getPresignedUrl({
13157
+ object_key: objectKey,
13158
+ method: "PUT",
13159
+ expire_seconds: expireSeconds
13160
+ });
13161
+ (_c = this.logger) === null || _c === void 0 || _c.debug(`[CosUploadService] Got PUT presigned URL`);
13162
+ const uploadResponse = await this.fetchImpl(putPresigned.url, {
13163
+ method: "PUT",
13164
+ body: file,
13165
+ headers: { "Content-Type": file.type || "application/octet-stream" }
13166
+ });
13167
+ if (!uploadResponse.ok) {
13168
+ const errorText = await uploadResponse.text().catch(() => uploadResponse.statusText);
13169
+ throw new Error(`COS upload failed: ${uploadResponse.status} ${errorText}`);
13170
+ }
13171
+ (_d = this.logger) === null || _d === void 0 || _d.debug(`[CosUploadService] File uploaded to COS`);
13172
+ const getPresigned = await this.getPresignedUrl({
13173
+ object_key: objectKey,
13174
+ method: "GET",
13175
+ expire_seconds: expireSeconds
13176
+ });
13177
+ (_e = this.logger) === null || _e === void 0 || _e.info(`[CosUploadService] Upload success: ${filename}`);
13178
+ return {
13179
+ success: true,
13180
+ url: getPresigned.url
13181
+ };
13182
+ } catch (error) {
13183
+ const errorMessage = error instanceof Error ? error.message : "Unknown error";
13184
+ (_f = this.logger) === null || _f === void 0 || _f.error(`[CosUploadService] Upload failed: ${filename}`, error);
13185
+ return {
13186
+ success: false,
13187
+ error: errorMessage
13188
+ };
13189
+ }
13190
+ }
13191
+ /**
13192
+ * 批量上传文件到 COS
13193
+ *
13194
+ * @param files - 要上传的文件数组
13195
+ * @param expireSeconds - 预签名 URL 过期时间(秒),默认 3600
13196
+ * @returns 所有文件的上传结果
13197
+ */
13198
+ async uploadFiles(files, expireSeconds = 3600) {
13199
+ var _a, _b;
13200
+ (_a = this.logger) === null || _a === void 0 || _a.info(`[CosUploadService] Uploading ${files.length} file(s)`);
13201
+ const results = [];
13202
+ const urls = [];
13203
+ for (const file of files) {
13204
+ const result = await this.uploadFile(file, expireSeconds);
13205
+ results.push(result);
13206
+ if (result.success && result.url) urls.push(result.url);
13207
+ }
13208
+ const failedResults = results.filter((r) => !r.success);
13209
+ if (failedResults.length > 0) {
13210
+ const failedErrors = failedResults.map((r) => r.error).join("; ");
13211
+ return {
13212
+ success: false,
13213
+ error: `${failedResults.length} file(s) failed: ${failedErrors}`,
13214
+ results
13215
+ };
13216
+ }
13217
+ (_b = this.logger) === null || _b === void 0 || _b.info(`[CosUploadService] All ${files.length} file(s) uploaded successfully`);
13218
+ return {
13219
+ success: true,
13220
+ urls,
13221
+ results
13222
+ };
13223
+ }
13224
+ };
13225
+ exports.CosUploadService = CosUploadService;
13226
+ exports.default = CosUploadService;
13227
+ }));
13228
+
13085
13229
  //#endregion
13086
13230
  //#region ../agent-provider/lib/backend/types.js
13087
13231
  var require_types$2 = /* @__PURE__ */ __commonJSMin(((exports) => {
@@ -13708,6 +13852,7 @@ var require_cloud_provider = /* @__PURE__ */ __commonJSMin(((exports) => {
13708
13852
  exports.CloudAgentProvider = void 0;
13709
13853
  const cloud_connection_js_1 = require_cloud_connection();
13710
13854
  const e2b_filesystem_js_1 = require_e2b_filesystem();
13855
+ const cos_upload_service_js_1 = require_cos_upload_service();
13711
13856
  const index_js_1 = require_backend();
13712
13857
  /**
13713
13858
  * CloudAgentProvider - Manages cloud-hosted agents via REST API
@@ -13788,6 +13933,11 @@ var require_cloud_provider = /* @__PURE__ */ __commonJSMin(((exports) => {
13788
13933
  this.options = options;
13789
13934
  this.logger = options.logger;
13790
13935
  this.fetchImpl = (_a = options.fetch) !== null && _a !== void 0 ? _a : globalThis.fetch.bind(globalThis);
13936
+ this.cosUploadService = new cos_upload_service_js_1.CosUploadService({
13937
+ request: (method, path, body) => this.request(method, path, body),
13938
+ logger: this.logger,
13939
+ fetch: this.fetchImpl
13940
+ });
13791
13941
  }
13792
13942
  /**
13793
13943
  * Get the filesystem provider (returns self)
@@ -14044,7 +14194,7 @@ var require_cloud_provider = /* @__PURE__ */ __commonJSMin(((exports) => {
14044
14194
  var _a, _b, _c;
14045
14195
  try {
14046
14196
  const body = { title };
14047
- const response = await this.request("PATCH", `/v2/cloudagent/agentmgmt/agents/${agentId}`, body);
14197
+ const response = await this.request("POST", `/console/cloudagent/agentmgmt/agents/${agentId}`, body);
14048
14198
  if (!response.ok) throw new Error(`Failed to rename agent: ${response.statusText}`);
14049
14199
  const apiResponse = await response.json();
14050
14200
  if (!apiResponse.data) {
@@ -14151,27 +14301,25 @@ var require_cloud_provider = /* @__PURE__ */ __commonJSMin(((exports) => {
14151
14301
  }[extLower] || null;
14152
14302
  }
14153
14303
  /**
14154
- * Upload files to cloud storage
14304
+ * Upload files to cloud storage via COS presigned URL
14155
14305
  *
14156
14306
  * @param params - files array (File objects in browser)
14157
14307
  * @returns Response with corresponding cloud URLs
14158
14308
  */
14159
14309
  async uploadFile(params) {
14160
- var _a, _b, _c;
14310
+ var _a;
14161
14311
  (_a = this.logger) === null || _a === void 0 || _a.info(`[CloudAgentProvider] uploadFile called for ${params.files.length} file(s)`);
14162
- try {
14163
- (_b = this.logger) === null || _b === void 0 || _b.warn("[CloudAgentProvider] uploadFile: Not implemented yet");
14164
- return {
14165
- success: false,
14166
- error: "Upload API not implemented yet"
14167
- };
14168
- } catch (error) {
14169
- (_c = this.logger) === null || _c === void 0 || _c.error("[CloudAgentProvider] uploadFile failed:", error);
14170
- return {
14171
- success: false,
14172
- error: error instanceof Error ? error.message : "Upload failed"
14173
- };
14174
- }
14312
+ const files = params.files.filter((f) => typeof f !== "string");
14313
+ if (files.length === 0) return {
14314
+ success: false,
14315
+ error: "No valid File objects provided"
14316
+ };
14317
+ const result = await this.cosUploadService.uploadFiles(files);
14318
+ return {
14319
+ success: result.success,
14320
+ urls: result.urls,
14321
+ error: result.error
14322
+ };
14175
14323
  }
14176
14324
  toAgentState(data) {
14177
14325
  const status = data.sessionStatus || data.status;
@@ -14235,7 +14383,7 @@ var require_cloud_agent_provider = /* @__PURE__ */ __commonJSMin(((exports) => {
14235
14383
  * Cloud Agent Provider exports
14236
14384
  */
14237
14385
  Object.defineProperty(exports, "__esModule", { value: true });
14238
- exports.E2BFilesystem = exports.CloudAgentProvider = exports.CloudAgentConnection = void 0;
14386
+ exports.CosUploadService = exports.E2BFilesystem = exports.CloudAgentProvider = exports.CloudAgentConnection = void 0;
14239
14387
  var cloud_connection_js_1 = require_cloud_connection();
14240
14388
  Object.defineProperty(exports, "CloudAgentConnection", {
14241
14389
  enumerable: true,
@@ -14257,6 +14405,13 @@ var require_cloud_agent_provider = /* @__PURE__ */ __commonJSMin(((exports) => {
14257
14405
  return e2b_filesystem_js_1.E2BFilesystem;
14258
14406
  }
14259
14407
  });
14408
+ var cos_upload_service_js_1 = require_cos_upload_service();
14409
+ Object.defineProperty(exports, "CosUploadService", {
14410
+ enumerable: true,
14411
+ get: function() {
14412
+ return cos_upload_service_js_1.CosUploadService;
14413
+ }
14414
+ });
14260
14415
  }));
14261
14416
 
14262
14417
  //#endregion
@@ -14943,7 +15098,7 @@ var require_local_connection = /* @__PURE__ */ __commonJSMin(((exports) => {
14943
15098
  */
14944
15099
  Object.defineProperty(exports, "__esModule", { value: true });
14945
15100
  exports.IPCAgentConnection = exports.LocalAgentConnection = void 0;
14946
- const sdk_1 = __require("@agentclientprotocol/sdk");
15101
+ const sdk_1 = __external_acp_sdk;
14947
15102
  const index_js_1 = require_acp();
14948
15103
  /**
14949
15104
  * Local Agent Connection implementation
@@ -17323,7 +17478,7 @@ var require_mock_agent_client = /* @__PURE__ */ __commonJSMin(((exports) => {
17323
17478
  */
17324
17479
  Object.defineProperty(exports, "__esModule", { value: true });
17325
17480
  exports.MockAgentClient = exports.MockAgentConnection = exports.MockHelpers = void 0;
17326
- const e2b_1 = __require("e2b");
17481
+ const e2b_1 = __external_e2b;
17327
17482
  const client_js_1 = require_client$1();
17328
17483
  const MockAgentProvider_js_1 = require_MockAgentProvider();
17329
17484
  exports.MockHelpers = {
package/dist/index.cjs CHANGED
@@ -13033,7 +13033,6 @@ var require_e2b_filesystem = /* @__PURE__ */ __commonJSMin(((exports) => {
13033
13033
  static async connect(info) {
13034
13034
  return new E2BFilesystem(await e2b_1$1.Sandbox.connect(info.sandboxId, {
13035
13035
  apiKey: info.apiKey,
13036
- accessToken: info.accessToken,
13037
13036
  domain: info.domain,
13038
13037
  apiUrl: info.apiUrl,
13039
13038
  requestTimeoutMs: info.requestTimeoutMs,
@@ -13079,6 +13078,152 @@ var require_e2b_filesystem = /* @__PURE__ */ __commonJSMin(((exports) => {
13079
13078
  exports.default = E2BFilesystem;
13080
13079
  }));
13081
13080
 
13081
+ //#endregion
13082
+ //#region ../agent-provider/lib/common/providers/cloud-agent-provider/cos-upload-service.js
13083
+ var require_cos_upload_service = /* @__PURE__ */ __commonJSMin(((exports) => {
13084
+ /**
13085
+ * COS Upload Service
13086
+ *
13087
+ * 负责通过预签名 URL 上传文件到腾讯云 COS
13088
+ *
13089
+ * 上传流程:
13090
+ * 1. 生成 objectKey (uploads/{timestamp}-{random}-{filename})
13091
+ * 2. 请求后端获取 PUT 预签名 URL
13092
+ * 3. 使用预签名 URL 直接上传文件到 COS
13093
+ * 4. 请求后端获取 GET 预签名 URL 作为访问地址
13094
+ */
13095
+ Object.defineProperty(exports, "__esModule", { value: true });
13096
+ exports.CosUploadService = void 0;
13097
+ /**
13098
+ * COS 上传服务
13099
+ *
13100
+ * @example
13101
+ * ```typescript
13102
+ * const service = new CosUploadService({
13103
+ * request: (method, path, body) => cloudProvider.request(method, path, body),
13104
+ * logger: console,
13105
+ * });
13106
+ *
13107
+ * const result = await service.uploadFile(file);
13108
+ * if (result.success) {
13109
+ * console.log('File URL:', result.url);
13110
+ * }
13111
+ * ```
13112
+ */
13113
+ var CosUploadService = class {
13114
+ constructor(options) {
13115
+ var _a;
13116
+ this.request = options.request;
13117
+ this.logger = options.logger;
13118
+ this.fetchImpl = (_a = options.fetch) !== null && _a !== void 0 ? _a : globalThis.fetch.bind(globalThis);
13119
+ }
13120
+ /**
13121
+ * 生成唯一的 objectKey
13122
+ *
13123
+ * 格式: uploads/{timestamp}-{randomId}-{encodedFilename}
13124
+ */
13125
+ generateObjectKey(filename) {
13126
+ return `uploads/${Date.now()}-${Math.random().toString(36).substring(2, 10)}-${encodeURIComponent(filename)}`;
13127
+ }
13128
+ /**
13129
+ * 获取预签名 URL
13130
+ *
13131
+ * POST /conversation/artifacts/presigned_url
13132
+ */
13133
+ async getPresignedUrl(params) {
13134
+ const response = await this.request("POST", "/conversation/artifacts/presigned_url", params);
13135
+ if (!response.ok) throw new Error(`Failed to get presigned URL: ${response.statusText}`);
13136
+ const apiResponse = await response.json();
13137
+ if (!apiResponse.data) throw new Error("No data in presigned URL response");
13138
+ return apiResponse.data;
13139
+ }
13140
+ /**
13141
+ * 上传单个文件到 COS
13142
+ *
13143
+ * @param file - 要上传的文件
13144
+ * @param expireSeconds - 预签名 URL 过期时间(秒),默认 3600
13145
+ * @returns 上传结果,包含访问 URL 或错误信息
13146
+ */
13147
+ async uploadFile(file, expireSeconds = 3600) {
13148
+ var _a, _b, _c, _d, _e, _f;
13149
+ const filename = file.name;
13150
+ (_a = this.logger) === null || _a === void 0 || _a.info(`[CosUploadService] Uploading file: ${filename}`);
13151
+ try {
13152
+ const objectKey = this.generateObjectKey(filename);
13153
+ (_b = this.logger) === null || _b === void 0 || _b.debug(`[CosUploadService] Generated objectKey: ${objectKey}`);
13154
+ const putPresigned = await this.getPresignedUrl({
13155
+ object_key: objectKey,
13156
+ method: "PUT",
13157
+ expire_seconds: expireSeconds
13158
+ });
13159
+ (_c = this.logger) === null || _c === void 0 || _c.debug(`[CosUploadService] Got PUT presigned URL`);
13160
+ const uploadResponse = await this.fetchImpl(putPresigned.url, {
13161
+ method: "PUT",
13162
+ body: file,
13163
+ headers: { "Content-Type": file.type || "application/octet-stream" }
13164
+ });
13165
+ if (!uploadResponse.ok) {
13166
+ const errorText = await uploadResponse.text().catch(() => uploadResponse.statusText);
13167
+ throw new Error(`COS upload failed: ${uploadResponse.status} ${errorText}`);
13168
+ }
13169
+ (_d = this.logger) === null || _d === void 0 || _d.debug(`[CosUploadService] File uploaded to COS`);
13170
+ const getPresigned = await this.getPresignedUrl({
13171
+ object_key: objectKey,
13172
+ method: "GET",
13173
+ expire_seconds: expireSeconds
13174
+ });
13175
+ (_e = this.logger) === null || _e === void 0 || _e.info(`[CosUploadService] Upload success: ${filename}`);
13176
+ return {
13177
+ success: true,
13178
+ url: getPresigned.url
13179
+ };
13180
+ } catch (error) {
13181
+ const errorMessage = error instanceof Error ? error.message : "Unknown error";
13182
+ (_f = this.logger) === null || _f === void 0 || _f.error(`[CosUploadService] Upload failed: ${filename}`, error);
13183
+ return {
13184
+ success: false,
13185
+ error: errorMessage
13186
+ };
13187
+ }
13188
+ }
13189
+ /**
13190
+ * 批量上传文件到 COS
13191
+ *
13192
+ * @param files - 要上传的文件数组
13193
+ * @param expireSeconds - 预签名 URL 过期时间(秒),默认 3600
13194
+ * @returns 所有文件的上传结果
13195
+ */
13196
+ async uploadFiles(files, expireSeconds = 3600) {
13197
+ var _a, _b;
13198
+ (_a = this.logger) === null || _a === void 0 || _a.info(`[CosUploadService] Uploading ${files.length} file(s)`);
13199
+ const results = [];
13200
+ const urls = [];
13201
+ for (const file of files) {
13202
+ const result = await this.uploadFile(file, expireSeconds);
13203
+ results.push(result);
13204
+ if (result.success && result.url) urls.push(result.url);
13205
+ }
13206
+ const failedResults = results.filter((r) => !r.success);
13207
+ if (failedResults.length > 0) {
13208
+ const failedErrors = failedResults.map((r) => r.error).join("; ");
13209
+ return {
13210
+ success: false,
13211
+ error: `${failedResults.length} file(s) failed: ${failedErrors}`,
13212
+ results
13213
+ };
13214
+ }
13215
+ (_b = this.logger) === null || _b === void 0 || _b.info(`[CosUploadService] All ${files.length} file(s) uploaded successfully`);
13216
+ return {
13217
+ success: true,
13218
+ urls,
13219
+ results
13220
+ };
13221
+ }
13222
+ };
13223
+ exports.CosUploadService = CosUploadService;
13224
+ exports.default = CosUploadService;
13225
+ }));
13226
+
13082
13227
  //#endregion
13083
13228
  //#region ../agent-provider/lib/backend/types.js
13084
13229
  var require_types$2 = /* @__PURE__ */ __commonJSMin(((exports) => {
@@ -13705,6 +13850,7 @@ var require_cloud_provider = /* @__PURE__ */ __commonJSMin(((exports) => {
13705
13850
  exports.CloudAgentProvider = void 0;
13706
13851
  const cloud_connection_js_1 = require_cloud_connection();
13707
13852
  const e2b_filesystem_js_1 = require_e2b_filesystem();
13853
+ const cos_upload_service_js_1 = require_cos_upload_service();
13708
13854
  const index_js_1 = require_backend();
13709
13855
  /**
13710
13856
  * CloudAgentProvider - Manages cloud-hosted agents via REST API
@@ -13785,6 +13931,11 @@ var require_cloud_provider = /* @__PURE__ */ __commonJSMin(((exports) => {
13785
13931
  this.options = options;
13786
13932
  this.logger = options.logger;
13787
13933
  this.fetchImpl = (_a = options.fetch) !== null && _a !== void 0 ? _a : globalThis.fetch.bind(globalThis);
13934
+ this.cosUploadService = new cos_upload_service_js_1.CosUploadService({
13935
+ request: (method, path, body) => this.request(method, path, body),
13936
+ logger: this.logger,
13937
+ fetch: this.fetchImpl
13938
+ });
13788
13939
  }
13789
13940
  /**
13790
13941
  * Get the filesystem provider (returns self)
@@ -14041,7 +14192,7 @@ var require_cloud_provider = /* @__PURE__ */ __commonJSMin(((exports) => {
14041
14192
  var _a, _b, _c;
14042
14193
  try {
14043
14194
  const body = { title };
14044
- const response = await this.request("PATCH", `/v2/cloudagent/agentmgmt/agents/${agentId}`, body);
14195
+ const response = await this.request("POST", `/console/cloudagent/agentmgmt/agents/${agentId}`, body);
14045
14196
  if (!response.ok) throw new Error(`Failed to rename agent: ${response.statusText}`);
14046
14197
  const apiResponse = await response.json();
14047
14198
  if (!apiResponse.data) {
@@ -14148,27 +14299,25 @@ var require_cloud_provider = /* @__PURE__ */ __commonJSMin(((exports) => {
14148
14299
  }[extLower] || null;
14149
14300
  }
14150
14301
  /**
14151
- * Upload files to cloud storage
14302
+ * Upload files to cloud storage via COS presigned URL
14152
14303
  *
14153
14304
  * @param params - files array (File objects in browser)
14154
14305
  * @returns Response with corresponding cloud URLs
14155
14306
  */
14156
14307
  async uploadFile(params) {
14157
- var _a, _b, _c;
14308
+ var _a;
14158
14309
  (_a = this.logger) === null || _a === void 0 || _a.info(`[CloudAgentProvider] uploadFile called for ${params.files.length} file(s)`);
14159
- try {
14160
- (_b = this.logger) === null || _b === void 0 || _b.warn("[CloudAgentProvider] uploadFile: Not implemented yet");
14161
- return {
14162
- success: false,
14163
- error: "Upload API not implemented yet"
14164
- };
14165
- } catch (error) {
14166
- (_c = this.logger) === null || _c === void 0 || _c.error("[CloudAgentProvider] uploadFile failed:", error);
14167
- return {
14168
- success: false,
14169
- error: error instanceof Error ? error.message : "Upload failed"
14170
- };
14171
- }
14310
+ const files = params.files.filter((f) => typeof f !== "string");
14311
+ if (files.length === 0) return {
14312
+ success: false,
14313
+ error: "No valid File objects provided"
14314
+ };
14315
+ const result = await this.cosUploadService.uploadFiles(files);
14316
+ return {
14317
+ success: result.success,
14318
+ urls: result.urls,
14319
+ error: result.error
14320
+ };
14172
14321
  }
14173
14322
  toAgentState(data) {
14174
14323
  const status = data.sessionStatus || data.status;
@@ -14232,7 +14381,7 @@ var require_cloud_agent_provider = /* @__PURE__ */ __commonJSMin(((exports) => {
14232
14381
  * Cloud Agent Provider exports
14233
14382
  */
14234
14383
  Object.defineProperty(exports, "__esModule", { value: true });
14235
- exports.E2BFilesystem = exports.CloudAgentProvider = exports.CloudAgentConnection = void 0;
14384
+ exports.CosUploadService = exports.E2BFilesystem = exports.CloudAgentProvider = exports.CloudAgentConnection = void 0;
14236
14385
  var cloud_connection_js_1 = require_cloud_connection();
14237
14386
  Object.defineProperty(exports, "CloudAgentConnection", {
14238
14387
  enumerable: true,
@@ -14254,6 +14403,13 @@ var require_cloud_agent_provider = /* @__PURE__ */ __commonJSMin(((exports) => {
14254
14403
  return e2b_filesystem_js_1.E2BFilesystem;
14255
14404
  }
14256
14405
  });
14406
+ var cos_upload_service_js_1 = require_cos_upload_service();
14407
+ Object.defineProperty(exports, "CosUploadService", {
14408
+ enumerable: true,
14409
+ get: function() {
14410
+ return cos_upload_service_js_1.CosUploadService;
14411
+ }
14412
+ });
14257
14413
  }));
14258
14414
 
14259
14415
  //#endregion