@superblocksteam/vite-plugin-file-sync 2.0.59-next.1 → 2.0.59-next.10
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/ai-service/agent/prompts/build-base-system-prompt.d.ts.map +1 -1
- package/dist/ai-service/agent/prompts/build-base-system-prompt.js +25 -9
- package/dist/ai-service/agent/prompts/build-base-system-prompt.js.map +1 -1
- package/dist/ai-service/agent/subagents/apis/examples.d.ts.map +1 -1
- package/dist/ai-service/agent/subagents/apis/examples.js +137 -10
- package/dist/ai-service/agent/subagents/apis/examples.js.map +1 -1
- package/dist/ai-service/agent/subagents/apis/static-analysis.d.ts.map +1 -1
- package/dist/ai-service/agent/subagents/apis/static-analysis.js +14 -7
- package/dist/ai-service/agent/subagents/apis/static-analysis.js.map +1 -1
- package/dist/ai-service/agent/tool-message-utils.d.ts.map +1 -1
- package/dist/ai-service/agent/tool-message-utils.js +6 -2
- package/dist/ai-service/agent/tool-message-utils.js.map +1 -1
- package/dist/ai-service/agent/tools/apis/analysis.d.ts +9 -0
- package/dist/ai-service/agent/tools/apis/analysis.d.ts.map +1 -0
- package/dist/ai-service/agent/tools/apis/analysis.js +358 -0
- package/dist/ai-service/agent/tools/apis/analysis.js.map +1 -0
- package/dist/ai-service/agent/{subagents → tools}/apis/api-executor.d.ts +35 -10
- package/dist/ai-service/agent/tools/apis/api-executor.d.ts.map +1 -0
- package/dist/ai-service/agent/{subagents → tools}/apis/api-executor.js +179 -94
- package/dist/ai-service/agent/tools/apis/api-executor.js.map +1 -0
- package/dist/ai-service/agent/tools/apis/api-source.d.ts +19 -0
- package/dist/ai-service/agent/tools/apis/api-source.d.ts.map +1 -0
- package/dist/ai-service/agent/tools/apis/api-source.js +73 -0
- package/dist/ai-service/agent/tools/apis/api-source.js.map +1 -0
- package/dist/ai-service/agent/tools/apis/api-validation-orchestrator.d.ts +51 -0
- package/dist/ai-service/agent/tools/apis/api-validation-orchestrator.d.ts.map +1 -0
- package/dist/ai-service/agent/tools/apis/api-validation-orchestrator.js +510 -0
- package/dist/ai-service/agent/tools/apis/api-validation-orchestrator.js.map +1 -0
- package/dist/ai-service/agent/tools/apis/build-api-artifact.d.ts +32 -0
- package/dist/ai-service/agent/tools/apis/build-api-artifact.d.ts.map +1 -0
- package/dist/ai-service/agent/tools/apis/build-api-artifact.js +313 -0
- package/dist/ai-service/agent/tools/apis/build-api-artifact.js.map +1 -0
- package/dist/ai-service/agent/tools/apis/build-api.d.ts +1 -10
- package/dist/ai-service/agent/tools/apis/build-api.d.ts.map +1 -1
- package/dist/ai-service/agent/tools/apis/build-api.js +26 -238
- package/dist/ai-service/agent/tools/apis/build-api.js.map +1 -1
- package/dist/ai-service/agent/tools/apis/get-api-docs.d.ts +11 -0
- package/dist/ai-service/agent/tools/apis/get-api-docs.d.ts.map +1 -0
- package/dist/ai-service/agent/tools/apis/get-api-docs.js +1841 -0
- package/dist/ai-service/agent/tools/apis/get-api-docs.js.map +1 -0
- package/dist/ai-service/agent/tools/apis/integration-types.d.ts +37 -0
- package/dist/ai-service/agent/tools/apis/integration-types.d.ts.map +1 -0
- package/dist/ai-service/agent/tools/apis/integration-types.js +689 -0
- package/dist/ai-service/agent/tools/apis/integration-types.js.map +1 -0
- package/dist/ai-service/agent/tools/apis/test-api.d.ts +25 -0
- package/dist/ai-service/agent/tools/apis/test-api.d.ts.map +1 -0
- package/dist/ai-service/agent/tools/apis/test-api.js +194 -0
- package/dist/ai-service/agent/tools/apis/test-api.js.map +1 -0
- package/dist/ai-service/agent/tools/apis/write-api.d.ts +11 -0
- package/dist/ai-service/agent/tools/apis/write-api.d.ts.map +1 -0
- package/dist/ai-service/agent/tools/apis/write-api.js +41 -0
- package/dist/ai-service/agent/tools/apis/write-api.js.map +1 -0
- package/dist/ai-service/agent/tools/build-read-files.js +2 -2
- package/dist/ai-service/agent/tools/build-read-files.js.map +1 -1
- package/dist/ai-service/agent/tools.d.ts +2 -5
- package/dist/ai-service/agent/tools.d.ts.map +1 -1
- package/dist/ai-service/agent/tools.js +51 -22
- package/dist/ai-service/agent/tools.js.map +1 -1
- package/dist/ai-service/agent/tools2/access-control.d.ts +1 -0
- package/dist/ai-service/agent/tools2/access-control.d.ts.map +1 -1
- package/dist/ai-service/agent/tools2/access-control.js +15 -13
- package/dist/ai-service/agent/tools2/access-control.js.map +1 -1
- package/dist/ai-service/agent/tools2/registry.d.ts +2 -1
- package/dist/ai-service/agent/tools2/registry.d.ts.map +1 -1
- package/dist/ai-service/agent/tools2/registry.js +4 -3
- package/dist/ai-service/agent/tools2/registry.js.map +1 -1
- package/dist/ai-service/agent/tools2/tools/exit-plan-mode.d.ts.map +1 -1
- package/dist/ai-service/agent/tools2/tools/exit-plan-mode.js +73 -127
- package/dist/ai-service/agent/tools2/tools/exit-plan-mode.js.map +1 -1
- package/dist/ai-service/agent/tools2/tools/grep-metadata.d.ts.map +1 -1
- package/dist/ai-service/agent/tools2/tools/grep-metadata.js +25 -4
- package/dist/ai-service/agent/tools2/tools/grep-metadata.js.map +1 -1
- package/dist/ai-service/agent/tools2/types.d.ts +1 -1
- package/dist/ai-service/agent/tools2/types.d.ts.map +1 -1
- package/dist/ai-service/agent/tools2/types.js.map +1 -1
- package/dist/ai-service/agent/tools2/utils.d.ts.map +1 -1
- package/dist/ai-service/agent/tools2/utils.js +4 -1
- package/dist/ai-service/agent/tools2/utils.js.map +1 -1
- package/dist/ai-service/agent/utils.d.ts +1 -3
- package/dist/ai-service/agent/utils.d.ts.map +1 -1
- package/dist/ai-service/agent/utils.js +55 -13
- package/dist/ai-service/agent/utils.js.map +1 -1
- package/dist/ai-service/app-interface/shell.d.ts +5 -0
- package/dist/ai-service/app-interface/shell.d.ts.map +1 -1
- package/dist/ai-service/app-interface/shell.js +17 -2
- package/dist/ai-service/app-interface/shell.js.map +1 -1
- package/dist/ai-service/chat/chat-session-store.d.ts +7 -0
- package/dist/ai-service/chat/chat-session-store.d.ts.map +1 -1
- package/dist/ai-service/chat/chat-session-store.js +26 -0
- package/dist/ai-service/chat/chat-session-store.js.map +1 -1
- package/dist/ai-service/const.d.ts +3 -1
- package/dist/ai-service/const.d.ts.map +1 -1
- package/dist/ai-service/const.js +3 -0
- package/dist/ai-service/const.js.map +1 -1
- package/dist/ai-service/index.d.ts +5 -1
- package/dist/ai-service/index.d.ts.map +1 -1
- package/dist/ai-service/index.js +55 -7
- package/dist/ai-service/index.js.map +1 -1
- package/dist/ai-service/integrations/metadata-storage/index.d.ts +10 -0
- package/dist/ai-service/integrations/metadata-storage/index.d.ts.map +1 -1
- package/dist/ai-service/integrations/metadata-storage/local.d.ts +4 -2
- package/dist/ai-service/integrations/metadata-storage/local.d.ts.map +1 -1
- package/dist/ai-service/integrations/metadata-storage/local.js +35 -9
- package/dist/ai-service/integrations/metadata-storage/local.js.map +1 -1
- package/dist/ai-service/integrations/store.d.ts +27 -2
- package/dist/ai-service/integrations/store.d.ts.map +1 -1
- package/dist/ai-service/integrations/store.js +129 -62
- package/dist/ai-service/integrations/store.js.map +1 -1
- package/dist/ai-service/llm/client.d.ts +123 -0
- package/dist/ai-service/llm/client.d.ts.map +1 -0
- package/dist/ai-service/llm/client.js +168 -0
- package/dist/ai-service/llm/client.js.map +1 -0
- package/dist/ai-service/llm/context/context-handle.d.ts +4 -4
- package/dist/ai-service/llm/context/context-handle.d.ts.map +1 -1
- package/dist/ai-service/llm/context/context-handle.js +7 -3
- package/dist/ai-service/llm/context/context-handle.js.map +1 -1
- package/dist/ai-service/llm/context/context.d.ts +28 -0
- package/dist/ai-service/llm/context/context.d.ts.map +1 -1
- package/dist/ai-service/llm/context/context.js +119 -0
- package/dist/ai-service/llm/context/context.js.map +1 -1
- package/dist/ai-service/llm/context/manager.d.ts +22 -2
- package/dist/ai-service/llm/context/manager.d.ts.map +1 -1
- package/dist/ai-service/llm/context/manager.js +86 -13
- package/dist/ai-service/llm/context/manager.js.map +1 -1
- package/dist/ai-service/llm/context/storage/index.d.ts +1 -0
- package/dist/ai-service/llm/context/storage/index.d.ts.map +1 -1
- package/dist/ai-service/llm/context/storage/local.d.ts +1 -0
- package/dist/ai-service/llm/context/storage/local.d.ts.map +1 -1
- package/dist/ai-service/llm/context/storage/local.js +13 -1
- package/dist/ai-service/llm/context/storage/local.js.map +1 -1
- package/dist/ai-service/llm/context/utils/message-utils.d.ts.map +1 -1
- package/dist/ai-service/llm/context/utils/message-utils.js +6 -2
- package/dist/ai-service/llm/context/utils/message-utils.js.map +1 -1
- package/dist/ai-service/llm/error.d.ts +14 -4
- package/dist/ai-service/llm/error.d.ts.map +1 -1
- package/dist/ai-service/llm/error.js +49 -4
- package/dist/ai-service/llm/error.js.map +1 -1
- package/dist/ai-service/llm/interaction/adapters/vercel.d.ts +67 -0
- package/dist/ai-service/llm/interaction/adapters/vercel.d.ts.map +1 -0
- package/dist/ai-service/llm/interaction/adapters/vercel.js +111 -0
- package/dist/ai-service/llm/interaction/adapters/vercel.js.map +1 -0
- package/dist/ai-service/llm/interaction/compose.d.ts +71 -0
- package/dist/ai-service/llm/interaction/compose.d.ts.map +1 -0
- package/dist/ai-service/llm/interaction/compose.js +88 -0
- package/dist/ai-service/llm/interaction/compose.js.map +1 -0
- package/dist/ai-service/llm/interaction/index.d.ts +68 -0
- package/dist/ai-service/llm/interaction/index.d.ts.map +1 -0
- package/dist/ai-service/llm/interaction/index.js +70 -0
- package/dist/ai-service/llm/interaction/index.js.map +1 -0
- package/dist/ai-service/llm/interaction/middleware.d.ts +52 -0
- package/dist/ai-service/llm/interaction/middleware.d.ts.map +1 -0
- package/dist/ai-service/llm/interaction/middleware.js +17 -0
- package/dist/ai-service/llm/interaction/middleware.js.map +1 -0
- package/dist/ai-service/llm/interaction/middlewares/llmobs.d.ts +45 -0
- package/dist/ai-service/llm/interaction/middlewares/llmobs.d.ts.map +1 -0
- package/dist/ai-service/llm/interaction/middlewares/llmobs.js +85 -0
- package/dist/ai-service/llm/interaction/middlewares/llmobs.js.map +1 -0
- package/dist/ai-service/llm/interaction/middlewares/logging.d.ts +88 -0
- package/dist/ai-service/llm/interaction/middlewares/logging.d.ts.map +1 -0
- package/dist/ai-service/llm/interaction/middlewares/logging.js +238 -0
- package/dist/ai-service/llm/interaction/middlewares/logging.js.map +1 -0
- package/dist/ai-service/llm/interaction/middlewares/profiler.d.ts +47 -0
- package/dist/ai-service/llm/interaction/middlewares/profiler.d.ts.map +1 -0
- package/dist/ai-service/llm/interaction/middlewares/profiler.js +183 -0
- package/dist/ai-service/llm/interaction/middlewares/profiler.js.map +1 -0
- package/dist/ai-service/llm/interaction/middlewares/stream-retry.d.ts +121 -0
- package/dist/ai-service/llm/interaction/middlewares/stream-retry.d.ts.map +1 -0
- package/dist/ai-service/llm/interaction/middlewares/stream-retry.js +291 -0
- package/dist/ai-service/llm/interaction/middlewares/stream-retry.js.map +1 -0
- package/dist/ai-service/llm/interaction/provider.d.ts +173 -0
- package/dist/ai-service/llm/interaction/provider.d.ts.map +1 -0
- package/dist/ai-service/llm/interaction/provider.js +15 -0
- package/dist/ai-service/llm/interaction/provider.js.map +1 -0
- package/dist/ai-service/llm/interaction/result-utils.d.ts +43 -0
- package/dist/ai-service/llm/interaction/result-utils.d.ts.map +1 -0
- package/dist/ai-service/llm/interaction/result-utils.js +49 -0
- package/dist/ai-service/llm/interaction/result-utils.js.map +1 -0
- package/dist/ai-service/llm/interaction/stream-lifecycle.d.ts +48 -0
- package/dist/ai-service/llm/interaction/stream-lifecycle.d.ts.map +1 -0
- package/dist/ai-service/llm/interaction/stream-lifecycle.js +129 -0
- package/dist/ai-service/llm/interaction/stream-lifecycle.js.map +1 -0
- package/dist/ai-service/llm/provider.d.ts +1 -2
- package/dist/ai-service/llm/provider.d.ts.map +1 -1
- package/dist/ai-service/llm/provider.js +3 -6
- package/dist/ai-service/llm/provider.js.map +1 -1
- package/dist/ai-service/llmobs/helpers.d.ts +7 -8
- package/dist/ai-service/llmobs/helpers.d.ts.map +1 -1
- package/dist/ai-service/llmobs/helpers.js +8 -48
- package/dist/ai-service/llmobs/helpers.js.map +1 -1
- package/dist/ai-service/llmobs/middleware/stream-text.d.ts +19 -21
- package/dist/ai-service/llmobs/middleware/stream-text.d.ts.map +1 -1
- package/dist/ai-service/llmobs/middleware/stream-text.js +98 -106
- package/dist/ai-service/llmobs/middleware/stream-text.js.map +1 -1
- package/dist/ai-service/llmobs/types.d.ts +14 -1
- package/dist/ai-service/llmobs/types.d.ts.map +1 -1
- package/dist/ai-service/state-machine/clark-fsm.d.ts +75 -5
- package/dist/ai-service/state-machine/clark-fsm.d.ts.map +1 -1
- package/dist/ai-service/state-machine/clark-fsm.js +100 -0
- package/dist/ai-service/state-machine/clark-fsm.js.map +1 -1
- package/dist/ai-service/state-machine/handlers/agent-planning.d.ts.map +1 -1
- package/dist/ai-service/state-machine/handlers/agent-planning.js +4 -0
- package/dist/ai-service/state-machine/handlers/agent-planning.js.map +1 -1
- package/dist/ai-service/state-machine/handlers/llm-generating.d.ts.map +1 -1
- package/dist/ai-service/state-machine/handlers/llm-generating.js +91 -456
- package/dist/ai-service/state-machine/handlers/llm-generating.js.map +1 -1
- package/dist/ai-service/state-machine/handlers/runtime-reviewing.js +1 -1
- package/dist/ai-service/state-machine/handlers/runtime-reviewing.js.map +1 -1
- package/dist/ai-service/state-machine/helpers/peer.d.ts.map +1 -1
- package/dist/ai-service/state-machine/helpers/peer.js +15 -0
- package/dist/ai-service/state-machine/helpers/peer.js.map +1 -1
- package/dist/ai-service/state-machine/mocks.d.ts.map +1 -1
- package/dist/ai-service/state-machine/mocks.js +1 -0
- package/dist/ai-service/state-machine/mocks.js.map +1 -1
- package/dist/ai-service/template-renderer.js +1 -1
- package/dist/ai-service/template-renderer.js.map +1 -1
- package/dist/ai-service/types.d.ts +30 -0
- package/dist/ai-service/types.d.ts.map +1 -1
- package/dist/binding-extraction/extract-identifiers.d.ts +14 -0
- package/dist/binding-extraction/extract-identifiers.d.ts.map +1 -1
- package/dist/binding-extraction/extract-identifiers.js +46 -1
- package/dist/binding-extraction/extract-identifiers.js.map +1 -1
- package/dist/binding-extraction/js-identifiers.d.ts +14 -0
- package/dist/binding-extraction/js-identifiers.d.ts.map +1 -1
- package/dist/binding-extraction/js-identifiers.js +168 -0
- package/dist/binding-extraction/js-identifiers.js.map +1 -1
- package/dist/binding-extraction/python-identifiers.d.ts +5 -0
- package/dist/binding-extraction/python-identifiers.d.ts.map +1 -1
- package/dist/binding-extraction/python-identifiers.js +76 -7
- package/dist/binding-extraction/python-identifiers.js.map +1 -1
- package/dist/file-sync-vite-plugin.d.ts.map +1 -1
- package/dist/file-sync-vite-plugin.js +73 -3
- package/dist/file-sync-vite-plugin.js.map +1 -1
- package/dist/file-system-manager.d.ts.map +1 -1
- package/dist/file-system-manager.js +6 -4
- package/dist/file-system-manager.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/lock-service/activity-tracker.d.ts +14 -2
- package/dist/lock-service/activity-tracker.d.ts.map +1 -1
- package/dist/lock-service/activity-tracker.js +43 -6
- package/dist/lock-service/activity-tracker.js.map +1 -1
- package/dist/lock-service/index.d.ts +13 -2
- package/dist/lock-service/index.d.ts.map +1 -1
- package/dist/lock-service/index.js +130 -44
- package/dist/lock-service/index.js.map +1 -1
- package/dist/parsing/jsx.d.ts.map +1 -1
- package/dist/parsing/jsx.js +78 -66
- package/dist/parsing/jsx.js.map +1 -1
- package/dist/socket-manager.js +1 -1
- package/dist/socket-manager.js.map +1 -1
- package/dist/sync-service/list-dir.d.ts.map +1 -1
- package/dist/sync-service/list-dir.js +41 -18
- package/dist/sync-service/list-dir.js.map +1 -1
- package/dist/vite-plugin-yaml-types.d.ts.map +1 -1
- package/dist/vite-plugin-yaml-types.js +2 -4
- package/dist/vite-plugin-yaml-types.js.map +1 -1
- package/package.json +7 -7
- package/dist/ai-service/agent/subagents/apis/api-executor.d.ts.map +0 -1
- package/dist/ai-service/agent/subagents/apis/api-executor.js.map +0 -1
- package/dist/ai-service/agent/subagents/apis/context.d.ts +0 -12
- package/dist/ai-service/agent/subagents/apis/context.d.ts.map +0 -1
- package/dist/ai-service/agent/subagents/apis/context.js +0 -18
- package/dist/ai-service/agent/subagents/apis/context.js.map +0 -1
- package/dist/ai-service/agent/subagents/apis/generate-api-source.d.ts +0 -40
- package/dist/ai-service/agent/subagents/apis/generate-api-source.d.ts.map +0 -1
- package/dist/ai-service/agent/subagents/apis/generate-api-source.js +0 -516
- package/dist/ai-service/agent/subagents/apis/generate-api-source.js.map +0 -1
- package/dist/ai-service/agent/subagents/apis/state.d.ts +0 -49
- package/dist/ai-service/agent/subagents/apis/state.d.ts.map +0 -1
- package/dist/ai-service/agent/subagents/apis/state.js +0 -25
- package/dist/ai-service/agent/subagents/apis/state.js.map +0 -1
- package/dist/ai-service/agent/subagents/apis/system-prompt.d.ts +0 -3
- package/dist/ai-service/agent/subagents/apis/system-prompt.d.ts.map +0 -1
- package/dist/ai-service/agent/subagents/apis/system-prompt.js +0 -1704
- package/dist/ai-service/agent/subagents/apis/system-prompt.js.map +0 -1
- package/dist/ai-service/agent/tools/apis/finalize-api.d.ts +0 -11
- package/dist/ai-service/agent/tools/apis/finalize-api.d.ts.map +0 -1
- package/dist/ai-service/agent/tools/apis/finalize-api.js +0 -133
- package/dist/ai-service/agent/tools/apis/finalize-api.js.map +0 -1
- package/dist/ai-service/llm/middleware/retry.d.ts +0 -112
- package/dist/ai-service/llm/middleware/retry.d.ts.map +0 -1
- package/dist/ai-service/llm/middleware/retry.js +0 -239
- package/dist/ai-service/llm/middleware/retry.js.map +0 -1
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* High-level provider interface for LLM streaming interactions.
|
|
3
|
+
*
|
|
4
|
+
* This interface defines a complete, SDK-agnostic contract for multi-step
|
|
5
|
+
* LLM streaming, including all lifecycle hooks. Concrete implementations
|
|
6
|
+
* (adapters) bridge this interface to specific SDKs (Vercel AI, Anthropic, etc.).
|
|
7
|
+
*
|
|
8
|
+
* Key features:
|
|
9
|
+
* - Complete lifecycle: prepareStep → onChunk → onStepFinish → onFinish → onFinally
|
|
10
|
+
* - onFinally: Guaranteed to run after stream consumption (our addition!)
|
|
11
|
+
* - SDK-agnostic: Could be implemented with any LLM SDK
|
|
12
|
+
* - Testable: Easy to mock for testing
|
|
13
|
+
*/
|
|
14
|
+
import type { Tool } from "../../agent/tools2/types.js";
|
|
15
|
+
import type { StopCondition } from "../../util/stop-condition.js";
|
|
16
|
+
import type { ProviderOptions } from "@ai-sdk/provider-utils";
|
|
17
|
+
import type { LanguageModel, TextStreamPart, LanguageModelUsage, ModelMessage, UserModelMessage } from "ai";
|
|
18
|
+
/**
|
|
19
|
+
* Provider interface for LLM streaming interactions.
|
|
20
|
+
*
|
|
21
|
+
* Implementations of this interface wrap specific SDKs and provide
|
|
22
|
+
* a consistent, high-level API with complete lifecycle management.
|
|
23
|
+
*/
|
|
24
|
+
export interface StreamTextProvider {
|
|
25
|
+
/**
|
|
26
|
+
* Streams text from an LLM with multi-step tool calling support.
|
|
27
|
+
*
|
|
28
|
+
* @param options - Configuration and lifecycle hooks
|
|
29
|
+
* @returns Promise resolving to stream result with text/full streams
|
|
30
|
+
*/
|
|
31
|
+
streamText<TOOLS extends Record<string, Tool> = Record<string, Tool>>(options: StreamTextOptions<TOOLS>): Promise<StreamTextResult<TOOLS>>;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Options for a streamText call.
|
|
35
|
+
*
|
|
36
|
+
* Includes model configuration, messages, tools, and comprehensive
|
|
37
|
+
* lifecycle hooks including onFinally (runs after stream consumption).
|
|
38
|
+
*/
|
|
39
|
+
export interface StreamTextOptions<TOOLS extends Record<string, Tool>> {
|
|
40
|
+
/** The language model to use */
|
|
41
|
+
model: LanguageModel;
|
|
42
|
+
/**
|
|
43
|
+
* Conversation messages.
|
|
44
|
+
* Note: When using context middleware, this will be populated automatically
|
|
45
|
+
* from context history. You typically provide user instead.
|
|
46
|
+
*/
|
|
47
|
+
messages?: ModelMessage[];
|
|
48
|
+
/**
|
|
49
|
+
* User message for this interaction.
|
|
50
|
+
* When using context middleware, this is added to the conversation history
|
|
51
|
+
* and messages are populated automatically from context.
|
|
52
|
+
*/
|
|
53
|
+
user?: UserModelMessage;
|
|
54
|
+
/** Available tools the model can call */
|
|
55
|
+
tools?: TOOLS;
|
|
56
|
+
/**
|
|
57
|
+
* System prompt.
|
|
58
|
+
* When using context middleware, this is set on the context.
|
|
59
|
+
*/
|
|
60
|
+
system?: string;
|
|
61
|
+
/** Maximum number of automatic tool call steps */
|
|
62
|
+
maxSteps?: number;
|
|
63
|
+
/** Abort signal for cancellation */
|
|
64
|
+
abortSignal?: AbortSignal;
|
|
65
|
+
/** Custom headers for the request */
|
|
66
|
+
headers?: Record<string, string | undefined>;
|
|
67
|
+
/** Provider-specific options */
|
|
68
|
+
providerOptions?: ProviderOptions;
|
|
69
|
+
/**
|
|
70
|
+
* Vercel AI SDK specific: Condition to stop generation early.
|
|
71
|
+
* Pass through to the underlying SDK.
|
|
72
|
+
*/
|
|
73
|
+
stopWhen?: StopCondition<any> | StopCondition<any>[];
|
|
74
|
+
/**
|
|
75
|
+
* Vercel AI SDK specific: Transformation stream for the output.
|
|
76
|
+
* Pass through to the underlying SDK.
|
|
77
|
+
*/
|
|
78
|
+
experimental_transform?: any;
|
|
79
|
+
/**
|
|
80
|
+
* Called before each LLM step.
|
|
81
|
+
* Can transform the step parameters before execution.
|
|
82
|
+
*/
|
|
83
|
+
prepareStep?: (step: StepParameters) => Promise<StepParameters> | StepParameters;
|
|
84
|
+
/**
|
|
85
|
+
* Called for each chunk in the stream during generation.
|
|
86
|
+
*/
|
|
87
|
+
onChunk?: (event: {
|
|
88
|
+
chunk: StreamChunk;
|
|
89
|
+
}) => Promise<void> | void;
|
|
90
|
+
/**
|
|
91
|
+
* Called after each step completes (after tool execution).
|
|
92
|
+
*/
|
|
93
|
+
onStepFinish?: (step: StepResult) => Promise<void> | void;
|
|
94
|
+
/**
|
|
95
|
+
* Called when the entire multi-step interaction finishes.
|
|
96
|
+
* This fires after generation completes, before stream consumption.
|
|
97
|
+
*/
|
|
98
|
+
onFinish?: (result: FinalResult) => Promise<void> | void;
|
|
99
|
+
/**
|
|
100
|
+
* Called after stream consumption completes.
|
|
101
|
+
*
|
|
102
|
+
* This is the key lifecycle hook for cleanup operations:
|
|
103
|
+
* - Releasing locks (context handles)
|
|
104
|
+
* - Finishing tracing spans
|
|
105
|
+
* - Closing database connections
|
|
106
|
+
* - Saving final artifacts
|
|
107
|
+
*
|
|
108
|
+
* Guarantees:
|
|
109
|
+
* - Runs exactly once, even if multiple stream accessors are used
|
|
110
|
+
* - Runs after the stream is fully consumed OR abandoned
|
|
111
|
+
* - Runs in error cases as well (usage may be partial)
|
|
112
|
+
* - Idempotent and safe to call multiple times
|
|
113
|
+
*
|
|
114
|
+
*/
|
|
115
|
+
onFinally?: () => Promise<void> | void;
|
|
116
|
+
/**
|
|
117
|
+
* Called if an error occurs during generation or consumption.
|
|
118
|
+
*/
|
|
119
|
+
onError?: (error: Error) => Promise<void> | void;
|
|
120
|
+
/**
|
|
121
|
+
* Called if the operation is aborted via the abortSignal.
|
|
122
|
+
*/
|
|
123
|
+
onAbort?: () => Promise<void> | void;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Parameters for a single LLM step.
|
|
127
|
+
*/
|
|
128
|
+
export interface StepParameters {
|
|
129
|
+
messages: ModelMessage[];
|
|
130
|
+
stepNumber: number;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* A chunk from the streaming response.
|
|
134
|
+
* This is a direct re-export of Vercel AI SDK's TextStreamPart.
|
|
135
|
+
*/
|
|
136
|
+
export type StreamChunk = TextStreamPart<Record<string, Tool>>;
|
|
137
|
+
import type { StepResult as VercelStepResult } from "ai";
|
|
138
|
+
/**
|
|
139
|
+
* Result of a single LLM step.
|
|
140
|
+
* Re-exported from Vercel AI SDK to avoid type incompatibilities.
|
|
141
|
+
*/
|
|
142
|
+
export type StepResult = VercelStepResult<any>;
|
|
143
|
+
/**
|
|
144
|
+
* Final result of the entire multi-step interaction.
|
|
145
|
+
* This is the result passed to onFinish callback.
|
|
146
|
+
* Re-exported from Vercel AI SDK's internal type.
|
|
147
|
+
*/
|
|
148
|
+
export type FinalResult = StepResult & {
|
|
149
|
+
readonly steps: StepResult[];
|
|
150
|
+
readonly totalUsage: LanguageModelUsage;
|
|
151
|
+
};
|
|
152
|
+
import type { AsyncIterableStream } from "ai";
|
|
153
|
+
/**
|
|
154
|
+
* Result of a streamText call.
|
|
155
|
+
*
|
|
156
|
+
* This type defines only the properties we actually use from the Vercel AI SDK's
|
|
157
|
+
* StreamTextResult. Adapters must use `createStreamResult()` to build this type
|
|
158
|
+
* from raw SDK results, ensuring all properties are plain enumerable values.
|
|
159
|
+
*
|
|
160
|
+
* The brand prevents returning raw SDK results (compile error) and ensures
|
|
161
|
+
* spread operators work correctly in middlewares.
|
|
162
|
+
*/
|
|
163
|
+
export type StreamTextResult<TOOLS extends Record<string, Tool> = Record<string, Tool>> = {
|
|
164
|
+
/** Brand to ensure properties are materialized (enumerable) */
|
|
165
|
+
readonly __materialized: unique symbol;
|
|
166
|
+
/** Stream of text deltas */
|
|
167
|
+
textStream: AsyncIterableStream<string>;
|
|
168
|
+
/** Stream of all events (text, tool calls, etc.) */
|
|
169
|
+
fullStream: AsyncIterableStream<TextStreamPart<TOOLS>>;
|
|
170
|
+
/** Promise that resolves with the final result */
|
|
171
|
+
response: Promise<FinalResult>;
|
|
172
|
+
};
|
|
173
|
+
//# sourceMappingURL=provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../../../../src/ai-service/llm/interaction/provider.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,6BAA6B,CAAC;AACxD,OAAO,KAAK,EAAE,aAAa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,QAAQ,CAAC,UAAU,EAAE,kBAAkB,CAAC;CACzC,CAAC;AAEF,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,IAAI,CAAC;AAE9C;;;;;;;;;GASG;AACH,MAAM,MAAM,gBAAgB,CAC1B,KAAK,SAAS,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,IACvD;IACF,+DAA+D;IAC/D,QAAQ,CAAC,cAAc,EAAE,OAAO,MAAM,CAAC;IAEvC,4BAA4B;IAC5B,UAAU,EAAE,mBAAmB,CAAC,MAAM,CAAC,CAAC;IAExC,oDAAoD;IACpD,UAAU,EAAE,mBAAmB,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC,CAAC;IAEvD,kDAAkD;IAClD,QAAQ,EAAE,OAAO,CAAC,WAAW,CAAC,CAAC;CAChC,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* High-level provider interface for LLM streaming interactions.
|
|
3
|
+
*
|
|
4
|
+
* This interface defines a complete, SDK-agnostic contract for multi-step
|
|
5
|
+
* LLM streaming, including all lifecycle hooks. Concrete implementations
|
|
6
|
+
* (adapters) bridge this interface to specific SDKs (Vercel AI, Anthropic, etc.).
|
|
7
|
+
*
|
|
8
|
+
* Key features:
|
|
9
|
+
* - Complete lifecycle: prepareStep → onChunk → onStepFinish → onFinish → onFinally
|
|
10
|
+
* - onFinally: Guaranteed to run after stream consumption (our addition!)
|
|
11
|
+
* - SDK-agnostic: Could be implemented with any LLM SDK
|
|
12
|
+
* - Testable: Easy to mock for testing
|
|
13
|
+
*/
|
|
14
|
+
export {};
|
|
15
|
+
//# sourceMappingURL=provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider.js","sourceRoot":"","sources":["../../../../src/ai-service/llm/interaction/provider.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utilities for creating StreamTextResult objects.
|
|
3
|
+
*
|
|
4
|
+
* The Vercel AI SDK's StreamTextResult has non-enumerable getters that are lost
|
|
5
|
+
* when using spread operators. This utility extracts only the properties we need
|
|
6
|
+
* into plain enumerable values, allowing spread operators to work correctly.
|
|
7
|
+
*/
|
|
8
|
+
import type { StreamTextResult } from "./provider.js";
|
|
9
|
+
import type { Tool } from "../../agent/tools2/types.js";
|
|
10
|
+
import type { StreamTextResult as VercelStreamTextResult } from "ai";
|
|
11
|
+
/**
|
|
12
|
+
* Creates our StreamTextResult from a Vercel SDK result.
|
|
13
|
+
*
|
|
14
|
+
* Extracts only the properties we actually use (textStream, fullStream, response)
|
|
15
|
+
* and creates a plain object with enumerable properties. This allows:
|
|
16
|
+
* 1. Spread operators to work correctly in middlewares
|
|
17
|
+
* 2. Type safety via the brand (can't return raw SDK results)
|
|
18
|
+
* 3. Simpler API - we only expose what we need
|
|
19
|
+
*
|
|
20
|
+
* **When to use:**
|
|
21
|
+
* - In adapters: Always call this on raw SDK results before returning
|
|
22
|
+
* - In middlewares: Never needed - just use spread operators
|
|
23
|
+
*
|
|
24
|
+
* @param raw - Raw StreamTextResult from Vercel AI SDK
|
|
25
|
+
* @returns Our branded StreamTextResult with enumerable properties
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```typescript
|
|
29
|
+
* // In Vercel adapter:
|
|
30
|
+
* async streamText(options) {
|
|
31
|
+
* const result = await streamText(...); // Vercel SDK
|
|
32
|
+
* return createStreamResult(result); // Extract + brand
|
|
33
|
+
* }
|
|
34
|
+
*
|
|
35
|
+
* // In middleware (no helper needed!):
|
|
36
|
+
* return {
|
|
37
|
+
* ...result, // Spread works because properties are enumerable
|
|
38
|
+
* textStream: wrappedStream
|
|
39
|
+
* };
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
export declare function createStreamResult<TOOLS extends Record<string, Tool>>(raw: VercelStreamTextResult<TOOLS, any>): StreamTextResult<TOOLS>;
|
|
43
|
+
//# sourceMappingURL=result-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"result-utils.d.ts","sourceRoot":"","sources":["../../../../src/ai-service/llm/interaction/result-utils.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACtD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,6BAA6B,CAAC;AACxD,OAAO,KAAK,EAAE,gBAAgB,IAAI,sBAAsB,EAAE,MAAM,IAAI,CAAC;AAErE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,SAAS,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,EACnE,GAAG,EAAE,sBAAsB,CAAC,KAAK,EAAE,GAAG,CAAC,GACtC,gBAAgB,CAAC,KAAK,CAAC,CASzB"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utilities for creating StreamTextResult objects.
|
|
3
|
+
*
|
|
4
|
+
* The Vercel AI SDK's StreamTextResult has non-enumerable getters that are lost
|
|
5
|
+
* when using spread operators. This utility extracts only the properties we need
|
|
6
|
+
* into plain enumerable values, allowing spread operators to work correctly.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Creates our StreamTextResult from a Vercel SDK result.
|
|
10
|
+
*
|
|
11
|
+
* Extracts only the properties we actually use (textStream, fullStream, response)
|
|
12
|
+
* and creates a plain object with enumerable properties. This allows:
|
|
13
|
+
* 1. Spread operators to work correctly in middlewares
|
|
14
|
+
* 2. Type safety via the brand (can't return raw SDK results)
|
|
15
|
+
* 3. Simpler API - we only expose what we need
|
|
16
|
+
*
|
|
17
|
+
* **When to use:**
|
|
18
|
+
* - In adapters: Always call this on raw SDK results before returning
|
|
19
|
+
* - In middlewares: Never needed - just use spread operators
|
|
20
|
+
*
|
|
21
|
+
* @param raw - Raw StreamTextResult from Vercel AI SDK
|
|
22
|
+
* @returns Our branded StreamTextResult with enumerable properties
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```typescript
|
|
26
|
+
* // In Vercel adapter:
|
|
27
|
+
* async streamText(options) {
|
|
28
|
+
* const result = await streamText(...); // Vercel SDK
|
|
29
|
+
* return createStreamResult(result); // Extract + brand
|
|
30
|
+
* }
|
|
31
|
+
*
|
|
32
|
+
* // In middleware (no helper needed!):
|
|
33
|
+
* return {
|
|
34
|
+
* ...result, // Spread works because properties are enumerable
|
|
35
|
+
* textStream: wrappedStream
|
|
36
|
+
* };
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
export function createStreamResult(raw) {
|
|
40
|
+
// Extract only the properties we use
|
|
41
|
+
// Access them directly to get the getter values
|
|
42
|
+
// Cast via unknown to satisfy the brand requirement
|
|
43
|
+
return {
|
|
44
|
+
textStream: raw.textStream,
|
|
45
|
+
fullStream: raw.fullStream,
|
|
46
|
+
response: raw.response,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=result-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"result-utils.js","sourceRoot":"","sources":["../../../../src/ai-service/llm/interaction/result-utils.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAMH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,MAAM,UAAU,kBAAkB,CAChC,GAAuC;IAEvC,qCAAqC;IACrC,gDAAgD;IAChD,oDAAoD;IACpD,OAAO;QACL,UAAU,EAAE,GAAG,CAAC,UAAU;QAC1B,UAAU,EAAE,GAAG,CAAC,UAAU;QAC1B,QAAQ,EAAE,GAAG,CAAC,QAAQ;KACe,CAAC;AAC1C,CAAC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stream lifecycle management utilities.
|
|
3
|
+
*
|
|
4
|
+
* Provides utilities for wrapping streams with lifecycle hooks, particularly
|
|
5
|
+
* `onFinally` which runs after stream consumption completes.
|
|
6
|
+
*
|
|
7
|
+
* Key challenge: The `streamText()` function returns immediately, but the
|
|
8
|
+
* streams are consumed asynchronously later. We need to track when consumption
|
|
9
|
+
* actually completes to run cleanup logic.
|
|
10
|
+
*
|
|
11
|
+
* Solution: Wrap streams with `TransformStream` that tracks consumption via
|
|
12
|
+
* the `flush()` method, which runs when the input stream closes.
|
|
13
|
+
*/
|
|
14
|
+
import type { StreamTextResult } from "./provider.js";
|
|
15
|
+
import type { Tool } from "../../agent/tools2/types.js";
|
|
16
|
+
/**
|
|
17
|
+
* Wraps a StreamTextResult to add onFinally lifecycle hook.
|
|
18
|
+
*
|
|
19
|
+
* The onFinally callback runs after stream consumption completes, handling:
|
|
20
|
+
* - Normal completion (stream exhausted)
|
|
21
|
+
* - Errors during consumption
|
|
22
|
+
* - Stream cancellation/abandonment
|
|
23
|
+
*
|
|
24
|
+
* Guarantees:
|
|
25
|
+
* - Runs exactly once, even if multiple stream accessors are used
|
|
26
|
+
* - Idempotent (safe to call multiple times)
|
|
27
|
+
* - Works with all consumption patterns (iteration, promises, piping)
|
|
28
|
+
*
|
|
29
|
+
* @param result - The stream result to wrap
|
|
30
|
+
* @param onFinally - Callback to run after consumption
|
|
31
|
+
* @returns Wrapped result with lifecycle tracking
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```typescript
|
|
35
|
+
* const result = await streamText({ model, messages });
|
|
36
|
+
* const wrapped = withStreamLifecycle(result, async () => {
|
|
37
|
+
* console.log('Stream consumed!');
|
|
38
|
+
* await cleanup();
|
|
39
|
+
* });
|
|
40
|
+
*
|
|
41
|
+
* for await (const text of wrapped.textStream) {
|
|
42
|
+
* console.log(text);
|
|
43
|
+
* }
|
|
44
|
+
* // onFinally runs here ^
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
export declare function withStreamLifecycle<TOOLS extends Record<string, Tool> = Record<string, Tool>>(result: StreamTextResult<TOOLS>, onFinally: () => Promise<void> | void): StreamTextResult<TOOLS>;
|
|
48
|
+
//# sourceMappingURL=stream-lifecycle.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stream-lifecycle.d.ts","sourceRoot":"","sources":["../../../../src/ai-service/llm/interaction/stream-lifecycle.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACtD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,6BAA6B,CAAC;AAGxD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,wBAAgB,mBAAmB,CACjC,KAAK,SAAS,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,EAEzD,MAAM,EAAE,gBAAgB,CAAC,KAAK,CAAC,EAC/B,SAAS,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,GACpC,gBAAgB,CAAC,KAAK,CAAC,CAiCzB"}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stream lifecycle management utilities.
|
|
3
|
+
*
|
|
4
|
+
* Provides utilities for wrapping streams with lifecycle hooks, particularly
|
|
5
|
+
* `onFinally` which runs after stream consumption completes.
|
|
6
|
+
*
|
|
7
|
+
* Key challenge: The `streamText()` function returns immediately, but the
|
|
8
|
+
* streams are consumed asynchronously later. We need to track when consumption
|
|
9
|
+
* actually completes to run cleanup logic.
|
|
10
|
+
*
|
|
11
|
+
* Solution: Wrap streams with `TransformStream` that tracks consumption via
|
|
12
|
+
* the `flush()` method, which runs when the input stream closes.
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* Wraps a StreamTextResult to add onFinally lifecycle hook.
|
|
16
|
+
*
|
|
17
|
+
* The onFinally callback runs after stream consumption completes, handling:
|
|
18
|
+
* - Normal completion (stream exhausted)
|
|
19
|
+
* - Errors during consumption
|
|
20
|
+
* - Stream cancellation/abandonment
|
|
21
|
+
*
|
|
22
|
+
* Guarantees:
|
|
23
|
+
* - Runs exactly once, even if multiple stream accessors are used
|
|
24
|
+
* - Idempotent (safe to call multiple times)
|
|
25
|
+
* - Works with all consumption patterns (iteration, promises, piping)
|
|
26
|
+
*
|
|
27
|
+
* @param result - The stream result to wrap
|
|
28
|
+
* @param onFinally - Callback to run after consumption
|
|
29
|
+
* @returns Wrapped result with lifecycle tracking
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```typescript
|
|
33
|
+
* const result = await streamText({ model, messages });
|
|
34
|
+
* const wrapped = withStreamLifecycle(result, async () => {
|
|
35
|
+
* console.log('Stream consumed!');
|
|
36
|
+
* await cleanup();
|
|
37
|
+
* });
|
|
38
|
+
*
|
|
39
|
+
* for await (const text of wrapped.textStream) {
|
|
40
|
+
* console.log(text);
|
|
41
|
+
* }
|
|
42
|
+
* // onFinally runs here ^
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
export function withStreamLifecycle(result, onFinally) {
|
|
46
|
+
// Track whether finalization has run
|
|
47
|
+
let finalized = false;
|
|
48
|
+
/**
|
|
49
|
+
* Ensures onFinally runs exactly once.
|
|
50
|
+
* Safe to call multiple times (idempotent).
|
|
51
|
+
*/
|
|
52
|
+
const ensureFinally = async () => {
|
|
53
|
+
if (finalized)
|
|
54
|
+
return;
|
|
55
|
+
finalized = true;
|
|
56
|
+
try {
|
|
57
|
+
await onFinally();
|
|
58
|
+
}
|
|
59
|
+
catch (error) {
|
|
60
|
+
// Log but don't throw - we're in cleanup, don't break the stream
|
|
61
|
+
console.error("[streamLifecycle] Error in onFinally:", error);
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
// Wrap textStream to track consumption
|
|
65
|
+
const wrappedTextStream = wrapAsyncIterable(result.textStream, ensureFinally);
|
|
66
|
+
// Wrap fullStream to track consumption
|
|
67
|
+
const wrappedFullStream = wrapAsyncIterable(result.fullStream, ensureFinally);
|
|
68
|
+
// Return result with wrapped streams
|
|
69
|
+
// Spread works because adapter materialized getters into enumerable properties
|
|
70
|
+
return {
|
|
71
|
+
...result,
|
|
72
|
+
textStream: wrappedTextStream,
|
|
73
|
+
fullStream: wrappedFullStream,
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Wraps an async iterable with a finalization callback.
|
|
78
|
+
*
|
|
79
|
+
* Uses TransformStream to intercept the stream lifecycle:
|
|
80
|
+
* - `transform()`: Passes chunks through unchanged
|
|
81
|
+
* - `flush()`: Called when input stream closes (after all chunks processed)
|
|
82
|
+
* - `cancel()`: Called if stream is cancelled/abandoned
|
|
83
|
+
*
|
|
84
|
+
* The finalization callback runs in both flush() and cancel() to ensure
|
|
85
|
+
* cleanup happens whether the stream completes normally or is abandoned.
|
|
86
|
+
*
|
|
87
|
+
* @param source - The async iterable to wrap
|
|
88
|
+
* @param onFinalize - Callback to run after consumption
|
|
89
|
+
* @returns Wrapped async iterable
|
|
90
|
+
*/
|
|
91
|
+
function wrapAsyncIterable(source, onFinalize) {
|
|
92
|
+
// Convert async iterable to ReadableStream if needed
|
|
93
|
+
let sourceStream;
|
|
94
|
+
if (source instanceof ReadableStream) {
|
|
95
|
+
sourceStream = source;
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
// Manually convert async iterable to ReadableStream
|
|
99
|
+
sourceStream = new ReadableStream({
|
|
100
|
+
async start(controller) {
|
|
101
|
+
try {
|
|
102
|
+
for await (const chunk of source) {
|
|
103
|
+
controller.enqueue(chunk);
|
|
104
|
+
}
|
|
105
|
+
controller.close();
|
|
106
|
+
}
|
|
107
|
+
catch (error) {
|
|
108
|
+
controller.error(error);
|
|
109
|
+
}
|
|
110
|
+
},
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
// Create transform stream that tracks lifecycle
|
|
114
|
+
const lifecycleTransform = new TransformStream({
|
|
115
|
+
// Pass through all chunks unchanged
|
|
116
|
+
transform(chunk, controller) {
|
|
117
|
+
controller.enqueue(chunk);
|
|
118
|
+
},
|
|
119
|
+
// Called when input stream closes (after all chunks processed)
|
|
120
|
+
async flush() {
|
|
121
|
+
await onFinalize();
|
|
122
|
+
},
|
|
123
|
+
});
|
|
124
|
+
// Pipe source through lifecycle tracker
|
|
125
|
+
const wrappedStream = sourceStream.pipeThrough(lifecycleTransform);
|
|
126
|
+
// Return as AsyncIterableStream (has both stream and iterable interfaces)
|
|
127
|
+
return wrappedStream;
|
|
128
|
+
}
|
|
129
|
+
//# sourceMappingURL=stream-lifecycle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stream-lifecycle.js","sourceRoot":"","sources":["../../../../src/ai-service/llm/interaction/stream-lifecycle.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAMH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,MAAM,UAAU,mBAAmB,CAGjC,MAA+B,EAC/B,SAAqC;IAErC,qCAAqC;IACrC,IAAI,SAAS,GAAG,KAAK,CAAC;IAEtB;;;OAGG;IACH,MAAM,aAAa,GAAG,KAAK,IAAI,EAAE;QAC/B,IAAI,SAAS;YAAE,OAAO;QACtB,SAAS,GAAG,IAAI,CAAC;QAEjB,IAAI,CAAC;YACH,MAAM,SAAS,EAAE,CAAC;QACpB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,iEAAiE;YACjE,OAAO,CAAC,KAAK,CAAC,uCAAuC,EAAE,KAAK,CAAC,CAAC;QAChE,CAAC;IACH,CAAC,CAAC;IAEF,uCAAuC;IACvC,MAAM,iBAAiB,GAAG,iBAAiB,CAAC,MAAM,CAAC,UAAU,EAAE,aAAa,CAAC,CAAC;IAE9E,uCAAuC;IACvC,MAAM,iBAAiB,GAAG,iBAAiB,CAAC,MAAM,CAAC,UAAU,EAAE,aAAa,C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/retry.js";
|
|
2
1
|
import type { LLMProvider, LLMProviderSettings } from "./types.js";
|
|
3
2
|
import type { LLMProviderConfig } from "@superblocksteam/library-shared/types";
|
|
4
|
-
export declare const createLLMProvider: (settings: LLMProviderSettings, getJwt?: () => string | undefined, llmConfig?: LLMProviderConfig
|
|
3
|
+
export declare const createLLMProvider: (settings: LLMProviderSettings, getJwt?: () => string | undefined, llmConfig?: LLMProviderConfig) => LLMProvider;
|
|
5
4
|
//# sourceMappingURL=provider.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../../../src/ai-service/llm/provider.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../../../src/ai-service/llm/provider.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EACV,WAAW,EACX,mBAAmB,EAGpB,MAAM,YAAY,CAAC;AAEpB,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,uCAAuC,CAAC;AAE/E,eAAO,MAAM,iBAAiB,GAC5B,UAAU,mBAAmB,EAC7B,SAAS,MAAM,MAAM,GAAG,SAAS,EACjC,YAAY,iBAAiB,KAC5B,WAuDF,CAAC"}
|
|
@@ -2,18 +2,15 @@ import { customProvider, wrapLanguageModel } from "ai";
|
|
|
2
2
|
import { getLogger } from "../../util/logger.js";
|
|
3
3
|
import { anthropicImpl } from "./impl/anthropic.js";
|
|
4
4
|
import { clarkImpl } from "./impl/clark.js";
|
|
5
|
-
import { retryMiddleware } from "./middleware/retry.js";
|
|
6
5
|
import { jwtMiddleware, modelFromClassification } from "./utils.js";
|
|
7
|
-
export const createLLMProvider = (settings, getJwt, llmConfig
|
|
6
|
+
export const createLLMProvider = (settings, getJwt, llmConfig) => {
|
|
8
7
|
const providerType = llmConfig?.provider || "bedrock";
|
|
9
8
|
const wrapDefaults = (model) => wrapLanguageModel({
|
|
10
9
|
model,
|
|
11
10
|
middleware: [
|
|
12
11
|
jwtMiddleware(getJwt),
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
...retryOptions,
|
|
16
|
-
}, getLogger()),
|
|
12
|
+
// Note: Retry is now handled at the StreamText level via createStreamRetryMiddleware
|
|
13
|
+
// to ensure fresh Vercel SDK state and correct message sequences on retry
|
|
17
14
|
],
|
|
18
15
|
});
|
|
19
16
|
getLogger().info(`Creating LLM provider: type=${providerType}, config=${JSON.stringify(llmConfig || {})}`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider.js","sourceRoot":"","sources":["../../../src/ai-service/llm/provider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,IAAI,CAAC;AACvD,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACjD,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"provider.js","sourceRoot":"","sources":["../../../src/ai-service/llm/provider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,IAAI,CAAC;AACvD,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACjD,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAC;AAUpE,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAC/B,QAA6B,EAC7B,MAAiC,EACjC,SAA6B,EAChB,EAAE;IACf,MAAM,YAAY,GAAG,SAAS,EAAE,QAAQ,IAAI,SAAS,CAAC;IAEtD,MAAM,YAAY,GAAG,CAAC,KAAsB,EAAE,EAAE,CAC9C,iBAAiB,CAAC;QAChB,KAAK;QACL,UAAU,E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EAAE,CACzC,uBAAuB,CAAC,YAAY,EAAE,cAAc,CAAC;KACxD,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { streamText, type ToolSet } from "ai";
|
|
2
1
|
import { type Logger } from "../../util/logger.js";
|
|
2
|
+
import { type StreamTextOptions } from "../llm/interaction/index.js";
|
|
3
3
|
import { LLMObsTracer } from "./tracer.js";
|
|
4
4
|
import type { LLMObsSpan } from "./types.js";
|
|
5
|
+
import type { Tool } from "../agent/tools2/types.js";
|
|
5
6
|
export declare function traceWorkflow<T>(name: string, operation: (span: any) => Promise<T>, tags?: Record<string, string | boolean>, llmobs?: LLMObsTracer): Promise<T>;
|
|
6
7
|
export declare function traceTask<T>(name: string, operation: (span: any) => Promise<T>, tags?: Record<string, string | boolean>, llmobs?: LLMObsTracer): Promise<T>;
|
|
7
8
|
export declare function traceLLM<T>(name: string, modelName: string, modelProvider: string, operation: (span: LLMObsSpan) => Promise<T>, tags?: Record<string, string | boolean>, llmobs?: LLMObsTracer): Promise<T>;
|
|
@@ -16,13 +17,11 @@ export declare function getCommonTraceTags(jwt: string | undefined, applicationI
|
|
|
16
17
|
* and chaos monkey error injection is handled at the fetch level. This function only applies
|
|
17
18
|
* LLMObs tracing.
|
|
18
19
|
*
|
|
19
|
-
* @param clark - Clark state machine instance
|
|
20
|
-
* @param services - Clark state handler parameters
|
|
21
20
|
* @param params - Parameters to pass to streamText
|
|
21
|
+
* @param tracer - Optional LLMObs tracer
|
|
22
|
+
* @param logger - Optional logger
|
|
23
|
+
*
|
|
24
|
+
* @deprecated use the LLMClient with LLMObs middleware instead (Clark.streamText in most cases)
|
|
22
25
|
*/
|
|
23
|
-
export declare function tracedStreamText<T extends
|
|
24
|
-
export declare const traceToolSet: <T extends ToolSet>(toolset: T, llmobs?: LLMObsTracer, hooks?: {
|
|
25
|
-
beforeExecute?: (name: string) => void;
|
|
26
|
-
afterExecute?: (name: string, span: LLMObsSpan) => void;
|
|
27
|
-
}) => T;
|
|
26
|
+
export declare function tracedStreamText<T extends Record<string, Tool>>(params: StreamTextOptions<T>, tracer?: LLMObsTracer, logger?: Logger): Promise<import("../llm/interaction/provider.js").StreamTextResult<T>>;
|
|
28
27
|
//# sourceMappingURL=helpers.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../../src/ai-service/llmobs/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../../src/ai-service/llmobs/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,MAAM,EAAa,MAAM,sBAAsB,CAAC;AAE9D,OAAO,EAGL,KAAK,iBAAiB,EACvB,MAAM,6BAA6B,CAAC;AAErC,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,0BAA0B,CAAC;AAGrD,wBAAgB,aAAa,CAAC,CAAC,EAC7B,IAAI,EAAE,MAAM,EACZ,SAAS,EAAE,CAAC,IAAI,EAAE,GAAG,KAAK,OAAO,CAAC,CAAC,CAAC,EACpC,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,EACvC,MAAM,GAAE,YAAoC,GAC3C,OAAO,CAAC,CAAC,CAAC,CAaZ;AAGD,wBAAgB,SAAS,CAAC,CAAC,EACzB,IAAI,EAAE,MAAM,EACZ,SAAS,EAAE,CAAC,IAAI,EAAE,GAAG,KAAK,OAAO,CAAC,CAAC,CAAC,EACpC,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,EACvC,MAAM,GAAE,YAAoC,GAC3C,OAAO,CAAC,CAAC,CAAC,CAaZ;AAGD,wBAAgB,QAAQ,CAAC,CAAC,EACxB,IAAI,EAAE,MAAM,EACZ,SAAS,EAAE,MAAM,EACjB,aAAa,EAAE,MAAM,EACrB,SAAS,EAAE,CAAC,IAAI,EAAE,UAAU,KAAK,OAAO,CAAC,CAAC,CAAC,EAC3C,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,EACvC,MAAM,GAAE,YAAoC,GAC3C,OAAO,CAAC,CAAC,CAAC,CAeZ;AAGD,wBAAgB,eAAe,CAC7B,GAAG,EAAE,MAAM,GAAG,SAAS,GACtB,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAUxB;AAGD,wBAAgB,kBAAkB,CAChC,GAAG,EAAE,MAAM,GAAG,SAAS,EACvB,aAAa,EAAE,MAAM,EACrB,cAAc,EAAE,MAAM,EACtB,cAAc,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAM,GACpD,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,CAclC;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,EAC7D,MAAM,EAAE,iBAAiB,CAAC,CAAC,CAAC,EAC5B,MAAM,GAAE,YAAoC,EAC5C,MAAM,GAAE,MAAoB,yEAQ7B"}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { streamText } from "ai";
|
|
2
1
|
import { getLogger } from "../../util/logger.js";
|
|
2
|
+
import { applyMiddleware } from "../llm/interaction/compose.js";
|
|
3
|
+
import { createLLMObsMiddleware, VercelStreamTextAdapter, } from "../llm/interaction/index.js";
|
|
3
4
|
import { parseJwt } from "../util/parse-jwt.js";
|
|
4
|
-
import { safeJsonStringify } from "../util/safe-stringify.js";
|
|
5
|
-
import { LLMObsStreamTextMiddleware } from "./middleware/stream-text.js";
|
|
6
5
|
import { LLMObsTracer } from "./tracer.js";
|
|
7
6
|
// Helper function for workflow tracing with common patterns
|
|
8
7
|
export function traceWorkflow(name, operation, tags, llmobs = LLMObsTracer.instance) {
|
|
@@ -77,54 +76,15 @@ export function getCommonTraceTags(jwt, applicationId, organizationId, additiona
|
|
|
77
76
|
* and chaos monkey error injection is handled at the fetch level. This function only applies
|
|
78
77
|
* LLMObs tracing.
|
|
79
78
|
*
|
|
80
|
-
* @param clark - Clark state machine instance
|
|
81
|
-
* @param services - Clark state handler parameters
|
|
82
79
|
* @param params - Parameters to pass to streamText
|
|
80
|
+
* @param tracer - Optional LLMObs tracer
|
|
81
|
+
* @param logger - Optional logger
|
|
82
|
+
*
|
|
83
|
+
* @deprecated use the LLMClient with LLMObs middleware instead (Clark.streamText in most cases)
|
|
83
84
|
*/
|
|
84
85
|
export function tracedStreamText(params, tracer = LLMObsTracer.instance, logger = getLogger()) {
|
|
85
|
-
// Disable built-in retries - we handle retries at the LanguageModelV2 middleware level
|
|
86
|
-
params = {
|
|
87
|
-
...params,
|
|
88
|
-
maxRetries: 0,
|
|
89
|
-
};
|
|
90
86
|
// Apply LLMObs tracing middleware
|
|
91
|
-
const
|
|
92
|
-
|
|
93
|
-
return tracedStreamText(params);
|
|
87
|
+
const traced = applyMiddleware(new VercelStreamTextAdapter(), createLLMObsMiddleware({ tracer, logger }));
|
|
88
|
+
return traced.streamText(params);
|
|
94
89
|
}
|
|
95
|
-
export const traceToolSet = (toolset, llmobs = LLMObsTracer.instance, hooks) => {
|
|
96
|
-
const tracedToolset = {};
|
|
97
|
-
for (const [name, tool] of Object.entries(toolset)) {
|
|
98
|
-
tracedToolset[name] = {
|
|
99
|
-
...tool,
|
|
100
|
-
execute: async (input, options) => {
|
|
101
|
-
hooks?.beforeExecute?.(name);
|
|
102
|
-
return await llmobs.trace({
|
|
103
|
-
kind: "tool",
|
|
104
|
-
name: `tool.${name}`,
|
|
105
|
-
}, async (span) => {
|
|
106
|
-
if (!tool.execute) {
|
|
107
|
-
throw new Error(`Tool ${name} has no execute method`);
|
|
108
|
-
}
|
|
109
|
-
const result = await tool.execute(input, options);
|
|
110
|
-
hooks?.afterExecute?.(name, span);
|
|
111
|
-
const metadata = {
|
|
112
|
-
toolCallid: options?.toolCallId,
|
|
113
|
-
...Object.fromEntries(Object.entries(tool).map(([key, value]) => [
|
|
114
|
-
key,
|
|
115
|
-
safeJsonStringify(value),
|
|
116
|
-
])),
|
|
117
|
-
};
|
|
118
|
-
llmobs.annotate(span, {
|
|
119
|
-
inputData: safeJsonStringify(input),
|
|
120
|
-
outputData: safeJsonStringify(result),
|
|
121
|
-
metadata,
|
|
122
|
-
});
|
|
123
|
-
return result;
|
|
124
|
-
});
|
|
125
|
-
},
|
|
126
|
-
};
|
|
127
|
-
}
|
|
128
|
-
return tracedToolset;
|
|
129
|
-
};
|
|
130
90
|
//# sourceMappingURL=helpers.js.map
|