@kaoruisaac/pedelec 0.1.0 → 0.1.3
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 +594 -2
- package/dist/index.d.ts +159 -19
- package/dist/index.js +398 -66
- package/dist/index.type-test.d.ts +1 -0
- package/dist/index.type-test.js +101 -0
- package/package.json +4 -3
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { Pedelec, defineTool, } from "./index";
|
|
2
|
+
async function typedOnToolNameFromCreateSession() {
|
|
3
|
+
const pedelec = new Pedelec();
|
|
4
|
+
const session = await pedelec.createSession({
|
|
5
|
+
provider: "codex",
|
|
6
|
+
skills: {
|
|
7
|
+
guidance: "Use available tools.",
|
|
8
|
+
tools: [
|
|
9
|
+
defineTool({
|
|
10
|
+
name: "get_selection",
|
|
11
|
+
description: "Get selected text.",
|
|
12
|
+
argsSchema: { type: "object", properties: {}, required: [] },
|
|
13
|
+
}),
|
|
14
|
+
defineTool({
|
|
15
|
+
name: "replace_text",
|
|
16
|
+
description: "Replace selected text.",
|
|
17
|
+
argsSchema: { type: "object", properties: {}, required: [] },
|
|
18
|
+
}),
|
|
19
|
+
],
|
|
20
|
+
},
|
|
21
|
+
});
|
|
22
|
+
session.onTool((name, args, ctx) => {
|
|
23
|
+
const allowed = name;
|
|
24
|
+
const stillUnknown = args;
|
|
25
|
+
const toolCtx = ctx;
|
|
26
|
+
return { allowed, stillUnknown, toolCtx };
|
|
27
|
+
});
|
|
28
|
+
session.onTool("get_selection", async (args, ctx) => {
|
|
29
|
+
const stillUnknown = args;
|
|
30
|
+
const toolName = ctx.tool;
|
|
31
|
+
const turnId = ctx.turnId;
|
|
32
|
+
return { ok: true, stillUnknown, toolName, turnId };
|
|
33
|
+
});
|
|
34
|
+
session.onTool("replace_text", async () => {
|
|
35
|
+
return { ok: true };
|
|
36
|
+
});
|
|
37
|
+
// @ts-expect-error tool name must come from skills.tools[].name
|
|
38
|
+
session.onTool("not_exists", async () => {
|
|
39
|
+
return { ok: false };
|
|
40
|
+
});
|
|
41
|
+
session.onTool((name, _args, ctx) => {
|
|
42
|
+
// @ts-expect-error generic handler name should not be arbitrary string
|
|
43
|
+
const invalid = name;
|
|
44
|
+
// @ts-expect-error user-facing context must not expose core seq
|
|
45
|
+
const noSeq = ctx.seq;
|
|
46
|
+
return noSeq ?? invalid;
|
|
47
|
+
});
|
|
48
|
+
session.onChat((_text, ctx) => {
|
|
49
|
+
const chatCtx = ctx;
|
|
50
|
+
const receivedAt = ctx.eventReceivedAt;
|
|
51
|
+
void receivedAt;
|
|
52
|
+
void chatCtx;
|
|
53
|
+
});
|
|
54
|
+
session.onStatus((_status, ctx) => {
|
|
55
|
+
const statusCtx = ctx;
|
|
56
|
+
const previous = ctx.previousStatus;
|
|
57
|
+
void previous;
|
|
58
|
+
void statusCtx;
|
|
59
|
+
});
|
|
60
|
+
session.onError((_error, ctx) => {
|
|
61
|
+
const errorCtx = ctx;
|
|
62
|
+
return errorCtx;
|
|
63
|
+
});
|
|
64
|
+
session.onEnded((ctx) => {
|
|
65
|
+
const endedCtx = ctx;
|
|
66
|
+
return endedCtx;
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
async function resumedSessionFallsBackToString() {
|
|
70
|
+
const pedelec = new Pedelec();
|
|
71
|
+
const session = await pedelec.resumeSession("thread_1");
|
|
72
|
+
session.onTool((name) => {
|
|
73
|
+
const anyString = name;
|
|
74
|
+
return anyString;
|
|
75
|
+
});
|
|
76
|
+
session.onTool("runtime_tool_name", async () => {
|
|
77
|
+
return { ok: true };
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
async function noSkillsFallsBackToString() {
|
|
81
|
+
const pedelec = new Pedelec();
|
|
82
|
+
const session = await pedelec.createSession({ provider: "codex" });
|
|
83
|
+
session.onTool((name) => {
|
|
84
|
+
const anyString = name;
|
|
85
|
+
return anyString;
|
|
86
|
+
});
|
|
87
|
+
session.onTool("runtime_tool_name", async () => {
|
|
88
|
+
return { ok: true };
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
void typedOnToolNameFromCreateSession;
|
|
92
|
+
void resumedSessionFallsBackToString;
|
|
93
|
+
void noSkillsFallsBackToString;
|
|
94
|
+
const baseContext = {
|
|
95
|
+
sessionId: "thread_1",
|
|
96
|
+
provider: "codex",
|
|
97
|
+
sessionCreatedAt: Date.now(),
|
|
98
|
+
eventEmittedAt: Date.now(),
|
|
99
|
+
source: "sdk",
|
|
100
|
+
};
|
|
101
|
+
void baseContext;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kaoruisaac/pedelec",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -20,13 +20,14 @@
|
|
|
20
20
|
},
|
|
21
21
|
"repository": {
|
|
22
22
|
"type": "git",
|
|
23
|
-
"url": "https://github.com/kaoruisaac/pedelec.git",
|
|
23
|
+
"url": "git+https://github.com/kaoruisaac/pedelec.git",
|
|
24
24
|
"directory": "sdk"
|
|
25
25
|
},
|
|
26
26
|
"scripts": {
|
|
27
27
|
"build": "tsc -p tsconfig.json",
|
|
28
28
|
"test": "vitest run",
|
|
29
|
-
"
|
|
29
|
+
"type-test": "tsc -p tsconfig.type-test.json",
|
|
30
|
+
"prepublishOnly": "npm run test && npm run type-test && npm run build"
|
|
30
31
|
},
|
|
31
32
|
"devDependencies": {
|
|
32
33
|
"typescript": "^5.8.3",
|