@theia/ai-core 1.61.0-next.8 → 1.61.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/browser/ai-core-frontend-module.d.ts.map +1 -1
- package/lib/browser/ai-core-frontend-module.js +7 -0
- package/lib/browser/ai-core-frontend-module.js.map +1 -1
- package/lib/browser/ai-variable-uri-label-provider.d.ts +17 -0
- package/lib/browser/ai-variable-uri-label-provider.d.ts.map +1 -0
- package/lib/browser/ai-variable-uri-label-provider.js +85 -0
- package/lib/browser/ai-variable-uri-label-provider.js.map +1 -0
- package/lib/browser/file-variable-contribution.d.ts +9 -3
- package/lib/browser/file-variable-contribution.d.ts.map +1 -1
- package/lib/browser/file-variable-contribution.js +26 -8
- package/lib/browser/file-variable-contribution.js.map +1 -1
- package/lib/browser/frontend-prompt-customization-service.d.ts +22 -1
- package/lib/browser/frontend-prompt-customization-service.d.ts.map +1 -1
- package/lib/browser/frontend-prompt-customization-service.js +63 -25
- package/lib/browser/frontend-prompt-customization-service.js.map +1 -1
- package/lib/browser/frontend-variable-service.d.ts +28 -4
- package/lib/browser/frontend-variable-service.d.ts.map +1 -1
- package/lib/browser/frontend-variable-service.js +84 -1
- package/lib/browser/frontend-variable-service.js.map +1 -1
- package/lib/common/ai-variable-resource.d.ts +18 -0
- package/lib/common/ai-variable-resource.d.ts.map +1 -0
- package/lib/common/ai-variable-resource.js +103 -0
- package/lib/common/ai-variable-resource.js.map +1 -0
- package/lib/common/configurable-in-memory-resources.d.ts +45 -0
- package/lib/common/configurable-in-memory-resources.d.ts.map +1 -0
- package/lib/common/configurable-in-memory-resources.js +147 -0
- package/lib/common/configurable-in-memory-resources.js.map +1 -0
- package/lib/common/index.d.ts +2 -0
- package/lib/common/index.d.ts.map +1 -1
- package/lib/common/index.js +2 -0
- package/lib/common/index.js.map +1 -1
- package/lib/common/prompt-service.d.ts +16 -4
- package/lib/common/prompt-service.d.ts.map +1 -1
- package/lib/common/prompt-service.js +1 -1
- package/lib/common/prompt-service.js.map +1 -1
- package/lib/common/prompt-variable-contribution.d.ts +2 -1
- package/lib/common/prompt-variable-contribution.d.ts.map +1 -1
- package/lib/common/prompt-variable-contribution.js +10 -1
- package/lib/common/prompt-variable-contribution.js.map +1 -1
- package/lib/common/variable-service.d.ts +17 -2
- package/lib/common/variable-service.d.ts.map +1 -1
- package/lib/common/variable-service.js +43 -32
- package/lib/common/variable-service.js.map +1 -1
- package/package.json +11 -10
- package/src/browser/ai-core-frontend-module.ts +12 -5
- package/src/browser/ai-variable-uri-label-provider.ts +66 -0
- package/src/browser/file-variable-contribution.ts +34 -14
- package/src/browser/frontend-prompt-customization-service.ts +72 -25
- package/src/browser/frontend-variable-service.ts +115 -5
- package/src/common/ai-variable-resource.ts +86 -0
- package/src/common/configurable-in-memory-resources.ts +156 -0
- package/src/common/index.ts +2 -0
- package/src/common/prompt-service.ts +14 -4
- package/src/common/prompt-variable-contribution.ts +10 -2
- package/src/common/variable-service.ts +58 -44
|
@@ -120,6 +120,13 @@ export namespace AIVariableResolutionRequest {
|
|
|
120
120
|
'variable' in arg &&
|
|
121
121
|
typeof (arg as { variable: { name: unknown } }).variable.name === 'string';
|
|
122
122
|
}
|
|
123
|
+
|
|
124
|
+
export function fromResolved(arg: ResolvedAIContextVariable): AIVariableResolutionRequest {
|
|
125
|
+
return {
|
|
126
|
+
variable: arg.variable,
|
|
127
|
+
arg: arg.arg
|
|
128
|
+
};
|
|
129
|
+
}
|
|
123
130
|
}
|
|
124
131
|
|
|
125
132
|
export interface AIVariableContext {
|
|
@@ -136,6 +143,11 @@ export interface AIVariableResolver {
|
|
|
136
143
|
resolve(request: AIVariableResolutionRequest, context: AIVariableContext): Promise<ResolvedAIVariable | undefined>;
|
|
137
144
|
}
|
|
138
145
|
|
|
146
|
+
export interface AIVariableOpener {
|
|
147
|
+
canOpen(request: AIVariableResolutionRequest, context: AIVariableContext): MaybePromise<number>;
|
|
148
|
+
open(request: AIVariableResolutionRequest, context: AIVariableContext): Promise<void>;
|
|
149
|
+
}
|
|
150
|
+
|
|
139
151
|
export interface AIVariableResolverWithVariableDependencies extends AIVariableResolver {
|
|
140
152
|
resolve(request: AIVariableResolutionRequest, context: AIVariableContext): Promise<ResolvedAIVariable | undefined>;
|
|
141
153
|
/**
|
|
@@ -166,6 +178,7 @@ export interface AIVariableService {
|
|
|
166
178
|
registerResolver(variable: AIVariable, resolver: AIVariableResolver): Disposable;
|
|
167
179
|
unregisterResolver(variable: AIVariable, resolver: AIVariableResolver): void;
|
|
168
180
|
getResolver(name: string, arg: string | undefined, context: AIVariableContext): Promise<AIVariableResolver | undefined>;
|
|
181
|
+
resolveVariable(variable: AIVariableArg, context: AIVariableContext, cache?: Map<string, ResolveAIVariableCacheEntry>): Promise<ResolvedAIVariable | undefined>;
|
|
169
182
|
|
|
170
183
|
registerArgumentPicker(variable: AIVariable, argPicker: AIVariableArgPicker): Disposable;
|
|
171
184
|
unregisterArgumentPicker(variable: AIVariable, argPicker: AIVariableArgPicker): void;
|
|
@@ -174,8 +187,6 @@ export interface AIVariableService {
|
|
|
174
187
|
registerArgumentCompletionProvider(variable: AIVariable, argPicker: AIVariableArgCompletionProvider): Disposable;
|
|
175
188
|
unregisterArgumentCompletionProvider(variable: AIVariable, argPicker: AIVariableArgCompletionProvider): void;
|
|
176
189
|
getArgumentCompletionProvider(name: string): Promise<AIVariableArgCompletionProvider | undefined>;
|
|
177
|
-
|
|
178
|
-
resolveVariable(variable: AIVariableArg, context: AIVariableContext, cache?: Map<string, ResolveAIVariableCacheEntry>): Promise<ResolvedAIVariable | undefined>;
|
|
179
190
|
}
|
|
180
191
|
|
|
181
192
|
/** Contributions on the frontend can optionally implement `FrontendVariableContribution`. */
|
|
@@ -191,7 +202,7 @@ export interface ResolveAIVariableCacheEntry {
|
|
|
191
202
|
|
|
192
203
|
export type ResolveAIVariableCache = Map<string, ResolveAIVariableCacheEntry>;
|
|
193
204
|
/**
|
|
194
|
-
* Creates a new, empty cache for AI variable
|
|
205
|
+
* Creates a new, empty cache for AI variable resolution to hand into `AIVariableService.resolveVariable`.
|
|
195
206
|
*/
|
|
196
207
|
export function createAIResolveVariableCache(): Map<string, ResolveAIVariableCacheEntry> {
|
|
197
208
|
return new Map();
|
|
@@ -216,6 +227,7 @@ export class DefaultAIVariableService implements AIVariableService {
|
|
|
216
227
|
protected variables = new Map<string, AIVariable>();
|
|
217
228
|
protected resolvers = new Map<string, AIVariableResolver[]>();
|
|
218
229
|
protected argPickers = new Map<string, AIVariableArgPicker>();
|
|
230
|
+
protected openers = new Map<string, AIVariableOpener[]>();
|
|
219
231
|
protected argCompletionProviders = new Map<string, AIVariableArgCompletionProvider>();
|
|
220
232
|
|
|
221
233
|
protected readonly onDidChangeVariablesEmitter = new Emitter<void>();
|
|
@@ -225,8 +237,7 @@ export class DefaultAIVariableService implements AIVariableService {
|
|
|
225
237
|
@inject(ContributionProvider) @named(AIVariableContribution)
|
|
226
238
|
protected readonly contributionProvider: ContributionProvider<AIVariableContribution>,
|
|
227
239
|
@inject(ILogger) protected readonly logger: ILogger
|
|
228
|
-
) {
|
|
229
|
-
}
|
|
240
|
+
) { }
|
|
230
241
|
|
|
231
242
|
protected initContributions(): void {
|
|
232
243
|
this.contributionProvider.getContributions().forEach(contribution => contribution.registerVariables(this));
|
|
@@ -339,22 +350,27 @@ export class DefaultAIVariableService implements AIVariableService {
|
|
|
339
350
|
return this.argCompletionProviders.get(this.getKey(name)) ?? undefined;
|
|
340
351
|
}
|
|
341
352
|
|
|
342
|
-
|
|
343
|
-
request: AIVariableArg,
|
|
344
|
-
context: AIVariableContext,
|
|
345
|
-
cache: ResolveAIVariableCache = createAIResolveVariableCache()
|
|
346
|
-
): Promise<ResolvedAIVariable | undefined> {
|
|
347
|
-
// Calculate unique variable cache key from variable name and argument
|
|
353
|
+
protected parseRequest(request: AIVariableArg): { variableName: string, arg: string | undefined } {
|
|
348
354
|
const variableName = typeof request === 'string'
|
|
349
355
|
? request
|
|
350
356
|
: typeof request.variable === 'string'
|
|
351
357
|
? request.variable
|
|
352
358
|
: request.variable.name;
|
|
353
359
|
const arg = typeof request === 'string' ? undefined : request.arg;
|
|
360
|
+
return { variableName, arg };
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
async resolveVariable(
|
|
364
|
+
request: AIVariableArg,
|
|
365
|
+
context: AIVariableContext,
|
|
366
|
+
cache: ResolveAIVariableCache = createAIResolveVariableCache()
|
|
367
|
+
): Promise<ResolvedAIVariable | undefined> {
|
|
368
|
+
// Calculate unique variable cache key from variable name and argument
|
|
369
|
+
const { variableName, arg } = this.parseRequest(request);
|
|
354
370
|
const cacheKey = `${variableName}${PromptText.VARIABLE_SEPARATOR_CHAR}${arg ?? ''}`;
|
|
355
371
|
|
|
356
372
|
// If the current cache key exists and is still in progress, we reached a cycle.
|
|
357
|
-
// If we reach it but it has been resolved, it was part of another
|
|
373
|
+
// If we reach it but it has been resolved, it was part of another resolution branch and we can simply return it.
|
|
358
374
|
if (cache.has(cacheKey)) {
|
|
359
375
|
const existingEntry = cache.get(cacheKey)!;
|
|
360
376
|
if (existingEntry.inProgress) {
|
|
@@ -364,40 +380,38 @@ export class DefaultAIVariableService implements AIVariableService {
|
|
|
364
380
|
return existingEntry.promise;
|
|
365
381
|
}
|
|
366
382
|
|
|
367
|
-
const entry: ResolveAIVariableCacheEntry = { promise:
|
|
383
|
+
const entry: ResolveAIVariableCacheEntry = { promise: this.doResolve(variableName, arg, context, cache), inProgress: true };
|
|
384
|
+
entry.promise.finally(() => entry.inProgress = false);
|
|
368
385
|
cache.set(cacheKey, entry);
|
|
369
386
|
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
const promise = (async () => {
|
|
373
|
-
const variable = this.getVariable(variableName);
|
|
374
|
-
if (!variable) {
|
|
375
|
-
return undefined;
|
|
376
|
-
}
|
|
377
|
-
const resolver = await this.getResolver(variableName, arg, context);
|
|
378
|
-
let resolved: ResolvedAIVariable | undefined;
|
|
379
|
-
if (isResolverWithDependencies(resolver)) {
|
|
380
|
-
// Explicit cast needed because Typescript does not consider the method parameter length of the type guard at compile time
|
|
381
|
-
resolved = await (resolver as AIVariableResolverWithVariableDependencies).resolve(
|
|
382
|
-
{ variable, arg },
|
|
383
|
-
context,
|
|
384
|
-
async (depRequest: AIVariableResolutionRequest) =>
|
|
385
|
-
this.resolveVariable(depRequest, context, cache)
|
|
386
|
-
);
|
|
387
|
-
} else if (resolver) {
|
|
388
|
-
// Explicit cast needed because Typescript does not consider the method parameter length of the type guard at compile time
|
|
389
|
-
resolved = await (resolver as AIVariableResolver).resolve({ variable, arg }, context);
|
|
390
|
-
} else {
|
|
391
|
-
resolved = undefined;
|
|
392
|
-
}
|
|
393
|
-
return resolved ? { ...resolved, arg } : undefined;
|
|
394
|
-
})();
|
|
395
|
-
|
|
396
|
-
entry.promise = promise;
|
|
397
|
-
promise.finally(() => {
|
|
398
|
-
entry.inProgress = false;
|
|
399
|
-
});
|
|
387
|
+
return entry.promise;
|
|
388
|
+
}
|
|
400
389
|
|
|
401
|
-
|
|
390
|
+
/**
|
|
391
|
+
* Asynchronously resolves a variable, handling its dependencies while preventing cyclical resolution.
|
|
392
|
+
* Selects the appropriate resolver and resolution strategy based on whether nested dependency resolution is supported.
|
|
393
|
+
*/
|
|
394
|
+
protected async doResolve(variableName: string, arg: string | undefined, context: AIVariableContext, cache: ResolveAIVariableCache): Promise<ResolvedAIVariable | undefined> {
|
|
395
|
+
const variable = this.getVariable(variableName);
|
|
396
|
+
if (!variable) {
|
|
397
|
+
return undefined;
|
|
398
|
+
}
|
|
399
|
+
const resolver = await this.getResolver(variableName, arg, context);
|
|
400
|
+
let resolved: ResolvedAIVariable | undefined;
|
|
401
|
+
if (isResolverWithDependencies(resolver)) {
|
|
402
|
+
// Explicit cast needed because Typescript does not consider the method parameter length of the type guard at compile time
|
|
403
|
+
resolved = await (resolver as AIVariableResolverWithVariableDependencies).resolve(
|
|
404
|
+
{ variable, arg },
|
|
405
|
+
context,
|
|
406
|
+
async (depRequest: AIVariableResolutionRequest) =>
|
|
407
|
+
this.resolveVariable(depRequest, context, cache)
|
|
408
|
+
);
|
|
409
|
+
} else if (resolver) {
|
|
410
|
+
// Explicit cast needed because Typescript does not consider the method parameter length of the type guard at compile time
|
|
411
|
+
resolved = await (resolver as AIVariableResolver).resolve({ variable, arg }, context);
|
|
412
|
+
} else {
|
|
413
|
+
resolved = undefined;
|
|
414
|
+
}
|
|
415
|
+
return resolved ? { ...resolved, arg } : undefined;
|
|
402
416
|
}
|
|
403
417
|
}
|