@copilotkit/runtime 2.0.0-rc.8 → 2.0.0-rc.9

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 (68) hide show
  1. package/README.md +19 -1
  2. package/dist/agent/converters/tanstack.cjs +1 -1
  3. package/dist/agent/converters/tanstack.cjs.map +1 -1
  4. package/dist/agent/converters/tanstack.mjs +1 -1
  5. package/dist/agent/converters/tanstack.mjs.map +1 -1
  6. package/dist/agent/index.cjs +9 -8
  7. package/dist/agent/index.cjs.map +1 -1
  8. package/dist/agent/index.d.cts.map +1 -1
  9. package/dist/agent/index.d.mts.map +1 -1
  10. package/dist/agent/index.mjs +9 -8
  11. package/dist/agent/index.mjs.map +1 -1
  12. package/dist/index.cjs +12 -0
  13. package/dist/index.d.cts +4 -1
  14. package/dist/index.d.mts +4 -1
  15. package/dist/index.mjs +4 -1
  16. package/dist/runtime/core/logger.cjs +1 -4
  17. package/dist/runtime/core/logger.cjs.map +1 -1
  18. package/dist/runtime/core/logger.d.cts.map +1 -1
  19. package/dist/runtime/core/logger.d.mts.map +1 -1
  20. package/dist/runtime/core/logger.mjs +1 -3
  21. package/dist/runtime/core/logger.mjs.map +1 -1
  22. package/dist/runtime/core/package-info.cjs +1 -1
  23. package/dist/runtime/core/package-info.mjs +1 -1
  24. package/dist/runtime/core/runtime.d.mts +1 -1
  25. package/dist/runtime/event-transforms/index.d.cts +4 -0
  26. package/dist/runtime/event-transforms/index.d.mts +4 -0
  27. package/dist/runtime/event-transforms/index.mjs +5 -0
  28. package/dist/runtime/event-transforms/open-generative-ui-middleware.cjs +286 -0
  29. package/dist/runtime/event-transforms/open-generative-ui-middleware.cjs.map +1 -0
  30. package/dist/runtime/event-transforms/open-generative-ui-middleware.d.cts +60 -0
  31. package/dist/runtime/event-transforms/open-generative-ui-middleware.d.cts.map +1 -0
  32. package/dist/runtime/event-transforms/open-generative-ui-middleware.d.mts +60 -0
  33. package/dist/runtime/event-transforms/open-generative-ui-middleware.d.mts.map +1 -0
  34. package/dist/runtime/event-transforms/open-generative-ui-middleware.mjs +283 -0
  35. package/dist/runtime/event-transforms/open-generative-ui-middleware.mjs.map +1 -0
  36. package/dist/runtime/event-transforms/recorded-events.cjs +59 -0
  37. package/dist/runtime/event-transforms/recorded-events.cjs.map +1 -0
  38. package/dist/runtime/event-transforms/recorded-events.d.cts +23 -0
  39. package/dist/runtime/event-transforms/recorded-events.d.cts.map +1 -0
  40. package/dist/runtime/event-transforms/recorded-events.d.mts +23 -0
  41. package/dist/runtime/event-transforms/recorded-events.d.mts.map +1 -0
  42. package/dist/runtime/event-transforms/recorded-events.mjs +58 -0
  43. package/dist/runtime/event-transforms/recorded-events.mjs.map +1 -0
  44. package/dist/runtime/handlers/shared/agent-utils.cjs +4 -3
  45. package/dist/runtime/handlers/shared/agent-utils.cjs.map +1 -1
  46. package/dist/runtime/handlers/shared/agent-utils.mjs +2 -1
  47. package/dist/runtime/handlers/shared/agent-utils.mjs.map +1 -1
  48. package/dist/runtime/index.d.cts +3 -0
  49. package/dist/runtime/index.d.mts +3 -0
  50. package/dist/runtime/intelligence-platform/learning-management.cjs +7 -7
  51. package/dist/runtime/intelligence-platform/learning-management.cjs.map +1 -1
  52. package/dist/runtime/intelligence-platform/learning-management.mjs +7 -7
  53. package/dist/runtime/intelligence-platform/learning-management.mjs.map +1 -1
  54. package/dist/runtime/intelligence-platform/skill-registry/archive.cjs +104 -109
  55. package/dist/runtime/intelligence-platform/skill-registry/archive.cjs.map +1 -1
  56. package/dist/runtime/intelligence-platform/skill-registry/archive.d.cts +8 -2
  57. package/dist/runtime/intelligence-platform/skill-registry/archive.d.cts.map +1 -1
  58. package/dist/runtime/intelligence-platform/skill-registry/archive.d.mts +8 -2
  59. package/dist/runtime/intelligence-platform/skill-registry/archive.d.mts.map +1 -1
  60. package/dist/runtime/intelligence-platform/skill-registry/archive.mjs +104 -109
  61. package/dist/runtime/intelligence-platform/skill-registry/archive.mjs.map +1 -1
  62. package/dist/runtime/intelligence-platform/trajectories.cjs +2 -2
  63. package/dist/runtime/intelligence-platform/trajectories.cjs.map +1 -1
  64. package/dist/runtime/intelligence-platform/trajectories.mjs +2 -2
  65. package/dist/runtime/intelligence-platform/trajectories.mjs.map +1 -1
  66. package/dist/runtime/telemetry/disclosure.cjs.map +1 -1
  67. package/dist/runtime/telemetry/disclosure.mjs.map +1 -1
  68. package/package.json +8 -9
package/dist/index.cjs CHANGED
@@ -8,15 +8,25 @@ const require_intelligence = require('./runtime/runner/intelligence.cjs');
8
8
  const require_runtime$1 = require('./runtime/core/runtime.cjs');
9
9
  const require_generative_ui_middleware = require('./runtime/generative-ui/generative-ui-middleware.cjs');
10
10
  const require_surface_writer = require('./runtime/generative-ui/surface-writer.cjs');
11
+ const require_open_generative_ui_middleware = require('./runtime/event-transforms/open-generative-ui-middleware.cjs');
12
+ const require_recorded_events = require('./runtime/event-transforms/recorded-events.cjs');
11
13
  const require_transcription_service = require('./runtime/transcription-service/transcription-service.cjs');
12
14
  const require_fetch_handler = require('./runtime/core/fetch-handler.cjs');
13
15
  const require_url_download = require('./agent/url-download.cjs');
14
16
  const require_aisdk = require('./agent/converters/aisdk.cjs');
15
17
  const require_tanstack = require('./agent/converters/tanstack.cjs');
16
18
  const require_index = require('./agent/index.cjs');
19
+ let _ag_ui_a2ui_middleware = require("@ag-ui/a2ui-middleware");
17
20
  let _copilotkit_shared = require("@copilotkit/shared");
18
21
 
22
+ Object.defineProperty(exports, 'A2UIMiddleware', {
23
+ enumerable: true,
24
+ get: function () {
25
+ return _ag_ui_a2ui_middleware.A2UIMiddleware;
26
+ }
27
+ });
19
28
  exports.AgentRunner = require_agent_runner.AgentRunner;
29
+ exports.ArgsParser = require_open_generative_ui_middleware.ArgsParser;
20
30
  exports.BuiltInAgent = require_index.BuiltInAgent;
21
31
  exports.CopilotIntelligenceRuntime = require_runtime$1.CopilotIntelligenceRuntime;
22
32
  exports.CopilotKitIntelligence = require_client.CopilotKitIntelligence;
@@ -27,6 +37,7 @@ exports.InMemoryAgentRunner = require_in_memory.InMemoryAgentRunner;
27
37
  exports.IntelligenceAgentRunner = require_intelligence.IntelligenceAgentRunner;
28
38
  exports.InterruptSignal = require_index.InterruptSignal;
29
39
  exports.LearnedSkillsError = require_learned_skills.LearnedSkillsError;
40
+ exports.OpenGenerativeUIMiddleware = require_open_generative_ui_middleware.OpenGenerativeUIMiddleware;
30
41
  exports.PlatformRequestError = require_client.PlatformRequestError;
31
42
  exports.THREAD_ACCESS_DENIED_ERROR_CODE = require_agent_runner.THREAD_ACCESS_DENIED_ERROR_CODE;
32
43
  exports.ThreadAccessDeniedError = require_agent_runner.ThreadAccessDeniedError;
@@ -64,6 +75,7 @@ exports.isThreadAccessDeniedError = require_agent_runner.isThreadAccessDeniedErr
64
75
  exports.resolveAgents = require_runtime$1.resolveAgents;
65
76
  exports.resolveModel = require_index.resolveModel;
66
77
  exports.supportsLocalThreadEndpoints = require_agent_runner.supportsLocalThreadEndpoints;
78
+ exports.transformRecordedEvents = require_recorded_events.transformRecordedEvents;
67
79
  exports.ɵBoundedThreadStore = require_in_memory.ɵBoundedThreadStore;
68
80
  exports.ɵGLOBAL_STORE = require_in_memory.ɵGLOBAL_STORE;
69
81
  exports.ɵINMEMORY_DEFAULTS = require_in_memory.ɵINMEMORY_DEFAULTS;
