@mupt-ai/dari-gateway 1.0.368 → 1.0.370

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.
Files changed (114) hide show
  1. package/dist/harnesses/claude_code.d.ts +11 -0
  2. package/dist/{ingress/claude_code/request_context.js → harnesses/claude_code.js} +40 -1
  3. package/dist/harnesses/codex.d.ts +9 -0
  4. package/dist/harnesses/codex.js +112 -0
  5. package/dist/harnesses/hermes.d.ts +4 -0
  6. package/dist/harnesses/hermes.js +6 -0
  7. package/dist/harnesses/index.d.ts +34 -0
  8. package/dist/harnesses/index.js +13 -0
  9. package/dist/harnesses/muse_code.d.ts +9 -0
  10. package/dist/harnesses/muse_code.js +22 -0
  11. package/dist/harnesses/openclaw.d.ts +4 -0
  12. package/dist/harnesses/openclaw.js +6 -0
  13. package/dist/harnesses/opencode.d.ts +7 -0
  14. package/dist/harnesses/opencode.js +40 -0
  15. package/dist/harnesses/pi.d.ts +6 -0
  16. package/dist/harnesses/pi.js +23 -0
  17. package/dist/ingress/client_harness.d.ts +1 -2
  18. package/dist/ingress/client_harness.js +4 -39
  19. package/dist/ingress/harness_request.js +6 -3
  20. package/dist/ingress/models.js +2 -1
  21. package/dist/link/endpoints.js +5 -5
  22. package/dist/link/self_hosted.js +0 -1
  23. package/dist/platform/platform.d.ts +2 -0
  24. package/dist/platform/routing_contract.d.ts +1 -0
  25. package/dist/platform/routing_contract.js +4 -0
  26. package/dist/protocol/output/anthropic_messages.d.ts +1 -0
  27. package/dist/protocol/output/anthropic_messages.js +1 -1
  28. package/dist/protocol/output/anthropic_messages_output.d.ts +1 -1
  29. package/dist/protocol/output/anthropic_messages_output.js +3 -1
  30. package/dist/protocol/output/anthropic_messages_stream.d.ts +1 -0
  31. package/dist/protocol/output/anthropic_messages_stream.js +1 -1
  32. package/dist/protocol/output/chat_completions.d.ts +2 -0
  33. package/dist/protocol/output/chat_completions.js +5 -3
  34. package/dist/protocol/output/openai_responses.d.ts +1 -0
  35. package/dist/protocol/output/openai_responses.js +1 -1
  36. package/dist/protocol/output/openai_responses_output.d.ts +1 -1
  37. package/dist/protocol/output/openai_responses_output.js +3 -1
  38. package/dist/protocol/output/openai_responses_stream.d.ts +1 -0
  39. package/dist/protocol/output/openai_responses_stream.js +1 -1
  40. package/dist/providers/execution.d.ts +1 -0
  41. package/dist/providers/execution.js +29 -7
  42. package/dist/providers/provider_call.d.ts +1 -0
  43. package/dist/providers/provider_call.js +2 -0
  44. package/dist/runtime/harness_identity/extract.d.ts +0 -8
  45. package/dist/runtime/harness_identity/extract.js +2 -201
  46. package/dist/runtime/harness_identity/ids.d.ts +2 -0
  47. package/dist/runtime/harness_identity/ids.js +26 -0
  48. package/dist/runtime/harness_identity/index.d.ts +1 -1
  49. package/dist/runtime/harness_identity/index.js +1 -1
  50. package/dist/runtime/prepare_routed_completion.d.ts +1 -0
  51. package/dist/runtime/prepare_routed_completion.js +4 -0
  52. package/dist/runtime/routed_completion.js +4 -1
  53. package/dist/runtime/routed_protocol.d.ts +2 -0
  54. package/dist/self_host/config.js +1 -1
  55. package/dist/self_host/connected.d.ts +7 -3
  56. package/dist/self_host/connected.js +9 -10
  57. package/dist/self_host/hosted_sync.js +1 -1
  58. package/dist/self_host/main.d.ts +3 -2
  59. package/dist/self_host/main.js +16 -6
  60. package/dist/self_host/private_mode.d.ts +16 -0
  61. package/dist/self_host/private_mode.js +35 -0
  62. package/dist/self_host/resolve.js +5 -2
  63. package/dist/self_host/router_models.js +1 -1
  64. package/dist/self_host/subscriptions/http.js +2 -17
  65. package/dist/self_host/subscriptions/store.d.ts +7 -6
  66. package/dist/self_host/subscriptions/store.js +15 -27
  67. package/dist/telemetry/report.js +1 -0
  68. package/dist/types.d.ts +2 -1
  69. package/package.json +2 -2
  70. package/src/{ingress/claude_code/request_context.ts → harnesses/claude_code.ts} +56 -2
  71. package/src/harnesses/codex.ts +156 -0
  72. package/src/harnesses/hermes.ts +8 -0
  73. package/src/harnesses/index.ts +29 -0
  74. package/src/harnesses/muse_code.ts +30 -0
  75. package/src/harnesses/openclaw.ts +8 -0
  76. package/src/harnesses/opencode.ts +51 -0
  77. package/src/harnesses/pi.ts +28 -0
  78. package/src/ingress/client_harness.ts +4 -41
  79. package/src/ingress/harness_request.ts +9 -9
  80. package/src/ingress/models.ts +2 -1
  81. package/src/link/endpoints.ts +5 -5
  82. package/src/link/self_hosted.ts +0 -1
  83. package/src/platform/platform.ts +6 -0
  84. package/src/platform/routing_contract.ts +5 -0
  85. package/src/protocol/output/anthropic_messages.ts +2 -1
  86. package/src/protocol/output/anthropic_messages_output.ts +4 -1
  87. package/src/protocol/output/anthropic_messages_stream.ts +2 -1
  88. package/src/protocol/output/chat_completions.ts +7 -3
  89. package/src/protocol/output/openai_responses.ts +2 -1
  90. package/src/protocol/output/openai_responses_output.ts +4 -1
  91. package/src/protocol/output/openai_responses_stream.ts +2 -1
  92. package/src/providers/execution.ts +36 -7
  93. package/src/providers/provider_call.ts +5 -0
  94. package/src/runtime/harness_identity/extract.ts +2 -284
  95. package/src/runtime/harness_identity/ids.ts +41 -0
  96. package/src/runtime/harness_identity/index.ts +1 -10
  97. package/src/runtime/prepare_routed_completion.ts +4 -0
  98. package/src/runtime/routed_completion.ts +4 -1
  99. package/src/runtime/routed_protocol.ts +2 -0
  100. package/src/self_host/config.ts +1 -1
  101. package/src/self_host/connected.ts +16 -12
  102. package/src/self_host/hosted_sync.ts +1 -1
  103. package/src/self_host/main.ts +14 -6
  104. package/src/self_host/private_mode.ts +41 -0
  105. package/src/self_host/resolve.ts +4 -2
  106. package/src/self_host/router_models.ts +1 -1
  107. package/src/self_host/subscriptions/http.ts +2 -15
  108. package/src/self_host/subscriptions/store.ts +15 -34
  109. package/src/telemetry/report.ts +1 -0
  110. package/src/types.ts +5 -10
  111. package/dist/ingress/claude_code/request_context.d.ts +0 -4
  112. package/dist/ingress/muse_code.d.ts +0 -2
  113. package/dist/ingress/muse_code.js +0 -8
  114. package/src/ingress/muse_code.ts +0 -9
