Skip to content

armgit / eve

Public Imported from GitHub
0

The Open Framework for Building Agents

fix(eve): derive Linq and Photon user auth (#2505)

Ben Pankowbca1304a765d
diff --git a/.changeset/linq-default-user-auth.md b/.changeset/linq-default-user-auth.md
new file mode 100644
index 000000000..0ed2fb1d4
--- /dev/null
+++ b/.changeset/linq-default-user-auth.md
@@ -0,0 +1,5 @@
+---
+"eve": patch
+---
+
+Linq and Photon inbound messages now derive user auth from their message authors, allowing user-scoped connections to request authorization by default.
diff --git a/docs/channels/linq.mdx b/docs/channels/linq.mdx
index 5e8558345..d47f98632 100644
--- a/docs/channels/linq.mdx
+++ b/docs/channels/linq.mdx
@@ -16,7 +16,7 @@ export default linqChannel({
});
```
-The default webhook route is `/eve/v1/linq`. The channel verifies forwarded webhooks with same-project Vercel OIDC by default, marks accepted messages as read, and continues the same eve session for every message in a Linq conversation. A new accepted message cooperatively cancels an active turn and steers its replacement turn.
+The default webhook route is `/eve/v1/linq`. The channel verifies forwarded webhooks with same-project Vercel OIDC by default, derives user auth from each message author, marks accepted messages as read, and continues the same eve session for every message in a Linq conversation. A new accepted message cooperatively cancels an active turn and steers its replacement turn.
Set `turnPolicy: "queue"` when every response should finish before Linq starts the next message.
diff --git a/docs/channels/photon.mdx b/docs/channels/photon.mdx
index 2642f8a19..bd491aef6 100644
--- a/docs/channels/photon.mdx
+++ b/docs/channels/photon.mdx
@@ -22,10 +22,10 @@ export default photonIMessageChannel({
```
The default webhook route is `/eve/v1/photon`. The channel verifies forwarded
-webhooks with same-project Vercel OIDC by default, marks accepted messages as
-read, and continues the same eve session for every message in an iMessage
-conversation. A new accepted message cooperatively cancels an active turn and
-steers its replacement turn.
+webhooks with same-project Vercel OIDC by default, derives user auth from each
+message author, marks accepted messages as read, and continues the same eve
+session for every message in an iMessage conversation. A new accepted message
+cooperatively cancels an active turn and steers its replacement turn.
Set `turnPolicy: "queue"` when every response should finish before Photon starts the next message.
diff --git a/packages/eve/src/public/channels/linq/index.ts b/packages/eve/src/public/channels/linq/index.ts
index 8ff44c186..92a3df568 100644
--- a/packages/eve/src/public/channels/linq/index.ts
+++ b/packages/eve/src/public/channels/linq/index.ts
@@ -1,4 +1,5 @@
export {
+ defaultLinqAuth,
linqChannel,
type LinqChannel,
type LinqChannelConfig,
diff --git a/packages/eve/src/public/channels/linq/linqChannel.test.ts b/packages/eve/src/public/channels/linq/linqChannel.test.ts
index 12056fe34..ff26596f4 100644
--- a/packages/eve/src/public/channels/linq/linqChannel.test.ts
+++ b/packages/eve/src/public/channels/linq/linqChannel.test.ts
@@ -58,7 +58,18 @@ describe("linqChannel", () => {
expect(markRead).toHaveBeenCalledWith(thread.id, message.id);
expect(send).toHaveBeenCalledWith(
{ context: [], message: "Hello Linq" },
- { auth: null, thread, title: undefined },
+ {
+ auth: {
+ attributes: { user_name: "user" },
+ authenticator: "linq-message",
+ issuer: "linq",
+ principalId: "linq:user",
+ principalType: "user",
+ subject: "user",
+ },
+ thread,
+ title: undefined,
+ },
);
});
diff --git a/packages/eve/src/public/channels/linq/linqChannel.ts b/packages/eve/src/public/channels/linq/linqChannel.ts
index 12401d00d..297bda8af 100644
--- a/packages/eve/src/public/channels/linq/linqChannel.ts
+++ b/packages/eve/src/public/channels/linq/linqChannel.ts
@@ -58,7 +58,7 @@ export interface LinqChannelConfig {
readonly credentials?: LinqChannelCredentials;
/** Per-event overrides for the underlying Chat SDK channel. */
readonly events?: ChatSdkChannelEvents<{ linq: ReturnType<typeof createLinqAdapter> }>;
- /** Inbound message policy. Defaults to dispatching every message with no user auth. */
+ /** Inbound message policy. Defaults to dispatching with the Linq message author's user auth. */
readonly onMessage?: (
ctx: LinqInboundMessageContext,
message: Message,
@@ -150,8 +150,25 @@ async function resolveCredentialValue(value: LinqCredentialValue): Promise<strin
return typeof value === "function" ? await value() : value;
}
-async function defaultOnMessage(): Promise<LinqInboundResult> {
- return { auth: null };
+/** Default Linq auth projection for inbound Chat SDK message authors. */
+export function defaultLinqAuth(message: Message): SessionAuthContext {
+ const attributes: Record<string, string> = {};
+ if (message.author.userName !== undefined) attributes.user_name = message.author.userName;
+ return {
+ attributes,
+ authenticator: "linq-message",
+ issuer: "linq",
+ principalId: `linq:${message.author.userId}`,
+ principalType: message.author.isBot ? "service" : "user",
+ subject: message.author.userId,
+ };
+}
+
+async function defaultOnMessage(
+ _ctx: LinqInboundMessageContext,
+ message: Message,
+): Promise<LinqInboundResult> {
+ return { auth: defaultLinqAuth(message) };
}
async function dispatchMessage(
diff --git a/packages/eve/src/public/channels/photon/index.ts b/packages/eve/src/public/channels/photon/index.ts
index 249b38e0c..e81e86a6e 100644
--- a/packages/eve/src/public/channels/photon/index.ts
+++ b/packages/eve/src/public/channels/photon/index.ts
@@ -1,4 +1,5 @@
export {
+ defaultPhotonAuth,
photonIMessageChannel,
type PhotonIMessageChannel,
type PhotonIMessageChannelConfig,
diff --git a/packages/eve/src/public/channels/photon/photonIMessageChannel.test.ts b/packages/eve/src/public/channels/photon/photonIMessageChannel.test.ts
index af7f6e16c..6a0e471f0 100644
--- a/packages/eve/src/public/channels/photon/photonIMessageChannel.test.ts
+++ b/packages/eve/src/public/channels/photon/photonIMessageChannel.test.ts
@@ -58,6 +58,40 @@ describe("photonIMessageChannel", () => {
);
});
+ it("derives user auth for default direct-message dispatch", async () => {
+ photonIMessageChannel({
+ credentials: async () => ({ projectId: "project-id", projectSecret: "project-secret" }),
+ });
+ const handler = directMessage.mock.calls[0]?.[0];
+ if (handler === undefined) throw new Error("Expected an inbound direct-message handler.");
+ const thread = { id: "thread-id" };
+ const message = new Message({
+ author: { isBot: false, isMe: false, userId: "user", userName: "user" },
+ id: "message-id",
+ raw: {},
+ text: "Hello Photon",
+ threadId: thread.id,
+ });
+
+ await handler(thread, message);
+
+ expect(send).toHaveBeenCalledWith(
+ { context: [], message: "Hello Photon" },
+ {
+ auth: {
+ attributes: { user_name: "user" },
+ authenticator: "photon-imessage",
+ issuer: "photon",
+ principalId: "photon:user",
+ principalType: "user",
+ subject: "user",
+ },
+ thread,
+ title: undefined,
+ },
+ );
+ });
+
it("drops blank inbound messages without cancelling or sending", async () => {
photonIMessageChannel({
credentials: async () => ({ projectId: "project-id", projectSecret: "project-secret" }),
@@ -100,7 +134,18 @@ describe("photonIMessageChannel", () => {
expect(send).toHaveBeenCalledWith(
{ context: [], message: "Hello group" },
- { auth: null, thread, title: undefined },
+ {
+ auth: {
+ attributes: { user_name: "user" },
+ authenticator: "photon-imessage",
+ issuer: "photon",
+ principalId: "photon:user",
+ principalType: "user",
+ subject: "user",
+ },
+ thread,
+ title: undefined,
+ },
);
});
});
diff --git a/packages/eve/src/public/channels/photon/photonIMessageChannel.ts b/packages/eve/src/public/channels/photon/photonIMessageChannel.ts
index f0ba2d96a..ddc63f866 100644
--- a/packages/eve/src/public/channels/photon/photonIMessageChannel.ts
+++ b/packages/eve/src/public/channels/photon/photonIMessageChannel.ts
@@ -42,7 +42,7 @@ export interface PhotonIMessageChannelConfig {
readonly credentials: PhotonIMessageChannelCredentials;
/** Per-event overrides for the underlying Chat SDK channel. */
readonly events?: ChatSdkChannelEvents<{ imessage: iMessageAdapter }>;
- /** Inbound message policy. Defaults to dispatching every message with no user auth. */
+ /** Inbound message policy. Defaults to dispatching with the Photon message author's user auth. */
readonly onMessage?: (
ctx: PhotonInboundMessageContext,
message: Message,
@@ -107,8 +107,25 @@ export function photonIMessageChannel(config: PhotonIMessageChannelConfig): Phot
return bridge.channel;
}
-async function defaultOnMessage(): Promise<PhotonInboundResult> {
- return { auth: null };
+/** Default Photon auth projection for inbound Chat SDK message authors. */
+export function defaultPhotonAuth(message: Message): SessionAuthContext {
+ const attributes: Record<string, string> = {};
+ if (message.author.userName !== undefined) attributes.user_name = message.author.userName;
+ return {
+ attributes,
+ authenticator: "photon-imessage",
+ issuer: "photon",
+ principalId: `photon:${message.author.userId}`,
+ principalType: message.author.isBot ? "service" : "user",
+ subject: message.author.userId,
+ };
+}
+
+async function defaultOnMessage(
+ _ctx: PhotonInboundMessageContext,
+ message: Message,
+): Promise<PhotonInboundResult> {
+ return { auth: defaultPhotonAuth(message) };
}
async function dispatchMessage(