Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 5cd267296e |
+14
-14
@@ -266,8 +266,10 @@ if [ "${PI_DEBUG}" = "true" ]; then
|
|||||||
TOOL_LOG=""
|
TOOL_LOG=""
|
||||||
|
|
||||||
if [ -n "${SESSION_FILE}" ]; then
|
if [ -n "${SESSION_FILE}" ]; then
|
||||||
# Extract tool-use entries: each line is a JSON object.
|
# Extract tool-call entries from Pi session JSONL.
|
||||||
# Tool calls appear as messages with tool_use/function_call content.
|
# Pi stores assistant messages with content blocks of type "toolCall"
|
||||||
|
# (NOT the Anthropic SDK's "tool_use"), using "arguments" (NOT "input").
|
||||||
|
# Tool results are separate entries with role "toolResult".
|
||||||
TOOL_LOG=$(node -e "
|
TOOL_LOG=$(node -e "
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const lines = fs.readFileSync('${SESSION_FILE}', 'utf8').trim().split('\n');
|
const lines = fs.readFileSync('${SESSION_FILE}', 'utf8').trim().split('\n');
|
||||||
@@ -275,18 +277,16 @@ if [ "${PI_DEBUG}" = "true" ]; then
|
|||||||
for (const line of lines) {
|
for (const line of lines) {
|
||||||
try {
|
try {
|
||||||
const entry = JSON.parse(line);
|
const entry = JSON.parse(line);
|
||||||
if (entry.type === 'message') {
|
if (entry.type !== 'message') continue;
|
||||||
const msg = entry.message;
|
const msg = entry.message;
|
||||||
// Model requesting tool use
|
if (!msg || !msg.content) continue;
|
||||||
if (msg.role === 'assistant' && msg.content) {
|
const parts = Array.isArray(msg.content) ? msg.content : [msg.content];
|
||||||
const parts = Array.isArray(msg.content) ? msg.content : [msg.content];
|
for (const part of parts) {
|
||||||
for (const part of parts) {
|
if (typeof part !== 'object') continue;
|
||||||
if (typeof part === 'object' && part.type === 'tool_use') {
|
if (part.type === 'toolCall') {
|
||||||
const input = part.input || {};
|
const args = Object.entries(part.arguments || {})
|
||||||
const args = Object.entries(input).map(([k,v]) => k + '=' + JSON.stringify(v)).join(' ');
|
.map(([k,v]) => k + '=' + JSON.stringify(v)).join(' ');
|
||||||
entries.push('[tool:' + part.name + '] ' + args);
|
entries.push('[tool:' + part.name + '] ' + args);
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch {}
|
} catch {}
|
||||||
|
|||||||
Reference in New Issue
Block a user