@@ -0,0 +1,11 @@
1
+ import type { AgentRequestContext } from "../interaction/types.js";
2
+ import type { HarnessConversationIdentity } from "../runtime/harness_identity/conversation.js";
3
+ export declare const claudeCode: {
4
+ readonly id: "claude_code";
5
+ readonly headers: readonly ["user-agent", "x-app", "anthropic-beta", "x-claude-code-session-id", "x-claude-code-request-class", "x-claude-code-agent-id", "x-claude-code-parent-agent-id", "x-claude-code-agent-type"];
6
+ readonly ownPlanOnly: true;
7
+ };
8
+ /** Whether a request carries Claude Code's own headers. */
9
+ export declare function isClaudeCodeRequest(headers: Headers): boolean;
10
+ export declare function claudeCodeRequestContext(headers: Headers): AgentRequestContext;
11
+ export declare function claudeCodeConversationIdentity(headers: Headers, metadataSessionId?: string): HarnessConversationIdentity | undefined;
@@ -1,4 +1,20 @@
1
- import { HttpError } from "../../http/errors.js";
1
+ import { HttpError } from "../http/errors.js";
2
+ import { boundedIdentity, uuidIdentity } from "../runtime/harness_identity/ids.js";
3
+ export const claudeCode = {
4
+ id: "claude_code",
5
+ headers: [
6
+ "user-agent",
7
+ "x-app",
8
+ "anthropic-beta",
9
+ "x-claude-code-session-id",
10
+ "x-claude-code-request-class",
11
+ "x-claude-code-agent-id",
12
+ "x-claude-code-parent-agent-id",
13
+ "x-claude-code-agent-type",
14
+ ],
15
+ // A Claude Code plan serves only Claude Code.
16
+ ownPlanOnly: true,
17
+ };
2
18
  const REQUEST_CLASSES = new Set([
3
19
  "main", "subagent", "workflow", "auxiliary", "compaction", "side_reply",
4
20
  ]);
@@ -40,3 +56,26 @@ function identifier(headers, name) {
40
56
  }
41
57
  return value;
42
58
  }
