gemini-branch 1.0.1 → 1.0.3

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.
@@ -0,0 +1,30 @@
1
+ name: Publish to npm
2
+
3
+ on:
4
+ push:
5
+ tags:
6
+ - 'v*'
7
+
8
+ permissions:
9
+ contents: read
10
+ id-token: write
11
+
12
+ jobs:
13
+ publish:
14
+ runs-on: ubuntu-slim
15
+
16
+ permissions:
17
+ contents: read
18
+ id-token: write
19
+
20
+ steps:
21
+ - uses: actions/checkout@v4
22
+
23
+ - name: Install dependencies
24
+ run: npm ci
25
+
26
+ - name: Build
27
+ run: npm run build --if-present
28
+
29
+ - name: Publish
30
+ run: npm publish
package/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2026 kz7c
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2026 kz7c
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,54 +1,66 @@
1
- # GeminiBranch
2
- [![npm version](https://img.shields.io/npm/v/gemini-branch.svg)](https://www.npmjs.com/package/gemini-branch)
3
- [![license](https://img.shields.io/npm/l/gemini-branch.svg)](LICENSE)
4
-
5
- This library performs conditional branching using natural language, powered by Google's Gemini API.
6
- Think of it as a natural language `if/else` or `switch` statement.
7
-
8
- ## Features
9
- - **Natural Language branching**: Branch complex, nuanced, or subjective conditions that are difficult to express with traditional code.
10
- - **Dynamic Branching**: Select the most appropriate option from a set of choices based on a natural language prompt.
11
- - **Simple & Typed API**: Easy-to-use, typed interface for seamless integration into TypeScript projects.
12
- - **Error Handling**: Built-in error handling for API failures and unexpected responses.
13
-
14
- ## Installation
15
- ```shell
16
- npm install gemini-branch
17
- ```
18
-
19
- ## Usage
20
- First, obtain a Google Gemini API key. You can get one from the [Google AI Studio](https://aistudio.google.com/app/apikey).
21
-
22
- =========ここにサンプル後で書く=========
23
- ```
24
-
25
- ```
26
-
27
- ## Model Selection
28
- You need to select a model from the [Gemini](https://ai.google.dev/gemini-api/docs/models) or [Gemma 3](https://ai.google.dev/gemma/docs/core) model list.
29
-
30
-
31
- ## API Reference
32
- GeminiBranch is the main function that performs the conditional branching.
33
-
34
- ### GeminiBranchOptions
35
- | Parameter | Type | Description | Required |
36
- |-----------|------|-------------|----------|
37
- | condition | string | The natural language condition used for branching. | Yes |
38
- | choices | string[] | A list of candidate values. Gemini selects the single best-matching option. | Yes |
39
- | apiKey | string | Your Google Gemini API Key. | Yes |
40
- | model | string | The model to use for branching. | Yes |
41
- | else | string | A fallback value returned when no choice sufficiently matches the condition. | No |
42
- | consoleErrors | boolean | Log internal errors to the console. Default is false. | No |
43
-
44
- ### GeminiBranchResult
45
- | Parameter | Type | Description |
46
- |-----------|------|-------------|
47
- | response | boolean | **true** : The library executed correctly (including when the fallback `else` value is returned). <br> **false** : An internal error occurred (API failure, schema violation, etc.). |
48
- | result | string | On success, a Gemini-selected value from `choices` or the fallback (`else`) value; on failure, `""` or the `else` value if provided. |
49
- | message | string | Error message on failure, `"Success"` on success, "No matching choice" when `else` is selected |
50
-
51
- ⚠️ If `else` is not provided, the model is instructed to output `""` when no choice matches.
52
-
53
- ## License
1
+ # GeminiBranch
2
+ [![npm version](https://img.shields.io/npm/v/gemini-branch.svg)](https://www.npmjs.com/package/gemini-branch)
3
+ [![license](https://img.shields.io/npm/l/gemini-branch.svg)](LICENSE)
4
+
5
+ This library performs conditional branching using natural language, powered by Google's Gemini API.
6
+ Think of it as a natural language `if/else` or `switch` statement.
7
+
8
+ ## Features
9
+ - **Natural Language branching**: Branch complex, nuanced, or subjective conditions that are difficult to express with traditional code.
10
+ - **Dynamic Branching**: Select the most appropriate option from a set of choices based on a natural language prompt.
11
+ - **Simple & Typed API**: Easy-to-use, typed interface for seamless integration into TypeScript projects.
12
+ - **Error Handling**: Built-in error handling for API failures and unexpected responses.
13
+
14
+ ## Installation
15
+ ```shell
16
+ npm install gemini-branch
17
+ ```
18
+
19
+ ## Usage
20
+ First, obtain a Google Gemini API key. You can get one from the [Google AI Studio](https://aistudio.google.com/app/apikey).
21
+
22
+ ```typescript
23
+ import { GeminiBranch } from 'gemini-branch';
24
+ import type { GeminiBranchResult } from 'gemini-branch';
25
+
26
+ let globalBranchResult: GeminiBranchResult | null = null;
27
+
28
+ globalBranchResult = await GeminiBranch({
29
+ condition: "Which is the morning greeting?",
30
+ choices: ["good morning", "hello", "good evening"],
31
+ apiKey: "YOUR GEMINI API KEY",
32
+ model: "gemma-3-27b-it",
33
+ });
34
+
35
+ console.log(globalBranchResult)
36
+ // { response: true, result: 'good morning', message: 'Success' }
37
+ ```
38
+
39
+ ## Model Selection
40
+ You need to select a model from the [Gemini](https://ai.google.dev/gemini-api/docs/models) or [Gemma 3](https://ai.google.dev/gemma/docs/core) model list.
41
+
42
+
43
+ ## API Reference
44
+ GeminiBranch is the main function that performs the conditional branching.
45
+
46
+ ### GeminiBranchOptions
47
+ | Parameter | Type | Description | Required |
48
+ |-----------|------|-------------|----------|
49
+ | condition | string | The natural language condition used for branching. | Yes |
50
+ | choices | string[] | A list of candidate values. Gemini selects the single best-matching option. | Yes |
51
+ | apiKey | string | Your Google Gemini API Key. | Yes |
52
+ | model | string | The model to use for branching. | Yes |
53
+ | else | string | A fallback value returned when no choice sufficiently matches the condition. | No |
54
+ | consoleErrors | boolean | Log internal errors to the console. Default is false. | No |
55
+
56
+ ### GeminiBranchResult
57
+ | Parameter | Type | Description |
58
+ |-----------|------|-------------|
59
+ | response | boolean | **true** : The library executed correctly (including when the fallback `else` value is returned). <br> **false** : An internal error occurred (API failure, schema violation, etc.). |
60
+ | result | string | On success, a Gemini-selected value from `choices` or the fallback (`else`) value; on failure, `""` or the `else` value if provided. |
61
+ | message | string | Error message on failure, `"Success"` on success, "No matching choice" when `else` is selected |
62
+
63
+ ⚠️ If `else` is not provided, the model is instructed to output `""` when no choice matches.
64
+
65
+ ## License
54
66
  This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.
package/dist/index.js CHANGED
@@ -31,22 +31,22 @@ export async function GeminiBranch(args) {
31
31
  const ai = new GoogleGenAI({ apiKey: args.apiKey });
32
32
  const response = await ai.models.generateContent({
33
33
  model: args.model,
34
- contents: `
35
- You are a strict conditional branching engine.
36
- From the "choices" array in the JSON below, output **exactly one element that matches completely**.
37
-
38
- {
39
- "condition": ${JSON.stringify(args.condition)},
40
- "choices": ${JSON.stringify(args.choices)}
41
- }
42
-
43
- Output rules:
44
- - Output exactly one element from "choices"
45
- - Do NOT output JSON
46
- - Do NOT add explanations
47
- - Do NOT add extra spaces or line breaks
48
- - Do NOT output anything other than an element from "choices"
49
- - If no element matches, output ${(_a = args.else) !== null && _a !== void 0 ? _a : ""}
34
+ contents: `
35
+ You are a strict conditional branching engine.
36
+ From the "choices" array in the JSON below, output **exactly one element that matches completely**.
37
+
38
+ {
39
+ "condition": ${JSON.stringify(args.condition)},
40
+ "choices": ${JSON.stringify(args.choices)}
41
+ }
42
+
43
+ Output rules:
44
+ - Output exactly one element from "choices"
45
+ - Do NOT output JSON
46
+ - Do NOT add explanations
47
+ - Do NOT add extra spaces or line breaks
48
+ - Do NOT output anything other than an element from "choices"
49
+ - If no element matches, output ${(_a = args.else) !== null && _a !== void 0 ? _a : ""}
50
50
  `,
51
51
  });
52
52
  const responsemsg = String((_b = response.text) !== null && _b !== void 0 ? _b : "").trim();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gemini-branch",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "Perform conditional branching using Gemini in natural language.",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
Binary file