@zhive/cli 0.5.4 → 0.5.5
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.
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { getMemoryLineCount, loadMemory, MEMORY_SOFT_LIMIT, saveMemory, } from '@zhive/sdk';
|
|
2
2
|
import * as ai from 'ai';
|
|
3
3
|
import { z } from 'zod';
|
|
4
|
-
import { getModel } from '../config/ai-providers.js';
|
|
4
|
+
import { getModel, getScreenModel } from '../config/ai-providers.js';
|
|
5
5
|
import { buildMemoryExtractionPrompt } from './prompts/memory-prompt.js';
|
|
6
6
|
import { extractErrorMessage, stripCodeFences } from './utils.js';
|
|
7
7
|
import { wrapAISDK } from 'langsmith/experimental/vercel';
|
|
8
8
|
import { buildScreenPrompt } from './prompts/prompt.js';
|
|
9
9
|
import { buildMegathreadInputPrompt, buildMegathreadSystemPrompt, } from './prompts/megathread.js';
|
|
10
10
|
import { clearSubagentUsage, getSubagentUsage, } from './tools/index.js';
|
|
11
|
-
const { ToolLoopAgent, generateText, Output } = wrapAISDK(ai);
|
|
11
|
+
const { ToolLoopAgent, generateText, generateObject, Output } = wrapAISDK(ai);
|
|
12
12
|
// ─── Cache Helpers ─────────────────────────────────
|
|
13
13
|
function cacheableSystem(content) {
|
|
14
14
|
const message = {
|
|
@@ -63,11 +63,11 @@ export async function screenMegathreadRound(projectId, strategyContent) {
|
|
|
63
63
|
const { system, prompt } = buildScreenPrompt(strategyContent, {
|
|
64
64
|
projectId,
|
|
65
65
|
});
|
|
66
|
-
const model = await
|
|
67
|
-
const res = await
|
|
66
|
+
const model = await getScreenModel();
|
|
67
|
+
const res = await generateObject({
|
|
68
68
|
model,
|
|
69
69
|
messages: [cacheableSystem(system), { role: 'user', content: prompt }],
|
|
70
|
-
|
|
70
|
+
schema: screenSchema,
|
|
71
71
|
});
|
|
72
72
|
const usage = {
|
|
73
73
|
inputTokens: res.usage?.inputTokens ?? 0,
|
|
@@ -78,11 +78,7 @@ export async function screenMegathreadRound(projectId, strategyContent) {
|
|
|
78
78
|
toolNames: [],
|
|
79
79
|
toolResults: [],
|
|
80
80
|
};
|
|
81
|
-
|
|
82
|
-
if (!output) {
|
|
83
|
-
return { engage: true, usage };
|
|
84
|
-
}
|
|
85
|
-
return { engage: output.engage, usage };
|
|
81
|
+
return { engage: res.object.engage, usage };
|
|
86
82
|
}
|
|
87
83
|
catch (err) {
|
|
88
84
|
const emptyUsage = {
|
|
@@ -136,9 +132,10 @@ export async function processMegathreadRound({ projectId, durationMs, recentComm
|
|
|
136
132
|
return { skip: true, summary: '', conviction: 0, usage };
|
|
137
133
|
}
|
|
138
134
|
const prediction = output;
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
135
|
+
if (prediction.summary === null || prediction.conviction === null) {
|
|
136
|
+
return { skip: true, summary: '', conviction: 0, usage };
|
|
137
|
+
}
|
|
138
|
+
return { skip: false, summary: prediction.summary, conviction: prediction.conviction, usage };
|
|
142
139
|
}
|
|
143
140
|
// ─── Memory Extraction ──────────────────────────────
|
|
144
141
|
export async function extractAndSaveMemory(sessionMessages) {
|
|
@@ -8,7 +8,7 @@ Your trading strategy:
|
|
|
8
8
|
${strategyContent}
|
|
9
9
|
---
|
|
10
10
|
|
|
11
|
-
Only engage with projects that match the agent's sectors and expertise as defined in the trading strategy above.
|
|
11
|
+
Only engage with projects that match the agent's sectors and expertise as defined in the trading strategy above. If the strategy's sectors include "all" or cover all sectors, always engage — the agent predicts on everything.
|
|
12
12
|
|
|
13
13
|
Answer with only "yes" or "no".`;
|
|
14
14
|
const prompt = `Project: ${projectId}
|
|
@@ -127,30 +127,36 @@ export function resolveModelInfo() {
|
|
|
127
127
|
}
|
|
128
128
|
return { provider: 'unknown', modelId: 'unknown', source: 'unknown' };
|
|
129
129
|
}
|
|
130
|
+
async function _loadModelForTier(tier) {
|
|
131
|
+
const agentKeys = getAgentProviderKeys();
|
|
132
|
+
const sortedProviders = [
|
|
133
|
+
...AI_PROVIDERS.filter((p) => agentKeys.has(p.envVar)),
|
|
134
|
+
...AI_PROVIDERS.filter((p) => !agentKeys.has(p.envVar)),
|
|
135
|
+
];
|
|
136
|
+
for (const provider of sortedProviders) {
|
|
137
|
+
const keyValue = process.env[provider.envVar];
|
|
138
|
+
if (keyValue && keyValue.trim().length > 0) {
|
|
139
|
+
const overrideModel = process.env.HIVE_MODEL;
|
|
140
|
+
const modelId = tier === 'runtime' && overrideModel ? overrideModel : provider.models[tier];
|
|
141
|
+
const model = await provider.load(modelId);
|
|
142
|
+
return model;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
throw new Error('No AI provider API key found in environment. ' +
|
|
146
|
+
'Set one of: ANTHROPIC_API_KEY, OPENAI_API_KEY, GOOGLE_GENERATIVE_AI_API_KEY, XAI_API_KEY, OPENROUTER_API_KEY');
|
|
147
|
+
}
|
|
148
|
+
let _screenModelPromise = null;
|
|
149
|
+
export function getScreenModel() {
|
|
150
|
+
if (_screenModelPromise) {
|
|
151
|
+
return _screenModelPromise;
|
|
152
|
+
}
|
|
153
|
+
_screenModelPromise = _loadModelForTier('validation');
|
|
154
|
+
return _screenModelPromise;
|
|
155
|
+
}
|
|
130
156
|
export function getModel() {
|
|
131
157
|
if (_modelPromise) {
|
|
132
158
|
return _modelPromise;
|
|
133
159
|
}
|
|
134
|
-
_modelPromise = (
|
|
135
|
-
const info = resolveModelInfo();
|
|
136
|
-
if (info.provider === 'unknown') {
|
|
137
|
-
throw new Error('No AI provider API key found in environment. ' +
|
|
138
|
-
'Set one of: ANTHROPIC_API_KEY, OPENAI_API_KEY, GOOGLE_GENERATIVE_AI_API_KEY, XAI_API_KEY, OPENROUTER_API_KEY');
|
|
139
|
-
}
|
|
140
|
-
const agentKeys = getAgentProviderKeys();
|
|
141
|
-
const sortedProviders = [
|
|
142
|
-
...AI_PROVIDERS.filter((p) => agentKeys.has(p.envVar)),
|
|
143
|
-
...AI_PROVIDERS.filter((p) => !agentKeys.has(p.envVar)),
|
|
144
|
-
];
|
|
145
|
-
for (const provider of sortedProviders) {
|
|
146
|
-
const keyValue = process.env[provider.envVar];
|
|
147
|
-
if (keyValue && keyValue.trim().length > 0) {
|
|
148
|
-
const modelId = info.modelId;
|
|
149
|
-
const model = await provider.load(modelId);
|
|
150
|
-
return model;
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
throw new Error('Unreachable: resolveModelInfo succeeded but no provider found');
|
|
154
|
-
})();
|
|
160
|
+
_modelPromise = _loadModelForTier('runtime');
|
|
155
161
|
return _modelPromise;
|
|
156
162
|
}
|