@elizaos/ui 2.0.0-alpha.344 → 2.0.0-alpha.346

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/package.json +1 -1
  2. package/packages/typescript/src/features/basic-capabilities/providers/actionState.d.ts.map +1 -1
  3. package/packages/typescript/src/features/basic-capabilities/providers/actionState.js +8 -51
  4. package/packages/typescript/src/features/basic-capabilities/providers/actions.d.ts.map +1 -1
  5. package/packages/typescript/src/features/basic-capabilities/providers/actions.js +2 -2
  6. package/packages/typescript/src/features/basic-capabilities/providers/non-actionable-chatter.d.ts.map +1 -1
  7. package/packages/typescript/src/features/basic-capabilities/providers/non-actionable-chatter.js +2 -4
  8. package/packages/typescript/src/features/basic-capabilities/providers/providers.d.ts.map +1 -1
  9. package/packages/typescript/src/features/basic-capabilities/providers/providers.js +2 -2
  10. package/packages/typescript/src/features/knowledge/utils.d.ts.map +1 -1
  11. package/packages/typescript/src/features/knowledge/utils.js +4 -3
  12. package/packages/typescript/src/runtime.d.ts +2 -0
  13. package/packages/typescript/src/runtime.d.ts.map +1 -1
  14. package/packages/typescript/src/runtime.js +80 -0
  15. package/packages/typescript/src/services/message.d.ts +3 -1
  16. package/packages/typescript/src/services/message.d.ts.map +1 -1
  17. package/packages/typescript/src/services/message.js +91 -135
  18. package/packages/typescript/src/utils/action-results.d.ts +33 -0
  19. package/packages/typescript/src/utils/action-results.d.ts.map +1 -0
  20. package/packages/typescript/src/utils/action-results.js +169 -0
  21. package/packages/typescript/src/utils/context-catalog.d.ts.map +1 -1
  22. package/packages/typescript/src/utils/context-catalog.js +11 -0
  23. package/packages/typescript/src/utils/context-routing.d.ts +3 -0
  24. package/packages/typescript/src/utils/context-routing.d.ts.map +1 -1
  25. package/packages/typescript/src/utils/context-routing.js +88 -0
  26. package/packages/typescript/src/utils/message-text.d.ts +5 -0
  27. package/packages/typescript/src/utils/message-text.d.ts.map +1 -0
  28. package/packages/typescript/src/utils/message-text.js +24 -0
  29. package/packages/typescript/src/utils.d.ts +2 -1
  30. package/packages/typescript/src/utils.d.ts.map +1 -1
  31. package/packages/typescript/src/utils.js +2 -1
  32. package/packages/ui/src/components/composites/chat/chat-composer.d.ts.map +1 -1
  33. package/packages/ui/src/components/composites/chat/chat-composer.js +101 -19
  34. package/packages/ui/src/layouts/page-layout/page-layout-mobile-drawer.d.ts.map +1 -1
  35. package/packages/ui/src/layouts/page-layout/page-layout-mobile-drawer.js +23 -4
  36. package/packages/ui/src/layouts/workspace-layout/index.d.ts +1 -0
  37. package/packages/ui/src/layouts/workspace-layout/index.d.ts.map +1 -1
  38. package/packages/ui/src/layouts/workspace-layout/index.js +1 -0
  39. package/packages/ui/src/layouts/workspace-layout/workspace-layout.d.ts.map +1 -1
  40. package/packages/ui/src/layouts/workspace-layout/workspace-layout.js +8 -2
  41. package/packages/ui/src/layouts/workspace-layout/workspace-mobile-sidebar-controls.d.ts +13 -0
  42. package/packages/ui/src/layouts/workspace-layout/workspace-mobile-sidebar-controls.d.ts.map +1 -0
  43. package/packages/ui/src/layouts/workspace-layout/workspace-mobile-sidebar-controls.js +5 -0
@@ -13,7 +13,9 @@ import { ModelType } from "../types/model";
13
13
  import { incomingPipelineHookContext, modelStreamChunkPipelineHookContext, outgoingPipelineHookContext, parallelWithShouldRespondPipelineHookContext, preShouldRespondPipelineHookContext, } from "../types/pipeline-hooks";
14
14
  import { asUUID, ChannelType, ContentType } from "../types/primitives";
15
15
  import { composePromptFromState, getLocalServerUrl, parseBooleanFromText, parseJSONObjectFromText, parseKeyValueXml, truncateToCompleteSentence, } from "../utils";
16
+ import { collectActionResultSizeWarnings, formatActionResultsForPrompt, trimActionResultForPromptState, } from "../utils/action-results";
16
17
  import { AVAILABLE_CONTEXTS_STATE_KEY, attachAvailableContexts, CONTEXT_ROUTING_STATE_KEY, getActiveRoutingContexts, mergeContextRouting, parseContextRoutingMetadata, setContextRoutingMetadata, } from "../utils/context-routing";
18
+ import { getUserMessageText } from "../utils/message-text";
17
19
  import { createStreamingContext, MarkableExtractor, ResponseStreamExtractor, } from "../utils/streaming";
18
20
  import { extractFirstSentence, hasFirstSentence, } from "../utils/text-splitting";
