@elizaos/core 2.0.0-alpha.7 → 2.0.0-alpha.71

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 (132) hide show
  1. package/README.md +213 -16
  2. package/dist/testing/index.js +22 -0
  3. package/dist/testing/index.js.map +9 -0
  4. package/package.json +46 -27
  5. package/dist/actions.d.ts +0 -22
  6. package/dist/actions.d.ts.map +0 -1
  7. package/dist/browser/index.browser.js +0 -771
  8. package/dist/browser/index.browser.js.map +0 -427
  9. package/dist/browser/index.d.ts +0 -2
  10. package/dist/character.d.ts +0 -39
  11. package/dist/character.d.ts.map +0 -1
  12. package/dist/constants/index.d.ts +0 -7
  13. package/dist/constants/secrets.d.ts +0 -67
  14. package/dist/database.d.ts +0 -494
  15. package/dist/database.d.ts.map +0 -1
  16. package/dist/elizaos.d.ts +0 -194
  17. package/dist/elizaos.d.ts.map +0 -1
  18. package/dist/entities.d.ts +0 -40
  19. package/dist/entities.d.ts.map +0 -1
  20. package/dist/index.browser.d.ts +0 -39
  21. package/dist/index.browser.d.ts.map +0 -1
  22. package/dist/index.d.ts +0 -40
  23. package/dist/index.d.ts.map +0 -1
  24. package/dist/index.js +0 -2
  25. package/dist/index.node.d.ts +0 -37
  26. package/dist/index.node.d.ts.map +0 -1
  27. package/dist/logger.d.ts +0 -72
  28. package/dist/logger.d.ts.map +0 -1
  29. package/dist/memory.d.ts +0 -63
  30. package/dist/memory.d.ts.map +0 -1
  31. package/dist/node/index.d.ts +0 -2
  32. package/dist/node/index.node.js +0 -53403
  33. package/dist/node/index.node.js.map +0 -511
  34. package/dist/onboarding-state.d.ts +0 -209
  35. package/dist/plugin.d.ts +0 -55
  36. package/dist/plugin.d.ts.map +0 -1
  37. package/dist/prompts.d.ts +0 -7
  38. package/dist/prompts.d.ts.map +0 -1
  39. package/dist/request-context.d.ts +0 -142
  40. package/dist/request-context.d.ts.map +0 -1
  41. package/dist/request-context.node.d.ts +0 -36
  42. package/dist/request-context.node.d.ts.map +0 -1
  43. package/dist/roles.d.ts +0 -23
  44. package/dist/roles.d.ts.map +0 -1
  45. package/dist/runtime.d.ts +0 -366
  46. package/dist/runtime.d.ts.map +0 -1
  47. package/dist/schemas/character.d.ts +0 -151
  48. package/dist/schemas/character.d.ts.map +0 -1
  49. package/dist/search.d.ts +0 -316
  50. package/dist/search.d.ts.map +0 -1
  51. package/dist/secrets.d.ts +0 -11
  52. package/dist/secrets.d.ts.map +0 -1
  53. package/dist/services/default-message-service.d.ts +0 -69
  54. package/dist/services/default-message-service.d.ts.map +0 -1
  55. package/dist/services/message-service.d.ts +0 -171
  56. package/dist/services/message-service.d.ts.map +0 -1
  57. package/dist/services.d.ts +0 -56
  58. package/dist/services.d.ts.map +0 -1
  59. package/dist/sessions/index.d.ts +0 -10
  60. package/dist/sessions/paths.d.ts +0 -56
  61. package/dist/sessions/provider.d.ts +0 -73
  62. package/dist/sessions/session-key.d.ts +0 -133
  63. package/dist/sessions/store.d.ts +0 -75
  64. package/dist/sessions/types.d.ts +0 -195
  65. package/dist/settings.d.ts +0 -90
  66. package/dist/settings.d.ts.map +0 -1
  67. package/dist/streaming-context.browser.d.ts +0 -26
  68. package/dist/streaming-context.browser.d.ts.map +0 -1
  69. package/dist/streaming-context.d.ts +0 -95
  70. package/dist/streaming-context.d.ts.map +0 -1
  71. package/dist/streaming-context.node.d.ts +0 -15
  72. package/dist/streaming-context.node.d.ts.map +0 -1
  73. package/dist/types/agent.d.ts +0 -97
  74. package/dist/types/agent.d.ts.map +0 -1
  75. package/dist/types/components.d.ts +0 -155
  76. package/dist/types/components.d.ts.map +0 -1
  77. package/dist/types/database.d.ts +0 -414
  78. package/dist/types/database.d.ts.map +0 -1
  79. package/dist/types/elizaos.d.ts +0 -159
  80. package/dist/types/elizaos.d.ts.map +0 -1
  81. package/dist/types/environment.d.ts +0 -116
  82. package/dist/types/environment.d.ts.map +0 -1
  83. package/dist/types/events.d.ts +0 -203
  84. package/dist/types/events.d.ts.map +0 -1
  85. package/dist/types/index.d.ts +0 -20
  86. package/dist/types/index.d.ts.map +0 -1
  87. package/dist/types/knowledge.d.ts +0 -30
  88. package/dist/types/knowledge.d.ts.map +0 -1
  89. package/dist/types/memory.d.ts +0 -102
  90. package/dist/types/memory.d.ts.map +0 -1
  91. package/dist/types/messaging.d.ts +0 -137
  92. package/dist/types/messaging.d.ts.map +0 -1
  93. package/dist/types/model.d.ts +0 -513
  94. package/dist/types/model.d.ts.map +0 -1
  95. package/dist/types/plugin.d.ts +0 -91
  96. package/dist/types/plugin.d.ts.map +0 -1
  97. package/dist/types/primitives.d.ts +0 -96
  98. package/dist/types/primitives.d.ts.map +0 -1
  99. package/dist/types/runtime.d.ts +0 -140
  100. package/dist/types/runtime.d.ts.map +0 -1
  101. package/dist/types/service.d.ts +0 -150
  102. package/dist/types/service.d.ts.map +0 -1
  103. package/dist/types/settings.d.ts +0 -29
  104. package/dist/types/settings.d.ts.map +0 -1
  105. package/dist/types/state.d.ts +0 -56
  106. package/dist/types/state.d.ts.map +0 -1
  107. package/dist/types/streaming.d.ts +0 -71
  108. package/dist/types/streaming.d.ts.map +0 -1
  109. package/dist/types/task.d.ts +0 -67
  110. package/dist/types/task.d.ts.map +0 -1
  111. package/dist/types/tee.d.ts +0 -96
  112. package/dist/types/tee.d.ts.map +0 -1
  113. package/dist/types/testing.d.ts +0 -28
  114. package/dist/types/testing.d.ts.map +0 -1
  115. package/dist/utils/buffer.d.ts +0 -104
  116. package/dist/utils/buffer.d.ts.map +0 -1
  117. package/dist/utils/crypto-compat.d.ts +0 -183
  118. package/dist/utils/crypto-compat.d.ts.map +0 -1
  119. package/dist/utils/environment.d.ts +0 -50
  120. package/dist/utils/environment.d.ts.map +0 -1
  121. package/dist/utils/node.d.ts +0 -5
  122. package/dist/utils/node.d.ts.map +0 -1
  123. package/dist/utils/paths.d.ts +0 -92
  124. package/dist/utils/paths.d.ts.map +0 -1
  125. package/dist/utils/server-health.d.ts +0 -22
  126. package/dist/utils/server-health.d.ts.map +0 -1
  127. package/dist/utils/streaming.d.ts +0 -179
  128. package/dist/utils/streaming.d.ts.map +0 -1
  129. package/dist/utils/type-guards.d.ts +0 -23
  130. package/dist/utils/type-guards.d.ts.map +0 -1
  131. package/dist/utils.d.ts +0 -182
  132. package/dist/utils.d.ts.map +0 -1