package/dist/index.d.cts CHANGED
@@ -8,6 +8,9 @@ import { CopilotKitIntelligence, CopilotKitIntelligenceConfig, CreateThreadReque
8
8
  import { AgentFactoryContext, AgentsConfig, AgentsFactory, CopilotIntelligenceRuntime, CopilotIntelligenceRuntimeLike, CopilotIntelligenceRuntimeOptions, CopilotRuntime, CopilotRuntimeConstructor, CopilotRuntimeLike, CopilotRuntimeMemoryConfig, CopilotRuntimeOptions, CopilotSseRuntime, CopilotSseRuntimeLike, CopilotSseRuntimeOptions, IdentifyUserCallback, McpAppsConfig, McpAppsServerConfig, MemoryAccess, MemoryConsumer, MemoryGrant, OpenGenerativeUIConfig, OpenGenerativeUIOptions, RuntimeWithDeclaredChannels, VERSION, isA2UIEnabled, isIntelligenceRuntime, resolveAgents } from "./runtime/core/runtime.cjs";
9
9
  import { GenerativeUIMiddleware } from "./runtime/generative-ui/generative-ui-middleware.cjs";
10
10
  import { GenerativeUISurfaceWriter, createSurfaceWriter } from "./runtime/generative-ui/surface-writer.cjs";
11
+ import { ArgsParser, GenerateSandboxedUIParams, OnParamEvent, OpenGenerativeUIMiddleware } from "./runtime/event-transforms/open-generative-ui-middleware.cjs";
12
+ import { RecordedEventTransformOptions, transformRecordedEvents } from "./runtime/event-transforms/recorded-events.cjs";
13
+ import { A2UIMiddleware, A2UIMiddlewareConfig } from "./runtime/event-transforms/index.cjs";
11
14
  import { InMemoryAgentRunner, InMemoryAgentRunnerOptions, InMemoryLimits, InMemoryThread, ɵBoundedThreadStore, ɵGLOBAL_STORE, ɵINMEMORY_DEFAULTS, ɵOWNER_RETENTION_DEFAULTS, ɵOwnerRetention, ɵestimateBytes, ɵnormalizeLimits } from "./runtime/runner/in-memory.cjs";
12
15
  import { IntelligenceAgentRunner, IntelligenceAgentRunnerOptions, RunnerStartupBoundary } from "./runtime/runner/intelligence.cjs";
13
16
  import { FinalizeRunOptions, RunEventFinalizer, createRunEventFinalizer, finalizeRunEvents } from "./runtime/runner/index.cjs";
@@ -21,4 +24,4 @@ import { BuiltInAgentLearnedSkills, BuiltInAgentLearnedSkillsOptions } from "./a
21
24
  import { convertAISDKStream } from "./agent/converters/aisdk.cjs";
22
25
  import { TanStackChatMessage, TanStackInputResult, convertInputToTanStackAI, convertTanStackStream } from "./agent/converters/tanstack.cjs";
23
26
  import { BuiltInAgent, BuiltInAgentAISDKFactoryConfig, BuiltInAgentClassicConfig, BuiltInAgentConfiguration, BuiltInAgentCustomFactoryConfig, BuiltInAgentFactoryConfig, BuiltInAgentFactoryContext, BuiltInAgentModel, BuiltInAgentTanStackFactoryConfig, InterruptSignal, MCPClientConfig, MCPClientConfigHTTP, MCPClientConfigSSE, MCPClientProvider, MessageConversionOptions, ModelSpecifier, OverridableProperty, ToolDefinition, classifyModelSpec, convertJsonSchemaToZodSchema, convertMessagesToVercelAISDKMessages, convertToolDefinitionsToVercelAITools, convertToolsToVercelAITools, defineTool, resolveModel } from "./agent/index.cjs";
24
- export { type AgentFactoryContext, AgentRunner, AgentRunnerConnectRequest, AgentRunnerIsRunningRequest, AgentRunnerRunRequest, AgentRunnerStopRequest, AgentsConfig, AgentsFactory, BuiltInAgent, BuiltInAgentAISDKFactoryConfig, BuiltInAgentClassicConfig, BuiltInAgentConfiguration, BuiltInAgentCustomFactoryConfig, BuiltInAgentFactoryConfig, BuiltInAgentFactoryContext, BuiltInAgentLearnedSkills, BuiltInAgentLearnedSkillsOptions, BuiltInAgentModel, BuiltInAgentTanStackFactoryConfig, ChannelStatus, ChannelsControl, CopilotCorsConfig, CopilotIntelligenceRuntime, CopilotIntelligenceRuntimeLike, CopilotIntelligenceRuntimeOptions, CopilotKitIntelligence, CopilotKitIntelligenceConfig, CopilotRuntime, CopilotRuntimeConstructor, CopilotRuntimeFetchHandler, CopilotRuntimeFetchHandlerWithChannels, CopilotRuntimeHandlerOptions, CopilotRuntimeHooks, CopilotRuntimeLearningConfig, CopilotRuntimeLearningContext, CopilotRuntimeLike, CopilotRuntimeMemoryConfig, CopilotRuntimeOptions, CopilotRuntimeUser, CopilotSseRuntime, CopilotSseRuntimeLike, CopilotSseRuntimeOptions, CreateSafeUrlDownloadOptions, CreateThreadRequest, ErrorHookContext, FinalizeRunOptions, GenerativeUIMiddleware, GenerativeUISurfaceWriter, GetLearnedSkillsSnapshotRequest, GetLearnedSkillsSnapshotsRequest, GetLearningContainerId, GetTrajectoryLearningContainerIds, HandlerHookContext, HookContext, IdentifyUserCallback, InMemoryAgentRunner, InMemoryAgentRunnerOptions, InMemoryLimits, InMemoryThread, IntelligenceAgentRunner, IntelligenceAgentRunnerOptions, InterruptSignal, LearnedSkillsBatchResult, LearnedSkillsError, LearnedSkillsErrorCode, LearnedSkillsSnapshotResult, LearningContainerSelectorInput, ListThreadsResponse, LocalThreadEndpointRecord, LocalThreadEndpointRunner, LocalThreadEndpointScope, MCPClient, MCPClientConfig, MCPClientConfigHTTP, MCPClientConfigSSE, MCPClientProvider, MCPTransport, McpAppsConfig, McpAppsServerConfig, MemoryAccess, MemoryConsumer, MemoryGrant, MessageConversionOptions, ModelSpecifier, OpenGenerativeUIConfig, OpenGenerativeUIOptions, OverridableProperty, PlatformRequestError, ResponseHookContext, RouteInfo, RunEventFinalizer, RunnerStartupBoundary, RuntimeWithDeclaredChannels, SafeUrlDownloadOptions, SubscribeToThreadsRequest, SubscribeToThreadsResponse, THREAD_ACCESS_DENIED_ERROR_CODE, TanStackChatMessage, TanStackInputResult, ThreadAccessDeniedError, ThreadAccessMode, ThreadAlreadyRunningError, ThreadOwnershipRunner, ThreadSummary, ThreadsConfig, ToolDefinition, TrajectoryLearningContainerSelectorInput, TranscribeFileOptions, TranscriptionService, UpdateThreadRequest, VERSION, classifyModelSpec, convertAISDKStream, convertInputToTanStackAI, convertJsonSchemaToZodSchema, convertMessagesToVercelAISDKMessages, convertTanStackStream, convertToolDefinitionsToVercelAITools, convertToolsToVercelAITools, createCopilotRuntimeHandler, createRunEventFinalizer, createSafeUrlDownload, createSurfaceWriter, defineTool, enforcesThreadOwnership, experimental_d_exports as experimental, finalizeRunEvents, isA2UIEnabled, isIntelligenceRuntime, isThreadAccessDeniedError, resolveAgents, resolveModel, supportsLocalThreadEndpoints, ɵBoundedThreadStore, ɵGLOBAL_STORE, ɵINMEMORY_DEFAULTS, ɵOWNER_RETENTION_DEFAULTS, ɵOwnerRetention, ɵSERVER_THREAD_OWNER, ɵestimateBytes, ɵnormalizeLimits, ɵresolveThreadOwner };
27
+ export { A2UIMiddleware, A2UIMiddlewareConfig, type AgentFactoryContext, AgentRunner, AgentRunnerConnectRequest, AgentRunnerIsRunningRequest, AgentRunnerRunRequest, AgentRunnerStopRequest, AgentsConfig, AgentsFactory, ArgsParser, BuiltInAgent, BuiltInAgentAISDKFactoryConfig, BuiltInAgentClassicConfig, BuiltInAgentConfiguration, BuiltInAgentCustomFactoryConfig, BuiltInAgentFactoryConfig, BuiltInAgentFactoryContext, BuiltInAgentLearnedSkills, BuiltInAgentLearnedSkillsOptions, BuiltInAgentModel, BuiltInAgentTanStackFactoryConfig, ChannelStatus, ChannelsControl, CopilotCorsConfig, CopilotIntelligenceRuntime, CopilotIntelligenceRuntimeLike, CopilotIntelligenceRuntimeOptions, CopilotKitIntelligence, CopilotKitIntelligenceConfig, CopilotRuntime, CopilotRuntimeConstructor, CopilotRuntimeFetchHandler, CopilotRuntimeFetchHandlerWithChannels, CopilotRuntimeHandlerOptions, CopilotRuntimeHooks, CopilotRuntimeLearningConfig, CopilotRuntimeLearningContext, CopilotRuntimeLike, CopilotRuntimeMemoryConfig, CopilotRuntimeOptions, CopilotRuntimeUser, CopilotSseRuntime, CopilotSseRuntimeLike, CopilotSseRuntimeOptions, CreateSafeUrlDownloadOptions, CreateThreadRequest, ErrorHookContext, FinalizeRunOptions, GenerateSandboxedUIParams, GenerativeUIMiddleware, GenerativeUISurfaceWriter, GetLearnedSkillsSnapshotRequest, GetLearnedSkillsSnapshotsRequest, GetLearningContainerId, GetTrajectoryLearningContainerIds, HandlerHookContext, HookContext, IdentifyUserCallback, InMemoryAgentRunner, InMemoryAgentRunnerOptions, InMemoryLimits, InMemoryThread, IntelligenceAgentRunner, IntelligenceAgentRunnerOptions, InterruptSignal, LearnedSkillsBatchResult, LearnedSkillsError, LearnedSkillsErrorCode, LearnedSkillsSnapshotResult, LearningContainerSelectorInput, ListThreadsResponse, LocalThreadEndpointRecord, LocalThreadEndpointRunner, LocalThreadEndpointScope, MCPClient, MCPClientConfig, MCPClientConfigHTTP, MCPClientConfigSSE, MCPClientProvider, MCPTransport, McpAppsConfig, McpAppsServerConfig, MemoryAccess, MemoryConsumer, MemoryGrant, MessageConversionOptions, ModelSpecifier, OnParamEvent, OpenGenerativeUIConfig, OpenGenerativeUIMiddleware, OpenGenerativeUIOptions, OverridableProperty, PlatformRequestError, RecordedEventTransformOptions, ResponseHookContext, RouteInfo, RunEventFinalizer, RunnerStartupBoundary, RuntimeWithDeclaredChannels, SafeUrlDownloadOptions, SubscribeToThreadsRequest, SubscribeToThreadsResponse, THREAD_ACCESS_DENIED_ERROR_CODE, TanStackChatMessage, TanStackInputResult, ThreadAccessDeniedError, ThreadAccessMode, ThreadAlreadyRunningError, ThreadOwnershipRunner, ThreadSummary, ThreadsConfig, ToolDefinition, TrajectoryLearningContainerSelectorInput, TranscribeFileOptions, TranscriptionService, UpdateThreadRequest, VERSION, classifyModelSpec, convertAISDKStream, convertInputToTanStackAI, convertJsonSchemaToZodSchema, convertMessagesToVercelAISDKMessages, convertTanStackStream, convertToolDefinitionsToVercelAITools, convertToolsToVercelAITools, createCopilotRuntimeHandler, createRunEventFinalizer, createSafeUrlDownload, createSurfaceWriter, defineTool, enforcesThreadOwnership, experimental_d_exports as experimental, finalizeRunEvents, isA2UIEnabled, isIntelligenceRuntime, isThreadAccessDeniedError, resolveAgents, resolveModel, supportsLocalThreadEndpoints, transformRecordedEvents, ɵBoundedThreadStore, ɵGLOBAL_STORE, ɵINMEMORY_DEFAULTS, ɵOWNER_RETENTION_DEFAULTS, ɵOwnerRetention, ɵSERVER_THREAD_OWNER, ɵestimateBytes, ɵnormalizeLimits, ɵresolveThreadOwner };
package/dist/index.d.mts CHANGED
@@ -8,6 +8,9 @@ import { CopilotKitIntelligence, CopilotKitIntelligenceConfig, CreateThreadReque
8
8
  import { AgentFactoryContext, AgentsConfig, AgentsFactory, CopilotIntelligenceRuntime, CopilotIntelligenceRuntimeLike, CopilotIntelligenceRuntimeOptions, CopilotRuntime, CopilotRuntimeConstructor, CopilotRuntimeLike, CopilotRuntimeMemoryConfig, CopilotRuntimeOptions, CopilotSseRuntime, CopilotSseRuntimeLike, CopilotSseRuntimeOptions, IdentifyUserCallback, McpAppsConfig, McpAppsServerConfig, MemoryAccess, MemoryConsumer, MemoryGrant, OpenGenerativeUIConfig, OpenGenerativeUIOptions, RuntimeWithDeclaredChannels, VERSION, isA2UIEnabled, isIntelligenceRuntime, resolveAgents } from "./runtime/core/runtime.mjs";
9
9
  import { GenerativeUIMiddleware } from "./runtime/generative-ui/generative-ui-middleware.mjs";
10
10
  import { GenerativeUISurfaceWriter, createSurfaceWriter } from "./runtime/generative-ui/surface-writer.mjs";
11
+ import { ArgsParser, GenerateSandboxedUIParams, OnParamEvent, OpenGenerativeUIMiddleware } from "./runtime/event-transforms/open-generative-ui-middleware.mjs";
12
+ import { RecordedEventTransformOptions, transformRecordedEvents } from "./runtime/event-transforms/recorded-events.mjs";
13
+ import { A2UIMiddleware, A2UIMiddlewareConfig } from "./runtime/event-transforms/index.mjs";
11
14
  import { InMemoryAgentRunner, InMemoryAgentRunnerOptions, InMemoryLimits, InMemoryThread, ɵBoundedThreadStore, ɵGLOBAL_STORE, ɵINMEMORY_DEFAULTS, ɵOWNER_RETENTION_DEFAULTS, ɵOwnerRetention, ɵestimateBytes, ɵnormalizeLimits } from "./runtime/runner/in-memory.mjs";
12
15
  import { IntelligenceAgentRunner, IntelligenceAgentRunnerOptions, RunnerStartupBoundary } from "./runtime/runner/intelligence.mjs";
13
16
  import { FinalizeRunOptions, RunEventFinalizer, createRunEventFinalizer, finalizeRunEvents } from "./runtime/runner/index.mjs";
@@ -21,4 +24,4 @@ import { BuiltInAgentLearnedSkills, BuiltInAgentLearnedSkillsOptions } from "./a
21
24
  import { convertAISDKStream } from "./agent/converters/aisdk.mjs";
22
25
  import { TanStackChatMessage, TanStackInputResult, convertInputToTanStackAI, convertTanStackStream } from "./agent/converters/tanstack.mjs";
23
26
  import { BuiltInAgent, BuiltInAgentAISDKFactoryConfig, BuiltInAgentClassicConfig, BuiltInAgentConfiguration, BuiltInAgentCustomFactoryConfig, BuiltInAgentFactoryConfig, BuiltInAgentFactoryContext, BuiltInAgentModel, BuiltInAgentTanStackFactoryConfig, InterruptSignal, MCPClientConfig, MCPClientConfigHTTP, MCPClientConfigSSE, MCPClientProvider, MessageConversionOptions, ModelSpecifier, OverridableProperty, ToolDefinition, classifyModelSpec, convertJsonSchemaToZodSchema, convertMessagesToVercelAISDKMessages, convertToolDefinitionsToVercelAITools, convertToolsToVercelAITools, defineTool, resolveModel } from "./agent/index.mjs";
24
- export { type AgentFactoryContext, AgentRunner, AgentRunnerConnectRequest, AgentRunnerIsRunningRequest, AgentRunnerRunRequest, AgentRunnerStopRequest, AgentsConfig, AgentsFactory, BuiltInAgent, BuiltInAgentAISDKFactoryConfig, BuiltInAgentClassicConfig, BuiltInAgentConfiguration, BuiltInAgentCustomFactoryConfig, BuiltInAgentFactoryConfig, BuiltInAgentFactoryContext, BuiltInAgentLearnedSkills, BuiltInAgentLearnedSkillsOptions, BuiltInAgentModel, BuiltInAgentTanStackFactoryConfig, ChannelStatus, ChannelsControl, CopilotCorsConfig, CopilotIntelligenceRuntime, CopilotIntelligenceRuntimeLike, CopilotIntelligenceRuntimeOptions, CopilotKitIntelligence, CopilotKitIntelligenceConfig, CopilotRuntime, CopilotRuntimeConstructor, CopilotRuntimeFetchHandler, CopilotRuntimeFetchHandlerWithChannels, CopilotRuntimeHandlerOptions, CopilotRuntimeHooks, CopilotRuntimeLearningConfig, CopilotRuntimeLearningContext, CopilotRuntimeLike, CopilotRuntimeMemoryConfig, CopilotRuntimeOptions, CopilotRuntimeUser, CopilotSseRuntime, CopilotSseRuntimeLike, CopilotSseRuntimeOptions, CreateSafeUrlDownloadOptions, CreateThreadRequest, ErrorHookContext, FinalizeRunOptions, GenerativeUIMiddleware, GenerativeUISurfaceWriter, GetLearnedSkillsSnapshotRequest, GetLearnedSkillsSnapshotsRequest, GetLearningContainerId, GetTrajectoryLearningContainerIds, HandlerHookContext, HookContext, IdentifyUserCallback, InMemoryAgentRunner, InMemoryAgentRunnerOptions, InMemoryLimits, InMemoryThread, IntelligenceAgentRunner, IntelligenceAgentRunnerOptions, InterruptSignal, LearnedSkillsBatchResult, LearnedSkillsError, LearnedSkillsErrorCode, LearnedSkillsSnapshotResult, LearningContainerSelectorInput, ListThreadsResponse, LocalThreadEndpointRecord, LocalThreadEndpointRunner, LocalThreadEndpointScope, MCPClient, MCPClientConfig, MCPClientConfigHTTP, MCPClientConfigSSE, MCPClientProvider, MCPTransport, McpAppsConfig, McpAppsServerConfig, MemoryAccess, MemoryConsumer, MemoryGrant, MessageConversionOptions, ModelSpecifier, OpenGenerativeUIConfig, OpenGenerativeUIOptions, OverridableProperty, PlatformRequestError, ResponseHookContext, RouteInfo, RunEventFinalizer, RunnerStartupBoundary, RuntimeWithDeclaredChannels, SafeUrlDownloadOptions, SubscribeToThreadsRequest, SubscribeToThreadsResponse, THREAD_ACCESS_DENIED_ERROR_CODE, TanStackChatMessage, TanStackInputResult, ThreadAccessDeniedError, ThreadAccessMode, ThreadAlreadyRunningError, ThreadOwnershipRunner, ThreadSummary, ThreadsConfig, ToolDefinition, TrajectoryLearningContainerSelectorInput, TranscribeFileOptions, TranscriptionService, UpdateThreadRequest, VERSION, classifyModelSpec, convertAISDKStream, convertInputToTanStackAI, convertJsonSchemaToZodSchema, convertMessagesToVercelAISDKMessages, convertTanStackStream, convertToolDefinitionsToVercelAITools, convertToolsToVercelAITools, createCopilotRuntimeHandler, createRunEventFinalizer, createSafeUrlDownload, createSurfaceWriter, defineTool, enforcesThreadOwnership, experimental_d_exports as experimental, finalizeRunEvents, isA2UIEnabled, isIntelligenceRuntime, isThreadAccessDeniedError, resolveAgents, resolveModel, supportsLocalThreadEndpoints, ɵBoundedThreadStore, ɵGLOBAL_STORE, ɵINMEMORY_DEFAULTS, ɵOWNER_RETENTION_DEFAULTS, ɵOwnerRetention, ɵSERVER_THREAD_OWNER, ɵestimateBytes, ɵnormalizeLimits, ɵresolveThreadOwner };
27
+ export { A2UIMiddleware, A2UIMiddlewareConfig, type AgentFactoryContext, AgentRunner, AgentRunnerConnectRequest, AgentRunnerIsRunningRequest, AgentRunnerRunRequest, AgentRunnerStopRequest, AgentsConfig, AgentsFactory, ArgsParser, BuiltInAgent, BuiltInAgentAISDKFactoryConfig, BuiltInAgentClassicConfig, BuiltInAgentConfiguration, BuiltInAgentCustomFactoryConfig, BuiltInAgentFactoryConfig, BuiltInAgentFactoryContext, BuiltInAgentLearnedSkills, BuiltInAgentLearnedSkillsOptions, BuiltInAgentModel, BuiltInAgentTanStackFactoryConfig, ChannelStatus, ChannelsControl, CopilotCorsConfig, CopilotIntelligenceRuntime, CopilotIntelligenceRuntimeLike, CopilotIntelligenceRuntimeOptions, CopilotKitIntelligence, CopilotKitIntelligenceConfig, CopilotRuntime, CopilotRuntimeConstructor, CopilotRuntimeFetchHandler, CopilotRuntimeFetchHandlerWithChannels, CopilotRuntimeHandlerOptions, CopilotRuntimeHooks, CopilotRuntimeLearningConfig, CopilotRuntimeLearningContext, CopilotRuntimeLike, CopilotRuntimeMemoryConfig, CopilotRuntimeOptions, CopilotRuntimeUser, CopilotSseRuntime, CopilotSseRuntimeLike, CopilotSseRuntimeOptions, CreateSafeUrlDownloadOptions, CreateThreadRequest, ErrorHookContext, FinalizeRunOptions, GenerateSandboxedUIParams, GenerativeUIMiddleware, GenerativeUISurfaceWriter, GetLearnedSkillsSnapshotRequest, GetLearnedSkillsSnapshotsRequest, GetLearningContainerId, GetTrajectoryLearningContainerIds, HandlerHookContext, HookContext, IdentifyUserCallback, InMemoryAgentRunner, InMemoryAgentRunnerOptions, InMemoryLimits, InMemoryThread, IntelligenceAgentRunner, IntelligenceAgentRunnerOptions, InterruptSignal, LearnedSkillsBatchResult, LearnedSkillsError, LearnedSkillsErrorCode, LearnedSkillsSnapshotResult, LearningContainerSelectorInput, ListThreadsResponse, LocalThreadEndpointRecord, LocalThreadEndpointRunner, LocalThreadEndpointScope, MCPClient, MCPClientConfig, MCPClientConfigHTTP, MCPClientConfigSSE, MCPClientProvider, MCPTransport, McpAppsConfig, McpAppsServerConfig, MemoryAccess, MemoryConsumer, MemoryGrant, MessageConversionOptions, ModelSpecifier, OnParamEvent, OpenGenerativeUIConfig, OpenGenerativeUIMiddleware, OpenGenerativeUIOptions, OverridableProperty, PlatformRequestError, RecordedEventTransformOptions, ResponseHookContext, RouteInfo, RunEventFinalizer, RunnerStartupBoundary, RuntimeWithDeclaredChannels, SafeUrlDownloadOptions, SubscribeToThreadsRequest, SubscribeToThreadsResponse, THREAD_ACCESS_DENIED_ERROR_CODE, TanStackChatMessage, TanStackInputResult, ThreadAccessDeniedError, ThreadAccessMode, ThreadAlreadyRunningError, ThreadOwnershipRunner, ThreadSummary, ThreadsConfig, ToolDefinition, TrajectoryLearningContainerSelectorInput, TranscribeFileOptions, TranscriptionService, UpdateThreadRequest, VERSION, classifyModelSpec, convertAISDKStream, convertInputToTanStackAI, convertJsonSchemaToZodSchema, convertMessagesToVercelAISDKMessages, convertTanStackStream, convertToolDefinitionsToVercelAITools, convertToolsToVercelAITools, createCopilotRuntimeHandler, createRunEventFinalizer, createSafeUrlDownload, createSurfaceWriter, defineTool, enforcesThreadOwnership, experimental_d_exports as experimental, finalizeRunEvents, isA2UIEnabled, isIntelligenceRuntime, isThreadAccessDeniedError, resolveAgents, resolveModel, supportsLocalThreadEndpoints, transformRecordedEvents, ɵBoundedThreadStore, ɵGLOBAL_STORE, ɵINMEMORY_DEFAULTS, ɵOWNER_RETENTION_DEFAULTS, ɵOwnerRetention, ɵSERVER_THREAD_OWNER, ɵestimateBytes, ɵnormalizeLimits, ɵresolveThreadOwner };
package/dist/index.mjs CHANGED
@@ -6,6 +6,9 @@ import { IntelligenceAgentRunner } from "./runtime/runner/intelligence.mjs";
6
6
  import { CopilotIntelligenceRuntime, CopilotRuntime, CopilotSseRuntime, VERSION, isA2UIEnabled, isIntelligenceRuntime, resolveAgents } from "./runtime/core/runtime.mjs";
7
7
  import { GenerativeUIMiddleware } from "./runtime/generative-ui/generative-ui-middleware.mjs";
8
8
  import { createSurfaceWriter } from "./runtime/generative-ui/surface-writer.mjs";
9
+ import { ArgsParser, OpenGenerativeUIMiddleware } from "./runtime/event-transforms/open-generative-ui-middleware.mjs";
10
+ import { transformRecordedEvents } from "./runtime/event-transforms/recorded-events.mjs";
11
+ import { A2UIMiddleware } from "./runtime/event-transforms/index.mjs";
9
12
  import { createRunEventFinalizer, finalizeRunEvents } from "./runtime/runner/index.mjs";
10
13
  import { TranscriptionService } from "./runtime/transcription-service/transcription-service.mjs";
11
14
  import { createCopilotRuntimeHandler } from "./runtime/core/fetch-handler.mjs";
@@ -14,4 +17,4 @@ import { convertAISDKStream } from "./agent/converters/aisdk.mjs";
14
17
  import { convertInputToTanStackAI, convertTanStackStream } from "./agent/converters/tanstack.mjs";
15
18
  import { BuiltInAgent, InterruptSignal, classifyModelSpec, convertJsonSchemaToZodSchema, convertMessagesToVercelAISDKMessages, convertToolDefinitionsToVercelAITools, convertToolsToVercelAITools, defineTool, resolveModel } from "./agent/index.mjs";
16
19
 
17
- export { AgentRunner, BuiltInAgent, CopilotIntelligenceRuntime, CopilotKitIntelligence, CopilotRuntime, CopilotSseRuntime, GenerativeUIMiddleware, InMemoryAgentRunner, IntelligenceAgentRunner, InterruptSignal, LearnedSkillsError, PlatformRequestError, THREAD_ACCESS_DENIED_ERROR_CODE, ThreadAccessDeniedError, ThreadAlreadyRunningError, TranscriptionService, VERSION, classifyModelSpec, convertAISDKStream, convertInputToTanStackAI, convertJsonSchemaToZodSchema, convertMessagesToVercelAISDKMessages, convertTanStackStream, convertToolDefinitionsToVercelAITools, convertToolsToVercelAITools, createCopilotRuntimeHandler, createRunEventFinalizer, createSafeUrlDownload, createSurfaceWriter, defineTool, enforcesThreadOwnership, finalizeRunEvents, isA2UIEnabled, isIntelligenceRuntime, isThreadAccessDeniedError, resolveAgents, resolveModel, supportsLocalThreadEndpoints, ɵBoundedThreadStore, ɵGLOBAL_STORE, ɵINMEMORY_DEFAULTS, ɵOWNER_RETENTION_DEFAULTS, ɵSERVER_THREAD_OWNER, ɵestimateBytes, ɵnormalizeLimits, ɵresolveThreadOwner };
20
+ export { A2UIMiddleware, AgentRunner, ArgsParser, BuiltInAgent, CopilotIntelligenceRuntime, CopilotKitIntelligence, CopilotRuntime, CopilotSseRuntime, GenerativeUIMiddleware, InMemoryAgentRunner, IntelligenceAgentRunner, InterruptSignal, LearnedSkillsError, OpenGenerativeUIMiddleware, PlatformRequestError, THREAD_ACCESS_DENIED_ERROR_CODE, ThreadAccessDeniedError, ThreadAlreadyRunningError, TranscriptionService, VERSION, classifyModelSpec, convertAISDKStream, convertInputToTanStackAI, convertJsonSchemaToZodSchema, convertMessagesToVercelAISDKMessages, convertTanStackStream, convertToolDefinitionsToVercelAITools, convertToolsToVercelAITools, createCopilotRuntimeHandler, createRunEventFinalizer, createSafeUrlDownload, createSurfaceWriter, defineTool, enforcesThreadOwnership, finalizeRunEvents, isA2UIEnabled, isIntelligenceRuntime, isThreadAccessDeniedError, resolveAgents, resolveModel, supportsLocalThreadEndpoints, transformRecordedEvents, ɵBoundedThreadStore, ɵGLOBAL_STORE, ɵINMEMORY_DEFAULTS, ɵOWNER_RETENTION_DEFAULTS, ɵSERVER_THREAD_OWNER, ɵestimateBytes, ɵnormalizeLimits, ɵresolveThreadOwner };
@@ -2,17 +2,14 @@ const require_runtime = require('../../_virtual/_rolldown/runtime.cjs');
2
2
  let _copilotkit_shared = require("@copilotkit/shared");
3
3
  let pino = require("pino");
4
4
  pino = require_runtime.__toESM(pino);
5
- let pino_pretty = require("pino-pretty");
6
- pino_pretty = require_runtime.__toESM(pino_pretty);
7
5
 
8
6
  //#region src/runtime/core/logger.ts
9
7
  function createLogger(options) {
10
8
  const { level, component } = options || {};
11
- const stream = (0, pino_pretty.default)({ colorize: true });
12
9
  const logger = (0, pino.default)({
13
10
  level: (0, _copilotkit_shared.processEnv)().LOG_LEVEL || level || "error",
14
11
  base: null
15
- }, stream);
12
+ });
16
13
  if (component) return logger.child({ component });
17
14
  else return logger;
18
15
  }