19
21
  import { OPTIMIZED_PROMPT_SERVICE, } from "./optimized-prompt";
@@ -718,18 +720,32 @@ function unwrapPlannerIdentifier(value) {
718
720
  return nameMatch[1].trim();
719
721
  }
720
722
  const actionMatch = trimmed.match(/^<action\b[^>]*>([\s\S]*?)<\/action>$/i);
721
- if (!actionMatch) {
722
- return trimmed;
723
- }
724
- const inner = actionMatch[1].trim();
725
- if (!inner) {
726
- return "";
727
- }
728
- const nestedNameMatch = inner.match(/<name\b[^>]*>([\s\S]*?)<\/name>/i);
729
- if (nestedNameMatch) {
730
- return nestedNameMatch[1].trim();
723
+ if (actionMatch) {
724
+ const inner = actionMatch[1].trim();
725
+ if (!inner) {
726
+ return "";
727
+ }
728
+ const nestedNameMatch = inner.match(/<name\b[^>]*>([\s\S]*?)<\/name>/i);
729
+ if (nestedNameMatch) {
730
+ return nestedNameMatch[1].trim();
731
+ }
732
+ return /<[A-Za-z][^>]*>/.test(inner) ? trimmed : inner;
733
+ }
734
+ // Tolerate malformed planner output where the closing </action> is missing
735
+ // or extra content trails the action body. Symptom in prod logs:
736
+ // "Dropping unknown planner action (actionName=<action><name>REPLY</name>)"
737
+ // The planner LLM occasionally emits an unclosed <action> wrapper around a
738
+ // well-formed <name>X</name>. Falling through to "return trimmed" treats
739
+ // the whole XML chunk as the action identifier, which then fails to match
740
+ // any registered action and the bot goes silent. If the input begins with
741
+ // <action> and contains a <name>X</name>, prefer that name.
742
+ if (/^<action\b[^>]*>/i.test(trimmed)) {
743
+ const looseNameMatch = trimmed.match(/<name\b[^>]*>([\s\S]*?)<\/name>/i);
744
+ if (looseNameMatch) {
745
+ return looseNameMatch[1].trim();
746
+ }
731
747
  }
732
- return /<[A-Za-z][^>]*>/.test(inner) ? trimmed : inner;
748
+ return trimmed;
733
749
  }
