@mupt-ai/dari-gateway 1.0.374 → 1.0.375

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 (42) hide show
  1. package/dist/activity/filters.d.ts +1 -1
  2. package/dist/activity/filters.js +1 -1
  3. package/dist/harnesses/antigravity.d.ts +11 -0
  4. package/dist/harnesses/antigravity.js +47 -0
  5. package/dist/harnesses/index.d.ts +3 -0
  6. package/dist/harnesses/index.js +2 -1
  7. package/dist/http/auth.d.ts +1 -0
  8. package/dist/http/auth.js +11 -0
  9. package/dist/http/handler.d.ts +1 -1
  10. package/dist/http/handler.js +16 -1
  11. package/dist/ingress/gemini.d.ts +18 -0
  12. package/dist/ingress/gemini.js +181 -0
  13. package/dist/ingress/harness_request.js +6 -2
  14. package/dist/interaction/types.d.ts +1 -1
  15. package/dist/protocol/gemini_thought_signature.d.ts +2 -0
  16. package/dist/protocol/gemini_thought_signature.js +23 -0
  17. package/dist/protocol/input/gemini_generate_content.d.ts +4 -0
  18. package/dist/protocol/input/gemini_generate_content.js +293 -0
  19. package/dist/protocol/input/router_model.d.ts +1 -0
  20. package/dist/protocol/input/router_model.js +7 -0
  21. package/dist/protocol/output/gemini_generate_content.d.ts +17 -0
  22. package/dist/protocol/output/gemini_generate_content.js +102 -0
  23. package/dist/protocol/output/gemini_generate_content_stream.d.ts +17 -0
  24. package/dist/protocol/output/gemini_generate_content_stream.js +86 -0
  25. package/dist/runtime/harness_identity/conversation.d.ts +4 -0
  26. package/dist/self_host/connected.js +14 -7
  27. package/package.json +2 -2
  28. package/src/activity/filters.ts +1 -1
  29. package/src/harnesses/antigravity.ts +50 -0
  30. package/src/harnesses/index.ts +2 -1
  31. package/src/http/auth.ts +11 -0
  32. package/src/http/handler.ts +20 -1
  33. package/src/ingress/gemini.ts +206 -0
  34. package/src/ingress/harness_request.ts +5 -1
  35. package/src/interaction/types.ts +1 -1
  36. package/src/protocol/gemini_thought_signature.ts +23 -0
  37. package/src/protocol/input/gemini_generate_content.ts +297 -0
  38. package/src/protocol/input/router_model.ts +8 -0
  39. package/src/protocol/output/gemini_generate_content.ts +108 -0
  40. package/src/protocol/output/gemini_generate_content_stream.ts +101 -0
  41. package/src/runtime/harness_identity/conversation.ts +5 -0
  42. package/src/self_host/connected.ts +14 -7
@@ -2,7 +2,7 @@ import { type Params } from "./params.js";
2
2
  import { type ActivityDb, type Sql } from "./sql.js";
3
3
  import { type Instant } from "./values.js";
4
4
  /** The source protocols Activity reads, in display order. */
5
- export declare const SUPPORTED_SOURCE_PROTOCOLS: readonly ["openai_chat", "openai_responses", "anthropic_messages"];
5
+ export declare const SUPPORTED_SOURCE_PROTOCOLS: readonly ["openai_chat", "openai_responses", "anthropic_messages", "gemini_generate_content"];
6
6
  export type SourceProtocol = (typeof SUPPORTED_SOURCE_PROTOCOLS)[number];
7
7
  /** Stands for the steps whose selector chose no model. */
8
8
  export declare const SELECTOR_UNRESOLVED_MODEL = "selector-unresolved";
@@ -4,7 +4,7 @@ import { badRequest } from "./params.js";
4
4
  import { and, or, raw, sql } from "./sql.js";
5
5
  import { canonicalInstant, formatInstant, readInt } from "./values.js";
6
6
  /** The source protocols Activity reads, in display order. */
7
- export const SUPPORTED_SOURCE_PROTOCOLS = ["openai_chat", "openai_responses", "anthropic_messages"];
7
+ export const SUPPORTED_SOURCE_PROTOCOLS = ["openai_chat", "openai_responses", "anthropic_messages", "gemini_generate_content"];
8
8
  /** Stands for the steps whose selector chose no model. */
