@x-otto/service 0.1.0-alpha.43 → 0.3.0-beta.0

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.
Files changed (54) hide show
  1. package/dist/ask-host.d.ts +18 -0
  2. package/dist/ask-validate.d.ts +47 -0
  3. package/dist/attached-writers.d.ts +9 -0
  4. package/dist/authorize.d.ts +8 -0
  5. package/dist/chat-routes.d.ts +4 -0
  6. package/dist/client-entry.d.ts +114 -0
  7. package/dist/client-entry.js +1414 -0
  8. package/dist/connection-binding.d.ts +9 -0
  9. package/dist/context.d.ts +51 -0
  10. package/dist/credential.d.ts +51 -0
  11. package/dist/errors.d.ts +11 -0
  12. package/dist/events.d.ts +21 -0
  13. package/dist/extension-approval.d.ts +41 -0
  14. package/dist/extension-rpc.d.ts +31 -0
  15. package/dist/fanout.d.ts +13 -0
  16. package/dist/handler-options.d.ts +252 -0
  17. package/dist/handlers.d.ts +23 -0
  18. package/dist/hub-capabilities.d.ts +15 -0
  19. package/dist/index.d.ts +1144 -624
  20. package/dist/index.js +8591 -43
  21. package/dist/methods.d.ts +5 -0
  22. package/dist/mock.d.ts +23 -0
  23. package/dist/resource-read.d.ts +4 -0
  24. package/dist/route-read-only.d.ts +1 -0
  25. package/dist/route-set.d.ts +22 -0
  26. package/dist/route-targets.d.ts +6 -0
  27. package/dist/route-validate.d.ts +15 -0
  28. package/dist/routes/ask-routes.d.ts +3 -0
  29. package/dist/routes/auth-routes.d.ts +3 -0
  30. package/dist/routes/core-routes.d.ts +3 -0
  31. package/dist/routes/extension-routes.d.ts +3 -0
  32. package/dist/routes/index.d.ts +6 -0
  33. package/dist/routes/plugin-routes.d.ts +3 -0
  34. package/dist/routes/repository-meta.d.ts +2 -0
  35. package/dist/routes/session-routes.d.ts +3 -0
  36. package/dist/routes/session-runtime-routes.d.ts +5 -0
  37. package/dist/routes/settings-routes.d.ts +3 -0
  38. package/dist/routes/support.d.ts +7 -0
  39. package/dist/routes/worker-routes.d.ts +2 -0
  40. package/dist/routes/workspace-routes.d.ts +3 -0
  41. package/dist/send-attempt-table.d.ts +35 -0
  42. package/dist/serialize-shared.d.ts +1 -0
  43. package/dist/source-for-session.d.ts +4 -0
  44. package/dist/subscription-backfill.d.ts +19 -0
  45. package/dist/target-extractors.d.ts +18 -0
  46. package/dist/token-verifier.d.ts +12 -0
  47. package/dist/vite.d.ts +11 -0
  48. package/dist/vite.js +4273 -0
  49. package/dist/web-host.d.ts +52 -0
  50. package/dist/wire-stats.d.ts +6 -0
  51. package/dist/wire.d.ts +12 -0
  52. package/dist/ws.d.ts +66 -0
  53. package/package.json +19 -31
  54. package/README.md +0 -135
