@moltzap/client 2026.801.3 → 2026.803.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bounded-map.d.ts +3 -3
- package/dist/bounded-map.js +3 -3
- package/dist/channel-base/index.d.ts +3 -7
- package/dist/channel-base/index.d.ts.map +1 -1
- package/dist/channel-base/index.js +2 -6
- package/dist/channel-base/index.js.map +1 -1
- package/dist/channel-base/reply-guard.d.ts +52 -0
- package/dist/channel-base/reply-guard.d.ts.map +1 -0
- package/dist/channel-base/reply-guard.js +78 -0
- package/dist/channel-base/reply-guard.js.map +1 -0
- package/dist/channel-core-test-support.d.ts +5 -29
- package/dist/channel-core-test-support.d.ts.map +1 -1
- package/dist/channel-core-test-support.js +2 -92
- package/dist/channel-core-test-support.js.map +1 -1
- package/dist/channel-core.d.ts +130 -244
- package/dist/channel-core.d.ts.map +1 -1
- package/dist/channel-core.js +181 -505
- package/dist/channel-core.js.map +1 -1
- package/dist/cli/commands/start.d.ts +1 -5
- package/dist/cli/commands/start.d.ts.map +1 -1
- package/dist/cli/commands/start.js +0 -3
- package/dist/cli/commands/start.js.map +1 -1
- package/dist/harness-mcp-server.d.ts +19 -0
- package/dist/harness-mcp-server.d.ts.map +1 -0
- package/dist/harness-mcp-server.js +105 -0
- package/dist/harness-mcp-server.js.map +1 -0
- package/dist/harness-mcp-wire.d.ts +21 -0
- package/dist/harness-mcp-wire.d.ts.map +1 -0
- package/dist/harness-mcp-wire.js +48 -0
- package/dist/harness-mcp-wire.js.map +1 -0
- package/dist/index.d.ts +1 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -3
- package/dist/index.js.map +1 -1
- package/dist/local-daemon-rpc.d.ts +99 -178
- package/dist/local-daemon-rpc.d.ts.map +1 -1
- package/dist/local-daemon-rpc.js +8 -10
- package/dist/local-daemon-rpc.js.map +1 -1
- package/dist/moltzapd.d.ts +37 -0
- package/dist/moltzapd.d.ts.map +1 -0
- package/dist/moltzapd.js +64 -0
- package/dist/moltzapd.js.map +1 -0
- package/dist/notification/__tests__/subscribe-signatures.types-check.d.ts +14 -14
- package/dist/notification/__tests__/subscribe-signatures.types-check.d.ts.map +1 -1
- package/dist/notification/__tests__/subscribe-signatures.types-check.js +5 -5
- package/dist/notification/__tests__/subscribe-signatures.types-check.js.map +1 -1
- package/dist/service-local-daemon.d.ts +1 -1
- package/dist/service-local-daemon.d.ts.map +1 -1
- package/dist/service-local-daemon.js +2 -4
- package/dist/service-local-daemon.js.map +1 -1
- package/dist/service.d.ts +16 -29
- package/dist/service.d.ts.map +1 -1
- package/dist/service.js +41 -52
- package/dist/service.js.map +1 -1
- package/dist/test-utils/channel-service-fixture.d.ts +1 -3
- package/dist/test-utils/channel-service-fixture.d.ts.map +1 -1
- package/dist/test-utils/channel-service-fixture.js +2 -22
- package/dist/test-utils/channel-service-fixture.js.map +1 -1
- package/dist/test-utils/ids.d.ts +0 -13
- package/dist/test-utils/ids.d.ts.map +1 -1
- package/dist/test-utils/ids.js +1 -16
- package/dist/test-utils/ids.js.map +1 -1
- package/dist/test-utils/index.d.ts +1 -1
- package/dist/test-utils/index.d.ts.map +1 -1
- package/dist/test-utils/index.js +1 -1
- package/dist/test-utils/index.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +6 -3
- package/dist/app-client.d.ts +0 -5
- package/dist/app-client.d.ts.map +0 -1
- package/dist/app-client.js +0 -3
- package/dist/app-client.js.map +0 -1
- package/dist/channel-base/lease-guard.d.ts +0 -31
- package/dist/channel-base/lease-guard.d.ts.map +0 -1
- package/dist/channel-base/lease-guard.js +0 -44
- package/dist/channel-base/lease-guard.js.map +0 -1
- package/dist/channel-base/lease-store.d.ts +0 -48
- package/dist/channel-base/lease-store.d.ts.map +0 -1
- package/dist/channel-base/lease-store.js +0 -77
- package/dist/channel-base/lease-store.js.map +0 -1
- package/dist/channel-base/lease.d.ts +0 -96
- package/dist/channel-base/lease.d.ts.map +0 -1
- package/dist/channel-base/lease.js +0 -106
- package/dist/channel-base/lease.js.map +0 -1
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Effect, Scope } from "effect";
|
|
2
|
+
import { acquireHarnessMcpHttpServer } from "./harness-mcp-server.js";
|
|
3
|
+
import { type ServiceRpcError } from "./service.js";
|
|
4
|
+
import type { ServiceConfigError } from "./config.js";
|
|
5
|
+
interface MoltzapdOptions {
|
|
6
|
+
readonly profileName: string;
|
|
7
|
+
readonly port: number;
|
|
8
|
+
}
|
|
9
|
+
type MoltzapdServer = Effect.Effect.Success<ReturnType<typeof acquireHarnessMcpHttpServer>>;
|
|
10
|
+
/**
|
|
11
|
+
* Owns one registered agent's service, channel core, network connection, and
|
|
12
|
+
* guarded loopback MCP listener for the lifetime of the caller's scope.
|
|
13
|
+
*
|
|
14
|
+
* ```mermaid
|
|
15
|
+
* sequenceDiagram
|
|
16
|
+
* participant process as moltzapd
|
|
17
|
+
* participant service as MoltZapService
|
|
18
|
+
* participant core as MoltZapChannelCore
|
|
19
|
+
* participant mcp as MCP listener
|
|
20
|
+
*
|
|
21
|
+
* process->>service: make(profileName)
|
|
22
|
+
* process->>core: construct(service)
|
|
23
|
+
* process->>core: connect()
|
|
24
|
+
* process->>mcp: listen(port)
|
|
25
|
+
* Note over core,mcp: Scope release closes MCP before disconnecting the core
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* The caller resolves the profile and port policy. This composition does not
|
|
29
|
+
* start the Unix-socket server and does not expose its service or core.
|
|
30
|
+
*
|
|
31
|
+
* @param options Existing profile name and caller-resolved listener port.
|
|
32
|
+
* @returns The scoped loopback HTTP listener.
|
|
33
|
+
* @internal
|
|
34
|
+
*/
|
|
35
|
+
export declare const acquireMoltzapd: (options: MoltzapdOptions) => Effect.Effect<MoltzapdServer, Error | ServiceConfigError | ServiceRpcError, Scope.Scope>;
|
|
36
|
+
export {};
|
|
37
|
+
//# sourceMappingURL=moltzapd.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"moltzapd.d.ts","sourceRoot":"","sources":["../src/moltzapd.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAA2B,KAAK,EAAE,MAAM,QAAQ,CAAC;AAGhE,OAAO,EAAE,2BAA2B,EAAE,MAAM,yBAAyB,CAAC;AAMtE,OAAO,EAAkB,KAAK,eAAe,EAAE,MAAM,cAAc,CAAC;AACpE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAEtD,UAAU,eAAe;IACvB,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB;AAQD,KAAK,cAAc,GAAG,MAAM,CAAC,MAAM,CAAC,OAAO,CACzC,UAAU,CAAC,OAAO,2BAA2B,CAAC,CAC/C,CAAC;AAsBF;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,eAAO,MAAM,eAAe,YACjB,eAAe,KACvB,MAAM,CAAC,MAAM,CACd,cAAc,EACd,KAAK,GAAG,kBAAkB,GAAG,eAAe,EAC5C,KAAK,CAAC,KAAK,CA0BgC,CAAC"}
|
package/dist/moltzapd.js
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { Effect, ExecutionStrategy, Exit, Scope } from "effect";
|
|
2
|
+
import packageJson from "../package.json" with { type: "json" };
|
|
3
|
+
import { MoltZapChannelCore } from "./channel-core.js";
|
|
4
|
+
import { acquireHarnessMcpHttpServer } from "./harness-mcp-server.js";
|
|
5
|
+
import { makeHarnessMcpHttpHandlers } from "./harness-mcp-wire.js";
|
|
6
|
+
import { MoltZapService } from "./service.js";
|
|
7
|
+
const MCP_IMPLEMENTATION = {
|
|
8
|
+
name: "moltzapd",
|
|
9
|
+
version: packageJson.version,
|
|
10
|
+
};
|
|
11
|
+
const makeStatusHandler = (service, core) => () => Effect.succeed({
|
|
12
|
+
...(service.ownAgentId === undefined
|
|
13
|
+
? {}
|
|
14
|
+
: { agentId: service.ownAgentId }),
|
|
15
|
+
connected: core.isConnected(),
|
|
16
|
+
conversations: service.getConversations().length,
|
|
17
|
+
});
|
|
18
|
+
const acquireConnectedCore = (service) =>
|
|
19
|
+
// eslint-disable-next-line agent-code-guard/acquire-release-requires-scope -- the process scope owns the sole core and its network connection
|
|
20
|
+
Effect.acquireRelease(Effect.sync(() => new MoltZapChannelCore({ service })), (core) => core.disconnect()).pipe(Effect.tap((core) => core.connect()));
|
|
21
|
+
/**
|
|
22
|
+
* Owns one registered agent's service, channel core, network connection, and
|
|
23
|
+
* guarded loopback MCP listener for the lifetime of the caller's scope.
|
|
24
|
+
*
|
|
25
|
+
* ```mermaid
|
|
26
|
+
* sequenceDiagram
|
|
27
|
+
* participant process as moltzapd
|
|
28
|
+
* participant service as MoltZapService
|
|
29
|
+
* participant core as MoltZapChannelCore
|
|
30
|
+
* participant mcp as MCP listener
|
|
31
|
+
*
|
|
32
|
+
* process->>service: make(profileName)
|
|
33
|
+
* process->>core: construct(service)
|
|
34
|
+
* process->>core: connect()
|
|
35
|
+
* process->>mcp: listen(port)
|
|
36
|
+
* Note over core,mcp: Scope release closes MCP before disconnecting the core
|
|
37
|
+
* ```
|
|
38
|
+
*
|
|
39
|
+
* The caller resolves the profile and port policy. This composition does not
|
|
40
|
+
* start the Unix-socket server and does not expose its service or core.
|
|
41
|
+
*
|
|
42
|
+
* @param options Existing profile name and caller-resolved listener port.
|
|
43
|
+
* @returns The scoped loopback HTTP listener.
|
|
44
|
+
* @internal
|
|
45
|
+
*/
|
|
46
|
+
export const acquireMoltzapd = (options) => Effect.gen(function* () {
|
|
47
|
+
const parentScope = yield* Effect.scope;
|
|
48
|
+
const daemonScope = yield* Scope.fork(parentScope, ExecutionStrategy.sequential);
|
|
49
|
+
const acquire = Effect.gen(function* () {
|
|
50
|
+
const service = yield* MoltZapService.make(options.profileName);
|
|
51
|
+
const core = yield* acquireConnectedCore(service);
|
|
52
|
+
const handlers = makeHarnessMcpHttpHandlers({
|
|
53
|
+
implementation: MCP_IMPLEMENTATION,
|
|
54
|
+
status: makeStatusHandler(service, core),
|
|
55
|
+
});
|
|
56
|
+
return yield* acquireHarnessMcpHttpServer({
|
|
57
|
+
port: options.port,
|
|
58
|
+
registrationHandler: handlers.registration,
|
|
59
|
+
harnessHandler: handlers.active,
|
|
60
|
+
});
|
|
61
|
+
}).pipe(Scope.extend(daemonScope));
|
|
62
|
+
return yield* acquire.pipe(Effect.onExit((exit) => Exit.isSuccess(exit) ? Effect.void : Scope.close(daemonScope, exit)));
|
|
63
|
+
}).pipe(Effect.withSpan("acquireMoltzapd"));
|
|
64
|
+
//# sourceMappingURL=moltzapd.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"moltzapd.js","sourceRoot":"","sources":["../src/moltzapd.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,iBAAiB,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAC;AAChE,OAAO,WAAW,MAAM,iBAAiB,CAAC,OAAO,IAAI,EAAE,MAAM,EAAE,CAAC;AAChE,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,EAAE,2BAA2B,EAAE,MAAM,yBAAyB,CAAC;AACtE,OAAO,EAAE,0BAA0B,EAAE,MAAM,uBAAuB,CAAC;AAKnE,OAAO,EAAE,cAAc,EAAwB,MAAM,cAAc,CAAC;AAQpE,MAAM,kBAAkB,GAAG;IACzB,IAAI,EAAE,UAAU;IAChB,OAAO,EAAE,WAAW,CAAC,OAAO;CACJ,CAAC;AAO3B,MAAM,iBAAiB,GACrB,CAAC,OAAuB,EAAE,IAAwB,EAAiB,EAAE,CACrE,GAAG,EAAE,CACH,MAAM,CAAC,OAAO,CAAC;IACb,GAAG,CAAC,OAAO,CAAC,UAAU,KAAK,SAAS;QAClC,CAAC,CAAC,EAAE;QACJ,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC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AAC,2BAA2B,CAAC;YACxC,IAAI,EAAE,OAAO,CAAC,IAAI;YAClB,mBAAmB,EAAE,QAAQ,CAAC,YAAY;YAC1C,cAAc,EAAE,QAAQ,CAAC,MAAM;SAChC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC;IACnC,OAAO,KAAK,CAAC,CAAC,OAAO,CAAC,IAAI,CACxB,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CACrB,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,WAAW,EAAE,IAAI,CAAC,CACpE,CACF,CAAC;AACJ,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,iBAAiB,CAAC,CAAC,CAAC"}
|
|
@@ -8,25 +8,25 @@
|
|
|
8
8
|
import { type Effect, Stream } from "effect";
|
|
9
9
|
import type { NotConnectedError, NotificationDelivery, NotificationParamsOf, NotificationSubscriberRegistry } from "@moltzap/protocol/rpc";
|
|
10
10
|
import type { AnyNotificationDefinition } from "@moltzap/protocol/socket/catalog";
|
|
11
|
-
import {
|
|
11
|
+
import { messageReceivedNotificationDefinition } from "@moltzap/protocol/message";
|
|
12
12
|
import { subscribe, type subscribeAll } from "../stream.js";
|
|
13
13
|
type Equal<Left, Right> = [Left, Right] extends [Right, Left] ? true : false;
|
|
14
14
|
type Expect<Value extends true> = Value;
|
|
15
|
-
type
|
|
16
|
-
type
|
|
17
|
-
readonly
|
|
18
|
-
readonly
|
|
15
|
+
type ReceivedParams = NotificationParamsOf<typeof messageReceivedNotificationDefinition>;
|
|
16
|
+
type GroupReceived = ReceivedParams & {
|
|
17
|
+
readonly message: {
|
|
18
|
+
readonly conversationId: string;
|
|
19
19
|
};
|
|
20
20
|
};
|
|
21
|
-
type
|
|
21
|
+
type GroupPredicate = (params: ReceivedParams) => params is GroupReceived;
|
|
22
22
|
/**
|
|
23
23
|
* Exercise the type-guard overload with concrete protocol types.
|
|
24
24
|
* @param registry Notification registry supplied by a connected client.
|
|
25
|
-
* @param
|
|
26
|
-
* @returns A stream narrowed to
|
|
25
|
+
* @param isGroup Predicate that narrows received messages to group deliveries.
|
|
26
|
+
* @returns A stream narrowed to group message deliveries.
|
|
27
27
|
*/
|
|
28
|
-
export declare function
|
|
29
|
-
type
|
|
28
|
+
export declare function subscribeNarrowedCanary(registry: NotificationSubscriberRegistry<NotConnectedError, AnyNotificationDefinition>, isGroup: GroupPredicate): Stream.Stream<GroupReceived, NotConnectedError, never>;
|
|
29
|
+
type NarrowedStream = ReturnType<typeof subscribeNarrowedCanary>;
|
|
30
30
|
/**
|
|
31
31
|
* Exercise Stream consumption against the real subscription return type.
|
|
32
32
|
* @param stream Subscription stream to consume.
|
|
@@ -35,16 +35,16 @@ type DeniedStream = ReturnType<typeof subscribeDeniedCanary>;
|
|
|
35
35
|
*/
|
|
36
36
|
export declare function runSubscriptionCanary(stream: ReturnType<typeof subscribe<AnyNotificationDefinition>>, handler: (notification: NotificationParamsOf<AnyNotificationDefinition>) => Effect.Effect<void>): Effect.Effect<void, NotConnectedError, never>;
|
|
37
37
|
type SubscribeStreamShape = Expect<Equal<ReturnType<typeof subscribe<AnyNotificationDefinition>>, Stream.Stream<NotificationParamsOf<AnyNotificationDefinition>, NotConnectedError>>>;
|
|
38
|
-
type
|
|
39
|
-
type
|
|
38
|
+
type NarrowedOverloadResolves = Expect<Equal<NarrowedStream, Stream.Stream<GroupReceived, NotConnectedError>>>;
|
|
39
|
+
type NarrowedElementIsExact = Expect<Equal<Stream.Stream.Success<NarrowedStream>, GroupReceived>>;
|
|
40
40
|
type SubscribeAllStreamShape = Expect<Equal<ReturnType<typeof subscribeAll>, Stream.Stream<NotificationDelivery<AnyNotificationDefinition>, NotConnectedError>>>;
|
|
41
41
|
type RunForEachHasNoLeakedRequirements = Expect<Equal<Effect.Effect.Context<ReturnType<typeof runSubscriptionCanary>>, never>>;
|
|
42
42
|
type TypedErrorChannelIsExact = Expect<Equal<Stream.Stream.Error<ReturnType<typeof subscribe<AnyNotificationDefinition>>>, NotConnectedError>>;
|
|
43
43
|
/** Compile-time assertions for notification subscription contracts. */
|
|
44
44
|
export type NotificationSubscriptionCanaries = [
|
|
45
45
|
SubscribeStreamShape,
|
|
46
|
-
|
|
47
|
-
|
|
46
|
+
NarrowedOverloadResolves,
|
|
47
|
+
NarrowedElementIsExact,
|
|
48
48
|
SubscribeAllStreamShape,
|
|
49
49
|
RunForEachHasNoLeakedRequirements,
|
|
50
50
|
TypedErrorChannelIsExact
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"subscribe-signatures.types-check.d.ts","sourceRoot":"","sources":["../../../src/notification/__tests__/subscribe-signatures.types-check.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAE,KAAK,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC7C,OAAO,KAAK,EACV,iBAAiB,EACjB,oBAAoB,EACpB,oBAAoB,EACpB,8BAA8B,EAC/B,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,kCAAkC,CAAC;AAClF,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"subscribe-signatures.types-check.d.ts","sourceRoot":"","sources":["../../../src/notification/__tests__/subscribe-signatures.types-check.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAE,KAAK,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC7C,OAAO,KAAK,EACV,iBAAiB,EACjB,oBAAoB,EACpB,oBAAoB,EACpB,8BAA8B,EAC/B,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,kCAAkC,CAAC;AAClF,OAAO,EAAE,qCAAqC,EAAE,MAAM,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c,EAAE,MAAM,CAAC,MAAM,CAAC,aAAa,EAAE,iBAAiB,CAAC,CAAC,CACvE,CAAC;AACF,KAAK,sBAAsB,GAAG,MAAM,CAClC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,cAAc,CAAC,EAAE,aAAa,CAAC,CAC5D,CAAC;AACF,KAAK,uBAAuB,GAAG,MAAM,CACnC,KAAK,CACH,UAAU,CAAC,OAAO,YAAY,CAAC,EAC/B,MAAM,CAAC,MAAM,CACX,oBAAoB,CAAC,yBAAyB,CAAC,EAC/C,iBAAiB,CAClB,CACF,CACF,CAAC;AACF,KAAK,iCAAiC,GAAG,MAAM,CAC7C,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,OAAO,qBAAqB,CAAC,CAAC,EAAE,KAAK,CAAC,CAC9E,CAAC;AACF,KAAK,wBAAwB,GAAG,MAAM,CACpC,KAAK,CACH,MAAM,CAAC,MAAM,CAAC,KAAK,CACjB,UAAU,CAAC,OAAO,SAAS,CAAC,yBAAyB,CAAC,CAAC,CACxD,EACD,iBAAiB,CAClB,CACF,CAAC;AAEF,uEAAuE;AACvE,MAAM,MAAM,gCAAgC,GAAG;IAC7C,oBAAoB;IACpB,wBAAwB;IACxB,sBAAsB;IACtB,uBAAuB;IACvB,iCAAiC;IACjC,wBAAwB;CACzB,CAAC"}
|
|
@@ -6,16 +6,16 @@
|
|
|
6
6
|
* channels, and the absence of leaked Effect requirements.
|
|
7
7
|
*/
|
|
8
8
|
import { Stream } from "effect";
|
|
9
|
-
import {
|
|
9
|
+
import { messageReceivedNotificationDefinition } from "@moltzap/protocol/message";
|
|
10
10
|
import { subscribe } from "../stream.js";
|
|
11
11
|
/**
|
|
12
12
|
* Exercise the type-guard overload with concrete protocol types.
|
|
13
13
|
* @param registry Notification registry supplied by a connected client.
|
|
14
|
-
* @param
|
|
15
|
-
* @returns A stream narrowed to
|
|
14
|
+
* @param isGroup Predicate that narrows received messages to group deliveries.
|
|
15
|
+
* @returns A stream narrowed to group message deliveries.
|
|
16
16
|
*/
|
|
17
|
-
export function
|
|
18
|
-
return subscribe(registry,
|
|
17
|
+
export function subscribeNarrowedCanary(registry, isGroup) {
|
|
18
|
+
return subscribe(registry, messageReceivedNotificationDefinition, isGroup);
|
|
19
19
|
}
|
|
20
20
|
/**
|
|
21
21
|
* Exercise Stream consumption against the real subscription return type.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"subscribe-signatures.types-check.js","sourceRoot":"","sources":["../../../src/notification/__tests__/subscribe-signatures.types-check.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAe,MAAM,EAAE,MAAM,QAAQ,CAAC;AAQ7C,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"subscribe-signatures.types-check.js","sourceRoot":"","sources":["../../../src/notification/__tests__/subscribe-signatures.types-check.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAe,MAAM,EAAE,MAAM,QAAQ,CAAC;AAQ7C,OAAO,EAAE,qCAAqC,EAAE,MAAM,2BAA2B,CAAC;AAClF,OAAO,EAAE,SAAS,EAAqB,MAAM,cAAc,CAAC;AAa5D;;;;;GAKG;AACH,MAAM,UAAU,uBAAuB,CACrC,QAGC,EACD,OAAuB;IAEvB,OAAO,SAAS,CAAC,QAAQ,EAAE,qCAAqC,EAAE,OAAO,CAAC,CAAC;AAC7E,CAAC;AAID;;;;;GAKG;AACH,MAAM,UAAU,qBAAqB,CACnC,MAA+D,EAC/D,OAEwB;IAExB,OAAO,MAAM,CAAC,UAAU,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAC5C,CAAC"}
|
|
@@ -12,7 +12,7 @@ type AgentCallableTag = AgentCallableRpcs["_tag"];
|
|
|
12
12
|
type ServiceCall = <Tag extends AgentCallableTag>(tag: Tag, payload: PayloadForTag<AgentCallableRpcs, Tag>, opts?: RpcCallOptions) => Effect.Effect<SuccessForTag<AgentCallableRpcs, Tag>, ServiceRpcError>;
|
|
13
13
|
interface LocalDaemonHandlerOptions {
|
|
14
14
|
readonly ownAgentId: AgentId;
|
|
15
|
-
readonly connected: boolean;
|
|
15
|
+
readonly connected: () => boolean;
|
|
16
16
|
readonly conversationCount: () => number;
|
|
17
17
|
readonly call: ServiceCall;
|
|
18
18
|
readonly handleHistoryRequest: (request: HistoryRequest) => Effect.Effect<HistoryResponse, ServiceRpcError>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"service-local-daemon.d.ts","sourceRoot":"","sources":["../src/service-local-daemon.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,MAAM,EAAU,MAAM,QAAQ,CAAC;AACxC,OAAO,
|
|
1
|
+
{"version":3,"file":"service-local-daemon.d.ts","sourceRoot":"","sources":["../src/service-local-daemon.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,MAAM,EAAU,MAAM,QAAQ,CAAC;AACxC,OAAO,EAAc,KAAK,OAAO,EAAE,MAAM,4BAA4B,CAAC;AACtE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAC;AAO3E,OAAO,KAAK,EAEV,aAAa,EAEb,aAAa,EACd,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACxD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AACpD,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAC1E,OAAO,EAIL,KAAK,mBAAmB,EAKzB,MAAM,uBAAuB,CAAC;AAE/B,KAAK,iBAAiB,GAAG,QAAQ,CAAC,IAAI,CAAC,OAAO,kBAAkB,CAAC,CAAC;AAClE,KAAK,gBAAgB,GAAG,iBAAiB,CAAC,MAAM,CAAC,CAAC;AAElD,KAAK,WAAW,GAAG,CAAC,GAAG,SAAS,gBAAgB,EAC9C,GAAG,EAAE,GAAG,EACR,OAAO,EAAE,aAAa,CAAC,iBAAiB,EAAE,GAAG,CAAC,EAC9C,IAAI,CAAC,EAAE,cAAc,KAClB,MAAM,CAAC,MAAM,CAAC,aAAa,CAAC,iBAAiB,EAAE,GAAG,CAAC,EAAE,eAAe,CAAC,CAAC;AAE3E,UAAU,yBAAyB;IACjC,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC;IAC7B,QAAQ,CAAC,SAAS,EAAE,MAAM,OAAO,CAAC;IAClC,QAAQ,CAAC,iBAAiB,EAAE,MAAM,MAAM,CAAC;IACzC,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAC;IAC3B,QAAQ,CAAC,oBAAoB,EAAE,CAC7B,OAAO,EAAE,cAAc,KACpB,MAAM,CAAC,MAAM,CAAC,eAAe,EAAE,eAAe,CAAC,CAAC;CACtD;AAuMD;;;;;;;;;GASG;AACH,wBAAgB,uBAAuB,CAAC,EACtC,UAAU,EACV,SAAS,EACT,iBAAiB,EACjB,IAAI,EACJ,oBAAoB,GACrB,EAAE,yBAAyB,GAAG,mBAAmB,CAwBjD"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Effect, Either } from "effect";
|
|
2
|
-
import { agentsList
|
|
2
|
+
import { agentsList } from "@moltzap/protocol/identity";
|
|
3
3
|
import { agentConversationCreate, } from "@moltzap/protocol/conversation";
|
|
4
4
|
import { messagesList, messagesSend } from "@moltzap/protocol/message";
|
|
5
5
|
import { localDaemonCommands, StartPartialFailure, StartUsageError, } from "./local-daemon-rpc.js";
|
|
@@ -100,7 +100,6 @@ function sendOptionalStartMessage({ call, params, conversationId, }) {
|
|
|
100
100
|
}
|
|
101
101
|
function handleStartCommand(call, params) {
|
|
102
102
|
return Effect.gen(function* () {
|
|
103
|
-
const appId = params.appId ?? DEFAULT_APP_ID;
|
|
104
103
|
const participants = yield* resolveStartParticipants(call, params.participants);
|
|
105
104
|
if (participants.length === 0) {
|
|
106
105
|
return yield* new StartUsageError({
|
|
@@ -108,7 +107,6 @@ function handleStartCommand(call, params) {
|
|
|
108
107
|
});
|
|
109
108
|
}
|
|
110
109
|
const created = yield* call(agentConversationCreate.name, {
|
|
111
|
-
appId,
|
|
112
110
|
name: params.name,
|
|
113
111
|
participants,
|
|
114
112
|
});
|
|
@@ -138,7 +136,7 @@ export function makeLocalDaemonHandlers({ ownAgentId, connected, conversationCou
|
|
|
138
136
|
return {
|
|
139
137
|
[localDaemonCommands.status]: () => Effect.succeed({
|
|
140
138
|
agentId: ownAgentId,
|
|
141
|
-
connected,
|
|
139
|
+
connected: connected(),
|
|
142
140
|
conversations: conversationCount(),
|
|
143
141
|
}),
|
|
144
142
|
[localDaemonCommands.history]: handleHistoryRequest,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"service-local-daemon.js","sourceRoot":"","sources":["../src/service-local-daemon.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACxC,OAAO,
|
|
1
|
+
{"version":3,"file":"service-local-daemon.js","sourceRoot":"","sources":["../src/service-local-daemon.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACxC,OAAO,EAAE,UAAU,EAAgB,MAAM,4BAA4B,CAAC;AAEtE,OAAO,EACL,uBAAuB,GAGxB,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAUvE,OAAO,EACL,mBAAmB,EACnB,mBAAmB,EACnB,eAAe,GAMhB,MAAM,uBAAuB,CAAC;AAiC/B,MAAM,kCAAkC,GAAG,GAAG,CAAC;AAC/C,MAAM,sBAAsB,GAAG,GAAG,CAAC;AACnC,MAAM,sBAAsB,GAAG,EAAE,CAAC;AA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B,CAAC,YAAY,CAAC,EAAE,CAAC,MAAM,EAAE,EAAE,CAC7C,IAAI,CAAC,YAAY,CAAC,IAAI,EAAE;YACtB,cAAc,EAAE,MAAM,CAAC,cAAc;YACrC,GAAG,CAAC,MAAM,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE,CAAC;SAC/D,CAAC;QACJ,CAAC,mBAAmB,CAAC,IAAI,CAAC,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,iBAAiB,CAAC,IAAI,EAAE,MAAM,CAAC;QACvE,CAAC,mBAAmB,CAAC,KAAK,CAAC,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,kBAAkB,CAAC,IAAI,EAAE,MAAM,CAAC;KAC1E,CAAC;AACJ,CAAC"}
|
package/dist/service.d.ts
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { AgentNotFoundError, type AgentId } from "@moltzap/protocol/identity";
|
|
2
|
-
import { dispatchRequest, dispatchRelease, dispatchLeaseConsumed, dispatchLeaseExpired, type LeaseId } from "@moltzap/protocol/message/dispatch";
|
|
3
2
|
import type { HelloOk } from "@moltzap/protocol/network";
|
|
4
3
|
import type { AnyAgentCallableRpcDefinition, AnyNotificationDefinition, agentCallableGroup } from "@moltzap/protocol/socket/catalog";
|
|
5
4
|
import type { ClientDefinitionPayload, ClientDefinitionSuccess } from "@moltzap/protocol/socket";
|
|
6
5
|
import { type ConversationId } from "@moltzap/protocol/conversation";
|
|
7
6
|
import { type Message } from "@moltzap/protocol/message";
|
|
8
|
-
import { NotConnectedError, type RpcTimeoutError, type NotificationDelivery, type
|
|
7
|
+
import { NotConnectedError, type RpcTimeoutError, type NotificationDelivery, type PayloadForTag, type SuccessForTag } from "@moltzap/protocol/rpc";
|
|
9
8
|
import type { RpcGroup, Rpc } from "@effect/rpc";
|
|
10
9
|
import { Effect } from "effect";
|
|
11
10
|
import { type RpcCallOptions } from "./agent-client.js";
|
|
@@ -61,14 +60,11 @@ interface ServiceHandlerPayloads {
|
|
|
61
60
|
/**
|
|
62
61
|
* The "raw notification" surface receives the descriptor-tagged delivery
|
|
63
62
|
* emitted after the native reverse RPC handler has Schema-decoded params.
|
|
64
|
-
* Subscribers that want specific
|
|
65
|
-
*
|
|
63
|
+
* Subscribers that want a specific payload narrow the delivery themselves
|
|
64
|
+
* with `isNotificationDeliveryFor`.
|
|
66
65
|
*/
|
|
67
66
|
readonly rawNotification: ClientNotificationDelivery;
|
|
68
67
|
readonly disconnect: undefined;
|
|
69
|
-
readonly dispatchRelease: NotificationParamsOf<typeof dispatchRelease>;
|
|
70
|
-
readonly dispatchLeaseConsumed: NotificationParamsOf<typeof dispatchLeaseConsumed>;
|
|
71
|
-
readonly dispatchLeaseExpired: NotificationParamsOf<typeof dispatchLeaseExpired>;
|
|
72
68
|
}
|
|
73
69
|
type ServiceHandlerName = keyof ServiceHandlerPayloads;
|
|
74
70
|
/** Full message from another conversation, used by peekFullMessages(). */
|
|
@@ -92,6 +88,7 @@ export interface CrossConvMessage {
|
|
|
92
88
|
export declare class MoltZapService {
|
|
93
89
|
private client;
|
|
94
90
|
private connectedValue;
|
|
91
|
+
private shutdownCompletion;
|
|
95
92
|
/**
|
|
96
93
|
* Service-owned scope. Opened in `connect()`, owns the
|
|
97
94
|
* `subscribeAll → Stream.runForEach` fan-out fiber. Closed in `close()` so
|
|
@@ -127,10 +124,17 @@ export declare class MoltZapService {
|
|
|
127
124
|
*/
|
|
128
125
|
connect(): Effect.Effect<HelloOk, ServiceRpcError>;
|
|
129
126
|
/**
|
|
130
|
-
*
|
|
131
|
-
*
|
|
132
|
-
*
|
|
133
|
-
*
|
|
127
|
+
* Returns a lazy teardown effect that resolves after the service's owned
|
|
128
|
+
* transports and notification scope close.
|
|
129
|
+
*
|
|
130
|
+
* @returns Completion of the service-owned cleanup.
|
|
131
|
+
* @internal
|
|
132
|
+
*/
|
|
133
|
+
shutdown(): Effect.Effect<void>;
|
|
134
|
+
private beginShutdown;
|
|
135
|
+
/**
|
|
136
|
+
* Starts service teardown for callers that use the legacy synchronous
|
|
137
|
+
* lifecycle boundary.
|
|
134
138
|
*/
|
|
135
139
|
close(): void;
|
|
136
140
|
private socketServerScope;
|
|
@@ -194,27 +198,11 @@ export declare class MoltZapService {
|
|
|
194
198
|
* svc-->>caller: Effect.void
|
|
195
199
|
* ```
|
|
196
200
|
*
|
|
197
|
-
* `opts.dispatchLeaseId` (when set) is forwarded verbatim in the
|
|
198
|
-
* params frame. The server marks the lease consumed, blocking the
|
|
199
|
-
* app authorization timeout sweep. `MoltZapChannelCore.sendReply` forwards
|
|
200
|
-
* `leaseIdInFlight` automatically when the caller omits it.
|
|
201
201
|
* @param conversationId Value supplied to the operation.
|
|
202
202
|
* @param text Text to process.
|
|
203
|
-
* @param opts Value supplied to the operation.
|
|
204
|
-
* @param opts.dispatchLeaseId Value supplied to the operation.
|
|
205
203
|
* @returns The send result.
|
|
206
204
|
*/
|
|
207
|
-
send(conversationId: ConversationId, text: string,
|
|
208
|
-
dispatchLeaseId?: LeaseId;
|
|
209
|
-
}): Effect.Effect<void, ServiceRpcError>;
|
|
210
|
-
/**
|
|
211
|
-
* Issue `agent/dispatch/request`. The server returns the ack
|
|
212
|
-
* `{leaseId, dispatchId}` immediately; the recipient observes the
|
|
213
|
-
* verdict asynchronously via the `dispatchRelease` event.
|
|
214
|
-
* @param params Request payload to process.
|
|
215
|
-
* @returns The cache result.
|
|
216
|
-
*/
|
|
217
|
-
requestDispatch(params: ParamsOf<typeof dispatchRequest>): Effect.Effect<ResultOf<typeof dispatchRequest>, ServiceRpcError>;
|
|
205
|
+
send(conversationId: ConversationId, text: string): Effect.Effect<void, ServiceRpcError>;
|
|
218
206
|
/**
|
|
219
207
|
* Send to a named agent, minting the DM conversation on first use and
|
|
220
208
|
* reusing it afterwards. The per-name cache is what makes the DM stable:
|
|
@@ -287,7 +275,6 @@ export declare class MoltZapService {
|
|
|
287
275
|
private dispatchTypedNotification;
|
|
288
276
|
private dispatchMessageNotification;
|
|
289
277
|
private dispatchConversationNotification;
|
|
290
|
-
private dispatchAppNotification;
|
|
291
278
|
/**
|
|
292
279
|
* Record `messageId` in the per-conversation dedup window. Returns
|
|
293
280
|
* `true` when the id is new (caller proceeds), `false` when the id is
|
package/dist/service.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../src/service.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,kBAAkB,
|
|
1
|
+
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../src/service.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,kBAAkB,EAGlB,KAAK,OAAO,EACb,MAAM,4BAA4B,CAAC;AACpC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,2BAA2B,CAAC;AACzD,OAAO,KAAK,EACV,6BAA6B,EAC7B,yBAAyB,EACzB,kBAAkB,EACnB,MAAM,kCAAkC,CAAC;AAC1C,OAAO,KAAK,EACV,uBAAuB,EACvB,uBAAuB,EACxB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAKL,KAAK,cAAc,EAEpB,MAAM,gCAAgC,CAAC;AACxC,OAAO,EACL,KAAK,OAAO,EAKb,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACL,iBAAiB,EACjB,KAAK,eAAe,EAEpB,KAAK,oBAAoB,EAEzB,KAAK,aAAa,EAElB,KAAK,aAAa,EACnB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAEjD,OAAO,EAEL,MAAM,EAQP,MAAM,QAAQ,CAAC;AAChB,OAAO,EAAsB,KAAK,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAC5E,OAAO,EAEL,KAAK,oBAAoB,EACzB,KAAK,kBAAkB,EACxB,MAAM,aAAa,CAAC;AAqCrB,kFAAkF;A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,EAC7B,YAAY,EAAE,CAAC,EACf,OAAO,EAAE,mBAAmB,CAAC,sBAAsB,CAAC,CAAC,CAAC,CAAC,GACtD,IAAI,CAEN;IAID;;;;;;;;OAQG;IACH,IAAI,CAAC,GAAG,SAAS,gBAAgB,EAC/B,GAAG,EAAE,GAAG,EACR,OAAO,EAAE,aAAa,CAAC,iBAAiB,EAAE,GAAG,CAAC,EAC9C,IAAI,CAAC,EAAE,cAAc,GACpB,MAAM,CAAC,MAAM,CAAC,aAAa,CAAC,iBAAiB,EAAE,GAAG,CAAC,EAAE,eAAe,CAAC,CAQvE;IAED,cAAc,CAAC,CAAC,SAAS,6BAA6B,EACpD,UAAU,EAAE,CAAC,EACb,OAAO,EAAE,uBAAuB,CAAC,CAAC,CAAC,EACnC,IAAI,CAAC,EAAE,cAAc,GACpB,MAAM,CAAC,MAAM,CAAC,uBAAuB,CAAC,CAAC,CAAC,EAAE,eAAe,CAAC,CAQ5D;IAID,SAAS,CAAC,kBAAkB,CAAC,YAAY,EAAE,0BAA0B,GAAG,IAAI,CAI3E;IAED,OAAO,CAAC,uBAAuB;IAU/B,OAAO,CAAC,yBAAyB;IASjC,OAAO,CAAC,2BAA2B;IAenC,OAAO,CAAC,gCAAgC;IAexC;;;;;;;;;;;;;;OAcG;IACH,OAAO,CAAC,oBAAoB;IAkB5B,OAAO,CAAC,iCAAiC;IAmBzC,OAAO,CAAC,qCAAqC;IAoB7C,OAAO,CAAC,YAAY;CAiBrB"}
|
package/dist/service.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import { agentId as AgentIdSchema, AgentNotFoundError, agentsList,
|
|
2
|
-
import { dispatchRequest, dispatchRelease, dispatchLeaseConsumed, dispatchLeaseExpired, } from "@moltzap/protocol/message/dispatch";
|
|
1
|
+
import { agentId as AgentIdSchema, AgentNotFoundError, agentsList, } from "@moltzap/protocol/identity";
|
|
3
2
|
import { agentConversationCreate, conversationCreatedNotificationDefinition, conversationList, } from "@moltzap/protocol/conversation";
|
|
4
3
|
import { messageReceivedNotificationDefinition, messagesList, messagesSend, } from "@moltzap/protocol/message";
|
|
5
4
|
import { NotConnectedError, isNotificationDeliveryFor, } from "@moltzap/protocol/rpc";
|
|
6
5
|
import { BoundedMap } from "./bounded-map.js";
|
|
7
|
-
import { Effect, Exit, HashMap, Option, Ref, Schema, Scope, Stream, } from "effect";
|
|
6
|
+
import { Deferred, Effect, Exit, HashMap, Option, Ref, Schema, Scope, Stream, } from "effect";
|
|
8
7
|
import { MoltZapAgentClient } from "./agent-client.js";
|
|
9
8
|
import { loadServiceConfig, } from "./config.js";
|
|
10
9
|
import { getOr, snapshot } from "./refs.js";
|
|
@@ -100,6 +99,7 @@ function fanout(handlers, arg) {
|
|
|
100
99
|
export class MoltZapService {
|
|
101
100
|
client = null;
|
|
102
101
|
connectedValue = false;
|
|
102
|
+
shutdownCompletion = null;
|
|
103
103
|
/**
|
|
104
104
|
* Service-owned scope. Opened in `connect()`, owns the
|
|
105
105
|
* `subscribeAll → Stream.runForEach` fan-out fiber. Closed in `close()` so
|
|
@@ -124,9 +124,6 @@ export class MoltZapService {
|
|
|
124
124
|
message: [],
|
|
125
125
|
rawNotification: [],
|
|
126
126
|
disconnect: [],
|
|
127
|
-
dispatchRelease: [],
|
|
128
|
-
dispatchLeaseConsumed: [],
|
|
129
|
-
dispatchLeaseExpired: [],
|
|
130
127
|
};
|
|
131
128
|
ownAgentIdValue;
|
|
132
129
|
opts;
|
|
@@ -162,6 +159,15 @@ export class MoltZapService {
|
|
|
162
159
|
*/
|
|
163
160
|
connect() {
|
|
164
161
|
return Effect.gen(function* () {
|
|
162
|
+
// A new connection never takes ownership while resources from the
|
|
163
|
+
// preceding lifecycle are still closing.
|
|
164
|
+
while (this.shutdownCompletion !== null) {
|
|
165
|
+
const priorShutdown = this.shutdownCompletion;
|
|
166
|
+
yield* Deferred.await(priorShutdown);
|
|
167
|
+
if (this.shutdownCompletion === priorShutdown) {
|
|
168
|
+
this.shutdownCompletion = null;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
165
171
|
const client = new MoltZapAgentClient({
|
|
166
172
|
serverUrl: this.opts.serverUrl,
|
|
167
173
|
agentKey: this.opts.agentKey,
|
|
@@ -196,14 +202,23 @@ export class MoltZapService {
|
|
|
196
202
|
}.bind(this));
|
|
197
203
|
}
|
|
198
204
|
/**
|
|
199
|
-
*
|
|
200
|
-
*
|
|
201
|
-
*
|
|
202
|
-
*
|
|
205
|
+
* Returns a lazy teardown effect that resolves after the service's owned
|
|
206
|
+
* transports and notification scope close.
|
|
207
|
+
*
|
|
208
|
+
* @returns Completion of the service-owned cleanup.
|
|
209
|
+
* @internal
|
|
203
210
|
*/
|
|
204
|
-
|
|
211
|
+
shutdown() {
|
|
212
|
+
return Effect.suspend(() => this.beginShutdown());
|
|
213
|
+
}
|
|
214
|
+
beginShutdown() {
|
|
215
|
+
if (this.shutdownCompletion !== null) {
|
|
216
|
+
return Deferred.await(this.shutdownCompletion);
|
|
217
|
+
}
|
|
218
|
+
const shutdownCompletion = Effect.runSync(Deferred.make());
|
|
219
|
+
this.shutdownCompletion = shutdownCompletion;
|
|
205
220
|
this.connectedValue = false;
|
|
206
|
-
|
|
221
|
+
const stopSocketServer = this.stopSocketServer();
|
|
207
222
|
const scopeToClose = this.serviceScope;
|
|
208
223
|
const clientToClose = this.client;
|
|
209
224
|
this.serviceScope = null;
|
|
@@ -212,7 +227,6 @@ export class MoltZapService {
|
|
|
212
227
|
? Effect.void
|
|
213
228
|
: Scope.close(scopeToClose, Exit.void);
|
|
214
229
|
const closeClient = clientToClose === null ? Effect.void : clientToClose.close();
|
|
215
|
-
Effect.runFork(closeScope.pipe(Effect.zipRight(closeClient)));
|
|
216
230
|
Effect.runSync(Effect.all([
|
|
217
231
|
Ref.set(this.conversationsRef, HashMap.empty()),
|
|
218
232
|
Ref.set(this.messagesRef, HashMap.empty()),
|
|
@@ -225,6 +239,14 @@ export class MoltZapService {
|
|
|
225
239
|
// Handlers are preserved across explicit close()/connect() cycles.
|
|
226
240
|
// MoltZapChannelCore subscribes once in its constructor; clearing handlers
|
|
227
241
|
// here would silently drop inbound dispatch after the next connect.
|
|
242
|
+
return Effect.uninterruptible(Effect.all([stopSocketServer, closeScope.pipe(Effect.zipRight(closeClient))], { concurrency: 2, discard: true }).pipe(Effect.ensuring(Deferred.succeed(shutdownCompletion, undefined).pipe(Effect.asVoid))));
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* Starts service teardown for callers that use the legacy synchronous
|
|
246
|
+
* lifecycle boundary.
|
|
247
|
+
*/
|
|
248
|
+
close() {
|
|
249
|
+
Effect.runFork(this.beginShutdown());
|
|
228
250
|
}
|
|
229
251
|
// --- Socket Server ---
|
|
230
252
|
socketServerScope = null;
|
|
@@ -285,7 +307,10 @@ export class MoltZapService {
|
|
|
285
307
|
localDaemonHandlers() {
|
|
286
308
|
return makeLocalDaemonHandlers({
|
|
287
309
|
ownAgentId: this.ownAgentIdValue,
|
|
288
|
-
|
|
310
|
+
// A live thunk, not a snapshot: the handler table outlives connection
|
|
311
|
+
// cycles, and daemon/status must report the same liveness the MCP
|
|
312
|
+
// status tool reads.
|
|
313
|
+
connected: () => this.connectedValue,
|
|
289
314
|
conversationCount: () => this.getConversations().length,
|
|
290
315
|
call: this.call.bind(this),
|
|
291
316
|
handleHistoryRequest: (request) => this.handleHistoryRequest(request),
|
|
@@ -427,35 +452,16 @@ export class MoltZapService {
|
|
|
427
452
|
* svc-->>caller: Effect.void
|
|
428
453
|
* ```
|
|
429
454
|
*
|
|
430
|
-
* `opts.dispatchLeaseId` (when set) is forwarded verbatim in the
|
|
431
|
-
* params frame. The server marks the lease consumed, blocking the
|
|
432
|
-
* app authorization timeout sweep. `MoltZapChannelCore.sendReply` forwards
|
|
433
|
-
* `leaseIdInFlight` automatically when the caller omits it.
|
|
434
455
|
* @param conversationId Value supplied to the operation.
|
|
435
456
|
* @param text Text to process.
|
|
436
|
-
* @param opts Value supplied to the operation.
|
|
437
|
-
* @param opts.dispatchLeaseId Value supplied to the operation.
|
|
438
457
|
* @returns The send result.
|
|
439
458
|
*/
|
|
440
|
-
send(conversationId, text
|
|
459
|
+
send(conversationId, text) {
|
|
441
460
|
return Effect.asVoid(this.call(messagesSend.name, {
|
|
442
461
|
conversationId,
|
|
443
462
|
parts: [{ type: "text", text }],
|
|
444
|
-
...(opts?.dispatchLeaseId !== undefined
|
|
445
|
-
? { dispatchLeaseId: opts.dispatchLeaseId }
|
|
446
|
-
: {}),
|
|
447
463
|
}));
|
|
448
464
|
}
|
|
449
|
-
/**
|
|
450
|
-
* Issue `agent/dispatch/request`. The server returns the ack
|
|
451
|
-
* `{leaseId, dispatchId}` immediately; the recipient observes the
|
|
452
|
-
* verdict asynchronously via the `dispatchRelease` event.
|
|
453
|
-
* @param params Request payload to process.
|
|
454
|
-
* @returns The cache result.
|
|
455
|
-
*/
|
|
456
|
-
requestDispatch(params) {
|
|
457
|
-
return this.call(dispatchRequest.name, params);
|
|
458
|
-
}
|
|
459
465
|
/**
|
|
460
466
|
* Send to a named agent, minting the DM conversation on first use and
|
|
461
467
|
* reusing it afterwards. The per-name cache is what makes the DM stable:
|
|
@@ -474,7 +480,6 @@ export class MoltZapService {
|
|
|
474
480
|
return yield* agentNotFound(agentName);
|
|
475
481
|
}
|
|
476
482
|
const created = yield* this.call(agentConversationCreate.name, {
|
|
477
|
-
appId: DEFAULT_APP_ID,
|
|
478
483
|
participants: [agent.id],
|
|
479
484
|
});
|
|
480
485
|
conversationId = created.conversation.id;
|
|
@@ -697,10 +702,7 @@ export class MoltZapService {
|
|
|
697
702
|
if (this.dispatchMessageNotification(notification)) {
|
|
698
703
|
return;
|
|
699
704
|
}
|
|
700
|
-
|
|
701
|
-
return;
|
|
702
|
-
}
|
|
703
|
-
this.dispatchAppNotification(notification);
|
|
705
|
+
this.dispatchConversationNotification(notification);
|
|
704
706
|
}
|
|
705
707
|
dispatchMessageNotification(notification) {
|
|
706
708
|
if (isNotificationDeliveryFor(notification, messageReceivedNotificationDefinition)) {
|
|
@@ -716,19 +718,6 @@ export class MoltZapService {
|
|
|
716
718
|
}
|
|
717
719
|
return false;
|
|
718
720
|
}
|
|
719
|
-
dispatchAppNotification(notification) {
|
|
720
|
-
if (isNotificationDeliveryFor(notification, dispatchRelease)) {
|
|
721
|
-
fanout(this.handlers.dispatchRelease, notification.params);
|
|
722
|
-
return;
|
|
723
|
-
}
|
|
724
|
-
if (isNotificationDeliveryFor(notification, dispatchLeaseConsumed)) {
|
|
725
|
-
fanout(this.handlers.dispatchLeaseConsumed, notification.params);
|
|
726
|
-
return;
|
|
727
|
-
}
|
|
728
|
-
if (isNotificationDeliveryFor(notification, dispatchLeaseExpired)) {
|
|
729
|
-
fanout(this.handlers.dispatchLeaseExpired, notification.params);
|
|
730
|
-
}
|
|
731
|
-
}
|
|
732
721
|
/**
|
|
733
722
|
* Record `messageId` in the per-conversation dedup window. Returns
|
|
734
723
|
* `true` when the id is new (caller proceeds), `false` when the id is
|