@howaboua/pi-durable-context 0.9.1 → 0.10.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/index.js
CHANGED
|
@@ -1885,6 +1885,74 @@ async function refreshRankedHistory(conversation, ranked, context) {
|
|
|
1885
1885
|
}
|
|
1886
1886
|
}
|
|
1887
1887
|
|
|
1888
|
+
// packages/context/src/input-placement.ts
|
|
1889
|
+
async function waitForInputPlacement(host, id, context) {
|
|
1890
|
+
const requestId = `context:input:${id}`;
|
|
1891
|
+
let revision = 0;
|
|
1892
|
+
let closing = false;
|
|
1893
|
+
let wake;
|
|
1894
|
+
const changed = () => {
|
|
1895
|
+
revision++;
|
|
1896
|
+
wake?.();
|
|
1897
|
+
};
|
|
1898
|
+
const unsubscribe = host.harness.subscribeCommits((publication) => {
|
|
1899
|
+
if (publication.changes.some((change) => change.type === "task" && change.value.id === id || change.type === "submission" && change.value.requestId === requestId))
|
|
1900
|
+
changed();
|
|
1901
|
+
});
|
|
1902
|
+
const stopClose = host.harness.subscribeClose(() => {
|
|
1903
|
+
closing = true;
|
|
1904
|
+
changed();
|
|
1905
|
+
});
|
|
1906
|
+
try {
|
|
1907
|
+
while (true) {
|
|
1908
|
+
context.abortSignal?.throwIfAborted();
|
|
1909
|
+
if (closing)
|
|
1910
|
+
throw new Error("Context host closed before input placement was observed");
|
|
1911
|
+
const before = revision;
|
|
1912
|
+
const task = await host.harness.getTask(id, context);
|
|
1913
|
+
if (!task || task.kind !== INPUT_TASK)
|
|
1914
|
+
throw new Error("Input task does not belong to Context management");
|
|
1915
|
+
const submission = await host.harness.commit((tx) => tx.submissionByRequest(task.conversationId, requestId), context);
|
|
1916
|
+
if (submission)
|
|
1917
|
+
return { status: "submitted", submissionId: submission.id };
|
|
1918
|
+
if (task.state.status === "terminal" || task.state.status === "completing") {
|
|
1919
|
+
const outcome = task.state.outcome;
|
|
1920
|
+
if (outcome.status === "aborted")
|
|
1921
|
+
return {
|
|
1922
|
+
status: "aborted",
|
|
1923
|
+
...outcome.reason ? { reason: outcome.reason } : {}
|
|
1924
|
+
};
|
|
1925
|
+
return {
|
|
1926
|
+
status: "failed",
|
|
1927
|
+
message: outcome.status === "failed" || outcome.status === "faulted" ? outcome.error.message : outcome.status === "orphaned" ? outcome.reason : "Managed input completed without a native submission receipt"
|
|
1928
|
+
};
|
|
1929
|
+
}
|
|
1930
|
+
if (revision !== before)
|
|
1931
|
+
continue;
|
|
1932
|
+
await new Promise((resolve, reject) => {
|
|
1933
|
+
const signal = context.abortSignal;
|
|
1934
|
+
const abort = () => {
|
|
1935
|
+
wake = undefined;
|
|
1936
|
+
reject(signal?.reason);
|
|
1937
|
+
};
|
|
1938
|
+
wake = () => {
|
|
1939
|
+
signal?.removeEventListener("abort", abort);
|
|
1940
|
+
wake = undefined;
|
|
1941
|
+
resolve();
|
|
1942
|
+
};
|
|
1943
|
+
signal?.addEventListener("abort", abort, { once: true });
|
|
1944
|
+
if (signal?.aborted)
|
|
1945
|
+
abort();
|
|
1946
|
+
else if (revision !== before || closing)
|
|
1947
|
+
wake();
|
|
1948
|
+
});
|
|
1949
|
+
}
|
|
1950
|
+
} finally {
|
|
1951
|
+
unsubscribe();
|
|
1952
|
+
stopClose();
|
|
1953
|
+
}
|
|
1954
|
+
}
|
|
1955
|
+
|
|
1888
1956
|
// packages/context/src/notes.ts
|
|
1889
1957
|
import {
|
|
1890
1958
|
defineTool as defineTool2
|
|
@@ -2580,6 +2648,10 @@ function createContextManagement(options) {
|
|
|
2580
2648
|
if (binding?.harness === harness)
|
|
2581
2649
|
binding = undefined;
|
|
2582
2650
|
},
|
|
2651
|
+
async rejoin(id, requestId, context) {
|
|
2652
|
+
const receipt = await host().harness.snapshot(InputReceipt, id, requestId, context);
|
|
2653
|
+
return receipt?.task;
|
|
2654
|
+
},
|
|
2583
2655
|
async submit(id, draft, context) {
|
|
2584
2656
|
await ensureWindow(id, context);
|
|
2585
2657
|
const conv = await conversation(host(), id, context);
|
|
@@ -2607,6 +2679,9 @@ function createContextManagement(options) {
|
|
|
2607
2679
|
host().harness.resume();
|
|
2608
2680
|
return task;
|
|
2609
2681
|
},
|
|
2682
|
+
waitForSubmission(task, context) {
|
|
2683
|
+
return waitForInputPlacement(host(), task, context);
|
|
2684
|
+
},
|
|
2610
2685
|
async retry(id, context) {
|
|
2611
2686
|
const conv = await conversation(host(), id, context);
|
|
2612
2687
|
await conv.commit(async (tx) => {
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type ComponentInstance, type ComponentRequest } from "@howaboua/pi-durable-components";
|
|
2
|
+
import { createContextManagement } from "./index.ts";
|
|
3
|
+
type Management = ReturnType<typeof createContextManagement>;
|
|
4
|
+
/** Optional advanced hooks. Ordinary hosts need only their shared Models grant. */
|
|
5
|
+
export declare const contextOptions: import("@howaboua/pi-durable-components").ComponentCapability<{
|
|
6
|
+
models: import("@earendil-works/pi-ai").Models;
|
|
7
|
+
archiveHistory?: boolean;
|
|
8
|
+
rankedHistory?: import("./history-ranker.ts").RankedHistory;
|
|
9
|
+
beforeRollover?: import("./rollover-preparation.ts").BeforeRollover;
|
|
10
|
+
modelRoles?: import("./model-roles.ts").ContextModelRoles;
|
|
11
|
+
remote?: import("./remote.ts").ContextRemoteCatalog;
|
|
12
|
+
now?: () => number;
|
|
13
|
+
newContextRequests?: import("./index.ts").NewContextRequests;
|
|
14
|
+
hasEligibleContextHistory?: (conversationId: import("@earendil-works/pi-durable").ConversationId, context: import("@earendil-works/chord").Context) => boolean | Promise<boolean>;
|
|
15
|
+
automaticIdleRollover?: boolean;
|
|
16
|
+
idleRolloverMinutes?: 0 | 5 | 15 | 25 | 55 | 115 | 355 | 715;
|
|
17
|
+
taskBoundaryReminderTokens?: number;
|
|
18
|
+
}>;
|
|
19
|
+
export declare function createComponent(request: ComponentRequest): ComponentInstance<Management>;
|
|
20
|
+
export {};
|
|
@@ -43,8 +43,12 @@ export declare function createContextManagement(options: {
|
|
|
43
43
|
bind(harness: Harness, storage: Storage): void;
|
|
44
44
|
/** Release only after draining host calls and closing this Harness and its task invocations. */
|
|
45
45
|
unbind(harness: Harness): void;
|
|
46
|
+
/** Read an existing receipt without opening a window, creating a document or resuming work. */
|
|
47
|
+
rejoin(id: ConversationId, requestId: string, context: Context): Promise<TaskId<InputResult> | undefined>;
|
|
46
48
|
submit(id: ConversationId, draft: InputSubmissionDraft, context: Context): Promise<TaskId<InputResult>>;
|
|
47
49
|
newContext(id: ConversationId, context: Context): Promise<TaskId<import("./window-state.ts").TransitionResult>>;
|
|
50
|
+
/** Resolves at native admission, before the turn's final answer. Observation cancellation leaves work owned. */
|
|
51
|
+
waitForSubmission(task: TaskId<InputResult>, context: Context): Promise<import("@howaboua/pi-durable-components").ComponentInputPlacement>;
|
|
48
52
|
retry(id: ConversationId, context: Context): Promise<void>;
|
|
49
53
|
status(id: ConversationId, context: Context): Promise<{
|
|
50
54
|
window: Readonly<{
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Context } from "@earendil-works/chord";
|
|
2
|
+
import type { TaskId } from "@earendil-works/pi-durable";
|
|
3
|
+
import type { ComponentInputPlacement } from "@howaboua/pi-durable-components";
|
|
4
|
+
import { type ContextHost, type InputResult } from "./lifecycle.ts";
|
|
5
|
+
/** Observe this component's native receipt, not its final answer or private checkpoint layout. */
|
|
6
|
+
export declare function waitForInputPlacement(host: ContextHost, id: TaskId<InputResult>, context: Context): Promise<ComponentInputPlacement>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@howaboua/pi-durable-context",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
4
4
|
"description": "Local notes, retained history and durable context rollover",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -27,6 +27,10 @@
|
|
|
27
27
|
".": {
|
|
28
28
|
"types": "./dist/packages/context/src/index.d.ts",
|
|
29
29
|
"import": "./dist/index.js"
|
|
30
|
+
},
|
|
31
|
+
"./component": {
|
|
32
|
+
"types": "./dist/packages/context/src/activation.d.ts",
|
|
33
|
+
"import": "./dist/activation.js"
|
|
30
34
|
}
|
|
31
35
|
},
|
|
32
36
|
"files": [
|
|
@@ -37,15 +41,31 @@
|
|
|
37
41
|
],
|
|
38
42
|
"sideEffects": false,
|
|
39
43
|
"dependencies": {
|
|
40
|
-
"typebox": "1.3.27"
|
|
44
|
+
"typebox": "1.3.27",
|
|
45
|
+
"@howaboua/pi-durable-components": "0.10.0"
|
|
41
46
|
},
|
|
42
47
|
"peerDependencies": {
|
|
43
48
|
"@earendil-works/chord": "1.4.0",
|
|
44
49
|
"@earendil-works/pi-ai": "1.4.0",
|
|
45
50
|
"@earendil-works/pi-durable": "1.4.0",
|
|
46
|
-
"@modelcontextprotocol/sdk": "1.25.2"
|
|
51
|
+
"@modelcontextprotocol/sdk": ">=1.25.2 <2"
|
|
47
52
|
},
|
|
48
53
|
"publishConfig": {
|
|
49
54
|
"access": "public"
|
|
55
|
+
},
|
|
56
|
+
"durable": {
|
|
57
|
+
"schemaVersion": 1,
|
|
58
|
+
"kind": "extension",
|
|
59
|
+
"entry": "./component",
|
|
60
|
+
"runtimes": [
|
|
61
|
+
"node"
|
|
62
|
+
],
|
|
63
|
+
"requires": [
|
|
64
|
+
"durable.models.v1"
|
|
65
|
+
],
|
|
66
|
+
"permissions": [
|
|
67
|
+
"storage",
|
|
68
|
+
"models"
|
|
69
|
+
]
|
|
50
70
|
}
|
|
51
71
|
}
|