@howone/sdk 0.3.10 → 0.3.12
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.d.mts +201 -27
- package/dist/index.d.ts +201 -27
- package/dist/index.js +204 -9
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +202 -9
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
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(
|
|
1963
|
-
|
|
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
|
-
|
|
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:
|
|
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,150 @@ 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.data.publicUrl
|
|
2472
|
+
};
|
|
2473
|
+
},
|
|
2474
|
+
/**
|
|
2475
|
+
* 上传图片(快捷方法,专为 AI 设计)
|
|
2476
|
+
*
|
|
2477
|
+
* @example
|
|
2478
|
+
* ```typescript
|
|
2479
|
+
* const { url } = await client.upload.image(imageFile)
|
|
2480
|
+
* ```
|
|
2481
|
+
*/
|
|
2482
|
+
async image(file) {
|
|
2483
|
+
const result = await this.file(file);
|
|
2484
|
+
return { url: result.url };
|
|
2485
|
+
},
|
|
2486
|
+
/**
|
|
2487
|
+
* 批量上传文件
|
|
2488
|
+
*
|
|
2489
|
+
* @example
|
|
2490
|
+
* ```typescript
|
|
2491
|
+
* const result = await client.upload.batch({
|
|
2492
|
+
* files: [file1, file2, file3],
|
|
2493
|
+
* concurrent: 3,
|
|
2494
|
+
* onProgress: (completed, total) => {
|
|
2495
|
+
* console.log(`${completed}/${total}`)
|
|
2496
|
+
* }
|
|
2497
|
+
* })
|
|
2498
|
+
* ```
|
|
2499
|
+
*/
|
|
2500
|
+
async batch(options) {
|
|
2501
|
+
const { files, concurrent = 3, onProgress, onFileComplete, signal } = options;
|
|
2502
|
+
const success = [];
|
|
2503
|
+
const failed = [];
|
|
2504
|
+
let completed = 0;
|
|
2505
|
+
for (let i = 0; i < files.length; i += concurrent) {
|
|
2506
|
+
if (signal?.aborted) break;
|
|
2507
|
+
const batch = files.slice(i, Math.min(i + concurrent, files.length));
|
|
2508
|
+
const promises = batch.map(async (file, batchIndex) => {
|
|
2509
|
+
const globalIndex = i + batchIndex;
|
|
2510
|
+
try {
|
|
2511
|
+
const result = await this.file(file, { signal });
|
|
2512
|
+
success.push(result);
|
|
2513
|
+
if (onFileComplete) {
|
|
2514
|
+
onFileComplete(result, globalIndex);
|
|
2515
|
+
}
|
|
2516
|
+
} catch (error) {
|
|
2517
|
+
const errorMsg = error instanceof Error ? error.message : String(error);
|
|
2518
|
+
failed.push({ index: globalIndex, error: errorMsg });
|
|
2519
|
+
if (onFileComplete) {
|
|
2520
|
+
onFileComplete(
|
|
2521
|
+
error instanceof Error ? error : new Error(errorMsg),
|
|
2522
|
+
globalIndex
|
|
2523
|
+
);
|
|
2524
|
+
}
|
|
2525
|
+
} finally {
|
|
2526
|
+
completed++;
|
|
2527
|
+
if (onProgress) {
|
|
2528
|
+
onProgress(completed, files.length);
|
|
2529
|
+
}
|
|
2530
|
+
}
|
|
2531
|
+
});
|
|
2532
|
+
await Promise.all(promises);
|
|
2533
|
+
}
|
|
2534
|
+
return {
|
|
2535
|
+
success,
|
|
2536
|
+
failed,
|
|
2537
|
+
total: files.length
|
|
2538
|
+
};
|
|
2539
|
+
}
|
|
2540
|
+
};
|
|
2541
|
+
}
|
|
2542
|
+
|
|
2543
|
+
// src/services/ai-client.ts
|
|
2544
|
+
function createAIClient(req, projectId) {
|
|
2545
|
+
const generateImageUrl = projectId ? `/entities/apps/${projectId}/generate-image` : "/generate-image";
|
|
2546
|
+
return {
|
|
2547
|
+
/**
|
|
2548
|
+
* 生成/修改图片
|
|
2549
|
+
*
|
|
2550
|
+
* @example
|
|
2551
|
+
* ```typescript
|
|
2552
|
+
* const result = await client.ai.generateImage({
|
|
2553
|
+
* imageUrl: 'https://example.com/image.jpg',
|
|
2554
|
+
* description: '把天空改成蓝色'
|
|
2555
|
+
* })
|
|
2556
|
+
* console.log('新图片:', result.imageUrl)
|
|
2557
|
+
* ```
|
|
2558
|
+
*/
|
|
2559
|
+
async generateImage(options) {
|
|
2560
|
+
const { imageUrl, description, signal } = options;
|
|
2561
|
+
const response = await req.post({
|
|
2562
|
+
url: generateImageUrl,
|
|
2563
|
+
data: {
|
|
2564
|
+
imageUrl,
|
|
2565
|
+
description
|
|
2566
|
+
},
|
|
2567
|
+
signal
|
|
2568
|
+
});
|
|
2569
|
+
return {
|
|
2570
|
+
imageUrl: response.imageUrl || response.url,
|
|
2571
|
+
taskId: response.taskId || response.id,
|
|
2572
|
+
metadata: response.metadata
|
|
2573
|
+
};
|
|
2574
|
+
}
|
|
2575
|
+
};
|
|
2576
|
+
}
|
|
2577
|
+
|
|
2422
2578
|
// src/services/sse-executor.ts
|
|
2423
2579
|
init_config();
|
|
2424
2580
|
async function executeSSEWorkflow(request, options = {}) {
|
|
@@ -3492,6 +3648,41 @@ function createClient(opts) {
|
|
|
3492
3648
|
workflowExecutor: workflowExecutorFactory,
|
|
3493
3649
|
// artifact helpers using artifacts-client
|
|
3494
3650
|
artifacts: createArtifactsClient(biz),
|
|
3651
|
+
/**
|
|
3652
|
+
* 文件上传模块(独立,不依赖 artifact)
|
|
3653
|
+
*
|
|
3654
|
+
* @example
|
|
3655
|
+
* ```typescript
|
|
3656
|
+
* // 最简单的用法
|
|
3657
|
+
* const { url } = await client.upload.file(imageFile)
|
|
3658
|
+
* console.log('文件地址:', url)
|
|
3659
|
+
*
|
|
3660
|
+
* // AI 友好版本(只返回 url)
|
|
3661
|
+
* const { url } = await client.upload.image(imageFile)
|
|
3662
|
+
*
|
|
3663
|
+
* // 批量上传
|
|
3664
|
+
* const result = await client.upload.batch({
|
|
3665
|
+
* files: [file1, file2, file3],
|
|
3666
|
+
* concurrent: 3,
|
|
3667
|
+
* onProgress: (completed, total) => console.log(`${completed}/${total}`)
|
|
3668
|
+
* })
|
|
3669
|
+
* ```
|
|
3670
|
+
*/
|
|
3671
|
+
upload: createUploadClient(bizWrapped, opts?.projectId),
|
|
3672
|
+
/**
|
|
3673
|
+
* AI 功能模块
|
|
3674
|
+
*
|
|
3675
|
+
* @example
|
|
3676
|
+
* ```typescript
|
|
3677
|
+
* // 图片生成/修改
|
|
3678
|
+
* const result = await client.ai.generateImage({
|
|
3679
|
+
* imageUrl: 'https://example.com/image.jpg',
|
|
3680
|
+
* description: '把天空改成蓝色'
|
|
3681
|
+
* })
|
|
3682
|
+
* console.log('新图片:', result.imageUrl)
|
|
3683
|
+
* ```
|
|
3684
|
+
*/
|
|
3685
|
+
ai: createAIClient(bizWrapped, opts?.projectId),
|
|
3495
3686
|
me: async () => {
|
|
3496
3687
|
try {
|
|
3497
3688
|
let availableToken = getCachedOrGlobalToken();
|
|
@@ -3995,12 +4186,14 @@ export {
|
|
|
3995
4186
|
ThemeToggle,
|
|
3996
4187
|
aiWorkflow,
|
|
3997
4188
|
canAccessArtifact,
|
|
4189
|
+
createAIClient,
|
|
3998
4190
|
createAIWorkflowClient,
|
|
3999
4191
|
createAIWorkflowClientAxios,
|
|
4000
4192
|
createArtifactsClient,
|
|
4001
4193
|
createClient,
|
|
4002
4194
|
createSSEClient,
|
|
4003
4195
|
createSSERequest,
|
|
4196
|
+
createUploadClient,
|
|
4004
4197
|
elementSelector,
|
|
4005
4198
|
executeSSEWorkflow,
|
|
4006
4199
|
getCodeStatus,
|