@theia/ai-core 1.55.0-next.37 → 1.55.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.
Files changed (38) hide show
  1. package/lib/browser/ai-configuration/agent-configuration-widget.d.ts +1 -0
  2. package/lib/browser/ai-configuration/agent-configuration-widget.d.ts.map +1 -1
  3. package/lib/browser/ai-configuration/agent-configuration-widget.js +7 -1
  4. package/lib/browser/ai-configuration/agent-configuration-widget.js.map +1 -1
  5. package/lib/browser/ai-configuration/template-settings-renderer.js +1 -1
  6. package/lib/browser/ai-configuration/template-settings-renderer.js.map +1 -1
  7. package/lib/browser/ai-core-frontend-application-contribution.d.ts +3 -1
  8. package/lib/browser/ai-core-frontend-application-contribution.d.ts.map +1 -1
  9. package/lib/browser/ai-core-frontend-application-contribution.js +6 -6
  10. package/lib/browser/ai-core-frontend-application-contribution.js.map +1 -1
  11. package/lib/browser/frontend-prompt-customization-service.d.ts +6 -5
  12. package/lib/browser/frontend-prompt-customization-service.d.ts.map +1 -1
  13. package/lib/browser/frontend-prompt-customization-service.js +72 -35
  14. package/lib/browser/frontend-prompt-customization-service.js.map +1 -1
  15. package/lib/browser/prompttemplate-contribution.d.ts +1 -0
  16. package/lib/browser/prompttemplate-contribution.d.ts.map +1 -1
  17. package/lib/browser/prompttemplate-contribution.js +3 -2
  18. package/lib/browser/prompttemplate-contribution.js.map +1 -1
  19. package/lib/common/agent-service.d.ts +21 -3
  20. package/lib/common/agent-service.d.ts.map +1 -1
  21. package/lib/common/agent-service.js +17 -13
  22. package/lib/common/agent-service.js.map +1 -1
  23. package/lib/common/communication-recording-service.d.ts +1 -0
  24. package/lib/common/communication-recording-service.d.ts.map +1 -1
  25. package/lib/common/prompt-service.d.ts +33 -3
  26. package/lib/common/prompt-service.d.ts.map +1 -1
  27. package/lib/common/prompt-service.js +23 -1
  28. package/lib/common/prompt-service.js.map +1 -1
  29. package/package.json +12 -10
  30. package/src/browser/ai-configuration/agent-configuration-widget.tsx +8 -0
  31. package/src/browser/ai-configuration/template-settings-renderer.tsx +1 -1
  32. package/src/browser/ai-core-frontend-application-contribution.ts +7 -8
  33. package/src/browser/frontend-prompt-customization-service.ts +73 -35
  34. package/src/browser/prompttemplate-contribution.ts +3 -1
  35. package/src/browser/style/index.css +5 -0
  36. package/src/common/agent-service.ts +42 -13
  37. package/src/common/communication-recording-service.ts +2 -0
  38. package/src/common/prompt-service.ts +51 -3
@@ -13,10 +13,11 @@
13
13
  //
14
14
  // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
15
  // *****************************************************************************
16
- import { inject, injectable, named, optional, postConstruct } from '@theia/core/shared/inversify';
17
- import { ContributionProvider } from '@theia/core';
16
+ import { inject, injectable, optional, postConstruct } from '@theia/core/shared/inversify';
17
+ import { Emitter, Event } from '@theia/core';
18
18
  import { Agent } from './agent';
19
19
  import { AISettingsService } from './settings-service';
20
+ import { PromptService } from './prompt-service';
20
21
 
21
22
  export const AgentService = Symbol('AgentService');
22
23
 
@@ -48,21 +49,42 @@ export interface AgentService {
48
49
  * @return true if the agent is enabled, false otherwise.
49
50
  */
50
51
  isEnabled(agentId: string): boolean;
52
+
53
+ /**
54
+ * Allows to register an agent programmatically.
55
+ * @param agent the agent to register
56
+ */
57
+ registerAgent(agent: Agent): void;
58
+
59
+ /**
60
+ * Allows to unregister an agent programmatically.
61
+ * @param agentId the agent id to unregister
62
+ */
63
+ unregisterAgent(agentId: string): void;
64
+
65
+ /**
66
+ * Emitted when the list of agents changes.
67
+ * This can be used to update the UI when agents are added or removed.
68
+ */
69
+ onDidChangeAgents: Event<void>;
51
70
  }
52
71
 
53
72
  @injectable()
