MCPcopy Create free account
hub / github.com/Noumena-Network/code / dispatchReplSandboxAsk

Function dispatchReplSandboxAsk

src/session/replSandboxAskDispatch.ts:24–142  ·  view source on GitHub ↗
(
  hostPattern: NetworkHostPattern,
  state: {
    swarmsEnabled: boolean
    swarmWorker: boolean
    bridgeModeEnabled: boolean
  },
  deps: {
    generateSandboxRequestId: () => string
    sendSandboxPermissionRequestViaMailbox: (
      host: string,
      requestId: string,
    ) => Promise<boolean>
    registerSandboxPermissionCallback: (params: {
      requestId: string
      host: string
      resolve: (allow: boolean) => void
    }) => void
    setSandboxPermissionRequestQueue: (
      update: (
        prev: ReplSandboxPermissionQueueItem[],
      ) => ReplSandboxPermissionQueueItem[],
    ) => void
    setAppState: (
      update: (prev: {
        pendingSandboxRequest?: { requestId: string; host: string } | undefined
      }) => {
        pendingSandboxRequest?: { requestId: string; host: string } | undefined
      },
    ) => void
    getBridgeCallbacks: () => BridgeCallbacks | null | undefined
    generateBridgeRequestId: () => UUID
    sandboxNetworkAccessToolName: string
    dispatchHostDecision: (params: { host: string; allow: boolean }) => void
    sandboxBridgeCleanupMap: Map<string, Array<() => void>>
  },
)

Source from the content-addressed store, hash-verified

22}
23
24export async function dispatchReplSandboxAsk(
25 hostPattern: NetworkHostPattern,
26 state: {
27 swarmsEnabled: boolean
28 swarmWorker: boolean
29 bridgeModeEnabled: boolean
30 },
31 deps: {
32 generateSandboxRequestId: () => string
33 sendSandboxPermissionRequestViaMailbox: (
34 host: string,
35 requestId: string,
36 ) => Promise<boolean>
37 registerSandboxPermissionCallback: (params: {
38 requestId: string
39 host: string
40 resolve: (allow: boolean) => void
41 }) => void
42 setSandboxPermissionRequestQueue: (
43 update: (
44 prev: ReplSandboxPermissionQueueItem[],
45 ) => ReplSandboxPermissionQueueItem[],
46 ) => void
47 setAppState: (
48 update: (prev: {
49 pendingSandboxRequest?: { requestId: string; host: string } | undefined
50 }) => {
51 pendingSandboxRequest?: { requestId: string; host: string } | undefined
52 },
53 ) => void
54 getBridgeCallbacks: () => BridgeCallbacks | null | undefined
55 generateBridgeRequestId: () => UUID
56 sandboxNetworkAccessToolName: string
57 dispatchHostDecision: (params: { host: string; allow: boolean }) => void
58 sandboxBridgeCleanupMap: Map<string, Array<() => void>>
59 },
60): Promise<boolean> {
61 if (state.swarmsEnabled && state.swarmWorker) {
62 const requestId = deps.generateSandboxRequestId()
63 const sent = await deps.sendSandboxPermissionRequestViaMailbox(
64 hostPattern.host,
65 requestId,
66 )
67 return new Promise(resolveShouldAllowHost => {
68 if (!sent) {
69 deps.setSandboxPermissionRequestQueue(prev => [
70 ...prev,
71 {
72 hostPattern,
73 resolvePromise: resolveShouldAllowHost,
74 },
75 ])
76 return
77 }
78
79 deps.registerSandboxPermissionCallback({
80 requestId,
81 host: hostPattern.host,

Callers 2

REPLFunction · 0.85

Calls 4

sendRequestMethod · 0.80
onResponseMethod · 0.80
setMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected