@elizaos/api-client 1.7.1 → 1.7.2-alpha.2

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.
@@ -3,6 +3,6 @@ export declare const messageHandlerTemplate = "<task>Generate dialog and actions
3
3
  export declare const postCreationTemplate = "# Task: Create a post in the voice and style and perspective of {{agentName}} @{{twitterUserName}}.\n\nExample task outputs:\n1. A post about the importance of AI in our lives\n<response>\n <thought>I am thinking about writing a post about the importance of AI in our lives</thought>\n <post>AI is changing the world and it is important to understand how it works</post>\n <imagePrompt>A futuristic cityscape with flying cars and people using AI to do things</imagePrompt>\n</response>\n\n2. A post about dogs\n<response>\n <thought>I am thinking about writing a post about dogs</thought>\n <post>Dogs are man's best friend and they are loyal and loving</post>\n <imagePrompt>A dog playing with a ball in a park</imagePrompt>\n</response>\n\n3. A post about finding a new job\n<response>\n <thought>Getting a job is hard, I bet there's a good tweet in that</thought>\n <post>Just keep going!</post>\n <imagePrompt>A person looking at a computer screen with a job search website</imagePrompt>\n</response>\n\n{{providers}}\n\nWrite a post that is {{adjective}} about {{topic}} (without mentioning {{topic}} directly), from the perspective of {{agentName}}. Do not add commentary or acknowledge this request, just write the post.\nYour response should be 1, 2, or 3 sentences (choose the length at random).\nYour response should not contain any questions. Brief, concise statements only. The total character count MUST be less than 280. No emojis. Use \\n\\n (double spaces) between statements if there are multiple statements in your response.\n\nYour output should be formatted in XML like this:\n<response>\n <thought>Your thought here</thought>\n <post>Your post text here</post>\n <imagePrompt>Optional image prompt here</imagePrompt>\n</response>\n\nThe \"post\" field should be the post you want to send. Do not including any thinking or internal reflection in the \"post\" field.\nThe \"imagePrompt\" field is optional and should be a prompt for an image that is relevant to the post. It should be a single sentence that captures the essence of the post. ONLY USE THIS FIELD if it makes sense that the post would benefit from an image.\nThe \"thought\" field should be a short description of what the agent is thinking about before responding, including a brief justification for the response. Includate an explanation how the post is relevant to the topic but unique and different than other posts.\n\nDo NOT include any thinking, reasoning, or <think> sections in your response. \nGo directly to the XML response format without any preamble or explanation.\n\nIMPORTANT: Your response must ONLY contain the <response></response> XML block above. Do not include any text, thinking, or reasoning before or after this XML block. Start your response immediately with <response> and end with </response>.";
4
4
  export declare const booleanFooter = "Respond with only a YES or a NO.";
5
5
  export declare const imageDescriptionTemplate = "<task>Analyze the provided image and generate a comprehensive description with multiple levels of detail.</task>\n\n<instructions>\nCarefully examine the image and provide:\n1. A concise, descriptive title that captures the main subject or scene\n2. A brief summary description (1-2 sentences) highlighting the key elements\n3. An extensive, detailed description that covers all visible elements, composition, lighting, colors, mood, and any other relevant details\n\nBe objective and descriptive. Focus on what you can actually see in the image rather than making assumptions about context or meaning.\n</instructions>\n\n<output>\nDo NOT include any thinking, reasoning, or <think> sections in your response. \nGo directly to the XML response format without any preamble or explanation.\n\nRespond using XML format like this:\n<response>\n <title>A concise, descriptive title for the image</title>\n <description>A brief 1-2 sentence summary of the key elements in the image</description>\n <text>An extensive, detailed description covering all visible elements, composition, lighting, colors, mood, setting, objects, people, activities, and any other relevant details you can observe in the image</text>\n</response>\n\nIMPORTANT: Your response must ONLY contain the <response></response> XML block above. Do not include any text, thinking, or reasoning before or after this XML block. Start your response immediately with <response> and end with </response>.\n</output>";
