happy-imou-cloud 2.0.19 → 2.0.21

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 (28) hide show
  1. package/dist/{BaseReasoningProcessor-CTaamD5D.cjs → BaseReasoningProcessor-0nj-PMFc.cjs} +3 -3
  2. package/dist/{BaseReasoningProcessor-pY3tfQ0E.mjs → BaseReasoningProcessor-DnVC7liC.mjs} +3 -3
  3. package/dist/{ProviderSelectionHandler-CYs2k-z1.cjs → ProviderSelectionHandler-Bafuy28L.cjs} +2 -2
  4. package/dist/{ProviderSelectionHandler-C8pLBbE4.mjs → ProviderSelectionHandler-R-2r7ItM.mjs} +2 -2
  5. package/dist/{api-B922KGF8.mjs → api-DJe9WP9M.mjs} +77 -4
  6. package/dist/{api-DmpNsXS1.cjs → api-MGlKcEf3.cjs} +78 -3
  7. package/dist/{command-uX614XS4.mjs → command-CfyFnMv2.mjs} +3 -3
  8. package/dist/{command-B4L9Deq_.cjs → command-DAlFmWmr.cjs} +3 -3
  9. package/dist/{index-BkAY8k_1.mjs → index-CHXCgpwi.mjs} +48 -15
  10. package/dist/{index-D0VIxWJC.cjs → index-CgVjDJpt.cjs} +51 -18
  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 +357 -0
  15. package/dist/lib.d.mts +357 -0
  16. package/dist/lib.mjs +1 -1
  17. package/dist/{persistence-BfGHkCeJ.mjs → persistence-CkP90vEt.mjs} +1 -1
  18. package/dist/{persistence-ZZDZ6dl9.cjs → persistence-DLFUNI9q.cjs} +1 -1
  19. package/dist/{registerKillSessionHandler-DZ1sXUOg.cjs → registerKillSessionHandler-Cs_INk4A.cjs} +356 -3
  20. package/dist/{registerKillSessionHandler-BqeqMcNV.mjs → registerKillSessionHandler-DsHTZDsU.mjs} +354 -4
  21. package/dist/{runClaude-taQoQffg.cjs → runClaude-BGSgcyUp.cjs} +72 -9
  22. package/dist/{runClaude-CVBty_g7.mjs → runClaude-DAQAEmHe.mjs} +72 -9
  23. package/dist/{runCodex-jA1hK-nj.mjs → runCodex-B2UpSn82.mjs} +102 -14
  24. package/dist/{runCodex-JcA8vuC7.cjs → runCodex-earICaxw.cjs} +102 -14
  25. package/dist/{runGemini-BqKLrnid.mjs → runGemini-BBUmH1Qh.mjs} +73 -9
  26. package/dist/{runGemini-DZ0x4eaa.cjs → runGemini-D5RAIaR0.cjs} +73 -9
  27. package/package.json +1 -1
  28. package/scripts/release-smoke.mjs +20 -4
@@ -1,10 +1,10 @@
1
1
  'use strict';
2
2
 
3
- var index = require('./index-D0VIxWJC.cjs');
4
- var persistence = require('./persistence-ZZDZ6dl9.cjs');
3
+ var index = require('./index-CgVjDJpt.cjs');
4
+ var persistence = require('./persistence-DLFUNI9q.cjs');
5
5
  var os = require('node:os');
6
6
  var path = require('node:path');
7
- var api = require('./api-DmpNsXS1.cjs');
7
+ var api = require('./api-MGlKcEf3.cjs');
8
8
  var node_crypto = require('node:crypto');
9
9
  var crypto = require('crypto');
10
10
  require('axios');
@@ -353,6 +353,356 @@ async function syncControlledByUserState(sessionClient, controlledByUser) {
353
353
  });
354
354
  }
355
355
 
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
+
356
706
  const DEFAULT_MAX_MESSAGES = 200;
357
707
  const DEFAULT_MAX_CHARACTERS = 1e5;
358
708
  const DEFAULT_MAX_MESSAGE_CHARACTERS = 8e3;
@@ -1185,14 +1535,17 @@ exports.INTERACTION_TIMED_OUT_ERROR = INTERACTION_TIMED_OUT_ERROR;
1185
1535
  exports.MessageBuffer = MessageBuffer;
1186
1536
  exports.MessageQueue2 = MessageQueue2;
1187
1537
  exports.MissingMachineIdError = MissingMachineIdError;
1538
+ exports.buildHappyOrgTurnPrompt = buildHappyOrgTurnPrompt;
1188
1539
  exports.closeProviderSession = closeProviderSession;
1189
1540
  exports.createSessionMetadata = createSessionMetadata;
1190
1541
  exports.ensureManagedProviderMachine = ensureManagedProviderMachine;
1542
+ exports.finalizeHappyOrgTurn = finalizeHappyOrgTurn;
1191
1543
  exports.forwardAgentMessageToProviderSession = forwardAgentMessageToProviderSession;
1192
1544
  exports.getPendingInteractionTimeoutMs = getPendingInteractionTimeoutMs;
1193
1545
  exports.hashObject = hashObject;
1194
1546
  exports.inferToolResultError = inferToolResultError;
1195
1547
  exports.launchRuntimeHandleWithFactoryResult = launchRuntimeHandleWithFactoryResult;
1196
1548
  exports.registerKillSessionHandler = registerKillSessionHandler;
1549
+ exports.resolveHappyOrgQueuedTurn = resolveHappyOrgQueuedTurn;
1197
1550
  exports.syncControlledByUserState = syncControlledByUserState;
1198
1551
  exports.waitForResponseCompleteWithAbort = waitForResponseCompleteWithAbort;