@kingsoftcloud/agentkit-harness-node 0.0.8 → 0.0.10
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 +38 -5
- package/dist/rpc-entry.mjs +40 -7
- package/package.json +2 -2
- package/src/native/a2a-tools.mjs +2 -1
- package/src/native/child-merge.mjs +3 -2
- package/src/native/child-readers.mjs +2 -1
- package/src/native/children.mjs +6 -1
- package/src/native/component-tools.mjs +2 -1
- package/src/native/context-profile.mjs +5 -2
- package/src/native/e2b-command-tools.mjs +3 -2
- package/src/native/local-command-tools.mjs +2 -1
- package/src/native/local-resource-profile.mjs +5 -1
- package/src/native/memory-extraction-tools.mjs +2 -1
- package/src/native/memory-tools.mjs +2 -1
- package/src/native/model-openai-chat.mjs +8 -3
- package/src/native/model-provider-compat.mjs +37 -4
- package/src/native/public-tool-result.mjs +34 -0
- package/src/native/skill-disclosure.mjs +10 -6
- package/src/native/skill-tools.mjs +3 -2
- package/src/native/web-tools.mjs +4 -3
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
|
|
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:
|
|
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
|
}
|
package/dist/rpc-entry.mjs
CHANGED
|
@@ -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
|
|
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:
|
|
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
|
}
|
|
@@ -5145,7 +5178,7 @@ function createWorkspaceToolExecutor({ workspaceDir, workspaceReal, granted, exe
|
|
|
5145
5178
|
}
|
|
5146
5179
|
|
|
5147
5180
|
// packages/agentkit-harness-node/src/rpc-entry.mjs
|
|
5148
|
-
import { publicErrorMessage } from "@kingsoftcloud/agentkit-harness-core/error-presentation";
|
|
5181
|
+
import { publicErrorMessage, publicFailureContent } from "@kingsoftcloud/agentkit-harness-core/error-presentation";
|
|
5149
5182
|
var RPC_PROTOCOL_VERSION = "agentkit.native-rpc/v1";
|
|
5150
5183
|
var ERR = {
|
|
5151
5184
|
parse_error: { code: -32700, message: "Parse error" },
|
|
@@ -5160,7 +5193,7 @@ var ERR = {
|
|
|
5160
5193
|
shutting_down: { code: -32005, message: "server shutting down" }
|
|
5161
5194
|
};
|
|
5162
5195
|
var success = (id, result) => ({ jsonrpc: "2.0", id, result });
|
|
5163
|
-
var errorResponse = (id, e, data) => ({ jsonrpc: "2.0", id, error: { code: e.code, message: e.message, ...data ? { data } : {} } });
|
|
5196
|
+
var errorResponse = (id, e, data) => ({ jsonrpc: "2.0", id, error: publicFailureContent({ code: e.code, message: e.message, ...data ? { data } : {} }) });
|
|
5164
5197
|
var sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
5165
5198
|
var digest = (value) => createHash7("sha256").update(canonical7(value)).digest("hex");
|
|
5166
5199
|
var runIdFor = (requestId) => "rpc:" + createHash7("sha256").update(requestId).digest("hex");
|
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.10",
|
|
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.
|
|
140
|
+
"@kingsoftcloud/agentkit-harness-core": "0.0.10",
|
|
141
141
|
"@astral-sh/ruff-wasm-nodejs": "0.16.8",
|
|
142
142
|
"parse5": "7.3.0",
|
|
143
143
|
"playwright-core": "1.58.2",
|
package/src/native/a2a-tools.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { publicToolExecution } from './public-tool-result.mjs';
|
|
1
2
|
/**
|
|
2
3
|
* Native Node A2A tools for the AgentKit Harness.
|
|
3
4
|
*
|
|
@@ -513,5 +514,5 @@ function createA2aToolPort({
|
|
|
513
514
|
sessionId,
|
|
514
515
|
})).digest('hex');
|
|
515
516
|
|
|
516
|
-
return { definitions: definitions.map(item => copy(item)), execute, contract, bindingDigest };
|
|
517
|
+
return { definitions: definitions.map(item => copy(item)), execute: publicToolExecution(execute), contract, bindingDigest };
|
|
517
518
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { canonical, copy, invariant, toolInputRejection, matchesToolExecutionContract } from '@kingsoftcloud/agentkit-harness-core';
|
|
2
2
|
import { loadSessionChild, accountedChildDelivery } from '@kingsoftcloud/agentkit-harness-node/native/owned-child';
|
|
3
3
|
import { createNativeToolAuthority } from './tool-authority.mjs';
|
|
4
|
+
import { publicToolExecution } from './public-tool-result.mjs';
|
|
4
5
|
|
|
5
6
|
export const STUDIO_NATIVE_CHILD_MERGE = 'native.child-file-merge/v2';
|
|
6
7
|
export function nativeChildMergeDefinition() {
|
|
@@ -25,7 +26,7 @@ export function createStudioNativeChildMerge({ scope, sessionId, store, roles, f
|
|
|
25
26
|
const authority = createNativeToolAuthority({ scope: boundScope, sessionId, store, isClosed });
|
|
26
27
|
const error = code => ({ status: 'error', content: { error_code: code, executed: false } });
|
|
27
28
|
return { definition: copy(definition), contract: STUDIO_NATIVE_CHILD_MERGE,
|
|
28
|
-
async execute(request) {
|
|
29
|
+
execute: publicToolExecution(async function execute(request) {
|
|
29
30
|
const signal = request?.signal;
|
|
30
31
|
const body = () => { const value = { ...request }; delete value.signal; return value; };
|
|
31
32
|
let snapshot;
|
|
@@ -93,6 +94,6 @@ export function createStudioNativeChildMerge({ scope, sessionId, store, roles, f
|
|
|
93
94
|
return uncertain(failure?.code || 'child_merge_publication_unknown', failure?.applied);
|
|
94
95
|
return error(failure?.code || 'child_workspace_merge_unavailable');
|
|
95
96
|
}
|
|
96
|
-
},
|
|
97
|
+
}),
|
|
97
98
|
};
|
|
98
99
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { publicToolExecution } from './public-tool-result.mjs';
|
|
1
2
|
// Scoped, paged read-only tools for already-accounted direct children.
|
|
2
3
|
//
|
|
3
4
|
// Ports the pure-read semantics of ksadk/harness/subagent_adapters/native_child_result.py
|
|
@@ -362,5 +363,5 @@ export function createNativeChildResultTools({ scope, childScopes = [scope], sto
|
|
|
362
363
|
}
|
|
363
364
|
}
|
|
364
365
|
|
|
365
|
-
return Object.freeze({ definitions, execute });
|
|
366
|
+
return Object.freeze({ definitions, execute: publicToolExecution(execute) });
|
|
366
367
|
}
|
package/src/native/children.mjs
CHANGED
|
@@ -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 } : {}),
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { publicToolExecution } from './public-tool-result.mjs';
|
|
1
2
|
/**
|
|
2
3
|
* Native component_status tool port.
|
|
3
4
|
*
|
|
@@ -276,5 +277,5 @@ export function createNativeComponentTools({ scope, sessionId, status, assertCur
|
|
|
276
277
|
|
|
277
278
|
function close() { closed = true; }
|
|
278
279
|
|
|
279
|
-
return { contract: NATIVE_COMPONENT_TOOLS_CONTRACT, definitions, execute, close };
|
|
280
|
+
return { contract: NATIVE_COMPONENT_TOOLS_CONTRACT, definitions, execute: publicToolExecution(execute), close };
|
|
280
281
|
}
|
|
@@ -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 { publicToolExecution } from './public-tool-result.mjs';
|
|
1
2
|
// E2B remote background command ToolPort — Node Native tool definitions + factory.
|
|
2
3
|
//
|
|
3
4
|
// Key contracts:
|
|
@@ -479,8 +480,8 @@ function createCommandTools({ sessionId, owner, storeFactory,
|
|
|
479
480
|
}
|
|
480
481
|
}
|
|
481
482
|
|
|
482
|
-
return Object.freeze({ definitions: copy(definitions), async
|
|
483
|
+
return Object.freeze({ definitions: copy(definitions), execute: publicToolExecution(async function executePublic(request) {
|
|
483
484
|
const result = await execute(request);
|
|
484
485
|
return result.content === undefined || request.resultGovernance === 'runtime-artifacts/v1' ? result : boundResult(result);
|
|
485
|
-
}, contract: ownership.contract });
|
|
486
|
+
}), contract: ownership.contract });
|
|
486
487
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { publicToolExecution } from './public-tool-result.mjs';
|
|
1
2
|
import { lstatSync, mkdirSync, realpathSync } from 'node:fs';
|
|
2
3
|
import { isAbsolute, join, relative, resolve, sep } from 'node:path';
|
|
3
4
|
import { canonical, copy, invariant, toolInputRejection } from '@kingsoftcloud/agentkit-harness-core';
|
|
@@ -285,7 +286,7 @@ export function createLocalCommandTransport({ workspaceRoot, stateRoot, sessionI
|
|
|
285
286
|
: errorResult(request?.signal?.aborted ? 'canceled' : error.code ?? 'local_command_error', { executed: false });
|
|
286
287
|
}
|
|
287
288
|
}
|
|
288
|
-
return Object.freeze({ get definitions() { return copy(definitions); }, execute, checkPlanMode,
|
|
289
|
+
return Object.freeze({ get definitions() { return copy(definitions); }, execute: publicToolExecution(execute), checkPlanMode,
|
|
289
290
|
commandId: operationKey => store.commandId(operationKey), reader: createLocalBackgroundReader(store) });
|
|
290
291
|
}
|
|
291
292
|
|
|
@@ -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. */
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { publicToolExecution } from './public-tool-result.mjs';
|
|
1
2
|
import { canonical, copy, invariant, toolInputRejection, assertNativeAuxiliaryToolExecution, assertNativeAuxiliaryReceiptObservation }
|
|
2
3
|
from '@kingsoftcloud/agentkit-harness-core';
|
|
3
4
|
import { memoryDigest, nativeMemoryScopeBindings, nativeMemorySensitiveLabels } from './memory-candidate.mjs';
|
|
@@ -112,5 +113,5 @@ export function createNativeMemoryExtractionTools({ run, store, provider, policy
|
|
|
112
113
|
callId: request.call.callId, result: result.receipt && !result.conflict
|
|
113
114
|
? { status: 'ok', content: result.receipt } : null };
|
|
114
115
|
}
|
|
115
|
-
return { definitions, execute, observeReceipt };
|
|
116
|
+
return { definitions, execute: publicToolExecution(execute), observeReceipt };
|
|
116
117
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { publicToolExecution } from './public-tool-result.mjs';
|
|
1
2
|
import { canonical, copy, invariant, toolInputRejection } from '@kingsoftcloud/agentkit-harness-core';
|
|
2
3
|
import { memoryDigest, nativeMemoryScopeBindings, nativeMemorySensitiveLabels,
|
|
3
4
|
deriveMemoryProfileSlotKey } from './memory-candidate.mjs';
|
|
@@ -325,5 +326,5 @@ export function buildNativeMemoryTools({ policy, principal, lockedDigest, provid
|
|
|
325
326
|
}
|
|
326
327
|
|
|
327
328
|
return Object.freeze({ contract: NATIVE_MEMORY_TOOLS_CONTRACT, definitions: copy(definitions),
|
|
328
|
-
execute, reconcile });
|
|
329
|
+
execute: publicToolExecution(execute), reconcile: publicToolExecution(reconcile) });
|
|
329
330
|
}
|
|
@@ -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/
|
|
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
|
|
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:
|
|
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
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { publicFailureContent, redactDiagnosticText } from '@kingsoftcloud/agentkit-harness-core/error-presentation';
|
|
2
|
+
|
|
3
|
+
function diagnosticContent(content) {
|
|
4
|
+
if (typeof content === 'string') return redactDiagnosticText(content, 1024);
|
|
5
|
+
if (Array.isArray(content)) return content.map(diagnosticContent);
|
|
6
|
+
if (!content || typeof content !== 'object') return content;
|
|
7
|
+
// Text blocks and nested MCP envelopes are diagnostic content on this path;
|
|
8
|
+
// do not traverse call arguments, receipts, media bytes or locators as text.
|
|
9
|
+
return { ...content,
|
|
10
|
+
...(typeof content.text === 'string' ? { text: redactDiagnosticText(content.text, 1024) } : {}),
|
|
11
|
+
...(Object.hasOwn(content, 'content') ? { content: diagnosticContent(content.content) } : {}) };
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/** One public boundary for failed, uncertain and approval-required results.
|
|
15
|
+
* Successful tool data is not diagnostic input. Keep timing, thrown errors,
|
|
16
|
+
* receiver, lifecycle callbacks and effect/interaction identities unchanged.
|
|
17
|
+
*/
|
|
18
|
+
export function publicToolResult(result) {
|
|
19
|
+
if (!result || typeof result !== 'object' || result.status === 'ok') return result;
|
|
20
|
+
const projected = publicFailureContent(result);
|
|
21
|
+
if (Object.hasOwn(projected, 'content')) return { ...projected, content: diagnosticContent(projected.content) };
|
|
22
|
+
// Authorizers may return a top-level decision rather than a ToolResult.
|
|
23
|
+
// The Kernel persists JSON content; absence is null, never undefined. This
|
|
24
|
+
// does not infer executed:false or change the original interaction identity.
|
|
25
|
+
return projected.status === 'approval_required' ? { ...projected, content: null } : projected;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function publicToolExecution(execute) {
|
|
29
|
+
return function (...args) {
|
|
30
|
+
const result = execute.apply(this, args);
|
|
31
|
+
return result && typeof result.then === 'function'
|
|
32
|
+
? result.then(publicToolResult) : publicToolResult(result);
|
|
33
|
+
};
|
|
34
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { publicToolExecution } from './public-tool-result.mjs';
|
|
1
2
|
// Native Skills progressive disclosure port.
|
|
2
3
|
//
|
|
3
4
|
// Ports ksadk/harness/skill_adapters/native_disclosure.py and
|
|
@@ -348,7 +349,7 @@ export function createNativeSkillDisclosurePort({ scope, sessionId, store, sourc
|
|
|
348
349
|
definitions: publicDefinitions,
|
|
349
350
|
contract: SKILL_DISCLOSURE_CONTRACT,
|
|
350
351
|
close() { closed = true; },
|
|
351
|
-
execute(request = {}) {
|
|
352
|
+
execute: publicToolExecution(function execute(request = {}) {
|
|
352
353
|
const { call } = request;
|
|
353
354
|
if (!call?.name) return { status: 'error', content: { code: 'NATIVE_SKILL_CALL_MISSING', executed: false, message: safeMessage('NATIVE_SKILL_CALL_MISSING') } };
|
|
354
355
|
const internalDef = internalDefinitionMap.get(call.name);
|
|
@@ -377,10 +378,13 @@ export function createNativeSkillDisclosurePort({ scope, sessionId, store, sourc
|
|
|
377
378
|
const gAuth = guard.check();
|
|
378
379
|
if (gAuth) return { status: 'error', content: { code: gAuth.code, executed: false, message: safeMessage(gAuth.code) } };
|
|
379
380
|
if (decision !== 'allow') {
|
|
380
|
-
if (typeof decision === 'object' && (decision.status === 'approval_required' || decision.approval_required))
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
381
|
+
if (decision && typeof decision === 'object' && (decision.status === 'approval_required' || decision.approval_required)) {
|
|
382
|
+
if (typeof decision.interactionId !== 'string' || !decision.interactionId.trim())
|
|
383
|
+
return { status: 'error', content: { code: 'NATIVE_SKILL_APPROVAL_INVALID', executed: false, message: 'Approval interaction is required' } };
|
|
384
|
+
return { status: 'approval_required', interactionId: decision.interactionId, content: decision };
|
|
385
|
+
}
|
|
386
|
+
const code = decision && typeof decision === 'object' ? decision.code : 'STUDIO_NATIVE_SKILL_PERMISSION_DENIED';
|
|
387
|
+
const message = decision && typeof decision === 'object' ? decision.message : 'not authorized';
|
|
384
388
|
return { status: 'error', content: { code, executed: false, message } };
|
|
385
389
|
}
|
|
386
390
|
const g1 = guard.check(); if (g1) return { status: 'error', content: { code: g1.code, executed: false, message: safeMessage(g1.code) } };
|
|
@@ -399,6 +403,6 @@ export function createNativeSkillDisclosurePort({ scope, sessionId, store, sourc
|
|
|
399
403
|
return { status: 'error', content: { code: error.code || 'NATIVE_SKILL_ERROR', executed: false, message: 'execution error' } };
|
|
400
404
|
}
|
|
401
405
|
})();
|
|
402
|
-
},
|
|
406
|
+
}),
|
|
403
407
|
};
|
|
404
408
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { publicToolExecution } from './public-tool-result.mjs';
|
|
1
2
|
import { publicErrorMessage, publicErrorCode, publicFailureContent } from '@kingsoftcloud/agentkit-harness-core/error-presentation';
|
|
2
3
|
// Native Skills builtin tools — bounded formal definitions and ToolPort.
|
|
3
4
|
//
|
|
@@ -410,7 +411,7 @@ export function createNativeSkillTools({
|
|
|
410
411
|
|
|
411
412
|
return {
|
|
412
413
|
tools: {
|
|
413
|
-
async execute(request = {}) {
|
|
414
|
+
execute: publicToolExecution(async function execute(request = {}) {
|
|
414
415
|
const { call, signal, scope, runId, sessionId, turnId, buildId,
|
|
415
416
|
parentRunId, taskChainId, operationKey, executionFence, definition } = request;
|
|
416
417
|
|
|
@@ -524,7 +525,7 @@ export function createNativeSkillTools({
|
|
|
524
525
|
}
|
|
525
526
|
return { status: 'error', content: { code: publicErrorCode(error, 'NATIVE_SKILL_ERROR'), executed: false, message: publicErrorMessage(error) } };
|
|
526
527
|
}
|
|
527
|
-
},
|
|
528
|
+
}),
|
|
528
529
|
},
|
|
529
530
|
};
|
|
530
531
|
},
|
package/src/native/web-tools.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { publicToolExecution } from './public-tool-result.mjs';
|
|
1
2
|
/**
|
|
2
3
|
* Native Node web tools for the AgentKit Harness.
|
|
3
4
|
*
|
|
@@ -520,7 +521,7 @@ export function createWebToolTransport({ fetch: fetchImpl, searchFetch = fetchIm
|
|
|
520
521
|
const definitions = nativeWebToolDefinitions(), formal = new Map(definitions.map(item => [item.name, item]));
|
|
521
522
|
return {
|
|
522
523
|
contract: 'agentkit.web-tool-transport/v1', definitions: definitions.map(item => copy(item)),
|
|
523
|
-
async execute(request) {
|
|
524
|
+
execute: publicToolExecution(async function execute(request) {
|
|
524
525
|
const call = request?.call, definition = formal.get(call?.name);
|
|
525
526
|
if (!definition) return { status: 'error', content: { code: 'unknown_tool' } };
|
|
526
527
|
if (!(request.signal instanceof AbortSignal)) return { status: 'error', content: { code: 'invalid_request' } };
|
|
@@ -554,7 +555,7 @@ export function createWebToolTransport({ fetch: fetchImpl, searchFetch = fetchIm
|
|
|
554
555
|
if (error?.code === 'web_authority_stale') return { status: 'error', content: { code: 'web_authority_stale', executed: false } };
|
|
555
556
|
return { status: 'error', content: { ok: false, error_type: 'WebToolError', error_message: 'web tool failed' } };
|
|
556
557
|
}
|
|
557
|
-
},
|
|
558
|
+
}),
|
|
558
559
|
};
|
|
559
560
|
}
|
|
560
561
|
|
|
@@ -639,5 +640,5 @@ export function createNativeWebTools({
|
|
|
639
640
|
// Return fresh deep copies of the definitions so callers cannot mutate the
|
|
640
641
|
// formal map through the returned array (the formal map stays the trusted
|
|
641
642
|
// source of truth for every execute).
|
|
642
|
-
return { definitions: definitions.map(item => copy(item)), execute, contract: NATIVE_WEB_TOOLS_CONTRACT };
|
|
643
|
+
return { definitions: definitions.map(item => copy(item)), execute: publicToolExecution(execute), contract: NATIVE_WEB_TOOLS_CONTRACT };
|
|
643
644
|
}
|