@downcity/agent 1.1.338 → 1.1.400
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/README.md +31 -15
- package/bin/agent/Agent.d.ts +42 -91
- package/bin/agent/Agent.d.ts.map +1 -1
- package/bin/agent/Agent.js +115 -200
- package/bin/agent/Agent.js.map +1 -1
- package/bin/agent/AgentModel.d.ts +8 -8
- package/bin/agent/AgentModel.d.ts.map +1 -1
- package/bin/agent/AgentModel.js +5 -5
- package/bin/agent/AgentModel.js.map +1 -1
- package/bin/agent/AgentSessions.d.ts +42 -28
- package/bin/agent/AgentSessions.d.ts.map +1 -1
- package/bin/agent/AgentSessions.js +80 -44
- package/bin/agent/AgentSessions.js.map +1 -1
- package/bin/agent/WorkspaceEntry.d.ts +82 -0
- package/bin/agent/WorkspaceEntry.d.ts.map +1 -0
- package/bin/agent/WorkspaceEntry.js +246 -0
- package/bin/agent/WorkspaceEntry.js.map +1 -0
- package/bin/agent/index.d.ts +5 -0
- package/bin/agent/index.d.ts.map +1 -0
- package/bin/agent/index.js +5 -0
- package/bin/agent/index.js.map +1 -0
- package/bin/city/host/CityHostRegistry.d.ts +44 -0
- package/bin/city/host/CityHostRegistry.d.ts.map +1 -0
- package/bin/city/host/CityHostRegistry.js +225 -0
- package/bin/city/host/CityHostRegistry.js.map +1 -0
- package/bin/city/index.d.ts +22 -0
- package/bin/city/index.d.ts.map +1 -0
- package/bin/city/index.js +10 -0
- package/bin/city/index.js.map +1 -0
- package/bin/city/runtime/City.d.ts +99 -0
- package/bin/city/runtime/City.d.ts.map +1 -0
- package/bin/city/runtime/City.js +376 -0
- package/bin/city/runtime/City.js.map +1 -0
- package/bin/city/transport/SerializedTransport.d.ts +30 -0
- package/bin/city/transport/SerializedTransport.d.ts.map +1 -0
- package/bin/city/transport/SerializedTransport.js +57 -0
- package/bin/city/transport/SerializedTransport.js.map +1 -0
- package/bin/city/transport/http/AgentHTTP.d.ts +66 -0
- package/bin/city/transport/http/AgentHTTP.d.ts.map +1 -0
- package/bin/city/transport/http/AgentHTTP.js +142 -0
- package/bin/city/transport/http/AgentHTTP.js.map +1 -0
- package/bin/city/transport/http/CityHTTP.d.ts +44 -0
- package/bin/city/transport/http/CityHTTP.d.ts.map +1 -0
- package/bin/city/transport/http/CityHTTP.js +171 -0
- package/bin/city/transport/http/CityHTTP.js.map +1 -0
- package/bin/city/transport/http/NodeHttpAdapter.d.ts +27 -0
- package/bin/city/transport/http/NodeHttpAdapter.d.ts.map +1 -0
- package/bin/city/transport/http/NodeHttpAdapter.js +57 -0
- package/bin/city/transport/http/NodeHttpAdapter.js.map +1 -0
- package/bin/city/transport/http/routes/RuntimeRoutes.d.ts +15 -0
- package/bin/city/transport/http/routes/RuntimeRoutes.d.ts.map +1 -0
- package/bin/city/transport/http/routes/RuntimeRoutes.js +38 -0
- package/bin/city/transport/http/routes/RuntimeRoutes.js.map +1 -0
- package/bin/city/transport/http/routes/SessionRoutes.d.ts +17 -0
- package/bin/city/transport/http/routes/SessionRoutes.d.ts.map +1 -0
- package/bin/city/transport/http/routes/SessionRoutes.js +417 -0
- package/bin/city/transport/http/routes/SessionRoutes.js.map +1 -0
- package/bin/city/transport/rpc/AgentRPC.d.ts +47 -0
- package/bin/city/transport/rpc/AgentRPC.d.ts.map +1 -0
- package/bin/city/transport/rpc/AgentRPC.js +89 -0
- package/bin/city/transport/rpc/AgentRPC.js.map +1 -0
- package/bin/city/transport/rpc/CityRPC.d.ts +26 -0
- package/bin/city/transport/rpc/CityRPC.d.ts.map +1 -0
- package/bin/city/transport/rpc/CityRPC.js +110 -0
- package/bin/city/transport/rpc/CityRPC.js.map +1 -0
- package/bin/city/transport/rpc/RpcServer.d.ts +30 -0
- package/bin/city/transport/rpc/RpcServer.d.ts.map +1 -0
- package/bin/city/transport/rpc/RpcServer.js +125 -0
- package/bin/city/transport/rpc/RpcServer.js.map +1 -0
- package/bin/city/transport/rpc/server/InternalHandlers.d.ts +22 -0
- package/bin/city/transport/rpc/server/InternalHandlers.d.ts.map +1 -0
- package/bin/city/transport/rpc/server/InternalHandlers.js +196 -0
- package/bin/city/transport/rpc/server/InternalHandlers.js.map +1 -0
- package/bin/city/transport/rpc/server/RequestDispatcher.d.ts +27 -0
- package/bin/city/transport/rpc/server/RequestDispatcher.d.ts.map +1 -0
- package/bin/city/transport/rpc/server/RequestDispatcher.js +38 -0
- package/bin/city/transport/rpc/server/RequestDispatcher.js.map +1 -0
- package/bin/city/transport/rpc/server/SdkSessionHandlers.d.ts +25 -0
- package/bin/city/transport/rpc/server/SdkSessionHandlers.d.ts.map +1 -0
- package/bin/city/transport/rpc/server/SdkSessionHandlers.js +146 -0
- package/bin/city/transport/rpc/server/SdkSessionHandlers.js.map +1 -0
- package/bin/city/transport/rpc/server/ServerTypes.d.ts +94 -0
- package/bin/city/transport/rpc/server/ServerTypes.d.ts.map +1 -0
- package/bin/city/transport/rpc/server/ServerTypes.js +9 -0
- package/bin/city/transport/rpc/server/ServerTypes.js.map +1 -0
- package/bin/city/transport/session/RemoteSessionConfig.d.ts +15 -0
- package/bin/city/transport/session/RemoteSessionConfig.d.ts.map +1 -0
- package/bin/city/transport/session/RemoteSessionConfig.js +23 -0
- package/bin/city/transport/session/RemoteSessionConfig.js.map +1 -0
- package/bin/city/transport/types/AgentHttpBinding.d.ts +24 -0
- package/bin/city/transport/types/AgentHttpBinding.d.ts.map +1 -0
- package/bin/city/transport/types/AgentHttpBinding.js +5 -0
- package/bin/city/transport/types/AgentHttpBinding.js.map +1 -0
- package/bin/city/transport/types/AgentHttpRuntime.d.ts +12 -0
- package/bin/city/transport/types/AgentHttpRuntime.d.ts.map +1 -0
- package/bin/city/transport/types/AgentHttpRuntime.js +7 -0
- package/bin/city/transport/types/AgentHttpRuntime.js.map +1 -0
- package/bin/city/transport/types/AgentRpcBinding.d.ts +27 -0
- package/bin/city/transport/types/AgentRpcBinding.d.ts.map +1 -0
- package/bin/city/transport/types/AgentRpcBinding.js +8 -0
- package/bin/city/transport/types/AgentRpcBinding.js.map +1 -0
- package/bin/city/transport/types/AgentRpcRuntime.d.ts +18 -0
- package/bin/city/transport/types/AgentRpcRuntime.d.ts.map +1 -0
- package/bin/city/transport/types/AgentRpcRuntime.js +7 -0
- package/bin/city/transport/types/AgentRpcRuntime.js.map +1 -0
- package/bin/city/transport/types/AgentSessionModelResolver.d.ts +11 -0
- package/bin/city/transport/types/AgentSessionModelResolver.d.ts.map +1 -0
- package/bin/city/transport/types/AgentSessionModelResolver.js +7 -0
- package/bin/city/transport/types/AgentSessionModelResolver.js.map +1 -0
- package/bin/city/transport/types/CityHttpRuntime.d.ts +36 -0
- package/bin/city/transport/types/CityHttpRuntime.d.ts.map +1 -0
- package/bin/city/transport/types/CityHttpRuntime.js +8 -0
- package/bin/city/transport/types/CityHttpRuntime.js.map +1 -0
- package/bin/city/transport/types/CityRpcRuntime.d.ts +17 -0
- package/bin/city/transport/types/CityRpcRuntime.d.ts.map +1 -0
- package/bin/city/transport/types/CityRpcRuntime.js +8 -0
- package/bin/city/transport/types/CityRpcRuntime.js.map +1 -0
- package/bin/city/transport/types/RpcProtocol.d.ts +24 -0
- package/bin/city/transport/types/RpcProtocol.d.ts.map +1 -0
- package/bin/city/transport/types/RpcProtocol.js +9 -0
- package/bin/city/transport/types/RpcProtocol.js.map +1 -0
- package/bin/city/types/City.d.ts +84 -0
- package/bin/city/types/City.d.ts.map +1 -0
- package/bin/city/types/City.js +7 -0
- package/bin/city/types/City.js.map +1 -0
- package/bin/city/types/PluginHostContext.d.ts +31 -0
- package/bin/city/types/PluginHostContext.d.ts.map +1 -0
- package/bin/city/types/PluginHostContext.js +11 -0
- package/bin/city/types/PluginHostContext.js.map +1 -0
- package/bin/city/types/SerializedTransport.d.ts +16 -0
- package/bin/city/types/SerializedTransport.d.ts.map +1 -0
- package/bin/city/types/SerializedTransport.js +3 -0
- package/bin/city/types/SerializedTransport.js.map +1 -0
- package/bin/executor/Executor.d.ts +4 -4
- package/bin/executor/Executor.d.ts.map +1 -1
- package/bin/executor/Executor.js +90 -34
- package/bin/executor/Executor.js.map +1 -1
- package/bin/executor/composer/system/SessionSystemComposer.d.ts +2 -2
- package/bin/executor/composer/system/SessionSystemComposer.d.ts.map +1 -1
- package/bin/executor/composer/system/default/DefaultSessionSystemComposer.d.ts +3 -3
- package/bin/executor/composer/system/default/DefaultSessionSystemComposer.js +1 -1
- package/bin/executor/composer/system/default/PromptRenderer.d.ts +3 -3
- package/bin/executor/composer/system/default/PromptRenderer.d.ts.map +1 -1
- package/bin/executor/composer/system/default/PromptRenderer.js +1 -1
- package/bin/executor/composer/system/default/SystemDomain.d.ts +3 -3
- package/bin/executor/composer/system/default/SystemDomain.d.ts.map +1 -1
- package/bin/executor/composer/system/default/SystemDomain.js +3 -3
- package/bin/executor/composer/system/default/SystemDomain.js.map +1 -1
- package/bin/executor/composer/system/default/SystemPromptAssets.js +2 -2
- package/bin/executor/composer/system/default/assets/core.prompt.d.ts +1 -1
- package/bin/executor/composer/system/default/assets/core.prompt.d.ts.map +1 -1
- package/bin/executor/composer/system/default/assets/core.prompt.js +1 -1
- package/bin/executor/composer/system/default/assets/core.prompt.js.map +1 -1
- package/bin/executor/composer/system/default/variables/GeoContext.d.ts +1 -1
- package/bin/executor/composer/system/default/variables/VariableReplacer.js +1 -1
- package/bin/executor/core-engine/CoreEngineContextCompaction.d.ts +6 -23
- package/bin/executor/core-engine/CoreEngineContextCompaction.d.ts.map +1 -1
- package/bin/executor/core-engine/CoreEngineContextCompaction.js +112 -344
- package/bin/executor/core-engine/CoreEngineContextCompaction.js.map +1 -1
- package/bin/executor/core-engine/CoreEngineError.d.ts +1 -1
- package/bin/executor/core-engine/CoreEngineError.js +1 -1
- package/bin/executor/core-engine/CoreEngineLoopDecision.d.ts +2 -3
- package/bin/executor/core-engine/CoreEngineLoopDecision.d.ts.map +1 -1
- package/bin/executor/core-engine/CoreEngineLoopDecision.js +1 -15
- package/bin/executor/core-engine/CoreEngineLoopDecision.js.map +1 -1
- package/bin/executor/core-engine/CoreEngineMessageState.d.ts +16 -39
- package/bin/executor/core-engine/CoreEngineMessageState.d.ts.map +1 -1
- package/bin/executor/core-engine/CoreEngineMessageState.js +25 -60
- package/bin/executor/core-engine/CoreEngineMessageState.js.map +1 -1
- package/bin/executor/core-engine/CoreEngineRunner.d.ts +10 -6
- package/bin/executor/core-engine/CoreEngineRunner.d.ts.map +1 -1
- package/bin/executor/core-engine/CoreEngineRunner.js +146 -234
- package/bin/executor/core-engine/CoreEngineRunner.js.map +1 -1
- package/bin/executor/core-engine/CoreEngineSignals.d.ts +20 -58
- package/bin/executor/core-engine/CoreEngineSignals.d.ts.map +1 -1
- package/bin/executor/core-engine/CoreEngineSignals.js +84 -304
- package/bin/executor/core-engine/CoreEngineSignals.js.map +1 -1
- package/bin/executor/messages/SessionAttachmentMapper.d.ts +6 -37
- package/bin/executor/messages/SessionAttachmentMapper.d.ts.map +1 -1
- package/bin/executor/messages/SessionAttachmentMapper.js +12 -243
- package/bin/executor/messages/SessionAttachmentMapper.js.map +1 -1
- package/bin/executor/messages/SessionMessageLog.d.ts +7 -14
- package/bin/executor/messages/SessionMessageLog.d.ts.map +1 -1
- package/bin/executor/messages/SessionMessageLog.js +11 -26
- package/bin/executor/messages/SessionMessageLog.js.map +1 -1
- package/bin/executor/messages/SessionModelMessages.d.ts +14 -0
- package/bin/executor/messages/SessionModelMessages.d.ts.map +1 -0
- package/bin/executor/messages/SessionModelMessages.js +187 -0
- package/bin/executor/messages/SessionModelMessages.js.map +1 -0
- package/bin/executor/model/ModelGenerate.d.ts +22 -0
- package/bin/executor/model/ModelGenerate.d.ts.map +1 -0
- package/bin/executor/model/ModelGenerate.js +54 -0
- package/bin/executor/model/ModelGenerate.js.map +1 -0
- package/bin/executor/model/ModelStepRunner.d.ts +70 -0
- package/bin/executor/model/ModelStepRunner.d.ts.map +1 -0
- package/bin/executor/model/ModelStepRunner.js +284 -0
- package/bin/executor/model/ModelStepRunner.js.map +1 -0
- package/bin/executor/services/ExecutorRecoveryPolicy.d.ts +4 -4
- package/bin/executor/services/ExecutorRecoveryPolicy.d.ts.map +1 -1
- package/bin/executor/types/SessionHistoryMeta.d.ts +7 -2
- package/bin/executor/types/SessionHistoryMeta.d.ts.map +1 -1
- package/bin/executor/types/SessionHistoryMeta.js +1 -1
- package/bin/executor/types/SessionLoop.d.ts +1 -21
- package/bin/executor/types/SessionLoop.d.ts.map +1 -1
- package/bin/executor/types/SessionPrompts.d.ts +8 -7
- package/bin/executor/types/SessionPrompts.d.ts.map +1 -1
- package/bin/executor/types/SessionPrompts.js +1 -2
- package/bin/executor/types/SessionPrompts.js.map +1 -1
- package/bin/group/Group.d.ts +20 -0
- package/bin/group/Group.d.ts.map +1 -0
- package/bin/group/Group.js +42 -0
- package/bin/group/Group.js.map +1 -0
- package/bin/group/GroupSession.d.ts +103 -0
- package/bin/group/GroupSession.d.ts.map +1 -0
- package/bin/group/GroupSession.js +666 -0
- package/bin/group/GroupSession.js.map +1 -0
- package/bin/group/GroupSessions.d.ts +21 -0
- package/bin/group/GroupSessions.d.ts.map +1 -0
- package/bin/group/GroupSessions.js +89 -0
- package/bin/group/GroupSessions.js.map +1 -0
- package/bin/group/index.d.ts +9 -0
- package/bin/group/index.d.ts.map +1 -0
- package/bin/group/index.js +6 -0
- package/bin/group/index.js.map +1 -0
- package/bin/index.d.ts +28 -20
- package/bin/index.d.ts.map +1 -1
- package/bin/index.js +7 -9
- package/bin/index.js.map +1 -1
- package/bin/internal/AgentRuntime.d.ts +43 -0
- package/bin/internal/AgentRuntime.d.ts.map +1 -0
- package/bin/internal/AgentRuntime.js +179 -0
- package/bin/internal/AgentRuntime.js.map +1 -0
- package/bin/internal/GroupRuntime.d.ts +17 -0
- package/bin/internal/GroupRuntime.d.ts.map +1 -0
- package/bin/internal/GroupRuntime.js +66 -0
- package/bin/internal/GroupRuntime.js.map +1 -0
- package/bin/internal/index.d.ts +8 -0
- package/bin/internal/index.d.ts.map +1 -0
- package/bin/internal/index.js +8 -0
- package/bin/internal/index.js.map +1 -0
- package/bin/plugin/core/ActionScheduleExecutor.d.ts +3 -2
- package/bin/plugin/core/ActionScheduleExecutor.d.ts.map +1 -1
- package/bin/plugin/core/ActionScheduleExecutor.js +14 -3
- package/bin/plugin/core/ActionScheduleExecutor.js.map +1 -1
- package/bin/plugin/core/ActionScheduleRuntime.d.ts +3 -1
- package/bin/plugin/core/ActionScheduleRuntime.d.ts.map +1 -1
- package/bin/plugin/core/ActionScheduleRuntime.js +9 -8
- package/bin/plugin/core/ActionScheduleRuntime.js.map +1 -1
- package/bin/plugin/core/ActionScheduleStore.d.ts +7 -3
- package/bin/plugin/core/ActionScheduleStore.d.ts.map +1 -1
- package/bin/plugin/core/ActionScheduleStore.js +32 -9
- package/bin/plugin/core/ActionScheduleStore.js.map +1 -1
- package/bin/plugin/core/HookRegistry.d.ts +4 -6
- package/bin/plugin/core/HookRegistry.d.ts.map +1 -1
- package/bin/plugin/core/HookRegistry.js +8 -14
- package/bin/plugin/core/HookRegistry.js.map +1 -1
- package/bin/plugin/core/PluginActionExecution.d.ts +33 -0
- package/bin/plugin/core/PluginActionExecution.d.ts.map +1 -0
- package/bin/plugin/core/PluginActionExecution.js +168 -0
- package/bin/plugin/core/PluginActionExecution.js.map +1 -0
- package/bin/plugin/core/PluginActionFactory.d.ts +6 -3
- package/bin/plugin/core/PluginActionFactory.d.ts.map +1 -1
- package/bin/plugin/core/PluginActionFactory.js +3 -0
- package/bin/plugin/core/PluginActionFactory.js.map +1 -1
- package/bin/plugin/core/PluginContext.d.ts +14 -4
- package/bin/plugin/core/PluginContext.d.ts.map +1 -1
- package/bin/plugin/core/PluginContext.js +11 -2
- package/bin/plugin/core/PluginContext.js.map +1 -1
- package/bin/plugin/core/PluginHttpRoutes.d.ts +1 -1
- package/bin/plugin/core/PluginHttpRoutes.d.ts.map +1 -1
- package/bin/plugin/core/PluginHttpRoutes.js +1 -1
- package/bin/plugin/core/PluginHttpRoutes.js.map +1 -1
- package/bin/plugin/core/PluginRegistry.d.ts +41 -26
- package/bin/plugin/core/PluginRegistry.d.ts.map +1 -1
- package/bin/plugin/core/PluginRegistry.js +125 -107
- package/bin/plugin/core/PluginRegistry.js.map +1 -1
- package/bin/plugin/tool/PluginToolRuntime.d.ts.map +1 -1
- package/bin/plugin/tool/PluginToolRuntime.js +4 -1
- package/bin/plugin/tool/PluginToolRuntime.js.map +1 -1
- package/bin/plugin/tool/PluginToolSchemas.d.ts +22 -2
- package/bin/plugin/tool/PluginToolSchemas.d.ts.map +1 -1
- package/bin/plugin/tool/PluginToolSchemas.js +3 -4
- package/bin/plugin/tool/PluginToolSchemas.js.map +1 -1
- package/bin/plugin/tool/PluginTools.d.ts +5 -8
- package/bin/plugin/tool/PluginTools.d.ts.map +1 -1
- package/bin/plugin/tool/PluginTools.js +9 -8
- package/bin/plugin/tool/PluginTools.js.map +1 -1
- package/bin/plugin/types/ActionSchedule.d.ts +6 -0
- package/bin/plugin/types/ActionSchedule.d.ts.map +1 -1
- package/bin/remote/RemoteAgent.js +2 -2
- package/bin/remote/RemoteSession.d.ts +1 -1
- package/bin/remote/TransportFactory.d.ts +1 -1
- package/bin/remote/TransportFactory.js +2 -2
- package/bin/remote/transports/HttpRemoteAgentTransport.d.ts +1 -1
- package/bin/remote/transports/HttpRemoteAgentTransport.d.ts.map +1 -1
- package/bin/remote/transports/HttpRemoteAgentTransport.js +3 -3
- package/bin/remote/transports/HttpRemoteAgentTransport.js.map +1 -1
- package/bin/remote/transports/RpcClient.d.ts +1 -0
- package/bin/remote/transports/RpcClient.d.ts.map +1 -1
- package/bin/remote/transports/RpcClient.js +16 -0
- package/bin/remote/transports/RpcClient.js.map +1 -1
- package/bin/remote/transports/RpcRemoteAgentTransport.d.ts +1 -1
- package/bin/remote/transports/RpcRemoteAgentTransport.d.ts.map +1 -1
- package/bin/remote/transports/RpcRemoteAgentTransport.js +2 -1
- package/bin/remote/transports/RpcRemoteAgentTransport.js.map +1 -1
- package/bin/session/DefaultSessionComposer.js +4 -4
- package/bin/session/DefaultSessionComposer.js.map +1 -1
- package/bin/session/Session.d.ts +9 -3
- package/bin/session/Session.d.ts.map +1 -1
- package/bin/session/Session.js +62 -53
- package/bin/session/Session.js.map +1 -1
- package/bin/session/SessionLoop.d.ts.map +1 -1
- package/bin/session/SessionLoop.js +23 -25
- package/bin/session/SessionLoop.js.map +1 -1
- package/bin/session/SessionMessages.d.ts +9 -11
- package/bin/session/SessionMessages.d.ts.map +1 -1
- package/bin/session/SessionMessages.js +56 -104
- package/bin/session/SessionMessages.js.map +1 -1
- package/bin/session/SessionQueue.d.ts +1 -1
- package/bin/session/SessionState.d.ts +3 -0
- package/bin/session/SessionState.d.ts.map +1 -1
- package/bin/session/SessionState.js +42 -12
- package/bin/session/SessionState.js.map +1 -1
- package/bin/session/SessionTitle.d.ts +6 -6
- package/bin/session/SessionTitle.d.ts.map +1 -1
- package/bin/session/SessionTitle.js +11 -39
- package/bin/session/SessionTitle.js.map +1 -1
- package/bin/session/browse/Browse.d.ts +6 -4
- package/bin/session/browse/Browse.d.ts.map +1 -1
- package/bin/session/browse/Browse.js +25 -43
- package/bin/session/browse/Browse.js.map +1 -1
- package/bin/session/control/SessionInteractions.d.ts +2 -2
- package/bin/session/control/SessionInteractions.d.ts.map +1 -1
- package/bin/session/control/SessionInteractions.js +68 -32
- package/bin/session/control/SessionInteractions.js.map +1 -1
- package/bin/session/execution/SessionAssistantOutputAdapter.d.ts +20 -17
- package/bin/session/execution/SessionAssistantOutputAdapter.d.ts.map +1 -1
- package/bin/session/execution/SessionAssistantOutputAdapter.js +35 -35
- package/bin/session/execution/SessionAssistantOutputAdapter.js.map +1 -1
- package/bin/session/execution/tools/SessionShellApprovalAdapter.d.ts +2 -2
- package/bin/session/execution/tools/SessionShellApprovalAdapter.d.ts.map +1 -1
- package/bin/session/execution/tools/SessionShellApprovalAdapter.js +20 -8
- package/bin/session/execution/tools/SessionShellApprovalAdapter.js.map +1 -1
- package/bin/session/messages/SessionAssistantMessageWriter.d.ts +42 -48
- package/bin/session/messages/SessionAssistantMessageWriter.d.ts.map +1 -1
- package/bin/session/messages/SessionAssistantMessageWriter.js +225 -543
- package/bin/session/messages/SessionAssistantMessageWriter.js.map +1 -1
- package/bin/session/messages/SessionJsonValue.d.ts +0 -10
- package/bin/session/messages/SessionJsonValue.d.ts.map +1 -1
- package/bin/session/messages/SessionJsonValue.js +0 -23
- package/bin/session/messages/SessionJsonValue.js.map +1 -1
- package/bin/session/messages/SessionMessageCompaction.d.ts +7 -3
- package/bin/session/messages/SessionMessageCompaction.d.ts.map +1 -1
- package/bin/session/messages/SessionMessageCompaction.js +69 -91
- package/bin/session/messages/SessionMessageCompaction.js.map +1 -1
- package/bin/session/messages/SessionMessageInteractionWriter.d.ts.map +1 -1
- package/bin/session/messages/SessionMessageInteractionWriter.js +22 -21
- package/bin/session/messages/SessionMessageInteractionWriter.js.map +1 -1
- package/bin/session/messages/SessionMessageText.d.ts +25 -0
- package/bin/session/messages/SessionMessageText.d.ts.map +1 -0
- package/bin/session/messages/SessionMessageText.js +52 -0
- package/bin/session/messages/SessionMessageText.js.map +1 -0
- package/bin/session/preview/SessionMessagePreview.d.ts +3 -3
- package/bin/session/preview/SessionMessagePreview.d.ts.map +1 -1
- package/bin/session/preview/SessionMessagePreview.js +10 -30
- package/bin/session/preview/SessionMessagePreview.js.map +1 -1
- package/bin/session/runtime/SessionTurnContext.d.ts.map +1 -1
- package/bin/session/runtime/SessionTurnContext.js +4 -2
- package/bin/session/runtime/SessionTurnContext.js.map +1 -1
- package/bin/session/storage/Metadata.d.ts +5 -3
- package/bin/session/storage/Metadata.d.ts.map +1 -1
- package/bin/session/storage/Metadata.js +26 -7
- package/bin/session/storage/Metadata.js.map +1 -1
- package/bin/tools/ask/AskQuestionsTool.d.ts +2 -16
- package/bin/tools/ask/AskQuestionsTool.d.ts.map +1 -1
- package/bin/tools/ask/AskQuestionsTool.js +21 -17
- package/bin/tools/ask/AskQuestionsTool.js.map +1 -1
- package/bin/types/action/ActionResult.d.ts +15 -10
- package/bin/types/action/ActionResult.d.ts.map +1 -1
- package/bin/types/action/ActionResult.js +2 -2
- package/bin/types/action/ActionResult.js.map +1 -1
- package/bin/types/agent/AgentOptions.d.ts +7 -14
- package/bin/types/agent/AgentOptions.d.ts.map +1 -1
- package/bin/types/agent/AgentSessionCollection.d.ts +42 -0
- package/bin/types/agent/AgentSessionCollection.d.ts.map +1 -0
- package/bin/types/agent/AgentSessionCollection.js +7 -0
- package/bin/types/agent/AgentSessionCollection.js.map +1 -0
- package/bin/types/agent/AgentStorage.d.ts +18 -0
- package/bin/types/agent/AgentStorage.d.ts.map +1 -0
- package/bin/types/agent/AgentStorage.js +8 -0
- package/bin/types/agent/AgentStorage.js.map +1 -0
- package/bin/types/agent/RemoteAgentOptions.d.ts +1 -1
- package/bin/types/agent/RemoteAgentPluginAction.d.ts +2 -2
- package/bin/types/agent/SessionActor.d.ts +15 -8
- package/bin/types/agent/SessionActor.d.ts.map +1 -1
- package/bin/types/agent/SessionTypes.d.ts +30 -11
- package/bin/types/agent/SessionTypes.d.ts.map +1 -1
- package/bin/types/agent/WorkspaceEntryOptions.d.ts +16 -0
- package/bin/types/agent/WorkspaceEntryOptions.d.ts.map +1 -0
- package/bin/types/agent/WorkspaceEntryOptions.js +8 -0
- package/bin/types/agent/WorkspaceEntryOptions.js.map +1 -0
- package/bin/types/executor/SessionAssistantOutput.d.ts +19 -17
- package/bin/types/executor/SessionAssistantOutput.d.ts.map +1 -1
- package/bin/types/executor/SessionAssistantOutput.js +2 -3
- package/bin/types/executor/SessionAssistantOutput.js.map +1 -1
- package/bin/types/executor/SessionToolExecutionContext.d.ts +8 -5
- package/bin/types/executor/SessionToolExecutionContext.d.ts.map +1 -1
- package/bin/types/executor/SessionToolExecutionContext.js +1 -1
- package/bin/types/executor/SessionTurnContext.d.ts +16 -16
- package/bin/types/executor/SessionTurnContext.d.ts.map +1 -1
- package/bin/types/group/DispatchStrategy.d.ts +62 -0
- package/bin/types/group/DispatchStrategy.d.ts.map +1 -0
- package/bin/types/group/DispatchStrategy.js +93 -0
- package/bin/types/group/DispatchStrategy.js.map +1 -0
- package/bin/types/group/Group.d.ts +61 -0
- package/bin/types/group/Group.d.ts.map +1 -0
- package/bin/types/group/Group.js +3 -0
- package/bin/types/group/Group.js.map +1 -0
- package/bin/types/group/GroupSession.d.ts +149 -0
- package/bin/types/group/GroupSession.d.ts.map +1 -0
- package/bin/types/group/GroupSession.js +3 -0
- package/bin/types/group/GroupSession.js.map +1 -0
- package/bin/types/group/GroupSessionStore.d.ts +77 -0
- package/bin/types/group/GroupSessionStore.d.ts.map +1 -0
- package/bin/types/group/GroupSessionStore.js +3 -0
- package/bin/types/group/GroupSessionStore.js.map +1 -0
- package/bin/types/plugin/AgentPluginContext.d.ts +25 -0
- package/bin/types/plugin/AgentPluginContext.d.ts.map +1 -0
- package/bin/types/plugin/AgentPluginContext.js +10 -0
- package/bin/types/plugin/AgentPluginContext.js.map +1 -0
- package/bin/types/plugin/PluginAction.d.ts +10 -8
- package/bin/types/plugin/PluginAction.d.ts.map +1 -1
- package/bin/types/plugin/PluginActionExecution.d.ts +31 -0
- package/bin/types/plugin/PluginActionExecution.d.ts.map +1 -0
- package/bin/types/plugin/PluginActionExecution.js +10 -0
- package/bin/types/plugin/PluginActionExecution.js.map +1 -0
- package/bin/types/plugin/PluginCommand.d.ts +5 -5
- package/bin/types/plugin/PluginCommand.d.ts.map +1 -1
- package/bin/types/plugin/PluginContext.d.ts +19 -8
- package/bin/types/plugin/PluginContext.d.ts.map +1 -1
- package/bin/types/plugin/PluginContext.js +1 -1
- package/bin/types/plugin/PluginDefinition.d.ts +6 -6
- package/bin/types/plugin/PluginExecutionContext.d.ts +4 -10
- package/bin/types/plugin/PluginExecutionContext.d.ts.map +1 -1
- package/bin/types/plugin/PluginExecutionContext.js +3 -5
- package/bin/types/plugin/PluginExecutionContext.js.map +1 -1
- package/bin/types/plugin/PluginHttp.d.ts +1 -1
- package/bin/types/plugin/PluginRuntime.d.ts +13 -8
- package/bin/types/plugin/PluginRuntime.d.ts.map +1 -1
- package/bin/types/plugin/PluginServices.d.ts +10 -0
- package/bin/types/plugin/PluginServices.d.ts.map +1 -0
- package/bin/types/plugin/PluginServices.js +3 -0
- package/bin/types/plugin/PluginServices.js.map +1 -0
- package/bin/types/plugin/PluginState.d.ts +3 -3
- package/bin/types/plugin/PluginState.d.ts.map +1 -1
- package/bin/types/plugin/PluginState.js +1 -1
- package/bin/types/plugin/PluginTool.d.ts +6 -4
- package/bin/types/plugin/PluginTool.d.ts.map +1 -1
- package/bin/types/rpc/RpcProtocol.d.ts +30 -8
- package/bin/types/rpc/RpcProtocol.d.ts.map +1 -1
- package/bin/types/sdk/AgentSessionAction.d.ts +6 -7
- package/bin/types/sdk/AgentSessionAction.d.ts.map +1 -1
- package/bin/types/sdk/AgentSessionAction.js +2 -3
- package/bin/types/sdk/AgentSessionAction.js.map +1 -1
- package/bin/types/sdk/AgentSessionPrompt.d.ts +7 -7
- package/bin/types/sdk/AgentSessionPrompt.d.ts.map +1 -1
- package/bin/types/sdk/AgentSessionPrompt.js +1 -4
- package/bin/types/sdk/AgentSessionPrompt.js.map +1 -1
- package/bin/types/session/SessionAction.d.ts +39 -0
- package/bin/types/session/SessionAction.d.ts.map +1 -0
- package/bin/types/session/SessionAction.js +8 -0
- package/bin/types/session/SessionAction.js.map +1 -0
- package/bin/types/session/SessionComposer.d.ts +10 -11
- package/bin/types/session/SessionComposer.d.ts.map +1 -1
- package/bin/types/session/SessionContent.d.ts +41 -0
- package/bin/types/session/SessionContent.d.ts.map +1 -0
- package/bin/types/session/SessionContent.js +8 -0
- package/bin/types/session/SessionContent.js.map +1 -0
- package/bin/types/session/SessionExecution.d.ts +9 -68
- package/bin/types/session/SessionExecution.d.ts.map +1 -1
- package/bin/types/session/SessionInteraction.d.ts +92 -58
- package/bin/types/session/SessionInteraction.d.ts.map +1 -1
- package/bin/types/session/SessionInteraction.js +11 -4
- package/bin/types/session/SessionInteraction.js.map +1 -1
- package/bin/types/session/SessionInteractions.d.ts +1 -1
- package/bin/types/session/SessionLocalState.d.ts +2 -2
- package/bin/types/session/SessionLoop.d.ts +5 -5
- package/bin/types/session/SessionLoop.d.ts.map +1 -1
- package/bin/types/session/SessionMessage.d.ts +27 -87
- package/bin/types/session/SessionMessage.d.ts.map +1 -1
- package/bin/types/session/SessionMessages.d.ts +14 -14
- package/bin/types/session/SessionMessages.d.ts.map +1 -1
- package/bin/types/session/SessionMutation.d.ts +2 -2
- package/bin/types/session/SessionOptions.d.ts +14 -9
- package/bin/types/session/SessionOptions.d.ts.map +1 -1
- package/bin/types/session/SessionOrigin.d.ts +19 -0
- package/bin/types/session/SessionOrigin.d.ts.map +1 -0
- package/bin/types/session/SessionOrigin.js +8 -0
- package/bin/types/session/SessionOrigin.js.map +1 -0
- package/bin/types/session/SessionPort.d.ts +16 -20
- package/bin/types/session/SessionPort.d.ts.map +1 -1
- package/bin/types/session/SessionSegment.d.ts +1 -1
- package/bin/types/session/SessionState.d.ts +9 -6
- package/bin/types/session/SessionState.d.ts.map +1 -1
- package/bin/types/session/SessionSystem.d.ts +1 -1
- package/bin/types/session/SessionTool.d.ts +12 -1
- package/bin/types/session/SessionTool.d.ts.map +1 -1
- package/bin/types/store/LocalStore.d.ts +19 -11
- package/bin/types/store/LocalStore.d.ts.map +1 -1
- package/bin/types/store/LocalStore.js +2 -2
- package/bin/types/store/SessionAttachmentStore.d.ts +4 -4
- package/bin/types/store/SessionAttachmentStore.js +3 -3
- package/bin/types/store/SessionDataStore.d.ts +85 -0
- package/bin/types/store/SessionDataStore.d.ts.map +1 -0
- package/bin/types/store/SessionDataStore.js +9 -0
- package/bin/types/store/SessionDataStore.js.map +1 -0
- package/bin/types/store/SessionStore.d.ts +24 -78
- package/bin/types/store/SessionStore.d.ts.map +1 -1
- package/bin/types/store/SessionStore.js +3 -3
- package/bin/types/tools/ToolActionExecutionContext.d.ts +30 -0
- package/bin/types/tools/ToolActionExecutionContext.d.ts.map +1 -0
- package/bin/types/tools/ToolActionExecutionContext.js +8 -0
- package/bin/types/tools/ToolActionExecutionContext.js.map +1 -0
- package/bin/types/tools/ask/AskQuestionsTool.d.ts +1 -1
- package/bin/utils/logger/Logger.d.ts +21 -9
- package/bin/utils/logger/Logger.d.ts.map +1 -1
- package/bin/utils/logger/Logger.js +18 -9
- package/bin/utils/logger/Logger.js.map +1 -1
- package/bin/workspace/WorkspacePaths.d.ts +3 -32
- package/bin/workspace/WorkspacePaths.d.ts.map +1 -1
- package/bin/workspace/WorkspacePaths.js +7 -46
- package/bin/workspace/WorkspacePaths.js.map +1 -1
- package/bin/workspace/store/JsonlSessionMessageStore.d.ts +1 -1
- package/bin/workspace/store/JsonlSessionMessageStore.d.ts.map +1 -1
- package/bin/workspace/store/LocalGroupSessionDataStore.d.ts +46 -0
- package/bin/workspace/store/LocalGroupSessionDataStore.d.ts.map +1 -0
- package/bin/workspace/store/LocalGroupSessionDataStore.js +197 -0
- package/bin/workspace/store/LocalGroupSessionDataStore.js.map +1 -0
- package/bin/workspace/store/LocalGroupSessionStore.d.ts +22 -0
- package/bin/workspace/store/LocalGroupSessionStore.d.ts.map +1 -0
- package/bin/workspace/store/LocalGroupSessionStore.js +75 -0
- package/bin/workspace/store/LocalGroupSessionStore.js.map +1 -0
- package/bin/workspace/store/LocalSessionAttachmentStore.d.ts +2 -2
- package/bin/workspace/store/LocalSessionAttachmentStore.d.ts.map +1 -1
- package/bin/workspace/store/LocalSessionAttachmentStore.js +2 -2
- package/bin/workspace/store/LocalSessionAttachmentStore.js.map +1 -1
- package/bin/workspace/store/LocalSessionDataStore.d.ts +45 -0
- package/bin/workspace/store/LocalSessionDataStore.d.ts.map +1 -0
- package/bin/workspace/store/LocalSessionDataStore.js +100 -0
- package/bin/workspace/store/LocalSessionDataStore.js.map +1 -0
- package/bin/workspace/store/LocalSessionStore.d.ts +38 -28
- package/bin/workspace/store/LocalSessionStore.d.ts.map +1 -1
- package/bin/workspace/store/LocalSessionStore.js +151 -51
- package/bin/workspace/store/LocalSessionStore.js.map +1 -1
- package/bin/workspace/store/LocalStorePaths.d.ts +31 -83
- package/bin/workspace/store/LocalStorePaths.d.ts.map +1 -1
- package/bin/workspace/store/LocalStorePaths.js +43 -101
- package/bin/workspace/store/LocalStorePaths.js.map +1 -1
- package/bin/workspace/store/SessionMessageStoreFactory.d.ts +1 -1
- package/bin/workspace/store/SessionMessageStoreFactory.d.ts.map +1 -1
- package/bin/workspace/store/SessionMessageStoreFactory.js +1 -1
- package/city-test/agent-http.test.mjs +326 -0
- package/city-test/city-container.test.mjs +156 -0
- package/city-test/city-host-registry.test.mjs +68 -0
- package/city-test/city-transport.test.mjs +282 -0
- package/city-test/group.test.mjs +739 -0
- package/city-test/session-model.test.mjs +169 -0
- package/city-test/transport-lifecycle.test.mjs +164 -0
- package/package.json +30 -17
- package/scripts/ModelClientMock.mjs +165 -0
- package/scripts/action-schedule-store.test.mjs +81 -11
- package/scripts/agent-compiler.mjs +10 -6
- package/scripts/agent-env-shell-sandbox.test.mjs +10 -10
- package/scripts/agent-env.test.mjs +6 -8
- package/scripts/agent-multi-workspace.test.mjs +213 -0
- package/scripts/agent-ready.test.mjs +71 -16
- package/scripts/agent-session-maintenance.test.mjs +15 -28
- package/scripts/agent-store.test.mjs +121 -22
- package/scripts/city-model-tool-loop.test.mjs +66 -195
- package/scripts/core-engine-context-compaction.test.mjs +65 -113
- package/scripts/core-engine-model-stream.test.mjs +87 -0
- package/scripts/executor-failure-result.test.mjs +13 -29
- package/scripts/file-tools.test.mjs +6 -6
- package/scripts/image-plugin-job.test.mjs +77 -40
- package/scripts/logger-isolation.test.mjs +2 -2
- package/scripts/multi-agent-plugin-isolation.test.mjs +11 -9
- package/scripts/plugin-tools.test.mjs +153 -18
- package/scripts/public-api-naming.test.mjs +0 -1
- package/scripts/rewrite-build-aliases.mjs +49 -0
- package/scripts/rpc-url-routing.test.mjs +29 -0
- package/scripts/search-tools.test.mjs +4 -4
- package/scripts/session-ask-question.test.mjs +23 -21
- package/scripts/session-attachments.test.mjs +11 -9
- package/scripts/session-compact-handle.test.mjs +6 -5
- package/scripts/session-composer.test.mjs +61 -18
- package/scripts/session-config-turn-boundary.test.mjs +123 -92
- package/scripts/session-dynamic-interaction.test.mjs +75 -0
- package/scripts/session-fork.test.mjs +35 -0
- package/scripts/session-list-title.test.mjs +14 -56
- package/scripts/session-messages.test.mjs +306 -1681
- package/scripts/session-shell-approval.test.mjs +16 -13
- package/scripts/session-system-blocks.test.mjs +1 -1
- package/scripts/session-title-event.test.mjs +38 -24
- package/scripts/session-tool-approval.test.mjs +17 -15
- package/scripts/session-turn-context.test.mjs +31 -28
- package/scripts/session-turn-failure.test.mjs +112 -110
- package/scripts/verify-build-aliases.mjs +32 -0
- package/scripts/workspace.test.mjs +146 -32
- package/src/agent/Agent.ts +138 -238
- package/src/agent/AgentModel.ts +9 -9
- package/src/agent/AgentSessions.ts +116 -65
- package/src/agent/WorkspaceEntry.ts +309 -0
- package/src/agent/index.ts +4 -0
- package/src/city/host/CityHostRegistry.ts +260 -0
- package/src/city/index.ts +49 -0
- package/src/city/runtime/City.ts +425 -0
- package/src/city/transport/SerializedTransport.ts +65 -0
- package/src/city/transport/http/AgentHTTP.ts +176 -0
- package/src/city/transport/http/CityHTTP.ts +196 -0
- package/src/city/transport/http/NodeHttpAdapter.ts +75 -0
- package/src/city/transport/http/routes/RuntimeRoutes.ts +51 -0
- package/src/city/transport/http/routes/SessionRoutes.ts +497 -0
- package/src/city/transport/rpc/AgentRPC.ts +111 -0
- package/src/city/transport/rpc/CityRPC.ts +138 -0
- package/src/city/transport/rpc/RpcServer.ts +158 -0
- package/src/city/transport/rpc/server/InternalHandlers.ts +223 -0
- package/src/city/transport/rpc/server/RequestDispatcher.ts +67 -0
- package/src/city/transport/rpc/server/SdkSessionHandlers.ts +166 -0
- package/src/city/transport/rpc/server/ServerTypes.ts +103 -0
- package/src/city/transport/session/RemoteSessionConfig.ts +34 -0
- package/src/city/transport/types/AgentHttpBinding.ts +25 -0
- package/src/city/transport/types/AgentHttpRuntime.ts +13 -0
- package/src/city/transport/types/AgentRpcBinding.ts +28 -0
- package/src/city/transport/types/AgentRpcRuntime.ts +20 -0
- package/src/city/transport/types/AgentSessionModelResolver.ts +13 -0
- package/src/city/transport/types/CityHttpRuntime.ts +45 -0
- package/src/city/transport/types/CityRpcRuntime.ts +27 -0
- package/src/city/transport/types/RpcProtocol.ts +32 -0
- package/src/city/types/City.ts +99 -0
- package/src/city/types/PluginHostContext.ts +40 -0
- package/src/city/types/SerializedTransport.ts +19 -0
- package/src/executor/Executor.ts +101 -43
- package/src/executor/README.md +11 -8
- package/src/executor/composer/system/SessionSystemComposer.ts +2 -2
- package/src/executor/composer/system/default/PromptRenderer.ts +2 -2
- package/src/executor/composer/system/default/SystemDomain.ts +5 -5
- package/src/executor/composer/system/default/assets/core.prompt.ts +1 -1
- package/src/executor/composer/system/default/assets/core.prompt.ts.txt +4 -12
- package/src/executor/core-engine/CoreEngineContextCompaction.ts +113 -427
- package/src/executor/core-engine/CoreEngineError.ts +1 -1
- package/src/executor/core-engine/CoreEngineLoopDecision.ts +1 -18
- package/src/executor/core-engine/CoreEngineMessageState.ts +32 -101
- package/src/executor/core-engine/CoreEngineRunner.ts +179 -281
- package/src/executor/core-engine/CoreEngineSignals.ts +98 -346
- package/src/executor/messages/SessionAttachmentMapper.ts +15 -273
- package/src/executor/messages/SessionMessageLog.ts +12 -25
- package/src/executor/messages/SessionModelMessages.ts +223 -0
- package/src/executor/model/ModelGenerate.ts +71 -0
- package/src/executor/model/ModelStepRunner.ts +381 -0
- package/src/executor/services/ExecutorRecoveryPolicy.ts +4 -4
- package/src/executor/types/SessionHistoryMeta.ts +8 -2
- package/src/executor/types/SessionLoop.ts +0 -26
- package/src/executor/types/SessionPrompts.ts +8 -8
- package/src/group/Group.ts +45 -0
- package/src/group/GroupSession.ts +728 -0
- package/src/group/GroupSessions.ts +104 -0
- package/src/group/index.ts +29 -0
- package/src/index.ts +108 -60
- package/src/internal/AgentRuntime.ts +229 -0
- package/src/internal/GroupRuntime.ts +89 -0
- package/src/internal/index.ts +33 -0
- package/src/plugin/core/ActionScheduleExecutor.ts +17 -5
- package/src/plugin/core/ActionScheduleRuntime.ts +16 -6
- package/src/plugin/core/ActionScheduleStore.ts +43 -12
- package/src/plugin/core/HookRegistry.ts +24 -14
- package/src/plugin/core/PluginActionExecution.ts +230 -0
- package/src/plugin/core/PluginActionFactory.ts +9 -3
- package/src/plugin/core/PluginContext.ts +25 -6
- package/src/plugin/core/PluginHttpRoutes.ts +2 -2
- package/src/plugin/core/PluginRegistry.ts +193 -107
- package/src/plugin/tool/PluginToolRuntime.ts +4 -1
- package/src/plugin/tool/PluginToolSchemas.ts +3 -4
- package/src/plugin/tool/PluginTools.ts +12 -8
- package/src/plugin/types/ActionSchedule.ts +6 -0
- package/src/remote/transports/HttpRemoteAgentTransport.ts +3 -3
- package/src/remote/transports/RpcClient.ts +17 -0
- package/src/remote/transports/RpcRemoteAgentTransport.ts +1 -0
- package/src/session/DefaultSessionComposer.ts +3 -3
- package/src/session/Session.ts +54 -42
- package/src/session/SessionLoop.ts +27 -34
- package/src/session/SessionMessages.ts +63 -121
- package/src/session/SessionState.ts +46 -21
- package/src/session/SessionTitle.ts +23 -40
- package/src/session/browse/Browse.ts +35 -63
- package/src/session/control/SessionInteractions.ts +72 -51
- package/src/session/execution/SessionAssistantOutputAdapter.ts +44 -45
- package/src/session/execution/tools/SessionShellApprovalAdapter.ts +20 -9
- package/src/session/messages/SessionAssistantMessageWriter.ts +259 -637
- package/src/session/messages/SessionJsonValue.ts +0 -23
- package/src/session/messages/SessionMessageCompaction.ts +78 -103
- package/src/session/messages/SessionMessageInteractionWriter.ts +22 -22
- package/src/session/messages/SessionMessageText.ts +73 -0
- package/src/session/preview/SessionMessagePreview.ts +15 -45
- package/src/session/runtime/SessionTurnContext.ts +11 -9
- package/src/session/storage/Metadata.ts +38 -9
- package/src/tools/ask/AskQuestionsTool.ts +28 -17
- package/src/types/action/ActionResult.ts +20 -11
- package/src/types/agent/AgentOptions.ts +6 -13
- package/src/types/agent/AgentSessionCollection.ts +61 -0
- package/src/types/agent/AgentStorage.ts +19 -0
- package/src/types/agent/RemoteAgentOptions.ts +1 -1
- package/src/types/agent/SessionActor.ts +9 -0
- package/src/types/agent/SessionTypes.ts +31 -11
- package/src/types/agent/WorkspaceEntryOptions.ts +18 -0
- package/src/types/executor/SessionAssistantOutput.ts +22 -17
- package/src/types/executor/SessionToolExecutionContext.ts +9 -4
- package/src/types/executor/SessionTurnContext.ts +11 -11
- package/src/types/group/DispatchStrategy.ts +165 -0
- package/src/types/group/Group.ts +64 -0
- package/src/types/group/GroupSession.ts +154 -0
- package/src/types/group/GroupSessionStore.ts +82 -0
- package/src/types/plugin/AgentPluginContext.ts +30 -0
- package/src/types/plugin/PluginAction.ts +7 -5
- package/src/types/plugin/PluginActionExecution.ts +36 -0
- package/src/types/plugin/PluginCommand.ts +5 -5
- package/src/types/plugin/PluginContext.ts +23 -7
- package/src/types/plugin/PluginExecutionContext.ts +6 -11
- package/src/types/plugin/PluginRuntime.ts +5 -0
- package/src/types/plugin/PluginServices.ts +11 -0
- package/src/types/plugin/PluginState.ts +2 -2
- package/src/types/plugin/PluginTool.ts +4 -1
- package/src/types/rpc/RpcProtocol.ts +24 -2
- package/src/types/sdk/AgentSessionAction.ts +8 -9
- package/src/types/sdk/AgentSessionPrompt.ts +8 -11
- package/src/types/session/SessionAction.ts +41 -0
- package/src/types/session/SessionComposer.ts +8 -13
- package/src/types/session/SessionContent.ts +52 -0
- package/src/types/session/SessionExecution.ts +9 -88
- package/src/types/session/SessionInteraction.ts +106 -73
- package/src/types/session/SessionLoop.ts +1 -1
- package/src/types/session/SessionMessage.ts +27 -94
- package/src/types/session/SessionMessages.ts +12 -9
- package/src/types/session/SessionOptions.ts +11 -4
- package/src/types/session/SessionOrigin.ts +21 -0
- package/src/types/session/SessionPort.ts +12 -20
- package/src/types/session/SessionState.ts +7 -4
- package/src/types/session/SessionTool.ts +12 -0
- package/src/types/store/LocalStore.ts +19 -11
- package/src/types/store/SessionAttachmentStore.ts +4 -4
- package/src/types/store/SessionDataStore.ts +109 -0
- package/src/types/store/SessionStore.ts +37 -94
- package/src/types/tools/ToolActionExecutionContext.ts +32 -0
- package/src/utils/logger/Logger.ts +33 -12
- package/src/workspace/WorkspacePaths.ts +7 -51
- package/src/workspace/store/JsonlSessionMessageStore.ts +2 -2
- package/src/workspace/store/LocalGroupSessionDataStore.ts +232 -0
- package/src/workspace/store/LocalGroupSessionStore.ts +90 -0
- package/src/workspace/store/LocalSessionAttachmentStore.ts +3 -3
- package/src/workspace/store/LocalSessionDataStore.ts +169 -0
- package/src/workspace/store/LocalSessionStore.ts +202 -86
- package/src/workspace/store/LocalStorePaths.ts +65 -147
- package/src/workspace/store/SessionMessageStoreFactory.ts +1 -1
- package/tsconfig.json +2 -1
- package/tsconfig.tsbuildinfo +1 -1
- package/LICENSE +0 -183
- package/bin/agent/AgentState.d.ts +0 -45
- package/bin/agent/AgentState.d.ts.map +0 -1
- package/bin/agent/AgentState.js +0 -74
- package/bin/agent/AgentState.js.map +0 -1
- package/bin/executor/core-engine/CoreEngineUiStreamCollector.d.ts +0 -48
- package/bin/executor/core-engine/CoreEngineUiStreamCollector.d.ts.map +0 -1
- package/bin/executor/core-engine/CoreEngineUiStreamCollector.js +0 -92
- package/bin/executor/core-engine/CoreEngineUiStreamCollector.js.map +0 -1
- package/bin/executor/messages/SessionMessageCodec.d.ts +0 -29
- package/bin/executor/messages/SessionMessageCodec.d.ts.map +0 -1
- package/bin/executor/messages/SessionMessageCodec.js +0 -75
- package/bin/executor/messages/SessionMessageCodec.js.map +0 -1
- package/bin/executor/messages/SessionStepEventMapper.d.ts +0 -19
- package/bin/executor/messages/SessionStepEventMapper.d.ts.map +0 -1
- package/bin/executor/messages/SessionStepEventMapper.js +0 -177
- package/bin/executor/messages/SessionStepEventMapper.js.map +0 -1
- package/bin/executor/messages/UIMessageTransformer.d.ts +0 -29
- package/bin/executor/messages/UIMessageTransformer.d.ts.map +0 -1
- package/bin/executor/messages/UIMessageTransformer.js +0 -114
- package/bin/executor/messages/UIMessageTransformer.js.map +0 -1
- package/bin/executor/messages/UserVisibleText.d.ts +0 -26
- package/bin/executor/messages/UserVisibleText.d.ts.map +0 -1
- package/bin/executor/messages/UserVisibleText.js +0 -65
- package/bin/executor/messages/UserVisibleText.js.map +0 -1
- package/bin/executor/types/SessionRecords.d.ts +0 -162
- package/bin/executor/types/SessionRecords.d.ts.map +0 -1
- package/bin/executor/types/SessionRecords.js +0 -51
- package/bin/executor/types/SessionRecords.js.map +0 -1
- package/bin/plugin/core/PluginActionRunner.d.ts +0 -24
- package/bin/plugin/core/PluginActionRunner.d.ts.map +0 -1
- package/bin/plugin/core/PluginActionRunner.js +0 -19
- package/bin/plugin/core/PluginActionRunner.js.map +0 -1
- package/bin/session/messages/SessionMessageCodec.d.ts +0 -23
- package/bin/session/messages/SessionMessageCodec.d.ts.map +0 -1
- package/bin/session/messages/SessionMessageCodec.js +0 -455
- package/bin/session/messages/SessionMessageCodec.js.map +0 -1
- package/bin/types/agent/AgentState.d.ts +0 -19
- package/bin/types/agent/AgentState.d.ts.map +0 -1
- package/bin/types/agent/AgentState.js +0 -9
- package/bin/types/agent/AgentState.js.map +0 -1
- package/bin/types/store/AgentStore.d.ts +0 -31
- package/bin/types/store/AgentStore.d.ts.map +0 -1
- package/bin/types/store/AgentStore.js +0 -9
- package/bin/types/store/AgentStore.js.map +0 -1
- package/bin/types/workspace/FileSystem.d.ts +0 -55
- package/bin/types/workspace/FileSystem.d.ts.map +0 -1
- package/bin/types/workspace/FileSystem.js +0 -9
- package/bin/types/workspace/FileSystem.js.map +0 -1
- package/bin/types/workspace/FileTool.d.ts +0 -181
- package/bin/types/workspace/FileTool.d.ts.map +0 -1
- package/bin/types/workspace/FileTool.js +0 -10
- package/bin/types/workspace/FileTool.js.map +0 -1
- package/bin/types/workspace/SearchTool.d.ts +0 -131
- package/bin/types/workspace/SearchTool.d.ts.map +0 -1
- package/bin/types/workspace/SearchTool.js +0 -10
- package/bin/types/workspace/SearchTool.js.map +0 -1
- package/bin/types/workspace/Workspace.d.ts +0 -24
- package/bin/types/workspace/Workspace.d.ts.map +0 -1
- package/bin/types/workspace/Workspace.js +0 -9
- package/bin/types/workspace/Workspace.js.map +0 -1
- package/bin/types/workspace/WorkspaceEnv.d.ts +0 -16
- package/bin/types/workspace/WorkspaceEnv.d.ts.map +0 -1
- package/bin/types/workspace/WorkspaceEnv.js +0 -9
- package/bin/types/workspace/WorkspaceEnv.js.map +0 -1
- package/bin/types/workspace/WorkspaceTools.d.ts +0 -20
- package/bin/types/workspace/WorkspaceTools.d.ts.map +0 -1
- package/bin/types/workspace/WorkspaceTools.js +0 -9
- package/bin/types/workspace/WorkspaceTools.js.map +0 -1
- package/bin/utils/cli/CliOutput.d.ts +0 -14
- package/bin/utils/cli/CliOutput.d.ts.map +0 -1
- package/bin/utils/cli/CliOutput.js +0 -98
- package/bin/utils/cli/CliOutput.js.map +0 -1
- package/bin/utils/cli/PrettyStatus.d.ts +0 -25
- package/bin/utils/cli/PrettyStatus.d.ts.map +0 -1
- package/bin/utils/cli/PrettyStatus.js +0 -77
- package/bin/utils/cli/PrettyStatus.js.map +0 -1
- package/bin/utils/logger/FormatRequest.d.ts +0 -29
- package/bin/utils/logger/FormatRequest.d.ts.map +0 -1
- package/bin/utils/logger/FormatRequest.js +0 -309
- package/bin/utils/logger/FormatRequest.js.map +0 -1
- package/bin/utils/logger/FormatResponse.d.ts +0 -46
- package/bin/utils/logger/FormatResponse.d.ts.map +0 -1
- package/bin/utils/logger/FormatResponse.js +0 -186
- package/bin/utils/logger/FormatResponse.js.map +0 -1
- package/bin/utils/logger/FormatShared.d.ts +0 -33
- package/bin/utils/logger/FormatShared.d.ts.map +0 -1
- package/bin/utils/logger/FormatShared.js +0 -215
- package/bin/utils/logger/FormatShared.js.map +0 -1
- package/bin/utils/object/DeepMerge.d.ts +0 -18
- package/bin/utils/object/DeepMerge.d.ts.map +0 -1
- package/bin/utils/object/DeepMerge.js +0 -37
- package/bin/utils/object/DeepMerge.js.map +0 -1
- package/bin/utils/object/ObjectGuards.d.ts +0 -17
- package/bin/utils/object/ObjectGuards.d.ts.map +0 -1
- package/bin/utils/object/ObjectGuards.js +0 -19
- package/bin/utils/object/ObjectGuards.js.map +0 -1
- package/bin/utils/path/AncestorFiles.d.ts +0 -17
- package/bin/utils/path/AncestorFiles.d.ts.map +0 -1
- package/bin/utils/path/AncestorFiles.js +0 -36
- package/bin/utils/path/AncestorFiles.js.map +0 -1
- package/bin/utils/storage/index.d.ts +0 -4
- package/bin/utils/storage/index.d.ts.map +0 -1
- package/bin/utils/storage/index.js +0 -17
- package/bin/utils/storage/index.js.map +0 -1
- package/bin/utils/string/EscapeRegExp.d.ts +0 -17
- package/bin/utils/string/EscapeRegExp.d.ts.map +0 -1
- package/bin/utils/string/EscapeRegExp.js +0 -19
- package/bin/utils/string/EscapeRegExp.js.map +0 -1
- package/bin/workspace/LocalFileSystem.d.ts +0 -44
- package/bin/workspace/LocalFileSystem.d.ts.map +0 -1
- package/bin/workspace/LocalFileSystem.js +0 -153
- package/bin/workspace/LocalFileSystem.js.map +0 -1
- package/bin/workspace/Workspace.d.ts +0 -53
- package/bin/workspace/Workspace.d.ts.map +0 -1
- package/bin/workspace/Workspace.js +0 -151
- package/bin/workspace/Workspace.js.map +0 -1
- package/bin/workspace/WorkspaceBase.d.ts +0 -41
- package/bin/workspace/WorkspaceBase.d.ts.map +0 -1
- package/bin/workspace/WorkspaceBase.js +0 -19
- package/bin/workspace/WorkspaceBase.js.map +0 -1
- package/bin/workspace/WorkspaceEnv.d.ts +0 -19
- package/bin/workspace/WorkspaceEnv.d.ts.map +0 -1
- package/bin/workspace/WorkspaceEnv.js +0 -50
- package/bin/workspace/WorkspaceEnv.js.map +0 -1
- package/bin/workspace/file/FileActionRuntime.d.ts +0 -14
- package/bin/workspace/file/FileActionRuntime.d.ts.map +0 -1
- package/bin/workspace/file/FileActionRuntime.js +0 -386
- package/bin/workspace/file/FileActionRuntime.js.map +0 -1
- package/bin/workspace/file/FileAtomicWriter.d.ts +0 -20
- package/bin/workspace/file/FileAtomicWriter.d.ts.map +0 -1
- package/bin/workspace/file/FileAtomicWriter.js +0 -50
- package/bin/workspace/file/FileAtomicWriter.js.map +0 -1
- package/bin/workspace/file/FileEncoding.d.ts +0 -34
- package/bin/workspace/file/FileEncoding.d.ts.map +0 -1
- package/bin/workspace/file/FileEncoding.js +0 -152
- package/bin/workspace/file/FileEncoding.js.map +0 -1
- package/bin/workspace/file/FilePathPolicy.d.ts +0 -26
- package/bin/workspace/file/FilePathPolicy.d.ts.map +0 -1
- package/bin/workspace/file/FilePathPolicy.js +0 -134
- package/bin/workspace/file/FilePathPolicy.js.map +0 -1
- package/bin/workspace/file/FileToolError.d.ts +0 -30
- package/bin/workspace/file/FileToolError.d.ts.map +0 -1
- package/bin/workspace/file/FileToolError.js +0 -78
- package/bin/workspace/file/FileToolError.js.map +0 -1
- package/bin/workspace/search/SearchActionRuntime.d.ts +0 -14
- package/bin/workspace/search/SearchActionRuntime.d.ts.map +0 -1
- package/bin/workspace/search/SearchActionRuntime.js +0 -359
- package/bin/workspace/search/SearchActionRuntime.js.map +0 -1
- package/bin/workspace/search/SearchToolError.d.ts +0 -26
- package/bin/workspace/search/SearchToolError.d.ts.map +0 -1
- package/bin/workspace/search/SearchToolError.js +0 -76
- package/bin/workspace/search/SearchToolError.js.map +0 -1
- package/bin/workspace/store/LocalAgentStore.d.ts +0 -43
- package/bin/workspace/store/LocalAgentStore.d.ts.map +0 -1
- package/bin/workspace/store/LocalAgentStore.js +0 -135
- package/bin/workspace/store/LocalAgentStore.js.map +0 -1
- package/bin/workspace/tool/FileToolSchemas.d.ts +0 -35
- package/bin/workspace/tool/FileToolSchemas.d.ts.map +0 -1
- package/bin/workspace/tool/FileToolSchemas.js +0 -73
- package/bin/workspace/tool/FileToolSchemas.js.map +0 -1
- package/bin/workspace/tool/FileTools.d.ts +0 -11
- package/bin/workspace/tool/FileTools.d.ts.map +0 -1
- package/bin/workspace/tool/FileTools.js +0 -61
- package/bin/workspace/tool/FileTools.js.map +0 -1
- package/bin/workspace/tool/SearchToolSchemas.d.ts +0 -24
- package/bin/workspace/tool/SearchToolSchemas.d.ts.map +0 -1
- package/bin/workspace/tool/SearchToolSchemas.js +0 -60
- package/bin/workspace/tool/SearchToolSchemas.js.map +0 -1
- package/bin/workspace/tool/SearchTools.d.ts +0 -11
- package/bin/workspace/tool/SearchTools.d.ts.map +0 -1
- package/bin/workspace/tool/SearchTools.js +0 -38
- package/bin/workspace/tool/SearchTools.js.map +0 -1
- package/bin/workspace/tool/WorkspaceTools.d.ts +0 -11
- package/bin/workspace/tool/WorkspaceTools.d.ts.map +0 -1
- package/bin/workspace/tool/WorkspaceTools.js +0 -22
- package/bin/workspace/tool/WorkspaceTools.js.map +0 -1
- package/scripts/core-engine-ui-stream-collector.test.mjs +0 -38
- package/scripts/openai-responses-continuation.test.mjs +0 -78
- package/src/agent/AgentState.ts +0 -96
- package/src/executor/core-engine/CoreEngineUiStreamCollector.ts +0 -136
- package/src/executor/messages/SessionMessageCodec.ts +0 -106
- package/src/executor/messages/SessionStepEventMapper.ts +0 -191
- package/src/executor/messages/UIMessageTransformer.ts +0 -152
- package/src/executor/messages/UserVisibleText.ts +0 -75
- package/src/executor/types/SessionRecords.ts +0 -217
- package/src/plugin/core/PluginActionRunner.ts +0 -36
- package/src/session/messages/SessionMessageCodec.ts +0 -495
- package/src/types/agent/AgentState.ts +0 -22
- package/src/types/store/AgentStore.ts +0 -52
- package/src/types/workspace/FileSystem.ts +0 -76
- package/src/types/workspace/FileTool.ts +0 -225
- package/src/types/workspace/SearchTool.ts +0 -156
- package/src/types/workspace/Workspace.ts +0 -27
- package/src/types/workspace/WorkspaceEnv.ts +0 -19
- package/src/types/workspace/WorkspaceTools.ts +0 -23
- package/src/utils/cli/CliOutput.ts +0 -128
- package/src/utils/cli/PrettyStatus.ts +0 -94
- package/src/utils/logger/FormatRequest.ts +0 -455
- package/src/utils/logger/FormatResponse.ts +0 -265
- package/src/utils/logger/FormatShared.ts +0 -258
- package/src/utils/object/DeepMerge.ts +0 -40
- package/src/utils/object/ObjectGuards.ts +0 -19
- package/src/utils/path/AncestorFiles.ts +0 -40
- package/src/utils/storage/index.ts +0 -19
- package/src/utils/string/EscapeRegExp.ts +0 -19
- package/src/workspace/LocalFileSystem.ts +0 -209
- package/src/workspace/Workspace.ts +0 -178
- package/src/workspace/WorkspaceBase.ts +0 -62
- package/src/workspace/WorkspaceEnv.ts +0 -54
- package/src/workspace/file/FileActionRuntime.ts +0 -433
- package/src/workspace/file/FileAtomicWriter.ts +0 -61
- package/src/workspace/file/FileEncoding.ts +0 -175
- package/src/workspace/file/FilePathPolicy.ts +0 -162
- package/src/workspace/file/FileToolError.ts +0 -99
- package/src/workspace/search/SearchActionRuntime.ts +0 -438
- package/src/workspace/search/SearchToolError.ts +0 -94
- package/src/workspace/store/LocalAgentStore.ts +0 -191
- package/src/workspace/tool/FileToolSchemas.ts +0 -77
- package/src/workspace/tool/FileTools.ts +0 -91
- package/src/workspace/tool/SearchToolSchemas.ts +0 -62
- package/src/workspace/tool/SearchTools.ts +0 -61
- package/src/workspace/tool/WorkspaceTools.ts +0 -31
|
@@ -1,455 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* LLM 请求日志格式化。
|
|
3
|
-
*
|
|
4
|
-
* 关键点(中文)
|
|
5
|
-
* - 这里专注把 provider request 规整成易读日志。
|
|
6
|
-
* - system / messages / tool calls 的展示策略统一收敛在本文件。
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
import type { JsonObject, JsonValue } from "@/types/common/Json.js";
|
|
10
|
-
import {
|
|
11
|
-
build_info_attrs,
|
|
12
|
-
content_to_text,
|
|
13
|
-
extract_function_call_exec_command_cmd,
|
|
14
|
-
extract_messages,
|
|
15
|
-
extract_system_for_log,
|
|
16
|
-
format_log_field,
|
|
17
|
-
get_object_field,
|
|
18
|
-
get_string_field,
|
|
19
|
-
is_json_object,
|
|
20
|
-
parse_info_block_text,
|
|
21
|
-
push_labeled_text_block,
|
|
22
|
-
safe_json_parse,
|
|
23
|
-
stringify_compact,
|
|
24
|
-
to_inline_log_value,
|
|
25
|
-
truncate,
|
|
26
|
-
type ParsedPayload,
|
|
27
|
-
} from "./FormatShared.js";
|
|
28
|
-
|
|
29
|
-
// 关键点(中文):system/developer 指令需要完整可审计,日志不做截断。
|
|
30
|
-
const UNLIMITED_LOG_CHARS = Number.MAX_SAFE_INTEGER;
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* 按会话记录“上次已打印的消息数”。
|
|
34
|
-
*
|
|
35
|
-
* 关键点(中文)
|
|
36
|
-
* - 用于 LLM 请求日志的增量打印,避免每轮都重复输出全量历史 messages。
|
|
37
|
-
* - key 建议使用 session_id;无 key 时保持原有行为(全量打印)。
|
|
38
|
-
*/
|
|
39
|
-
const lastLoggedMessagesCountByKey = new Map<string, number>();
|
|
40
|
-
|
|
41
|
-
interface FormattedToolCall {
|
|
42
|
-
/**
|
|
43
|
-
* provider 返回的 tool call id。
|
|
44
|
-
*/
|
|
45
|
-
id?: string;
|
|
46
|
-
/**
|
|
47
|
-
* provider 返回的 tool call 类型。
|
|
48
|
-
*/
|
|
49
|
-
type?: string;
|
|
50
|
-
/**
|
|
51
|
-
* 工具或函数名。
|
|
52
|
-
*/
|
|
53
|
-
name?: string;
|
|
54
|
-
/**
|
|
55
|
-
* 归一化后的参数文本。
|
|
56
|
-
*/
|
|
57
|
-
arguments?: string;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
function formatToolCalls(
|
|
61
|
-
toolCalls: JsonValue | undefined,
|
|
62
|
-
maxArgsChars: number,
|
|
63
|
-
): FormattedToolCall[] | null {
|
|
64
|
-
if (!Array.isArray(toolCalls) || toolCalls.length === 0) return null;
|
|
65
|
-
const out: FormattedToolCall[] = [];
|
|
66
|
-
|
|
67
|
-
for (const toolCall of toolCalls) {
|
|
68
|
-
if (!is_json_object(toolCall)) continue;
|
|
69
|
-
|
|
70
|
-
const id = get_string_field(toolCall, "id");
|
|
71
|
-
const type = get_string_field(toolCall, "type");
|
|
72
|
-
const fn = get_object_field(toolCall, "function");
|
|
73
|
-
const name =
|
|
74
|
-
(fn && get_string_field(fn, "name")) || get_string_field(toolCall, "tool");
|
|
75
|
-
const argsRaw = fn ? fn.arguments : toolCall.arguments;
|
|
76
|
-
const args =
|
|
77
|
-
typeof argsRaw === "string"
|
|
78
|
-
? truncate(argsRaw, maxArgsChars)
|
|
79
|
-
: truncate(JSON.stringify(argsRaw ?? {}), maxArgsChars);
|
|
80
|
-
|
|
81
|
-
out.push({
|
|
82
|
-
...(id ? { id } : {}),
|
|
83
|
-
...(type ? { type } : {}),
|
|
84
|
-
...(name ? { name } : {}),
|
|
85
|
-
...(args ? { arguments: args } : {}),
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
return out.length > 0 ? out : null;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
function summarizeValue(value: JsonValue | undefined): string {
|
|
93
|
-
if (value === null || value === undefined) return "";
|
|
94
|
-
if (typeof value === "string") return value;
|
|
95
|
-
if (typeof value === "number" || typeof value === "boolean") {
|
|
96
|
-
return String(value);
|
|
97
|
-
}
|
|
98
|
-
if (Array.isArray(value)) return `[array:${value.length}]`;
|
|
99
|
-
if (is_json_object(value)) return `[object:${Object.keys(value).length}]`;
|
|
100
|
-
return String(value);
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
/**
|
|
104
|
-
* 规范化 system 提示词文本用于日志展示。
|
|
105
|
-
*
|
|
106
|
-
* 关键点(中文)
|
|
107
|
-
* - `system` 可能是 string / object / array(不同 provider 形态不一致)。
|
|
108
|
-
* - 统一折叠为可读文本,便于和历史 message 分段展示。
|
|
109
|
-
*/
|
|
110
|
-
function normalizeSystemTextForLog(
|
|
111
|
-
system: JsonValue | undefined,
|
|
112
|
-
maxChars: number,
|
|
113
|
-
): string {
|
|
114
|
-
if (system === null || system === undefined) return "";
|
|
115
|
-
if (typeof system === "string") return truncate(system, maxChars);
|
|
116
|
-
|
|
117
|
-
if (Array.isArray(system)) {
|
|
118
|
-
const merged = system
|
|
119
|
-
.map((item) => summarizeValue(item))
|
|
120
|
-
.filter(Boolean)
|
|
121
|
-
.join("\n");
|
|
122
|
-
return truncate(merged, maxChars);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
if (is_json_object(system)) {
|
|
126
|
-
const directText =
|
|
127
|
-
get_string_field(system, "text") ||
|
|
128
|
-
get_string_field(system, "content") ||
|
|
129
|
-
get_string_field(system, "instructions");
|
|
130
|
-
if (directText) return truncate(directText, maxChars);
|
|
131
|
-
return stringify_compact(system, maxChars);
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
return truncate(String(system), maxChars);
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
function formatMessagesForLog(
|
|
138
|
-
messages: JsonObject[],
|
|
139
|
-
opts: {
|
|
140
|
-
/**
|
|
141
|
-
* 普通消息的最大字符数。
|
|
142
|
-
*/
|
|
143
|
-
maxContentChars: number;
|
|
144
|
-
/**
|
|
145
|
-
* tool 参数的最大字符数。
|
|
146
|
-
*/
|
|
147
|
-
maxToolArgsChars: number;
|
|
148
|
-
/**
|
|
149
|
-
* system 消息的最大字符数。
|
|
150
|
-
*/
|
|
151
|
-
maxSystemChars: number;
|
|
152
|
-
},
|
|
153
|
-
): string[] {
|
|
154
|
-
const out: string[] = [];
|
|
155
|
-
|
|
156
|
-
for (const message of messages) {
|
|
157
|
-
const role = String(get_string_field(message, "role") || "").trim().toLowerCase();
|
|
158
|
-
const itemType = String(get_string_field(message, "type") || "")
|
|
159
|
-
.trim()
|
|
160
|
-
.toLowerCase();
|
|
161
|
-
const output = summarizeValue(message.output);
|
|
162
|
-
const outputText = summarizeValue(message.output_text);
|
|
163
|
-
|
|
164
|
-
const toolCalls = formatToolCalls(message.tool_calls, opts.maxToolArgsChars);
|
|
165
|
-
if (toolCalls) {
|
|
166
|
-
for (const toolCall of toolCalls) {
|
|
167
|
-
const detail = [
|
|
168
|
-
toolCall.name ? String(toolCall.name) : "",
|
|
169
|
-
toolCall.arguments ? `args=${toolCall.arguments}` : "",
|
|
170
|
-
]
|
|
171
|
-
.filter(Boolean)
|
|
172
|
-
.join(" | ");
|
|
173
|
-
if (detail) {
|
|
174
|
-
push_labeled_text_block(out, "tool", detail, opts.maxToolArgsChars);
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
if (itemType === "function_call") {
|
|
180
|
-
const functionName = String(get_string_field(message, "name") || "").trim();
|
|
181
|
-
const functionCallExecCmd = extract_function_call_exec_command_cmd(message);
|
|
182
|
-
const argsText =
|
|
183
|
-
typeof message.arguments === "string"
|
|
184
|
-
? truncate(message.arguments, opts.maxToolArgsChars)
|
|
185
|
-
: "";
|
|
186
|
-
const functionCallDetail = [
|
|
187
|
-
functionName || "function_call",
|
|
188
|
-
functionCallExecCmd ? `cmd=${functionCallExecCmd}` : "",
|
|
189
|
-
!functionCallExecCmd && argsText ? `args=${argsText}` : "",
|
|
190
|
-
]
|
|
191
|
-
.filter(Boolean)
|
|
192
|
-
.join(" | ");
|
|
193
|
-
push_labeled_text_block(
|
|
194
|
-
out,
|
|
195
|
-
"tool",
|
|
196
|
-
functionCallDetail || "function_call",
|
|
197
|
-
opts.maxToolArgsChars,
|
|
198
|
-
);
|
|
199
|
-
continue;
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
let body_text = "";
|
|
203
|
-
let userInfoAttrs: string[] = [];
|
|
204
|
-
if ("content" in message) {
|
|
205
|
-
const isSystemRole = role === "system" || role === "developer";
|
|
206
|
-
const contentText = content_to_text(
|
|
207
|
-
message.content,
|
|
208
|
-
isSystemRole ? opts.maxSystemChars : opts.maxContentChars,
|
|
209
|
-
);
|
|
210
|
-
if (role === "user") {
|
|
211
|
-
const parsedInfoBlock = parse_info_block_text(contentText);
|
|
212
|
-
body_text = parsedInfoBlock ? parsedInfoBlock.body : contentText;
|
|
213
|
-
userInfoAttrs = parsedInfoBlock ? build_info_attrs(parsedInfoBlock.info) : [];
|
|
214
|
-
} else {
|
|
215
|
-
body_text = contentText;
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
if (role === "user") {
|
|
220
|
-
push_labeled_text_block(
|
|
221
|
-
out,
|
|
222
|
-
"user",
|
|
223
|
-
body_text || "-",
|
|
224
|
-
opts.maxContentChars,
|
|
225
|
-
userInfoAttrs,
|
|
226
|
-
);
|
|
227
|
-
continue;
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
if (role === "system" || role === "developer") {
|
|
231
|
-
push_labeled_text_block(out, "system", body_text || "-", opts.maxSystemChars);
|
|
232
|
-
continue;
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
if (
|
|
236
|
-
role === "tool" ||
|
|
237
|
-
itemType === "function_call_output" ||
|
|
238
|
-
itemType === "tool-result" ||
|
|
239
|
-
itemType === "tool_error" ||
|
|
240
|
-
itemType === "tool-error"
|
|
241
|
-
) {
|
|
242
|
-
const toolResultText = [body_text, outputText, output].filter(Boolean).join(" | ");
|
|
243
|
-
push_labeled_text_block(
|
|
244
|
-
out,
|
|
245
|
-
"tool_result",
|
|
246
|
-
toolResultText || "-",
|
|
247
|
-
opts.maxContentChars,
|
|
248
|
-
);
|
|
249
|
-
continue;
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
const assistantText = [body_text, outputText, output]
|
|
253
|
-
.filter(Boolean)
|
|
254
|
-
.join(body_text ? "" : " | ");
|
|
255
|
-
if (assistantText) {
|
|
256
|
-
push_labeled_text_block(out, "assistant", assistantText, opts.maxContentChars);
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
return out;
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
function formatPayloadSummaryLines(
|
|
264
|
-
payload: ParsedPayload,
|
|
265
|
-
maxChars: number,
|
|
266
|
-
): string[] {
|
|
267
|
-
if (Array.isArray(payload)) {
|
|
268
|
-
return [format_log_field("agent", `payload=[array:${payload.length}]`)];
|
|
269
|
-
}
|
|
270
|
-
const keys = Object.keys(payload).slice(0, 12).join(",") || "-";
|
|
271
|
-
return [format_log_field("agent", to_inline_log_value(`payload.keys=${keys}`, maxChars))];
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
function selectMessagesForIncrementalLog(
|
|
275
|
-
messages: JsonObject[],
|
|
276
|
-
incrementalKey: string,
|
|
277
|
-
): JsonObject[] {
|
|
278
|
-
if (!incrementalKey) return messages;
|
|
279
|
-
|
|
280
|
-
const prevCount = lastLoggedMessagesCountByKey.get(incrementalKey) ?? 0;
|
|
281
|
-
const currentCount = messages.length;
|
|
282
|
-
lastLoggedMessagesCountByKey.set(incrementalKey, currentCount);
|
|
283
|
-
|
|
284
|
-
if (currentCount > prevCount) {
|
|
285
|
-
return trimLeadingAssistantMessages(messages.slice(prevCount));
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
// 关键点(中文):当消息数回退(compact/rewrite)时,打印最近两条作为对齐点。
|
|
289
|
-
if (currentCount < prevCount) {
|
|
290
|
-
return trimLeadingAssistantMessages(
|
|
291
|
-
messages.slice(Math.max(0, currentCount - 2)),
|
|
292
|
-
);
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
return [];
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
function trimLeadingAssistantMessages(messages: JsonObject[]): JsonObject[] {
|
|
299
|
-
if (!Array.isArray(messages) || messages.length === 0) return [];
|
|
300
|
-
const firstUserIndex = messages.findIndex(
|
|
301
|
-
(message) => get_string_field(message, "role") === "user",
|
|
302
|
-
);
|
|
303
|
-
if (firstUserIndex <= 0) return messages;
|
|
304
|
-
for (let index = 0; index < firstUserIndex; index += 1) {
|
|
305
|
-
if (get_string_field(messages[index], "role") !== "assistant") {
|
|
306
|
-
return messages;
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
|
-
// 关键点(中文):增量片段若以“上一轮 assistant 历史”开头且随后有新 user,默认省略前置 assistant,避免视觉延迟错觉。
|
|
310
|
-
return messages.slice(firstUserIndex);
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
export function parse_fetch_request_for_log(
|
|
314
|
-
input: string | URL | Request,
|
|
315
|
-
init?: RequestInit,
|
|
316
|
-
opts?: {
|
|
317
|
-
/**
|
|
318
|
-
* 增量日志 key,通常使用 session_id。
|
|
319
|
-
*/
|
|
320
|
-
incrementalKey?: string;
|
|
321
|
-
},
|
|
322
|
-
): {
|
|
323
|
-
url: string;
|
|
324
|
-
method: string;
|
|
325
|
-
payload: ParsedPayload | null;
|
|
326
|
-
includePayload: boolean;
|
|
327
|
-
maxChars: number;
|
|
328
|
-
messages: JsonObject[] | null;
|
|
329
|
-
system: JsonValue | undefined;
|
|
330
|
-
model?: string;
|
|
331
|
-
toolsCount: number;
|
|
332
|
-
systemLength?: number;
|
|
333
|
-
requestText: string;
|
|
334
|
-
meta: JsonObject;
|
|
335
|
-
} | null {
|
|
336
|
-
// 关键注释:这里的 maxChars 不用于“整体截断请求日志”,仅作为 payload 兜底 stringify 的保护上限。
|
|
337
|
-
const maxChars = 12000;
|
|
338
|
-
// 统一开关:只由宿主配置的 llm.logMessages 控制(由宿主模型工厂读取)。
|
|
339
|
-
// 这里不支持额外的“更敏感 payload”开关,避免不一致与误配置。
|
|
340
|
-
const includePayload = false;
|
|
341
|
-
|
|
342
|
-
const url =
|
|
343
|
-
typeof input === "string"
|
|
344
|
-
? input
|
|
345
|
-
: input instanceof URL
|
|
346
|
-
? input.toString()
|
|
347
|
-
: input.url;
|
|
348
|
-
const method = String(
|
|
349
|
-
init?.method ||
|
|
350
|
-
(input instanceof Request ? input.method : "POST"),
|
|
351
|
-
);
|
|
352
|
-
|
|
353
|
-
const initBody = typeof init?.body === "string" ? init.body : undefined;
|
|
354
|
-
const payload = safe_json_parse(initBody);
|
|
355
|
-
if (!payload) {
|
|
356
|
-
if (initBody) {
|
|
357
|
-
return {
|
|
358
|
-
url,
|
|
359
|
-
method,
|
|
360
|
-
payload: null,
|
|
361
|
-
includePayload,
|
|
362
|
-
maxChars,
|
|
363
|
-
messages: null,
|
|
364
|
-
system: undefined,
|
|
365
|
-
toolsCount: 0,
|
|
366
|
-
requestText: format_log_field("agent", "llm.request non-json body"),
|
|
367
|
-
meta: { kind: "llm_request", url, method },
|
|
368
|
-
};
|
|
369
|
-
}
|
|
370
|
-
return null;
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
const payloadObject = is_json_object(payload) ? payload : undefined;
|
|
374
|
-
const model = payloadObject ? get_string_field(payloadObject, "model") : undefined;
|
|
375
|
-
const system = extract_system_for_log(payloadObject);
|
|
376
|
-
const messages = payloadObject ? extract_messages(payloadObject) : null;
|
|
377
|
-
const tools = payloadObject ? payloadObject.tools : undefined;
|
|
378
|
-
const toolChoiceRaw = payloadObject
|
|
379
|
-
? payloadObject.tool_choice ?? payloadObject.toolChoice
|
|
380
|
-
: undefined;
|
|
381
|
-
const toolChoice =
|
|
382
|
-
typeof toolChoiceRaw === "string"
|
|
383
|
-
? toolChoiceRaw
|
|
384
|
-
: toolChoiceRaw !== undefined
|
|
385
|
-
? stringify_compact(toolChoiceRaw as JsonValue | object, 300)
|
|
386
|
-
: undefined;
|
|
387
|
-
const toolsCount = Array.isArray(tools)
|
|
388
|
-
? tools.length
|
|
389
|
-
: is_json_object(tools)
|
|
390
|
-
? Object.keys(tools).length
|
|
391
|
-
: 0;
|
|
392
|
-
|
|
393
|
-
const messageTextParts: string[] = [];
|
|
394
|
-
const maxSystemChars = UNLIMITED_LOG_CHARS;
|
|
395
|
-
|
|
396
|
-
if (messages && Array.isArray(messages)) {
|
|
397
|
-
const hasSystemMessage = messages.some((item) => {
|
|
398
|
-
const role = String(get_string_field(item, "role") || "")
|
|
399
|
-
.trim()
|
|
400
|
-
.toLowerCase();
|
|
401
|
-
return role === "system" || role === "developer";
|
|
402
|
-
});
|
|
403
|
-
if (!hasSystemMessage) {
|
|
404
|
-
const systemText = normalizeSystemTextForLog(system, maxSystemChars).trim();
|
|
405
|
-
if (systemText) {
|
|
406
|
-
push_labeled_text_block(messageTextParts, "system", systemText, maxSystemChars);
|
|
407
|
-
}
|
|
408
|
-
}
|
|
409
|
-
|
|
410
|
-
const incrementalKey = String(opts?.incrementalKey || "").trim();
|
|
411
|
-
const selectedMessages = selectMessagesForIncrementalLog(
|
|
412
|
-
messages,
|
|
413
|
-
incrementalKey,
|
|
414
|
-
);
|
|
415
|
-
messageTextParts.push(...formatMessagesForLog(selectedMessages, {
|
|
416
|
-
maxContentChars: 2000,
|
|
417
|
-
maxToolArgsChars: 1200,
|
|
418
|
-
maxSystemChars,
|
|
419
|
-
}));
|
|
420
|
-
if (selectedMessages.length === 0) {
|
|
421
|
-
messageTextParts.push(format_log_field("agent", "no incremental items"));
|
|
422
|
-
}
|
|
423
|
-
} else {
|
|
424
|
-
messageTextParts.push(...formatPayloadSummaryLines(payload, maxChars));
|
|
425
|
-
}
|
|
426
|
-
if (messageTextParts.length === 0) {
|
|
427
|
-
messageTextParts.push(format_log_field("agent", "empty"));
|
|
428
|
-
}
|
|
429
|
-
|
|
430
|
-
return {
|
|
431
|
-
url,
|
|
432
|
-
method,
|
|
433
|
-
payload,
|
|
434
|
-
includePayload,
|
|
435
|
-
maxChars,
|
|
436
|
-
messages,
|
|
437
|
-
system,
|
|
438
|
-
model,
|
|
439
|
-
toolsCount,
|
|
440
|
-
systemLength: typeof system === "string" ? system.length : undefined,
|
|
441
|
-
// 注意:不做整体截断;每条消息已单独截断。
|
|
442
|
-
requestText: messageTextParts.join("\n\n"),
|
|
443
|
-
meta: {
|
|
444
|
-
kind: "llm_request",
|
|
445
|
-
url,
|
|
446
|
-
method,
|
|
447
|
-
...(model ? { model } : {}),
|
|
448
|
-
toolsCount,
|
|
449
|
-
...(toolChoice ? { toolChoice } : {}),
|
|
450
|
-
messagesCount: Array.isArray(messages) ? messages.length : 0,
|
|
451
|
-
...(typeof system === "string" ? { systemLength: system.length } : {}),
|
|
452
|
-
...(includePayload ? { payload } : {}),
|
|
453
|
-
},
|
|
454
|
-
};
|
|
455
|
-
}
|
|
@@ -1,265 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* LLM 响应日志格式化。
|
|
3
|
-
*
|
|
4
|
-
* 关键点(中文)
|
|
5
|
-
* - JSON 响应和 SSE 响应走不同摘要逻辑。
|
|
6
|
-
* - 日志里保留状态、内容类型、函数调用摘要,方便定位 provider 行为。
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
import type { JsonObject, JsonValue } from "@/types/common/Json.js";
|
|
10
|
-
import {
|
|
11
|
-
format_log_field,
|
|
12
|
-
get_array_field,
|
|
13
|
-
get_object_field,
|
|
14
|
-
get_string_field,
|
|
15
|
-
is_json_object,
|
|
16
|
-
safe_json_parse,
|
|
17
|
-
to_inline_log_value,
|
|
18
|
-
} from "./FormatShared.js";
|
|
19
|
-
|
|
20
|
-
interface ProviderResponseLike {
|
|
21
|
-
/**
|
|
22
|
-
* HTTP 状态码。
|
|
23
|
-
*/
|
|
24
|
-
status: number;
|
|
25
|
-
/**
|
|
26
|
-
* 是否为成功响应。
|
|
27
|
-
*/
|
|
28
|
-
ok: boolean;
|
|
29
|
-
/**
|
|
30
|
-
* 响应头访问器。
|
|
31
|
-
*/
|
|
32
|
-
headers: {
|
|
33
|
-
/**
|
|
34
|
-
* 根据头名获取值。
|
|
35
|
-
*/
|
|
36
|
-
get(name: string): string | null;
|
|
37
|
-
};
|
|
38
|
-
/**
|
|
39
|
-
* 将响应体读取为文本。
|
|
40
|
-
*/
|
|
41
|
-
text(): Promise<string>;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
function pickOutputTypes(output: JsonValue[] | undefined): string[] {
|
|
45
|
-
if (!Array.isArray(output)) return [];
|
|
46
|
-
return output
|
|
47
|
-
.map((item) => {
|
|
48
|
-
if (!is_json_object(item)) return "";
|
|
49
|
-
return get_string_field(item, "type") || "";
|
|
50
|
-
})
|
|
51
|
-
.filter((type) => Boolean(type))
|
|
52
|
-
.slice(0, 16);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
function pickFunctionCallNames(output: JsonValue[] | undefined): string[] {
|
|
56
|
-
if (!Array.isArray(output)) return [];
|
|
57
|
-
return output
|
|
58
|
-
.map((item) => {
|
|
59
|
-
if (!is_json_object(item)) return "";
|
|
60
|
-
if (get_string_field(item, "type") !== "function_call") return "";
|
|
61
|
-
return get_string_field(item, "name") || "";
|
|
62
|
-
})
|
|
63
|
-
.filter((name) => Boolean(name))
|
|
64
|
-
.slice(0, 8);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
function summarizeResponseObjectForLog(
|
|
68
|
-
responseObject: JsonObject | undefined,
|
|
69
|
-
): JsonObject {
|
|
70
|
-
if (!responseObject) return {};
|
|
71
|
-
|
|
72
|
-
const output = get_array_field(responseObject, "output");
|
|
73
|
-
const incompleteDetails =
|
|
74
|
-
get_object_field(responseObject, "incomplete_details") ||
|
|
75
|
-
get_object_field(responseObject, "incompleteDetails");
|
|
76
|
-
const finishReason =
|
|
77
|
-
get_string_field(responseObject, "finish_reason") ||
|
|
78
|
-
get_string_field(responseObject, "finishReason");
|
|
79
|
-
|
|
80
|
-
return {
|
|
81
|
-
responseId: get_string_field(responseObject, "id") || null,
|
|
82
|
-
responseObjectType: get_string_field(responseObject, "object") || null,
|
|
83
|
-
responseFinishReason: finishReason || null,
|
|
84
|
-
responseIncompleteReason:
|
|
85
|
-
get_string_field(incompleteDetails || {}, "reason") || null,
|
|
86
|
-
responseOutputCount: Array.isArray(output) ? output.length : 0,
|
|
87
|
-
responseOutputTypes: pickOutputTypes(output),
|
|
88
|
-
responseFunctionCallNames: pickFunctionCallNames(output),
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
function summarizeSseBodyForLog(body_text: string): JsonObject {
|
|
93
|
-
const eventTypes: string[] = [];
|
|
94
|
-
const streamedOutputTypes: string[] = [];
|
|
95
|
-
const functionCallNames: string[] = [];
|
|
96
|
-
let lastResponseObject: JsonObject | undefined;
|
|
97
|
-
|
|
98
|
-
let currentEvent = "";
|
|
99
|
-
let currentDataLines: string[] = [];
|
|
100
|
-
|
|
101
|
-
const flushEvent = (): void => {
|
|
102
|
-
const rawData = currentDataLines.join("\n").trim();
|
|
103
|
-
currentDataLines = [];
|
|
104
|
-
if (!rawData) {
|
|
105
|
-
currentEvent = "";
|
|
106
|
-
return;
|
|
107
|
-
}
|
|
108
|
-
if (rawData === "[DONE]") {
|
|
109
|
-
eventTypes.push(currentEvent || "done");
|
|
110
|
-
currentEvent = "";
|
|
111
|
-
return;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
const parsed = safe_json_parse(rawData);
|
|
115
|
-
if (parsed && is_json_object(parsed)) {
|
|
116
|
-
const explicitType = get_string_field(parsed, "type");
|
|
117
|
-
const eventLabel = currentEvent || explicitType || "message";
|
|
118
|
-
eventTypes.push(eventLabel);
|
|
119
|
-
|
|
120
|
-
const nestedResponse = get_object_field(parsed, "response");
|
|
121
|
-
if (nestedResponse) {
|
|
122
|
-
lastResponseObject = nestedResponse;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
const nestedItem = get_object_field(parsed, "item");
|
|
126
|
-
const itemType = get_string_field(nestedItem || {}, "type");
|
|
127
|
-
if (itemType && !streamedOutputTypes.includes(itemType)) {
|
|
128
|
-
streamedOutputTypes.push(itemType);
|
|
129
|
-
}
|
|
130
|
-
const functionName = get_string_field(nestedItem || {}, "name");
|
|
131
|
-
if (
|
|
132
|
-
itemType === "function_call" &&
|
|
133
|
-
functionName &&
|
|
134
|
-
!functionCallNames.includes(functionName)
|
|
135
|
-
) {
|
|
136
|
-
functionCallNames.push(functionName);
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
const directOutput = get_array_field(parsed, "output");
|
|
140
|
-
for (const outputType of pickOutputTypes(directOutput)) {
|
|
141
|
-
if (!streamedOutputTypes.includes(outputType)) {
|
|
142
|
-
streamedOutputTypes.push(outputType);
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
for (const functionCallName of pickFunctionCallNames(directOutput)) {
|
|
146
|
-
if (!functionCallNames.includes(functionCallName)) {
|
|
147
|
-
functionCallNames.push(functionCallName);
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
} else {
|
|
151
|
-
eventTypes.push(currentEvent || "message");
|
|
152
|
-
}
|
|
153
|
-
currentEvent = "";
|
|
154
|
-
};
|
|
155
|
-
|
|
156
|
-
for (const rawLine of String(body_text || "").split(/\r?\n/)) {
|
|
157
|
-
const line = String(rawLine || "");
|
|
158
|
-
if (!line.trim()) {
|
|
159
|
-
flushEvent();
|
|
160
|
-
continue;
|
|
161
|
-
}
|
|
162
|
-
if (line.startsWith("event:")) {
|
|
163
|
-
currentEvent = line.slice("event:".length).trim();
|
|
164
|
-
continue;
|
|
165
|
-
}
|
|
166
|
-
if (line.startsWith("data:")) {
|
|
167
|
-
currentDataLines.push(line.slice("data:".length).trim());
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
flushEvent();
|
|
171
|
-
|
|
172
|
-
const responseSummary = summarizeResponseObjectForLog(lastResponseObject);
|
|
173
|
-
return {
|
|
174
|
-
responseEventTypes: eventTypes.slice(0, 20),
|
|
175
|
-
streamedOutputTypes: streamedOutputTypes.slice(0, 16),
|
|
176
|
-
streamedFunctionCallNames: functionCallNames.slice(0, 8),
|
|
177
|
-
...responseSummary,
|
|
178
|
-
};
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
export async function parse_fetch_response_for_log(
|
|
182
|
-
response: ProviderResponseLike,
|
|
183
|
-
opts?: {
|
|
184
|
-
/**
|
|
185
|
-
* 原始请求 URL。
|
|
186
|
-
*/
|
|
187
|
-
url?: string;
|
|
188
|
-
/**
|
|
189
|
-
* 原始请求方法。
|
|
190
|
-
*/
|
|
191
|
-
method?: string;
|
|
192
|
-
},
|
|
193
|
-
): Promise<{
|
|
194
|
-
responseText: string;
|
|
195
|
-
meta: JsonObject;
|
|
196
|
-
}> {
|
|
197
|
-
const maxBodyPreviewChars = 2000;
|
|
198
|
-
const contentType = String(response.headers.get("content-type") || "").trim();
|
|
199
|
-
let body_text = "";
|
|
200
|
-
|
|
201
|
-
try {
|
|
202
|
-
body_text = await response.text();
|
|
203
|
-
} catch (error) {
|
|
204
|
-
const errorText = String(error || "unknown_error");
|
|
205
|
-
return {
|
|
206
|
-
responseText: format_log_field(
|
|
207
|
-
"agent",
|
|
208
|
-
to_inline_log_value(
|
|
209
|
-
`llm.response status=${response.status} ok=${response.ok} contentType=${contentType || "-"} body_read_error=${errorText}`,
|
|
210
|
-
maxBodyPreviewChars,
|
|
211
|
-
),
|
|
212
|
-
),
|
|
213
|
-
meta: {
|
|
214
|
-
kind: "llm_response",
|
|
215
|
-
status: response.status,
|
|
216
|
-
ok: response.ok,
|
|
217
|
-
...(contentType ? { contentType } : {}),
|
|
218
|
-
...(opts?.url ? { url: opts.url } : {}),
|
|
219
|
-
...(opts?.method ? { method: opts.method } : {}),
|
|
220
|
-
bodyReadError: errorText,
|
|
221
|
-
},
|
|
222
|
-
};
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
let responseSummary: JsonObject = {};
|
|
226
|
-
if (contentType.includes("application/json")) {
|
|
227
|
-
const parsed = safe_json_parse(body_text);
|
|
228
|
-
if (parsed && is_json_object(parsed)) {
|
|
229
|
-
const nestedResponse = get_object_field(parsed, "response");
|
|
230
|
-
responseSummary = summarizeResponseObjectForLog(
|
|
231
|
-
nestedResponse || parsed,
|
|
232
|
-
);
|
|
233
|
-
}
|
|
234
|
-
} else if (contentType.includes("text/event-stream")) {
|
|
235
|
-
responseSummary = summarizeSseBodyForLog(body_text);
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
const preview = to_inline_log_value(body_text, maxBodyPreviewChars);
|
|
239
|
-
const responseTextParts = [
|
|
240
|
-
format_log_field(
|
|
241
|
-
"agent",
|
|
242
|
-
to_inline_log_value(
|
|
243
|
-
`llm.response status=${response.status} ok=${response.ok} contentType=${contentType || "-"}`,
|
|
244
|
-
maxBodyPreviewChars,
|
|
245
|
-
),
|
|
246
|
-
),
|
|
247
|
-
];
|
|
248
|
-
if (preview) {
|
|
249
|
-
responseTextParts.push(format_log_field("response_body", preview));
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
return {
|
|
253
|
-
responseText: responseTextParts.join("\n\n"),
|
|
254
|
-
meta: {
|
|
255
|
-
kind: "llm_response",
|
|
256
|
-
status: response.status,
|
|
257
|
-
ok: response.ok,
|
|
258
|
-
...(contentType ? { contentType } : {}),
|
|
259
|
-
...(opts?.url ? { url: opts.url } : {}),
|
|
260
|
-
...(opts?.method ? { method: opts.method } : {}),
|
|
261
|
-
responseBodyLength: body_text.length,
|
|
262
|
-
...responseSummary,
|
|
263
|
-
},
|
|
264
|
-
};
|
|
265
|
-
}
|