pokt-cli 1.0.12 → 1.0.13
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/bin/pokt.js +15 -3
- package/dist/chat/client.js +2 -2
- package/dist/commands/chat.js +6 -2
- package/dist/commands/models.js +6 -3
- package/dist/commands/provider.js +2 -2
- package/dist/config.d.ts +3 -1
- package/dist/config.js +25 -3
- package/dist/mcp/client.js +3 -3
- package/package.json +1 -1
package/dist/bin/pokt.js
CHANGED
|
@@ -124,7 +124,7 @@ async function showMenu() {
|
|
|
124
124
|
}
|
|
125
125
|
}
|
|
126
126
|
async function handleModelsMenu(providerFilter) {
|
|
127
|
-
const { config, getEffectiveActiveModel, PROVIDER_LABELS, ALL_PROVIDERS } = await import('../config.js');
|
|
127
|
+
const { config, getEffectiveActiveModel, PROVIDER_LABELS, ALL_PROVIDERS, getOllamaCloudApiKey } = await import('../config.js');
|
|
128
128
|
let allModels = config.get('registeredModels');
|
|
129
129
|
if (!Array.isArray(allModels)) {
|
|
130
130
|
const defaults = [
|
|
@@ -157,8 +157,20 @@ async function handleModelsMenu(providerFilter) {
|
|
|
157
157
|
return handleAddModelsMenu();
|
|
158
158
|
return handleModelsMenu(cat.category);
|
|
159
159
|
}
|
|
160
|
-
// Segunda tela: listar modelos da categoria escolhida
|
|
161
|
-
|
|
160
|
+
// Segunda tela: listar modelos da categoria escolhida — sincroniza da API se a lista estiver vazia e houver credencial (ou API pública OpenRouter)
|
|
161
|
+
let providerModels = allModels.filter((m) => m.provider === providerFilter);
|
|
162
|
+
if (providerModels.length === 0 && providerFilter === 'openrouter') {
|
|
163
|
+
const { modelsCommand } = await import('../commands/models.js');
|
|
164
|
+
await modelsCommand.handler({ action: 'fetch-openrouter' });
|
|
165
|
+
allModels = config.get('registeredModels');
|
|
166
|
+
providerModels = allModels.filter((m) => m.provider === providerFilter);
|
|
167
|
+
}
|
|
168
|
+
if (providerModels.length === 0 && providerFilter === 'ollama-cloud' && getOllamaCloudApiKey()) {
|
|
169
|
+
const { modelsCommand } = await import('../commands/models.js');
|
|
170
|
+
await modelsCommand.handler({ action: 'fetch-ollama-cloud' });
|
|
171
|
+
allModels = config.get('registeredModels');
|
|
172
|
+
providerModels = allModels.filter((m) => m.provider === providerFilter);
|
|
173
|
+
}
|
|
162
174
|
const label = PROVIDER_LABELS[providerFilter] || providerFilter;
|
|
163
175
|
const choices = [
|
|
164
176
|
...providerModels.map((m, i) => ({
|
package/dist/chat/client.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import OpenAI from 'openai';
|
|
2
|
-
import { getPoktApiBaseUrl,
|
|
2
|
+
import { getPoktApiBaseUrl, getOpenAIApiKey, getGrokApiKey, getOpenRouterToken, getGeminiApiKey, getOllamaCloudApiKey, getOllamaBaseUrl, getPoktToken, } from '../config.js';
|
|
3
3
|
export async function getClient(modelConfig) {
|
|
4
4
|
// openai / grok / … → hosts oficiais abaixo. Só `controller` usa getPoktApiBaseUrl (token Pokt, não é api.openai.com).
|
|
5
5
|
if (modelConfig.provider === 'controller') {
|
|
6
6
|
const baseUrl = getPoktApiBaseUrl();
|
|
7
7
|
const token = getPoktToken();
|
|
8
8
|
if (!token) {
|
|
9
|
-
throw new Error(
|
|
9
|
+
throw new Error('Token Pokt não configurado. Use: pokt config set-pokt-token -v <token>');
|
|
10
10
|
}
|
|
11
11
|
return new OpenAI({
|
|
12
12
|
baseURL: `${baseUrl}/api/v1`,
|
package/dist/commands/chat.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getEffectiveActiveModel, getOpenAIApiKey, getGrokApiKey, getOpenRouterToken, getGeminiApiKey,
|
|
1
|
+
import { getEffectiveActiveModel, getOpenAIApiKey, getGrokApiKey, getOpenRouterToken, getGeminiApiKey, getOllamaCloudApiKey, getPoktToken, } from '../config.js';
|
|
2
2
|
import { startChatLoop } from '../chat/loop.js';
|
|
3
3
|
import { ui } from '../ui.js';
|
|
4
4
|
export const chatCommand = {
|
|
@@ -27,9 +27,13 @@ export const chatCommand = {
|
|
|
27
27
|
console.log(ui.error('Gemini API key not set. Use: pokt config set-gemini -v <key>'));
|
|
28
28
|
return;
|
|
29
29
|
}
|
|
30
|
+
if (activeModel.provider === 'ollama-cloud' && !getOllamaCloudApiKey()) {
|
|
31
|
+
console.log(ui.error('Ollama Cloud API key not set. Use: pokt config set-ollama-cloud -v <key>'));
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
30
34
|
if (activeModel.provider === 'controller') {
|
|
31
35
|
if (!getPoktToken()) {
|
|
32
|
-
console.log(ui.error(
|
|
36
|
+
console.log(ui.error('Pokt token not set. Use: pokt config set-pokt-token -v <token>'));
|
|
33
37
|
return;
|
|
34
38
|
}
|
|
35
39
|
}
|
package/dist/commands/models.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { config, getEffectiveActiveModel, PROVIDER_LABELS, getOpenAIApiKey, getGrokApiKey } from '../config.js';
|
|
1
|
+
import { config, getEffectiveActiveModel, PROVIDER_LABELS, getOpenAIApiKey, getGrokApiKey, getOpenRouterToken, getOllamaCloudApiKey } from '../config.js';
|
|
2
2
|
import chalk from 'chalk';
|
|
3
3
|
import ora from 'ora';
|
|
4
4
|
import { ui } from '../ui.js';
|
|
@@ -101,7 +101,10 @@ export const modelsCommand = {
|
|
|
101
101
|
if (action === 'fetch-openrouter') {
|
|
102
102
|
const spinner = ora('Fetching OpenRouter models...').start();
|
|
103
103
|
try {
|
|
104
|
-
const
|
|
104
|
+
const orToken = getOpenRouterToken();
|
|
105
|
+
const response = await fetch('https://openrouter.ai/api/v1/models', {
|
|
106
|
+
headers: orToken ? { Authorization: `Bearer ${orToken}` } : undefined,
|
|
107
|
+
});
|
|
105
108
|
if (!response.ok) {
|
|
106
109
|
spinner.fail(ui.error(`Failed to fetch OpenRouter models: HTTP ${response.status}`));
|
|
107
110
|
const body = await response.text();
|
|
@@ -149,7 +152,7 @@ export const modelsCommand = {
|
|
|
149
152
|
return;
|
|
150
153
|
}
|
|
151
154
|
if (action === 'fetch-ollama-cloud') {
|
|
152
|
-
const apiKey =
|
|
155
|
+
const apiKey = getOllamaCloudApiKey();
|
|
153
156
|
if (!apiKey) {
|
|
154
157
|
console.log(ui.error('Ollama Cloud API key not set. Run: pokt config set-ollama-cloud -v <key>'));
|
|
155
158
|
console.log(ui.dim('Create keys at: https://ollama.com/settings/keys'));
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { config, ALL_PROVIDERS, getOpenAIApiKey, getGrokApiKey, getOpenRouterToken, getGeminiApiKey, getOllamaCloudApiKey, getPoktToken,
|
|
1
|
+
import { config, ALL_PROVIDERS, getOpenAIApiKey, getGrokApiKey, getOpenRouterToken, getGeminiApiKey, getOllamaCloudApiKey, getPoktToken, } from '../config.js';
|
|
2
2
|
import { ui } from '../ui.js';
|
|
3
3
|
export const providerCommand = {
|
|
4
4
|
command: 'provider use <provider>',
|
|
@@ -54,7 +54,7 @@ export const providerCommand = {
|
|
|
54
54
|
return;
|
|
55
55
|
}
|
|
56
56
|
if (provider === 'controller' && !getPoktToken()) {
|
|
57
|
-
console.log(ui.error(
|
|
57
|
+
console.log(ui.error('Pokt token not set. Use: pokt config set-pokt-token -v <token>'));
|
|
58
58
|
return;
|
|
59
59
|
}
|
|
60
60
|
if (provider === 'ollama-cloud' && !getOllamaCloudApiKey()) {
|
package/dist/config.d.ts
CHANGED
|
@@ -85,6 +85,8 @@ export declare function getTokenPurchaseUrl(): string;
|
|
|
85
85
|
export declare const getControllerBaseUrl: typeof getPoktApiBaseUrl;
|
|
86
86
|
/** URL aberta por `pokt pro` (comprar token) — Vercel por padrão. */
|
|
87
87
|
export declare const getProPurchaseUrl: () => string;
|
|
88
|
-
/**
|
|
88
|
+
/** True se o modelo pode ser usado com as credenciais atuais (evita ficar preso em controller sem token Pokt). */
|
|
89
|
+
export declare function isModelCredentialReady(model: ModelConfig): boolean;
|
|
90
|
+
/** Prioridade: modelo ativo explícito (se credenciais OK) → Pokt (controller) se token setado → OpenRouter → Gemini → Ollama Cloud → Ollama local */
|
|
89
91
|
export declare function getEffectiveActiveModel(): ModelConfig | null;
|
|
90
92
|
export {};
|
package/dist/config.js
CHANGED
|
@@ -162,10 +162,31 @@ export function getTokenPurchaseUrl() {
|
|
|
162
162
|
export const getControllerBaseUrl = getPoktApiBaseUrl;
|
|
163
163
|
/** URL aberta por `pokt pro` (comprar token) — Vercel por padrão. */
|
|
164
164
|
export const getProPurchaseUrl = () => getTokenPurchaseUrl();
|
|
165
|
-
/**
|
|
165
|
+
/** True se o modelo pode ser usado com as credenciais atuais (evita ficar preso em controller sem token Pokt). */
|
|
166
|
+
export function isModelCredentialReady(model) {
|
|
167
|
+
switch (model.provider) {
|
|
168
|
+
case 'controller':
|
|
169
|
+
return !!getPoktToken();
|
|
170
|
+
case 'openai':
|
|
171
|
+
return !!getOpenAIApiKey();
|
|
172
|
+
case 'grok':
|
|
173
|
+
return !!getGrokApiKey();
|
|
174
|
+
case 'openrouter':
|
|
175
|
+
return !!getOpenRouterToken();
|
|
176
|
+
case 'gemini':
|
|
177
|
+
return !!getGeminiApiKey();
|
|
178
|
+
case 'ollama-cloud':
|
|
179
|
+
return !!getOllamaCloudApiKey();
|
|
180
|
+
case 'ollama':
|
|
181
|
+
return true;
|
|
182
|
+
default:
|
|
183
|
+
return false;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
/** Prioridade: modelo ativo explícito (se credenciais OK) → Pokt (controller) se token setado → OpenRouter → Gemini → Ollama Cloud → Ollama local */
|
|
166
187
|
export function getEffectiveActiveModel() {
|
|
167
188
|
const explicit = config.get('activeModel');
|
|
168
|
-
if (explicit)
|
|
189
|
+
if (explicit && isModelCredentialReady(explicit))
|
|
169
190
|
return explicit;
|
|
170
191
|
const models = config.get('registeredModels');
|
|
171
192
|
if (getPoktToken()) {
|
|
@@ -201,5 +222,6 @@ export function getEffectiveActiveModel() {
|
|
|
201
222
|
const ollama = models.find((m) => m.provider === 'ollama');
|
|
202
223
|
if (ollama)
|
|
203
224
|
return ollama;
|
|
204
|
-
|
|
225
|
+
const anyUsable = models.find((m) => isModelCredentialReady(m));
|
|
226
|
+
return anyUsable ?? null;
|
|
205
227
|
}
|
package/dist/mcp/client.js
CHANGED
|
@@ -77,7 +77,7 @@ async function connectMcpStdio(serverConfig) {
|
|
|
77
77
|
args: serverConfig.args ?? [],
|
|
78
78
|
env: mergeProcessEnv(serverConfig.env),
|
|
79
79
|
});
|
|
80
|
-
const client = new Client({ name: 'pokt-cli', version: '1.0.
|
|
80
|
+
const client = new Client({ name: 'pokt-cli', version: '1.0.13' });
|
|
81
81
|
await client.connect(transport);
|
|
82
82
|
const tools = await buildToolsFromClient(serverConfig, client);
|
|
83
83
|
return pushSession(serverConfig, client, tools, transport);
|
|
@@ -112,7 +112,7 @@ async function connectMcpHttp(serverConfig) {
|
|
|
112
112
|
}
|
|
113
113
|
return makeStreamableTransport(url, { authProvider, headers });
|
|
114
114
|
};
|
|
115
|
-
const client = new Client({ name: 'pokt-cli', version: '1.0.
|
|
115
|
+
const client = new Client({ name: 'pokt-cli', version: '1.0.13' });
|
|
116
116
|
let transport = await makeTransport();
|
|
117
117
|
const cleanupCb = async () => {
|
|
118
118
|
try {
|
|
@@ -151,7 +151,7 @@ async function connectMcpHttp(serverConfig) {
|
|
|
151
151
|
const transport = useSse
|
|
152
152
|
? await makeSseTransport(url, { headers })
|
|
153
153
|
: await makeStreamableTransport(url, { headers });
|
|
154
|
-
const client = new Client({ name: 'pokt-cli', version: '1.0.
|
|
154
|
+
const client = new Client({ name: 'pokt-cli', version: '1.0.13' });
|
|
155
155
|
await client.connect(transport);
|
|
156
156
|
const tools = await buildToolsFromClient(serverConfig, client);
|
|
157
157
|
return pushSession(serverConfig, client, tools, transport);
|