-
Notifications
You must be signed in to change notification settings - Fork 561
Expand file tree
/
Copy pathgatewayAdapters.ts
More file actions
71 lines (66 loc) · 3.06 KB
/
Copy pathgatewayAdapters.ts
File metadata and controls
71 lines (66 loc) · 3.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import type { SessionDirectory } from '@/modules/sessionDirectory'
import type { SessionDirectoryChanges } from '@/modules/sessionDirectoryChanges'
import type { SessionLifecycle } from '@/modules/sessionLifecycle'
import type { SessionRouting } from '@/modules/sessionRouting'
import type { TurnCommands } from '@/modules/turnCommands'
import type { PendingInputQueuePort } from '@/modules/pendingInputQueue'
import { createPrivateGatewayTransports } from './privateTransports'
import { createV4SessionDirectory } from './sessionDirectoryV4'
import { createV4SessionDirectoryChanges } from './sessionDirectoryChangesV4'
import { createV4SessionLifecycle } from './sessionLifecycleV4'
import { createV4SessionRouting } from './sessionRoutingV4'
import { createV4TurnCommands } from './turnCommandsV4'
import { createV4PendingInputQueue } from './pendingInputQueueV4'
import { createApprovalCenterV4 } from './approvalCenterV4'
import type { ApprovalCenter } from '@/modules/approvalCenter'
import type { HttpRequestOptions } from './privateHttpTransport'
import type { GoalCenter } from '@/modules/goalCenter'
import { createV4GoalCenter } from './goalCenterV4'
import type { WorkspaceFiles } from '@/modules/workspaceFiles'
import { createWorkspaceFiles } from './workspaceFiles'
type RpcStoreTransportSource = Parameters<typeof createPrivateGatewayTransports>[0]
export interface GatewayAdapters {
readonly sessionDirectory: SessionDirectory
readonly sessionDirectoryChanges: SessionDirectoryChanges
readonly sessionLifecycle: SessionLifecycle
readonly sessionRouting: SessionRouting
readonly turnCommands: TurnCommands
readonly pendingInputQueue: PendingInputQueuePort
readonly approvalCenter: ApprovalCenter
readonly goalCenter: GoalCenter
readonly workspaceFiles: WorkspaceFiles
}
interface GatewayHttpSource {
requestJson<T = unknown>(endpoint: string, options?: HttpRequestOptions): Promise<T>
}
export interface GatewayAdapterOptions {
http?: GatewayHttpSource
}
/** Wire Gateway-backed domain Adapters without leaking generic transports. */
export function createGatewayAdapters(
source: RpcStoreTransportSource,
options: GatewayAdapterOptions = {},
): GatewayAdapters {
const transports = createPrivateGatewayTransports(source)
const http = options.http ?? {
requestJson: async () => {
throw new Error('Gateway HTTP transport is unavailable.')
},
}
const sessionDirectory = createV4SessionDirectory(transports.rpc)
const adapters: GatewayAdapters = {
sessionDirectory,
sessionDirectoryChanges: createV4SessionDirectoryChanges(
transports.rpc,
transports.events,
),
sessionLifecycle: createV4SessionLifecycle(transports.rpc),
sessionRouting: createV4SessionRouting(transports.rpc, transports.events),
turnCommands: createV4TurnCommands(transports.rpc),
pendingInputQueue: createV4PendingInputQueue(transports.rpc),
approvalCenter: createApprovalCenterV4(transports.rpc, transports.events, { http }),
goalCenter: createV4GoalCenter(transports.rpc),
workspaceFiles: createWorkspaceFiles({ http }),
}
return adapters
}