@memberjunction/ai-heygen 6.2.0-edge.4 → 6.2.0-edge.6

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.
@@ -1,4 +1,4 @@
1
1
 
2
- > @memberjunction/ai-heygen@6.2.0-edge.4 build /home/runner/work/MJ/MJ/packages/AI/Providers/HeyGen
2
+ > @memberjunction/ai-heygen@6.2.0-edge.6 build /home/runner/work/MJ/MJ/packages/AI/Providers/HeyGen
3
3
  > tsc && tsc-alias -f
4
4
 
package/CHANGELOG.md CHANGED
@@ -1,5 +1,62 @@
1
1
  # @memberjunction/ai-heygen
2
2
 
3
+ ## 6.2.0-edge.6
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [4c6a28b]
8
+ - Updated dependencies [709de1a]
9
+ - Updated dependencies [1090caa]
10
+ - Updated dependencies [914e6ff]
11
+ - Updated dependencies [1141164]
12
+ - Updated dependencies [6a5fb64]
13
+ - Updated dependencies [0e93e1f]
14
+ - Updated dependencies [c4645bc]
15
+ - Updated dependencies [5b41d48]
16
+ - @memberjunction/ai@6.2.0-edge.6
17
+ - @memberjunction/global@6.2.0-edge.6
18
+ - @memberjunction/network-utils@6.2.0-edge.6
19
+
20
+ ## 6.2.0-edge.5
21
+
22
+ ### Patch Changes
23
+
24
+ - 4e4c82d: A cancelled model call now stops where it is: it is never failed over or retried, a call cancelled in flight is reported as `Cancelled` (a non-chat call cancelled before it starts is refused before a run row exists), and the cancellation reaches the vendor's SDK so the request is torn down rather than abandoned (#5548, #3132).
25
+
26
+ **Prompts and agents (#5548)**
27
+ - **No failover walk after a cancel.** `ExecuteWithFailover` stops before each candidate once the caller's token is aborted, and after any attempt that fails while it is aborted or that reports a cancellation. Before, one abort walked every model candidate (113 real driver calls in a live test) and logged an `[ERROR] [ModelExecution]` with a stack trace for each. Real failures before the cancel are still recorded as failover attempts. A timeout is not a cancellation and still fails over.
28
+ - **Logged once, recorded as cancelled.** One info line instead of an error per candidate. The prompt run is saved `Cancelled` / `user_requested`, and the `AIPromptRunResult` carries `status: 'Cancelled'` and `cancelled: true`.
29
+ - **Agent runs end Cancelled.** `BaseAgent` checks the token before treating a failed prompt as a failure, and before counting a failed step toward the consecutive-failure limit, so a run cancelled mid-prompt no longer ends `Failed`. A final answer that had already finished when Stop landed still completes the run.
30
+ - **Failover fields persist.** A prompt run's `FailoverAttempts`, `FailoverErrors`, `FailoverDurations`, `TotalFailoverDuration` and failed-over `ModelID` / `VendorID` were written while its `Running` INSERT could still be in flight, and the INSERT's reload reset them, so a run that failed over could be saved with `FailoverAttempts = 0`. They are now set again in the queued finalize update, after the reload. This affected every runner, not only cancellation.
31
+
32
+ **Cancellation in `@memberjunction/ai` (#3132)**
33
+ - **`AIErrorType` has `'Cancelled'`**: Fatal and never failed over. `ErrorAnalyzer` on its own classifies an error named `AbortError`, `APIUserAbortError` or `RequestAbortedError` as `Cancelled`. The signal-aware helpers that `BaseLLM`, `BaseDecision` and every runner use (`BuildCancellationErrorInfo`) decide by why the signal was aborted, so an abort caused by a timeout stays a retriable `NetworkError`. A timeout is recognized by the abort reason's type — a `TimeoutError`, or a reason flagged `IsTimeout` (new `TimeoutAbortReason`; `AIPromptTimeoutError` sets it) — never by the words of a caller's reason.
34
+ - **Shared helpers** (exported): `IsAbortError`, `IsTimeoutAbort`, `IsRequestAborted`, `BuildCancellationErrorInfo`, `IsCancellationErrorInfo`, `DescribeCancellation`, `CreateCancellationError`, `ThrowIfAborted`, `AbortableDelay`, and the `REQUEST_CANCELLED_CODE` / `REQUEST_TIMEOUT_CODE` codes.
35
+ - **`BaseLLM` owns chat cancellation, per request.** It answers an already-aborted request without calling the driver, turns an abort (thrown, or a failed result while the signal is aborted) into one cancelled result, and decides a streaming cancellation from the request's own signal, so drivers no longer keep cancellation state on a shared instance. New protected `BuildCancelledChatResult`, `IsCancellationError` and the `IsProviderAbortError` hook. A pre-aborted streaming request now resolves cancelled on every driver instead of rejecting with a generic error.
36
+ - **Every chat driver uses it.** The duplicated cancelled-result builders, predicates and stream-cancel flags are gone from Anthropic, Azure, Bedrock, Betty, BettyBot, Cerebras, Fireworks, Gemini (and Vertex), Groq, Inception, LMStudio, Mistral, Ollama and OpenAI (and its subclasses). Anthropic, Bedrock, Gemini, Mistral and Ollama used to report a cancel as a retriable `Unknown` error. Cancel messages now read "Request was cancelled[: reason]".
37
+ - **Bedrock streaming** iterated the response envelope instead of its body, so every streaming call failed with "stream is not async iterable". Fixed.
38
+ - `BaseDecision` and the decision runner classify an aborted decision by its signal, so a timeout fails over and a cancel does not.
39
+
40
+ **Non-chat models**
41
+ - **Media** (text-to-speech, speech-to-text, video): the driver params carry `CancellationToken`, the runner passes the call's bound signal, and the OpenAI, Groq, ElevenLabs and HeyGen drivers forward it. `MediaOperation.Invoke` takes the signal as a third argument.
42
+ - **Embeddings, rerank and image generation** gain timeout and cancellation: `TimeoutMS` / `CancellationToken` on their run options, a pre-aborted run refused before a run row exists, a cancelled run recorded `Cancelled` and not failed over, and a timeout failed over. The param types gain `CancellationToken`, and the OpenAI, Azure, Bedrock, Cohere, Gemini, Mistral, Ollama and local embedding drivers, the Cohere, LLM and decision rerankers, and the OpenAI, Gemini and FLUX image drivers forward it. A cancelled `BaseEmbeddings.EmbedTexts` now throws a cancellation error instead of returning an empty result. The local embedding model can only stop between texts or batches.
43
+
44
+ **Testing**
45
+ - `TestLLM` gains a `hangUntilAborted` outcome. The LLM conformance suite drops `PreAbortedStreamingBehavior`: every driver must resolve a pre-aborted request as `Cancelled`.
46
+ - New integration bundle **IT122 - Agent Prompt Cancellation**: a real agent run cancelled mid-call stops at that call and is recorded cancelled throughout.
47
+
48
+ - Updated dependencies [0d81c53]
49
+ - Updated dependencies [3080e83]
50
+ - Updated dependencies [81aea34]
51
+ - Updated dependencies [2274f42]
52
+ - Updated dependencies [230cdad]
53
+ - Updated dependencies [4e4c82d]
54
+ - Updated dependencies [72dd65c]
55
+ - Updated dependencies [17a4137]
56
+ - @memberjunction/ai@6.2.0-edge.5
57
+ - @memberjunction/global@6.2.0-edge.5
58
+ - @memberjunction/network-utils@6.2.0-edge.5
59
+
3
60
  ## 6.2.0-edge.4
4
61
 
5
62
  ### Patch Changes
package/dist/index.d.ts CHANGED
@@ -3,12 +3,18 @@ export declare class HeyGenVideoGenerator extends BaseVideoGenerator {
3
3
  private _generateUrl;
4
4
  private _avatarsUrl;
5
5
  constructor(apiKey: string);
6
+ /**
7
+ * Requests an avatar video. `params.CancellationToken` is passed to the request, so aborting it
8
+ * tears the request down; the failure is then classified as a cancellation.
9
+ */
6
10
  CreateAvatarVideo(params: AvatarVideoParams): Promise<VideoResult>;
7
11
  /**
8
12
  * Classifies a failed request. `HttpError` carries the response's status as `Status`, which
9
13
  * `ErrorAnalyzer` does not read, so the analyzer is given the status, and the `retry-after`
10
14
  * header, under the names it reads. The original error stays on the result. A request that got
11
- * no response (status 0: a timeout or a network failure) is classified from its message.
15
+ * no response (status 0: a timeout or a network failure) is classified from its message. A
16
+ * request ended by its `CancellationToken` is a cancellation, never failed over, or a network
17
+ * error when the signal was aborted by a timeout.
12
18
  */
13
19
  private classifyError;
14
20
  CreateVideoTranslation(params: any): Promise<VideoResult>;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAe,UAAU,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,WAAW,EAAiB,MAAM,oBAAoB,CAAC;AAsBhI,qBACa,oBAAqB,SAAQ,kBAAkB;IACxD,OAAO,CAAC,YAAY,CAAsD;IAC1E,OAAO,CAAC,WAAW,CAA+C;gBAEtD,MAAM,EAAE,MAAM;IAIb,iBAAiB,CAAC,MAAM,EAAE,iBAAiB,GAAG,OAAO,CAAC,WAAW,CAAC;IAgD/E;;;;;OAKG;IACH,OAAO,CAAC,aAAa;IAQR,sBAAsB,CAAC,MAAM,EAAE,GAAG,GAAG,OAAO,CAAC,WAAW,CAAC;IAIzD,UAAU,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC;IAsBnC,mBAAmB,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;CAGxD"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAe,UAAU,EAAE,iBAAiB,EAAE,kBAAkB,EAAgD,WAAW,EAAiB,MAAM,oBAAoB,CAAC;AAsB9K,qBACa,oBAAqB,SAAQ,kBAAkB;IACxD,OAAO,CAAC,YAAY,CAAsD;IAC1E,OAAO,CAAC,WAAW,CAA+C;gBAEtD,MAAM,EAAE,MAAM;IAI1B;;;OAGG;IACU,iBAAiB,CAAC,MAAM,EAAE,iBAAiB,GAAG,OAAO,CAAC,WAAW,CAAC;IAiD/E;;;;;;;OAOG;IACH,OAAO,CAAC,aAAa;IAWR,sBAAsB,CAAC,MAAM,EAAE,GAAG,GAAG,OAAO,CAAC,WAAW,CAAC;IAIzD,UAAU,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC;IAsBnC,mBAAmB,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;CAGxD"}
package/dist/index.js CHANGED
@@ -8,7 +8,7 @@ var __metadata = (this && this.__metadata) || function (k, v) {
8
8
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
9
  };
10
10
  import { RegisterClass } from "@memberjunction/global";
11
- import { AvatarInfo, BaseVideoGenerator, VideoResult, ErrorAnalyzer } from "@memberjunction/ai";
11
+ import { AvatarInfo, BaseVideoGenerator, BuildCancellationErrorInfo, IsRequestAborted, VideoResult, ErrorAnalyzer } from "@memberjunction/ai";
12
12
  import { HttpGet, HttpPost, IsHttpError } from "@memberjunction/network-utils";
13
13
  let HeyGenVideoGenerator = class HeyGenVideoGenerator extends BaseVideoGenerator {
14
14
  constructor(apiKey) {
@@ -16,6 +16,10 @@ let HeyGenVideoGenerator = class HeyGenVideoGenerator extends BaseVideoGenerator
16
16
  this._generateUrl = "https://api.heygen.com/v2/video/generate";
17
17
  this._avatarsUrl = "https://api.heygen.com/v2/avatars";
18
18
  }
19
+ /**
20
+ * Requests an avatar video. `params.CancellationToken` is passed to the request, so aborting it
21
+ * tears the request down; the failure is then classified as a cancellation.
22
+ */
19
23
  async CreateAvatarVideo(params) {
20
24
  const videoResult = new VideoResult();
21
25
  try {
@@ -44,13 +48,14 @@ let HeyGenVideoGenerator = class HeyGenVideoGenerator extends BaseVideoGenerator
44
48
  height: params.outputHeight,
45
49
  }
46
50
  }, {
47
- Headers: { Accept: 'application/json', 'X-Api-Key': this.apiKey }
51
+ Headers: { Accept: 'application/json', 'X-Api-Key': this.apiKey },
52
+ Signal: params.CancellationToken,
48
53
  });
49
54
  videoResult.videoId = response.Data.data.video_id;
50
55
  videoResult.success = true;
51
56
  }
52
57
  catch (error) {
53
- const errorInfo = this.classifyError(error);
58
+ const errorInfo = this.classifyError(error, params.CancellationToken);
54
59
  videoResult.success = false;
55
60
  videoResult.errorMessage = error?.message || 'Unknown error occurred';
56
61
  // Kept so a caller can tell a rejected request (a 400) from an outage: the message,
@@ -64,9 +69,14 @@ let HeyGenVideoGenerator = class HeyGenVideoGenerator extends BaseVideoGenerator
64
69
  * Classifies a failed request. `HttpError` carries the response's status as `Status`, which
65
70
  * `ErrorAnalyzer` does not read, so the analyzer is given the status, and the `retry-after`
66
71
  * header, under the names it reads. The original error stays on the result. A request that got
67
- * no response (status 0: a timeout or a network failure) is classified from its message.
72
+ * no response (status 0: a timeout or a network failure) is classified from its message. A
73
+ * request ended by its `CancellationToken` is a cancellation, never failed over, or a network
74
+ * error when the signal was aborted by a timeout.
68
75
  */
69
- classifyError(error) {
76
+ classifyError(error, signal) {
77
+ if (IsRequestAborted(error, signal) || (IsHttpError(error) && error.IsCancelled)) {
78
+ return BuildCancellationErrorInfo({ error, signal, provider: 'HeyGen' });
79
+ }
70
80
  if (IsHttpError(error) && error.Status > 0) {
71
81
  const withStatus = { name: error.name, message: error.message, status: error.Status, headers: error.Headers };
72
82
  return { ...ErrorAnalyzer.AnalyzeError(withStatus, 'HeyGen'), error };
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,EAAe,UAAU,EAAqB,kBAAkB,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAChI,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAC;AAsBxE,IAAM,oBAAoB,GAA1B,MAAM,oBAAqB,SAAQ,kBAAkB;IAIxD,YAAY,MAAc;QACtB,KAAK,CAAC,MAAM,CAAC,CAAC;QAJV,iBAAY,GAAW,0CAA0C,CAAC;QAClE,gBAAW,GAAW,mCAAmC,CAAC;IAIlE,CAAC;IAEM,KAAK,CAAC,iBAAiB,CAAC,MAAyB;QACpD,MAAM,WAAW,GAAG,IAAI,WAAW,EAAE,CAAC;QACtC,IAAI,CAAC;YACD,MAAM,QAAQ,GAAG,MAAM,QAAQ,CAC3B,IAAI,CAAC,YAAY,EAAE;gBACf,YAAY,EAAE;oBACV;wBACI,SAAS,EAAE;4BACP,IAAI,EAAE,QAAQ;4BACd,SAAS,EAAE,MAAM,CAAC,QAAQ;4BAC1B,KAAK,EAAE,MAAM,CAAC,KAAK;4BACnB,YAAY,EAAE,MAAM,CAAC,WAAW;4BAChC,MAAM,EAAE,EAAC,CAAC,EAAE,MAAM,CAAC,OAAO,EAAE,CAAC,EAAE,MAAM,CAAC,OAAO,EAAC;yBACjD;wBACD,KAAK,EAAE;4BACH,IAAI,EAAE,OAAO;4BACb,cAAc,EAAE,MAAM,CAAC,YAAY;yBACtC;wBACD,UAAU,EAAE;4BACR,IAAI,EAAE,OAAO;4BACb,cAAc,EAAE,MAAM,CAAC,YAAY;yBACtC;qBACJ;iBACJ;gBACD,SAAS,EAAE;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,EAAE,QAAQ,CAAC,CAAC;YAC9D,OAAO,CAAC,KAAK,CAAC,0BAA0B,EAAE,SAAS,CAAC,CAAC;QACzD,CAAC;QACD,OAAO,MAAM,CAAC;IAClB,CAAC;IAEM,KAAK,CAAC,mBAAmB;QAC5B,OAAO,CAAC,mBAAmB,EAAE,wBAAwB,EAAE,YAAY,CAAC,CAAC;IACzE,CAAC;CACJ,CAAA;AA7GY,oBAAoB;IADhC,aAAa,CAAC,kBAAkB,EAAE,sBAAsB,CAAC;;GAC7C,oBAAoB,CA6GhC"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@memberjunction/ai-heygen",
3
3
  "type": "module",
4
- "version": "6.2.0-edge.4",
4
+ "version": "6.2.0-edge.6",
5
5
  "description": "MemberJunction Wrapper for HeyGen Video Generation",
6
6
  "main": "dist/index.js",
7
7
  "author": "MemberJunction.com",
@@ -12,9 +12,9 @@
12
12
  },
13
13
  "dependencies": {
14
14
  "@elevenlabs/elevenlabs-js": "^2.34.0",
15
- "@memberjunction/ai": "6.2.0-edge.4",
16
- "@memberjunction/global": "6.2.0-edge.4",
17
- "@memberjunction/network-utils": "6.2.0-edge.4"
15
+ "@memberjunction/ai": "6.2.0-edge.6",
16
+ "@memberjunction/global": "6.2.0-edge.6",
17
+ "@memberjunction/network-utils": "6.2.0-edge.6"
18
18
  },
19
19
  "repository": {
20
20
  "type": "git",
@@ -89,3 +89,25 @@ describe('HeyGenVideoGenerator error classification', () => {
89
89
  expect(result.errorInfo).toMatchObject({ errorType: 'NetworkError', canFailover: true });
90
90
  });
91
91
  });
92
+
93
+ describe('HeyGenVideoGenerator cancellation', () => {
94
+ beforeEach(() => {
95
+ mockHttpPost.mockReset();
96
+ vi.spyOn(console, 'error').mockImplementation(() => undefined);
97
+ });
98
+
99
+ it('passes the CancellationToken to the request, and reports its abort as Cancelled', async () => {
100
+ const controller = new AbortController();
101
+ mockHttpPost.mockImplementationOnce((_url: string, _body: object, config?: { Signal?: AbortSignal }) => new Promise<never>((_resolve, reject) => {
102
+ config?.Signal?.addEventListener('abort', () => reject(new HttpError('Request was cancelled', { Url: GENERATE_URL, Method: 'POST', IsCancelled: true })), { once: true });
103
+ }));
104
+
105
+ const pending = new HeyGenVideoGenerator('test-key').CreateAvatarVideo({ ...params(), CancellationToken: controller.signal });
106
+ controller.abort();
107
+ const result = await pending;
108
+
109
+ expect(mockHttpPost.mock.calls[0][2]).toMatchObject({ Signal: controller.signal });
110
+ expect(result.success).toBe(false);
111
+ expect(result.errorInfo).toMatchObject({ errorType: 'Cancelled', severity: 'Fatal', canFailover: false });
112
+ });
113
+ });
@@ -44,6 +44,8 @@ vi.mock('@memberjunction/ai', () => {
44
44
  analyzeError: vi.fn().mockReturnValue({ category: 'unknown' }),
45
45
  AnalyzeError: vi.fn().mockReturnValue({ category: 'unknown' }),
46
46
  },
47
+ IsRequestAborted: (_error: unknown, signal?: AbortSignal) => signal?.aborted === true,
48
+ BuildCancellationErrorInfo: vi.fn().mockReturnValue({ errorType: 'Cancelled' }),
47
49
  };
48
50
  });
49
51
 
package/src/index.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { RegisterClass } from "@memberjunction/global";
2
- import { AIErrorInfo, AvatarInfo, AvatarVideoParams, BaseVideoGenerator, VideoResult, ErrorAnalyzer } from "@memberjunction/ai";
2
+ import { AIErrorInfo, AvatarInfo, AvatarVideoParams, BaseVideoGenerator, BuildCancellationErrorInfo, IsRequestAborted, VideoResult, ErrorAnalyzer } from "@memberjunction/ai";
3
3
  import { HttpGet, HttpPost, IsHttpError } from "@memberjunction/network-utils";
4
4
 
5
5
 
@@ -30,6 +30,10 @@ export class HeyGenVideoGenerator extends BaseVideoGenerator {
30
30
  super(apiKey);
31
31
  }
32
32
 
33
+ /**
34
+ * Requests an avatar video. `params.CancellationToken` is passed to the request, so aborting it
35
+ * tears the request down; the failure is then classified as a cancellation.
36
+ */
33
37
  public async CreateAvatarVideo(params: AvatarVideoParams): Promise<VideoResult> {
34
38
  const videoResult = new VideoResult();
35
39
  try {
@@ -60,14 +64,15 @@ export class HeyGenVideoGenerator extends BaseVideoGenerator {
60
64
  }
61
65
  },
62
66
  {
63
- Headers: { Accept: 'application/json', 'X-Api-Key': this.apiKey }
67
+ Headers: { Accept: 'application/json', 'X-Api-Key': this.apiKey },
68
+ Signal: params.CancellationToken,
64
69
  }
65
70
  );
66
71
 
67
72
  videoResult.videoId = response.Data.data.video_id;
68
73
  videoResult.success = true;
69
74
  } catch (error) {
70
- const errorInfo = this.classifyError(error);
75
+ const errorInfo = this.classifyError(error, params.CancellationToken);
71
76
  videoResult.success = false;
72
77
  videoResult.errorMessage = error?.message || 'Unknown error occurred';
73
78
  // Kept so a caller can tell a rejected request (a 400) from an outage: the message,
@@ -82,9 +87,14 @@ export class HeyGenVideoGenerator extends BaseVideoGenerator {
82
87
  * Classifies a failed request. `HttpError` carries the response's status as `Status`, which
83
88
  * `ErrorAnalyzer` does not read, so the analyzer is given the status, and the `retry-after`
84
89
  * header, under the names it reads. The original error stays on the result. A request that got
85
- * no response (status 0: a timeout or a network failure) is classified from its message.
90
+ * no response (status 0: a timeout or a network failure) is classified from its message. A
91
+ * request ended by its `CancellationToken` is a cancellation, never failed over, or a network
92
+ * error when the signal was aborted by a timeout.
86
93
  */
87
- private classifyError(error: unknown): AIErrorInfo {
94
+ private classifyError(error: unknown, signal: AbortSignal | undefined): AIErrorInfo {
95
+ if (IsRequestAborted(error, signal) || (IsHttpError(error) && error.IsCancelled)) {
96
+ return BuildCancellationErrorInfo({ error, signal, provider: 'HeyGen' });
97
+ }
88
98
  if (IsHttpError(error) && error.Status > 0) {
89
99
  const withStatus = { name: error.name, message: error.message, status: error.Status, headers: error.Headers };
90
100
  return { ...ErrorAnalyzer.AnalyzeError(withStatus, 'HeyGen'), error };
package/vitest.config.ts CHANGED
@@ -1,9 +1,13 @@
1
- import { defineConfig } from 'vitest/config';
1
+ import { defineProject, mergeConfig } from 'vitest/config';
2
+ import sharedConfig from '../../../../vitest.shared';
2
3
 
3
- export default defineConfig({
4
- test: {
5
- globals: true,
6
- environment: 'node',
7
- include: ['src/__tests__/**/*.test.ts']
8
- }
9
- });
4
+ export default mergeConfig(
5
+ sharedConfig,
6
+ defineProject({
7
+ test: {
8
+ globals: true,
9
+ environment: 'node',
10
+ include: ['src/__tests__/**/*.test.ts']
11
+ }
12
+ })
13
+ );