@workbench-ai/workbench-protocol 0.0.43 → 0.0.45
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/dist/adapter-definition.d.ts +47 -0
- package/dist/adapter-definition.d.ts.map +1 -0
- package/dist/adapter-definition.js +241 -0
- package/dist/adapter-manifest.d.ts +24 -11
- package/dist/adapter-manifest.d.ts.map +1 -1
- package/dist/adapter-manifest.js +169 -50
- package/dist/adapter-protocol.d.ts +55 -44
- package/dist/adapter-protocol.d.ts.map +1 -1
- package/dist/adapter-protocol.js +171 -131
- package/dist/engine-resolve-result.d.ts +31 -0
- package/dist/engine-resolve-result.d.ts.map +1 -0
- package/dist/engine-resolve-result.js +162 -0
- package/dist/index.d.ts +4 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -2
- package/package.json +2 -2
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { Json } from "@workbench-ai/workbench-contract";
|
|
2
|
+
import type { WorkbenchAdapterAuthManifest, WorkbenchAdapterInvocationLike, WorkbenchAdapterManifest, WorkbenchAdapterOperation, WorkbenchAdapterSlotManifest } from "./adapter-manifest.ts";
|
|
3
|
+
import { type WorkbenchAdapterOperationRequest, type WorkbenchAdapterOperationResult, type WorkbenchAdapterOperationResultValue } from "./adapter-protocol.ts";
|
|
4
|
+
export interface WorkbenchAdapterDefinition<TContext = unknown> {
|
|
5
|
+
id: string;
|
|
6
|
+
setup?: string[];
|
|
7
|
+
auth?: WorkbenchAdapterAuthManifest;
|
|
8
|
+
engineResolve?: WorkbenchAdapterOperationDefinition<TContext>;
|
|
9
|
+
engineRun?: WorkbenchAdapterOperationDefinition<TContext>;
|
|
10
|
+
subject?: WorkbenchAdapterOperationDefinition<TContext>;
|
|
11
|
+
improve?: WorkbenchAdapterOperationDefinition<TContext>;
|
|
12
|
+
slots?: Record<string, WorkbenchAdapterSlotManifest>;
|
|
13
|
+
}
|
|
14
|
+
export interface WorkbenchAdapterOperationDefinition<TContext = unknown> {
|
|
15
|
+
command?: string;
|
|
16
|
+
handle?: WorkbenchAdapterOperationHandler<TContext>;
|
|
17
|
+
}
|
|
18
|
+
export interface WorkbenchAdapterHandlerContext<TContext = unknown> {
|
|
19
|
+
request: WorkbenchAdapterOperationRequest;
|
|
20
|
+
operation: WorkbenchAdapterOperation;
|
|
21
|
+
invocation: WorkbenchAdapterOperationRequest["invocation"];
|
|
22
|
+
with: Record<string, Json>;
|
|
23
|
+
paths: WorkbenchAdapterOperationRequest["paths"];
|
|
24
|
+
runtime: TContext;
|
|
25
|
+
slot(name: string): WorkbenchAdapterInvocationLike | null;
|
|
26
|
+
result<TValue extends WorkbenchAdapterOperationResultValue>(value: TValue, metadata?: Omit<WorkbenchAdapterOperationResult<TValue>, "protocol" | "operation" | "value">): WorkbenchAdapterOperationResult<TValue>;
|
|
27
|
+
}
|
|
28
|
+
export type WorkbenchAdapterOperationHandler<TContext = unknown> = (context: WorkbenchAdapterHandlerContext<TContext>) => WorkbenchAdapterHandlerReturn | Promise<WorkbenchAdapterHandlerReturn>;
|
|
29
|
+
export type WorkbenchAdapterHandlerReturn = WorkbenchAdapterOperationResult | WorkbenchAdapterOperationResultValue | undefined | void;
|
|
30
|
+
export interface RunDefinedWorkbenchAdapterOptions<TContext = unknown> {
|
|
31
|
+
requestPath?: string;
|
|
32
|
+
outputRoot?: string;
|
|
33
|
+
runtime?: TContext;
|
|
34
|
+
}
|
|
35
|
+
export declare function defineAdapter<TContext = unknown>(definition: WorkbenchAdapterDefinition<TContext>): WorkbenchAdapterDefinition<TContext>;
|
|
36
|
+
export declare function defineEngineResolver<TContext = unknown>(definition?: WorkbenchAdapterOperationDefinition<TContext>): WorkbenchAdapterOperationDefinition<TContext>;
|
|
37
|
+
export declare function defineSubject<TContext = unknown>(definition?: WorkbenchAdapterOperationDefinition<TContext>): WorkbenchAdapterOperationDefinition<TContext>;
|
|
38
|
+
export declare function defineEngineRunner<TContext = unknown>(definition?: WorkbenchAdapterOperationDefinition<TContext>): WorkbenchAdapterOperationDefinition<TContext>;
|
|
39
|
+
export declare function defineOptimizer<TContext = unknown>(definition?: WorkbenchAdapterOperationDefinition<TContext>): WorkbenchAdapterOperationDefinition<TContext>;
|
|
40
|
+
export declare function adapterSlot(path: string, operation: WorkbenchAdapterOperation): WorkbenchAdapterSlotManifest;
|
|
41
|
+
export declare function workbenchAdapterManifestFromDefinition(definition: WorkbenchAdapterDefinition): WorkbenchAdapterManifest;
|
|
42
|
+
export declare function runDefinedAdapter<TContext = unknown>(definition: WorkbenchAdapterDefinition<TContext>, options?: RunDefinedWorkbenchAdapterOptions<TContext>): Promise<WorkbenchAdapterOperationResult | null>;
|
|
43
|
+
export declare function runSubjectFromEngine<TContext = unknown>(context: WorkbenchAdapterHandlerContext<TContext>): Promise<WorkbenchAdapterOperationResult>;
|
|
44
|
+
export declare function operationDefinitionForRequest<TContext = unknown>(definition: WorkbenchAdapterDefinition<TContext>, operation: WorkbenchAdapterOperation): WorkbenchAdapterOperationDefinition<TContext> | undefined;
|
|
45
|
+
export declare function adapterResult<TValue extends WorkbenchAdapterOperationResultValue>(operation: WorkbenchAdapterOperation, value: TValue, metadata?: Omit<WorkbenchAdapterOperationResult<TValue>, "protocol" | "operation" | "value">): WorkbenchAdapterOperationResult<TValue>;
|
|
46
|
+
export declare function adapterSlotInvocation(request: WorkbenchAdapterOperationRequest, slots: Record<string, WorkbenchAdapterSlotManifest> | undefined, name: string): WorkbenchAdapterInvocationLike | null;
|
|
47
|
+
//# sourceMappingURL=adapter-definition.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter-definition.d.ts","sourceRoot":"","sources":["../src/adapter-definition.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EACV,IAAI,EACL,MAAM,kCAAkC,CAAC;AAE1C,OAAO,KAAK,EACV,4BAA4B,EAC5B,8BAA8B,EAC9B,wBAAwB,EACxB,yBAAyB,EAEzB,4BAA4B,EAC7B,MA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,SAAS,EAAE,yBAAyB,GACnC,4BAA4B,CAE9B;AAED,wBAAgB,sCAAsC,CACpD,UAAU,EAAE,0BAA0B,GACrC,wBAAwB,CAiB1B;AAED,wBAAsB,iBAAiB,CAAC,QAAQ,GAAG,OAAO,EACxD,UAAU,EAAE,0BAA0B,CAAC,QAAQ,CAAC,EAChD,OAAO,GAAE,iCAAiC,CAAC,QAAQ,CAAM,GACxD,OAAO,CAAC,+BAA+B,GAAG,IAAI,CAAC,CAkCjD;AAED,wBAAsB,oBAAoB,CAAC,QAAQ,GAAG,OAAO,EAC3D,OAAO,EAAE,8BAA8B,CAAC,QAAQ,CAAC,GAChD,OAAO,CAAC,+BAA+B,CAAC,CAuD1C;AAsBD,wBAAgB,6BAA6B,CAAC,QAAQ,GAAG,OAAO,EAC9D,UAAU,EAAE,0BAA0B,CAAC,QAAQ,CAAC,EAChD,SAAS,EAAE,yBAAyB,GACnC,mCAAmC,CAAC,QAAQ,CAAC,GAAG,SAAS,CAc3D;AAED,wBAAgB,aAAa,CAAC,MAAM,SAAS,oCAAoC,EAC/E,SAAS,EAAE,yBAAyB,EACpC,KAAK,EAAE,MAAM,EACb,QAAQ,GAAE,IAAI,CAAC,+BAA+B,CAAC,MAAM,CAAC,EAAE,UAAU,GAAG,WAAW,GAAG,OAAO,CAAM,GAC/F,+BAA+B,CAAC,MAAM,CAAC,CAQzC;AAED,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,gCAAgC,EACzC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,4BAA4B,CAAC,GAAG,SAAS,EAC/D,IAAI,EAAE,MAAM,GACX,8BAA8B,GAAG,IAAI,CAOvC"}
|
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
import { promises as fs } from "node:fs";
|
|
2
|
+
import { execFile } from "node:child_process";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { promisify } from "node:util";
|
|
5
|
+
import { WORKBENCH_ADAPTER_MANIFEST_PROTOCOL, adapterCommandName, normalizeWorkbenchAdapterOperation, } from "./adapter-manifest.js";
|
|
6
|
+
import { WORKBENCH_ADAPTER_RESULT_PROTOCOL, ensureWorkbenchAdapterOutputDir, assertWorkbenchAdapterOperationResultOk, readWorkbenchAdapterOperationRequest, readWorkbenchAdapterOperationResult, workbenchAdapterOperationResultPath, writeWorkbenchAdapterOperationResult, } from "./adapter-protocol.js";
|
|
7
|
+
const execFileAsync = promisify(execFile);
|
|
8
|
+
export function defineAdapter(definition) {
|
|
9
|
+
return definition;
|
|
10
|
+
}
|
|
11
|
+
export function defineEngineResolver(definition = {}) {
|
|
12
|
+
return definition;
|
|
13
|
+
}
|
|
14
|
+
export function defineSubject(definition = {}) {
|
|
15
|
+
return definition;
|
|
16
|
+
}
|
|
17
|
+
export function defineEngineRunner(definition = {}) {
|
|
18
|
+
return definition;
|
|
19
|
+
}
|
|
20
|
+
export function defineOptimizer(definition = {}) {
|
|
21
|
+
return definition;
|
|
22
|
+
}
|
|
23
|
+
export function adapterSlot(path, operation) {
|
|
24
|
+
return { path, operation: normalizeWorkbenchAdapterOperation(operation, "adapter slot operation") };
|
|
25
|
+
}
|
|
26
|
+
export function workbenchAdapterManifestFromDefinition(definition) {
|
|
27
|
+
const operations = {};
|
|
28
|
+
addOperation(operations, definition.id, "engine.resolve", definition.engineResolve);
|
|
29
|
+
addOperation(operations, definition.id, "engine.run", definition.engineRun);
|
|
30
|
+
addOperation(operations, definition.id, "subject.run", definition.subject);
|
|
31
|
+
addOperation(operations, definition.id, "optimizer.improve", definition.improve);
|
|
32
|
+
if (Object.keys(operations).length === 0) {
|
|
33
|
+
throw new Error(`Adapter ${definition.id} must define at least one operation.`);
|
|
34
|
+
}
|
|
35
|
+
return {
|
|
36
|
+
id: definition.id,
|
|
37
|
+
protocol: WORKBENCH_ADAPTER_MANIFEST_PROTOCOL,
|
|
38
|
+
operations,
|
|
39
|
+
setup: definition.setup ? [...definition.setup] : [],
|
|
40
|
+
...(definition.auth ? { auth: cloneJson(definition.auth) } : {}),
|
|
41
|
+
...(definition.slots ? { slots: cloneJson(definition.slots) } : {}),
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
export async function runDefinedAdapter(definition, options = {}) {
|
|
45
|
+
let request = await readWorkbenchAdapterOperationRequest(options.requestPath);
|
|
46
|
+
if (request.invocation.use !== definition.id) {
|
|
47
|
+
throw new Error(`Adapter ${definition.id} cannot execute request for ${request.invocation.use}.`);
|
|
48
|
+
}
|
|
49
|
+
if (options.outputRoot && options.outputRoot !== request.paths.output) {
|
|
50
|
+
request = {
|
|
51
|
+
...request,
|
|
52
|
+
paths: {
|
|
53
|
+
...request.paths,
|
|
54
|
+
output: options.outputRoot,
|
|
55
|
+
result: workbenchAdapterOperationResultPath(options.outputRoot),
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
await ensureWorkbenchAdapterOutputDir(request);
|
|
60
|
+
const operationDefinition = operationDefinitionForRequest(definition, request.operation);
|
|
61
|
+
if (!operationDefinition) {
|
|
62
|
+
throw new Error(`Adapter ${definition.id} does not implement ${request.operation}.`);
|
|
63
|
+
}
|
|
64
|
+
if (!operationDefinition.handle) {
|
|
65
|
+
throw new Error(`Adapter ${definition.id} ${request.operation} does not define a handler.`);
|
|
66
|
+
}
|
|
67
|
+
const handlerResult = await operationDefinition.handle(adapterHandlerContext({
|
|
68
|
+
definition,
|
|
69
|
+
request,
|
|
70
|
+
runtime: options.runtime,
|
|
71
|
+
}));
|
|
72
|
+
if (await fileExists(request.paths.result)) {
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
const result = normalizeHandlerResult(request.operation, handlerResult);
|
|
76
|
+
await writeWorkbenchAdapterOperationResult(request.paths.output, result);
|
|
77
|
+
return result;
|
|
78
|
+
}
|
|
79
|
+
export async function runSubjectFromEngine(context) {
|
|
80
|
+
if (context.operation !== "engine.run") {
|
|
81
|
+
throw new Error("runSubjectFromEngine can only be used while handling engine.run.");
|
|
82
|
+
}
|
|
83
|
+
const subject = context.request.context?.subject?.run;
|
|
84
|
+
if (!subject?.command) {
|
|
85
|
+
throw new Error("engine.run request context.subject.run.command is required to invoke the subject.");
|
|
86
|
+
}
|
|
87
|
+
const nestedRoot = path.join(context.paths.output, ".workbench", "internal", "subject-run", safeInternalPathSegment(context.request.id));
|
|
88
|
+
const nestedOutput = path.join(nestedRoot, "output");
|
|
89
|
+
const requestPath = path.join(nestedRoot, "request.json");
|
|
90
|
+
const resultPath = workbenchAdapterOperationResultPath(nestedOutput);
|
|
91
|
+
const subjectPaths = { ...context.paths };
|
|
92
|
+
delete subjectPaths.enginePrivate;
|
|
93
|
+
await fs.mkdir(nestedOutput, { recursive: true });
|
|
94
|
+
await fs.writeFile(requestPath, `${JSON.stringify({
|
|
95
|
+
...context.request,
|
|
96
|
+
id: `${context.request.id}:subject`,
|
|
97
|
+
operation: "subject.run",
|
|
98
|
+
invocation: {
|
|
99
|
+
use: subject.use,
|
|
100
|
+
with: subject.with ?? {},
|
|
101
|
+
...(subject.auth !== undefined ? { auth: subject.auth } : {}),
|
|
102
|
+
},
|
|
103
|
+
...(context.request.auth !== undefined
|
|
104
|
+
? { auth: adapterScopedAuth(context.request.auth, subject.use) }
|
|
105
|
+
: {}),
|
|
106
|
+
paths: {
|
|
107
|
+
...subjectPaths,
|
|
108
|
+
output: nestedOutput,
|
|
109
|
+
result: resultPath,
|
|
110
|
+
},
|
|
111
|
+
}, null, 2)}\n`);
|
|
112
|
+
await execFileAsync("sh", ["-c", subject.command], {
|
|
113
|
+
cwd: context.paths.cwd ?? context.paths.workspace,
|
|
114
|
+
env: {
|
|
115
|
+
...process.env,
|
|
116
|
+
WORKBENCH_ADAPTER_REQUEST: requestPath,
|
|
117
|
+
WORKBENCH_OUTPUT: nestedOutput,
|
|
118
|
+
WORKBENCH_RESULT: resultPath,
|
|
119
|
+
},
|
|
120
|
+
maxBuffer: 10 * 1024 * 1024,
|
|
121
|
+
});
|
|
122
|
+
const result = await readWorkbenchAdapterOperationResult(nestedOutput, "subject.run");
|
|
123
|
+
assertWorkbenchAdapterOperationResultOk(result, `Subject adapter ${subject.use} subject.run`);
|
|
124
|
+
return result;
|
|
125
|
+
}
|
|
126
|
+
function safeInternalPathSegment(value) {
|
|
127
|
+
const safe = value.replace(/[^a-z0-9._-]+/giu, "_").replace(/^_+|_+$/gu, "");
|
|
128
|
+
return safe || "subject";
|
|
129
|
+
}
|
|
130
|
+
function adapterScopedAuth(auth, adapterId) {
|
|
131
|
+
if (!auth || typeof auth !== "object" || Array.isArray(auth)) {
|
|
132
|
+
return auth;
|
|
133
|
+
}
|
|
134
|
+
const record = cloneJson(auth);
|
|
135
|
+
const adapters = record.adapters;
|
|
136
|
+
if (adapters && typeof adapters === "object" && !Array.isArray(adapters)) {
|
|
137
|
+
const scoped = adapters[adapterId];
|
|
138
|
+
if (scoped !== undefined) {
|
|
139
|
+
record.self = scoped;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
return record;
|
|
143
|
+
}
|
|
144
|
+
export function operationDefinitionForRequest(definition, operation) {
|
|
145
|
+
if (operation === "engine.resolve") {
|
|
146
|
+
return definition.engineResolve;
|
|
147
|
+
}
|
|
148
|
+
if (operation === "engine.run") {
|
|
149
|
+
return definition.engineRun;
|
|
150
|
+
}
|
|
151
|
+
if (operation === "subject.run") {
|
|
152
|
+
return definition.subject;
|
|
153
|
+
}
|
|
154
|
+
if (operation === "optimizer.improve") {
|
|
155
|
+
return definition.improve;
|
|
156
|
+
}
|
|
157
|
+
return undefined;
|
|
158
|
+
}
|
|
159
|
+
export function adapterResult(operation, value, metadata = {}) {
|
|
160
|
+
return {
|
|
161
|
+
protocol: WORKBENCH_ADAPTER_RESULT_PROTOCOL,
|
|
162
|
+
operation: normalizeWorkbenchAdapterOperation(operation, "adapter result operation"),
|
|
163
|
+
ok: true,
|
|
164
|
+
...metadata,
|
|
165
|
+
value,
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
export function adapterSlotInvocation(request, slots, name) {
|
|
169
|
+
const slot = slots?.[name];
|
|
170
|
+
if (!slot) {
|
|
171
|
+
return null;
|
|
172
|
+
}
|
|
173
|
+
const value = jsonPointerValue(adapterWithRecord(request), slot.path);
|
|
174
|
+
return isInvocationLike(value) ? value : null;
|
|
175
|
+
}
|
|
176
|
+
function addOperation(operations, adapterId, operation, definition) {
|
|
177
|
+
if (!definition) {
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
operations[operation] = {
|
|
181
|
+
command: definition.command ?? adapterCommandName(adapterId),
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
function cloneJson(value) {
|
|
185
|
+
return JSON.parse(JSON.stringify(value));
|
|
186
|
+
}
|
|
187
|
+
function adapterHandlerContext(args) {
|
|
188
|
+
return {
|
|
189
|
+
request: args.request,
|
|
190
|
+
operation: args.request.operation,
|
|
191
|
+
invocation: args.request.invocation,
|
|
192
|
+
with: adapterWithRecord(args.request),
|
|
193
|
+
paths: args.request.paths,
|
|
194
|
+
runtime: args.runtime,
|
|
195
|
+
slot: (name) => adapterSlotInvocation(args.request, args.definition.slots, name),
|
|
196
|
+
result: (value, metadata = {}) => adapterResult(args.request.operation, value, metadata),
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
function normalizeHandlerResult(operation, result) {
|
|
200
|
+
if (isOperationResult(result)) {
|
|
201
|
+
return result;
|
|
202
|
+
}
|
|
203
|
+
return adapterResult(operation, result === undefined ? null : result);
|
|
204
|
+
}
|
|
205
|
+
function isOperationResult(value) {
|
|
206
|
+
return !!value &&
|
|
207
|
+
typeof value === "object" &&
|
|
208
|
+
!Array.isArray(value) &&
|
|
209
|
+
value.protocol === WORKBENCH_ADAPTER_RESULT_PROTOCOL &&
|
|
210
|
+
typeof value.operation === "string";
|
|
211
|
+
}
|
|
212
|
+
function adapterWithRecord(request) {
|
|
213
|
+
const value = request.invocation.with;
|
|
214
|
+
return value && typeof value === "object" && !Array.isArray(value)
|
|
215
|
+
? value
|
|
216
|
+
: {};
|
|
217
|
+
}
|
|
218
|
+
function jsonPointerValue(root, pointer) {
|
|
219
|
+
if (pointer === "") {
|
|
220
|
+
return root;
|
|
221
|
+
}
|
|
222
|
+
let current = root;
|
|
223
|
+
for (const rawPart of pointer.slice(1).split("/")) {
|
|
224
|
+
const part = rawPart.replace(/~1/gu, "/").replace(/~0/gu, "~");
|
|
225
|
+
if (!current || typeof current !== "object") {
|
|
226
|
+
return undefined;
|
|
227
|
+
}
|
|
228
|
+
current = current[part];
|
|
229
|
+
}
|
|
230
|
+
return current;
|
|
231
|
+
}
|
|
232
|
+
function isInvocationLike(value) {
|
|
233
|
+
return !!value &&
|
|
234
|
+
typeof value === "object" &&
|
|
235
|
+
!Array.isArray(value) &&
|
|
236
|
+
typeof value.use === "string" &&
|
|
237
|
+
(value.use.length > 0);
|
|
238
|
+
}
|
|
239
|
+
async function fileExists(filePath) {
|
|
240
|
+
return fs.stat(filePath).then((stat) => stat.isFile(), () => false);
|
|
241
|
+
}
|
|
@@ -1,13 +1,21 @@
|
|
|
1
|
+
export declare const WORKBENCH_ADAPTER_MANIFEST_PROTOCOL = "workbench.adapter.v3";
|
|
1
2
|
export interface WorkbenchAdapterManifest {
|
|
2
3
|
id: string;
|
|
3
|
-
protocol:
|
|
4
|
-
|
|
4
|
+
protocol: typeof WORKBENCH_ADAPTER_MANIFEST_PROTOCOL;
|
|
5
|
+
operations: Partial<Record<WorkbenchAdapterOperation, WorkbenchAdapterOperationManifest>>;
|
|
5
6
|
setup: string[];
|
|
6
|
-
command: string;
|
|
7
7
|
auth?: WorkbenchAdapterAuthManifest;
|
|
8
|
-
|
|
8
|
+
slots?: Record<string, WorkbenchAdapterSlotManifest>;
|
|
9
|
+
}
|
|
10
|
+
export type WorkbenchPrimitiveAdapterOperation = "engine.resolve" | "engine.run" | "subject.run" | "optimizer.improve";
|
|
11
|
+
export type WorkbenchAdapterOperation = WorkbenchPrimitiveAdapterOperation;
|
|
12
|
+
export interface WorkbenchAdapterOperationManifest {
|
|
13
|
+
command: string;
|
|
14
|
+
}
|
|
15
|
+
export interface WorkbenchAdapterSlotManifest {
|
|
16
|
+
path: string;
|
|
17
|
+
operation: WorkbenchAdapterOperation;
|
|
9
18
|
}
|
|
10
|
-
export type WorkbenchAdapterCapability = "task-source" | "runner" | "scorer" | "optimizer";
|
|
11
19
|
export interface WorkbenchAdapterAuthManifest {
|
|
12
20
|
methods?: Record<string, WorkbenchAdapterAuthMethodManifest>;
|
|
13
21
|
slots?: Record<string, {
|
|
@@ -37,17 +45,22 @@ export interface WorkbenchAdapterAuthRequirement {
|
|
|
37
45
|
slot?: string;
|
|
38
46
|
profile: string;
|
|
39
47
|
}
|
|
48
|
+
export interface WorkbenchAdapterOperationRequirement {
|
|
49
|
+
invocation: WorkbenchAdapterInvocationLike;
|
|
50
|
+
operation: WorkbenchAdapterOperation;
|
|
51
|
+
}
|
|
40
52
|
export declare function adapterCommandName(adapterId: string): string;
|
|
53
|
+
export declare function workbenchAdapterManifestSupportsOperation(manifest: WorkbenchAdapterManifest, operation: WorkbenchAdapterOperation): boolean;
|
|
54
|
+
export declare function workbenchAdapterOperationCommand(manifest: WorkbenchAdapterManifest, operation: WorkbenchAdapterOperation): string;
|
|
41
55
|
export declare function cloneWorkbenchAdapterManifest(manifest: WorkbenchAdapterManifest): WorkbenchAdapterManifest;
|
|
42
56
|
export declare function parseWorkbenchAdapterManifest(source: string, label?: string): WorkbenchAdapterManifest;
|
|
43
57
|
export declare function workbenchAdapterManifestRequiresAuth(manifest: WorkbenchAdapterManifest): boolean;
|
|
44
58
|
export declare function collectWorkbenchAdapterInvocations(roots: readonly WorkbenchAdapterInvocationLike[], manifests: readonly WorkbenchAdapterManifest[] | Map<string, WorkbenchAdapterManifest>): WorkbenchAdapterInvocationLike[];
|
|
59
|
+
export declare function collectWorkbenchAdapterOperationRequirements(roots: readonly WorkbenchAdapterOperationRequirement[], manifests: readonly WorkbenchAdapterManifest[] | Map<string, WorkbenchAdapterManifest>): WorkbenchAdapterOperationRequirement[];
|
|
60
|
+
export declare function collectWorkbenchAdapterOperationIssues(roots: readonly WorkbenchAdapterOperationRequirement[], manifests: readonly WorkbenchAdapterManifest[] | Map<string, WorkbenchAdapterManifest>): string[];
|
|
61
|
+
export declare function assertWorkbenchAdapterOperationSupport(roots: readonly WorkbenchAdapterOperationRequirement[], manifests: readonly WorkbenchAdapterManifest[] | Map<string, WorkbenchAdapterManifest>): void;
|
|
45
62
|
export declare function collectWorkbenchAdapterAuthRequirements(roots: readonly WorkbenchAdapterInvocationLike[], manifests: readonly WorkbenchAdapterManifest[] | Map<string, WorkbenchAdapterManifest>): WorkbenchAdapterAuthRequirement[];
|
|
46
|
-
export declare function withDefaultWorkbenchAdapterAuthProfiles<T extends
|
|
47
|
-
improve?: WorkbenchAdapterInvocationLike;
|
|
48
|
-
run: WorkbenchAdapterInvocationLike;
|
|
49
|
-
score?: WorkbenchAdapterInvocationLike;
|
|
50
|
-
grade?: WorkbenchAdapterInvocationLike;
|
|
51
|
-
}>(spec: T, manifests: readonly WorkbenchAdapterManifest[] | Map<string, WorkbenchAdapterManifest>): T;
|
|
63
|
+
export declare function withDefaultWorkbenchAdapterAuthProfiles<T extends Record<string, unknown>>(spec: T, manifests: readonly WorkbenchAdapterManifest[] | Map<string, WorkbenchAdapterManifest>): T;
|
|
52
64
|
export declare function withDefaultWorkbenchAdapterAuth<T extends WorkbenchAdapterInvocationLike>(invocation: T, manifests: readonly WorkbenchAdapterManifest[] | Map<string, WorkbenchAdapterManifest>): T;
|
|
65
|
+
export declare function normalizeWorkbenchAdapterOperation(value: unknown, label: string): WorkbenchAdapterOperation;
|
|
53
66
|
//# sourceMappingURL=adapter-manifest.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adapter-manifest.d.ts","sourceRoot":"","sources":["../src/adapter-manifest.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,wBAAwB;IACvC,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,
|
|
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