@shivaedev/agent-pi 0.2.0 → 0.3.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.
Files changed (63) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +55 -1
  3. package/dist/PiOptions.d.ts +5 -0
  4. package/dist/PiOptions.d.ts.map +1 -0
  5. package/dist/PiOptions.js +2 -0
  6. package/dist/PiOptions.js.map +1 -0
  7. package/dist/adapters/deliver.d.ts +4 -0
  8. package/dist/adapters/deliver.d.ts.map +1 -0
  9. package/dist/adapters/deliver.js +19 -0
  10. package/dist/adapters/deliver.js.map +1 -0
  11. package/dist/adapters/effort.d.ts +5 -0
  12. package/dist/adapters/effort.d.ts.map +1 -0
  13. package/dist/adapters/effort.js +13 -0
  14. package/dist/adapters/effort.js.map +1 -0
  15. package/dist/adapters/failure.d.ts +6 -0
  16. package/dist/adapters/failure.d.ts.map +1 -0
  17. package/dist/adapters/failure.js +14 -0
  18. package/dist/adapters/failure.js.map +1 -0
  19. package/dist/adapters/listPiModels.d.ts +8 -0
  20. package/dist/adapters/listPiModels.d.ts.map +1 -0
  21. package/dist/adapters/listPiModels.js +11 -0
  22. package/dist/adapters/listPiModels.js.map +1 -0
  23. package/dist/adapters/mapping.d.ts +9 -0
  24. package/dist/adapters/mapping.d.ts.map +1 -0
  25. package/dist/adapters/mapping.js +44 -0
  26. package/dist/adapters/mapping.js.map +1 -0
  27. package/dist/adapters/messageEvents.d.ts +9 -0
  28. package/dist/adapters/messageEvents.d.ts.map +1 -0
  29. package/dist/adapters/messageEvents.js +41 -0
  30. package/dist/adapters/messageEvents.js.map +1 -0
  31. package/dist/adapters/openSession.d.ts +323 -0
  32. package/dist/adapters/openSession.d.ts.map +1 -0
  33. package/dist/adapters/openSession.js +41 -0
  34. package/dist/adapters/openSession.js.map +1 -0
  35. package/dist/adapters/runtime.d.ts +24 -0
  36. package/dist/adapters/runtime.d.ts.map +1 -0
  37. package/dist/adapters/runtime.js +60 -0
  38. package/dist/adapters/runtime.js.map +1 -0
  39. package/dist/adapters/textOf.d.ts +3 -0
  40. package/dist/adapters/textOf.d.ts.map +1 -0
  41. package/dist/adapters/textOf.js +4 -0
  42. package/dist/adapters/textOf.js.map +1 -0
  43. package/dist/makeOperations.d.ts +668 -0
  44. package/dist/makeOperations.d.ts.map +1 -0
  45. package/dist/makeOperations.js +55 -0
  46. package/dist/makeOperations.js.map +1 -0
  47. package/dist/pi.d.ts +4 -1
  48. package/dist/pi.d.ts.map +1 -1
  49. package/dist/pi.js +39 -1
  50. package/dist/pi.js.map +1 -1
  51. package/package.json +27 -4
  52. package/src/PiOptions.ts +4 -0
  53. package/src/adapters/deliver.ts +24 -0
  54. package/src/adapters/effort.ts +15 -0
  55. package/src/adapters/failure.ts +14 -0
  56. package/src/adapters/listPiModels.ts +16 -0
  57. package/src/adapters/mapping.ts +50 -0
  58. package/src/adapters/messageEvents.ts +50 -0
  59. package/src/adapters/openSession.ts +46 -0
  60. package/src/adapters/runtime.ts +70 -0
  61. package/src/adapters/textOf.ts +5 -0
  62. package/src/makeOperations.ts +75 -0
  63. package/src/pi.ts +44 -1