59
+ export function claudeCodeConversationIdentity(headers, metadataSessionId) {
60
+ const candidates = [
61
+ uuidIdentity(headers.get("x-claude-code-session-id"), "x-claude-code-session-id"),
62
+ uuidIdentity(metadataSessionId, "metadata.user_id.session_id"),
63
+ ].filter((value) => value !== undefined);
64
+ if (candidates.length === 0)
65
+ return undefined;
66
+ // Claude Code can carry a stale metadata session after a resume or fork.
67
+ // The header names the live session, so it wins over the metadata.
68
+ const [sessionId] = candidates;
69
+ // Claude Code reuses the parent session UUID for every subagent, but gives
70
+ // each subagent a stable agent header. Keep the parent thread on the bare
71
+ // session identity and scope each subagent to its own composite identity.
72
+ // Treat this as an opaque Claude identifier. Besides ordinary subagent IDs,
73
+ // Claude may send labeled agents or Agent Teams identities such as
74
+ // `reviewer@backend`; Dari only needs a stable, bounded value to hash.
75
+ const agentId = boundedIdentity(headers.get("x-claude-code-agent-id"), "x-claude-code-agent-id");
76
+ return {
77
+ kind: "claude_code_session",
78
+ value: sessionId,
79
+ ...(agentId === undefined ? {} : { qualifiers: [agentId] }),
80
+ };
81
+ }
@@ -0,0 +1,9 @@
1
+ import type { AgentRequestContext, InteractionRequestPurpose } from "../interaction/types.js";
2
+ import type { HarnessConversationIdentity } from "../runtime/harness_identity/conversation.js";
3
+ export declare const codex: {
4
+ readonly id: "codex";
5
+ readonly headers: readonly ["x-codex-turn-metadata", "thread-id"];
6
+ };
7
+ export declare function codexConversationIdentity(headers: Headers, payload: Record<string, unknown>): HarnessConversationIdentity | undefined;
8
+ export declare function codexRequestPurpose(headers: Headers, payload: Record<string, unknown>): InteractionRequestPurpose | undefined;
9
+ export declare function codexRequestContext(headers: Headers, payload: Record<string, unknown>): AgentRequestContext | undefined;
@@ -0,0 +1,112 @@
1
+ import { isRecord } from "@mupt-ai/dari-router/policy-engine";
2
+ import { HttpError } from "../http/errors.js";
3
+ import { boundedIdentity, uuidIdentity } from "../runtime/harness_identity/ids.js";
4
+ export const codex = {
5
+ id: "codex",
6
+ headers: ["x-codex-turn-metadata", "thread-id"],
7
+ };
8
+ export function codexConversationIdentity(headers, payload) {
9
+ const clientMetadata = isRecord(payload.client_metadata)
10
+ ? payload.client_metadata
11
+ : undefined;
12
+ const turnMetadata = codexTurnMetadataCollection(headers, payload);
13
+ if (turnMetadata.length === 0) {
14
+ return undefined;
15
+ }
16
+ // Clients can carry a stale projection after a resume or fork. Conflicts
17
+ // must not fail the request, and fields must not mix across projections:
18
+ // take thread, turn, and parent from one turn metadata projection, header
19
+ // first, falling back to the standalone thread fields only for the thread.
20
+ const entry = turnMetadata.find((metadata) => metadata.thread_id !== undefined)
21
+ ?? turnMetadata[0];
22
+ const threadId = uuidIdentity(entry.thread_id, "x-codex-turn-metadata.thread_id")
23
+ ?? uuidIdentity(headers.get("thread-id"), "thread-id")
24
+ ?? uuidIdentity(clientMetadata?.thread_id, "client_metadata.thread_id");
25
+ if (threadId === undefined) {
26
+ return undefined;
27
+ }
28
+ const userTurnId = uuidIdentity(entry.turn_id, "x-codex-turn-metadata.turn_id");
29
+ const parentThreadId = uuidIdentity(entry.parent_thread_id, "x-codex-turn-metadata.parent_thread_id");
30
+ return {
31
+ kind: "codex_thread",
32
+ value: threadId,
33
+ ...(parentThreadId === undefined ? {} : { parentThreadId }),
34
+ ...(userTurnId === undefined ? {} : { userTurnId }),
35
+ };
36
+ }
37
+ export function codexRequestPurpose(headers, payload) {
38
+ const turnMetadata = codexTurnMetadataCollection(headers, payload);
39
+ return turnMetadata.length > 0 && turnMetadata.every(isCodexMemoryExtraction)
40
+ ? "memory_extraction"
41
+ : undefined;
42
+ }
43
+ export function codexRequestContext(headers, payload) {
44
+ const metadata = codexTurnMetadataCollection(headers, payload);
45
+ if (metadata.length === 0)
46
+ return undefined;
47
+ // Classify from one projection, header first, skipping one that omits the
48
+ // request kind so a partial header falls back to a complete body.
49
+ const entry = metadata.find((candidate) => candidate.request_kind !== undefined)
50
+ ?? metadata[0];
51
+ const kind = entry.request_kind;
52
+ const agentKind = entry.subagent_kind;
53
+ const agentId = uuidIdentity(entry.thread_id, "x-codex-turn-metadata.thread_id");
54
+ const requestClass = kind === "compaction" ? "compaction"
55
+ : kind === "memory" || kind === "prewarm" ? "auxiliary"
56
+ : kind === "turn" && agentKind === "memory_consolidation" ? "auxiliary"
57
+ : kind === "turn" && agentKind === "compact" ? "compaction"
58
+ : kind === "turn" && agentKind !== undefined ? "subagent"
59
+ : kind === "turn" ? "main" : "unknown";
60
+ return {
61
+ requestClass,
62
+ ...(requestClass === "subagent" && agentId !== undefined ? { agentId } : {}),
63
+ parentAgentId: uuidIdentity(entry.parent_thread_id, "x-codex-turn-metadata.parent_thread_id"),
64
+ agentType: boundedIdentity(agentKind, "x-codex-turn-metadata.subagent_kind"),
65
+ };
66
+ }
67
+ // Muse Code sends its thread on every Responses request. The main agent's
68
+ // thread is its session, and each subagent has its own thread, so each keeps
69
+ // its own conversation and lease.
70
+ function isCodexMemoryExtraction(metadata) {
71
+ if (metadata.request_kind !== "memory" ||
72
+ metadata.thread_source !== "memory_consolidation") {
73
+ return false;
74
+ }
75
+ // Codex deliberately omits canonical turn identity for detached phase-1
76
+ // memory jobs, while compatibility projections still carry the live root
77
+ // thread UUID. Phase-2 consolidation agents use ordinary turn metadata and
78
+ // their own thread identities, so they do not match this shape.
79
+ return [
80
+ "session_id",
81
+ "thread_id",
82
+ "turn_id",
83
+ "root_turn_id",
84
+ "window_id",
85
+ "forked_from_thread_id",
86
+ ].every((field) => metadata[field] === undefined);
87
+ }
88
+ function codexTurnMetadataCollection(headers, payload) {
89
+ const clientMetadata = isRecord(payload.client_metadata)
90
+ ? payload.client_metadata
91
+ : undefined;
92
+ return [
93
+ codexTurnMetadata(headers.get("x-codex-turn-metadata"), "x-codex-turn-metadata"),
94
+ codexTurnMetadata(clientMetadata?.["x-codex-turn-metadata"], "client_metadata.x-codex-turn-metadata"),
95
+ ].filter((value) => value !== undefined);
96
+ }
97
+ function codexTurnMetadata(raw, field) {
98
+ if (raw === undefined || raw === null)
99
+ return undefined;
100
+ if (typeof raw !== "string") {
101
+ throw new HttpError(400, `${field} must be a JSON string.`, "invalid_request_error", field);
102
+ }
103
+ try {
104
+ const parsed = JSON.parse(raw);
105
+ if (!isRecord(parsed))
106
+ throw new Error("not an object");
107
+ return parsed;
108
+ }
109
+ catch {
110
+ throw new HttpError(400, `${field} must contain a JSON object.`, "invalid_request_error", field);
111
+ }
112
+ }
@@ -0,0 +1,4 @@
1
+ export declare const hermes: {
2
+ readonly id: "hermes";
3
+ readonly headers: readonly [];
4
+ };
@@ -0,0 +1,6 @@
1
+ // Sends nothing of its own that tells it apart, so the Dari CLI sets it up to
2
+ // name itself in x-dari-client-harness.
3
+ export const hermes = {
4
+ id: "hermes",
5
+ headers: [],
6
+ };
@@ -0,0 +1,34 @@
1
+ /** A coding agent the gateway serves. */
2
+ export type Harness = {
3
+ id: string;
4
+ headers: readonly string[];
5
+ ownPlanOnly?: true;
6
+ };
7
+ export declare const HARNESSES: readonly [{
8
+ readonly id: "claude_code";
9
+ readonly headers: readonly ["user-agent", "x-app", "anthropic-beta", "x-claude-code-session-id", "x-claude-code-request-class", "x-claude-code-agent-id", "x-claude-code-parent-agent-id", "x-claude-code-agent-type"];
10
+ readonly ownPlanOnly: true;
11
+ }, {
12
+ readonly id: "codex";
13
+ readonly headers: readonly ["x-codex-turn-metadata", "thread-id"];
14
+ }, {
15
+ readonly id: "muse_code";
16
+ readonly headers: readonly ["x-client-id", "x-tbh-thread-id"];
17
+ readonly ownPlanOnly: true;
18
+ }, {
19
+ readonly id: "opencode";
20
+ readonly headers: readonly ["x-opencode-session-id", "x-opencode-parent-session-id", "x-opencode-request-kind", "x-opencode-agent", "x-session-affinity"];
21
+ }, {
22
+ readonly id: "pi";
23
+ readonly headers: readonly ["x-pi-session-id", "x-pi-request-kind"];
24
+ }, {
25
+ readonly id: "openclaw";
26
+ readonly headers: readonly [];
27
+ }, {
28
+ readonly id: "hermes";
29
+ readonly headers: readonly [];
30
+ }];
31
+ export type ClientHarness = (typeof HARNESSES)[number]["id"];
32
+ export declare const CLIENT_HARNESSES: readonly string[];
33
+ /** The agents whose own plan serves only them. */
34
+ export declare const OWN_PLAN_HARNESSES: readonly ClientHarness[];
@@ -0,0 +1,13 @@
1
+ import { claudeCode } from "./claude_code.js";
2
+ import { codex } from "./codex.js";
3
+ import { hermes } from "./hermes.js";
4
+ import { museCode } from "./muse_code.js";
5
+ import { openclaw } from "./openclaw.js";
6
+ import { opencode } from "./opencode.js";
7
+ import { pi } from "./pi.js";
8
+ export const HARNESSES = [claudeCode, codex, museCode, opencode, pi, openclaw, hermes];
9
+ export const CLIENT_HARNESSES = HARNESSES.map((harness) => harness.id);
10
+ /** The agents whose own plan serves only them. */
11
+ export const OWN_PLAN_HARNESSES = HARNESSES
12
+ .filter((harness) => "ownPlanOnly" in harness)
13
+ .map((harness) => harness.id);
@@ -0,0 +1,9 @@
1
+ import type { HarnessConversationIdentity } from "../runtime/harness_identity/conversation.js";
2
+ export declare const museCode: {
3
+ readonly id: "muse_code";
4
+ readonly headers: readonly ["x-client-id", "x-tbh-thread-id"];
5
+ readonly ownPlanOnly: true;
6
+ };
7
+ /** Muse Code's x-client-id when the request comes from Muse Code. */
8
+ export declare function museCodeClientId(headers: Headers): string | undefined;
9
+ export declare function museCodeConversationIdentity(headers: Headers): HarnessConversationIdentity | undefined;
@@ -0,0 +1,22 @@
1
+ import { boundedIdentity } from "../runtime/harness_identity/ids.js";
2
+ export const museCode = {
3
+ id: "muse_code",
4
+ headers: ["x-client-id", "x-tbh-thread-id"],
5
+ // A Muse Code plan serves only Muse Code.
6
+ ownPlanOnly: true,
7
+ };
8
+ // Muse Code names its surface (TUI, `muse exec`, desktop, `muse serve`) in
9
+ // x-client-id on every model request.
10
+ const MUSE_CODE_CLIENT_IDS = new Set(["tbh:tui", "tbh:exec", "tbh:desktop", "tbh:serve"]);
11
+ /** Muse Code's x-client-id when the request comes from Muse Code. */
12
+ export function museCodeClientId(headers) {
13
+ const clientId = headers.get("x-client-id")?.trim().toLowerCase();
14
+ return clientId !== undefined && MUSE_CODE_CLIENT_IDS.has(clientId) ? clientId : undefined;
15
+ }
16
+ // Muse Code sends its thread on every Responses request. The main agent's
17
+ // thread is its session, and each subagent has its own thread, so each keeps
18
+ // its own conversation and lease.
19
+ export function museCodeConversationIdentity(headers) {
20
+ const threadId = boundedIdentity(headers.get("x-tbh-thread-id"), "x-tbh-thread-id");
21
+ return threadId === undefined ? undefined : { kind: "muse_code_thread", value: threadId };
22
+ }
@@ -0,0 +1,4 @@
1
+ export declare const openclaw: {
2
+ readonly id: "openclaw";
3
+ readonly headers: readonly [];
4
+ };
@@ -0,0 +1,6 @@
1
+ // Sends nothing of its own that tells it apart, so the Dari CLI sets it up to
2
+ // name itself in x-dari-client-harness.
3
+ export const openclaw = {
4
+ id: "openclaw",
5
+ headers: [],
6
+ };
@@ -0,0 +1,7 @@
1
+ import type { AgentRequestContext } from "../interaction/types.js";
2
+ export declare const opencode: {
3
+ readonly id: "opencode";
4
+ readonly headers: readonly ["x-opencode-session-id", "x-opencode-parent-session-id", "x-opencode-request-kind", "x-opencode-agent", "x-session-affinity"];
5
+ };
6
+ export declare function openCodeRequestContext(headers: Headers): AgentRequestContext | undefined;
7
+ export declare function openCodeSubagentId(headers: Headers): string | undefined;
@@ -0,0 +1,40 @@
1
+ import { boundedIdentity } from "../runtime/harness_identity/ids.js";
2
+ export const opencode = {
3
+ id: "opencode",
4
+ // With the `dari opencode` plugin's request kind and agent.
5
+ headers: [
6
+ "x-opencode-session-id",
7
+ "x-opencode-parent-session-id",
8
+ "x-opencode-request-kind",
9
+ "x-opencode-agent",
10
+ "x-session-affinity",
11
+ ],
12
+ };
13
+ // OpenCode names the session behind every request, and a subagent's parent
14
+ // session too. The `dari opencode` plugin adds the request kind and agent,
15
+ // which OpenCode does not send itself. Like Claude Code's headers, these are
16
+ // client-supplied routing hints, never inferred from prompt text.
17
+ export function openCodeRequestContext(headers) {
18
+ if (boundedIdentity(headers.get("x-opencode-session-id"), "x-opencode-session-id") === undefined) {
19
+ return undefined;
20
+ }
21
+ const kind = headers.get("x-opencode-request-kind")?.trim();
22
+ const subagentId = openCodeSubagentId(headers);
23
+ const requestClass = kind === "compaction" ? "compaction"
24
+ : kind === "title" || kind === "generate" ? "auxiliary"
25
+ : subagentId === undefined ? "main" : "subagent";
26
+ return {
27
+ requestClass,
28
+ ...(subagentId === undefined ? {} : {
29
+ agentId: subagentId,
30
+ parentAgentId: boundedIdentity(headers.get("x-opencode-parent-session-id"), "x-opencode-parent-session-id"),
31
+ }),
32
+ agentType: boundedIdentity(headers.get("x-opencode-agent"), "x-opencode-agent"),
33
+ };
34
+ }
35
+ export function openCodeSubagentId(headers) {
36
+ const parent = boundedIdentity(headers.get("x-opencode-parent-session-id"), "x-opencode-parent-session-id");
37
+ return parent === undefined
38
+ ? undefined
39
+ : boundedIdentity(headers.get("x-opencode-session-id"), "x-opencode-session-id");
40
+ }
@@ -0,0 +1,6 @@
1
+ import type { AgentRequestContext } from "../interaction/types.js";
2
+ export declare const pi: {
3
+ readonly id: "pi";
4
+ readonly headers: readonly ["x-pi-session-id", "x-pi-request-kind"];
5
+ };
6
+ export declare function piRequestContext(headers: Headers): AgentRequestContext | undefined;
@@ -0,0 +1,23 @@
1
+ import { boundedIdentity } from "../runtime/harness_identity/ids.js";
2
+ export const pi = {
3
+ id: "pi",
4
+ headers: ["x-pi-session-id", "x-pi-request-kind"],
5
+ };
6
+ export function piRequestContext(headers) {
7
+ if (boundedIdentity(headers.get("x-pi-session-id"), "x-pi-session-id") === undefined) {
8
+ return undefined;
9
+ }
10
+ const kind = headers.get("x-pi-request-kind")?.trim();
11
+ return {
12
+ requestClass: kind === "turn" ? "main"
13
+ : kind === "compaction" ? "compaction"
14
+ // The Dari extension's web search tool: one request beside the turn,
15
+ // served as background work like Claude Code's own search.
16
+ : kind === "search" ? "auxiliary"
17
+ : "unknown",
18
+ };
19
+ }
20
+ // OpenCode names the session behind every request, and a subagent's parent
21
+ // session too. The `dari opencode` plugin adds the request kind and agent,
22
+ // which OpenCode does not send itself. Like Claude Code's headers, these are
23
+ // client-supplied routing hints, never inferred from prompt text.
@@ -1,6 +1,5 @@
1
- import type { ClientHarness } from "../types.js";
1
+ import { type ClientHarness } from "../harnesses/index.js";
2
2
  export declare const CLIENT_HARNESS_HEADER = "x-dari-client-harness";
