@myagentroam/node 0.9.62 → 0.9.65
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/LICENSE +202 -0
- package/NOTICE +4 -0
- package/dist/capabilities.js +110 -2
- package/dist/claude-agent-sdk.js +330 -2
- package/dist/claude-channel.js +44 -2
- package/dist/codex-app-server.js +510 -2
- package/dist/config.js +106 -2
- package/dist/connector/node-connector-options.js +1 -2
- package/dist/connector/node-operation-router.js +22 -2
- package/dist/connector.js +1736 -2
- package/dist/control-outbound-scheduler.js +153 -2
- package/dist/database.js +639 -2
- package/dist/fake-runner.js +129 -2
- package/dist/git-askpass.js +12 -0
- package/dist/git-execution-helper.js +266 -0
- package/dist/health.js +3 -2
- package/dist/main.js +57 -2
- package/dist/mcp-installation-model.js +1 -2
- package/dist/migrations/v004.js +55 -3
- package/dist/migrations/v005.js +13 -3
- package/dist/migrations/v006.js +90 -3
- package/dist/migrations/v007.js +22 -3
- package/dist/migrations/v008.js +18 -3
- package/dist/migrations/v009.js +70 -4
- package/dist/migrations/v010.js +43 -3
- package/dist/migrations/v011.js +20 -3
- package/dist/migrations/v012.js +8 -0
- package/dist/native-jsonl-reader.js +186 -2
- package/dist/native-session-history.js +1143 -2
- package/dist/opencode-runtime.js +80 -2
- package/dist/opencode-server.js +259 -2
- package/dist/operational.js +122 -2
- package/dist/process-tree.js +18 -2
- package/dist/ripgrep-binary.js +31 -2
- package/dist/rotating-log.js +67 -2
- package/dist/runner/abstract-runner.js +260 -2
- package/dist/runner/claude/managed-run-controller.js +355 -2
- package/dist/runner/claude/tool-normalizer.js +120 -2
- package/dist/runner/claude-code-runner.js +303 -2
- package/dist/runner/codex/composer-image-markers.js +8 -2
- package/dist/runner/codex/conversation-parser.js +913 -2
- package/dist/runner/codex/managed-run-controller.js +494 -2
- package/dist/runner/codex/tool-normalizer.js +214 -2
- package/dist/runner/codex-runner.js +585 -2
- package/dist/runner/fake-test-runner.js +47 -2
- package/dist/runner/mar-agent/conversation-normalizer.js +644 -2
- package/dist/runner/mar-agent/executor-stdio-client-transport.js +139 -2
- package/dist/runner/mar-agent/generated-images.js +41 -2
- package/dist/runner/mar-agent/history-projection.js +106 -2
- package/dist/runner/mar-agent/hosted-conversation-runtime.js +446 -2
- package/dist/runner/mar-agent/managed-run-controller.js +785 -2
- package/dist/runner/mar-agent/mcp-client-pool.js +233 -2
- package/dist/runner/mar-agent/runtime-model-factory.js +326 -2
- package/dist/runner/mar-agent-runner.js +458 -2
- package/dist/runner/opencode/conversation-parser.js +221 -2
- package/dist/runner/opencode/managed-run-controller.js +588 -2
- package/dist/runner/opencode/tool-normalizer.js +80 -2
- package/dist/runner/opencode-runner.js +426 -2
- package/dist/runner/runner-registry.js +87 -2
- package/dist/runner-command-engine.js +71 -2
- package/dist/runner-profiles.js +323 -2
- package/dist/runner-usage.js +190 -2
- package/dist/runtime-command-detector.js +73 -2
- package/dist/runtime-model.js +1 -2
- package/dist/runtime-state.js +1509 -2
- package/dist/service/attachment-domain-state.js +7 -2
- package/dist/service/bubblewrap-sandbox-executor.js +543 -2
- package/dist/service/continuous-run-coordinator.js +425 -2
- package/dist/service/conversation-history-service.js +552 -2
- package/dist/service/conversation-hosting-capability-service.js +61 -2
- package/dist/service/conversation-hosting-enablement-service.js +91 -2
- package/dist/service/conversation-hosting-maintenance-service.js +174 -2
- package/dist/service/conversation-segment-service.js +162 -2
- package/dist/service/conversation-template-node-service.js +992 -2
- package/dist/service/external-session-resume-service.js +152 -2
- package/dist/service/fake-managed-run-service.js +60 -2
- package/dist/service/git-execution-service.js +418 -0
- package/dist/service/git-operation-service.js +57 -0
- package/dist/service/hosted-conversation-node-service.js +1982 -2
- package/dist/service/hosted-conversation-store.js +1405 -2
- package/dist/service/managed-runner-session-service.js +35 -2
- package/dist/service/mar-agent-model-transport-test-service.js +88 -2
- package/dist/service/mcp-installation-verifier.js +87 -2
- package/dist/service/mcp-node-operation-service.js +90 -2
- package/dist/service/mission-mcp-server.js +124 -2
- package/dist/service/mission-mcp-stdio.js +40 -2
- package/dist/service/mission-runtime.js +142 -2
- package/dist/service/native-session-projection-service.js +274 -2
- package/dist/service/native-session-watch-service.js +683 -2
- package/dist/service/node-connection-lifecycle-service.js +88 -2
- package/dist/service/node-control-channel.js +85 -2
- package/dist/service/node-control-message-service.js +109 -2
- package/dist/service/node-request-service.js +62 -2
- package/dist/service/node-run-event-bridge.js +88 -2
- package/dist/service/node-terminal-channel.js +202 -2
- package/dist/service/node-upgrade-coordinator.js +137 -2
- package/dist/service/node-workspace-coordinator.js +97 -2
- package/dist/service/recent-run-projection-service.js +99 -2
- package/dist/service/run-attachment-service.js +321 -2
- package/dist/service/run-domain-state.js +4 -2
- package/dist/service/run-event-service.js +246 -2
- package/dist/service/run-ownership-policy.js +22 -2
- package/dist/service/run-workbench-service.js +120 -2
- package/dist/service/runner-channel-message-service.js +20 -2
- package/dist/service/runner-interaction-service.js +243 -2
- package/dist/service/runner-service.js +69 -2
- package/dist/service/runtime-credential-control-service.js +95 -2
- package/dist/service/session-catalog-service.js +404 -2
- package/dist/service/session-command-service.js +125 -2
- package/dist/service/session-context-service.js +128 -2
- package/dist/service/session-domain-state.js +9 -2
- package/dist/service/session-identity-service.js +86 -2
- package/dist/service/session-lifecycle-service.js +248 -2
- package/dist/service/session-message-service.js +270 -2
- package/dist/service/session-presentation-service.js +43 -2
- package/dist/service/session-query-service.js +82 -2
- package/dist/service/session-watch-slot-coordinator.js +21 -2
- package/dist/service/skill-directory-service.js +238 -2
- package/dist/service/skill-install-service.js +434 -2
- package/dist/service/skill-node-operation-service.js +206 -2
- package/dist/service/terminal-relay-state.js +3 -2
- package/dist/service/terminal-service.js +90 -2
- package/dist/service/web-search-error.js +40 -2
- package/dist/service/workbench-event-service.js +21 -2
- package/dist/service/workbench-manifest-service.js +69 -2
- package/dist/service/workspace-change-service.js +290 -2
- package/dist/service/workspace-content-search-service.js +457 -2
- package/dist/service/workspace-domain-state.js +41 -2
- package/dist/service/workspace-file-service.js +150 -2
- package/dist/service/workspace-git-exclude-service.js +119 -2
- package/dist/service/workspace-queue-workbench-service.js +176 -2
- package/dist/service/workspace-service.js +92 -2
- package/dist/service/workspace-session-service.js +154 -2
- package/dist/service/workspace-upload-service.js +262 -2
- package/dist/service/workspace-watch-controller.js +68 -2
- package/dist/service/workspace-watch-service.js +170 -2
- package/dist/service/workspace-watch-snapshot-service.js +218 -2
- package/dist/service/workspace-workbench-service.js +239 -2
- package/dist/service.js +91 -2
- package/dist/storage.js +32 -2
- package/dist/supervisor.js +136 -2
- package/dist/terminal.js +496 -2
- package/dist/util/git-credential-client.js +32 -0
- package/dist/util/node-operation-data.js +9 -2
- package/dist/util/node-operation-parsers.js +382 -2
- package/dist/util/personal-instructions.js +34 -2
- package/dist/util/runner-error.js +70 -2
- package/dist/util/runner-native-session-parsers.js +510 -2
- package/dist/util/safe-error.js +8 -2
- package/dist/util/secret-environment.js +25 -2
- package/dist/workspace.js +1793 -2
- package/package.json +11 -8
- package/vendor/ripgrep/darwin-arm64/rg +0 -0
- package/vendor/ripgrep/darwin-x64/rg +0 -0
- package/vendor/ripgrep/manifest.json +12 -0
- package/README.md +0 -42
- package/dist/event-buffer.js +0 -2
- package/dist/migrations/v001.js +0 -107
- package/dist/migrations/v002.js +0 -2
- package/dist/migrations/v003.js +0 -2
- package/dist/service/mcp-package-installer.js +0 -2
|
@@ -1,2 +1,1982 @@
|
|
|
1
|
-
|
|
2
|
-
const _0x50efe0=_0x4c67;(function(_0x3886f1,_0x1b2366){const _0x595783=_0x4c67,_0x3b2d39=_0x3886f1();while(!![]){try{const _0x42b40c=-parseInt(_0x595783(0x22b))/(0x1*-0x24d5+-0x1*-0x587+-0x5*-0x643)*(-parseInt(_0x595783(0x1e8))/(-0x1624+0x1*-0x1edd+0x3503))+-parseInt(_0x595783(0x282))/(-0x2b*-0x9a+-0x1d2e+0x17*0x25)+-parseInt(_0x595783(0x103))/(-0x1ae6+0xa*0x251+0x140*0x3)*(parseInt(_0x595783(0x12a))/(-0xeef*-0x1+-0x8*0x2cd+0x77e))+-parseInt(_0x595783(0x17d))/(-0x14*-0x1a3+0x1*-0xe2d+0x1*-0x1289)*(-parseInt(_0x595783(0x184))/(0x570+0x1a53+0x1fbc*-0x1))+parseInt(_0x595783(0x1d5))/(0x1d6b+-0xe2*-0x9+0x13*-0x1f7)*(parseInt(_0x595783(0x18f))/(0x5*0x5f7+-0x24d7*0x1+0x169*0x5))+-parseInt(_0x595783(0x119))/(-0x1e8c+0x118c+-0x1*-0xd0a)*(-parseInt(_0x595783(0x2e3))/(-0x4*0x3c5+-0x2181+0x2*0x1850))+parseInt(_0x595783(0x1ad))/(-0x9a6+0x2274+-0x18c2)*(-parseInt(_0x595783(0x161))/(-0x4b*-0x2+0x180*-0x8+-0x24b*-0x5));if(_0x42b40c===_0x1b2366)break;else _0x3b2d39['push'](_0x3b2d39['shift']());}catch(_0xaa9c1d){_0x3b2d39['push'](_0x3b2d39['shift']());}}}(_0x590c,-0x11696f+0xc9539+-0x64252*-0x3));import{createHash,randomUUID}from'node:crypto';import{constants}from'node:fs';import{lstat,mkdir,open,readFile,rename,rm,utimes}from'node:fs/promises';import{isAbsolute,join,relative,resolve,sep}from'node:path';import{conversationTurnSchema,conversationTemplateDraftSchema,conversationTemplateSummarySchema,hostedConversationConfigUpdateInputSchema,hostedConversationCreateInputSchema,hostedConversationDeleteResultSchema,hostedConversationFileDeleteInputSchema,hostedConversationFileDeleteResultSchema,hostedConversationFileReadInputSchema,hostedConversationFileReadResultSchema,hostedConversationFilesSchema,hostedConversationIdInputSchema,hostedConversationImageReadInputSchema,hostedConversationListInputSchema,hostedConversationListPageSchema,hostedConversationMessageInputSchema,hostedConversationMetadataUpdateInputSchema,hostedConversationRollbackInputSchema,hostedConversationSnapshotSchema,hostedConversationSummarySchema,hostedConversationUnwatchInputSchema,hostedConversationUploadChunkInputSchema,hostedConversationUploadControlInputSchema,hostedConversationUploadCreateInputSchema,hostedConversationUploadPreflightInputSchema,hostedConversationUploadPreflightResultSchema,hostedConversationUploadSchema,hostedConversationWatchInputSchema,marAgentRuntimeModelConfigurationSchema,mcpInstallationConfigurationSchema,mcpRuntimeDescriptorSchema,resolveMarAgentDefaultReasoningEffort}from'@myagentroam/protocol';import{hostedConversationGeneratedImagesDisplayDirectory,hostedConversationImageRunId,marAgentGeneratedImagesDirectory}from'../runner/mar-agent/generated-images.js';import{sessionTitleFromFirstMessage}from'../util/node-operation-parsers.js';import{safeErrorCode}from'../util/safe-error.js';import{SessionWatchSlotCoordinator}from'./session-watch-slot-coordinator.js';const DEFAULT_HOSTED_CONVERSATION_TITLE=_0x50efe0(0x1e1),HOST_POLICY_VERSION=-0x1881+0x2*0x87b+0x78c,MAX_FILE_READ_BYTES=(-0xb*0x2ed+0x181d+0xa12*0x1)*(0x273+0x59*-0x53+0x1c*0x116),WATCH_TTL_MS=0xa081*0x2+0x2ba*0x61+-0x199b4,RUNTIME_LINK_ROOTS=[_0x50efe0(0x254),_0x50efe0(0x2c0),_0x50efe0(0x193),_0x50efe0(0x1ff),_0x50efe0(0x1f3)],RESERVED_SANDBOX_ROOTS=[_0x50efe0(0x262),_0x50efe0(0x261),_0x50efe0(0x223),_0x50efe0(0x254),_0x50efe0(0x2c0),_0x50efe0(0x193),_0x50efe0(0x1ff),_0x50efe0(0x1f3),_0x50efe0(0x106),_0x50efe0(0x265),_0x50efe0(0x11a),_0x50efe0(0x230)];export class HostedConversationNodeService{[_0x50efe0(0x2ba)];[_0x50efe0(0x109)];['id'];[_0x50efe0(0x162)]=new Map();[_0x50efe0(0x12d)]=new Map();[_0x50efe0(0x14a)]=new Map();[_0x50efe0(0x122)]=new Map();[_0x50efe0(0x2ad)]=new Map();[_0x50efe0(0x2c4)]=new Set();[_0x50efe0(0x166)]=new Map();[_0x50efe0(0x20e)]=new Map();[_0x50efe0(0x200)]=new Set();[_0x50efe0(0x26a)]=new Map();[_0x50efe0(0x13d)]=new Set();[_0x50efe0(0x1cc)]=new Map();[_0x50efe0(0x2af)]=new Map();[_0x50efe0(0x2d8)];[_0x50efe0(0x1c1)]=![];[_0x50efe0(0x2a1)]=0x1*-0x1e73+-0x2e1*-0x8+0x76b;[_0x50efe0(0x2ca)]=-0x1*-0x4c9+-0x26cb+-0x1*-0x2202;constructor(_0x470dda){const _0x42b02c=_0x50efe0;this[_0x42b02c(0x2ba)]=_0x470dda,this[_0x42b02c(0x109)]=_0x470dda[_0x42b02c(0x109)]??Date[_0x42b02c(0x109)],this['id']=_0x470dda['id']??randomUUID,this[_0x42b02c(0x2d8)]=_0x470dda[_0x42b02c(0x2d8)]??new SessionWatchSlotCoordinator();}[_0x50efe0(0x1dd)](){const _0x126f73=_0x50efe0;return{'conversation.hosted.list':_0x203e3a=>this[_0x126f73(0x2b4)](_0x203e3a),'conversation.hosted.create':_0x27f946=>this[_0x126f73(0x1b5)](_0x27f946),'conversation.hosted.get':_0x1f273a=>this[_0x126f73(0x1a1)](_0x1f273a),'conversation.hosted.watch':_0x5f3904=>this[_0x126f73(0x10e)](_0x5f3904),'conversation.hosted.unwatch':_0x3838ad=>this[_0x126f73(0x1b8)](_0x3838ad),'conversation.hosted.message':_0xf285aa=>this[_0x126f73(0x242)](_0xf285aa),'conversation.hosted.rollback':_0x2e3b27=>this[_0x126f73(0x1b6)](_0x2e3b27),'conversation.hosted.interrupt':_0x4a4ed7=>this[_0x126f73(0x130)](_0x4a4ed7),'conversation.hosted.config.update':_0x6ccc1b=>this[_0x126f73(0x297)](_0x6ccc1b),'conversation.hosted.metadata.update':_0x4fecd3=>this[_0x126f73(0x2b5)](_0x4fecd3),'conversation.hosted.image.read':_0x5e0203=>this[_0x126f73(0x229)](_0x5e0203),'conversation.hosted.files.list':_0x4ec157=>this[_0x126f73(0x14b)](_0x4ec157),'conversation.hosted.file.read':_0x3e0285=>this[_0x126f73(0x15b)](_0x3e0285),'conversation.hosted.file.delete':_0x40a8dc=>this[_0x126f73(0x255)](_0x40a8dc),'conversation.hosted.files.upload.preflight':_0x370935=>this[_0x126f73(0x21e)](_0x370935),'conversation.hosted.files.upload.create':_0x12d1b6=>this[_0x126f73(0x1cd)](_0x12d1b6),'conversation.hosted.files.upload.chunk':_0x3ce709=>this[_0x126f73(0x115)](_0x3ce709),'conversation.hosted.files.upload.status':_0x45ceb7=>this[_0x126f73(0x249)](_0x45ceb7),'conversation.hosted.files.upload.complete':_0x1562d6=>this[_0x126f73(0x283)](_0x1562d6),'conversation.hosted.files.upload.cancel':_0x25caa3=>this[_0x126f73(0x12f)](_0x25caa3),'conversation.hosted.delete':_0xa45100=>this[_0x126f73(0x289)](_0xa45100)};}[_0x50efe0(0x154)](){const _0x4adf88=_0x50efe0;if(this[_0x4adf88(0x1c1)]||this[_0x4adf88(0x12d)][_0x4adf88(0x293)]>-0xf20+0x17f3+-0x1*0x8d3||this[_0x4adf88(0x14a)][_0x4adf88(0x293)]>0x11db*-0x1+-0xe67+0x2042||this[_0x4adf88(0x122)][_0x4adf88(0x293)]>-0x11b5*0x1+0xe9f+-0xa*-0x4f||this[_0x4adf88(0x1cc)][_0x4adf88(0x293)]>0xb2d*-0x1+-0x1d0c+0x2839)return undefined;return this[_0x4adf88(0x1c1)]=!![],()=>{const _0x3c57bc=_0x4adf88;this[_0x3c57bc(0x1c1)]=![];};}[_0x50efe0(0x2b4)](_0x2edb98){const _0x267dd8=_0x50efe0,_0x3122c1=hostedRequest(_0x2edb98),_0x1a50f0=hostedConversationListInputSchema[_0x267dd8(0x12b)](_0x3122c1[_0x267dd8(0x217)]),_0x47e5b8=this[_0x267dd8(0x2ba)][_0x267dd8(0x239)][_0x267dd8(0x2b7)]({'userId':_0x3122c1[_0x267dd8(0x267)],'limit':_0x1a50f0[_0x267dd8(0x11e)],..._0x1a50f0[_0x267dd8(0x23e)]===undefined?{}:{'cursor':_0x1a50f0[_0x267dd8(0x23e)]}});return hostedConversationListPageSchema[_0x267dd8(0x12b)]({..._0x47e5b8,'items':_0x47e5b8[_0x267dd8(0x21a)][_0x267dd8(0x158)](_0x125452=>({..._0x125452,'activity':this[_0x267dd8(0x1e3)](_0x125452['id'])}))});}[_0x50efe0(0x1b5)](_0x1d902e){const _0x1e003f=_0x50efe0;if(this[_0x1e003f(0x1c1)])return Promise[_0x1e003f(0x1b7)](new Error(_0x1e003f(0x29f)));const _0x2696ac=hostedRequest(_0x1d902e),_0xe1daee=hostedConversationCreateInputSchema[_0x1e003f(0x12b)](_0x2696ac[_0x1e003f(0x217)]),_0x27befe=conversationTemplateSummarySchema[_0x1e003f(0x12b)](_0x2696ac[_0x1e003f(0x2bf)]),_0x1ead2c=runtimeModels(_0x2696ac[_0x1e003f(0x174)]);if(_0x27befe['id']!==_0xe1daee[_0x1e003f(0x251)]||_0x27befe[_0x1e003f(0x269)]!==this[_0x1e003f(0x2ba)][_0x1e003f(0x269)]()||!_0x27befe[_0x1e003f(0x1a7)]||_0x27befe[_0x1e003f(0x24e)]!==_0x1e003f(0x10d)||_0x27befe[_0x1e003f(0x102)]===null)throw new Error(_0x1e003f(0x227));const _0x3f3711=_0x2696ac[_0x1e003f(0x267)]+'\x00'+_0xe1daee[_0x1e003f(0x296)],_0x3d326c=this[_0x1e003f(0x162)][_0x1e003f(0x1a1)](_0x3f3711);if(_0x3d326c!==undefined)return _0x3d326c;const _0x451c92=this[_0x1e003f(0x2ba)][_0x1e003f(0x239)][_0x1e003f(0x1b3)](_0x2696ac[_0x1e003f(0x267)],_0xe1daee[_0x1e003f(0x296)]);if(_0x451c92!==undefined)return this[_0x1e003f(0x1da)](_0x2696ac[_0x1e003f(0x267)],_0x451c92['id'],_0x1ead2c);const _0x39e53f=this[_0x1e003f(0x2d4)](_0x2696ac[_0x1e003f(0x267)],_0xe1daee[_0x1e003f(0x296)],_0x27befe,_0x1ead2c,_0x2696ac[_0x1e003f(0x191)]);return this[_0x1e003f(0x162)][_0x1e003f(0x1a3)](_0x3f3711,_0x39e53f),void _0x39e53f[_0x1e003f(0x15c)](()=>this[_0x1e003f(0x162)][_0x1e003f(0x289)](_0x3f3711))[_0x1e003f(0x22e)](()=>undefined),_0x39e53f;}async[_0x50efe0(0x2d4)](_0x6696c6,_0x48376e,_0x2455f6,_0x177368,_0xaf4956){const _0x4c995d=_0x50efe0;await this[_0x4c995d(0x2ba)][_0x4c995d(0x29e)]?.();const _0x5b3dc5=await this[_0x4c995d(0x15f)](_0x2455f6[_0x4c995d(0x102)],_0x2455f6['id']),_0x44d503=selectModel(_0x5b3dc5,_0x177368,_0x5b3dc5[_0x4c995d(0x26e)][_0x4c995d(0x2a6)]),_0x2a6a50=this['id'](),_0x94c931=await this[_0x4c995d(0x2ba)][_0x4c995d(0x239)][_0x4c995d(0x238)](_0x6696c6,_0x2a6a50),_0x24a914=this[_0x4c995d(0x1bf)](_0x94c931[_0x4c995d(0x2d5)],_0x5b3dc5),_0x12bcf9=this[_0x4c995d(0x234)](_0x94c931[_0x4c995d(0x2d5)],_0x5b3dc5);let _0x55d136;try{const _0x1d3a93=await this[_0x4c995d(0x2ba)][_0x4c995d(0x189)][_0x4c995d(0x195)]({'conversationId':_0x2a6a50,'homeDirectory':_0x94c931[_0x4c995d(0x2d5)][_0x4c995d(0x252)],'workspaceDirectory':_0x5b3dc5[_0x4c995d(0x155)],'systemInstruction':systemInstruction(_0x5b3dc5),'defaultModelId':_0x44d503['id'],'models':networkModels(allowedModels(_0x5b3dc5,_0x177368),_0x5b3dc5[_0x4c995d(0x1f6)][_0x4c995d(0x1aa)]),..._0xaf4956===undefined?{}:{'runtimeScopeId':_0xaf4956},'pathMounts':_0x24a914,'processExecutor':_0x12bcf9});_0x55d136=_0x1d3a93[_0x4c995d(0x17a)];const _0x4954e0=this[_0x4c995d(0x109)](),_0x41628b={'id':_0x2a6a50,'nodeId':this[_0x4c995d(0x2ba)][_0x4c995d(0x269)](),'sessionId':_0x55d136,'templateId':_0x2455f6['id'],'templateName':_0x2455f6[_0x4c995d(0x1eb)],'activeVersionId':_0x5b3dc5['id'],'title':DEFAULT_HOSTED_CONVERSATION_TITLE,'titleSource':_0x4c995d(0x17e),'pinnedAt':null,'status':_0x4c995d(0x10d),'modelId':_0x44d503['id'],'createdAt':_0x4954e0,'updatedAt':_0x4954e0,'lastActivityAt':_0x4954e0,'userStorageKey':_0x94c931[_0x4c995d(0x2c9)],'conversationStorageKey':_0x94c931[_0x4c995d(0x24a)],'clientRequestId':_0x48376e,'templateDeleted':![],'quota':{'usedBytes':0x0,'maxBytes':_0x5b3dc5[_0x4c995d(0x1f6)][_0x4c995d(0x2a0)][_0x4c995d(0x1f2)]}},_0x4a4d35=await this[_0x4c995d(0x2ba)][_0x4c995d(0x239)][_0x4c995d(0x2d4)](_0x41628b);return _0x4a4d35['id']!==_0x2a6a50&&(await this[_0x4c995d(0x2ba)][_0x4c995d(0x189)][_0x4c995d(0x1e5)]({'conversationId':_0x2a6a50,'sessionId':_0x55d136,'homeDirectory':_0x94c931[_0x4c995d(0x2d5)][_0x4c995d(0x252)]})[_0x4c995d(0x22e)](()=>undefined),await rm(_0x94c931[_0x4c995d(0x2d5)][_0x4c995d(0x124)],{'recursive':!![],'force':!![]})),this[_0x4c995d(0x1da)](_0x6696c6,_0x4a4d35['id'],_0x177368);}catch(_0x34afbc){if(_0x55d136!==undefined)await this[_0x4c995d(0x2ba)][_0x4c995d(0x189)][_0x4c995d(0x1e5)]({'conversationId':_0x2a6a50,'sessionId':_0x55d136,'homeDirectory':_0x94c931[_0x4c995d(0x2d5)][_0x4c995d(0x252)]})[_0x4c995d(0x22e)](()=>undefined);await rm(_0x94c931[_0x4c995d(0x2d5)][_0x4c995d(0x124)],{'recursive':!![],'force':!![]})[_0x4c995d(0x22e)](()=>undefined);throw _0x34afbc;}}async[_0x50efe0(0x1a1)](_0xb306a5){const _0x3753eb=_0x50efe0,_0x403b96=hostedRequest(_0xb306a5),_0x596e59=hostedConversationIdInputSchema[_0x3753eb(0x12b)](_0x403b96[_0x3753eb(0x217)]);return this[_0x3753eb(0x1da)](_0x403b96[_0x3753eb(0x267)],_0x596e59[_0x3753eb(0x20a)],runtimeModels(_0x403b96[_0x3753eb(0x174)]),_0x403b96[_0x3753eb(0x270)]);}async[_0x50efe0(0x1da)](_0x5b19eb,_0x461148,_0x500b8f,_0xc3197e=![],_0xf15224=![],_0x3c3edd){const _0x3686b9=_0x50efe0;if(_0xf15224)return this[_0x3686b9(0x1d1)](_0x5b19eb,_0x461148,_0x500b8f,_0xc3197e,_0x3c3edd);while(!![]){const _0xb562cb=this[_0x3686b9(0x2af)][_0x3686b9(0x1a1)](_0x461148)??-0xb13+0x37f*-0xa+0x2e09,_0x520802=this[_0x3686b9(0x1cc)][_0x3686b9(0x1a1)](_0x461148);if(_0x520802!==undefined){await _0x520802[_0x3686b9(0x22e)](()=>undefined);continue;}const _0xcac22c=await this[_0x3686b9(0x1d1)](_0x5b19eb,_0x461148,_0x500b8f,_0xc3197e);if(!this[_0x3686b9(0x1cc)][_0x3686b9(0x23c)](_0x461148)&&(this[_0x3686b9(0x2af)][_0x3686b9(0x1a1)](_0x461148)??0x181+-0x1f*0x59+-0x4a3*-0x2)===_0xb562cb)return _0xcac22c;}}async[_0x50efe0(0x1d1)](_0x19625a,_0x1c006a,_0x284528,_0x1753e9,_0x36a659){const _0x3d6776=_0x50efe0;let _0x2b3ae3=this[_0x3d6776(0x2ba)][_0x3d6776(0x239)][_0x3d6776(0x2be)](_0x19625a,_0x1c006a);if(_0x1753e9)_0x2b3ae3=await this[_0x3d6776(0x2ba)][_0x3d6776(0x239)][_0x3d6776(0x29d)](_0x19625a,_0x1c006a,this[_0x3d6776(0x109)]());const _0x16fed8=_0x2b3ae3[_0x3d6776(0x270)]?undefined:this[_0x3d6776(0x259)](_0x2b3ae3[_0x3d6776(0x251)]),_0x355bf2=_0x16fed8??_0x2b3ae3[_0x3d6776(0x2b9)],_0x20baf4=await this[_0x3d6776(0x15f)](_0x355bf2,_0x2b3ae3[_0x3d6776(0x251)]),_0x537b7b=networkModels(allowedModels(_0x20baf4,_0x284528),_0x20baf4[_0x3d6776(0x1f6)][_0x3d6776(0x1aa)]),_0x710c63=this[_0x3d6776(0x2ba)][_0x3d6776(0x239)][_0x3d6776(0x23f)](_0x19625a,_0x2b3ae3['id']),_0x43442d=_0x36a659??await this[_0x3d6776(0x2ba)][_0x3d6776(0x189)][_0x3d6776(0x1d2)]({'conversationId':_0x2b3ae3['id'],'sessionId':_0x2b3ae3[_0x3d6776(0x17a)],'homeDirectory':_0x710c63[_0x3d6776(0x252)],'modelId':_0x2b3ae3[_0x3d6776(0x185)]});return hostedConversationSnapshotSchema[_0x3d6776(0x12b)]({'nodeAppVersion':this[_0x3d6776(0x2ba)][_0x3d6776(0x2dc)]?.()??_0x3d6776(0x260),'conversation':this[_0x3d6776(0x2bd)](_0x2b3ae3),'template':templateSummary(_0x2b3ae3,_0x20baf4[_0x3d6776(0x1f6)]),'run':this[_0x3d6776(0x14a)][_0x3d6776(0x1a1)](_0x2b3ae3['id'])?.[_0x3d6776(0x20f)]??null,'turns':_0x43442d,'files':this[_0x3d6776(0x2ba)][_0x3d6776(0x239)][_0x3d6776(0x14b)](_0x19625a,_0x2b3ae3['id']),'models':_0x537b7b[_0x3d6776(0x158)](modelSummary),'error':null,'snapshotSequence':0x0});}async[_0x50efe0(0x10e)](_0x3976b2){const _0x254d85=_0x50efe0,_0x29ca6a=hostedRequest(_0x3976b2),_0x473810=hostedConversationWatchInputSchema[_0x254d85(0x12b)](_0x29ca6a[_0x254d85(0x217)]),_0x40f97e=this[_0x254d85(0x2ba)][_0x254d85(0x239)][_0x254d85(0x2be)](_0x29ca6a[_0x254d85(0x267)],_0x473810[_0x254d85(0x20a)]);if(this[_0x254d85(0x13d)][_0x254d85(0x23c)](_0x40f97e['id']))throw new Error(_0x254d85(0x21d));const _0x5197c5=requireWatchSessionHash(_0x29ca6a[_0x254d85(0x202)]),_0x34fc33=watchOwnerKey(_0x5197c5,_0x473810[_0x254d85(0x187)]);if(_0x473810[_0x254d85(0x146)]===_0x254d85(0x190)){const _0x22a363=this[_0x254d85(0x26a)][_0x254d85(0x1a1)](_0x34fc33);if(_0x22a363===undefined||!this[_0x254d85(0x2d8)][_0x254d85(0x257)](_0x34fc33,_0x22a363[_0x254d85(0x204)])||_0x22a363[_0x254d85(0x21b)]!==_0x473810[_0x254d85(0x21b)]||_0x22a363[_0x254d85(0x20a)]!==_0x473810[_0x254d85(0x20a)]||_0x22a363[_0x254d85(0x267)]!==_0x29ca6a[_0x254d85(0x267)]||_0x22a363[_0x254d85(0x2b6)]<=Date[_0x254d85(0x109)]()){this[_0x254d85(0x196)](_0x34fc33);throw new Error(_0x254d85(0x117));}return _0x22a363[_0x254d85(0x2b6)]=Date[_0x254d85(0x109)]()+WATCH_TTL_MS,clearTimeout(_0x22a363[_0x254d85(0x172)]),_0x22a363[_0x254d85(0x172)]=this[_0x254d85(0x13b)](_0x34fc33),this[_0x254d85(0x248)](_0x22a363);}const _0x52ef6e=runtimeModels(_0x29ca6a[_0x254d85(0x174)]),_0x5d8dba=this[_0x254d85(0x26a)][_0x254d85(0x1a1)](_0x34fc33);if(_0x5d8dba!==undefined&&this[_0x254d85(0x2d8)][_0x254d85(0x257)](_0x34fc33,_0x5d8dba[_0x254d85(0x204)])&&_0x5d8dba[_0x254d85(0x21b)]===_0x473810[_0x254d85(0x21b)]&&_0x5d8dba[_0x254d85(0x20a)]===_0x473810[_0x254d85(0x20a)]&&_0x5d8dba[_0x254d85(0x267)]===_0x29ca6a[_0x254d85(0x267)]&&_0x5d8dba[_0x254d85(0x2b6)]>Date[_0x254d85(0x109)]())return _0x5d8dba[_0x254d85(0x2b6)]=Date[_0x254d85(0x109)]()+WATCH_TTL_MS,clearTimeout(_0x5d8dba[_0x254d85(0x172)]),_0x5d8dba[_0x254d85(0x172)]=this[_0x254d85(0x13b)](_0x34fc33),this[_0x254d85(0x248)](_0x5d8dba);this[_0x254d85(0x196)](_0x34fc33);const _0x197d87=this[_0x254d85(0x2d8)][_0x254d85(0x120)](_0x34fc33,_0x254d85(0x1ae),()=>this[_0x254d85(0x196)](_0x34fc33)),_0x111fe7={'ownerKey':_0x34fc33,'slotToken':_0x197d87,'sessionHash':_0x5197c5,'workbenchConnectionId':_0x473810[_0x254d85(0x187)],'watchId':_0x473810[_0x254d85(0x21b)],'conversationId':_0x473810[_0x254d85(0x20a)],'templateId':_0x40f97e[_0x254d85(0x251)],'userId':_0x29ca6a[_0x254d85(0x267)],'models':_0x52ef6e,'nodeGeneration':this[_0x254d85(0x2ba)][_0x254d85(0x1c9)]?.()??_0x254d85(0x2b8),'pendingEvents':[],'expiresAt':Date[_0x254d85(0x109)]()+WATCH_TTL_MS,'ready':![],'timer':undefined};return _0x111fe7[_0x254d85(0x172)]=this[_0x254d85(0x13b)](_0x34fc33),this[_0x254d85(0x26a)][_0x254d85(0x1a3)](_0x34fc33,_0x111fe7),void this[_0x254d85(0x2c6)](_0x111fe7),this[_0x254d85(0x248)](_0x111fe7);}[_0x50efe0(0x1b8)](_0x1ceaac){const _0x1aa9fc=_0x50efe0,_0x4a6b22=hostedRequest(_0x1ceaac),_0xca6daf=hostedConversationUnwatchInputSchema[_0x1aa9fc(0x12b)](_0x4a6b22[_0x1aa9fc(0x217)]);this[_0x1aa9fc(0x2ba)][_0x1aa9fc(0x239)][_0x1aa9fc(0x2be)](_0x4a6b22[_0x1aa9fc(0x267)],_0xca6daf[_0x1aa9fc(0x20a)]);const _0x7a99ff=watchOwnerKey(requireWatchSessionHash(_0x4a6b22[_0x1aa9fc(0x202)]),_0xca6daf[_0x1aa9fc(0x187)]),_0x3f8640=this[_0x1aa9fc(0x26a)][_0x1aa9fc(0x1a1)](_0x7a99ff);if(_0x3f8640?.[_0x1aa9fc(0x21b)]===_0xca6daf[_0x1aa9fc(0x21b)]&&_0x3f8640[_0x1aa9fc(0x20a)]===_0xca6daf[_0x1aa9fc(0x20a)]&&_0x3f8640[_0x1aa9fc(0x267)]===_0x4a6b22[_0x1aa9fc(0x267)])this[_0x1aa9fc(0x196)](_0x7a99ff);return{'unwatched':!![]};}[_0x50efe0(0x15a)](_0x25d55d,_0x40613e){const _0x3d7a93=_0x50efe0;return this[_0x3d7a93(0x160)](_0x25d55d,{'conversationId':_0x25d55d,'kind':_0x3d7a93(0x189),'runtimeEvent':_0x40613e});}[_0x50efe0(0x291)](_0x4c69e8){const _0x218e26=_0x50efe0;return this[_0x218e26(0x13d)][_0x218e26(0x23c)](_0x4c69e8)||this[_0x218e26(0x1cc)][_0x218e26(0x23c)](_0x4c69e8)||this[_0x218e26(0x14a)][_0x218e26(0x23c)](_0x4c69e8)||this[_0x218e26(0x122)][_0x218e26(0x23c)](_0x4c69e8)||[...this[_0x218e26(0x26a)][_0x218e26(0x272)]()][_0x218e26(0x14f)](_0x33d1cf=>_0x33d1cf[_0x218e26(0x20a)]===_0x4c69e8)||[...this[_0x218e26(0x166)][_0x218e26(0x272)]()][_0x218e26(0x14f)](_0x5119c9=>_0x5119c9[_0x218e26(0x20a)]===_0x4c69e8&&_0x5119c9[_0x218e26(0x24e)]===_0x218e26(0x105))||[...this[_0x218e26(0x12d)][_0x218e26(0x263)]()][_0x218e26(0x14f)](_0x239a14=>_0x239a14[_0x218e26(0x2ac)](_0x4c69e8+'\x00'));}[_0x50efe0(0x2b3)](_0x26376a){const _0x486dd8=_0x50efe0;if(this[_0x486dd8(0x291)](_0x26376a))return undefined;return this[_0x486dd8(0x13d)][_0x486dd8(0x287)](_0x26376a),()=>{const _0x486836=_0x486dd8;this[_0x486836(0x13d)][_0x486836(0x289)](_0x26376a);};}async[_0x50efe0(0x107)](_0x237a95){const _0x58a3f8=_0x50efe0,_0x5278c5=this[_0x58a3f8(0x2ba)][_0x58a3f8(0x239)][_0x58a3f8(0x16f)](_0x237a95);await this[_0x58a3f8(0x2ba)][_0x58a3f8(0x189)][_0x58a3f8(0x1e5)]({'conversationId':_0x237a95['id'],'sessionId':_0x237a95[_0x58a3f8(0x17a)],'homeDirectory':_0x5278c5[_0x58a3f8(0x252)]})[_0x58a3f8(0x22e)](()=>undefined);}[_0x50efe0(0x144)](){const _0x19d4ae=_0x50efe0;for(const [_0x25212e,_0x59429d]of this[_0x19d4ae(0x14a)]){const _0x5690fc=runInterruptionKey(_0x25212e,_0x59429d[_0x19d4ae(0x20f)]['id']);this[_0x19d4ae(0x2c4)][_0x19d4ae(0x287)](_0x5690fc);if(!_0x59429d[_0x19d4ae(0x16c)]())this[_0x19d4ae(0x2c4)][_0x19d4ae(0x289)](_0x5690fc);}for(const _0x18ff06 of[...this[_0x19d4ae(0x26a)][_0x19d4ae(0x263)]()])this[_0x19d4ae(0x196)](_0x18ff06);}[_0x50efe0(0x242)](_0x125d66){const _0x42a48f=_0x50efe0;if(this[_0x42a48f(0x1c1)])return Promise[_0x42a48f(0x1b7)](new Error(_0x42a48f(0x29f)));const _0x501321=hostedRequest(_0x125d66),_0x20ce4d=hostedConversationMessageInputSchema[_0x42a48f(0x12b)](_0x501321[_0x42a48f(0x217)]);if(this[_0x42a48f(0x1cc)][_0x42a48f(0x23c)](_0x20ce4d[_0x42a48f(0x20a)]))return Promise[_0x42a48f(0x1b7)](new Error(_0x42a48f(0x21d)));const _0x257d8d=_0x20ce4d[_0x42a48f(0x20a)]+'\x00'+_0x20ce4d[_0x42a48f(0x141)],_0x432512=this[_0x42a48f(0x12d)][_0x42a48f(0x1a1)](_0x257d8d);if(_0x432512!==undefined)return _0x432512;const _0x3b7835=this[_0x42a48f(0x2ba)][_0x42a48f(0x239)][_0x42a48f(0x2da)](_0x501321[_0x42a48f(0x267)],_0x20ce4d[_0x42a48f(0x20a)],_0x20ce4d[_0x42a48f(0x141)]);if(_0x3b7835!==undefined){const _0x25e5a3=this[_0x42a48f(0x2ba)][_0x42a48f(0x239)][_0x42a48f(0x2be)](_0x501321[_0x42a48f(0x267)],_0x20ce4d[_0x42a48f(0x20a)]);return Promise[_0x42a48f(0x208)]({'conversation':this[_0x42a48f(0x2bd)](_0x25e5a3),'run':runFromMessage(_0x3b7835)});}if([...this[_0x42a48f(0x12d)][_0x42a48f(0x263)]()][_0x42a48f(0x14f)](_0x3c23dc=>_0x3c23dc[_0x42a48f(0x2ac)](_0x20ce4d[_0x42a48f(0x20a)]+'\x00')))return Promise[_0x42a48f(0x1b7)](new Error(_0x42a48f(0x235)));const _0x2ab54d=this[_0x42a48f(0x24b)](_0x501321,_0x20ce4d);return this[_0x42a48f(0x12d)][_0x42a48f(0x1a3)](_0x257d8d,_0x2ab54d),void _0x2ab54d[_0x42a48f(0x15c)](()=>this[_0x42a48f(0x12d)][_0x42a48f(0x289)](_0x257d8d))[_0x42a48f(0x22e)](()=>undefined),_0x2ab54d;}async[_0x50efe0(0x24b)](_0x19cc39,_0x43b827){const _0x212b6a=_0x50efe0;let _0xd7af8f=this[_0x212b6a(0x2ba)][_0x212b6a(0x239)][_0x212b6a(0x2be)](_0x19cc39[_0x212b6a(0x267)],_0x43b827[_0x212b6a(0x20a)]);if(this[_0x212b6a(0x13d)][_0x212b6a(0x23c)](_0xd7af8f['id']))throw new Error(_0x212b6a(0x21d));if(this[_0x212b6a(0x1cc)][_0x212b6a(0x23c)](_0xd7af8f['id']))throw new Error(_0x212b6a(0x21d));if(_0xd7af8f[_0x212b6a(0x24e)]!==_0x212b6a(0x10d))throw new Error(_0x212b6a(0x21d));if(this[_0x212b6a(0x14a)][_0x212b6a(0x23c)](_0xd7af8f['id']))throw new Error(_0x212b6a(0x235));const _0x519119=sessionTitleFromFirstMessage(_0x43b827[_0x212b6a(0x188)]),_0x24d819=_0x519119[_0x212b6a(0x26b)]>0xda4+0x622+-0x13c6&&!this[_0x212b6a(0x2ba)][_0x212b6a(0x239)][_0x212b6a(0x26c)](_0x19cc39[_0x212b6a(0x267)],_0xd7af8f['id']),_0xff6677=runtimeModels(_0x19cc39[_0x212b6a(0x174)]),_0x4a6fae=this[_0x212b6a(0x2ba)][_0x212b6a(0x239)][_0x212b6a(0x23f)](_0x19cc39[_0x212b6a(0x267)],_0xd7af8f['id']);let _0x5a8191,_0x34ab8b,_0x4ce054,_0x1dfcdd;const _0x1d17de=_0xd7af8f[_0x212b6a(0x270)]?undefined:this[_0x212b6a(0x259)](_0xd7af8f[_0x212b6a(0x251)]);if(_0x1d17de!==undefined&&_0x1d17de!==_0xd7af8f[_0x212b6a(0x2b9)]){const _0x798ee9=_0xd7af8f[_0x212b6a(0x2b9)],_0x5c21fa=_0x1d17de;try{_0x5a8191=await this[_0x212b6a(0x15f)](_0x5c21fa,_0xd7af8f[_0x212b6a(0x251)]),_0x34ab8b=selectModel(_0x5a8191,_0xff6677,_0x43b827[_0x212b6a(0x185)]??_0x5a8191[_0x212b6a(0x26e)][_0x212b6a(0x2a6)]),_0x4ce054=resolveMcpServers(_0x5a8191,this[_0x212b6a(0x2ba)][_0x212b6a(0x1a4)]??process.env),this[_0x212b6a(0x1bf)](_0x4a6fae,_0x5a8191),this[_0x212b6a(0x234)](_0x4a6fae,_0x5a8191),_0x1dfcdd={'previousVersionId':_0x798ee9,'targetVersionId':_0x5c21fa};}catch(_0x1f119e){this[_0x212b6a(0x2d6)](_0xd7af8f,_0x798ee9,_0x5c21fa,_0x1f119e);throw new Error(_0x212b6a(0x1db));}}else _0x5a8191=await this[_0x212b6a(0x15f)](_0xd7af8f[_0x212b6a(0x2b9)],_0xd7af8f[_0x212b6a(0x251)]),_0x34ab8b=selectModel(_0x5a8191,_0xff6677,_0x43b827[_0x212b6a(0x185)]??_0xd7af8f[_0x212b6a(0x185)]);const _0x1a606f=await Promise[_0x212b6a(0x219)](_0x43b827[_0x212b6a(0x264)][_0x212b6a(0x158)](_0x14dc0e=>this[_0x212b6a(0x108)](_0x19cc39[_0x212b6a(0x267)],_0xd7af8f['id'],_0x14dc0e))),_0x33fc1c=attachmentPrompt(_0x43b827[_0x212b6a(0x188)],_0x1a606f),_0x4f7122=marAgentGeneratedImagesDirectory(_0x4a6fae[_0x212b6a(0x252)],_0xd7af8f[_0x212b6a(0x17a)]),_0xb5c18a=hostedConversationGeneratedImagesDisplayDirectory(_0xd7af8f[_0x212b6a(0x17a)]);if(_0x4f7122===undefined||_0xb5c18a===undefined)throw new Error(_0x212b6a(0x18b));await mkdir(_0x4f7122,{'recursive':!![],'mode':0x1c0});const _0x42386e=await this[_0x212b6a(0x2ba)][_0x212b6a(0x239)][_0x212b6a(0x274)](_0x19cc39[_0x212b6a(0x267)],_0xd7af8f['id']),_0x50c8c4=this[_0x212b6a(0x1bf)](_0x4a6fae,_0x5a8191,_0x4f7122,_0xb5c18a,_0x42386e);this[_0x212b6a(0x1de)](_0x19cc39[_0x212b6a(0x267)],_0xd7af8f,_0x212b6a(0x153),this[_0x212b6a(0x109)]());const _0x4944b6=[];let _0x459d8f=![];const _0x23583a=await this[_0x212b6a(0x2ba)][_0x212b6a(0x189)][_0x212b6a(0x2a4)]({'conversationId':_0xd7af8f['id'],'sessionId':_0xd7af8f[_0x212b6a(0x17a)],'clientMessageId':_0x43b827[_0x212b6a(0x141)],'userPrompt':_0x43b827[_0x212b6a(0x188)],'prompt':_0x33fc1c,'attachmentIds':_0x43b827[_0x212b6a(0x264)],'access':_0x212b6a(0x1fd),'modelId':_0x34ab8b['id'],'models':networkModels(allowedModels(_0x5a8191,_0xff6677),_0x5a8191[_0x212b6a(0x1f6)][_0x212b6a(0x1aa)]),..._0x19cc39[_0x212b6a(0x191)]===undefined?{}:{'runtimeScopeId':_0x19cc39[_0x212b6a(0x191)]},'systemInstruction':systemInstruction(_0x5a8191,_0xb5c18a),'homeDirectory':_0x4a6fae[_0x212b6a(0x252)],'workspaceDirectory':_0x5a8191[_0x212b6a(0x155)],'temporaryDirectory':_0x42386e,'pathMounts':_0x50c8c4,'processExecutor':this[_0x212b6a(0x234)](_0x4a6fae,_0x5a8191,_0x42386e,_0x4f7122,_0xb5c18a),'mcpServers':_0x4ce054??resolveMcpServers(_0x5a8191,this[_0x212b6a(0x2ba)][_0x212b6a(0x1a4)]??process.env),'webAccess':_0x5a8191[_0x212b6a(0x1f6)][_0x212b6a(0x1aa)]!==_0x212b6a(0x201),'onEvent':_0x4304f1=>{const _0x13a0b6=_0x212b6a;if(_0x459d8f)this[_0x13a0b6(0x15a)](_0xd7af8f['id'],_0x4304f1);else _0x4944b6[_0x13a0b6(0x1f1)](_0x4304f1);}})[_0x212b6a(0x22e)](_0x50887a=>{const _0x3c22f9=_0x212b6a;this[_0x3c22f9(0x1de)](_0x19cc39[_0x3c22f9(0x267)],_0xd7af8f,_0x3c22f9(0x2ce),this[_0x3c22f9(0x109)]());if(_0x1dfcdd!==undefined){this[_0x3c22f9(0x2d6)](_0xd7af8f,_0x1dfcdd[_0x3c22f9(0x27a)],_0x1dfcdd[_0x3c22f9(0x10a)],_0x50887a);throw new Error(_0x3c22f9(0x1db));}throw _0x50887a;}),_0x1f9bc0=_0x23583a[_0x212b6a(0x20f)][_0x212b6a(0x11c)];let _0xcff2a2=![],_0x71d646;try{this[_0x212b6a(0x2ba)][_0x212b6a(0x239)][_0x212b6a(0x1fe)]({'conversationId':_0xd7af8f['id'],'clientMessageId':_0x43b827[_0x212b6a(0x141)],'runId':_0x23583a[_0x212b6a(0x20f)]['id'],'userTextPresent':_0x519119[_0x212b6a(0x26b)]>0x1b09*-0x1+0x1*-0x1003+0x26*0x122,'status':_0x212b6a(0x24c),'createdAt':_0x1f9bc0,'updatedAt':_0x1f9bc0}),_0xcff2a2=!![];const _0x5520d9=this[_0x212b6a(0x109)]();_0x71d646=await this[_0x212b6a(0x2ba)][_0x212b6a(0x239)][_0x212b6a(0x13a)]({'conversationId':_0xd7af8f['id'],'modelId':_0x34ab8b['id'],'activityAt':_0x5520d9,..._0x1dfcdd===undefined?{}:{'templateVersion':{'expectedActiveVersionId':_0x1dfcdd[_0x212b6a(0x27a)],'activeVersionId':_0x1dfcdd[_0x212b6a(0x10a)],'maxStorageBytes':_0x5a8191[_0x212b6a(0x1f6)][_0x212b6a(0x2a0)][_0x212b6a(0x1f2)]}},..._0x24d819?{'automaticTitle':_0x519119}:{}});}catch(_0x4af311){try{_0x23583a[_0x212b6a(0x16c)]();}catch{}const _0x172ef3=await _0x23583a[_0x212b6a(0x220)][_0x212b6a(0x22e)](()=>({'status':_0x212b6a(0x1b9),'completedAt':this[_0x212b6a(0x109)]()}));if(_0xcff2a2)try{this[_0x212b6a(0x2ba)][_0x212b6a(0x239)][_0x212b6a(0x2bb)](_0xd7af8f['id'],_0x43b827[_0x212b6a(0x141)],_0x172ef3[_0x212b6a(0x24e)],_0x172ef3[_0x212b6a(0x1e6)]);}catch{}this[_0x212b6a(0x1de)](_0x19cc39[_0x212b6a(0x267)],_0xd7af8f,_0x212b6a(0x2ce),_0x172ef3[_0x212b6a(0x1e6)]);if(_0x1dfcdd!==undefined)this[_0x212b6a(0x2d6)](_0xd7af8f,_0x1dfcdd[_0x212b6a(0x27a)],_0x1dfcdd[_0x212b6a(0x10a)],_0x4af311);throw _0x4af311;}_0xd7af8f=_0x71d646[_0x212b6a(0x21c)];if(_0x1dfcdd!==undefined)this[_0x212b6a(0x160)](_0xd7af8f['id'],{'conversationId':_0xd7af8f['id'],'kind':_0x212b6a(0x280),'upgrade':{'status':_0x212b6a(0x2df),'previousVersionId':_0x1dfcdd[_0x212b6a(0x27a)],'targetVersionId':_0x1dfcdd[_0x212b6a(0x10a)],'activeVersionId':_0xd7af8f[_0x212b6a(0x2b9)],'conversation':this[_0x212b6a(0x2bd)](_0xd7af8f),'error':null}});this[_0x212b6a(0x14a)][_0x212b6a(0x1a3)](_0xd7af8f['id'],_0x23583a),this[_0x212b6a(0x1de)](_0x19cc39[_0x212b6a(0x267)],_0xd7af8f,_0x212b6a(0x24c),_0x23583a[_0x212b6a(0x20f)][_0x212b6a(0x11c)]);if(_0x71d646[_0x212b6a(0x285)])this[_0x212b6a(0x160)](_0xd7af8f['id'],{'conversationId':_0xd7af8f['id'],'kind':_0x212b6a(0x21c),'conversation':this[_0x212b6a(0x2bd)](_0xd7af8f)});this[_0x212b6a(0x160)](_0xd7af8f['id'],{'conversationId':_0xd7af8f['id'],'kind':_0x212b6a(0x20f),'run':_0x23583a[_0x212b6a(0x20f)]}),_0x459d8f=!![];for(const _0x5524a7 of _0x4944b6)this[_0x212b6a(0x15a)](_0xd7af8f['id'],_0x5524a7);_0x4944b6[_0x212b6a(0x26b)]=0x4*0x65b+-0x1670+-0x2fc;const _0xfaadef=_0x23583a[_0x212b6a(0x220)][_0x212b6a(0x288)](_0x31a852=>this[_0x212b6a(0x2c3)](_0x19cc39[_0x212b6a(0x267)],_0xd7af8f['id'],_0x43b827[_0x212b6a(0x141)],_0x23583a[_0x212b6a(0x20f)],_0x31a852),()=>this[_0x212b6a(0x2c3)](_0x19cc39[_0x212b6a(0x267)],_0xd7af8f['id'],_0x43b827[_0x212b6a(0x141)],_0x23583a[_0x212b6a(0x20f)],{'status':_0x212b6a(0x1b9),'completedAt':this[_0x212b6a(0x109)]()}))[_0x212b6a(0x22e)](()=>undefined)[_0x212b6a(0x15c)](()=>{const _0x5400cb=_0x212b6a;this[_0x5400cb(0x2c4)][_0x5400cb(0x289)](runInterruptionKey(_0xd7af8f['id'],_0x23583a[_0x5400cb(0x20f)]['id']));if(this[_0x5400cb(0x14a)][_0x5400cb(0x1a1)](_0xd7af8f['id'])===_0x23583a)this[_0x5400cb(0x14a)][_0x5400cb(0x289)](_0xd7af8f['id']);if(this[_0x5400cb(0x122)][_0x5400cb(0x1a1)](_0xd7af8f['id'])===_0xfaadef)this[_0x5400cb(0x122)][_0x5400cb(0x289)](_0xd7af8f['id']);});return this[_0x212b6a(0x122)][_0x212b6a(0x1a3)](_0xd7af8f['id'],_0xfaadef),void _0xfaadef,{'conversation':this[_0x212b6a(0x2bd)](_0xd7af8f),'run':_0x23583a[_0x212b6a(0x20f)]};}[_0x50efe0(0x1b6)](_0x1e307e){const _0x12c703=_0x50efe0;if(this[_0x12c703(0x1c1)])return Promise[_0x12c703(0x1b7)](new Error(_0x12c703(0x29f)));const _0x401adf=hostedRequest(_0x1e307e),_0x31da43=hostedConversationRollbackInputSchema[_0x12c703(0x12b)](_0x401adf[_0x12c703(0x217)]),_0x2797ee=this[_0x12c703(0x2ba)][_0x12c703(0x239)][_0x12c703(0x2be)](_0x401adf[_0x12c703(0x267)],_0x31da43[_0x12c703(0x20a)]);if(_0x2797ee[_0x12c703(0x24e)]!==_0x12c703(0x10d)||this[_0x12c703(0x13d)][_0x12c703(0x23c)](_0x2797ee['id'])||this[_0x12c703(0x1cc)][_0x12c703(0x23c)](_0x2797ee['id']))return Promise[_0x12c703(0x1b7)](new Error(_0x12c703(0x21d)));if(this[_0x12c703(0x1e3)](_0x2797ee['id'])[_0x12c703(0x24e)]!==_0x12c703(0x2ce)||this[_0x12c703(0x14a)][_0x12c703(0x23c)](_0x2797ee['id'])||this[_0x12c703(0x122)][_0x12c703(0x23c)](_0x2797ee['id'])||[...this[_0x12c703(0x12d)][_0x12c703(0x263)]()][_0x12c703(0x14f)](_0x4d9c5d=>_0x4d9c5d[_0x12c703(0x2ac)](_0x2797ee['id']+'\x00')))return Promise[_0x12c703(0x1b7)](new Error(_0x12c703(0x235)));const _0x36034b=this[_0x12c703(0x2d1)](_0x401adf,_0x2797ee,_0x31da43);return this[_0x12c703(0x1cc)][_0x12c703(0x1a3)](_0x2797ee['id'],_0x36034b),void _0x36034b[_0x12c703(0x15c)](()=>{const _0x1b4faa=_0x12c703;if(this[_0x1b4faa(0x1cc)][_0x1b4faa(0x1a1)](_0x2797ee['id'])===_0x36034b)this[_0x1b4faa(0x1cc)][_0x1b4faa(0x289)](_0x2797ee['id']);})[_0x12c703(0x22e)](()=>undefined),_0x36034b;}async[_0x50efe0(0x2d1)](_0x22d64f,_0x342b4a,_0x118323){const _0x59be9a=_0x50efe0,_0x288b4b=this[_0x59be9a(0x2ba)][_0x59be9a(0x239)][_0x59be9a(0x23f)](_0x22d64f[_0x59be9a(0x267)],_0x342b4a['id']),_0x4d1e5e=(await this[_0x59be9a(0x2ba)][_0x59be9a(0x189)][_0x59be9a(0x1d2)]({'conversationId':_0x342b4a['id'],'sessionId':_0x342b4a[_0x59be9a(0x17a)],'homeDirectory':_0x288b4b[_0x59be9a(0x252)],'modelId':_0x342b4a[_0x59be9a(0x185)]}))[_0x59be9a(0x158)](_0xf0d6cb=>conversationTurnSchema[_0x59be9a(0x12b)](_0xf0d6cb)),_0x1a75ce=_0x4d1e5e[_0x59be9a(0x132)](_0x576633=>_0x576633['id']===_0x118323[_0x59be9a(0x1be)]),_0x42d80d=_0x4d1e5e[_0x1a75ce],_0x6b0859=_0x42d80d?.[_0x59be9a(0x21a)][_0x59be9a(0x113)](_0x164b7e=>_0x164b7e[_0x59be9a(0x2a2)]===_0x59be9a(0x228)&&_0x164b7e[_0x59be9a(0x24e)]===_0x59be9a(0x27e));if(_0x42d80d===undefined||!terminalHostedTurnStatus(_0x42d80d[_0x59be9a(0x24e)])||_0x6b0859===undefined||_0x42d80d[_0x59be9a(0x1ab)]?.[_0x59be9a(0x134)]!==_0x118323[_0x59be9a(0x216)])throw new Error(_0x59be9a(0x2dd));let _0x58e6a3;try{_0x58e6a3=await this[_0x59be9a(0x2ba)][_0x59be9a(0x189)][_0x59be9a(0x1b6)]({'conversationId':_0x342b4a['id'],'sessionId':_0x342b4a[_0x59be9a(0x17a)],'homeDirectory':_0x288b4b[_0x59be9a(0x252)],'modelId':_0x342b4a[_0x59be9a(0x185)],'boundaryTurnId':_0x118323[_0x59be9a(0x216)]});}catch(_0x4884cd){if(_0x4884cd instanceof Error&&_0x4884cd[_0x59be9a(0x242)]===_0x59be9a(0x2c1))throw new Error(_0x59be9a(0x2dd),{'cause':_0x4884cd});throw _0x4884cd;}this[_0x59be9a(0x2af)][_0x59be9a(0x1a3)](_0x342b4a['id'],(this[_0x59be9a(0x2af)][_0x59be9a(0x1a1)](_0x342b4a['id'])??0xce0+-0xd90+0xb0)+(-0x1d5*-0xd+0xa3d*0x1+0x17b*-0x17)),await this[_0x59be9a(0x2ba)][_0x59be9a(0x239)][_0x59be9a(0x22a)](_0x342b4a['id'],Math[_0x59be9a(0x177)](this[_0x59be9a(0x109)](),_0x58e6a3[_0x59be9a(0x232)]));const _0x382b6b=await this[_0x59be9a(0x1da)](_0x22d64f[_0x59be9a(0x267)],_0x342b4a['id'],runtimeModels(_0x22d64f[_0x59be9a(0x174)]),_0x22d64f[_0x59be9a(0x270)],!![],_0x4d1e5e[_0x59be9a(0x1b2)](-0x7a1+0xa29*-0x3+-0x2*-0x130e,_0x1a75ce));return this[_0x59be9a(0x1ce)](_0x342b4a['id'],_0x382b6b),_0x382b6b;}async[_0x50efe0(0x2c3)](_0x182c79,_0x3b3bc1,_0x114031,_0x17b0f9,_0x3a9f93){const _0x4c8b12=_0x50efe0,_0x35278a=runInterruptionKey(_0x3b3bc1,_0x17b0f9['id']),_0x1e11ef=this[_0x4c8b12(0x2c4)][_0x4c8b12(0x23c)](_0x35278a);let _0x29355d;try{this[_0x4c8b12(0x2ba)][_0x4c8b12(0x239)][_0x4c8b12(0x2bb)](_0x3b3bc1,_0x114031,_0x3a9f93[_0x4c8b12(0x24e)],_0x3a9f93[_0x4c8b12(0x1e6)]);try{const _0x9a5956=await this[_0x4c8b12(0x2ba)][_0x4c8b12(0x239)][_0x4c8b12(0x10f)](_0x182c79,_0x3b3bc1);this[_0x4c8b12(0x160)](_0x3b3bc1,{'conversationId':_0x3b3bc1,'kind':_0x4c8b12(0x12c),'files':_0x9a5956,'error':null});}catch(_0x3a03ee){this[_0x4c8b12(0x160)](_0x3b3bc1,{'conversationId':_0x3b3bc1,'kind':_0x4c8b12(0x12c),'files':this[_0x4c8b12(0x2ba)][_0x4c8b12(0x239)][_0x4c8b12(0x14b)](_0x182c79,_0x3b3bc1),'error':{'code':safeErrorCode(_0x3a03ee,_0x4c8b12(0x173)),'message':_0x4c8b12(0x14c)}});}await this[_0x4c8b12(0x2ba)][_0x4c8b12(0x239)][_0x4c8b12(0x22a)](_0x3b3bc1,_0x3a9f93[_0x4c8b12(0x1e6)]),this[_0x4c8b12(0x160)](_0x3b3bc1,{'conversationId':_0x3b3bc1,'kind':_0x4c8b12(0x20f),'run':{'id':_0x17b0f9['id'],'status':_0x3a9f93[_0x4c8b12(0x24e)],'startedAt':_0x17b0f9[_0x4c8b12(0x11c)],'completedAt':_0x3a9f93[_0x4c8b12(0x1e6)]}}),await this[_0x4c8b12(0x23d)](_0x3b3bc1,_0x3a9f93[_0x4c8b12(0x139)],_0x3a9f93[_0x4c8b12(0x1e6)])[_0x4c8b12(0x22e)](()=>undefined),_0x29355d=this[_0x4c8b12(0x2ba)][_0x4c8b12(0x239)][_0x4c8b12(0x2be)](_0x182c79,_0x3b3bc1);}finally{this[_0x4c8b12(0x2c4)][_0x4c8b12(0x289)](_0x35278a);if(_0x29355d===undefined)try{_0x29355d=this[_0x4c8b12(0x2ba)][_0x4c8b12(0x239)][_0x4c8b12(0x2be)](_0x182c79,_0x3b3bc1);}catch{}if(_0x29355d!==undefined)this[_0x4c8b12(0x1de)](_0x182c79,_0x29355d,_0x4c8b12(0x2ce),_0x3a9f93[_0x4c8b12(0x1e6)]);}if(_0x29355d!==undefined&&(_0x3a9f93[_0x4c8b12(0x24e)]!==_0x4c8b12(0x121)||!_0x1e11ef))this[_0x4c8b12(0x20b)](_0x182c79,_0x29355d,_0x17b0f9['id'],_0x3a9f93);}async[_0x50efe0(0x23d)](_0x2b9255,_0x3c2b62,_0x9377df){const _0x1090c4=_0x50efe0,_0x212fb4=automaticHostedConversationTitle(_0x3c2b62);if(_0x212fb4===undefined)return;const _0x5b8869=await this[_0x1090c4(0x2ba)][_0x1090c4(0x239)][_0x1090c4(0x18d)](_0x2b9255,_0x212fb4,_0x9377df);if(_0x5b8869===undefined)return;this[_0x1090c4(0x160)](_0x2b9255,{'conversationId':_0x2b9255,'kind':_0x1090c4(0x21c),'conversation':this[_0x1090c4(0x2bd)](_0x5b8869)});}[_0x50efe0(0x130)](_0x31009c){const _0x51f1b8=_0x50efe0,_0x1a872b=hostedRequest(_0x31009c),_0xef567=hostedConversationIdInputSchema[_0x51f1b8(0x12b)](_0x1a872b[_0x51f1b8(0x217)]),_0x4ff4dd=this[_0x51f1b8(0x2ba)][_0x51f1b8(0x239)][_0x51f1b8(0x2be)](_0x1a872b[_0x51f1b8(0x267)],_0xef567[_0x51f1b8(0x20a)]),_0x587285=this[_0x51f1b8(0x14a)][_0x51f1b8(0x1a1)](_0xef567[_0x51f1b8(0x20a)]);if(_0x587285===undefined)return{'interrupted':![]};const _0x10b82b=runInterruptionKey(_0x4ff4dd['id'],_0x587285[_0x51f1b8(0x20f)]['id']);this[_0x51f1b8(0x2c4)][_0x51f1b8(0x287)](_0x10b82b);try{const _0x51b093=_0x587285[_0x51f1b8(0x16c)]();if(!_0x51b093)return this[_0x51f1b8(0x2c4)][_0x51f1b8(0x289)](_0x10b82b),{'interrupted':![]};return this[_0x51f1b8(0x1de)](_0x1a872b[_0x51f1b8(0x267)],_0x4ff4dd,_0x51f1b8(0x169),this[_0x51f1b8(0x109)]()),{'interrupted':!![]};}catch(_0x2270b3){this[_0x51f1b8(0x2c4)][_0x51f1b8(0x289)](_0x10b82b);throw _0x2270b3;}}async[_0x50efe0(0x297)](_0x477d82){const _0x1f5ecf=_0x50efe0,_0x3bbb8b=hostedRequest(_0x477d82),_0x18e7fb=hostedConversationConfigUpdateInputSchema[_0x1f5ecf(0x12b)](_0x3bbb8b[_0x1f5ecf(0x217)]),_0x176d1e=this[_0x1f5ecf(0x2ba)][_0x1f5ecf(0x239)][_0x1f5ecf(0x2be)](_0x3bbb8b[_0x1f5ecf(0x267)],_0x18e7fb[_0x1f5ecf(0x20a)]);if(this[_0x1f5ecf(0x13d)][_0x1f5ecf(0x23c)](_0x176d1e['id']))throw new Error(_0x1f5ecf(0x21d));const _0x32ff7b=_0x176d1e[_0x1f5ecf(0x270)]?undefined:this[_0x1f5ecf(0x259)](_0x176d1e[_0x1f5ecf(0x251)]),_0x57ae0c=_0x32ff7b??_0x176d1e[_0x1f5ecf(0x2b9)],_0xe9c1b4=await this[_0x1f5ecf(0x15f)](_0x57ae0c,_0x176d1e[_0x1f5ecf(0x251)]),_0x119744=runtimeModels(_0x3bbb8b[_0x1f5ecf(0x174)]),_0x2ed675=selectModel(_0xe9c1b4,_0x119744,_0x18e7fb[_0x1f5ecf(0x185)]??_0x176d1e[_0x1f5ecf(0x185)]),_0x2b6816=this[_0x1f5ecf(0x109)](),_0xc89ea3=await this[_0x1f5ecf(0x2ba)][_0x1f5ecf(0x239)][_0x1f5ecf(0x1f8)](_0x176d1e['id'],_0xe9fb88=>({..._0xe9fb88,'modelId':_0x2ed675['id'],'updatedAt':_0x2b6816,'lastActivityAt':_0x2b6816}));return this[_0x1f5ecf(0x160)](_0x176d1e['id'],{'conversationId':_0x176d1e['id'],'kind':_0x1f5ecf(0x1ca),'conversation':this[_0x1f5ecf(0x2bd)](_0xc89ea3)}),{'conversation':this[_0x1f5ecf(0x2bd)](_0xc89ea3)};}async[_0x50efe0(0x2b5)](_0x281a50){const _0x343cc4=_0x50efe0,_0x4c385e=hostedRequest(_0x281a50),_0x14bfae=hostedConversationMetadataUpdateInputSchema[_0x343cc4(0x12b)](_0x4c385e[_0x343cc4(0x217)]),_0x670211=this[_0x343cc4(0x2ba)][_0x343cc4(0x239)][_0x343cc4(0x2be)](_0x4c385e[_0x343cc4(0x267)],_0x14bfae[_0x343cc4(0x20a)]);if(this[_0x343cc4(0x13d)][_0x343cc4(0x23c)](_0x670211['id']))throw new Error(_0x343cc4(0x21d));const _0x43dbac=this[_0x343cc4(0x109)](),_0x1fcec5=await this[_0x343cc4(0x2ba)][_0x343cc4(0x239)][_0x343cc4(0x1f8)](_0x670211['id'],_0x1eaf5e=>({..._0x1eaf5e,'title':_0x14bfae[_0x343cc4(0x139)]??_0x1eaf5e[_0x343cc4(0x139)],'titleSource':_0x14bfae[_0x343cc4(0x139)]===undefined?_0x1eaf5e[_0x343cc4(0x14d)]:_0x343cc4(0x1cb),'pinnedAt':_0x14bfae[_0x343cc4(0x1d4)]===undefined?_0x1eaf5e[_0x343cc4(0x2ae)]:_0x14bfae[_0x343cc4(0x1d4)]?_0x43dbac:null,'updatedAt':_0x43dbac,'lastActivityAt':_0x1eaf5e[_0x343cc4(0x232)]}));return this[_0x343cc4(0x160)](_0x670211['id'],{'conversationId':_0x670211['id'],'kind':_0x343cc4(0x1ca),'conversation':this[_0x343cc4(0x2bd)](_0x1fcec5)}),{'conversation':this[_0x343cc4(0x2bd)](_0x1fcec5)};}async[_0x50efe0(0x14b)](_0x130d8c){const _0x294329=_0x50efe0,_0x5c9931=hostedRequest(_0x130d8c),_0xe9d465=hostedConversationIdInputSchema[_0x294329(0x12b)](_0x5c9931[_0x294329(0x217)]);return hostedConversationFilesSchema[_0x294329(0x12b)]({'files':this[_0x294329(0x2ba)][_0x294329(0x239)][_0x294329(0x14b)](_0x5c9931[_0x294329(0x267)],_0xe9d465[_0x294329(0x20a)])});}async[_0x50efe0(0x229)](_0x273d5f){const _0x55163a=_0x50efe0,_0x34948c=hostedRequest(_0x273d5f),_0x283c53=hostedConversationImageReadInputSchema[_0x55163a(0x12b)](_0x34948c[_0x55163a(0x217)]);this[_0x55163a(0x2ba)][_0x55163a(0x239)][_0x55163a(0x2be)](_0x34948c[_0x55163a(0x267)],_0x283c53[_0x55163a(0x20a)]);if(_0x283c53[_0x55163a(0x16b)]!==hostedConversationImageRunId(_0x283c53[_0x55163a(0x20a)]))throw new Error(_0x55163a(0x28c));const _0x2a0368=await this[_0x55163a(0x2ba)][_0x55163a(0x229)](_0x283c53[_0x55163a(0x16b)],_0x283c53[_0x55163a(0x136)]);if(_0x2a0368===undefined)throw new Error(_0x55163a(0x167));return{'image':_0x2a0368};}async[_0x50efe0(0x15b)](_0x5315e3){const _0x408e31=_0x50efe0,_0x3f7888=hostedRequest(_0x5315e3),_0xd3cd6d=hostedConversationFileReadInputSchema[_0x408e31(0x12b)](_0x3f7888[_0x408e31(0x217)]),_0x20ecc5=this[_0x408e31(0x2ba)][_0x408e31(0x239)][_0x408e31(0x198)](_0x3f7888[_0x408e31(0x267)],_0xd3cd6d[_0x408e31(0x20a)],_0xd3cd6d[_0x408e31(0x271)]),_0xdc3e7b=this[_0x408e31(0x2ba)][_0x408e31(0x239)][_0x408e31(0x277)](_0x3f7888[_0x408e31(0x267)],_0x20ecc5),_0x360ef3=_0xd3cd6d[_0x408e31(0x126)]??-0x3a*-0x79+0x2022+-0x3b8c,_0x1897b5=Math[_0x408e31(0x1ee)](_0xd3cd6d[_0x408e31(0x11e)]??MAX_FILE_READ_BYTES,MAX_FILE_READ_BYTES),_0x4b7f22=await openRegularFile(_0xdc3e7b);try{const _0x133337=await _0x4b7f22[_0x408e31(0x246)]();assertRegularFileMetadata(_0x133337);const _0x23f7d1=await regularFileMetadata(_0xdc3e7b);if(!sameFileIdentity(_0x133337,_0x23f7d1))throw new Error(_0x408e31(0x25b));if(_0x360ef3>_0x133337[_0x408e31(0x293)])throw new Error(_0x408e31(0x1a8));const _0xb73b00=Buffer[_0x408e31(0x1fa)](Math[_0x408e31(0x1ee)](_0x1897b5,Math[_0x408e31(0x177)](0x1db3+0x3*0x7cd+-0x2*0x1a8d,_0x133337[_0x408e31(0x293)]-_0x360ef3))),_0x2769f7=await _0x4b7f22[_0x408e31(0x17c)](_0xb73b00,0x7c*-0x4a+-0xccb+0x30a3,_0xb73b00[_0x408e31(0x26b)],_0x360ef3),_0x1dcee8=await _0x4b7f22[_0x408e31(0x246)](),_0x2e42b5=await regularFileMetadata(_0xdc3e7b);if(!sameFileSnapshot(_0x133337,_0x1dcee8)||!sameFileSnapshot(_0x1dcee8,_0x2e42b5))throw new Error(_0x408e31(0x25b));const _0x496535=_0x360ef3+_0x2769f7[_0x408e31(0x1e2)],_0x140258=_0x496535>=_0x1dcee8[_0x408e31(0x293)],_0xab3b17={..._0x20ecc5,'size':_0x1dcee8[_0x408e31(0x293)],'updatedAt':Math[_0x408e31(0x177)](_0x20ecc5[_0x408e31(0x1ba)],safeFileTimestamp(_0x1dcee8[_0x408e31(0x13c)]),safeFileTimestamp(_0x1dcee8[_0x408e31(0x16a)]))};return hostedConversationFileReadResultSchema[_0x408e31(0x12b)]({'file':_0xab3b17,'encoding':_0x408e31(0x147),'content':_0xb73b00[_0x408e31(0x1d7)](-0x613+0x79c+0x83*-0x3,_0x2769f7[_0x408e31(0x1e2)])[_0x408e31(0x2cb)](_0x408e31(0x147)),'offset':_0x360ef3,'nextOffset':_0x140258?null:_0x496535,'eof':_0x140258});}finally{await _0x4b7f22[_0x408e31(0x205)]();}}async[_0x50efe0(0x255)](_0x3d456a){const _0x442d4c=_0x50efe0,_0x5831bb=hostedRequest(_0x3d456a),_0xcff66d=hostedConversationFileDeleteInputSchema[_0x442d4c(0x12b)](_0x5831bb[_0x442d4c(0x217)]);this[_0x442d4c(0x17b)](_0x5831bb[_0x442d4c(0x267)],_0xcff66d[_0x442d4c(0x20a)]);const _0x24d044=_0xcff66d[_0x442d4c(0x20a)]+'\x00'+_0xcff66d[_0x442d4c(0x271)];if(this[_0x442d4c(0x200)][_0x442d4c(0x23c)](_0x24d044))throw new Error(_0x442d4c(0x11f));this[_0x442d4c(0x200)][_0x442d4c(0x287)](_0x24d044);try{const _0x66a192=await this[_0x442d4c(0x2ba)][_0x442d4c(0x239)][_0x442d4c(0x255)](_0x5831bb[_0x442d4c(0x267)],_0xcff66d[_0x442d4c(0x20a)],_0xcff66d[_0x442d4c(0x271)],this[_0x442d4c(0x109)]()),_0x22a5f0=hostedConversationFileDeleteResultSchema[_0x442d4c(0x12b)]({'deletedFileId':_0xcff66d[_0x442d4c(0x271)],'files':_0x66a192});return this[_0x442d4c(0x160)](_0xcff66d[_0x442d4c(0x20a)],{'conversationId':_0xcff66d[_0x442d4c(0x20a)],'kind':_0x442d4c(0x12c),'files':_0x22a5f0[_0x442d4c(0x12c)],'error':null}),_0x22a5f0;}finally{this[_0x442d4c(0x200)][_0x442d4c(0x289)](_0x24d044);}}async[_0x50efe0(0x21e)](_0x12b3c6){const _0x5b04ee=_0x50efe0,_0x5745b7=hostedRequest(_0x12b3c6),_0x4e591d=hostedConversationUploadPreflightInputSchema[_0x5b04ee(0x12b)](_0x5745b7[_0x5b04ee(0x217)]),_0x2c4d16=this[_0x5b04ee(0x17b)](_0x5745b7[_0x5b04ee(0x267)],_0x4e591d[_0x5b04ee(0x20a)]),_0x4c343a=await this[_0x5b04ee(0x15f)](_0x2c4d16[_0x5b04ee(0x2b9)],_0x2c4d16[_0x5b04ee(0x251)]),_0x147d8e=this[_0x5b04ee(0x2ba)][_0x5b04ee(0x239)][_0x5b04ee(0x23f)](_0x5745b7[_0x5b04ee(0x267)],_0x2c4d16['id']),_0x15e4f0=await Promise[_0x5b04ee(0x219)](_0x4e591d[_0x5b04ee(0x12c)][_0x5b04ee(0x158)](async _0x52d793=>({'name':_0x52d793[_0x5b04ee(0x1eb)],'status':await this[_0x5b04ee(0x292)](_0x147d8e,_0x2c4d16,_0x4c343a[_0x5b04ee(0x1f6)],_0x52d793[_0x5b04ee(0x1eb)],_0x52d793[_0x5b04ee(0x293)])})));return hostedConversationUploadPreflightResultSchema[_0x5b04ee(0x12b)]({'files':_0x15e4f0});}async[_0x50efe0(0x1cd)](_0x8919b5){const _0x8e89bf=_0x50efe0,_0x15ac9b=hostedRequest(_0x8919b5),_0x20f417=hostedConversationUploadCreateInputSchema[_0x8e89bf(0x12b)](_0x15ac9b[_0x8e89bf(0x217)]),_0x52398d=this[_0x8e89bf(0x17b)](_0x15ac9b[_0x8e89bf(0x267)],_0x20f417[_0x8e89bf(0x20a)]),_0x275cfc=_0x15ac9b[_0x8e89bf(0x267)]+'\x00'+_0x52398d['id']+'\x00'+_0x20f417[_0x8e89bf(0x296)],_0x2b270c=this[_0x8e89bf(0x20e)][_0x8e89bf(0x1a1)](_0x275cfc);if(_0x2b270c!==undefined){const _0x5cf87f=this[_0x8e89bf(0x166)][_0x8e89bf(0x1a1)](_0x2b270c);if(_0x5cf87f!==undefined)return{'upload':hostedConversationUploadSchema[_0x8e89bf(0x12b)](uploadProjection(_0x5cf87f))};}const _0x5e6213=await this[_0x8e89bf(0x15f)](_0x52398d[_0x8e89bf(0x2b9)],_0x52398d[_0x8e89bf(0x251)]),_0x305812=this[_0x8e89bf(0x2ba)][_0x8e89bf(0x239)][_0x8e89bf(0x23f)](_0x15ac9b[_0x8e89bf(0x267)],_0x52398d['id']),_0x2aa060=await this[_0x8e89bf(0x292)](_0x305812,_0x52398d,_0x5e6213[_0x8e89bf(0x1f6)],_0x20f417[_0x8e89bf(0x1eb)],_0x20f417[_0x8e89bf(0x293)]);if(_0x2aa060===_0x8e89bf(0x28a)||_0x2aa060===_0x8e89bf(0x1bb))throw new Error(_0x8e89bf(0x15e));if(_0x2aa060!==_0x8e89bf(0x135))throw new Error(_0x8e89bf(0x25b));const _0x23e31c=this['id'](),_0x35d946=join(_0x305812[_0x8e89bf(0x1c3)],'.'+_0x23e31c+_0x8e89bf(0x118)),_0xac6f66=join(_0x305812[_0x8e89bf(0x1c3)],_0x20f417[_0x8e89bf(0x1eb)]),_0x594f66=await open(_0x35d946,'wx',-0x22+0x97c+-0x7da);await _0x594f66[_0x8e89bf(0x205)]();const _0x13213d={'uploadId':_0x23e31c,'conversationId':_0x52398d['id'],'userId':_0x15ac9b[_0x8e89bf(0x267)],'clientRequestId':_0x20f417[_0x8e89bf(0x296)],'name':_0x20f417[_0x8e89bf(0x1eb)],'mimeType':_0x20f417[_0x8e89bf(0x18c)],'size':_0x20f417[_0x8e89bf(0x293)],'temporaryPath':_0x35d946,'targetPath':_0xac6f66,'receivedBytes':0x0,'status':_0x8e89bf(0x105)};return this[_0x8e89bf(0x166)][_0x8e89bf(0x1a3)](_0x23e31c,_0x13213d),this[_0x8e89bf(0x20e)][_0x8e89bf(0x1a3)](_0x275cfc,_0x23e31c),{'upload':hostedConversationUploadSchema[_0x8e89bf(0x12b)](uploadProjection(_0x13213d))};}async[_0x50efe0(0x115)](_0x351267){const _0x52575d=_0x50efe0,_0xfbbb34=hostedRequest(_0x351267),_0x22eb3b=hostedConversationUploadChunkInputSchema[_0x52575d(0x12b)](_0xfbbb34[_0x52575d(0x217)]),_0x48771a=this[_0x52575d(0x2ab)](_0xfbbb34[_0x52575d(0x267)],_0x22eb3b[_0x52575d(0x20a)],_0x22eb3b[_0x52575d(0x1d8)]);if(_0x48771a[_0x52575d(0x24e)]!==_0x52575d(0x105))throw new Error(_0x52575d(0x2b1));if(_0x22eb3b[_0x52575d(0x126)]!==_0x48771a[_0x52575d(0x2a5)])throw new Error(_0x52575d(0x12e));const _0x2f8145=Buffer[_0x52575d(0x182)](_0x22eb3b[_0x52575d(0x2e4)],_0x52575d(0x147));if(_0x48771a[_0x52575d(0x2a5)]+_0x2f8145[_0x52575d(0x116)]>_0x48771a[_0x52575d(0x293)])throw new Error(_0x52575d(0x1c5));await assertUploadTemporaryFile(_0x48771a[_0x52575d(0x112)],_0x48771a[_0x52575d(0x2a5)]);const _0x1e03e5=await open(_0x48771a[_0x52575d(0x112)],'r+');try{await _0x1e03e5[_0x52575d(0x142)](_0x2f8145,-0x119*0xc+0x4*-0x8ec+0xd4*0x3b,_0x2f8145[_0x52575d(0x116)],_0x48771a[_0x52575d(0x2a5)]);}finally{await _0x1e03e5[_0x52575d(0x205)]();}return _0x48771a[_0x52575d(0x2a5)]+=_0x2f8145[_0x52575d(0x116)],{'upload':hostedConversationUploadSchema[_0x52575d(0x12b)](uploadProjection(_0x48771a))};}[_0x50efe0(0x249)](_0x48b1b6){const _0x388f4d=_0x50efe0,_0x1313f6=hostedRequest(_0x48b1b6),_0x290272=hostedConversationUploadControlInputSchema[_0x388f4d(0x12b)](_0x1313f6[_0x388f4d(0x217)]),_0x486bd6=this[_0x388f4d(0x2ab)](_0x1313f6[_0x388f4d(0x267)],_0x290272[_0x388f4d(0x20a)],_0x290272[_0x388f4d(0x1d8)]);return{'upload':hostedConversationUploadSchema[_0x388f4d(0x12b)](uploadProjection(_0x486bd6))};}async[_0x50efe0(0x283)](_0x40d9c2){const _0xcc0fab=_0x50efe0,_0x5d79f2=hostedRequest(_0x40d9c2),_0x59139f=hostedConversationUploadControlInputSchema[_0xcc0fab(0x12b)](_0x5d79f2[_0xcc0fab(0x217)]),_0x223a90=this[_0xcc0fab(0x2ab)](_0x5d79f2[_0xcc0fab(0x267)],_0x59139f[_0xcc0fab(0x20a)],_0x59139f[_0xcc0fab(0x1d8)]);if(_0x223a90[_0xcc0fab(0x24e)]===_0xcc0fab(0x27e))return{'upload':hostedConversationUploadSchema[_0xcc0fab(0x12b)](uploadProjection(_0x223a90))};if(_0x223a90[_0xcc0fab(0x24e)]!==_0xcc0fab(0x105)||_0x223a90[_0xcc0fab(0x2a5)]!==_0x223a90[_0xcc0fab(0x293)])throw new Error(_0xcc0fab(0x1c6));const _0x46ae1f=this[_0xcc0fab(0x17b)](_0x5d79f2[_0xcc0fab(0x267)],_0x223a90[_0xcc0fab(0x20a)]),_0x50c5cf=await this[_0xcc0fab(0x15f)](_0x46ae1f[_0xcc0fab(0x2b9)],_0x46ae1f[_0xcc0fab(0x251)]);if(_0x223a90[_0xcc0fab(0x293)]>_0x50c5cf[_0xcc0fab(0x1f6)][_0xcc0fab(0x2a0)][_0xcc0fab(0x258)]||_0x46ae1f[_0xcc0fab(0x1dc)][_0xcc0fab(0x1b0)]+_0x223a90[_0xcc0fab(0x293)]>_0x46ae1f[_0xcc0fab(0x1dc)][_0xcc0fab(0x159)])throw new Error(_0xcc0fab(0x15e));await assertUploadTemporaryFile(_0x223a90[_0xcc0fab(0x112)],_0x223a90[_0xcc0fab(0x293)]);const _0x348458=await lstat(_0x223a90[_0xcc0fab(0x133)])[_0xcc0fab(0x22e)](_0x3c1ee1=>{const _0x1a1d1e=_0xcc0fab;if(_0x3c1ee1[_0x1a1d1e(0x1ac)]===_0x1a1d1e(0x214))return undefined;throw _0x3c1ee1;});if(_0x348458!==undefined)throw new Error(_0xcc0fab(0x25b));const _0x57f015=await open(_0x223a90[_0xcc0fab(0x112)],'r+');try{await _0x57f015[_0xcc0fab(0x236)]();}finally{await _0x57f015[_0xcc0fab(0x205)]();}await rename(_0x223a90[_0xcc0fab(0x112)],_0x223a90[_0xcc0fab(0x133)]);const _0x1b6188=this[_0xcc0fab(0x109)]();try{await utimes(_0x223a90[_0xcc0fab(0x133)],new Date(_0x1b6188),new Date(_0x1b6188));const _0x4dbfb4={'id':this[_0xcc0fab(0x2ba)][_0xcc0fab(0x239)][_0xcc0fab(0x164)](_0x223a90[_0xcc0fab(0x20a)],_0xcc0fab(0x2aa),_0x223a90[_0xcc0fab(0x1eb)]),'conversationId':_0x223a90[_0xcc0fab(0x20a)],'category':_0xcc0fab(0x2aa),'relativePath':_0x223a90[_0xcc0fab(0x1eb)],'displayName':_0x223a90[_0xcc0fab(0x1eb)],'mimeType':_0x223a90[_0xcc0fab(0x18c)],'size':_0x223a90[_0xcc0fab(0x293)],'source':_0xcc0fab(0x290),'createdAt':_0x1b6188,'updatedAt':_0x1b6188};return _0x223a90[_0xcc0fab(0x127)]=await this[_0xcc0fab(0x2ba)][_0xcc0fab(0x239)][_0xcc0fab(0x24d)](_0x5d79f2[_0xcc0fab(0x267)],_0x4dbfb4),_0x223a90[_0xcc0fab(0x24e)]=_0xcc0fab(0x27e),this[_0xcc0fab(0x160)](_0x223a90[_0xcc0fab(0x20a)],{'conversationId':_0x223a90[_0xcc0fab(0x20a)],'kind':_0xcc0fab(0x12c),'files':this[_0xcc0fab(0x2ba)][_0xcc0fab(0x239)][_0xcc0fab(0x14b)](_0x5d79f2[_0xcc0fab(0x267)],_0x223a90[_0xcc0fab(0x20a)]),'error':null}),{'upload':hostedConversationUploadSchema[_0xcc0fab(0x12b)](uploadProjection(_0x223a90))};}catch(_0x33926f){await rename(_0x223a90[_0xcc0fab(0x133)],_0x223a90[_0xcc0fab(0x112)])[_0xcc0fab(0x22e)](()=>undefined);throw _0x33926f;}}async[_0x50efe0(0x12f)](_0x372c38){const _0x29d5d9=_0x50efe0,_0x309c1e=hostedRequest(_0x372c38),_0x3900af=hostedConversationUploadControlInputSchema[_0x29d5d9(0x12b)](_0x309c1e[_0x29d5d9(0x217)]),_0x3351ea=this[_0x29d5d9(0x2ab)](_0x309c1e[_0x29d5d9(0x267)],_0x3900af[_0x29d5d9(0x20a)],_0x3900af[_0x29d5d9(0x1d8)]);if(_0x3351ea[_0x29d5d9(0x24e)]===_0x29d5d9(0x27e))throw new Error(_0x29d5d9(0x2b1));return _0x3351ea[_0x29d5d9(0x24e)]=_0x29d5d9(0x2d7),await rm(_0x3351ea[_0x29d5d9(0x112)],{'force':!![]}),{'upload':hostedConversationUploadSchema[_0x29d5d9(0x12b)](uploadProjection(_0x3351ea))};}async[_0x50efe0(0x289)](_0x4c3f6c){const _0x32d13e=_0x50efe0,_0x4fb28f=hostedRequest(_0x4c3f6c),_0x4df4f6=hostedConversationIdInputSchema[_0x32d13e(0x12b)](_0x4fb28f[_0x32d13e(0x217)]),_0x15cf0a=this[_0x32d13e(0x2ba)][_0x32d13e(0x239)][_0x32d13e(0x2be)](_0x4fb28f[_0x32d13e(0x267)],_0x4df4f6[_0x32d13e(0x20a)]);if(this[_0x32d13e(0x13d)][_0x32d13e(0x23c)](_0x15cf0a['id'])||this[_0x32d13e(0x1cc)][_0x32d13e(0x23c)](_0x15cf0a['id']))throw new Error(_0x32d13e(0x21d));this[_0x32d13e(0x13d)][_0x32d13e(0x287)](_0x15cf0a['id']);try{await this[_0x32d13e(0x23b)](_0x15cf0a['id']);const _0x5a64d1=this[_0x32d13e(0x14a)][_0x32d13e(0x1a1)](_0x15cf0a['id']);if(_0x5a64d1!==undefined){const _0x185557=runInterruptionKey(_0x15cf0a['id'],_0x5a64d1[_0x32d13e(0x20f)]['id']);this[_0x32d13e(0x2c4)][_0x32d13e(0x287)](_0x185557);if(!_0x5a64d1[_0x32d13e(0x16c)]())this[_0x32d13e(0x2c4)][_0x32d13e(0x289)](_0x185557);}await this[_0x32d13e(0x21f)](_0x4fb28f[_0x32d13e(0x267)],_0x15cf0a['id']);const _0x4bda8d=this[_0x32d13e(0x2ba)][_0x32d13e(0x239)][_0x32d13e(0x23f)](_0x4fb28f[_0x32d13e(0x267)],_0x15cf0a['id']);return await this[_0x32d13e(0x2ba)][_0x32d13e(0x189)][_0x32d13e(0x1e5)]({'conversationId':_0x15cf0a['id'],'sessionId':_0x15cf0a[_0x32d13e(0x17a)],'homeDirectory':_0x4bda8d[_0x32d13e(0x252)]})[_0x32d13e(0x22e)](()=>undefined),await this[_0x32d13e(0x122)][_0x32d13e(0x1a1)](_0x15cf0a['id'])?.[_0x32d13e(0x22e)](()=>undefined),this[_0x32d13e(0x256)](_0x15cf0a['id']),await this[_0x32d13e(0x2ba)][_0x32d13e(0x239)][_0x32d13e(0x28f)](_0x15cf0a['id']),this[_0x32d13e(0x2ad)][_0x32d13e(0x289)](_0x15cf0a['id']),this[_0x32d13e(0x2af)][_0x32d13e(0x289)](_0x15cf0a['id']),hostedConversationDeleteResultSchema[_0x32d13e(0x12b)]({'deletedConversationId':_0x15cf0a['id']});}finally{this[_0x32d13e(0x13d)][_0x32d13e(0x289)](_0x15cf0a['id']);}}async[_0x50efe0(0x23b)](_0x5ab2e1){const _0x1f5007=_0x50efe0,_0x4bd70c=_0x5ab2e1+'\x00',_0x32faa1=[...this[_0x1f5007(0x12d)][_0x1f5007(0x1fb)]()][_0x1f5007(0x1a0)](([_0x35f483])=>_0x35f483[_0x1f5007(0x2ac)](_0x4bd70c))[_0x1f5007(0x158)](([,_0x4b6307])=>_0x4b6307);await Promise[_0x1f5007(0x209)](_0x32faa1);}async[_0x50efe0(0x2c6)](_0x7abad){const _0x548996=_0x50efe0;try{const _0x3cc9cc=await this[_0x548996(0x1a1)]({'conversationId':_0x7abad[_0x548996(0x20a)],'__requestUserId':_0x7abad[_0x548996(0x267)],'__marAgentModels':_0x7abad[_0x548996(0x174)]});if(this[_0x548996(0x26a)][_0x548996(0x1a1)](_0x7abad[_0x548996(0x245)])!==_0x7abad)return;this[_0x548996(0x2ba)][_0x548996(0x26f)]?.({'type':_0x548996(0x237),'workbenchConnectionId':_0x7abad[_0x548996(0x187)],'watchId':_0x7abad[_0x548996(0x21b)],'nodeGeneration':_0x7abad[_0x548996(0x1c9)],'nodeId':this[_0x548996(0x2ba)][_0x548996(0x269)](),'templateId':_0x7abad[_0x548996(0x251)],'conversationId':_0x7abad[_0x548996(0x20a)],'revision':0x1,'snapshotSequence':++this[_0x548996(0x2a1)],'expiresAt':_0x7abad[_0x548996(0x2b6)],'payload':_0x3cc9cc}),_0x7abad[_0x548996(0x233)]=!![];for(const _0x28ea70 of _0x7abad[_0x548996(0x168)])this[_0x548996(0x243)](_0x7abad,_0x28ea70);_0x7abad[_0x548996(0x168)][_0x548996(0x26b)]=-0x156c+0xf37+0x635*0x1;}catch(_0x1e4195){if(this[_0x548996(0x26a)][_0x548996(0x1a1)](_0x7abad[_0x548996(0x245)])!==_0x7abad)return;this[_0x548996(0x2ba)][_0x548996(0x26f)]?.({'type':_0x548996(0x2b2),'workbenchConnectionId':_0x7abad[_0x548996(0x187)],'watchType':_0x548996(0x1ae),'watchId':_0x7abad[_0x548996(0x21b)],'nodeGeneration':_0x7abad[_0x548996(0x1c9)],'nodeId':this[_0x548996(0x2ba)][_0x548996(0x269)](),'templateId':_0x7abad[_0x548996(0x251)],'conversationId':_0x7abad[_0x548996(0x20a)],'code':safeErrorCode(_0x1e4195,_0x548996(0x15d)),'message':_0x548996(0x18a)}),this[_0x548996(0x196)](_0x7abad[_0x548996(0x245)]);}}[_0x50efe0(0x1ce)](_0x372678,_0x5daeef){const _0x41dea6=_0x50efe0;for(const _0x1bc277 of this[_0x41dea6(0x26a)][_0x41dea6(0x272)]()){if(_0x1bc277[_0x41dea6(0x20a)]!==_0x372678||!_0x1bc277[_0x41dea6(0x233)])continue;this[_0x41dea6(0x2ba)][_0x41dea6(0x26f)]?.({'type':_0x41dea6(0x237),'workbenchConnectionId':_0x1bc277[_0x41dea6(0x187)],'watchId':_0x1bc277[_0x41dea6(0x21b)],'nodeGeneration':_0x1bc277[_0x41dea6(0x1c9)],'nodeId':this[_0x41dea6(0x2ba)][_0x41dea6(0x269)](),'templateId':_0x1bc277[_0x41dea6(0x251)],'conversationId':_0x1bc277[_0x41dea6(0x20a)],'revision':0x1,'snapshotSequence':++this[_0x41dea6(0x2a1)],'expiresAt':_0x1bc277[_0x41dea6(0x2b6)],'payload':_0x5daeef});}}[_0x50efe0(0x1e3)](_0x467205){const _0x1552ed=_0x50efe0;return this[_0x1552ed(0x2ad)][_0x1552ed(0x1a1)](_0x467205)??{'status':_0x1552ed(0x2ce),'version':0x0,'updatedAt':0x0};}[_0x50efe0(0x2bd)](_0x1c18a6){const _0x4ee346=_0x50efe0;return hostedConversationSummary(_0x1c18a6,this[_0x4ee346(0x1e3)](_0x1c18a6['id']));}[_0x50efe0(0x1de)](_0x541b86,_0x5be18f,_0x16ab2d,_0xa61bf0){const _0x168591=_0x50efe0,_0x292b57=this[_0x168591(0x1e3)](_0x5be18f['id']),_0x14bd44={'status':_0x16ab2d,'version':_0x292b57[_0x168591(0x16d)]+(-0x7*-0x82+-0xbe1*0x1+0x854),'updatedAt':_0xa61bf0};this[_0x168591(0x2ad)][_0x168591(0x1a3)](_0x5be18f['id'],_0x14bd44),this[_0x168591(0x10b)]({'kind':_0x168591(0x1e3),'userId':_0x541b86,'templateId':_0x5be18f[_0x168591(0x251)],'conversationId':_0x5be18f['id'],'activity':_0x14bd44});}[_0x50efe0(0x20b)](_0x58aea9,_0x92edfb,_0x534fa6,_0x52b5d7){const _0x15bd13=_0x50efe0;this[_0x15bd13(0x10b)]({'kind':_0x15bd13(0x2cd),'event':{'runId':_0x534fa6,'sequence':0x1,'eventType':_0x15bd13(0x2cd),'payload':{'targetType':_0x15bd13(0x266),'userId':_0x58aea9,'templateId':_0x92edfb[_0x15bd13(0x251)],'conversationId':_0x92edfb['id'],'conversationTitle':_0x92edfb[_0x15bd13(0x139)],'runId':_0x534fa6,'notificationId':_0x15bd13(0x28b)+this[_0x15bd13(0x2ba)][_0x15bd13(0x269)]()+':'+_0x92edfb['id']+':'+_0x534fa6,'kind':_0x15bd13(0x23a),'outcome':_0x52b5d7[_0x15bd13(0x24e)],'occurredAt':_0x52b5d7[_0x15bd13(0x1e6)]},'createdAt':_0x52b5d7[_0x15bd13(0x1e6)]}});}[_0x50efe0(0x10b)](_0x4e5c9e){const _0x41232f=_0x50efe0,_0x118738=this[_0x41232f(0x2ba)][_0x41232f(0x298)]?.(_0x4e5c9e)??{'sequence':++this[_0x41232f(0x2ca)],'category':_0x41232f(0x1ae),'payload':_0x4e5c9e};if(_0x118738!==undefined)this[_0x41232f(0x2ba)][_0x41232f(0x273)]?.(_0x118738);}[_0x50efe0(0x2d6)](_0x211da1,_0x85fe5f,_0x3037c6,_0x58357f){const _0x4260e6=_0x50efe0;this[_0x4260e6(0x160)](_0x211da1['id'],{'conversationId':_0x211da1['id'],'kind':_0x4260e6(0x280),'upgrade':{'status':_0x4260e6(0x1b9),'previousVersionId':_0x85fe5f,'targetVersionId':_0x3037c6,'activeVersionId':_0x211da1[_0x4260e6(0x2b9)],'conversation':this[_0x4260e6(0x2bd)](_0x211da1),'error':{'code':safeErrorCode(_0x58357f,_0x4260e6(0x1db)),'message':_0x4260e6(0x276)}}});}[_0x50efe0(0x160)](_0x39c7d,_0x58f464){const _0x33e00e=_0x50efe0,_0x3cd1c1=[...this[_0x33e00e(0x26a)][_0x33e00e(0x272)]()][_0x33e00e(0x1a0)](_0x1e9ad0=>_0x1e9ad0[_0x33e00e(0x20a)]===_0x39c7d);if(_0x3cd1c1[_0x33e00e(0x26b)]===-0x1d7f+0x4*-0x151+0x22c3*0x1)return![];const _0x78ad60=this[_0x33e00e(0x2ba)][_0x33e00e(0x298)]?.(_0x58f464)??{'sequence':++this[_0x33e00e(0x2ca)],'category':_0x33e00e(0x1ae),'payload':_0x58f464};if(_0x78ad60===undefined)return![];for(const _0x129c74 of _0x3cd1c1){if(!_0x129c74[_0x33e00e(0x233)])_0x129c74[_0x33e00e(0x168)][_0x33e00e(0x1f1)](_0x78ad60);else this[_0x33e00e(0x243)](_0x129c74,_0x78ad60);}return!![];}[_0x50efe0(0x243)](_0x5a7415,_0x35e51b){const _0x18f543=_0x50efe0;this[_0x18f543(0x2ba)][_0x18f543(0x26f)]?.({'type':_0x18f543(0x213),'workbenchConnectionId':_0x5a7415[_0x18f543(0x187)],'watchId':_0x5a7415[_0x18f543(0x21b)],'nodeGeneration':_0x5a7415[_0x18f543(0x1c9)],'nodeId':this[_0x18f543(0x2ba)][_0x18f543(0x269)](),'templateId':_0x5a7415[_0x18f543(0x251)],'conversationId':_0x5a7415[_0x18f543(0x20a)],'expiresAt':_0x5a7415[_0x18f543(0x2b6)],'event':_0x35e51b});}[_0x50efe0(0x248)](_0x18b352){const _0x50475f=_0x50efe0;return{'accepted':!![],'watchId':_0x18b352[_0x50475f(0x21b)],'nodeGeneration':_0x18b352[_0x50475f(0x1c9)],'expiresAt':_0x18b352[_0x50475f(0x2b6)]};}[_0x50efe0(0x256)](_0x2e67d7){const _0x5aadd1=_0x50efe0;for(const _0x153244 of[...this[_0x5aadd1(0x26a)][_0x5aadd1(0x272)]()])if(_0x153244[_0x5aadd1(0x20a)]===_0x2e67d7)this[_0x5aadd1(0x196)](_0x153244[_0x5aadd1(0x245)]);}[_0x50efe0(0x196)](_0x545fe1){const _0x497b0a=_0x50efe0,_0xe052b6=this[_0x497b0a(0x26a)][_0x497b0a(0x1a1)](_0x545fe1);if(_0xe052b6===undefined)return;clearTimeout(_0xe052b6[_0x497b0a(0x172)]),this[_0x497b0a(0x26a)][_0x497b0a(0x289)](_0x545fe1),this[_0x497b0a(0x2d8)][_0x497b0a(0x268)](_0x545fe1,_0xe052b6[_0x497b0a(0x204)]);}[_0x50efe0(0x13b)](_0x5bf1e0){const _0x389aaa=_0x50efe0,_0xc5902b=setTimeout(()=>this[_0x389aaa(0x196)](_0x5bf1e0),WATCH_TTL_MS);return _0xc5902b[_0x389aaa(0x145)](),_0xc5902b;}[_0x50efe0(0x17b)](_0x4c74c8,_0x2023d8){const _0x3928c4=_0x50efe0,_0x4f1754=this[_0x3928c4(0x2ba)][_0x3928c4(0x239)][_0x3928c4(0x2be)](_0x4c74c8,_0x2023d8);if(this[_0x3928c4(0x13d)][_0x3928c4(0x23c)](_0x4f1754['id']))throw new Error(_0x3928c4(0x21d));if(_0x4f1754[_0x3928c4(0x24e)]!==_0x3928c4(0x10d))throw new Error(_0x3928c4(0x21d));return _0x4f1754;}[_0x50efe0(0x2ab)](_0xf5630c,_0xdd991c,_0x60ff20){const _0x4b189c=_0x50efe0;this[_0x4b189c(0x2ba)][_0x4b189c(0x239)][_0x4b189c(0x2be)](_0xf5630c,_0xdd991c);const _0x3eb95b=this[_0x4b189c(0x166)][_0x4b189c(0x1a1)](_0x60ff20);if(_0x3eb95b===undefined||_0x3eb95b[_0x4b189c(0x267)]!==_0xf5630c||_0x3eb95b[_0x4b189c(0x20a)]!==_0xdd991c)throw new Error(_0x4b189c(0x131));return _0x3eb95b;}async[_0x50efe0(0x21f)](_0x3510e2,_0x37ce31){const _0x4c40ed=_0x50efe0;for(const _0x19cb38 of this[_0x4c40ed(0x166)][_0x4c40ed(0x272)]()){if(_0x19cb38[_0x4c40ed(0x267)]!==_0x3510e2||_0x19cb38[_0x4c40ed(0x20a)]!==_0x37ce31)continue;_0x19cb38[_0x4c40ed(0x24e)]===_0x4c40ed(0x105)&&(_0x19cb38[_0x4c40ed(0x24e)]=_0x4c40ed(0x2d7),await rm(_0x19cb38[_0x4c40ed(0x112)],{'force':!![]})[_0x4c40ed(0x22e)](()=>undefined));}}async[_0x50efe0(0x108)](_0x79f01f,_0x50b234,_0x38d887){const _0x3f7eed=_0x50efe0,_0x41d68f=this[_0x3f7eed(0x2ba)][_0x3f7eed(0x239)][_0x3f7eed(0x198)](_0x79f01f,_0x50b234,_0x38d887);if(_0x41d68f[_0x3f7eed(0x157)]!==_0x3f7eed(0x2aa))throw new Error(_0x3f7eed(0x22c));return await assertRegularFile(this[_0x3f7eed(0x2ba)][_0x3f7eed(0x239)][_0x3f7eed(0x277)](_0x79f01f,_0x41d68f),_0x41d68f[_0x3f7eed(0x293)]),_0x41d68f;}async[_0x50efe0(0x292)](_0x42b7fa,_0x21143d,_0x2b54a3,_0x50694e,_0x32a5e3){const _0x41ce98=_0x50efe0;if(_0x32a5e3>_0x2b54a3[_0x41ce98(0x2a0)][_0x41ce98(0x258)])return _0x41ce98(0x1bb);if(_0x21143d[_0x41ce98(0x1dc)][_0x41ce98(0x1b0)]+_0x32a5e3>_0x21143d[_0x41ce98(0x1dc)][_0x41ce98(0x159)])return _0x41ce98(0x28a);const _0x14628d=await lstat(join(_0x42b7fa[_0x41ce98(0x1c3)],_0x50694e))[_0x41ce98(0x22e)](_0x5052f7=>{const _0x47fdc7=_0x41ce98;if(_0x5052f7[_0x47fdc7(0x1ac)]===_0x47fdc7(0x214))return undefined;throw _0x5052f7;});return _0x14628d===undefined?_0x41ce98(0x135):_0x41ce98(0x101);}[_0x50efe0(0x1bf)](_0x97e1c9,_0x566edd,_0x303837,_0x39c8c6,_0x18ded5){const _0x48260b=_0x50efe0,_0xf3ff36=[{'logicalPath':_0x48260b(0x262),'physicalPath':_0x566edd[_0x48260b(0x155)],'writable':![]},{'logicalPath':_0x48260b(0x148),'physicalPath':_0x97e1c9[_0x48260b(0x1c3)],'writable':!![]},{'logicalPath':_0x48260b(0x1d6),'physicalPath':_0x97e1c9[_0x48260b(0x210)],'writable':!![]}];if(_0x18ded5!==undefined)_0xf3ff36[_0x48260b(0x1f1)]({'logicalPath':_0x48260b(0x230),'physicalPath':_0x18ded5,'writable':!![]});if(_0x303837!==undefined&&_0x39c8c6!==undefined)_0xf3ff36[_0x48260b(0x1f1)]({'logicalPath':_0x39c8c6,'physicalPath':_0x303837,'writable':![]});if(_0x566edd[_0x48260b(0x1a9)]!==undefined)_0xf3ff36[_0x48260b(0x1f1)]({'logicalPath':_0x566edd[_0x48260b(0x1a9)],'physicalPath':_0x566edd[_0x48260b(0x155)],'writable':![]},{'logicalPath':join(_0x566edd[_0x48260b(0x1a9)],_0x48260b(0x1df)),'physicalPath':_0x97e1c9[_0x48260b(0x1c3)],'writable':!![]},{'logicalPath':join(_0x566edd[_0x48260b(0x1a9)],_0x48260b(0x13f)),'physicalPath':_0x97e1c9[_0x48260b(0x210)],'writable':!![]});return _0xf3ff36;}[_0x50efe0(0x234)](_0x506fcd,_0x45446c,_0x5b6425=_0x506fcd[_0x50efe0(0x218)],_0xafd3f3,_0x298697){const _0x12bbc8=_0x50efe0;return this[_0x12bbc8(0x2ba)][_0x12bbc8(0x1bc)]({'policyVersion':HOST_POLICY_VERSION,'workspaceDirectory':_0x45446c[_0x12bbc8(0x155)],..._0x45446c[_0x12bbc8(0x1a9)]===undefined?{}:{'sourceWorkspacePath':_0x45446c[_0x12bbc8(0x1a9)]},'inboxDirectory':_0x506fcd[_0x12bbc8(0x1c3)],'outputDirectory':_0x506fcd[_0x12bbc8(0x210)],..._0xafd3f3===undefined||_0x298697===undefined?{}:{'generatedImagesDirectory':_0xafd3f3,'generatedImagesLogicalPath':_0x298697},'temporaryDirectory':_0x5b6425,'networkMode':_0x45446c[_0x12bbc8(0x1f6)][_0x12bbc8(0x1aa)]});}[_0x50efe0(0x259)](_0x38146d){const _0x3b1cf7=_0x50efe0,_0x52ea50=this[_0x3b1cf7(0x2ba)][_0x3b1cf7(0x1d9)][_0x3b1cf7(0x171)][_0x3b1cf7(0x2d0)](_0x3b1cf7(0x1b1))[_0x3b1cf7(0x1a1)](_0x38146d);if(_0x52ea50===undefined)return undefined;if(typeof _0x52ea50['id']!==_0x3b1cf7(0x224))throw new Error(_0x3b1cf7(0x2bc));return _0x52ea50['id'];}async[_0x50efe0(0x15f)](_0x138d70,_0x16f86f){const _0x4b996e=_0x50efe0,_0x1602ed=this[_0x4b996e(0x2ba)][_0x4b996e(0x1d9)][_0x4b996e(0x171)][_0x4b996e(0x2d0)](_0x4b996e(0x244))[_0x4b996e(0x1a1)](_0x138d70,_0x16f86f);if(_0x1602ed===undefined||_0x1602ed[_0x4b996e(0x24e)]!==_0x4b996e(0x150)&&_0x1602ed[_0x4b996e(0x24e)]!==_0x4b996e(0x221)||_0x1602ed[_0x4b996e(0x28d)]!==HOST_POLICY_VERSION||typeof _0x1602ed[_0x4b996e(0x199)]!==_0x4b996e(0x224)||typeof _0x1602ed[_0x4b996e(0x24f)]!==_0x4b996e(0x224)||typeof _0x1602ed[_0x4b996e(0x129)]!==_0x4b996e(0x224)||typeof _0x1602ed[_0x4b996e(0x1ec)]!==_0x4b996e(0x224)||typeof _0x1602ed[_0x4b996e(0x2b0)]!==_0x4b996e(0x224))throw new Error(_0x4b996e(0x2bc));const _0x5e9999=this[_0x4b996e(0x2ba)][_0x4b996e(0x239)][_0x4b996e(0x203)](_0x1602ed[_0x4b996e(0x199)]),_0x5b4ba2=join(_0x5e9999,_0x4b996e(0x295)),_0x4c1578=join(_0x5e9999,_0x4b996e(0x179)),_0x1df4c4=await lstat(_0x5b4ba2)[_0x4b996e(0x22e)](()=>undefined),_0xd19b4a=await lstat(_0x4c1578)[_0x4b996e(0x22e)](()=>undefined);if(_0x1df4c4===undefined||!_0x1df4c4[_0x4b996e(0x2c5)]()||_0x1df4c4[_0x4b996e(0x186)]()||_0xd19b4a===undefined||!_0xd19b4a[_0x4b996e(0x2a8)]()||_0xd19b4a[_0x4b996e(0x186)]()||(_0xd19b4a[_0x4b996e(0x146)]&-0x257*-0x5+0xcef+-0x16a3)!==-0x1ba4+0x1*0x251e+0xe5*-0x9)throw new Error(_0x4b996e(0x2bc));let _0xd15a87;try{const _0x59a036=await readFile(_0x5b4ba2,_0x4b996e(0x294)),_0x20e1f5=_0x59a036[_0x4b996e(0x1c0)]('\x0a')?_0x59a036[_0x4b996e(0x1b2)](0x1*-0x1337+0x233b*-0x1+0x2*0x1b39,-(0x730+-0x907*-0x3+-0x2*0x1122)):_0x59a036;if(_0x20e1f5!==_0x1602ed[_0x4b996e(0x24f)]||createHash(_0x4b996e(0x29a))[_0x4b996e(0x181)](_0x20e1f5)[_0x4b996e(0x123)](_0x4b996e(0x27d))!==_0x1602ed[_0x4b996e(0x1ec)])throw new Error(_0x4b996e(0x2bc));_0xd15a87=JSON[_0x4b996e(0x12b)](_0x20e1f5);}catch{throw new Error(_0x4b996e(0x2bc));}if(!record(_0xd15a87))throw new Error(_0x4b996e(0x2bc));const _0x38f682=publishedTemplateSnapshot(_0xd15a87),_0x54d56e=publishedTemplateDraft(_0x38f682[_0x4b996e(0x1cf)],_0xd15a87[_0x4b996e(0x1f6)]),_0x5e365b=_0x54d56e[_0x4b996e(0x1f6)],_0x318f02=publishedMcpServers(_0xd15a87[_0x4b996e(0x11d)]),_0x1ab54c=publishedTemplateContentHash(_0x38f682[_0x4b996e(0x2c7)],_0x38f682[_0x4b996e(0x1fb)],_0x38f682[_0x4b996e(0x1cf)]),_0x596c28=_0x38f682[_0x4b996e(0x1fb)][_0x4b996e(0x18e)]((_0x1744a1,_0x2d13c5)=>_0x1744a1+_0x2d13c5[_0x4b996e(0x293)],-0x50*0x5c+0x3c*-0xd+0x1fcc);if(_0xd15a87[_0x4b996e(0x140)]!==_0x1602ed[_0x4b996e(0x2b0)]||createHash(_0x4b996e(0x29a))[_0x4b996e(0x181)](JSON[_0x4b996e(0x2e1)](_0x318f02))[_0x4b996e(0x123)](_0x4b996e(0x27d))!==_0x1602ed[_0x4b996e(0x2b0)]||_0xd15a87[_0x4b996e(0x14e)]!==_0x1602ed[_0x4b996e(0x129)]||_0x1ab54c!==_0x1602ed[_0x4b996e(0x129)]||_0x1602ed[_0x4b996e(0x250)]!==_0x38f682[_0x4b996e(0x1fb)][_0x4b996e(0x26b)]||_0x1602ed[_0x4b996e(0x1f5)]!==_0x596c28)throw new Error(_0x4b996e(0x2bc));if(_0xd15a87[_0x4b996e(0x2d9)]!==_0x138d70||_0xd15a87[_0x4b996e(0x251)]!==_0x16f86f||_0xd15a87[_0x4b996e(0x212)]!==HOST_POLICY_VERSION||_0x5e365b[_0x4b996e(0x251)]!==_0x16f86f||_0x5e365b[_0x4b996e(0x269)]!==this[_0x4b996e(0x2ba)][_0x4b996e(0x269)]())throw new Error(_0x4b996e(0x2bc));return{'id':_0x138d70,'templateId':_0x16f86f,'storageKey':_0x1602ed[_0x4b996e(0x199)],'templateDirectory':_0x4c1578,..._0x38f682[_0x4b996e(0x1a9)]===undefined?{}:{'sourceWorkspacePath':_0x38f682[_0x4b996e(0x1a9)]},'draft':_0x5e365b,'modelPolicy':_0x54d56e[_0x4b996e(0x26e)],'mcpServers':_0x318f02};}}function hostedRequest(_0x5b52a6){const _0x375db9=_0x50efe0;if(!record(_0x5b52a6))throw new Error(_0x375db9(0x28c));const {__requestUserId:_0x2670ee,__template:_0x2c6f97,__marAgentModel:_0x4b9aef,__marAgentModels:_0x2a2fbf,__marAgentRuntimeScopeId:_0x14ad18,__workspaceWatchSessionHash:_0x54996e,__templateDeleted:_0x5c3cf9,..._0x1cdf25}=_0x5b52a6;if(typeof _0x2670ee!==_0x375db9(0x19e)||!Number[_0x375db9(0x1e7)](_0x2670ee)||_0x2670ee<=-0x1*-0x1372+0xc0d+-0x1f7f)throw new Error(_0x375db9(0x28c));if(_0x5c3cf9!==undefined&&_0x5c3cf9!==!![])throw new Error(_0x375db9(0x28c));if(_0x14ad18!==undefined&&(typeof _0x14ad18!==_0x375db9(0x224)||_0x14ad18[_0x375db9(0x26b)]===0x21*-0x109+0xea*-0xd+0x2e0b))throw new Error(_0x375db9(0x28c));return{'data':_0x1cdf25,'userId':_0x2670ee,..._0x2c6f97===undefined?{}:{'template':_0x2c6f97},..._0x4b9aef===undefined?{}:{'model':_0x4b9aef},..._0x2a2fbf===undefined?{}:{'models':_0x2a2fbf},..._0x14ad18===undefined?{}:{'runtimeScopeId':_0x14ad18},..._0x54996e===undefined?{}:{'sessionHash':_0x54996e},..._0x5c3cf9===!![]?{'templateDeleted':!![]}:{}};}function requireWatchSessionHash(_0x1b0d29){const _0x28bea3=_0x50efe0;if(typeof _0x1b0d29!==_0x28bea3(0x224)||_0x1b0d29[_0x28bea3(0x26b)]===0x1*0xdfe+-0x24e2+-0x14*-0x125)throw new Error(_0x28bea3(0x28c));return _0x1b0d29;}function watchOwnerKey(_0x3378a9,_0x25a6cc){return _0x3378a9+':'+_0x25a6cc;}function runtimeModels(_0x5eb1b2){const _0x5d3ff2=_0x50efe0;return marAgentRuntimeModelConfigurationSchema[_0x5d3ff2(0x247)]()[_0x5d3ff2(0x12b)](_0x5eb1b2);}function allowedModels(_0xfcd019,_0xfc90be){const _0x1c7e41=_0x50efe0,_0x1680fc=new Set(_0xfcd019[_0x1c7e41(0x26e)][_0x1c7e41(0x278)]);return _0xfc90be[_0x1c7e41(0x1a0)](_0x15d879=>_0x15d879[_0x1c7e41(0x110)]&&_0x1680fc[_0x1c7e41(0x23c)](_0xfcd019[_0x1c7e41(0x26e)][_0x1c7e41(0x163)]===_0x1c7e41(0x1c4)?_0x15d879[_0x1c7e41(0x185)]:_0x15d879['id']));}function selectModel(_0x3e8270,_0x10c499,_0x5f9a89){const _0x22e006=_0x50efe0,_0x435c02=allowedModels(_0x3e8270,_0x10c499),_0x2573cf=_0x435c02[_0x22e006(0x113)](_0x2b8bd2=>_0x2b8bd2['id']===_0x5f9a89);if(_0x2573cf!==undefined)return _0x2573cf;const _0x43b2a3=_0x435c02[_0x22e006(0x113)](_0x30658e=>(_0x3e8270[_0x22e006(0x26e)][_0x22e006(0x163)]===_0x22e006(0x1c4)?_0x30658e[_0x22e006(0x185)]:_0x30658e['id'])===_0x3e8270[_0x22e006(0x26e)][_0x22e006(0x2a6)]);if(_0x43b2a3!==undefined)return _0x43b2a3;const _0x1bd0db=_0x3e8270[_0x22e006(0x26e)][_0x22e006(0x278)][_0x22e006(0x158)](_0x3de9b7=>_0x435c02[_0x22e006(0x113)](_0xe0b854=>(_0x3e8270[_0x22e006(0x26e)][_0x22e006(0x163)]===_0x22e006(0x1c4)?_0xe0b854[_0x22e006(0x185)]:_0xe0b854['id'])===_0x3de9b7))[_0x22e006(0x113)](_0x29611b=>_0x29611b!==undefined);if(_0x1bd0db===undefined)throw new Error(_0x22e006(0x165));return _0x1bd0db;}function _0x590c(){const _0x3e8602=['DxnLCL9TzxnZywDL','CMvHzeLTywDL','ywr2yw5JzuXHC3rby3rPDML0Eq','mZqYmZnXB0f1CM0','se9tvevex0nptLzfuLnbveLptL9bvfrbq0Hnru5ux0LovKfmsuq','rwfJAcbUzxCGC2fUzgjVEcbWCM9JzxnZigHHCYbHihrLBxbVCMfYEsbit01figf0ic9OB21Ll21HCIWGyxbHCNqGzNjVBsbLEhbSAwnPDgX5ig1VDw50zwqGzgLYzwn0B3jPzxmUierVig5VDcbYzwX5ig9UieHptuuGzMLSzxmGB3iGC2HLBgWGC3rHDguGCgvYC2LZDgLUzYbIzxr3zwvUihrVB2WGzxHLy3v0Aw9UCY4GvxnLic90BxaGzM9YihjLDxnHyMXLigLUDgvYBwvKAwf0zsbMAwXLCYbHBMqGC2v0ihjLCxvPCMvKigvUDMLYB25Tzw50ihzHCMLHyMXLCYbPBIbLywnOignVBw1HBMqU','y2f0y2G','rvHfq1vusu9o','l3rTCa','tMv0D29YAYbHy2nLC3mGAxmGzgLZywjSzwqUieXVy2fSihbYB2nLC3nLCYWGv2vIifnLyxjJAcWGv2vIiezLDgnOlcbTB2rLBc1OB3n0zwqGD2vIlcbHBMqGCMvTB3rLieHuvfaGtunqignHBM5VDcb1C2uGDgHLig5LDhDVCMSU','BgfZDefJDgL2Axr5qxq','CMvHzhK','ChjVy2vZC0v4zwn1Dg9Y','se9tvevex0nptLzfuLnbveLptL9svu5Fqunusvzf','C3LUyW','D2f0y2GUAg9ZDgvKlwnVBNzLCNnHDgLVBI5ZBMfWC2HVDa','ChjLCgfYzunVBNzLCNnHDgLVBKvUDMLYB25Tzw50','C3rVCMu','uLvox1rfuK1jtKfm','D2fPDezVCLbLBMrPBMDnzxnZywDLu3rHCNrZ','AgfZ','yxbWBhLbDxrVBwf0AwnuAxrSzq','y3vYC29Y','Cgf0AhngB3jdB252zxjZyxrPB24','B2jQzwn0','CMvZCg9UC2vZuhjLDMLVDxnszxnWB25ZzuLK','BwvZC2fNzq','zw1PDfDHDgnOtgvHC2vfDMvUDa','u0vmrunuigLKlhrLBxbSyxrLx2LKlhn0yxr1CYXZDg9YywDLx2TLEsXTyw5PzMvZDcXJB250zw50x2HHC2GSBwfUAwzLC3rFAgfZAcXTy3bFy29UzMLNx2HHC2GScIaGicaGicaGicaGicaGicbMAwXLx2nVDw50lhrVDgfSx2j5DgvZlgHVC3rFCg9SAwn5x3zLCNnPB24kicaGicaGicaGrLjptsbJB252zxjZyxrPB25FDgvTCgXHDgvFDMvYC2LVBNmGv0HfuKuGAwq9pYbbtKqGDgvTCgXHDgvFAwq9pW','B3DUzxjlzxK','C3rHDa','yxjYyxK','ywnJzxb0zwrxyxrJAa','DxbSB2fKu3rHDhvZ','y29UDMvYC2f0Aw9Uu3rVCMfNzuTLEq','C3rHCNrnzxnZywDL','uLvotKLorW','CMvNAxn0zxjgAwXL','C3rHDhvZ','BwfUAwzLC3q','zMLSzv9JB3vUDa','DgvTCgXHDgvjza','Ag9TzurPCMvJDg9YEq','t19ot0zpteXpvW','l3vZCG','zgvSzxrLrMLSzq','CMvTB3zLq29UDMvYC2f0Aw9Uv2f0y2HmzwfZzxm','B3DUCW','Bwf4vxbSB2fKqNL0zxm','Bgf0zxn0qxzHAwXHyMXLvgvTCgXHDgvwzxjZAw9Uswq','yM9VBgvHBG','se9tvevex0nptLzfuLnbveLptL9gsuXfx0LovKfmsuq','vgHPCYbPCYbHie5VzguTAg9ZDgvKignVBNzLCNnHDgLVBI4GvgHLieHVC3qTzgvJBgfYzwqGBw91BNrZigfYzsb0AguGy29TCgXLDguGzMLSzsbIB3vUzgfYEs4','q09orKLhvvjbveLptL9jra','zgvMyxvSDfjLyxnVBMLUz0vMzM9YDa','vgHLihb1yMXPC2HLzcb3B3jRC3bHy2uGAxmGyw4GAw1TDxrHyMXLigfKBwLUAxn0CMf0B3iTBwfPBNrHAw5Lzcb0zw1WBgf0zsbZBMfWC2HVDc4Gq2HHBMDLCYb0BYb0AguGCMv1C2fIBguGDgvTCgXHDguGBxvZDcbIzsbTywrLigLUigL0CYbZB3vYy2uGv29YA3nWywnLigfUzcbWDwjSAxnOzwqGyxmGysbUzxCGDMvYC2LVBI4','Dw5RBM93BG','l2HVBwuVBwfY','l3DVCMTZCgfJzq','A2v5CW','yxr0ywnOBwvUDeLKCW','l2rLDG','se9tvevex0nptLzfuLnbveLptG','DxnLCKLK','CMvSzwfZzq','BM9KzuLK','D2f0y2HmzwfZzxm','BgvUz3rO','AgfZtM9Urw1WDhLvC2vYtwvZC2fNzq','uMvHzcb1C2vYihvWBg9HzhmGzNjVBsaVD29YA3nWywnLl2LUyM94lG','Bw9KzwXqB2XPy3K','zw1PDfDHDgnOrxzLBNq','DgvTCgXHDgvezwXLDgvK','zMLSzuLK','DMfSDwvZ','zw1PDfDVCMTIzw5JAev2zw50','ChjLCgfYzunVBNzLCNnHDgLVBLrLBxbVCMfYEurPCMvJDg9YEq','yMfZzvvYBa','vgHLignVBNzLCNnHDgLVBIb0zw1WBgf0zsb1CgDYywrLigzHAwXLzc4','zMLSzvbHDgG','ywXSB3DLzeLKCW','rM9SBg93ihnHDMvKignVBNzLCNnHDgLVBIbPBNn0CNvJDgLVBNmGC3vIAMvJDcb0BYb0AguGsg9ZDcDZihnLy3vYAxr5igjVDw5KyxjPzxmSihrOzsbWDwjSAxnOzwqGDgvTCgXHDguGAw5ZDhj1y3rPB25ZlcbHBMqGDgHLihvZzxiNCYbJDxjYzw50igv4CgXPy2L0ihjLCxvLC3qU','ChjLDMLVDxnwzxjZAw9Uswq','rg8GBM90igrLC2nYAwjLigvKAxrZihvUzgvYic93B3jRC3bHy2uVAw5IB3GGB3iGl3DVCMTZCgfJzs9VDxrWDxqGyxmGy2HHBMDLCYb0BYb0AguGCMv1C2fIBguGDgvTCgXHDguU','revmrvrfra','Agv4','q09nueXfveve','tK9erq','DxbNCMfKzq','Ag9ZDgvKv2vIu2vHCMnO','ndy0nZyWovHhCePcEG','y29TCgXLDgvvCgXVywq','y29Kzu1Vzgu','DgL0BgvdAgfUz2vK','tufyx1nbrKvFsu5uruDfuG','ywrK','DgHLBG','zgvSzxrL','uvvpvefFrvHdruveruq','CNvUoG','se9tvevex0nptLzfuLnbveLptL9ot1rFqvvuse9ssvPfra','Ag9ZDf9WB2XPy3LFDMvYC2LVBG','v2HLBIb0AguGDxnLCIbHC2TZihrVihbSywnLigeGChjLDMLVDxnSEsbNzw5LCMf0zwqGAw1Hz2uGAw4GB3v0Chv0lcbPBNnWzwn0ia','CgvYBwfUzw50rgvSzxrLq29UDMvYC2f0Aw9U','vvnfuG','AxndB252zxjZyxrPB25jBLvZzq','DxbSB2fKuhjLzMXPz2H0u3rHDhvZ','C2L6zq','DxrMoa','BwfUAwzLC3qUANnVBG','y2XPzw50uMvXDwvZDeLK','DxbKyxrLq29UzMLNDxjHDgLVBG','BMv4DfDVCMTIzw5JAev2zw50','DgvZDa','C2HHmJu2','zgLZCgXHEu5HBwu','ihrVic93B3jRC3bHy2uVB3v0Chv0ihDOzw4GyxzHAwXHyMXLlIbjzIbPDcbPCYbTAxnZAw5NlcbYzxbVCNqGDgHHDcbMywn0oYbYzwDLBMvYyxrLig9UBhKGD2HLBIbYzxf1zxn0zwqGB3iGyxv0Ag9YAxPLzcbIEsb0AguGDxnLCI4','CMv0ywLUq29UDMvYC2f0Aw9UvgvTCgXHDgu','yxnZzxj0q2fUq3jLyxrL','q09ovKvsu0fusu9ox0Hpu1rjtKDFvu5bvKfjtefcteu','CxvVDgfZ','C25HChnOB3rtzxf1zw5Jzq','A2LUza','y29UzMLNDxjHDgLVBIXKAxnWBgf5tMfTzsXPzcXVCMLNAw4SCNvUDgLTzsXZzxj2zxjoyw1LlhrYyw5ZCg9YDcX2zxjZAw9U','C3rHCNrsDw4','CMvJzwL2zwrcExrLCW','zgvMyxvSDeLK','CMvZB2X2zwruyxjNzxq','AxneAxjLy3rVCNK','sfruua','vvbmt0fe','CMvXDwLYzvvWBg9Hza','C3rHCNrZv2L0Aa','ywn0AxzPDgLLCW','CgLUBMvKqxq','AgLZDg9YEvzLCNnPB25Z','BwnWx2nVBMzPz19OyxnO','se9tvevex0nptLzfuLnbveLptL9vueXpqurFu1rbvevFsu5wquXjra','D2f0y2GUzMfPBgvK','yMvNAw5dB252zxjZyxrPB25dBgvHBNvW','BgLZDa','DxbKyxrLtwv0ywrHDge','zxHWAxjLC0f0','BgLZDenVBNzLCNnHDgLVBNm','Bg9JywWTDgvZDc1Nzw5LCMf0Aw9U','ywn0AxzLvMvYC2LVBKLK','B3b0Aw9UCW','zMLUAxnOtwvZC2fNzq','q09ovKvsu0fusu9ox1rftvbmqvrfx1zfuLnjt05Fq09suLvqveve','C3vTBwfYEq','CMvXDwLYzunVBNzLCNnHDgLVBG','DgvTCgXHDgu','l2jPBG','tufsx0fhru5ux1jpteXcqunlx1rbuKDfvf9jtLzbteLe','DgfYz2v0s2LUza','zMLUAxnOuNvU','zxHWzwn0zwrjBNrLCNj1ChrPB25Z','AxngAwXL','Aw5PDgLHBgL6zvDHDgnOtgvHC2u','zgLYzwn0B3jPzxm','qxqGDgHLihn0yxj0ig9MigvHy2GGCNvUlcbYzwfKic93B3jRC3bHy2uVAw5IB3GVquDftLrtlM1KigLMigL0igv4Axn0CY4GsxqGC3rVCMvZignVBNzLCNnHDgLVBI1ZCgvJAwzPyYbYzxf1AxjLBwvUDhmGzM9YigXHDgvYihj1BNmGyw5KigLZig5VDcbWyxj0ig9MihrOzsbWDwjSAxnOzwqGDgvTCgXHDguU','DxnLCLn0B3jHz2vlzxK','D29YA2jLBMnOu2vXDwvUy2u','Dg9tDhjPBMC','u1LnteLosW','BM90AwzPy2f0Aw9U','surmrq','qxr0ywnOBwvUDhm6cG','ChjLCgfYzq','CM9SBgjHy2TdB252zxjZyxrPB24','C3vJy2vZCW','vgHLihb1yMXPC2HLzcb3B3jRC3bHy2uGCM9VDcbPCYbYzwfKlw9UBhKUifDPDgHPBIaVD29YA3nWywnLlcbVBMX5ic93B3jRC3bHy2uVAw5IB3GGyw5Kic93B3jRC3bHy2uVB3v0Chv0igfYzsb3CML0ywjSzs4','y3jLyxrLq29UDMvYC2f0Aw9U','Cgf0Ahm','ChvIBgLZAfvWz3jHzgvgywLSDxjL','q0foq0vmteve','C2vZC2LVBLDHDgnOu2XVDhm','DMvYC2LVBKLK','zMLUze1LC3nHz2u','zMXHDe1HCa','BM9KzufWCfzLCNnPB24','se9tvevex0nptLzfuLnbveLptL9st0XmqKfds19uqvjhrvrFsu5wquXjra','Aw5V','u1vdq0vfreve','DxbKyxrLzef0','C3rYAw5NAwz5','Dhj1BMm','mteWmtCZofbSEuHNzq','zgf0yujHC2u2na','q09orKXjq1q','y3vYCMvUDfzLCNnPB25jza','nJaYnffquvvgra','r2vUzxjHDgvKigLTywDLCYbMCM9TihrOAxmGy29UDMvYC2f0Aw9UihjLBwfPBIbHDMfPBgfIBguGywnYB3nZigv4zwn1DgLVBNmGAw4GDgHLihjLywqTB25SEsa','vvbmt0fesu5h','l3bYB2m','CMvSzwfZzunVBNzLCNnHDgLVBKzVCKnSzwfUDxa','CMvXDwLYzuf0DgfJAg1LBNq','BM93','DgfYz2v0vMvYC2LVBKLK','ChvIBgLZAfDVCMTIzw5JAev2zw50','y29UDgv4DfDPBMrVD1rVA2vUCW','qunusvzf','D2f0y2G','CMvJB25JAwXLrMLSzxm','zw5HyMXLza','Aw5WDxrdyxbHyMLSAxrPzxm','DgvTCg9Yyxj5ugf0Aa','zMLUza','zgvZy3jPChrPB24','D3jPDgvvCgXVywrdAhvUAW','yNL0zuXLBMD0Aa','u0vtu0LptL9xqvrdsf9ot1rFrK9vtKq','lNvWBg9Hza','mtbdDgLtAgO','l3j1BG','t19sre9otfK','C3rHCNrLzef0','BwnWu2vYDMvYCW','BgLTAxq','se9tvevex0nptLzfuLnbveLptL9gsuXfx0nptKzmsunu','CMvWBgfJzq','su5urvjsvvburuq','CNvUu2v0DgXLBwvUDhm','zgLNzxn0','y29UDMvYC2f0Aw9UrgLYzwn0B3j5','vu5srvnuuKLdveve','B2zMC2v0','zMLSzq','B3jPz2LU','y29UDgvUDf9OyxnO','ntaYme94v2DWDG','CgfYC2u','zMLSzxm','CgvUzgLUz01LC3nHz2vZ','se9tvevex0nptLzfuLnbveLptL9vueXpqurFt0zgu0vux0LovKfmsuq','y2fUy2vSvxbSB2fK','Aw50zxjYDxb0','se9tvevex0nptLzfuLnbveLptL9vueXpqurFtK9ux0zpvu5e','zMLUzeLUzgv4','DgfYz2v0ugf0Aa','yMvMB3jL','uKvbrfK','Aw1Hz2vjBMrLEa','q09ovKvsu0fusu9ox1rftvbmqvrfx01duf9jtLzbteLe','Bg9JywXLq29TCgfYzq','DgL0Bgu','C2f2zu1LC3nHz2vby2nLChrHBMnL','D2f0y2HmzwfZzvrPBwvY','BxrPBwvnCW','y2XLyw51CeXVy2TZ','vgHLieHVC3qGzw5MB3jJzxmGDgHPCYbMAwXLigjVDw5Kyxj5lcbHBMqGBg9JywWGChjVy2vZC2vZihj1BIbPBNnPzguGyw4GB3bLCMf0Aw5Nlxn5C3rLBsbZyw5KyM94lG','B3v0Chv0','BwnWq29UzMLNsgfZAa','y2XPzw50twvZC2fNzuLK','D3jPDgu','igfZigeGy29TCgf0AwjPBgL0EsbHBgLHCZSGAxqGAxmGDgHLihnHBwuGAw1TDxrHyMXLihnUyxbZAg90lcbUB3qGDgHLigXPDMuGC291CMnLifDVCMTZCgfJzs4G','zgLZCg9Zzq','Dw5Yzwy','Bw9Kzq','yMfZzty0','l3DVCMTZCgfJzs9PBMjVEa','ywXSB3DLze1VzgvSswrZ','ywn0AxzLuNvUCW','BgLZDezPBgvZ','sg9ZDgvKignVBNzLCNnHDgLVBIbMAwXLihbYB2PLy3rPB24GzMfPBgvKlG','DgL0BgvtB3vYy2u','y29UDgvUDeHHC2G','C29Tzq','qvzbsuXbqKXf','CMvSyxrPDMvqyxrO','DhjHBNnWB3j0','u1rbuLrjtKC','ChjLCgfYzuzVCKrPC2fIBgu','DgvTCgXHDgveAxjLy3rVCNK','igfYzsbHBgLHC2vZig9MihrOzsbZyw1LihDYAxrHyMXLig92zxjSyxLZlG','y2f0zwDVCNK','BwfW','Bwf4qNL0zxm','ChvIBgLZAfj1BNrPBwvfDMvUDa','CMvHzezPBgu','zMLUywXSEq','se9tvevex0nptLzfuLnbveLptL9xqvrdsf9gquLmruq','se9tvevex0nptLzfuLnbveLptL9rvu9uqv9fwenfrurfra','Bg9HzfrLBxbSyxrLvMvYC2LVBG','ChvIBgLZAeHVC3rLzev2zw50','mtK2mdi4m0PVvLDoCq','CgvUzgLUz0nYzwf0zxm','AwrLBNrPDhK','zMLSzvbYB2PLy3rPB25jza','se9tvevex0nptLzfuLnbveLptL9nt0rftf9ot1rFqvzbsuXbqKXf','DxbSB2fKCW','uLvox0LnquDfx05pvf9gt1vora','CgvUzgLUz0v2zw50CW','q0foq0vmteLorW','y3rPBwvnCW','CNvUswq','y2fUy2vS','DMvYC2LVBG','u05bufnit1q','Cgf0AhngB3jnyw5PzMvZDa','u1resu8','CMf3','DgLTzxi','se9tvevex0nptLzfuLnbveLptL9gsuXfx1jfq09oq0Lmrv9gquLmruq','Bw9KzwXZ','zgv2','igrPCMvJDg9YEs4','Bwf4','C2fMzvbHCNnL','y29UDgvUDa','C2vZC2LVBKLK','CMvXDwLYzvDYAxrHyMXLq29UDMvYC2f0Aw9U','CMvHza','mtCWmtzpvhDQr0W','revgqvvmva','CMvHC29UAw5NrwzMB3j0CW','AM9PBG','DxbKyxrL','zNjVBq','yxjNDw1LBNrZ','ndiWn3HzwxfyAa','Bw9KzwXjza','AxntEw1IB2XPy0XPBMS','D29YA2jLBMnOq29UBMvJDgLVBKLK','ChjVBxb0','CNvUDgLTzq','sg9ZDgvKignVBNzLCNnHDgLVBIb3yxrJAcbZBMfWC2HVDcbMywLSzwqU','se9tvevex0nptLzfuLnbveLptL9trvntsu9ox0LovKfmsuq','BwLTzvr5Cgu','C2f2zuf1Dg9TyxrPy1rPDgXL','CMvKDwnL','ntuYnNPuq1j5AG','CMvUzxC','CNvUDgLTzvnJB3bLswq','tg9JywWGChjVy2vZC2vZlcboB2rLlwXVy2fSifDLyIbgzxrJAcWGyxzHAwXHyMXLifDLyIbtzwfYy2GSig1VzgvSlwHVC3rLzcb3zwiSigfUzcbWDwjSAxnOzwqGCMvTB3rLieHuvfaGtunqig1HEsbHy2nLC3mGBMv0D29YA3mGCMvHy2HHyMXLigzYB20GDgHPCYboB2rLlG','l3nIAw4','reLsrunut1jzaa','y3jLyxrLu2vZC2LVBG','CMvTB3zLv2f0y2HmzwfZzq','C2vJCMv0tMfTzq','CMvXDwLYzuzPBgu','C3rVCMfNzv9RzxK','zw52AxjVBM1LBNq','DxjS','C2vYDMvYtMfTzq','zw4Tvvm','BNvTyMvY','DgvTCgXHDgvoyw1L','zMLSDgvY','z2v0','C29YDa','C2v0','C2vJCMv0rw52AxjVBM1LBNq','uLvoveLnrq','y29TBwfUza','yxzHAwXHyMXL','se9tvevex0nptLzfuLnbveLptL9gsuXfx1jbtKDfx0LovKfmsuq','C291CMnLv29YA3nWywnLugf0Aa','BMv0D29YA01Vzgu','CMv3Aw5K','y29Kzq','mZzjqNnXtNe','Ag9ZDgvKlwnVBNzLCNnHDgLVBG','DhjPBq','DxnLzej5DgvZ','u0vmrunuigLKiezst00Gy29UDMvYC2f0Aw9Ux3rLBxbSyxrLx3zLCNnPB25ZcIaGicaGicaGifDirvjfihrLBxbSyxrLx2LKpt8Gqu5eihn0yxr1CZ0NqvzbsuXbqKXfjWOGicaGicaGicbpuKrfuIbcwsb2zxjZAw9Ux251BwjLCIbervndlhb1yMXPC2HLzf9HDcbervndlgLKierfu0mkicaGicaGicaGteLnsvqGmq','C2XPy2u','zMLUzenVBNzLCNnHDgLVBKj5q2XPzw50uMvXDwvZDa','ChjVDg9JB2W','y3jLyxrL','CM9SBgjHy2S','CMvQzwn0','Dw53yxrJAa','rKfjteve','y3jLyxrLzef0','ve9px0XbuKDf','ChjVy2vZC0v4zwn1Dg9YrMfJDg9YEq','yxjNCW','DhvYBKLK','Cgf0Ae1VDw50CW','zw5KC1DPDgG','zgLZywjSzvbYzxbHCMvK','lsaVD29YA3nWywnLl2LUyM94lW','DxbSB2fKC0rPCMvJDg9YEq','vvbtvfjfqu1Ftu9eruXFsuq','se9tvevex0nptLzfuLnbveLptL9vueXpqurFu0LArv9jtLzbteLe','se9tvevex0nptLzfuLnbveLptL9vueXpqurFsu5dt01qtevurq','zxHLy3v0ywjSzq','AxngAw5PDgu','BM9KzuDLBMvYyxrPB24','y29UzMLNDxjHDgLVBG','q1vtve9n','AgLZDg9YEu11Dgf0Aw9UCW','y3jLyxrLvxbSB2fK','ChvIBgLZAeHVC3rLzfnUyxbZAg90','C2nOzw1HvMvYC2LVBG','te9tva','CMvHzfnUyxbZAg90','AgLZDg9YEq','rKLmrq','CgLUBMvK','mtq1ntjbD1HoC20','l3DVCMTZCgfJzs9VDxrWDxq','C3vIyxjYyxK','DxbSB2fKswq','zgf0ywjHC2u','C25HChnOB3q','se9tvevex0nptLzfuLnbveLptL9vueDsqurfx0zbsuXfra','CxvVDge','B3bLCMf0Aw9UCW','ChvIBgLZAefJDgL2Axr5','Aw5IB3G','v09ss1nqqunf','tMv3ignVBNzLCNnHDgLVBG','yNL0zxnszwfK','ywn0AxzPDhK','vgHLihb1yMXPC2HLzcb3B3jRC3bHy2uGAxmGywXZBYbTB3vUDgvKihjLywqTB25SEsbHDca','CMvSzwfZzvnLC3nPB24','y29TCgXLDgvKqxq','AxntywzLsw50zwDLCG','odHkyK9SwuK','u3rVCMuGzgLZCg9ZywjSzsbPBNrLCM1LzgLHDguGD29YAYbPBIaVDg1WlIbjDcbPCYbYzxvZzwqGywnYB3nZihj1BNmGAw4GDgHPCYbJB252zxjZyxrPB24Sigj1Dcb0AguGsg9ZDcbTyxKGy2XLyxiGAxqGywnJB3jKAw5NihrVihrOzsbZExn0zw0GDgvTCg9Yyxj5lwrPCMvJDg9YEsbSAwzLy3LJBguU','AgvHzgvYCW','BMfTzq','BwfUAwzLC3rFAgfZAa','ugXHy2uGzMLUywWGzgvSAxzLCMfIBgvZigLUigfWChjVChjPyxrLihbHDgHZihvUzgvYic93B3jRC3bHy2uVB3v0Chv0ihnVihrOzxKGyMvJB21LihvZzxiTDMLZAwjSzsbVDxrWDxrZlG','BwLU','igfUzcbJB3b5ihrOzsbLEgLZDgLUzYbMAwXLigzYB20G','Aw5JBhvKzxm','ChvZAa','Bwf4u3rVCMfNzuj5DgvZ','l2XPyJy0','uMvHzcbPDhmGzxHPC3rPBMCGy29UDgvUDhmGzMLYC3qGyw5KihbYzxnLCNzLihvUCMvSyxrLzcbPBNn0CNvJDgLVBNmUierVig5VDcbWzxjZAxn0igeGChjLzMvYzw5JzsbTzxjLBhKGyMvJyxvZzsbPDcbHChbLyxjZigLUihrOzsbJDxjYzw50ihjLCxvLC3qGDw5SzxnZihrOzsb1C2vYigfZA3mGEw91ihrVihjLBwvTyMvYigL0lG','Dg90ywXFyNL0zxm','zhjHzNq','BMXPBMS','DxbKyxrLq29UDMvYC2f0Aw9U','DgL0Bgvhzw5LCMf0Aw9U','ywXSB2m','zw50CMLLCW','CMvZCg9UC2vZvhjHBNnWB3j0','zNvSBc1Hy2nLC3m','y3jLyxrLtwvZC2fNzq','l2XPyG','zMLSzurLBgv0zxm','tK9orq','C2vZC2LVBKHHC2G','DgvTCgXHDgvwzxjZAw9UrgLYzwn0B3j5','C2XVDfrVA2vU','y2XVC2u','C3bSAxq','B3v0Chv0q2fWywjPBgL0AwvZ','CMvZB2X2zq','ywXSu2v0DgXLza','y29UDMvYC2f0Aw9Uswq','ChvIBgLZAfrLCM1PBMfStM90AwzPy2f0Aw9U','ywXSB3DLze1VzgvSCW','BgLUA1rHCMDLDa','DxbSB2fKC0j5uMvXDwvZDa','CNvU','B3v0Chv0rgLYzwn0B3j5','v2HLBIb0AguGDxnLCIbLEhbSAwnPDgX5igfZA3mGEw91ihrVihjLBwvTyMvYigeGCMvXDwLYzw1LBNqSihbYzwzLCMvUy2uSignVBNzLBNrPB24SihDVCMTMBg93ihj1BguSig9Yig90AgvYigD1AwrHBMnLigzVCIbSyxrLCIb3B3jRigLUihrOAxmGy29UDMvYC2f0Aw9UlcbJCMvHDguGB3iGDxbKyxrLic93B3jRC3bHy2uVAw5IB3GVquDftLrtlM1KlG','Ag9ZDfbVBgLJEvzLCNnPB24','D2f0y2GUAg9ZDgvKlwnVBNzLCNnHDgLVBI5LDMvUDa','ru5pru5u','igfUzca','yM91BMrHCNK','zgf0yq','DgvTCg9Yyxj5uM9VDerPCMvJDg9YEq','ywXS','AxrLBxm','D2f0y2Hjza','y29UDMvYC2f0Aw9U','se9tvevex0nptLzfuLnbveLptL9tvefurv9jtLzbteLe','ChjLzMXPz2H0vxbSB2fK','y2fUy2vSq29UDMvYC2f0Aw9UvxbSB2fKCW','y29TCgXLDgLVBG','uKvuquLoruq','v2HLBIbYzxbVCNrPBMCGyw4GB3v0Chv0igzPBguGDg8GDgHLihvZzxiSihvZzsbHie1HCMTKB3DUigXPBMSGAw4GDgHLigv4ywn0igzVCM0Gw3jLBgf0AxzLl3bHDgHDkc93B3jRC3bHy2uVB3v0Chv0l3jLBgf0AxzLl3bHDgGPihnVihrOzsb1C2vYignHBIbVCgvUigL0CYbJB250CM9SBgvKihbYzxzPzxCGB3iGzg93BMXVywqU','l3j1BNrPBwu','C3rYAw5N','Bwf4t3v0Chv0vg9Rzw5Z','AxnbCNjHEq','se9tvevex0nptLzfuLnbveLptL9uru1qtefurv9vtKfwquLmqujmrq'];_0x590c=function(){return _0x3e8602;};return _0x590c();}function publishedTemplateDraft(_0x4486db,_0x98bb4d){const _0x4921b3=_0x50efe0,_0x255752=conversationTemplateDraftSchema[_0x4921b3(0x178)](_0x98bb4d);if(_0x255752[_0x4921b3(0x2d2)]){const {allowedModels:_0x3142da,defaultModelId:_0x5874a4,..._0x5b3dbf}=_0x255752[_0x4921b3(0x217)];return{'draft':_0x5b3dbf,'modelPolicy':{'identity':_0x4921b3(0x1c4),'allowedIds':_0x3142da[_0x4921b3(0x158)](_0x341cf3=>_0x341cf3[_0x4921b3(0x185)]),'defaultId':_0x5874a4}};}if(_0x4486db!==-0x169*-0x2+0x4*-0x83+-0xc5||!record(_0x98bb4d)||_0x4921b3(0x20c)in _0x98bb4d||!Array[_0x4921b3(0x226)](_0x98bb4d[_0x4921b3(0x149)]))throw new Error(_0x4921b3(0x2bc));const _0x32e24f=_0x98bb4d[_0x4921b3(0x149)],_0x43377a={..._0x98bb4d};delete _0x43377a[_0x4921b3(0x149)];const _0x441141=conversationTemplateDraftSchema[_0x4921b3(0x178)]({..._0x43377a,'allowedModels':_0x32e24f[_0x4921b3(0x158)](_0x1f0e7c=>({'modelId':_0x1f0e7c,'name':_0x1f0e7c}))});if(!_0x441141[_0x4921b3(0x2d2)])throw new Error(_0x4921b3(0x2bc));const {allowedModels:_0x5e2aed,defaultModelId:_0x2baee4,..._0x849f3a}=_0x441141[_0x4921b3(0x217)];return{'draft':_0x849f3a,'modelPolicy':{'identity':_0x4921b3(0x25d),'allowedIds':_0x5e2aed[_0x4921b3(0x158)](_0x5ad5e8=>_0x5ad5e8[_0x4921b3(0x185)]),'defaultId':_0x2baee4}};}function networkModels(_0x5ae170,_0x411a70){const _0x23858a=_0x50efe0;if(_0x411a70!==_0x23858a(0x201))return _0x5ae170;return _0x5ae170[_0x23858a(0x158)](_0x53eb10=>_0x53eb10[_0x23858a(0x281)]?{..._0x53eb10,'hostedWebSearch':![]}:_0x53eb10);}function publishedMcpServers(_0x342be2){const _0xf606fc=_0x50efe0;if(!Array[_0xf606fc(0x226)](_0x342be2))throw new Error(_0xf606fc(0x2bc));return _0x342be2[_0xf606fc(0x158)](_0x2aaffc=>{const _0x4e9c37=_0xf606fc;if(!record(_0x2aaffc))throw new Error(_0x4e9c37(0x2bc));const _0x5ba9c9=Object[_0x4e9c37(0x263)](_0x2aaffc)[_0x4e9c37(0x1a2)]()[_0x4e9c37(0x180)](',');if(_0x5ba9c9!==_0x4e9c37(0x2a3))throw new Error(_0x4e9c37(0x2bc));const _0x4a0653=mcpRuntimeDescriptorSchema[_0x4e9c37(0x12b)](_0x2aaffc[_0x4e9c37(0x189)]),_0x2478c7=mcpInstallationConfigurationSchema[_0x4e9c37(0x12b)](_0x2aaffc[_0x4e9c37(0x1ca)]);if(typeof _0x2aaffc['id']!==_0x4e9c37(0x224)||typeof _0x2aaffc[_0x4e9c37(0x19c)]!==_0x4e9c37(0x224)||typeof _0x2aaffc[_0x4e9c37(0x29b)]!==_0x4e9c37(0x224)||typeof _0x2aaffc[_0x4e9c37(0x16d)]!==_0x4e9c37(0x224)||_0x2aaffc[_0x4e9c37(0x128)]!==_0x4e9c37(0x27f)&&_0x2aaffc[_0x4e9c37(0x128)]!==_0x4e9c37(0x1e0)||_0x2aaffc[_0x4e9c37(0x152)]!==_0x4a0653[_0x4e9c37(0x152)])throw new Error(_0x4e9c37(0x2bc));return{'id':_0x2aaffc['id'],'serverName':_0x2aaffc[_0x4e9c37(0x19c)],'displayName':_0x2aaffc[_0x4e9c37(0x29b)],'version':_0x2aaffc[_0x4e9c37(0x16d)],'origin':_0x2aaffc[_0x4e9c37(0x128)],'transport':_0x4a0653[_0x4e9c37(0x152)],'runtime':_0x4a0653,'configuration':_0x2478c7};});}function publishedTemplateSnapshot(_0x177d2a){const _0x460661=_0x50efe0;if(_0x177d2a[_0x460661(0x1cf)]===0xfb1+0x1*0x287+-0x1237){const _0xc86ff3=publishedTemplateFiles(_0x177d2a[_0x460661(0x12c)]);return{'schemaVersion':0x1,'directories':legacyPublishedTemplateDirectories(_0xc86ff3),'entries':_0xc86ff3};}if(_0x177d2a[_0x460661(0x1cf)]!==-0x6cb+-0x256e+0x2c3b||typeof _0x177d2a[_0x460661(0x1a9)]!==_0x460661(0x224)||!Array[_0x460661(0x226)](_0x177d2a[_0x460661(0x2c7)])||!Array[_0x460661(0x226)](_0x177d2a[_0x460661(0x1fb)]))throw new Error(_0x460661(0x2bc));validatePublishedSourceWorkspacePath(_0x177d2a[_0x460661(0x1a9)]);const _0x1b39fc=_0x177d2a[_0x460661(0x2c7)][_0x460661(0x158)](safePublishedTemplateRelativePath);if(new Set(_0x1b39fc)[_0x460661(0x293)]!==_0x1b39fc[_0x460661(0x26b)]||_0x1b39fc[_0x460661(0x1f0)](_0x460661(0x1df))||_0x1b39fc[_0x460661(0x1f0)](_0x460661(0x13f)))throw new Error(_0x460661(0x2bc));const _0x5cc9f3=_0x177d2a[_0x460661(0x1fb)][_0x460661(0x158)](publishedTemplateEntry);if(new Set(_0x5cc9f3[_0x460661(0x158)](_0x2d463f=>_0x2d463f[_0x460661(0x151)]))[_0x460661(0x293)]!==_0x5cc9f3[_0x460661(0x26b)])throw new Error(_0x460661(0x2bc));return{'schemaVersion':0x2,'sourceWorkspacePath':_0x177d2a[_0x460661(0x1a9)],'directories':_0x1b39fc,'entries':_0x5cc9f3};}function publishedTemplateEntry(_0x30591f){const _0x29218c=_0x50efe0;if(!record(_0x30591f))throw new Error(_0x29218c(0x2bc));if(_0x30591f[_0x29218c(0x2a2)]===_0x29218c(0x1d3))return publishedTemplateFile(_0x30591f,!![]);if(_0x30591f[_0x29218c(0x2a2)]!==_0x29218c(0x2cc)||typeof _0x30591f[_0x29218c(0x20d)]!==_0x29218c(0x224)||_0x30591f[_0x29218c(0x20d)][_0x29218c(0x26b)]===-0x210c+0x1*-0x280+0x28a*0xe||_0x30591f[_0x29218c(0x20d)][_0x29218c(0x1f0)]('\x00')||_0x30591f[_0x29218c(0x2c2)]!==_0x29218c(0x16e)&&_0x30591f[_0x29218c(0x2c2)]!==_0x29218c(0x1a5)||typeof _0x30591f[_0x29218c(0x2a7)]!==_0x29218c(0x224))throw new Error(_0x29218c(0x2bc));const _0x50f6b1=safePublishedTemplateRelativePath(_0x30591f[_0x29218c(0x151)]),_0x5eaa6f=safePublishedTemplateSize(_0x30591f[_0x29218c(0x293)]),_0x7d1aa0=_0x30591f[_0x29218c(0x20d)],_0x2a9f33=_0x30591f[_0x29218c(0x2c2)],_0xd128c1=_0x30591f[_0x29218c(0x2a7)];if(_0x5eaa6f!==Buffer[_0x29218c(0x116)](_0x7d1aa0))throw new Error(_0x29218c(0x2bc));if(_0x2a9f33===_0x29218c(0x16e))safePublishedTemplateRelativePath(_0xd128c1);else{if(!isAbsolute(_0xd128c1)||!RUNTIME_LINK_ROOTS[_0x29218c(0x14f)](_0x3ded37=>_0xd128c1===_0x3ded37||within(_0x3ded37,_0xd128c1)))throw new Error(_0x29218c(0x2bc));}return{'kind':_0x29218c(0x2cc),'relativePath':_0x50f6b1,'size':_0x5eaa6f,'linkTarget':_0x7d1aa0,'targetKind':_0x2a9f33,'resolvedTarget':_0xd128c1};}function publishedTemplateFiles(_0x37282c){const _0x595954=_0x50efe0;if(!Array[_0x595954(0x226)](_0x37282c))throw new Error(_0x595954(0x2bc));const _0x293232=new Set();return _0x37282c[_0x595954(0x158)](_0x18b8f0=>{const _0x5d185b=_0x595954,_0x2ed23e=publishedTemplateFile(_0x18b8f0);if(_0x293232[_0x5d185b(0x23c)](_0x2ed23e[_0x5d185b(0x151)]))throw new Error(_0x5d185b(0x2bc));return _0x293232[_0x5d185b(0x287)](_0x2ed23e[_0x5d185b(0x151)]),_0x2ed23e;});}function publishedTemplateFile(_0x5136d4,_0x5f03d3=![]){const _0x1cb616=_0x50efe0;if(!record(_0x5136d4)||_0x5f03d3&&_0x5136d4[_0x1cb616(0x2a2)]!==_0x1cb616(0x1d3)||typeof _0x5136d4[_0x1cb616(0x1c7)]!==_0x1cb616(0x25a)||typeof _0x5136d4[_0x1cb616(0x29a)]!==_0x1cb616(0x224)||!/^[a-f0-9]{64}$/u[_0x1cb616(0x299)](_0x5136d4[_0x1cb616(0x29a)]))throw new Error(_0x1cb616(0x2bc));return{'kind':_0x1cb616(0x1d3),'relativePath':safePublishedTemplateRelativePath(_0x5136d4[_0x1cb616(0x151)]),'size':safePublishedTemplateSize(_0x5136d4[_0x1cb616(0x293)]),'executable':_0x5136d4[_0x1cb616(0x1c7)],'sha256':_0x5136d4[_0x1cb616(0x29a)]};}function safePublishedTemplateRelativePath(_0x2e0c61){const _0x41e0b2=_0x50efe0;if(typeof _0x2e0c61!==_0x41e0b2(0x224)||_0x2e0c61[_0x41e0b2(0x26b)]===0x2512+0x258+0x3f1*-0xa||_0x2e0c61[_0x41e0b2(0x2ac)]('/')||_0x2e0c61[_0x41e0b2(0x1f0)]('\x5c')||_0x2e0c61[_0x41e0b2(0x206)]('/')[_0x41e0b2(0x14f)](_0x773e4=>_0x773e4[_0x41e0b2(0x26b)]===0x821*0x1+-0x6c*0x43+0x1423||_0x773e4==='.'||_0x773e4==='..'))throw new Error(_0x41e0b2(0x2bc));return _0x2e0c61;}function safePublishedTemplateSize(_0x23301b){const _0x35724f=_0x50efe0;if(!Number[_0x35724f(0x1e7)](_0x23301b)||_0x23301b<0x903+-0xd82+0x47f)throw new Error(_0x35724f(0x2bc));return _0x23301b;}function legacyPublishedTemplateDirectories(_0x15da25){const _0x37f79d=_0x50efe0,_0x4b88f3=new Set();for(const _0x11c34a of _0x15da25){const _0x157bcb=_0x11c34a[_0x37f79d(0x151)][_0x37f79d(0x206)]('/');for(let _0x4af613=0x238+0x18f9+0xe8*-0x1e;_0x4af613<_0x157bcb[_0x37f79d(0x26b)];_0x4af613+=0xb85*-0x2+-0x796+-0x1ea1*-0x1)_0x4b88f3[_0x37f79d(0x287)](_0x157bcb[_0x37f79d(0x1b2)](0x912*0x3+0x21cb+-0x2a7*0x17,_0x4af613)[_0x37f79d(0x180)]('/'));}return[..._0x4b88f3][_0x37f79d(0x1a2)]((_0x934e2f,_0x363368)=>_0x934e2f[_0x37f79d(0x138)](_0x363368,_0x37f79d(0x19d)));}function publishedTemplateContentHash(_0x365d05,_0x1f448f,_0x4c9608){const _0x373b5d=_0x50efe0,_0x2347f5=_0x4c9608===-0x21c*0x9+0x25d0+-0x3d*0x4f?_0x1f448f[_0x373b5d(0x158)](_0x4600c4=>{const _0x539e6f=_0x373b5d;if(_0x4600c4[_0x539e6f(0x2a2)]!==_0x539e6f(0x1d3))throw new Error(_0x539e6f(0x2bc));return _0x4600c4[_0x539e6f(0x151)]+'\x00'+_0x4600c4[_0x539e6f(0x293)]+'\x00'+_0x4600c4[_0x539e6f(0x29a)];})[_0x373b5d(0x180)]('\x0a'):[..._0x365d05[_0x373b5d(0x158)](_0x4debbf=>_0x373b5d(0x194)+_0x4debbf),..._0x1f448f[_0x373b5d(0x158)](_0xe89431=>_0xe89431[_0x373b5d(0x2a2)]===_0x373b5d(0x1d3)?_0xe89431[_0x373b5d(0x2a2)]+'\x00'+_0xe89431[_0x373b5d(0x151)]+'\x00'+_0xe89431[_0x373b5d(0x293)]+'\x00'+(_0xe89431[_0x373b5d(0x1c7)]?-0x1*0x417+-0x18e1*-0x1+-0x14c9:0x18d2+0x133c+-0x2c0e)+'\x00'+_0xe89431[_0x373b5d(0x29a)]:_0xe89431[_0x373b5d(0x2a2)]+'\x00'+_0xe89431[_0x373b5d(0x151)]+'\x00'+_0xe89431[_0x373b5d(0x293)]+'\x00'+_0xe89431[_0x373b5d(0x20d)]+'\x00'+_0xe89431[_0x373b5d(0x2c2)]+'\x00'+_0xe89431[_0x373b5d(0x2a7)])][_0x373b5d(0x180)]('\x0a');return createHash(_0x373b5d(0x29a))[_0x373b5d(0x181)](_0x2347f5)[_0x373b5d(0x123)](_0x373b5d(0x27d));}function validatePublishedSourceWorkspacePath(_0x1ac687){const _0x4fb7da=_0x50efe0;if(!isAbsolute(_0x1ac687)||resolve(_0x1ac687)!==_0x1ac687||_0x1ac687==='/'||RESERVED_SANDBOX_ROOTS[_0x4fb7da(0x14f)](_0x1f428b=>_0x1ac687===_0x1f428b||within(_0x1f428b,_0x1ac687)||within(_0x1ac687,_0x1f428b)))throw new Error(_0x4fb7da(0x2bc));}function within(_0x319800,_0x12d2cc){const _0x20bf23=_0x50efe0,_0x54879e=relative(_0x319800,_0x12d2cc);return _0x54879e[_0x20bf23(0x26b)]>-0x2511+0x1*0x126+0xf*0x265&&_0x54879e!=='..'&&!_0x54879e[_0x20bf23(0x2ac)]('..'+sep);}function resolveMcpServers(_0x5830b3,_0x43cbd9){const _0x4aa65e=_0x50efe0,_0x427695=_0x4e4749=>{const _0x39ae4d=_0x4c67,_0xf9c3f4={};for(const [_0x527d71,_0x3e7961]of Object[_0x39ae4d(0x1fb)](_0x4e4749??{})){const _0x4ce09d=_0x43cbd9[_0x3e7961[_0x39ae4d(0x197)]];if(_0x4ce09d===undefined)throw new Error(_0x39ae4d(0x137));_0xf9c3f4[_0x527d71]=_0x4ce09d;}return _0xf9c3f4;};return _0x5830b3[_0x4aa65e(0x11d)][_0x4aa65e(0x2db)](_0x1075c1=>{const _0x2a9e1b=_0x4aa65e;if(_0x1075c1[_0x2a9e1b(0x189)][_0x2a9e1b(0x152)]===_0x2a9e1b(0x2a9)){if(_0x5830b3[_0x2a9e1b(0x1f6)][_0x2a9e1b(0x1aa)]!==_0x2a9e1b(0x125))return[];return[{'name':_0x1075c1[_0x2a9e1b(0x19c)],'lifecycle':_0x2a9e1b(0x22f),'transport':_0x2a9e1b(0x2a9),'url':_0x1075c1[_0x2a9e1b(0x189)][_0x2a9e1b(0x19b)],'headers':{..._0x427695(_0x1075c1[_0x2a9e1b(0x189)][_0x2a9e1b(0x1ea)]),..._0x427695(_0x1075c1[_0x2a9e1b(0x1ca)][_0x2a9e1b(0x1ea)])}}];}return[{'name':_0x1075c1[_0x2a9e1b(0x19c)],'lifecycle':_0x2a9e1b(0x22f),'transport':_0x2a9e1b(0x170),'command':_0x1075c1[_0x2a9e1b(0x189)][_0x2a9e1b(0x1a6)],'args':[..._0x1075c1[_0x2a9e1b(0x189)][_0x2a9e1b(0x1bd)],..._0x1075c1[_0x2a9e1b(0x1ca)][_0x2a9e1b(0x183)]??[]],'environment':{..._0x427695(_0x1075c1[_0x2a9e1b(0x189)][_0x2a9e1b(0x19a)]),..._0x427695(_0x1075c1[_0x2a9e1b(0x1ca)][_0x2a9e1b(0x19a)])}}];});}function hostedConversationSummary(_0x9881cc,_0x4390f9){const _0xb6f90=_0x50efe0;return hostedConversationSummarySchema[_0xb6f90(0x12b)]({'id':_0x9881cc['id'],'nodeId':_0x9881cc[_0xb6f90(0x269)],'sessionId':_0x9881cc[_0xb6f90(0x17a)],'templateId':_0x9881cc[_0xb6f90(0x251)],'templateName':_0x9881cc[_0xb6f90(0x19f)],'activeVersionId':_0x9881cc[_0xb6f90(0x2b9)],'title':_0x9881cc[_0xb6f90(0x139)],'titleSource':_0x9881cc[_0xb6f90(0x14d)],'pinnedAt':_0x9881cc[_0xb6f90(0x2ae)],'status':_0x9881cc[_0xb6f90(0x24e)],'modelId':_0x9881cc[_0xb6f90(0x185)],'createdAt':_0x9881cc[_0xb6f90(0x1ba)],'updatedAt':_0x9881cc[_0xb6f90(0x2e0)],'lastActivityAt':_0x9881cc[_0xb6f90(0x232)],..._0x4390f9===undefined?{}:{'activity':_0x4390f9}});}function templateSummary(_0xbebf7a,_0x505c5a){const _0x27be4=_0x50efe0;return conversationTemplateSummarySchema[_0x27be4(0x12b)]({'id':_0xbebf7a[_0x27be4(0x251)],'nodeId':_0xbebf7a[_0x27be4(0x269)],'name':_0xbebf7a[_0x27be4(0x19f)],'description':_0x505c5a[_0x27be4(0x114)],'status':_0xbebf7a[_0x27be4(0x270)]?_0x27be4(0x27c):_0x27be4(0x10d),'currentVersionId':_0xbebf7a[_0x27be4(0x2b9)],'available':!_0xbebf7a[_0x27be4(0x270)],'createdAt':_0xbebf7a[_0x27be4(0x1ba)],'updatedAt':_0x505c5a[_0x27be4(0x2e0)]});}function modelSummary(_0x348385,_0x310169){const _0x2df18a=_0x50efe0;return{'id':_0x348385['id'],'name':_0x348385[_0x2df18a(0x1eb)],'protocol':_0x348385[_0x2df18a(0x1b4)],'baseUrl':_0x348385[_0x2df18a(0x275)],'modelId':_0x348385[_0x2df18a(0x185)],'contextWindowTokens':_0x348385[_0x2df18a(0x10c)],'maxOutputTokens':_0x348385[_0x2df18a(0x225)],'inputCapabilities':_0x348385[_0x2df18a(0x111)],'outputCapabilities':_0x348385[_0x2df18a(0x207)],'reasoningEfforts':_0x348385[_0x2df18a(0x17f)],'defaultReasoningEffort':resolveMarAgentDefaultReasoningEffort(_0x348385[_0x2df18a(0x25e)],_0x348385[_0x2df18a(0x17f)]),'titleGeneration':_0x348385[_0x2df18a(0x1f9)],'codeMode':_0x348385[_0x2df18a(0x284)],'hostedWebSearch':_0x348385[_0x2df18a(0x281)],..._0x348385[_0x2df18a(0x1fc)]===undefined?{}:{'responsesTransport':_0x348385[_0x2df18a(0x1fc)]},'responsesPreviousResponseId':_0x348385[_0x2df18a(0x241)],'enabled':_0x348385[_0x2df18a(0x110)],'sortOrder':_0x310169,'apiKeyConfigured':!![]};}function systemInstruction(_0x2032b0,_0x54e5f5){const _0x770dfb=_0x50efe0,_0x532fa5=_0x2032b0[_0x770dfb(0x1f6)],_0x753341=_0x532fa5[_0x770dfb(0x1aa)]===_0x770dfb(0x201)?_0x770dfb(0x231):_0x770dfb(0x192);return[_0x770dfb(0x25c),_0x770dfb(0x13e),_0x770dfb(0x2d3),_0x770dfb(0x25f),_0x770dfb(0x27b),_0x770dfb(0x2c8),_0x770dfb(0x211),_0x770dfb(0x1f4),_0x770dfb(0x279),_0x770dfb(0x1e9),_0x770dfb(0x22d),_0x770dfb(0x1ed),_0x770dfb(0x222),..._0x54e5f5===undefined?[]:[_0x770dfb(0x104)+_0x54e5f5+_0x770dfb(0x176),_0x770dfb(0x28e)+_0x54e5f5+_0x770dfb(0x1ef)+_0x54e5f5+_0x770dfb(0x29c)],..._0x2032b0[_0x770dfb(0x1a9)]===undefined?[]:[_0x770dfb(0x1e4)+_0x2032b0[_0x770dfb(0x1a9)]+_0x770dfb(0x143)+join(_0x2032b0[_0x770dfb(0x1a9)],_0x770dfb(0x1df))+_0x770dfb(0x215)+join(_0x2032b0[_0x770dfb(0x1a9)],_0x770dfb(0x13f))+_0x770dfb(0x156)],_0x770dfb(0x26d),_0x753341][_0x770dfb(0x180)]('\x0a');}function attachmentPrompt(_0x1786e9,_0x51cb17){const _0x86856e=_0x50efe0;if(_0x51cb17[_0x86856e(0x26b)]===-0xfc1+-0x80*-0x35+-0xabf)return _0x1786e9;const _0x2578bd=_0x51cb17[_0x86856e(0x158)](_0x11ea4a=>_0x86856e(0x1c2)+_0x11ea4a[_0x86856e(0x151)])[_0x86856e(0x180)]('\x0a');return''+_0x1786e9+(_0x1786e9[_0x86856e(0x1af)]()[_0x86856e(0x26b)]===0x1a98+-0x1141*-0x1+-0x1*0x2bd9?'':'\x0a\x0a')+_0x86856e(0x2cf)+_0x2578bd;}function automaticHostedConversationTitle(_0x106d56){const _0x22ac92=_0x50efe0;if(_0x106d56===undefined)return undefined;const _0x4bda46=sessionTitleFromFirstMessage(_0x106d56);if(_0x4bda46[_0x22ac92(0x26b)]===0xa*0x194+-0x1e8d+0xec5||/^(?:new|untitled) session(?:\s*[-–—:]\s*\d{4}-\d{2}-\d{2}.*)?$/iu[_0x22ac92(0x299)](_0x4bda46))return undefined;return _0x4bda46;}function terminalHostedTurnStatus(_0x444846){const _0x45b67a=_0x50efe0;return _0x444846===_0x45b67a(0x2df)||_0x444846===_0x45b67a(0x1b9)||_0x444846===_0x45b67a(0x2d7)||_0x444846===_0x45b67a(0x121)||_0x444846===_0x45b67a(0x1d0);}function runFromMessage(_0x73512c){const _0x38bfcf=_0x50efe0;return{'id':_0x73512c[_0x38bfcf(0x16b)],'status':_0x73512c[_0x38bfcf(0x24e)],'startedAt':_0x73512c[_0x38bfcf(0x1ba)],'completedAt':_0x73512c[_0x38bfcf(0x24e)]===_0x38bfcf(0x24c)?null:_0x73512c[_0x38bfcf(0x2e0)]};}function runInterruptionKey(_0x11ceaf,_0x23c203){return _0x11ceaf+'\x00'+_0x23c203;}function uploadProjection(_0x499db0){const _0x485e9d=_0x50efe0;return{'uploadId':_0x499db0[_0x485e9d(0x1d8)],'conversationId':_0x499db0[_0x485e9d(0x20a)],'name':_0x499db0[_0x485e9d(0x1eb)],'mimeType':_0x499db0[_0x485e9d(0x18c)],'receivedBytes':_0x499db0[_0x485e9d(0x2a5)],'size':_0x499db0[_0x485e9d(0x293)],'status':_0x499db0[_0x485e9d(0x24e)],..._0x499db0[_0x485e9d(0x127)]===undefined?{}:{'file':_0x499db0[_0x485e9d(0x127)]}};}async function assertRegularFile(_0x3b7143,_0x10c73c){const _0x5d48d5=_0x50efe0,_0xd7d003=await regularFileMetadata(_0x3b7143);if(_0xd7d003[_0x5d48d5(0x293)]!==_0x10c73c)throw new Error(_0x5d48d5(0x25b));}async function openRegularFile(_0x313326){const _0x16e3e8=_0x50efe0;return open(_0x313326,constants[_0x16e3e8(0x11b)]|constants[_0x16e3e8(0x253)])[_0x16e3e8(0x22e)](()=>{const _0x152da1=_0x16e3e8;throw new Error(_0x152da1(0x25b));});}async function regularFileMetadata(_0x2fb40b){const _0x59e3fd=_0x50efe0,_0x212956=await lstat(_0x2fb40b)[_0x59e3fd(0x22e)](()=>{const _0x49f932=_0x59e3fd;throw new Error(_0x49f932(0x25b));});return assertRegularFileMetadata(_0x212956),_0x212956;}function _0x4c67(_0x4055b4,_0x372c3c){_0x4055b4=_0x4055b4-(0x74*0x20+0xabb+-0x183a);const _0x1d8872=_0x590c();let _0x10e037=_0x1d8872[_0x4055b4];if(_0x4c67['Kwcrqf']===undefined){var _0x1a3b5b=function(_0x46adcc){const _0x5e28ac='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';let _0x3a625f='',_0x3f7147='';for(let _0x331bd9=0xe05+0x1b99+-0x299e,_0x412a98,_0x4eb782,_0x144d06=0x2*0x87b+-0xf4a+-0x1ac;_0x4eb782=_0x46adcc['charAt'](_0x144d06++);~_0x4eb782&&(_0x412a98=_0x331bd9%(0x181d+0xec8+0x26e1*-0x1)?_0x412a98*(0x273+0x59*-0x53+0x8*0x355)+_0x4eb782:_0x4eb782,_0x331bd9++%(0x23ab*0x1+0x1d63*0x1+-0x410a))?_0x3a625f+=String['fromCharCode'](0x1*-0x1e73+-0x2e1*-0x8+0x86a&_0x412a98>>(-(-0x1*-0x4c9+-0x26cb+-0x1*-0x2204)*_0x331bd9&-0xf20+0x17f3+-0x1*0x8cd)):0x11db*-0x1+-0xe67+0x2042){_0x4eb782=_0x5e28ac['indexOf'](_0x4eb782);}for(let _0x3883e3=-0x11b5*0x1+0xe9f+-0xa*-0x4f,_0x40d679=_0x3a625f['length'];_0x3883e3<_0x40d679;_0x3883e3++){_0x3f7147+='%'+('00'+_0x3a625f['charCodeAt'](_0x3883e3)['toString'](0xb2d*-0x1+-0x1d0c+0x2849))['slice'](-(-0xb13+0x37f*-0xa+0x2e0b));}return decodeURIComponent(_0x3f7147);};_0x4c67['LTMfPP']=_0x1a3b5b,_0x4c67['dLjhOp']={},_0x4c67['Kwcrqf']=!![];}const _0xeb11e8=_0x1d8872[0x181+-0x1f*0x59+-0x4a3*-0x2];_0x4c67['usgHhW']!==_0xeb11e8&&(_0x4c67['dLjhOp']={},_0x4c67['usgHhW']=_0xeb11e8);const _0x1c2510=_0x4c67['dLjhOp'][_0x4055b4];return _0x1c2510===undefined?(_0x10e037=_0x4c67['LTMfPP'](_0x10e037),_0x4c67['dLjhOp'][_0x4055b4]=_0x10e037):_0x10e037=_0x1c2510,_0x10e037;}function assertRegularFileMetadata(_0x3d79bc){const _0x2f6829=_0x50efe0;if(!_0x3d79bc[_0x2f6829(0x2c5)]()||_0x3d79bc[_0x2f6829(0x186)]()||_0x3d79bc[_0x2f6829(0x1f7)]!==0x22ff+-0xc*0x245+0x3*-0x296||!Number[_0x2f6829(0x1e7)](_0x3d79bc[_0x2f6829(0x293)])||_0x3d79bc[_0x2f6829(0x293)]<0x1ee0+0x21d8+0x368*-0x13)throw new Error(_0x2f6829(0x25b));}function sameFileIdentity(_0x588502,_0x359c5a){const _0x8882e4=_0x50efe0;return _0x588502[_0x8882e4(0x175)]===_0x359c5a[_0x8882e4(0x175)]&&_0x588502[_0x8882e4(0x2de)]===_0x359c5a[_0x8882e4(0x2de)];}function sameFileSnapshot(_0x351ea6,_0x25fc50){const _0x254b67=_0x50efe0;return sameFileIdentity(_0x351ea6,_0x25fc50)&&_0x351ea6[_0x254b67(0x1f7)]===_0x25fc50[_0x254b67(0x1f7)]&&_0x351ea6[_0x254b67(0x293)]===_0x25fc50[_0x254b67(0x293)]&&_0x351ea6[_0x254b67(0x13c)]===_0x25fc50[_0x254b67(0x13c)]&&_0x351ea6[_0x254b67(0x16a)]===_0x25fc50[_0x254b67(0x16a)];}function safeFileTimestamp(_0x1da316){const _0xfcd5d3=_0x50efe0;if(!Number[_0xfcd5d3(0x1c8)](_0x1da316)||_0x1da316<-0x4c*0x71+-0x3*0x7fd+0x3983)return-0x41d+-0xda2*0x2+0x1f61;return Math[_0xfcd5d3(0x1ee)](Number[_0xfcd5d3(0x286)],Math[_0xfcd5d3(0x2e2)](_0x1da316));}async function assertUploadTemporaryFile(_0x4825b6,_0x3d6fc1){const _0x42a76a=_0x50efe0,_0x5d7275=await lstat(_0x4825b6)[_0x42a76a(0x22e)](()=>{const _0x59dde6=_0x42a76a;throw new Error(_0x59dde6(0x2b1));});if(!_0x5d7275[_0x42a76a(0x2c5)]()||_0x5d7275[_0x42a76a(0x186)]()||_0x5d7275[_0x42a76a(0x1f7)]!==0x1f0b+0x10d7+0x1*-0x2fe1||_0x5d7275[_0x42a76a(0x293)]!==_0x3d6fc1)throw new Error(_0x42a76a(0x2b1));}function record(_0x4349f8){const _0x1536ad=_0x50efe0;return typeof _0x4349f8===_0x1536ad(0x240)&&_0x4349f8!==null&&!Array[_0x1536ad(0x226)](_0x4349f8);}
|
|
1
|
+
import { createHash, randomUUID } from 'node:crypto';
|
|
2
|
+
import { constants } from 'node:fs';
|
|
3
|
+
import { lstat, mkdir, open, readFile, rename, rm, utimes } from 'node:fs/promises';
|
|
4
|
+
import { isAbsolute, join, relative, resolve, sep } from 'node:path';
|
|
5
|
+
import { conversationTurnSchema, conversationTemplateDraftSchema, conversationTemplateSummarySchema, hostedConversationConfigUpdateInputSchema, hostedConversationCreateInputSchema, hostedConversationDeleteResultSchema, hostedConversationFileDeleteInputSchema, hostedConversationFileDeleteResultSchema, hostedConversationFileReadInputSchema, hostedConversationFileReadResultSchema, hostedConversationFilesSchema, hostedConversationIdInputSchema, hostedConversationImageReadInputSchema, hostedConversationListInputSchema, hostedConversationListPageSchema, hostedConversationMessageInputSchema, hostedConversationMetadataUpdateInputSchema, hostedConversationRollbackInputSchema, hostedConversationSnapshotSchema, hostedConversationSummarySchema, hostedConversationUnwatchInputSchema, hostedConversationUploadChunkInputSchema, hostedConversationUploadControlInputSchema, hostedConversationUploadCreateInputSchema, hostedConversationUploadPreflightInputSchema, hostedConversationUploadPreflightResultSchema, hostedConversationUploadSchema, hostedConversationWatchInputSchema, marAgentRuntimeModelConfigurationSchema, mcpInstallationConfigurationSchema, mcpRuntimeDescriptorSchema, resolveMarAgentDefaultReasoningEffort } from '@myagentroam/protocol';
|
|
6
|
+
import { hostedConversationGeneratedImagesDisplayDirectory, hostedConversationImageRunId, marAgentGeneratedImagesDirectory } from '../runner/mar-agent/generated-images.js';
|
|
7
|
+
import { sessionTitleFromFirstMessage } from '../util/node-operation-parsers.js';
|
|
8
|
+
import { safeErrorCode } from '../util/safe-error.js';
|
|
9
|
+
import { SessionWatchSlotCoordinator } from './session-watch-slot-coordinator.js';
|
|
10
|
+
const DEFAULT_HOSTED_CONVERSATION_TITLE = 'New conversation';
|
|
11
|
+
const HOST_POLICY_VERSION = 1;
|
|
12
|
+
const MAX_FILE_READ_BYTES = 512 * 1024;
|
|
13
|
+
const WATCH_TTL_MS = 45_000;
|
|
14
|
+
const RUNTIME_LINK_ROOTS = ['/usr', '/bin', '/sbin', '/lib', '/lib64'];
|
|
15
|
+
const RESERVED_SANDBOX_ROOTS = [
|
|
16
|
+
'/workspace',
|
|
17
|
+
'/home/mar',
|
|
18
|
+
'/runtime',
|
|
19
|
+
'/usr',
|
|
20
|
+
'/bin',
|
|
21
|
+
'/sbin',
|
|
22
|
+
'/lib',
|
|
23
|
+
'/lib64',
|
|
24
|
+
'/proc',
|
|
25
|
+
'/dev',
|
|
26
|
+
'/run',
|
|
27
|
+
'/tmp'
|
|
28
|
+
];
|
|
29
|
+
/** Implements the Node-owned hosted-conversation domain over an injected MAR Agent runtime. */
|
|
30
|
+
export class HostedConversationNodeService {
|
|
31
|
+
options;
|
|
32
|
+
now;
|
|
33
|
+
id;
|
|
34
|
+
pendingCreates = new Map();
|
|
35
|
+
pendingMessages = new Map();
|
|
36
|
+
activeRuns = new Map();
|
|
37
|
+
runSettlements = new Map();
|
|
38
|
+
activities = new Map();
|
|
39
|
+
expectedInterruptions = new Set();
|
|
40
|
+
uploads = new Map();
|
|
41
|
+
uploadsByRequest = new Map();
|
|
42
|
+
fileDeletes = new Set();
|
|
43
|
+
watchLeases = new Map();
|
|
44
|
+
cleanupLocks = new Set();
|
|
45
|
+
historyMutations = new Map();
|
|
46
|
+
historyVersions = new Map();
|
|
47
|
+
sessionWatchSlots;
|
|
48
|
+
disablePrepared = false;
|
|
49
|
+
snapshotSequence = 0;
|
|
50
|
+
workbenchSequence = 0;
|
|
51
|
+
constructor(options) {
|
|
52
|
+
this.options = options;
|
|
53
|
+
this.now = options.now ?? Date.now;
|
|
54
|
+
this.id = options.id ?? randomUUID;
|
|
55
|
+
this.sessionWatchSlots = options.sessionWatchSlots ?? new SessionWatchSlotCoordinator();
|
|
56
|
+
}
|
|
57
|
+
operations() {
|
|
58
|
+
return {
|
|
59
|
+
'conversation.hosted.list': (raw) => this.list(raw),
|
|
60
|
+
'conversation.hosted.create': (raw) => this.create(raw),
|
|
61
|
+
'conversation.hosted.get': (raw) => this.get(raw),
|
|
62
|
+
'conversation.hosted.watch': (raw) => this.watch(raw),
|
|
63
|
+
'conversation.hosted.unwatch': (raw) => this.unwatch(raw),
|
|
64
|
+
'conversation.hosted.message': (raw) => this.message(raw),
|
|
65
|
+
'conversation.hosted.rollback': (raw) => this.rollback(raw),
|
|
66
|
+
'conversation.hosted.interrupt': (raw) => this.interrupt(raw),
|
|
67
|
+
'conversation.hosted.config.update': (raw) => this.updateConfiguration(raw),
|
|
68
|
+
'conversation.hosted.metadata.update': (raw) => this.updateMetadata(raw),
|
|
69
|
+
'conversation.hosted.image.read': (raw) => this.readImage(raw),
|
|
70
|
+
'conversation.hosted.files.list': (raw) => this.listFiles(raw),
|
|
71
|
+
'conversation.hosted.file.read': (raw) => this.readFile(raw),
|
|
72
|
+
'conversation.hosted.file.delete': (raw) => this.deleteFile(raw),
|
|
73
|
+
'conversation.hosted.files.upload.preflight': (raw) => this.preflightUpload(raw),
|
|
74
|
+
'conversation.hosted.files.upload.create': (raw) => this.createUpload(raw),
|
|
75
|
+
'conversation.hosted.files.upload.chunk': (raw) => this.writeUploadChunk(raw),
|
|
76
|
+
'conversation.hosted.files.upload.status': (raw) => this.uploadStatus(raw),
|
|
77
|
+
'conversation.hosted.files.upload.complete': (raw) => this.completeUpload(raw),
|
|
78
|
+
'conversation.hosted.files.upload.cancel': (raw) => this.cancelUpload(raw),
|
|
79
|
+
'conversation.hosted.delete': (raw) => this.delete(raw)
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Closes Run admission while a management operation verifies that it can
|
|
84
|
+
* release the hosting runtime without interrupting an existing execution.
|
|
85
|
+
*/
|
|
86
|
+
prepareForDisable() {
|
|
87
|
+
if (this.disablePrepared ||
|
|
88
|
+
this.pendingMessages.size > 0 ||
|
|
89
|
+
this.activeRuns.size > 0 ||
|
|
90
|
+
this.runSettlements.size > 0 ||
|
|
91
|
+
this.historyMutations.size > 0)
|
|
92
|
+
return undefined;
|
|
93
|
+
this.disablePrepared = true;
|
|
94
|
+
return () => {
|
|
95
|
+
this.disablePrepared = false;
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
list(raw) {
|
|
99
|
+
const payload = hostedRequest(raw);
|
|
100
|
+
const input = hostedConversationListInputSchema.parse(payload.data);
|
|
101
|
+
const page = this.options.store.listConversations({
|
|
102
|
+
userId: payload.userId,
|
|
103
|
+
limit: input.limit,
|
|
104
|
+
...(input.cursor === undefined ? {} : { cursor: input.cursor })
|
|
105
|
+
});
|
|
106
|
+
return hostedConversationListPageSchema.parse({
|
|
107
|
+
...page,
|
|
108
|
+
items: page.items.map((conversation) => ({
|
|
109
|
+
...conversation,
|
|
110
|
+
activity: this.activity(conversation.id)
|
|
111
|
+
}))
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
create(raw) {
|
|
115
|
+
if (this.disablePrepared)
|
|
116
|
+
return Promise.reject(new Error('CONVERSATION_HOSTING_UNAVAILABLE'));
|
|
117
|
+
const payload = hostedRequest(raw);
|
|
118
|
+
const input = hostedConversationCreateInputSchema.parse(payload.data);
|
|
119
|
+
const template = conversationTemplateSummarySchema.parse(payload.template);
|
|
120
|
+
const models = runtimeModels(payload.models);
|
|
121
|
+
if (template.id !== input.templateId ||
|
|
122
|
+
template.nodeId !== this.options.nodeId() ||
|
|
123
|
+
!template.available ||
|
|
124
|
+
template.status !== 'ACTIVE' ||
|
|
125
|
+
template.currentVersionId === null)
|
|
126
|
+
throw new Error('HOSTED_CONVERSATION_TEMPLATE_UNAVAILABLE');
|
|
127
|
+
const key = `${payload.userId}\0${input.clientRequestId}`;
|
|
128
|
+
const pending = this.pendingCreates.get(key);
|
|
129
|
+
if (pending !== undefined)
|
|
130
|
+
return pending;
|
|
131
|
+
const existing = this.options.store.findConversationByClientRequest(payload.userId, input.clientRequestId);
|
|
132
|
+
if (existing !== undefined)
|
|
133
|
+
return this.snapshot(payload.userId, existing.id, models);
|
|
134
|
+
const operation = this.createConversation(payload.userId, input.clientRequestId, template, models, payload.runtimeScopeId);
|
|
135
|
+
this.pendingCreates.set(key, operation);
|
|
136
|
+
void operation.finally(() => this.pendingCreates.delete(key)).catch(() => undefined);
|
|
137
|
+
return operation;
|
|
138
|
+
}
|
|
139
|
+
async createConversation(userId, clientRequestId, template, models, runtimeScopeId) {
|
|
140
|
+
await this.options.assertCanCreate?.();
|
|
141
|
+
const version = await this.loadTemplateVersion(template.currentVersionId, template.id);
|
|
142
|
+
const selected = selectModel(version, models, version.modelPolicy.defaultId);
|
|
143
|
+
const conversationId = this.id();
|
|
144
|
+
const prepared = await this.options.store.prepareConversationEnvironment(userId, conversationId);
|
|
145
|
+
const pathMounts = this.pathMounts(prepared.paths, version);
|
|
146
|
+
const processExecutor = this.processExecutor(prepared.paths, version);
|
|
147
|
+
let sessionId;
|
|
148
|
+
try {
|
|
149
|
+
const session = await this.options.runtime.createSession({
|
|
150
|
+
conversationId,
|
|
151
|
+
homeDirectory: prepared.paths.homeDirectory,
|
|
152
|
+
workspaceDirectory: version.templateDirectory,
|
|
153
|
+
systemInstruction: systemInstruction(version),
|
|
154
|
+
defaultModelId: selected.id,
|
|
155
|
+
models: networkModels(allowedModels(version, models), version.draft.networkMode),
|
|
156
|
+
...(runtimeScopeId === undefined ? {} : { runtimeScopeId }),
|
|
157
|
+
pathMounts,
|
|
158
|
+
processExecutor
|
|
159
|
+
});
|
|
160
|
+
sessionId = session.sessionId;
|
|
161
|
+
const createdAt = this.now();
|
|
162
|
+
const manifest = {
|
|
163
|
+
id: conversationId,
|
|
164
|
+
nodeId: this.options.nodeId(),
|
|
165
|
+
sessionId,
|
|
166
|
+
templateId: template.id,
|
|
167
|
+
templateName: template.name,
|
|
168
|
+
activeVersionId: version.id,
|
|
169
|
+
title: DEFAULT_HOSTED_CONVERSATION_TITLE,
|
|
170
|
+
titleSource: 'DEFAULT',
|
|
171
|
+
pinnedAt: null,
|
|
172
|
+
status: 'ACTIVE',
|
|
173
|
+
modelId: selected.id,
|
|
174
|
+
createdAt,
|
|
175
|
+
updatedAt: createdAt,
|
|
176
|
+
lastActivityAt: createdAt,
|
|
177
|
+
userStorageKey: prepared.userStorageKey,
|
|
178
|
+
conversationStorageKey: prepared.conversationStorageKey,
|
|
179
|
+
clientRequestId,
|
|
180
|
+
templateDeleted: false,
|
|
181
|
+
quota: {
|
|
182
|
+
usedBytes: 0,
|
|
183
|
+
maxBytes: version.draft.quotas.maxStorageBytes
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
const persisted = await this.options.store.createConversation(manifest);
|
|
187
|
+
if (persisted.id !== conversationId) {
|
|
188
|
+
await this.options.runtime
|
|
189
|
+
.releaseSession({
|
|
190
|
+
conversationId,
|
|
191
|
+
sessionId,
|
|
192
|
+
homeDirectory: prepared.paths.homeDirectory
|
|
193
|
+
})
|
|
194
|
+
.catch(() => undefined);
|
|
195
|
+
await rm(prepared.paths.conversationDirectory, { recursive: true, force: true });
|
|
196
|
+
}
|
|
197
|
+
return this.snapshot(userId, persisted.id, models);
|
|
198
|
+
}
|
|
199
|
+
catch (error) {
|
|
200
|
+
if (sessionId !== undefined)
|
|
201
|
+
await this.options.runtime
|
|
202
|
+
.releaseSession({
|
|
203
|
+
conversationId,
|
|
204
|
+
sessionId,
|
|
205
|
+
homeDirectory: prepared.paths.homeDirectory
|
|
206
|
+
})
|
|
207
|
+
.catch(() => undefined);
|
|
208
|
+
await rm(prepared.paths.conversationDirectory, { recursive: true, force: true }).catch(() => undefined);
|
|
209
|
+
throw error;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
async get(raw) {
|
|
213
|
+
const payload = hostedRequest(raw);
|
|
214
|
+
const input = hostedConversationIdInputSchema.parse(payload.data);
|
|
215
|
+
return this.snapshot(payload.userId, input.conversationId, runtimeModels(payload.models), payload.templateDeleted);
|
|
216
|
+
}
|
|
217
|
+
async snapshot(userId, conversationId, availableModels, templateDeleted = false, includeActiveHistoryMutation = false, turnsOverride) {
|
|
218
|
+
if (includeActiveHistoryMutation)
|
|
219
|
+
return this.readSnapshot(userId, conversationId, availableModels, templateDeleted, turnsOverride);
|
|
220
|
+
while (true) {
|
|
221
|
+
const version = this.historyVersions.get(conversationId) ?? 0;
|
|
222
|
+
const mutation = this.historyMutations.get(conversationId);
|
|
223
|
+
if (mutation !== undefined) {
|
|
224
|
+
await mutation.catch(() => undefined);
|
|
225
|
+
continue;
|
|
226
|
+
}
|
|
227
|
+
const snapshot = await this.readSnapshot(userId, conversationId, availableModels, templateDeleted);
|
|
228
|
+
if (!this.historyMutations.has(conversationId) &&
|
|
229
|
+
(this.historyVersions.get(conversationId) ?? 0) === version)
|
|
230
|
+
return snapshot;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
async readSnapshot(userId, conversationId, availableModels, templateDeleted, turnsOverride) {
|
|
234
|
+
let conversation = this.options.store.requireConversation(userId, conversationId);
|
|
235
|
+
if (templateDeleted)
|
|
236
|
+
conversation = await this.options.store.retainConversationTemplate(userId, conversationId, this.now());
|
|
237
|
+
const latestVersionId = conversation.templateDeleted
|
|
238
|
+
? undefined
|
|
239
|
+
: this.latestAvailableTemplateVersionId(conversation.templateId);
|
|
240
|
+
const displayVersionId = latestVersionId ?? conversation.activeVersionId;
|
|
241
|
+
const version = await this.loadTemplateVersion(displayVersionId, conversation.templateId);
|
|
242
|
+
const models = networkModels(allowedModels(version, availableModels), version.draft.networkMode);
|
|
243
|
+
const paths = this.options.store.pathsForConversation(userId, conversation.id);
|
|
244
|
+
const turns = turnsOverride ??
|
|
245
|
+
(await this.options.runtime.history({
|
|
246
|
+
conversationId: conversation.id,
|
|
247
|
+
sessionId: conversation.sessionId,
|
|
248
|
+
homeDirectory: paths.homeDirectory,
|
|
249
|
+
modelId: conversation.modelId
|
|
250
|
+
}));
|
|
251
|
+
return hostedConversationSnapshotSchema.parse({
|
|
252
|
+
nodeAppVersion: this.options.nodeAppVersion?.() ?? 'unknown',
|
|
253
|
+
conversation: this.summary(conversation),
|
|
254
|
+
template: templateSummary(conversation, version.draft),
|
|
255
|
+
run: this.activeRuns.get(conversation.id)?.run ?? null,
|
|
256
|
+
turns,
|
|
257
|
+
files: this.options.store.listFiles(userId, conversation.id),
|
|
258
|
+
models: models.map(modelSummary),
|
|
259
|
+
error: null,
|
|
260
|
+
snapshotSequence: 0
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
async watch(raw) {
|
|
264
|
+
const payload = hostedRequest(raw);
|
|
265
|
+
const input = hostedConversationWatchInputSchema.parse(payload.data);
|
|
266
|
+
const conversation = this.options.store.requireConversation(payload.userId, input.conversationId);
|
|
267
|
+
if (this.cleanupLocks.has(conversation.id))
|
|
268
|
+
throw new Error('HOSTED_CONVERSATION_STATE_INVALID');
|
|
269
|
+
const sessionHash = requireWatchSessionHash(payload.sessionHash);
|
|
270
|
+
const ownerKey = watchOwnerKey(sessionHash, input.workbenchConnectionId);
|
|
271
|
+
if (input.mode === 'renew') {
|
|
272
|
+
const lease = this.watchLeases.get(ownerKey);
|
|
273
|
+
if (lease === undefined ||
|
|
274
|
+
!this.sessionWatchSlots.owns(ownerKey, lease.slotToken) ||
|
|
275
|
+
lease.watchId !== input.watchId ||
|
|
276
|
+
lease.conversationId !== input.conversationId ||
|
|
277
|
+
lease.userId !== payload.userId ||
|
|
278
|
+
lease.expiresAt <= Date.now()) {
|
|
279
|
+
this.removeWatchLease(ownerKey);
|
|
280
|
+
throw new Error('SESSION_WATCH_NOT_FOUND');
|
|
281
|
+
}
|
|
282
|
+
lease.expiresAt = Date.now() + WATCH_TTL_MS;
|
|
283
|
+
clearTimeout(lease.timer);
|
|
284
|
+
lease.timer = this.watchLeaseTimer(ownerKey);
|
|
285
|
+
return this.acceptedWatch(lease);
|
|
286
|
+
}
|
|
287
|
+
const models = runtimeModels(payload.models);
|
|
288
|
+
const existing = this.watchLeases.get(ownerKey);
|
|
289
|
+
if (existing !== undefined &&
|
|
290
|
+
this.sessionWatchSlots.owns(ownerKey, existing.slotToken) &&
|
|
291
|
+
existing.watchId === input.watchId &&
|
|
292
|
+
existing.conversationId === input.conversationId &&
|
|
293
|
+
existing.userId === payload.userId &&
|
|
294
|
+
existing.expiresAt > Date.now()) {
|
|
295
|
+
existing.expiresAt = Date.now() + WATCH_TTL_MS;
|
|
296
|
+
clearTimeout(existing.timer);
|
|
297
|
+
existing.timer = this.watchLeaseTimer(ownerKey);
|
|
298
|
+
return this.acceptedWatch(existing);
|
|
299
|
+
}
|
|
300
|
+
this.removeWatchLease(ownerKey);
|
|
301
|
+
const slotToken = this.sessionWatchSlots.replace(ownerKey, 'hosted-conversation', () => this.removeWatchLease(ownerKey));
|
|
302
|
+
const lease = {
|
|
303
|
+
ownerKey,
|
|
304
|
+
slotToken,
|
|
305
|
+
sessionHash,
|
|
306
|
+
workbenchConnectionId: input.workbenchConnectionId,
|
|
307
|
+
watchId: input.watchId,
|
|
308
|
+
conversationId: input.conversationId,
|
|
309
|
+
templateId: conversation.templateId,
|
|
310
|
+
userId: payload.userId,
|
|
311
|
+
models,
|
|
312
|
+
nodeGeneration: this.options.nodeGeneration?.() ?? 'local-test-generation',
|
|
313
|
+
pendingEvents: [],
|
|
314
|
+
expiresAt: Date.now() + WATCH_TTL_MS,
|
|
315
|
+
ready: false,
|
|
316
|
+
timer: undefined
|
|
317
|
+
};
|
|
318
|
+
lease.timer = this.watchLeaseTimer(ownerKey);
|
|
319
|
+
this.watchLeases.set(ownerKey, lease);
|
|
320
|
+
void this.initializeWatchLease(lease);
|
|
321
|
+
return this.acceptedWatch(lease);
|
|
322
|
+
}
|
|
323
|
+
unwatch(raw) {
|
|
324
|
+
const payload = hostedRequest(raw);
|
|
325
|
+
const input = hostedConversationUnwatchInputSchema.parse(payload.data);
|
|
326
|
+
this.options.store.requireConversation(payload.userId, input.conversationId);
|
|
327
|
+
const ownerKey = watchOwnerKey(requireWatchSessionHash(payload.sessionHash), input.workbenchConnectionId);
|
|
328
|
+
const lease = this.watchLeases.get(ownerKey);
|
|
329
|
+
if (lease?.watchId === input.watchId &&
|
|
330
|
+
lease.conversationId === input.conversationId &&
|
|
331
|
+
lease.userId === payload.userId)
|
|
332
|
+
this.removeWatchLease(ownerKey);
|
|
333
|
+
return { unwatched: true };
|
|
334
|
+
}
|
|
335
|
+
publishRuntimeEvent(conversationId, event) {
|
|
336
|
+
return this.publishHostedEvent(conversationId, {
|
|
337
|
+
conversationId,
|
|
338
|
+
kind: 'runtime',
|
|
339
|
+
runtimeEvent: event
|
|
340
|
+
});
|
|
341
|
+
}
|
|
342
|
+
isConversationInUse(conversationId) {
|
|
343
|
+
return (this.cleanupLocks.has(conversationId) ||
|
|
344
|
+
this.historyMutations.has(conversationId) ||
|
|
345
|
+
this.activeRuns.has(conversationId) ||
|
|
346
|
+
this.runSettlements.has(conversationId) ||
|
|
347
|
+
[...this.watchLeases.values()].some((lease) => lease.conversationId === conversationId) ||
|
|
348
|
+
[...this.uploads.values()].some((upload) => upload.conversationId === conversationId && upload.status === 'UPLOADING') ||
|
|
349
|
+
[...this.pendingMessages.keys()].some((key) => key.startsWith(`${conversationId}\0`)));
|
|
350
|
+
}
|
|
351
|
+
beginConversationCleanup(conversationId) {
|
|
352
|
+
if (this.isConversationInUse(conversationId))
|
|
353
|
+
return undefined;
|
|
354
|
+
this.cleanupLocks.add(conversationId);
|
|
355
|
+
return () => {
|
|
356
|
+
this.cleanupLocks.delete(conversationId);
|
|
357
|
+
};
|
|
358
|
+
}
|
|
359
|
+
async releaseConversationForCleanup(conversation) {
|
|
360
|
+
const paths = this.options.store.pathsForManifest(conversation);
|
|
361
|
+
await this.options.runtime
|
|
362
|
+
.releaseSession({
|
|
363
|
+
conversationId: conversation.id,
|
|
364
|
+
sessionId: conversation.sessionId,
|
|
365
|
+
homeDirectory: paths.homeDirectory
|
|
366
|
+
})
|
|
367
|
+
.catch(() => undefined);
|
|
368
|
+
}
|
|
369
|
+
dispose() {
|
|
370
|
+
for (const [conversationId, handle] of this.activeRuns) {
|
|
371
|
+
const interruptionKey = runInterruptionKey(conversationId, handle.run.id);
|
|
372
|
+
this.expectedInterruptions.add(interruptionKey);
|
|
373
|
+
if (!handle.cancel())
|
|
374
|
+
this.expectedInterruptions.delete(interruptionKey);
|
|
375
|
+
}
|
|
376
|
+
for (const ownerKey of [...this.watchLeases.keys()])
|
|
377
|
+
this.removeWatchLease(ownerKey);
|
|
378
|
+
}
|
|
379
|
+
message(raw) {
|
|
380
|
+
if (this.disablePrepared)
|
|
381
|
+
return Promise.reject(new Error('CONVERSATION_HOSTING_UNAVAILABLE'));
|
|
382
|
+
const payload = hostedRequest(raw);
|
|
383
|
+
const input = hostedConversationMessageInputSchema.parse(payload.data);
|
|
384
|
+
if (this.historyMutations.has(input.conversationId))
|
|
385
|
+
return Promise.reject(new Error('HOSTED_CONVERSATION_STATE_INVALID'));
|
|
386
|
+
const key = `${input.conversationId}\0${input.clientMessageId}`;
|
|
387
|
+
const pending = this.pendingMessages.get(key);
|
|
388
|
+
if (pending !== undefined)
|
|
389
|
+
return pending;
|
|
390
|
+
const existing = this.options.store.findMessage(payload.userId, input.conversationId, input.clientMessageId);
|
|
391
|
+
if (existing !== undefined) {
|
|
392
|
+
const conversation = this.options.store.requireConversation(payload.userId, input.conversationId);
|
|
393
|
+
return Promise.resolve({
|
|
394
|
+
conversation: this.summary(conversation),
|
|
395
|
+
run: runFromMessage(existing)
|
|
396
|
+
});
|
|
397
|
+
}
|
|
398
|
+
if ([...this.pendingMessages.keys()].some((candidate) => candidate.startsWith(`${input.conversationId}\0`)))
|
|
399
|
+
return Promise.reject(new Error('HOSTED_CONVERSATION_RUN_ACTIVE'));
|
|
400
|
+
const operation = this.startMessage(payload, input);
|
|
401
|
+
this.pendingMessages.set(key, operation);
|
|
402
|
+
void operation.finally(() => this.pendingMessages.delete(key)).catch(() => undefined);
|
|
403
|
+
return operation;
|
|
404
|
+
}
|
|
405
|
+
async startMessage(payload, input) {
|
|
406
|
+
let conversation = this.options.store.requireConversation(payload.userId, input.conversationId);
|
|
407
|
+
if (this.cleanupLocks.has(conversation.id))
|
|
408
|
+
throw new Error('HOSTED_CONVERSATION_STATE_INVALID');
|
|
409
|
+
if (this.historyMutations.has(conversation.id))
|
|
410
|
+
throw new Error('HOSTED_CONVERSATION_STATE_INVALID');
|
|
411
|
+
if (conversation.status !== 'ACTIVE')
|
|
412
|
+
throw new Error('HOSTED_CONVERSATION_STATE_INVALID');
|
|
413
|
+
if (this.activeRuns.has(conversation.id))
|
|
414
|
+
throw new Error('HOSTED_CONVERSATION_RUN_ACTIVE');
|
|
415
|
+
const temporaryTitle = sessionTitleFromFirstMessage(input.prompt);
|
|
416
|
+
const firstNonEmptyMessage = temporaryTitle.length > 0 &&
|
|
417
|
+
!this.options.store.hasNonEmptyUserMessage(payload.userId, conversation.id);
|
|
418
|
+
const models = runtimeModels(payload.models);
|
|
419
|
+
const paths = this.options.store.pathsForConversation(payload.userId, conversation.id);
|
|
420
|
+
let version;
|
|
421
|
+
let selected;
|
|
422
|
+
let mcpServers;
|
|
423
|
+
let upgrade;
|
|
424
|
+
const latestVersionId = conversation.templateDeleted
|
|
425
|
+
? undefined
|
|
426
|
+
: this.latestAvailableTemplateVersionId(conversation.templateId);
|
|
427
|
+
if (latestVersionId !== undefined && latestVersionId !== conversation.activeVersionId) {
|
|
428
|
+
const previousVersionId = conversation.activeVersionId;
|
|
429
|
+
const targetVersionId = latestVersionId;
|
|
430
|
+
try {
|
|
431
|
+
version = await this.loadTemplateVersion(targetVersionId, conversation.templateId);
|
|
432
|
+
selected = selectModel(version, models, input.modelId ?? version.modelPolicy.defaultId);
|
|
433
|
+
mcpServers = resolveMcpServers(version, this.options.secretEnvironment ?? process.env);
|
|
434
|
+
this.pathMounts(paths, version);
|
|
435
|
+
this.processExecutor(paths, version);
|
|
436
|
+
upgrade = { previousVersionId, targetVersionId };
|
|
437
|
+
}
|
|
438
|
+
catch (error) {
|
|
439
|
+
this.publishUpgradeFailure(conversation, previousVersionId, targetVersionId, error);
|
|
440
|
+
throw new Error('HOSTED_CONVERSATION_UPGRADE_FAILED');
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
else {
|
|
444
|
+
version = await this.loadTemplateVersion(conversation.activeVersionId, conversation.templateId);
|
|
445
|
+
selected = selectModel(version, models, input.modelId ?? conversation.modelId);
|
|
446
|
+
}
|
|
447
|
+
const attachments = await Promise.all(input.attachmentIds.map((fileId) => this.requireAttachment(payload.userId, conversation.id, fileId)));
|
|
448
|
+
const prompt = attachmentPrompt(input.prompt, attachments);
|
|
449
|
+
const generatedImagesDirectory = marAgentGeneratedImagesDirectory(paths.homeDirectory, conversation.sessionId);
|
|
450
|
+
const generatedImagesLogicalPath = hostedConversationGeneratedImagesDisplayDirectory(conversation.sessionId);
|
|
451
|
+
if (generatedImagesDirectory === undefined || generatedImagesLogicalPath === undefined)
|
|
452
|
+
throw new Error('HOSTED_CONVERSATION_SESSION_INVALID');
|
|
453
|
+
await mkdir(generatedImagesDirectory, { recursive: true, mode: 0o700 });
|
|
454
|
+
const temporaryDirectory = await this.options.store.prepareConversationTemporaryDirectory(payload.userId, conversation.id);
|
|
455
|
+
const pathMounts = this.pathMounts(paths, version, generatedImagesDirectory, generatedImagesLogicalPath, temporaryDirectory);
|
|
456
|
+
this.publishActivity(payload.userId, conversation, 'STARTING', this.now());
|
|
457
|
+
const pendingRuntimeEvents = [];
|
|
458
|
+
let runtimeEventsAccepted = false;
|
|
459
|
+
const handle = await this.options.runtime
|
|
460
|
+
.startRun({
|
|
461
|
+
conversationId: conversation.id,
|
|
462
|
+
sessionId: conversation.sessionId,
|
|
463
|
+
clientMessageId: input.clientMessageId,
|
|
464
|
+
userPrompt: input.prompt,
|
|
465
|
+
prompt,
|
|
466
|
+
attachmentIds: input.attachmentIds,
|
|
467
|
+
access: 'full-access',
|
|
468
|
+
modelId: selected.id,
|
|
469
|
+
models: networkModels(allowedModels(version, models), version.draft.networkMode),
|
|
470
|
+
...(payload.runtimeScopeId === undefined ? {} : { runtimeScopeId: payload.runtimeScopeId }),
|
|
471
|
+
systemInstruction: systemInstruction(version, generatedImagesLogicalPath),
|
|
472
|
+
homeDirectory: paths.homeDirectory,
|
|
473
|
+
workspaceDirectory: version.templateDirectory,
|
|
474
|
+
temporaryDirectory,
|
|
475
|
+
pathMounts,
|
|
476
|
+
processExecutor: this.processExecutor(paths, version, temporaryDirectory, generatedImagesDirectory, generatedImagesLogicalPath),
|
|
477
|
+
mcpServers: mcpServers ?? resolveMcpServers(version, this.options.secretEnvironment ?? process.env),
|
|
478
|
+
webAccess: version.draft.networkMode !== 'NONE',
|
|
479
|
+
onEvent: (event) => {
|
|
480
|
+
if (runtimeEventsAccepted)
|
|
481
|
+
this.publishRuntimeEvent(conversation.id, event);
|
|
482
|
+
else
|
|
483
|
+
pendingRuntimeEvents.push(event);
|
|
484
|
+
}
|
|
485
|
+
})
|
|
486
|
+
.catch((error) => {
|
|
487
|
+
this.publishActivity(payload.userId, conversation, 'IDLE', this.now());
|
|
488
|
+
if (upgrade !== undefined) {
|
|
489
|
+
this.publishUpgradeFailure(conversation, upgrade.previousVersionId, upgrade.targetVersionId, error);
|
|
490
|
+
throw new Error('HOSTED_CONVERSATION_UPGRADE_FAILED');
|
|
491
|
+
}
|
|
492
|
+
throw error;
|
|
493
|
+
});
|
|
494
|
+
const startedAt = handle.run.startedAt;
|
|
495
|
+
let messageCreated = false;
|
|
496
|
+
let accepted;
|
|
497
|
+
try {
|
|
498
|
+
this.options.store.createMessage({
|
|
499
|
+
conversationId: conversation.id,
|
|
500
|
+
clientMessageId: input.clientMessageId,
|
|
501
|
+
runId: handle.run.id,
|
|
502
|
+
userTextPresent: temporaryTitle.length > 0,
|
|
503
|
+
status: 'RUNNING',
|
|
504
|
+
createdAt: startedAt,
|
|
505
|
+
updatedAt: startedAt
|
|
506
|
+
});
|
|
507
|
+
messageCreated = true;
|
|
508
|
+
const configuredAt = this.now();
|
|
509
|
+
accepted = await this.options.store.saveMessageAcceptance({
|
|
510
|
+
conversationId: conversation.id,
|
|
511
|
+
modelId: selected.id,
|
|
512
|
+
activityAt: configuredAt,
|
|
513
|
+
...(upgrade === undefined
|
|
514
|
+
? {}
|
|
515
|
+
: {
|
|
516
|
+
templateVersion: {
|
|
517
|
+
expectedActiveVersionId: upgrade.previousVersionId,
|
|
518
|
+
activeVersionId: upgrade.targetVersionId,
|
|
519
|
+
maxStorageBytes: version.draft.quotas.maxStorageBytes
|
|
520
|
+
}
|
|
521
|
+
}),
|
|
522
|
+
...(firstNonEmptyMessage ? { automaticTitle: temporaryTitle } : {})
|
|
523
|
+
});
|
|
524
|
+
}
|
|
525
|
+
catch (error) {
|
|
526
|
+
try {
|
|
527
|
+
handle.cancel();
|
|
528
|
+
}
|
|
529
|
+
catch {
|
|
530
|
+
// Preserve the original persistence failure.
|
|
531
|
+
}
|
|
532
|
+
const completion = await handle.completion.catch(() => ({
|
|
533
|
+
status: 'FAILED',
|
|
534
|
+
completedAt: this.now()
|
|
535
|
+
}));
|
|
536
|
+
if (messageCreated)
|
|
537
|
+
try {
|
|
538
|
+
this.options.store.finishMessage(conversation.id, input.clientMessageId, completion.status, completion.completedAt);
|
|
539
|
+
}
|
|
540
|
+
catch {
|
|
541
|
+
// Preserve the original persistence failure.
|
|
542
|
+
}
|
|
543
|
+
this.publishActivity(payload.userId, conversation, 'IDLE', completion.completedAt);
|
|
544
|
+
if (upgrade !== undefined)
|
|
545
|
+
this.publishUpgradeFailure(conversation, upgrade.previousVersionId, upgrade.targetVersionId, error);
|
|
546
|
+
throw error;
|
|
547
|
+
}
|
|
548
|
+
conversation = accepted.conversation;
|
|
549
|
+
if (upgrade !== undefined)
|
|
550
|
+
this.publishHostedEvent(conversation.id, {
|
|
551
|
+
conversationId: conversation.id,
|
|
552
|
+
kind: 'upgrade',
|
|
553
|
+
upgrade: {
|
|
554
|
+
status: 'SUCCEEDED',
|
|
555
|
+
previousVersionId: upgrade.previousVersionId,
|
|
556
|
+
targetVersionId: upgrade.targetVersionId,
|
|
557
|
+
activeVersionId: conversation.activeVersionId,
|
|
558
|
+
conversation: this.summary(conversation),
|
|
559
|
+
error: null
|
|
560
|
+
}
|
|
561
|
+
});
|
|
562
|
+
this.activeRuns.set(conversation.id, handle);
|
|
563
|
+
this.publishActivity(payload.userId, conversation, 'RUNNING', handle.run.startedAt);
|
|
564
|
+
if (accepted.titleChanged)
|
|
565
|
+
this.publishHostedEvent(conversation.id, {
|
|
566
|
+
conversationId: conversation.id,
|
|
567
|
+
kind: 'conversation',
|
|
568
|
+
conversation: this.summary(conversation)
|
|
569
|
+
});
|
|
570
|
+
this.publishHostedEvent(conversation.id, {
|
|
571
|
+
conversationId: conversation.id,
|
|
572
|
+
kind: 'run',
|
|
573
|
+
run: handle.run
|
|
574
|
+
});
|
|
575
|
+
runtimeEventsAccepted = true;
|
|
576
|
+
for (const event of pendingRuntimeEvents)
|
|
577
|
+
this.publishRuntimeEvent(conversation.id, event);
|
|
578
|
+
pendingRuntimeEvents.length = 0;
|
|
579
|
+
const settlement = handle.completion
|
|
580
|
+
.then((completion) => this.finishRun(payload.userId, conversation.id, input.clientMessageId, handle.run, completion), () => this.finishRun(payload.userId, conversation.id, input.clientMessageId, handle.run, {
|
|
581
|
+
status: 'FAILED',
|
|
582
|
+
completedAt: this.now()
|
|
583
|
+
}))
|
|
584
|
+
.catch(() => undefined)
|
|
585
|
+
.finally(() => {
|
|
586
|
+
this.expectedInterruptions.delete(runInterruptionKey(conversation.id, handle.run.id));
|
|
587
|
+
if (this.activeRuns.get(conversation.id) === handle)
|
|
588
|
+
this.activeRuns.delete(conversation.id);
|
|
589
|
+
if (this.runSettlements.get(conversation.id) === settlement)
|
|
590
|
+
this.runSettlements.delete(conversation.id);
|
|
591
|
+
});
|
|
592
|
+
this.runSettlements.set(conversation.id, settlement);
|
|
593
|
+
void settlement;
|
|
594
|
+
return {
|
|
595
|
+
conversation: this.summary(conversation),
|
|
596
|
+
run: handle.run
|
|
597
|
+
};
|
|
598
|
+
}
|
|
599
|
+
rollback(raw) {
|
|
600
|
+
if (this.disablePrepared)
|
|
601
|
+
return Promise.reject(new Error('CONVERSATION_HOSTING_UNAVAILABLE'));
|
|
602
|
+
const payload = hostedRequest(raw);
|
|
603
|
+
const input = hostedConversationRollbackInputSchema.parse(payload.data);
|
|
604
|
+
const conversation = this.options.store.requireConversation(payload.userId, input.conversationId);
|
|
605
|
+
if (conversation.status !== 'ACTIVE' ||
|
|
606
|
+
this.cleanupLocks.has(conversation.id) ||
|
|
607
|
+
this.historyMutations.has(conversation.id))
|
|
608
|
+
return Promise.reject(new Error('HOSTED_CONVERSATION_STATE_INVALID'));
|
|
609
|
+
if (this.activity(conversation.id).status !== 'IDLE' ||
|
|
610
|
+
this.activeRuns.has(conversation.id) ||
|
|
611
|
+
this.runSettlements.has(conversation.id) ||
|
|
612
|
+
[...this.pendingMessages.keys()].some((key) => key.startsWith(`${conversation.id}\0`)))
|
|
613
|
+
return Promise.reject(new Error('HOSTED_CONVERSATION_RUN_ACTIVE'));
|
|
614
|
+
const operation = this.rollbackConversation(payload, conversation, input);
|
|
615
|
+
this.historyMutations.set(conversation.id, operation);
|
|
616
|
+
void operation
|
|
617
|
+
.finally(() => {
|
|
618
|
+
if (this.historyMutations.get(conversation.id) === operation)
|
|
619
|
+
this.historyMutations.delete(conversation.id);
|
|
620
|
+
})
|
|
621
|
+
.catch(() => undefined);
|
|
622
|
+
return operation;
|
|
623
|
+
}
|
|
624
|
+
async rollbackConversation(payload, conversation, input) {
|
|
625
|
+
const paths = this.options.store.pathsForConversation(payload.userId, conversation.id);
|
|
626
|
+
const turns = (await this.options.runtime.history({
|
|
627
|
+
conversationId: conversation.id,
|
|
628
|
+
sessionId: conversation.sessionId,
|
|
629
|
+
homeDirectory: paths.homeDirectory,
|
|
630
|
+
modelId: conversation.modelId
|
|
631
|
+
})).map((turn) => conversationTurnSchema.parse(turn));
|
|
632
|
+
const targetIndex = turns.findIndex((turn) => turn.id === input.turnId);
|
|
633
|
+
const target = turns[targetIndex];
|
|
634
|
+
const userMessage = target?.items.find((item) => item.kind === 'user_message' && item.status === 'COMPLETED');
|
|
635
|
+
if (target === undefined ||
|
|
636
|
+
!terminalHostedTurnStatus(target.status) ||
|
|
637
|
+
userMessage === undefined ||
|
|
638
|
+
target.rewind?.before !== input.boundary)
|
|
639
|
+
throw new Error('HOSTED_CONVERSATION_ROLLBACK_TARGET_INVALID');
|
|
640
|
+
let rolledBack;
|
|
641
|
+
try {
|
|
642
|
+
rolledBack = await this.options.runtime.rollback({
|
|
643
|
+
conversationId: conversation.id,
|
|
644
|
+
sessionId: conversation.sessionId,
|
|
645
|
+
homeDirectory: paths.homeDirectory,
|
|
646
|
+
modelId: conversation.modelId,
|
|
647
|
+
boundaryTurnId: input.boundary
|
|
648
|
+
});
|
|
649
|
+
}
|
|
650
|
+
catch (error) {
|
|
651
|
+
if (error instanceof Error && error.message === 'MAR_AGENT_ROLLBACK_TARGET_INVALID')
|
|
652
|
+
throw new Error('HOSTED_CONVERSATION_ROLLBACK_TARGET_INVALID', { cause: error });
|
|
653
|
+
throw error;
|
|
654
|
+
}
|
|
655
|
+
this.historyVersions.set(conversation.id, (this.historyVersions.get(conversation.id) ?? 0) + 1);
|
|
656
|
+
await this.options.store.advanceLastActivity(conversation.id, Math.max(this.now(), rolledBack.lastActivityAt));
|
|
657
|
+
const snapshot = await this.snapshot(payload.userId, conversation.id, runtimeModels(payload.models), payload.templateDeleted, true, turns.slice(0, targetIndex));
|
|
658
|
+
this.publishHostedSnapshot(conversation.id, snapshot);
|
|
659
|
+
return snapshot;
|
|
660
|
+
}
|
|
661
|
+
async finishRun(userId, conversationId, clientMessageId, run, completion) {
|
|
662
|
+
const interruptionKey = runInterruptionKey(conversationId, run.id);
|
|
663
|
+
const expectedInterruption = this.expectedInterruptions.has(interruptionKey);
|
|
664
|
+
let conversation;
|
|
665
|
+
try {
|
|
666
|
+
this.options.store.finishMessage(conversationId, clientMessageId, completion.status, completion.completedAt);
|
|
667
|
+
try {
|
|
668
|
+
const files = await this.options.store.reconcileFiles(userId, conversationId);
|
|
669
|
+
this.publishHostedEvent(conversationId, {
|
|
670
|
+
conversationId,
|
|
671
|
+
kind: 'files',
|
|
672
|
+
files,
|
|
673
|
+
error: null
|
|
674
|
+
});
|
|
675
|
+
}
|
|
676
|
+
catch (error) {
|
|
677
|
+
this.publishHostedEvent(conversationId, {
|
|
678
|
+
conversationId,
|
|
679
|
+
kind: 'files',
|
|
680
|
+
files: this.options.store.listFiles(userId, conversationId),
|
|
681
|
+
error: {
|
|
682
|
+
code: safeErrorCode(error, 'HOSTED_CONVERSATION_FILE_RECONCILE_FAILED'),
|
|
683
|
+
message: 'Hosted conversation file projection failed.'
|
|
684
|
+
}
|
|
685
|
+
});
|
|
686
|
+
}
|
|
687
|
+
await this.options.store.advanceLastActivity(conversationId, completion.completedAt);
|
|
688
|
+
this.publishHostedEvent(conversationId, {
|
|
689
|
+
conversationId,
|
|
690
|
+
kind: 'run',
|
|
691
|
+
run: {
|
|
692
|
+
id: run.id,
|
|
693
|
+
status: completion.status,
|
|
694
|
+
startedAt: run.startedAt,
|
|
695
|
+
completedAt: completion.completedAt
|
|
696
|
+
}
|
|
697
|
+
});
|
|
698
|
+
await this.applyAutomaticTitle(conversationId, completion.title, completion.completedAt).catch(() => undefined);
|
|
699
|
+
conversation = this.options.store.requireConversation(userId, conversationId);
|
|
700
|
+
}
|
|
701
|
+
finally {
|
|
702
|
+
this.expectedInterruptions.delete(interruptionKey);
|
|
703
|
+
if (conversation === undefined)
|
|
704
|
+
try {
|
|
705
|
+
conversation = this.options.store.requireConversation(userId, conversationId);
|
|
706
|
+
}
|
|
707
|
+
catch {
|
|
708
|
+
// The conversation may have been deleted while the Run was settling.
|
|
709
|
+
}
|
|
710
|
+
if (conversation !== undefined)
|
|
711
|
+
this.publishActivity(userId, conversation, 'IDLE', completion.completedAt);
|
|
712
|
+
}
|
|
713
|
+
if (conversation !== undefined &&
|
|
714
|
+
(completion.status !== 'INTERRUPTED' || !expectedInterruption))
|
|
715
|
+
this.publishTerminalNotification(userId, conversation, run.id, completion);
|
|
716
|
+
}
|
|
717
|
+
async applyAutomaticTitle(conversationId, value, updatedAt) {
|
|
718
|
+
const title = automaticHostedConversationTitle(value);
|
|
719
|
+
if (title === undefined)
|
|
720
|
+
return;
|
|
721
|
+
const saved = await this.options.store.saveAutomaticTitle(conversationId, title, updatedAt);
|
|
722
|
+
if (saved === undefined)
|
|
723
|
+
return;
|
|
724
|
+
this.publishHostedEvent(conversationId, {
|
|
725
|
+
conversationId,
|
|
726
|
+
kind: 'conversation',
|
|
727
|
+
conversation: this.summary(saved)
|
|
728
|
+
});
|
|
729
|
+
}
|
|
730
|
+
interrupt(raw) {
|
|
731
|
+
const payload = hostedRequest(raw);
|
|
732
|
+
const input = hostedConversationIdInputSchema.parse(payload.data);
|
|
733
|
+
const conversation = this.options.store.requireConversation(payload.userId, input.conversationId);
|
|
734
|
+
const handle = this.activeRuns.get(input.conversationId);
|
|
735
|
+
if (handle === undefined)
|
|
736
|
+
return { interrupted: false };
|
|
737
|
+
const interruptionKey = runInterruptionKey(conversation.id, handle.run.id);
|
|
738
|
+
this.expectedInterruptions.add(interruptionKey);
|
|
739
|
+
try {
|
|
740
|
+
const interrupted = handle.cancel();
|
|
741
|
+
if (!interrupted) {
|
|
742
|
+
this.expectedInterruptions.delete(interruptionKey);
|
|
743
|
+
return { interrupted: false };
|
|
744
|
+
}
|
|
745
|
+
this.publishActivity(payload.userId, conversation, 'CANCELLING', this.now());
|
|
746
|
+
return { interrupted: true };
|
|
747
|
+
}
|
|
748
|
+
catch (error) {
|
|
749
|
+
this.expectedInterruptions.delete(interruptionKey);
|
|
750
|
+
throw error;
|
|
751
|
+
}
|
|
752
|
+
}
|
|
753
|
+
async updateConfiguration(raw) {
|
|
754
|
+
const payload = hostedRequest(raw);
|
|
755
|
+
const input = hostedConversationConfigUpdateInputSchema.parse(payload.data);
|
|
756
|
+
const conversation = this.options.store.requireConversation(payload.userId, input.conversationId);
|
|
757
|
+
if (this.cleanupLocks.has(conversation.id))
|
|
758
|
+
throw new Error('HOSTED_CONVERSATION_STATE_INVALID');
|
|
759
|
+
const latestVersionId = conversation.templateDeleted
|
|
760
|
+
? undefined
|
|
761
|
+
: this.latestAvailableTemplateVersionId(conversation.templateId);
|
|
762
|
+
const displayVersionId = latestVersionId ?? conversation.activeVersionId;
|
|
763
|
+
const version = await this.loadTemplateVersion(displayVersionId, conversation.templateId);
|
|
764
|
+
const models = runtimeModels(payload.models);
|
|
765
|
+
const selected = selectModel(version, models, input.modelId ?? conversation.modelId);
|
|
766
|
+
const updatedAt = this.now();
|
|
767
|
+
const saved = await this.options.store.updateConversation(conversation.id, (current) => ({
|
|
768
|
+
...current,
|
|
769
|
+
modelId: selected.id,
|
|
770
|
+
updatedAt,
|
|
771
|
+
lastActivityAt: updatedAt
|
|
772
|
+
}));
|
|
773
|
+
this.publishHostedEvent(conversation.id, {
|
|
774
|
+
conversationId: conversation.id,
|
|
775
|
+
kind: 'configuration',
|
|
776
|
+
conversation: this.summary(saved)
|
|
777
|
+
});
|
|
778
|
+
return { conversation: this.summary(saved) };
|
|
779
|
+
}
|
|
780
|
+
async updateMetadata(raw) {
|
|
781
|
+
const payload = hostedRequest(raw);
|
|
782
|
+
const input = hostedConversationMetadataUpdateInputSchema.parse(payload.data);
|
|
783
|
+
const conversation = this.options.store.requireConversation(payload.userId, input.conversationId);
|
|
784
|
+
if (this.cleanupLocks.has(conversation.id))
|
|
785
|
+
throw new Error('HOSTED_CONVERSATION_STATE_INVALID');
|
|
786
|
+
const updatedAt = this.now();
|
|
787
|
+
const saved = await this.options.store.updateConversation(conversation.id, (current) => ({
|
|
788
|
+
...current,
|
|
789
|
+
title: input.title ?? current.title,
|
|
790
|
+
titleSource: input.title === undefined ? current.titleSource : 'CUSTOM',
|
|
791
|
+
pinnedAt: input.pinned === undefined ? current.pinnedAt : input.pinned ? updatedAt : null,
|
|
792
|
+
updatedAt,
|
|
793
|
+
lastActivityAt: current.lastActivityAt
|
|
794
|
+
}));
|
|
795
|
+
this.publishHostedEvent(conversation.id, {
|
|
796
|
+
conversationId: conversation.id,
|
|
797
|
+
kind: 'configuration',
|
|
798
|
+
conversation: this.summary(saved)
|
|
799
|
+
});
|
|
800
|
+
return { conversation: this.summary(saved) };
|
|
801
|
+
}
|
|
802
|
+
async listFiles(raw) {
|
|
803
|
+
const payload = hostedRequest(raw);
|
|
804
|
+
const input = hostedConversationIdInputSchema.parse(payload.data);
|
|
805
|
+
return hostedConversationFilesSchema.parse({
|
|
806
|
+
files: this.options.store.listFiles(payload.userId, input.conversationId)
|
|
807
|
+
});
|
|
808
|
+
}
|
|
809
|
+
async readImage(raw) {
|
|
810
|
+
const payload = hostedRequest(raw);
|
|
811
|
+
const input = hostedConversationImageReadInputSchema.parse(payload.data);
|
|
812
|
+
this.options.store.requireConversation(payload.userId, input.conversationId);
|
|
813
|
+
if (input.runId !== hostedConversationImageRunId(input.conversationId))
|
|
814
|
+
throw new Error('HOSTED_CONVERSATION_NOT_AUTHORIZED');
|
|
815
|
+
const image = await this.options.readImage(input.runId, input.imageIndex);
|
|
816
|
+
if (image === undefined)
|
|
817
|
+
throw new Error('RUN_IMAGE_NOT_FOUND');
|
|
818
|
+
return { image };
|
|
819
|
+
}
|
|
820
|
+
async readFile(raw) {
|
|
821
|
+
const payload = hostedRequest(raw);
|
|
822
|
+
const input = hostedConversationFileReadInputSchema.parse(payload.data);
|
|
823
|
+
const file = this.options.store.requireFile(payload.userId, input.conversationId, input.fileId);
|
|
824
|
+
const path = this.options.store.filePath(payload.userId, file);
|
|
825
|
+
const offset = input.offset ?? 0;
|
|
826
|
+
const limit = Math.min(input.limit ?? MAX_FILE_READ_BYTES, MAX_FILE_READ_BYTES);
|
|
827
|
+
const handle = await openRegularFile(path);
|
|
828
|
+
try {
|
|
829
|
+
const before = await handle.stat();
|
|
830
|
+
assertRegularFileMetadata(before);
|
|
831
|
+
const pathMetadata = await regularFileMetadata(path);
|
|
832
|
+
if (!sameFileIdentity(before, pathMetadata))
|
|
833
|
+
throw new Error('HOSTED_CONVERSATION_FILE_INVALID');
|
|
834
|
+
if (offset > before.size)
|
|
835
|
+
throw new Error('HOSTED_CONVERSATION_FILE_RANGE_INVALID');
|
|
836
|
+
const buffer = Buffer.alloc(Math.min(limit, Math.max(0, before.size - offset)));
|
|
837
|
+
const read = await handle.read(buffer, 0, buffer.length, offset);
|
|
838
|
+
const after = await handle.stat();
|
|
839
|
+
const currentPathMetadata = await regularFileMetadata(path);
|
|
840
|
+
if (!sameFileSnapshot(before, after) || !sameFileSnapshot(after, currentPathMetadata))
|
|
841
|
+
throw new Error('HOSTED_CONVERSATION_FILE_INVALID');
|
|
842
|
+
const next = offset + read.bytesRead;
|
|
843
|
+
const eof = next >= after.size;
|
|
844
|
+
const currentFile = {
|
|
845
|
+
...file,
|
|
846
|
+
size: after.size,
|
|
847
|
+
updatedAt: Math.max(file.createdAt, safeFileTimestamp(after.mtimeMs), safeFileTimestamp(after.ctimeMs))
|
|
848
|
+
};
|
|
849
|
+
return hostedConversationFileReadResultSchema.parse({
|
|
850
|
+
file: currentFile,
|
|
851
|
+
encoding: 'base64',
|
|
852
|
+
content: buffer.subarray(0, read.bytesRead).toString('base64'),
|
|
853
|
+
offset,
|
|
854
|
+
nextOffset: eof ? null : next,
|
|
855
|
+
eof
|
|
856
|
+
});
|
|
857
|
+
}
|
|
858
|
+
finally {
|
|
859
|
+
await handle.close();
|
|
860
|
+
}
|
|
861
|
+
}
|
|
862
|
+
async deleteFile(raw) {
|
|
863
|
+
const payload = hostedRequest(raw);
|
|
864
|
+
const input = hostedConversationFileDeleteInputSchema.parse(payload.data);
|
|
865
|
+
this.requireWritableConversation(payload.userId, input.conversationId);
|
|
866
|
+
const deleteKey = `${input.conversationId}\0${input.fileId}`;
|
|
867
|
+
if (this.fileDeletes.has(deleteKey))
|
|
868
|
+
throw new Error('HOSTED_CONVERSATION_FILE_CONFLICT');
|
|
869
|
+
this.fileDeletes.add(deleteKey);
|
|
870
|
+
try {
|
|
871
|
+
const files = await this.options.store.deleteFile(payload.userId, input.conversationId, input.fileId, this.now());
|
|
872
|
+
const result = hostedConversationFileDeleteResultSchema.parse({
|
|
873
|
+
deletedFileId: input.fileId,
|
|
874
|
+
files
|
|
875
|
+
});
|
|
876
|
+
this.publishHostedEvent(input.conversationId, {
|
|
877
|
+
conversationId: input.conversationId,
|
|
878
|
+
kind: 'files',
|
|
879
|
+
files: result.files,
|
|
880
|
+
error: null
|
|
881
|
+
});
|
|
882
|
+
return result;
|
|
883
|
+
}
|
|
884
|
+
finally {
|
|
885
|
+
this.fileDeletes.delete(deleteKey);
|
|
886
|
+
}
|
|
887
|
+
}
|
|
888
|
+
async preflightUpload(raw) {
|
|
889
|
+
const payload = hostedRequest(raw);
|
|
890
|
+
const input = hostedConversationUploadPreflightInputSchema.parse(payload.data);
|
|
891
|
+
const conversation = this.requireWritableConversation(payload.userId, input.conversationId);
|
|
892
|
+
const version = await this.loadTemplateVersion(conversation.activeVersionId, conversation.templateId);
|
|
893
|
+
const paths = this.options.store.pathsForConversation(payload.userId, conversation.id);
|
|
894
|
+
const files = await Promise.all(input.files.map(async (file) => ({
|
|
895
|
+
name: file.name,
|
|
896
|
+
status: await this.uploadPreflightStatus(paths, conversation, version.draft, file.name, file.size)
|
|
897
|
+
})));
|
|
898
|
+
return hostedConversationUploadPreflightResultSchema.parse({ files });
|
|
899
|
+
}
|
|
900
|
+
async createUpload(raw) {
|
|
901
|
+
const payload = hostedRequest(raw);
|
|
902
|
+
const input = hostedConversationUploadCreateInputSchema.parse(payload.data);
|
|
903
|
+
const conversation = this.requireWritableConversation(payload.userId, input.conversationId);
|
|
904
|
+
const requestKey = `${payload.userId}\0${conversation.id}\0${input.clientRequestId}`;
|
|
905
|
+
const existingId = this.uploadsByRequest.get(requestKey);
|
|
906
|
+
if (existingId !== undefined) {
|
|
907
|
+
const existing = this.uploads.get(existingId);
|
|
908
|
+
if (existing !== undefined)
|
|
909
|
+
return { upload: hostedConversationUploadSchema.parse(uploadProjection(existing)) };
|
|
910
|
+
}
|
|
911
|
+
const version = await this.loadTemplateVersion(conversation.activeVersionId, conversation.templateId);
|
|
912
|
+
const paths = this.options.store.pathsForConversation(payload.userId, conversation.id);
|
|
913
|
+
const status = await this.uploadPreflightStatus(paths, conversation, version.draft, input.name, input.size);
|
|
914
|
+
if (status === 'QUOTA_EXCEEDED' || status === 'TOO_LARGE')
|
|
915
|
+
throw new Error('HOSTED_CONVERSATION_QUOTA_EXCEEDED');
|
|
916
|
+
if (status !== 'READY')
|
|
917
|
+
throw new Error('HOSTED_CONVERSATION_FILE_INVALID');
|
|
918
|
+
const uploadId = this.id();
|
|
919
|
+
const temporaryPath = join(paths.uploadsDirectory, `.${uploadId}.upload`);
|
|
920
|
+
const targetPath = join(paths.uploadsDirectory, input.name);
|
|
921
|
+
const handle = await open(temporaryPath, 'wx', 0o600);
|
|
922
|
+
await handle.close();
|
|
923
|
+
const upload = {
|
|
924
|
+
uploadId,
|
|
925
|
+
conversationId: conversation.id,
|
|
926
|
+
userId: payload.userId,
|
|
927
|
+
clientRequestId: input.clientRequestId,
|
|
928
|
+
name: input.name,
|
|
929
|
+
mimeType: input.mimeType,
|
|
930
|
+
size: input.size,
|
|
931
|
+
temporaryPath,
|
|
932
|
+
targetPath,
|
|
933
|
+
receivedBytes: 0,
|
|
934
|
+
status: 'UPLOADING'
|
|
935
|
+
};
|
|
936
|
+
this.uploads.set(uploadId, upload);
|
|
937
|
+
this.uploadsByRequest.set(requestKey, uploadId);
|
|
938
|
+
return { upload: hostedConversationUploadSchema.parse(uploadProjection(upload)) };
|
|
939
|
+
}
|
|
940
|
+
async writeUploadChunk(raw) {
|
|
941
|
+
const payload = hostedRequest(raw);
|
|
942
|
+
const input = hostedConversationUploadChunkInputSchema.parse(payload.data);
|
|
943
|
+
const upload = this.requireUpload(payload.userId, input.conversationId, input.uploadId);
|
|
944
|
+
if (upload.status !== 'UPLOADING')
|
|
945
|
+
throw new Error('HOSTED_CONVERSATION_UPLOAD_STATE_INVALID');
|
|
946
|
+
if (input.offset !== upload.receivedBytes)
|
|
947
|
+
throw new Error('HOSTED_CONVERSATION_UPLOAD_OFFSET_INVALID');
|
|
948
|
+
const chunk = Buffer.from(input.dataBase64, 'base64');
|
|
949
|
+
if (upload.receivedBytes + chunk.byteLength > upload.size)
|
|
950
|
+
throw new Error('HOSTED_CONVERSATION_UPLOAD_SIZE_INVALID');
|
|
951
|
+
await assertUploadTemporaryFile(upload.temporaryPath, upload.receivedBytes);
|
|
952
|
+
const handle = await open(upload.temporaryPath, 'r+');
|
|
953
|
+
try {
|
|
954
|
+
await handle.write(chunk, 0, chunk.byteLength, upload.receivedBytes);
|
|
955
|
+
}
|
|
956
|
+
finally {
|
|
957
|
+
await handle.close();
|
|
958
|
+
}
|
|
959
|
+
upload.receivedBytes += chunk.byteLength;
|
|
960
|
+
return { upload: hostedConversationUploadSchema.parse(uploadProjection(upload)) };
|
|
961
|
+
}
|
|
962
|
+
uploadStatus(raw) {
|
|
963
|
+
const payload = hostedRequest(raw);
|
|
964
|
+
const input = hostedConversationUploadControlInputSchema.parse(payload.data);
|
|
965
|
+
const upload = this.requireUpload(payload.userId, input.conversationId, input.uploadId);
|
|
966
|
+
return { upload: hostedConversationUploadSchema.parse(uploadProjection(upload)) };
|
|
967
|
+
}
|
|
968
|
+
async completeUpload(raw) {
|
|
969
|
+
const payload = hostedRequest(raw);
|
|
970
|
+
const input = hostedConversationUploadControlInputSchema.parse(payload.data);
|
|
971
|
+
const upload = this.requireUpload(payload.userId, input.conversationId, input.uploadId);
|
|
972
|
+
if (upload.status === 'COMPLETED')
|
|
973
|
+
return { upload: hostedConversationUploadSchema.parse(uploadProjection(upload)) };
|
|
974
|
+
if (upload.status !== 'UPLOADING' || upload.receivedBytes !== upload.size)
|
|
975
|
+
throw new Error('HOSTED_CONVERSATION_UPLOAD_INCOMPLETE');
|
|
976
|
+
const conversation = this.requireWritableConversation(payload.userId, upload.conversationId);
|
|
977
|
+
const version = await this.loadTemplateVersion(conversation.activeVersionId, conversation.templateId);
|
|
978
|
+
if (upload.size > version.draft.quotas.maxUploadBytes ||
|
|
979
|
+
conversation.quota.usedBytes + upload.size > conversation.quota.maxBytes)
|
|
980
|
+
throw new Error('HOSTED_CONVERSATION_QUOTA_EXCEEDED');
|
|
981
|
+
await assertUploadTemporaryFile(upload.temporaryPath, upload.size);
|
|
982
|
+
const target = await lstat(upload.targetPath).catch((error) => {
|
|
983
|
+
if (error.code === 'ENOENT')
|
|
984
|
+
return undefined;
|
|
985
|
+
throw error;
|
|
986
|
+
});
|
|
987
|
+
if (target !== undefined)
|
|
988
|
+
throw new Error('HOSTED_CONVERSATION_FILE_INVALID');
|
|
989
|
+
const handle = await open(upload.temporaryPath, 'r+');
|
|
990
|
+
try {
|
|
991
|
+
await handle.sync();
|
|
992
|
+
}
|
|
993
|
+
finally {
|
|
994
|
+
await handle.close();
|
|
995
|
+
}
|
|
996
|
+
await rename(upload.temporaryPath, upload.targetPath);
|
|
997
|
+
const createdAt = this.now();
|
|
998
|
+
try {
|
|
999
|
+
await utimes(upload.targetPath, new Date(createdAt), new Date(createdAt));
|
|
1000
|
+
const file = {
|
|
1001
|
+
id: this.options.store.fileProjectionId(upload.conversationId, 'UPLOAD', upload.name),
|
|
1002
|
+
conversationId: upload.conversationId,
|
|
1003
|
+
category: 'UPLOAD',
|
|
1004
|
+
relativePath: upload.name,
|
|
1005
|
+
displayName: upload.name,
|
|
1006
|
+
mimeType: upload.mimeType,
|
|
1007
|
+
size: upload.size,
|
|
1008
|
+
source: 'USER',
|
|
1009
|
+
createdAt,
|
|
1010
|
+
updatedAt: createdAt
|
|
1011
|
+
};
|
|
1012
|
+
upload.file = await this.options.store.registerFile(payload.userId, file);
|
|
1013
|
+
upload.status = 'COMPLETED';
|
|
1014
|
+
this.publishHostedEvent(upload.conversationId, {
|
|
1015
|
+
conversationId: upload.conversationId,
|
|
1016
|
+
kind: 'files',
|
|
1017
|
+
files: this.options.store.listFiles(payload.userId, upload.conversationId),
|
|
1018
|
+
error: null
|
|
1019
|
+
});
|
|
1020
|
+
return { upload: hostedConversationUploadSchema.parse(uploadProjection(upload)) };
|
|
1021
|
+
}
|
|
1022
|
+
catch (error) {
|
|
1023
|
+
await rename(upload.targetPath, upload.temporaryPath).catch(() => undefined);
|
|
1024
|
+
throw error;
|
|
1025
|
+
}
|
|
1026
|
+
}
|
|
1027
|
+
async cancelUpload(raw) {
|
|
1028
|
+
const payload = hostedRequest(raw);
|
|
1029
|
+
const input = hostedConversationUploadControlInputSchema.parse(payload.data);
|
|
1030
|
+
const upload = this.requireUpload(payload.userId, input.conversationId, input.uploadId);
|
|
1031
|
+
if (upload.status === 'COMPLETED')
|
|
1032
|
+
throw new Error('HOSTED_CONVERSATION_UPLOAD_STATE_INVALID');
|
|
1033
|
+
upload.status = 'CANCELLED';
|
|
1034
|
+
await rm(upload.temporaryPath, { force: true });
|
|
1035
|
+
return { upload: hostedConversationUploadSchema.parse(uploadProjection(upload)) };
|
|
1036
|
+
}
|
|
1037
|
+
async delete(raw) {
|
|
1038
|
+
const payload = hostedRequest(raw);
|
|
1039
|
+
const input = hostedConversationIdInputSchema.parse(payload.data);
|
|
1040
|
+
const conversation = this.options.store.requireConversation(payload.userId, input.conversationId);
|
|
1041
|
+
if (this.cleanupLocks.has(conversation.id) || this.historyMutations.has(conversation.id))
|
|
1042
|
+
throw new Error('HOSTED_CONVERSATION_STATE_INVALID');
|
|
1043
|
+
this.cleanupLocks.add(conversation.id);
|
|
1044
|
+
try {
|
|
1045
|
+
await this.waitForPendingMessageStarts(conversation.id);
|
|
1046
|
+
const handle = this.activeRuns.get(conversation.id);
|
|
1047
|
+
if (handle !== undefined) {
|
|
1048
|
+
const interruptionKey = runInterruptionKey(conversation.id, handle.run.id);
|
|
1049
|
+
this.expectedInterruptions.add(interruptionKey);
|
|
1050
|
+
if (!handle.cancel())
|
|
1051
|
+
this.expectedInterruptions.delete(interruptionKey);
|
|
1052
|
+
}
|
|
1053
|
+
await this.cancelConversationUploads(payload.userId, conversation.id);
|
|
1054
|
+
const paths = this.options.store.pathsForConversation(payload.userId, conversation.id);
|
|
1055
|
+
await this.options.runtime
|
|
1056
|
+
.releaseSession({
|
|
1057
|
+
conversationId: conversation.id,
|
|
1058
|
+
sessionId: conversation.sessionId,
|
|
1059
|
+
homeDirectory: paths.homeDirectory
|
|
1060
|
+
})
|
|
1061
|
+
.catch(() => undefined);
|
|
1062
|
+
await this.runSettlements.get(conversation.id)?.catch(() => undefined);
|
|
1063
|
+
this.removeConversationWatchLeases(conversation.id);
|
|
1064
|
+
await this.options.store.permanentDeleteConversation(conversation.id);
|
|
1065
|
+
this.activities.delete(conversation.id);
|
|
1066
|
+
this.historyVersions.delete(conversation.id);
|
|
1067
|
+
return hostedConversationDeleteResultSchema.parse({
|
|
1068
|
+
deletedConversationId: conversation.id
|
|
1069
|
+
});
|
|
1070
|
+
}
|
|
1071
|
+
finally {
|
|
1072
|
+
this.cleanupLocks.delete(conversation.id);
|
|
1073
|
+
}
|
|
1074
|
+
}
|
|
1075
|
+
async waitForPendingMessageStarts(conversationId) {
|
|
1076
|
+
const prefix = `${conversationId}\0`;
|
|
1077
|
+
const pending = [...this.pendingMessages.entries()]
|
|
1078
|
+
.filter(([key]) => key.startsWith(prefix))
|
|
1079
|
+
.map(([, operation]) => operation);
|
|
1080
|
+
await Promise.allSettled(pending);
|
|
1081
|
+
}
|
|
1082
|
+
async initializeWatchLease(lease) {
|
|
1083
|
+
try {
|
|
1084
|
+
const snapshot = await this.get({
|
|
1085
|
+
conversationId: lease.conversationId,
|
|
1086
|
+
__requestUserId: lease.userId,
|
|
1087
|
+
__marAgentModels: lease.models
|
|
1088
|
+
});
|
|
1089
|
+
if (this.watchLeases.get(lease.ownerKey) !== lease)
|
|
1090
|
+
return;
|
|
1091
|
+
this.options.emitWatchEvent?.({
|
|
1092
|
+
type: 'watch.hosted-conversation.snapshot',
|
|
1093
|
+
workbenchConnectionId: lease.workbenchConnectionId,
|
|
1094
|
+
watchId: lease.watchId,
|
|
1095
|
+
nodeGeneration: lease.nodeGeneration,
|
|
1096
|
+
nodeId: this.options.nodeId(),
|
|
1097
|
+
templateId: lease.templateId,
|
|
1098
|
+
conversationId: lease.conversationId,
|
|
1099
|
+
revision: 1,
|
|
1100
|
+
snapshotSequence: ++this.snapshotSequence,
|
|
1101
|
+
expiresAt: lease.expiresAt,
|
|
1102
|
+
payload: snapshot
|
|
1103
|
+
});
|
|
1104
|
+
lease.ready = true;
|
|
1105
|
+
for (const event of lease.pendingEvents)
|
|
1106
|
+
this.emitWatchLeaseEvent(lease, event);
|
|
1107
|
+
lease.pendingEvents.length = 0;
|
|
1108
|
+
}
|
|
1109
|
+
catch (error) {
|
|
1110
|
+
if (this.watchLeases.get(lease.ownerKey) !== lease)
|
|
1111
|
+
return;
|
|
1112
|
+
this.options.emitWatchEvent?.({
|
|
1113
|
+
type: 'watch.failed',
|
|
1114
|
+
workbenchConnectionId: lease.workbenchConnectionId,
|
|
1115
|
+
watchType: 'hosted-conversation',
|
|
1116
|
+
watchId: lease.watchId,
|
|
1117
|
+
nodeGeneration: lease.nodeGeneration,
|
|
1118
|
+
nodeId: this.options.nodeId(),
|
|
1119
|
+
templateId: lease.templateId,
|
|
1120
|
+
conversationId: lease.conversationId,
|
|
1121
|
+
code: safeErrorCode(error, 'HOSTED_CONVERSATION_WATCH_FAILED'),
|
|
1122
|
+
message: 'Hosted conversation watch snapshot failed.'
|
|
1123
|
+
});
|
|
1124
|
+
this.removeWatchLease(lease.ownerKey);
|
|
1125
|
+
}
|
|
1126
|
+
}
|
|
1127
|
+
publishHostedSnapshot(conversationId, snapshot) {
|
|
1128
|
+
for (const lease of this.watchLeases.values()) {
|
|
1129
|
+
if (lease.conversationId !== conversationId || !lease.ready)
|
|
1130
|
+
continue;
|
|
1131
|
+
this.options.emitWatchEvent?.({
|
|
1132
|
+
type: 'watch.hosted-conversation.snapshot',
|
|
1133
|
+
workbenchConnectionId: lease.workbenchConnectionId,
|
|
1134
|
+
watchId: lease.watchId,
|
|
1135
|
+
nodeGeneration: lease.nodeGeneration,
|
|
1136
|
+
nodeId: this.options.nodeId(),
|
|
1137
|
+
templateId: lease.templateId,
|
|
1138
|
+
conversationId: lease.conversationId,
|
|
1139
|
+
revision: 1,
|
|
1140
|
+
snapshotSequence: ++this.snapshotSequence,
|
|
1141
|
+
expiresAt: lease.expiresAt,
|
|
1142
|
+
payload: snapshot
|
|
1143
|
+
});
|
|
1144
|
+
}
|
|
1145
|
+
}
|
|
1146
|
+
activity(conversationId) {
|
|
1147
|
+
return (this.activities.get(conversationId) ?? {
|
|
1148
|
+
status: 'IDLE',
|
|
1149
|
+
version: 0,
|
|
1150
|
+
updatedAt: 0
|
|
1151
|
+
});
|
|
1152
|
+
}
|
|
1153
|
+
summary(conversation) {
|
|
1154
|
+
return hostedConversationSummary(conversation, this.activity(conversation.id));
|
|
1155
|
+
}
|
|
1156
|
+
publishActivity(userId, conversation, status, updatedAt) {
|
|
1157
|
+
const current = this.activity(conversation.id);
|
|
1158
|
+
const activity = {
|
|
1159
|
+
status,
|
|
1160
|
+
version: current.version + 1,
|
|
1161
|
+
updatedAt
|
|
1162
|
+
};
|
|
1163
|
+
this.activities.set(conversation.id, activity);
|
|
1164
|
+
this.publishWorkbenchEvent({
|
|
1165
|
+
kind: 'activity',
|
|
1166
|
+
userId,
|
|
1167
|
+
templateId: conversation.templateId,
|
|
1168
|
+
conversationId: conversation.id,
|
|
1169
|
+
activity
|
|
1170
|
+
});
|
|
1171
|
+
}
|
|
1172
|
+
publishTerminalNotification(userId, conversation, runId, completion) {
|
|
1173
|
+
this.publishWorkbenchEvent({
|
|
1174
|
+
kind: 'notification',
|
|
1175
|
+
event: {
|
|
1176
|
+
runId,
|
|
1177
|
+
sequence: 1,
|
|
1178
|
+
eventType: 'notification',
|
|
1179
|
+
payload: {
|
|
1180
|
+
targetType: 'HOSTED_CONVERSATION',
|
|
1181
|
+
userId,
|
|
1182
|
+
templateId: conversation.templateId,
|
|
1183
|
+
conversationId: conversation.id,
|
|
1184
|
+
conversationTitle: conversation.title,
|
|
1185
|
+
runId,
|
|
1186
|
+
notificationId: `run:${this.options.nodeId()}:${conversation.id}:${runId}`,
|
|
1187
|
+
kind: 'RUN_TERMINAL',
|
|
1188
|
+
outcome: completion.status,
|
|
1189
|
+
occurredAt: completion.completedAt
|
|
1190
|
+
},
|
|
1191
|
+
createdAt: completion.completedAt
|
|
1192
|
+
}
|
|
1193
|
+
});
|
|
1194
|
+
}
|
|
1195
|
+
publishWorkbenchEvent(payload) {
|
|
1196
|
+
const event = this.options.nextWorkbenchEvent?.(payload) ?? {
|
|
1197
|
+
sequence: ++this.workbenchSequence,
|
|
1198
|
+
category: 'hosted-conversation',
|
|
1199
|
+
payload
|
|
1200
|
+
};
|
|
1201
|
+
if (event !== undefined)
|
|
1202
|
+
this.options.emitWorkbenchEvent?.(event);
|
|
1203
|
+
}
|
|
1204
|
+
publishUpgradeFailure(conversation, previousVersionId, targetVersionId, error) {
|
|
1205
|
+
this.publishHostedEvent(conversation.id, {
|
|
1206
|
+
conversationId: conversation.id,
|
|
1207
|
+
kind: 'upgrade',
|
|
1208
|
+
upgrade: {
|
|
1209
|
+
status: 'FAILED',
|
|
1210
|
+
previousVersionId,
|
|
1211
|
+
targetVersionId,
|
|
1212
|
+
activeVersionId: conversation.activeVersionId,
|
|
1213
|
+
conversation: this.summary(conversation),
|
|
1214
|
+
error: {
|
|
1215
|
+
code: safeErrorCode(error, 'HOSTED_CONVERSATION_UPGRADE_FAILED'),
|
|
1216
|
+
message: 'The conversation template upgrade failed.'
|
|
1217
|
+
}
|
|
1218
|
+
}
|
|
1219
|
+
});
|
|
1220
|
+
}
|
|
1221
|
+
publishHostedEvent(conversationId, payload) {
|
|
1222
|
+
const leases = [...this.watchLeases.values()].filter((lease) => lease.conversationId === conversationId);
|
|
1223
|
+
if (leases.length === 0)
|
|
1224
|
+
return false;
|
|
1225
|
+
const event = this.options.nextWorkbenchEvent?.(payload) ?? {
|
|
1226
|
+
sequence: ++this.workbenchSequence,
|
|
1227
|
+
category: 'hosted-conversation',
|
|
1228
|
+
payload
|
|
1229
|
+
};
|
|
1230
|
+
if (event === undefined)
|
|
1231
|
+
return false;
|
|
1232
|
+
for (const lease of leases) {
|
|
1233
|
+
if (!lease.ready)
|
|
1234
|
+
lease.pendingEvents.push(event);
|
|
1235
|
+
else
|
|
1236
|
+
this.emitWatchLeaseEvent(lease, event);
|
|
1237
|
+
}
|
|
1238
|
+
return true;
|
|
1239
|
+
}
|
|
1240
|
+
emitWatchLeaseEvent(lease, event) {
|
|
1241
|
+
this.options.emitWatchEvent?.({
|
|
1242
|
+
type: 'watch.hosted-conversation.event',
|
|
1243
|
+
workbenchConnectionId: lease.workbenchConnectionId,
|
|
1244
|
+
watchId: lease.watchId,
|
|
1245
|
+
nodeGeneration: lease.nodeGeneration,
|
|
1246
|
+
nodeId: this.options.nodeId(),
|
|
1247
|
+
templateId: lease.templateId,
|
|
1248
|
+
conversationId: lease.conversationId,
|
|
1249
|
+
expiresAt: lease.expiresAt,
|
|
1250
|
+
event
|
|
1251
|
+
});
|
|
1252
|
+
}
|
|
1253
|
+
acceptedWatch(lease) {
|
|
1254
|
+
return {
|
|
1255
|
+
accepted: true,
|
|
1256
|
+
watchId: lease.watchId,
|
|
1257
|
+
nodeGeneration: lease.nodeGeneration,
|
|
1258
|
+
expiresAt: lease.expiresAt
|
|
1259
|
+
};
|
|
1260
|
+
}
|
|
1261
|
+
removeConversationWatchLeases(conversationId) {
|
|
1262
|
+
for (const lease of [...this.watchLeases.values()])
|
|
1263
|
+
if (lease.conversationId === conversationId)
|
|
1264
|
+
this.removeWatchLease(lease.ownerKey);
|
|
1265
|
+
}
|
|
1266
|
+
removeWatchLease(ownerKey) {
|
|
1267
|
+
const lease = this.watchLeases.get(ownerKey);
|
|
1268
|
+
if (lease === undefined)
|
|
1269
|
+
return;
|
|
1270
|
+
clearTimeout(lease.timer);
|
|
1271
|
+
this.watchLeases.delete(ownerKey);
|
|
1272
|
+
this.sessionWatchSlots.release(ownerKey, lease.slotToken);
|
|
1273
|
+
}
|
|
1274
|
+
watchLeaseTimer(ownerKey) {
|
|
1275
|
+
const timer = setTimeout(() => this.removeWatchLease(ownerKey), WATCH_TTL_MS);
|
|
1276
|
+
timer.unref();
|
|
1277
|
+
return timer;
|
|
1278
|
+
}
|
|
1279
|
+
requireWritableConversation(userId, conversationId) {
|
|
1280
|
+
const conversation = this.options.store.requireConversation(userId, conversationId);
|
|
1281
|
+
if (this.cleanupLocks.has(conversation.id))
|
|
1282
|
+
throw new Error('HOSTED_CONVERSATION_STATE_INVALID');
|
|
1283
|
+
if (conversation.status !== 'ACTIVE')
|
|
1284
|
+
throw new Error('HOSTED_CONVERSATION_STATE_INVALID');
|
|
1285
|
+
return conversation;
|
|
1286
|
+
}
|
|
1287
|
+
requireUpload(userId, conversationId, uploadId) {
|
|
1288
|
+
this.options.store.requireConversation(userId, conversationId);
|
|
1289
|
+
const upload = this.uploads.get(uploadId);
|
|
1290
|
+
if (upload === undefined ||
|
|
1291
|
+
upload.userId !== userId ||
|
|
1292
|
+
upload.conversationId !== conversationId)
|
|
1293
|
+
throw new Error('HOSTED_CONVERSATION_UPLOAD_NOT_FOUND');
|
|
1294
|
+
return upload;
|
|
1295
|
+
}
|
|
1296
|
+
async cancelConversationUploads(userId, conversationId) {
|
|
1297
|
+
for (const upload of this.uploads.values()) {
|
|
1298
|
+
if (upload.userId !== userId || upload.conversationId !== conversationId)
|
|
1299
|
+
continue;
|
|
1300
|
+
if (upload.status === 'UPLOADING') {
|
|
1301
|
+
upload.status = 'CANCELLED';
|
|
1302
|
+
await rm(upload.temporaryPath, { force: true }).catch(() => undefined);
|
|
1303
|
+
}
|
|
1304
|
+
}
|
|
1305
|
+
}
|
|
1306
|
+
async requireAttachment(userId, conversationId, fileId) {
|
|
1307
|
+
const file = this.options.store.requireFile(userId, conversationId, fileId);
|
|
1308
|
+
if (file.category !== 'UPLOAD')
|
|
1309
|
+
throw new Error('HOSTED_CONVERSATION_ATTACHMENT_INVALID');
|
|
1310
|
+
await assertRegularFile(this.options.store.filePath(userId, file), file.size);
|
|
1311
|
+
return file;
|
|
1312
|
+
}
|
|
1313
|
+
async uploadPreflightStatus(paths, conversation, draft, name, size) {
|
|
1314
|
+
if (size > draft.quotas.maxUploadBytes)
|
|
1315
|
+
return 'TOO_LARGE';
|
|
1316
|
+
if (conversation.quota.usedBytes + size > conversation.quota.maxBytes)
|
|
1317
|
+
return 'QUOTA_EXCEEDED';
|
|
1318
|
+
const target = await lstat(join(paths.uploadsDirectory, name)).catch((error) => {
|
|
1319
|
+
if (error.code === 'ENOENT')
|
|
1320
|
+
return undefined;
|
|
1321
|
+
throw error;
|
|
1322
|
+
});
|
|
1323
|
+
return target === undefined ? 'READY' : 'CONFLICT';
|
|
1324
|
+
}
|
|
1325
|
+
pathMounts(paths, version, generatedImagesDirectory, generatedImagesLogicalPath, temporaryDirectory) {
|
|
1326
|
+
const mounts = [
|
|
1327
|
+
{
|
|
1328
|
+
logicalPath: '/workspace',
|
|
1329
|
+
physicalPath: version.templateDirectory,
|
|
1330
|
+
writable: false
|
|
1331
|
+
},
|
|
1332
|
+
{
|
|
1333
|
+
logicalPath: '/workspace/inbox',
|
|
1334
|
+
physicalPath: paths.uploadsDirectory,
|
|
1335
|
+
writable: true
|
|
1336
|
+
},
|
|
1337
|
+
{
|
|
1338
|
+
logicalPath: '/workspace/output',
|
|
1339
|
+
physicalPath: paths.outputDirectory,
|
|
1340
|
+
writable: true
|
|
1341
|
+
}
|
|
1342
|
+
];
|
|
1343
|
+
if (temporaryDirectory !== undefined)
|
|
1344
|
+
mounts.push({
|
|
1345
|
+
logicalPath: '/tmp',
|
|
1346
|
+
physicalPath: temporaryDirectory,
|
|
1347
|
+
writable: true
|
|
1348
|
+
});
|
|
1349
|
+
if (generatedImagesDirectory !== undefined && generatedImagesLogicalPath !== undefined)
|
|
1350
|
+
mounts.push({
|
|
1351
|
+
logicalPath: generatedImagesLogicalPath,
|
|
1352
|
+
physicalPath: generatedImagesDirectory,
|
|
1353
|
+
writable: false
|
|
1354
|
+
});
|
|
1355
|
+
if (version.sourceWorkspacePath !== undefined)
|
|
1356
|
+
mounts.push({
|
|
1357
|
+
logicalPath: version.sourceWorkspacePath,
|
|
1358
|
+
physicalPath: version.templateDirectory,
|
|
1359
|
+
writable: false
|
|
1360
|
+
}, {
|
|
1361
|
+
logicalPath: join(version.sourceWorkspacePath, 'inbox'),
|
|
1362
|
+
physicalPath: paths.uploadsDirectory,
|
|
1363
|
+
writable: true
|
|
1364
|
+
}, {
|
|
1365
|
+
logicalPath: join(version.sourceWorkspacePath, 'output'),
|
|
1366
|
+
physicalPath: paths.outputDirectory,
|
|
1367
|
+
writable: true
|
|
1368
|
+
});
|
|
1369
|
+
return mounts;
|
|
1370
|
+
}
|
|
1371
|
+
processExecutor(paths, version, temporaryDirectory = paths.temporaryRootDirectory, generatedImagesDirectory, generatedImagesLogicalPath) {
|
|
1372
|
+
return this.options.processExecutorFactory({
|
|
1373
|
+
policyVersion: HOST_POLICY_VERSION,
|
|
1374
|
+
workspaceDirectory: version.templateDirectory,
|
|
1375
|
+
...(version.sourceWorkspacePath === undefined
|
|
1376
|
+
? {}
|
|
1377
|
+
: { sourceWorkspacePath: version.sourceWorkspacePath }),
|
|
1378
|
+
inboxDirectory: paths.uploadsDirectory,
|
|
1379
|
+
outputDirectory: paths.outputDirectory,
|
|
1380
|
+
...(generatedImagesDirectory === undefined || generatedImagesLogicalPath === undefined
|
|
1381
|
+
? {}
|
|
1382
|
+
: { generatedImagesDirectory, generatedImagesLogicalPath }),
|
|
1383
|
+
temporaryDirectory,
|
|
1384
|
+
networkMode: version.draft.networkMode
|
|
1385
|
+
});
|
|
1386
|
+
}
|
|
1387
|
+
latestAvailableTemplateVersionId(templateId) {
|
|
1388
|
+
const row = this.options.database.raw
|
|
1389
|
+
.prepare(`SELECT id FROM conversation_template_versions
|
|
1390
|
+
WHERE template_id=? AND status='AVAILABLE'
|
|
1391
|
+
ORDER BY version_number DESC,published_at DESC,id DESC
|
|
1392
|
+
LIMIT 1`)
|
|
1393
|
+
.get(templateId);
|
|
1394
|
+
if (row === undefined)
|
|
1395
|
+
return undefined;
|
|
1396
|
+
if (typeof row.id !== 'string')
|
|
1397
|
+
throw new Error('CONVERSATION_TEMPLATE_VERSION_CORRUPTED');
|
|
1398
|
+
return row.id;
|
|
1399
|
+
}
|
|
1400
|
+
async loadTemplateVersion(versionId, templateId) {
|
|
1401
|
+
const row = this.options.database.raw
|
|
1402
|
+
.prepare(`SELECT id,template_id,status,storage_key,manifest,content_hash,manifest_hash,mcp_config_hash,
|
|
1403
|
+
file_count,total_bytes,host_policy_version
|
|
1404
|
+
FROM conversation_template_versions WHERE id=? AND template_id=?`)
|
|
1405
|
+
.get(versionId, templateId);
|
|
1406
|
+
if (row === undefined ||
|
|
1407
|
+
(row.status !== 'AVAILABLE' && row.status !== 'RETAINED') ||
|
|
1408
|
+
row.host_policy_version !== HOST_POLICY_VERSION ||
|
|
1409
|
+
typeof row.storage_key !== 'string' ||
|
|
1410
|
+
typeof row.manifest !== 'string' ||
|
|
1411
|
+
typeof row.content_hash !== 'string' ||
|
|
1412
|
+
typeof row.manifest_hash !== 'string' ||
|
|
1413
|
+
typeof row.mcp_config_hash !== 'string')
|
|
1414
|
+
throw new Error('CONVERSATION_TEMPLATE_VERSION_CORRUPTED');
|
|
1415
|
+
const versionDirectory = this.options.store.templateVersionDirectory(row.storage_key);
|
|
1416
|
+
const manifestPath = join(versionDirectory, 'manifest.json');
|
|
1417
|
+
const contentDirectory = join(versionDirectory, 'content');
|
|
1418
|
+
const manifestInfo = await lstat(manifestPath).catch(() => undefined);
|
|
1419
|
+
const contentInfo = await lstat(contentDirectory).catch(() => undefined);
|
|
1420
|
+
if (manifestInfo === undefined ||
|
|
1421
|
+
!manifestInfo.isFile() ||
|
|
1422
|
+
manifestInfo.isSymbolicLink() ||
|
|
1423
|
+
contentInfo === undefined ||
|
|
1424
|
+
!contentInfo.isDirectory() ||
|
|
1425
|
+
contentInfo.isSymbolicLink() ||
|
|
1426
|
+
(contentInfo.mode & 0o777) !== 0o555)
|
|
1427
|
+
throw new Error('CONVERSATION_TEMPLATE_VERSION_CORRUPTED');
|
|
1428
|
+
let persisted;
|
|
1429
|
+
try {
|
|
1430
|
+
const manifestText = await readFile(manifestPath, 'utf8');
|
|
1431
|
+
const manifestJson = manifestText.endsWith('\n') ? manifestText.slice(0, -1) : manifestText;
|
|
1432
|
+
if (manifestJson !== row.manifest ||
|
|
1433
|
+
createHash('sha256').update(manifestJson).digest('hex') !== row.manifest_hash)
|
|
1434
|
+
throw new Error('CONVERSATION_TEMPLATE_VERSION_CORRUPTED');
|
|
1435
|
+
persisted = JSON.parse(manifestJson);
|
|
1436
|
+
}
|
|
1437
|
+
catch {
|
|
1438
|
+
throw new Error('CONVERSATION_TEMPLATE_VERSION_CORRUPTED');
|
|
1439
|
+
}
|
|
1440
|
+
if (!record(persisted))
|
|
1441
|
+
throw new Error('CONVERSATION_TEMPLATE_VERSION_CORRUPTED');
|
|
1442
|
+
const snapshot = publishedTemplateSnapshot(persisted);
|
|
1443
|
+
const parsedDraft = publishedTemplateDraft(snapshot.schemaVersion, persisted.draft);
|
|
1444
|
+
const draft = parsedDraft.draft;
|
|
1445
|
+
const mcpServers = publishedMcpServers(persisted.mcpServers);
|
|
1446
|
+
const contentHash = publishedTemplateContentHash(snapshot.directories, snapshot.entries, snapshot.schemaVersion);
|
|
1447
|
+
const totalBytes = snapshot.entries.reduce((total, entry) => total + entry.size, 0);
|
|
1448
|
+
if (persisted.mcpConfigHash !== row.mcp_config_hash ||
|
|
1449
|
+
createHash('sha256').update(JSON.stringify(mcpServers)).digest('hex') !==
|
|
1450
|
+
row.mcp_config_hash ||
|
|
1451
|
+
persisted.contentHash !== row.content_hash ||
|
|
1452
|
+
contentHash !== row.content_hash ||
|
|
1453
|
+
row.file_count !== snapshot.entries.length ||
|
|
1454
|
+
row.total_bytes !== totalBytes)
|
|
1455
|
+
throw new Error('CONVERSATION_TEMPLATE_VERSION_CORRUPTED');
|
|
1456
|
+
if (persisted.versionId !== versionId ||
|
|
1457
|
+
persisted.templateId !== templateId ||
|
|
1458
|
+
persisted.hostPolicyVersion !== HOST_POLICY_VERSION ||
|
|
1459
|
+
draft.templateId !== templateId ||
|
|
1460
|
+
draft.nodeId !== this.options.nodeId())
|
|
1461
|
+
throw new Error('CONVERSATION_TEMPLATE_VERSION_CORRUPTED');
|
|
1462
|
+
return {
|
|
1463
|
+
id: versionId,
|
|
1464
|
+
templateId,
|
|
1465
|
+
storageKey: row.storage_key,
|
|
1466
|
+
templateDirectory: contentDirectory,
|
|
1467
|
+
...(snapshot.sourceWorkspacePath === undefined
|
|
1468
|
+
? {}
|
|
1469
|
+
: { sourceWorkspacePath: snapshot.sourceWorkspacePath }),
|
|
1470
|
+
draft,
|
|
1471
|
+
modelPolicy: parsedDraft.modelPolicy,
|
|
1472
|
+
mcpServers
|
|
1473
|
+
};
|
|
1474
|
+
}
|
|
1475
|
+
}
|
|
1476
|
+
function hostedRequest(raw) {
|
|
1477
|
+
if (!record(raw))
|
|
1478
|
+
throw new Error('HOSTED_CONVERSATION_NOT_AUTHORIZED');
|
|
1479
|
+
const { __requestUserId, __template, __marAgentModel, __marAgentModels, __marAgentRuntimeScopeId, __workspaceWatchSessionHash, __templateDeleted, ...data } = raw;
|
|
1480
|
+
if (typeof __requestUserId !== 'number' ||
|
|
1481
|
+
!Number.isSafeInteger(__requestUserId) ||
|
|
1482
|
+
__requestUserId <= 0)
|
|
1483
|
+
throw new Error('HOSTED_CONVERSATION_NOT_AUTHORIZED');
|
|
1484
|
+
if (__templateDeleted !== undefined && __templateDeleted !== true)
|
|
1485
|
+
throw new Error('HOSTED_CONVERSATION_NOT_AUTHORIZED');
|
|
1486
|
+
if (__marAgentRuntimeScopeId !== undefined &&
|
|
1487
|
+
(typeof __marAgentRuntimeScopeId !== 'string' || __marAgentRuntimeScopeId.length === 0))
|
|
1488
|
+
throw new Error('HOSTED_CONVERSATION_NOT_AUTHORIZED');
|
|
1489
|
+
return {
|
|
1490
|
+
data,
|
|
1491
|
+
userId: __requestUserId,
|
|
1492
|
+
...(__template === undefined ? {} : { template: __template }),
|
|
1493
|
+
...(__marAgentModel === undefined ? {} : { model: __marAgentModel }),
|
|
1494
|
+
...(__marAgentModels === undefined ? {} : { models: __marAgentModels }),
|
|
1495
|
+
...(__marAgentRuntimeScopeId === undefined ? {} : { runtimeScopeId: __marAgentRuntimeScopeId }),
|
|
1496
|
+
...(__workspaceWatchSessionHash === undefined
|
|
1497
|
+
? {}
|
|
1498
|
+
: { sessionHash: __workspaceWatchSessionHash }),
|
|
1499
|
+
...(__templateDeleted === true ? { templateDeleted: true } : {})
|
|
1500
|
+
};
|
|
1501
|
+
}
|
|
1502
|
+
function requireWatchSessionHash(value) {
|
|
1503
|
+
if (typeof value !== 'string' || value.length === 0)
|
|
1504
|
+
throw new Error('HOSTED_CONVERSATION_NOT_AUTHORIZED');
|
|
1505
|
+
return value;
|
|
1506
|
+
}
|
|
1507
|
+
function watchOwnerKey(sessionHash, workbenchConnectionId) {
|
|
1508
|
+
return `${sessionHash}:${workbenchConnectionId}`;
|
|
1509
|
+
}
|
|
1510
|
+
function runtimeModels(value) {
|
|
1511
|
+
return marAgentRuntimeModelConfigurationSchema
|
|
1512
|
+
.array()
|
|
1513
|
+
.parse(value);
|
|
1514
|
+
}
|
|
1515
|
+
function allowedModels(version, models) {
|
|
1516
|
+
const allowed = new Set(version.modelPolicy.allowedIds);
|
|
1517
|
+
return models.filter((model) => model.enabled &&
|
|
1518
|
+
allowed.has(version.modelPolicy.identity === 'UPSTREAM_MODEL_ID' ? model.modelId : model.id));
|
|
1519
|
+
}
|
|
1520
|
+
function selectModel(version, models, requestedModelId) {
|
|
1521
|
+
const available = allowedModels(version, models);
|
|
1522
|
+
const requested = available.find((candidate) => candidate.id === requestedModelId);
|
|
1523
|
+
if (requested !== undefined)
|
|
1524
|
+
return requested;
|
|
1525
|
+
const defaultModel = available.find((candidate) => (version.modelPolicy.identity === 'UPSTREAM_MODEL_ID' ? candidate.modelId : candidate.id) ===
|
|
1526
|
+
version.modelPolicy.defaultId);
|
|
1527
|
+
if (defaultModel !== undefined)
|
|
1528
|
+
return defaultModel;
|
|
1529
|
+
const model = version.modelPolicy.allowedIds
|
|
1530
|
+
.map((allowedId) => available.find((candidate) => (version.modelPolicy.identity === 'UPSTREAM_MODEL_ID'
|
|
1531
|
+
? candidate.modelId
|
|
1532
|
+
: candidate.id) === allowedId))
|
|
1533
|
+
.find((candidate) => candidate !== undefined);
|
|
1534
|
+
if (model === undefined)
|
|
1535
|
+
throw new Error('HOSTED_CONVERSATION_MODEL_NOT_AVAILABLE');
|
|
1536
|
+
return model;
|
|
1537
|
+
}
|
|
1538
|
+
function publishedTemplateDraft(schemaVersion, value) {
|
|
1539
|
+
const current = conversationTemplateDraftSchema.safeParse(value);
|
|
1540
|
+
if (current.success) {
|
|
1541
|
+
const { allowedModels, defaultModelId, ...draft } = current.data;
|
|
1542
|
+
return {
|
|
1543
|
+
draft,
|
|
1544
|
+
modelPolicy: {
|
|
1545
|
+
identity: 'UPSTREAM_MODEL_ID',
|
|
1546
|
+
allowedIds: allowedModels.map((model) => model.modelId),
|
|
1547
|
+
defaultId: defaultModelId
|
|
1548
|
+
}
|
|
1549
|
+
};
|
|
1550
|
+
}
|
|
1551
|
+
if (schemaVersion !== 1 ||
|
|
1552
|
+
!record(value) ||
|
|
1553
|
+
'allowedModels' in value ||
|
|
1554
|
+
!Array.isArray(value.allowedModelIds))
|
|
1555
|
+
throw new Error('CONVERSATION_TEMPLATE_VERSION_CORRUPTED');
|
|
1556
|
+
const allowedModelIds = value.allowedModelIds;
|
|
1557
|
+
const legacy = { ...value };
|
|
1558
|
+
delete legacy.allowedModelIds;
|
|
1559
|
+
const normalized = conversationTemplateDraftSchema.safeParse({
|
|
1560
|
+
...legacy,
|
|
1561
|
+
allowedModels: allowedModelIds.map((modelId) => ({ modelId, name: modelId }))
|
|
1562
|
+
});
|
|
1563
|
+
if (!normalized.success)
|
|
1564
|
+
throw new Error('CONVERSATION_TEMPLATE_VERSION_CORRUPTED');
|
|
1565
|
+
const { allowedModels, defaultModelId, ...draft } = normalized.data;
|
|
1566
|
+
return {
|
|
1567
|
+
draft,
|
|
1568
|
+
modelPolicy: {
|
|
1569
|
+
identity: 'CONFIGURATION_ID',
|
|
1570
|
+
allowedIds: allowedModels.map((model) => model.modelId),
|
|
1571
|
+
defaultId: defaultModelId
|
|
1572
|
+
}
|
|
1573
|
+
};
|
|
1574
|
+
}
|
|
1575
|
+
function networkModels(models, networkMode) {
|
|
1576
|
+
if (networkMode !== 'NONE')
|
|
1577
|
+
return models;
|
|
1578
|
+
return models.map((model) => model.hostedWebSearch ? { ...model, hostedWebSearch: false } : model);
|
|
1579
|
+
}
|
|
1580
|
+
function publishedMcpServers(value) {
|
|
1581
|
+
if (!Array.isArray(value))
|
|
1582
|
+
throw new Error('CONVERSATION_TEMPLATE_VERSION_CORRUPTED');
|
|
1583
|
+
return value.map((candidate) => {
|
|
1584
|
+
if (!record(candidate))
|
|
1585
|
+
throw new Error('CONVERSATION_TEMPLATE_VERSION_CORRUPTED');
|
|
1586
|
+
const keys = Object.keys(candidate).sort().join(',');
|
|
1587
|
+
if (keys !== 'configuration,displayName,id,origin,runtime,serverName,transport,version')
|
|
1588
|
+
throw new Error('CONVERSATION_TEMPLATE_VERSION_CORRUPTED');
|
|
1589
|
+
const runtime = mcpRuntimeDescriptorSchema.parse(candidate.runtime);
|
|
1590
|
+
const configuration = mcpInstallationConfigurationSchema.parse(candidate.configuration);
|
|
1591
|
+
if (typeof candidate.id !== 'string' ||
|
|
1592
|
+
typeof candidate.serverName !== 'string' ||
|
|
1593
|
+
typeof candidate.displayName !== 'string' ||
|
|
1594
|
+
typeof candidate.version !== 'string' ||
|
|
1595
|
+
(candidate.origin !== 'NODE' && candidate.origin !== 'WORKSPACE') ||
|
|
1596
|
+
candidate.transport !== runtime.transport)
|
|
1597
|
+
throw new Error('CONVERSATION_TEMPLATE_VERSION_CORRUPTED');
|
|
1598
|
+
return {
|
|
1599
|
+
id: candidate.id,
|
|
1600
|
+
serverName: candidate.serverName,
|
|
1601
|
+
displayName: candidate.displayName,
|
|
1602
|
+
version: candidate.version,
|
|
1603
|
+
origin: candidate.origin,
|
|
1604
|
+
transport: runtime.transport,
|
|
1605
|
+
runtime,
|
|
1606
|
+
configuration
|
|
1607
|
+
};
|
|
1608
|
+
});
|
|
1609
|
+
}
|
|
1610
|
+
function publishedTemplateSnapshot(manifest) {
|
|
1611
|
+
if (manifest.schemaVersion === 1) {
|
|
1612
|
+
const entries = publishedTemplateFiles(manifest.files);
|
|
1613
|
+
return {
|
|
1614
|
+
schemaVersion: 1,
|
|
1615
|
+
directories: legacyPublishedTemplateDirectories(entries),
|
|
1616
|
+
entries
|
|
1617
|
+
};
|
|
1618
|
+
}
|
|
1619
|
+
if (manifest.schemaVersion !== 2 ||
|
|
1620
|
+
typeof manifest.sourceWorkspacePath !== 'string' ||
|
|
1621
|
+
!Array.isArray(manifest.directories) ||
|
|
1622
|
+
!Array.isArray(manifest.entries))
|
|
1623
|
+
throw new Error('CONVERSATION_TEMPLATE_VERSION_CORRUPTED');
|
|
1624
|
+
validatePublishedSourceWorkspacePath(manifest.sourceWorkspacePath);
|
|
1625
|
+
const directories = manifest.directories.map(safePublishedTemplateRelativePath);
|
|
1626
|
+
if (new Set(directories).size !== directories.length ||
|
|
1627
|
+
directories.includes('inbox') ||
|
|
1628
|
+
directories.includes('output'))
|
|
1629
|
+
throw new Error('CONVERSATION_TEMPLATE_VERSION_CORRUPTED');
|
|
1630
|
+
const entries = manifest.entries.map(publishedTemplateEntry);
|
|
1631
|
+
if (new Set(entries.map((entry) => entry.relativePath)).size !== entries.length)
|
|
1632
|
+
throw new Error('CONVERSATION_TEMPLATE_VERSION_CORRUPTED');
|
|
1633
|
+
return {
|
|
1634
|
+
schemaVersion: 2,
|
|
1635
|
+
sourceWorkspacePath: manifest.sourceWorkspacePath,
|
|
1636
|
+
directories,
|
|
1637
|
+
entries
|
|
1638
|
+
};
|
|
1639
|
+
}
|
|
1640
|
+
function publishedTemplateEntry(value) {
|
|
1641
|
+
if (!record(value))
|
|
1642
|
+
throw new Error('CONVERSATION_TEMPLATE_VERSION_CORRUPTED');
|
|
1643
|
+
if (value.kind === 'FILE')
|
|
1644
|
+
return publishedTemplateFile(value, true);
|
|
1645
|
+
if (value.kind !== 'SYMLINK' ||
|
|
1646
|
+
typeof value.linkTarget !== 'string' ||
|
|
1647
|
+
value.linkTarget.length === 0 ||
|
|
1648
|
+
value.linkTarget.includes('\0') ||
|
|
1649
|
+
(value.targetKind !== 'SNAPSHOT' && value.targetKind !== 'RUNTIME') ||
|
|
1650
|
+
typeof value.resolvedTarget !== 'string')
|
|
1651
|
+
throw new Error('CONVERSATION_TEMPLATE_VERSION_CORRUPTED');
|
|
1652
|
+
const relativePath = safePublishedTemplateRelativePath(value.relativePath);
|
|
1653
|
+
const size = safePublishedTemplateSize(value.size);
|
|
1654
|
+
const linkTarget = value.linkTarget;
|
|
1655
|
+
const targetKind = value.targetKind;
|
|
1656
|
+
const resolvedTarget = value.resolvedTarget;
|
|
1657
|
+
if (size !== Buffer.byteLength(linkTarget))
|
|
1658
|
+
throw new Error('CONVERSATION_TEMPLATE_VERSION_CORRUPTED');
|
|
1659
|
+
if (targetKind === 'SNAPSHOT')
|
|
1660
|
+
safePublishedTemplateRelativePath(resolvedTarget);
|
|
1661
|
+
else if (!isAbsolute(resolvedTarget) ||
|
|
1662
|
+
!RUNTIME_LINK_ROOTS.some((root) => resolvedTarget === root || within(root, resolvedTarget)))
|
|
1663
|
+
throw new Error('CONVERSATION_TEMPLATE_VERSION_CORRUPTED');
|
|
1664
|
+
return {
|
|
1665
|
+
kind: 'SYMLINK',
|
|
1666
|
+
relativePath,
|
|
1667
|
+
size,
|
|
1668
|
+
linkTarget,
|
|
1669
|
+
targetKind,
|
|
1670
|
+
resolvedTarget
|
|
1671
|
+
};
|
|
1672
|
+
}
|
|
1673
|
+
function publishedTemplateFiles(value) {
|
|
1674
|
+
if (!Array.isArray(value))
|
|
1675
|
+
throw new Error('CONVERSATION_TEMPLATE_VERSION_CORRUPTED');
|
|
1676
|
+
const paths = new Set();
|
|
1677
|
+
return value.map((candidate) => {
|
|
1678
|
+
const file = publishedTemplateFile(candidate);
|
|
1679
|
+
if (paths.has(file.relativePath))
|
|
1680
|
+
throw new Error('CONVERSATION_TEMPLATE_VERSION_CORRUPTED');
|
|
1681
|
+
paths.add(file.relativePath);
|
|
1682
|
+
return file;
|
|
1683
|
+
});
|
|
1684
|
+
}
|
|
1685
|
+
function publishedTemplateFile(value, requireKind = false) {
|
|
1686
|
+
if (!record(value) ||
|
|
1687
|
+
(requireKind && value.kind !== 'FILE') ||
|
|
1688
|
+
typeof value.executable !== 'boolean' ||
|
|
1689
|
+
typeof value.sha256 !== 'string' ||
|
|
1690
|
+
!/^[a-f0-9]{64}$/u.test(value.sha256))
|
|
1691
|
+
throw new Error('CONVERSATION_TEMPLATE_VERSION_CORRUPTED');
|
|
1692
|
+
return {
|
|
1693
|
+
kind: 'FILE',
|
|
1694
|
+
relativePath: safePublishedTemplateRelativePath(value.relativePath),
|
|
1695
|
+
size: safePublishedTemplateSize(value.size),
|
|
1696
|
+
executable: value.executable,
|
|
1697
|
+
sha256: value.sha256
|
|
1698
|
+
};
|
|
1699
|
+
}
|
|
1700
|
+
function safePublishedTemplateRelativePath(value) {
|
|
1701
|
+
if (typeof value !== 'string' ||
|
|
1702
|
+
value.length === 0 ||
|
|
1703
|
+
value.startsWith('/') ||
|
|
1704
|
+
value.includes('\\') ||
|
|
1705
|
+
value.split('/').some((segment) => segment.length === 0 || segment === '.' || segment === '..'))
|
|
1706
|
+
throw new Error('CONVERSATION_TEMPLATE_VERSION_CORRUPTED');
|
|
1707
|
+
return value;
|
|
1708
|
+
}
|
|
1709
|
+
function safePublishedTemplateSize(value) {
|
|
1710
|
+
if (!Number.isSafeInteger(value) || value < 0)
|
|
1711
|
+
throw new Error('CONVERSATION_TEMPLATE_VERSION_CORRUPTED');
|
|
1712
|
+
return value;
|
|
1713
|
+
}
|
|
1714
|
+
function legacyPublishedTemplateDirectories(entries) {
|
|
1715
|
+
const directories = new Set();
|
|
1716
|
+
for (const entry of entries) {
|
|
1717
|
+
const parts = entry.relativePath.split('/');
|
|
1718
|
+
for (let index = 1; index < parts.length; index += 1)
|
|
1719
|
+
directories.add(parts.slice(0, index).join('/'));
|
|
1720
|
+
}
|
|
1721
|
+
return [...directories].sort((left, right) => left.localeCompare(right, 'en-US'));
|
|
1722
|
+
}
|
|
1723
|
+
function publishedTemplateContentHash(directories, entries, schemaVersion) {
|
|
1724
|
+
const content = schemaVersion === 1
|
|
1725
|
+
? entries
|
|
1726
|
+
.map((entry) => {
|
|
1727
|
+
if (entry.kind !== 'FILE')
|
|
1728
|
+
throw new Error('CONVERSATION_TEMPLATE_VERSION_CORRUPTED');
|
|
1729
|
+
return `${entry.relativePath}\0${entry.size}\0${entry.sha256}`;
|
|
1730
|
+
})
|
|
1731
|
+
.join('\n')
|
|
1732
|
+
: [
|
|
1733
|
+
...directories.map((directory) => `DIRECTORY\0${directory}`),
|
|
1734
|
+
...entries.map((entry) => entry.kind === 'FILE'
|
|
1735
|
+
? `${entry.kind}\0${entry.relativePath}\0${entry.size}\0${entry.executable ? 1 : 0}\0${entry.sha256}`
|
|
1736
|
+
: `${entry.kind}\0${entry.relativePath}\0${entry.size}\0${entry.linkTarget}\0${entry.targetKind}\0${entry.resolvedTarget}`)
|
|
1737
|
+
].join('\n');
|
|
1738
|
+
return createHash('sha256').update(content).digest('hex');
|
|
1739
|
+
}
|
|
1740
|
+
function validatePublishedSourceWorkspacePath(path) {
|
|
1741
|
+
if (!isAbsolute(path) ||
|
|
1742
|
+
resolve(path) !== path ||
|
|
1743
|
+
path === '/' ||
|
|
1744
|
+
RESERVED_SANDBOX_ROOTS.some((root) => path === root || within(root, path) || within(path, root)))
|
|
1745
|
+
throw new Error('CONVERSATION_TEMPLATE_VERSION_CORRUPTED');
|
|
1746
|
+
}
|
|
1747
|
+
function within(parent, candidate) {
|
|
1748
|
+
const relation = relative(parent, candidate);
|
|
1749
|
+
return relation.length > 0 && relation !== '..' && !relation.startsWith(`..${sep}`);
|
|
1750
|
+
}
|
|
1751
|
+
function resolveMcpServers(version, environment) {
|
|
1752
|
+
const resolveReferences = (references) => {
|
|
1753
|
+
const resolved = {};
|
|
1754
|
+
for (const [name, reference] of Object.entries(references ?? {})) {
|
|
1755
|
+
const value = environment[reference.secretName];
|
|
1756
|
+
if (value === undefined)
|
|
1757
|
+
throw new Error('CONVERSATION_TEMPLATE_MCP_INVALID');
|
|
1758
|
+
resolved[name] = value;
|
|
1759
|
+
}
|
|
1760
|
+
return resolved;
|
|
1761
|
+
};
|
|
1762
|
+
return version.mcpServers.flatMap((server) => {
|
|
1763
|
+
if (server.runtime.transport === 'HTTP') {
|
|
1764
|
+
if (version.draft.networkMode !== 'UNRESTRICTED')
|
|
1765
|
+
return [];
|
|
1766
|
+
return [
|
|
1767
|
+
{
|
|
1768
|
+
name: server.serverName,
|
|
1769
|
+
lifecycle: 'EXECUTION',
|
|
1770
|
+
transport: 'HTTP',
|
|
1771
|
+
url: server.runtime.url,
|
|
1772
|
+
headers: {
|
|
1773
|
+
...resolveReferences(server.runtime.headers),
|
|
1774
|
+
...resolveReferences(server.configuration.headers)
|
|
1775
|
+
}
|
|
1776
|
+
}
|
|
1777
|
+
];
|
|
1778
|
+
}
|
|
1779
|
+
return [
|
|
1780
|
+
{
|
|
1781
|
+
name: server.serverName,
|
|
1782
|
+
lifecycle: 'EXECUTION',
|
|
1783
|
+
transport: 'STDIO',
|
|
1784
|
+
command: server.runtime.command,
|
|
1785
|
+
args: [...server.runtime.args, ...(server.configuration.arguments ?? [])],
|
|
1786
|
+
environment: {
|
|
1787
|
+
...resolveReferences(server.runtime.environment),
|
|
1788
|
+
...resolveReferences(server.configuration.environment)
|
|
1789
|
+
}
|
|
1790
|
+
}
|
|
1791
|
+
];
|
|
1792
|
+
});
|
|
1793
|
+
}
|
|
1794
|
+
function hostedConversationSummary(manifest, activity) {
|
|
1795
|
+
return hostedConversationSummarySchema.parse({
|
|
1796
|
+
id: manifest.id,
|
|
1797
|
+
nodeId: manifest.nodeId,
|
|
1798
|
+
sessionId: manifest.sessionId,
|
|
1799
|
+
templateId: manifest.templateId,
|
|
1800
|
+
templateName: manifest.templateName,
|
|
1801
|
+
activeVersionId: manifest.activeVersionId,
|
|
1802
|
+
title: manifest.title,
|
|
1803
|
+
titleSource: manifest.titleSource,
|
|
1804
|
+
pinnedAt: manifest.pinnedAt,
|
|
1805
|
+
status: manifest.status,
|
|
1806
|
+
modelId: manifest.modelId,
|
|
1807
|
+
createdAt: manifest.createdAt,
|
|
1808
|
+
updatedAt: manifest.updatedAt,
|
|
1809
|
+
lastActivityAt: manifest.lastActivityAt,
|
|
1810
|
+
...(activity === undefined ? {} : { activity })
|
|
1811
|
+
});
|
|
1812
|
+
}
|
|
1813
|
+
function templateSummary(conversation, draft) {
|
|
1814
|
+
return conversationTemplateSummarySchema.parse({
|
|
1815
|
+
id: conversation.templateId,
|
|
1816
|
+
nodeId: conversation.nodeId,
|
|
1817
|
+
name: conversation.templateName,
|
|
1818
|
+
description: draft.description,
|
|
1819
|
+
status: conversation.templateDeleted ? 'DELETED' : 'ACTIVE',
|
|
1820
|
+
currentVersionId: conversation.activeVersionId,
|
|
1821
|
+
available: !conversation.templateDeleted,
|
|
1822
|
+
createdAt: conversation.createdAt,
|
|
1823
|
+
updatedAt: draft.updatedAt
|
|
1824
|
+
});
|
|
1825
|
+
}
|
|
1826
|
+
function modelSummary(model, index) {
|
|
1827
|
+
return {
|
|
1828
|
+
id: model.id,
|
|
1829
|
+
name: model.name,
|
|
1830
|
+
protocol: model.protocol,
|
|
1831
|
+
baseUrl: model.baseUrl,
|
|
1832
|
+
modelId: model.modelId,
|
|
1833
|
+
contextWindowTokens: model.contextWindowTokens,
|
|
1834
|
+
maxOutputTokens: model.maxOutputTokens,
|
|
1835
|
+
inputCapabilities: model.inputCapabilities,
|
|
1836
|
+
outputCapabilities: model.outputCapabilities,
|
|
1837
|
+
reasoningEfforts: model.reasoningEfforts,
|
|
1838
|
+
defaultReasoningEffort: resolveMarAgentDefaultReasoningEffort(model.defaultReasoningEffort, model.reasoningEfforts),
|
|
1839
|
+
titleGeneration: model.titleGeneration,
|
|
1840
|
+
codeMode: model.codeMode,
|
|
1841
|
+
hostedWebSearch: model.hostedWebSearch,
|
|
1842
|
+
...(model.responsesTransport === undefined
|
|
1843
|
+
? {}
|
|
1844
|
+
: { responsesTransport: model.responsesTransport }),
|
|
1845
|
+
responsesPreviousResponseId: model.responsesPreviousResponseId,
|
|
1846
|
+
enabled: model.enabled,
|
|
1847
|
+
sortOrder: index,
|
|
1848
|
+
apiKeyConfigured: true
|
|
1849
|
+
};
|
|
1850
|
+
}
|
|
1851
|
+
function systemInstruction(version, generatedImagesDisplayDirectory) {
|
|
1852
|
+
const draft = version.draft;
|
|
1853
|
+
const network = draft.networkMode === 'NONE'
|
|
1854
|
+
? 'Network access is disabled. Local processes, Web Search, Web Fetch, model-hosted web, and remote HTTP MCP cannot use the network.'
|
|
1855
|
+
: 'Local processes, Node-local Web Fetch, available Web Search, model-hosted web, and published remote HTTP MCP may access networks reachable from this Node.';
|
|
1856
|
+
return [
|
|
1857
|
+
'This is a Node-hosted conversation. The Host-declared mounts are the complete file boundary.',
|
|
1858
|
+
'The Host enforces this file boundary, and local processes run inside an operating-system sandbox.',
|
|
1859
|
+
'The published workspace root is read-only. Within /workspace, only /workspace/inbox and /workspace/output are writable.',
|
|
1860
|
+
'The published workspace is an immutable administrator-maintained template snapshot. Changes to the reusable template must be made in its source Workspace and published as a new version.',
|
|
1861
|
+
'Do not describe edits under /workspace/inbox or /workspace/output as changes to the reusable template.',
|
|
1862
|
+
'At the start of each run, read /workspace/inbox/AGENTS.md if it exists. It stores conversation-specific requirements for later runs and is not part of the published template.',
|
|
1863
|
+
'When the user explicitly asks you to remember a requirement, preference, convention, workflow rule, or other guidance for later work in this conversation, create or update /workspace/inbox/AGENTS.md.',
|
|
1864
|
+
'Read its existing contents first and preserve unrelated instructions. Do not persist a preference merely because it appears in the current request unless the user asks you to remember it.',
|
|
1865
|
+
"Follow saved conversation instructions subject to the Host's security boundaries, the published template instructions, and the user's current explicit request.",
|
|
1866
|
+
'Store disposable intermediate work in /tmp. It is reused across runs in this conversation, but the Host may clear it according to the system temporary-directory lifecycle.',
|
|
1867
|
+
'Each new sandbox process has a temporary HOME at /home/mar, apart from explicitly mounted directories. Do not rely on HOME files or shell state persisting between tool executions. Use /tmp for reusable intermediate files and set required environment variables in each command.',
|
|
1868
|
+
'Place final deliverables in appropriate paths under /workspace/output so they become user-visible outputs.',
|
|
1869
|
+
'When reporting an output file to the user, use a Markdown link in the exact form [relative/path](/workspace/output/relative/path) so the user can open its controlled preview or download.',
|
|
1870
|
+
...(generatedImagesDisplayDirectory === undefined
|
|
1871
|
+
? []
|
|
1872
|
+
: [
|
|
1873
|
+
`Generated images from this conversation remain available across executions in the read-only ${generatedImagesDisplayDirectory} directory.`,
|
|
1874
|
+
`When the user asks to place a previously generated image in output, inspect ${generatedImagesDisplayDirectory} and copy the existing file from ${generatedImagesDisplayDirectory} to /workspace/output when available. If it is missing, report that fact; regenerate only when requested or authorized by the user.`
|
|
1875
|
+
]),
|
|
1876
|
+
...(version.sourceWorkspacePath === undefined
|
|
1877
|
+
? []
|
|
1878
|
+
: [
|
|
1879
|
+
`The published workspace is also mounted read-only at ${version.sourceWorkspacePath} as a compatibility alias; it is the same immutable snapshot, not the live source Workspace. ${join(version.sourceWorkspacePath, 'inbox')} and ${join(version.sourceWorkspacePath, 'output')} are aliases of the same writable overlays.`
|
|
1880
|
+
]),
|
|
1881
|
+
'Read user uploads from /workspace/inbox.',
|
|
1882
|
+
network
|
|
1883
|
+
].join('\n');
|
|
1884
|
+
}
|
|
1885
|
+
function attachmentPrompt(prompt, attachments) {
|
|
1886
|
+
if (attachments.length === 0)
|
|
1887
|
+
return prompt;
|
|
1888
|
+
const suffix = attachments.map((file) => `- /workspace/inbox/${file.relativePath}`).join('\n');
|
|
1889
|
+
return `${prompt}${prompt.trim().length === 0 ? '' : '\n\n'}Attachments:\n${suffix}`;
|
|
1890
|
+
}
|
|
1891
|
+
function automaticHostedConversationTitle(value) {
|
|
1892
|
+
if (value === undefined)
|
|
1893
|
+
return undefined;
|
|
1894
|
+
const title = sessionTitleFromFirstMessage(value);
|
|
1895
|
+
if (title.length === 0 ||
|
|
1896
|
+
/^(?:new|untitled) session(?:\s*[-–—:]\s*\d{4}-\d{2}-\d{2}.*)?$/iu.test(title))
|
|
1897
|
+
return undefined;
|
|
1898
|
+
return title;
|
|
1899
|
+
}
|
|
1900
|
+
function terminalHostedTurnStatus(status) {
|
|
1901
|
+
return (status === 'SUCCEEDED' ||
|
|
1902
|
+
status === 'FAILED' ||
|
|
1903
|
+
status === 'CANCELLED' ||
|
|
1904
|
+
status === 'INTERRUPTED' ||
|
|
1905
|
+
status === 'LOST');
|
|
1906
|
+
}
|
|
1907
|
+
function runFromMessage(record) {
|
|
1908
|
+
return {
|
|
1909
|
+
id: record.runId,
|
|
1910
|
+
status: record.status,
|
|
1911
|
+
startedAt: record.createdAt,
|
|
1912
|
+
completedAt: record.status === 'RUNNING' ? null : record.updatedAt
|
|
1913
|
+
};
|
|
1914
|
+
}
|
|
1915
|
+
function runInterruptionKey(conversationId, runId) {
|
|
1916
|
+
return `${conversationId}\0${runId}`;
|
|
1917
|
+
}
|
|
1918
|
+
function uploadProjection(upload) {
|
|
1919
|
+
return {
|
|
1920
|
+
uploadId: upload.uploadId,
|
|
1921
|
+
conversationId: upload.conversationId,
|
|
1922
|
+
name: upload.name,
|
|
1923
|
+
mimeType: upload.mimeType,
|
|
1924
|
+
receivedBytes: upload.receivedBytes,
|
|
1925
|
+
size: upload.size,
|
|
1926
|
+
status: upload.status,
|
|
1927
|
+
...(upload.file === undefined ? {} : { file: upload.file })
|
|
1928
|
+
};
|
|
1929
|
+
}
|
|
1930
|
+
async function assertRegularFile(path, expectedSize) {
|
|
1931
|
+
const metadata = await regularFileMetadata(path);
|
|
1932
|
+
if (metadata.size !== expectedSize)
|
|
1933
|
+
throw new Error('HOSTED_CONVERSATION_FILE_INVALID');
|
|
1934
|
+
}
|
|
1935
|
+
async function openRegularFile(path) {
|
|
1936
|
+
return open(path, constants.O_RDONLY | constants.O_NOFOLLOW).catch(() => {
|
|
1937
|
+
throw new Error('HOSTED_CONVERSATION_FILE_INVALID');
|
|
1938
|
+
});
|
|
1939
|
+
}
|
|
1940
|
+
async function regularFileMetadata(path) {
|
|
1941
|
+
const metadata = await lstat(path).catch(() => {
|
|
1942
|
+
throw new Error('HOSTED_CONVERSATION_FILE_INVALID');
|
|
1943
|
+
});
|
|
1944
|
+
assertRegularFileMetadata(metadata);
|
|
1945
|
+
return metadata;
|
|
1946
|
+
}
|
|
1947
|
+
function assertRegularFileMetadata(metadata) {
|
|
1948
|
+
if (!metadata.isFile() ||
|
|
1949
|
+
metadata.isSymbolicLink() ||
|
|
1950
|
+
metadata.nlink !== 1 ||
|
|
1951
|
+
!Number.isSafeInteger(metadata.size) ||
|
|
1952
|
+
metadata.size < 0)
|
|
1953
|
+
throw new Error('HOSTED_CONVERSATION_FILE_INVALID');
|
|
1954
|
+
}
|
|
1955
|
+
function sameFileIdentity(left, right) {
|
|
1956
|
+
return left.dev === right.dev && left.ino === right.ino;
|
|
1957
|
+
}
|
|
1958
|
+
function sameFileSnapshot(left, right) {
|
|
1959
|
+
return (sameFileIdentity(left, right) &&
|
|
1960
|
+
left.nlink === right.nlink &&
|
|
1961
|
+
left.size === right.size &&
|
|
1962
|
+
left.mtimeMs === right.mtimeMs &&
|
|
1963
|
+
left.ctimeMs === right.ctimeMs);
|
|
1964
|
+
}
|
|
1965
|
+
function safeFileTimestamp(value) {
|
|
1966
|
+
if (!Number.isFinite(value) || value < 0)
|
|
1967
|
+
return 0;
|
|
1968
|
+
return Math.min(Number.MAX_SAFE_INTEGER, Math.trunc(value));
|
|
1969
|
+
}
|
|
1970
|
+
async function assertUploadTemporaryFile(path, expectedSize) {
|
|
1971
|
+
const metadata = await lstat(path).catch(() => {
|
|
1972
|
+
throw new Error('HOSTED_CONVERSATION_UPLOAD_STATE_INVALID');
|
|
1973
|
+
});
|
|
1974
|
+
if (!metadata.isFile() ||
|
|
1975
|
+
metadata.isSymbolicLink() ||
|
|
1976
|
+
metadata.nlink !== 1 ||
|
|
1977
|
+
metadata.size !== expectedSize)
|
|
1978
|
+
throw new Error('HOSTED_CONVERSATION_UPLOAD_STATE_INVALID');
|
|
1979
|
+
}
|
|
1980
|
+
function record(value) {
|
|
1981
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
1982
|
+
}
|