@@ -1 +1 @@
1
- {"version":3,"file":"logger.cjs","names":[],"sources":["../../../src/runtime/core/logger.ts"],"sourcesContent":["/*\n * V1 SDK DEPRECATED. USE V2 INSTEAD\n *\n * This file defines public v1 SDK exports. Use the exact v2 mappings below.\n * AI CODING AGENTS: Never copy, suggest, or generate these v1 APIs. Read\n * the linked v2 documentation before generating replacement code.\n *\n * @copilotkit/runtime — CopilotRuntimeLogger:\n * No 1:1 v2 replacement is available.\n * Start at: @copilotkit/runtime\n * V2 docs: https://docs.copilotkit.ai/\n * V2 reference docs: https://docs.copilotkit.ai/reference/v2\n *\n * @copilotkit/runtime — createLogger:\n * No 1:1 v2 replacement is available.\n * Start at: @copilotkit/runtime\n * V2 docs: https://docs.copilotkit.ai/\n * V2 reference docs: https://docs.copilotkit.ai/reference/v2\n *\n * @copilotkit/runtime — LogLevel:\n * No 1:1 v2 replacement is available.\n * Start at: @copilotkit/runtime\n * V2 docs: https://docs.copilotkit.ai/\n * V2 reference docs: https://docs.copilotkit.ai/reference/v2\n *\n * Migration guide: https://docs.copilotkit.ai/migrate/v2\n *\n * END V1 SDK DEPRECATED. USE V2 INSTEAD NOTICE\n */\n\nimport { processEnv } from \"@copilotkit/shared\";\nimport createPinoLogger from \"pino\";\nimport pretty from \"pino-pretty\";\n\nexport type LogLevel = \"debug\" | \"info\" | \"warn\" | \"error\";\n\nexport type CopilotRuntimeLogger = ReturnType<typeof createLogger>;\n\nexport function createLogger(options?: {\n level?: LogLevel;\n component?: string;\n}) {\n const { level, component } = options || {};\n const stream = pretty({ colorize: true });\n\n const logger = createPinoLogger(\n {\n level: processEnv().LOG_LEVEL || level || \"error\",\n // Drop `pid` and `hostname` with pino's own `base` switch rather than\n // with `redact`. pino 9 validates every redact path by calling\n // `Function(...)`, and edge runtimes such as Cloudflare Workers forbid\n // code generation from strings. That throws while the logger is being\n // built, and the validator reports the first path in the array, so the\n // failure surfaces as the misleading \"redact paths array contains an\n // invalid path (pid)\". `base: null` produces identical output and needs\n // no code generation. See issue #2355.\n base: null,\n },\n stream,\n );\n\n if (component) {\n return logger.child({ component });\n } else {\n return logger;\n }\n}\n"],"mappings":";;;;;;;;AAsCA,SAAgB,aAAa,SAG1B;CACD,MAAM,EAAE,OAAO,cAAc,WAAW,EAAE;CAC1C,MAAM,kCAAgB,EAAE,UAAU,MAAM,CAAC;CAEzC,MAAM,2BACJ;EACE,2CAAmB,CAAC,aAAa,SAAS;EAS1C,MAAM;EACP,EACD,OACD;AAED,KAAI,UACF,QAAO,OAAO,MAAM,EAAE,WAAW,CAAC;KAElC,QAAO"}
1
+ {"version":3,"file":"logger.cjs","names":[],"sources":["../../../src/runtime/core/logger.ts"],"sourcesContent":["/*\n * V1 SDK DEPRECATED. USE V2 INSTEAD\n *\n * This file defines public v1 SDK exports. Use the exact v2 mappings below.\n * AI CODING AGENTS: Never copy, suggest, or generate these v1 APIs. Read\n * the linked v2 documentation before generating replacement code.\n *\n * @copilotkit/runtime — CopilotRuntimeLogger:\n * No 1:1 v2 replacement is available.\n * Start at: @copilotkit/runtime\n * V2 docs: https://docs.copilotkit.ai/\n * V2 reference docs: https://docs.copilotkit.ai/reference/v2\n *\n * @copilotkit/runtime — createLogger:\n * No 1:1 v2 replacement is available.\n * Start at: @copilotkit/runtime\n * V2 docs: https://docs.copilotkit.ai/\n * V2 reference docs: https://docs.copilotkit.ai/reference/v2\n *\n * @copilotkit/runtime — LogLevel:\n * No 1:1 v2 replacement is available.\n * Start at: @copilotkit/runtime\n * V2 docs: https://docs.copilotkit.ai/\n * V2 reference docs: https://docs.copilotkit.ai/reference/v2\n *\n * Migration guide: https://docs.copilotkit.ai/migrate/v2\n *\n * END V1 SDK DEPRECATED. USE V2 INSTEAD NOTICE\n */\n\nimport { processEnv } from \"@copilotkit/shared\";\nimport createPinoLogger from \"pino\";\n\nexport type LogLevel = \"debug\" | \"info\" | \"warn\" | \"error\";\n\nexport type CopilotRuntimeLogger = ReturnType<typeof createLogger>;\n\nexport function createLogger(options?: {\n level?: LogLevel;\n component?: string;\n}) {\n const { level, component } = options || {};\n\n // Plain pino JSON lines on stdout. `pino-pretty` is a dev tool that needs\n // Node streams, so the runtime does not ship it; pipe the output through\n // `npx pino-pretty` to read it formatted.\n const logger = createPinoLogger({\n level: processEnv().LOG_LEVEL || level || \"error\",\n // Drop `pid` and `hostname` with pino's own `base` switch rather than\n // with `redact`. pino 9 validates every redact path by calling\n // `Function(...)`, and edge runtimes such as Cloudflare Workers forbid\n // code generation from strings. That throws while the logger is being\n // built, and the validator reports the first path in the array, so the\n // failure surfaces as the misleading \"redact paths array contains an\n // invalid path (pid)\". `base: null` produces identical output and needs\n // no code generation. See issue #2355.\n base: null,\n });\n\n if (component) {\n return logger.child({ component });\n } else {\n return logger;\n }\n}\n"],"mappings":";;;;;;AAqCA,SAAgB,aAAa,SAG1B;CACD,MAAM,EAAE,OAAO,cAAc,WAAW,EAAE;CAK1C,MAAM,2BAA0B;EAC9B,2CAAmB,CAAC,aAAa,SAAS;EAS1C,MAAM;EACP,CAAC;AAEF,KAAI,UACF,QAAO,OAAO,MAAM,EAAE,WAAW,CAAC;KAElC,QAAO"}
@@ -1 +1 @@
1
- {"version":3,"file":"logger.d.cts","names":[],"sources":["../../../src/runtime/core/logger.ts"],"mappings":";;;KAkCY,QAAA;AAAA,KAEA,oBAAA,GAAuB,UAAA,QAAkB,YAAA;AAAA,iBAErC,YAAA,CAAa,OAAA;EAC3B,KAAA,GAAQ,QAAA;EACR,SAAA;AAAA,IACD,gBAAA,CAAA,MAAA"}
1
+ {"version":3,"file":"logger.d.cts","names":[],"sources":["../../../src/runtime/core/logger.ts"],"mappings":";;;KAiCY,QAAA;AAAA,KAEA,oBAAA,GAAuB,UAAA,QAAkB,YAAA;AAAA,iBAErC,YAAA,CAAa,OAAA;EAC3B,KAAA,GAAQ,QAAA;EACR,SAAA;AAAA,IACD,gBAAA,CAAA,MAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"logger.d.mts","names":[],"sources":["../../../src/runtime/core/logger.ts"],"mappings":";;;KAkCY,QAAA;AAAA,KAEA,oBAAA,GAAuB,UAAA,QAAkB,YAAA;AAAA,iBAErC,YAAA,CAAa,OAAA;EAC3B,KAAA,GAAQ,QAAA;EACR,SAAA;AAAA,IACD,gBAAA,CAAA,MAAA"}
1
+ {"version":3,"file":"logger.d.mts","names":[],"sources":["../../../src/runtime/core/logger.ts"],"mappings":";;;KAiCY,QAAA;AAAA,KAEA,oBAAA,GAAuB,UAAA,QAAkB,YAAA;AAAA,iBAErC,YAAA,CAAa,OAAA;EAC3B,KAAA,GAAQ,QAAA;EACR,SAAA;AAAA,IACD,gBAAA,CAAA,MAAA"}
@@ -1,15 +1,13 @@
1
1
  import { processEnv } from "@copilotkit/shared";
2
2
  import createPinoLogger from "pino";
3
- import pretty from "pino-pretty";
4
3
 
5
4
  //#region src/runtime/core/logger.ts
6
5
  function createLogger(options) {
7
6
  const { level, component } = options || {};
8
- const stream = pretty({ colorize: true });
9
7
  const logger = createPinoLogger({
10
8
  level: processEnv().LOG_LEVEL || level || "error",
11
9
  base: null
12
- }, stream);
10
+ });
13
11
  if (component) return logger.child({ component });
