@sema-agent/client-core 0.12.1 → 0.13.0
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/README.md +15 -2
- package/dist/abortableSleep.d.ts +29 -0
- package/dist/abortableSleep.js +43 -0
- package/dist/adapt/arms.d.ts +58 -0
- package/dist/adapt/arms.js +613 -0
- package/dist/adapt/ids.d.ts +22 -0
- package/dist/adapt/ids.js +34 -0
- package/dist/adapt/instanceLedger.d.ts +36 -0
- package/dist/adapt/instanceLedger.js +50 -0
- package/dist/adapt/panelTasks.d.ts +54 -0
- package/dist/adapt/panelTasks.js +193 -0
- package/dist/adapt/textStream.d.ts +49 -0
- package/dist/adapt/textStream.js +141 -0
- package/dist/adapt/toolCards.d.ts +65 -0
- package/dist/adapt/toolCards.js +100 -0
- package/dist/adapt/turnFlags.d.ts +33 -0
- package/dist/adapt/turnFlags.js +55 -0
- package/dist/adapt/wireShapes.d.ts +93 -0
- package/dist/adapt/wireShapes.js +167 -0
- package/dist/adapt.d.ts +32 -59
- package/dist/adapt.js +78 -1206
- package/dist/adapter/downstream/eventToSdkMessage.d.ts +55 -13
- package/dist/adapter/downstream/eventToSdkMessage.js +166 -106
- package/dist/adapter/downstream/terminalToSdkResult.js +149 -160
- package/dist/adapter/downstream/turnUsageToModelUsage.d.ts +36 -0
- package/dist/adapter/downstream/turnUsageToModelUsage.js +34 -6
- package/dist/adapter/runStream.d.ts +29 -4
- package/dist/adapter/runStream.js +129 -13
- package/dist/adapter/types.d.ts +2 -2
- package/dist/agentSession/backgroundView.js +4 -15
- package/dist/agentsWireCaps.d.ts +10 -6
- package/dist/agentsWireCaps.js +21 -7
- package/dist/argvFlagValue.d.ts +41 -0
- package/dist/argvFlagValue.js +69 -0
- package/dist/attachmentsWireCaps.d.ts +3 -2
- package/dist/attachmentsWireCaps.js +5 -3
- package/dist/classifierVerdictWire.d.ts +8 -0
- package/dist/classifierVerdictWire.js +8 -0
- package/dist/cloudConfigWireCaps.d.ts +28 -1
- package/dist/cloudConfigWireCaps.js +51 -11
- package/dist/controlRouter.d.ts +14 -8
- package/dist/controlRouter.js +15 -21
- package/dist/detachWire.d.ts +15 -5
- package/dist/detachWire.js +17 -7
- package/dist/effortWire.d.ts +0 -21
- package/dist/effortWire.js +6 -20
- package/dist/engineInlineTaskStats.d.ts +12 -6
- package/dist/engineWireSdk.d.ts +12 -0
- package/dist/env/localeGeo.js +2 -1
- package/dist/envFlag.d.ts +39 -0
- package/dist/envFlag.js +51 -0
- package/dist/finalVerifyWire.d.ts +7 -5
- package/dist/finalVerifyWire.js +6 -5
- package/dist/fleet/fleetLedger.d.ts +32 -9
- package/dist/fleet/fleetLedger.js +119 -34
- package/dist/fleet/fleetProjection.d.ts +44 -6
- package/dist/fleet/fleetProjection.js +52 -10
- package/dist/fleetAgentPanelProjection.d.ts +18 -1
- package/dist/fleetAgentPanelProjection.js +61 -14
- package/dist/forkWireCaps.d.ts +2 -1
- package/dist/forkWireCaps.js +5 -11
- package/dist/goalStopHook.d.ts +142 -0
- package/dist/goalStopHook.js +258 -0
- package/dist/headlessPermissionModeWire.d.ts +10 -0
- package/dist/headlessPermissionModeWire.js +24 -21
- package/dist/headlessReconnectWire.d.ts +7 -1
- package/dist/headlessReconnectWire.js +20 -2
- package/dist/hitl/approvalsFeed.js +31 -8
- package/dist/hitl/askGateWire.d.ts +27 -96
- package/dist/hitl/askGateWire.js +69 -546
- package/dist/hitl/frameRouter.d.ts +86 -0
- package/dist/hitl/frameRouter.js +342 -0
- package/dist/hitl/gateLedger.d.ts +107 -0
- package/dist/hitl/gateLedger.js +113 -0
- package/dist/hitl/hitlBridge.d.ts +75 -15
- package/dist/hitl/hitlBridge.js +94 -22
- package/dist/hitl/hitlHostSurface.d.ts +49 -0
- package/dist/hitl/hitlHostSurface.js +155 -0
- package/dist/hitl/parkResolver.d.ts +74 -0
- package/dist/hitl/parkResolver.js +241 -0
- package/dist/hitl/planReviewWire.d.ts +60 -2
- package/dist/hitl/planReviewWire.js +152 -74
- package/dist/hitl/toolApprovalWire.d.ts +67 -4
- package/dist/hitl/toolApprovalWire.js +119 -31
- package/dist/hooksWireCaps.d.ts +1 -82
- package/dist/hooksWireCaps.js +34 -235
- package/dist/host.d.ts +16 -5
- package/dist/index.d.ts +2 -0
- package/dist/index.js +15 -1
- package/dist/interactiveToolsWire.d.ts +15 -4
- package/dist/interactiveToolsWire.js +24 -26
- package/dist/limitsWire.js +7 -40
- package/dist/liveInitToolFace.d.ts +51 -6
- package/dist/liveQuestionStore.d.ts +5 -6
- package/dist/model/providerPresets.js +11 -1
- package/dist/notifications.d.ts +48 -2
- package/dist/notifications.js +223 -46
- package/dist/retainBackgroundWireCaps.d.ts +3 -2
- package/dist/retainBackgroundWireCaps.js +5 -9
- package/dist/sandboxWire.d.ts +9 -31
- package/dist/sandboxWire.js +51 -50
- package/dist/scenarioWire.d.ts +1 -1
- package/dist/scenarioWire.js +25 -36
- package/dist/seam.d.ts +23 -6
- package/dist/seam.js +40 -30
- package/dist/seatContract.d.ts +369 -83
- package/dist/seatContract.js +585 -198
- package/dist/selfOrchestrationWireCaps.d.ts +6 -5
- package/dist/selfOrchestrationWireCaps.js +8 -12
- package/dist/sessionSlot.d.ts +8 -0
- package/dist/sessionSlot.js +1 -0
- package/dist/steering.js +2 -2
- package/dist/subagent/engineTaskHandleWire.d.ts +3 -0
- package/dist/subagent/engineTaskHandleWire.js +17 -2
- package/dist/subagentContentStore.d.ts +5 -5
- package/dist/toolResult.d.ts +89 -8
- package/dist/toolResult.js +99 -30
- package/dist/typePins.d.ts +17 -0
- package/dist/typePins.js +1 -0
- package/dist/ultracodeWireCaps.js +5 -6
- package/dist/unrefTimer.d.ts +19 -0
- package/dist/unrefTimer.js +5 -0
- package/dist/workflow.d.ts +3 -2
- package/dist/workflow.js +3 -2
- package/dist/workflowClient.d.ts +7 -0
- package/dist/workflowClient.js +47 -12
- package/package.json +3 -3
package/dist/workflowClient.js
CHANGED
|
@@ -57,6 +57,7 @@
|
|
|
57
57
|
* state once one resolves. `dispose()` aborts the stream + stops the background loop on host unmount.
|
|
58
58
|
*/
|
|
59
59
|
import { APIError } from '@sema-agent/sdk';
|
|
60
|
+
import { abortableSleep } from './abortableSleep.js';
|
|
60
61
|
import { engineSessionParamSpread } from './engineSessionParam.js';
|
|
61
62
|
import { makeEngineWireClient } from './engineWireSdk.js';
|
|
62
63
|
import { engineWireDebugEnabled } from './engineWireTarget.js';
|
|
@@ -246,13 +247,14 @@ function stripPhase(a) {
|
|
|
246
247
|
* one phase per distinct tag; (3) neither → a single synthetic 'Workflow' phase holding every agent. */
|
|
247
248
|
function projectPhases(run, agents) {
|
|
248
249
|
const raw = readPhases(run);
|
|
249
|
-
|
|
250
|
+
const firstRaw = raw[0];
|
|
251
|
+
if (raw.length > 0 && firstRaw !== undefined) {
|
|
250
252
|
const known = new Set(raw.map(p => p.title));
|
|
251
253
|
const buckets = new Map();
|
|
252
254
|
for (const p of raw)
|
|
253
255
|
buckets.set(p.title, []);
|
|
254
256
|
for (const a of agents) {
|
|
255
|
-
const t = a._phase && known.has(a._phase) ? a._phase :
|
|
257
|
+
const t = a._phase && known.has(a._phase) ? a._phase : firstRaw.title;
|
|
256
258
|
buckets.get(t).push(a);
|
|
257
259
|
}
|
|
258
260
|
return raw.map(p => {
|
|
@@ -318,6 +320,23 @@ export function projectWorkflowRun(run) {
|
|
|
318
320
|
state.description = run.description;
|
|
319
321
|
return state;
|
|
320
322
|
}
|
|
323
|
+
// ── 轮询/退避节拍(REF-CC-131,域词表-15):三个 3000ms 常量语义各不相同,拆开命名——合并成一个
|
|
324
|
+
// 会把三条独立的退避策略绑死在一起(其中任一策略调优都会误伤另外两条)。──────────────────────
|
|
325
|
+
/** owner 名下暂无任何 run(`resolveRunId` 回 null)时的重试间隔:不是错误,只是「还没有可监的
|
|
326
|
+
* run」——退避到下一次 list() 重试,给一个正在被启动的 run 留出出现的时间。 */
|
|
327
|
+
const NO_RUN_BACKOFF_MS = 3000;
|
|
328
|
+
/** `refresh()` 判定 degraded(501 S8-off / 404 gone)后的重试间隔:不再尝试 stream(),直接退避
|
|
329
|
+
* 重跑外层循环——与 NO_RUN_BACKOFF_MS 数值巧合相同但触发条件不同(有 run id 但拿不到快照)。 */
|
|
330
|
+
const DEGRADED_BACKOFF_MS = 3000;
|
|
331
|
+
/** consume() 外层 catch 兜到的未归类异常(list/refresh 之外的意外)后的退避间隔——保守值,
|
|
332
|
+
* 与前两个 3000 又是同一个数字、不同的触发路径,故各自具名而非合一常量。 */
|
|
333
|
+
const UNEXPECTED_ERROR_BACKOFF_MS = 3000;
|
|
334
|
+
/** stream() 以「无终帧」收场(丢连,非可续传)之后、重新 re-`get()` 快照前的退避间隔——比另外
|
|
335
|
+
* 三个短,因为这是「已知在连接一个存在的 run」而不是「不确定还有没有事可做」。 */
|
|
336
|
+
const STREAM_DROP_BACKOFF_MS = 1000;
|
|
337
|
+
/** stream() ticker 帧触达时,距上一次 `refresh()` 的最小间隔——节流 re-GET 频率,不是退避:
|
|
338
|
+
* 帧到来表示「有变化」,但没必要每一帧都打一次权威快照。 */
|
|
339
|
+
const REFRESH_THROTTLE_MS = 400;
|
|
321
340
|
/**
|
|
322
341
|
* createLiveWorkflowSource({ baseUrl, authToken, principal, workflowId? }) — the LIVE workflow-monitor source.
|
|
323
342
|
*
|
|
@@ -360,10 +379,17 @@ export function createLiveWorkflowSource(config) {
|
|
|
360
379
|
...(config.authToken ? { token: config.authToken } : {}),
|
|
361
380
|
principal: config.principal,
|
|
362
381
|
maxRetries: 2,
|
|
382
|
+
...(config.fetchImpl ? { fetchImpl: config.fetchImpl } : {}),
|
|
363
383
|
});
|
|
364
384
|
const abort = new AbortController();
|
|
365
385
|
/** record a degrade/error WITHOUT throwing: 501 (S8 off) / 404 (non-owner|absent) are EXPECTED degrades;
|
|
366
|
-
* anything else (connection refused, parse) is a soft error — either way the host keeps the mock/empty.
|
|
386
|
+
* anything else (connection refused, parse) is a soft error — either way the host keeps the mock/empty.
|
|
387
|
+
*
|
|
388
|
+
* REF-CC-153(midband-01,fix-outright):the non-APIError branch must explicitly clear `code`/`degraded`
|
|
389
|
+
* rather than leave a prior call's values sitting there — `status().code` is documented as "the HTTP
|
|
390
|
+
* status behind a degrade (501/404), else null", so a stale 404 surviving into a later connection-refused
|
|
391
|
+
* error would misreport an unrelated failure as "still a 404 (run gone)".
|
|
392
|
+
*/
|
|
367
393
|
function noteDegrade(err) {
|
|
368
394
|
connected = false;
|
|
369
395
|
if (err instanceof APIError) {
|
|
@@ -372,6 +398,8 @@ export function createLiveWorkflowSource(config) {
|
|
|
372
398
|
lastError = `${err.status} ${err.message}`;
|
|
373
399
|
}
|
|
374
400
|
else {
|
|
401
|
+
code = null;
|
|
402
|
+
degraded = false;
|
|
375
403
|
lastError = err instanceof Error ? err.message : String(err);
|
|
376
404
|
}
|
|
377
405
|
if (engineWireDebugEnabled()) {
|
|
@@ -397,7 +425,12 @@ export function createLiveWorkflowSource(config) {
|
|
|
397
425
|
if (!workflows?.length)
|
|
398
426
|
return null;
|
|
399
427
|
const running = workflows.find(w => w.status === 'running');
|
|
400
|
-
|
|
428
|
+
const firstWorkflow = workflows[0];
|
|
429
|
+
// `workflows.length > 0` above guarantees index 0 exists; noUncheckedIndexedAccess can't see that,
|
|
430
|
+
// so re-check explicitly rather than reach for a non-null assertion.
|
|
431
|
+
if (firstWorkflow === undefined)
|
|
432
|
+
return null;
|
|
433
|
+
return (running ?? firstWorkflow).id;
|
|
401
434
|
}
|
|
402
435
|
/** take the authoritative snapshot + project it; records degrade on failure (never throws). */
|
|
403
436
|
async function refresh(id, signal) {
|
|
@@ -435,13 +468,13 @@ export function createLiveWorkflowSource(config) {
|
|
|
435
468
|
degraded = true;
|
|
436
469
|
code = null;
|
|
437
470
|
connected = false;
|
|
438
|
-
await
|
|
471
|
+
await abortableSleep(NO_RUN_BACKOFF_MS, abort.signal);
|
|
439
472
|
continue;
|
|
440
473
|
}
|
|
441
474
|
await refresh(id, abort.signal);
|
|
442
475
|
// snapshot degraded (501 S8-off / 404 gone) → don't attempt the stream; back off and retry.
|
|
443
476
|
if (degraded) {
|
|
444
|
-
await
|
|
477
|
+
await abortableSleep(DEGRADED_BACKOFF_MS, abort.signal);
|
|
445
478
|
continue;
|
|
446
479
|
}
|
|
447
480
|
try {
|
|
@@ -453,7 +486,7 @@ export function createLiveWorkflowSource(config) {
|
|
|
453
486
|
if (disposed)
|
|
454
487
|
return;
|
|
455
488
|
connected = true;
|
|
456
|
-
if (Date.now() - lastGetAt >=
|
|
489
|
+
if (Date.now() - lastGetAt >= REFRESH_THROTTLE_MS)
|
|
457
490
|
await refresh(id, abort.signal);
|
|
458
491
|
if (degraded)
|
|
459
492
|
break;
|
|
@@ -466,19 +499,21 @@ export function createLiveWorkflowSource(config) {
|
|
|
466
499
|
}
|
|
467
500
|
// stream ended (drop, not resumable) → re-snapshot on the next loop after a small backoff.
|
|
468
501
|
if (!disposed && !abort.signal.aborted)
|
|
469
|
-
await
|
|
502
|
+
await abortableSleep(STREAM_DROP_BACKOFF_MS, abort.signal);
|
|
470
503
|
}
|
|
471
504
|
catch (err) {
|
|
472
505
|
if (disposed || abort.signal.aborted)
|
|
473
506
|
return;
|
|
474
507
|
noteDegrade(err);
|
|
475
|
-
await
|
|
508
|
+
await abortableSleep(UNEXPECTED_ERROR_BACKOFF_MS, abort.signal);
|
|
476
509
|
}
|
|
477
510
|
}
|
|
478
511
|
}
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
512
|
+
// REF-CC-147(域词表-17):此前这里有一个私有 `sleep()`,裸 Promise+定时器形
|
|
513
|
+
// ——不感知 abort:dispose() 唤不醒正在等待的那一轮,循环最多多跑一轮,且未清的 setTimeout 在
|
|
514
|
+
// Node 上继续维持事件循环存活(拖慢 headless `-p` 车道的进程退出)。已改用共享叶 abortableSleep
|
|
515
|
+
// (与 agentSession/backgroundView.ts 同一实现,详见 ./abortableSleep.ts 头注),消费点全改传
|
|
516
|
+
// `abort.signal` ——dispose() 一旦 `abort.abort()`,四处退避里在飞的那一个立即唤醒。
|
|
482
517
|
// 差分① 的 fail-soft 半场:工厂造不出 client(SDK 拒绝构造)⇒ 不起循环、恒 degraded,
|
|
483
518
|
// `snapshot()` 恒 null ⇒ 宿主走它既有的 mock/空态回落。**绝不抛进宿主**(与 501/404/空列表同路)。
|
|
484
519
|
if (client === null) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sema-agent/client-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.0",
|
|
4
4
|
"description": "Client-side session runtime shared by every sema human client (TUI / web / desktop): sema wire frames (AgentEvent) -> CC session vocabulary (SDKMessage) with dual-plane output (transcript/chrome), deterministic transcript ids, lane discipline as a type, and the notification/dedup ledgers. Every CC-skin shape is collected here so the wire itself stays neutral. Blackboard [1832] design axioms; [1651]/[1652]/[1653] signed seam design. Renamed from @sema-agent/wire-cc-adapter (0.1.x).",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -28,11 +28,11 @@
|
|
|
28
28
|
},
|
|
29
29
|
"peerDependencies": {
|
|
30
30
|
"@sema-agent/agent-types": ">=0.2.0",
|
|
31
|
-
"@sema-agent/sdk": ">=
|
|
31
|
+
"@sema-agent/sdk": ">=4.1.0"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"@sema-agent/agent-types": "^0.2.0",
|
|
35
|
-
"@sema-agent/sdk": "^
|
|
35
|
+
"@sema-agent/sdk": "^4.1.0",
|
|
36
36
|
"esbuild": "^0.27.4",
|
|
37
37
|
"typescript": "^6.0.2"
|
|
38
38
|
}
|