chat-js 1.0.0-alpha.4 → 1.0.0-alpha.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.
Files changed (27) hide show
  1. package/README.md +3 -3
  2. package/dist/index.js +21924 -22023
  3. package/package.json +2 -3
  4. package/templates/chat-app/chatjs/core/gateway/defaults.ts +43 -0
  5. package/templates/chat-app/chatjs/core/gateway/gateway-provider.ts +23 -0
  6. package/templates/chat-app/chatjs/core/gateway/models.test.ts +39 -0
  7. package/templates/chat-app/chatjs/core/gateway/models.ts +67 -0
  8. package/templates/chat-app/chatjs/core/gateway/provider-types.ts +11 -0
  9. package/templates/chat-app/chatjs/core/gateway/runtime.test.ts +30 -0
  10. package/templates/chat-app/chatjs/core/gateway/runtime.ts +62 -0
  11. package/templates/chat-app/chatjs/plugins/mcp/oauth/mcp-client.ts +1 -1
  12. package/templates/chat-app/chatjs/providers/gateway-defaults.ts +1 -1
  13. package/templates/chat-app/chatjs/providers/gateway.ts +13 -10
  14. package/templates/chat-app/integrations/chat/model-options.ts +75 -0
  15. package/templates/chat-app/lib/ai/gateways/fallback-models.ts +1 -1
  16. package/templates/chat-app/lib/ai/gateways/registry.ts +2 -2
  17. package/templates/chat-app/lib/ai/models.generated.ts +1 -1
  18. package/templates/chat-app/lib/ai/models.ts +1 -1
  19. package/templates/chat-app/lib/ai/to-model-data.test.ts +1 -1
  20. package/templates/chat-app/lib/ai/to-model-data.ts +1 -1
  21. package/templates/chat-app/lib/eve/model-selection.ts +1 -1
  22. package/templates/chat-app/lib/eve/tool-accounting.test.ts +14 -2
  23. package/templates/chat-app/lib/eve/tool-accounting.ts +30 -29
  24. package/templates/chat-app/lib/eve/tool-cost.ts +1 -1
  25. package/templates/chat-app/next.config.ts +0 -1
  26. package/templates/chat-app/package.json +11 -9
  27. package/templates/chat-app/scripts/fetch-models.ts +1 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "chat-js",
3
- "version": "1.0.0-alpha.4",
3
+ "version": "1.0.0-alpha.6",
4
4
  "private": false,
5
5
  "description": "CLI for creating and extending ChatJS apps",
6
6
  "keywords": [
@@ -51,7 +51,6 @@
51
51
  "test:native-agent": "bun test/native-agent-acceptance.ts"
52
52
  },
