@kingsoftcloud/agentkit-harness-node 0.0.17 → 0.0.18
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/engine-view.html +566 -0
- package/dist/index.mjs +4 -0
- package/dist/rpc-entry.mjs +4 -0
- package/package.json +16 -2
- package/src/native/child-owner.mjs +8 -4
- package/src/native/children.mjs +12 -7
- package/src/native/command-shell.mjs +28 -3
- package/src/native/engine-client.mjs +83 -0
- package/src/native/engine-context.mjs +47 -0
- package/src/native/engine-hooks.mjs +53 -0
- package/src/native/engine-host-effects.mjs +98 -0
- package/src/native/engine-managed-delivery.mjs +65 -0
- package/src/native/engine-managed-host.mjs +75 -0
- package/src/native/engine-managed-service.mjs +249 -0
- package/src/native/engine-runtime.mjs +480 -0
- package/src/native/engine-server.mjs +454 -0
- package/src/native/engine-service.mjs +281 -0
- package/src/native/engine-tool-policy.mjs +29 -0
- package/src/native/engine-verification.mjs +111 -0
- package/src/native/engine-view-store.mjs +63 -0
- package/src/native/instruction-assembly.mjs +67 -3
- package/src/native/local-background-supervisor.mjs +1 -1
- package/src/native/local-background.mjs +4 -3
- package/src/native/local-command-tools.mjs +10 -7
- package/src/native/native-kernel-events.mjs +103 -0
- package/src/native/native-kernel-permit.mjs +95 -0
- package/src/native/native-managed-execution-grants.mjs +232 -0
- package/src/native/native-managed-injection.mjs +53 -0
- package/src/native/native-managed-interaction.mjs +192 -0
- package/src/native/native-managed-kernel-http.mjs +122 -0
- package/src/native/native-managed-kernel.mjs +922 -0
- package/src/native/native-managed-scoped-control.mjs +116 -0
- package/src/native/native-managed-session-frames.mjs +43 -0
- package/src/native/native-managed-teams-context.mjs +126 -0
- package/src/native/native-teams-callback-authority.mjs +73 -0
- package/src/native/native-teams-context-contract.mjs +272 -0
- package/src/native/native-teams-json.mjs +38 -0
- package/src/native/native-terminal-failure.mjs +53 -0
- package/src/native/sqlite-store.mjs +1 -0
- package/src/native/workspace-tools.mjs +2 -0
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/** Teams transport uses RFC8785, independently of Native's lossless journal
|
|
2
|
+
* codec. In particular -0 serializes as 0; BigInt and unsafe integral numbers
|
|
3
|
+
* cannot be signed as interoperable Teams JSON. */
|
|
4
|
+
import { invariant } from '@kingsoftcloud/agentkit-harness-core';
|
|
5
|
+
|
|
6
|
+
export function canonicalTeamsJson(value) {
|
|
7
|
+
const active = new Set(), check = condition => invariant(condition, 'NATIVE_TEAMS_JSON_INVALID');
|
|
8
|
+
const string = value => { check(value.isWellFormed()); return JSON.stringify(value); };
|
|
9
|
+
function encode(item, depth) {
|
|
10
|
+
check(depth <= 50);
|
|
11
|
+
if (item === null || typeof item === 'boolean') return JSON.stringify(item);
|
|
12
|
+
if (typeof item === 'string') return string(item);
|
|
13
|
+
if (typeof item === 'number') {
|
|
14
|
+
check(Number.isFinite(item) && (!Number.isInteger(item) || Number.isSafeInteger(item)));
|
|
15
|
+
return JSON.stringify(item);
|
|
16
|
+
}
|
|
17
|
+
check(item && typeof item === 'object' && !active.has(item)); active.add(item);
|
|
18
|
+
let result;
|
|
19
|
+
if (Array.isArray(item)) {
|
|
20
|
+
check(Reflect.ownKeys(item).length === item.length + 1);
|
|
21
|
+
result = '[' + Array.from({ length: item.length }, (_, i) => {
|
|
22
|
+
const descriptor = Object.getOwnPropertyDescriptor(item, i); check(descriptor && Object.hasOwn(descriptor, 'value'));
|
|
23
|
+
return encode(descriptor.value, depth + 1);
|
|
24
|
+
}).join(',') + ']';
|
|
25
|
+
} else {
|
|
26
|
+
check(Object.getPrototypeOf(item) === Object.prototype || Object.getPrototypeOf(item) === null);
|
|
27
|
+
const keys = Reflect.ownKeys(item); check(keys.every(key => typeof key === 'string'));
|
|
28
|
+
result = '{' + keys.sort().map(key => {
|
|
29
|
+
const descriptor = Object.getOwnPropertyDescriptor(item, key); check(descriptor.enumerable && Object.hasOwn(descriptor, 'value'));
|
|
30
|
+
return string(key) + ':' + encode(descriptor.value, depth + 1);
|
|
31
|
+
}).join(',') + '}';
|
|
32
|
+
}
|
|
33
|
+
active.delete(item); return result;
|
|
34
|
+
}
|
|
35
|
+
return encode(value, 0);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export const copyTeamsJson = value => JSON.parse(canonicalTeamsJson(value));
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/** Public explanations for stable Native terminal reasons. Never copy a raw
|
|
2
|
+
* provider, tool or exception message into the task conversation. */
|
|
3
|
+
import { validateModelFailure } from '@kingsoftcloud/agentkit-harness-core';
|
|
4
|
+
const messages = Object.freeze({
|
|
5
|
+
effect_outcome_unknown: '操作结果尚未确认。请核对原操作,不会自动重复执行。',
|
|
6
|
+
provider_terminal_error: '模型请求未能完成,请查看运行诊断。',
|
|
7
|
+
model_policy_abort: '模型请求被服务端策略拒绝,请检查模型与任务配置。',
|
|
8
|
+
model_budget_exhausted: '本次运行已达到模型调用预算。',
|
|
9
|
+
execution_budget_exhausted: '本次运行已达到执行时间预算。',
|
|
10
|
+
tool_call_after_budget_exhaustion: '工具调用超过本次运行预算。',
|
|
11
|
+
tool_call_after_finalization_reserve: '工具调用占用了收尾预留预算。',
|
|
12
|
+
continuation_budget_exhausted: '本次运行没有足够预算继续完成任务。',
|
|
13
|
+
context_port_missing: '上下文服务不可用,请检查运行配置。',
|
|
14
|
+
context_compaction_unavailable: '上下文整理未能完成,请检查模型与上下文配置。',
|
|
15
|
+
context_compaction_limit: '本次运行已达到上下文压缩次数上限,任务尚未完成。',
|
|
16
|
+
context_compaction_no_progress: '多次压缩后任务仍无进展,已停止继续消耗模型预算。',
|
|
17
|
+
context_summary_validation_exhausted: '上下文摘要未通过校验,已达到重试上限。',
|
|
18
|
+
context_mandatory_state_over_budget: '任务必需的上下文超过可用预算,无法安全省略后继续。',
|
|
19
|
+
context_finalization_budget_unavailable: '剩余上下文预算不足以完成任务收尾。',
|
|
20
|
+
repeated_tool_error_no_progress: '工具连续失败且任务没有进展,请检查工具配置或输入。',
|
|
21
|
+
verification_report_missing: '任务验证没有返回结果,无法确认完成。',
|
|
22
|
+
child_owner_unavailable: '子任务执行端不可用,请核对原子任务状态。',
|
|
23
|
+
child_receipt_unavailable: '子任务结果尚未确认,请核对原子任务。',
|
|
24
|
+
background_children_unsettled: '后台子任务尚未结算,请核对后继续。',
|
|
25
|
+
browser_session_unavailable: '浏览器会话不可用,请重新建立浏览器连接。',
|
|
26
|
+
recovery_retry_exhausted: '原运行的恢复预算已耗尽,请核对执行记录。',
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
const modelReasons = new Set(['provider_terminal_error', 'provider_retryable_error_retry_exhausted',
|
|
30
|
+
'malformed_tool_call_retry_exhausted', 'model_policy_abort']);
|
|
31
|
+
function modelFailureMessage(value) {
|
|
32
|
+
if (!value) return null;
|
|
33
|
+
try { validateModelFailure(value); } catch { return null; }
|
|
34
|
+
if (value.code === 'http_authentication') return '模型服务拒绝身份认证,请检查模型凭据。';
|
|
35
|
+
if (value.code === 'http_permission') return '模型请求被服务端权限或策略拒绝。';
|
|
36
|
+
if (value.code === 'http_rate_limit') return '模型服务持续限流,本次运行的重试次数已耗尽。';
|
|
37
|
+
if (value.code === 'host_binding') return '模型连接配置未能加载,请检查运行配置。';
|
|
38
|
+
if (value.phase === 'request') return '模型请求在发送前未通过校验,请查看运行诊断。';
|
|
39
|
+
if (value.code === 'stream_timeout' || value.code === 'http_timeout') return '等待模型服务响应超时,本次运行未能完成。';
|
|
40
|
+
if (value.code === 'transport_error') return '与模型服务的连接中断,本次运行未能完成。';
|
|
41
|
+
if (value.code === 'provider_error' || value.code === 'http_server') return '模型服务返回执行错误,本次运行未能完成。';
|
|
42
|
+
if (value.phase === 'stream' || value.phase === 'buffered') return '模型响应未通过协议校验,本次运行已停止,请查看运行诊断。';
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
export function nativePublicTerminalError(phase, reason, modelFailure) {
|
|
46
|
+
if (phase !== 'failed' && phase !== 'interrupted') return null;
|
|
47
|
+
return {
|
|
48
|
+
code: phase === 'interrupted' ? 'NATIVE_EXECUTION_INTERRUPTED' : 'NATIVE_EXECUTION_NOT_COMPLETED',
|
|
49
|
+
message: (modelReasons.has(reason) ? modelFailureMessage(modelFailure) : null) ?? (Object.hasOwn(messages, reason) ? messages[reason] : (phase === 'interrupted'
|
|
50
|
+
? '原运行需要核对后才能继续,不会自动重复可能产生副作用的操作。'
|
|
51
|
+
: 'Native 运行未完成,请检查运行记录和配置。')),
|
|
52
|
+
};
|
|
53
|
+
}
|
|
@@ -636,6 +636,7 @@ export class SqliteRunStore extends TransactionalRunStore {
|
|
|
636
636
|
return scope;
|
|
637
637
|
});
|
|
638
638
|
};
|
|
639
|
+
this.probe = () => { open(); db.prepare('SELECT version FROM native_schema LIMIT 1').get(); };
|
|
639
640
|
this.close = () => { if (!closed) { db.close(); closed = true; } };
|
|
640
641
|
}
|
|
641
642
|
}
|
|
@@ -1108,6 +1108,8 @@ export function createNativeWorkspaceTools({
|
|
|
1108
1108
|
throw e;
|
|
1109
1109
|
}
|
|
1110
1110
|
if (decision === 'deny') return { status: 'error', content: { code: 'policy_denied' } };
|
|
1111
|
+
if (request.definition?.approvalPolicy === 'durable-preflight/v1' && decision?.status === 'approval_required'
|
|
1112
|
+
&& decision.approvalPolicy === request.definition.approvalPolicy && typeof decision.interactionId === 'string') return decision;
|
|
1111
1113
|
if (decision === 'approval_required') {
|
|
1112
1114
|
const pending = store.addPending({
|
|
1113
1115
|
callId: call.callId, name, argumentsDigest: argumentsDigest(call.arguments),
|