3
- export declare const CLIENT_HARNESSES: readonly string[];
4
3
  /**
5
4
  * The headers of `CLIENT_HEADERS` the request carries, as the client sent
6
5
  * them, so hosted Dari serving it for a connected gateway sees the same
@@ -1,42 +1,7 @@
1
+ import { CLIENT_HARNESSES, HARNESSES, OWN_PLAN_HARNESSES } from "../harnesses/index.js";
1
2
  export const CLIENT_HARNESS_HEADER = "x-dari-client-harness";
2
- export const CLIENT_HARNESSES = [
3
- "claude_code",
4
- "codex",
5
- "muse_code",
6
- "opencode",
7
- "pi",
8
- "openclaw",
9
- "hermes",
10
- ];
11
- // The headers a coding agent describes itself and each request with: which
12
- // agent it is, its session, and what the request is for. harness_request.ts
13
- // reads every one of them.
14
- const CLIENT_HEADERS = [
15
- // Claude Code
16
- "user-agent",
17
- "x-app",
18
- "anthropic-beta",
19
- "x-claude-code-session-id",
20
- "x-claude-code-request-class",
21
- "x-claude-code-agent-id",
22
- "x-claude-code-parent-agent-id",
23
- "x-claude-code-agent-type",
24
- // Codex
25
- "x-codex-turn-metadata",
26
- "thread-id",
27
- // Muse Code
28
- "x-client-id",
29
- "x-tbh-thread-id",
30
- // OpenCode, with the `dari opencode` plugin's request kind and agent
31
- "x-opencode-session-id",
32
- "x-opencode-parent-session-id",
33
- "x-opencode-request-kind",
34
- "x-opencode-agent",
35
- "x-session-affinity",
36
- // Pi
37
- "x-pi-session-id",
38
- "x-pi-request-kind",
39
- ];
3
+ // Every coding agent's own headers. harness_request.ts reads every one of them.
4
+ const CLIENT_HEADERS = HARNESSES.flatMap((harness) => harness.headers);
40
5
  /**
41
6
  * The headers of `CLIENT_HEADERS` the request carries, as the client sent
42
7
  * them, so hosted Dari serving it for a connected gateway sees the same
@@ -66,5 +31,5 @@ export function namedClientHarness(headers) {
66
31
  */