9
9
  export const SELECTOR_UNRESOLVED_MODEL = "selector-unresolved";
10
10
  /** A step's model, under the alias `r`: `SELECTOR_UNRESOLVED_MODEL` when its selector chose none. */
@@ -0,0 +1,11 @@
1
+ import type { HarnessConversationIdentity } from "../runtime/harness_identity/conversation.js";
2
+ export declare const antigravity: {
3
+ readonly id: "antigravity";
4
+ readonly headers: readonly [];
5
+ };
6
+ /**
7
+ * Antigravity's conversation, from its system prompt in whichever API
8
+ * carries it: Gemini's from the agent, or Anthropic's or Responses when a
9
+ * connected gateway has hosted Dari serve the model.
10
+ */
11
+ export declare function antigravityConversationIdentity(payload: Record<string, unknown>): HarnessConversationIdentity | undefined;
@@ -0,0 +1,47 @@
1
+ import { isRecord } from "@mupt-ai/dari-router/policy-engine";
2
+ // Antigravity (the CLI under `dari agy`, and the desktop app) sends no header
3
+ // of its own: the gateway tells it apart by its system prompt.
4
+ export const antigravity = {
5
+ id: "antigravity",
6
+ headers: [],
7
+ };
8
+ // Its system prompt names its app data directory (`antigravity-cli` for the
9
+ // CLI, `antigravity` for the desktop app) and the conversation.
10
+ const ANTIGRAVITY_CONVERSATION = /App Data Directory: [^\n]*antigravity[^\n]*\s+Conversation ID: ([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})/;
11
+ /**
12
+ * Antigravity's conversation, from its system prompt in whichever API
13
+ * carries it: Gemini's from the agent, or Anthropic's or Responses when a
14
+ * connected gateway has hosted Dari serve the model.
15
+ */
16
+ export function antigravityConversationIdentity(payload) {
17
+ for (const text of systemTexts(payload)) {
18
+ const match = ANTIGRAVITY_CONVERSATION.exec(text);
19
+ if (match !== null)
20
+ return { kind: "antigravity_conversation", value: match[1] };
21
+ }
22
+ return undefined;
23
+ }
24
+ function systemTexts(payload) {
25
+ const texts = [];
26
+ const add = (value) => {
27
+ if (typeof value === "string")
28
+ texts.push(value);
29
+ else if (Array.isArray(value))
30
+ for (const part of value)
31
+ if (isRecord(part) && typeof part.text === "string")
32
+ texts.push(part.text);
33
+ };
34
+ // Gemini's systemInstruction, Anthropic's system, and the Responses API's
35
+ // instructions or system and developer messages.
36
+ if (isRecord(payload.systemInstruction))
37
+ add(payload.systemInstruction.parts);
38
+ add(payload.system);
39
+ add(payload.instructions);
40
+ if (Array.isArray(payload.input)) {
41
+ for (const item of payload.input) {
42
+ if (isRecord(item) && (item.role === "system" || item.role === "developer"))
43
+ add(item.content);
44
+ }
45
+ }
46
+ return texts;
47
+ }
@@ -27,6 +27,9 @@ export declare const HARNESSES: readonly [{
27
27
  }, {
28
28
  readonly id: "hermes";
29
29
  readonly headers: readonly [];
30
+ }, {
31
+ readonly id: "antigravity";
32
+ readonly headers: readonly [];
30
33
  }];
31
34
  export type ClientHarness = (typeof HARNESSES)[number]["id"];
32
35
  export declare const CLIENT_HARNESSES: readonly string[];
@@ -1,3 +1,4 @@
1
+ import { antigravity } from "./antigravity.js";
1
2
  import { claudeCode } from "./claude_code.js";
2
3
  import { codex } from "./codex.js";
3
4
  import { hermes } from "./hermes.js";
@@ -5,7 +6,7 @@ import { museCode } from "./muse_code.js";
5
6
  import { openclaw } from "./openclaw.js";
6
7
  import { opencode } from "./opencode.js";
7
8
  import { pi } from "./pi.js";
