@unieai/rabi-spill 0.2.1-rc.3 → 0.2.2-rc.5

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@unieai/rabi-spill",
3
3
  "description": "Abstract spill storage seam (ctx.spillStore) for the Rabi Harness — save oversized tool text and return a retrieval locator",
4
- "version": "0.2.1-rc.3",
4
+ "version": "0.2.2-rc.5",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
@@ -19,13 +19,16 @@
19
19
  "files": [
20
20
  "lib/index.js",
21
21
  "lib/types/**/*.d.ts",
22
+ "lib/types/**/*.d.ts.map",
23
+ "lib/**/*.js.map",
24
+ "src",
22
25
  "README.md"
23
26
  ],
24
27
  "license": "MIT",
25
28
  "peerDependencies": {
26
- "@unieai/rabi-brand": "0.2.1-rc.3",
27
- "@unieai/rabi-llm": "0.2.1-rc.3",
28
- "@unieai/rabi-session": "0.2.1-rc.3",
29
- "@unieai/cordis": "4.0.5"
29
+ "@unieai/rabi-brand": "0.2.2-rc.5",
30
+ "@unieai/rabi-llm": "0.2.2-rc.5",
31
+ "@unieai/rabi-session": "0.2.2-rc.5",
32
+ "@unieai/cordis": "4.1.0"
30
33
  }
31
34
  }
package/src/index.ts ADDED
@@ -0,0 +1,58 @@
1
+ /**
2
+ * Service Definition for the spill storage capability seam (`ctx.spillStore`): an abstract service defining WHAT a
3
+ * spill backend does — persist oversized text and return a model-facing
4
+ * locator plus retrieval guidance — without saying HOW. Implementations
5
+ * subclass {@link SpillStore} and register as the `spillStore` service;
6
+ * `@unieai/rabi-spill-local` (host filesystem) is the first.
7
+ *
8
+ * The Service Definition is deliberately minimal: `saveText` and nothing else. It owns NO
9
+ * retention policy (that is `@unieai/rabi-output-retention`), NO tool-result
10
+ * replacement (that is `@unieai/rabi-spill-policy`), and NO retrieval or
11
+ * search API. The backend supplies the locator and retrieval hint appropriate
12
+ * for its storage substrate.
13
+ *
14
+ * @module @unieai/rabi-spill
15
+ */
16
+
17
+ import { Context, Service } from '@unieai/cordis'
18
+ import type { SaveTextSpill, SpillRef } from './types.ts'
19
+
20
+ export { SpillLocator } from './types.ts'
21
+ export type { SaveTextSpill, SpillOwner, SpillRef, SpillSource } from './types.ts'
22
+
23
+ declare module '@unieai/cordis' {
24
+ interface Context {
25
+ spillStore: SpillStore
26
+ }
27
+ }
28
+
29
+ /**
30
+ * Abstract spill storage service. Subclass, implement {@link saveText}, and load
31
+ * the subclass as a plugin — it registers as `ctx.spillStore` (one
32
+ * implementation per context; loading a second throws, cordis' standard
33
+ * duplicate-service behavior).
34
+ *
35
+ * Semantics every implementation must honor:
36
+ * - {@link saveText} persists the FULL `content` verbatim and returns an opaque
37
+ * locator, exact byte length, and model-facing retrieval guidance.
38
+ * - Storage is scoped by the request's {@link SaveTextSpill.owner} session; the
39
+ * backend chooses a private (not world-readable) location and a collision-free
40
+ * name derived from — never equal to — the caller's `suggestedName`.
41
+ * - `saveText` REJECTS on a real storage failure (permissions, ENOSPC, backend
42
+ * unavailable); the caller decides how to degrade (the spill policy treats a
43
+ * rejection as best-effort and keeps the inline result).
44
+ */
45
+ export abstract class SpillStore extends Service {
46
+ constructor(ctx: Context) {
47
+ super(ctx, 'spillStore')
48
+ }
49
+
50
+ /**
51
+ * Persist `input.content` to a session-scoped spill artifact.
52
+ * @param input - the owner, caller-supplied source fields, suggested name, and full text to save.
53
+ * @returns the saved artifact's {@link SpillRef}; rejects on a storage failure.
54
+ */
55
+ abstract saveText(input: SaveTextSpill): Promise<SpillRef>
56
+ }
57
+
58
+ export default SpillStore
package/src/types.ts ADDED
@@ -0,0 +1,80 @@
1
+ /**
2
+ * Vocabulary for the spill storage Service Definition. Types only — the abstract service
3
+ * lives in `./index.ts`, implementations in sibling packages
4
+ * (`@unieai/rabi-spill-local` first).
5
+ *
6
+ * @module @unieai/rabi-spill/types
7
+ */
8
+
9
+ import type { Branded } from '@unieai/rabi-brand'
10
+ import type { ToolCallId } from '@unieai/rabi-llm'
11
+ import type { SessionId } from '@unieai/rabi-session'
12
+
13
+ /**
14
+ * Opaque model-facing handle for one spilled artifact. A local backend may use a
15
+ * filesystem path; a remote or database backend may use a URI or key. Consumers
16
+ * render it with {@link SpillRef.retrievalHint}, but do not parse it.
17
+ */
18
+ export type SpillLocator = Branded<'SpillLocator'>
19
+
20
+ /**
21
+ * Brand a string as a {@link SpillLocator}.
22
+ *
23
+ * @param locator The backend-produced locator string to brand.
24
+ * @returns The branded spill locator.
25
+ */
26
+ export function SpillLocator(locator: string): SpillLocator {
27
+ return locator as SpillLocator
28
+ }
29
+
30
+ /**
31
+ * Save-time storage namespace for a spilled artifact. The session id lets a
32
+ * backend group storage under the producing session, but the returned
33
+ * {@link SpillLocator} is the model-facing handle. Forked sessions inherit
34
+ * locators already present in the seeded log; those artifacts are not copied or
35
+ * re-owned, and spills produced after the fork use the child session id.
36
+ */
37
+ export interface SpillOwner {
38
+ sessionId: SessionId
39
+ }
40
+
41
+ /**
42
+ * Producer of a spilled artifact. Tool results carry their model-issued call id;
43
+ * session references identify the captured source session instead. Descriptive
44
+ * source description only, never access control.
45
+ */
46
+ export type SpillSource = {
47
+ kind: 'tool'
48
+ /** The tool whose result was spilled (e.g. `web_fetch`). */
49
+ toolName: string
50
+ /** The model-issued call id the result belongs to. */
51
+ callId: ToolCallId
52
+ /** A short human label for the artifact (e.g. `result`). */
53
+ label: string
54
+ } | {
55
+ kind: 'session-reference'
56
+ /** Session whose projected conversation was captured. */
57
+ sessionId: SessionId
58
+ /** Host-provided label for the referenced session. */
59
+ label: string
60
+ }
61
+
62
+ /** One request to persist text to a spill artifact. */
63
+ export interface SaveTextSpill {
64
+ owner: SpillOwner
65
+ source: SpillSource
66
+ /**
67
+ * A caller-suggested base name (e.g. `web_fetch.txt`). The backend sanitizes
68
+ * it to a single safe path segment before use — it is a hint, never a path.
69
+ */
70
+ suggestedName: string
71
+ /** The full text to persist (UTF-8). */
72
+ content: string
73
+ }
74
+
75
+ /** A saved spill artifact: its locator, byte length, and backend-specific retrieval guidance. */
76
+ export interface SpillRef {
77
+ locator: SpillLocator
78
+ bytes: number
79
+ retrievalHint: string
80
+ }