yichong-canva2 1.4.0 → 2.0.0
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/README.md +76 -8
- package/dist/api/chat.js +38 -0
- package/dist/api/request.js +2 -1
- package/dist/login/context.js +3 -0
- package/dist/login/privider.js +9 -2
- package/dist/types/api/chat.d.ts +4 -0
- package/dist/types/api/index.d.ts +1 -1
- package/dist/types/api/request.d.ts +1 -0
- package/dist/types/api/types.d.ts +22 -0
- package/dist/types/login/context.d.ts +2 -2
- package/dist/types/login/privider.d.ts +3 -1
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
## 使用
|
|
6
6
|
|
|
7
7
|
```sh
|
|
8
|
-
npm install yichong-canva2@
|
|
8
|
+
npm install yichong-canva2@2.0.0
|
|
9
9
|
```
|
|
10
10
|
|
|
11
11
|
`1.2.0` 新增文本审核、三个消费接口,以及 Cloudflare R2 单次和分片上传;继续复用原有 Provider。
|
|
@@ -14,7 +14,11 @@ npm install yichong-canva2@1.3.1
|
|
|
14
14
|
|
|
15
15
|
`1.3.1` 补齐通用参数中的 `timezone`,并统一旧登录、通行证、状态查询、版本配置及旧消费请求。
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
`1.4.0` 新增 `client.contentExtract` 内容提取接口,已发布到 npm。
|
|
18
|
+
|
|
19
|
+
`2.0.0` 要求宿主应用使用 React / React DOM 19(`^19.0.0`),开发和测试依赖统一为 `19.3.0`,并新增 `client.chat` 大模型接口。仍使用 React 18 的旧应用请继续使用 `1.x`,升级 React 后再安装 `2.x`。
|
|
20
|
+
|
|
21
|
+
React 继续作为 peer dependency,不打入工具包产物。应用与 Provider 必须复用同一份 React;即使版本相同,本地源码链接也可能引入两个实例。开发时优先使用脚手架 `--sdk-path` 的 tarball 安装方式;直接链接源码时需将 React 解析统一到应用的依赖目录。
|
|
18
22
|
|
|
19
23
|
```tsx
|
|
20
24
|
import { useState } from "react";
|
|
@@ -82,6 +86,8 @@ function GenerateButton() {
|
|
|
82
86
|
|
|
83
87
|
内容提取默认使用 `https://ai.imgkits.com`,无需新增配置。Provider 可选的 `contentBaseUrl` 仅供覆盖测试服务地址;它独立于 `apiBaseUrl` 和 `uploadBaseUrl`,后者只控制上传签名服务。
|
|
84
88
|
|
|
89
|
+
大模型 `chat` 同样默认使用 `https://ai.imgkits.com`,无需新增配置。Provider 可选的 `chatBaseUrl` 仅供覆盖大模型测试服务地址,独立于 `apiBaseUrl`、`contentBaseUrl` 和 `uploadBaseUrl`。
|
|
90
|
+
|
|
85
91
|
语言默认在每次请求时读取 `document.documentElement.lang` 或浏览器语言;应用有自己的国际化状态时,在 Provider 上传 `getLocale={() => currentLocale}`。
|
|
86
92
|
|
|
87
93
|
## 后端接口
|
|
@@ -91,7 +97,8 @@ function GenerateButton() {
|
|
|
91
97
|
| `client.createSpecifyPrediction({ owner, name, input })` | `POST /replicate/createSpecifyPrediction` | `{ code: 0, msg: "ok", data: "任务 ID" }` |
|
|
92
98
|
| `client.getPrediction({ id })` | `POST /replicate/getPrediction` | `{ code: 0, msg: "ok", data: { id, status, output, ... } }` |
|
|
93
99
|
| `client.textCheck({ text, scene? })` | `POST /api/public/text-moderation/check` | `{ code: 0, msg: "展示文案", data: { allowed, decision, categories, ... } }` |
|
|
94
|
-
| `client.contentExtract({ type, url })
|
|
100
|
+
| `client.contentExtract({ type, url })` | `POST {contentBaseUrl}/api/content-extract` | `{ code: 0, msg, data: { content: "提取的原文", ... } }` |
|
|
101
|
+
| `client.chat({ payload, model?, img_url?, image_url?, image_urls? })` | `POST {chatBaseUrl}/api/chat` | `{ code: 0, msg, data: { result: "模型输出", ... } }` |
|
|
95
102
|
| `client.reportError({ error, source?, stage?, api?, context? })` | `POST https://report.imgkits.com` | Worker 原始 `{ success: true, data: { code: 0, ... } }` 或过滤响应 |
|
|
96
103
|
| `client.reduceFreeCnt({ cnt })` | `POST {baseUrl}/api/user/reduce-free-cnt` | `{ ok: 0, msg: "success" }` |
|
|
97
104
|
| `client.addMonthlyUsage({ cnt })` | `POST {baseUrl}/api/user/add-monthly-usage` | `{ ok: 0, msg: "success" }` |
|
|
@@ -104,9 +111,9 @@ function GenerateButton() {
|
|
|
104
111
|
|
|
105
112
|
Provider 自动注入自有后端请求 query 中的 `uid`、`platform_uid`、`platform=canva_addon`、`app_channel`、`timezone`,以及请求头 `Accept-Language`。时区每次请求通过 `Intl.DateTimeFormat().resolvedOptions().timeZone` 读取,如 `Asia/Taipei`;运行环境不支持时使用 `UTC`。浏览器请求不额外发送 `accept_language` 参数。
|
|
106
113
|
|
|
107
|
-
|
|
114
|
+
这些通用信息覆盖预测、文本审核、内容提取、大模型 `chat`、消费、上传签名和分片管理,以及原有登录、通行证、状态查询、版本配置和 `use` 消费请求。登录开始时不附带未知的用户 ID;拿到 Canva 用户 ID 后附带 `platform_uid`,拿到系统用户 ID 后再附带 `uid`,后续刷新和轮询读取最新语言与时区。调用方无需配置时区或在业务参数中重复填写通用字段。
|
|
108
115
|
|
|
109
|
-
|
|
116
|
+
预测、文本审核、内容提取和大模型 `chat` 还携带 `Authorization: Bearer <jwt>`、`Channel: ai`;具名消费接口使用 `X-Access-Ticket`、`X-Access-Channel`;签名接口使用 `Channel: node-nauth`。R2 PUT 原样使用签名 URL,只携带文件的 `Content-Type`;错误上报 Worker 使用独立协议,身份与渠道信息放在诊断消息中。创建请求中的 `user_id` 使用系统用户 ID(`userStatus.profile.id`)。公共审核只要求有效的业务 JWT;`uid` 和 `platform_uid` 在账户状态包含这些值时才附带,审核身份由后端验签确定。
|
|
110
117
|
|
|
111
118
|
当前创建接口支持普通的 `owner/name/input` 合同;视频 `schema_v2` 等高级参数后续接入。模型参数按 JSON 原样发送,不改写 prompt 或供应商。创建、查询和文本审核只发送一次请求,不自动轮询、重试、额外扣费或插入 Canva 设计。消费由应用显式调用具名方法。原有登录、额度和结账会话方法继续由同一个 hook 提供。
|
|
112
119
|
|
|
@@ -224,9 +231,9 @@ function FileUploadPanel() {
|
|
|
224
231
|
|
|
225
232
|
当前后端没有终止分片会话的接口,取消只停止客户端流程,已上传分片需由 bucket 的生命周期规则清理。[R2 官方文档](https://developers.cloudflare.com/r2/objects/upload-objects/) 说明默认会在 7 天后清理未完成会话,实际以当前 bucket 配置为准。
|
|
226
233
|
|
|
227
|
-
##
|
|
234
|
+
## 内容提取
|
|
228
235
|
|
|
229
|
-
`client.contentExtract({ type, url }, options?)`
|
|
236
|
+
`client.contentExtract({ type, url }, options?)` 从 `1.4.0` 提供,直接封装 `POST https://ai.imgkits.com/api/content-extract`,继续使用同一个 Provider 的用户 JWT 和通用参数。业务直接调用这个方法,无需再写只改名或转发参数的包装层。
|
|
230
237
|
|
|
231
238
|
| 输入 | type | url |
|
|
232
239
|
| --- | --- | --- |
|
|
@@ -282,6 +289,67 @@ const articleText = page.data.content;
|
|
|
282
289
|
|
|
283
290
|
第二个参数支持 `{ signal, timeoutMs }`,默认超时 `360_000` 毫秒(6 分钟,包含读取响应正文)。取消或超时只终止客户端等待,不能保证后端已停止提取。非法参数、HTTP 失败、后端 `code` 非 `0`、响应格式错误、网络错误、超时或取消沿用 `ApiError`;后端 `msg` 保留在 `error.message` / `error.userMessage`,应用应展示原始错误信息。
|
|
284
291
|
|
|
292
|
+
## 大模型 chat
|
|
293
|
+
|
|
294
|
+
`client.chat(params, options?)` 直接封装 `POST https://ai.imgkits.com/api/chat`,继续使用同一个 Provider。从 `2.0.0` 提供;`1.4.0` 不包含此方法。
|
|
295
|
+
|
|
296
|
+
```ts
|
|
297
|
+
const response = await client.chat({
|
|
298
|
+
payload: {
|
|
299
|
+
messages: [
|
|
300
|
+
{ role: "system", content: "你是文案助手,回答简洁清楚。" },
|
|
301
|
+
{ role: "user", content: "为一本旅行相册写三个封面标题。" },
|
|
302
|
+
],
|
|
303
|
+
temperature: 0.7,
|
|
304
|
+
max_tokens: 1000,
|
|
305
|
+
},
|
|
306
|
+
});
|
|
307
|
+
|
|
308
|
+
console.log(response.data.result);
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
| 参数 | 说明 |
|
|
312
|
+
| --- | --- |
|
|
313
|
+
| `payload.messages` | 必填 JSON 对象数组;文本对话使用 `system` / `user` / `assistant`,系统提示也放在这里 |
|
|
314
|
+
| `payload` 的其他字段 | JSON 模型参数,例如 `temperature`、`max_tokens`、`max_completion_tokens`、`response_format`;后端选取已支持字段,不保证任意 OpenAI 字段都生效 |
|
|
315
|
+
| `model?` | 可选字符串,SDK 原样传递且不填默认值;实际模型选择与回退由后端决定 |
|
|
316
|
+
| `img_url?` / `image_url?` / `image_urls?` | 图片地址简写,每个字段支持字符串或字符串数组;使用其中一种即可 |
|
|
317
|
+
|
|
318
|
+
消息的 `content` 支持字符串,也支持标准 `text` / `image_url` 多模态数组,例如 `[{ type: "text", text: "描述图片" }, { type: "image_url", image_url: { url: imageUrl } }]`。也可传图片简写与 `payload: { messages: [] }`,由后端补入用户消息。当前后端先尝试 Qwen,失败后可回退到 Replicate;填入 `model` 不保证指定模型一定被使用。
|
|
319
|
+
|
|
320
|
+
需要先提取内容再处理时,由业务显式组合两个方法:
|
|
321
|
+
|
|
322
|
+
```ts
|
|
323
|
+
const controller = new AbortController();
|
|
324
|
+
|
|
325
|
+
try {
|
|
326
|
+
const extracted = await client.contentExtract(
|
|
327
|
+
{ type: "link", url: "https://example.com/article" },
|
|
328
|
+
{ signal: controller.signal },
|
|
329
|
+
);
|
|
330
|
+
const response = await client.chat(
|
|
331
|
+
{
|
|
332
|
+
payload: {
|
|
333
|
+
messages: [
|
|
334
|
+
{ role: "system", content: "将用户提供的文章概括成三个要点。" },
|
|
335
|
+
{ role: "user", content: extracted.data.content },
|
|
336
|
+
],
|
|
337
|
+
},
|
|
338
|
+
},
|
|
339
|
+
{ signal: controller.signal, timeoutMs: 360_000 },
|
|
340
|
+
);
|
|
341
|
+
setSummary(response.data.result);
|
|
342
|
+
} catch (error) {
|
|
343
|
+
setError(error instanceof Error ? error.message : "内容处理失败");
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
// 取消按钮调用 controller.abort()。
|
|
347
|
+
```
|
|
348
|
+
|
|
349
|
+
接口一次同步返回原始 `{ code: 0, msg, data: { result, ... } }`,文本在 `data.result`,附加响应字段保留。SDK 不清洗、截断或自动解析 JSON;若业务请求 JSON 输出,由业务自行解析和校验。它不自动调用审核、消费、轮询或重试,也不接入 `/api/chat/create`、`/api/chat/result` 或流式接口。
|
|
350
|
+
|
|
351
|
+
默认超时 `360_000` 毫秒(6 分钟,包含读取响应正文),是客户端等待预算;后端模型回退可能花费更久,可通过第二参数的 `timeoutMs` 调整。`signal` 只取消客户端等待,不保证停止后端生成。失败沿用 `ApiError`,后端 `msg` 保留在 `error.message` / `error.userMessage`;上例直接展示该信息。内容提取与 chat 各自计算超时,共用取消信号。
|
|
352
|
+
|
|
285
353
|
## 文本审核
|
|
286
354
|
|
|
287
355
|
`client.textCheck` 封装后端的公共文本审核接口,复用现有 Provider,无需另外配置令牌。请求发送到用户 JWT 公共入口。
|
|
@@ -317,7 +385,7 @@ const prediction = await client.getPrediction(
|
|
|
317
385
|
);
|
|
318
386
|
```
|
|
319
387
|
|
|
320
|
-
取消只终止当前 HTTP 等待,不会取消已经创建的后端任务或撤销已提交的消费。创建、查询、文本审核和底层签名的默认请求超时为 60
|
|
388
|
+
取消只终止当前 HTTP 等待,不会取消已经创建的后端任务或撤销已提交的消费。创建、查询、文本审核和底层签名的默认请求超时为 60 秒,包含读取响应正文的时间;内容提取和大模型 `chat` 为 360 秒,消费为 30 秒,单次 PUT 上传为 120 秒,分片上传整体为 30 分钟。
|
|
321
389
|
|
|
322
390
|
## 错误上报
|
|
323
391
|
|
package/dist/api/chat.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { ApiError } from "./error.js";
|
|
2
|
+
import { isObject, invalid, isNonemptyString, validateJson, postApi } from "./request.js";
|
|
3
|
+
function createChatApi(getContext) {
|
|
4
|
+
return {
|
|
5
|
+
async chat(params, options) {
|
|
6
|
+
if (!isObject(params) || !isObject(params.payload) || !Array.isArray(params.payload.messages) || ![...params.payload.messages].every(isObject)) {
|
|
7
|
+
invalid("chat requires a payload object with a messages array of objects.");
|
|
8
|
+
}
|
|
9
|
+
if (Object.keys(params).some((key) => !["model", "payload", "img_url", "image_url", "image_urls"].includes(key))) {
|
|
10
|
+
invalid("chat supports model, payload, img_url, image_url and image_urls only.");
|
|
11
|
+
}
|
|
12
|
+
if (params.model !== void 0 && !isNonemptyString(params.model)) {
|
|
13
|
+
invalid("model must be a nonempty string when provided.");
|
|
14
|
+
}
|
|
15
|
+
const body = { payload: params.payload };
|
|
16
|
+
if (params.model !== void 0) body.model = params.model;
|
|
17
|
+
for (const key of ["img_url", "image_url", "image_urls"]) {
|
|
18
|
+
const value = params[key];
|
|
19
|
+
if (value !== void 0 && typeof value !== "string" && !(Array.isArray(value) && [...value].every((item) => typeof item === "string"))) {
|
|
20
|
+
invalid(`${key} must be a string or an array of strings.`);
|
|
21
|
+
}
|
|
22
|
+
if (value !== void 0) body[key] = value;
|
|
23
|
+
}
|
|
24
|
+
validateJson(body);
|
|
25
|
+
const response = await postApi(getContext(), "chat", body, {
|
|
26
|
+
...options,
|
|
27
|
+
timeoutMs: (options == null ? void 0 : options.timeoutMs) ?? 36e4
|
|
28
|
+
});
|
|
29
|
+
if (!isObject(response.data) || typeof response.data.result !== "string") {
|
|
30
|
+
throw new ApiError("Backend returned an invalid chat result.", "invalid_response");
|
|
31
|
+
}
|
|
32
|
+
return response;
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
export {
|
|
37
|
+
createChatApi
|
|
38
|
+
};
|
package/dist/api/request.js
CHANGED
|
@@ -4,7 +4,8 @@ const apiPaths = {
|
|
|
4
4
|
createSpecifyPrediction: "/replicate/createSpecifyPrediction",
|
|
5
5
|
getPrediction: "/replicate/getPrediction",
|
|
6
6
|
textCheck: "/api/public/text-moderation/check",
|
|
7
|
-
contentExtract: "/api/content-extract"
|
|
7
|
+
contentExtract: "/api/content-extract",
|
|
8
|
+
chat: "/api/chat"
|
|
8
9
|
};
|
|
9
10
|
function isObject(value) {
|
|
10
11
|
return value !== null && typeof value === "object" && !Array.isArray(value);
|
package/dist/login/context.js
CHANGED
|
@@ -42,6 +42,9 @@ const YiChongCanvaContext = React.createContext(
|
|
|
42
42
|
contentExtract: async () => {
|
|
43
43
|
throw new ApiError("Wrap your components in YiChongCanvaProvider first.", "provider_missing");
|
|
44
44
|
},
|
|
45
|
+
chat: async () => {
|
|
46
|
+
throw new ApiError("Wrap your components in YiChongCanvaProvider first.", "provider_missing");
|
|
47
|
+
},
|
|
45
48
|
reportError: async () => {
|
|
46
49
|
throw new ApiError("Wrap your components in YiChongCanvaProvider first.", "provider_missing");
|
|
47
50
|
},
|
package/dist/login/privider.js
CHANGED
|
@@ -7,6 +7,7 @@ import { getAppVersion } from "./version.js";
|
|
|
7
7
|
import { createPredictionApi } from "../api/predictions.js";
|
|
8
8
|
import { createTextModerationApi } from "../api/moderation.js";
|
|
9
9
|
import { createContentExtractionApi } from "../api/content.js";
|
|
10
|
+
import { createChatApi } from "../api/chat.js";
|
|
10
11
|
import { createUsageApi } from "../api/usage.js";
|
|
11
12
|
import { createUploadApi } from "../api/uploads.js";
|
|
12
13
|
import { createErrorReportingApi } from "../api/reporting.js";
|
|
@@ -55,6 +56,7 @@ const YiChongCanvaProvider = ({
|
|
|
55
56
|
baseUrl,
|
|
56
57
|
apiBaseUrl = "https://api.imgkits.com",
|
|
57
58
|
contentBaseUrl = "https://ai.imgkits.com",
|
|
59
|
+
chatBaseUrl = "https://ai.imgkits.com",
|
|
58
60
|
uploadBaseUrl = "https://ai.imgkits.com",
|
|
59
61
|
getLocale,
|
|
60
62
|
autoLogin = true,
|
|
@@ -75,8 +77,8 @@ const YiChongCanvaProvider = ({
|
|
|
75
77
|
const sessionStopRef = useRef(null);
|
|
76
78
|
const [loginStatus, setLoginStatus] = useState("idle");
|
|
77
79
|
const userStatusRef = useRef({});
|
|
78
|
-
const apiConfigRef = useRef({ apiBaseUrl, contentBaseUrl, baseUrl, uploadBaseUrl, productName, appId, version, getLocale });
|
|
79
|
-
apiConfigRef.current = { apiBaseUrl, contentBaseUrl, baseUrl, uploadBaseUrl, productName, appId, version, getLocale };
|
|
80
|
+
const apiConfigRef = useRef({ apiBaseUrl, contentBaseUrl, chatBaseUrl, baseUrl, uploadBaseUrl, productName, appId, version, getLocale });
|
|
81
|
+
apiConfigRef.current = { apiBaseUrl, contentBaseUrl, chatBaseUrl, baseUrl, uploadBaseUrl, productName, appId, version, getLocale };
|
|
80
82
|
const passportRef = useRef(null);
|
|
81
83
|
const onPassport = (passport, userId, uid) => {
|
|
82
84
|
passportRef.current = { passport, userId, uid, productName };
|
|
@@ -91,6 +93,10 @@ const YiChongCanvaProvider = ({
|
|
|
91
93
|
...getApiContext(),
|
|
92
94
|
apiBaseUrl: apiConfigRef.current.contentBaseUrl
|
|
93
95
|
})));
|
|
96
|
+
const [chatApi] = useState(() => createChatApi(() => ({
|
|
97
|
+
...getApiContext(),
|
|
98
|
+
apiBaseUrl: apiConfigRef.current.chatBaseUrl
|
|
99
|
+
})));
|
|
94
100
|
const [usageApi] = useState(() => createUsageApi(() => {
|
|
95
101
|
var _a;
|
|
96
102
|
const context = getApiContext();
|
|
@@ -611,6 +617,7 @@ const YiChongCanvaProvider = ({
|
|
|
611
617
|
...predictionApi,
|
|
612
618
|
...textModerationApi,
|
|
613
619
|
...contentExtractionApi,
|
|
620
|
+
...chatApi,
|
|
614
621
|
...usageApi,
|
|
615
622
|
...uploadApi,
|
|
616
623
|
...errorReportingApi,
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { ApiError } from './error';
|
|
2
|
-
export type { ApiRequestOptions, ApiResponse, CompleteUploadParams, CompleteUploadResponse, ContentExtractParams, ContentExtractResult, ContentExtractionApi, TextCheckParams, CreateSpecifyPredictionParams, ErrorReportingApi, ErrorReportSource, GetPredictionParams, GeneratePresignedUrlParams, GetUploadUrlParams, InitiateUploadParams, InitiateUploadResponse, JsonObject, JsonValue, Prediction, PredictionApi, ReportErrorParams, ReportErrorResult, PresignedUrlResponse, TextModerationApi, TextModerationCategory, TextModerationDecision, TextModerationResult, UploadApi, UploadFileParams, UploadFileResult, UploadedPart, UploadPartUrlResponse, UsageApi, UsageParams, UsageResponse, } from './types';
|
|
2
|
+
export type { ApiRequestOptions, ApiResponse, ChatApi, ChatParams, ChatPayload, ChatResult, CompleteUploadParams, CompleteUploadResponse, ContentExtractParams, ContentExtractResult, ContentExtractionApi, TextCheckParams, CreateSpecifyPredictionParams, ErrorReportingApi, ErrorReportSource, GetPredictionParams, GeneratePresignedUrlParams, GetUploadUrlParams, InitiateUploadParams, InitiateUploadResponse, JsonObject, JsonValue, Prediction, PredictionApi, ReportErrorParams, ReportErrorResult, PresignedUrlResponse, TextModerationApi, TextModerationCategory, TextModerationDecision, TextModerationResult, UploadApi, UploadFileParams, UploadFileResult, UploadedPart, UploadPartUrlResponse, UsageApi, UsageParams, UsageResponse, } from './types';
|
|
@@ -15,6 +15,7 @@ declare const apiPaths: {
|
|
|
15
15
|
readonly getPrediction: "/replicate/getPrediction";
|
|
16
16
|
readonly textCheck: "/api/public/text-moderation/check";
|
|
17
17
|
readonly contentExtract: "/api/content-extract";
|
|
18
|
+
readonly chat: "/api/chat";
|
|
18
19
|
};
|
|
19
20
|
export declare function isObject(value: unknown): value is Record<string, unknown>;
|
|
20
21
|
export declare function isNonemptyString(value: unknown): value is string;
|
|
@@ -22,6 +22,24 @@ export interface ContentExtractResult {
|
|
|
22
22
|
content: string;
|
|
23
23
|
[key: string]: unknown;
|
|
24
24
|
}
|
|
25
|
+
/** 保留后端 payload 结构;消息语义和模型参数支持范围由后端验证。 */
|
|
26
|
+
export type ChatPayload = JsonObject & {
|
|
27
|
+
messages: JsonObject[];
|
|
28
|
+
};
|
|
29
|
+
export interface ChatParams {
|
|
30
|
+
payload: ChatPayload;
|
|
31
|
+
/** 原样传递;实际模型选择与回退由后端决定,SDK 不填默认模型。 */
|
|
32
|
+
model?: string;
|
|
33
|
+
/** 图片简写;也可直接在 messages 中使用多模态内容。 */
|
|
34
|
+
img_url?: string | string[];
|
|
35
|
+
image_url?: string | string[];
|
|
36
|
+
image_urls?: string | string[];
|
|
37
|
+
}
|
|
38
|
+
export interface ChatResult {
|
|
39
|
+
/** 后端返回的完整文本;不在客户端解析 JSON 或改写内容。 */
|
|
40
|
+
result: string;
|
|
41
|
+
[key: string]: unknown;
|
|
42
|
+
}
|
|
25
43
|
export interface TextCheckParams {
|
|
26
44
|
/** 完整原文;最多 1024 个 Unicode 字符且最多 1024 个 UTF-8 字节。 */
|
|
27
45
|
text: string;
|
|
@@ -84,6 +102,10 @@ export interface ContentExtractionApi {
|
|
|
84
102
|
/** 单次等待最终内容,默认超时 360000 毫秒;不轮询、重试、扣费或总结。 */
|
|
85
103
|
contentExtract(params: ContentExtractParams, options?: ApiRequestOptions): Promise<ApiResponse<ContentExtractResult>>;
|
|
86
104
|
}
|
|
105
|
+
export interface ChatApi {
|
|
106
|
+
/** 同步等待完整回复;默认等待 360000 毫秒,不自动轮询、重试或扣费。 */
|
|
107
|
+
chat(params: ChatParams, options?: ApiRequestOptions): Promise<ApiResponse<ChatResult>>;
|
|
108
|
+
}
|
|
87
109
|
export type ErrorReportSource = "ui" | "api" | "runtime" | "promise" | "react" | "upload" | "host_sdk";
|
|
88
110
|
export interface ReportErrorParams {
|
|
89
111
|
/** Error、ApiError、字符串或其他错误值;工具包只提取诊断字段,脱敏并限制长度。 */
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { default as React } from 'react';
|
|
2
|
-
import { ContentExtractionApi, ErrorReportingApi, PredictionApi, TextModerationApi, UploadApi, UsageApi } from '../api/types';
|
|
2
|
+
import { ChatApi, ContentExtractionApi, ErrorReportingApi, PredictionApi, TextModerationApi, UploadApi, UsageApi } from '../api/types';
|
|
3
3
|
import { canUseError, CheckoutSessionOptions, TestMode, UserStatus } from './interface';
|
|
4
4
|
/**
|
|
5
5
|
*
|
|
@@ -17,7 +17,7 @@ import { canUseError, CheckoutSessionOptions, TestMode, UserStatus } from './int
|
|
|
17
17
|
* @property {() => string} getPricingLink 获取付费链接
|
|
18
18
|
* @property {() => void} updateTestMode 更新测试模式, 只有在开发环境下有效
|
|
19
19
|
*/
|
|
20
|
-
export interface YiChongCanvaContextType extends PredictionApi, TextModerationApi, ContentExtractionApi, UsageApi, UploadApi, ErrorReportingApi {
|
|
20
|
+
export interface YiChongCanvaContextType extends PredictionApi, TextModerationApi, ContentExtractionApi, ChatApi, UsageApi, UploadApi, ErrorReportingApi {
|
|
21
21
|
userStatus: UserStatus;
|
|
22
22
|
updateUserStatus: (user: Partial<UserStatus>) => void;
|
|
23
23
|
handleLogin: () => void;
|
|
@@ -20,6 +20,8 @@ export interface YiChongCanvaProviderProps {
|
|
|
20
20
|
apiBaseUrl?: string;
|
|
21
21
|
/** 内容提取服务根地址,默认 https://ai.imgkits.com。 */
|
|
22
22
|
contentBaseUrl?: string;
|
|
23
|
+
/** 大模型 Chat 服务根地址,默认 https://ai.imgkits.com。 */
|
|
24
|
+
chatBaseUrl?: string;
|
|
23
25
|
/** R2 签名服务根地址,默认 https://ai.imgkits.com。 */
|
|
24
26
|
uploadBaseUrl?: string;
|
|
25
27
|
/** 每次 API 请求读取当前界面语言,默认使用浏览器语言。 */
|
|
@@ -43,4 +45,4 @@ export interface YiChongCanvaProviderProps {
|
|
|
43
45
|
* @param {string} params0.mode 测试模式
|
|
44
46
|
* @returns
|
|
45
47
|
*/
|
|
46
|
-
export declare const YiChongCanvaProvider: ({ children, appId, productName, onUpdateUserStatus, baseUrl, apiBaseUrl, contentBaseUrl, uploadBaseUrl, getLocale, autoLogin, testMode: _testMode, version, mode, retry, maxAvailablePoints, }: YiChongCanvaProviderProps) => React.JSX.Element;
|
|
48
|
+
export declare const YiChongCanvaProvider: ({ children, appId, productName, onUpdateUserStatus, baseUrl, apiBaseUrl, contentBaseUrl, chatBaseUrl, uploadBaseUrl, getLocale, autoLogin, testMode: _testMode, version, mode, retry, maxAvailablePoints, }: YiChongCanvaProviderProps) => React.JSX.Element;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "yichong-canva2",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -24,8 +24,8 @@
|
|
|
24
24
|
},
|
|
25
25
|
"peerDependencies": {
|
|
26
26
|
"@canva/user": ">=2.1.0",
|
|
27
|
-
"react": "
|
|
28
|
-
"react-dom": "
|
|
27
|
+
"react": "^19.0.0",
|
|
28
|
+
"react-dom": "^19.0.0"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"lodash": "^4.17.21"
|
|
@@ -42,9 +42,9 @@
|
|
|
42
42
|
"eslint-plugin-react-hooks": "^5.1.0",
|
|
43
43
|
"eslint-plugin-react-refresh": "^0.4.19",
|
|
44
44
|
"globals": "^15.15.0",
|
|
45
|
-
"react": "
|
|
46
|
-
"react-dom": "
|
|
47
|
-
"react-test-renderer": "
|
|
45
|
+
"react": "19.3.0",
|
|
46
|
+
"react-dom": "19.3.0",
|
|
47
|
+
"react-test-renderer": "19.3.0",
|
|
48
48
|
"rollup-plugin-terser": "^7.0.2",
|
|
49
49
|
"typescript": "~5.7.3",
|
|
50
50
|
"typescript-eslint": "^8.24.1",
|