@tanstack/ai 0.26.1 → 0.27.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 (30) hide show
  1. package/dist/esm/activities/chat/index.d.ts +0 -6
  2. package/dist/esm/activities/chat/index.js +2 -17
  3. package/dist/esm/activities/chat/index.js.map +1 -1
  4. package/dist/esm/activities/chat/middleware/types.d.ts +1 -4
  5. package/dist/esm/activities/summarize/chat-stream-summarize.js +62 -3
  6. package/dist/esm/activities/summarize/chat-stream-summarize.js.map +1 -1
  7. package/dist/esm/logger/internal-logger.d.ts +8 -0
  8. package/dist/esm/logger/internal-logger.js +15 -0
  9. package/dist/esm/logger/internal-logger.js.map +1 -1
  10. package/dist/esm/middlewares/otel.js +30 -6
  11. package/dist/esm/middlewares/otel.js.map +1 -1
  12. package/dist/esm/types.d.ts +0 -35
  13. package/dist/esm/utilities/sampling-keys.d.ts +20 -0
  14. package/dist/esm/utilities/sampling-keys.js +20 -0
  15. package/dist/esm/utilities/sampling-keys.js.map +1 -0
  16. package/package.json +2 -2
  17. package/skills/ai-core/adapter-configuration/SKILL.md +67 -6
  18. package/skills/ai-core/adapter-configuration/references/anthropic-adapter.md +6 -3
  19. package/skills/ai-core/adapter-configuration/references/gemini-adapter.md +3 -0
  20. package/skills/ai-core/adapter-configuration/references/ollama-adapter.md +10 -1
  21. package/skills/ai-core/adapter-configuration/references/openai-adapter.md +4 -0
  22. package/skills/ai-core/chat-experience/SKILL.md +24 -7
  23. package/skills/ai-core/middleware/SKILL.md +11 -0
  24. package/src/activities/chat/index.ts +2 -23
  25. package/src/activities/chat/middleware/types.ts +1 -4
  26. package/src/activities/summarize/chat-stream-summarize.ts +162 -3
  27. package/src/logger/internal-logger.ts +18 -0
  28. package/src/middlewares/otel.ts +48 -6
  29. package/src/types.ts +0 -35
  30. package/src/utilities/sampling-keys.ts +28 -0
package/src/types.ts CHANGED
@@ -812,41 +812,6 @@ export interface TextOptions<
812
812
  */
813
813
  systemPrompts?: Array<SystemPrompt>
814
814
  agentLoopStrategy?: AgentLoopStrategy
815
- /**
816
- * Controls the randomness of the output.
817
- * Higher values (e.g., 0.8) make output more random, lower values (e.g., 0.2) make it more focused and deterministic.
818
- * Range: [0.0, 2.0]
819
- *
820
- * Note: Generally recommended to use either temperature or topP, but not both.
821
- *
822
- * Provider usage:
823
- * - OpenAI: `temperature` (number) - in text.top_p field
824
- * - Anthropic: `temperature` (number) - ranges from 0.0 to 1.0, default 1.0
825
- * - Gemini: `generationConfig.temperature` (number) - ranges from 0.0 to 2.0
826
- */
827
- temperature?: number
828
- /**
829
- * Nucleus sampling parameter. An alternative to temperature sampling.
830
- * The model considers the results of tokens with topP probability mass.
831
- * For example, 0.1 means only tokens comprising the top 10% probability mass are considered.
832
- *
833
- * Note: Generally recommended to use either temperature or topP, but not both.
834
- *
835
- * Provider usage:
836
- * - OpenAI: `text.top_p` (number)
837
- * - Anthropic: `top_p` (number | null)
838
- * - Gemini: `generationConfig.topP` (number)
839
- */
840
- topP?: number
841
- /**
842
- * The maximum number of tokens to generate in the response.
843
- *
844
- * Provider usage:
845
- * - OpenAI: `max_output_tokens` (number) - includes visible output and reasoning tokens
846
- * - Anthropic: `max_tokens` (number, required) - range x >= 1
847
- * - Gemini: `generationConfig.maxOutputTokens` (number)
848
- */
849
- maxTokens?: number
850
815
  /**
851
816
  * Additional metadata to attach to the request.
852
817
  * Can be used for tracking, debugging, or passing custom information.
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Single source of truth for the provider-native key spellings that cap output
3
+ * tokens. Sampling options live in opaque, provider-native `modelOptions`, and
4
+ * every provider spells the token cap differently. Two call sites must agree on
5
+ * this set or they silently drift:
6
+ *
7
+ * - `activities/summarize/chat-stream-summarize.ts` — detects a caller-supplied
8
+ * token limit so the summarize default never overrides it.
9
+ * - `middlewares/otel.ts` — picks the first numeric spelling to populate the
10
+ * `gen_ai.request.max_tokens` attribute across providers.
11
+ *
12
+ * Keep this list in lockstep with `MAX_TOKENS_KEY_BY_ADAPTER` (the adapter →
13
+ * native-key map) in the summarize wrapper.
14
+ */
15
+ export const MAX_TOKENS_KEYS = [
16
+ 'max_output_tokens', // OpenAI (Responses)
17
+ 'max_tokens', // Anthropic / Grok
18
+ 'max_completion_tokens', // Groq
19
+ 'maxOutputTokens', // Gemini
20
+ 'maxCompletionTokens', // OpenRouter
21
+ 'maxTokens', // generic / migration leftover (no adapter reads it)
22
+ ] as const
23
+
24
+ /**
25
+ * Ollama nests sampling under `options`; its token cap is `options.num_predict`
26
+ * rather than a flat key.
27
+ */
28
+ export const NESTED_MAX_TOKENS_KEY = 'num_predict' as const