@relkit/runtime-hono 0.7.1 → 0.7.4
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/agent-observation-pages.d.ts +15 -0
- package/dist/agent-observation-pages.d.ts.map +1 -0
- package/dist/agent-observation-pages.js +69 -0
- package/dist/agent-observation-pages.js.map +1 -0
- package/dist/agent-observation.d.ts +18 -21
- package/dist/agent-observation.d.ts.map +1 -1
- package/dist/agent-observation.js +39 -73
- package/dist/agent-observation.js.map +1 -1
- package/dist/agent-observation.schemas.d.ts +16 -0
- package/dist/agent-observation.schemas.d.ts.map +1 -0
- package/dist/agent-observation.schemas.js +18 -0
- package/dist/agent-observation.schemas.js.map +1 -0
- package/dist/agent-observation.types.d.ts +25 -1
- package/dist/agent-observation.types.d.ts.map +1 -1
- package/dist/agent-rpc-resume-admission.d.ts +80 -0
- package/dist/agent-rpc-resume-admission.d.ts.map +1 -0
- package/dist/agent-rpc-resume-admission.js +95 -0
- package/dist/agent-rpc-resume-admission.js.map +1 -0
- package/dist/agent-rpc-resume.d.ts +22 -52
- package/dist/agent-rpc-resume.d.ts.map +1 -1
- package/dist/agent-rpc-resume.js +38 -86
- package/dist/agent-rpc-resume.js.map +1 -1
- package/dist/agent-rpc-resume.types.d.ts +17 -1
- package/dist/agent-rpc-resume.types.d.ts.map +1 -1
- package/dist/create-app.d.ts +8 -8
- package/dist/create-app.d.ts.map +1 -1
- package/dist/create-app.js +6 -91
- package/dist/create-app.js.map +1 -1
- package/dist/create-rest-app.d.ts +36 -0
- package/dist/create-rest-app.d.ts.map +1 -0
- package/dist/create-rest-app.js +128 -0
- package/dist/create-rest-app.js.map +1 -0
- package/dist/materialize-rest-routes.d.ts +9 -0
- package/dist/materialize-rest-routes.d.ts.map +1 -0
- package/dist/materialize-rest-routes.js +62 -0
- package/dist/materialize-rest-routes.js.map +1 -0
- package/dist/materialize-routes-utils.d.ts +1 -1
- package/dist/materialize-routes-utils.d.ts.map +1 -1
- package/dist/materialize-routes-utils.js +10 -3
- package/dist/materialize-routes-utils.js.map +1 -1
- package/dist/materialize-routes.d.ts +5 -0
- package/dist/materialize-routes.d.ts.map +1 -1
- package/dist/materialize-routes.js +2 -49
- package/dist/materialize-routes.js.map +1 -1
- package/dist/materialize-routes.types.d.ts +3 -0
- package/dist/materialize-routes.types.d.ts.map +1 -1
- package/dist/prepared-app.d.ts +17 -0
- package/dist/prepared-app.d.ts.map +1 -0
- package/dist/prepared-app.js +56 -0
- package/dist/prepared-app.js.map +1 -0
- package/dist/prepared-transports.service.d.ts +30 -0
- package/dist/prepared-transports.service.d.ts.map +1 -0
- package/dist/prepared-transports.service.js +45 -0
- package/dist/prepared-transports.service.js.map +1 -0
- package/dist/prepared-transports.types.d.ts +33 -0
- package/dist/prepared-transports.types.d.ts.map +1 -0
- package/dist/prepared-transports.types.js +2 -0
- package/dist/prepared-transports.types.js.map +1 -0
- package/package.json +19 -15
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Effect, Option } from "effect";
|
|
2
|
+
import type { AgentObservationFrame, ObservationAuthorize, ObservationPageState } from "./agent-observation.types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Fetches one page after optional owned wait and current authorization.
|
|
5
|
+
* @param authorize - Refreshes request identity and provider scope each time.
|
|
6
|
+
* @param threadId - Already validated requested thread identity.
|
|
7
|
+
* @param state - Complete decoded page checkpoint and wait policy.
|
|
8
|
+
* @param signal - Optional native transport cancellation combined with fiber cancellation.
|
|
9
|
+
* @returns Ordered frames and next state, or typed provider/authorization failure.
|
|
10
|
+
*/
|
|
11
|
+
export declare const readObservationPage: (authorize: ObservationAuthorize, threadId: string, state: ObservationPageState, signal?: AbortSignal | undefined) => Effect.Effect<readonly [AgentObservationFrame[], Option.Option<{
|
|
12
|
+
after: import("@relkit/contracts").JournalCheckpoint;
|
|
13
|
+
wait: boolean;
|
|
14
|
+
}>] | readonly [readonly [], Option.Option<ObservationPageState>], import("./http-effect.js").HttpBoundaryError, never>;
|
|
15
|
+
//# sourceMappingURL=agent-observation-pages.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent-observation-pages.d.ts","sourceRoot":"","sources":["../src/agent-observation-pages.ts"],"names":[],"mappings":"AAOA,OAAO,EAAS,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAG/C,OAAO,KAAK,EACV,qBAAqB,EAErB,oBAAoB,EACpB,oBAAoB,EACrB,MAAM,8BAA8B,CAAC;AAEtC;;;;;;;GAOG;AACH,eAAO,MAAM,mBAAmB;;;uHAkD9B,CAAC"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reads authorized journal pages and projects bounded public frames. This module
|
|
3
|
+
* imports the small event projection entrypoint rather than agent execution;
|
|
4
|
+
* the stream consumer owns waits, cancellation and fresh frame authorization.
|
|
5
|
+
*/
|
|
6
|
+
import { agentClientEvents } from "@relkit/agents/client-events";
|
|
7
|
+
import { REALTIME_RUNTIME_LIMITS } from "@relkit/contracts";
|
|
8
|
+
import { Clock, Effect, Option } from "effect";
|
|
9
|
+
import { httpBoundary, observeHttp } from "./http-effect.js";
|
|
10
|
+
import { clientAgentSnapshot } from "./agent-compatibility.js";
|
|
11
|
+
/**
|
|
12
|
+
* Fetches one page after optional owned wait and current authorization.
|
|
13
|
+
* @param authorize - Refreshes request identity and provider scope each time.
|
|
14
|
+
* @param threadId - Already validated requested thread identity.
|
|
15
|
+
* @param state - Complete decoded page checkpoint and wait policy.
|
|
16
|
+
* @param signal - Optional native transport cancellation combined with fiber cancellation.
|
|
17
|
+
* @returns Ordered frames and next state, or typed provider/authorization failure.
|
|
18
|
+
*/
|
|
19
|
+
export const readObservationPage = Effect.fn("AgentObservation.readPage")(function* (authorize, threadId, state, signal) {
|
|
20
|
+
if (signal?.aborted)
|
|
21
|
+
return [[], Option.none()];
|
|
22
|
+
const resolved = yield* authorize();
|
|
23
|
+
if (state.wait) {
|
|
24
|
+
const now = yield* Clock.currentTimeMillis;
|
|
25
|
+
yield* httpBoundary("agent.observe.wait", (fiberSignal) => resolved.provider.waitForJournal({
|
|
26
|
+
...resolved.scope,
|
|
27
|
+
threadId,
|
|
28
|
+
after: state.after,
|
|
29
|
+
deadlineMs: now + 15_000,
|
|
30
|
+
signal: signal === undefined ? fiberSignal : AbortSignal.any([signal, fiberSignal]),
|
|
31
|
+
}));
|
|
32
|
+
}
|
|
33
|
+
const page = yield* observeHttp("agent.observe.read", httpBoundary("agent.observe.read", () => resolved.provider.readJournal({
|
|
34
|
+
...resolved.scope,
|
|
35
|
+
threadId,
|
|
36
|
+
after: state.after,
|
|
37
|
+
limit: 100,
|
|
38
|
+
maxEncodedBytes: 1024 * 1024,
|
|
39
|
+
})));
|
|
40
|
+
const frames = [];
|
|
41
|
+
if (page.gap !== undefined) {
|
|
42
|
+
const snapshot = yield* readObservationSnapshot(resolved, threadId);
|
|
43
|
+
frames.push({ kind: "gap", reason: page.gap, snapshot });
|
|
44
|
+
return [frames, Option.some({ after: snapshot.checkpoint, wait: false })];
|
|
45
|
+
}
|
|
46
|
+
for (const record of page.records)
|
|
47
|
+
for (const event of agentClientEvents(record))
|
|
48
|
+
frames.push({ kind: "event", event });
|
|
49
|
+
if (page.records.some((record) => ["approval", "control", "terminal", "interruption"].includes(record.kind)))
|
|
50
|
+
frames.push({
|
|
51
|
+
kind: "snapshot",
|
|
52
|
+
snapshot: yield* readObservationSnapshot(resolved, threadId),
|
|
53
|
+
});
|
|
54
|
+
return [frames, Option.some({ after: page.checkpoint, wait: !page.hasMore })];
|
|
55
|
+
});
|
|
56
|
+
/**
|
|
57
|
+
* Loads a bounded public snapshot through the already authorized provider scope.
|
|
58
|
+
* @param resolved - Fresh request identity and provider lease from the current page.
|
|
59
|
+
* @param threadId - Validated requested thread identity.
|
|
60
|
+
* @returns Compatibility-projected snapshot or typed native provider failure.
|
|
61
|
+
*/
|
|
62
|
+
const readObservationSnapshot = Effect.fn("AgentObservation.snapshot")(function* (resolved, threadId) {
|
|
63
|
+
return clientAgentSnapshot(yield* httpBoundary("agent.observe.snapshot", () => resolved.provider.loadThread({
|
|
64
|
+
...resolved.scope,
|
|
65
|
+
threadId,
|
|
66
|
+
maxEncodedBytes: REALTIME_RUNTIME_LIMITS.initialSnapshotBytes,
|
|
67
|
+
})));
|
|
68
|
+
});
|
|
69
|
+
//# sourceMappingURL=agent-observation-pages.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent-observation-pages.js","sourceRoot":"","sources":["../src/agent-observation-pages.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAC;AAC5D,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC/C,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC7D,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAQ/D;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,MAAM,CAAC,EAAE,CAAC,2BAA2B,CAAC,CAAC,QAAQ,CAAC,EACjF,SAA+B,EAC/B,QAAgB,EAChB,KAA2B,EAC3B,MAAoB;IAEpB,IAAI,MAAM,EAAE,OAAO;QAAE,OAAO,CAAC,EAAE,EAAE,MAAM,CAAC,IAAI,EAAwB,CAAU,CAAC;IAC/E,MAAM,QAAQ,GAAG,KAAK,CAAC,CAAC,SAAS,EAAE,CAAC;IACpC,IAAI,KAAK,CAAC,IAAI,EAAE,CAAC;QACf,MAAM,GAAG,GAAG,KAAK,CAAC,CAAC,KAAK,CAAC,iBAAiB,CAAC;QAC3C,KAAK,CAAC,CAAC,YAAY,CAAC,oBAAoB,EAAE,CAAC,WAAW,EAAE,EAAE,CACxD,QAAQ,CAAC,QAAQ,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AAE,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC;IACvF,IACE,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAC3B,CAAC,UAAU,EAAE,SAAS,EAAE,UAAU,EAAE,cAAc,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,CAC1E;QAED,MAAM,CAAC,IAAI,CAAC;YACV,IAAI,EAAE,UAAU;YAChB,QAAQ,EAAE,KAAK,CAAC,CAAC,uBAAuB,CAAC,QAAQ,EAAE,QAAQ,CAAC;SAC7D,CAAC,CAAC;IACL,OAAO,CAAC,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,UAAU,EAAE,IAAI,EAAE,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,CAAU,CAAC;AACzF,CAAC,CAAC,CAAC;AAEH;;;;;GAKG;AACH,MAAM,uBAAuB,GAAG,MAAM,CAAC,EAAE,CAAC,2BAA2B,CAAC,CAAC,QAAQ,CAAC,EAC9E,QAA2B,EAC3B,QAAgB;IAEhB,OAAO,mBAAmB,CACxB,KAAK,CAAC,CAAC,YAAY,CAAC,wBAAwB,EAAE,GAAG,EAAE,CACjD,QAAQ,CAAC,QAAQ,CAAC,UAAU,CAAC;QAC3B,GAAG,QAAQ,CAAC,KAAK;QACjB,QAAQ;QACR,eAAe,EAAE,uBAAuB,CAAC,oBAAoB;KAC9D,CAAC,CACH,CACF,CAAC;AACJ,CAAC,CAAC,CAAC"}
|
|
@@ -1,31 +1,28 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Opens request-owned authorized journal streams through a replaceable Effect
|
|
3
|
+
* service. The native iterable edge preserves scoped waits and cancellation;
|
|
4
|
+
* page projection loads no agent execution or language-model runtime.
|
|
5
|
+
*/
|
|
6
|
+
import { Context, Effect, Layer } from "effect";
|
|
3
7
|
import { type AgentInput } from "./agent-rpc-support.js";
|
|
4
8
|
import type { RpcContext } from "./rpc.js";
|
|
5
9
|
import type { RouteMaterializationOptions } from "./materialize-routes.js";
|
|
6
|
-
import type { AgentObservationFrame } from "./agent-observation.types.js";
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
* @param signal - Optional transport cancellation signal.
|
|
12
|
-
* @returns A lazy stream with typed native failures and fresh authorization before every frame.
|
|
13
|
-
*/
|
|
14
|
-
declare function observation(input: AgentInput, context: RpcContext, options: RouteMaterializationOptions, signal?: AbortSignal): Stream.Stream<AgentObservationFrame, HttpBoundaryError, never>;
|
|
15
|
-
declare const AgentObservation_base: Context.ServiceClass<AgentObservation, "@relkit/runtime-hono/AgentObservation", {
|
|
16
|
-
readonly observe: typeof observation;
|
|
17
|
-
}>;
|
|
18
|
-
/** Journal observations preserve fresh authorization, bounded pages and cancellable waits. */
|
|
10
|
+
import type { AgentObservationFrame, AgentObservationOperations } from "./agent-observation.types.js";
|
|
11
|
+
declare const AgentObservation_base: Context.ServiceClass<AgentObservation, "@relkit/runtime-hono/AgentObservation", AgentObservationOperations> & {
|
|
12
|
+
readonly make: Effect.Effect<AgentObservationOperations, never, never>;
|
|
13
|
+
};
|
|
14
|
+
/** Per-request journal observations; service acquisition captures no request context. */
|
|
19
15
|
export declare class AgentObservation extends AgentObservation_base {
|
|
20
16
|
}
|
|
21
|
-
/**
|
|
17
|
+
/** Builds the concrete service; callers can supply the same contract through a test Layer. */
|
|
22
18
|
export declare const AgentObservationLive: Layer.Layer<AgentObservation, never, never>;
|
|
23
|
-
/**
|
|
24
|
-
*
|
|
19
|
+
/**
|
|
20
|
+
* Opens an authorized journal at the native transport edge.
|
|
21
|
+
* @param input - Submitted agent identity, thread and checkpoint.
|
|
25
22
|
* @param context - Trusted transport context.
|
|
26
|
-
* @param options -
|
|
27
|
-
* @param signal - Optional
|
|
28
|
-
* @returns
|
|
23
|
+
* @param options - Active generation dependencies.
|
|
24
|
+
* @param signal - Optional native cancellation.
|
|
25
|
+
* @returns Lazy iterable; returning joins the pending provider wait through its scope.
|
|
29
26
|
*/
|
|
30
27
|
export declare function observeAgent(input: AgentInput, context: RpcContext, options: RouteMaterializationOptions, signal?: AbortSignal): AsyncIterable<AgentObservationFrame>;
|
|
31
28
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent-observation.d.ts","sourceRoot":"","sources":["../src/agent-observation.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"agent-observation.d.ts","sourceRoot":"","sources":["../src/agent-observation.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAkB,MAAM,QAAQ,CAAC;AAEhE,OAAO,EAAsC,KAAK,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAK7F,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAC3C,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,yBAAyB,CAAC;AAC3E,OAAO,KAAK,EACV,qBAAqB,EACrB,0BAA0B,EAC3B,MAAM,8BAA8B,CAAC;;;;AAkDtC,yFAAyF;AACzF,qBAAa,gBAAiB,SAAQ,qBAWpC;CAAG;AAEL,8FAA8F;AAC9F,eAAO,MAAM,oBAAoB,6CAAwD,CAAC;AAE1F;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAC1B,KAAK,EAAE,UAAU,EACjB,OAAO,EAAE,UAAU,EACnB,OAAO,EAAE,2BAA2B,EACpC,MAAM,CAAC,EAAE,WAAW,GACnB,aAAa,CAAC,qBAAqB,CAAC,CAMtC"}
|
|
@@ -1,94 +1,60 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Opens request-owned authorized journal streams through a replaceable Effect
|
|
3
|
+
* service. The native iterable edge preserves scoped waits and cancellation;
|
|
4
|
+
* page projection loads no agent execution or language-model runtime.
|
|
5
|
+
*/
|
|
6
|
+
import { Context, Effect, Layer, Schema, Stream } from "effect";
|
|
7
|
+
import { httpBoundary, httpIterable, HttpBoundaryError } from "./http-effect.js";
|
|
5
8
|
import { agentContext, requireAgentThreadId } from "./agent-rpc-support.js";
|
|
6
9
|
import { assertExpectedIdentity } from "./rpc-identity.js";
|
|
7
|
-
import {
|
|
10
|
+
import { ObservationCheckpoint } from "./agent-observation.schemas.js";
|
|
11
|
+
import { readObservationPage } from "./agent-observation-pages.js";
|
|
8
12
|
import { observeHttpStream } from "./http-stream-observation.js";
|
|
9
|
-
/**
|
|
10
|
-
*
|
|
11
|
-
* @param
|
|
12
|
-
* @param
|
|
13
|
-
* @param
|
|
14
|
-
* @
|
|
13
|
+
/**
|
|
14
|
+
* Builds a journal feed with fresh authorization before pages and frames.
|
|
15
|
+
* @param input - Request agent/thread identity and submitted checkpoint.
|
|
16
|
+
* @param context - Trusted transport context for this consumer.
|
|
17
|
+
* @param options - Active generation and provider authority.
|
|
18
|
+
* @param signal - Optional native transport cancellation.
|
|
19
|
+
* @returns Lazy scoped stream with typed boundary failures and decoded cursors.
|
|
15
20
|
*/
|
|
16
21
|
function observation(input, context, options, signal) {
|
|
17
22
|
return Stream.unwrap(Effect.gen(function* () {
|
|
18
23
|
const threadId = requireAgentThreadId(input.threadId);
|
|
19
24
|
if (input.after === undefined)
|
|
20
|
-
return yield*
|
|
25
|
+
return yield* new HttpBoundaryError({
|
|
21
26
|
operation: "agent.observe",
|
|
22
27
|
cause: new TypeError("checkpoint is required."),
|
|
23
|
-
})
|
|
24
|
-
/** Refreshes
|
|
25
|
-
* @returns The currently authorized agent provider scope.
|
|
26
|
-
*/
|
|
28
|
+
});
|
|
29
|
+
/** Refreshes request identity and provider authorization. @returns The current authorized provider scope. */
|
|
27
30
|
const authorize = Effect.fn("AgentObservation.authorize")(function* () {
|
|
28
31
|
yield* httpBoundary("agent.observe.identity", () => assertExpectedIdentity(context, options.clientIdentity, input.expectedIdentity));
|
|
29
32
|
return yield* httpBoundary("agent.observe.authorize", () => agentContext({ ...input, threadId }, context, options, "observe"));
|
|
30
33
|
});
|
|
31
|
-
|
|
32
|
-
const checkpoint = input.after
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
if (state.wait) {
|
|
38
|
-
const now = yield* Clock.currentTimeMillis;
|
|
39
|
-
yield* httpBoundary("agent.observe.wait", (fiberSignal) => resolved.provider.waitForJournal({
|
|
40
|
-
...resolved.scope,
|
|
41
|
-
threadId,
|
|
42
|
-
after: state.after,
|
|
43
|
-
deadlineMs: now + 15_000,
|
|
44
|
-
signal: signal === undefined ? fiberSignal : AbortSignal.any([signal, fiberSignal]),
|
|
45
|
-
}));
|
|
46
|
-
}
|
|
47
|
-
const page = yield* observeHttp("agent.observe.read", httpBoundary("agent.observe.read", () => resolved.provider.readJournal({
|
|
48
|
-
...resolved.scope,
|
|
49
|
-
threadId,
|
|
50
|
-
after: state.after,
|
|
51
|
-
limit: 100,
|
|
52
|
-
maxEncodedBytes: 1024 * 1024,
|
|
53
|
-
})));
|
|
54
|
-
const frames = [];
|
|
55
|
-
if (page.gap !== undefined) {
|
|
56
|
-
const snapshot = clientAgentSnapshot(yield* httpBoundary("agent.observe.snapshot", () => resolved.provider.loadThread({
|
|
57
|
-
...resolved.scope,
|
|
58
|
-
threadId,
|
|
59
|
-
maxEncodedBytes: REALTIME_RUNTIME_LIMITS.initialSnapshotBytes,
|
|
60
|
-
})));
|
|
61
|
-
frames.push({ kind: "gap", reason: page.gap, snapshot });
|
|
62
|
-
return [frames, Option.some({ after: snapshot.checkpoint, wait: false })];
|
|
63
|
-
}
|
|
64
|
-
for (const record of page.records)
|
|
65
|
-
for (const event of agentClientEvents(record))
|
|
66
|
-
frames.push({ kind: "event", event });
|
|
67
|
-
if (page.records.some((record) => ["approval", "control", "terminal", "interruption"].includes(record.kind))) {
|
|
68
|
-
const snapshot = clientAgentSnapshot(yield* httpBoundary("agent.observe.snapshot", () => resolved.provider.loadThread({
|
|
69
|
-
...resolved.scope,
|
|
70
|
-
threadId,
|
|
71
|
-
maxEncodedBytes: REALTIME_RUNTIME_LIMITS.initialSnapshotBytes,
|
|
72
|
-
})));
|
|
73
|
-
frames.push({ kind: "snapshot", snapshot });
|
|
74
|
-
}
|
|
75
|
-
return [frames, Option.some({ after: page.checkpoint, wait: !page.hasMore })];
|
|
76
|
-
})).pipe(Stream.mapEffect((frame) => authorize().pipe(Effect.as(frame))));
|
|
34
|
+
yield* authorize();
|
|
35
|
+
const checkpoint = yield* Schema.decodeUnknownEffect(ObservationCheckpoint)(input.after).pipe(Effect.mapError(() => new HttpBoundaryError({
|
|
36
|
+
operation: "agent.observe",
|
|
37
|
+
cause: new TypeError("checkpoint is invalid."),
|
|
38
|
+
})));
|
|
39
|
+
return Stream.paginate({ after: checkpoint, wait: false }, (state) => readObservationPage(authorize, threadId, state, signal)).pipe(Stream.mapEffect((frame) => authorize().pipe(Effect.as(frame))));
|
|
77
40
|
}));
|
|
78
41
|
}
|
|
79
|
-
/**
|
|
80
|
-
export class AgentObservation extends Context.Service()("@relkit/runtime-hono/AgentObservation"
|
|
42
|
+
/** Per-request journal observations; service acquisition captures no request context. */
|
|
43
|
+
export class AgentObservation extends Context.Service()("@relkit/runtime-hono/AgentObservation", {
|
|
44
|
+
make: Effect.sync(() => ({
|
|
45
|
+
observe: (...args) => observeHttpStream("agent.observe", observation(...args)),
|
|
46
|
+
})),
|
|
47
|
+
}) {
|
|
81
48
|
}
|
|
82
|
-
/**
|
|
83
|
-
export const AgentObservationLive = Layer.
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
* @param input - Agent identity, thread and checkpoint.
|
|
49
|
+
/** Builds the concrete service; callers can supply the same contract through a test Layer. */
|
|
50
|
+
export const AgentObservationLive = Layer.effect(AgentObservation, AgentObservation.make);
|
|
51
|
+
/**
|
|
52
|
+
* Opens an authorized journal at the native transport edge.
|
|
53
|
+
* @param input - Submitted agent identity, thread and checkpoint.
|
|
88
54
|
* @param context - Trusted transport context.
|
|
89
|
-
* @param options -
|
|
90
|
-
* @param signal - Optional
|
|
91
|
-
* @returns
|
|
55
|
+
* @param options - Active generation dependencies.
|
|
56
|
+
* @param signal - Optional native cancellation.
|
|
57
|
+
* @returns Lazy iterable; returning joins the pending provider wait through its scope.
|
|
92
58
|
*/
|
|
93
59
|
export function observeAgent(input, context, options, signal) {
|
|
94
60
|
return httpIterable(Stream.unwrap(Effect.map(AgentObservation, (service) => service.observe(input, context, options, signal))).pipe(Stream.provide(AgentObservationLive)));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent-observation.js","sourceRoot":"","sources":["../src/agent-observation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"agent-observation.js","sourceRoot":"","sources":["../src/agent-observation.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChE,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACjF,OAAO,EAAE,YAAY,EAAE,oBAAoB,EAAmB,MAAM,wBAAwB,CAAC;AAC7F,OAAO,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AAC3D,OAAO,EAAE,qBAAqB,EAAE,MAAM,gCAAgC,CAAC;AACvE,OAAO,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AAQjE;;;;;;;GAOG;AACH,SAAS,WAAW,CAClB,KAAiB,EACjB,OAAmB,EACnB,OAAoC,EACpC,MAAoB;IAEpB,OAAO,MAAM,CAAC,MAAM,CAClB,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;QAClB,MAAM,QAAQ,GAAG,oBAAoB,CAAC,KAAK,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AC,SAAS,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,SAAS,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;IAC1E,CAAC,CAAC,CACH,CAAC;AACJ,CAAC;AAED,yFAAyF;AACzF,MAAM,OAAO,gBAAiB,SAAQ,OAAO,CAAC,OAAO,EAGlD,CAAC,uCAAuC,EAAE;IAC3C,IAAI,EAAE,MAAM,CAAC,IAAI,CACf,GAAG,EAAE,CACH,CAAC;QACC,OAAO,EAAE,CAAC,GAAG,IAAoC,EAAE,EAAE,CACnD,iBAAiB,CAAC,eAAe,EAAE,WAAW,CAAC,GAAG,IAAI,CAAC,CAAC;KAC3D,CAAsC,CAC1C;CACF,CAAC;CAAG;AAEL,8FAA8F;AAC9F,MAAM,CAAC,MAAM,oBAAoB,GAAG,KAAK,CAAC,MAAM,CAAC,gBAAgB,EAAE,gBAAgB,CAAC,IAAI,CAAC,CAAC;AAE1F;;;;;;;GAOG;AACH,MAAM,UAAU,YAAY,CAC1B,KAAiB,EACjB,OAAmB,EACnB,OAAoC,EACpC,MAAoB;IAEpB,OAAO,YAAY,CACjB,MAAM,CAAC,MAAM,CACX,MAAM,CAAC,GAAG,CAAC,gBAAgB,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC,CAC5F,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,oBAAoB,CAAC,CAAC,CAC7C,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Validates incoming journal checkpoints before observation reaches a provider.
|
|
3
|
+
* The codec mirrors the owner contract's partition fields and decimal sequence;
|
|
4
|
+
* authentication remains ahead of this promotion in the request-owned stream.
|
|
5
|
+
*/
|
|
6
|
+
import { Schema } from "effect";
|
|
7
|
+
/** Full journal identity required by provider read/wait methods. */
|
|
8
|
+
export declare const ObservationCheckpoint: Schema.Struct<{
|
|
9
|
+
readonly applicationId: Schema.String;
|
|
10
|
+
readonly environment: Schema.String;
|
|
11
|
+
readonly profile: Schema.String;
|
|
12
|
+
readonly providerEpoch: Schema.String;
|
|
13
|
+
readonly threadId: Schema.String;
|
|
14
|
+
readonly sequence: Schema.String;
|
|
15
|
+
}>;
|
|
16
|
+
//# sourceMappingURL=agent-observation.schemas.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent-observation.schemas.d.ts","sourceRoot":"","sources":["../src/agent-observation.schemas.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAKhC,oEAAoE;AACpE,eAAO,MAAM,qBAAqB;;;;;;;EAOhC,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Validates incoming journal checkpoints before observation reaches a provider.
|
|
3
|
+
* The codec mirrors the owner contract's partition fields and decimal sequence;
|
|
4
|
+
* authentication remains ahead of this promotion in the request-owned stream.
|
|
5
|
+
*/
|
|
6
|
+
import { Schema } from "effect";
|
|
7
|
+
/** Partition names are required nonempty strings, matching the transport cursor guard. */
|
|
8
|
+
const CheckpointIdentity = Schema.String.check(Schema.isMinLength(1));
|
|
9
|
+
/** Full journal identity required by provider read/wait methods. */
|
|
10
|
+
export const ObservationCheckpoint = Schema.Struct({
|
|
11
|
+
applicationId: CheckpointIdentity,
|
|
12
|
+
environment: CheckpointIdentity,
|
|
13
|
+
profile: CheckpointIdentity,
|
|
14
|
+
providerEpoch: CheckpointIdentity,
|
|
15
|
+
threadId: CheckpointIdentity,
|
|
16
|
+
sequence: Schema.String.check(Schema.isPattern(/^(0|[1-9]\d*)$/)),
|
|
17
|
+
});
|
|
18
|
+
//# sourceMappingURL=agent-observation.schemas.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent-observation.schemas.js","sourceRoot":"","sources":["../src/agent-observation.schemas.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,0FAA0F;AAC1F,MAAM,kBAAkB,GAAG,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC;AAEtE,oEAAoE;AACpE,MAAM,CAAC,MAAM,qBAAqB,GAAG,MAAM,CAAC,MAAM,CAAC;IACjD,aAAa,EAAE,kBAAkB;IACjC,WAAW,EAAE,kBAAkB;IAC/B,OAAO,EAAE,kBAAkB;IAC3B,aAAa,EAAE,kBAAkB;IACjC,QAAQ,EAAE,kBAAkB;IAC5B,QAAQ,EAAE,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,SAAS,CAAC,gBAAgB,CAAC,CAAC;CAClE,CAAC,CAAC"}
|
|
@@ -1,5 +1,16 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Shares precise public frames, page state and per-request authorization between
|
|
3
|
+
* observation workflows. Checkpoints enter these contracts only after decoding;
|
|
4
|
+
* live provider/context authority is never persisted or captured across requests.
|
|
5
|
+
*/
|
|
6
|
+
import type { agentClientEvents } from "@relkit/agents/client-events";
|
|
7
|
+
import type { JournalCheckpoint } from "@relkit/contracts";
|
|
8
|
+
import type { Effect, Stream } from "effect";
|
|
2
9
|
import type { agentContext } from "./agent-rpc-support.js";
|
|
10
|
+
import type { AgentInput } from "./agent-rpc-support.js";
|
|
11
|
+
import type { HttpBoundaryError } from "./http-effect.js";
|
|
12
|
+
import type { RpcContext } from "./rpc.js";
|
|
13
|
+
import type { RouteMaterializationOptions } from "./materialize-routes.js";
|
|
3
14
|
import type { clientAgentSnapshot } from "./agent-compatibility.js";
|
|
4
15
|
/** Public observation frames after compatibility projection and fresh authorization. */
|
|
5
16
|
export type AgentObservationFrame = {
|
|
@@ -13,4 +24,17 @@ export type AgentObservationFrame = {
|
|
|
13
24
|
readonly reason: NonNullable<Awaited<ReturnType<Awaited<ReturnType<typeof agentContext>>["provider"]["readJournal"]>>["gap"]>;
|
|
14
25
|
readonly snapshot: ReturnType<typeof clientAgentSnapshot>;
|
|
15
26
|
};
|
|
27
|
+
/** Cursor plus whether the following page must wait for new journal content. */
|
|
28
|
+
export interface ObservationPageState {
|
|
29
|
+
readonly after: JournalCheckpoint;
|
|
30
|
+
readonly wait: boolean;
|
|
31
|
+
}
|
|
32
|
+
/** Freshly authorized native provider scope for this request only. */
|
|
33
|
+
export type ObservationAccess = Awaited<ReturnType<typeof agentContext>>;
|
|
34
|
+
/** Reauthorization is repeated before pages and individual emitted frames. */
|
|
35
|
+
export type ObservationAuthorize = () => Effect.Effect<ObservationAccess, HttpBoundaryError>;
|
|
36
|
+
/** Stream service contract shared by live implementation and deterministic test Layers. */
|
|
37
|
+
export interface AgentObservationOperations {
|
|
38
|
+
readonly observe: (input: AgentInput, context: RpcContext, options: RouteMaterializationOptions, signal?: AbortSignal) => Stream.Stream<AgentObservationFrame, HttpBoundaryError>;
|
|
39
|
+
}
|
|
16
40
|
//# sourceMappingURL=agent-observation.types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent-observation.types.d.ts","sourceRoot":"","sources":["../src/agent-observation.types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"agent-observation.types.d.ts","sourceRoot":"","sources":["../src/agent-observation.types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACtE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAC3D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC7C,OAAO,KAAK,EAAE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,oBAAoB,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,iBAAiB,EAAE,iBAAiB,CAAC,CAAC;AAE7F,2FAA2F;AAC3F,MAAM,WAAW,0BAA0B;IACzC,QAAQ,CAAC,OAAO,EAAE,CAChB,KAAK,EAAE,UAAU,EACjB,OAAO,EAAE,UAAU,EACnB,OAAO,EAAE,2BAA2B,EACpC,MAAM,CAAC,EAAE,WAAW,KACjB,MAAM,CAAC,MAAM,CAAC,qBAAqB,EAAE,iBAAiB,CAAC,CAAC;CAC9D"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Performs durable duplicate lookup and revision-fenced continuation admission.
|
|
3
|
+
* The caller supplies authorized request/provider scope; validators load through
|
|
4
|
+
* their narrow entrypoint and accepted execution stays owned by generation tasks.
|
|
5
|
+
*/
|
|
6
|
+
import { type OperationId } from "@relkit/contracts";
|
|
7
|
+
import { Effect } from "effect";
|
|
8
|
+
import { HttpBoundaryError } from "./http-effect.js";
|
|
9
|
+
import { type AgentInput } from "./agent-rpc-support.js";
|
|
10
|
+
import type { RouteMaterializationOptions } from "./materialize-routes.js";
|
|
11
|
+
/**
|
|
12
|
+
* Recovers an already admitted receipt without creating a second continuation.
|
|
13
|
+
* @param input - Submitted payload used only to resume an existing accepted run.
|
|
14
|
+
* @param threadId - Authorized durable thread identity.
|
|
15
|
+
* @param operationId - Stable idempotency identity.
|
|
16
|
+
* @param resolved - Current descriptor/provider authority.
|
|
17
|
+
* @param options - Generation task owner and execution dependencies.
|
|
18
|
+
* @param requestDigest - Verified request identity for duplicate comparison.
|
|
19
|
+
* @returns Existing accepted receipt or typed missing-continuation rejection.
|
|
20
|
+
*/
|
|
21
|
+
export declare const lookupAgentContinuation: (input: AgentInput, threadId: string, operationId: OperationId, resolved: {
|
|
22
|
+
descriptor: {
|
|
23
|
+
readonly input: import("@relkit/schema").StandardSchemaV1;
|
|
24
|
+
readonly output: import("@relkit/schema").StandardSchemaV1;
|
|
25
|
+
readonly client?: unknown;
|
|
26
|
+
readonly chat?: {
|
|
27
|
+
readonly input?: unknown;
|
|
28
|
+
readonly output?: unknown;
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
node: import("@relkit/graph").AgentRegistration;
|
|
32
|
+
provider: import("@relkit/agents").AgentStateProvider;
|
|
33
|
+
scope: import("@relkit/contracts").AgentRequestScope;
|
|
34
|
+
trusted: unknown;
|
|
35
|
+
}, options: RouteMaterializationOptions, requestDigest: string) => Effect.Effect<{
|
|
36
|
+
operationId: OperationId;
|
|
37
|
+
threadId: string;
|
|
38
|
+
runId: string;
|
|
39
|
+
status: "accepted";
|
|
40
|
+
duplicate: boolean;
|
|
41
|
+
}, HttpBoundaryError, never>;
|
|
42
|
+
/**
|
|
43
|
+
* Validates the waiting revision and reply before joining and admitting a new run.
|
|
44
|
+
* @param input - Submitted revision and reply.
|
|
45
|
+
* @param threadId - Authorized durable thread identity.
|
|
46
|
+
* @param operationId - Stable idempotency identity.
|
|
47
|
+
* @param resolved - Current descriptor/provider authority.
|
|
48
|
+
* @param options - Owning generation dependencies.
|
|
49
|
+
* @param requestDigest - Verified request digest for durable admission.
|
|
50
|
+
* @param waiting - Provider-owned waiting state, never a caller assertion.
|
|
51
|
+
* @returns Accepted receipt after the interrupted run joins; typed failures preserve fencing.
|
|
52
|
+
*/
|
|
53
|
+
export declare const admitAgentContinuation: (input: AgentInput, threadId: string, operationId: OperationId, resolved: {
|
|
54
|
+
descriptor: {
|
|
55
|
+
readonly input: import("@relkit/schema").StandardSchemaV1;
|
|
56
|
+
readonly output: import("@relkit/schema").StandardSchemaV1;
|
|
57
|
+
readonly client?: unknown;
|
|
58
|
+
readonly chat?: {
|
|
59
|
+
readonly input?: unknown;
|
|
60
|
+
readonly output?: unknown;
|
|
61
|
+
};
|
|
62
|
+
};
|
|
63
|
+
node: import("@relkit/graph").AgentRegistration;
|
|
64
|
+
provider: import("@relkit/agents").AgentStateProvider;
|
|
65
|
+
scope: import("@relkit/contracts").AgentRequestScope;
|
|
66
|
+
trusted: unknown;
|
|
67
|
+
}, options: RouteMaterializationOptions, requestDigest: string, waiting: import("@relkit/contracts").AgentWaitingState) => Effect.Effect<{
|
|
68
|
+
operationId: OperationId;
|
|
69
|
+
threadId: string;
|
|
70
|
+
runId: string;
|
|
71
|
+
status: "accepted";
|
|
72
|
+
duplicate: boolean;
|
|
73
|
+
}, HttpBoundaryError, never>;
|
|
74
|
+
/**
|
|
75
|
+
* Retains the existing public validation failure at the native compatibility edge.
|
|
76
|
+
* @param message - Fixed public validation message.
|
|
77
|
+
* @returns Typed failure retaining the original public TypeError.
|
|
78
|
+
*/
|
|
79
|
+
export declare function resumeError(message: string): HttpBoundaryError;
|
|
80
|
+
//# sourceMappingURL=agent-rpc-resume-admission.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent-rpc-resume-admission.d.ts","sourceRoot":"","sources":["../src/agent-rpc-resume-admission.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAA2B,KAAK,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAE9E,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAgB,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACnE,OAAO,EAAU,KAAK,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAGjE,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,yBAAyB,CAAC;AAG3E;;;;;;;;;GASG;AACH,eAAO,MAAM,uBAAuB;;;;;;0BAmEc,CAAC;2BAEnD,CAAA;;;;;;;;;;;;;4BAhDE,CAAC;AAEH;;;;;;;;;;GAUG;AACH,eAAO,MAAM,sBAAsB;;;;;;0BAiCe,CAAC;2BAEnD,CAAA;;;;;;;;;;;;;4BAAE,CAAC;AAEH;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,iBAAiB,CAE9D"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Performs durable duplicate lookup and revision-fenced continuation admission.
|
|
3
|
+
* The caller supplies authorized request/provider scope; validators load through
|
|
4
|
+
* their narrow entrypoint and accepted execution stays owned by generation tasks.
|
|
5
|
+
*/
|
|
6
|
+
import { REALTIME_RUNTIME_LIMITS } from "@relkit/contracts";
|
|
7
|
+
import { Effect } from "effect";
|
|
8
|
+
import { httpBoundary, HttpBoundaryError } from "./http-effect.js";
|
|
9
|
+
import { digest } from "./agent-rpc-support.js";
|
|
10
|
+
import { startAgentRun } from "./agent-rpc-worker.js";
|
|
11
|
+
import { waitForAgentRun } from "./agent-run-tasks.js";
|
|
12
|
+
/**
|
|
13
|
+
* Recovers an already admitted receipt without creating a second continuation.
|
|
14
|
+
* @param input - Submitted payload used only to resume an existing accepted run.
|
|
15
|
+
* @param threadId - Authorized durable thread identity.
|
|
16
|
+
* @param operationId - Stable idempotency identity.
|
|
17
|
+
* @param resolved - Current descriptor/provider authority.
|
|
18
|
+
* @param options - Generation task owner and execution dependencies.
|
|
19
|
+
* @param requestDigest - Verified request identity for duplicate comparison.
|
|
20
|
+
* @returns Existing accepted receipt or typed missing-continuation rejection.
|
|
21
|
+
*/
|
|
22
|
+
export const lookupAgentContinuation = Effect.fn("AgentContinuations.lookup")(function* (input, threadId, operationId, resolved, options, requestDigest) {
|
|
23
|
+
const prior = yield* httpBoundary("agent.resume.receipt", () => resolved.provider.lookupContinuationReceipt({
|
|
24
|
+
...resolved.scope,
|
|
25
|
+
operationId,
|
|
26
|
+
threadId,
|
|
27
|
+
semanticDigest: requestDigest,
|
|
28
|
+
now: new Date().toISOString(),
|
|
29
|
+
}));
|
|
30
|
+
if (prior.status !== "found")
|
|
31
|
+
return yield* resumeError("Agent has no waiting continuation.");
|
|
32
|
+
const accepted = asAcceptedRun({ ...prior.receipt, duplicate: true });
|
|
33
|
+
startAgentRun(resolved, accepted, input.payload, options, true);
|
|
34
|
+
return accepted;
|
|
35
|
+
});
|
|
36
|
+
/**
|
|
37
|
+
* Validates the waiting revision and reply before joining and admitting a new run.
|
|
38
|
+
* @param input - Submitted revision and reply.
|
|
39
|
+
* @param threadId - Authorized durable thread identity.
|
|
40
|
+
* @param operationId - Stable idempotency identity.
|
|
41
|
+
* @param resolved - Current descriptor/provider authority.
|
|
42
|
+
* @param options - Owning generation dependencies.
|
|
43
|
+
* @param requestDigest - Verified request digest for durable admission.
|
|
44
|
+
* @param waiting - Provider-owned waiting state, never a caller assertion.
|
|
45
|
+
* @returns Accepted receipt after the interrupted run joins; typed failures preserve fencing.
|
|
46
|
+
*/
|
|
47
|
+
export const admitAgentContinuation = Effect.fn("AgentContinuations.admit")(function* (input, threadId, operationId, resolved, options, requestDigest, waiting) {
|
|
48
|
+
if (input.waitingRevision !== waiting.revision)
|
|
49
|
+
return yield* resumeError("Agent waiting revision is stale.");
|
|
50
|
+
const reply = yield* httpBoundary("agent.resume.validate", async () => {
|
|
51
|
+
const validators = await import("@relkit/agents/continuation-validation");
|
|
52
|
+
return validators.isGraphDescriptor(resolved.descriptor)
|
|
53
|
+
? validators.validateGraphResumeInput(resolved.descriptor, waiting.requests, input.payload)
|
|
54
|
+
: validators.validateNativeAgentResumeInput(waiting.requests, input.payload);
|
|
55
|
+
}).pipe(Effect.mapError(() => resumeError("Agent resume input validation failed.")));
|
|
56
|
+
yield* httpBoundary("agent.resume.join", () => waitForAgentRun(waiting.runId));
|
|
57
|
+
const continuation = yield* httpBoundary("agent.resume.admit", () => resolved.provider.admitContinuation({
|
|
58
|
+
...resolved.scope,
|
|
59
|
+
kind: "resume",
|
|
60
|
+
operationId,
|
|
61
|
+
semanticDigest: requestDigest,
|
|
62
|
+
threadId,
|
|
63
|
+
interruptedRunId: waiting.runId,
|
|
64
|
+
interruptSetDigest: digest(waiting),
|
|
65
|
+
waitingRevision: waiting.revision,
|
|
66
|
+
admittedAt: new Date().toISOString(),
|
|
67
|
+
receiptExpiresAt: new Date(Date.now() + REALTIME_RUNTIME_LIMITS.agentReceiptMs).toISOString(),
|
|
68
|
+
}));
|
|
69
|
+
const accepted = asAcceptedRun(continuation);
|
|
70
|
+
startAgentRun(resolved, accepted, reply, options, true);
|
|
71
|
+
return accepted;
|
|
72
|
+
});
|
|
73
|
+
/**
|
|
74
|
+
* Retains the existing public validation failure at the native compatibility edge.
|
|
75
|
+
* @param message - Fixed public validation message.
|
|
76
|
+
* @returns Typed failure retaining the original public TypeError.
|
|
77
|
+
*/
|
|
78
|
+
export function resumeError(message) {
|
|
79
|
+
return new HttpBoundaryError({ operation: "agent.resume", cause: new TypeError(message) });
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Projects a provider continuation receipt to the existing accepted-run response.
|
|
83
|
+
* @param continuation - Provider-owned durable receipt, including duplicate status.
|
|
84
|
+
* @returns Complete accepted run identity with the existing status discriminant.
|
|
85
|
+
*/
|
|
86
|
+
function asAcceptedRun(continuation) {
|
|
87
|
+
return {
|
|
88
|
+
operationId: continuation.operationId,
|
|
89
|
+
threadId: continuation.threadId,
|
|
90
|
+
runId: continuation.runId,
|
|
91
|
+
status: "accepted",
|
|
92
|
+
duplicate: continuation.duplicate,
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
//# sourceMappingURL=agent-rpc-resume-admission.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent-rpc-resume-admission.js","sourceRoot":"","sources":["../src/agent-rpc-resume-admission.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,uBAAuB,EAAoB,MAAM,mBAAmB,CAAC;AAE9E,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACnE,OAAO,EAAE,MAAM,EAAmB,MAAM,wBAAwB,CAAC;AACjE,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAAE,eAAe,EAAE,MAAM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