@jupyterlite/ai 0.8.0 → 0.9.0-a0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (162) hide show
  1. package/lib/agent.d.ts +233 -0
  2. package/lib/agent.js +604 -0
  3. package/lib/chat-model.d.ts +195 -0
  4. package/lib/chat-model.js +590 -0
  5. package/lib/completion/completion-provider.d.ts +83 -0
  6. package/lib/completion/completion-provider.js +209 -0
  7. package/lib/completion/index.d.ts +1 -0
  8. package/lib/completion/index.js +1 -0
  9. package/lib/components/clear-button.d.ts +18 -0
  10. package/lib/components/clear-button.js +31 -0
  11. package/lib/components/index.d.ts +3 -0
  12. package/lib/components/index.js +3 -0
  13. package/lib/components/model-select.d.ts +19 -0
  14. package/lib/components/model-select.js +154 -0
  15. package/lib/components/stop-button.d.ts +3 -3
  16. package/lib/components/stop-button.js +8 -9
  17. package/lib/components/token-usage-display.d.ts +45 -0
  18. package/lib/components/token-usage-display.js +74 -0
  19. package/lib/components/tool-select.d.ts +27 -0
  20. package/lib/components/tool-select.js +130 -0
  21. package/lib/icons.d.ts +3 -1
  22. package/lib/icons.js +10 -13
  23. package/lib/index.d.ts +4 -5
  24. package/lib/index.js +322 -167
  25. package/lib/mcp/browser.d.ts +68 -0
  26. package/lib/mcp/browser.js +132 -0
  27. package/lib/models/settings-model.d.ts +69 -0
  28. package/lib/models/settings-model.js +295 -0
  29. package/lib/providers/built-in-providers.d.ts +9 -0
  30. package/lib/providers/built-in-providers.js +192 -0
  31. package/lib/providers/models.d.ts +37 -0
  32. package/lib/providers/models.js +28 -0
  33. package/lib/providers/provider-registry.d.ts +94 -0
  34. package/lib/providers/provider-registry.js +155 -0
  35. package/lib/tokens.d.ts +157 -86
  36. package/lib/tokens.js +16 -12
  37. package/lib/tools/commands.d.ts +11 -0
  38. package/lib/tools/commands.js +126 -0
  39. package/lib/tools/file.d.ts +27 -0
  40. package/lib/tools/file.js +262 -0
  41. package/lib/tools/notebook.d.ts +40 -0
  42. package/lib/tools/notebook.js +762 -0
  43. package/lib/tools/tool-registry.d.ts +35 -0
  44. package/lib/tools/tool-registry.js +55 -0
  45. package/lib/widgets/ai-settings.d.ts +39 -0
  46. package/lib/widgets/ai-settings.js +506 -0
  47. package/lib/widgets/chat-wrapper.d.ts +144 -0
  48. package/lib/widgets/chat-wrapper.js +390 -0
  49. package/lib/widgets/provider-config-dialog.d.ts +13 -0
  50. package/lib/widgets/provider-config-dialog.js +104 -0
  51. package/package.json +150 -41
  52. package/schema/settings-model.json +153 -0
  53. package/src/agent.ts +800 -0
  54. package/src/chat-model.ts +770 -0
  55. package/src/completion/completion-provider.ts +308 -0
  56. package/src/completion/index.ts +1 -0
  57. package/src/components/clear-button.tsx +56 -0
  58. package/src/components/index.ts +3 -0
  59. package/src/components/model-select.tsx +245 -0
  60. package/src/components/stop-button.tsx +11 -11
  61. package/src/components/token-usage-display.tsx +130 -0
  62. package/src/components/tool-select.tsx +218 -0
  63. package/src/icons.ts +12 -14
  64. package/src/index.ts +468 -238
  65. package/src/mcp/browser.ts +213 -0
  66. package/src/models/settings-model.ts +409 -0
  67. package/src/providers/built-in-providers.ts +216 -0
  68. package/src/providers/models.ts +79 -0
  69. package/src/providers/provider-registry.ts +189 -0
  70. package/src/tokens.ts +203 -90
  71. package/src/tools/commands.ts +151 -0
  72. package/src/tools/file.ts +307 -0
  73. package/src/tools/notebook.ts +964 -0
  74. package/src/tools/tool-registry.ts +63 -0
  75. package/src/types.d.ts +4 -0
  76. package/src/widgets/ai-settings.tsx +1100 -0
  77. package/src/widgets/chat-wrapper.tsx +543 -0
  78. package/src/widgets/provider-config-dialog.tsx +256 -0
  79. package/style/base.css +335 -14
  80. package/style/icons/jupyternaut-lite.svg +1 -1
  81. package/lib/base-completer.d.ts +0 -49
  82. package/lib/base-completer.js +0 -14
  83. package/lib/chat-handler.d.ts +0 -56
  84. package/lib/chat-handler.js +0 -201
  85. package/lib/completion-provider.d.ts +0 -34
  86. package/lib/completion-provider.js +0 -32
  87. package/lib/default-prompts.d.ts +0 -2
  88. package/lib/default-prompts.js +0 -31
  89. package/lib/default-providers/Anthropic/completer.d.ts +0 -12
  90. package/lib/default-providers/Anthropic/completer.js +0 -46
  91. package/lib/default-providers/Anthropic/settings-schema.json +0 -70
  92. package/lib/default-providers/ChromeAI/completer.d.ts +0 -12
  93. package/lib/default-providers/ChromeAI/completer.js +0 -56
  94. package/lib/default-providers/ChromeAI/instructions.d.ts +0 -6
  95. package/lib/default-providers/ChromeAI/instructions.js +0 -42
  96. package/lib/default-providers/ChromeAI/settings-schema.json +0 -18
  97. package/lib/default-providers/Gemini/completer.d.ts +0 -12
  98. package/lib/default-providers/Gemini/completer.js +0 -48
  99. package/lib/default-providers/Gemini/instructions.d.ts +0 -2
  100. package/lib/default-providers/Gemini/instructions.js +0 -9
  101. package/lib/default-providers/Gemini/settings-schema.json +0 -64
  102. package/lib/default-providers/MistralAI/completer.d.ts +0 -13
  103. package/lib/default-providers/MistralAI/completer.js +0 -52
  104. package/lib/default-providers/MistralAI/instructions.d.ts +0 -2
  105. package/lib/default-providers/MistralAI/instructions.js +0 -18
  106. package/lib/default-providers/MistralAI/settings-schema.json +0 -75
  107. package/lib/default-providers/Ollama/completer.d.ts +0 -12
  108. package/lib/default-providers/Ollama/completer.js +0 -43
  109. package/lib/default-providers/Ollama/instructions.d.ts +0 -2
  110. package/lib/default-providers/Ollama/instructions.js +0 -70
  111. package/lib/default-providers/Ollama/settings-schema.json +0 -143
  112. package/lib/default-providers/OpenAI/completer.d.ts +0 -12
  113. package/lib/default-providers/OpenAI/completer.js +0 -43
  114. package/lib/default-providers/OpenAI/settings-schema.json +0 -628
  115. package/lib/default-providers/WebLLM/completer.d.ts +0 -21
  116. package/lib/default-providers/WebLLM/completer.js +0 -127
  117. package/lib/default-providers/WebLLM/instructions.d.ts +0 -6
  118. package/lib/default-providers/WebLLM/instructions.js +0 -32
  119. package/lib/default-providers/WebLLM/settings-schema.json +0 -19
  120. package/lib/default-providers/index.d.ts +0 -2
  121. package/lib/default-providers/index.js +0 -179
  122. package/lib/provider.d.ts +0 -144
  123. package/lib/provider.js +0 -412
  124. package/lib/settings/base.json +0 -7
  125. package/lib/settings/index.d.ts +0 -3
  126. package/lib/settings/index.js +0 -3
  127. package/lib/settings/panel.d.ts +0 -226
  128. package/lib/settings/panel.js +0 -510
  129. package/lib/settings/textarea.d.ts +0 -2
  130. package/lib/settings/textarea.js +0 -18
  131. package/lib/settings/utils.d.ts +0 -2
  132. package/lib/settings/utils.js +0 -4
  133. package/lib/types/ai-model.d.ts +0 -24
  134. package/lib/types/ai-model.js +0 -5
  135. package/schema/chat.json +0 -28
  136. package/schema/provider-registry.json +0 -29
  137. package/schema/system-prompts.json +0 -22
  138. package/src/base-completer.ts +0 -75
  139. package/src/chat-handler.ts +0 -262
  140. package/src/completion-provider.ts +0 -64
  141. package/src/default-prompts.ts +0 -33
  142. package/src/default-providers/Anthropic/completer.ts +0 -59
  143. package/src/default-providers/ChromeAI/completer.ts +0 -73
  144. package/src/default-providers/ChromeAI/instructions.ts +0 -45
  145. package/src/default-providers/Gemini/completer.ts +0 -61
  146. package/src/default-providers/Gemini/instructions.ts +0 -9
  147. package/src/default-providers/MistralAI/completer.ts +0 -69
  148. package/src/default-providers/MistralAI/instructions.ts +0 -18
  149. package/src/default-providers/Ollama/completer.ts +0 -54
  150. package/src/default-providers/Ollama/instructions.ts +0 -70
  151. package/src/default-providers/OpenAI/completer.ts +0 -54
  152. package/src/default-providers/WebLLM/completer.ts +0 -151
  153. package/src/default-providers/WebLLM/instructions.ts +0 -33
  154. package/src/default-providers/index.ts +0 -211
  155. package/src/global.d.ts +0 -9
  156. package/src/provider.ts +0 -514
  157. package/src/settings/index.ts +0 -3
  158. package/src/settings/panel.tsx +0 -773
  159. package/src/settings/textarea.tsx +0 -33
  160. package/src/settings/utils.ts +0 -5
  161. package/src/types/ai-model.ts +0 -37
  162. package/src/types/service-worker.d.ts +0 -6
