xyne-sdk 1.0.2

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/package.json ADDED
@@ -0,0 +1,25 @@
1
+ {
2
+ "name": "xyne-sdk",
3
+ "version": "1.0.2",
4
+ "description": "TypeScript types for the Xyne AI coding agent SDK — sessions, messages, parts, events, and client interface",
5
+ "type": "module",
6
+ "exports": {
7
+ ".": "./src/index.ts"
8
+ },
9
+ "files": [
10
+ "src"
11
+ ],
12
+ "keywords": [
13
+ "xyne",
14
+ "sdk",
15
+ "ai",
16
+ "agent",
17
+ "coding"
18
+ ],
19
+ "license": "MIT",
20
+ "repository": {
21
+ "type": "git",
22
+ "url": "https://github.com/xynehq/xyne.git",
23
+ "directory": "npm/xyne-sdk"
24
+ }
25
+ }
package/src/client.ts ADDED
@@ -0,0 +1,81 @@
1
+ import type {
2
+ Session,
3
+ Message,
4
+ Part,
5
+ TodoItem,
6
+ ModelInfo,
7
+ AgentInfo,
8
+ ToolInfo,
9
+ AuthEntry,
10
+ SendOptions,
11
+ PermissionRequest,
12
+ PermissionReply,
13
+ QuestionRequest,
14
+ } from "./types"
15
+ import type { ClientEvent, Unsubscribe } from "./events"
16
+
17
+ export interface Client {
18
+ session: {
19
+ create(opts?: { id?: string; title?: string }): Promise<Session>
20
+ get(id: string): Promise<Session | undefined>
21
+ list(): Promise<Session[]>
22
+ delete(id: string): Promise<void>
23
+ update(id: string, patch: { title?: string }): Promise<Session>
24
+ send(opts: SendOptions): Promise<Message>
25
+ cancel(sessionID: string): Promise<string[] | null>
26
+ isBusy(sessionID: string): boolean
27
+ compact(sessionID: string): Promise<boolean>
28
+ }
29
+
30
+ message: {
31
+ list(sessionID: string): Promise<Message[]>
32
+ get(id: string): Promise<Message | undefined>
33
+ delete(id: string): Promise<void>
34
+ }
35
+
36
+ part: {
37
+ list(messageID: string): Promise<Part[]>
38
+ listBatch(messageIDs: string[]): Promise<Map<string, Part[]>>
39
+ }
40
+
41
+ todo: {
42
+ list(sessionID: string): Promise<TodoItem[]>
43
+ set(sessionID: string, todos: TodoItem[]): Promise<void>
44
+ }
45
+
46
+ tool: {
47
+ list(): ToolInfo[]
48
+ /** Invalidate the tool cache — call when MCP tools change. */
49
+ invalidate(): void
50
+ }
51
+
52
+ model: {
53
+ list(): Promise<ModelInfo[]>
54
+ get(providerID: string, modelID: string): ModelInfo | undefined
55
+ }
56
+
57
+ agent: {
58
+ list(): AgentInfo[]
59
+ get(name: string): AgentInfo | undefined
60
+ }
61
+
62
+ permission: {
63
+ list(): PermissionRequest[]
64
+ reply(requestID: string, sessionID: string, reply: PermissionReply): void
65
+ }
66
+
67
+ question: {
68
+ list(): QuestionRequest[]
69
+ reply(requestID: string, sessionID: string, answers: string[][]): void
70
+ reject(requestID: string, sessionID: string): void
71
+ }
72
+
73
+ auth: {
74
+ get(providerID: string): Promise<AuthEntry | undefined>
75
+ set(providerID: string, entry: AuthEntry): Promise<void>
76
+ remove(providerID: string): Promise<void>
77
+ list(): Promise<Record<string, AuthEntry>>
78
+ }
79
+
80
+ subscribe(callback: (event: ClientEvent) => void): Unsubscribe
81
+ }
package/src/events.ts ADDED
@@ -0,0 +1,29 @@
1
+ import type {
2
+ Session,
3
+ Message,
4
+ Part,
5
+ PartDelta,
6
+ PermissionRequest,
7
+ QuestionRequest,
8
+ FileChange,
9
+ } from "./types"
10
+
11
+ export type SessionStatus =
12
+ | { type: "idle" }
13
+ | { type: "busy" }
14
+ | { type: "retry"; attempt: number; message: string; next: number }
15
+
16
+ export type ClientEvent =
17
+ | { type: "session.status"; sessionID: string; status: SessionStatus }
18
+ | { type: "session.updated"; session: Session }
19
+ | { type: "session.compacted"; sessionID: string }
20
+ | { type: "message.created"; message: Message }
21
+ | { type: "message.updated"; message: Message }
22
+ | { type: "part.created"; part: Part }
23
+ | { type: "part.updated"; part: Part }
24
+ | { type: "part.delta"; delta: PartDelta }
25
+ | { type: "permission.asked"; request: PermissionRequest }
26
+ | { type: "question.asked"; request: QuestionRequest }
27
+ | { type: "file.changed"; change: FileChange }
28
+
29
+ export type Unsubscribe = () => void
package/src/index.ts ADDED
@@ -0,0 +1,56 @@
1
+ /**
2
+ * xyne-sdk — TypeScript types for the Xyne AI coding agent.
3
+ *
4
+ * This package provides type definitions for sessions, messages, parts,
5
+ * events, and the client interface. It has zero runtime dependencies —
6
+ * all exports are TypeScript types.
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * import type { Client, Session, Message, Part } from "xyne-sdk"
11
+ * ```
12
+ */
13
+
14
+ // SDK types
15
+ export type {
16
+ Session,
17
+ TokenUsage,
18
+ MessageError,
19
+ Message,
20
+ TextPart,
21
+ ReasoningPart,
22
+ ToolState,
23
+ ToolPart,
24
+ StepStartPart,
25
+ StepFinishPart,
26
+ RetryPart,
27
+ CompactionPart,
28
+ SubtaskPart,
29
+ PatchPart,
30
+ MediaPart,
31
+ AgentPart,
32
+ Part,
33
+ PartDelta,
34
+ ModelInfo,
35
+ CredentialSource,
36
+ AgentInfo,
37
+ ToolInfo,
38
+ TodoItem,
39
+ PermissionRequest,
40
+ PermissionReply,
41
+ QuestionOption,
42
+ QuestionInfo,
43
+ QuestionRequest,
44
+ SendOptions,
45
+ SendAttachment,
46
+ ImageAttachment,
47
+ FilePathAttachment,
48
+ FileChange,
49
+ AuthEntry,
50
+ } from "./types"
51
+
52
+ // Events
53
+ export type { SessionStatus, ClientEvent, Unsubscribe } from "./events"
54
+
55
+ // Client interface
56
+ export type { Client } from "./client"
package/src/types.ts ADDED
@@ -0,0 +1,298 @@
1
+ // Xyne SDK types — plain serializable objects, no runtime dependencies
2
+
3
+ // ─── Session ────────────────────────────────────────────────────────
4
+
5
+ export interface Session {
6
+ id: string
7
+ created: number
8
+ updated: number
9
+ title?: string
10
+ parentID?: string
11
+ directory: string
12
+ }
13
+
14
+ // ─── Message ────────────────────────────────────────────────────────
15
+
16
+ export interface TokenUsage {
17
+ input: number
18
+ output: number
19
+ cacheRead: number
20
+ cacheWrite: number
21
+ reasoning: number
22
+ }
23
+
24
+ export type MessageError =
25
+ | { name: "AuthError"; providerID: string; message: string }
26
+ | { name: "APIError"; message: string; statusCode?: number; isRetryable: boolean }
27
+ | { name: "ContextOverflowError"; message: string }
28
+ | { name: "AbortedError"; message: string }
29
+ | { name: "OutputLengthError" }
30
+ | { name: "StructuredOutputError"; message: string; retries: number }
31
+ | { name: "Unknown"; message: string }
32
+
33
+ export interface Message {
34
+ id: string
35
+ sessionID: string
36
+ role: "user" | "assistant"
37
+ created: number
38
+ completed?: number
39
+ parentID?: string
40
+ agentID?: string
41
+ modelID?: string
42
+ providerID?: string
43
+ path?: { cwd: string; root: string }
44
+ finish?: string
45
+ error?: MessageError
46
+ cost?: number
47
+ tokens?: TokenUsage
48
+ summary?: string
49
+ }
50
+
51
+ // ─── Parts ──────────────────────────────────────────────────────────
52
+
53
+ interface BasePart {
54
+ id: string
55
+ messageID: string
56
+ sessionID: string
57
+ }
58
+
59
+ export interface TextPart extends BasePart {
60
+ type: "text"
61
+ text: string
62
+ startTime: number
63
+ endTime?: number
64
+ synthetic?: boolean
65
+ }
66
+
67
+ export interface ReasoningPart extends BasePart {
68
+ type: "reasoning"
69
+ text: string
70
+ startTime: number
71
+ endTime?: number
72
+ }
73
+
74
+ export type ToolState =
75
+ | { status: "pending" }
76
+ | {
77
+ status: "running"
78
+ input: unknown
79
+ startTime: number
80
+ title?: string
81
+ metadata?: unknown
82
+ }
83
+ | {
84
+ status: "completed"
85
+ input: unknown
86
+ output: string
87
+ title: string
88
+ metadata: unknown
89
+ startTime: number
90
+ endTime: number
91
+ }
92
+ | {
93
+ status: "error"
94
+ input: unknown
95
+ error: string
96
+ startTime: number
97
+ endTime: number
98
+ }
99
+
100
+ export interface ToolPart extends BasePart {
101
+ type: "tool"
102
+ callID: string
103
+ tool: string
104
+ state: ToolState
105
+ }
106
+
107
+ export interface StepStartPart extends BasePart {
108
+ type: "step-start"
109
+ }
110
+
111
+ export interface StepFinishPart extends BasePart {
112
+ type: "step-finish"
113
+ reason: string
114
+ tokens?: TokenUsage
115
+ cost?: number
116
+ }
117
+
118
+ export interface RetryPart extends BasePart {
119
+ type: "retry"
120
+ attempt: number
121
+ error: MessageError
122
+ time: { created: number }
123
+ }
124
+
125
+ export interface CompactionPart extends BasePart {
126
+ type: "compaction"
127
+ auto: boolean
128
+ overflow?: boolean
129
+ }
130
+
131
+ export interface SubtaskPart extends BasePart {
132
+ type: "subtask"
133
+ prompt: string
134
+ description: string
135
+ agent: string
136
+ model?: { providerID: string; modelID: string }
137
+ command?: string
138
+ }
139
+
140
+ export interface PatchPart extends BasePart {
141
+ type: "patch"
142
+ hash: string
143
+ files: string[]
144
+ }
145
+
146
+ export interface MediaPart extends BasePart {
147
+ type: "media"
148
+ mime: string
149
+ filename?: string
150
+ url: string
151
+ }
152
+
153
+ export interface AgentPart extends BasePart {
154
+ type: "agent"
155
+ name: string
156
+ }
157
+
158
+ export type Part =
159
+ | TextPart
160
+ | ReasoningPart
161
+ | ToolPart
162
+ | StepStartPart
163
+ | StepFinishPart
164
+ | RetryPart
165
+ | CompactionPart
166
+ | SubtaskPart
167
+ | PatchPart
168
+ | MediaPart
169
+ | AgentPart
170
+
171
+ // ─── Part Delta (streaming) ─────────────────────────────────────────
172
+
173
+ export interface PartDelta {
174
+ sessionID: string
175
+ messageID: string
176
+ partID: string
177
+ field: "text" | "reasoning"
178
+ delta: string
179
+ }
180
+
181
+ // ─── Model ──────────────────────────────────────────────────────────
182
+
183
+ /** How a provider's API key was resolved. */
184
+ export type CredentialSource = "config" | "env" | "auth"
185
+
186
+ export interface ModelInfo {
187
+ providerID: string
188
+ modelID: string
189
+ name: string
190
+ contextLength: number
191
+ maxOutputTokens: number
192
+ supportsVision?: boolean
193
+ supportsReasoning?: boolean
194
+ hasCredential: boolean
195
+ credentialSource?: CredentialSource
196
+ }
197
+
198
+ // ─── Agent ──────────────────────────────────────────────────────────
199
+
200
+ export interface AgentInfo {
201
+ name: string
202
+ description?: string
203
+ mode: "primary" | "subagent" | "all"
204
+ color?: string
205
+ hidden?: boolean
206
+ native?: boolean
207
+ }
208
+
209
+ // ─── Tool ───────────────────────────────────────────────────────────
210
+
211
+ export interface ToolInfo {
212
+ id: string
213
+ description: string
214
+ }
215
+
216
+ // ─── Todo ───────────────────────────────────────────────────────────
217
+
218
+ export interface TodoItem {
219
+ id: string
220
+ subject: string
221
+ description?: string
222
+ status: "pending" | "in_progress" | "completed" | "cancelled"
223
+ priority?: "low" | "medium" | "high"
224
+ }
225
+
226
+ // ─── Permission ─────────────────────────────────────────────────────
227
+
228
+ export interface PermissionRequest {
229
+ id: string
230
+ sessionID: string
231
+ permission: string
232
+ patterns: string[]
233
+ metadata: Record<string, unknown>
234
+ always: string[]
235
+ tool?: { messageID: string; callID: string }
236
+ }
237
+
238
+ export type PermissionReply = "once" | "always" | "reject"
239
+
240
+ // ─── Question ───────────────────────────────────────────────────────
241
+
242
+ export interface QuestionOption {
243
+ label: string
244
+ description: string
245
+ }
246
+
247
+ export interface QuestionInfo {
248
+ question: string
249
+ header: string
250
+ options: QuestionOption[]
251
+ multiple?: boolean
252
+ }
253
+
254
+ export interface QuestionRequest {
255
+ id: string
256
+ sessionID: string
257
+ questions: QuestionInfo[]
258
+ tool?: { messageID: string; callID: string }
259
+ }
260
+
261
+ // ─── Auth ──────────────────────────────────────────────────────────
262
+
263
+ export type AuthEntry =
264
+ | { type: "api"; key: string }
265
+ | { type: "oauth"; access: string; refresh: string; expires: number }
266
+
267
+ // ─── Send Options ───────────────────────────────────────────────────
268
+
269
+ export interface ImageAttachment {
270
+ type: "image"
271
+ data: string // base64
272
+ mime: string
273
+ }
274
+
275
+ export interface FilePathAttachment {
276
+ type: "file-path"
277
+ path: string // absolute filesystem path
278
+ filename: string
279
+ }
280
+
281
+ export type SendAttachment = ImageAttachment | FilePathAttachment
282
+
283
+ export interface SendOptions {
284
+ sessionID: string
285
+ text: string
286
+ attachments?: SendAttachment[]
287
+ model?: { providerID: string; modelID: string }
288
+ agentID?: string
289
+ abort?: AbortSignal
290
+ }
291
+
292
+ // ─── File Change ────────────────────────────────────────────────────
293
+
294
+ export interface FileChange {
295
+ sessionID: string
296
+ type: "create" | "update"
297
+ path: string
298
+ }