@langwatch/server 3.1.0-beta.21 → 3.1.0-beta.22
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/langevals/evaluators/topic_clustering/langevals_topic_clustering/__init__.py +36 -0
- package/langevals/evaluators/topic_clustering/langevals_topic_clustering/_logger.py +165 -0
- package/langevals/evaluators/topic_clustering/langevals_topic_clustering/batch_clustering.py +153 -0
- package/langevals/evaluators/topic_clustering/langevals_topic_clustering/build_response.py +77 -0
- package/langevals/evaluators/topic_clustering/langevals_topic_clustering/constants.py +7 -0
- package/langevals/evaluators/topic_clustering/langevals_topic_clustering/incremental_clustering.py +325 -0
- package/langevals/evaluators/topic_clustering/langevals_topic_clustering/topic_naming.py +432 -0
- package/langevals/evaluators/topic_clustering/langevals_topic_clustering/types.py +42 -0
- package/langevals/evaluators/topic_clustering/langevals_topic_clustering/utils.py +191 -0
- package/langevals/evaluators/topic_clustering/pyproject.toml +52 -0
- package/langevals/evaluators/topic_clustering/tests/test_topic_clustering.py +239 -0
- package/langevals/evaluators/topic_clustering/tests/test_topic_clustering_integration.py +97 -0
- package/langevals/evaluators/topic_clustering/tests/test_topic_naming.py +72 -0
- package/langevals/langevals/pytest_plugins/pass_rate_plugin.py +7 -1
- package/langevals/langevals/server.py +28 -0
- package/langevals/pyproject.toml +3 -0
- package/langevals/uv.lock +119 -20
- package/langwatch/dist/client/assets/{AnnotationsTable-BDAkYaz6.js → AnnotationsTable-uS_9SQ-g.js} +2 -2
- package/langwatch/dist/client/assets/{BatchEvaluationSummary-DMaQM_VB.js → BatchEvaluationSummary-DtFd8yKJ.js} +2 -2
- package/langwatch/dist/client/assets/{BudgetEditDrawer-CHaqmdIl.js → BudgetEditDrawer-CHEPz0hH.js} +2 -2
- package/langwatch/dist/client/assets/{ChartCard-D14PUg_d.js → ChartCard-s5fMPo7b.js} +2 -2
- package/langwatch/dist/client/assets/{ChatWindow-CRDnlP-Q.js → ChatWindow-C0XSteVJ.js} +2 -2
- package/langwatch/dist/client/assets/ChatWindow-DFEmNXQL.js +1 -0
- package/langwatch/dist/client/assets/{ConfirmDialog-CXIhncvW.js → ConfirmDialog-M94yLNvP.js} +2 -2
- package/langwatch/dist/client/assets/{ContactSalesBlock-CijLBwRC.js → ContactSalesBlock-CnnuZ8iI.js} +2 -2
- package/langwatch/dist/client/assets/{DSPyExperiment-B1YOL2m8.js → DSPyExperiment-CMA6lrlx.js} +2 -2
- package/langwatch/dist/client/assets/{FilterDisplay-BB0xWrLn.js → FilterDisplay-0S3NqCkq.js} +2 -2
- package/langwatch/dist/client/assets/{FormatMoney-w9vr_h0X.js → FormatMoney-CCygtAHg.js} +2 -2
- package/langwatch/dist/client/assets/{FoundryDrawer-CdJDXtpz.js → FoundryDrawer-B35xZ26C.js} +2 -2
- package/langwatch/dist/client/assets/{GatewayErrorPanel-DvE9U2dS.js → GatewayErrorPanel-BsaYQEie.js} +2 -2
- package/langwatch/dist/client/assets/{GatewayLayout-lv1p_6B5.js → GatewayLayout-LvwwrwMf.js} +2 -2
- package/langwatch/dist/client/assets/{GraphsLayout-BJ68J9e-.js → GraphsLayout-DJ-HI9N1.js} +2 -2
- package/langwatch/dist/client/assets/{GroupBindingInputRow-DebZBCnD.js → GroupBindingInputRow-CV-fBkX9.js} +2 -2
- package/langwatch/dist/client/assets/{MessagesTable-B6lYde-x.js → MessagesTable-9taaKCOZ.js} +2 -2
- package/langwatch/dist/client/assets/{NavigationFooter-CiOVzDUh.js → NavigationFooter-Dzvauw3l.js} +2 -2
- package/langwatch/dist/client/assets/{NoDataInfoBlock-quSW_MRm.js → NoDataInfoBlock-CLKl_wlX.js} +2 -2
- package/langwatch/dist/client/assets/{OpsPageShell-DJ1WlI6-.js → OpsPageShell-C_mTziRS.js} +2 -2
- package/langwatch/dist/client/assets/{OptimizationStudio-BlozXjcN.js → OptimizationStudio-D2zpsmJj.js} +8 -12
- package/langwatch/dist/client/assets/{PreconditionsField-BOfcWvmZ.js → PreconditionsField-WXB8kcTK.js} +2 -2
- package/langwatch/dist/client/assets/{SettingsLayout-CLCGxMAe.js → SettingsLayout--1gdEuhv.js} +2 -2
- package/langwatch/dist/client/assets/{SubscriptionPage-J8b2Zaj6.js → SubscriptionPage-B0ox_4kM.js} +2 -2
- package/langwatch/dist/client/assets/{VirtualKeySecretReveal-DR1VDLy7.js → VirtualKeySecretReveal-CRbI1dKQ.js} +2 -2
- package/langwatch/dist/client/assets/{WithPermissionGuard-DD8uo3UK.js → WithPermissionGuard-B4Jo8E5-.js} +2 -2
- package/langwatch/dist/client/assets/{__...path__-BZVaIayJ.js → __...path__-BF2zkD84.js} +2 -2
- package/langwatch/dist/client/assets/{_experiment_-B1aT-wS3.js → _experiment_-D02aoVQk.js} +2 -2
- package/langwatch/dist/client/assets/{_id_-oI_eq-I_.js → _id_-Ch8YmTiM.js} +2 -2
- package/langwatch/dist/client/assets/{_id_-DAqPuO73.js → _id_-D6ZvwHpH.js} +2 -2
- package/langwatch/dist/client/assets/{_id_-DUngklVb.js → _id_-DOC1ZkBm.js} +2 -2
- package/langwatch/dist/client/assets/{_id_-jFDAfbob.js → _id_-DfWwW6_N.js} +2 -2
- package/langwatch/dist/client/assets/{_id_-BKBrWGG0.js → _id_-DxUo4W7J.js} +2 -2
- package/langwatch/dist/client/assets/_not-found-DDh108-i.js +1 -0
- package/langwatch/dist/client/assets/{_project_-Bt1tayHB.js → _project_-_UUt5Ar9.js} +2 -2
- package/langwatch/dist/client/assets/{_runId_-CfvnDt5H.js → _runId_-Dimwzp48.js} +2 -2
- package/langwatch/dist/client/assets/_slug_-BMvKBwS_.js +2 -0
- package/langwatch/dist/client/assets/{_slug_-DZAdl0QS.js → _slug_-CE6VoDSC.js} +2 -2
- package/langwatch/dist/client/assets/{_slug_-DmoWXjKT.js → _slug_-OiOLG1Mv.js} +2 -2
- package/langwatch/dist/client/assets/{_team_-DL_wKSWK.js → _team_-DKvmwO_5.js} +2 -2
- package/langwatch/dist/client/assets/{_workflow_-DcMXLPUe.js → _workflow_-FkilKiB-.js} +3 -3
- package/langwatch/dist/client/assets/{_workflow_-NI9bac7d.js → _workflow_-gJZppg3h.js} +2 -2
- package/langwatch/dist/client/assets/{access-audit-CFwNwusI.js → access-audit-xcUVYMMT.js} +2 -2
- package/langwatch/dist/client/assets/{agents-Di4XRwcn.js → agents-D32g91cu.js} +2 -2
- package/langwatch/dist/client/assets/{all-C273mlDB.js → all-vnREzDZj.js} +2 -2
- package/langwatch/dist/client/assets/{analytics-CEAcSf6B.js → analytics-DP6Y4Feh.js} +2 -2
- package/langwatch/dist/client/assets/{annotation-scores-CHfn4LQp.js → annotation-scores-CjD4CEB6.js} +2 -2
- package/langwatch/dist/client/assets/{annotations-CHZQrha6.js → annotations-1rVXiDRQ.js} +2 -2
- package/langwatch/dist/client/assets/{api-keys-BT7HExHM.js → api-keys-BJpKyuaz.js} +2 -2
- package/langwatch/dist/client/assets/{audit-log-BGk-51Dt.js → audit-log-BdUdZjxp.js} +2 -2
- package/langwatch/dist/client/assets/{authentication-DvwXfkp-.js → authentication-8mQB00CC.js} +2 -2
- package/langwatch/dist/client/assets/{authorize-tXpHrWyw.js → authorize-BpUueMNW.js} +2 -2
- package/langwatch/dist/client/assets/{authorize-CRu9xlpU.js → authorize-CbNBtmxW.js} +2 -2
- package/langwatch/dist/client/assets/{automations-CjDvz9Ak.js → automations-34KMkRxd.js} +2 -2
- package/langwatch/dist/client/assets/{billing-plans-FUqEPN62.js → billing-plans-BUQp08MI.js} +2 -2
- package/langwatch/dist/client/assets/{budgets-BV6_RHrs.js → budgets-CdelE8Hv.js} +2 -2
- package/langwatch/dist/client/assets/{cache-rules-CtYA79E_.js → cache-rules-D2m1QlNJ.js} +2 -2
- package/langwatch/dist/client/assets/choose-C0LdeUiH.js +2 -0
- package/langwatch/dist/client/assets/{command-bar-CaJygoez.js → command-bar-DUK45yin.js} +7 -9
- package/langwatch/dist/client/assets/custom-hBq2K4FJ.js +1 -0
- package/langwatch/dist/client/assets/{datasets-vLWpH84_.js → datasets-ErNNhmjg.js} +2 -2
- package/langwatch/dist/client/assets/{dejaview-DwVR3RGg.js → dejaview-BaD4_v90.js} +2 -2
- package/langwatch/dist/client/assets/{dist-SwV3YZv3.js → dist-Cds4Mqhj.js} +4 -6
- package/langwatch/dist/client/assets/{edit-CyxsmQmW.js → edit-DpT8ejBV.js} +2 -2
- package/langwatch/dist/client/assets/{evaluations-BfgeZMph.js → evaluations-BdQ2Dm2r.js} +2 -2
- package/langwatch/dist/client/assets/{evaluations-HSQIMvbX.js → evaluations-C90I4VAr.js} +2 -2
- package/langwatch/dist/client/assets/{evaluators-DLHVvnrh.js → evaluators-ig_ugRLt.js} +2 -2
- package/langwatch/dist/client/assets/{foundry-Ckq0WjPU.js → foundry-B-X_80pD.js} +2 -2
- package/langwatch/dist/client/assets/{gateway-CDSYPZ6w.js → gateway-CS_mtJx-.js} +2 -2
- package/langwatch/dist/client/assets/{groups-CCCRUqPj.js → groups-Bp90ChP3.js} +2 -2
- package/langwatch/dist/client/assets/{index-Bm6z2fM9.js → index-TNQ6uyis.js} +4 -4
- package/langwatch/dist/client/assets/{license-CHOarGWr.js → license-CgnlvyuI.js} +2 -2
- package/langwatch/dist/client/assets/{me-CBya_vXs.js → me-DEqhm_KC.js} +2 -2
- package/langwatch/dist/client/assets/{members-lIFLh-rh.js → members-CUJANDtH.js} +2 -2
- package/langwatch/dist/client/assets/{messages-CG9j8Dz8.js → messages-fQBfCjvp.js} +2 -2
- package/langwatch/dist/client/assets/{metrics-C9pzeaI6.js → metrics-DeIxebpD.js} +2 -2
- package/langwatch/dist/client/assets/{model-costs-Bc5uqjkl.js → model-costs-C1RbgK--.js} +2 -2
- package/langwatch/dist/client/assets/{model-providers-B5UjRgS_.js → model-providers-Pv3ML_-t.js} +2 -2
- package/langwatch/dist/client/assets/{my-queue-BkEfiWyR.js → my-queue-BLre2NMr.js} +2 -2
- package/langwatch/dist/client/assets/{ops-Cc-g-CMn.js → ops-CCw-FJaT.js} +2 -2
- package/langwatch/dist/client/assets/{organization-features-CoIKKHkQ.js → organization-features-rqg-75mI.js} +2 -2
- package/langwatch/dist/client/assets/{organizations-DWcQUTzi.js → organizations-DjCzIHVx.js} +2 -2
- package/langwatch/dist/client/assets/{persistence-CTQ44vGL.js → persistence-BPvHS0F6.js} +2 -2
- package/langwatch/dist/client/assets/{plans-Dq3eFg5K.js → plans-Ch2Ol-Fd.js} +2 -2
- package/langwatch/dist/client/assets/{projections-CTNj1QBM.js → projections-it4FOVjm.js} +2 -2
- package/langwatch/dist/client/assets/{projects-BxM7C87h.js → projects-CjWZFLfn.js} +2 -2
- package/langwatch/dist/client/assets/{prompts-DhXnJT6e.js → prompts-DilmFH_s.js} +2 -2
- package/langwatch/dist/client/assets/{providers-DW7VWdqq.js → providers-tlLT_lTF.js} +2 -2
- package/langwatch/dist/client/assets/{reports-D3QFKhNP.js → reports-vlrcTrLs.js} +2 -2
- package/langwatch/dist/client/assets/{roles-B_0t5DWA.js → roles-DNgi-NQ9.js} +2 -2
- package/langwatch/dist/client/assets/{scenarios-BX3XslU0.js → scenarios-BmG_wDkR.js} +2 -2
- package/langwatch/dist/client/assets/{scim-DDsLO39r.js → scim-BKr1_FHt.js} +2 -2
- package/langwatch/dist/client/assets/{secrets-BvEGwDCy.js → secrets-CU8ocTGv.js} +2 -2
- package/langwatch/dist/client/assets/{settings-9giNiAQQ.js → settings-CDzdoYVK.js} +2 -2
- package/langwatch/dist/client/assets/{setup-HxXKoVKG.js → setup-nEvn2rjN.js} +2 -2
- package/langwatch/dist/client/assets/{subscription-DhyswDze.js → subscription-BPNl_6jF.js} +3 -3
- package/langwatch/dist/client/assets/{subscriptions-Dyyau22a.js → subscriptions-D0G-OE5C.js} +2 -2
- package/langwatch/dist/client/assets/{teams-DRmeAxzf.js → teams-DThgDQvB.js} +2 -2
- package/langwatch/dist/client/assets/{textOverflowHeuristic-JibhpzDV.js → textOverflowHeuristic-DTC8-Ffx.js} +2 -2
- package/langwatch/dist/client/assets/{topic-clustering-Bllfw5rZ.js → topic-clustering-BR2Mbpao.js} +2 -2
- package/langwatch/dist/client/assets/{topics-CpiGYxqb.js → topics-CI8GoNqp.js} +2 -2
- package/langwatch/dist/client/assets/{traceExecutor-CiHXJB0V.js → traceExecutor-CDUGyUaw.js} +2 -2
- package/langwatch/dist/client/assets/{usage-BnsstwBY.js → usage-B4mR7ut_.js} +2 -2
- package/langwatch/dist/client/assets/{usage-CoyGtJoI.js → usage-C8fbffYi.js} +2 -2
- package/langwatch/dist/client/assets/{useAdminResource-SPC5iBHM.js → useAdminResource-SmnnHro6.js} +2 -2
- package/langwatch/dist/client/assets/{useAnnotationQueues-2DKZTC7r.js → useAnnotationQueues-CA6Vk--V.js} +2 -2
- package/langwatch/dist/client/assets/{useAvailableEvaluators-HndTl2LV.js → useAvailableEvaluators-hmbmcRQr.js} +2 -2
- package/langwatch/dist/client/assets/{useDeleteDatasetConfirmation-BgWN6Qqb.js → useDeleteDatasetConfirmation-BCK_zUUe.js} +2 -2
- package/langwatch/dist/client/assets/{useWorkflowStore-e1wFCvo2.js → useWorkflowStore-QUJ3J8X9.js} +2 -2
- package/langwatch/dist/client/assets/{users-C6wjliCC.js → users-CfhanCfR.js} +2 -2
- package/langwatch/dist/client/assets/{users-tF6ZKeV1.js → users-HjuN3o6k.js} +2 -2
- package/langwatch/dist/client/assets/{virtual-keys-BL-65S0B.js → virtual-keys-Bj-MhW66.js} +2 -2
- package/langwatch/dist/client/assets/{wizard-faGkpZDT.js → wizard-dRWCVVx6.js} +2 -2
- package/langwatch/dist/client/assets/{workbench-Oj0s_YR-.js → workbench-CuixH3G1.js} +2 -2
- package/langwatch/dist/client/assets/{workflows-Cu9k-Twu.js → workflows-BT6m4Yu9.js} +2 -2
- package/langwatch/dist/client/index.html +3 -3
- package/langwatch/scripts/seed-dogfood-password.ts +163 -0
- package/langwatch/src/app/api/workflows/post_event/__tests__/post-event-evaluator.integration.test.ts +458 -0
- package/langwatch/src/app/api/workflows/post_event/__tests__/post-event-routing.test.ts +180 -0
- package/langwatch/src/app/api/workflows/post_event/__tests__/post-event.integration.test.ts +274 -0
- package/langwatch/src/app/api/workflows/post_event/post-event.ts +29 -1
- package/langwatch/src/components/agents/AgentCodeEditorDrawer.tsx +4 -5
- package/langwatch/src/components/agents/__tests__/AgentCodeEditorDrawer.integration.test.tsx +40 -0
- package/langwatch/src/components/evaluations/wizard/hooks/evaluation-wizard-store/slices/factories/__tests__/code-execution-node.factory.unit.test.ts +47 -0
- package/langwatch/src/components/evaluations/wizard/hooks/evaluation-wizard-store/slices/factories/code-execution-node.factory.ts +2 -4
- package/langwatch/src/components/experiments/BatchEvaluationV2/BatchEvaluationV2EvaluationResults.tsx +6 -1
- package/langwatch/src/optimization_studio/__tests__/registry.test.ts +29 -1
- package/langwatch/src/optimization_studio/components/Optimize.tsx +17 -3
- package/langwatch/src/optimization_studio/components/properties/AgentPropertiesPanel.tsx +4 -5
- package/langwatch/src/optimization_studio/hooks/workflowStoreCore.ts +17 -6
- package/langwatch/src/optimization_studio/hooks/workflowStoreCore.unit.test.ts +42 -0
- package/langwatch/src/optimization_studio/registry.ts +2 -4
- package/langwatch/src/optimization_studio/server/lambda/index.ts +12 -2
- package/langwatch/src/server/api/routers/workflows.ts +18 -0
- package/langwatch/src/server/evaluations-v3/execution/workflowBuilder.ts +3 -2
- package/langwatch/src/server/evaluations-v3/services/__tests__/experiment-run.service.getRun-null.unit.test.ts +71 -0
- package/langwatch/src/server/evaluations-v3/services/experiment-run.service.ts +18 -9
- package/langwatch/src/server/modelProviders/utils.ts +11 -1
- package/langwatch/src/server/nlpgo/__tests__/nlpgoFetch.integration.test.ts +248 -0
- package/langwatch/src/server/nlpgo/nlpgoFetch.ts +142 -0
- package/langwatch/src/server/routes/__tests__/playground-proxy.integration.test.ts +242 -0
- package/langwatch/src/server/routes/playground.ts +11 -1
- package/langwatch/src/server/routes/workflows.ts +17 -0
- package/langwatch/src/server/topicClustering/topicClustering.ts +33 -8
- package/langwatch/src/server/workflows/runWorkflow.ts +10 -13
- package/langwatch_nlp/langwatch_nlp/topic_clustering/topic_naming.py +39 -32
- package/langwatch_nlp/scripts/entrypoint.sh +67 -0
- package/package.json +1 -1
- package/packages/server/dist/cli.cjs +67 -94
- package/langwatch/dist/client/assets/ChatWindow-DzB-tNlQ.js +0 -1
- package/langwatch/dist/client/assets/_not-found-PEUaWdF3.js +0 -1
- package/langwatch/dist/client/assets/_slug_-C-8AjsjC.js +0 -2
- package/langwatch/dist/client/assets/choose--PBky27o.js +0 -2
- package/langwatch/dist/client/assets/custom-CSiS1liN.js +0 -1
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @vitest-environment node
|
|
3
|
+
*
|
|
4
|
+
* End-to-end TS integration: spins up a real `nlpgo` Go subprocess,
|
|
5
|
+
* mocks the feature flag to ON, and exercises the same `nlpgoFetch`
|
|
6
|
+
* helper that `runWorkflow.ts` calls in production. The signature
|
|
7
|
+
* node hits a live OpenAI endpoint via the in-process dispatcher.
|
|
8
|
+
*
|
|
9
|
+
* Why this test exists:
|
|
10
|
+
* - rchaves's QA matrix asks for proof that the actual app surface
|
|
11
|
+
* works end-to-end, not unit tests of individual components.
|
|
12
|
+
* - Browser dogfood is one form of evidence; this is the
|
|
13
|
+
* repeatable-on-CI variant. Stays green forever (or alerts) if
|
|
14
|
+
* any link in the chain breaks: TS app routing, nlpgoFetch
|
|
15
|
+
* envelope, nlpgo handler, engine, dispatcher, Bifrost,
|
|
16
|
+
* provider integration.
|
|
17
|
+
*
|
|
18
|
+
* Skipped (not failed) when:
|
|
19
|
+
* - OPENAI_API_KEY not set
|
|
20
|
+
* - go binary not on PATH
|
|
21
|
+
*
|
|
22
|
+
* Each run takes ~2-4s for the dispatch + LLM call; subprocess startup
|
|
23
|
+
* adds ~3s on first invocation due to `go run` compilation.
|
|
24
|
+
*/
|
|
25
|
+
import { spawn, type ChildProcess } from "node:child_process";
|
|
26
|
+
import { setTimeout as sleep } from "node:timers/promises";
|
|
27
|
+
import path from "node:path";
|
|
28
|
+
|
|
29
|
+
import { afterAll, beforeAll, describe, expect, it, vi } from "vitest";
|
|
30
|
+
|
|
31
|
+
// Mock the feature flag service BEFORE importing the helper so the
|
|
32
|
+
// FF check returns true regardless of PostHog state.
|
|
33
|
+
vi.mock("../../featureFlag/featureFlag.service", () => ({
|
|
34
|
+
featureFlagService: {
|
|
35
|
+
isEnabled: vi.fn().mockResolvedValue(true),
|
|
36
|
+
},
|
|
37
|
+
}));
|
|
38
|
+
|
|
39
|
+
// Mock lambdaFetch so it routes through plain fetch instead of trying
|
|
40
|
+
// to invoke an AWS Lambda. The Go subprocess is reachable on
|
|
41
|
+
// http://127.0.0.1:5562 so we use that as the "function arn"
|
|
42
|
+
// (lambdaFetch's URL fallback is a string base URL).
|
|
43
|
+
vi.mock("../../../utils/lambdaFetch", () => ({
|
|
44
|
+
lambdaFetch: async (
|
|
45
|
+
baseURL: string,
|
|
46
|
+
pathSuffix: string,
|
|
47
|
+
init: { method: string; headers: Record<string, string>; body: string },
|
|
48
|
+
) => {
|
|
49
|
+
const resp = await fetch(baseURL + pathSuffix, init);
|
|
50
|
+
return {
|
|
51
|
+
ok: resp.ok,
|
|
52
|
+
status: resp.status,
|
|
53
|
+
statusText: resp.statusText,
|
|
54
|
+
json: () => resp.json(),
|
|
55
|
+
text: () => resp.text(),
|
|
56
|
+
};
|
|
57
|
+
},
|
|
58
|
+
}));
|
|
59
|
+
|
|
60
|
+
// Mock getProjectLambdaArn to return our local nlpgo URL.
|
|
61
|
+
vi.mock("../../../optimization_studio/server/lambda", () => ({
|
|
62
|
+
getProjectLambdaArn: async () => "http://127.0.0.1:5562",
|
|
63
|
+
}));
|
|
64
|
+
|
|
65
|
+
const NLPGO_PORT = 5562;
|
|
66
|
+
const REPO_ROOT = path.resolve(__dirname, "../../../../../..");
|
|
67
|
+
|
|
68
|
+
let nlpgoProcess: ChildProcess | null = null;
|
|
69
|
+
|
|
70
|
+
async function waitForHealth(timeoutMs = 30_000): Promise<void> {
|
|
71
|
+
const deadline = Date.now() + timeoutMs;
|
|
72
|
+
while (Date.now() < deadline) {
|
|
73
|
+
try {
|
|
74
|
+
const r = await fetch(`http://127.0.0.1:${NLPGO_PORT}/healthz`);
|
|
75
|
+
if (r.status === 200 || r.status === 503) return;
|
|
76
|
+
} catch {
|
|
77
|
+
// not ready yet
|
|
78
|
+
}
|
|
79
|
+
await sleep(250);
|
|
80
|
+
}
|
|
81
|
+
throw new Error(`nlpgo did not become healthy within ${timeoutMs}ms`);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
beforeAll(async () => {
|
|
85
|
+
if (!process.env.OPENAI_API_KEY) return; // test will be skipped at the it() level
|
|
86
|
+
// Spawn `go run ./cmd/service nlpgo` from the repo root, with
|
|
87
|
+
// NLPGO_CHILD_BYPASS=true so it doesn't try to spawn uvicorn (no
|
|
88
|
+
// langwatch_nlp Python venv in test env).
|
|
89
|
+
// detached:true so afterAll's process.kill(-pid) reaches the
|
|
90
|
+
// compiled child of `go run`, not just the toolchain wrapper.
|
|
91
|
+
// See post-event.integration.test.ts for the full rationale.
|
|
92
|
+
nlpgoProcess = spawn("go", ["run", "./cmd/service", "nlpgo"], {
|
|
93
|
+
cwd: REPO_ROOT,
|
|
94
|
+
env: {
|
|
95
|
+
...process.env,
|
|
96
|
+
NLPGO_CHILD_BYPASS: "true",
|
|
97
|
+
},
|
|
98
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
99
|
+
detached: true,
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
// Surface stderr to the test logs for debugging — stdout is just
|
|
103
|
+
// structured logs.
|
|
104
|
+
nlpgoProcess.stderr?.on("data", (chunk: Buffer) => {
|
|
105
|
+
if (process.env.NLPGO_TEST_LOG === "1") {
|
|
106
|
+
process.stderr.write(`[nlpgo] ${chunk.toString()}`);
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
nlpgoProcess.on("exit", (code, signal) => {
|
|
110
|
+
if (code !== 0 && code !== null) {
|
|
111
|
+
console.error(`nlpgo exited unexpectedly: code=${code} signal=${signal}`);
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
await waitForHealth();
|
|
116
|
+
}, 90_000);
|
|
117
|
+
|
|
118
|
+
afterAll(async () => {
|
|
119
|
+
if (!nlpgoProcess?.pid) return;
|
|
120
|
+
const pgid = -nlpgoProcess.pid;
|
|
121
|
+
try {
|
|
122
|
+
process.kill(pgid, "SIGTERM");
|
|
123
|
+
} catch {
|
|
124
|
+
// group already gone
|
|
125
|
+
}
|
|
126
|
+
const exited = await Promise.race([
|
|
127
|
+
new Promise<boolean>((resolve) =>
|
|
128
|
+
nlpgoProcess!.once("exit", () => resolve(true)),
|
|
129
|
+
),
|
|
130
|
+
sleep(2000).then(() => false),
|
|
131
|
+
]);
|
|
132
|
+
if (!exited) {
|
|
133
|
+
try {
|
|
134
|
+
process.kill(pgid, "SIGKILL");
|
|
135
|
+
} catch {
|
|
136
|
+
// best-effort
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
const liveOpenAI = process.env.OPENAI_API_KEY ? it : it.skip;
|
|
142
|
+
|
|
143
|
+
describe("nlpgoFetch end-to-end against live nlpgo subprocess", () => {
|
|
144
|
+
liveOpenAI("routes a Studio workflow to /go/studio/execute_sync and returns a real LLM result", async () => {
|
|
145
|
+
const { nlpgoFetch } = await import("../nlpgoFetch");
|
|
146
|
+
|
|
147
|
+
const workflow = {
|
|
148
|
+
workflow_id: "ts-e2e",
|
|
149
|
+
api_key: "k",
|
|
150
|
+
spec_version: "1.3",
|
|
151
|
+
name: "TS E2E",
|
|
152
|
+
icon: "🧪",
|
|
153
|
+
description: "ts integration",
|
|
154
|
+
version: "1.3",
|
|
155
|
+
template_adapter: "default",
|
|
156
|
+
nodes: [
|
|
157
|
+
{
|
|
158
|
+
id: "entry",
|
|
159
|
+
type: "entry",
|
|
160
|
+
data: {
|
|
161
|
+
outputs: [{ identifier: "question", type: "str" }],
|
|
162
|
+
dataset: {
|
|
163
|
+
inline: {
|
|
164
|
+
records: { question: ["Reply with just the digit 4."] },
|
|
165
|
+
},
|
|
166
|
+
},
|
|
167
|
+
entry_selection: 0,
|
|
168
|
+
train_size: 1.0,
|
|
169
|
+
test_size: 0.0,
|
|
170
|
+
seed: 1,
|
|
171
|
+
},
|
|
172
|
+
},
|
|
173
|
+
{
|
|
174
|
+
id: "answer",
|
|
175
|
+
type: "signature",
|
|
176
|
+
data: {
|
|
177
|
+
name: "Answer",
|
|
178
|
+
parameters: [
|
|
179
|
+
{
|
|
180
|
+
identifier: "llm",
|
|
181
|
+
type: "llm",
|
|
182
|
+
value: {
|
|
183
|
+
model: "openai/gpt-5-mini",
|
|
184
|
+
litellm_params: { api_key: process.env.OPENAI_API_KEY },
|
|
185
|
+
},
|
|
186
|
+
},
|
|
187
|
+
],
|
|
188
|
+
inputs: [{ identifier: "question", type: "str" }],
|
|
189
|
+
outputs: [{ identifier: "answer", type: "str" }],
|
|
190
|
+
},
|
|
191
|
+
},
|
|
192
|
+
{
|
|
193
|
+
id: "end",
|
|
194
|
+
type: "end",
|
|
195
|
+
data: { inputs: [{ identifier: "answer", type: "str" }] },
|
|
196
|
+
},
|
|
197
|
+
],
|
|
198
|
+
edges: [
|
|
199
|
+
{
|
|
200
|
+
id: "e1",
|
|
201
|
+
source: "entry",
|
|
202
|
+
sourceHandle: "outputs.question",
|
|
203
|
+
target: "answer",
|
|
204
|
+
targetHandle: "inputs.question",
|
|
205
|
+
type: "default",
|
|
206
|
+
},
|
|
207
|
+
{
|
|
208
|
+
id: "e2",
|
|
209
|
+
source: "answer",
|
|
210
|
+
sourceHandle: "outputs.answer",
|
|
211
|
+
target: "end",
|
|
212
|
+
targetHandle: "inputs.answer",
|
|
213
|
+
type: "default",
|
|
214
|
+
},
|
|
215
|
+
],
|
|
216
|
+
state: {},
|
|
217
|
+
};
|
|
218
|
+
|
|
219
|
+
const event = {
|
|
220
|
+
type: "execute_flow",
|
|
221
|
+
payload: {
|
|
222
|
+
trace_id: "ts-e2e-trace",
|
|
223
|
+
workflow,
|
|
224
|
+
inputs: [{}],
|
|
225
|
+
origin: "workflow",
|
|
226
|
+
},
|
|
227
|
+
};
|
|
228
|
+
|
|
229
|
+
const res = await nlpgoFetch({
|
|
230
|
+
projectId: "test-project",
|
|
231
|
+
path: "/studio/execute_sync",
|
|
232
|
+
body: event,
|
|
233
|
+
origin: "workflow",
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
expect(res.ok).toBe(true);
|
|
237
|
+
expect(res.enginePath).toBe("go");
|
|
238
|
+
|
|
239
|
+
const body = (await res.json()) as {
|
|
240
|
+
status: string;
|
|
241
|
+
result?: { answer?: string };
|
|
242
|
+
error?: { message?: string };
|
|
243
|
+
};
|
|
244
|
+
expect(body.status, JSON.stringify(body.error)).toBe("success");
|
|
245
|
+
expect(body.result?.answer).toBeDefined();
|
|
246
|
+
expect(body.result?.answer).toContain("4");
|
|
247
|
+
}, 60_000);
|
|
248
|
+
});
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { featureFlagService } from "../featureFlag/featureFlag.service";
|
|
2
|
+
import { lambdaFetch } from "../../utils/lambdaFetch";
|
|
3
|
+
import { getProjectLambdaArn } from "../../optimization_studio/server/lambda";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Origin tag for the X-LangWatch-Origin header. Set at the request
|
|
7
|
+
* boundary by the call site so every span downstream (nlpgo + gateway)
|
|
8
|
+
* inherits a consistent attribution. See specs/nlp-go/telemetry.feature.
|
|
9
|
+
*/
|
|
10
|
+
export type NLPOrigin =
|
|
11
|
+
| "workflow"
|
|
12
|
+
| "playground"
|
|
13
|
+
| "evaluation"
|
|
14
|
+
| "scenario"
|
|
15
|
+
| "topic_clustering";
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* `release_nlp_go_engine_enabled` — gates whether traffic for a project
|
|
19
|
+
* routes through the new Go path (`/go/*`) or stays on the legacy Python
|
|
20
|
+
* path. Per-project rollout via PostHog. Topic clustering is intentionally
|
|
21
|
+
* NOT gated by this flag (it stays on Python regardless).
|
|
22
|
+
*/
|
|
23
|
+
const NLP_GO_FLAG = "release_nlp_go_engine_enabled";
|
|
24
|
+
|
|
25
|
+
export interface NLPGOFetchOptions<TBody = unknown> {
|
|
26
|
+
/** projectId is the distinct_id used for the per-project flag rollout. */
|
|
27
|
+
projectId: string;
|
|
28
|
+
/** Path under the NLP service, e.g. "/studio/execute_sync". The Go path
|
|
29
|
+
* prefix `/go` is added automatically when the flag is on. */
|
|
30
|
+
path: string;
|
|
31
|
+
/** Request body to JSON-stringify. */
|
|
32
|
+
body: TBody;
|
|
33
|
+
/** Tag the request as one of the canonical origins; sent as
|
|
34
|
+
* X-LangWatch-Origin so spans downstream are attributable. */
|
|
35
|
+
origin: NLPOrigin;
|
|
36
|
+
/** Optional organization scope for PostHog group targeting. */
|
|
37
|
+
organizationId?: string;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export interface NLPGOFetchResult<T> {
|
|
41
|
+
ok: boolean;
|
|
42
|
+
status: number;
|
|
43
|
+
statusText: string;
|
|
44
|
+
enginePath: "go" | "python";
|
|
45
|
+
json: () => Promise<T>;
|
|
46
|
+
text: () => Promise<string>;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Send a request to the langwatch_nlp service, choosing between the new
|
|
51
|
+
* Go engine path and the legacy Python path based on the
|
|
52
|
+
* `release_nlp_go_engine_enabled` feature flag (per-project).
|
|
53
|
+
*
|
|
54
|
+
* When the flag is on:
|
|
55
|
+
* - the path is rewritten with the `/go` prefix
|
|
56
|
+
* - X-LangWatch-Origin is added with the call site's origin
|
|
57
|
+
*
|
|
58
|
+
* When off: existing behavior — POST to the legacy Python handler.
|
|
59
|
+
* Bit-identical to today's traffic shape. There is no auth on this
|
|
60
|
+
* hop — TS app and nlpgo share the Lambda function URL boundary, the
|
|
61
|
+
* same posture today's Python NLP service uses.
|
|
62
|
+
*
|
|
63
|
+
* Topic clustering and other code paths that should stay on Python
|
|
64
|
+
* regardless MUST NOT call this helper — they should keep using
|
|
65
|
+
* `lambdaFetch` directly.
|
|
66
|
+
*/
|
|
67
|
+
export async function nlpgoFetch<T = unknown>(
|
|
68
|
+
opts: NLPGOFetchOptions,
|
|
69
|
+
): Promise<NLPGOFetchResult<T>> {
|
|
70
|
+
const goEnabled = await isNlpGoEnabled(opts);
|
|
71
|
+
const enginePath: "go" | "python" = goEnabled ? "go" : "python";
|
|
72
|
+
const finalPath = goEnabled ? "/go" + opts.path : opts.path;
|
|
73
|
+
const bodyStr = JSON.stringify(opts.body);
|
|
74
|
+
|
|
75
|
+
const headers: Record<string, string> = {
|
|
76
|
+
"Content-Type": "application/json",
|
|
77
|
+
"X-LangWatch-Origin": opts.origin,
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
const functionArn = process.env.LANGWATCH_NLP_LAMBDA_CONFIG
|
|
81
|
+
? await getProjectLambdaArn(opts.projectId)
|
|
82
|
+
: process.env.LANGWATCH_NLP_SERVICE!;
|
|
83
|
+
|
|
84
|
+
const response = await lambdaFetch<T>(functionArn, finalPath, {
|
|
85
|
+
method: "POST",
|
|
86
|
+
headers,
|
|
87
|
+
body: bodyStr,
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
return {
|
|
91
|
+
ok: response.ok,
|
|
92
|
+
status: response.status,
|
|
93
|
+
statusText: response.statusText,
|
|
94
|
+
enginePath,
|
|
95
|
+
json: response.json,
|
|
96
|
+
text: response.text,
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Public read-only check for whether a project would route to the Go
|
|
102
|
+
* engine. Used by:
|
|
103
|
+
* - the studio UI to hide the (now-defunct) Optimize button
|
|
104
|
+
* - the optimize REST endpoint to return 410
|
|
105
|
+
* - tRPC procedures that want to surface the engine choice to the UI
|
|
106
|
+
*/
|
|
107
|
+
export async function isNlpGoEnabled(
|
|
108
|
+
opts: Pick<NLPGOFetchOptions, "projectId" | "organizationId">,
|
|
109
|
+
): Promise<boolean> {
|
|
110
|
+
return featureFlagService.isEnabled(NLP_GO_FLAG, opts.projectId, false, {
|
|
111
|
+
projectId: opts.projectId,
|
|
112
|
+
organizationId: opts.organizationId,
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Return the OpenAI-compatible proxy base URL for the playground +
|
|
118
|
+
* modelProviders surface, gated on `release_nlp_go_engine_enabled`.
|
|
119
|
+
*
|
|
120
|
+
* - FF on → `${LANGWATCH_NLP_SERVICE}/go/proxy/v1` (Go playground proxy:
|
|
121
|
+
* dispatcher in-process, real AI Gateway, no LiteLLM)
|
|
122
|
+
* - FF off → `${LANGWATCH_NLP_SERVICE}/proxy/v1` (legacy LiteLLM proxy
|
|
123
|
+
* on the uvicorn child)
|
|
124
|
+
*
|
|
125
|
+
* On the wire shape stays bit-identical: x-litellm-* credential headers
|
|
126
|
+
* + OpenAI-shape body. The Go side parses x-litellm-* via gatewayproxy/
|
|
127
|
+
* headers.go and forwards to the gateway dispatcher; the Python side
|
|
128
|
+
* keeps doing whatever LiteLLM does today. Customers don't see a
|
|
129
|
+
* difference unless they've opted into the Go path.
|
|
130
|
+
*/
|
|
131
|
+
export async function nlpgoProxyBaseURL(opts: {
|
|
132
|
+
projectId: string;
|
|
133
|
+
baseURL: string;
|
|
134
|
+
organizationId?: string;
|
|
135
|
+
}): Promise<string> {
|
|
136
|
+
const goEnabled = await isNlpGoEnabled({
|
|
137
|
+
projectId: opts.projectId,
|
|
138
|
+
organizationId: opts.organizationId,
|
|
139
|
+
});
|
|
140
|
+
const trimmed = opts.baseURL.replace(/\/$/, "");
|
|
141
|
+
return goEnabled ? `${trimmed}/go/proxy/v1` : `${trimmed}/proxy/v1`;
|
|
142
|
+
}
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @vitest-environment node
|
|
3
|
+
*
|
|
4
|
+
* Live OpenAI-shape chat completion through the new
|
|
5
|
+
* /go/proxy/v1/chat/completions endpoint. Spawns nlpgo as a subprocess,
|
|
6
|
+
* POSTs an OpenAI-style request with x-litellm-* credential headers
|
|
7
|
+
* (the same shape playground.ts + getVercelAIModel build today), asserts
|
|
8
|
+
* the upstream response decodes as a real OpenAI completion with
|
|
9
|
+
* non-empty assistant content.
|
|
10
|
+
*
|
|
11
|
+
* Why this test exists:
|
|
12
|
+
* The playground proxy chain landed in three commits across iter 18+:
|
|
13
|
+
* 1. 3570dc12c — gatewayproxy/headers.go (header → Credential map)
|
|
14
|
+
* 2. 89dd7e4b9 — handler + dispatcher wiring
|
|
15
|
+
* 3. 6564c7dfc — TS callsite flag-gating
|
|
16
|
+
* Without an end-to-end test, a regression in any of those layers
|
|
17
|
+
* wouldn't surface until customer playground traffic hit it. This
|
|
18
|
+
* test pins the whole chain at the wire level — same shape the TS
|
|
19
|
+
* app actually sends (x-litellm-* headers, OpenAI body).
|
|
20
|
+
*
|
|
21
|
+
* Skipped (not failed) when:
|
|
22
|
+
* - OPENAI_API_KEY not set
|
|
23
|
+
* - go binary not on PATH
|
|
24
|
+
*
|
|
25
|
+
* Run cost: ~3-5s per invocation + ~3s subprocess startup.
|
|
26
|
+
*/
|
|
27
|
+
import { spawn, type ChildProcess } from "node:child_process";
|
|
28
|
+
import { setTimeout as sleep } from "node:timers/promises";
|
|
29
|
+
import path from "node:path";
|
|
30
|
+
|
|
31
|
+
import { afterAll, beforeAll, describe, expect, it } from "vitest";
|
|
32
|
+
|
|
33
|
+
// Port choice: 55620 (one extra zero on the standard nlpgo :5562) so the
|
|
34
|
+
// test doesn't collide with any worktree running langwatch on PORT=5570
|
|
35
|
+
// (which would put aigateway on :5573 by the +N*10 convention). High
|
|
36
|
+
// enough not to clash with any normal dev server or another test slot.
|
|
37
|
+
const NLPGO_PORT = 55620;
|
|
38
|
+
const REPO_ROOT = path.resolve(__dirname, "../../../../../..");
|
|
39
|
+
|
|
40
|
+
let nlpgoProcess: ChildProcess | null = null;
|
|
41
|
+
|
|
42
|
+
async function waitForHealth(timeoutMs = 30_000): Promise<void> {
|
|
43
|
+
const deadline = Date.now() + timeoutMs;
|
|
44
|
+
while (Date.now() < deadline) {
|
|
45
|
+
try {
|
|
46
|
+
const r = await fetch(`http://127.0.0.1:${NLPGO_PORT}/healthz`);
|
|
47
|
+
if (r.status === 200 || r.status === 503) return;
|
|
48
|
+
} catch {
|
|
49
|
+
// not ready yet
|
|
50
|
+
}
|
|
51
|
+
await sleep(250);
|
|
52
|
+
}
|
|
53
|
+
throw new Error(`nlpgo did not become healthy within ${timeoutMs}ms`);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
beforeAll(async () => {
|
|
57
|
+
if (!process.env.OPENAI_API_KEY) return;
|
|
58
|
+
|
|
59
|
+
// detached:true so afterAll's process.kill(-pid) reaches the
|
|
60
|
+
// compiled child of `go run`, not just the toolchain wrapper.
|
|
61
|
+
// See post-event.integration.test.ts for the full rationale.
|
|
62
|
+
nlpgoProcess = spawn("go", ["run", "./cmd/service", "nlpgo"], {
|
|
63
|
+
cwd: REPO_ROOT,
|
|
64
|
+
env: {
|
|
65
|
+
...process.env,
|
|
66
|
+
NLPGO_CHILD_BYPASS: "true",
|
|
67
|
+
SERVER_ADDR: `:${NLPGO_PORT}`,
|
|
68
|
+
},
|
|
69
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
70
|
+
detached: true,
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
nlpgoProcess.stderr?.on("data", (chunk: Buffer) => {
|
|
74
|
+
if (process.env.NLPGO_TEST_LOG === "1") {
|
|
75
|
+
process.stderr.write(`[nlpgo] ${chunk.toString()}`);
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
nlpgoProcess.on("exit", (code, signal) => {
|
|
79
|
+
if (code !== 0 && code !== null) {
|
|
80
|
+
console.error(`nlpgo exited unexpectedly: code=${code} signal=${signal}`);
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
await waitForHealth();
|
|
85
|
+
}, 90_000);
|
|
86
|
+
|
|
87
|
+
afterAll(async () => {
|
|
88
|
+
if (!nlpgoProcess?.pid) return;
|
|
89
|
+
const pgid = -nlpgoProcess.pid;
|
|
90
|
+
try {
|
|
91
|
+
process.kill(pgid, "SIGTERM");
|
|
92
|
+
} catch {
|
|
93
|
+
// group already gone
|
|
94
|
+
}
|
|
95
|
+
const exited = await Promise.race([
|
|
96
|
+
new Promise<boolean>((resolve) =>
|
|
97
|
+
nlpgoProcess!.once("exit", () => resolve(true)),
|
|
98
|
+
),
|
|
99
|
+
sleep(2000).then(() => false),
|
|
100
|
+
]);
|
|
101
|
+
if (!exited) {
|
|
102
|
+
try {
|
|
103
|
+
process.kill(pgid, "SIGKILL");
|
|
104
|
+
} catch {
|
|
105
|
+
// best-effort
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
const liveOpenAI = process.env.OPENAI_API_KEY ? it : it.skip;
|
|
111
|
+
|
|
112
|
+
describe("playground proxy /go/proxy/v1/chat/completions", () => {
|
|
113
|
+
liveOpenAI(
|
|
114
|
+
"non-streaming OpenAI chat completion routes through nlpgo and returns assistant content",
|
|
115
|
+
async () => {
|
|
116
|
+
const url = `http://127.0.0.1:${NLPGO_PORT}/go/proxy/v1/chat/completions`;
|
|
117
|
+
const body = {
|
|
118
|
+
model: "openai/gpt-5-mini",
|
|
119
|
+
messages: [
|
|
120
|
+
{
|
|
121
|
+
role: "user" as const,
|
|
122
|
+
content: "Reply with the single digit '4' and nothing else.",
|
|
123
|
+
},
|
|
124
|
+
],
|
|
125
|
+
temperature: 0,
|
|
126
|
+
max_tokens: 16,
|
|
127
|
+
};
|
|
128
|
+
const resp = await fetch(url, {
|
|
129
|
+
method: "POST",
|
|
130
|
+
headers: {
|
|
131
|
+
"Content-Type": "application/json",
|
|
132
|
+
"x-litellm-model": "openai/gpt-5-mini",
|
|
133
|
+
"x-litellm-api_key": process.env.OPENAI_API_KEY!,
|
|
134
|
+
},
|
|
135
|
+
body: JSON.stringify(body),
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
expect(resp.status).toBe(200);
|
|
139
|
+
const json = (await resp.json()) as {
|
|
140
|
+
id?: string;
|
|
141
|
+
choices?: Array<{
|
|
142
|
+
message?: { role?: string; content?: string };
|
|
143
|
+
}>;
|
|
144
|
+
usage?: { total_tokens?: number };
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
// OpenAI completion shape — id, choices array, message with content.
|
|
148
|
+
expect(typeof json.id).toBe("string");
|
|
149
|
+
expect(Array.isArray(json.choices)).toBe(true);
|
|
150
|
+
expect(json.choices?.length ?? 0).toBeGreaterThan(0);
|
|
151
|
+
const content = json.choices?.[0]?.message?.content ?? "";
|
|
152
|
+
expect(content.length).toBeGreaterThan(0);
|
|
153
|
+
// Loose containment so model variations don't flake the test.
|
|
154
|
+
expect(content).toContain("4");
|
|
155
|
+
},
|
|
156
|
+
30_000,
|
|
157
|
+
);
|
|
158
|
+
|
|
159
|
+
liveOpenAI(
|
|
160
|
+
"streaming OpenAI chat completion delivers SSE deltas terminated by [DONE]",
|
|
161
|
+
async () => {
|
|
162
|
+
const url = `http://127.0.0.1:${NLPGO_PORT}/go/proxy/v1/chat/completions`;
|
|
163
|
+
const body = {
|
|
164
|
+
model: "openai/gpt-5-mini",
|
|
165
|
+
messages: [
|
|
166
|
+
{ role: "user" as const, content: "Say 'hi' in one word." },
|
|
167
|
+
],
|
|
168
|
+
temperature: 0,
|
|
169
|
+
max_tokens: 8,
|
|
170
|
+
stream: true,
|
|
171
|
+
};
|
|
172
|
+
const resp = await fetch(url, {
|
|
173
|
+
method: "POST",
|
|
174
|
+
headers: {
|
|
175
|
+
"Content-Type": "application/json",
|
|
176
|
+
"x-litellm-model": "openai/gpt-5-mini",
|
|
177
|
+
"x-litellm-api_key": process.env.OPENAI_API_KEY!,
|
|
178
|
+
},
|
|
179
|
+
body: JSON.stringify(body),
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
expect(resp.status).toBe(200);
|
|
183
|
+
const ct = resp.headers.get("content-type") ?? "";
|
|
184
|
+
expect(ct).toContain("text/event-stream");
|
|
185
|
+
|
|
186
|
+
// Drain the SSE stream and collect data: frames.
|
|
187
|
+
const reader = resp.body!.getReader();
|
|
188
|
+
const decoder = new TextDecoder();
|
|
189
|
+
let buffer = "";
|
|
190
|
+
const dataFrames: string[] = [];
|
|
191
|
+
while (true) {
|
|
192
|
+
const { value, done } = await reader.read();
|
|
193
|
+
if (done) break;
|
|
194
|
+
buffer += decoder.decode(value, { stream: true });
|
|
195
|
+
const lines = buffer.split("\n");
|
|
196
|
+
buffer = lines.pop() ?? "";
|
|
197
|
+
for (const line of lines) {
|
|
198
|
+
if (line.startsWith("data: ")) {
|
|
199
|
+
dataFrames.push(line.slice(6).trim());
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
expect(dataFrames.length).toBeGreaterThan(1);
|
|
205
|
+
// The OpenAI streaming protocol terminates with a literal [DONE]
|
|
206
|
+
// sentinel; the playground reducer relies on it to close the bubble.
|
|
207
|
+
expect(dataFrames[dataFrames.length - 1]).toBe("[DONE]");
|
|
208
|
+
// Some frames must carry actual delta content (not all blank).
|
|
209
|
+
const hasContent = dataFrames.some((f) => {
|
|
210
|
+
if (f === "[DONE]") return false;
|
|
211
|
+
try {
|
|
212
|
+
const parsed = JSON.parse(f) as {
|
|
213
|
+
choices?: Array<{ delta?: { content?: string } }>;
|
|
214
|
+
};
|
|
215
|
+
return Boolean(parsed.choices?.[0]?.delta?.content);
|
|
216
|
+
} catch {
|
|
217
|
+
return false;
|
|
218
|
+
}
|
|
219
|
+
});
|
|
220
|
+
expect(hasContent).toBe(true);
|
|
221
|
+
},
|
|
222
|
+
30_000,
|
|
223
|
+
);
|
|
224
|
+
|
|
225
|
+
liveOpenAI(
|
|
226
|
+
"missing provider header returns 400 without touching upstream",
|
|
227
|
+
async () => {
|
|
228
|
+
const url = `http://127.0.0.1:${NLPGO_PORT}/go/proxy/v1/chat/completions`;
|
|
229
|
+
const resp = await fetch(url, {
|
|
230
|
+
method: "POST",
|
|
231
|
+
headers: { "Content-Type": "application/json" },
|
|
232
|
+
// No x-litellm-* headers and no provider prefix in body.model.
|
|
233
|
+
body: JSON.stringify({
|
|
234
|
+
model: "gpt-5-mini",
|
|
235
|
+
messages: [{ role: "user", content: "hi" }],
|
|
236
|
+
}),
|
|
237
|
+
});
|
|
238
|
+
expect(resp.status).toBe(400);
|
|
239
|
+
},
|
|
240
|
+
10_000,
|
|
241
|
+
);
|
|
242
|
+
});
|
|
@@ -13,6 +13,7 @@ import { loggerMiddleware } from "~/app/api/middleware/logger";
|
|
|
13
13
|
import { tracerMiddleware } from "~/app/api/middleware/tracer";
|
|
14
14
|
import { env } from "~/env.mjs";
|
|
15
15
|
import { hasProjectPermission } from "~/server/api/rbac";
|
|
16
|
+
import { nlpgoProxyBaseURL } from "~/server/nlpgo/nlpgoFetch";
|
|
16
17
|
import {
|
|
17
18
|
getProjectModelProviders,
|
|
18
19
|
prepareLitellmParams,
|
|
@@ -105,9 +106,18 @@ app.post("/playground", async (c) => {
|
|
|
105
106
|
]),
|
|
106
107
|
);
|
|
107
108
|
|
|
109
|
+
// FF-gated proxy: when release_nlp_go_engine_enabled is on for this
|
|
110
|
+
// project, route through nlpgo's /go/proxy/v1/* (in-process AI Gateway,
|
|
111
|
+
// no LiteLLM); otherwise stay on the legacy /proxy/v1/* (Python LiteLLM
|
|
112
|
+
// proxy). Wire shape (x-litellm-* headers + OpenAI body) is identical
|
|
113
|
+
// either way.
|
|
114
|
+
const baseURL = await nlpgoProxyBaseURL({
|
|
115
|
+
projectId,
|
|
116
|
+
baseURL: env.LANGWATCH_NLP_SERVICE,
|
|
117
|
+
});
|
|
108
118
|
const vercelProvider = createOpenAI({
|
|
109
119
|
apiKey: litellmParams.api_key,
|
|
110
|
-
baseURL
|
|
120
|
+
baseURL,
|
|
111
121
|
headers,
|
|
112
122
|
});
|
|
113
123
|
|
|
@@ -18,6 +18,7 @@ import { loggerMiddleware } from "~/app/api/middleware/logger";
|
|
|
18
18
|
import { tracerMiddleware } from "~/app/api/middleware/tracer";
|
|
19
19
|
import { addEnvs } from "~/optimization_studio/server/addEnvs";
|
|
20
20
|
import { loadDatasets } from "~/optimization_studio/server/loadDatasets";
|
|
21
|
+
import { isNlpGoEnabled } from "~/server/nlpgo/nlpgoFetch";
|
|
21
22
|
import {
|
|
22
23
|
type StudioClientEvent,
|
|
23
24
|
type StudioServerEvent,
|
|
@@ -163,6 +164,22 @@ app.post(
|
|
|
163
164
|
);
|
|
164
165
|
}
|
|
165
166
|
|
|
167
|
+
// Optimization is DSPy-only; the Go engine intentionally drops it.
|
|
168
|
+
// Stop events still pass so a previously-started run can be cancelled.
|
|
169
|
+
if (message.type === "execute_optimization") {
|
|
170
|
+
const goEnabled = await isNlpGoEnabled({ projectId });
|
|
171
|
+
if (goEnabled) {
|
|
172
|
+
return c.json(
|
|
173
|
+
{
|
|
174
|
+
type: "optimize_disabled",
|
|
175
|
+
message:
|
|
176
|
+
"Optimization is no longer supported on the Go engine. The Optimize feature relied on DSPy, which has been removed.",
|
|
177
|
+
},
|
|
178
|
+
{ status: 410 },
|
|
179
|
+
);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
166
183
|
return streamSSE(c, async (stream) => {
|
|
167
184
|
let resolved = false;
|
|
168
185
|
const streamDone = new Promise<void>((resolve) => {
|