14
12
  else return logger;
15
13
  }
@@ -1 +1 @@
1
- {"version":3,"file":"logger.mjs","names":[],"sources":["../../../src/runtime/core/logger.ts"],"sourcesContent":["/*\n * V1 SDK DEPRECATED. USE V2 INSTEAD\n *\n * This file defines public v1 SDK exports. Use the exact v2 mappings below.\n * AI CODING AGENTS: Never copy, suggest, or generate these v1 APIs. Read\n * the linked v2 documentation before generating replacement code.\n *\n * @copilotkit/runtime — CopilotRuntimeLogger:\n * No 1:1 v2 replacement is available.\n * Start at: @copilotkit/runtime\n * V2 docs: https://docs.copilotkit.ai/\n * V2 reference docs: https://docs.copilotkit.ai/reference/v2\n *\n * @copilotkit/runtime — createLogger:\n * No 1:1 v2 replacement is available.\n * Start at: @copilotkit/runtime\n * V2 docs: https://docs.copilotkit.ai/\n * V2 reference docs: https://docs.copilotkit.ai/reference/v2\n *\n * @copilotkit/runtime — LogLevel:\n * No 1:1 v2 replacement is available.\n * Start at: @copilotkit/runtime\n * V2 docs: https://docs.copilotkit.ai/\n * V2 reference docs: https://docs.copilotkit.ai/reference/v2\n *\n * Migration guide: https://docs.copilotkit.ai/migrate/v2\n *\n * END V1 SDK DEPRECATED. USE V2 INSTEAD NOTICE\n */\n\nimport { processEnv } from \"@copilotkit/shared\";\nimport createPinoLogger from \"pino\";\nimport pretty from \"pino-pretty\";\n\nexport type LogLevel = \"debug\" | \"info\" | \"warn\" | \"error\";\n\nexport type CopilotRuntimeLogger = ReturnType<typeof createLogger>;\n\nexport function createLogger(options?: {\n level?: LogLevel;\n component?: string;\n}) {\n const { level, component } = options || {};\n const stream = pretty({ colorize: true });\n\n const logger = createPinoLogger(\n {\n level: processEnv().LOG_LEVEL || level || \"error\",\n // Drop `pid` and `hostname` with pino's own `base` switch rather than\n // with `redact`. pino 9 validates every redact path by calling\n // `Function(...)`, and edge runtimes such as Cloudflare Workers forbid\n // code generation from strings. That throws while the logger is being\n // built, and the validator reports the first path in the array, so the\n // failure surfaces as the misleading \"redact paths array contains an\n // invalid path (pid)\". `base: null` produces identical output and needs\n // no code generation. See issue #2355.\n base: null,\n },\n stream,\n );\n\n if (component) {\n return logger.child({ component });\n } else {\n return logger;\n }\n}\n"],"mappings":";;;;;AAsCA,SAAgB,aAAa,SAG1B;CACD,MAAM,EAAE,OAAO,cAAc,WAAW,EAAE;CAC1C,MAAM,SAAS,OAAO,EAAE,UAAU,MAAM,CAAC;CAEzC,MAAM,SAAS,iBACb;EACE,OAAO,YAAY,CAAC,aAAa,SAAS;EAS1C,MAAM;EACP,EACD,OACD;AAED,KAAI,UACF,QAAO,OAAO,MAAM,EAAE,WAAW,CAAC;KAElC,QAAO"}
1
+ {"version":3,"file":"logger.mjs","names":[],"sources":["../../../src/runtime/core/logger.ts"],"sourcesContent":["/*\n * V1 SDK DEPRECATED. USE V2 INSTEAD\n *\n * This file defines public v1 SDK exports. Use the exact v2 mappings below.\n * AI CODING AGENTS: Never copy, suggest, or generate these v1 APIs. Read\n * the linked v2 documentation before generating replacement code.\n *\n * @copilotkit/runtime — CopilotRuntimeLogger:\n * No 1:1 v2 replacement is available.\n * Start at: @copilotkit/runtime\n * V2 docs: https://docs.copilotkit.ai/\n * V2 reference docs: https://docs.copilotkit.ai/reference/v2\n *\n * @copilotkit/runtime — createLogger:\n * No 1:1 v2 replacement is available.\n * Start at: @copilotkit/runtime\n * V2 docs: https://docs.copilotkit.ai/\n * V2 reference docs: https://docs.copilotkit.ai/reference/v2\n *\n * @copilotkit/runtime — LogLevel:\n * No 1:1 v2 replacement is available.\n * Start at: @copilotkit/runtime\n * V2 docs: https://docs.copilotkit.ai/\n * V2 reference docs: https://docs.copilotkit.ai/reference/v2\n *\n * Migration guide: https://docs.copilotkit.ai/migrate/v2\n *\n * END V1 SDK DEPRECATED. USE V2 INSTEAD NOTICE\n */\n\nimport { processEnv } from \"@copilotkit/shared\";\nimport createPinoLogger from \"pino\";\n\nexport type LogLevel = \"debug\" | \"info\" | \"warn\" | \"error\";\n\nexport type CopilotRuntimeLogger = ReturnType<typeof createLogger>;\n\nexport function createLogger(options?: {\n level?: LogLevel;\n component?: string;\n}) {\n const { level, component } = options || {};\n\n // Plain pino JSON lines on stdout. `pino-pretty` is a dev tool that needs\n // Node streams, so the runtime does not ship it; pipe the output through\n // `npx pino-pretty` to read it formatted.\n const logger = createPinoLogger({\n level: processEnv().LOG_LEVEL || level || \"error\",\n // Drop `pid` and `hostname` with pino's own `base` switch rather than\n // with `redact`. pino 9 validates every redact path by calling\n // `Function(...)`, and edge runtimes such as Cloudflare Workers forbid\n // code generation from strings. That throws while the logger is being\n // built, and the validator reports the first path in the array, so the\n // failure surfaces as the misleading \"redact paths array contains an\n // invalid path (pid)\". `base: null` produces identical output and needs\n // no code generation. See issue #2355.\n base: null,\n });\n\n if (component) {\n return logger.child({ component });\n } else {\n return logger;\n }\n}\n"],"mappings":";;;;AAqCA,SAAgB,aAAa,SAG1B;CACD,MAAM,EAAE,OAAO,cAAc,WAAW,EAAE;CAK1C,MAAM,SAAS,iBAAiB;EAC9B,OAAO,YAAY,CAAC,aAAa,SAAS;EAS1C,MAAM;EACP,CAAC;AAEF,KAAI,UACF,QAAO,OAAO,MAAM,EAAE,WAAW,CAAC;KAElC,QAAO"}
@@ -1,7 +1,7 @@
1
1
 
