@syntero/orca-cli 1.0.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/README.md +122 -0
- package/dist/assistant.d.ts +31 -0
- package/dist/assistant.d.ts.map +1 -0
- package/dist/assistant.js +280 -0
- package/dist/assistant.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +310 -0
- package/dist/index.js.map +1 -0
- package/dist/providers.d.ts +26 -0
- package/dist/providers.d.ts.map +1 -0
- package/dist/providers.js +283 -0
- package/dist/providers.js.map +1 -0
- package/dist/settings.d.ts +41 -0
- package/dist/settings.d.ts.map +1 -0
- package/dist/settings.js +132 -0
- package/dist/settings.js.map +1 -0
- package/dist/tools.d.ts +332 -0
- package/dist/tools.d.ts.map +1 -0
- package/dist/tools.js +359 -0
- package/dist/tools.js.map +1 -0
- package/dist/utils.d.ts +40 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +178 -0
- package/dist/utils.js.map +1 -0
- package/package.json +50 -0
package/README.md
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
# Orca Deployment Assistant (TypeScript CLI)
|
|
2
|
+
|
|
3
|
+
LLM-powered deployment troubleshooting assistant for Orca.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
### Global Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
# Install globally
|
|
11
|
+
npm install -g orca-deploy-assistant
|
|
12
|
+
|
|
13
|
+
# Run
|
|
14
|
+
orca-deploy-assistant
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
### Using npx
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npx orca-deploy-assistant
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
### Local Development
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
# Install dependencies
|
|
27
|
+
npm install
|
|
28
|
+
|
|
29
|
+
# Build
|
|
30
|
+
npm run build
|
|
31
|
+
|
|
32
|
+
# Run
|
|
33
|
+
npm start
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Usage
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
# Interactive mode (default)
|
|
40
|
+
orca-deploy-assistant
|
|
41
|
+
|
|
42
|
+
# Single query
|
|
43
|
+
orca-deploy-assistant "Why is the backend restarting?"
|
|
44
|
+
|
|
45
|
+
# Force interactive mode
|
|
46
|
+
orca-deploy-assistant --interactive
|
|
47
|
+
|
|
48
|
+
# Configure credentials
|
|
49
|
+
orca-deploy-assistant --login
|
|
50
|
+
|
|
51
|
+
# Specify deployment directory
|
|
52
|
+
orca-deploy-assistant -d /path/to/deployment
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Commands (Interactive Mode)
|
|
56
|
+
|
|
57
|
+
| Command | Description |
|
|
58
|
+
|---------|-------------|
|
|
59
|
+
| `/login` | Configure LLM provider credentials |
|
|
60
|
+
| `/settings` | Show current settings (secrets masked) |
|
|
61
|
+
| `/models` | List available models |
|
|
62
|
+
| `/model` | Change model for current provider |
|
|
63
|
+
| `/provider <name>` | Switch provider (anthropic, openai, azure) |
|
|
64
|
+
| `/clear` | Clear conversation history |
|
|
65
|
+
| `/help` | Show available commands |
|
|
66
|
+
| `quit`, `exit` | Exit the assistant |
|
|
67
|
+
|
|
68
|
+
## Supported Providers
|
|
69
|
+
|
|
70
|
+
- **Anthropic** (Claude) - Default
|
|
71
|
+
- **OpenAI** (GPT)
|
|
72
|
+
- **Azure OpenAI**
|
|
73
|
+
|
|
74
|
+
## Features
|
|
75
|
+
|
|
76
|
+
- Multi-provider support with easy switching
|
|
77
|
+
- Streaming responses
|
|
78
|
+
- Tool use for deployment inspection:
|
|
79
|
+
- `run_command` - Execute shell commands
|
|
80
|
+
- `read_file` - Read configuration files
|
|
81
|
+
- `list_directory` - List directory contents
|
|
82
|
+
- `inspect_env` - View .env with secrets redacted
|
|
83
|
+
- `query_database` - Read-only SQLite queries
|
|
84
|
+
- `search_logs` - Search container logs
|
|
85
|
+
- `check_container_health` - Container health reports
|
|
86
|
+
- Settings persistence (~/.deployment_assistant.json)
|
|
87
|
+
- Cancellation with 'q' or Ctrl+C
|
|
88
|
+
|
|
89
|
+
## Configuration
|
|
90
|
+
|
|
91
|
+
Settings are stored in `.deployment_assistant.json` in the deployment directory. The file is automatically created on first run and contains:
|
|
92
|
+
|
|
93
|
+
- Provider selection
|
|
94
|
+
- API keys (stored locally)
|
|
95
|
+
- Model preferences
|
|
96
|
+
|
|
97
|
+
## Development
|
|
98
|
+
|
|
99
|
+
```bash
|
|
100
|
+
# Install dependencies
|
|
101
|
+
npm install
|
|
102
|
+
|
|
103
|
+
# Build TypeScript
|
|
104
|
+
npm run build
|
|
105
|
+
|
|
106
|
+
# Run development
|
|
107
|
+
npm run dev
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
## Requirements
|
|
111
|
+
|
|
112
|
+
- Node.js 18+
|
|
113
|
+
- Docker (for container inspection tools)
|
|
114
|
+
- SQLite (via better-sqlite3)
|
|
115
|
+
|
|
116
|
+
## Environment Variables
|
|
117
|
+
|
|
118
|
+
- `DEPLOYMENT_DIR` - Override the deployment directory path
|
|
119
|
+
|
|
120
|
+
## License
|
|
121
|
+
|
|
122
|
+
MIT
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import Anthropic from '@anthropic-ai/sdk';
|
|
2
|
+
import OpenAI from 'openai';
|
|
3
|
+
import { Settings } from './settings.js';
|
|
4
|
+
import type { LLMClient } from './providers.js';
|
|
5
|
+
export interface AnthropicMessage {
|
|
6
|
+
role: 'user' | 'assistant';
|
|
7
|
+
content: string | AnthropicContentBlock[];
|
|
8
|
+
}
|
|
9
|
+
interface AnthropicContentBlock {
|
|
10
|
+
type: 'text' | 'tool_use' | 'tool_result';
|
|
11
|
+
text?: string;
|
|
12
|
+
id?: string;
|
|
13
|
+
name?: string;
|
|
14
|
+
input?: Record<string, unknown>;
|
|
15
|
+
tool_use_id?: string;
|
|
16
|
+
content?: string;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Run assistant with Anthropic API with streaming.
|
|
20
|
+
*/
|
|
21
|
+
export declare function runAssistantAnthropic(client: Anthropic, settings: Settings, userMessage: string, messages: AnthropicMessage[]): AsyncGenerator<string, AnthropicMessage[], void>;
|
|
22
|
+
/**
|
|
23
|
+
* Run assistant with OpenAI/Azure API with streaming.
|
|
24
|
+
*/
|
|
25
|
+
export declare function runAssistantOpenAI(client: OpenAI, settings: Settings, userMessage: string, messages: AnthropicMessage[], isAzure?: boolean): AsyncGenerator<string, AnthropicMessage[], void>;
|
|
26
|
+
/**
|
|
27
|
+
* Run the assistant with the appropriate provider.
|
|
28
|
+
*/
|
|
29
|
+
export declare function runAssistant(client: LLMClient, settings: Settings, userMessage: string, messages?: AnthropicMessage[]): AsyncGenerator<string, AnthropicMessage[], void>;
|
|
30
|
+
export {};
|
|
31
|
+
//# sourceMappingURL=assistant.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assistant.d.ts","sourceRoot":"","sources":["../src/assistant.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,mBAAmB,CAAC;AAC1C,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAE,QAAQ,EAAY,MAAM,eAAe,CAAC;AAGnD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AA8BhD,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,MAAM,GAAG,WAAW,CAAC;IAC3B,OAAO,EAAE,MAAM,GAAG,qBAAqB,EAAE,CAAC;CAC3C;AAED,UAAU,qBAAqB;IAC7B,IAAI,EAAE,MAAM,GAAG,UAAU,GAAG,aAAa,CAAC;IAC1C,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAChC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAwBD;;GAEG;AACH,wBAAuB,qBAAqB,CAC1C,MAAM,EAAE,SAAS,EACjB,QAAQ,EAAE,QAAQ,EAClB,WAAW,EAAE,MAAM,EACnB,QAAQ,EAAE,gBAAgB,EAAE,GAC3B,cAAc,CAAC,MAAM,EAAE,gBAAgB,EAAE,EAAE,IAAI,CAAC,CA+ElD;AAED;;GAEG;AACH,wBAAuB,kBAAkB,CACvC,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,QAAQ,EAClB,WAAW,EAAE,MAAM,EACnB,QAAQ,EAAE,gBAAgB,EAAE,EAC5B,OAAO,UAAQ,GACd,cAAc,CAAC,MAAM,EAAE,gBAAgB,EAAE,EAAE,IAAI,CAAC,CAmKlD;AAED;;GAEG;AACH,wBAAuB,YAAY,CACjC,MAAM,EAAE,SAAS,EACjB,QAAQ,EAAE,QAAQ,EAClB,WAAW,EAAE,MAAM,EACnB,QAAQ,GAAE,gBAAgB,EAAO,GAChC,cAAc,CAAC,MAAM,EAAE,gBAAgB,EAAE,EAAE,IAAI,CAAC,CAUlD"}
|
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
import { Provider } from './settings.js';
|
|
2
|
+
import { TOOLS_ANTHROPIC, TOOLS_OPENAI, handleToolCall } from './tools.js';
|
|
3
|
+
import { Colors, color } from './utils.js';
|
|
4
|
+
const SYSTEM_PROMPT = `You are an expert deployment assistant for Orca, a workflow automation application.
|
|
5
|
+
|
|
6
|
+
## Your Role
|
|
7
|
+
Help diagnose and resolve deployment issues. You have read-only access to:
|
|
8
|
+
- Docker containers, logs, and configuration
|
|
9
|
+
- Deployment files (docker-compose.yml, .env template)
|
|
10
|
+
- The main application database (SQLite)
|
|
11
|
+
|
|
12
|
+
## Orca Architecture
|
|
13
|
+
- **orca-backend**: Flask app (port 5000)
|
|
14
|
+
- **orca-frontend**: Nginx/React (ports 80/443)
|
|
15
|
+
- **orca-redis**: Redis for caching
|
|
16
|
+
- **orca-sandbox-{org_id}**: Per-org Python sandboxes (dynamic)
|
|
17
|
+
- **orca-runtime-data-{org_id}**: Per-org PostgreSQL (dynamic)
|
|
18
|
+
|
|
19
|
+
## Common Issues
|
|
20
|
+
- Backend crash loops: Check logs for database/migration errors
|
|
21
|
+
- Missing tables: Usually migration issues
|
|
22
|
+
- Permission errors: UID/GID mismatches (containers run as 1000:1000)
|
|
23
|
+
- Network issues: Check cors_origins.json and orca-network
|
|
24
|
+
|
|
25
|
+
## Guidelines
|
|
26
|
+
1. Start with container status and logs
|
|
27
|
+
2. Use inspect_env (not read_file) for .env
|
|
28
|
+
3. Explain issues clearly with fix steps
|
|
29
|
+
4. Be thorough but concise
|
|
30
|
+
`;
|
|
31
|
+
/**
|
|
32
|
+
* Run assistant with Anthropic API with streaming.
|
|
33
|
+
*/
|
|
34
|
+
export async function* runAssistantAnthropic(client, settings, userMessage, messages) {
|
|
35
|
+
messages.push({ role: 'user', content: userMessage });
|
|
36
|
+
while (true) {
|
|
37
|
+
let responseText = '';
|
|
38
|
+
const toolCalls = [];
|
|
39
|
+
const stream = client.messages.stream({
|
|
40
|
+
model: settings.anthropic.model,
|
|
41
|
+
max_tokens: 8192,
|
|
42
|
+
system: SYSTEM_PROMPT,
|
|
43
|
+
tools: TOOLS_ANTHROPIC,
|
|
44
|
+
messages: messages,
|
|
45
|
+
});
|
|
46
|
+
for await (const event of stream) {
|
|
47
|
+
if (event.type === 'content_block_start') {
|
|
48
|
+
const contentBlock = event.content_block;
|
|
49
|
+
if (contentBlock?.type === 'tool_use') {
|
|
50
|
+
toolCalls.push({
|
|
51
|
+
id: contentBlock.id || '',
|
|
52
|
+
name: contentBlock.name || '',
|
|
53
|
+
input: '',
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
else if (event.type === 'content_block_delta') {
|
|
58
|
+
const delta = event.delta;
|
|
59
|
+
if (delta?.type === 'text_delta' && delta.text) {
|
|
60
|
+
yield delta.text;
|
|
61
|
+
responseText += delta.text;
|
|
62
|
+
}
|
|
63
|
+
else if (delta?.type === 'input_json_delta' && delta.partial_json && toolCalls.length > 0) {
|
|
64
|
+
toolCalls[toolCalls.length - 1].input += delta.partial_json;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
const finalMessage = await stream.finalMessage();
|
|
69
|
+
// Build assistant content
|
|
70
|
+
const assistantContent = [];
|
|
71
|
+
if (responseText) {
|
|
72
|
+
assistantContent.push({ type: 'text', text: responseText });
|
|
73
|
+
}
|
|
74
|
+
for (const tc of toolCalls) {
|
|
75
|
+
try {
|
|
76
|
+
tc.input = tc.input ? JSON.parse(tc.input) : {};
|
|
77
|
+
}
|
|
78
|
+
catch {
|
|
79
|
+
tc.input = {};
|
|
80
|
+
}
|
|
81
|
+
assistantContent.push({
|
|
82
|
+
type: 'tool_use',
|
|
83
|
+
id: tc.id,
|
|
84
|
+
name: tc.name,
|
|
85
|
+
input: tc.input,
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
messages.push({ role: 'assistant', content: assistantContent });
|
|
89
|
+
if (finalMessage.stop_reason === 'tool_use') {
|
|
90
|
+
const toolResults = [];
|
|
91
|
+
for (const tc of toolCalls) {
|
|
92
|
+
yield color(`\n\n[${tc.name}]\n`, Colors.dim);
|
|
93
|
+
const result = handleToolCall(tc.name, tc.input);
|
|
94
|
+
const preview = result.length > 500 ? result.slice(0, 500) + '...' : result;
|
|
95
|
+
yield color(`${preview}\n`, Colors.dim);
|
|
96
|
+
toolResults.push({
|
|
97
|
+
type: 'tool_result',
|
|
98
|
+
tool_use_id: tc.id,
|
|
99
|
+
content: result,
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
messages.push({ role: 'user', content: toolResults });
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
break;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return messages;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Run assistant with OpenAI/Azure API with streaming.
|
|
112
|
+
*/
|
|
113
|
+
export async function* runAssistantOpenAI(client, settings, userMessage, messages, isAzure = false) {
|
|
114
|
+
const model = isAzure ? settings.azure.deployment : settings.openai.model;
|
|
115
|
+
// Convert messages format for OpenAI
|
|
116
|
+
const openaiMessages = [{ role: 'system', content: SYSTEM_PROMPT }];
|
|
117
|
+
for (const msg of messages) {
|
|
118
|
+
if (msg.role === 'user') {
|
|
119
|
+
if (Array.isArray(msg.content)) {
|
|
120
|
+
// Tool results
|
|
121
|
+
for (const item of msg.content) {
|
|
122
|
+
if (item.type === 'tool_result') {
|
|
123
|
+
openaiMessages.push({
|
|
124
|
+
role: 'tool',
|
|
125
|
+
tool_call_id: item.tool_use_id || '',
|
|
126
|
+
content: item.content || '',
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
openaiMessages.push({ role: 'user', content: msg.content });
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
else if (msg.role === 'assistant') {
|
|
136
|
+
if (Array.isArray(msg.content)) {
|
|
137
|
+
const toolCallsArr = [];
|
|
138
|
+
let textContent = '';
|
|
139
|
+
for (const item of msg.content) {
|
|
140
|
+
if (item.type === 'text') {
|
|
141
|
+
textContent = item.text || '';
|
|
142
|
+
}
|
|
143
|
+
else if (item.type === 'tool_use') {
|
|
144
|
+
toolCallsArr.push({
|
|
145
|
+
id: item.id || '',
|
|
146
|
+
type: 'function',
|
|
147
|
+
function: {
|
|
148
|
+
name: item.name || '',
|
|
149
|
+
arguments: JSON.stringify(item.input || {}),
|
|
150
|
+
},
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
const assistantMsg = {
|
|
155
|
+
role: 'assistant',
|
|
156
|
+
content: textContent || null,
|
|
157
|
+
};
|
|
158
|
+
if (toolCallsArr.length > 0) {
|
|
159
|
+
assistantMsg.tool_calls = toolCallsArr;
|
|
160
|
+
}
|
|
161
|
+
openaiMessages.push(assistantMsg);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
openaiMessages.push({ role: 'user', content: userMessage });
|
|
166
|
+
messages.push({ role: 'user', content: userMessage });
|
|
167
|
+
while (true) {
|
|
168
|
+
let responseText = '';
|
|
169
|
+
const toolCalls = {};
|
|
170
|
+
let currentToolId = null;
|
|
171
|
+
const stream = await client.chat.completions.create({
|
|
172
|
+
model,
|
|
173
|
+
messages: openaiMessages,
|
|
174
|
+
tools: TOOLS_OPENAI,
|
|
175
|
+
stream: true,
|
|
176
|
+
max_tokens: 8192,
|
|
177
|
+
});
|
|
178
|
+
let finishReason = null;
|
|
179
|
+
for await (const chunk of stream) {
|
|
180
|
+
const delta = chunk.choices[0]?.delta;
|
|
181
|
+
finishReason = chunk.choices[0]?.finish_reason || null;
|
|
182
|
+
if (delta) {
|
|
183
|
+
if (delta.content) {
|
|
184
|
+
yield delta.content;
|
|
185
|
+
responseText += delta.content;
|
|
186
|
+
}
|
|
187
|
+
if (delta.tool_calls) {
|
|
188
|
+
for (const tc of delta.tool_calls) {
|
|
189
|
+
if (tc.id) {
|
|
190
|
+
currentToolId = tc.id;
|
|
191
|
+
toolCalls[currentToolId] = {
|
|
192
|
+
id: tc.id,
|
|
193
|
+
name: tc.function?.name || '',
|
|
194
|
+
input: '',
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
if (tc.function?.arguments && currentToolId) {
|
|
198
|
+
toolCalls[currentToolId].input += tc.function.arguments;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
// Build assistant message
|
|
205
|
+
const assistantContent = [];
|
|
206
|
+
if (responseText) {
|
|
207
|
+
assistantContent.push({ type: 'text', text: responseText });
|
|
208
|
+
}
|
|
209
|
+
const openaiAssistantMsg = {
|
|
210
|
+
role: 'assistant',
|
|
211
|
+
content: responseText || null,
|
|
212
|
+
};
|
|
213
|
+
if (Object.keys(toolCalls).length > 0) {
|
|
214
|
+
openaiAssistantMsg.tool_calls = Object.values(toolCalls).map((tc) => ({
|
|
215
|
+
id: tc.id,
|
|
216
|
+
type: 'function',
|
|
217
|
+
function: {
|
|
218
|
+
name: tc.name,
|
|
219
|
+
arguments: tc.input,
|
|
220
|
+
},
|
|
221
|
+
}));
|
|
222
|
+
for (const tc of Object.values(toolCalls)) {
|
|
223
|
+
try {
|
|
224
|
+
tc.input = tc.input ? JSON.parse(tc.input) : {};
|
|
225
|
+
}
|
|
226
|
+
catch {
|
|
227
|
+
tc.input = {};
|
|
228
|
+
}
|
|
229
|
+
assistantContent.push({
|
|
230
|
+
type: 'tool_use',
|
|
231
|
+
id: tc.id,
|
|
232
|
+
name: tc.name,
|
|
233
|
+
input: tc.input,
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
openaiMessages.push(openaiAssistantMsg);
|
|
238
|
+
messages.push({ role: 'assistant', content: assistantContent });
|
|
239
|
+
if (finishReason === 'tool_calls' && Object.keys(toolCalls).length > 0) {
|
|
240
|
+
const toolResults = [];
|
|
241
|
+
for (const tc of Object.values(toolCalls)) {
|
|
242
|
+
yield color(`\n\n[${tc.name}]\n`, Colors.dim);
|
|
243
|
+
const result = handleToolCall(tc.name, tc.input);
|
|
244
|
+
const preview = result.length > 500 ? result.slice(0, 500) + '...' : result;
|
|
245
|
+
yield color(`${preview}\n`, Colors.dim);
|
|
246
|
+
openaiMessages.push({
|
|
247
|
+
role: 'tool',
|
|
248
|
+
tool_call_id: tc.id,
|
|
249
|
+
content: result,
|
|
250
|
+
});
|
|
251
|
+
toolResults.push({
|
|
252
|
+
type: 'tool_result',
|
|
253
|
+
tool_use_id: tc.id,
|
|
254
|
+
content: result,
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
messages.push({ role: 'user', content: toolResults });
|
|
258
|
+
}
|
|
259
|
+
else {
|
|
260
|
+
break;
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
return messages;
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Run the assistant with the appropriate provider.
|
|
267
|
+
*/
|
|
268
|
+
export async function* runAssistant(client, settings, userMessage, messages = []) {
|
|
269
|
+
if (settings.provider === Provider.ANTHROPIC) {
|
|
270
|
+
return yield* runAssistantAnthropic(client, settings, userMessage, messages);
|
|
271
|
+
}
|
|
272
|
+
else if (settings.provider === Provider.OPENAI) {
|
|
273
|
+
return yield* runAssistantOpenAI(client, settings, userMessage, messages, false);
|
|
274
|
+
}
|
|
275
|
+
else if (settings.provider === Provider.AZURE) {
|
|
276
|
+
return yield* runAssistantOpenAI(client, settings, userMessage, messages, true);
|
|
277
|
+
}
|
|
278
|
+
throw new Error(`Unknown provider: ${settings.provider}`);
|
|
279
|
+
}
|
|
280
|
+
//# sourceMappingURL=assistant.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assistant.js","sourceRoot":"","sources":["../src/assistant.ts"],"names":[],"mappings":"AAEA,OAAO,EAAY,QAAQ,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC3E,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAG3C,MAAM,aAAa,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;CA0BrB,CAAC;AAuCF;;GAEG;AACH,MAAM,CAAC,KAAK,SAAS,CAAC,CAAC,qBAAqB,CAC1C,MAAiB,EACjB,QAAkB,EAClB,WAAmB,EACnB,QAA4B;IAE5B,QAAQ,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW,EAAE,CAAC,CAAC;IAEt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