@hearsay-tools/squawk 0.18.0-pr4005.7626 → 0.18.0-pr4006.7633

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.
@@ -0,0 +1,133 @@
1
+ import { z } from 'zod';
2
+ import { readNdjson } from '../../core/ndjson.js';
3
+ const idSchema = z.union([z.string(), z.number()]);
4
+ const frameSchema = z.object({
5
+ jsonrpc: z.literal('2.0'), id: idSchema.optional(), method: z.string().optional(),
6
+ params: z.unknown().optional(), result: z.unknown().optional(),
7
+ error: z.object({ code: z.number(), message: z.string(), data: z.unknown().optional() }).optional(),
8
+ });
9
+ export class AcpRpcError extends Error {
10
+ code;
11
+ data;
12
+ constructor(code, message, data) {
13
+ super(message);
14
+ this.code = code;
15
+ this.data = data;
16
+ }
17
+ }
18
+ /** ACP v1 uses one JSON-RPC object per UTF-8 line, not Content-Length headers.
19
+ * The caller owns the child, its deadline and process-tree cleanup. Closing this wire
20
+ * rejects receipts immediately; it does not claim that the child has exited. */
21
+ export class AcpTransport {
22
+ streams;
23
+ handlers;
24
+ serial = 0;
25
+ failure;
26
+ pending = new Map();
27
+ completion;
28
+ constructor(streams, handlers) {
29
+ this.streams = streams;
30
+ this.handlers = handlers;
31
+ const fail = (error) => this.close(error);
32
+ streams.input.on('error', fail);
33
+ streams.output.on('error', fail);
34
+ this.completion = this.read().finally(() => {
35
+ streams.input.off('error', fail);
36
+ streams.output.off('error', fail);
37
+ });
38
+ }
39
+ request(method, params) {
40
+ if (this.failure)
41
+ return Promise.reject(this.failure);
42
+ const id = ++this.serial;
43
+ return new Promise((resolve, reject) => {
44
+ this.pending.set(id, { resolve, reject });
45
+ try {
46
+ this.write({ jsonrpc: '2.0', id, method, params });
47
+ }
48
+ catch (error) {
49
+ this.close(asError(error));
50
+ }
51
+ });
52
+ }
53
+ notify(method, params) {
54
+ this.write({ jsonrpc: '2.0', method, params });
55
+ }
56
+ close(error = new Error('ACP transport closed')) {
57
+ this.failure ??= error;
58
+ for (const pending of this.pending.values())
59
+ pending.reject(this.failure);
60
+ this.pending.clear();
61
+ }
62
+ write(frame) {
63
+ if (this.failure)
64
+ throw this.failure;
65
+ if (!this.streams.input.writable)
66
+ throw new Error('ACP input is not writable');
67
+ this.streams.input.write(`${JSON.stringify(frame)}\n`, error => { if (error)
68
+ this.close(error); });
69
+ }
70
+ async read() {
71
+ try {
72
+ for await (const line of readNdjson(this.streams.output)) {
73
+ const frame = frameSchema.parse(JSON.parse(line));
74
+ this.handlers.activity?.();
75
+ if (frame.method !== undefined) {
76
+ if (frame.id === undefined)
77
+ this.notification(frame.method, frame.params);
78
+ else
79
+ void this.answer(frame.method, frame.params, frame.id);
80
+ }
81
+ else {
82
+ if (frame.id === undefined || (!('result' in frame) && !frame.error))
83
+ throw new Error('Invalid ACP response');
84
+ const pending = this.pending.get(frame.id);
85
+ this.pending.delete(frame.id);
86
+ if (frame.error)
87
+ pending?.reject(new AcpRpcError(frame.error.code, frame.error.message, frame.error.data));
88
+ else
89
+ pending?.resolve(frame.result);
90
+ }
91
+ }
92
+ this.close();
93
+ return undefined;
94
+ }
95
+ catch (error) {
96
+ const failure = asError(error);
97
+ this.close(failure);
98
+ return failure;
99
+ }
100
+ }
101
+ notification(method, params) {
102
+ try {
103
+ this.handlers.notification(method, params);
104
+ }
105
+ catch (error) {
106
+ // A well-framed notification is not a transport failure. Provider extensions and
107
+ // malformed update payloads must not reject an unrelated in-flight prompt.
108
+ try {
109
+ this.handlers.notice?.(`ACP ignored ${method}: ${asError(error).message}`);
110
+ }
111
+ catch { /* A diagnostic consumer cannot turn a dropped notification into a disconnect. */ }
112
+ }
113
+ }
114
+ async answer(method, params, id) {
115
+ try {
116
+ const result = await this.handlers.request(method, params, id);
117
+ this.write({ jsonrpc: '2.0', id, result });
118
+ }
119
+ catch (error) {
120
+ if (this.failure)
121
+ return;
122
+ const rpc = error instanceof AcpRpcError ? error : new AcpRpcError(-32603, asError(error).message);
123
+ try {
124
+ this.write({ jsonrpc: '2.0', id, error: { code: rpc.code, message: rpc.message } });
125
+ }
126
+ catch (writeError) {
127
+ this.close(asError(writeError));
128
+ }
129
+ }
130
+ }
131
+ }
132
+ function asError(error) { return error instanceof Error ? error : new Error(String(error)); }
133
+ //# sourceMappingURL=transport.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transport.js","sourceRoot":"","sources":["../../../src/runners/acp/transport.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAElD,MAAM,QAAQ,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;AACnD,MAAM,WAAW,GAAG,CAAC,CAAC,MAAM,CAAC;IAC3B,OAAO,EAAE,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,EAAE,EAAE,QAAQ,CAAC,QAAQ,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IACjF,MAAM,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE;IAC9D,KAAK,EAAE,CAAC,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC,QAAQ,EAAE;CACpG,CAAC,CAAC;AAEH,MAAM,OAAO,WAAY,SAAQ,KAAK;IACf,IAAI;IAAoC,IAAI;IAAjE,YAAqB,IAAY,EAAE,OAAe,EAAW,IAAc;QAAI,KAAK,CAAC,OAAO,CAAC,CAAC;oBAAzE,IAAI;oBAAoC,IAA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E,EAAE,CAAC,CAAC;YAAC,CAAC;YAC5F,OAAO,UAAU,EAAE,CAAC;gBAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC;YAAC,CAAC;QACzD,CAAC;IACH,CAAC;CACF;AAED,SAAS,OAAO,CAAC,KAAc,IAAW,OAAO,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC"}
@@ -40,7 +40,7 @@ export declare const reportsRoutes: import("hono/hono-base").HonoBase<ProjectApi
40
40
  error: string;
41
41
  };
42
42
  outputFormat: "json";
43
- status: 409;
43
+ status: 400;
44
44
  input: {
45
45
  query: {
46
46
  q?: string | undefined;
@@ -53,7 +53,7 @@ export declare const reportsRoutes: import("hono/hono-base").HonoBase<ProjectApi
53
53
  error: string;
54
54
  };
55
55
  outputFormat: "json";
56
- status: 400;
56
+ status: 409;
57
57
  input: {
58
58
  query: {
59
59
  q?: string | undefined;