modality-ai 0.2.1 → 0.3.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/dist/index.js
CHANGED
|
@@ -125288,6 +125288,23 @@ class ModalityClientImpl {
|
|
|
125288
125288
|
return "unknown-transport";
|
|
125289
125289
|
}
|
|
125290
125290
|
}
|
|
125291
|
+
async closeTransportAndKillProcess(transport) {
|
|
125292
|
+
await transport.close();
|
|
125293
|
+
if (this.transportConfig.type === "stdio") {
|
|
125294
|
+
const stdioBased = transport;
|
|
125295
|
+
const pid2 = stdioBased.pid;
|
|
125296
|
+
if (pid2) {
|
|
125297
|
+
try {
|
|
125298
|
+
process.kill(pid2, "SIGTERM");
|
|
125299
|
+
await new Promise((resolve2) => setTimeout(resolve2, 50));
|
|
125300
|
+
try {
|
|
125301
|
+
process.kill(pid2, 0);
|
|
125302
|
+
process.kill(pid2, "SIGKILL");
|
|
125303
|
+
} catch {}
|
|
125304
|
+
} catch {}
|
|
125305
|
+
}
|
|
125306
|
+
}
|
|
125307
|
+
}
|
|
125291
125308
|
async call(method, params, autoParse = true) {
|
|
125292
125309
|
try {
|
|
125293
125310
|
const client = this.client;
|
|
@@ -125318,6 +125335,37 @@ class ModalityClientImpl {
|
|
|
125318
125335
|
this.client.close();
|
|
125319
125336
|
return result;
|
|
125320
125337
|
}
|
|
125338
|
+
async callOnceAndKill(method, params, autoParse = true) {
|
|
125339
|
+
let transport = null;
|
|
125340
|
+
try {
|
|
125341
|
+
const client = this.client;
|
|
125342
|
+
transport = this.createTransport();
|
|
125343
|
+
await client.connect(transport);
|
|
125344
|
+
const result = await client.callTool({
|
|
125345
|
+
name: method,
|
|
125346
|
+
arguments: params
|
|
125347
|
+
}, undefined, { timeout: this.timeout });
|
|
125348
|
+
await this.closeTransportAndKillProcess(transport);
|
|
125349
|
+
client.close();
|
|
125350
|
+
if (autoParse) {
|
|
125351
|
+
return this.parseContent(result);
|
|
125352
|
+
} else {
|
|
125353
|
+
return result;
|
|
125354
|
+
}
|
|
125355
|
+
} catch (error48) {
|
|
125356
|
+
if (transport) {
|
|
125357
|
+
try {
|
|
125358
|
+
await this.closeTransportAndKillProcess(transport);
|
|
125359
|
+
} catch (closeError) {}
|
|
125360
|
+
}
|
|
125361
|
+
try {
|
|
125362
|
+
this.client.close();
|
|
125363
|
+
} catch {}
|
|
125364
|
+
const transportId = this.getTransportIdentifier();
|
|
125365
|
+
logger6.error(`${transportId}-callOnceAndKill-failed`, error48);
|
|
125366
|
+
throw error48;
|
|
125367
|
+
}
|
|
125368
|
+
}
|
|
125321
125369
|
callStream(method, params, callback) {
|
|
125322
125370
|
try {
|
|
125323
125371
|
const client = this.client;
|
|
@@ -126643,17 +126691,23 @@ var createStdioToHttpClient = (options) => {
|
|
|
126643
126691
|
args: optionArgs = [],
|
|
126644
126692
|
env: optionEnv,
|
|
126645
126693
|
pkg,
|
|
126646
|
-
timeout: timeout6 = 120000
|
|
126694
|
+
timeout: timeout6 = 120000,
|
|
126695
|
+
quiet = false
|
|
126647
126696
|
} = options || {};
|
|
126648
126697
|
const args2 = pkg ? [pkg, ...optionArgs] : optionArgs;
|
|
126649
126698
|
const env = {
|
|
126650
126699
|
...Object.fromEntries(Object.entries(process.env).filter((entry) => entry[1] !== undefined)),
|
|
126651
126700
|
...optionEnv || {}
|
|
126652
126701
|
};
|
|
126702
|
+
if (quiet) {
|
|
126703
|
+
env.QUIET = "true";
|
|
126704
|
+
env.DEBUG = "";
|
|
126705
|
+
}
|
|
126653
126706
|
const client = ModalityClient.stdio({
|
|
126654
126707
|
command,
|
|
126655
126708
|
args: args2,
|
|
126656
|
-
env
|
|
126709
|
+
env,
|
|
126710
|
+
stderr: quiet ? "ignore" : "inherit"
|
|
126657
126711
|
}, timeout6);
|
|
126658
126712
|
return client;
|
|
126659
126713
|
};
|
|
@@ -25,8 +25,18 @@ declare class ModalityClientImpl {
|
|
|
25
25
|
constructor(config: TransportConfig, timeout?: number);
|
|
26
26
|
private createTransport;
|
|
27
27
|
private getTransportIdentifier;
|
|
28
|
+
/**
|
|
29
|
+
* Close transport and kill subprocess (for stdio transports only)
|
|
30
|
+
* Useful for one-off CLI operations where the subprocess should not persist
|
|
31
|
+
*/
|
|
32
|
+
private closeTransportAndKillProcess;
|
|
28
33
|
call(method: string, params?: any, autoParse?: boolean): Promise<any>;
|
|
29
34
|
callOnce(method: string, params?: any, autoParse?: boolean): Promise<any>;
|
|
35
|
+
/**
|
|
36
|
+
* Call a tool once and kill the subprocess (for stdio transports only)
|
|
37
|
+
* Useful for one-off CLI operations where the subprocess should not persist
|
|
38
|
+
*/
|
|
39
|
+
callOnceAndKill(method: string, params?: any, autoParse?: boolean): Promise<any>;
|
|
30
40
|
callStream(method: string, params?: any, callback?: (p: any) => void): ReadableStream;
|
|
31
41
|
close(): void;
|
|
32
42
|
listTools(): Promise<ListToolsResult>;
|
package/package.json
CHANGED