@jupyterlite/ai 0.11.1 → 0.13.0
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.
- package/lib/agent.d.ts +61 -7
- package/lib/agent.js +286 -103
- package/lib/chat-commands/clear.d.ts +8 -0
- package/lib/chat-commands/clear.js +30 -0
- package/lib/chat-commands/index.d.ts +2 -0
- package/lib/chat-commands/index.js +2 -0
- package/lib/chat-commands/skills.d.ts +19 -0
- package/lib/chat-commands/skills.js +57 -0
- package/lib/{chat-model-registry.d.ts → chat-model-handler.d.ts} +12 -11
- package/lib/{chat-model-registry.js → chat-model-handler.js} +6 -40
- package/lib/chat-model.d.ts +16 -0
- package/lib/chat-model.js +191 -11
- package/lib/completion/completion-provider.d.ts +1 -1
- package/lib/completion/completion-provider.js +14 -2
- package/lib/components/model-select.js +4 -4
- package/lib/components/tool-select.d.ts +11 -2
- package/lib/components/tool-select.js +77 -18
- package/lib/index.d.ts +3 -3
- package/lib/index.js +311 -72
- package/lib/models/settings-model.d.ts +3 -0
- package/lib/models/settings-model.js +63 -14
- package/lib/providers/built-in-providers.js +12 -7
- package/lib/providers/provider-tools.d.ts +36 -0
- package/lib/providers/provider-tools.js +93 -0
- package/lib/rendered-message-outputarea.d.ts +24 -0
- package/lib/rendered-message-outputarea.js +48 -0
- package/lib/skills/index.d.ts +4 -0
- package/lib/skills/index.js +7 -0
- package/lib/skills/parse-skill.d.ts +25 -0
- package/lib/skills/parse-skill.js +69 -0
- package/lib/skills/skill-loader.d.ts +25 -0
- package/lib/skills/skill-loader.js +133 -0
- package/lib/skills/skill-registry.d.ts +31 -0
- package/lib/skills/skill-registry.js +100 -0
- package/lib/skills/types.d.ts +29 -0
- package/lib/skills/types.js +5 -0
- package/lib/tokens.d.ts +77 -7
- package/lib/tokens.js +6 -1
- package/lib/tools/commands.js +4 -2
- package/lib/tools/skills.d.ts +9 -0
- package/lib/tools/skills.js +73 -0
- package/lib/tools/web.d.ts +8 -0
- package/lib/tools/web.js +196 -0
- package/lib/widgets/ai-settings.d.ts +1 -1
- package/lib/widgets/ai-settings.js +157 -38
- package/lib/widgets/main-area-chat.d.ts +6 -0
- package/lib/widgets/main-area-chat.js +28 -0
- package/lib/widgets/provider-config-dialog.js +207 -4
- package/package.json +18 -11
- package/schema/settings-model.json +97 -2
- package/src/agent.ts +397 -123
- package/src/chat-commands/clear.ts +46 -0
- package/src/chat-commands/index.ts +2 -0
- package/src/chat-commands/skills.ts +87 -0
- package/src/{chat-model-registry.ts → chat-model-handler.ts} +16 -51
- package/src/chat-model.ts +270 -23
- package/src/completion/completion-provider.ts +26 -12
- package/src/components/model-select.tsx +4 -5
- package/src/components/tool-select.tsx +110 -7
- package/src/index.ts +395 -87
- package/src/models/settings-model.ts +70 -15
- package/src/providers/built-in-providers.ts +12 -7
- package/src/providers/provider-tools.ts +179 -0
- package/src/rendered-message-outputarea.ts +62 -0
- package/src/skills/index.ts +14 -0
- package/src/skills/parse-skill.ts +91 -0
- package/src/skills/skill-loader.ts +175 -0
- package/src/skills/skill-registry.ts +137 -0
- package/src/skills/types.ts +37 -0
- package/src/tokens.ts +109 -9
- package/src/tools/commands.ts +4 -2
- package/src/tools/skills.ts +84 -0
- package/src/tools/web.ts +238 -0
- package/src/widgets/ai-settings.tsx +357 -77
- package/src/widgets/main-area-chat.ts +34 -1
- package/src/widgets/provider-config-dialog.tsx +496 -3
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { ChatCommand, IChatCommandProvider, IInputModel } from '@jupyter/chat';
|
|
2
|
+
|
|
3
|
+
import { AIChatModel } from '../chat-model';
|
|
4
|
+
|
|
5
|
+
export class ClearCommandProvider implements IChatCommandProvider {
|
|
6
|
+
public id: string = '@jupyterlite/ai:clear-command';
|
|
7
|
+
|
|
8
|
+
async listCommandCompletions(
|
|
9
|
+
inputModel: IInputModel
|
|
10
|
+
): Promise<ChatCommand[]> {
|
|
11
|
+
const match = inputModel.currentWord?.match(this._regex)?.[0];
|
|
12
|
+
if (!match) {
|
|
13
|
+
return [];
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
if (this._command.name.startsWith(match)) {
|
|
17
|
+
return [this._command];
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return [];
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
async onSubmit(inputModel: IInputModel): Promise<void> {
|
|
24
|
+
const trimmed = inputModel.value.trim();
|
|
25
|
+
if (trimmed !== this._command.name) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const context = inputModel.chatContext as
|
|
30
|
+
| AIChatModel.IAIChatContext
|
|
31
|
+
| undefined;
|
|
32
|
+
context?.clearMessages?.();
|
|
33
|
+
|
|
34
|
+
inputModel.value = '';
|
|
35
|
+
inputModel.clearAttachments();
|
|
36
|
+
inputModel.clearMentions();
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
private _command: ChatCommand = {
|
|
40
|
+
name: '/clear',
|
|
41
|
+
providerId: this.id,
|
|
42
|
+
description: 'Clear the current chat history'
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
private _regex: RegExp = /^\/\w*$/;
|
|
46
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { ChatCommand, IChatCommandProvider, IInputModel } from '@jupyter/chat';
|
|
2
|
+
|
|
3
|
+
import { CommandRegistry } from '@lumino/commands';
|
|
4
|
+
|
|
5
|
+
import { AIChatModel } from '../chat-model';
|
|
6
|
+
import { CommandIds, ISkillRegistry } from '../tokens';
|
|
7
|
+
|
|
8
|
+
export class SkillsCommandProvider implements IChatCommandProvider {
|
|
9
|
+
constructor(options: SkillsCommandProvider.IOptions) {
|
|
10
|
+
this._skillRegistry = options.skillRegistry;
|
|
11
|
+
this._commands = options.commands;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
public id: string = '@jupyterlite/ai:skills-command';
|
|
15
|
+
|
|
16
|
+
async listCommandCompletions(
|
|
17
|
+
inputModel: IInputModel
|
|
18
|
+
): Promise<ChatCommand[]> {
|
|
19
|
+
const match = inputModel.currentWord?.match(this._regex)?.[0];
|
|
20
|
+
if (!match) {
|
|
21
|
+
return [];
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (this._command.name.startsWith(match)) {
|
|
25
|
+
return [this._command];
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return [];
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
async onSubmit(inputModel: IInputModel): Promise<void> {
|
|
32
|
+
const trimmed = inputModel.value.trim();
|
|
33
|
+
const match = trimmed.match(/^\/skills(?:\s+(.+))?$/);
|
|
34
|
+
if (!match) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Refresh skills from disk before listing
|
|
39
|
+
if (this._commands.hasCommand(CommandIds.refreshSkills)) {
|
|
40
|
+
await this._commands.execute(CommandIds.refreshSkills);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const query = match[1]?.trim();
|
|
44
|
+
const filtered = this._skillRegistry.listSkills(query);
|
|
45
|
+
|
|
46
|
+
let body = '';
|
|
47
|
+
if (filtered.length === 0) {
|
|
48
|
+
body = query
|
|
49
|
+
? `No skills found matching "${query}".`
|
|
50
|
+
: 'No skills are currently registered.';
|
|
51
|
+
} else {
|
|
52
|
+
const heading = query
|
|
53
|
+
? `Skills matching "${query}" (${filtered.length}):`
|
|
54
|
+
: `Available skills (${filtered.length}):`;
|
|
55
|
+
const lines = filtered.map(
|
|
56
|
+
skill => `- \`${skill.name}\` — ${skill.description}`
|
|
57
|
+
);
|
|
58
|
+
body = [heading, '', ...lines].join('\n');
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const context = inputModel.chatContext as
|
|
62
|
+
| AIChatModel.IAIChatContext
|
|
63
|
+
| undefined;
|
|
64
|
+
context?.addSystemMessage?.(body);
|
|
65
|
+
|
|
66
|
+
inputModel.value = '';
|
|
67
|
+
inputModel.clearAttachments();
|
|
68
|
+
inputModel.clearMentions();
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
private _command: ChatCommand = {
|
|
72
|
+
name: '/skills',
|
|
73
|
+
providerId: this.id,
|
|
74
|
+
description: 'List available skills'
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
private _regex: RegExp = /^\/\w*$/;
|
|
78
|
+
private _commands: CommandRegistry;
|
|
79
|
+
private _skillRegistry: ISkillRegistry;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export namespace SkillsCommandProvider {
|
|
83
|
+
export interface IOptions {
|
|
84
|
+
skillRegistry: ISkillRegistry;
|
|
85
|
+
commands: CommandRegistry;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
@@ -4,31 +4,32 @@ import { AgentManagerFactory } from './agent';
|
|
|
4
4
|
import { AIChatModel } from './chat-model';
|
|
5
5
|
import { AISettingsModel } from './models/settings-model';
|
|
6
6
|
import {
|
|
7
|
-
|
|
7
|
+
IChatModelHandler,
|
|
8
8
|
IProviderRegistry,
|
|
9
9
|
ITokenUsage,
|
|
10
10
|
IToolRegistry
|
|
11
11
|
} from './tokens';
|
|
12
12
|
import { IDocumentManager } from '@jupyterlab/docmanager';
|
|
13
|
-
import {
|
|
13
|
+
import { IRenderMimeRegistry } from '@jupyterlab/rendermime';
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
|
-
* The chat model
|
|
16
|
+
* The chat model handler.
|
|
17
17
|
*/
|
|
18
|
-
export class
|
|
19
|
-
constructor(options:
|
|
18
|
+
export class ChatModelHandler implements IChatModelHandler {
|
|
19
|
+
constructor(options: ChatModelHandler.IOptions) {
|
|
20
20
|
this._docManager = options.docManager;
|
|
21
21
|
this._agentManagerFactory = options.agentManagerFactory;
|
|
22
22
|
this._settingsModel = options.settingsModel;
|
|
23
23
|
this._toolRegistry = options.toolRegistry;
|
|
24
24
|
this._providerRegistry = options.providerRegistry;
|
|
25
|
+
this._rmRegistry = options.rmRegistry;
|
|
25
26
|
this._activeCellManager = options.activeCellManager;
|
|
26
27
|
this._trans = options.trans;
|
|
27
28
|
}
|
|
28
29
|
|
|
29
30
|
createModel(
|
|
30
|
-
name
|
|
31
|
-
activeProvider
|
|
31
|
+
name: string,
|
|
32
|
+
activeProvider: string,
|
|
32
33
|
tokenUsage?: ITokenUsage
|
|
33
34
|
): AIChatModel {
|
|
34
35
|
// Create Agent Manager first so it can be shared
|
|
@@ -37,7 +38,8 @@ export class ChatModelRegistry implements IChatModelRegistry {
|
|
|
37
38
|
toolRegistry: this._toolRegistry,
|
|
38
39
|
providerRegistry: this._providerRegistry,
|
|
39
40
|
activeProvider,
|
|
40
|
-
tokenUsage
|
|
41
|
+
tokenUsage,
|
|
42
|
+
renderMimeRegistry: this._rmRegistry
|
|
41
43
|
});
|
|
42
44
|
|
|
43
45
|
// Create AI chat model
|
|
@@ -50,52 +52,11 @@ export class ChatModelRegistry implements IChatModelRegistry {
|
|
|
50
52
|
trans: this._trans
|
|
51
53
|
});
|
|
52
54
|
|
|
53
|
-
// Set the name of the chat if not provided.
|
|
54
|
-
// The name will be the name set by the user to the model if not already used by
|
|
55
|
-
// another chat.
|
|
56
|
-
if (!name || this._models.findIndex(m => m.name === name) !== -1) {
|
|
57
|
-
const existingName = this.getAll().map(model => model.name);
|
|
58
|
-
|
|
59
|
-
const modelName =
|
|
60
|
-
this._settingsModel.getProvider(agentManager.activeProvider)?.name ||
|
|
61
|
-
UUID.uuid4();
|
|
62
|
-
name = modelName;
|
|
63
|
-
let i = 1;
|
|
64
|
-
while (existingName.includes(name)) {
|
|
65
|
-
name = `${modelName}-${i}`;
|
|
66
|
-
i += 1;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
55
|
model.name = name;
|
|
70
|
-
this.add(model);
|
|
71
56
|
|
|
72
57
|
return model;
|
|
73
58
|
}
|
|
74
59
|
|
|
75
|
-
add(model: AIChatModel): void {
|
|
76
|
-
if (!this._models.find(m => m.name === model.name)) {
|
|
77
|
-
this._models.push(model);
|
|
78
|
-
model.disposed.connect(() => {
|
|
79
|
-
this.remove(model.name);
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
get(name: string): AIChatModel | undefined {
|
|
85
|
-
return this._models.find(m => m.name === name);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
getAll(): AIChatModel[] {
|
|
89
|
-
return this._models;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
remove(name: string): void {
|
|
93
|
-
const index = this._models.findIndex(m => m.name === name);
|
|
94
|
-
if (index !== -1) {
|
|
95
|
-
this._models.splice(index, 1);
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
|
|
99
60
|
/**
|
|
100
61
|
* Getter/setter for the active cell manager.
|
|
101
62
|
*/
|
|
@@ -106,17 +67,17 @@ export class ChatModelRegistry implements IChatModelRegistry {
|
|
|
106
67
|
this._activeCellManager = manager;
|
|
107
68
|
}
|
|
108
69
|
|
|
109
|
-
private _models: AIChatModel[] = [];
|
|
110
70
|
private _docManager: IDocumentManager;
|
|
111
71
|
private _agentManagerFactory: AgentManagerFactory;
|
|
112
72
|
private _settingsModel: AISettingsModel;
|
|
113
73
|
private _toolRegistry?: IToolRegistry;
|
|
114
74
|
private _providerRegistry?: IProviderRegistry;
|
|
75
|
+
private _rmRegistry: IRenderMimeRegistry;
|
|
115
76
|
private _activeCellManager?: ActiveCellManager;
|
|
116
77
|
private _trans: TranslationBundle;
|
|
117
78
|
}
|
|
118
79
|
|
|
119
|
-
export namespace
|
|
80
|
+
export namespace ChatModelHandler {
|
|
120
81
|
export interface IOptions {
|
|
121
82
|
/**
|
|
122
83
|
* The document manager.
|
|
@@ -138,6 +99,10 @@ export namespace ChatModelRegistry {
|
|
|
138
99
|
* Optional provider registry for model creation
|
|
139
100
|
*/
|
|
140
101
|
providerRegistry?: IProviderRegistry;
|
|
102
|
+
/**
|
|
103
|
+
* Render mime registry.
|
|
104
|
+
*/
|
|
105
|
+
rmRegistry: IRenderMimeRegistry;
|
|
141
106
|
/**
|
|
142
107
|
* The active cell manager.
|
|
143
108
|
*/
|