@odla-ai/ai 0.1.0 → 0.1.2
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/index.cjs +25 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +8 -2
- package/dist/index.d.ts +8 -2
- package/dist/index.js +25 -2
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -1930,6 +1930,10 @@ function entityCrudSkill(opts) {
|
|
|
1930
1930
|
return out;
|
|
1931
1931
|
};
|
|
1932
1932
|
const ok = (obj) => ({ content: JSON.stringify(obj) });
|
|
1933
|
+
const existsById = async (id) => {
|
|
1934
|
+
const res = await db.query({ [entity]: { $: {} } });
|
|
1935
|
+
return (res[entity] ?? []).some((r) => String(r.id ?? "") === id);
|
|
1936
|
+
};
|
|
1933
1937
|
const listTool = {
|
|
1934
1938
|
name: `list_${plural}`,
|
|
1935
1939
|
description: `List ${plural}. Optionally filter by exact field values and/or limit the count.`,
|
|
@@ -1955,6 +1959,12 @@ function entityCrudSkill(opts) {
|
|
|
1955
1959
|
description: `Create a new ${singular}.`,
|
|
1956
1960
|
inputSchema: { type: "object", properties: fields, ...opts.required ? { required: opts.required } : {} },
|
|
1957
1961
|
handler: async (input) => {
|
|
1962
|
+
for (const req of opts.required ?? []) {
|
|
1963
|
+
const v = input[req];
|
|
1964
|
+
if (v === void 0 || v === null || v === "") {
|
|
1965
|
+
return { content: `Cannot create ${singular}: field "${req}" is required.`, isError: true };
|
|
1966
|
+
}
|
|
1967
|
+
}
|
|
1958
1968
|
const id = genId();
|
|
1959
1969
|
const attrs = pickFields(input);
|
|
1960
1970
|
if (stampAttr) attrs[stampAttr] = Date.now();
|
|
@@ -1967,7 +1977,10 @@ function entityCrudSkill(opts) {
|
|
|
1967
1977
|
description: `Update fields of an existing ${singular} by ${idField}. Only the fields you pass change.`,
|
|
1968
1978
|
inputSchema: {
|
|
1969
1979
|
type: "object",
|
|
1970
|
-
properties: {
|
|
1980
|
+
properties: {
|
|
1981
|
+
[idField]: { type: "string", description: `The exact ${idField} string from list_${plural} \u2014 NOT the item's position in a numbered list.` },
|
|
1982
|
+
...fields
|
|
1983
|
+
},
|
|
1971
1984
|
required: [idField]
|
|
1972
1985
|
},
|
|
1973
1986
|
handler: async (input) => {
|
|
@@ -1975,6 +1988,9 @@ function entityCrudSkill(opts) {
|
|
|
1975
1988
|
if (!id) return { content: `Missing "${idField}".`, isError: true };
|
|
1976
1989
|
const attrs = pickFields(input);
|
|
1977
1990
|
if (Object.keys(attrs).length === 0) return { content: "No fields to update.", isError: true };
|
|
1991
|
+
if (!await existsById(id)) {
|
|
1992
|
+
return { content: `No ${singular} with ${idField} "${id}". Call list_${plural} for valid ids, then retry.`, isError: true };
|
|
1993
|
+
}
|
|
1978
1994
|
await db.transact([{ t: "update", ns: entity, id, attrs }]);
|
|
1979
1995
|
return ok({ id, updated: true });
|
|
1980
1996
|
}
|
|
@@ -1982,10 +1998,17 @@ function entityCrudSkill(opts) {
|
|
|
1982
1998
|
const deleteTool = {
|
|
1983
1999
|
name: `delete_${singular}`,
|
|
1984
2000
|
description: `Delete a ${singular} by ${idField}.`,
|
|
1985
|
-
inputSchema: {
|
|
2001
|
+
inputSchema: {
|
|
2002
|
+
type: "object",
|
|
2003
|
+
properties: { [idField]: { type: "string", description: `The exact ${idField} string from list_${plural} \u2014 NOT the item's position in a numbered list.` } },
|
|
2004
|
+
required: [idField]
|
|
2005
|
+
},
|
|
1986
2006
|
handler: async (input) => {
|
|
1987
2007
|
const id = String(input[idField] ?? "");
|
|
1988
2008
|
if (!id) return { content: `Missing "${idField}".`, isError: true };
|
|
2009
|
+
if (!await existsById(id)) {
|
|
2010
|
+
return { content: `No ${singular} with ${idField} "${id}". Call list_${plural} for valid ids.`, isError: true };
|
|
2011
|
+
}
|
|
1989
2012
|
const op = { t: "delete", ns: entity, id };
|
|
1990
2013
|
await db.transact([op]);
|
|
1991
2014
|
return ok({ id, deleted: true });
|