@howaboua/pi-durable-pulses 0.9.1 → 0.11.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.
@@ -1,27 +1,16 @@
1
1
  import type { Context } from "@earendil-works/chord";
2
2
  import type { ConversationId, SettledSubmissionRecord, TaskId, ToolExecutionApi, Tx } from "@earendil-works/pi-durable";
3
+ import type { ScheduledAdmissionDecision, ScheduledInput, ScheduledOccurrence, ScheduledResult, ScheduledSource, ScheduledTrigger, SchedulingBinding } from "@howaboua/pi-durable-components";
3
4
  import type { PulseDefinition } from "./definitions.ts";
4
- export type PulseBinding = {
5
- key: string;
6
- root: string;
7
- parentConversationId?: ConversationId;
8
- };
9
- export type PulseSource = {
10
- id: string;
11
- text: string;
12
- error?: string;
13
- };
5
+ export type PulseBinding = SchedulingBinding;
6
+ export type PulseSource = ScheduledSource;
14
7
  export type PulseRunRequest = {
15
8
  bindingKey: string;
16
9
  pulseId: string;
17
10
  requestId: string;
18
11
  };
19
- export type PulseTrigger = "manual" | "scheduled";
20
- export type PulseOccurrence = {
21
- count: number;
22
- startAt: number;
23
- endAt: number;
24
- };
12
+ export type PulseTrigger = ScheduledTrigger;
13
+ export type PulseOccurrence = ScheduledOccurrence;
25
14
  export type PulseAdmission = {
26
15
  binding: PulseBinding;
27
16
  definition: PulseDefinition;
@@ -31,33 +20,11 @@ export type PulseAdmission = {
31
20
  conversationId: ConversationId;
32
21
  occurrence?: PulseOccurrence;
33
22
  };
34
- export type PulseAdmissionDecision = {
35
- status: "accepted";
36
- } | {
37
- status: "blocked";
38
- reason: string;
39
- retryAt?: number;
40
- };
41
- export type PulseInputDelivery = {
42
- conversationId: ConversationId;
43
- taskId: TaskId;
44
- requestId: string;
45
- content: string;
46
- };
23
+ export type PulseAdmissionDecision = ScheduledAdmissionDecision;
24
+ export type PulseInputDelivery = ScheduledInput;
47
25
  /** The abort-before-dispatch case has a native task outcome but no submission receipt. */
48
- export type PulseOutcome = SettledSubmissionRecord | {
49
- status: "aborted";
50
- };
51
- export type PulseResultDelivery = {
52
- parentConversationId: ConversationId;
53
- conversationId: ConversationId;
54
- taskId: TaskId;
55
- outcome: PulseOutcome;
56
- requestId: string;
57
- title: string;
58
- text: string;
59
- occurrence?: PulseOccurrence;
60
- };
26
+ export type PulseOutcome = ScheduledResult["outcome"];
27
+ export type PulseResultDelivery = ScheduledResult;
61
28
  export interface PulsesOptions {
62
29
  /** Resolve the caller's authorised binding in api.env. Never infer from global bindings or host paths. */
63
30
  resolveToolBinding?(api: ToolExecutionApi, context: Context): Promise<string>;
package/dist/index.d.ts CHANGED
@@ -34,7 +34,7 @@ export declare function createPulses(options: PulsesOptions): {
34
34
  run?: string;
35
35
  skill?: true;
36
36
  };
37
- structuredOutputSchema?: import("typebox").TSchema;
37
+ structuredOutputSchema?: object;
38
38
  callers?: readonly ("model" | "tools")[];
39
39
  deferred?: true;
40
40
  outputLimits?: {
@@ -64,7 +64,7 @@ export declare function createPulses(options: PulsesOptions): {
64
64
  run?: string;
65
65
  skill?: true;
66
66
  };
67
- structuredOutputSchema?: import("typebox").TSchema;
67
+ structuredOutputSchema?: object;
68
68
  callers?: readonly ("model" | "tools")[];
69
69
  deferred?: true;
70
70
  outputLimits?: {
@@ -125,6 +125,8 @@ export declare function createPulses(options: PulsesOptions): {
125
125
  pulseId: string;
126
126
  }, context: Context): Promise<void>;
127
127
  bind(value: Harness, context: Context): Promise<void>;
128
- /** Stop admission first; host must drain/close native task invocations before releasing this binding. */
128
+ /** Stop new admissions and drain admission work while task bindings remain available. */
129
+ stopAdmission(): Promise<void>;
130
+ /** Release only after the host has drained/closed native task invocations. */
129
131
  unbind(): Promise<void>;
130
132
  };
package/dist/index.js CHANGED
@@ -1150,10 +1150,17 @@ function createPulses(options) {
1150
1150
  unsubscribeCommits?.();
1151
1151
  unsubscribeCommits = undefined;
1152
1152
  });
1153
- unsubscribeCommits = value.subscribeCommits((publication) => {
1154
- if (publication.changes.some((change) => change.type === "task" && change.value.kind === "howaboua.pulses.run" && change.value.state.status === "terminal"))
1155
- releaseCapacity(context);
1153
+ const commits = value.observeCommits({
1154
+ advance(publication) {
1155
+ if (publication.changes.some((change) => change.type === "task" && change.value.kind === "howaboua.pulses.run" && change.value.state.status === "terminal"))
1156
+ releaseCapacity(context);
1157
+ },
1158
+ end(end) {
1159
+ if (end.kind === "failed" && accepting)
1160
+ options.onError(end.error);
1161
+ }
1156
1162
  });
1163
+ unsubscribeCommits = () => commits.detach();
1157
1164
  timer = setInterval(() => {
1158
1165
  scan(context).catch(options.onError);
1159
1166
  }, 300000);
@@ -1178,7 +1185,7 @@ function createPulses(options) {
1178
1185
  bindingFlight.catch(options.onError);
1179
1186
  return bindingFlight;
1180
1187
  },
1181
- async unbind() {
1188
+ async stopAdmission() {
1182
1189
  accepting = false;
1183
1190
  unsubscribeClose?.();
1184
1191
  unsubscribeClose = undefined;
@@ -1190,6 +1197,9 @@ function createPulses(options) {
1190
1197
  await pending;
1191
1198
  if (bindingFlight)
1192
1199
  await bindingFlight.catch(() => {});
1200
+ },
1201
+ async unbind() {
1202
+ await component.stopAdmission();
1193
1203
  bindingFlight = undefined;
1194
1204
  harness = undefined;
1195
1205
  }
@@ -1,25 +1,5 @@
1
- export type PulseSchedule = {
2
- kind: "manual";
3
- } | {
4
- kind: "interval";
5
- everyMs: number;
6
- } | {
7
- kind: "daily";
8
- hour: number;
9
- minute: number;
10
- } | {
11
- kind: "weekly";
12
- day: number;
13
- hour: number;
14
- minute: number;
15
- } | {
16
- kind: "at";
17
- atMs: number;
18
- };
19
- export type PulseQuietHours = {
20
- startMinute: number;
21
- endMinute: number;
22
- };
1
+ export type { ScheduledQuietHours as PulseQuietHours, ScheduledTiming as PulseSchedule, } from "@howaboua/pi-durable-components";
2
+ import type { ScheduledQuietHours as PulseQuietHours, ScheduledTiming as PulseSchedule } from "@howaboua/pi-durable-components";
23
3
  export declare function parsePulseQuietHours(raw: string): PulseQuietHours | null;
24
4
  export declare function isPulseQuietAt(quietHours: PulseQuietHours, nowMs: number): boolean;
25
5
  export declare function parsePulseSchedule(raw: string): PulseSchedule | null;
package/dist/tool.d.ts CHANGED
@@ -20,7 +20,7 @@ export declare function createPulsesTool(options: PulsesOptions, operations: {
20
20
  run?: string;
21
21
  skill?: true;
22
22
  };
23
- structuredOutputSchema?: Type.TSchema;
23
+ structuredOutputSchema?: object;
24
24
  callers?: readonly ("model" | "tools")[];
25
25
  deferred?: true;
26
26
  outputLimits?: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@howaboua/pi-durable-pulses",
3
- "version": "0.9.1",
3
+ "version": "0.11.0",
4
4
  "description": "Persistent native scheduled pulse conversations",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -19,6 +19,10 @@
19
19
  ".": {
20
20
  "types": "./dist/index.d.ts",
21
21
  "import": "./dist/index.js"
22
+ },
23
+ "./component": {
24
+ "types": "./dist/activation.d.ts",
25
+ "import": "./dist/activation.js"
22
26
  }
23
27
  },
24
28
  "files": [
@@ -30,15 +34,32 @@
30
34
  ],
31
35
  "sideEffects": false,
32
36
  "dependencies": {
33
- "typebox": "1.3.27"
37
+ "typebox": "1.3.27",
38
+ "@howaboua/pi-durable-components": "0.11.0"
34
39
  },
35
40
  "peerDependencies": {
36
- "@earendil-works/chord": "1.4.0",
37
- "@earendil-works/pi-ai": "1.4.0",
38
- "@earendil-works/pi-durable": "1.4.0",
39
- "@modelcontextprotocol/sdk": "1.25.2"
41
+ "@earendil-works/chord": "1.5.0",
42
+ "@earendil-works/pi-ai": "1.5.0",
43
+ "@earendil-works/pi-durable": "1.5.0",
44
+ "@modelcontextprotocol/sdk": ">=1.25.2 <2"
40
45
  },
41
46
  "publishConfig": {
42
47
  "access": "public"
48
+ },
49
+ "durable": {
50
+ "schemaVersion": 1,
51
+ "kind": "extension",
52
+ "entry": "./component",
53
+ "runtimes": [
54
+ "node"
55
+ ],
56
+ "requires": [
57
+ "durable.scheduling.v1"
58
+ ],
59
+ "permissions": [
60
+ "storage",
61
+ "filesystem",
62
+ "models"
63
+ ]
43
64
  }
44
65
  }