gemini-branch 1.0.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.
- package/LICENSE +21 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +79 -0
- package/dist/index.js.map +1 -0
- package/geminibranch-1.0.0.tgz +0 -0
- package/package.json +35 -0
package/LICENSE
ADDED
|
@@ -0,0 +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.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAKA,MAAM,WAAW,mBAAmB;IAClC,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB;AAED,MAAM,WAAW,kBAAkB;IAC/B,QAAQ,EAAE,OAAO,CAAC;IAChB;;;OAGG;IACL,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;CACnB;AAwBD,wBAAsB,YAAY,CAAE,IAAI,EAAE,mBAAmB,GAAI,OAAO,CAAC,kBAAkB,CAAC,CAkE3F"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { GoogleGenAI } from '@google/genai';
|
|
2
|
+
/* ======================
|
|
3
|
+
* Fail function (Error handling)
|
|
4
|
+
* ====================== */
|
|
5
|
+
function fail(message, args) {
|
|
6
|
+
var _a, _b;
|
|
7
|
+
if ((_a = args.consoleErrors) !== null && _a !== void 0 ? _a : false) {
|
|
8
|
+
console.error(message);
|
|
9
|
+
}
|
|
10
|
+
return {
|
|
11
|
+
response: false,
|
|
12
|
+
result: (_b = args.else) !== null && _b !== void 0 ? _b : "",
|
|
13
|
+
message,
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
/* ======================
|
|
17
|
+
* Main function
|
|
18
|
+
* ====================== */
|
|
19
|
+
export async function GeminiBranch(args) {
|
|
20
|
+
var _a, _b;
|
|
21
|
+
try {
|
|
22
|
+
// condition is non-empty string check
|
|
23
|
+
if (typeof args.condition !== "string" || args.condition.trim() === "") {
|
|
24
|
+
return fail("condition must be a non-empty string", args);
|
|
25
|
+
}
|
|
26
|
+
// choices is non-empty array check
|
|
27
|
+
if (!Array.isArray(args.choices) || args.choices.length === 0) {
|
|
28
|
+
return fail("choices must be a non-empty array", args);
|
|
29
|
+
}
|
|
30
|
+
// Gemini API call
|
|
31
|
+
const ai = new GoogleGenAI({ apiKey: args.apiKey });
|
|
32
|
+
const response = await ai.models.generateContent({
|
|
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 : ""}
|
|
50
|
+
`,
|
|
51
|
+
});
|
|
52
|
+
const responsemsg = String((_b = response.text) !== null && _b !== void 0 ? _b : "").trim();
|
|
53
|
+
// args.else was selected(≒ Success)
|
|
54
|
+
if (args.else && responsemsg === (args.else)) {
|
|
55
|
+
return {
|
|
56
|
+
response: true,
|
|
57
|
+
result: args.else,
|
|
58
|
+
message: "No matching choice"
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
// response is not in args.choices
|
|
62
|
+
if (!args.choices.includes(responsemsg)) {
|
|
63
|
+
return fail("Response by Gemini is not in choices: " + responsemsg, args);
|
|
64
|
+
}
|
|
65
|
+
// Success
|
|
66
|
+
return {
|
|
67
|
+
response: true,
|
|
68
|
+
result: responsemsg,
|
|
69
|
+
message: "Success"
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
catch (e) {
|
|
73
|
+
// Gemini API error
|
|
74
|
+
return fail("Gemini API error: " + String(e), args);
|
|
75
|
+
}
|
|
76
|
+
// Unknown error
|
|
77
|
+
return fail("Unknown error", args);
|
|
78
|
+
}
|
|
79
|
+
//# sourceMappingURL=index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AAS,CAAC;qBAChC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC;;;;;;;;;wCAST,MAAA,IAAI,CAAC,IAAI,mCAAI,EAAE;OAChD;SACF,CAAC,CAAC;QAEH,MAAM,WAAW,GAAG,MAAM,CAAC,MAAA,QAAQ,CAAC,IAAI,mCAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;QAEvD,oCAAoC;QACpC,IAAI,IAAI,CAAC,IAAI,IAAI,WAAW,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;YAC7C,OAAO;gBACL,QAAQ,EAAE,IAAI;gBACd,MAAM,EAAE,IAAI,CAAC,IAAI;gBACjB,OAAO,EAAE,oBAAoB;aAC9B,CAAC;QACJ,CAAC;QAED,kCAAkC;QAClC,IAAG,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAC,EAAC,CAAC;YACtC,OAAO,IAAI,CAAC,wCAAwC,GAAG,WAAW,EAAE,IAAI,CAAC,CAAC;QAC5E,CAAC;QAED,UAAU;QACV,OAAO;YACL,QAAQ,EAAE,IAAI;YACd,MAAM,EAAE,WAAW;YACnB,OAAO,EAAE,SAAS;SACnB,CAAC;IAEJ,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,mBAAmB;QACnB,OAAO,IAAI,CAAC,oBAAoB,GAAG,MAAM,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC;IACtD,CAAC;IAGD,gBAAgB;IAChB,OAAO,IAAI,CAAC,eAAe,EAAE,IAAI,CAAC,CAAC;AACrC,CAAC"}
|
|
Binary file
|
package/package.json
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "gemini-branch",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Perform conditional branching using Gemini in natural language.",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"build": "tsc"
|
|
8
|
+
},
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/kz7c/GeminiBranch.git"
|
|
12
|
+
},
|
|
13
|
+
"keywords": [
|
|
14
|
+
"AI",
|
|
15
|
+
"Gemini",
|
|
16
|
+
"Branching",
|
|
17
|
+
"Google",
|
|
18
|
+
"GenAI",
|
|
19
|
+
"Natural Language"
|
|
20
|
+
],
|
|
21
|
+
"author": "kz7c",
|
|
22
|
+
"license": "MIT",
|
|
23
|
+
"type": "module",
|
|
24
|
+
"bugs": {
|
|
25
|
+
"url": "https://github.com/kz7c/GeminiBranch/issues"
|
|
26
|
+
},
|
|
27
|
+
"homepage": "https://github.com/kz7c/GeminiBranch#readme",
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"@types/node": "^25.0.3",
|
|
30
|
+
"typescript": "^5.9.3"
|
|
31
|
+
},
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"@google/genai": "^1.35.0"
|
|
34
|
+
}
|
|
35
|
+
}
|