@dsmm/dsmm 0.3.22 → 0.3.24
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/agent-presets/dsmm-builder/agent.cordis.yml +1 -17
- package/agent-presets/dsmm-clarifier/agent.cordis.yml +1 -17
- package/agent-presets/dsmm-code-search/agent.cordis.yml +1 -17
- package/agent-presets/dsmm-coding/agent.cordis.yml +1 -17
- package/agent-presets/dsmm-complex/agent.cordis.yml +1 -17
- package/agent-presets/dsmm-creative/agent.cordis.yml +1 -17
- package/agent-presets/dsmm-cross-cutting/agent.cordis.yml +1 -17
- package/agent-presets/dsmm-deep/agent.cordis.yml +1 -17
- package/agent-presets/dsmm-doc-search/agent.cordis.yml +1 -17
- package/agent-presets/dsmm-documenting/agent.cordis.yml +1 -17
- package/agent-presets/dsmm-frontend/agent.cordis.yml +1 -17
- package/agent-presets/dsmm-hard-reasoning/agent.cordis.yml +1 -17
- package/agent-presets/dsmm-media-reader/agent.cordis.yml +1 -17
- package/agent-presets/dsmm-normal-task/agent.cordis.yml +1 -17
- package/agent-presets/dsmm-oracle/agent.cordis.yml +1 -17
- package/agent-presets/dsmm-oracle-2nd/agent.cordis.yml +1 -17
- package/agent-presets/dsmm-orchestrator/agent.cordis.yml +1 -17
- package/agent-presets/dsmm-plan-critic/agent.cordis.yml +1 -17
- package/agent-presets/dsmm-planner/agent.cordis.yml +1 -17
- package/agent-presets/dsmm-quick/agent.cordis.yml +1 -17
- package/agent-presets/dsmm-research/agent.cordis.yml +1 -17
- package/agent-presets/dsmm-reviewer/agent.cordis.yml +1 -17
- package/cordis.patch.yml +3 -0
- package/docs/agent-presets.md +1 -1
- package/docs/compatibility.md +13 -1
- package/docs/maintenance.md +48 -10
- package/docs/model-routing.md +25 -3
- package/docs/native-permissions.md +20 -4
- package/docs/releasing.md +3 -3
- package/docs/roadmap.md +33 -11
- package/docs/runtime-recovery.md +5 -3
- package/docs/settings-status.md +2 -2
- package/docs/testing.md +10 -0
- package/docs/web-fetch-fakeip.md +8 -2
- package/dsh-plugin.json +1 -1
- package/lib/agent-prompt-scope.d.ts +6 -0
- package/lib/agent-prompt-scope.js +66 -0
- package/lib/child-capture.d.ts +1 -1
- package/lib/child-capture.js +3 -1
- package/lib/client/DeploymentFields.js +1 -1
- package/lib/client/RoleToolView-data.d.ts +4 -2
- package/lib/client/RoleToolView-data.js +18 -4
- package/lib/client/RoleToolView-locales.d.ts +9 -0
- package/lib/client/RoleToolView-locales.js +4 -0
- package/lib/client/RoleToolView.d.ts +9 -3
- package/lib/client/RoleToolView.js +29 -8
- package/lib/client/children-locales.d.ts +4 -4
- package/lib/client/deployment-locales.d.ts +1 -0
- package/lib/client/deployment-locales.js +3 -1
- package/lib/client/index.js +36 -1
- package/lib/client/role-call-observations.d.ts +33 -0
- package/lib/client/role-call-observations.js +207 -0
- package/lib/client.js +501 -96
- package/lib/dsh-types.d.ts +15 -0
- package/lib/index.js +4 -1
- package/lib/live-pi-ai-owner.d.ts +1 -2
- package/lib/live-pi-ai-owner.js +10 -7
- package/lib/locale-guidance.d.ts +3 -0
- package/lib/locale-guidance.js +12 -0
- package/lib/model-family.d.ts +16 -0
- package/lib/model-family.js +156 -35
- package/lib/model-routing.d.ts +23 -2
- package/lib/model-routing.js +145 -7
- package/lib/native-admission.d.ts +36 -1
- package/lib/native-admission.js +408 -24
- package/lib/native-pi-ai-wire.js +17 -4
- package/lib/profile-diagnostics.js +1 -1
- package/lib/profile-remote.d.ts +2 -0
- package/lib/profile-remote.js +12 -3
- package/lib/profile-types.d.ts +5 -0
- package/lib/prompt-content.js +1 -1
- package/lib/prompts.d.ts +3 -2
- package/lib/prompts.js +32 -45
- package/lib/role-control-remote.d.ts +5 -2
- package/lib/role-control-remote.js +84 -4
- package/lib/role-control-rpc.d.ts +8 -1
- package/lib/role-control-rpc.js +122 -50
- package/lib/role-control-types.d.ts +62 -1
- package/lib/role-control-types.js +3 -0
- package/lib/role-invocation.js +1 -1
- package/lib/role-llm-runtime.js +2 -2
- package/lib/role-routing.d.ts +27 -7
- package/lib/role-routing.js +129 -16
- package/lib/role-subagents.js +13 -26
- package/lib/runtime-recovery.js +23 -6
- package/lib/session-metadata.d.ts +13 -1
- package/lib/session-metadata.js +21 -1
- package/lib/settings.d.ts +1 -0
- package/lib/settings.js +2 -1
- package/lib/web-fetch-address-policy.d.ts +6 -2
- package/lib/web-fetch-fakeip.d.ts +6 -0
- package/lib/web-fetch-fakeip.js +29 -2
- package/package.json +2 -2
- package/prompts/deepwork.md +3 -25
- package/prompts/source/deepwork/claude-opus-5.md +2 -8
- package/prompts/source/deepwork/codex.md +2 -8
- package/prompts/source/deepwork/default.md +3 -14
- package/prompts/source/deepwork/gemini-4.md +1 -7
- package/prompts/source/deepwork/gemini.md +3 -19
- package/prompts/source/deepwork/glm.md +6 -23
- package/prompts/source/deepwork/gpt.md +7 -15
- package/prompts/source/deepwork/kimi-k3-1.md +65 -0
- package/prompts/source/deepwork/kimi.md +1 -7
- package/prompts/source/deepwork/planner.md +0 -4
- package/prompts/source/deepwork/swe-2.md +2 -8
- package/prompts/source/shared/locale.md +1 -6
- package/skills/avoid-ai-slop/SKILL.md +2 -0
- package/skills/frontend/references/design/interaction-skill.md +14 -0
- package/skills/remove-ai-slops/SKILL.md +4 -4
- package/skills/report-fidelity/SKILL.md +3 -0
- package/prompts/source/shared/dsh-host-contract.md +0 -8
|
@@ -252,25 +252,25 @@ export declare const childrenLocaleZh: {
|
|
|
252
252
|
initialRoute: string;
|
|
253
253
|
routeSource: string;
|
|
254
254
|
description: string;
|
|
255
|
-
|
|
255
|
+
pending: string;
|
|
256
256
|
runId: string;
|
|
257
257
|
childId: string;
|
|
258
258
|
jobId: string;
|
|
259
|
-
|
|
259
|
+
delivery: string;
|
|
260
|
+
epoch: string;
|
|
260
261
|
yes: string;
|
|
261
262
|
no: string;
|
|
263
|
+
liveRoute: string;
|
|
262
264
|
runtime: string;
|
|
263
265
|
activity: string;
|
|
264
266
|
refresh: string;
|
|
265
267
|
images: string;
|
|
266
268
|
restart: string;
|
|
267
269
|
title: string;
|
|
268
|
-
liveRoute: string;
|
|
269
270
|
descendants: string;
|
|
270
271
|
interrupt: string;
|
|
271
272
|
readonly: string;
|
|
272
273
|
children: string;
|
|
273
|
-
delivery: string;
|
|
274
274
|
queue: string;
|
|
275
275
|
steer: string;
|
|
276
276
|
foreign: string;
|
|
@@ -11,6 +11,7 @@ export const deploymentEn = {
|
|
|
11
11
|
boundaries: "Saved settings apply to new sessions; restart-required changes need a separate Host restart that may cancel sessions.",
|
|
12
12
|
core: "Core", coreHint: "Core-owned desired settings. Model-parameter passthrough is ordinary config, not a subplugin. The permission-control enabled flag is startup-pinned. Save does not change current-session admission; inspect desired, startup and admitted values below. Unavailable admission stays unknown.",
|
|
13
13
|
modelParametersHint: "Off sends no custom parameters and uses native reasoning defaults. Saved values and the selected model stay unchanged.",
|
|
14
|
+
forceBackgroundHint: "Takes priority over Allow background runs: every delegation uses native parent delivery, whether run_in_background is omitted, true or false. Returns accepted child/message IDs without waiting for completion.",
|
|
14
15
|
permissionControlHint: "Permission-control mounting is startup-pinned. Saved configuration does not prove runtime coverage or remove current protections. Root rules keep their independent authority inside Permissions.",
|
|
15
16
|
modules: "Configuration sections", scope: "Configuration scope", loading: "Loading configuration…", unset: "Use default configuration",
|
|
16
17
|
"module:run": "Run and modules", "module:routes": "Model routes and recovery", "module:workflow": "Workflow, roles and subagents", "module:permissions": "Permissions and safety", "module:other": "Other / advanced", "module:state": "Configuration state",
|
|
@@ -55,6 +56,7 @@ export const deploymentZh = {
|
|
|
55
56
|
boundaries: "保存的设置供新会话使用;需重启的更改须另行重启宿主,可能取消会话。",
|
|
56
57
|
core: "Core 核心配置", coreHint: "Core 所有的 desired 意图配置。模型参数透传为普通配置,非子插件;权限控制 enabled 仅启动时捕获。保存不改变当前会话准入;下方可检查意图、启动与准入值,不可用的准入仍为未知。",
|
|
57
58
|
modelParametersHint: "关闭后不发送自定义参数,改用原生推理默认值;已保存值与所选模型不变。",
|
|
59
|
+
forceBackgroundHint: "优先于“允许后台执行”:run_in_background 无论省略、true 或 false,所有委派都使用原生父级后台交付,不等待任务完成,返回已接收的 child/message 标识。",
|
|
58
60
|
permissionControlHint: "权限控制挂载仅启动时捕获。保存配置不证明运行时覆盖,也不移除当前保护;Root 规则在权限模块内保持独立权限。",
|
|
59
61
|
modules: "配置分区", scope: "配置范围", loading: "正在加载配置…", unset: "使用默认配置",
|
|
60
62
|
"module:run": "运行与模块", "module:routes": "模型路由与恢复", "module:workflow": "工作流、角色与子 Agent", "module:permissions": "权限与安全", "module:other": "其他与高级", "module:state": "配置状态",
|
|
@@ -103,7 +105,7 @@ export const deploymentFieldLabels = {
|
|
|
103
105
|
gitWriteScope: ["Git write protection scope", "Git 写操作保护范围"],
|
|
104
106
|
toolOutputTruncation: ["Tool output truncation", "工具输出截断"], maxInlineBytes: ["Inline byte limit", "内联字节上限"],
|
|
105
107
|
planFormatValidation: ["Plan format validation", "计划格式校验"], questionLabelHelper: ["Question labels", "提问标签"], maxLabelChars: ["Label character limit", "标签字符上限"], todoDisciplineHelper: ["Todo discipline", "待办纪律"],
|
|
106
|
-
enableRunInBackground: ["Allow background runs", "允许后台执行"], backgroundMode: ["Background mode", "后台模式"], maxDepth: ["Maximum depth", "最大深度"],
|
|
108
|
+
enableRunInBackground: ["Allow background runs", "允许后台执行"], forceBackground: ["Force all delegations into background", "强制所有委派后台执行"], backgroundMode: ["Background mode", "后台模式"], maxDepth: ["Maximum depth", "最大深度"],
|
|
107
109
|
policy: ["Policy", "策略"], strictGates: ["Strict gates", "严格关卡"], reviewCap: ["Review limit", "审查上限"], finalReviewPolicy: ["Final review policy", "最终审查策略"],
|
|
108
110
|
retryOnStatusCodes: ["Retry HTTP statuses", "重试 HTTP 状态码"], retryOnCodes: ["Retry error codes", "重试错误码"], fallbackRoutes: ["Ordered fallback routes", "有序备用路由"], maxFallbackAttempts: ["Fallback attempt limit", "备用尝试上限"], idleContinuation: ["Idle continuation", "空闲继续"], maxContinuations: ["Continuation limit", "继续次数上限"], prompt: ["Continuation prompt", "继续提示词"],
|
|
109
111
|
root: ["Materialization directory", "物化目录"], strategy: ["Routing strategy", "路由策略"], rateLimit: ["Bounded rate-limit retry", "有界限流重试"], maxRetries: ["Retry limit", "重试上限"], initialDelayMs: ["Initial delay (ms)", "初始延迟(毫秒)"], maxDelayMs: ["Delay limit (ms)", "延迟上限(毫秒)"], maxTotalDelayMs: ["Total wait budget (ms)", "累计等待上限(毫秒)"], switchAfterRateLimits: ["Rate limits before switching", "切换前限流次数"], maxSwitches: ["Switch limit", "切换上限"],
|
package/lib/client/index.js
CHANGED
|
@@ -15,6 +15,7 @@ import { bindPermissionSession } from "./permission-session.js";
|
|
|
15
15
|
import { PermissionController } from "./permission-controller.js";
|
|
16
16
|
import { PERMISSIONS_NS, permissionEn, permissionZh } from "./permission-locales.js";
|
|
17
17
|
import { registerRoleToolViews } from "./RoleToolView.js";
|
|
18
|
+
import { RoleCallObservationController } from "./role-call-observations.js";
|
|
18
19
|
import { profileBlankNative } from "./profile-blank.js";
|
|
19
20
|
export { ProfilesController, NEW_PROFILE_CONTENT } from "./controller.js";
|
|
20
21
|
export { ProfilesSection } from "./ProfilesSection.js";
|
|
@@ -28,7 +29,9 @@ export { ROLE_CONTROL_REMOTE } from "../role-control-remote.js";
|
|
|
28
29
|
/** No self-dependency on a namespace that this contribution has not mounted. */
|
|
29
30
|
export const inject = ["slots", "locale", "remote"];
|
|
30
31
|
export async function apply(ctx) {
|
|
31
|
-
|
|
32
|
+
const roleCalls = new RoleCallObservationController();
|
|
33
|
+
registerRoleToolViews(ctx, roleCalls);
|
|
34
|
+
ctx.effect(() => () => roleCalls.dispose(), "dsmm: role call observations");
|
|
32
35
|
await ctx.remote.$mount(TYPERT_REMOTE);
|
|
33
36
|
await ctx.remote.$mount(ROLE_CONTROL_REMOTE);
|
|
34
37
|
await ctx.remote.$mount(PERMISSION_REMOTE);
|
|
@@ -42,6 +45,38 @@ export async function apply(ctx) {
|
|
|
42
45
|
connectionCtx.effect(() => handle.generation.subscribe(update));
|
|
43
46
|
connectionCtx.effect(() => () => permissions.bindConnection(null), "dsmm: permission connection withdrawal");
|
|
44
47
|
});
|
|
48
|
+
void ctx.inject(["connection", "remote.dsmmChildren"], connectionCtx => {
|
|
49
|
+
const handle = connectionCtx.connection;
|
|
50
|
+
let active = true, observedGeneration;
|
|
51
|
+
let unbindRoleCalls, stopReady;
|
|
52
|
+
const update = () => {
|
|
53
|
+
if (!active)
|
|
54
|
+
return;
|
|
55
|
+
const generation = handle.generation.getSnapshot();
|
|
56
|
+
if (generation === observedGeneration)
|
|
57
|
+
return;
|
|
58
|
+
stopReady?.();
|
|
59
|
+
unbindRoleCalls?.();
|
|
60
|
+
stopReady = undefined;
|
|
61
|
+
unbindRoleCalls = undefined;
|
|
62
|
+
observedGeneration = generation;
|
|
63
|
+
if (generation === undefined)
|
|
64
|
+
return;
|
|
65
|
+
unbindRoleCalls = roleCalls.bindConnection(connectionCtx.remote, (sessionId, signal) => connectionCtx.remote.dsmmChildren.observe(sessionId, signal));
|
|
66
|
+
stopReady = connectionCtx.remote.$on("api-session/added", summary => {
|
|
67
|
+
if (!active || observedGeneration !== generation || handle.generation.getSnapshot() !== generation)
|
|
68
|
+
return;
|
|
69
|
+
roleCalls.observeSessionAvailability(summary.sessionId, summary.agentAvailable);
|
|
70
|
+
});
|
|
71
|
+
};
|
|
72
|
+
update();
|
|
73
|
+
connectionCtx.effect(() => handle.generation.subscribe(update));
|
|
74
|
+
connectionCtx.effect(() => () => {
|
|
75
|
+
active = false;
|
|
76
|
+
stopReady?.();
|
|
77
|
+
unbindRoleCalls?.();
|
|
78
|
+
}, "dsmm: role call connection withdrawal");
|
|
79
|
+
});
|
|
45
80
|
void ctx.inject(["uiSession", "sessions"], sessionCtx => {
|
|
46
81
|
const source = sessionCtx.uiSession.adapter.current, sessions = sessionCtx.sessions;
|
|
47
82
|
sessionCtx.effect(() => bindPermissionSession(source, sessions, permissions), "dsmm: permission native session withdrawal");
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { RemoteStream, RemoteStreamOptions } from "@deepseek-ai/dsh-api-gateway/client";
|
|
2
|
+
import type { HostObservable } from "@deepseek-ai/dsh-client-ui-slots";
|
|
3
|
+
import type { RoleCallObservation, RoleCallObservationFrame, RoleControlErrorInfo } from "../role-control-types.js";
|
|
4
|
+
export type RoleCallObservationIssue = ({
|
|
5
|
+
readonly kind: "domain";
|
|
6
|
+
} & RoleControlErrorInfo) | {
|
|
7
|
+
readonly kind: "transport";
|
|
8
|
+
readonly code: "unavailable" | "cancelled" | "internal";
|
|
9
|
+
} | {
|
|
10
|
+
readonly kind: "protocol";
|
|
11
|
+
readonly code: "invalid-frame" | "invalid-error";
|
|
12
|
+
};
|
|
13
|
+
export interface RoleCallObservationState {
|
|
14
|
+
readonly sessionId: string;
|
|
15
|
+
readonly status: "unavailable" | "connecting" | "live" | "stale";
|
|
16
|
+
readonly admissionEpoch?: string;
|
|
17
|
+
readonly issue?: RoleCallObservationIssue;
|
|
18
|
+
readonly calls: ReadonlyMap<string, RoleCallObservation>;
|
|
19
|
+
}
|
|
20
|
+
export type RoleCallStreamOpen = (sessionId: string, signal: AbortSignal) => AsyncIterable<RoleCallObservationFrame>;
|
|
21
|
+
export interface RoleCallStreamFactory {
|
|
22
|
+
$stream<Item>(options: RemoteStreamOptions<Item>): RemoteStream<Item>;
|
|
23
|
+
}
|
|
24
|
+
export declare class RoleCallObservationController {
|
|
25
|
+
private binding;
|
|
26
|
+
private readonly sources;
|
|
27
|
+
private disposed;
|
|
28
|
+
source(sessionId: string): HostObservable<RoleCallObservationState>;
|
|
29
|
+
observeSessionAvailability(sessionId: string, available: boolean): void;
|
|
30
|
+
bindConnection(factory: RoleCallStreamFactory, open: RoleCallStreamOpen): () => void;
|
|
31
|
+
dispose(): void;
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=role-call-observations.d.ts.map
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
import { remoteErrorOf } from "@deepseek-ai/dsh-typert-protocol";
|
|
2
|
+
import { parseRoleControlErrorInfo } from "../role-control-remote.js";
|
|
3
|
+
class ObservationProtocolError extends Error {
|
|
4
|
+
code;
|
|
5
|
+
constructor(code) {
|
|
6
|
+
super(code);
|
|
7
|
+
this.code = code;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
function observationIssue(error) {
|
|
11
|
+
if (error instanceof ObservationProtocolError)
|
|
12
|
+
return { kind: "protocol", code: error.code };
|
|
13
|
+
const remote = remoteErrorOf(error);
|
|
14
|
+
if (remote?.code === "dsmm-children/refused") {
|
|
15
|
+
try {
|
|
16
|
+
return { kind: "domain", ...parseRoleControlErrorInfo(remote.details) };
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
return { kind: "protocol", code: "invalid-error" };
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return { kind: "transport", code: remote?.code === "gateway/cancelled" ? "cancelled" : remote?.code === "gateway/internal" ? "internal" : "unavailable" };
|
|
23
|
+
}
|
|
24
|
+
export class RoleCallObservationController {
|
|
25
|
+
binding = null;
|
|
26
|
+
sources = new Map();
|
|
27
|
+
disposed = false;
|
|
28
|
+
source(sessionId) {
|
|
29
|
+
let source = this.sources.get(sessionId);
|
|
30
|
+
if (source === undefined) {
|
|
31
|
+
source = new RoleCallObservationSource(sessionId);
|
|
32
|
+
if (this.disposed)
|
|
33
|
+
source.dispose();
|
|
34
|
+
else
|
|
35
|
+
source.bind(this.binding);
|
|
36
|
+
this.sources.set(sessionId, source);
|
|
37
|
+
}
|
|
38
|
+
return source;
|
|
39
|
+
}
|
|
40
|
+
observeSessionAvailability(sessionId, available) {
|
|
41
|
+
if (!this.disposed && available)
|
|
42
|
+
this.sources.get(sessionId)?.observeAvailability();
|
|
43
|
+
}
|
|
44
|
+
bindConnection(factory, open) {
|
|
45
|
+
if (this.disposed)
|
|
46
|
+
return () => { };
|
|
47
|
+
const binding = { identity: {}, factory, open };
|
|
48
|
+
this.binding = binding;
|
|
49
|
+
for (const source of this.sources.values())
|
|
50
|
+
source.bind(binding);
|
|
51
|
+
return () => {
|
|
52
|
+
if (this.binding !== binding)
|
|
53
|
+
return;
|
|
54
|
+
this.binding = null;
|
|
55
|
+
for (const source of this.sources.values())
|
|
56
|
+
source.bind(null);
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
dispose() {
|
|
60
|
+
this.disposed = true;
|
|
61
|
+
this.binding = null;
|
|
62
|
+
for (const source of this.sources.values())
|
|
63
|
+
source.dispose();
|
|
64
|
+
this.sources.clear();
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
class RoleCallObservationSource {
|
|
68
|
+
sessionId;
|
|
69
|
+
snapshot;
|
|
70
|
+
listeners = new Set();
|
|
71
|
+
binding = null;
|
|
72
|
+
revision = 0;
|
|
73
|
+
stream;
|
|
74
|
+
hint = 0;
|
|
75
|
+
consumedHint = 0;
|
|
76
|
+
disposed = false;
|
|
77
|
+
constructor(sessionId) {
|
|
78
|
+
this.sessionId = sessionId;
|
|
79
|
+
this.snapshot = { sessionId, status: "unavailable", calls: new Map() };
|
|
80
|
+
}
|
|
81
|
+
getSnapshot() { return this.snapshot; }
|
|
82
|
+
observeAvailability() {
|
|
83
|
+
if (this.disposed || this.binding === null || this.listeners.size === 0)
|
|
84
|
+
return;
|
|
85
|
+
this.hint++;
|
|
86
|
+
if (this.snapshot.status === "live")
|
|
87
|
+
this.consumedHint = this.hint;
|
|
88
|
+
else
|
|
89
|
+
this.start();
|
|
90
|
+
}
|
|
91
|
+
subscribe(listener) {
|
|
92
|
+
if (this.disposed)
|
|
93
|
+
return () => { };
|
|
94
|
+
this.listeners.add(listener);
|
|
95
|
+
if (this.listeners.size === 1)
|
|
96
|
+
this.start();
|
|
97
|
+
return () => {
|
|
98
|
+
this.listeners.delete(listener);
|
|
99
|
+
if (this.listeners.size !== 0)
|
|
100
|
+
return;
|
|
101
|
+
this.revision++;
|
|
102
|
+
this.consumedHint = this.hint;
|
|
103
|
+
const stream = this.stream;
|
|
104
|
+
this.stream = undefined;
|
|
105
|
+
if (stream !== undefined)
|
|
106
|
+
void stream.dispose();
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
bind(binding) {
|
|
110
|
+
if (this.disposed || this.binding?.identity === binding?.identity)
|
|
111
|
+
return;
|
|
112
|
+
this.binding = binding;
|
|
113
|
+
this.revision++;
|
|
114
|
+
this.consumedHint = this.hint;
|
|
115
|
+
const stream = this.stream;
|
|
116
|
+
this.stream = undefined;
|
|
117
|
+
if (stream !== undefined)
|
|
118
|
+
void stream.dispose();
|
|
119
|
+
this.publish({ sessionId: this.sessionId, status: "unavailable", calls: new Map() });
|
|
120
|
+
if (this.listeners.size > 0)
|
|
121
|
+
this.start();
|
|
122
|
+
}
|
|
123
|
+
dispose() {
|
|
124
|
+
this.disposed = true;
|
|
125
|
+
this.binding = null;
|
|
126
|
+
this.revision++;
|
|
127
|
+
this.consumedHint = this.hint;
|
|
128
|
+
const stream = this.stream;
|
|
129
|
+
this.stream = undefined;
|
|
130
|
+
if (stream !== undefined)
|
|
131
|
+
void stream.dispose();
|
|
132
|
+
this.listeners.clear();
|
|
133
|
+
}
|
|
134
|
+
start() {
|
|
135
|
+
const binding = this.binding;
|
|
136
|
+
if (this.disposed || binding === null || this.listeners.size === 0 || this.stream !== undefined)
|
|
137
|
+
return;
|
|
138
|
+
const revision = ++this.revision;
|
|
139
|
+
this.consumedHint = this.hint;
|
|
140
|
+
const stream = binding.factory.$stream({
|
|
141
|
+
name: `DSMM role calls for ${this.sessionId}`,
|
|
142
|
+
open: signal => binding.open(this.sessionId, signal),
|
|
143
|
+
ended: accepted => new Error(`DSMM role call stream ended ${accepted ? "after" : "before"} its snapshot`),
|
|
144
|
+
carrierFailed: () => {
|
|
145
|
+
if (this.revision === revision && this.stream === stream)
|
|
146
|
+
this.invalidate("stale", { kind: "transport", code: "unavailable" });
|
|
147
|
+
},
|
|
148
|
+
});
|
|
149
|
+
this.stream = stream;
|
|
150
|
+
this.invalidate("connecting", this.snapshot.issue);
|
|
151
|
+
void this.consume(stream, revision);
|
|
152
|
+
}
|
|
153
|
+
async consume(stream, revision) {
|
|
154
|
+
let generation = 0, admissionEpoch;
|
|
155
|
+
try {
|
|
156
|
+
for await (const item of stream) {
|
|
157
|
+
if (this.revision !== revision || this.stream !== stream)
|
|
158
|
+
return;
|
|
159
|
+
const frame = item.value;
|
|
160
|
+
if (frame.sessionId !== this.sessionId)
|
|
161
|
+
throw new ObservationProtocolError("invalid-frame");
|
|
162
|
+
if (item.generation !== generation) {
|
|
163
|
+
if (frame.type !== "snapshot")
|
|
164
|
+
throw new ObservationProtocolError("invalid-frame");
|
|
165
|
+
generation = item.generation;
|
|
166
|
+
admissionEpoch = frame.admissionEpoch;
|
|
167
|
+
this.consumedHint = this.hint;
|
|
168
|
+
item.accept();
|
|
169
|
+
this.publish({ sessionId: this.sessionId, status: "live", admissionEpoch,
|
|
170
|
+
calls: new Map(frame.calls.map(call => [call.callId, call])) });
|
|
171
|
+
continue;
|
|
172
|
+
}
|
|
173
|
+
if (frame.type === "snapshot" || frame.admissionEpoch !== admissionEpoch)
|
|
174
|
+
throw new ObservationProtocolError("invalid-frame");
|
|
175
|
+
const calls = new Map(this.snapshot.calls);
|
|
176
|
+
if (frame.type === "update")
|
|
177
|
+
calls.set(frame.call.callId, frame.call);
|
|
178
|
+
else
|
|
179
|
+
calls.delete(frame.callId);
|
|
180
|
+
this.publish({ sessionId: this.sessionId, status: "live", admissionEpoch, calls });
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
catch (error) {
|
|
184
|
+
if (this.revision === revision && this.stream === stream)
|
|
185
|
+
this.invalidate("unavailable", observationIssue(error));
|
|
186
|
+
}
|
|
187
|
+
finally {
|
|
188
|
+
if (this.revision === revision && this.stream === stream) {
|
|
189
|
+
this.stream = undefined;
|
|
190
|
+
if (this.hint > this.consumedHint)
|
|
191
|
+
this.start();
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
invalidate(status, issue) {
|
|
196
|
+
const calls = new Map([...this.snapshot.calls].map(([callId, call]) => [callId, call.phase === "settled" ? call : Object.freeze({
|
|
197
|
+
...call, actualRoute: Object.freeze({ status: "unknown", reason: "not-observed" }),
|
|
198
|
+
})]));
|
|
199
|
+
this.publish({ ...this.snapshot, status, issue, calls });
|
|
200
|
+
}
|
|
201
|
+
publish(snapshot) {
|
|
202
|
+
this.snapshot = snapshot;
|
|
203
|
+
for (const listener of this.listeners)
|
|
204
|
+
listener();
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
//# sourceMappingURL=role-call-observations.js.map
|