@make-u-free/migi 0.3.3 → 0.3.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.
- package/bin/migi.js +88 -61
- package/package.json +1 -1
- package/src/tools.js +3 -1
package/bin/migi.js
CHANGED
|
@@ -66,78 +66,105 @@ console.log(chalk.dim(' /exit 終了\n'))
|
|
|
66
66
|
|
|
67
67
|
const agent = new MigiAgent({ context, promptFn, apiKey, model, name: agentName, userName, teamsWebhookUrl })
|
|
68
68
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
69
|
+
const SEP = chalk.dim('─'.repeat(50))
|
|
70
|
+
|
|
71
|
+
// ---- 複数行入力(空行で送信) ----
|
|
72
|
+
async function readMultiLine() {
|
|
73
|
+
const lines = []
|
|
74
|
+
process.stdout.write(chalk.dim(' Enter で改行 / 空行で送信\n'))
|
|
75
|
+
return new Promise((resolve) => {
|
|
76
|
+
const onLine = (line) => {
|
|
77
|
+
if (line === '' && lines.length > 0) {
|
|
78
|
+
rl.removeListener('line', onLine)
|
|
79
|
+
resolve(lines.join('\n'))
|
|
80
|
+
} else {
|
|
81
|
+
lines.push(line)
|
|
82
|
+
process.stdout.write(chalk.cyan(' '))
|
|
83
|
+
}
|
|
79
84
|
}
|
|
85
|
+
process.stdout.write(chalk.cyan(' '))
|
|
86
|
+
rl.on('line', onLine)
|
|
87
|
+
})
|
|
88
|
+
}
|
|
80
89
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
90
|
+
// ---- メインループ ----
|
|
91
|
+
async function prompt() {
|
|
92
|
+
console.log('\n' + SEP)
|
|
93
|
+
process.stdout.write(chalk.bold.cyan(` ${userName || 'あなた'}\n`) + SEP + '\n')
|
|
94
|
+
|
|
95
|
+
const input = (await readMultiLine()).trim()
|
|
96
|
+
if (!input) return prompt()
|
|
97
|
+
|
|
98
|
+
// --- ビルトインコマンド ---
|
|
99
|
+
if (input === '/exit' || input === '/quit') {
|
|
100
|
+
console.log(chalk.cyan(`\n お疲れ様でした!またね。\n`))
|
|
101
|
+
process.exit(0)
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
if (input === '/config') {
|
|
105
|
+
const current = loadGlobalConfig()
|
|
106
|
+
await runSetup(promptFn, current)
|
|
107
|
+
console.log(chalk.yellow(' 再起動して設定を反映してください。\n'))
|
|
108
|
+
return prompt()
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
if (input === '/models') {
|
|
112
|
+
try {
|
|
113
|
+
console.log(chalk.dim('\n 利用可能なモデルを取得中...\n'))
|
|
114
|
+
const OpenAI = (await import('openai')).default
|
|
115
|
+
const client = new OpenAI({ apiKey })
|
|
116
|
+
const res = await client.models.list()
|
|
117
|
+
const models = res.data
|
|
118
|
+
.map(m => m.id)
|
|
119
|
+
.filter(id => id.includes('gpt') || id.includes('o1') || id.includes('o3') || id.includes('o4'))
|
|
120
|
+
.sort()
|
|
121
|
+
console.log(chalk.cyan(' 利用可能なモデル:'))
|
|
122
|
+
for (const m of models) {
|
|
123
|
+
const mark = m === model ? chalk.green(' ← 現在') : ''
|
|
124
|
+
console.log(chalk.dim(` • ${m}`) + mark)
|
|
125
|
+
}
|
|
126
|
+
console.log(chalk.dim('\n /config でモデルを変更できます。\n'))
|
|
127
|
+
} catch (err) {
|
|
128
|
+
console.error(chalk.red('\n 取得失敗: ' + err.message + '\n'))
|
|
86
129
|
}
|
|
130
|
+
return prompt()
|
|
131
|
+
}
|
|
87
132
|
|
|
88
|
-
|
|
133
|
+
// --- スキルルーティング ---
|
|
134
|
+
const parsed = parseSkillInput(input)
|
|
135
|
+
if (parsed) {
|
|
136
|
+
const skill = resolveSkill(parsed.name, process.cwd())
|
|
137
|
+
if (skill) {
|
|
138
|
+
console.log('\n' + SEP)
|
|
139
|
+
console.log(chalk.bold.cyan(` ${agentName}`) + chalk.dim(` [スキル: ${parsed.name}]`))
|
|
140
|
+
console.log(SEP)
|
|
141
|
+
const expanded = expandSkill(skill.content, parsed.args)
|
|
89
142
|
try {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
const client = new OpenAI({ apiKey })
|
|
93
|
-
const res = await client.models.list()
|
|
94
|
-
const models = res.data
|
|
95
|
-
.map(m => m.id)
|
|
96
|
-
.filter(id => id.includes('gpt') || id.includes('o1') || id.includes('o3') || id.includes('o4'))
|
|
97
|
-
.sort()
|
|
98
|
-
console.log(chalk.cyan(' 利用可能なモデル:'))
|
|
99
|
-
for (const m of models) {
|
|
100
|
-
const mark = m === model ? chalk.green(' ← 現在') : ''
|
|
101
|
-
console.log(chalk.dim(` • ${m}`) + mark)
|
|
102
|
-
}
|
|
103
|
-
console.log(chalk.dim('\n /config でモデルを変更できます。\n'))
|
|
143
|
+
const reply = await agent.chat(expanded)
|
|
144
|
+
console.log('\n' + reply + '\n')
|
|
104
145
|
} catch (err) {
|
|
105
|
-
console.error(chalk.red('\n
|
|
146
|
+
console.error(chalk.red('\n エラー: ' + err.message + '\n'))
|
|
106
147
|
}
|
|
107
148
|
return prompt()
|
|
149
|
+
} else {
|
|
150
|
+
console.log(chalk.yellow(`\n スキル「${parsed.name}」が見つかりません。`))
|
|
151
|
+
console.log(chalk.dim(` .migi/skills/${parsed.name}.md を作成してください。`))
|
|
152
|
+
return prompt()
|
|
108
153
|
}
|
|
154
|
+
}
|
|
109
155
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
} catch (err) {
|
|
121
|
-
console.error(chalk.red('\n エラー: ' + err.message + '\n'))
|
|
122
|
-
}
|
|
123
|
-
return prompt()
|
|
124
|
-
} else {
|
|
125
|
-
console.log(chalk.yellow(` スキル「${parsed.name}」が見つかりません。`))
|
|
126
|
-
console.log(chalk.dim(` .migi/skills/${parsed.name}.md を作成してください。\n`))
|
|
127
|
-
return prompt()
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
// --- 通常チャット ---
|
|
132
|
-
try {
|
|
133
|
-
const reply = await agent.chat(input)
|
|
134
|
-
console.log('\n' + reply + '\n')
|
|
135
|
-
} catch (err) {
|
|
136
|
-
console.error(chalk.red('\n エラー: ' + err.message + '\n'))
|
|
137
|
-
}
|
|
156
|
+
// --- 通常チャット ---
|
|
157
|
+
console.log('\n' + SEP)
|
|
158
|
+
console.log(chalk.bold.cyan(` ${agentName}`))
|
|
159
|
+
console.log(SEP)
|
|
160
|
+
try {
|
|
161
|
+
const reply = await agent.chat(input)
|
|
162
|
+
console.log('\n' + reply + '\n')
|
|
163
|
+
} catch (err) {
|
|
164
|
+
console.error(chalk.red('\n エラー: ' + err.message + '\n'))
|
|
165
|
+
}
|
|
138
166
|
|
|
139
|
-
|
|
140
|
-
})
|
|
167
|
+
prompt()
|
|
141
168
|
}
|
|
142
169
|
|
|
143
170
|
prompt()
|
package/package.json
CHANGED
package/src/tools.js
CHANGED
|
@@ -4,7 +4,9 @@ import { dirname, extname } from 'path'
|
|
|
4
4
|
import { request } from 'https'
|
|
5
5
|
import { glob } from 'glob'
|
|
6
6
|
import xlsxPkg from 'xlsx'
|
|
7
|
-
import
|
|
7
|
+
import { createRequire } from 'module'
|
|
8
|
+
const require = createRequire(import.meta.url)
|
|
9
|
+
const pdfParse = require('pdf-parse')
|
|
8
10
|
import AdmZip from 'adm-zip'
|
|
9
11
|
import OpenAI from 'openai'
|
|
10
12
|
import { httpsAgent } from './tls.js'
|