@kehto/services 0.11.0 → 0.12.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/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @kehto/services
2
2
 
3
- Reference service handlers for the napplet protocol — audio, notifications, identity, relay pool, cache, keys, media, notify, theme.
3
+ Reference service handlers for the napplet protocol — audio, notifications, identity, relay pool, cache, keys, media, notify, theme, link, common, lists, serial, BLE, WebRTC.
4
4
 
5
5
  > **Alpha status:** Kehto is an early runtime implementation for a draft NIP-5D
6
6
  > protocol. NAP contracts and service envelopes are not final; treat these
@@ -23,22 +23,27 @@ Current draft posture:
23
23
  - The v1.1 signer service is deleted outright. Its responsibilities split into two: read-only identity lookups go through `createIdentityService` (`getPublicKey`, `getRelays`, `getProfile`, `getFollows`, `getList`, `getZaps`, `getMutes`, `getBlocked`, `getBadges`); signing happens inside the shell as part of `relay.publish` / `relay.publishEncrypted` and is never exposed to napplets.
24
24
  - `createKeysService` and `createMediaService` ship real reference backends as of v1.4 (see the dedicated sections below). `createKeysService` attaches a document-level `keydown` listener by default and delivers `keys.action` push envelopes to registered napplets; `createMediaService` mirrors session metadata and playback state to `navigator.mediaSession` and emits `media.command` push envelopes on OS transport events. Both accept a host-bridge option (`HostKeysBridge` / `HostMediaBridge`) so Electron / Tauri / native shells can swap in OS-level backends without re-implementing the wire-protocol bookkeeping.
25
25
  - `createNotifyService` (NIP-5D `notify.*` NAP) coexists with the legacy `createNotificationService` (inc-emit `notifications:*` channel). Both may be registered simultaneously while hosts migrate.
26
+ - `createResourceService` supports `resource.bytesMany` from draft NAP-RESOURCE. Bulk requests return ordered per-URL items and keep per-URL failures local while preserving legacy single-fetch fields for existing Kehto callers.
26
27
 
27
28
  ## Quick Start
28
29
 
29
30
  ```ts
30
31
  import {
31
32
  createIdentityService,
33
+ createListsService,
32
34
  createNotificationService,
35
+ createBleService,
36
+ createSerialService,
37
+ createWebrtcService,
33
38
  } from '@kehto/services';
34
39
 
35
40
  // Identity service — read-only lookups backed by a signer adapter.
36
41
  runtime.registerService(
37
42
  'identity',
38
43
  createIdentityService({
39
- getPublicKey: () => signer.getPublicKey(),
40
- getRelays: () => signer.getRelays(),
44
+ getSigner: () => signer,
41
45
  getProfile: (pk) => nostrClient.fetchProfile(pk),
46
+ getFollows: (pk) => contactListCache.getFollows(pk),
42
47
  }),
43
48
  );
44
49
 
@@ -47,6 +52,70 @@ runtime.registerService(
47
52
  'notifications',
48
53
  createNotificationService({ onChange: (list) => updateBadge(list) }),
49
54
  );
55
+
56
+ // Lists service — shell-owned NIP-51 metadata and mutations.
57
+ runtime.registerService(
58
+ 'lists',
59
+ createListsService({
60
+ supported: () => [{ kind: 10003, type: 'bookmarks', addressable: false }],
61
+ add: (_list, items) => ({ ok: true, added: items.length }),
62
+ remove: (_list, items) => ({ ok: true, removed: items.length }),
63
+ }),
64
+ );
65
+
66
+ // Serial service — runtime-owned serial sessions and host-owned device access.
67
+ runtime.registerService(
68
+ 'serial',
69
+ createSerialService({
70
+ open: () => ({ session: { id: 'host-session-1', state: 'open' } }),
71
+ write: (_sessionId, _data) => {},
72
+ close: (_sessionId) => {},
73
+ }),
74
+ );
75
+
76
+ // BLE service — runtime-owned BLE/GATT sessions and host-owned device access.
77
+ runtime.registerService(
78
+ 'ble',
79
+ createBleService({
80
+ open: () => ({
81
+ session: {
82
+ id: 'host-ble-1',
83
+ state: 'open',
84
+ device: { id: 'host-device-1', name: 'Host BLE' },
85
+ },
86
+ }),
87
+ services: () => [],
88
+ read: () => [87],
89
+ write: (_sessionId, _target, _data) => {},
90
+ subscribe: (_sessionId, _target) => {},
91
+ unsubscribe: (_sessionId, _target) => {},
92
+ close: (_sessionId) => {},
93
+ }),
94
+ );
95
+
96
+ // WebRTC service — runtime-owned sessions and host-owned signaling/transport.
97
+ runtime.registerService(
98
+ 'webrtc',
99
+ createWebrtcService({
100
+ open: (request, ctx) => {
101
+ const id = 'host-webrtc-1';
102
+ ctx.emit({ type: 'state', sessionId: id, state: 'open' });
103
+ return {
104
+ session: {
105
+ id,
106
+ scope: request.scope,
107
+ channel: request.channel ?? 'default',
108
+ protocol: request.protocol,
109
+ state: 'open',
110
+ },
111
+ };
112
+ },
113
+ send: (sessionId, payload, ctx) => {
114
+ ctx.emit({ type: 'message', sessionId, from: 'host', payload });
115
+ },
116
+ close: (_sessionId) => {},
117
+ }),
118
+ );
50
119
  ```
