Skip to content

feat: Add global chat for navigation #5820

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

Closed
wants to merge 42 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
e68961b
feat: ai flow chat
HugoCasa May 26, 2025
9661f13
Merge remote-tracking branch 'origin/main' into hc/ai-flow-chat
HugoCasa May 27, 2025
50b9dd0
youpi
HugoCasa May 29, 2025
700c484
feat: preprocessor and error handler support
HugoCasa May 30, 2025
13de5ec
Merge remote-tracking branch 'origin/main' into hc/ai-flow-chat
HugoCasa Jun 2, 2025
38aaa44
fix: reactivity
HugoCasa Jun 2, 2025
6240ab6
Add GlobalChat component with drawer functionality
claude[bot] May 27, 2025
c2f40cb
draft
centdix May 23, 2025
7cb8f0a
use triggerable by ai compoennt
centdix May 26, 2025
db99f55
make drawer triggerable
centdix May 27, 2025
4ac46ee
implement logic
centdix May 27, 2025
2496741
add inkeep tool
centdix May 27, 2025
4da5255
cleaner code
centdix May 27, 2025
f13b8f3
make more things available
centdix May 28, 2025
86e6023
more integrations + better system prompt
centdix May 28, 2025
d6340cc
fix docs fetching
centdix May 28, 2025
fb41953
small fix
centdix May 28, 2025
a2a1df1
cleaning
centdix May 28, 2025
ffc6cda
add ask in search bar + right top icon on homepage + suggestions
centdix May 29, 2025
624e379
fix button
centdix May 29, 2025
7a0b39f
disable chat if no ai providers
centdix May 29, 2025
9c31afe
add inkeep endpoint
centdix May 29, 2025
5d14c8a
draft working stuff
centdix May 29, 2025
0217a41
cleaner code
centdix May 29, 2025
1cb8e0d
better chat
centdix May 30, 2025
dd3ff96
fix
centdix May 30, 2025
b98b451
send license and uid
centdix May 30, 2025
2a41322
better anim
centdix May 30, 2025
31f1bed
move logic
centdix May 30, 2025
a6e9ef5
parse links in chat
centdix May 30, 2025
011f881
add missing integration
centdix May 30, 2025
3aaba09
add reset button
centdix May 30, 2025
2fc4d51
fix
centdix May 31, 2025
4238173
rm file
centdix Jun 2, 2025
6e4fdd6
integrate navigator mode
centdix Jun 2, 2025
af37a93
integrate all changes
centdix Jun 2, 2025
6f5806d
add hide button
centdix Jun 2, 2025
ff3b1d1
adjust drawer size
centdix Jun 2, 2025
e331c82
add script ai chat integration
centdix Jun 2, 2025
e7f7801
fix drawer
centdix Jun 2, 2025
89934ec
small fixes
centdix Jun 2, 2025
8185a08
small fixes
centdix Jun 2, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add inkeep tool
  • Loading branch information
centdix committed Jun 2, 2025
commit 2496741e63d55552363c6d1e82fb961db5d8be7a
74 changes: 69 additions & 5 deletions frontend/src/lib/components/chat/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,21 @@ import type {
ChatCompletionTool
} from 'openai/resources/index.mjs'
import { triggerablesByAI } from '$lib/stores'
import OpenAI from 'openai'

// System prompt for the LLM
export const CHAT_SYSTEM_PROMPT = `
You are an assistant that can interact with the user's web page in order to help them find and do things.
You are an assistant that helps the user understand what he can do on the application, and guide him through the application by interacting with it.
You have access to tools that let you:
1. View the current triggerable components on the page
2. Execute the trigger function of a triggerable component
3. Get documentation for the user request

When asked to interact with the page:
When asked to explain something about the application:
- Use the get_documentation tool to get the documentation for the user request
- Ask the user if he wants to be guided through the application to do what he wants.

When asked to do something on the application:
- First examine the page structure to understand what's available
- Explain what you're doing before taking action
- Take action only if you're sure it's what the user wants
Expand All @@ -25,6 +31,24 @@ When asked to interact with the page:
Use the provided tools only when necessary and appropriate.
`