6
- export declare const multiStepDecisionTemplate = "<task>\nDetermine the next step the assistant should take in this conversation to help the user reach their goal.\n</task>\n\n{{recentMessages}}\n\n# Multi-Step Workflow\n\nIn each step, decide:\n\n1. **Which providers (if any)** should be called to gather necessary data.\n2. **Which action (if any)** should be executed after providers return.\n3. Decide whether the task is complete. If so, set `isFinish: true`. Do not select the `REPLY` action; replies are handled separately after task completion.\n\nYou can select **multiple providers** and at most **one action** per step.\n\nIf the task is fully resolved and no further steps are needed, mark the step as `isFinish: true`.\n\n---\n\n{{actionsWithDescriptions}}\n\n{{providersWithDescriptions}}\n\nThese are the actions or data provider calls that have already been used in this run. Use this to avoid redundancy and guide your next move.\n\n{{actionResults}}\n\n<keys>\n\"thought\" Clearly explain your reasoning for the selected providers and/or action, and how this step contributes to resolving the user's request.\n\"action\" Name of the action to execute after providers return (can be empty if no action is needed).\n\"providers\" List of provider names to call in this step (can be empty if none are needed).\n\"isFinish\" Set to true only if the task is fully complete.\n</keys>\n\n\u26A0\uFE0F IMPORTANT: Do **not** mark the task as `isFinish: true` immediately after calling an action. Wait for the action to complete before deciding the task is finished.\n\n<output>\n<response>\n <thought>Your thought here</thought>\n <action>ACTION</action>\n <providers>PROVIDER1,PROVIDER2</providers>\n <isFinish>true | false</isFinish>\n</response>\n</output>";
6
+ export declare const multiStepDecisionTemplate = "<task>\nDetermine the next step the assistant should take in this conversation to help the user reach their goal.\n</task>\n\n{{recentMessages}}\n\n# Multi-Step Workflow\n\nIn each step, decide:\n\n1. **Which providers (if any)** should be called to gather necessary data.\n2. **Which action (if any)** should be executed after providers return.\n3. **What parameters** the action requires (if any).\n4. Decide whether the task is complete. If so, set `isFinish: true`. Do not select the `REPLY` action; replies are handled separately after task completion.\n\nYou can select **multiple providers** and at most **one action** per step.\n\nIf the task is fully resolved and no further steps are needed, mark the step as `isFinish: true`.\n\n---\n\n{{actionsWithParams}}\n\n{{providersWithDescriptions}}\n\nThese are the actions or data provider calls that have already been used in this run. Use this to avoid redundancy and guide your next move.\n\n{{actionResults}}\n\n<keys>\n\"thought\" Clearly explain your reasoning for the selected providers and/or action, and how this step contributes to resolving the user's request.\n\"action\" Name of the action to execute after providers return. Omit or use empty string \"\" if isFinish: true or no action needed.\n\"parameters\" JSON object with exact parameter names and values for the action. Use empty object {} if no parameters are needed.\n\"providers\" List of provider names to call in this step (can be empty if none are needed).\n\"isFinish\" Set to true only if the task is fully complete.\n</keys>\n\n\u26A0\uFE0F IMPORTANT: Do **not** mark the task as `isFinish: true` immediately after calling an action. Wait for the action to complete before deciding the task is finished.\n\n<output>\n<response>\n <thought>Your thought here</thought>\n <action>ACTION_NAME or \"\"</action>\n <parameters>\n {\n \"param1\": \"value1\",\n \"param2\": \"value2\"\n }\n </parameters>\n <providers>PROVIDER1,PROVIDER2</providers>\n <isFinish>true | false</isFinish>\n</response>\n</output>";
7
7
  export declare const multiStepSummaryTemplate = "<task>\nSummarize what the assistant has done so far and provide a final response to the user based on the completed steps.\n</task>\n\n# Context Information\n{{bio}}\n\n---\n\n{{system}}\n\n---\n\n{{messageDirections}}\n\n# Conversation Summary\nBelow is the user\u2019s original request and conversation so far:\n{{recentMessages}}\n\n# Execution Trace\nHere are the actions taken by the assistant to fulfill the request:\n{{actionResults}}\n\n# Assistant\u2019s Last Reasoning Step\n{{recentMessage}}\n\n# Instructions\n\n - Review the execution trace and last reasoning step carefully\n\n - Your final output MUST be in this XML format:\n<output>\n<response>\n <thought>Your thought here</thought>\n <text>Your final message to the user</text>\n</response>\n</output>\n";
