@pontia/claude-client 0.7.12 → 0.7.14
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/dist/src/facts.js +37 -9
- package/dist/src/host.js +26 -6
- package/dist/src/input.js +7 -8
- package/dist/src/server.js +3 -0
- package/package.json +1 -1
package/dist/src/facts.js
CHANGED
|
@@ -21,29 +21,32 @@ function outcome(message) {
|
|
|
21
21
|
message.stop_reason === "stop_sequence" &&
|
|
22
22
|
message.terminal_reason === "api_error")
|
|
23
23
|
return "failed";
|
|
24
|
-
if (message.subtype === "error_during_execution" &&
|
|
25
|
-
message.is_error &&
|
|
24
|
+
if (((message.subtype === "error_during_execution" && message.is_error) ||
|
|
25
|
+
(message.subtype === "success" && !message.is_error)) &&
|
|
26
26
|
((message.stop_reason === null && message.terminal_reason === "aborted_streaming") ||
|
|
27
27
|
(message.stop_reason === "tool_use" && message.terminal_reason === "aborted_tools")))
|
|
28
28
|
return "interrupted";
|
|
29
29
|
return undefined;
|
|
30
30
|
}
|
|
31
|
-
function association(message,
|
|
31
|
+
function association(message, inputs) {
|
|
32
32
|
const ids = message.user_message_uuids ?? (message.user_message_uuid ? [message.user_message_uuid] : []);
|
|
33
33
|
if (!ids.length)
|
|
34
34
|
return message.user_message_uuid ? "conflict" : "none";
|
|
35
|
-
return ids.
|
|
36
|
-
|
|
37
|
-
(!message.user_message_uuid || message.user_message_uuid === input)
|
|
35
|
+
return ids.every((id) => inputs.has(id)) &&
|
|
36
|
+
(!message.user_message_uuid || ids.includes(message.user_message_uuid))
|
|
38
37
|
? "matched"
|
|
39
38
|
: "conflict";
|
|
40
39
|
}
|
|
41
|
-
// One
|
|
40
|
+
// One Pontia task, including native steering continuations.
|
|
42
41
|
export class InputFacts {
|
|
43
42
|
id;
|
|
44
43
|
emit;
|
|
45
44
|
started = false;
|
|
46
45
|
finished = false;
|
|
46
|
+
inputs;
|
|
47
|
+
pending;
|
|
48
|
+
// Steering text until a native frame proves which reply consumed it.
|
|
49
|
+
unconsumed = new Map();
|
|
47
50
|
ownsReplies = false;
|
|
48
51
|
streamMessage;
|
|
49
52
|
streamed = new Set();
|
|
@@ -54,12 +57,29 @@ export class InputFacts {
|
|
|
54
57
|
this.id = id;
|
|
55
58
|
this.emit = emit;
|
|
56
59
|
this.historyAnchor = id;
|
|
60
|
+
this.inputs = new Set([id]);
|
|
61
|
+
this.pending = new Set([id]);
|
|
62
|
+
}
|
|
63
|
+
steer(id, text) {
|
|
64
|
+
this.inputs.add(id);
|
|
65
|
+
this.pending.add(id);
|
|
66
|
+
this.unconsumed.set(id, text);
|
|
67
|
+
}
|
|
68
|
+
consumed(message) {
|
|
69
|
+
const ids = message.user_message_uuids ?? (message.user_message_uuid ? [message.user_message_uuid] : []);
|
|
70
|
+
for (const id of ids) {
|
|
71
|
+
const text = this.unconsumed.get(id);
|
|
72
|
+
if (text === undefined)
|
|
73
|
+
continue;
|
|
74
|
+
this.unconsumed.delete(id);
|
|
75
|
+
this.emit({ kind: "input", input_id: this.id, item_id: id, text });
|
|
76
|
+
}
|
|
57
77
|
}
|
|
58
78
|
accept(message) {
|
|
59
79
|
if ("parent_tool_use_id" in message && message.parent_tool_use_id)
|
|
60
80
|
return;
|
|
61
81
|
if (message.type === "result") {
|
|
62
|
-
const match = association(message, this.
|
|
82
|
+
const match = association(message, this.inputs);
|
|
63
83
|
if (match === "none")
|
|
64
84
|
return; // An automatic/background result does not consume our task.
|
|
65
85
|
this.ownsReplies = false;
|
|
@@ -71,9 +91,16 @@ export class InputFacts {
|
|
|
71
91
|
return;
|
|
72
92
|
if (!this.started)
|
|
73
93
|
throw new FactError("result_without_start", message);
|
|
94
|
+
this.consumed(message);
|
|
74
95
|
const terminal = outcome(message);
|
|
75
96
|
if (!terminal)
|
|
76
97
|
throw new FactError("unsupported_result", message);
|
|
98
|
+
const ids = message.user_message_uuids ?? [message.user_message_uuid];
|
|
99
|
+
for (const id of ids)
|
|
100
|
+
this.pending.delete(id);
|
|
101
|
+
// A native result may finish only the round displaced by steering.
|
|
102
|
+
if (this.pending.size)
|
|
103
|
+
return;
|
|
77
104
|
this.finished = true;
|
|
78
105
|
this.emit({
|
|
79
106
|
kind: "finished",
|
|
@@ -87,7 +114,7 @@ export class InputFacts {
|
|
|
87
114
|
if (this.finished)
|
|
88
115
|
return;
|
|
89
116
|
if (message.type === "stream_event" || message.type === "assistant") {
|
|
90
|
-
const match = association(message, this.
|
|
117
|
+
const match = association(message, this.inputs);
|
|
91
118
|
if (match === "conflict")
|
|
92
119
|
throw new Error("input_association_conflict");
|
|
93
120
|
if (match === "matched") {
|
|
@@ -96,6 +123,7 @@ export class InputFacts {
|
|
|
96
123
|
this.started = true;
|
|
97
124
|
this.emit({ kind: "started", input_id: this.id });
|
|
98
125
|
}
|
|
126
|
+
this.consumed(message);
|
|
99
127
|
}
|
|
100
128
|
if (!this.ownsReplies)
|
|
101
129
|
return;
|
package/dist/src/host.js
CHANGED
|
@@ -48,12 +48,7 @@ export class Host {
|
|
|
48
48
|
submit(id, text) {
|
|
49
49
|
if (!this.acceptsControl())
|
|
50
50
|
throw new ControlError("rejected", "execution_unavailable");
|
|
51
|
-
|
|
52
|
-
!text.trim()) {
|
|
53
|
-
throw new ControlError("rejected", "invalid_input");
|
|
54
|
-
}
|
|
55
|
-
if (this.usedInputs.has(id))
|
|
56
|
-
throw new ControlError("rejected", "input_already_submitted");
|
|
51
|
+
this.validateInput(id, text);
|
|
57
52
|
if (this.current && !this.current.finished)
|
|
58
53
|
throw new ControlError("rejected", "input_busy");
|
|
59
54
|
this.usedInputs.add(id);
|
|
@@ -102,6 +97,31 @@ export class Host {
|
|
|
102
97
|
}
|
|
103
98
|
}
|
|
104
99
|
}
|
|
100
|
+
steer(target, id, text) {
|
|
101
|
+
if (!this.acceptsControl())
|
|
102
|
+
throw new ControlError("rejected", "execution_unavailable");
|
|
103
|
+
this.validateInput(id, text);
|
|
104
|
+
if (!this.current?.started || this.current.finished || this.current.id !== target)
|
|
105
|
+
throw new ControlError("rejected", "no_matching_execution");
|
|
106
|
+
this.input.push({
|
|
107
|
+
type: "user",
|
|
108
|
+
uuid: id,
|
|
109
|
+
session_id: this.native,
|
|
110
|
+
parent_tool_use_id: null,
|
|
111
|
+
message: { role: "user", content: text },
|
|
112
|
+
priority: "now",
|
|
113
|
+
});
|
|
114
|
+
this.usedInputs.add(id);
|
|
115
|
+
this.current.steer(id, text);
|
|
116
|
+
}
|
|
117
|
+
validateInput(id, text) {
|
|
118
|
+
if (!/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(id) ||
|
|
119
|
+
!text.trim()) {
|
|
120
|
+
throw new ControlError("rejected", "invalid_input");
|
|
121
|
+
}
|
|
122
|
+
if (this.usedInputs.has(id))
|
|
123
|
+
throw new ControlError("rejected", "input_already_submitted");
|
|
124
|
+
}
|
|
105
125
|
async listModels() {
|
|
106
126
|
if (!this.acceptsControl() || !this.execution || !this.native)
|
|
107
127
|
throw new ControlError("rejected", "execution_unavailable");
|
package/dist/src/input.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
//
|
|
1
|
+
// Host admits a task and its steering messages to the SDK stream.
|
|
2
2
|
export class Input {
|
|
3
|
-
pending;
|
|
3
|
+
pending = [];
|
|
4
4
|
waiter;
|
|
5
5
|
ended = false;
|
|
6
6
|
push(message) {
|
|
7
|
-
if (this.ended
|
|
7
|
+
if (this.ended)
|
|
8
8
|
throw new Error("Input is unavailable");
|
|
9
9
|
if (this.waiter) {
|
|
10
10
|
const resolve = this.waiter;
|
|
@@ -12,21 +12,20 @@ export class Input {
|
|
|
12
12
|
resolve({ done: false, value: message });
|
|
13
13
|
}
|
|
14
14
|
else {
|
|
15
|
-
this.pending
|
|
15
|
+
this.pending.push(message);
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
18
|
end() {
|
|
19
19
|
this.ended = true;
|
|
20
|
-
this.pending =
|
|
20
|
+
this.pending = [];
|
|
21
21
|
this.waiter?.({ done: true, value: undefined });
|
|
22
22
|
this.waiter = undefined;
|
|
23
23
|
}
|
|
24
24
|
[Symbol.asyncIterator]() {
|
|
25
25
|
return {
|
|
26
26
|
next: () => {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
this.pending = undefined;
|
|
27
|
+
const value = this.pending.shift();
|
|
28
|
+
if (value) {
|
|
30
29
|
return Promise.resolve({ done: false, value });
|
|
31
30
|
}
|
|
32
31
|
if (this.ended)
|
package/dist/src/server.js
CHANGED
|
@@ -76,6 +76,9 @@ export async function serve(config, factory) {
|
|
|
76
76
|
case "input":
|
|
77
77
|
host.submit(string(request.input_id), string(request.text));
|
|
78
78
|
break;
|
|
79
|
+
case "steer":
|
|
80
|
+
host.steer(string(request.target_input_id), string(request.input_id), string(request.text));
|
|
81
|
+
break;
|
|
79
82
|
case "interrupt":
|
|
80
83
|
await host.interrupt(string(request.input_id));
|
|
81
84
|
break;
|