@syntero/orca-cli 1.2.1 → 1.2.3
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/assistant/anthropic.d.ts +23 -0
- package/dist/assistant/anthropic.d.ts.map +1 -0
- package/dist/assistant/anthropic.js +186 -0
- package/dist/assistant/anthropic.js.map +1 -0
- package/dist/assistant/cache.d.ts +20 -0
- package/dist/assistant/cache.d.ts.map +1 -0
- package/dist/assistant/cache.js +55 -0
- package/dist/assistant/cache.js.map +1 -0
- package/dist/assistant/helpers.d.ts +10 -0
- package/dist/assistant/helpers.d.ts.map +1 -0
- package/dist/assistant/helpers.js +74 -0
- package/dist/assistant/helpers.js.map +1 -0
- package/dist/assistant/index.d.ts +13 -0
- package/dist/assistant/index.d.ts.map +1 -0
- package/dist/assistant/index.js +40 -0
- package/dist/assistant/index.js.map +1 -0
- package/dist/assistant/openai.d.ts +34 -0
- package/dist/assistant/openai.d.ts.map +1 -0
- package/dist/assistant/openai.js +303 -0
- package/dist/assistant/openai.js.map +1 -0
- package/dist/assistant/prompts.d.ts +11 -0
- package/dist/assistant/prompts.d.ts.map +1 -0
- package/dist/assistant/prompts.js +203 -0
- package/dist/assistant/prompts.js.map +1 -0
- package/dist/assistant/summarize.d.ts +32 -0
- package/dist/assistant/summarize.d.ts.map +1 -0
- package/dist/assistant/summarize.js +134 -0
- package/dist/assistant/summarize.js.map +1 -0
- package/dist/assistant/types.d.ts +62 -0
- package/dist/assistant/types.d.ts.map +1 -0
- package/dist/assistant/types.js +2 -0
- package/dist/assistant/types.js.map +1 -0
- package/dist/assistant.d.ts.map +1 -1
- package/dist/assistant.js +161 -383
- package/dist/assistant.js.map +1 -1
- package/dist/auth.d.ts +2 -1
- package/dist/auth.d.ts.map +1 -1
- package/dist/auth.js +6 -3
- package/dist/auth.js.map +1 -1
- package/dist/components/ChatApp.d.ts.map +1 -1
- package/dist/components/ChatApp.js +50 -339
- package/dist/components/ChatApp.js.map +1 -1
- package/dist/components/InputFooter.d.ts +23 -1
- package/dist/components/InputFooter.d.ts.map +1 -1
- package/dist/components/InputFooter.js +11 -8
- package/dist/components/InputFooter.js.map +1 -1
- package/dist/components/MultiSelectList.d.ts +25 -0
- package/dist/components/MultiSelectList.d.ts.map +1 -0
- package/dist/components/MultiSelectList.js +70 -0
- package/dist/components/MultiSelectList.js.map +1 -0
- package/dist/components/SyncMenu.d.ts +30 -6
- package/dist/components/SyncMenu.d.ts.map +1 -1
- package/dist/components/SyncMenu.js +383 -43
- package/dist/components/SyncMenu.js.map +1 -1
- package/dist/conversations/storage.d.ts +1 -1
- package/dist/conversations/storage.d.ts.map +1 -1
- package/dist/conversations/types.d.ts +1 -1
- package/dist/conversations/types.d.ts.map +1 -1
- package/dist/hooks/useConversationPersistence.d.ts +15 -0
- package/dist/hooks/useConversationPersistence.d.ts.map +1 -0
- package/dist/hooks/useConversationPersistence.js +86 -0
- package/dist/hooks/useConversationPersistence.js.map +1 -0
- package/dist/hooks/useInputDispatch.d.ts +11 -0
- package/dist/hooks/useInputDispatch.d.ts.map +1 -0
- package/dist/hooks/useInputDispatch.js +112 -0
- package/dist/hooks/useInputDispatch.js.map +1 -0
- package/dist/hooks/useSlashCommands.d.ts +21 -0
- package/dist/hooks/useSlashCommands.d.ts.map +1 -0
- package/dist/hooks/useSlashCommands.js +146 -0
- package/dist/hooks/useSlashCommands.js.map +1 -0
- package/dist/hooks/useSyncFetchers.d.ts +8 -0
- package/dist/hooks/useSyncFetchers.d.ts.map +1 -0
- package/dist/hooks/useSyncFetchers.js +103 -0
- package/dist/hooks/useSyncFetchers.js.map +1 -0
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/sync/download.d.ts +3 -3
- package/dist/sync/download.d.ts.map +1 -1
- package/dist/sync/download.js +16 -11
- package/dist/sync/download.js.map +1 -1
- package/dist/sync/sync-engine.d.ts.map +1 -1
- package/dist/sync/sync-engine.js +7 -4
- package/dist/sync/sync-engine.js.map +1 -1
- package/dist/tokens.d.ts +1 -1
- package/dist/tokens.d.ts.map +1 -1
- package/dist/types/sync.d.ts +2 -0
- package/dist/types/sync.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import Anthropic from '@anthropic-ai/sdk';
|
|
2
|
+
import { Settings } from '../settings.js';
|
|
3
|
+
import type { AnthropicMessage, ConfirmCommandCallback } from './types.js';
|
|
4
|
+
/**
|
|
5
|
+
* Run assistant with Anthropic API with streaming.
|
|
6
|
+
* @param getQueuedMessage - Optional callback to check for queued messages at each iteration
|
|
7
|
+
* @param confirmCommand - Optional callback to confirm dangerous commands
|
|
8
|
+
* @param approvedCategories - Set of command categories approved for the session
|
|
9
|
+
*/
|
|
10
|
+
export declare function runAssistantAnthropic(client: Anthropic, settings: Settings, userMessage: string, messages: AnthropicMessage[], signal?: AbortSignal, getQueuedMessage?: () => string | null, confirmCommand?: ConfirmCommandCallback, approvedCategories?: Set<string>): AsyncGenerator<string, AnthropicMessage[], void>;
|
|
11
|
+
/**
|
|
12
|
+
* Run assistant with Anthropic API without streaming.
|
|
13
|
+
* Fetches complete responses in a single request to eliminate screen jitter.
|
|
14
|
+
* @param getQueuedMessage - Optional callback to check for queued messages at each iteration
|
|
15
|
+
* @param confirmCommand - Optional callback to confirm dangerous commands
|
|
16
|
+
* @param approvedCategories - Set of command categories approved for the session
|
|
17
|
+
*/
|
|
18
|
+
export declare function runAssistantAnthropicNonStreaming(client: Anthropic, settings: Settings, userMessage: string, messages: AnthropicMessage[], signal?: AbortSignal, getQueuedMessage?: () => string | null, confirmCommand?: ConfirmCommandCallback, approvedCategories?: Set<string>): AsyncGenerator<string, AnthropicMessage[], void>;
|
|
19
|
+
/**
|
|
20
|
+
* Summarize a conversation using the Anthropic API.
|
|
21
|
+
*/
|
|
22
|
+
export declare function summarizeWithAnthropic(client: Anthropic, settings: Settings, conversationText: string): Promise<string>;
|
|
23
|
+
//# sourceMappingURL=anthropic.d.ts.map
|
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import { TOOLS_ANTHROPIC, } from '../tools.js';
|
|
2
|
+
import { SYSTEM_PROMPT, SUMMARIZATION_PROMPT } from './prompts.js';
|
|
3
|
+
import { addMessageCacheControl, addToolsCacheControl } from './cache.js';
|
|
4
|
+
import { executeToolCalls, injectQueuedMessage } from './helpers.js';
|
|
5
|
+
/**
|
|
6
|
+
* Run assistant with Anthropic API with streaming.
|
|
7
|
+
* @param getQueuedMessage - Optional callback to check for queued messages at each iteration
|
|
8
|
+
* @param confirmCommand - Optional callback to confirm dangerous commands
|
|
9
|
+
* @param approvedCategories - Set of command categories approved for the session
|
|
10
|
+
*/
|
|
11
|
+
export async function* runAssistantAnthropic(client, settings, userMessage, messages, signal, getQueuedMessage, confirmCommand, approvedCategories) {
|
|
12
|
+
messages.push({ role: 'user', content: userMessage });
|
|
13
|
+
while (true) {
|
|
14
|
+
// Check for queued messages at the start of each iteration
|
|
15
|
+
const queuedMessage = getQueuedMessage?.();
|
|
16
|
+
if (queuedMessage) {
|
|
17
|
+
yield* injectQueuedMessage(queuedMessage, messages);
|
|
18
|
+
}
|
|
19
|
+
let responseText = '';
|
|
20
|
+
const toolCalls = [];
|
|
21
|
+
// Anthropic prompt caching: Add cache_control markers to reduce token costs
|
|
22
|
+
const cachedSystem = [
|
|
23
|
+
{ type: 'text', text: SYSTEM_PROMPT, cache_control: { type: 'ephemeral' } },
|
|
24
|
+
];
|
|
25
|
+
const cachedTools = addToolsCacheControl(TOOLS_ANTHROPIC);
|
|
26
|
+
const cachedMessages = addMessageCacheControl(messages);
|
|
27
|
+
const stream = client.messages.stream({
|
|
28
|
+
model: settings.anthropic.model,
|
|
29
|
+
max_tokens: 8192,
|
|
30
|
+
system: cachedSystem,
|
|
31
|
+
tools: cachedTools,
|
|
32
|
+
messages: cachedMessages,
|
|
33
|
+
}, { signal });
|
|
34
|
+
for await (const event of stream) {
|
|
35
|
+
if (event.type === 'content_block_start') {
|
|
36
|
+
const contentBlock = event.content_block;
|
|
37
|
+
if (contentBlock?.type === 'tool_use') {
|
|
38
|
+
toolCalls.push({
|
|
39
|
+
id: contentBlock.id || '',
|
|
40
|
+
name: contentBlock.name || '',
|
|
41
|
+
input: '',
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
else if (event.type === 'content_block_delta') {
|
|
46
|
+
const delta = event.delta;
|
|
47
|
+
if (delta?.type === 'text_delta' && delta.text) {
|
|
48
|
+
yield delta.text;
|
|
49
|
+
responseText += delta.text;
|
|
50
|
+
}
|
|
51
|
+
else if (delta?.type === 'input_json_delta' && delta.partial_json && toolCalls.length > 0) {
|
|
52
|
+
toolCalls[toolCalls.length - 1].input += delta.partial_json;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
const finalMessage = await stream.finalMessage();
|
|
57
|
+
// Build assistant content
|
|
58
|
+
const assistantContent = [];
|
|
59
|
+
if (responseText) {
|
|
60
|
+
assistantContent.push({ type: 'text', text: responseText });
|
|
61
|
+
}
|
|
62
|
+
for (const tc of toolCalls) {
|
|
63
|
+
try {
|
|
64
|
+
tc.input = tc.input ? JSON.parse(tc.input) : {};
|
|
65
|
+
}
|
|
66
|
+
catch {
|
|
67
|
+
tc.input = {};
|
|
68
|
+
}
|
|
69
|
+
assistantContent.push({
|
|
70
|
+
type: 'tool_use',
|
|
71
|
+
id: tc.id,
|
|
72
|
+
name: tc.name,
|
|
73
|
+
input: tc.input,
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
messages.push({ role: 'assistant', content: assistantContent });
|
|
77
|
+
if (finalMessage.stop_reason === 'tool_use') {
|
|
78
|
+
const { anthropicResults } = yield* executeToolCalls(toolCalls, confirmCommand, approvedCategories);
|
|
79
|
+
messages.push({ role: 'user', content: anthropicResults });
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
break;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return messages;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Run assistant with Anthropic API without streaming.
|
|
89
|
+
* Fetches complete responses in a single request to eliminate screen jitter.
|
|
90
|
+
* @param getQueuedMessage - Optional callback to check for queued messages at each iteration
|
|
91
|
+
* @param confirmCommand - Optional callback to confirm dangerous commands
|
|
92
|
+
* @param approvedCategories - Set of command categories approved for the session
|
|
93
|
+
*/
|
|
94
|
+
export async function* runAssistantAnthropicNonStreaming(client, settings, userMessage, messages, signal, getQueuedMessage, confirmCommand, approvedCategories) {
|
|
95
|
+
messages.push({ role: 'user', content: userMessage });
|
|
96
|
+
while (true) {
|
|
97
|
+
// Check for queued messages at the start of each iteration
|
|
98
|
+
const queuedMessage = getQueuedMessage?.();
|
|
99
|
+
if (queuedMessage) {
|
|
100
|
+
yield* injectQueuedMessage(queuedMessage, messages);
|
|
101
|
+
}
|
|
102
|
+
// Anthropic prompt caching: Add cache_control markers to reduce token costs
|
|
103
|
+
const cachedSystem = [
|
|
104
|
+
{ type: 'text', text: SYSTEM_PROMPT, cache_control: { type: 'ephemeral' } },
|
|
105
|
+
];
|
|
106
|
+
const cachedTools = addToolsCacheControl(TOOLS_ANTHROPIC);
|
|
107
|
+
const cachedMessages = addMessageCacheControl(messages);
|
|
108
|
+
// Make non-streaming API call
|
|
109
|
+
const response = await client.messages.create({
|
|
110
|
+
model: settings.anthropic.model,
|
|
111
|
+
max_tokens: 8192,
|
|
112
|
+
system: cachedSystem,
|
|
113
|
+
tools: cachedTools,
|
|
114
|
+
messages: cachedMessages,
|
|
115
|
+
}, { signal });
|
|
116
|
+
// Extract text and tool calls from response
|
|
117
|
+
let responseText = '';
|
|
118
|
+
const toolCalls = [];
|
|
119
|
+
for (const block of response.content) {
|
|
120
|
+
if (block.type === 'text') {
|
|
121
|
+
responseText = block.text;
|
|
122
|
+
}
|
|
123
|
+
else if (block.type === 'tool_use') {
|
|
124
|
+
toolCalls.push({
|
|
125
|
+
id: block.id,
|
|
126
|
+
name: block.name,
|
|
127
|
+
input: block.input,
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
// Yield the complete response text at once
|
|
132
|
+
if (responseText) {
|
|
133
|
+
yield responseText;
|
|
134
|
+
}
|
|
135
|
+
// Build assistant content
|
|
136
|
+
const assistantContent = [];
|
|
137
|
+
if (responseText) {
|
|
138
|
+
assistantContent.push({ type: 'text', text: responseText });
|
|
139
|
+
}
|
|
140
|
+
for (const tc of toolCalls) {
|
|
141
|
+
assistantContent.push({
|
|
142
|
+
type: 'tool_use',
|
|
143
|
+
id: tc.id,
|
|
144
|
+
name: tc.name,
|
|
145
|
+
input: tc.input,
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
messages.push({ role: 'assistant', content: assistantContent });
|
|
149
|
+
if (response.stop_reason === 'tool_use') {
|
|
150
|
+
const { anthropicResults } = yield* executeToolCalls(toolCalls, confirmCommand, approvedCategories);
|
|
151
|
+
messages.push({ role: 'user', content: anthropicResults });
|
|
152
|
+
}
|
|
153
|
+
else {
|
|
154
|
+
break;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
return messages;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Summarize a conversation using the Anthropic API.
|
|
161
|
+
*/
|
|
162
|
+
export async function summarizeWithAnthropic(client, settings, conversationText) {
|
|
163
|
+
// Cache the system prompt for Anthropic (reduces token costs on repeated summarizations)
|
|
164
|
+
const cachedSystem = [
|
|
165
|
+
{ type: 'text', text: SUMMARIZATION_PROMPT, cache_control: { type: 'ephemeral' } },
|
|
166
|
+
];
|
|
167
|
+
const response = await client.messages.create({
|
|
168
|
+
model: settings.anthropic.model,
|
|
169
|
+
max_tokens: 2500,
|
|
170
|
+
system: cachedSystem,
|
|
171
|
+
messages: [
|
|
172
|
+
{
|
|
173
|
+
role: 'user',
|
|
174
|
+
content: `Please summarize the following deployment troubleshooting conversation:\n\n${conversationText}`,
|
|
175
|
+
},
|
|
176
|
+
],
|
|
177
|
+
});
|
|
178
|
+
// Extract text from response
|
|
179
|
+
for (const block of response.content) {
|
|
180
|
+
if (block.type === 'text') {
|
|
181
|
+
return block.text;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
return 'Unable to generate summary.';
|
|
185
|
+
}
|
|
186
|
+
//# sourceMappingURL=anthropic.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"anthropic.js","sourceRoot":"","sources":["../../src/assistant/anthropic.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,eAAe,GAChB,MAAM,aAAa,CAAC;AAOrB,OAAO,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AACnE,OAAO,EAAE,sBAAsB,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAC1E,OAAO,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAErE;;;;;GAKG;AACH,MAAM,CAAC,KAAK,SAAS,CAAC,CAAC,qBAAqB,CAC1C,MAAiB,EACjB,QAAkB,EAClB,WAAmB,EACnB,QAA4B,EAC5B,MAAoB,EACpB,gBAAsC,EACtC,cAAuC,EACvC,kBAAgC;IAEhC,QAAQ,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW,EAAE,CAAC,CAAC;IAEtD,OAAO,IAAI,EAAE,CAAC;QACZ,2DAA2D;QAC3D,MAAM,aAAa,GAAG,gBAAgB,EAAE,EAAE,CAAC;QAC3C,IAAI,aAAa,EAAE,CAAC;YAClB,KAAK,CAAC,CAAC,mBAAmB,CAAC,aAAa,EAAE,QAAQ,CAAC,CAAC;QACtD,CAAC;QAED,IAAI,YAAY,GAAG,EAAE,CAAC;QACtB,MAAM,SAAS,GAAmB,EAAE,CAAC;QAErC,4EAA4E;QAC5E,MAAM,YAAY,GAAG;YACnB,EAAE,IAAI,EAAE,MAAe,EAAE,IAAI,EAAE,aAAa,EAAE,aAAa,EAAE,EAAE,IAAI,EAAE,WAAoB,EAAE,EAAE;SAC9F,CA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AAE,OAAO,EAAE,gBAAgB,EAAE,CAAC,CAAC;QAC7D,CAAC;aAAM,CAAC;YACN,MAAM;QACR,CAAC;IACH,CAAC;IAED,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAC1C,MAAiB,EACjB,QAAkB,EAClB,gBAAwB;IAExB,yFAAyF;IACzF,MAAM,YAAY,GAAG;QACnB,EAAE,IAAI,EAAE,MAAe,EAAE,IAAI,EAAE,oBAAoB,EAAE,aAAa,EAAE,EAAE,IAAI,EAAE,WAAoB,EAAE,EAAE;KACrG,CAAC;IAEF,MAAM,QAAQ,GAAG,MAAM,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC;QAC5C,KAAK,EAAE,QAAQ,CAAC,SAAS,CAAC,KAAK;QAC/B,UAAU,EAAE,IAAI;QAChB,MAAM,EAAE,YAAY;QACpB,QAAQ,EAAE;YACR;gBACE,IAAI,EAAE,MAAM;gBACZ,OAAO,EAAE,8EAA8E,gBAAgB,EAAE;aAC1G;SACF;KACF,CAAC,CAAC;IAEH,6BAA6B;IAC7B,KAAK,MAAM,KAAK,IAAI,QAAQ,CAAC,OAAO,EAAE,CAAC;QACrC,IAAI,KAAK,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;YAC1B,OAAO,KAAK,CAAC,IAAI,CAAC;QACpB,CAAC;IACH,CAAC;IAED,OAAO,6BAA6B,CAAC;AACvC,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { AnthropicMessage } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Add cache_control to the last content block of the last message.
|
|
4
|
+
* This enables incremental conversation caching for Anthropic - each API call
|
|
5
|
+
* caches the conversation history up to the last message, so subsequent calls
|
|
6
|
+
* can read the cached prefix instead of re-processing it.
|
|
7
|
+
*
|
|
8
|
+
* @param messages - List of conversation messages
|
|
9
|
+
* @returns Deep copy of messages with cache_control added to last content block
|
|
10
|
+
*/
|
|
11
|
+
export declare function addMessageCacheControl(messages: AnthropicMessage[]): AnthropicMessage[];
|
|
12
|
+
/**
|
|
13
|
+
* Add cache_control to the last tool definition.
|
|
14
|
+
* This allows Anthropic to cache the entire tool definitions array.
|
|
15
|
+
*
|
|
16
|
+
* @param tools - Array of tool definitions
|
|
17
|
+
* @returns Copy of tools with cache_control on the last tool
|
|
18
|
+
*/
|
|
19
|
+
export declare function addToolsCacheControl<T extends object>(tools: T[]): T[];
|
|
20
|
+
//# sourceMappingURL=cache.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["../../src/assistant/cache.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAyB,MAAM,YAAY,CAAC;AAE1E;;;;;;;;GAQG;AACH,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,gBAAgB,EAAE,GAAG,gBAAgB,EAAE,CA6BvF;AAED;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAAC,CAAC,SAAS,MAAM,EAAE,KAAK,EAAE,CAAC,EAAE,GAAG,CAAC,EAAE,CAatE"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Add cache_control to the last content block of the last message.
|
|
3
|
+
* This enables incremental conversation caching for Anthropic - each API call
|
|
4
|
+
* caches the conversation history up to the last message, so subsequent calls
|
|
5
|
+
* can read the cached prefix instead of re-processing it.
|
|
6
|
+
*
|
|
7
|
+
* @param messages - List of conversation messages
|
|
8
|
+
* @returns Deep copy of messages with cache_control added to last content block
|
|
9
|
+
*/
|
|
10
|
+
export function addMessageCacheControl(messages) {
|
|
11
|
+
if (messages.length === 0) {
|
|
12
|
+
return messages;
|
|
13
|
+
}
|
|
14
|
+
// Deep copy to avoid mutating the original
|
|
15
|
+
const messagesCopy = JSON.parse(JSON.stringify(messages));
|
|
16
|
+
// Get the last message
|
|
17
|
+
const lastMessage = messagesCopy[messagesCopy.length - 1];
|
|
18
|
+
const content = lastMessage.content;
|
|
19
|
+
if (content === undefined || content === null) {
|
|
20
|
+
return messagesCopy;
|
|
21
|
+
}
|
|
22
|
+
// Content can be a string or a list of content blocks
|
|
23
|
+
if (typeof content === 'string') {
|
|
24
|
+
// Convert string to content block format with cache_control
|
|
25
|
+
lastMessage.content = [
|
|
26
|
+
{ type: 'text', text: content, cache_control: { type: 'ephemeral' } },
|
|
27
|
+
];
|
|
28
|
+
}
|
|
29
|
+
else if (Array.isArray(content) && content.length > 0) {
|
|
30
|
+
// Add cache_control to the last content block
|
|
31
|
+
const lastBlock = content[content.length - 1];
|
|
32
|
+
lastBlock.cache_control = { type: 'ephemeral' };
|
|
33
|
+
}
|
|
34
|
+
return messagesCopy;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Add cache_control to the last tool definition.
|
|
38
|
+
* This allows Anthropic to cache the entire tool definitions array.
|
|
39
|
+
*
|
|
40
|
+
* @param tools - Array of tool definitions
|
|
41
|
+
* @returns Copy of tools with cache_control on the last tool
|
|
42
|
+
*/
|
|
43
|
+
export function addToolsCacheControl(tools) {
|
|
44
|
+
if (tools.length === 0) {
|
|
45
|
+
return tools;
|
|
46
|
+
}
|
|
47
|
+
// Shallow copy the array, deep copy only the last tool
|
|
48
|
+
const toolsCopy = [...tools];
|
|
49
|
+
toolsCopy[toolsCopy.length - 1] = {
|
|
50
|
+
...toolsCopy[toolsCopy.length - 1],
|
|
51
|
+
cache_control: { type: 'ephemeral' },
|
|
52
|
+
};
|
|
53
|
+
return toolsCopy;
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=cache.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache.js","sourceRoot":"","sources":["../../src/assistant/cache.ts"],"names":[],"mappings":"AAEA;;;;;;;;GAQG;AACH,MAAM,UAAU,sBAAsB,CAAC,QAA4B;IACjE,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;Q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G,SAAS,CAAC,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC;QAClC,aAAa,EAAE,EAAE,IAAI,EAAE,WAAW,EAAE;KACrC,CAAC;IAEF,OAAO,SAAS,CAAC;AACnB,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ToolCallInfo, ToolExecutionResult, ConfirmCommandCallback, AnthropicMessage, OpenAIMessage } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Execute tool calls: display headers, check dangerous commands, run tools, collect results.
|
|
4
|
+
*/
|
|
5
|
+
export declare function executeToolCalls(toolCalls: ToolCallInfo[], confirmCommand?: ConfirmCommandCallback, approvedCategories?: Set<string>): AsyncGenerator<string, ToolExecutionResult, void>;
|
|
6
|
+
/**
|
|
7
|
+
* Inject a queued user message into conversation history.
|
|
8
|
+
*/
|
|
9
|
+
export declare function injectQueuedMessage(msg: string, messages: AnthropicMessage[], openaiMessages?: OpenAIMessage[]): Generator<string>;
|
|
10
|
+
//# sourceMappingURL=helpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../src/assistant/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,YAAY,EACZ,mBAAmB,EAEnB,sBAAsB,EACtB,gBAAgB,EAChB,aAAa,EACd,MAAM,YAAY,CAAC;AAQpB;;GAEG;AACH,wBAAuB,gBAAgB,CACrC,SAAS,EAAE,YAAY,EAAE,EACzB,cAAc,CAAC,EAAE,sBAAsB,EACvC,kBAAkB,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,GAC/B,cAAc,CAAC,MAAM,EAAE,mBAAmB,EAAE,IAAI,CAAC,CA4DnD;AAED;;GAEG;AACH,wBAAiB,mBAAmB,CAClC,GAAG,EAAE,MAAM,EACX,QAAQ,EAAE,gBAAgB,EAAE,EAC5B,cAAc,CAAC,EAAE,aAAa,EAAE,GAC/B,SAAS,CAAC,MAAM,CAAC,CAOnB"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { handleToolCall, checkCommand, allCategoriesApproved, } from '../tools.js';
|
|
2
|
+
import { Colors, color } from '../utils.js';
|
|
3
|
+
/**
|
|
4
|
+
* Execute tool calls: display headers, check dangerous commands, run tools, collect results.
|
|
5
|
+
*/
|
|
6
|
+
export async function* executeToolCalls(toolCalls, confirmCommand, approvedCategories) {
|
|
7
|
+
const anthropicResults = [];
|
|
8
|
+
const openaiResults = [];
|
|
9
|
+
for (const tc of toolCalls) {
|
|
10
|
+
const input = tc.input;
|
|
11
|
+
// Show tool header
|
|
12
|
+
if (tc.name === 'run_command') {
|
|
13
|
+
yield color(`\n\n[${tc.name}] `, Colors.dim);
|
|
14
|
+
yield color(`${input.command}\n`, Colors.cyan);
|
|
15
|
+
if (input.gist) {
|
|
16
|
+
yield color(`${input.gist}\n`, Colors.dim);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
yield color(`\n\n[${tc.name}]\n`, Colors.dim);
|
|
21
|
+
}
|
|
22
|
+
let result;
|
|
23
|
+
if (tc.name === 'run_command' && confirmCommand) {
|
|
24
|
+
const command = input.command;
|
|
25
|
+
const gist = input.gist;
|
|
26
|
+
const dangerCheck = checkCommand(command);
|
|
27
|
+
if (dangerCheck.isDangerous && !allCategoriesApproved(dangerCheck, approvedCategories || new Set())) {
|
|
28
|
+
yield color(`Dangerous command detected. Waiting for confirmation...\n`, Colors.yellow);
|
|
29
|
+
const confirmResult = await confirmCommand(command, dangerCheck, gist);
|
|
30
|
+
if (!confirmResult.confirmed) {
|
|
31
|
+
result = 'Command cancelled by user.';
|
|
32
|
+
yield color(`${result}\n`, Colors.dim);
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
result = await handleToolCall(tc.name, tc.input);
|
|
36
|
+
const preview = result.length > 500 ? result.slice(0, 500) + '...' : result;
|
|
37
|
+
yield color(`${preview}\n`, Colors.dim);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
result = await handleToolCall(tc.name, tc.input);
|
|
42
|
+
const preview = result.length > 500 ? result.slice(0, 500) + '...' : result;
|
|
43
|
+
yield color(`${preview}\n`, Colors.dim);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
result = await handleToolCall(tc.name, tc.input);
|
|
48
|
+
const preview = result.length > 500 ? result.slice(0, 500) + '...' : result;
|
|
49
|
+
yield color(`${preview}\n`, Colors.dim);
|
|
50
|
+
}
|
|
51
|
+
anthropicResults.push({
|
|
52
|
+
type: 'tool_result',
|
|
53
|
+
tool_use_id: tc.id,
|
|
54
|
+
content: result,
|
|
55
|
+
});
|
|
56
|
+
openaiResults.push({
|
|
57
|
+
tool_call_id: tc.id,
|
|
58
|
+
content: result,
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
return { anthropicResults, openaiResults };
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Inject a queued user message into conversation history.
|
|
65
|
+
*/
|
|
66
|
+
export function* injectQueuedMessage(msg, messages, openaiMessages) {
|
|
67
|
+
const injectedContent = `[User update while AI was working]: ${msg}`;
|
|
68
|
+
messages.push({ role: 'user', content: injectedContent });
|
|
69
|
+
if (openaiMessages) {
|
|
70
|
+
openaiMessages.push({ role: 'user', content: injectedContent });
|
|
71
|
+
}
|
|
72
|
+
yield color(`\n[Queued message injected: "${msg.length > 50 ? msg.slice(0, 50) + '...' : msg}"]\n`, Colors.dim);
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../src/assistant/helpers.ts"],"names":[],"mappings":"AAQA,OAAO,EACL,cAAc,EACd,YAAY,EACZ,qBAAqB,GACtB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAE5C;;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CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC;YAC5E,MAAM,KAAK,CAAC,GAAG,OAAO,IAAI,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC;QAC1C,CAAC;QAED,gBAAgB,CAAC,IAAI,CAAC;YACpB,IAAI,EAAE,aAAa;YACnB,WAAW,EAAE,EAAE,CAAC,EAAE;YAClB,OAAO,EAAE,MAAM;SAChB,CAAC,CAAC;QACH,aAAa,CAAC,IAAI,CAAC;YACjB,YAAY,EAAE,EAAE,CAAC,EAAE;YACnB,OAAO,EAAE,MAAM;SAChB,CAAC,CAAC;IACL,CAAC;IAED,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE,CAAC;AAC7C,CAAC;AAED;;GAEG;AACH,MAAM,SAAS,CAAC,CAAC,mBAAmB,CAClC,GAAW,EACX,QAA4B,EAC5B,cAAgC;IAEhC,MAAM,eAAe,GAAG,uCAAuC,GAAG,EAAE,CAAC;IACrE,QAAQ,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,eAAe,EAAE,CAAC,CAAC;IAC1D,IAAI,cAAc,EAAE,CAAC;QACnB,cAAc,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,eAAe,EAAE,CAAC,CAAC;IAClE,CAAC;IACD,MAAM,KAAK,CAAC,gCAAgC,GAAG,CAAC,MAAM,GAAG,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,GAAG,MAAM,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC;AAClH,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Settings } from '../settings.js';
|
|
2
|
+
import type { LLMClient } from '../providers.js';
|
|
3
|
+
import type { AnthropicMessage, ConfirmCommandCallback } from './types.js';
|
|
4
|
+
/**
|
|
5
|
+
* Run the assistant with the appropriate provider.
|
|
6
|
+
* @param getQueuedMessage - Optional callback to check for queued messages at each iteration
|
|
7
|
+
* @param confirmCommand - Optional callback to confirm dangerous commands
|
|
8
|
+
* @param approvedCategories - Set of command categories approved for the session
|
|
9
|
+
*/
|
|
10
|
+
export declare function runAssistant(client: LLMClient, settings: Settings, userMessage: string, messages?: AnthropicMessage[], signal?: AbortSignal, getQueuedMessage?: () => string | null, confirmCommand?: ConfirmCommandCallback, approvedCategories?: Set<string>): AsyncGenerator<string, AnthropicMessage[], void>;
|
|
11
|
+
export type { AnthropicMessage, CommandConfirmResult, ConfirmCommandCallback } from './types.js';
|
|
12
|
+
export { summarizeConversation, generateAITitle } from './summarize.js';
|
|
13
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/assistant/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAY,MAAM,gBAAgB,CAAC;AACpD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,KAAK,EAAE,gBAAgB,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AAI3E;;;;;GAKG;AACH,wBAAuB,YAAY,CACjC,MAAM,EAAE,SAAS,EACjB,QAAQ,EAAE,QAAQ,EAClB,WAAW,EAAE,MAAM,EACnB,QAAQ,GAAE,gBAAgB,EAAO,EACjC,MAAM,CAAC,EAAE,WAAW,EACpB,gBAAgB,CAAC,EAAE,MAAM,MAAM,GAAG,IAAI,EACtC,cAAc,CAAC,EAAE,sBAAsB,EACvC,kBAAkB,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,GAC/B,cAAc,CAAC,MAAM,EAAE,gBAAgB,EAAE,EAAE,IAAI,CAAC,CA2ClD;AAGD,YAAY,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AACjG,OAAO,EAAE,qBAAqB,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { Provider } from '../settings.js';
|
|
2
|
+
import { runAssistantAnthropic, runAssistantAnthropicNonStreaming } from './anthropic.js';
|
|
3
|
+
import { runAssistantOpenAI, runAssistantOpenAINonStreaming } from './openai.js';
|
|
4
|
+
/**
|
|
5
|
+
* Run the assistant with the appropriate provider.
|
|
6
|
+
* @param getQueuedMessage - Optional callback to check for queued messages at each iteration
|
|
7
|
+
* @param confirmCommand - Optional callback to confirm dangerous commands
|
|
8
|
+
* @param approvedCategories - Set of command categories approved for the session
|
|
9
|
+
*/
|
|
10
|
+
export async function* runAssistant(client, settings, userMessage, messages = [], signal, getQueuedMessage, confirmCommand, approvedCategories) {
|
|
11
|
+
// Choose streaming or non-streaming based on settings
|
|
12
|
+
const useStreaming = settings.streaming !== false; // Default to true
|
|
13
|
+
if (settings.provider === Provider.ANTHROPIC) {
|
|
14
|
+
if (useStreaming) {
|
|
15
|
+
return yield* runAssistantAnthropic(client, settings, userMessage, messages, signal, getQueuedMessage, confirmCommand, approvedCategories);
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
return yield* runAssistantAnthropicNonStreaming(client, settings, userMessage, messages, signal, getQueuedMessage, confirmCommand, approvedCategories);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
else if (settings.provider === Provider.OPENAI) {
|
|
22
|
+
if (useStreaming) {
|
|
23
|
+
return yield* runAssistantOpenAI(client, settings, userMessage, messages, false, signal, getQueuedMessage, confirmCommand, approvedCategories);
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
return yield* runAssistantOpenAINonStreaming(client, settings, userMessage, messages, false, signal, getQueuedMessage, confirmCommand, approvedCategories);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
else if (settings.provider === Provider.AZURE) {
|
|
30
|
+
if (useStreaming) {
|
|
31
|
+
return yield* runAssistantOpenAI(client, settings, userMessage, messages, true, signal, getQueuedMessage, confirmCommand, approvedCategories);
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
return yield* runAssistantOpenAINonStreaming(client, settings, userMessage, messages, true, signal, getQueuedMessage, confirmCommand, approvedCategories);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
throw new Error(`Unknown provider: ${settings.provider}`);
|
|
38
|
+
}
|
|
39
|
+
export { summarizeConversation, generateAITitle } from './summarize.js';
|
|
40
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/assistant/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAY,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAGpD,OAAO,EAAE,qBAAqB,EAAE,iCAAiC,EAAE,MAAM,gBAAgB,CAAC;AAC1F,OAAO,EAAE,kBAAkB,EAAE,8BAA8B,EAAE,MAAM,aAAa,CAAC;AAEjF;;;;;GAKG;AACH,MAAM,CAAC,KAAK,SAAS,CAAC,CAAC,YAAY,CACjC,MAAiB,EACjB,QAAkB,EAClB,WAAmB,EACnB,WAA+B,EAAE,EACjC,MAAoB,EACpB,gBAAsC,EACtC,cAAuC,EACvC,kBAAgC;IAEhC,sDAAsD;IACtD,MAAM,YAAY,GAAG,QAAQ,CAAC,SAAS,KAAK,KAAK,CAAC,CAAE,kBAAkB;IAEtE,IAAI,QAAQ,CAAC,QAAQ,KAAK,QAAQ,CAAC,SAAS,EAAE,CAAC;QAC7C,IAAI,YAAY,EAAE,CAAC;YACjB,OAAO,KAAK,CAAC,CAAC,qBAAqB,CACjC,MAAmB,EAAE,QAAQ,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,EAC5D,gBAAgB,EAAE,cAAc,EAAE,kBAAkB,CACrD,CAAC;QACJ,CAAC;aAAM,CAAC;YACN,OAAO,KAAK,CAAC,CAAC,iCAAiC,CAC7C,MAAmB,EAAE,QAAQ,EAAE,WAA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@@ -0,0 +1,34 @@
|
|
|
1
|
+
import OpenAI from 'openai';
|
|
2
|
+
import { Settings } from '../settings.js';
|
|
3
|
+
import type { AnthropicMessage, OpenAIMessage, ConfirmCommandCallback } from './types.js';
|
|
4
|
+
/**
|
|
5
|
+
* Resolve the OpenAI/Azure model name and registry ID.
|
|
6
|
+
*/
|
|
7
|
+
export declare function resolveOpenAIModel(settings: Settings, isAzure: boolean): {
|
|
8
|
+
model: string;
|
|
9
|
+
modelIdForRegistry: string;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Convert Anthropic message history to OpenAI message format.
|
|
13
|
+
*/
|
|
14
|
+
export declare function convertMessagesToOpenAI(messages: AnthropicMessage[]): OpenAIMessage[];
|
|
15
|
+
/**
|
|
16
|
+
* Run assistant with OpenAI/Azure API with streaming.
|
|
17
|
+
* @param getQueuedMessage - Optional callback to check for queued messages at each iteration
|
|
18
|
+
* @param confirmCommand - Optional callback to confirm dangerous commands
|
|
19
|
+
* @param approvedCategories - Set of command categories approved for the session
|
|
20
|
+
*/
|
|
21
|
+
export declare function runAssistantOpenAI(client: OpenAI, settings: Settings, userMessage: string, messages: AnthropicMessage[], isAzure?: boolean, signal?: AbortSignal, getQueuedMessage?: () => string | null, confirmCommand?: ConfirmCommandCallback, approvedCategories?: Set<string>): AsyncGenerator<string, AnthropicMessage[], void>;
|
|
22
|
+
/**
|
|
23
|
+
* Run assistant with OpenAI/Azure API without streaming.
|
|
24
|
+
* Fetches complete responses in a single request to eliminate screen jitter.
|
|
25
|
+
* @param getQueuedMessage - Optional callback to check for queued messages at each iteration
|
|
26
|
+
* @param confirmCommand - Optional callback to confirm dangerous commands
|
|
27
|
+
* @param approvedCategories - Set of command categories approved for the session
|
|
28
|
+
*/
|
|
29
|
+
export declare function runAssistantOpenAINonStreaming(client: OpenAI, settings: Settings, userMessage: string, messages: AnthropicMessage[], isAzure?: boolean, signal?: AbortSignal, getQueuedMessage?: () => string | null, confirmCommand?: ConfirmCommandCallback, approvedCategories?: Set<string>): AsyncGenerator<string, AnthropicMessage[], void>;
|
|
30
|
+
/**
|
|
31
|
+
* Summarize a conversation using the OpenAI/Azure API.
|
|
32
|
+
*/
|
|
33
|
+
export declare function summarizeWithOpenAI(client: OpenAI, settings: Settings, conversationText: string, isAzure: boolean): Promise<string>;
|
|
34
|
+
//# sourceMappingURL=openai.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openai.d.ts","sourceRoot":"","sources":["../../src/assistant/openai.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAO1C,OAAO,KAAK,EACV,gBAAgB,EAEhB,aAAa,EAGb,sBAAsB,EACvB,MAAM,YAAY,CAAC;AAIpB;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,GAAG;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,kBAAkB,EAAE,MAAM,CAAA;CAAE,CAUtH;AAED;;GAEG;AACH,wBAAgB,uBAAuB,CAAC,QAAQ,EAAE,gBAAgB,EAAE,GAAG,aAAa,EAAE,CAmDrF;AAED;;;;;GAKG;AACH,wBAAuB,kBAAkB,CACvC,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,QAAQ,EAClB,WAAW,EAAE,MAAM,EACnB,QAAQ,EAAE,gBAAgB,EAAE,EAC5B,OAAO,UAAQ,EACf,MAAM,CAAC,EAAE,WAAW,EACpB,gBAAgB,CAAC,EAAE,MAAM,MAAM,GAAG,IAAI,EACtC,cAAc,CAAC,EAAE,sBAAsB,EACvC,kBAAkB,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,GAC/B,cAAc,CAAC,MAAM,EAAE,gBAAgB,EAAE,EAAE,IAAI,CAAC,CAwHlD;AAED;;;;;;GAMG;AACH,wBAAuB,8BAA8B,CACnD,MAAM,EAAE,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