@deepseek-ai/dsh-subagent 0.2.0-rc.2 → 0.2.1-alpha.2
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 +36 -36
- package/README.md +33 -27
- package/README.zh.md +33 -27
- package/lib/index.js +1436 -1304
- package/lib/typert.host.js +73 -60
- package/lib/typert.remote-client.js +2 -2
- package/lib/types/activation.d.ts +114 -0
- package/lib/types/activation.js +112 -0
- package/lib/types/catalog.d.ts +14 -6
- package/lib/types/catalog.js +34 -30
- package/lib/types/child-agent.d.ts +1 -3
- package/lib/types/child-agent.js +1 -3
- package/lib/types/continuation-messages.d.ts +4 -3
- package/lib/types/continuation-messages.js +13 -5
- package/lib/types/control-types.d.ts +7 -0
- package/lib/types/descriptor.d.ts +7 -46
- package/lib/types/descriptor.js +20 -21
- package/lib/types/index.d.ts +52 -53
- package/lib/types/index.js +75 -95
- package/lib/types/internal.d.ts +1 -1
- package/lib/types/lifecycle.d.ts +28 -58
- package/lib/types/lifecycle.js +9 -74
- package/lib/types/list-children.js +1 -1
- package/lib/types/manager.d.ts +247 -0
- package/lib/types/manager.js +1294 -0
- package/lib/types/out-of-process.d.ts +2 -28
- package/lib/types/out-of-process.js +3 -44
- package/lib/types/projection-types.d.ts +3 -0
- package/lib/types/structured.d.ts +49 -0
- package/lib/types/structured.js +130 -0
- package/lib/types/types.d.ts +57 -81
- package/lib/types/types.js +1 -1
- package/package.json +53 -63
- package/lib/invariant.js +0 -76
- package/lib/types/continuation-activation.d.ts +0 -267
- package/lib/types/continuation-activation.js +0 -700
- package/lib/types/continuation.d.ts +0 -124
- package/lib/types/continuation.js +0 -455
- package/lib/types/inbox.d.ts +0 -43
- package/lib/types/inbox.js +0 -61
- package/lib/types/invariant.d.ts +0 -13
- package/lib/types/invariant.js +0 -91
- package/lib/types/run-settlement.d.ts +0 -17
- package/lib/types/run-settlement.js +0 -70
package/lib/types/inbox.js
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Activation-local admission around one continuable subagent's Agent inbox.
|
|
3
|
-
*
|
|
4
|
-
* @module @deepseek-ai/dsh-subagent/inbox
|
|
5
|
-
*/
|
|
6
|
-
import { SubagentError } from "./error.js";
|
|
7
|
-
/** Delegate Queue and Steer to one live Agent until its Activation starts closing. */
|
|
8
|
-
export class SubagentInbox {
|
|
9
|
-
agent;
|
|
10
|
-
closingPromise;
|
|
11
|
-
/**
|
|
12
|
-
* Wrap one live continuable Agent.
|
|
13
|
-
* @param agent - the Agent whose inbox receives accepted deliveries.
|
|
14
|
-
*/
|
|
15
|
-
constructor(agent) {
|
|
16
|
-
this.agent = agent;
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* Read the Activation's close transaction.
|
|
20
|
-
* @returns the memoized transaction, or `undefined` while delivery remains open.
|
|
21
|
-
*/
|
|
22
|
-
get closing() {
|
|
23
|
-
return this.closingPromise;
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Read whether the underlying Agent still has accepted work to claim.
|
|
27
|
-
* @returns whether either Agent inbox destination is non-empty.
|
|
28
|
-
*/
|
|
29
|
-
get hasPending() {
|
|
30
|
-
return this.agent.inbox.nextTurn.length > 0 || this.agent.inbox.nextStep.length > 0;
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Submit through the Agent only while its Activation remains resident.
|
|
34
|
-
* @param message - the accepted input to submit.
|
|
35
|
-
* @param delivery - whether to queue a distinct turn or steer the nearest step.
|
|
36
|
-
*/
|
|
37
|
-
deliver(message, delivery) {
|
|
38
|
-
if (this.closingPromise !== undefined) {
|
|
39
|
-
throw new SubagentError(`subagent "${this.agent.id}" activation is being disposed; the message was not accepted`, 'ACTIVATION_CLOSING');
|
|
40
|
-
}
|
|
41
|
-
if (delivery === 'steer')
|
|
42
|
-
this.agent.steer(message);
|
|
43
|
-
else
|
|
44
|
-
this.agent.followup(message);
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* Close delivery synchronously and share one asynchronous release.
|
|
48
|
-
* @param release - the one release operation to start after closing admission.
|
|
49
|
-
* @returns the memoized release transaction.
|
|
50
|
-
*/
|
|
51
|
-
close(release) {
|
|
52
|
-
const existing = this.closingPromise;
|
|
53
|
-
if (existing !== undefined)
|
|
54
|
-
return existing;
|
|
55
|
-
const completion = Promise.withResolvers();
|
|
56
|
-
this.closingPromise = completion.promise;
|
|
57
|
-
void release().then(completion.resolve, completion.reject);
|
|
58
|
-
return completion.promise;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
//# sourceMappingURL=inbox.js.map
|
package/lib/types/invariant.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/** Package-owned subagent registry and lifecycle invariants. @module @deepseek-ai/dsh-subagent/invariant */
|
|
2
|
-
import type { Context } from '@deepseek-ai/cordis';
|
|
3
|
-
/** Cordis companion plugin name. */
|
|
4
|
-
export declare const name = "subagent-invariant";
|
|
5
|
-
/** Service required before the companion can reserve package ownership. */
|
|
6
|
-
export declare const inject: string[];
|
|
7
|
-
/**
|
|
8
|
-
* Register the subagent invariant companion.
|
|
9
|
-
* @param ctx - Cordis context carrying the invariant service.
|
|
10
|
-
* @returns the installed registration's disposer after setup succeeds.
|
|
11
|
-
*/
|
|
12
|
-
export declare const apply: (ctx: Context) => Promise<() => void>;
|
|
13
|
-
//# sourceMappingURL=invariant.d.ts.map
|
package/lib/types/invariant.js
DELETED
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
/** Package-owned subagent registry and lifecycle invariants. @module @deepseek-ai/dsh-subagent/invariant */
|
|
2
|
-
const PACKAGE_NAME = '@deepseek-ai/dsh-subagent';
|
|
3
|
-
/** Cordis companion plugin name. */
|
|
4
|
-
export const name = 'subagent-invariant';
|
|
5
|
-
/** Service required before the companion can reserve package ownership. */
|
|
6
|
-
export const inject = ['invariants'];
|
|
7
|
-
/** Assert that a terminal lifecycle payload matches its start identity. */
|
|
8
|
-
function validateRunEnd(start, end, fail) {
|
|
9
|
-
if (start.provider !== end.provider || start.id !== end.id || start.local !== end.local) {
|
|
10
|
-
fail(`subagent/end identity diverges from subagent/start for run ${JSON.stringify(end.runId)}`);
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
/** Install provider-registry and start/end pairing checks. */
|
|
14
|
-
const install = Object.assign((ctx, fail) => {
|
|
15
|
-
const providers = new Set(ctx.subagents.list());
|
|
16
|
-
const runs = new Map();
|
|
17
|
-
const stagedProviders = new WeakSet();
|
|
18
|
-
const stagedRemovals = new Set();
|
|
19
|
-
const stagedStarts = new WeakSet();
|
|
20
|
-
const stagedEnds = new WeakSet();
|
|
21
|
-
ctx.on('internal/dispatch', (_mode, eventName, args) => {
|
|
22
|
-
if (eventName === 'subagent/provider-added') {
|
|
23
|
-
const provider = args[0];
|
|
24
|
-
if (provider.name.length === 0)
|
|
25
|
-
fail('subagent provider names must be non-empty');
|
|
26
|
-
if (providers.has(provider.name))
|
|
27
|
-
fail(`subagent/provider-added repeated ${JSON.stringify(provider.name)}`);
|
|
28
|
-
stagedProviders.add(provider);
|
|
29
|
-
return;
|
|
30
|
-
}
|
|
31
|
-
if (eventName === 'subagent/provider-removed') {
|
|
32
|
-
const providerName = args[0];
|
|
33
|
-
if (!providers.has(providerName))
|
|
34
|
-
fail(`subagent/provider-removed names unknown provider ${JSON.stringify(providerName)}`);
|
|
35
|
-
stagedRemovals.add(providerName);
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
if (eventName === 'subagent/start') {
|
|
39
|
-
const info = args[0];
|
|
40
|
-
// Provider availability is an admission-time relationship. A published
|
|
41
|
-
// one-shot run may outlive provider removal, and a cold-resumed Activation
|
|
42
|
-
// records the initial provider name without dispatching through it.
|
|
43
|
-
if (info.provider.length === 0 || String(info.runId).length === 0 || String(info.id).length === 0) {
|
|
44
|
-
fail('subagent/start provider, runId, and child id must be non-empty');
|
|
45
|
-
}
|
|
46
|
-
if (runs.has(info.runId))
|
|
47
|
-
fail(`subagent/start repeated run id ${JSON.stringify(info.runId)}`);
|
|
48
|
-
stagedStarts.add(info);
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
|
-
if (eventName !== 'subagent/end')
|
|
52
|
-
return;
|
|
53
|
-
const info = args[0];
|
|
54
|
-
const start = runs.get(info.runId);
|
|
55
|
-
if (start === undefined)
|
|
56
|
-
fail(`subagent/end has no matching subagent/start for run ${JSON.stringify(info.runId)}`);
|
|
57
|
-
validateRunEnd(start, info, fail);
|
|
58
|
-
stagedEnds.add(info);
|
|
59
|
-
}, { global: true });
|
|
60
|
-
ctx.on('subagent/provider-added', (provider) => {
|
|
61
|
-
/* v8 ignore next -- internal/dispatch stages the same provider object */
|
|
62
|
-
if (!stagedProviders.delete(provider))
|
|
63
|
-
return;
|
|
64
|
-
providers.add(provider.name);
|
|
65
|
-
}, { global: true });
|
|
66
|
-
ctx.on('subagent/provider-removed', (providerName) => {
|
|
67
|
-
/* v8 ignore next -- internal/dispatch stages the same provider name */
|
|
68
|
-
if (!stagedRemovals.delete(providerName))
|
|
69
|
-
return;
|
|
70
|
-
providers.delete(providerName);
|
|
71
|
-
}, { global: true });
|
|
72
|
-
ctx.on('subagent/start', (info) => {
|
|
73
|
-
/* v8 ignore next -- internal/dispatch stages the same lifecycle object */
|
|
74
|
-
if (!stagedStarts.delete(info))
|
|
75
|
-
return;
|
|
76
|
-
runs.set(info.runId, info);
|
|
77
|
-
}, { global: true });
|
|
78
|
-
ctx.on('subagent/end', (info) => {
|
|
79
|
-
/* v8 ignore next -- internal/dispatch stages the same lifecycle object */
|
|
80
|
-
if (!stagedEnds.delete(info))
|
|
81
|
-
return;
|
|
82
|
-
runs.delete(info.runId);
|
|
83
|
-
}, { global: true });
|
|
84
|
-
}, { inject: ['subagents'] });
|
|
85
|
-
/**
|
|
86
|
-
* Register the subagent invariant companion.
|
|
87
|
-
* @param ctx - Cordis context carrying the invariant service.
|
|
88
|
-
* @returns the installed registration's disposer after setup succeeds.
|
|
89
|
-
*/
|
|
90
|
-
export const apply = (ctx) => Promise.resolve(ctx.invariants.register(PACKAGE_NAME, install));
|
|
91
|
-
//# sourceMappingURL=invariant.js.map
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Settlement of one ONE-SHOT subagent run into a background-Task outcome. Only
|
|
3
|
-
* the one-shot background path uses Jobs; continuable children have no Task,
|
|
4
|
-
* no per-message result, and no Task cancellation.
|
|
5
|
-
*
|
|
6
|
-
* @module @deepseek-ai/dsh-subagent/run-settlement
|
|
7
|
-
*/
|
|
8
|
-
import type { JobOutcome } from '@deepseek-ai/dsh-jobs';
|
|
9
|
-
import type { SubagentRun } from './types.ts';
|
|
10
|
-
/**
|
|
11
|
-
* Await the child result, dispose the run, then return its task outcome. Result
|
|
12
|
-
* and disposal failures become `failed`; when both fail, both details survive.
|
|
13
|
-
* @param run - live run to settle and release.
|
|
14
|
-
* @returns outcome after child resources are released.
|
|
15
|
-
*/
|
|
16
|
-
export declare function settleRun(run: SubagentRun): Promise<JobOutcome>;
|
|
17
|
-
//# sourceMappingURL=run-settlement.d.ts.map
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Settlement of one ONE-SHOT subagent run into a background-Task outcome. Only
|
|
3
|
-
* the one-shot background path uses Jobs; continuable children have no Task,
|
|
4
|
-
* no per-message result, and no Task cancellation.
|
|
5
|
-
*
|
|
6
|
-
* @module @deepseek-ai/dsh-subagent/run-settlement
|
|
7
|
-
*/
|
|
8
|
-
/** Flatten a child's final output blocks to the task's final text. */
|
|
9
|
-
function finalText(blocks) {
|
|
10
|
-
return blocks
|
|
11
|
-
.filter((block) => block.type === 'text')
|
|
12
|
-
.map(block => block.text)
|
|
13
|
-
.join('');
|
|
14
|
-
}
|
|
15
|
-
/** Render a failed stop reason with optional provider-authored detail. */
|
|
16
|
-
function failureDetail(result) {
|
|
17
|
-
const stopReason = result.stopReason;
|
|
18
|
-
return result.diagnostic === undefined
|
|
19
|
-
? stopReason
|
|
20
|
-
: `${stopReason}; diagnostic: ${result.diagnostic}`;
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Map a child result to the task outcome: completed carries final text, local
|
|
24
|
-
* cancellation (`aborted` without a diagnostic) is killed, and provider-
|
|
25
|
-
* diagnosed remote aborts plus every other reason are failed without partial
|
|
26
|
-
* output.
|
|
27
|
-
* @param result - child terminal result.
|
|
28
|
-
* @returns outcome for the `ctx.jobs` registration.
|
|
29
|
-
*/
|
|
30
|
-
function runOutcome(result) {
|
|
31
|
-
switch (result.stopReason) {
|
|
32
|
-
case 'completed':
|
|
33
|
-
return { status: 'completed', result: finalText(result.output) };
|
|
34
|
-
case 'aborted':
|
|
35
|
-
return result.diagnostic === undefined
|
|
36
|
-
? { status: 'killed' }
|
|
37
|
-
: { status: 'failed', detail: failureDetail(result) };
|
|
38
|
-
case 'error':
|
|
39
|
-
case 'max-tokens':
|
|
40
|
-
case 'refusal':
|
|
41
|
-
return { status: 'failed', detail: failureDetail(result) };
|
|
42
|
-
// Merge-extensible reasons remain failures with provider-authored detail.
|
|
43
|
-
default:
|
|
44
|
-
return { status: 'failed', detail: failureDetail(result) };
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* Await the child result, dispose the run, then return its task outcome. Result
|
|
49
|
-
* and disposal failures become `failed`; when both fail, both details survive.
|
|
50
|
-
* @param run - live run to settle and release.
|
|
51
|
-
* @returns outcome after child resources are released.
|
|
52
|
-
*/
|
|
53
|
-
export async function settleRun(run) {
|
|
54
|
-
let outcome;
|
|
55
|
-
try {
|
|
56
|
-
outcome = runOutcome(await run.result);
|
|
57
|
-
}
|
|
58
|
-
catch (error) {
|
|
59
|
-
outcome = { status: 'failed', detail: String(error) };
|
|
60
|
-
}
|
|
61
|
-
try {
|
|
62
|
-
await run.dispose();
|
|
63
|
-
}
|
|
64
|
-
catch (error) {
|
|
65
|
-
const prefix = outcome.detail === undefined ? '' : `${outcome.detail}; `;
|
|
66
|
-
return { status: 'failed', detail: `${prefix}dispose failed: ${String(error)}` };
|
|
67
|
-
}
|
|
68
|
-
return outcome;
|
|
69
|
-
}
|
|
70
|
-
//# sourceMappingURL=run-settlement.js.map
|