happy2 0.0.12 → 0.0.13
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/package.json +2 -2
- package/packages/happy2-server/PLUGINS.md +99 -11
- package/packages/happy2-server/README.md +8 -7
- package/packages/happy2-server/dist/index.d.ts +2 -1
- package/packages/happy2-server/dist/index.d.ts.map +1 -1
- package/packages/happy2-server/dist/index.js +1 -0
- package/packages/happy2-server/dist/index.js.map +1 -1
- package/packages/happy2-server/dist/modules/agent/agentChatBind.d.ts +1 -0
- package/packages/happy2-server/dist/modules/agent/agentChatBind.d.ts.map +1 -1
- package/packages/happy2-server/dist/modules/agent/agentChatBind.js +4 -0
- package/packages/happy2-server/dist/modules/agent/agentChatBind.js.map +1 -1
- package/packages/happy2-server/dist/modules/agent/agentChatGetContext.d.ts.map +1 -1
- package/packages/happy2-server/dist/modules/agent/agentChatGetContext.js +3 -1
- package/packages/happy2-server/dist/modules/agent/agentChatGetContext.js.map +1 -1
- package/packages/happy2-server/dist/modules/agent/agentChatGetIdBySession.d.ts +7 -0
- package/packages/happy2-server/dist/modules/agent/agentChatGetIdBySession.d.ts.map +1 -0
- package/packages/happy2-server/dist/modules/agent/agentChatGetIdBySession.js +15 -0
- package/packages/happy2-server/dist/modules/agent/agentChatGetIdBySession.js.map +1 -0
- package/packages/happy2-server/dist/modules/agent/agentCreate.d.ts.map +1 -1
- package/packages/happy2-server/dist/modules/agent/agentCreate.js +1 -0
- package/packages/happy2-server/dist/modules/agent/agentCreate.js.map +1 -1
- package/packages/happy2-server/dist/modules/agent/agentEffortBindingList.d.ts +4 -2
- package/packages/happy2-server/dist/modules/agent/agentEffortBindingList.d.ts.map +1 -1
- package/packages/happy2-server/dist/modules/agent/agentEffortBindingList.js +8 -8
- package/packages/happy2-server/dist/modules/agent/agentEffortBindingList.js.map +1 -1
- package/packages/happy2-server/dist/modules/agent/agentEffortGetContext.d.ts +3 -3
- package/packages/happy2-server/dist/modules/agent/agentEffortGetContext.d.ts.map +1 -1
- package/packages/happy2-server/dist/modules/agent/agentEffortGetContext.js +4 -4
- package/packages/happy2-server/dist/modules/agent/agentEffortGetContext.js.map +1 -1
- package/packages/happy2-server/dist/modules/agent/agentEffortUpdate.d.ts +4 -4
- package/packages/happy2-server/dist/modules/agent/agentEffortUpdate.d.ts.map +1 -1
- package/packages/happy2-server/dist/modules/agent/agentEffortUpdate.js +57 -41
- package/packages/happy2-server/dist/modules/agent/agentEffortUpdate.js.map +1 -1
- package/packages/happy2-server/dist/modules/agent/agentImageCommitChange.d.ts +1 -1
- package/packages/happy2-server/dist/modules/agent/agentImageCommitChange.js +3 -3
- package/packages/happy2-server/dist/modules/agent/agentImageCommitChange.js.map +1 -1
- package/packages/happy2-server/dist/modules/agent/agentImageCreate.d.ts +1 -1
- package/packages/happy2-server/dist/modules/agent/agentImageCreate.js +3 -3
- package/packages/happy2-server/dist/modules/agent/agentImageCreate.js.map +1 -1
- package/packages/happy2-server/dist/modules/agent/agentImageGet.d.ts +1 -1
- package/packages/happy2-server/dist/modules/agent/agentImageGet.js +3 -3
- package/packages/happy2-server/dist/modules/agent/agentImageGet.js.map +1 -1
- package/packages/happy2-server/dist/modules/agent/agentImageGetChangeContext.d.ts +2 -1
- package/packages/happy2-server/dist/modules/agent/agentImageGetChangeContext.d.ts.map +1 -1
- package/packages/happy2-server/dist/modules/agent/agentImageGetChangeContext.js +11 -4
- package/packages/happy2-server/dist/modules/agent/agentImageGetChangeContext.js.map +1 -1
- package/packages/happy2-server/dist/modules/agent/agentImageList.d.ts +2 -2
- package/packages/happy2-server/dist/modules/agent/agentImageList.d.ts.map +1 -1
- package/packages/happy2-server/dist/modules/agent/agentImageList.js +8 -4
- package/packages/happy2-server/dist/modules/agent/agentImageList.js.map +1 -1
- package/packages/happy2-server/dist/modules/agent/agentImageRequestBuild.d.ts +1 -1
- package/packages/happy2-server/dist/modules/agent/agentImageRequestBuild.js +3 -3
- package/packages/happy2-server/dist/modules/agent/agentImageRequestBuild.js.map +1 -1
- package/packages/happy2-server/dist/modules/agent/agentImageSetDefault.d.ts +1 -1
- package/packages/happy2-server/dist/modules/agent/agentImageSetDefault.js +3 -3
- package/packages/happy2-server/dist/modules/agent/agentImageSetDefault.js.map +1 -1
- package/packages/happy2-server/dist/modules/agent/agentSecretAssignmentDelete.d.ts +1 -1
- package/packages/happy2-server/dist/modules/agent/agentSecretAssignmentDelete.js +3 -3
- package/packages/happy2-server/dist/modules/agent/agentSecretAssignmentDelete.js.map +1 -1
- package/packages/happy2-server/dist/modules/agent/agentSecretAssignmentList.d.ts +1 -1
- package/packages/happy2-server/dist/modules/agent/agentSecretAssignmentList.js +3 -3
- package/packages/happy2-server/dist/modules/agent/agentSecretAssignmentList.js.map +1 -1
- package/packages/happy2-server/dist/modules/agent/agentSecretAttachToAgent.d.ts +1 -1
- package/packages/happy2-server/dist/modules/agent/agentSecretAttachToAgent.js +3 -3
- package/packages/happy2-server/dist/modules/agent/agentSecretAttachToAgent.js.map +1 -1
- package/packages/happy2-server/dist/modules/agent/agentSecretAttachToChannel.d.ts +1 -1
- package/packages/happy2-server/dist/modules/agent/agentSecretAttachToChannel.js +3 -3
- package/packages/happy2-server/dist/modules/agent/agentSecretAttachToChannel.js.map +1 -1
- package/packages/happy2-server/dist/modules/agent/agentSecretAuthorizeManagement.d.ts +4 -3
- package/packages/happy2-server/dist/modules/agent/agentSecretAuthorizeManagement.d.ts.map +1 -1
- package/packages/happy2-server/dist/modules/agent/agentSecretAuthorizeManagement.js +5 -5
- package/packages/happy2-server/dist/modules/agent/agentSecretAuthorizeManagement.js.map +1 -1
- package/packages/happy2-server/dist/modules/agent/agentSecretDetachFromAgent.d.ts +1 -1
- package/packages/happy2-server/dist/modules/agent/agentSecretDetachFromAgent.js +3 -3
- package/packages/happy2-server/dist/modules/agent/agentSecretDetachFromAgent.js.map +1 -1
- package/packages/happy2-server/dist/modules/agent/agentSecretDetachFromChannel.d.ts +2 -2
- package/packages/happy2-server/dist/modules/agent/agentSecretDetachFromChannel.js +4 -4
- package/packages/happy2-server/dist/modules/agent/agentSecretDetachFromChannel.js.map +1 -1
- package/packages/happy2-server/dist/modules/agent/agentSecretRecordRegistration.d.ts +1 -1
- package/packages/happy2-server/dist/modules/agent/agentSecretRecordRegistration.js +3 -3
- package/packages/happy2-server/dist/modules/agent/agentSecretRecordRegistration.js.map +1 -1
- package/packages/happy2-server/dist/modules/agent/agentTurnStreamReply.d.ts +4 -0
- package/packages/happy2-server/dist/modules/agent/agentTurnStreamReply.d.ts.map +1 -1
- package/packages/happy2-server/dist/modules/agent/agentTurnStreamReply.js +207 -9
- package/packages/happy2-server/dist/modules/agent/agentTurnStreamReply.js.map +1 -1
- package/packages/happy2-server/dist/modules/agent/agentTurnTraceGet.d.ts +8 -0
- package/packages/happy2-server/dist/modules/agent/agentTurnTraceGet.d.ts.map +1 -0
- package/packages/happy2-server/dist/modules/agent/agentTurnTraceGet.js +86 -0
- package/packages/happy2-server/dist/modules/agent/agentTurnTraceGet.js.map +1 -0
- package/packages/happy2-server/dist/modules/agent/agentTurnTraceStart.d.ts +19 -0
- package/packages/happy2-server/dist/modules/agent/agentTurnTraceStart.d.ts.map +1 -0
- package/packages/happy2-server/dist/modules/agent/agentTurnTraceStart.js +87 -0
- package/packages/happy2-server/dist/modules/agent/agentTurnTraceStart.js.map +1 -0
- package/packages/happy2-server/dist/modules/agent/impl/agentChatContext.d.ts +2 -1
- package/packages/happy2-server/dist/modules/agent/impl/agentChatContext.d.ts.map +1 -1
- package/packages/happy2-server/dist/modules/agent/impl/agentEffortContext.d.ts +4 -1
- package/packages/happy2-server/dist/modules/agent/impl/agentEffortContext.d.ts.map +1 -1
- package/packages/happy2-server/dist/modules/agent/impl/agentEffortContextDb.d.ts +3 -3
- package/packages/happy2-server/dist/modules/agent/impl/agentEffortContextDb.d.ts.map +1 -1
- package/packages/happy2-server/dist/modules/agent/impl/agentEffortContextDb.js +26 -40
- package/packages/happy2-server/dist/modules/agent/impl/agentEffortContextDb.js.map +1 -1
- package/packages/happy2-server/dist/modules/agent/impl/finishAgentTurn.d.ts.map +1 -1
- package/packages/happy2-server/dist/modules/agent/impl/finishAgentTurn.js +63 -2
- package/packages/happy2-server/dist/modules/agent/impl/finishAgentTurn.js.map +1 -1
- package/packages/happy2-server/dist/modules/agent/types.d.ts +53 -0
- package/packages/happy2-server/dist/modules/agent/types.d.ts.map +1 -1
- package/packages/happy2-server/dist/modules/agents/daemon.d.ts +31 -2
- package/packages/happy2-server/dist/modules/agents/daemon.d.ts.map +1 -1
- package/packages/happy2-server/dist/modules/agents/daemon.js +12 -2
- package/packages/happy2-server/dist/modules/agents/daemon.js.map +1 -1
- package/packages/happy2-server/dist/modules/agents/service.d.ts +13 -6
- package/packages/happy2-server/dist/modules/agents/service.d.ts.map +1 -1
- package/packages/happy2-server/dist/modules/agents/service.js +497 -49
- package/packages/happy2-server/dist/modules/agents/service.js.map +1 -1
- package/packages/happy2-server/dist/modules/auth/developmentTokenCreate.d.ts +12 -0
- package/packages/happy2-server/dist/modules/auth/developmentTokenCreate.d.ts.map +1 -0
- package/packages/happy2-server/dist/modules/auth/developmentTokenCreate.js +27 -0
- package/packages/happy2-server/dist/modules/auth/developmentTokenCreate.js.map +1 -0
- package/packages/happy2-server/dist/modules/auth/developmentTokenFindActive.d.ts +8 -0
- package/packages/happy2-server/dist/modules/auth/developmentTokenFindActive.d.ts.map +1 -0
- package/packages/happy2-server/dist/modules/auth/developmentTokenFindActive.js +22 -0
- package/packages/happy2-server/dist/modules/auth/developmentTokenFindActive.js.map +1 -0
- package/packages/happy2-server/dist/modules/auth/methods.d.ts +1 -0
- package/packages/happy2-server/dist/modules/auth/methods.d.ts.map +1 -1
- package/packages/happy2-server/dist/modules/auth/methods.js +10 -6
- package/packages/happy2-server/dist/modules/auth/methods.js.map +1 -1
- package/packages/happy2-server/dist/modules/auth/service.d.ts +2 -0
- package/packages/happy2-server/dist/modules/auth/service.d.ts.map +1 -1
- package/packages/happy2-server/dist/modules/auth/service.js +26 -0
- package/packages/happy2-server/dist/modules/auth/service.js.map +1 -1
- package/packages/happy2-server/dist/modules/auth/tokens.d.ts +6 -0
- package/packages/happy2-server/dist/modules/auth/tokens.d.ts.map +1 -1
- package/packages/happy2-server/dist/modules/auth/tokens.js +26 -0
- package/packages/happy2-server/dist/modules/auth/tokens.js.map +1 -1
- package/packages/happy2-server/dist/modules/auth/tokens.test.js +20 -0
- package/packages/happy2-server/dist/modules/auth/tokens.test.js.map +1 -1
- package/packages/happy2-server/dist/modules/chat/asAgentTurnTrace.d.ts +17 -0
- package/packages/happy2-server/dist/modules/chat/asAgentTurnTrace.d.ts.map +1 -0
- package/packages/happy2-server/dist/modules/chat/asAgentTurnTrace.js +98 -0
- package/packages/happy2-server/dist/modules/chat/asAgentTurnTrace.js.map +1 -0
- package/packages/happy2-server/dist/modules/chat/asServiceMessage.d.ts.map +1 -1
- package/packages/happy2-server/dist/modules/chat/asServiceMessage.js +13 -5
- package/packages/happy2-server/dist/modules/chat/asServiceMessage.js.map +1 -1
- package/packages/happy2-server/dist/modules/chat/chatUpdateMetadata.d.ts +20 -0
- package/packages/happy2-server/dist/modules/chat/chatUpdateMetadata.d.ts.map +1 -0
- package/packages/happy2-server/dist/modules/chat/chatUpdateMetadata.js +38 -0
- package/packages/happy2-server/dist/modules/chat/chatUpdateMetadata.js.map +1 -0
- package/packages/happy2-server/dist/modules/chat/types.d.ts +6 -0
- package/packages/happy2-server/dist/modules/chat/types.d.ts.map +1 -1
- package/packages/happy2-server/dist/modules/chat/types.js.map +1 -1
- package/packages/happy2-server/dist/modules/chat/userRequireActiveHuman.d.ts +7 -0
- package/packages/happy2-server/dist/modules/chat/userRequireActiveHuman.d.ts.map +1 -0
- package/packages/happy2-server/dist/modules/chat/userRequireActiveHuman.js +19 -0
- package/packages/happy2-server/dist/modules/chat/userRequireActiveHuman.js.map +1 -0
- package/packages/happy2-server/dist/modules/chat/userRequireServerAdmin.d.ts +2 -2
- package/packages/happy2-server/dist/modules/chat/userRequireServerAdmin.d.ts.map +1 -1
- package/packages/happy2-server/dist/modules/chat/userRequireServerAdmin.js +8 -5
- package/packages/happy2-server/dist/modules/chat/userRequireServerAdmin.js.map +1 -1
- package/packages/happy2-server/dist/modules/config/defaults.d.ts.map +1 -1
- package/packages/happy2-server/dist/modules/config/defaults.js +1 -0
- package/packages/happy2-server/dist/modules/config/defaults.js.map +1 -1
- package/packages/happy2-server/dist/modules/config/defaults.test.js +1 -0
- package/packages/happy2-server/dist/modules/config/defaults.test.js.map +1 -1
- package/packages/happy2-server/dist/modules/config/loader.d.ts.map +1 -1
- package/packages/happy2-server/dist/modules/config/loader.js +4 -0
- package/packages/happy2-server/dist/modules/config/loader.js.map +1 -1
- package/packages/happy2-server/dist/modules/config/loader.test.js +12 -0
- package/packages/happy2-server/dist/modules/config/loader.test.js.map +1 -1
- package/packages/happy2-server/dist/modules/config/type.d.ts +3 -0
- package/packages/happy2-server/dist/modules/config/type.d.ts.map +1 -1
- package/packages/happy2-server/dist/modules/message/messageGetProjection.d.ts.map +1 -1
- package/packages/happy2-server/dist/modules/message/messageGetProjection.js +28 -0
- package/packages/happy2-server/dist/modules/message/messageGetProjection.js.map +1 -1
- package/packages/happy2-server/dist/modules/permission/impl/permissionEffectiveDb.d.ts +4 -0
- package/packages/happy2-server/dist/modules/permission/impl/permissionEffectiveDb.d.ts.map +1 -0
- package/packages/happy2-server/dist/modules/permission/impl/permissionEffectiveDb.js +39 -0
- package/packages/happy2-server/dist/modules/permission/impl/permissionEffectiveDb.js.map +1 -0
- package/packages/happy2-server/dist/modules/permission/impl/permissionMutationRecord.d.ts +10 -0
- package/packages/happy2-server/dist/modules/permission/impl/permissionMutationRecord.d.ts.map +1 -0
- package/packages/happy2-server/dist/modules/permission/impl/permissionMutationRecord.js +31 -0
- package/packages/happy2-server/dist/modules/permission/impl/permissionMutationRecord.js.map +1 -0
- package/packages/happy2-server/dist/modules/permission/permissionGetEffective.d.ts +8 -0
- package/packages/happy2-server/dist/modules/permission/permissionGetEffective.d.ts.map +1 -0
- package/packages/happy2-server/dist/modules/permission/permissionGetEffective.js +13 -0
- package/packages/happy2-server/dist/modules/permission/permissionGetEffective.js.map +1 -0
- package/packages/happy2-server/dist/modules/permission/roleCreate.d.ts +16 -0
- package/packages/happy2-server/dist/modules/permission/roleCreate.d.ts.map +1 -0
- package/packages/happy2-server/dist/modules/permission/roleCreate.js +70 -0
- package/packages/happy2-server/dist/modules/permission/roleCreate.js.map +1 -0
- package/packages/happy2-server/dist/modules/permission/roleDelete.d.ts +11 -0
- package/packages/happy2-server/dist/modules/permission/roleDelete.d.ts.map +1 -0
- package/packages/happy2-server/dist/modules/permission/roleDelete.js +41 -0
- package/packages/happy2-server/dist/modules/permission/roleDelete.js.map +1 -0
- package/packages/happy2-server/dist/modules/permission/roleList.d.ts +8 -0
- package/packages/happy2-server/dist/modules/permission/roleList.d.ts.map +1 -0
- package/packages/happy2-server/dist/modules/permission/roleList.js +36 -0
- package/packages/happy2-server/dist/modules/permission/roleList.js.map +1 -0
- package/packages/happy2-server/dist/modules/permission/roleUpdate.d.ts +14 -0
- package/packages/happy2-server/dist/modules/permission/roleUpdate.d.ts.map +1 -0
- package/packages/happy2-server/dist/modules/permission/roleUpdate.js +78 -0
- package/packages/happy2-server/dist/modules/permission/roleUpdate.js.map +1 -0
- package/packages/happy2-server/dist/modules/permission/types.d.ts +24 -0
- package/packages/happy2-server/dist/modules/permission/types.d.ts.map +1 -0
- package/packages/happy2-server/dist/modules/permission/types.js +10 -0
- package/packages/happy2-server/dist/modules/permission/types.js.map +1 -0
- package/packages/happy2-server/dist/modules/permission/userPermissionGet.d.ts +16 -0
- package/packages/happy2-server/dist/modules/permission/userPermissionGet.d.ts.map +1 -0
- package/packages/happy2-server/dist/modules/permission/userPermissionGet.js +33 -0
- package/packages/happy2-server/dist/modules/permission/userPermissionGet.js.map +1 -0
- package/packages/happy2-server/dist/modules/permission/userPermissionUpdate.d.ts +12 -0
- package/packages/happy2-server/dist/modules/permission/userPermissionUpdate.d.ts.map +1 -0
- package/packages/happy2-server/dist/modules/permission/userPermissionUpdate.js +44 -0
- package/packages/happy2-server/dist/modules/permission/userPermissionUpdate.js.map +1 -0
- package/packages/happy2-server/dist/modules/permission/userRequireAnyPermission.d.ts +8 -0
- package/packages/happy2-server/dist/modules/permission/userRequireAnyPermission.d.ts.map +1 -0
- package/packages/happy2-server/dist/modules/permission/userRequireAnyPermission.js +12 -0
- package/packages/happy2-server/dist/modules/permission/userRequireAnyPermission.js.map +1 -0
- package/packages/happy2-server/dist/modules/permission/userRequirePermission.d.ts +8 -0
- package/packages/happy2-server/dist/modules/permission/userRequirePermission.d.ts.map +1 -0
- package/packages/happy2-server/dist/modules/permission/userRequirePermission.js +12 -0
- package/packages/happy2-server/dist/modules/permission/userRequirePermission.js.map +1 -0
- package/packages/happy2-server/dist/modules/permission/userRoleAssign.d.ts +12 -0
- package/packages/happy2-server/dist/modules/permission/userRoleAssign.d.ts.map +1 -0
- package/packages/happy2-server/dist/modules/permission/userRoleAssign.js +46 -0
- package/packages/happy2-server/dist/modules/permission/userRoleAssign.js.map +1 -0
- package/packages/happy2-server/dist/modules/permission/userRoleUnassign.d.ts +12 -0
- package/packages/happy2-server/dist/modules/permission/userRoleUnassign.d.ts.map +1 -0
- package/packages/happy2-server/dist/modules/permission/userRoleUnassign.js +53 -0
- package/packages/happy2-server/dist/modules/permission/userRoleUnassign.js.map +1 -0
- package/packages/happy2-server/dist/modules/plugin/archive.d.ts +7 -0
- package/packages/happy2-server/dist/modules/plugin/archive.d.ts.map +1 -0
- package/packages/happy2-server/dist/modules/plugin/archive.js +222 -0
- package/packages/happy2-server/dist/modules/plugin/archive.js.map +1 -0
- package/packages/happy2-server/dist/modules/plugin/catalog.d.ts +5 -1
- package/packages/happy2-server/dist/modules/plugin/catalog.d.ts.map +1 -1
- package/packages/happy2-server/dist/modules/plugin/catalog.js +33 -14
- package/packages/happy2-server/dist/modules/plugin/catalog.js.map +1 -1
- package/packages/happy2-server/dist/modules/plugin/catalog.test.js +6 -2
- package/packages/happy2-server/dist/modules/plugin/catalog.test.js.map +1 -1
- package/packages/happy2-server/dist/modules/plugin/httpBridge.d.ts +1 -0
- package/packages/happy2-server/dist/modules/plugin/httpBridge.d.ts.map +1 -1
- package/packages/happy2-server/dist/modules/plugin/httpBridge.js +7 -0
- package/packages/happy2-server/dist/modules/plugin/httpBridge.js.map +1 -1
- package/packages/happy2-server/dist/modules/plugin/impl/asInstallation.d.ts.map +1 -1
- package/packages/happy2-server/dist/modules/plugin/impl/asInstallation.js +3 -2
- package/packages/happy2-server/dist/modules/plugin/impl/asInstallation.js.map +1 -1
- package/packages/happy2-server/dist/modules/plugin/impl/asPlugin.d.ts.map +1 -1
- package/packages/happy2-server/dist/modules/plugin/impl/asPlugin.js +3 -2
- package/packages/happy2-server/dist/modules/plugin/impl/asPlugin.js.map +1 -1
- package/packages/happy2-server/dist/modules/plugin/impl/installedManifest.js +1 -1
- package/packages/happy2-server/dist/modules/plugin/impl/installedManifest.js.map +1 -1
- package/packages/happy2-server/dist/modules/plugin/impl/pluginSkillSource.d.ts +11 -0
- package/packages/happy2-server/dist/modules/plugin/impl/pluginSkillSource.d.ts.map +1 -0
- package/packages/happy2-server/dist/modules/plugin/impl/pluginSkillSource.js +2 -0
- package/packages/happy2-server/dist/modules/plugin/impl/pluginSkillSource.js.map +1 -0
- package/packages/happy2-server/dist/modules/plugin/packageStore.d.ts +13 -0
- package/packages/happy2-server/dist/modules/plugin/packageStore.d.ts.map +1 -1
- package/packages/happy2-server/dist/modules/plugin/packageStore.js +122 -14
- package/packages/happy2-server/dist/modules/plugin/packageStore.js.map +1 -1
- package/packages/happy2-server/dist/modules/plugin/pluginAuthorizeManagement.d.ts +1 -1
- package/packages/happy2-server/dist/modules/plugin/pluginAuthorizeManagement.js +3 -3
- package/packages/happy2-server/dist/modules/plugin/pluginAuthorizeManagement.js.map +1 -1
- package/packages/happy2-server/dist/modules/plugin/pluginFindBySource.d.ts +3 -1
- package/packages/happy2-server/dist/modules/plugin/pluginFindBySource.d.ts.map +1 -1
- package/packages/happy2-server/dist/modules/plugin/pluginFindBySource.js +1 -1
- package/packages/happy2-server/dist/modules/plugin/pluginFindBySource.js.map +1 -1
- package/packages/happy2-server/dist/modules/plugin/pluginGetImage.d.ts +1 -1
- package/packages/happy2-server/dist/modules/plugin/pluginGetImage.js +3 -3
- package/packages/happy2-server/dist/modules/plugin/pluginGetImage.js.map +1 -1
- package/packages/happy2-server/dist/modules/plugin/pluginGetSource.d.ts +13 -0
- package/packages/happy2-server/dist/modules/plugin/pluginGetSource.d.ts.map +1 -0
- package/packages/happy2-server/dist/modules/plugin/pluginGetSource.js +37 -0
- package/packages/happy2-server/dist/modules/plugin/pluginGetSource.js.map +1 -0
- package/packages/happy2-server/dist/modules/plugin/pluginInstall.d.ts.map +1 -1
- package/packages/happy2-server/dist/modules/plugin/pluginInstall.js +18 -4
- package/packages/happy2-server/dist/modules/plugin/pluginInstall.js.map +1 -1
- package/packages/happy2-server/dist/modules/plugin/pluginInstallationList.d.ts +1 -1
- package/packages/happy2-server/dist/modules/plugin/pluginInstallationList.js +3 -3
- package/packages/happy2-server/dist/modules/plugin/pluginInstallationList.js.map +1 -1
- package/packages/happy2-server/dist/modules/plugin/pluginList.d.ts +1 -1
- package/packages/happy2-server/dist/modules/plugin/pluginList.js +3 -3
- package/packages/happy2-server/dist/modules/plugin/pluginList.js.map +1 -1
- package/packages/happy2-server/dist/modules/plugin/pluginSkillsListInstalled.d.ts +8 -0
- package/packages/happy2-server/dist/modules/plugin/pluginSkillsListInstalled.d.ts.map +1 -0
- package/packages/happy2-server/dist/modules/plugin/pluginSkillsListInstalled.js +24 -0
- package/packages/happy2-server/dist/modules/plugin/pluginSkillsListInstalled.js.map +1 -0
- package/packages/happy2-server/dist/modules/plugin/pluginSkillsListReady.d.ts +8 -0
- package/packages/happy2-server/dist/modules/plugin/pluginSkillsListReady.d.ts.map +1 -0
- package/packages/happy2-server/dist/modules/plugin/pluginSkillsListReady.js +25 -0
- package/packages/happy2-server/dist/modules/plugin/pluginSkillsListReady.js.map +1 -0
- package/packages/happy2-server/dist/modules/plugin/pluginUninstall.d.ts +13 -0
- package/packages/happy2-server/dist/modules/plugin/pluginUninstall.d.ts.map +1 -0
- package/packages/happy2-server/dist/modules/plugin/pluginUninstall.js +63 -0
- package/packages/happy2-server/dist/modules/plugin/pluginUninstall.js.map +1 -0
- package/packages/happy2-server/dist/modules/plugin/runtime.d.ts +1 -0
- package/packages/happy2-server/dist/modules/plugin/runtime.d.ts.map +1 -1
- package/packages/happy2-server/dist/modules/plugin/runtime.js +1 -0
- package/packages/happy2-server/dist/modules/plugin/runtime.js.map +1 -1
- package/packages/happy2-server/dist/modules/plugin/service.d.ts +54 -3
- package/packages/happy2-server/dist/modules/plugin/service.d.ts.map +1 -1
- package/packages/happy2-server/dist/modules/plugin/service.js +339 -6
- package/packages/happy2-server/dist/modules/plugin/service.js.map +1 -1
- package/packages/happy2-server/dist/modules/plugin/source.d.ts +35 -0
- package/packages/happy2-server/dist/modules/plugin/source.d.ts.map +1 -0
- package/packages/happy2-server/dist/modules/plugin/source.js +189 -0
- package/packages/happy2-server/dist/modules/plugin/source.js.map +1 -0
- package/packages/happy2-server/dist/modules/plugin/types.d.ts +48 -9
- package/packages/happy2-server/dist/modules/plugin/types.d.ts.map +1 -1
- package/packages/happy2-server/dist/modules/plugin/types.js.map +1 -1
- package/packages/happy2-server/dist/modules/realtime/events.d.ts +3 -0
- package/packages/happy2-server/dist/modules/realtime/events.d.ts.map +1 -1
- package/packages/happy2-server/dist/modules/realtime/events.js +37 -5
- package/packages/happy2-server/dist/modules/realtime/events.js.map +1 -1
- package/packages/happy2-server/dist/modules/realtime/local.test.js +2 -0
- package/packages/happy2-server/dist/modules/realtime/local.test.js.map +1 -1
- package/packages/happy2-server/dist/modules/sandbox/localOciSandboxProvider.d.ts.map +1 -1
- package/packages/happy2-server/dist/modules/sandbox/localOciSandboxProvider.js +4 -2
- package/packages/happy2-server/dist/modules/sandbox/localOciSandboxProvider.js.map +1 -1
- package/packages/happy2-server/dist/modules/sandbox/localOciSandboxProvider.test.js +4 -1
- package/packages/happy2-server/dist/modules/sandbox/localOciSandboxProvider.test.js.map +1 -1
- package/packages/happy2-server/dist/modules/sandbox/types.d.ts +1 -0
- package/packages/happy2-server/dist/modules/sandbox/types.d.ts.map +1 -1
- package/packages/happy2-server/dist/modules/schema.d.ts +1949 -331
- package/packages/happy2-server/dist/modules/schema.d.ts.map +1 -1
- package/packages/happy2-server/dist/modules/schema.js +105 -0
- package/packages/happy2-server/dist/modules/schema.js.map +1 -1
- package/packages/happy2-server/dist/modules/sync/syncGetDifference.d.ts.map +1 -1
- package/packages/happy2-server/dist/modules/sync/syncGetDifference.js +2 -0
- package/packages/happy2-server/dist/modules/sync/syncGetDifference.js.map +1 -1
- package/packages/happy2-server/dist/modules/user/userAdministrationList.js +2 -2
- package/packages/happy2-server/dist/modules/user/userAdministrationList.js.map +1 -1
- package/packages/happy2-server/dist/modules/user/userAdministrationUpdate.d.ts.map +1 -1
- package/packages/happy2-server/dist/modules/user/userAdministrationUpdate.js +49 -6
- package/packages/happy2-server/dist/modules/user/userAdministrationUpdate.js.map +1 -1
- package/packages/happy2-server/dist/modules/user/userCreateProfile.d.ts.map +1 -1
- package/packages/happy2-server/dist/modules/user/userCreateProfile.js +17 -2
- package/packages/happy2-server/dist/modules/user/userCreateProfile.js.map +1 -1
- package/packages/happy2-server/dist/routes/agents.d.ts.map +1 -1
- package/packages/happy2-server/dist/routes/agents.js +4 -2
- package/packages/happy2-server/dist/routes/agents.js.map +1 -1
- package/packages/happy2-server/dist/routes/auth.d.ts.map +1 -1
- package/packages/happy2-server/dist/routes/auth.js +12 -0
- package/packages/happy2-server/dist/routes/auth.js.map +1 -1
- package/packages/happy2-server/dist/routes/collaboration.d.ts.map +1 -1
- package/packages/happy2-server/dist/routes/collaboration.js +7 -0
- package/packages/happy2-server/dist/routes/collaboration.js.map +1 -1
- package/packages/happy2-server/dist/routes/files.d.ts.map +1 -1
- package/packages/happy2-server/dist/routes/files.js +2 -0
- package/packages/happy2-server/dist/routes/files.js.map +1 -1
- package/packages/happy2-server/dist/routes/permissions.d.ts +6 -0
- package/packages/happy2-server/dist/routes/permissions.d.ts.map +1 -0
- package/packages/happy2-server/dist/routes/permissions.js +207 -0
- package/packages/happy2-server/dist/routes/permissions.js.map +1 -0
- package/packages/happy2-server/dist/routes/pluginHost.d.ts.map +1 -1
- package/packages/happy2-server/dist/routes/pluginHost.js +70 -1
- package/packages/happy2-server/dist/routes/pluginHost.js.map +1 -1
- package/packages/happy2-server/dist/routes/plugins.d.ts.map +1 -1
- package/packages/happy2-server/dist/routes/plugins.js +147 -5
- package/packages/happy2-server/dist/routes/plugins.js.map +1 -1
- package/packages/happy2-server/dist/server.d.ts +2 -0
- package/packages/happy2-server/dist/server.d.ts.map +1 -1
- package/packages/happy2-server/dist/server.js +4 -1
- package/packages/happy2-server/dist/server.js.map +1 -1
- package/packages/happy2-server/dist/web/assets/index-BaPUPGPe.css +2 -0
- package/packages/happy2-server/dist/web/assets/index-BnhFxR3U.js +39 -0
- package/packages/happy2-server/dist/web/index.html +2 -2
- package/packages/happy2-server/drizzle/0023_roles_and_permissions.sql +82 -0
- package/packages/happy2-server/drizzle/0024_session_bound_dev_tokens.sql +11 -0
- package/packages/happy2-server/drizzle/0025_plugin_skills.sql +8 -0
- package/packages/happy2-server/drizzle/0026_agent_turn_traces.sql +35 -0
- package/packages/happy2-server/drizzle/0027_chat_agent_effort.sql +9 -0
- package/packages/happy2-server/drizzle/meta/_journal.json +35 -0
- package/packages/happy2-server/happy2.example.toml +6 -0
- package/packages/happy2-server/plugins/README.md +3 -1
- package/packages/happy2-server/plugins/chat-management/container/Dockerfile +6 -0
- package/packages/happy2-server/plugins/chat-management/plugin.json +17 -0
- package/packages/happy2-server/plugins/chat-management/plugin.png +0 -0
- package/packages/happy2-server/plugins/chat-management/server.mjs +113 -0
- package/packages/happy2-server/dist/web/assets/index-9SGCQLg7.js +0 -46
- package/packages/happy2-server/dist/web/assets/index-DWXBQDJB.css +0 -2
|
@@ -11,6 +11,7 @@ import { agentTurnGetRunning } from "../agent/agentTurnGetRunning.js";
|
|
|
11
11
|
import { agentTurnFail } from "../agent/agentTurnFail.js";
|
|
12
12
|
import { agentTurnComplete } from "../agent/agentTurnComplete.js";
|
|
13
13
|
import { agentTurnCheckpoint } from "../agent/agentTurnCheckpoint.js";
|
|
14
|
+
import { agentTurnTraceStart } from "../agent/agentTurnTraceStart.js";
|
|
14
15
|
import { agentSecretRecordRegistration } from "../agent/agentSecretRecordRegistration.js";
|
|
15
16
|
import { agentSecretDetachFromChannel } from "../agent/agentSecretDetachFromChannel.js";
|
|
16
17
|
import { agentSecretDetachFromAgent } from "../agent/agentSecretDetachFromAgent.js";
|
|
@@ -55,6 +56,7 @@ import { CollaborationError, } from "../chat/types.js";
|
|
|
55
56
|
import { realtimeTopics } from "../realtime/index.js";
|
|
56
57
|
import { isRetryableRigError, RigDaemonClient, } from "./daemon.js";
|
|
57
58
|
import { BUILTIN_AGENT_IMAGES } from "./builtin-images.js";
|
|
59
|
+
import { agentChatGetIdBySession } from "../agent/agentChatGetIdBySession.js";
|
|
58
60
|
import { pluginFunctionResultAcquire } from "../plugin/pluginFunctionResultAcquire.js";
|
|
59
61
|
import { pluginFunctionResultComplete } from "../plugin/pluginFunctionResultComplete.js";
|
|
60
62
|
import { setupBaseImageCompleteBuild, setupBaseImageFailBuild, setupBaseImageGetStatus, setupBaseImageRetryBuild, setupBaseImageSelect, } from "../setup/index.js";
|
|
@@ -75,6 +77,13 @@ const MAX_BUILD_LOG_LINE_CHARACTERS = 1_000;
|
|
|
75
77
|
const MAX_CONCURRENT_IMAGE_BUILDS = 1;
|
|
76
78
|
const AGENT_REPLY_FLUSH_INTERVAL_MS = 50;
|
|
77
79
|
const AGENT_REPLY_FLUSH_CHARACTERS = 1_024;
|
|
80
|
+
const MAX_TRACE_DETAIL_CHARACTERS = 64 * 1_024;
|
|
81
|
+
const MAX_TRACE_SUMMARY_CHARACTERS = 500;
|
|
82
|
+
const MAX_TRACE_COLLECTION_ITEMS = 32;
|
|
83
|
+
const MAX_TRACE_ID_CHARACTERS = 128;
|
|
84
|
+
const MAX_ACTIVITY_TEXT_CHARACTERS = 240;
|
|
85
|
+
const MAX_PENDING_TRACE_UPDATES = 512;
|
|
86
|
+
const MAX_TRACKED_TOOL_NAMES = 512;
|
|
78
87
|
const AGENT_CONTAINER_SECURITY = {
|
|
79
88
|
init: true,
|
|
80
89
|
readonlyRootFilesystem: true,
|
|
@@ -104,7 +113,7 @@ export class AgentService {
|
|
|
104
113
|
daemon;
|
|
105
114
|
sandboxRuntime;
|
|
106
115
|
defaultCwd;
|
|
107
|
-
|
|
116
|
+
pluginCapabilities;
|
|
108
117
|
onError;
|
|
109
118
|
workerId = createId();
|
|
110
119
|
bindingCreations = new Map();
|
|
@@ -122,13 +131,13 @@ export class AgentService {
|
|
|
122
131
|
shutdown = new AbortController();
|
|
123
132
|
queueTask;
|
|
124
133
|
stopping = false;
|
|
125
|
-
constructor(executor, pubsub, daemon, sandboxRuntime, defaultCwd,
|
|
134
|
+
constructor(executor, pubsub, daemon, sandboxRuntime, defaultCwd, pluginCapabilities, onError = () => undefined) {
|
|
126
135
|
this.executor = executor;
|
|
127
136
|
this.pubsub = pubsub;
|
|
128
137
|
this.daemon = daemon;
|
|
129
138
|
this.sandboxRuntime = sandboxRuntime;
|
|
130
139
|
this.defaultCwd = defaultCwd;
|
|
131
|
-
this.
|
|
140
|
+
this.pluginCapabilities = pluginCapabilities;
|
|
132
141
|
this.onError = onError;
|
|
133
142
|
}
|
|
134
143
|
async createAgent(input) {
|
|
@@ -247,25 +256,24 @@ export class AgentService {
|
|
|
247
256
|
this.startDrain(chatId);
|
|
248
257
|
}
|
|
249
258
|
async getAgentEffort(input) {
|
|
250
|
-
const context = await agentEffortGetContext(this.executor, input.actorUserId, input.agentUserId);
|
|
259
|
+
const context = await agentEffortGetContext(this.executor, input.actorUserId, input.chatId, input.agentUserId);
|
|
251
260
|
return this.agentEffortConfiguration(context);
|
|
252
261
|
}
|
|
253
262
|
async changeAgentEffort(input) {
|
|
254
|
-
return this.serializeAgentConfiguration(input.agentUserId
|
|
255
|
-
const context = await agentEffortGetContext(this.executor, input.actorUserId, input.
|
|
263
|
+
return this.serializeAgentConfiguration(`${input.agentUserId}:${input.chatId}`, async () => {
|
|
264
|
+
const context = await agentEffortGetContext(this.executor, input.actorUserId, input.chatId, input.agentUserId);
|
|
256
265
|
const configuration = await this.agentEffortConfiguration(context);
|
|
257
266
|
if (!configuration.options.includes(input.effort))
|
|
258
267
|
throw new CollaborationError("invalid", `Effort must be one of: ${configuration.options.join(", ")}`);
|
|
259
268
|
const result = await agentEffortUpdate(this.executor, input);
|
|
260
269
|
try {
|
|
261
|
-
await
|
|
270
|
+
await this.reconcileSessionEffort(context.sessionId, input.effort);
|
|
262
271
|
}
|
|
263
272
|
finally {
|
|
264
273
|
if (result.hint)
|
|
265
274
|
await this.publishAgentHint(result.hint);
|
|
266
275
|
}
|
|
267
276
|
return {
|
|
268
|
-
agent: result.user,
|
|
269
277
|
agentUserId: input.agentUserId,
|
|
270
278
|
effort: input.effort,
|
|
271
279
|
options: configuration.options,
|
|
@@ -368,7 +376,7 @@ export class AgentService {
|
|
|
368
376
|
workspaceDirectory: binding.cwd,
|
|
369
377
|
}, this.shutdown.signal);
|
|
370
378
|
try {
|
|
371
|
-
const session = await this.daemon.createSession(binding.cwd, containerName, context.user.agentEffort, this.shutdown.signal);
|
|
379
|
+
const session = await this.daemon.createSession(binding.cwd, containerName, binding.effort ?? context.user.agentEffort, this.shutdown.signal);
|
|
372
380
|
replacements.push({
|
|
373
381
|
chatId: binding.chatId,
|
|
374
382
|
containerName,
|
|
@@ -435,7 +443,7 @@ export class AgentService {
|
|
|
435
443
|
return this.serializeAgentSecret(input.id, () => this.createAgentSecretMutation(input));
|
|
436
444
|
}
|
|
437
445
|
async createAgentSecretMutation(input) {
|
|
438
|
-
await agentSecretAuthorizeManagement(this.executor, input.actorUserId);
|
|
446
|
+
await agentSecretAuthorizeManagement(this.executor, input.actorUserId, "manageSecrets");
|
|
439
447
|
const secret = await this.daemon.registerSecret({
|
|
440
448
|
id: input.id,
|
|
441
449
|
description: input.description,
|
|
@@ -461,7 +469,7 @@ export class AgentService {
|
|
|
461
469
|
return this.serializeAgentSecret(input.secretId, () => this.deleteAgentSecretMutation(input));
|
|
462
470
|
}
|
|
463
471
|
async deleteAgentSecretMutation(input) {
|
|
464
|
-
await agentSecretAuthorizeManagement(this.executor, input.actorUserId);
|
|
472
|
+
await agentSecretAuthorizeManagement(this.executor, input.actorUserId, "manageSecrets");
|
|
465
473
|
const sync = await agentSecretAssignmentDelete(this.executor, input);
|
|
466
474
|
let removed;
|
|
467
475
|
try {
|
|
@@ -588,8 +596,9 @@ export class AgentService {
|
|
|
588
596
|
if (!context)
|
|
589
597
|
return undefined;
|
|
590
598
|
if (context.binding) {
|
|
591
|
-
|
|
592
|
-
|
|
599
|
+
const effort = context.binding.effort ?? context.agentDefaultEffort;
|
|
600
|
+
if (effort)
|
|
601
|
+
await this.reconcileSessionEffort(context.binding.sessionId, effort);
|
|
593
602
|
await this.reconcileSecretBindings({
|
|
594
603
|
agentUserId: context.agentUserId,
|
|
595
604
|
chatId,
|
|
@@ -605,8 +614,9 @@ export class AgentService {
|
|
|
605
614
|
if (!latest)
|
|
606
615
|
throw new CollaborationError("not_found", "Agent conversation was not found");
|
|
607
616
|
if (latest.binding) {
|
|
608
|
-
|
|
609
|
-
|
|
617
|
+
const effort = latest.binding.effort ?? latest.agentDefaultEffort;
|
|
618
|
+
if (effort)
|
|
619
|
+
await this.reconcileSessionEffort(latest.binding.sessionId, effort);
|
|
610
620
|
return latest.binding;
|
|
611
621
|
}
|
|
612
622
|
const sandbox = sandboxDirectories(this.defaultCwd, latest.agentUserId, latest.sandboxScope.kind, latest.sandboxScope.id, latest.sandboxScope.conversationId);
|
|
@@ -632,13 +642,14 @@ export class AgentService {
|
|
|
632
642
|
workspaceDirectory: sandbox.workspace,
|
|
633
643
|
}, this.shutdown.signal);
|
|
634
644
|
try {
|
|
635
|
-
const session = await this.daemon.createSession(sandbox.workspace, containerName, latest.
|
|
645
|
+
const session = await this.daemon.createSession(sandbox.workspace, containerName, latest.agentDefaultEffort, this.shutdown.signal);
|
|
636
646
|
const binding = await agentChatBind(this.executor, {
|
|
637
647
|
actorUserId,
|
|
638
648
|
agentUserId: latest.agentUserId,
|
|
639
649
|
chatId,
|
|
640
650
|
containerName,
|
|
641
651
|
cwd: sandbox.workspace,
|
|
652
|
+
effort: session.effort,
|
|
642
653
|
imageId: latest.image.id,
|
|
643
654
|
sessionId: session.id,
|
|
644
655
|
});
|
|
@@ -837,15 +848,12 @@ export class AgentService {
|
|
|
837
848
|
}
|
|
838
849
|
}
|
|
839
850
|
async agentEffortConfiguration(context) {
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
const configurations = await Promise.all(context.sessionIds.map((sessionId) => this.daemon.effortConfiguration(sessionId, this.shutdown.signal)));
|
|
843
|
-
const options = configurations[0].options.filter((option) => configurations.every((configuration) => configuration.options.includes(option)));
|
|
844
|
-
const effort = context.effort ?? configurations[0].effort;
|
|
851
|
+
const configuration = await this.daemon.effortConfiguration(context.sessionId, this.shutdown.signal);
|
|
852
|
+
const effort = [context.effort, context.defaultEffort].find((candidate) => candidate && configuration.options.includes(candidate)) ?? configuration.effort;
|
|
845
853
|
return {
|
|
846
854
|
agentUserId: context.agentUserId,
|
|
847
855
|
effort,
|
|
848
|
-
options,
|
|
856
|
+
options: configuration.options,
|
|
849
857
|
};
|
|
850
858
|
}
|
|
851
859
|
async reconcileAgentEfforts() {
|
|
@@ -857,15 +865,14 @@ export class AgentService {
|
|
|
857
865
|
byAgent.set(binding.agentUserId, group);
|
|
858
866
|
}
|
|
859
867
|
for (const [agentUserId, agentBindings] of byAgent) {
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
(await this.daemon.effortConfiguration(agentBindings[0].sessionId, this.shutdown.signal)).effort;
|
|
863
|
-
|
|
864
|
-
const hint = await agentEffortInitialize(this.executor, agentUserId, effort);
|
|
868
|
+
let defaultEffort = agentBindings[0]?.defaultEffort;
|
|
869
|
+
if (!defaultEffort) {
|
|
870
|
+
defaultEffort = (await this.daemon.effortConfiguration(agentBindings[0].sessionId, this.shutdown.signal)).effort;
|
|
871
|
+
const hint = await agentEffortInitialize(this.executor, agentUserId, defaultEffort);
|
|
865
872
|
if (hint)
|
|
866
873
|
await this.publishAgentHint(hint);
|
|
867
874
|
}
|
|
868
|
-
await Promise.all(agentBindings.map((binding) => this.reconcileSessionEffort(binding.sessionId, effort)));
|
|
875
|
+
await Promise.all(agentBindings.map((binding) => this.reconcileSessionEffort(binding.sessionId, binding.effort ?? defaultEffort)));
|
|
869
876
|
}
|
|
870
877
|
}
|
|
871
878
|
async reconcileFunctionPermissions() {
|
|
@@ -883,7 +890,7 @@ export class AgentService {
|
|
|
883
890
|
await this.daemon.changeEffort(sessionId, effort, this.shutdown.signal);
|
|
884
891
|
}
|
|
885
892
|
async requireAgentSecret(actorUserId, secretId) {
|
|
886
|
-
await agentSecretAuthorizeManagement(this.executor, actorUserId);
|
|
893
|
+
await agentSecretAuthorizeManagement(this.executor, actorUserId, "assignSecrets");
|
|
887
894
|
const secrets = await this.daemon.listSecrets(this.shutdown.signal);
|
|
888
895
|
if (!secrets.some((secret) => secret.id === secretId))
|
|
889
896
|
throw new CollaborationError("not_found", "Agent secret was not found");
|
|
@@ -961,7 +968,9 @@ export class AgentService {
|
|
|
961
968
|
const event = entry.event;
|
|
962
969
|
if (event.type === "external_tool_call_requested" && event.data.call) {
|
|
963
970
|
const call = event.data.call;
|
|
964
|
-
const result =
|
|
971
|
+
const result = call.skill
|
|
972
|
+
? await this.executePluginSkillRead(event.sessionId, call.id, call.definition.name, call.skill)
|
|
973
|
+
: await this.executePluginFunctionCall(event.sessionId, call.id, call.definition.name, call.arguments);
|
|
965
974
|
await this.daemon.resolveExternalToolCall(event.sessionId, call.id, result, this.shutdown.signal);
|
|
966
975
|
return;
|
|
967
976
|
}
|
|
@@ -1015,6 +1024,49 @@ export class AgentService {
|
|
|
1015
1024
|
throw new Error(`Rig run ${runId} finished before its session snapshot was complete.`);
|
|
1016
1025
|
}
|
|
1017
1026
|
async executePluginFunctionCall(sessionId, callId, functionName, args) {
|
|
1027
|
+
return this.executeDurablePluginCall(sessionId, callId, async () => {
|
|
1028
|
+
if (!this.pluginCapabilities)
|
|
1029
|
+
return {
|
|
1030
|
+
status: "failed",
|
|
1031
|
+
error: {
|
|
1032
|
+
code: "plugin_functions_unavailable",
|
|
1033
|
+
message: "Plugin functions are unavailable on this server",
|
|
1034
|
+
},
|
|
1035
|
+
};
|
|
1036
|
+
const chatId = await agentChatGetIdBySession(this.executor, sessionId);
|
|
1037
|
+
if (!chatId)
|
|
1038
|
+
return {
|
|
1039
|
+
status: "failed",
|
|
1040
|
+
error: {
|
|
1041
|
+
code: "plugin_chat_unavailable",
|
|
1042
|
+
message: "The agent session is not bound to one current chat",
|
|
1043
|
+
},
|
|
1044
|
+
};
|
|
1045
|
+
return this.pluginCapabilities.callFunction(functionName, args, { chatId }, this.shutdown.signal);
|
|
1046
|
+
});
|
|
1047
|
+
}
|
|
1048
|
+
async executePluginSkillRead(sessionId, callId, functionName, skill) {
|
|
1049
|
+
return this.executeDurablePluginCall(sessionId, callId, () => {
|
|
1050
|
+
if (functionName !== "read_skill")
|
|
1051
|
+
return Promise.resolve({
|
|
1052
|
+
status: "failed",
|
|
1053
|
+
error: {
|
|
1054
|
+
code: "plugin_skill_invalid",
|
|
1055
|
+
message: "Rig requested a durable skill through an unknown function",
|
|
1056
|
+
},
|
|
1057
|
+
});
|
|
1058
|
+
return this.pluginCapabilities
|
|
1059
|
+
? this.pluginCapabilities.readSkill(skill, this.shutdown.signal)
|
|
1060
|
+
: Promise.resolve({
|
|
1061
|
+
status: "failed",
|
|
1062
|
+
error: {
|
|
1063
|
+
code: "plugin_skills_unavailable",
|
|
1064
|
+
message: "Plugin skills are unavailable on this server",
|
|
1065
|
+
},
|
|
1066
|
+
});
|
|
1067
|
+
});
|
|
1068
|
+
}
|
|
1069
|
+
async executeDurablePluginCall(sessionId, callId, execute) {
|
|
1018
1070
|
const leaseToken = createId();
|
|
1019
1071
|
for (;;) {
|
|
1020
1072
|
this.shutdown.signal.throwIfAborted();
|
|
@@ -1032,15 +1084,7 @@ export class AgentService {
|
|
|
1032
1084
|
await delay(Math.min(Math.max(claim.retryAt - now, EVENT_RETRY_INTERVAL_MS), PLUGIN_FUNCTION_WAIT_INTERVAL_MS), this.shutdown.signal);
|
|
1033
1085
|
continue;
|
|
1034
1086
|
}
|
|
1035
|
-
const result =
|
|
1036
|
-
? await this.pluginFunctions.callFunction(functionName, args, this.shutdown.signal)
|
|
1037
|
-
: {
|
|
1038
|
-
status: "failed",
|
|
1039
|
-
error: {
|
|
1040
|
-
code: "plugin_functions_unavailable",
|
|
1041
|
-
message: "Plugin functions are unavailable on this server",
|
|
1042
|
-
},
|
|
1043
|
-
};
|
|
1087
|
+
const result = await execute();
|
|
1044
1088
|
return pluginFunctionResultComplete(this.executor, {
|
|
1045
1089
|
callId,
|
|
1046
1090
|
leaseToken,
|
|
@@ -1079,6 +1123,9 @@ export class AgentService {
|
|
|
1079
1123
|
if (!input)
|
|
1080
1124
|
return;
|
|
1081
1125
|
try {
|
|
1126
|
+
const traced = await agentTurnTraceStart(this.executor, input);
|
|
1127
|
+
if (traced)
|
|
1128
|
+
await this.publishAgentReplyHint(input.chatId, traced.hint);
|
|
1082
1129
|
await this.startAgentActivity(input);
|
|
1083
1130
|
await this.startTyping(input);
|
|
1084
1131
|
const submission = await this.ensureTurnSubmitted(input);
|
|
@@ -1146,11 +1193,14 @@ export class AgentService {
|
|
|
1146
1193
|
runId,
|
|
1147
1194
|
}),
|
|
1148
1195
|
};
|
|
1149
|
-
const externalTools =
|
|
1196
|
+
const [externalTools, skills] = await Promise.all([
|
|
1197
|
+
this.pluginCapabilities?.listFunctions(this.shutdown.signal) ?? [],
|
|
1198
|
+
this.pluginCapabilities?.listSkills(this.shutdown.signal) ?? [],
|
|
1199
|
+
]);
|
|
1150
1200
|
for (;;) {
|
|
1151
1201
|
let submitted;
|
|
1152
1202
|
try {
|
|
1153
|
-
submitted = await this.daemon.submitTurn(input.sessionId, input.text, externalTools, this.shutdown.signal);
|
|
1203
|
+
submitted = await this.daemon.submitTurn(input.sessionId, input.text, externalTools, skills, this.shutdown.signal);
|
|
1154
1204
|
}
|
|
1155
1205
|
catch (error) {
|
|
1156
1206
|
if (this.shutdown.signal.aborted)
|
|
@@ -1220,6 +1270,9 @@ export class AgentService {
|
|
|
1220
1270
|
sessionId: input.sessionId,
|
|
1221
1271
|
streamCommittedText: update.streamCommittedText,
|
|
1222
1272
|
text: update.text,
|
|
1273
|
+
traceUpdates: update.traceUpdates,
|
|
1274
|
+
subagents: update.subagents,
|
|
1275
|
+
backgroundTerminals: update.backgroundTerminals,
|
|
1223
1276
|
userMessageId: input.userMessageId,
|
|
1224
1277
|
workerId: input.workerId,
|
|
1225
1278
|
});
|
|
@@ -1284,8 +1337,11 @@ export class AgentService {
|
|
|
1284
1337
|
shouldPersist = true;
|
|
1285
1338
|
}
|
|
1286
1339
|
}
|
|
1287
|
-
if (runId &&
|
|
1288
|
-
|
|
1340
|
+
if (runId &&
|
|
1341
|
+
(event.data.runId === runId || event.type === "subagent_changed")) {
|
|
1342
|
+
const traceUpdates = await this.updateAgentActivity(input, event);
|
|
1343
|
+
if (traceUpdates.length > 0)
|
|
1344
|
+
shouldPersist = true;
|
|
1289
1345
|
if (event.type === "agent_event") {
|
|
1290
1346
|
const nextPartial = agentLoopText(event);
|
|
1291
1347
|
if (nextPartial !== undefined) {
|
|
@@ -1301,12 +1357,29 @@ export class AgentService {
|
|
|
1301
1357
|
shouldPersist = true;
|
|
1302
1358
|
}
|
|
1303
1359
|
}
|
|
1360
|
+
if (shouldPersist) {
|
|
1361
|
+
const activity = this.agentActivities.get(input.userMessageId);
|
|
1362
|
+
output.add({
|
|
1363
|
+
eventId: event.id,
|
|
1364
|
+
streamCommittedText: committedText,
|
|
1365
|
+
text: appendAgentText(committedText, partialText),
|
|
1366
|
+
traceUpdates,
|
|
1367
|
+
...(activity
|
|
1368
|
+
? {
|
|
1369
|
+
subagents: activitySubagents(activity),
|
|
1370
|
+
backgroundTerminals: activityBackgroundTerminals(activity),
|
|
1371
|
+
}
|
|
1372
|
+
: {}),
|
|
1373
|
+
});
|
|
1374
|
+
shouldPersist = false;
|
|
1375
|
+
}
|
|
1304
1376
|
}
|
|
1305
1377
|
if (shouldPersist)
|
|
1306
1378
|
output.add({
|
|
1307
1379
|
eventId: event.id,
|
|
1308
1380
|
streamCommittedText: committedText,
|
|
1309
1381
|
text: appendAgentText(committedText, partialText),
|
|
1382
|
+
traceUpdates: [],
|
|
1310
1383
|
});
|
|
1311
1384
|
}, signal);
|
|
1312
1385
|
after = output.lastEventId;
|
|
@@ -1399,6 +1472,13 @@ export class AgentService {
|
|
|
1399
1472
|
async startAgentActivity(input) {
|
|
1400
1473
|
if (this.agentActivities.has(input.userMessageId))
|
|
1401
1474
|
return;
|
|
1475
|
+
let snapshot;
|
|
1476
|
+
try {
|
|
1477
|
+
snapshot = await this.daemon.turnActivity(input.sessionId, this.shutdown.signal);
|
|
1478
|
+
}
|
|
1479
|
+
catch (error) {
|
|
1480
|
+
this.onError(error);
|
|
1481
|
+
}
|
|
1402
1482
|
let activity;
|
|
1403
1483
|
const timer = setInterval(() => {
|
|
1404
1484
|
if (this.agentActivities.get(input.userMessageId) !== activity)
|
|
@@ -1407,11 +1487,25 @@ export class AgentService {
|
|
|
1407
1487
|
}, AGENT_ACTIVITY_RENEW_INTERVAL_MS);
|
|
1408
1488
|
timer.unref();
|
|
1409
1489
|
activity = {
|
|
1490
|
+
backgroundTerminals: new Map((snapshot?.backgroundProcesses ?? [])
|
|
1491
|
+
.slice(0, MAX_TRACE_COLLECTION_ITEMS)
|
|
1492
|
+
.map((process) => {
|
|
1493
|
+
const terminal = backgroundTerminalSummary(process, Date.now());
|
|
1494
|
+
return [terminal.id, terminal];
|
|
1495
|
+
})),
|
|
1410
1496
|
lastOccurredAt: 0,
|
|
1411
1497
|
phase: "thinking",
|
|
1412
1498
|
startedAt: sqliteTimestamp(input.startedAt),
|
|
1499
|
+
subagents: new Map((snapshot?.subagents ?? [])
|
|
1500
|
+
.filter(subagentIsActive)
|
|
1501
|
+
.slice(0, MAX_TRACE_COLLECTION_ITEMS)
|
|
1502
|
+
.map((subagent) => {
|
|
1503
|
+
const summary = subagentSummary(subagent);
|
|
1504
|
+
return [summary.id, summary];
|
|
1505
|
+
})),
|
|
1413
1506
|
timer,
|
|
1414
1507
|
tokenCounts: new Map(),
|
|
1508
|
+
toolNames: new Map(),
|
|
1415
1509
|
userMessageId: input.userMessageId,
|
|
1416
1510
|
};
|
|
1417
1511
|
this.agentActivities.set(input.userMessageId, activity);
|
|
@@ -1425,7 +1519,8 @@ export class AgentService {
|
|
|
1425
1519
|
async updateAgentActivity(input, event) {
|
|
1426
1520
|
const activity = this.agentActivities.get(input.userMessageId);
|
|
1427
1521
|
if (!activity)
|
|
1428
|
-
return;
|
|
1522
|
+
return [];
|
|
1523
|
+
const traceUpdates = agentTurnTraceUpdates(event, activity);
|
|
1429
1524
|
if (event.type === "run_started" &&
|
|
1430
1525
|
Number.isSafeInteger(event.createdAt) &&
|
|
1431
1526
|
event.createdAt >= 0)
|
|
@@ -1434,17 +1529,19 @@ export class AgentService {
|
|
|
1434
1529
|
const phaseChanged = phase !== undefined && phase !== activity.phase;
|
|
1435
1530
|
if (phase !== undefined)
|
|
1436
1531
|
activity.phase = phase;
|
|
1532
|
+
const workChanged = agentActivityWorkApply(activity, event);
|
|
1437
1533
|
const usage = agentEventTokenCount(event);
|
|
1438
1534
|
if (usage)
|
|
1439
1535
|
activity.tokenCounts.set(usage.messageId, usage.tokenCount);
|
|
1440
|
-
if (!phaseChanged)
|
|
1441
|
-
return;
|
|
1536
|
+
if (!phaseChanged && !workChanged)
|
|
1537
|
+
return traceUpdates;
|
|
1442
1538
|
try {
|
|
1443
1539
|
await this.publishAgentActivity(input, activity, true);
|
|
1444
1540
|
}
|
|
1445
1541
|
catch (error) {
|
|
1446
1542
|
this.onError(error);
|
|
1447
1543
|
}
|
|
1544
|
+
return traceUpdates;
|
|
1448
1545
|
}
|
|
1449
1546
|
async stopAgentActivity(input) {
|
|
1450
1547
|
const activity = this.agentActivities.get(input.userMessageId);
|
|
@@ -1467,7 +1564,7 @@ export class AgentService {
|
|
|
1467
1564
|
publishAgentActivity(input, activity, active) {
|
|
1468
1565
|
const occurredAt = Math.max(Date.now(), activity.lastOccurredAt + 1);
|
|
1469
1566
|
activity.lastOccurredAt = occurredAt;
|
|
1470
|
-
const tokenCount = [...activity.tokenCounts.values()].reduce((total, count) => total + count, 0);
|
|
1567
|
+
const tokenCount = boundedInteger([...activity.tokenCounts.values()].reduce((total, count) => Math.min(Number.MAX_SAFE_INTEGER, total + count), 0), 0);
|
|
1471
1568
|
return this.pubsub.publish(realtimeTopics.chat(input.chatId), {
|
|
1472
1569
|
type: "agent.activity",
|
|
1473
1570
|
chatId: input.chatId,
|
|
@@ -1476,8 +1573,10 @@ export class AgentService {
|
|
|
1476
1573
|
active,
|
|
1477
1574
|
phase: activity.phase,
|
|
1478
1575
|
tokenCount,
|
|
1479
|
-
startedAt: activity.startedAt,
|
|
1576
|
+
startedAt: Math.min(boundedTimestamp(activity.startedAt), occurredAt),
|
|
1480
1577
|
occurredAt,
|
|
1578
|
+
subagents: activitySubagents(activity),
|
|
1579
|
+
backgroundTerminals: activityBackgroundTerminals(activity),
|
|
1481
1580
|
...(active
|
|
1482
1581
|
? {
|
|
1483
1582
|
expiresAt: occurredAt + AGENT_ACTIVITY_TTL_MS,
|
|
@@ -1580,7 +1679,19 @@ class AgentReplyStreamOutput {
|
|
|
1580
1679
|
add(update) {
|
|
1581
1680
|
if (this.failure)
|
|
1582
1681
|
return;
|
|
1583
|
-
this.pending
|
|
1682
|
+
const traces = new Map((this.pending?.traceUpdates ?? []).map((trace) => [trace.traceKey, trace]));
|
|
1683
|
+
for (const trace of update.traceUpdates) {
|
|
1684
|
+
if (!traces.has(trace.traceKey) && traces.size >= MAX_PENDING_TRACE_UPDATES)
|
|
1685
|
+
continue;
|
|
1686
|
+
traces.delete(trace.traceKey);
|
|
1687
|
+
traces.set(trace.traceKey, trace);
|
|
1688
|
+
}
|
|
1689
|
+
this.pending = {
|
|
1690
|
+
...update,
|
|
1691
|
+
traceUpdates: [...traces.values()],
|
|
1692
|
+
subagents: update.subagents ?? this.pending?.subagents,
|
|
1693
|
+
backgroundTerminals: update.backgroundTerminals ?? this.pending?.backgroundTerminals,
|
|
1694
|
+
};
|
|
1584
1695
|
if (Math.abs(update.text.length - this.persistedTextLength) >= AGENT_REPLY_FLUSH_CHARACTERS) {
|
|
1585
1696
|
this.flushInBackground();
|
|
1586
1697
|
return;
|
|
@@ -1800,6 +1911,343 @@ function agentLoopText(event) {
|
|
|
1800
1911
|
return undefined;
|
|
1801
1912
|
return textBlocks.map((block) => block.text ?? "").join("");
|
|
1802
1913
|
}
|
|
1914
|
+
function agentActivityWorkApply(activity, event) {
|
|
1915
|
+
if (event.type === "subagent_changed" && event.data.subagent) {
|
|
1916
|
+
const summary = subagentSummary(event.data.subagent);
|
|
1917
|
+
if (subagentIsActive(event.data.subagent) &&
|
|
1918
|
+
(activity.subagents.has(summary.id) ||
|
|
1919
|
+
activity.subagents.size < MAX_TRACE_COLLECTION_ITEMS))
|
|
1920
|
+
activity.subagents.set(summary.id, summary);
|
|
1921
|
+
else
|
|
1922
|
+
activity.subagents.delete(summary.id);
|
|
1923
|
+
return true;
|
|
1924
|
+
}
|
|
1925
|
+
const loop = event.type === "agent_event" ? event.data.event : undefined;
|
|
1926
|
+
if (loop?.type !== "background_processes_changed")
|
|
1927
|
+
return false;
|
|
1928
|
+
const processes = loop.processes ?? (loop.running === 0 ? [] : undefined);
|
|
1929
|
+
if (!processes)
|
|
1930
|
+
return false;
|
|
1931
|
+
const observedAt = boundedTimestamp(event.createdAt);
|
|
1932
|
+
const next = new Map();
|
|
1933
|
+
for (const process of processes.slice(0, MAX_TRACE_COLLECTION_ITEMS)) {
|
|
1934
|
+
const id = boundedIdentifier(String(process.sessionId), "terminal");
|
|
1935
|
+
next.set(id, activity.backgroundTerminals.get(id) ?? backgroundTerminalSummary(process, observedAt));
|
|
1936
|
+
}
|
|
1937
|
+
activity.backgroundTerminals = next;
|
|
1938
|
+
return true;
|
|
1939
|
+
}
|
|
1940
|
+
function agentTurnTraceUpdates(event, activity) {
|
|
1941
|
+
const occurredAt = boundedTimestamp(event.createdAt);
|
|
1942
|
+
if (event.type === "subagent_changed" && event.data.subagent) {
|
|
1943
|
+
const subagent = subagentSummary(event.data.subagent);
|
|
1944
|
+
const status = traceStatusForSubagent(subagent.status);
|
|
1945
|
+
return [
|
|
1946
|
+
{
|
|
1947
|
+
traceKey: `subagent:${subagent.id}`,
|
|
1948
|
+
sessionEventId: event.id,
|
|
1949
|
+
kind: "subagent",
|
|
1950
|
+
title: subagent.description,
|
|
1951
|
+
...(subagent.latestText ? { detail: traceDetail(subagent.latestText) } : {}),
|
|
1952
|
+
status,
|
|
1953
|
+
occurredAt,
|
|
1954
|
+
...(status === "running" ? {} : { completedAt: occurredAt }),
|
|
1955
|
+
},
|
|
1956
|
+
];
|
|
1957
|
+
}
|
|
1958
|
+
if (event.type === "run_started")
|
|
1959
|
+
return [
|
|
1960
|
+
{
|
|
1961
|
+
traceKey: `run:${event.data.runId ?? "active"}`,
|
|
1962
|
+
sessionEventId: event.id,
|
|
1963
|
+
kind: "status",
|
|
1964
|
+
title: "Thinking",
|
|
1965
|
+
status: "running",
|
|
1966
|
+
occurredAt,
|
|
1967
|
+
},
|
|
1968
|
+
];
|
|
1969
|
+
if (event.type === "agent_message") {
|
|
1970
|
+
const detail = messageText(event.data.message);
|
|
1971
|
+
return detail
|
|
1972
|
+
? [
|
|
1973
|
+
{
|
|
1974
|
+
traceKey: `response:${event.data.message?.id ?? "active"}`,
|
|
1975
|
+
sessionEventId: event.id,
|
|
1976
|
+
kind: "response",
|
|
1977
|
+
title: "Response completed",
|
|
1978
|
+
detail: traceDetail(detail),
|
|
1979
|
+
status: "complete",
|
|
1980
|
+
occurredAt,
|
|
1981
|
+
completedAt: occurredAt,
|
|
1982
|
+
},
|
|
1983
|
+
]
|
|
1984
|
+
: [];
|
|
1985
|
+
}
|
|
1986
|
+
const loop = event.type === "agent_event" ? event.data.event : undefined;
|
|
1987
|
+
const type = loop?.type;
|
|
1988
|
+
if (!loop || !type)
|
|
1989
|
+
return [];
|
|
1990
|
+
if (type.startsWith("thinking_")) {
|
|
1991
|
+
const detail = agentLoopContent(loop, "thinking");
|
|
1992
|
+
return [
|
|
1993
|
+
{
|
|
1994
|
+
traceKey: `reasoning:${loop.partial?.id ?? "active"}:${loop.contentIndex ?? 0}`,
|
|
1995
|
+
sessionEventId: event.id,
|
|
1996
|
+
kind: "reasoning",
|
|
1997
|
+
title: "Reasoning",
|
|
1998
|
+
...(detail ? { detail: traceDetail(detail) } : {}),
|
|
1999
|
+
status: type === "thinking_end" ? "complete" : "running",
|
|
2000
|
+
occurredAt,
|
|
2001
|
+
...(type === "thinking_end" ? { completedAt: occurredAt } : {}),
|
|
2002
|
+
},
|
|
2003
|
+
];
|
|
2004
|
+
}
|
|
2005
|
+
if (type.startsWith("text_")) {
|
|
2006
|
+
const detail = agentLoopContent(loop, "text");
|
|
2007
|
+
return [
|
|
2008
|
+
{
|
|
2009
|
+
traceKey: `response:${loop.partial?.id ?? "active"}:${loop.contentIndex ?? 0}`,
|
|
2010
|
+
sessionEventId: event.id,
|
|
2011
|
+
kind: "response",
|
|
2012
|
+
title: type === "text_end" ? "Response drafted" : "Writing response",
|
|
2013
|
+
...(detail ? { detail: traceDetail(detail) } : {}),
|
|
2014
|
+
status: type === "text_end" ? "complete" : "running",
|
|
2015
|
+
occurredAt,
|
|
2016
|
+
...(type === "text_end" ? { completedAt: occurredAt } : {}),
|
|
2017
|
+
},
|
|
2018
|
+
];
|
|
2019
|
+
}
|
|
2020
|
+
if (type === "toolcall_end" && loop.toolCall?.id) {
|
|
2021
|
+
const toolCallId = boundedIdentifier(loop.toolCall.id, "tool");
|
|
2022
|
+
const name = traceSummary(loop.toolCall.name ?? "tool") || "tool";
|
|
2023
|
+
if (activity.toolNames.has(toolCallId) || activity.toolNames.size < MAX_TRACKED_TOOL_NAMES)
|
|
2024
|
+
activity.toolNames.set(toolCallId, name);
|
|
2025
|
+
return [
|
|
2026
|
+
{
|
|
2027
|
+
traceKey: `tool:${toolCallId}`,
|
|
2028
|
+
sessionEventId: event.id,
|
|
2029
|
+
kind: "tool",
|
|
2030
|
+
title: traceTitle(`Calling ${humanizeTraceToolName(name)}`),
|
|
2031
|
+
detail: traceDetail(JSON.stringify(loop.toolCall.arguments ?? {})),
|
|
2032
|
+
status: "running",
|
|
2033
|
+
occurredAt,
|
|
2034
|
+
},
|
|
2035
|
+
];
|
|
2036
|
+
}
|
|
2037
|
+
if (type === "tool_execution_start" && loop.toolCall?.id) {
|
|
2038
|
+
const toolCallId = boundedIdentifier(loop.toolCall.id, "tool");
|
|
2039
|
+
const name = traceSummary(loop.toolCall.name ?? "tool") || "tool";
|
|
2040
|
+
if (activity.toolNames.has(toolCallId) || activity.toolNames.size < MAX_TRACKED_TOOL_NAMES)
|
|
2041
|
+
activity.toolNames.set(toolCallId, name);
|
|
2042
|
+
return [
|
|
2043
|
+
{
|
|
2044
|
+
traceKey: `tool:${toolCallId}`,
|
|
2045
|
+
sessionEventId: event.id,
|
|
2046
|
+
kind: "tool",
|
|
2047
|
+
title: traceTitle(`Running ${humanizeTraceToolName(name)}`),
|
|
2048
|
+
detail: traceDetail(JSON.stringify(loop.toolCall.arguments ?? {})),
|
|
2049
|
+
status: "running",
|
|
2050
|
+
occurredAt,
|
|
2051
|
+
},
|
|
2052
|
+
];
|
|
2053
|
+
}
|
|
2054
|
+
if ((type === "tool_execution_progress" || type === "tool_execution_status") &&
|
|
2055
|
+
loop.toolCallId) {
|
|
2056
|
+
const toolCallId = boundedIdentifier(loop.toolCallId, "tool");
|
|
2057
|
+
const name = activity.toolNames.get(toolCallId) ?? "tool";
|
|
2058
|
+
const detail = type === "tool_execution_progress" ? loop.display : loop.status;
|
|
2059
|
+
return [
|
|
2060
|
+
{
|
|
2061
|
+
traceKey: `tool:${toolCallId}`,
|
|
2062
|
+
sessionEventId: event.id,
|
|
2063
|
+
kind: "tool",
|
|
2064
|
+
title: traceTitle(`Running ${humanizeTraceToolName(name)}`),
|
|
2065
|
+
...(detail ? { detail: traceDetail(detail) } : {}),
|
|
2066
|
+
status: "running",
|
|
2067
|
+
occurredAt,
|
|
2068
|
+
},
|
|
2069
|
+
];
|
|
2070
|
+
}
|
|
2071
|
+
if (type === "tool_execution_end" && loop.result?.toolCallId) {
|
|
2072
|
+
const toolCallId = boundedIdentifier(loop.result.toolCallId, "tool");
|
|
2073
|
+
const name = traceSummary(loop.result.toolName ?? activity.toolNames.get(toolCallId) ?? "tool") ||
|
|
2074
|
+
"tool";
|
|
2075
|
+
activity.toolNames.delete(toolCallId);
|
|
2076
|
+
return [
|
|
2077
|
+
{
|
|
2078
|
+
traceKey: `tool:${toolCallId}`,
|
|
2079
|
+
sessionEventId: event.id,
|
|
2080
|
+
kind: "tool",
|
|
2081
|
+
title: traceTitle(`${humanizeTraceToolName(name)} ${loop.result.isError ? "failed" : "completed"}`),
|
|
2082
|
+
...(loop.result.display ? { detail: traceDetail(loop.result.display) } : {}),
|
|
2083
|
+
status: loop.result.isError ? "failed" : "complete",
|
|
2084
|
+
occurredAt,
|
|
2085
|
+
completedAt: occurredAt,
|
|
2086
|
+
},
|
|
2087
|
+
];
|
|
2088
|
+
}
|
|
2089
|
+
if (type === "background_processes_changed") {
|
|
2090
|
+
const processes = loop.processes ?? (loop.running === 0 ? [] : undefined);
|
|
2091
|
+
if (!processes)
|
|
2092
|
+
return [];
|
|
2093
|
+
const boundedProcesses = processes.slice(0, MAX_TRACE_COLLECTION_ITEMS);
|
|
2094
|
+
const nextIds = new Set(boundedProcesses.map((process) => boundedIdentifier(String(process.sessionId), "terminal")));
|
|
2095
|
+
const completed = [...activity.backgroundTerminals.values()]
|
|
2096
|
+
.filter((terminal) => !nextIds.has(terminal.id))
|
|
2097
|
+
.map((terminal) => ({
|
|
2098
|
+
traceKey: `terminal:${terminal.id}`,
|
|
2099
|
+
sessionEventId: event.id,
|
|
2100
|
+
kind: "terminal",
|
|
2101
|
+
title: "Background terminal completed",
|
|
2102
|
+
detail: traceDetail(terminal.command),
|
|
2103
|
+
status: "complete",
|
|
2104
|
+
occurredAt: terminal.startedAt,
|
|
2105
|
+
completedAt: occurredAt,
|
|
2106
|
+
}));
|
|
2107
|
+
const running = boundedProcesses.map((process) => {
|
|
2108
|
+
const id = boundedIdentifier(String(process.sessionId), "terminal");
|
|
2109
|
+
const existing = activity.backgroundTerminals.get(id);
|
|
2110
|
+
return {
|
|
2111
|
+
traceKey: `terminal:${id}`,
|
|
2112
|
+
sessionEventId: event.id,
|
|
2113
|
+
kind: "terminal",
|
|
2114
|
+
title: "Background terminal running",
|
|
2115
|
+
detail: traceDetail(process.command),
|
|
2116
|
+
status: "running",
|
|
2117
|
+
occurredAt: existing?.startedAt ?? occurredAt,
|
|
2118
|
+
};
|
|
2119
|
+
});
|
|
2120
|
+
return [...completed, ...running];
|
|
2121
|
+
}
|
|
2122
|
+
if (type === "inference_iteration_start")
|
|
2123
|
+
return [
|
|
2124
|
+
{
|
|
2125
|
+
traceKey: `inference:${loop.iteration ?? event.id}`,
|
|
2126
|
+
sessionEventId: event.id,
|
|
2127
|
+
kind: "status",
|
|
2128
|
+
title: traceTitle(`Inference ${loop.iteration ?? "started"}`),
|
|
2129
|
+
status: "complete",
|
|
2130
|
+
occurredAt,
|
|
2131
|
+
completedAt: occurredAt,
|
|
2132
|
+
},
|
|
2133
|
+
];
|
|
2134
|
+
if (type === "context_compacted")
|
|
2135
|
+
return [
|
|
2136
|
+
{
|
|
2137
|
+
traceKey: `context:${event.id}`,
|
|
2138
|
+
sessionEventId: event.id,
|
|
2139
|
+
kind: "status",
|
|
2140
|
+
title: "Context compacted",
|
|
2141
|
+
status: "complete",
|
|
2142
|
+
occurredAt,
|
|
2143
|
+
completedAt: occurredAt,
|
|
2144
|
+
},
|
|
2145
|
+
];
|
|
2146
|
+
return [];
|
|
2147
|
+
}
|
|
2148
|
+
function subagentSummary(subagent) {
|
|
2149
|
+
const latestText = subagent.latestText ? activityText(subagent.latestText) : "";
|
|
2150
|
+
return {
|
|
2151
|
+
id: boundedIdentifier(subagent.id, "subagent"),
|
|
2152
|
+
depth: boundedInteger(subagent.depth, 1),
|
|
2153
|
+
description: activityText(subagent.description) || "Subagent",
|
|
2154
|
+
status: subagentStatus(subagent.status),
|
|
2155
|
+
...(latestText ? { latestText } : {}),
|
|
2156
|
+
startedAt: boundedTimestamp(subagent.activeSince ?? subagent.createdAt),
|
|
2157
|
+
totalTokens: boundedInteger(subagent.totalTokens ?? 0, 0),
|
|
2158
|
+
};
|
|
2159
|
+
}
|
|
2160
|
+
function subagentIsActive(subagent) {
|
|
2161
|
+
return ((subagent.status === "queued" || subagent.status === "running") &&
|
|
2162
|
+
!subagent.taskName?.startsWith("workflow_"));
|
|
2163
|
+
}
|
|
2164
|
+
function traceStatusForSubagent(status) {
|
|
2165
|
+
if (status === "queued" || status === "running")
|
|
2166
|
+
return "running";
|
|
2167
|
+
return status === "error" || status === "aborted" ? "failed" : "complete";
|
|
2168
|
+
}
|
|
2169
|
+
function backgroundTerminalSummary(process, startedAt) {
|
|
2170
|
+
return {
|
|
2171
|
+
id: boundedIdentifier(String(process.sessionId), "terminal"),
|
|
2172
|
+
command: activityText(process.command) || "Background command",
|
|
2173
|
+
cwd: activityText(process.cwd) || ".",
|
|
2174
|
+
startedAt: boundedTimestamp(startedAt),
|
|
2175
|
+
};
|
|
2176
|
+
}
|
|
2177
|
+
function activitySubagents(activity) {
|
|
2178
|
+
return [...activity.subagents.values()].slice(0, MAX_TRACE_COLLECTION_ITEMS);
|
|
2179
|
+
}
|
|
2180
|
+
function activityBackgroundTerminals(activity) {
|
|
2181
|
+
return [...activity.backgroundTerminals.values()].slice(0, MAX_TRACE_COLLECTION_ITEMS);
|
|
2182
|
+
}
|
|
2183
|
+
function agentLoopContent(loop, kind) {
|
|
2184
|
+
const blocks = loop.partial?.content ?? loop.message?.content ?? loop.error?.content ?? [];
|
|
2185
|
+
const content = blocks
|
|
2186
|
+
.filter((block) => block.type === kind)
|
|
2187
|
+
.map((block) => (kind === "text" ? block.text : block.thinking) ?? "")
|
|
2188
|
+
.join("");
|
|
2189
|
+
return content || (typeof loop.content === "string" ? loop.content : undefined);
|
|
2190
|
+
}
|
|
2191
|
+
function humanizeTraceToolName(name) {
|
|
2192
|
+
const spaced = name
|
|
2193
|
+
.replaceAll(/[_-]+/gu, " ")
|
|
2194
|
+
.replaceAll(/([a-z\d])([A-Z])/gu, "$1 $2")
|
|
2195
|
+
.trim();
|
|
2196
|
+
return spaced ? `${spaced[0].toUpperCase()}${spaced.slice(1)}` : "Tool";
|
|
2197
|
+
}
|
|
2198
|
+
function traceDetail(value) {
|
|
2199
|
+
return textValue(value).trim().slice(-MAX_TRACE_DETAIL_CHARACTERS);
|
|
2200
|
+
}
|
|
2201
|
+
function traceSummary(value) {
|
|
2202
|
+
return textValue(value).trim().slice(-MAX_TRACE_SUMMARY_CHARACTERS);
|
|
2203
|
+
}
|
|
2204
|
+
function activityText(value) {
|
|
2205
|
+
return textValue(value).trim().slice(-MAX_ACTIVITY_TEXT_CHARACTERS);
|
|
2206
|
+
}
|
|
2207
|
+
function traceTitle(value) {
|
|
2208
|
+
return traceSummary(value) || "Agent activity";
|
|
2209
|
+
}
|
|
2210
|
+
function boundedIdentifier(value, prefix) {
|
|
2211
|
+
const text = textValue(value);
|
|
2212
|
+
const clean = [...text]
|
|
2213
|
+
.filter((character) => {
|
|
2214
|
+
const code = character.charCodeAt(0);
|
|
2215
|
+
return code > 31 && code !== 127;
|
|
2216
|
+
})
|
|
2217
|
+
.join("");
|
|
2218
|
+
if (clean.length > 0 && clean.length <= MAX_TRACE_ID_CHARACTERS)
|
|
2219
|
+
return clean;
|
|
2220
|
+
return `${prefix}-${createHash("sha256").update(text).digest("hex").slice(0, 32)}`;
|
|
2221
|
+
}
|
|
2222
|
+
function boundedTimestamp(value) {
|
|
2223
|
+
const now = Date.now();
|
|
2224
|
+
return typeof value === "number" && Number.isSafeInteger(value) && value >= 0
|
|
2225
|
+
? Math.min(value, now)
|
|
2226
|
+
: now;
|
|
2227
|
+
}
|
|
2228
|
+
function boundedInteger(value, minimum) {
|
|
2229
|
+
return typeof value === "number" && Number.isSafeInteger(value)
|
|
2230
|
+
? Math.max(minimum, Math.min(value, Number.MAX_SAFE_INTEGER))
|
|
2231
|
+
: minimum;
|
|
2232
|
+
}
|
|
2233
|
+
function textValue(value) {
|
|
2234
|
+
return typeof value === "string"
|
|
2235
|
+
? value
|
|
2236
|
+
: value === undefined || value === null
|
|
2237
|
+
? ""
|
|
2238
|
+
: String(value);
|
|
2239
|
+
}
|
|
2240
|
+
function subagentStatus(value) {
|
|
2241
|
+
return value === "idle" ||
|
|
2242
|
+
value === "queued" ||
|
|
2243
|
+
value === "running" ||
|
|
2244
|
+
value === "completed" ||
|
|
2245
|
+
value === "aborted" ||
|
|
2246
|
+
value === "suspended" ||
|
|
2247
|
+
value === "error"
|
|
2248
|
+
? value
|
|
2249
|
+
: "error";
|
|
2250
|
+
}
|
|
1803
2251
|
function agentActivityPhase(event) {
|
|
1804
2252
|
if (event.type === "run_started")
|
|
1805
2253
|
return "thinking";
|