thoughtgear 0.1.1 → 0.1.2
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 +65 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -116,8 +116,8 @@ Notes:
|
|
|
116
116
|
|
|
117
117
|
- The `sessionId` is just a string you choose (e.g. a user ID, a chat thread ID, a UUID).
|
|
118
118
|
- Without `sessionId`, each `handlePrompt` is isolated — the model only sees that single prompt and the loop's own tool calls.
|
|
119
|
-
- Session history is loaded via `orm.getSessionHistory(sessionId)`. The in-memory
|
|
120
|
-
- Resume a session in a different process by passing the same `sessionId` and pointing at the same persistent DB (e.g. `db: { type: "
|
|
119
|
+
- Session history is loaded via `orm.getSessionHistory(sessionId)`. The in-memory, files, and S3 adapters fully implement this; the Mongo / SQL adapters are stubs (one-liner query you fill in).
|
|
120
|
+
- Resume a session in a different process by passing the same `sessionId` and pointing at the same persistent DB (e.g. `db: { type: "files", path: "./.thoughtgear" }` or `db: { type: "s3", bucket: "my-bucket" }`).
|
|
121
121
|
|
|
122
122
|
## Streaming callbacks
|
|
123
123
|
|
|
@@ -134,7 +134,7 @@ callbacks: {
|
|
|
134
134
|
|
|
135
135
|
## Persistence: `orm` or `db`
|
|
136
136
|
|
|
137
|
-
`PromptHandler` accepts **either** a pre-built `orm` **or** raw `db` settings. The `db` form is just a shortcut — internally the handler constructs an `ORM` from your `DbConfig` and picks the right adapter (`memory` / `mongodb` / `sql`).
|
|
137
|
+
`PromptHandler` accepts **either** a pre-built `orm` **or** raw `db` settings. The `db` form is just a shortcut — internally the handler constructs an `ORM` from your `DbConfig` and picks the right adapter (`memory` / `files` / `s3` / `mongodb` / `sql`).
|
|
138
138
|
|
|
139
139
|
### Shortcut: pass `db` settings
|
|
140
140
|
|
|
@@ -153,10 +153,69 @@ Other supported `db` shapes:
|
|
|
153
153
|
|
|
154
154
|
```ts
|
|
155
155
|
db: { type: "memory" }
|
|
156
|
+
db: { type: "files", path: "./.thoughtgear" }
|
|
157
|
+
db: { type: "s3", bucket: "my-bucket", path: "thoughtgear/prod", region: "us-east-1" }
|
|
156
158
|
db: { type: "mongodb", uri: "...", database: "..." }
|
|
157
159
|
db: { type: "sql", dialect: "postgres", uri: "..." }
|
|
158
160
|
```
|
|
159
161
|
|
|
162
|
+
### Files adapter (`type: "files"`)
|
|
163
|
+
|
|
164
|
+
Zero-dependency, on-disk JSON persistence — ideal for local development, CLIs, and single-process apps that don't want to stand up a database. Pass a directory and the adapter writes:
|
|
165
|
+
|
|
166
|
+
```
|
|
167
|
+
{path}/
|
|
168
|
+
sessions/{sessionId}.json # all messages + run states for the session
|
|
169
|
+
runs/{runId}.json # for runs without a sessionId
|
|
170
|
+
cache.json
|
|
171
|
+
memory.json
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
```ts
|
|
175
|
+
const handler = new PromptHandler({
|
|
176
|
+
sessionId: "user-42",
|
|
177
|
+
context: "You are a helpful assistant.",
|
|
178
|
+
tools: [],
|
|
179
|
+
model: { name: "gpt-4o-mini", provider: "openai", apiKey: process.env.OPENAI_API_KEY! },
|
|
180
|
+
db: { type: "files", path: "./.thoughtgear" },
|
|
181
|
+
});
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
Writes are atomic (write-temp-then-rename) but there is no cross-process locking — concurrent writers to the same session file can race. That's fine for single-process use; reach for `s3` / `mongodb` if you need a multi-writer story.
|
|
185
|
+
|
|
186
|
+
### S3 adapter (`type: "s3"`)
|
|
187
|
+
|
|
188
|
+
Same layout as the files adapter, but keys live in an S3 bucket under an optional prefix:
|
|
189
|
+
|
|
190
|
+
```
|
|
191
|
+
{bucket}/{path}/
|
|
192
|
+
sessions/{sessionId}.json
|
|
193
|
+
runs/{runId}.json
|
|
194
|
+
cache.json
|
|
195
|
+
memory.json
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
```ts
|
|
199
|
+
const handler = new PromptHandler({
|
|
200
|
+
sessionId: "user-42",
|
|
201
|
+
context: "You are a helpful assistant.",
|
|
202
|
+
tools: [],
|
|
203
|
+
model: { name: "gpt-4o-mini", provider: "openai", apiKey: process.env.OPENAI_API_KEY! },
|
|
204
|
+
db: {
|
|
205
|
+
type: "s3",
|
|
206
|
+
bucket: "my-bucket",
|
|
207
|
+
path: "thoughtgear/prod", // optional key prefix
|
|
208
|
+
region: "us-east-1", // optional — falls back to AWS_REGION env
|
|
209
|
+
credentials: { // optional — omit to use the default credential chain
|
|
210
|
+
accessKeyId: process.env.AWS_ACCESS_KEY_ID!,
|
|
211
|
+
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY!,
|
|
212
|
+
},
|
|
213
|
+
},
|
|
214
|
+
});
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
`region` and `credentials` are both optional. When omitted, the AWS SDK's default credential chain (env vars, shared config file, IAM role) is used — typical for apps running on EC2 / ECS / Lambda. Same race caveat as the files adapter applies (S3 has no atomic compare-and-swap).
|
|
218
|
+
|
|
160
219
|
### Bring your own ORM
|
|
161
220
|
|
|
162
221
|
Use this when you want to share one ORM across multiple handlers, or you need to read the transcript back yourself:
|
|
@@ -184,7 +243,9 @@ const history = await orm.getHistory(runId);
|
|
|
184
243
|
const state = await orm.getRunState(runId);
|
|
185
244
|
```
|
|
186
245
|
|
|
187
|
-
|
|
246
|
+
Adapter status:
|
|
247
|
+
- `memory`, `files`, `s3` — fully implemented.
|
|
248
|
+
- `mongodb`, `sql` — stubbed in `src/classes/PromptHandler.ts`; fill in the eight `OrmAdapter` methods using the `mongodb` / `pg` / `kysely` drivers to make them live. Mongo collections used: `messages`, `run_states`, `cache`, `memory`.
|
|
188
249
|
|
|
189
250
|
## Switching providers
|
|
190
251
|
|
package/package.json
CHANGED