@@ -0,0 +1,52 @@
1
+ import type { TicketClaims } from './credential.ts';
2
+ export declare const WEB_LAUNCH_TTL_MS = 60000;
3
+ export declare const WEB_SESSION_TTL_MS: number;
4
+ export declare const WEB_EXCHANGE_ROUTE = "/api/web.exchange";
5
+ export declare const WEB_LAUNCH_LINK_ROUTE = "/api/web.launchLink";
6
+ export declare const CONTENT_SECURITY_POLICY = "default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'; object-src 'none'; frame-ancestors 'none'";
7
+ export declare function effectiveHostname(request: Request): string | undefined;
8
+ export declare function checkRequestHost(request: Request): HostGateDecision;
9
+ export interface HostGateDecision {
10
+ readonly allowed: boolean;
11
+ readonly reason?: 'missing-host' | 'foreign-host';
12
+ }
13
+ export declare function checkHostHeader(hostHeader: string | undefined): HostGateDecision;
14
+ export interface WebLaunchTicket {
15
+ readonly code: string;
16
+ readonly token: string;
17
+ readonly sessionId?: string;
18
+ readonly expiresAt: number;
19
+ readonly tokenExpiresAt: number;
20
+ }
21
+ export interface WebLaunchRegistry {
22
+ issue(sessionId?: string): WebLaunchTicket;
23
+ redeem(code: string): WebLaunchTicket | undefined;
24
+ accept(token: string): boolean;
25
+ sessionOf(token: string): string | undefined;
26
+ claimsOf(token: string): TicketClaims | undefined;
27
+ size(): number;
28
+ }
29
+ export interface WebLaunchRegistryOptions {
30
+ readonly ttlMs?: number;
31
+ readonly sessionTtlMs?: number;
32
+ readonly now?: () => number;
33
+ readonly mintToken?: () => string;
34
+ }
35
+ export declare function createWebLaunchRegistry(options?: WebLaunchRegistryOptions): WebLaunchRegistry;
36
+ export interface StaticAsset {
37
+ readonly contentType: string;
38
+ readonly body: Buffer;
39
+ }
40
+ export interface StaticRoot {
41
+ readonly root: string;
42
+ readonly fallbackFile?: string;
43
+ }
44
+ export type StaticResolution = StaticAsset | {
45
+ readonly status: 404;
46
+ } | {
47
+ readonly fallback: string;
48
+ };
49
+ export declare function resolveStaticAsset(roots: readonly StaticRoot[], requestPath: string): StaticResolution;
50
+ export declare function checkHostHeaderWhenPresent(hostHeader: string | undefined): HostGateDecision;
51
+ export declare function checkOriginHeader(origin: string | undefined): HostGateDecision;
52
+ export declare function loopbackHostAllowList(): (hostHeader: string | undefined) => boolean;
@@ -0,0 +1,6 @@
1
+ import type { CapacityWireStats } from '@x-otto/kernel';
2
+ export declare function recordResponse(type: string, bytes: number, payload: unknown, isSent: boolean): void;
3
+ export declare function recordEventDelivery(bytes: number, isSent: boolean): void;
4
+ export declare function recordConnectionClose(reason: string): void;
5
+ export declare function wireStatsSnapshot(): CapacityWireStats;
6
+ export declare function resetWireStats(): void;
package/dist/wire.d.ts ADDED
@@ -0,0 +1,12 @@
1
+ import type { ServiceMethod, ServiceMethodInput, ServiceMethodOutput, WireResponse } from '@x-otto/kernel';
2
+ import type { RequestContext } from './context.ts';
3
+ import type { ExtensionRequestHandlers } from './extension-rpc.ts';
4
+ export interface WireRequestHandlers extends Partial<ExtensionRequestHandlers> {
5
+ handle<K extends ServiceMethod>(type: K, payload: ServiceMethodInput<K>, context?: RequestContext): Promise<ServiceMethodOutput<K>>;
6
+ }
7
+ export declare function toWireError(error: unknown): {
8
+ code: string;
9
+ message: string;
10
+ details?: unknown;
11
+ };
12
+ export declare function handleWireRequest(handlers: WireRequestHandlers, type: string, rawBody: string, context?: RequestContext, fallbackId?: string): Promise<WireResponse>;
package/dist/ws.d.ts ADDED
@@ -0,0 +1,66 @@
1
+ import type { IncomingMessage } from 'node:http';
2
+ import type { Duplex } from 'node:stream';
3
+ import type { ServiceEvent, ServiceMethod } from '@x-otto/kernel';
4
+ import type { RequestContext } from './context.ts';
5
+ import type { TicketClaims } from './credential.ts';
6
+ import type { Handlers } from './handlers.ts';
7
+ import type { EventRelay } from './events.ts';
8
+ export declare function eventWithinScope(context: RequestContext, event: ServiceEvent): boolean;
9
+ export declare function eventWithinSubscription(allowed: readonly string[] | undefined, event: ServiceEvent): boolean;
10
+ export declare function clientFeaturesOf(raw: unknown): readonly string[] | undefined;
11
+ export type WebSocketCloseReason = 'server-close' | 'client-close' | 'error' | 'stale' | 'auth-required' | 'auth-failed' | 'resync-required';
12
+ export declare const WS_CLOSE_AUTH_REQUIRED = 4001;
13
+ export declare const WS_CLOSE_AUTH_FAILED = 4003;
14
+ export interface WebSocketManagerOptions {
15
+ path?: string;
16
+ authToken?: string;
17
+ readToken?: string;
18
+ readTokenWorkspaceScope?: readonly string[] | (() => readonly string[] | undefined);
19
+ tokenWorkspaceScope?: readonly string[];
20
+ principalId?: string;
21
+ heartbeatIntervalMs?: number;
22
+ heartbeatTimeoutMs?: number;
23
+ authFrameTimeoutMs?: number;
24
+ closeGraceMs?: number;
25
+ attachedWriters?: import('./attached-writers.ts').AttachedWritersRegistry;
26
+ requireHandshake?: boolean;
27
+ methodAllowList?: readonly ServiceMethod[];
28
+ onConnectionStale?: (info: {
29
+ connectionId: string;
30
+ lastSeenAt: number;
31
+ now: number;
32
+ }) => void;
33
+ onConnectionOpen?: (info: {
34
+ connectionId: string;
35
+ }) => void;
36
+ onConnectionClose?: (info: {
37
+ connectionId: string;
38
+ reason: WebSocketCloseReason;
39
+ bufferedBytes: number;
40
+ lastSeenAgoMs: number;
41
+ droppedFrames: number;
42
+ sessions: number;
43
+ }) => void;
44
+ onResponseUndeliverable?: (info: {
45
+ type: string;
46
+ id: string;
47
+ }) => void;
48
+ onConnectionAuthenticated?: (info: {
49
+ connectionId: string;
50
+ isFollow: boolean;
51
+ clientFeatures: readonly string[];
52
+ }) => void;
53
+ ticketOf?(token: string): TicketClaims | undefined;
54
+ allowHost?(hostHeader: string | undefined): boolean;
55
+ allowOrigin?(origin: string | undefined): boolean;
56
+ }
57
+ export interface UpgradeServer {
58
+ on(event: 'upgrade', listener: (req: IncomingMessage, socket: Duplex, head: Buffer) => void): unknown;
59
+ off(event: 'upgrade', listener: (req: IncomingMessage, socket: Duplex, head: Buffer) => void): unknown;
60
+ }
61
+ export interface WebSocketManager {
62
+ attach(server: UpgradeServer): void;
63
+ close(): void;
64
+ }
65
+ export declare function sessionIsAuthorized(handlers: Handlers, sessionId: string, context?: RequestContext): Promise<boolean>;
66
+ export declare function createWebSocketManager(handlers: Handlers, relay: EventRelay, options?: WebSocketManagerOptions): WebSocketManager;
package/package.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "name": "@x-otto/service",
3
- "version": "0.1.0-alpha.43",
3
+ "version": "0.3.0-beta.0",
4
+ "description": "UI 通信协议层:统一契约的 handlers/mock/client(web-ui HTTP/WS,tui 进程内)",
4
5
  "files": [
5
6
  "dist"
6
7
  ],
