Skip to content

Commit 43ecfbd

Browse files
committedDec 8, 2023
add icons for managed sources
1 parent 1fc2e5a commit 43ecfbd

File tree

8 files changed

+65
-13
lines changed

8 files changed

+65
-13
lines changed
 

‎assets/icons/github.svg

+1
Loading

‎assets/icons/google_drive.svg

+1
Loading

‎assets/icons/intercom.svg

+1
Loading

‎assets/icons/notion.svg

+1
Loading

‎assets/icons/slack.svg

+1
Loading

‎src/agents.tsx

+35-1
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,48 @@
11
import { AgentConfigurationType, AgentType } from "./dust_api/agent";
22
import { DustApi, DustAPICredentials } from "./dust_api/api";
33
import { useEffect, useState } from "react";
4-
import { getPreferenceValues, LocalStorage } from "@raycast/api";
4+
import { Color, getPreferenceValues, Image, LocalStorage } from "@raycast/api";
5+
import Asset = Image.Asset;
56

67
export const DUST_AGENT: AgentType = {
78
sId: "dust",
89
name: "Dust",
910
description: "An assistant with context on your company data.",
1011
};
1112

13+
interface ManagedSource {
14+
icon: Asset;
15+
color: Color;
16+
name: string;
17+
}
18+
export const MANAGED_SOURCES: { [id: string]: ManagedSource } = {
19+
"managed-github": {
20+
icon: "icons/github.svg",
21+
color: Color.PrimaryText,
22+
name: "GitHub",
23+
},
24+
"managed-google_drive": {
25+
icon: "icons/google_drive.svg",
26+
color: Color.Yellow,
27+
name: "Google Drive",
28+
},
29+
"managed-slack": {
30+
icon: "icons/slack.svg",
31+
color: Color.Red,
32+
name: "Slack",
33+
},
34+
"managed-notion": {
35+
icon: "icons/notion.svg",
36+
color: Color.Purple,
37+
name: "Notion",
38+
},
39+
"managed-intercom": {
40+
icon: "icons/intercom.svg",
41+
color: Color.Blue,
42+
name: "Intercom",
43+
},
44+
};
45+
1246
async function saveAgents(agents: { [id: string]: AgentConfigurationType }) {
1347
await LocalStorage.setItem("dust_agents", JSON.stringify(agents));
1448
}

‎src/answerQuestion.tsx

+20-11
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { DustApi, DustAPICredentials, DustDocument } from "./dust_api/api";
33
import { useEffect, useState } from "react";
44
import { addDustHistory } from "./history";
55
import { AgentType } from "./dust_api/agent";
6-
import { DUST_AGENT } from "./agents";
6+
import { DUST_AGENT, MANAGED_SOURCES } from "./agents";
77

88
async function answerQuestion({
99
question,
@@ -103,16 +103,7 @@ export function AskDustQuestion({ question, agent = DUST_AGENT }: { question: st
103103
);
104104
}
105105

106-
const colors = [Color.Blue, Color.Red, Color.Green, Color.Yellow, Color.Purple, Color.Orange];
107106
function DocumentsList({ documents }: { documents: DustDocument[] }) {
108-
const sourceIdColors: { [id: string]: Color } = {};
109-
let index = 0;
110-
documents.forEach((document) => {
111-
if (!sourceIdColors[document.dataSourceId]) {
112-
sourceIdColors[document.dataSourceId] = colors[index % colors.length];
113-
index++;
114-
}
115-
});
116107
return (
117108
<List>
118109
{documents
@@ -123,7 +114,25 @@ function DocumentsList({ documents }: { documents: DustDocument[] }) {
123114
<List.Item
124115
key={document.id}
125116
title={`${document.reference} - ${document.sourceUrl}`}
126-
accessories={[{ tag: { color: sourceIdColors[document.dataSourceId], value: document.dataSourceId } }]}
117+
icon={
118+
document.dataSourceId in MANAGED_SOURCES
119+
? { source: MANAGED_SOURCES[document.dataSourceId].icon }
120+
: { source: Icon.Globe }
121+
}
122+
accessories={[
123+
{
124+
tag: {
125+
color:
126+
document.dataSourceId in MANAGED_SOURCES
127+
? MANAGED_SOURCES[document.dataSourceId].color
128+
: Color.SecondaryText,
129+
value:
130+
document.dataSourceId in MANAGED_SOURCES
131+
? MANAGED_SOURCES[document.dataSourceId].name
132+
: document.dataSourceId,
133+
},
134+
},
135+
]}
127136
actions={
128137
<ActionPanel>
129138
<Action.OpenInBrowser title="Open in Browser" url={document.sourceUrl} />

‎src/dust_api/api.tsx

+5-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import fetch from "node-fetch";
22
import { createParser } from "eventsource-parser";
33
import { ConversationType, UserMessageType } from "./conversation";
44
import { AgentConfigurationType } from "./agent";
5+
import { MANAGED_SOURCES } from "../agents";
56
export type AgentActionType = RetrievalActionType | DustAppRunActionType;
67

78
type RetrievalActionType = {
@@ -376,7 +377,10 @@ export class DustApi {
376377
reference: refCounter[k],
377378
});
378379
}
379-
return `[[${refCounter[k]}](${link})]`;
380+
const icon = ref.dataSourceId in MANAGED_SOURCES ? MANAGED_SOURCES[ref.dataSourceId].icon : undefined;
381+
const markdownIcon = icon ? `<img src="${icon}" width="16" height="16"> ` : "";
382+
console.log("markdownIcon", markdownIcon);
383+
return `[${markdownIcon}[${refCounter[k]}](${link})]`;
380384
}
381385
return "";
382386
})

0 commit comments

Comments
 (0)
Please sign in to comment.