Skip to content

armgit / eve

Public Imported from GitHub
0

The Open Framework for Building Agents

fix(eve): preserve configured channel turn policy (#2173)

vercel-gh-bot-3[bot]542c380eec6e
diff --git a/.changeset/tidy-channel-turn-policy.md b/.changeset/tidy-channel-turn-policy.md
new file mode 100644
index 000000000..ef9ecf782
--- /dev/null
+++ b/.changeset/tidy-channel-turn-policy.md
@@ -0,0 +1,5 @@
+---
+"eve": patch
+---
+
+Preserve the configured `turnPolicy` on built-in and custom channels, and restore the option for Slack channels.
diff --git a/packages/eve/extension-contracts/compatibility/channel/v3.ts b/packages/eve/extension-contracts/compatibility/channel/v3.ts
new file mode 100644
index 000000000..cc473da47
--- /dev/null
+++ b/packages/eve/extension-contracts/compatibility/channel/v3.ts
@@ -0,0 +1,13 @@
+import { defineChannel, POST } from "#public/definitions/channel.js";
+
+export default defineChannel({
+ routes: [POST("/input", async () => new Response("ok"))],
+ events: {
+ "input.requested"(data) {
+ console.info(
+ "input requested",
+ data.requests.map((request) => request.requestId),
+ );
+ },
+ },
+});
diff --git a/packages/eve/extension-contracts/reports/channel/v4.json b/packages/eve/extension-contracts/reports/channel/v4.json
new file mode 100644
index 000000000..6fd2593bb
--- /dev/null
+++ b/packages/eve/extension-contracts/reports/channel/v4.json
@@ -0,0 +1,17 @@
+{
+ "kind": "eve-extension-capability-contract",
+ "capability": "channel",
+ "epoch": 4,
+ "sha256": "ad14e519a02919616483b3a996286b11092b424ee3f8a18975b1dbb67fe6d475",
+ "exports": [
+ "DELETE",
+ "GET",
+ "PATCH",
+ "POST",
+ "PUT",
+ "WS",
+ "createWebSocketUpgradeServer",
+ "defineChannel",
+ "isChannel"
+ ]
+}
diff --git a/packages/eve/src/compiler/extension-compatibility.ts b/packages/eve/src/compiler/extension-compatibility.ts
index b5af79650..ca8a86ccd 100644
--- a/packages/eve/src/compiler/extension-compatibility.ts
+++ b/packages/eve/src/compiler/extension-compatibility.ts
@@ -27,7 +27,7 @@ const EXTENSION_CAPABILITY_CONTRACTS = {
supported: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18],
dropped: {},
},
- channel: { current: 3, supported: [1, 2, 3], dropped: {} },
+ channel: { current: 4, supported: [1, 2, 3, 4], dropped: {} },
schedule: { current: 2, supported: [1, 2], dropped: {} },
subagent: { current: 2, supported: [1, 2], dropped: {} },
connection: { current: 5, supported: [1, 2, 3, 4, 5], dropped: {} },
diff --git a/packages/eve/src/public/channels/slack/slackChannel.test.ts b/packages/eve/src/public/channels/slack/slackChannel.test.ts
index 8ec1d4206..cf9c23a5d 100644
--- a/packages/eve/src/public/channels/slack/slackChannel.test.ts
+++ b/packages/eve/src/public/channels/slack/slackChannel.test.ts
@@ -329,6 +329,14 @@ async function firePost(
return { cancel, reset, response, send, waitUntil };
}
+describe("slackChannel()", () => {
+ it("preserves the configured turn policy", () => {
+ const channel = slackChannel({ turnPolicy: "queue" });
+
+ expect(channel).toMatchObject({ turnPolicy: "queue" });
+ });
+});
+
describe("slackChannel() default event handlers", () => {
let fetchMock: ReturnType<typeof vi.fn>;
beforeEach(() => {
diff --git a/packages/eve/src/public/channels/slack/slackChannel.ts b/packages/eve/src/public/channels/slack/slackChannel.ts
index 27d44dde9..e90d15338 100644
--- a/packages/eve/src/public/channels/slack/slackChannel.ts
+++ b/packages/eve/src/public/channels/slack/slackChannel.ts
@@ -8,7 +8,7 @@ import type {
} from "#channel/channel-operations.js";
import { defaultDeliverResult } from "#channel/adapter.js";
import type { Session, SessionHandle } from "#channel/session.js";
-import type { SessionAuthContext } from "#channel/types.js";
+import type { SessionAuthContext, TurnPolicy } from "#channel/types.js";
import type { CardElement } from "#compiled/chat/index.js";
import type { SessionContext } from "#public/definitions/callback-context.js";
import type { ChannelContinuationOps } from "#public/definitions/channel.js";
@@ -531,6 +531,8 @@ export interface SlackChannelConfig {
/** Override the default webhook route path (`/eve/v1/slack`). */
readonly route?: string;
+ /** Policy for accepted messages that arrive while a turn is active. */
+ readonly turnPolicy?: TurnPolicy;
/**
* Inbound upload policy applied to file attachments before they reach
@@ -747,6 +749,7 @@ export function slackChannel(config: SlackChannelConfig = {}): SlackChannel {
SlackInstrumentationMetadata
>({
kindHint: "slack",
+ turnPolicy: config.turnPolicy,
state: {
channelId: null as string | null,
threadTs: null as string | null,
diff --git a/packages/eve/src/public/definitions/channel.test.ts b/packages/eve/src/public/definitions/channel.test.ts
index 637345b90..068a46b58 100644
--- a/packages/eve/src/public/definitions/channel.test.ts
+++ b/packages/eve/src/public/definitions/channel.test.ts
@@ -35,6 +35,15 @@ function getAdapter(channel: unknown): ChannelAdapter<any> {
}
describe("defineChannel", () => {
+ it("preserves the configured turn policy", () => {
+ const channel = defineChannel({
+ routes: [POST("/x", async () => new Response("ok"))],
+ turnPolicy: "queue",
+ });
+
+ expect(channel).toMatchObject({ turnPolicy: "queue" });
+ });
+
it("returns the bare passthrough adapter when nothing is configured", () => {
const channel = defineChannel({ routes: [POST("/x", async () => new Response("ok"))] });
diff --git a/packages/eve/src/public/definitions/channel.ts b/packages/eve/src/public/definitions/channel.ts
index 5c96917a3..82fbc7f72 100644
--- a/packages/eve/src/public/definitions/channel.ts
+++ b/packages/eve/src/public/definitions/channel.ts
@@ -17,7 +17,7 @@ import type {
} from "#channel/channel-operations.js";
import type { RouteDefinition } from "#channel/routes.js";
import type { Session, SessionHandle } from "#channel/session.js";
-import type { DeliverPayload } from "#channel/types.js";
+import type { DeliverPayload, TurnPolicy } from "#channel/types.js";
import { buildCallbackContext } from "#context/build-callback-context.js";
import type { UnstampedMessageStreamEvent } from "#protocol/message.js";
import type { SessionContext } from "#public/definitions/callback-context.js";
@@ -250,6 +250,7 @@ export interface Channel<
input: ReceiveInput<TReceiveTarget>,
ctx: ChannelReceiveContext<TState>,
) => Promise<Session>;
+ readonly turnPolicy?: TurnPolicy;
}
/**
@@ -282,6 +283,7 @@ export function defineChannel<
adapter,
cors,
receive: definition.receive,
+ turnPolicy: definition.turnPolicy,
};
return compiled;
diff --git a/packages/eve/test/scenarios/mounted-extension-installed.scenario.test.ts b/packages/eve/test/scenarios/mounted-extension-installed.scenario.test.ts
index 88640a372..1fe940260 100644
--- a/packages/eve/test/scenarios/mounted-extension-installed.scenario.test.ts
+++ b/packages/eve/test/scenarios/mounted-extension-installed.scenario.test.ts
@@ -249,7 +249,7 @@ describe("mounted extension installed under node_modules", () => {
);
expect(
JSON.parse(extensionFiles[`node_modules/${PACKAGE_NAME}/dist/extension/_manifest.json`]!),
- ).toMatchObject({ requires: { channel: 3, schedule: 2, subagent: 2 } });
+ ).toMatchObject({ requires: { channel: 4, schedule: 2, subagent: 2 } });
const app = await scenarioApp({
name: "mounted-extension-installed",
installDependencies: true,