Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 9501fb9

Browse files
LeksykLeksyk
and
Leksyk
authoredMar 12, 2025··
Wiring asset's mimeType to TemplatePart #4605
Wiring asset's mimeType to TemplatePart #4605 > It's a good idea to open an issue first for discussion. - [x] Tests pass - [ ] Appropriate changes to documentation are included in the PR --------- Co-authored-by: Leksyk <[email protected]>
1 parent f36dfbe commit 9501fb9

File tree

4 files changed

+30
-8
lines changed

4 files changed

+30
-8
lines changed
 

‎packages/breadboard/src/utils/template.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export type TemplatePart = {
3232
* dangling autowire or missing asset
3333
*/
3434
invalid?: true;
35+
mimeType?: string;
3536
};
3637

3738
export type TemplatePartTransformCallback = (
@@ -171,8 +172,9 @@ class Template {
171172
return `{${JSON.stringify(part)}}`;
172173
}
173174

174-
static preamble({ type, path }: TemplatePart) {
175-
return `{{"type": ${JSON.stringify(type)}, "path": ${JSON.stringify(path)}, "title": "`;
175+
static preamble({ type, path, mimeType }: TemplatePart) {
176+
const maybeMimeType = mimeType ? `"mimeType": "${mimeType}"` : "";
177+
return `{{"type": ${JSON.stringify(type)}, "path": ${JSON.stringify(path)}, ${maybeMimeType} "title": "`;
176178
}
177179

178180
static postamble() {

‎packages/shared-ui/src/elements/fast-access-menu/fast-access-menu.ts

+16-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@ import { SignalWatcher } from "@lit-labs/signals";
1313
import { css, html, LitElement, PropertyValues } from "lit";
1414
import { customElement, property, state } from "lit/decorators.js";
1515
import { Component, FastAccess, GraphAsset, Tool } from "../../state";
16-
import { GraphIdentifier, NodeIdentifier } from "@breadboard-ai/types";
16+
import {
17+
GraphIdentifier,
18+
LLMContent,
19+
NodeIdentifier,
20+
} from "@breadboard-ai/types";
1721
import {
1822
FastAccessDismissedEvent,
1923
FastAccessSelectEvent,
@@ -337,6 +341,15 @@ export class FastAccessMenu extends SignalWatcher(LitElement) {
337341
return value;
338342
}
339343

344+
#getMimeType(data: LLMContent[]): string | undefined {
345+
for (const element of data) {
346+
for (const part of element.parts) {
347+
if ("inlineData" in part && part.inlineData.mimeType)
348+
return part.inlineData.mimeType;
349+
}
350+
}
351+
}
352+
340353
#emitCurrentItem() {
341354
let idx = this.selectedIndex;
342355
if (idx < this.#items.assets.length) {
@@ -345,7 +358,8 @@ export class FastAccessMenu extends SignalWatcher(LitElement) {
345358
new FastAccessSelectEvent(
346359
asset.path,
347360
asset.metadata?.title ?? "Untitled asset",
348-
"asset"
361+
"asset",
362+
this.#getMimeType(asset.data)
349363
)
350364
);
351365
return;

‎packages/shared-ui/src/elements/input/text-editor/text-editor.ts

+8-3
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ export class TextEditor extends LitElement {
260260
selection.addRange(this.#lastRange);
261261
}
262262

263-
#add(path: string, title: string, type: TemplatePartType) {
263+
#add(path: string, title: string, type: TemplatePartType, mimeType?: string) {
264264
if (!this.#editorRef.value) {
265265
return null;
266266
}
@@ -282,7 +282,12 @@ export class TextEditor extends LitElement {
282282
label.classList.add(type);
283283
label.dataset.path = path;
284284

285-
preambleText.textContent = Template.preamble({ title, path, type });
285+
preambleText.textContent = Template.preamble({
286+
title,
287+
path,
288+
type,
289+
mimeType,
290+
});
286291
postamableText.textContent = Template.postamble();
287292
titleText.textContent = title;
288293
titleText.classList.add("visible");
@@ -774,7 +779,7 @@ export class TextEditor extends LitElement {
774779
@bbfastaccessselect=${(evt: FastAccessSelectEvent) => {
775780
this.#hideFastAccess();
776781
this.#restoreLastRange();
777-
this.#add(evt.path, evt.title, evt.accessType);
782+
this.#add(evt.path, evt.title, evt.accessType, evt.mimeType);
778783
779784
this.#captureEditorValue();
780785
}}

‎packages/shared-ui/src/events/events.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1331,7 +1331,8 @@ export class FastAccessSelectEvent extends Event {
13311331
constructor(
13321332
public readonly path: string,
13331333
public readonly title: string,
1334-
public readonly accessType: "asset" | "tool" | "in"
1334+
public readonly accessType: "asset" | "tool" | "in",
1335+
public readonly mimeType?: string
13351336
) {
13361337
super(FastAccessSelectEvent.eventName, { ...eventInit });
13371338
}

0 commit comments

Comments
 (0)
Please sign in to comment.