@howone/sdk 0.3.10 → 0.3.11

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.mjs CHANGED
@@ -1959,18 +1959,30 @@ var ToastContent = ({ type, title, message, component, closeToast }) => {
1959
1959
  }
1960
1960
  }
1961
1961
  ),
1962
- /* @__PURE__ */ jsx12("div", { className: "flex-shrink-0 mt-0.5 relative z-10", children: /* @__PURE__ */ jsx12("div", { className: `w-7 h-7 backdrop-blur-sm rounded-full flex items-center justify-center ${theme === "dark" || theme === "system" && window.matchMedia("(prefers-color-scheme: dark)").matches ? "bg-white/10" : "bg-black/5"}`, children: /* @__PURE__ */ jsx12(
1963
- Icon4,
1962
+ /* @__PURE__ */ jsx12("div", { className: "flex-shrink-0 flex-grow-0 mt-0.5 relative z-10", children: /* @__PURE__ */ jsx12(
1963
+ "div",
1964
1964
  {
1965
- icon: iconConfig.icon,
1966
- width: 16,
1967
- height: 16,
1968
- className: iconConfig.color,
1965
+ className: "backdrop-blur-sm rounded-full flex items-center justify-center overflow-hidden flex-shrink-0 flex-grow-0",
1969
1966
  style: {
1970
- color: themeConfig.gradientColor
1971
- }
1967
+ backgroundColor: theme === "dark" || theme === "system" && window.matchMedia("(prefers-color-scheme: dark)").matches ? "rgba(255, 255, 255, 0.1)" : "rgba(0, 0, 0, 0.05)",
1968
+ width: "28px",
1969
+ height: "28px"
1970
+ },
1971
+ children: /* @__PURE__ */ jsx12("div", { className: "rounded-full flex items-center justify-center", children: /* @__PURE__ */ jsx12(
1972
+ Icon4,
1973
+ {
1974
+ icon: iconConfig.icon,
1975
+ width: 16,
1976
+ height: 16,
1977
+ className: `flex-shrink-0`,
1978
+ style: {
1979
+ color: themeConfig.gradientColor,
1980
+ display: "block"
1981
+ }
1982
+ }
1983
+ ) })
1972
1984
  }
1973
- ) }) }),
1985
+ ) }),
1974
1986
  /* @__PURE__ */ jsxs9("div", { className: "flex flex-col gap-1 flex-1 relative z-10", children: [
1975
1987
  title && /* @__PURE__ */ jsx12(
1976
1988
  "div",
@@ -2419,6 +2431,154 @@ function createArtifactsClient(req) {
2419
2431
  };
2420
2432
  }
2421
2433
 
2434
+ // src/services/upload-client.ts
2435
+ function createUploadClient(req, projectId) {
2436
+ const uploadUrl = projectId ? `/entities/apps/${projectId}/files` : "/files";
2437
+ return {
2438
+ /**
2439
+ * 上传单个文件
2440
+ *
2441
+ * @example
2442
+ * ```typescript
2443
+ * const { url } = await client.upload.file(imageFile)
2444
+ * console.log('文件地址:', url)
2445
+ * ```
2446
+ */
2447
+ async file(file, options) {
2448
+ const formData = new FormData();
2449
+ if (typeof file === "string") {
2450
+ if (file.startsWith("data:")) {
2451
+ const response2 = await fetch(file);
2452
+ const blob = await response2.blob();
2453
+ formData.append("file", blob, "upload.bin");
2454
+ } else {
2455
+ formData.append("fileUrl", file);
2456
+ }
2457
+ } else if (file instanceof File) {
2458
+ formData.append("file", file, file.name);
2459
+ } else {
2460
+ formData.append("file", file, "upload.bin");
2461
+ }
2462
+ if (options?.metadata) {
2463
+ formData.append("metadata", JSON.stringify(options.metadata));
2464
+ }
2465
+ const response = await req.post({
2466
+ url: uploadUrl,
2467
+ data: formData,
2468
+ signal: options?.signal
2469
+ });
2470
+ return {
2471
+ url: response.url || response.storageUrl,
2472
+ thumbnailUrl: response.thumbnailUrl,
2473
+ id: response.id,
2474
+ size: response.size,
2475
+ mimeType: response.mimeType || response.contentType
2476
+ };
2477
+ },
2478
+ /**
2479
+ * 上传图片(快捷方法,专为 AI 设计)
2480
+ *
2481
+ * @example
2482
+ * ```typescript
2483
+ * const { url } = await client.upload.image(imageFile)
2484
+ * ```
2485
+ */
2486
+ async image(file) {
2487
+ const result = await this.file(file);
2488
+ return { url: result.url };
2489
+ },
2490
+ /**
2491
+ * 批量上传文件
2492
+ *
2493
+ * @example
2494
+ * ```typescript
2495
+ * const result = await client.upload.batch({
2496
+ * files: [file1, file2, file3],
2497
+ * concurrent: 3,
2498
+ * onProgress: (completed, total) => {
2499
+ * console.log(`${completed}/${total}`)
2500
+ * }
2501
+ * })
2502
+ * ```
2503
+ */
2504
+ async batch(options) {
2505
+ const { files, concurrent = 3, onProgress, onFileComplete, signal } = options;
2506
+ const success = [];
2507
+ const failed = [];
2508
+ let completed = 0;
2509
+ for (let i = 0; i < files.length; i += concurrent) {
2510
+ if (signal?.aborted) break;
2511
+ const batch = files.slice(i, Math.min(i + concurrent, files.length));
2512
+ const promises = batch.map(async (file, batchIndex) => {
2513
+ const globalIndex = i + batchIndex;
2514
+ try {
2515
+ const result = await this.file(file, { signal });
2516
+ success.push(result);
2517
+ if (onFileComplete) {
2518
+ onFileComplete(result, globalIndex);
2519
+ }
2520
+ } catch (error) {
2521
+ const errorMsg = error instanceof Error ? error.message : String(error);
2522
+ failed.push({ index: globalIndex, error: errorMsg });
2523
+ if (onFileComplete) {
2524
+ onFileComplete(
2525
+ error instanceof Error ? error : new Error(errorMsg),
2526
+ globalIndex
2527
+ );
2528
+ }
2529
+ } finally {
2530
+ completed++;
2531
+ if (onProgress) {
2532
+ onProgress(completed, files.length);
2533
+ }
2534
+ }
2535
+ });
2536
+ await Promise.all(promises);
2537
+ }
2538
+ return {
2539
+ success,
2540
+ failed,
2541
+ total: files.length
2542
+ };
2543
+ }
2544
+ };
2545
+ }
2546
+
2547
+ // src/services/ai-client.ts
2548
+ function createAIClient(req, projectId) {
2549
+ const generateImageUrl = projectId ? `/entities/apps/${projectId}/generate-image` : "/generate-image";
2550
+ return {
2551
+ /**
2552
+ * 生成/修改图片
2553
+ *
2554
+ * @example
2555
+ * ```typescript
2556
+ * const result = await client.ai.generateImage({
2557
+ * imageUrl: 'https://example.com/image.jpg',
2558
+ * description: '把天空改成蓝色'
2559
+ * })
2560
+ * console.log('新图片:', result.imageUrl)
2561
+ * ```
2562
+ */
2563
+ async generateImage(options) {
2564
+ const { imageUrl, description, signal } = options;
2565
+ const response = await req.post({
2566
+ url: generateImageUrl,
2567
+ data: {
2568
+ imageUrl,
2569
+ description
2570
+ },
2571
+ signal
2572
+ });
2573
+ return {
2574
+ imageUrl: response.imageUrl || response.url,
2575
+ taskId: response.taskId || response.id,
2576
+ metadata: response.metadata
2577
+ };
2578
+ }
2579
+ };
2580
+ }
2581
+
2422
2582
  // src/services/sse-executor.ts
2423
2583
  init_config();
2424
2584
  async function executeSSEWorkflow(request, options = {}) {
@@ -3492,6 +3652,41 @@ function createClient(opts) {
3492
3652
  workflowExecutor: workflowExecutorFactory,
3493
3653
  // artifact helpers using artifacts-client
3494
3654
  artifacts: createArtifactsClient(biz),
3655
+ /**
3656
+ * 文件上传模块(独立,不依赖 artifact)
3657
+ *
3658
+ * @example
3659
+ * ```typescript
3660
+ * // 最简单的用法
3661
+ * const { url } = await client.upload.file(imageFile)
3662
+ * console.log('文件地址:', url)
3663
+ *
3664
+ * // AI 友好版本(只返回 url)
3665
+ * const { url } = await client.upload.image(imageFile)
3666
+ *
3667
+ * // 批量上传
3668
+ * const result = await client.upload.batch({
3669
+ * files: [file1, file2, file3],
3670
+ * concurrent: 3,
3671
+ * onProgress: (completed, total) => console.log(`${completed}/${total}`)
3672
+ * })
3673
+ * ```
3674
+ */
3675
+ upload: createUploadClient(bizWrapped, opts?.projectId),
3676
+ /**
3677
+ * AI 功能模块
3678
+ *
3679
+ * @example
3680
+ * ```typescript
3681
+ * // 图片生成/修改
3682
+ * const result = await client.ai.generateImage({
3683
+ * imageUrl: 'https://example.com/image.jpg',
3684
+ * description: '把天空改成蓝色'
3685
+ * })
3686
+ * console.log('新图片:', result.imageUrl)
3687
+ * ```
3688
+ */
3689
+ ai: createAIClient(bizWrapped, opts?.projectId),
3495
3690
  me: async () => {
3496
3691
  try {
3497
3692
  let availableToken = getCachedOrGlobalToken();
@@ -3995,12 +4190,14 @@ export {
3995
4190
  ThemeToggle,
3996
4191
  aiWorkflow,
3997
4192
  canAccessArtifact,
4193
+ createAIClient,
3998
4194
  createAIWorkflowClient,
3999
4195
  createAIWorkflowClientAxios,
4000
4196
  createArtifactsClient,
4001
4197
  createClient,
4002
4198
  createSSEClient,
4003
4199
  createSSERequest,
4200
+ createUploadClient,
4004
4201
  elementSelector,
4005
4202
  executeSSEWorkflow,
4006
4203
  getCodeStatus,