MCPcopy Index your code
hub / github.com/callstack/agent-device / prepareLockedRequestScope

Function prepareLockedRequestScope

src/daemon/request-execution-scope.ts:179–255  ·  view source on GitHub ↗
(params: {
  scope: RequestExecutionScope;
  sessionStore: SessionStore;
  trackDownloadableArtifact: (opts: {
    artifactPath: string;
    tenantId?: string;
    fileName?: string;
  }) => string;
})

Source from the content-addressed store, hash-verified

177}
178
179export function prepareLockedRequestScope(params: {
180 scope: RequestExecutionScope;
181 sessionStore: SessionStore;
182 trackDownloadableArtifact: (opts: {
183 artifactPath: string;
184 tenantId?: string;
185 fileName?: string;
186 }) => string;
187}): LockedRequestScopeResult {
188 const { scope, sessionStore, trackDownloadableArtifact } = params;
189 const logPath = scope.runnerLogPath;
190 scope.throwIfCanceled();
191 let existingSession = sessionStore.get(scope.sessionName);
192 if (existingSession) {
193 // Called under runLocked: refreshRecordingHealth may mutate session recording state.
194 refreshRecordingHealth(existingSession);
195 sessionStore.set(scope.sessionName, existingSession);
196 }
197 const binding = prepareLockedRequestBinding({
198 req: scope.req,
199 sessionName: scope.sessionName,
200 sessionStore,
201 });
202 const lockedReq = binding.req;
203 existingSession = binding.existingSession;
204 const finalize = (response: DaemonResponse): DaemonResponse =>
205 finalizeDaemonResponse(lockedReq, response, trackDownloadableArtifact);
206
207 if (
208 existingSession?.recording?.invalidatedReason &&
209 shouldBlockForInvalidRecording(scope.command)
210 ) {
211 return {
212 type: 'response',
213 response: finalize({
214 ok: false,
215 error: {
216 code: 'COMMAND_FAILED',
217 message: existingSession.recording.invalidatedReason,
218 },
219 }),
220 };
221 }
222
223 if (
224 existingSession &&
225 !lockedReq.meta?.lockPolicy &&
226 shouldValidateSessionSelector(scope.command)
227 ) {
228 assertSessionSelectorMatches(existingSession, lockedReq.flags);
229 }
230
231 const contextFromFlags = (
232 flags: CommandFlags | undefined,
233 appBundleId?: string,
234 traceLogPath?: string,
235 ): DaemonCommandContext =>
236 contextFromRequestFlags(logPath, flags, appBundleId, traceLogPath, lockedReq.meta);

Callers 2

runFunction · 0.90

Calls 9

refreshRecordingHealthFunction · 0.90
contextFromFlagsFunction · 0.90
finalizeFunction · 0.85
getMethod · 0.80
setMethod · 0.80

Tested by

no test coverage detected