@theokit/sdk-tools 0.10.0 → 0.11.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/CHANGELOG.md +11 -0
- package/dist/index.cjs +23 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +14 -3
- package/dist/index.d.ts +14 -3
- package/dist/index.js +23 -7
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.cts
CHANGED
|
@@ -708,6 +708,11 @@ declare function createShellTool(opts: CreateShellToolOptions): CustomTool;
|
|
|
708
708
|
* - remove(id) → remove an item
|
|
709
709
|
* - list() → show all items with status
|
|
710
710
|
* - clear_completed() → remove all done items
|
|
711
|
+
*
|
|
712
|
+
* #119 — state is keyed by `ctx.threadId` (the run's session identity, injected by the
|
|
713
|
+
* SDK from `Agent.getOrCreate(sessionId, …)`). One tool object served to many sessions
|
|
714
|
+
* from a single process keeps each session's list isolated. When no `threadId` is present
|
|
715
|
+
* (single-session CLI usage) every call shares one default session — behavior unchanged.
|
|
711
716
|
*/
|
|
712
717
|
interface TodoItem {
|
|
713
718
|
id: string;
|
|
@@ -720,9 +725,15 @@ interface TodolistTool {
|
|
|
720
725
|
name: string;
|
|
721
726
|
description: string;
|
|
722
727
|
inputSchema: unknown;
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
728
|
+
/**
|
|
729
|
+
* #119 — the optional 2nd `ctx` carries the run's `threadId`; state is scoped to it.
|
|
730
|
+
* Single-argument callers (CLI / tests) share one default session.
|
|
731
|
+
*/
|
|
732
|
+
handler: (input: TodoInput, ctx?: {
|
|
733
|
+
threadId?: string;
|
|
734
|
+
}) => string;
|
|
735
|
+
/** Expose a session's items for testing (defaults to the no-threadId session). */
|
|
736
|
+
getItems: (threadId?: string) => TodoItem[];
|
|
726
737
|
}
|
|
727
738
|
type TodoInput = {
|
|
728
739
|
action: "add";
|
package/dist/index.d.ts
CHANGED
|
@@ -708,6 +708,11 @@ declare function createShellTool(opts: CreateShellToolOptions): CustomTool;
|
|
|
708
708
|
* - remove(id) → remove an item
|
|
709
709
|
* - list() → show all items with status
|
|
710
710
|
* - clear_completed() → remove all done items
|
|
711
|
+
*
|
|
712
|
+
* #119 — state is keyed by `ctx.threadId` (the run's session identity, injected by the
|
|
713
|
+
* SDK from `Agent.getOrCreate(sessionId, …)`). One tool object served to many sessions
|
|
714
|
+
* from a single process keeps each session's list isolated. When no `threadId` is present
|
|
715
|
+
* (single-session CLI usage) every call shares one default session — behavior unchanged.
|
|
711
716
|
*/
|
|
712
717
|
interface TodoItem {
|
|
713
718
|
id: string;
|
|
@@ -720,9 +725,15 @@ interface TodolistTool {
|
|
|
720
725
|
name: string;
|
|
721
726
|
description: string;
|
|
722
727
|
inputSchema: unknown;
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
728
|
+
/**
|
|
729
|
+
* #119 — the optional 2nd `ctx` carries the run's `threadId`; state is scoped to it.
|
|
730
|
+
* Single-argument callers (CLI / tests) share one default session.
|
|
731
|
+
*/
|
|
732
|
+
handler: (input: TodoInput, ctx?: {
|
|
733
|
+
threadId?: string;
|
|
734
|
+
}) => string;
|
|
735
|
+
/** Expose a session's items for testing (defaults to the no-threadId session). */
|
|
736
|
+
getItems: (threadId?: string) => TodoItem[];
|
|
726
737
|
}
|
|
727
738
|
type TodoInput = {
|
|
728
739
|
action: "add";
|
package/dist/index.js
CHANGED
|
@@ -1801,7 +1801,7 @@ function requireId(input) {
|
|
|
1801
1801
|
if (!("id" in input) || !input.id) return null;
|
|
1802
1802
|
return input.id;
|
|
1803
1803
|
}
|
|
1804
|
-
function
|
|
1804
|
+
function makeSessionOps() {
|
|
1805
1805
|
const items = [];
|
|
1806
1806
|
let nextId = 1;
|
|
1807
1807
|
function genId() {
|
|
@@ -1870,6 +1870,26 @@ ${done}/${items.length} done | ${inProg} in progress | ${pending} pending`);
|
|
|
1870
1870
|
list: () => listResult({}),
|
|
1871
1871
|
clear_completed: handleClearCompleted
|
|
1872
1872
|
};
|
|
1873
|
+
return {
|
|
1874
|
+
handle: (input) => {
|
|
1875
|
+
const action = actions[input.action];
|
|
1876
|
+
if (!action) return fail({ error: "invalid_action" });
|
|
1877
|
+
return action(input);
|
|
1878
|
+
},
|
|
1879
|
+
getItems: () => [...items]
|
|
1880
|
+
};
|
|
1881
|
+
}
|
|
1882
|
+
function createTodolistTool() {
|
|
1883
|
+
const sessions = /* @__PURE__ */ new Map();
|
|
1884
|
+
function ops(threadId) {
|
|
1885
|
+
const key = threadId ?? "__default__";
|
|
1886
|
+
let session = sessions.get(key);
|
|
1887
|
+
if (session === void 0) {
|
|
1888
|
+
session = makeSessionOps();
|
|
1889
|
+
sessions.set(key, session);
|
|
1890
|
+
}
|
|
1891
|
+
return session;
|
|
1892
|
+
}
|
|
1873
1893
|
return {
|
|
1874
1894
|
name: "todolist",
|
|
1875
1895
|
description: "Create and maintain a structured task list for the current session \u2014 tracks progress and keeps a multi-step plan visible across turns. Use it proactively when the work has 3+ steps or the user gave multiple tasks; skip it for a single trivial step. Keep exactly ONE item 'in_progress' at a time, and mark 'complete' only after the work is actually done. Actions: 'add' (create with title), 'in_progress' (mark started by id), 'complete' (mark done by id), 'remove' (delete by id), 'list' (show all), 'clear_completed' (remove done items). Returns { ok, items, items_summary } (items = structured array; items_summary = formatted text).",
|
|
@@ -1892,12 +1912,8 @@ ${done}/${items.length} done | ${inProg} in progress | ${pending} pending`);
|
|
|
1892
1912
|
},
|
|
1893
1913
|
required: ["action"]
|
|
1894
1914
|
},
|
|
1895
|
-
handler: (input) =>
|
|
1896
|
-
|
|
1897
|
-
if (!action) return fail({ error: "invalid_action" });
|
|
1898
|
-
return action(input);
|
|
1899
|
-
},
|
|
1900
|
-
getItems: () => [...items]
|
|
1915
|
+
handler: (input, ctx) => ops(ctx?.threadId).handle(input),
|
|
1916
|
+
getItems: (threadId) => ops(threadId).getItems()
|
|
1901
1917
|
};
|
|
1902
1918
|
}
|
|
1903
1919
|
function truncateOutput(output, opts) {
|