pi-agy-acp 0.1.2 → 0.1.4
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 +17 -0
- package/README.md +9 -4
- package/docs/development.md +69 -20
- package/docs/reference.md +60 -37
- package/index.ts +178 -47
- package/package.json +7 -4
- package/src/acp-process.ts +8 -2
- package/src/config.ts +75 -0
- package/src/conversation.ts +327 -71
- package/src/format.ts +332 -19
- package/src/history.ts +75 -24
- package/src/jsonrpc.ts +16 -0
- package/src/mcp-bridge.ts +121 -43
- package/src/pi-stream.ts +43 -2
- package/src/preflight.ts +1 -14
- package/src/runtime.ts +330 -138
- package/src/util.ts +12 -5
package/src/util.ts
CHANGED
|
@@ -90,8 +90,8 @@ export class AsyncQueue<T> {
|
|
|
90
90
|
* @returns whether an item is available.
|
|
91
91
|
*/
|
|
92
92
|
async wait(signal?: AbortSignal, timeoutMs?: number): Promise<boolean> {
|
|
93
|
-
if (this.items.length > 0) return true
|
|
94
93
|
if (signal?.aborted === true) return false
|
|
94
|
+
if (this.items.length > 0) return true
|
|
95
95
|
return new Promise<boolean>((resolve) => {
|
|
96
96
|
let timer: ReturnType<typeof setTimeout> | undefined
|
|
97
97
|
const finish = (value: boolean): void => {
|
|
@@ -117,9 +117,10 @@ export class KeyedMutex {
|
|
|
117
117
|
/**
|
|
118
118
|
* Acquire the lock for one key.
|
|
119
119
|
* @param key - lock key.
|
|
120
|
+
* @param signal - cancels waiting without bypassing earlier lock holders.
|
|
120
121
|
* @returns the release function.
|
|
121
122
|
*/
|
|
122
|
-
async acquire(key: string): Promise<() => void> {
|
|
123
|
+
async acquire(key: string, signal?: AbortSignal): Promise<() => void> {
|
|
123
124
|
const previous = this.tails.get(key) ?? Promise.resolve()
|
|
124
125
|
let release!: () => void
|
|
125
126
|
const current = new Promise<void>((resolve) => {
|
|
@@ -127,10 +128,16 @@ export class KeyedMutex {
|
|
|
127
128
|
})
|
|
128
129
|
const tail = previous.then(() => current)
|
|
129
130
|
this.tails.set(key, tail)
|
|
130
|
-
|
|
131
|
-
return () => {
|
|
132
|
-
release()
|
|
131
|
+
void tail.then(() => {
|
|
133
132
|
if (this.tails.get(key) === tail) this.tails.delete(key)
|
|
133
|
+
})
|
|
134
|
+
try {
|
|
135
|
+
await abortable(previous, signal)
|
|
136
|
+
signal?.throwIfAborted()
|
|
137
|
+
return release
|
|
138
|
+
} catch (error) {
|
|
139
|
+
release()
|
|
140
|
+
throw error
|
|
134
141
|
}
|
|
135
142
|
}
|
|
136
143
|
}
|