pi-agy-acp 0.1.0 → 0.1.2
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 +22 -0
- package/README.md +12 -36
- package/docs/development.md +60 -13
- package/docs/reference.md +39 -28
- package/index.ts +100 -9
- package/package.json +4 -2
- package/src/acp-process.ts +1 -3
- package/src/conversation.ts +107 -7
- package/src/format.ts +54 -12
- package/src/mcp-bridge.ts +124 -6
- package/src/pi-stream.ts +77 -44
- package/src/preflight.ts +61 -0
- package/src/quota.ts +15 -0
- package/src/runtime.ts +114 -382
- package/src/util.ts +23 -0
- package/src/version.ts +5 -0
package/src/util.ts
CHANGED
|
@@ -155,3 +155,26 @@ export function digest(value: unknown): string {
|
|
|
155
155
|
export function delay(ms: number): Promise<void> {
|
|
156
156
|
return new Promise((resolve) => setTimeout(resolve, ms))
|
|
157
157
|
}
|
|
158
|
+
|
|
159
|
+
/** Cancel one caller's wait without cancelling work shared with other callers. */
|
|
160
|
+
export function abortable<T>(
|
|
161
|
+
promise: Promise<T>,
|
|
162
|
+
signal?: AbortSignal,
|
|
163
|
+
): Promise<T> {
|
|
164
|
+
if (!signal) return promise
|
|
165
|
+
return new Promise<T>((resolve, reject) => {
|
|
166
|
+
const abort = () => reject(signal.reason)
|
|
167
|
+
if (signal.aborted) abort()
|
|
168
|
+
else signal.addEventListener('abort', abort, { once: true })
|
|
169
|
+
promise.then(
|
|
170
|
+
(value) => {
|
|
171
|
+
signal.removeEventListener('abort', abort)
|
|
172
|
+
resolve(value)
|
|
173
|
+
},
|
|
174
|
+
(error) => {
|
|
175
|
+
signal.removeEventListener('abort', abort)
|
|
176
|
+
reject(error)
|
|
177
|
+
},
|
|
178
|
+
)
|
|
179
|
+
})
|
|
180
|
+
}
|