happy-imou-cloud 2.0.21 → 2.0.23

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.
Files changed (29) hide show
  1. package/dist/{BaseReasoningProcessor-0nj-PMFc.cjs → BaseReasoningProcessor-BzbDRBqp.cjs} +3 -3
  2. package/dist/{BaseReasoningProcessor-DnVC7liC.mjs → BaseReasoningProcessor-DH3BCCTf.mjs} +3 -3
  3. package/dist/ProviderSelectionHandler-CbkbtIRC.mjs +673 -0
  4. package/dist/ProviderSelectionHandler-meVvz9NZ.cjs +680 -0
  5. package/dist/{api-MGlKcEf3.cjs → api-C4bF6GEA.cjs} +35 -3
  6. package/dist/{api-DJe9WP9M.mjs → api-DX7Vg4Hz.mjs} +35 -4
  7. package/dist/{command-DAlFmWmr.cjs → command-CF6Wi_v2.cjs} +3 -3
  8. package/dist/{command-CfyFnMv2.mjs → command-DicPZ-Up.mjs} +3 -3
  9. package/dist/{index-CgVjDJpt.cjs → index-BybqdOf2.cjs} +63 -15
  10. package/dist/{index-CHXCgpwi.mjs → index-CEJmASSW.mjs} +60 -12
  11. package/dist/index.cjs +3 -3
  12. package/dist/index.mjs +3 -3
  13. package/dist/lib.cjs +1 -1
  14. package/dist/lib.d.cts +108 -105
  15. package/dist/lib.d.mts +108 -105
  16. package/dist/lib.mjs +1 -1
  17. package/dist/{persistence-DLFUNI9q.cjs → persistence-CdqBfAwo.cjs} +1 -1
  18. package/dist/{persistence-CkP90vEt.mjs → persistence-xypxp7ei.mjs} +1 -1
  19. package/dist/{registerKillSessionHandler-Cs_INk4A.cjs → registerKillSessionHandler-BK3fZIch.cjs} +14 -364
  20. package/dist/{registerKillSessionHandler-DsHTZDsU.mjs → registerKillSessionHandler-BNN-_qNu.mjs} +15 -362
  21. package/dist/{runClaude-DAQAEmHe.mjs → runClaude-B-ex_tr3.mjs} +8 -6
  22. package/dist/{runClaude-BGSgcyUp.cjs → runClaude-CT3jCZjH.cjs} +11 -9
  23. package/dist/{runCodex-B2UpSn82.mjs → runCodex-DhbvUtJC.mjs} +9 -7
  24. package/dist/{runCodex-earICaxw.cjs → runCodex-DodH9jhh.cjs} +12 -10
  25. package/dist/{runGemini-BBUmH1Qh.mjs → runGemini-BsFR5Pd3.mjs} +12 -74
  26. package/dist/{runGemini-D5RAIaR0.cjs → runGemini-CeHCZ1l4.cjs} +12 -74
  27. package/package.json +1 -1
  28. package/dist/ProviderSelectionHandler-Bafuy28L.cjs +0 -265
  29. package/dist/ProviderSelectionHandler-R-2r7ItM.mjs +0 -261
@@ -1,10 +1,10 @@
1
1
  'use strict';
2
2
 
3
- var index = require('./index-CgVjDJpt.cjs');
4
- var persistence = require('./persistence-DLFUNI9q.cjs');
3
+ var index = require('./index-BybqdOf2.cjs');
4
+ var persistence = require('./persistence-CdqBfAwo.cjs');
5
5
  var os = require('node:os');
6
6
  var path = require('node:path');
7
- var api = require('./api-MGlKcEf3.cjs');
7
+ var api = require('./api-C4bF6GEA.cjs');
8
8
  var node_crypto = require('node:crypto');
9
9
  var crypto = require('crypto');
10
10
  require('axios');
@@ -261,15 +261,18 @@ async function closeProviderSession(session, opts = {}) {
261
261
  firstError = error;
262
262
  }
263
263
  };
264
- if (opts.archiveReason) {
264
+ if (opts.archiveOnClose || opts.archiveReason) {
265
265
  try {
266
- session.updateMetadata((currentMetadata) => ({
267
- ...currentMetadata,
268
- lifecycleState: "archived",
269
- lifecycleStateSince: Date.now(),
270
- archivedBy: opts.archivedBy ?? "cli",
271
- archiveReason: opts.archiveReason
272
- }));
266
+ session.updateMetadata((currentMetadata) => {
267
+ const { archiveReason: _existingArchiveReason, ...metadataWithoutArchiveReason } = currentMetadata;
268
+ return {
269
+ ...metadataWithoutArchiveReason,
270
+ lifecycleState: "archived",
271
+ lifecycleStateSince: Date.now(),
272
+ archivedBy: opts.archivedBy ?? "cli",
273
+ ...opts.archiveReason ? { archiveReason: opts.archiveReason } : {}
274
+ };
275
+ });
273
276
  } catch (error) {
274
277
  captureError(error);
275
278
  }
@@ -353,356 +356,6 @@ async function syncControlledByUserState(sessionClient, controlledByUser) {
353
356
  });
354
357
  }
