@x-otto/service 0.1.0-alpha.9 → 0.4.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.
- package/dist/ask-host.d.ts +18 -0
- package/dist/ask-validate.d.ts +47 -0
- package/dist/attached-writers.d.ts +9 -0
- package/dist/authorize.d.ts +8 -0
- package/dist/chat-routes.d.ts +4 -0
- package/dist/client-entry.d.ts +114 -0
- package/dist/client-entry.js +1414 -0
- package/dist/connection-binding.d.ts +9 -0
- package/dist/context.d.ts +51 -0
- package/dist/credential.d.ts +51 -0
- package/dist/errors.d.ts +11 -0
- package/dist/events.d.ts +21 -0
- package/dist/extension-approval.d.ts +41 -0
- package/dist/extension-rpc.d.ts +31 -0
- package/dist/fanout.d.ts +13 -0
- package/dist/handler-options.d.ts +252 -0
- package/dist/handlers.d.ts +23 -0
- package/dist/hub-capabilities.d.ts +15 -0
- package/dist/index.d.ts +1144 -625
- package/dist/index.js +8591 -44
- package/dist/methods.d.ts +5 -0
- package/dist/mock.d.ts +23 -0
- package/dist/resource-read.d.ts +4 -0
- package/dist/route-read-only.d.ts +1 -0
- package/dist/route-set.d.ts +22 -0
- package/dist/route-targets.d.ts +6 -0
- package/dist/route-validate.d.ts +15 -0
- package/dist/routes/ask-routes.d.ts +3 -0
- package/dist/routes/auth-routes.d.ts +3 -0
- package/dist/routes/core-routes.d.ts +3 -0
- package/dist/routes/extension-routes.d.ts +3 -0
- package/dist/routes/index.d.ts +6 -0
- package/dist/routes/plugin-routes.d.ts +3 -0
- package/dist/routes/repository-meta.d.ts +2 -0
- package/dist/routes/session-routes.d.ts +3 -0
- package/dist/routes/session-runtime-routes.d.ts +5 -0
- package/dist/routes/settings-routes.d.ts +3 -0
- package/dist/routes/support.d.ts +7 -0
- package/dist/routes/worker-routes.d.ts +2 -0
- package/dist/routes/workspace-routes.d.ts +3 -0
- package/dist/send-attempt-table.d.ts +35 -0
- package/dist/serialize-shared.d.ts +1 -0
- package/dist/source-for-session.d.ts +4 -0
- package/dist/subscription-backfill.d.ts +19 -0
- package/dist/target-extractors.d.ts +18 -0
- package/dist/token-verifier.d.ts +12 -0
- package/dist/vite.d.ts +11 -0
- package/dist/vite.js +4273 -0
- package/dist/web-host.d.ts +52 -0
- package/dist/wire-stats.d.ts +6 -0
- package/dist/wire.d.ts +12 -0
- package/dist/ws.d.ts +66 -0
- package/package.json +19 -31
- package/README.md +0 -135
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { AskConnection, AskInvalidationReason, AskPeer, AskScope, AskViewMessage, RuntimeAskChannels } from '@x-otto/kernel';
|
|
2
|
+
export type AskAccessAction = 'observe' | 'answer';
|
|
3
|
+
export interface AskHostOptions {
|
|
4
|
+
resolveOwner: (scope: AskScope) => RuntimeAskChannels | undefined | Promise<RuntimeAskChannels | undefined>;
|
|
5
|
+
authorize?: (peer: AskPeer, scope: AskScope, action: AskAccessAction) => boolean | Promise<boolean>;
|
|
6
|
+
diagnose?: (input: {
|
|
7
|
+
code: string;
|
|
8
|
+
message: string;
|
|
9
|
+
detail?: unknown;
|
|
10
|
+
}) => void;
|
|
11
|
+
}
|
|
12
|
+
export interface AskHost {
|
|
13
|
+
connect(peer: AskPeer, send: (message: AskViewMessage) => void, onInvalidated?: (scope: AskScope, reason: AskInvalidationReason) => void): AskConnection;
|
|
14
|
+
invalidate(predicate: (peer: AskPeer, scope: AskScope) => boolean, reason: AskInvalidationReason): void;
|
|
15
|
+
revoke(peer: AskPeer, scope: AskScope, reason: AskInvalidationReason): boolean;
|
|
16
|
+
dispose(): void;
|
|
17
|
+
}
|
|
18
|
+
export declare function createAskHost(options: AskHostOptions): AskHost;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { AskInvalidationReason, AskRef, AskRespond, AskScope, AskViewMessage, HitlAnswer, HitlAskRequest, HitlReply, PermissionAskRef, PermissionAskRequest, PermissionAskResponse, SandboxBackendName } from '@x-otto/kernel';
|
|
2
|
+
type UnknownRecord = Record<string, unknown>;
|
|
3
|
+
export declare const APPROVAL_SCOPES: readonly ["once", "session", "project", "global"];
|
|
4
|
+
export declare const SANDBOX_BACKENDS: readonly SandboxBackendName[];
|
|
5
|
+
export declare const ASK_INVALIDATION_REASONS: readonly ["disconnected", "scope-denied", "stale-runtime", "closed"];
|
|
6
|
+
export declare function isRecord(value: unknown): value is UnknownRecord;
|
|
7
|
+
export declare function parseAskScope(value: unknown): AskScope | undefined;
|
|
8
|
+
export declare function scopeKey(scope: AskScope): string;
|
|
9
|
+
export declare function parseAskRef(value: unknown): AskRef | undefined;
|
|
10
|
+
export declare function parsePermissionAskRef(value: unknown): PermissionAskRef | undefined;
|
|
11
|
+
export declare function parsePermissionAskResponse(value: unknown): PermissionAskResponse | undefined;
|
|
12
|
+
export declare function parseHitlAnswer(value: unknown): HitlAnswer | undefined;
|
|
13
|
+
export declare function parseHitlReply(value: unknown): HitlReply | undefined;
|
|
14
|
+
export declare function parsePermissionAskRequest(value: unknown): PermissionAskRequest | undefined;
|
|
15
|
+
export declare function parseHitlAskRequest(value: unknown): HitlAskRequest | undefined;
|
|
16
|
+
export declare function parseAskViewMessage(value: unknown): AskViewMessage | undefined;
|
|
17
|
+
export declare function viewMessageScope(message: AskViewMessage): AskScope;
|
|
18
|
+
export declare function parseAskInvalidated(value: unknown): {
|
|
19
|
+
scope: AskScope;
|
|
20
|
+
reason: AskInvalidationReason;
|
|
21
|
+
} | undefined;
|
|
22
|
+
export type ParsedAskFrame = {
|
|
23
|
+
kind: 'message';
|
|
24
|
+
message: AskViewMessage;
|
|
25
|
+
} | {
|
|
26
|
+
kind: 'invalidated';
|
|
27
|
+
scope: AskScope;
|
|
28
|
+
reason: AskInvalidationReason;
|
|
29
|
+
};
|
|
30
|
+
export declare function parseAskFrame(value: unknown): ParsedAskFrame | undefined;
|
|
31
|
+
export declare function parseAskOpenPayload(payload: unknown): {
|
|
32
|
+
scope: AskScope;
|
|
33
|
+
answer: boolean;
|
|
34
|
+
} | undefined;
|
|
35
|
+
export declare function parseAskScopePayload(payload: unknown): AskScope | undefined;
|
|
36
|
+
export declare function parseApprovalRespondPayload(payload: unknown): {
|
|
37
|
+
ref: PermissionAskRef;
|
|
38
|
+
response: PermissionAskResponse;
|
|
39
|
+
} | undefined;
|
|
40
|
+
export declare function parseHitlRespondPayload(payload: unknown): {
|
|
41
|
+
ref: AskRef;
|
|
42
|
+
reply: HitlReply;
|
|
43
|
+
} | undefined;
|
|
44
|
+
export declare function parseAskRespond(command: unknown): AskRespond | undefined;
|
|
45
|
+
export declare function validatePermissionResponse(request: PermissionAskRequest, response: PermissionAskResponse): boolean;
|
|
46
|
+
export declare function validateHitlReply(request: HitlAskRequest, reply: HitlReply): boolean;
|
|
47
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export interface AttachedWriter {
|
|
2
|
+
connectionId: string;
|
|
3
|
+
capable: boolean;
|
|
4
|
+
}
|
|
5
|
+
export interface AttachedWritersRegistry {
|
|
6
|
+
attach(sessionId: string, writer: AttachedWriter): () => void;
|
|
7
|
+
writersOf(sessionId: string): readonly AttachedWriter[];
|
|
8
|
+
}
|
|
9
|
+
export declare function createAttachedWritersRegistry(): AttachedWritersRegistry;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ServiceMethod } from '@x-otto/kernel';
|
|
2
|
+
import type { RequestContext } from './context.ts';
|
|
3
|
+
import type { Authorizer } from './handlers.ts';
|
|
4
|
+
import type { RouteTarget } from './route-targets.ts';
|
|
5
|
+
export declare function isReadOnlyMethod(action: ServiceMethod): boolean;
|
|
6
|
+
export declare function targetWithinScope(context: RequestContext, target: RouteTarget | undefined): boolean;
|
|
7
|
+
export declare function createDefaultAuthorizer(): Authorizer;
|
|
8
|
+
export declare function assertCredentialAllowed(context: RequestContext, method: ServiceMethod, payload: unknown, target: RouteTarget | undefined): void;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { SendAttemptTable } from './send-attempt-table.ts';
|
|
2
|
+
import type { RouteSet } from './route-set.ts';
|
|
3
|
+
import type { HandlerOptions } from './handler-options.ts';
|
|
4
|
+
export declare function chatRoutes(deps: HandlerOptions, attempts?: SendAttemptTable): RouteSet;
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { AskConnection, AskInvalidationReason, AskScope, AskViewMessage, ExtensionClientFrame, ExtensionRpcAccess, ExtensionWirePayload, ExtensionWireRequest, RateLimitInfo, ServiceClientContract, ServiceEvent, ServiceEvent as ServiceEvent$1, SessionEntry, SessionRestoreResult, StreamErrorKind, WireRequest, WireResponse } from "@x-otto/kernel";
|
|
2
|
+
|
|
3
|
+
//#region src/events.d.ts
|
|
4
|
+
declare const GLOBAL_EVENTS_CHANNEL = "__global__";
|
|
5
|
+
declare function isPrivateAskEvent(event: unknown): boolean;
|
|
6
|
+
declare function isPerSessionOnlyEvent(event: unknown): boolean;
|
|
7
|
+
declare function filterPrivateAskEvents(handler: (event: ServiceEvent$1) => void): (event: ServiceEvent$1) => void;
|
|
8
|
+
//#endregion
|
|
9
|
+
//#region src/errors.d.ts
|
|
10
|
+
declare class ServiceError extends Error {
|
|
11
|
+
readonly code: string;
|
|
12
|
+
readonly details?: unknown | undefined;
|
|
13
|
+
constructor(code: string, message: string, details?: unknown | undefined);
|
|
14
|
+
}
|
|
15
|
+
declare function isServiceError(error: unknown): error is ServiceError;
|
|
16
|
+
declare class RequestForbiddenError extends ServiceError {
|
|
17
|
+
readonly action: string;
|
|
18
|
+
readonly principalId: string;
|
|
19
|
+
constructor(action: string, principalId: string);
|
|
20
|
+
}
|
|
21
|
+
//#endregion
|
|
22
|
+
//#region src/client.d.ts
|
|
23
|
+
interface ServiceClient extends ServiceClientContract {
|
|
24
|
+
asks?: AskConnection;
|
|
25
|
+
requestExtension?(type: string, payload: ExtensionWirePayload, contractVersion: number, access?: ExtensionRpcAccess): Promise<unknown>;
|
|
26
|
+
subscribe(sessionId: string, handler: (event: ServiceEvent$1) => void): () => void;
|
|
27
|
+
onReconnected?(handler: () => void): () => void;
|
|
28
|
+
onExtension?(handler: (frame: ExtensionClientFrame) => void): () => void;
|
|
29
|
+
subscribeAwaited?(sessionId: string): Promise<void>;
|
|
30
|
+
close(): void;
|
|
31
|
+
}
|
|
32
|
+
interface WireCloseInfo {
|
|
33
|
+
reason: 'local' | 'remote';
|
|
34
|
+
reconnecting: boolean;
|
|
35
|
+
}
|
|
36
|
+
type WireControlRequest = {
|
|
37
|
+
id: string;
|
|
38
|
+
type: 'session.subscribe';
|
|
39
|
+
payload: {
|
|
40
|
+
sessionId: string;
|
|
41
|
+
sinceSeq?: number;
|
|
42
|
+
};
|
|
43
|
+
} | {
|
|
44
|
+
id: string;
|
|
45
|
+
type: 'session.unsubscribe';
|
|
46
|
+
payload: {
|
|
47
|
+
sessionId: string;
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
interface WireSendOptions {
|
|
51
|
+
access?: ExtensionRpcAccess;
|
|
52
|
+
}
|
|
53
|
+
interface WireTransport {
|
|
54
|
+
send(request: WireRequest | WireControlRequest | ExtensionWireRequest, options?: WireSendOptions): void;
|
|
55
|
+
subscribe(sessionId: string): void;
|
|
56
|
+
subscribeAwaited?(sessionId: string): Promise<void>;
|
|
57
|
+
unsubscribe(sessionId: string): void;
|
|
58
|
+
onGeneration?(handler: (generation: number) => void): () => void;
|
|
59
|
+
onReconnected?(handler: () => void): () => void;
|
|
60
|
+
onResponse(handler: (res: WireResponse) => void): void;
|
|
61
|
+
onEvent(handler: (event: ServiceEvent$1) => void): void;
|
|
62
|
+
onExtension?(handler: (frame: ExtensionClientFrame) => void): void;
|
|
63
|
+
onClose(handler: (info?: WireCloseInfo) => void): void;
|
|
64
|
+
onAskView?(handler: (message: AskViewMessage) => void): void;
|
|
65
|
+
onAskInvalidated?(handler: (scope: AskScope, reason: AskInvalidationReason) => void): void;
|
|
66
|
+
askOpen?(scope: AskScope, options: {
|
|
67
|
+
answer: boolean;
|
|
68
|
+
}): Promise<void>;
|
|
69
|
+
askRefresh?(scope: AskScope): Promise<void>;
|
|
70
|
+
askClose?(scope: AskScope): void;
|
|
71
|
+
closeReason?(): string | undefined;
|
|
72
|
+
close(): void;
|
|
73
|
+
}
|
|
74
|
+
declare function createHttpWsClient(transport: WireTransport): ServiceClient;
|
|
75
|
+
//#endregion
|
|
76
|
+
//#region src/transport.d.ts
|
|
77
|
+
interface WebSocketReconnectOptions {
|
|
78
|
+
maxAttempts: number;
|
|
79
|
+
backoffMs?: number;
|
|
80
|
+
maxBackoffMs?: number;
|
|
81
|
+
}
|
|
82
|
+
type WebSocketTransportCloseReason = 'local' | 'remote' | 'exhausted' | 'stale' | 'auth-failed' | 'resync-required';
|
|
83
|
+
interface WebSocketTransportOptions {
|
|
84
|
+
reconnect?: WebSocketReconnectOptions;
|
|
85
|
+
authToken?: string;
|
|
86
|
+
mode?: 'follow' | 'attach';
|
|
87
|
+
features?: readonly string[];
|
|
88
|
+
socketFactory?: (url: string) => WebSocket;
|
|
89
|
+
writeGate?: () => boolean;
|
|
90
|
+
}
|
|
91
|
+
interface WebSocketTransportHandle {
|
|
92
|
+
transport: WireTransport;
|
|
93
|
+
ready: Promise<void>;
|
|
94
|
+
close(): void;
|
|
95
|
+
closeReason(): WebSocketTransportCloseReason | undefined;
|
|
96
|
+
generation(): number;
|
|
97
|
+
}
|
|
98
|
+
declare function createWebSocketTransport(url: string, options?: WebSocketTransportOptions): WebSocketTransportHandle;
|
|
99
|
+
//#endregion
|
|
100
|
+
//#region src/fanout.d.ts
|
|
101
|
+
type ServiceEventHandler = (event: ServiceEvent$1) => void;
|
|
102
|
+
interface EventFanoutOptions {
|
|
103
|
+
onFirstSubscriber?: (sessionId: string) => void;
|
|
104
|
+
onLastSubscriberRemoved?: (sessionId: string) => void;
|
|
105
|
+
}
|
|
106
|
+
interface EventFanout {
|
|
107
|
+
add(sessionId: string, handler: ServiceEventHandler): () => void;
|
|
108
|
+
deliver(sessionId: string, deliver: (handler: ServiceEventHandler) => void): void;
|
|
109
|
+
clear(): void;
|
|
110
|
+
sessionCount(): number;
|
|
111
|
+
}
|
|
112
|
+
declare function createEventFanout(options?: EventFanoutOptions): EventFanout;
|
|
113
|
+
//#endregion
|
|
114
|
+
export { type EventFanout, GLOBAL_EVENTS_CHANNEL, type RateLimitInfo, RequestForbiddenError, type ServiceClient, ServiceError, type ServiceEvent, type ServiceEventHandler, type SessionEntry, type SessionRestoreResult, type StreamErrorKind, type WebSocketTransportOptions, type WireCloseInfo, type WireTransport, createEventFanout, createHttpWsClient, createWebSocketTransport, filterPrivateAskEvents, isPerSessionOnlyEvent, isPrivateAskEvent, isServiceError };
|