@h-ai/feedback 0.0.0-stage → 0.1.0-alpha.69
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 +202 -0
- package/README.en.md +115 -0
- package/README.ja.md +115 -0
- package/README.md +116 -2
- package/dist/bundle/index.d.ts +212 -0
- package/dist/bundle/index.js +3 -0
- package/dist/bundle/index.js.map +1 -0
- package/dist/chunk-43AOXE4W.js +333 -0
- package/dist/chunk-43AOXE4W.js.map +1 -0
- package/dist/chunk-DYEK2FNM.js +101 -0
- package/dist/chunk-DYEK2FNM.js.map +1 -0
- package/dist/client/index.d.ts +187 -0
- package/dist/client/index.js +889 -0
- package/dist/client/index.js.map +1 -0
- package/dist/index.d.ts +154 -0
- package/dist/index.js +1396 -0
- package/dist/index.js.map +1 -0
- package/package.json +62 -3
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
import { PaginatedResult, HaiResult } from '@h-ai/core';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 离线证据项;业务字段放在 data 中,读取器不理解业务表结构。
|
|
5
|
+
* @example
|
|
6
|
+
* ```ts
|
|
7
|
+
* import type { FeedbackBundleEvidence } from '@h-ai/feedback/bundle'
|
|
8
|
+
* const event: FeedbackBundleEvidence = { source: 'browser', kind: 'log', timestamp: 1, data: { message: 'ready' } }
|
|
9
|
+
* ```
|
|
10
|
+
*/
|
|
11
|
+
interface FeedbackBundleEvidence {
|
|
12
|
+
id?: string;
|
|
13
|
+
source: string;
|
|
14
|
+
kind: string;
|
|
15
|
+
timestamp: number;
|
|
16
|
+
sequence?: number;
|
|
17
|
+
requestId?: string;
|
|
18
|
+
errorId?: string;
|
|
19
|
+
missingReason?: string;
|
|
20
|
+
data?: unknown;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* 随包传输的二进制附件,名称只作显示,不用于构造文件路径。
|
|
24
|
+
* @example
|
|
25
|
+
* ```ts
|
|
26
|
+
* import type { FeedbackBundleAttachment } from '@h-ai/feedback/bundle'
|
|
27
|
+
* const file: FeedbackBundleAttachment = { id: 'file-1', name: 'notes.txt', contentType: 'text/plain', bytes: new TextEncoder().encode('diagnostic notes') }
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
interface FeedbackBundleAttachment {
|
|
31
|
+
id: string;
|
|
32
|
+
name: string;
|
|
33
|
+
contentType: string;
|
|
34
|
+
bytes: Uint8Array;
|
|
35
|
+
checksum?: string;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* 离线包的输入;泛型允许直接传入框架报告类型,不要求调用方添加索引签名。
|
|
39
|
+
* @example
|
|
40
|
+
* ```ts
|
|
41
|
+
* import type { FeedbackBundleInput } from '@h-ai/feedback/bundle'
|
|
42
|
+
* const input: FeedbackBundleInput = { report: { id: 'report-1' }, evidence: [], missing: ['screenshot-unavailable'] }
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
interface FeedbackBundleInput<TReport extends {
|
|
46
|
+
id: string;
|
|
47
|
+
} = {
|
|
48
|
+
id: string;
|
|
49
|
+
}> {
|
|
50
|
+
report: TReport;
|
|
51
|
+
evidence: readonly FeedbackBundleEvidence[];
|
|
52
|
+
history?: readonly object[];
|
|
53
|
+
attachments?: readonly FeedbackBundleAttachment[];
|
|
54
|
+
missing?: readonly string[];
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* manifest 中单个文件的完整性与展示信息。
|
|
58
|
+
* @example
|
|
59
|
+
* ```ts
|
|
60
|
+
* import type { FeedbackBundleFile } from '@h-ai/feedback/bundle'
|
|
61
|
+
* const metadata: FeedbackBundleFile = { path: 'report.json', size: 2, sha256: '0'.repeat(64), kind: 'report' }
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
interface FeedbackBundleFile {
|
|
65
|
+
path: string;
|
|
66
|
+
size: number;
|
|
67
|
+
sha256: string;
|
|
68
|
+
kind: 'report' | 'evidence' | 'history' | 'attachment' | 'summary' | 'viewer';
|
|
69
|
+
attachmentId?: string;
|
|
70
|
+
name?: string;
|
|
71
|
+
contentType?: string;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* 版本化的离线包清单;manifest 本身不声称具备来源签名。
|
|
75
|
+
* @example
|
|
76
|
+
* ```ts
|
|
77
|
+
* import type { FeedbackBundleManifest } from '@h-ai/feedback/bundle'
|
|
78
|
+
* const manifest: FeedbackBundleManifest = { format: 'hai-feedback', version: 1, reportId: 'report-1', evidenceRevision: 1, createdAt: 1, missing: [], files: [] }
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
81
|
+
interface FeedbackBundleManifest {
|
|
82
|
+
format: 'hai-feedback';
|
|
83
|
+
version: 1;
|
|
84
|
+
reportId: string;
|
|
85
|
+
evidenceRevision: number;
|
|
86
|
+
createdAt: number;
|
|
87
|
+
missing: string[];
|
|
88
|
+
files: FeedbackBundleFile[];
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* 校验后的离线包;files 中的内容仍是待显示的非可信输入。
|
|
92
|
+
* @example
|
|
93
|
+
* ```ts
|
|
94
|
+
* import type { FeedbackBundle } from '@h-ai/feedback/bundle'
|
|
95
|
+
* import { readFeedbackBundle } from '@h-ai/feedback/bundle'
|
|
96
|
+
* async function parse(bytes: Uint8Array): Promise<FeedbackBundle | undefined> {
|
|
97
|
+
* const result = await readFeedbackBundle(bytes)
|
|
98
|
+
* return result.success ? result.data : undefined
|
|
99
|
+
* }
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
102
|
+
interface FeedbackBundle {
|
|
103
|
+
manifest: FeedbackBundleManifest;
|
|
104
|
+
report: Record<string, unknown> & {
|
|
105
|
+
id: string;
|
|
106
|
+
};
|
|
107
|
+
evidence: FeedbackBundleEvidence[];
|
|
108
|
+
history: Record<string, unknown>[];
|
|
109
|
+
files: Readonly<Record<string, Uint8Array>>;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* ZIP 解压与读取上限,在解压前及解压后均核对。
|
|
113
|
+
* @example
|
|
114
|
+
* ```ts
|
|
115
|
+
* import type { FeedbackBundleReadOptions } from '@h-ai/feedback/bundle'
|
|
116
|
+
* const limits: FeedbackBundleReadOptions = { maxFiles: 100, maxBytes: 8 * 1024 * 1024, maxFileBytes: 2 * 1024 * 1024 }
|
|
117
|
+
* ```
|
|
118
|
+
*/
|
|
119
|
+
interface FeedbackBundleReadOptions {
|
|
120
|
+
maxFiles?: number;
|
|
121
|
+
maxBytes?: number;
|
|
122
|
+
maxFileBytes?: number;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* 按索引分页读取证据,不要求把所有日志送入 AI 上下文。
|
|
126
|
+
* @example
|
|
127
|
+
* ```ts
|
|
128
|
+
* import type { FeedbackBundleQuery } from '@h-ai/feedback/bundle'
|
|
129
|
+
* const query: FeedbackBundleQuery = { errorId: 'error-1', page: 1, pageSize: 20 }
|
|
130
|
+
* ```
|
|
131
|
+
*/
|
|
132
|
+
interface FeedbackBundleQuery {
|
|
133
|
+
page?: number;
|
|
134
|
+
pageSize?: number;
|
|
135
|
+
kind?: string;
|
|
136
|
+
requestId?: string;
|
|
137
|
+
errorId?: string;
|
|
138
|
+
from?: number;
|
|
139
|
+
to?: number;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* 离线证据分页结果。
|
|
143
|
+
* @example
|
|
144
|
+
* ```ts
|
|
145
|
+
* import type { FeedbackBundleEvidencePage } from '@h-ai/feedback/bundle'
|
|
146
|
+
* const page: FeedbackBundleEvidencePage = { items: [], total: 0, page: 1, pageSize: 20 }
|
|
147
|
+
* ```
|
|
148
|
+
*/
|
|
149
|
+
type FeedbackBundleEvidencePage = PaginatedResult<FeedbackBundleEvidence>;
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* 生成含摘要、证据索引、附件与静态查看器的 ZIP;调用前应完成授权与脱敏。
|
|
153
|
+
* @example
|
|
154
|
+
* ```ts
|
|
155
|
+
* import { createFeedbackBundle } from '@h-ai/feedback/bundle'
|
|
156
|
+
* const result = await createFeedbackBundle({ report: { id: 'fb_1' }, evidence: [] })
|
|
157
|
+
* if (result.success) { const bytes: Uint8Array = result.data }
|
|
158
|
+
* ```
|
|
159
|
+
*/
|
|
160
|
+
declare function createFeedbackBundle<TReport extends {
|
|
161
|
+
id: string;
|
|
162
|
+
}>(input: FeedbackBundleInput<TReport>): Promise<HaiResult<Uint8Array>>;
|
|
163
|
+
/**
|
|
164
|
+
* 校验 ZIP 路径、容量、协议与所有文件的 SHA-256 后读取;不执行包内代码。
|
|
165
|
+
* @example
|
|
166
|
+
* ```ts
|
|
167
|
+
* import { createFeedbackBundle, readFeedbackBundle } from '@h-ai/feedback/bundle'
|
|
168
|
+
* const created = await createFeedbackBundle({ report: { id: 'fb_1' }, evidence: [] })
|
|
169
|
+
* if (created.success) {
|
|
170
|
+
* const parsed = await readFeedbackBundle(created.data, { maxBytes: 32 * 1024 * 1024 })
|
|
171
|
+
* if (parsed.success) { const reportId: string = parsed.data.report.id }
|
|
172
|
+
* }
|
|
173
|
+
* ```
|
|
174
|
+
*/
|
|
175
|
+
declare function readFeedbackBundle(bytes: Uint8Array, options?: FeedbackBundleReadOptions): Promise<HaiResult<FeedbackBundle>>;
|
|
176
|
+
/**
|
|
177
|
+
* 生成人工与 AI 可读摘要,明确用户描述与采集事实。
|
|
178
|
+
* @example
|
|
179
|
+
* ```ts
|
|
180
|
+
* import { createFeedbackBundle, readFeedbackBundle, summarizeFeedbackBundle } from '@h-ai/feedback/bundle'
|
|
181
|
+
* const created = await createFeedbackBundle({ report: { id: 'fb_1' }, evidence: [] })
|
|
182
|
+
* if (created.success) {
|
|
183
|
+
* const parsed = await readFeedbackBundle(created.data)
|
|
184
|
+
* if (parsed.success) { const markdown: string = summarizeFeedbackBundle(parsed.data) }
|
|
185
|
+
* }
|
|
186
|
+
* ```
|
|
187
|
+
*/
|
|
188
|
+
declare function summarizeFeedbackBundle(bundle: FeedbackBundle): string;
|
|
189
|
+
/**
|
|
190
|
+
* 通过时间、请求、错误与类型筛选离线证据;错误按锚点来源和请求取前后各 100 条,分页最大 100 条。
|
|
191
|
+
* @example
|
|
192
|
+
* ```ts
|
|
193
|
+
* import { createFeedbackBundle, queryFeedbackBundle, readFeedbackBundle } from '@h-ai/feedback/bundle'
|
|
194
|
+
* const created = await createFeedbackBundle({ report: { id: 'fb_1' }, evidence: [] })
|
|
195
|
+
* if (created.success) {
|
|
196
|
+
* const parsed = await readFeedbackBundle(created.data)
|
|
197
|
+
* if (parsed.success) { const page = queryFeedbackBundle(parsed.data, { requestId: 'req_1', page: 1, pageSize: 20 }) }
|
|
198
|
+
* }
|
|
199
|
+
* ```
|
|
200
|
+
*/
|
|
201
|
+
declare function queryFeedbackBundle(bundle: FeedbackBundle, query?: FeedbackBundleQuery): FeedbackBundleEvidencePage;
|
|
202
|
+
/**
|
|
203
|
+
* 获取内置可信离线查看器;本地服务必须使用此资源而不是执行导入包中的脚本。
|
|
204
|
+
* @example
|
|
205
|
+
* ```ts
|
|
206
|
+
* import { getFeedbackBundleViewerFiles } from '@h-ai/feedback/bundle'
|
|
207
|
+
* const html: Uint8Array | undefined = getFeedbackBundleViewerFiles()['viewer/index.html']
|
|
208
|
+
* ```
|
|
209
|
+
*/
|
|
210
|
+
declare function getFeedbackBundleViewerFiles(): Readonly<Record<string, Uint8Array>>;
|
|
211
|
+
|
|
212
|
+
export { type FeedbackBundle, type FeedbackBundleAttachment, type FeedbackBundleEvidence, type FeedbackBundleEvidencePage, type FeedbackBundleFile, type FeedbackBundleInput, type FeedbackBundleManifest, type FeedbackBundleQuery, type FeedbackBundleReadOptions, createFeedbackBundle, getFeedbackBundleViewerFiles, queryFeedbackBundle, readFeedbackBundle, summarizeFeedbackBundle };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
|