@kingsoftcloud/agentkit-harness-node 0.0.8 → 0.0.9

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.
@@ -5145,7 +5145,7 @@ function createWorkspaceToolExecutor({ workspaceDir, workspaceReal, granted, exe
5145
5145
  }
5146
5146
 
5147
5147
  // packages/agentkit-harness-node/src/rpc-entry.mjs
5148
- import { publicErrorMessage } from "@kingsoftcloud/agentkit-harness-core/error-presentation";
5148
+ import { publicErrorMessage, publicFailureContent } from "@kingsoftcloud/agentkit-harness-core/error-presentation";
5149
5149
  var RPC_PROTOCOL_VERSION = "agentkit.native-rpc/v1";
5150
5150
  var ERR = {
5151
5151
  parse_error: { code: -32700, message: "Parse error" },
@@ -5160,7 +5160,7 @@ var ERR = {
5160
5160
  shutting_down: { code: -32005, message: "server shutting down" }
5161
5161
  };
5162
5162
  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 } : {} } });
5163
+ var errorResponse = (id, e, data) => ({ jsonrpc: "2.0", id, error: publicFailureContent({ code: e.code, message: e.message, ...data ? { data } : {} }) });
5164
5164
  var sleep = (ms) => new Promise((r) => setTimeout(r, ms));
5165
5165
  var digest = (value) => createHash7("sha256").update(canonical7(value)).digest("hex");
5166
5166
  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.8",
3
+ "version": "0.0.9",
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.8",
140
+ "@kingsoftcloud/agentkit-harness-core": "0.0.9",
141
141
  "@astral-sh/ruff-wasm-nodejs": "0.16.8",
142
142
  "parse5": "7.3.0",
143
143
  "playwright-core": "1.58.2",
@@ -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
  }
@@ -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
  }
@@ -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 execute(request) {
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 { 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
  }
@@ -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
- return { status: 'approval_required', interactionId: decision.interactionId || '', content: decision };
382
- const code = typeof decision === 'object' ? decision.code : 'STUDIO_NATIVE_SKILL_PERMISSION_DENIED';
383
- const message = typeof decision === 'object' ? decision.message : 'not authorized';
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
  },
@@ -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
  }