pi-agy-acp 0.1.2 → 0.1.3
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/CHANGELOG.md +7 -0
- package/README.md +9 -4
- package/docs/development.md +34 -10
- package/docs/reference.md +31 -27
- package/index.ts +57 -10
- package/package.json +6 -3
- package/src/acp-process.ts +6 -2
- package/src/config.ts +75 -0
- package/src/conversation.ts +154 -30
- package/src/format.ts +17 -3
- package/src/history.ts +30 -7
- package/src/jsonrpc.ts +16 -0
- package/src/mcp-bridge.ts +119 -42
- package/src/pi-stream.ts +43 -2
- package/src/preflight.ts +1 -14
- package/src/runtime.ts +318 -133
- package/src/util.ts +12 -5
package/src/pi-stream.ts
CHANGED
|
@@ -146,12 +146,53 @@ export function streamPi(
|
|
|
146
146
|
max: 'high',
|
|
147
147
|
}[options.reasoning ?? 'off'],
|
|
148
148
|
}
|
|
149
|
+
// onPayload may replace request content, but harness-owned routing/cancellation
|
|
150
|
+
// metadata (sessionId, signal) is always preserved. Omitting `tools` inherits
|
|
151
|
+
// the original tools; passing `tools: []` explicitly disables them.
|
|
149
152
|
const replacement = await options.onPayload?.(request, model)
|
|
150
|
-
if (replacement !== undefined)
|
|
153
|
+
if (replacement !== undefined) {
|
|
154
|
+
if (
|
|
155
|
+
replacement === null ||
|
|
156
|
+
typeof replacement !== 'object' ||
|
|
157
|
+
Array.isArray(replacement)
|
|
158
|
+
) {
|
|
159
|
+
throw new LlmError(
|
|
160
|
+
'onPayload must return a payload object or undefined',
|
|
161
|
+
'INVALID_PAYLOAD',
|
|
162
|
+
)
|
|
163
|
+
}
|
|
164
|
+
const candidate = replacement as Record<string, unknown>
|
|
165
|
+
if (
|
|
166
|
+
typeof candidate.model !== 'string' ||
|
|
167
|
+
candidate.model.trim().length === 0
|
|
168
|
+
) {
|
|
169
|
+
throw new LlmError(
|
|
170
|
+
'onPayload replacement must include a non-empty string model',
|
|
171
|
+
'INVALID_PAYLOAD',
|
|
172
|
+
)
|
|
173
|
+
}
|
|
174
|
+
if (!Array.isArray(candidate.messages)) {
|
|
175
|
+
throw new LlmError(
|
|
176
|
+
'onPayload replacement must include a messages array',
|
|
177
|
+
'INVALID_PAYLOAD',
|
|
178
|
+
)
|
|
179
|
+
}
|
|
180
|
+
if (candidate.tools !== undefined && !Array.isArray(candidate.tools)) {
|
|
181
|
+
throw new LlmError(
|
|
182
|
+
'onPayload replacement tools must be an array when provided',
|
|
183
|
+
'INVALID_PAYLOAD',
|
|
184
|
+
)
|
|
185
|
+
}
|
|
151
186
|
request = {
|
|
152
|
-
...(
|
|
187
|
+
...(candidate as unknown as GenerateOptions),
|
|
188
|
+
tools:
|
|
189
|
+
candidate.tools === undefined
|
|
190
|
+
? request.tools
|
|
191
|
+
: (candidate.tools as GenerateOptions['tools']),
|
|
192
|
+
sessionId: options.sessionId,
|
|
153
193
|
signal: options.signal,
|
|
154
194
|
}
|
|
195
|
+
}
|
|
155
196
|
stream.push({ type: 'start', partial: message })
|
|
156
197
|
let finish: Extract<StreamChunk, { type: 'finish' }> | undefined
|
|
157
198
|
let responseReported = false
|
package/src/preflight.ts
CHANGED
|
@@ -22,6 +22,7 @@ import {
|
|
|
22
22
|
} from 'node:fs'
|
|
23
23
|
import { homedir } from 'node:os'
|
|
24
24
|
import { delimiter, isAbsolute, join } from 'node:path'
|
|
25
|
+
import { readJson } from './config.ts'
|
|
25
26
|
|
|
26
27
|
/** Agent id installed in the isolated home. */
|
|
27
28
|
export const BRIDGE_AGENT = 'pi-bridge'
|
|
@@ -339,20 +340,6 @@ function writeIfChanged(path: string, content: string): void {
|
|
|
339
340
|
writeFileSync(path, content)
|
|
340
341
|
}
|
|
341
342
|
|
|
342
|
-
function readJson(path: string): Record<string, unknown> {
|
|
343
|
-
try {
|
|
344
|
-
const parsed: unknown = JSON.parse(readFileSync(path, 'utf8'))
|
|
345
|
-
return parsed !== null &&
|
|
346
|
-
typeof parsed === 'object' &&
|
|
347
|
-
!Array.isArray(parsed)
|
|
348
|
-
? (parsed as Record<string, unknown>)
|
|
349
|
-
: {}
|
|
350
|
-
} catch (_missingSettings) {
|
|
351
|
-
// A missing or unreadable settings file starts empty.
|
|
352
|
-
return {}
|
|
353
|
-
}
|
|
354
|
-
}
|
|
355
|
-
|
|
356
343
|
function isFile(path: string): boolean {
|
|
357
344
|
try {
|
|
358
345
|
return statSync(path).isFile()
|