@kingsoftcloud/agentkit-harness-node 0.0.15 → 0.0.17
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 +24 -18
- package/dist/rpc-entry.mjs +24 -18
- package/package.json +2 -2
- package/src/native/activity-status.mjs +6 -4
- package/src/native/dsh-turn-runtime.mjs +19 -11
- package/src/native/model-provider-compat.mjs +12 -7
package/dist/index.mjs
CHANGED
|
@@ -373,7 +373,7 @@ function nativeContextStatus(record, { driving = false } = {}) {
|
|
|
373
373
|
|
|
374
374
|
// packages/agentkit-harness-node/src/native/activity-status.mjs
|
|
375
375
|
import { createHash as createHash2 } from "node:crypto";
|
|
376
|
-
import { canonical as canonical4 } from "@kingsoftcloud/agentkit-harness-core";
|
|
376
|
+
import { canonical as canonical4, projectBackgroundCommands } from "@kingsoftcloud/agentkit-harness-core";
|
|
377
377
|
var settledCommandStates = /* @__PURE__ */ new Set(["completed", "failed", "canceled", "timed_out", "output_limit"]);
|
|
378
378
|
function foregroundReceiptState(record, ref, intent) {
|
|
379
379
|
if (ref.sourceRunId !== record.snapshot.runId || intent?.kind !== "tool" || intent.payload.calls?.length !== 1) return null;
|
|
@@ -398,9 +398,11 @@ function nativeActivityStatus(record, { driving = false } = {}) {
|
|
|
398
398
|
const observations = /* @__PURE__ */ new Map();
|
|
399
399
|
for (const event of record.events ?? []) if (event.kind === "background.commands_observed")
|
|
400
400
|
for (const command of event.payload.commands ?? []) observations.set(command.taskId, command);
|
|
401
|
-
const
|
|
401
|
+
const commands = snapshot.backgroundCommands ?? [];
|
|
402
|
+
const intents = new Map(record.intents.map((intent) => [intent.operationKey, intent]));
|
|
403
|
+
const terminals = projectBackgroundCommands(commands, 128).map(({ ref }) => {
|
|
402
404
|
const observed = observations.get(ref.taskId);
|
|
403
|
-
const intent =
|
|
405
|
+
const intent = intents.get(ref.operationKey);
|
|
404
406
|
const calls = intent?.payload.calls ?? [];
|
|
405
407
|
const call = calls.length === 1 ? calls[0] : null;
|
|
406
408
|
return {
|
|
@@ -423,7 +425,7 @@ function nativeActivityStatus(record, { driving = false } = {}) {
|
|
|
423
425
|
omittedItems: Math.max(0, todos.length - items.length)
|
|
424
426
|
} : null,
|
|
425
427
|
terminals,
|
|
426
|
-
omittedTerminals:
|
|
428
|
+
omittedTerminals: commands.length - terminals.length
|
|
427
429
|
};
|
|
428
430
|
}
|
|
429
431
|
|
|
@@ -2007,6 +2009,7 @@ function taggedPrefixProjector(marker) {
|
|
|
2007
2009
|
}
|
|
2008
2010
|
|
|
2009
2011
|
// packages/agentkit-harness-node/src/native/model-provider-compat.mjs
|
|
2012
|
+
import { FINAL_SUBMISSION_TOOL as FINAL_SUBMISSION_TOOL2 } from "@kingsoftcloud/agentkit-harness-core";
|
|
2010
2013
|
var strict = /* @__PURE__ */ new Set(["openai", "strict-openai", "cerebras", "groq"]);
|
|
2011
2014
|
var requiredAuto = /* @__PURE__ */ new Set(["claude-opus-5-5", "claude-sonnet-5-5", "claude-fable-5-1", "claude-mythos-5-1"]);
|
|
2012
2015
|
var mandatory = /* @__PURE__ */ new Set(["claude-fable-5-1", "claude-opus-5-5", "claude-sonnet-5-5"]);
|
|
@@ -2037,26 +2040,28 @@ function applyAnthropicThinking(payload, profile, binding) {
|
|
|
2037
2040
|
}
|
|
2038
2041
|
function resolveProviderCompatibility(policy, binding) {
|
|
2039
2042
|
if (!policy) return null;
|
|
2040
|
-
|
|
2043
|
+
const version = ["provider-compat/v1", "provider-compat/v2", "provider-compat/v3", "provider-compat/v4", "provider-compat/v5"].indexOf(policy.contract) + 1;
|
|
2044
|
+
if (!version) throw new ProtocolError("invalid_provider_compatibility_policy");
|
|
2041
2045
|
const rule = resolveCompatibilityRule(policy.rule, binding);
|
|
2042
2046
|
const name = String(binding.model ?? "").trim().toLowerCase();
|
|
2043
2047
|
const kimi = ["kspmas-gateway", "moonshot"].includes(rule) && ["kimi-k2.7-code", "kimi-k2.7-code-highspeed"].includes(name);
|
|
2044
|
-
const modern =
|
|
2048
|
+
const modern = version >= 3;
|
|
2045
2049
|
const reasoningRequired = modern && rule === "kspmas-gateway" && name === "glm-5.3-flash";
|
|
2046
2050
|
const disabledEfforts = mandatory.has(name) || reasoningRequired ? [] : name === "claude-haiku-5-5" ? ["low", "medium", "high"] : null;
|
|
2047
2051
|
return {
|
|
2048
2052
|
rule,
|
|
2049
2053
|
supportsUsage: !strict.has(rule),
|
|
2050
2054
|
supportsThinking: !strict.has(rule) && !kimi,
|
|
2051
|
-
supportsToolArgumentStreaming:
|
|
2055
|
+
supportsToolArgumentStreaming: version >= 2 && ["zai", "kspmas-gateway"].includes(rule) && incrementalToolModels.has(normalized(binding.model)),
|
|
2052
2056
|
reasoningRequired,
|
|
2053
2057
|
modern,
|
|
2058
|
+
firstToolLowEffort: version >= 5 && reasoningRequired,
|
|
2054
2059
|
// This route already uses the supported non-thinking mode for tool work.
|
|
2055
2060
|
// A bounded summary has no tools: omitting the switch can instead select
|
|
2056
2061
|
// the provider's default high reasoning and consume its whole output cap.
|
|
2057
2062
|
// Freeze this purpose-specific default only on new admissions; mandatory
|
|
2058
2063
|
// thinking models and explicit caller choices remain authoritative.
|
|
2059
|
-
compactionThinkingOff:
|
|
2064
|
+
compactionThinkingOff: version >= 4 && rule === "kspmas-gateway" && !kimi,
|
|
2060
2065
|
// Only the observed provider/model dialects may seal without [DONE].
|
|
2061
2066
|
finishOnEof: modern && ["permissive", "kspmas-gateway"].includes(rule) && ["minimax-m3", "minimax-m2.5"].includes(name),
|
|
2062
2067
|
supportsEffort: !kimi,
|
|
@@ -2097,7 +2102,9 @@ function applyProviderChatCompatibility(payload, request, binding) {
|
|
|
2097
2102
|
}
|
|
2098
2103
|
const model = binding.model, name = normalized(model);
|
|
2099
2104
|
const requested = options.reasoningEffort ?? result.reasoning_effort ?? null;
|
|
2105
|
+
const mode = options.thinkingMode ?? result.thinking?.type;
|
|
2100
2106
|
let effort = requested;
|
|
2107
|
+
if (requested === null && mode === void 0 && compat.firstToolLowEffort && request.beforeFirstTool && !request.finalizationOnly && result.tool_choice !== "none" && result.tools?.some((tool) => tool.type === "function" && tool.function?.name !== FINAL_SUBMISSION_TOOL2)) effort = "low";
|
|
2101
2108
|
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";
|
|
2102
2109
|
if (requested === null && request.purpose === "compaction" && compat.rule === "kspmas-gateway" && ["glm-5.2", "deepseek-v4-flash"].includes(name)) effort = "none";
|
|
2103
2110
|
if (requested === null && request.purpose === "compaction" && compat.reasoningRequired) effort = "low";
|
|
@@ -2109,7 +2116,6 @@ function applyProviderChatCompatibility(payload, request, binding) {
|
|
|
2109
2116
|
delete result.stream_options.include_usage;
|
|
2110
2117
|
if (!Object.keys(result.stream_options).length) delete result.stream_options;
|
|
2111
2118
|
}
|
|
2112
|
-
const mode = options.thinkingMode ?? result.thinking?.type;
|
|
2113
2119
|
if (mode === "disabled" && compat.reasoningRequired) throw new ProtocolError("model_thinking_disable_unsupported");
|
|
2114
2120
|
const mayDisable = compat.supportsThinking && (compat.disabledEfforts === null || compat.disabledEfforts.includes(effort));
|
|
2115
2121
|
const summaryOff = request.purpose === "compaction" && requested === null && compat.rule === "kspmas-gateway" && name === "glm-5.3-flash";
|
|
@@ -2247,7 +2253,7 @@ function mergeChatUsage(previous, reported, policy, finalized = false) {
|
|
|
2247
2253
|
}
|
|
2248
2254
|
|
|
2249
2255
|
// packages/agentkit-harness-node/src/native/model-openai-chat.mjs
|
|
2250
|
-
import { parseModelJson, stringifyModelJson, modelWireToolCall as modelWireToolCall2, FINAL_SUBMISSION_TOOL as
|
|
2256
|
+
import { parseModelJson, stringifyModelJson, modelWireToolCall as modelWireToolCall2, FINAL_SUBMISSION_TOOL as FINAL_SUBMISSION_TOOL3 } from "@kingsoftcloud/agentkit-harness-core";
|
|
2251
2257
|
function strictParseJson(text) {
|
|
2252
2258
|
try {
|
|
2253
2259
|
return parseModelJson(text);
|
|
@@ -2315,13 +2321,13 @@ function buildOpenAIRequest(binding, request) {
|
|
|
2315
2321
|
payload.max_tokens = boundOutputTokens(parameters.max_tokens, profile.maxOutputTokens);
|
|
2316
2322
|
}
|
|
2317
2323
|
const tools = request.tools || [];
|
|
2318
|
-
const advertised = request.finalizationOnly ? tools.filter((tool) => tool.name ===
|
|
2324
|
+
const advertised = request.finalizationOnly ? tools.filter((tool) => tool.name === FINAL_SUBMISSION_TOOL3) : tools;
|
|
2319
2325
|
if (advertised.length) {
|
|
2320
2326
|
payload.tools = advertised.map((tool) => ({
|
|
2321
2327
|
type: "function",
|
|
2322
2328
|
function: { name: tool.name, description: tool.description, parameters: tool.parameters || { type: "object", properties: {} } }
|
|
2323
2329
|
}));
|
|
2324
|
-
payload.tool_choice = request.toolChoice ?? (profile.providerCompatibilityPolicy && request.finalizationOnly ? { type: "function", function: { name:
|
|
2330
|
+
payload.tool_choice = request.toolChoice ?? (profile.providerCompatibilityPolicy && request.finalizationOnly ? { type: "function", function: { name: FINAL_SUBMISSION_TOOL3 } } : "auto");
|
|
2325
2331
|
}
|
|
2326
2332
|
if (profile.parallelToolCalls !== void 0) payload.parallel_tool_calls = profile.parallelToolCalls;
|
|
2327
2333
|
if (profile.temperature !== void 0) payload.temperature = profile.temperature;
|
|
@@ -2811,7 +2817,7 @@ function usageCounters(usage) {
|
|
|
2811
2817
|
}
|
|
2812
2818
|
|
|
2813
2819
|
// packages/agentkit-harness-node/src/native/model-anthropic.mjs
|
|
2814
|
-
import { parseModelJson as parseModelJson2, stringifyModelJson as stringifyModelJson2, parseNativeJson as parseNativeJson3, modelWireToolCall as modelWireToolCall3, FINAL_SUBMISSION_TOOL as
|
|
2820
|
+
import { parseModelJson as parseModelJson2, stringifyModelJson as stringifyModelJson2, parseNativeJson as parseNativeJson3, modelWireToolCall as modelWireToolCall3, FINAL_SUBMISSION_TOOL as FINAL_SUBMISSION_TOOL4 } from "@kingsoftcloud/agentkit-harness-core";
|
|
2815
2821
|
|
|
2816
2822
|
// packages/agentkit-harness-node/src/native/model-anthropic-cache.mjs
|
|
2817
2823
|
var ephemeral = () => ({ type: "ephemeral" });
|
|
@@ -2983,7 +2989,7 @@ function buildAnthropicRequest(binding, request) {
|
|
|
2983
2989
|
payload[key] = value;
|
|
2984
2990
|
}
|
|
2985
2991
|
const tools = request.tools || [];
|
|
2986
|
-
const advertised = request.finalizationOnly && profile.toolCatalogPolicy !== "stable-task/v1" && !native ? tools.filter((tool) => tool.name ===
|
|
2992
|
+
const advertised = request.finalizationOnly && profile.toolCatalogPolicy !== "stable-task/v1" && !native ? tools.filter((tool) => tool.name === FINAL_SUBMISSION_TOOL4) : tools;
|
|
2987
2993
|
if (advertised.length) {
|
|
2988
2994
|
payload.tools = advertised.map((tool) => native ? anthropicToolEntry(tool) : {
|
|
2989
2995
|
name: tool.name,
|
|
@@ -2991,7 +2997,7 @@ function buildAnthropicRequest(binding, request) {
|
|
|
2991
2997
|
input_schema: tool.parameters || { type: "object", properties: {} }
|
|
2992
2998
|
});
|
|
2993
2999
|
const choice = projectProviderToolChoice(
|
|
2994
|
-
request.toolChoice ?? (profile.providerCompatibilityPolicy && request.finalizationOnly && advertised.some((tool) => tool.name ===
|
|
3000
|
+
request.toolChoice ?? (profile.providerCompatibilityPolicy && request.finalizationOnly && advertised.some((tool) => tool.name === FINAL_SUBMISSION_TOOL4) ? { type: "function", function: { name: FINAL_SUBMISSION_TOOL4 } } : "auto"),
|
|
2995
3001
|
resolveProviderCompatibility(profile.providerCompatibilityPolicy, binding)
|
|
2996
3002
|
);
|
|
2997
3003
|
payload.tool_choice = typeof choice === "string" ? { type: choice === "required" ? "any" : choice } : { type: "tool", name: choice.function.name };
|
|
@@ -3591,7 +3597,7 @@ function deepCopy(value) {
|
|
|
3591
3597
|
}
|
|
3592
3598
|
|
|
3593
3599
|
// packages/agentkit-harness-node/src/native/model-responses.mjs
|
|
3594
|
-
import { parseModelJson as parseModelJson3, stringifyModelJson as stringifyModelJson3, modelWireToolCall as modelWireToolCall4, FINAL_SUBMISSION_TOOL as
|
|
3600
|
+
import { parseModelJson as parseModelJson3, stringifyModelJson as stringifyModelJson3, modelWireToolCall as modelWireToolCall4, FINAL_SUBMISSION_TOOL as FINAL_SUBMISSION_TOOL5 } from "@kingsoftcloud/agentkit-harness-core";
|
|
3595
3601
|
function strictParseJson3(text) {
|
|
3596
3602
|
try {
|
|
3597
3603
|
return parseModelJson3(text);
|
|
@@ -3708,7 +3714,7 @@ function buildResponsesRequest(binding, request) {
|
|
|
3708
3714
|
payload.max_output_tokens = boundOutputTokens(parameters.max_output_tokens, profile.maxOutputTokens);
|
|
3709
3715
|
}
|
|
3710
3716
|
const tools = request.tools || [];
|
|
3711
|
-
const advertised = request.finalizationOnly ? tools.filter((tool) => tool.name ===
|
|
3717
|
+
const advertised = request.finalizationOnly ? tools.filter((tool) => tool.name === FINAL_SUBMISSION_TOOL5) : tools;
|
|
3712
3718
|
if (advertised.length) {
|
|
3713
3719
|
payload.tools = advertised.map((tool) => {
|
|
3714
3720
|
const flat = {
|
|
@@ -3719,7 +3725,7 @@ function buildResponsesRequest(binding, request) {
|
|
|
3719
3725
|
};
|
|
3720
3726
|
return flat;
|
|
3721
3727
|
});
|
|
3722
|
-
const choice = request.toolChoice ?? (profile.providerCompatibilityPolicy && request.finalizationOnly ? { type: "function", function: { name:
|
|
3728
|
+
const choice = request.toolChoice ?? (profile.providerCompatibilityPolicy && request.finalizationOnly ? { type: "function", function: { name: FINAL_SUBMISSION_TOOL5 } } : "auto");
|
|
3723
3729
|
payload.tool_choice = typeof choice === "string" ? choice : { type: "function", name: choice.function.name };
|
|
3724
3730
|
payload.parallel_tool_calls = profile.parallelToolCalls ?? true;
|
|
3725
3731
|
}
|
package/dist/rpc-entry.mjs
CHANGED
|
@@ -384,7 +384,7 @@ function nativeContextStatus(record, { driving = false } = {}) {
|
|
|
384
384
|
|
|
385
385
|
// packages/agentkit-harness-node/src/native/activity-status.mjs
|
|
386
386
|
import { createHash as createHash2 } from "node:crypto";
|
|
387
|
-
import { canonical as canonical4 } from "@kingsoftcloud/agentkit-harness-core";
|
|
387
|
+
import { canonical as canonical4, projectBackgroundCommands } from "@kingsoftcloud/agentkit-harness-core";
|
|
388
388
|
var settledCommandStates = /* @__PURE__ */ new Set(["completed", "failed", "canceled", "timed_out", "output_limit"]);
|
|
389
389
|
function foregroundReceiptState(record, ref, intent) {
|
|
390
390
|
if (ref.sourceRunId !== record.snapshot.runId || intent?.kind !== "tool" || intent.payload.calls?.length !== 1) return null;
|
|
@@ -409,9 +409,11 @@ function nativeActivityStatus(record, { driving = false } = {}) {
|
|
|
409
409
|
const observations = /* @__PURE__ */ new Map();
|
|
410
410
|
for (const event of record.events ?? []) if (event.kind === "background.commands_observed")
|
|
411
411
|
for (const command of event.payload.commands ?? []) observations.set(command.taskId, command);
|
|
412
|
-
const
|
|
412
|
+
const commands = snapshot.backgroundCommands ?? [];
|
|
413
|
+
const intents = new Map(record.intents.map((intent) => [intent.operationKey, intent]));
|
|
414
|
+
const terminals = projectBackgroundCommands(commands, 128).map(({ ref }) => {
|
|
413
415
|
const observed = observations.get(ref.taskId);
|
|
414
|
-
const intent =
|
|
416
|
+
const intent = intents.get(ref.operationKey);
|
|
415
417
|
const calls = intent?.payload.calls ?? [];
|
|
416
418
|
const call = calls.length === 1 ? calls[0] : null;
|
|
417
419
|
return {
|
|
@@ -434,7 +436,7 @@ function nativeActivityStatus(record, { driving = false } = {}) {
|
|
|
434
436
|
omittedItems: Math.max(0, todos.length - items.length)
|
|
435
437
|
} : null,
|
|
436
438
|
terminals,
|
|
437
|
-
omittedTerminals:
|
|
439
|
+
omittedTerminals: commands.length - terminals.length
|
|
438
440
|
};
|
|
439
441
|
}
|
|
440
442
|
|
|
@@ -2018,6 +2020,7 @@ function taggedPrefixProjector(marker) {
|
|
|
2018
2020
|
}
|
|
2019
2021
|
|
|
2020
2022
|
// packages/agentkit-harness-node/src/native/model-provider-compat.mjs
|
|
2023
|
+
import { FINAL_SUBMISSION_TOOL as FINAL_SUBMISSION_TOOL2 } from "@kingsoftcloud/agentkit-harness-core";
|
|
2021
2024
|
var strict = /* @__PURE__ */ new Set(["openai", "strict-openai", "cerebras", "groq"]);
|
|
2022
2025
|
var requiredAuto = /* @__PURE__ */ new Set(["claude-opus-5-5", "claude-sonnet-5-5", "claude-fable-5-1", "claude-mythos-5-1"]);
|
|
2023
2026
|
var mandatory = /* @__PURE__ */ new Set(["claude-fable-5-1", "claude-opus-5-5", "claude-sonnet-5-5"]);
|
|
@@ -2048,26 +2051,28 @@ function applyAnthropicThinking(payload, profile, binding) {
|
|
|
2048
2051
|
}
|
|
2049
2052
|
function resolveProviderCompatibility(policy, binding) {
|
|
2050
2053
|
if (!policy) return null;
|
|
2051
|
-
|
|
2054
|
+
const version = ["provider-compat/v1", "provider-compat/v2", "provider-compat/v3", "provider-compat/v4", "provider-compat/v5"].indexOf(policy.contract) + 1;
|
|
2055
|
+
if (!version) throw new ProtocolError("invalid_provider_compatibility_policy");
|
|
2052
2056
|
const rule = resolveCompatibilityRule(policy.rule, binding);
|
|
2053
2057
|
const name = String(binding.model ?? "").trim().toLowerCase();
|
|
2054
2058
|
const kimi = ["kspmas-gateway", "moonshot"].includes(rule) && ["kimi-k2.7-code", "kimi-k2.7-code-highspeed"].includes(name);
|
|
2055
|
-
const modern =
|
|
2059
|
+
const modern = version >= 3;
|
|
2056
2060
|
const reasoningRequired = modern && rule === "kspmas-gateway" && name === "glm-5.3-flash";
|
|
2057
2061
|
const disabledEfforts = mandatory.has(name) || reasoningRequired ? [] : name === "claude-haiku-5-5" ? ["low", "medium", "high"] : null;
|
|
2058
2062
|
return {
|
|
2059
2063
|
rule,
|
|
2060
2064
|
supportsUsage: !strict.has(rule),
|
|
2061
2065
|
supportsThinking: !strict.has(rule) && !kimi,
|
|
2062
|
-
supportsToolArgumentStreaming:
|
|
2066
|
+
supportsToolArgumentStreaming: version >= 2 && ["zai", "kspmas-gateway"].includes(rule) && incrementalToolModels.has(normalized(binding.model)),
|
|
2063
2067
|
reasoningRequired,
|
|
2064
2068
|
modern,
|
|
2069
|
+
firstToolLowEffort: version >= 5 && reasoningRequired,
|
|
2065
2070
|
// This route already uses the supported non-thinking mode for tool work.
|
|
2066
2071
|
// A bounded summary has no tools: omitting the switch can instead select
|
|
2067
2072
|
// the provider's default high reasoning and consume its whole output cap.
|
|
2068
2073
|
// Freeze this purpose-specific default only on new admissions; mandatory
|
|
2069
2074
|
// thinking models and explicit caller choices remain authoritative.
|
|
2070
|
-
compactionThinkingOff:
|
|
2075
|
+
compactionThinkingOff: version >= 4 && rule === "kspmas-gateway" && !kimi,
|
|
2071
2076
|
// Only the observed provider/model dialects may seal without [DONE].
|
|
2072
2077
|
finishOnEof: modern && ["permissive", "kspmas-gateway"].includes(rule) && ["minimax-m3", "minimax-m2.5"].includes(name),
|
|
2073
2078
|
supportsEffort: !kimi,
|
|
@@ -2108,7 +2113,9 @@ function applyProviderChatCompatibility(payload, request, binding) {
|
|
|
2108
2113
|
}
|
|
2109
2114
|
const model = binding.model, name = normalized(model);
|
|
2110
2115
|
const requested = options.reasoningEffort ?? result.reasoning_effort ?? null;
|
|
2116
|
+
const mode = options.thinkingMode ?? result.thinking?.type;
|
|
2111
2117
|
let effort = requested;
|
|
2118
|
+
if (requested === null && mode === void 0 && compat.firstToolLowEffort && request.beforeFirstTool && !request.finalizationOnly && result.tool_choice !== "none" && result.tools?.some((tool) => tool.type === "function" && tool.function?.name !== FINAL_SUBMISSION_TOOL2)) effort = "low";
|
|
2112
2119
|
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";
|
|
2113
2120
|
if (requested === null && request.purpose === "compaction" && compat.rule === "kspmas-gateway" && ["glm-5.2", "deepseek-v4-flash"].includes(name)) effort = "none";
|
|
2114
2121
|
if (requested === null && request.purpose === "compaction" && compat.reasoningRequired) effort = "low";
|
|
@@ -2120,7 +2127,6 @@ function applyProviderChatCompatibility(payload, request, binding) {
|
|
|
2120
2127
|
delete result.stream_options.include_usage;
|
|
2121
2128
|
if (!Object.keys(result.stream_options).length) delete result.stream_options;
|
|
2122
2129
|
}
|
|
2123
|
-
const mode = options.thinkingMode ?? result.thinking?.type;
|
|
2124
2130
|
if (mode === "disabled" && compat.reasoningRequired) throw new ProtocolError("model_thinking_disable_unsupported");
|
|
2125
2131
|
const mayDisable = compat.supportsThinking && (compat.disabledEfforts === null || compat.disabledEfforts.includes(effort));
|
|
2126
2132
|
const summaryOff = request.purpose === "compaction" && requested === null && compat.rule === "kspmas-gateway" && name === "glm-5.3-flash";
|
|
@@ -2258,7 +2264,7 @@ function mergeChatUsage(previous, reported, policy, finalized = false) {
|
|
|
2258
2264
|
}
|
|
2259
2265
|
|
|
2260
2266
|
// packages/agentkit-harness-node/src/native/model-openai-chat.mjs
|
|
2261
|
-
import { parseModelJson, stringifyModelJson, modelWireToolCall as modelWireToolCall2, FINAL_SUBMISSION_TOOL as
|
|
2267
|
+
import { parseModelJson, stringifyModelJson, modelWireToolCall as modelWireToolCall2, FINAL_SUBMISSION_TOOL as FINAL_SUBMISSION_TOOL3 } from "@kingsoftcloud/agentkit-harness-core";
|
|
2262
2268
|
function strictParseJson(text) {
|
|
2263
2269
|
try {
|
|
2264
2270
|
return parseModelJson(text);
|
|
@@ -2326,13 +2332,13 @@ function buildOpenAIRequest(binding, request) {
|
|
|
2326
2332
|
payload.max_tokens = boundOutputTokens(parameters.max_tokens, profile.maxOutputTokens);
|
|
2327
2333
|
}
|
|
2328
2334
|
const tools = request.tools || [];
|
|
2329
|
-
const advertised = request.finalizationOnly ? tools.filter((tool) => tool.name ===
|
|
2335
|
+
const advertised = request.finalizationOnly ? tools.filter((tool) => tool.name === FINAL_SUBMISSION_TOOL3) : tools;
|
|
2330
2336
|
if (advertised.length) {
|
|
2331
2337
|
payload.tools = advertised.map((tool) => ({
|
|
2332
2338
|
type: "function",
|
|
2333
2339
|
function: { name: tool.name, description: tool.description, parameters: tool.parameters || { type: "object", properties: {} } }
|
|
2334
2340
|
}));
|
|
2335
|
-
payload.tool_choice = request.toolChoice ?? (profile.providerCompatibilityPolicy && request.finalizationOnly ? { type: "function", function: { name:
|
|
2341
|
+
payload.tool_choice = request.toolChoice ?? (profile.providerCompatibilityPolicy && request.finalizationOnly ? { type: "function", function: { name: FINAL_SUBMISSION_TOOL3 } } : "auto");
|
|
2336
2342
|
}
|
|
2337
2343
|
if (profile.parallelToolCalls !== void 0) payload.parallel_tool_calls = profile.parallelToolCalls;
|
|
2338
2344
|
if (profile.temperature !== void 0) payload.temperature = profile.temperature;
|
|
@@ -2822,7 +2828,7 @@ function usageCounters(usage) {
|
|
|
2822
2828
|
}
|
|
2823
2829
|
|
|
2824
2830
|
// packages/agentkit-harness-node/src/native/model-anthropic.mjs
|
|
2825
|
-
import { parseModelJson as parseModelJson2, stringifyModelJson as stringifyModelJson2, parseNativeJson as parseNativeJson3, modelWireToolCall as modelWireToolCall3, FINAL_SUBMISSION_TOOL as
|
|
2831
|
+
import { parseModelJson as parseModelJson2, stringifyModelJson as stringifyModelJson2, parseNativeJson as parseNativeJson3, modelWireToolCall as modelWireToolCall3, FINAL_SUBMISSION_TOOL as FINAL_SUBMISSION_TOOL4 } from "@kingsoftcloud/agentkit-harness-core";
|
|
2826
2832
|
|
|
2827
2833
|
// packages/agentkit-harness-node/src/native/model-anthropic-cache.mjs
|
|
2828
2834
|
var ephemeral = () => ({ type: "ephemeral" });
|
|
@@ -2994,7 +3000,7 @@ function buildAnthropicRequest(binding, request) {
|
|
|
2994
3000
|
payload[key] = value;
|
|
2995
3001
|
}
|
|
2996
3002
|
const tools = request.tools || [];
|
|
2997
|
-
const advertised = request.finalizationOnly && profile.toolCatalogPolicy !== "stable-task/v1" && !native ? tools.filter((tool) => tool.name ===
|
|
3003
|
+
const advertised = request.finalizationOnly && profile.toolCatalogPolicy !== "stable-task/v1" && !native ? tools.filter((tool) => tool.name === FINAL_SUBMISSION_TOOL4) : tools;
|
|
2998
3004
|
if (advertised.length) {
|
|
2999
3005
|
payload.tools = advertised.map((tool) => native ? anthropicToolEntry(tool) : {
|
|
3000
3006
|
name: tool.name,
|
|
@@ -3002,7 +3008,7 @@ function buildAnthropicRequest(binding, request) {
|
|
|
3002
3008
|
input_schema: tool.parameters || { type: "object", properties: {} }
|
|
3003
3009
|
});
|
|
3004
3010
|
const choice = projectProviderToolChoice(
|
|
3005
|
-
request.toolChoice ?? (profile.providerCompatibilityPolicy && request.finalizationOnly && advertised.some((tool) => tool.name ===
|
|
3011
|
+
request.toolChoice ?? (profile.providerCompatibilityPolicy && request.finalizationOnly && advertised.some((tool) => tool.name === FINAL_SUBMISSION_TOOL4) ? { type: "function", function: { name: FINAL_SUBMISSION_TOOL4 } } : "auto"),
|
|
3006
3012
|
resolveProviderCompatibility(profile.providerCompatibilityPolicy, binding)
|
|
3007
3013
|
);
|
|
3008
3014
|
payload.tool_choice = typeof choice === "string" ? { type: choice === "required" ? "any" : choice } : { type: "tool", name: choice.function.name };
|
|
@@ -3602,7 +3608,7 @@ function deepCopy(value) {
|
|
|
3602
3608
|
}
|
|
3603
3609
|
|
|
3604
3610
|
// packages/agentkit-harness-node/src/native/model-responses.mjs
|
|
3605
|
-
import { parseModelJson as parseModelJson3, stringifyModelJson as stringifyModelJson3, modelWireToolCall as modelWireToolCall4, FINAL_SUBMISSION_TOOL as
|
|
3611
|
+
import { parseModelJson as parseModelJson3, stringifyModelJson as stringifyModelJson3, modelWireToolCall as modelWireToolCall4, FINAL_SUBMISSION_TOOL as FINAL_SUBMISSION_TOOL5 } from "@kingsoftcloud/agentkit-harness-core";
|
|
3606
3612
|
function strictParseJson3(text) {
|
|
3607
3613
|
try {
|
|
3608
3614
|
return parseModelJson3(text);
|
|
@@ -3719,7 +3725,7 @@ function buildResponsesRequest(binding, request) {
|
|
|
3719
3725
|
payload.max_output_tokens = boundOutputTokens(parameters.max_output_tokens, profile.maxOutputTokens);
|
|
3720
3726
|
}
|
|
3721
3727
|
const tools = request.tools || [];
|
|
3722
|
-
const advertised = request.finalizationOnly ? tools.filter((tool) => tool.name ===
|
|
3728
|
+
const advertised = request.finalizationOnly ? tools.filter((tool) => tool.name === FINAL_SUBMISSION_TOOL5) : tools;
|
|
3723
3729
|
if (advertised.length) {
|
|
3724
3730
|
payload.tools = advertised.map((tool) => {
|
|
3725
3731
|
const flat = {
|
|
@@ -3730,7 +3736,7 @@ function buildResponsesRequest(binding, request) {
|
|
|
3730
3736
|
};
|
|
3731
3737
|
return flat;
|
|
3732
3738
|
});
|
|
3733
|
-
const choice = request.toolChoice ?? (profile.providerCompatibilityPolicy && request.finalizationOnly ? { type: "function", function: { name:
|
|
3739
|
+
const choice = request.toolChoice ?? (profile.providerCompatibilityPolicy && request.finalizationOnly ? { type: "function", function: { name: FINAL_SUBMISSION_TOOL5 } } : "auto");
|
|
3734
3740
|
payload.tool_choice = typeof choice === "string" ? choice : { type: "function", name: choice.function.name };
|
|
3735
3741
|
payload.parallel_tool_calls = profile.parallelToolCalls ?? true;
|
|
3736
3742
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kingsoftcloud/agentkit-harness-node",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.17",
|
|
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.",
|
|
@@ -140,7 +140,7 @@
|
|
|
140
140
|
"src/package-integrity.mjs"
|
|
141
141
|
],
|
|
142
142
|
"dependencies": {
|
|
143
|
-
"@kingsoftcloud/agentkit-harness-core": "0.0.
|
|
143
|
+
"@kingsoftcloud/agentkit-harness-core": "0.0.17",
|
|
144
144
|
"@astral-sh/ruff-wasm-nodejs": "0.16.8",
|
|
145
145
|
"parse5": "7.3.0",
|
|
146
146
|
"playwright-core": "1.58.2",
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createHash } from 'node:crypto';
|
|
2
|
-
import { canonical } from '@kingsoftcloud/agentkit-harness-core';
|
|
2
|
+
import { canonical, projectBackgroundCommands } from '@kingsoftcloud/agentkit-harness-core';
|
|
3
3
|
|
|
4
4
|
const settledCommandStates = new Set(['completed', 'failed', 'canceled', 'timed_out', 'output_limit']);
|
|
5
5
|
|
|
@@ -44,9 +44,11 @@ export function nativeActivityStatus(record, { driving = false } = {}) {
|
|
|
44
44
|
const observations = new Map();
|
|
45
45
|
for (const event of record.events ?? []) if (event.kind === 'background.commands_observed')
|
|
46
46
|
for (const command of event.payload.commands ?? []) observations.set(command.taskId, command);
|
|
47
|
-
const
|
|
47
|
+
const commands = snapshot.backgroundCommands ?? [];
|
|
48
|
+
const intents = new Map(record.intents.map(intent => [intent.operationKey, intent]));
|
|
49
|
+
const terminals = projectBackgroundCommands(commands, 128).map(({ ref }) => {
|
|
48
50
|
const observed = observations.get(ref.taskId);
|
|
49
|
-
const intent =
|
|
51
|
+
const intent = intents.get(ref.operationKey);
|
|
50
52
|
const calls = intent?.payload.calls ?? [];
|
|
51
53
|
const call = calls.length === 1 ? calls[0] : null;
|
|
52
54
|
return { id: ref.taskId, runId: snapshot.runId,
|
|
@@ -57,5 +59,5 @@ export function nativeActivityStatus(record, { driving = false } = {}) {
|
|
|
57
59
|
isRunning: driving, plan: todos.length ? { items,
|
|
58
60
|
completedCount: todos.filter(todo => todo.status === 'completed').length, totalCount: todos.length,
|
|
59
61
|
omittedItems: Math.max(0, todos.length - items.length) } : null,
|
|
60
|
-
terminals, omittedTerminals:
|
|
62
|
+
terminals, omittedTerminals: commands.length - terminals.length };
|
|
61
63
|
}
|
|
@@ -280,10 +280,14 @@ export function createNativeDshTurnExecutor({ store, resolveTurn, resolveRecover
|
|
|
280
280
|
taskChainId: binding.taskChainId ?? sessionId };
|
|
281
281
|
const start = () => background ? store.load(scope, runId).snapshot : kernel.start({ ...identity, parentRunId: null }, configuration,
|
|
282
282
|
durableOwnership || binding.taskContractFactory ? { expectedParentRunId: parentRunId } : {});
|
|
283
|
-
let idleApproval = null;
|
|
284
283
|
// The SDK disposes the owner on graceful Host shutdown. A persisted
|
|
285
|
-
// approval wait has no live effect to cancel and may be rebound later
|
|
286
|
-
|
|
284
|
+
// approval wait has no live effect to cancel and may be rebound later,
|
|
285
|
+
// including shutdown between its commit and the idle driver registering.
|
|
286
|
+
const detachingApproval = () => {
|
|
287
|
+
if (!durableOwnership || cancelReason(signal.reason)?.kind !== 'disposed') return null;
|
|
288
|
+
const { snapshot } = store.load(scope, runId);
|
|
289
|
+
return snapshot.phase === 'awaiting_interaction' && snapshot.pendingIntent === null ? snapshot : null;
|
|
290
|
+
};
|
|
287
291
|
const persistCancel = () => {
|
|
288
292
|
if (detachingApproval()) return;
|
|
289
293
|
const commandId = `${runId}:dsh-turn-cancel`;
|
|
@@ -329,14 +333,17 @@ export function createNativeDshTurnExecutor({ store, resolveTurn, resolveRecover
|
|
|
329
333
|
}
|
|
330
334
|
}
|
|
331
335
|
let snapshot;
|
|
336
|
+
// The durable DSH listener above owns cancellation and interrupts the
|
|
337
|
+
// worker by submitting its command. A second generic Kernel listener
|
|
338
|
+
// would enqueue an unconditional cancel at the approval checkpoint.
|
|
339
|
+
const driveOptions = durableOwnership ? undefined : { signal };
|
|
332
340
|
try {
|
|
333
|
-
snapshot = await kernel.runUntilIdle(scope, runId,
|
|
341
|
+
snapshot = await kernel.runUntilIdle(scope, runId, driveOptions);
|
|
334
342
|
while (!terminal(snapshot.phase)) {
|
|
335
343
|
signal.throwIfAborted();
|
|
336
344
|
if (!onIdle) throw failure('NATIVE_TURN_SUSPENDED', snapshot);
|
|
337
345
|
const idle = new AbortController(), idlePayload = { ...payload, signal: AbortSignal.any([signal, idle.signal]) };
|
|
338
346
|
let command, woken = false;
|
|
339
|
-
idleApproval = snapshot.phase === 'awaiting_interaction' ? snapshot : null;
|
|
340
347
|
wakeIdle = () => { woken = true; idle.abort(new NativeError('native_idle_woken')); };
|
|
341
348
|
try {
|
|
342
349
|
if (store.load(scope, runId).commands.some(row => !row.consumed)) wakeIdle();
|
|
@@ -346,22 +353,21 @@ export function createNativeDshTurnExecutor({ store, resolveTurn, resolveRecover
|
|
|
346
353
|
}), idlePayload);
|
|
347
354
|
} catch (error) {
|
|
348
355
|
if (!woken || signal.aborted) throw error;
|
|
349
|
-
|
|
350
|
-
snapshot = await kernel.runUntilIdle(scope, runId, { signal });
|
|
356
|
+
snapshot = await kernel.runUntilIdle(scope, runId, driveOptions);
|
|
351
357
|
continue;
|
|
352
358
|
} finally { wakeIdle = () => {}; idle.abort(); }
|
|
353
359
|
if (!command) throw failure('NATIVE_TURN_SUSPENDED', snapshot);
|
|
354
360
|
signal.throwIfAborted();
|
|
355
|
-
idleApproval = null;
|
|
356
361
|
const revision = snapshot.revision;
|
|
357
362
|
const receipt = kernel.submit(scope, runId, command);
|
|
358
363
|
invariant(receipt.status !== 'rejected', 'native_dsh_command_rejected');
|
|
359
|
-
snapshot = await kernel.runUntilIdle(scope, runId,
|
|
364
|
+
snapshot = await kernel.runUntilIdle(scope, runId, driveOptions);
|
|
360
365
|
invariant(terminal(snapshot.phase) || snapshot.revision > revision, 'native_dsh_command_made_no_progress');
|
|
361
366
|
}
|
|
362
367
|
signal.throwIfAborted();
|
|
363
368
|
} catch (error) {
|
|
364
|
-
|
|
369
|
+
const approval = detachingApproval();
|
|
370
|
+
if (approval) throw failure('NATIVE_TURN_SUSPENDED', approval);
|
|
365
371
|
if (signal.aborted && !terminal(store.load(scope, runId).snapshot.phase)) {
|
|
366
372
|
// A turn can be canceled while no kernel worker is active (approval
|
|
367
373
|
// or host checkpoint). Persist first, then drain without allowing a
|
|
@@ -501,7 +507,9 @@ export function createNativeDshTurnExecutor({ store, resolveTurn, resolveRecover
|
|
|
501
507
|
// it can only validate the existing notice and enqueue its cancel.
|
|
502
508
|
verified ??= await verifyNativeDshBackgroundOwnership(ownership, { ...facts, signal: new AbortController().signal });
|
|
503
509
|
const { identity } = verified.admission, record = store.load(identity.scope, identity.runId);
|
|
504
|
-
if (!['completed', 'failed', 'canceled'].includes(record.snapshot.phase)
|
|
510
|
+
if (!['completed', 'failed', 'canceled'].includes(record.snapshot.phase)
|
|
511
|
+
&& !(cancelReason(payload.signal.reason)?.kind === 'disposed' && record.snapshot.phase === 'awaiting_interaction'
|
|
512
|
+
&& record.snapshot.pendingIntent === null)) {
|
|
505
513
|
const commandId = `${identity.runId}:dsh-turn-cancel`;
|
|
506
514
|
const previous = record.commands.find(row => row.command.commandId === commandId)?.command;
|
|
507
515
|
new NativeKernel({ store, digest: hash, owner, ports: {} }).submit(identity.scope, identity.runId,
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// Frozen Chat Completions request policy, ported from the pinned Python
|
|
2
2
|
// model_proxy.compat and transform.model-effort-map/v2. No IO or retries here.
|
|
3
|
+
import { FINAL_SUBMISSION_TOOL } from '@kingsoftcloud/agentkit-harness-core';
|
|
3
4
|
import { admitInlineReasoningPolicy, resolveCompatibilityRule } from './model-inline-reasoning.mjs';
|
|
4
5
|
import { ProtocolError } from './model-normalize.mjs';
|
|
5
6
|
|
|
@@ -44,29 +45,30 @@ export function applyAnthropicThinking(payload, profile, binding) {
|
|
|
44
45
|
}
|
|
45
46
|
|
|
46
47
|
export function admitProviderCompatibilityPolicy(override) {
|
|
47
|
-
return { contract: 'provider-compat/
|
|
48
|
+
return { contract: 'provider-compat/v5', rule: admitInlineReasoningPolicy(override).rule };
|
|
48
49
|
}
|
|
49
50
|
|
|
50
51
|
export function resolveProviderCompatibility(policy, binding) {
|
|
51
52
|
if (!policy) return null;
|
|
52
|
-
|
|
53
|
+
const version = ['provider-compat/v1', 'provider-compat/v2', 'provider-compat/v3', 'provider-compat/v4', 'provider-compat/v5'].indexOf(policy.contract) + 1;
|
|
54
|
+
if (!version) throw new ProtocolError('invalid_provider_compatibility_policy');
|
|
53
55
|
const rule = resolveCompatibilityRule(policy.rule, binding);
|
|
54
56
|
const name = String(binding.model ?? '').trim().toLowerCase();
|
|
55
57
|
const kimi = ['kspmas-gateway', 'moonshot'].includes(rule)
|
|
56
58
|
&& ['kimi-k2.7-code', 'kimi-k2.7-code-highspeed'].includes(name);
|
|
57
|
-
const modern =
|
|
59
|
+
const modern = version >= 3;
|
|
58
60
|
const reasoningRequired = modern && rule === 'kspmas-gateway' && name === 'glm-5.3-flash';
|
|
59
61
|
const disabledEfforts = mandatory.has(name) || reasoningRequired ? [] : name === 'claude-haiku-5-5' ? ['low', 'medium', 'high'] : null;
|
|
60
62
|
return { rule, supportsUsage: !strict.has(rule), supportsThinking: !strict.has(rule) && !kimi,
|
|
61
|
-
supportsToolArgumentStreaming:
|
|
63
|
+
supportsToolArgumentStreaming: version >= 2
|
|
62
64
|
&& ['zai', 'kspmas-gateway'].includes(rule) && incrementalToolModels.has(normalized(binding.model)),
|
|
63
|
-
reasoningRequired, modern,
|
|
65
|
+
reasoningRequired, modern, firstToolLowEffort: version >= 5 && reasoningRequired,
|
|
64
66
|
// This route already uses the supported non-thinking mode for tool work.
|
|
65
67
|
// A bounded summary has no tools: omitting the switch can instead select
|
|
66
68
|
// the provider's default high reasoning and consume its whole output cap.
|
|
67
69
|
// Freeze this purpose-specific default only on new admissions; mandatory
|
|
68
70
|
// thinking models and explicit caller choices remain authoritative.
|
|
69
|
-
compactionThinkingOff:
|
|
71
|
+
compactionThinkingOff: version >= 4 && rule === 'kspmas-gateway' && !kimi,
|
|
70
72
|
// Only the observed provider/model dialects may seal without [DONE].
|
|
71
73
|
finishOnEof: modern && ['permissive', 'kspmas-gateway'].includes(rule)
|
|
72
74
|
&& ['minimax-m3', 'minimax-m2.5'].includes(name),
|
|
@@ -105,7 +107,11 @@ export function applyProviderChatCompatibility(payload, request, binding) {
|
|
|
105
107
|
}
|
|
106
108
|
const model = binding.model, name = normalized(model);
|
|
107
109
|
const requested = options.reasoningEffort ?? result.reasoning_effort ?? null;
|
|
110
|
+
const mode = options.thinkingMode ?? result.thinking?.type;
|
|
108
111
|
let effort = requested;
|
|
112
|
+
if (requested === null && mode === undefined && compat.firstToolLowEffort && request.beforeFirstTool
|
|
113
|
+
&& !request.finalizationOnly && result.tool_choice !== 'none'
|
|
114
|
+
&& result.tools?.some(tool => tool.type === 'function' && tool.function?.name !== FINAL_SUBMISSION_TOOL)) effort = 'low';
|
|
109
115
|
if (requested === null && options.controllerReasoningPolicy === 'disclosed-delegate/v1'
|
|
110
116
|
&& ['zai', 'kspmas-gateway'].includes(compat.rule) && name.startsWith('glm-5.3')
|
|
111
117
|
&& result.tools?.some(tool => tool.type === 'function' && tool.function?.name === 'delegate_task')) effort = 'low';
|
|
@@ -119,7 +125,6 @@ export function applyProviderChatCompatibility(payload, request, binding) {
|
|
|
119
125
|
result.stream_options = { ...result.stream_options }; delete result.stream_options.include_usage;
|
|
120
126
|
if (!Object.keys(result.stream_options).length) delete result.stream_options;
|
|
121
127
|
}
|
|
122
|
-
const mode = options.thinkingMode ?? result.thinking?.type;
|
|
123
128
|
if (mode === 'disabled' && compat.reasoningRequired) throw new ProtocolError('model_thinking_disable_unsupported');
|
|
124
129
|
const mayDisable = compat.supportsThinking && (compat.disabledEfforts === null || compat.disabledEfforts.includes(effort));
|
|
125
130
|
const summaryOff = request.purpose === 'compaction' && requested === null && compat.rule === 'kspmas-gateway' && name === 'glm-5.3-flash';
|