@jini-ai/registry 0.6.15 → 0.6.16
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,15 @@
|
|
|
1
|
+
/** Search hits carry this compact argument line instead of the full input schema: a full schema
|
|
2
|
+
* on every hit doubled search output (7,988 -> 16,381 bytes for ten theme hits) on every search,
|
|
3
|
+
* every run, while the first call only needs each required name and its type. */
|
|
4
|
+
export declare const MAX_SIGNATURE_BYTES = 300;
|
|
5
|
+
/**
|
|
6
|
+
* A bounded one-line argument signature for a search hit, e.g. `themeId: string, includeTrash?: boolean`.
|
|
7
|
+
* Required fields come first; optional ones are dropped before the line exceeds the byte cap, and a
|
|
8
|
+
* line whose required part alone is too long tells the model to call describe_tool.
|
|
9
|
+
* @returns The signature, or undefined for a schema-less or non-object descriptor.
|
|
10
|
+
* @complexity O(p + e) for p properties and e enum values; pure.
|
|
11
|
+
*/
|
|
12
|
+
export declare function inputSignature({ inputSchema }: {
|
|
13
|
+
inputSchema: unknown;
|
|
14
|
+
}, _optional?: Record<string, never>): string | undefined;
|
|
15
|
+
//# sourceMappingURL=input-signature.d.ts.map
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { batchItemRequiredFields } from '@jini-ai/core';
|
|
2
|
+
/** Search hits carry this compact argument line instead of the full input schema: a full schema
|
|
3
|
+
* on every hit doubled search output (7,988 -> 16,381 bytes for ten theme hits) on every search,
|
|
4
|
+
* every run, while the first call only needs each required name and its type. */
|
|
5
|
+
export const MAX_SIGNATURE_BYTES = 300;
|
|
6
|
+
const DESCRIBE = 'call describe_tool for the arguments';
|
|
7
|
+
const MAX_ENUM_CHARS = 60;
|
|
8
|
+
function isSchema(value) {
|
|
9
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
10
|
+
}
|
|
11
|
+
function byteLength(text) {
|
|
12
|
+
return new TextEncoder().encode(text).length;
|
|
13
|
+
}
|
|
14
|
+
function scalarType(schema) {
|
|
15
|
+
if (Array.isArray(schema.enum)) {
|
|
16
|
+
const values = schema.enum.map(value => JSON.stringify(value)).join('|');
|
|
17
|
+
return values.length <= MAX_ENUM_CHARS ? values : 'enum';
|
|
18
|
+
}
|
|
19
|
+
return typeof schema.type === 'string' ? schema.type : 'any';
|
|
20
|
+
}
|
|
21
|
+
/** One nesting level: `{label: string, value?: string}`. Deeper shapes print their bare type. */
|
|
22
|
+
function objectShape(schema) {
|
|
23
|
+
if (!isSchema(schema.properties))
|
|
24
|
+
return undefined;
|
|
25
|
+
const required = Array.isArray(schema.required) ? schema.required : [];
|
|
26
|
+
const fields = Object.entries(schema.properties).map(([name, field]) => `${name}${required.includes(name) ? '' : '?'}: ${isSchema(field) ? scalarType(field) : 'any'}`);
|
|
27
|
+
return `{${fields.join(', ')}}`;
|
|
28
|
+
}
|
|
29
|
+
function typeLabel(schema) {
|
|
30
|
+
if (!isSchema(schema))
|
|
31
|
+
return 'any';
|
|
32
|
+
if (schema.type === 'array')
|
|
33
|
+
return `array<${isSchema(schema.items) ? objectShape(schema.items) ?? scalarType(schema.items) : 'any'}>`;
|
|
34
|
+
return objectShape(schema) ?? scalarType(schema);
|
|
35
|
+
}
|
|
36
|
+
/** Where the required names live: the schema itself, the first `anyOf` alternative (the primary
|
|
37
|
+
* form; others are aliases), or the items description a batch wrapper moved them into. */
|
|
38
|
+
function requiredNames(schema) {
|
|
39
|
+
if (Array.isArray(schema.required) && schema.required.length > 0)
|
|
40
|
+
return { names: schema.required.map(String), alternatives: false };
|
|
41
|
+
const first = Array.isArray(schema.anyOf) ? schema.anyOf[0] : undefined;
|
|
42
|
+
if (isSchema(first) && Array.isArray(first.required))
|
|
43
|
+
return { names: first.required.map(String), alternatives: true };
|
|
44
|
+
return { names: batchItemRequiredFields({ inputSchema: schema }), alternatives: false };
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* A bounded one-line argument signature for a search hit, e.g. `themeId: string, includeTrash?: boolean`.
|
|
48
|
+
* Required fields come first; optional ones are dropped before the line exceeds the byte cap, and a
|
|
49
|
+
* line whose required part alone is too long tells the model to call describe_tool.
|
|
50
|
+
* @returns The signature, or undefined for a schema-less or non-object descriptor.
|
|
51
|
+
* @complexity O(p + e) for p properties and e enum values; pure.
|
|
52
|
+
*/
|
|
53
|
+
export function inputSignature({ inputSchema }, _optional = {}) {
|
|
54
|
+
if (!isSchema(inputSchema) || !isSchema(inputSchema.properties))
|
|
55
|
+
return undefined;
|
|
56
|
+
const properties = inputSchema.properties;
|
|
57
|
+
const { names, alternatives } = requiredNames(inputSchema);
|
|
58
|
+
const required = names.map(name => `${name}: ${typeLabel(properties[name])}`);
|
|
59
|
+
const optional = Object.keys(properties).filter(name => !names.includes(name)).map(name => `${name}?: ${typeLabel(properties[name])}`);
|
|
60
|
+
const suffix = alternatives ? ' (other forms: describe_tool)' : '';
|
|
61
|
+
const full = [...required, ...optional].join(', ') + suffix;
|
|
62
|
+
if (full === '')
|
|
63
|
+
return 'no arguments';
|
|
64
|
+
if (byteLength(full) <= MAX_SIGNATURE_BYTES)
|
|
65
|
+
return full;
|
|
66
|
+
const requiredOnly = `${required.length > 0 ? required.join(', ') : 'no required arguments'}; optional fields: describe_tool`;
|
|
67
|
+
return byteLength(requiredOnly) <= MAX_SIGNATURE_BYTES ? requiredOnly : DESCRIBE;
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=input-signature.js.map
|
|
@@ -22,6 +22,8 @@ export interface ToolCatalogEntry {
|
|
|
22
22
|
}
|
|
23
23
|
export interface ToolCatalogHit extends ToolCatalogEntry {
|
|
24
24
|
readonly score: number;
|
|
25
|
+
/** Bounded one-line argument signature (required names and types); describe_tool has the schema. */
|
|
26
|
+
readonly signature?: string;
|
|
25
27
|
}
|
|
26
28
|
export interface ToolCatalogQuery {
|
|
27
29
|
search(required: {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { toolDiscoveryMetadata } from '@jini-ai/core';
|
|
2
2
|
import { nowIso } from '@jini-ai/core/primitives';
|
|
3
|
+
import { inputSignature } from './input-signature.js';
|
|
3
4
|
/** Live overview, preserving registration order; vocabulary and source policy are host-owned. */
|
|
4
5
|
export function listToolCatalogEntries(required) {
|
|
5
6
|
return required.source.list().map(descriptor => ({
|
|
@@ -24,6 +25,9 @@ export function buildToolCatalogQuery(required, optional = {}) {
|
|
|
24
25
|
throw new Error('catalog tool IDs must be unique');
|
|
25
26
|
}
|
|
26
27
|
const authored = new Map();
|
|
28
|
+
// Hits carry a compact signature, never the schema (PROP §6.1): every hit's first call needs the
|
|
29
|
+
// required names and types, while full schemas on every hit doubled each search's output.
|
|
30
|
+
const signatures = new Map(descriptors.map(descriptor => [descriptor.id, inputSignature({ inputSchema: descriptor.inputSchema })]));
|
|
27
31
|
const effects = new Map(descriptors.map(descriptor => [descriptor.id, toolDiscoveryMetadata({ descriptor })]));
|
|
28
32
|
const entries = descriptors.map(descriptor => {
|
|
29
33
|
const description = descriptor.description ?? '';
|
|
@@ -47,7 +51,10 @@ export function buildToolCatalogQuery(required, optional = {}) {
|
|
|
47
51
|
search({ query }, { limit = 10 } = {}) {
|
|
48
52
|
if (!Number.isSafeInteger(limit) || limit < 0)
|
|
49
53
|
throw new RangeError('catalog limit must be a nonnegative integer');
|
|
50
|
-
return store.search({ query }, { limit }).map(
|
|
54
|
+
return store.search({ query }, { limit }).map(({ inputSchema: _schema, ...hit }) => {
|
|
55
|
+
const signature = signatures.get(hit.id);
|
|
56
|
+
return { ...hit, ...effects.get(hit.id), ...(signature === undefined ? {} : { signature }), description: descriptionFor(hit) };
|
|
57
|
+
});
|
|
51
58
|
},
|
|
52
59
|
describe({ id }) {
|
|
53
60
|
const entry = store.describe({ id });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jini-ai/registry",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.16",
|
|
4
4
|
"description": "Pluggable content-registry backends (static, GitHub, database) and semver specifier resolution over @jini-ai/protocol’s registry wire types.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -24,6 +24,10 @@
|
|
|
24
24
|
"./tool-catalog-builder": "tool-catalog",
|
|
25
25
|
"./tool-catalog-builder/sqlite": "tool-catalog"
|
|
26
26
|
}
|
|
27
|
+
},
|
|
28
|
+
"optionalPeers": {
|
|
29
|
+
"better-sqlite3": "opt-in: sqlite storage — SQLite storage could not load better-sqlite3. Install better-sqlite3 to enable this feature, or check its installed version and native binaries.",
|
|
30
|
+
"@jini-ai/db": "opt-in: database-backed adapters — Database-backed adapters could not load @jini-ai/db. Install @jini-ai/db to enable this feature, or check its installed version and native binaries."
|
|
27
31
|
}
|
|
28
32
|
},
|
|
29
33
|
"type": "module",
|
|
@@ -74,13 +78,21 @@
|
|
|
74
78
|
"registry": "https://registry.npmjs.org"
|
|
75
79
|
},
|
|
76
80
|
"dependencies": {
|
|
77
|
-
"@jini-ai/
|
|
78
|
-
"@jini-ai/core": "^0.6.
|
|
81
|
+
"@jini-ai/platform": "^0.6.16",
|
|
82
|
+
"@jini-ai/core": "^0.6.16",
|
|
83
|
+
"@jini-ai/protocol": "^0.6.16"
|
|
79
84
|
},
|
|
80
85
|
"peerDependencies": {
|
|
81
86
|
"better-sqlite3": "^13.0.0",
|
|
82
|
-
"@jini-ai/db": "^0.6.10"
|
|
83
|
-
|
|
87
|
+
"@jini-ai/db": "^0.6.10"
|
|
88
|
+
},
|
|
89
|
+
"devDependencies": {
|
|
90
|
+
"@types/better-sqlite3": "^7.6.11",
|
|
91
|
+
"better-sqlite3": "^13.0.0",
|
|
92
|
+
"@jini-ai/db": "0.6.16",
|
|
93
|
+
"@jini-ai/platform": "^0.6.16",
|
|
94
|
+
"@jini-ai/core": "^0.6.16",
|
|
95
|
+
"@jini-ai/protocol": "^0.6.16"
|
|
84
96
|
},
|
|
85
97
|
"peerDependenciesMeta": {
|
|
86
98
|
"better-sqlite3": {
|
|
@@ -88,19 +100,8 @@
|
|
|
88
100
|
},
|
|
89
101
|
"@jini-ai/db": {
|
|
90
102
|
"optional": true
|
|
91
|
-
},
|
|
92
|
-
"@jini-ai/platform": {
|
|
93
|
-
"optional": true
|
|
94
103
|
}
|
|
95
104
|
},
|
|
96
|
-
"devDependencies": {
|
|
97
|
-
"@types/better-sqlite3": "^7.6.11",
|
|
98
|
-
"better-sqlite3": "^13.0.0",
|
|
99
|
-
"@jini-ai/db": "0.6.15",
|
|
100
|
-
"@jini-ai/protocol": "^0.6.15",
|
|
101
|
-
"@jini-ai/core": "^0.6.15",
|
|
102
|
-
"@jini-ai/platform": "^0.6.15"
|
|
103
|
-
},
|
|
104
105
|
"scripts": {
|
|
105
106
|
"build": "tsc -p tsconfig.json",
|
|
106
107
|
"typecheck": "tsc -p tsconfig.json --noEmit",
|