Repository navigation
feat(connectors): add venice connector (5 endpoints) #107
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
Open
sabrinaaquino
wants to merge
4
commits into
monid-ai:main
Choose a base branch
from
sabrinaaquino:feat/connector-venice
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
fff5635
feat(connectors): add venice connector (5 endpoints)
sabrinaaquino f7dc2d1
test(venice): cover provider errors and valid schema boundaries
sabrinaaquino c2452bb
fix(venice): bound the chat hold with tools, images, and injected con…
sabrinaaquino 661d3db
test(venice): complete the sync-provider template on every endpoint
sabrinaaquino 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
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
93 changes: 93 additions & 0 deletions
93
connectors/venice/endpoints/augment-scrape/endpoint.test.ts
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,93 @@ | ||
| import { assertEquals, assertRejects } from "@std/assert"; | ||
| import { fromFileUrl } from "@std/path"; | ||
| import { | ||
| estimateEndpoint, | ||
| liveSkip, | ||
| loadFixture, | ||
| runEndpoint, | ||
| testSealedUnit, | ||
| } from "@shared/testing"; | ||
|
|
||
| const ID = "venice#augment/scrape"; | ||
| const chains = fromFileUrl(new URL("../../fixtures/", import.meta.url)); | ||
|
|
||
| Deno.test(`${ID} happy (recorded): flat $0.01, markdown content`, async () => { | ||
| const unit = await testSealedUnit(ID); | ||
| const result = await runEndpoint({ | ||
| unit, | ||
| input: { body: { url: "https://example.com" } }, | ||
| mode: "replay", | ||
| fixture: await loadFixture(`${chains}scrape-ok.json`), | ||
| }); | ||
| assertEquals(result.httpStatus, 200); | ||
| assertEquals(result.isProviderError, false); | ||
| assertEquals(result.usage, { | ||
| credits: { default: 0.01 }, | ||
| evidence: { CALL: 1 }, | ||
| }); | ||
| const output = result.output as Record<string, unknown>; | ||
| assertEquals(output.format, "markdown"); | ||
| assertEquals(typeof output.content, "string"); | ||
| }); | ||
|
|
||
| Deno.test(`${ID} blocked site (recorded 400): zero usage, digested error`, async () => { | ||
| const unit = await testSealedUnit(ID); | ||
| const result = await runEndpoint({ | ||
| unit, | ||
| input: { body: { url: "https://x.com/venice_ai" } }, | ||
| mode: "replay", | ||
| fixture: await loadFixture(`${chains}scrape-blocked.json`), | ||
| }); | ||
| assertEquals(result.httpStatus, 400); | ||
| assertEquals(result.isProviderError, true); | ||
| assertEquals(result.usage, { credits: {}, evidence: {} }); | ||
| const output = result.output as Record<string, unknown>; | ||
| assertEquals( | ||
| (output.message as string).includes("blocks automated access"), | ||
| true, | ||
| ); | ||
| }); | ||
|
|
||
| Deno.test(`${ID} schema gate: a non-URL is rejected before the wire`, async () => { | ||
| const unit = await testSealedUnit(ID); | ||
| await assertRejects( | ||
| () => | ||
| runEndpoint({ | ||
| unit, | ||
| input: { body: { url: "not a url" } }, | ||
| mode: "replay", | ||
| fixture: { | ||
| name: "unused", | ||
| description: "never reached", | ||
| calls: [], | ||
| }, | ||
| }), | ||
| Error, | ||
| "INVALID_INPUT", | ||
| ); | ||
| // Passing near-twin: a different valid https URL clears the gate. | ||
| const accepted = await estimateEndpoint(unit, { | ||
| body: { url: "https://example.org/valid-page" }, | ||
| }); | ||
| assertEquals(accepted.evidence, { CALL: 1 }); | ||
| }); | ||
|
|
||
| Deno.test({ | ||
| name: `${ID} live (gated on VENICE_API_KEY)`, | ||
| ignore: liveSkip("venice"), | ||
| fn: async () => { | ||
| const unit = await testSealedUnit(ID); | ||
| const result = await runEndpoint({ | ||
| unit, | ||
| input: { body: { url: "https://example.com" } }, | ||
| mode: "live", | ||
| }); | ||
| assertEquals( | ||
| result.isProviderError, | ||
| false, | ||
| JSON.stringify(result.output), | ||
| ); | ||
| const output = result.output as Record<string, unknown>; | ||
| assertEquals(output.format, "markdown"); | ||
| }, | ||
| }); |
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,41 @@ | ||
| import { defineEndpoint, UsageModelKind } from "@shared/core"; | ||
| import { zAugmentScrapeBody } from "./schema/inputs.ts"; | ||
|
|
||
| /** | ||
| * Venice `POST /augment/scrape` — fetch one URL and return it as Markdown. | ||
| * Flat $0.01 per successful call (Venice price sheet: `scrape-augmentation` | ||
| * $10 per 1,000, verified 2026-10-08); rejected and failed URLs are not | ||
| * charged. No meter on the response — the derived fold is the bill. | ||
| */ | ||
| export default defineEndpoint({ | ||
| meta: { | ||
| displayName: "Venice Web Scrape", | ||
| summary: "Fetch a public web page as clean Markdown.", | ||
| description: "Fetch one public URL and return its main content as " + | ||
| 'Markdown ({url, content, format: "markdown"}). Useful after ' + | ||
| "`venice#augment/search` to read a result in full. Sites that " + | ||
| "block automated access — notably X/Twitter and Reddit — are " + | ||
| "rejected immediately (and not charged); private, internal and " + | ||
| "localhost addresses are refused.", | ||
| docsUrl: "https://docs.venice.ai/api-reference/endpoint/augment/scrape", | ||
| categories: ["web-scraping"], | ||
| notes: [ | ||
| "Flat $0.01 per page.", | ||
| "Venice rate-limits this endpoint at 20 requests per minute " + | ||
| "per account.", | ||
| "X/Twitter and Reddit URLs are refused with a 4xx before any " + | ||
| "fetch.", | ||
| ], | ||
| }, | ||
| request: { method: "POST", path: "/augment/scrape" }, | ||
| input: { schema: { body: zAugmentScrapeBody } }, | ||
| usage: { | ||
| model: { | ||
| kind: UsageModelKind.PER_CALL, | ||
| consumes: { credit: "default", amount: 0.01 }, | ||
| label: "page", | ||
| description: "one successfully scraped page", | ||
| }, | ||
| }, | ||
| timeouts: { requestMs: 60_000, runMs: 60_000 }, | ||
| }); |
12 changes: 12 additions & 0 deletions
12
connectors/venice/endpoints/augment-scrape/schema/inputs.ts
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,12 @@ | ||
| import { z } from "zod"; | ||
|
|
||
| /** | ||
| * `POST /augment/scrape` request body — mirrors Venice's | ||
| * `WebScrapeRequest`. Optionality only (D25). | ||
| */ | ||
| export const zAugmentScrapeBody = z.object({ | ||
| url: z.string().url().describe( | ||
| "Public http(s) URL to fetch. Private/internal addresses are " + | ||
| "rejected.", | ||
| ), | ||
| }); |
121 changes: 121 additions & 0 deletions
121
connectors/venice/endpoints/augment-search/endpoint.test.ts
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,121 @@ | ||
| import { assertEquals, assertRejects } from "@std/assert"; | ||
| import { fromFileUrl } from "@std/path"; | ||
| import { | ||
| estimateEndpoint, | ||
| liveSkip, | ||
| loadFixture, | ||
| runEndpoint, | ||
| testSealedUnit, | ||
| } from "@shared/testing"; | ||
|
|
||
| const ID = "venice#augment/search"; | ||
| const chains = fromFileUrl(new URL("../../fixtures/", import.meta.url)); | ||
|
|
||
| Deno.test(`${ID} happy (recorded): flat $0.01, structured results`, async () => { | ||
| const unit = await testSealedUnit(ID); | ||
| const result = await runEndpoint({ | ||
| unit, | ||
| input: { body: { query: "deno 2.9 release notes", limit: 3 } }, | ||
| mode: "replay", | ||
| fixture: await loadFixture(`${chains}search-ok.json`), | ||
| }); | ||
| assertEquals(result.httpStatus, 200); | ||
| assertEquals(result.isProviderError, false); | ||
| assertEquals(result.usage, { | ||
| credits: { default: 0.01 }, | ||
| evidence: { CALL: 1 }, | ||
| }); | ||
| const output = result.output as Record<string, unknown>; | ||
| const results = output.results as Record<string, unknown>[]; | ||
| assertEquals(typeof results[0].url, "string"); | ||
| assertEquals(typeof results[0].title, "string"); | ||
| }); | ||
|
|
||
| Deno.test(`${ID} provider error (recorded 401): zero usage, digested error`, async () => { | ||
| const unit = await testSealedUnit(ID); | ||
| const result = await runEndpoint({ | ||
| unit, | ||
| input: { body: { query: "venice ai", limit: 3 } }, | ||
| mode: "replay", | ||
| fixture: await loadFixture(`${chains}unauthorized.json`), | ||
| }); | ||
| assertEquals(result.httpStatus, 401); | ||
| assertEquals(result.isProviderError, true); | ||
| assertEquals(result.usage, { credits: {}, evidence: {} }); | ||
| const output = result.output as Record<string, unknown>; | ||
| assertEquals(output.message, "Authentication failed"); | ||
| }); | ||
|
|
||
| Deno.test(`${ID} provider error (429): no usage`, async () => { | ||
| const unit = await testSealedUnit(ID); | ||
| const result = await runEndpoint({ | ||
| unit, | ||
| input: { body: { query: "deno 2.9 release notes", limit: 3 } }, | ||
| mode: "replay", | ||
| fixture: { | ||
| name: "synthetic-augment-search-rate-limited", | ||
| description: "A Venice 429 must not bill search usage.", | ||
| calls: [{ | ||
| req: { method: "POST", url: unit.doc.request.url }, | ||
| res: { status: 429, body: { error: "rate limit exceeded" } }, | ||
| }], | ||
| }, | ||
| }); | ||
| assertEquals(result.httpStatus, 429); | ||
| assertEquals(result.isProviderError, true); | ||
| assertEquals(result.usage, { credits: {}, evidence: {} }); | ||
| const output = result.output as Record<string, unknown>; | ||
| assertEquals(output.message, "rate limit exceeded"); | ||
| }); | ||
|
|
||
| Deno.test(`${ID} schema gate: limit over 20 and unknown backends are rejected`, async () => { | ||
| const unit = await testSealedUnit(ID); | ||
| const fixture = await loadFixture(`${chains}search-ok.json`); | ||
| await assertRejects( | ||
| () => | ||
| runEndpoint({ | ||
| unit, | ||
| input: { body: { query: "q", limit: 21 } }, | ||
| mode: "replay", | ||
| fixture, | ||
| }), | ||
| Error, | ||
| "INVALID_INPUT", | ||
| ); | ||
| await assertRejects( | ||
| () => | ||
| runEndpoint({ | ||
| unit, | ||
| input: { body: { query: "q", search_provider: "bing" } }, | ||
| mode: "replay", | ||
| fixture, | ||
| }), | ||
| Error, | ||
| "INVALID_INPUT", | ||
| ); | ||
| // Passing near-twin: limit 20 is allowed. | ||
| const accepted = await estimateEndpoint(unit, { | ||
| body: { query: "q", limit: 20 }, | ||
| }); | ||
| assertEquals(accepted.evidence, { CALL: 1 }); | ||
| }); | ||
|
|
||
| Deno.test({ | ||
| name: `${ID} live (gated on VENICE_API_KEY)`, | ||
| ignore: liveSkip("venice"), | ||
| fn: async () => { | ||
| const unit = await testSealedUnit(ID); | ||
| const result = await runEndpoint({ | ||
| unit, | ||
| input: { body: { query: "venice ai", limit: 2 } }, | ||
| mode: "live", | ||
| }); | ||
| assertEquals( | ||
| result.isProviderError, | ||
| false, | ||
| JSON.stringify(result.output), | ||
| ); | ||
| const output = result.output as Record<string, unknown>; | ||
| assertEquals(Array.isArray(output.results), true); | ||
| }, | ||
| }); | ||
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,52 @@ | ||
| import { defineEndpoint, UsageModelKind } from "@shared/core"; | ||
| import { zAugmentSearchBody } from "./schema/inputs.ts"; | ||
|
|
||
| /** | ||
| * Venice `POST /augment/search` — live web search returning structured | ||
| * results. Flat $0.01 per successful call (Venice price sheet: | ||
| * `search-augmentation` $10 per 1,000, verified 2026-10-08); errors are | ||
| * not charged. No meter on the response — the derived fold is the bill. | ||
| */ | ||
| export default defineEndpoint({ | ||
| meta: { | ||
| displayName: "Venice Web Search", | ||
| summary: "Private live web search — Brave (zero data retention) or " + | ||
| "anonymized Google.", | ||
| description: "Search the live web and get structured results " + | ||
| "({title, url, content, date}) — up to 20 per call. Two " + | ||
| "privacy-preserving backends: `brave` (default) runs with Zero " + | ||
| "Data Retention, so the query is never stored or logged; " + | ||
| "`google` proxies the query through Venice so your identity is " + | ||
| "never attached to it. `content` is a page excerpt, often " + | ||
| "several paragraphs. Pipe a result URL to " + | ||
| "`venice#augment/scrape` for the full page as Markdown, or use " + | ||
| "`venice#chat/completions` with web search enabled when you " + | ||
| "want a synthesized answer instead of raw results.", | ||
| docsUrl: "https://docs.venice.ai/api-reference/endpoint/augment/search", | ||
| categories: ["web-search"], | ||
| notes: [ | ||
| "Flat $0.01 per call, whatever `limit` is.", | ||
| "Venice rate-limits this endpoint at 20 requests per minute " + | ||
| "per account.", | ||
| ], | ||
| }, | ||
| request: { method: "POST", path: "/augment/search" }, | ||
| input: { | ||
| schema: { | ||
| body: zAugmentSearchBody.extend({ | ||
| limit: zAugmentSearchBody.shape.limit.unwrap().default(10), | ||
| search_provider: zAugmentSearchBody.shape.search_provider | ||
| .unwrap().default("brave"), | ||
| }), | ||
| }, | ||
| }, | ||
| usage: { | ||
| model: { | ||
| kind: UsageModelKind.PER_CALL, | ||
| consumes: { credit: "default", amount: 0.01 }, | ||
| label: "search", | ||
| description: "one successful web search", | ||
| }, | ||
| }, | ||
| timeouts: { requestMs: 60_000, runMs: 60_000 }, | ||
| }); |
18 changes: 18 additions & 0 deletions
18
connectors/venice/endpoints/augment-search/schema/inputs.ts
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,18 @@ | ||
| import { z } from "zod"; | ||
|
|
||
| /** | ||
| * `POST /augment/search` request body — mirrors Venice's | ||
| * `WebSearchRequest` (https://docs.venice.ai). Optionality only (D25). | ||
| */ | ||
| export const zAugmentSearchBody = z.object({ | ||
| query: z.string().min(1).max(400).describe("The search query."), | ||
| limit: z.number().int().min(1).max(20).optional().describe( | ||
| "Maximum results to return (vendor default 10, max 20).", | ||
| ), | ||
| search_provider: z.enum(["brave", "google"]).optional().describe( | ||
| "`brave` (vendor default): Brave Search with Zero Data Retention " + | ||
| "— queries are never stored or logged. `google`: Google " + | ||
| "Search, anonymized — proxied so your identity is not " + | ||
| "attached to the query.", | ||
| ), | ||
| }); |
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.
Uh oh!
There was an error while loading. Please reload this page.