-
Notifications
You must be signed in to change notification settings - Fork 18
feat: port email + whatsapp + teams + webex + signal channel adapters from TS to Rust #58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
b97467d
feat: port email channel adapter from TS to Rust
rohitg00 45fd955
feat: port whatsapp channel adapter from TS to Rust
rohitg00 891ae30
feat: port teams channel adapter from TS to Rust
rohitg00 e3682da
feat: port webex channel adapter from TS to Rust
rohitg00 893a60d
feat: port signal channel adapter from TS to Rust
rohitg00 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,164 @@ | ||
| // @ts-nocheck | ||
| import { describe, it, expect, vi, beforeEach, beforeAll } from "vitest"; | ||
|
|
||
| const mockTrigger = vi.fn(async (fnId: string, data?: any): Promise<any> => { | ||
| if (fnId === "agent::chat") return { content: "Reply" }; | ||
| return null; | ||
| }); | ||
| const mockTriggerVoid = vi.fn(); | ||
|
|
||
| const handlers: Record<string, Function> = {}; | ||
| vi.mock("iii-sdk", () => ({ | ||
| registerWorker: () => ({ | ||
| registerFunction: (config: any, handler: Function) => { | ||
| handlers[config.id] = handler; | ||
| }, | ||
| registerTrigger: vi.fn(), | ||
| trigger: (req: any) => | ||
| req.action | ||
| ? mockTriggerVoid(req.function_id, req.payload) | ||
| : mockTrigger(req.function_id, req.payload), | ||
| shutdown: vi.fn(), | ||
| }), | ||
| TriggerAction: { Void: () => ({}) }, | ||
| })); | ||
|
|
||
| vi.mock("@agentos/shared/utils", () => ({ | ||
| httpOk: (req: any, data: any) => data, | ||
| splitMessage: vi.fn((text: string, limit: number) => { | ||
| const chunks: string[] = []; | ||
| for (let i = 0; i < text.length; i += limit) | ||
| chunks.push(text.slice(i, i + limit)); | ||
| return chunks.length ? chunks : [text]; | ||
| }), | ||
| resolveAgent: vi.fn(async () => "default-agent"), | ||
| })); | ||
|
|
||
| const mockFetch = vi.fn(async () => ({ | ||
| ok: true, | ||
| json: async () => ({ | ||
| text: "Fetched message", | ||
| id: "msg-1", | ||
| accessJwt: "jwt", | ||
| did: "did:plc:test", | ||
| }), | ||
| })); | ||
| vi.stubGlobal("fetch", mockFetch); | ||
|
|
||
| beforeEach(() => { | ||
| mockTrigger.mockReset(); | ||
| mockTrigger.mockImplementation( | ||
| async (fnId: string, data?: any): Promise<any> => { | ||
| if (fnId === "agent::chat") return { content: "Reply" }; | ||
| return null; | ||
| }, | ||
| ); | ||
| mockTriggerVoid.mockClear(); | ||
| mockFetch.mockClear(); | ||
| mockFetch.mockImplementation(async () => ({ | ||
| ok: true, | ||
| json: async () => ({ | ||
| text: "Fetched message", | ||
| id: "msg-1", | ||
| accessJwt: "jwt", | ||
| did: "did:plc:test", | ||
| }), | ||
| })); | ||
| }); | ||
|
|
||
| beforeAll(async () => { | ||
| process.env.BLUESKY_HANDLE = "test.bsky.social"; | ||
| process.env.BLUESKY_PASSWORD = "test-password"; | ||
| await import("../channels/bluesky.js"); | ||
| }); | ||
|
|
||
| async function call(id: string, input: any) { | ||
| const handler = handlers[id]; | ||
| if (!handler) throw new Error(`Handler ${id} not registered`); | ||
| return handler(input); | ||
| } | ||
|
|
||
| describe("channel::bluesky::webhook", () => { | ||
| it("registers the handler", () => { | ||
| expect(handlers["channel::bluesky::webhook"]).toBeDefined(); | ||
| }); | ||
|
|
||
| it("ignores messages without text", async () => { | ||
| const result = await call("channel::bluesky::webhook", { | ||
| body: { did: "did:plc:user1" }, | ||
| }); | ||
| expect(result.status_code).toBe(200); | ||
| }); | ||
|
|
||
| it("processes valid mention", async () => { | ||
| const result = await call("channel::bluesky::webhook", { | ||
| body: { | ||
| did: "did:plc:user2", | ||
| text: "Hello Bluesky", | ||
| uri: "at://did:plc:user2/post/1", | ||
| cid: "bafyrei1", | ||
| }, | ||
| }); | ||
| expect(result.status_code).toBe(200); | ||
| }); | ||
|
|
||
| it("routes to agent::chat with bluesky session", async () => { | ||
| await call("channel::bluesky::webhook", { | ||
| body: { | ||
| did: "did:plc:user3", | ||
| text: "Bluesky msg", | ||
| uri: "at://x/post/2", | ||
| cid: "bafyrei2", | ||
| }, | ||
| }); | ||
| const chatCalls = mockTrigger.mock.calls.filter( | ||
| (c) => c[0] === "agent::chat", | ||
| ); | ||
| expect(chatCalls.length).toBe(1); | ||
| expect(chatCalls[0][1].sessionId).toBe("bluesky:did:plc:user3"); | ||
| }); | ||
|
|
||
| it("calls Bluesky API to send reply", async () => { | ||
| await call("channel::bluesky::webhook", { | ||
| body: { | ||
| did: "did:plc:user4", | ||
| text: "Auth test", | ||
| uri: "at://x/post/3", | ||
| cid: "bafyrei3", | ||
| }, | ||
| }); | ||
| expect(mockFetch).toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it("sends reply as post via AT Protocol", async () => { | ||
| await call("channel::bluesky::webhook", { | ||
| body: { | ||
| did: "did:plc:user5", | ||
| text: "Post test", | ||
| uri: "at://x/post/4", | ||
| cid: "bafyrei4", | ||
| }, | ||
| }); | ||
| const createCalls = (mockFetch.mock.calls as any[][]).filter((c) => | ||
| (c[0] as string).includes("createRecord"), | ||
| ); | ||
| expect(createCalls.length).toBeGreaterThanOrEqual(1); | ||
| }); | ||
|
|
||
| it("emits audit event", async () => { | ||
| await call("channel::bluesky::webhook", { | ||
| body: { | ||
| did: "did:plc:user6", | ||
| text: "Audit bsky", | ||
| uri: "at://x/post/5", | ||
| cid: "bafyrei5", | ||
| }, | ||
| }); | ||
| expect(mockTriggerVoid).toHaveBeenCalledWith( | ||
| "security::audit", | ||
| expect.objectContaining({ | ||
| detail: expect.objectContaining({ channel: "bluesky" }), | ||
| }), | ||
| ); | ||
| }); | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔴 Cargo.toml accidentally removes
browserandcode-agentfrom workspace membersworkers/browserandworkers/code-agentwere workspace members before this PR (confirmed at merge baseb813556), and theirCargo.tomlfiles still exist on disk. The newchannel-emailandchannel-signalentries replaced them instead of being added alongside them. This meanscargo build/cargo testwill no longer compile these two crates as part of the workspace, silently breaking their builds.Was this helpful? React with 👍 or 👎 to provide feedback.