@fishwithcat/dsh-subagent 0.0.0-stage → 0.2.2-alpha.3
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 +121 -0
- package/README.md +258 -2
- package/README.zh.md +259 -0
- package/lib/index.js +3065 -0
- package/lib/typert.host.d.ts +3 -0
- package/lib/typert.host.js +1086 -0
- package/lib/typert.remote-client.d.ts +29 -0
- package/lib/typert.remote-client.js +122 -0
- package/lib/types/activation.d.ts +110 -0
- package/lib/types/activation.js +112 -0
- package/lib/types/archive-admission.d.ts +23 -0
- package/lib/types/archive-admission.js +75 -0
- package/lib/types/assistant-output.d.ts +48 -0
- package/lib/types/assistant-output.js +73 -0
- package/lib/types/catalog.d.ts +87 -0
- package/lib/types/catalog.js +113 -0
- package/lib/types/child-agent.d.ts +145 -0
- package/lib/types/child-agent.js +229 -0
- package/lib/types/client.d.ts +8 -0
- package/lib/types/client.js +7 -0
- package/lib/types/continuation-messages.d.ts +66 -0
- package/lib/types/continuation-messages.js +116 -0
- package/lib/types/control-types.d.ts +121 -0
- package/lib/types/control-types.js +8 -0
- package/lib/types/control.d.ts +41 -0
- package/lib/types/control.js +75 -0
- package/lib/types/depth.d.ts +31 -0
- package/lib/types/depth.js +39 -0
- package/lib/types/descriptor.d.ts +105 -0
- package/lib/types/descriptor.js +192 -0
- package/lib/types/error.d.ts +11 -0
- package/lib/types/error.js +14 -0
- package/lib/types/index.d.ts +282 -0
- package/lib/types/index.js +398 -0
- package/lib/types/lifecycle.d.ts +54 -0
- package/lib/types/lifecycle.js +89 -0
- package/lib/types/list-children.d.ts +36 -0
- package/lib/types/list-children.js +166 -0
- package/lib/types/manager.d.ts +215 -0
- package/lib/types/manager.js +1171 -0
- package/lib/types/out-of-process.d.ts +92 -0
- package/lib/types/out-of-process.js +177 -0
- package/lib/types/projection-types.d.ts +93 -0
- package/lib/types/projection-types.js +7 -0
- package/lib/types/projection.d.ts +94 -0
- package/lib/types/projection.js +157 -0
- package/lib/types/structured.d.ts +49 -0
- package/lib/types/structured.js +130 -0
- package/lib/types/types.d.ts +331 -0
- package/lib/types/types.js +17 -0
- package/locale/de.json +6 -0
- package/locale/en.json +5 -0
- package/locale/es.json +6 -0
- package/locale/fr.json +6 -0
- package/locale/ja.json +6 -0
- package/locale/pt.json +6 -0
- package/locale/ru.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +131 -4
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Model-visible messages owned by continuable-subagent orchestration.
|
|
3
|
+
*
|
|
4
|
+
* @module @deepseek-ai/dsh-subagent/continuation-messages
|
|
5
|
+
*/
|
|
6
|
+
import { boundContextSummary, createUserMessage } from '@deepseek-ai/dsh-llm';
|
|
7
|
+
/** Build durable attribution for one Agent message. */
|
|
8
|
+
function agentMessageSource(sender) {
|
|
9
|
+
return {
|
|
10
|
+
kind: 'agent-message',
|
|
11
|
+
form: 'relay',
|
|
12
|
+
senderSessionId: sender.id,
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Build the model-visible and durable representation of one Agent message.
|
|
17
|
+
* @param sender - exact live Agent that authored the message.
|
|
18
|
+
* @param content - model-visible message blocks supplied by the sender.
|
|
19
|
+
* @returns the durable user-message representation delivered to the recipient.
|
|
20
|
+
*/
|
|
21
|
+
export function createAgentMessage(sender, content) {
|
|
22
|
+
return createUserMessage({
|
|
23
|
+
content: [
|
|
24
|
+
{ type: 'text', text: `Agent ${sender.id} sent a message: ` },
|
|
25
|
+
...content,
|
|
26
|
+
],
|
|
27
|
+
source: agentMessageSource(sender),
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Append automatic result-delivery guidance to a parent-delivered child's initial task.
|
|
32
|
+
* @param prompt - initial model-visible task blocks.
|
|
33
|
+
* @returns task blocks followed by the result-delivery guidance.
|
|
34
|
+
*/
|
|
35
|
+
export function withResultDeliveryGuidance(prompt) {
|
|
36
|
+
return [
|
|
37
|
+
...prompt,
|
|
38
|
+
{
|
|
39
|
+
type: 'text',
|
|
40
|
+
text: 'Your final answer is delivered automatically if your '
|
|
41
|
+
+ 'parent is still online. Include the result and relevant evidence in that answer; the parent does not '
|
|
42
|
+
+ 'receive your full transcript, tool output, or reasoning. If your last action is a message to your '
|
|
43
|
+
+ 'parent, the completion notice omits your final answer; include the result and relevant evidence in that message.',
|
|
44
|
+
},
|
|
45
|
+
];
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* One line telling a parent that a background child is finished and why, in
|
|
49
|
+
* the parent's own task vocabulary.
|
|
50
|
+
* @param childId - the durable child the parent knows by id.
|
|
51
|
+
* @param stopReason - how the child's last ordinary turn ended.
|
|
52
|
+
* @param continuable - whether the child accepts a later message.
|
|
53
|
+
* @returns the model-facing opening line of the settlement notice.
|
|
54
|
+
*/
|
|
55
|
+
function settlementSummary(childId, stopReason, continuable) {
|
|
56
|
+
const subject = `Background subagent ${childId}`;
|
|
57
|
+
switch (stopReason) {
|
|
58
|
+
case 'completed':
|
|
59
|
+
return continuable
|
|
60
|
+
? `${subject} finished and will do no further work unless you send it more.`
|
|
61
|
+
: `${subject} finished. It cannot receive follow-up messages.`;
|
|
62
|
+
case 'aborted':
|
|
63
|
+
return `${subject} was stopped before it finished.`;
|
|
64
|
+
case 'max-tokens':
|
|
65
|
+
return `${subject} ran out of room before it finished.`;
|
|
66
|
+
// A pre-step rejection — a hook deny, a policy plugin — discarded input
|
|
67
|
+
// the child had claimed, so the parent must not treat the task as done.
|
|
68
|
+
case 'refusal':
|
|
69
|
+
return `${subject} declined the task.`;
|
|
70
|
+
case 'error':
|
|
71
|
+
return `${subject} failed before it finished.`;
|
|
72
|
+
/* v8 ignore next 4 -- `SubagentResult['stopReason']` is merge-extensible, so this arm
|
|
73
|
+
* needs a backend that adds a variant; an unnameable ending is reported as unfinished
|
|
74
|
+
* rather than silently as success. */
|
|
75
|
+
default:
|
|
76
|
+
return `${subject} ended abnormally (${String(stopReason)}) before it finished.`;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Build the runtime-owned settlement notice from the child's nonempty closing text.
|
|
81
|
+
* @param childId - durable child session id named in the notice.
|
|
82
|
+
* @param terminal - recorded terminal state for the settled Activation.
|
|
83
|
+
* @param continuable - whether the child can accept another task.
|
|
84
|
+
* @param omitClosingText - replace the closing text when the child's last action
|
|
85
|
+
* was a message to its direct parent.
|
|
86
|
+
* @returns the durable user-message representation delivered to the parent.
|
|
87
|
+
*/
|
|
88
|
+
export function createSettlementMessage(childId, terminal, continuable = true, omitClosingText = false) {
|
|
89
|
+
const summary = settlementSummary(childId, terminal.stopReason, continuable);
|
|
90
|
+
// Parent providers receive this notice as a user message and may reject
|
|
91
|
+
// nontext assistant blocks. Keep this conversion local so SDK/UI consumers
|
|
92
|
+
// retain the complete child output.
|
|
93
|
+
const closingText = terminal.output.flatMap(block => block.type === 'text' && block.text.length > 0 ? [block] : []);
|
|
94
|
+
return createUserMessage({
|
|
95
|
+
content: [
|
|
96
|
+
{ type: 'text', text: summary },
|
|
97
|
+
...omitClosingText
|
|
98
|
+
? [{ type: 'text', text: 'It sent you a message just before finishing, so its closing message is omitted.' }]
|
|
99
|
+
: closingText.length === 0
|
|
100
|
+
? [{ type: 'text', text: 'It left no closing message.' }]
|
|
101
|
+
: [{ type: 'text', text: 'Its closing message:' }, ...closingText],
|
|
102
|
+
...terminal.structured !== undefined
|
|
103
|
+
? [{ type: 'text', text: `Structured result: ${JSON.stringify(terminal.structured)}` }] : [],
|
|
104
|
+
...terminal.diagnostic !== undefined
|
|
105
|
+
? [{ type: 'text', text: terminal.diagnostic }] : [],
|
|
106
|
+
],
|
|
107
|
+
source: {
|
|
108
|
+
kind: 'subagent-settled',
|
|
109
|
+
form: 'notice',
|
|
110
|
+
summary: boundContextSummary(summary),
|
|
111
|
+
stopReason: terminal.stopReason,
|
|
112
|
+
senderSessionId: childId,
|
|
113
|
+
},
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
//# sourceMappingURL=continuation-messages.js.map
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Client-safe recursive catalog rows and browser continuation requests,
|
|
3
|
+
* receipts, and failures.
|
|
4
|
+
*
|
|
5
|
+
* @module @deepseek-ai/dsh-subagent/control-types
|
|
6
|
+
*/
|
|
7
|
+
import type { PromptContentPart } from '@deepseek-ai/dsh-attachment/types';
|
|
8
|
+
import type { Branded } from '@deepseek-ai/dsh-brand';
|
|
9
|
+
import type { MessageId } from '@deepseek-ai/dsh-llm/brand';
|
|
10
|
+
import type { SessionId } from '@deepseek-ai/dsh-session/types';
|
|
11
|
+
import type { KnownSubagentCatalogFields } from './projection-types.ts';
|
|
12
|
+
/**
|
|
13
|
+
* Client-minted identity of one browser prompt, persisted on the exact accepted
|
|
14
|
+
* message. It carries the Session Controller's `session-request-id` brand so a
|
|
15
|
+
* subagent prompt and an ordinary Session prompt share one identity
|
|
16
|
+
* vocabulary; that package depends on this one, so the brand is spelled here
|
|
17
|
+
* rather than imported.
|
|
18
|
+
*/
|
|
19
|
+
export type SubagentPromptRequestId = Branded<'session-request-id'>;
|
|
20
|
+
/** Shared child fields for recursive catalog listing. */
|
|
21
|
+
export type SubagentCatalogRow = {
|
|
22
|
+
/** The durable child session id, stable across Activations. */
|
|
23
|
+
readonly id: SessionId;
|
|
24
|
+
/**
|
|
25
|
+
* Whether recursive catalog listing observed a resident Session. This
|
|
26
|
+
* does not encode a durable outcome or guarantee continuation delivery.
|
|
27
|
+
*/
|
|
28
|
+
readonly activity: 'running' | 'inactive';
|
|
29
|
+
} & KnownSubagentCatalogFields;
|
|
30
|
+
/**
|
|
31
|
+
* One recursive catalog row. Traversal may also return diagnostics for
|
|
32
|
+
* unknown catalog modes or unreadable child catalogs.
|
|
33
|
+
*/
|
|
34
|
+
export type SubagentListEntry = SubagentCatalogRow & {
|
|
35
|
+
readonly kind: 'child';
|
|
36
|
+
/** Whether the child catalog contains a direct child. */
|
|
37
|
+
readonly hasChildren: boolean;
|
|
38
|
+
} | {
|
|
39
|
+
readonly kind: 'diagnostic';
|
|
40
|
+
/** The candidate's session id. */
|
|
41
|
+
readonly id: SessionId;
|
|
42
|
+
/**
|
|
43
|
+
* `corrupt` means the child catalog read found invalid or conflicting
|
|
44
|
+
* Session data; `unavailable` means it could not be read. Either failure
|
|
45
|
+
* stops that branch. `unsupported` means the parent catalog records an
|
|
46
|
+
* unknown child mode; its readable catalog is still traversed.
|
|
47
|
+
*/
|
|
48
|
+
readonly reason: 'corrupt' | 'unsupported' | 'unavailable';
|
|
49
|
+
};
|
|
50
|
+
/** Durable parent/child browsing address; unknown mode is resolved when child history is read. */
|
|
51
|
+
export type SubagentAddress = {
|
|
52
|
+
readonly parentSessionId: SessionId;
|
|
53
|
+
readonly childSessionId: SessionId;
|
|
54
|
+
} & ({
|
|
55
|
+
readonly mode: 'one-shot';
|
|
56
|
+
} | {
|
|
57
|
+
readonly mode: 'continuable';
|
|
58
|
+
} | {
|
|
59
|
+
readonly mode: 'unknown';
|
|
60
|
+
});
|
|
61
|
+
/** One Agent inbox destination for a continuation message. */
|
|
62
|
+
export type SubagentDelivery = 'queue' | 'steer';
|
|
63
|
+
/** One human message addressed to a continuable subagent. */
|
|
64
|
+
export interface SubagentPromptRequest {
|
|
65
|
+
/** Identity persisted on the accepted message, minted before the call. */
|
|
66
|
+
readonly requestId: SubagentPromptRequestId;
|
|
67
|
+
readonly childSessionId: SessionId;
|
|
68
|
+
/** Whether this message queues a later turn or targets the nearest step. */
|
|
69
|
+
readonly delivery: SubagentDelivery;
|
|
70
|
+
/**
|
|
71
|
+
* Browser prompt parts delivered as the child's user message. The Host
|
|
72
|
+
* admits and persists image parts before delivery, so the wire never
|
|
73
|
+
* carries a durable attachment reference the caller could fabricate.
|
|
74
|
+
*/
|
|
75
|
+
readonly content: readonly PromptContentPart[];
|
|
76
|
+
/** Optional browser zone sampled for this exact human prompt. */
|
|
77
|
+
readonly clientTimeZone?: string;
|
|
78
|
+
}
|
|
79
|
+
/** Inbox identity returned once the continuation accepts one human message. */
|
|
80
|
+
export interface SubagentPromptReceipt {
|
|
81
|
+
readonly messageId: MessageId;
|
|
82
|
+
}
|
|
83
|
+
/** Uniform acknowledgement that one interrupt request was admitted. */
|
|
84
|
+
export interface SubagentInterruptReceipt {
|
|
85
|
+
readonly accepted: true;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Failure details the control surface answers with. Prompts and interrupts
|
|
89
|
+
* share these failures with the Client Remote result.
|
|
90
|
+
*/
|
|
91
|
+
declare module '@deepseek-ai/dsh-workspace/types' {
|
|
92
|
+
interface SessionActivityKindMap {
|
|
93
|
+
/** A subagent session delegated from this session (at any depth) is inside a turn. */
|
|
94
|
+
subagent: true;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
declare module '@deepseek-ai/dsh-typert-protocol' {
|
|
98
|
+
interface RemoteErrorDetailsMap {
|
|
99
|
+
/** A browser-supplied zone is neither UTC nor a canonical IANA name. */
|
|
100
|
+
'subagent/invalid-time-zone': {
|
|
101
|
+
readonly value: string;
|
|
102
|
+
};
|
|
103
|
+
/** The addressed child cannot take a continuation. */
|
|
104
|
+
'subagent/not-resumable': {
|
|
105
|
+
readonly childSessionId: SessionId;
|
|
106
|
+
};
|
|
107
|
+
/** The supplied address or live subagent-tree identity could not be verified. */
|
|
108
|
+
'subagent/unauthorized': {
|
|
109
|
+
readonly childSessionId: SessionId;
|
|
110
|
+
};
|
|
111
|
+
/** Image admission or model image-capability refusal. */
|
|
112
|
+
'subagent/attachment-invalid': {
|
|
113
|
+
readonly reason: string;
|
|
114
|
+
};
|
|
115
|
+
/** The child exists but its inbox cannot admit the message now. */
|
|
116
|
+
'subagent/delivery-unavailable': {
|
|
117
|
+
readonly childSessionId: SessionId;
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
//# sourceMappingURL=control-types.d.ts.map
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Browser-facing subagent prompt and interrupt request validation plus the
|
|
3
|
+
* stable prompt failure codes returned by the Remote surface.
|
|
4
|
+
*
|
|
5
|
+
* @module @deepseek-ai/dsh-subagent
|
|
6
|
+
*/
|
|
7
|
+
import type { SessionId } from '@deepseek-ai/dsh-session';
|
|
8
|
+
import { z } from 'zod';
|
|
9
|
+
declare const CONTROL_ID_SCHEMAS: {
|
|
10
|
+
readonly 'subagent.prompt': z.ZodObject<{
|
|
11
|
+
childSessionId: z.ZodString;
|
|
12
|
+
delivery: z.ZodEnum<{
|
|
13
|
+
queue: "queue";
|
|
14
|
+
steer: "steer";
|
|
15
|
+
}>;
|
|
16
|
+
}, z.core.$strip>;
|
|
17
|
+
readonly 'subagent.interrupt': z.ZodObject<{
|
|
18
|
+
childSessionId: z.ZodString;
|
|
19
|
+
}, z.core.$strip>;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Apply the subagent payload checks that are stricter than generated
|
|
23
|
+
* branded-string codecs.
|
|
24
|
+
* @param method - method name carried in the failure message.
|
|
25
|
+
* @param payload - decoded control fields to validate.
|
|
26
|
+
* @throws {RemoteError} `gateway/bad-request` with the original Zod issues.
|
|
27
|
+
*/
|
|
28
|
+
export declare function validateControlRequest(method: keyof typeof CONTROL_ID_SCHEMAS, payload: unknown): void;
|
|
29
|
+
/**
|
|
30
|
+
* Refuse one continuation prompt without exposing provider detail: admission
|
|
31
|
+
* failures the caller can act on keep their own code, everything else is
|
|
32
|
+
* internal.
|
|
33
|
+
* @param error - the thrown value.
|
|
34
|
+
* @param childSessionId - the addressed child.
|
|
35
|
+
* @param signal - the caller's cancellation.
|
|
36
|
+
* @returns Never — the refusal is thrown.
|
|
37
|
+
* @throws {RemoteError} always.
|
|
38
|
+
*/
|
|
39
|
+
export declare function rejectPrompt(error: unknown, childSessionId: SessionId, signal: AbortSignal): never;
|
|
40
|
+
export {};
|
|
41
|
+
//# sourceMappingURL=control.d.ts.map
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Browser-facing subagent prompt and interrupt request validation plus the
|
|
3
|
+
* stable prompt failure codes returned by the Remote surface.
|
|
4
|
+
*
|
|
5
|
+
* @module @deepseek-ai/dsh-subagent
|
|
6
|
+
*/
|
|
7
|
+
import { AttachmentError } from '@deepseek-ai/dsh-attachment';
|
|
8
|
+
import { RemoteError } from '@deepseek-ai/dsh-typert-protocol';
|
|
9
|
+
import { z } from 'zod';
|
|
10
|
+
import { SubagentError } from "./error.js";
|
|
11
|
+
const SESSION_ID_SCHEMA = z.string().min(1);
|
|
12
|
+
const CONTROL_ID_SCHEMAS = {
|
|
13
|
+
'subagent.prompt': z.object({
|
|
14
|
+
childSessionId: SESSION_ID_SCHEMA,
|
|
15
|
+
delivery: z.enum(['queue', 'steer']),
|
|
16
|
+
}),
|
|
17
|
+
'subagent.interrupt': z.object({
|
|
18
|
+
childSessionId: SESSION_ID_SCHEMA,
|
|
19
|
+
}),
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Apply the subagent payload checks that are stricter than generated
|
|
23
|
+
* branded-string codecs.
|
|
24
|
+
* @param method - method name carried in the failure message.
|
|
25
|
+
* @param payload - decoded control fields to validate.
|
|
26
|
+
* @throws {RemoteError} `gateway/bad-request` with the original Zod issues.
|
|
27
|
+
*/
|
|
28
|
+
export function validateControlRequest(method, payload) {
|
|
29
|
+
const parsed = CONTROL_ID_SCHEMAS[method].safeParse(payload);
|
|
30
|
+
if (!parsed.success) {
|
|
31
|
+
throw new RemoteError('gateway/bad-request', `invalid payload for ${method}`, { issues: parsed.error.issues });
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Refuse one continuation prompt without exposing provider detail: admission
|
|
36
|
+
* failures the caller can act on keep their own code, everything else is
|
|
37
|
+
* internal.
|
|
38
|
+
* @param error - the thrown value.
|
|
39
|
+
* @param childSessionId - the addressed child.
|
|
40
|
+
* @param signal - the caller's cancellation.
|
|
41
|
+
* @returns Never — the refusal is thrown.
|
|
42
|
+
* @throws {RemoteError} always.
|
|
43
|
+
*/
|
|
44
|
+
export function rejectPrompt(error, childSessionId, signal) {
|
|
45
|
+
if (isCancellation(error, signal)) {
|
|
46
|
+
throw new RemoteError('gateway/cancelled', 'subagent prompt was cancelled', {}, { cause: error });
|
|
47
|
+
}
|
|
48
|
+
if (error instanceof AttachmentError) {
|
|
49
|
+
throw new RemoteError('subagent/attachment-invalid', error.message, { reason: error.code }, { cause: error });
|
|
50
|
+
}
|
|
51
|
+
if (error instanceof SubagentError) {
|
|
52
|
+
switch (error.code) {
|
|
53
|
+
case 'MODEL_DOES_NOT_SUPPORT_IMAGES':
|
|
54
|
+
throw new RemoteError('subagent/attachment-invalid', error.message, { reason: error.code }, { cause: error });
|
|
55
|
+
case 'NOT_RESUMABLE':
|
|
56
|
+
throw new RemoteError('subagent/not-resumable', 'subagent cannot be resumed', { childSessionId }, { cause: error });
|
|
57
|
+
case 'UNAUTHORIZED':
|
|
58
|
+
throw new RemoteError('subagent/unauthorized', 'subagent membership in the active tree could not be verified', { childSessionId }, { cause: error });
|
|
59
|
+
case 'DRAINING':
|
|
60
|
+
case 'ACTIVATION_CLOSING':
|
|
61
|
+
case 'ACTIVATION_LIMIT_REACHED':
|
|
62
|
+
case 'CONTINUATION_UNAVAILABLE':
|
|
63
|
+
case 'PERSISTENCE_UNAVAILABLE':
|
|
64
|
+
throw new RemoteError('subagent/delivery-unavailable', 'subagent follow-up is temporarily unavailable', { childSessionId }, { cause: error });
|
|
65
|
+
// A code outside the admission vocabulary is not the caller's move to make.
|
|
66
|
+
default:
|
|
67
|
+
break;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
throw new RemoteError('gateway/internal', 'subagent prompt failed', {}, { cause: error });
|
|
71
|
+
}
|
|
72
|
+
function isCancellation(error, signal) {
|
|
73
|
+
return signal.aborted || (error instanceof SubagentError && error.code === 'CANCELLED');
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=control.js.map
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Delegation-depth accounting: the recursion budget a parent passes to its
|
|
3
|
+
* children. Kept apart from the service so composition helpers can read it
|
|
4
|
+
* without importing the registry.
|
|
5
|
+
*
|
|
6
|
+
* @module @deepseek-ai/dsh-subagent/depth
|
|
7
|
+
*/
|
|
8
|
+
import type { Agent } from '@deepseek-ai/dsh-agent';
|
|
9
|
+
declare module '@deepseek-ai/dsh-agent' {
|
|
10
|
+
interface AgentOptions {
|
|
11
|
+
/** Delegation depth: zero for a top-level agent and parent depth + 1 for a child. */
|
|
12
|
+
subagentDepth?: number;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Read an agent's delegation depth, treating absence as top-level depth zero.
|
|
17
|
+
* The persisted session header is authoritative and monotone: runtime
|
|
18
|
+
* `AgentOptions.subagentDepth` may DEEPEN the count but can never lower it —
|
|
19
|
+
* a resumed child arrives with fresh options, and counting it from zero would
|
|
20
|
+
* let it delegate as if it were top-level.
|
|
21
|
+
* @param agent - the agent whose header and options carry the depth.
|
|
22
|
+
* @returns its non-negative safe-integer depth.
|
|
23
|
+
* @throws if the runtime `AgentOptions.subagentDepth` is not a non-negative safe integer.
|
|
24
|
+
*/
|
|
25
|
+
export declare function delegationDepthOf(agent: Agent): number;
|
|
26
|
+
/**
|
|
27
|
+
* Reject a recursion cap that cannot represent an exact delegation depth.
|
|
28
|
+
* @param maxDepth - the optional runtime value to validate.
|
|
29
|
+
*/
|
|
30
|
+
export declare function assertSubagentMaxDepth(maxDepth: unknown): void;
|
|
31
|
+
//# sourceMappingURL=depth.d.ts.map
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Delegation-depth accounting: the recursion budget a parent passes to its
|
|
3
|
+
* children. Kept apart from the service so composition helpers can read it
|
|
4
|
+
* without importing the registry.
|
|
5
|
+
*
|
|
6
|
+
* @module @deepseek-ai/dsh-subagent/depth
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Read an agent's delegation depth, treating absence as top-level depth zero.
|
|
10
|
+
* The persisted session header is authoritative and monotone: runtime
|
|
11
|
+
* `AgentOptions.subagentDepth` may DEEPEN the count but can never lower it —
|
|
12
|
+
* a resumed child arrives with fresh options, and counting it from zero would
|
|
13
|
+
* let it delegate as if it were top-level.
|
|
14
|
+
* @param agent - the agent whose header and options carry the depth.
|
|
15
|
+
* @returns its non-negative safe-integer depth.
|
|
16
|
+
* @throws if the runtime `AgentOptions.subagentDepth` is not a non-negative safe integer.
|
|
17
|
+
*/
|
|
18
|
+
export function delegationDepthOf(agent) {
|
|
19
|
+
const runtime = agent.options.subagentDepth;
|
|
20
|
+
if (runtime !== undefined && (!Number.isSafeInteger(runtime) || runtime < 0 || Object.is(runtime, -0))) {
|
|
21
|
+
throw new TypeError('agent subagentDepth must be a non-negative safe integer');
|
|
22
|
+
}
|
|
23
|
+
// The header value was validated at the session boundary (creation and
|
|
24
|
+
// persistence load both construct through the store).
|
|
25
|
+
return Math.max(agent.session.header.delegationDepth ?? 0, runtime ?? 0);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Reject a recursion cap that cannot represent an exact delegation depth.
|
|
29
|
+
* @param maxDepth - the optional runtime value to validate.
|
|
30
|
+
*/
|
|
31
|
+
export function assertSubagentMaxDepth(maxDepth) {
|
|
32
|
+
if (maxDepth !== undefined && (typeof maxDepth !== 'number'
|
|
33
|
+
|| !Number.isSafeInteger(maxDepth)
|
|
34
|
+
|| maxDepth < 0
|
|
35
|
+
|| Object.is(maxDepth, -0))) {
|
|
36
|
+
throw new TypeError('subagent maxDepth must be a non-negative safe integer');
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=depth.js.map
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The durable subagent-child descriptor: the versioned, model-hidden
|
|
3
|
+
* `subagent/descriptor` session event that identifies every session-backed
|
|
4
|
+
* subagent, including historical one-shot records. The manager appends each
|
|
5
|
+
* continuable child's descriptor inside its initial turn, preserving the
|
|
6
|
+
* declared composition required for cold resume.
|
|
7
|
+
*
|
|
8
|
+
* The descriptor deliberately snapshots explicit fields rather than the
|
|
9
|
+
* merge-extensible `AgentOptions` object: an unrelated extension value cannot
|
|
10
|
+
* make continuation fail merely because it is not JSON, and later composition
|
|
11
|
+
* inputs require a deliberate {@link SUBAGENT_DESCRIPTOR_VERSION} change. It
|
|
12
|
+
* omits `subagentDepth` — cold resume trusts the persisted header's
|
|
13
|
+
* `delegationDepth` as the monotone floor — and `outputSchema`, which belongs
|
|
14
|
+
* to one activation's result contract rather than durable child composition.
|
|
15
|
+
* Per-activation knobs such as `maxTokens` are omitted for the same reason as
|
|
16
|
+
* `outputSchema`: they budget one activation. Cold resume requires the exact
|
|
17
|
+
* live subagent tree root for authorization but reconstructs child options only from the
|
|
18
|
+
* durable descriptor, so it neither restores the prior budget nor inherits
|
|
19
|
+
* the parent's current one; the resumed route's defaults apply instead.
|
|
20
|
+
*
|
|
21
|
+
* @module @deepseek-ai/dsh-subagent/descriptor
|
|
22
|
+
*/
|
|
23
|
+
import type { SessionEvent } from '@deepseek-ai/dsh-session';
|
|
24
|
+
import type { ReasoningEffortId } from '@deepseek-ai/dsh-llm';
|
|
25
|
+
import type { ToolRestriction } from '@deepseek-ai/dsh-tools';
|
|
26
|
+
declare module '@deepseek-ai/dsh-session/types' {
|
|
27
|
+
interface SessionEventMap {
|
|
28
|
+
/**
|
|
29
|
+
* Durable identity and lifecycle mode of a session-backed subagent child,
|
|
30
|
+
* appended once inside the child's initial turn, before its first
|
|
31
|
+
* request. Continuable records also carry their
|
|
32
|
+
* resumable composition. Log-only: it carries no `surfaceOp`, never enters
|
|
33
|
+
* model history, and survives compaction.
|
|
34
|
+
*/
|
|
35
|
+
'subagent/descriptor': SubagentDescriptorData;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* The current descriptor format version, stamped into every appended
|
|
40
|
+
* `subagent/descriptor` event and required verbatim by {@link foldSubagentDescriptor}.
|
|
41
|
+
* Supporting another composition input is a deliberate version change, never
|
|
42
|
+
* an implicit extra field.
|
|
43
|
+
*/
|
|
44
|
+
export declare const SUBAGENT_DESCRIPTOR_VERSION = 3;
|
|
45
|
+
/** Fields shared by every supported `subagent/descriptor` payload. */
|
|
46
|
+
interface SubagentDescriptorBase {
|
|
47
|
+
/** Descriptor format version ({@link SUBAGENT_DESCRIPTOR_VERSION}). */
|
|
48
|
+
readonly version: number;
|
|
49
|
+
/** Whether the child is a terminal one-shot run or a resumable conversation. */
|
|
50
|
+
readonly mode: 'one-shot' | 'continuable';
|
|
51
|
+
/** The `ctx.subagents` provider name that established the child. */
|
|
52
|
+
readonly provider: string;
|
|
53
|
+
}
|
|
54
|
+
/** A session-backed subagent that cannot be cold-resumed after its run. */
|
|
55
|
+
export interface OneShotSubagentDescriptorData extends SubagentDescriptorBase {
|
|
56
|
+
readonly mode: 'one-shot';
|
|
57
|
+
/**
|
|
58
|
+
* The initial delegation's short `description`, kept as the child's durable
|
|
59
|
+
* creation label so enumeration can identify the conversation without
|
|
60
|
+
* replaying parent tool results or exposing the child prompt.
|
|
61
|
+
*/
|
|
62
|
+
readonly label?: string;
|
|
63
|
+
}
|
|
64
|
+
/** A session-backed subagent whose declared composition supports cold resume. */
|
|
65
|
+
export interface ContinuableSubagentDescriptorData extends SubagentDescriptorBase {
|
|
66
|
+
readonly mode: 'continuable';
|
|
67
|
+
/** The initial delegation's short `description`, used for durable enumeration. */
|
|
68
|
+
readonly label: string;
|
|
69
|
+
/** Resolved child `agentOptions.provider`, when one was declared. */
|
|
70
|
+
readonly agentProvider?: string;
|
|
71
|
+
/** Resolved child `agentOptions.model`, when one was declared. */
|
|
72
|
+
readonly agentModel?: string;
|
|
73
|
+
/** Resolved child `agentOptions.reasoningEffort`, when one was declared. */
|
|
74
|
+
readonly agentReasoningEffort?: ReasoningEffortId;
|
|
75
|
+
/** Per-child persona that shadows the deployment persona on resume. */
|
|
76
|
+
readonly persona?: string;
|
|
77
|
+
/** Child tool scoping reapplied on resume. */
|
|
78
|
+
readonly toolFilter?: ToolRestriction;
|
|
79
|
+
}
|
|
80
|
+
/** The supported durable subagent identity and optional continuation composition. */
|
|
81
|
+
export type SubagentDescriptorData = OneShotSubagentDescriptorData | ContinuableSubagentDescriptorData;
|
|
82
|
+
/** Continuable composition fields before the snapshot stamps their format version. */
|
|
83
|
+
export type ContinuableSubagentDescriptorInput = Omit<ContinuableSubagentDescriptorData, 'version'>;
|
|
84
|
+
/**
|
|
85
|
+
* Validate and detach a continuable descriptor input.
|
|
86
|
+
* @param input - the caller-collected continuable composition fields.
|
|
87
|
+
* @returns the versioned, detached continuable descriptor payload.
|
|
88
|
+
* @throws when a field is not losslessly JSON-serializable.
|
|
89
|
+
*/
|
|
90
|
+
export declare function snapshotSubagentDescriptor(input: ContinuableSubagentDescriptorInput): ContinuableSubagentDescriptorData;
|
|
91
|
+
/**
|
|
92
|
+
* Fold a persisted child log to its supported descriptor. The first
|
|
93
|
+
* `subagent/descriptor` event is authoritative — the establishing provider
|
|
94
|
+
* appends exactly one, so a later same-type event cannot rewrite the declared
|
|
95
|
+
* composition.
|
|
96
|
+
* @param events - the loaded child session events.
|
|
97
|
+
* @returns the descriptor, or `undefined` when the log has none or its
|
|
98
|
+
* version is not {@link SUBAGENT_DESCRIPTOR_VERSION} (the child cannot be
|
|
99
|
+
* classified by this runtime).
|
|
100
|
+
* @throws when a current-version persisted payload does not match its complete
|
|
101
|
+
* declared schema.
|
|
102
|
+
*/
|
|
103
|
+
export declare function foldSubagentDescriptor(events: readonly SessionEvent[]): SubagentDescriptorData | undefined;
|
|
104
|
+
export {};
|
|
105
|
+
//# sourceMappingURL=descriptor.d.ts.map
|