llmist 0.4.0 → 0.4.1
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/dist/{chunk-VRTKJK2X.js → chunk-A4GRCCXF.js} +2 -2
- package/dist/{chunk-VYBRYR2S.js → chunk-LQE7TKKW.js} +43 -38
- package/dist/chunk-LQE7TKKW.js.map +1 -0
- package/dist/{chunk-I55AV3WV.js → chunk-QVDGTUQN.js} +2 -2
- package/dist/cli.cjs +43 -38
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +3 -3
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +42 -37
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +17 -3
- package/dist/index.d.ts +17 -3
- package/dist/index.js +3 -3
- package/dist/testing/index.cjs +42 -37
- package/dist/testing/index.cjs.map +1 -1
- package/dist/testing/index.js +2 -2
- package/package.json +1 -1
- package/dist/chunk-VYBRYR2S.js.map +0 -1
- /package/dist/{chunk-VRTKJK2X.js.map → chunk-A4GRCCXF.js.map} +0 -0
- /package/dist/{chunk-I55AV3WV.js.map → chunk-QVDGTUQN.js.map} +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
BaseGadget
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-LQE7TKKW.js";
|
|
4
4
|
|
|
5
5
|
// src/gadgets/create-gadget.ts
|
|
6
6
|
function createGadget(config) {
|
|
@@ -19,4 +19,4 @@ function createGadget(config) {
|
|
|
19
19
|
export {
|
|
20
20
|
createGadget
|
|
21
21
|
};
|
|
22
|
-
//# sourceMappingURL=chunk-
|
|
22
|
+
//# sourceMappingURL=chunk-QVDGTUQN.js.map
|
package/dist/cli.cjs
CHANGED
|
@@ -2745,10 +2745,11 @@ var init_gemini = __esm({
|
|
|
2745
2745
|
return GEMINI_MODELS;
|
|
2746
2746
|
}
|
|
2747
2747
|
buildRequestPayload(options, descriptor, _spec, messages) {
|
|
2748
|
-
const
|
|
2748
|
+
const contents = this.convertMessagesToContents(messages);
|
|
2749
2749
|
const generationConfig = this.buildGenerationConfig(options);
|
|
2750
2750
|
const config = {
|
|
2751
|
-
|
|
2751
|
+
// Note: systemInstruction removed - it doesn't work with countTokens()
|
|
2752
|
+
// System messages are now included in contents as user+model exchanges
|
|
2752
2753
|
...generationConfig ? { ...generationConfig } : {},
|
|
2753
2754
|
// Explicitly disable function calling to prevent UNEXPECTED_TOOL_CALL errors
|
|
2754
2755
|
toolConfig: {
|
|
@@ -2769,31 +2770,37 @@ var init_gemini = __esm({
|
|
|
2769
2770
|
const streamResponse = await client.models.generateContentStream(payload);
|
|
2770
2771
|
return streamResponse;
|
|
2771
2772
|
}
|
|
2772
|
-
|
|
2773
|
-
|
|
2774
|
-
|
|
2775
|
-
|
|
2776
|
-
|
|
2777
|
-
|
|
2778
|
-
|
|
2779
|
-
|
|
2780
|
-
|
|
2781
|
-
|
|
2782
|
-
|
|
2773
|
+
/**
|
|
2774
|
+
* Convert LLM messages to Gemini contents format.
|
|
2775
|
+
*
|
|
2776
|
+
* For Gemini, we convert system messages to user+model exchanges instead of
|
|
2777
|
+
* using systemInstruction, because:
|
|
2778
|
+
* 1. systemInstruction doesn't work with countTokens() API
|
|
2779
|
+
* 2. This approach gives perfect token counting accuracy (0% error)
|
|
2780
|
+
* 3. The model receives and follows system instructions identically
|
|
2781
|
+
*
|
|
2782
|
+
* System message: "You are a helpful assistant"
|
|
2783
|
+
* Becomes:
|
|
2784
|
+
* - User: "You are a helpful assistant"
|
|
2785
|
+
* - Model: "Understood."
|
|
2786
|
+
*/
|
|
2787
|
+
convertMessagesToContents(messages) {
|
|
2788
|
+
const expandedMessages = [];
|
|
2789
|
+
for (const message of messages) {
|
|
2790
|
+
if (message.role === "system") {
|
|
2791
|
+
expandedMessages.push({
|
|
2792
|
+
role: "user",
|
|
2793
|
+
content: message.content
|
|
2794
|
+
});
|
|
2795
|
+
expandedMessages.push({
|
|
2796
|
+
role: "assistant",
|
|
2797
|
+
content: "Understood."
|
|
2798
|
+
});
|
|
2799
|
+
} else {
|
|
2800
|
+
expandedMessages.push(message);
|
|
2801
|
+
}
|
|
2783
2802
|
}
|
|
2784
|
-
|
|
2785
|
-
const nonSystemMessages = [
|
|
2786
|
-
...messages.slice(0, firstSystemIndex),
|
|
2787
|
-
...messages.slice(systemBlockEnd)
|
|
2788
|
-
];
|
|
2789
|
-
const systemInstruction = {
|
|
2790
|
-
role: "system",
|
|
2791
|
-
parts: systemMessages.map((message) => ({ text: message.content }))
|
|
2792
|
-
};
|
|
2793
|
-
return {
|
|
2794
|
-
systemInstruction,
|
|
2795
|
-
contents: this.mergeConsecutiveMessages(nonSystemMessages)
|
|
2796
|
-
};
|
|
2803
|
+
return this.mergeConsecutiveMessages(expandedMessages);
|
|
2797
2804
|
}
|
|
2798
2805
|
mergeConsecutiveMessages(messages) {
|
|
2799
2806
|
if (messages.length === 0) {
|
|
@@ -2882,8 +2889,8 @@ var init_gemini = __esm({
|
|
|
2882
2889
|
*
|
|
2883
2890
|
* This method provides accurate token estimation for Gemini models by:
|
|
2884
2891
|
* - Using the SDK's countTokens() method
|
|
2885
|
-
* -
|
|
2886
|
-
* -
|
|
2892
|
+
* - Converting system messages to user+model exchanges (same as in generation)
|
|
2893
|
+
* - This gives perfect token counting accuracy (0% error vs actual usage)
|
|
2887
2894
|
*
|
|
2888
2895
|
* @param messages - The messages to count tokens for
|
|
2889
2896
|
* @param descriptor - Model descriptor containing the model name
|
|
@@ -2902,16 +2909,14 @@ var init_gemini = __esm({
|
|
|
2902
2909
|
*/
|
|
2903
2910
|
async countTokens(messages, descriptor, _spec) {
|
|
2904
2911
|
const client = this.client;
|
|
2905
|
-
const
|
|
2906
|
-
const request = {
|
|
2907
|
-
model: descriptor.name,
|
|
2908
|
-
contents: this.convertContentsForNewSDK(contents)
|
|
2909
|
-
};
|
|
2910
|
-
if (systemInstruction) {
|
|
2911
|
-
request.systemInstruction = systemInstruction.parts.map((p) => p.text).join("\n");
|
|
2912
|
-
}
|
|
2912
|
+
const contents = this.convertMessagesToContents(messages);
|
|
2913
2913
|
try {
|
|
2914
|
-
const response = await client.models.countTokens(
|
|
2914
|
+
const response = await client.models.countTokens({
|
|
2915
|
+
model: descriptor.name,
|
|
2916
|
+
contents: this.convertContentsForNewSDK(contents)
|
|
2917
|
+
// Note: systemInstruction not used - it's not supported by countTokens()
|
|
2918
|
+
// and would cause a 2100% token counting error
|
|
2919
|
+
});
|
|
2915
2920
|
return response.totalTokens ?? 0;
|
|
2916
2921
|
} catch (error) {
|
|
2917
2922
|
console.warn(
|
|
@@ -4305,7 +4310,7 @@ var import_commander3 = require("commander");
|
|
|
4305
4310
|
// package.json
|
|
4306
4311
|
var package_default = {
|
|
4307
4312
|
name: "llmist",
|
|
4308
|
-
version: "0.
|
|
4313
|
+
version: "0.4.0",
|
|
4309
4314
|
description: "Universal TypeScript LLM client with streaming-first agent framework. Works with any model - no structured outputs or native tool calling required. Implements its own flexible grammar for function calling.",
|
|
4310
4315
|
type: "module",
|
|
4311
4316
|
main: "dist/index.cjs",
|