@stitchwire/client 0.0.0-stage → 0.31.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 (78) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +296 -2
  3. package/dist/chunk-d3248e3w.js +728 -0
  4. package/dist/chunk-mva06nh4.js +709 -0
  5. package/dist/contracts.d.ts +1 -0
  6. package/dist/contracts.js +84 -0
  7. package/dist/enrollment.d.ts +1 -0
  8. package/dist/enrollment.js +503 -0
  9. package/dist/index.d.ts +1 -0
  10. package/dist/index.js +1680 -0
  11. package/dist/types/client/src/contracts.d.ts +1 -0
  12. package/dist/types/client/src/enrollment.d.ts +11 -0
  13. package/dist/types/client/src/index.d.ts +1 -0
  14. package/dist/types/contracts/src/door/client-error.d.ts +20 -0
  15. package/dist/types/contracts/src/door/common.d.ts +3 -0
  16. package/dist/types/contracts/src/door/event-lifecycle.d.ts +22 -0
  17. package/dist/types/contracts/src/door/local-contract.d.ts +466 -0
  18. package/dist/types/contracts/src/door/paths.d.ts +17 -0
  19. package/dist/types/contracts/src/door/request-bounds.d.ts +4 -0
  20. package/dist/types/contracts/src/door/requests.d.ts +47 -0
  21. package/dist/types/contracts/src/door/results.d.ts +319 -0
  22. package/dist/types/contracts/src/door/status.d.ts +859 -0
  23. package/dist/types/contracts/src/door/streams.d.ts +226 -0
  24. package/dist/types/contracts/src/enrollment/fleet-admission.d.ts +413 -0
  25. package/dist/types/contracts/src/enrollment/outcome.d.ts +29 -0
  26. package/dist/types/contracts/src/enrollment/request.d.ts +281 -0
  27. package/dist/types/contracts/src/enrollment/result.d.ts +713 -0
  28. package/dist/types/contracts/src/fleet/bundle.d.ts +209 -0
  29. package/dist/types/contracts/src/fleet/identity.d.ts +4 -0
  30. package/dist/types/contracts/src/fleet/manifest.d.ts +71 -0
  31. package/dist/types/contracts/src/fleet/status.d.ts +56 -0
  32. package/dist/types/contracts/src/peer-contract.d.ts +78 -0
  33. package/dist/types/contracts/src/protocol/bounds.d.ts +37 -0
  34. package/dist/types/contracts/src/protocol/broker-health.d.ts +384 -0
  35. package/dist/types/contracts/src/protocol/event.d.ts +222 -0
  36. package/dist/types/contracts/src/protocol/failure.d.ts +146 -0
  37. package/dist/types/contracts/src/protocol/identity.d.ts +11 -0
  38. package/dist/types/contracts/src/protocol/json-bounds.d.ts +6 -0
  39. package/dist/types/contracts/src/protocol/lane-url.d.ts +16 -0
  40. package/dist/types/contracts/src/protocol/paths.d.ts +7 -0
  41. package/dist/types/contracts/src/protocol/payload.d.ts +25 -0
  42. package/dist/types/contracts/src/protocol/presence.d.ts +66 -0
  43. package/dist/types/contracts/src/protocol/release.d.ts +61 -0
  44. package/dist/types/contracts/src/protocol/result.d.ts +41 -0
  45. package/dist/types/contracts/src/protocol/rpc.d.ts +106 -0
  46. package/dist/types/contracts/src/protocol/schema-parse.d.ts +23 -0
  47. package/dist/types/contracts/src/protocol/stream.d.ts +290 -0
  48. package/dist/types/contracts/src/protocol/topic.d.ts +185 -0
  49. package/dist/types/contracts/src/service/budgets.d.ts +3 -0
  50. package/dist/types/contracts/src/service/contract-descriptor.d.ts +9 -0
  51. package/dist/types/contracts/src/service/contracts.d.ts +430 -0
  52. package/dist/types/contracts/src/service/declaration.d.ts +122 -0
  53. package/dist/types/contracts/src/service/diagnostics.d.ts +104 -0
  54. package/dist/types/contracts/src/service/owner-route-path.d.ts +11 -0
  55. package/dist/types/contracts/src/service/policy-schema.d.ts +154 -0
  56. package/dist/types/contracts/src/service/request-bounds.d.ts +5 -0
  57. package/dist/types/contracts/src/service/service-contract.d.ts +112 -0
  58. package/dist/types/local-client/src/broker-health.d.ts +18 -0
  59. package/dist/types/local-client/src/client.d.ts +377 -0
  60. package/dist/types/local-client/src/contracts.d.ts +112 -0
  61. package/dist/types/local-client/src/declarations.d.ts +57 -0
  62. package/dist/types/local-client/src/door-paths.d.ts +18 -0
  63. package/dist/types/local-client/src/errno.d.ts +6 -0
  64. package/dist/types/local-client/src/error-chain.d.ts +25 -0
  65. package/dist/types/local-client/src/errors.d.ts +39 -0
  66. package/dist/types/local-client/src/event-sequence.d.ts +4 -0
  67. package/dist/types/local-client/src/feed.d.ts +8 -0
  68. package/dist/types/local-client/src/http.d.ts +20 -0
  69. package/dist/types/local-client/src/index.d.ts +13 -0
  70. package/dist/types/local-client/src/ingress.d.ts +31 -0
  71. package/dist/types/local-client/src/operation.d.ts +37 -0
  72. package/dist/types/local-client/src/options.d.ts +18 -0
  73. package/dist/types/local-client/src/paths.d.ts +52 -0
  74. package/dist/types/local-client/src/readers.d.ts +143 -0
  75. package/dist/types/local-client/src/service.d.ts +33 -0
  76. package/dist/types/local-client/src/status-readers.d.ts +756 -0
  77. package/dist/types/local-client/src/unary.d.ts +10 -0
  78. package/package.json +58 -4