51
120
 
52
121
  ## Keys Service
@@ -353,6 +422,8 @@ Each factory returns a `ServiceHandler` registrable via `runtime.registerService
353
422
  ### Identity NAP
354
423
  - `createIdentityService` — `identity.*` reads (`identity:read`). No signing surface; shell mediates signing internally.
355
424
 
425
+ `createIdentityService` uses `getSigner()` for `identity.getPublicKey` and `identity.getRelays`. Hosts may also pass optional read-only provider hooks for `getProfile`, `getFollows`, `getList`, `getZaps`, `getMutes`, `getBlocked`, and `getBadges`. These hooks receive the current signer pubkey (or `""` when no signer is connected) and return the payload portion of the corresponding `.result` envelope. Kehto does not query relays itself; the hooks are for hosts that already maintain profile, contact-list, list, zap, moderation, or badge data.
426
+
356
427
  ### Notify NAP
357
428
  - `createNotifyService` — canonical `notify.*` envelopes (`notify:send` / `notify:channel`).
358
429
  - `createNotificationService` — legacy inc-emit `notifications:*` channel; coexists with `createNotifyService` until retired.
@@ -368,6 +439,9 @@ Each factory returns a `ServiceHandler` registrable via `runtime.registerService
368
439
  ### Media NAP
