@inkeep/agents-run-api 0.39.5 → 0.41.0
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/_virtual/_raw_/home/runner/work/agents/agents/agents-run-api/templates/v1/phase1/system-prompt.js +5 -0
- package/dist/_virtual/_raw_/home/runner/work/agents/agents/agents-run-api/templates/v1/phase1/thinking-preparation.js +5 -0
- package/dist/_virtual/_raw_/home/runner/work/agents/agents/agents-run-api/templates/v1/phase1/tool.js +5 -0
- package/dist/_virtual/_raw_/home/runner/work/agents/agents/agents-run-api/templates/v1/phase2/data-component.js +5 -0
- package/dist/_virtual/_raw_/home/runner/work/agents/agents/agents-run-api/templates/v1/phase2/data-components.js +5 -0
- package/dist/_virtual/_raw_/home/runner/work/agents/agents/agents-run-api/templates/v1/phase2/system-prompt.js +5 -0
- package/dist/_virtual/_raw_/home/runner/work/agents/agents/agents-run-api/templates/v1/shared/artifact-retrieval-guidance.js +5 -0
- package/dist/_virtual/_raw_/home/runner/work/agents/agents/agents-run-api/templates/v1/shared/artifact.js +5 -0
- package/dist/a2a/client.d.ts +184 -0
- package/dist/a2a/client.js +510 -0
- package/dist/a2a/handlers.d.ts +7 -0
- package/dist/a2a/handlers.js +576 -0
- package/dist/a2a/transfer.d.ts +22 -0
- package/dist/a2a/transfer.js +46 -0
- package/dist/a2a/types.d.ts +79 -0
- package/dist/a2a/types.js +22 -0
- package/dist/agents/Agent.d.ts +268 -0
- package/dist/agents/Agent.js +1932 -0
- package/dist/agents/ModelFactory.d.ts +63 -0
- package/dist/agents/ModelFactory.js +194 -0
- package/dist/agents/SystemPromptBuilder.d.ts +21 -0
- package/dist/agents/SystemPromptBuilder.js +48 -0
- package/dist/agents/ToolSessionManager.d.ts +63 -0
- package/dist/agents/ToolSessionManager.js +146 -0
- package/dist/agents/generateTaskHandler.d.ts +49 -0
- package/dist/agents/generateTaskHandler.js +523 -0
- package/dist/agents/relationTools.d.ts +57 -0
- package/dist/agents/relationTools.js +262 -0
- package/dist/agents/types.d.ts +28 -0
- package/dist/agents/types.js +1 -0
- package/dist/agents/versions/v1/Phase1Config.d.ts +27 -0
- package/dist/agents/versions/v1/Phase1Config.js +424 -0
- package/dist/agents/versions/v1/Phase2Config.d.ts +31 -0
- package/dist/agents/versions/v1/Phase2Config.js +330 -0
- package/dist/constants/execution-limits/defaults.d.ts +51 -0
- package/dist/constants/execution-limits/defaults.js +52 -0
- package/dist/constants/execution-limits/index.d.ts +6 -0
- package/dist/constants/execution-limits/index.js +21 -0
- package/dist/create-app.d.ts +9 -0
- package/dist/create-app.js +195 -0
- package/dist/data/agent.d.ts +7 -0
- package/dist/data/agent.js +72 -0
- package/dist/data/agents.d.ts +34 -0
- package/dist/data/agents.js +139 -0
- package/dist/data/conversations.d.ts +128 -0
- package/dist/data/conversations.js +522 -0
- package/dist/data/db/dbClient.d.ts +6 -0
- package/dist/data/db/dbClient.js +17 -0
- package/dist/env.d.ts +57 -0
- package/dist/env.js +1 -2
- package/dist/handlers/executionHandler.d.ts +41 -0
- package/dist/handlers/executionHandler.js +457 -0
- package/dist/index.d.ts +8 -29
- package/dist/index.js +5 -11386
- package/dist/instrumentation.d.ts +1 -2
- package/dist/instrumentation.js +66 -3
- package/dist/{logger2.js → logger.d.ts} +1 -2
- package/dist/logger.js +1 -1
- package/dist/middleware/api-key-auth.d.ts +26 -0
- package/dist/middleware/api-key-auth.js +240 -0
- package/dist/middleware/index.d.ts +2 -0
- package/dist/middleware/index.js +3 -0
- package/dist/openapi.d.ts +4 -0
- package/dist/openapi.js +54 -0
- package/dist/routes/agents.d.ts +12 -0
- package/dist/routes/agents.js +147 -0
- package/dist/routes/chat.d.ts +13 -0
- package/dist/routes/chat.js +305 -0
- package/dist/routes/chatDataStream.d.ts +13 -0
- package/dist/routes/chatDataStream.js +365 -0
- package/dist/routes/mcp.d.ts +13 -0
- package/dist/routes/mcp.js +495 -0
- package/dist/services/AgentSession.d.ts +356 -0
- package/dist/services/AgentSession.js +1208 -0
- package/dist/services/ArtifactParser.d.ts +105 -0
- package/dist/services/ArtifactParser.js +338 -0
- package/dist/services/ArtifactService.d.ts +123 -0
- package/dist/services/ArtifactService.js +612 -0
- package/dist/services/BaseCompressor.d.ts +183 -0
- package/dist/services/BaseCompressor.js +500 -0
- package/dist/services/ConversationCompressor.d.ts +32 -0
- package/dist/services/ConversationCompressor.js +91 -0
- package/dist/services/IncrementalStreamParser.d.ts +98 -0
- package/dist/services/IncrementalStreamParser.js +327 -0
- package/dist/services/MidGenerationCompressor.d.ts +63 -0
- package/dist/services/MidGenerationCompressor.js +104 -0
- package/dist/services/PendingToolApprovalManager.d.ts +62 -0
- package/dist/services/PendingToolApprovalManager.js +133 -0
- package/dist/services/ResponseFormatter.d.ts +39 -0
- package/dist/services/ResponseFormatter.js +152 -0
- package/dist/tools/NativeSandboxExecutor.d.ts +38 -0
- package/dist/tools/NativeSandboxExecutor.js +432 -0
- package/dist/tools/SandboxExecutorFactory.d.ts +36 -0
- package/dist/tools/SandboxExecutorFactory.js +80 -0
- package/dist/tools/VercelSandboxExecutor.d.ts +71 -0
- package/dist/tools/VercelSandboxExecutor.js +340 -0
- package/dist/tools/distill-conversation-history-tool.d.ts +62 -0
- package/dist/tools/distill-conversation-history-tool.js +206 -0
- package/dist/tools/distill-conversation-tool.d.ts +41 -0
- package/dist/tools/distill-conversation-tool.js +141 -0
- package/dist/tools/sandbox-utils.d.ts +18 -0
- package/dist/tools/sandbox-utils.js +53 -0
- package/dist/types/chat.d.ts +27 -0
- package/dist/types/chat.js +1 -0
- package/dist/types/execution-context.d.ts +46 -0
- package/dist/types/execution-context.js +27 -0
- package/dist/types/xml.d.ts +5 -0
- package/dist/utils/SchemaProcessor.d.ts +52 -0
- package/dist/utils/SchemaProcessor.js +182 -0
- package/dist/utils/agent-operations.d.ts +62 -0
- package/dist/utils/agent-operations.js +53 -0
- package/dist/utils/artifact-component-schema.d.ts +42 -0
- package/dist/utils/artifact-component-schema.js +186 -0
- package/dist/utils/cleanup.d.ts +21 -0
- package/dist/utils/cleanup.js +59 -0
- package/dist/utils/data-component-schema.d.ts +2 -0
- package/dist/utils/data-component-schema.js +3 -0
- package/dist/utils/default-status-schemas.d.ts +20 -0
- package/dist/utils/default-status-schemas.js +24 -0
- package/dist/utils/json-postprocessor.d.ts +13 -0
- package/dist/{json-postprocessor.cjs → utils/json-postprocessor.js} +2 -3
- package/dist/utils/model-context-utils.d.ts +39 -0
- package/dist/utils/model-context-utils.js +181 -0
- package/dist/utils/model-resolver.d.ts +6 -0
- package/dist/utils/model-resolver.js +34 -0
- package/dist/utils/schema-validation.d.ts +44 -0
- package/dist/utils/schema-validation.js +97 -0
- package/dist/utils/stream-helpers.d.ts +197 -0
- package/dist/utils/stream-helpers.js +518 -0
- package/dist/utils/stream-registry.d.ts +22 -0
- package/dist/utils/stream-registry.js +34 -0
- package/dist/utils/token-estimator.d.ts +69 -0
- package/dist/utils/token-estimator.js +53 -0
- package/dist/utils/tracer.d.ts +7 -0
- package/dist/utils/tracer.js +7 -0
- package/package.json +10 -26
- package/dist/SandboxExecutorFactory.cjs +0 -895
- package/dist/SandboxExecutorFactory.js +0 -893
- package/dist/SandboxExecutorFactory.js.map +0 -1
- package/dist/chunk-VBDAOXYI.cjs +0 -927
- package/dist/chunk-VBDAOXYI.js +0 -832
- package/dist/chunk-VBDAOXYI.js.map +0 -1
- package/dist/chunk.cjs +0 -34
- package/dist/conversations.cjs +0 -7
- package/dist/conversations.js +0 -7
- package/dist/conversations2.cjs +0 -209
- package/dist/conversations2.js +0 -180
- package/dist/conversations2.js.map +0 -1
- package/dist/dbClient.cjs +0 -9676
- package/dist/dbClient.js +0 -9670
- package/dist/dbClient.js.map +0 -1
- package/dist/dbClient2.cjs +0 -5
- package/dist/dbClient2.js +0 -5
- package/dist/env.cjs +0 -59
- package/dist/env.js.map +0 -1
- package/dist/execution-limits.cjs +0 -260
- package/dist/execution-limits.js +0 -63
- package/dist/execution-limits.js.map +0 -1
- package/dist/index.cjs +0 -11411
- package/dist/index.d.cts +0 -36
- package/dist/index.d.cts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/instrumentation.cjs +0 -12
- package/dist/instrumentation.d.cts +0 -18
- package/dist/instrumentation.d.cts.map +0 -1
- package/dist/instrumentation.d.ts.map +0 -1
- package/dist/instrumentation2.cjs +0 -116
- package/dist/instrumentation2.js +0 -69
- package/dist/instrumentation2.js.map +0 -1
- package/dist/json-postprocessor.js +0 -20
- package/dist/json-postprocessor.js.map +0 -1
- package/dist/logger.cjs +0 -5
- package/dist/logger2.cjs +0 -1
- package/dist/nodefs.cjs +0 -29
- package/dist/nodefs.js +0 -27
- package/dist/nodefs.js.map +0 -1
- package/dist/opfs-ahp.cjs +0 -367
- package/dist/opfs-ahp.js +0 -368
- package/dist/opfs-ahp.js.map +0 -1
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
//#region src/utils/schema-validation.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Clear the validator cache to free memory
|
|
4
|
+
* Useful for testing or when memory usage becomes a concern
|
|
5
|
+
*/
|
|
6
|
+
declare function clearValidatorCache(): void;
|
|
7
|
+
/**
|
|
8
|
+
* Get the current cache size for monitoring
|
|
9
|
+
*/
|
|
10
|
+
declare function getValidatorCacheSize(): number;
|
|
11
|
+
/**
|
|
12
|
+
* Extended JSON Schema that includes preview field indicators
|
|
13
|
+
*/
|
|
14
|
+
interface ExtendedJsonSchema {
|
|
15
|
+
type: string;
|
|
16
|
+
properties?: Record<string, ExtendedJsonSchemaProperty>;
|
|
17
|
+
required?: string[];
|
|
18
|
+
[key: string]: any;
|
|
19
|
+
}
|
|
20
|
+
interface ExtendedJsonSchemaProperty {
|
|
21
|
+
type: string;
|
|
22
|
+
description?: string;
|
|
23
|
+
inPreview?: boolean;
|
|
24
|
+
[key: string]: any;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Validate that a schema is valid (either JSON Schema or Zod)
|
|
28
|
+
* Following the same pattern as context validation
|
|
29
|
+
*/
|
|
30
|
+
declare function validateComponentSchema(schema: any, componentName: string): {
|
|
31
|
+
isValid: boolean;
|
|
32
|
+
error?: string;
|
|
33
|
+
validatedSchema?: ExtendedJsonSchema;
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* Extract preview fields from a schema (fields marked with inPreview: true)
|
|
37
|
+
*/
|
|
38
|
+
declare function extractPreviewFields(schema: ExtendedJsonSchema): Record<string, any>;
|
|
39
|
+
/**
|
|
40
|
+
* Extract full fields from a schema (all fields, with inPreview flags removed)
|
|
41
|
+
*/
|
|
42
|
+
declare function extractFullFields(schema: ExtendedJsonSchema): Record<string, any>;
|
|
43
|
+
//#endregion
|
|
44
|
+
export { ExtendedJsonSchema, ExtendedJsonSchemaProperty, clearValidatorCache, extractFullFields, extractPreviewFields, getValidatorCacheSize, validateComponentSchema };
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { getLogger } from "../logger.js";
|
|
2
|
+
import { z } from "@hono/zod-openapi";
|
|
3
|
+
import { convertZodToJsonSchemaWithPreview } from "@inkeep/agents-core/utils/schema-conversion";
|
|
4
|
+
import Ajv from "ajv";
|
|
5
|
+
|
|
6
|
+
//#region src/utils/schema-validation.ts
|
|
7
|
+
const logger = getLogger("SchemaValidation");
|
|
8
|
+
const ajv = new Ajv({
|
|
9
|
+
allErrors: true,
|
|
10
|
+
strict: false
|
|
11
|
+
});
|
|
12
|
+
const validatorCache = /* @__PURE__ */ new Map();
|
|
13
|
+
/**
|
|
14
|
+
* Clear the validator cache to free memory
|
|
15
|
+
* Useful for testing or when memory usage becomes a concern
|
|
16
|
+
*/
|
|
17
|
+
function clearValidatorCache() {
|
|
18
|
+
validatorCache.clear();
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Get the current cache size for monitoring
|
|
22
|
+
*/
|
|
23
|
+
function getValidatorCacheSize() {
|
|
24
|
+
return validatorCache.size;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Validate that a schema is valid (either JSON Schema or Zod)
|
|
28
|
+
* Following the same pattern as context validation
|
|
29
|
+
*/
|
|
30
|
+
function validateComponentSchema(schema, componentName) {
|
|
31
|
+
try {
|
|
32
|
+
if (schema instanceof z.ZodType) return {
|
|
33
|
+
isValid: true,
|
|
34
|
+
validatedSchema: convertZodToJsonSchemaWithPreview(schema)
|
|
35
|
+
};
|
|
36
|
+
if (!schema || typeof schema !== "object" || Array.isArray(schema)) return {
|
|
37
|
+
isValid: false,
|
|
38
|
+
error: "Schema must be a valid JSON Schema object or Zod schema"
|
|
39
|
+
};
|
|
40
|
+
const schemaKey = JSON.stringify(schema);
|
|
41
|
+
let validator = validatorCache.get(schemaKey);
|
|
42
|
+
if (!validator) {
|
|
43
|
+
validator = ajv.compile(schema);
|
|
44
|
+
validatorCache.set(schemaKey, validator);
|
|
45
|
+
}
|
|
46
|
+
return {
|
|
47
|
+
isValid: true,
|
|
48
|
+
validatedSchema: schema
|
|
49
|
+
};
|
|
50
|
+
} catch (error) {
|
|
51
|
+
logger.error({
|
|
52
|
+
componentName,
|
|
53
|
+
error: error instanceof Error ? error.message : "Unknown error"
|
|
54
|
+
}, "Invalid component schema");
|
|
55
|
+
return {
|
|
56
|
+
isValid: false,
|
|
57
|
+
error: error instanceof Error ? error.message : "Invalid JSON Schema"
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Extract preview fields from a schema (fields marked with inPreview: true)
|
|
63
|
+
*/
|
|
64
|
+
function extractPreviewFields(schema) {
|
|
65
|
+
const previewProperties = {};
|
|
66
|
+
if (schema.properties) {
|
|
67
|
+
for (const [key, prop] of Object.entries(schema.properties)) if (prop.inPreview === true) {
|
|
68
|
+
const cleanProp = { ...prop };
|
|
69
|
+
delete cleanProp.inPreview;
|
|
70
|
+
previewProperties[key] = cleanProp;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return {
|
|
74
|
+
type: "object",
|
|
75
|
+
properties: previewProperties,
|
|
76
|
+
required: schema.required?.filter((field) => previewProperties[field])
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Extract full fields from a schema (all fields, with inPreview flags removed)
|
|
81
|
+
*/
|
|
82
|
+
function extractFullFields(schema) {
|
|
83
|
+
const fullProperties = {};
|
|
84
|
+
if (schema.properties) for (const [key, prop] of Object.entries(schema.properties)) {
|
|
85
|
+
const cleanProp = { ...prop };
|
|
86
|
+
delete cleanProp.inPreview;
|
|
87
|
+
fullProperties[key] = cleanProp;
|
|
88
|
+
}
|
|
89
|
+
return {
|
|
90
|
+
type: "object",
|
|
91
|
+
properties: fullProperties,
|
|
92
|
+
required: schema.required
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
//#endregion
|
|
97
|
+
export { clearValidatorCache, extractFullFields, extractPreviewFields, getValidatorCacheSize, validateComponentSchema };
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import { ErrorEvent, OperationEvent } from "./agent-operations.js";
|
|
2
|
+
import { SummaryEvent } from "@inkeep/agents-core";
|
|
3
|
+
|
|
4
|
+
//#region src/utils/stream-helpers.d.ts
|
|
5
|
+
interface StreamHelper {
|
|
6
|
+
writeRole(role?: string): Promise<void>;
|
|
7
|
+
writeContent(content: string): Promise<void>;
|
|
8
|
+
streamData(data: any): Promise<void>;
|
|
9
|
+
streamText(text: string, delayMs?: number): Promise<void>;
|
|
10
|
+
writeError(error: string | ErrorEvent): Promise<void>;
|
|
11
|
+
complete(): Promise<void>;
|
|
12
|
+
writeData(type: string, data: any): Promise<void>;
|
|
13
|
+
writeOperation(operation: OperationEvent): Promise<void>;
|
|
14
|
+
writeSummary(summary: SummaryEvent): Promise<void>;
|
|
15
|
+
}
|
|
16
|
+
interface HonoSSEStream {
|
|
17
|
+
writeSSE(message: {
|
|
18
|
+
data: string;
|
|
19
|
+
event?: string;
|
|
20
|
+
id?: string;
|
|
21
|
+
}): Promise<void>;
|
|
22
|
+
sleep(ms: number): Promise<unknown>;
|
|
23
|
+
}
|
|
24
|
+
interface ChatCompletionChunk {
|
|
25
|
+
id: string;
|
|
26
|
+
object: string;
|
|
27
|
+
created: number;
|
|
28
|
+
model: string;
|
|
29
|
+
choices: Array<{
|
|
30
|
+
index: number;
|
|
31
|
+
delta: {
|
|
32
|
+
role?: string;
|
|
33
|
+
content?: string;
|
|
34
|
+
};
|
|
35
|
+
finish_reason: string | null;
|
|
36
|
+
}>;
|
|
37
|
+
}
|
|
38
|
+
declare class SSEStreamHelper implements StreamHelper {
|
|
39
|
+
private stream;
|
|
40
|
+
private requestId;
|
|
41
|
+
private timestamp;
|
|
42
|
+
private isTextStreaming;
|
|
43
|
+
private queuedEvents;
|
|
44
|
+
constructor(stream: HonoSSEStream, requestId: string, timestamp: number);
|
|
45
|
+
/**
|
|
46
|
+
* Write the initial role message
|
|
47
|
+
*/
|
|
48
|
+
writeRole(role?: string): Promise<void>;
|
|
49
|
+
/**
|
|
50
|
+
* Write content chunk
|
|
51
|
+
*/
|
|
52
|
+
writeContent(content: string): Promise<void>;
|
|
53
|
+
/**
|
|
54
|
+
* Stream text word by word with optional delay
|
|
55
|
+
*/
|
|
56
|
+
streamText(text: string, delayMs?: number): Promise<void>;
|
|
57
|
+
streamData(data: any): Promise<void>;
|
|
58
|
+
/**
|
|
59
|
+
* Write error message or error event
|
|
60
|
+
*/
|
|
61
|
+
writeError(error: string | ErrorEvent): Promise<void>;
|
|
62
|
+
/**
|
|
63
|
+
* Write the final completion message
|
|
64
|
+
*/
|
|
65
|
+
writeCompletion(finishReason?: string): Promise<void>;
|
|
66
|
+
writeData(type: string, data: any): Promise<void>;
|
|
67
|
+
writeSummary(summary: SummaryEvent): Promise<void>;
|
|
68
|
+
writeOperation(operation: OperationEvent): Promise<void>;
|
|
69
|
+
/**
|
|
70
|
+
* Flush all queued operations in order after text streaming completes
|
|
71
|
+
*/
|
|
72
|
+
private flushQueuedOperations;
|
|
73
|
+
/**
|
|
74
|
+
* Write the final [DONE] message
|
|
75
|
+
*/
|
|
76
|
+
writeDone(): Promise<void>;
|
|
77
|
+
/**
|
|
78
|
+
* Complete the stream with finish reason and done message
|
|
79
|
+
*/
|
|
80
|
+
complete(finishReason?: string): Promise<void>;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Factory function to create SSE stream helper
|
|
84
|
+
*/
|
|
85
|
+
declare function createSSEStreamHelper(stream: HonoSSEStream, requestId: string, timestamp: number): SSEStreamHelper;
|
|
86
|
+
interface VercelUIWriter {
|
|
87
|
+
write(chunk: any): void;
|
|
88
|
+
merge(stream: any): void;
|
|
89
|
+
onError?: (error: Error) => void;
|
|
90
|
+
}
|
|
91
|
+
declare class VercelDataStreamHelper implements StreamHelper {
|
|
92
|
+
private writer;
|
|
93
|
+
private textId;
|
|
94
|
+
private jsonBuffer;
|
|
95
|
+
private sentItems;
|
|
96
|
+
private completedItems;
|
|
97
|
+
private sessionId?;
|
|
98
|
+
private static readonly MAX_BUFFER_SIZE;
|
|
99
|
+
private isCompleted;
|
|
100
|
+
private isTextStreaming;
|
|
101
|
+
private queuedEvents;
|
|
102
|
+
private lastTextEndTimestamp;
|
|
103
|
+
private connectionDropTimer?;
|
|
104
|
+
constructor(writer: VercelUIWriter);
|
|
105
|
+
setSessionId(sessionId: string): void;
|
|
106
|
+
writeRole(_?: string): Promise<void>;
|
|
107
|
+
writeContent(content: string): Promise<void>;
|
|
108
|
+
streamText(text: string, delayMs?: number): Promise<void>;
|
|
109
|
+
writeData(type: string, data: any): Promise<void>;
|
|
110
|
+
writeError(error: string | ErrorEvent): Promise<void>;
|
|
111
|
+
streamData(data: any): Promise<void>;
|
|
112
|
+
mergeStream(stream: any): Promise<void>;
|
|
113
|
+
/**
|
|
114
|
+
* Clean up all memory allocations
|
|
115
|
+
* Should be called when the stream helper is no longer needed
|
|
116
|
+
*/
|
|
117
|
+
cleanup(): void;
|
|
118
|
+
/**
|
|
119
|
+
* JSON-aware buffer truncation that preserves complete JSON structures
|
|
120
|
+
*/
|
|
121
|
+
private truncateJsonBufferSafely;
|
|
122
|
+
/**
|
|
123
|
+
* Reindex sent items after buffer truncation
|
|
124
|
+
*/
|
|
125
|
+
private reindexSentItems;
|
|
126
|
+
/**
|
|
127
|
+
* Force cleanup on connection drop or timeout
|
|
128
|
+
*/
|
|
129
|
+
private forceCleanup;
|
|
130
|
+
/**
|
|
131
|
+
* Check if the stream has been completed and cleaned up
|
|
132
|
+
*/
|
|
133
|
+
isStreamCompleted(): boolean;
|
|
134
|
+
/**
|
|
135
|
+
* Get current memory usage stats (for debugging/monitoring)
|
|
136
|
+
*/
|
|
137
|
+
getMemoryStats(): {
|
|
138
|
+
bufferSize: number;
|
|
139
|
+
sentItemsCount: number;
|
|
140
|
+
completedItemsCount: number;
|
|
141
|
+
isCompleted: boolean;
|
|
142
|
+
};
|
|
143
|
+
writeSummary(summary: SummaryEvent): Promise<void>;
|
|
144
|
+
writeOperation(operation: OperationEvent): Promise<void>;
|
|
145
|
+
/**
|
|
146
|
+
* Flush all queued operations in order after text streaming completes
|
|
147
|
+
*/
|
|
148
|
+
private flushQueuedOperations;
|
|
149
|
+
writeCompletion(_finishReason?: string): Promise<void>;
|
|
150
|
+
writeDone(): Promise<void>;
|
|
151
|
+
/**
|
|
152
|
+
* Complete the stream and clean up all memory
|
|
153
|
+
* This is the primary cleanup point to prevent memory leaks between requests
|
|
154
|
+
*/
|
|
155
|
+
complete(): Promise<void>;
|
|
156
|
+
}
|
|
157
|
+
declare function createVercelStreamHelper(writer: VercelUIWriter): VercelDataStreamHelper;
|
|
158
|
+
/**
|
|
159
|
+
* Buffering Stream Helper that captures content instead of streaming
|
|
160
|
+
* Used for MCP tool responses and non-streaming API responses that require a single complete message
|
|
161
|
+
*/
|
|
162
|
+
declare class BufferingStreamHelper implements StreamHelper {
|
|
163
|
+
private capturedText;
|
|
164
|
+
private capturedData;
|
|
165
|
+
private capturedOperations;
|
|
166
|
+
private capturedSummaries;
|
|
167
|
+
private hasError;
|
|
168
|
+
private errorMessage;
|
|
169
|
+
private sessionId?;
|
|
170
|
+
setSessionId(sessionId: string): void;
|
|
171
|
+
writeRole(_role?: string): Promise<void>;
|
|
172
|
+
writeContent(content: string): Promise<void>;
|
|
173
|
+
streamText(text: string, _delayMs?: number): Promise<void>;
|
|
174
|
+
streamData(data: any): Promise<void>;
|
|
175
|
+
streamSummary(summary: SummaryEvent): Promise<void>;
|
|
176
|
+
streamOperation(operation: OperationEvent): Promise<void>;
|
|
177
|
+
writeData(_type: string, data: any): Promise<void>;
|
|
178
|
+
writeSummary(summary: SummaryEvent): Promise<void>;
|
|
179
|
+
writeOperation(operation: OperationEvent): Promise<void>;
|
|
180
|
+
writeError(error: string | ErrorEvent): Promise<void>;
|
|
181
|
+
complete(): Promise<void>;
|
|
182
|
+
/**
|
|
183
|
+
* Get the captured response for non-streaming output
|
|
184
|
+
*/
|
|
185
|
+
getCapturedResponse(): {
|
|
186
|
+
text: string;
|
|
187
|
+
data: any[];
|
|
188
|
+
operations: OperationEvent[];
|
|
189
|
+
hasError: boolean;
|
|
190
|
+
errorMessage: string;
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
declare function createBufferingStreamHelper(): BufferingStreamHelper;
|
|
194
|
+
declare const createMCPStreamHelper: typeof createBufferingStreamHelper;
|
|
195
|
+
type MCPStreamHelper = BufferingStreamHelper;
|
|
196
|
+
//#endregion
|
|
197
|
+
export { BufferingStreamHelper, ChatCompletionChunk, HonoSSEStream, MCPStreamHelper, SSEStreamHelper, StreamHelper, VercelDataStreamHelper, VercelUIWriter, createBufferingStreamHelper, createMCPStreamHelper, createSSEStreamHelper, createVercelStreamHelper };
|