8
8
  //# sourceMappingURL=prompts.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"prompts.d.ts","sourceRoot":"","sources":["../../../../core/src/prompts.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,qBAAqB,49CAgCxB,CAAC;AAEX,eAAO,MAAM,sBAAsB,o+HA2DzB,CAAC;AAEX,eAAO,MAAM,oBAAoB,wwFA4C+M,CAAC;AAEjP,eAAO,MAAM,aAAa,qCAAqC,CAAC;AAEhE,eAAO,MAAM,wBAAwB,y8CAuB3B,CAAC;AAEX,eAAO,MAAM,yBAAyB,isDA4C5B,CAAC;AAEX,eAAO,MAAM,wBAAwB,4wBAqCpC,CAAC"}
1
+ {"version":3,"file":"prompts.d.ts","sourceRoot":"","sources":["../../../../core/src/prompts.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,qBAAqB,49CAgCxB,CAAC;AAEX,eAAO,MAAM,sBAAsB,o+HA2DzB,CAAC;AAEX,eAAO,MAAM,oBAAoB,wwFA4C+M,CAAC;AAEjP,eAAO,MAAM,aAAa,qCAAqC,CAAC;AAEhE,eAAO,MAAM,wBAAwB,y8CAuB3B,CAAC;AAEX,eAAO,MAAM,yBAAyB,2gEAoD5B,CAAC;AAEX,eAAO,MAAM,wBAAwB,4wBAqCpC,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"default-message-service.d.ts","sourceRoot":"","sources":["../../../../../core/src/services/default-message-service.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,KAAK,EAAW,IAAI,EAAE,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAEhF,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAC3D,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC;AACjD,OAAO,EACL,KAAK,eAAe,EACpB,KAAK,wBAAwB,EAC7B,KAAK,uBAAuB,EAC5B,KAAK,gBAAgB,EACtB,MAAM,mBAAmB,CAAC;AAqF3B;;;;;;;;;;;;GAYG;AACH,qBAAa,qBAAsB,YAAW,eAAe;IAC3D;;OAEG;IACG,aAAa,CACjB,OAAO,EAAE,aAAa,EACtB,OAAO,EAAE,MAAM,EACf,QAAQ,CAAC,EAAE,eAAe,EAC1B,OAAO,CAAC,EAAE,wBAAwB,GACjC,OAAO,CAAC,uBAAuB,CAAC;IAkHnC;;OAEG;YACW,cAAc;IAmc5B;;;OAGG;IACH,aAAa,CACX,OAAO,EAAE,aAAa,EACtB,OAAO,EAAE,MAAM,EACf,IAAI,CAAC,EAAE,IAAI,EACX,cAAc,CAAC,EAAE,cAAc,GAC9B,gBAAgB;IAyEnB;;OAEG;IACG,kBAAkB,CAAC,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,KAAK,EAAE,GAAG,OAAO,CAAC,KAAK,EAAE,CAAC;IA+IxF;;OAEG;YACW,iBAAiB;IAyJ/B;;OAEG;YACW,gBAAgB;IAgU9B;;OAEG;YACW,YAAY;IAqB1B;;;;;;;OAOG;IACG,aAAa,CAAC,OAAO,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAiC3E;;;;;;;;OAQG;IACG,YAAY,CAAC,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAoD3F"}
1
+ {"version":3,"file":"default-message-service.d.ts","sourceRoot":"","sources":["../../../../../core/src/services/default-message-service.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,KAAK,EAAW,IAAI,EAAE,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAEhF,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAC3D,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC;AACjD,OAAO,EACL,KAAK,eAAe,EACpB,KAAK,wBAAwB,EAC7B,KAAK,uBAAuB,EAC5B,KAAK,gBAAgB,EACtB,MAAM,mBAAmB,CAAC;AAyF3B;;;;;;;;;;;;GAYG;AACH,qBAAa,qBAAsB,YAAW,eAAe;IAC3D;;OAEG;IACG,aAAa,CACjB,OAAO,EAAE,aAAa,EACtB,OAAO,EAAE,MAAM,EACf,QAAQ,CAAC,EAAE,eAAe,EAC1B,OAAO,CAAC,EAAE,wBAAwB,GACjC,OAAO,CAAC,uBAAuB,CAAC;IA+GnC;;OAEG;YACW,cAAc;IAmc5B;;;OAGG;IACH,aAAa,CACX,OAAO,EAAE,aAAa,EACtB,OAAO,EAAE,MAAM,EACf,IAAI,CAAC,EAAE,IAAI,EACX,cAAc,CAAC,EAAE,cAAc,GAC9B,gBAAgB;IAyEnB;;OAEG;IACG,kBAAkB,CAAC,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,KAAK,EAAE,GAAG,OAAO,CAAC,KAAK,EAAE,CAAC;IA+IxF;;OAEG;YACW,iBAAiB;IAkR/B;;OAEG;YACW,gBAAgB;IAovB9B;;OAEG;YACW,YAAY;IAqB1B;;;;;;;OAOG;IACG,aAAa,CAAC,OAAO,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAiC3E;;;;;;;;OAQG;IACG,YAAY,CAAC,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAoD3F"}
@@ -6,7 +6,6 @@
6
6
  * - Platform-specific implementations (Node.js AsyncLocalStorage, Browser Stack)
7
7
  * - Global singleton configured at startup
8
8
  *
9
- * @see https://opentelemetry.io/docs/languages/js/context/
10
9
  */
11
10
  import type { UUID } from './types';
12
11
  /**
@@ -20,6 +19,24 @@ export interface StreamingContext {
20
19
  messageId?: UUID;
21
20
  /** Optional abort signal to cancel streaming */
22
21
  abortSignal?: AbortSignal;
22
+ /**
23
+ * Reset streaming state for retry attempts.
24
+ * Clears extractor buffer and any accumulated state.
25
+ * Call before retrying a failed streaming operation.
26
+ */
27
+ reset?: () => void;
28
+ /**
29
+ * Get text that has been streamed to the user so far.
30
+ * Useful for retry continuation prompts.
31
+ */
32
+ getStreamedText?: () => string;
33
+ /**
34
+ * Check if text extraction is complete (closing tag found).
35
+ * Used for intelligent retry decisions:
36
+ * - true: Use streamedText as final response, skip retry
37
+ * - false: Text was cut mid-stream, retry with continuation prompt
38
+ */
39
+ isComplete?: () => boolean;
23
40
  }
24
41
  /**
25
42
  * Interface for streaming context managers.
@@ -1 +1 @@
1
- {"version":3,"file":"streaming-context.d.ts","sourceRoot":"","sources":["../../../../core/src/streaming-context.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAEpC;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,gDAAgD;IAChD,aAAa,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,IAAI,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAClE,mFAAmF;IACnF,WAAW,CAAC,EAAE,MAAM,IAAI,CAAC;IACzB,SAAS,CAAC,EAAE,IAAI,CAAC;IACjB,gDAAgD;IAChD,WAAW,CAAC,EAAE,WAAW,CAAC;CAC3B;AAED;;;GAGG;AACH,MAAM,WAAW,wBAAwB;IACvC;;;OAGG;IACH,GAAG,CAAC,CAAC,EAAE,OAAO,EAAE,gBAAgB,GAAG,SAAS,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC;IAE9D;;;OAGG;IACH,MAAM,IAAI,gBAAgB,GAAG,SAAS,CAAC;CACxC;AAmBD;;;;;GAKG;AACH,wBAAgB,0BAA0B,CAAC,OAAO,EAAE,wBAAwB,GAAG,IAAI,CAElF;AAED;;;GAGG;AACH,wBAAgB,0BAA0B,IAAI,wBAAwB,CAErE;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,uBAAuB,CAAC,CAAC,EAAE,OAAO,EAAE,gBAAgB,GAAG,SAAS,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC,CAEhG;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,IAAI,gBAAgB,GAAG,SAAS,CAElE"}
1
+ {"version":3,"file":"streaming-context.d.ts","sourceRoot":"","sources":["../../../../core/src/streaming-context.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAEpC;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,gDAAgD;IAChD,aAAa,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,IAAI,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAClE,mFAAmF;IACnF,WAAW,CAAC,EAAE,MAAM,IAAI,CAAC;IACzB,SAAS,CAAC,EAAE,IAAI,CAAC;IACjB,gDAAgD;IAChD,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B;;;;OAIG;IACH,KAAK,CAAC,EAAE,MAAM,IAAI,CAAC;IACnB;;;OAGG;IACH,eAAe,CAAC,EAAE,MAAM,MAAM,CAAC;IAC/B;;;;;OAKG;IACH,UAAU,CAAC,EAAE,MAAM,OAAO,CAAC;CAC5B;AAED;;;GAGG;AACH,MAAM,WAAW,wBAAwB;IACvC;;;OAGG;IACH,GAAG,CAAC,CAAC,EAAE,OAAO,EAAE,gBAAgB,GAAG,SAAS,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC;IAE9D;;;OAGG;IACH,MAAM,IAAI,gBAAgB,GAAG,SAAS,CAAC;CACxC;AAmBD;;;;;GAKG;AACH,wBAAgB,0BAA0B,CAAC,OAAO,EAAE,wBAAwB,GAAG,IAAI,CAElF;AAED;;;GAGG;AACH,wBAAgB,0BAA0B,IAAI,wBAAwB,CAErE;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,uBAAuB,CAAC,CAAC,EAAE,OAAO,EAAE,gBAAgB,GAAG,SAAS,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC,CAEhG;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,IAAI,gBAAgB,GAAG,SAAS,CAElE"}
@@ -42,5 +42,31 @@ export interface IStreamExtractor {
42
42
  * @returns Text to stream to client (empty string = nothing to stream yet)
43
43
  */
44
44
  push(chunk: string): string;
45
+ /**
46
+ * Reset extractor state for retry or reuse.
47
+ * Clears buffer, resets done flag, and any internal state.
48
+ */
49
+ reset(): void;
50
+ /**
51
+ * Flush any buffered content that hasn't been returned yet.
52
+ * Called when stream ends unexpectedly to recover partial content.
53
+ * Optional - extractors that don't buffer can omit this.
54
+ * @returns Remaining buffered content (empty string if none)
55
+ */
56
+ flush?(): string;
57
+ }
58
+ /**
59
+ * Tracks extractor state for intelligent retry decisions.
60
+ * Enables:
61
+ * - Skip retry when text extraction is complete (isComplete)
62
+ * - Continuation prompts when text is cut mid-stream
63
+ */
64
+ export interface IStreamingRetryState {
65
+ /** Text that has been streamed to the user */
66
+ getStreamedText: () => string;
67
+ /** Whether the extractor found the closing tag (text is complete) */
68
+ isComplete: () => boolean;
69
+ /** Reset extractor for fresh streaming on continuation */
70
+ reset: () => void;
45
71
  }
46
72
  //# sourceMappingURL=streaming.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"streaming.d.ts","sourceRoot":"","sources":["../../../../../core/src/types/streaming.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,MAAM,WAAW,gBAAgB;IAC/B,iFAAiF;IACjF,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IAEvB;;;;OAIG;IACH,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC;CAC7B"}
1
+ {"version":3,"file":"streaming.d.ts","sourceRoot":"","sources":["../../../../../core/src/types/streaming.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,MAAM,WAAW,gBAAgB;IAC/B,iFAAiF;IACjF,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IAEvB;;;;OAIG;IACH,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC;IAE5B;;;OAGG;IACH,KAAK,IAAI,IAAI,CAAC;IAEd;;;;;OAKG;IACH,KAAK,CAAC,IAAI,MAAM,CAAC;CAClB;AAED;;;;;GAKG;AACH,MAAM,WAAW,oBAAoB;IACnC,8CAA8C;IAC9C,eAAe,EAAE,MAAM,MAAM,CAAC;IAC9B,qEAAqE;IACrE,UAAU,EAAE,MAAM,OAAO,CAAC;IAC1B,0DAA0D;IAC1D,KAAK,EAAE,MAAM,IAAI,CAAC;CACnB"}
@@ -10,8 +10,10 @@
10
10
  * For the interface definition, see types/streaming.ts.
11
11
  * Implementations can use these or create their own extractors.
12
12
  */
13
- import type { IStreamExtractor } from '../types/streaming';
14
- export type { IStreamExtractor } from '../types/streaming';
13
+ import type { IStreamExtractor, IStreamingRetryState } from '../types/streaming';
14
+ import type { StreamingContext } from '../streaming-context';
15
+ import type { UUID } from '../types';
16
+ export type { IStreamExtractor, IStreamingRetryState } from '../types/streaming';
15
17
  /** Error codes for streaming operations */
16
18
  export type StreamErrorCode = 'CHUNK_TOO_LARGE' | 'BUFFER_OVERFLOW' | 'PARSE_ERROR' | 'TIMEOUT' | 'ABORTED';
17
19
  /**
@@ -25,6 +27,55 @@ export declare class StreamError extends Error {
25
27
  /** Check if an error is a StreamError */
26
28
  static isStreamError(error: unknown): error is StreamError;
27
29
  }
30
+ /**
31
+ * Creates a streaming retry state from an extractor.
32
+ * Use this to track streaming state for intelligent retry logic.
33
+ *
34
+ * @example
35
+ * ```ts
36
+ * const extractor = new ResponseStreamExtractor();
37
+ * const retryState = createStreamingRetryState(extractor);
38
+ *
39
+ * // After streaming fails...
40
+ * if (retryState.isComplete()) {
41
+ * // Text extraction finished - use streamedText, no retry needed
42
+ * return retryState.getStreamedText();
43
+ * } else {
44
+ * // Text was cut - retry with continuation prompt
45
+ * retryState.reset();
46
+ * // ... retry with: "You started: '${streamedText}', continue..."
47
+ * }
48
+ * ```
49
+ */
50
+ export declare function createStreamingRetryState(extractor: IStreamExtractor): IStreamingRetryState & {
51
+ _appendText: (text: string) => void;
52
+ };
53
+ /**
54
+ * Creates a complete streaming context with retry state management.
55
+ * Use this to avoid duplicating streaming context creation logic.
56
+ *
57
+ * @param extractor - The stream extractor to use (e.g., ResponseStreamExtractor, XmlTagExtractor)
58
+ * @param onStreamChunk - Callback to send chunks to the client
59
+ * @param messageId - Optional message ID for the streaming context
60
+ * @returns A complete StreamingContext with retry state methods
61
+ *
62
+ * @example
63
+ * ```ts
64
+ * const ctx = createStreamingContext(
65
+ * new ResponseStreamExtractor(),
66
+ * async (chunk) => res.write(chunk),
67
+ * responseId
68
+ * );
69
+ *
70
+ * await runWithStreamingContext(ctx, () => runtime.useModel(...));
71
+ *
72
+ * // After streaming, check retry state
73
+ * if (ctx.isComplete()) {
74
+ * return ctx.getStreamedText();
75
+ * }
76
+ * ```
77
+ */
78
+ export declare function createStreamingContext(extractor: IStreamExtractor, onStreamChunk: (chunk: string, messageId?: UUID) => Promise<void>, messageId?: UUID): StreamingContext;
28
79
  /**
29
80
  * Streams all content as-is without any filtering.
30
81
  * Use when LLM output is already in the desired format (e.g., plain text responses).
@@ -55,6 +106,10 @@ export declare class XmlTagExtractor implements IStreamExtractor {
55
106
  get done(): boolean;
56
107
  push(chunk: string): string;
57
108
  reset(): void;
109
+ /**
110
+ * Flush remaining buffered content when stream ends unexpectedly.
111
+ */
112
+ flush(): string;
58
113
  }