@@ -0,0 +1,323 @@
1
+ import { Effect, Stream } from "effect";
2
+ import type { PiOptions } from "#PiOptions.ts";
3
+ export declare const openSession: (options: PiOptions, request: {
4
+ readonly cwd: string;
5
+ readonly effort?: string | undefined;
6
+ readonly input: {
7
+ readonly id?: string | undefined;
8
+ readonly parts: readonly [{
9
+ readonly text: string;
10
+ readonly type: "text";
11
+ }, ...{
12
+ readonly text: string;
13
+ readonly type: "text";
14
+ }[]];
15
+ };
16
+ readonly model?: string | undefined;
17
+ readonly operationId: string;
18
+ }, resume: string | undefined) => Effect.Effect<{
19
+ acknowledge: Effect.Effect<void, never, never>;
20
+ events: Stream.Stream<{
21
+ readonly origin?: {
22
+ readonly node?: string | undefined;
23
+ readonly parentNode?: string | undefined;
24
+ readonly spawnedBy: string;
25
+ } | undefined;
26
+ readonly raw?: {
27
+ readonly kind: string;
28
+ readonly payload: string;
29
+ readonly source: string;
30
+ } | undefined;
31
+ readonly receipt: {
32
+ readonly backend: string;
33
+ readonly operationId: string;
34
+ readonly reference: {
35
+ readonly value: string;
36
+ readonly version: number;
37
+ };
38
+ readonly session?: {
39
+ readonly value: string;
40
+ readonly version: number;
41
+ } | undefined;
42
+ };
43
+ readonly type: "acknowledged";
44
+ } | {
45
+ readonly origin?: {
46
+ readonly node?: string | undefined;
47
+ readonly parentNode?: string | undefined;
48
+ readonly spawnedBy: string;
49
+ } | undefined;
50
+ readonly raw?: {
51
+ readonly kind: string;
52
+ readonly payload: string;
53
+ readonly source: string;
54
+ } | undefined;
55
+ readonly state: "accepted" | "awaiting-input" | "completed" | "failed" | "interrupted" | "running";
56
+ readonly type: "execution";
57
+ } | {
58
+ readonly origin?: {
59
+ readonly node?: string | undefined;
60
+ readonly parentNode?: string | undefined;
61
+ readonly spawnedBy: string;
62
+ } | undefined;
63
+ readonly raw?: {
64
+ readonly kind: string;
65
+ readonly payload: string;
66
+ readonly source: string;
67
+ } | undefined;
68
+ readonly reference: string;
69
+ readonly type: "session.opened";
70
+ } | {
71
+ readonly origin?: {
72
+ readonly node?: string | undefined;
73
+ readonly parentNode?: string | undefined;
74
+ readonly spawnedBy: string;
75
+ } | undefined;
76
+ readonly raw?: {
77
+ readonly kind: string;
78
+ readonly payload: string;
79
+ readonly source: string;
80
+ } | undefined;
81
+ readonly inputId?: string | undefined;
82
+ readonly parts: readonly ({
83
+ readonly text: string;
84
+ readonly type: "text";
85
+ } | {
86
+ readonly mediaType: string;
87
+ readonly path: string;
88
+ readonly type: "image";
89
+ } | {
90
+ readonly kind: string;
91
+ readonly payload: string;
92
+ readonly type: "native";
93
+ })[];
94
+ readonly role: "agent" | "user";
95
+ readonly type: "message";
96
+ } | {
97
+ readonly origin?: {
98
+ readonly node?: string | undefined;
99
+ readonly parentNode?: string | undefined;
100
+ readonly spawnedBy: string;
101
+ } | undefined;
102
+ readonly raw?: {
103
+ readonly kind: string;
104
+ readonly payload: string;
105
+ readonly source: string;
106
+ } | undefined;
107
+ readonly text: string;
108
+ readonly type: "thinking";
109
+ } | {
110
+ readonly origin?: {
111
+ readonly node?: string | undefined;
112
+ readonly parentNode?: string | undefined;
113
+ readonly spawnedBy: string;
114
+ } | undefined;
115
+ readonly raw?: {
116
+ readonly kind: string;
117
+ readonly payload: string;
118
+ readonly source: string;
119
+ } | undefined;
120
+ readonly input: string;
121
+ readonly name: string;
122
+ readonly providerName?: string | undefined;
123
+ readonly toolId: string;
124
+ readonly type: "tool.started";
125
+ } | {
126
+ readonly origin?: {
127
+ readonly node?: string | undefined;
128
+ readonly parentNode?: string | undefined;
129
+ readonly spawnedBy: string;
130
+ } | undefined;
131
+ readonly raw?: {
132
+ readonly kind: string;
133
+ readonly payload: string;
134
+ readonly source: string;
135
+ } | undefined;
136
+ readonly ok: boolean;
137
+ readonly output: string;
138
+ readonly toolId: string;
139
+ readonly type: "tool.completed";
140
+ } | {
141
+ readonly origin?: {
142
+ readonly node?: string | undefined;
143
+ readonly parentNode?: string | undefined;
144
+ readonly spawnedBy: string;
145
+ } | undefined;
146
+ readonly raw?: {
147
+ readonly kind: string;
148
+ readonly payload: string;
149
+ readonly source: string;
150
+ } | undefined;
151
+ readonly approvalId: string;
152
+ readonly description: string;
153
+ readonly toolId?: string | undefined;
154
+ readonly type: "approval.requested";
155
+ } | {
156
+ readonly origin?: {
157
+ readonly node?: string | undefined;
158
+ readonly parentNode?: string | undefined;
159
+ readonly spawnedBy: string;
160
+ } | undefined;
161
+ readonly raw?: {
162
+ readonly kind: string;
163
+ readonly payload: string;
164
+ readonly source: string;
165
+ } | undefined;
166
+ readonly type: "usage";
167
+ readonly cacheReadTokens?: number | undefined;
168
+ readonly cacheWriteTokens?: number | undefined;
169
+ readonly inputTokens?: number | undefined;
170
+ readonly model?: string | undefined;
171
+ readonly outputTokens?: number | undefined;
172
+ readonly scope: "cumulative" | "delta";
173
+ readonly unit: "run" | "session" | "turn";
174
+ } | {
175
+ readonly origin?: {
176
+ readonly node?: string | undefined;
177
+ readonly parentNode?: string | undefined;
178
+ readonly spawnedBy: string;
179
+ } | undefined;
180
+ readonly raw?: {
181
+ readonly kind: string;
182
+ readonly payload: string;
183
+ readonly source: string;
184
+ } | undefined;
185
+ readonly type: "cost";
186
+ readonly amount: number;
187
+ readonly currency: string;
188
+ readonly model?: string | undefined;
189
+ readonly scope: "cumulative" | "delta";
190
+ readonly source: "estimated" | "provider";
191
+ readonly unit: "run" | "session" | "turn";
192
+ } | {
193
+ readonly origin?: {
194
+ readonly node?: string | undefined;
195
+ readonly parentNode?: string | undefined;
196
+ readonly spawnedBy: string;
197
+ } | undefined;
198
+ readonly raw?: {
199
+ readonly kind: string;
200
+ readonly payload: string;
201
+ readonly source: string;
202
+ } | undefined;
203
+ readonly model: string;
204
+ readonly reason?: string | undefined;
205
+ readonly type: "model.changed";
206
+ } | {
207
+ readonly origin?: {
208
+ readonly node?: string | undefined;
209
+ readonly parentNode?: string | undefined;
210
+ readonly spawnedBy: string;
211
+ } | undefined;
212
+ readonly raw?: {
213
+ readonly kind: string;
214
+ readonly payload: string;
215
+ readonly source: string;
216
+ } | undefined;
217
+ readonly charter?: string | undefined;
218
+ readonly childRef: string;
219
+ readonly label?: string | undefined;
220
+ readonly parentRef?: string | undefined;
221
+ readonly spawnedBy: string;
222
+ readonly type: "child.opened";
223
+ } | {
224
+ readonly origin?: {
225
+ readonly node?: string | undefined;
226
+ readonly parentNode?: string | undefined;
227
+ readonly spawnedBy: string;
228
+ } | undefined;
229
+ readonly raw?: {
230
+ readonly kind: string;
231
+ readonly payload: string;
232
+ readonly source: string;
233
+ } | undefined;
234
+ readonly childRef: string;
235
+ readonly outcome: "completed" | "failed" | "interrupted" | "unknown";
236
+ readonly summary?: string | undefined;
237
+ readonly type: "child.ended";
238
+ } | {
239
+ readonly origin?: {
240
+ readonly node?: string | undefined;
241
+ readonly parentNode?: string | undefined;
242
+ readonly spawnedBy: string;
243
+ } | undefined;
244
+ readonly raw?: {
245
+ readonly kind: string;
246
+ readonly payload: string;
247
+ readonly source: string;
248
+ } | undefined;
249
+ readonly status: "allowed" | "rejected" | "unknown" | "warning";
250
+ readonly type: "rate.limit";
251
+ readonly windows: readonly {
252
+ readonly durationMinutes?: number | undefined;
253
+ readonly model?: string | undefined;
254
+ readonly resetsAt?: number | undefined;
255
+ readonly usedPercent: number;
256
+ }[];
257
+ } | {
258
+ readonly origin?: {
259
+ readonly node?: string | undefined;
260
+ readonly parentNode?: string | undefined;
261
+ readonly spawnedBy: string;
262
+ } | undefined;
263
+ readonly raw?: {
264
+ readonly kind: string;
265
+ readonly payload: string;
266
+ readonly source: string;
267
+ } | undefined;
268
+ readonly tasks: readonly {
269
+ readonly description: string;
270
+ readonly id: string;
271
+ readonly kind: string;
272
+ }[];
273
+ readonly type: "session.background";
274
+ } | {
275
+ readonly origin?: {
276
+ readonly node?: string | undefined;
277
+ readonly parentNode?: string | undefined;
278
+ readonly spawnedBy: string;
279
+ } | undefined;
280
+ readonly raw?: {
281
+ readonly kind: string;
282
+ readonly payload: string;
283
+ readonly source: string;
284
+ } | undefined;
285
+ readonly type: "gap";
286
+ readonly detail: string;
287
+ readonly kind: string;
288
+ } | {
289
+ readonly origin?: {
290
+ readonly node?: string | undefined;
291
+ readonly parentNode?: string | undefined;
292
+ readonly spawnedBy: string;
293
+ } | undefined;
294
+ readonly raw: {
295
+ readonly kind: string;
296
+ readonly payload: string;
297
+ readonly source: string;
298
+ };
299
+ readonly type: "raw";
300
+ }, never, never>;
301
+ inspect: Effect.Effect<{
302
+ readonly state: "accepted" | "awaiting-input" | "completed" | "failed" | "interrupted" | "running";
303
+ readonly type: "known";
304
+ } | {
305
+ readonly reason: string;
306
+ readonly type: "missing";
307
+ }, never, never>;
308
+ interrupt: Effect.Effect<void, import("@shivaedev/agent/failures.ts").BackendUnavailable, never>;
309
+ prompt: (text: string, delivery: "followUp" | "steer") => Effect.Effect<void, import("@shivaedev/agent/failures.ts").BackendUnavailable | import("@shivaedev/agent/failures.ts").ProtocolFailure | import("@shivaedev/agent/failures.ts").Rejected | import("@shivaedev/agent/failures.ts").UnknownAcceptance, never>;
310
+ receipt: {
311
+ readonly backend: string;
312
+ readonly operationId: string;
313
+ readonly reference: {
314
+ readonly value: string;
315
+ readonly version: number;
316
+ };
317
+ readonly session?: {
318
+ readonly value: string;
319
+ readonly version: number;
320
+ } | undefined;
321
+ };
322
+ }, import("@shivaedev/agent/failures.ts").BackendUnavailable | import("@shivaedev/agent/failures.ts").Rejected, import("effect/Scope").Scope>;
323
+ //# sourceMappingURL=openSession.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"openSession.d.ts","sourceRoot":"","sources":["../../src/adapters/openSession.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,MAAM,EAAS,MAAM,EAAE,MAAM,QAAQ,CAAC;AAO3D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAE/C,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;mBAiCP,MAAM,YAAY,UAAU,GAAG,OAAO;;;;;;;;;;;;;6IAGrD,CAAC"}
@@ -0,0 +1,41 @@
1
+ import { Effect, Queue, Stream } from "effect";
2
+ import { deliver } from "#adapters/deliver.ts";
3
+ import { unavailable } from "#adapters/failure.ts";
4
+ import { rawOf, toAgentEvents } from "#adapters/mapping.ts";
5
+ import { openRuntime } from "#adapters/runtime.ts";
6
+ export const openSession = Effect.fnUntraced(function* (options, request, resume) {
7
+ const { session, sessionFile } = yield* openRuntime(options, request, resume);
8
+ const output = yield* Queue.unbounded();
9
+ let observation = { state: "accepted", type: "known" };
10
+ function emit(event) {
11
+ if (event.type === "execution") {
12
+ observation = { state: event.state, type: "known" };
13
+ }
14
+ Queue.offerUnsafe(output, event);
15
+ }
16
+ const unsubscribe = session.subscribe((event) => {
17
+ for (const mapped of toAgentEvents(event)) {
18
+ emit(mapped);
19
+ }
20
+ });
21
+ yield* Effect.addFinalizer(() => Effect.sync(() => {
22
+ unsubscribe();
23
+ Queue.endUnsafe(output);
24
+ }));
25
+ const receipt = {
26
+ backend: "pi",
27
+ operationId: request.operationId,
28
+ reference: { value: sessionFile, version: 1 },
29
+ session: { value: sessionFile, version: 1 },
30
+ };
31
+ emit({ raw: rawOf("session/opened", { sessionFile, sessionId: session.sessionId }), reference: sessionFile, type: "session.opened" });
32
+ return {
33
+ acknowledge: Effect.sync(() => emit({ receipt, type: "acknowledged" })),
34
+ events: Stream.fromQueue(output),
35
+ inspect: Effect.sync(() => observation),
36
+ interrupt: Effect.tryPromise({ catch: unavailable, try: () => session.abort() }),
37
+ prompt: (text, delivery) => deliver(session, text, delivery),
38
+ receipt,
39
+ };
40
+ });
41
+ //# sourceMappingURL=openSession.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"openSession.js","sourceRoot":"","sources":["../../src/adapters/openSession.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAG3D,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAAE,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAC5D,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAGnD,MAAM,CAAC,M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EAAE,WAAW,EAAE,OAAO,EAAE,CAAC,EAAE;KAC3C,CAAC;IACF,IAAI,CAAC,EAAE,GAAG,EAAE,KAAK,CAAC,gBAAgB,EAAE,EAAE,WAAW,EAAE,SAAS,EAAE,OAAO,CAAC,SAAS,EAAE,CAAC,EAAE,SAAS,EAAE,WAAW,EAAE,IAAI,EAAE,gBAAgB,EAAE,CAAC,CAAC;IACtI,OAAO;QACN,WAAW,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,cAAc,EAAE,CAAC,CAAC;QACvE,MAAM,EAAE,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC;QAChC,OAAO,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,WAAW,CAAC;QACvC,SAAS,EAAE,MAAM,CAAC,UAAU,CAAC,EAAE,KAAK,EAAE,WAAW,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC;QAChF,MAAM,EAAE,CAAC,IAAY,EAAE,QAA8B,EAAE,EAAE,CAAC,OAAO,CAAC,OAAO,EAAE,IAAI,EAAE,QAAQ,CAAC;QAC1F,OAAO;KACP,CAAC;AACH,CAAC,CAAC,CAAC"}
@@ -0,0 +1,24 @@
1
+ import type { AgentSession } from "@earendil-works/pi-coding-agent";
2
+ import { Effect } from "effect";
3
+ import type { PiOptions } from "#PiOptions.ts";
4
+ export declare const loadSdk: Effect.Effect<typeof import("@earendil-works/pi-coding-agent"), import("@shivaedev/agent/failures.ts").BackendUnavailable, never>;
5
+ export declare const openRuntime: (options: PiOptions, request: {
6
+ readonly cwd: string;
7
+ readonly effort?: string | undefined;
8
+ readonly input: {
9
+ readonly id?: string | undefined;
10
+ readonly parts: readonly [{
11
+ readonly text: string;
12
+ readonly type: "text";
13
+ }, ...{
14
+ readonly text: string;
15
+ readonly type: "text";
16
+ }[]];
17
+ };
18
+ readonly model?: string | undefined;
19
+ readonly operationId: string;
20
+ }, resume: string | undefined) => Effect.Effect<{
21
+ session: AgentSession;
22
+ sessionFile: string;
23
+ }, import("@shivaedev/agent/failures.ts").BackendUnavailable | import("@shivaedev/agent/failures.ts").Rejected, import("effect/Scope").Scope>;
24
+ //# sourceMappingURL=runtime.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../../src/adapters/runtime.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAC;AACpE,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAIhC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAE/C,eAAO,MAAM,OAAO,mIAAkG,CAAC;AAEvH,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;;;6IA6CtB,CAAC"}
@@ -0,0 +1,60 @@
1
+ import { access } from "node:fs/promises";
2
+ import { Effect } from "effect";
3
+ import { thinkingLevel } from "#adapters/effort.ts";
4
+ import { rejected, unavailable } from "#adapters/failure.ts";
5
+ export const loadSdk = Effect.tryPromise({ catch: unavailable, try: () => import("@earendil-works/pi-coding-agent") });
6
+ export const openRuntime = Effect.fnUntraced(function* (options, request, resume) {
7
+ const effort = yield* thinkingLevel(request.effort);
8
+ if (resume !== undefined) {
9
+ yield* Effect.tryPromise({ catch: () => unavailable("Pi session file is unavailable for resume"), try: () => access(resume) });
10
+ }
11
+ const sdk = yield* loadSdk;
12
+ const modelRuntime = yield* Effect.tryPromise({ catch: unavailable, try: () => sdk.ModelRuntime.create() });
13
+ const models = yield* Effect.tryPromise({ catch: unavailable, try: () => modelRuntime.getAvailable() });
14
+ const model = request.model === undefined ? models[0] : models.find((value) => `${value.provider}/${value.id}` === request.model);
15
+ if (model === undefined) {
16
+ return yield* Effect.fail(rejected(`Pi offers no model ${request.model ?? "(default)"} with credentials; choose provider/model-id from its catalog`));
17
+ }
18
+ const session = yield* Effect.acquireRelease(Effect.tryPromise({
19
+ catch: unavailable,
20
+ try: async () => {
21
+ const agentDir = sdk.getAgentDir();
22
+ const resourceLoader = new sdk.DefaultResourceLoader({
23
+ agentDir,
24
+ cwd: request.cwd,
25
+ ...resourceOptions(options),
26
+ });
27
+ await resourceLoader.reload();
28
+ const { session: opened } = await sdk.createAgentSession({
29
+ agentDir,
30
+ customTools: [],
31
+ cwd: request.cwd,
32
+ model,
33
+ modelRuntime,
34
+ resourceLoader,
35
+ sessionManager: resume === undefined ? sdk.SessionManager.create(request.cwd) : sdk.SessionManager.open(resume, undefined, request.cwd),
36
+ ...(options.constrainedPrompt === undefined ? {} : { tools: [] }),
37
+ ...(effort === undefined ? {} : { thinkingLevel: effort }),
38
+ });
39
+ return opened;
40
+ },
41
+ }), (openedSession) => Effect.promise(() => openedSession.abort()).pipe(Effect.ensuring(Effect.sync(() => openedSession.dispose()))));
42
+ if (session.sessionFile === undefined) {
43
+ return yield* Effect.fail(unavailable("Pi opened a session without a persisted file reference"));
44
+ }
45
+ return { session, sessionFile: session.sessionFile };
46
+ });
47
+ function resourceOptions(options) {
48
+ if (options.constrainedPrompt === undefined) {
49
+ return { additionalSkillPaths: [...(options.skills ?? [])] };
50
+ }
51
+ return {
52
+ noContextFiles: true,
53
+ noExtensions: true,
54
+ noPromptTemplates: true,
55
+ noSkills: true,
56
+ noThemes: true,
57
+ systemPrompt: options.constrainedPrompt,
58
+ };
59
+ }
60
+ //# sourceMappingURL=runtime.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime.js","sourceRoot":"","sources":["../../src/adapters/runtime.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAE1C,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC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AC,EAAE,CAAC,CAAC,CAAC,EAAE,aAAa,EAAE,MAAM,EAAE,CAAC;aAC1D,CAAC,CAAC;YACH,OAAO,MAAM,CAAC;QACf,CAAC;KACD,CAAC,EACF,CAAC,aAA2B,EAAE,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,aAAa,CAAC,KAAK,EAAE,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,aAAa,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,CAC9I,CAAC;IACF,IAAI,OAAO,CAAC,WAAW,KAAK,SAAS,EAAE,CAAC;QACvC,OAAO,KAAK,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,wDAAwD,CAAC,CAAC,CAAC;IAClG,CAAC;IACD,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,OAAO,CAAC,WAAW,EAAE,CAAC;AACtD,CAAC,CAAC,CAAC;AAEH,SAAS,eAAe,CAAC,OAAkB;IAC1C,IAAI,OAAO,CAAC,iBAAiB,KAAK,SAAS,EAAE,CAAC;QAC7C,OAAO,EAAE,oBAAoB,EAAE,CAAC,GAAG,CAAC,OAAO,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC;IAC9D,CAAC;IACD,OAAO;QACN,cAAc,EAAE,IAAI;QACpB,YAAY,EAAE,IAAI;QAClB,iBAAiB,EAAE,IAAI;QACvB,QAAQ,EAAE,IAAI;QACd,QAAQ,EAAE,IAAI;QACd,YAAY,EAAE,OAAO,CAAC,iBAAiB;KACvC,CAAC;AACH,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { Input } from "@shivaedev/agent/run.ts";
2
+ export declare function textOf(input: Input): string;
3
+ //# sourceMappingURL=textOf.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"textOf.d.ts","sourceRoot":"","sources":["../../src/adapters/textOf.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AAErD,wBAAgB,MAAM,CAAC,KAAK,EAAE,KAAK,UAElC"}
@@ -0,0 +1,4 @@
1
+ export function textOf(input) {
2
+ return input.parts.map((part) => part.text).join("\n");
3
+ }
4
+ //# sourceMappingURL=textOf.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"textOf.js","sourceRoot":"","sources":["../../src/adapters/textOf.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,MAAM,CAAC,KAAY;IAClC,OAAO,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACxD,CAAC"}