langflower 0.0.8 → 0.0.10
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/package.json +2 -2
- package/ui-dist/{chunk-Y6VMBLSJ.js → chunk-7UMVYN3A.js} +1 -1
- package/ui-dist/{chunk-6DQ2XSRW.js → chunk-MDGXX73Z.js} +3 -3
- package/ui-dist/index.html +2 -2
- package/ui-dist/main-Z7CPFXFA.js +313 -0
- package/ui-dist/styles-2TMDAUD7.css +1 -0
- package/vendor/common-nodes/dist/ai/chat-completion-stream.d.ts +2 -0
- package/vendor/common-nodes/dist/ai/critique/node.d.ts +246 -0
- package/vendor/common-nodes/dist/ai/critique/node.js +2 -2
- package/vendor/common-nodes/dist/ai/fake-llm/node.d.ts +246 -0
- package/vendor/common-nodes/dist/ai/features/chat-completion-stream.d.ts +53 -0
- package/vendor/common-nodes/dist/ai/features/chat-completion-stream.js +1 -0
- package/vendor/common-nodes/dist/ai/features/llm-loop/autokick-recovery.d.ts +13 -0
- package/vendor/common-nodes/dist/ai/features/llm-loop/autokick-recovery.js +17 -0
- package/vendor/common-nodes/dist/ai/features/llm-loop/classify-llm-failure.d.ts +2 -0
- package/vendor/common-nodes/dist/ai/features/llm-loop/classify-llm-failure.js +113 -0
- package/vendor/common-nodes/dist/ai/features/llm-loop/dead-loop-detector.d.ts +28 -0
- package/vendor/common-nodes/dist/ai/features/llm-loop/dead-loop-detector.js +194 -0
- package/vendor/common-nodes/dist/ai/features/llm-loop/live-get-tools.d.ts +9 -0
- package/vendor/common-nodes/dist/ai/features/llm-loop/live-get-tools.js +21 -0
- package/vendor/common-nodes/dist/ai/features/llm-loop/llm-loop-reducer.d.ts +2 -0
- package/vendor/common-nodes/dist/ai/features/llm-loop/llm-loop-reducer.js +204 -0
- package/vendor/common-nodes/dist/ai/features/llm-loop/llm-loop-types.d.ts +120 -0
- package/vendor/common-nodes/dist/ai/features/llm-loop/llm-loop-types.js +39 -0
- package/vendor/common-nodes/dist/ai/features/llm-loop/normalize-llm-recovery-policy.d.ts +2 -0
- package/vendor/common-nodes/dist/ai/features/llm-loop/normalize-llm-recovery-policy.js +59 -0
- package/vendor/common-nodes/dist/ai/features/llm-loop/operators/normalize-tool-result.d.ts +1 -0
- package/vendor/common-nodes/dist/ai/features/llm-loop/operators/normalize-tool-result.js +7 -0
- package/vendor/common-nodes/dist/ai/features/llm-loop/operators/observe-provider-stream.d.ts +43 -0
- package/vendor/common-nodes/dist/ai/features/llm-loop/operators/observe-provider-stream.js +96 -0
- package/vendor/common-nodes/dist/ai/features/llm-loop/run-agent-loop.d.ts +29 -0
- package/vendor/common-nodes/dist/ai/features/llm-loop/run-agent-loop.js +44 -0
- package/vendor/common-nodes/dist/ai/features/llm-loop/run-llm-loop.d.ts +74 -0
- package/vendor/common-nodes/dist/ai/features/llm-loop/run-llm-loop.js +658 -0
- package/vendor/common-nodes/dist/ai/features/llm-role-preset.d.ts +69 -0
- package/vendor/common-nodes/dist/ai/features/llm-role-preset.js +265 -0
- package/vendor/common-nodes/dist/ai/features/llm-session/llm-session-shell.d.ts +141 -0
- package/vendor/common-nodes/dist/ai/features/llm-session/llm-session-shell.js +193 -0
- package/vendor/common-nodes/dist/ai/features/llm-session/run-session-machine.d.ts +21 -0
- package/vendor/common-nodes/dist/ai/features/llm-session/run-session-machine.js +118 -0
- package/vendor/common-nodes/dist/ai/features/openai/context-length-error.d.ts +14 -0
- package/vendor/common-nodes/dist/ai/features/openai/context-length-error.js +63 -0
- package/vendor/common-nodes/dist/ai/features/openai/create-chat-completion-stream.d.ts +19 -0
- package/vendor/common-nodes/dist/ai/features/openai/create-chat-completion-stream.js +182 -0
- package/vendor/common-nodes/dist/ai/features/openai/list-provider-models.d.ts +28 -0
- package/vendor/common-nodes/dist/ai/features/openai/list-provider-models.js +52 -0
- package/vendor/common-nodes/dist/ai/features/openai/llm-context-compaction.d.ts +31 -0
- package/vendor/common-nodes/dist/ai/features/openai/llm-context-compaction.js +326 -0
- package/vendor/common-nodes/dist/ai/features/openai/normalize-compaction-params.d.ts +14 -0
- package/vendor/common-nodes/dist/ai/features/openai/normalize-compaction-params.js +21 -0
- package/vendor/common-nodes/dist/ai/features/openai/prepare-chat-completion.d.ts +30 -0
- package/vendor/common-nodes/dist/ai/features/openai/prepare-chat-completion.js +132 -0
- package/vendor/common-nodes/dist/ai/features/path-choice/control-tools.d.ts +20 -0
- package/vendor/common-nodes/dist/ai/features/path-choice/control-tools.js +70 -0
- package/vendor/common-nodes/dist/ai/features/path-choice/run-reactive-path-choice-loop.d.ts +32 -0
- package/vendor/common-nodes/dist/ai/features/path-choice/run-reactive-path-choice-loop.js +93 -0
- package/vendor/common-nodes/dist/ai/features/prompt/build-effective-system-prompt.d.ts +9 -0
- package/vendor/common-nodes/dist/ai/features/prompt/build-effective-system-prompt.js +21 -0
- package/vendor/common-nodes/dist/ai/features/prompt/normalize-max-iterations.d.ts +13 -0
- package/vendor/common-nodes/dist/ai/features/prompt/normalize-max-iterations.js +23 -0
- package/vendor/common-nodes/dist/ai/features/prompt/resolve-chat-provider-model.d.ts +10 -0
- package/vendor/common-nodes/dist/ai/features/prompt/resolve-chat-provider-model.js +8 -0
- package/vendor/common-nodes/dist/ai/features/run-host-services.d.ts +54 -0
- package/vendor/common-nodes/dist/ai/features/run-host-services.js +29 -0
- package/vendor/common-nodes/dist/ai/features/scripted-chat-completion-stream.d.ts +17 -0
- package/vendor/common-nodes/dist/ai/features/scripted-chat-completion-stream.js +61 -0
- package/vendor/common-nodes/dist/ai/features/sub-agent-protocol.d.ts +40 -0
- package/vendor/common-nodes/dist/ai/features/sub-agent-protocol.js +44 -0
- package/vendor/common-nodes/dist/ai/features/ui-schema/llm-compaction-ui-schema.d.ts +14 -0
- package/vendor/common-nodes/dist/ai/features/ui-schema/llm-compaction-ui-schema.js +18 -0
- package/vendor/common-nodes/dist/ai/features/ui-schema/llm-panel-ui-schema.d.ts +80 -0
- package/vendor/common-nodes/dist/ai/features/ui-schema/llm-panel-ui-schema.js +76 -0
- package/vendor/common-nodes/dist/ai/features/ui-schema/llm-recovery-ui-schema.d.ts +113 -0
- package/vendor/common-nodes/dist/ai/features/ui-schema/llm-recovery-ui-schema.js +131 -0
- package/vendor/common-nodes/dist/ai/features/wait-for-subagent-result.d.ts +7 -0
- package/vendor/common-nodes/dist/ai/features/wait-for-subagent-result.js +31 -0
- package/vendor/common-nodes/dist/ai/llm-loop/autokick-recovery.d.ts +13 -0
- package/vendor/common-nodes/dist/ai/llm-loop/autokick-recovery.js +17 -0
- package/vendor/common-nodes/dist/ai/llm-loop/dead-loop-detector.d.ts +28 -0
- package/vendor/common-nodes/dist/ai/llm-loop/dead-loop-detector.js +194 -0
- package/vendor/common-nodes/dist/ai/llm-loop/llm-loop-reducer.js +36 -0
- package/vendor/common-nodes/dist/ai/llm-loop/llm-loop-types.d.ts +35 -0
- package/vendor/common-nodes/dist/ai/llm-loop/llm-loop-types.js +19 -0
- package/vendor/common-nodes/dist/ai/llm-loop/normalize-llm-recovery-policy.js +52 -9
- package/vendor/common-nodes/dist/ai/llm-loop/operators/observe-provider-stream.d.ts +8 -2
- package/vendor/common-nodes/dist/ai/llm-loop/operators/observe-provider-stream.js +43 -13
- package/vendor/common-nodes/dist/ai/llm-loop/run-llm-loop.d.ts +3 -5
- package/vendor/common-nodes/dist/ai/llm-loop/run-llm-loop.js +116 -1
- package/vendor/common-nodes/dist/ai/llm-recovery-ui-schema.d.ts +82 -0
- package/vendor/common-nodes/dist/ai/llm-recovery-ui-schema.js +95 -0
- package/vendor/common-nodes/dist/ai/llm-session-shell.d.ts +4 -9
- package/vendor/common-nodes/dist/ai/llm-session-shell.js +2 -4
- package/vendor/common-nodes/dist/ai/nodes/critique/node.d.ts +588 -0
- package/vendor/common-nodes/dist/ai/nodes/critique/node.js +227 -0
- package/vendor/common-nodes/dist/ai/nodes/fake-llm/node.d.ts +571 -0
- package/vendor/common-nodes/dist/ai/nodes/fake-llm/node.js +201 -0
- package/vendor/common-nodes/dist/ai/nodes/openai-llm/node.d.ts +587 -0
- package/vendor/common-nodes/dist/ai/nodes/openai-llm/node.js +84 -0
- package/vendor/common-nodes/dist/ai/nodes/review/node.d.ts +593 -0
- package/vendor/common-nodes/dist/ai/nodes/review/node.js +227 -0
- package/vendor/common-nodes/dist/ai/nodes/sub-agent/node.d.ts +630 -0
- package/vendor/common-nodes/dist/ai/nodes/sub-agent/node.js +417 -0
- package/vendor/common-nodes/dist/ai/openai/create-chat-completion-stream.js +6 -0
- package/vendor/common-nodes/dist/ai/openai/prepare-chat-completion.d.ts +2 -0
- package/vendor/common-nodes/dist/ai/openai/prepare-chat-completion.js +18 -0
- package/vendor/common-nodes/dist/ai/openai-llm/node.d.ts +246 -0
- package/vendor/common-nodes/dist/ai/review/node.d.ts +246 -0
- package/vendor/common-nodes/dist/ai/review/node.js +2 -2
- package/vendor/common-nodes/dist/ai/sub-agent/node.d.ts +246 -0
- package/vendor/common-nodes/dist/ai/sub-agent/node.js +2 -2
- package/vendor/common-nodes/dist/catalog.js +9 -5
- package/vendor/common-nodes/dist/compile-custom-nodes/node.d.ts +21 -0
- package/vendor/common-nodes/dist/compile-custom-nodes/node.js +45 -0
- package/vendor/common-nodes/dist/crawl/crawl/node.js +1 -1
- package/vendor/common-nodes/dist/crawl/fetch-url/node.js +1 -1
- package/vendor/common-nodes/dist/flow/repeat/node.js +6 -1
- package/vendor/common-nodes/dist/langflower-tools/emit-registration-tools.d.ts +18 -0
- package/vendor/common-nodes/dist/langflower-tools/emit-registration-tools.js +29 -0
- package/vendor/common-nodes/dist/langflower-tools/node.d.ts +20 -0
- package/vendor/common-nodes/dist/langflower-tools/node.js +77 -0
- package/vendor/common-nodes/dist/mcp/mcp-http/node.d.ts +4 -4
- package/vendor/common-nodes/dist/mcp/mcp-http/node.js +9 -10
- package/vendor/common-nodes/dist/mcp/mcp-stdio/node.d.ts +4 -4
- package/vendor/common-nodes/dist/mcp/mcp-stdio/node.js +9 -10
- package/vendor/common-nodes/dist/text/append-file/node.js +1 -1
- package/vendor/common-nodes/dist/text/read-file/node.js +1 -1
- package/vendor/common-nodes/dist/text/write-file/node.js +1 -1
- package/vendor/common-nodes/dist/tools/collect-agent-tool-handles.d.ts +4 -4
- package/vendor/common-nodes/dist/tools/collect-agent-tool-handles.js +3 -11
- package/vendor/common-nodes/dist/tools/inventory-tool-round.d.ts +1 -11
- package/vendor/common-nodes/dist/tools/inventory-tool-round.js +0 -84
- package/vendor/common-nodes/dist/tools/tool-collection/node.d.ts +20 -0
- package/vendor/common-nodes/dist/tools/tool-collection/node.js +42 -0
- package/vendor/common-nodes/package.json +9 -13
- package/vendor/compiler/dist/compile-project-nodes.d.ts +2 -1
- package/vendor/compiler/dist/compile-project-nodes.js +35 -6
- package/vendor/compiler/dist/resolve-host-types.d.ts +0 -5
- package/vendor/compiler/dist/resolve-host-types.js +0 -8
- package/vendor/compiler/package.json +1 -1
- package/vendor/node-sdk/dist/node-factory/define-llm-node/default-llm-ports.d.ts +3 -7
- package/vendor/node-sdk/dist/node-factory/define-llm-node/default-llm-ports.js +4 -44
- package/vendor/node-sdk/dist/node-factory/define-llm-node/define-llm-node.d.ts +4 -6
- package/vendor/node-sdk/dist/node-factory/define-llm-node/define-llm-node.js +4 -6
- package/vendor/node-sdk/dist/node-factory/define-llm-node/llm-inventory-wire.d.ts +1 -0
- package/vendor/node-sdk/dist/node-factory/define-llm-node/llm-inventory-wire.js +1 -0
- package/vendor/node-sdk/dist/node-factory/define-llm-node/recovery-notice.d.ts +8 -0
- package/vendor/node-sdk/dist/node-factory/define-llm-node/recovery-notice.js +14 -0
- package/vendor/node-sdk/dist/node-factory/define-mcp/mcp-handle.d.ts +3 -4
- package/vendor/node-sdk/dist/node-factory/define-mcp/mcp-handle.js +1 -1
- package/vendor/node-sdk/dist/node-factory/define-reactive-node/types.d.ts +2 -4
- package/vendor/node-sdk/dist/node-factory/define-reactive-node/ui-schema-inference.d.ts +1 -1
- package/vendor/node-sdk/package.json +1 -1
- package/vendor/runtime/dist/port-feed-override.d.ts +13 -0
- package/vendor/runtime/dist/port-feed-override.js +21 -0
- package/vendor/runtime/dist/port-signal-from-response.d.ts +15 -0
- package/vendor/runtime/dist/port-signal-from-response.js +48 -0
- package/vendor/runtime/dist/runtime-editor.d.ts +5 -1
- package/vendor/runtime/dist/runtime-editor.js +19 -0
- package/vendor/runtime/dist/runtime-runner.d.ts +8 -3
- package/vendor/runtime/dist/runtime-runner.js +108 -87
- package/vendor/runtime/dist/runtime.d.ts +3 -1
- package/vendor/runtime/dist/runtime.js +1 -0
- package/vendor/runtime/dist/testing/workflows/workflow-events.d.ts +10 -6
- package/vendor/runtime/dist/testing/workflows/workflow-events.js +21 -31
- package/vendor/runtime/dist/types.d.ts +52 -40
- package/vendor/runtime/dist/types.js +5 -1
- package/vendor/runtime/package.json +1 -1
- package/vendor/server/dist/bridge/attach-langflower-bridge.js +3 -2
- package/vendor/server/dist/bridge/bridge-event-log.js +17 -102
- package/vendor/server/dist/bridge/build-execution-context.d.ts +5 -2
- package/vendor/server/dist/bridge/build-execution-context.js +48 -8
- package/vendor/server/dist/bridge/forward-runner-event.d.ts +1 -1
- package/vendor/server/dist/bridge/forward-runner-event.js +7 -12
- package/vendor/server/dist/bridge/get-live-wired-tools.d.ts +13 -0
- package/vendor/server/dist/bridge/get-live-wired-tools.js +83 -0
- package/vendor/server/dist/bridge/langflower-tools-rpc.d.ts +7 -0
- package/vendor/server/dist/bridge/langflower-tools-rpc.js +29 -0
- package/vendor/server/dist/bridge/wire-custom-palette-handlers.d.ts +2 -1
- package/vendor/server/dist/bridge/wire-custom-palette-handlers.js +3 -5
- package/vendor/server/dist/bridge/wire-runner-handlers.js +17 -10
- package/vendor/server/dist/bridge/wire-workflow-handlers.js +23 -9
- package/vendor/server/dist/checkpoint/run-checkpoint-session.d.ts +1 -1
- package/vendor/server/dist/checkpoint/run-checkpoint-session.js +10 -9
- package/vendor/server/dist/palette/compile-and-hot-swap-custom-nodes.d.ts +10 -0
- package/vendor/server/dist/palette/compile-and-hot-swap-custom-nodes.js +23 -0
- package/vendor/server/dist/session/reset-session-execution-feed.d.ts +6 -0
- package/vendor/server/dist/session/reset-session-execution-feed.js +8 -0
- package/vendor/server/dist/workflow/apply-editor-mutation.d.ts +5 -0
- package/vendor/server/dist/workflow/apply-editor-mutation.js +32 -0
- package/vendor/server/skeleton/instructions.md +9 -5
- package/vendor/server/skeleton/nodes/my-nodes/README.md +4 -3
- package/vendor/server/skeleton/nodes/my-nodes/package.json +1 -1
- package/vendor/server/skeleton/skills/langflower-helper/SKILL.md +82 -38
- package/vendor/server/skeleton/skills/langflower-helper/architecture.md +29 -10
- package/vendor/server/skeleton/skills/langflower-helper/layout.md +16 -15
- package/vendor/server/skeleton/skills/langflower-node-writer/SKILL.md +19 -9
- package/vendor/server/skeleton/skills/langflower-workflow-writer/SKILL.md +23 -15
- package/vendor/server/skeleton/workflows/kb-create.json +15 -43
- package/vendor/server/skeleton/workflows/kb-navigate.json +8 -22
- package/vendor/server/skeleton/workflows/simple-coder.json +18 -46
- package/vendor/server/skeleton/workflows/starter.json +35 -22
- package/vendor/shared/dist/execution/derive-run-settle-outcome.d.ts +1 -1
- package/vendor/shared/dist/execution/derive-run-settle-outcome.js +4 -3
- package/vendor/shared/dist/execution/derive-run-settle-outcome.test.js +18 -15
- package/vendor/shared/dist/langflower-bus-config.d.ts +6 -14
- package/vendor/shared/dist/langflower-bus-config.js +4 -12
- package/vendor/shared/dist/langflower-config/resolve-wired-tool-options.js +6 -0
- package/vendor/shared/dist/langflower-config/resolve-wired-tool-options.test.js +30 -0
- package/vendor/shared/dist/langflower-ws-waits.d.ts +9 -14
- package/vendor/shared/dist/langflower-ws-waits.js +14 -14
- package/vendor/websocket-bridge/dist/bridge-codec.d.ts +1 -0
- package/vendor/websocket-bridge/dist/bridge-codec.js +11 -11
- package/vendor/websocket-bridge/dist/bridge-frame.js +1 -1
- package/vendor/websocket-bridge/dist/bridge-subjects.d.ts +1 -1
- package/vendor/websocket-bridge/dist/bridge-subjects.js +2 -2
- package/vendor/websocket-bridge/dist/bridge-types.d.ts +13 -1
- package/vendor/websocket-bridge/dist/create-client.js +3 -3
- package/vendor/websocket-bridge/dist/create-server.js +12 -6
- package/vendor/websocket-bridge/package.json +8 -0
- package/ui-dist/main-ECEWAM6V.js +0 -311
- package/ui-dist/styles-EOXODOI7.css +0 -1
|
@@ -1,22 +1,22 @@
|
|
|
1
|
+
const isBridgeFrame = (value) => Array.isArray(value) &&
|
|
2
|
+
value.length === 4 &&
|
|
3
|
+
typeof value[0] === 'string' &&
|
|
4
|
+
(value[1] === 'in' || value[1] === 'out') &&
|
|
5
|
+
typeof value[2] === 'string';
|
|
6
|
+
export const encodeBridgeFrame = (transportDir, busType, payload, ts = new Date().toISOString()) => JSON.stringify([ts, transportDir, busType, payload]);
|
|
1
7
|
export const defaultWsBridgeCodec = {
|
|
2
|
-
encode(event) {
|
|
3
|
-
return
|
|
8
|
+
encode(event, transportDir) {
|
|
9
|
+
return encodeBridgeFrame(transportDir, event.type, event.payload);
|
|
4
10
|
},
|
|
5
11
|
decode(raw) {
|
|
6
12
|
try {
|
|
7
13
|
const parsed = JSON.parse(raw);
|
|
8
|
-
if (
|
|
9
|
-
parsed === null ||
|
|
10
|
-
Array.isArray(parsed)) {
|
|
11
|
-
return null;
|
|
12
|
-
}
|
|
13
|
-
const record = parsed;
|
|
14
|
-
if (typeof record['type'] !== 'string' || !('payload' in record)) {
|
|
14
|
+
if (!isBridgeFrame(parsed)) {
|
|
15
15
|
return null;
|
|
16
16
|
}
|
|
17
17
|
return {
|
|
18
|
-
type:
|
|
19
|
-
payload:
|
|
18
|
+
type: parsed[2],
|
|
19
|
+
payload: parsed[3],
|
|
20
20
|
};
|
|
21
21
|
}
|
|
22
22
|
catch {
|
|
@@ -19,6 +19,6 @@ export function decodeInboundFrame(config, codec, raw, section) {
|
|
|
19
19
|
};
|
|
20
20
|
}
|
|
21
21
|
return {
|
|
22
|
-
error: createWsBridgeError('INVALID_ENVELOPE', 'Frame must be a
|
|
22
|
+
error: createWsBridgeError('INVALID_ENVELOPE', 'Frame must be a bridge tuple [ts, transportDir, busType, payload]'),
|
|
23
23
|
};
|
|
24
24
|
}
|
|
@@ -5,6 +5,6 @@ export type WsBridgeMessageSection = keyof Pick<WsBridgeConfig, 'fromClientToSer
|
|
|
5
5
|
export declare function readMessageKeys(config: WsBridgeConfig, section: WsBridgeMessageSection): readonly string[];
|
|
6
6
|
export declare function createSubjectMap(keys: readonly string[]): Record<string, Subject<unknown>>;
|
|
7
7
|
export declare function toObservables(subjects: Record<string, Subject<unknown>>): Record<string, Observable<unknown>>;
|
|
8
|
-
export declare function wireOutgoingSubjects(subjects: Record<string, Subject<unknown>>, send: (event: WsBridgeEvent) => void): Subscription[];
|
|
8
|
+
export declare function wireOutgoingSubjects(subjects: Record<string, Subject<unknown>>, send: (event: WsBridgeEvent, transportDir: 'in' | 'out') => void, transportDir: 'in' | 'out'): Subscription[];
|
|
9
9
|
export declare function routeInboundEvent(event: WsBridgeEvent, subjects: Record<string, Subject<unknown>>, clientId?: string): boolean;
|
|
10
10
|
export declare function completeSubjects(subjects: Record<string, Subject<unknown>>): void;
|
|
@@ -16,9 +16,9 @@ export function toObservables(subjects) {
|
|
|
16
16
|
}
|
|
17
17
|
return observables;
|
|
18
18
|
}
|
|
19
|
-
export function wireOutgoingSubjects(subjects, send) {
|
|
19
|
+
export function wireOutgoingSubjects(subjects, send, transportDir) {
|
|
20
20
|
return Object.entries(subjects).map(([type, subject]) => subject.subscribe((payload) => {
|
|
21
|
-
send({ type, payload });
|
|
21
|
+
send({ type, payload }, transportDir);
|
|
22
22
|
}));
|
|
23
23
|
}
|
|
24
24
|
export function routeInboundEvent(event, subjects, clientId) {
|
|
@@ -12,8 +12,15 @@ export type WsBridgeEvent<Payload = unknown> = {
|
|
|
12
12
|
readonly type: string;
|
|
13
13
|
readonly payload: Payload;
|
|
14
14
|
};
|
|
15
|
+
/** Wire + log line: `[ts, transportDir, busType, payload]`. */
|
|
16
|
+
export type BridgeFrame = readonly [
|
|
17
|
+
ts: string,
|
|
18
|
+
transportDir: 'in' | 'out',
|
|
19
|
+
busType: string,
|
|
20
|
+
payload: unknown
|
|
21
|
+
];
|
|
15
22
|
export type WsBridgeCodec = {
|
|
16
|
-
encode(event: WsBridgeEvent): string;
|
|
23
|
+
encode(event: WsBridgeEvent, transportDir: 'in' | 'out'): string;
|
|
17
24
|
decode(raw: string): WsBridgeEvent | null;
|
|
18
25
|
};
|
|
19
26
|
export type WsBridgeConfig<ClientToServer extends WsBridgeMessageConfig = WsBridgeMessageConfig, ServerToClient extends WsBridgeMessageConfig = WsBridgeMessageConfig> = {
|
|
@@ -84,6 +91,11 @@ export type WsBridgeServer<C extends WsBridgeConfig> = {
|
|
|
84
91
|
readonly errors$: Observable<WsBridgeError>;
|
|
85
92
|
readonly status$: Observable<WsBridgeStatus>;
|
|
86
93
|
close(): void;
|
|
94
|
+
/**
|
|
95
|
+
* Push a client-to-server event as if a socket sent it (in-process
|
|
96
|
+
* hosts). Inbound channels stay Observables — not Subjects.
|
|
97
|
+
*/
|
|
98
|
+
injectInbound<K extends WsBridgeServerInboundKey<C>>(type: K, payload: WsBridgeServerInboundPayload<C, K>, clientId?: string): void;
|
|
87
99
|
};
|
|
88
100
|
export type WsBridgeServerApi<C extends WsBridgeConfig> = WsBridgeServer<C> & WsBridgeServerIncoming<C> & WsBridgeServerOutgoing<C>;
|
|
89
101
|
/** Type carrier for config entries — no casts in consumer config. */
|
|
@@ -89,7 +89,7 @@ export function createClient(config, options = {}) {
|
|
|
89
89
|
const errorsSubject = new Subject();
|
|
90
90
|
const statusSubject = new BehaviorSubject('connecting');
|
|
91
91
|
const socket = connectSocket(url);
|
|
92
|
-
const sendEvent = (event) => {
|
|
92
|
+
const sendEvent = (event, transportDir) => {
|
|
93
93
|
if (socket.readyState !== OPEN) {
|
|
94
94
|
errorsSubject.next({
|
|
95
95
|
code: 'TRANSPORT_NOT_OPEN',
|
|
@@ -97,11 +97,11 @@ export function createClient(config, options = {}) {
|
|
|
97
97
|
});
|
|
98
98
|
return;
|
|
99
99
|
}
|
|
100
|
-
socket.send(codec.encode(event));
|
|
100
|
+
socket.send(codec.encode(event, transportDir));
|
|
101
101
|
};
|
|
102
102
|
// Wire at construction so early `.next` is not silently dropped; sendEvent
|
|
103
103
|
// still rejects until the socket is OPEN.
|
|
104
|
-
const wireSubscriptions = wireOutgoingSubjects(outgoingSubjects, sendEvent);
|
|
104
|
+
const wireSubscriptions = wireOutgoingSubjects(outgoingSubjects, sendEvent, 'in');
|
|
105
105
|
socket.onOpen(() => {
|
|
106
106
|
statusSubject.next('connected');
|
|
107
107
|
});
|
|
@@ -18,14 +18,14 @@ export function createServer(config, options = {}) {
|
|
|
18
18
|
const errorsSubject = new Subject();
|
|
19
19
|
const statusSubject = new BehaviorSubject('connecting');
|
|
20
20
|
const clients = new Set();
|
|
21
|
-
const wireSubscriptions = wireOutgoingSubjects(broadcastSubjects, (event) => {
|
|
22
|
-
const raw = codec.encode(event);
|
|
21
|
+
const wireSubscriptions = wireOutgoingSubjects(broadcastSubjects, (event, transportDir) => {
|
|
22
|
+
const raw = codec.encode(event, transportDir);
|
|
23
23
|
for (const client of clients) {
|
|
24
24
|
if (client.ws.readyState === client.ws.OPEN) {
|
|
25
25
|
client.ws.send(raw);
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
|
-
});
|
|
28
|
+
}, 'out');
|
|
29
29
|
const wss = options.httpServer !== undefined
|
|
30
30
|
? new WebSocketServer({ server: options.httpServer, path })
|
|
31
31
|
: new WebSocketServer({ host, port, path });
|
|
@@ -57,12 +57,12 @@ export function createServer(config, options = {}) {
|
|
|
57
57
|
const outgoingSubjects = createSubjectMap(serverToClientKeys);
|
|
58
58
|
const disconnectedSubject = new Subject();
|
|
59
59
|
const connectedSubject = new BehaviorSubject(true);
|
|
60
|
-
const subscriptions = wireOutgoingSubjects(outgoingSubjects, (event) => {
|
|
60
|
+
const subscriptions = wireOutgoingSubjects(outgoingSubjects, (event, transportDir) => {
|
|
61
61
|
if (ws.readyState !== ws.OPEN) {
|
|
62
62
|
return;
|
|
63
63
|
}
|
|
64
|
-
ws.send(codec.encode(event));
|
|
65
|
-
});
|
|
64
|
+
ws.send(codec.encode(event, transportDir));
|
|
65
|
+
}, 'out');
|
|
66
66
|
const closeClient = () => {
|
|
67
67
|
if (ws.readyState === ws.OPEN || ws.readyState === ws.CONNECTING) {
|
|
68
68
|
ws.close();
|
|
@@ -108,6 +108,12 @@ export function createServer(config, options = {}) {
|
|
|
108
108
|
connections$: connectionsSubject.asObservable(),
|
|
109
109
|
errors$: errorsSubject.asObservable(),
|
|
110
110
|
status$: statusSubject.asObservable(),
|
|
111
|
+
injectInbound(type, payload, clientId = 'in-process') {
|
|
112
|
+
const routed = routeInboundEvent({ type, payload }, inboundSubjects, clientId);
|
|
113
|
+
if (!routed) {
|
|
114
|
+
throw new Error(`Unknown inbound event: ${String(type)}`);
|
|
115
|
+
}
|
|
116
|
+
},
|
|
111
117
|
close() {
|
|
112
118
|
statusSubject.next('disconnected');
|
|
113
119
|
for (const client of [...clients]) {
|
|
@@ -14,6 +14,14 @@
|
|
|
14
14
|
"./create-server": {
|
|
15
15
|
"types": "./dist/create-server.d.ts",
|
|
16
16
|
"import": "./dist/create-server.js"
|
|
17
|
+
},
|
|
18
|
+
"./bridge-codec": {
|
|
19
|
+
"types": "./dist/bridge-codec.d.ts",
|
|
20
|
+
"import": "./dist/bridge-codec.js"
|
|
21
|
+
},
|
|
22
|
+
"./bridge-codec.js": {
|
|
23
|
+
"types": "./dist/bridge-codec.d.ts",
|
|
24
|
+
"import": "./dist/bridge-codec.js"
|
|
17
25
|
}
|
|
18
26
|
},
|
|
19
27
|
"dependencies": {
|