@qilin-agent/tools 3.1.5 → 3.1.7
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/README.i18n.yaml +2 -2
- package/README.md +1 -1
- package/README.zh.md +1 -1
- package/lib/index.js +373 -275
- package/lib/types/index.d.ts +2 -1
- package/lib/types/index.js +5 -3
- package/lib/types/presentation.d.ts +3 -3
- package/lib/types/ptc-calls.d.ts +24 -0
- package/lib/types/ptc-calls.js +62 -0
- package/lib/types/ptc.d.ts +5 -3
- package/lib/types/ptc.js +363 -342
- package/lib/types/py-types.d.ts +1 -1
- package/lib/types/py-types.js +3 -3
- package/lib/types/ts-types.d.ts +2 -1
- package/lib/types/ts-types.js +26 -9
- package/locale/en.json +5 -0
- package/locale/zh.json +6 -0
- package/package.json +30 -28
package/lib/types/index.d.ts
CHANGED
|
@@ -539,9 +539,10 @@ export declare class ToolRuntime extends Service {
|
|
|
539
539
|
* Reserved presentation transport, kept outside the filterable registration
|
|
540
540
|
* layers. Built on first need rather than at construction: which agents run
|
|
541
541
|
* a PTC mode is no longer known when the service is constructed, and the
|
|
542
|
-
* transport
|
|
542
|
+
* transport owns its PTC call tracking and state-owner registrations.
|
|
543
543
|
*/
|
|
544
544
|
private ptcTransport;
|
|
545
|
+
private readonly ptcContext;
|
|
545
546
|
constructor(ctx: Context, config?: Config);
|
|
546
547
|
/**
|
|
547
548
|
* The prompt statement of the `ptc` executor collapse, registered wherever
|
package/lib/types/index.js
CHANGED
|
@@ -248,11 +248,13 @@ export class ToolRuntime extends Service {
|
|
|
248
248
|
* Reserved presentation transport, kept outside the filterable registration
|
|
249
249
|
* layers. Built on first need rather than at construction: which agents run
|
|
250
250
|
* a PTC mode is no longer known when the service is constructed, and the
|
|
251
|
-
* transport
|
|
251
|
+
* transport owns its PTC call tracking and state-owner registrations.
|
|
252
252
|
*/
|
|
253
253
|
ptcTransport;
|
|
254
|
+
ptcContext;
|
|
254
255
|
constructor(ctx, config = {}) {
|
|
255
256
|
super(ctx, 'tools');
|
|
257
|
+
this.ptcContext = ctx;
|
|
256
258
|
// The schema already defaulted an omitted mode; the ?? narrows the
|
|
257
259
|
// optional-input type for direct (non-Loader) construction in tests.
|
|
258
260
|
this.defaultMode = config.mode ?? 'native';
|
|
@@ -314,7 +316,7 @@ export class ToolRuntime extends Service {
|
|
|
314
316
|
/* v8 ignore next -- requirePtcRuntime rejects an unknown language before this runs. */
|
|
315
317
|
if (render === undefined)
|
|
316
318
|
throw new Error(`qilin-tools: no SDK renderer for ${runtime.language}`);
|
|
317
|
-
return render(this.sdkSchemas(context.scope));
|
|
319
|
+
return render(this.sdkSchemas(context.scope), runtime.programFormat);
|
|
318
320
|
},
|
|
319
321
|
};
|
|
320
322
|
}
|
|
@@ -372,7 +374,7 @@ export class ToolRuntime extends Service {
|
|
|
372
374
|
peekRuntime: () => this.ctx.get('ptcRuntime'),
|
|
373
375
|
maxParallel: this.maxParallelSubCalls,
|
|
374
376
|
shapeDispatchLog: dispatch => this.shapeDispatchLog(dispatch),
|
|
375
|
-
});
|
|
377
|
+
}, this.ptcContext);
|
|
376
378
|
return this.ptcTransport;
|
|
377
379
|
}
|
|
378
380
|
/**
|
|
@@ -155,10 +155,10 @@ export interface TerminalResultView {
|
|
|
155
155
|
/** Captured command output (stdout+stderr as the tool chooses to combine them). */
|
|
156
156
|
output?: string;
|
|
157
157
|
/**
|
|
158
|
-
* Process exit code, when the run ended
|
|
159
|
-
*
|
|
158
|
+
* Process exit code, or null when the run ended without a code or signal.
|
|
159
|
+
* Omit when killed by a signal or when the result carries no exit status.
|
|
160
160
|
*/
|
|
161
|
-
exitCode?: number;
|
|
161
|
+
exitCode?: number | null;
|
|
162
162
|
/** Signal name that killed the process (e.g. `SIGTERM`). Mutually exclusive with `exitCode`. */
|
|
163
163
|
signal?: string;
|
|
164
164
|
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/** Cancellation and settlement of complete PTC calls, including nested tools. */
|
|
2
|
+
import type { Context } from '@qilin-agent/kylin';
|
|
3
|
+
import type { SessionId } from '@qilin-agent/session';
|
|
4
|
+
import type { SandboxMode } from '@qilin-agent/sandbox';
|
|
5
|
+
/** Keeps calls under a changed policy from overlapping their canceled predecessors. */
|
|
6
|
+
export declare class PtcCalls {
|
|
7
|
+
private readonly calls;
|
|
8
|
+
private disposed;
|
|
9
|
+
/**
|
|
10
|
+
* Observe policy changes for the owning tool registry.
|
|
11
|
+
* @param ctx - Registry lifecycle and Session events.
|
|
12
|
+
*/
|
|
13
|
+
constructor(ctx: Context);
|
|
14
|
+
/**
|
|
15
|
+
* Await canceled predecessors before resolving authority and admitting a call.
|
|
16
|
+
* @param sessionId - Calling Session.
|
|
17
|
+
* @param signal - Caller cancellation.
|
|
18
|
+
* @param mode - Current standing mode, read after preceding cleanup.
|
|
19
|
+
* @param run - Complete call, including nested-tool cleanup.
|
|
20
|
+
* @returns The call result.
|
|
21
|
+
*/
|
|
22
|
+
run<T>(sessionId: SessionId, signal: AbortSignal, mode: () => SandboxMode, run: (signal: AbortSignal) => Promise<T>): Promise<T>;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=ptc-calls.d.ts.map
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/** Keeps calls under a changed policy from overlapping their canceled predecessors. */
|
|
2
|
+
export class PtcCalls {
|
|
3
|
+
calls = new Map();
|
|
4
|
+
disposed = false;
|
|
5
|
+
/**
|
|
6
|
+
* Observe policy changes for the owning tool registry.
|
|
7
|
+
* @param ctx - Registry lifecycle and Session events.
|
|
8
|
+
*/
|
|
9
|
+
constructor(ctx) {
|
|
10
|
+
ctx.on('session/event', (session, event) => {
|
|
11
|
+
if (event.type !== 'sandbox/mode')
|
|
12
|
+
return;
|
|
13
|
+
for (const call of this.calls.get(session.id) ?? []) {
|
|
14
|
+
if (call.mode !== event.data.mode)
|
|
15
|
+
call.controller.abort(new Error('sandbox mode changed'));
|
|
16
|
+
}
|
|
17
|
+
}, { global: true });
|
|
18
|
+
ctx.effect(() => async () => {
|
|
19
|
+
this.disposed = true;
|
|
20
|
+
const calls = [...this.calls.values()].flatMap(calls => [...calls]);
|
|
21
|
+
for (const call of calls)
|
|
22
|
+
call.controller.abort(new Error('PTC tool registry disposed'));
|
|
23
|
+
await Promise.all(calls.map(call => call.done));
|
|
24
|
+
}, 'PTC calls');
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Await canceled predecessors before resolving authority and admitting a call.
|
|
28
|
+
* @param sessionId - Calling Session.
|
|
29
|
+
* @param signal - Caller cancellation.
|
|
30
|
+
* @param mode - Current standing mode, read after preceding cleanup.
|
|
31
|
+
* @param run - Complete call, including nested-tool cleanup.
|
|
32
|
+
* @returns The call result.
|
|
33
|
+
*/
|
|
34
|
+
async run(sessionId, signal, mode, run) {
|
|
35
|
+
for (;;) {
|
|
36
|
+
const pending = [...this.calls.get(sessionId) ?? []].filter(call => call.controller.signal.aborted);
|
|
37
|
+
if (pending.length === 0)
|
|
38
|
+
break;
|
|
39
|
+
await Promise.all(pending.map(call => call.done));
|
|
40
|
+
}
|
|
41
|
+
signal.throwIfAborted();
|
|
42
|
+
if (this.disposed)
|
|
43
|
+
throw new Error('PTC tool registry disposed');
|
|
44
|
+
const controller = new AbortController();
|
|
45
|
+
const done = Promise.withResolvers();
|
|
46
|
+
const call = { mode: mode(), controller, done: done.promise };
|
|
47
|
+
let calls = this.calls.get(sessionId);
|
|
48
|
+
if (calls === undefined)
|
|
49
|
+
this.calls.set(sessionId, calls = new Set());
|
|
50
|
+
calls.add(call);
|
|
51
|
+
try {
|
|
52
|
+
return await run(AbortSignal.any([signal, controller.signal]));
|
|
53
|
+
}
|
|
54
|
+
finally {
|
|
55
|
+
calls.delete(call);
|
|
56
|
+
if (calls.size === 0)
|
|
57
|
+
this.calls.delete(sessionId);
|
|
58
|
+
done.resolve(undefined);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=ptc-calls.js.map
|
package/lib/types/ptc.d.ts
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* outer curated result enters model history.
|
|
6
6
|
* @module @qilin-agent/tools/src/ptc
|
|
7
7
|
*/
|
|
8
|
+
import { type Context } from '@qilin-agent/kylin';
|
|
8
9
|
import { HarnessError } from '@qilin-agent/llm';
|
|
9
10
|
declare module '@qilin-agent/llm' {
|
|
10
11
|
interface MessageSourceMap {
|
|
@@ -68,15 +69,16 @@ export interface RunCodeBridgeOptions {
|
|
|
68
69
|
shapeDispatchLog: (dispatch: PtcDispatchLog) => Promise<ContentBlock[]>;
|
|
69
70
|
}
|
|
70
71
|
/**
|
|
71
|
-
* Build the `run_code` {@link ToolDefinition}: required `
|
|
72
|
-
* `
|
|
72
|
+
* Build the `run_code` {@link ToolDefinition}: required `code` and
|
|
73
|
+
* `description` parameters, executed through the dispatch bridge described
|
|
73
74
|
* above. The
|
|
74
75
|
* registry reserves it as presentation infrastructure under non-native modes,
|
|
75
76
|
* outside the filterable global/scoped capability layers.
|
|
76
77
|
* @param registry - the owning registry (sub-calls go through its `execute`,
|
|
77
78
|
* bindings cover its registered tools).
|
|
78
79
|
* @param options - the registry-private capabilities described above.
|
|
80
|
+
* @param ctx - Owning registry context, independent of the calling Agent.
|
|
79
81
|
* @returns the registry-ready definition.
|
|
80
82
|
*/
|
|
81
|
-
export declare function createRunCodeTool(registry: ToolRuntime, options: RunCodeBridgeOptions): ToolDefinition;
|
|
83
|
+
export declare function createRunCodeTool(registry: ToolRuntime, options: RunCodeBridgeOptions, ctx: Context): ToolDefinition;
|
|
82
84
|
//# sourceMappingURL=ptc.d.ts.map
|