@nexum-hub/sdk 0.0.0-stage → 0.0.1

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/README.md CHANGED
@@ -1,3 +1,21 @@
1
- # Temporary Holding Version
1
+ # @nexum-hub/sdk — Nexum 扩展协议类型
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ 此包由 Agent 的 `src/extension-api.ts` 自动生成,包含扩展工厂、调用上下文、资源及公开 SDK 的 TypeScript 类型。类型协议没有运行初始化逻辑,不启动 Agent、不读取配置或凭据,也不提供私有 Core manager。
4
+
5
+ ```ts
6
+ import type { ExtensionFactory } from "@nexum-hub/sdk";
7
+
8
+ export const createExtension: ExtensionFactory = (host) => ({
9
+ methods: {
10
+ hello: {
11
+ description: "返回问候",
12
+ permissions: [],
13
+ inputSchema: { type: "object", additionalProperties: false },
14
+ schemaDialect: "2020-12",
15
+ handle: () => "hello",
16
+ },
17
+ },
18
+ });
19
+ ```
20
+
21
+ 在 Agent 仓库运行 `node scripts/build-extension-api.mjs` 生成本地 `dist`。这是供 Nexum 扩展开发者使用的类型协议包,**不是**通用 AI Host SDK;以 npm Registry 实际状态判断是否已经发布。
@@ -0,0 +1,502 @@
1
+ // Generated by dts-bundle-generator v10.0.0
2
+
3
+ /// <reference types="node" />
4
+
5
+ import { Blob as Blob$1 } from 'node:buffer';
6
+
7
+ export interface AccessTarget {
8
+ type: "path" | "url" | "resource" | "connection" | "agent-state" | "user-state" | "transfer" | "maintenance";
9
+ value: string;
10
+ access: string;
11
+ }
12
+ export interface ContributionOrigin extends JsonObject {
13
+ type: "local" | "platform" | "extension";
14
+ owner: string;
15
+ namespace: string | null;
16
+ version: string | null;
17
+ revision: string;
18
+ }
19
+ export interface ExtensionHost {
20
+ readonly context: Readonly<JsonObject>;
21
+ readonly config: Readonly<JsonObject>;
22
+ readonly signal: AbortSignal;
23
+ readonly resources: ResourceService;
24
+ readonly storage: StorageService;
25
+ /** Current instance authority, independent of any particular run/caller. */
26
+ authorize(target: AccessTarget): void;
27
+ log(entry: LogEntry): void;
28
+ }
29
+ export interface ExtensionInstance {
30
+ methods: Readonly<Record<string, MethodDefinition>>;
31
+ dispose?(): void | Promise<void>;
32
+ }
33
+ export interface HostRequestOptions {
34
+ /** Cancellation of this particular Host request, independent of the whole run. */
35
+ readonly signal?: AbortSignal;
36
+ }
37
+ /** Actual capabilities of the original Host session, never the last connected Host. */
38
+ export interface HostRequestServices {
39
+ readonly capabilities: Readonly<JsonObject>;
40
+ assertCurrent(): void;
41
+ sampling(params: JsonObject, options?: HostRequestOptions): Promise<JsonObject>;
42
+ elicitation(params: JsonObject, options?: HostRequestOptions): Promise<JsonObject>;
43
+ roots(options?: HostRequestOptions): Promise<JsonObject>;
44
+ }
45
+ export interface InputRequest {
46
+ message: string;
47
+ inputSchema: JsonValue;
48
+ timeoutMs?: number;
49
+ }
50
+ export interface Invocation {
51
+ readonly context: Readonly<JsonObject>;
52
+ readonly operationId: string;
53
+ readonly signal: AbortSignal;
54
+ readonly deadline: number;
55
+ readonly resources: ResourceService;
56
+ readonly storage: StorageService;
57
+ readonly output: OutputAPI;
58
+ readonly state: StateService;
59
+ readonly transfer: TransferService;
60
+ readonly maintenance: MaintenanceService;
61
+ /** Available only when the original, currently authorized Host session supports it. */
62
+ readonly hostRequests?: HostRequestServices;
63
+ log(entry: LogEntry): void;
64
+ progress(value: JsonObject): void;
65
+ authorize(target: AccessTarget): void;
66
+ requestInput(request: InputRequest): Promise<JsonObject>;
67
+ }
68
+ export interface LogEntry {
69
+ level: "debug" | "info" | "warn" | "error";
70
+ message: string;
71
+ data?: JsonObject;
72
+ }
73
+ export interface MaintenanceCreated {
74
+ readonly requestId: string;
75
+ readonly status: MaintenanceStatus;
76
+ readonly approvalUrl?: string;
77
+ readonly expiresAt: string;
78
+ }
79
+ export interface MaintenanceListOptions {
80
+ readonly target?: MaintenanceTarget;
81
+ readonly name?: string;
82
+ readonly status?: MaintenanceStatus;
83
+ readonly limit?: number;
84
+ readonly cursor?: string;
85
+ }
86
+ export interface MaintenanceRequestView {
87
+ readonly requestId: string;
88
+ readonly agentId: string;
89
+ readonly profile: Binding["profile"];
90
+ readonly target: MaintenanceTarget;
91
+ readonly action: string;
92
+ readonly name: string;
93
+ readonly status: MaintenanceStatus;
94
+ readonly revision: number;
95
+ readonly candidateRevision: string;
96
+ readonly objectId: string | null;
97
+ readonly baseRevision: string | null;
98
+ readonly summary: MaintenanceSummary;
99
+ readonly authStatus: MaintenanceAuthStatus;
100
+ readonly createdAt: string;
101
+ readonly expiresAt: string;
102
+ readonly approvalUrl?: string;
103
+ readonly agentName?: string;
104
+ readonly source?: {
105
+ readonly name?: string;
106
+ };
107
+ readonly decidedAt?: string;
108
+ readonly decision?: MaintenanceDecision;
109
+ readonly execution?: MaintenanceExecution;
110
+ }
111
+ export interface MaintenanceService {
112
+ readonly packages: {
113
+ install(input: {
114
+ name: string;
115
+ version?: string;
116
+ }): Promise<MaintenanceCreated>;
117
+ update(input: {
118
+ name: string;
119
+ version?: string;
120
+ }): Promise<MaintenanceCreated>;
121
+ remove(input: {
122
+ name: string;
123
+ }): Promise<MaintenanceCreated>;
124
+ };
125
+ readonly extensions: {
126
+ enable(input: {
127
+ name: string;
128
+ }): Promise<MaintenanceCreated>;
129
+ disable(input: {
130
+ name: string;
131
+ }): Promise<MaintenanceCreated>;
132
+ };
133
+ readonly mcp: {
134
+ add(input: {
135
+ name: string;
136
+ config: JsonObject;
137
+ }): Promise<MaintenanceCreated>;
138
+ update(input: {
139
+ name: string;
140
+ config: JsonObject;
141
+ }): Promise<MaintenanceCreated>;
142
+ remove(input: {
143
+ name: string;
144
+ }): Promise<MaintenanceCreated>;
145
+ };
146
+ readonly api: {
147
+ import(input: {
148
+ name: string;
149
+ url?: string;
150
+ path?: string;
151
+ config?: JsonObject;
152
+ }): Promise<MaintenanceCreated>;
153
+ update(input: {
154
+ name: string;
155
+ url?: string;
156
+ path?: string;
157
+ config?: JsonObject;
158
+ }): Promise<MaintenanceCreated>;
159
+ remove(input: {
160
+ name: string;
161
+ }): Promise<MaintenanceCreated>;
162
+ };
163
+ get(requestId: string): Promise<MaintenanceRequestView>;
164
+ list(options?: MaintenanceListOptions): Promise<{
165
+ requests: readonly MaintenanceRequestView[];
166
+ nextCursor: string | null;
167
+ }>;
168
+ cancel(requestId: string): Promise<MaintenanceRequestView>;
169
+ }
170
+ /** Extension-side control objects. Neither these nor ResourceRef cross the script/wire boundary. */
171
+ export interface ManagedResource {
172
+ readonly closed: Promise<void>;
173
+ dispose(reason?: unknown): void | Promise<void>;
174
+ }
175
+ export interface McpReadScope {
176
+ readonly ownerKey: string;
177
+ readonly grantId?: string;
178
+ readonly signal?: AbortSignal;
179
+ assertCurrent(): void;
180
+ authorizeConnection(connection: string, uri?: string, access?: McpAccess): void;
181
+ }
182
+ /** A registered cold connection implements this; it is never a script result. */
183
+ export interface McpResourceReader extends ManagedResource {
184
+ readonly connection: string;
185
+ assertCurrent(): void;
186
+ readResource(uri: string, scope: McpReadScope): Promise<unknown>;
187
+ listResources?(scope: McpReadScope, cursor?: string): Promise<unknown>;
188
+ }
189
+ export interface McpResultOptions {
190
+ readonly connectionResourceId: string;
191
+ readonly connection: string;
192
+ readonly method?: McpMethod;
193
+ }
194
+ export interface MethodDefinition {
195
+ description: string;
196
+ permissions: readonly string[];
197
+ inputSchema: unknown;
198
+ schemaDialect?: SchemaDialect;
199
+ schemas?: readonly unknown[];
200
+ outputSchema?: unknown;
201
+ outputSchemaDialect?: SchemaDialect;
202
+ /** Internal adapter mapping; the source method name is retained separately. */
203
+ path?: readonly string[];
204
+ normalize?(args: readonly unknown[]): unknown;
205
+ handle(input: any, call: Invocation): unknown;
206
+ }
207
+ export interface OutputAPI {
208
+ mcpResult(value: unknown, options: McpResultOptions): JsonObject;
209
+ mcpResourceResult(value: unknown, options: Omit<McpResultOptions, "method">): JsonObject;
210
+ text(value: string, options?: OutputOptions): OutputIntent;
211
+ json(value: unknown): OutputIntent;
212
+ image(source: string | OutputSource, options?: OutputOptions): OutputIntent;
213
+ images(sources: readonly (string | OutputSource)[], options?: OutputOptions): OutputIntent;
214
+ audio(source: string | OutputSource, options?: OutputOptions): OutputIntent;
215
+ resourceLink(source: string | OutputSource, options?: OutputOptions): OutputIntent;
216
+ file(source: string | OutputSource, options?: OutputOptions): OutputIntent;
217
+ embeddedResource(source: string | OutputSource, options?: OutputOptions): OutputIntent;
218
+ resource(source: string | OutputSource, options?: OutputOptions): OutputIntent;
219
+ result(value: OutputResult): OutputIntent;
220
+ error(message: string, options?: {
221
+ content?: readonly unknown[];
222
+ structuredContent?: unknown;
223
+ }): OutputIntent;
224
+ }
225
+ export interface OutputIntent {
226
+ readonly kind: "text" | "json" | "image" | "audio" | "resource_link" | "resource" | "collection" | "result";
227
+ readonly value: unknown;
228
+ readonly options: Readonly<OutputOptions>;
229
+ }
230
+ export interface OutputOptions {
231
+ name?: string;
232
+ description?: string;
233
+ mimeType?: string;
234
+ annotations?: {
235
+ audience?: ("user" | "assistant")[];
236
+ priority?: number;
237
+ lastModified?: string;
238
+ };
239
+ }
240
+ export interface OutputResult {
241
+ content: readonly unknown[];
242
+ structuredContent?: unknown;
243
+ isError?: boolean;
244
+ }
245
+ export interface OutputSource {
246
+ path?: string;
247
+ uri?: string;
248
+ data?: ArrayBufferView | ArrayBuffer | SharedArrayBuffer | Blob$1;
249
+ mimeType?: string;
250
+ name?: string;
251
+ }
252
+ export interface ResourcePage {
253
+ /** Byte/scan budgets may shorten a page; nextCursor preserves the remaining position. */
254
+ readonly items: readonly ResourceSnapshot[];
255
+ readonly nextCursor: string | null;
256
+ }
257
+ export interface ResourceQuery {
258
+ readonly kind?: string;
259
+ readonly status?: string;
260
+ /** Exact reported details.state, independently of physical closure/status. */
261
+ readonly state?: string;
262
+ readonly runId?: string;
263
+ readonly contextId?: string;
264
+ readonly limit?: number;
265
+ readonly cursor?: string;
266
+ }
267
+ export interface ResourceRef<T extends ManagedResource = ManagedResource> {
268
+ readonly id: string;
269
+ readonly kind: string;
270
+ readonly signal: AbortSignal;
271
+ readonly value: T;
272
+ /** Publish bounded resource facts for its actual lifetime; does not change ownership or closure. */
273
+ report(details: JsonObject): void;
274
+ }
275
+ export interface ResourceService {
276
+ register<T extends ManagedResource>(input: {
277
+ kind: string;
278
+ value: T;
279
+ }): Promise<ResourceRef<T>>;
280
+ get<T extends ManagedResource = ManagedResource>(id: string): Promise<ResourceRef<T>>;
281
+ handoff(id: string): Promise<ResourceRecord>;
282
+ /** Call-bound, read-only retained history; never returns a live controller. */
283
+ describe(id: string): Promise<ResourceSnapshot>;
284
+ list(query?: ResourceQuery): Promise<ResourcePage>;
285
+ }
286
+ export interface ResourceSnapshot extends JsonObject {
287
+ readonly id: string;
288
+ readonly kind: string;
289
+ readonly status: string;
290
+ readonly lifetime: ResourceRecord["lifetime"];
291
+ readonly originRunId: string | null;
292
+ readonly contextId: string | null;
293
+ readonly origin: ContributionOrigin;
294
+ readonly createdAt: number;
295
+ readonly closedAt: number | null;
296
+ readonly handedOffAt: number | null;
297
+ readonly details: JsonObject;
298
+ readonly controlAvailable: boolean;
299
+ }
300
+ export interface StateService {
301
+ readonly agent: StateNamespace;
302
+ readonly user: StateNamespace;
303
+ }
304
+ /** Budget ownership only; neither a filesystem handle nor a native-close proof. */
305
+ export interface StorageReservation {
306
+ release(): void;
307
+ }
308
+ export interface StorageService {
309
+ reserve(bytes: number): Promise<StorageReservation>;
310
+ }
311
+ export interface TransferListOptions {
312
+ readonly direction?: "upload" | "download";
313
+ readonly status?: TransferStatus;
314
+ readonly runId?: string;
315
+ readonly limit?: number;
316
+ readonly cursor?: string;
317
+ }
318
+ export interface TransferService {
319
+ createUpload(options: UploadOptions): Promise<UploadOffer>;
320
+ createDownload(options: DownloadOptions): Promise<DownloadOffer>;
321
+ get(transferId: string, options?: {
322
+ readonly waitMs?: number;
323
+ }): Promise<TransferSnapshot>;
324
+ list(options?: TransferListOptions): Promise<{
325
+ readonly transfers: readonly TransferSnapshot[];
326
+ readonly nextCursor: string | null;
327
+ }>;
328
+ cancel(transferId: string): Promise<{
329
+ readonly accepted: boolean;
330
+ readonly transfer: TransferSnapshot;
331
+ }>;
332
+ }
333
+ /** A retained point-in-time view. No request URL or live controller is included. */
334
+ export interface TransferSnapshot {
335
+ readonly transferId: string;
336
+ readonly direction: "upload" | "download";
337
+ readonly status: TransferStatus;
338
+ readonly runId: string | null;
339
+ readonly contextId: string | null;
340
+ readonly projectId: string | null;
341
+ readonly path?: string;
342
+ readonly resource?: TransferResource;
343
+ readonly progress: {
344
+ readonly bytesTransferred: number;
345
+ readonly totalBytes: number | null;
346
+ };
347
+ readonly createdAt: string;
348
+ readonly expiresAt: string | null;
349
+ readonly startedAt: string | null;
350
+ readonly deadlineAt: string | null;
351
+ readonly finishedAt: string | null;
352
+ readonly file?: UploadFileReceipt;
353
+ readonly error: JsonObject | null;
354
+ }
355
+ export interface UploadOptions {
356
+ readonly path: string;
357
+ readonly expectedSize?: number;
358
+ readonly expectedSha256?: string;
359
+ readonly mimeType?: string;
360
+ }
361
+ export type DownloadOffer = TransferSnapshot & TransferOffer & {
362
+ readonly direction: "download";
363
+ readonly status: "pending";
364
+ readonly resource: TransferResource;
365
+ readonly expiresAt: string;
366
+ };
367
+ export type DownloadOptions = ({
368
+ readonly path: string;
369
+ readonly uri?: never;
370
+ } | {
371
+ readonly uri: string;
372
+ readonly path?: never;
373
+ }) & {
374
+ readonly name?: string;
375
+ readonly mimeType?: string;
376
+ };
377
+ export type ExtensionFactory = (host: ExtensionHost) => ExtensionInstance | Promise<ExtensionInstance>;
378
+ export type JsonObject = {
379
+ [key: string]: JsonValue;
380
+ };
381
+ export type JsonValue = null | boolean | number | string | JsonValue[] | {
382
+ [key: string]: JsonValue;
383
+ };
384
+ export type McpAccess = "result" | "resources.read" | "resources.list";
385
+ export type SchemaDialect = "draft7" | "2020-12";
386
+ export type UploadOffer = TransferSnapshot & TransferOffer & {
387
+ readonly direction: "upload";
388
+ readonly status: "pending";
389
+ readonly path: string;
390
+ readonly expiresAt: string;
391
+ readonly maxBytes: number;
392
+ };
393
+ interface ArtifactRecord {
394
+ readonly resourceId: string;
395
+ readonly agentId: string;
396
+ readonly uri: string;
397
+ readonly name: string;
398
+ readonly mimeType: string;
399
+ readonly size: number;
400
+ readonly sha256: string;
401
+ readonly originRunId: string | null;
402
+ readonly createdAt: string;
403
+ readonly expiresAt: string;
404
+ }
405
+ interface Binding {
406
+ readonly agentId: string;
407
+ readonly profile: Profile;
408
+ readonly cloudEnvironment: string;
409
+ }
410
+ interface MaintenanceDecision {
411
+ readonly status: "approved" | "denied";
412
+ readonly revision: number;
413
+ readonly candidateRevision: string;
414
+ readonly decidedAt: string;
415
+ readonly decisionId: string;
416
+ }
417
+ interface MaintenanceExecution {
418
+ readonly operationId: string;
419
+ readonly startedAt: string;
420
+ readonly status?: string;
421
+ readonly result?: JsonObject;
422
+ readonly error?: {
423
+ readonly code: string;
424
+ readonly message: string;
425
+ };
426
+ }
427
+ interface MaintenanceSummary {
428
+ readonly title: string;
429
+ readonly changeKinds: readonly string[];
430
+ readonly permissions: readonly string[];
431
+ readonly version: string | null;
432
+ readonly namespace: string | null;
433
+ readonly restartMayBeRequired: boolean;
434
+ }
435
+ interface ResourceRecord {
436
+ readonly resourceId: string;
437
+ readonly originRunId: string | null;
438
+ readonly ownerRunId: string | null;
439
+ readonly callerKey: string;
440
+ readonly bootId: string;
441
+ readonly kind: string;
442
+ readonly lifetime: "run" | "instance" | "background";
443
+ readonly source: JsonObject;
444
+ readonly status: string;
445
+ readonly revision: number;
446
+ readonly diagnostic: JsonObject;
447
+ readonly createdAt: number;
448
+ readonly handedOffAt: number | null;
449
+ readonly closedAt: number | null;
450
+ }
451
+ interface StateDeletion {
452
+ readonly deleted: true;
453
+ readonly version: number;
454
+ readonly updatedAt: number;
455
+ }
456
+ interface StateNamespace {
457
+ get(key: string): Promise<StateValue | null>;
458
+ set(key: string, value: JsonValue, options: {
459
+ expectedVersion: number | null;
460
+ }): Promise<StateValue>;
461
+ delete(key: string, options: {
462
+ expectedVersion: number;
463
+ }): Promise<StateDeletion>;
464
+ }
465
+ interface StateValue {
466
+ readonly value: JsonValue;
467
+ readonly version: number;
468
+ readonly updatedAt: number;
469
+ }
470
+ interface UploadFileReceipt {
471
+ readonly path: string;
472
+ readonly name: string;
473
+ readonly size: number;
474
+ readonly mimeType: string;
475
+ readonly sha256: string;
476
+ readonly revision: string;
477
+ }
478
+ type IssuedTransferSnapshot = JsonObject & {
479
+ transferId: string;
480
+ direction: "upload" | "download";
481
+ status: "pending";
482
+ expiresAt: string;
483
+ };
484
+ type MaintenanceAuthStatus = "not_required" | "required" | "ready" | "failed";
485
+ type MaintenanceStatus = "pending" | "approved" | "denied" | "cancelled" | "expired";
486
+ type MaintenanceTarget = "package" | "extension" | "mcp" | "api";
487
+ type McpMethod = "tools/call" | "tools/list" | "resources/list" | "resources/templates/list" | "prompts/list" | "prompts/get";
488
+ type Profile = "development" | "production";
489
+ type TransferOffer = Readonly<IssuedTransferSnapshot & {
490
+ request: TransferRequest;
491
+ }>;
492
+ type TransferRequest = {
493
+ readonly method: "GET" | "PUT";
494
+ readonly url: string;
495
+ readonly headers: Readonly<Record<string, string>>;
496
+ readonly expiresAt: string;
497
+ };
498
+ type TransferResource = Pick<ArtifactRecord, "uri" | "name" | "mimeType" | "size">;
499
+ type TransferStatus = "preparing" | "pending" | "transferring" | "cancelling" | "succeeded" | "failed" | "cancelled" | "expired" | "interrupted";
500
+
501
+ export {};
502
+
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ // Type-only public contract: no Agent initialization.
2
+ export {};
package/package.json CHANGED
@@ -1,6 +1,31 @@
1
1
  {
2
2
  "name": "@nexum-hub/sdk",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.0.1",
4
+ "private": false,
5
+ "description": "Nexum SDK 扩展公共类型协议",
6
+ "license": "UNLICENSED",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/bYiyLi/NexumAgent.git",
10
+ "directory": "packages/extension-api"
11
+ },
12
+ "publishConfig": {
13
+ "access": "public",
14
+ "tag": "next"
15
+ },
16
+ "type": "module",
17
+ "engines": {
18
+ "node": ">=24.22.1 <25"
19
+ },
20
+ "exports": {
21
+ ".": {
22
+ "types": "./dist/index.d.ts",
23
+ "import": "./dist/index.js"
24
+ }
25
+ },
26
+ "types": "./dist/index.d.ts",
27
+ "files": [
28
+ "dist"
29
+ ],
30
+ "sideEffects": false
31
+ }