@tinywork/glass 1.0.50 → 1.1.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/index.d.ts +212 -15
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import type { OutgoingHttpHeaders, IncomingHttpHeaders } from "node:http";
|
|
2
2
|
|
|
3
|
-
type IGlassExtensionEvent<T> = (
|
|
3
|
+
type IGlassExtensionEvent<T> = (
|
|
4
|
+
params: T,
|
|
5
|
+
api?: Glass.IGlassBridge,
|
|
6
|
+
) => Promise<T>;
|
|
4
7
|
type IGlassExtensionInvokeResponse<T> = Promise<{
|
|
5
8
|
success: boolean;
|
|
6
9
|
message?: string;
|
|
@@ -9,6 +12,180 @@ type IGlassExtensionInvokeResponse<T> = Promise<{
|
|
|
9
12
|
|
|
10
13
|
declare global {
|
|
11
14
|
namespace Glass {
|
|
15
|
+
type ExtensionKind = "extension" | "agent";
|
|
16
|
+
|
|
17
|
+
type AgentFailurePolicy = "open" | "closed";
|
|
18
|
+
|
|
19
|
+
type TrafficMatch = {
|
|
20
|
+
origins?: string[];
|
|
21
|
+
pathnames?: string[];
|
|
22
|
+
methods?: string[];
|
|
23
|
+
requestHeaders?: Record<string, string>;
|
|
24
|
+
statusCodes?: number[];
|
|
25
|
+
resourceTypes?: ResourceType[];
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
type AgentExtensionOptions = {
|
|
29
|
+
entry?: string;
|
|
30
|
+
match?: TrafficMatch;
|
|
31
|
+
timeoutMs?: number;
|
|
32
|
+
maxBodyBytes?: number;
|
|
33
|
+
maxDelayMs?: number;
|
|
34
|
+
failurePolicy?: AgentFailurePolicy;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
type ExtensionManifest = {
|
|
38
|
+
kind?: ExtensionKind;
|
|
39
|
+
capabilities?: string[];
|
|
40
|
+
agent?: AgentExtensionOptions;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
type TrafficDiagnostic = {
|
|
44
|
+
level: "info" | "warning" | "error";
|
|
45
|
+
message: string;
|
|
46
|
+
details?: unknown;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
type TrafficResponse = {
|
|
50
|
+
statusCode?: number;
|
|
51
|
+
statusMessage?: string;
|
|
52
|
+
headers?: OutgoingHttpHeaders;
|
|
53
|
+
body?: any;
|
|
54
|
+
source?: "agent" | "mock" | "upstream";
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
type TrafficRequestContext = {
|
|
58
|
+
requestId?: string;
|
|
59
|
+
/** url为null时表示break了请求 */
|
|
60
|
+
url: string | null;
|
|
61
|
+
originUrl?: string | null;
|
|
62
|
+
method?: string;
|
|
63
|
+
headers?: IncomingHttpHeaders;
|
|
64
|
+
body?: any;
|
|
65
|
+
response?: TrafficResponse;
|
|
66
|
+
isLocal?: boolean;
|
|
67
|
+
rule?: RuleSchema;
|
|
68
|
+
delayMs?: number;
|
|
69
|
+
diagnostics?: TrafficDiagnostic[];
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
type TrafficRequestSnapshot = {
|
|
73
|
+
requestId: string;
|
|
74
|
+
url: string;
|
|
75
|
+
originUrl?: string;
|
|
76
|
+
method?: string;
|
|
77
|
+
headers?: IncomingHttpHeaders;
|
|
78
|
+
body?: any;
|
|
79
|
+
isLocal?: boolean;
|
|
80
|
+
rule?: RuleSchema;
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
type TrafficResponseContext = {
|
|
84
|
+
request: TrafficRequestSnapshot;
|
|
85
|
+
response: TrafficResponse;
|
|
86
|
+
resourceType?: ResourceType;
|
|
87
|
+
delayMs?: number;
|
|
88
|
+
diagnostics?: TrafficDiagnostic[];
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
type TrafficResponseChunkContext = TrafficResponseContext & {
|
|
92
|
+
chunk: string;
|
|
93
|
+
sequence: number;
|
|
94
|
+
isLast: boolean;
|
|
95
|
+
terminate?: boolean;
|
|
96
|
+
terminateReason?: string;
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
type TrafficCompleteContext = TrafficResponseContext & {
|
|
100
|
+
duration?: number;
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
type AgentTrafficChange = {
|
|
104
|
+
path: string;
|
|
105
|
+
before?: unknown;
|
|
106
|
+
after?: unknown;
|
|
107
|
+
masked?: boolean;
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
type AgentTrafficMessage = {
|
|
111
|
+
id: string;
|
|
112
|
+
conversationId: string;
|
|
113
|
+
agentId: string;
|
|
114
|
+
requestUid: string;
|
|
115
|
+
hook: keyof IGlassExtension;
|
|
116
|
+
action: string;
|
|
117
|
+
title: string;
|
|
118
|
+
summary?: string;
|
|
119
|
+
changes?: AgentTrafficChange[];
|
|
120
|
+
diagnostics?: TrafficDiagnostic[];
|
|
121
|
+
duration?: number;
|
|
122
|
+
createdAt: number;
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
type AgentExtensionRuntimeStatus = "stopped" | "validating" | "starting" | "running" | "reloading" | "stopping" | "error";
|
|
126
|
+
|
|
127
|
+
type AgentExtensionDraft = {
|
|
128
|
+
id: string;
|
|
129
|
+
name: string;
|
|
130
|
+
description?: string;
|
|
131
|
+
version?: string;
|
|
132
|
+
required?: string;
|
|
133
|
+
icon?: string;
|
|
134
|
+
private?: boolean;
|
|
135
|
+
manifest?: ExtensionManifest;
|
|
136
|
+
source: string;
|
|
137
|
+
readme?: string;
|
|
138
|
+
revision?: string;
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
type AgentExtensionSummary = {
|
|
142
|
+
id: string;
|
|
143
|
+
name: string;
|
|
144
|
+
description?: string;
|
|
145
|
+
version?: string;
|
|
146
|
+
required?: string;
|
|
147
|
+
icon?: string;
|
|
148
|
+
private?: boolean;
|
|
149
|
+
revision?: string;
|
|
150
|
+
md5?: string;
|
|
151
|
+
publishedMd5?: string;
|
|
152
|
+
hasChanges?: boolean;
|
|
153
|
+
status?: boolean;
|
|
154
|
+
runtimeStatus: AgentExtensionRuntimeStatus;
|
|
155
|
+
hooks?: string[];
|
|
156
|
+
lastError?: string;
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
type AgentExtensionValidation = {
|
|
160
|
+
valid: boolean;
|
|
161
|
+
hooks?: string[];
|
|
162
|
+
revision?: string;
|
|
163
|
+
message?: string;
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
type AgentExtensionMutationResult = AgentExtensionSummary & {
|
|
167
|
+
reloaded?: boolean;
|
|
168
|
+
rollback?: boolean;
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
type AgentExtensionPublishInput = {
|
|
172
|
+
id: string;
|
|
173
|
+
name?: string;
|
|
174
|
+
description?: string;
|
|
175
|
+
version?: string;
|
|
176
|
+
icon?: string;
|
|
177
|
+
orgId?: string;
|
|
178
|
+
teamId?: string;
|
|
179
|
+
private?: boolean;
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
type AgentExtensionActionParams = {
|
|
183
|
+
type: "agentExtension";
|
|
184
|
+
action: "create" | "update" | "publish";
|
|
185
|
+
data: AgentExtensionDraft;
|
|
186
|
+
conversationId?: string;
|
|
187
|
+
};
|
|
188
|
+
|
|
12
189
|
type MenuItem = {
|
|
13
190
|
/** 用来click回调时区分 */
|
|
14
191
|
id: string;
|
|
@@ -325,20 +502,16 @@ declare global {
|
|
|
325
502
|
activate?: IGlassExtensionEvent<void>;
|
|
326
503
|
/** 通过设置页面修改数据 */
|
|
327
504
|
onItemChange?: IGlassExtensionEvent<void>;
|
|
328
|
-
/**
|
|
329
|
-
onRequest?: IGlassExtensionEvent<
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
isLocal?: boolean;
|
|
339
|
-
headers?: IncomingHttpHeaders;
|
|
340
|
-
rule?: RuleSchema;
|
|
341
|
-
}>;
|
|
505
|
+
/** 请求发送到上游或本地 Mock 处理前触发 */
|
|
506
|
+
onRequest?: IGlassExtensionEvent<TrafficRequestContext>;
|
|
507
|
+
/** 响应头返回客户端前触发 */
|
|
508
|
+
onResponseHeaders?: IGlassExtensionEvent<TrafficResponseContext>;
|
|
509
|
+
/** 响应体返回客户端前触发;命中该 Hook 时 Glass 会按配置限制缓冲响应体 */
|
|
510
|
+
onResponseBody?: IGlassExtensionEvent<TrafficResponseContext>;
|
|
511
|
+
/** SSE 事件帧返回客户端前触发;可修改单帧、延迟发送或主动中断连接 */
|
|
512
|
+
onResponseChunk?: IGlassExtensionEvent<TrafficResponseChunkContext>;
|
|
513
|
+
/** 请求处理完成后触发;用于诊断与观察,不再修改客户端响应 */
|
|
514
|
+
onComplete?: IGlassExtensionEvent<TrafficCompleteContext>;
|
|
342
515
|
/** 在执行请求用例时触发,用于修改config */
|
|
343
516
|
onRequestExec?: IGlassExtensionEvent<{
|
|
344
517
|
url: string;
|
|
@@ -509,6 +682,30 @@ declare global {
|
|
|
509
682
|
isFinish: boolean;
|
|
510
683
|
}): IGlassExtensionInvokeResponse<void>;
|
|
511
684
|
|
|
685
|
+
queryAgentExtensions(): IGlassExtensionInvokeResponse<AgentExtensionSummary[]>;
|
|
686
|
+
getAgentExtension(id: string): IGlassExtensionInvokeResponse<AgentExtensionDraft>;
|
|
687
|
+
createAgentExtension(
|
|
688
|
+
input: AgentExtensionDraft,
|
|
689
|
+
): IGlassExtensionInvokeResponse<AgentExtensionMutationResult>;
|
|
690
|
+
updateAgentExtension(
|
|
691
|
+
input: AgentExtensionDraft,
|
|
692
|
+
): IGlassExtensionInvokeResponse<AgentExtensionMutationResult>;
|
|
693
|
+
validateAgentExtension(
|
|
694
|
+
input: AgentExtensionDraft | { id: string },
|
|
695
|
+
): IGlassExtensionInvokeResponse<AgentExtensionValidation>;
|
|
696
|
+
publishAgentExtension(
|
|
697
|
+
input: AgentExtensionPublishInput,
|
|
698
|
+
): IGlassExtensionInvokeResponse<AgentExtensionSummary>;
|
|
699
|
+
setAgentExtensionStatus(input: {
|
|
700
|
+
id: string;
|
|
701
|
+
enabled: boolean;
|
|
702
|
+
}): IGlassExtensionInvokeResponse<AgentExtensionSummary>;
|
|
703
|
+
queryAgentExtensionMessages(params: {
|
|
704
|
+
id: string;
|
|
705
|
+
requestUid?: string;
|
|
706
|
+
limit?: number;
|
|
707
|
+
}): IGlassExtensionInvokeResponse<AgentTrafficMessage[]>;
|
|
708
|
+
|
|
512
709
|
queryRules(): IGlassExtensionInvokeResponse<RuleSchema[]>;
|
|
513
710
|
getRule(
|
|
514
711
|
params: { apiId: string } | { ruleId: string },
|