355
358
 
356
- function normalizeOptionalText(value) {
357
- if (typeof value !== "string") {
358
- return null;
359
- }
360
- const trimmed = value.trim();
361
- return trimmed.length > 0 ? trimmed : null;
362
- }
363
- function cloneHappyOrgMetadata(happyOrg) {
364
- return {
365
- taskContext: happyOrg?.taskContext ? { ...happyOrg.taskContext } : void 0,
366
- runtime: happyOrg?.runtime ? { ...happyOrg.runtime } : void 0,
367
- activeOwner: happyOrg?.activeOwner ? { ...happyOrg.activeOwner } : null,
368
- repeat: happyOrg?.repeat ? {
369
- threshold: happyOrg.repeat.threshold,
370
- fingerprints: Object.fromEntries(
371
- Object.entries(happyOrg.repeat.fingerprints ?? {}).map(([fingerprint, entry]) => [
372
- fingerprint,
373
- { ...entry }
374
- ])
375
- )
376
- } : void 0,
377
- lastTurnReport: happyOrg?.lastTurnReport ? { ...happyOrg.lastTurnReport } : void 0
378
- };
379
- }
380
- function normalizeHappyOrgMetadata(metadata) {
381
- const happyOrg = cloneHappyOrgMetadata(metadata?.happyOrg);
382
- return {
383
- ...happyOrg,
384
- runtime: happyOrg.runtime ?? {
385
- status: "active",
386
- reason: null
387
- },
388
- repeat: happyOrg.repeat ?? {
389
- threshold: api.HAPPY_ORG_REPEAT_THRESHOLD,
390
- fingerprints: {}
391
- }
392
- };
393
- }
394
- function withHappyOrgMetadata(metadata, happyOrg) {
395
- return {
396
- ...metadata,
397
- happyOrg
398
- };
399
- }
400
- function resetHappyOrgRuntimeForTask(taskContext) {
401
- return {
402
- taskContext,
403
- runtime: {
404
- status: "active",
405
- reason: null
406
- },
407
- activeOwner: null,
408
- repeat: {
409
- threshold: api.HAPPY_ORG_REPEAT_THRESHOLD,
410
- fingerprints: {}
411
- }
412
- };
413
- }
414
- function buildTerminatedStatusMessage(taskId) {
415
- return `Task ${taskId} is terminated. Reopen it with new context, a new decision, or a new resource before continuing.`;
416
- }
417
- function buildOwnerConflictStatusMessage(taskId, ownerAgentId) {
418
- return `Task ${taskId} is already active under owner ${ownerAgentId}. This turn must exit without continuing token usage.`;
419
- }
420
- function inferInterventionType(draft) {
421
- if (draft?.interventionType === "none" || draft?.interventionType === "review_needed" || draft?.interventionType === "blocker" || draft?.interventionType === "decision_needed") {
422
- return draft.interventionType;
423
- }
424
- if (normalizeOptionalText(draft?.decisionNeeded)) {
425
- return "decision_needed";
426
- }
427
- if (normalizeOptionalText(draft?.blockerCode)) {
428
- return "blocker";
429
- }
430
- return "none";
431
- }
432
- function buildFallbackSummary(text, turnStatus) {
433
- const trimmed = text.trim();
434
- if (trimmed) {
435
- return trimmed.replace(/\s+/g, " ").slice(0, 160);
436
- }
437
- return turnStatus === "turn_aborted" ? "Turn aborted before completion." : "Turn completed without a textual summary.";
438
- }
439
- function normalizeTurnReportDraft(draft) {
440
- return {
441
- summary: normalizeOptionalText(draft?.summary)?.replace(/\s+/g, " ").slice(0, 160) ?? null,
442
- interventionType: inferInterventionType(draft),
443
- blockerCode: normalizeOptionalText(draft?.blockerCode),
444
- decisionNeeded: normalizeOptionalText(draft?.decisionNeeded),
445
- targetArtifact: normalizeOptionalText(draft?.targetArtifact)
446
- };
447
- }
448
- function stripCodeFence(text) {
449
- return text.replace(/^```(?:json)?\s*/i, "").replace(/\s*```$/i, "").trim();
450
- }
451
- function extractTaggedTurnReport(text) {
452
- const matcher = new RegExp(
453
- `<${api.HAPPY_ORG_TURN_REPORT_TAG}>\\s*([\\s\\S]*?)\\s*</${api.HAPPY_ORG_TURN_REPORT_TAG}>`,
454
- "gi"
455
- );
456
- let lastMatch = null;
457
- for (let match = matcher.exec(text); match; match = matcher.exec(text)) {
458
- lastMatch = match;
459
- }
460
- if (!lastMatch) {
461
- return {
462
- cleanedText: text.trim(),
463
- draft: null
464
- };
465
- }
466
- const rawBlock = stripCodeFence(lastMatch[1] ?? "");
467
- let draft = null;
468
- try {
469
- const parsed = JSON.parse(rawBlock);
470
- draft = {
471
- summary: normalizeOptionalText(parsed.summary),
472
- interventionType: normalizeOptionalText(parsed.interventionType),
473
- blockerCode: normalizeOptionalText(parsed.blockerCode),
474
- decisionNeeded: normalizeOptionalText(parsed.decisionNeeded),
475
- targetArtifact: normalizeOptionalText(parsed.targetArtifact)
476
- };
477
- } catch {
478
- draft = null;
479
- }
480
- const cleanedText = `${text.slice(0, lastMatch.index)}${text.slice(lastMatch.index + lastMatch[0].length)}`.replace(/\n{3,}/g, "\n\n").trim();
481
- return {
482
- cleanedText,
483
- draft
484
- };
485
- }
486
- function buildRepeatFingerprint(context, blockerCode, targetArtifact) {
487
- if (!blockerCode) {
488
- return null;
489
- }
490
- return [
491
- context.taskId,
492
- context.memberAgentId,
493
- blockerCode,
494
- targetArtifact ?? ""
495
- ].join("::");
496
- }
497
- function buildHappyOrgTurnPrompt(prompt, turn) {
498
- const reopenLines = turn.reopenContext ? [
499
- "",
500
- "This task was explicitly reopened for this turn with the following new inputs:",
501
- turn.reopenContext.newContext ? `- newContext: ${turn.reopenContext.newContext}` : null,
502
- turn.reopenContext.newDecision ? `- newDecision: ${turn.reopenContext.newDecision}` : null,
503
- turn.reopenContext.newResource ? `- newResource: ${turn.reopenContext.newResource}` : null
504
- ].filter(Boolean) : [];
505
- const header = [
506
- "[HAPPY_ORG_TASK_CONTEXT]",
507
- `taskId=${turn.context.taskId}`,
508
- `organizationId=${turn.context.organizationId}`,
509
- `memberAgentId=${turn.context.memberAgentId}`,
510
- `supervisorAgentId=${turn.context.supervisorAgentId}`,
511
- "Stay on this exact task for the whole turn.",
512
- "End your response with exactly one raw JSON block inside these tags and do not wrap it in a markdown code fence:",
513
- `<${api.HAPPY_ORG_TURN_REPORT_TAG}>{"summary":"short factual summary","interventionType":"none","blockerCode":null,"decisionNeeded":null,"targetArtifact":null}</${api.HAPPY_ORG_TURN_REPORT_TAG}>`,
514
- "Allowed interventionType values: none, review_needed, blocker, decision_needed.",
515
- "summary must read like a CEO todo card title: short, actionable, and without long process logs.",
516
- "Use blocker only for problems the organization may still solve internally.",
517
- "Use decision_needed only when a CEO or user decision is required.",
518
- "Use review_needed when supervisor review is needed but the work is not blocked.",
519
- ...reopenLines,
520
- "[/HAPPY_ORG_TASK_CONTEXT]",
521
- "",
522
- prompt
523
- ];
524
- return header.join("\n");
525
- }
526
- function resolveHappyOrgQueuedTurn(opts) {
527
- const metadata = opts.metadata ?? null;
528
- if (!metadata) {
529
- return {
530
- nextMetadata: null,
531
- queuedTurn: null,
532
- blocked: false
533
- };
534
- }
535
- const currentHappyOrg = normalizeHappyOrgMetadata(metadata);
536
- let nextHappyOrg = cloneHappyOrgMetadata(currentHappyOrg);
537
- const messageHappyOrg = opts.message.meta?.happyOrg;
538
- const now = opts.now?.() ?? Date.now();
539
- const createRunId = opts.createRunId ?? ((taskContext2, currentNow) => `${taskContext2.taskId}:${taskContext2.memberAgentId}:${currentNow}`);
540
- if (messageHappyOrg?.taskContext) {
541
- const currentTaskId = currentHappyOrg.taskContext?.taskId ?? null;
542
- if (currentTaskId !== messageHappyOrg.taskContext.taskId) {
543
- nextHappyOrg = resetHappyOrgRuntimeForTask(messageHappyOrg.taskContext);
544
- } else {
545
- nextHappyOrg.taskContext = { ...messageHappyOrg.taskContext };
546
- }
547
- }
548
- const taskContext = nextHappyOrg.taskContext ?? null;
549
- if (!taskContext) {
550
- return {
551
- nextMetadata: metadata,
552
- queuedTurn: null,
553
- blocked: false
554
- };
555
- }
556
- const control = messageHappyOrg?.control;
557
- if (control?.action === "terminate") {
558
- nextHappyOrg.runtime = {
559
- status: "terminated",
560
- reason: normalizeOptionalText(control.reason) ?? "terminated_by_supervisor",
561
- terminatedAt: now
562
- };
563
- nextHappyOrg.activeOwner = null;
564
- return {
565
- nextMetadata: withHappyOrgMetadata(metadata, nextHappyOrg),
566
- queuedTurn: null,
567
- blocked: true,
568
- statusMessage: buildTerminatedStatusMessage(taskContext.taskId)
569
- };
570
- }
571
- const hasReopenInputs = Boolean(
572
- normalizeOptionalText(control?.newContext) || normalizeOptionalText(control?.newDecision) || normalizeOptionalText(control?.newResource)
573
- );
574
- if (nextHappyOrg.runtime?.status === "terminated") {
575
- if (control?.action !== "reopen") {
576
- return {
577
- nextMetadata: withHappyOrgMetadata(metadata, nextHappyOrg),
578
- queuedTurn: null,
579
- blocked: true,
580
- statusMessage: buildTerminatedStatusMessage(taskContext.taskId)
581
- };
582
- }
583
- if (!hasReopenInputs) {
584
- return {
585
- nextMetadata: withHappyOrgMetadata(metadata, nextHappyOrg),
586
- queuedTurn: null,
587
- blocked: true,
588
- statusMessage: `Task ${taskContext.taskId} can only reopen with new context, a new decision, or a new resource.`
589
- };
590
- }
591
- }
592
- const reopenContext = control?.action === "reopen" && hasReopenInputs ? {
593
- newContext: normalizeOptionalText(control.newContext),
594
- newDecision: normalizeOptionalText(control.newDecision),
595
- newResource: normalizeOptionalText(control.newResource)
596
- } : void 0;
597
- if (reopenContext) {
598
- nextHappyOrg.runtime = {
599
- status: "active",
600
- reason: null,
601
- reopenedAt: now
602
- };
603
- } else if (!nextHappyOrg.runtime) {
604
- nextHappyOrg.runtime = {
605
- status: "active",
606
- reason: null
607
- };
608
- }
609
- if (!nextHappyOrg.activeOwner) {
610
- nextHappyOrg.activeOwner = {
611
- ownerAgentId: taskContext.memberAgentId,
612
- ownerRunId: createRunId(taskContext, now),
613
- claimedAt: now
614
- };
615
- } else if (nextHappyOrg.activeOwner.ownerAgentId !== taskContext.memberAgentId) {
616
- return {
617
- nextMetadata: withHappyOrgMetadata(metadata, nextHappyOrg),
618
- queuedTurn: null,
619
- blocked: true,
620
- statusMessage: buildOwnerConflictStatusMessage(
621
- taskContext.taskId,
622
- nextHappyOrg.activeOwner.ownerAgentId
623
- )
624
- };
625
- }
626
- return {
627
- nextMetadata: withHappyOrgMetadata(metadata, nextHappyOrg),
628
- queuedTurn: {
629
- context: taskContext,
630
- ...reopenContext ? { reopenContext } : {}
631
- },
632
- blocked: false
633
- };
634
- }
635
- function finalizeHappyOrgTurn(opts) {
636
- const metadata = opts.metadata ?? null;
637
- const queuedTurn = opts.queuedTurn ?? null;
638
- const { cleanedText, draft } = extractTaggedTurnReport(opts.responseText);
639
- if (!metadata || !queuedTurn) {
640
- return {
641
- cleanedText,
642
- report: null,
643
- nextMetadata: metadata
644
- };
645
- }
646
- const now = opts.now?.() ?? Date.now();
647
- const normalizedDraft = normalizeTurnReportDraft(draft);
648
- const report = {
649
- ...queuedTurn.context,
650
- turnStatus: opts.turnStatus,
651
- interventionType: normalizedDraft.interventionType ?? "none",
652
- summary: normalizedDraft.summary ?? buildFallbackSummary(cleanedText, opts.turnStatus),
653
- blockerCode: normalizedDraft.blockerCode ?? null,
654
- decisionNeeded: normalizedDraft.decisionNeeded ?? null,
655
- targetArtifact: normalizedDraft.targetArtifact ?? null,
656
- repeatFingerprint: buildRepeatFingerprint(
657
- queuedTurn.context,
658
- normalizedDraft.blockerCode ?? null,
659
- normalizedDraft.targetArtifact ?? null
660
- )
661
- };
662
- const nextHappyOrg = normalizeHappyOrgMetadata(metadata);
663
- nextHappyOrg.taskContext = { ...queuedTurn.context };
664
- nextHappyOrg.lastTurnReport = report;
665
- nextHappyOrg.activeOwner = null;
666
- nextHappyOrg.repeat = nextHappyOrg.repeat ?? {
667
- threshold: api.HAPPY_ORG_REPEAT_THRESHOLD,
668
- fingerprints: {}
669
- };
670
- let terminateMessage;
671
- if (report.repeatFingerprint) {
672
- const currentEntry = nextHappyOrg.repeat.fingerprints[report.repeatFingerprint] ?? {
673
- count: 0};
674
- const nextCount = currentEntry.count + 1;
675
- nextHappyOrg.repeat.fingerprints[report.repeatFingerprint] = {
676
- count: nextCount,
677
- lastSeenAt: now
678
- };
679
- if (nextCount >= nextHappyOrg.repeat.threshold) {
680
- nextHappyOrg.runtime = {
681
- status: "terminated",
682
- reason: `repeat_fingerprint:${report.repeatFingerprint}`,
683
- terminatedAt: now
684
- };
685
- terminateMessage = `Task ${queuedTurn.context.taskId} hit repeat threshold for ${report.repeatFingerprint} and is now terminated until reopen.`;
686
- } else if (!nextHappyOrg.runtime || nextHappyOrg.runtime.status !== "terminated") {
687
- nextHappyOrg.runtime = {
688
- status: "active",
689
- reason: null
690
- };
691
- }
692
- } else if (!nextHappyOrg.runtime || nextHappyOrg.runtime.status !== "terminated") {
693
- nextHappyOrg.runtime = {
694
- status: "active",
695
- reason: null
696
- };
697
- }
698
- return {
699
- cleanedText,
700
- report,
701
- nextMetadata: withHappyOrgMetadata(metadata, nextHappyOrg),
702
- terminateMessage
703
- };
704
- }
705
-
706
359
  const DEFAULT_MAX_MESSAGES = 200;