67
32
  export function claimedClientHarness(headers) {
68
33
  const named = namedClientHarness(headers);
69
- return named === "claude_code" || named === "muse_code" ? undefined : named;
34
+ return named === undefined || OWN_PLAN_HARNESSES.includes(named) ? undefined : named;
70
35
  }
@@ -1,7 +1,10 @@
1
- import { chatCompletionsConversationIdentity, claudeCodeConversationIdentity, codexConversationIdentity, codexRequestContext, codexRequestPurpose, museCodeConversationIdentity, openCodeRequestContext, piRequestContext, } from "../runtime/harness_identity/index.js";
2
- import { claudeCodeRequestContext, isClaudeCodeRequest } from "./claude_code/request_context.js";
1
+ import { claudeCodeConversationIdentity, claudeCodeRequestContext, isClaudeCodeRequest, } from "../harnesses/claude_code.js";
2
+ import { codexConversationIdentity, codexRequestContext, codexRequestPurpose } from "../harnesses/codex.js";
3
+ import { museCodeClientId, museCodeConversationIdentity } from "../harnesses/muse_code.js";
4
+ import { openCodeRequestContext } from "../harnesses/opencode.js";
5
+ import { piRequestContext } from "../harnesses/pi.js";
6
+ import { chatCompletionsConversationIdentity, } from "../runtime/harness_identity/index.js";
3
7
  import { claimedClientHarness } from "./client_harness.js";
