@pontia/claude-client 0.7.7 → 0.7.9
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/host.js +29 -0
- package/dist/src/server.js +5 -0
- package/package.json +1 -1
package/dist/src/host.js
CHANGED
|
@@ -27,6 +27,7 @@ export class Host {
|
|
|
27
27
|
closing = false;
|
|
28
28
|
closed = false;
|
|
29
29
|
usedInputs = new Set();
|
|
30
|
+
changingModel = false;
|
|
30
31
|
constructor(options, emit, createQuery = query) {
|
|
31
32
|
this.options = options;
|
|
32
33
|
this.emit = emit;
|
|
@@ -101,6 +102,33 @@ export class Host {
|
|
|
101
102
|
}
|
|
102
103
|
}
|
|
103
104
|
}
|
|
105
|
+
async listModels() {
|
|
106
|
+
if (!this.acceptsControl() || !this.execution || !this.native)
|
|
107
|
+
throw new ControlError("rejected", "execution_unavailable");
|
|
108
|
+
return (await this.execution.supportedModels()).map((model) => ({
|
|
109
|
+
id: model.value,
|
|
110
|
+
name: model.displayName,
|
|
111
|
+
description: model.description,
|
|
112
|
+
}));
|
|
113
|
+
}
|
|
114
|
+
async setModel(model) {
|
|
115
|
+
if (this.changingModel)
|
|
116
|
+
throw new ControlError("rejected", "model_change_busy");
|
|
117
|
+
this.changingModel = true;
|
|
118
|
+
try {
|
|
119
|
+
if (!(await this.listModels()).some((entry) => entry.id === model))
|
|
120
|
+
throw new ControlError("rejected", "model_unavailable");
|
|
121
|
+
if (!this.acceptsControl())
|
|
122
|
+
throw new ControlError("rejected", "execution_unavailable");
|
|
123
|
+
await this.execution.setModel(model);
|
|
124
|
+
if (!this.acceptsControl())
|
|
125
|
+
throw new ControlError("unknown", "model_change_unconfirmed");
|
|
126
|
+
this.emit({ kind: "model", model });
|
|
127
|
+
}
|
|
128
|
+
finally {
|
|
129
|
+
this.changingModel = false;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
104
132
|
async interrupt(id) {
|
|
105
133
|
if (this.closed ||
|
|
106
134
|
this.closing ||
|
|
@@ -196,6 +224,7 @@ export class Host {
|
|
|
196
224
|
this.native = message.session_id;
|
|
197
225
|
this.emit({ kind: "ready", native_session_id: this.native });
|
|
198
226
|
}
|
|
227
|
+
this.emit({ kind: "model", model: message.model });
|
|
199
228
|
return;
|
|
200
229
|
}
|
|
201
230
|
if (message.type === "system" && message.subtype === "api_retry") {
|
package/dist/src/server.js
CHANGED
|
@@ -68,6 +68,11 @@ export async function serve(config, factory) {
|
|
|
68
68
|
const invoke = async (request) => {
|
|
69
69
|
try {
|
|
70
70
|
switch (request.method) {
|
|
71
|
+
case "list_models":
|
|
72
|
+
return { status: "accepted", models: await host.listModels() };
|
|
73
|
+
case "set_model":
|
|
74
|
+
await host.setModel(string(request.model));
|
|
75
|
+
break;
|
|
71
76
|
case "input":
|
|
72
77
|
host.submit(string(request.input_id), string(request.text));
|
|
73
78
|
break;
|