@jpowersdev/effect-pi 0.1.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 +15 -0
- package/CONTRIBUTING.md +40 -0
- package/LICENSE +21 -0
- package/README.md +91 -0
- package/dist/ClusterSessions.d.ts +2 -0
- package/dist/ClusterSessions.d.ts.map +1 -0
- package/dist/ClusterSessions.js +2 -0
- package/dist/ClusterSessions.js.map +1 -0
- package/dist/LocalSessions.d.ts +2 -0
- package/dist/LocalSessions.d.ts.map +1 -0
- package/dist/LocalSessions.js +2 -0
- package/dist/LocalSessions.js.map +1 -0
- package/dist/ModelRuntime.d.ts +2 -0
- package/dist/ModelRuntime.d.ts.map +1 -0
- package/dist/ModelRuntime.js +2 -0
- package/dist/ModelRuntime.js.map +1 -0
- package/dist/ResourceLoader.d.ts +2 -0
- package/dist/ResourceLoader.d.ts.map +1 -0
- package/dist/ResourceLoader.js +2 -0
- package/dist/ResourceLoader.js.map +1 -0
- package/dist/Session.d.ts +3 -0
- package/dist/Session.d.ts.map +1 -0
- package/dist/Session.js +3 -0
- package/dist/Session.js.map +1 -0
- package/dist/Sessions.d.ts +14 -0
- package/dist/Sessions.d.ts.map +1 -0
- package/dist/Sessions.js +5 -0
- package/dist/Sessions.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -0
- package/dist/internal/ClusterSessions.d.ts +44 -0
- package/dist/internal/ClusterSessions.d.ts.map +1 -0
- package/dist/internal/ClusterSessions.js +72 -0
- package/dist/internal/ClusterSessions.js.map +1 -0
- package/dist/internal/LocalSessions.d.ts +19 -0
- package/dist/internal/LocalSessions.d.ts.map +1 -0
- package/dist/internal/LocalSessions.js +25 -0
- package/dist/internal/LocalSessions.js.map +1 -0
- package/dist/internal/ModelRuntime.d.ts +42 -0
- package/dist/internal/ModelRuntime.d.ts.map +1 -0
- package/dist/internal/ModelRuntime.js +66 -0
- package/dist/internal/ModelRuntime.js.map +1 -0
- package/dist/internal/Persistence.d.ts +12 -0
- package/dist/internal/Persistence.d.ts.map +1 -0
- package/dist/internal/Persistence.js +26 -0
- package/dist/internal/Persistence.js.map +1 -0
- package/dist/internal/Pi.d.ts +51 -0
- package/dist/internal/Pi.d.ts.map +1 -0
- package/dist/internal/Pi.js +258 -0
- package/dist/internal/Pi.js.map +1 -0
- package/dist/internal/Protocol.d.ts +41 -0
- package/dist/internal/Protocol.d.ts.map +1 -0
- package/dist/internal/Protocol.js +33 -0
- package/dist/internal/Protocol.js.map +1 -0
- package/dist/internal/ResourceLoader.d.ts +46 -0
- package/dist/internal/ResourceLoader.d.ts.map +1 -0
- package/dist/internal/ResourceLoader.js +77 -0
- package/dist/internal/ResourceLoader.js.map +1 -0
- package/dist/internal/Session.d.ts +82 -0
- package/dist/internal/Session.d.ts.map +1 -0
- package/dist/internal/Session.js +63 -0
- package/dist/internal/Session.js.map +1 -0
- package/dist-examples/cluster-session.d.ts +2 -0
- package/dist-examples/cluster-session.d.ts.map +1 -0
- package/dist-examples/cluster-session.js +77 -0
- package/dist-examples/cluster-session.js.map +1 -0
- package/dist-examples/local-session-pool.d.ts +2 -0
- package/dist-examples/local-session-pool.d.ts.map +1 -0
- package/dist-examples/local-session-pool.js +60 -0
- package/dist-examples/local-session-pool.js.map +1 -0
- package/dist-examples/single-session.d.ts +2 -0
- package/dist-examples/single-session.d.ts.map +1 -0
- package/dist-examples/single-session.js +49 -0
- package/dist-examples/single-session.js.map +1 -0
- package/docs/reference.md +248 -0
- package/examples/README.md +111 -0
- package/examples/cluster-session.ts +131 -0
- package/examples/local-session-pool.ts +107 -0
- package/examples/single-session.ts +85 -0
- package/package.json +62 -0
- package/src/ClusterSessions.ts +6 -0
- package/src/LocalSessions.ts +1 -0
- package/src/ModelRuntime.ts +10 -0
- package/src/ResourceLoader.ts +13 -0
- package/src/Session.ts +14 -0
- package/src/Sessions.ts +17 -0
- package/src/index.ts +6 -0
- package/src/internal/ClusterSessions.ts +126 -0
- package/src/internal/LocalSessions.ts +45 -0
- package/src/internal/ModelRuntime.ts +105 -0
- package/src/internal/Persistence.ts +40 -0
- package/src/internal/Pi.ts +346 -0
- package/src/internal/Protocol.ts +39 -0
- package/src/internal/ResourceLoader.ts +128 -0
- package/src/internal/Session.ts +109 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.1.0 — 2026-09-21
|
|
4
|
+
|
|
5
|
+
- Scoped direct, local-pool, and cluster-backed Pi sessions with authoritative KeyValueStore JSONL.
|
|
6
|
+
- First-class ResourceLoader and ModelRuntime layers, typed SDK setup failures, and per-session isolation of resources, settings, and model runtimes. Session construction now requires ModelRuntime; SDK configuration callbacks no longer own these bindings.
|
|
7
|
+
- Config-driven layer constructors for resources, model runtimes, local pools, and cluster runners; standalone examples compose top-level layers with lazy ConfigProvider resolution.
|
|
8
|
+
- Cancellation-safe SDK acquisition; session-owned prompt fibers settle before release or reuse.
|
|
9
|
+
- Interruptible cluster prompts, concurrent abort, and cancellation of queued prompts without aborting unrelated work.
|
|
10
|
+
- Checkpoints on construction, completed/failed prompts, abort, and release; release checkpoint failures are surfaced.
|
|
11
|
+
- Rejection of malformed JSON syntax and mismatched stored session identities.
|
|
12
|
+
- Fresh-response detection, terminal model-error reporting, and prompt-wide recorded usage totals.
|
|
13
|
+
- Bounded sliding event streams, coalesced checkpoint requests, and SDK diagnostic logging.
|
|
14
|
+
- Isolated regression tests and self-contained session, pool, and single-process socket-cluster examples using SQLite.
|
|
15
|
+
- Exact Effect peer dependency, source-map sources in the tarball, and MIT licensing.
|
package/CONTRIBUTING.md
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# Contributing and releasing
|
|
2
|
+
|
|
3
|
+
This is a small experimental library. Bug reports and focused changes are welcome; discuss API expansion before investing in it. There is no promised support schedule.
|
|
4
|
+
|
|
5
|
+
Use Node 26 and the pnpm version in `package.json`. Nix/direnv is optional. The Linux development shell downloads/refreshes a read-only Effect checkout in `.vendor/`; installed dependencies remain authoritative.
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
pnpm install --frozen-lockfile
|
|
9
|
+
pnpm check
|
|
10
|
+
pnpm test
|
|
11
|
+
pnpm pack --pack-destination /tmp/effect-pi-pack
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
`check` covers source, tests, and examples. `pack` starts with a clean build and runs checks/tests. Test fixtures must not load a contributor's Pi credentials, extensions, or working files. Normal tests never make model requests.
|
|
15
|
+
|
|
16
|
+
## Design boundaries
|
|
17
|
+
|
|
18
|
+
- Keep public exports under `src/index.ts`: `ResourceLoader`, `ModelRuntime`, `Session`, `Sessions`, `LocalSessions`, `ClusterSessions`.
|
|
19
|
+
- `ModelRuntime` captures `ResourceLoader`. Reuse configuration layers while allocating mutable SDK bindings per live session; keep Promise adapters inside the library.
|
|
20
|
+
- Pi owns JSONL formats/migrations/tree semantics. The configured `KeyValueStore` owns the durable document.
|
|
21
|
+
- One live session serializes prompts; cancellation, snapshots, and event subscriptions must remain concurrent.
|
|
22
|
+
- Prompt cancellation must settle the underlying SDK operation before the gate or resource is released.
|
|
23
|
+
- Do not persist model prompt RPCs without a real idempotency protocol.
|
|
24
|
+
- Live events are bounded and ephemeral, not another durable conversation log.
|
|
25
|
+
- Keep examples self-contained, even when that repeats setup. The cluster example owns both the runner and client in one process.
|
|
26
|
+
- Define reusable layers at module scope. Use `layerConfig` for config-driven options and reserve `Layer.unwrap` for construction that needs yielded values/services. Keep application Effects focused on consuming services.
|
|
27
|
+
|
|
28
|
+
See `AGENTS.md` and `EFFECT.md` for implementation guidance. Where the SDK offers no cancellation API, document the protected acquisition/cleanup boundary rather than pretending interruption can force it to stop.
|
|
29
|
+
|
|
30
|
+
## Release checklist
|
|
31
|
+
|
|
32
|
+
1. Review changes and update `CHANGELOG.md` and the package version.
|
|
33
|
+
2. Keep Effect and all `@effect/*` versions aligned and update the lockfile together; review Pi changes together with the SDK-boundary tests.
|
|
34
|
+
3. Run a frozen install, checks, tests, and `pnpm pack`.
|
|
35
|
+
4. Inspect the tarball: public exports, license, source maps, example assets, and no private/runtime data.
|
|
36
|
+
5. Install the tarball in a fresh consumer; typecheck an import and run the compiled `--snapshot` examples with their optional dependencies. See `examples/README.md`.
|
|
37
|
+
6. If Git history is available, scan it for secrets before making the repository public. Never include real credentials or transcripts in fixtures/issues.
|
|
38
|
+
7. Review API/known-limitations documentation, then publish the reviewed tarball from the intended npm account. Use npm 2FA or trusted publishing; add provenance when the release environment supports it.
|
|
39
|
+
|
|
40
|
+
CI checks build/test/package creation and exercises the self-contained session, pool, and single-process socket-cluster examples without model requests. Production network partitions, forced process loss, and paid provider behavior still require separate integration validation.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 jpowersdev
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
# effect-pi
|
|
2
|
+
|
|
3
|
+
Use the [Pi coding agent](https://github.com/earendil-works/pi) in an [Effect](https://effect.website) application.
|
|
4
|
+
|
|
5
|
+
effect-pi wraps Pi's SDK so you can send prompts, follow responses as they arrive, and pick up saved conversations later. It handles session cleanup and makes sure prompts for the same session run one at a time.
|
|
6
|
+
|
|
7
|
+
Start with sessions running in your own process. If you later want to run them on separate workers, switch to Effect Cluster—the code that uses a session stays the same.
|
|
8
|
+
|
|
9
|
+
This is a small, experimental project for personal use. The API may change.
|
|
10
|
+
|
|
11
|
+
## What using it looks like
|
|
12
|
+
|
|
13
|
+
Once you've set up a `Sessions` layer, your application code looks like this:
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import * as Console from "effect/Console"
|
|
17
|
+
import * as Effect from "effect/Effect"
|
|
18
|
+
|
|
19
|
+
import { Session, Sessions } from "@jpowersdev/effect-pi"
|
|
20
|
+
|
|
21
|
+
export const program = Effect.gen(function* () {
|
|
22
|
+
const sessions = yield* Sessions
|
|
23
|
+
|
|
24
|
+
const id = Session.Id.make("my-project")
|
|
25
|
+
|
|
26
|
+
const session = yield* sessions.open(id)
|
|
27
|
+
|
|
28
|
+
const reply = yield* session.prompt("Explain how this project is organized")
|
|
29
|
+
|
|
30
|
+
yield* Console.log(reply.text)
|
|
31
|
+
}).pipe(Effect.scoped)
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Use the same id and storage to continue the conversation later. You can also listen to `session.events`, check progress with `session.snapshot`, or stop the current prompt with `session.abort`.
|
|
35
|
+
|
|
36
|
+
Model and resource setup are Effect layers too: `ResourceLoader` feeds `ModelRuntime`, which sessions consume. Define and compose them at module scope; `layerConfig` reads configuration when they're built. The library handles Pi's asynchronous setup and errors—you don't need to write Promise adapters.
|
|
37
|
+
|
|
38
|
+
The [complete local example](examples/local-session-pool.ts) shows how to provide these layers and storage around this code.
|
|
39
|
+
|
|
40
|
+
## Try it
|
|
41
|
+
|
|
42
|
+
You'll need **Node.js 26+**, pnpm, and a model provider's credentials to send prompts.
|
|
43
|
+
|
|
44
|
+
```sh
|
|
45
|
+
pnpm install --frozen-lockfile
|
|
46
|
+
pnpm build
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Follow the [example setup](examples/README.md#setup) to create the data directory and configure a model and credentials, then run:
|
|
50
|
+
|
|
51
|
+
```sh
|
|
52
|
+
pnpm example:pool "Say hello in one sentence"
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
The examples use SQLite to save conversations and explicitly configure Pi rather than loading your usual extensions and settings.
|
|
56
|
+
|
|
57
|
+
There are three ways to use the library:
|
|
58
|
+
|
|
59
|
+
- **One session:** [`single-session.ts`](examples/single-session.ts) sends a prompt and saves the conversation.
|
|
60
|
+
- **A pool of sessions:** [`local-session-pool.ts`](examples/local-session-pool.ts) opens a session, releases it, and reopens it in another request. This is the best place to start.
|
|
61
|
+
- **Cluster-backed sessions:** [`cluster-session.ts`](examples/cluster-session.ts) starts a client and runner in one process, communicating over a local socket.
|
|
62
|
+
|
|
63
|
+
Each example is self-contained, including its configuration and storage setup.
|
|
64
|
+
|
|
65
|
+
For use in another project, see [installation and compatibility](docs/reference.md#installation-and-compatibility). The package is named `@jpowersdev/effect-pi` and currently uses Effect `4.0.0-rc.116` and Pi `0.86.1`.
|
|
66
|
+
|
|
67
|
+
## A few things to know
|
|
68
|
+
|
|
69
|
+
- **This isn't a sandbox.** Pi's tools and extensions run with your process's permissions. Even read-only tools can read outside the working directory, so use trusted workspaces and protect your credentials.
|
|
70
|
+
- **Saved conversations can contain private data.** Choose storage and access controls accordingly. The examples don't encrypt their database.
|
|
71
|
+
- **Stopping work doesn't undo it.** Cancellation waits for Pi and its tools to stop. A timeout or lost connection doesn't undo file changes or model charges, so don't blindly retry a prompt.
|
|
72
|
+
|
|
73
|
+
Pi still handles the agent loop and its conversation format. This library adds the Effect integration; it doesn't try to replace Pi or provide a hosted agent service.
|
|
74
|
+
|
|
75
|
+
The [reference guide](docs/reference.md) covers configuration, storage requirements, cancellation, and the limits of cluster execution.
|
|
76
|
+
|
|
77
|
+
## Development
|
|
78
|
+
|
|
79
|
+
```sh
|
|
80
|
+
pnpm check
|
|
81
|
+
pnpm test
|
|
82
|
+
pnpm pack
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
Tests don't make paid model requests. `pnpm pack` runs a clean build, checks, and tests before producing the package. Nix/direnv is available but optional.
|
|
86
|
+
|
|
87
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md) for development and release notes, and [CHANGELOG.md](CHANGELOG.md) for changes.
|
|
88
|
+
|
|
89
|
+
## License
|
|
90
|
+
|
|
91
|
+
[MIT](LICENSE), the same license used by Effect.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ClusterSessions.d.ts","sourceRoot":"","sources":["../src/ClusterSessions.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,WAAW,EACX,iBAAiB,EACjB,KAAK,OAAO,EACb,MAAM,+BAA+B,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ClusterSessions.js","sourceRoot":"","sources":["../src/ClusterSessions.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,WAAW,EACX,iBAAiB,EAElB,MAAM,+BAA+B,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LocalSessions.d.ts","sourceRoot":"","sources":["../src/LocalSessions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,KAAK,OAAO,EAAE,MAAM,6BAA6B,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LocalSessions.js","sourceRoot":"","sources":["../src/LocalSessions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,WAAW,EAAgB,MAAM,6BAA6B,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ModelRuntime.d.ts","sourceRoot":"","sources":["../src/ModelRuntime.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,OAAO,EACZ,KAAK,EACL,KAAK,EACL,WAAW,EACX,IAAI,EACJ,YAAY,EACZ,KAAK,UAAU,EACf,KAAK,OAAO,EACb,MAAM,4BAA4B,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ModelRuntime.js","sourceRoot":"","sources":["../src/ModelRuntime.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,EACL,KAAK,EACL,WAAW,EACX,IAAI,EACJ,YAAY,EAGb,MAAM,4BAA4B,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ResourceLoader.d.ts","sourceRoot":"","sources":["../src/ResourceLoader.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,EACL,KAAK,EACL,WAAW,EACX,UAAU,EACV,gBAAgB,EAChB,KAAK,YAAY,EACjB,KAAK,MAAM,EACX,KAAK,UAAU,EACf,KAAK,OAAO,EACZ,cAAc,EACd,KAAK,QAAQ,EACd,MAAM,8BAA8B,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ResourceLoader.js","sourceRoot":"","sources":["../src/ResourceLoader.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,EACL,KAAK,EACL,WAAW,EACX,UAAU,EACV,gBAAgB,EAKhB,cAAc,EAEf,MAAM,8BAA8B,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Session.d.ts","sourceRoot":"","sources":["../src/Session.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,EACL,KAAK,EACL,EAAE,EACF,KAAK,MAAM,EACX,KAAK,WAAW,EAChB,KAAK,SAAS,EACd,KAAK,SAAS,EACd,YAAY,EACZ,KAAK,OAAO,EACZ,QAAQ,EACR,MAAM,EACP,MAAM,uBAAuB,CAAA;AAC9B,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAA"}
|
package/dist/Session.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Session.js","sourceRoot":"","sources":["../src/Session.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,EACL,KAAK,EACL,EAAE,EAKF,YAAY,EAEZ,QAAQ,EACR,MAAM,EACP,MAAM,uBAAuB,CAAA;AAC9B,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAA"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import * as Context from "effect/Context";
|
|
2
|
+
import type * as Effect from "effect/Effect";
|
|
3
|
+
import type * as Scope from "effect/Scope";
|
|
4
|
+
import type * as Session from "./internal/Session.js";
|
|
5
|
+
export interface Operations {
|
|
6
|
+
/** Acquire the session for an id within the current scope. */
|
|
7
|
+
readonly open: (id: Session.Id) => Effect.Effect<Session.Session, Session.Error, Scope.Scope>;
|
|
8
|
+
}
|
|
9
|
+
declare const Sessions_base: Context.ServiceClass<Sessions, "@jpowersdev/effect-pi/Sessions", Operations>;
|
|
10
|
+
/** Location-independent access to keyed Pi sessions. */
|
|
11
|
+
export declare class Sessions extends Sessions_base {
|
|
12
|
+
}
|
|
13
|
+
export {};
|
|
14
|
+
//# sourceMappingURL=Sessions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Sessions.d.ts","sourceRoot":"","sources":["../src/Sessions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAA;AACzC,OAAO,KAAK,KAAK,MAAM,MAAM,eAAe,CAAA;AAC5C,OAAO,KAAK,KAAK,KAAK,MAAM,cAAc,CAAA;AAE1C,OAAO,KAAK,KAAK,OAAO,MAAM,uBAAuB,CAAA;AAErD,MAAM,WAAW,UAAU;IACzB,8DAA8D;IAC9D,QAAQ,CAAC,IAAI,EAAE,CACb,EAAE,EAAE,OAAO,CAAC,EAAE,KACX,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,OAAO,EAAE,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC,CAAA;CAChE;;AAED,wDAAwD;AACxD,qBAAa,QAAS,SAAQ,aAE7B;CAAG"}
|
package/dist/Sessions.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Sessions.js","sourceRoot":"","sources":["../src/Sessions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAA;AAazC,wDAAwD;AACxD,MAAM,OAAO,QAAS,SAAQ,OAAO,CAAC,OAAO,EAAwB,CACnE,gCAAgC,CACjC;CAAG"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export * as ClusterSessions from "./ClusterSessions.js";
|
|
2
|
+
export * as LocalSessions from "./LocalSessions.js";
|
|
3
|
+
export * as ModelRuntime from "./ModelRuntime.js";
|
|
4
|
+
export * as ResourceLoader from "./ResourceLoader.js";
|
|
5
|
+
export * as Session from "./Session.js";
|
|
6
|
+
export { Sessions } from "./Sessions.js";
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,eAAe,MAAM,sBAAsB,CAAA;AACvD,OAAO,KAAK,aAAa,MAAM,oBAAoB,CAAA;AACnD,OAAO,KAAK,YAAY,MAAM,mBAAmB,CAAA;AACjD,OAAO,KAAK,cAAc,MAAM,qBAAqB,CAAA;AACrD,OAAO,KAAK,OAAO,MAAM,cAAc,CAAA;AACvC,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export * as ClusterSessions from "./ClusterSessions.js";
|
|
2
|
+
export * as LocalSessions from "./LocalSessions.js";
|
|
3
|
+
export * as ModelRuntime from "./ModelRuntime.js";
|
|
4
|
+
export * as ResourceLoader from "./ResourceLoader.js";
|
|
5
|
+
export * as Session from "./Session.js";
|
|
6
|
+
export { Sessions } from "./Sessions.js";
|
|
7
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,eAAe,MAAM,sBAAsB,CAAA;AACvD,OAAO,KAAK,aAAa,MAAM,oBAAoB,CAAA;AACnD,OAAO,KAAK,YAAY,MAAM,mBAAmB,CAAA;AACjD,OAAO,KAAK,cAAc,MAAM,qBAAqB,CAAA;AACrD,OAAO,KAAK,OAAO,MAAM,cAAc,CAAA;AACvC,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import * as Config from "effect/Config";
|
|
2
|
+
import type * as Duration from "effect/Duration";
|
|
3
|
+
import * as Effect from "effect/Effect";
|
|
4
|
+
import * as Layer from "effect/Layer";
|
|
5
|
+
import * as Schema from "effect/Schema";
|
|
6
|
+
import type * as Scope from "effect/Scope";
|
|
7
|
+
import * as Entity from "effect/unstable/cluster/Entity";
|
|
8
|
+
import type * as Sharding from "effect/unstable/cluster/Sharding";
|
|
9
|
+
import { Sessions } from "../Sessions.js";
|
|
10
|
+
import * as Session from "./Session.js";
|
|
11
|
+
export interface Options extends Session.Config {
|
|
12
|
+
/** Idle live-resource lifetime; defaults to 15 minutes. */
|
|
13
|
+
readonly resourceIdleTimeToLive?: Duration.Input;
|
|
14
|
+
readonly entityMaxIdleTime?: Duration.Input;
|
|
15
|
+
/** Queued entity messages; does not limit all concurrently executing handlers. Defaults to 128. */
|
|
16
|
+
readonly mailboxCapacity?: number | "unbounded";
|
|
17
|
+
}
|
|
18
|
+
type MakeSession<R> = (options: Session.MakeOptions) => Effect.Effect<Session.Session, Session.Error, Scope.Scope | R>;
|
|
19
|
+
/** Internal constructor seam used to test entity behavior without model calls. */
|
|
20
|
+
export declare const runnerLayerWith: <R>(options: Options, makeSession: MakeSession<R>) => Layer.Layer<never, never, Sharding.Sharding | R>;
|
|
21
|
+
/** Registers the server-side cluster entity handlers. */
|
|
22
|
+
export declare const runnerLayer: (options: Options) => Layer.Layer<never, never, import("effect/FileSystem").FileSystem | import("effect/unstable/persistence/KeyValueStore").KeyValueStore | import("./ModelRuntime.js").ModelRuntime | import("effect/Path").Path | Sharding.Sharding>;
|
|
23
|
+
/** Resolve runner options using the active ConfigProvider at layer build time. */
|
|
24
|
+
export declare const runnerLayerConfig: (options: Config.Wrap<Options>) => Layer.Layer<never, Config.ConfigError, import("effect/FileSystem").FileSystem | import("effect/unstable/persistence/KeyValueStore").KeyValueStore | import("./ModelRuntime.js").ModelRuntime | import("effect/Path").Path | Sharding.Sharding>;
|
|
25
|
+
/** Implements Sessions using location-transparent Effect Cluster clients. */
|
|
26
|
+
export declare const clientLayer: Layer.Layer<Sessions, never, Sharding.Sharding>;
|
|
27
|
+
export declare const entity: Entity.Entity<"PiSession", import("effect/unstable/rpc/Rpc").Rpc<"Abort", Schema.Void, Schema.Void, typeof Session.Error, never, never> | import("effect/unstable/rpc/Rpc").Rpc<"Events", Schema.Void, import("effect/unstable/rpc/RpcSchema").Stream<Schema.Union<readonly [Schema.TaggedStruct<"Status", {
|
|
28
|
+
readonly sequence: Schema.Natural;
|
|
29
|
+
readonly status: Schema.Literals<readonly ["idle", "streaming"]>;
|
|
30
|
+
}>, Schema.TaggedStruct<"TextDelta", {
|
|
31
|
+
readonly sequence: Schema.Natural;
|
|
32
|
+
readonly delta: Schema.String;
|
|
33
|
+
}>, Schema.TaggedStruct<"ToolStarted", {
|
|
34
|
+
readonly sequence: Schema.Natural;
|
|
35
|
+
readonly toolName: Schema.String;
|
|
36
|
+
}>, Schema.TaggedStruct<"ToolFinished", {
|
|
37
|
+
readonly sequence: Schema.Natural;
|
|
38
|
+
readonly toolName: Schema.String;
|
|
39
|
+
readonly isError: Schema.Boolean;
|
|
40
|
+
}>]>, typeof Session.Error>, Schema.Never, never, never> | import("effect/unstable/rpc/Rpc").Rpc<"Jsonl", Schema.Void, Schema.String, typeof Session.Error, never, never> | import("effect/unstable/rpc/Rpc").Rpc<"Prompt", Schema.Struct<{
|
|
41
|
+
text: Schema.NonEmptyString;
|
|
42
|
+
}>, typeof Session.PromptResult, typeof Session.Error, never, never> | import("effect/unstable/rpc/Rpc").Rpc<"Snapshot", Schema.Void, typeof Session.Snapshot, typeof Session.Error, never, never>>;
|
|
43
|
+
export {};
|
|
44
|
+
//# sourceMappingURL=ClusterSessions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ClusterSessions.d.ts","sourceRoot":"","sources":["../../src/internal/ClusterSessions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,KAAK,QAAQ,MAAM,iBAAiB,CAAA;AAChD,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AACrC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,KAAK,KAAK,MAAM,cAAc,CAAA;AAE1C,OAAO,KAAK,MAAM,MAAM,gCAAgC,CAAA;AAExD,OAAO,KAAK,KAAK,QAAQ,MAAM,kCAAkC,CAAA;AAEjE,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AAGzC,OAAO,KAAK,OAAO,MAAM,cAAc,CAAA;AAEvC,MAAM,WAAW,OAAQ,SAAQ,OAAO,CAAC,MAAM;IAC7C,2DAA2D;IAC3D,QAAQ,CAAC,sBAAsB,CAAC,EAAE,QAAQ,CAAC,KAAK,CAAA;IAChD,QAAQ,CAAC,iBAAiB,CAAC,EAAE,QAAQ,CAAC,KAAK,CAAA;IAC3C,mGAAmG;IACnG,QAAQ,CAAC,eAAe,CAAC,EAAE,MAAM,GAAG,WAAW,CAAA;CAChD;AAED,KAAK,WAAW,CAAC,CAAC,IAAI,CACpB,OAAO,EAAE,OAAO,CAAC,WAAW,KACzB,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,OAAO,EAAE,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC,KAAK,GAAG,CAAC,CAAC,CAAA;AAqBnE,kFAAkF;AAClF,eAAO,MAAM,eAAe,GAAI,CAAC,WACtB,OAAO,eACH,WAAW,CAAC,CAAC,CAAC,KAC1B,KAAK,CAAC,KAAK,CAAC,KAAK,EAAE,KAAK,EAAE,QAAQ,CAAC,QAAQ,GAAG,CAAC,CAkCjD,CAAA;AAED,yDAAyD;AACzD,eAAO,MAAM,WAAW,YAAa,OAAO,sOAAsC,CAAA;AAElF,kFAAkF;AAClF,eAAO,MAAM,iBAAiB,YAAa,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,mPACS,CAAA;AAExE,6EAA6E;AAC7E,eAAO,MAAM,WAAW,EAAE,KAAK,CAAC,KAAK,CAAC,QAAQ,EAAE,KAAK,EAAE,QAAQ,CAAC,QAAQ,CA4BvE,CAAA;AAED,eAAO,MAAM,MAAM;;;;;;;;;;;;;;;mMAAkB,CAAA"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import * as Config from "effect/Config";
|
|
2
|
+
import * as Effect from "effect/Effect";
|
|
3
|
+
import * as Layer from "effect/Layer";
|
|
4
|
+
import * as Schema from "effect/Schema";
|
|
5
|
+
import * as Stream from "effect/Stream";
|
|
6
|
+
import * as Entity from "effect/unstable/cluster/Entity";
|
|
7
|
+
import * as EntityResource from "effect/unstable/cluster/EntityResource";
|
|
8
|
+
import { Sessions } from "../Sessions.js";
|
|
9
|
+
import * as Pi from "./Pi.js";
|
|
10
|
+
import * as Protocol from "./Protocol.js";
|
|
11
|
+
import * as Session from "./Session.js";
|
|
12
|
+
const failureMessage = (cause) => {
|
|
13
|
+
if (typeof cause === "object" && cause !== null && "message" in cause) {
|
|
14
|
+
return String(cause.message);
|
|
15
|
+
}
|
|
16
|
+
return String(cause);
|
|
17
|
+
};
|
|
18
|
+
const transportError = (id, operation, cause) => cause instanceof Session.Error
|
|
19
|
+
? cause
|
|
20
|
+
: new Session.Error({
|
|
21
|
+
sessionId: id,
|
|
22
|
+
operation,
|
|
23
|
+
message: failureMessage(cause)
|
|
24
|
+
});
|
|
25
|
+
/** Internal constructor seam used to test entity behavior without model calls. */
|
|
26
|
+
export const runnerLayerWith = (options, makeSession) => {
|
|
27
|
+
const handlers = Effect.gen(function* () {
|
|
28
|
+
const address = yield* Entity.CurrentAddress;
|
|
29
|
+
const id = yield* Schema.decodeUnknownEffect(Session.Id)(address.entityId).pipe(Effect.orDie);
|
|
30
|
+
const resource = yield* EntityResource.make({
|
|
31
|
+
acquire: makeSession({
|
|
32
|
+
id,
|
|
33
|
+
cwd: options.cwd,
|
|
34
|
+
...(options.keyPrefix === undefined ? {} : { keyPrefix: options.keyPrefix }),
|
|
35
|
+
...(options.configure === undefined ? {} : { configure: options.configure })
|
|
36
|
+
}),
|
|
37
|
+
idleTimeToLive: options.resourceIdleTimeToLive ?? "15 minutes"
|
|
38
|
+
}).pipe(Effect.orDie);
|
|
39
|
+
return Protocol.entity.of({
|
|
40
|
+
Snapshot: () => resource.get.pipe(Effect.flatMap((session) => session.snapshot)),
|
|
41
|
+
Prompt: (request) => resource.get.pipe(Effect.flatMap((session) => session.prompt(request.payload.text))),
|
|
42
|
+
Abort: () => resource.get.pipe(Effect.flatMap((session) => session.abort)),
|
|
43
|
+
Jsonl: () => resource.get.pipe(Effect.flatMap((session) => session.jsonl)),
|
|
44
|
+
Events: () => Stream.unwrap(resource.get.pipe(Effect.map((session) => session.events)))
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
return Protocol.entity.toLayer(handlers, {
|
|
48
|
+
concurrency: "unbounded",
|
|
49
|
+
mailboxCapacity: options.mailboxCapacity ?? 128,
|
|
50
|
+
maxIdleTime: options.entityMaxIdleTime ?? "20 minutes"
|
|
51
|
+
});
|
|
52
|
+
};
|
|
53
|
+
/** Registers the server-side cluster entity handlers. */
|
|
54
|
+
export const runnerLayer = (options) => runnerLayerWith(options, Pi.make);
|
|
55
|
+
/** Resolve runner options using the active ConfigProvider at layer build time. */
|
|
56
|
+
export const runnerLayerConfig = (options) => Layer.unwrap(Effect.map(Config.unwrap(options), runnerLayer));
|
|
57
|
+
/** Implements Sessions using location-transparent Effect Cluster clients. */
|
|
58
|
+
export const clientLayer = Layer.effect(Sessions, Protocol.entity.client.pipe(Effect.map((makeClient) => Sessions.of({
|
|
59
|
+
open: (id) => Effect.succeed((() => {
|
|
60
|
+
const client = makeClient(id);
|
|
61
|
+
return {
|
|
62
|
+
id,
|
|
63
|
+
snapshot: client.Snapshot().pipe(Effect.mapError((cause) => transportError(id, "snapshot", cause))),
|
|
64
|
+
prompt: (text) => Schema.decodeUnknownEffect(Schema.NonEmptyString)(text).pipe(Effect.flatMap((text) => client.Prompt({ text })), Effect.mapError((cause) => transportError(id, "prompt", cause))),
|
|
65
|
+
abort: client.Abort().pipe(Effect.mapError((cause) => transportError(id, "abort", cause))),
|
|
66
|
+
events: client.Events().pipe(Stream.mapError((cause) => transportError(id, "events", cause))),
|
|
67
|
+
jsonl: client.Jsonl().pipe(Effect.mapError((cause) => transportError(id, "jsonl", cause)))
|
|
68
|
+
};
|
|
69
|
+
})())
|
|
70
|
+
}))));
|
|
71
|
+
export const entity = Protocol.entity;
|
|
72
|
+
//# sourceMappingURL=ClusterSessions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+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QAAQ,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,cAAc,CAAC,EAAE,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC,CAC/D;SACwB,CAAA;IAC7B,CAAC,CAAC,EAAE,CAAC;CACN,CAAC,CAAC,CACJ,CACF,CAAA;AAED,MAAM,CAAC,MAAM,MAAM,GAAG,QAAQ,CAAC,MAAM,CAAA"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import * as Config from "effect/Config";
|
|
2
|
+
import type * as Duration from "effect/Duration";
|
|
3
|
+
import * as Effect from "effect/Effect";
|
|
4
|
+
import * as Layer from "effect/Layer";
|
|
5
|
+
import type * as Scope from "effect/Scope";
|
|
6
|
+
import { Sessions } from "../Sessions.js";
|
|
7
|
+
import type * as Session from "./Session.js";
|
|
8
|
+
export interface Options extends Session.Config {
|
|
9
|
+
/** How long an unreferenced live Pi session remains resident. */
|
|
10
|
+
readonly idleTimeToLive?: Duration.Input;
|
|
11
|
+
}
|
|
12
|
+
type MakeSession<R> = (options: Session.MakeOptions) => Effect.Effect<Session.Session, Session.Error, Scope.Scope | R>;
|
|
13
|
+
/** Internal constructor seam used to verify pool behavior without model calls. */
|
|
14
|
+
export declare const layerWith: <R>(options: Options, makeSession: MakeSession<R>) => Layer.Layer<Sessions, never, R>;
|
|
15
|
+
export declare const layer: (options: Options) => Layer.Layer<Sessions, never, import("effect/FileSystem").FileSystem | import("effect/unstable/persistence/KeyValueStore").KeyValueStore | import("./ModelRuntime.js").ModelRuntime | import("effect/Path").Path>;
|
|
16
|
+
/** Resolve pool options using the active ConfigProvider at layer build time. */
|
|
17
|
+
export declare const layerConfig: (options: Config.Wrap<Options>) => Layer.Layer<Sessions, Config.ConfigError, import("effect/FileSystem").FileSystem | import("effect/unstable/persistence/KeyValueStore").KeyValueStore | import("./ModelRuntime.js").ModelRuntime | import("effect/Path").Path>;
|
|
18
|
+
export {};
|
|
19
|
+
//# sourceMappingURL=LocalSessions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LocalSessions.d.ts","sourceRoot":"","sources":["../../src/internal/LocalSessions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,KAAK,QAAQ,MAAM,iBAAiB,CAAA;AAChD,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AAErC,OAAO,KAAK,KAAK,KAAK,MAAM,cAAc,CAAA;AAE1C,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AAEzC,OAAO,KAAK,KAAK,OAAO,MAAM,cAAc,CAAA;AAE5C,MAAM,WAAW,OAAQ,SAAQ,OAAO,CAAC,MAAM;IAC7C,iEAAiE;IACjE,QAAQ,CAAC,cAAc,CAAC,EAAE,QAAQ,CAAC,KAAK,CAAA;CACzC;AAED,KAAK,WAAW,CAAC,CAAC,IAAI,CACpB,OAAO,EAAE,OAAO,CAAC,WAAW,KACzB,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,OAAO,EAAE,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC,KAAK,GAAG,CAAC,CAAC,CAAA;AAEnE,kFAAkF;AAClF,eAAO,MAAM,SAAS,GAAI,CAAC,WAChB,OAAO,eACH,WAAW,CAAC,CAAC,CAAC,KAC1B,KAAK,CAAC,KAAK,CAAC,QAAQ,EAAE,KAAK,EAAE,CAAC,CAc9B,CAAA;AAEH,eAAO,MAAM,KAAK,YAAa,OAAO,qNAAgC,CAAA;AAEtE,gFAAgF;AAChF,eAAO,MAAM,WAAW,YAAa,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,kOACS,CAAA"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import * as Config from "effect/Config";
|
|
2
|
+
import * as Effect from "effect/Effect";
|
|
3
|
+
import * as Layer from "effect/Layer";
|
|
4
|
+
import * as RcMap from "effect/RcMap";
|
|
5
|
+
import { Sessions } from "../Sessions.js";
|
|
6
|
+
import * as Pi from "./Pi.js";
|
|
7
|
+
/** Internal constructor seam used to verify pool behavior without model calls. */
|
|
8
|
+
export const layerWith = (options, makeSession) => Layer.effect(Sessions, Effect.gen(function* () {
|
|
9
|
+
const sessions = yield* RcMap.make({
|
|
10
|
+
lookup: (id) => makeSession({
|
|
11
|
+
id,
|
|
12
|
+
cwd: options.cwd,
|
|
13
|
+
...(options.keyPrefix === undefined ? {} : { keyPrefix: options.keyPrefix }),
|
|
14
|
+
...(options.configure === undefined ? {} : { configure: options.configure })
|
|
15
|
+
}),
|
|
16
|
+
idleTimeToLive: options.idleTimeToLive ?? "15 minutes"
|
|
17
|
+
});
|
|
18
|
+
return Sessions.of({
|
|
19
|
+
open: (id) => RcMap.get(sessions, id)
|
|
20
|
+
});
|
|
21
|
+
}));
|
|
22
|
+
export const layer = (options) => layerWith(options, Pi.make);
|
|
23
|
+
/** Resolve pool options using the active ConfigProvider at layer build time. */
|
|
24
|
+
export const layerConfig = (options) => Layer.unwrap(Effect.map(Config.unwrap(options), layer));
|
|
25
|
+
//# sourceMappingURL=LocalSessions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LocalSessions.js","sourceRoot":"","sources":["../../src/internal/LocalSessions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAEvC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AACrC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AAGrC,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AACzC,OAAO,KAAK,EAAE,MAAM,SAAS,CAAA;AAY7B,kFAAkF;AAClF,MAAM,CAAC,MAAM,SAAS,GAAG,CACvB,OAAgB,EAChB,WAA2B,EACM,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,QAAQ,EAAE,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;IAC/E,MAAM,QAAQ,GAAG,KAAK,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC;QACjC,MAAM,EAAE,CAAC,EAAc,EAAE,EAAE,CAAC,WAAW,CAAC;YACtC,EAAE;YACF,GAAG,EAAE,OAAO,CAAC,GAAG;YAChB,GAAG,CAAC,OAAO,CAAC,SAAS,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,OAAO,CAAC,SAAS,EAAE,CAAC;YAC5E,GAAG,CAAC,OAAO,CAAC,SAAS,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,OAAO,CAAC,SAAS,EAAE,CAAC;SAC7E,CAAC;QACF,cAAc,EAAE,OAAO,CAAC,cAAc,IAAI,YAAY;KACvD,CAAC,CAAA;IAEF,OAAO,QAAQ,CAAC,EAAE,CAAC;QACjB,IAAI,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,QAAQ,EAAE,EAAE,CAAC;KACtC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAC,CAAA;AAEH,MAAM,CAAC,MAAM,KAAK,GAAG,CAAC,OAAgB,EAAE,EAAE,CAAC,SAAS,CAAC,OAAO,EAAE,EAAE,CAAC,IAAI,CAAC,CAAA;AAEtE,gFAAgF;AAChF,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,OAA6B,EAAE,EAAE,CAC3D,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,MAAM,CAAU,OAAO,CAAC,EAAE,KAAK,CAAC,CAAC,CAAA"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import * as Pi from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import * as Config from "effect/Config";
|
|
3
|
+
import * as Context from "effect/Context";
|
|
4
|
+
import * as Effect from "effect/Effect";
|
|
5
|
+
import * as Layer from "effect/Layer";
|
|
6
|
+
import * as Redacted from "effect/Redacted";
|
|
7
|
+
import * as Schema from "effect/Schema";
|
|
8
|
+
import type * as Scope from "effect/Scope";
|
|
9
|
+
import * as ResourceLoader from "./ResourceLoader.js";
|
|
10
|
+
export interface Options extends Omit<Pi.CreateModelRuntimeOptions, "signal"> {
|
|
11
|
+
/** Omit to let Pi restore/select the model using the session and settings. */
|
|
12
|
+
readonly model?: {
|
|
13
|
+
readonly provider: string;
|
|
14
|
+
readonly id: string;
|
|
15
|
+
};
|
|
16
|
+
/** Runtime-only overrides. Keys are never persisted to auth.json. */
|
|
17
|
+
readonly apiKeys?: Readonly<Record<string, Redacted.Redacted<string>>>;
|
|
18
|
+
}
|
|
19
|
+
declare const Error_base: Schema.Class<Error, Schema.TaggedStruct<"ModelRuntimeError", {
|
|
20
|
+
readonly operation: Schema.Literals<readonly ["create", "providers", "credentials", "model"]>;
|
|
21
|
+
readonly message: Schema.String;
|
|
22
|
+
}>, import("effect/Cause").YieldableError>;
|
|
23
|
+
export declare class Error extends Error_base {
|
|
24
|
+
}
|
|
25
|
+
/** SDK interoperability values; never share one binding between live sessions. */
|
|
26
|
+
export interface Binding extends ResourceLoader.Loaded {
|
|
27
|
+
readonly modelRuntime: Pi.ModelRuntime;
|
|
28
|
+
readonly model?: NonNullable<Pi.CreateAgentSessionOptions["model"]>;
|
|
29
|
+
}
|
|
30
|
+
export interface Operations {
|
|
31
|
+
readonly sessionOptions: (cwd: string) => Effect.Effect<Binding, Error | ResourceLoader.Error, Scope.Scope>;
|
|
32
|
+
}
|
|
33
|
+
declare const ModelRuntime_base: Context.ServiceClass<ModelRuntime, "@jpowersdev/effect-pi/ModelRuntime", Operations>;
|
|
34
|
+
export declare class ModelRuntime extends ModelRuntime_base {
|
|
35
|
+
}
|
|
36
|
+
/** Capture the loading policy; SDK objects are owned by each live session's scope. */
|
|
37
|
+
export declare const make: (options?: Options | undefined) => Effect.Effect<Operations, never, ResourceLoader.ResourceLoader>;
|
|
38
|
+
export declare const layer: (options?: Options) => Layer.Layer<ModelRuntime, never, ResourceLoader.ResourceLoader>;
|
|
39
|
+
/** Resolve configuration when the layer is built, using the active ConfigProvider. */
|
|
40
|
+
export declare const layerConfig: (options: Config.Wrap<Options>) => Layer.Layer<ModelRuntime, Config.ConfigError, ResourceLoader.ResourceLoader>;
|
|
41
|
+
export {};
|
|
42
|
+
//# sourceMappingURL=ModelRuntime.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ModelRuntime.d.ts","sourceRoot":"","sources":["../../src/internal/ModelRuntime.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,iCAAiC,CAAA;AACrD,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAA;AACzC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AACrC,OAAO,KAAK,QAAQ,MAAM,iBAAiB,CAAA;AAC3C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,KAAK,KAAK,MAAM,cAAc,CAAA;AAE1C,OAAO,KAAK,cAAc,MAAM,qBAAqB,CAAA;AAErD,MAAM,WAAW,OAAQ,SAAQ,IAAI,CAAC,EAAE,CAAC,yBAAyB,EAAE,QAAQ,CAAC;IAC3E,8EAA8E;IAC9E,QAAQ,CAAC,KAAK,CAAC,EAAE;QAAE,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAA;KAAE,CAAA;IAEnE,qEAAqE;IACrE,QAAQ,CAAC,OAAO,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAA;CACvE;;;;;AAED,qBAAa,KAAM,SAAQ,UAGzB;CAAG;AAEL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