@wingman-ai/gateway 0.4.2 → 0.4.4
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/README.md +14 -0
- package/dist/agent/config/mcpClientManager.cjs +104 -1
- package/dist/agent/config/mcpClientManager.d.ts +30 -0
- package/dist/agent/config/mcpClientManager.js +104 -1
- package/dist/agent/config/modelFactory.cjs +10 -0
- package/dist/agent/config/modelFactory.js +10 -0
- package/dist/agent/config/xaiImageModel.cjs +242 -0
- package/dist/agent/config/xaiImageModel.d.ts +33 -0
- package/dist/agent/config/xaiImageModel.js +202 -0
- package/dist/agent/tests/mcpClientManager.test.cjs +116 -0
- package/dist/agent/tests/mcpClientManager.test.js +117 -1
- package/dist/agent/tests/mcpResourceTools.test.cjs +101 -0
- package/dist/agent/tests/mcpResourceTools.test.d.ts +1 -0
- package/dist/agent/tests/mcpResourceTools.test.js +95 -0
- package/dist/agent/tests/modelFactory.test.cjs +16 -2
- package/dist/agent/tests/modelFactory.test.js +16 -2
- package/dist/agent/tests/xaiImageModel.test.cjs +194 -0
- package/dist/agent/tests/xaiImageModel.test.d.ts +1 -0
- package/dist/agent/tests/xaiImageModel.test.js +188 -0
- package/dist/agent/tools/mcp_resources.cjs +111 -0
- package/dist/agent/tools/mcp_resources.d.ts +3 -0
- package/dist/agent/tools/mcp_resources.js +77 -0
- package/dist/bench/adapters/commandAdapter.cjs +93 -0
- package/dist/bench/adapters/commandAdapter.d.ts +6 -0
- package/dist/bench/adapters/commandAdapter.js +59 -0
- package/dist/bench/adapters/helpers.cjs +170 -0
- package/dist/bench/adapters/helpers.d.ts +7 -0
- package/dist/bench/adapters/helpers.js +133 -0
- package/dist/bench/adapters/index.cjs +41 -0
- package/dist/bench/adapters/index.d.ts +2 -0
- package/dist/bench/adapters/index.js +7 -0
- package/dist/bench/adapters/wingmanCliAdapter.cjs +100 -0
- package/dist/bench/adapters/wingmanCliAdapter.d.ts +6 -0
- package/dist/bench/adapters/wingmanCliAdapter.js +66 -0
- package/dist/bench/cleanup.cjs +122 -0
- package/dist/bench/cleanup.d.ts +9 -0
- package/dist/bench/cleanup.js +85 -0
- package/dist/bench/config.cjs +190 -0
- package/dist/bench/config.d.ts +2 -0
- package/dist/bench/config.js +156 -0
- package/dist/bench/index.cjs +43 -0
- package/dist/bench/index.d.ts +3 -0
- package/dist/bench/index.js +3 -0
- package/dist/bench/official.cjs +616 -0
- package/dist/bench/official.d.ts +80 -0
- package/dist/bench/official.js +546 -0
- package/dist/bench/officialCli.cjs +204 -0
- package/dist/bench/officialCli.d.ts +5 -0
- package/dist/bench/officialCli.js +170 -0
- package/dist/bench/process.cjs +78 -0
- package/dist/bench/process.d.ts +14 -0
- package/dist/bench/process.js +44 -0
- package/dist/bench/runner.cjs +237 -0
- package/dist/bench/runner.d.ts +7 -0
- package/dist/bench/runner.js +197 -0
- package/dist/bench/scoring.cjs +171 -0
- package/dist/bench/scoring.d.ts +9 -0
- package/dist/bench/scoring.js +137 -0
- package/dist/bench/types.cjs +18 -0
- package/dist/bench/types.d.ts +200 -0
- package/dist/bench/types.js +0 -0
- package/dist/bench/validator.cjs +92 -0
- package/dist/bench/validator.d.ts +2 -0
- package/dist/bench/validator.js +58 -0
- package/dist/cli/config/schema.cjs +36 -1
- package/dist/cli/config/schema.d.ts +46 -0
- package/dist/cli/config/schema.js +36 -1
- package/dist/cli/config/warnings.cjs +119 -51
- package/dist/cli/config/warnings.js +119 -51
- package/dist/cli/core/agentInvoker.cjs +9 -2
- package/dist/cli/core/agentInvoker.d.ts +1 -0
- package/dist/cli/core/agentInvoker.js +9 -2
- package/dist/cli/core/imagePersistence.cjs +17 -1
- package/dist/cli/core/imagePersistence.d.ts +2 -0
- package/dist/cli/core/imagePersistence.js +13 -3
- package/dist/cli/core/sessionManager.cjs +2 -0
- package/dist/cli/core/sessionManager.js +3 -1
- package/dist/cli/types.d.ts +18 -0
- package/dist/gateway/adapters/teams.cjs +419 -0
- package/dist/gateway/adapters/teams.d.ts +47 -0
- package/dist/gateway/adapters/teams.js +361 -0
- package/dist/gateway/http/sms.cjs +286 -0
- package/dist/gateway/http/sms.d.ts +4 -0
- package/dist/gateway/http/sms.js +249 -0
- package/dist/gateway/server.cjs +54 -3
- package/dist/gateway/server.d.ts +2 -0
- package/dist/gateway/server.js +54 -3
- package/dist/gateway/sms/commands.cjs +116 -0
- package/dist/gateway/sms/commands.d.ts +15 -0
- package/dist/gateway/sms/commands.js +79 -0
- package/dist/gateway/sms/control.cjs +118 -0
- package/dist/gateway/sms/control.d.ts +18 -0
- package/dist/gateway/sms/control.js +84 -0
- package/dist/gateway/sms/policyStore.cjs +198 -0
- package/dist/gateway/sms/policyStore.d.ts +37 -0
- package/dist/gateway/sms/policyStore.js +161 -0
- package/dist/providers/registry.cjs +1 -0
- package/dist/providers/registry.js +1 -0
- package/dist/tests/cli-config-warnings.test.cjs +41 -0
- package/dist/tests/cli-config-warnings.test.js +41 -0
- package/dist/tests/cli-init.test.cjs +32 -26
- package/dist/tests/cli-init.test.js +32 -26
- package/dist/tests/gateway-http-security.test.cjs +21 -0
- package/dist/tests/gateway-http-security.test.js +21 -0
- package/dist/tests/gateway-origin-policy.test.cjs +22 -0
- package/dist/tests/gateway-origin-policy.test.js +22 -0
- package/dist/tests/gateway.test.cjs +57 -0
- package/dist/tests/gateway.test.js +57 -0
- package/dist/tests/imagePersistence.test.cjs +26 -0
- package/dist/tests/imagePersistence.test.js +27 -1
- package/dist/tests/run-terminal-bench-official-script.test.cjs +61 -0
- package/dist/tests/run-terminal-bench-official-script.test.d.ts +1 -0
- package/dist/tests/run-terminal-bench-official-script.test.js +55 -0
- package/dist/tests/sessions-api.test.cjs +69 -1
- package/dist/tests/sessions-api.test.js +70 -2
- package/dist/tests/sms-api.test.cjs +183 -0
- package/dist/tests/sms-api.test.d.ts +1 -0
- package/dist/tests/sms-api.test.js +177 -0
- package/dist/tests/sms-commands.test.cjs +90 -0
- package/dist/tests/sms-commands.test.d.ts +1 -0
- package/dist/tests/sms-commands.test.js +84 -0
- package/dist/tests/sms-policy-store.test.cjs +69 -0
- package/dist/tests/sms-policy-store.test.d.ts +1 -0
- package/dist/tests/sms-policy-store.test.js +63 -0
- package/dist/tests/teams-adapter.test.cjs +58 -0
- package/dist/tests/teams-adapter.test.d.ts +1 -0
- package/dist/tests/teams-adapter.test.js +52 -0
- package/dist/tests/terminal-bench-adapters-helpers.test.cjs +64 -0
- package/dist/tests/terminal-bench-adapters-helpers.test.d.ts +1 -0
- package/dist/tests/terminal-bench-adapters-helpers.test.js +58 -0
- package/dist/tests/terminal-bench-cleanup.test.cjs +93 -0
- package/dist/tests/terminal-bench-cleanup.test.d.ts +1 -0
- package/dist/tests/terminal-bench-cleanup.test.js +87 -0
- package/dist/tests/terminal-bench-config.test.cjs +62 -0
- package/dist/tests/terminal-bench-config.test.d.ts +1 -0
- package/dist/tests/terminal-bench-config.test.js +56 -0
- package/dist/tests/terminal-bench-official.test.cjs +194 -0
- package/dist/tests/terminal-bench-official.test.d.ts +1 -0
- package/dist/tests/terminal-bench-official.test.js +188 -0
- package/dist/tests/terminal-bench-runner.test.cjs +82 -0
- package/dist/tests/terminal-bench-runner.test.d.ts +1 -0
- package/dist/tests/terminal-bench-runner.test.js +76 -0
- package/dist/tests/terminal-bench-scoring.test.cjs +128 -0
- package/dist/tests/terminal-bench-scoring.test.d.ts +1 -0
- package/dist/tests/terminal-bench-scoring.test.js +122 -0
- package/dist/tools/mcp-fal-ai.cjs +1 -1
- package/dist/tools/mcp-fal-ai.js +1 -1
- package/dist/webui/assets/index-Cyg_Hs57.css +11 -0
- package/dist/webui/assets/{index-BMekSELC.js → index-DZXLLjaA.js} +109 -109
- package/dist/webui/index.html +2 -2
- package/package.json +11 -2
- package/templates/agents/game-dev/agent.md +110 -63
- package/templates/agents/game-dev/art-director.md +106 -0
- package/templates/agents/game-dev/game-designer.md +87 -0
- package/templates/agents/game-dev/scene-engineer.md +474 -0
- package/dist/webui/assets/index-Cwkg4DKj.css +0 -11
- package/templates/agents/game-dev/art-generation.md +0 -38
- package/templates/agents/game-dev/asset-refinement.md +0 -17
- package/templates/agents/game-dev/planning-idea.md +0 -17
- package/templates/agents/game-dev/ui-specialist.md +0 -17
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
5
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: definition[key]
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
})();
|
|
11
|
+
(()=>{
|
|
12
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
13
|
+
})();
|
|
14
|
+
(()=>{
|
|
15
|
+
__webpack_require__.r = (exports1)=>{
|
|
16
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
17
|
+
value: 'Module'
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
20
|
+
value: true
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
})();
|
|
24
|
+
var __webpack_exports__ = {};
|
|
25
|
+
__webpack_require__.r(__webpack_exports__);
|
|
26
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
27
|
+
CommandAdapter: ()=>CommandAdapter
|
|
28
|
+
});
|
|
29
|
+
const external_process_cjs_namespaceObject = require("../process.cjs");
|
|
30
|
+
function _define_property(obj, key, value) {
|
|
31
|
+
if (key in obj) Object.defineProperty(obj, key, {
|
|
32
|
+
value: value,
|
|
33
|
+
enumerable: true,
|
|
34
|
+
configurable: true,
|
|
35
|
+
writable: true
|
|
36
|
+
});
|
|
37
|
+
else obj[key] = value;
|
|
38
|
+
return obj;
|
|
39
|
+
}
|
|
40
|
+
function applyTemplate(input, context) {
|
|
41
|
+
return input.replaceAll("{{prompt}}", context.task.prompt).replaceAll("{{taskId}}", context.task.id).replaceAll("{{workingDirectory}}", context.workingDirectory);
|
|
42
|
+
}
|
|
43
|
+
function mapArgs(args, context) {
|
|
44
|
+
if (!args || 0 === args.length) return [];
|
|
45
|
+
return args.map((arg)=>applyTemplate(arg, context));
|
|
46
|
+
}
|
|
47
|
+
function mapEnv(env, context) {
|
|
48
|
+
const mapped = {
|
|
49
|
+
WINGMAN_BENCH_PROMPT: context.task.prompt,
|
|
50
|
+
WINGMAN_BENCH_TASK_ID: context.task.id,
|
|
51
|
+
WINGMAN_BENCH_WORKDIR: context.workingDirectory
|
|
52
|
+
};
|
|
53
|
+
for (const [key, value] of Object.entries(env || {}))mapped[key] = applyTemplate(value, context);
|
|
54
|
+
return mapped;
|
|
55
|
+
}
|
|
56
|
+
class CommandAdapter {
|
|
57
|
+
async invoke(context) {
|
|
58
|
+
const command = applyTemplate(this.config.command.command, context);
|
|
59
|
+
const args = mapArgs(this.config.command.args, context);
|
|
60
|
+
const env = mapEnv(this.config.command.env, context);
|
|
61
|
+
const execution = await (0, external_process_cjs_namespaceObject.runCommand)(command, args, {
|
|
62
|
+
cwd: context.workingDirectory,
|
|
63
|
+
timeoutMs: context.timeoutMs,
|
|
64
|
+
shell: this.config.command.shell,
|
|
65
|
+
env
|
|
66
|
+
});
|
|
67
|
+
return {
|
|
68
|
+
exitCode: execution.exitCode,
|
|
69
|
+
timedOut: execution.timedOut,
|
|
70
|
+
durationMs: execution.durationMs,
|
|
71
|
+
stdout: execution.stdout,
|
|
72
|
+
stderr: execution.stderr,
|
|
73
|
+
assistantText: execution.stdout.trim(),
|
|
74
|
+
errorMessage: 0 === execution.exitCode ? void 0 : execution.stderr.trim(),
|
|
75
|
+
tokens: {
|
|
76
|
+
inputTokens: 0,
|
|
77
|
+
outputTokens: 0,
|
|
78
|
+
totalTokens: 0
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
constructor(config){
|
|
83
|
+
_define_property(this, "config", void 0);
|
|
84
|
+
this.config = config;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
exports.CommandAdapter = __webpack_exports__.CommandAdapter;
|
|
88
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
89
|
+
"CommandAdapter"
|
|
90
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
91
|
+
Object.defineProperty(exports, '__esModule', {
|
|
92
|
+
value: true
|
|
93
|
+
});
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { AdapterInvocationResult, CommandAdapterConfig, TaskRunContext, TerminalBenchAdapter } from "../types.js";
|
|
2
|
+
export declare class CommandAdapter implements TerminalBenchAdapter {
|
|
3
|
+
private readonly config;
|
|
4
|
+
constructor(config: CommandAdapterConfig);
|
|
5
|
+
invoke(context: TaskRunContext): Promise<AdapterInvocationResult>;
|
|
6
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { runCommand } from "../process.js";
|
|
2
|
+
function _define_property(obj, key, value) {
|
|
3
|
+
if (key in obj) Object.defineProperty(obj, key, {
|
|
4
|
+
value: value,
|
|
5
|
+
enumerable: true,
|
|
6
|
+
configurable: true,
|
|
7
|
+
writable: true
|
|
8
|
+
});
|
|
9
|
+
else obj[key] = value;
|
|
10
|
+
return obj;
|
|
11
|
+
}
|
|
12
|
+
function applyTemplate(input, context) {
|
|
13
|
+
return input.replaceAll("{{prompt}}", context.task.prompt).replaceAll("{{taskId}}", context.task.id).replaceAll("{{workingDirectory}}", context.workingDirectory);
|
|
14
|
+
}
|
|
15
|
+
function mapArgs(args, context) {
|
|
16
|
+
if (!args || 0 === args.length) return [];
|
|
17
|
+
return args.map((arg)=>applyTemplate(arg, context));
|
|
18
|
+
}
|
|
19
|
+
function mapEnv(env, context) {
|
|
20
|
+
const mapped = {
|
|
21
|
+
WINGMAN_BENCH_PROMPT: context.task.prompt,
|
|
22
|
+
WINGMAN_BENCH_TASK_ID: context.task.id,
|
|
23
|
+
WINGMAN_BENCH_WORKDIR: context.workingDirectory
|
|
24
|
+
};
|
|
25
|
+
for (const [key, value] of Object.entries(env || {}))mapped[key] = applyTemplate(value, context);
|
|
26
|
+
return mapped;
|
|
27
|
+
}
|
|
28
|
+
class CommandAdapter {
|
|
29
|
+
async invoke(context) {
|
|
30
|
+
const command = applyTemplate(this.config.command.command, context);
|
|
31
|
+
const args = mapArgs(this.config.command.args, context);
|
|
32
|
+
const env = mapEnv(this.config.command.env, context);
|
|
33
|
+
const execution = await runCommand(command, args, {
|
|
34
|
+
cwd: context.workingDirectory,
|
|
35
|
+
timeoutMs: context.timeoutMs,
|
|
36
|
+
shell: this.config.command.shell,
|
|
37
|
+
env
|
|
38
|
+
});
|
|
39
|
+
return {
|
|
40
|
+
exitCode: execution.exitCode,
|
|
41
|
+
timedOut: execution.timedOut,
|
|
42
|
+
durationMs: execution.durationMs,
|
|
43
|
+
stdout: execution.stdout,
|
|
44
|
+
stderr: execution.stderr,
|
|
45
|
+
assistantText: execution.stdout.trim(),
|
|
46
|
+
errorMessage: 0 === execution.exitCode ? void 0 : execution.stderr.trim(),
|
|
47
|
+
tokens: {
|
|
48
|
+
inputTokens: 0,
|
|
49
|
+
outputTokens: 0,
|
|
50
|
+
totalTokens: 0
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
constructor(config){
|
|
55
|
+
_define_property(this, "config", void 0);
|
|
56
|
+
this.config = config;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
export { CommandAdapter };
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
5
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: definition[key]
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
})();
|
|
11
|
+
(()=>{
|
|
12
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
13
|
+
})();
|
|
14
|
+
(()=>{
|
|
15
|
+
__webpack_require__.r = (exports1)=>{
|
|
16
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
17
|
+
value: 'Module'
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
20
|
+
value: true
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
})();
|
|
24
|
+
var __webpack_exports__ = {};
|
|
25
|
+
__webpack_require__.r(__webpack_exports__);
|
|
26
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
27
|
+
detectAssistantFailureMessage: ()=>detectAssistantFailureMessage,
|
|
28
|
+
parseWingmanJsonOutput: ()=>parseWingmanJsonOutput
|
|
29
|
+
});
|
|
30
|
+
function asRecord(value) {
|
|
31
|
+
if (!value || "object" != typeof value || Array.isArray(value)) return null;
|
|
32
|
+
return value;
|
|
33
|
+
}
|
|
34
|
+
function getNumber(value) {
|
|
35
|
+
return "number" == typeof value && Number.isFinite(value) ? value : 0;
|
|
36
|
+
}
|
|
37
|
+
function extractTextFromContent(content) {
|
|
38
|
+
if ("string" == typeof content) return content;
|
|
39
|
+
if (!Array.isArray(content)) return "";
|
|
40
|
+
const parts = [];
|
|
41
|
+
for (const part of content){
|
|
42
|
+
if (!part || "object" != typeof part) continue;
|
|
43
|
+
const typedPart = part;
|
|
44
|
+
if ("string" == typeof typedPart.text) parts.push(typedPart.text);
|
|
45
|
+
}
|
|
46
|
+
return parts.join("");
|
|
47
|
+
}
|
|
48
|
+
function normalizeRoleLike(value) {
|
|
49
|
+
if ("string" != typeof value) return null;
|
|
50
|
+
const normalized = value.trim().toLowerCase();
|
|
51
|
+
return normalized.length > 0 ? normalized : null;
|
|
52
|
+
}
|
|
53
|
+
function isAssistantLikeMessage(message) {
|
|
54
|
+
const role = normalizeRoleLike(message.role);
|
|
55
|
+
if ("assistant" === role || "ai" === role) return true;
|
|
56
|
+
const type = normalizeRoleLike(message.type);
|
|
57
|
+
if ("assistant" === type || "ai" === type) return true;
|
|
58
|
+
const id = Array.isArray(message.id) ? message.id.filter((part)=>"string" == typeof part) : [];
|
|
59
|
+
return id.some((part)=>part.toLowerCase().includes("aimessage"));
|
|
60
|
+
}
|
|
61
|
+
function extractTextFromMessage(message) {
|
|
62
|
+
const direct = extractTextFromContent(message.content);
|
|
63
|
+
if (direct) return direct;
|
|
64
|
+
const kwargs = asRecord(message.kwargs);
|
|
65
|
+
if (kwargs) {
|
|
66
|
+
const kwargsContent = extractTextFromContent(kwargs.content);
|
|
67
|
+
if (kwargsContent) return kwargsContent;
|
|
68
|
+
if ("string" == typeof kwargs.text) return kwargs.text;
|
|
69
|
+
}
|
|
70
|
+
const data = asRecord(message.data);
|
|
71
|
+
if (data) {
|
|
72
|
+
const dataContent = extractTextFromContent(data.content);
|
|
73
|
+
if (dataContent) return dataContent;
|
|
74
|
+
if ("string" == typeof data.text) return data.text;
|
|
75
|
+
}
|
|
76
|
+
return "";
|
|
77
|
+
}
|
|
78
|
+
const ASSISTANT_FAILURE_PATTERNS = [
|
|
79
|
+
/^model call failed/i,
|
|
80
|
+
/\bbadrequesterror\b/i,
|
|
81
|
+
/\bstatus code\s*[45]\d{2}\b/i,
|
|
82
|
+
/\brate limit\b/i,
|
|
83
|
+
/\binsufficient[_\s-]?quota\b/i,
|
|
84
|
+
/\binvalid api key\b/i,
|
|
85
|
+
/\bauthentication\b/i
|
|
86
|
+
];
|
|
87
|
+
function detectAssistantFailureMessage(assistantText) {
|
|
88
|
+
const text = String(assistantText || "").trim();
|
|
89
|
+
if (!text) return;
|
|
90
|
+
for (const pattern of ASSISTANT_FAILURE_PATTERNS)if (pattern.test(text)) return text;
|
|
91
|
+
}
|
|
92
|
+
function collectTokenUsage(target, payload) {
|
|
93
|
+
const record = asRecord(payload);
|
|
94
|
+
if (!record) return;
|
|
95
|
+
const directInput = getNumber(record.input_tokens) || getNumber(record.inputTokens) || getNumber(record.prompt_tokens) || getNumber(record.promptTokens);
|
|
96
|
+
const directOutput = getNumber(record.output_tokens) || getNumber(record.outputTokens) || getNumber(record.completion_tokens) || getNumber(record.completionTokens);
|
|
97
|
+
const directTotal = getNumber(record.total_tokens) || getNumber(record.totalTokens);
|
|
98
|
+
if (directInput > 0) target.inputTokens = Math.max(target.inputTokens, directInput);
|
|
99
|
+
if (directOutput > 0) target.outputTokens = Math.max(target.outputTokens, directOutput);
|
|
100
|
+
if (directTotal > 0) target.totalTokens = Math.max(target.totalTokens, directTotal);
|
|
101
|
+
const nestedCandidates = [
|
|
102
|
+
record.usage,
|
|
103
|
+
record.usage_metadata,
|
|
104
|
+
record.tokenUsage,
|
|
105
|
+
record.response_metadata
|
|
106
|
+
];
|
|
107
|
+
for (const nested of nestedCandidates){
|
|
108
|
+
const nestedRecord = asRecord(nested);
|
|
109
|
+
if (nestedRecord) collectTokenUsage(target, nestedRecord);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
function parseWingmanJsonOutput(output) {
|
|
113
|
+
const lines = output.split(/\r?\n/).map((line)=>line.trim());
|
|
114
|
+
const assistantParts = [];
|
|
115
|
+
let errorMessage;
|
|
116
|
+
const tokenUsage = {
|
|
117
|
+
inputTokens: 0,
|
|
118
|
+
outputTokens: 0,
|
|
119
|
+
totalTokens: 0
|
|
120
|
+
};
|
|
121
|
+
for (const line of lines){
|
|
122
|
+
if (!line) continue;
|
|
123
|
+
let parsed;
|
|
124
|
+
try {
|
|
125
|
+
parsed = JSON.parse(line);
|
|
126
|
+
} catch {
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
129
|
+
const event = asRecord(parsed);
|
|
130
|
+
if (event && "string" == typeof event.type) {
|
|
131
|
+
if ("agent-error" === event.type && "string" == typeof event.error) errorMessage = event.error;
|
|
132
|
+
if ("agent-complete" === event.type) {
|
|
133
|
+
const result = asRecord(event.result);
|
|
134
|
+
const messages = Array.isArray(result?.messages) ? result?.messages : [];
|
|
135
|
+
for (const message of messages){
|
|
136
|
+
const messageRecord = asRecord(message);
|
|
137
|
+
if (!messageRecord || !isAssistantLikeMessage(messageRecord)) continue;
|
|
138
|
+
const text = extractTextFromMessage(messageRecord);
|
|
139
|
+
if (text) assistantParts.push(text);
|
|
140
|
+
}
|
|
141
|
+
collectTokenUsage(tokenUsage, result);
|
|
142
|
+
}
|
|
143
|
+
if ("agent-stream" === event.type) {
|
|
144
|
+
const chunk = asRecord(event.chunk);
|
|
145
|
+
if (!chunk) continue;
|
|
146
|
+
collectTokenUsage(tokenUsage, chunk);
|
|
147
|
+
const data = asRecord(chunk.data);
|
|
148
|
+
const streamChunk = asRecord(data?.chunk) || asRecord(data?.message);
|
|
149
|
+
if (!streamChunk) continue;
|
|
150
|
+
const text = "string" == typeof streamChunk.text ? streamChunk.text : extractTextFromContent(streamChunk.content);
|
|
151
|
+
if (text) assistantParts.push(text);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
if (0 === tokenUsage.totalTokens) tokenUsage.totalTokens = tokenUsage.inputTokens + tokenUsage.outputTokens;
|
|
156
|
+
return {
|
|
157
|
+
assistantText: assistantParts.join("").trim(),
|
|
158
|
+
tokenUsage,
|
|
159
|
+
errorMessage
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
exports.detectAssistantFailureMessage = __webpack_exports__.detectAssistantFailureMessage;
|
|
163
|
+
exports.parseWingmanJsonOutput = __webpack_exports__.parseWingmanJsonOutput;
|
|
164
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
165
|
+
"detectAssistantFailureMessage",
|
|
166
|
+
"parseWingmanJsonOutput"
|
|
167
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
168
|
+
Object.defineProperty(exports, '__esModule', {
|
|
169
|
+
value: true
|
|
170
|
+
});
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { AdapterTokenUsage } from "../types.js";
|
|
2
|
+
export declare function detectAssistantFailureMessage(assistantText: string | null | undefined): string | undefined;
|
|
3
|
+
export declare function parseWingmanJsonOutput(output: string): {
|
|
4
|
+
assistantText: string;
|
|
5
|
+
tokenUsage: AdapterTokenUsage;
|
|
6
|
+
errorMessage?: string;
|
|
7
|
+
};
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
function asRecord(value) {
|
|
2
|
+
if (!value || "object" != typeof value || Array.isArray(value)) return null;
|
|
3
|
+
return value;
|
|
4
|
+
}
|
|
5
|
+
function getNumber(value) {
|
|
6
|
+
return "number" == typeof value && Number.isFinite(value) ? value : 0;
|
|
7
|
+
}
|
|
8
|
+
function extractTextFromContent(content) {
|
|
9
|
+
if ("string" == typeof content) return content;
|
|
10
|
+
if (!Array.isArray(content)) return "";
|
|
11
|
+
const parts = [];
|
|
12
|
+
for (const part of content){
|
|
13
|
+
if (!part || "object" != typeof part) continue;
|
|
14
|
+
const typedPart = part;
|
|
15
|
+
if ("string" == typeof typedPart.text) parts.push(typedPart.text);
|
|
16
|
+
}
|
|
17
|
+
return parts.join("");
|
|
18
|
+
}
|
|
19
|
+
function normalizeRoleLike(value) {
|
|
20
|
+
if ("string" != typeof value) return null;
|
|
21
|
+
const normalized = value.trim().toLowerCase();
|
|
22
|
+
return normalized.length > 0 ? normalized : null;
|
|
23
|
+
}
|
|
24
|
+
function isAssistantLikeMessage(message) {
|
|
25
|
+
const role = normalizeRoleLike(message.role);
|
|
26
|
+
if ("assistant" === role || "ai" === role) return true;
|
|
27
|
+
const type = normalizeRoleLike(message.type);
|
|
28
|
+
if ("assistant" === type || "ai" === type) return true;
|
|
29
|
+
const id = Array.isArray(message.id) ? message.id.filter((part)=>"string" == typeof part) : [];
|
|
30
|
+
return id.some((part)=>part.toLowerCase().includes("aimessage"));
|
|
31
|
+
}
|
|
32
|
+
function extractTextFromMessage(message) {
|
|
33
|
+
const direct = extractTextFromContent(message.content);
|
|
34
|
+
if (direct) return direct;
|
|
35
|
+
const kwargs = asRecord(message.kwargs);
|
|
36
|
+
if (kwargs) {
|
|
37
|
+
const kwargsContent = extractTextFromContent(kwargs.content);
|
|
38
|
+
if (kwargsContent) return kwargsContent;
|
|
39
|
+
if ("string" == typeof kwargs.text) return kwargs.text;
|
|
40
|
+
}
|
|
41
|
+
const data = asRecord(message.data);
|
|
42
|
+
if (data) {
|
|
43
|
+
const dataContent = extractTextFromContent(data.content);
|
|
44
|
+
if (dataContent) return dataContent;
|
|
45
|
+
if ("string" == typeof data.text) return data.text;
|
|
46
|
+
}
|
|
47
|
+
return "";
|
|
48
|
+
}
|
|
49
|
+
const ASSISTANT_FAILURE_PATTERNS = [
|
|
50
|
+
/^model call failed/i,
|
|
51
|
+
/\bbadrequesterror\b/i,
|
|
52
|
+
/\bstatus code\s*[45]\d{2}\b/i,
|
|
53
|
+
/\brate limit\b/i,
|
|
54
|
+
/\binsufficient[_\s-]?quota\b/i,
|
|
55
|
+
/\binvalid api key\b/i,
|
|
56
|
+
/\bauthentication\b/i
|
|
57
|
+
];
|
|
58
|
+
function detectAssistantFailureMessage(assistantText) {
|
|
59
|
+
const text = String(assistantText || "").trim();
|
|
60
|
+
if (!text) return;
|
|
61
|
+
for (const pattern of ASSISTANT_FAILURE_PATTERNS)if (pattern.test(text)) return text;
|
|
62
|
+
}
|
|
63
|
+
function collectTokenUsage(target, payload) {
|
|
64
|
+
const record = asRecord(payload);
|
|
65
|
+
if (!record) return;
|
|
66
|
+
const directInput = getNumber(record.input_tokens) || getNumber(record.inputTokens) || getNumber(record.prompt_tokens) || getNumber(record.promptTokens);
|
|
67
|
+
const directOutput = getNumber(record.output_tokens) || getNumber(record.outputTokens) || getNumber(record.completion_tokens) || getNumber(record.completionTokens);
|
|
68
|
+
const directTotal = getNumber(record.total_tokens) || getNumber(record.totalTokens);
|
|
69
|
+
if (directInput > 0) target.inputTokens = Math.max(target.inputTokens, directInput);
|
|
70
|
+
if (directOutput > 0) target.outputTokens = Math.max(target.outputTokens, directOutput);
|
|
71
|
+
if (directTotal > 0) target.totalTokens = Math.max(target.totalTokens, directTotal);
|
|
72
|
+
const nestedCandidates = [
|
|
73
|
+
record.usage,
|
|
74
|
+
record.usage_metadata,
|
|
75
|
+
record.tokenUsage,
|
|
76
|
+
record.response_metadata
|
|
77
|
+
];
|
|
78
|
+
for (const nested of nestedCandidates){
|
|
79
|
+
const nestedRecord = asRecord(nested);
|
|
80
|
+
if (nestedRecord) collectTokenUsage(target, nestedRecord);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
function parseWingmanJsonOutput(output) {
|
|
84
|
+
const lines = output.split(/\r?\n/).map((line)=>line.trim());
|
|
85
|
+
const assistantParts = [];
|
|
86
|
+
let errorMessage;
|
|
87
|
+
const tokenUsage = {
|
|
88
|
+
inputTokens: 0,
|
|
89
|
+
outputTokens: 0,
|
|
90
|
+
totalTokens: 0
|
|
91
|
+
};
|
|
92
|
+
for (const line of lines){
|
|
93
|
+
if (!line) continue;
|
|
94
|
+
let parsed;
|
|
95
|
+
try {
|
|
96
|
+
parsed = JSON.parse(line);
|
|
97
|
+
} catch {
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
100
|
+
const event = asRecord(parsed);
|
|
101
|
+
if (event && "string" == typeof event.type) {
|
|
102
|
+
if ("agent-error" === event.type && "string" == typeof event.error) errorMessage = event.error;
|
|
103
|
+
if ("agent-complete" === event.type) {
|
|
104
|
+
const result = asRecord(event.result);
|
|
105
|
+
const messages = Array.isArray(result?.messages) ? result?.messages : [];
|
|
106
|
+
for (const message of messages){
|
|
107
|
+
const messageRecord = asRecord(message);
|
|
108
|
+
if (!messageRecord || !isAssistantLikeMessage(messageRecord)) continue;
|
|
109
|
+
const text = extractTextFromMessage(messageRecord);
|
|
110
|
+
if (text) assistantParts.push(text);
|
|
111
|
+
}
|
|
112
|
+
collectTokenUsage(tokenUsage, result);
|
|
113
|
+
}
|
|
114
|
+
if ("agent-stream" === event.type) {
|
|
115
|
+
const chunk = asRecord(event.chunk);
|
|
116
|
+
if (!chunk) continue;
|
|
117
|
+
collectTokenUsage(tokenUsage, chunk);
|
|
118
|
+
const data = asRecord(chunk.data);
|
|
119
|
+
const streamChunk = asRecord(data?.chunk) || asRecord(data?.message);
|
|
120
|
+
if (!streamChunk) continue;
|
|
121
|
+
const text = "string" == typeof streamChunk.text ? streamChunk.text : extractTextFromContent(streamChunk.content);
|
|
122
|
+
if (text) assistantParts.push(text);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
if (0 === tokenUsage.totalTokens) tokenUsage.totalTokens = tokenUsage.inputTokens + tokenUsage.outputTokens;
|
|
127
|
+
return {
|
|
128
|
+
assistantText: assistantParts.join("").trim(),
|
|
129
|
+
tokenUsage,
|
|
130
|
+
errorMessage
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
export { detectAssistantFailureMessage, parseWingmanJsonOutput };
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
5
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: definition[key]
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
})();
|
|
11
|
+
(()=>{
|
|
12
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
13
|
+
})();
|
|
14
|
+
(()=>{
|
|
15
|
+
__webpack_require__.r = (exports1)=>{
|
|
16
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
17
|
+
value: 'Module'
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
20
|
+
value: true
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
})();
|
|
24
|
+
var __webpack_exports__ = {};
|
|
25
|
+
__webpack_require__.r(__webpack_exports__);
|
|
26
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
27
|
+
createAdapter: ()=>createAdapter
|
|
28
|
+
});
|
|
29
|
+
const external_commandAdapter_cjs_namespaceObject = require("./commandAdapter.cjs");
|
|
30
|
+
const external_wingmanCliAdapter_cjs_namespaceObject = require("./wingmanCliAdapter.cjs");
|
|
31
|
+
function createAdapter(config) {
|
|
32
|
+
if ("command" === config.type) return new external_commandAdapter_cjs_namespaceObject.CommandAdapter(config);
|
|
33
|
+
return new external_wingmanCliAdapter_cjs_namespaceObject.WingmanCliAdapter(config);
|
|
34
|
+
}
|
|
35
|
+
exports.createAdapter = __webpack_exports__.createAdapter;
|
|
36
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
37
|
+
"createAdapter"
|
|
38
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
39
|
+
Object.defineProperty(exports, '__esModule', {
|
|
40
|
+
value: true
|
|
41
|
+
});
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { CommandAdapter } from "./commandAdapter.js";
|
|
2
|
+
import { WingmanCliAdapter } from "./wingmanCliAdapter.js";
|
|
3
|
+
function createAdapter(config) {
|
|
4
|
+
if ("command" === config.type) return new CommandAdapter(config);
|
|
5
|
+
return new WingmanCliAdapter(config);
|
|
6
|
+
}
|
|
7
|
+
export { createAdapter };
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
5
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: definition[key]
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
})();
|
|
11
|
+
(()=>{
|
|
12
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
13
|
+
})();
|
|
14
|
+
(()=>{
|
|
15
|
+
__webpack_require__.r = (exports1)=>{
|
|
16
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
17
|
+
value: 'Module'
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
20
|
+
value: true
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
})();
|
|
24
|
+
var __webpack_exports__ = {};
|
|
25
|
+
__webpack_require__.r(__webpack_exports__);
|
|
26
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
27
|
+
WingmanCliAdapter: ()=>WingmanCliAdapter
|
|
28
|
+
});
|
|
29
|
+
const external_node_fs_namespaceObject = require("node:fs");
|
|
30
|
+
const external_node_path_namespaceObject = require("node:path");
|
|
31
|
+
const external_process_cjs_namespaceObject = require("../process.cjs");
|
|
32
|
+
const external_helpers_cjs_namespaceObject = require("./helpers.cjs");
|
|
33
|
+
function _define_property(obj, key, value) {
|
|
34
|
+
if (key in obj) Object.defineProperty(obj, key, {
|
|
35
|
+
value: value,
|
|
36
|
+
enumerable: true,
|
|
37
|
+
configurable: true,
|
|
38
|
+
writable: true
|
|
39
|
+
});
|
|
40
|
+
else obj[key] = value;
|
|
41
|
+
return obj;
|
|
42
|
+
}
|
|
43
|
+
function resolveAgent(config, context) {
|
|
44
|
+
return context.task.adapterOverrides?.agent || config.agent;
|
|
45
|
+
}
|
|
46
|
+
function resolveArgs(config, context) {
|
|
47
|
+
const overrideArgs = context.task.adapterOverrides?.extraArgs || [];
|
|
48
|
+
const extraArgs = [
|
|
49
|
+
...config.extraArgs || [],
|
|
50
|
+
...overrideArgs
|
|
51
|
+
];
|
|
52
|
+
const cliArgs = [
|
|
53
|
+
"agent",
|
|
54
|
+
"--local",
|
|
55
|
+
"--output=json",
|
|
56
|
+
"--agent",
|
|
57
|
+
resolveAgent(config, context),
|
|
58
|
+
...extraArgs,
|
|
59
|
+
context.task.prompt
|
|
60
|
+
];
|
|
61
|
+
return cliArgs;
|
|
62
|
+
}
|
|
63
|
+
class WingmanCliAdapter {
|
|
64
|
+
async invoke(context) {
|
|
65
|
+
const configuredCommand = this.config.cliPath || "./bin/wingman";
|
|
66
|
+
const cliEntryPath = (0, external_node_path_namespaceObject.isAbsolute)(configuredCommand) ? configuredCommand : (0, external_node_path_namespaceObject.resolve)(process.cwd(), configuredCommand);
|
|
67
|
+
const args = resolveArgs(this.config, context);
|
|
68
|
+
const runtimeCommand = (0, external_node_fs_namespaceObject.existsSync)(process.execPath) ? process.execPath : "bun";
|
|
69
|
+
const execution = await (0, external_process_cjs_namespaceObject.runCommand)(runtimeCommand, [
|
|
70
|
+
cliEntryPath,
|
|
71
|
+
...args
|
|
72
|
+
], {
|
|
73
|
+
cwd: context.workingDirectory,
|
|
74
|
+
timeoutMs: context.timeoutMs,
|
|
75
|
+
env: this.config.env
|
|
76
|
+
});
|
|
77
|
+
const parsed = (0, external_helpers_cjs_namespaceObject.parseWingmanJsonOutput)(execution.stdout);
|
|
78
|
+
return {
|
|
79
|
+
exitCode: execution.exitCode,
|
|
80
|
+
timedOut: execution.timedOut,
|
|
81
|
+
durationMs: execution.durationMs,
|
|
82
|
+
stdout: execution.stdout,
|
|
83
|
+
stderr: execution.stderr,
|
|
84
|
+
assistantText: parsed.assistantText,
|
|
85
|
+
errorMessage: parsed.errorMessage || (0 === execution.exitCode ? void 0 : execution.stderr.trim()),
|
|
86
|
+
tokens: parsed.tokenUsage
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
constructor(config){
|
|
90
|
+
_define_property(this, "config", void 0);
|
|
91
|
+
this.config = config;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
exports.WingmanCliAdapter = __webpack_exports__.WingmanCliAdapter;
|
|
95
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
96
|
+
"WingmanCliAdapter"
|
|
97
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
98
|
+
Object.defineProperty(exports, '__esModule', {
|
|
99
|
+
value: true
|
|
100
|
+
});
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { AdapterInvocationResult, TaskRunContext, TerminalBenchAdapter, WingmanCliAdapterConfig } from "../types.js";
|
|
2
|
+
export declare class WingmanCliAdapter implements TerminalBenchAdapter {
|
|
3
|
+
private readonly config;
|
|
4
|
+
constructor(config: WingmanCliAdapterConfig);
|
|
5
|
+
invoke(context: TaskRunContext): Promise<AdapterInvocationResult>;
|
|
6
|
+
}
|