Address code review feedback: improve type safety and documentation

- Added specific return types for LLM functions
- Added LLMChatResponse interface for type safety
- Enhanced plugin documentation with TODO comments
- Clarified intended functionality and future extension points
- Rebuilt package with improvements

Co-authored-by: johndoe6345789 <224850594+johndoe6345789@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2026-01-17 09:00:42 +00:00
parent 6fb37377a0
commit 65f9f8191c
12 changed files with 50 additions and 24 deletions

View File

@@ -6,6 +6,10 @@
* - LLM service (language model integration)
* - User authentication
*/
interface LLMChatResponse {
role: string;
content: string;
}
export declare const sparkRuntime: {
kv: {
get: <T = any>(key: string) => T | undefined;
@@ -15,11 +19,8 @@ export declare const sparkRuntime: {
keys: () => string[];
};
llm: {
(prompt: string, model?: string, jsonMode?: boolean): Promise<any>;
chat(messages: any[]): Promise<{
role: string;
content: string;
}>;
(prompt: string, model?: string, jsonMode?: boolean): Promise<string>;
chat(messages: any[]): Promise<LLMChatResponse>;
complete(prompt: string): Promise<string>;
};
user: {
@@ -31,4 +32,5 @@ export declare const sparkRuntime: {
isAuthenticated: () => boolean;
};
};
export {};
//# sourceMappingURL=spark-runtime.d.ts.map

View File

@@ -1 +1 @@
{"version":3,"file":"spark-runtime.d.ts","sourceRoot":"","sources":["../../src/lib/spark-runtime.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAwBH,eAAO,MAAM,YAAY;;cAEf,CAAC,aAAa,MAAM,KAAG,CAAC,GAAG,SAAS;mBAa/B,MAAM,SAAS,GAAG;sBAQf,MAAM;;;;;iBAzCW,MAAM,UAAU,MAAM,aAAa,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC;uBAKxD,GAAG,EAAE;;;;yBAQH,MAAM;;;;;;;;;;CA4D3C,CAAA"}
{"version":3,"file":"spark-runtime.d.ts","sourceRoot":"","sources":["../../src/lib/spark-runtime.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,UAAU,eAAe;IACvB,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,MAAM,CAAA;CAChB;AAwBD,eAAO,MAAM,YAAY;;cAEf,CAAC,aAAa,MAAM,KAAG,CAAC,GAAG,SAAS;mBAa/B,MAAM,SAAS,GAAG;sBAQf,MAAM;;;;;iBAzCW,MAAM,UAAU,MAAM,aAAa,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC;uBAK3D,GAAG,EAAE,GAAG,OAAO,CAAC,eAAe,CAAC;yBAQ9B,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;;;;;;;;;;CA4D7D,CAAA"}

View File

@@ -1 +1 @@
{"version":3,"file":"spark-runtime-wNXbhm34.js","sources":["../src/lib/spark-runtime.ts"],"sourcesContent":["/**\n * Spark Runtime - Core runtime services for Spark applications\n * \n * This module provides mock implementations of Spark services including:\n * - KV storage (key-value store)\n * - LLM service (language model integration)\n * - User authentication\n */\n\n// Mock KV Storage\nconst kvStorage = new Map<string, any>()\n\n// Create llm function with additional properties\nconst llmFunction = async (prompt: string, model?: string, jsonMode?: boolean): Promise<any> => {\n console.log('Mock LLM called with prompt:', prompt, 'model:', model, 'jsonMode:', jsonMode)\n return 'This is a mock response from the Spark LLM service.'\n}\n\nllmFunction.chat = async (messages: any[]) => {\n console.log('Mock LLM chat called with messages:', messages)\n return {\n role: 'assistant',\n content: 'This is a mock response from the Spark LLM service.'\n }\n}\n\nllmFunction.complete = async (prompt: string) => {\n console.log('Mock LLM complete called with prompt:', prompt)\n return 'This is a mock completion from the Spark LLM service.'\n}\n\nexport const sparkRuntime = {\n kv: {\n get: <T = any>(key: string): T | undefined => {\n try {\n const value = kvStorage.get(key)\n if (value !== undefined) {\n return value as T\n }\n const stored = localStorage.getItem(key)\n return stored ? JSON.parse(stored) : undefined\n } catch (error) {\n console.error('Error getting KV value:', error)\n return undefined\n }\n },\n set: (key: string, value: any) => {\n try {\n kvStorage.set(key, value)\n localStorage.setItem(key, JSON.stringify(value))\n } catch (error) {\n console.error('Error setting KV value:', error)\n }\n },\n delete: (key: string) => {\n try {\n kvStorage.delete(key)\n localStorage.removeItem(key)\n } catch (error) {\n console.error('Error deleting KV value:', error)\n }\n },\n clear: () => {\n try {\n // Get keys before clearing\n const keysToRemove = Array.from(kvStorage.keys())\n kvStorage.clear()\n // Clear corresponding keys from localStorage\n keysToRemove.forEach(key => localStorage.removeItem(key))\n } catch (error) {\n console.error('Error clearing KV storage:', error)\n }\n },\n keys: () => Array.from(kvStorage.keys())\n },\n \n llm: llmFunction,\n \n user: {\n getCurrentUser: () => ({\n id: 'mock-user-id',\n name: 'Mock User',\n email: 'mock@example.com'\n }),\n isAuthenticated: () => true\n }\n}\n"],"names":["kvStorage","Map","llmFunction","async","prompt","model","jsonMode","console","log","chat","messages","role","content","complete","sparkRuntime","kv","get","key","value","undefined","stored","localStorage","getItem","JSON","parse","error","set","setItem","stringify","delete","removeItem","clear","keysToRemove","Array","from","keys","forEach","llm","user","getCurrentUser","id","name","email","isAuthenticated"],"mappings":"AAUA,MAAMA,EAAY,IAAIC,IAGhBC,EAAcC,MAAOC,EAAgBC,EAAgBC,KACzDC,QAAQC,IAAI,+BAAgCJ,EAAQ,SAAUC,EAAO,YAAaC,GAC3E,uDAGTJ,EAAYO,KAAON,MAAOO,IACxBH,QAAQC,IAAI,sCAAuCE,GAC5C,CACLC,KAAM,YACNC,QAAS,wDAIbV,EAAYW,SAAWV,MAAOC,IAC5BG,QAAQC,IAAI,wCAAyCJ,GAC9C,yDAGF,MAAMU,EAAe,CAC1BC,GAAI,CACFC,IAAeC,IACb,IACE,MAAMC,EAAQlB,EAAUgB,IAAIC,GAC5B,QAAcE,IAAVD,EACF,OAAOA,EAET,MAAME,EAASC,aAAaC,QAAQL,GACpC,OAAOG,EAASG,KAAKC,MAAMJ,QAAUD,CACvC,CAAE,MAAOM,GAEP,YADAlB,QAAQkB,MAAM,0BAA2BA,EAE3C,GAEFC,IAAK,CAACT,EAAaC,KACjB,IACElB,EAAU0B,IAAIT,EAAKC,GACnBG,aAAaM,QAAQV,EAAKM,KAAKK,UAAUV,GAC3C,CAAE,MAAOO,GACPlB,QAAQkB,MAAM,0BAA2BA,EAC3C,GAEFI,OAASZ,IACP,IACEjB,EAAU6B,OAAOZ,GACjBI,aAAaS,WAAWb,EAC1B,CAAE,MAAOQ,GACPlB,QAAQkB,MAAM,2BAA4BA,EAC5C,GAEFM,MAAO,KACL,IAEE,MAAMC,EAAeC,MAAMC,KAAKlC,EAAUmC,QAC1CnC,EAAU+B,QAEVC,EAAaI,QAAQnB,GAAOI,aAAaS,WAAWb,GACtD,CAAE,MAAOQ,GACPlB,QAAQkB,MAAM,6BAA8BA,EAC9C,GAEFU,KAAM,IAAMF,MAAMC,KAAKlC,EAAUmC,SAGnCE,IAAKnC,EAELoC,KAAM,CACJC,eAAgB,KAAA,CACdC,GAAI,eACJC,KAAM,YACNC,MAAO,qBAETC,gBAAiB,KAAM"}
{"version":3,"file":"spark-runtime-wNXbhm34.js","sources":["../src/lib/spark-runtime.ts"],"sourcesContent":["/**\n * Spark Runtime - Core runtime services for Spark applications\n * \n * This module provides mock implementations of Spark services including:\n * - KV storage (key-value store)\n * - LLM service (language model integration)\n * - User authentication\n */\n\n// Type definitions for LLM responses\ninterface LLMChatResponse {\n role: string\n content: string\n}\n\n// Mock KV Storage\nconst kvStorage = new Map<string, any>()\n\n// Create llm function with additional properties\nconst llmFunction = async (prompt: string, model?: string, jsonMode?: boolean): Promise<string> => {\n console.log('Mock LLM called with prompt:', prompt, 'model:', model, 'jsonMode:', jsonMode)\n return 'This is a mock response from the Spark LLM service.'\n}\n\nllmFunction.chat = async (messages: any[]): Promise<LLMChatResponse> => {\n console.log('Mock LLM chat called with messages:', messages)\n return {\n role: 'assistant',\n content: 'This is a mock response from the Spark LLM service.'\n }\n}\n\nllmFunction.complete = async (prompt: string): Promise<string> => {\n console.log('Mock LLM complete called with prompt:', prompt)\n return 'This is a mock completion from the Spark LLM service.'\n}\n\nexport const sparkRuntime = {\n kv: {\n get: <T = any>(key: string): T | undefined => {\n try {\n const value = kvStorage.get(key)\n if (value !== undefined) {\n return value as T\n }\n const stored = localStorage.getItem(key)\n return stored ? JSON.parse(stored) : undefined\n } catch (error) {\n console.error('Error getting KV value:', error)\n return undefined\n }\n },\n set: (key: string, value: any) => {\n try {\n kvStorage.set(key, value)\n localStorage.setItem(key, JSON.stringify(value))\n } catch (error) {\n console.error('Error setting KV value:', error)\n }\n },\n delete: (key: string) => {\n try {\n kvStorage.delete(key)\n localStorage.removeItem(key)\n } catch (error) {\n console.error('Error deleting KV value:', error)\n }\n },\n clear: () => {\n try {\n // Get keys before clearing\n const keysToRemove = Array.from(kvStorage.keys())\n kvStorage.clear()\n // Clear corresponding keys from localStorage\n keysToRemove.forEach(key => localStorage.removeItem(key))\n } catch (error) {\n console.error('Error clearing KV storage:', error)\n }\n },\n keys: () => Array.from(kvStorage.keys())\n },\n \n llm: llmFunction,\n \n user: {\n getCurrentUser: () => ({\n id: 'mock-user-id',\n name: 'Mock User',\n email: 'mock@example.com'\n }),\n isAuthenticated: () => true\n }\n}\n"],"names":["kvStorage","Map","llmFunction","async","prompt","model","jsonMode","console","log","chat","messages","role","content","complete","sparkRuntime","kv","get","key","value","undefined","stored","localStorage","getItem","JSON","parse","error","set","setItem","stringify","delete","removeItem","clear","keysToRemove","Array","from","keys","forEach","llm","user","getCurrentUser","id","name","email","isAuthenticated"],"mappings":"AAgBA,MAAMA,EAAY,IAAIC,IAGhBC,EAAcC,MAAOC,EAAgBC,EAAgBC,KACzDC,QAAQC,IAAI,+BAAgCJ,EAAQ,SAAUC,EAAO,YAAaC,GAC3E,uDAGTJ,EAAYO,KAAON,MAAOO,IACxBH,QAAQC,IAAI,sCAAuCE,GAC5C,CACLC,KAAM,YACNC,QAAS,wDAIbV,EAAYW,SAAWV,MAAOC,IAC5BG,QAAQC,IAAI,wCAAyCJ,GAC9C,yDAGF,MAAMU,EAAe,CAC1BC,GAAI,CACFC,IAAeC,IACb,IACE,MAAMC,EAAQlB,EAAUgB,IAAIC,GAC5B,QAAcE,IAAVD,EACF,OAAOA,EAET,MAAME,EAASC,aAAaC,QAAQL,GACpC,OAAOG,EAASG,KAAKC,MAAMJ,QAAUD,CACvC,CAAE,MAAOM,GAEP,YADAlB,QAAQkB,MAAM,0BAA2BA,EAE3C,GAEFC,IAAK,CAACT,EAAaC,KACjB,IACElB,EAAU0B,IAAIT,EAAKC,GACnBG,aAAaM,QAAQV,EAAKM,KAAKK,UAAUV,GAC3C,CAAE,MAAOO,GACPlB,QAAQkB,MAAM,0BAA2BA,EAC3C,GAEFI,OAASZ,IACP,IACEjB,EAAU6B,OAAOZ,GACjBI,aAAaS,WAAWb,EAC1B,CAAE,MAAOQ,GACPlB,QAAQkB,MAAM,2BAA4BA,EAC5C,GAEFM,MAAO,KACL,IAEE,MAAMC,EAAeC,MAAMC,KAAKlC,EAAUmC,QAC1CnC,EAAU+B,QAEVC,EAAaI,QAAQnB,GAAOI,aAAaS,WAAWb,GACtD,CAAE,MAAOQ,GACPlB,QAAQkB,MAAM,6BAA8BA,EAC9C,GAEFU,KAAM,IAAMF,MAAMC,KAAKlC,EAAUmC,SAGnCE,IAAKnC,EAELoC,KAAM,CACJC,eAAgB,KAAA,CACdC,GAAI,eACJC,KAAM,YACNC,MAAO,qBAETC,gBAAiB,KAAM"}

View File

@@ -2,7 +2,10 @@
* Spark Vite Plugin
*
* This plugin integrates Spark functionality into the Vite build process.
* It handles initialization and configuration of Spark features.
* Currently provides a minimal implementation that can be extended with:
* - Spark runtime injection
* - Configuration validation
* - Development server enhancements
*/
export default function sparkPlugin(): {
name: string;

View File

@@ -1 +1 @@
{"version":3,"file":"sparkVitePlugin.d.ts","sourceRoot":"","sources":["../src/sparkVitePlugin.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,CAAC,OAAO,UAAU,WAAW;;2BAIR,GAAG;6BAID,MAAM;EAKlC"}
{"version":3,"file":"sparkVitePlugin.d.ts","sourceRoot":"","sources":["../src/sparkVitePlugin.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,MAAM,CAAC,OAAO,UAAU,WAAW;;2BAIR,GAAG;6BAKD,MAAM;EAMlC"}

View File

@@ -1 +1 @@
{"version":3,"file":"sparkVitePlugin.js","sources":["../src/sparkVitePlugin.ts"],"sourcesContent":["/**\n * Spark Vite Plugin\n * \n * This plugin integrates Spark functionality into the Vite build process.\n * It handles initialization and configuration of Spark features.\n */\n\nexport default function sparkPlugin() {\n return {\n name: 'spark-vite-plugin',\n \n configResolved(config: any) {\n // Plugin configuration\n },\n \n transformIndexHtml(html: string) {\n // Inject Spark initialization if needed\n return html\n }\n }\n}\n"],"names":["sparkPlugin","name","configResolved","config","transformIndexHtml","html"],"mappings":"AAOc,SAAUA,IACtB,MAAO,CACLC,KAAM,oBAEN,cAAAC,CAAeC,GAEf,EAEAC,mBAAmBC,GAEVA,EAGb"}
{"version":3,"file":"sparkVitePlugin.js","sources":["../src/sparkVitePlugin.ts"],"sourcesContent":["/**\n * Spark Vite Plugin\n * \n * This plugin integrates Spark functionality into the Vite build process.\n * Currently provides a minimal implementation that can be extended with:\n * - Spark runtime injection\n * - Configuration validation\n * - Development server enhancements\n */\n\nexport default function sparkPlugin() {\n return {\n name: 'spark-vite-plugin',\n \n configResolved(config: any) {\n // TODO: Add Spark-specific configuration handling if needed\n // This hook is called after the Vite config is resolved\n },\n \n transformIndexHtml(html: string) {\n // TODO: Add Spark runtime injection to HTML if needed\n // Currently returns HTML unchanged\n return html\n }\n }\n}\n"],"names":["sparkPlugin","name","configResolved","config","transformIndexHtml","html"],"mappings":"AAUc,SAAUA,IACtB,MAAO,CACLC,KAAM,oBAEN,cAAAC,CAAeC,GAGf,EAEAC,mBAAmBC,GAGVA,EAGb"}

View File

@@ -1,8 +1,12 @@
/**
* Vite Phosphor Icon Proxy Plugin
*
* This plugin provides a proxy for Phosphor icon imports to improve
* build performance and bundle size.
* This plugin provides a proxy for Phosphor icon imports.
* Currently provides a pass-through implementation that allows
* Vite to handle icon imports normally. Can be extended to:
* - Optimize icon bundle sizes
* - Implement lazy loading for icons
* - Transform icon imports for better tree-shaking
*/
export default function createIconImportProxy(): {
name: string;

View File

@@ -1 +1 @@
{"version":3,"file":"vitePhosphorIconProxyPlugin.d.ts","sourceRoot":"","sources":["../src/vitePhosphorIconProxyPlugin.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,CAAC,OAAO,UAAU,qBAAqB;;kBAI3B,MAAM;oBAOJ,MAAM,MAAM,MAAM;EAKrC"}
{"version":3,"file":"vitePhosphorIconProxyPlugin.d.ts","sourceRoot":"","sources":["../src/vitePhosphorIconProxyPlugin.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,MAAM,CAAC,OAAO,UAAU,qBAAqB;;kBAI3B,MAAM;oBAQJ,MAAM,MAAM,MAAM;EAMrC"}

View File

@@ -1 +1 @@
{"version":3,"file":"vitePhosphorIconProxyPlugin.js","sources":["../src/vitePhosphorIconProxyPlugin.ts"],"sourcesContent":["/**\n * Vite Phosphor Icon Proxy Plugin\n * \n * This plugin provides a proxy for Phosphor icon imports to improve\n * build performance and bundle size.\n */\n\nexport default function createIconImportProxy() {\n return {\n name: 'vite-phosphor-icon-proxy',\n \n resolveId(id: string) {\n // Handle icon imports\n if (id.includes('@phosphor-icons/react')) {\n return null // Let Vite handle it normally\n }\n },\n \n transform(code: string, id: string) {\n // Transform icon imports if needed\n return null\n }\n }\n}\n"],"names":["createIconImportProxy","name","resolveId","id","includes","transform","code"],"mappings":"AAOc,SAAUA,IACtB,MAAO,CACLC,KAAM,2BAEN,SAAAC,CAAUC,GAER,GAAIA,EAAGC,SAAS,yBACd,OAAO,IAEX,EAEAC,UAAS,CAACC,EAAcH,IAEf,KAGb"}
{"version":3,"file":"vitePhosphorIconProxyPlugin.js","sources":["../src/vitePhosphorIconProxyPlugin.ts"],"sourcesContent":["/**\n * Vite Phosphor Icon Proxy Plugin\n * \n * This plugin provides a proxy for Phosphor icon imports.\n * Currently provides a pass-through implementation that allows\n * Vite to handle icon imports normally. Can be extended to:\n * - Optimize icon bundle sizes\n * - Implement lazy loading for icons\n * - Transform icon imports for better tree-shaking\n */\n\nexport default function createIconImportProxy() {\n return {\n name: 'vite-phosphor-icon-proxy',\n \n resolveId(id: string) {\n // TODO: Add custom icon resolution if needed\n // Currently lets Vite handle all icon imports normally\n if (id.includes('@phosphor-icons/react')) {\n return null // Let Vite handle it normally\n }\n },\n \n transform(code: string, id: string) {\n // TODO: Add icon import transformations if needed\n // Currently returns null to let Vite handle transformations\n return null\n }\n }\n}\n"],"names":["createIconImportProxy","name","resolveId","id","includes","transform","code"],"mappings":"AAWc,SAAUA,IACtB,MAAO,CACLC,KAAM,2BAEN,SAAAC,CAAUC,GAGR,GAAIA,EAAGC,SAAS,yBACd,OAAO,IAEX,EAEAC,UAAS,CAACC,EAAcH,IAGf,KAGb"}

View File

@@ -7,16 +7,22 @@
* - User authentication
*/
// Type definitions for LLM responses
interface LLMChatResponse {
role: string
content: string
}
// 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> => {
const llmFunction = async (prompt: string, model?: string, jsonMode?: boolean): Promise<string> => {
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[]) => {
llmFunction.chat = async (messages: any[]): Promise<LLMChatResponse> => {
console.log('Mock LLM chat called with messages:', messages)
return {
role: 'assistant',
@@ -24,7 +30,7 @@ llmFunction.chat = async (messages: any[]) => {
}
}
llmFunction.complete = async (prompt: string) => {
llmFunction.complete = async (prompt: string): Promise<string> => {
console.log('Mock LLM complete called with prompt:', prompt)
return 'This is a mock completion from the Spark LLM service.'
}

View File

@@ -2,7 +2,10 @@
* Spark Vite Plugin
*
* This plugin integrates Spark functionality into the Vite build process.
* It handles initialization and configuration of Spark features.
* Currently provides a minimal implementation that can be extended with:
* - Spark runtime injection
* - Configuration validation
* - Development server enhancements
*/
export default function sparkPlugin() {
@@ -10,11 +13,13 @@ export default function sparkPlugin() {
name: 'spark-vite-plugin',
configResolved(config: any) {
// Plugin configuration
// TODO: Add Spark-specific configuration handling if needed
// This hook is called after the Vite config is resolved
},
transformIndexHtml(html: string) {
// Inject Spark initialization if needed
// TODO: Add Spark runtime injection to HTML if needed
// Currently returns HTML unchanged
return html
}
}

View File

@@ -1,8 +1,12 @@
/**
* Vite Phosphor Icon Proxy Plugin
*
* This plugin provides a proxy for Phosphor icon imports to improve
* build performance and bundle size.
* This plugin provides a proxy for Phosphor icon imports.
* Currently provides a pass-through implementation that allows
* Vite to handle icon imports normally. Can be extended to:
* - Optimize icon bundle sizes
* - Implement lazy loading for icons
* - Transform icon imports for better tree-shaking
*/
export default function createIconImportProxy() {
@@ -10,14 +14,16 @@ export default function createIconImportProxy() {
name: 'vite-phosphor-icon-proxy',
resolveId(id: string) {
// Handle icon imports
// TODO: Add custom icon resolution if needed
// Currently lets Vite handle all icon imports normally
if (id.includes('@phosphor-icons/react')) {
return null // Let Vite handle it normally
}
},
transform(code: string, id: string) {
// Transform icon imports if needed
// TODO: Add icon import transformations if needed
// Currently returns null to let Vite handle transformations
return null
}
}