@kingsoftcloud/agentkit-harness-node 0.0.10 → 0.0.11

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,21 +2001,16 @@ 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", "provider-compat/v3"].includes(policy.contract)) throw new ProtocolError("invalid_provider_compatibility_policy");
2004
+ if (!["provider-compat/v1", "provider-compat/v2"].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 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;
2008
+ const disabledEfforts = mandatory.has(name) ? [] : name === "claude-haiku-5-5" ? ["low", "medium", "high"] : null;
2010
2009
  return {
2011
2010
  rule,
2012
2011
  supportsUsage: !strict.has(rule),
2013
2012
  supportsThinking: !strict.has(rule) && !kimi,
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),
2013
+ supportsToolArgumentStreaming: policy.contract === "provider-compat/v2" && ["zai", "kspmas-gateway"].includes(rule) && incrementalToolModels.has(normalized(binding.model)),
2019
2014
  supportsEffort: !kimi,
2020
2015
  toolThinkingOff: ["zai", "kspmas-gateway"].includes(rule) && !kimi,
2021
2016
  thinkingBudget: rule === "zai" && !kimi && !disabledEfforts ? 32e3 : null,
@@ -2057,7 +2052,6 @@ function applyProviderChatCompatibility(payload, request, binding) {
2057
2052
  let effort = requested;
2058
2053
  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";
2059
2054
  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";
2061
2055
  effort = compat.supportsEffort ? clampReasoningEffort(model, effort) : null;
2062
2056
  if (effort !== null) result.reasoning_effort = effort;
2063
2057
  if (result.stream) result.stream_options = { ...object(result.stream_options) ? result.stream_options : {}, include_usage: true };
@@ -2067,7 +2061,6 @@ function applyProviderChatCompatibility(payload, request, binding) {
2067
2061
  if (!Object.keys(result.stream_options).length) delete result.stream_options;
2068
2062
  }
2069
2063
  const mode = options.thinkingMode ?? result.thinking?.type;
2070
- if (mode === "disabled" && compat.reasoningRequired) throw new ProtocolError("model_thinking_disable_unsupported");
2071
2064
  const mayDisable = compat.supportsThinking && (compat.disabledEfforts === null || compat.disabledEfforts.includes(effort));
2072
2065
  const summaryOff = request.purpose === "compaction" && requested === null && compat.rule === "kspmas-gateway" && name === "glm-5.3-flash";
2073
2066
  const budget = result.max_completion_tokens ?? result.max_tokens;
@@ -2077,9 +2070,6 @@ function applyProviderChatCompatibility(payload, request, binding) {
2077
2070
  } 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" };
2078
2071
  if (!compat.supportsThinking) delete result.thinking;
2079
2072
  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
- }
2083
2073
  if (result.tool_choice !== void 0) result.tool_choice = projectProviderToolChoice(result.tool_choice, compat);
2084
2074
  if (compat.echo === "strip" || compat.echo === "thinking" && !compat.hints.some((hint) => normalized(model).includes(hint))) {
2085
2075
  result.messages = result.messages.map((message) => {
@@ -2091,25 +2081,6 @@ function applyProviderChatCompatibility(payload, request, binding) {
2091
2081
  }
2092
2082
  return result;
2093
2083
  }
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
- }
2113
2084
 
2114
2085
  // packages/agentkit-harness-node/src/native/model-chat-usage.mjs
2115
2086
  var CUMULATIVE_CHAT_USAGE = "cumulative-snapshots/v1";
@@ -2439,9 +2410,6 @@ function chatReasoning(message) {
2439
2410
  return native || alias || "";
2440
2411
  }
2441
2412
  function createOpenAIStreamTurn(profile, binding) {
2442
- const compatibility = resolveProviderCompatibility(profile.providerCompatibilityPolicy, binding);
2443
- const modern = compatibility?.modern === true;
2444
- const finishOnEof = compatibility?.finishOnEof === true;
2445
2413
  const captureReplay = profile.providerReplayMode !== "none";
2446
2414
  const emitThinking = profile.providerThinkingDisplay ?? profile.providerReplayMode !== "none";
2447
2415
  const marker = inlineReasoningMarker(profile.inlineReasoningPolicy, binding);
@@ -2564,7 +2532,7 @@ function createOpenAIStreamTurn(profile, binding) {
2564
2532
  for (const field of ["id", "type"]) {
2565
2533
  if (field in fragment) {
2566
2534
  const value = fragment[field];
2567
- if (value == null || modern && value === "") continue;
2535
+ if (value == null) continue;
2568
2536
  if (typeof value !== "string" || !value || call[field] != null && call[field] !== value) {
2569
2537
  throw new ProtocolError("conflicting tool identity", "identity_conflict");
2570
2538
  }
@@ -2620,7 +2588,7 @@ function createOpenAIStreamTurn(profile, binding) {
2620
2588
  ...failureKind ? { failureKind } : {}
2621
2589
  };
2622
2590
  }
2623
- if (errorKind === "provider_retryable_error" || !this.done && !(finishOnEof && this.finish != null && this.usageAtFinish && !this.usageConflict)) {
2591
+ if (errorKind === "provider_retryable_error" || !this.done) {
2624
2592
  const normalized3 = normalizeResponse({ text: this.text, toolCalls: [], finishReason: finish, streamComplete: false });
2625
2593
  if (normalized3.kind === "provider_retryable_error") {
2626
2594
  return { ...normalized3, usage, usageReported, failureKind: failureKind || "incomplete_response" };
@@ -2641,7 +2609,6 @@ function createOpenAIStreamTurn(profile, binding) {
2641
2609
  try {
2642
2610
  if (this.malformedTools) throw new ProtocolError("malformed tool fragments");
2643
2611
  calls = this.buildCalls();
2644
- if (!this.done && calls.some((call) => call.wireArgumentsInvalid)) throw new ProtocolError("unfinished EOF tool arguments");
2645
2612
  } catch {
2646
2613
  calls = [{}];
2647
2614
  }
@@ -2012,21 +2012,16 @@ 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", "provider-compat/v3"].includes(policy.contract)) throw new ProtocolError("invalid_provider_compatibility_policy");
2015
+ if (!["provider-compat/v1", "provider-compat/v2"].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 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;
2019
+ const disabledEfforts = mandatory.has(name) ? [] : name === "claude-haiku-5-5" ? ["low", "medium", "high"] : null;
2021
2020
  return {
2022
2021
  rule,
2023
2022
  supportsUsage: !strict.has(rule),
2024
2023
  supportsThinking: !strict.has(rule) && !kimi,
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),
2024
+ supportsToolArgumentStreaming: policy.contract === "provider-compat/v2" && ["zai", "kspmas-gateway"].includes(rule) && incrementalToolModels.has(normalized(binding.model)),
2030
2025
  supportsEffort: !kimi,
2031
2026
  toolThinkingOff: ["zai", "kspmas-gateway"].includes(rule) && !kimi,
2032
2027
  thinkingBudget: rule === "zai" && !kimi && !disabledEfforts ? 32e3 : null,
@@ -2068,7 +2063,6 @@ function applyProviderChatCompatibility(payload, request, binding) {
2068
2063
  let effort = requested;
2069
2064
  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";
2070
2065
  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";
2072
2066
  effort = compat.supportsEffort ? clampReasoningEffort(model, effort) : null;
2073
2067
  if (effort !== null) result.reasoning_effort = effort;
2074
2068
  if (result.stream) result.stream_options = { ...object(result.stream_options) ? result.stream_options : {}, include_usage: true };
@@ -2078,7 +2072,6 @@ function applyProviderChatCompatibility(payload, request, binding) {
2078
2072
  if (!Object.keys(result.stream_options).length) delete result.stream_options;
2079
2073
  }
2080
2074
  const mode = options.thinkingMode ?? result.thinking?.type;
2081
- if (mode === "disabled" && compat.reasoningRequired) throw new ProtocolError("model_thinking_disable_unsupported");
2082
2075
  const mayDisable = compat.supportsThinking && (compat.disabledEfforts === null || compat.disabledEfforts.includes(effort));
2083
2076
  const summaryOff = request.purpose === "compaction" && requested === null && compat.rule === "kspmas-gateway" && name === "glm-5.3-flash";
2084
2077
  const budget = result.max_completion_tokens ?? result.max_tokens;
@@ -2088,9 +2081,6 @@ function applyProviderChatCompatibility(payload, request, binding) {
2088
2081
  } 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" };
2089
2082
  if (!compat.supportsThinking) delete result.thinking;
2090
2083
  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
- }
2094
2084
  if (result.tool_choice !== void 0) result.tool_choice = projectProviderToolChoice(result.tool_choice, compat);
2095
2085
  if (compat.echo === "strip" || compat.echo === "thinking" && !compat.hints.some((hint) => normalized(model).includes(hint))) {
2096
2086
  result.messages = result.messages.map((message) => {
@@ -2102,25 +2092,6 @@ function applyProviderChatCompatibility(payload, request, binding) {
2102
2092
  }
2103
2093
  return result;
2104
2094
  }
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
- }
2124
2095
 
2125
2096
  // packages/agentkit-harness-node/src/native/model-chat-usage.mjs
2126
2097
  var CUMULATIVE_CHAT_USAGE = "cumulative-snapshots/v1";
@@ -2450,9 +2421,6 @@ function chatReasoning(message) {
2450
2421
  return native || alias || "";
2451
2422
  }
2452
2423
  function createOpenAIStreamTurn(profile, binding) {
2453
- const compatibility = resolveProviderCompatibility(profile.providerCompatibilityPolicy, binding);
2454
- const modern = compatibility?.modern === true;
2455
- const finishOnEof = compatibility?.finishOnEof === true;
2456
2424
  const captureReplay = profile.providerReplayMode !== "none";
2457
2425
  const emitThinking = profile.providerThinkingDisplay ?? profile.providerReplayMode !== "none";
2458
2426
  const marker = inlineReasoningMarker(profile.inlineReasoningPolicy, binding);
@@ -2575,7 +2543,7 @@ function createOpenAIStreamTurn(profile, binding) {
2575
2543
  for (const field of ["id", "type"]) {
2576
2544
  if (field in fragment) {
2577
2545
  const value = fragment[field];
2578
- if (value == null || modern && value === "") continue;
2546
+ if (value == null) continue;
2579
2547
  if (typeof value !== "string" || !value || call[field] != null && call[field] !== value) {
2580
2548
  throw new ProtocolError("conflicting tool identity", "identity_conflict");
2581
2549
  }
@@ -2631,7 +2599,7 @@ function createOpenAIStreamTurn(profile, binding) {
2631
2599
  ...failureKind ? { failureKind } : {}
2632
2600
  };
2633
2601
  }
2634
- if (errorKind === "provider_retryable_error" || !this.done && !(finishOnEof && this.finish != null && this.usageAtFinish && !this.usageConflict)) {
2602
+ if (errorKind === "provider_retryable_error" || !this.done) {
2635
2603
  const normalized3 = normalizeResponse({ text: this.text, toolCalls: [], finishReason: finish, streamComplete: false });
2636
2604
  if (normalized3.kind === "provider_retryable_error") {
2637
2605
  return { ...normalized3, usage, usageReported, failureKind: failureKind || "incomplete_response" };
@@ -2652,7 +2620,6 @@ function createOpenAIStreamTurn(profile, binding) {
2652
2620
  try {
2653
2621
  if (this.malformedTools) throw new ProtocolError("malformed tool fragments");
2654
2622
  calls = this.buildCalls();
2655
- if (!this.done && calls.some((call) => call.wireArgumentsInvalid)) throw new ProtocolError("unfinished EOF tool arguments");
2656
2623
  } catch {
2657
2624
  calls = [{}];
2658
2625
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kingsoftcloud/agentkit-harness-node",
3
- "version": "0.0.10",
3
+ "version": "0.0.11",
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.10",
140
+ "@kingsoftcloud/agentkit-harness-core": "0.0.11",
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, providerRecoveryPolicy, 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, modelSurface, goalContractFactory = ({ goal }) => ({ objective: goal }) }) {
115
115
  if (!roles.length) return null;
116
116
  if (workspaceContext !== undefined) {
117
117
  validateNativeWorkspaceContext(workspaceContext);
@@ -121,7 +121,6 @@ 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');
125
124
  invariant(outputRecoveryPolicy === undefined || outputRecoveryPolicy === 'response-boundary/v2', 'studio_native_child_output_policy_invalid');
126
125
  invariant(childTaskPolicy === undefined || childTaskPolicy === CHILD_TASK_POLICY, 'studio_native_child_task_policy_invalid');
127
126
  invariant(childPlanPolicy === undefined || childPlanPolicy === CHILD_PLAN_POLICY, 'studio_native_child_plan_policy_invalid');
@@ -225,7 +224,6 @@ export async function createNativeChildren({ roles, scope, sessionId, store, too
225
224
  'studio_native_child_command_resource_changed');
226
225
  const hostBindingDigest = hash({ contract: STUDIO_NATIVE_CHILD_CONTRACT, role, profile: bound.model.profile, scope: child, tools: bound.tools,
227
226
  ...(outputRecoveryPolicy ? { outputRecoveryPolicy } : {}),
228
- ...(providerRecoveryPolicy ? { providerRecoveryPolicy } : {}),
229
227
  ...(toolExecutionPolicy ? { toolExecutionPolicy } : {}),
230
228
  ...(childPlanPolicy ? { childPlanPolicy } : {}),
231
229
  ...(childTaskPolicy ? { childTaskPolicy } : {}),
@@ -256,7 +254,6 @@ export async function createNativeChildren({ roles, scope, sessionId, store, too
256
254
  supportsImages: bound.model.supportsImages, tools: bound.tools }) } : {}),
257
255
  ...(childAllocationPolicy ? { childAllocationPolicy } : {}),
258
256
  ...(outputRecoveryPolicy ? { outputRecoveryPolicy } : {}),
259
- ...(providerRecoveryPolicy ? { providerRecoveryPolicy } : {}),
260
257
  ...(toolExecutionPolicy ? { toolExecutionPolicy } : {}),
261
258
  ...(executionResource ? { backgroundNotificationPolicy: 'completed-before-model/v1' } : {}),
262
259
  ...(childTaskPolicy ? { todoPolicy: 'session-todos/v1', coordinatorResponsePolicy: COORDINATOR_RESPONSE_POLICY } : {}),
@@ -312,7 +309,6 @@ export async function createNativeChildren({ roles, scope, sessionId, store, too
312
309
  hostBindingDigest: configuration.hostBindingDigest }).profile;
313
310
  invariant(bound && role && canonical(configuration.tools) === canonical(bound.tools)
314
311
  && configuration.outputRecoveryPolicy === outputRecoveryPolicy
315
- && configuration.providerRecoveryPolicy === providerRecoveryPolicy
316
312
  && configuration.toolExecutionPolicy === toolExecutionPolicy
317
313
  && configuration.inputPolicy === (instructionSource ? 'before-first-model/v1' : undefined)
318
314
  && canonical(configuration.contextSources) === canonical(instructionSource ? [instructionSource.source] : [])
@@ -333,7 +329,6 @@ export async function createNativeChildren({ roles, scope, sessionId, store, too
333
329
  && configuration.hostBindingDigest === hash({ contract: STUDIO_NATIVE_CHILD_CONTRACT, role,
334
330
  profile: bound.model.profile, scope: childScope(role), tools: bound.tools,
335
331
  ...(outputRecoveryPolicy ? { outputRecoveryPolicy } : {}),
336
- ...(providerRecoveryPolicy ? { providerRecoveryPolicy } : {}),
337
332
  ...(toolExecutionPolicy ? { toolExecutionPolicy } : {}),
338
333
  ...(childPlanPolicy ? { childPlanPolicy } : {}),
339
334
  ...(childTaskPolicy ? { childTaskPolicy } : {}),
@@ -5,7 +5,6 @@ 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',
9
8
  structuredContinuityDefaults: !configuration || policy?.summaryFormatPolicy === 'task-continuity/v1',
10
9
  readWorkingSetDefaults: !configuration || Object.hasOwn(policy ?? {}, 'readWorkingSetCount'),
11
10
  recentToolBatchDefaults: !configuration || Object.hasOwn(policy ?? {}, 'recentToolBatchCount'),
@@ -19,7 +18,7 @@ export function nativeContextDefaults(configuration) {
19
18
  }
20
19
 
21
20
  /** Bind budget, counter and policy from the resolved Agent revision/Frozen Build. */
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 } = {}) {
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 } = {}) {
23
22
  invariant(context && typeof context === 'object' && !Array.isArray(context), 'studio_native_context_invalid');
24
23
  const raw = context.compaction ?? {};
25
24
  invariant(raw && typeof raw === 'object' && !Array.isArray(raw), 'studio_native_compaction_invalid');
@@ -30,7 +29,7 @@ export function bindNativeContext({ description, context = {}, maxTokens, adapti
30
29
  'pruneToolResults', 'pruneKeepRecentBatches', 'pruneMinSavedTokens', 'pruneThresholdTokens', 'pruneIdleThresholdMinutes'];
31
30
  invariant(Object.keys(raw).every(key => supported.includes(key)), 'studio_native_compaction_option_unsupported');
32
31
  const requestedWindow = context.maxInputTokens ?? description.contextWindow;
33
- const output = maxTokens ?? context.reserveOutputTokens ?? description.requestOutputTokens ?? description.maxOutputTokens;
32
+ const output = maxTokens ?? context.reserveOutputTokens ?? description.maxOutputTokens;
34
33
  invariant(Number.isSafeInteger(requestedWindow) && requestedWindow > 0
35
34
  && Number.isSafeInteger(output) && output > 0 && output <= description.maxOutputTokens, 'studio_native_context_budget_invalid');
36
35
  const contextWindow = Math.min(requestedWindow, description.contextWindow);
@@ -40,8 +39,6 @@ export function bindNativeContext({ description, context = {}, maxTokens, adapti
40
39
  return { port, profile: { contextWindow, maxOutputTokens: output }, policy: {
41
40
  tokenizerId: port.tokens.tokenizerId, tokenizerDigest: port.tokens.tokenizerDigest,
42
41
  summaryBudgetMode: 'context_bounded_estimate',
43
- ...(adaptiveSummaryDefaults ? { summaryRecoveryPolicy: 'adaptive-budget/v1',
44
- summaryOutputCeiling: Math.min(raw.summaryMaxTokens ?? output, output) } : {}),
45
42
  ...(structuredContinuityDefaults ? { summaryFormatPolicy: 'task-continuity/v1' } : {}),
46
43
  ...(preModelBudgetDefaults ? { budgetTiming: 'before-model/v1' } : {}),
47
44
  ...(orderedContextDefaults && description.protocol === 'openai-chat' ? { continuityPlacement: 'after-history/v1' } : {}),
@@ -1,4 +1,3 @@
1
- import { NATIVE_LOCAL_RESOURCE_PROFILES } from '@kingsoftcloud/agentkit-harness-core';
2
1
  import { localControlSettings } from './local-process.mjs';
3
2
 
4
3
  export const LOCAL_RESOURCE_PROFILE = 'agentkit.local-resource-profile/v1';
@@ -8,12 +7,9 @@ const profiles = Object.freeze({
8
7
  // per-file allowance. Keep a finite development allowance; explicit Host
9
8
  // settings always win. Other limits retain their existing values.
10
9
  '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 }),
14
10
  });
15
11
  export function validLocalResourceProfile(profile) {
16
- return typeof profile === 'string' && NATIVE_LOCAL_RESOURCE_PROFILES.includes(profile) && Object.hasOwn(profiles, profile);
12
+ return typeof profile === 'string' && Object.hasOwn(profiles, profile);
17
13
  }
18
14
 
19
15
  /** 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, resolveProviderCompatibility } from './model-provider-compat.mjs';
17
+ import { applyProviderChatCompatibility } 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,9 +339,6 @@ 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;
345
342
  const captureReplay = profile.providerReplayMode !== 'none';
346
343
  const emitThinking = profile.providerThinkingDisplay ?? profile.providerReplayMode !== 'none';
347
344
  const marker = inlineReasoningMarker(profile.inlineReasoningPolicy, binding);
@@ -455,7 +452,7 @@ export function createOpenAIStreamTurn(profile, binding) {
455
452
  // Some OpenAI-compatible SSE providers emit null for unchanged
456
453
  // identity fields in later fragments. Only non-null deltas can
457
454
  // establish or conflict with the original tool identity.
458
- if (value == null || modern && value === '') continue;
455
+ if (value == null) continue;
459
456
  if (typeof value !== 'string' || !value || (call[field] != null && call[field] !== value)) {
460
457
  throw new ProtocolError('conflicting tool identity', 'identity_conflict');
461
458
  }
@@ -506,8 +503,7 @@ export function createOpenAIStreamTurn(profile, binding) {
506
503
  ...(failureKind ? { failureKind } : {}),
507
504
  };
508
505
  }
509
- if (errorKind === 'provider_retryable_error' || !this.done && !(finishOnEof
510
- && this.finish != null && this.usageAtFinish && !this.usageConflict)) {
506
+ if (errorKind === 'provider_retryable_error' || !this.done) {
511
507
  const normalized = normalizeResponse({ text: this.text, toolCalls: [], finishReason: finish, streamComplete: false });
512
508
  if (normalized.kind === 'provider_retryable_error') {
513
509
  return { ...normalized, usage, usageReported, failureKind: failureKind || 'incomplete_response' };
@@ -525,7 +521,6 @@ export function createOpenAIStreamTurn(profile, binding) {
525
521
  try {
526
522
  if (this.malformedTools) throw new ProtocolError('malformed tool fragments');
527
523
  calls = this.buildCalls();
528
- if (!this.done && calls.some(call => call.wireArgumentsInvalid)) throw new ProtocolError('unfinished EOF tool arguments');
529
524
  } catch {
530
525
  calls = [{}];
531
526
  }
@@ -44,25 +44,20 @@ export function applyAnthropicThinking(payload, profile, binding) {
44
44
  }
45
45
 
46
46
  export function admitProviderCompatibilityPolicy(override) {
47
- return { contract: 'provider-compat/v3', rule: admitInlineReasoningPolicy(override).rule };
47
+ return { contract: 'provider-compat/v2', 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', 'provider-compat/v3'].includes(policy.contract)) throw new ProtocolError('invalid_provider_compatibility_policy');
52
+ if (!['provider-compat/v1', 'provider-compat/v2'].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 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;
57
+ const disabledEfforts = mandatory.has(name) ? [] : name === 'claude-haiku-5-5' ? ['low', 'medium', 'high'] : null;
59
58
  return { rule, supportsUsage: !strict.has(rule), supportsThinking: !strict.has(rule) && !kimi,
60
- supportsToolArgumentStreaming: ['provider-compat/v2', 'provider-compat/v3'].includes(policy.contract)
59
+ supportsToolArgumentStreaming: policy.contract === 'provider-compat/v2'
61
60
  && ['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),
66
61
  supportsEffort: !kimi, toolThinkingOff: ['zai', 'kspmas-gateway'].includes(rule) && !kimi,
67
62
  thinkingBudget: rule === 'zai' && !kimi && !disabledEfforts ? 32000 : null,
68
63
  disabledEfforts, requiredAuto: kimi || requiredAuto.has(name),
@@ -104,7 +99,6 @@ export function applyProviderChatCompatibility(payload, request, binding) {
104
99
  && result.tools?.some(tool => tool.type === 'function' && tool.function?.name === 'delegate_task')) effort = 'low';
105
100
  if (requested === null && request.purpose === 'compaction' && compat.rule === 'kspmas-gateway'
106
101
  && ['glm-5.2', 'deepseek-v4-flash'].includes(name)) effort = 'none';
107
- if (requested === null && request.purpose === 'compaction' && compat.reasoningRequired) effort = 'low';
108
102
  effort = compat.supportsEffort ? clampReasoningEffort(model, effort) : null;
109
103
  if (effort !== null) result.reasoning_effort = effort;
110
104
  if (result.stream) result.stream_options = { ...(object(result.stream_options) ? result.stream_options : {}), include_usage: true };
@@ -113,7 +107,6 @@ export function applyProviderChatCompatibility(payload, request, binding) {
113
107
  if (!Object.keys(result.stream_options).length) delete result.stream_options;
114
108
  }
115
109
  const mode = options.thinkingMode ?? result.thinking?.type;
116
- if (mode === 'disabled' && compat.reasoningRequired) throw new ProtocolError('model_thinking_disable_unsupported');
117
110
  const mayDisable = compat.supportsThinking && (compat.disabledEfforts === null || compat.disabledEfforts.includes(effort));
118
111
  const summaryOff = request.purpose === 'compaction' && requested === null && compat.rule === 'kspmas-gateway' && name === 'glm-5.3-flash';
119
112
  const budget = result.max_completion_tokens ?? result.max_tokens;
@@ -125,10 +118,6 @@ export function applyProviderChatCompatibility(payload, request, binding) {
125
118
  || compat.thinkingBudget !== null && budget <= compat.thinkingBudget)) result.thinking = { type: 'disabled' };
126
119
  if (!compat.supportsThinking) delete result.thinking;
127
120
  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
- }
132
121
  if (result.tool_choice !== undefined) result.tool_choice = projectProviderToolChoice(result.tool_choice, compat);
133
122
  if (compat.echo === 'strip' || compat.echo === 'thinking' && !compat.hints.some(hint => normalized(model).includes(hint))) {
134
123
  result.messages = result.messages.map(message => {
@@ -138,25 +127,3 @@ export function applyProviderChatCompatibility(payload, request, binding) {
138
127
  }
139
128
  return result;
140
129
  }
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
- }
@@ -27,6 +27,18 @@ export function nativeToolOutcomeFact(identity, callId, status, presentationTurn
27
27
  callId: nativeDeliveryId(identity.scope, identity.runId, `call:${callId}`), status };
28
28
  }
29
29
  const hash = value => createHash('sha256').update(canonical(value)).digest('hex');
30
+ /** Delivery atoms are idempotent: a repeated key must carry identical content.
31
+ * A mismatch means either the journal was written by an older delivery contract
32
+ * or a retried delivery changed its payload. Failing the whole projection makes
33
+ * the session history unreadable, so keep the first delivered atom and skip the
34
+ * conflicting duplicate (the host then renders the first delivery). */
35
+ const reportedDeliveryConflicts = new Set();
36
+ function reportDeliveryConflict(key) {
37
+ if (reportedDeliveryConflicts.has(key)) return;
38
+ reportedDeliveryConflicts.add(key);
39
+ console.warn('[agentkit-harness] native delivery atom conflict; keeping the first atom', { key });
40
+ }
41
+
30
42
  const ownObject = value => value !== null && typeof value === 'object' && !Array.isArray(value);
31
43
 
32
44
  /** Public display deltas only. Opaque replay/signatures and tool previews are never content. */
@@ -113,7 +125,10 @@ export function nativeDeliveryProjection() {
113
125
  const key = atomKey(event);
114
126
  if (key === null) return state;
115
127
  const fingerprint = atomDigest(event);
116
- invariant(!Object.hasOwn(state.atoms, key) || state.atoms[key] === fingerprint, 'native_delivery_atom_conflict');
128
+ if (Object.hasOwn(state.atoms, key) && state.atoms[key] !== fingerprint) {
129
+ reportDeliveryConflict(key);
130
+ return state;
131
+ }
117
132
  const head = event.type === 'system/message' && event.surfaceOp
118
133
  ? { id: event.data.message.id, seq: event.seq, content: event.data.message.content } : state.head;
119
134
  return { ...state, atoms: { ...state.atoms, [key]: fingerprint }, seqs: { ...state.seqs, [key]: event.seq }, head,
@@ -171,7 +186,10 @@ export function createNativeSessionDelivery({ store, scope, runId, session, turn
171
186
  const event = { type, data, ...options }, key = atomKey(event);
172
187
  invariant(key !== null, 'native_delivery_event_invalid');
173
188
  const fingerprint = atomDigest(event), previous = state().atoms[key];
174
- if (previous !== undefined) { invariant(previous === fingerprint, 'native_delivery_atom_conflict'); return state().seqs[key]; }
189
+ if (previous !== undefined) {
190
+ if (previous !== fingerprint) reportDeliveryConflict(key);
191
+ return state().seqs[key];
192
+ }
175
193
  session.append(type, data, options);
176
194
  invariant(state().atoms[key] === fingerprint, 'native_delivery_projection_not_advanced');
177
195
  return state().seqs[key];