happy-imou-cloud 2.0.21 → 2.0.22

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 (34) hide show
  1. package/bin/happy-cloud.mjs +1 -1
  2. package/dist/{BaseReasoningProcessor-0nj-PMFc.cjs → BaseReasoningProcessor-CJVv1aNR.cjs} +3 -3
  3. package/dist/{BaseReasoningProcessor-DnVC7liC.mjs → BaseReasoningProcessor-mIqqngd3.mjs} +3 -3
  4. package/dist/ProviderSelectionHandler-BjLyIfSR.mjs +673 -0
  5. package/dist/ProviderSelectionHandler-e4zL4Y5_.cjs +680 -0
  6. package/dist/{api-MGlKcEf3.cjs → api-DP-RQUao.cjs} +13 -3
  7. package/dist/{api-DJe9WP9M.mjs → api-DrijKeDb.mjs} +13 -4
  8. package/dist/{command-CfyFnMv2.mjs → command--vV6BSsL.mjs} +3 -3
  9. package/dist/{command-DAlFmWmr.cjs → command-BZphfJrt.cjs} +3 -3
  10. package/dist/{index-CHXCgpwi.mjs → index-BIki80pQ.mjs} +8 -8
  11. package/dist/{index-CgVjDJpt.cjs → index-CqCEZDFi.cjs} +11 -11
  12. package/dist/index.cjs +3 -3
  13. package/dist/index.mjs +3 -3
  14. package/dist/lib.cjs +1 -1
  15. package/dist/lib.d.cts +13 -13
  16. package/dist/lib.d.mts +13 -13
  17. package/dist/lib.mjs +1 -1
  18. package/dist/{persistence-CkP90vEt.mjs → persistence-C3NBdZdz.mjs} +1 -1
  19. package/dist/{persistence-DLFUNI9q.cjs → persistence-yVTbf_Ng.cjs} +1 -1
  20. package/dist/{registerKillSessionHandler-DsHTZDsU.mjs → registerKillSessionHandler-CHEj7UjN.mjs} +4 -354
  21. package/dist/{registerKillSessionHandler-Cs_INk4A.cjs → registerKillSessionHandler-QmBN446A.cjs} +3 -356
  22. package/dist/{runClaude-BGSgcyUp.cjs → runClaude-BuI6OOEv.cjs} +8 -8
  23. package/dist/{runClaude-DAQAEmHe.mjs → runClaude-D0DD_Ya5.mjs} +5 -5
  24. package/dist/{runCodex-earICaxw.cjs → runCodex-1jTTmCvq.cjs} +9 -9
  25. package/dist/{runCodex-B2UpSn82.mjs → runCodex-BzZ0jODI.mjs} +6 -6
  26. package/dist/{runGemini-D5RAIaR0.cjs → runGemini-1gJRE8oT.cjs} +9 -73
  27. package/dist/{runGemini-BBUmH1Qh.mjs → runGemini-Bx2SYAyG.mjs} +9 -73
  28. package/package.json +1 -1
  29. package/scripts/build.mjs +66 -66
  30. package/scripts/devtools/README.md +9 -9
  31. package/scripts/e2e/fake-codex-acp-agent.mjs +139 -139
  32. package/scripts/e2e/local-server-session-roundtrip.mjs +1063 -1063
  33. package/dist/ProviderSelectionHandler-Bafuy28L.cjs +0 -265
  34. package/dist/ProviderSelectionHandler-R-2r7ItM.mjs +0 -261
@@ -1,8 +1,8 @@
1
- import { i as initialMachineMetadata, e as projectPath, R as RuntimeShell, h as resolveCanonicalToolNameV2, f as formatDisplayMessage } from './index-CHXCgpwi.mjs';
2
- import { readSettings } from './persistence-CkP90vEt.mjs';
1
+ import { i as initialMachineMetadata, e as projectPath, R as RuntimeShell, h as resolveCanonicalToolNameV2, f as formatDisplayMessage } from './index-BIki80pQ.mjs';
2
+ import { readSettings } from './persistence-C3NBdZdz.mjs';
3
3
  import os from 'node:os';
4
4
  import { resolve } from 'node:path';
5
- import { c as configuration, p as packageJson, H as HAPPY_ORG_TURN_REPORT_TAG, d as HAPPY_ORG_REPEAT_THRESHOLD, l as logger } from './api-DJe9WP9M.mjs';
5
+ import { c as configuration, p as packageJson, l as logger } from './api-DrijKeDb.mjs';
6
6
  import { randomUUID } from 'node:crypto';
