@chopin-ai/harness-pi 0.0.0-stage → 0.2.0
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/LICENSE +202 -0
- package/dist/acp.d.ts +42 -0
- package/dist/acp.js +122 -0
- package/dist/acp.js.map +1 -0
- package/dist/auth.d.ts +25 -0
- package/dist/auth.js +56 -0
- package/dist/auth.js.map +1 -0
- package/dist/backoff.d.ts +5 -0
- package/dist/backoff.js +13 -0
- package/dist/backoff.js.map +1 -0
- package/dist/bridge.d.ts +11 -0
- package/dist/bridge.js +259 -0
- package/dist/bridge.js.map +1 -0
- package/dist/http.d.ts +7 -0
- package/dist/http.js +73 -0
- package/dist/http.js.map +1 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.js +11 -0
- package/dist/index.js.map +1 -0
- package/dist/layer.d.ts +8 -0
- package/dist/layer.js +84 -0
- package/dist/layer.js.map +1 -0
- package/dist/mcp.d.ts +24 -0
- package/dist/mcp.js +126 -0
- package/dist/mcp.js.map +1 -0
- package/dist/mode.d.ts +11 -0
- package/dist/mode.js +33 -0
- package/dist/mode.js.map +1 -0
- package/dist/pages.d.ts +8 -0
- package/dist/pages.js +12 -0
- package/dist/pages.js.map +1 -0
- package/dist/project-context.d.ts +18 -0
- package/dist/project-context.js +77 -0
- package/dist/project-context.js.map +1 -0
- package/dist/protocol.d.ts +247 -0
- package/dist/protocol.js +327 -0
- package/dist/protocol.js.map +1 -0
- package/dist/server.d.ts +25 -0
- package/dist/server.js +349 -0
- package/dist/server.js.map +1 -0
- package/dist/service.d.ts +96 -0
- package/dist/service.js +493 -0
- package/dist/service.js.map +1 -0
- package/dist/shell.d.ts +31 -0
- package/dist/shell.js +57 -0
- package/dist/shell.js.map +1 -0
- package/dist/submissions.d.ts +22 -0
- package/dist/submissions.js +33 -0
- package/dist/submissions.js.map +1 -0
- package/package.json +48 -3
- package/README.md +0 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/dist/acp.d.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { StopReason, ToolCallContent, SessionUpdate, Usage as AcpUsage } from "@agentclientprotocol/sdk";
|
|
2
|
+
import type { AssistantMessage, UserMessage } from "@earendil-works/pi-ai";
|
|
3
|
+
import type { ConversationView, EntryRecord } from "@earendil-works/pi-durable";
|
|
4
|
+
import type { TranscriptEntry } from "@chopin-ai/core";
|
|
5
|
+
/** A tool call's input as clients show it: its JSON, or nothing when it has none or no JSON says it. */
|
|
6
|
+
export declare function inputText(rawInput: unknown): string;
|
|
7
|
+
/** The text of what a user sent, its text blocks one after another. */
|
|
8
|
+
export declare function userText(content: UserMessage["content"]): string;
|
|
9
|
+
/** Text with its direction overrides and isolates marked, so a client shows it in the order it was written. */
|
|
10
|
+
export declare function inWrittenOrder(text: string): string;
|
|
11
|
+
/** A conversation's entries as transcript lines, each at its message's time, or at `now` when it has none. */
|
|
12
|
+
export declare function entryTranscript(sessionId: string, entries: readonly EntryRecord[], now?: string): TranscriptEntry[];
|
|
13
|
+
/** What a committed entry says, in ACP. Entries without a model-facing message say nothing. */
|
|
14
|
+
export declare function entryUpdates(entry: EntryRecord): SessionUpdate[];
|
|
15
|
+
/** What the agent is generating right now, in ACP; nothing between generations. */
|
|
16
|
+
export declare function liveUpdates(view: ConversationView): SessionUpdate[];
|
|
17
|
+
/** Whether the conversation has a run in progress. */
|
|
18
|
+
export declare function isRunning(view: ConversationView): boolean;
|
|
19
|
+
/** Whether the conversation's history is being summarized. */
|
|
20
|
+
export declare function isCompacting(view: ConversationView): boolean;
|
|
21
|
+
/** The newest compaction that failed, until one produces a summary: its task, and why. */
|
|
22
|
+
export declare function compactionFailure(view: ConversationView): {
|
|
23
|
+
taskId: number;
|
|
24
|
+
error: string;
|
|
25
|
+
} | undefined;
|
|
26
|
+
/** The submissions the run in progress serves, none between runs. */
|
|
27
|
+
export declare function runInputs(view: ConversationView): number[];
|
|
28
|
+
/** The text a tool returned. */
|
|
29
|
+
export declare function toolText(content: readonly ToolCallContent[]): string;
|
|
30
|
+
export declare function stopReason(message: AssistantMessage | undefined): StopReason;
|
|
31
|
+
/** Token totals over the given assistant messages, in ACP's usage shape. */
|
|
32
|
+
export declare function totalUsage(messages: readonly AssistantMessage[]): {
|
|
33
|
+
usage: AcpUsage;
|
|
34
|
+
cost: number;
|
|
35
|
+
};
|
|
36
|
+
/** Why a submission got no answer, with the harness's detail, such as the provider's own message, when it gave one. */
|
|
37
|
+
export declare function unansweredText(settled: {
|
|
38
|
+
reason: string;
|
|
39
|
+
detail?: unknown;
|
|
40
|
+
}): string;
|
|
41
|
+
/** The detail the harness gave with an unanswered submission, as text. */
|
|
42
|
+
export declare function detailText(detail: unknown): string | undefined;
|
package/dist/acp.js
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/** A tool call's input as clients show it: its JSON, or nothing when it has none or no JSON says it. */
|
|
2
|
+
export function inputText(rawInput) {
|
|
3
|
+
const text = rawInput === undefined ? undefined : JSON.stringify(rawInput);
|
|
4
|
+
return text === undefined || text === "{}" ? "" : text;
|
|
5
|
+
}
|
|
6
|
+
/** The text of what a user sent, its text blocks one after another. */
|
|
7
|
+
export function userText(content) {
|
|
8
|
+
return typeof content === "string" ? content : content.flatMap((block) => (block.type === "text" ? [block.text] : [])).join("\n");
|
|
9
|
+
}
|
|
10
|
+
/** Text with its direction overrides and isolates marked, so a client shows it in the order it was written. */
|
|
11
|
+
export function inWrittenOrder(text) {
|
|
12
|
+
return text.replace(/[\u202a-\u202e\u2066-\u2069]/g, "\ufffd");
|
|
13
|
+
}
|
|
14
|
+
/** A conversation's entries as transcript lines, each at its message's time, or at `now` when it has none. */
|
|
15
|
+
export function entryTranscript(sessionId, entries, now = new Date().toISOString()) {
|
|
16
|
+
return entries.flatMap((entry) => {
|
|
17
|
+
const time = entry.model?.find((message) => "timestamp" in message)?.timestamp;
|
|
18
|
+
const at = time === undefined ? now : new Date(time).toISOString();
|
|
19
|
+
return entryUpdates(entry).map((update) => ({ at, notification: { sessionId, update } }));
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
/** What a committed entry says, in ACP. Entries without a model-facing message say nothing. */
|
|
23
|
+
export function entryUpdates(entry) {
|
|
24
|
+
return (entry.model ?? []).flatMap(messageUpdates);
|
|
25
|
+
}
|
|
26
|
+
/** What the agent is generating right now, in ACP; nothing between generations. */
|
|
27
|
+
export function liveUpdates(view) {
|
|
28
|
+
const partial = view.docs["pi.live"]?.generation?.message;
|
|
29
|
+
return partial === undefined ? [] : messageUpdates(partial);
|
|
30
|
+
}
|
|
31
|
+
/** Whether the conversation has a run in progress. */
|
|
32
|
+
export function isRunning(view) {
|
|
33
|
+
return view.docs["pi.live"]?.run !== undefined;
|
|
34
|
+
}
|
|
35
|
+
/** Whether the conversation's history is being summarized. */
|
|
36
|
+
export function isCompacting(view) {
|
|
37
|
+
return (view.docs["pi.live"]?.compactions?.length ?? 0) > 0;
|
|
38
|
+
}
|
|
39
|
+
/** The newest compaction that failed, until one produces a summary: its task, and why. */
|
|
40
|
+
export function compactionFailure(view) {
|
|
41
|
+
return view.docs["pi.live"]?.compactionFailure;
|
|
42
|
+
}
|
|
43
|
+
/** The submissions the run in progress serves, none between runs. */
|
|
44
|
+
export function runInputs(view) {
|
|
45
|
+
return view.docs["pi.live"]?.run?.inputs ?? [];
|
|
46
|
+
}
|
|
47
|
+
/** The text a tool returned. */
|
|
48
|
+
export function toolText(content) {
|
|
49
|
+
return content.flatMap((item) => (item.type === "content" && item.content.type === "text" ? [item.content.text] : [])).join("\n");
|
|
50
|
+
}
|
|
51
|
+
function messageUpdates(message) {
|
|
52
|
+
switch (message.role) {
|
|
53
|
+
case "user": {
|
|
54
|
+
const blocks = typeof message.content === "string" ? [{ type: "text", text: message.content }] : message.content;
|
|
55
|
+
return blocks.map((block) => ({ sessionUpdate: "user_message_chunk", content: content(block) }));
|
|
56
|
+
}
|
|
57
|
+
case "assistant":
|
|
58
|
+
return message.content.map((block) => {
|
|
59
|
+
if (block.type === "text")
|
|
60
|
+
return { sessionUpdate: "agent_message_chunk", content: content(block) };
|
|
61
|
+
if (block.type === "thinking")
|
|
62
|
+
return { sessionUpdate: "agent_thought_chunk", content: { type: "text", text: block.thinking } };
|
|
63
|
+
return {
|
|
64
|
+
sessionUpdate: "tool_call", toolCallId: block.id, title: block.name, kind: toolKind(block.name),
|
|
65
|
+
status: "pending", rawInput: block.arguments,
|
|
66
|
+
};
|
|
67
|
+
});
|
|
68
|
+
case "toolResult":
|
|
69
|
+
return [{
|
|
70
|
+
sessionUpdate: "tool_call_update", toolCallId: message.toolCallId, status: message.isError ? "failed" : "completed",
|
|
71
|
+
content: message.content.map((block) => ({ type: "content", content: content(block) })),
|
|
72
|
+
}];
|
|
73
|
+
default:
|
|
74
|
+
return [];
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
function content(block) {
|
|
78
|
+
return block.type === "text" ? { type: "text", text: block.text } : { type: "image", data: block.data, mimeType: block.mimeType };
|
|
79
|
+
}
|
|
80
|
+
function toolKind(name) {
|
|
81
|
+
if (name === "read" || name === "skill")
|
|
82
|
+
return "read";
|
|
83
|
+
if (name === "write" || name === "edit")
|
|
84
|
+
return "edit";
|
|
85
|
+
if (name === "bash")
|
|
86
|
+
return "execute";
|
|
87
|
+
return "other";
|
|
88
|
+
}
|
|
89
|
+
export function stopReason(message) {
|
|
90
|
+
if (message?.stopReason === "aborted")
|
|
91
|
+
return "cancelled";
|
|
92
|
+
if (message?.stopReason === "length")
|
|
93
|
+
return "max_tokens";
|
|
94
|
+
return "end_turn";
|
|
95
|
+
}
|
|
96
|
+
/** Token totals over the given assistant messages, in ACP's usage shape. */
|
|
97
|
+
export function totalUsage(messages) {
|
|
98
|
+
const sum = (pick) => messages.reduce((total, m) => total + (pick(m.usage) ?? 0), 0);
|
|
99
|
+
const cacheRead = sum((u) => u.cacheRead);
|
|
100
|
+
const cacheWrite = sum((u) => u.cacheWrite);
|
|
101
|
+
return {
|
|
102
|
+
usage: {
|
|
103
|
+
totalTokens: sum((u) => u.totalTokens),
|
|
104
|
+
inputTokens: sum((u) => u.input) + cacheRead + cacheWrite,
|
|
105
|
+
outputTokens: sum((u) => u.output),
|
|
106
|
+
thoughtTokens: sum((u) => u.reasoning),
|
|
107
|
+
cachedReadTokens: cacheRead,
|
|
108
|
+
cachedWriteTokens: cacheWrite,
|
|
109
|
+
},
|
|
110
|
+
cost: sum((u) => u.cost.total),
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
/** Why a submission got no answer, with the harness's detail, such as the provider's own message, when it gave one. */
|
|
114
|
+
export function unansweredText(settled) {
|
|
115
|
+
const detail = detailText(settled.detail);
|
|
116
|
+
return detail === undefined ? settled.reason : `${settled.reason}: ${detail}`;
|
|
117
|
+
}
|
|
118
|
+
/** The detail the harness gave with an unanswered submission, as text. */
|
|
119
|
+
export function detailText(detail) {
|
|
120
|
+
return detail === undefined ? undefined : typeof detail === "string" ? detail : JSON.stringify(detail);
|
|
121
|
+
}
|
|
122
|
+
//# sourceMappingURL=acp.js.map
|
package/dist/acp.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"acp.js","sourceRoot":"","sources":["../src/acp.ts"],"names":[],"mappings":"AAKA,wGAAwG;AACxG,MAAM,UAAU,SAAS,CAAC,QAAiB;IACzC,MAAM,IAAI,GAAG,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,QAAQ,CAA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,CAAC,CAAC;IAC1C,OAAO,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,MAAM,KAAK,MAAM,EAAE,CAAC;AAChF,CAAC;AAED,0EAA0E;AAC1E,MAAM,UAAU,UAAU,CAAC,MAAe;IACxC,OAAO,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,OAAO,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;AACzG,CAAC"}
|
package/dist/auth.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { IncomingMessage } from "node:http";
|
|
2
|
+
import { jwtVerify } from "jose";
|
|
3
|
+
import type { Principal } from "./protocol.js";
|
|
4
|
+
/** Names the owner a credential stands for, or refuses it with `undefined`. */
|
|
5
|
+
export type Authenticate = (credential: string) => Principal | undefined | Promise<Principal | undefined>;
|
|
6
|
+
/**
|
|
7
|
+
* The cookie a browser keeps its credential in, set when it first presents one as `?token=`. Browsers share cookies
|
|
8
|
+
* across the ports of a host, so each service names its own by port.
|
|
9
|
+
*/
|
|
10
|
+
export declare function credentialCookie(request: IncomingMessage): string;
|
|
11
|
+
/**
|
|
12
|
+
* The credential a request presents. Browsers cannot set headers on a WebSocket, so besides a bearer header it may
|
|
13
|
+
* travel as `?token=` or, once a page has presented it, as a cookie.
|
|
14
|
+
*/
|
|
15
|
+
export declare function credentialOf(request: IncomingMessage): string | undefined;
|
|
16
|
+
/** Single-user mode: whoever presents the launch token is the one local owner. */
|
|
17
|
+
export declare function launchToken(token: string, owner?: string): Authenticate;
|
|
18
|
+
export interface IntegratorTokenOptions {
|
|
19
|
+
/** The integrator's public key, or a key set such as one from `createRemoteJWKSet`. */
|
|
20
|
+
key: Parameters<typeof jwtVerify>[1];
|
|
21
|
+
issuer?: string;
|
|
22
|
+
audience?: string;
|
|
23
|
+
}
|
|
24
|
+
/** Integrated mode: the integrator signs short-lived tokens, and their subject is the owner. There are no accounts here. */
|
|
25
|
+
export declare function integratorTokens(options: IntegratorTokenOptions): Authenticate;
|
package/dist/auth.js
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { timingSafeEqual } from "node:crypto";
|
|
2
|
+
import { jwtVerify } from "jose";
|
|
3
|
+
/**
|
|
4
|
+
* The cookie a browser keeps its credential in, set when it first presents one as `?token=`. Browsers share cookies
|
|
5
|
+
* across the ports of a host, so each service names its own by port.
|
|
6
|
+
*/
|
|
7
|
+
export function credentialCookie(request) {
|
|
8
|
+
try {
|
|
9
|
+
const port = new URL(`http://${request.headers.host ?? "localhost"}`).port;
|
|
10
|
+
return port === "" ? "chopin" : `chopin-${port}`;
|
|
11
|
+
}
|
|
12
|
+
catch {
|
|
13
|
+
return "chopin";
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* The credential a request presents. Browsers cannot set headers on a WebSocket, so besides a bearer header it may
|
|
18
|
+
* travel as `?token=` or, once a page has presented it, as a cookie.
|
|
19
|
+
*/
|
|
20
|
+
export function credentialOf(request) {
|
|
21
|
+
// Any page of the host can plant a malformed cookie; it must refuse the request, not end the service.
|
|
22
|
+
try {
|
|
23
|
+
const bearer = /^Bearer (.+)$/.exec(request.headers.authorization ?? "")?.[1];
|
|
24
|
+
const query = new URL(request.url ?? "/", "http://localhost").searchParams.get("token");
|
|
25
|
+
const name = credentialCookie(request);
|
|
26
|
+
const cookie = (request.headers.cookie ?? "").split(";").map((part) => part.trim().split("="))
|
|
27
|
+
.find(([key]) => key === name)?.[1];
|
|
28
|
+
return bearer ?? query ?? (cookie === undefined ? undefined : decodeURIComponent(cookie));
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
return undefined;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
/** Single-user mode: whoever presents the launch token is the one local owner. */
|
|
35
|
+
export function launchToken(token, owner = "local") {
|
|
36
|
+
const expected = Buffer.from(token);
|
|
37
|
+
return (credential) => {
|
|
38
|
+
const given = Buffer.from(credential);
|
|
39
|
+
return given.length === expected.length && timingSafeEqual(given, expected) ? { kind: "owner", owner } : undefined;
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
/** Integrated mode: the integrator signs short-lived tokens, and their subject is the owner. There are no accounts here. */
|
|
43
|
+
export function integratorTokens(options) {
|
|
44
|
+
const verify = { ...(options.issuer && { issuer: options.issuer }), ...(options.audience && { audience: options.audience }) };
|
|
45
|
+
return async (credential) => {
|
|
46
|
+
try {
|
|
47
|
+
const { payload } = await jwtVerify(credential, options.key, { ...verify, requiredClaims: ["sub", "exp"] });
|
|
48
|
+
const owner = payload.sub;
|
|
49
|
+
return typeof owner === "string" && owner !== "" && !/[\r\n]/.test(owner) ? { kind: "owner", owner } : undefined;
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
return undefined;
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=auth.js.map
|
package/dist/auth.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.js","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAE9C,OAAO,EAAE,SAAS,EAAE,MAAM,MAAM,CAAC;AAMjC;;;GAGG;AACH,MAAM,UAAU,gBAAgB,CAAC,OAAwB;IACvD,IAAI,CAAC;QACH,MAAM,IAAI,GAAG,IAAI,GAAG,CAAC,UAAU,OAAO,CAAC,OAAO,CAAC,IAAI,IAAI,WAAW,EAAE,CAAC,CAAC,IAAI,CAAC;QAC3E,OAAO,IAAI,KAAK,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,UAAU,IAAI,EAAE,CAAC;IACnD,CAAC;IAAC,MAAM,CAAC;QACP,O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,CAAC;QACtC,OAAO,KAAK,CAAC,MAAM,KAAK,QAAQ,CAAC,MAAM,IAAI,eAAe,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;IACrH,CAAC,CAAC;AACJ,CAAC;AASD,4HAA4H;AAC5H,MAAM,UAAU,gBAAgB,CAAC,OAA+B;IAC9D,MAAM,MAAM,GAAG,EAAE,GAAG,CAAC,OAAO,CAAC,MAAM,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,CAAC,EAAE,GAAG,CAAC,OAAO,CAAC,QAAQ,IAAI,EAAE,QAAQ,EAAE,OAAO,CAAC,QAAQ,EAAE,CAAC,EAAE,CAAC;IAC9H,OAAO,KAAK,EAAE,UAAU,EAAE,EAAE;QAC1B,IAAI,CAAC;YACH,MAAM,EAAE,OAAO,EAAE,GAAG,MAAM,SAAS,CAAC,UAAU,EAAE,OAAO,CAAC,GAAG,EAAE,EAAE,GAAG,MAAM,EAAE,cAAc,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,EAAE,CAAC,CAAC;YAC5G,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC;YAC1B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;QACnH,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,SAAS,CAAC;QACnB,CAAC;IACH,CAAC,CAAC;AACJ,CAAC"}
|
package/dist/backoff.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** Waits that double from `first` up to `last`, back to `first` on `reset`. */
|
|
2
|
+
export function backoff(first, last) {
|
|
3
|
+
let wait = first;
|
|
4
|
+
return {
|
|
5
|
+
next: () => {
|
|
6
|
+
const now = wait;
|
|
7
|
+
wait = Math.min(wait * 2, last);
|
|
8
|
+
return now;
|
|
9
|
+
},
|
|
10
|
+
reset: () => void (wait = first),
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=backoff.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"backoff.js","sourceRoot":"","sources":["../src/backoff.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,MAAM,UAAU,OAAO,CAAC,KAAa,EAAE,IAAY;IACjD,IAAI,IAAI,GAAG,KAAK,CAAC;IACjB,OAAO;QACL,IAAI,EAAE,GAAG,EAAE;YACT,MAAM,GAAG,GAAG,IAAI,CAAC;YACjB,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC,EAAE,IAAI,CAAC,CAAC;YAChC,OAAO,GAAG,CAAC;QACb,CAAC;QACD,KAAK,EAAE,GAAG,EAAE,CAAC,KAAK,CAAC,IAAI,GAAG,KAAK,CAAC;KACjC,CAAC;AACJ,CAAC"}
|
package/dist/bridge.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { AgentSideConnection, type Stream } from "@agentclientprotocol/sdk";
|
|
2
|
+
import type { Host } from "@earendil-works/chord";
|
|
3
|
+
export interface BridgeOptions {
|
|
4
|
+
/** How long a request waits for a service it lost to come back before it fails; `CALL_TIMEOUT_MS` by default. */
|
|
5
|
+
lostAfterMs?: number;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Speaks ACP on `stream` for the agent behind `client`, a host connected to the agent service, so any ACP client
|
|
9
|
+
* can drive it. One ACP session is one conversation.
|
|
10
|
+
*/
|
|
11
|
+
export declare function serveAcp(stream: Stream, client: Host, options?: BridgeOptions): AgentSideConnection;
|