askimo 1.4.0 → 1.6.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/index.mjs +12 -2
- package/lib/conversationsClient.js +189 -0
- package/lib/{conversations-ui.mjs → conversationsUi.mjs} +11 -194
- package/lib/providers.mjs +16 -97
- package/lib/stream.mjs +20 -1
- package/package.json +15 -15
package/index.mjs
CHANGED
|
@@ -4,10 +4,10 @@ import { Command } from 'commander'
|
|
|
4
4
|
import { startChat } from './lib/chat.mjs'
|
|
5
5
|
import { ensureDirectories, loadConfig } from './lib/config.mjs'
|
|
6
6
|
import { createConversation, loadConversation, loadConversationById, saveConversation } from './lib/conversation.mjs'
|
|
7
|
-
import { showConversationsInBrowser } from './lib/
|
|
7
|
+
import { showConversationsInBrowser } from './lib/conversationsUi.mjs'
|
|
8
8
|
import { buildMessage, readFile, readStdin } from './lib/input.mjs'
|
|
9
9
|
import { DEFAULT_MODELS, determineProvider, getProvider, listModels } from './lib/providers.mjs'
|
|
10
|
-
import { generateResponse, outputJson, streamResponse } from './lib/stream.mjs'
|
|
10
|
+
import { generateResponse, outputJson, printResponse, streamResponse } from './lib/stream.mjs'
|
|
11
11
|
import pkg from './package.json' with { type: 'json' }
|
|
12
12
|
|
|
13
13
|
const program = new Command()
|
|
@@ -24,6 +24,7 @@ program
|
|
|
24
24
|
.option('-x, --xai', 'Use xAI Grok')
|
|
25
25
|
.option('-g, --gemini', 'Use Google Gemini')
|
|
26
26
|
.option('-j, --json', 'Output as JSON instead of streaming')
|
|
27
|
+
.option('-n, --no-stream', 'Disable streaming (print full response at once)')
|
|
27
28
|
.option('-c, --continue <n>', 'Continue conversation N (1=last, 2=second-to-last)', Number.parseInt)
|
|
28
29
|
.option('--cid <id>', 'Continue conversation by ID')
|
|
29
30
|
.option('-f, --file <path>', 'Read content from file')
|
|
@@ -95,6 +96,15 @@ program
|
|
|
95
96
|
})
|
|
96
97
|
await saveConversation(conversation, existingPath)
|
|
97
98
|
outputJson(conversation, responseText, sources, duration)
|
|
99
|
+
} else if (!options.stream) {
|
|
100
|
+
const { text, sources, duration } = await generateResponse(model, conversation.messages)
|
|
101
|
+
responseText = text
|
|
102
|
+
conversation.messages.push({
|
|
103
|
+
role: 'assistant',
|
|
104
|
+
content: responseText
|
|
105
|
+
})
|
|
106
|
+
await saveConversation(conversation, existingPath)
|
|
107
|
+
printResponse(responseText, sources, duration, modelName)
|
|
98
108
|
} else {
|
|
99
109
|
responseText = await streamResponse(model, conversation.messages, modelName)
|
|
100
110
|
conversation.messages.push({
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
let currentPage = 1
|
|
2
|
+
// biome-ignore lint/correctness/noUndeclaredVariables: global set by prior <script> tag in HTML
|
|
3
|
+
const totalPages = Math.ceil(conversations.length / ITEMS_PER_PAGE)
|
|
4
|
+
|
|
5
|
+
function escapeHtml(text) {
|
|
6
|
+
const div = document.createElement('div')
|
|
7
|
+
div.textContent = text
|
|
8
|
+
return div.innerHTML
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function formatDate(isoString) {
|
|
12
|
+
const date = new Date(isoString)
|
|
13
|
+
return date.toLocaleDateString('en-US', {
|
|
14
|
+
year: 'numeric',
|
|
15
|
+
month: 'short',
|
|
16
|
+
day: 'numeric',
|
|
17
|
+
hour: '2-digit',
|
|
18
|
+
minute: '2-digit'
|
|
19
|
+
})
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function renderMessages(messages) {
|
|
23
|
+
return messages
|
|
24
|
+
.map(
|
|
25
|
+
(msg) => `
|
|
26
|
+
<div class="message ${msg.role}">
|
|
27
|
+
<div class="message-role">${msg.role === 'user' ? 'You' : 'Assistant'}</div>
|
|
28
|
+
<div class="message-content">${escapeHtml(msg.content)}</div>
|
|
29
|
+
</div>
|
|
30
|
+
`
|
|
31
|
+
)
|
|
32
|
+
.join('')
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function renderPage(page) {
|
|
36
|
+
currentPage = page
|
|
37
|
+
const container = document.getElementById('conversations-container')
|
|
38
|
+
// biome-ignore lint/correctness/noUndeclaredVariables: global set by prior <script> tag in HTML
|
|
39
|
+
const start = (page - 1) * ITEMS_PER_PAGE
|
|
40
|
+
// biome-ignore lint/correctness/noUndeclaredVariables: global set by prior <script> tag in HTML
|
|
41
|
+
const end = Math.min(start + ITEMS_PER_PAGE, conversations.length)
|
|
42
|
+
// biome-ignore lint/correctness/noUndeclaredVariables: global set by prior <script> tag in HTML
|
|
43
|
+
const pageConversations = conversations.slice(start, end)
|
|
44
|
+
|
|
45
|
+
// biome-ignore lint/correctness/noUndeclaredVariables: global set by prior <script> tag in HTML
|
|
46
|
+
if (conversations.length === 0) {
|
|
47
|
+
container.innerHTML = `
|
|
48
|
+
<div class="empty">
|
|
49
|
+
<p>No conversations found.</p>
|
|
50
|
+
<p>Start a conversation with: <code>askimo "your question"</code></p>
|
|
51
|
+
</div>
|
|
52
|
+
`
|
|
53
|
+
return
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const rows = pageConversations
|
|
57
|
+
.map((conv, idx) => {
|
|
58
|
+
const globalIndex = start + idx
|
|
59
|
+
return `
|
|
60
|
+
<tr class="conversation-row" data-index="${globalIndex}">
|
|
61
|
+
<td class="id">
|
|
62
|
+
<span class="id-text">${escapeHtml(conv.id)}</span>
|
|
63
|
+
<button class="copy-btn" data-id="${escapeHtml(conv.id)}" title="Copy ID">
|
|
64
|
+
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
65
|
+
<rect x="9" y="9" width="13" height="13" rx="2" ry="2"></rect>
|
|
66
|
+
<path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"></path>
|
|
67
|
+
</svg>
|
|
68
|
+
</button>
|
|
69
|
+
</td>
|
|
70
|
+
<td class="provider">${escapeHtml(conv.provider)}</td>
|
|
71
|
+
<td class="model">${escapeHtml(conv.model)}</td>
|
|
72
|
+
<td class="date">${formatDate(conv.createdAt)}</td>
|
|
73
|
+
<td class="messages">${conv.messageCount}</td>
|
|
74
|
+
<td class="preview">${escapeHtml(conv.preview)}</td>
|
|
75
|
+
</tr>
|
|
76
|
+
<tr class="conversation-detail" data-index="${globalIndex}">
|
|
77
|
+
<td colspan="6">
|
|
78
|
+
<div class="detail-content">
|
|
79
|
+
${renderMessages(conv.messages)}
|
|
80
|
+
</div>
|
|
81
|
+
</td>
|
|
82
|
+
</tr>
|
|
83
|
+
`
|
|
84
|
+
})
|
|
85
|
+
.join('')
|
|
86
|
+
|
|
87
|
+
const pagination =
|
|
88
|
+
totalPages > 1
|
|
89
|
+
? `
|
|
90
|
+
<div class="pagination">
|
|
91
|
+
<button class="page-btn" onclick="renderPage(1)" ${currentPage === 1 ? 'disabled' : ''}>
|
|
92
|
+
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
93
|
+
<polyline points="11 17 6 12 11 7"></polyline>
|
|
94
|
+
<polyline points="18 17 13 12 18 7"></polyline>
|
|
95
|
+
</svg>
|
|
96
|
+
</button>
|
|
97
|
+
<button class="page-btn" onclick="renderPage(${currentPage - 1})" ${currentPage === 1 ? 'disabled' : ''}>
|
|
98
|
+
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
99
|
+
<polyline points="15 18 9 12 15 6"></polyline>
|
|
100
|
+
</svg>
|
|
101
|
+
</button>
|
|
102
|
+
<span class="page-info">Page ${currentPage} of ${totalPages}</span>
|
|
103
|
+
<button class="page-btn" onclick="renderPage(${currentPage + 1})" ${currentPage === totalPages ? 'disabled' : ''}>
|
|
104
|
+
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
105
|
+
<polyline points="9 18 15 12 9 6"></polyline>
|
|
106
|
+
</svg>
|
|
107
|
+
</button>
|
|
108
|
+
<button class="page-btn" onclick="renderPage(${totalPages})" ${currentPage === totalPages ? 'disabled' : ''}>
|
|
109
|
+
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
110
|
+
<polyline points="13 17 18 12 13 7"></polyline>
|
|
111
|
+
<polyline points="6 17 11 12 6 7"></polyline>
|
|
112
|
+
</svg>
|
|
113
|
+
</button>
|
|
114
|
+
</div>
|
|
115
|
+
`
|
|
116
|
+
: ''
|
|
117
|
+
|
|
118
|
+
container.innerHTML = `
|
|
119
|
+
<table>
|
|
120
|
+
<thead>
|
|
121
|
+
<tr>
|
|
122
|
+
<th>ID</th>
|
|
123
|
+
<th>Provider</th>
|
|
124
|
+
<th>Model</th>
|
|
125
|
+
<th>Date</th>
|
|
126
|
+
<th>Messages</th>
|
|
127
|
+
<th>Preview</th>
|
|
128
|
+
</tr>
|
|
129
|
+
</thead>
|
|
130
|
+
<tbody>
|
|
131
|
+
${rows}
|
|
132
|
+
</tbody>
|
|
133
|
+
</table>
|
|
134
|
+
${pagination}
|
|
135
|
+
`
|
|
136
|
+
|
|
137
|
+
attachEventListeners()
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function attachEventListeners() {
|
|
141
|
+
// Accordion behavior
|
|
142
|
+
document.querySelectorAll('.conversation-row').forEach((row) => {
|
|
143
|
+
row.addEventListener('click', (e) => {
|
|
144
|
+
if (e.target.closest('.copy-btn')) return
|
|
145
|
+
|
|
146
|
+
const index = row.dataset.index
|
|
147
|
+
const detailRow = document.querySelector(`.conversation-detail[data-index="${index}"]`)
|
|
148
|
+
const isExpanded = row.classList.contains('expanded')
|
|
149
|
+
|
|
150
|
+
document.querySelectorAll('.conversation-row.expanded').forEach((r) => {
|
|
151
|
+
r.classList.remove('expanded')
|
|
152
|
+
})
|
|
153
|
+
document.querySelectorAll('.conversation-detail.expanded').forEach((d) => {
|
|
154
|
+
d.classList.remove('expanded')
|
|
155
|
+
})
|
|
156
|
+
|
|
157
|
+
if (!isExpanded) {
|
|
158
|
+
row.classList.add('expanded')
|
|
159
|
+
detailRow.classList.add('expanded')
|
|
160
|
+
}
|
|
161
|
+
})
|
|
162
|
+
})
|
|
163
|
+
|
|
164
|
+
// Copy button functionality
|
|
165
|
+
document.querySelectorAll('.copy-btn').forEach((btn) => {
|
|
166
|
+
btn.addEventListener('click', async (e) => {
|
|
167
|
+
e.stopPropagation()
|
|
168
|
+
const id = btn.dataset.id
|
|
169
|
+
|
|
170
|
+
try {
|
|
171
|
+
await navigator.clipboard.writeText(id)
|
|
172
|
+
btn.classList.add('copied')
|
|
173
|
+
btn.innerHTML =
|
|
174
|
+
'<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polyline points="20 6 9 17 4 12"></polyline></svg>'
|
|
175
|
+
|
|
176
|
+
setTimeout(() => {
|
|
177
|
+
btn.classList.remove('copied')
|
|
178
|
+
btn.innerHTML =
|
|
179
|
+
'<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect x="9" y="9" width="13" height="13" rx="2" ry="2"></rect><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"></path></svg>'
|
|
180
|
+
}, 2000)
|
|
181
|
+
} catch (err) {
|
|
182
|
+
console.error('Failed to copy:', err)
|
|
183
|
+
}
|
|
184
|
+
})
|
|
185
|
+
})
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
// Initial render
|
|
189
|
+
renderPage(1)
|
|
@@ -1,38 +1,21 @@
|
|
|
1
|
+
import fs from 'node:fs/promises'
|
|
1
2
|
import hcat from 'hcat'
|
|
2
3
|
import { getAllConversations } from './conversation.mjs'
|
|
3
4
|
|
|
4
|
-
function formatDate(isoString) {
|
|
5
|
-
const date = new Date(isoString)
|
|
6
|
-
return date.toLocaleDateString('en-US', {
|
|
7
|
-
year: 'numeric',
|
|
8
|
-
month: 'short',
|
|
9
|
-
day: 'numeric',
|
|
10
|
-
hour: '2-digit',
|
|
11
|
-
minute: '2-digit'
|
|
12
|
-
})
|
|
13
|
-
}
|
|
14
|
-
|
|
15
5
|
function getPreview(messages, maxLength = 100) {
|
|
16
6
|
const firstUserMessage = messages.find((m) => m.role === 'user')
|
|
17
7
|
if (!firstUserMessage) return 'No messages'
|
|
18
8
|
|
|
19
9
|
const content = firstUserMessage.content
|
|
20
10
|
if (content.length <= maxLength) return content
|
|
21
|
-
return content.slice(0, maxLength)
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
function escapeHtml(text) {
|
|
25
|
-
return text
|
|
26
|
-
.replace(/&/g, '&')
|
|
27
|
-
.replace(/</g, '<')
|
|
28
|
-
.replace(/>/g, '>')
|
|
29
|
-
.replace(/"/g, '"')
|
|
30
|
-
.replace(/'/g, ''')
|
|
11
|
+
return `${content.slice(0, maxLength)}...`
|
|
31
12
|
}
|
|
32
13
|
|
|
33
14
|
const ITEMS_PER_PAGE = 20
|
|
34
15
|
|
|
35
|
-
function generateHtml(conversations) {
|
|
16
|
+
async function generateHtml(conversations) {
|
|
17
|
+
const clientJs = await fs.readFile(new URL('conversationsClient.js', import.meta.url), 'utf8')
|
|
18
|
+
|
|
36
19
|
// Prepare conversation data for client-side rendering
|
|
37
20
|
const conversationsJson = JSON.stringify(
|
|
38
21
|
conversations.map((conv) => ({
|
|
@@ -385,177 +368,11 @@ function generateHtml(conversations) {
|
|
|
385
368
|
</div>
|
|
386
369
|
|
|
387
370
|
<script>
|
|
388
|
-
const conversations = ${conversationsJson}
|
|
389
|
-
const ITEMS_PER_PAGE = ${ITEMS_PER_PAGE}
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
function escapeHtml(text) {
|
|
394
|
-
const div = document.createElement('div');
|
|
395
|
-
div.textContent = text;
|
|
396
|
-
return div.innerHTML;
|
|
397
|
-
}
|
|
398
|
-
|
|
399
|
-
function formatDate(isoString) {
|
|
400
|
-
const date = new Date(isoString);
|
|
401
|
-
return date.toLocaleDateString('en-US', {
|
|
402
|
-
year: 'numeric',
|
|
403
|
-
month: 'short',
|
|
404
|
-
day: 'numeric',
|
|
405
|
-
hour: '2-digit',
|
|
406
|
-
minute: '2-digit'
|
|
407
|
-
});
|
|
408
|
-
}
|
|
409
|
-
|
|
410
|
-
function renderMessages(messages) {
|
|
411
|
-
return messages.map(msg => \`
|
|
412
|
-
<div class="message \${msg.role}">
|
|
413
|
-
<div class="message-role">\${msg.role === 'user' ? 'You' : 'Assistant'}</div>
|
|
414
|
-
<div class="message-content">\${escapeHtml(msg.content)}</div>
|
|
415
|
-
</div>
|
|
416
|
-
\`).join('');
|
|
417
|
-
}
|
|
418
|
-
|
|
419
|
-
function renderPage(page) {
|
|
420
|
-
currentPage = page;
|
|
421
|
-
const container = document.getElementById('conversations-container');
|
|
422
|
-
const start = (page - 1) * ITEMS_PER_PAGE;
|
|
423
|
-
const end = Math.min(start + ITEMS_PER_PAGE, conversations.length);
|
|
424
|
-
const pageConversations = conversations.slice(start, end);
|
|
425
|
-
|
|
426
|
-
if (conversations.length === 0) {
|
|
427
|
-
container.innerHTML = \`
|
|
428
|
-
<div class="empty">
|
|
429
|
-
<p>No conversations found.</p>
|
|
430
|
-
<p>Start a conversation with: <code>askimo "your question"</code></p>
|
|
431
|
-
</div>
|
|
432
|
-
\`;
|
|
433
|
-
return;
|
|
434
|
-
}
|
|
435
|
-
|
|
436
|
-
const rows = pageConversations.map((conv, idx) => {
|
|
437
|
-
const globalIndex = start + idx;
|
|
438
|
-
return \`
|
|
439
|
-
<tr class="conversation-row" data-index="\${globalIndex}">
|
|
440
|
-
<td class="id">
|
|
441
|
-
<span class="id-text">\${escapeHtml(conv.id)}</span>
|
|
442
|
-
<button class="copy-btn" data-id="\${escapeHtml(conv.id)}" title="Copy ID">
|
|
443
|
-
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
444
|
-
<rect x="9" y="9" width="13" height="13" rx="2" ry="2"></rect>
|
|
445
|
-
<path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"></path>
|
|
446
|
-
</svg>
|
|
447
|
-
</button>
|
|
448
|
-
</td>
|
|
449
|
-
<td class="provider">\${escapeHtml(conv.provider)}</td>
|
|
450
|
-
<td class="model">\${escapeHtml(conv.model)}</td>
|
|
451
|
-
<td class="date">\${formatDate(conv.createdAt)}</td>
|
|
452
|
-
<td class="messages">\${conv.messageCount}</td>
|
|
453
|
-
<td class="preview">\${escapeHtml(conv.preview)}</td>
|
|
454
|
-
</tr>
|
|
455
|
-
<tr class="conversation-detail" data-index="\${globalIndex}">
|
|
456
|
-
<td colspan="6">
|
|
457
|
-
<div class="detail-content">
|
|
458
|
-
\${renderMessages(conv.messages)}
|
|
459
|
-
</div>
|
|
460
|
-
</td>
|
|
461
|
-
</tr>
|
|
462
|
-
\`;
|
|
463
|
-
}).join('');
|
|
464
|
-
|
|
465
|
-
const pagination = totalPages > 1 ? \`
|
|
466
|
-
<div class="pagination">
|
|
467
|
-
<button class="page-btn" onclick="renderPage(1)" \${currentPage === 1 ? 'disabled' : ''}>
|
|
468
|
-
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
469
|
-
<polyline points="11 17 6 12 11 7"></polyline>
|
|
470
|
-
<polyline points="18 17 13 12 18 7"></polyline>
|
|
471
|
-
</svg>
|
|
472
|
-
</button>
|
|
473
|
-
<button class="page-btn" onclick="renderPage(\${currentPage - 1})" \${currentPage === 1 ? 'disabled' : ''}>
|
|
474
|
-
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
475
|
-
<polyline points="15 18 9 12 15 6"></polyline>
|
|
476
|
-
</svg>
|
|
477
|
-
</button>
|
|
478
|
-
<span class="page-info">Page \${currentPage} of \${totalPages}</span>
|
|
479
|
-
<button class="page-btn" onclick="renderPage(\${currentPage + 1})" \${currentPage === totalPages ? 'disabled' : ''}>
|
|
480
|
-
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
481
|
-
<polyline points="9 18 15 12 9 6"></polyline>
|
|
482
|
-
</svg>
|
|
483
|
-
</button>
|
|
484
|
-
<button class="page-btn" onclick="renderPage(\${totalPages})" \${currentPage === totalPages ? 'disabled' : ''}>
|
|
485
|
-
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
486
|
-
<polyline points="13 17 18 12 13 7"></polyline>
|
|
487
|
-
<polyline points="6 17 11 12 6 7"></polyline>
|
|
488
|
-
</svg>
|
|
489
|
-
</button>
|
|
490
|
-
</div>
|
|
491
|
-
\` : '';
|
|
492
|
-
|
|
493
|
-
container.innerHTML = \`
|
|
494
|
-
<table>
|
|
495
|
-
<thead>
|
|
496
|
-
<tr>
|
|
497
|
-
<th>ID</th>
|
|
498
|
-
<th>Provider</th>
|
|
499
|
-
<th>Model</th>
|
|
500
|
-
<th>Date</th>
|
|
501
|
-
<th>Messages</th>
|
|
502
|
-
<th>Preview</th>
|
|
503
|
-
</tr>
|
|
504
|
-
</thead>
|
|
505
|
-
<tbody>
|
|
506
|
-
\${rows}
|
|
507
|
-
</tbody>
|
|
508
|
-
</table>
|
|
509
|
-
\${pagination}
|
|
510
|
-
\`;
|
|
511
|
-
|
|
512
|
-
attachEventListeners();
|
|
513
|
-
}
|
|
514
|
-
|
|
515
|
-
function attachEventListeners() {
|
|
516
|
-
// Accordion behavior
|
|
517
|
-
document.querySelectorAll('.conversation-row').forEach(row => {
|
|
518
|
-
row.addEventListener('click', (e) => {
|
|
519
|
-
if (e.target.closest('.copy-btn')) return;
|
|
520
|
-
|
|
521
|
-
const index = row.dataset.index;
|
|
522
|
-
const detailRow = document.querySelector('.conversation-detail[data-index="' + index + '"]');
|
|
523
|
-
const isExpanded = row.classList.contains('expanded');
|
|
524
|
-
|
|
525
|
-
document.querySelectorAll('.conversation-row.expanded').forEach(r => r.classList.remove('expanded'));
|
|
526
|
-
document.querySelectorAll('.conversation-detail.expanded').forEach(d => d.classList.remove('expanded'));
|
|
527
|
-
|
|
528
|
-
if (!isExpanded) {
|
|
529
|
-
row.classList.add('expanded');
|
|
530
|
-
detailRow.classList.add('expanded');
|
|
531
|
-
}
|
|
532
|
-
});
|
|
533
|
-
});
|
|
534
|
-
|
|
535
|
-
// Copy button functionality
|
|
536
|
-
document.querySelectorAll('.copy-btn').forEach(btn => {
|
|
537
|
-
btn.addEventListener('click', async (e) => {
|
|
538
|
-
e.stopPropagation();
|
|
539
|
-
const id = btn.dataset.id;
|
|
540
|
-
|
|
541
|
-
try {
|
|
542
|
-
await navigator.clipboard.writeText(id);
|
|
543
|
-
btn.classList.add('copied');
|
|
544
|
-
btn.innerHTML = '<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polyline points="20 6 9 17 4 12"></polyline></svg>';
|
|
545
|
-
|
|
546
|
-
setTimeout(() => {
|
|
547
|
-
btn.classList.remove('copied');
|
|
548
|
-
btn.innerHTML = '<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect x="9" y="9" width="13" height="13" rx="2" ry="2"></rect><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"></path></svg>';
|
|
549
|
-
}, 2000);
|
|
550
|
-
} catch (err) {
|
|
551
|
-
console.error('Failed to copy:', err);
|
|
552
|
-
}
|
|
553
|
-
});
|
|
554
|
-
});
|
|
555
|
-
}
|
|
556
|
-
|
|
557
|
-
// Initial render
|
|
558
|
-
renderPage(1);
|
|
371
|
+
const conversations = ${conversationsJson}
|
|
372
|
+
const ITEMS_PER_PAGE = ${ITEMS_PER_PAGE}
|
|
373
|
+
</script>
|
|
374
|
+
<script>
|
|
375
|
+
${clientJs}
|
|
559
376
|
</script>
|
|
560
377
|
</body>
|
|
561
378
|
</html>`
|
|
@@ -563,7 +380,7 @@ function generateHtml(conversations) {
|
|
|
563
380
|
|
|
564
381
|
async function showConversationsInBrowser() {
|
|
565
382
|
const conversations = await getAllConversations()
|
|
566
|
-
const html = generateHtml(conversations)
|
|
383
|
+
const html = await generateHtml(conversations)
|
|
567
384
|
|
|
568
385
|
console.log('Opening conversations in browser...')
|
|
569
386
|
hcat(html, { port: 0 })
|
package/lib/providers.mjs
CHANGED
|
@@ -12,115 +12,34 @@ const DEFAULT_MODELS = {
|
|
|
12
12
|
gemini: 'gemini-3-pro-preview'
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
//
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
{ id: 'sonar-reasoning', description: 'Chain-of-thought problem solving' },
|
|
20
|
-
{ id: 'sonar-reasoning-pro', description: 'Advanced reasoning (DeepSeek-R1)' },
|
|
21
|
-
{ id: 'sonar-deep-research', description: 'Deep research sessions' }
|
|
22
|
-
]
|
|
23
|
-
|
|
24
|
-
// xAI doesn't have a public models list API, so we hardcode these
|
|
25
|
-
const XAI_MODELS = [
|
|
26
|
-
{ id: 'grok-4-1-fast-reasoning', description: 'Grok 4.1 fast with reasoning' },
|
|
27
|
-
{ id: 'grok-4-1-fast-non-reasoning', description: 'Grok 4.1 fast without reasoning' },
|
|
28
|
-
{ id: 'grok-code-fast-1', description: 'Grok optimized for code' },
|
|
29
|
-
{ id: 'grok-4-fast-reasoning', description: 'Grok 4 fast with reasoning' },
|
|
30
|
-
{ id: 'grok-4-fast-non-reasoning', description: 'Grok 4 fast without reasoning' },
|
|
31
|
-
{ id: 'grok-4-0709', description: 'Grok 4 flagship model' },
|
|
32
|
-
{ id: 'grok-3-mini', description: 'Lightweight Grok 3 model' },
|
|
33
|
-
{ id: 'grok-3', description: 'Grok 3 base model' },
|
|
34
|
-
{ id: 'grok-2-vision-1212', description: 'Grok 2 with vision capabilities' },
|
|
35
|
-
{ id: 'grok-2-image-1212', description: 'Image generation model' }
|
|
36
|
-
]
|
|
37
|
-
|
|
38
|
-
async function fetchOpenAiModels(apiKey) {
|
|
39
|
-
const response = await fetch('https://api.openai.com/v1/models', {
|
|
40
|
-
// biome-ignore lint/style/useNamingConvention: headers use standard capitalization
|
|
41
|
-
headers: { Authorization: `Bearer ${apiKey}` }
|
|
42
|
-
})
|
|
15
|
+
// Provider name mapping (askimo name → models.dev name)
|
|
16
|
+
const PROVIDER_MAP = {
|
|
17
|
+
gemini: 'google'
|
|
18
|
+
}
|
|
43
19
|
|
|
20
|
+
async function fetchModelsFromApi() {
|
|
21
|
+
const response = await fetch('https://models.dev/api.json')
|
|
44
22
|
if (!response.ok) {
|
|
45
|
-
throw new Error(`
|
|
23
|
+
throw new Error(`models.dev API error: ${response.status}`)
|
|
46
24
|
}
|
|
47
|
-
|
|
48
|
-
const data = await response.json()
|
|
49
|
-
return data.data.map((m) => ({ id: m.id, created: m.created })).sort((a, b) => b.created - a.created)
|
|
25
|
+
return response.json()
|
|
50
26
|
}
|
|
51
27
|
|
|
52
|
-
async function
|
|
53
|
-
const
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
'anthropic-version': '2023-06-01'
|
|
57
|
-
}
|
|
58
|
-
})
|
|
28
|
+
async function listModels(provider) {
|
|
29
|
+
const apiData = await fetchModelsFromApi()
|
|
30
|
+
const providerKey = PROVIDER_MAP[provider] || provider
|
|
31
|
+
const providerData = apiData[providerKey]
|
|
59
32
|
|
|
60
|
-
if (!
|
|
61
|
-
throw new Error(`
|
|
33
|
+
if (!providerData) {
|
|
34
|
+
throw new Error(`Unknown provider: ${provider}`)
|
|
62
35
|
}
|
|
63
36
|
|
|
64
|
-
|
|
65
|
-
return data.data.map((m) => ({
|
|
37
|
+
return Object.values(providerData.models).map((m) => ({
|
|
66
38
|
id: m.id,
|
|
67
|
-
|
|
39
|
+
description: m.name
|
|
68
40
|
}))
|
|
69
41
|
}
|
|
70
42
|
|
|
71
|
-
async function fetchGeminiModels(apiKey) {
|
|
72
|
-
const response = await fetch(`https://generativelanguage.googleapis.com/v1beta/models?key=${apiKey}`)
|
|
73
|
-
|
|
74
|
-
if (!response.ok) {
|
|
75
|
-
throw new Error(`Google AI API error: ${response.status}`)
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
const data = await response.json()
|
|
79
|
-
return data.models
|
|
80
|
-
.filter((m) => m.name.includes('gemini'))
|
|
81
|
-
.map((m) => ({
|
|
82
|
-
id: m.name.replace('models/', ''),
|
|
83
|
-
displayName: m.displayName
|
|
84
|
-
}))
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
async function listModels(provider, config) {
|
|
88
|
-
switch (provider) {
|
|
89
|
-
case 'perplexity':
|
|
90
|
-
return PERPLEXITY_MODELS
|
|
91
|
-
|
|
92
|
-
case 'openai': {
|
|
93
|
-
const apiKey = config.OPENAI_API_KEY
|
|
94
|
-
if (!apiKey) {
|
|
95
|
-
throw new Error('OPENAI_API_KEY not found in config')
|
|
96
|
-
}
|
|
97
|
-
return fetchOpenAiModels(apiKey)
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
case 'anthropic': {
|
|
101
|
-
const apiKey = config.ANTHROPIC_API_KEY
|
|
102
|
-
if (!apiKey) {
|
|
103
|
-
throw new Error('ANTHROPIC_API_KEY not found in config')
|
|
104
|
-
}
|
|
105
|
-
return fetchAnthropicModels(apiKey)
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
case 'xai':
|
|
109
|
-
return XAI_MODELS
|
|
110
|
-
|
|
111
|
-
case 'gemini': {
|
|
112
|
-
const apiKey = config.GOOGLE_GENERATIVE_AI_API_KEY
|
|
113
|
-
if (!apiKey) {
|
|
114
|
-
throw new Error('GOOGLE_GENERATIVE_AI_API_KEY not found in config')
|
|
115
|
-
}
|
|
116
|
-
return fetchGeminiModels(apiKey)
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
default:
|
|
120
|
-
throw new Error(`Unknown provider: ${provider}`)
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
|
|
124
43
|
function getProvider(providerName, config) {
|
|
125
44
|
switch (providerName) {
|
|
126
45
|
case 'perplexity': {
|
package/lib/stream.mjs
CHANGED
|
@@ -55,6 +55,25 @@ async function generateResponse(model, messages) {
|
|
|
55
55
|
return { text, sources, duration }
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
+
function printResponse(text, sources, duration, modelName) {
|
|
59
|
+
process.stdout.write(text)
|
|
60
|
+
process.stdout.write('\n')
|
|
61
|
+
|
|
62
|
+
if (sources?.length > 0) {
|
|
63
|
+
process.stdout.write('\n\x1b[2m─── Sources ───\x1b[0m\n')
|
|
64
|
+
sources.forEach((source, index) => {
|
|
65
|
+
const num = index + 1
|
|
66
|
+
const title = source.title || source.url
|
|
67
|
+
process.stdout.write(`\x1b[2m[${num}] ${title}\x1b[0m\n`)
|
|
68
|
+
if (source.url && source.title) {
|
|
69
|
+
process.stdout.write(`\x1b[2m ${source.url}\x1b[0m\n`)
|
|
70
|
+
}
|
|
71
|
+
})
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
process.stdout.write(`\n\x1b[2m${modelName} · ${formatDuration(duration)}\x1b[0m\n`)
|
|
75
|
+
}
|
|
76
|
+
|
|
58
77
|
function buildJsonOutput(conversation, response, sources, duration) {
|
|
59
78
|
const lastUserMessage = conversation.messages.findLast((m) => m.role === 'user')
|
|
60
79
|
const output = {
|
|
@@ -79,4 +98,4 @@ function outputJson(conversation, response, sources, duration) {
|
|
|
79
98
|
console.log(JSON.stringify(output, null, 2))
|
|
80
99
|
}
|
|
81
100
|
|
|
82
|
-
export { streamResponse, generateResponse, outputJson, buildJsonOutput }
|
|
101
|
+
export { streamResponse, generateResponse, printResponse, outputJson, buildJsonOutput }
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "askimo",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.0",
|
|
4
4
|
"description": "A CLI tool for communicating with AI providers (Perplexity, OpenAI, Anthropic)",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "Amit Tal",
|
|
@@ -20,10 +20,6 @@
|
|
|
20
20
|
"bin": {
|
|
21
21
|
"askimo": "./index.mjs"
|
|
22
22
|
},
|
|
23
|
-
"scripts": {
|
|
24
|
-
"test": "ava",
|
|
25
|
-
"lint": "biome check --write"
|
|
26
|
-
},
|
|
27
23
|
"ava": {
|
|
28
24
|
"files": [
|
|
29
25
|
"test/**/*.mjs"
|
|
@@ -32,18 +28,22 @@
|
|
|
32
28
|
"repository": "https://github.com/amitosdev/askimo.git",
|
|
33
29
|
"homepage": "https://github.com/amitosdev/askimo#readme",
|
|
34
30
|
"devDependencies": {
|
|
35
|
-
"@biomejs/biome": "^2.
|
|
31
|
+
"@biomejs/biome": "^2.4.4",
|
|
36
32
|
"ava": "^6.4.1"
|
|
37
33
|
},
|
|
38
34
|
"dependencies": {
|
|
39
|
-
"@ai-sdk/anthropic": "^3.0.
|
|
40
|
-
"@ai-sdk/google": "^3.0.
|
|
41
|
-
"@ai-sdk/openai": "^3.0.
|
|
42
|
-
"@ai-sdk/perplexity": "^3.0.
|
|
43
|
-
"@ai-sdk/xai": "^3.0.
|
|
44
|
-
"@inquirer/input": "^5.0.
|
|
45
|
-
"ai": "^6.0.
|
|
46
|
-
"commander": "^14.0.
|
|
35
|
+
"@ai-sdk/anthropic": "^3.0.46",
|
|
36
|
+
"@ai-sdk/google": "^3.0.30",
|
|
37
|
+
"@ai-sdk/openai": "^3.0.30",
|
|
38
|
+
"@ai-sdk/perplexity": "^3.0.19",
|
|
39
|
+
"@ai-sdk/xai": "^3.0.57",
|
|
40
|
+
"@inquirer/input": "^5.0.7",
|
|
41
|
+
"ai": "^6.0.97",
|
|
42
|
+
"commander": "^14.0.3",
|
|
47
43
|
"hcat": "^2.2.1"
|
|
44
|
+
},
|
|
45
|
+
"scripts": {
|
|
46
|
+
"test": "ava",
|
|
47
|
+
"lint": "biome check --write"
|
|
48
48
|
}
|
|
49
|
-
}
|
|
49
|
+
}
|