@falai/agent 3.2.4 → 3.3.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.
Files changed (62) hide show
  1. package/dist/cjs/core/Agent.d.ts +7 -2
  2. package/dist/cjs/core/Agent.d.ts.map +1 -1
  3. package/dist/cjs/core/Agent.js +13 -7
  4. package/dist/cjs/core/Agent.js.map +1 -1
  5. package/dist/cjs/core/ResponsePipeline.d.ts.map +1 -1
  6. package/dist/cjs/core/ResponsePipeline.js +3 -1
  7. package/dist/cjs/core/ResponsePipeline.js.map +1 -1
  8. package/dist/cjs/index.d.ts +2 -0
  9. package/dist/cjs/index.d.ts.map +1 -1
  10. package/dist/cjs/index.js +4 -2
  11. package/dist/cjs/index.js.map +1 -1
  12. package/dist/cjs/providers/ZaiProvider.d.ts +41 -0
  13. package/dist/cjs/providers/ZaiProvider.d.ts.map +1 -0
  14. package/dist/cjs/providers/ZaiProvider.js +49 -0
  15. package/dist/cjs/providers/ZaiProvider.js.map +1 -0
  16. package/dist/cjs/providers/index.d.ts +2 -0
  17. package/dist/cjs/providers/index.d.ts.map +1 -1
  18. package/dist/cjs/providers/index.js +3 -1
  19. package/dist/cjs/providers/index.js.map +1 -1
  20. package/dist/cjs/utils/index.d.ts +1 -1
  21. package/dist/cjs/utils/index.d.ts.map +1 -1
  22. package/dist/cjs/utils/index.js +2 -1
  23. package/dist/cjs/utils/index.js.map +1 -1
  24. package/dist/cjs/utils/session.d.ts +7 -0
  25. package/dist/cjs/utils/session.d.ts.map +1 -1
  26. package/dist/cjs/utils/session.js +16 -0
  27. package/dist/cjs/utils/session.js.map +1 -1
  28. package/dist/core/Agent.d.ts +7 -2
  29. package/dist/core/Agent.d.ts.map +1 -1
  30. package/dist/core/Agent.js +14 -8
  31. package/dist/core/Agent.js.map +1 -1
  32. package/dist/core/ResponsePipeline.d.ts.map +1 -1
  33. package/dist/core/ResponsePipeline.js +4 -2
  34. package/dist/core/ResponsePipeline.js.map +1 -1
  35. package/dist/index.d.ts +2 -0
  36. package/dist/index.d.ts.map +1 -1
  37. package/dist/index.js +1 -0
  38. package/dist/index.js.map +1 -1
  39. package/dist/providers/ZaiProvider.d.ts +41 -0
  40. package/dist/providers/ZaiProvider.d.ts.map +1 -0
  41. package/dist/providers/ZaiProvider.js +45 -0
  42. package/dist/providers/ZaiProvider.js.map +1 -0
  43. package/dist/providers/index.d.ts +2 -0
  44. package/dist/providers/index.d.ts.map +1 -1
  45. package/dist/providers/index.js +1 -0
  46. package/dist/providers/index.js.map +1 -1
  47. package/dist/utils/index.d.ts +1 -1
  48. package/dist/utils/index.d.ts.map +1 -1
  49. package/dist/utils/index.js +1 -1
  50. package/dist/utils/index.js.map +1 -1
  51. package/dist/utils/session.d.ts +7 -0
  52. package/dist/utils/session.d.ts.map +1 -1
  53. package/dist/utils/session.js +15 -0
  54. package/dist/utils/session.js.map +1 -1
  55. package/package.json +2 -2
  56. package/src/core/Agent.ts +15 -7
  57. package/src/core/ResponsePipeline.ts +4 -1
  58. package/src/index.ts +2 -0
  59. package/src/providers/ZaiProvider.ts +67 -0
  60. package/src/providers/index.ts +3 -0
  61. package/src/utils/index.ts +1 -0
  62. package/src/utils/session.ts +24 -0