734
750
  const PLANNER_ACTION_ALIASES = new Map([
735
751
  ["BULK_RESCHEDULE", "OWNER_CALENDAR"],
@@ -1146,9 +1162,7 @@ function findDirectOwnedActionSuggestion(runtime, messageText) {
1146
1162
  return null;
1147
1163
  }
1148
1164
  export function suggestOwnedActionFromMetadata(runtime, message) {
1149
- const messageText = typeof message.content?.text === "string"
1150
- ? message.content.text.trim()
1151
- : "";
1165
+ const messageText = getUserMessageText(message);
1152
1166
  if (messageText.length === 0 ||
1153
1167
  !ACTION_OWNERSHIP_TRIGGER_PATTERNS.some((pattern) => pattern.test(messageText))) {
1154
1168
  return null;
@@ -1247,7 +1261,7 @@ function shouldAttemptActionRescue(runtime, message, state, responseContent) {
1247
1261
  return true;
1248
1262
  }
1249
1263
  function getMessageText(message) {
1250
- return typeof message.content?.text === "string" ? message.content.text : "";
1264
+ return getUserMessageText(message);
1251
1265
  }
1252
1266
  function looksLikeOwnershipSensitiveRequest(message) {
1253
1267
  const text = getMessageText(message).toLowerCase();
@@ -1565,19 +1579,24 @@ export function shouldEmitPlannerPreamble(runtime, responseContent) {
1565
1579
  normalizedFirstAction !== normalizeActionIdentifier("IGNORE") &&
1566
1580
  normalizedFirstAction !== normalizeActionIdentifier("STOP"));
1567
1581
  }
1582
+ // Actions that are passive bookkeeping / chitchat. Safe to drop when a
1583
+ // turn-owning action (one that sets suppressPostActionContinuation = true,
1584
+ // e.g. SPAWN_AGENT) is also picked for the same turn. Keeping them around
1585
+ // alongside explicit delegation produces duplicate user-visible noise:
1586
+ // "Created task X" message followed by the actual delegated result.
1587
+ const PASSIVE_TURN_ACTIONS = new Set(["REPLY", "MANAGE_TASKS"].map(normalizeActionIdentifier));
1568
1588
  export function stripReplyWhenActionOwnsTurn(runtime, actions) {
1569
1589
  if (!actions || actions.length <= 1) {
1570
1590
  return Array.isArray(actions) ? [...actions] : [];
1571
1591
  }
1572
- const normalizedReply = normalizeActionIdentifier("REPLY");
1573
- const hasReply = actions.some((action) => normalizeActionIdentifier(action) === normalizedReply);
1574
- if (!hasReply) {
1592
+ const hasPassive = actions.some((action) => PASSIVE_TURN_ACTIONS.has(normalizeActionIdentifier(action)));
1593
+ if (!hasPassive) {
1575
1594
  return [...actions];
1576
1595
  }
1577
1596
  const actionLookup = buildRuntimeActionLookup(runtime);
1578
1597
  const ownedActions = actions.filter((action) => {
1579
1598
  const normalized = normalizeActionIdentifier(action);
1580
- if (!normalized || normalized === normalizedReply) {
1599
+ if (!normalized || PASSIVE_TURN_ACTIONS.has(normalized)) {
1581
1600
  return false;
1582
1601
  }
1583
1602
  return (resolveRuntimeAction(actionLookup, action)
@@ -1586,13 +1605,13 @@ export function stripReplyWhenActionOwnsTurn(runtime, actions) {
1586
1605
  if (ownedActions.length === 0) {
1587
1606
  return [...actions];
1588
1607
  }
1589
- const filtered = actions.filter((action) => normalizeActionIdentifier(action) !== normalizedReply);
1608
+ const filtered = actions.filter((action) => !PASSIVE_TURN_ACTIONS.has(normalizeActionIdentifier(action)));
1590
1609
  runtime.logger.info({
1591
1610
  src: "service:message",
1592
1611
  originalActions: actions,
1593
1612
  filteredActions: filtered,
1594
- replySuppressedBy: ownedActions,
1595
- }, "Dropped REPLY because another selected action already owns the turn");
1613
+ suppressedBy: ownedActions,
1614
+ }, "Dropped passive actions because another selected action already owns the turn");
1596
1615
  return filtered.length > 0 ? filtered : ["REPLY"];
1597
1616
  }
1598
1617
  function callbackTextPreview(content) {
@@ -1768,34 +1787,7 @@ function shouldWaitForUserAfterIncompleteReflection(responseContent, actionResul
1768
1787
  return normalizeActionIdentifier(actionName) === "REPLY";
1769
1788
  });
1770
1789
  }
1771
- function formatActionResultsForPrompt(actionResults) {
1772
- if (actionResults.length === 0) {
1773
- return "No action results available.";
1774
- }
1775
- return [
1776
- "# Action Results",
1777
- ...actionResults.map((result, index) => {
1778
- const actionNameValue = result.data?.actionName;
1779
- const actionName = typeof actionNameValue === "string"
1780
- ? actionNameValue
1781
- : "Unknown Action";
1782
- const lines = [
1783
- `${index + 1}. ${actionName} - ${result.success === false ? "failed" : "succeeded"}`,
1784
- ];
1785
- if (typeof result.text === "string" && result.text.trim()) {
1786
- lines.push(`Output: ${result.text.trim().slice(0, 2000)}`);
1787
- }
1788
- if (result.error) {
1789
- const errorText = result.error instanceof Error
1790
- ? result.error.message
1791
- : String(result.error);
1792
- lines.push(`Error: ${errorText.slice(0, 1000)}`);
1793
- }
1794
- return lines.join("\n");
1795
- }),
1796
- ].join("\n\n");
1797
- }
1798
- function withActionResults(state, actionResults) {
1790
+ export function withActionResultsForPrompt(state, actionResults) {
1799
1791
  return {
1800
1792
  ...state,
1801
1793
  values: {
@@ -1808,6 +1800,23 @@ function withActionResults(state, actionResults) {
1808
1800
  },
1809
1801
  };
1810
1802
  }
1803
+ const withActionResults = withActionResultsForPrompt;
1804
+ function preparePromptActionResult(runtime, message, result) {
1805
+ for (const warning of collectActionResultSizeWarnings(result)) {
1806
+ runtime.logger.warn({
1807
+ src: "service:message",
1808
+ agentId: runtime.agentId,
1809
+ messageId: message.id,
1810
+ roomId: message.roomId,
1811
+ action: warning.actionName,
1812
+ field: warning.field,
1813
+ rawCharLength: warning.rawCharLength,
1814
+ estimatedTokens: warning.estimatedTokens,
1815
+ thresholdTokens: warning.thresholdTokens,
1816
+ }, "Action result exceeds prompt-size warning threshold");
1817
+ }
1818
+ return trimActionResultForPromptState(result);
1819
+ }
1811
1820
  function withTaskCompletion(state, taskCompletion) {
1812
1821
  if (!taskCompletion) {
1813
1822
  return state;
@@ -1827,52 +1836,6 @@ function withTaskCompletion(state, taskCompletion) {
1827
1836
  },
1828
1837
  };
1829
1838
  }
1830
- function getStructuredOutputFailure(state) {
1831
- const candidate = state.data?.structuredOutputFailure;
1832
- if (!candidate || typeof candidate !== "object") {
1833
- return null;
1834
- }
1835
- return candidate;
1836
- }
1837
- function summarizeStructuredOutputFailure(failure) {
1838
- if (!failure) {
1839
- return "Structured output parsing failed, but no additional diagnostics were recorded.";
1840
- }
1841
- const parts = [
1842
- `Kind: ${failure.kind}`,
1843
- `Model: ${failure.model}`,
1844
- `Format: ${failure.format}`,
1845
- `Attempts: ${failure.attempts}/${failure.maxRetries + 1}`,
1846
- ];
1847
- if (failure.key) {
1848
- parts.push(`Key: ${failure.key}`);
1849
- }
1850
- if (failure.parseError) {
1851
- parts.push(`Error: ${failure.parseError}`);
1852
- }
1853
- if (failure.issues && failure.issues.length > 0) {
1854
- parts.push(`Issues: ${failure.issues.join(" | ")}`);
1855
- }
1856
- if (failure.responsePreview) {
1857
- parts.push(`Response Preview:\n${failure.responsePreview}`);
1858
- }
1859
- return parts.join("\n");
1860
- }
1861
- function summarizeActionResultsForUser(actionResults) {
1862
- if (actionResults.length === 0) {
1863
- return "";
1864
- }
1865
- const summary = actionResults
1866
- .slice(-3)
1867
- .map((result) => {
1868
- const actionName = typeof result.data?.actionName === "string"
1869
- ? result.data.actionName
1870
- : "unknown action";
1871
- return `${actionName} (${result.success === false ? "failed" : "succeeded"})`;
1872
- })
1873
- .join(", ");
1874
- return `Completed action state before the error: ${summary}.`;
1875
- }
1876
1839
  function withContextRoutingValues(state, contextRoutingStateValues) {
1877
1840
  if (!contextRoutingStateValues) {
1878
1841
  return state;
@@ -2406,6 +2369,9 @@ export class DefaultMessageService {
2406
2369
  // Ensure latestResponseIds is cleaned up even if processMessage
2407
2370
  // threw before reaching its own cleanup at the end of the method.
2408
2371
  clearLatestResponseId(runtime.agentId, message.roomId, responseId);
2372
+ if (message.id) {
2373
+ runtime.stateCache.delete(`${message.id}_action_results`);
2374
+ }
2409
2375
  }
2410
2376
  });
2411
2377
  }
@@ -4345,7 +4311,6 @@ Output ONLY the continuation, starting immediately after the last character abov
4345
4311
  }
4346
4312
  }
4347
4313
  async buildStructuredFailureReply(runtime, message, state, responseId, stage) {
4348
- const failure = getStructuredOutputFailure(state);
4349
4314
  const recentMessages = typeof state.values?.recentMessages === "string" &&
4350
4315
  state.values.recentMessages.trim().length > 0
4351
4316
  ? state.values.recentMessages
@@ -4354,35 +4319,29 @@ Output ONLY the continuation, starting immediately after the last character abov
4354
4319
  : typeof message.content.text === "string"
4355
4320
  ? message.content.text
4356
4321
  : "(unavailable)";
4357
- const actionResults = Array.isArray(state.data?.actionResults)
4358
- ? state.data.actionResults
4359
- : [];
4360
4322
  const failurePrompt = [
4361
- "You are recovering from an internal structured-output failure while responding to a user.",
4362
- "Write the next user-facing reply in plain language.",
4363
- "",
4364
- "Rules:",
4365
- "- Explain what failed and why using only the diagnostics below.",
4366
- "- Mention any completed or failed actions if action results are available.",
4367
- "- Be transparent, concise, and avoid inventing causes.",
4368
- "- If the model returned malformed XML, TOON, or JSON, say that clearly.",
4369
- "- Suggest the most useful next step for the user.",
4370
- "- Return only the reply text. No XML, JSON, TOON, bullet labels, or <think>.",
4323
+ "You hit a transient model error and have to send a short user-facing reply.",
4324
+ "Write a one or two sentence reply in plain language.",
4371
4325
  "",
4372
- `Failure Stage: ${stage}`,
4373
- "",
4374
- "Structured Failure Diagnostics:",
4375
- summarizeStructuredOutputFailure(failure),
4326
+ "Hard rules:",
4327
+ "- Stay in character. Keep your usual voice and tone.",
4328
+ "- NEVER mention internal mechanism words such as: planner, action_planner,",
4329
+ " XML, TOON, JSON, schema, structured output, model, retries, sonnet,",
4330
+ " opus, claude, anthropic, prompt, parse, parser, xml plan, decision",
4331
+ " loop, runtime, dispatch, or hand off. The user does not know or care",
4332
+ " what those are.",
4333
+ "- Do not use em-dashes or en-dashes. Use a plain hyphen, period, or comma.",
4334
+ "- Just acknowledge that something went wrong and suggest a retry.",
4335
+ ' Examples: "something flaked, try again in a sec",',
4336
+ ' "weird hiccup, give me another shot in a moment",',
4337
+ ' "got stuck on my end, retry that?"',
4338
+ "- If the user already gave a clear command and you can plausibly act,",
4339
+ " acknowledge it and offer to take the action directly. Keep it short.",
4340
+ "- Return only the reply text. No labels, no XML, no JSON, no <think>.",
4376
4341
  "",
4377
4342
  "Recent Conversation:",
4378
4343
  recentMessages,
4379
4344
  "",
4380
- "Action Results So Far:",
4381
- typeof state.values?.actionResults === "string" &&
4382
- state.values.actionResults.trim().length > 0
4383
- ? state.values.actionResults
4384
- : "No action results available.",
4385
- "",
4386
4345
  "Reply:",
4387
4346
  ].join("\n");
4388
4347
  let replyText = "";
@@ -4426,21 +4385,17 @@ Output ONLY the continuation, starting immediately after the last character abov
4426
4385
  }
4427
4386
  }
4428
4387
  if (!replyText) {
4429
- const failureReason = failure?.parseError ??
4430
- failure?.issues?.[0] ??
4431
- "the model returned output that did not match the required format";
4432
- replyText = [
4433
- `I hit an internal parsing error while ${stage}.`,
4434
- `Reason: ${failureReason}.`,
4435
- summarizeActionResultsForUser(actionResults),
4436
- "Please try again or ask me to retry the last step.",
4437
- ]
4438
- .filter(Boolean)
4439
- .join(" ");
4388
+ // Last-ditch fallback when every model call above also failed.
4389
+ // Voice-neutral so any character can ship this default; characters
4390
+ // can override with their own phrasing via
4391
+ // character.templates.transientFailureReply.
4392
+ replyText =
4393
+ runtime.character.templates?.transientFailureReply ||
4394
+ "Something went wrong on my end. Please try again.";
4440
4395
  }
4441
4396
  replyText = truncateToCompleteSentence(replyText.trim(), 2000);
4442
4397
  const responseContent = {
4443
- thought: `Explain the structured-output failure during ${stage}.`,
4398
+ thought: `Handle a temporary reply failure during ${stage}.`,
4444
4399
  actions: ["REPLY"],
4445
4400
  providers: [],
4446
4401
  text: replyText,
@@ -4483,7 +4438,7 @@ Output ONLY the continuation, starting immediately after the last character abov
4483
4438
  maxIterations: opts.maxMultiStepIterations,
4484
4439
  }, "Starting multi-step iteration");
4485
4440
  accumulatedState = withContextRoutingValues((await runtime.composeState(message, ["RECENT_MESSAGES", "ACTION_STATE", "PROVIDERS"], false, false)), contextRoutingStateValues);
4486
- accumulatedState.data.actionResults = traceActionResult;
4441
+ accumulatedState = withActionResults(accumulatedState, traceActionResult);
4487
4442
  // Use dynamicPromptExecFromState for structured decision output
4488
4443
  const optimizedPlannerService = runtime.getService(OPTIMIZED_PROMPT_SERVICE);
4489
4444
  const baselinePlannerTemplate = runtime.character.templates?.multiStepDecisionTemplate ||
@@ -4680,12 +4635,12 @@ Output ONLY the continuation, starting immediately after the last character abov
4680
4635
  for (const result of providerResults) {
4681
4636
  if (result.status === "fulfilled") {
4682
4637
  const { providerName, success, text, error } = result.value;
4683
- traceActionResult.push({
4638
+ traceActionResult.push(preparePromptActionResult(runtime, message, {
4684
4639
  data: { actionName: providerName },
4685
4640
  success,
4686
4641
  text,
4687
4642
  error,
4688
- });
4643
+ }));
4689
4644
  if (callback) {
4690
4645
  await callback({
4691
4646
  text: `🔎 Provider executed: ${providerName}`,
@@ -4755,6 +4710,7 @@ Output ONLY the continuation, starting immediately after the last character abov
4755
4710
  runtime.logger.warn({ src: "service:message", maxIterations: opts.maxMultiStepIterations }, "Reached maximum iterations, forcing completion");
4756
4711
  }
4757
4712
  accumulatedState = withContextRoutingValues((await runtime.composeState(message, ["RECENT_MESSAGES", "ACTION_STATE"], false, false)), contextRoutingStateValues);
4713
+ accumulatedState = withActionResults(accumulatedState, traceActionResult);
4758
4714
  // Use dynamicPromptExecFromState for final summary generation
4759
4715
  // Stream the final summary for better UX
4760
4716
  const summary = await runtime.dynamicPromptExecFromState({
@@ -0,0 +1,33 @@
1
+ import type { ActionResult } from "../types/components";
2
+ export declare const MAX_PROMPTED_ACTION_RESULTS = 8;
3
+ export declare const MAX_ACTION_RESULT_TEXT_CHARS = 4000;
4
+ export declare const MAX_ACTION_RESULT_ERROR_CHARS = 2000;
5
+ export declare const ACTION_RESULT_OVERSIZE_WARNING_TOKENS = 10000;
6
+ export declare const ACTION_RESULT_TOKEN_ESTIMATE_CHARS = 4;
7
+ export declare const ACTION_RESULT_FULL_OUTPUT_REFERENCE_KEYS: Set<string>;
8
+ export declare const ACTION_RESULT_FULL_ERROR_REFERENCE_KEYS: Set<string>;
9
+ export type ActionResultTextField = "text" | "error";
10
+ export interface ActionResultSizeWarning {
11
+ actionName: string;
12
+ field: ActionResultTextField;
13
+ rawCharLength: number;
14
+ estimatedTokens: number;
15
+ thresholdTokens: number;
16
+ }
17
+ export interface ActionResultReferences {
18
+ text?: string;
19
+ error?: string;
20
+ }
21
+ export declare function estimateActionResultTokens(text: string): number;
22
+ export declare function getActionResultActionName(result: ActionResult): string;
23
+ export declare function stringifyActionResultError(error: ActionResult["error"]): string | undefined;
24
+ export declare function getActionResultReference(result: ActionResult, field: ActionResultTextField): string | undefined;
25
+ export declare function truncateMiddle(text: string, maxChars: number, reference?: string): string;
26
+ export declare function collectActionResultSizeWarnings(result: ActionResult, thresholdTokens?: number): ActionResultSizeWarning[];
27
+ export declare function trimActionResultForPromptState<T extends ActionResult>(result: T, references?: ActionResultReferences): T;
28
+ export declare function formatActionResultsForPrompt(actionResults: ActionResult[], options?: {
29
+ header?: string;
30
+ maxResults?: number;
31
+ preserveAbsoluteIndex?: boolean;
32
+ }): string;
33
+ //# sourceMappingURL=action-results.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"action-results.d.ts","sourceRoot":"","sources":["../../../../../../typescript/src/utils/action-results.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAsB,MAAM,qBAAqB,CAAC;AAE5E,eAAO,MAAM,2BAA2B,IAAI,CAAC;AAC7C,eAAO,MAAM,4BAA4B,OAAO,CAAC;AACjD,eAAO,MAAM,6BAA6B,OAAO,CAAC;AAClD,eAAO,MAAM,qCAAqC,QAAQ,CAAC;AAC3D,eAAO,MAAM,kCAAkC,IAAI,CAAC;AAEpD,eAAO,MAAM,wCAAwC,aAYnD,CAAC;AAEH,eAAO,MAAM,uCAAuC,aASlD,CAAC;AAEH,MAAM,MAAM,qBAAqB,GAAG,MAAM,GAAG,OAAO,CAAC;AAErD,MAAM,WAAW,uBAAuB;IACvC,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,qBAAqB,CAAC;IAC7B,aAAa,EAAE,MAAM,CAAC;IACtB,eAAe,EAAE,MAAM,CAAC;IACxB,eAAe,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,WAAW,sBAAsB;IACtC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;CACf;AAED,wBAAgB,0BAA0B,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAE/D;AAED,wBAAgB,yBAAyB,CAAC,MAAM,EAAE,YAAY,GAAG,MAAM,CAKtE;AAED,wBAAgB,0BAA0B,CACzC,KAAK,EAAE,YAAY,CAAC,OAAO,CAAC,GAC1B,MAAM,GAAG,SAAS,CAKpB;AAkBD,wBAAgB,wBAAwB,CACvC,MAAM,EAAE,YAAY,EACpB,KAAK,EAAE,qBAAqB,GAC1B,MAAM,GAAG,SAAS,CAOpB;AAED,wBAAgB,cAAc,CAC7B,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,MAAM,EAChB,SAAS,CAAC,EAAE,MAAM,GAChB,MAAM,CAoBR;AAED,wBAAgB,+BAA+B,CAC9C,MAAM,EAAE,YAAY,EACpB,eAAe,SAAwC,GACrD,uBAAuB,EAAE,CAwB3B;AAED,wBAAgB,8BAA8B,CAAC,CAAC,SAAS,YAAY,EACpE,MAAM,EAAE,CAAC,EACT,UAAU,GAAE,sBAA2B,GACrC,CAAC,CAiCH;AAED,wBAAgB,4BAA4B,CAC3C,aAAa,EAAE,YAAY,EAAE,EAC7B,OAAO,GAAE;IACR,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,qBAAqB,CAAC,EAAE,OAAO,CAAC;CAC3B,GACJ,MAAM,CA4DR"}
@@ -0,0 +1,169 @@
1
+ export const MAX_PROMPTED_ACTION_RESULTS = 8;
2
+ export const MAX_ACTION_RESULT_TEXT_CHARS = 4000;
3
+ export const MAX_ACTION_RESULT_ERROR_CHARS = 2000;
4
+ export const ACTION_RESULT_OVERSIZE_WARNING_TOKENS = 10000;
5
+ export const ACTION_RESULT_TOKEN_ESTIMATE_CHARS = 4;
6
+ export const ACTION_RESULT_FULL_OUTPUT_REFERENCE_KEYS = new Set([
7
+ "fullOutputPath",
8
+ "fullOutputFile",
9
+ "outputPath",
10
+ "outputFile",
11
+ "outputFilePath",
12
+ "stdoutPath",
13
+ "stdoutFile",
14
+ "artifactPath",
15
+ "resultPath",
16
+ "filePath",
17
+ "path",
18
+ ]);
19
+ export const ACTION_RESULT_FULL_ERROR_REFERENCE_KEYS = new Set([
20
+ "fullErrorPath",
21
+ "fullErrorFile",
22
+ "errorPath",
23
+ "errorFile",
24
+ "stderrPath",
25
+ "stderrFile",
26
+ "logPath",
27
+ "logFile",
28
+ ]);
29
+ export function estimateActionResultTokens(text) {
30
+ return Math.ceil(text.length / ACTION_RESULT_TOKEN_ESTIMATE_CHARS);
31
+ }
32
+ export function getActionResultActionName(result) {
33
+ const actionNameValue = result.data?.actionName;
34
+ return typeof actionNameValue === "string" && actionNameValue.trim()
35
+ ? actionNameValue.trim()
36
+ : "Unknown Action";
37
+ }
38
+ export function stringifyActionResultError(error) {
39
+ if (error === undefined || error === null) {
40
+ return undefined;
41
+ }
42
+ return error instanceof Error ? error.message : String(error);
43
+ }
44
+ function getReferenceFromData(data, keys) {
45
+ if (!data) {
46
+ return undefined;
47
+ }
48
+ for (const key of keys) {
49
+ const value = data[key];
50
+ if (typeof value === "string" && value.trim()) {
51
+ return value.trim();
52
+ }
53
+ }
54
+ return undefined;
55
+ }
56
+ export function getActionResultReference(result, field) {
57
+ return getReferenceFromData(result.data, field === "text"
58
+ ? ACTION_RESULT_FULL_OUTPUT_REFERENCE_KEYS
59
+ : ACTION_RESULT_FULL_ERROR_REFERENCE_KEYS);
60
+ }
61
+ export function truncateMiddle(text, maxChars, reference) {
62
+ const trimmed = text.trim();
63
+ if (trimmed.length <= maxChars) {
64
+ return trimmed;
65
+ }
66
+ let marker = "\n\n[... chars omitted ...]\n\n";
67
+ let available = Math.max(0, maxChars - marker.length);
68
+ let headChars = Math.ceil(available / 2);
69
+ let tailChars = Math.floor(available / 2);
70
+ const omittedChars = Math.max(0, trimmed.length - headChars - tailChars);
71
+ marker = `\n\n[... ${omittedChars} chars omitted ...]\n\n`;
72
+ available = Math.max(0, maxChars - marker.length);
73
+ headChars = Math.ceil(available / 2);
74
+ tailChars = Math.floor(available / 2);
75
+ const rendered = `${trimmed.slice(0, headChars)}${marker}${trimmed.slice(trimmed.length - tailChars)}`;
76
+ return reference ? `${rendered}\n\nFull output: ${reference}` : rendered;
77
+ }
78
+ export function collectActionResultSizeWarnings(result, thresholdTokens = ACTION_RESULT_OVERSIZE_WARNING_TOKENS) {
79
+ const actionName = getActionResultActionName(result);
80
+ const fields = [
81
+ { field: "text", text: result.text },
82
+ { field: "error", text: stringifyActionResultError(result.error) },
83
+ ];
84
+ return fields.flatMap(({ field, text }) => {
85
+ if (!text) {
86
+ return [];
87
+ }
88
+ const estimatedTokens = estimateActionResultTokens(text);
89
+ return estimatedTokens > thresholdTokens
90
+ ? [
91
+ {
92
+ actionName,
93
+ field,
94
+ rawCharLength: text.length,
95
+ estimatedTokens,
96
+ thresholdTokens,
97
+ },
98
+ ]
99
+ : [];
100
+ });
101
+ }
102
+ export function trimActionResultForPromptState(result, references = {}) {
103
+ const textReference = references.text ?? getActionResultReference(result, "text");
104
+ const errorReference = references.error ?? getActionResultReference(result, "error");
105
+ const data = { ...(result.data ?? {}) };
106
+ if (textReference) {
107
+ data.fullOutputPath = textReference;
108
+ }
109
+ if (errorReference) {
110
+ data.fullErrorPath = errorReference;
111
+ }
112
+ const text = typeof result.text === "string"
113
+ ? truncateMiddle(result.text, MAX_ACTION_RESULT_TEXT_CHARS, textReference)
114
+ : result.text;
115
+ const errorText = stringifyActionResultError(result.error);
116
+ const error = errorText === undefined
117
+ ? result.error
118
+ : truncateMiddle(errorText, MAX_ACTION_RESULT_ERROR_CHARS, errorReference);
119
+ return {
120
+ ...result,
121
+ ...(text !== undefined ? { text } : {}),
122
+ ...(error !== undefined ? { error } : {}),
123
+ data,
124
+ };
125
+ }
126
+ export function formatActionResultsForPrompt(actionResults, options = {}) {
127
+ const { header = "# Current Chain Action Results", maxResults = MAX_PROMPTED_ACTION_RESULTS, preserveAbsoluteIndex = true, } = options;
128
+ if (actionResults.length === 0) {
129
+ return "No action results available.";
130
+ }
131
+ const rendered = actionResults.length > maxResults
132
+ ? actionResults.slice(-maxResults)
133
+ : actionResults;
134
+ const truncatedCount = actionResults.length - rendered.length;
135
+ const omittedNote = truncatedCount > 0
136
+ ? [`(${truncatedCount} earlier action result(s) omitted.)`]
137
+ : [];
138
+ return [
139
+ header,
140
+ ...omittedNote,
141
+ ...rendered.map((result, index) => {
142
+ const displayIndex = preserveAbsoluteIndex
143
+ ? truncatedCount + index + 1
144
+ : index + 1;
145
+ const status = result.success === false ? "failed" : "succeeded";
146
+ const lines = [
147
+ `${displayIndex}. ${getActionResultActionName(result)} - ${status}`,
148
+ ];
149
+ if (typeof result.text === "string" && result.text.trim()) {
150
+ lines.push(`Output: ${result.text.trim()}`);
151
+ }
152
+ const errorText = stringifyActionResultError(result.error);
153
+ if (errorText) {
154
+ lines.push(`Error: ${errorText}`);
155
+ }
156
+ const outputReference = getActionResultReference(result, "text");
157
+ if (outputReference &&
158
+ !lines.some((line) => line.includes(outputReference))) {
159
+ lines.push(`Full output: ${outputReference}`);
160
+ }
161
+ const errorReference = getActionResultReference(result, "error");
162
+ if (errorReference &&
163
+ !lines.some((line) => line.includes(errorReference))) {
164
+ lines.push(`Full error: ${errorReference}`);
165
+ }
166
+ return lines.join("\n");
167
+ }),
168
+ ].join("\n\n");
169
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"context-catalog.d.ts","sourceRoot":"","sources":["../../../../../../typescript/src/utils/context-catalog.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAE1E,eAAO,MAAM,kBAAkB,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,EAAE,CAqG7D,CAAC;AAEF,eAAO,MAAM,oBAAoB,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,EAAE,CAsB/D,CAAC;AAUF,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,MAAM,GAAG,YAAY,EAAE,CAOpE;AAED,wBAAgB,uBAAuB,CAAC,QAAQ,EAAE,QAAQ,GAAG,YAAY,EAAE,CAO1E"}
1
+ {"version":3,"file":"context-catalog.d.ts","sourceRoot":"","sources":["../../../../../../typescript/src/utils/context-catalog.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAE1E,eAAO,MAAM,kBAAkB,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,EAAE,CA8G7D,CAAC;AAEF,eAAO,MAAM,oBAAoB,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,EAAE,CAwB/D,CAAC;AAUF,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,MAAM,GAAG,YAAY,EAAE,CAOpE;AAED,wBAAgB,uBAAuB,CAAC,QAAQ,EAAE,QAAQ,GAAG,YAAY,EAAE,CAO1E"}
@@ -38,6 +38,7 @@ export const ACTION_CONTEXT_MAP = {
38
38
  WEB_SEARCH: ["knowledge", "browser"],
39
39
  SUMMARIZE: ["knowledge"],
40
40
  ANALYZE: ["knowledge"],
41
+ CREATE_TASK: ["code", "automation"],
41
42
  BROWSER_SESSION: ["browser"],
42
43
  BROWSE: ["browser"],
43
44
  SCREENSHOT: ["browser", "media"],
@@ -46,6 +47,14 @@ export const ACTION_CONTEXT_MAP = {
46
47
  TYPE_TEXT: ["browser"],
47
48
  EXTRACT_PAGE: ["browser", "knowledge"],
48
49
  SPAWN_AGENT: ["code", "automation"],
50
+ SEND_TO_AGENT: ["code", "automation"],
51
+ LIST_AGENTS: ["code", "automation"],
52
+ STOP_AGENT: ["code", "automation"],
53
+ TASK_HISTORY: ["code", "automation"],
54
+ TASK_CONTROL: ["code", "automation"],
55
+ TASK_SHARE: ["code", "automation"],
56
+ PROVISION_WORKSPACE: ["code", "automation"],
57
+ FINALIZE_WORKSPACE: ["code", "automation"],
49
58
  KILL_AGENT: ["code", "automation"],
50
59
  UPDATE_AGENT: ["code", "system"],
51
60
  RUN_SCRIPT: ["code", "automation"],
@@ -115,6 +124,8 @@ export const PROVIDER_CONTEXT_MAP = {
115
124
  walletPortfolio: ["wallet"],
116
125
  tokenPrices: ["wallet", "knowledge"],
117
126
  chainInfo: ["wallet"],
127
+ CODING_AGENT_EXAMPLES: ["code", "automation"],
128
+ ACTIVE_WORKSPACE_CONTEXT: ["code", "automation"],
118
129
  contacts: ["social"],
119
130
  trustScores: ["social"],
120
131
  platformIdentity: ["social"],
@@ -15,9 +15,12 @@ export declare function getContextRoutingFromState(state: State | null | undefin
15
15
  export declare function getContextRoutingFromMessage(message: Memory): ContextRoutingDecision;
16
16
  export declare function mergeContextRouting(state: State | null | undefined, message: Memory): ContextRoutingDecision;
17
17
  export declare function getActiveRoutingContexts(routing: ContextRoutingDecision): AgentContext[];
18
+ export declare function getActiveRoutingContextsForTurn(state: State | null | undefined, message: Memory): AgentContext[];
18
19
  export declare function shouldIncludeByContext(declaredContexts: AgentContext[] | undefined, activeContexts: AgentContext[] | undefined): boolean;
19
20
  export declare function setContextRoutingMetadata(message: Memory, routing: ContextRoutingDecision): void;
20
21
  export declare function deriveAvailableContexts(actions: Action[], providers: Provider[]): AgentContext[];
22
+ export declare function inferContextRoutingFromText(text: string | null | undefined): ContextRoutingDecision;
23
+ export declare function inferContextRoutingFromMessage(message: Pick<Memory, "content">): ContextRoutingDecision;
21
24
  export declare function attachAvailableContexts(state: State, runtime: {
22
25
  actions: Action[];
23
26
  providers: Provider[];
@@ -1 +1 @@
1
- {"version":3,"file":"context-routing.d.ts","sourceRoot":"","sources":["../../../../../../typescript/src/utils/context-routing.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC1E,OAAO,KAAK,EAAE,M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