@tansr/protocol 0.2.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/LICENSE +21 -0
- package/README.md +74 -0
- package/dist/canonical/common.d.ts +37 -0
- package/dist/canonical/common.js +149 -0
- package/dist/canonical/digest.d.ts +12 -0
- package/dist/canonical/digest.js +58 -0
- package/dist/canonical/encode.d.ts +15 -0
- package/dist/canonical/encode.js +157 -0
- package/dist/canonical/errors.d.ts +81 -0
- package/dist/canonical/errors.js +89 -0
- package/dist/canonical/index.d.ts +21 -0
- package/dist/canonical/index.js +21 -0
- package/dist/canonical/parse.d.ts +21 -0
- package/dist/canonical/parse.js +295 -0
- package/dist/client.d.ts +42 -0
- package/dist/client.js +1 -0
- package/dist/config.d.ts +4990 -0
- package/dist/config.js +657 -0
- package/dist/daemon.d.ts +70 -0
- package/dist/daemon.js +48 -0
- package/dist/events.d.ts +2152 -0
- package/dist/events.js +625 -0
- package/dist/governance.d.ts +445 -0
- package/dist/governance.js +183 -0
- package/dist/headless.d.ts +97 -0
- package/dist/headless.js +39 -0
- package/dist/identity.d.ts +96 -0
- package/dist/identity.js +45 -0
- package/dist/index.d.ts +525 -0
- package/dist/index.js +529 -0
- package/dist/ir.d.ts +1418 -0
- package/dist/ir.js +283 -0
- package/dist/journal.d.ts +297 -0
- package/dist/journal.js +150 -0
- package/dist/media.d.ts +563 -0
- package/dist/media.js +190 -0
- package/dist/metering.d.ts +225 -0
- package/dist/metering.js +90 -0
- package/dist/orchestration.d.ts +1551 -0
- package/dist/orchestration.js +333 -0
- package/dist/redact-patterns.d.ts +49 -0
- package/dist/redact-patterns.js +141 -0
- package/dist/storage.d.ts +507 -0
- package/dist/storage.js +110 -0
- package/dist/tool-result-artifact.d.ts +257 -0
- package/dist/tool-result-artifact.js +263 -0
- package/package.json +30 -0
package/dist/media.d.ts
ADDED
|
@@ -0,0 +1,563 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 媒体产物形与授权模型描述子(媒体能力内核化 doc/128 §3.1,K-1;加法模块,不占 contract 号)。
|
|
3
|
+
*
|
|
4
|
+
* 本模块是四个媒体工具(ImageGen / VideoGen / SpeechToText / TextToSpeech)`ToolResult.data`
|
|
5
|
+
* 形状的**单源**——此前四形各自散落在 sdk 环3 工具文件(`ImageGenData` / `VideoGenData` /
|
|
6
|
+
* `TranscriptData` / `SpeechData`),sdk 侧改为本模块的类型别名与 re-export(D-M5:形状逐字
|
|
7
|
+
* 不变、不加判别键)。三类内容:
|
|
8
|
+
*
|
|
9
|
+
* - 授权模型描述子 `MediaModelDescriptor<C>` 与四约束型(逐字迁自 sdk `platform/bundle.ts`;
|
|
10
|
+
* sdk `AppBundleXxxModel` / `XxxConstraints` 改为本类型别名)——工具描述装配的入参形;
|
|
11
|
+
* - 四产物 schema(zod `.passthrough()` 容未知键——端侧/旧消费方对加法键零破坏)与同名接口;
|
|
12
|
+
* - `parseMediaArtifact()`:doc/123 §3.7「端侧形状规则」的 **TS 参考实现**——Android
|
|
13
|
+
* `ToolCardArtifact.kt` / iOS `ToolCardArtifact.swift` 按形状(不按工具名)识别产物的三端
|
|
14
|
+
* 对表基准(doc/128 D-M5 / D-M10 / A-12)。
|
|
15
|
+
*
|
|
16
|
+
* 契约面(D-M11):不新 KernelEvent、不新 IR 块、`tool.completed.data` 仍 `unknown`、
|
|
17
|
+
* `kernel-event.schema.json` 零 diff;本模块不入 JSON Schema 导出集(产物形随事件 data 位出线,
|
|
18
|
+
* 消费方按形状识别,无独立书写/生成方)。
|
|
19
|
+
*/
|
|
20
|
+
import { z } from 'zod';
|
|
21
|
+
/**
|
|
22
|
+
* 产出托管地(S-ARCH P2-c 加法键 2026-09-02;平台媒体探针按产出 URL 宿主定性):
|
|
23
|
+
* overseas = 境外托管(中国大陆网络可能无法直接访问)/ domestic / inline(b64 内联返回,
|
|
24
|
+
* 无托管地问题)。缺席 = 未探/未识别。工具描述据此逐模型前置告知。
|
|
25
|
+
*/
|
|
26
|
+
export type MediaOutputHosting = 'domestic' | 'overseas' | 'inline';
|
|
27
|
+
/**
|
|
28
|
+
* 授权媒体模型描述子(S-G1 媒体池化顺位取用):`model` = canonical handle(工具/网关
|
|
29
|
+
* `model` 位可直用);`displayName` 异名时描述行附注;`constraints` 按面特化(下方四型),
|
|
30
|
+
* 缺席 = 受理面未实录(描述恒不臆造);序 = 平台收敛稳定序,**顺位第一即 `model` 缺省时
|
|
31
|
+
* 的生效模型**。恒不携价格/成本/供应商内部信息。
|
|
32
|
+
*/
|
|
33
|
+
export interface MediaModelDescriptor<C> {
|
|
34
|
+
model: string;
|
|
35
|
+
displayName: string;
|
|
36
|
+
constraints?: C;
|
|
37
|
+
outputHosting?: MediaOutputHosting;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* 图像模型受理约束(bundle platformModels.imageGen 行 constraints 加法键,2026-09-01;
|
|
41
|
+
* 网关侧单源 = /t1 运行时校验档同一 classify 词表)。工具描述逐模型拼注——智能体首发即中,
|
|
42
|
+
* 不再靠拒收错误试错。
|
|
43
|
+
*/
|
|
44
|
+
export interface ImageModelConstraints {
|
|
45
|
+
/** false = 模型定档分辨率,size 在场即拒。 */
|
|
46
|
+
size: boolean;
|
|
47
|
+
seed: boolean;
|
|
48
|
+
negativePrompt: boolean;
|
|
49
|
+
/** 单请求张数帽(n 超帽由网关钳)。 */
|
|
50
|
+
maxImages: number;
|
|
51
|
+
/** 富输入 imageUrls 受理域(null = 纯文生行,在场即拒)。 */
|
|
52
|
+
imageInput: {
|
|
53
|
+
min: number;
|
|
54
|
+
max: number;
|
|
55
|
+
urlOk: boolean;
|
|
56
|
+
b64Ok: boolean;
|
|
57
|
+
} | null;
|
|
58
|
+
/** false = 动词行(引用既有任务),prompt 在场即拒。 */
|
|
59
|
+
promptRequired: boolean;
|
|
60
|
+
/** 动词行必携 action{taskId,actionId}。 */
|
|
61
|
+
actionRequired?: boolean;
|
|
62
|
+
}
|
|
63
|
+
/** 视频模型受理约束(同上镜像;时长域/首帧受理/比例域是实测三大拒收源)。 */
|
|
64
|
+
export interface VideoModelConstraints {
|
|
65
|
+
durations: {
|
|
66
|
+
kind: 'set';
|
|
67
|
+
values: number[];
|
|
68
|
+
defaultSec: number;
|
|
69
|
+
} | {
|
|
70
|
+
kind: 'range';
|
|
71
|
+
min: number;
|
|
72
|
+
max: number;
|
|
73
|
+
defaultSec: number;
|
|
74
|
+
};
|
|
75
|
+
/** 比例词形域(null = ratio 在场即拒;键缺席 = 透传上游,域未实录)。 */
|
|
76
|
+
ratio?: string[] | null;
|
|
77
|
+
negativePrompt: boolean;
|
|
78
|
+
seed: boolean;
|
|
79
|
+
/** 首帧图受理域(required = i2v 专用行必携 imageUrls;null = 纯文生行在场即拒)。 */
|
|
80
|
+
imageInput: {
|
|
81
|
+
required: boolean;
|
|
82
|
+
max: number;
|
|
83
|
+
urlOk: boolean;
|
|
84
|
+
b64Ok: boolean;
|
|
85
|
+
} | null;
|
|
86
|
+
audioInput: boolean;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* ASR(语音转文字)模型受理约束(doc/123 §3.4 / §二「音频面档」):受理格式 / 时长帽 /
|
|
90
|
+
* 语种 / 说话人分离——`diarize:true` 点名不受理家族恒 400 可解释,前置进描述免试错。
|
|
91
|
+
*/
|
|
92
|
+
export interface AudioAsrConstraints {
|
|
93
|
+
/** 受理音频格式(如 wav/mp3/m4a;data URI mime 与之对应) */
|
|
94
|
+
formats: string[];
|
|
95
|
+
/** 单文件时长帽(秒;超帽 bad_request) */
|
|
96
|
+
maxSeconds: number;
|
|
97
|
+
/** 提示语种域(缺席 = 未实录,language 位透传上游) */
|
|
98
|
+
languages?: string[];
|
|
99
|
+
/** 说话人分离受理(false 时 diarize 在场即拒) */
|
|
100
|
+
diarization: boolean;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* TTS(文字转语音)模型受理约束(doc/123 §3.4):音色表(voice 缺席 = defaultVoice;非表内
|
|
104
|
+
* 音色 400 列出可选)/ 受理格式(家族不受理的格式按面档回落,如 dashscope 恒 wav)/ 字数帽。
|
|
105
|
+
*/
|
|
106
|
+
/** 验证语音模型的原子输入上限及其计数单位,独立于加权字符预算。 */
|
|
107
|
+
export declare const AudioTtsInputLimitSchema: z.ZodObject<{
|
|
108
|
+
max: z.ZodNumber;
|
|
109
|
+
unit: z.ZodEnum<["unicode_code_points", "utf16_code_units", "utf8_bytes"]>;
|
|
110
|
+
}, "strict", z.ZodTypeAny, {
|
|
111
|
+
max: number;
|
|
112
|
+
unit: "unicode_code_points" | "utf16_code_units" | "utf8_bytes";
|
|
113
|
+
}, {
|
|
114
|
+
max: number;
|
|
115
|
+
unit: "unicode_code_points" | "utf16_code_units" | "utf8_bytes";
|
|
116
|
+
}>;
|
|
117
|
+
/** 语音模型的可用音色、格式、加权字符预算及原子输入上限。 */
|
|
118
|
+
export interface AudioTtsConstraints {
|
|
119
|
+
voices: Array<{
|
|
120
|
+
id: string;
|
|
121
|
+
label: string;
|
|
122
|
+
lang?: string;
|
|
123
|
+
}>;
|
|
124
|
+
defaultVoice: string;
|
|
125
|
+
formats: string[];
|
|
126
|
+
maxChars: number;
|
|
127
|
+
/** 已确认单位的原子输入帽;缺席未知,在场坏形不可丢弃后放行。 */
|
|
128
|
+
inputLimit?: z.infer<typeof AudioTtsInputLimitSchema>;
|
|
129
|
+
}
|
|
130
|
+
/** 图片模型目录条目:通用描述符 + 图片受理约束。 */
|
|
131
|
+
export type ImageModelDescriptor = MediaModelDescriptor<ImageModelConstraints>;
|
|
132
|
+
/** 视频模型目录条目:通用描述符 + 视频受理约束。 */
|
|
133
|
+
export type VideoModelDescriptor = MediaModelDescriptor<VideoModelConstraints>;
|
|
134
|
+
/** 语音转文字模型目录条目:通用描述符 + ASR 受理约束。 */
|
|
135
|
+
export type SpeechToTextModelDescriptor = MediaModelDescriptor<AudioAsrConstraints>;
|
|
136
|
+
/** 文字转语音模型目录条目:通用描述符 + TTS 受理约束。 */
|
|
137
|
+
export type TextToSpeechModelDescriptor = MediaModelDescriptor<AudioTtsConstraints>;
|
|
138
|
+
/**
|
|
139
|
+
* ImageGen 产物(表面层渲染用结构化数据;错误时携错误码、`images` 为空数组、`imageCount` 0)。
|
|
140
|
+
* 端侧按形状识别:`images` 数组 → Images 型产物。
|
|
141
|
+
*/
|
|
142
|
+
export interface ImageGenData {
|
|
143
|
+
model: string;
|
|
144
|
+
images: Array<{
|
|
145
|
+
url: string;
|
|
146
|
+
}>;
|
|
147
|
+
imageCount: number;
|
|
148
|
+
/** 错误码(如 forbidden / imagegen_not_configured / model_not_authorized;成功缺席)。 */
|
|
149
|
+
errorCode?: string;
|
|
150
|
+
/**
|
|
151
|
+
* 异步任务号(平台任务径在场时恒携)。预算耗尽/中断时凭此找回产出:
|
|
152
|
+
* GET /t1/imagegen/tasks/{taskId}(服务端照跑照扣,7 天可查)。同步回落径 / BYO 径缺席。
|
|
153
|
+
*/
|
|
154
|
+
taskId?: string;
|
|
155
|
+
}
|
|
156
|
+
/** ImageGenData 的 zod schema(passthrough 容未知键;消费方按需校验 ToolResult.data)。 */
|
|
157
|
+
export declare const ImageGenDataSchema: z.ZodObject<{
|
|
158
|
+
model: z.ZodString;
|
|
159
|
+
images: z.ZodArray<z.ZodObject<{
|
|
160
|
+
url: z.ZodString;
|
|
161
|
+
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
|
162
|
+
url: z.ZodString;
|
|
163
|
+
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
164
|
+
url: z.ZodString;
|
|
165
|
+
}, z.ZodTypeAny, "passthrough">>, "many">;
|
|
166
|
+
imageCount: z.ZodNumber;
|
|
167
|
+
errorCode: z.ZodOptional<z.ZodString>;
|
|
168
|
+
taskId: z.ZodOptional<z.ZodString>;
|
|
169
|
+
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
|
170
|
+
model: z.ZodString;
|
|
171
|
+
images: z.ZodArray<z.ZodObject<{
|
|
172
|
+
url: z.ZodString;
|
|
173
|
+
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
|
174
|
+
url: z.ZodString;
|
|
175
|
+
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
176
|
+
url: z.ZodString;
|
|
177
|
+
}, z.ZodTypeAny, "passthrough">>, "many">;
|
|
178
|
+
imageCount: z.ZodNumber;
|
|
179
|
+
errorCode: z.ZodOptional<z.ZodString>;
|
|
180
|
+
taskId: z.ZodOptional<z.ZodString>;
|
|
181
|
+
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
182
|
+
model: z.ZodString;
|
|
183
|
+
images: z.ZodArray<z.ZodObject<{
|
|
184
|
+
url: z.ZodString;
|
|
185
|
+
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
|
186
|
+
url: z.ZodString;
|
|
187
|
+
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
188
|
+
url: z.ZodString;
|
|
189
|
+
}, z.ZodTypeAny, "passthrough">>, "many">;
|
|
190
|
+
imageCount: z.ZodNumber;
|
|
191
|
+
errorCode: z.ZodOptional<z.ZodString>;
|
|
192
|
+
taskId: z.ZodOptional<z.ZodString>;
|
|
193
|
+
}, z.ZodTypeAny, "passthrough">>;
|
|
194
|
+
/**
|
|
195
|
+
* VideoGen 产物(错误时携错误码、`videos` 为空数组、`videoCount` / `billedSeconds` 0)。
|
|
196
|
+
* 端侧按形状识别:`videos` 数组 → Videos 型产物。
|
|
197
|
+
*/
|
|
198
|
+
export interface VideoGenData {
|
|
199
|
+
model: string;
|
|
200
|
+
videos: Array<{
|
|
201
|
+
url: string;
|
|
202
|
+
}>;
|
|
203
|
+
videoCount: number;
|
|
204
|
+
/** 计费秒数(= 上游成功报量;错误时 0)。 */
|
|
205
|
+
billedSeconds: number;
|
|
206
|
+
/** 错误码(如 forbidden / videogen_not_configured / model_not_authorized;成功缺席)。 */
|
|
207
|
+
errorCode?: string;
|
|
208
|
+
/** 异步任务号(平台任务径在场时恒携;GET /t1/videogen/tasks/{taskId} 可找回)。 */
|
|
209
|
+
taskId?: string;
|
|
210
|
+
}
|
|
211
|
+
/** VideoGenData 的 zod schema(passthrough 容未知键)。 */
|
|
212
|
+
export declare const VideoGenDataSchema: z.ZodObject<{
|
|
213
|
+
model: z.ZodString;
|
|
214
|
+
videos: z.ZodArray<z.ZodObject<{
|
|
215
|
+
url: z.ZodString;
|
|
216
|
+
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
|
217
|
+
url: z.ZodString;
|
|
218
|
+
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
219
|
+
url: z.ZodString;
|
|
220
|
+
}, z.ZodTypeAny, "passthrough">>, "many">;
|
|
221
|
+
videoCount: z.ZodNumber;
|
|
222
|
+
billedSeconds: z.ZodNumber;
|
|
223
|
+
errorCode: z.ZodOptional<z.ZodString>;
|
|
224
|
+
taskId: z.ZodOptional<z.ZodString>;
|
|
225
|
+
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
|
226
|
+
model: z.ZodString;
|
|
227
|
+
videos: z.ZodArray<z.ZodObject<{
|
|
228
|
+
url: z.ZodString;
|
|
229
|
+
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
|
230
|
+
url: z.ZodString;
|
|
231
|
+
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
232
|
+
url: z.ZodString;
|
|
233
|
+
}, z.ZodTypeAny, "passthrough">>, "many">;
|
|
234
|
+
videoCount: z.ZodNumber;
|
|
235
|
+
billedSeconds: z.ZodNumber;
|
|
236
|
+
errorCode: z.ZodOptional<z.ZodString>;
|
|
237
|
+
taskId: z.ZodOptional<z.ZodString>;
|
|
238
|
+
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
239
|
+
model: z.ZodString;
|
|
240
|
+
videos: z.ZodArray<z.ZodObject<{
|
|
241
|
+
url: z.ZodString;
|
|
242
|
+
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
|
243
|
+
url: z.ZodString;
|
|
244
|
+
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
245
|
+
url: z.ZodString;
|
|
246
|
+
}, z.ZodTypeAny, "passthrough">>, "many">;
|
|
247
|
+
videoCount: z.ZodNumber;
|
|
248
|
+
billedSeconds: z.ZodNumber;
|
|
249
|
+
errorCode: z.ZodOptional<z.ZodString>;
|
|
250
|
+
taskId: z.ZodOptional<z.ZodString>;
|
|
251
|
+
}, z.ZodTypeAny, "passthrough">>;
|
|
252
|
+
/** 转写分段(speaker 仅说话人分离家族在场) */
|
|
253
|
+
export interface TranscriptSegment {
|
|
254
|
+
start: number;
|
|
255
|
+
end: number;
|
|
256
|
+
text: string;
|
|
257
|
+
speaker?: string;
|
|
258
|
+
}
|
|
259
|
+
/** TranscriptSegment 的 zod schema(passthrough 容未知键)。 */
|
|
260
|
+
export declare const TranscriptSegmentSchema: z.ZodObject<{
|
|
261
|
+
start: z.ZodNumber;
|
|
262
|
+
end: z.ZodNumber;
|
|
263
|
+
text: z.ZodString;
|
|
264
|
+
speaker: z.ZodOptional<z.ZodString>;
|
|
265
|
+
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
|
266
|
+
start: z.ZodNumber;
|
|
267
|
+
end: z.ZodNumber;
|
|
268
|
+
text: z.ZodString;
|
|
269
|
+
speaker: z.ZodOptional<z.ZodString>;
|
|
270
|
+
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
271
|
+
start: z.ZodNumber;
|
|
272
|
+
end: z.ZodNumber;
|
|
273
|
+
text: z.ZodString;
|
|
274
|
+
speaker: z.ZodOptional<z.ZodString>;
|
|
275
|
+
}, z.ZodTypeAny, "passthrough">>;
|
|
276
|
+
/**
|
|
277
|
+
* SpeechToText 产物(错误时携错误码、`text` 为空串)。端侧按形状
|
|
278
|
+
* 识别:`text` + `model` 且无 images/videos/results/audio → Transcript 型产物。
|
|
279
|
+
* 空串 `text` 本身是合法转写(静音输入),不是零产物。
|
|
280
|
+
*/
|
|
281
|
+
export interface TranscriptData {
|
|
282
|
+
model: string;
|
|
283
|
+
text: string;
|
|
284
|
+
language?: string;
|
|
285
|
+
durationSec?: number;
|
|
286
|
+
segments?: TranscriptSegment[];
|
|
287
|
+
/** 错误码(如 forbidden / asr_not_configured / model_not_authorized;成功缺席)。 */
|
|
288
|
+
errorCode?: string;
|
|
289
|
+
/** 异步任务号(平台任务径在场时恒携;GET /t1/asr/tasks/{taskId} 可找回)。 */
|
|
290
|
+
taskId?: string;
|
|
291
|
+
}
|
|
292
|
+
/** TranscriptData 的 zod schema(passthrough 容未知键)。 */
|
|
293
|
+
export declare const TranscriptDataSchema: z.ZodObject<{
|
|
294
|
+
model: z.ZodString;
|
|
295
|
+
text: z.ZodString;
|
|
296
|
+
language: z.ZodOptional<z.ZodString>;
|
|
297
|
+
durationSec: z.ZodOptional<z.ZodNumber>;
|
|
298
|
+
segments: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
299
|
+
start: z.ZodNumber;
|
|
300
|
+
end: z.ZodNumber;
|
|
301
|
+
text: z.ZodString;
|
|
302
|
+
speaker: z.ZodOptional<z.ZodString>;
|
|
303
|
+
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
|
304
|
+
start: z.ZodNumber;
|
|
305
|
+
end: z.ZodNumber;
|
|
306
|
+
text: z.ZodString;
|
|
307
|
+
speaker: z.ZodOptional<z.ZodString>;
|
|
308
|
+
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
309
|
+
start: z.ZodNumber;
|
|
310
|
+
end: z.ZodNumber;
|
|
311
|
+
text: z.ZodString;
|
|
312
|
+
speaker: z.ZodOptional<z.ZodString>;
|
|
313
|
+
}, z.ZodTypeAny, "passthrough">>, "many">>;
|
|
314
|
+
errorCode: z.ZodOptional<z.ZodString>;
|
|
315
|
+
taskId: z.ZodOptional<z.ZodString>;
|
|
316
|
+
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
|
317
|
+
model: z.ZodString;
|
|
318
|
+
text: z.ZodString;
|
|
319
|
+
language: z.ZodOptional<z.ZodString>;
|
|
320
|
+
durationSec: z.ZodOptional<z.ZodNumber>;
|
|
321
|
+
segments: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
322
|
+
start: z.ZodNumber;
|
|
323
|
+
end: z.ZodNumber;
|
|
324
|
+
text: z.ZodString;
|
|
325
|
+
speaker: z.ZodOptional<z.ZodString>;
|
|
326
|
+
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
|
327
|
+
start: z.ZodNumber;
|
|
328
|
+
end: z.ZodNumber;
|
|
329
|
+
text: z.ZodString;
|
|
330
|
+
speaker: z.ZodOptional<z.ZodString>;
|
|
331
|
+
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
332
|
+
start: z.ZodNumber;
|
|
333
|
+
end: z.ZodNumber;
|
|
334
|
+
text: z.ZodString;
|
|
335
|
+
speaker: z.ZodOptional<z.ZodString>;
|
|
336
|
+
}, z.ZodTypeAny, "passthrough">>, "many">>;
|
|
337
|
+
errorCode: z.ZodOptional<z.ZodString>;
|
|
338
|
+
taskId: z.ZodOptional<z.ZodString>;
|
|
339
|
+
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
340
|
+
model: z.ZodString;
|
|
341
|
+
text: z.ZodString;
|
|
342
|
+
language: z.ZodOptional<z.ZodString>;
|
|
343
|
+
durationSec: z.ZodOptional<z.ZodNumber>;
|
|
344
|
+
segments: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
345
|
+
start: z.ZodNumber;
|
|
346
|
+
end: z.ZodNumber;
|
|
347
|
+
text: z.ZodString;
|
|
348
|
+
speaker: z.ZodOptional<z.ZodString>;
|
|
349
|
+
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
|
350
|
+
start: z.ZodNumber;
|
|
351
|
+
end: z.ZodNumber;
|
|
352
|
+
text: z.ZodString;
|
|
353
|
+
speaker: z.ZodOptional<z.ZodString>;
|
|
354
|
+
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
355
|
+
start: z.ZodNumber;
|
|
356
|
+
end: z.ZodNumber;
|
|
357
|
+
text: z.ZodString;
|
|
358
|
+
speaker: z.ZodOptional<z.ZodString>;
|
|
359
|
+
}, z.ZodTypeAny, "passthrough">>, "many">>;
|
|
360
|
+
errorCode: z.ZodOptional<z.ZodString>;
|
|
361
|
+
taskId: z.ZodOptional<z.ZodString>;
|
|
362
|
+
}, z.ZodTypeAny, "passthrough">>;
|
|
363
|
+
/**
|
|
364
|
+
* 合成产物(SpeechData.audio;`url` 与 `b64` 恒至少一个在场)。
|
|
365
|
+
* `path` 为加法可选键:cli 内联产物落盘后的本地路径(kernel 工具 `artifactSink` 在场且
|
|
366
|
+
* `b64` 在场时写入);sdk / serve 恒不接 sink,径上恒缺席——端侧形状识别不受影响。
|
|
367
|
+
*/
|
|
368
|
+
export interface SpeechAudio {
|
|
369
|
+
/** 托管形直链(上游域内 OSS,约 24h 失效) */
|
|
370
|
+
url?: string;
|
|
371
|
+
/** 内联形 base64(无 data: 前缀;mime 见同级键) */
|
|
372
|
+
b64?: string;
|
|
373
|
+
mime: string;
|
|
374
|
+
format: string;
|
|
375
|
+
durationMs?: number;
|
|
376
|
+
sampleRate?: number;
|
|
377
|
+
/** 本地落盘路径(仅 cli artifactSink 径出现) */
|
|
378
|
+
path?: string;
|
|
379
|
+
}
|
|
380
|
+
/** SpeechAudio 的 zod schema(passthrough 容未知键)。 */
|
|
381
|
+
export declare const SpeechAudioSchema: z.ZodObject<{
|
|
382
|
+
url: z.ZodOptional<z.ZodString>;
|
|
383
|
+
b64: z.ZodOptional<z.ZodString>;
|
|
384
|
+
mime: z.ZodString;
|
|
385
|
+
format: z.ZodString;
|
|
386
|
+
durationMs: z.ZodOptional<z.ZodNumber>;
|
|
387
|
+
sampleRate: z.ZodOptional<z.ZodNumber>;
|
|
388
|
+
path: z.ZodOptional<z.ZodString>;
|
|
389
|
+
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
|
390
|
+
url: z.ZodOptional<z.ZodString>;
|
|
391
|
+
b64: z.ZodOptional<z.ZodString>;
|
|
392
|
+
mime: z.ZodString;
|
|
393
|
+
format: z.ZodString;
|
|
394
|
+
durationMs: z.ZodOptional<z.ZodNumber>;
|
|
395
|
+
sampleRate: z.ZodOptional<z.ZodNumber>;
|
|
396
|
+
path: z.ZodOptional<z.ZodString>;
|
|
397
|
+
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
398
|
+
url: z.ZodOptional<z.ZodString>;
|
|
399
|
+
b64: z.ZodOptional<z.ZodString>;
|
|
400
|
+
mime: z.ZodString;
|
|
401
|
+
format: z.ZodString;
|
|
402
|
+
durationMs: z.ZodOptional<z.ZodNumber>;
|
|
403
|
+
sampleRate: z.ZodOptional<z.ZodNumber>;
|
|
404
|
+
path: z.ZodOptional<z.ZodString>;
|
|
405
|
+
}, z.ZodTypeAny, "passthrough">>;
|
|
406
|
+
/**
|
|
407
|
+
* TextToSpeech 产物。端侧按形状识别:`audio.mime` 在场 → Speech 型
|
|
408
|
+
* 产物。**错误形 `audio` 缺席**(恒不伪造音频对象),`billedChars` 为 0。
|
|
409
|
+
*/
|
|
410
|
+
export interface SpeechData {
|
|
411
|
+
model: string;
|
|
412
|
+
audio?: SpeechAudio;
|
|
413
|
+
/** 计费字符数(= 上游成功报量;错误时 0)。 */
|
|
414
|
+
billedChars: number;
|
|
415
|
+
/** 错误码(如 forbidden / tts_not_configured / model_not_authorized;成功缺席)。 */
|
|
416
|
+
errorCode?: string;
|
|
417
|
+
/** 异步任务号(平台任务径在场时恒携;GET /t1/tts/tasks/{taskId} 可找回)。 */
|
|
418
|
+
taskId?: string;
|
|
419
|
+
}
|
|
420
|
+
/** SpeechData 的 zod schema(passthrough 容未知键)。 */
|
|
421
|
+
export declare const SpeechDataSchema: z.ZodObject<{
|
|
422
|
+
model: z.ZodString;
|
|
423
|
+
audio: z.ZodOptional<z.ZodObject<{
|
|
424
|
+
url: z.ZodOptional<z.ZodString>;
|
|
425
|
+
b64: z.ZodOptional<z.ZodString>;
|
|
426
|
+
mime: z.ZodString;
|
|
427
|
+
format: z.ZodString;
|
|
428
|
+
durationMs: z.ZodOptional<z.ZodNumber>;
|
|
429
|
+
sampleRate: z.ZodOptional<z.ZodNumber>;
|
|
430
|
+
path: z.ZodOptional<z.ZodString>;
|
|
431
|
+
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
|
432
|
+
url: z.ZodOptional<z.ZodString>;
|
|
433
|
+
b64: z.ZodOptional<z.ZodString>;
|
|
434
|
+
mime: z.ZodString;
|
|
435
|
+
format: z.ZodString;
|
|
436
|
+
durationMs: z.ZodOptional<z.ZodNumber>;
|
|
437
|
+
sampleRate: z.ZodOptional<z.ZodNumber>;
|
|
438
|
+
path: z.ZodOptional<z.ZodString>;
|
|
439
|
+
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
440
|
+
url: z.ZodOptional<z.ZodString>;
|
|
441
|
+
b64: z.ZodOptional<z.ZodString>;
|
|
442
|
+
mime: z.ZodString;
|
|
443
|
+
format: z.ZodString;
|
|
444
|
+
durationMs: z.ZodOptional<z.ZodNumber>;
|
|
445
|
+
sampleRate: z.ZodOptional<z.ZodNumber>;
|
|
446
|
+
path: z.ZodOptional<z.ZodString>;
|
|
447
|
+
}, z.ZodTypeAny, "passthrough">>>;
|
|
448
|
+
billedChars: z.ZodNumber;
|
|
449
|
+
errorCode: z.ZodOptional<z.ZodString>;
|
|
450
|
+
taskId: z.ZodOptional<z.ZodString>;
|
|
451
|
+
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
|
452
|
+
model: z.ZodString;
|
|
453
|
+
audio: z.ZodOptional<z.ZodObject<{
|
|
454
|
+
url: z.ZodOptional<z.ZodString>;
|
|
455
|
+
b64: z.ZodOptional<z.ZodString>;
|
|
456
|
+
mime: z.ZodString;
|
|
457
|
+
format: z.ZodString;
|
|
458
|
+
durationMs: z.ZodOptional<z.ZodNumber>;
|
|
459
|
+
sampleRate: z.ZodOptional<z.ZodNumber>;
|
|
460
|
+
path: z.ZodOptional<z.ZodString>;
|
|
461
|
+
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
|
462
|
+
url: z.ZodOptional<z.ZodString>;
|
|
463
|
+
b64: z.ZodOptional<z.ZodString>;
|
|
464
|
+
mime: z.ZodString;
|
|
465
|
+
format: z.ZodString;
|
|
466
|
+
durationMs: z.ZodOptional<z.ZodNumber>;
|
|
467
|
+
sampleRate: z.ZodOptional<z.ZodNumber>;
|
|
468
|
+
path: z.ZodOptional<z.ZodString>;
|
|
469
|
+
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
470
|
+
url: z.ZodOptional<z.ZodString>;
|
|
471
|
+
b64: z.ZodOptional<z.ZodString>;
|
|
472
|
+
mime: z.ZodString;
|
|
473
|
+
format: z.ZodString;
|
|
474
|
+
durationMs: z.ZodOptional<z.ZodNumber>;
|
|
475
|
+
sampleRate: z.ZodOptional<z.ZodNumber>;
|
|
476
|
+
path: z.ZodOptional<z.ZodString>;
|
|
477
|
+
}, z.ZodTypeAny, "passthrough">>>;
|
|
478
|
+
billedChars: z.ZodNumber;
|
|
479
|
+
errorCode: z.ZodOptional<z.ZodString>;
|
|
480
|
+
taskId: z.ZodOptional<z.ZodString>;
|
|
481
|
+
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
482
|
+
model: z.ZodString;
|
|
483
|
+
audio: z.ZodOptional<z.ZodObject<{
|
|
484
|
+
url: z.ZodOptional<z.ZodString>;
|
|
485
|
+
b64: z.ZodOptional<z.ZodString>;
|
|
486
|
+
mime: z.ZodString;
|
|
487
|
+
format: z.ZodString;
|
|
488
|
+
durationMs: z.ZodOptional<z.ZodNumber>;
|
|
489
|
+
sampleRate: z.ZodOptional<z.ZodNumber>;
|
|
490
|
+
path: z.ZodOptional<z.ZodString>;
|
|
491
|
+
}, "passthrough", z.ZodTypeAny, z.objectOutputType<{
|
|
492
|
+
url: z.ZodOptional<z.ZodString>;
|
|
493
|
+
b64: z.ZodOptional<z.ZodString>;
|
|
494
|
+
mime: z.ZodString;
|
|
495
|
+
format: z.ZodString;
|
|
496
|
+
durationMs: z.ZodOptional<z.ZodNumber>;
|
|
497
|
+
sampleRate: z.ZodOptional<z.ZodNumber>;
|
|
498
|
+
path: z.ZodOptional<z.ZodString>;
|
|
499
|
+
}, z.ZodTypeAny, "passthrough">, z.objectInputType<{
|
|
500
|
+
url: z.ZodOptional<z.ZodString>;
|
|
501
|
+
b64: z.ZodOptional<z.ZodString>;
|
|
502
|
+
mime: z.ZodString;
|
|
503
|
+
format: z.ZodString;
|
|
504
|
+
durationMs: z.ZodOptional<z.ZodNumber>;
|
|
505
|
+
sampleRate: z.ZodOptional<z.ZodNumber>;
|
|
506
|
+
path: z.ZodOptional<z.ZodString>;
|
|
507
|
+
}, z.ZodTypeAny, "passthrough">>>;
|
|
508
|
+
billedChars: z.ZodNumber;
|
|
509
|
+
errorCode: z.ZodOptional<z.ZodString>;
|
|
510
|
+
taskId: z.ZodOptional<z.ZodString>;
|
|
511
|
+
}, z.ZodTypeAny, "passthrough">>;
|
|
512
|
+
/** 产物判别结果:kind 判别 + 原 data(未经 schema 剥离,unknown 键原样保留) */
|
|
513
|
+
export type MediaArtifact = {
|
|
514
|
+
kind: 'image';
|
|
515
|
+
data: ImageGenData;
|
|
516
|
+
} | {
|
|
517
|
+
kind: 'video';
|
|
518
|
+
data: VideoGenData;
|
|
519
|
+
} | {
|
|
520
|
+
kind: 'transcript';
|
|
521
|
+
data: TranscriptData;
|
|
522
|
+
} | {
|
|
523
|
+
kind: 'speech';
|
|
524
|
+
data: SpeechData;
|
|
525
|
+
};
|
|
526
|
+
/**
|
|
527
|
+
* 三端共享谓词:
|
|
528
|
+
* 「产物可渲染为成功」的**单一判定**——Kotlin `isRenderableArtifact` / Swift `isRenderableArtifact` 同名同语义,
|
|
529
|
+
* 四金样 `test/fixtures/golden/tool-card-artifact-{speech-empty,image-errorcode,video-errorcode,errorcode-null}.json`
|
|
530
|
+
* 三端逐字 `[false, false, false, true]`。语义逐字:
|
|
531
|
+
*
|
|
532
|
+
* - `errorCode == null`(键缺席 / 值 `null` / 空串皆视为**无错**;任何其它值 = 错误响应,不论产物位是否非空——
|
|
533
|
+
* 此前两端 image / video 分支**不查** `errorCode`,携 url 的错误响应被渲染为成功;Android 用 `containsKey`,
|
|
534
|
+
* `errorCode: null` 被当失败)
|
|
535
|
+
* - 且 `kind ∉ {image, video} || url/path 非空`(`images` / `videos` 键在场即按该形判;空数组 / 全坏 / 全空串 = 不可渲染)
|
|
536
|
+
* - 且 `kind ≠ speech || url/b64 至少一非空`(`audio` 键在场即按 speech 判;此前 iOS 对 `url: ""` 放行为 Speech)
|
|
537
|
+
* - 其余形(transcript / search / 未知)只受 `errorCode` 一条约束(空 `text` 转写仍是合法产物)。
|
|
538
|
+
*
|
|
539
|
+
* 只判「可不可以当成功渲染」,不判「是什么形」——形由 [parseMediaArtifact] 判;本谓词为其前置门。
|
|
540
|
+
*/
|
|
541
|
+
export declare function isRenderableArtifact(data: unknown): boolean;
|
|
542
|
+
/**
|
|
543
|
+
* `tool.completed.data` / `ToolResult.data` → 媒体产物判别(**规则与判序逐字对齐
|
|
544
|
+
* Android `toolCardArtifact` / iOS `toolCardArtifact` 现行实现**):
|
|
545
|
+
*
|
|
546
|
+
* - 非对象(含 null / 数组)→ null;
|
|
547
|
+
* - `errorCode` 为字符串 → 恒 null(错误响应不是产物,即使携空产物位);
|
|
548
|
+
* - 判序 image → video → speech → transcript(端侧同序:URL 集形 → 音频 → 排他的裸文本形);
|
|
549
|
+
* - image:`model` 为字符串,且 `images` 为数组并至少一条目携字符串 `url`(空数组 / 全坏条目 = 零产物 → 不判);
|
|
550
|
+
* - video:`model` 为字符串,且 `videos` 同上;
|
|
551
|
+
* - speech:`model` 为字符串,`audio` 为对象、`audio.mime` 为字符串,且 `audio.url` / `audio.b64` 至少一者为
|
|
552
|
+
* 非空字符串(皆缺 / 皆空 = 零产物 → 不判);
|
|
553
|
+
* - transcript:`text` 与 `model` 皆字符串,且无 `images` / `videos` / `results` / `audio` 键
|
|
554
|
+
* (`results` 排 WebSearchData;三端同四键——tansr-android 补 `audio` 后与 iOS / 本实现一致);
|
|
555
|
+
* - 其余 null。
|
|
556
|
+
*
|
|
557
|
+
* 判序 image-first 以实现为准、三端一致。
|
|
558
|
+
* 只判形不校验(不经 zod 剥离未知键):返回的 data 是原对象的类型收窄视图,消费方按需再过
|
|
559
|
+
* 对应 *DataSchema。端侧两卷(Android `ToolCardArtifactsTest` / iOS `ToolCardArtifactsTests`)**既有 17 例**
|
|
560
|
+
* 在本函数上同判(protocol `media.test.ts` ⑤ 镜像收录);空串 / errorCode 判型两类异形**已以四金样
|
|
561
|
+
* 三端同源镜像**(`test/fixtures/golden/tool-card-artifact-*.json`;三端共享谓词 [isRenderableArtifact])。
|
|
562
|
+
*/
|
|
563
|
+
export declare function parseMediaArtifact(data: unknown): MediaArtifact | null;
|