@oh-my-pi/pi-utils 17.2.8 → 17.2.10
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/CHANGELOG.md +32 -0
- package/dist/types/acp/connection.d.ts +118 -0
- package/dist/types/acp/protocol.d.ts +526 -0
- package/dist/types/acp/schema.d.ts +41 -0
- package/dist/types/acp/stream.d.ts +8 -0
- package/dist/types/acp/transport.d.ts +81 -0
- package/dist/types/acp.d.ts +6 -0
- package/dist/types/browsers.d.ts +68 -0
- package/dist/types/chalk.d.ts +125 -0
- package/dist/types/dates.d.ts +7 -0
- package/dist/types/docx/converter.d.ts +46 -0
- package/dist/types/docx/xml.d.ts +26 -0
- package/dist/types/docx/zip.d.ts +6 -0
- package/dist/types/docx.d.ts +11 -0
- package/dist/types/dom/core.d.ts +431 -0
- package/dist/types/dom/parser.d.ts +7 -0
- package/dist/types/dom/selector.d.ts +5 -0
- package/dist/types/dom.d.ts +5 -0
- package/dist/types/headers.d.ts +34 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/logger/rotating-file.d.ts +18 -0
- package/dist/types/lru.d.ts +46 -0
- package/dist/types/marked/core.d.ts +445 -0
- package/dist/types/marked.d.ts +2 -0
- package/dist/types/postmortem.d.ts +14 -0
- package/dist/types/procmgr.d.ts +16 -0
- package/dist/types/prompt.d.ts +2 -2
- package/dist/types/readability/readability.d.ts +9 -0
- package/dist/types/readability/readerable.d.ts +10 -0
- package/dist/types/readability/types.d.ts +70 -0
- package/dist/types/readability.d.ts +4 -0
- package/dist/types/template.d.ts +62 -0
- package/dist/types/turndown/gfm.d.ts +11 -0
- package/dist/types/turndown/html.d.ts +5 -0
- package/dist/types/turndown/service.d.ts +21 -0
- package/dist/types/turndown/types.d.ts +70 -0
- package/dist/types/turndown.d.ts +4 -0
- package/dist/types/version.d.ts +18 -0
- package/dist/types/vterm/buffer.d.ts +99 -0
- package/dist/types/vterm/terminal.d.ts +44 -0
- package/dist/types/vterm.d.ts +8 -0
- package/dist/types/xml.d.ts +31 -0
- package/package.json +2 -5
- package/src/acp/connection.ts +344 -0
- package/src/acp/protocol.ts +466 -0
- package/src/acp/schema.ts +160 -0
- package/src/acp/stream.ts +82 -0
- package/src/acp/transport.ts +213 -0
- package/src/acp.ts +6 -0
- package/src/browsers.ts +501 -0
- package/src/chalk.ts +312 -0
- package/src/dates.ts +194 -0
- package/src/docx/converter.ts +681 -0
- package/src/docx/xml.ts +166 -0
- package/src/docx/zip.ts +87 -0
- package/src/docx.ts +20 -0
- package/src/dom/core.ts +1254 -0
- package/src/dom/parser.ts +370 -0
- package/src/dom/selector.ts +290 -0
- package/src/dom.ts +33 -0
- package/src/fetch-retry.ts +7 -1
- package/src/frontmatter.ts +1 -1
- package/src/headers.ts +167 -0
- package/src/index.ts +1 -0
- package/src/logger/rotating-file.ts +149 -0
- package/src/logger.ts +12 -28
- package/src/lru.ts +185 -0
- package/src/marked/core.ts +1576 -0
- package/src/marked.ts +2 -0
- package/src/postmortem.ts +44 -1
- package/src/procmgr.ts +21 -4
- package/src/prompt.ts +5 -22
- package/src/readability/readability.ts +533 -0
- package/src/readability/readerable.ts +51 -0
- package/src/readability/types.ts +72 -0
- package/src/readability.ts +11 -0
- package/src/template.ts +586 -0
- package/src/turndown/gfm.ts +106 -0
- package/src/turndown/html.ts +257 -0
- package/src/turndown/service.ts +334 -0
- package/src/turndown/types.ts +81 -0
- package/src/turndown.ts +5 -0
- package/src/version.ts +99 -0
- package/src/vterm/buffer.ts +218 -0
- package/src/vterm/terminal.ts +773 -0
- package/src/vterm.ts +8 -0
- package/src/which.ts +6 -4
- package/src/xml.ts +313 -0
- package/src/winston-daily-rotate-file.d.ts +0 -6
|
@@ -0,0 +1,344 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
Agent,
|
|
3
|
+
AuthenticateRequest,
|
|
4
|
+
AuthenticateResponse,
|
|
5
|
+
CloseSessionRequest,
|
|
6
|
+
CloseSessionResponse,
|
|
7
|
+
CompleteElicitationNotification,
|
|
8
|
+
CreateElicitationRequest,
|
|
9
|
+
CreateElicitationResponse,
|
|
10
|
+
CreateTerminalRequest,
|
|
11
|
+
ForkSessionRequest,
|
|
12
|
+
ForkSessionResponse,
|
|
13
|
+
InitializeRequest,
|
|
14
|
+
InitializeResponse,
|
|
15
|
+
ListSessionsRequest,
|
|
16
|
+
ListSessionsResponse,
|
|
17
|
+
LoadSessionRequest,
|
|
18
|
+
LoadSessionResponse,
|
|
19
|
+
MaybePromise,
|
|
20
|
+
NewSessionRequest,
|
|
21
|
+
NewSessionResponse,
|
|
22
|
+
PromptRequest,
|
|
23
|
+
PromptResponse,
|
|
24
|
+
ReadTextFileRequest,
|
|
25
|
+
ReadTextFileResponse,
|
|
26
|
+
RequestPermissionRequest,
|
|
27
|
+
RequestPermissionResponse,
|
|
28
|
+
ResumeSessionRequest,
|
|
29
|
+
ResumeSessionResponse,
|
|
30
|
+
SessionNotification,
|
|
31
|
+
SetSessionConfigOptionRequest,
|
|
32
|
+
SetSessionConfigOptionResponse,
|
|
33
|
+
SetSessionModeRequest,
|
|
34
|
+
SetSessionModeResponse,
|
|
35
|
+
TerminalActionResponse,
|
|
36
|
+
TerminalOutputResponse,
|
|
37
|
+
WaitForTerminalExitResponse,
|
|
38
|
+
WriteTextFileRequest,
|
|
39
|
+
WriteTextFileResponse,
|
|
40
|
+
} from "./protocol";
|
|
41
|
+
import type { Stream } from "./stream";
|
|
42
|
+
import { RequestError, RpcConnection } from "./transport";
|
|
43
|
+
|
|
44
|
+
/** Terminal creation response returned by a client. */
|
|
45
|
+
export interface CreateTerminalResponse {
|
|
46
|
+
terminalId: string;
|
|
47
|
+
}
|
|
48
|
+
/** Client callbacks handled by a client-side connection. */
|
|
49
|
+
export interface Client {
|
|
50
|
+
requestPermission(params: RequestPermissionRequest): MaybePromise<RequestPermissionResponse>;
|
|
51
|
+
sessionUpdate(params: SessionNotification): MaybePromise<void>;
|
|
52
|
+
readTextFile?(params: ReadTextFileRequest): MaybePromise<ReadTextFileResponse>;
|
|
53
|
+
writeTextFile?(params: WriteTextFileRequest): MaybePromise<WriteTextFileResponse | void>;
|
|
54
|
+
createTerminal?(params: CreateTerminalRequest): MaybePromise<CreateTerminalResponse>;
|
|
55
|
+
terminalOutput?(params: { sessionId: string; terminalId: string }): MaybePromise<TerminalOutputResponse>;
|
|
56
|
+
waitForTerminalExit?(params: { sessionId: string; terminalId: string }): MaybePromise<WaitForTerminalExitResponse>;
|
|
57
|
+
killTerminal?(params: { sessionId: string; terminalId: string }): MaybePromise<TerminalActionResponse | void>;
|
|
58
|
+
releaseTerminal?(params: { sessionId: string; terminalId: string }): MaybePromise<TerminalActionResponse | void>;
|
|
59
|
+
unstable_createElicitation?(params: CreateElicitationRequest): MaybePromise<CreateElicitationResponse>;
|
|
60
|
+
unstable_completeElicitation?(params: CompleteElicitationNotification): MaybePromise<void>;
|
|
61
|
+
extMethod?(method: string, params: Record<string, unknown>): MaybePromise<Record<string, unknown>>;
|
|
62
|
+
extNotification?(method: string, params: Record<string, unknown>): MaybePromise<void>;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** Agent-side ACP connection. */
|
|
66
|
+
export class AgentSideConnection {
|
|
67
|
+
#connection: RpcConnection;
|
|
68
|
+
|
|
69
|
+
constructor(toAgent: (connection: AgentSideConnection) => Agent, stream: Stream) {
|
|
70
|
+
let agent: Agent | undefined;
|
|
71
|
+
this.#connection = new RpcConnection(stream, async (method, params, notification) => {
|
|
72
|
+
const target = agent;
|
|
73
|
+
if (!target) throw RequestError.internalError(undefined, "Agent is not initialized");
|
|
74
|
+
return dispatchAgent(target, method, params, notification);
|
|
75
|
+
});
|
|
76
|
+
agent = toAgent(this);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** Signal aborted when the transport closes. */
|
|
80
|
+
get signal(): AbortSignal {
|
|
81
|
+
return this.#connection.signal;
|
|
82
|
+
}
|
|
83
|
+
/** Promise resolved when the transport closes. */
|
|
84
|
+
get closed(): Promise<void> {
|
|
85
|
+
return this.#connection.closed;
|
|
86
|
+
}
|
|
87
|
+
/** Sends a session update notification. */
|
|
88
|
+
sessionUpdate(params: SessionNotification): Promise<void> {
|
|
89
|
+
return this.#connection.notify("session/update", params);
|
|
90
|
+
}
|
|
91
|
+
/** Requests permission from the client. */
|
|
92
|
+
requestPermission(params: RequestPermissionRequest): Promise<RequestPermissionResponse> {
|
|
93
|
+
return this.#connection.request("session/request_permission", params);
|
|
94
|
+
}
|
|
95
|
+
/** Reads a client-side text file. */
|
|
96
|
+
readTextFile(params: ReadTextFileRequest): Promise<ReadTextFileResponse> {
|
|
97
|
+
return this.#connection.request("fs/read_text_file", params);
|
|
98
|
+
}
|
|
99
|
+
/** Writes a client-side text file. */
|
|
100
|
+
writeTextFile(params: WriteTextFileRequest): Promise<WriteTextFileResponse> {
|
|
101
|
+
return this.#connection.request("fs/write_text_file", params);
|
|
102
|
+
}
|
|
103
|
+
/** Creates a client terminal and returns its control handle. */
|
|
104
|
+
async createTerminal(params: CreateTerminalRequest): Promise<TerminalHandle> {
|
|
105
|
+
const response = await this.#connection.request<CreateTerminalResponse>("terminal/create", params);
|
|
106
|
+
return new TerminalHandle(response.terminalId, params.sessionId, this.#connection);
|
|
107
|
+
}
|
|
108
|
+
/** Creates an interactive elicitation on the client. */
|
|
109
|
+
unstable_createElicitation(params: CreateElicitationRequest): Promise<CreateElicitationResponse> {
|
|
110
|
+
return this.#connection.request("elicitation/create", params);
|
|
111
|
+
}
|
|
112
|
+
/** Notifies a client that URL elicitation completed. */
|
|
113
|
+
unstable_completeElicitation(params: CompleteElicitationNotification): Promise<void> {
|
|
114
|
+
return this.#connection.notify("elicitation/complete", params);
|
|
115
|
+
}
|
|
116
|
+
/** Sends a custom request. */
|
|
117
|
+
request<Response = unknown, Params = unknown>(method: string, params?: Params): Promise<Response> {
|
|
118
|
+
return this.#connection.request(method, params);
|
|
119
|
+
}
|
|
120
|
+
/** Sends a custom notification. */
|
|
121
|
+
notify<Params = unknown>(method: string, params?: Params): Promise<void> {
|
|
122
|
+
return this.#connection.notify(method, params);
|
|
123
|
+
}
|
|
124
|
+
/** Sends a legacy extension request. */
|
|
125
|
+
extMethod(method: string, params: Record<string, unknown>): Promise<Record<string, unknown>> {
|
|
126
|
+
return this.request(method, params);
|
|
127
|
+
}
|
|
128
|
+
/** Sends a legacy extension notification. */
|
|
129
|
+
extNotification(method: string, params: Record<string, unknown>): Promise<void> {
|
|
130
|
+
return this.notify(method, params);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/** Handle for controlling a client-owned terminal. */
|
|
135
|
+
export class TerminalHandle {
|
|
136
|
+
/** Client terminal identifier. */
|
|
137
|
+
readonly id: string;
|
|
138
|
+
#sessionId: string;
|
|
139
|
+
#connection: RpcConnection;
|
|
140
|
+
|
|
141
|
+
constructor(id: string, sessionId: string, connection: RpcConnection) {
|
|
142
|
+
this.id = id;
|
|
143
|
+
this.#sessionId = sessionId;
|
|
144
|
+
this.#connection = connection;
|
|
145
|
+
}
|
|
146
|
+
/** Gets current terminal output. */
|
|
147
|
+
currentOutput(): Promise<TerminalOutputResponse> {
|
|
148
|
+
return this.#connection.request("terminal/output", { sessionId: this.#sessionId, terminalId: this.id });
|
|
149
|
+
}
|
|
150
|
+
/** Waits for terminal exit. */
|
|
151
|
+
waitForExit(): Promise<WaitForTerminalExitResponse> {
|
|
152
|
+
return this.#connection.request("terminal/wait_for_exit", { sessionId: this.#sessionId, terminalId: this.id });
|
|
153
|
+
}
|
|
154
|
+
/** Kills the terminal. */
|
|
155
|
+
kill(): Promise<TerminalActionResponse> {
|
|
156
|
+
return this.#connection.request("terminal/kill", { sessionId: this.#sessionId, terminalId: this.id });
|
|
157
|
+
}
|
|
158
|
+
/** Releases the terminal. */
|
|
159
|
+
release(): Promise<TerminalActionResponse | void> {
|
|
160
|
+
return this.#connection.request("terminal/release", { sessionId: this.#sessionId, terminalId: this.id });
|
|
161
|
+
}
|
|
162
|
+
/** Releases the terminal during async disposal. */
|
|
163
|
+
async [Symbol.asyncDispose](): Promise<void> {
|
|
164
|
+
await this.release();
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/** Client-side ACP connection used to call an agent. */
|
|
169
|
+
export class ClientSideConnection {
|
|
170
|
+
#connection: RpcConnection;
|
|
171
|
+
|
|
172
|
+
constructor(toClient: (connection: ClientSideConnection) => Client, stream: Stream) {
|
|
173
|
+
let client: Client | undefined;
|
|
174
|
+
this.#connection = new RpcConnection(stream, async (method, params, notification) => {
|
|
175
|
+
const target = client;
|
|
176
|
+
if (!target) throw RequestError.internalError(undefined, "Client is not initialized");
|
|
177
|
+
return dispatchClient(target, method, params, notification);
|
|
178
|
+
});
|
|
179
|
+
client = toClient(this);
|
|
180
|
+
}
|
|
181
|
+
/** Signal aborted when the transport closes. */
|
|
182
|
+
get signal(): AbortSignal {
|
|
183
|
+
return this.#connection.signal;
|
|
184
|
+
}
|
|
185
|
+
/** Promise resolved when the transport closes. */
|
|
186
|
+
get closed(): Promise<void> {
|
|
187
|
+
return this.#connection.closed;
|
|
188
|
+
}
|
|
189
|
+
/** Initializes protocol capabilities. */
|
|
190
|
+
initialize(params: InitializeRequest): Promise<InitializeResponse> {
|
|
191
|
+
return this.#connection.request("initialize", params);
|
|
192
|
+
}
|
|
193
|
+
/** Authenticates with an agent. */
|
|
194
|
+
authenticate(params: AuthenticateRequest): Promise<AuthenticateResponse> {
|
|
195
|
+
return this.#connection.request("authenticate", params);
|
|
196
|
+
}
|
|
197
|
+
/** Creates a session. */
|
|
198
|
+
newSession(params: NewSessionRequest): Promise<NewSessionResponse> {
|
|
199
|
+
return this.#connection.request("session/new", params);
|
|
200
|
+
}
|
|
201
|
+
/** Loads a session. */
|
|
202
|
+
loadSession(params: LoadSessionRequest): Promise<LoadSessionResponse> {
|
|
203
|
+
return this.#connection.request("session/load", params);
|
|
204
|
+
}
|
|
205
|
+
/** Lists sessions. */
|
|
206
|
+
listSessions(params: ListSessionsRequest): Promise<ListSessionsResponse> {
|
|
207
|
+
return this.#connection.request("session/list", params);
|
|
208
|
+
}
|
|
209
|
+
/** Resumes a session. */
|
|
210
|
+
resumeSession(params: ResumeSessionRequest): Promise<ResumeSessionResponse> {
|
|
211
|
+
return this.#connection.request("session/resume", params);
|
|
212
|
+
}
|
|
213
|
+
/** Forks a session. */
|
|
214
|
+
unstable_forkSession(params: ForkSessionRequest): Promise<ForkSessionResponse> {
|
|
215
|
+
return this.#connection.request("session/fork", params);
|
|
216
|
+
}
|
|
217
|
+
/** Closes a session. */
|
|
218
|
+
closeSession(params: CloseSessionRequest): Promise<CloseSessionResponse> {
|
|
219
|
+
return this.#connection.request("session/close", params);
|
|
220
|
+
}
|
|
221
|
+
/** Sets a session mode. */
|
|
222
|
+
setSessionMode(params: SetSessionModeRequest): Promise<SetSessionModeResponse> {
|
|
223
|
+
return this.#connection.request("session/set_mode", params);
|
|
224
|
+
}
|
|
225
|
+
/** Sets a session config option. */
|
|
226
|
+
setSessionConfigOption(params: SetSessionConfigOptionRequest): Promise<SetSessionConfigOptionResponse> {
|
|
227
|
+
return this.#connection.request("session/set_config_option", params);
|
|
228
|
+
}
|
|
229
|
+
/** Sends a prompt. */
|
|
230
|
+
prompt(params: PromptRequest): Promise<PromptResponse> {
|
|
231
|
+
return this.#connection.request("session/prompt", params);
|
|
232
|
+
}
|
|
233
|
+
/** Cancels an active prompt. */
|
|
234
|
+
cancel(params: { sessionId: string }): Promise<void> {
|
|
235
|
+
return this.#connection.notify("session/cancel", params);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
async function dispatchAgent(agent: Agent, method: string, params: unknown, notification: boolean): Promise<unknown> {
|
|
240
|
+
switch (method) {
|
|
241
|
+
case "initialize":
|
|
242
|
+
return agent.initialize(params as InitializeRequest);
|
|
243
|
+
case "authenticate":
|
|
244
|
+
return invokeRequired(agent, agent.authenticate, method, params as AuthenticateRequest);
|
|
245
|
+
case "session/new":
|
|
246
|
+
return agent.newSession(params as NewSessionRequest);
|
|
247
|
+
case "session/load":
|
|
248
|
+
return invokeRequired(agent, agent.loadSession, method, params as LoadSessionRequest);
|
|
249
|
+
case "session/list":
|
|
250
|
+
return invokeRequired(agent, agent.listSessions, method, params as ListSessionsRequest);
|
|
251
|
+
case "session/resume":
|
|
252
|
+
return invokeRequired(agent, agent.resumeSession, method, params as ResumeSessionRequest);
|
|
253
|
+
case "session/fork":
|
|
254
|
+
return invokeRequired(agent, agent.unstable_forkSession, method, params as ForkSessionRequest);
|
|
255
|
+
case "session/close":
|
|
256
|
+
return invokeRequired(agent, agent.closeSession, method, params as CloseSessionRequest);
|
|
257
|
+
case "session/set_mode":
|
|
258
|
+
return invokeRequired(agent, agent.setSessionMode, method, params as SetSessionModeRequest);
|
|
259
|
+
case "session/set_config_option":
|
|
260
|
+
return invokeRequired(agent, agent.setSessionConfigOption, method, params as SetSessionConfigOptionRequest);
|
|
261
|
+
case "session/prompt":
|
|
262
|
+
return agent.prompt(params as PromptRequest);
|
|
263
|
+
case "session/cancel":
|
|
264
|
+
return agent.cancel(params as { sessionId: string });
|
|
265
|
+
default:
|
|
266
|
+
if (method === "$/cancel_request") return;
|
|
267
|
+
if (notification && agent.extNotification)
|
|
268
|
+
return agent.extNotification(method, params as Record<string, unknown>);
|
|
269
|
+
if (!notification && agent.extMethod) return agent.extMethod(method, params as Record<string, unknown>);
|
|
270
|
+
throw RequestError.methodNotFound(method);
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
async function dispatchClient(
|
|
275
|
+
client: Client,
|
|
276
|
+
method: string,
|
|
277
|
+
params: unknown,
|
|
278
|
+
notification: boolean,
|
|
279
|
+
): Promise<unknown> {
|
|
280
|
+
switch (method) {
|
|
281
|
+
case "session/request_permission":
|
|
282
|
+
return client.requestPermission(params as RequestPermissionRequest);
|
|
283
|
+
case "session/update":
|
|
284
|
+
return client.sessionUpdate(params as SessionNotification);
|
|
285
|
+
case "fs/read_text_file":
|
|
286
|
+
return invokeRequired(client, client.readTextFile, method, params as ReadTextFileRequest);
|
|
287
|
+
case "fs/write_text_file":
|
|
288
|
+
return invokeRequired(client, client.writeTextFile, method, params as WriteTextFileRequest);
|
|
289
|
+
case "terminal/create":
|
|
290
|
+
return invokeRequired(client, client.createTerminal, method, params as CreateTerminalRequest);
|
|
291
|
+
case "terminal/output":
|
|
292
|
+
return invokeRequired(
|
|
293
|
+
client,
|
|
294
|
+
client.terminalOutput,
|
|
295
|
+
method,
|
|
296
|
+
params as { sessionId: string; terminalId: string },
|
|
297
|
+
);
|
|
298
|
+
case "terminal/wait_for_exit":
|
|
299
|
+
return invokeRequired(
|
|
300
|
+
client,
|
|
301
|
+
client.waitForTerminalExit,
|
|
302
|
+
method,
|
|
303
|
+
params as { sessionId: string; terminalId: string },
|
|
304
|
+
);
|
|
305
|
+
case "terminal/kill":
|
|
306
|
+
return invokeRequired(
|
|
307
|
+
client,
|
|
308
|
+
client.killTerminal,
|
|
309
|
+
method,
|
|
310
|
+
params as { sessionId: string; terminalId: string },
|
|
311
|
+
);
|
|
312
|
+
case "terminal/release":
|
|
313
|
+
return invokeRequired(
|
|
314
|
+
client,
|
|
315
|
+
client.releaseTerminal,
|
|
316
|
+
method,
|
|
317
|
+
params as { sessionId: string; terminalId: string },
|
|
318
|
+
);
|
|
319
|
+
case "elicitation/create":
|
|
320
|
+
return invokeRequired(client, client.unstable_createElicitation, method, params as CreateElicitationRequest);
|
|
321
|
+
case "elicitation/complete":
|
|
322
|
+
return invokeRequired(
|
|
323
|
+
client,
|
|
324
|
+
client.unstable_completeElicitation,
|
|
325
|
+
method,
|
|
326
|
+
params as CompleteElicitationNotification,
|
|
327
|
+
);
|
|
328
|
+
default:
|
|
329
|
+
if (notification && client.extNotification)
|
|
330
|
+
return client.extNotification(method, params as Record<string, unknown>);
|
|
331
|
+
if (!notification && client.extMethod) return client.extMethod(method, params as Record<string, unknown>);
|
|
332
|
+
throw RequestError.methodNotFound(method);
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
function invokeRequired<Params, Response>(
|
|
337
|
+
receiver: Agent | Client,
|
|
338
|
+
handler: ((params: Params) => MaybePromise<Response>) | undefined,
|
|
339
|
+
method: string,
|
|
340
|
+
params: Params,
|
|
341
|
+
): MaybePromise<Response> {
|
|
342
|
+
if (!handler) throw RequestError.methodNotFound(method);
|
|
343
|
+
return handler.call(receiver, params);
|
|
344
|
+
}
|