4
- import { museCodeClientId } from "./muse_code.js";
5
8
  /**
6
9
  * Read the coding agent from its own headers.
7
10
  *
@@ -15,6 +15,7 @@ import { modelSupportsImageInput, modelSupportsNativeCompaction } from "../provi
15
15
  import { modelMetadataLookup } from "../providers/pi.js";
16
16
  import { resolveRouter } from "../strategies/routing.js";
17
17
  import { anthropicModelsResponse } from "./anthropic_models.js";
18
+ import { OWN_PLAN_HARNESSES } from "../harnesses/index.js";
18
19
  import { namedClientHarness } from "./client_harness.js";
19
20
  import { codexModelsEtag, codexModelsResponse } from "./codex_models.js";
20
21
  import { CANONICAL_ROUTER_MODEL, explicitModelSlug, LINK_CHILD_TOKEN_PREFIX } from "../protocol/input/router_model.js";
@@ -100,7 +101,7 @@ export async function handleModels(request, routerId) {
100
101
  async function childTokenModels(routerId, apiKey) {
101
102
  if (!apiKey.startsWith(LINK_CHILD_TOKEN_PREFIX))
102
103
  return [];
103
- for (const clientHarness of ["claude_code", "muse_code"]) {
104
+ for (const clientHarness of OWN_PLAN_HARNESSES) {
104
105
  try {
105
106
  const router = await resolveRouter({ routerId, apiKey, clientHarness, provisional: true });
106
107
  return router.link_models ?? router.enabled_models;
@@ -68,6 +68,7 @@ import { budgetBody, limitsBody, spendBody, validBudget, validLimits } from "./b
68
68
  import { catalogModelFor } from "./grant_access.js";
69
69
  import { registeredRedirect } from "./grants.js";
70
70
  import { requestTags } from "../runtime/request_tags.js";
71
+ import { CLIENT_HARNESSES } from "../harnesses/index.js";
71
72
  import { parseJsonRequest } from "../ingress/json.js";
72
73
  import { DARI_MARK, ICONS, linkLogo } from "./assets.js";
73
74
  import { GEIST_WOFF2 } from "./font.js";
@@ -128,9 +129,6 @@ const CHILD_TOKEN_MAX_SECONDS = 12 * 60 * 60;
128
129
  const MAX_MODEL_CHARS = 200;
129
130
  const MAX_PURPOSE_CHARS = 200;
130
131
  const MAX_CHILD_MODELS = 16;
131
- // Clients an app can say it runs with `client` on the authorize request.
132
- // Claude Code and Muse Code plans serve only an app that runs those.
133
- const CLIENTS = ["claude_code", "codex", "muse_code", "opencode", "pi", "openclaw", "hermes"];
134
132
  const PLAN_KINDS = Object.keys(SUBSCRIPTION_PLAN_LABELS);
135
133
  // An API key, as a kind an app asks for in `plans` and reads on a grant.
136
134
  const API_KEY = "api_key";
@@ -1124,8 +1122,10 @@ async function authorizeRequest(link, params) {
1124
1122
  return badRequest(`The only scope is ${LINK_SCOPE}.`);
1125
1123
  }
1126
1124
  const clients = listParam(params.get("client"));
1127
- if (!clients.every((client) => CLIENTS.includes(client))) {
1128
- return badRequest(`client lists the clients the app runs: ${CLIENTS.join(", ")}.`);
1125
+ // The clients an app can say it runs. Claude Code and Muse Code plans serve
1126
+ // only an app that runs those.
1127
+ if (!clients.every((client) => CLIENT_HARNESSES.includes(client))) {
1128
+ return badRequest(`client lists the clients the app runs: ${CLIENT_HARNESSES.join(", ")}.`);
1129
1129
  }
1130
1130
  const plans = [...new Set(listParam(params.get("plans")).flatMap((plan) => plan === SUPPORTED ? [...SUPPORTED_KINDS] : [plan]))];
1131
1131
  if (!plans.every((plan) => OFFER_KINDS.includes(plan))) {
@@ -98,7 +98,6 @@ export function selfHostedLink(deps) {
98
98
  flow: authorization.flow,
99
99
  credentialName: null,
100
100
  owner: newSubject(),
101
- private: false,
102
101
  movingFrom: null,
103
102
  expiresAt: authorization.expiresAt,
104
103
  });
@@ -484,6 +484,7 @@ export type ResolveRouterRequest = {
484
484
  includePublicEvalCatalog?: boolean;
485
485
  clientHarness?: ClientHarness;
486
486
  clientHeaders?: Record<string, string>;
487
+ private?: boolean;
487
488
  provisional?: boolean;
488
489
  };
489
490
  export type ProviderCredentialRequest = {
@@ -563,6 +564,7 @@ export type RequestRecord = {
563
564
  credentialId: string | null;
564
565
  };
565
566
  subscriptionCredentialId?: string;
567
+ private: boolean;
566
568
  router: RequestRecordRouter;
567
569
  candidates: Array<{
568
570
  model: string;
@@ -1,3 +1,4 @@
1
1
  export declare const DEFAULT_ROUTER_ALIAS = "default";
2
2
  export declare const ROUTING_PREFIX_HASHES_MAX_COUNT = 200;
3
3
  export declare const HOSTED_DARI_PROVIDER = "dari";
4
+ export declare const PRIVATE_HEADER = "x-dari-private";
@@ -6,3 +6,7 @@ export const ROUTING_PREFIX_HASHES_MAX_COUNT = 200;
6
6
  // The provider id of hosted Dari when a gateway connected to it calls it for
7
7
  // a model, as `dari/model/<id>` with the user's Dari key.
8
8
  export const HOSTED_DARI_PROVIDER = "dari";
9
+ // A request with this header set to `true` stays out of Activity: the
10
+ // platform keeps only what billing needs. A gateway in private mode sets it on
11
+ // every request, and on each it hands hosted Dari.
12
+ export const PRIVATE_HEADER = "x-dari-private";
@@ -8,4 +8,5 @@ export declare function anthropicMessagesResponse(args: {
8
8
  request: InteractionRequest;
9
9
  routing: RoutingDecision;
10
10
  conversationId?: string;
11
+ private?: boolean;
11
12
  }): Record<string, unknown>;
@@ -11,6 +11,6 @@ export function anthropicMessagesResponse(args) {
11
11
  // As on Chat Completions. Null means unpriced, never a fabricated free request.
12
12
  usage: { ...anthropicUsage(args.output), cost: args.modelCost ?? null },
13
13
  ...(args.output.safeguardResults ? { safeguard_results: args.output.safeguardResults } : {}),
14
- dari_routing: anthropicRouting(args.routing, args.id, args.conversationId),
14
+ dari_routing: anthropicRouting(args.routing, args.id, args.conversationId, args.private),
15
15
  };
16
16
  }
@@ -7,4 +7,4 @@ export declare function anthropicReasoningBlock(item: Extract<InteractionOutput[
7
7
  }>): Record<string, unknown>;
8
8
  export declare function anthropicStopReason(output: Pick<InteractionOutput, "stopReason">): string;
9
9
  export declare function anthropicUsage(output: Pick<InteractionOutput, "usage">): Record<string, unknown>;
10
- export declare function anthropicRouting(decision: ServedDecision, requestId: string, conversationId?: string): Record<string, unknown>;
10
+ export declare function anthropicRouting(decision: ServedDecision, requestId: string, conversationId?: string, isPrivate?: boolean): Record<string, unknown>;
@@ -111,7 +111,7 @@ export function anthropicUsage(output) {
111
111
  output_tokens: output.usage.output,
112
112
  };
113
113
  }
114
- export function anthropicRouting(decision, requestId, conversationId) {
114
+ export function anthropicRouting(decision, requestId, conversationId, isPrivate) {
115
115
  return {
116
116
  requested_model: "dari/routing",
117
117
  selected_model: decision.selectedModel,
@@ -119,6 +119,8 @@ export function anthropicRouting(decision, requestId, conversationId) {
119
119
  reason: decision.reason,
120
120
  request_id: requestId,
121
121
  ...(conversationId ? { conversation_id: conversationId } : {}),
122
+ // Kept out of Activity, so no link to it there.
123
+ ...(isPrivate ? { private: true } : {}),
122
124
  ...(decision.leaseTurnsRemaining === undefined
123
125
  ? {}
124
126
  : { lease_turns_remaining: decision.leaseTurnsRemaining }),
@@ -8,6 +8,7 @@ export declare function anthropicMessagesSseStream(args: {
8
8
  source: ProviderIdentity;
9
9
  request: InteractionRequest;
10
10
  conversationId?: string;
11
+ private?: boolean;
11
12
  onFinal?: (outcome: ProviderStreamOutcome) => void;
12
13
  modelCost?: (message: Record<string, unknown>, failed: boolean) => number | null;
13
14
  beforeClose?: (outcome: ProviderStreamOutcome) => Promise<void> | void;
@@ -33,7 +33,7 @@ export function anthropicMessagesSseStream(args) {
33
33
  stop_reason: null,
34
34
  stop_sequence: null,
35
35
  usage: { input_tokens: 0, output_tokens: 0 },
36
- dari_routing: anthropicRouting(args.routing, args.id, args.conversationId),
36
+ dari_routing: anthropicRouting(args.routing, args.id, args.conversationId, args.private),
37
37
  },
38
38
  });
39
39
  const argumentDeltaIndexes = new Set();
@@ -8,6 +8,7 @@ export declare function chatCompletionResponse(args: {
8
8
  modelCost?: number | null;
9
9
  routing: RoutingDecision;
10
10
  conversationId?: string;
11
+ private?: boolean;
11
12
  }): Record<string, unknown>;
12
13
  export declare function chatCompletionsSseStream(args: {
13
14
  id: string;
@@ -17,6 +18,7 @@ export declare function chatCompletionsSseStream(args: {
17
18
  source: ProviderIdentity;
18
19
  request: InteractionRequest;
19
20
  conversationId?: string;
21
+ private?: boolean;
20
22
  onFinal?: (outcome: ProviderStreamOutcome) => void;
21
23
  modelCost?: (message: Record<string, unknown>, failed: boolean) => number | null;
22
24
  beforeClose?: (outcome: ProviderStreamOutcome) => Promise<void> | void;