@langwatch/mcp-server 0.5.0 → 0.6.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/CHANGELOG.md +25 -0
- package/dist/{archive-scenario-GAE4XVFM.js → archive-scenario-YFD5THOR.js} +3 -3
- package/dist/archive-scenario-YFD5THOR.js.map +1 -0
- package/dist/chunk-5UOPNRXW.js +37 -0
- package/dist/chunk-5UOPNRXW.js.map +1 -0
- package/dist/{chunk-K2YFPOSD.js → chunk-6U4TCGFC.js} +2 -2
- package/dist/chunk-IX6QJKAD.js +22 -0
- package/dist/chunk-IX6QJKAD.js.map +1 -0
- package/dist/{chunk-JVWDWL3J.js → chunk-LLRQIF52.js} +3 -11
- package/dist/chunk-LLRQIF52.js.map +1 -0
- package/dist/create-evaluator-E5X5ZP3B.js +27 -0
- package/dist/create-evaluator-E5X5ZP3B.js.map +1 -0
- package/dist/create-prompt-7Z35MIL6.js +36 -0
- package/dist/create-prompt-7Z35MIL6.js.map +1 -0
- package/dist/{create-scenario-3YRZVDYF.js → create-scenario-DIMPJRPY.js} +3 -3
- package/dist/create-scenario-DIMPJRPY.js.map +1 -0
- package/dist/discover-evaluator-schema-H23XCLNE.js +1402 -0
- package/dist/discover-evaluator-schema-H23XCLNE.js.map +1 -0
- package/dist/{get-analytics-BAVXTAPB.js → get-analytics-4YJW4S5L.js} +2 -2
- package/dist/get-evaluator-WDEH2F7M.js +47 -0
- package/dist/get-evaluator-WDEH2F7M.js.map +1 -0
- package/dist/{get-prompt-LKCPT26O.js → get-prompt-F6PDVC76.js} +2 -5
- package/dist/get-prompt-F6PDVC76.js.map +1 -0
- package/dist/{get-scenario-3SCDW4Z6.js → get-scenario-H24ZYNT5.js} +3 -3
- package/dist/{get-trace-QFDWJ5D4.js → get-trace-27USKGO7.js} +2 -2
- package/dist/index.js +13310 -2410
- package/dist/index.js.map +1 -1
- package/dist/list-evaluators-KRGI72EH.js +34 -0
- package/dist/list-evaluators-KRGI72EH.js.map +1 -0
- package/dist/list-model-providers-A5YCFTPI.js +35 -0
- package/dist/list-model-providers-A5YCFTPI.js.map +1 -0
- package/dist/{list-prompts-UQPBCUYA.js → list-prompts-LKJSE7XN.js} +6 -7
- package/dist/list-prompts-LKJSE7XN.js.map +1 -0
- package/dist/{list-scenarios-573YOUKC.js → list-scenarios-ZK5CMGC4.js} +5 -5
- package/dist/list-scenarios-ZK5CMGC4.js.map +1 -0
- package/dist/{search-traces-RSMYCAN7.js → search-traces-SOKAAMAR.js} +2 -2
- package/dist/set-model-provider-7MGULZDH.js +33 -0
- package/dist/set-model-provider-7MGULZDH.js.map +1 -0
- package/dist/update-evaluator-A3XINFLJ.js +24 -0
- package/dist/update-evaluator-A3XINFLJ.js.map +1 -0
- package/dist/update-prompt-IW7X2UQM.js +22 -0
- package/dist/update-prompt-IW7X2UQM.js.map +1 -0
- package/dist/{update-scenario-SSGVOBJO.js → update-scenario-ZT7TOBFR.js} +3 -3
- package/dist/update-scenario-ZT7TOBFR.js.map +1 -0
- package/package.json +10 -10
- package/src/__tests__/all-tools.integration.test.ts +1337 -0
- package/src/__tests__/discover-evaluator-schema.unit.test.ts +89 -0
- package/src/__tests__/evaluator-tools.unit.test.ts +262 -0
- package/src/__tests__/integration.integration.test.ts +9 -34
- package/src/__tests__/langwatch-api.unit.test.ts +4 -32
- package/src/__tests__/model-provider-tools.unit.test.ts +190 -0
- package/src/__tests__/scenario-tools.integration.test.ts +5 -5
- package/src/__tests__/scenario-tools.unit.test.ts +2 -2
- package/src/__tests__/tools.unit.test.ts +59 -65
- package/src/index.ts +249 -88
- package/src/langwatch-api-evaluators.ts +70 -0
- package/src/langwatch-api-model-providers.ts +41 -0
- package/src/langwatch-api.ts +3 -28
- package/src/tools/archive-scenario.ts +1 -1
- package/src/tools/create-evaluator.ts +33 -0
- package/src/tools/create-prompt.ts +30 -5
- package/src/tools/create-scenario.ts +1 -1
- package/src/tools/discover-evaluator-schema.ts +143 -0
- package/src/tools/get-evaluator.ts +53 -0
- package/src/tools/get-prompt.ts +1 -4
- package/src/tools/list-evaluators.ts +37 -0
- package/src/tools/list-model-providers.ts +40 -0
- package/src/tools/list-prompts.ts +5 -6
- package/src/tools/list-scenarios.ts +3 -3
- package/src/tools/set-model-provider.ts +46 -0
- package/src/tools/update-evaluator.ts +30 -0
- package/src/tools/update-prompt.ts +9 -25
- package/src/tools/update-scenario.ts +1 -1
- package/dist/archive-scenario-GAE4XVFM.js.map +0 -1
- package/dist/chunk-JVWDWL3J.js.map +0 -1
- package/dist/create-prompt-P35POKBW.js +0 -22
- package/dist/create-prompt-P35POKBW.js.map +0 -1
- package/dist/create-scenario-3YRZVDYF.js.map +0 -1
- package/dist/get-prompt-LKCPT26O.js.map +0 -1
- package/dist/list-prompts-UQPBCUYA.js.map +0 -1
- package/dist/list-scenarios-573YOUKC.js.map +0 -1
- package/dist/update-prompt-G2Y5EBQY.js +0 -31
- package/dist/update-prompt-G2Y5EBQY.js.map +0 -1
- package/dist/update-scenario-SSGVOBJO.js.map +0 -1
- /package/dist/{chunk-K2YFPOSD.js.map → chunk-6U4TCGFC.js.map} +0 -0
- /package/dist/{get-analytics-BAVXTAPB.js.map → get-analytics-4YJW4S5L.js.map} +0 -0
- /package/dist/{get-scenario-3SCDW4Z6.js.map → get-scenario-H24ZYNT5.js.map} +0 -0
- /package/dist/{get-trace-QFDWJ5D4.js.map → get-trace-27USKGO7.js.map} +0 -0
- /package/dist/{search-traces-RSMYCAN7.js.map → search-traces-SOKAAMAR.js.map} +0 -0
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach } from "vitest";
|
|
2
|
+
|
|
3
|
+
vi.mock("../langwatch-api-model-providers.js", () => ({
|
|
4
|
+
listModelProviders: vi.fn(),
|
|
5
|
+
setModelProvider: vi.fn(),
|
|
6
|
+
}));
|
|
7
|
+
|
|
8
|
+
import {
|
|
9
|
+
listModelProviders,
|
|
10
|
+
setModelProvider,
|
|
11
|
+
} from "../langwatch-api-model-providers.js";
|
|
12
|
+
|
|
13
|
+
import { handleListModelProviders } from "../tools/list-model-providers.js";
|
|
14
|
+
import { handleSetModelProvider } from "../tools/set-model-provider.js";
|
|
15
|
+
|
|
16
|
+
const mockListModelProviders = vi.mocked(listModelProviders);
|
|
17
|
+
const mockSetModelProvider = vi.mocked(setModelProvider);
|
|
18
|
+
|
|
19
|
+
beforeEach(() => {
|
|
20
|
+
vi.clearAllMocks();
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
describe("handleListModelProviders()", () => {
|
|
24
|
+
const sampleProviders = {
|
|
25
|
+
openai: {
|
|
26
|
+
provider: "openai",
|
|
27
|
+
enabled: true,
|
|
28
|
+
customKeys: { OPENAI_API_KEY: "HAS_KEY" },
|
|
29
|
+
models: ["gpt-4o", "gpt-4o-mini"],
|
|
30
|
+
embeddingsModels: ["text-embedding-3-small"],
|
|
31
|
+
deploymentMapping: null,
|
|
32
|
+
extraHeaders: [],
|
|
33
|
+
},
|
|
34
|
+
anthropic: {
|
|
35
|
+
provider: "anthropic",
|
|
36
|
+
enabled: false,
|
|
37
|
+
customKeys: null,
|
|
38
|
+
models: ["claude-sonnet-4-5-20250929"],
|
|
39
|
+
embeddingsModels: null,
|
|
40
|
+
deploymentMapping: null,
|
|
41
|
+
extraHeaders: [],
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
describe("when providers exist", () => {
|
|
46
|
+
let result: string;
|
|
47
|
+
|
|
48
|
+
beforeEach(async () => {
|
|
49
|
+
mockListModelProviders.mockResolvedValue(sampleProviders);
|
|
50
|
+
result = await handleListModelProviders();
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it("includes the total count header", () => {
|
|
54
|
+
expect(result).toContain("# Model Providers (2 total)");
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it("includes provider name", () => {
|
|
58
|
+
expect(result).toContain("## openai");
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it("shows enabled status", () => {
|
|
62
|
+
expect(result).toContain("**Status**: enabled");
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it("shows disabled status", () => {
|
|
66
|
+
expect(result).toContain("**Status**: disabled");
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it("shows key fields that are set", () => {
|
|
70
|
+
expect(result).toContain("OPENAI_API_KEY: set");
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it("shows model count", () => {
|
|
74
|
+
expect(result).toContain("2 available");
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
describe("when no providers exist", () => {
|
|
79
|
+
let result: string;
|
|
80
|
+
|
|
81
|
+
beforeEach(async () => {
|
|
82
|
+
mockListModelProviders.mockResolvedValue({});
|
|
83
|
+
result = await handleListModelProviders();
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it("returns a no-providers message", () => {
|
|
87
|
+
expect(result).toContain("No model providers configured");
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it("includes a tip to use platform_set_model_provider", () => {
|
|
91
|
+
expect(result).toContain("platform_set_model_provider");
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
describe("handleSetModelProvider()", () => {
|
|
97
|
+
describe("when update succeeds", () => {
|
|
98
|
+
let result: string;
|
|
99
|
+
|
|
100
|
+
beforeEach(async () => {
|
|
101
|
+
mockSetModelProvider.mockResolvedValue({
|
|
102
|
+
openai: {
|
|
103
|
+
provider: "openai",
|
|
104
|
+
enabled: true,
|
|
105
|
+
customKeys: { OPENAI_API_KEY: "HAS_KEY" },
|
|
106
|
+
models: ["gpt-4o"],
|
|
107
|
+
embeddingsModels: null,
|
|
108
|
+
deploymentMapping: null,
|
|
109
|
+
extraHeaders: [],
|
|
110
|
+
},
|
|
111
|
+
});
|
|
112
|
+
result = await handleSetModelProvider({
|
|
113
|
+
provider: "openai",
|
|
114
|
+
enabled: true,
|
|
115
|
+
customKeys: { OPENAI_API_KEY: "sk-test123" },
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
it("confirms update", () => {
|
|
120
|
+
expect(result).toContain("Model provider updated successfully!");
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
it("includes provider name", () => {
|
|
124
|
+
expect(result).toContain("**Provider**: openai");
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
it("shows enabled status", () => {
|
|
128
|
+
expect(result).toContain("**Status**: enabled");
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
it("shows key fields", () => {
|
|
132
|
+
expect(result).toContain("OPENAI_API_KEY: set");
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
describe("when setting default model without provider prefix", () => {
|
|
137
|
+
let result: string;
|
|
138
|
+
|
|
139
|
+
beforeEach(async () => {
|
|
140
|
+
mockSetModelProvider.mockResolvedValue({
|
|
141
|
+
openai: {
|
|
142
|
+
provider: "openai",
|
|
143
|
+
enabled: true,
|
|
144
|
+
customKeys: null,
|
|
145
|
+
models: ["gpt-4o"],
|
|
146
|
+
embeddingsModels: null,
|
|
147
|
+
deploymentMapping: null,
|
|
148
|
+
extraHeaders: [],
|
|
149
|
+
},
|
|
150
|
+
});
|
|
151
|
+
result = await handleSetModelProvider({
|
|
152
|
+
provider: "openai",
|
|
153
|
+
enabled: true,
|
|
154
|
+
defaultModel: "gpt-4o",
|
|
155
|
+
});
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
it("prepends provider prefix in response", () => {
|
|
159
|
+
expect(result).toContain("**Default Model**: openai/gpt-4o");
|
|
160
|
+
});
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
describe("when setting default model with provider prefix already", () => {
|
|
164
|
+
let result: string;
|
|
165
|
+
|
|
166
|
+
beforeEach(async () => {
|
|
167
|
+
mockSetModelProvider.mockResolvedValue({
|
|
168
|
+
openai: {
|
|
169
|
+
provider: "openai",
|
|
170
|
+
enabled: true,
|
|
171
|
+
customKeys: null,
|
|
172
|
+
models: ["gpt-4o"],
|
|
173
|
+
embeddingsModels: null,
|
|
174
|
+
deploymentMapping: null,
|
|
175
|
+
extraHeaders: [],
|
|
176
|
+
},
|
|
177
|
+
});
|
|
178
|
+
result = await handleSetModelProvider({
|
|
179
|
+
provider: "openai",
|
|
180
|
+
enabled: true,
|
|
181
|
+
defaultModel: "openai/gpt-4o",
|
|
182
|
+
});
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
it("keeps the prefix as-is", () => {
|
|
186
|
+
expect(result).toContain("**Default Model**: openai/gpt-4o");
|
|
187
|
+
expect(result).not.toContain("openai/openai/");
|
|
188
|
+
});
|
|
189
|
+
});
|
|
190
|
+
});
|
|
@@ -165,7 +165,7 @@ describe("MCP scenario tools integration", () => {
|
|
|
165
165
|
await new Promise<void>((resolve) => server.close(() => resolve()));
|
|
166
166
|
});
|
|
167
167
|
|
|
168
|
-
describe("
|
|
168
|
+
describe("platform_list_scenarios", () => {
|
|
169
169
|
describe("when the API returns scenarios", () => {
|
|
170
170
|
it("returns a non-empty result", async () => {
|
|
171
171
|
const { handleListScenarios } = await import(
|
|
@@ -187,7 +187,7 @@ describe("MCP scenario tools integration", () => {
|
|
|
187
187
|
});
|
|
188
188
|
});
|
|
189
189
|
|
|
190
|
-
describe("
|
|
190
|
+
describe("platform_get_scenario", () => {
|
|
191
191
|
describe("when the scenario exists", () => {
|
|
192
192
|
it("returns a non-empty result", async () => {
|
|
193
193
|
const { handleGetScenario } = await import(
|
|
@@ -210,7 +210,7 @@ describe("MCP scenario tools integration", () => {
|
|
|
210
210
|
});
|
|
211
211
|
});
|
|
212
212
|
|
|
213
|
-
describe("
|
|
213
|
+
describe("platform_create_scenario", () => {
|
|
214
214
|
describe("when valid data is provided", () => {
|
|
215
215
|
it("returns confirmation with new scenario ID", async () => {
|
|
216
216
|
const { handleCreateScenario } = await import(
|
|
@@ -241,7 +241,7 @@ describe("MCP scenario tools integration", () => {
|
|
|
241
241
|
});
|
|
242
242
|
});
|
|
243
243
|
|
|
244
|
-
describe("
|
|
244
|
+
describe("platform_update_scenario", () => {
|
|
245
245
|
describe("when the scenario exists", () => {
|
|
246
246
|
it("returns a non-empty result", async () => {
|
|
247
247
|
const { handleUpdateScenario } = await import(
|
|
@@ -270,7 +270,7 @@ describe("MCP scenario tools integration", () => {
|
|
|
270
270
|
});
|
|
271
271
|
});
|
|
272
272
|
|
|
273
|
-
describe("
|
|
273
|
+
describe("platform_archive_scenario", () => {
|
|
274
274
|
describe("when the scenario exists", () => {
|
|
275
275
|
it("returns confirmation that scenario was archived", async () => {
|
|
276
276
|
const { handleArchiveScenario } = await import(
|
|
@@ -96,8 +96,8 @@ describe("handleListScenarios()", () => {
|
|
|
96
96
|
expect(result).toContain("No scenarios found");
|
|
97
97
|
});
|
|
98
98
|
|
|
99
|
-
it("includes a tip to use
|
|
100
|
-
expect(result).toContain("
|
|
99
|
+
it("includes a tip to use platform_create_scenario", () => {
|
|
100
|
+
expect(result).toContain("platform_create_scenario");
|
|
101
101
|
});
|
|
102
102
|
});
|
|
103
103
|
|
|
@@ -8,7 +8,6 @@ vi.mock("../langwatch-api.js", () => ({
|
|
|
8
8
|
getPrompt: vi.fn(),
|
|
9
9
|
createPrompt: vi.fn(),
|
|
10
10
|
updatePrompt: vi.fn(),
|
|
11
|
-
createPromptVersion: vi.fn(),
|
|
12
11
|
}));
|
|
13
12
|
|
|
14
13
|
import {
|
|
@@ -19,7 +18,6 @@ import {
|
|
|
19
18
|
getPrompt,
|
|
20
19
|
createPrompt,
|
|
21
20
|
updatePrompt,
|
|
22
|
-
createPromptVersion,
|
|
23
21
|
type PromptSummary,
|
|
24
22
|
} from "../langwatch-api.js";
|
|
25
23
|
|
|
@@ -38,7 +36,6 @@ const mockListPrompts = vi.mocked(listPrompts);
|
|
|
38
36
|
const mockGetPrompt = vi.mocked(getPrompt);
|
|
39
37
|
const mockCreatePrompt = vi.mocked(createPrompt);
|
|
40
38
|
const mockUpdatePrompt = vi.mocked(updatePrompt);
|
|
41
|
-
const mockCreatePromptVersion = vi.mocked(createPromptVersion);
|
|
42
39
|
|
|
43
40
|
beforeEach(() => {
|
|
44
41
|
vi.clearAllMocks();
|
|
@@ -449,22 +446,20 @@ describe("handleListPrompts()", () => {
|
|
|
449
446
|
handle: "greeting",
|
|
450
447
|
name: "Greeting Prompt",
|
|
451
448
|
latestVersionNumber: 3,
|
|
452
|
-
description: "A friendly greeting prompt",
|
|
453
449
|
},
|
|
454
450
|
{
|
|
455
451
|
id: "p2",
|
|
456
452
|
name: "Summary",
|
|
457
453
|
version: 1,
|
|
458
|
-
description: "",
|
|
459
454
|
},
|
|
460
455
|
]);
|
|
461
456
|
|
|
462
457
|
const result = await handleListPrompts();
|
|
463
458
|
|
|
464
459
|
expect(result).toContain("# Prompts (2 total)");
|
|
465
|
-
expect(result).toContain("| Handle | Name | Latest Version |
|
|
466
|
-
expect(result).toContain("| greeting | Greeting Prompt | v3 |
|
|
467
|
-
expect(result).toContain("| p2 | Summary | v1 |
|
|
460
|
+
expect(result).toContain("| Handle | Name | Latest Version |");
|
|
461
|
+
expect(result).toContain("| greeting | Greeting Prompt | v3 |");
|
|
462
|
+
expect(result).toContain("| p2 | Summary | v1 |");
|
|
468
463
|
});
|
|
469
464
|
});
|
|
470
465
|
|
|
@@ -488,14 +483,14 @@ describe("handleListPrompts()", () => {
|
|
|
488
483
|
});
|
|
489
484
|
});
|
|
490
485
|
|
|
491
|
-
it("includes usage tip about
|
|
486
|
+
it("includes usage tip about platform_get_prompt", async () => {
|
|
492
487
|
mockListPrompts.mockResolvedValue([
|
|
493
488
|
{ handle: "test", name: "Test", latestVersionNumber: 1 },
|
|
494
489
|
]);
|
|
495
490
|
|
|
496
491
|
const result = await handleListPrompts();
|
|
497
492
|
|
|
498
|
-
expect(result).toContain("
|
|
493
|
+
expect(result).toContain("platform_get_prompt");
|
|
499
494
|
});
|
|
500
495
|
});
|
|
501
496
|
|
|
@@ -506,13 +501,11 @@ describe("handleGetPrompt()", () => {
|
|
|
506
501
|
id: "p1",
|
|
507
502
|
handle: "greeting",
|
|
508
503
|
name: "Greeting Prompt",
|
|
509
|
-
description: "A greeting",
|
|
510
504
|
latestVersionNumber: 2,
|
|
511
505
|
versions: [
|
|
512
506
|
{
|
|
513
507
|
version: 2,
|
|
514
|
-
model: "gpt-4o",
|
|
515
|
-
modelProvider: "openai",
|
|
508
|
+
model: "openai/gpt-4o",
|
|
516
509
|
messages: [
|
|
517
510
|
{ role: "system", content: "You are a greeter." },
|
|
518
511
|
{ role: "user", content: "Hello!" },
|
|
@@ -531,10 +524,9 @@ describe("handleGetPrompt()", () => {
|
|
|
531
524
|
expect(result).toContain("# Prompt: Greeting Prompt");
|
|
532
525
|
expect(result).toContain("**Handle**: greeting");
|
|
533
526
|
expect(result).toContain("**ID**: p1");
|
|
534
|
-
expect(result).toContain("**Description**: A greeting");
|
|
535
527
|
expect(result).toContain("**Latest Version**: v2");
|
|
536
|
-
expect(result).toContain("**Model**: gpt-4o");
|
|
537
|
-
expect(result).toContain("**Provider
|
|
528
|
+
expect(result).toContain("**Model**: openai/gpt-4o");
|
|
529
|
+
expect(result).not.toContain("**Provider**");
|
|
538
530
|
});
|
|
539
531
|
|
|
540
532
|
it("formats messages", async () => {
|
|
@@ -598,15 +590,14 @@ describe("handleGetPrompt()", () => {
|
|
|
598
590
|
it("uses prompt-level model config", async () => {
|
|
599
591
|
mockGetPrompt.mockResolvedValue({
|
|
600
592
|
name: "Simple",
|
|
601
|
-
model: "gpt-3.5-turbo",
|
|
602
|
-
modelProvider: "openai",
|
|
593
|
+
model: "openai/gpt-3.5-turbo",
|
|
603
594
|
messages: [{ role: "system", content: "Be brief." }],
|
|
604
595
|
});
|
|
605
596
|
|
|
606
597
|
const result = await handleGetPrompt({ idOrHandle: "simple" });
|
|
607
598
|
|
|
608
|
-
expect(result).toContain("**Model**: gpt-3.5-turbo");
|
|
609
|
-
expect(result).toContain("**Provider
|
|
599
|
+
expect(result).toContain("**Model**: openai/gpt-3.5-turbo");
|
|
600
|
+
expect(result).not.toContain("**Provider**");
|
|
610
601
|
expect(result).toContain("### system\nBe brief.");
|
|
611
602
|
});
|
|
612
603
|
});
|
|
@@ -626,17 +617,55 @@ describe("handleCreatePrompt()", () => {
|
|
|
626
617
|
name: "My Prompt",
|
|
627
618
|
handle: "my-prompt",
|
|
628
619
|
messages: [{ role: "system", content: "You are helpful." }],
|
|
629
|
-
model: "gpt-4o",
|
|
630
|
-
modelProvider: "openai",
|
|
620
|
+
model: "openai/gpt-4o",
|
|
631
621
|
});
|
|
632
622
|
|
|
633
623
|
expect(result).toContain("Prompt created successfully!");
|
|
634
624
|
expect(result).toContain("**ID**: new-id-123");
|
|
635
625
|
expect(result).toContain("**Handle**: my-prompt");
|
|
636
626
|
expect(result).toContain("**Name**: My Prompt");
|
|
637
|
-
expect(result).toContain("**Model**: gpt-4o
|
|
627
|
+
expect(result).toContain("**Model**: openai/gpt-4o");
|
|
638
628
|
expect(result).toContain("**Version**: v1");
|
|
639
629
|
});
|
|
630
|
+
|
|
631
|
+
it("generates handle from name when handle is not provided", async () => {
|
|
632
|
+
mockCreatePrompt.mockResolvedValue({
|
|
633
|
+
id: "new-id",
|
|
634
|
+
handle: "my-prompt",
|
|
635
|
+
});
|
|
636
|
+
|
|
637
|
+
await handleCreatePrompt({
|
|
638
|
+
name: "My Prompt!",
|
|
639
|
+
messages: [{ role: "system", content: "test" }],
|
|
640
|
+
model: "openai/gpt-4o",
|
|
641
|
+
});
|
|
642
|
+
|
|
643
|
+
expect(mockCreatePrompt).toHaveBeenCalledWith({
|
|
644
|
+
handle: "my-prompt",
|
|
645
|
+
messages: [{ role: "system", content: "test" }],
|
|
646
|
+
model: "openai/gpt-4o",
|
|
647
|
+
});
|
|
648
|
+
});
|
|
649
|
+
|
|
650
|
+
it("uses provided handle instead of generating one", async () => {
|
|
651
|
+
mockCreatePrompt.mockResolvedValue({
|
|
652
|
+
id: "new-id",
|
|
653
|
+
handle: "custom-handle",
|
|
654
|
+
});
|
|
655
|
+
|
|
656
|
+
await handleCreatePrompt({
|
|
657
|
+
name: "My Prompt",
|
|
658
|
+
handle: "custom-handle",
|
|
659
|
+
messages: [{ role: "system", content: "test" }],
|
|
660
|
+
model: "openai/gpt-4o",
|
|
661
|
+
});
|
|
662
|
+
|
|
663
|
+
expect(mockCreatePrompt).toHaveBeenCalledWith({
|
|
664
|
+
handle: "custom-handle",
|
|
665
|
+
messages: [{ role: "system", content: "test" }],
|
|
666
|
+
model: "openai/gpt-4o",
|
|
667
|
+
});
|
|
668
|
+
});
|
|
640
669
|
});
|
|
641
670
|
|
|
642
671
|
describe("when API returns no name", () => {
|
|
@@ -646,8 +675,7 @@ describe("handleCreatePrompt()", () => {
|
|
|
646
675
|
const result = await handleCreatePrompt({
|
|
647
676
|
name: "Fallback Name",
|
|
648
677
|
messages: [{ role: "system", content: "test" }],
|
|
649
|
-
model: "gpt-4o",
|
|
650
|
-
modelProvider: "openai",
|
|
678
|
+
model: "openai/gpt-4o",
|
|
651
679
|
});
|
|
652
680
|
|
|
653
681
|
expect(result).toContain("**Name**: Fallback Name");
|
|
@@ -656,7 +684,7 @@ describe("handleCreatePrompt()", () => {
|
|
|
656
684
|
});
|
|
657
685
|
|
|
658
686
|
describe("handleUpdatePrompt()", () => {
|
|
659
|
-
describe("when updating
|
|
687
|
+
describe("when updating a prompt", () => {
|
|
660
688
|
it("formats an update success message", async () => {
|
|
661
689
|
mockUpdatePrompt.mockResolvedValue({
|
|
662
690
|
id: "p1",
|
|
@@ -677,53 +705,19 @@ describe("handleUpdatePrompt()", () => {
|
|
|
677
705
|
expect(result).toContain("**Commit**: Update system prompt");
|
|
678
706
|
});
|
|
679
707
|
|
|
680
|
-
it("calls updatePrompt API", async () => {
|
|
708
|
+
it("calls updatePrompt API with correct params", async () => {
|
|
681
709
|
mockUpdatePrompt.mockResolvedValue({});
|
|
682
710
|
|
|
683
711
|
await handleUpdatePrompt({
|
|
684
712
|
idOrHandle: "greeting",
|
|
685
|
-
model: "gpt-4o",
|
|
713
|
+
model: "openai/gpt-4o",
|
|
714
|
+
commitMessage: "Switch model",
|
|
686
715
|
});
|
|
687
716
|
|
|
688
717
|
expect(mockUpdatePrompt).toHaveBeenCalledWith("greeting", {
|
|
689
|
-
model: "gpt-4o",
|
|
690
|
-
|
|
691
|
-
expect(mockCreatePromptVersion).not.toHaveBeenCalled();
|
|
692
|
-
});
|
|
693
|
-
});
|
|
694
|
-
|
|
695
|
-
describe("when creating a new version", () => {
|
|
696
|
-
it("formats a version creation success message", async () => {
|
|
697
|
-
mockCreatePromptVersion.mockResolvedValue({
|
|
698
|
-
id: "p1",
|
|
699
|
-
latestVersionNumber: 3,
|
|
700
|
-
});
|
|
701
|
-
|
|
702
|
-
const result = await handleUpdatePrompt({
|
|
703
|
-
idOrHandle: "greeting",
|
|
704
|
-
messages: [{ role: "system", content: "New version" }],
|
|
705
|
-
createVersion: true,
|
|
706
|
-
commitMessage: "v3",
|
|
707
|
-
});
|
|
708
|
-
|
|
709
|
-
expect(result).toContain("New version created successfully!");
|
|
710
|
-
expect(result).toContain("**Version**: v3");
|
|
711
|
-
expect(result).toContain("**Commit**: v3");
|
|
712
|
-
});
|
|
713
|
-
|
|
714
|
-
it("calls createPromptVersion API", async () => {
|
|
715
|
-
mockCreatePromptVersion.mockResolvedValue({});
|
|
716
|
-
|
|
717
|
-
await handleUpdatePrompt({
|
|
718
|
-
idOrHandle: "greeting",
|
|
719
|
-
messages: [{ role: "system", content: "New" }],
|
|
720
|
-
createVersion: true,
|
|
721
|
-
});
|
|
722
|
-
|
|
723
|
-
expect(mockCreatePromptVersion).toHaveBeenCalledWith("greeting", {
|
|
724
|
-
messages: [{ role: "system", content: "New" }],
|
|
718
|
+
model: "openai/gpt-4o",
|
|
719
|
+
commitMessage: "Switch model",
|
|
725
720
|
});
|
|
726
|
-
expect(mockUpdatePrompt).not.toHaveBeenCalled();
|
|
727
721
|
});
|
|
728
722
|
});
|
|
729
723
|
});
|