Repository navigation
Expand file tree
/
Copy pathport.ts
More file actions
238 lines (207 loc) · 7.46 KB
/
Copy pathport.ts
File metadata and controls
238 lines (207 loc) · 7.46 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
// ── Permission types ──────────────────────────────────────────────────────────
export type SessionPermissionRule = {
permission: string
pattern: string
action: 'allow' | 'deny' | 'ask'
}
// ── Session param types ──────────────────────────────────────────────────────
export type SessionCreateParams = {
title?: string
directory?: string
workspaceID?: string
workspace?: string
permission?: SessionPermissionRule[]
}
export type SessionGetParams = {
sessionID: string
directory?: string
}
export type SessionUpdateParams = {
sessionID: string
directory?: string
title?: string
permission?: SessionPermissionRule[]
}
export type SessionMessagesParams = {
sessionID: string
directory?: string
limit?: number
}
export type SessionStatusParams = {
directory?: string
}
export type SessionPromptAsyncParams = {
sessionID: string
directory?: string
workspace?: string
parts?: SessionMessagePart[]
agent?: string
model?: { providerID: string; modelID: string }
variant?: string
}
export type SessionAbortParams = {
sessionID: string
directory?: string
}
export type SessionDeleteParams = {
sessionID: string
directory?: string
}
// ── Session result types ─────────────────────────────────────────────────────
export type Session = {
id: string
slug: string
projectID: string
directory: string
title: string
version: string
time: { created: number; updated: number }
parentID?: string
workspaceID?: string
permission?: SessionPermissionRule[]
}
export type SessionStatus = Record<string, {
type: 'idle' | 'busy' | 'retry'
attempt?: number
message?: string
next?: number
[key: string]: unknown
}>
// ── Session message types ────────────────────────────────────────────────────
export type SessionMessagePart = {
id?: string
messageID?: string
sessionID?: string
type: string
text?: string
synthetic?: boolean
tool?: string
callID?: string
state?: Record<string, unknown>
}
export type SessionMessageInfo = {
id?: string
role: string
agent?: string
sessionID?: string
time: { created: number; completed?: number }
finish?: string
cost?: number
tokens?: { input: number; output: number; reasoning: number; cache: { read: number; write: number } }
providerID?: string
modelID?: string
error?: { name?: string; data?: { message?: string; statusCode?: number } }
}
export type SessionMessage = {
info: SessionMessageInfo
parts: SessionMessagePart[]
}
export type SessionMessages = SessionMessage[]
// ── Workspace param types ────────────────────────────────────────────────────
export type WorkspaceCreateParams = {
type?: string
branch?: string | null
extra?: Record<string, unknown> | null
}
export type WorkspaceListParams = {
directory?: string
}
export type WorkspaceRemoveParams = {
id: string
}
export type WorkspaceWarpParams = {
id: string
sessionID: string
copyChanges?: boolean
}
// ── Workspace result types ───────────────────────────────────────────────────
export type WorkspaceInfo = {
id: string
type?: string | null
name?: string
branch?: string | null
directory?: string | null
extra?: Record<string, unknown> | null
projectID?: string
}
export type WorkspaceCreateResult = WorkspaceInfo & { timeUsed?: number | string }
export type WorkspaceList = WorkspaceInfo[]
// ── Provider result types ──────────────────────────────────────────────────
export type ProviderModelInfo = {
id: string
name: string
release_date?: string
capabilities?: {
temperature?: boolean
toolcall?: boolean
reasoning?: boolean
attachment?: boolean
}
cost?: { input?: number; output?: number }
variants?: Record<string, { disabled?: boolean; [key: string]: unknown }>
}
export type ProviderListEntry = {
id: string
name: string
models: Record<string, ProviderModelInfo>
}
export type ProviderList = {
all: ProviderListEntry[]
connected: string[]
default: Record<string, string>
}
// ── Toast types ────────────────────────────────────────────────────────────
export type ToastInput = {
directory: string
title?: string
message: string
variant?: 'info' | 'success' | 'warning' | 'error'
duration?: number
}
// ── Event types ────────────────────────────────────────────────────────────
export type ForgeEvent = {
type: string
properties: Record<string, unknown>
}
// ── Error model ──────────────────────────────────────────────────────────────
export type ForgeClientErrorKind = 'connection' | 'not-found' | 'unavailable' | 'request'
export class ForgeClientError extends Error {
readonly kind: ForgeClientErrorKind
readonly method: string
override readonly cause?: unknown
/** SDK error code, propagated from `cause.code` when available (e.g. `"concurrent_prompt"`). */
readonly code?: string
constructor(args: { kind: ForgeClientErrorKind; method: string; message: string; cause?: unknown }) {
super(args.message)
this.name = 'ForgeClientError'
this.kind = args.kind
this.method = args.method
this.cause = args.cause
// Propagate SDK error code through so callers can detect specific error
// codes (e.g. 'concurrent_prompt') on a port-level error.
this.code = (args.cause && typeof args.cause === 'object' && 'code' in (args.cause as Record<string, unknown>))
? (args.cause as { code: string }).code
: undefined
}
}
// ── Port interface ───────────────────────────────────────────────────────────
export interface ForgeClient {
session: {
create(params: SessionCreateParams): Promise<Session>
get(params: SessionGetParams): Promise<Session>
update(params: SessionUpdateParams): Promise<void>
messages(params: SessionMessagesParams): Promise<SessionMessages>
status(params?: SessionStatusParams): Promise<SessionStatus>
promptAsync(params: SessionPromptAsyncParams): Promise<void>
abort(params: SessionAbortParams): Promise<void>
delete(params: SessionDeleteParams): Promise<void>
}
workspace: {
create(params: WorkspaceCreateParams): Promise<WorkspaceCreateResult>
list(params?: WorkspaceListParams): Promise<WorkspaceList>
remove(params: WorkspaceRemoveParams): Promise<void>
warp(params: WorkspaceWarpParams): Promise<void>
}
/** Emits a toast notification to the host TUI. */
toast(input: ToastInput): Promise<void>
}