707
360
  const DEFAULT_MAX_CHARACTERS = 1e5;
708
361
  const DEFAULT_MAX_MESSAGE_CHARACTERS = 8e3;
@@ -1535,17 +1188,14 @@ exports.INTERACTION_TIMED_OUT_ERROR = INTERACTION_TIMED_OUT_ERROR;
1535
1188
  exports.MessageBuffer = MessageBuffer;
1536
1189
  exports.MessageQueue2 = MessageQueue2;
1537
1190
  exports.MissingMachineIdError = MissingMachineIdError;
1538
- exports.buildHappyOrgTurnPrompt = buildHappyOrgTurnPrompt;
1539
1191
  exports.closeProviderSession = closeProviderSession;
1540
1192
  exports.createSessionMetadata = createSessionMetadata;
1541
1193
  exports.ensureManagedProviderMachine = ensureManagedProviderMachine;
1542
- exports.finalizeHappyOrgTurn = finalizeHappyOrgTurn;
1543
1194
  exports.forwardAgentMessageToProviderSession = forwardAgentMessageToProviderSession;
1544
1195
  exports.getPendingInteractionTimeoutMs = getPendingInteractionTimeoutMs;
1545
1196
  exports.hashObject = hashObject;
1546
1197
  exports.inferToolResultError = inferToolResultError;
1547
1198
  exports.launchRuntimeHandleWithFactoryResult = launchRuntimeHandleWithFactoryResult;
1548
1199
  exports.registerKillSessionHandler = registerKillSessionHandler;
1549
- exports.resolveHappyOrgQueuedTurn = resolveHappyOrgQueuedTurn;
1550
1200
  exports.syncControlledByUserState = syncControlledByUserState;
1551
1201
  exports.waitForResponseCompleteWithAbort = waitForResponseCompleteWithAbort;