@@ -1,179 +0,0 @@
1
- /**
2
- * Streaming utilities for filtering and extracting streamable content.
3
- *
4
- * This module provides implementations of {@link IStreamExtractor}:
5
- * - PassthroughExtractor - Simple passthrough (no filtering)
6
- * - XmlTagExtractor - Extract content from a specific XML tag
7
- * - ResponseStreamExtractor - Action-aware XML (for DefaultMessageService)
8
- * - ActionStreamFilter - Content-type aware filter (for action handlers)
9
- *
10
- * For the interface definition, see types/streaming.ts.
11
- * Implementations can use these or create their own extractors.
12
- */
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';
17
- /** Error codes for streaming operations */
18
- export type StreamErrorCode = 'CHUNK_TOO_LARGE' | 'BUFFER_OVERFLOW' | 'PARSE_ERROR' | 'TIMEOUT' | 'ABORTED';
19
- /**
20
- * Standardized error class for streaming operations.
21
- * Provides structured error codes for easier handling.
22
- */
23
- export declare class StreamError extends Error {
24
- readonly code: StreamErrorCode;
25
- readonly details?: Record<string, unknown>;
26
- constructor(code: StreamErrorCode, message: string, details?: Record<string, unknown>);
27
- /** Check if an error is a StreamError */
28
- static isStreamError(error: unknown): error is StreamError;
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;
79
- /**
80
- * Streams all content as-is without any filtering.
81
- * Use when LLM output is already in the desired format (e.g., plain text responses).
82
- */
83
- export declare class PassthroughExtractor implements IStreamExtractor {
84
- get done(): boolean;
85
- push(chunk: string): string;
86
- reset(): void;
87
- }
88
- /**
89
- * Extracts content from a specific XML tag, streaming it progressively.
90
- * Use when you have a simple XML format like `<response><text>content</text></response>`.
91
- *
92
- * @example
93
- * ```ts
94
- * const extractor = new XmlTagExtractor('text');
95
- * extractor.push('<response><text>Hello'); // Returns 'Hel' (keeps margin for split tags)
96
- * extractor.push(' world!</text></response>'); // Returns 'lo world!'
97
- * ```
98
- */
99
- export declare class XmlTagExtractor implements IStreamExtractor {
100
- private readonly openTag;
101
- private readonly closeTag;
102
- private buffer;
103
- private insideTag;
104
- private finished;
105
- constructor(tagName: string);
106
- get done(): boolean;
107
- push(chunk: string): string;
108
- reset(): void;
109
- /**
110
- * Flush remaining buffered content when stream ends unexpectedly.
111
- */
112
- flush(): string;
113
- }
114
- /**
115
- * Extracts streamable text from XML-structured LLM responses with action-based routing.
116
- *
117
- * This is the default implementation used by DefaultMessageService.
118
- * It understands the `<actions>` tag to determine whether to stream `<text>` content.
119
- *
120
- * Strategy:
121
- * - Parse <actions> to determine if response is direct (REPLY) or delegated (other actions)
122
- * - If direct: stream <text> content immediately
123
- * - If delegated: skip <text> (action handler will generate its own response via ActionStreamFilter)
124
- *
125
- * For simpler use cases without action routing, use {@link XmlTagExtractor} instead.
126
- */
127
- export declare class ResponseStreamExtractor implements IStreamExtractor {
128
- private static readonly STREAM_TAGS;
129
- private buffer;
130
- private insideTag;
131
- private currentTag;
132
- private finished;
133
- private responseStrategy;
134
- get done(): boolean;
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;
141
- push(chunk: string): string;
142
- /** Detect response strategy from <actions> tag using indexOf (ReDoS-safe) */
143
- private detectResponseStrategy;
144
- /** Parse comma-separated actions */
145
- private parseActions;
146
- /** Check if actions represent a direct reply */
147
- private isDirectReply;
148
- /** Determine if a tag should be streamed based on strategy */
149
- private shouldStreamTag;
150
- }
151
- /**
152
- * Filters action handler output for streaming.
153
- * Used by runtime.ts processActions() for each action's useModel calls.
154
- *
155
- * Auto-detects content type from first non-whitespace character:
156
- * - JSON (starts with { or [) → Don't stream (structured data for parsing)
157
- * - XML (starts with <) → Look for <text> tag and stream its content
158
- * - Plain text → Stream immediately
159
- */
160
- export declare class ActionStreamFilter implements IStreamExtractor {
161
- private buffer;
162
- private decided;
163
- private contentType;
164
- private insideTextTag;
165
- private finished;
166
- get done(): boolean;
167
- reset(): void;
168
- /**
169
- * Flush remaining buffered content when stream ends unexpectedly.
170
- */
171
- flush(): string;
172
- push(chunk: string): string;
173
- /** Detect content type from first non-whitespace character */
174
- private detectContentType;
175
- /** Handle plain text - stream everything */
176
- private handlePlainText;
177
- /** Handle XML content - extract and stream <text> tag content */
178
- private handleXml;
179
- }
@@ -1 +0,0 @@
1
- {"version":3,"file":"streaming.d.ts","sourceRoot":"","sources":["../../src/utils/streaming.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AACjF,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAC7D,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAGrC,YAAY,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAMjF,2CAA2C;AAC3C,MAAM,MAAM,eAAe,GACvB,iBAAiB,GACjB,iBAAiB,GACjB,aAAa,GACb,SAAS,GACT,SAAS,CAAC;AAEd;;;GAGG;AACH,qBAAa,WAAY,SAAQ,KAAK;IACpC,QAAQ,CAAC,IAAI,EAAE,eAAe,CAAC;IAC/B,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;gBAE/B,IAAI,EAAE,eAAe,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAOrF,yCAAyC;IACzC,MAAM,CAAC,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,WAAW;CAG3D;AAMD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,yBAAyB,CACvC,SAAS,EAAE,gBAAgB,GAC1B,oBAAoB,GAAG;IAAE,WAAW,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAA;CAAE,CAuBhE;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,sBAAsB,CACpC,SAAS,EAAE,gBAAgB,EAC3B,aAAa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pB,gDAAgD;IAChD,OAAO,CAAC,aAAa;IAIrB,8DAA8D;IAC9D,OAAO,CAAC,eAAe;CAGxB;AASD;;;;;;;;GAQG;AACH,qBAAa,kBAAmB,YAAW,gBAAgB;IACzD,OAAO,CAAC,MAAM,CAAM;IACpB,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,WAAW,CAA4B;IAC/C,OAAO,CAAC,aAAa,CAAS;IAC9B,OAAO,CAAC,QAAQ,CAAS;IAEzB,IAAI,IAAI,IAAI,OAAO,CAElB;IAED,KAAK,IAAI,IAAI;IAQb;;OAEG;IACH,KAAK,IAAI,MAAM;IAUf,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM;IA+B3B,8DAA8D;IAC9D,OAAO,CAAC,iBAAiB;IAUzB,4CAA4C;IAC5C,OAAO,CAAC,eAAe;IAMvB,iEAAiE;IACjE,OAAO,CAAC,SAAS;CAuBlB"}
@@ -1,23 +0,0 @@
1
- /**
2
- * Type guard utilities for runtime type checking
3
- * These functions help TypeScript narrow types safely
4
- */
5
- /**
6
- * Check if a value is a plain object (not a special object type)
7
- * Type guard that narrows the type to Record<string, unknown>
8
- *
9
- * Excludes: null, arrays, buffers, Date, RegExp, Map, Set, WeakMap, WeakSet, Error, Promise
10
- *
11
- * @param value - The value to check
12
- * @returns True if the value is a plain object
13
- *
14
- * @example
15
- * ```typescript
16
- * const data: unknown = { name: 'test' };
17
- * if (isPlainObject(data)) {
18
- * // TypeScript knows data is Record<string, unknown>
19
- * console.log(data.name);
20
- * }
21
- * ```
22
- */
23
- export declare function isPlainObject(value: unknown): value is Record<string, unknown>;
@@ -1 +0,0 @@
1
- {"version":3,"file":"type-guards.d.ts","sourceRoot":"","sources":["../../src/utils/type-guards.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAmC9E"}
package/dist/utils.d.ts DELETED
@@ -1,182 +0,0 @@
1
- import type { Entity, IAgentRuntime, Memory, State, TemplateType } from './types';
2
- import { UUID, ContentType } from './types';
3
- /**
4
- * Composes a context string by replacing placeholders in a template with corresponding values from the state.
5
- *
6
- * This function takes a template string with placeholders in the format `{{placeholder}}` and a state object.
7
- * It replaces each placeholder with the value from the state object that matches the placeholder's name.
8
- * If a matching key is not found in the state object for a given placeholder, the placeholder is replaced with an empty string.
9
- *
10
- * @param {Object} params - The parameters for composing the context.
11
- * @param {State} params.state - The state object containing values to replace the placeholders in the template.
12
- * @param {TemplateType} params.template - The template string or function containing placeholders to be replaced with state values.
13
- * @returns {string} The composed context string with placeholders replaced by corresponding state values.
14
- *
15
- * @example
16
- * // Given a state object and a template
17
- * const state = { userName: "Alice", userAge: 30 };
18
- * const template = "Hello, {{userName}}! You are {{userAge}} years old";
19
- *
20
- * // Composing the context with simple string replacement will result in:
21
- * // "Hello, Alice! You are 30 years old."
22
- * const contextSimple = composePromptFromState({ state, template });
23
- *
24
- * // Using composePromptFromState with a template function for dynamic template
25
- * const template = ({ state }) => {
26
- * const tone = Math.random() > 0.5 ? "kind" : "rude";
27
- * return `Hello, {{userName}}! You are {{userAge}} years old. Be ${tone}`;
28
- * };
29
- * const contextSimple = composePromptFromState({ state, template });
30
- */
31
- /**
32
- * Function to compose a prompt using a provided template and state.
33
- * It compiles the template (upgrading double braces to triple braces for non-HTML escaping)
34
- * and then populates it with values from the state. Additionally, it processes the
35
- * resulting string with `composeRandomUser` to replace placeholders like `{{nameX}}`.
36
- *
37
- * @param {Object} options - Object containing state and template information.
38
- * @param {State} options.state - The state object containing values to fill the template.
39
- * @param {TemplateType} options.template - The template string or function to be used for composing the prompt.
40
- * @returns {string} The composed prompt output, with state values and random user names populated.
41
- */
42
- export declare const composePrompt: ({ state, template, }: {
43
- state: {
44
- [key: string]: string;
45
- };
46
- template: TemplateType;
47
- }) => string;
48
- /**
49
- * Function to compose a prompt using a provided template and state.
50
- *
51
- * @param {Object} options - Object containing state and template information.
52
- * @param {State} options.state - The state object containing values to fill the template.
53
- * @param {TemplateType} options.template - The template to be used for composing the prompt.
54
- * @returns {string} The composed prompt output.
55
- */
56
- export declare const composePromptFromState: ({ state, template, }: {
57
- state: State;
58
- template: TemplateType;
59
- }) => string;
60
- /**
61
- * Adds a header to a body of text.
62
- *
63
- * This function takes a header string and a body string and returns a new string with the header prepended to the body.
64
- * If the body string is empty, the header is returned as is.
65
- *
66
- * @param {string} header - The header to add to the body.
67
- * @param {string} body - The body to which to add the header.
68
- * @returns {string} The body with the header prepended.
69
- *
70
- * @example
71
- * // Given a header and a body
72
- * const header = "Header";
73
- * const body = "Body";
74
- *
75
- * // Adding the header to the body will result in:
76
- * // "Header\nBody"
77
- * const text = addHeader(header, body);
78
- */
79
- export declare const addHeader: (header: string, body: string) => string;
80
- export declare const formatPosts: ({ messages, entities, conversationHeader, }: {
81
- messages: Memory[];
82
- entities: Entity[];
83
- conversationHeader?: boolean;
84
- }) => string;
85
- /**
86
- * Format messages into a string
87
- * @param {Object} params - The formatting parameters
88
- * @param {Memory[]} params.messages - List of messages to format
89
- * @param {Entity[]} params.entities - List of entities for name resolution
90
- * @returns {string} Formatted message string with timestamps and user information
91
- */
92
- export declare const formatMessages: ({ messages, entities, }: {
93
- messages: Memory[];
94
- entities: Entity[];
95
- }) => string;
96
- export declare const formatTimestamp: (messageDate: number) => string;
97
- /**
98
- * Parses key-value pairs from a simple XML structure within a given text.
99
- * It looks for an XML block (e.g., <response>...</response>) and extracts
100
- * text content from direct child elements (e.g., <key>value</key>).
101
- *
102
- * Note: This uses regex and is suitable for simple, predictable XML structures.
103
- * For complex XML, a proper parsing library is recommended.
104
- *
105
- * @typeParam T - The expected shape of the parsed result. Defaults to Record<string, unknown>.
106
- * @param text - The input text containing the XML structure.
107
- * @returns The parsed object cast to type T, or null if parsing fails.
108
- *
109
- * @example
110
- * interface MyResponse { thought: string; message: string; }
111
- * const result = parseKeyValueXml<MyResponse>(xmlText);
112
- * // result is MyResponse | null
113
- */
114
- export declare function parseKeyValueXml<T = Record<string, unknown>>(text: string): T | null;
115
- /**
116
- * Parses a JSON object from a given text. The function looks for a JSON block wrapped in triple backticks
117
- * with `json` language identifier, and if not found, it searches for an object pattern within the text.
118
- * It then attempts to parse the JSON string into a JavaScript object. If parsing is successful and the result
119
- * is an object (but not an array), it returns the object; otherwise, it tries to parse an array if the result
120
- * is an array, or returns null if parsing is unsuccessful or the result is neither an object nor an array.
121
- *
122
- * @param text - The input text from which to extract and parse the JSON object.
123
- * @returns An object parsed from the JSON string if successful; otherwise, null or the result of parsing an array.
124
- */
125
- export declare function parseJSONObjectFromText(text: string): Record<string, unknown> | null;
126
- /**
127
- * Normalizes a JSON-like string by correcting formatting issues:
128
- * - Removes extra spaces after '{' and before '}'.
129
- * - Wraps unquoted values in double quotes.
130
- * - Converts single-quoted values to double-quoted.
131
- * - Ensures consistency in key-value formatting.
132
- * - Normalizes mixed adjacent quote pairs.
133
- *
134
- * This is useful for cleaning up improperly formatted JSON strings
135
- * before parsing them into valid JSON.
136
- *
137
- * @param str - The JSON-like string to normalize.
138
- * @returns A properly formatted JSON string.
139
- */
140
- export declare const normalizeJsonString: (str: string) => string;
141
- /**
142
- * Truncate text to fit within the character limit, ensuring it ends at a complete sentence.
143
- */
144
- export declare function truncateToCompleteSentence(text: string, maxLength: number): string;
145
- export declare function splitChunks(content: string, chunkSize?: number, bleed?: number): Promise<string[]>;
146
- /**
147
- * Trims the provided text prompt to a specified token limit using a tokenizer model and type.
148
- */
149
- export declare function trimTokens(prompt: string, maxTokens: number, runtime: IAgentRuntime): Promise<string>;
150
- export declare function safeReplacer(): (_key: string, value: unknown) => unknown;
151
- /**
152
- * Parses a string to determine its boolean equivalent.
153
- *
154
- * Recognized affirmative values: "YES", "Y", "TRUE", "T", "1", "ON", "ENABLE"
155
- * Recognized negative values: "NO", "N", "FALSE", "F", "0", "OFF", "DISABLE"
156
- *
157
- * @param {string | undefined | null} value - The input text to parse
158
- * @returns {boolean} - Returns `true` for affirmative inputs, `false` for negative or unrecognized inputs
159
- */
160
- export declare function parseBooleanFromText(value: string | undefined | null): boolean;
161
- /**
162
- * Validates a UUID value.
163
- *
164
- * @param {unknown} value - The value to validate.
165
- * @returns {UUID | null} Returns the validated UUID value or null if validation fails.
166
- */
167
- export declare function validateUuid(value: unknown): UUID | null;
168
- /**
169
- * Converts a string or number to a UUID.
170
- *
171
- * @param {string | number} target - The string or number to convert to a UUID.
172
- * @returns {UUID} The UUID generated from the input target.
173
- * @throws {TypeError} Throws an error if the input target is not a string.
174
- */
175
- export declare function stringToUuid(target: string | number): UUID;
176
- /**
177
- * Pre-warm the SHA-1 cache with common values using WebCrypto
178
- * Call this during initialization to improve performance
179
- */
180
- export declare function prewarmUuidCache(values: string[]): Promise<void>;
181
- export declare const getContentTypeFromMimeType: (mimeType: string) => ContentType | undefined;
182
- export declare function getLocalServerUrl(path: string): string;
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAW,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAC3F,OAAO,EAAa,IAAI,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AA8BvD;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH;;;;;;;;;;GAUG;AACH,eAAO,MAAM,aAAa,GAAI,sBAG3B;IACD,KAAK,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAC;IACjC,QAAQ,EAAE,YAAY,CAAC;CACxB,WAKA,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,sBAAsB,GAAI,sBAGpC;IACD,KAAK,EAAE,KAAK,CAAC;IACb,QAAQ,EAAE,YAAY,CAAC;CACxB,WAiBA,CAAC;AAEF;;;;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