53
53
  "dependencies": {
54
- "@chat-js/gateways": "0.2.1",
55
54
  "@clack/prompts": "^1.0.1",
56
55
  "commander": "^14.0.0",
57
56
  "files-sdk": "2.5.0",
@@ -67,7 +66,7 @@
67
66
  "@types/bun": "latest",
68
67
  "@types/node": "22.13.10",
69
68
  "@vercel/sandbox": "3.3.0",
70
- "eve": "npm:@chat-js/eve@1.0.0-rc.6-chatjs.1",
69
+ "eve": "npm:@chat-js/eve@1.1.1-chatjs.0",
71
70
  "next": "16.3.0",
72
71
  "playwright": "^1.59.1",
73
72
  "png2icons": "^2.0.1",
@@ -0,0 +1,43 @@
1
+ import type { ConfigMediaModelId } from "./provider-types.ts";
2
+ import type { GatewayProvider } from "./gateway-provider.ts";
3
+
4
+ const MODEL_ID_PARAMETER_INDEX = 0;
5
+
6
+ interface GatewayModelDefaults<TGateway extends GatewayProvider> {
7
+ curatedDefaults: Parameters<
8
+ TGateway["createLanguageModel"]
9
+ >[typeof MODEL_ID_PARAMETER_INDEX][];
10
+ disabledModels: Parameters<
11
+ TGateway["createLanguageModel"]
12
+ >[typeof MODEL_ID_PARAMETER_INDEX][];
13
+ providerOrder: string[];
14
+ roles: {
15
+ fast: Parameters<
16
+ TGateway["createLanguageModel"]
17
+ >[typeof MODEL_ID_PARAMETER_INDEX];
18
+ balanced: Parameters<
19
+ TGateway["createLanguageModel"]
20
+ >[typeof MODEL_ID_PARAMETER_INDEX];
21
+ smart: Parameters<
22
+ TGateway["createLanguageModel"]
23
+ >[typeof MODEL_ID_PARAMETER_INDEX];
24
+ image?: ConfigMediaModelId<TGateway["createImageModel"]>;
25
+ video?: ConfigMediaModelId<TGateway["createVideoModel"]>;
26
+ };
27
+ workflows: {
28
+ chat: Parameters<
29
+ TGateway["createLanguageModel"]
30
+ >[typeof MODEL_ID_PARAMETER_INDEX];
31
+ title: Parameters<
32
+ TGateway["createLanguageModel"]
33
+ >[typeof MODEL_ID_PARAMETER_INDEX];
34
+ pdf: Parameters<
35
+ TGateway["createLanguageModel"]
36
+ >[typeof MODEL_ID_PARAMETER_INDEX];
37
+ chatImageCompatible: Parameters<
38
+ TGateway["createLanguageModel"]
39
+ >[typeof MODEL_ID_PARAMETER_INDEX];
40
+ };
41
+ }
42
+
43
+ export type { GatewayModelDefaults };
@@ -0,0 +1,23 @@
1
+ import type {
2
+ Experimental_VideoModelV4,
3
+ LanguageModelV4,
4
+ } from "@ai-sdk/provider";
5
+ import type { AiGatewayModel } from "./models.ts";
6
+ import type { ImageModel } from "ai";
7
+
8
+ interface GatewayProvider<TGateway extends string = string> {
9
+ /** Dedicated image model factory; null when this capability is unsupported. */
10
+ createImageModel: ((modelId: string) => ImageModel) | null;
11
+
12
+ /** Create a language model instance from a model ID like "openai/gpt-5-nano" */
13
+ createLanguageModel: (modelId: string) => LanguageModelV4;
14
+
15
+ /** Video model factory; null when this capability is unsupported. */
16
+ createVideoModel: ((modelId: string) => Experimental_VideoModelV4) | null;
17
+
18
+ /** Fetch the list of available models from the gateway's API */
19
+ fetchModels: () => Promise<AiGatewayModel[]>;
20
+ readonly type: TGateway;
21
+ }
22
+
23
+ export type { GatewayProvider };
@@ -0,0 +1,39 @@
1
+ import { describe, expect, expectTypeOf, it } from "vitest";
2
+
3
+ import type { AiGatewayModel } from "./models";
4
+ import { aiGatewayModelSchema } from "./models";
5
+
6
+ const tagsSchema = aiGatewayModelSchema.shape.tags;
7
+
8
+ describe("gateway model tags", () => {
9
+ it("accepts known and future provider tags without changing their values", () => {
10
+ const tags: NonNullable<AiGatewayModel["tags"]> = [
11
+ "reasoning",
12
+ "tool-use",
13
+ "vision",
14
+ "file-input",
15
+ "image-generation",
16
+ "implicit-caching",
17
+ "future-provider-tag",
18
+ "",
19
+ ];
20
+
21
+ expect(tagsSchema.parse(tags)).toEqual(tags);
22
+ expectTypeOf<string>().toExtend<
23
+ NonNullable<AiGatewayModel["tags"]>[number]
24
+ >();
25
+ expectTypeOf(tagsSchema.parse(tags)).toExtend<string[] | undefined>();
26
+ });
27
+
28
+ it("keeps tags optional and accepts an empty list", () => {
29
+ expect(aiGatewayModelSchema.pick({ tags: true }).parse({})).toEqual({});
30
+ expect(tagsSchema.parse([])).toEqual([]);
31
+ });
32
+
33
+ it.each([{ tag: true }, { tag: {} }, { tag: [] }])(
34
+ "rejects non-string tags: $tag",
35
+ ({ tag }: { readonly tag: unknown }) => {
36
+ expect(tagsSchema.safeParse([tag]).success).toBe(false);
37
+ }
38
+ );
39
+ });
@@ -0,0 +1,67 @@
1
+ import { z } from "zod";
2
+
3
+ // Known tags provide IDE hints; providers may introduce other string tags.
4
+ type KnownTag =
5
+ | "reasoning"
6
+ | "tool-use"
7
+ | "vision"
8
+ | "file-input"
9
+ | "image-generation"
10
+ | "implicit-caching";
11
+
12
+ type ModelTag = KnownTag | (string & Record<never, never>);
13
+
14
+ const tagSchema: z.ZodType<ModelTag> = z.string();
15
+
16
+ const supportedAiGatewayModelTypes = [
17
+ "language",
18
+ "embedding",
19
+ "image",
20
+ "video",
21
+ ] as const;
22
+
23
+ type AiGatewayModelType = (typeof supportedAiGatewayModelTypes)[number];
24
+
25
+ const aiGatewayModelTypeSchema = z.enum(supportedAiGatewayModelTypes);
26
+
27
+ const MIN_PRICING_TIER_BOUND = 0;
28
+
29
+ const pricingTierSchema = z.object({
30
+ cost: z.string(),
31
+ max: z.number().optional(),
32
+ min: z.number().default(MIN_PRICING_TIER_BOUND),
33
+ });
34
+
35
+ // Model catalog record returned by gateway adapters.
36
+ const aiGatewayModelSchema = z.object({
37
+ context_window: z.number(),
38
+ created: z.number(),
39
+ description: z.string(),
40
+ id: z.string(),
41
+ max_tokens: z.number(),
42
+ name: z.string(),
43
+ object: z.literal("model"),
44
+ owned_by: z.string(),
45
+ pricing: z.object({
46
+ image: z.string().optional(),
47
+ input: z.string().optional(),
48
+ input_cache_read: z.string().optional(),
49
+ input_cache_read_tiers: z.array(pricingTierSchema).optional(),
50
+ input_cache_write: z.string().optional(),
51
+ input_tiers: z.array(pricingTierSchema).optional(),
52
+ output: z.string().optional(),
53
+ output_tiers: z.array(pricingTierSchema).optional(),
54
+ web_search: z.string().optional(),
55
+ }),
56
+ tags: z.array(tagSchema).optional(),
57
+ type: aiGatewayModelTypeSchema,
58
+ });
59
+
60
+ type AiGatewayModel = z.infer<typeof aiGatewayModelSchema>;
61
+
62
+ const isAiGatewayModelType = (type: string): type is AiGatewayModelType =>
63
+ supportedAiGatewayModelTypes.some((supportedType) => supportedType === type);
64
+
65
+ export { aiGatewayModelSchema, isAiGatewayModelType };
66
+
67
+ export type { AiGatewayModelType, AiGatewayModel };
@@ -0,0 +1,11 @@
1
+ type StrictLiterals<TValue> = TValue extends string
2
+ ? string extends TValue
3
+ ? never
4
+ : TValue
5
+ : TValue;
6
+
7
+ // Null capabilities have no configurable IDs; supported factories retain SDK suggestions.
8
+ type ConfigMediaModelId<Factory extends ((modelId: string) => unknown) | null> =
9
+ Parameters<NonNullable<Factory>>[0];
10
+
11
+ export type { ConfigMediaModelId, StrictLiterals };
@@ -0,0 +1,30 @@
1
+ import { afterEach, expect, test, vi } from "vitest";
2
+ import { GatewayRuntime } from "./runtime";
3
+
4
+ class RuntimeProbe extends GatewayRuntime {
5
+ public get request(): typeof fetch {
6
+ return this.fetch;
7
+ }
8
+ }
9
+
10
+ afterEach(() => {
11
+ vi.unstubAllGlobals();
12
+ });
13
+
14
+ test("default fetch reads the current global and forwards arguments, results and failures", async () => {
15
+ const runtime = new RuntimeProbe();
16
+ const response = Promise.resolve(new Response("ok"));
17
+ const request = new Request("https://example.com");
18
+ const options = { headers: { "x-test": "forwarded" } };
19
+ const fetchMock = vi.fn<typeof fetch>().mockReturnValue(response);
20
+ vi.stubGlobal("fetch", fetchMock);
21
+ await expect(runtime.request(request, options)).resolves.toBe(await response);
22
+ expect(fetchMock.mock.calls[0]?.[0]).toBe(request);
23
+ expect(fetchMock.mock.calls[0]?.[1]).toBe(options);
24
+
25
+ const failure = new Error("custom fetch validation");
26
+ fetchMock.mockImplementation(() => {
27
+ throw failure;
28
+ });
29
+ await expect(runtime.request(request)).rejects.toBe(failure);
30
+ });
@@ -0,0 +1,62 @@
1
+ import type { AiGatewayModel } from "./models.ts";
2
+
3
+ interface GatewayLogger {
4
+ debug: (data: unknown, message?: string) => void;
5
+ info: (data: unknown, message?: string) => void;
6
+ warn: (data: unknown, message?: string) => void;
7
+ error: (data: unknown, message?: string) => void;
8
+ }
9
+
10
+ interface GatewayOptions {
11
+ env?: Record<string, string | undefined>;
12
+ fetch?: (
13
+ ...args: Parameters<typeof globalThis.fetch>
14
+ ) => ReturnType<typeof globalThis.fetch>;
15
+ getFallbackModels?: (gateway: string) => readonly AiGatewayModel[];
16
+ logger?: GatewayLogger;
17
+ }
18
+
19
+ type GatewayReaderOptions = Readonly<Omit<GatewayOptions, "env" | "logger">> & {
20
+ readonly env?: Readonly<NonNullable<GatewayOptions["env"]>>;
21
+ readonly logger?: Readonly<GatewayLogger>;
22
+ };
23
+
24
+ const silentLogger: GatewayLogger = {
25
+ debug: (): void => {
26
+ /* Intentionally silent when no logger is provided. */
27
+ },
28
+ error: (): void => {
29
+ /* Intentionally silent when no logger is provided. */
30
+ },
31
+ info: (): void => {
32
+ /* Intentionally silent when no logger is provided. */
33
+ },
34
+ warn: (): void => {
35
+ /* Intentionally silent when no logger is provided. */
36
+ },
37
+ };
38
+
39
+ class GatewayRuntime {
40
+ protected readonly env: NonNullable<GatewayOptions["env"]>;
41
+ protected readonly fetch: NonNullable<GatewayOptions["fetch"]>;
42
+ protected readonly getFallbackModels: NonNullable<
43
+ GatewayOptions["getFallbackModels"]
44
+ >;
45
+ protected readonly log: GatewayLogger;
46
+
47
+ public constructor(options: GatewayReaderOptions = {}) {
48
+ this.env = options.env ?? process.env;
49
+ this.fetch =
50
+ options.fetch ??
51
+ (async (
52
+ ...args: Parameters<typeof globalThis.fetch>
53
+ ): ReturnType<typeof globalThis.fetch> =>
54
+ await globalThis.fetch(...args));
55
+ this.getFallbackModels = options.getFallbackModels ?? ((): never[] => []);
56
+ this.log = options.logger ?? silentLogger;
57
+ }
58
+ }
59
+
60
+ export { GatewayRuntime };
61
+
62
+ export type { GatewayOptions };
@@ -416,7 +416,7 @@ export class MCPClient {
416
416
  throw new Error("Client not connected");
417
417
  }
418
418
  try {
419
- return await client.experimental_listPrompts();
419
+ return await client.listPrompts();
420
420
  } catch (error) {
421
421
  await this.handlePotentialAuthError(error, client);
422
422
  throw error;
@@ -1,4 +1,4 @@
1
- import type { GatewayModelDefaults } from "@chat-js/gateways/defaults";
1
+ import type { GatewayModelDefaults } from "@/chatjs/core/gateway/defaults";
2
2
  import type { Gateway } from "@/chatjs/providers/gateway";
3
3
 
4
4
  const gatewayType = "vercel" satisfies InstanceType<typeof Gateway>["type"];
@@ -3,18 +3,17 @@ import type {
3
3
  LanguageModelV4,
4
4
  } from "@ai-sdk/provider";
5
5
  import {
6
- aiGatewayModelDiscriminatorSchema,
7
6
  aiGatewayModelSchema,
8
- aiGatewayModelsEnvelopeSchema,
9
7
  isAiGatewayModelType,
10
- } from "@chat-js/gateways/models";
11
- import type { AiGatewayModel } from "@chat-js/gateways/models";
12
- import type { GatewayProvider } from "@chat-js/gateways/gateway-provider";
13
- import { GatewayRuntime } from "@chat-js/gateways/runtime";
8
+ } from "@/chatjs/core/gateway/models";
9
+ import type { AiGatewayModel } from "@/chatjs/core/gateway/models";
10
+ import type { GatewayProvider } from "@/chatjs/core/gateway/gateway-provider";
11
+ import { GatewayRuntime } from "@/chatjs/core/gateway/runtime";
14
12
  import type { ImageModel } from "ai";
15
13
 
16
14
  import { createGateway } from "@ai-sdk/gateway";
17
15
  import type { gateway } from "@ai-sdk/gateway";
16
+ import { z } from "zod";
18
17
 
19
18
  const MODEL_ID_PARAMETER_INDEX = 0;
20
19
  type VercelImageModelId = Parameters<
@@ -25,6 +24,11 @@ type VercelVideoModelId = Parameters<
25
24
  >[typeof MODEL_ID_PARAMETER_INDEX];
26
25
 
27
26
  const EMPTY_MODEL_TYPE_COUNT = 0;
27
+ const modelDiscriminatorSchema = z.object({ type: z.string() });
28
+ const modelsEnvelopeSchema = z.object({
29
+ data: z.array(z.unknown()),
30
+ object: z.literal("list"),
31
+ });
28
32
 
29
33
  class VercelGateway
30
34
  extends GatewayRuntime
@@ -94,15 +98,14 @@ class VercelGateway
94
98
  }
