@make-u-free/migi 0.2.8 → 0.3.0
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/agent.js +23 -1
- package/src/tls.js +4 -2
package/package.json
CHANGED
package/src/agent.js
CHANGED
|
@@ -65,7 +65,25 @@ ${userNameLine}
|
|
|
65
65
|
(context ? `\n## ロードされたコンテキスト\n${context}` : '')
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
+
// tool_calls に対応する tool 結果がない壊れた履歴を修復する
|
|
69
|
+
_sanitizeHistory() {
|
|
70
|
+
const cleaned = []
|
|
71
|
+
for (let i = 0; i < this.history.length; i++) {
|
|
72
|
+
const msg = this.history[i]
|
|
73
|
+
if (msg.role === 'assistant' && msg.tool_calls?.length) {
|
|
74
|
+
const toolIds = msg.tool_calls.map(t => t.id)
|
|
75
|
+
const hasAllResults = toolIds.every(id =>
|
|
76
|
+
this.history.slice(i + 1).some(m => m.role === 'tool' && m.tool_call_id === id)
|
|
77
|
+
)
|
|
78
|
+
if (!hasAllResults) continue // 対応する結果がなければ丸ごとスキップ
|
|
79
|
+
}
|
|
80
|
+
cleaned.push(msg)
|
|
81
|
+
}
|
|
82
|
+
this.history = cleaned
|
|
83
|
+
}
|
|
84
|
+
|
|
68
85
|
async chat(userMessage) {
|
|
86
|
+
this._sanitizeHistory()
|
|
69
87
|
this.history.push({ role: 'user', content: userMessage })
|
|
70
88
|
|
|
71
89
|
const messages = [
|
|
@@ -104,7 +122,11 @@ ${userNameLine}
|
|
|
104
122
|
let result
|
|
105
123
|
|
|
106
124
|
if (approved) {
|
|
107
|
-
|
|
125
|
+
try {
|
|
126
|
+
result = await executeTool(name, args, { teamsWebhookUrl: this.teamsWebhookUrl })
|
|
127
|
+
} catch (err) {
|
|
128
|
+
result = `エラー: ${err.message}`
|
|
129
|
+
}
|
|
108
130
|
} else {
|
|
109
131
|
result = 'ユーザーによりキャンセルされました'
|
|
110
132
|
console.log(chalk.dim(' → キャンセル'))
|
package/src/tls.js
CHANGED
|
@@ -17,11 +17,13 @@ function scanDir(dir) {
|
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
function findCA() {
|
|
20
|
-
// 優先順: 環境変数 → カレント.migi/ → ホーム.migi/
|
|
20
|
+
// 優先順: 環境変数 → カレント.migi/ → カレント直下 → ホーム.migi/ → ホーム直下
|
|
21
21
|
const candidates = [
|
|
22
22
|
process.env.NODE_EXTRA_CA_CERTS,
|
|
23
23
|
...scanDir(join(process.cwd(), '.migi')),
|
|
24
|
+
...scanDir(process.cwd()),
|
|
24
25
|
...scanDir(join(homedir(), '.migi')),
|
|
26
|
+
...scanDir(homedir()),
|
|
25
27
|
].filter(Boolean)
|
|
26
28
|
|
|
27
29
|
for (const p of candidates) {
|
|
@@ -58,7 +60,7 @@ if (caPath) {
|
|
|
58
60
|
|
|
59
61
|
console.log(` [TLS] CA loaded: ${caPath}`)
|
|
60
62
|
} else {
|
|
61
|
-
console.log(' [TLS] CA未設定 (社内エラー時は
|
|
63
|
+
console.log(' [TLS] CA未設定 (社内エラー時は ~/.migi/ か ~/ に .crt/.pem を配置)')
|
|
62
64
|
}
|
|
63
65
|
|
|
64
66
|
export const httpsAgent = _httpsAgent
|