7
7
  import { createHash } from 'crypto';
8
8
  import 'axios';
@@ -351,356 +351,6 @@ async function syncControlledByUserState(sessionClient, controlledByUser) {
351
351
  });
352
352
  }
353
353
 
354
- function normalizeOptionalText(value) {
355
- if (typeof value !== "string") {
356
- return null;
357
- }
358
- const trimmed = value.trim();
359
- return trimmed.length > 0 ? trimmed : null;
360
- }
361
- function cloneHappyOrgMetadata(happyOrg) {
362
- return {
363
- taskContext: happyOrg?.taskContext ? { ...happyOrg.taskContext } : void 0,
364
- runtime: happyOrg?.runtime ? { ...happyOrg.runtime } : void 0,
365
- activeOwner: happyOrg?.activeOwner ? { ...happyOrg.activeOwner } : null,
366
- repeat: happyOrg?.repeat ? {
367
- threshold: happyOrg.repeat.threshold,
368
- fingerprints: Object.fromEntries(
369
- Object.entries(happyOrg.repeat.fingerprints ?? {}).map(([fingerprint, entry]) => [
370
- fingerprint,
371
- { ...entry }
372
- ])
373
- )
374
- } : void 0,
375
- lastTurnReport: happyOrg?.lastTurnReport ? { ...happyOrg.lastTurnReport } : void 0
376
- };
377
- }
378
- function normalizeHappyOrgMetadata(metadata) {
379
- const happyOrg = cloneHappyOrgMetadata(metadata?.happyOrg);
380
- return {
381
- ...happyOrg,
382
- runtime: happyOrg.runtime ?? {
383
- status: "active",
384
- reason: null
385
- },
386
- repeat: happyOrg.repeat ?? {
387
- threshold: HAPPY_ORG_REPEAT_THRESHOLD,
388
- fingerprints: {}
389
- }
390
- };
391
- }
392
- function withHappyOrgMetadata(metadata, happyOrg) {
393
- return {
394
- ...metadata,
395
- happyOrg
396
- };
397
- }
398
- function resetHappyOrgRuntimeForTask(taskContext) {
399
- return {
400
- taskContext,
401
- runtime: {
402
- status: "active",
403
- reason: null
404
- },
405
- activeOwner: null,
406
- repeat: {
407
- threshold: HAPPY_ORG_REPEAT_THRESHOLD,
408
- fingerprints: {}
409
- }
410
- };
411
- }
412
- function buildTerminatedStatusMessage(taskId) {
413
- return `Task ${taskId} is terminated. Reopen it with new context, a new decision, or a new resource before continuing.`;
414
- }
415
- function buildOwnerConflictStatusMessage(taskId, ownerAgentId) {
416
- return `Task ${taskId} is already active under owner ${ownerAgentId}. This turn must exit without continuing token usage.`;
417
- }
418
- function inferInterventionType(draft) {
419
- if (draft?.interventionType === "none" || draft?.interventionType === "review_needed" || draft?.interventionType === "blocker" || draft?.interventionType === "decision_needed") {
420
- return draft.interventionType;
421
- }
422
- if (normalizeOptionalText(draft?.decisionNeeded)) {
423
- return "decision_needed";
424
- }
425
- if (normalizeOptionalText(draft?.blockerCode)) {
426
- return "blocker";
427
- }
428
- return "none";
429
- }
430
- function buildFallbackSummary(text, turnStatus) {
431
- const trimmed = text.trim();
432
- if (trimmed) {
433
- return trimmed.replace(/\s+/g, " ").slice(0, 160);
434
- }
435
- return turnStatus === "turn_aborted" ? "Turn aborted before completion." : "Turn completed without a textual summary.";
436
- }
437
- function normalizeTurnReportDraft(draft) {
438
- return {
439
- summary: normalizeOptionalText(draft?.summary)?.replace(/\s+/g, " ").slice(0, 160) ?? null,
440
- interventionType: inferInterventionType(draft),
441
- blockerCode: normalizeOptionalText(draft?.blockerCode),
442
- decisionNeeded: normalizeOptionalText(draft?.decisionNeeded),
443
- targetArtifact: normalizeOptionalText(draft?.targetArtifact)
444
- };
445
- }
446
- function stripCodeFence(text) {
447
- return text.replace(/^```(?:json)?\s*/i, "").replace(/\s*```$/i, "").trim();
448
- }
449
- function extractTaggedTurnReport(text) {
450
- const matcher = new RegExp(
451
- `<${HAPPY_ORG_TURN_REPORT_TAG}>\\s*([\\s\\S]*?)\\s*</${HAPPY_ORG_TURN_REPORT_TAG}>`,
452
- "gi"
453
- );
454
- let lastMatch = null;
455
- for (let match = matcher.exec(text); match; match = matcher.exec(text)) {
456
- lastMatch = match;
457
- }
458
- if (!lastMatch) {
459
- return {
460
- cleanedText: text.trim(),
461
- draft: null
462
- };
463
- }
464
- const rawBlock = stripCodeFence(lastMatch[1] ?? "");
465
- let draft = null;
466
- try {
467
- const parsed = JSON.parse(rawBlock);
468
- draft = {
469
- summary: normalizeOptionalText(parsed.summary),
470
- interventionType: normalizeOptionalText(parsed.interventionType),
471
- blockerCode: normalizeOptionalText(parsed.blockerCode),
472
- decisionNeeded: normalizeOptionalText(parsed.decisionNeeded),
473
- targetArtifact: normalizeOptionalText(parsed.targetArtifact)
474
- };
475
- } catch {
476
- draft = null;
477
- }
478
- const cleanedText = `${text.slice(0, lastMatch.index)}${text.slice(lastMatch.index + lastMatch[0].length)}`.replace(/\n{3,}/g, "\n\n").trim();
479
- return {
480
- cleanedText,
481
- draft
482
- };
483
- }
484
- function buildRepeatFingerprint(context, blockerCode, targetArtifact) {
485
- if (!blockerCode) {
486
- return null;
487
- }
488
- return [
489
- context.taskId,
490
- context.memberAgentId,
491
- blockerCode,
492
- targetArtifact ?? ""
493
- ].join("::");
494
- }
495
- function buildHappyOrgTurnPrompt(prompt, turn) {
496
- const reopenLines = turn.reopenContext ? [
497
- "",
498
- "This task was explicitly reopened for this turn with the following new inputs:",
499
- turn.reopenContext.newContext ? `- newContext: ${turn.reopenContext.newContext}` : null,
500
- turn.reopenContext.newDecision ? `- newDecision: ${turn.reopenContext.newDecision}` : null,
501
- turn.reopenContext.newResource ? `- newResource: ${turn.reopenContext.newResource}` : null
502
- ].filter(Boolean) : [];
503
- const header = [
504
- "[HAPPY_ORG_TASK_CONTEXT]",
505
- `taskId=${turn.context.taskId}`,
506
- `organizationId=${turn.context.organizationId}`,
507
- `memberAgentId=${turn.context.memberAgentId}`,
508
- `supervisorAgentId=${turn.context.supervisorAgentId}`,
509
- "Stay on this exact task for the whole turn.",
510
- "End your response with exactly one raw JSON block inside these tags and do not wrap it in a markdown code fence:",
511
- `<${HAPPY_ORG_TURN_REPORT_TAG}>{"summary":"short factual summary","interventionType":"none","blockerCode":null,"decisionNeeded":null,"targetArtifact":null}</${HAPPY_ORG_TURN_REPORT_TAG}>`,
512
- "Allowed interventionType values: none, review_needed, blocker, decision_needed.",
513
- "summary must read like a CEO todo card title: short, actionable, and without long process logs.",
514
- "Use blocker only for problems the organization may still solve internally.",
515
- "Use decision_needed only when a CEO or user decision is required.",
516
- "Use review_needed when supervisor review is needed but the work is not blocked.",
517
- ...reopenLines,
518
- "[/HAPPY_ORG_TASK_CONTEXT]",
519
- "",
520
- prompt
521
- ];
522
- return header.join("\n");
523
- }
524
- function resolveHappyOrgQueuedTurn(opts) {
525
- const metadata = opts.metadata ?? null;
526
- if (!metadata) {
527
- return {
528
- nextMetadata: null,
529
- queuedTurn: null,
530
- blocked: false
531
- };
532
- }
533
- const currentHappyOrg = normalizeHappyOrgMetadata(metadata);
534
- let nextHappyOrg = cloneHappyOrgMetadata(currentHappyOrg);
535
- const messageHappyOrg = opts.message.meta?.happyOrg;
536
- const now = opts.now?.() ?? Date.now();
537
- const createRunId = opts.createRunId ?? ((taskContext2, currentNow) => `${taskContext2.taskId}:${taskContext2.memberAgentId}:${currentNow}`);
538
- if (messageHappyOrg?.taskContext) {
539
- const currentTaskId = currentHappyOrg.taskContext?.taskId ?? null;
540
- if (currentTaskId !== messageHappyOrg.taskContext.taskId) {
541
- nextHappyOrg = resetHappyOrgRuntimeForTask(messageHappyOrg.taskContext);
542
- } else {
543
- nextHappyOrg.taskContext = { ...messageHappyOrg.taskContext };
544
- }
545
- }
546
- const taskContext = nextHappyOrg.taskContext ?? null;
547
- if (!taskContext) {
548
- return {
549
- nextMetadata: metadata,
550
- queuedTurn: null,
551
- blocked: false
552
- };
553
- }
554
- const control = messageHappyOrg?.control;
555
- if (control?.action === "terminate") {
556
- nextHappyOrg.runtime = {
557
- status: "terminated",
558
- reason: normalizeOptionalText(control.reason) ?? "terminated_by_supervisor",
559
- terminatedAt: now
560
- };
561
- nextHappyOrg.activeOwner = null;
562
- return {
563
- nextMetadata: withHappyOrgMetadata(metadata, nextHappyOrg),
564
- queuedTurn: null,
565
- blocked: true,
566
- statusMessage: buildTerminatedStatusMessage(taskContext.taskId)
567
- };
568
- }
569
- const hasReopenInputs = Boolean(
570
- normalizeOptionalText(control?.newContext) || normalizeOptionalText(control?.newDecision) || normalizeOptionalText(control?.newResource)
571
- );
572
- if (nextHappyOrg.runtime?.status === "terminated") {
573
- if (control?.action !== "reopen") {
574
- return {
575
- nextMetadata: withHappyOrgMetadata(metadata, nextHappyOrg),
576
- queuedTurn: null,
577
- blocked: true,
578
- statusMessage: buildTerminatedStatusMessage(taskContext.taskId)
579
- };
580
- }
581
- if (!hasReopenInputs) {
582
- return {
583
- nextMetadata: withHappyOrgMetadata(metadata, nextHappyOrg),
584
- queuedTurn: null,
585
- blocked: true,
586
- statusMessage: `Task ${taskContext.taskId} can only reopen with new context, a new decision, or a new resource.`
587
- };
588
- }
589
- }
590
- const reopenContext = control?.action === "reopen" && hasReopenInputs ? {
591
- newContext: normalizeOptionalText(control.newContext),
592
- newDecision: normalizeOptionalText(control.newDecision),
593
- newResource: normalizeOptionalText(control.newResource)
594
- } : void 0;
595
- if (reopenContext) {
596
- nextHappyOrg.runtime = {
597
- status: "active",
598
- reason: null,
599
- reopenedAt: now
600
- };
601
- } else if (!nextHappyOrg.runtime) {
602
- nextHappyOrg.runtime = {
603
- status: "active",
604
- reason: null
605
- };
606
- }
607
- if (!nextHappyOrg.activeOwner) {
608
- nextHappyOrg.activeOwner = {
609
- ownerAgentId: taskContext.memberAgentId,
610
- ownerRunId: createRunId(taskContext, now),
611
- claimedAt: now
612
- };
613
- } else if (nextHappyOrg.activeOwner.ownerAgentId !== taskContext.memberAgentId) {
614
- return {
615
- nextMetadata: withHappyOrgMetadata(metadata, nextHappyOrg),
616
- queuedTurn: null,
617
- blocked: true,
618
- statusMessage: buildOwnerConflictStatusMessage(
619
- taskContext.taskId,
620
- nextHappyOrg.activeOwner.ownerAgentId
621
- )
622
- };
623
- }
624
- return {
625
- nextMetadata: withHappyOrgMetadata(metadata, nextHappyOrg),
626
- queuedTurn: {
627
- context: taskContext,
628
- ...reopenContext ? { reopenContext } : {}
629
- },
630
- blocked: false
631
- };
632
- }
633
- function finalizeHappyOrgTurn(opts) {
634
- const metadata = opts.metadata ?? null;
635
- const queuedTurn = opts.queuedTurn ?? null;
636
- const { cleanedText, draft } = extractTaggedTurnReport(opts.responseText);
637
- if (!metadata || !queuedTurn) {
638
- return {
639
- cleanedText,
640
- report: null,
641
- nextMetadata: metadata
642
- };
643
- }
644
- const now = opts.now?.() ?? Date.now();
645
- const normalizedDraft = normalizeTurnReportDraft(draft);
646
- const report = {
647
- ...queuedTurn.context,
648
- turnStatus: opts.turnStatus,
649
- interventionType: normalizedDraft.interventionType ?? "none",
650
- summary: normalizedDraft.summary ?? buildFallbackSummary(cleanedText, opts.turnStatus),
651
- blockerCode: normalizedDraft.blockerCode ?? null,
652
- decisionNeeded: normalizedDraft.decisionNeeded ?? null,
653
- targetArtifact: normalizedDraft.targetArtifact ?? null,
654
- repeatFingerprint: buildRepeatFingerprint(
655
- queuedTurn.context,
656
- normalizedDraft.blockerCode ?? null,
657
- normalizedDraft.targetArtifact ?? null
658
- )
659
- };
660
- const nextHappyOrg = normalizeHappyOrgMetadata(metadata);
661
- nextHappyOrg.taskContext = { ...queuedTurn.context };
662
- nextHappyOrg.lastTurnReport = report;
663
- nextHappyOrg.activeOwner = null;
664
- nextHappyOrg.repeat = nextHappyOrg.repeat ?? {
665
- threshold: HAPPY_ORG_REPEAT_THRESHOLD,
666
- fingerprints: {}
667
- };
668
- let terminateMessage;
669
- if (report.repeatFingerprint) {
670
- const currentEntry = nextHappyOrg.repeat.fingerprints[report.repeatFingerprint] ?? {
671
- count: 0};
672
- const nextCount = currentEntry.count + 1;
673
- nextHappyOrg.repeat.fingerprints[report.repeatFingerprint] = {
674
- count: nextCount,
675
- lastSeenAt: now
676
- };
677
- if (nextCount >= nextHappyOrg.repeat.threshold) {
678
- nextHappyOrg.runtime = {
679
- status: "terminated",
680
- reason: `repeat_fingerprint:${report.repeatFingerprint}`,
681
- terminatedAt: now
682
- };
683
- terminateMessage = `Task ${queuedTurn.context.taskId} hit repeat threshold for ${report.repeatFingerprint} and is now terminated until reopen.`;
684
- } else if (!nextHappyOrg.runtime || nextHappyOrg.runtime.status !== "terminated") {
685
- nextHappyOrg.runtime = {
686
- status: "active",
687
- reason: null
688
- };
689
- }
690
- } else if (!nextHappyOrg.runtime || nextHappyOrg.runtime.status !== "terminated") {
691
- nextHappyOrg.runtime = {
692
- status: "active",
693
- reason: null
694
- };
695
- }
696
- return {
697
- cleanedText,
698
- report,
699
- nextMetadata: withHappyOrgMetadata(metadata, nextHappyOrg),
700
- terminateMessage
701
- };
702
- }
703
-
704
354
  const DEFAULT_MAX_MESSAGES = 200;