8
- export const HARNESSES = [claudeCode, codex, museCode, opencode, pi, openclaw, hermes];
9
+ export const HARNESSES = [claudeCode, codex, museCode, opencode, pi, openclaw, hermes, antigravity];
9
10
  export const CLIENT_HARNESSES = HARNESSES.map((harness) => harness.id);
10
11
  /** The agents whose own plan serves only them. */
11
12
  export const OWN_PLAN_HARNESSES = HARNESSES
@@ -1,2 +1,3 @@
1
1
  export declare function bearerToken(headers: Headers): string;
2
2
  export declare function anthropicToken(headers: Headers): string;
3
+ export declare function geminiToken(headers: Headers): string;
package/dist/http/auth.js CHANGED
@@ -18,6 +18,17 @@ export function anthropicToken(headers) {
18
18
  }
19
19
  return publicRoutingToken(apiKey);
20
20
  }
21
+ // Gemini clients send `x-goog-api-key`, or a bearer token when
22
+ // GEMINI_API_KEY_AUTH_MECHANISM=bearer.
23
+ export function geminiToken(headers) {
24
+ if (headers.get("authorization"))
25
+ return bearerToken(headers);
26
+ const apiKey = headers.get("x-goog-api-key");
27
+ if (!apiKey) {
28
+ throw new HttpError(401, "Missing or invalid API key.", "authentication_error");
29
+ }
30
+ return publicRoutingToken(apiKey);
31
+ }
21
32
  function publicRoutingToken(token) {
22
33
  const internalToken = process.env.DARI_ROUTING_INTERNAL_TOKEN;
23
34
  if (internalToken && matchesInternalToken(token, internalToken)) {
@@ -6,7 +6,7 @@ export type GatewayHandlerOptions = {
6
6
  };
7
7
  /**
8
8
  * The gateway's routed HTTP surface: `/v1/{chat/completions,responses,
9
- * messages,models}` on the default router and `/{router_id}/v1/...` on a
9
+ * messages,models}` and Gemini's `/v1beta/models` and `/v1beta/models/{model}:{method}` on the default router and `/{router_id}/v1/...` on a
10
10
  * named one, the Dari CLI's commit reports at `/v1/dari/git-events` on
11
11
  * either, the Dari Link grant endpoints under `/v1/link/`, and the Activity
12
12
  * reads under `/v1/organizations/{organization}/routing/activity/`. Binds
@@ -6,12 +6,13 @@ import { handleModels } from "../ingress/models.js";
6
6
  import { handleMuseCodeModels } from "../ingress/muse_models.js";
7
7
  import { handleChatCompletions } from "../ingress/chat_completions.js";
8
8
  import { anthropicErrorResponse, handleAnthropicMessages } from "../ingress/anthropic_messages.js";
9
+ import { handleGeminiModels, handleGeminiRequest } from "../ingress/gemini.js";
9
10
  import { bindGatewayPlatform } from "../platform/platform.js";
10
11
  import { DEFAULT_ROUTER_ALIAS } from "../platform/routing_contract.js";
11
12
  import { errorResponse, HttpError } from "./errors.js";
12
13
  /**
13
14
  * The gateway's routed HTTP surface: `/v1/{chat/completions,responses,
14
- * messages,models}` on the default router and `/{router_id}/v1/...` on a
15
+ * messages,models}` and Gemini's `/v1beta/models` and `/v1beta/models/{model}:{method}` on the default router and `/{router_id}/v1/...` on a
15
16
  * named one, the Dari CLI's commit reports at `/v1/dari/git-events` on
16
17
  * either, the Dari Link grant endpoints under `/v1/link/`, and the Activity
17
18
  * reads under `/v1/organizations/{organization}/routing/activity/`. Binds
@@ -47,6 +48,20 @@ export function createRequestHandler(options) {
47
48
  if (request.method === "POST" && gitEvents !== null) {
48
49
  return await handleGitEvents(request, gitEvents[1] ?? DEFAULT_ROUTER_ALIAS, options.platform.activity);
49
50
  }
51
+ // Gemini CLI: `{base}/v1beta/models/{model}:{method}`, where the model may
52
+ // hold slashes, raw or percent-encoded.
53
+ const gemini = url.pathname.match(/^(?:\/([^/]+))?\/v1beta\/models\/(.+):(generateContent|streamGenerateContent|countTokens)$/);
54
+ if (request.method === "POST" && gemini !== null) {
55
+ return await handleGeminiRequest(request, {
56
+ routerId: gemini[1] ?? DEFAULT_ROUTER_ALIAS,
57
+ model: decodeURIComponent(gemini[2]),
58
+ method: gemini[3],
59
+ }, selectorBackend);
60
+ }
61
+ const geminiModels = url.pathname.match(/^(?:\/([^/]+))?\/v1beta\/models$/);
62
+ if (request.method === "GET" && geminiModels !== null) {
63
+ return await handleGeminiModels(request, geminiModels[1] ?? DEFAULT_ROUTER_ALIAS);
64
+ }
50
65
  const endpoint = routedEndpoint(url.pathname);
51
66
  if (endpoint !== null) {
52
67
  // Browsers send Origin on every cross-origin call; a request without
@@ -0,0 +1,18 @@
1
+ import { type SelectorBackend } from "../strategies/routing.js";
2
+ import type { ResolvedRouter } from "../types.js";
3
+ export type GeminiRoute = {
4
+ routerId: string;
5
+ model: string;
6
+ method: "generateContent" | "streamGenerateContent" | "countTokens";
7
+ };
8
+ export declare function handleGeminiRequest(request: Request, route: GeminiRoute, selectorBackend: SelectorBackend): Promise<Response>;
9
+ /**
10
+ * The Gemini API's model list. Antigravity CLI reads it from its model
11
+ * gateway and offers these models and no others: `dari/routing` when the
12
+ * router routes, then each of its models at each thinking level it serves. It
13
+ * keeps a conversation within `inputTokenLimit` less `outputTokenLimit`, the
14
+ * output it asks for, and asks a model not marked `thinking` for none.
15
+ */
16
+ export declare function geminiModelsResponse(router: Pick<ResolvedRouter, "enabled_models" | "model_configs" | "model_thinking_levels" | "allow_long_context" | "autorouting_enabled" | "routing_listed">): Record<string, unknown>;
17
+ export declare function handleGeminiModels(request: Request, routerId: string): Promise<Response>;
18
+ export declare function geminiErrorResponse(error: unknown): Response;
@@ -0,0 +1,181 @@
1
+ import { geminiToken } from "../http/auth.js";
2
+ import { errorResponseHeaders, normalizeError } from "../http/errors.js";
3
+ import { LINK_GRANT_ERROR_CODES, LINK_TOKEN_ERROR_CODES } from "../link/errors.js";
4
+ import { captureRequestError } from "../observability/errors.js";
5
+ import { geminiGenerateContentToInteraction } from "../protocol/input/gemini_generate_content.js";
6
+ import { listedContextWindow } from "../models/context_limits.js";
7
+ import { CANONICAL_ROUTER_MODEL, explicitModelId, explicitModelSlug, linkTokenModel } from "../protocol/input/router_model.js";
8
+ import { geminiGenerateContentResponse } from "../protocol/output/gemini_generate_content.js";
9
+ import { geminiGenerateContentSseStream } from "../protocol/output/gemini_generate_content_stream.js";
10
+ import { modelMetadataLookup } from "../providers/pi.js";
11
+ import { handleRoutedCompletion } from "../runtime/routed_completion.js";
12
+ import { resolveRouter } from "../strategies/routing.js";
13
+ import { namedClientHarness } from "./client_harness.js";
14
+ import { harnessRequest } from "./harness_request.js";
15
+ import { parseJsonRequest } from "./json.js";
16
+ export async function handleGeminiRequest(request, route, selectorBackend) {
17
+ try {
18
+ const apiKey = geminiToken(request.headers);
19
+ const rawPayload = await parseJsonRequest(request);
20
+ if (route.method === "countTokens")
21
+ return Response.json({ totalTokens: estimatedTokens(rawPayload) });
22
+ const named = modelAtLevel(route.model);
23
+ const model = String(linkTokenModel(apiKey, named.model));
24
+ const interaction = geminiGenerateContentToInteraction({ ...rawPayload, model }, {
25
+ stream: route.method === "streamGenerateContent",
26
+ });
27
+ const harness = harnessRequest(request.headers, {
28
+ sourceProtocol: "gemini_generate_content",
29
+ payload: rawPayload,
30
+ promptCacheKey: interaction.promptCacheKey,
31
+ });
32
+ // The client's thinking settings describe one Gemini model; when the
33
+ // router routes, Dari picks the effort. A level in the model's name is
34
+ // the one the user picked, whatever thinking budget comes with it.
35
+ const reasoning = explicitModelId(interaction.model) === null ? undefined
36
+ : named.effort === undefined ? interaction.reasoning : { effort: named.effort, enabled: true };
37
+ const payload = {
38
+ ...interaction,
39
+ reasoning,
40
+ ...(harness.agentContext === undefined ? {} : { agentContext: harness.agentContext }),
41
+ ...(harness.requestPurpose === undefined ? {} : { requestPurpose: harness.requestPurpose }),
42
+ };
43
+ return await handleRoutedCompletion({
44
+ request,
45
+ routerId: route.routerId,
46
+ apiKey,
47
+ payload,
48
+ responseBody: geminiGenerateContentResponse,
49
+ streamBody: geminiGenerateContentSseStream,
50
+ errorResponse: geminiErrorResponse,
51
+ selectorBackend,
52
+ clientHarness: harness.clientHarness,
53
+ harnessConversationIdentity: harness.conversationIdentity,
54
+ });
55
+ }
56
+ catch (error) {
57
+ const response = geminiErrorResponse(error);
58
+ captureRequestError(error, {
59
+ request,
60
+ routerId: route.routerId,
61
+ sourceProtocol: "gemini_generate_content",
62
+ status: response.status,
63
+ });
64
+ return response;
65
+ }
66
+ }
67
+ // Antigravity CLI's own output limit, which it uses for a model that states
68
+ // none, and the least it accepts for the conversation: a model's window less
69
+ // the output it asks for.
70
+ const ANTIGRAVITY_OUTPUT_TOKENS = 64_000;
71
+ const ANTIGRAVITY_CONVERSATION_TOKENS = 20_000;
72
+ /* Antigravity CLI changes a model's thinking level only between models whose
73
+ names end in its own levels, as `dari/model/<id>-high` shown as
74
+ `<id> (High)`: it lists them as one model with an effort gauge in /model
75
+ and /effort, and shows the level beside the model. */
76
+ const ANTIGRAVITY_LEVELS = { low: "Low", medium: "Medium", high: "High", xhigh: "XHigh", max: "Max" };
77
+ const MODEL_AT_LEVEL = new RegExp(`^(.+)-(${Object.keys(ANTIGRAVITY_LEVELS).join("|")})$`);
78
+ // The `dari/model/<id>` and thinking level a name from the model list holds.
79
+ function modelAtLevel(model) {
80
+ const match = explicitModelId(model) === null ? null : MODEL_AT_LEVEL.exec(model);
81
+ return match === null ? { model } : { model: match[1], effort: match[2] };
82
+ }
83
+ /**
84
+ * The Gemini API's model list. Antigravity CLI reads it from its model
85
+ * gateway and offers these models and no others: `dari/routing` when the
86
+ * router routes, then each of its models at each thinking level it serves. It
87
+ * keeps a conversation within `inputTokenLimit` less `outputTokenLimit`, the
88
+ * output it asks for, and asks a model not marked `thinking` for none.
89
+ */
90
+ export function geminiModelsResponse(router) {
91
+ const metadata = modelMetadataLookup(router.model_configs);
92
+ const limits = (model) => {
93
+ const { model: known, supportedThinkingLevels } = metadata(model);
94
+ const enabled = router.model_thinking_levels?.[model] ?? supportedThinkingLevels;
95
+ return {
96
+ input: listedContextWindow(router, [model]),
97
+ output: Number(known.maxTokens),
98
+ levels: supportedThinkingLevels.filter((level) => level !== "off" && enabled.includes(level)),
99
+ };
100
+ };
101
+ // Routing lists its largest model's window, as it serves a long conversation on the models that fit it.
102
+ const listed = (id, displayName, models) => {
103
+ const served = models.map(limits);
104
+ const input = Math.max(...served.map(({ input }) => input));
105
+ return {
106
+ name: `models/${id}`,
107
+ displayName,
108
+ ...(served.length === 0 ? {} : {
109
+ inputTokenLimit: input,
110
+ // A small window gives up output to leave room for the conversation.
111
+ outputTokenLimit: Math.max(1, Math.min(ANTIGRAVITY_OUTPUT_TOKENS, input - ANTIGRAVITY_CONVERSATION_TOKENS, ...served.map(({ output }) => output))),
112
+ }),
113
+ thinking: served.length === 0 || served.some(({ levels }) => levels.length > 0),
114
+ };
115
+ };
116
+ return {
117
+ models: [
118
+ ...(router.autorouting_enabled === false || router.routing_listed === false ? [] : [listed(CANONICAL_ROUTER_MODEL, "Dari Routing", router.enabled_models)]),
119
+ ...router.enabled_models.flatMap((model) => {
120
+ // Antigravity starts on the first model listed when its saved pick is
121
+ // not one of these, so each model's medium level comes first.
122
+ const levels = Object.entries(ANTIGRAVITY_LEVELS)
123
+ .filter(([level]) => limits(model).levels.includes(level))
124
+ .sort(([a], [b]) => Number(b === "medium") - Number(a === "medium"));
125
+ return levels.length === 0
126
+ ? [listed(explicitModelSlug(model), model, [model])]
127
+ : levels.map(([level, label]) => listed(`${explicitModelSlug(model)}-${level}`, `${model} (${label})`, [model]));
128
+ }),
129
+ ],
130
+ };
131
+ }
132
+ export async function handleGeminiModels(request, routerId) {
133
+ try {
134
+ // The Dari CLI names the agent it launched, whose models the router may set apart.
135
+ const clientHarness = namedClientHarness(request.headers);
136
+ const router = await resolveRouter({
137
+ routerId,
138
+ apiKey: geminiToken(request.headers),
139
+ ...(clientHarness ? { clientHarness } : {}),
140
+ });
141
+ return Response.json(geminiModelsResponse(router), { headers: { "Cache-Control": "no-store" } });
142
+ }
143
+ catch (error) {
144
+ return geminiErrorResponse(error);
145
+ }
146
+ }
147
+ // The gateway counts no tokens; Gemini CLI only needs a size for non-text
148
+ // parts, so this is the usual four characters per token.
149
+ function estimatedTokens(payload) {
150
+ return Math.ceil(JSON.stringify(payload.contents ?? []).length / 4);
151
+ }
152
+ // Dari-specific codes clients act on; every other code stays internal.
153
+ const CLIENT_VISIBLE_ERROR_CODES = new Set([
154
+ ...LINK_GRANT_ERROR_CODES,
155
+ ...LINK_TOKEN_ERROR_CODES,
156
+ "personal_subscription_unavailable",
157
+ "subscription_switched",
158
+ "subscription_usage_limit",
159
+ ]);
160
+ export function geminiErrorResponse(error) {
161
+ const { status, message, code } = normalizeError(error);
162
+ return Response.json({
163
+ error: {
164
+ code: status,
165
+ message,
166
+ status: geminiStatus(status),
167
+ ...(CLIENT_VISIBLE_ERROR_CODES.has(code) ? { dari_code: code } : {}),
168
+ },
169
+ }, { status, headers: errorResponseHeaders(error) });
170
+ }
171
+ function geminiStatus(status) {
172
+ switch (status) {
173
+ case 400: return "INVALID_ARGUMENT";
174
+ case 401: return "UNAUTHENTICATED";
175
+ case 403: return "PERMISSION_DENIED";
176
+ case 404: return "NOT_FOUND";
177
+ case 429: return "RESOURCE_EXHAUSTED";
178
+ case 503: return "UNAVAILABLE";
179
+ default: return status >= 500 ? "INTERNAL" : "INVALID_ARGUMENT";
180
+ }
181
+ }
@@ -1,3 +1,4 @@
1
+ import { antigravityConversationIdentity } from "../harnesses/antigravity.js";
1
2
  import { claudeCodeConversationIdentity, claudeCodeRequestContext, isClaudeCodeRequest, } from "../harnesses/claude_code.js";
2
3
  import { codexConversationIdentity, codexRequestContext, codexRequestPurpose } from "../harnesses/codex.js";
3
4
  import { museCodeClientId, museCodeConversationIdentity } from "../harnesses/muse_code.js";
@@ -39,17 +40,20 @@ export function harnessRequest(headers, body) {
39
40
  const session = chat || piContext !== undefined || openCodeContext !== undefined
40
41
  ? chatCompletionsConversationIdentity(headers, chat ? body.promptCacheKey : undefined)
41
42
  : undefined;
43
+ const antigravity = chat || codexContext !== undefined ? undefined : antigravityConversationIdentity(body.payload);
42
44
  const conversationIdentity = chat ? session
43
45
  : codexConversationIdentity(headers, body.payload)
44
46
  ?? (museClientId === undefined ? undefined : museCodeConversationIdentity(headers))
45
- ?? session;
47
+ ?? session
48
+ ?? antigravity;
46
49
  // OpenClaw and Hermes send nothing of their own that tells them apart, so
47
50
  // the Dari CLI sets them up to name themselves.
48
51
  const clientHarness = museClientId !== undefined ? "muse_code"
49
52
  : codexContext !== undefined ? "codex"
50
53
  : piContext !== undefined ? "pi"
51
54
  : openCodeContext !== undefined ? "opencode"
52
- : claimedClientHarness(headers);
55
+ : antigravity !== undefined ? "antigravity"
56
+ : claimedClientHarness(headers);
53
57
  return {
54
58
  ...(clientHarness === undefined ? {} : { clientHarness }),
55
59
  ...(agentContext === undefined ? {} : { agentContext }),
@@ -1,7 +1,7 @@
1
1
  import type { ReasoningEffort } from "@mupt-ai/dari-router/policy-engine";
2
2
  export type { ProviderIdentity, ProviderContinuationState, } from "@mupt-ai/dari-router/protocols";
3
3
  import type { ProviderContinuationState, ProviderIdentity } from "@mupt-ai/dari-router/protocols";
4
- export type SourceProtocol = "anthropic_messages" | "openai_chat" | "openai_responses";
4
+ export type SourceProtocol = "anthropic_messages" | "openai_chat" | "openai_responses" | "gemini_generate_content";
5
5
  export type AgentRequestClass = "main" | "subagent" | "workflow" | "auxiliary" | "compaction" | "side_reply" | "unknown";
6
6
  export type AgentRequestContext = {
7
7
  requestClass: AgentRequestClass;
@@ -0,0 +1,2 @@
1
+ export declare function encodeGeminiThoughtSignature(states: readonly string[]): string;
2
+ export declare function decodeGeminiThoughtSignature(signature: string): string[] | null;
@@ -0,0 +1,23 @@
1
+ /* Gemini clients hand back a part's `thoughtSignature` verbatim on the next
2
+ turn. Dari puts the turn's reasoning state there: each reasoning item's
3
+ continuation envelope (or portable state), as a JSON array behind a prefix
4
+ that tells it apart from Google's own signatures. The field is bytes, which
5
+ clients such as Antigravity CLI parse, so the whole value is base64. */
6
+ const PREFIX = "dari_reasoning:";
7
+ export function encodeGeminiThoughtSignature(states) {
8
+ return Buffer.from(PREFIX + JSON.stringify(states)).toString("base64");
9
+ }
10
+ // Null for any signature Dari did not write, including the clients' synthetic
11
+ // `skip_thought_signature_validator`.
12
+ export function decodeGeminiThoughtSignature(signature) {
13
+ const decoded = Buffer.from(signature, "base64").toString("utf8");
14
+ if (!decoded.startsWith(PREFIX))
15
+ return null;
16
+ try {
17
+ const states = JSON.parse(decoded.slice(PREFIX.length));
18
+ return Array.isArray(states) && states.every((state) => typeof state === "string") ? states : null;
19
+ }
20
+ catch {
21
+ return null;
22
+ }
23
+ }
@@ -0,0 +1,4 @@
1
+ import type { InteractionRequest } from "../../interaction/types.js";
2
+ export declare function geminiGenerateContentToInteraction(payload: Record<string, unknown>, args: {
3
+ stream: boolean;
4
+ }): InteractionRequest;