54
73
  export class AgentServiceImpl implements AgentService {
55
74
 
56
- @inject(ContributionProvider) @named(Agent)
57
- protected readonly agentsProvider: ContributionProvider<Agent>;
58
-
59
75
  @inject(AISettingsService) @optional()
60
76
  protected readonly aiSettingsService: AISettingsService | undefined;
61
77
 
78
+ @inject(PromptService)
79
+ protected readonly promptService: PromptService;
80
+
62
81
  protected disabledAgents = new Set<string>();
63
82
 
64
83
  protected _agents: Agent[] = [];
65
84
 
85
+ private readonly onDidChangeAgentsEmitter = new Emitter<void>();
86
+ readonly onDidChangeAgents = this.onDidChangeAgentsEmitter.event;
87
+
66
88
  @postConstruct()
67
89
  protected init(): void {
68
90
  this.aiSettingsService?.getSettings().then(settings => {
@@ -74,22 +96,29 @@ export class AgentServiceImpl implements AgentService {
74
96
  });
75
97
  }
76
98
 
77
- private get agents(): Agent[] {
78
- // We can't collect the contributions at @postConstruct because this will lead to a circular dependency
79
- // with agents reusing the chat agent service (e.g. orchestrator) which in turn injects the agent service
80
- return [...this.agentsProvider.getContributions(), ...this._agents];
81
- }
82
-
83
99
  registerAgent(agent: Agent): void {
84
100
  this._agents.push(agent);
101
+ agent.promptTemplates.forEach(
102
+ template => this.promptService.storePrompt(template.id, template.template)
103
+ );
104
+ this.onDidChangeAgentsEmitter.fire();
105
+ }
106
+
107
+ unregisterAgent(agentId: string): void {
108
+ const agent = this._agents.find(a => a.id === agentId);
109
+ this._agents = this._agents.filter(a => a.id !== agentId);
110
+ this.onDidChangeAgentsEmitter.fire();
111
+ agent?.promptTemplates.forEach(
112
+ template => this.promptService.removePrompt(template.id)
113
+ );
85
114
  }
86
115
 
87
116
  getAgents(): Agent[] {
88
- return this.agents.filter(agent => this.isEnabled(agent.id));
117
+ return this._agents.filter(agent => this.isEnabled(agent.id));
89
118
  }
90
119
 
91
120
  getAllAgents(): Agent[] {
92
- return this.agents;
121
+ return this._agents;
93
122
  }
94
123
 
95
124
  enableAgent(agentId: string): void {
@@ -42,6 +42,8 @@ export interface CommunicationRecordingService {
42
42
 
43
43
  getHistory(agentId: string): CommunicationHistory;
44
44
 
45
+ getSessionHistory(sessionId: string): CommunicationHistory;
46
+
45
47
  clearHistory(): void;
46
48
  readonly onStructuralChange: Event<void>;
47
49
  }
@@ -58,17 +58,46 @@ export interface PromptService {
58
58
  */
59
59
  getPrompt(id: string, args?: { [key: string]: unknown }): Promise<ResolvedPromptTemplate | undefined>;
60
60
  /**
61
- * Manually add a prompt to the list of prompts.
61
+ * Adds a prompt to the list of prompts.
62
62
  * @param id the id of the prompt
63
63
  * @param prompt the prompt template to store
64
64
  */
65
65
  storePrompt(id: string, prompt: string): void;
66
+ /**
67
+ * Removes a prompt from the list of prompts.
68
+ * @param id the id of the prompt
69
+ */
70
+ removePrompt(id: string): void;
66
71
  /**
67
72
  * Return all known prompts as a {@link PromptMap map}.
68
73
  */
69
74
  getAllPrompts(): PromptMap;
70
75
  }
71
76
 
77
+ export interface CustomAgentDescription {
78
+ id: string;
79
+ name: string;
80
+ description: string;
81
+ prompt: string;
82
+ defaultLLM: string;
83
+ }
84
+ export namespace CustomAgentDescription {
85
+ export function is(entry: unknown): entry is CustomAgentDescription {
86
+ // eslint-disable-next-line no-null/no-null
87
+ return typeof entry === 'object' && entry !== null
88
+ && 'id' in entry && typeof entry.id === 'string'
89
+ && 'name' in entry && typeof entry.name === 'string'
90
+ && 'description' in entry && typeof entry.description === 'string'
91
+ && 'prompt' in entry
92
+ && typeof entry.prompt === 'string'
93
+ && 'defaultLLM' in entry
94
+ && typeof entry.defaultLLM === 'string';
95
+ }
96
+ export function equals(a: CustomAgentDescription, b: CustomAgentDescription): boolean {
97
+ return a.id === b.id && a.name === b.name && a.description === b.description && a.prompt === b.prompt && a.defaultLLM === b.defaultLLM;
98
+ }
99
+ }
100
+
72
101
  export const PromptCustomizationService = Symbol('PromptCustomizationService');
73
102
  export interface PromptCustomizationService {
74
103
  /**
@@ -89,9 +118,9 @@ export interface PromptCustomizationService {
89
118
  * on the implementation. Implementation may for example decide to
90
119
  * open an editor, or request more information from the user, ...
91
120
  * @param id the template id.
92
- * @param content optional content to customize the template.
121
+ * @param content optional default content to initialize the template
93
122
  */
94
- editTemplate(id: string, content?: string): void;
123
+ editTemplate(id: string, defaultContent?: string): void;
95
124
 
96
125
  /**
97
126
  * Reset the template to its default value.
@@ -109,6 +138,22 @@ export interface PromptCustomizationService {
109
138
  * Event which is fired when the prompt template is changed.
110
139
  */
111
140
  readonly onDidChangePrompt: Event<string>;
141
+
142
+ /**
143
+ * Return all custom agents.
144
+ * @returns all custom agents
145
+ */
146
+ getCustomAgents(): Promise<CustomAgentDescription[]>;
147
+
148
+ /**
149
+ * Event which is fired when custom agents are modified.
150
+ */
151
+ readonly onDidChangeCustomAgents: Event<void>;
152
+
153
+ /**
154
+ * Open the custom agent yaml file.
155
+ */
156
+ openCustomAgentYaml(): void;
112
157
  }
113
158
 
114
159
  @injectable()
@@ -210,4 +255,7 @@ export class PromptServiceImpl implements PromptService {
210
255
  storePrompt(id: string, prompt: string): void {
211
256
  this._prompts[id] = { id, template: prompt };
212
257
  }
258
+ removePrompt(id: string): void {
259
+ delete this._prompts[id];
260
+ }
213
261
  }