Fix TypeScript types for window.spark API compatibility

Co-authored-by: johndoe6345789 <224850594+johndoe6345789@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2026-01-17 00:55:31 +00:00
parent c22fcb4946
commit 5ee0a16040
3 changed files with 28 additions and 8391 deletions

8374
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -10,12 +10,35 @@
// Mock KV Storage
const kvStorage = new Map<string, any>()
// Create llm function with additional properties
const llmFunction = async (prompt: string, model?: string, jsonMode?: boolean): Promise<any> => {
console.log('Mock LLM called with prompt:', prompt, 'model:', model, 'jsonMode:', jsonMode)
return 'This is a mock response from the Spark LLM service.'
}
llmFunction.chat = async (messages: any[]) => {
console.log('Mock LLM chat called with messages:', messages)
return {
role: 'assistant',
content: 'This is a mock response from the Spark LLM service.'
}
}
llmFunction.complete = async (prompt: string) => {
console.log('Mock LLM complete called with prompt:', prompt)
return 'This is a mock completion from the Spark LLM service.'
}
export const sparkRuntime = {
kv: {
get: (key: string) => {
get: <T = any>(key: string): T | undefined => {
try {
const value = kvStorage.get(key)
return value !== undefined ? value : localStorage.getItem(key) ? JSON.parse(localStorage.getItem(key)!) : undefined
if (value !== undefined) {
return value as T
}
const stored = localStorage.getItem(key)
return stored ? JSON.parse(stored) : undefined
} catch (error) {
console.error('Error getting KV value:', error)
return undefined
@@ -47,19 +70,7 @@ export const sparkRuntime = {
keys: () => Array.from(kvStorage.keys())
},
llm: {
chat: async (messages: any[]) => {
console.log('Mock LLM chat called with messages:', messages)
return {
role: 'assistant',
content: 'This is a mock response from the Spark LLM service.'
}
},
complete: async (prompt: string) => {
console.log('Mock LLM complete called with prompt:', prompt)
return 'This is a mock completion from the Spark LLM service.'
}
},
llm: llmFunction,
user: {
getCurrentUser: () => ({

View File

@@ -8,13 +8,13 @@ declare global {
interface Window {
spark: {
kv: {
get: (key: string) => any
get: <T = any>(key: string) => T | undefined
set: (key: string, value: any) => void
delete: (key: string) => void
clear: () => void
keys: () => string[]
}
llm: {
llm: ((prompt: string, model?: string, jsonMode?: boolean) => Promise<any>) & {
chat: (messages: any[]) => Promise<{ role: string; content: string }>
complete: (prompt: string) => Promise<string>
}