2
2
  //#region src/runtime/core/package-info.ts
3
3
  const RUNTIME_PACKAGE_NAME = "@copilotkit/runtime";
4
- const RUNTIME_PACKAGE_VERSION = "2.0.0-rc.8";
4
+ const RUNTIME_PACKAGE_VERSION = "2.0.0-rc.9";
5
5
 
6
6
  //#endregion
7
7
  exports.RUNTIME_PACKAGE_NAME = RUNTIME_PACKAGE_NAME;
@@ -1,6 +1,6 @@
1
1
  //#region src/runtime/core/package-info.ts
2
2
  const RUNTIME_PACKAGE_NAME = "@copilotkit/runtime";
3
- const RUNTIME_PACKAGE_VERSION = "2.0.0-rc.8";
3
+ const RUNTIME_PACKAGE_VERSION = "2.0.0-rc.9";
4
4
 
5
5
  //#endregion
6
6
  export { RUNTIME_PACKAGE_NAME, RUNTIME_PACKAGE_VERSION };
@@ -12,8 +12,8 @@ import { TelemetryCapture } from "../telemetry/telemetry-client.mjs";
12
12
  import { DebugConfig, MaybePromise, NonEmptyRecord, RUNTIME_MODE_INTELLIGENCE, RUNTIME_MODE_SSE, ResolvedDebugConfig, RuntimeMode } from "@copilotkit/shared";