@@ -0,0 +1,37 @@
1
+ import type { LanguageModel } from 'ai';
2
+ import type { IChatProviderRegistry, ICompletionProviderRegistry } from '../tokens';
3
+ /**
4
+ * Configuration options for creating language models.
5
+ */
6
+ export interface IModelOptions {
7
+ /**
8
+ * The provider name (e.g., 'openai', 'anthropic', 'huggingface')
9
+ */
10
+ provider: string;
11
+ /**
12
+ * The specific model name. If not provided, uses provider's default model
13
+ */
14
+ model?: string;
15
+ /**
16
+ * API key for authentication with the provider
17
+ */
18
+ apiKey?: string;
19
+ /**
20
+ * Additional HTTP headers to send with requests
21
+ */
22
+ headers?: Record<string, string>;
23
+ /**
24
+ * Custom base URL for the provider's API endpoint
25
+ */
26
+ baseURL?: string;
27
+ }
28
+ /**
29
+ * Create a completion model using the provider registry.
30
+ * Built-in providers are automatically registered during extension initialization.
31
+ */
32
+ export declare function createCompletionModel(options: IModelOptions, registry?: ICompletionProviderRegistry): LanguageModel;
33
+ /**
34
+ * Create a chat model using the provider registry.
35
+ * Built-in providers are automatically registered during extension initialization.
36
+ */
37
+ export declare function createModel(options: IModelOptions, registry?: IChatProviderRegistry): any;
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Create a completion model using the provider registry.
3
+ * Built-in providers are automatically registered during extension initialization.
4
+ */
5
+ export function createCompletionModel(options, registry) {
6
+ if (!registry) {
7
+ throw new Error('Completion provider registry not available');
8
+ }
9
+ const model = registry.createCompletionModel(options.provider, options);
10
+ if (!model) {
11
+ throw new Error(`Provider ${options.provider} not found or failed to create model`);
12
+ }
13
+ return model;
14
+ }
15
+ /**
16
+ * Create a chat model using the provider registry.
17
+ * Built-in providers are automatically registered during extension initialization.
18
+ */
19
+ export function createModel(options, registry) {
20
+ if (!registry) {
21
+ throw new Error('Chat provider registry not available');
22
+ }
23
+ const model = registry.createChatModel(options.provider, options);
24
+ if (!model) {
25
+ throw new Error(`Provider ${options.provider} not found or failed to create model`);
26
+ }
27
+ return model;
28
+ }
@@ -0,0 +1,94 @@
1
+ import { ISignal } from '@lumino/signaling';
2
+ import type { LanguageModel } from 'ai';
3
+ import type { IModelOptions } from './models';
4
+ import { IChatProviderInfo, IChatProviderRegistry, ICompletionProviderInfo, ICompletionProviderRegistry } from '../tokens';
5
+ /**
6
+ * Implementation of the chat provider registry
7
+ */
8
+ export declare class ChatProviderRegistry implements IChatProviderRegistry {
9
+ /**
10
+ * Get a copy of all registered providers
11
+ */
12
+ get providers(): Record<string, IChatProviderInfo>;
13
+ /**
14
+ * Signal emitted when providers are added or removed
15
+ */
16
+ get providersChanged(): ISignal<IChatProviderRegistry, void>;
17
+ /**
18
+ * Register a new chat provider
19
+ * @param info Provider information including factory
20
+ */
21
+ registerProvider(info: IChatProviderInfo): void;
22
+ /**
23
+ * Unregister a chat provider by ID
24
+ * @param id Provider ID to remove
25
+ * @returns true if provider was found and removed, false otherwise
26
+ */
27
+ unregisterProvider(id: string): boolean;
28
+ /**
29
+ * Get provider information by ID
30
+ * @param id Provider ID
31
+ * @returns Provider info or null if not found
32
+ */
33
+ getProviderInfo(id: string): IChatProviderInfo | null;
34
+ /**
35
+ * Create a chat model instance using the specified provider
36
+ * @param id Provider ID
37
+ * @param options Model configuration options
38
+ * @returns Chat model instance or null if creation fails
39
+ */
40
+ createChatModel(id: string, options: IModelOptions): any | null;
41
+ /**
42
+ * Get list of all available provider IDs
43
+ * @returns Array of provider IDs
44
+ */
45
+ getAvailableProviders(): string[];
46
+ private _providers;
47
+ private _factories;
48
+ private _providersChanged;
49
+ }
50
+ /**
51
+ * Implementation of the completion provider registry
52
+ */
53
+ export declare class CompletionProviderRegistry implements ICompletionProviderRegistry {
54
+ /**
55
+ * Get a copy of all registered providers
56
+ */
57
+ get providers(): Record<string, ICompletionProviderInfo>;
58
+ /**
59
+ * Signal emitted when providers are added or removed
60
+ */
61
+ get providersChanged(): ISignal<ICompletionProviderRegistry, void>;
62
+ /**
63
+ * Register a new completion provider
64
+ * @param info Provider information including factory
65
+ */
66
+ registerProvider(info: ICompletionProviderInfo): void;
67
+ /**
68
+ * Unregister a completion provider by ID
69
+ * @param id Provider ID to remove
70
+ * @returns true if provider was found and removed, false otherwise
71
+ */
72
+ unregisterProvider(id: string): boolean;
73
+ /**
74
+ * Get provider information by ID
75
+ * @param id Provider ID
76
+ * @returns Provider info or null if not found
77
+ */
78
+ getProviderInfo(id: string): ICompletionProviderInfo | null;
79
+ /**
80
+ * Create a completion model instance using the specified provider
81
+ * @param id Provider ID
82
+ * @param options Model configuration options
83
+ * @returns Language model instance or null if creation fails
84
+ */
85
+ createCompletionModel(id: string, options: IModelOptions): LanguageModel | null;
86
+ /**
87
+ * Get list of all available provider IDs
88
+ * @returns Array of provider IDs
89
+ */
90
+ getAvailableProviders(): string[];
91
+ private _providers;
92
+ private _factories;
93
+ private _providersChanged;
94
+ }
@@ -0,0 +1,155 @@
1
+ import { Signal } from '@lumino/signaling';
2
+ /**
3
+ * Implementation of the chat provider registry
4
+ */
5
+ export class ChatProviderRegistry {
6
+ /**
7
+ * Get a copy of all registered providers
8
+ */
9
+ get providers() {
10
+ return { ...this._providers };
11
+ }
12
+ /**
13
+ * Signal emitted when providers are added or removed
14
+ */
15
+ get providersChanged() {
16
+ return this._providersChanged;
17
+ }
18
+ /**
19
+ * Register a new chat provider
20
+ * @param info Provider information including factory
21
+ */
22
+ registerProvider(info) {
23
+ this._providers[info.id] = { ...info };
24
+ this._factories[info.id] = info.factory;
25
+ this._providersChanged.emit();
26
+ }
27
+ /**
28
+ * Unregister a chat provider by ID
29
+ * @param id Provider ID to remove
30
+ * @returns true if provider was found and removed, false otherwise
31
+ */
32
+ unregisterProvider(id) {
33
+ if (id in this._providers) {
34
+ delete this._providers[id];
35
+ delete this._factories[id];
36
+ this._providersChanged.emit();
37
+ return true;
38
+ }
39
+ return false;
40
+ }
41
+ /**
42
+ * Get provider information by ID
43
+ * @param id Provider ID
44
+ * @returns Provider info or null if not found
45
+ */
46
+ getProviderInfo(id) {
47
+ return this._providers[id] || null;
48
+ }
49
+ /**
50
+ * Create a chat model instance using the specified provider
51
+ * @param id Provider ID
52
+ * @param options Model configuration options
53
+ * @returns Chat model instance or null if creation fails
54
+ */
55
+ createChatModel(id, options) {
56
+ const factory = this._factories[id];
57
+ if (!factory) {
58
+ return null;
59
+ }
60
+ try {
61
+ return factory(options);
62
+ }
63
+ catch (error) {
64
+ console.error(`Failed to create chat model for provider ${id}:`, error);
65
+ return null;
66
+ }
67
+ }
68
+ /**
69
+ * Get list of all available provider IDs
70
+ * @returns Array of provider IDs
71
+ */
72
+ getAvailableProviders() {
73
+ return Object.keys(this._providers);
74
+ }
75
+ _providers = {};
76
+ _factories = {};
77
+ _providersChanged = new Signal(this);
78
+ }
79
+ /**
80
+ * Implementation of the completion provider registry
81
+ */
82
+ export class CompletionProviderRegistry {
83
+ /**
84
+ * Get a copy of all registered providers
85
+ */
86
+ get providers() {
87
+ return { ...this._providers };
88
+ }
89
+ /**
90
+ * Signal emitted when providers are added or removed
91
+ */
92
+ get providersChanged() {
93
+ return this._providersChanged;
94
+ }
95
+ /**
96
+ * Register a new completion provider
97
+ * @param info Provider information including factory
98
+ */
99
+ registerProvider(info) {
100
+ this._providers[info.id] = { ...info };
101
+ this._factories[info.id] = info.factory;
102
+ this._providersChanged.emit();
103
+ }
104
+ /**
105
+ * Unregister a completion provider by ID
106
+ * @param id Provider ID to remove
107
+ * @returns true if provider was found and removed, false otherwise
108
+ */
109
+ unregisterProvider(id) {
110
+ if (id in this._providers) {
111
+ delete this._providers[id];
112
+ delete this._factories[id];
113
+ this._providersChanged.emit();
114
+ return true;
115
+ }
116
+ return false;
117
+ }
118
+ /**
119
+ * Get provider information by ID
120
+ * @param id Provider ID
121
+ * @returns Provider info or null if not found
122
+ */
123
+ getProviderInfo(id) {
124
+ return this._providers[id] || null;
125
+ }
126
+ /**
127
+ * Create a completion model instance using the specified provider
128
+ * @param id Provider ID
129
+ * @param options Model configuration options
130
+ * @returns Language model instance or null if creation fails
131
+ */
132
+ createCompletionModel(id, options) {
133
+ const factory = this._factories[id];
134
+ if (!factory) {
135
+ return null;
136
+ }
137
+ try {
138
+ return factory(options);
139
+ }
140
+ catch (error) {
141
+ console.error(`Failed to create completion model for provider ${id}:`, error);
142
+ return null;
143
+ }
144
+ }
145
+ /**
146
+ * Get list of all available provider IDs
147
+ * @returns Array of provider IDs
148
+ */
149
+ getAvailableProviders() {
150
+ return Object.keys(this._providers);
151
+ }
152
+ _providers = {};
153
+ _factories = {};
154
+ _providersChanged = new Signal(this);
155
+ }
package/lib/tokens.d.ts CHANGED
@@ -1,145 +1,216 @@
1
- import { BaseChatModel } from '@langchain/core/language_models/chat_models';
2
- import { ReadonlyPartialJSONObject, Token } from '@lumino/coreutils';
1
+ import { Token } from '@lumino/coreutils';
3
2
  import { ISignal } from '@lumino/signaling';
