@codex-infinity/pi-infinity 0.64.2 → 0.65.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/CHANGELOG.md +57 -34
- package/README.md +5 -3
- package/dist/cli/args.d.ts +7 -4
- package/dist/cli/args.d.ts.map +1 -1
- package/dist/cli/args.js +37 -15
- package/dist/cli/args.js.map +1 -1
- package/dist/core/agent-session-runtime.d.ts +51 -102
- package/dist/core/agent-session-runtime.d.ts.map +1 -1
- package/dist/core/agent-session-runtime.js +103 -138
- package/dist/core/agent-session-runtime.js.map +1 -1
- package/dist/core/agent-session-services.d.ts +86 -0
- package/dist/core/agent-session-services.d.ts.map +1 -0
- package/dist/core/agent-session-services.js +116 -0
- package/dist/core/agent-session-services.js.map +1 -0
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +1 -1
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/extensions/index.d.ts +2 -2
- package/dist/core/extensions/index.d.ts.map +1 -1
- package/dist/core/extensions/index.js +1 -1
- package/dist/core/extensions/index.js.map +1 -1
- package/dist/core/extensions/types.d.ts +10 -13
- package/dist/core/extensions/types.d.ts.map +1 -1
- package/dist/core/extensions/types.js +10 -0
- package/dist/core/extensions/types.js.map +1 -1
- package/dist/core/index.d.ts +3 -2
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +3 -2
- package/dist/core/index.js.map +1 -1
- package/dist/core/keybindings.d.ts +4 -1
- package/dist/core/keybindings.d.ts.map +1 -1
- package/dist/core/keybindings.js +3 -14
- package/dist/core/keybindings.js.map +1 -1
- package/dist/core/package-manager.d.ts +20 -0
- package/dist/core/package-manager.d.ts.map +1 -1
- package/dist/core/package-manager.js +32 -0
- package/dist/core/package-manager.js.map +1 -1
- package/dist/core/resource-loader.d.ts.map +1 -1
- package/dist/core/resource-loader.js +21 -0
- package/dist/core/resource-loader.js.map +1 -1
- package/dist/core/sdk.d.ts +1 -1
- package/dist/core/sdk.d.ts.map +1 -1
- package/dist/core/sdk.js +1 -1
- package/dist/core/sdk.js.map +1 -1
- package/dist/core/settings-manager.d.ts +1 -1
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js +2 -1
- package/dist/core/settings-manager.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +202 -456
- package/dist/main.js.map +1 -1
- package/dist/migrations.d.ts.map +1 -1
- package/dist/migrations.js +20 -0
- package/dist/migrations.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts +3 -2
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +56 -29
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/print-mode.d.ts +2 -2
- package/dist/modes/print-mode.d.ts.map +1 -1
- package/dist/modes/print-mode.js +4 -0
- package/dist/modes/print-mode.js.map +1 -1
- package/dist/modes/rpc/rpc-client.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-client.js +1 -0
- package/dist/modes/rpc/rpc-client.js.map +1 -1
- package/dist/modes/rpc/rpc-mode.d.ts +2 -2
- package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-mode.js +23 -15
- package/dist/modes/rpc/rpc-mode.js.map +1 -1
- package/dist/package-manager-cli.d.ts +4 -0
- package/dist/package-manager-cli.d.ts.map +1 -0
- package/dist/package-manager-cli.js +234 -0
- package/dist/package-manager-cli.js.map +1 -0
- package/docs/extensions.md +34 -26
- package/docs/sdk.md +109 -46
- package/docs/settings.md +1 -1
- package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
- package/examples/extensions/custom-provider-anthropic/package.json +1 -1
- package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
- package/examples/extensions/custom-provider-qwen-cli/package.json +1 -1
- package/examples/extensions/hello.ts +18 -17
- package/examples/extensions/with-deps/package-lock.json +2 -2
- package/examples/extensions/with-deps/package.json +1 -1
- package/examples/sdk/13-session-runtime.ts +30 -12
- package/examples/sdk/README.md +2 -0
- package/package.json +4 -4
package/docs/sdk.md
CHANGED
|
@@ -115,33 +115,46 @@ interface AgentSession {
|
|
|
115
115
|
}
|
|
116
116
|
```
|
|
117
117
|
|
|
118
|
-
Session replacement APIs such as new-session, resume, fork, and import live on `
|
|
118
|
+
Session replacement APIs such as new-session, resume, fork, and import live on `AgentSessionRuntime`, not on `AgentSession`.
|
|
119
119
|
|
|
120
|
-
### createAgentSessionRuntime() and
|
|
120
|
+
### createAgentSessionRuntime() and AgentSessionRuntime
|
|
121
121
|
|
|
122
122
|
Use the runtime API when you need to replace the active session and rebuild cwd-bound runtime state.
|
|
123
123
|
This is the same layer used by the built-in interactive, print, and RPC modes.
|
|
124
124
|
|
|
125
|
+
`createAgentSessionRuntime()` takes a runtime factory plus the initial cwd/session target. The factory closes over process-global fixed inputs, recreates cwd-bound services for the effective cwd, resolves session options against those services, and returns a full runtime result.
|
|
126
|
+
|
|
125
127
|
```typescript
|
|
126
128
|
import {
|
|
127
|
-
|
|
129
|
+
type CreateAgentSessionRuntimeFactory,
|
|
130
|
+
createAgentSessionFromServices,
|
|
128
131
|
createAgentSessionRuntime,
|
|
132
|
+
createAgentSessionServices,
|
|
133
|
+
getAgentDir,
|
|
129
134
|
SessionManager,
|
|
130
135
|
} from "@mariozechner/pi-coding-agent";
|
|
131
136
|
|
|
132
|
-
const
|
|
133
|
-
|
|
137
|
+
const createRuntime: CreateAgentSessionRuntimeFactory = async ({ cwd, sessionManager, sessionStartEvent }) => {
|
|
138
|
+
const services = await createAgentSessionServices({ cwd });
|
|
139
|
+
return {
|
|
140
|
+
...(await createAgentSessionFromServices({
|
|
141
|
+
services,
|
|
142
|
+
sessionManager,
|
|
143
|
+
sessionStartEvent,
|
|
144
|
+
})),
|
|
145
|
+
services,
|
|
146
|
+
diagnostics: services.diagnostics,
|
|
147
|
+
};
|
|
134
148
|
};
|
|
135
149
|
|
|
136
|
-
const runtime = await createAgentSessionRuntime(
|
|
150
|
+
const runtime = await createAgentSessionRuntime(createRuntime, {
|
|
137
151
|
cwd: process.cwd(),
|
|
152
|
+
agentDir: getAgentDir(),
|
|
138
153
|
sessionManager: SessionManager.create(process.cwd()),
|
|
139
154
|
});
|
|
140
|
-
|
|
141
|
-
const runtimeHost = new AgentSessionRuntimeHost(bootstrap, runtime);
|
|
142
155
|
```
|
|
143
156
|
|
|
144
|
-
`
|
|
157
|
+
`AgentSessionRuntime` owns replacement of the active runtime across:
|
|
145
158
|
|
|
146
159
|
- `newSession()`
|
|
147
160
|
- `switchSession()`
|
|
@@ -150,18 +163,20 @@ const runtimeHost = new AgentSessionRuntimeHost(bootstrap, runtime);
|
|
|
150
163
|
|
|
151
164
|
Important behavior:
|
|
152
165
|
|
|
153
|
-
- `
|
|
166
|
+
- `runtime.session` changes after those operations
|
|
154
167
|
- event subscriptions are attached to a specific `AgentSession`, so re-subscribe after replacement
|
|
155
|
-
- if you use extensions, call `
|
|
168
|
+
- if you use extensions, call `runtime.session.bindExtensions(...)` again for the new session
|
|
169
|
+
- creation returns diagnostics on `runtime.diagnostics`
|
|
170
|
+
- if runtime creation or replacement fails, the method throws and the caller decides how to handle it
|
|
156
171
|
|
|
157
172
|
```typescript
|
|
158
|
-
let session =
|
|
173
|
+
let session = runtime.session;
|
|
159
174
|
let unsubscribe = session.subscribe(() => {});
|
|
160
175
|
|
|
161
|
-
await
|
|
176
|
+
await runtime.newSession();
|
|
162
177
|
|
|
163
178
|
unsubscribe();
|
|
164
|
-
session =
|
|
179
|
+
session = runtime.session;
|
|
165
180
|
unsubscribe = session.subscribe(() => {});
|
|
166
181
|
```
|
|
167
182
|
|
|
@@ -493,21 +508,21 @@ const { session } = await createAgentSession({
|
|
|
493
508
|
|
|
494
509
|
```typescript
|
|
495
510
|
import { Type } from "@sinclair/typebox";
|
|
496
|
-
import { createAgentSession,
|
|
511
|
+
import { createAgentSession, defineTool } from "@mariozechner/pi-coding-agent";
|
|
497
512
|
|
|
498
513
|
// Inline custom tool
|
|
499
|
-
const myTool
|
|
514
|
+
const myTool = defineTool({
|
|
500
515
|
name: "my_tool",
|
|
501
516
|
label: "My Tool",
|
|
502
517
|
description: "Does something useful",
|
|
503
518
|
parameters: Type.Object({
|
|
504
519
|
input: Type.String({ description: "Input value" }),
|
|
505
520
|
}),
|
|
506
|
-
execute: async (
|
|
521
|
+
execute: async (_toolCallId, params) => ({
|
|
507
522
|
content: [{ type: "text", text: `Result: ${params.input}` }],
|
|
508
523
|
details: {},
|
|
509
524
|
}),
|
|
510
|
-
};
|
|
525
|
+
});
|
|
511
526
|
|
|
512
527
|
// Pass custom tools directly
|
|
513
528
|
const { session } = await createAgentSession({
|
|
@@ -515,6 +530,8 @@ const { session } = await createAgentSession({
|
|
|
515
530
|
});
|
|
516
531
|
```
|
|
517
532
|
|
|
533
|
+
Use `defineTool()` for standalone definitions and arrays like `customTools: [myTool]`. Inline `pi.registerTool({ ... })` already infers parameter types correctly.
|
|
534
|
+
|
|
518
535
|
Custom tools passed via `customTools` are combined with extension-registered tools. Extensions loaded by the ResourceLoader can also register tools via `pi.registerTool()`.
|
|
519
536
|
|
|
520
537
|
> See [examples/sdk/05-tools.ts](../examples/sdk/05-tools.ts)
|
|
@@ -644,9 +661,12 @@ Sessions use a tree structure with `id`/`parentId` linking, enabling in-place br
|
|
|
644
661
|
|
|
645
662
|
```typescript
|
|
646
663
|
import {
|
|
647
|
-
|
|
664
|
+
type CreateAgentSessionRuntimeFactory,
|
|
648
665
|
createAgentSession,
|
|
666
|
+
createAgentSessionFromServices,
|
|
649
667
|
createAgentSessionRuntime,
|
|
668
|
+
createAgentSessionServices,
|
|
669
|
+
getAgentDir,
|
|
650
670
|
SessionManager,
|
|
651
671
|
} from "@mariozechner/pi-coding-agent";
|
|
652
672
|
|
|
@@ -678,21 +698,33 @@ const currentProjectSessions = await SessionManager.list(process.cwd());
|
|
|
678
698
|
const allSessions = await SessionManager.listAll(process.cwd());
|
|
679
699
|
|
|
680
700
|
// Session replacement API for /new, /resume, /fork, and import flows.
|
|
681
|
-
const
|
|
682
|
-
const
|
|
701
|
+
const createRuntime: CreateAgentSessionRuntimeFactory = async ({ cwd, sessionManager, sessionStartEvent }) => {
|
|
702
|
+
const services = await createAgentSessionServices({ cwd });
|
|
703
|
+
return {
|
|
704
|
+
...(await createAgentSessionFromServices({
|
|
705
|
+
services,
|
|
706
|
+
sessionManager,
|
|
707
|
+
sessionStartEvent,
|
|
708
|
+
})),
|
|
709
|
+
services,
|
|
710
|
+
diagnostics: services.diagnostics,
|
|
711
|
+
};
|
|
712
|
+
};
|
|
713
|
+
|
|
714
|
+
const runtime = await createAgentSessionRuntime(createRuntime, {
|
|
683
715
|
cwd: process.cwd(),
|
|
716
|
+
agentDir: getAgentDir(),
|
|
684
717
|
sessionManager: SessionManager.create(process.cwd()),
|
|
685
718
|
});
|
|
686
|
-
const runtimeHost = new AgentSessionRuntimeHost(bootstrap, runtime);
|
|
687
719
|
|
|
688
720
|
// Replace the active session with a fresh one
|
|
689
|
-
await
|
|
721
|
+
await runtime.newSession();
|
|
690
722
|
|
|
691
723
|
// Replace the active session with another saved session
|
|
692
|
-
await
|
|
724
|
+
await runtime.switchSession("/path/to/session.jsonl");
|
|
693
725
|
|
|
694
726
|
// Replace the active session with a fork from a specific entry
|
|
695
|
-
await
|
|
727
|
+
await runtime.fork("entry-id");
|
|
696
728
|
```
|
|
697
729
|
|
|
698
730
|
**SessionManager tree API:**
|
|
@@ -828,14 +860,14 @@ import { getModel } from "@mariozechner/pi-ai";
|
|
|
828
860
|
import { Type } from "@sinclair/typebox";
|
|
829
861
|
import {
|
|
830
862
|
AuthStorage,
|
|
863
|
+
bashTool,
|
|
831
864
|
createAgentSession,
|
|
832
865
|
DefaultResourceLoader,
|
|
866
|
+
defineTool,
|
|
833
867
|
ModelRegistry,
|
|
868
|
+
readTool,
|
|
834
869
|
SessionManager,
|
|
835
870
|
SettingsManager,
|
|
836
|
-
readTool,
|
|
837
|
-
bashTool,
|
|
838
|
-
type ToolDefinition,
|
|
839
871
|
} from "@mariozechner/pi-coding-agent";
|
|
840
872
|
|
|
841
873
|
// Set up auth storage (custom location)
|
|
@@ -850,7 +882,7 @@ if (process.env.MY_KEY) {
|
|
|
850
882
|
const modelRegistry = ModelRegistry.create(authStorage);
|
|
851
883
|
|
|
852
884
|
// Inline tool
|
|
853
|
-
const statusTool
|
|
885
|
+
const statusTool = defineTool({
|
|
854
886
|
name: "status",
|
|
855
887
|
label: "Status",
|
|
856
888
|
description: "Get system status",
|
|
@@ -859,7 +891,7 @@ const statusTool: ToolDefinition = {
|
|
|
859
891
|
content: [{ type: "text", text: `Uptime: ${process.uptime()}s` }],
|
|
860
892
|
details: {},
|
|
861
893
|
}),
|
|
862
|
-
};
|
|
894
|
+
});
|
|
863
895
|
|
|
864
896
|
const model = getModel("anthropic", "claude-opus-4-5");
|
|
865
897
|
if (!model) throw new Error("Model not found");
|
|
@@ -914,20 +946,30 @@ Full TUI interactive mode with editor, chat history, and all built-in commands:
|
|
|
914
946
|
|
|
915
947
|
```typescript
|
|
916
948
|
import {
|
|
917
|
-
|
|
949
|
+
type CreateAgentSessionRuntimeFactory,
|
|
950
|
+
createAgentSessionFromServices,
|
|
918
951
|
createAgentSessionRuntime,
|
|
952
|
+
createAgentSessionServices,
|
|
953
|
+
getAgentDir,
|
|
919
954
|
InteractiveMode,
|
|
920
955
|
SessionManager,
|
|
921
956
|
} from "@mariozechner/pi-coding-agent";
|
|
922
957
|
|
|
923
|
-
const
|
|
924
|
-
const
|
|
958
|
+
const createRuntime: CreateAgentSessionRuntimeFactory = async ({ cwd, sessionManager, sessionStartEvent }) => {
|
|
959
|
+
const services = await createAgentSessionServices({ cwd });
|
|
960
|
+
return {
|
|
961
|
+
...(await createAgentSessionFromServices({ services, sessionManager, sessionStartEvent })),
|
|
962
|
+
services,
|
|
963
|
+
diagnostics: services.diagnostics,
|
|
964
|
+
};
|
|
965
|
+
};
|
|
966
|
+
const runtime = await createAgentSessionRuntime(createRuntime, {
|
|
925
967
|
cwd: process.cwd(),
|
|
968
|
+
agentDir: getAgentDir(),
|
|
926
969
|
sessionManager: SessionManager.create(process.cwd()),
|
|
927
970
|
});
|
|
928
|
-
const runtimeHost = new AgentSessionRuntimeHost(bootstrap, runtime);
|
|
929
971
|
|
|
930
|
-
const mode = new InteractiveMode(
|
|
972
|
+
const mode = new InteractiveMode(runtime, {
|
|
931
973
|
migratedProviders: [],
|
|
932
974
|
modelFallbackMessage: undefined,
|
|
933
975
|
initialMessage: "Hello",
|
|
@@ -944,20 +986,30 @@ Single-shot mode: send prompts, output result, exit:
|
|
|
944
986
|
|
|
945
987
|
```typescript
|
|
946
988
|
import {
|
|
947
|
-
|
|
989
|
+
type CreateAgentSessionRuntimeFactory,
|
|
990
|
+
createAgentSessionFromServices,
|
|
948
991
|
createAgentSessionRuntime,
|
|
992
|
+
createAgentSessionServices,
|
|
993
|
+
getAgentDir,
|
|
949
994
|
runPrintMode,
|
|
950
995
|
SessionManager,
|
|
951
996
|
} from "@mariozechner/pi-coding-agent";
|
|
952
997
|
|
|
953
|
-
const
|
|
954
|
-
const
|
|
998
|
+
const createRuntime: CreateAgentSessionRuntimeFactory = async ({ cwd, sessionManager, sessionStartEvent }) => {
|
|
999
|
+
const services = await createAgentSessionServices({ cwd });
|
|
1000
|
+
return {
|
|
1001
|
+
...(await createAgentSessionFromServices({ services, sessionManager, sessionStartEvent })),
|
|
1002
|
+
services,
|
|
1003
|
+
diagnostics: services.diagnostics,
|
|
1004
|
+
};
|
|
1005
|
+
};
|
|
1006
|
+
const runtime = await createAgentSessionRuntime(createRuntime, {
|
|
955
1007
|
cwd: process.cwd(),
|
|
1008
|
+
agentDir: getAgentDir(),
|
|
956
1009
|
sessionManager: SessionManager.create(process.cwd()),
|
|
957
1010
|
});
|
|
958
|
-
const runtimeHost = new AgentSessionRuntimeHost(bootstrap, runtime);
|
|
959
1011
|
|
|
960
|
-
await runPrintMode(
|
|
1012
|
+
await runPrintMode(runtime, {
|
|
961
1013
|
mode: "text",
|
|
962
1014
|
initialMessage: "Hello",
|
|
963
1015
|
initialImages: [],
|
|
@@ -971,20 +1023,30 @@ JSON-RPC mode for subprocess integration:
|
|
|
971
1023
|
|
|
972
1024
|
```typescript
|
|
973
1025
|
import {
|
|
974
|
-
|
|
1026
|
+
type CreateAgentSessionRuntimeFactory,
|
|
1027
|
+
createAgentSessionFromServices,
|
|
975
1028
|
createAgentSessionRuntime,
|
|
1029
|
+
createAgentSessionServices,
|
|
1030
|
+
getAgentDir,
|
|
976
1031
|
runRpcMode,
|
|
977
1032
|
SessionManager,
|
|
978
1033
|
} from "@mariozechner/pi-coding-agent";
|
|
979
1034
|
|
|
980
|
-
const
|
|
981
|
-
const
|
|
1035
|
+
const createRuntime: CreateAgentSessionRuntimeFactory = async ({ cwd, sessionManager, sessionStartEvent }) => {
|
|
1036
|
+
const services = await createAgentSessionServices({ cwd });
|
|
1037
|
+
return {
|
|
1038
|
+
...(await createAgentSessionFromServices({ services, sessionManager, sessionStartEvent })),
|
|
1039
|
+
services,
|
|
1040
|
+
diagnostics: services.diagnostics,
|
|
1041
|
+
};
|
|
1042
|
+
};
|
|
1043
|
+
const runtime = await createAgentSessionRuntime(createRuntime, {
|
|
982
1044
|
cwd: process.cwd(),
|
|
1045
|
+
agentDir: getAgentDir(),
|
|
983
1046
|
sessionManager: SessionManager.create(process.cwd()),
|
|
984
1047
|
});
|
|
985
|
-
const runtimeHost = new AgentSessionRuntimeHost(bootstrap, runtime);
|
|
986
1048
|
|
|
987
|
-
await runRpcMode(
|
|
1049
|
+
await runRpcMode(runtime);
|
|
988
1050
|
```
|
|
989
1051
|
|
|
990
1052
|
See [RPC documentation](rpc.md) for the JSON protocol.
|
|
@@ -1018,7 +1080,7 @@ The main entry point exports:
|
|
|
1018
1080
|
// Factory
|
|
1019
1081
|
createAgentSession
|
|
1020
1082
|
createAgentSessionRuntime
|
|
1021
|
-
|
|
1083
|
+
AgentSessionRuntime
|
|
1022
1084
|
|
|
1023
1085
|
// Auth and Models
|
|
1024
1086
|
AuthStorage
|
|
@@ -1030,6 +1092,7 @@ type ResourceLoader
|
|
|
1030
1092
|
createEventBus
|
|
1031
1093
|
|
|
1032
1094
|
// Helpers
|
|
1095
|
+
defineTool
|
|
1033
1096
|
|
|
1034
1097
|
// Session management
|
|
1035
1098
|
SessionManager
|
package/docs/settings.md
CHANGED
|
@@ -137,7 +137,7 @@ When a provider requests a retry delay longer than `maxDelayMs` (e.g., Google's
|
|
|
137
137
|
{ "sessionDir": ".pi/sessions" }
|
|
138
138
|
```
|
|
139
139
|
|
|
140
|
-
When multiple sources specify a session directory, `--session-dir` CLI flag takes precedence
|
|
140
|
+
When multiple sources specify a session directory, `--session-dir` CLI flag takes precedence over `sessionDir` in settings.json.
|
|
141
141
|
|
|
142
142
|
### Model Cycling
|
|
143
143
|
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-extension-custom-provider",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.16.1",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "pi-extension-custom-provider",
|
|
9
|
-
"version": "1.
|
|
9
|
+
"version": "1.16.1",
|
|
10
10
|
"dependencies": {
|
|
11
11
|
"@anthropic-ai/sdk": "^0.52.0"
|
|
12
12
|
}
|
|
@@ -3,23 +3,24 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
import { Type } from "@mariozechner/pi-ai";
|
|
6
|
-
import type
|
|
6
|
+
import { defineTool, type ExtensionAPI } from "@mariozechner/pi-coding-agent";
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
8
|
+
const helloTool = defineTool({
|
|
9
|
+
name: "hello",
|
|
10
|
+
label: "Hello",
|
|
11
|
+
description: "A simple greeting tool",
|
|
12
|
+
parameters: Type.Object({
|
|
13
|
+
name: Type.String({ description: "Name to greet" }),
|
|
14
|
+
}),
|
|
15
|
+
|
|
16
|
+
async execute(_toolCallId, params, _signal, _onUpdate, _ctx) {
|
|
17
|
+
return {
|
|
18
|
+
content: [{ type: "text", text: `Hello, ${params.name}!` }],
|
|
19
|
+
details: { greeted: params.name },
|
|
20
|
+
};
|
|
21
|
+
},
|
|
22
|
+
});
|
|
16
23
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
return {
|
|
20
|
-
content: [{ type: "text", text: `Hello, ${name}!` }],
|
|
21
|
-
details: { greeted: name },
|
|
22
|
-
};
|
|
23
|
-
},
|
|
24
|
-
});
|
|
24
|
+
export default function (pi: ExtensionAPI) {
|
|
25
|
+
pi.registerTool(helloTool);
|
|
25
26
|
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-extension-with-deps",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.29.1",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "pi-extension-with-deps",
|
|
9
|
-
"version": "1.
|
|
9
|
+
"version": "1.29.1",
|
|
10
10
|
"dependencies": {
|
|
11
11
|
"ms": "^2.1.3"
|
|
12
12
|
},
|
|
@@ -1,27 +1,45 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Session
|
|
2
|
+
* Session runtime
|
|
3
3
|
*
|
|
4
|
-
* Use
|
|
4
|
+
* Use AgentSessionRuntime when you need to replace the active AgentSession,
|
|
5
5
|
* for example for new-session, resume, fork, or import flows.
|
|
6
6
|
*
|
|
7
|
-
* The important pattern is: after the
|
|
8
|
-
* session-local subscriptions and extension bindings to `
|
|
7
|
+
* The important pattern is: after the runtime replaces the active session,
|
|
8
|
+
* rebind any session-local subscriptions and extension bindings to `runtime.session`.
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
|
-
import {
|
|
11
|
+
import {
|
|
12
|
+
type CreateAgentSessionRuntimeFactory,
|
|
13
|
+
createAgentSessionFromServices,
|
|
14
|
+
createAgentSessionRuntime,
|
|
15
|
+
createAgentSessionServices,
|
|
16
|
+
getAgentDir,
|
|
17
|
+
SessionManager,
|
|
18
|
+
} from "@mariozechner/pi-coding-agent";
|
|
12
19
|
|
|
13
|
-
const
|
|
14
|
-
const
|
|
20
|
+
const createRuntime: CreateAgentSessionRuntimeFactory = async ({ cwd, sessionManager, sessionStartEvent }) => {
|
|
21
|
+
const services = await createAgentSessionServices({ cwd });
|
|
22
|
+
return {
|
|
23
|
+
...(await createAgentSessionFromServices({
|
|
24
|
+
services,
|
|
25
|
+
sessionManager,
|
|
26
|
+
sessionStartEvent,
|
|
27
|
+
})),
|
|
28
|
+
services,
|
|
29
|
+
diagnostics: services.diagnostics,
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
const runtime = await createAgentSessionRuntime(createRuntime, {
|
|
15
33
|
cwd: process.cwd(),
|
|
34
|
+
agentDir: getAgentDir(),
|
|
16
35
|
sessionManager: SessionManager.create(process.cwd()),
|
|
17
36
|
});
|
|
18
|
-
const runtimeHost = new AgentSessionRuntimeHost(bootstrap, runtime);
|
|
19
37
|
|
|
20
38
|
let unsubscribe: (() => void) | undefined;
|
|
21
39
|
|
|
22
40
|
async function bindSession() {
|
|
23
41
|
unsubscribe?.();
|
|
24
|
-
const session =
|
|
42
|
+
const session = runtime.session;
|
|
25
43
|
await session.bindExtensions({});
|
|
26
44
|
unsubscribe = session.subscribe((event) => {
|
|
27
45
|
if (event.type === "queue_update") {
|
|
@@ -35,15 +53,15 @@ let session = await bindSession();
|
|
|
35
53
|
const originalSessionFile = session.sessionFile;
|
|
36
54
|
console.log("Initial session:", originalSessionFile);
|
|
37
55
|
|
|
38
|
-
await
|
|
56
|
+
await runtime.newSession();
|
|
39
57
|
session = await bindSession();
|
|
40
58
|
console.log("After newSession():", session.sessionFile);
|
|
41
59
|
|
|
42
60
|
if (originalSessionFile) {
|
|
43
|
-
await
|
|
61
|
+
await runtime.switchSession(originalSessionFile);
|
|
44
62
|
session = await bindSession();
|
|
45
63
|
console.log("After switchSession():", session.sessionFile);
|
|
46
64
|
}
|
|
47
65
|
|
|
48
66
|
unsubscribe?.();
|
|
49
|
-
await
|
|
67
|
+
await runtime.dispose();
|
package/examples/sdk/README.md
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
Programmatic usage of pi-coding-agent via `createAgentSession()` and `createAgentSessionRuntime()`.
|
|
4
4
|
|
|
5
|
+
The runtime example shows how to build a recreate function that closes over process-global fixed inputs and recreates cwd-bound services and sessions as the active session cwd changes.
|
|
6
|
+
|
|
5
7
|
## Examples
|
|
6
8
|
|
|
7
9
|
| File | Description |
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@codex-infinity/pi-infinity",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.65.1",
|
|
4
4
|
"description": "Coding agent CLI with read, bash, edit, write tools and session management",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"piConfig": {
|
|
@@ -40,9 +40,9 @@
|
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
42
|
"@mariozechner/jiti": "^2.6.2",
|
|
43
|
-
"@mariozechner/pi-agent-core": "^0.
|
|
44
|
-
"@mariozechner/pi-ai": "^0.
|
|
45
|
-
"@mariozechner/pi-tui": "^0.
|
|
43
|
+
"@mariozechner/pi-agent-core": "^0.65.1",
|
|
44
|
+
"@mariozechner/pi-ai": "^0.65.1",
|
|
45
|
+
"@mariozechner/pi-tui": "^0.65.1",
|
|
46
46
|
"@silvia-odwyer/photon-node": "^0.3.4",
|
|
47
47
|
"ajv": "^8.17.1",
|
|
48
48
|
"chalk": "^5.5.0",
|