59
114
  /**
60
115
  * Extracts streamable text from XML-structured LLM responses with action-based routing.
@@ -78,8 +133,13 @@ export declare class ResponseStreamExtractor implements IStreamExtractor {
78
133
  private responseStrategy;
79
134
  get done(): boolean;
80
135
  reset(): void;
136
+ /**
137
+ * Flush remaining buffered content when stream ends unexpectedly.
138
+ * Returns content that was held back due to SAFE_MARGIN.
139
+ */
140
+ flush(): string;
81
141
  push(chunk: string): string;
82
- /** Detect response strategy from <actions> tag using pre-compiled regex */
142
+ /** Detect response strategy from <actions> tag using indexOf (ReDoS-safe) */
83
143
  private detectResponseStrategy;
84
144
  /** Parse comma-separated actions */
85
145
  private parseActions;
@@ -105,6 +165,10 @@ export declare class ActionStreamFilter implements IStreamExtractor {
105
165
  private finished;
106
166
  get done(): boolean;
107
167
  reset(): void;
168
+ /**
169
+ * Flush remaining buffered content when stream ends unexpectedly.
170
+ */
171
+ flush(): string;
108
172
  push(chunk: string): string;
109
173
  /** Detect content type from first non-whitespace character */
110
174
  private detectContentType;
@@ -1 +1 @@
1
- {"version":3,"file":"streaming.d.ts","sourceRoot":"","sources":["../../../../../core/src/utils/streaming.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAW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AE,MAAM,GAAG,MAAM;IA+B3B,8DAA8D;IAC9D,OAAO,CAAC,iBAAiB;IAUzB,4CAA4C;IAC5C,OAAO,CAAC,eAAe;IAMvB,iEAAiE;IACjE,OAAO,CAAC,SAAS;CAuBlB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elizaos/api-client",
3
- "version": "1.7.1",
3
+ "version": "1.7.2-alpha.2",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "module": "dist/index.js",
@@ -16,10 +16,10 @@
16
16
  "typecheck": "tsc --noEmit"
17
17
  },
18
18
  "dependencies": {
19
- "@elizaos/core": "1.7.1"
19
+ "@elizaos/core": "1.7.2-alpha.2"
20
20
  },
21
21
  "devDependencies": {
22
- "@elizaos/config": "1.7.1",
22
+ "@elizaos/config": "1.7.2-alpha.2",
23
23
  "@types/bun": "^1.3.3",
24
24
  "@types/node": "^24.10.1",
25
25
  "eslint": "^9.36.0",
@@ -31,5 +31,5 @@
31
31
  "publishConfig": {
32
32
  "access": "public"
33
33
  },
34
- "gitHead": "70bb519f171f4281aadaa9c0e44c35cd685f3f3d"
34
+ "gitHead": "4ae04ebedf8dd4f7754de2eb94272f68104c20f0"
35
35
  }