@orxataguy/tyr 1.0.38 → 1.0.39
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/package.json +1 -1
- package/src/core/sys/chat.ts +21 -4
package/package.json
CHANGED
package/src/core/sys/chat.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import path from 'path';
|
|
2
2
|
import { readFile } from 'fs/promises';
|
|
3
3
|
import { TyrContext } from '../Kernel';
|
|
4
|
-
import type { AIContentBlock, AIMessage } from '../../lib/AIVendorManager';
|
|
4
|
+
import type { AIContentBlock, AIMessage, TaskPriority } from '../../lib/AIVendorManager';
|
|
5
5
|
import type { ChatMessageContext } from '../../lib/ChatManager';
|
|
6
6
|
|
|
7
7
|
function parseFlag(args: string[], name: string): string | undefined {
|
|
@@ -19,9 +19,25 @@ export default function chat({ logger, chat: chatManager, aiVendor, fail }: TyrC
|
|
|
19
19
|
const port = portArg ? parseInt(portArg, 10) : undefined;
|
|
20
20
|
const splitRatio = splitArg ? parseFloat(splitArg) : undefined;
|
|
21
21
|
|
|
22
|
+
// Which routing priority (model tier + thinking effort) answers a chat message with —
|
|
23
|
+
// see AIVendorManager.TaskPriority. Chat defaults to 'media-prioridad' (the same default
|
|
24
|
+
// ai:code uses) rather than something cheaper, since a wrong answer in an interactive
|
|
25
|
+
// back-and-forth is more disruptive than in a one-shot batch command.
|
|
26
|
+
const priority = (parseFlag(args, '--priority') as TaskPriority | undefined) ?? 'media-prioridad';
|
|
27
|
+
|
|
28
|
+
// Complexity/cost ceiling ("techo de complejidad"): no resolved priority may ever exceed
|
|
29
|
+
// this, no matter what --priority above (or a future per-message override) asks for. Falls
|
|
30
|
+
// back to AI_CHAT_MAX_PRIORITY so a chat session can be capped independently from ai:code /
|
|
31
|
+
// ai:describe (which fall back to the general AI_MAX_PRIORITY instead — see
|
|
32
|
+
// AIVendorManager.getPriorityCeiling()). --max-priority overrides both for this one run.
|
|
33
|
+
const maxPriority = (parseFlag(args, '--max-priority') as TaskPriority | undefined)
|
|
34
|
+
?? (process.env.AI_CHAT_MAX_PRIORITY as TaskPriority | undefined);
|
|
35
|
+
if (maxPriority) aiVendor.setPriorityCeiling(maxPriority);
|
|
36
|
+
|
|
22
37
|
// Default responder: forwards the conversation (plus any attached images) to the
|
|
23
|
-
// configured AI vendor
|
|
24
|
-
//
|
|
38
|
+
// configured AI vendor, routed through the same priority/ceiling system as ai:code and
|
|
39
|
+
// ai:describe. Replace with your own chatManager.onMessage(...) in a custom command if you
|
|
40
|
+
// want different behaviour.
|
|
25
41
|
chatManager.onMessage(async ({ message, history, dir: chatDir }: ChatMessageContext) => {
|
|
26
42
|
const priorTurns: AIMessage[] = history.slice(0, -1).map((m) => ({
|
|
27
43
|
role: m.role === 'user' ? 'user' : 'assistant',
|
|
@@ -49,7 +65,7 @@ export default function chat({ logger, chat: chatManager, aiVendor, fail }: TyrC
|
|
|
49
65
|
{ role: 'user', content: contentBlocks.length > 0 ? contentBlocks : message.text },
|
|
50
66
|
];
|
|
51
67
|
|
|
52
|
-
const result = await aiVendor.
|
|
68
|
+
const result = await aiVendor.completeWithPriority(messages, priority);
|
|
53
69
|
return result.content;
|
|
54
70
|
});
|
|
55
71
|
|
|
@@ -65,6 +81,7 @@ export default function chat({ logger, chat: chatManager, aiVendor, fail }: TyrC
|
|
|
65
81
|
const session = await chatManager.open(dir, { port, splitRatio });
|
|
66
82
|
logger.success(`Chat ready at: ${session.url}`);
|
|
67
83
|
logger.info(`Browsing: ${session.dir}`);
|
|
84
|
+
logger.info(`Priority: ${priority}${maxPriority ? ` (ceiling: ${maxPriority})` : ''}`);
|
|
68
85
|
logger.info('Press Ctrl+C to stop.');
|
|
69
86
|
} catch (e: any) {
|
|
70
87
|
fail(`Could not start chat: ${e.message}`, 'Check that the directory exists and the port is free.');
|