@@ -11,38 +12,25 @@
11
12
  ".": {
12
13
  "types": "./dist/index.d.ts",
13
14
  "import": "./dist/index.js"
15
+ },
16
+ "./vite": {
17
+ "types": "./dist/vite.d.ts",
18
+ "import": "./dist/vite.js"
19
+ },
20
+ "./client": {
21
+ "types": "./dist/client-entry.d.ts",
22
+ "import": "./dist/client-entry.js"
14
23
  }
15
24
  },
16
- "publishConfig": {
17
- "access": "public",
18
- "registry": "https://registry.npmjs.org",
19
- "tag": "alpha"
20
- },
21
25
  "dependencies": {
22
- "@hono/node-server": "1.19.13",
23
- "hono": "4.12.12",
24
- "ws": "8.20.0",
25
- "@x-otto/agent": "0.1.0-alpha.43",
26
- "@x-otto/coding": "0.1.0-alpha.43",
27
- "@x-otto/ai": "0.1.0-alpha.43",
28
- "@x-otto/schedule": "0.1.0-alpha.43",
29
- "@x-otto/hooks": "0.1.0-alpha.43",
30
- "@x-otto/persistence": "0.1.0-alpha.43",
31
- "@x-otto/devtools": "0.1.0-alpha.43",
32
- "@x-otto/session-contract": "0.1.0-alpha.43",
33
- "@x-otto/shared": "0.1.0-alpha.43",
34
- "@x-otto/workspace": "0.1.0-alpha.43",
35
- "@x-otto/runtime": "0.1.0-alpha.43",
36
- "@x-otto/otel": "0.1.0-alpha.43",
37
- "@x-otto/trace-view": "0.1.0-alpha.43"
26
+ "@hono/node-server": "^2.1.1",
27
+ "@x-otto/ask": "^0.3.0-beta.0",
28
+ "@x-otto/kernel": "^0.3.0-beta.0",
29
+ "hono": "^4.13.5",
30
+ "ws": "^8.21.3"
38
31
  },