95
99
 
96
100
  const bodyRaw: unknown = await response.json();
97
- const body = aiGatewayModelsEnvelopeSchema.parse(bodyRaw);
101
+ const body = modelsEnvelopeSchema.parse(bodyRaw);
98
102
  const unsupportedTypes = new Set<string>();
99
103
  const models: AiGatewayModel[] = [];
100
104
 
101
105
  for (const candidate of body.data) {
102
- const { type } = aiGatewayModelDiscriminatorSchema.parse(candidate);
106
+ const { type } = modelDiscriminatorSchema.parse(candidate);
103
107
  if (isAiGatewayModelType(type)) {
104
- const model = aiGatewayModelSchema.parse(candidate);
105
- models.push({ ...model, type });
108
+ models.push(aiGatewayModelSchema.parse(candidate));
106
109
  } else {
107
110
  unsupportedTypes.add(type);
108
111
  }
@@ -0,0 +1,75 @@
1
+ import type { JSONObject, SharedV4ProviderOptions } from "@ai-sdk/provider";
2
+
3
+ const ANTHROPIC_REASONING_BUDGET_TOKENS = 4096;
4
+ const GOOGLE_REASONING_BUDGET_TOKENS = 10_000;
5
+
6
+ const getOpenAIProviderOptions = (
7
+ apiModelId: string,
8
+ reasoning: boolean
9
+ ): JSONObject => {
10
+ if (!reasoning) {
11
+ return {};
12
+ }
13
+ // Vercel IDs include the provider prefix; direct OpenAI IDs do not.
14
+ const modelName = apiModelId.split("/").pop() ?? apiModelId;
15
+ const options: JSONObject = {
16
+ reasoningSummary: "auto",
17
+ };
18
+ if (
19
+ modelName === "gpt-5" ||
20
+ modelName === "gpt-5-mini" ||
21
+ modelName === "gpt-5-nano"
22
+ ) {
23
+ options.reasoningEffort = "low";
24
+ }
25
+ return options;
26
+ };
27
+
28
+ const getModelProviderOptions = (
29
+ model: Readonly<{
30
+ apiModelId: string;
31
+ owned_by: string;
32
+ reasoning: boolean;
33
+ }>
34
+ ): SharedV4ProviderOptions => {
35
+ switch (model.owned_by) {
36
+ case "openai": {
37
+ return {
38
+ openai: getOpenAIProviderOptions(model.apiModelId, model.reasoning),
39
+ };
40
+ }
41
+ case "anthropic": {
42
+ if (model.reasoning) {
43
+ return {
44
+ anthropic: {
45
+ thinking: {
46
+ budgetTokens: ANTHROPIC_REASONING_BUDGET_TOKENS,
47
+ type: "enabled",
48
+ },
49
+ },
50
+ };
51
+ }
52
+ return { anthropic: {} };
53
+ }
54
+ case "xai": {
55
+ return { xai: {} };
56
+ }
57
+ case "google": {
58
+ if (model.reasoning) {
59
+ return {
60
+ google: {
61
+ thinkingConfig: {
62
+ thinkingBudget: GOOGLE_REASONING_BUDGET_TOKENS,
63
+ },
64
+ },
65
+ };
66
+ }
67
+ return { google: {} };
68
+ }
69
+ default: {
70
+ return {};
71
+ }
72
+ }
73
+ };
74
+
75
+ export { getModelProviderOptions };
@@ -2,7 +2,7 @@ import {
2
2
  models as fallbackModels,
3
3
  generatedForGateway,
4
4
  } from "@/lib/ai/models.generated";
5
- import type { AiGatewayModel } from "@chat-js/gateways/models";
5
+ import type { AiGatewayModel } from "@/chatjs/core/gateway/models";
6
6
  import { createModuleLogger } from "@/lib/logger";
7
7
 
8
8
  const log = createModuleLogger("ai/gateways/fallback");
@@ -1,10 +1,10 @@
1
1
  import type { generatedForGateway, models } from "@/lib/ai/models.generated";
2
2
  import type { createGateway } from "@/integrations/providers/gateway";
3
- import type { GatewayProvider as GatewayProviderBase } from "@chat-js/gateways/gateway-provider";
3
+ import type { GatewayProvider as GatewayProviderBase } from "@/chatjs/core/gateway/gateway-provider";
4
4
  import type {
5
5
  ConfigMediaModelId,
6
6
  StrictLiterals,
7
- } from "@chat-js/gateways/provider-types";
7
+ } from "@/chatjs/core/gateway/provider-types";
8
8
  import type { gatewayType } from "@/chatjs/providers/gateway-defaults";