369
440
  - `createMediaService` — owner-aware `media.session.create` / `update` / `destroy` / `media.state` / `media.capabilities` + `media.command` push envelopes (`media:control`). Napplet-owned sessions mirror to `navigator.mediaSession` by default; shell-owned creates are rejected until a host playback/fetch bridge is supplied. Implement the `HostMediaBridge` interface to swap in native backends. See [Media Service](#media-service) for the full contract.
370
441
 
442
+ ### WebRTC NAP
443
+ - `createWebrtcService` — `webrtc.open`, `webrtc.send`, `webrtc.close` + host-pushed `webrtc.event` envelopes. The reference handler owns only the NAP request/result bookkeeping; host bridges own signaling, SDP, ICE, peer connection lifecycle, and policy.
444
+
371
445
  ### Theme NAP
372
446
  - `createThemeService` — `theme.get` + `theme.changed` fan-out (`theme:read`). Returns a `ThemeService` with `publishTheme()` / `setTheme()` utilities for host-side updates.
373
447
 
@@ -375,7 +449,7 @@ Each factory returns a `ServiceHandler` registrable via `runtime.registerService
375
449
  - `createAudioService` — `audio:*` inc-emit topic handler. Browser-agnostic registry of per-window audio sources; host wires `onChange` to update transport UI.
376
450
 
377
451
  ### Types
378
- `AudioSource`, `AudioServiceOptions`, `Notification`, `NotificationServiceOptions`, `IdentityServiceOptions`, `RelayPoolServiceOptions`, `CacheServiceOptions`, `CoordinatedRelayOptions`, `KeysServiceOptions`, `MediaServiceOptions`, `NotifyServiceOptions`, `ThemeServiceOptions`, `ThemeService`.
452
+ `AudioSource`, `AudioServiceOptions`, `Notification`, `NotificationServiceOptions`, `IdentityServiceOptions`, `RelayPoolServiceOptions`, `CacheServiceOptions`, `CoordinatedRelayOptions`, `KeysServiceOptions`, `MediaServiceOptions`, `NotifyServiceOptions`, `ThemeServiceOptions`, `ThemeService`, `WebrtcServiceOptions`, `WebrtcServiceContext`.
379
453
 
380
454
  ## API Reference
381
455
 
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { ServiceHandler, Signer } from '@kehto/runtime';
2
- import { NostrFilter, NostrEvent, EventTemplate } from '@napplet/core';
2
+ import { IdentityGetProfileMessage, IdentityGetProfileResultMessage, IdentityGetFollowsMessage, IdentityGetFollowsResultMessage, IdentityGetListMessage, IdentityGetListResultMessage, IdentityGetZapsMessage, IdentityGetZapsResultMessage, IdentityGetMutesMessage, IdentityGetMutesResultMessage, IdentityGetBlockedMessage, IdentityGetBlockedResultMessage, IdentityGetBadgesMessage, IdentityGetBadgesResultMessage } from '@napplet/nap/identity/types';
3
+ import { NostrFilter, NostrEvent, EventTemplate, LinkOpenOptions, LinkOpenResult, ListSupport, ListRef, ListItem, ListOptions, ListMutationResult, SerialOpenRequest, SerialOpenResult, BleOpenRequest, BleOpenResult, BleService, BleAttribute, BleWriteOptions, WebrtcEvent, WebrtcOpenRequest, WebrtcOpenResult, CommonProfileTarget, CommonProfileResult, CommonFollowsResult, CommonActionResult, CommonReaction, CommonReportTarget, CommonReportReason } from '@napplet/core';
3
4
  import { MediaMetadata, MediaAction } from '@napplet/nap/media/types';
4
5
  export { MediaAction } from '@napplet/nap/media/types';
5
6
  import { NotifySendMessage } from '@napplet/nap/notify/types';
@@ -189,11 +190,12 @@ declare function createNotificationService(options?: NotificationServiceOptions)
189
190
  *
190
191
  * Handles 9 identity.* request types from @napplet/nap/identity. getPublicKey
191
192
  * and getRelays return real values sourced from hooks.auth.getSigner(); the
192
- * remaining 7 (getProfile/getFollows/getList/getZaps/getMutes/getBlocked/
193
- * getBadges) are stub-level. Host apps plug real backends via
194
- * runtime.registerService('identity', realHandler).
193
+ * remaining read-only queries can be backed by optional host providers. When a
194
+ * provider is absent, the service keeps returning spec-shaped empty results.
195
195
  */
196
196
 
197
+ /** A value that may be returned synchronously or through a Promise. */
198
+ type MaybePromise<T> = T | Promise<T>;
197
199
  /**
198
200
  * Options for creating the identity service.
199
201
  *
@@ -212,14 +214,75 @@ interface IdentityServiceOptions {
212
214
  * availability can change dynamically.
213
215
  */
214
216
  getSigner: () => Signer | null;
217
+ /**
218
+ * Optional host-backed profile lookup for the current user.
219
+ *
220
+ * Kehto does not query relays itself; hosts that already maintain kind-0
221
+ * metadata can provide it here without replacing the whole identity service.
222
+ *
223
+ * @param pubkey - Current signer pubkey, or "" when no signer is connected.
224
+ * @param message - Original identity.getProfile request envelope.
225
+ * @returns Profile metadata, or null when unavailable.
226
+ */
227
+ getProfile?: (pubkey: string, message: IdentityGetProfileMessage) => MaybePromise<IdentityGetProfileResultMessage['profile']>;
228
+ /**
229
+ * Optional host-backed follow-list lookup for the current user.
230
+ *
231
+ * @param pubkey - Current signer pubkey, or "" when no signer is connected.
232
+ * @param message - Original identity.getFollows request envelope.
233
+ * @returns Hex-encoded followed pubkeys.
234
+ */
235
+ getFollows?: (pubkey: string, message: IdentityGetFollowsMessage) => MaybePromise<IdentityGetFollowsResultMessage['pubkeys']>;
236
+ /**
237
+ * Optional host-backed categorized-list lookup for the current user.
238
+ *
239
+ * @param listType - Requested list category from the wire envelope.
240
+ * @param pubkey - Current signer pubkey, or "" when no signer is connected.
241
+ * @param message - Original identity.getList request envelope.
242
+ * @returns List entries.
243
+ */
244
+ getList?: (listType: string, pubkey: string, message: IdentityGetListMessage) => MaybePromise<IdentityGetListResultMessage['entries']>;
245
+ /**
246
+ * Optional host-backed zap receipt lookup for the current user.
247
+ *
248
+ * @param pubkey - Current signer pubkey, or "" when no signer is connected.
249
+ * @param message - Original identity.getZaps request envelope.
250
+ * @returns Zap receipts.
251
+ */
252
+ getZaps?: (pubkey: string, message: IdentityGetZapsMessage) => MaybePromise<IdentityGetZapsResultMessage['zaps']>;
253
+ /**
254
+ * Optional host-backed mute-list lookup for the current user.
255
+ *
256
+ * @param pubkey - Current signer pubkey, or "" when no signer is connected.
257
+ * @param message - Original identity.getMutes request envelope.
258
+ * @returns Hex-encoded muted pubkeys.
259
+ */
260
+ getMutes?: (pubkey: string, message: IdentityGetMutesMessage) => MaybePromise<IdentityGetMutesResultMessage['pubkeys']>;
261
+ /**
262
+ * Optional host-backed block-list lookup for the current user.
263
+ *
264
+ * @param pubkey - Current signer pubkey, or "" when no signer is connected.
265
+ * @param message - Original identity.getBlocked request envelope.
266
+ * @returns Hex-encoded blocked pubkeys.
267
+ */
268
+ getBlocked?: (pubkey: string, message: IdentityGetBlockedMessage) => MaybePromise<IdentityGetBlockedResultMessage['pubkeys']>;
269
+ /**
270
+ * Optional host-backed badge lookup for the current user.
271
+ *
272
+ * @param pubkey - Current signer pubkey, or "" when no signer is connected.
273
+ * @param message - Original identity.getBadges request envelope.
274
+ * @returns Badges awarded to the user.
275
+ */
276
+ getBadges?: (pubkey: string, message: IdentityGetBadgesMessage) => MaybePromise<IdentityGetBadgesResultMessage['badges']>;
215
277
  }
216
278
  /**
217
279
  * Create an identity service that handles NIP-5D identity.* envelope messages.
218
280
  *
219
281
  * Supports the 9 read-only identity.* request types from @napplet/nap/identity.
220
282
  * The two nostr-info queries (getPublicKey, getRelays) resolve through the
221
- * caller-supplied signer; the remaining 7 return default/empty payloads with
222
- * spec-correct envelope shapes so napplets always receive a result envelope.
283
+ * caller-supplied signer; the remaining read-only queries resolve through
284
+ * optional host providers or return default/empty payloads with spec-correct
285
+ * envelope shapes so napplets always receive a result envelope.
223
286
  *
224
287
  * @param options - Identity service configuration (getSigner)
225
288
  * @returns A ServiceHandler ready for runtime.registerService('identity', handler)
@@ -1343,11 +1406,12 @@ declare function createConfigService(options: ConfigServiceOptions): ConfigServi
1343
1406
  *
1344
1407
  * Shell-side reference implementation for the canonical NAP-RESOURCE wire
1345
1408
  * protocol (`internal-resource.ts` in @kehto/shell/src/types; kehto-internal
1346
- * model per PROJECT.md Decision #31 — diverges from upstream `@napplet/nap/
1347
- * resource` in field names + error vocabulary). Handles the canonical
1348
- * 4-message protocol:
1349
- * Inbound: resource.bytes, resource.cancel
1350
- * Outbound: resource.bytes.result, resource.bytes.error
1409
+ * model per PROJECT.md Decision #31. Kehto keeps legacy single-fetch fields
1410
+ * for existing callers and also emits the current NAP-RESOURCE fields.
1411
+ * Handles:
1412
+ * Inbound: resource.bytes, resource.bytesMany, resource.cancel
1413
+ * Outbound: resource.bytes.result, resource.bytes.error,
1414
+ * resource.bytesMany.result, resource.bytesMany.error
1351
1415
  *
1352
1416
  * ──────────────────────── SCOPE BOUNDARY (RESOURCE-01) ────────────────────────
1353
1417
  * NAP-RESOURCE is an **authenticated fetch proxy** — read-only, atomic.
@@ -1454,10 +1518,8 @@ type ResourceService = ServiceHandler;
1454
1518
  /**
1455
1519
  * Create a NAP-RESOURCE reference service.
1456
1520
  *
1457
- * Implements canonical 4-message protocol: `resource.bytes` (napplet → shell
1458
- * fetch request), `resource.cancel` (napplet → shell in-flight cancellation),
1459
- * `resource.bytes.result` (shell → napplet success), `resource.bytes.error`
1460
- * (shell → napplet failure/denial/cancel).
1521
+ * Implements the NAP-RESOURCE request/response protocol: `resource.bytes`,
1522
+ * `resource.bytesMany`, `resource.cancel`, and their result/error envelopes.
1461
1523
  *
1462
1524
  * On-construction guard (H-03 prevention): all four options are validated at
1463
1525
  * factory call time. If any is missing, the factory throws immediately with a
@@ -2338,4 +2400,222 @@ interface ManifestArchetypeInput {
2338
2400
  */
2339
2401
  declare function manifestToIntentCatalogEntry(manifest: ManifestArchetypeInput): IntentCatalogEntry;
2340
2402
 
2341
- export { type AudioServiceOptions, type AudioSource, type CacheServiceOptions, type CatalogIntentResolver, type CatalogIntentResolverOptions, type ConfigSchemaValidation, type ConfigService, type ConfigServiceOptions, type CoordinatedRelayOptions, type HostCacheBridge, type HostKeyEvent, type HostKeysBridge, type HostMediaBridge, type HttpUploaderOptions, type HttpUploaderRails, type IdentityServiceOptions, type IntentArchetypeSupport, type IntentAvailability, type IntentBehavior, type IntentCandidate, type IntentCatalogEntry, type IntentHandlerPreference, type IntentOpenParams, type IntentRequest, type IntentResolver, type IntentResolverContext, type IntentResult, type IntentServiceOptions, type IntentWindowController, type KeysServiceOptions, type ManifestArchetypeInput, type MediaMetadataLike, type MediaPlaybackOwner, type MediaServiceOptions, type MediaSessionCreateOptions, type MediaSessionTarget, type MediaSourceRef, type NostrTag, type Notification, type NotificationServiceOptions, type NotifyServiceOptions, type OutboxPublishOptions, type OutboxPublishResult, type OutboxQueryOptions, type OutboxRelayPlan, type OutboxRelayPool, type OutboxResult, type OutboxRouter, type OutboxRouterSubscription, type OutboxServiceOptions, type OutboxStrategy, type OutboxSubscribeOptions, type OutboxSubscriptionSink, type OutboxTarget, type RailServerConfig, type RelayListEntry, type RelayPoolOutboxRouterOptions, type RelayPoolServiceOptions, type ResourceService, type ResourceServiceOptions, type SignEvent, type ThemeService, type ThemeServiceOptions, type UploadDimensions, type UploadRail, type UploadRequest, type UploadResult, type UploadServiceOptions, type UploadState, type UploadStatus, type Uploader, type UploaderContext, createAudioService, createBrowserMediaBridge, createCacheService, createCatalogIntentResolver, createConfigService, createCoordinatedRelay, createHttpUploader, createIdentityService, createIntentService, createKeysService, createMediaService, createNotificationService, createNotifyService, createOutboxService, createRelayPoolOutboxRouter, createRelayPoolService, createResourceService, createThemeService, createUploadService, manifestToIntentCatalogEntry };
2403
+ /**
2404
+ * link-service.ts — NAP-LINK reference service.
2405
+ *
2406
+ * Shell-mediated user-visible navigation. The napplet requests `link.open`;
2407
+ * the shell validates policy and hands navigation to a host-owned context.
2408
+ */
2409
+
2410
+ /**
2411
+ * Host context passed to {@link LinkServiceOptions.open}.
2412
+ */
2413
+ interface LinkOpenContext {
2414
+ /** Window id of the requesting napplet. */
2415
+ windowId: string;
2416
+ /** Parsed absolute URL after validation. */
2417
+ url: URL;
2418
+ /** Optional untrusted napplet display hints. */
2419
+ options?: LinkOpenOptions;
2420
+ }
2421
+ /**
2422
+ * Options for {@link createLinkService}.
2423
+ */
2424
+ interface LinkServiceOptions {
2425
+ /**
2426
+ * Protocols allowed before host policy runs. Defaults to `http:` and `https:`.
2427
+ */
2428
+ allowedProtocols?: readonly string[];
2429
+ /**
2430
+ * Host-owned opener. Return `{ status: "opened" }` after handing navigation
2431
+ * to the host context, or `{ status: "denied" }` to reject by policy/user.
2432
+ * When omitted, all otherwise-valid URLs are denied.
2433
+ */
2434
+ open?: (context: LinkOpenContext) => LinkOpenResult | Promise<LinkOpenResult>;
2435
+ }
2436
+ /**
2437
+ * Create the NAP-LINK reference service.
2438
+ *
2439
+ * @param options - Host policy and opener hooks for link.open requests.
2440
+ * @returns A runtime service handler for the `link` domain.
2441
+ *
2442
+ * @example
2443
+ * ```ts
2444
+ * const service = createLinkService({
2445
+ * open: ({ url }) => ({ status: url.protocol === 'https:' ? 'opened' : 'denied' }),
2446
+ * });
2447
+ * ```
2448
+ */
2449
+ declare function createLinkService(options?: LinkServiceOptions): ServiceHandler;
2450
+
2451
+ /**
2452
+ * lists-service.ts — NAP-LISTS reference service.
2453
+ *
2454
+ * Shell-mediated NIP-51 list metadata and mutation hooks. The napplet requests
2455
+ * `lists.*`; the shell owns list lookup, validation, signing, publishing, and
2456
+ * private-item policy.
2457
+ */
2458
+
2459
+ /** Context passed to host-provided NAP-LISTS hooks. */
2460
+ interface ListsServiceContext {
2461
+ /** Window id of the requesting napplet. */
2462
+ windowId: string;
2463
+ }
2464
+ /** Options for {@link createListsService}. */
2465
+ interface ListsServiceOptions {
2466
+ /** Host-owned supported list metadata. */
2467
+ supported?: (context: ListsServiceContext) => readonly ListSupport[] | Promise<readonly ListSupport[]>;
2468
+ /** Host-owned add mutation. */
2469
+ add?: (list: ListRef, items: readonly ListItem[], options: ListOptions | undefined, context: ListsServiceContext) => ListMutationResult | Promise<ListMutationResult>;
2470
+ /** Host-owned remove mutation. */
2471
+ remove?: (list: ListRef, items: readonly ListItem[], options: ListOptions | undefined, context: ListsServiceContext) => ListMutationResult | Promise<ListMutationResult>;
2472
+ }
2473
+ /**
2474
+ * Create the NAP-LISTS reference service.
2475
+ *
2476
+ * @param options - Host list metadata and mutation hooks for lists.* requests.
2477
+ * @returns A runtime service handler for the `lists` domain.
2478
+ */
2479
+ declare function createListsService(options?: ListsServiceOptions): ServiceHandler;
2480
+
2481
+ /**
2482
+ * serial-service.ts — NAP-SERIAL reference service.
2483
+ *
2484
+ * Shell-mediated serial sessions. The napplet requests `serial.*`; the shell
2485
+ * owns device selection, permissions, session handles, reads, write ordering,
2486
+ * close events, and policy.
2487
+ */
2488
+
2489
+ /** Context passed to host-provided NAP-SERIAL hooks. */
2490
+ interface SerialServiceContext {
2491
+ /** Window id of the requesting napplet. */
2492
+ windowId: string;
2493
+ }
2494
+ /** Options for {@link createSerialService}. */
2495
+ interface SerialServiceOptions {
2496
+ /** Host-owned serial open hook. */
2497
+ open?: (request: SerialOpenRequest, context: SerialServiceContext) => SerialOpenResult | Promise<SerialOpenResult>;
2498
+ /** Host-owned serial write hook. */
2499
+ write?: (sessionId: string, data: readonly number[], context: SerialServiceContext) => void | Promise<void>;
2500
+ /** Host-owned serial close hook. */
2501
+ close?: (sessionId: string, reason: string | undefined, context: SerialServiceContext) => void | Promise<void>;
2502
+ /** Optional host cleanup when a napplet window is destroyed. */
2503
+ destroyWindow?: (windowId: string) => void;
2504
+ }
2505
+ /**
2506
+ * Create the NAP-SERIAL reference service.
2507
+ *
2508
+ * @param options - Host serial session hooks for serial.* requests.
2509
+ * @returns A runtime service handler for the `serial` domain.
2510
+ */
2511
+ declare function createSerialService(options?: SerialServiceOptions): ServiceHandler;
2512
+
2513
+ /**
2514
+ * ble-service.ts — NAP-BLE reference service.
2515
+ *
2516
+ * Shell-mediated BLE/GATT sessions. The napplet requests `ble.*`; the shell
2517
+ * owns chooser UI, permissions, GATT handles, notifications, and policy.
2518
+ */
2519
+
2520
+ /** Context passed to host-provided NAP-BLE hooks. */
2521
+ interface BleServiceContext {
2522
+ /** Window id of the requesting napplet. */
2523
+ windowId: string;
2524
+ }
2525
+ /** Options for {@link createBleService}. */
2526
+ interface BleServiceOptions {
2527
+ /** Host-owned BLE open hook. */
2528
+ open?: (request: BleOpenRequest, context: BleServiceContext) => BleOpenResult | Promise<BleOpenResult>;
2529
+ /** Host-owned GATT service listing hook. */
2530
+ services?: (sessionId: string, context: BleServiceContext) => BleService[] | Promise<BleService[]>;
2531
+ /** Host-owned GATT read hook. */
2532
+ read?: (sessionId: string, target: BleAttribute, context: BleServiceContext) => number[] | Promise<number[]>;
2533
+ /** Host-owned GATT write hook. */
2534
+ write?: (sessionId: string, target: BleAttribute, data: readonly number[], options: BleWriteOptions | undefined, context: BleServiceContext) => void | Promise<void>;
2535
+ /** Host-owned notification subscription hook. */
2536
+ subscribe?: (sessionId: string, target: BleAttribute, context: BleServiceContext) => void | Promise<void>;
2537
+ /** Host-owned notification unsubscribe hook. */
2538
+ unsubscribe?: (sessionId: string, target: BleAttribute, context: BleServiceContext) => void | Promise<void>;
2539
+ /** Host-owned BLE close hook. */
2540
+ close?: (sessionId: string, reason: string | undefined, context: BleServiceContext) => void | Promise<void>;
2541
+ /** Optional host cleanup when a napplet window is destroyed. */
2542
+ destroyWindow?: (windowId: string) => void;
2543
+ }
2544
+ /**
2545
+ * Create the NAP-BLE reference service.
2546
+ *
2547
+ * @param options - Host BLE session hooks for ble.* requests.
2548
+ * @returns A runtime service handler for the `ble` domain.
2549
+ */
2550
+ declare function createBleService(options?: BleServiceOptions): ServiceHandler;
2551
+
2552
+ /**
2553
+ * webrtc-service.ts — NAP-WEBRTC reference service.
2554
+ *
2555
+ * Shell-mediated WebRTC sessions. The napplet requests `webrtc.*`; the shell
2556
+ * owns signaling, signing/encryption, SDP, ICE, peer connections, and policy.
2557
+ */
2558
+
2559
+ /** Context passed to host-provided NAP-WEBRTC hooks. */
2560
+ interface WebrtcServiceContext {
2561
+ /** Window id of the requesting napplet. */
2562
+ windowId: string;
2563
+ /** Emit a runtime-owned WebRTC event back to the requesting napplet. */
2564
+ emit(event: WebrtcEvent): void;
2565
+ }
2566
+ /** Options for {@link createWebrtcService}. */
2567
+ interface WebrtcServiceOptions {
2568
+ /** Host-owned WebRTC open hook. */
2569
+ open?: (request: WebrtcOpenRequest, context: WebrtcServiceContext) => WebrtcOpenResult | Promise<WebrtcOpenResult>;
2570
+ /** Host-owned WebRTC send hook. */
2571
+ send?: (sessionId: string, payload: unknown, context: WebrtcServiceContext) => void | Promise<void>;
2572
+ /** Host-owned WebRTC close hook. */
2573
+ close?: (sessionId: string, reason: string | undefined, context: WebrtcServiceContext) => void | Promise<void>;
2574
+ /** Optional host cleanup when a napplet window is destroyed. */
2575
+ destroyWindow?: (windowId: string) => void;
2576
+ }
2577
+ /**
2578
+ * Create the NAP-WEBRTC reference service.
2579
+ *
2580
+ * @param options - Host WebRTC session hooks for webrtc.* requests.
2581
+ * @returns A runtime service handler for the `webrtc` domain.
2582
+ */
2583
+ declare function createWebrtcService(options?: WebrtcServiceOptions): ServiceHandler;
2584
+
2585
+ /**
2586
+ * common-service.ts — NAP-COMMON reference service.
2587
+ *
2588
+ * Shell-mediated public NIP-19 helpers and common social actions. The napplet
2589
+ * requests `common.*`; the shell owns identity, consent, event construction,
2590
+ * signing, publishing, relay access, and NIP-19 handling.
2591
+ */
2592
+
2593
+ /** Context passed to host-provided NAP-COMMON hooks. */
2594
+ interface CommonServiceContext {
2595
+ /** Window id of the requesting napplet. */
2596
+ windowId: string;
2597
+ }
2598
+ /** Options for {@link createCommonService}. */
2599
+ interface CommonServiceOptions {
2600
+ /** Host-owned profile lookup. */
2601
+ getProfile?: (target: CommonProfileTarget, context: CommonServiceContext) => CommonProfileResult | Promise<CommonProfileResult>;
2602
+ /** Host-owned current-user follows lookup. */
2603
+ follows?: (context: CommonServiceContext) => CommonFollowsResult | Promise<CommonFollowsResult>;
2604
+ /** Host-owned follow action. */
2605
+ follow?: (pubkeys: string[], context: CommonServiceContext) => CommonActionResult | Promise<CommonActionResult>;
2606
+ /** Host-owned unfollow action. */
2607
+ unfollow?: (pubkeys: string[], context: CommonServiceContext) => CommonActionResult | Promise<CommonActionResult>;
2608
+ /** Host-owned reaction action. */
2609
+ react?: (targetEventId: string, reaction: CommonReaction, customEmojiHref: string | undefined, context: CommonServiceContext) => CommonActionResult | Promise<CommonActionResult>;
2610
+ /** Host-owned report action. */
2611
+ report?: (target: CommonReportTarget, reason: CommonReportReason, text: string, context: CommonServiceContext) => CommonActionResult | Promise<CommonActionResult>;
2612
+ }
2613
+ /**
2614
+ * Create the NAP-COMMON reference service.
2615
+ *
2616
+ * @param options - Host profile/social hooks for common.* requests.
2617
+ * @returns A runtime service handler for the `common` domain.
2618
+ */
2619
+ declare function createCommonService(options?: CommonServiceOptions): ServiceHandler;
2620
+
2621
+ export { type AudioServiceOptions, type AudioSource, type BleServiceContext, type BleServiceOptions, type CacheServiceOptions, type CatalogIntentResolver, type CatalogIntentResolverOptions, type CommonServiceContext, type CommonServiceOptions, type ConfigSchemaValidation, type ConfigService, type ConfigServiceOptions, type CoordinatedRelayOptions, type HostCacheBridge, type HostKeyEvent, type HostKeysBridge, type HostMediaBridge, type HttpUploaderOptions, type HttpUploaderRails, type IdentityServiceOptions, type IntentArchetypeSupport, type IntentAvailability, type IntentBehavior, type IntentCandidate, type IntentCatalogEntry, type IntentHandlerPreference, type IntentOpenParams, type IntentRequest, type IntentResolver, type IntentResolverContext, type IntentResult, type IntentServiceOptions, type IntentWindowController, type KeysServiceOptions, type LinkOpenContext, type LinkServiceOptions, type ListsServiceContext, type ListsServiceOptions, type ManifestArchetypeInput, type MaybePromise, type MediaMetadataLike, type MediaPlaybackOwner, type MediaServiceOptions, type MediaSessionCreateOptions, type MediaSessionTarget, type MediaSourceRef, type NostrTag, type Notification, type NotificationServiceOptions, type NotifyServiceOptions, type OutboxPublishOptions, type OutboxPublishResult, type OutboxQueryOptions, type OutboxRelayPlan, type OutboxRelayPool, type OutboxResult, type OutboxRouter, type OutboxRouterSubscription, type OutboxServiceOptions, type OutboxStrategy, type OutboxSubscribeOptions, type OutboxSubscriptionSink, type OutboxTarget, type RailServerConfig, type RelayListEntry, type RelayPoolOutboxRouterOptions, type RelayPoolServiceOptions, type ResourceService, type ResourceServiceOptions, type SerialServiceContext, type SerialServiceOptions, type SignEvent, type ThemeService, type ThemeServiceOptions, type UploadDimensions, type UploadRail, type UploadRequest, type UploadResult, type UploadServiceOptions, type UploadState, type UploadStatus, type Uploader, type UploaderContext, type WebrtcServiceContext, type WebrtcServiceOptions, createAudioService, createBleService, createBrowserMediaBridge, createCacheService, createCatalogIntentResolver, createCommonService, createConfigService, createCoordinatedRelay, createHttpUploader, createIdentityService, createIntentService, createKeysService, createLinkService, createListsService, createMediaService, createNotificationService, createNotifyService, createOutboxService, createRelayPoolOutboxRouter, createRelayPoolService, createResourceService, createSerialService, createThemeService, createUploadService, createWebrtcService, manifestToIntentCatalogEntry };