@axiom-lattice/client-sdk 1.0.43 → 1.0.44
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/dist/ChunkMessageMerger.d.ts +18 -0
- package/dist/ChunkMessageMerger.d.ts.map +1 -0
- package/dist/ChunkMessageMerger.js +264 -0
- package/dist/ChunkMessageMerger.js.map +1 -0
- package/dist/abstract-client.d.ts +129 -0
- package/dist/abstract-client.d.ts.map +1 -0
- package/dist/abstract-client.js +279 -0
- package/dist/abstract-client.js.map +1 -0
- package/dist/client.d.ts +54 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +224 -0
- package/dist/client.js.map +1 -0
- package/dist/index.d.ts +96 -103
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2049 -358
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2061 -358
- package/dist/index.mjs.map +1 -1
- package/dist/types.d.ts +282 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +27 -0
- package/dist/types.js.map +1 -0
- package/dist/wechat-client.d.ts +56 -0
- package/dist/wechat-client.d.ts.map +1 -0
- package/dist/wechat-client.js +226 -0
- package/dist/wechat-client.js.map +1 -0
- package/dist/wechat_lib/encoding-indexes.d.ts +2 -0
- package/dist/wechat_lib/encoding-indexes.d.ts.map +1 -0
- package/dist/wechat_lib/encoding-indexes.js +46 -0
- package/dist/wechat_lib/encoding-indexes.js.map +1 -0
- package/dist/wechat_lib/encoding.d.ts +4 -0
- package/dist/wechat_lib/encoding.d.ts.map +1 -0
- package/dist/wechat_lib/encoding.js +2897 -0
- package/dist/wechat_lib/encoding.js.map +1 -0
- package/package.json +3 -3
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ChunkMessageMerger
|
|
3
|
+
*
|
|
4
|
+
* A utility for handling streaming message chunks and merging them into complete messages.
|
|
5
|
+
*/
|
|
6
|
+
import { MessageChunk } from "@axiom-lattice/protocols";
|
|
7
|
+
/**
|
|
8
|
+
* Creates a simple message merger for handling streaming message chunks
|
|
9
|
+
* @returns An object with methods to push chunks and retrieve merged messages
|
|
10
|
+
*/
|
|
11
|
+
export declare function createSimpleMessageMerger(): {
|
|
12
|
+
push: (chunk: MessageChunk) => void;
|
|
13
|
+
initialMessages: (msgs: any[]) => void;
|
|
14
|
+
getMessages: () => any[];
|
|
15
|
+
getMessagesWithoutToolCalls: () => any[];
|
|
16
|
+
reset: () => void;
|
|
17
|
+
};
|
|
18
|
+
//# sourceMappingURL=ChunkMessageMerger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ChunkMessageMerger.d.ts","sourceRoot":"","sources":["../src/ChunkMessageMerger.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAW,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAEjE;;;GAGG;AACH,wBAAgB,yBAAyB;kBAwIlB,YAAY;4BATF,GAAG,EAAE;uBAmGZ,GAAG,EAAE;uCAiDW,GAAG,EAAE;;EAwB9C"}
|
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ChunkMessageMerger
|
|
3
|
+
*
|
|
4
|
+
* A utility for handling streaming message chunks and merging them into complete messages.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Creates a simple message merger for handling streaming message chunks
|
|
8
|
+
* @returns An object with methods to push chunks and retrieve merged messages
|
|
9
|
+
*/
|
|
10
|
+
export function createSimpleMessageMerger() {
|
|
11
|
+
let messages = [];
|
|
12
|
+
const messageMap = new Map();
|
|
13
|
+
// Tool call builder: messageId -> index -> build state
|
|
14
|
+
const toolBuilders = new Map();
|
|
15
|
+
/**
|
|
16
|
+
* Normalizes role string to standard role
|
|
17
|
+
* @param type - Role string from the input
|
|
18
|
+
* @returns Normalized role
|
|
19
|
+
*/
|
|
20
|
+
function normalizeRole(type) {
|
|
21
|
+
switch (type) {
|
|
22
|
+
case "ai":
|
|
23
|
+
return "ai";
|
|
24
|
+
case "human":
|
|
25
|
+
case "user":
|
|
26
|
+
return "human";
|
|
27
|
+
case "system":
|
|
28
|
+
return "system";
|
|
29
|
+
case "tool":
|
|
30
|
+
return "tool";
|
|
31
|
+
case "developer":
|
|
32
|
+
return "developer";
|
|
33
|
+
default:
|
|
34
|
+
return "ai";
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Safely parses JSON string
|
|
39
|
+
* @param str - JSON string to parse
|
|
40
|
+
* @returns Parsed object or original string if parsing fails
|
|
41
|
+
*/
|
|
42
|
+
function safeJsonParse(str) {
|
|
43
|
+
try {
|
|
44
|
+
return JSON.parse(str);
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
return str; // Return original string if parsing fails
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Ensures a message exists, creating it if needed
|
|
52
|
+
* @param id - Message ID
|
|
53
|
+
* @param role - Message role
|
|
54
|
+
* @returns The message object
|
|
55
|
+
*/
|
|
56
|
+
function ensureMessage(id, role) {
|
|
57
|
+
const index = messageMap.get(id);
|
|
58
|
+
if (index !== undefined) {
|
|
59
|
+
return messages[index];
|
|
60
|
+
}
|
|
61
|
+
// Create new message
|
|
62
|
+
let newMessage;
|
|
63
|
+
switch (role) {
|
|
64
|
+
case "human":
|
|
65
|
+
newMessage = { id, role: "human", content: "" };
|
|
66
|
+
break;
|
|
67
|
+
case "system":
|
|
68
|
+
newMessage = { id, role: "system", content: "" };
|
|
69
|
+
break;
|
|
70
|
+
case "tool":
|
|
71
|
+
newMessage = { id, role: "tool", content: "", tool_call_id: "" };
|
|
72
|
+
break;
|
|
73
|
+
case "developer":
|
|
74
|
+
newMessage = { id, role: "developer", content: "" };
|
|
75
|
+
break;
|
|
76
|
+
default:
|
|
77
|
+
newMessage = { id, role: "ai", content: "" };
|
|
78
|
+
}
|
|
79
|
+
messages.push(newMessage);
|
|
80
|
+
messageMap.set(id, messages.length - 1);
|
|
81
|
+
return newMessage;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Updates tool calls for a message
|
|
85
|
+
* @param message - Message to update
|
|
86
|
+
*/
|
|
87
|
+
function updateToolCalls(message) {
|
|
88
|
+
if (message.role !== "ai")
|
|
89
|
+
return;
|
|
90
|
+
const builders = toolBuilders.get(message.id);
|
|
91
|
+
if (!builders || builders.size === 0)
|
|
92
|
+
return;
|
|
93
|
+
const toolCalls = [];
|
|
94
|
+
for (const [index, builder] of Array.from(builders.entries())) {
|
|
95
|
+
if (builder.name && builder.id) {
|
|
96
|
+
// Try to parse arguments as JSON object
|
|
97
|
+
const args = builder.args.trim();
|
|
98
|
+
const parsedArgs = safeJsonParse(args);
|
|
99
|
+
// Create ToolCall object
|
|
100
|
+
toolCalls.push({
|
|
101
|
+
id: builder.id,
|
|
102
|
+
name: builder.name,
|
|
103
|
+
args: typeof parsedArgs === "object" ? parsedArgs : { value: parsedArgs },
|
|
104
|
+
type: "tool_call",
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
// Only set tool_calls if there are any
|
|
109
|
+
if (toolCalls.length > 0) {
|
|
110
|
+
message.tool_calls = toolCalls;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Initialize messages
|
|
115
|
+
* @param msgs - Initial messages
|
|
116
|
+
*/
|
|
117
|
+
function initialMessages(msgs) {
|
|
118
|
+
// Just store the messages as-is
|
|
119
|
+
messages = msgs;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Processes a message chunk
|
|
123
|
+
* @param chunk - Message chunk to process
|
|
124
|
+
*/
|
|
125
|
+
function push(chunk) {
|
|
126
|
+
const role = normalizeRole(chunk.type);
|
|
127
|
+
const message = ensureMessage(chunk.data.id, role);
|
|
128
|
+
// Accumulate content
|
|
129
|
+
if (chunk.data.content) {
|
|
130
|
+
message.content = (message.content || "") + chunk.data.content;
|
|
131
|
+
}
|
|
132
|
+
// Handle tool call ID (for tool messages)
|
|
133
|
+
if (message.role === "tool" && chunk.data.tool_call_id) {
|
|
134
|
+
message.tool_call_id = chunk.data.tool_call_id;
|
|
135
|
+
}
|
|
136
|
+
// Handle tool call chunks (incremental)
|
|
137
|
+
if (chunk.data.tool_call_chunks && message.role === "ai") {
|
|
138
|
+
let builders = toolBuilders.get(message.id);
|
|
139
|
+
if (!builders) {
|
|
140
|
+
builders = new Map();
|
|
141
|
+
toolBuilders.set(message.id, builders);
|
|
142
|
+
}
|
|
143
|
+
for (const chunk_item of chunk.data.tool_call_chunks) {
|
|
144
|
+
let builder = builders.get(chunk_item.index);
|
|
145
|
+
if (!builder) {
|
|
146
|
+
builder = { args: "" };
|
|
147
|
+
builders.set(chunk_item.index, builder);
|
|
148
|
+
}
|
|
149
|
+
if (chunk_item.name)
|
|
150
|
+
builder.name = chunk_item.name;
|
|
151
|
+
if (chunk_item.id)
|
|
152
|
+
builder.id = chunk_item.id;
|
|
153
|
+
if (chunk_item.args)
|
|
154
|
+
builder.args += chunk_item.args;
|
|
155
|
+
}
|
|
156
|
+
updateToolCalls(message);
|
|
157
|
+
}
|
|
158
|
+
// Handle complete tool calls (overwrite)
|
|
159
|
+
if (chunk.data.tool_calls && message.role === "ai") {
|
|
160
|
+
const toolCalls = chunk.data.tool_calls
|
|
161
|
+
.filter((tc) => tc.name && tc.id)
|
|
162
|
+
.map((tc) => ({
|
|
163
|
+
id: tc.id,
|
|
164
|
+
name: tc.name,
|
|
165
|
+
args: tc.args,
|
|
166
|
+
type: "tool_call",
|
|
167
|
+
response: tc.response,
|
|
168
|
+
status: "success",
|
|
169
|
+
}));
|
|
170
|
+
if (toolCalls.length > 0) {
|
|
171
|
+
message.tool_calls = toolCalls;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
// Handle tool calls in additional_kwargs
|
|
175
|
+
if (chunk.data.additional_kwargs?.tool_calls &&
|
|
176
|
+
message.role === "ai" &&
|
|
177
|
+
!message.tool_calls) {
|
|
178
|
+
const toolCalls = [];
|
|
179
|
+
for (const tc of chunk.data.additional_kwargs.tool_calls) {
|
|
180
|
+
if (tc.function?.name && tc.id) {
|
|
181
|
+
// Convert to our format
|
|
182
|
+
const args = typeof tc.function.arguments === "string"
|
|
183
|
+
? safeJsonParse(tc.function.arguments)
|
|
184
|
+
: tc.function.arguments || {};
|
|
185
|
+
toolCalls.push({
|
|
186
|
+
id: tc.id,
|
|
187
|
+
name: tc.function.name,
|
|
188
|
+
args,
|
|
189
|
+
type: "tool_call",
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
if (toolCalls.length > 0) {
|
|
194
|
+
message.tool_calls = toolCalls;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Gets all messages with tool responses merged into tool calls
|
|
200
|
+
* @returns Array of messages with tool responses merged into tool calls
|
|
201
|
+
*/
|
|
202
|
+
function getMessages() {
|
|
203
|
+
// Create a map to store tool responses by their tool_call_id
|
|
204
|
+
const toolResponsesMap = {};
|
|
205
|
+
// First pass: collect all tool responses
|
|
206
|
+
messages.forEach((message) => {
|
|
207
|
+
if (message.role === "tool" && message.tool_call_id) {
|
|
208
|
+
toolResponsesMap[message.tool_call_id] = message;
|
|
209
|
+
}
|
|
210
|
+
});
|
|
211
|
+
// Second pass: merge tool responses with their corresponding AI messages
|
|
212
|
+
return messages
|
|
213
|
+
.filter((message) => {
|
|
214
|
+
// Keep all messages except tool messages
|
|
215
|
+
return message.role !== "tool";
|
|
216
|
+
})
|
|
217
|
+
.map((message) => {
|
|
218
|
+
if (message.role === "ai" && message.tool_calls) {
|
|
219
|
+
// Create a new message object with merged tool responses
|
|
220
|
+
const mergedMessage = { ...message };
|
|
221
|
+
// Add tool responses to the corresponding tool calls
|
|
222
|
+
if (mergedMessage.tool_calls) {
|
|
223
|
+
mergedMessage.tool_calls = mergedMessage.tool_calls.map((toolCall) => {
|
|
224
|
+
const toolResponse = toolResponsesMap[toolCall.id];
|
|
225
|
+
if (toolResponse) {
|
|
226
|
+
return {
|
|
227
|
+
...toolCall,
|
|
228
|
+
response: toolResponse.content,
|
|
229
|
+
status: "success",
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
return toolCall;
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
return mergedMessage;
|
|
236
|
+
}
|
|
237
|
+
return message;
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* Gets messages without tool calls
|
|
242
|
+
* @returns Array of messages without tool calls
|
|
243
|
+
*/
|
|
244
|
+
function getMessagesWithoutToolCalls() {
|
|
245
|
+
return messages.filter((message) => message.role !== "tool" &&
|
|
246
|
+
(message.role !== "ai" || !message.tool_calls));
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* Resets the message merger state
|
|
250
|
+
*/
|
|
251
|
+
function reset() {
|
|
252
|
+
messages.length = 0;
|
|
253
|
+
messageMap.clear();
|
|
254
|
+
toolBuilders.clear();
|
|
255
|
+
}
|
|
256
|
+
return {
|
|
257
|
+
push,
|
|
258
|
+
initialMessages,
|
|
259
|
+
getMessages,
|
|
260
|
+
getMessagesWithoutToolCalls,
|
|
261
|
+
reset,
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
//# sourceMappingURL=ChunkMessageMerger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ChunkMessageMerger.js","sourceRoot":"","sources":["../src/ChunkMessageMerger.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH;;;GAGG;AACH,MAAM,UAAU,yBAAyB;IACvC,IAAI,QAAQ,GAAc,EAAE,CAAC;IAC7B,MAAM,UAAU,GAAG,IAAI,GAAG,EAAkB,CAAC;IAE7C,uDAAuD;IACvD,MAAM,YAAY,GAAG,IAAI,GAAG,EAUzB,CAAC;IAEJ;;;;OAIG;IACH,SAAS,aAAa,CAAC,IAA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C,MAAM,GAAG,CAAC,CAAC;QACpB,UAAU,CAAC,KAAK,EAAE,CAAC;QACnB,YAAY,CAAC,KAAK,EAAE,CAAC;IACvB,CAAC;IAED,OAAO;QACL,IAAI;QACJ,eAAe;QACf,WAAW;QACX,2BAA2B;QAC3B,KAAK;KACN,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { Message, MessageChunk } from "@axiom-lattice/protocols";
|
|
2
|
+
import { AgentState, ChatResponse, ChatSendOptions, ChatStreamOptions, ClientConfig, CreateThreadOptions, GetMessagesOptions, ListThreadsOptions, RegisterToolOptions, RunOptions, Thread } from "./types";
|
|
3
|
+
/**
|
|
4
|
+
* Abstract client class for interacting with the Axiom Lattice Agent Service API
|
|
5
|
+
* Provides common functionality for different client implementations
|
|
6
|
+
*/
|
|
7
|
+
export declare abstract class AbstractClient {
|
|
8
|
+
protected config: ClientConfig;
|
|
9
|
+
protected assistantId: string;
|
|
10
|
+
protected tenantId: string;
|
|
11
|
+
protected registeredTools: Map<string, RegisterToolOptions>;
|
|
12
|
+
/**
|
|
13
|
+
* Creates a new AbstractClient instance
|
|
14
|
+
* @param config - Configuration options for the client
|
|
15
|
+
*/
|
|
16
|
+
constructor(config: ClientConfig);
|
|
17
|
+
/**
|
|
18
|
+
* Set tenant ID for multi-tenant environments
|
|
19
|
+
* @param tenantId - Tenant identifier
|
|
20
|
+
*/
|
|
21
|
+
abstract setTenantId(tenantId: string): void;
|
|
22
|
+
/**
|
|
23
|
+
* Abstract method for making API requests
|
|
24
|
+
* To be implemented by concrete client classes
|
|
25
|
+
*/
|
|
26
|
+
protected abstract makeRequest<T>(url: string, options?: {
|
|
27
|
+
method?: string;
|
|
28
|
+
body?: any;
|
|
29
|
+
headers?: Record<string, string>;
|
|
30
|
+
}): Promise<T>;
|
|
31
|
+
/**
|
|
32
|
+
* Abstract method for streaming API requests
|
|
33
|
+
* To be implemented by concrete client classes
|
|
34
|
+
*/
|
|
35
|
+
/**
|
|
36
|
+
* Helper method to build stream request parameters
|
|
37
|
+
* @param options - Options for running the agent
|
|
38
|
+
* @returns The formatted request parameters
|
|
39
|
+
*/
|
|
40
|
+
protected buildStreamRequestParams(options: RunOptions): {
|
|
41
|
+
url: string;
|
|
42
|
+
method: string;
|
|
43
|
+
body: any;
|
|
44
|
+
};
|
|
45
|
+
protected abstract streamRequest(options: RunOptions, onEvent: (event: MessageChunk) => void, onComplete?: (state?: AgentState) => void, onError?: (error: Error) => void): () => void;
|
|
46
|
+
/**
|
|
47
|
+
* Creates a new thread
|
|
48
|
+
* @param options - Options for creating a thread
|
|
49
|
+
* @returns A promise that resolves to the thread ID
|
|
50
|
+
*/
|
|
51
|
+
createThread(options: CreateThreadOptions): Promise<string>;
|
|
52
|
+
/**
|
|
53
|
+
* Retrieves thread information
|
|
54
|
+
* @param threadId - Thread identifier
|
|
55
|
+
* @returns A promise that resolves to the thread information
|
|
56
|
+
*/
|
|
57
|
+
getThread(threadId: string): Promise<Thread>;
|
|
58
|
+
/**
|
|
59
|
+
* Lists all threads
|
|
60
|
+
* @param options - Options for listing threads
|
|
61
|
+
* @returns A promise that resolves to an array of threads
|
|
62
|
+
*/
|
|
63
|
+
listThreads(options?: ListThreadsOptions): Promise<Thread[]>;
|
|
64
|
+
/**
|
|
65
|
+
* Deletes a thread
|
|
66
|
+
* @param threadId - Thread identifier
|
|
67
|
+
* @returns A promise that resolves when the thread is deleted
|
|
68
|
+
*/
|
|
69
|
+
deleteThread(threadId: string): Promise<void>;
|
|
70
|
+
/**
|
|
71
|
+
* Retrieves messages from a thread
|
|
72
|
+
* @param options - Options for retrieving messages
|
|
73
|
+
* @returns A promise that resolves to an array of messages
|
|
74
|
+
*/
|
|
75
|
+
getMessages(options: GetMessagesOptions): Promise<Message[]>;
|
|
76
|
+
/**
|
|
77
|
+
* Retrieves agent state
|
|
78
|
+
* @param threadId - Thread identifier
|
|
79
|
+
* @returns A promise that resolves to the agent state
|
|
80
|
+
*/
|
|
81
|
+
getAgentState(threadId: string): Promise<AgentState>;
|
|
82
|
+
/**
|
|
83
|
+
* Gets agent graph visualization
|
|
84
|
+
* @returns A promise that resolves to the graph visualization data
|
|
85
|
+
*/
|
|
86
|
+
getAgentGraph(): Promise<string>;
|
|
87
|
+
/**
|
|
88
|
+
* Run agent with options
|
|
89
|
+
* @param options - Options for running the agent
|
|
90
|
+
* @returns A promise that resolves to the run result
|
|
91
|
+
*/
|
|
92
|
+
run(options: RunOptions): Promise<ChatResponse>;
|
|
93
|
+
/**
|
|
94
|
+
* Chat namespace for sending messages and streaming responses
|
|
95
|
+
*/
|
|
96
|
+
chat: {
|
|
97
|
+
/**
|
|
98
|
+
* Sends a message to a thread and receives a response
|
|
99
|
+
* @param options - Options for sending a message
|
|
100
|
+
* @returns A promise that resolves to the chat response
|
|
101
|
+
*/
|
|
102
|
+
send: (options: ChatSendOptions) => Promise<ChatResponse>;
|
|
103
|
+
/**
|
|
104
|
+
* Sends a message to a thread and streams the response
|
|
105
|
+
* @param options - Options for streaming a message
|
|
106
|
+
* @param onEvent - Callback function that receives stream events
|
|
107
|
+
* @param onComplete - Optional callback function called when streaming completes
|
|
108
|
+
* @param onError - Optional callback function called when an error occurs
|
|
109
|
+
* @returns A function that can be called to stop the stream
|
|
110
|
+
*/
|
|
111
|
+
stream: (options: ChatStreamOptions, onEvent: (event: MessageChunk) => void, onComplete?: (state?: AgentState) => void, onError?: (error: Error) => void) => (() => void);
|
|
112
|
+
};
|
|
113
|
+
/**
|
|
114
|
+
* Tools namespace for registering and unregistering client-side tools
|
|
115
|
+
*/
|
|
116
|
+
tools: {
|
|
117
|
+
/**
|
|
118
|
+
* Registers a client-side tool
|
|
119
|
+
* @param options - Options for registering a tool
|
|
120
|
+
*/
|
|
121
|
+
register: (options: RegisterToolOptions) => void;
|
|
122
|
+
/**
|
|
123
|
+
* Unregisters a client-side tool
|
|
124
|
+
* @param name - Tool name
|
|
125
|
+
*/
|
|
126
|
+
unregister: (name: string) => void;
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
//# sourceMappingURL=abstract-client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"abstract-client.d.ts","sourceRoot":"","sources":["../src/abstract-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACjE,OAAO,EACL,UAAU,EAEV,YAAY,EACZ,eAAe,EACf,iBAAiB,EACjB,YAAY,EACZ,mBAAmB,EACnB,kBAAkB,EAClB,kBAAkB,EAClB,mBAAmB,EACnB,UAAU,EACV,MAAM,EACP,MAAM,SAAS,CAAC;AAEjB;;;GAGG;AACH,8BAAsB,cAAc;IAClC,SAAS,CAAC,MAAM,EAAE,YAAY,CAAC;IAC/B,SAAS,CAAC,WAAW,EAAE,MAAM,CAAC;IAC9B,SAAS,CAAC,QAAQ,EAAE,MAAM,CAAM;IAChC,SAAS,CAAC,eAAe,EAAE,GAAG,CAAC,MAAM,EAAE,mBAAmB,CAAC,CAAa;IAExE;;;OAGG;gBACS,MAAM,EAAE,YAAY;IAShC;;;OAGG;IACH,QAAQ,CAAC,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI;IAE5C;;;OAGG;IACH,SAAS,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC,EAC9B,GAAG,EAAE,MAAM,EACX,OAAO,CAAC,EAAE;QACR,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,IAAI,CAAC,EAAE,GAAG,CAAC;QACX,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;KAClC,GACA,OAAO,CAAC,CAAC,CAAC;IAEb;;;OAGG;IACH;;;;OAIG;IACH,SAAS,CAAC,wBAAwB,CAAC,OAAO,EAAE,UAAU,GAAG;QACvD,GAAG,EAAE,MAAM,CAAC;QACZ,MAAM,EAAE,MAAM,CAAC;QACf,IAAI,EAAE,GAAG,CAAC;KACX;IAmBD,SAAS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