@haibun/core 4.0.0-alpha.2 → 4.0.0-alpha.3
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/build/currentVersion.d.ts +1 -1
- package/build/currentVersion.js +1 -1
- package/build/index.d.ts +1 -1
- package/build/index.d.ts.map +1 -1
- package/build/index.js +1 -1
- package/build/index.js.map +1 -1
- package/build/kireji/converter.d.ts +2 -2
- package/build/kireji/converter.d.ts.map +1 -1
- package/build/kireji/converter.js +12 -9
- package/build/kireji/converter.js.map +1 -1
- package/build/kireji/withAction.d.ts +16 -4
- package/build/kireji/withAction.d.ts.map +1 -1
- package/build/kireji/withAction.js +40 -11
- package/build/kireji/withAction.js.map +1 -1
- package/build/lib/EventLogger.d.ts +5 -5
- package/build/lib/EventLogger.d.ts.map +1 -1
- package/build/lib/EventLogger.js +39 -37
- package/build/lib/EventLogger.js.map +1 -1
- package/build/lib/PhaseRunner.d.ts +3 -3
- package/build/lib/PhaseRunner.d.ts.map +1 -1
- package/build/lib/PhaseRunner.js +7 -5
- package/build/lib/PhaseRunner.js.map +1 -1
- package/build/lib/astepper.d.ts +90 -13
- package/build/lib/astepper.d.ts.map +1 -1
- package/build/lib/astepper.js +35 -6
- package/build/lib/astepper.js.map +1 -1
- package/build/lib/base-prompt-manager.d.ts +1 -1
- package/build/lib/base-prompt-manager.d.ts.map +1 -1
- package/build/lib/base-prompt-manager.js.map +1 -1
- package/build/lib/capture-locator.d.ts +1 -1
- package/build/lib/capture-locator.d.ts.map +1 -1
- package/build/lib/capture-locator.js +5 -5
- package/build/lib/capture-locator.js.map +1 -1
- package/build/lib/core/flow-runner.d.ts +8 -7
- package/build/lib/core/flow-runner.d.ts.map +1 -1
- package/build/lib/core/flow-runner.js +42 -71
- package/build/lib/core/flow-runner.js.map +1 -1
- package/build/lib/core-domains.d.ts +2 -2
- package/build/lib/core-domains.d.ts.map +1 -1
- package/build/lib/core-domains.js +17 -18
- package/build/lib/core-domains.js.map +1 -1
- package/build/lib/defs.d.ts +2 -13
- package/build/lib/defs.d.ts.map +1 -1
- package/build/lib/defs.js.map +1 -1
- package/build/lib/document-content.d.ts +18 -0
- package/build/lib/document-content.d.ts.map +1 -0
- package/build/lib/document-content.js +158 -0
- package/build/lib/document-content.js.map +1 -0
- package/build/lib/domains.d.ts +31 -0
- package/build/lib/domains.d.ts.map +1 -0
- package/build/lib/domains.js +105 -0
- package/build/lib/domains.js.map +1 -0
- package/build/lib/execution.d.ts +304 -0
- package/build/lib/execution.d.ts.map +1 -0
- package/build/lib/execution.js +23 -0
- package/build/lib/execution.js.map +1 -0
- package/build/lib/feature-variables.d.ts +21 -50
- package/build/lib/feature-variables.d.ts.map +1 -1
- package/build/lib/feature-variables.js +122 -232
- package/build/lib/feature-variables.js.map +1 -1
- package/build/lib/features.d.ts +2 -2
- package/build/lib/features.d.ts.map +1 -1
- package/build/lib/features.js +13 -17
- package/build/lib/features.js.map +1 -1
- package/build/lib/fixme.d.ts.map +1 -1
- package/build/lib/host-id.d.ts +44 -0
- package/build/lib/host-id.d.ts.map +1 -0
- package/build/lib/host-id.js +51 -0
- package/build/lib/host-id.js.map +1 -0
- package/build/lib/http-observations.d.ts +15 -2
- package/build/lib/http-observations.d.ts.map +1 -1
- package/build/lib/http-observations.js +40 -23
- package/build/lib/http-observations.js.map +1 -1
- package/build/lib/hypermedia.d.ts +62 -0
- package/build/lib/hypermedia.d.ts.map +1 -0
- package/build/lib/hypermedia.js +228 -0
- package/build/lib/hypermedia.js.map +1 -0
- package/build/lib/namedVars.d.ts +2 -2
- package/build/lib/namedVars.d.ts.map +1 -1
- package/build/lib/namedVars.js +25 -30
- package/build/lib/namedVars.js.map +1 -1
- package/build/lib/node-http-events.d.ts +3 -3
- package/build/lib/node-http-events.d.ts.map +1 -1
- package/build/lib/node-http-events.js +26 -26
- package/build/lib/node-http-events.js.map +1 -1
- package/build/lib/populateActionArgs.d.ts +4 -4
- package/build/lib/populateActionArgs.d.ts.map +1 -1
- package/build/lib/populateActionArgs.js +4 -6
- package/build/lib/populateActionArgs.js.map +1 -1
- package/build/lib/prompter.d.ts.map +1 -1
- package/build/lib/prompter.js +10 -7
- package/build/lib/prompter.js.map +1 -1
- package/build/lib/quad-store.d.ts +34 -10
- package/build/lib/quad-store.d.ts.map +1 -1
- package/build/lib/quad-store.js +169 -21
- package/build/lib/quad-store.js.map +1 -1
- package/build/lib/quad-types.d.ts +80 -9
- package/build/lib/quad-types.d.ts.map +1 -1
- package/build/lib/quad-types.js +46 -2
- package/build/lib/quad-types.js.map +1 -1
- package/build/lib/readline-prompter.d.ts +1 -1
- package/build/lib/readline-prompter.js +4 -4
- package/build/lib/remote-stepper-proxy.d.ts +56 -0
- package/build/lib/remote-stepper-proxy.d.ts.map +1 -0
- package/build/lib/remote-stepper-proxy.js +123 -0
- package/build/lib/remote-stepper-proxy.js.map +1 -0
- package/build/lib/resolver-features.d.ts +1 -1
- package/build/lib/resolver-features.d.ts.map +1 -1
- package/build/lib/resolver-features.js +2 -2
- package/build/lib/resolver-features.js.map +1 -1
- package/build/lib/resources.d.ts +461 -0
- package/build/lib/resources.d.ts.map +1 -0
- package/build/lib/resources.js +249 -0
- package/build/lib/resources.js.map +1 -0
- package/build/lib/rpc-client.d.ts +68 -0
- package/build/lib/rpc-client.d.ts.map +1 -0
- package/build/lib/rpc-client.js +186 -0
- package/build/lib/rpc-client.js.map +1 -0
- package/build/lib/sse-subscriber.d.ts +57 -0
- package/build/lib/sse-subscriber.d.ts.map +1 -0
- package/build/lib/sse-subscriber.js +110 -0
- package/build/lib/sse-subscriber.js.map +1 -0
- package/build/lib/step-dispatch.d.ts +92 -28
- package/build/lib/step-dispatch.d.ts.map +1 -1
- package/build/lib/step-dispatch.js +331 -75
- package/build/lib/step-dispatch.js.map +1 -1
- package/build/lib/step-validation.d.ts +3 -3
- package/build/lib/step-validation.d.ts.map +1 -1
- package/build/lib/step-validation.js +2 -2
- package/build/lib/step-validation.js.map +1 -1
- package/build/lib/stepper-cycles.d.ts +5 -0
- package/build/lib/stepper-cycles.d.ts.map +1 -0
- package/build/lib/stepper-cycles.js +31 -0
- package/build/lib/stepper-cycles.js.map +1 -0
- package/build/lib/stepper-registry.d.ts +6 -3
- package/build/lib/stepper-registry.d.ts.map +1 -1
- package/build/lib/stepper-registry.js +9 -8
- package/build/lib/stepper-registry.js.map +1 -1
- package/build/lib/subprocess-runner.d.ts +35 -0
- package/build/lib/subprocess-runner.d.ts.map +1 -0
- package/build/lib/subprocess-runner.js +60 -0
- package/build/lib/subprocess-runner.js.map +1 -0
- package/build/lib/subprocess-transport.d.ts +37 -0
- package/build/lib/subprocess-transport.d.ts.map +1 -0
- package/build/lib/subprocess-transport.js +113 -0
- package/build/lib/subprocess-transport.js.map +1 -0
- package/build/lib/test/EventCollectorStepper.d.ts +3 -3
- package/build/lib/test/EventCollectorStepper.d.ts.map +1 -1
- package/build/lib/test/EventCollectorStepper.js +3 -3
- package/build/lib/test/EventCollectorStepper.js.map +1 -1
- package/build/lib/test/SetTimeStepper.d.ts +3 -3
- package/build/lib/test/SetTimeStepper.d.ts.map +1 -1
- package/build/lib/test/SetTimeStepper.js +7 -7
- package/build/lib/test/SetTimeStepper.js.map +1 -1
- package/build/lib/test/TestSteps.d.ts +7 -7
- package/build/lib/test/TestSteps.d.ts.map +1 -1
- package/build/lib/test/TestSteps.js +7 -7
- package/build/lib/test/TestSteps.js.map +1 -1
- package/build/lib/test/TestStepsWithOptions.d.ts +6 -6
- package/build/lib/test/TestStepsWithOptions.js +7 -7
- package/build/lib/test/lib.d.ts +3 -3
- package/build/lib/test/lib.d.ts.map +1 -1
- package/build/lib/test/lib.js +27 -21
- package/build/lib/test/lib.js.map +1 -1
- package/build/lib/test/resolvedTestFeatures.d.ts +6 -6
- package/build/lib/test/resolvedTestFeatures.d.ts.map +1 -1
- package/build/lib/test/resolvedTestFeatures.js +5 -5
- package/build/lib/test/subprocess-fixture.d.ts +8 -0
- package/build/lib/test/subprocess-fixture.d.ts.map +1 -0
- package/build/lib/test/subprocess-fixture.js +27 -0
- package/build/lib/test/subprocess-fixture.js.map +1 -0
- package/build/lib/ttag.d.ts +7 -1
- package/build/lib/ttag.d.ts.map +1 -1
- package/build/lib/ttag.js +5 -4
- package/build/lib/ttag.js.map +1 -1
- package/build/lib/util/dot-path.d.ts +2 -2
- package/build/lib/util/dot-path.d.ts.map +1 -1
- package/build/lib/util/dot-path.js +8 -7
- package/build/lib/util/dot-path.js.map +1 -1
- package/build/lib/util/index.d.ts +10 -24
- package/build/lib/util/index.d.ts.map +1 -1
- package/build/lib/util/index.js +43 -93
- package/build/lib/util/index.js.map +1 -1
- package/build/lib/util/node/actualURI.d.ts +4 -0
- package/build/lib/util/node/actualURI.d.ts.map +1 -0
- package/build/lib/util/node/actualURI.js +10 -0
- package/build/lib/util/node/actualURI.js.map +1 -0
- package/build/lib/util/node/module-loader.d.ts +14 -0
- package/build/lib/util/node/module-loader.d.ts.map +1 -0
- package/build/lib/util/node/module-loader.js +51 -0
- package/build/lib/util/node/module-loader.js.map +1 -0
- package/build/lib/util/node/workspace-lib.d.ts +15 -0
- package/build/lib/util/node/workspace-lib.d.ts.map +1 -0
- package/build/lib/util/node/workspace-lib.js +119 -0
- package/build/lib/util/node/workspace-lib.js.map +1 -0
- package/build/lib/util/secret-utils.d.ts.map +1 -1
- package/build/lib/util/secret-utils.js +2 -2
- package/build/lib/util/secret-utils.js.map +1 -1
- package/build/lib/vertex-crud.d.ts +22 -0
- package/build/lib/vertex-crud.d.ts.map +1 -0
- package/build/lib/vertex-crud.js +73 -0
- package/build/lib/vertex-crud.js.map +1 -0
- package/build/lib/workspace-discovery.d.ts +1 -1
- package/build/lib/workspace-discovery.d.ts.map +1 -1
- package/build/lib/workspace-discovery.js +10 -10
- package/build/lib/workspace-discovery.js.map +1 -1
- package/build/lib/zcap-like-authority.d.ts +38 -0
- package/build/lib/zcap-like-authority.d.ts.map +1 -0
- package/build/lib/zcap-like-authority.js +56 -0
- package/build/lib/zcap-like-authority.js.map +1 -0
- package/build/monitor/index.d.ts +1 -1
- package/build/monitor/index.d.ts.map +1 -1
- package/build/monitor/index.js +1 -1
- package/build/monitor/index.js.map +1 -1
- package/build/phases/Executor.d.ts +31 -7
- package/build/phases/Executor.d.ts.map +1 -1
- package/build/phases/Executor.js +201 -219
- package/build/phases/Executor.js.map +1 -1
- package/build/phases/Resolver.d.ts +2 -2
- package/build/phases/Resolver.d.ts.map +1 -1
- package/build/phases/Resolver.js +35 -30
- package/build/phases/Resolver.js.map +1 -1
- package/build/phases/collector.d.ts +3 -3
- package/build/phases/collector.d.ts.map +1 -1
- package/build/phases/collector.js +19 -17
- package/build/phases/collector.js.map +1 -1
- package/build/run-policy/run-policy-schema.d.ts +3 -5
- package/build/run-policy/run-policy-schema.d.ts.map +1 -1
- package/build/run-policy/run-policy-schema.js +41 -37
- package/build/run-policy/run-policy-schema.js.map +1 -1
- package/build/run-policy/run-policy-types.d.ts +1 -1
- package/build/run-policy/run-policy-types.d.ts.map +1 -1
- package/build/run-policy/run-policy-types.js +19 -16
- package/build/run-policy/run-policy-types.js.map +1 -1
- package/build/runner.d.ts +4 -4
- package/build/runner.d.ts.map +1 -1
- package/build/runner.js +15 -13
- package/build/runner.js.map +1 -1
- package/build/schema/protocol.d.ts +153 -61
- package/build/schema/protocol.d.ts.map +1 -1
- package/build/schema/protocol.js +177 -148
- package/build/schema/protocol.js.map +1 -1
- package/build/steps/activities-stepper.d.ts +13 -13
- package/build/steps/activities-stepper.d.ts.map +1 -1
- package/build/steps/activities-stepper.js +105 -79
- package/build/steps/activities-stepper.js.map +1 -1
- package/build/steps/conformance.d.ts +5 -5
- package/build/steps/conformance.js +4 -4
- package/build/steps/console-monitor-stepper.d.ts +2 -2
- package/build/steps/console-monitor-stepper.d.ts.map +1 -1
- package/build/steps/console-monitor-stepper.js +22 -22
- package/build/steps/console-monitor-stepper.js.map +1 -1
- package/build/steps/debugger-stepper.d.ts +11 -11
- package/build/steps/debugger-stepper.d.ts.map +1 -1
- package/build/steps/debugger-stepper.js +65 -64
- package/build/steps/debugger-stepper.js.map +1 -1
- package/build/steps/finalizer-stepper.d.ts +3 -4
- package/build/steps/finalizer-stepper.d.ts.map +1 -1
- package/build/steps/finalizer-stepper.js +16 -19
- package/build/steps/finalizer-stepper.js.map +1 -1
- package/build/steps/haibun.d.ts +27 -20
- package/build/steps/haibun.d.ts.map +1 -1
- package/build/steps/haibun.js +76 -67
- package/build/steps/haibun.js.map +1 -1
- package/build/steps/lib/tts.d.ts +1 -1
- package/build/steps/lib/tts.d.ts.map +1 -1
- package/build/steps/lib/tts.js +28 -28
- package/build/steps/lib/tts.js.map +1 -1
- package/build/steps/logic-stepper.d.ts +5 -5
- package/build/steps/logic-stepper.d.ts.map +1 -1
- package/build/steps/logic-stepper.js +76 -76
- package/build/steps/logic-stepper.js.map +1 -1
- package/build/steps/narrator.d.ts +9 -9
- package/build/steps/narrator.d.ts.map +1 -1
- package/build/steps/narrator.js +32 -28
- package/build/steps/narrator.js.map +1 -1
- package/build/steps/resources-stepper.d.ts +47 -0
- package/build/steps/resources-stepper.d.ts.map +1 -0
- package/build/steps/resources-stepper.js +100 -0
- package/build/steps/resources-stepper.js.map +1 -0
- package/build/steps/variables-stepper.d.ts +57 -57
- package/build/steps/variables-stepper.d.ts.map +1 -1
- package/build/steps/variables-stepper.js +252 -224
- package/build/steps/variables-stepper.js.map +1 -1
- package/build/steps/zcap-like-stepper.d.ts +50 -0
- package/build/steps/zcap-like-stepper.d.ts.map +1 -0
- package/build/steps/zcap-like-stepper.js +113 -0
- package/build/steps/zcap-like-stepper.js.map +1 -0
- package/package.json +1 -1
- package/build/lib/consts.d.ts +0 -5
- package/build/lib/consts.d.ts.map +0 -1
- package/build/lib/consts.js +0 -5
- package/build/lib/consts.js.map +0 -1
- package/build/lib/step-helpers.d.ts +0 -10
- package/build/lib/step-helpers.d.ts.map +0 -1
- package/build/lib/step-helpers.js +0 -16
- package/build/lib/step-helpers.js.map +0 -1
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resources — the vocabulary and topology of things stored in a graph.
|
|
3
|
+
*
|
|
4
|
+
* Answers "what is a graph resource, how is it typed, how does it link, and how is it governed?"
|
|
5
|
+
* Pure declarative data: zod schemas, type aliases, vocabulary consts, and tiny pure derivations.
|
|
6
|
+
* No runtime behavior, no node built-ins — browser-safe.
|
|
7
|
+
*
|
|
8
|
+
* Contents:
|
|
9
|
+
* - Resource identity (id/type), Access levels, Comment vocabulary
|
|
10
|
+
* - LinkRelations + EdgePredicates: semantic labels for properties and edges (ActivityStreams / JSON-LD)
|
|
11
|
+
* - TRel / TPropertyDef / TEdgeDef / TDomainTopology: the shape of a vertex-type declaration
|
|
12
|
+
* - TDomainDefinition / TRegisteredDomain: how steppers register a domain
|
|
13
|
+
* - Helpers: getRel, getMediaType, edgeRel, isReplyEdge
|
|
14
|
+
*
|
|
15
|
+
* Grounded in JSON-LD / ActivityStreams / RDF — vertex label is a local handle, `type` is the
|
|
16
|
+
* RDF class URI that JSON-LD emits, `id` is the IRI.
|
|
17
|
+
*/
|
|
18
|
+
import { z } from "zod";
|
|
19
|
+
// ============================================================================
|
|
20
|
+
// Resource identity
|
|
21
|
+
// ============================================================================
|
|
22
|
+
/**
|
|
23
|
+
* The universal shape of anything identifiable and typed.
|
|
24
|
+
* `id` is the identifier (IRI in JSON-LD emission), `type` is the RDF class
|
|
25
|
+
* (typically a compact IRI like "vc:VerifiableCredential"; mapped to `@type` via JSON-LD context).
|
|
26
|
+
*
|
|
27
|
+
* Field naming follows the W3C VC 2.0 data model (unquoted `id`/`type`); the `@id`/`@type`
|
|
28
|
+
* JSON-LD keywords are produced by the context at serialization time.
|
|
29
|
+
*/
|
|
30
|
+
export const ResourceSchema = z.object({
|
|
31
|
+
id: z.string(),
|
|
32
|
+
type: z.string(),
|
|
33
|
+
});
|
|
34
|
+
/** Root vertex label — any resource. Use as edge range when the target is polymorphic. */
|
|
35
|
+
export const RESOURCE_LABEL = "Resource";
|
|
36
|
+
// ============================================================================
|
|
37
|
+
// Access levels
|
|
38
|
+
// ============================================================================
|
|
39
|
+
/**
|
|
40
|
+
* Visibility policy for stored resources:
|
|
41
|
+
* - private: visible only to the resource's owner.
|
|
42
|
+
* - public: visible to everyone.
|
|
43
|
+
* - opened: previously private, deliberately widened for audit; history preserves the prior state.
|
|
44
|
+
*
|
|
45
|
+
* Query contexts also accept `all` to mean "do not filter by access level"; this is not
|
|
46
|
+
* a storage value, only a query-time relaxation.
|
|
47
|
+
*/
|
|
48
|
+
const ACCESS_LEVELS = ["private", "public", "opened"];
|
|
49
|
+
const ACCESS_QUERY_LEVELS = [...ACCESS_LEVELS, "all"];
|
|
50
|
+
export const AccessLevelSchema = z.enum(ACCESS_LEVELS, {
|
|
51
|
+
message: `accessLevel must be one of ${ACCESS_LEVELS.map((v) => `"${v}"`).join(", ")}`,
|
|
52
|
+
});
|
|
53
|
+
export const Access = AccessLevelSchema.enum;
|
|
54
|
+
export const AccessQueryLevelSchema = z.enum(ACCESS_QUERY_LEVELS, {
|
|
55
|
+
message: `accessLevel (query) must be one of ${ACCESS_QUERY_LEVELS.map((v) => `"${v}"`).join(", ")}`,
|
|
56
|
+
});
|
|
57
|
+
export const AccessQuery = AccessQueryLevelSchema.enum;
|
|
58
|
+
// ============================================================================
|
|
59
|
+
// Comment vocabulary
|
|
60
|
+
// ============================================================================
|
|
61
|
+
/**
|
|
62
|
+
* Free-text annotation attached to any Resource. Threads via IN_REPLY_TO.
|
|
63
|
+
* The commentsOn edge carries rel IN_REPLY_TO and range Resource.
|
|
64
|
+
*
|
|
65
|
+
* Full Zod schema and domain definition live at the bottom of this file,
|
|
66
|
+
* after TDomainDefinition is declared — see `CommentSchema` and
|
|
67
|
+
* `commentDomainDefinition`.
|
|
68
|
+
*/
|
|
69
|
+
export const COMMENT_LABEL = "Comment";
|
|
70
|
+
export const COMMENT_DOMAIN = "comment";
|
|
71
|
+
export const COMMENT_EDGE = "commentsOn";
|
|
72
|
+
/**
|
|
73
|
+
* Discourse — closed set of speech acts a Comment can perform.
|
|
74
|
+
*
|
|
75
|
+
* Every Comment carries a required discourse tag. The set is deliberately
|
|
76
|
+
* small and closed; adding a value is a PR and requires a linked-data
|
|
77
|
+
* mapping note.
|
|
78
|
+
*
|
|
79
|
+
* suggest — schema:SuggestAction; proposing a change
|
|
80
|
+
* measure — narration of a sosa:Observation
|
|
81
|
+
* report — schema:Report / as:Announce
|
|
82
|
+
* narrate — prose narration (no standard mapping)
|
|
83
|
+
* question — schema:Question; asking for clarification
|
|
84
|
+
* apply — narration of a schema:UpdateAction (the Development is the act)
|
|
85
|
+
* revert — narration of a schema:UpdateAction undoing a prior apply
|
|
86
|
+
* play — rehearsal or try-out; prov:Activity with no side effects
|
|
87
|
+
*/
|
|
88
|
+
export const DISCOURSE = {
|
|
89
|
+
suggest: "suggest",
|
|
90
|
+
measure: "measure",
|
|
91
|
+
report: "report",
|
|
92
|
+
narrate: "narrate",
|
|
93
|
+
question: "question",
|
|
94
|
+
apply: "apply",
|
|
95
|
+
revert: "revert",
|
|
96
|
+
play: "play",
|
|
97
|
+
};
|
|
98
|
+
const DISCOURSE_VALUES = Object.values(DISCOURSE);
|
|
99
|
+
export const DiscourseSchema = z.enum(DISCOURSE_VALUES, {
|
|
100
|
+
message: `discourse must be one of ${DISCOURSE_VALUES.map((v) => `"${v}"`).join(", ")}`,
|
|
101
|
+
});
|
|
102
|
+
export const LinkRelations = {
|
|
103
|
+
NAME: { rel: "name", uri: "as:name", range: "literal", relation: false },
|
|
104
|
+
PUBLISHED: { rel: "published", uri: "as:published", range: "literal", relation: false },
|
|
105
|
+
ATTRIBUTED_TO: { rel: "attributedTo", uri: "as:attributedTo", range: "iri", relation: false },
|
|
106
|
+
AUDIENCE: { rel: "audience", uri: "as:to", range: "iri", relation: false },
|
|
107
|
+
CONTEXT: { rel: "context", uri: "as:context", range: "container", relation: false },
|
|
108
|
+
UPDATED: { rel: "updated", uri: "as:updated", range: "literal", relation: false },
|
|
109
|
+
CONTENT: { rel: "content", uri: "as:content", range: "literal", relation: false },
|
|
110
|
+
IN_REPLY_TO: { rel: "inReplyTo", uri: "as:inReplyTo", range: "iri", relation: true },
|
|
111
|
+
ATTACHMENT: { rel: "attachment", uri: "as:attachment", range: "iri", relation: false },
|
|
112
|
+
TAG: { rel: "tag", uri: "as:tag", range: "literal", relation: false },
|
|
113
|
+
IDENTIFIER: { rel: "identifier", uri: "dcterms:identifier", range: "iri", relation: false },
|
|
114
|
+
URL: { rel: "url", uri: "as:url", range: "literal", relation: false },
|
|
115
|
+
// PROV-O — provenance and lineage
|
|
116
|
+
WAS_INFORMED_BY: { rel: "wasInformedBy", uri: "prov:wasInformedBy", range: "iri", relation: true },
|
|
117
|
+
INVALIDATED: { rel: "invalidated", uri: "prov:invalidated", range: "iri", relation: true },
|
|
118
|
+
WAS_ASSOCIATED_WITH: { rel: "wasAssociatedWith", uri: "prov:wasAssociatedWith", range: "iri", relation: false },
|
|
119
|
+
WAS_STARTED_BY: { rel: "wasStartedBy", uri: "prov:wasStartedBy", range: "iri", relation: true },
|
|
120
|
+
STARTED_AT_TIME: { rel: "startedAtTime", uri: "prov:startedAtTime", range: "literal", relation: false },
|
|
121
|
+
// SOSA / W3C SSN — observation and sensing
|
|
122
|
+
PHENOMENON_TIME: { rel: "phenomenonTime", uri: "sosa:phenomenonTime", range: "literal", relation: false },
|
|
123
|
+
RESULT_TIME: { rel: "resultTime", uri: "sosa:resultTime", range: "literal", relation: false },
|
|
124
|
+
HAS_RESULT: { rel: "hasResult", uri: "sosa:hasResult", range: "container", relation: false },
|
|
125
|
+
MADE_BY_SENSOR: { rel: "madeBySensor", uri: "sosa:madeBySensor", range: "iri", relation: true },
|
|
126
|
+
OBSERVED_PROPERTY: { rel: "observedProperty", uri: "sosa:observedProperty", range: "literal", relation: false },
|
|
127
|
+
// schema.org — action outcomes
|
|
128
|
+
SCHEMA_OBJECT: { rel: "schemaObject", uri: "schema:object", range: "literal", relation: false },
|
|
129
|
+
SCHEMA_RESULT: { rel: "schemaResult", uri: "schema:result", range: "literal", relation: false },
|
|
130
|
+
REPLACEE: { rel: "replacee", uri: "schema:replacee", range: "literal", relation: false },
|
|
131
|
+
REPLACEMENT: { rel: "replacement", uri: "schema:replacement", range: "literal", relation: false },
|
|
132
|
+
// Haibun native — no existing vocabulary mapping
|
|
133
|
+
DISCOURSE: { rel: "discourse", uri: "hbn:discourse", range: "literal", relation: false },
|
|
134
|
+
SEQ_PATH: { rel: "seqPath", uri: "hbn:seqPath", range: "literal", relation: false },
|
|
135
|
+
HOST_ID: { rel: "hostId", uri: "hbn:hostId", range: "literal", relation: false },
|
|
136
|
+
ACCESS_LEVEL: { rel: "accessLevel", uri: "hbn:accessLevel", range: "literal", relation: false },
|
|
137
|
+
MEASUREMENT_KIND: { rel: "measurementKind", uri: "hbn:measurementKind", range: "literal", relation: false },
|
|
138
|
+
SHAPE_DIGEST: { rel: "shapeDigest", uri: "hbn:shapeDigest", range: "container", relation: false },
|
|
139
|
+
OUTCOME_REASON: { rel: "outcomeReason", uri: "hbn:outcomeReason", range: "literal", relation: false },
|
|
140
|
+
};
|
|
141
|
+
/** Lookup a rel's RDF range. Returns undefined for unknown rels. */
|
|
142
|
+
export function getRelRange(rel) {
|
|
143
|
+
for (const entry of Object.values(LinkRelations)) {
|
|
144
|
+
if (entry.rel === rel)
|
|
145
|
+
return entry.range;
|
|
146
|
+
}
|
|
147
|
+
return undefined;
|
|
148
|
+
}
|
|
149
|
+
/** JSON-LD context mapping: rel → standard URI. Derived from LinkRelations. */
|
|
150
|
+
export const REL_CONTEXT = Object.fromEntries(Object.values(LinkRelations).map(({ rel, uri }) => [rel, uri]));
|
|
151
|
+
/**
|
|
152
|
+
* Standard edge predicates for graph vertices.
|
|
153
|
+
* Each carries its LinkRelation rel — the single source of truth for predicate→rel resolution.
|
|
154
|
+
* Steppers use these as edge keys in getConcerns().edges and in createEdge() calls.
|
|
155
|
+
*/
|
|
156
|
+
export const EdgePredicates = {
|
|
157
|
+
from: { rel: LinkRelations.ATTRIBUTED_TO.rel },
|
|
158
|
+
to: { rel: LinkRelations.AUDIENCE.rel },
|
|
159
|
+
cc: { rel: LinkRelations.AUDIENCE.rel },
|
|
160
|
+
author: { rel: LinkRelations.ATTRIBUTED_TO.rel },
|
|
161
|
+
attachment: { rel: LinkRelations.ATTACHMENT.rel },
|
|
162
|
+
inReplyTo: { rel: LinkRelations.IN_REPLY_TO.rel },
|
|
163
|
+
references: { rel: LinkRelations.CONTEXT.rel },
|
|
164
|
+
commentsOn: { rel: LinkRelations.IN_REPLY_TO.rel },
|
|
165
|
+
endpoint: { rel: LinkRelations.URL.rel },
|
|
166
|
+
wasInformedBy: { rel: LinkRelations.WAS_INFORMED_BY.rel },
|
|
167
|
+
invalidated: { rel: LinkRelations.INVALIDATED.rel },
|
|
168
|
+
madeBySensor: { rel: LinkRelations.MADE_BY_SENSOR.rel },
|
|
169
|
+
};
|
|
170
|
+
/** Edge predicate name strings — use `EDGE.from` instead of `"from"`. */
|
|
171
|
+
export const EDGE = Object.fromEntries(Object.keys(EdgePredicates).map((k) => [k, k]));
|
|
172
|
+
/** Resolve a predicate name to its rel. */
|
|
173
|
+
export function edgeRel(predicate) {
|
|
174
|
+
return EdgePredicates[predicate]?.rel;
|
|
175
|
+
}
|
|
176
|
+
/** Rel values that are reply-type (derived from LinkRelations entries with relation: true). */
|
|
177
|
+
const relationRels = new Set(Object.values(LinkRelations)
|
|
178
|
+
.filter((lr) => lr.relation)
|
|
179
|
+
.map((lr) => lr.rel));
|
|
180
|
+
/** Check if a rel value is a reply-type (conversational/threading link). */
|
|
181
|
+
function isRelationRel(rel) {
|
|
182
|
+
return relationRels.has(rel);
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Check if an edge type (predicate name or rel) is a reply-type link.
|
|
186
|
+
* Resolves predicate names via EdgePredicates, then checks the rel.
|
|
187
|
+
*/
|
|
188
|
+
export function isReplyEdge(edgeType) {
|
|
189
|
+
if (isRelationRel(edgeType))
|
|
190
|
+
return true;
|
|
191
|
+
const rel = edgeRel(edgeType);
|
|
192
|
+
return rel ? isRelationRel(rel) : false;
|
|
193
|
+
}
|
|
194
|
+
/** Get the rel for a property definition. */
|
|
195
|
+
export function getRel(def) {
|
|
196
|
+
return typeof def === "string" ? def : def.rel;
|
|
197
|
+
}
|
|
198
|
+
/** Get the mediaType for a content property, if any. */
|
|
199
|
+
export function getMediaType(def) {
|
|
200
|
+
return typeof def === "string" ? undefined : def.mediaType;
|
|
201
|
+
}
|
|
202
|
+
/** Domain name for type labels — auto-populated from registered domains with topology. */
|
|
203
|
+
export const DOMAIN_VERTEX_LABEL = "vertex-label";
|
|
204
|
+
// ============================================================================
|
|
205
|
+
// Comment schema + domain definition
|
|
206
|
+
// ============================================================================
|
|
207
|
+
/**
|
|
208
|
+
* Comment — free-text annotation attached to any Resource. See COMMENT_LABEL /
|
|
209
|
+
* COMMENT_DOMAIN / COMMENT_EDGE near the top of this file for the vocabulary
|
|
210
|
+
* consts.
|
|
211
|
+
*
|
|
212
|
+
* `discourse` tags the speech act (suggest, measure, report, narrate,
|
|
213
|
+
* question, apply, revert, play). Closed enum in ./discourse.ts.
|
|
214
|
+
*
|
|
215
|
+
* `author` stays an optional URI string at the storage layer (e.g.
|
|
216
|
+
* "user:alice", "stepper:llm", "llm:gpt-x"). Legacy data may lack it.
|
|
217
|
+
* Structured-Actor hydration is a query-time projection, not storage.
|
|
218
|
+
*/
|
|
219
|
+
export const CommentSchema = z.object({
|
|
220
|
+
id: z.string(),
|
|
221
|
+
text: z.string(),
|
|
222
|
+
author: z.string().optional(),
|
|
223
|
+
discourse: DiscourseSchema,
|
|
224
|
+
timestamp: z.string(),
|
|
225
|
+
});
|
|
226
|
+
/**
|
|
227
|
+
* Comment domain definition — register this in a stepper's
|
|
228
|
+
* `getConcerns().domains` to expose Comment as a first-class graph vertex.
|
|
229
|
+
* Topology uses existing LinkRelations for every property; no new rels
|
|
230
|
+
* introduced here.
|
|
231
|
+
*/
|
|
232
|
+
export const commentDomainDefinition = {
|
|
233
|
+
selectors: [COMMENT_DOMAIN],
|
|
234
|
+
schema: CommentSchema,
|
|
235
|
+
description: "Comment",
|
|
236
|
+
topology: {
|
|
237
|
+
vertexLabel: COMMENT_LABEL,
|
|
238
|
+
id: "id",
|
|
239
|
+
properties: {
|
|
240
|
+
id: LinkRelations.IDENTIFIER.rel,
|
|
241
|
+
text: { rel: LinkRelations.CONTENT.rel, mediaType: "text/markdown" },
|
|
242
|
+
author: LinkRelations.ATTRIBUTED_TO.rel,
|
|
243
|
+
discourse: LinkRelations.DISCOURSE.rel,
|
|
244
|
+
timestamp: LinkRelations.PUBLISHED.rel,
|
|
245
|
+
},
|
|
246
|
+
edges: { [COMMENT_EDGE]: { rel: LinkRelations.IN_REPLY_TO.rel, range: RESOURCE_LABEL } },
|
|
247
|
+
},
|
|
248
|
+
};
|
|
249
|
+
//# sourceMappingURL=resources.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resources.js","sourceRoot":"","sources":["../../src/lib/resources.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,+EAA+E;AAC/E,oBAAoB;AACpB,+EAA+E;AAE/E;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,CAAC,MAAM,CAAC;IACtC,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE;IACd,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE;CAChB,CAAC,CAAC;AAGH,0FAA0F;AAC1F,MAAM,CAAC,MAAM,cAAc,GAAG,UAAU,CAAC;AAEzC,+EAA+E;AAC/E,gBAAgB;AAChB,+EAA+E;AAE/E;;;;;;;;GAQG;AACH,MAAM,aAAa,GAAG,CAAC,SAAS,EAAE,QAAQ,EAAE,QAAQ,CAAU,CAAC;AAC/D,MAAM,mBAAmB,GAAG,C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C,CAAC,MAAM,EAAE;IAChB,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC7B,SAAS,EAAE,eAAe;IAC1B,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE;CACrB,CAAC,CAAC;AAIH;;;;;GAKG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAsB;IACzD,SAAS,EAAE,CAAC,cAAc,CAAC;IAC3B,MAAM,EAAE,aAAa;IACrB,WAAW,EAAE,SAAS;IACtB,QAAQ,EAAE;QACT,WAAW,EAAE,aAAa;QAC1B,EAAE,EAAE,IAAI;QACR,UAAU,EAAE;YACX,EAAE,EAAE,aAAa,CAAC,UAAU,CAAC,GAAG;YAChC,IAAI,EAAE,EAAE,GAAG,EAAE,aAAa,CAAC,OAAO,CAAC,GAAG,EAAE,SAAS,EAAE,eAAe,EAAE;YACpE,MAAM,EAAE,aAAa,CAAC,aAAa,CAAC,GAAG;YACvC,SAAS,EAAE,aAAa,CAAC,SAAS,CAAC,GAAG;YACtC,SAAS,EAAE,aAAa,CAAC,SAAS,CAAC,GAAG;SACtC;QACD,KAAK,EAAE,EAAE,CAAC,YAAY,CAAC,EAAE,EAAE,GAAG,EAAE,aAAa,CAAC,WAAW,CAAC,GAAG,EAAE,KAAK,EAAE,cAAc,EAAE,EAAE;KACxF;CACD,CAAC"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* rpc-client — capability-scoped client for a haibun host's RPC
|
|
3
|
+
* transport (modules/web-server-hono/sse-transport.ts).
|
|
4
|
+
*
|
|
5
|
+
* Centralises Bearer-token auth, seqPath threading, timeout, retry
|
|
6
|
+
* with backoff, and streaming-NDJSON parsing. Callers that already
|
|
7
|
+
* have a seqPath (feature-step context) pass it; external callers
|
|
8
|
+
* may pass `[]` and the server synthesises a seqPath rooted on its
|
|
9
|
+
* own hostId, matching the MCP dispatch path.
|
|
10
|
+
*/
|
|
11
|
+
export type RpcClientConfig = {
|
|
12
|
+
/** Base URL of the main host (e.g. "http://localhost:8223"). */
|
|
13
|
+
baseUrl: string;
|
|
14
|
+
/** Bearer token granting the caller's scoped capabilities on the target host. */
|
|
15
|
+
capabilityToken?: string;
|
|
16
|
+
/** Per-call timeout in ms before abort. Default 30_000. */
|
|
17
|
+
timeoutMs?: number;
|
|
18
|
+
/** Retry policy. */
|
|
19
|
+
retry?: {
|
|
20
|
+
maxAttempts?: number;
|
|
21
|
+
baseDelayMs?: number;
|
|
22
|
+
};
|
|
23
|
+
/** Injected for tests. Defaults to global fetch. */
|
|
24
|
+
fetchImpl?: typeof fetch;
|
|
25
|
+
};
|
|
26
|
+
export type RpcCallOptions = {
|
|
27
|
+
/** Abort signal from the caller. Fires in addition to the per-call timeout. */
|
|
28
|
+
signal?: AbortSignal;
|
|
29
|
+
};
|
|
30
|
+
export type RpcError = {
|
|
31
|
+
error: string;
|
|
32
|
+
[k: string]: unknown;
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Every RPC call must thread the caller's seqPath so observations on
|
|
36
|
+
* the target host link back to the invoking context (no synthetic
|
|
37
|
+
* `[0, N]` roots). Callers supply either their current feature-step's
|
|
38
|
+
* seqPath or the seqPath of the observation they are acting on.
|
|
39
|
+
*/
|
|
40
|
+
export declare class RpcClient {
|
|
41
|
+
private readonly baseUrl;
|
|
42
|
+
private readonly capabilityToken?;
|
|
43
|
+
private readonly timeoutMs;
|
|
44
|
+
private readonly maxAttempts;
|
|
45
|
+
private readonly baseDelayMs;
|
|
46
|
+
private readonly fetchImpl;
|
|
47
|
+
constructor(config: RpcClientConfig);
|
|
48
|
+
/**
|
|
49
|
+
* Blocking JSON-RPC call. Returns parsed JSON on success; an RpcError
|
|
50
|
+
* object (with string `error` field) on HTTP or application error.
|
|
51
|
+
*/
|
|
52
|
+
call<T = unknown>(method: string, params: Record<string, unknown>, seqPath: number[], opts?: RpcCallOptions): Promise<T | RpcError>;
|
|
53
|
+
/**
|
|
54
|
+
* Streaming JSON-RPC call. Yields chunks as they arrive over NDJSON
|
|
55
|
+
* (one JSON object per line). Completes when the stream closes.
|
|
56
|
+
* Consumers may `break` early; the underlying connection is aborted.
|
|
57
|
+
*/
|
|
58
|
+
stream<TChunk = unknown>(method: string, params: Record<string, unknown>, seqPath: number[], opts?: RpcCallOptions): AsyncGenerator<TChunk, void, unknown>;
|
|
59
|
+
private buildHeaders;
|
|
60
|
+
/**
|
|
61
|
+
* Retry `operation` with exponential backoff + jitter. Returns the
|
|
62
|
+
* last error as an RpcError when `maxAttempts` is exhausted. Retries
|
|
63
|
+
* on fetch network errors; does NOT retry on application errors
|
|
64
|
+
* (RpcError with `error` string) — those are the server's answer.
|
|
65
|
+
*/
|
|
66
|
+
private withRetry;
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=rpc-client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rpc-client.d.ts","sourceRoot":"","sources":["../../src/lib/rpc-client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,MAAM,MAAM,eAAe,GAAG;IAC7B,gEAAgE;IAChE,OAAO,EAAE,MAAM,CAAC;IAChB,iFAAiF;IACjF,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,2DAA2D;IAC3D,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,oBAAoB;IACpB,KAAK,CAAC,EAAE;QACP,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,WAAW,CAAC,EAAE,MAAM,CAAC;KACrB,CAAC;IACF,oDAAoD;IACpD,SAAS,CAAC,EAAE,OAAO,KAAK,CAAC;CACzB,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG;IAC5B,+EAA+E;IAC/E,MAAM,CAAC,EAAE,WAAW,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,QAAQ,GAAG;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAAA;CAAE,CAAC;AAE/D;;;;;GAKG;AACH,qBAAa,SAAS;IACrB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAC,CAAS;IAC1C,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;IACnC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAS;IACrC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAS;IACrC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAe;gBAE7B,MAAM,EAAE,eAAe;IASnC;;;OAGG;IACH,IAAI,CAAC,CAAC,GAAG,OAAO,EACf,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC/B,OAAO,EAAE,MAAM,EAAE,EACjB,IAAI,GAAE,cAAmB,GACvB,OAAO,CAAC,CAAC,GAAG,QAAQ,CAAC;IAmBxB;;;;OAIG;IACI,MAAM,CAAC,MAAM,GAAG,OAAO,EAC7B,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC/B,OAAO,EAAE,MAAM,EAAE,EACjB,IAAI,GAAE,cAAmB,GACvB,cAAc,CAAC,MAAM,EAAE,IAAI,EAAE,OAAO,CAAC;IA4BxC,OAAO,CAAC,YAAY;IAMpB;;;;;OAKG;YACW,SAAS;CAiCvB"}
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* rpc-client — capability-scoped client for a haibun host's RPC
|
|
3
|
+
* transport (modules/web-server-hono/sse-transport.ts).
|
|
4
|
+
*
|
|
5
|
+
* Centralises Bearer-token auth, seqPath threading, timeout, retry
|
|
6
|
+
* with backoff, and streaming-NDJSON parsing. Callers that already
|
|
7
|
+
* have a seqPath (feature-step context) pass it; external callers
|
|
8
|
+
* may pass `[]` and the server synthesises a seqPath rooted on its
|
|
9
|
+
* own hostId, matching the MCP dispatch path.
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* Every RPC call must thread the caller's seqPath so observations on
|
|
13
|
+
* the target host link back to the invoking context (no synthetic
|
|
14
|
+
* `[0, N]` roots). Callers supply either their current feature-step's
|
|
15
|
+
* seqPath or the seqPath of the observation they are acting on.
|
|
16
|
+
*/
|
|
17
|
+
export class RpcClient {
|
|
18
|
+
baseUrl;
|
|
19
|
+
capabilityToken;
|
|
20
|
+
timeoutMs;
|
|
21
|
+
maxAttempts;
|
|
22
|
+
baseDelayMs;
|
|
23
|
+
fetchImpl;
|
|
24
|
+
constructor(config) {
|
|
25
|
+
this.baseUrl = config.baseUrl.replace(/\/+$/, "");
|
|
26
|
+
this.capabilityToken = config.capabilityToken;
|
|
27
|
+
this.timeoutMs = config.timeoutMs ?? 30_000;
|
|
28
|
+
this.maxAttempts = config.retry?.maxAttempts ?? 3;
|
|
29
|
+
this.baseDelayMs = config.retry?.baseDelayMs ?? 250;
|
|
30
|
+
this.fetchImpl = config.fetchImpl ?? ((...args) => fetch(...args));
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Blocking JSON-RPC call. Returns parsed JSON on success; an RpcError
|
|
34
|
+
* object (with string `error` field) on HTTP or application error.
|
|
35
|
+
*/
|
|
36
|
+
call(method, params, seqPath, opts = {}) {
|
|
37
|
+
return this.withRetry(async (signal) => {
|
|
38
|
+
const url = `${this.baseUrl}/rpc/${encodeURIComponent(method)}`;
|
|
39
|
+
const res = await this.fetchImpl(url, {
|
|
40
|
+
method: "POST",
|
|
41
|
+
headers: this.buildHeaders(),
|
|
42
|
+
body: JSON.stringify({ jsonrpc: "2.0", id: `rpc-${Date.now()}`, method, params, seqPath }),
|
|
43
|
+
signal,
|
|
44
|
+
});
|
|
45
|
+
const body = (await res.json());
|
|
46
|
+
if (!res.ok) {
|
|
47
|
+
// 422 = application error with a body we want to surface intact.
|
|
48
|
+
if (typeof body.error === "string")
|
|
49
|
+
return body;
|
|
50
|
+
return { error: `HTTP ${res.status}` };
|
|
51
|
+
}
|
|
52
|
+
return body;
|
|
53
|
+
}, opts.signal);
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Streaming JSON-RPC call. Yields chunks as they arrive over NDJSON
|
|
57
|
+
* (one JSON object per line). Completes when the stream closes.
|
|
58
|
+
* Consumers may `break` early; the underlying connection is aborted.
|
|
59
|
+
*/
|
|
60
|
+
async *stream(method, params, seqPath, opts = {}) {
|
|
61
|
+
const controller = new AbortController();
|
|
62
|
+
if (opts.signal) {
|
|
63
|
+
if (opts.signal.aborted)
|
|
64
|
+
controller.abort();
|
|
65
|
+
else
|
|
66
|
+
opts.signal.addEventListener("abort", () => controller.abort(), { once: true });
|
|
67
|
+
}
|
|
68
|
+
const timeoutHandle = setTimeout(() => controller.abort(), this.timeoutMs);
|
|
69
|
+
try {
|
|
70
|
+
const url = `${this.baseUrl}/rpc/${encodeURIComponent(method)}`;
|
|
71
|
+
const res = await this.fetchImpl(url, {
|
|
72
|
+
method: "POST",
|
|
73
|
+
headers: this.buildHeaders(),
|
|
74
|
+
body: JSON.stringify({ jsonrpc: "2.0", id: `rpc-stream-${Date.now()}`, method, params, seqPath, stream: true }),
|
|
75
|
+
signal: controller.signal,
|
|
76
|
+
});
|
|
77
|
+
if (!res.ok || !res.body) {
|
|
78
|
+
const text = res.body ? await res.text().catch(() => "") : "";
|
|
79
|
+
throw new Error(`stream ${method}: HTTP ${res.status}${text ? ` — ${text}` : ""}`);
|
|
80
|
+
}
|
|
81
|
+
yield* readNdjson(res.body);
|
|
82
|
+
}
|
|
83
|
+
finally {
|
|
84
|
+
clearTimeout(timeoutHandle);
|
|
85
|
+
// If the consumer didn't already abort, do so now to ensure
|
|
86
|
+
// no dangling connection — this is a no-op if already closed.
|
|
87
|
+
controller.abort();
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
buildHeaders() {
|
|
91
|
+
const h = { "Content-Type": "application/json" };
|
|
92
|
+
if (this.capabilityToken)
|
|
93
|
+
h.Authorization = `Bearer ${this.capabilityToken}`;
|
|
94
|
+
return h;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Retry `operation` with exponential backoff + jitter. Returns the
|
|
98
|
+
* last error as an RpcError when `maxAttempts` is exhausted. Retries
|
|
99
|
+
* on fetch network errors; does NOT retry on application errors
|
|
100
|
+
* (RpcError with `error` string) — those are the server's answer.
|
|
101
|
+
*/
|
|
102
|
+
async withRetry(operation, outerSignal) {
|
|
103
|
+
let lastErr;
|
|
104
|
+
for (let attempt = 0; attempt < this.maxAttempts; attempt++) {
|
|
105
|
+
const controller = new AbortController();
|
|
106
|
+
const abortFromOuter = () => controller.abort();
|
|
107
|
+
if (outerSignal) {
|
|
108
|
+
if (outerSignal.aborted) {
|
|
109
|
+
controller.abort();
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
outerSignal.addEventListener("abort", abortFromOuter, { once: true });
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
const timeout = setTimeout(() => controller.abort(), this.timeoutMs);
|
|
116
|
+
try {
|
|
117
|
+
return await operation(controller.signal);
|
|
118
|
+
}
|
|
119
|
+
catch (err) {
|
|
120
|
+
lastErr = err;
|
|
121
|
+
if (outerSignal?.aborted)
|
|
122
|
+
throw err;
|
|
123
|
+
}
|
|
124
|
+
finally {
|
|
125
|
+
clearTimeout(timeout);
|
|
126
|
+
outerSignal?.removeEventListener("abort", abortFromOuter);
|
|
127
|
+
}
|
|
128
|
+
if (attempt + 1 < this.maxAttempts) {
|
|
129
|
+
const backoff = this.baseDelayMs * 2 ** attempt;
|
|
130
|
+
const jitter = Math.floor(Math.random() * this.baseDelayMs);
|
|
131
|
+
await new Promise((r) => setTimeout(r, backoff + jitter));
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
return { error: `rpc failed after ${this.maxAttempts} attempts: ${lastErr instanceof Error ? lastErr.message : String(lastErr)}` };
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Parse an NDJSON response body — one JSON object per line. Tolerates
|
|
139
|
+
* partial lines across chunks. Stops on stream end.
|
|
140
|
+
*/
|
|
141
|
+
async function* readNdjson(body) {
|
|
142
|
+
const reader = body.getReader();
|
|
143
|
+
const decoder = new TextDecoder();
|
|
144
|
+
let buffer = "";
|
|
145
|
+
try {
|
|
146
|
+
while (true) {
|
|
147
|
+
const { done, value } = await reader.read();
|
|
148
|
+
if (done)
|
|
149
|
+
break;
|
|
150
|
+
buffer += decoder.decode(value, { stream: true });
|
|
151
|
+
let idx = buffer.indexOf("\n");
|
|
152
|
+
while (idx !== -1) {
|
|
153
|
+
const line = buffer.slice(0, idx).trim();
|
|
154
|
+
buffer = buffer.slice(idx + 1);
|
|
155
|
+
if (line.length > 0) {
|
|
156
|
+
try {
|
|
157
|
+
yield JSON.parse(line);
|
|
158
|
+
}
|
|
159
|
+
catch {
|
|
160
|
+
// Malformed chunk — skip rather than crash the stream.
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
idx = buffer.indexOf("\n");
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
// Flush any remaining buffered content (final line without trailing newline).
|
|
167
|
+
const tail = buffer.trim();
|
|
168
|
+
if (tail.length > 0) {
|
|
169
|
+
try {
|
|
170
|
+
yield JSON.parse(tail);
|
|
171
|
+
}
|
|
172
|
+
catch {
|
|
173
|
+
/* ignore trailing malformed content */
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
finally {
|
|
178
|
+
try {
|
|
179
|
+
await reader.cancel();
|
|
180
|
+
}
|
|
181
|
+
catch {
|
|
182
|
+
/* reader already closed */
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
//# sourceMappingURL=rpc-client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rpc-client.js","sourceRoot":"","sources":["../../src/lib/rpc-client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAyBH;;;;;GAKG;AACH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5B,CAAC;QACF,CAAC;QACD,8EAA8E;QAC9E,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,EAAE,CAAC;QAC3B,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACrB,IAAI,CAAC;gBACJ,MAAM,IAAI,CAAC,KAAK,CAAC,IAAI,CAAM,CAAC;YAC7B,CAAC;YAAC,MAAM,CAAC;gBACR,uCAAuC;YACxC,CAAC;QACF,CAAC;IACF,CAAC;YAAS,CAAC;QACV,IAAI,CAAC;YACJ,MAAM,MAAM,CAAC,MAAM,EAAE,CAAC;QACvB,CAAC;QAAC,MAAM,CAAC;YACR,2BAA2B;QAC5B,CAAC;IACF,CAAC;AACF,CAAC"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* sse-subscriber — EventSource client shared by every consumer of a
|
|
3
|
+
* haibun host's /sse event stream.
|
|
4
|
+
*
|
|
5
|
+
* Browser SPAs connect to their own origin's /sse; Node-side peers
|
|
6
|
+
* connect to another host's /sse. Both need the same primitives: open,
|
|
7
|
+
* dispatch parsed events to listeners, reconnect on error with backoff,
|
|
8
|
+
* filter subscriptions, close cleanly. This class centralises that.
|
|
9
|
+
*
|
|
10
|
+
* Transport-agnostic within the EventSource contract: the caller
|
|
11
|
+
* supplies the URL; whether it resolves to the same origin or a
|
|
12
|
+
* remote host is the caller's concern.
|
|
13
|
+
*
|
|
14
|
+
* The SSE message format this subscriber decodes is the one
|
|
15
|
+
* web-server-hono's SSETransport emits: each `message` event's
|
|
16
|
+
* `data` field is a JSON envelope with `{ type, event, ... }` or a
|
|
17
|
+
* plain event payload. Payloads that don't parse as JSON are passed
|
|
18
|
+
* through verbatim so callers can handle wire-format variants.
|
|
19
|
+
*/
|
|
20
|
+
type EventHandler = (event: Record<string, unknown>) => void;
|
|
21
|
+
type EventFilter = (event: Record<string, unknown>) => boolean;
|
|
22
|
+
type EventSourceCtor = new (url: string) => any;
|
|
23
|
+
export type SseSubscriberConfig = {
|
|
24
|
+
/** Full URL of the SSE endpoint — absolute for remote hosts, relative for same-origin. */
|
|
25
|
+
url: string;
|
|
26
|
+
/** Reconnect delay on error, in ms. Default 2000. */
|
|
27
|
+
reconnectDelayMs?: number;
|
|
28
|
+
/**
|
|
29
|
+
* Override the EventSource constructor. Defaults to globalThis.EventSource.
|
|
30
|
+
* Tests inject a mock; Node consumers can pass undici's or a polyfill.
|
|
31
|
+
*/
|
|
32
|
+
EventSourceCtor?: EventSourceCtor;
|
|
33
|
+
/** Short tag included in log lines to distinguish multiple subscribers. */
|
|
34
|
+
clientId?: string;
|
|
35
|
+
};
|
|
36
|
+
export declare class SseSubscriber {
|
|
37
|
+
private readonly url;
|
|
38
|
+
private readonly reconnectDelayMs;
|
|
39
|
+
private readonly EventSourceCtor;
|
|
40
|
+
private readonly clientId;
|
|
41
|
+
private source;
|
|
42
|
+
private reconnectTimer;
|
|
43
|
+
private readonly listeners;
|
|
44
|
+
private closed;
|
|
45
|
+
constructor(config: SseSubscriberConfig);
|
|
46
|
+
/** Open the stream. Subsequent subscribe/close calls operate on this connection. Idempotent. */
|
|
47
|
+
connect(): void;
|
|
48
|
+
/** Register a listener. Returns an unsubscribe function. */
|
|
49
|
+
subscribe(handler: EventHandler, filter?: EventFilter): () => void;
|
|
50
|
+
/** Tag for log correlation. */
|
|
51
|
+
get id(): string;
|
|
52
|
+
/** Close the connection and stop reconnecting. */
|
|
53
|
+
close(): void;
|
|
54
|
+
private dispatch;
|
|
55
|
+
}
|
|
56
|
+
export {};
|
|
57
|
+
//# sourceMappingURL=sse-subscriber.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sse-subscriber.d.ts","sourceRoot":"","sources":["../../src/lib/sse-subscriber.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,KAAK,YAAY,GAAG,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,IAAI,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