@springbrand/agent-runtime 0.3.0-alpha.22 → 0.3.0-alpha.23
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/canonical-context.d.ts +661 -0
- package/dist/canonical-context.js +122 -0
- package/package.json +12 -4
- package/scripts/build-canonical-context.mjs +38 -0
- package/src/adapter/cloudflare/agent.ts +2 -2
- package/src/adapter/cloudflare/define-agent.ts +3 -5
- package/src/config/public-contracts.ts +1 -0
- package/src/conversation/canonical-context.ts +144 -0
- package/src/conversation/history.ts +41 -45
- package/src/conversation/message/contract.ts +2 -11
- package/src/conversation/message/conversion.ts +3 -5
- package/src/conversation/message/user-sidecar.ts +7 -0
- package/src/conversation/native-extensions.ts +13 -0
- package/src/index.ts +1 -1
- package/src/models/openrouter/protocol-response.ts +1 -11
- package/src/submission/steer-delivery.ts +4 -2
|
@@ -9,20 +9,10 @@ import {
|
|
|
9
9
|
} from "@earendil-works/pi-ai";
|
|
10
10
|
import type { RuntimeModelProtocol } from "../../config/ports";
|
|
11
11
|
import { overlayProviderStreams } from "../provider-streams";
|
|
12
|
+
import type { ModelProtocolResponse } from "../../conversation/canonical-context";
|
|
12
13
|
|
|
13
14
|
export type OpenRouterProtocol = Extract<RuntimeModelProtocol, `openrouter-${string}`>;
|
|
14
15
|
|
|
15
|
-
/** Native output required by OpenRouter's stateless continuation. */
|
|
16
|
-
export interface ModelProtocolResponse {
|
|
17
|
-
readonly output: readonly Readonly<Record<string, unknown>>[];
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
declare module "@earendil-works/pi-ai" {
|
|
21
|
-
interface AssistantMessage {
|
|
22
|
-
protocolResponse?: ModelProtocolResponse;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
16
|
function record(value: unknown): Record<string, unknown> | undefined {
|
|
27
17
|
return value !== null && typeof value === "object" && !Array.isArray(value)
|
|
28
18
|
? value as Record<string, unknown>
|
|
@@ -6,6 +6,7 @@ import type { SubmitMessageOptions } from "./admission";
|
|
|
6
6
|
import type { SubmissionHandle } from "./lifecycle";
|
|
7
7
|
import { submissionAbortReason, type StoredSubmission, type SubmissionRepository } from "./repository";
|
|
8
8
|
import type { PiCanonicalUserInput } from "../conversation/message/contract";
|
|
9
|
+
import { captureUIUserSidecar } from "../conversation/message/conversion";
|
|
9
10
|
import type { MessageUiRepository } from "../conversation/repository";
|
|
10
11
|
import type { PendingSteer, SteerRepository } from "./steer-repository";
|
|
11
12
|
|
|
@@ -70,6 +71,7 @@ export async function finishPendingSteers(options: {
|
|
|
70
71
|
const userMessage = steer.uiMessageJson
|
|
71
72
|
? JSON.parse(steer.uiMessageJson) as UIMessage & { role: "user" }
|
|
72
73
|
: undefined;
|
|
74
|
+
const userSidecar = userMessage ? { id: userMessage.id, ...captureUIUserSidecar(userMessage) } : undefined;
|
|
73
75
|
const requestId = `${options.submissionId}:steer:${steer.steerId}`;
|
|
74
76
|
if (options.aborted) {
|
|
75
77
|
const owner = options.transaction(() => {
|
|
@@ -81,7 +83,7 @@ export async function finishPendingSteers(options: {
|
|
|
81
83
|
}
|
|
82
84
|
return handoff?.status === "aborted" || handoff?.status === "skipped" ? handoff.submissionId : options.submissionId;
|
|
83
85
|
});
|
|
84
|
-
await options.conversation.append(steer.messageId, message, { submissionId: owner, ...(
|
|
86
|
+
await options.conversation.append(steer.messageId, message, { submissionId: owner, ...(userSidecar ? { userSidecar } : {}) });
|
|
85
87
|
options.transaction(() => {
|
|
86
88
|
if (steer.harnessEntryId) options.messageUi.delete(steer.harnessEntryId);
|
|
87
89
|
options.steers.deleteByMessageId(steer.messageId);
|
|
@@ -117,7 +119,7 @@ export async function finishPendingSteers(options: {
|
|
|
117
119
|
}
|
|
118
120
|
return current;
|
|
119
121
|
});
|
|
120
|
-
if (handoff.status === "skipped" || handoff.status === "aborted") await options.conversation.append(steer.messageId, message, { submissionId: handoff.submissionId, ...(
|
|
122
|
+
if (handoff.status === "skipped" || handoff.status === "aborted") await options.conversation.append(steer.messageId, message, { submissionId: handoff.submissionId, ...(userSidecar ? { userSidecar } : {}) });
|
|
121
123
|
options.transaction(() => options.steers.deleteByMessageId(steer.messageId));
|
|
122
124
|
}
|
|
123
125
|
}
|