@equationalapplications/core-llm-tools 6.4.0 → 6.5.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/README.md +7 -8
- package/dist/index.d.mts +22 -7
- package/dist/index.d.ts +22 -7
- package/dist/index.js +9 -9
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +8 -9
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -60,10 +60,10 @@ export const getCalendarEventsManifest: AgentToolManifest = {
|
|
|
60
60
|
|
|
61
61
|
### 2. Injecting Authorized Tools
|
|
62
62
|
|
|
63
|
-
At runtime, use `
|
|
63
|
+
At runtime, use `buildAuthorizedToolsArray` to filter your tool library against the user's granted permissions. It returns the full Gemini `tools[]` array: at most one `functionDeclarations` group containing every authorized function tool's schema, plus one entry per authorized built-in tool (e.g. Google Search grounding).
|
|
64
64
|
|
|
65
65
|
```typescript
|
|
66
|
-
import {
|
|
66
|
+
import { buildAuthorizedToolsArray, escalateToCloudManifest } from '@equationalapplications/core-llm-tools';
|
|
67
67
|
|
|
68
68
|
// 1. Gather all manifests known to your app
|
|
69
69
|
const allAppTools = [escalateToCloudManifest, getCalendarEventsManifest];
|
|
@@ -71,14 +71,16 @@ const allAppTools = [escalateToCloudManifest, getCalendarEventsManifest];
|
|
|
71
71
|
// 2. Fetch the user's authorized scopes from your DB (e.g., SQLite/Postgres)
|
|
72
72
|
const userGrantedScopes = ['calendar:read'];
|
|
73
73
|
|
|
74
|
-
// 3. The injector automatically includes 'core' tools and authorized scoped tools
|
|
75
|
-
|
|
74
|
+
// 3. The injector automatically includes 'core' tools and authorized scoped tools,
|
|
75
|
+
// collapsing all authorized function tools into a single functionDeclarations group
|
|
76
|
+
const tools = buildAuthorizedToolsArray(allAppTools, userGrantedScopes);
|
|
77
|
+
// => [{ functionDeclarations: [get_calendar_events, escalate_to_cloud] }]
|
|
76
78
|
|
|
77
79
|
// 4. Pass safely to Gemini
|
|
78
80
|
const response = await ai.models.generateContent({
|
|
79
81
|
model: 'gemini-2.5-flash',
|
|
80
82
|
contents: userInput,
|
|
81
|
-
tools
|
|
83
|
+
tools,
|
|
82
84
|
});
|
|
83
85
|
```
|
|
84
86
|
|
|
@@ -114,9 +116,6 @@ const response = await ai.models.generateContent({
|
|
|
114
116
|
> (search queries, source citations, etc.) on the response. Parsing that metadata is the
|
|
115
117
|
> caller's responsibility — this package only handles the request-side tool declaration.
|
|
116
118
|
|
|
117
|
-
`buildAuthorizedSchemaArray` is still available for callers that only ever use function tools,
|
|
118
|
-
but is deprecated in favor of `buildAuthorizedToolsArray`.
|
|
119
|
-
|
|
120
119
|
## Helpful Resources & Links
|
|
121
120
|
|
|
122
121
|
- [Google Gen AI: Function Calling Tutorial](https://ai.google.dev/gemini-api/docs/function-calling) — Official docs on how the JSON schemas in this package interact with Gemini models.
|
package/dist/index.d.mts
CHANGED
|
@@ -30,12 +30,6 @@ type AgentToolManifest = FunctionToolManifest;
|
|
|
30
30
|
/** Union of function and built-in manifests for mixed tool arrays. */
|
|
31
31
|
type AnyAgentToolManifest = FunctionToolManifest | BuiltInToolManifest;
|
|
32
32
|
|
|
33
|
-
/**
|
|
34
|
-
* @deprecated Use buildAuthorizedToolsArray instead — it returns the full Gemini
|
|
35
|
-
* tools[] array, including built-in tools like google_search. This function only
|
|
36
|
-
* ever returns function-declaration schemas; built-in manifests are ignored.
|
|
37
|
-
*/
|
|
38
|
-
declare function buildAuthorizedSchemaArray(availableManifests: AgentToolManifest[], userGrantedScopes: string[]): AgentToolSchema[];
|
|
39
33
|
/** One entry of a Gemini `tools[]` array: a function-declarations group, or a built-in tool. */
|
|
40
34
|
type GeminiToolEntry = {
|
|
41
35
|
functionDeclarations: AgentToolSchema[];
|
|
@@ -49,6 +43,27 @@ type GeminiToolEntry = {
|
|
|
49
43
|
*/
|
|
50
44
|
declare function buildAuthorizedToolsArray(availableManifests: AnyAgentToolManifest[], userGrantedScopes: string[]): GeminiToolEntry[];
|
|
51
45
|
|
|
46
|
+
/**
|
|
47
|
+
* Scopes that are ALWAYS authorized, with no user grant required.
|
|
48
|
+
*
|
|
49
|
+
* Single source of truth: tool *injection* (buildAuthorizedToolsArray) and tool
|
|
50
|
+
* *execution* (scopelab's function-caller) must agree on this list. Never write
|
|
51
|
+
* the 'core' literal in scope-check code.
|
|
52
|
+
*
|
|
53
|
+
* `satisfies readonly AgentScope[]` makes drift from the AgentScope union a
|
|
54
|
+
* compile error.
|
|
55
|
+
*/
|
|
56
|
+
declare const AUTHORIZED_SCOPES: readonly ["core"];
|
|
57
|
+
type AuthorizedScope = (typeof AUTHORIZED_SCOPES)[number];
|
|
58
|
+
/**
|
|
59
|
+
* Fail-closed guard: true only for always-on scopes.
|
|
60
|
+
*
|
|
61
|
+
* The `as readonly string[]` cast is required — TypeScript's `.includes()` on a
|
|
62
|
+
* `readonly ['core']` tuple demands a `'core'` argument, but callers pass the
|
|
63
|
+
* wider `AgentScope` / `string`.
|
|
64
|
+
*/
|
|
65
|
+
declare function isAuthorizedScope(scope: string): scope is AuthorizedScope;
|
|
66
|
+
|
|
52
67
|
declare const getCurrentTimeManifest: AgentToolManifest;
|
|
53
68
|
declare const escalateToCloudManifest: AgentToolManifest;
|
|
54
69
|
declare const googleSearchManifest: BuiltInToolManifest;
|
|
@@ -56,4 +71,4 @@ declare const googleSearchManifest: BuiltInToolManifest;
|
|
|
56
71
|
declare const wikiGetOntologyManifest: AgentToolManifest;
|
|
57
72
|
declare const wikiTraverseGraphManifest: AgentToolManifest;
|
|
58
73
|
|
|
59
|
-
export { type AgentScope, type AgentToolManifest, type AgentToolSchema, type AnyAgentToolManifest, type BuiltInToolManifest, type BuiltInToolName, type FunctionToolManifest, type GeminiToolEntry,
|
|
74
|
+
export { AUTHORIZED_SCOPES, type AgentScope, type AgentToolManifest, type AgentToolSchema, type AnyAgentToolManifest, type AuthorizedScope, type BuiltInToolManifest, type BuiltInToolName, type FunctionToolManifest, type GeminiToolEntry, buildAuthorizedToolsArray, escalateToCloudManifest, getCurrentTimeManifest, googleSearchManifest, isAuthorizedScope, wikiGetOntologyManifest, wikiTraverseGraphManifest };
|
package/dist/index.d.ts
CHANGED
|
@@ -30,12 +30,6 @@ type AgentToolManifest = FunctionToolManifest;
|
|
|
30
30
|
/** Union of function and built-in manifests for mixed tool arrays. */
|
|
31
31
|
type AnyAgentToolManifest = FunctionToolManifest | BuiltInToolManifest;
|
|
32
32
|
|
|
33
|
-
/**
|
|
34
|
-
* @deprecated Use buildAuthorizedToolsArray instead — it returns the full Gemini
|
|
35
|
-
* tools[] array, including built-in tools like google_search. This function only
|
|
36
|
-
* ever returns function-declaration schemas; built-in manifests are ignored.
|
|
37
|
-
*/
|
|
38
|
-
declare function buildAuthorizedSchemaArray(availableManifests: AgentToolManifest[], userGrantedScopes: string[]): AgentToolSchema[];
|
|
39
33
|
/** One entry of a Gemini `tools[]` array: a function-declarations group, or a built-in tool. */
|
|
40
34
|
type GeminiToolEntry = {
|
|
41
35
|
functionDeclarations: AgentToolSchema[];
|
|
@@ -49,6 +43,27 @@ type GeminiToolEntry = {
|
|
|
49
43
|
*/
|
|
50
44
|
declare function buildAuthorizedToolsArray(availableManifests: AnyAgentToolManifest[], userGrantedScopes: string[]): GeminiToolEntry[];
|
|
51
45
|
|
|
46
|
+
/**
|
|
47
|
+
* Scopes that are ALWAYS authorized, with no user grant required.
|
|
48
|
+
*
|
|
49
|
+
* Single source of truth: tool *injection* (buildAuthorizedToolsArray) and tool
|
|
50
|
+
* *execution* (scopelab's function-caller) must agree on this list. Never write
|
|
51
|
+
* the 'core' literal in scope-check code.
|
|
52
|
+
*
|
|
53
|
+
* `satisfies readonly AgentScope[]` makes drift from the AgentScope union a
|
|
54
|
+
* compile error.
|
|
55
|
+
*/
|
|
56
|
+
declare const AUTHORIZED_SCOPES: readonly ["core"];
|
|
57
|
+
type AuthorizedScope = (typeof AUTHORIZED_SCOPES)[number];
|
|
58
|
+
/**
|
|
59
|
+
* Fail-closed guard: true only for always-on scopes.
|
|
60
|
+
*
|
|
61
|
+
* The `as readonly string[]` cast is required — TypeScript's `.includes()` on a
|
|
62
|
+
* `readonly ['core']` tuple demands a `'core'` argument, but callers pass the
|
|
63
|
+
* wider `AgentScope` / `string`.
|
|
64
|
+
*/
|
|
65
|
+
declare function isAuthorizedScope(scope: string): scope is AuthorizedScope;
|
|
66
|
+
|
|
52
67
|
declare const getCurrentTimeManifest: AgentToolManifest;
|
|
53
68
|
declare const escalateToCloudManifest: AgentToolManifest;
|
|
54
69
|
declare const googleSearchManifest: BuiltInToolManifest;
|
|
@@ -56,4 +71,4 @@ declare const googleSearchManifest: BuiltInToolManifest;
|
|
|
56
71
|
declare const wikiGetOntologyManifest: AgentToolManifest;
|
|
57
72
|
declare const wikiTraverseGraphManifest: AgentToolManifest;
|
|
58
73
|
|
|
59
|
-
export { type AgentScope, type AgentToolManifest, type AgentToolSchema, type AnyAgentToolManifest, type BuiltInToolManifest, type BuiltInToolName, type FunctionToolManifest, type GeminiToolEntry,
|
|
74
|
+
export { AUTHORIZED_SCOPES, type AgentScope, type AgentToolManifest, type AgentToolSchema, type AnyAgentToolManifest, type AuthorizedScope, type BuiltInToolManifest, type BuiltInToolName, type FunctionToolManifest, type GeminiToolEntry, buildAuthorizedToolsArray, escalateToCloudManifest, getCurrentTimeManifest, googleSearchManifest, isAuthorizedScope, wikiGetOntologyManifest, wikiTraverseGraphManifest };
|
package/dist/index.js
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
// src/
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
).filter(
|
|
8
|
-
(manifest) => "schema" in manifest
|
|
9
|
-
).map((manifest) => manifest.schema);
|
|
3
|
+
// src/scopes.ts
|
|
4
|
+
var AUTHORIZED_SCOPES = Object.freeze(["core"]);
|
|
5
|
+
function isAuthorizedScope(scope) {
|
|
6
|
+
return AUTHORIZED_SCOPES.includes(scope);
|
|
10
7
|
}
|
|
8
|
+
|
|
9
|
+
// src/injector.ts
|
|
11
10
|
function buildAuthorizedToolsArray(availableManifests, userGrantedScopes) {
|
|
12
11
|
const authorized = availableManifests.filter(
|
|
13
|
-
(manifest) => manifest.scope
|
|
12
|
+
(manifest) => isAuthorizedScope(manifest.scope) || userGrantedScopes.includes(manifest.scope)
|
|
14
13
|
);
|
|
15
14
|
const entries = [];
|
|
16
15
|
const fnSchemas = authorized.filter(
|
|
@@ -92,11 +91,12 @@ var wikiTraverseGraphManifest = {
|
|
|
92
91
|
}
|
|
93
92
|
};
|
|
94
93
|
|
|
95
|
-
exports.
|
|
94
|
+
exports.AUTHORIZED_SCOPES = AUTHORIZED_SCOPES;
|
|
96
95
|
exports.buildAuthorizedToolsArray = buildAuthorizedToolsArray;
|
|
97
96
|
exports.escalateToCloudManifest = escalateToCloudManifest;
|
|
98
97
|
exports.getCurrentTimeManifest = getCurrentTimeManifest;
|
|
99
98
|
exports.googleSearchManifest = googleSearchManifest;
|
|
99
|
+
exports.isAuthorizedScope = isAuthorizedScope;
|
|
100
100
|
exports.wikiGetOntologyManifest = wikiGetOntologyManifest;
|
|
101
101
|
exports.wikiTraverseGraphManifest = wikiTraverseGraphManifest;
|
|
102
102
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/injector.ts","../src/manifests/core.ts","../src/manifests/graph.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"sources":["../src/scopes.ts","../src/injector.ts","../src/manifests/core.ts","../src/manifests/graph.ts"],"names":[],"mappings":";;;AAeO,IAAM,iBAAA,GAAoB,MAAA,CAAO,MAAA,CAAO,CAAC,MAAM,CAAU;AAWzD,SAAS,kBAAkB,KAAA,EAAyC;AACzE,EAAA,OAAQ,iBAAA,CAAwC,SAAS,KAAK,CAAA;AAChE;;;ACTO,SAAS,yBAAA,CACd,oBACA,iBAAA,EACmB;AACnB,E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,EAAM,QAAA,EAAS,EAAG,WAAA,EAAa,4GAAA;AAA6G,OACnL;AAAA,MACA,QAAA,EAAU,CAAC,UAAA,EAAY,UAAU;AAAA;AACnC;AAEJ","file":"index.js","sourcesContent":["import type { AgentScope } from './types';\n\n/**\n * Scopes that are ALWAYS authorized, with no user grant required.\n *\n * Single source of truth: tool *injection* (buildAuthorizedToolsArray) and tool\n * *execution* (scopelab's function-caller) must agree on this list. Never write\n * the 'core' literal in scope-check code.\n *\n * `satisfies readonly AgentScope[]` makes drift from the AgentScope union a\n * compile error.\n */\n// Object.freeze, not just `as const`: the latter is compile-time only, so a JS\n// consumer (or TS via `any`) could push() at runtime and silently widen\n// always-on authorization for every downstream check in the process.\nexport const AUTHORIZED_SCOPES = Object.freeze(['core'] as const) satisfies readonly AgentScope[];\n\nexport type AuthorizedScope = (typeof AUTHORIZED_SCOPES)[number];\n\n/**\n * Fail-closed guard: true only for always-on scopes.\n *\n * The `as readonly string[]` cast is required — TypeScript's `.includes()` on a\n * `readonly ['core']` tuple demands a `'core'` argument, but callers pass the\n * wider `AgentScope` / `string`.\n */\nexport function isAuthorizedScope(scope: string): scope is AuthorizedScope {\n return (AUTHORIZED_SCOPES as readonly string[]).includes(scope);\n}\n","import type {\n AgentToolManifest,\n AgentToolSchema,\n AnyAgentToolManifest,\n BuiltInToolName,\n FunctionToolManifest,\n} from './types';\nimport { isAuthorizedScope } from './scopes';\n\n/** One entry of a Gemini `tools[]` array: a function-declarations group, or a built-in tool. */\nexport type GeminiToolEntry =\n | { functionDeclarations: AgentToolSchema[] }\n | { [K in BuiltInToolName]: Record<string, never> };\n\n/**\n * Filters manifests by granted scope (core-scoped manifests always pass) and\n * returns the full Gemini tools[] array: at most one functionDeclarations\n * group, plus one entry per authorized built-in tool.\n */\nexport function buildAuthorizedToolsArray(\n availableManifests: AnyAgentToolManifest[],\n userGrantedScopes: string[]\n): GeminiToolEntry[] {\n const authorized = availableManifests.filter(\n (manifest) =>\n isAuthorizedScope(manifest.scope) || userGrantedScopes.includes(manifest.scope)\n );\n\n const entries: GeminiToolEntry[] = [];\n\n const fnSchemas = authorized\n .filter(\n (manifest): manifest is FunctionToolManifest => manifest.kind !== 'built_in'\n )\n .map((manifest) => manifest.schema);\n if (fnSchemas.length > 0) entries.push({ functionDeclarations: fnSchemas });\n\n for (const manifest of authorized) {\n if (manifest.kind === 'built_in') {\n entries.push({ [manifest.builtIn]: {} } as GeminiToolEntry);\n }\n }\n\n return entries;\n}\n","import type { AgentToolManifest, BuiltInToolManifest } from '../types';\n\nexport const getCurrentTimeManifest: AgentToolManifest = {\n name: 'get_current_time',\n scope: 'core',\n schema: {\n name: 'get_current_time',\n description:\n 'Get the exact current date and time. Always call this tool first if resolving relative temporal words like \"today\" or \"tomorrow\".',\n parameters: { type: 'object', properties: {} },\n },\n};\n\nexport const escalateToCloudManifest: AgentToolManifest = {\n name: 'escalate_to_cloud_agent',\n scope: 'core',\n schema: {\n name: 'escalate_to_cloud_agent',\n description:\n 'Use this tool when the user asks to schedule a reminder, perform deep memory searches, or execute a complex workflow that requires cloud resources.',\n parameters: { type: 'object', properties: {} },\n },\n};\n\nexport const googleSearchManifest: BuiltInToolManifest = {\n name: 'google_search',\n scope: 'core',\n kind: 'built_in',\n builtIn: 'google_search',\n};\n","import type { AgentToolManifest } from '../types';\n\nexport const wikiGetOntologyManifest: AgentToolManifest = {\n name: 'wiki_get_ontology',\n scope: 'memory:read',\n schema: {\n name: 'wiki_get_ontology',\n description:\n \"Retrieve the current ontology manifest (allowed node types and edge types) for the user's memory. Use this to understand the structure of the knowledge graph and what relationships exist.\",\n parameters: {\n type: 'object',\n properties: {\n entityId: { type: 'string', description: 'The namespace/entity ID to inspect.' },\n },\n required: ['entityId'],\n },\n },\n};\n\nexport const wikiTraverseGraphManifest: AgentToolManifest = {\n name: 'wiki_traverse_graph',\n scope: 'memory:read',\n schema: {\n name: 'wiki_traverse_graph',\n description:\n 'Traverse the knowledge graph starting from a specific fact ID to discover connected concepts and relationships. Returns a formatted neighborhood subgraph.',\n parameters: {\n type: 'object',\n properties: {\n entityId: { type: 'string', description: 'The namespace/entity ID to traverse.' },\n sourceId: { type: 'string', description: 'The exact ID of the starting fact node (obtained from a previous wiki_read call).' },\n maxDepth: {\n type: 'integer',\n minimum: 1,\n maximum: 3,\n description: 'How many relationship hops to traverse. Maximum allowed is 3.',\n },\n direction: { type: 'string', enum: ['inbound', 'outbound', 'both'], description: \"The direction of relationships to follow. Default 'both'.\" },\n edgeTypes: { type: 'array', items: { type: 'string' }, description: 'Optional filter. If provided, traversal only follows these edge types (e.g. [\"reports_to\", \"depends_on\"]).' },\n },\n required: ['entityId', 'sourceId'],\n },\n },\n};\n"]}
|
package/dist/index.mjs
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
// src/
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
).filter(
|
|
6
|
-
(manifest) => "schema" in manifest
|
|
7
|
-
).map((manifest) => manifest.schema);
|
|
1
|
+
// src/scopes.ts
|
|
2
|
+
var AUTHORIZED_SCOPES = Object.freeze(["core"]);
|
|
3
|
+
function isAuthorizedScope(scope) {
|
|
4
|
+
return AUTHORIZED_SCOPES.includes(scope);
|
|
8
5
|
}
|
|
6
|
+
|
|
7
|
+
// src/injector.ts
|
|
9
8
|
function buildAuthorizedToolsArray(availableManifests, userGrantedScopes) {
|
|
10
9
|
const authorized = availableManifests.filter(
|
|
11
|
-
(manifest) => manifest.scope
|
|
10
|
+
(manifest) => isAuthorizedScope(manifest.scope) || userGrantedScopes.includes(manifest.scope)
|
|
12
11
|
);
|
|
13
12
|
const entries = [];
|
|
14
13
|
const fnSchemas = authorized.filter(
|
|
@@ -90,6 +89,6 @@ var wikiTraverseGraphManifest = {
|
|
|
90
89
|
}
|
|
91
90
|
};
|
|
92
91
|
|
|
93
|
-
export {
|
|
92
|
+
export { AUTHORIZED_SCOPES, buildAuthorizedToolsArray, escalateToCloudManifest, getCurrentTimeManifest, googleSearchManifest, isAuthorizedScope, wikiGetOntologyManifest, wikiTraverseGraphManifest };
|
|
94
93
|
//# sourceMappingURL=index.mjs.map
|
|
95
94
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/injector.ts","../src/manifests/core.ts","../src/manifests/graph.ts"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"sources":["../src/scopes.ts","../src/injector.ts","../src/manifests/core.ts","../src/manifests/graph.ts"],"names":[],"mappings":";AAeO,IAAM,iBAAA,GAAoB,MAAA,CAAO,MAAA,CAAO,CAAC,MAAM,CAAU;AAWzD,SAAS,kBAAkB,KAAA,EAAyC;AACzE,EAAA,OAAQ,iBAAA,CAAwC,SAAS,KAAK,CAAA;AAChE;;;ACTO,SAAS,yBAAA,CACd,oBACA,iBAAA,EACmB;AACnB,EAAA,MAAM,aAAa,kBAAA,CAAmB,MAAA;AAAA,IACpC,CAAC,aACC,iBAAA,CAAkB,QAAA,CAAS,KAAK,CAAA,IAAK,iBAAA,CAAkB,QAAA,CAAS,QAAA,CAAS,KAAK;AAAA,GAClF;AAEA,EAAA,MAAM,UAA6B,EAAC;AAEpC,EAAA,MAAM,YAAY,UAAA,CACf,MAAA;AAAA,IACC,CAAC,QAAA,KAA+C,QAAA,CAAS,IAAA,KAAS;AAAA,GACpE,CACC,GAAA,CAAI,CAAC,QAAA,KAAa,SAAS,MAAM,CAAA;AACpC,EAAA,IAAI,SAAA,CAAU,SAAS,CAAA,EAAG,OAAA,CAAQ,KAAK,EAAE,oBAAA,EAAsB,WAAW,CAAA;AAE1E,EAAA,KAAA,MAAW,YAAY,UAAA,EAAY;AACjC,IAAA,IAAI,QAAA,CAAS,SAAS,UAAA,EAAY;AAChC,MAAA,OAAA,CAAQ,IAAA,CAAK,EAAE,CAAC,QAAA,CAAS,OAAO,GAAG,IAAuB,CAAA;AAAA,IAC5D;AAAA,EACF;AAEA,EAAA,OAAO,OAAA;AAC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AA,EAAM,QAAA;AAAA,MACN,UAAA,EAAY;AAAA,QACV,QAAA,EAAU,EAAE,IAAA,EAAM,QAAA,EAAU,aAAa,sCAAA,EAAuC;AAAA,QAChF,QAAA,EAAU,EAAE,IAAA,EAAM,QAAA,EAAU,aAAa,mFAAA,EAAoF;AAAA,QAC7H,QAAA,EAAU;AAAA,UACR,IAAA,EAAM,SAAA;AAAA,UACN,OAAA,EAAS,CAAA;AAAA,UACT,OAAA,EAAS,CAAA;AAAA,UACT,WAAA,EAAa;AAAA,SACf;AAAA,QACA,SAAA,EAAW,EAAE,IAAA,EAAM,QAAA,EAAU,IAAA,EAAM,CAAC,SAAA,EAAW,UAAA,EAAY,MAAM,CAAA,EAAG,WAAA,EAAa,2DAAA,EAA4D;AAAA,QAC7I,SAAA,EAAW,EAAE,IAAA,EAAM,OAAA,EAAS,KAAA,EAAO,EAAE,IAAA,EAAM,QAAA,EAAS,EAAG,WAAA,EAAa,4GAAA;AAA6G,OACnL;AAAA,MACA,QAAA,EAAU,CAAC,UAAA,EAAY,UAAU;AAAA;AACnC;AAEJ","file":"index.mjs","sourcesContent":["import type { AgentScope } from './types';\n\n/**\n * Scopes that are ALWAYS authorized, with no user grant required.\n *\n * Single source of truth: tool *injection* (buildAuthorizedToolsArray) and tool\n * *execution* (scopelab's function-caller) must agree on this list. Never write\n * the 'core' literal in scope-check code.\n *\n * `satisfies readonly AgentScope[]` makes drift from the AgentScope union a\n * compile error.\n */\n// Object.freeze, not just `as const`: the latter is compile-time only, so a JS\n// consumer (or TS via `any`) could push() at runtime and silently widen\n// always-on authorization for every downstream check in the process.\nexport const AUTHORIZED_SCOPES = Object.freeze(['core'] as const) satisfies readonly AgentScope[];\n\nexport type AuthorizedScope = (typeof AUTHORIZED_SCOPES)[number];\n\n/**\n * Fail-closed guard: true only for always-on scopes.\n *\n * The `as readonly string[]` cast is required — TypeScript's `.includes()` on a\n * `readonly ['core']` tuple demands a `'core'` argument, but callers pass the\n * wider `AgentScope` / `string`.\n */\nexport function isAuthorizedScope(scope: string): scope is AuthorizedScope {\n return (AUTHORIZED_SCOPES as readonly string[]).includes(scope);\n}\n","import type {\n AgentToolManifest,\n AgentToolSchema,\n AnyAgentToolManifest,\n BuiltInToolName,\n FunctionToolManifest,\n} from './types';\nimport { isAuthorizedScope } from './scopes';\n\n/** One entry of a Gemini `tools[]` array: a function-declarations group, or a built-in tool. */\nexport type GeminiToolEntry =\n | { functionDeclarations: AgentToolSchema[] }\n | { [K in BuiltInToolName]: Record<string, never> };\n\n/**\n * Filters manifests by granted scope (core-scoped manifests always pass) and\n * returns the full Gemini tools[] array: at most one functionDeclarations\n * group, plus one entry per authorized built-in tool.\n */\nexport function buildAuthorizedToolsArray(\n availableManifests: AnyAgentToolManifest[],\n userGrantedScopes: string[]\n): GeminiToolEntry[] {\n const authorized = availableManifests.filter(\n (manifest) =>\n isAuthorizedScope(manifest.scope) || userGrantedScopes.includes(manifest.scope)\n );\n\n const entries: GeminiToolEntry[] = [];\n\n const fnSchemas = authorized\n .filter(\n (manifest): manifest is FunctionToolManifest => manifest.kind !== 'built_in'\n )\n .map((manifest) => manifest.schema);\n if (fnSchemas.length > 0) entries.push({ functionDeclarations: fnSchemas });\n\n for (const manifest of authorized) {\n if (manifest.kind === 'built_in') {\n entries.push({ [manifest.builtIn]: {} } as GeminiToolEntry);\n }\n }\n\n return entries;\n}\n","import type { AgentToolManifest, BuiltInToolManifest } from '../types';\n\nexport const getCurrentTimeManifest: AgentToolManifest = {\n name: 'get_current_time',\n scope: 'core',\n schema: {\n name: 'get_current_time',\n description:\n 'Get the exact current date and time. Always call this tool first if resolving relative temporal words like \"today\" or \"tomorrow\".',\n parameters: { type: 'object', properties: {} },\n },\n};\n\nexport const escalateToCloudManifest: AgentToolManifest = {\n name: 'escalate_to_cloud_agent',\n scope: 'core',\n schema: {\n name: 'escalate_to_cloud_agent',\n description:\n 'Use this tool when the user asks to schedule a reminder, perform deep memory searches, or execute a complex workflow that requires cloud resources.',\n parameters: { type: 'object', properties: {} },\n },\n};\n\nexport const googleSearchManifest: BuiltInToolManifest = {\n name: 'google_search',\n scope: 'core',\n kind: 'built_in',\n builtIn: 'google_search',\n};\n","import type { AgentToolManifest } from '../types';\n\nexport const wikiGetOntologyManifest: AgentToolManifest = {\n name: 'wiki_get_ontology',\n scope: 'memory:read',\n schema: {\n name: 'wiki_get_ontology',\n description:\n \"Retrieve the current ontology manifest (allowed node types and edge types) for the user's memory. Use this to understand the structure of the knowledge graph and what relationships exist.\",\n parameters: {\n type: 'object',\n properties: {\n entityId: { type: 'string', description: 'The namespace/entity ID to inspect.' },\n },\n required: ['entityId'],\n },\n },\n};\n\nexport const wikiTraverseGraphManifest: AgentToolManifest = {\n name: 'wiki_traverse_graph',\n scope: 'memory:read',\n schema: {\n name: 'wiki_traverse_graph',\n description:\n 'Traverse the knowledge graph starting from a specific fact ID to discover connected concepts and relationships. Returns a formatted neighborhood subgraph.',\n parameters: {\n type: 'object',\n properties: {\n entityId: { type: 'string', description: 'The namespace/entity ID to traverse.' },\n sourceId: { type: 'string', description: 'The exact ID of the starting fact node (obtained from a previous wiki_read call).' },\n maxDepth: {\n type: 'integer',\n minimum: 1,\n maximum: 3,\n description: 'How many relationship hops to traverse. Maximum allowed is 3.',\n },\n direction: { type: 'string', enum: ['inbound', 'outbound', 'both'], description: \"The direction of relationships to follow. Default 'both'.\" },\n edgeTypes: { type: 'array', items: { type: 'string' }, description: 'Optional filter. If provided, traversal only follows these edge types (e.g. [\"reports_to\", \"depends_on\"]).' },\n },\n required: ['entityId', 'sourceId'],\n },\n },\n};\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@equationalapplications/core-llm-tools",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.5.1",
|
|
4
4
|
"description": "Zero-dependency Gemini function-calling schemas and capability-scoped tool injection for edge AI agents. Works in Node.js, browser, and React Native (Hermes).",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|