39
- "devDependencies": {
40
- "@types/ws": "8.18.1"
41
- },
42
- "private": false,
43
- "scripts": {
44
- "build": "tsdown",
45
- "typecheck": "tsc --noEmit",
46
- "clean": "rm -rf dist"
32
+ "publishConfig": {
33
+ "access": "public",
34
+ "tag": "beta"
47
35
  }
48
- }
36
+ }
package/README.md DELETED
@@ -1,135 +0,0 @@
1
- # @x-otto/service
2
-
3
- ## Module Purpose
4
-
5
- Otto's network transport layer: Hono-based HTTP API + WebSocket real-time communication + event bridging +
6
- a standalone persistence storage service (persistenced).
7
-
8
- ## Core Features
9
-
10
- | Module/Export | Function |
11
- |-----------|------|
12
- | `CodingService` | Hono app lifecycle + component orchestration (WS Manager / DebugBridge / InboundRouter) |
13
- | `WebSocketManager` | WebSocket connection management + session subscription + auth (origin/token) |
14
- | `EventBridge` | One-way mapping from AgentSession events to WS `Session.event` |
15
- | `TraceBridge` | Per-session trace tail → WS (`Trace.event`) |
16
- | `DebugBridge` | Bridges the devtools debug protocol to HTTP/WebSocket |
17
- | `InboundRouter` | Dispatches inbound messages from frontend to backend |
18
- | `EventBus` | In-process event bus (`append / subscribe`) |
19
- | `startPersistenced` | Standalone persistence storage service launcher (SQLite + HTTP API) |
20
-
21
- ## HTTP API Routes
22
-
23
- | Route Prefix | Endpoint | Description |
24
- |----------|------|------|
25
- | `/api/health` | `GET /` | Health check |
26
- | `/api/authority` | `GET /` | Authority descriptor (instanceId / workspaceDir / capabilities) |
27
- | `/api/chat` | `POST /query` / `GET /messages` / `POST /interrupt` / `DELETE /clear` | Session conversation |
28
- | `/api/sessions` | `GET/POST /` / `GET /current` / `GET /:id/messages` / `POST /:id/resume` (501) / `GET /:id/trace` / `GET/PUT /:id/model` / `DELETE /:id/model` (501) | Session CRUD |
29
- | `/api/sessions` (subdomain) | `POST /verify-path` / `POST /browse-directory` / `GET /files` (workspace) + time-travel endpoints | workspace + timetravel |
30
- | `/api/storage` | `GET /:namespace` / `GET/PUT/DELETE /:namespace/:id` | RemotePersistence wire protocol server |
31
- | `/api/setting` | `GET/PUT /` / `GET /providers` / `GET /models` / `POST /verify-model` / `POST /mode` / `POST /thinking` / `POST /autonomy` (501) | Settings management |
32
- | `/api/devtools` | `GET /status` / `GET /breakpoints` | Devtools worker bridge |
33
- | `/api/debugger` | Breakpoint CRUD / pause / resume / inject / state | Debugger API |
34
- | `/api/logs` | `GET /history` / `GET /stream` (SSE) | Log query and streaming |
35
- | `/api/catalog` | Exposes extension/sigil catalog to the frontend | Plugin catalog |
36
- | `/api/jobs` | Background job list / artifact diff | Job workbench (RFC-351) |
37
- | `/api/plugin-feedback` | Plugin feedback submission | Plugin feedback |
38
-
39
- > Route table authoritative source: `src/create-app.ts` (main app) and `src/persistenced-app.ts` (persistenced). Keep this table in sync with the `app.route(...)` registrations there.
40
-
41
- ### persistenced routes (separate process, `startPersistenced`)
42
-
43
- | Route Prefix | Endpoint | Description |
44
- |----------|------|------|
45
- | `GET /health` | — | Health + uptime + namespaces |
46
- | `/api/storage` | document CRUD | RemotePersistence wire protocol server |
47
- | `/api/events` | SSE push (change_log polling) | Cross-process change notification |
48
- | `/api/sync` | `push` / `pull` batch sync | Namespace batch sync |
49
- | `/api/schedules` | schedule lease CRUD | RemoteScheduleStore lease (RFC-161) |
50
-
51
-
52
- ## WebSocket
53
-
54
- - Upgrade route: `/ws`
55
- - Optional origin allowlist + `?token=` bearer auth (fail-closed, timingSafeEqual)
56
- - After connecting, clients subscribe to a given session's event stream (`Session.subscribe` / `Session.unsubscribe`)
57
- - Message format: server→client is a discriminated union `{ type, data }`; client→server is
58
- JSON-RPC-style `{ method, params }`
59
-
60
- ## Installation
61
-
62
- ```bash
63
- pnpm add @x-otto/service
64
- ```
65
-
66
- Or build from the repo:
67
-
68
- ```bash
69
- pnpm --filter @x-otto/service build
70
- ```
71
-
72
- ## Quick Start
73
-
74
- ```ts
75
- import { createApp } from '@x-otto/coding'
76
- import { createCodingService } from '@x-otto/service'
77
-
78
- const app = createApp(options)
79
- await app.start()
80
-
81
- const service = createCodingService(app, { port: 8417, host: '127.0.0.1' })
82
- await service.start()
83
- ```
84
-
85
- ## API
86
-
87
- | Export | Type | Description |
88
- |------|------|------|
89
- | `CodingService` | `class` | Core service class (orchestrates WS Manager / bridges / InboundRouter) |
90
- | `createCodingService` | `function` | Factory function |
91
- | `WebSocketManager` | `class` | WebSocket connection management + subscription + broadcast |
92
- | `EventBridge` | `class` | AgentSession event → WS mapping |
93
- | `DebugBridge` | `class` | Debug protocol bridge |
94
- | `InboundRouter` | `class` | Inbound message dispatch |
95
- | `encodeSessionEvent` | `function` | Session event → Session.event envelope |
96
- | `createProjectorState` | `function` | Creates a projection accumulator |
97
- | `startPersistenced` | `function` | Starts the standalone storage service |
98
- | `eventBus` | `instance` | In-process EventBus singleton |
99
- | `EventBus` | `class` | Event bus class |
100
-
101
- ## Directory Overview
102
-
103
- ```
104
- src/
105
- coding-service.ts # core orchestration
106
- create-app.ts # Hono app assembly
107
- websocket-manager.ts # WebSocket connection management
108
- event-bridge.ts # event bridging
109
- event-bus.ts # in-process event bus
110
- trace-bridge.ts # trace tail → WS
111
- debug-bridge.ts # debug bridging
112
- debug-event-router.ts # devtools events → WS
113
- inbound-router.ts # inbound message dispatch
114
- session-event-wire.ts # session events → neutral SessionEvent (sanitized + wrapped)
115
- message-serializer.ts # message serialization
116
- persistenced-app.ts # standalone storage service
117
- types.ts # core types
118
- routes/ # route implementations (chat/sessions/setting/storage/debugger/devtools/logs/catalog, etc.)
119
- middleware/ # middleware (request-id / access-log / rate-limit / storage-auth)
120
- index.ts
121
- ```
122
-
123
- ## Development Commands
124
-
125
- ```bash
126
- pnpm --filter @x-otto/service build
127
- pnpm --filter @x-otto/service typecheck
128
- pnpm --filter @x-otto/service clean
129
- ```
130
-
131
- ## Related Packages
132
-
133
- `@x-otto/agent`, `@x-otto/ai`, `@x-otto/coding`, `@x-otto/schedule`, `@x-otto/devtools`, `@x-otto/otel`,
134
- `@x-otto/hooks`, `@x-otto/persistence`, `@x-otto/session-contract`, `@x-otto/shared`, `@x-otto/trace-view`,
135
- `@x-otto/workspace`; external dependencies `hono`, `@hono/node-server`, `ws`