Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 21 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,14 @@ Gotchas:

## Link wallet

> [!NOTE]
> Link purchases are temporarily disabled. No release of
> `@stripe/link-integrations-eve` is built for eve 1.0 yet, and eve 1.0 refuses
> to load extensions built with 0.83 or earlier. Users can still connect a
> wallet. To re-enable purchases once Stripe ships a 1.0-compatible release,
> restore `agent/extensions/link.ts`, the `link__*` coordinator tools, and the
> Link purchase instructions in `agent/instructions/content/worker-coordination.md`.

Link lets users approve purchases from their own wallet. It is optional and
requires separate setup after deployment; the deploy button does not configure
it. Stripe currently supports Link Agent Wallet for US and Canadian consumers.
Expand Down Expand Up @@ -274,14 +282,19 @@ require additional financial-data scopes and connected-source permissions.
<details>
<summary>Eve version and active-session compatibility</summary>

This repository pins Eve `0.66.3` and the published Link extension `0.2.4`.
The extension's tool contract is supported directly, so it needs no compatibility
rebuild. Browser work uses the background workflow and `agentId` continuation
APIs supported by this Eve version.

Keep active sessions on their owning deployment until they finish; do not move
an Eve `0.69` session onto this `0.66.3` deployment. Start a new conversation
after changing Eve versions.
This repository pins Eve `1.0.0-rc.1`. Eve 1.0 refuses to load extensions
built with Eve 0.83 or earlier, so the Link extension is disabled until Stripe
ships a compatible release (see [Link wallet](#link-wallet)). Browser work uses
the resumable `run_browser` task: the coordinator continues a worker by its
`taskId` and stops one with `eve__task_cancel`.

Sessions started on Eve 0.69 through 0.83 move to a 1.0 deployment on their
own when they next receive a message, and Eve compacts their earlier
conversation. Sessions started on this repository's previous Eve `0.66.3`
deployment predate 0.69 and never move: keep that deployment running until
they finish, and start a new conversation for new work. A scheduled run that
was waiting for the user's answer when you deploy stores the old request
format; re-run it after the upgrade.

</details>

Expand Down
39 changes: 20 additions & 19 deletions agent/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,29 @@ import { getGatewayModel } from "@db/services/settings";
import { scopeFromPrincipal } from "@agent/lib/principal-scope";

export default defineAgent({
build: {
// The browser-agent subagent's Browser Loop tools load this at runtime.
externalDependencies: ["@onkernel/browser-loop"],
},
defaultTools: false,
model: defineDynamic({
events: {
"step.started": async (_event, ctx) => {
const scheduledRun = scheduledRunIdentity(ctx.session.auth);
if (
scheduledRun &&
!(await isScheduledAgentRunLeaseActive(
scheduledRun.runId,
scheduledRun.leaseToken
))
) {
throw new Error("The scheduled run lease is no longer active.");
}
const caller = ctx.session.auth.current ?? ctx.session.auth.initiator;
if (!caller) throw new Error("An authenticated user is required.");
return getGatewayModel(scopeFromPrincipal(caller));
},
},
// eve resolves this before every model call, so the lease is rechecked per step.
model: defineDynamic(async (ctx) => {
const scheduledRun = scheduledRunIdentity(ctx.session.auth);
if (
scheduledRun &&
!(await isScheduledAgentRunLeaseActive(
scheduledRun.runId,
scheduledRun.leaseToken
))
) {
throw new Error("The scheduled run lease is no longer active.");
}
const caller = ctx.session.auth.current ?? ctx.session.auth.initiator;
if (!caller) throw new Error("An authenticated user is required.");
return getGatewayModel(scopeFromPrincipal(caller));
}),
reasoning: "low",
compaction: {
thresholdPercent: 0.7,
threshold: 0.7,
},
});
58 changes: 36 additions & 22 deletions agent/channels/eve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
} from "@shared/identity/access-scope";
import { getAuthSession } from "@db/services/auth/session";
import { sendMessageToolResultSchema } from "@shared/chat/message-delivery";
import { settledToolResult } from "@agent/lib/settled-tool-result";
import {
finalizeScheduledReportDelivery,
releaseScheduledReportDelivery,
Expand Down Expand Up @@ -70,32 +71,42 @@ const authenticate: Parameters<typeof routeAuth>[1] = [
const channel = eveChannel({
auth: authenticate,
events: {
async "action.result"(event, _channel, session) {
const message = sendMessageToolResultSchema.safeParse(event.result);
if (event.status === "completed" && message.success) {
await finalizeScheduledReportDelivery(session);
async "call.settled"(event, ctx) {
const message = sendMessageToolResultSchema.safeParse(
settledToolResult(event, ctx.view)
);
if (message.success) {
await finalizeScheduledReportDelivery(ctx);
}
},
async "message.completed"(event, _channel, session) {
if (event.finishReason === "tool-calls") return;
if (scheduledReportFromSession(session)) {
await finalizeScheduledReportDelivery(session, "suppressed");
async "turn.settled"(event, ctx) {
switch (event.data.outcome) {
case "completed":
if (scheduledReportFromSession(ctx)) {
await finalizeScheduledReportDelivery(ctx, "suppressed");
}
return;
case "cancelled":
await releaseScheduledReportDelivery(
ctx,
"Scheduled result reporting was cancelled."
);
return;
case "failed":
await releaseScheduledReportDelivery(
ctx,
event.data.error?.message ?? "The scheduled report turn failed."
);
return;
default:
return;
}
},
async "session.completed"(_event, _channel, session) {
if (scheduledReportFromSession(session)) {
await finalizeScheduledReportDelivery(session, "suppressed");
async "session.ended"(_event, ctx) {
if (scheduledReportFromSession(ctx)) {
await finalizeScheduledReportDelivery(ctx, "suppressed");
}
},
async "turn.cancelled"(_event, _channel, session) {
await releaseScheduledReportDelivery(
session,
"Scheduled result reporting was cancelled."
);
},
async "turn.failed"(event, _channel, session) {
await releaseScheduledReportDelivery(session, event.message);
},
},
});

Expand All @@ -105,7 +116,6 @@ const ownedCallbackRoutes = new Set([
"/eve/v1/connections/:name/callback/:attemptId/:token",
"/eve/v1/connections/:name/callback/:token",
"/eve/v1/callback/:token",
"/eve/v1/task-input/:token",
]);

export default {
Expand All @@ -131,7 +141,11 @@ export default {

// Routes without a session subject. Every other eve route must name a session
// this caller owns, either in the path or inside a hook token.
const subjectFreeRoutes = new Set(["/eve/v1/info", "/eve/v1/session"]);
const subjectFreeRoutes = new Set([
"/eve/v1/health",
"/eve/v1/info",
"/eve/v1/session",
]);

async function requireOwnedRouteSubject(scope: AccessScope, request: Request) {
const { pathname } = new URL(request.url);
Expand Down
96 changes: 51 additions & 45 deletions agent/channels/linq.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { scopeFromPrincipal } from "@agent/lib/principal-scope";
import { getAuth } from "@db/services/auth";
import { sendMessageToolResultSchema } from "@shared/chat/message-delivery";
import { reactToMessageToolResultSchema } from "@shared/chat/reaction";
import { settledToolResult } from "@agent/lib/settled-tool-result";
import { accessScopeForUser } from "@shared/identity/access-scope";
import { normalizeAuthPhoneNumber } from "@shared/identity/phone-number";
import { prepareLinqImageArtifactDelivery } from "../lib/linq-image-artifact/delivery";
Expand Down Expand Up @@ -59,17 +60,26 @@ const credentials = {
export default linqChannel({
credentials,
events: {
async "authorization.required"(event, context, session) {
const { thread } = context;
if (!thread || event.candidateId !== undefined) return;
const displayName = event.authorization?.displayName ?? event.name;
async "interaction.opened"(event, ctx) {
const { origin, request } = event.data;
const { thread } = ctx.channel;
// Approvals and questions render through the default committed handler;
// delegated sign-ins stay out of the root conversation.
if (
request.kind !== "sign-in" ||
!thread ||
(origin !== undefined && origin.sessionId !== ctx.session.id)
)
return;
const signIn = request.signIn;
const displayName = signIn?.displayName ?? signIn?.name ?? "this account";
if (!thread.isDM) {
await thread.post({
raw: `Connect ${displayName} in a direct message with this agent.`,
});
return;
}
const adapter = context.bot.getAdapter("linq");
const adapter = ctx.channel.bot.getAdapter("linq");
const { chatId, pendingHandle } = adapter.decodeThreadId(thread.id);
if (!chatId || pendingHandle)
throw new Error(
Expand All @@ -79,35 +89,31 @@ export default linqChannel({
{
type: "text",
value: [
event.authorization?.instructions ??
`Connect ${displayName} to continue.`,
event.authorization?.userCode
? `Code: ${event.authorization.userCode}`
: undefined,
signIn?.instructions ?? `Connect ${displayName} to continue.`,
signIn?.userCode ? `Code: ${signIn.userCode}` : undefined,
]
.filter(Boolean)
.join("\n\n"),
},
];
const idempotencyKey = `authorization:${session.session.id}:${event.attemptId ?? `${event.turnId}:${event.name}`}`;
const result = await sendNativeLinqMessage(chatId, {
const idempotencyKey = `authorization:${ctx.session.id}:${event.data.interactionId}`;
await sendNativeLinqMessage(chatId, {
parts,
idempotency_key: `${idempotencyKey}:prompt`,
});
context.state.pendingAuthMessageIds = {
...context.state.pendingAuthMessageIds,
[event.name]: result.message.id,
};
// Linq requires a native link to be the message's only part.
if (event.authorization?.url)
if (signIn?.url)
await sendNativeLinqMessage(chatId, {
parts: [{ type: "link", value: event.authorization.url }],
parts: [{ type: "link", value: signIn.url }],
idempotency_key: `${idempotencyKey}:link`,
});
},
async "action.result"(event, context, session) {
const reaction = reactToMessageToolResultSchema.safeParse(event.result);
if (event.status === "completed" && reaction.success) {
async "call.settled"(event, ctx) {
const context = ctx.channel;
const session = ctx;
const result = settledToolResult(event, ctx.view);
const reaction = reactToMessageToolResultSchema.safeParse(result);
if (reaction.success) {
if (!context.thread) {
throw new Error(
"react_to_message requires an active Linq conversation thread."
Expand Down Expand Up @@ -143,12 +149,8 @@ export default linqChannel({
return;
}

const message = sendMessageToolResultSchema.safeParse(event.result);
if (
event.status === "completed" &&
message.success &&
message.data.toolName === "send_message"
) {
const message = sendMessageToolResultSchema.safeParse(result);
if (message.success && message.data.toolName === "send_message") {
const { thread } = context;
if (!thread) {
throw new Error(
Expand Down Expand Up @@ -309,28 +311,32 @@ export default linqChannel({
await finalizeScheduledReportDelivery(session);
}
},
async "message.completed"(event, _context, session) {
if (event.finishReason === "tool-calls") return;
const report = scheduledReportFromSession(session);
if (report) {
await finalizeScheduledReportDelivery(session, "suppressed");
// Linq output is delivered only through send_message, so the default
// reply posting is replaced with a no-op.
// oxlint-disable-next-line eslint/no-empty-function -- Overriding the built-in handler suppresses automatic reply posting.
async "content.completed"() {},
async "session.ended"(_event, ctx) {
if (scheduledReportFromSession(ctx)) {
await finalizeScheduledReportDelivery(ctx, "suppressed");
}
},
async "session.completed"(_event, _context, session) {
const report = scheduledReportFromSession(session);
if (report) {
await finalizeScheduledReportDelivery(session, "suppressed");
async "turn.settled"(event, ctx) {
if (event.data.outcome === "completed") {
if (scheduledReportFromSession(ctx)) {
await finalizeScheduledReportDelivery(ctx, "suppressed");
}
} else if (event.data.outcome === "cancelled") {
await releaseScheduledReportDelivery(
ctx,
"Scheduled result reporting was cancelled."
);
} else {
await releaseScheduledReportDelivery(
ctx,
event.data.error?.message ?? "The scheduled report turn failed."
);
}
},
async "turn.cancelled"(_event, _context, session) {
await releaseScheduledReportDelivery(
session,
"Scheduled result reporting was cancelled."
);
},
async "turn.failed"(event, _context, session) {
await releaseScheduledReportDelivery(session, event.message);
},
},
async onMessage(context, message) {
if (message.author.isBot) return null;
Expand Down
Loading
Loading