@@ -0,0 +1,67 @@
1
+ /**
2
+ * Z.ai Coding Plan.
3
+ *
4
+ * The flat-rate plan hosts GLM on an Anthropic-compatible endpoint with
5
+ * Bearer auth and its own thinking dialect — all of that lives in
6
+ * `@providerkit/core` (adapter + preset); this file is the constructor, the
7
+ * family default for cheap high-volume work.
8
+ *
9
+ * Dialect notes (measured 2026-09-13, see the core preset for detail):
10
+ * model ids are BARE (`glm-5.3-flash`, not `z-ai/glm-5.3-flash`), and
11
+ * "no thinking" must be an explicit marker — silence means the model default,
12
+ * which is thinking ON.
13
+ */
14
+
15
+ import { createZaiCodingProvider } from "@providerkit/core";
16
+
17
+ import type { ProviderCapabilities } from "../types/ai.js";
18
+ import { ProviderAdapter, type RequestConfig } from "./ProviderAdapter.js";
19
+
20
+ export interface ZaiProviderOptions {
21
+ /** Z.ai Coding Plan key */
22
+ apiKey: string;
23
+ /** Model to use. Defaults to the fleet workhorse `glm-5.3-flash`. */
24
+ model?: string;
25
+ /** Backup models to try if the primary fails (default: []) */
26
+ backupModels?: string[];
27
+ /** Any endpoint speaking the Anthropic Messages dialect with the plan's
28
+ * auth. Defaults to the coding endpoint. */
29
+ baseUrl?: string;
30
+ /** Request defaults sent with every call */
31
+ config?: RequestConfig;
32
+ /** Idle-stream deadline and retry budget */
33
+ retryConfig?: { timeout?: number; retries?: number };
34
+ /** Replacement `fetch`, for tests that script the wire. */
35
+ fetchImpl?: typeof fetch;
36
+ }
37
+
38
+ export class ZaiProvider extends ProviderAdapter {
39
+ public readonly name = "zai";
40
+ public readonly capabilities: ProviderCapabilities = {
41
+ supportsTools: true,
42
+ supportsNativeJsonSchema: false,
43
+ supportsStreaming: true,
44
+ supportsStreamingToolCalls: true,
45
+ supportsPromptCaching: true,
46
+ };
47
+
48
+ constructor(options: ZaiProviderOptions) {
49
+ if (!options.apiKey) throw new Error("Z.ai Coding Plan API key is required");
50
+
51
+ const model = options.model ?? "glm-5.3-flash";
52
+ super({
53
+ provider: createZaiCodingProvider({
54
+ apiKey: options.apiKey,
55
+ model,
56
+ ...(options.baseUrl ? { baseUrl: options.baseUrl } : {}),
57
+ ...(options.config?.maxTokens ? { maxTokens: options.config.maxTokens } : {}),
58
+ ...(options.config?.effort ? { effort: options.config.effort } : {}),
59
+ ...(options.fetchImpl ? { fetchImpl: options.fetchImpl } : {}),
60
+ }),
61
+ model,
62
+ ...(options.config ? { defaults: options.config } : {}),
63
+ ...(options.backupModels ? { backupModels: options.backupModels } : {}),
64
+ ...(options.retryConfig ? { retryConfig: options.retryConfig } : {}),
65
+ });
66
+ }
67
+ }
@@ -33,3 +33,6 @@ export type { OpenAICompatibleOptions } from "./GenericOpenAICompatibleProvider.
33
33
 
34
34
  export { ProviderAdapter, resolveRetryConfig } from "./ProviderAdapter.js";
35
35
  export type { ProviderAdapterInit, RequestConfig, RetryConfig } from "./ProviderAdapter.js";
36
+
37
+ export { ZaiProvider } from "./ZaiProvider.js";
38
+ export type { ZaiProviderOptions } from "./ZaiProvider.js";
@@ -24,6 +24,7 @@ export {
24
24
  completeCurrentFlow,
25
25
  isFlowCompletedThisSession,
26
26
  mergeCollected,
27
+ dropUndeclaredFields,
27
28
  sessionStepToData,
28
29
  sessionDataToStep,
29
30
  } from "./session.js";
@@ -3,6 +3,7 @@ import type { SessionState } from "../types/session.js";
3
3
  import type { History } from "../types/history.js";
4
4
  import type { Directive } from "../types/flow.js";
5
5
  import type { CollectedStateData } from "../types/persistence.js";
6
+ import type { StructuredSchema } from "../types/schema.js";
6
7
  import { logger } from "./logger.js";
7
8
 
8
9
  /**
@@ -288,6 +289,29 @@ export function mergeCollected<TData = Record<string, unknown>>(
288
289
  };
289
290
  }
290
291
 
292
+ /**
293
+ * Keep only the fields the agent schema declares. A model can extract a key
294
+ * nobody declared (e.g. `battery_health`); it is dropped with one warning
295
+ * instead of reaching session data. No schema, or no properties, keeps all.
296
+ */
297
+ export function dropUndeclaredFields<TData>(
298
+ data: Partial<TData>,
299
+ schema: StructuredSchema | undefined
300
+ ): Partial<TData> {
301
+ const properties = schema?.properties;
302
+ if (!properties) return data;
303
+
304
+ const dropped = Object.keys(data).filter((key) => !(key in properties));
305
+ if (dropped.length === 0) return data;
306
+
307
+ logger.warn(
308
+ `[Agent] Dropped fields not declared in agent schema: ${dropped.join(", ")}`
309
+ );
310
+ return Object.fromEntries(
311
+ Object.entries(data).filter(([key]) => key in properties)
312
+ ) as Partial<TData>;
313
+ }
314
+
291
315
  /**
292
316
  * Helper to convert SessionState to persistence-friendly format
293
317
  * Used when saving to database