9
9
 
10
10
  type InstalledGateway = ReturnType<typeof createGateway>;
@@ -1,4 +1,4 @@
1
- import type { AiGatewayModel } from "@chat-js/gateways/models";
1
+ import type { AiGatewayModel } from "@/chatjs/core/gateway/models";
2
2
 
3
3
  export const generatedForGateway = "vercel";
4
4
 
@@ -1,4 +1,4 @@
1
- import type { AiGatewayModel } from "@chat-js/gateways/models";
1
+ import type { AiGatewayModel } from "@/chatjs/core/gateway/models";
2
2
  import type { ModelData } from "./model-data";
3
3
  import type { ReadonlyAiGatewayModel } from "./to-model-data";
4
4
 
@@ -1,5 +1,5 @@
1
1
  import { expect, test } from "vitest";
2
- import type { AiGatewayModel } from "@chat-js/gateways/models";
2
+ import type { AiGatewayModel } from "@/chatjs/core/gateway/models";
3
3
 
4
4
  import { toModelData } from "./to-model-data";
5
5
 
@@ -1,4 +1,4 @@
1
- import type { AiGatewayModel } from "@chat-js/gateways/models";
1
+ import type { AiGatewayModel } from "@/chatjs/core/gateway/models";
2
2
 
3
3
  import type { ModelData } from "./model-data";