705
355
  const DEFAULT_MAX_CHARACTERS = 1e5;
706
356
  const DEFAULT_MAX_MESSAGE_CHARACTERS = 8e3;
@@ -1526,4 +1176,4 @@ function registerKillSessionHandler(rpcHandlerManager, killThisHappy) {
1526
1176
  });
1527
1177
  }
1528
1178
 
1529
- export { BasePermissionHandler as B, ConversationHistory$1 as C, INTERACTION_SUPERSEDED_ERROR as I, MissingMachineIdError as M, INTERACTION_TIMED_OUT_ERROR as a, MessageQueue2 as b, createSessionMetadata as c, MessageBuffer as d, ensureManagedProviderMachine as e, registerKillSessionHandler as f, getPendingInteractionTimeoutMs as g, hashObject as h, buildHappyOrgTurnPrompt as i, finalizeHappyOrgTurn as j, closeProviderSession as k, launchRuntimeHandleWithFactoryResult as l, inferToolResultError as m, forwardAgentMessageToProviderSession as n, resolveHappyOrgQueuedTurn as r, syncControlledByUserState as s, waitForResponseCompleteWithAbort as w };
1179
+ export { BasePermissionHandler as B, ConversationHistory$1 as C, INTERACTION_SUPERSEDED_ERROR as I, MissingMachineIdError as M, INTERACTION_TIMED_OUT_ERROR as a, MessageQueue2 as b, createSessionMetadata as c, MessageBuffer as d, ensureManagedProviderMachine as e, closeProviderSession as f, getPendingInteractionTimeoutMs as g, hashObject as h, inferToolResultError as i, forwardAgentMessageToProviderSession as j, launchRuntimeHandleWithFactoryResult as l, registerKillSessionHandler as r, syncControlledByUserState as s, waitForResponseCompleteWithAbort as w };