@kingsoftcloud/agentkit-harness-node 0.0.11 → 0.0.12

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/dist/index.mjs CHANGED
@@ -2001,16 +2001,21 @@ function applyAnthropicThinking(payload, profile, binding) {
2001
2001
  }
2002
2002
  function resolveProviderCompatibility(policy, binding) {
2003
2003
  if (!policy) return null;
2004
- if (!["provider-compat/v1", "provider-compat/v2"].includes(policy.contract)) throw new ProtocolError("invalid_provider_compatibility_policy");
2004
+ if (!["provider-compat/v1", "provider-compat/v2", "provider-compat/v3"].includes(policy.contract)) throw new ProtocolError("invalid_provider_compatibility_policy");
2005
2005
  const rule = resolveCompatibilityRule(policy.rule, binding);
2006
2006
  const name = String(binding.model ?? "").trim().toLowerCase();
2007
2007
  const kimi = ["kspmas-gateway", "moonshot"].includes(rule) && ["kimi-k2.7-code", "kimi-k2.7-code-highspeed"].includes(name);
2008
- const disabledEfforts = mandatory.has(name) ? [] : name === "claude-haiku-5-5" ? ["low", "medium", "high"] : null;
2008
+ const reasoningRequired = policy.contract === "provider-compat/v3" && rule === "kspmas-gateway" && name === "glm-5.3-flash";
2009
+ const disabledEfforts = mandatory.has(name) || reasoningRequired ? [] : name === "claude-haiku-5-5" ? ["low", "medium", "high"] : null;
2009
2010
  return {
2010
2011
  rule,
2011
2012
  supportsUsage: !strict.has(rule),
2012
2013
  supportsThinking: !strict.has(rule) && !kimi,
2013
- supportsToolArgumentStreaming: policy.contract === "provider-compat/v2" && ["zai", "kspmas-gateway"].includes(rule) && incrementalToolModels.has(normalized(binding.model)),
2014
+ supportsToolArgumentStreaming: ["provider-compat/v2", "provider-compat/v3"].includes(policy.contract) && ["zai", "kspmas-gateway"].includes(rule) && incrementalToolModels.has(normalized(binding.model)),
2015
+ reasoningRequired,
2016
+ modern: policy.contract === "provider-compat/v3",
2017
+ // Only the observed provider/model dialects may seal without [DONE].
2018
+ finishOnEof: policy.contract === "provider-compat/v3" && ["permissive", "kspmas-gateway"].includes(rule) && ["minimax-m3", "minimax-m2.5"].includes(name),
2014
2019
  supportsEffort: !kimi,
2015
2020
  toolThinkingOff: ["zai", "kspmas-gateway"].includes(rule) && !kimi,
2016
2021
  thinkingBudget: rule === "zai" && !kimi && !disabledEfforts ? 32e3 : null,
@@ -2052,6 +2057,7 @@ function applyProviderChatCompatibility(payload, request, binding) {
2052
2057
  let effort = requested;
2053
2058
  if (requested === null && options.controllerReasoningPolicy === "disclosed-delegate/v1" && ["zai", "kspmas-gateway"].includes(compat.rule) && name.startsWith("glm-5.3") && result.tools?.some((tool) => tool.type === "function" && tool.function?.name === "delegate_task")) effort = "low";
2054
2059
  if (requested === null && request.purpose === "compaction" && compat.rule === "kspmas-gateway" && ["glm-5.2", "deepseek-v4-flash"].includes(name)) effort = "none";
2060
+ if (requested === null && request.purpose === "compaction" && compat.reasoningRequired) effort = "low";
2055
2061
  effort = compat.supportsEffort ? clampReasoningEffort(model, effort) : null;
2056
2062
  if (effort !== null) result.reasoning_effort = effort;
2057
2063
  if (result.stream) result.stream_options = { ...object(result.stream_options) ? result.stream_options : {}, include_usage: true };
@@ -2061,6 +2067,7 @@ function applyProviderChatCompatibility(payload, request, binding) {
2061
2067
  if (!Object.keys(result.stream_options).length) delete result.stream_options;
2062
2068
  }
2063
2069
  const mode = options.thinkingMode ?? result.thinking?.type;
2070
+ if (mode === "disabled" && compat.reasoningRequired) throw new ProtocolError("model_thinking_disable_unsupported");
2064
2071
  const mayDisable = compat.supportsThinking && (compat.disabledEfforts === null || compat.disabledEfforts.includes(effort));
2065
2072
  const summaryOff = request.purpose === "compaction" && requested === null && compat.rule === "kspmas-gateway" && name === "glm-5.3-flash";
2066
2073
  const budget = result.max_completion_tokens ?? result.max_tokens;
@@ -2070,6 +2077,9 @@ function applyProviderChatCompatibility(payload, request, binding) {
2070
2077
  } else if (mayDisable && (mode === "disabled" || summaryOff || compat.toolThinkingOff && !!result.tools?.length && result.tool_choice !== "none" || compat.thinkingBudget !== null && budget <= compat.thinkingBudget)) result.thinking = { type: "disabled" };
2071
2078
  if (!compat.supportsThinking) delete result.thinking;
2072
2079
  if (!compat.supportsEffort) delete result.reasoning_effort;
2080
+ if (compat.modern && ["moonshot", "kspmas-gateway"].includes(compat.rule) && result.tools) {
2081
+ result.tools = result.tools.map((tool) => tool.type === "function" && tool.function?.parameters ? { ...tool, function: { ...tool.function, parameters: explicitLiteralTypes(tool.function.parameters) } } : tool);
2082
+ }
2073
2083
  if (result.tool_choice !== void 0) result.tool_choice = projectProviderToolChoice(result.tool_choice, compat);
2074
2084
  if (compat.echo === "strip" || compat.echo === "thinking" && !compat.hints.some((hint) => normalized(model).includes(hint))) {
2075
2085
  result.messages = result.messages.map((message) => {
@@ -2081,6 +2091,25 @@ function applyProviderChatCompatibility(payload, request, binding) {
2081
2091
  }
2082
2092
  return result;
2083
2093
  }
2094
+ function explicitLiteralTypes(schema) {
2095
+ if (!object(schema)) return schema;
2096
+ const result = { ...schema };
2097
+ if (result.type === void 0 && (Object.hasOwn(result, "const") || Array.isArray(result.enum))) {
2098
+ const values = Object.hasOwn(result, "const") ? [result.const] : result.enum;
2099
+ const types = new Set(values.map((value) => value === null ? "null" : typeof value));
2100
+ if (types.size === 1 && ["string", "number", "boolean", "null"].includes([...types][0])) result.type = [...types][0];
2101
+ }
2102
+ for (const key of ["properties", "patternProperties", "$defs", "definitions", "dependentSchemas"]) {
2103
+ if (object(result[key])) result[key] = Object.fromEntries(Object.entries(result[key]).map(([name, value]) => [name, explicitLiteralTypes(value)]));
2104
+ }
2105
+ for (const key of ["items", "additionalProperties", "contains", "not", "if", "then", "else", "propertyNames"]) {
2106
+ if (object(result[key])) result[key] = explicitLiteralTypes(result[key]);
2107
+ }
2108
+ for (const key of ["allOf", "anyOf", "oneOf", "prefixItems"]) {
2109
+ if (Array.isArray(result[key])) result[key] = result[key].map(explicitLiteralTypes);
2110
+ }
2111
+ return result;
2112
+ }
2084
2113
 
2085
2114
  // packages/agentkit-harness-node/src/native/model-chat-usage.mjs
2086
2115
  var CUMULATIVE_CHAT_USAGE = "cumulative-snapshots/v1";
@@ -2410,6 +2439,9 @@ function chatReasoning(message) {
2410
2439
  return native || alias || "";
2411
2440
  }
2412
2441
  function createOpenAIStreamTurn(profile, binding) {
2442
+ const compatibility = resolveProviderCompatibility(profile.providerCompatibilityPolicy, binding);
2443
+ const modern = compatibility?.modern === true;
2444
+ const finishOnEof = compatibility?.finishOnEof === true;
2413
2445
  const captureReplay = profile.providerReplayMode !== "none";
2414
2446
  const emitThinking = profile.providerThinkingDisplay ?? profile.providerReplayMode !== "none";
2415
2447
  const marker = inlineReasoningMarker(profile.inlineReasoningPolicy, binding);
@@ -2532,7 +2564,7 @@ function createOpenAIStreamTurn(profile, binding) {
2532
2564
  for (const field of ["id", "type"]) {
2533
2565
  if (field in fragment) {
2534
2566
  const value = fragment[field];
2535
- if (value == null) continue;
2567
+ if (value == null || modern && value === "") continue;
2536
2568
  if (typeof value !== "string" || !value || call[field] != null && call[field] !== value) {
2537
2569
  throw new ProtocolError("conflicting tool identity", "identity_conflict");
2538
2570
  }
@@ -2588,7 +2620,7 @@ function createOpenAIStreamTurn(profile, binding) {
2588
2620
  ...failureKind ? { failureKind } : {}
2589
2621
  };
2590
2622
  }
2591
- if (errorKind === "provider_retryable_error" || !this.done) {
2623
+ if (errorKind === "provider_retryable_error" || !this.done && !(finishOnEof && this.finish != null && this.usageAtFinish && !this.usageConflict)) {
2592
2624
  const normalized3 = normalizeResponse({ text: this.text, toolCalls: [], finishReason: finish, streamComplete: false });
2593
2625
  if (normalized3.kind === "provider_retryable_error") {
2594
2626
  return { ...normalized3, usage, usageReported, failureKind: failureKind || "incomplete_response" };
@@ -2609,6 +2641,7 @@ function createOpenAIStreamTurn(profile, binding) {
2609
2641
  try {
2610
2642
  if (this.malformedTools) throw new ProtocolError("malformed tool fragments");
2611
2643
  calls = this.buildCalls();
2644
+ if (!this.done && calls.some((call) => call.wireArgumentsInvalid)) throw new ProtocolError("unfinished EOF tool arguments");
2612
2645
  } catch {
2613
2646
  calls = [{}];
2614
2647
  }
@@ -2012,16 +2012,21 @@ function applyAnthropicThinking(payload, profile, binding) {
2012
2012
  }
2013
2013
  function resolveProviderCompatibility(policy, binding) {
2014
2014
  if (!policy) return null;
2015
- if (!["provider-compat/v1", "provider-compat/v2"].includes(policy.contract)) throw new ProtocolError("invalid_provider_compatibility_policy");
2015
+ if (!["provider-compat/v1", "provider-compat/v2", "provider-compat/v3"].includes(policy.contract)) throw new ProtocolError("invalid_provider_compatibility_policy");
2016
2016
  const rule = resolveCompatibilityRule(policy.rule, binding);
2017
2017
  const name = String(binding.model ?? "").trim().toLowerCase();
2018
2018
  const kimi = ["kspmas-gateway", "moonshot"].includes(rule) && ["kimi-k2.7-code", "kimi-k2.7-code-highspeed"].includes(name);
2019
- const disabledEfforts = mandatory.has(name) ? [] : name === "claude-haiku-5-5" ? ["low", "medium", "high"] : null;
2019
+ const reasoningRequired = policy.contract === "provider-compat/v3" && rule === "kspmas-gateway" && name === "glm-5.3-flash";
2020
+ const disabledEfforts = mandatory.has(name) || reasoningRequired ? [] : name === "claude-haiku-5-5" ? ["low", "medium", "high"] : null;
2020
2021
  return {
2021
2022
  rule,
2022
2023
  supportsUsage: !strict.has(rule),
2023
2024
  supportsThinking: !strict.has(rule) && !kimi,
2024
- supportsToolArgumentStreaming: policy.contract === "provider-compat/v2" && ["zai", "kspmas-gateway"].includes(rule) && incrementalToolModels.has(normalized(binding.model)),
2025
+ supportsToolArgumentStreaming: ["provider-compat/v2", "provider-compat/v3"].includes(policy.contract) && ["zai", "kspmas-gateway"].includes(rule) && incrementalToolModels.has(normalized(binding.model)),
2026
+ reasoningRequired,
2027
+ modern: policy.contract === "provider-compat/v3",
2028
+ // Only the observed provider/model dialects may seal without [DONE].
2029
+ finishOnEof: policy.contract === "provider-compat/v3" && ["permissive", "kspmas-gateway"].includes(rule) && ["minimax-m3", "minimax-m2.5"].includes(name),
2025
2030
  supportsEffort: !kimi,
2026
2031
  toolThinkingOff: ["zai", "kspmas-gateway"].includes(rule) && !kimi,
2027
2032
  thinkingBudget: rule === "zai" && !kimi && !disabledEfforts ? 32e3 : null,
@@ -2063,6 +2068,7 @@ function applyProviderChatCompatibility(payload, request, binding) {
2063
2068
  let effort = requested;
2064
2069
  if (requested === null && options.controllerReasoningPolicy === "disclosed-delegate/v1" && ["zai", "kspmas-gateway"].includes(compat.rule) && name.startsWith("glm-5.3") && result.tools?.some((tool) => tool.type === "function" && tool.function?.name === "delegate_task")) effort = "low";
2065
2070
  if (requested === null && request.purpose === "compaction" && compat.rule === "kspmas-gateway" && ["glm-5.2", "deepseek-v4-flash"].includes(name)) effort = "none";
2071
+ if (requested === null && request.purpose === "compaction" && compat.reasoningRequired) effort = "low";
2066
2072
  effort = compat.supportsEffort ? clampReasoningEffort(model, effort) : null;
2067
2073
  if (effort !== null) result.reasoning_effort = effort;
2068
2074
  if (result.stream) result.stream_options = { ...object(result.stream_options) ? result.stream_options : {}, include_usage: true };
@@ -2072,6 +2078,7 @@ function applyProviderChatCompatibility(payload, request, binding) {
2072
2078
  if (!Object.keys(result.stream_options).length) delete result.stream_options;
2073
2079
  }
2074
2080
  const mode = options.thinkingMode ?? result.thinking?.type;
2081
+ if (mode === "disabled" && compat.reasoningRequired) throw new ProtocolError("model_thinking_disable_unsupported");
2075
2082
  const mayDisable = compat.supportsThinking && (compat.disabledEfforts === null || compat.disabledEfforts.includes(effort));
2076
2083
  const summaryOff = request.purpose === "compaction" && requested === null && compat.rule === "kspmas-gateway" && name === "glm-5.3-flash";
2077
2084
  const budget = result.max_completion_tokens ?? result.max_tokens;
@@ -2081,6 +2088,9 @@ function applyProviderChatCompatibility(payload, request, binding) {
2081
2088
  } else if (mayDisable && (mode === "disabled" || summaryOff || compat.toolThinkingOff && !!result.tools?.length && result.tool_choice !== "none" || compat.thinkingBudget !== null && budget <= compat.thinkingBudget)) result.thinking = { type: "disabled" };
2082
2089
  if (!compat.supportsThinking) delete result.thinking;
2083
2090
  if (!compat.supportsEffort) delete result.reasoning_effort;
2091
+ if (compat.modern && ["moonshot", "kspmas-gateway"].includes(compat.rule) && result.tools) {
2092
+ result.tools = result.tools.map((tool) => tool.type === "function" && tool.function?.parameters ? { ...tool, function: { ...tool.function, parameters: explicitLiteralTypes(tool.function.parameters) } } : tool);
2093
+ }
2084
2094
  if (result.tool_choice !== void 0) result.tool_choice = projectProviderToolChoice(result.tool_choice, compat);
2085
2095
  if (compat.echo === "strip" || compat.echo === "thinking" && !compat.hints.some((hint) => normalized(model).includes(hint))) {
2086
2096
  result.messages = result.messages.map((message) => {
@@ -2092,6 +2102,25 @@ function applyProviderChatCompatibility(payload, request, binding) {
2092
2102
  }
2093
2103
  return result;
2094
2104
  }
2105
+ function explicitLiteralTypes(schema) {
2106
+ if (!object(schema)) return schema;
2107
+ const result = { ...schema };
2108
+ if (result.type === void 0 && (Object.hasOwn(result, "const") || Array.isArray(result.enum))) {
2109
+ const values = Object.hasOwn(result, "const") ? [result.const] : result.enum;
2110
+ const types = new Set(values.map((value) => value === null ? "null" : typeof value));
2111
+ if (types.size === 1 && ["string", "number", "boolean", "null"].includes([...types][0])) result.type = [...types][0];
2112
+ }
2113
+ for (const key of ["properties", "patternProperties", "$defs", "definitions", "dependentSchemas"]) {
2114
+ if (object(result[key])) result[key] = Object.fromEntries(Object.entries(result[key]).map(([name, value]) => [name, explicitLiteralTypes(value)]));
2115
+ }
2116
+ for (const key of ["items", "additionalProperties", "contains", "not", "if", "then", "else", "propertyNames"]) {
2117
+ if (object(result[key])) result[key] = explicitLiteralTypes(result[key]);
2118
+ }
2119
+ for (const key of ["allOf", "anyOf", "oneOf", "prefixItems"]) {
2120
+ if (Array.isArray(result[key])) result[key] = result[key].map(explicitLiteralTypes);
2121
+ }
2122
+ return result;
2123
+ }
2095
2124
 
2096
2125
  // packages/agentkit-harness-node/src/native/model-chat-usage.mjs
2097
2126
  var CUMULATIVE_CHAT_USAGE = "cumulative-snapshots/v1";
@@ -2421,6 +2450,9 @@ function chatReasoning(message) {
2421
2450
  return native || alias || "";
2422
2451
  }
2423
2452
  function createOpenAIStreamTurn(profile, binding) {
2453
+ const compatibility = resolveProviderCompatibility(profile.providerCompatibilityPolicy, binding);
2454
+ const modern = compatibility?.modern === true;
2455
+ const finishOnEof = compatibility?.finishOnEof === true;
2424
2456
  const captureReplay = profile.providerReplayMode !== "none";
2425
2457
  const emitThinking = profile.providerThinkingDisplay ?? profile.providerReplayMode !== "none";
2426
2458
  const marker = inlineReasoningMarker(profile.inlineReasoningPolicy, binding);
@@ -2543,7 +2575,7 @@ function createOpenAIStreamTurn(profile, binding) {
2543
2575
  for (const field of ["id", "type"]) {
2544
2576
  if (field in fragment) {
2545
2577
  const value = fragment[field];
2546
- if (value == null) continue;
2578
+ if (value == null || modern && value === "") continue;
2547
2579
  if (typeof value !== "string" || !value || call[field] != null && call[field] !== value) {
2548
2580
  throw new ProtocolError("conflicting tool identity", "identity_conflict");
2549
2581
  }
@@ -2599,7 +2631,7 @@ function createOpenAIStreamTurn(profile, binding) {
2599
2631
  ...failureKind ? { failureKind } : {}
2600
2632
  };
2601
2633
  }
2602
- if (errorKind === "provider_retryable_error" || !this.done) {
2634
+ if (errorKind === "provider_retryable_error" || !this.done && !(finishOnEof && this.finish != null && this.usageAtFinish && !this.usageConflict)) {
2603
2635
  const normalized3 = normalizeResponse({ text: this.text, toolCalls: [], finishReason: finish, streamComplete: false });
2604
2636
  if (normalized3.kind === "provider_retryable_error") {
2605
2637
  return { ...normalized3, usage, usageReported, failureKind: failureKind || "incomplete_response" };
@@ -2620,6 +2652,7 @@ function createOpenAIStreamTurn(profile, binding) {
2620
2652
  try {
2621
2653
  if (this.malformedTools) throw new ProtocolError("malformed tool fragments");
2622
2654
  calls = this.buildCalls();
2655
+ if (!this.done && calls.some((call) => call.wireArgumentsInvalid)) throw new ProtocolError("unfinished EOF tool arguments");
2623
2656
  } catch {
2624
2657
  calls = [{}];
2625
2658
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kingsoftcloud/agentkit-harness-node",
3
- "version": "0.0.11",
3
+ "version": "0.0.12",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "Standalone Native Harness Node adapters: a durable SQLite run store, a one-request model HTTP port, and a minimal versioned JSON-RPC 2.0 over NDJSON process entry. Reuses the shared Native adapter implementations and externalizes @kingsoftcloud/agentkit-harness-core; depends on no Studio/DSH code at runtime.",
@@ -137,7 +137,7 @@
137
137
  "src/package-integrity.mjs"
138
138
  ],
139
139
  "dependencies": {
140
- "@kingsoftcloud/agentkit-harness-core": "0.0.11",
140
+ "@kingsoftcloud/agentkit-harness-core": "0.0.12",
141
141
  "@astral-sh/ruff-wasm-nodejs": "0.16.8",
142
142
  "parse5": "7.3.0",
143
143
  "playwright-core": "1.58.2",
@@ -111,7 +111,7 @@ export function nativeChildRoles(spec = {}, { childAllocationPolicy } = {}) {
111
111
 
112
112
  /** Bind every child to a declared role and its own scoped tool state. */
113
113
  export async function createNativeChildren({ roles, scope, sessionId, store, tools, hasSkills, hasMcp, mcpBinding, skillBinding, skillInstructions, workspaceContext,
114
- resolveModel, bindTools, verificationFactory, fileWorkspaces, commandResource, isClosed, onStream, a2aBinding, waitForChildReceipt, mediaSources = new Map(), artifactPolicy, artifactFactory, sourceReadPolicy, childTaskPolicy, childPlanPolicy, childAllocationPolicy, childCapabilityPolicy, outputRecoveryPolicy, toolExecutionPolicy, modelSurface, goalContractFactory = ({ goal }) => ({ objective: goal }) }) {
114
+ resolveModel, bindTools, verificationFactory, fileWorkspaces, commandResource, isClosed, onStream, a2aBinding, waitForChildReceipt, mediaSources = new Map(), artifactPolicy, artifactFactory, sourceReadPolicy, childTaskPolicy, childPlanPolicy, childAllocationPolicy, childCapabilityPolicy, outputRecoveryPolicy, toolExecutionPolicy, providerRecoveryPolicy, modelSurface, goalContractFactory = ({ goal }) => ({ objective: goal }) }) {
115
115
  if (!roles.length) return null;
116
116
  if (workspaceContext !== undefined) {
117
117
  validateNativeWorkspaceContext(workspaceContext);
@@ -121,6 +121,7 @@ export async function createNativeChildren({ roles, scope, sessionId, store, too
121
121
  invariant(childAllocationPolicy === undefined || childAllocationPolicy === CHILD_ALLOCATION_POLICY, 'studio_native_child_allocation_policy_invalid');
122
122
  invariant(childCapabilityPolicy === undefined || childCapabilityPolicy === CHILD_CAPABILITY_POLICY, 'studio_native_child_capability_policy_invalid');
123
123
  invariant(toolExecutionPolicy === undefined || toolExecutionPolicy === 'owner-execution/v1', 'studio_native_child_execution_policy_invalid');
124
+ invariant(providerRecoveryPolicy === undefined || providerRecoveryPolicy === 'provider-recovery/v2', 'native_child_provider_recovery_policy_invalid');
124
125
  invariant(outputRecoveryPolicy === undefined || outputRecoveryPolicy === 'response-boundary/v2', 'studio_native_child_output_policy_invalid');
125
126
  invariant(childTaskPolicy === undefined || childTaskPolicy === CHILD_TASK_POLICY, 'studio_native_child_task_policy_invalid');
126
127
  invariant(childPlanPolicy === undefined || childPlanPolicy === CHILD_PLAN_POLICY, 'studio_native_child_plan_policy_invalid');
@@ -224,6 +225,7 @@ export async function createNativeChildren({ roles, scope, sessionId, store, too
224
225
  'studio_native_child_command_resource_changed');
225
226
  const hostBindingDigest = hash({ contract: STUDIO_NATIVE_CHILD_CONTRACT, role, profile: bound.model.profile, scope: child, tools: bound.tools,
226
227
  ...(outputRecoveryPolicy ? { outputRecoveryPolicy } : {}),
228
+ ...(providerRecoveryPolicy ? { providerRecoveryPolicy } : {}),
227
229
  ...(toolExecutionPolicy ? { toolExecutionPolicy } : {}),
228
230
  ...(childPlanPolicy ? { childPlanPolicy } : {}),
229
231
  ...(childTaskPolicy ? { childTaskPolicy } : {}),
@@ -254,6 +256,7 @@ export async function createNativeChildren({ roles, scope, sessionId, store, too
254
256
  supportsImages: bound.model.supportsImages, tools: bound.tools }) } : {}),
255
257
  ...(childAllocationPolicy ? { childAllocationPolicy } : {}),
256
258
  ...(outputRecoveryPolicy ? { outputRecoveryPolicy } : {}),
259
+ ...(providerRecoveryPolicy ? { providerRecoveryPolicy } : {}),
257
260
  ...(toolExecutionPolicy ? { toolExecutionPolicy } : {}),
258
261
  ...(executionResource ? { backgroundNotificationPolicy: 'completed-before-model/v1' } : {}),
259
262
  ...(childTaskPolicy ? { todoPolicy: 'session-todos/v1', coordinatorResponsePolicy: COORDINATOR_RESPONSE_POLICY } : {}),
@@ -309,6 +312,7 @@ export async function createNativeChildren({ roles, scope, sessionId, store, too
309
312
  hostBindingDigest: configuration.hostBindingDigest }).profile;
310
313
  invariant(bound && role && canonical(configuration.tools) === canonical(bound.tools)
311
314
  && configuration.outputRecoveryPolicy === outputRecoveryPolicy
315
+ && configuration.providerRecoveryPolicy === providerRecoveryPolicy
312
316
  && configuration.toolExecutionPolicy === toolExecutionPolicy
313
317
  && configuration.inputPolicy === (instructionSource ? 'before-first-model/v1' : undefined)
314
318
  && canonical(configuration.contextSources) === canonical(instructionSource ? [instructionSource.source] : [])
@@ -329,6 +333,7 @@ export async function createNativeChildren({ roles, scope, sessionId, store, too
329
333
  && configuration.hostBindingDigest === hash({ contract: STUDIO_NATIVE_CHILD_CONTRACT, role,
330
334
  profile: bound.model.profile, scope: childScope(role), tools: bound.tools,
331
335
  ...(outputRecoveryPolicy ? { outputRecoveryPolicy } : {}),
336
+ ...(providerRecoveryPolicy ? { providerRecoveryPolicy } : {}),
332
337
  ...(toolExecutionPolicy ? { toolExecutionPolicy } : {}),
333
338
  ...(childPlanPolicy ? { childPlanPolicy } : {}),
334
339
  ...(childTaskPolicy ? { childTaskPolicy } : {}),
@@ -5,6 +5,7 @@ import { createNativeContextPort } from '@kingsoftcloud/agentkit-harness-node/na
5
5
  export function nativeContextDefaults(configuration) {
6
6
  const policy = configuration?.contextPolicy;
7
7
  return {
8
+ adaptiveSummaryDefaults: !configuration || policy?.summaryRecoveryPolicy === 'adaptive-budget/v1',
8
9
  structuredContinuityDefaults: !configuration || policy?.summaryFormatPolicy === 'task-continuity/v1',
9
10
  readWorkingSetDefaults: !configuration || Object.hasOwn(policy ?? {}, 'readWorkingSetCount'),
10
11
  recentToolBatchDefaults: !configuration || Object.hasOwn(policy ?? {}, 'recentToolBatchCount'),
@@ -18,7 +19,7 @@ export function nativeContextDefaults(configuration) {
18
19
  }
19
20
 
20
21
  /** Bind budget, counter and policy from the resolved Agent revision/Frozen Build. */
21
- export function bindNativeContext({ description, context = {}, maxTokens, structuredContinuityDefaults = false, preModelBudgetDefaults = false, orderedContextDefaults = false, sourceReuseDefaults = false, readWorkingSetDefaults = false, recentToolBatchDefaults = false, pruningThresholdDefaults = false, pruningSummaryDefaults = false, pruningIdleDefaults = false } = {}) {
22
+ export function bindNativeContext({ description, context = {}, maxTokens, adaptiveSummaryDefaults = false, structuredContinuityDefaults = false, preModelBudgetDefaults = false, orderedContextDefaults = false, sourceReuseDefaults = false, readWorkingSetDefaults = false, recentToolBatchDefaults = false, pruningThresholdDefaults = false, pruningSummaryDefaults = false, pruningIdleDefaults = false } = {}) {
22
23
  invariant(context && typeof context === 'object' && !Array.isArray(context), 'studio_native_context_invalid');
23
24
  const raw = context.compaction ?? {};
24
25
  invariant(raw && typeof raw === 'object' && !Array.isArray(raw), 'studio_native_compaction_invalid');
@@ -29,7 +30,7 @@ export function bindNativeContext({ description, context = {}, maxTokens, struct
29
30
  'pruneToolResults', 'pruneKeepRecentBatches', 'pruneMinSavedTokens', 'pruneThresholdTokens', 'pruneIdleThresholdMinutes'];
30
31
  invariant(Object.keys(raw).every(key => supported.includes(key)), 'studio_native_compaction_option_unsupported');
31
32
  const requestedWindow = context.maxInputTokens ?? description.contextWindow;
32
- const output = maxTokens ?? context.reserveOutputTokens ?? description.maxOutputTokens;
33
+ const output = maxTokens ?? context.reserveOutputTokens ?? description.requestOutputTokens ?? description.maxOutputTokens;
33
34
  invariant(Number.isSafeInteger(requestedWindow) && requestedWindow > 0
34
35
  && Number.isSafeInteger(output) && output > 0 && output <= description.maxOutputTokens, 'studio_native_context_budget_invalid');
35
36
  const contextWindow = Math.min(requestedWindow, description.contextWindow);
@@ -39,6 +40,8 @@ export function bindNativeContext({ description, context = {}, maxTokens, struct
39
40
  return { port, profile: { contextWindow, maxOutputTokens: output }, policy: {
40
41
  tokenizerId: port.tokens.tokenizerId, tokenizerDigest: port.tokens.tokenizerDigest,
41
42
  summaryBudgetMode: 'context_bounded_estimate',
43
+ ...(adaptiveSummaryDefaults ? { summaryRecoveryPolicy: 'adaptive-budget/v1',
44
+ summaryOutputCeiling: Math.min(raw.summaryMaxTokens ?? output, output) } : {}),
42
45
  ...(structuredContinuityDefaults ? { summaryFormatPolicy: 'task-continuity/v1' } : {}),
43
46
  ...(preModelBudgetDefaults ? { budgetTiming: 'before-model/v1' } : {}),
44
47
  ...(orderedContextDefaults && description.protocol === 'openai-chat' ? { continuityPlacement: 'after-history/v1' } : {}),
@@ -1,3 +1,4 @@
1
+ import { NATIVE_LOCAL_RESOURCE_PROFILES } from '@kingsoftcloud/agentkit-harness-core';
1
2
  import { localControlSettings } from './local-process.mjs';
2
3
 
3
4
  export const LOCAL_RESOURCE_PROFILE = 'agentkit.local-resource-profile/v1';
@@ -7,9 +8,12 @@ const profiles = Object.freeze({
7
8
  // per-file allowance. Keep a finite development allowance; explicit Host
8
9
  // settings always win. Other limits retain their existing values.
9
10
  'local-development/v1': Object.freeze({ maxFileBytes: 1024 ** 3 }),
11
+ // Versioned development budget: allow long builds without changing old Runs
12
+ // or the restricted profile. A Host's explicit lower limit still wins.
13
+ 'local-development/v2': Object.freeze({ cpuSeconds: 900, maxFileBytes: 1024 ** 3 }),
10
14
  });
11
15
  export function validLocalResourceProfile(profile) {
12
- return typeof profile === 'string' && Object.hasOwn(profiles, profile);
16
+ return typeof profile === 'string' && NATIVE_LOCAL_RESOURCE_PROFILES.includes(profile) && Object.hasOwn(profiles, profile);
13
17
  }
14
18
 
15
19
  /** Host admission selects this policy, never a model/tool argument. */
@@ -14,7 +14,7 @@ import {
14
14
  import { sealModelReplay, openAIReplayFields } from './model-replay.mjs';
15
15
  import { validateMediaBlock, projectMediaOpenAI, MediaError } from './model-media.mjs';
16
16
  import { inlineReasoningMarker, projectInlineReasoning, createInlineReasoningProjector } from './model-inline-reasoning.mjs';
17
- import { applyProviderChatCompatibility } from './model-provider-compat.mjs';
17
+ import { applyProviderChatCompatibility, resolveProviderCompatibility } from './model-provider-compat.mjs';
18
18
  import { mergeChatUsage } from './model-chat-usage.mjs';
19
19
  // parseModelJson is the kernel's strict finite JSON parser: it rejects
20
20
  // duplicate object keys and non-finite numbers (e.g. 1e400). Using it here keeps
@@ -339,6 +339,9 @@ function chatReasoning(message) {
339
339
  // ksadk._StreamTurn. Frame errors throw ProtocolError; finalize preserves the
340
340
  // accumulated text/usage and classifies the attempt.
341
341
  export function createOpenAIStreamTurn(profile, binding) {
342
+ const compatibility = resolveProviderCompatibility(profile.providerCompatibilityPolicy, binding);
343
+ const modern = compatibility?.modern === true;
344
+ const finishOnEof = compatibility?.finishOnEof === true;
342
345
  const captureReplay = profile.providerReplayMode !== 'none';
343
346
  const emitThinking = profile.providerThinkingDisplay ?? profile.providerReplayMode !== 'none';
344
347
  const marker = inlineReasoningMarker(profile.inlineReasoningPolicy, binding);
@@ -452,7 +455,7 @@ export function createOpenAIStreamTurn(profile, binding) {
452
455
  // Some OpenAI-compatible SSE providers emit null for unchanged
453
456
  // identity fields in later fragments. Only non-null deltas can
454
457
  // establish or conflict with the original tool identity.
455
- if (value == null) continue;
458
+ if (value == null || modern && value === '') continue;
456
459
  if (typeof value !== 'string' || !value || (call[field] != null && call[field] !== value)) {
457
460
  throw new ProtocolError('conflicting tool identity', 'identity_conflict');
458
461
  }
@@ -503,7 +506,8 @@ export function createOpenAIStreamTurn(profile, binding) {
503
506
  ...(failureKind ? { failureKind } : {}),
504
507
  };
505
508
  }
506
- if (errorKind === 'provider_retryable_error' || !this.done) {
509
+ if (errorKind === 'provider_retryable_error' || !this.done && !(finishOnEof
510
+ && this.finish != null && this.usageAtFinish && !this.usageConflict)) {
507
511
  const normalized = normalizeResponse({ text: this.text, toolCalls: [], finishReason: finish, streamComplete: false });
508
512
  if (normalized.kind === 'provider_retryable_error') {
509
513
  return { ...normalized, usage, usageReported, failureKind: failureKind || 'incomplete_response' };
@@ -521,6 +525,7 @@ export function createOpenAIStreamTurn(profile, binding) {
521
525
  try {
522
526
  if (this.malformedTools) throw new ProtocolError('malformed tool fragments');
523
527
  calls = this.buildCalls();
528
+ if (!this.done && calls.some(call => call.wireArgumentsInvalid)) throw new ProtocolError('unfinished EOF tool arguments');
524
529
  } catch {
525
530
  calls = [{}];
526
531
  }
@@ -44,20 +44,25 @@ export function applyAnthropicThinking(payload, profile, binding) {
44
44
  }
45
45
 
46
46
  export function admitProviderCompatibilityPolicy(override) {
47
- return { contract: 'provider-compat/v2', rule: admitInlineReasoningPolicy(override).rule };
47
+ return { contract: 'provider-compat/v3', rule: admitInlineReasoningPolicy(override).rule };
48
48
  }
49
49
 
50
50
  export function resolveProviderCompatibility(policy, binding) {
51
51
  if (!policy) return null;
52
- if (!['provider-compat/v1', 'provider-compat/v2'].includes(policy.contract)) throw new ProtocolError('invalid_provider_compatibility_policy');
52
+ if (!['provider-compat/v1', 'provider-compat/v2', 'provider-compat/v3'].includes(policy.contract)) throw new ProtocolError('invalid_provider_compatibility_policy');
53
53
  const rule = resolveCompatibilityRule(policy.rule, binding);
54
54
  const name = String(binding.model ?? '').trim().toLowerCase();
55
55
  const kimi = ['kspmas-gateway', 'moonshot'].includes(rule)
56
56
  && ['kimi-k2.7-code', 'kimi-k2.7-code-highspeed'].includes(name);
57
- const disabledEfforts = mandatory.has(name) ? [] : name === 'claude-haiku-5-5' ? ['low', 'medium', 'high'] : null;
57
+ const reasoningRequired = policy.contract === 'provider-compat/v3' && rule === 'kspmas-gateway' && name === 'glm-5.3-flash';
58
+ const disabledEfforts = mandatory.has(name) || reasoningRequired ? [] : name === 'claude-haiku-5-5' ? ['low', 'medium', 'high'] : null;
58
59
  return { rule, supportsUsage: !strict.has(rule), supportsThinking: !strict.has(rule) && !kimi,
59
- supportsToolArgumentStreaming: policy.contract === 'provider-compat/v2'
60
+ supportsToolArgumentStreaming: ['provider-compat/v2', 'provider-compat/v3'].includes(policy.contract)
60
61
  && ['zai', 'kspmas-gateway'].includes(rule) && incrementalToolModels.has(normalized(binding.model)),
62
+ reasoningRequired, modern: policy.contract === 'provider-compat/v3',
63
+ // Only the observed provider/model dialects may seal without [DONE].
64
+ finishOnEof: policy.contract === 'provider-compat/v3' && ['permissive', 'kspmas-gateway'].includes(rule)
65
+ && ['minimax-m3', 'minimax-m2.5'].includes(name),
61
66
  supportsEffort: !kimi, toolThinkingOff: ['zai', 'kspmas-gateway'].includes(rule) && !kimi,
62
67
  thinkingBudget: rule === 'zai' && !kimi && !disabledEfforts ? 32000 : null,
63
68
  disabledEfforts, requiredAuto: kimi || requiredAuto.has(name),
@@ -99,6 +104,7 @@ export function applyProviderChatCompatibility(payload, request, binding) {
99
104
  && result.tools?.some(tool => tool.type === 'function' && tool.function?.name === 'delegate_task')) effort = 'low';
100
105
  if (requested === null && request.purpose === 'compaction' && compat.rule === 'kspmas-gateway'
101
106
  && ['glm-5.2', 'deepseek-v4-flash'].includes(name)) effort = 'none';
107
+ if (requested === null && request.purpose === 'compaction' && compat.reasoningRequired) effort = 'low';
102
108
  effort = compat.supportsEffort ? clampReasoningEffort(model, effort) : null;
103
109
  if (effort !== null) result.reasoning_effort = effort;
104
110
  if (result.stream) result.stream_options = { ...(object(result.stream_options) ? result.stream_options : {}), include_usage: true };
@@ -107,6 +113,7 @@ export function applyProviderChatCompatibility(payload, request, binding) {
107
113
  if (!Object.keys(result.stream_options).length) delete result.stream_options;
108
114
  }
109
115
  const mode = options.thinkingMode ?? result.thinking?.type;
116
+ if (mode === 'disabled' && compat.reasoningRequired) throw new ProtocolError('model_thinking_disable_unsupported');
110
117
  const mayDisable = compat.supportsThinking && (compat.disabledEfforts === null || compat.disabledEfforts.includes(effort));
111
118
  const summaryOff = request.purpose === 'compaction' && requested === null && compat.rule === 'kspmas-gateway' && name === 'glm-5.3-flash';
112
119
  const budget = result.max_completion_tokens ?? result.max_tokens;
@@ -118,6 +125,10 @@ export function applyProviderChatCompatibility(payload, request, binding) {
118
125
  || compat.thinkingBudget !== null && budget <= compat.thinkingBudget)) result.thinking = { type: 'disabled' };
119
126
  if (!compat.supportsThinking) delete result.thinking;
120
127
  if (!compat.supportsEffort) delete result.reasoning_effort;
128
+ if (compat.modern && ['moonshot', 'kspmas-gateway'].includes(compat.rule) && result.tools) {
129
+ result.tools = result.tools.map(tool => tool.type === 'function' && tool.function?.parameters
130
+ ? { ...tool, function: { ...tool.function, parameters: explicitLiteralTypes(tool.function.parameters) } } : tool);
131
+ }
121
132
  if (result.tool_choice !== undefined) result.tool_choice = projectProviderToolChoice(result.tool_choice, compat);
122
133
  if (compat.echo === 'strip' || compat.echo === 'thinking' && !compat.hints.some(hint => normalized(model).includes(hint))) {
123
134
  result.messages = result.messages.map(message => {
@@ -127,3 +138,25 @@ export function applyProviderChatCompatibility(payload, request, binding) {
127
138
  }
128
139
  return result;
129
140
  }
141
+
142
+ /** Narrow JSON Schema dialect projection. Infer only homogeneous primitive
143
+ * literals; never rewrite user data, mixed enums, refs or union semantics. */
144
+ export function explicitLiteralTypes(schema) {
145
+ if (!object(schema)) return schema;
146
+ const result = { ...schema };
147
+ if (result.type === undefined && (Object.hasOwn(result, 'const') || Array.isArray(result.enum))) {
148
+ const values = Object.hasOwn(result, 'const') ? [result.const] : result.enum;
149
+ const types = new Set(values.map(value => value === null ? 'null' : typeof value));
150
+ if (types.size === 1 && ['string', 'number', 'boolean', 'null'].includes([...types][0])) result.type = [...types][0];
151
+ }
152
+ for (const key of ['properties', 'patternProperties', '$defs', 'definitions', 'dependentSchemas']) {
153
+ if (object(result[key])) result[key] = Object.fromEntries(Object.entries(result[key]).map(([name, value]) => [name, explicitLiteralTypes(value)]));
154
+ }
155
+ for (const key of ['items', 'additionalProperties', 'contains', 'not', 'if', 'then', 'else', 'propertyNames']) {
156
+ if (object(result[key])) result[key] = explicitLiteralTypes(result[key]);
157
+ }
158
+ for (const key of ['allOf', 'anyOf', 'oneOf', 'prefixItems']) {
159
+ if (Array.isArray(result[key])) result[key] = result[key].map(explicitLiteralTypes);
160
+ }
161
+ return result;
162
+ }