@kirosnn/mosaic 0.0.91 → 0.73.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/LICENSE +1 -1
- package/README.md +2 -6
- package/package.json +55 -48
- package/src/agent/Agent.ts +353 -131
- package/src/agent/context.ts +4 -4
- package/src/agent/prompts/systemPrompt.ts +209 -70
- package/src/agent/prompts/toolsPrompt.ts +285 -138
- package/src/agent/provider/anthropic.ts +109 -105
- package/src/agent/provider/google.ts +111 -107
- package/src/agent/provider/mistral.ts +95 -95
- package/src/agent/provider/ollama.ts +73 -17
- package/src/agent/provider/openai.ts +146 -102
- package/src/agent/provider/rateLimit.ts +178 -0
- package/src/agent/provider/reasoning.ts +29 -0
- package/src/agent/provider/xai.ts +108 -104
- package/src/agent/tools/definitions.ts +15 -1
- package/src/agent/tools/executor.ts +717 -98
- package/src/agent/tools/exploreExecutor.ts +20 -22
- package/src/agent/tools/fetch.ts +58 -0
- package/src/agent/tools/glob.ts +20 -4
- package/src/agent/tools/grep.ts +64 -9
- package/src/agent/tools/plan.ts +27 -0
- package/src/agent/tools/question.ts +7 -1
- package/src/agent/tools/read.ts +2 -0
- package/src/agent/types.ts +15 -14
- package/src/components/App.tsx +50 -8
- package/src/components/CustomInput.tsx +461 -77
- package/src/components/Main.tsx +1459 -1112
- package/src/components/Setup.tsx +1 -1
- package/src/components/ShortcutsModal.tsx +11 -8
- package/src/components/Welcome.tsx +1 -1
- package/src/components/main/ApprovalPanel.tsx +4 -3
- package/src/components/main/ChatPage.tsx +858 -516
- package/src/components/main/HomePage.tsx +58 -39
- package/src/components/main/QuestionPanel.tsx +52 -7
- package/src/components/main/ThinkingIndicator.tsx +13 -2
- package/src/components/main/types.ts +11 -10
- package/src/index.tsx +53 -25
- package/src/mcp/approvalPolicy.ts +148 -0
- package/src/mcp/cli/add.ts +185 -0
- package/src/mcp/cli/doctor.ts +77 -0
- package/src/mcp/cli/index.ts +85 -0
- package/src/mcp/cli/list.ts +50 -0
- package/src/mcp/cli/logs.ts +24 -0
- package/src/mcp/cli/manage.ts +99 -0
- package/src/mcp/cli/show.ts +53 -0
- package/src/mcp/cli/tools.ts +77 -0
- package/src/mcp/config.ts +223 -0
- package/src/mcp/index.ts +80 -0
- package/src/mcp/processManager.ts +299 -0
- package/src/mcp/rateLimiter.ts +50 -0
- package/src/mcp/registry.ts +151 -0
- package/src/mcp/schemaConverter.ts +100 -0
- package/src/mcp/servers/navigation.ts +854 -0
- package/src/mcp/toolCatalog.ts +169 -0
- package/src/mcp/types.ts +95 -0
- package/src/utils/approvalBridge.ts +45 -12
- package/src/utils/approvalModeBridge.ts +17 -0
- package/src/utils/commands/approvals.ts +48 -0
- package/src/utils/commands/compact.ts +30 -0
- package/src/utils/commands/echo.ts +1 -1
- package/src/utils/commands/image.ts +109 -0
- package/src/utils/commands/index.ts +9 -7
- package/src/utils/commands/new.ts +15 -0
- package/src/utils/commands/types.ts +3 -0
- package/src/utils/config.ts +3 -1
- package/src/utils/diffRendering.tsx +13 -16
- package/src/utils/exploreBridge.ts +10 -0
- package/src/utils/history.ts +82 -40
- package/src/utils/imageBridge.ts +28 -0
- package/src/utils/images.ts +31 -0
- package/src/utils/markdown.tsx +163 -99
- package/src/utils/models.ts +31 -16
- package/src/utils/notificationBridge.ts +23 -0
- package/src/utils/questionBridge.ts +36 -1
- package/src/utils/tokenEstimator.ts +32 -0
- package/src/utils/toolFormatting.ts +428 -48
- package/src/web/app.tsx +65 -5
- package/src/web/assets/css/ChatPage.css +102 -30
- package/src/web/assets/css/MessageItem.css +26 -29
- package/src/web/assets/css/ThinkingIndicator.css +44 -6
- package/src/web/assets/css/ToolMessage.css +36 -14
- package/src/web/components/ChatPage.tsx +228 -105
- package/src/web/components/HomePage.tsx +3 -3
- package/src/web/components/MessageItem.tsx +80 -81
- package/src/web/components/QuestionPanel.tsx +72 -12
- package/src/web/components/Setup.tsx +1 -1
- package/src/web/components/Sidebar.tsx +1 -3
- package/src/web/components/ThinkingIndicator.tsx +41 -21
- package/src/web/router.ts +1 -1
- package/src/web/server.tsx +894 -662
- package/src/web/storage.ts +23 -1
- package/src/web/types.ts +7 -6
- package/src/utils/commands/redo.ts +0 -74
- package/src/utils/commands/sessions.ts +0 -129
- package/src/utils/commands/undo.ts +0 -75
- package/src/utils/undoRedo.ts +0 -429
- package/src/utils/undoRedoBridge.ts +0 -45
- package/src/utils/undoRedoDb.ts +0 -338
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import { streamText, CoreMessage } from 'ai';
|
|
2
|
-
import { createAnthropic } from '@ai-sdk/anthropic';
|
|
3
|
-
import { AgentEvent, Provider, ProviderConfig, ProviderSendOptions } from '../types';
|
|
1
|
+
import { streamText, CoreMessage } from 'ai';
|
|
2
|
+
import { createAnthropic } from '@ai-sdk/anthropic';
|
|
3
|
+
import { AgentEvent, Provider, ProviderConfig, ProviderSendOptions } from '../types';
|
|
4
|
+
import { shouldEnableReasoning } from './reasoning';
|
|
5
|
+
import { getRetryDecision, normalizeError, runWithRetry } from './rateLimit';
|
|
4
6
|
|
|
5
7
|
export class AnthropicProvider implements Provider {
|
|
6
8
|
async *sendMessage(
|
|
@@ -8,115 +10,117 @@ export class AnthropicProvider implements Provider {
|
|
|
8
10
|
config: ProviderConfig,
|
|
9
11
|
options?: ProviderSendOptions
|
|
10
12
|
): AsyncGenerator<AgentEvent> {
|
|
11
|
-
const cleanApiKey = config.apiKey?.trim().replace(/[\r\n]+/g, '');
|
|
12
|
-
const cleanModel = config.model.trim().replace(/[\r\n]+/g, '');
|
|
13
|
+
const cleanApiKey = config.apiKey?.trim().replace(/[\r\n]+/g, '');
|
|
14
|
+
const cleanModel = config.model.trim().replace(/[\r\n]+/g, '');
|
|
15
|
+
const reasoningEnabled = await shouldEnableReasoning(config.provider, cleanModel);
|
|
13
16
|
|
|
14
17
|
const anthropic = createAnthropic({
|
|
15
18
|
apiKey: cleanApiKey,
|
|
16
19
|
});
|
|
17
20
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
21
|
+
try {
|
|
22
|
+
let stepCounter = 0;
|
|
23
|
+
|
|
24
|
+
yield* runWithRetry(async function* () {
|
|
25
|
+
const result = streamText({
|
|
26
|
+
model: anthropic(cleanModel),
|
|
27
|
+
messages: messages,
|
|
28
|
+
system: config.systemPrompt,
|
|
29
|
+
tools: config.tools,
|
|
30
|
+
maxSteps: config.maxSteps || 100,
|
|
31
|
+
abortSignal: options?.abortSignal,
|
|
32
|
+
experimental_providerMetadata: reasoningEnabled
|
|
33
|
+
? {
|
|
34
|
+
anthropic: {
|
|
35
|
+
thinkingBudgetTokens: 10000,
|
|
36
|
+
},
|
|
37
|
+
}
|
|
38
|
+
: undefined,
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
for await (const chunk of result.fullStream as any) {
|
|
42
|
+
const c: any = chunk;
|
|
43
|
+
switch (c.type) {
|
|
44
|
+
case 'reasoning':
|
|
45
|
+
if (c.textDelta) {
|
|
46
|
+
yield {
|
|
47
|
+
type: 'reasoning-delta',
|
|
48
|
+
content: c.textDelta,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
break;
|
|
52
|
+
|
|
53
|
+
case 'text-delta':
|
|
54
|
+
yield {
|
|
55
|
+
type: 'text-delta',
|
|
56
|
+
content: c.textDelta,
|
|
57
|
+
};
|
|
58
|
+
break;
|
|
59
|
+
|
|
60
|
+
case 'step-start':
|
|
61
|
+
yield {
|
|
62
|
+
type: 'step-start',
|
|
63
|
+
stepNumber: typeof c.stepIndex === 'number' ? c.stepIndex : stepCounter,
|
|
64
|
+
};
|
|
65
|
+
stepCounter++;
|
|
66
|
+
break;
|
|
67
|
+
|
|
68
|
+
case 'step-finish':
|
|
69
|
+
yield {
|
|
70
|
+
type: 'step-finish',
|
|
71
|
+
stepNumber:
|
|
72
|
+
typeof c.stepIndex === 'number' ? c.stepIndex : Math.max(0, stepCounter - 1),
|
|
73
|
+
finishReason: String(c.finishReason ?? 'stop'),
|
|
74
|
+
};
|
|
75
|
+
break;
|
|
76
|
+
|
|
77
|
+
case 'tool-call':
|
|
78
|
+
yield {
|
|
79
|
+
type: 'tool-call-end',
|
|
80
|
+
toolCallId: String(c.toolCallId ?? ''),
|
|
81
|
+
toolName: String(c.toolName ?? ''),
|
|
82
|
+
args: (c.args ?? {}) as Record<string, unknown>,
|
|
83
|
+
};
|
|
84
|
+
break;
|
|
85
|
+
|
|
86
|
+
case 'tool-result':
|
|
87
|
+
yield {
|
|
88
|
+
type: 'tool-result',
|
|
89
|
+
toolCallId: String(c.toolCallId ?? ''),
|
|
90
|
+
toolName: String(c.toolName ?? ''),
|
|
91
|
+
result: c.result,
|
|
92
|
+
};
|
|
93
|
+
break;
|
|
94
|
+
|
|
95
|
+
case 'finish':
|
|
96
|
+
yield {
|
|
97
|
+
type: 'finish',
|
|
98
|
+
finishReason: String(c.finishReason ?? 'stop'),
|
|
99
|
+
usage: c.usage,
|
|
100
|
+
};
|
|
101
|
+
break;
|
|
102
|
+
|
|
103
|
+
case 'error': {
|
|
104
|
+
const err = normalizeError(c.error);
|
|
105
|
+
const decision = getRetryDecision(err);
|
|
106
|
+
if (decision.shouldRetry) {
|
|
107
|
+
throw err;
|
|
108
|
+
}
|
|
109
|
+
yield {
|
|
110
|
+
type: 'error',
|
|
111
|
+
error: err.message,
|
|
112
|
+
};
|
|
113
|
+
break;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}, { abortSignal: options?.abortSignal });
|
|
118
|
+
} catch (error) {
|
|
119
|
+
if (options?.abortSignal?.aborted) return;
|
|
120
|
+
yield {
|
|
117
121
|
type: 'error',
|
|
118
122
|
error: error instanceof Error ? error.message : 'Unknown error occurred',
|
|
119
123
|
};
|
|
120
124
|
}
|
|
121
125
|
}
|
|
122
|
-
}
|
|
126
|
+
}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import { streamText, CoreMessage } from 'ai';
|
|
2
|
-
import { createGoogleGenerativeAI } from '@ai-sdk/google';
|
|
3
|
-
import { AgentEvent, Provider, ProviderConfig, ProviderSendOptions } from '../types';
|
|
1
|
+
import { streamText, CoreMessage } from 'ai';
|
|
2
|
+
import { createGoogleGenerativeAI } from '@ai-sdk/google';
|
|
3
|
+
import { AgentEvent, Provider, ProviderConfig, ProviderSendOptions } from '../types';
|
|
4
|
+
import { shouldEnableReasoning } from './reasoning';
|
|
5
|
+
import { getRetryDecision, normalizeError, runWithRetry } from './rateLimit';
|
|
4
6
|
|
|
5
7
|
export class GoogleProvider implements Provider {
|
|
6
8
|
async *sendMessage(
|
|
@@ -8,117 +10,119 @@ export class GoogleProvider implements Provider {
|
|
|
8
10
|
config: ProviderConfig,
|
|
9
11
|
options?: ProviderSendOptions
|
|
10
12
|
): AsyncGenerator<AgentEvent> {
|
|
11
|
-
const cleanApiKey = config.apiKey?.trim().replace(/[\r\n]+/g, '');
|
|
12
|
-
const cleanModel = config.model.trim().replace(/[\r\n]+/g, '');
|
|
13
|
+
const cleanApiKey = config.apiKey?.trim().replace(/[\r\n]+/g, '');
|
|
14
|
+
const cleanModel = config.model.trim().replace(/[\r\n]+/g, '');
|
|
15
|
+
const reasoningEnabled = await shouldEnableReasoning(config.provider, cleanModel);
|
|
13
16
|
|
|
14
17
|
const google = createGoogleGenerativeAI({
|
|
15
18
|
apiKey: cleanApiKey,
|
|
16
19
|
});
|
|
17
20
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
21
|
+
try {
|
|
22
|
+
let stepCounter = 0;
|
|
23
|
+
|
|
24
|
+
yield* runWithRetry(async function* () {
|
|
25
|
+
const result = streamText({
|
|
26
|
+
model: google(cleanModel),
|
|
27
|
+
messages: messages,
|
|
28
|
+
system: config.systemPrompt,
|
|
29
|
+
tools: config.tools,
|
|
30
|
+
maxSteps: config.maxSteps || 100,
|
|
31
|
+
abortSignal: options?.abortSignal,
|
|
32
|
+
providerOptions: reasoningEnabled
|
|
33
|
+
? {
|
|
34
|
+
google: {
|
|
35
|
+
thinkingConfig: {
|
|
36
|
+
style: 'THINKING_STYLE_DETAILED',
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
}
|
|
40
|
+
: undefined,
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
for await (const chunk of result.fullStream as any) {
|
|
44
|
+
const c: any = chunk;
|
|
45
|
+
switch (c.type) {
|
|
46
|
+
case 'reasoning':
|
|
47
|
+
if (c.textDelta) {
|
|
48
|
+
yield {
|
|
49
|
+
type: 'reasoning-delta',
|
|
50
|
+
content: c.textDelta,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
break;
|
|
54
|
+
|
|
55
|
+
case 'text-delta':
|
|
56
|
+
yield {
|
|
57
|
+
type: 'text-delta',
|
|
58
|
+
content: c.textDelta,
|
|
59
|
+
};
|
|
60
|
+
break;
|
|
61
|
+
|
|
62
|
+
case 'step-start':
|
|
63
|
+
yield {
|
|
64
|
+
type: 'step-start',
|
|
65
|
+
stepNumber: typeof c.stepIndex === 'number' ? c.stepIndex : stepCounter,
|
|
66
|
+
};
|
|
67
|
+
stepCounter++;
|
|
68
|
+
break;
|
|
69
|
+
|
|
70
|
+
case 'step-finish':
|
|
71
|
+
yield {
|
|
72
|
+
type: 'step-finish',
|
|
73
|
+
stepNumber:
|
|
74
|
+
typeof c.stepIndex === 'number' ? c.stepIndex : Math.max(0, stepCounter - 1),
|
|
75
|
+
finishReason: String(c.finishReason ?? 'stop'),
|
|
76
|
+
};
|
|
77
|
+
break;
|
|
78
|
+
|
|
79
|
+
case 'tool-call':
|
|
80
|
+
yield {
|
|
81
|
+
type: 'tool-call-end',
|
|
82
|
+
toolCallId: String(c.toolCallId ?? ''),
|
|
83
|
+
toolName: String(c.toolName ?? ''),
|
|
84
|
+
args: (c.args ?? {}) as Record<string, unknown>,
|
|
85
|
+
};
|
|
86
|
+
break;
|
|
87
|
+
|
|
88
|
+
case 'tool-result':
|
|
89
|
+
yield {
|
|
90
|
+
type: 'tool-result',
|
|
91
|
+
toolCallId: String(c.toolCallId ?? ''),
|
|
92
|
+
toolName: String(c.toolName ?? ''),
|
|
93
|
+
result: c.result,
|
|
94
|
+
};
|
|
95
|
+
break;
|
|
96
|
+
|
|
97
|
+
case 'finish':
|
|
98
|
+
yield {
|
|
99
|
+
type: 'finish',
|
|
100
|
+
finishReason: String(c.finishReason ?? 'stop'),
|
|
101
|
+
usage: c.usage,
|
|
102
|
+
};
|
|
103
|
+
break;
|
|
104
|
+
|
|
105
|
+
case 'error': {
|
|
106
|
+
const err = normalizeError(c.error);
|
|
107
|
+
const decision = getRetryDecision(err);
|
|
108
|
+
if (decision.shouldRetry) {
|
|
109
|
+
throw err;
|
|
110
|
+
}
|
|
111
|
+
yield {
|
|
112
|
+
type: 'error',
|
|
113
|
+
error: err.message,
|
|
114
|
+
};
|
|
115
|
+
break;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}, { abortSignal: options?.abortSignal });
|
|
120
|
+
} catch (error) {
|
|
121
|
+
if (options?.abortSignal?.aborted) return;
|
|
122
|
+
yield {
|
|
119
123
|
type: 'error',
|
|
120
124
|
error: error instanceof Error ? error.message : 'Unknown error occurred',
|
|
121
125
|
};
|
|
122
126
|
}
|
|
123
127
|
}
|
|
124
|
-
}
|
|
128
|
+
}
|