@kingsoftcloud/agentkit-harness-node 0.0.15 → 0.0.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs
CHANGED
|
@@ -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
|
|
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
|
|
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.16",
|
|
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.16",
|
|
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,
|