4
- import { JSONSchema7 } from 'json-schema';
5
- import { IBaseCompleter } from './base-completer';
6
- import { AIChatModel, AICompleter } from './types/ai-model';
7
- export declare const PLUGIN_IDS: {
8
- chat: string;
9
- chatCommandRegistry: string;
10
- completer: string;
11
- providerRegistry: string;
12
- settingsConnector: string;
13
- systemPrompts: string;
14
- };
15
- export type ModelRole = 'chat' | 'completer';
16
- export interface IDict<T = any> {
17
- [key: string]: T;
18
- }
19
- export interface IType<T> {
20
- new (...args: any[]): T;
3
+ import { FunctionTool } from '@openai/agents';
4
+ import { LanguageModel } from 'ai';
5
+ import type { AISettingsModel } from './models/settings-model';
6
+ import type { IModelOptions } from './providers/models';
7
+ /**
8
+ * Type definition for a tool
9
+ */
10
+ export type ITool = FunctionTool<any, any, any>;
11
+ /**
12
+ * Interface for token usage statistics from AI model interactions
13
+ */
14
+ export interface ITokenUsage {
15
+ /**
16
+ * Number of input tokens consumed (prompt tokens)
17
+ */
18
+ inputTokens: number;
19
+ /**
20
+ * Number of output tokens generated (completion tokens)
21
+ */
22
+ outputTokens: number;
21
23
  }
22
24
  /**
23
- * The provider interface.
25
+ * Interface for a named tool (tool with a name identifier)
24
26
  */
25
- export interface IAIProvider {
27
+ export interface INamedTool {
26
28
  /**
27
- * The name of the provider.
29
+ * The unique name of the tool
28
30
  */
29
31
  name: string;
30
32
  /**
31
- * The chat model class to use.
33
+ * The tool instance
32
34
  */
33
- chat?: IType<BaseChatModel>;
35
+ tool: ITool;
36
+ }
37
+ /**
38
+ * The tool registry interface for managing AI tools
39
+ */
40
+ export interface IToolRegistry {
34
41
  /**
35
- * The completer class to use.
42
+ * The registered tools as a record (name -> tool mapping).
36
43
  */
37
- completer?: IType<IBaseCompleter>;
44
+ readonly tools: Record<string, ITool>;
38
45
  /**
39
- * the settings schema for the provider.
46
+ * The registered named tools array.
40
47
  */
41
- settingsSchema?: any;
48
+ readonly namedTools: INamedTool[];
42
49
  /**
43
- * The instructions to be displayed in the settings, as helper to use the provider.
44
- * A markdown renderer is used to render the instructions.
50
+ * A signal triggered when the tools have changed.
45
51
  */
46
- instructions?: string;
52
+ readonly toolsChanged: ISignal<IToolRegistry, void>;
47
53
  /**
48
- * A function that extract the error message from the provider API error.
49
- * Default to `(error) => error.message`.
54
+ * Add a new tool to the registry.
50
55
  */
51
- errorMessage?: (error: any) => string;
56
+ add(name: string, tool: ITool): void;
52
57
  /**
53
- * Compatibility check function, to determine if the provider is compatible with the
54
- * current environment.
58
+ * Get a tool for a given name.
59
+ * Return null if the name is not provided or if there is no registered tool with the
60
+ * given name.
55
61
  */
56
- compatibilityCheck?: () => Promise<string | null>;
62
+ get(name: string | null): ITool | null;
57
63
  /**
58
- * Whether to expose or not the chat model.
59
- *
60
- * ### CAUTION
61
- * This flag will expose the whole chat model API, which may contain private keys.
62
- * Be sure to use it with a model that does not expose sensitive information in the
63
- * API.
64
+ * Remove a tool from the registry by name.
64
65
  */
65
- exposeChatModel?: boolean;
66
+ remove(name: string): boolean;
66
67
  }
67
68
  /**
68
- * The provider registry interface.
69
+ * The tool registry token.
70
+ */
71
+ export declare const IToolRegistry: Token<IToolRegistry>;
72
+ /**
73
+ * Token for the chat provider registry.
69
74
  */
70
- export interface IAIProviderRegistry {
75
+ export declare const IChatProviderRegistry: Token<IChatProviderRegistry>;
76
+ /**
77
+ * Token for the completion provider registry.
78
+ */
79
+ export declare const ICompletionProviderRegistry: Token<ICompletionProviderRegistry>;
80
+ /**
81
+ * Interface for a provider factory function that creates chat models
82
+ */
83
+ export interface IChatProviderFactory {
84
+ (options: IModelOptions): any;
85
+ }
86
+ /**
87
+ * Interface for a provider factory function that creates completion models
88
+ */
89
+ export interface ICompletionProviderFactory {
90
+ (options: IModelOptions): LanguageModel;
91
+ }
92
+ /**
93
+ * Base information about a registered provider
94
+ */
95
+ export interface IBaseProviderInfo {
71
96
  /**
72
- * Get the list of provider names.
97
+ * Unique identifier for the provider
73
98
  */
74
- readonly providers: string[];
99
+ id: string;
75
100
  /**
76
- * Add a new provider.
101
+ * Display name for the provider
77
102
  */
78
- add(provider: IAIProvider): void;
103
+ name: string;
79
104
  /**
80
- * Get the current provider name.
105
+ * Whether this provider requires an API key
81
106
  */
82
- currentName(role: ModelRole): string;
107
+ requiresApiKey: boolean;
83
108
  /**
84
- * Get the current completer of the completion provider.
109
+ * Default model names for this provider
85
110
  */
86
- currentCompleter: AICompleter | null;
111
+ defaultModels: string[];
87
112
  /**
88
- * Getter/setter for the completer system prompt.
113
+ * Whether this provider supports custom base URLs
89
114
  */
90
- completerSystemPrompt: string;
115
+ supportsBaseURL?: boolean;
91
116
  /**
92
- * Get the current llm chat model.
117
+ * Whether this provider supports custom headers
93
118
  */
94
- currentChatModel: AIChatModel | null;
119
+ supportsHeaders?: boolean;
95
120
  /**
96
- * Getter/setter for the chat system prompt.
121
+ * Whether this provider supports tool calling
97
122
  */
98
- chatSystemPrompt: string;
123
+ supportsToolCalling?: boolean;
99
124
  /**
100
- * Get the settings schema of a given provider.
125
+ * Additional provider-specific configuration schema
101
126
  */
102
- getSettingsSchema(provider: string): JSONSchema7;
127
+ customSettings?: Record<string, any>;
128
+ }
129
+ /**
130
+ * Information about a chat provider
131
+ */
132
+ export interface IChatProviderInfo extends IBaseProviderInfo {
133
+ /**
134
+ * Factory function for creating chat models
135
+ */
136
+ factory: IChatProviderFactory;
137
+ }
138
+ /**
139
+ * Information about a completion provider
140
+ */
141
+ export interface ICompletionProviderInfo extends IBaseProviderInfo {
142
+ /**
143
+ * Factory function for creating completion models
144
+ */
145
+ factory: ICompletionProviderFactory;
146
+ }
147
+ /**
148
+ * Registry for chat AI providers
149
+ */
150
+ export interface IChatProviderRegistry {
151
+ /**
152
+ * The registered providers as a record (id -> info mapping).
153
+ */
154
+ readonly providers: Record<string, IChatProviderInfo>;
103
155
  /**
104
- * Get the instructions of a given provider.
156
+ * A signal triggered when providers have changed.
105
157
  */
106
- getInstructions(provider: string): string | undefined;
158
+ readonly providersChanged: ISignal<IChatProviderRegistry, void>;
159
+ /**
160
+ * Register a new chat provider.
161
+ */
162
+ registerProvider(info: IChatProviderInfo): void;
163
+ /**
164
+ * Unregister a chat provider.
165
+ */
166
+ unregisterProvider(id: string): boolean;
167
+ /**
168
+ * Get provider info by id.
169
+ */
170
+ getProviderInfo(id: string): IChatProviderInfo | null;
171
+ /**
172
+ * Create a chat model instance for the given provider.
173
+ */
174
+ createChatModel(id: string, options: IModelOptions): any | null;
175
+ /**
176
+ * Get all available provider IDs.
177
+ */
178
+ getAvailableProviders(): string[];
179
+ }
180
+ /**
181
+ * Registry for completion providers
182
+ */
183
+ export interface ICompletionProviderRegistry {
107
184
  /**
108
- * Get the compatibility check function of a given provider.
185
+ * The registered providers as a record (id -> info mapping).
109
186
  */
110
- getCompatibilityCheck(provider: string): (() => Promise<string | null>) | undefined;
187
+ readonly providers: Record<string, ICompletionProviderInfo>;
111
188
  /**
112
- * Format an error message from the current provider.
189
+ * A signal triggered when providers have changed.
113
190
  */
114
- formatErrorMessage(error: any): string;
191
+ readonly providersChanged: ISignal<ICompletionProviderRegistry, void>;
115
192
  /**
116
- * Set the completer provider.
117
- * Creates the provider if the name has changed, otherwise only updates its config.
118
- *
119
- * @param options - An object with the name and the settings of the provider to use.
193
+ * Register a new completion provider.
120
194
  */
121
- setCompleterProvider(settings: ReadonlyPartialJSONObject): void;
195
+ registerProvider(info: ICompletionProviderInfo): void;
122
196
  /**
123
- * Set the chat provider.
124
- * Creates the provider if the name has changed, otherwise only updates its config.
125
- *
126
- * @param options - An object with the name and the settings of the provider to use.
197
+ * Unregister a completion provider.
127
198
  */
128
- setChatProvider(settings: ReadonlyPartialJSONObject): void;
199
+ unregisterProvider(id: string): boolean;
129
200
  /**
130
- * A signal emitting when the provider or its settings has changed.
201
+ * Get provider info by id.
131
202
  */
132
- readonly providerChanged: ISignal<IAIProviderRegistry, ModelRole>;
203
+ getProviderInfo(id: string): ICompletionProviderInfo | null;
133
204
  /**
134
- * Get the current chat error;
205
+ * Create a completion model instance for the given provider.
135
206
  */
136
- readonly chatError: string;
207
+ createCompletionModel(id: string, options: IModelOptions): LanguageModel | null;
137
208
  /**
138
- * get the current completer error.
209
+ * Get all available provider IDs.
139
210
  */
140
- readonly completerError: string;
211
+ getAvailableProviders(): string[];
141
212
  }
142
213
  /**
143
- * The provider registry token.
214
+ * Token for the AI settings model.
144
215
  */
145
- export declare const IAIProviderRegistry: Token<IAIProviderRegistry>;
216
+ export declare const IAISettingsModel: Token<AISettingsModel>;
package/lib/tokens.js CHANGED
@@ -1,13 +1,17 @@
1
1
  import { Token } from '@lumino/coreutils';
2
- export const PLUGIN_IDS = {
3
- chat: '@jupyterlite/ai:chat',
4
- chatCommandRegistry: '@jupyterlite/ai:autocompletion-registry',
5
- completer: '@jupyterlite/ai:completer',
6
- providerRegistry: '@jupyterlite/ai:provider-registry',
7
- settingsConnector: '@jupyterlite/ai:settings-connector',
8
- systemPrompts: '@jupyterlite/ai:system-prompts'
9
- };
10
- /**
11
- * The provider registry token.
12
- */
13
- export const IAIProviderRegistry = new Token('@jupyterlite/ai:provider-registry', 'Provider for chat and completion LLM provider');
2
+ /**
3
+ * The tool registry token.
4
+ */
5
+ export const IToolRegistry = new Token('@jupyterlite/ai:tool-registry', 'Tool registry for AI agent functionality');
6
+ /**
7
+ * Token for the chat provider registry.
8
+ */
9
+ export const IChatProviderRegistry = new Token('@jupyterlite/ai:chat-provider-registry', 'Registry for chat AI providers');
10
+ /**
11
+ * Token for the completion provider registry.
12
+ */
13
+ export const ICompletionProviderRegistry = new Token('@jupyterlite/ai:completion-provider-registry', 'Registry for completion providers');
14
+ /**
15
+ * Token for the AI settings model.
16
+ */
17
+ export const IAISettingsModel = new Token('@jupyterlite/ai:IAISettingsModel');
@@ -0,0 +1,11 @@
1
+ import { CommandRegistry } from '@lumino/commands';
2
+ import { ITool } from '../tokens';
3
+ import { AISettingsModel } from '../models/settings-model';
4
+ /**
5
+ * Create a tool to discover all available commands and their metadata
6
+ */
7
+ export declare function createDiscoverCommandsTool(commands: CommandRegistry): ITool;
8
+ /**
9
+ * Create a tool to execute a specific JupyterLab command
10
+ */
11
+ export declare function createExecuteCommandTool(commands: CommandRegistry, settingsModel: AISettingsModel): ITool;