4
4
 
@@ -1,5 +1,5 @@
1
1
  import type { SessionModel } from "@/chatjs/core/session/contracts";
2
- import { getModelProviderOptions } from "@chat-js/gateways/provider-options";
2
+ import { getModelProviderOptions } from "@/integrations/chat/model-options";
3
3
  import { wrapLanguageModel } from "ai";
4
4
  import { z } from "zod";
5
5
 
@@ -50,13 +50,25 @@ describe("native tool accounting assembly", () => {
50
50
  type: "text",
51
51
  value: "done",
52
52
  });
53
- expect(tool.label?.complete?.({ value: "done" }, receipt)).toBe("done");
54
- expect(tool.label?.delta?.({ value: "done" }, receipt)).toBe("done");
53
+ const label = tool.label === false ? undefined : tool.label;
54
+ expect(label?.complete?.({ value: "done" }, receipt)).toBe("done");
55
+ expect(label?.delta?.({ value: "done" }, receipt)).toBe("done");
55
56
  expect(
56
57
  typeof tool.endsTurn === "function" && (await tool.endsTurn(receipt))
57
58
  ).toBe(true);
58
59
  });
59
60
 
61
+ it("preserves a tool's disabled label", () => {
62
+ const tool = defineTool({
63
+ description: "Example without a label",
64
+ inputSchema: z.object({}),
65
+ execute: () => "done",
66
+ label: false,
67
+ });
68
+
69
+ expect(withToolAccounting(tool, "none").label).toBe(false);
70
+ });
71
+
60
72
  it("retains native failures and prevents execution after cancellation", async () => {
61
73
  const failure = new Error("upstream unavailable");
62
74
  const execute = vi.fn((): string => {
@@ -63,34 +63,35 @@ export const withToolAccounting = <Input, Output extends ToolOutput>(
63
63
  ? async (result) =>
64
64
  result.status === "success" && (await endsTurn(result.output))
65
65
  : endsTurn,
66
- label: label
67
- ? {
68
- start: (input) => label.start(input),
69
- ...(label.delta
70
- ? {
71
- delta: (
72
- input: Readonly<Input>,
73
- result: Readonly<ToolResult<Output>>
74
- ) =>
75
- result.status === "success"
76
- ? (label.delta?.(input, result.output) ??
77
- label.start(input))
78
- : label.start(input),
79
- }
80
- : {}),
81
- ...(label.complete
82
- ? {
83
- complete: (
84
- input: Readonly<Input>,
85
- result: Readonly<ToolResult<Output>>
86
- ) =>
87
- result.status === "success"
88
- ? (label.complete?.(input, result.output) ??
89
- label.start(input))
90
- : label.start(input),
91
- }
92
- : {}),
93
- }
94
- : undefined,
66
+ label:
67
+ label !== undefined && label !== false
68
+ ? {
69
+ start: (input) => label.start(input),
70
+ ...(label.delta
71
+ ? {
72
+ delta: (
73
+ input: Readonly<Input>,
74
+ result: Readonly<ToolResult<Output>>
75
+ ) =>
76
+ result.status === "success"
77
+ ? (label.delta?.(input, result.output) ??
78
+ label.start(input))
79
+ : label.start(input),
80
+ }
81
+ : {}),
82
+ ...(label.complete
83
+ ? {
84
+ complete: (
85
+ input: Readonly<Input>,
86
+ result: Readonly<ToolResult<Output>>
87
+ ) =>
88
+ result.status === "success"
89
+ ? (label.complete?.(input, result.output) ??
90
+ label.start(input))
91
+ : label.start(input),
92
+ }
93
+ : {}),
94
+ }
95
+ : label,
95
96
  });
96
97
  };
@@ -1,4 +1,4 @@
1
- import type { AiGatewayModel } from "@chat-js/gateways/models";
1
+ import type { AiGatewayModel } from "@/chatjs/core/gateway/models";
2
2
 
3
3
  import { getActiveGateway } from "@/lib/ai/active-gateway";
4
4
  import type { ReadonlyNativeSurface } from "@/lib/readonly-native-surface";
@@ -34,7 +34,6 @@ const nextConfig: NextConfig = {
34
34
  },
35
35
  partialPrefetching: true,
36
36
  serverExternalPackages: ["pino", "pino-pretty"],
37
- transpilePackages: ["@chat-js/gateways"],
38
37
  typedRoutes: true,
39
38
  };
40
39