@pylonsync/functions 0.4.20 → 0.4.22

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/dist/types.d.ts CHANGED
@@ -134,11 +134,15 @@ export interface DbReader {
134
134
  * hits come back best-first with the full row on `doc` (vector
135
135
  * fields stripped — re-fetch by id if you need the embedding).
136
136
  *
137
+ * Available wherever `ctx.db` is — queries and mutations. Actions
138
+ * have no `ctx.db`: embed there, then `ctx.runQuery` a query that
139
+ * searches with the vector.
140
+ *
137
141
  * ```ts
138
- * const [embedding] = await ctx.llm.embed(["how do I reset my password?"]);
142
+ * // In a query: the vector arrives as an arg (an action embedded it).
139
143
  * const { hits } = await ctx.db.vectorSearch("Doc", {
140
144
  * field: "embedding",
141
- * vector: embedding,
145
+ * vector,
142
146
  * limit: 5,
143
147
  * filter: { status: "published" }, // equality / IN pre-filter
144
148
  * });
@@ -251,10 +255,20 @@ export interface DbWriter extends DbReader {
251
255
  */
252
256
  advisoryLock(key: string): Promise<void>;
253
257
  }
258
+ /**
259
+ * Progressive output to the calling client (SSE). Every fn stream is
260
+ * RESUMABLE: the host buffers each chunk under a server-assigned
261
+ * stream id (the `X-Pylon-Stream-Id` response header) with a
262
+ * monotonically increasing sequence, so a client that loses its
263
+ * connection reconnects to `GET /api/fn-streams/<id>` from its last
264
+ * cursor and misses nothing — including the terminal result after the
265
+ * handler already returned. The handler never blocks on (or notices)
266
+ * client disconnects; it just keeps writing.
267
+ */
254
268
  export interface Stream {
255
269
  /** Write a text chunk to the client (SSE). */
256
270
  write(data: string): void;
257
- /** Write a typed SSE event. */
271
+ /** Write a typed SSE event (`event: <name>` framing on the wire). */
258
272
  writeEvent(event: string, data: string): void;
259
273
  }
260
274
  export interface Scheduler {
@@ -391,11 +405,12 @@ export interface Llm {
391
405
  * Batch-embed texts via the configured embeddings provider. One
392
406
  * embedding per input, in input order. Pair with a
393
407
  * `field.vector(dims)` field and `ctx.db.vectorSearch` for
394
- * retrieval:
408
+ * retrieval. From an action (which has no `ctx.db`), store via a
409
+ * mutation:
395
410
  *
396
411
  * ```ts
397
412
  * const [vec] = await ctx.llm.embed([doc.body]);
398
- * await ctx.db.update("Doc", doc.id, { embedding: vec });
413
+ * await ctx.runMutation("saveEmbedding", { docId: doc.id, embedding: vec });
399
414
  * ```
400
415
  *
401
416
  * The embeddings provider is a separate axis from chat: with
@@ -447,11 +462,16 @@ export type LlmStreamEvent = {
447
462
  * `useRoom(roomId, userId)`, and the same delivery path a member's
448
463
  * `broadcast()` uses.
449
464
  *
450
- * This is the surface for streaming agent output that must survive a
451
- * closed tab or reach a second device: write tokens to the room, and
452
- * every watcher gets them, not just the caller holding the HTTP
453
- * response. `ctx.stream.write` reaches only the one client that made
454
- * the call.
465
+ * This is the surface for fanning agent output out to a second device
466
+ * or a second tab that is CONNECTED RIGHT NOW: write tokens to the
467
+ * room and every current watcher gets them, not just the caller
468
+ * holding the HTTP response. Delivery is live-only — a subscriber that
469
+ * reconnects does NOT replay messages sent during its gap. For output
470
+ * that must survive a closed tab or a dropped connection, rely on the
471
+ * fn stream itself: every `ctx.stream` stream is buffered server-side
472
+ * and resumable by stream id (`streamFn`'s `onStreamId` +
473
+ * `resumeStream` in the clients), including the final result after the
474
+ * handler finished.
455
475
  *
456
476
  * Not available in queries — a reactive handler re-runs on every dep
457
477
  * change, which would re-broadcast each time.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pylonsync/functions",
3
- "version": "0.4.20",
3
+ "version": "0.4.22",
4
4
  "description": "TypeScript function runtime for pylon — defines server-side queries, mutations, and actions.",
5
5
  "type": "module",
6
6
  "main": "src/index.ts",
package/src/types.ts CHANGED
@@ -162,11 +162,15 @@ export interface DbReader {
162
162
  * hits come back best-first with the full row on `doc` (vector
163
163
  * fields stripped — re-fetch by id if you need the embedding).
164
164
  *
165
+ * Available wherever `ctx.db` is — queries and mutations. Actions
166
+ * have no `ctx.db`: embed there, then `ctx.runQuery` a query that
167
+ * searches with the vector.
168
+ *
165
169
  * ```ts
166
- * const [embedding] = await ctx.llm.embed(["how do I reset my password?"]);
170
+ * // In a query: the vector arrives as an arg (an action embedded it).
167
171
  * const { hits } = await ctx.db.vectorSearch("Doc", {
168
172
  * field: "embedding",
169
- * vector: embedding,
173
+ * vector,
170
174
  * limit: 5,
171
175
  * filter: { status: "published" }, // equality / IN pre-filter
172
176
  * });
@@ -308,11 +312,21 @@ export interface DbWriter extends DbReader {
308
312
  // Streaming
309
313
  // ---------------------------------------------------------------------------
310
314
 
315
+ /**
316
+ * Progressive output to the calling client (SSE). Every fn stream is
317
+ * RESUMABLE: the host buffers each chunk under a server-assigned
318
+ * stream id (the `X-Pylon-Stream-Id` response header) with a
319
+ * monotonically increasing sequence, so a client that loses its
320
+ * connection reconnects to `GET /api/fn-streams/<id>` from its last
321
+ * cursor and misses nothing — including the terminal result after the
322
+ * handler already returned. The handler never blocks on (or notices)
323
+ * client disconnects; it just keeps writing.
324
+ */
311
325
  export interface Stream {
312
326
  /** Write a text chunk to the client (SSE). */
313
327
  write(data: string): void;
314
328
 
315
- /** Write a typed SSE event. */
329
+ /** Write a typed SSE event (`event: <name>` framing on the wire). */
316
330
  writeEvent(event: string, data: string): void;
317
331
  }
318
332
 
@@ -477,11 +491,12 @@ export interface Llm {
477
491
  * Batch-embed texts via the configured embeddings provider. One
478
492
  * embedding per input, in input order. Pair with a
479
493
  * `field.vector(dims)` field and `ctx.db.vectorSearch` for
480
- * retrieval:
494
+ * retrieval. From an action (which has no `ctx.db`), store via a
495
+ * mutation:
481
496
  *
482
497
  * ```ts
483
498
  * const [vec] = await ctx.llm.embed([doc.body]);
484
- * await ctx.db.update("Doc", doc.id, { embedding: vec });
499
+ * await ctx.runMutation("saveEmbedding", { docId: doc.id, embedding: vec });
485
500
  * ```
486
501
  *
487
502
  * The embeddings provider is a separate axis from chat: with
@@ -524,11 +539,16 @@ export type LlmStreamEvent =
524
539
  * `useRoom(roomId, userId)`, and the same delivery path a member's
525
540
  * `broadcast()` uses.
526
541
  *
527
- * This is the surface for streaming agent output that must survive a
528
- * closed tab or reach a second device: write tokens to the room, and
529
- * every watcher gets them, not just the caller holding the HTTP
530
- * response. `ctx.stream.write` reaches only the one client that made
531
- * the call.
542
+ * This is the surface for fanning agent output out to a second device
543
+ * or a second tab that is CONNECTED RIGHT NOW: write tokens to the
544
+ * room and every current watcher gets them, not just the caller
545
+ * holding the HTTP response. Delivery is live-only — a subscriber that
546
+ * reconnects does NOT replay messages sent during its gap. For output
547
+ * that must survive a closed tab or a dropped connection, rely on the
548
+ * fn stream itself: every `ctx.stream` stream is buffered server-side
549
+ * and resumable by stream id (`streamFn`'s `onStreamId` +
550
+ * `resumeStream` in the clients), including the final result after the
551
+ * handler finished.
532
552
  *
533
553
  * Not available in queries — a reactive handler re-runs on every dep
534
554
  * change, which would re-broadcast each time.