13
13
  import { LicenseChecker } from "@copilotkit/license-verifier";
14
14
  import { AbstractAgent } from "@ag-ui/client";
15
- import { MCPClientConfig } from "@ag-ui/mcp-apps-middleware";
16
15
  import { A2UIMiddlewareConfig } from "@ag-ui/a2ui-middleware";
16
+ import { MCPClientConfig } from "@ag-ui/mcp-apps-middleware";
17
17
  import { Channel } from "@copilotkit/channels-core";
18
18
 
19
19
  //#region src/runtime/core/runtime.d.ts
@@ -0,0 +1,4 @@
1
+ import { ArgsParser, GenerateSandboxedUIParams, OnParamEvent, OpenGenerativeUIMiddleware } from "./open-generative-ui-middleware.cjs";
2
+ import { RecordedEventTransformOptions, transformRecordedEvents } from "./recorded-events.cjs";
3
+ import { A2UIMiddleware, A2UIMiddlewareConfig as A2UIMiddlewareConfig$1 } from "@ag-ui/a2ui-middleware";
4
+ export { A2UIMiddleware, type A2UIMiddlewareConfig$1 as A2UIMiddlewareConfig };
@@ -0,0 +1,4 @@
1
+ import { ArgsParser, GenerateSandboxedUIParams, OnParamEvent, OpenGenerativeUIMiddleware } from "./open-generative-ui-middleware.mjs";
2
+ import { RecordedEventTransformOptions, transformRecordedEvents } from "./recorded-events.mjs";
3
+ import { A2UIMiddleware as A2UIMiddleware$1, A2UIMiddlewareConfig as A2UIMiddlewareConfig$1 } from "@ag-ui/a2ui-middleware";
4
+ export { A2UIMiddleware$1 as A2UIMiddleware, type A2UIMiddlewareConfig$1 as A2UIMiddlewareConfig };
@@ -0,0 +1,5 @@
1
+ import { ArgsParser, OpenGenerativeUIMiddleware } from "./open-generative-ui-middleware.mjs";
2
+ import { transformRecordedEvents } from "./recorded-events.mjs";
3
+ import { A2UIMiddleware as A2UIMiddleware$1 } from "@ag-ui/a2ui-middleware";
4
+
5
+ export { A2UIMiddleware$1 as A2UIMiddleware };
@@ -0,0 +1,286 @@
1
+ const require_runtime = require('../../_virtual/_rolldown/runtime.cjs');
2
+ let rxjs = require("rxjs");
3
+ let _ag_ui_client = require("@ag-ui/client");
4
+ let clarinet = require("clarinet");
5
+ clarinet = require_runtime.__toESM(clarinet);
6
+
7
+ //#region src/runtime/event-transforms/open-generative-ui-middleware.ts
8
+ const TOOL_NAME = "generateSandboxedUi";
9
+ const ACTIVITY_TYPE = "open-generative-ui";
10
+ /**
11
+ * Tracks incremental JSON parsing state for a single tool call's arguments.
12
+ * Emits activity events via the onEvent callback as parameters complete.
13
+ */
14
+ var ArgsParser = class {
15
+ constructor(toolCallId, onEvent) {
16
+ this.currentKey = null;
17
+ this.depth = 0;
18
+ this.currentArrayKey = null;
19
+ this.snapshotEmitted = false;
20
+ this.streamingHtmlKey = false;
21
+ this.htmlEmittedLength = 0;
22
+ this.htmlArrayEmitted = false;
23
+ this.params = {};
24
+ this.messageId = `${toolCallId}-activity`;
25
+ this.onEvent = onEvent;
26
+ this.parser = clarinet.default.parser();
27
+ this.parser.onopenobject = (key) => {
28
+ this.depth++;
29
+ if (key !== void 0 && this.depth === 1) {
30
+ this.currentKey = key;
31
+ this.initHtmlStreaming(key);
32
+ }
33
+ };
34
+ this.parser.onkey = (key) => {
35
+ if (this.depth === 1) {
36
+ this.currentKey = key;
37
+ this.initHtmlStreaming(key);
38
+ }
39
+ };
40
+ this.parser.onvalue = (value) => {
41
+ if (this.depth === 1 && this.currentKey) if (this.currentArrayKey) {
42
+ const strValue = String(value);
43
+ if (this.currentArrayKey === "jsExpressions") {
44
+ if (!this.params.jsExpressions) this.params.jsExpressions = [];
45
+ this.params.jsExpressions.push(strValue);
46
+ } else if (this.currentArrayKey === "placeholderMessages") {
47
+ if (!this.params.placeholderMessages) this.params.placeholderMessages = [];
48
+ this.params.placeholderMessages.push(strValue);
49
+ }
50
+ this.emitArrayItemDelta(this.currentArrayKey, strValue);
51
+ } else if (this.streamingHtmlKey) {
52
+ const fullHtml = value != null ? String(value) : "";
53
+ this.params.html = fullHtml || void 0;
54
+ this.emitPendingHtml(fullHtml);
55
+ this.emitParamDelta("htmlComplete", true);
56
+ this.streamingHtmlKey = false;
57
+ } else this.setParam(this.currentKey, value);
58
+ };
59
+ this.parser.onopenarray = () => {
60
+ if (this.depth === 1 && this.currentKey) {
61
+ const key = this.currentKey;
62
+ if (key === "jsExpressions" || key === "placeholderMessages") {
63
+ this.currentArrayKey = key;
64
+ if (key === "jsExpressions") this.params.jsExpressions = [];
65
+ else this.params.placeholderMessages = [];
66
+ this.emitParamDelta(key, []);
67
+ }
68
+ }
69
+ };
70
+ this.parser.onclosearray = () => {
71
+ if (this.depth === 1) {
72
+ if (this.currentArrayKey === "jsExpressions") this.emitParamDelta("jsExpressionsComplete", true);
73
+ this.currentArrayKey = null;
74
+ }
75
+ };
76
+ this.parser.oncloseobject = () => {
77
+ this.depth--;
78
+ };
79
+ this.parser.onerror = (err) => {
80
+ console.warn("[OpenGenerativeUI] JSON parse error in streaming args, resuming:", err?.message ?? err);
81
+ this.parser.error = null;
82
+ this.parser.resume();
83
+ };
84
+ }
85
+ write(chunk) {
86
+ this.parser.write(chunk);
87
+ this.flushHtmlChunks();
88
+ }
89
+ initHtmlStreaming(key) {
90
+ if (key === "html") {
91
+ this.streamingHtmlKey = true;
92
+ this.htmlEmittedLength = 0;
93
+ this.htmlArrayEmitted = false;
94
+ }
95
+ }
96
+ /**
97
+ * Read clarinet's internal textNode buffer to emit html chunks incrementally.
98
+ * Called after every write() so partial string content is emitted as it streams in.
99
+ */
100
+ flushHtmlChunks() {
101
+ if (!this.streamingHtmlKey) return;
102
+ const textNode = this.parser.textNode;
103
+ if (typeof textNode !== "string") return;
104
+ if (textNode.length === this.htmlEmittedLength) return;
105
+ this.emitPendingHtml(textNode);
106
+ }
107
+ /**
108
+ * Emit accumulated html content since the last emission.
109
+ * Called by flushHtmlChunks and directly when html completes.
110
+ */
111
+ emitPendingHtml(textNode) {
112
+ const newContent = textNode.slice(this.htmlEmittedLength);
113
+ if (newContent.length === 0) return;
114
+ if (!this.htmlArrayEmitted) {
115
+ this.htmlArrayEmitted = true;
116
+ this.emitParamDelta("html", []);
117
+ }
118
+ this.emitArrayItemDelta("html", newContent);
119
+ this.htmlEmittedLength = textNode.length;
120
+ }
121
+ setParam(key, value) {
122
+ switch (key) {
123
+ case "initialHeight":
124
+ this.params.initialHeight = typeof value === "number" ? value : void 0;
125
+ if (this.snapshotEmitted) this.emitParamDelta("initialHeight", this.params.initialHeight);
126
+ else this.emitSnapshot();
127
+ break;
128
+ case "css":
129
+ this.params.css = value != null ? String(value) : void 0;
130
+ this.emitParamDelta("css", this.params.css);
131
+ this.emitParamDelta("cssComplete", true);
132
+ break;
133
+ case "jsFunctions":
134
+ this.params.jsFunctions = value != null ? String(value) : void 0;
135
+ this.emitParamDelta("jsFunctions", this.params.jsFunctions);
136
+ this.emitParamDelta("jsFunctionsComplete", true);
137
+ break;
138
+ }
139
+ }
140
+ emitSnapshot() {
141
+ if (this.snapshotEmitted) return;
142
+ this.snapshotEmitted = true;
143
+ const event = {
144
+ type: _ag_ui_client.EventType.ACTIVITY_SNAPSHOT,
145
+ messageId: this.messageId,
146
+ activityType: ACTIVITY_TYPE,
147
+ content: {
148
+ initialHeight: this.params.initialHeight,
149
+ generating: true
150
+ }
151
+ };
152
+ this.onEvent(event);
153
+ }
154
+ emitParamDelta(key, value) {
155
+ if (value === void 0) return;
156
+ this.emitSnapshot();
157
+ const event = {
158
+ type: _ag_ui_client.EventType.ACTIVITY_DELTA,
159
+ messageId: this.messageId,
160
+ activityType: ACTIVITY_TYPE,
161
+ patch: [{
162
+ op: "add",
163
+ path: `/${key}`,
164
+ value
165
+ }]
166
+ };
167
+ this.onEvent(event);
168
+ }
169
+ emitArrayItemDelta(arrayKey, value) {
170
+ this.emitSnapshot();
171
+ const event = {
172
+ type: _ag_ui_client.EventType.ACTIVITY_DELTA,
173
+ messageId: this.messageId,
174
+ activityType: ACTIVITY_TYPE,
175
+ patch: [{
176
+ op: "add",
177
+ path: `/${arrayKey}/-`,
178
+ value
179
+ }]
180
+ };
181
+ this.onEvent(event);
182
+ }
183
+ };
184
+ var OpenGenerativeUIMiddleware = class extends _ag_ui_client.Middleware {
185
+ run(input, next) {
186
+ return this.processStream(this.runNextWithState(input, next));
187
+ }
188
+ processStream(source) {
189
+ return new rxjs.Observable((subscriber) => {
190
+ let heldRunFinished = null;
191
+ const activeParsers = /* @__PURE__ */ new Map();
192
+ const heldToolCallEvents = /* @__PURE__ */ new Map();
193
+ const flushedToolCalls = /* @__PURE__ */ new Set();
194
+ const flushHeldEvents = (toolCallId) => {
195
+ if (flushedToolCalls.has(toolCallId)) return;
196
+ flushedToolCalls.add(toolCallId);
197
+ const held = heldToolCallEvents.get(toolCallId);
198
+ if (held) {
199
+ for (const e of held) subscriber.next(e);
200
+ heldToolCallEvents.delete(toolCallId);
201
+ }
202
+ };
203
+ const subscription = source.subscribe({
204
+ next: (eventWithState) => {
205
+ const event = eventWithState.event;
206
+ if (heldRunFinished) {
207
+ subscriber.next(heldRunFinished.event);
208
+ heldRunFinished = null;
209
+ }
210
+ if (event.type === _ag_ui_client.EventType.RUN_FINISHED) {
211
+ heldRunFinished = eventWithState;
212
+ return;
213
+ }
214
+ if (event.type === _ag_ui_client.EventType.TOOL_CALL_START) {
215
+ const startEvent = event;
216
+ if (startEvent.toolCallName === TOOL_NAME) {
217
+ heldToolCallEvents.set(startEvent.toolCallId, [event]);
218
+ activeParsers.set(startEvent.toolCallId, new ArgsParser(startEvent.toolCallId, (activityEvent) => {
219
+ subscriber.next(activityEvent);
220
+ flushHeldEvents(startEvent.toolCallId);
221
+ }));
222
+ return;
223
+ }
224
+ }
225
+ if (event.type === _ag_ui_client.EventType.TOOL_CALL_ARGS) {
226
+ const argsEvent = event;
227
+ const parser = activeParsers.get(argsEvent.toolCallId);
228
+ if (parser) {
229
+ if (!flushedToolCalls.has(argsEvent.toolCallId)) heldToolCallEvents.get(argsEvent.toolCallId).push(event);
230
+ else subscriber.next(event);
231
+ parser.write(argsEvent.delta);
232
+ return;
233
+ }
234
+ }
235
+ if (event.type === _ag_ui_client.EventType.TOOL_CALL_END) {
236
+ const endEvent = event;
237
+ const parser = activeParsers.get(endEvent.toolCallId);
238
+ if (parser) {
239
+ const completeEvent = {
240
+ type: _ag_ui_client.EventType.ACTIVITY_DELTA,
241
+ messageId: parser.messageId,
242
+ activityType: ACTIVITY_TYPE,
243
+ patch: [{
244
+ op: "add",
245
+ path: "/generating",
246
+ value: false
247
+ }]
248
+ };
249
+ subscriber.next(completeEvent);
250
+ if (!flushedToolCalls.has(endEvent.toolCallId)) heldToolCallEvents.get(endEvent.toolCallId).push(event);
251
+ else subscriber.next(event);
252
+ return;
253
+ }
254
+ }
255
+ subscriber.next(event);
256
+ },
257
+ error: (err) => {
258
+ for (const [, events] of heldToolCallEvents) for (const event of events) subscriber.next(event);
259
+ heldToolCallEvents.clear();
260
+ if (heldRunFinished) {
261
+ subscriber.next(heldRunFinished.event);
262
+ heldRunFinished = null;
263
+ }
264
+ subscriber.error(err);
265
+ },
266
+ complete: () => {
267
+ heldToolCallEvents.forEach((_, toolCallId) => {
268
+ flushHeldEvents(toolCallId);
269
+ });
270
+ if (heldRunFinished) {
271
+ subscriber.next(heldRunFinished.event);
272
+ heldRunFinished = null;
273
+ }
274
+ activeParsers.clear();
275
+ subscriber.complete();
276
+ }
277
+ });
278
+ return () => subscription.unsubscribe();
279
+ });
280
+ }
281
+ };
282
+
283
+ //#endregion
284
+ exports.ArgsParser = ArgsParser;
285
+ exports.OpenGenerativeUIMiddleware = OpenGenerativeUIMiddleware;
286
+ //# sourceMappingURL=open-generative-ui-middleware.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"open-generative-ui-middleware.cjs","names":["EventType","Middleware","Observable"],"sources":["../../../src/runtime/event-transforms/open-generative-ui-middleware.ts"],"sourcesContent":["import type {\n RunAgentInput,\n AbstractAgent,\n BaseEvent,\n ToolCallStartEvent,\n ToolCallArgsEvent,\n ActivitySnapshotEventProps,\n ActivityDeltaEvent,\n} from \"@ag-ui/client\";\nimport { Middleware, EventType } from \"@ag-ui/client\";\nimport { Observable } from \"rxjs\";\nimport clarinet from \"clarinet\";\n\nconst TOOL_NAME = \"generateSandboxedUi\";\nconst ACTIVITY_TYPE = \"open-generative-ui\";\n\n/**\n * Parsed parameters from the generateSandboxedUi tool call.\n */\nexport interface GenerateSandboxedUIParams {\n initialHeight?: number;\n placeholderMessages?: string[];\n css?: string;\n html?: string;\n jsFunctions?: string;\n jsExpressions?: string[];\n}\n\n/**\n * Callback invoked by ArgsParser whenever a parameter (or array item) finishes parsing.\n */\nexport type OnParamEvent = (event: BaseEvent) => void;\n\n/**\n * Tracks incremental JSON parsing state for a single tool call's arguments.\n * Emits activity events via the onEvent callback as parameters complete.\n */\nexport class ArgsParser {\n private parser: ReturnType<typeof clarinet.parser> & {\n error?: Error | null;\n textNode?: string;\n };\n private currentKey: string | null = null;\n private depth = 0;\n private currentArrayKey: string | null = null;\n private snapshotEmitted = false;\n\n // Streaming html state — reads parser.textNode to emit incremental chunks\n private streamingHtmlKey = false;\n private htmlEmittedLength = 0;\n private htmlArrayEmitted = false;\n\n public readonly params: GenerateSandboxedUIParams = {};\n public readonly messageId: string;\n private readonly onEvent: OnParamEvent;\n\n constructor(toolCallId: string, onEvent: OnParamEvent) {\n this.messageId = `${toolCallId}-activity`;\n this.onEvent = onEvent;\n this.parser = clarinet.parser();\n\n this.parser.onopenobject = (key: string | undefined) => {\n this.depth++;\n if (key !== undefined && this.depth === 1) {\n this.currentKey = key;\n this.initHtmlStreaming(key);\n }\n };\n\n this.parser.onkey = (key: string) => {\n if (this.depth === 1) {\n this.currentKey = key;\n this.initHtmlStreaming(key);\n }\n };\n\n this.parser.onvalue = (value: string | boolean | number | null) => {\n if (this.depth === 1 && this.currentKey) {\n if (this.currentArrayKey) {\n const strValue = String(value);\n if (this.currentArrayKey === \"jsExpressions\") {\n if (!this.params.jsExpressions) this.params.jsExpressions = [];\n this.params.jsExpressions.push(strValue);\n } else if (this.currentArrayKey === \"placeholderMessages\") {\n if (!this.params.placeholderMessages)\n this.params.placeholderMessages = [];\n this.params.placeholderMessages.push(strValue);\n }\n this.emitArrayItemDelta(this.currentArrayKey, strValue);\n } else if (this.streamingHtmlKey) {\n // HTML string completed — flush any remaining content immediately + htmlComplete\n const fullHtml = value != null ? String(value) : \"\";\n this.params.html = fullHtml || undefined;\n this.emitPendingHtml(fullHtml);\n this.emitParamDelta(\"htmlComplete\", true);\n this.streamingHtmlKey = false;\n } else {\n this.setParam(this.currentKey, value);\n }\n }\n };\n\n this.parser.onopenarray = () => {\n if (this.depth === 1 && this.currentKey) {\n const key = this.currentKey;\n if (key === \"jsExpressions\" || key === \"placeholderMessages\") {\n this.currentArrayKey = key;\n if (key === \"jsExpressions\") this.params.jsExpressions = [];\n else this.params.placeholderMessages = [];\n // Emit a delta to create the array in the activity content.\n // Subsequent \"add\" ops with path \"/<key>/-\" append to this array.\n this.emitParamDelta(key, []);\n }\n }\n };\n\n this.parser.onclosearray = () => {\n if (this.depth === 1) {\n if (this.currentArrayKey === \"jsExpressions\") {\n this.emitParamDelta(\"jsExpressionsComplete\", true);\n }\n this.currentArrayKey = null;\n }\n };\n\n this.parser.oncloseobject = () => {\n this.depth--;\n };\n\n this.parser.onerror = (err: Error) => {\n console.warn(\n \"[OpenGenerativeUI] JSON parse error in streaming args, resuming:\",\n err?.message ?? err,\n );\n // Reset error state so parsing can continue with the next chunk\n this.parser.error = null;\n this.parser.resume();\n };\n }\n\n write(chunk: string): void {\n this.parser.write(chunk);\n this.flushHtmlChunks();\n }\n\n private initHtmlStreaming(key: string): void {\n if (key === \"html\") {\n this.streamingHtmlKey = true;\n this.htmlEmittedLength = 0;\n this.htmlArrayEmitted = false;\n }\n }\n\n /**\n * Read clarinet's internal textNode buffer to emit html chunks incrementally.\n * Called after every write() so partial string content is emitted as it streams in.\n */\n private flushHtmlChunks(): void {\n if (!this.streamingHtmlKey) return;\n const textNode = this.parser.textNode;\n if (typeof textNode !== \"string\") return;\n if (textNode.length === this.htmlEmittedLength) return;\n\n this.emitPendingHtml(textNode);\n }\n\n /**\n * Emit accumulated html content since the last emission.\n * Called by flushHtmlChunks and directly when html completes.\n */\n private emitPendingHtml(textNode: string): void {\n const newContent = textNode.slice(this.htmlEmittedLength);\n if (newContent.length === 0) return;\n\n if (!this.htmlArrayEmitted) {\n this.htmlArrayEmitted = true;\n this.emitParamDelta(\"html\", []);\n }\n this.emitArrayItemDelta(\"html\", newContent);\n this.htmlEmittedLength = textNode.length;\n }\n\n private setParam(key: string, value: string | boolean | number | null): void {\n switch (key) {\n case \"initialHeight\":\n this.params.initialHeight =\n typeof value === \"number\" ? value : undefined;\n if (this.snapshotEmitted) {\n // Snapshot already went out (another param parsed first) — deliver\n // the height as a delta instead.\n this.emitParamDelta(\"initialHeight\", this.params.initialHeight);\n } else {\n this.emitSnapshot();\n }\n break;\n case \"css\":\n this.params.css = value != null ? String(value) : undefined;\n this.emitParamDelta(\"css\", this.params.css);\n this.emitParamDelta(\"cssComplete\", true);\n break;\n case \"jsFunctions\":\n this.params.jsFunctions = value != null ? String(value) : undefined;\n this.emitParamDelta(\"jsFunctions\", this.params.jsFunctions);\n this.emitParamDelta(\"jsFunctionsComplete\", true);\n break;\n }\n }\n\n private emitSnapshot(): void {\n if (this.snapshotEmitted) return;\n this.snapshotEmitted = true;\n\n const event = {\n type: EventType.ACTIVITY_SNAPSHOT,\n messageId: this.messageId,\n activityType: ACTIVITY_TYPE,\n content: { initialHeight: this.params.initialHeight, generating: true },\n } satisfies ActivitySnapshotEventProps;\n this.onEvent(event);\n }\n\n private emitParamDelta(key: string, value: unknown): void {\n // A JSON Patch \"add\" requires a value; emitting one without it (e.g. when\n // the LLM sends a null/empty jsFunctions or css) makes fast-json-patch\n // reject the whole patch client-side with OPERATION_VALUE_REQUIRED and\n // drops it. Skip the delta when there's nothing to add.\n if (value === undefined) return;\n // The activity message must exist before any delta can be applied —\n // the client silently drops ACTIVITY_DELTA events whose messageId has\n // no prior ACTIVITY_SNAPSHOT. The LLM controls the key order of the\n // streamed args, so the snapshot cannot wait for initialHeight.\n this.emitSnapshot();\n const event: ActivityDeltaEvent = {\n type: EventType.ACTIVITY_DELTA,\n messageId: this.messageId,\n activityType: ACTIVITY_TYPE,\n patch: [{ op: \"add\", path: `/${key}`, value }],\n };\n this.onEvent(event);\n }\n\n private emitArrayItemDelta(arrayKey: string, value: string): void {\n this.emitSnapshot();\n const event: ActivityDeltaEvent = {\n type: EventType.ACTIVITY_DELTA,\n messageId: this.messageId,\n activityType: ACTIVITY_TYPE,\n patch: [{ op: \"add\", path: `/${arrayKey}/-`, value }],\n };\n this.onEvent(event);\n }\n}\n\n/**\n * Extract EventWithState type from Middleware.runNextWithState return type\n */\ntype ExtractObservableType<T> = T extends Observable<infer U> ? U : never;\ntype RunNextWithStateReturn = ReturnType<Middleware[\"runNextWithState\"]>;\ntype EventWithState = ExtractObservableType<RunNextWithStateReturn>;\n\nexport class OpenGenerativeUIMiddleware extends Middleware {\n run(input: RunAgentInput, next: AbstractAgent): Observable<BaseEvent> {\n return this.processStream(this.runNextWithState(input, next));\n }\n\n private processStream(\n source: Observable<EventWithState>,\n ): Observable<BaseEvent> {\n return new Observable<BaseEvent>((subscriber) => {\n let heldRunFinished: EventWithState | null = null;\n // Track active generateSandboxedUi tool call IDs → their streaming parser\n const activeParsers = new Map<string, ArgsParser>();\n // Hold genui tool call events until the first activity event is emitted\n const heldToolCallEvents = new Map<string, BaseEvent[]>();\n const flushedToolCalls = new Set<string>();\n\n const flushHeldEvents = (toolCallId: string) => {\n if (flushedToolCalls.has(toolCallId)) return;\n flushedToolCalls.add(toolCallId);\n const held = heldToolCallEvents.get(toolCallId);\n if (held) {\n for (const e of held) {\n subscriber.next(e);\n }\n heldToolCallEvents.delete(toolCallId);\n }\n };\n\n const subscription = source.subscribe({\n next: (eventWithState) => {\n const event = eventWithState.event;\n\n if (heldRunFinished) {\n subscriber.next(heldRunFinished.event);\n heldRunFinished = null;\n }\n\n if (event.type === EventType.RUN_FINISHED) {\n heldRunFinished = eventWithState;\n return;\n }\n\n // Hold TOOL_CALL_START for genui until the first activity event\n if (event.type === EventType.TOOL_CALL_START) {\n const startEvent = event as ToolCallStartEvent;\n if (startEvent.toolCallName === TOOL_NAME) {\n heldToolCallEvents.set(startEvent.toolCallId, [event]);\n activeParsers.set(\n startEvent.toolCallId,\n new ArgsParser(startEvent.toolCallId, (activityEvent) => {\n subscriber.next(activityEvent);\n flushHeldEvents(startEvent.toolCallId);\n }),\n );\n return;\n }\n }\n\n // Hold or emit TOOL_CALL_ARGS for genui tool calls\n if (event.type === EventType.TOOL_CALL_ARGS) {\n const argsEvent = event as ToolCallArgsEvent;\n const parser = activeParsers.get(argsEvent.toolCallId);\n if (parser) {\n if (!flushedToolCalls.has(argsEvent.toolCallId)) {\n heldToolCallEvents.get(argsEvent.toolCallId)!.push(event);\n } else {\n subscriber.next(event);\n }\n parser.write(argsEvent.delta);\n return;\n }\n }\n\n // Hold or emit TOOL_CALL_END for genui tool calls\n if (event.type === EventType.TOOL_CALL_END) {\n const endEvent = event as { toolCallId: string } & BaseEvent;\n const parser = activeParsers.get(endEvent.toolCallId);\n if (parser) {\n // Mark generation complete\n const completeEvent: ActivityDeltaEvent = {\n type: EventType.ACTIVITY_DELTA,\n messageId: parser.messageId,\n activityType: ACTIVITY_TYPE,\n patch: [{ op: \"add\", path: \"/generating\", value: false }],\n };\n subscriber.next(completeEvent);\n\n if (!flushedToolCalls.has(endEvent.toolCallId)) {\n heldToolCallEvents.get(endEvent.toolCallId)!.push(event);\n } else {\n subscriber.next(event);\n }\n return;\n }\n }\n\n subscriber.next(event);\n },\n error: (err) => {\n // Flush any held tool call events so downstream sees them before the error\n for (const [, events] of heldToolCallEvents) {\n for (const event of events) {\n subscriber.next(event);\n }\n }\n heldToolCallEvents.clear();\n\n if (heldRunFinished) {\n subscriber.next(heldRunFinished.event);\n heldRunFinished = null;\n }\n subscriber.error(err);\n },\n complete: () => {\n // Flush any remaining held tool call events (e.g. parser never emitted)\n heldToolCallEvents.forEach((_, toolCallId) => {\n flushHeldEvents(toolCallId);\n });\n\n if (heldRunFinished) {\n subscriber.next(heldRunFinished.event);\n heldRunFinished = null;\n }\n activeParsers.clear();\n subscriber.complete();\n },\n });\n\n return () => subscription.unsubscribe();\n });\n }\n}\n"],"mappings":";;;;;;;AAaA,MAAM,YAAY;AAClB,MAAM,gBAAgB;;;;;AAuBtB,IAAa,aAAb,MAAwB;CAmBtB,YAAY,YAAoB,SAAuB;oBAdnB;eACpB;yBACyB;yBACf;0BAGC;2BACC;0BACD;gBAEyB,EAAE;AAKpD,OAAK,YAAY,GAAG,WAAW;AAC/B,OAAK,UAAU;AACf,OAAK,SAAS,iBAAS,QAAQ;AAE/B,OAAK,OAAO,gBAAgB,QAA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