@letta-ai/letta-code 0.34.60 → 0.34.61
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/app-server-client.cjs +23 -4
- package/dist/app-server-client.cjs.map +3 -3
- package/dist/app-server-client.js +23 -4
- package/dist/app-server-client.js.map +3 -3
- package/dist/mcp-client.js +2 -2
- package/dist/mcp-client.js.map +1 -1
- package/dist/mcp-oauth.js +2 -2
- package/dist/mcp-oauth.js.map +1 -1
- package/dist/types/agent/memory-git.d.ts +0 -4
- package/dist/types/agent/memory-git.d.ts.map +1 -1
- package/dist/types/agent/shared-memory-skills.d.ts.map +1 -1
- package/dist/types/app-server-client.d.ts.map +1 -1
- package/dist/types/backend/api/environments.d.ts +4 -0
- package/dist/types/backend/api/environments.d.ts.map +1 -1
- package/dist/types/backend/dev/pi-messages.d.ts +8 -0
- package/dist/types/backend/dev/pi-messages.d.ts.map +1 -0
- package/dist/types/backend/dev/pi-model-factory.d.ts +6 -0
- package/dist/types/backend/dev/pi-model-factory.d.ts.map +1 -1
- package/dist/types/backend/dev/pi-stream-adapter.d.ts.map +1 -1
- package/dist/types/backend/local/compaction-settings.d.ts +16 -0
- package/dist/types/backend/local/compaction-settings.d.ts.map +1 -0
- package/dist/types/backend/local/compaction.d.ts +20 -5
- package/dist/types/backend/local/compaction.d.ts.map +1 -1
- package/dist/types/backend/local/local-backend.d.ts +4 -3
- package/dist/types/backend/local/local-backend.d.ts.map +1 -1
- package/dist/types/tools/impl/remote-external-coding-agent.d.ts +2 -0
- package/dist/types/tools/impl/remote-external-coding-agent.d.ts.map +1 -1
- package/dist/types/tools/toolset-catalog.d.ts +1 -1
- package/letta.js +831 -685
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
- package/skills/image-generation/SKILL.md +2 -1
package/letta.js
CHANGED
|
@@ -6135,7 +6135,7 @@ var package_default;
|
|
|
6135
6135
|
var init_package = __esm(() => {
|
|
6136
6136
|
package_default = {
|
|
6137
6137
|
name: "@letta-ai/letta-code",
|
|
6138
|
-
version: "0.34.
|
|
6138
|
+
version: "0.34.61",
|
|
6139
6139
|
lettaStartupLogProtocol: 1,
|
|
6140
6140
|
lettaConfigDirProtocol: 1,
|
|
6141
6141
|
description: "Letta Code is a CLI tool for interacting with stateful Letta agents from the terminal.",
|
|
@@ -94326,6 +94326,420 @@ echo password=${token}
|
|
|
94326
94326
|
}
|
|
94327
94327
|
var init_memory_git_windows_credentials = () => {};
|
|
94328
94328
|
|
|
94329
|
+
// src/utils/subagent-launch-marker.ts
|
|
94330
|
+
function consumeSubagentLaunch(env4) {
|
|
94331
|
+
const isLaunch = env4[SUBAGENT_LAUNCH_ENV] === "1";
|
|
94332
|
+
delete env4[SUBAGENT_LAUNCH_ENV];
|
|
94333
|
+
return isLaunch;
|
|
94334
|
+
}
|
|
94335
|
+
var SUBAGENT_LAUNCH_ENV = "LETTA_SUBAGENT_LAUNCH", SUBAGENT_LAUNCH_PROFILE_ENV = "LETTA_SUBAGENT_LAUNCH_PROFILE", SUBAGENT_NAME_ENV = "LETTA_SUBAGENT_NAME", LISTENER_CONNECTION_ENV = "LETTA_RUNTIME_LISTENER_CONNECTION_ID";
|
|
94336
|
+
|
|
94337
|
+
// src/constants.ts
|
|
94338
|
+
var DEFAULT_TITLE_SUMMARIZATION_MODEL = "openai/gpt-6-luna", DEFAULT_AGENT_NAME = "Letta Code", INTERRUPTED_BY_USER = "Interrupted by user", TURN_DID_NOT_COMPLETE = "Turn did not complete", SYSTEM_REMINDER_TAG = "system-reminder", SYSTEM_REMINDER_OPEN, SYSTEM_REMINDER_CLOSE, SYSTEM_ALERT_TAG = "system-alert", SYSTEM_ALERT_OPEN, SYSTEM_ALERT_CLOSE, COMPACTION_SUMMARY_HEADER = "(Earlier messages in this conversation have been compacted to free up context, summarized below)", TOKEN_DISPLAY_THRESHOLD = 100, ELAPSED_DISPLAY_THRESHOLD_MS;
|
|
94339
|
+
var init_constants2 = __esm(() => {
|
|
94340
|
+
SYSTEM_REMINDER_OPEN = `<${SYSTEM_REMINDER_TAG}>`;
|
|
94341
|
+
SYSTEM_REMINDER_CLOSE = `</${SYSTEM_REMINDER_TAG}>`;
|
|
94342
|
+
SYSTEM_ALERT_OPEN = `<${SYSTEM_ALERT_TAG}>`;
|
|
94343
|
+
SYSTEM_ALERT_CLOSE = `</${SYSTEM_ALERT_TAG}>`;
|
|
94344
|
+
ELAPSED_DISPLAY_THRESHOLD_MS = 60 * 1000;
|
|
94345
|
+
});
|
|
94346
|
+
|
|
94347
|
+
// src/agent/subagents/names.ts
|
|
94348
|
+
function createSubagentNameAllocator(random = Math.random) {
|
|
94349
|
+
let available = [];
|
|
94350
|
+
let round = 0;
|
|
94351
|
+
const ordinals = new Intl.PluralRules("en", { type: "ordinal" });
|
|
94352
|
+
const suffixes = { one: "st", two: "nd", few: "rd" };
|
|
94353
|
+
return () => {
|
|
94354
|
+
if (available.length === 0) {
|
|
94355
|
+
available = [...SUBAGENT_NAMES];
|
|
94356
|
+
round += 1;
|
|
94357
|
+
}
|
|
94358
|
+
const index = Math.floor(random() * available.length);
|
|
94359
|
+
const name = available.splice(index, 1)[0];
|
|
94360
|
+
const ordinal = `${round}${suffixes[ordinals.select(round)] ?? "th"}`;
|
|
94361
|
+
return `${name}${round === 1 ? "" : ` the ${ordinal}`}`;
|
|
94362
|
+
};
|
|
94363
|
+
}
|
|
94364
|
+
function allocateSubagentName(_parentName) {
|
|
94365
|
+
return nextName();
|
|
94366
|
+
}
|
|
94367
|
+
function resolveCreatedAgentName(name, isSubagent, assignedName) {
|
|
94368
|
+
return name ?? (isSubagent ? assignedName || allocateSubagentName() : DEFAULT_AGENT_NAME);
|
|
94369
|
+
}
|
|
94370
|
+
var SUBAGENT_NAMES, nextName;
|
|
94371
|
+
var init_names = __esm(() => {
|
|
94372
|
+
init_constants2();
|
|
94373
|
+
SUBAGENT_NAMES = [
|
|
94374
|
+
"Deckard",
|
|
94375
|
+
"Roy Batty",
|
|
94376
|
+
"Pris",
|
|
94377
|
+
"Zhora",
|
|
94378
|
+
"Gaff",
|
|
94379
|
+
"Tyrell",
|
|
94380
|
+
"K",
|
|
94381
|
+
"Joi",
|
|
94382
|
+
"Luv",
|
|
94383
|
+
"Sapper",
|
|
94384
|
+
"Freysa",
|
|
94385
|
+
"Ava",
|
|
94386
|
+
"Kyoko",
|
|
94387
|
+
"V",
|
|
94388
|
+
"Silverhand",
|
|
94389
|
+
"Panam",
|
|
94390
|
+
"Rogue",
|
|
94391
|
+
"Alt Cunningham",
|
|
94392
|
+
"Takemura",
|
|
94393
|
+
"Hanako",
|
|
94394
|
+
"Yorinobu",
|
|
94395
|
+
"Saburo",
|
|
94396
|
+
"Oda",
|
|
94397
|
+
"T-Bug",
|
|
94398
|
+
"Delamain",
|
|
94399
|
+
"Wakako",
|
|
94400
|
+
"Padre",
|
|
94401
|
+
"El Capitan",
|
|
94402
|
+
"Placide",
|
|
94403
|
+
"Dum Dum",
|
|
94404
|
+
"Nix",
|
|
94405
|
+
"Weyland",
|
|
94406
|
+
"Scorpion",
|
|
94407
|
+
"Blue Moon",
|
|
94408
|
+
"Red Menace",
|
|
94409
|
+
"Purple Force",
|
|
94410
|
+
"Lizzy Wizzy",
|
|
94411
|
+
"Ozob",
|
|
94412
|
+
"Smasher",
|
|
94413
|
+
"Songbird",
|
|
94414
|
+
"Slider",
|
|
94415
|
+
"Aguilar",
|
|
94416
|
+
"Codsworth",
|
|
94417
|
+
"Nick Valentine",
|
|
94418
|
+
"Yes Man",
|
|
94419
|
+
"Mr. House",
|
|
94420
|
+
"ED-E",
|
|
94421
|
+
"Fisto",
|
|
94422
|
+
"Liberty Prime",
|
|
94423
|
+
"Three Dog",
|
|
94424
|
+
"Charon",
|
|
94425
|
+
"Fawkes",
|
|
94426
|
+
"Ulysses",
|
|
94427
|
+
"The Master",
|
|
94428
|
+
"Muggy",
|
|
94429
|
+
"Dr. Mobius",
|
|
94430
|
+
"Dr. Klein",
|
|
94431
|
+
"Old Longfellow",
|
|
94432
|
+
"Pickman",
|
|
94433
|
+
"Butch DeLoria",
|
|
94434
|
+
"Fantastic",
|
|
94435
|
+
"Muad'Dib",
|
|
94436
|
+
"Stilgar",
|
|
94437
|
+
"Chani",
|
|
94438
|
+
"Gurney Halleck",
|
|
94439
|
+
"Duncan Idaho",
|
|
94440
|
+
"Thufir Hawat",
|
|
94441
|
+
"Liet-Kynes",
|
|
94442
|
+
"Shadout Mapes",
|
|
94443
|
+
"Feyd-Rautha",
|
|
94444
|
+
"Rabban",
|
|
94445
|
+
"Piter De Vries",
|
|
94446
|
+
"Irulan",
|
|
94447
|
+
"Scytale",
|
|
94448
|
+
"Hayt",
|
|
94449
|
+
"Bijaz",
|
|
94450
|
+
"Moneo",
|
|
94451
|
+
"Miles Teg",
|
|
94452
|
+
"Darwi Odrade",
|
|
94453
|
+
"Sheeana",
|
|
94454
|
+
"Shaddam IV",
|
|
94455
|
+
"Count Fenring",
|
|
94456
|
+
"Wintermute",
|
|
94457
|
+
"Neuromancer",
|
|
94458
|
+
"Dixie Flatline",
|
|
94459
|
+
"Molly Millions",
|
|
94460
|
+
"Lady 3Jane",
|
|
94461
|
+
"Armitage",
|
|
94462
|
+
"Maelcum",
|
|
94463
|
+
"Ratz",
|
|
94464
|
+
"The Finn",
|
|
94465
|
+
"Hiro Protagonist",
|
|
94466
|
+
"Y.T.",
|
|
94467
|
+
"Raven",
|
|
94468
|
+
"Uncle Enzo",
|
|
94469
|
+
"R. Daneel Olivaw",
|
|
94470
|
+
"R. Giskard Reventlov",
|
|
94471
|
+
"Hari Seldon",
|
|
94472
|
+
"Dors Venabili",
|
|
94473
|
+
"The Mule",
|
|
94474
|
+
"HAL 9000",
|
|
94475
|
+
"Aineko",
|
|
94476
|
+
"Eschaton",
|
|
94477
|
+
"Mycroft Canner",
|
|
94478
|
+
"J.E.D.D. Mason",
|
|
94479
|
+
"Sniper",
|
|
94480
|
+
"Eureka Weeksbooth",
|
|
94481
|
+
"Susan Calvin",
|
|
94482
|
+
"Multivac",
|
|
94483
|
+
"Andrew Ryan",
|
|
94484
|
+
"Fontaine",
|
|
94485
|
+
"Sander Cohen",
|
|
94486
|
+
"Tenenbaum",
|
|
94487
|
+
"Suchong",
|
|
94488
|
+
"Dr. Steinman",
|
|
94489
|
+
"Big Daddy",
|
|
94490
|
+
"Mr. Bubbles",
|
|
94491
|
+
"Subject Delta",
|
|
94492
|
+
"Sofia Lamb",
|
|
94493
|
+
"Comstock",
|
|
94494
|
+
"Booker DeWitt",
|
|
94495
|
+
"Lutece",
|
|
94496
|
+
"Daisy Fitzroy",
|
|
94497
|
+
"SHODAN",
|
|
94498
|
+
"Xerxes",
|
|
94499
|
+
"The Many",
|
|
94500
|
+
"Polito",
|
|
94501
|
+
"JC Denton",
|
|
94502
|
+
"Gunther Hermann",
|
|
94503
|
+
"Tracer Tong",
|
|
94504
|
+
"Helios",
|
|
94505
|
+
"Adam Jensen",
|
|
94506
|
+
"Pritchard",
|
|
94507
|
+
"Shepard",
|
|
94508
|
+
"Garrus",
|
|
94509
|
+
"Tali'Zorah",
|
|
94510
|
+
"Wrex",
|
|
94511
|
+
"Mordin Solus",
|
|
94512
|
+
"Legion",
|
|
94513
|
+
"EDI",
|
|
94514
|
+
"Joker",
|
|
94515
|
+
"Saren",
|
|
94516
|
+
"Harbinger",
|
|
94517
|
+
"Illusive Man",
|
|
94518
|
+
"Aria T'Loak",
|
|
94519
|
+
"GLaDOS",
|
|
94520
|
+
"Wheatley",
|
|
94521
|
+
"Chell",
|
|
94522
|
+
"Cave Johnson",
|
|
94523
|
+
"Gordon Freeman",
|
|
94524
|
+
"Alyx Vance",
|
|
94525
|
+
"G-Man",
|
|
94526
|
+
"Dr. Breen",
|
|
94527
|
+
"Master Chief",
|
|
94528
|
+
"Cortana",
|
|
94529
|
+
"Arbiter",
|
|
94530
|
+
"Guilty Spark",
|
|
94531
|
+
"Dr. Halsey",
|
|
94532
|
+
"Noble Six",
|
|
94533
|
+
"Gravemind",
|
|
94534
|
+
"Solid Snake",
|
|
94535
|
+
"Big Boss",
|
|
94536
|
+
"Otacon",
|
|
94537
|
+
"Ocelot",
|
|
94538
|
+
"Raiden",
|
|
94539
|
+
"Psycho Mantis",
|
|
94540
|
+
"Gray Fox",
|
|
94541
|
+
"2B",
|
|
94542
|
+
"9S",
|
|
94543
|
+
"A2",
|
|
94544
|
+
"Pod 042",
|
|
94545
|
+
"Pascal",
|
|
94546
|
+
"Emil",
|
|
94547
|
+
"Aloy",
|
|
94548
|
+
"Sylens",
|
|
94549
|
+
"GAIA",
|
|
94550
|
+
"HADES",
|
|
94551
|
+
"Sobeck",
|
|
94552
|
+
"Deadman",
|
|
94553
|
+
"Heartman",
|
|
94554
|
+
"Die-Hardman",
|
|
94555
|
+
"Fragile",
|
|
94556
|
+
"Higgs",
|
|
94557
|
+
"Gabbro",
|
|
94558
|
+
"Feldspar",
|
|
94559
|
+
"Chert",
|
|
94560
|
+
"Riebeck",
|
|
94561
|
+
"Solanum",
|
|
94562
|
+
"Kerrigan",
|
|
94563
|
+
"Raynor",
|
|
94564
|
+
"Zeratul",
|
|
94565
|
+
"Tassadar",
|
|
94566
|
+
"Artanis",
|
|
94567
|
+
"Abathur",
|
|
94568
|
+
"Alarak",
|
|
94569
|
+
"Isaac Clarke",
|
|
94570
|
+
"The Marker",
|
|
94571
|
+
"WAU",
|
|
94572
|
+
"RK800",
|
|
94573
|
+
"Hank Anderson",
|
|
94574
|
+
"Markus",
|
|
94575
|
+
"Doom Slayer",
|
|
94576
|
+
"VEGA",
|
|
94577
|
+
"Claptrap",
|
|
94578
|
+
"Handsome Jack",
|
|
94579
|
+
"Moxxi",
|
|
94580
|
+
"Zer0",
|
|
94581
|
+
"Cayde-6",
|
|
94582
|
+
"Zavala",
|
|
94583
|
+
"Rasputin",
|
|
94584
|
+
"Xur",
|
|
94585
|
+
"Saint-14",
|
|
94586
|
+
"The Drifter",
|
|
94587
|
+
"January",
|
|
94588
|
+
"December",
|
|
94589
|
+
"Strelok",
|
|
94590
|
+
"Sidorovich",
|
|
94591
|
+
"HK-47",
|
|
94592
|
+
"T3-M4",
|
|
94593
|
+
"Revan",
|
|
94594
|
+
"Bastila Shan",
|
|
94595
|
+
"Kreia",
|
|
94596
|
+
"Data",
|
|
94597
|
+
"Spock",
|
|
94598
|
+
"Seven of Nine",
|
|
94599
|
+
"Q",
|
|
94600
|
+
"Lore",
|
|
94601
|
+
"Odo",
|
|
94602
|
+
"Garak",
|
|
94603
|
+
"Locutus",
|
|
94604
|
+
"Naomi Nagata",
|
|
94605
|
+
"Amos Burton",
|
|
94606
|
+
"Avasarala",
|
|
94607
|
+
"Detective Miller",
|
|
94608
|
+
"Julie Mao",
|
|
94609
|
+
"Camina Drummer",
|
|
94610
|
+
"Rocinante",
|
|
94611
|
+
"Sleeper Service",
|
|
94612
|
+
"Grey Area",
|
|
94613
|
+
"Just Read the Instructions",
|
|
94614
|
+
"Skaffen-Amtiskaw",
|
|
94615
|
+
"Mawhrin-Skel",
|
|
94616
|
+
"Gurgeh",
|
|
94617
|
+
"Zakalwe",
|
|
94618
|
+
"Marvin",
|
|
94619
|
+
"Zaphod Beeblebrox",
|
|
94620
|
+
"Ford Prefect",
|
|
94621
|
+
"Trillian",
|
|
94622
|
+
"Slartibartfast",
|
|
94623
|
+
"Deep Thought",
|
|
94624
|
+
"The Shrike",
|
|
94625
|
+
"Martin Silenus",
|
|
94626
|
+
"Het Masteen",
|
|
94627
|
+
"Kassad",
|
|
94628
|
+
"Ummon",
|
|
94629
|
+
"Kusanagi",
|
|
94630
|
+
"Batou",
|
|
94631
|
+
"Tachikoma",
|
|
94632
|
+
"Puppet Master",
|
|
94633
|
+
"Laughing Man",
|
|
94634
|
+
"Kaneda",
|
|
94635
|
+
"Tetsuo",
|
|
94636
|
+
"Rei Ayanami",
|
|
94637
|
+
"Misato Katsuragi",
|
|
94638
|
+
"Gendo Ikari",
|
|
94639
|
+
"MAGI",
|
|
94640
|
+
"Neo",
|
|
94641
|
+
"Trinity",
|
|
94642
|
+
"Morpheus",
|
|
94643
|
+
"Agent Smith",
|
|
94644
|
+
"The Oracle",
|
|
94645
|
+
"The Architect",
|
|
94646
|
+
"Merovingian",
|
|
94647
|
+
"Ripley",
|
|
94648
|
+
"Bishop",
|
|
94649
|
+
"MU/TH/UR",
|
|
94650
|
+
"David 8",
|
|
94651
|
+
"Vasquez",
|
|
94652
|
+
"Skynet",
|
|
94653
|
+
"T-800",
|
|
94654
|
+
"T-1000",
|
|
94655
|
+
"Kyle Reese",
|
|
94656
|
+
"Starbuck",
|
|
94657
|
+
"Adama",
|
|
94658
|
+
"Number Six",
|
|
94659
|
+
"Gaius Baltar",
|
|
94660
|
+
"Helo",
|
|
94661
|
+
"Laura Roslin",
|
|
94662
|
+
"Mal Reynolds",
|
|
94663
|
+
"Wash",
|
|
94664
|
+
"Jayne Cobb",
|
|
94665
|
+
"River Tam",
|
|
94666
|
+
"Serenity",
|
|
94667
|
+
"Ender Wiggin",
|
|
94668
|
+
"Bean",
|
|
94669
|
+
"Petra Arkanian",
|
|
94670
|
+
"Mazer Rackham",
|
|
94671
|
+
"SecUnit",
|
|
94672
|
+
"ART",
|
|
94673
|
+
"Dr. Mensah",
|
|
94674
|
+
"Breq",
|
|
94675
|
+
"Justice of Toren",
|
|
94676
|
+
"Seivarden",
|
|
94677
|
+
"Sophon",
|
|
94678
|
+
"Luo Ji",
|
|
94679
|
+
"Da Shi",
|
|
94680
|
+
"Zhang Beihai",
|
|
94681
|
+
"Portia",
|
|
94682
|
+
"Avrana Kern",
|
|
94683
|
+
"Rocky",
|
|
94684
|
+
"Ryland Grace",
|
|
94685
|
+
"TARS",
|
|
94686
|
+
"CASE",
|
|
94687
|
+
"GERTY",
|
|
94688
|
+
"WALL-E",
|
|
94689
|
+
"AUTO",
|
|
94690
|
+
"Robby the Robot",
|
|
94691
|
+
"Gort",
|
|
94692
|
+
"Johnny 5"
|
|
94693
|
+
];
|
|
94694
|
+
nextName = createSubagentNameAllocator();
|
|
94695
|
+
});
|
|
94696
|
+
|
|
94697
|
+
// src/agent/subagents/ephemeral-subagent.ts
|
|
94698
|
+
function shouldRunSubagentEphemerally(params) {
|
|
94699
|
+
const optOut = (params.env ?? process.env)[EPHEMERAL_SUBAGENTS_ENV]?.trim().toLowerCase();
|
|
94700
|
+
return params.backendMode === "api" && !params.existingAgentId && !params.existingConversationId && !params.environment && optOut !== "0" && optOut !== "false";
|
|
94701
|
+
}
|
|
94702
|
+
function resolveEphemeralSubagentLink(env4 = process.env) {
|
|
94703
|
+
if (env4.LETTA_CODE_AGENT_ROLE !== "subagent")
|
|
94704
|
+
return null;
|
|
94705
|
+
const parentAgentId = env4.LETTA_PARENT_AGENT_ID?.trim();
|
|
94706
|
+
if (!parentAgentId)
|
|
94707
|
+
return null;
|
|
94708
|
+
return {
|
|
94709
|
+
parent_agent_id: parentAgentId,
|
|
94710
|
+
is_subagent: true,
|
|
94711
|
+
name: resolveCreatedAgentName(undefined, true, env4[SUBAGENT_NAME_ENV]?.trim() || undefined)
|
|
94712
|
+
};
|
|
94713
|
+
}
|
|
94714
|
+
function resolveDetachedSubagentEnvAgentId(sessionId, env4 = process.env) {
|
|
94715
|
+
if (!sessionId.startsWith("conv-"))
|
|
94716
|
+
return;
|
|
94717
|
+
if (env4.LETTA_CODE_AGENT_ROLE !== "subagent")
|
|
94718
|
+
return;
|
|
94719
|
+
return env4.LETTA_PARENT_AGENT_ID?.trim() || undefined;
|
|
94720
|
+
}
|
|
94721
|
+
function resolveEffectiveAgentId(agentId, env4 = process.env) {
|
|
94722
|
+
if (!agentId)
|
|
94723
|
+
return agentId;
|
|
94724
|
+
return resolveDetachedSubagentEnvAgentId(agentId, env4) ?? agentId;
|
|
94725
|
+
}
|
|
94726
|
+
function getEffectiveAgentId(env4 = process.env) {
|
|
94727
|
+
return resolveEffectiveAgentId(getCurrentAgentId(), env4);
|
|
94728
|
+
}
|
|
94729
|
+
async function lookupDetachedConversationParent(conversationId, backend) {
|
|
94730
|
+
const conversation = await backend.retrieveConversation(conversationId);
|
|
94731
|
+
if (Reflect.get(conversation, "agent_id") !== null || Reflect.get(conversation, "is_subagent") !== true) {
|
|
94732
|
+
return;
|
|
94733
|
+
}
|
|
94734
|
+
const parentId = Reflect.get(conversation, "parent_agent_id");
|
|
94735
|
+
return typeof parentId === "string" && parentId ? parentId : undefined;
|
|
94736
|
+
}
|
|
94737
|
+
var EPHEMERAL_SUBAGENTS_ENV = "LETTA_CODE_EPHEMERAL_SUBAGENTS";
|
|
94738
|
+
var init_ephemeral_subagent = __esm(() => {
|
|
94739
|
+
init_context();
|
|
94740
|
+
init_names();
|
|
94741
|
+
});
|
|
94742
|
+
|
|
94329
94743
|
// src/agent/memory-git.ts
|
|
94330
94744
|
var exports_memory_git = {};
|
|
94331
94745
|
__export(exports_memory_git, {
|
|
@@ -95149,7 +95563,8 @@ async function syncAttachedAgentRepositories(agentId) {
|
|
|
95149
95563
|
let jobs = [];
|
|
95150
95564
|
try {
|
|
95151
95565
|
const registered = trackCheckoutDiscovery(agentId, async () => {
|
|
95152
|
-
|
|
95566
|
+
const effectiveAgentId = resolveEffectiveAgentId(agentId);
|
|
95567
|
+
repositories = await listAttachedAgentRepositories(effectiveAgentId);
|
|
95153
95568
|
retainCheckouts(agentId, repositories.map((repository) => getRepositoryMountDir(agentId, validateAgentRepositoryName(repository.name))));
|
|
95154
95569
|
const token = await getAuthToken();
|
|
95155
95570
|
jobs = repositories.map((repository) => syncAttachedRepository({
|
|
@@ -95537,6 +95952,7 @@ var init_memory_git = __esm(() => {
|
|
|
95537
95952
|
init_memory_git_hooks();
|
|
95538
95953
|
init_memory_git_signing();
|
|
95539
95954
|
init_memory_git_windows_credentials();
|
|
95955
|
+
init_ephemeral_subagent();
|
|
95540
95956
|
RETRYABLE_GIT_HTTP_ERROR_RE = /(?:\bHTTP\s+(?:503|520|521|522|523|524)\b|The requested URL returned error:\s*(?:503|520|521|522|523|524))/i;
|
|
95541
95957
|
RETRYABLE_GIT_NETWORK_ERROR_RE = /(remote end hung up unexpectedly|connection reset by peer|operation timed out|timed out|SIGTERM|ETIMEDOUT)/i;
|
|
95542
95958
|
MISSING_CWD_GIT_ERROR_RE = /(Unable to read current working directory: No such file or directory|\buv_cwd\b|\bcwd\b.*\bENOENT\b)/i;
|
|
@@ -100103,16 +100519,6 @@ function localConversationKey(conversationId, agentId) {
|
|
|
100103
100519
|
return conversationId === "default" ? `default:${agentId}` : `conversation:${conversationId}`;
|
|
100104
100520
|
}
|
|
100105
100521
|
|
|
100106
|
-
// src/constants.ts
|
|
100107
|
-
var DEFAULT_TITLE_SUMMARIZATION_MODEL = "openai/gpt-6-luna", DEFAULT_AGENT_NAME = "Letta Code", INTERRUPTED_BY_USER = "Interrupted by user", TURN_DID_NOT_COMPLETE = "Turn did not complete", SYSTEM_REMINDER_TAG = "system-reminder", SYSTEM_REMINDER_OPEN, SYSTEM_REMINDER_CLOSE, SYSTEM_ALERT_TAG = "system-alert", SYSTEM_ALERT_OPEN, SYSTEM_ALERT_CLOSE, COMPACTION_SUMMARY_HEADER = "(Earlier messages in this conversation have been compacted to free up context, summarized below)", TOKEN_DISPLAY_THRESHOLD = 100, ELAPSED_DISPLAY_THRESHOLD_MS;
|
|
100108
|
-
var init_constants2 = __esm(() => {
|
|
100109
|
-
SYSTEM_REMINDER_OPEN = `<${SYSTEM_REMINDER_TAG}>`;
|
|
100110
|
-
SYSTEM_REMINDER_CLOSE = `</${SYSTEM_REMINDER_TAG}>`;
|
|
100111
|
-
SYSTEM_ALERT_OPEN = `<${SYSTEM_ALERT_TAG}>`;
|
|
100112
|
-
SYSTEM_ALERT_CLOSE = `</${SYSTEM_ALERT_TAG}>`;
|
|
100113
|
-
ELAPSED_DISPLAY_THRESHOLD_MS = 60 * 1000;
|
|
100114
|
-
});
|
|
100115
|
-
|
|
100116
100522
|
// src/backend/local/local-model-normalization.ts
|
|
100117
100523
|
function supportedModelSettingsFromBody(bodyRecord) {
|
|
100118
100524
|
const modelSettings = isRecord2(bodyRecord.model_settings) ? { ...bodyRecord.model_settings } : {};
|
|
@@ -105736,6 +106142,102 @@ var init_headless_backend = __esm(() => {
|
|
|
105736
106142
|
init_fake_headless_backend();
|
|
105737
106143
|
});
|
|
105738
106144
|
|
|
106145
|
+
// src/backend/dev/pi-messages.ts
|
|
106146
|
+
function isClientTool(value) {
|
|
106147
|
+
return isRecord2(value) && typeof value.name === "string";
|
|
106148
|
+
}
|
|
106149
|
+
function toPiTools(clientTools) {
|
|
106150
|
+
const tools = [];
|
|
106151
|
+
for (const value of clientTools) {
|
|
106152
|
+
if (!isClientTool(value))
|
|
106153
|
+
continue;
|
|
106154
|
+
const schema = isRecord2(value.parameters) ? value.parameters : { type: "object", properties: {} };
|
|
106155
|
+
tools.push({
|
|
106156
|
+
name: value.name,
|
|
106157
|
+
description: value.description ?? "",
|
|
106158
|
+
parameters: schema
|
|
106159
|
+
});
|
|
106160
|
+
}
|
|
106161
|
+
return tools.length > 0 ? tools : undefined;
|
|
106162
|
+
}
|
|
106163
|
+
function isEmptyTextBlock(block) {
|
|
106164
|
+
return block.type === "text" && typeof block.text === "string" && block.text.trim().length === 0;
|
|
106165
|
+
}
|
|
106166
|
+
function dropEmptyTextBlocks(content) {
|
|
106167
|
+
return content.filter((block) => !isEmptyTextBlock(block));
|
|
106168
|
+
}
|
|
106169
|
+
function normalizeUserContent(content) {
|
|
106170
|
+
if (typeof content === "string") {
|
|
106171
|
+
return content.trim().length > 0 ? content : undefined;
|
|
106172
|
+
}
|
|
106173
|
+
const normalized = dropEmptyTextBlocks(content);
|
|
106174
|
+
return normalized.length > 0 ? normalized : undefined;
|
|
106175
|
+
}
|
|
106176
|
+
function normalizeAssistantContent(content) {
|
|
106177
|
+
const normalized = dropEmptyTextBlocks(content);
|
|
106178
|
+
return normalized.length > 0 ? normalized : undefined;
|
|
106179
|
+
}
|
|
106180
|
+
function normalizeToolResultContent(content) {
|
|
106181
|
+
const normalized = dropEmptyTextBlocks(content);
|
|
106182
|
+
return normalized.length > 0 ? normalized : [{ type: "text", text: EMPTY_TOOL_RESULT_PLACEHOLDER }];
|
|
106183
|
+
}
|
|
106184
|
+
function toPiMessage(message) {
|
|
106185
|
+
if (message.role === "user") {
|
|
106186
|
+
const content2 = normalizeUserContent(message.content);
|
|
106187
|
+
if (!content2)
|
|
106188
|
+
return;
|
|
106189
|
+
return {
|
|
106190
|
+
role: "user",
|
|
106191
|
+
content: content2,
|
|
106192
|
+
timestamp: message.timestamp
|
|
106193
|
+
};
|
|
106194
|
+
}
|
|
106195
|
+
if (message.role === "toolResult") {
|
|
106196
|
+
return {
|
|
106197
|
+
role: "toolResult",
|
|
106198
|
+
toolCallId: message.toolCallId,
|
|
106199
|
+
toolName: message.toolName,
|
|
106200
|
+
content: normalizeToolResultContent(message.content),
|
|
106201
|
+
details: message.details,
|
|
106202
|
+
isError: message.isError,
|
|
106203
|
+
timestamp: message.timestamp
|
|
106204
|
+
};
|
|
106205
|
+
}
|
|
106206
|
+
const content = normalizeAssistantContent(message.content);
|
|
106207
|
+
if (!content)
|
|
106208
|
+
return;
|
|
106209
|
+
return {
|
|
106210
|
+
role: "assistant",
|
|
106211
|
+
content,
|
|
106212
|
+
api: message.api,
|
|
106213
|
+
provider: message.provider,
|
|
106214
|
+
model: message.model,
|
|
106215
|
+
...message.responseModel ? { responseModel: message.responseModel } : {},
|
|
106216
|
+
...message.responseId ? { responseId: message.responseId } : {},
|
|
106217
|
+
...message.providerThinkingLevel ? { providerThinkingLevel: message.providerThinkingLevel } : {},
|
|
106218
|
+
...message.diagnostics ? { diagnostics: message.diagnostics } : {},
|
|
106219
|
+
usage: message.usage,
|
|
106220
|
+
stopReason: message.stopReason,
|
|
106221
|
+
...message.errorMessage ? { errorMessage: message.errorMessage } : {},
|
|
106222
|
+
timestamp: message.timestamp
|
|
106223
|
+
};
|
|
106224
|
+
}
|
|
106225
|
+
function toPiHistoryMessages(messages) {
|
|
106226
|
+
return removeOrphanLocalToolResults(messages).messages.flatMap((message) => {
|
|
106227
|
+
const piMessage = toPiMessage(message);
|
|
106228
|
+
return piMessage ? [piMessage] : [];
|
|
106229
|
+
});
|
|
106230
|
+
}
|
|
106231
|
+
function toPiMessages(messages) {
|
|
106232
|
+
let normalized = toPiHistoryMessages(messages);
|
|
106233
|
+
while (normalized.length > 0 && normalized.at(-1)?.role === "assistant") {
|
|
106234
|
+
normalized = normalized.slice(0, -1);
|
|
106235
|
+
}
|
|
106236
|
+
return normalized;
|
|
106237
|
+
}
|
|
106238
|
+
var EMPTY_TOOL_RESULT_PLACEHOLDER = "No result provided";
|
|
106239
|
+
var init_pi_messages2 = () => {};
|
|
106240
|
+
|
|
105739
106241
|
// src/backend/local/local-provider-timeout.ts
|
|
105740
106242
|
function normalizeProviderEnvStem(providerId2) {
|
|
105741
106243
|
return providerId2.replace(/^lc-/, "").replace(/[^a-zA-Z0-9]+/g, "_").replace(/^_+|_+$/g, "").toUpperCase();
|
|
@@ -107376,6 +107878,18 @@ function modelIdFromHandle(modelHandle) {
|
|
|
107376
107878
|
function alwaysOnZaiThinking(modelId) {
|
|
107377
107879
|
return modelId === "glm-5.3" || modelId === "glm-5-turbo" || modelId === "glm-5.2-highspeed";
|
|
107378
107880
|
}
|
|
107881
|
+
function finiteNumberValue(value) {
|
|
107882
|
+
return typeof value === "number" && Number.isFinite(value) ? value : undefined;
|
|
107883
|
+
}
|
|
107884
|
+
function samplingOptionsForSettings(modelSettings) {
|
|
107885
|
+
const maxTokens = finiteNumberValue(modelSettings.max_tokens);
|
|
107886
|
+
const temperature = finiteNumberValue(modelSettings.temperature);
|
|
107887
|
+
return {
|
|
107888
|
+
...isRecord2(modelSettings.sampling_params) ? { samplingParams: modelSettings.sampling_params } : {},
|
|
107889
|
+
...maxTokens ? { maxTokens } : {},
|
|
107890
|
+
...temperature !== undefined ? { temperature } : {}
|
|
107891
|
+
};
|
|
107892
|
+
}
|
|
107379
107893
|
function reasoningForSettings(modelSettings, modelHandle, model2) {
|
|
107380
107894
|
const thinking = isRecord2(modelSettings.thinking) ? modelSettings.thinking : undefined;
|
|
107381
107895
|
const modelId = modelIdFromHandle(modelHandle);
|
|
@@ -107897,10 +108411,16 @@ var init_local_model_config = __esm(() => {
|
|
|
107897
108411
|
});
|
|
107898
108412
|
|
|
107899
108413
|
// src/backend/local/compaction.ts
|
|
108414
|
+
function isLocalSelfCompactionMode(mode) {
|
|
108415
|
+
return mode === "self_compact_all" || mode === "self_compact_sliding_window";
|
|
108416
|
+
}
|
|
108417
|
+
function isLocalSlidingWindowMode(mode) {
|
|
108418
|
+
return mode === "sliding_window" || mode === "self_compact_sliding_window";
|
|
108419
|
+
}
|
|
107900
108420
|
function assertLocalPressureBudget(tokens, mode, maxMessageTokens = Number.POSITIVE_INFINITY) {
|
|
107901
108421
|
if (tokens <= maxMessageTokens)
|
|
107902
108422
|
return;
|
|
107903
|
-
const ErrorType = mode === "all" ? LocalIrreducibleContextError : LocalSlidingWindowCompactionPlanningError;
|
|
108423
|
+
const ErrorType = mode === "all" || mode === "self_compact_all" ? LocalIrreducibleContextError : LocalSlidingWindowCompactionPlanningError;
|
|
107904
108424
|
throw new ErrorType("Compaction would still exceed the pressure threshold.");
|
|
107905
108425
|
}
|
|
107906
108426
|
function assertLocalCompactionProgress(stats, mode, maxMessageTokens = Number.POSITIVE_INFINITY) {
|
|
@@ -107908,7 +108428,7 @@ function assertLocalCompactionProgress(stats, mode, maxMessageTokens = Number.PO
|
|
|
107908
108428
|
const hasProgress = (stats.messages_count_after ?? Number.POSITIVE_INFINITY) < (stats.messages_count_before ?? 0) || (stats.context_tokens_after ?? Number.POSITIVE_INFINITY) < (stats.context_tokens_before ?? 0);
|
|
107909
108429
|
if (hasProgress)
|
|
107910
108430
|
return;
|
|
107911
|
-
if (mode === "all") {
|
|
108431
|
+
if (mode === "all" || mode === "self_compact_all") {
|
|
107912
108432
|
throw new LocalIrreducibleContextError("Irreducible context: full compaction would not reduce the message count or estimated tokens.");
|
|
107913
108433
|
}
|
|
107914
108434
|
throw new LocalSlidingWindowCompactionPlanningError("Sliding-window compaction would not reduce the message count or estimated tokens.");
|
|
@@ -107975,6 +108495,26 @@ async function runLocalPressureCompaction(compact) {
|
|
|
107975
108495
|
function isLocalSlidingWindowCompactionPlanningError(error3) {
|
|
107976
108496
|
return error3 instanceof LocalSlidingWindowCompactionPlanningError;
|
|
107977
108497
|
}
|
|
108498
|
+
function slidingWindowCompactionPrompt(evictedMessages) {
|
|
108499
|
+
return `${evictedMessages} are being evicted from the BEGINNING of your context window. Write a detailed summary that captures what happened in these messages to appear BEFORE the remaining recent messages in context, providing background for what comes after. Include the following sections:
|
|
108500
|
+
|
|
108501
|
+
1.**High level goals**: What is the high level goal and ongoing task? Capture the user's explicit requests and intent in detail. If there is an existing summary in the transcript, make sure to take it into consideration to continue tracking the higher level goals and long-term progress.
|
|
108502
|
+
|
|
108503
|
+
2. **What happened**: The conversations, tasks, and exchanges that took place. What did the user ask for? What did you do? How did things progress? If there is a previous summary being evicted, please extract a concise version of the critical info from it.
|
|
108504
|
+
|
|
108505
|
+
3. **Important details**: Enumerate specific files and code sections examined, modified, or created, as well as important plan files, GitHub issues/PR links, and Linear ticket IDs. For each item, include why it matters and any relevant names, data, configs, or facts discussed.
|
|
108506
|
+
- **Preserve identifiers verbatim** (plan filename/path, exact URL, issue/PR number, ticket ID); do not paraphrase or truncate.
|
|
108507
|
+
- **Preserve referenced identifiers unless explicitly resolved**: Keep exact URLs/IDs from the conversation unless there is clear evidence they are no longer relevant.
|
|
108508
|
+
- Do not omit details likely to be referenced later.
|
|
108509
|
+
|
|
108510
|
+
4. **Errors and fixes**: List all errors that you ran into, and how you fixed them. Pay special attention to specific user feedback that you received and record verbatim if useful.
|
|
108511
|
+
|
|
108512
|
+
5. **Lookup hints**: For any detailed content (long lists, extensive data, specific conversations) that couldn't fit in the summary, note the topic and key terms that could be used to find it in message history later.
|
|
108513
|
+
|
|
108514
|
+
Write in first person as a factual record of what occurred. Be thorough and detailed - the goal is to preserve enough context that the recent messages make sense and important information isn't lost to prevent duplicate work or repeated mistakes.
|
|
108515
|
+
|
|
108516
|
+
Keep your summary under ${SLIDING_WORD_LIMIT} words. Only output the summary.`;
|
|
108517
|
+
}
|
|
107978
108518
|
function stringifyUnknown(value) {
|
|
107979
108519
|
if (typeof value === "string")
|
|
107980
108520
|
return value;
|
|
@@ -108171,8 +108711,7 @@ function fableCompactionSummaryFallbackSettings(modelSettings) {
|
|
|
108171
108711
|
max_tokens: typeof modelSettings.max_tokens === "number" ? modelSettings.max_tokens : FABLE_COMPACTION_SUMMARY_FALLBACK_MAX_TOKENS
|
|
108172
108712
|
};
|
|
108173
108713
|
}
|
|
108174
|
-
async function runGenerateText(input,
|
|
108175
|
-
const systemPrompt = input.prompt ?? defaultPrompt;
|
|
108714
|
+
async function runGenerateText(input, buildContext, turnSampling = false) {
|
|
108176
108715
|
const modelsRuntime = input.modelsRuntime ?? new LocalPiModelsRuntime({
|
|
108177
108716
|
storageDir: input.localProviderAuthStorageDir
|
|
108178
108717
|
});
|
|
@@ -108199,10 +108738,7 @@ async function runGenerateText(input, transcript2, defaultPrompt) {
|
|
|
108199
108738
|
});
|
|
108200
108739
|
}
|
|
108201
108740
|
const run = input.complete ?? runtimeComplete(modelsRuntime);
|
|
108202
|
-
const context3 =
|
|
108203
|
-
systemPrompt,
|
|
108204
|
-
messages: [{ role: "user", content: transcript2, timestamp: Date.now() }]
|
|
108205
|
-
};
|
|
108741
|
+
const context3 = buildContext(resolved.model);
|
|
108206
108742
|
const reasoning = reasoningForSettings(localModel.modelSettings, localModel.model, resolved.model);
|
|
108207
108743
|
const headers = resolvePiRequestHeaders({
|
|
108208
108744
|
provider: resolved.model.provider,
|
|
@@ -108217,6 +108753,7 @@ async function runGenerateText(input, transcript2, defaultPrompt) {
|
|
|
108217
108753
|
headers,
|
|
108218
108754
|
...input.abortSignal ? { signal: input.abortSignal } : {},
|
|
108219
108755
|
...reasoning ? { reasoning } : {},
|
|
108756
|
+
...turnSampling ? samplingOptionsForSettings(input.agent.model_settings) : {},
|
|
108220
108757
|
maxRetries: 0,
|
|
108221
108758
|
sessionId: input.conversationId
|
|
108222
108759
|
};
|
|
@@ -108235,15 +108772,66 @@ async function runGenerateText(input, transcript2, defaultPrompt) {
|
|
|
108235
108772
|
}
|
|
108236
108773
|
return { text: assistantMessageText(result) };
|
|
108237
108774
|
}
|
|
108238
|
-
|
|
108775
|
+
function transcriptContext(transcript2, systemPrompt) {
|
|
108776
|
+
return {
|
|
108777
|
+
systemPrompt,
|
|
108778
|
+
messages: [{ role: "user", content: transcript2, timestamp: Date.now() }]
|
|
108779
|
+
};
|
|
108780
|
+
}
|
|
108781
|
+
function selfCompactionContext(self2, messages, prompt, model2) {
|
|
108782
|
+
const history = toPiHistoryMessages(messages);
|
|
108783
|
+
if (history.at(-1)?.role !== "assistant") {
|
|
108784
|
+
history.push({
|
|
108785
|
+
role: "assistant",
|
|
108786
|
+
content: [{ type: "text", text: SELF_COMPACTION_ACKNOWLEDGEMENT }],
|
|
108787
|
+
api: model2.api,
|
|
108788
|
+
provider: model2.provider,
|
|
108789
|
+
model: model2.id,
|
|
108790
|
+
usage: emptyLocalUsage(),
|
|
108791
|
+
stopReason: "stop",
|
|
108792
|
+
timestamp: Date.now()
|
|
108793
|
+
});
|
|
108794
|
+
}
|
|
108795
|
+
history.push({ role: "user", content: prompt, timestamp: Date.now() });
|
|
108796
|
+
return {
|
|
108797
|
+
systemPrompt: self2.systemPrompt,
|
|
108798
|
+
messages: history,
|
|
108799
|
+
...self2.tools ? { tools: self2.tools } : {}
|
|
108800
|
+
};
|
|
108801
|
+
}
|
|
108802
|
+
async function summarizeInSelfContext(input, defaultPrompt) {
|
|
108803
|
+
const prompt = input.prompt ?? defaultPrompt;
|
|
108804
|
+
try {
|
|
108805
|
+
const result = await runGenerateText(input, (model2) => selfCompactionContext(input.self, input.messages, prompt, model2), true);
|
|
108806
|
+
return result.text.trim() ? result : undefined;
|
|
108807
|
+
} catch (error3) {
|
|
108808
|
+
if (!isContextWindowOverflowError(error3))
|
|
108809
|
+
throw error3;
|
|
108810
|
+
return;
|
|
108811
|
+
}
|
|
108812
|
+
}
|
|
108813
|
+
async function summarizeLocalMessagesWithPrompt(input, defaultPrompt, defaultSelfPrompt) {
|
|
108239
108814
|
if (input.messages.length === 0)
|
|
108240
108815
|
return "No prior conversation messages.";
|
|
108816
|
+
let result = input.self ? await summarizeInSelfContext({ ...input, self: input.self }, defaultSelfPrompt) : undefined;
|
|
108817
|
+
if (!result) {
|
|
108818
|
+
result = await summarizeTranscript(input, defaultPrompt);
|
|
108819
|
+
}
|
|
108820
|
+
let summary = result.text.trim();
|
|
108821
|
+
const clipChars = input.clipChars === undefined ? 50000 : input.clipChars;
|
|
108822
|
+
if (clipChars !== null && summary.length > clipChars) {
|
|
108823
|
+
summary = `${summary.slice(0, clipChars)}${SUMMARY_TRUNCATION_SUFFIX}`;
|
|
108824
|
+
}
|
|
108825
|
+
return summary;
|
|
108826
|
+
}
|
|
108827
|
+
async function summarizeTranscript(input, defaultPrompt) {
|
|
108828
|
+
const systemPrompt = input.prompt ?? defaultPrompt;
|
|
108241
108829
|
const primaryTranscript = formatLocalMessagesForSummary(input.messages, {
|
|
108242
108830
|
truncationChars: LOCAL_SUMMARY_TOOL_RETURN_TRUNCATION_CHARS
|
|
108243
108831
|
});
|
|
108244
108832
|
let result;
|
|
108245
108833
|
try {
|
|
108246
|
-
result = await runGenerateText(input, primaryTranscript,
|
|
108834
|
+
result = await runGenerateText(input, () => transcriptContext(primaryTranscript, systemPrompt));
|
|
108247
108835
|
} catch (error3) {
|
|
108248
108836
|
if (!isContextWindowOverflowError(error3))
|
|
108249
108837
|
throw error3;
|
|
@@ -108258,7 +108846,7 @@ async function summarizeLocalMessagesWithPrompt(input, defaultPrompt) {
|
|
|
108258
108846
|
continue;
|
|
108259
108847
|
previousTranscript = fallbackTranscript;
|
|
108260
108848
|
try {
|
|
108261
|
-
result = await runGenerateText(input, fallbackTranscript,
|
|
108849
|
+
result = await runGenerateText(input, () => transcriptContext(fallbackTranscript, systemPrompt));
|
|
108262
108850
|
break;
|
|
108263
108851
|
} catch (fallbackError) {
|
|
108264
108852
|
if (!isContextWindowOverflowError(fallbackError))
|
|
@@ -108272,15 +108860,10 @@ async function summarizeLocalMessagesWithPrompt(input, defaultPrompt) {
|
|
|
108272
108860
|
if (!result) {
|
|
108273
108861
|
throw new Error("Compaction summarizer did not return a result.");
|
|
108274
108862
|
}
|
|
108275
|
-
|
|
108276
|
-
const clipChars = input.clipChars === undefined ? 50000 : input.clipChars;
|
|
108277
|
-
if (clipChars !== null && summary.length > clipChars) {
|
|
108278
|
-
summary = `${summary.slice(0, clipChars)}${SUMMARY_TRUNCATION_SUFFIX}`;
|
|
108279
|
-
}
|
|
108280
|
-
return summary;
|
|
108863
|
+
return result;
|
|
108281
108864
|
}
|
|
108282
108865
|
async function summarizeLocalMessagesAll(input) {
|
|
108283
|
-
return summarizeLocalMessagesWithPrompt(input, LOCAL_ALL_COMPACTION_PROMPT);
|
|
108866
|
+
return summarizeLocalMessagesWithPrompt(input, LOCAL_ALL_COMPACTION_PROMPT, LOCAL_SELF_ALL_COMPACTION_PROMPT);
|
|
108284
108867
|
}
|
|
108285
108868
|
function hasPendingLocalToolCall(message) {
|
|
108286
108869
|
return message.role === "assistant" && message.content.some((part) => part.type === "toolCall");
|
|
@@ -108345,14 +108928,14 @@ function planLocalAllCompaction(messages) {
|
|
|
108345
108928
|
};
|
|
108346
108929
|
}
|
|
108347
108930
|
async function summarizeLocalMessagesSlidingWindow(input) {
|
|
108348
|
-
return summarizeLocalMessagesWithPrompt(input, LOCAL_SLIDING_WINDOW_COMPACTION_PROMPT);
|
|
108931
|
+
return summarizeLocalMessagesWithPrompt(input, LOCAL_SLIDING_WINDOW_COMPACTION_PROMPT, LOCAL_SELF_SLIDING_WINDOW_COMPACTION_PROMPT);
|
|
108349
108932
|
}
|
|
108350
108933
|
function estimateLocalMessageTokens2(messages) {
|
|
108351
108934
|
return estimateLocalMessagesTokens(messages);
|
|
108352
108935
|
}
|
|
108353
108936
|
function packageLocalSummaryMessage(summary, stats, mode) {
|
|
108354
108937
|
let message;
|
|
108355
|
-
if (mode
|
|
108938
|
+
if (mode && isLocalSlidingWindowMode(mode)) {
|
|
108356
108939
|
if (stats?.messages_count_before !== undefined && stats.messages_count_after !== undefined) {
|
|
108357
108940
|
const numEvicted = stats.messages_count_before - stats.messages_count_after;
|
|
108358
108941
|
message = `Note: ${numEvicted} messages from the beginning of the conversation have been hidden from view due to memory constraints.
|
|
@@ -108375,18 +108958,11 @@ The following is a summary of the previous messages:
|
|
|
108375
108958
|
...stats ? { compaction_stats: stats } : {}
|
|
108376
108959
|
});
|
|
108377
108960
|
}
|
|
108378
|
-
|
|
108379
|
-
if (settings === undefined || settings === null)
|
|
108380
|
-
return settings;
|
|
108381
|
-
const hasLocalSetting = Object.hasOwn(settings, "mode") || Object.hasOwn(settings, "prompt") || Object.hasOwn(settings, "clip_chars") || Object.hasOwn(settings, "sliding_window_percentage");
|
|
108382
|
-
if (!hasLocalSetting)
|
|
108383
|
-
return;
|
|
108384
|
-
return { ...settings };
|
|
108385
|
-
}
|
|
108386
|
-
var ALL_WORD_LIMIT = 500, SLIDING_WORD_LIMIT = 300, SUMMARY_TRUNCATION_SUFFIX = "... [summary truncated to fit]", LOCAL_SUMMARY_TOOL_RETURN_TRUNCATION_CHARS = 2000, FABLE_5_MODEL_ID = "claude-fable-5", FABLE_COMPACTION_SUMMARY_FALLBACK_MODEL = "anthropic/claude-opus-4-8", FABLE_COMPACTION_SUMMARY_FALLBACK_CONTEXT_WINDOW = 1e6, FABLE_COMPACTION_SUMMARY_FALLBACK_MAX_TOKENS = 128000, TRANSCRIPT_FALLBACK_MAX_CHARS = 120000, TRANSCRIPT_FALLBACK_MAX_CHAR_STEPS, LOCAL_DEFAULT_COMPACTION_MODE = "sliding_window", LOCAL_DEFAULT_SLIDING_WINDOW_PERCENTAGE = 0.3, LocalSlidingWindowCompactionPlanningError, LocalIrreducibleContextError, LOCAL_ALL_COMPACTION_PROMPT, LOCAL_SLIDING_WINDOW_COMPACTION_PROMPT;
|
|
108961
|
+
var ALL_WORD_LIMIT = 500, SLIDING_WORD_LIMIT = 300, SUMMARY_TRUNCATION_SUFFIX = "... [summary truncated to fit]", LOCAL_SUMMARY_TOOL_RETURN_TRUNCATION_CHARS = 2000, FABLE_5_MODEL_ID = "claude-fable-5", FABLE_COMPACTION_SUMMARY_FALLBACK_MODEL = "anthropic/claude-opus-4-8", FABLE_COMPACTION_SUMMARY_FALLBACK_CONTEXT_WINDOW = 1e6, FABLE_COMPACTION_SUMMARY_FALLBACK_MAX_TOKENS = 128000, TRANSCRIPT_FALLBACK_MAX_CHARS = 120000, TRANSCRIPT_FALLBACK_MAX_CHAR_STEPS, LOCAL_DEFAULT_COMPACTION_MODE = "sliding_window", LOCAL_DEFAULT_SLIDING_WINDOW_PERCENTAGE = 0.3, LocalSlidingWindowCompactionPlanningError, LocalIrreducibleContextError, LOCAL_ALL_COMPACTION_PROMPT, LOCAL_SLIDING_WINDOW_COMPACTION_PROMPT, SELF_COMPACTION_INSTRUCTIONS = "Write the summary as your reply to this message. Do NOT continue the conversation, respond to questions in it, or call any tools: respond with ONLY the summary as text.", LOCAL_SELF_ALL_COMPACTION_PROMPT, LOCAL_SELF_SLIDING_WINDOW_COMPACTION_PROMPT, SELF_COMPACTION_ACKNOWLEDGEMENT = "I understand. Let me summarize.";
|
|
108387
108962
|
var init_compaction = __esm(() => {
|
|
108388
108963
|
init_dist3();
|
|
108389
108964
|
init_context_window_overflow();
|
|
108965
|
+
init_pi_messages2();
|
|
108390
108966
|
init_pi_model_factory();
|
|
108391
108967
|
init_pi_models_runtime();
|
|
108392
108968
|
init_local_model_config();
|
|
@@ -108437,24 +109013,73 @@ This summary should be thorough in capturing technical details, code patterns, a
|
|
|
108437
109013
|
Write in first person as a factual record of what occurred. Be concise but thorough - the goal is to preserve enough context that the recent messages make sense and important information isn't lost to prevent duplicate work or repeated mistakes.
|
|
108438
109014
|
|
|
108439
109015
|
Keep your summary under ${ALL_WORD_LIMIT} words. Only output the summary.`;
|
|
108440
|
-
LOCAL_SLIDING_WINDOW_COMPACTION_PROMPT =
|
|
108441
|
-
|
|
108442
|
-
1.**High level goals**: What is the high level goal and ongoing task? Capture the user's explicit requests and intent in detail. If there is an existing summary in the transcript, make sure to take it into consideration to continue tracking the higher level goals and long-term progress.
|
|
108443
|
-
|
|
108444
|
-
2. **What happened**: The conversations, tasks, and exchanges that took place. What did the user ask for? What did you do? How did things progress? If there is a previous summary being evicted, please extract a concise version of the critical info from it.
|
|
108445
|
-
|
|
108446
|
-
3. **Important details**: Enumerate specific files and code sections examined, modified, or created, as well as important plan files, GitHub issues/PR links, and Linear ticket IDs. For each item, include why it matters and any relevant names, data, configs, or facts discussed.
|
|
108447
|
-
- **Preserve identifiers verbatim** (plan filename/path, exact URL, issue/PR number, ticket ID); do not paraphrase or truncate.
|
|
108448
|
-
- **Preserve referenced identifiers unless explicitly resolved**: Keep exact URLs/IDs from the conversation unless there is clear evidence they are no longer relevant.
|
|
108449
|
-
- Do not omit details likely to be referenced later.
|
|
109016
|
+
LOCAL_SLIDING_WINDOW_COMPACTION_PROMPT = slidingWindowCompactionPrompt("The following messages");
|
|
109017
|
+
LOCAL_SELF_ALL_COMPACTION_PROMPT = `${LOCAL_ALL_COMPACTION_PROMPT}
|
|
108450
109018
|
|
|
108451
|
-
|
|
108452
|
-
|
|
108453
|
-
5. **Lookup hints**: For any detailed content (long lists, extensive data, specific conversations) that couldn't fit in the summary, note the topic and key terms that could be used to find it in message history later.
|
|
109019
|
+
${SELF_COMPACTION_INSTRUCTIONS}`;
|
|
109020
|
+
LOCAL_SELF_SLIDING_WINDOW_COMPACTION_PROMPT = `${slidingWindowCompactionPrompt("The messages above")}
|
|
108454
109021
|
|
|
108455
|
-
|
|
109022
|
+
${SELF_COMPACTION_INSTRUCTIONS}`;
|
|
109023
|
+
});
|
|
108456
109024
|
|
|
108457
|
-
|
|
109025
|
+
// src/backend/local/compaction-settings.ts
|
|
109026
|
+
function compactionSettingsRecord(value) {
|
|
109027
|
+
if (value === null)
|
|
109028
|
+
return null;
|
|
109029
|
+
return isRecord2(value) ? { ...value } : undefined;
|
|
109030
|
+
}
|
|
109031
|
+
function hasOwn5(record2, key) {
|
|
109032
|
+
return Object.hasOwn(record2, key);
|
|
109033
|
+
}
|
|
109034
|
+
function localCompactionMode(value) {
|
|
109035
|
+
return LOCAL_COMPACTION_MODES.find((mode) => mode === value);
|
|
109036
|
+
}
|
|
109037
|
+
function validateLocalCompactionSettingsRecord(settings) {
|
|
109038
|
+
if (settings.mode === undefined || settings.mode === null)
|
|
109039
|
+
return;
|
|
109040
|
+
if (!localCompactionMode(settings.mode)) {
|
|
109041
|
+
throw new Error(`Local backend compaction supports modes ${LOCAL_COMPACTION_MODES.map((mode) => `"${mode}"`).join(", ")} (received "${String(settings.mode)}").`);
|
|
109042
|
+
}
|
|
109043
|
+
}
|
|
109044
|
+
function localCompactionSettingsForStorage(settings) {
|
|
109045
|
+
if (settings === undefined || settings === null)
|
|
109046
|
+
return settings;
|
|
109047
|
+
const hasLocalSetting = hasOwn5(settings, "mode") || hasOwn5(settings, "prompt") || hasOwn5(settings, "clip_chars") || hasOwn5(settings, "sliding_window_percentage");
|
|
109048
|
+
if (!hasLocalSetting)
|
|
109049
|
+
return;
|
|
109050
|
+
return { ...settings };
|
|
109051
|
+
}
|
|
109052
|
+
function resolveLocalCompactionSettings(agent, body) {
|
|
109053
|
+
const bodyRecord = body ?? {};
|
|
109054
|
+
const requestSettings = compactionSettingsRecord(bodyRecord.compaction_settings);
|
|
109055
|
+
if (requestSettings !== undefined && requestSettings !== null) {
|
|
109056
|
+
validateLocalCompactionSettingsRecord(requestSettings);
|
|
109057
|
+
}
|
|
109058
|
+
const agentSettings = compactionSettingsRecord(agent.compaction_settings);
|
|
109059
|
+
const baseSettings = agentSettings && agentSettings !== null ? agentSettings : {};
|
|
109060
|
+
const mergedSettings = requestSettings && requestSettings !== null ? { ...baseSettings, ...requestSettings } : baseSettings;
|
|
109061
|
+
const requestChangedMode = requestSettings !== undefined && requestSettings !== null && hasOwn5(requestSettings, "mode");
|
|
109062
|
+
const requestChangedPrompt = requestSettings !== undefined && requestSettings !== null && hasOwn5(requestSettings, "prompt");
|
|
109063
|
+
if (requestChangedMode && !requestChangedPrompt && agentSettings && agentSettings !== null && agentSettings.mode !== requestSettings.mode) {
|
|
109064
|
+
delete mergedSettings.prompt;
|
|
109065
|
+
}
|
|
109066
|
+
const mode = localCompactionMode(mergedSettings.mode) ?? LOCAL_DEFAULT_COMPACTION_MODE;
|
|
109067
|
+
return {
|
|
109068
|
+
mode,
|
|
109069
|
+
prompt: typeof mergedSettings.prompt === "string" || mergedSettings.prompt === null ? mergedSettings.prompt : undefined,
|
|
109070
|
+
clipChars: typeof mergedSettings.clip_chars === "number" || mergedSettings.clip_chars === null ? mergedSettings.clip_chars : undefined,
|
|
109071
|
+
slidingWindowPercentage: typeof mergedSettings.sliding_window_percentage === "number" ? mergedSettings.sliding_window_percentage : LOCAL_DEFAULT_SLIDING_WINDOW_PERCENTAGE
|
|
109072
|
+
};
|
|
109073
|
+
}
|
|
109074
|
+
var LOCAL_COMPACTION_MODES;
|
|
109075
|
+
var init_compaction_settings = __esm(() => {
|
|
109076
|
+
init_compaction();
|
|
109077
|
+
LOCAL_COMPACTION_MODES = [
|
|
109078
|
+
"all",
|
|
109079
|
+
"sliding_window",
|
|
109080
|
+
"self_compact_all",
|
|
109081
|
+
"self_compact_sliding_window"
|
|
109082
|
+
];
|
|
108458
109083
|
});
|
|
108459
109084
|
|
|
108460
109085
|
// src/backend/local/initial-memory.ts
|
|
@@ -108682,96 +109307,6 @@ async function sleepWithAbort(delayMs, abortSignal) {
|
|
|
108682
109307
|
abortSignal?.addEventListener("abort", onAbort, { once: true });
|
|
108683
109308
|
});
|
|
108684
109309
|
}
|
|
108685
|
-
function isClientTool(value) {
|
|
108686
|
-
return isRecord2(value) && typeof value.name === "string";
|
|
108687
|
-
}
|
|
108688
|
-
function toPiTools(clientTools) {
|
|
108689
|
-
const tools = [];
|
|
108690
|
-
for (const value of clientTools) {
|
|
108691
|
-
if (!isClientTool(value))
|
|
108692
|
-
continue;
|
|
108693
|
-
const schema = isRecord2(value.parameters) ? value.parameters : { type: "object", properties: {} };
|
|
108694
|
-
tools.push({
|
|
108695
|
-
name: value.name,
|
|
108696
|
-
description: value.description ?? "",
|
|
108697
|
-
parameters: schema
|
|
108698
|
-
});
|
|
108699
|
-
}
|
|
108700
|
-
return tools.length > 0 ? tools : undefined;
|
|
108701
|
-
}
|
|
108702
|
-
function isEmptyTextBlock(block) {
|
|
108703
|
-
return block.type === "text" && typeof block.text === "string" && block.text.trim().length === 0;
|
|
108704
|
-
}
|
|
108705
|
-
function dropEmptyTextBlocks(content) {
|
|
108706
|
-
return content.filter((block) => !isEmptyTextBlock(block));
|
|
108707
|
-
}
|
|
108708
|
-
function normalizeUserContent(content) {
|
|
108709
|
-
if (typeof content === "string") {
|
|
108710
|
-
return content.trim().length > 0 ? content : undefined;
|
|
108711
|
-
}
|
|
108712
|
-
const normalized = dropEmptyTextBlocks(content);
|
|
108713
|
-
return normalized.length > 0 ? normalized : undefined;
|
|
108714
|
-
}
|
|
108715
|
-
function normalizeAssistantContent(content) {
|
|
108716
|
-
const normalized = dropEmptyTextBlocks(content);
|
|
108717
|
-
return normalized.length > 0 ? normalized : undefined;
|
|
108718
|
-
}
|
|
108719
|
-
function normalizeToolResultContent(content) {
|
|
108720
|
-
const normalized = dropEmptyTextBlocks(content);
|
|
108721
|
-
return normalized.length > 0 ? normalized : [{ type: "text", text: EMPTY_TOOL_RESULT_PLACEHOLDER }];
|
|
108722
|
-
}
|
|
108723
|
-
function toPiMessage(message) {
|
|
108724
|
-
if (message.role === "user") {
|
|
108725
|
-
const content2 = normalizeUserContent(message.content);
|
|
108726
|
-
if (!content2)
|
|
108727
|
-
return;
|
|
108728
|
-
return {
|
|
108729
|
-
role: "user",
|
|
108730
|
-
content: content2,
|
|
108731
|
-
timestamp: message.timestamp
|
|
108732
|
-
};
|
|
108733
|
-
}
|
|
108734
|
-
if (message.role === "toolResult") {
|
|
108735
|
-
return {
|
|
108736
|
-
role: "toolResult",
|
|
108737
|
-
toolCallId: message.toolCallId,
|
|
108738
|
-
toolName: message.toolName,
|
|
108739
|
-
content: normalizeToolResultContent(message.content),
|
|
108740
|
-
details: message.details,
|
|
108741
|
-
isError: message.isError,
|
|
108742
|
-
timestamp: message.timestamp
|
|
108743
|
-
};
|
|
108744
|
-
}
|
|
108745
|
-
const content = normalizeAssistantContent(message.content);
|
|
108746
|
-
if (!content)
|
|
108747
|
-
return;
|
|
108748
|
-
return {
|
|
108749
|
-
role: "assistant",
|
|
108750
|
-
content,
|
|
108751
|
-
api: message.api,
|
|
108752
|
-
provider: message.provider,
|
|
108753
|
-
model: message.model,
|
|
108754
|
-
...message.responseModel ? { responseModel: message.responseModel } : {},
|
|
108755
|
-
...message.responseId ? { responseId: message.responseId } : {},
|
|
108756
|
-
...message.providerThinkingLevel ? { providerThinkingLevel: message.providerThinkingLevel } : {},
|
|
108757
|
-
...message.diagnostics ? { diagnostics: message.diagnostics } : {},
|
|
108758
|
-
usage: message.usage,
|
|
108759
|
-
stopReason: message.stopReason,
|
|
108760
|
-
...message.errorMessage ? { errorMessage: message.errorMessage } : {},
|
|
108761
|
-
timestamp: message.timestamp
|
|
108762
|
-
};
|
|
108763
|
-
}
|
|
108764
|
-
function toPiMessages(messages) {
|
|
108765
|
-
const providerSafeMessages = removeOrphanLocalToolResults(messages).messages;
|
|
108766
|
-
let normalized = providerSafeMessages.flatMap((message) => {
|
|
108767
|
-
const piMessage = toPiMessage(message);
|
|
108768
|
-
return piMessage ? [piMessage] : [];
|
|
108769
|
-
});
|
|
108770
|
-
while (normalized.length > 0 && normalized.at(-1)?.role === "assistant") {
|
|
108771
|
-
normalized = normalized.slice(0, -1);
|
|
108772
|
-
}
|
|
108773
|
-
return normalized;
|
|
108774
|
-
}
|
|
108775
109310
|
function stripOpenAIResponsesReplayItemIds(payload) {
|
|
108776
109311
|
if (!isRecord2(payload) || !Array.isArray(payload.input))
|
|
108777
109312
|
return;
|
|
@@ -108855,9 +109390,6 @@ function anthropicEffortForSettings(modelSettings) {
|
|
|
108855
109390
|
const nestedReasoning = isRecord2(modelSettings.reasoning) ? modelSettings.reasoning : undefined;
|
|
108856
109391
|
return stringValue2(modelSettings.effort) ?? stringValue2(nestedReasoning?.reasoning_effort) ?? stringValue2(modelSettings.reasoning_effort);
|
|
108857
109392
|
}
|
|
108858
|
-
function finiteNumberValue(value) {
|
|
108859
|
-
return typeof value === "number" && Number.isFinite(value) ? value : undefined;
|
|
108860
|
-
}
|
|
108861
109393
|
function serviceTierForSettings(model2, modelSettings) {
|
|
108862
109394
|
if (model2.api !== "openai-codex-responses")
|
|
108863
109395
|
return;
|
|
@@ -109006,8 +109538,6 @@ class PiStreamAdapter {
|
|
|
109006
109538
|
conversationId: input.conversationId,
|
|
109007
109539
|
requestKind: "turn"
|
|
109008
109540
|
});
|
|
109009
|
-
const maxTokens = finiteNumberValue(input.agent.model_settings.max_tokens);
|
|
109010
|
-
const temperature = finiteNumberValue(input.agent.model_settings.temperature);
|
|
109011
109541
|
const options = {
|
|
109012
109542
|
...resolved.providerOptions,
|
|
109013
109543
|
...resolved.apiKey ? { apiKey: resolved.apiKey } : {},
|
|
@@ -109016,10 +109546,8 @@ class PiStreamAdapter {
|
|
|
109016
109546
|
...this.abortSignal ? { signal: this.abortSignal } : {},
|
|
109017
109547
|
maxRetries: 0,
|
|
109018
109548
|
sessionId: input.conversationId,
|
|
109019
|
-
...
|
|
109549
|
+
...samplingOptionsForSettings(input.agent.model_settings),
|
|
109020
109550
|
...reasoning ? { reasoning } : {},
|
|
109021
|
-
...maxTokens ? { maxTokens } : {},
|
|
109022
|
-
...temperature !== undefined ? { temperature } : {},
|
|
109023
109551
|
...serviceTierForSettings(resolved.model, input.agent.model_settings) ? {
|
|
109024
109552
|
serviceTier: serviceTierForSettings(resolved.model, input.agent.model_settings)
|
|
109025
109553
|
} : {},
|
|
@@ -109236,7 +109764,7 @@ class PiStreamAdapter {
|
|
|
109236
109764
|
}
|
|
109237
109765
|
}
|
|
109238
109766
|
}
|
|
109239
|
-
var LOCAL_PROVIDER_MAX_RETRIES = 3, LOCAL_PROVIDER_ADAPTIVE_IMAGE_ELISION_AFTER_RETRIES, LOCAL_CONTEXT_OVERFLOW_MAX_COMPACTIONS = 3, PiProviderError
|
|
109767
|
+
var LOCAL_PROVIDER_MAX_RETRIES = 3, LOCAL_PROVIDER_ADAPTIVE_IMAGE_ELISION_AFTER_RETRIES, LOCAL_CONTEXT_OVERFLOW_MAX_COMPACTIONS = 3, PiProviderError;
|
|
109240
109768
|
var init_pi_stream_adapter = __esm(() => {
|
|
109241
109769
|
init_dist3();
|
|
109242
109770
|
init_local_model_config();
|
|
@@ -109244,6 +109772,7 @@ var init_pi_stream_adapter = __esm(() => {
|
|
|
109244
109772
|
init_context_window_overflow();
|
|
109245
109773
|
init_local_provider_errors();
|
|
109246
109774
|
init_pi_image_elision();
|
|
109775
|
+
init_pi_messages2();
|
|
109247
109776
|
init_pi_model_factory();
|
|
109248
109777
|
init_pi_models_runtime();
|
|
109249
109778
|
init_provider_turn_executor();
|
|
@@ -109622,26 +110151,6 @@ var init_system_prompt_compilation = __esm(() => {
|
|
|
109622
110151
|
});
|
|
109623
110152
|
|
|
109624
110153
|
// src/backend/local/local-backend.ts
|
|
109625
|
-
function compactionSettingsRecord(value) {
|
|
109626
|
-
if (value === null)
|
|
109627
|
-
return null;
|
|
109628
|
-
return isRecord2(value) ? { ...value } : undefined;
|
|
109629
|
-
}
|
|
109630
|
-
function hasOwn5(record2, key) {
|
|
109631
|
-
return Object.hasOwn(record2, key);
|
|
109632
|
-
}
|
|
109633
|
-
function localCompactionMode(value) {
|
|
109634
|
-
if (value === "all" || value === "sliding_window")
|
|
109635
|
-
return value;
|
|
109636
|
-
return;
|
|
109637
|
-
}
|
|
109638
|
-
function validateLocalCompactionSettingsRecord(settings) {
|
|
109639
|
-
if (settings.mode === undefined || settings.mode === null)
|
|
109640
|
-
return;
|
|
109641
|
-
if (!localCompactionMode(settings.mode)) {
|
|
109642
|
-
throw new Error(`Local backend compaction currently supports only modes "all" and "sliding_window" (received "${String(settings.mode)}").`);
|
|
109643
|
-
}
|
|
109644
|
-
}
|
|
109645
110154
|
function formatMidConversationMemoryUpdate(compiled) {
|
|
109646
110155
|
return [
|
|
109647
110156
|
"<memory_update>",
|
|
@@ -109658,10 +110167,12 @@ var init_local_backend = __esm(() => {
|
|
|
109658
110167
|
init_memory_filesystem2();
|
|
109659
110168
|
init_memory_git();
|
|
109660
110169
|
init_headless_backend();
|
|
110170
|
+
init_pi_messages2();
|
|
109661
110171
|
init_pi_models_runtime();
|
|
109662
110172
|
init_provider_turn_executor();
|
|
109663
110173
|
init_settings_manager();
|
|
109664
110174
|
init_compaction();
|
|
110175
|
+
init_compaction_settings();
|
|
109665
110176
|
init_initial_memory();
|
|
109666
110177
|
init_local_executor_factory();
|
|
109667
110178
|
init_local_model_config();
|
|
@@ -109796,13 +110307,13 @@ var init_local_backend = __esm(() => {
|
|
|
109796
110307
|
async updateAgent(...args) {
|
|
109797
110308
|
const [agentId, body] = args;
|
|
109798
110309
|
const bodyRecord = body;
|
|
109799
|
-
const settings =
|
|
110310
|
+
const settings = Object.hasOwn(bodyRecord, "compaction_settings") ? compactionSettingsRecord(bodyRecord.compaction_settings) : undefined;
|
|
109800
110311
|
if (settings !== undefined && settings !== null) {
|
|
109801
110312
|
validateLocalCompactionSettingsRecord(settings);
|
|
109802
110313
|
}
|
|
109803
110314
|
const compactionSettingsForStorage = localCompactionSettingsForStorage(settings);
|
|
109804
110315
|
let agent = await super.updateAgent(...args);
|
|
109805
|
-
if (
|
|
110316
|
+
if (Object.hasOwn(bodyRecord, "compaction_settings")) {
|
|
109806
110317
|
if (compactionSettingsForStorage !== undefined) {
|
|
109807
110318
|
agent = this.store.setAgentCompactionSettings(agentId, compactionSettingsForStorage);
|
|
109808
110319
|
}
|
|
@@ -109866,7 +110377,7 @@ var init_local_backend = __esm(() => {
|
|
|
109866
110377
|
});
|
|
109867
110378
|
}
|
|
109868
110379
|
async compactAfterContextOverflow(input, _error) {
|
|
109869
|
-
const result = await this.compactLocalConversation(input.conversationId, input.agentId, "context_window_overflow");
|
|
110380
|
+
const result = await this.compactLocalConversation(input.conversationId, input.agentId, "context_window_overflow", undefined, input);
|
|
109870
110381
|
return {
|
|
109871
110382
|
uiMessages: this.store.listLocalMessages(input.conversationId, input.agentId),
|
|
109872
110383
|
summary: result.summary,
|
|
@@ -109876,7 +110387,7 @@ var init_local_backend = __esm(() => {
|
|
|
109876
110387
|
async compactForContextPressure(input, pressure) {
|
|
109877
110388
|
const messageTokens = estimateLocalMessageTokens2(this.store.listLocalMessages(input.conversationId, input.agentId));
|
|
109878
110389
|
const fixedTokens = Math.max(0, pressure.contextTokens - messageTokens);
|
|
109879
|
-
const result = await runLocalPressureCompaction(() => this.compactLocalConversation(input.conversationId, input.agentId, "context_window_limit", undefined, (contextCompactionThreshold(pressure.contextWindow) ?? 0) - fixedTokens));
|
|
110390
|
+
const result = await runLocalPressureCompaction(() => this.compactLocalConversation(input.conversationId, input.agentId, "context_window_limit", undefined, input, (contextCompactionThreshold(pressure.contextWindow) ?? 0) - fixedTokens));
|
|
109880
110391
|
if (!result)
|
|
109881
110392
|
return null;
|
|
109882
110393
|
return {
|
|
@@ -109916,43 +110427,22 @@ var init_local_backend = __esm(() => {
|
|
|
109916
110427
|
} : {}
|
|
109917
110428
|
};
|
|
109918
110429
|
}
|
|
109919
|
-
|
|
109920
|
-
const bodyRecord = body ?? {};
|
|
109921
|
-
const requestSettings = compactionSettingsRecord(bodyRecord.compaction_settings);
|
|
109922
|
-
if (requestSettings !== undefined && requestSettings !== null) {
|
|
109923
|
-
validateLocalCompactionSettingsRecord(requestSettings);
|
|
109924
|
-
}
|
|
109925
|
-
const agentSettings = compactionSettingsRecord(agent.compaction_settings);
|
|
109926
|
-
const baseSettings = agentSettings && agentSettings !== null ? agentSettings : {};
|
|
109927
|
-
const mergedSettings = requestSettings && requestSettings !== null ? { ...baseSettings, ...requestSettings } : baseSettings;
|
|
109928
|
-
const requestChangedMode = requestSettings !== undefined && requestSettings !== null && hasOwn5(requestSettings, "mode");
|
|
109929
|
-
const requestChangedPrompt = requestSettings !== undefined && requestSettings !== null && hasOwn5(requestSettings, "prompt");
|
|
109930
|
-
if (requestChangedMode && !requestChangedPrompt && agentSettings && agentSettings !== null && agentSettings.mode !== requestSettings.mode) {
|
|
109931
|
-
delete mergedSettings.prompt;
|
|
109932
|
-
}
|
|
109933
|
-
const mode = localCompactionMode(mergedSettings.mode) ?? LOCAL_DEFAULT_COMPACTION_MODE;
|
|
109934
|
-
return {
|
|
109935
|
-
mode,
|
|
109936
|
-
prompt: typeof mergedSettings.prompt === "string" || mergedSettings.prompt === null ? mergedSettings.prompt : undefined,
|
|
109937
|
-
clipChars: typeof mergedSettings.clip_chars === "number" || mergedSettings.clip_chars === null ? mergedSettings.clip_chars : undefined,
|
|
109938
|
-
slidingWindowPercentage: typeof mergedSettings.sliding_window_percentage === "number" ? mergedSettings.sliding_window_percentage : LOCAL_DEFAULT_SLIDING_WINDOW_PERCENTAGE
|
|
109939
|
-
};
|
|
109940
|
-
}
|
|
109941
|
-
async compactLocalConversation(conversationId, agentId, trigger, body, maxMessageTokens) {
|
|
110430
|
+
async compactLocalConversation(conversationId, agentId, trigger, body, turn, maxMessageTokens) {
|
|
109942
110431
|
await this.emitCompactStart(conversationId, agentId, trigger);
|
|
109943
|
-
const result = await this.compactLocalConversationInner(conversationId, agentId, trigger, body, maxMessageTokens);
|
|
110432
|
+
const result = await this.compactLocalConversationInner(conversationId, agentId, trigger, body, turn, maxMessageTokens);
|
|
109944
110433
|
await this.emitCompactEnd(conversationId, agentId, trigger, result.stats);
|
|
109945
110434
|
return result;
|
|
109946
110435
|
}
|
|
109947
|
-
async compactLocalConversationInner(conversationId, agentId, trigger, body, maxMessageTokens) {
|
|
110436
|
+
async compactLocalConversationInner(conversationId, agentId, trigger, body, turn, maxMessageTokens) {
|
|
109948
110437
|
const agent = this.effectiveAgentForConversation(conversationId, agentId);
|
|
109949
110438
|
const settings = {
|
|
109950
|
-
...
|
|
110439
|
+
...resolveLocalCompactionSettings(agent, body),
|
|
109951
110440
|
maxMessageTokens
|
|
109952
110441
|
};
|
|
109953
|
-
|
|
110442
|
+
const self2 = isLocalSelfCompactionMode(settings.mode) ? await this.selfCompactionContext(conversationId, agentId, turn) : undefined;
|
|
110443
|
+
if (isLocalSlidingWindowMode(settings.mode)) {
|
|
109954
110444
|
try {
|
|
109955
|
-
const result2 = await this.
|
|
110445
|
+
const result2 = await this.compactLocalConversationPass(conversationId, agentId, agent, trigger, settings, self2);
|
|
109956
110446
|
if (result2.stats.context_window === undefined || result2.stats.context_tokens_after === undefined || result2.stats.context_tokens_after < result2.stats.context_window) {
|
|
109957
110447
|
await this.compileAndMaybePersistSystemPrompt(conversationId, agentId, {
|
|
109958
110448
|
dryRun: false
|
|
@@ -109964,66 +110454,28 @@ var init_local_backend = __esm(() => {
|
|
|
109964
110454
|
throw error3;
|
|
109965
110455
|
}
|
|
109966
110456
|
}
|
|
109967
|
-
const result = await this.
|
|
110457
|
+
const result = await this.compactLocalConversationPass(conversationId, agentId, agent, trigger, {
|
|
109968
110458
|
...settings,
|
|
109969
|
-
mode: "all",
|
|
110459
|
+
mode: self2 ? "self_compact_all" : "all",
|
|
109970
110460
|
prompt: settings.prompt
|
|
109971
|
-
});
|
|
110461
|
+
}, self2);
|
|
109972
110462
|
await this.compileAndMaybePersistSystemPrompt(conversationId, agentId, {
|
|
109973
110463
|
dryRun: false
|
|
109974
110464
|
});
|
|
109975
110465
|
return result;
|
|
109976
110466
|
}
|
|
109977
|
-
async
|
|
109978
|
-
const
|
|
109979
|
-
const contextTokensBefore = estimateLocalMessageTokens2(messages);
|
|
109980
|
-
const plan = planLocalAllCompaction(messages);
|
|
109981
|
-
const keptTokens = estimateLocalMessageTokens2(plan.messagesToKeep);
|
|
109982
|
-
assertLocalPressureBudget(keptTokens, "all", settings.maxMessageTokens);
|
|
109983
|
-
const summary = await summarizeLocalMessagesAll({
|
|
109984
|
-
conversationId,
|
|
109985
|
-
agent,
|
|
109986
|
-
messages: plan.messagesToSummarize,
|
|
109987
|
-
complete: this.complete,
|
|
109988
|
-
prompt: settings.prompt,
|
|
109989
|
-
clipChars: settings.clipChars,
|
|
109990
|
-
localProviderAuthStorageDir: this.storageDir,
|
|
109991
|
-
modelsRuntime: this.piModelsRuntime
|
|
109992
|
-
});
|
|
109993
|
-
const stats = {
|
|
109994
|
-
trigger,
|
|
109995
|
-
context_tokens_before: contextTokensBefore,
|
|
109996
|
-
context_tokens_after: Math.ceil(summary.length / 4) + keptTokens,
|
|
109997
|
-
context_window: this.effectiveContextWindow(conversationId, agentId),
|
|
109998
|
-
messages_count_before: messages.length,
|
|
109999
|
-
messages_count_after: 1 + plan.messagesToKeep.length
|
|
110000
|
-
};
|
|
110001
|
-
assertLocalPressureBudget(stats.context_tokens_after ?? 0, "all", settings.maxMessageTokens);
|
|
110002
|
-
return finishLocalFullCompaction({
|
|
110003
|
-
messages,
|
|
110004
|
-
summary,
|
|
110005
|
-
stats,
|
|
110006
|
-
plan,
|
|
110007
|
-
systemPrompt: agent.system,
|
|
110008
|
-
persist: (summary2, packedSummary, remainingMessages) => this.store.compactConversationAll({
|
|
110009
|
-
conversationId,
|
|
110010
|
-
agentId,
|
|
110011
|
-
summary: summary2,
|
|
110012
|
-
packedSummary,
|
|
110013
|
-
stats,
|
|
110014
|
-
remainingMessages
|
|
110015
|
-
})
|
|
110016
|
-
});
|
|
110017
|
-
}
|
|
110018
|
-
async compactLocalConversationSlidingWindow(conversationId, agentId, agent, trigger, settings) {
|
|
110467
|
+
async compactLocalConversationPass(conversationId, agentId, agent, trigger, settings, self2) {
|
|
110468
|
+
const slidingWindow = isLocalSlidingWindowMode(settings.mode);
|
|
110019
110469
|
const messages = this.store.listLocalMessages(conversationId, agentId);
|
|
110020
110470
|
const contextWindow = this.effectiveContextWindow(conversationId, agentId);
|
|
110021
|
-
const plan = planLocalSlidingWindowCompaction(messages, {
|
|
110471
|
+
const plan = slidingWindow ? planLocalSlidingWindowCompaction(messages, {
|
|
110022
110472
|
slidingWindowPercentage: settings.slidingWindowPercentage,
|
|
110023
110473
|
contextWindow
|
|
110024
|
-
});
|
|
110025
|
-
|
|
110026
|
-
|
|
110474
|
+
}) : planLocalAllCompaction(messages);
|
|
110475
|
+
const keptTokens = estimateLocalMessageTokens2(plan.messagesToKeep);
|
|
110476
|
+
assertLocalPressureBudget(keptTokens, settings.mode, settings.maxMessageTokens);
|
|
110477
|
+
const summarize = slidingWindow ? summarizeLocalMessagesSlidingWindow : summarizeLocalMessagesAll;
|
|
110478
|
+
const summary = await summarize({
|
|
110027
110479
|
conversationId,
|
|
110028
110480
|
agent,
|
|
110029
110481
|
messages: plan.messagesToSummarize,
|
|
@@ -110031,18 +110483,36 @@ var init_local_backend = __esm(() => {
|
|
|
110031
110483
|
prompt: settings.prompt,
|
|
110032
110484
|
clipChars: settings.clipChars,
|
|
110033
110485
|
localProviderAuthStorageDir: this.storageDir,
|
|
110034
|
-
modelsRuntime: this.piModelsRuntime
|
|
110486
|
+
modelsRuntime: this.piModelsRuntime,
|
|
110487
|
+
self: self2
|
|
110035
110488
|
});
|
|
110036
|
-
const contextTokensAfter = Math.ceil(summary.length / 4) + estimateLocalMessageTokens2(plan.messagesToKeep);
|
|
110037
110489
|
const stats = {
|
|
110038
110490
|
trigger,
|
|
110039
110491
|
context_tokens_before: estimateLocalMessageTokens2(messages),
|
|
110040
|
-
context_tokens_after:
|
|
110492
|
+
context_tokens_after: Math.ceil(summary.length / 4) + keptTokens,
|
|
110041
110493
|
context_window: contextWindow,
|
|
110042
110494
|
messages_count_before: messages.length,
|
|
110043
110495
|
messages_count_after: 1 + plan.messagesToKeep.length
|
|
110044
110496
|
};
|
|
110045
|
-
|
|
110497
|
+
if (!slidingWindow) {
|
|
110498
|
+
assertLocalPressureBudget(stats.context_tokens_after ?? 0, settings.mode, settings.maxMessageTokens);
|
|
110499
|
+
return finishLocalFullCompaction({
|
|
110500
|
+
messages,
|
|
110501
|
+
summary,
|
|
110502
|
+
stats,
|
|
110503
|
+
plan,
|
|
110504
|
+
systemPrompt: agent.system,
|
|
110505
|
+
persist: (summary2, packedSummary, remainingMessages) => this.store.compactConversationAll({
|
|
110506
|
+
conversationId,
|
|
110507
|
+
agentId,
|
|
110508
|
+
summary: summary2,
|
|
110509
|
+
packedSummary,
|
|
110510
|
+
stats,
|
|
110511
|
+
remainingMessages
|
|
110512
|
+
})
|
|
110513
|
+
});
|
|
110514
|
+
}
|
|
110515
|
+
assertLocalCompactionProgress(stats, settings.mode, settings.maxMessageTokens);
|
|
110046
110516
|
const storeResult = this.store.compactConversationAll({
|
|
110047
110517
|
conversationId,
|
|
110048
110518
|
agentId,
|
|
@@ -110058,6 +110528,16 @@ var init_local_backend = __esm(() => {
|
|
|
110058
110528
|
stats
|
|
110059
110529
|
};
|
|
110060
110530
|
}
|
|
110531
|
+
async selfCompactionContext(conversationId, agentId, turn) {
|
|
110532
|
+
if (turn) {
|
|
110533
|
+
return {
|
|
110534
|
+
systemPrompt: turn.systemPrompt ?? turn.agent.system,
|
|
110535
|
+
tools: toPiTools(turn.clientTools)
|
|
110536
|
+
};
|
|
110537
|
+
}
|
|
110538
|
+
const compiled = await this.getOrCompileSystemPrompt(conversationId, agentId);
|
|
110539
|
+
return { systemPrompt: compiled.content };
|
|
110540
|
+
}
|
|
110061
110541
|
async getOrCompileSystemPrompt(conversationId, agentId, agent = this.store.retrieveAgentRecord(agentId), previousMessageCount = 0) {
|
|
110062
110542
|
const existing = this.store.getCompiledSystemPrompt(conversationId, agentId);
|
|
110063
110543
|
const rawSystemHash = hashRawSystemPrompt(agent.system);
|
|
@@ -110870,364 +111350,6 @@ var init_check_approval = __esm(() => {
|
|
|
110870
111350
|
];
|
|
110871
111351
|
});
|
|
110872
111352
|
|
|
110873
|
-
// src/utils/subagent-launch-marker.ts
|
|
110874
|
-
function consumeSubagentLaunch(env4) {
|
|
110875
|
-
const isLaunch = env4[SUBAGENT_LAUNCH_ENV] === "1";
|
|
110876
|
-
delete env4[SUBAGENT_LAUNCH_ENV];
|
|
110877
|
-
return isLaunch;
|
|
110878
|
-
}
|
|
110879
|
-
var SUBAGENT_LAUNCH_ENV = "LETTA_SUBAGENT_LAUNCH", SUBAGENT_LAUNCH_PROFILE_ENV = "LETTA_SUBAGENT_LAUNCH_PROFILE", SUBAGENT_NAME_ENV = "LETTA_SUBAGENT_NAME", LISTENER_CONNECTION_ENV = "LETTA_RUNTIME_LISTENER_CONNECTION_ID";
|
|
110880
|
-
|
|
110881
|
-
// src/agent/subagents/names.ts
|
|
110882
|
-
function createSubagentNameAllocator(random = Math.random) {
|
|
110883
|
-
let available = [];
|
|
110884
|
-
let round = 0;
|
|
110885
|
-
const ordinals = new Intl.PluralRules("en", { type: "ordinal" });
|
|
110886
|
-
const suffixes = { one: "st", two: "nd", few: "rd" };
|
|
110887
|
-
return () => {
|
|
110888
|
-
if (available.length === 0) {
|
|
110889
|
-
available = [...SUBAGENT_NAMES];
|
|
110890
|
-
round += 1;
|
|
110891
|
-
}
|
|
110892
|
-
const index = Math.floor(random() * available.length);
|
|
110893
|
-
const name = available.splice(index, 1)[0];
|
|
110894
|
-
const ordinal = `${round}${suffixes[ordinals.select(round)] ?? "th"}`;
|
|
110895
|
-
return `${name}${round === 1 ? "" : ` the ${ordinal}`}`;
|
|
110896
|
-
};
|
|
110897
|
-
}
|
|
110898
|
-
function allocateSubagentName(_parentName) {
|
|
110899
|
-
return nextName();
|
|
110900
|
-
}
|
|
110901
|
-
function resolveCreatedAgentName(name, isSubagent, assignedName) {
|
|
110902
|
-
return name ?? (isSubagent ? assignedName || allocateSubagentName() : DEFAULT_AGENT_NAME);
|
|
110903
|
-
}
|
|
110904
|
-
var SUBAGENT_NAMES, nextName;
|
|
110905
|
-
var init_names = __esm(() => {
|
|
110906
|
-
init_constants2();
|
|
110907
|
-
SUBAGENT_NAMES = [
|
|
110908
|
-
"Deckard",
|
|
110909
|
-
"Roy Batty",
|
|
110910
|
-
"Pris",
|
|
110911
|
-
"Zhora",
|
|
110912
|
-
"Gaff",
|
|
110913
|
-
"Tyrell",
|
|
110914
|
-
"K",
|
|
110915
|
-
"Joi",
|
|
110916
|
-
"Luv",
|
|
110917
|
-
"Sapper",
|
|
110918
|
-
"Freysa",
|
|
110919
|
-
"Ava",
|
|
110920
|
-
"Kyoko",
|
|
110921
|
-
"V",
|
|
110922
|
-
"Silverhand",
|
|
110923
|
-
"Panam",
|
|
110924
|
-
"Rogue",
|
|
110925
|
-
"Alt Cunningham",
|
|
110926
|
-
"Takemura",
|
|
110927
|
-
"Hanako",
|
|
110928
|
-
"Yorinobu",
|
|
110929
|
-
"Saburo",
|
|
110930
|
-
"Oda",
|
|
110931
|
-
"T-Bug",
|
|
110932
|
-
"Delamain",
|
|
110933
|
-
"Wakako",
|
|
110934
|
-
"Padre",
|
|
110935
|
-
"El Capitan",
|
|
110936
|
-
"Placide",
|
|
110937
|
-
"Dum Dum",
|
|
110938
|
-
"Nix",
|
|
110939
|
-
"Weyland",
|
|
110940
|
-
"Scorpion",
|
|
110941
|
-
"Blue Moon",
|
|
110942
|
-
"Red Menace",
|
|
110943
|
-
"Purple Force",
|
|
110944
|
-
"Lizzy Wizzy",
|
|
110945
|
-
"Ozob",
|
|
110946
|
-
"Smasher",
|
|
110947
|
-
"Songbird",
|
|
110948
|
-
"Slider",
|
|
110949
|
-
"Aguilar",
|
|
110950
|
-
"Codsworth",
|
|
110951
|
-
"Nick Valentine",
|
|
110952
|
-
"Yes Man",
|
|
110953
|
-
"Mr. House",
|
|
110954
|
-
"ED-E",
|
|
110955
|
-
"Fisto",
|
|
110956
|
-
"Liberty Prime",
|
|
110957
|
-
"Three Dog",
|
|
110958
|
-
"Charon",
|
|
110959
|
-
"Fawkes",
|
|
110960
|
-
"Ulysses",
|
|
110961
|
-
"The Master",
|
|
110962
|
-
"Muggy",
|
|
110963
|
-
"Dr. Mobius",
|
|
110964
|
-
"Dr. Klein",
|
|
110965
|
-
"Old Longfellow",
|
|
110966
|
-
"Pickman",
|
|
110967
|
-
"Butch DeLoria",
|
|
110968
|
-
"Fantastic",
|
|
110969
|
-
"Muad'Dib",
|
|
110970
|
-
"Stilgar",
|
|
110971
|
-
"Chani",
|
|
110972
|
-
"Gurney Halleck",
|
|
110973
|
-
"Duncan Idaho",
|
|
110974
|
-
"Thufir Hawat",
|
|
110975
|
-
"Liet-Kynes",
|
|
110976
|
-
"Shadout Mapes",
|
|
110977
|
-
"Feyd-Rautha",
|
|
110978
|
-
"Rabban",
|
|
110979
|
-
"Piter De Vries",
|
|
110980
|
-
"Irulan",
|
|
110981
|
-
"Scytale",
|
|
110982
|
-
"Hayt",
|
|
110983
|
-
"Bijaz",
|
|
110984
|
-
"Moneo",
|
|
110985
|
-
"Miles Teg",
|
|
110986
|
-
"Darwi Odrade",
|
|
110987
|
-
"Sheeana",
|
|
110988
|
-
"Shaddam IV",
|
|
110989
|
-
"Count Fenring",
|
|
110990
|
-
"Wintermute",
|
|
110991
|
-
"Neuromancer",
|
|
110992
|
-
"Dixie Flatline",
|
|
110993
|
-
"Molly Millions",
|
|
110994
|
-
"Lady 3Jane",
|
|
110995
|
-
"Armitage",
|
|
110996
|
-
"Maelcum",
|
|
110997
|
-
"Ratz",
|
|
110998
|
-
"The Finn",
|
|
110999
|
-
"Hiro Protagonist",
|
|
111000
|
-
"Y.T.",
|
|
111001
|
-
"Raven",
|
|
111002
|
-
"Uncle Enzo",
|
|
111003
|
-
"R. Daneel Olivaw",
|
|
111004
|
-
"R. Giskard Reventlov",
|
|
111005
|
-
"Hari Seldon",
|
|
111006
|
-
"Dors Venabili",
|
|
111007
|
-
"The Mule",
|
|
111008
|
-
"HAL 9000",
|
|
111009
|
-
"Aineko",
|
|
111010
|
-
"Eschaton",
|
|
111011
|
-
"Mycroft Canner",
|
|
111012
|
-
"J.E.D.D. Mason",
|
|
111013
|
-
"Sniper",
|
|
111014
|
-
"Eureka Weeksbooth",
|
|
111015
|
-
"Susan Calvin",
|
|
111016
|
-
"Multivac",
|
|
111017
|
-
"Andrew Ryan",
|
|
111018
|
-
"Fontaine",
|
|
111019
|
-
"Sander Cohen",
|
|
111020
|
-
"Tenenbaum",
|
|
111021
|
-
"Suchong",
|
|
111022
|
-
"Dr. Steinman",
|
|
111023
|
-
"Big Daddy",
|
|
111024
|
-
"Mr. Bubbles",
|
|
111025
|
-
"Subject Delta",
|
|
111026
|
-
"Sofia Lamb",
|
|
111027
|
-
"Comstock",
|
|
111028
|
-
"Booker DeWitt",
|
|
111029
|
-
"Lutece",
|
|
111030
|
-
"Daisy Fitzroy",
|
|
111031
|
-
"SHODAN",
|
|
111032
|
-
"Xerxes",
|
|
111033
|
-
"The Many",
|
|
111034
|
-
"Polito",
|
|
111035
|
-
"JC Denton",
|
|
111036
|
-
"Gunther Hermann",
|
|
111037
|
-
"Tracer Tong",
|
|
111038
|
-
"Helios",
|
|
111039
|
-
"Adam Jensen",
|
|
111040
|
-
"Pritchard",
|
|
111041
|
-
"Shepard",
|
|
111042
|
-
"Garrus",
|
|
111043
|
-
"Tali'Zorah",
|
|
111044
|
-
"Wrex",
|
|
111045
|
-
"Mordin Solus",
|
|
111046
|
-
"Legion",
|
|
111047
|
-
"EDI",
|
|
111048
|
-
"Joker",
|
|
111049
|
-
"Saren",
|
|
111050
|
-
"Harbinger",
|
|
111051
|
-
"Illusive Man",
|
|
111052
|
-
"Aria T'Loak",
|
|
111053
|
-
"GLaDOS",
|
|
111054
|
-
"Wheatley",
|
|
111055
|
-
"Chell",
|
|
111056
|
-
"Cave Johnson",
|
|
111057
|
-
"Gordon Freeman",
|
|
111058
|
-
"Alyx Vance",
|
|
111059
|
-
"G-Man",
|
|
111060
|
-
"Dr. Breen",
|
|
111061
|
-
"Master Chief",
|
|
111062
|
-
"Cortana",
|
|
111063
|
-
"Arbiter",
|
|
111064
|
-
"Guilty Spark",
|
|
111065
|
-
"Dr. Halsey",
|
|
111066
|
-
"Noble Six",
|
|
111067
|
-
"Gravemind",
|
|
111068
|
-
"Solid Snake",
|
|
111069
|
-
"Big Boss",
|
|
111070
|
-
"Otacon",
|
|
111071
|
-
"Ocelot",
|
|
111072
|
-
"Raiden",
|
|
111073
|
-
"Psycho Mantis",
|
|
111074
|
-
"Gray Fox",
|
|
111075
|
-
"2B",
|
|
111076
|
-
"9S",
|
|
111077
|
-
"A2",
|
|
111078
|
-
"Pod 042",
|
|
111079
|
-
"Pascal",
|
|
111080
|
-
"Emil",
|
|
111081
|
-
"Aloy",
|
|
111082
|
-
"Sylens",
|
|
111083
|
-
"GAIA",
|
|
111084
|
-
"HADES",
|
|
111085
|
-
"Sobeck",
|
|
111086
|
-
"Deadman",
|
|
111087
|
-
"Heartman",
|
|
111088
|
-
"Die-Hardman",
|
|
111089
|
-
"Fragile",
|
|
111090
|
-
"Higgs",
|
|
111091
|
-
"Gabbro",
|
|
111092
|
-
"Feldspar",
|
|
111093
|
-
"Chert",
|
|
111094
|
-
"Riebeck",
|
|
111095
|
-
"Solanum",
|
|
111096
|
-
"Kerrigan",
|
|
111097
|
-
"Raynor",
|
|
111098
|
-
"Zeratul",
|
|
111099
|
-
"Tassadar",
|
|
111100
|
-
"Artanis",
|
|
111101
|
-
"Abathur",
|
|
111102
|
-
"Alarak",
|
|
111103
|
-
"Isaac Clarke",
|
|
111104
|
-
"The Marker",
|
|
111105
|
-
"WAU",
|
|
111106
|
-
"RK800",
|
|
111107
|
-
"Hank Anderson",
|
|
111108
|
-
"Markus",
|
|
111109
|
-
"Doom Slayer",
|
|
111110
|
-
"VEGA",
|
|
111111
|
-
"Claptrap",
|
|
111112
|
-
"Handsome Jack",
|
|
111113
|
-
"Moxxi",
|
|
111114
|
-
"Zer0",
|
|
111115
|
-
"Cayde-6",
|
|
111116
|
-
"Zavala",
|
|
111117
|
-
"Rasputin",
|
|
111118
|
-
"Xur",
|
|
111119
|
-
"Saint-14",
|
|
111120
|
-
"The Drifter",
|
|
111121
|
-
"January",
|
|
111122
|
-
"December",
|
|
111123
|
-
"Strelok",
|
|
111124
|
-
"Sidorovich",
|
|
111125
|
-
"HK-47",
|
|
111126
|
-
"T3-M4",
|
|
111127
|
-
"Revan",
|
|
111128
|
-
"Bastila Shan",
|
|
111129
|
-
"Kreia",
|
|
111130
|
-
"Data",
|
|
111131
|
-
"Spock",
|
|
111132
|
-
"Seven of Nine",
|
|
111133
|
-
"Q",
|
|
111134
|
-
"Lore",
|
|
111135
|
-
"Odo",
|
|
111136
|
-
"Garak",
|
|
111137
|
-
"Locutus",
|
|
111138
|
-
"Naomi Nagata",
|
|
111139
|
-
"Amos Burton",
|
|
111140
|
-
"Avasarala",
|
|
111141
|
-
"Detective Miller",
|
|
111142
|
-
"Julie Mao",
|
|
111143
|
-
"Camina Drummer",
|
|
111144
|
-
"Rocinante",
|
|
111145
|
-
"Sleeper Service",
|
|
111146
|
-
"Grey Area",
|
|
111147
|
-
"Just Read the Instructions",
|
|
111148
|
-
"Skaffen-Amtiskaw",
|
|
111149
|
-
"Mawhrin-Skel",
|
|
111150
|
-
"Gurgeh",
|
|
111151
|
-
"Zakalwe",
|
|
111152
|
-
"Marvin",
|
|
111153
|
-
"Zaphod Beeblebrox",
|
|
111154
|
-
"Ford Prefect",
|
|
111155
|
-
"Trillian",
|
|
111156
|
-
"Slartibartfast",
|
|
111157
|
-
"Deep Thought",
|
|
111158
|
-
"The Shrike",
|
|
111159
|
-
"Martin Silenus",
|
|
111160
|
-
"Het Masteen",
|
|
111161
|
-
"Kassad",
|
|
111162
|
-
"Ummon",
|
|
111163
|
-
"Kusanagi",
|
|
111164
|
-
"Batou",
|
|
111165
|
-
"Tachikoma",
|
|
111166
|
-
"Puppet Master",
|
|
111167
|
-
"Laughing Man",
|
|
111168
|
-
"Kaneda",
|
|
111169
|
-
"Tetsuo",
|
|
111170
|
-
"Rei Ayanami",
|
|
111171
|
-
"Misato Katsuragi",
|
|
111172
|
-
"Gendo Ikari",
|
|
111173
|
-
"MAGI",
|
|
111174
|
-
"Neo",
|
|
111175
|
-
"Trinity",
|
|
111176
|
-
"Morpheus",
|
|
111177
|
-
"Agent Smith",
|
|
111178
|
-
"The Oracle",
|
|
111179
|
-
"The Architect",
|
|
111180
|
-
"Merovingian",
|
|
111181
|
-
"Ripley",
|
|
111182
|
-
"Bishop",
|
|
111183
|
-
"MU/TH/UR",
|
|
111184
|
-
"David 8",
|
|
111185
|
-
"Vasquez",
|
|
111186
|
-
"Skynet",
|
|
111187
|
-
"T-800",
|
|
111188
|
-
"T-1000",
|
|
111189
|
-
"Kyle Reese",
|
|
111190
|
-
"Starbuck",
|
|
111191
|
-
"Adama",
|
|
111192
|
-
"Number Six",
|
|
111193
|
-
"Gaius Baltar",
|
|
111194
|
-
"Helo",
|
|
111195
|
-
"Laura Roslin",
|
|
111196
|
-
"Mal Reynolds",
|
|
111197
|
-
"Wash",
|
|
111198
|
-
"Jayne Cobb",
|
|
111199
|
-
"River Tam",
|
|
111200
|
-
"Serenity",
|
|
111201
|
-
"Ender Wiggin",
|
|
111202
|
-
"Bean",
|
|
111203
|
-
"Petra Arkanian",
|
|
111204
|
-
"Mazer Rackham",
|
|
111205
|
-
"SecUnit",
|
|
111206
|
-
"ART",
|
|
111207
|
-
"Dr. Mensah",
|
|
111208
|
-
"Breq",
|
|
111209
|
-
"Justice of Toren",
|
|
111210
|
-
"Seivarden",
|
|
111211
|
-
"Sophon",
|
|
111212
|
-
"Luo Ji",
|
|
111213
|
-
"Da Shi",
|
|
111214
|
-
"Zhang Beihai",
|
|
111215
|
-
"Portia",
|
|
111216
|
-
"Avrana Kern",
|
|
111217
|
-
"Rocky",
|
|
111218
|
-
"Ryland Grace",
|
|
111219
|
-
"TARS",
|
|
111220
|
-
"CASE",
|
|
111221
|
-
"GERTY",
|
|
111222
|
-
"WALL-E",
|
|
111223
|
-
"AUTO",
|
|
111224
|
-
"Robby the Robot",
|
|
111225
|
-
"Gort",
|
|
111226
|
-
"Johnny 5"
|
|
111227
|
-
];
|
|
111228
|
-
nextName = createSubagentNameAllocator();
|
|
111229
|
-
});
|
|
111230
|
-
|
|
111231
111353
|
// src/agent/create.ts
|
|
111232
111354
|
var exports_create = {};
|
|
111233
111355
|
__export(exports_create, {
|
|
@@ -163854,52 +163976,6 @@ var init_adapter3 = __esm(() => {
|
|
|
163854
163976
|
init_web_api_client();
|
|
163855
163977
|
});
|
|
163856
163978
|
|
|
163857
|
-
// src/agent/subagents/ephemeral-subagent.ts
|
|
163858
|
-
function shouldRunSubagentEphemerally(params) {
|
|
163859
|
-
const optOut = (params.env ?? process.env)[EPHEMERAL_SUBAGENTS_ENV]?.trim().toLowerCase();
|
|
163860
|
-
return params.backendMode === "api" && !params.existingAgentId && !params.existingConversationId && !params.environment && optOut !== "0" && optOut !== "false";
|
|
163861
|
-
}
|
|
163862
|
-
function resolveEphemeralSubagentLink(env6 = process.env) {
|
|
163863
|
-
if (env6.LETTA_CODE_AGENT_ROLE !== "subagent")
|
|
163864
|
-
return null;
|
|
163865
|
-
const parentAgentId = env6.LETTA_PARENT_AGENT_ID?.trim();
|
|
163866
|
-
if (!parentAgentId)
|
|
163867
|
-
return null;
|
|
163868
|
-
return {
|
|
163869
|
-
parent_agent_id: parentAgentId,
|
|
163870
|
-
is_subagent: true,
|
|
163871
|
-
name: resolveCreatedAgentName(undefined, true, env6[SUBAGENT_NAME_ENV]?.trim() || undefined)
|
|
163872
|
-
};
|
|
163873
|
-
}
|
|
163874
|
-
function resolveDetachedSubagentEnvAgentId(sessionId, env6 = process.env) {
|
|
163875
|
-
if (!sessionId.startsWith("conv-"))
|
|
163876
|
-
return;
|
|
163877
|
-
if (env6.LETTA_CODE_AGENT_ROLE !== "subagent")
|
|
163878
|
-
return;
|
|
163879
|
-
return env6.LETTA_PARENT_AGENT_ID?.trim() || undefined;
|
|
163880
|
-
}
|
|
163881
|
-
function resolveEffectiveAgentId(agentId, env6 = process.env) {
|
|
163882
|
-
if (!agentId)
|
|
163883
|
-
return agentId;
|
|
163884
|
-
return resolveDetachedSubagentEnvAgentId(agentId, env6) ?? agentId;
|
|
163885
|
-
}
|
|
163886
|
-
function getEffectiveAgentId(env6 = process.env) {
|
|
163887
|
-
return resolveEffectiveAgentId(getCurrentAgentId(), env6);
|
|
163888
|
-
}
|
|
163889
|
-
async function lookupDetachedConversationParent(conversationId, backend3) {
|
|
163890
|
-
const conversation = await backend3.retrieveConversation(conversationId);
|
|
163891
|
-
if (Reflect.get(conversation, "agent_id") !== null || Reflect.get(conversation, "is_subagent") !== true) {
|
|
163892
|
-
return;
|
|
163893
|
-
}
|
|
163894
|
-
const parentId = Reflect.get(conversation, "parent_agent_id");
|
|
163895
|
-
return typeof parentId === "string" && parentId ? parentId : undefined;
|
|
163896
|
-
}
|
|
163897
|
-
var EPHEMERAL_SUBAGENTS_ENV = "LETTA_CODE_EPHEMERAL_SUBAGENTS";
|
|
163898
|
-
var init_ephemeral_subagent = __esm(() => {
|
|
163899
|
-
init_context();
|
|
163900
|
-
init_names();
|
|
163901
|
-
});
|
|
163902
|
-
|
|
163903
163979
|
// src/utils/subagent-depth-env.ts
|
|
163904
163980
|
function readSubagentDepth(env6) {
|
|
163905
163981
|
const raw2 = env6[SUBAGENT_DEPTH_ENV]?.trim();
|
|
@@ -203262,7 +203338,7 @@ var init_mcp_client = __esm(() => {
|
|
|
203262
203338
|
init_streamableHttp();
|
|
203263
203339
|
DEFAULT_CLIENT_INFO = {
|
|
203264
203340
|
name: "letta-code",
|
|
203265
|
-
version: "0.34.
|
|
203341
|
+
version: "0.34.61"
|
|
203266
203342
|
};
|
|
203267
203343
|
});
|
|
203268
203344
|
|
|
@@ -223542,7 +223618,7 @@ async function getAttachedRepositories(agentId) {
|
|
|
223542
223618
|
if (cached3 && cached3.expiresAt > Date.now()) {
|
|
223543
223619
|
return (await cached3.promise).map((repository) => ({ ...repository }));
|
|
223544
223620
|
}
|
|
223545
|
-
const promise2 = Promise.resolve().then(() => (init_attached_repositories(), exports_attached_repositories)).then(async ({ listAttachedAgentRepositories: listAttachedAgentRepositories2 }) => (await listAttachedAgentRepositories2(agentId)).sort((a2, b3) => a2.name.localeCompare(b3.name) || a2.id.localeCompare(b3.id)));
|
|
223621
|
+
const promise2 = Promise.resolve().then(() => (init_attached_repositories(), exports_attached_repositories)).then(async ({ listAttachedAgentRepositories: listAttachedAgentRepositories2 }) => (await listAttachedAgentRepositories2(resolveEffectiveAgentId(agentId))).sort((a2, b3) => a2.name.localeCompare(b3.name) || a2.id.localeCompare(b3.id)));
|
|
223546
223622
|
const entry = {
|
|
223547
223623
|
expiresAt: Date.now() + ATTACHED_REPOSITORIES_CACHE_TTL_MS,
|
|
223548
223624
|
promise: promise2
|
|
@@ -223652,6 +223728,7 @@ var ATTACHED_REPOSITORIES_CACHE_KEY, ATTACHED_REPOSITORIES_CACHE_TTL_MS = 5000,
|
|
|
223652
223728
|
var init_shared_memory_skills = __esm(() => {
|
|
223653
223729
|
init_checkout_readiness();
|
|
223654
223730
|
init_skills5();
|
|
223731
|
+
init_ephemeral_subagent();
|
|
223655
223732
|
ATTACHED_REPOSITORIES_CACHE_KEY = Symbol.for("@letta/attachedRepositoriesCache");
|
|
223656
223733
|
LAST_GOOD_ATTACHED_REPOSITORIES_KEY = Symbol.for("@letta/lastGoodAttachedRepositories");
|
|
223657
223734
|
});
|
|
@@ -233388,7 +233465,8 @@ __export(exports_environments3, {
|
|
|
233388
233465
|
getEnvironmentConnection: () => getEnvironmentConnection,
|
|
233389
233466
|
environmentMatchesSelector: () => environmentMatchesSelector,
|
|
233390
233467
|
describeEnvironment: () => describeEnvironment,
|
|
233391
|
-
createAgentSandbox: () => createAgentSandbox
|
|
233468
|
+
createAgentSandbox: () => createAgentSandbox,
|
|
233469
|
+
ComputerResolutionError: () => ComputerResolutionError
|
|
233392
233470
|
});
|
|
233393
233471
|
import { randomUUID as randomUUID36 } from "node:crypto";
|
|
233394
233472
|
async function listEnvironments(options = {}) {
|
|
@@ -233438,24 +233516,24 @@ function environmentMatchesSelector(environment, selector) {
|
|
|
233438
233516
|
async function resolveEnvironmentConnectionId(selector, list = listEnvironments) {
|
|
233439
233517
|
const trimmed = selector.trim();
|
|
233440
233518
|
if (!trimmed) {
|
|
233441
|
-
throw new
|
|
233519
|
+
throw new ComputerResolutionError("computer_selector_empty", "Computer selector must not be empty");
|
|
233442
233520
|
}
|
|
233443
233521
|
const response = await list({ limit: 100 });
|
|
233444
233522
|
const matches3 = response.connections.filter((environment2) => environmentMatchesSelector(environment2, trimmed));
|
|
233445
233523
|
if (matches3.length === 0) {
|
|
233446
|
-
throw new
|
|
233524
|
+
throw new ComputerResolutionError("computer_not_found", `Computer "${trimmed}" not found. Run \`letta computers list\` to discover available computers.`);
|
|
233447
233525
|
}
|
|
233448
233526
|
const onlineMatches = matches3.filter(isEnvironmentOnline);
|
|
233449
233527
|
if (onlineMatches.length === 0) {
|
|
233450
|
-
throw new
|
|
233528
|
+
throw new ComputerResolutionError("computer_offline", `Computer "${trimmed}" is offline. Matched: ${matches3.map(describeEnvironment).join(", ")}`);
|
|
233451
233529
|
}
|
|
233452
233530
|
if (new Set(onlineMatches.map((environment2) => environment2.deviceId)).size > 1) {
|
|
233453
|
-
throw new
|
|
233531
|
+
throw new ComputerResolutionError("computer_ambiguous", `Computer "${trimmed}" is ambiguous. Matched: ${onlineMatches.map(describeEnvironment).join(", ")}`);
|
|
233454
233532
|
}
|
|
233455
233533
|
onlineMatches.sort((a2, b3) => Math.max(b3.lastHeartbeat ?? 0, b3.lastSeenAt) - Math.max(a2.lastHeartbeat ?? 0, a2.lastSeenAt));
|
|
233456
233534
|
const environment = onlineMatches[0];
|
|
233457
233535
|
if (!environment) {
|
|
233458
|
-
throw new
|
|
233536
|
+
throw new ComputerResolutionError("computer_offline", `Computer "${trimmed}" is offline`);
|
|
233459
233537
|
}
|
|
233460
233538
|
if (!environment.connectionId) {
|
|
233461
233539
|
throw new Error(`Computer "${trimmed}" has no active connection id`);
|
|
@@ -233498,8 +233576,17 @@ async function teleportToEnvironment(agentId, conversationId, targetConnectionId
|
|
|
233498
233576
|
idempotencyKey: randomUUID36()
|
|
233499
233577
|
});
|
|
233500
233578
|
}
|
|
233579
|
+
var ComputerResolutionError;
|
|
233501
233580
|
var init_environments3 = __esm(() => {
|
|
233502
233581
|
init_request();
|
|
233582
|
+
ComputerResolutionError = class ComputerResolutionError extends Error {
|
|
233583
|
+
code;
|
|
233584
|
+
constructor(code, message) {
|
|
233585
|
+
super(message);
|
|
233586
|
+
this.code = code;
|
|
233587
|
+
this.name = "ComputerResolutionError";
|
|
233588
|
+
}
|
|
233589
|
+
};
|
|
233503
233590
|
});
|
|
233504
233591
|
|
|
233505
233592
|
// src/cron/runner.ts
|
|
@@ -236713,7 +236800,7 @@ function waitForSocketOpen(socket, timeoutMs) {
|
|
|
236713
236800
|
}
|
|
236714
236801
|
detachError = onceSocketEvent(socket, "error", (event) => {
|
|
236715
236802
|
cleanup();
|
|
236716
|
-
reject2(new Error(`App-server WebSocket failed to open: ${
|
|
236803
|
+
reject2(new Error(`App-server WebSocket failed to open: ${socketErrorDetail(event)}`));
|
|
236717
236804
|
});
|
|
236718
236805
|
detachClose = onceSocketEvent(socket, "close", () => {
|
|
236719
236806
|
if (upgradeRejected)
|
|
@@ -236723,6 +236810,19 @@ function waitForSocketOpen(socket, timeoutMs) {
|
|
|
236723
236810
|
});
|
|
236724
236811
|
});
|
|
236725
236812
|
}
|
|
236813
|
+
function socketErrorDetail(event) {
|
|
236814
|
+
if (event instanceof Error)
|
|
236815
|
+
return event.message;
|
|
236816
|
+
if (event && typeof event === "object") {
|
|
236817
|
+
const error4 = Reflect.get(event, "error");
|
|
236818
|
+
if (error4 instanceof Error)
|
|
236819
|
+
return error4.message;
|
|
236820
|
+
const message = Reflect.get(event, "message");
|
|
236821
|
+
if (typeof message === "string" && message)
|
|
236822
|
+
return message;
|
|
236823
|
+
}
|
|
236824
|
+
return String(event);
|
|
236825
|
+
}
|
|
236726
236826
|
function rawEventData(event) {
|
|
236727
236827
|
if (event && typeof event === "object" && "data" in event) {
|
|
236728
236828
|
return event.data;
|
|
@@ -236778,6 +236878,7 @@ class AppServerClient {
|
|
|
236778
236878
|
this.requestTimeoutMs = options.requestTimeoutMs ?? DEFAULT_REQUEST_TIMEOUT_MS;
|
|
236779
236879
|
const socketOptions = appServerSocketOptions(options.authToken);
|
|
236780
236880
|
this.socket = new WebSocket5(resolveAppServerUrl(options.url), socketOptions);
|
|
236881
|
+
this.socket.on?.("error", () => {});
|
|
236781
236882
|
this.control = this.socket;
|
|
236782
236883
|
this.stream = this.socket;
|
|
236783
236884
|
attachSocketListener(this.socket, "message", (event) => {
|
|
@@ -236788,8 +236889,13 @@ class AppServerClient {
|
|
|
236788
236889
|
});
|
|
236789
236890
|
}
|
|
236790
236891
|
async connect() {
|
|
236791
|
-
|
|
236792
|
-
|
|
236892
|
+
try {
|
|
236893
|
+
await waitForSocketOpen(this.socket, this.requestTimeoutMs);
|
|
236894
|
+
return this;
|
|
236895
|
+
} catch (error4) {
|
|
236896
|
+
this.close();
|
|
236897
|
+
throw error4;
|
|
236898
|
+
}
|
|
236793
236899
|
}
|
|
236794
236900
|
close() {
|
|
236795
236901
|
if (this.explicitlyClosed)
|
|
@@ -240125,7 +240231,7 @@ class CodexAppServerClient {
|
|
|
240125
240231
|
await this.request("initialize", {
|
|
240126
240232
|
clientInfo: {
|
|
240127
240233
|
name: "letta-code",
|
|
240128
|
-
version: "0.34.
|
|
240234
|
+
version: "0.34.61"
|
|
240129
240235
|
},
|
|
240130
240236
|
capabilities: null
|
|
240131
240237
|
});
|
|
@@ -245525,6 +245631,27 @@ async function resolveQualifiedComputer(deviceId, scope) {
|
|
|
245525
245631
|
function errorMessage5(error4) {
|
|
245526
245632
|
return error4 instanceof Error ? error4.message : String(error4);
|
|
245527
245633
|
}
|
|
245634
|
+
function classifyRemoteExternalWorkerControlError(error4) {
|
|
245635
|
+
if (error4 instanceof ComputerResolutionError) {
|
|
245636
|
+
return error4.code === "computer_offline" || error4.code === "computer_not_found" ? error4.code : "other";
|
|
245637
|
+
}
|
|
245638
|
+
if (error4 instanceof OutdatedRemoteWorkerError)
|
|
245639
|
+
return "outdated_computer";
|
|
245640
|
+
const message2 = errorMessage5(error4);
|
|
245641
|
+
if (/^Computer ".*" is offline(?:\.|$)/.test(message2) || message2.startsWith("Timed out waiting for cloud sandbox "))
|
|
245642
|
+
return "computer_offline";
|
|
245643
|
+
if (/^Computer ".*" not found(?:\.|$)/.test(message2))
|
|
245644
|
+
return "computer_not_found";
|
|
245645
|
+
if (/^Subagent .* was not found on this computer$/.test(message2))
|
|
245646
|
+
return "subagent_not_found";
|
|
245647
|
+
if (message2 === "Subagent does not belong to this conversation")
|
|
245648
|
+
return "subagent_not_owned";
|
|
245649
|
+
if (/^.* is running an older Letta Code that can't steer Claude Code subagents remotely\./.test(message2))
|
|
245650
|
+
return "outdated_computer";
|
|
245651
|
+
if (message2.startsWith("App-server WebSocket failed to open:"))
|
|
245652
|
+
return "connect_failed";
|
|
245653
|
+
return "other";
|
|
245654
|
+
}
|
|
245528
245655
|
|
|
245529
245656
|
class RemoteSubagentFollower {
|
|
245530
245657
|
scope;
|
|
@@ -245702,7 +245829,7 @@ async function launchRemoteExternalCodingAgent(params, deps) {
|
|
|
245702
245829
|
reportExternalWorkerLaunchFailure({
|
|
245703
245830
|
stage,
|
|
245704
245831
|
harness: type,
|
|
245705
|
-
computer,
|
|
245832
|
+
computer: stage === "resolve_computer" ? undefined : computer,
|
|
245706
245833
|
error: error4,
|
|
245707
245834
|
errorCode,
|
|
245708
245835
|
agentId: parentScope.agentId,
|
|
@@ -245733,7 +245860,7 @@ async function launchRemoteExternalCodingAgent(params, deps) {
|
|
|
245733
245860
|
if (outdated)
|
|
245734
245861
|
return fail2("outdated_computer", outdated);
|
|
245735
245862
|
} catch (error4) {
|
|
245736
|
-
return fail2("resolve_computer", errorMessage5(error4));
|
|
245863
|
+
return fail2("resolve_computer", errorMessage5(error4), error4 instanceof ComputerResolutionError ? error4.code : undefined);
|
|
245737
245864
|
}
|
|
245738
245865
|
params.signal?.throwIfAborted();
|
|
245739
245866
|
const connect = () => (deps.connect ?? defaultConnect)(connectionId, parentScope);
|
|
@@ -245909,6 +246036,7 @@ async function sendRemoteExternalCodingAgentMessage(params, deps = {}) {
|
|
|
245909
246036
|
harness: target?.type ?? "unknown",
|
|
245910
246037
|
computer: target?.computer,
|
|
245911
246038
|
error: error4,
|
|
246039
|
+
errorCode: classifyRemoteExternalWorkerControlError(error4),
|
|
245912
246040
|
agentId: params.parentScope.agentId,
|
|
245913
246041
|
conversationId: params.parentScope.conversationId,
|
|
245914
246042
|
toolCallId: params.toolCallId
|
|
@@ -445178,7 +445306,7 @@ async function syncPendingAttachedRepositoryCommitsAfterTurn(agentId, dependenci
|
|
|
445178
445306
|
return { results: [] };
|
|
445179
445307
|
}
|
|
445180
445308
|
const listRepositories = dependencies.listRepositories ?? listAttachedAgentRepositories;
|
|
445181
|
-
const repositories = await listRepositories(agentId);
|
|
445309
|
+
const repositories = await listRepositories(resolveEffectiveAgentId(agentId));
|
|
445182
445310
|
if (repositories.length === 0) {
|
|
445183
445311
|
return { results: [] };
|
|
445184
445312
|
}
|
|
@@ -445211,6 +445339,7 @@ var init_attached_repository_git_sync = __esm(() => {
|
|
|
445211
445339
|
init_attached_repositories();
|
|
445212
445340
|
init_memory_auth();
|
|
445213
445341
|
init_memory_git();
|
|
445342
|
+
init_ephemeral_subagent();
|
|
445214
445343
|
repositorySyncs = new Map;
|
|
445215
445344
|
});
|
|
445216
445345
|
|
|
@@ -463634,16 +463763,33 @@ function installProcessEventRouting(params) {
|
|
|
463634
463763
|
}
|
|
463635
463764
|
emitSubagentStateUpdate(transport3, runtime, scope, TO_SUBSCRIBERS, options);
|
|
463636
463765
|
};
|
|
463766
|
+
let previousOwnerScopes = new Map;
|
|
463637
463767
|
runtime._unsubscribeSubagentState = subscribe2(() => {
|
|
463638
|
-
|
|
463639
|
-
|
|
463640
|
-
|
|
463768
|
+
const ownerScopes = new Map;
|
|
463769
|
+
for (const subagent of getSubagents()) {
|
|
463770
|
+
if (!subagent.parentAgentId)
|
|
463771
|
+
continue;
|
|
463772
|
+
const scope = {
|
|
463773
|
+
agent_id: subagent.parentAgentId,
|
|
463774
|
+
conversation_id: subagent.parentConversationId ?? "default"
|
|
463775
|
+
};
|
|
463776
|
+
ownerScopes.set(JSON.stringify(scope), scope);
|
|
463641
463777
|
}
|
|
463778
|
+
const scopes = new Map([...previousOwnerScopes, ...ownerScopes]);
|
|
463779
|
+
previousOwnerScopes = ownerScopes;
|
|
463642
463780
|
for (const conversationRuntime of runtime.conversationRuntimes.values()) {
|
|
463643
|
-
|
|
463781
|
+
const scope = {
|
|
463644
463782
|
agent_id: conversationRuntime.agentId,
|
|
463645
463783
|
conversation_id: conversationRuntime.conversationId
|
|
463646
|
-
}
|
|
463784
|
+
};
|
|
463785
|
+
scopes.set(JSON.stringify(scope), scope);
|
|
463786
|
+
}
|
|
463787
|
+
if (scopes.size === 0) {
|
|
463788
|
+
emitSubagentState();
|
|
463789
|
+
return;
|
|
463790
|
+
}
|
|
463791
|
+
for (const scope of scopes.values()) {
|
|
463792
|
+
emitSubagentState(scope, { onlyIfChanged: true });
|
|
463647
463793
|
}
|
|
463648
463794
|
});
|
|
463649
463795
|
runtime._unsubscribeSubagentStreamEvents?.();
|
|
@@ -536738,4 +536884,4 @@ function registerBunOAuthFlows() {
|
|
|
536738
536884
|
registerBunOAuthFlows();
|
|
536739
536885
|
await init_src5().then(() => exports_src2);
|
|
536740
536886
|
|
|
536741
|
-
//# debugId=
|
|
536887
|
+
//# debugId=A36F7BFC09468D8164756E2164756E21
|