@@ -0,0 +1,112 @@
1
+ /**
2
+ * Browser-safe Stitchwire contracts, forward-compatible Zod readers and pure helpers.
3
+ *
4
+ * Imports ONLY `zod` and pure contract modules (no `node:*`, no `stitchkit`, no `process`, no
5
+ * `Buffer`), so browser/Tauri/React/Vite consumers can validate status, broker health, topic
6
+ * descriptors and service declarations without pulling in Node transport dependencies.
7
+ */
8
+ import type { z } from 'zod';
9
+ import { type ClientErrorCode, ClientErrorCodeSchema, type DeliveryCertainty } from '../../contracts/src/door/client-error.ts';
10
+ import { LOCAL_API_VERSION } from '../../contracts/src/door/common.ts';
11
+ import { brokerHealthUrl, type EventLoopDelaySnapshot, type TransportObservationSnapshot } from '../../contracts/src/protocol/broker-health.ts';
12
+ import type { TransportCause } from '../../contracts/src/protocol/failure.ts';
13
+ import { isTopicAuthorized, isTopicInNamespace, MAX_DECLARED_TOPICS, MAX_TOPIC_DESCRIPTOR_FILES, parseTopicDescriptor, TOPIC_MAX_DESCRIPTOR_BYTES, type TopicAccessMode, type TopicAuthorizationGrants, type TopicDescriptor, type TopicDescriptorInput, TopicDescriptorSchema, TopicNamespaceSchema, type TopicProfile, type TopicProfileInput, TopicProfileSchema, TopicRetentionSchema } from '../../contracts/src/protocol/topic.ts';
14
+ import { SERVICE_MAX_DESCRIPTOR_BYTES, SERVICE_MAX_INFLIGHT, SERVICE_MAX_RESPONSE_BYTES, SERVICE_MAX_TIMEOUT_MS, type ServiceCall, type ServiceFailureCode, ServiceFailureCodeSchema, type ServiceOutcome } from '../../contracts/src/service/contracts.ts';
15
+ import { parseServiceDeclaration, SERVICE_MAX_DECLARATION_BYTES, type ServiceDeclaration, type ServiceDeclarationInput, ServiceDeclarationSchema, ServiceNamespaceSchema, serviceInNamespace } from '../../contracts/src/service/declaration.ts';
16
+ import type { ServiceCancellationOrigin, ServiceClientTrace, ServiceDiagnostics, ServicePhase } from '../../contracts/src/service/diagnostics.ts';
17
+ import { type ServiceBinding, ServiceBindingSchema, type ServiceDescriptor, ServiceDescriptorSchema, type ServiceEffect, ServiceEffectSchema, ServiceLimitsSchema } from '../../contracts/src/service/policy-schema.ts';
18
+ import { SERVICE_DEFAULT_REQUEST_BYTES, SERVICE_MAX_REQUEST_BYTES } from '../../contracts/src/service/request-bounds.ts';
19
+ export declare const CallResultSchema: z.ZodObject<{
20
+ refusal: z.ZodEnum<{
21
+ capacity: "capacity";
22
+ none: "none";
23
+ policy: "policy";
24
+ request: "request";
25
+ }>;
26
+ retryAfterMs: z.ZodNullable<z.ZodNumber>;
27
+ transportCause: z.ZodNullable<z.ZodEnum<{
28
+ "acknowledgement-timeout": "acknowledgement-timeout";
29
+ "lane-lost-after-dispatch": "lane-lost-after-dispatch";
30
+ "no-connected-lane": "no-connected-lane";
31
+ "presence-pending-timeout": "presence-pending-timeout";
32
+ "target-offline": "target-offline";
33
+ }>>;
34
+ id: z.ZodUUID;
35
+ ts: z.ZodString;
36
+ from: z.ZodUnion<readonly [z.ZodString, z.ZodLiteral<"broker">]>;
37
+ code: z.ZodNumber;
38
+ stdout: z.ZodString;
39
+ stderr: z.ZodString;
40
+ failure: z.ZodEnum<{
41
+ cancelled: "cancelled";
42
+ denied: "denied";
43
+ exec: "exec";
44
+ none: "none";
45
+ offline: "offline";
46
+ rejected: "rejected";
47
+ timeout: "timeout";
48
+ transport: "transport";
49
+ }>;
50
+ detail: z.ZodString;
51
+ truncated: z.ZodBoolean;
52
+ v: z.ZodLiteral<7>;
53
+ }, z.core.$strip>;
54
+ export declare const PublishResultSchema: z.ZodObject<{
55
+ refusal: z.ZodEnum<{
56
+ capacity: "capacity";
57
+ none: "none";
58
+ policy: "policy";
59
+ request: "request";
60
+ }>;
61
+ retryAfterMs: z.ZodNullable<z.ZodNumber>;
62
+ transportCause: z.ZodNullable<z.ZodEnum<{
63
+ "acknowledgement-timeout": "acknowledgement-timeout";
64
+ "lane-lost-after-dispatch": "lane-lost-after-dispatch";
65
+ "no-connected-lane": "no-connected-lane";
66
+ "presence-pending-timeout": "presence-pending-timeout";
67
+ "target-offline": "target-offline";
68
+ }>>;
69
+ ok: z.ZodBoolean;
70
+ failure: z.ZodEnum<{
71
+ cancelled: "cancelled";
72
+ denied: "denied";
73
+ exec: "exec";
74
+ none: "none";
75
+ offline: "offline";
76
+ rejected: "rejected";
77
+ timeout: "timeout";
78
+ transport: "transport";
79
+ }>;
80
+ detail: z.ZodString;
81
+ }, z.core.$strip>;
82
+ export declare const PeerResultSchema: z.ZodObject<{
83
+ v: z.ZodLiteral<7>;
84
+ observer: z.ZodString;
85
+ target: z.ZodString;
86
+ outcome: z.ZodEnum<{
87
+ capacity: "capacity";
88
+ denied: "denied";
89
+ offline: "offline";
90
+ ok: "ok";
91
+ stale: "stale";
92
+ timeout: "timeout";
93
+ unsupported: "unsupported";
94
+ }>;
95
+ observedAt: z.ZodNullable<z.ZodISODateTime>;
96
+ freshnessMs: z.ZodLiteral<5000>;
97
+ ageMs: z.ZodNullable<z.ZodNumber>;
98
+ aggregationWindowMs: z.ZodLiteral<60000>;
99
+ sampleCount: z.ZodNumber;
100
+ latestMs: z.ZodNullable<z.ZodNumber>;
101
+ medianMs: z.ZodNullable<z.ZodNumber>;
102
+ route: z.ZodNullable<z.ZodObject<{
103
+ id: z.ZodString;
104
+ url: z.ZodString;
105
+ epoch: z.ZodString;
106
+ }, z.core.$strip>>;
107
+ }, z.core.$strip>;
108
+ export { AuditStatusSchema, type AuditStatus, type BrokerHealth, BrokerHealthSchema, FleetConfigStateSchema, type FleetConfigState, FleetEditionStatusSchema, type FleetEditionStatus, FleetNodeStatusSchema, type FleetNodeStatus, LaneStatusSchema, type LaneStatus, type StatusResult, StatusResultSchema, } from './status-readers.ts';
109
+ export type CallResult = z.output<typeof CallResultSchema>;
110
+ export type PublishResult = z.output<typeof PublishResultSchema>;
111
+ export type PeerResult = z.output<typeof PeerResultSchema>;
112
+ export { brokerHealthUrl, ClientErrorCodeSchema, isTopicAuthorized, isTopicInNamespace, LOCAL_API_VERSION, MAX_DECLARED_TOPICS, MAX_TOPIC_DESCRIPTOR_FILES, parseServiceDeclaration, parseTopicDescriptor, SERVICE_DEFAULT_REQUEST_BYTES, SERVICE_MAX_DECLARATION_BYTES, SERVICE_MAX_DESCRIPTOR_BYTES, SERVICE_MAX_INFLIGHT, SERVICE_MAX_REQUEST_BYTES, SERVICE_MAX_RESPONSE_BYTES, SERVICE_MAX_TIMEOUT_MS, ServiceBindingSchema, ServiceDeclarationSchema, ServiceDescriptorSchema, ServiceEffectSchema, ServiceFailureCodeSchema, ServiceLimitsSchema, ServiceNamespaceSchema, serviceInNamespace, TOPIC_MAX_DESCRIPTOR_BYTES, TopicDescriptorSchema, TopicNamespaceSchema, TopicProfileSchema, TopicRetentionSchema, type ClientErrorCode, type DeliveryCertainty, type EventLoopDelaySnapshot, type ServiceBinding, type ServiceCall, type ServiceCancellationOrigin, type ServiceClientTrace, type ServiceDeclaration, type ServiceDeclarationInput, type ServiceDescriptor, type ServiceDiagnostics, type ServiceEffect, type ServiceFailureCode, type ServiceOutcome, type ServicePhase, type TopicAccessMode, type TopicAuthorizationGrants, type TopicDescriptor, type TopicDescriptorInput, type TopicProfile, type TopicProfileInput, type TransportCause, type TransportObservationSnapshot, };
@@ -0,0 +1,57 @@
1
+ import { type Stats } from 'node:fs';
2
+ import { type TopicDescriptorInput } from '../../contracts/src/protocol/topic.ts';
3
+ import { type ServiceDeclarationInput } from '../../contracts/src/service/declaration.ts';
4
+ import { WireClientError } from './errors.ts';
5
+ import { type WireDropInPathOptions } from './paths.ts';
6
+ /** Which rule of the drop-in policy refused a directory or file, and in words. */
7
+ export interface DropInRefusal {
8
+ rule: 'type' | 'owner' | 'mode';
9
+ detail: string;
10
+ }
11
+ /**
12
+ * The one acceptance rule for a drop-in directory and for each file in it, judged on the metadata
13
+ * of the object itself (`lstat` of the directory, `fstat` of the opened file): it must be a real
14
+ * directory or regular file — never a symlink —, owned by the agent's uid, and writable by nobody
15
+ * else. The agent refuses what this refuses; this SDK writes only what it accepts. The writer
16
+ * therefore must run as the same user as the agent. `uid` is the agent's: this process's, unless a
17
+ * caller judges the set for an agent that runs as another user (enrollment, `config validate`).
18
+ */
19
+ export declare function dropInRefusal(info: Pick<Stats, 'uid' | 'mode' | 'isDirectory' | 'isFile'>, kind: 'directory' | 'file', uid?: number | undefined): DropInRefusal | null;
20
+ export interface DeclarationFileOptions extends WireDropInPathOptions {
21
+ /** Absolute target drop-in directory, instead of the one beside `node.json`; a relative one is `invalid-request`. */
22
+ dropInDir?: string;
23
+ }
24
+ export interface DeclarationWriteResult {
25
+ path: string;
26
+ changed: boolean;
27
+ }
28
+ export interface DeclarationRemoveResult {
29
+ path: string;
30
+ removed: boolean;
31
+ }
32
+ /**
33
+ * A filesystem call that failed: `permission` only when the operating system denied access, any
34
+ * other failure (no space, read-only filesystem, I/O error) is the local delivery medium failing,
35
+ * `transport`, with the system error kept as the cause.
36
+ */
37
+ export declare function filesystemFailure(message: string, cause: unknown): WireClientError;
38
+ /**
39
+ * Validate and atomically write a service declaration into the node agent's `services.d/` drop-in
40
+ * directory, without touching `node.json` or restarting the agent. A written file is not yet a loaded
41
+ * declaration: an agent that reads drop-in directories picks it up on its next poll and reports it
42
+ * in `status().services.declarations.descriptors` (by path, with its state). An agent whose
43
+ * `node.json` sets `services.dropInDir` reads only that directory: pass it as `dropInDir`. The writer
44
+ * must run as the agent's user (`dropInRefusal`).
45
+ */
46
+ export declare function writeServiceDeclarationFile(name: string, declaration: ServiceDeclarationInput, options?: DeclarationFileOptions): Promise<DeclarationWriteResult>;
47
+ /** Idempotently remove a service declaration file from `services.d/`. */
48
+ export declare function removeServiceDeclarationFile(name: string, options?: DeclarationFileOptions): Promise<DeclarationRemoveResult>;
49
+ /**
50
+ * Validate and atomically write a topic descriptor into the node agent's `events.d/` drop-in
51
+ * directory, on the same terms as `writeServiceDeclarationFile`: the agent confirms it in
52
+ * `status().events.declarations.descriptors`, `events.dropInDir` in `node.json` must be passed as
53
+ * `dropInDir`, and the writer runs as the agent's user.
54
+ */
55
+ export declare function writeTopicDescriptorFile(name: string, descriptor: TopicDescriptorInput, options?: DeclarationFileOptions): Promise<DeclarationWriteResult>;
56
+ /** Idempotently remove a topic descriptor file from `events.d/`. */
57
+ export declare function removeTopicDescriptorFile(name: string, options?: DeclarationFileOptions): Promise<DeclarationRemoveResult>;
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Every path this SDK can call, composed from the contracts that define them.
3
+ *
4
+ * The contracts live where both sides reach them, so there are no path literals here: a changed
5
+ * prefix moves the client and the door together or not at all.
6
+ */
7
+ export declare const DOOR: {
8
+ readonly call: string;
9
+ readonly status: string;
10
+ readonly peerObservation: string;
11
+ readonly stream: string;
12
+ readonly publish: string;
13
+ readonly subscribe: string;
14
+ readonly invokeService: string;
15
+ };
16
+ export type DoorPath = (typeof DOOR)[keyof typeof DOOR];
17
+ /** The two answers that never end: a bounded stream and a live subscription. */
18
+ export declare const STREAMING_DOOR_PATHS: readonly string[];
@@ -0,0 +1,6 @@
1
+ /**
2
+ * The system error code (`ENOENT`, `EACCES`, …) a failed filesystem or socket call carries, or
3
+ * `undefined` when the value has none. Not a public export: the SDK and the agent judge their own
4
+ * filesystem failures with it, so the two read an error the same way.
5
+ */
6
+ export declare function errnoOf(error: unknown): string | undefined;
@@ -0,0 +1,25 @@
1
+ import type { ClientErrorCode } from '../../contracts/src/door/client-error.ts';
2
+ import type { ServiceFailureCode } from '../../contracts/src/service/contracts.ts';
3
+ import { WireClientError } from './errors.ts';
4
+ import { WireServiceError } from './service.ts';
5
+ /** Locate the outermost `WireServiceError` along the `.cause` chain. */
6
+ export declare function extractWireServiceError(error: unknown, maxDepth?: number): WireServiceError | undefined;
7
+ /** Locate the outermost `WireClientError` along the `.cause` chain. */
8
+ export declare function extractWireClientError(error: unknown, maxDepth?: number): WireClientError | undefined;
9
+ /**
10
+ * A Wire failure code with the side that produced it. The two code spaces overlap (`timeout`,
11
+ * `cancelled`, `unavailable`, `capacity`, ...): `service` is the remote service's or the route's
12
+ * refusal (`WireServiceError`), `client` is this process's local failure (`WireClientError`).
13
+ */
14
+ export type WireErrorCode = {
15
+ source: 'service';
16
+ code: ServiceFailureCode;
17
+ } | {
18
+ source: 'client';
19
+ code: ClientErrorCode;
20
+ };
21
+ /**
22
+ * The code and source of the nearest `WireServiceError` or `WireClientError` along the `.cause`
23
+ * chain (outermost first), or `undefined` when the failure did not originate from Wire.
24
+ */
25
+ export declare function wireErrorCode(error: unknown, maxDepth?: number): WireErrorCode | undefined;
@@ -0,0 +1,39 @@
1
+ import { type ClientErrorCode, ClientErrorCodeSchema, type DeliveryCertainty } from '../../contracts/src/door/client-error.ts';
2
+ import type { ServiceCancellationOrigin } from '../../contracts/src/service/diagnostics.ts';
3
+ export { type ClientErrorCode, ClientErrorCodeSchema, type DeliveryCertainty };
4
+ /** Local failure is not a remote command's exit code or a proof of non-execution. */
5
+ export declare class WireClientError extends Error {
6
+ readonly code: ClientErrorCode;
7
+ readonly delivery: DeliveryCertainty;
8
+ readonly metadata: {
9
+ status?: number;
10
+ actualVersion?: number;
11
+ cause?: unknown;
12
+ traceId?: string;
13
+ cancellationOrigin?: ServiceCancellationOrigin;
14
+ timing?: {
15
+ startedAt: string;
16
+ elapsedMs: number;
17
+ headersMs: number | null;
18
+ timeoutMs: number;
19
+ phase: 'dispatch' | 'headers' | 'body';
20
+ callerAborted: boolean;
21
+ };
22
+ };
23
+ constructor(code: ClientErrorCode, message: string, delivery: DeliveryCertainty, metadata?: {
24
+ status?: number;
25
+ actualVersion?: number;
26
+ cause?: unknown;
27
+ traceId?: string;
28
+ cancellationOrigin?: ServiceCancellationOrigin;
29
+ timing?: {
30
+ startedAt: string;
31
+ elapsedMs: number;
32
+ headersMs: number | null;
33
+ timeoutMs: number;
34
+ phase: 'dispatch' | 'headers' | 'body';
35
+ callerAborted: boolean;
36
+ };
37
+ });
38
+ }
39
+ export declare function localError(error: unknown, delivery: DeliveryCertainty): WireClientError;
@@ -0,0 +1,4 @@
1
+ import type { EventResume } from '../../contracts/src/protocol/event.ts';
2
+ import type { EventItem } from './readers.ts';
3
+ /** One declared producer per topic. Constant state, no payload interpretation or recovery. */
4
+ export declare function eventSequence(topic: string, resume?: EventResume | null): (item: EventItem) => EventItem;
@@ -0,0 +1,8 @@
1
+ import type { ClientSession } from './operation.ts';
2
+ import { type DoorPath } from './http.ts';
3
+ import { z } from 'zod';
4
+ export interface WireFeed<T> extends AsyncIterableIterator<T> {
5
+ close(): void;
6
+ return(): Promise<IteratorResult<T>>;
7
+ }
8
+ export declare function createFeed<T>(session: ClientSession, path: DoorPath, body: unknown, parse: (value: unknown) => T, terminal: z.ZodType, signal?: AbortSignal, durationMs?: number, confirmsOpen?: (item: T) => boolean): WireFeed<T>;
@@ -0,0 +1,20 @@
1
+ import type { ClientSession, Operation } from './operation.ts';
2
+ import { type DoorPath } from './door-paths.ts';
3
+ export type { DoorPath };
4
+ /** True when a request announces, in `content-length`, a body past `maxBytes`: refused before a byte is read. */
5
+ export declare function declaredLengthExceeds(headers: Headers, maxBytes: number): boolean;
6
+ export declare function openDoor(session: ClientSession, operation: Operation, path: DoorPath, body?: unknown, signal?: AbortSignal, traceId?: string): Promise<Response>;
7
+ export declare function checkResponse(response: Response, expected: 'json' | 'ndjson'): void;
8
+ export interface ReadJsonOptions {
9
+ /** What the body is, in a refusal's message; `Wire response` by default. */
10
+ label?: string;
11
+ /** Stops the body read; the read then rejects with `abortError`. */
12
+ signal?: AbortSignal;
13
+ abortError?: (reason: unknown) => unknown;
14
+ }
15
+ /**
16
+ * The one bounded read of a JSON body: a declared length past `limit` is refused before a byte is
17
+ * read, the body is read to at most `limit`, and its bytes must be strict UTF-8 JSON. A lossy decode
18
+ * would let bytes the writer never sent parse as a value, so a bad byte is `invalid-response`.
19
+ */
20
+ export declare function readJson(response: Response, limit: number, options?: ReadJsonOptions): Promise<unknown>;
@@ -0,0 +1,13 @@
1
+ export { serviceDescriptorFromContract } from '../../contracts/src/service/contract-descriptor.ts';
2
+ export { type BrokerHealthFetch, DEFAULT_BROKER_HEALTH_MAX_BYTES, DEFAULT_BROKER_HEALTH_TIMEOUT_MS, readBrokerHealth, type ReadBrokerHealthOptions, } from './broker-health.ts';
3
+ export { type CallRequest, createWireClient, type PeerRequest, type PublishRequest, type ServiceRequestOptions, type StreamRequest, type SubscribeRequest, type WireClient, } from './client.ts';
4
+ export * from './contracts.ts';
5
+ export { type DeclarationFileOptions, type DeclarationRemoveResult, type DeclarationWriteResult, removeServiceDeclarationFile, removeTopicDescriptorFile, writeServiceDeclarationFile, writeTopicDescriptorFile, } from './declarations.ts';
6
+ export { extractWireClientError, extractWireServiceError, type WireErrorCode, wireErrorCode, } from './error-chain.ts';
7
+ export { WireClientError } from './errors.ts';
8
+ export type { WireFeed } from './feed.ts';
9
+ export { createServiceIngress, type ServiceCaller, serviceCaller } from './ingress.ts';
10
+ export type { RequestOptions, WireClientOptions } from './options.ts';
11
+ export { defaultConfigDir, defaultEventDropInDir, defaultNodeConfigPath, defaultServiceDropInDir, defaultStateDir, defaultWireSocketPath, type WireDropInPathOptions, type WirePathOptions, } from './paths.ts';
12
+ export { decodeWireData, type EventFlowItem, type EventItem, type StreamItem, } from './readers.ts';
13
+ export { createServiceFetch, WireServiceError } from './service.ts';
@@ -0,0 +1,31 @@
1
+ import { type ServiceDescriptor } from '../../contracts/src/service/policy-schema.ts';
2
+ /** What the node established about one delivered call; the owner's handler cannot learn it from headers. */
3
+ export interface ServiceCaller {
4
+ readonly caller: string;
5
+ readonly operation: string;
6
+ readonly id: string;
7
+ readonly traceId: string;
8
+ }
9
+ /**
10
+ * The node-authenticated caller of the request an endpoint received from `createServiceIngress`;
11
+ * `undefined` for any other. The parameter is structural so that a Node consumer's declarations do not pull Stitchkit's server types (they need Bun's); `source` is the endpoint context (`authorize`, `beforeHandle`, a handler or `onError`).
12
+ */
13
+ export declare function serviceCaller(source: {
14
+ readonly req?: Request | undefined;
15
+ }): ServiceCaller | undefined;
16
+ /**
17
+ * Turns the node's envelope POST into the owner's own Stitchkit request.
18
+ *
19
+ * The returned fetch handler is the whole door of a service owner: it answers `invalid-request` (400)
20
+ * without calling `handler` for anything the descriptor does not declare, and otherwise calls
21
+ * `handler` with `POST <operation path>` and the payload as its JSON body.
22
+ *
23
+ * `bodyTimeoutMs` bounds only the read of the envelope: a body not complete within it is cancelled and
24
+ * answered `invalid-request` without calling `handler`. It ends when the envelope is read; `handler`, a
25
+ * streamed response and the node's cancellation on `request.signal` are not under it.
26
+ */
27
+ export declare function createServiceIngress(options: {
28
+ descriptor: ServiceDescriptor;
29
+ handler: (request: Request) => Response | Promise<Response>;
30
+ bodyTimeoutMs?: number;
31
+ }): (request: Request) => Promise<Response>;
@@ -0,0 +1,37 @@
1
+ import { type ClientErrorCode, WireClientError } from './errors.ts';
2
+ import { type ResolvedOptions } from './options.ts';
3
+ /**
4
+ * The transport's own wait for unary headers. It is a backstop against a door that never answers,
5
+ * never the deadline: it sits strictly past the longest operation deadline a caller can set, so the
6
+ * caller's deadline always fires first and a call at the boundary ends with one verdict —
7
+ * `timeout` from the caller's deadline — instead of whichever of two equal timers ran first.
8
+ */
9
+ export declare const UNARY_HEADERS_TIMEOUT_MS: number;
10
+ export declare class Operation {
11
+ private readonly release;
12
+ readonly controller: AbortController;
13
+ private timer;
14
+ private external;
15
+ private readonly externalAbort;
16
+ private finished;
17
+ sent: boolean;
18
+ constructor(release: () => void);
19
+ listen(signal?: AbortSignal): void;
20
+ deadline(ms: number): void;
21
+ clearDeadline(): void;
22
+ abort(code: ClientErrorCode): void;
23
+ error(error: unknown): WireClientError;
24
+ finish(): void;
25
+ }
26
+ export declare class ClientSession {
27
+ readonly options: ResolvedOptions;
28
+ private readonly transport;
29
+ private readonly streaming;
30
+ private readonly admission;
31
+ private closed;
32
+ private readonly active;
33
+ constructor(options: ResolvedOptions);
34
+ begin(signal?: AbortSignal): Operation;
35
+ fetch(url: string, init: RequestInit, streaming: boolean): Promise<Response>;
36
+ close(): void;
37
+ }
@@ -0,0 +1,18 @@
1
+ import { z } from 'zod';
2
+ export declare const COMMAND_RESULT_GRACE_MS = 10000;
3
+ /** How long past its declared lifetime a stream may take to deliver its terminal frame. */
4
+ export declare const STREAM_TERMINAL_GRACE_MS = 10000;
5
+ export declare const ClientOptionsSchema: z.ZodObject<{
6
+ socketPath: z.ZodString;
7
+ timeoutMs: z.ZodDefault<z.ZodNumber>;
8
+ openTimeoutMs: z.ZodDefault<z.ZodNumber>;
9
+ maxConcurrentRequests: z.ZodDefault<z.ZodNumber>;
10
+ maxResponseBytes: z.ZodDefault<z.ZodNumber>;
11
+ maxFrameBytes: z.ZodDefault<z.ZodNumber>;
12
+ }, z.core.$strict>;
13
+ export type WireClientOptions = z.input<typeof ClientOptionsSchema>;
14
+ export type ResolvedOptions = z.output<typeof ClientOptionsSchema>;
15
+ export interface RequestOptions {
16
+ signal?: AbortSignal;
17
+ }
18
+ export declare function requestInput<T>(schema: z.ZodType<T>, input: unknown): T;
@@ -0,0 +1,52 @@
1
+ /**
2
+ * The one local layout Stitchwire installs, on macOS and Linux alike: configuration under
3
+ * `<home>/.config/stitchwire`, the agent's door and journals under `<home>/.local/state/stitchwire`.
4
+ * A system unit runs the same layout under its own user's home; there is no second, system-wide one.
5
+ */
6
+ export interface WirePathOptions {
7
+ /** Home directory the layout is rooted in; defaults to `os.homedir()`. */
8
+ homeDir?: string;
9
+ /** Environment map inspected at call time; defaults to `process.env`. */
10
+ env?: Readonly<Record<string, string | undefined>>;
11
+ }
12
+ export interface WireDropInPathOptions extends WirePathOptions {
13
+ /** Explicit absolute path to `node.json`; when supplied, drop-in directories resolve beside it. */
14
+ configPath?: string;
15
+ }
16
+ /** The configuration file whose directory also holds the default drop-in directories. */
17
+ export declare const NODE_CONFIG_FILE = "node.json";
18
+ /**
19
+ * A path named for the agent's layout, which more than one process resolves: it must be absolute,
20
+ * since a relative one would resolve against each process's own working directory — the writer's
21
+ * and the agent's differ. A relative path is a `RangeError` naming `what`.
22
+ */
23
+ export declare function absolutePath(what: string, path: string): string;
24
+ /**
25
+ * A path an operator set in the environment: its value verbatim, or `undefined` when the variable is
26
+ * unset or empty. Empty counts as unset, as in the XDG base-directory convention; nothing is trimmed,
27
+ * and a value that is not an absolute path is refused (`absolutePath`).
28
+ */
29
+ export declare function envPath(name: 'STITCHWIRE_CONFIG_DIR' | 'STITCHWIRE_STATE_DIR' | 'STITCHWIRE_AGENT_SOCKET', env?: Readonly<Record<string, string | undefined>>): string | undefined;
30
+ /** Default directory holding `node.json` and drop-in subdirectories, evaluated at call time. */
31
+ export declare function defaultConfigDir(options?: WirePathOptions): string;
32
+ /** Default directory holding `agent.sock` and the agent's local journals, evaluated at call time. */
33
+ export declare function defaultStateDir(options?: WirePathOptions): string;
34
+ /**
35
+ * Default local Unix door socket path (`agent.sock`), evaluated at call time.
36
+ * Precedence: `STITCHWIRE_AGENT_SOCKET` > `STITCHWIRE_STATE_DIR/agent.sock` > `<home>/.local/state/stitchwire/agent.sock`.
37
+ * An agent whose `node.json` names another `agentSocket` is reached only at that path.
38
+ */
39
+ export declare function defaultWireSocketPath(options?: WirePathOptions): string;
40
+ /** Default `node.json` path, evaluated at call time (`STITCHWIRE_CONFIG_DIR/node.json` > default). */
41
+ export declare function defaultNodeConfigPath(options?: WirePathOptions): string;
42
+ /**
43
+ * The drop-in directory an agent reads by default for the configuration at `configPath`, or
44
+ * `undefined` when that configuration has none. Only a file named `node.json` has default drop-in
45
+ * directories, beside it: two configurations in one directory never share one. An agent started from
46
+ * another file reads drop-in declarations only where its `dropInDir` names them.
47
+ */
48
+ export declare function dropInDirBeside(configPath: string, kind: 'services.d' | 'events.d'): string | undefined;
49
+ /** Default drop-in directory for owner service declarations (`services.d` beside `node.json`). */
50
+ export declare function defaultServiceDropInDir(options?: WireDropInPathOptions): string;
51
+ /** Default drop-in directory for owner topic descriptors (`events.d` beside `node.json`). */
52
+ export declare function defaultEventDropInDir(options?: WireDropInPathOptions): string;
@@ -0,0 +1,143 @@
1
+ import { z } from 'zod';
2
+ import { LocalEventSubscriptionStateSchema } from '../../contracts/src/door/event-lifecycle.ts';
3
+ import { LocalEventErrorSchema, LocalEventFrameSchema, LocalEventGapSchema, LocalStreamChunkSchema, LocalStreamEndSchema, LocalStreamErrorSchema } from '../../contracts/src/door/results.ts';
4
+ import { type CallResult, CallResultSchema, type PeerResult, PeerResultSchema, type PublishResult, PublishResultSchema, type StatusResult, StatusResultSchema } from './contracts.ts';
5
+ export declare const ServiceResultReaderSchema: z.ZodObject<{
6
+ v: z.ZodLiteral<7>;
7
+ traceId: z.ZodOptional<z.ZodUUID>;
8
+ outcome: z.ZodDiscriminatedUnion<[z.ZodObject<{
9
+ status: z.ZodLiteral<"response">;
10
+ delivery: z.ZodLiteral<"received">;
11
+ httpStatus: z.ZodNumber;
12
+ payload: z.ZodString;
13
+ diagnostics: z.ZodOptional<z.ZodObject<{
14
+ traceId: z.ZodUUID;
15
+ requestId: z.ZodUUID;
16
+ phases: z.ZodArray<z.ZodObject<{
17
+ phase: z.ZodEnum<{
18
+ admitted: "admitted";
19
+ "body-end": "body-end";
20
+ "body-start": "body-start";
21
+ "descriptor-end": "descriptor-end";
22
+ "descriptor-start": "descriptor-start";
23
+ "endpoint-end": "endpoint-end";
24
+ "endpoint-start": "endpoint-start";
25
+ "http-headers": "http-headers";
26
+ "http-start": "http-start";
27
+ "target-received": "target-received";
28
+ terminal: "terminal";
29
+ }>;
30
+ elapsedMs: z.ZodNumber;
31
+ }, z.core.$strip>>;
32
+ }, z.core.$strip>>;
33
+ }, z.core.$strip>, z.ZodObject<{
34
+ status: z.ZodLiteral<"failure">;
35
+ code: z.ZodEnum<{
36
+ cancelled: "cancelled";
37
+ capacity: "capacity";
38
+ denied: "denied";
39
+ "invalid-request": "invalid-request";
40
+ "invalid-response": "invalid-response";
41
+ offline: "offline";
42
+ timeout: "timeout";
43
+ unavailable: "unavailable";
44
+ unsupported: "unsupported";
45
+ }>;
46
+ delivery: z.ZodEnum<{
47
+ "not-dispatched": "not-dispatched";
48
+ unknown: "unknown";
49
+ }>;
50
+ retryAfterMs: z.ZodNullable<z.ZodNumber>;
51
+ refusal: z.ZodEnum<{
52
+ capacity: "capacity";
53
+ none: "none";
54
+ policy: "policy";
55
+ request: "request";
56
+ }>;
57
+ detail: z.ZodOptional<z.ZodString>;
58
+ transportCause: z.ZodNullable<z.ZodEnum<{
59
+ "acknowledgement-timeout": "acknowledgement-timeout";
60
+ "lane-lost-after-dispatch": "lane-lost-after-dispatch";
61
+ "no-connected-lane": "no-connected-lane";
62
+ "presence-pending-timeout": "presence-pending-timeout";
63
+ "target-offline": "target-offline";
64
+ }>>;
65
+ cancellationOrigin: z.ZodOptional<z.ZodEnum<{
66
+ "agent-shutdown": "agent-shutdown";
67
+ "broker-deadline": "broker-deadline";
68
+ "broker-shutdown": "broker-shutdown";
69
+ "caller-abort": "caller-abort";
70
+ "caller-deadline": "caller-deadline";
71
+ "caller-disconnect": "caller-disconnect";
72
+ "door-deadline": "door-deadline";
73
+ "door-disconnect": "door-disconnect";
74
+ "executor-deadline": "executor-deadline";
75
+ "lane-disconnect": "lane-disconnect";
76
+ "target-disconnect": "target-disconnect";
77
+ }>>;
78
+ diagnostics: z.ZodOptional<z.ZodObject<{
79
+ traceId: z.ZodUUID;
80
+ requestId: z.ZodUUID;
81
+ phases: z.ZodArray<z.ZodObject<{
82
+ phase: z.ZodEnum<{
83
+ admitted: "admitted";
84
+ "body-end": "body-end";
85
+ "body-start": "body-start";
86
+ "descriptor-end": "descriptor-end";
87
+ "descriptor-start": "descriptor-start";
88
+ "endpoint-end": "endpoint-end";
89
+ "endpoint-start": "endpoint-start";
90
+ "http-headers": "http-headers";
91
+ "http-start": "http-start";
92
+ "target-received": "target-received";
93
+ terminal: "terminal";
94
+ }>;
95
+ elapsedMs: z.ZodNumber;
96
+ }, z.core.$strip>>;
97
+ }, z.core.$strip>>;
98
+ }, z.core.$strip>], "status">;
99
+ }, z.core.$strip>;
100
+ export { type CallResult, CallResultSchema, type PeerResult, PeerResultSchema, type PublishResult, PublishResultSchema, type StatusResult, StatusResultSchema, };
101
+ export declare function readResponse<T>(schema: z.ZodType<T>, value: unknown, versioned?: boolean): T;
102
+ export declare function decodeWireData(frame: {
103
+ data: string;
104
+ bytes: number;
105
+ }): Uint8Array;
106
+ export type StreamItem = {
107
+ kind: 'chunk';
108
+ frame: z.output<typeof LocalStreamChunkSchema>;
109
+ data: Uint8Array;
110
+ } | {
111
+ kind: 'end';
112
+ frame: z.output<typeof LocalStreamEndSchema>;
113
+ } | {
114
+ kind: 'error';
115
+ frame: z.output<typeof LocalStreamErrorSchema>;
116
+ };
117
+ export type EventItem = {
118
+ kind: 'subscription';
119
+ frame: z.output<typeof LocalEventSubscriptionStateSchema>;
120
+ } | {
121
+ kind: 'event';
122
+ frame: z.output<typeof LocalEventFrameSchema>;
123
+ data: Uint8Array;
124
+ } | {
125
+ kind: 'gap';
126
+ frame: z.output<typeof LocalEventGapSchema>;
127
+ } | {
128
+ kind: 'error';
129
+ frame: z.output<typeof LocalEventErrorSchema>;
130
+ };
131
+ /**
132
+ * What a subscription yields when the caller did not ask for `lifecycle` — the topic's own flow.
133
+ *
134
+ * `subscription` frames are opt-in at the request and emitted nowhere else, so a caller who never
135
+ * asked for them cannot receive one; without this type they still had to handle one, and a member
136
+ * added to the full union moved the exhaustive `switch` of every consumer, including those who had
137
+ * opted out of the feature that produced it.
138
+ */
139
+ export type EventFlowItem = Exclude<EventItem, {
140
+ kind: 'subscription';
141
+ }>;
142
+ export declare function readStreamItem(value: unknown): StreamItem;
143
+ export declare function readEventItem(value: unknown): EventItem;
@@ -0,0 +1,33 @@
1
+ import { type ServiceOutcome } from '../../contracts/src/service/contracts.ts';
2
+ import { type ServiceDescriptor } from '../../contracts/src/service/policy-schema.ts';
3
+ import type { WireClient } from './client.ts';
4
+ import { type ServiceClientTrace } from '../../contracts/src/service/diagnostics.ts';
5
+ export declare class WireServiceError extends Error {
6
+ readonly outcome: Extract<ServiceOutcome, {
7
+ status: 'failure';
8
+ }>;
9
+ readonly traceId?: string | undefined;
10
+ constructor(outcome: Extract<ServiceOutcome, {
11
+ status: 'failure';
12
+ }>, traceId?: string | undefined);
13
+ get delivery(): "not-dispatched" | "unknown";
14
+ get transportCause(): "acknowledgement-timeout" | "lane-lost-after-dispatch" | "no-connected-lane" | "presence-pending-timeout" | "target-offline" | null;
15
+ get refusal(): "capacity" | "none" | "policy" | "request";
16
+ get detail(): string | null;
17
+ get cancellationOrigin(): "agent-shutdown" | "broker-deadline" | "broker-shutdown" | "caller-abort" | "caller-deadline" | "caller-disconnect" | "door-deadline" | "door-disconnect" | "executor-deadline" | "lane-disconnect" | "target-disconnect" | undefined;
18
+ get diagnostics(): {
19
+ traceId: string;
20
+ requestId: string;
21
+ phases: {
22
+ phase: "admitted" | "body-end" | "body-start" | "descriptor-end" | "descriptor-start" | "endpoint-end" | "endpoint-start" | "http-headers" | "http-start" | "target-received" | "terminal";
23
+ elapsedMs: number;
24
+ }[];
25
+ } | undefined;
26
+ }
27
+ /** Virtual owner URLs select declared operations; never a network fetch or an endpoint discovery. */
28
+ export declare function createServiceFetch(client: Pick<WireClient, 'invokeService' | 'stream'>, binding: {
29
+ to: string;
30
+ baseUrl: string;
31
+ descriptor: ServiceDescriptor;
32
+ onTrace?: (trace: ServiceClientTrace) => void;
33
+ }): (input: string | Request | URL, init?: RequestInit) => Promise<Response>;