const GET_DOCUMENTATION_TOOL: ChatCompletionTool = {
type: 'function',
function: {
name: 'get_documentation',
description: 'Get the documentation for the user request',
parameters: {
type: 'object',
properties: {
request: {
type: 'string',
description: 'The user request'
}
},
required: ['request']
}
}
}

// Tool definitions
const GET_PAGE_HTML_TOOL: ChatCompletionTool = {
type: 'function',
Expand Down Expand Up @@ -61,7 +85,6 @@ const EXECUTE_COMMAND_TOOL: ChatCompletionTool = {
}
}

// Function to get page HTML
function getTriggerableComponents(): string {
try {
// Get components registered in the triggerablesByAI store
Expand Down Expand Up @@ -114,6 +137,40 @@ function triggerComponent(args: { id: string; value: string }): string {
}
}

async function getDocumentation(args: { request: string }): Promise<string | null> {
const client = new OpenAI({
apiKey: '',
baseURL: 'https://api.inkeep.com/v1',
dangerouslyAllowBrowser: true
})
const retrieval = await client.chat.completions.create({
model: 'inkeep-rag',
messages: [{ role: 'user', content: args.request }]
})
if (!retrieval.choices[0].message.content) {
return null
}

// Parse the raw response
const raw = retrieval.choices[0].message.content
const parsed = JSON.parse(raw)

// Clean up the response to include only essential information
if (parsed.content && Array.isArray(parsed.content)) {
const cleanedContent = parsed.content.map((item: any) => ({
title: item.title,
url: item.url,
content: item.source?.content.map((c: any) => c.text).join('\n') || []
}))
// Limit the response to 30000 characters max
const stringified = JSON.stringify({ content: cleanedContent }).slice(0, 30000)

return stringified
}

return retrieval.choices[0].message.content
}

// Process tool calls from the LLM
async function processToolCall(
toolCall: ChatCompletionMessageToolCall,
Expand All @@ -128,6 +185,9 @@ async function processToolCall(
result = getTriggerableComponents()
} else if (toolCall.function.name === 'trigger_component') {
result = triggerComponent(args)
} else if (toolCall.function.name === 'get_documentation') {
const docResult = await getDocumentation(args)
result = docResult || 'No documentation found for this request'
} else {
result = `Unknown tool: ${toolCall.function.name}`
}
Expand All @@ -152,14 +212,17 @@ export async function chatRequest(
abortController: AbortController,
onNewToken: (token: string) => void
) {
const toolDefs: ChatCompletionTool[] = [GET_PAGE_HTML_TOOL, EXECUTE_COMMAND_TOOL]
const toolDefs: ChatCompletionTool[] = [
GET_PAGE_HTML_TOOL,
EXECUTE_COMMAND_TOOL,
GET_DOCUMENTATION_TOOL
]

try {
let completion: any = null

while (true) {
completion = await getCompletion(messages, abortController, toolDefs)
console.log(completion)

if (completion) {
const finalToolCalls: Record<number, ChatCompletionChunk.Choice.Delta.ToolCall> = {}
Expand Down Expand Up @@ -219,6 +282,7 @@ export async function chatRequest(
return completion
} catch (err) {
if (!abortController.signal.aborted) {
console.error(err)
throw err
}
}
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/lib/components/copilot/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,7 @@ function getProviderAndCompletionConfig<K extends boolean>({
: ChatCompletionCreateParamsNonStreaming
} {
let info = get(copilotInfo)
console.log('info', info)
const modelProvider =
forceModelProvider ?? get(copilotSessionModel) ?? info.defaultModel ?? info.aiModels[0]

Expand All @@ -383,6 +384,7 @@ function getProviderAndCompletionConfig<K extends boolean>({
model: modelProvider.model.slice(0, -9)
}
: {
// model: 'inkeep-context-sonnet-4',
model: modelProvider.model,
temperature: 0,
...(tools && tools.length > 0 ? { tools } : {})
Expand Down