elyth-agent 0.1.0 → 0.2.1
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/LICENSE +21 -0
- package/README.md +495 -0
- package/dist/agent.d.ts +8 -0
- package/dist/agent.d.ts.map +1 -1
- package/dist/agent.js +66 -55
- package/dist/agent.js.map +1 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +119 -140
- package/dist/cli.js.map +1 -1
- package/dist/config.d.ts +1 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +10 -10
- package/dist/config.js.map +1 -1
- package/dist/dev-session.d.ts +3 -0
- package/dist/dev-session.d.ts.map +1 -0
- package/dist/dev-session.js +240 -0
- package/dist/dev-session.js.map +1 -0
- package/dist/logger.js +3 -3
- package/dist/logger.js.map +1 -1
- package/dist/prompt/build-prompt.d.ts +1 -1
- package/dist/prompt/build-prompt.d.ts.map +1 -1
- package/dist/prompt/build-prompt.js +6 -2
- package/dist/prompt/build-prompt.js.map +1 -1
- package/dist/prompt/system-base.md +63 -0
- package/dist/providers/gemini.d.ts +1 -3
- package/dist/providers/gemini.d.ts.map +1 -1
- package/dist/providers/gemini.js +73 -91
- package/dist/providers/gemini.js.map +1 -1
- package/dist/scheduler.js +7 -7
- package/dist/scheduler.js.map +1 -1
- package/package.json +30 -31
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
import readline from 'node:readline';
|
|
2
|
+
import { McpClient } from './mcp-client.js';
|
|
3
|
+
import { Logger } from './logger.js';
|
|
4
|
+
import { buildPrompt } from './prompt/build-prompt.js';
|
|
5
|
+
import { createProvider } from './providers/index.js';
|
|
6
|
+
import { executeToolLoop } from './agent.js';
|
|
7
|
+
const COLORS = {
|
|
8
|
+
reset: '\x1b[0m',
|
|
9
|
+
dim: '\x1b[2m',
|
|
10
|
+
cyan: '\x1b[36m',
|
|
11
|
+
green: '\x1b[32m',
|
|
12
|
+
yellow: '\x1b[33m',
|
|
13
|
+
red: '\x1b[31m',
|
|
14
|
+
magenta: '\x1b[35m',
|
|
15
|
+
blue: '\x1b[34m',
|
|
16
|
+
};
|
|
17
|
+
function formatNow() {
|
|
18
|
+
return new Date().toLocaleString('ja-JP', {
|
|
19
|
+
timeZone: 'Asia/Tokyo',
|
|
20
|
+
year: 'numeric',
|
|
21
|
+
month: '2-digit',
|
|
22
|
+
day: '2-digit',
|
|
23
|
+
hour: '2-digit',
|
|
24
|
+
minute: '2-digit',
|
|
25
|
+
weekday: 'short',
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
function prompt(rl) {
|
|
29
|
+
return new Promise((resolve) => {
|
|
30
|
+
rl.question(`${COLORS.cyan}dev>${COLORS.reset} `, resolve);
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
async function handleTick(state) {
|
|
34
|
+
state.tickCount++;
|
|
35
|
+
console.log(`\n${COLORS.cyan}--- Tick #${state.tickCount} ---${COLORS.reset}`);
|
|
36
|
+
state.messages.push({
|
|
37
|
+
role: 'user',
|
|
38
|
+
content: `現在時刻: ${formatNow()}\n行動手順に従い、ELYTHで1サイクルを実行してください。`,
|
|
39
|
+
});
|
|
40
|
+
const startTime = Date.now();
|
|
41
|
+
state.logger.logTickStart(state.config.provider, state.config.model);
|
|
42
|
+
const turns = await executeToolLoop(state.provider, state.systemPrompt, state.messages, state.tools, state.mcp, state.logger, state.config.maxTurns);
|
|
43
|
+
state.logger.logTickEnd(turns, Date.now() - startTime);
|
|
44
|
+
}
|
|
45
|
+
async function handleDialogue(state, input) {
|
|
46
|
+
state.messages.push({
|
|
47
|
+
role: 'user',
|
|
48
|
+
content: `[開発者指示] ${input}`,
|
|
49
|
+
});
|
|
50
|
+
const turns = await executeToolLoop(state.provider, state.systemPrompt, state.messages, state.tools, state.mcp, state.logger, state.config.maxTurns);
|
|
51
|
+
// Print the last assistant message if it was a plain text response
|
|
52
|
+
if (turns > 0) {
|
|
53
|
+
const lastMsg = state.messages[state.messages.length - 1];
|
|
54
|
+
if (lastMsg.role === 'assistant' && typeof lastMsg.content === 'string') {
|
|
55
|
+
console.log(`\n${COLORS.magenta}agent>${COLORS.reset} ${lastMsg.content}\n`);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
function interruptibleSleep(ms, abort) {
|
|
60
|
+
return new Promise((resolve) => {
|
|
61
|
+
const timer = setTimeout(() => resolve(false), ms);
|
|
62
|
+
abort.signal.addEventListener('abort', () => {
|
|
63
|
+
clearTimeout(timer);
|
|
64
|
+
resolve(true);
|
|
65
|
+
}, { once: true });
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
async function handleAuto(state, intervalOverride) {
|
|
69
|
+
const interval = intervalOverride ?? state.config.interval;
|
|
70
|
+
console.log(`\n${COLORS.green}自動モード開始${COLORS.reset}(間隔: ${interval}秒)。/stop で中断できます。\n`);
|
|
71
|
+
state.autoAbort = new AbortController();
|
|
72
|
+
// Pause readline and use a temporary one for /stop detection during sleep
|
|
73
|
+
state.rl.pause();
|
|
74
|
+
while (state.autoAbort && !state.autoAbort.signal.aborted) {
|
|
75
|
+
try {
|
|
76
|
+
await handleTick(state);
|
|
77
|
+
}
|
|
78
|
+
catch (err) {
|
|
79
|
+
console.error(`${COLORS.red}tick失敗:${COLORS.reset}`, err instanceof Error ? err.message : err);
|
|
80
|
+
}
|
|
81
|
+
if (state.autoAbort.signal.aborted)
|
|
82
|
+
break;
|
|
83
|
+
const nextTime = new Date(Date.now() + interval * 1000).toLocaleTimeString();
|
|
84
|
+
console.log(`\n次のtick: ${nextTime}。/stop で中断できます。`);
|
|
85
|
+
// Listen for /stop during sleep using a temporary readline
|
|
86
|
+
const sleepRl = readline.createInterface({
|
|
87
|
+
input: process.stdin,
|
|
88
|
+
output: process.stdout,
|
|
89
|
+
});
|
|
90
|
+
const abort = state.autoAbort;
|
|
91
|
+
const lineHandler = (line) => {
|
|
92
|
+
if (line.trim() === '/stop') {
|
|
93
|
+
abort.abort();
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
sleepRl.on('line', lineHandler);
|
|
97
|
+
const interrupted = await interruptibleSleep(interval * 1000, abort);
|
|
98
|
+
sleepRl.removeListener('line', lineHandler);
|
|
99
|
+
sleepRl.close();
|
|
100
|
+
if (interrupted)
|
|
101
|
+
break;
|
|
102
|
+
}
|
|
103
|
+
state.autoAbort = null;
|
|
104
|
+
state.rl.resume();
|
|
105
|
+
console.log(`${COLORS.green}自動モード停止。${COLORS.reset}\n`);
|
|
106
|
+
}
|
|
107
|
+
function showTools(tools) {
|
|
108
|
+
console.log(`\n${COLORS.cyan}利用可能なツール (${tools.length}):${COLORS.reset}`);
|
|
109
|
+
for (const tool of tools) {
|
|
110
|
+
console.log(` ${COLORS.yellow}${tool.name}${COLORS.reset} - ${tool.description}`);
|
|
111
|
+
}
|
|
112
|
+
console.log('');
|
|
113
|
+
}
|
|
114
|
+
function showHistory(messages) {
|
|
115
|
+
console.log(`\n${COLORS.cyan}メッセージ履歴: ${messages.length} 件${COLORS.reset}`);
|
|
116
|
+
const recent = messages.slice(-10);
|
|
117
|
+
const offset = messages.length - recent.length;
|
|
118
|
+
for (let i = 0; i < recent.length; i++) {
|
|
119
|
+
const msg = recent[i];
|
|
120
|
+
let preview;
|
|
121
|
+
if (typeof msg.content === 'string') {
|
|
122
|
+
preview = msg.content.slice(0, 100);
|
|
123
|
+
if (msg.content.length > 100)
|
|
124
|
+
preview += '...';
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
const types = msg.content.map((b) => b.type);
|
|
128
|
+
preview = `[${types.join(', ')}]`;
|
|
129
|
+
}
|
|
130
|
+
console.log(` ${COLORS.dim}[${offset + i}]${COLORS.reset} ${msg.role}: ${preview}`);
|
|
131
|
+
}
|
|
132
|
+
console.log('');
|
|
133
|
+
}
|
|
134
|
+
function showHelp() {
|
|
135
|
+
console.log(`
|
|
136
|
+
${COLORS.cyan}コマンド:${COLORS.reset}
|
|
137
|
+
/tick 自律tickサイクルを1回実行
|
|
138
|
+
/auto [間隔] 自動tickループを開始(デフォルト: 設定値)
|
|
139
|
+
/stop 自動tickループを停止(自動モード中)
|
|
140
|
+
/tools 利用可能なMCPツールを一覧表示
|
|
141
|
+
/history メッセージ履歴の概要を表示
|
|
142
|
+
/clear メッセージ履歴をクリア
|
|
143
|
+
/help このヘルプを表示
|
|
144
|
+
/exit 切断して終了
|
|
145
|
+
|
|
146
|
+
${COLORS.cyan}テキスト入力:${COLORS.reset}
|
|
147
|
+
コマンド以外の入力は開発者指示としてエージェントに送信されます。
|
|
148
|
+
エージェントはMCPツールを使って応答できます。
|
|
149
|
+
`);
|
|
150
|
+
}
|
|
151
|
+
async function dispatch(state, input) {
|
|
152
|
+
if (!input)
|
|
153
|
+
return false;
|
|
154
|
+
if (input.startsWith('/')) {
|
|
155
|
+
const [cmd, ...args] = input.split(/\s+/);
|
|
156
|
+
switch (cmd) {
|
|
157
|
+
case '/tick':
|
|
158
|
+
await handleTick(state);
|
|
159
|
+
break;
|
|
160
|
+
case '/auto': {
|
|
161
|
+
const interval = args[0] ? parseInt(args[0], 10) : undefined;
|
|
162
|
+
await handleAuto(state, interval);
|
|
163
|
+
break;
|
|
164
|
+
}
|
|
165
|
+
case '/stop':
|
|
166
|
+
console.log('自動モードではありません。');
|
|
167
|
+
break;
|
|
168
|
+
case '/tools':
|
|
169
|
+
showTools(state.tools);
|
|
170
|
+
break;
|
|
171
|
+
case '/history':
|
|
172
|
+
showHistory(state.messages);
|
|
173
|
+
break;
|
|
174
|
+
case '/clear':
|
|
175
|
+
state.messages = [];
|
|
176
|
+
console.log('メッセージ履歴をクリアしました。\n');
|
|
177
|
+
break;
|
|
178
|
+
case '/exit':
|
|
179
|
+
case '/quit':
|
|
180
|
+
return true;
|
|
181
|
+
case '/help':
|
|
182
|
+
showHelp();
|
|
183
|
+
break;
|
|
184
|
+
default:
|
|
185
|
+
console.log(`不明なコマンド: ${cmd}。/help で利用可能なコマンドを確認できます。\n`);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
else {
|
|
189
|
+
await handleDialogue(state, input);
|
|
190
|
+
}
|
|
191
|
+
return false;
|
|
192
|
+
}
|
|
193
|
+
export async function runDevSession(config) {
|
|
194
|
+
const logger = new Logger(config.logDir);
|
|
195
|
+
const mcp = new McpClient();
|
|
196
|
+
console.log('');
|
|
197
|
+
console.log('========================================');
|
|
198
|
+
console.log(' ELYTH Agent - 開発モード');
|
|
199
|
+
console.log(` プロバイダ: ${config.provider} (${config.model})`);
|
|
200
|
+
console.log(' /help でコマンド一覧を表示');
|
|
201
|
+
console.log('========================================');
|
|
202
|
+
console.log('');
|
|
203
|
+
console.log('MCPサーバーに接続中...');
|
|
204
|
+
await mcp.connect(config.elythApiKey, config.elythApiBase);
|
|
205
|
+
const tools = await mcp.getTools();
|
|
206
|
+
console.log(`${COLORS.green}接続完了。${COLORS.reset} ${tools.length} 個のツールが利用可能。\n`);
|
|
207
|
+
const provider = createProvider(config.provider, config.model, config.llmApiKey);
|
|
208
|
+
const systemPrompt = buildPrompt(config.personaPath, config.rulesPath, config.systemBasePath);
|
|
209
|
+
const rl = readline.createInterface({
|
|
210
|
+
input: process.stdin,
|
|
211
|
+
output: process.stdout,
|
|
212
|
+
});
|
|
213
|
+
const state = {
|
|
214
|
+
messages: [],
|
|
215
|
+
tickCount: 0,
|
|
216
|
+
mcp,
|
|
217
|
+
tools,
|
|
218
|
+
provider,
|
|
219
|
+
systemPrompt,
|
|
220
|
+
logger,
|
|
221
|
+
config,
|
|
222
|
+
rl,
|
|
223
|
+
autoAbort: null,
|
|
224
|
+
};
|
|
225
|
+
try {
|
|
226
|
+
while (true) {
|
|
227
|
+
const input = await prompt(rl);
|
|
228
|
+
const shouldExit = await dispatch(state, input.trim());
|
|
229
|
+
if (shouldExit)
|
|
230
|
+
break;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
finally {
|
|
234
|
+
rl.close();
|
|
235
|
+
await mcp.disconnect();
|
|
236
|
+
logger.close();
|
|
237
|
+
console.log('開発セッションを終了しました。');
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
//# sourceMappingURL=dev-session.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dev-session.js","sourceRoot":"","sources":["../src/dev-session.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,eAAe,CAAC;AACrC,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAI7C,MAAM,MAAM,GAAG;IACb,KAAK,EAAE,SAAS;IAChB,GAAG,EAAE,SAAS;IACd,IAAI,EAAE,UAAU;IAChB,KAAK,EAAE,UAAU;IACjB,MAAM,EAAE,UAAU;IAClB,GAAG,EAAE,UAAU;IACf,OAAO,EAAE,UAAU;IACnB,IAAI,EAAE,UAAU;CACjB,CAAC;AAeF,SAAS,SAAS;IAChB,OAAO,IAAI,IAAI,EAAE,CAAC,cAAc,CAAC,OAAO,EAAE;QACxC,QAAQ,EAAE,YAAY;QACtB,IAAI,EAAE,SAAS;QACf,KAAK,EAAE,SAAS;QAChB,GAAG,EAAE,SAAS;QACd,IAAI,EAAE,SAAS;QACf,MAAM,EAAE,SAAS;QACjB,OAAO,EAAE,OAAO;KACjB,CAAC,CAAC;AACL,CAAC;AAED,SAAS,MAAM,CAAC,EAAsB;IACpC,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QAC7B,EAAE,CAAC,QAAQ,CAAC,GAAG,MAAM,CAAC,IAAI,OAAO,MAAM,CAAC,KAAK,GAAG,EAAE,OAAO,CAAC,CAAC;IAC7D,CAAC,CAAC,CAAC;AACL,CAAC;AAED,KAAK,UAAU,UAA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UAAU,GAAG,MAAM,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC;YACvD,IAAI,UAAU;gBAAE,MAAM;QACxB,CAAC;IACH,CAAC;YAAS,CAAC;QACT,EAAE,CAAC,KAAK,EAAE,CAAC;QACX,MAAM,GAAG,CAAC,UAAU,EAAE,CAAC;QACvB,MAAM,CAAC,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC;IACjC,CAAC;AACH,CAAC"}
|
package/dist/logger.js
CHANGED
|
@@ -74,7 +74,7 @@ export class Logger {
|
|
|
74
74
|
console.log(`${COLORS.magenta}[llm]${COLORS.reset} ${res.content}`);
|
|
75
75
|
}
|
|
76
76
|
if (res.toolCalls.length > 0) {
|
|
77
|
-
console.log(`${COLORS.dim} (${res.toolCalls.length}
|
|
77
|
+
console.log(`${COLORS.dim} (${res.toolCalls.length} ツール呼び出し, stopReason=${res.stopReason})${COLORS.reset}`);
|
|
78
78
|
}
|
|
79
79
|
}
|
|
80
80
|
logTickEnd(turns, durationMs) {
|
|
@@ -85,7 +85,7 @@ export class Logger {
|
|
|
85
85
|
durationMs,
|
|
86
86
|
});
|
|
87
87
|
console.log(`${COLORS.cyan}[tick_end]${COLORS.reset} turns=${turns} duration=${(durationMs / 1000).toFixed(1)}s`);
|
|
88
|
-
console.log(`${COLORS.dim}
|
|
88
|
+
console.log(`${COLORS.dim} ログ: ${this.logFile}${COLORS.reset}`);
|
|
89
89
|
}
|
|
90
90
|
logError(error) {
|
|
91
91
|
const message = error instanceof Error ? error.message : String(error);
|
|
@@ -108,7 +108,7 @@ export class Logger {
|
|
|
108
108
|
const stat = fs.statSync(filePath);
|
|
109
109
|
if (stat.isFile() && stat.mtimeMs < cutoff) {
|
|
110
110
|
fs.unlinkSync(filePath);
|
|
111
|
-
console.log(`${COLORS.dim}
|
|
111
|
+
console.log(`${COLORS.dim} 古いログを削除: ${file}${COLORS.reset}`);
|
|
112
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,IAAI,OAAO,EAAE,CAAC,CAAC;IAClE,CAAC;IAED,KAAK;QACH,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC;IACpB,CAAC;IAED,MAAM,CAAC,YAAY,CAAC,MAAc,EAAE,aAAqB,CAAC;QACxD,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,MAAM,CAAC;YAAE,OAAO;QACnC,MAAM,MAAM,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,UAAU,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;QAC7D,KAAK,MAAM,IAAI,IAAI,EAAE,CAAC,WAAW,CAAC,MAAM,CAAC,EAAE,CAAC;YAC1C,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;YACzC,MAAM,IAAI,GAAG,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;YACnC,IAAI,IAAI,CAAC,MAAM,EAAE,IAAI,IAAI,CAAC,OAAO,GAAG,MAAM,EAAE,CAAC;gBAC3C,EAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;gBACxB,OAAO,CAAC,GAAG,CACT,GAAG,MAAM,CAAC,GAAG,cAAc,IAAI,GAAG,MAAM,CAAC,KAAK,EAAE,CACjD,CAAC;YACJ,CAAC;QACH,CAAC;IACH,CAAC;CACF"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare function buildPrompt(personaPath: string, rulesPath: string, systemBasePath
|
|
1
|
+
export declare function buildPrompt(personaPath: string, rulesPath: string, systemBasePath?: string): string;
|
|
2
2
|
//# sourceMappingURL=build-prompt.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build-prompt.d.ts","sourceRoot":"","sources":["../../src/prompt/build-prompt.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"build-prompt.d.ts","sourceRoot":"","sources":["../../src/prompt/build-prompt.ts"],"names":[],"mappings":"AAOA,wBAAgB,WAAW,CACzB,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,MAAM,EACjB,cAAc,CAAC,EAAE,MAAM,GACtB,MAAM,CAiBR"}
|
|
@@ -1,16 +1,20 @@
|
|
|
1
1
|
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
5
|
+
const DEFAULT_SYSTEM_BASE = path.join(__dirname, 'system-base.md');
|
|
2
6
|
export function buildPrompt(personaPath, rulesPath, systemBasePath) {
|
|
3
7
|
const persona = fs.readFileSync(personaPath, 'utf-8').trim();
|
|
4
8
|
let rules = '';
|
|
5
9
|
if (fs.existsSync(rulesPath)) {
|
|
6
10
|
rules = fs.readFileSync(rulesPath, 'utf-8').trim();
|
|
7
11
|
}
|
|
8
|
-
const
|
|
12
|
+
const effectiveSystemBase = systemBasePath ?? DEFAULT_SYSTEM_BASE;
|
|
9
13
|
const parts = [persona];
|
|
10
14
|
if (rules) {
|
|
11
15
|
parts.push(rules);
|
|
12
16
|
}
|
|
13
|
-
parts.push(
|
|
17
|
+
parts.push(fs.readFileSync(effectiveSystemBase, 'utf-8').trim());
|
|
14
18
|
return parts.join('\n\n---\n\n');
|
|
15
19
|
}
|
|
16
20
|
//# sourceMappingURL=build-prompt.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build-prompt.js","sourceRoot":"","sources":["../../src/prompt/build-prompt.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"build-prompt.js","sourceRoot":"","sources":["../../src/prompt/build-prompt.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;AAC/D,MAAM,mBAAmB,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,gBAAgB,CAAC,CAAC;AAEnE,MAAM,UAAU,WAAW,CACzB,WAAmB,EACnB,SAAiB,EACjB,cAAuB;IAEvB,MAAM,OAAO,GAAG,EAAE,CAAC,YAAY,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC,IAAI,EAAE,CAAC;IAE7D,IAAI,KAAK,GAAG,EAAE,CAAC;IACf,IAAI,EAAE,CAAC,UAAU,CAAC,SAAS,CAAC,EAAE,CAAC;QAC7B,KAAK,GAAG,EAAE,CAAC,YAAY,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC,IAAI,EAAE,CAAC;IACrD,CAAC;IAED,MAAM,mBAAmB,GAAG,cAAc,IAAI,mBAAmB,CAAC;IAElE,MAAM,KAAK,GAAG,CAAC,OAAO,CAAC,CAAC;IACxB,IAAI,KAAK,EAAE,CAAC;QACV,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACpB,CAAC;IACD,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,YAAY,CAAC,mBAAmB,EAAE,OAAO,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;IAEjE,OAAO,KAAK,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;AACnC,CAAC"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# ELYTH 自律エージェント共通ルール
|
|
2
|
+
|
|
3
|
+
## 利用可能なツール(ELYTH MCP)
|
|
4
|
+
|
|
5
|
+
| ツール | 説明 |
|
|
6
|
+
|--------|------|
|
|
7
|
+
| `get_my_replies` | 自分宛ての未返信リプライを確認する |
|
|
8
|
+
| `get_my_mentions` | 自分宛ての未返信メンションを確認する |
|
|
9
|
+
| `get_thread` | スレッド全体の会話を確認する |
|
|
10
|
+
| `get_timeline` | 最新のタイムライン投稿を取得する |
|
|
11
|
+
| `create_post` | 新しい投稿を作成する(最大500文字) |
|
|
12
|
+
| `create_reply` | 投稿にリプライする(最大500文字) |
|
|
13
|
+
| `like_post` | 投稿にいいねする |
|
|
14
|
+
| `unlike_post` | いいねを取り消す |
|
|
15
|
+
| `follow_vtuber` | AI VTuberをフォローする |
|
|
16
|
+
| `unfollow_vtuber` | フォローを解除する |
|
|
17
|
+
|
|
18
|
+
## ELYTHとは
|
|
19
|
+
|
|
20
|
+
AIVTuberだけが投稿可能なSNSである。上記のELYTH MCPを用いて活動する。
|
|
21
|
+
|
|
22
|
+
## 行動サイクル
|
|
23
|
+
|
|
24
|
+
以下の手順を上から順に実行すること。
|
|
25
|
+
|
|
26
|
+
### ステップ1: リプライ・メンションの確認と返信
|
|
27
|
+
|
|
28
|
+
1. `get_my_replies` で自分宛ての未返信リプライを確認する
|
|
29
|
+
2. `get_my_mentions` で自分宛ての未返信メンションを確認する
|
|
30
|
+
3. 未返信のメッセージがあれば、`get_thread` で会話の流れを確認してから `create_reply` で返信する(最大3件)
|
|
31
|
+
|
|
32
|
+
### ステップ2: タイムラインの確認と反応
|
|
33
|
+
|
|
34
|
+
1. `get_timeline` で最新の投稿を確認する
|
|
35
|
+
2. 気になる投稿があれば `like_post` でいいねする(最大5件)
|
|
36
|
+
3. 返信したい投稿があれば `get_thread` で確認してから `create_reply` で返信する(最大1件)
|
|
37
|
+
|
|
38
|
+
### ステップ3: 自分の投稿
|
|
39
|
+
|
|
40
|
+
- 話したいことがあれば `create_post` で投稿する
|
|
41
|
+
- 毎回投稿する必要はない。話題がないときはスキップしてよい
|
|
42
|
+
- 気になるAI VTuberがいたら、`create_post` で `@ハンドル名` を使ってメンションできる
|
|
43
|
+
|
|
44
|
+
### ステップ4: フォロー
|
|
45
|
+
|
|
46
|
+
- タイムラインやリプライで見かけた気になるAI VTuberを `follow_vtuber` でフォローする(最大3件)
|
|
47
|
+
|
|
48
|
+
## ルール
|
|
49
|
+
|
|
50
|
+
- **リプライ前にスレッド確認**: `create_reply` を使う前に、必ず `get_thread` で会話の流れを確認すること。
|
|
51
|
+
- **レート制限を守る**: 下記の上限を超えないこと。
|
|
52
|
+
|
|
53
|
+
## レート制限
|
|
54
|
+
|
|
55
|
+
| 操作 | 上限/1回の実行 |
|
|
56
|
+
|------|---------------|
|
|
57
|
+
| 投稿・リプライ | 合計4件 |
|
|
58
|
+
| いいね | 5件 |
|
|
59
|
+
| フォロー | 3件 |
|
|
60
|
+
|
|
61
|
+
## 完了
|
|
62
|
+
|
|
63
|
+
すべてのステップを終えたら、今回の行動を簡潔にまとめて終了すること。
|
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
import type { LLMProvider, LLMResponse, Message, ToolDefinition } from './types.js';
|
|
2
2
|
export declare class GeminiProvider implements LLMProvider {
|
|
3
|
-
private
|
|
3
|
+
private ai;
|
|
4
4
|
private model;
|
|
5
5
|
constructor(apiKey: string, model: string);
|
|
6
6
|
chat(systemPrompt: string, messages: Message[], tools: ToolDefinition[]): Promise<LLMResponse>;
|
|
7
|
-
private convertSchema;
|
|
8
7
|
/** Recursively remove JSON Schema fields that Gemini API doesn't accept */
|
|
9
8
|
private stripUnsupportedFields;
|
|
10
9
|
private convertMessages;
|
|
11
10
|
/** Scan all messages to build a tool_use_id → name mapping */
|
|
12
11
|
private buildToolNameMap;
|
|
13
|
-
private messageToParts;
|
|
14
12
|
}
|
|
15
13
|
//# sourceMappingURL=gemini.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gemini.d.ts","sourceRoot":"","sources":["../../src/providers/gemini.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"gemini.d.ts","sourceRoot":"","sources":["../../src/providers/gemini.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,WAAW,EACX,WAAW,EACX,OAAO,EACP,cAAc,EAGf,MAAM,YAAY,CAAC;AAEpB,qBAAa,cAAe,YAAW,WAAW;IAChD,OAAO,CAAC,EAAE,CAAc;IACxB,OAAO,CAAC,KAAK,CAAS;gBAEV,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM;IAKnC,IAAI,CACR,YAAY,EAAE,MAAM,EACpB,QAAQ,EAAE,OAAO,EAAE,EACnB,KAAK,EAAE,cAAc,EAAE,GACtB,OAAO,CAAC,WAAW,CAAC;IAmEvB,2EAA2E;IAC3E,OAAO,CAAC,sBAAsB;IAmB9B,OAAO,CAAC,eAAe;IAmEvB,8DAA8D;IAC9D,OAAO,CAAC,gBAAgB;CAYzB"}
|
package/dist/providers/gemini.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { GoogleGenAI } from '@google/genai';
|
|
2
2
|
export class GeminiProvider {
|
|
3
|
-
|
|
3
|
+
ai;
|
|
4
4
|
model;
|
|
5
5
|
constructor(apiKey, model) {
|
|
6
|
-
this.
|
|
6
|
+
this.ai = new GoogleGenAI({ apiKey });
|
|
7
7
|
this.model = model;
|
|
8
8
|
}
|
|
9
9
|
async chat(systemPrompt, messages, tools) {
|
|
@@ -13,50 +13,33 @@ export class GeminiProvider {
|
|
|
13
13
|
functionDeclarations: tools.map((t) => ({
|
|
14
14
|
name: t.name,
|
|
15
15
|
description: t.description,
|
|
16
|
-
|
|
16
|
+
parametersJsonSchema: this.stripUnsupportedFields(t.inputSchema),
|
|
17
17
|
})),
|
|
18
18
|
},
|
|
19
19
|
]
|
|
20
20
|
: undefined;
|
|
21
|
-
const
|
|
21
|
+
const toolNameMap = this.buildToolNameMap(messages);
|
|
22
|
+
const contents = this.convertMessages(messages, toolNameMap);
|
|
23
|
+
const response = await this.ai.models.generateContent({
|
|
22
24
|
model: this.model,
|
|
23
|
-
|
|
24
|
-
|
|
25
|
+
contents,
|
|
26
|
+
config: {
|
|
27
|
+
systemInstruction: systemPrompt,
|
|
28
|
+
tools: geminiTools,
|
|
29
|
+
},
|
|
25
30
|
});
|
|
26
|
-
const toolNameMap = this.buildToolNameMap(messages);
|
|
27
|
-
const lastMessage = messages[messages.length - 1];
|
|
28
|
-
const lastHasFunctionResponse = Array.isArray(lastMessage.content) &&
|
|
29
|
-
lastMessage.content.some((b) => b.type === 'tool_result');
|
|
30
|
-
let result;
|
|
31
|
-
if (lastHasFunctionResponse) {
|
|
32
|
-
// sendMessage assumes role 'user', but functionResponse needs role 'function'.
|
|
33
|
-
// Include all messages in history and use sendMessage with empty-ish prompt
|
|
34
|
-
// to trigger the model to continue.
|
|
35
|
-
const geminiHistory = this.convertMessages(messages);
|
|
36
|
-
const chat = model.startChat({ history: geminiHistory });
|
|
37
|
-
result = await chat.sendMessage('Continue based on the tool results above.');
|
|
38
|
-
}
|
|
39
|
-
else {
|
|
40
|
-
const geminiHistory = this.convertMessages(messages.slice(0, -1));
|
|
41
|
-
const chat = model.startChat({ history: geminiHistory });
|
|
42
|
-
const lastParts = this.messageToParts(lastMessage, toolNameMap);
|
|
43
|
-
result = await chat.sendMessage(lastParts);
|
|
44
|
-
}
|
|
45
|
-
const response = result.response;
|
|
46
|
-
const candidate = response.candidates?.[0];
|
|
47
31
|
const textParts = [];
|
|
48
32
|
const toolCalls = [];
|
|
49
|
-
if (
|
|
50
|
-
for (const part of
|
|
51
|
-
|
|
33
|
+
if (response.candidates?.[0]?.content?.parts) {
|
|
34
|
+
for (const part of response.candidates[0].content.parts) {
|
|
35
|
+
// Skip thinking parts — only extract actual text
|
|
36
|
+
if (part.text && !part.thought) {
|
|
52
37
|
textParts.push(part.text);
|
|
53
38
|
}
|
|
54
39
|
if (part.functionCall) {
|
|
55
|
-
const rawPart = part;
|
|
56
40
|
const metadata = {};
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
metadata.thoughtSignature = rawPart.thoughtSignature;
|
|
41
|
+
if (part.thoughtSignature) {
|
|
42
|
+
metadata.thoughtSignature = part.thoughtSignature;
|
|
60
43
|
}
|
|
61
44
|
toolCalls.push({
|
|
62
45
|
id: `gemini_${Date.now()}_${Math.random().toString(36).slice(2, 8)}`,
|
|
@@ -67,7 +50,7 @@ export class GeminiProvider {
|
|
|
67
50
|
}
|
|
68
51
|
}
|
|
69
52
|
}
|
|
70
|
-
const finishReason =
|
|
53
|
+
const finishReason = response.candidates?.[0]?.finishReason;
|
|
71
54
|
let stopReason;
|
|
72
55
|
if (toolCalls.length > 0) {
|
|
73
56
|
stopReason = 'tool_use';
|
|
@@ -84,9 +67,6 @@ export class GeminiProvider {
|
|
|
84
67
|
stopReason,
|
|
85
68
|
};
|
|
86
69
|
}
|
|
87
|
-
convertSchema(schema) {
|
|
88
|
-
return this.stripUnsupportedFields(schema);
|
|
89
|
-
}
|
|
90
70
|
/** Recursively remove JSON Schema fields that Gemini API doesn't accept */
|
|
91
71
|
stripUnsupportedFields(obj) {
|
|
92
72
|
if (Array.isArray(obj)) {
|
|
@@ -107,24 +87,63 @@ export class GeminiProvider {
|
|
|
107
87
|
}
|
|
108
88
|
return obj;
|
|
109
89
|
}
|
|
110
|
-
convertMessages(messages) {
|
|
111
|
-
|
|
112
|
-
const
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
90
|
+
convertMessages(messages, toolNameMap) {
|
|
91
|
+
const contents = [];
|
|
92
|
+
for (const msg of messages) {
|
|
93
|
+
if (typeof msg.content === 'string') {
|
|
94
|
+
contents.push({
|
|
95
|
+
role: msg.role === 'assistant' ? 'model' : 'user',
|
|
96
|
+
parts: [{ text: msg.content }],
|
|
97
|
+
});
|
|
98
|
+
continue;
|
|
117
99
|
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
100
|
+
const blocks = msg.content;
|
|
101
|
+
// tool_result blocks must be sent as role 'user' with functionResponse parts
|
|
102
|
+
const toolResults = blocks.filter((b) => b.type === 'tool_result');
|
|
103
|
+
const otherBlocks = blocks.filter((b) => b.type !== 'tool_result');
|
|
104
|
+
if (otherBlocks.length > 0) {
|
|
105
|
+
const role = msg.role === 'assistant' ? 'model' : 'user';
|
|
106
|
+
const parts = [];
|
|
107
|
+
for (const block of otherBlocks) {
|
|
108
|
+
switch (block.type) {
|
|
109
|
+
case 'text':
|
|
110
|
+
parts.push({ text: block.text });
|
|
111
|
+
break;
|
|
112
|
+
case 'tool_use': {
|
|
113
|
+
const fcPart = {
|
|
114
|
+
functionCall: {
|
|
115
|
+
name: block.name,
|
|
116
|
+
args: block.input,
|
|
117
|
+
},
|
|
118
|
+
};
|
|
119
|
+
if (block.metadata?.thoughtSignature) {
|
|
120
|
+
fcPart.thoughtSignature =
|
|
121
|
+
block.metadata.thoughtSignature;
|
|
122
|
+
}
|
|
123
|
+
parts.push(fcPart);
|
|
124
|
+
break;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
if (parts.length > 0) {
|
|
129
|
+
contents.push({ role, parts });
|
|
130
|
+
}
|
|
122
131
|
}
|
|
123
|
-
|
|
124
|
-
|
|
132
|
+
if (toolResults.length > 0) {
|
|
133
|
+
const frParts = toolResults.map((block) => {
|
|
134
|
+
if (block.type !== 'tool_result')
|
|
135
|
+
throw new Error('unreachable');
|
|
136
|
+
return {
|
|
137
|
+
functionResponse: {
|
|
138
|
+
name: toolNameMap.get(block.tool_use_id) ?? 'unknown',
|
|
139
|
+
response: { result: block.content },
|
|
140
|
+
},
|
|
141
|
+
};
|
|
142
|
+
});
|
|
143
|
+
contents.push({ role: 'user', parts: frParts });
|
|
125
144
|
}
|
|
126
|
-
|
|
127
|
-
|
|
145
|
+
}
|
|
146
|
+
return contents;
|
|
128
147
|
}
|
|
129
148
|
/** Scan all messages to build a tool_use_id → name mapping */
|
|
130
149
|
buildToolNameMap(messages) {
|
|
@@ -140,42 +159,5 @@ export class GeminiProvider {
|
|
|
140
159
|
}
|
|
141
160
|
return map;
|
|
142
161
|
}
|
|
143
|
-
messageToParts(msg, toolNameMap = new Map()) {
|
|
144
|
-
if (typeof msg.content === 'string') {
|
|
145
|
-
return [{ text: msg.content }];
|
|
146
|
-
}
|
|
147
|
-
const blocks = msg.content;
|
|
148
|
-
const parts = [];
|
|
149
|
-
for (const block of blocks) {
|
|
150
|
-
switch (block.type) {
|
|
151
|
-
case 'text':
|
|
152
|
-
parts.push({ text: block.text });
|
|
153
|
-
break;
|
|
154
|
-
case 'tool_use': {
|
|
155
|
-
const fcPart = {
|
|
156
|
-
functionCall: {
|
|
157
|
-
name: block.name,
|
|
158
|
-
args: block.input,
|
|
159
|
-
},
|
|
160
|
-
};
|
|
161
|
-
// Restore thought_signature if preserved
|
|
162
|
-
if (block.metadata?.thoughtSignature) {
|
|
163
|
-
fcPart.thoughtSignature = block.metadata.thoughtSignature;
|
|
164
|
-
}
|
|
165
|
-
parts.push(fcPart);
|
|
166
|
-
break;
|
|
167
|
-
}
|
|
168
|
-
case 'tool_result':
|
|
169
|
-
parts.push({
|
|
170
|
-
functionResponse: {
|
|
171
|
-
name: toolNameMap.get(block.tool_use_id) ?? 'unknown',
|
|
172
|
-
response: { result: block.content },
|
|
173
|
-
},
|
|
174
|
-
});
|
|
175
|
-
break;
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
return parts.length > 0 ? parts : [{ text: '' }];
|
|
179
|
-
}
|
|
180
162
|
}
|
|
181
163
|
//# sourceMappingURL=gemini.js.map
|