@qlairoslabs/acp-client 0.7.2 → 0.7.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/CONSUMER_GUIDE.md +12 -1
- package/README.md +11 -2
- package/package.json +1 -1
- package/src/agent-session.ts +5 -3
- package/src/index.ts +1 -0
- package/src/response.ts +17 -1
- package/src/types.ts +6 -2
package/CONSUMER_GUIDE.md
CHANGED
|
@@ -48,6 +48,7 @@ import {
|
|
|
48
48
|
AuditLogReader,
|
|
49
49
|
SessionManager,
|
|
50
50
|
TranscriptReader,
|
|
51
|
+
formatResponseMessages,
|
|
51
52
|
type Adapter,
|
|
52
53
|
type AgentSessionNotification,
|
|
53
54
|
type PromptHandlers,
|
|
@@ -189,7 +190,11 @@ const handlers: PromptHandlers = {
|
|
|
189
190
|
const result = await session.prompt("Inspect the failing tests.", handlers);
|
|
190
191
|
|
|
191
192
|
console.log(result.status);
|
|
192
|
-
|
|
193
|
+
for (const message of result.messages) {
|
|
194
|
+
renderAssistantMessage(message);
|
|
195
|
+
}
|
|
196
|
+
// Only when this consumer explicitly needs one string:
|
|
197
|
+
console.log(formatResponseMessages(result.messages, "\n\n"));
|
|
193
198
|
console.log(result.operationId);
|
|
194
199
|
console.log(result.metering);
|
|
195
200
|
```
|
|
@@ -197,6 +202,12 @@ console.log(result.metering);
|
|
|
197
202
|
Prompts, configuration changes, handoffs, and other mutations are serialized by each
|
|
198
203
|
`AgentSession`. Multiple different `AgentSession` objects may operate concurrently.
|
|
199
204
|
|
|
205
|
+
`result.messages` is the canonical response. A prompt operation may contain several
|
|
206
|
+
distinct assistant messages; render them separately when the UI supports that. The
|
|
207
|
+
deprecated `result.text` property is only a compatibility projection and inserts a blank
|
|
208
|
+
line between messages. `formatResponseMessages()` makes any deliberate flattening policy
|
|
209
|
+
consumer-owned.
|
|
210
|
+
|
|
200
211
|
## Observe state, context, and usage
|
|
201
212
|
|
|
202
213
|
Read a snapshot first, then subscribe to changes:
|
package/README.md
CHANGED
|
@@ -75,7 +75,12 @@ see the [consumer guide](./CONSUMER_GUIDE.md).
|
|
|
75
75
|
### One-shot prompt
|
|
76
76
|
|
|
77
77
|
```ts
|
|
78
|
-
import {
|
|
78
|
+
import {
|
|
79
|
+
AgentController,
|
|
80
|
+
ADAPTERS,
|
|
81
|
+
createConsoleLogger,
|
|
82
|
+
formatResponseMessages,
|
|
83
|
+
} from "@qlairoslabs/acp-client";
|
|
79
84
|
|
|
80
85
|
const agent = new AgentController({
|
|
81
86
|
adapter: ADAPTERS.codex,
|
|
@@ -89,7 +94,11 @@ const { sessionId, resumed } = await agent.start();
|
|
|
89
94
|
console.log(resumed ? "resumed" : "new", sessionId);
|
|
90
95
|
|
|
91
96
|
const result = await agent.prompt("Refactor utils.ts for readability.");
|
|
92
|
-
console.log(
|
|
97
|
+
for (const message of result.messages) console.log(message.text);
|
|
98
|
+
console.log(result.stopReason, result.usage);
|
|
99
|
+
|
|
100
|
+
// If this application specifically needs a single string:
|
|
101
|
+
const displayText = formatResponseMessages(result.messages, "\n\n");
|
|
93
102
|
|
|
94
103
|
await agent.stop();
|
|
95
104
|
```
|
package/package.json
CHANGED
package/src/agent-session.ts
CHANGED
|
@@ -19,7 +19,7 @@ import type { Capabilities } from "./capabilities.ts";
|
|
|
19
19
|
import type { ConfigOption, ConfigOptions } from "./config-options.ts";
|
|
20
20
|
import type { ConnectResult } from "./client.ts";
|
|
21
21
|
import { noopLogger, type Logger } from "./logger.ts";
|
|
22
|
-
import { ResponseAccumulator } from "./response.ts";
|
|
22
|
+
import { formatResponseMessages, ResponseAccumulator } from "./response.ts";
|
|
23
23
|
import { MeteringEngine, type OpenOperation } from "./metering/engine.ts";
|
|
24
24
|
import {
|
|
25
25
|
AgentSessionHandoffError,
|
|
@@ -1892,7 +1892,9 @@ export class AgentSession implements AgentClient, Bridgeable {
|
|
|
1892
1892
|
if (generated.status !== "completed" || !generated.text.trim()) {
|
|
1893
1893
|
throw new Error(`handoff summary generation ${generated.status}`);
|
|
1894
1894
|
}
|
|
1895
|
-
|
|
1895
|
+
// Handoff requires one seed string, so this internal boundary policy is explicit;
|
|
1896
|
+
// it is not treated as the canonical shape of the provider response.
|
|
1897
|
+
summary = formatResponseMessages(generated.messages, "\n\n").trim();
|
|
1896
1898
|
}
|
|
1897
1899
|
|
|
1898
1900
|
const created = await this.controller.newSession();
|
|
@@ -2886,7 +2888,7 @@ export class AgentSession implements AgentClient, Bridgeable {
|
|
|
2886
2888
|
kind: "message",
|
|
2887
2889
|
operationId,
|
|
2888
2890
|
role: "assistant",
|
|
2889
|
-
text: result.
|
|
2891
|
+
text: formatResponseMessages(result.messages, "\n\n"),
|
|
2890
2892
|
structured: { version: 1, messages: result.messages },
|
|
2891
2893
|
stopReason: result.stopReason,
|
|
2892
2894
|
status: result.status,
|
package/src/index.ts
CHANGED
|
@@ -98,6 +98,7 @@ export type {
|
|
|
98
98
|
export type { TerminalHandlers } from "./transport/acp-transport.ts";
|
|
99
99
|
|
|
100
100
|
export { extractChunkText, extractResponseChunk, toActivityEvent } from "./updates.ts";
|
|
101
|
+
export { formatResponseMessages } from "./response.ts";
|
|
101
102
|
|
|
102
103
|
export {
|
|
103
104
|
ActivityAggregator,
|
package/src/response.ts
CHANGED
|
@@ -7,14 +7,29 @@ export interface IncomingResponseChunk {
|
|
|
7
7
|
startsMessage?: boolean;
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
+
/**
|
|
11
|
+
* Explicitly flatten structured response messages using a separator chosen by the
|
|
12
|
+
* consumer. This is a display conversion; it does not alter the messages themselves.
|
|
13
|
+
*/
|
|
14
|
+
export function formatResponseMessages(
|
|
15
|
+
messages: readonly ResponseMessage[],
|
|
16
|
+
separator: string,
|
|
17
|
+
): string {
|
|
18
|
+
if (typeof separator !== "string") throw new TypeError("response message separator must be a string");
|
|
19
|
+
return messages.map((message) => message.text).join(separator);
|
|
20
|
+
}
|
|
21
|
+
|
|
10
22
|
/**
|
|
11
23
|
* Produce the legacy combined-text view without erasing protocol message boundaries.
|
|
12
24
|
* Message text is preserved verbatim; the only inserted content is the boundary between
|
|
13
25
|
* entries. Empty entries therefore participate in the literal join rather than being
|
|
14
26
|
* silently removed.
|
|
27
|
+
*
|
|
28
|
+
* @deprecated Use the canonical message array, or call `formatResponseMessages` with an
|
|
29
|
+
* explicit consumer-selected separator.
|
|
15
30
|
*/
|
|
16
31
|
export function joinResponseMessages(messages: readonly ResponseMessage[]): string {
|
|
17
|
-
return messages
|
|
32
|
+
return formatResponseMessages(messages, "\n\n");
|
|
18
33
|
}
|
|
19
34
|
|
|
20
35
|
/**
|
|
@@ -54,6 +69,7 @@ export class ResponseAccumulator {
|
|
|
54
69
|
: { text: chunk.text, messageId: chunk.messageId, startsMessage };
|
|
55
70
|
}
|
|
56
71
|
|
|
72
|
+
/** @deprecated Prefer `snapshot()` and preserve the distinct response messages. */
|
|
57
73
|
get text(): string {
|
|
58
74
|
return joinResponseMessages(this.entries);
|
|
59
75
|
}
|
package/src/types.ts
CHANGED
|
@@ -58,9 +58,13 @@ export type Usage = TokenUsage;
|
|
|
58
58
|
* call RESOLVES (not rejects) with whatever partial text arrived.
|
|
59
59
|
*/
|
|
60
60
|
export interface PromptResult {
|
|
61
|
-
/**
|
|
61
|
+
/**
|
|
62
|
+
* Legacy lossy projection of `messages`, separated by one blank line.
|
|
63
|
+
* @deprecated Use `messages`, preserving each logical ACP response message. Consumers
|
|
64
|
+
* that require one string can call `formatResponseMessages` with their own separator.
|
|
65
|
+
*/
|
|
62
66
|
text: string;
|
|
63
|
-
/**
|
|
67
|
+
/** Canonical assistant result in protocol order, preserving ACP message boundaries. */
|
|
64
68
|
messages: readonly ResponseMessage[];
|
|
65
69
|
/** Raw protocol stop reason: "end_turn" | "cancelled" | "max_tokens" | ... */
|
|
66
70
|
stopReason: string;
|