YC (S26) | Open Computer History | Continuously record your company computer work, map your workflows, help you find work worth automating, and power your agents' context
Rust agentsagiaiai-memoryaudio-recordingcomputer-visionhermeshermes-agentllmlocal-ailocal-firstmachine-learningmcpmultimodalopenclawprivacyrewindscreen-recordingspeech-to-textycombinator
fix(chat): keep live-view width schema Gemini-compatible (#6245)
Ezra Ellette0cf11be8107f
diff --git a/apps/screenpipe-app-tauri/src-tauri/assets/extensions/__tests__/live-views.test.ts b/apps/screenpipe-app-tauri/src-tauri/assets/extensions/__tests__/live-views.test.tsindex 093a2050a..334fbc583 100644--- a/apps/screenpipe-app-tauri/src-tauri/assets/extensions/__tests__/live-views.test.ts+++ b/apps/screenpipe-app-tauri/src-tauri/assets/extensions/__tests__/live-views.test.ts@@ -7,6 +7,7 @@ import registerLiveViews from "../live-views";type ToolDef = {name: string;+ parameters: any;promptGuidelines?: string[];execute: (toolCallId: string,@@ -466,6 +467,15 @@ describe("live view retrieval the model drives", () => {describe("screenpipe_live_view_propose", () => {const signal = () => new AbortController().signal;+ it("registers a provider-compatible integer width schema", () => {+ const width = getProposeTool().parameters.properties.blocks.items.properties+ .width;++ expect(width.type).toBe("integer");+ expect(width.enum).toBeUndefined();+ expect(width.description).toContain("3, 6, or 12");+ });+it("accepts a valid targeted edit without writing anything", async () => {const result = await getProposeTool().execute("propose",diff --git a/apps/screenpipe-app-tauri/src-tauri/assets/extensions/live-views.ts b/apps/screenpipe-app-tauri/src-tauri/assets/extensions/live-views.tsindex 8ba8eb11f..65c9866a0 100644--- a/apps/screenpipe-app-tauri/src-tauri/assets/extensions/live-views.ts+++ b/apps/screenpipe-app-tauri/src-tauri/assets/extensions/live-views.ts@@ -391,7 +391,10 @@ const blockSchema = {"The source-backed calculation or summary this Block asks its task for, including how missing evidence is handled.",},component: { type: "string", enum: COMPONENTS },- width: { type: "integer", enum: WIDTHS },+ width: {+ type: "integer",+ description: "Grid width in columns: 3, 6, or 12.",+ },pipeName: {type: ["string", "null"],description:diff --git a/packages/ai-gateway/src/providers/gemini.ts b/packages/ai-gateway/src/providers/gemini.tsindex 1284cf554..15af2520d 100644--- a/packages/ai-gateway/src/providers/gemini.ts+++ b/packages/ai-gateway/src/providers/gemini.ts@@ -478,8 +478,17 @@ export class GeminiProvider implements AIProvider {return { type: 'OBJECT', properties: {} };}- const rawType = String(params.type || 'object').toLowerCase();+ // Gemini's `type` is a single enum, not a JSON-Schema union. A nullable+ // field like `type: ["string", "null"]` used to stringify to "STRING,NULL"+ // and 400 with "Invalid value at … .parameters.properties[X].type". Keep+ // the first real type and move the nullability onto Gemini's own+ // `nullable` flag, which also lets `["array", "null"]` still get `items`.+ const declaredTypes = (Array.isArray(params.type) ? params.type : [params.type])+ .filter((t: unknown): t is string => typeof t === 'string' && t.length > 0)+ .map((t: string) => t.toLowerCase());+ const rawType = declaredTypes.find((t: string) => t !== 'null') || 'object';const converted: any = { type: rawType.toUpperCase() };+ if (declaredTypes.includes('null')) converted.nullable = true;if (params.description) converted.description = params.description;// Gemini requires enum values to be TYPE_STRING regardless of thediff --git a/packages/ai-gateway/src/test/gemini.unit.test.ts b/packages/ai-gateway/src/test/gemini.unit.test.tsindex c5d9e45f2..7ac6e2d41 100644--- a/packages/ai-gateway/src/test/gemini.unit.test.ts+++ b/packages/ai-gateway/src/test/gemini.unit.test.ts@@ -225,6 +225,79 @@ describe('GeminiProvider tool schema conversion (Sentry SCREENPIPE-AI-PROXY-9)',});expect(out.properties.name.items).toBeUndefined();});++ it('collapses a nullable union type into one type plus nullable', () => {+ // `type: ["string", "null"]` used to stringify to "STRING,NULL" — the+ // shape the live-views block schema sends for pipeName.+ const out = convert({+ type: 'object',+ properties: {+ pipeName: {+ type: ['string', 'null'],+ description: 'Installed scheduled task, or null when none fits.',+ },+ },+ });+ expect(out.properties.pipeName.type).toBe('STRING');+ expect(out.properties.pipeName.nullable).toBe(true);+ expect(out.properties.pipeName.description).toBe(+ 'Installed scheduled task, or null when none fits.'+ );+ });++ it('still fills items for a nullable array union', () => {+ const out = convert({+ type: 'object',+ properties: {+ tags: { type: ['array', 'null'], items: { type: 'string' } },+ },+ });+ expect(out.properties.tags.type).toBe('ARRAY');+ expect(out.properties.tags.nullable).toBe(true);+ expect(out.properties.tags.items).toEqual({ type: 'STRING' });+ });++ it('recurses into a nullable object union', () => {+ const out = convert({+ type: ['object', 'null'],+ properties: { a: { type: 'string' } },+ required: ['a'],+ });+ expect(out.type).toBe('OBJECT');+ expect(out.nullable).toBe(true);+ expect(out.properties.a.type).toBe('STRING');+ expect(out.required).toEqual(['a']);+ });++ it('leaves a plain string type untouched (no stray nullable)', () => {+ const out = convert({+ type: 'object',+ properties: { name: { type: 'string' } },+ });+ expect(out.properties.name.type).toBe('STRING');+ expect(out.properties.name.nullable).toBeUndefined();+ expect(out.nullable).toBeUndefined();+ });++ it('coerces enum values on a nullable union without regressing the type', () => {+ const out = convert({+ type: 'object',+ properties: {+ width: { type: ['integer', 'null'], enum: [3, 6, 12] },+ },+ });+ expect(out.properties.width.type).toBe('INTEGER');+ expect(out.properties.width.nullable).toBe(true);+ expect(out.properties.width.enum).toEqual(['3', '6', '12']);+ });++ it('falls back to OBJECT for a missing or unusable type', () => {+ expect(convert({ description: 'no type at all' }).type).toBe('OBJECT');+ expect(convert({ type: [] }).type).toBe('OBJECT');+ // `type: ["null"]` has no real member left to keep.+ expect(convert({ type: ['null'] }).type).toBe('OBJECT');+ expect(convert({ type: ['null'] }).nullable).toBe(true);+ });});describe('GeminiProvider.formatMessages history sanitization', () => {