@lloyal-labs/rig 2.1.0 → 3.0.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.
Files changed (100) hide show
  1. package/LICENSE +107 -0
  2. package/LICENSE-FAQ.md +256 -0
  3. package/README.md +78 -72
  4. package/dist/bundle.d.ts +211 -0
  5. package/dist/bundle.d.ts.map +1 -0
  6. package/dist/bundle.js +296 -0
  7. package/dist/bundle.js.map +1 -0
  8. package/dist/cancellable-fetch.d.ts +98 -0
  9. package/dist/cancellable-fetch.d.ts.map +1 -0
  10. package/dist/cancellable-fetch.js +133 -0
  11. package/dist/cancellable-fetch.js.map +1 -0
  12. package/dist/config-store.d.ts +30 -0
  13. package/dist/config-store.d.ts.map +1 -0
  14. package/dist/config-store.js +45 -0
  15. package/dist/config-store.js.map +1 -0
  16. package/dist/define-app.d.ts +98 -0
  17. package/dist/define-app.d.ts.map +1 -0
  18. package/dist/define-app.js +232 -0
  19. package/dist/define-app.js.map +1 -0
  20. package/dist/grant-store.d.ts +31 -0
  21. package/dist/grant-store.d.ts.map +1 -0
  22. package/dist/grant-store.js +49 -0
  23. package/dist/grant-store.js.map +1 -0
  24. package/dist/index.d.ts +13 -6
  25. package/dist/index.d.ts.map +1 -1
  26. package/dist/index.js +37 -11
  27. package/dist/index.js.map +1 -1
  28. package/dist/node.d.ts +3 -2
  29. package/dist/node.d.ts.map +1 -1
  30. package/dist/node.js +3 -2
  31. package/dist/node.js.map +1 -1
  32. package/dist/protocol.d.ts +155 -0
  33. package/dist/protocol.d.ts.map +1 -0
  34. package/dist/protocol.js +184 -0
  35. package/dist/protocol.js.map +1 -0
  36. package/dist/registry.d.ts +87 -0
  37. package/dist/registry.d.ts.map +1 -0
  38. package/dist/registry.js +245 -0
  39. package/dist/registry.js.map +1 -0
  40. package/dist/reranker.d.ts +25 -7
  41. package/dist/reranker.d.ts.map +1 -1
  42. package/dist/reranker.js +103 -63
  43. package/dist/reranker.js.map +1 -1
  44. package/dist/resources/types.d.ts +10 -37
  45. package/dist/resources/types.d.ts.map +1 -1
  46. package/dist/resources/types.js +12 -0
  47. package/dist/resources/types.js.map +1 -1
  48. package/dist/spine-render.d.ts +97 -0
  49. package/dist/spine-render.d.ts.map +1 -0
  50. package/dist/spine-render.js +121 -0
  51. package/dist/spine-render.js.map +1 -0
  52. package/dist/tools/index.d.ts +26 -22
  53. package/dist/tools/index.d.ts.map +1 -1
  54. package/dist/tools/index.js +24 -28
  55. package/dist/tools/index.js.map +1 -1
  56. package/dist/tools/keyless-search.d.ts +67 -0
  57. package/dist/tools/keyless-search.d.ts.map +1 -0
  58. package/dist/tools/keyless-search.js +401 -0
  59. package/dist/tools/keyless-search.js.map +1 -0
  60. package/dist/tools/plan.d.ts +31 -4
  61. package/dist/tools/plan.d.ts.map +1 -1
  62. package/dist/tools/plan.js +46 -11
  63. package/dist/tools/plan.js.map +1 -1
  64. package/dist/tools/types.d.ts +12 -56
  65. package/dist/tools/types.d.ts.map +1 -1
  66. package/dist/tools/types.js +17 -0
  67. package/dist/tools/types.js.map +1 -1
  68. package/dist/tools/web-search.d.ts +9 -25
  69. package/dist/tools/web-search.d.ts.map +1 -1
  70. package/dist/tools/web-search.js +11 -119
  71. package/dist/tools/web-search.js.map +1 -1
  72. package/package.json +9 -6
  73. package/dist/sources/corpus.d.ts +0 -80
  74. package/dist/sources/corpus.d.ts.map +0 -1
  75. package/dist/sources/corpus.js +0 -100
  76. package/dist/sources/corpus.js.map +0 -1
  77. package/dist/sources/index.d.ts +0 -12
  78. package/dist/sources/index.d.ts.map +0 -1
  79. package/dist/sources/index.js +0 -14
  80. package/dist/sources/index.js.map +0 -1
  81. package/dist/sources/web.d.ts +0 -67
  82. package/dist/sources/web.d.ts.map +0 -1
  83. package/dist/sources/web.js +0 -104
  84. package/dist/sources/web.js.map +0 -1
  85. package/dist/tools/fetch-page.d.ts +0 -48
  86. package/dist/tools/fetch-page.d.ts.map +0 -1
  87. package/dist/tools/fetch-page.js +0 -309
  88. package/dist/tools/fetch-page.js.map +0 -1
  89. package/dist/tools/grep.d.ts +0 -35
  90. package/dist/tools/grep.d.ts.map +0 -1
  91. package/dist/tools/grep.js +0 -84
  92. package/dist/tools/grep.js.map +0 -1
  93. package/dist/tools/read-file.d.ts +0 -74
  94. package/dist/tools/read-file.d.ts.map +0 -1
  95. package/dist/tools/read-file.js +0 -192
  96. package/dist/tools/read-file.js.map +0 -1
  97. package/dist/tools/search.d.ts +0 -34
  98. package/dist/tools/search.d.ts.map +0 -1
  99. package/dist/tools/search.js +0 -101
  100. package/dist/tools/search.js.map +0 -1
@@ -0,0 +1,245 @@
1
+ "use strict";
2
+ /**
3
+ * `createAppRegistry` — harness-wide app registry with a **declarative**
4
+ * app set and structured, **isolated** per-app lifecycle.
5
+ *
6
+ * The harness declares its apps as factories; the registry owns the rest:
7
+ *
8
+ * - `createAppRegistry({ configStore, apps })` runs each factory in its own
9
+ * **detached** Effection scope, seeded with the app-facing framework
10
+ * contexts (`AppConfigStoreCtx`, `RerankerCtx`) so the factory
11
+ * reads config + reranker. The factory body is setup; a `resource()`
12
+ * factory's `ensure(...)` is teardown. The registry tears the scopes
13
+ * down on its own scope exit, reverse register-order, **best-effort** —
14
+ * a throwing teardown is logged but never strands a sibling, and never
15
+ * crashes the harness. The harness does **not** call a per-app register
16
+ * verb at boot.
17
+ * - `registry.enable(factory)` / `registry.disable(name)` handle the
18
+ * genuine dynamic case (mid-session enable/disable). `enable` →
19
+ * `'enabled'`, `disable` → `'disabled'` (matching {@link AppState}).
20
+ * `disable` swallows + logs a throwing teardown, so a mid-session
21
+ * uninstall can't crash the session — possible only because each app
22
+ * owns a detached scope whose teardown errors don't propagate to a
23
+ * parent.
24
+ *
25
+ * There are no install/uninstall/enable/disable hooks on the App. A
26
+ * factory that throws (or whose manifest fails validation) tears down its
27
+ * partial scope and propagates; the app never enters the registry.
28
+ * Per-app independent — one app's failure can't roll back another.
29
+ *
30
+ * @packageDocumentation
31
+ * @category Protocol
32
+ */
33
+ Object.defineProperty(exports, "__esModule", { value: true });
34
+ exports.createAppRegistry = createAppRegistry;
35
+ const effection_1 = require("effection");
36
+ const lloyal_agents_1 = require("@lloyal-labs/lloyal-agents");
37
+ const protocol_1 = require("./protocol");
38
+ /**
39
+ * Create the harness-wide app registry.
40
+ *
41
+ * Sets `AppRegistryCtx` and `AppConfigStoreCtx` in the caller's scope (the
42
+ * `initAgents` pattern), enables each factory in `opts.apps`, and tears
43
+ * every enabled app's scope down on the caller's scope exit (reverse
44
+ * order, best-effort).
45
+ *
46
+ * @example
47
+ * ```ts
48
+ * import { createWebApp } from '@lloyal-labs/web-app';
49
+ * import { createCorpusApp } from '@lloyal-labs/corpus-app';
50
+ * import { createJiraApp } from '@lloyal-labs/jira-app';
51
+ *
52
+ * yield* RerankerCtx.set(reranker); // before, if factories read it
53
+ * const registry = yield* createAppRegistry({
54
+ * configStore,
55
+ * apps: [createWebApp, createCorpusApp, createJiraApp],
56
+ * });
57
+ * // ... pool dispatch ...
58
+ * // registry scope exit tears down every app (factory ensures fire)
59
+ * ```
60
+ */
61
+ function* createAppRegistry(opts) {
62
+ const { configStore, grantStore, apps } = opts;
63
+ const entries = new Map();
64
+ const order = [];
65
+ const registry = {
66
+ byName(name) {
67
+ return entries.get(name)?.app;
68
+ },
69
+ enabled() {
70
+ return order.map((n) => entries.get(n).app).filter(Boolean);
71
+ },
72
+ stateOf(name) {
73
+ return entries.has(name) ? 'enabled' : 'disabled';
74
+ },
75
+ *enable(factory) {
76
+ // Read the app-facing framework contexts to seed into the app's
77
+ // detached scope (factories read config + reranker).
78
+ let reranker;
79
+ try {
80
+ reranker = yield* lloyal_agents_1.RerankerCtx.expect();
81
+ }
82
+ catch {
83
+ reranker = undefined;
84
+ }
85
+ const [scope, destroy] = (0, effection_1.createScope)();
86
+ let added = false;
87
+ try {
88
+ // Run the factory in a DETACHED scope (so its teardown errors stay
89
+ // isolated and swallowable), seeded with the framework contexts.
90
+ // It resolves the App out, then suspends — keeping the App and its
91
+ // ensure() teardown alive until `destroy()`.
92
+ const app = yield* (0, effection_1.call)(() => new Promise((resolve, reject) => {
93
+ scope
94
+ .run(function* () {
95
+ try {
96
+ yield* lloyal_agents_1.AppConfigStoreCtx.set(configStore);
97
+ yield* lloyal_agents_1.AppRegistryCtx.set(registry);
98
+ if (reranker !== undefined)
99
+ yield* lloyal_agents_1.RerankerCtx.set(reranker);
100
+ const constructed = yield* factory();
101
+ resolve(constructed);
102
+ yield* (0, effection_1.suspend)();
103
+ }
104
+ catch (err) {
105
+ reject(err);
106
+ }
107
+ })
108
+ .catch(() => {
109
+ /* halt-after-resolve rejection — expected, ignore */
110
+ });
111
+ }));
112
+ const declared = app.manifest.appProtocolVersion ?? '3.0';
113
+ if (!protocol_1.SUPPORTED_APP_PROTOCOL_VERSIONS.includes(declared)) {
114
+ throw new Error(`App "${app.manifest.name}" declares appProtocolVersion="${declared}", ` +
115
+ `but the framework supports [${protocol_1.SUPPORTED_APP_PROTOCOL_VERSIONS.map((v) => `"${v}"`).join(', ')}]. ` +
116
+ `Upgrade the app or use a framework version that supports this protocol.`);
117
+ }
118
+ const existingConfig = yield* configStore.get(app.manifest.name);
119
+ if (existingConfig !== undefined && app.manifest.configSchema) {
120
+ validateConfigShape(app.manifest.name, existingConfig, app.manifest.configSchema);
121
+ }
122
+ if (entries.has(app.manifest.name)) {
123
+ throw new Error(`App "${app.manifest.name}" is already enabled. ` +
124
+ `Call registry.disable("${app.manifest.name}") first to replace it.`);
125
+ }
126
+ entries.set(app.manifest.name, { app, destroy });
127
+ order.push(app.manifest.name);
128
+ added = true;
129
+ return app;
130
+ }
131
+ finally {
132
+ // Factory threw, validation failed, or the caller was halted before
133
+ // the app entered the registry → tear down its detached scope
134
+ // (best-effort; don't mask the original error).
135
+ if (!added) {
136
+ try {
137
+ yield* (0, effection_1.call)(() => destroy());
138
+ }
139
+ catch {
140
+ /* teardown error on the failure path — original error wins */
141
+ }
142
+ }
143
+ }
144
+ },
145
+ *disable(name) {
146
+ const entry = entries.get(name);
147
+ if (!entry)
148
+ return;
149
+ entries.delete(name);
150
+ const idx = order.indexOf(name);
151
+ if (idx >= 0)
152
+ order.splice(idx, 1);
153
+ try {
154
+ yield* (0, effection_1.call)(() => entry.destroy());
155
+ }
156
+ catch (err) {
157
+ console.error(`[lloyal-rig] teardown for app "${name}" threw during disable — app removed regardless:`, err);
158
+ }
159
+ },
160
+ };
161
+ yield* lloyal_agents_1.AppRegistryCtx.set(registry);
162
+ yield* lloyal_agents_1.AppConfigStoreCtx.set(configStore);
163
+ // Seed the grant store so the agent pool's authGuard can
164
+ // read the session's protected-tool grants. Absent = fail-closed.
165
+ if (grantStore)
166
+ yield* lloyal_agents_1.GrantStoreCtx.set(grantStore);
167
+ // Tear down every still-enabled app on registry scope exit, reverse
168
+ // register-order, best-effort (a throwing teardown is logged, never
169
+ // strands a sibling, never crashes the harness). Registered before the
170
+ // boot set so a mid-boot failure still cleans up the apps that enabled.
171
+ yield* (0, effection_1.ensure)(function* () {
172
+ for (let i = order.length - 1; i >= 0; i--) {
173
+ const name = order[i];
174
+ const entry = entries.get(name);
175
+ if (!entry)
176
+ continue;
177
+ try {
178
+ yield* (0, effection_1.call)(() => entry.destroy());
179
+ }
180
+ catch (err) {
181
+ console.error(`[lloyal-rig] teardown for app "${name}" threw — continuing teardown:`, err);
182
+ }
183
+ }
184
+ entries.clear();
185
+ order.length = 0;
186
+ });
187
+ if (apps) {
188
+ for (const factory of apps) {
189
+ yield* registry.enable(factory);
190
+ }
191
+ }
192
+ return registry;
193
+ }
194
+ // ── Helpers ───────────────────────────────────────────────────────
195
+ /**
196
+ * Minimal structural schema check. Validates that every property in
197
+ * `schema.required` exists on `config` with a type compatible with
198
+ * `schema.properties[name].type`. This is a guardrail — the framework
199
+ * does not ship a full JSON Schema validator. Apps requiring richer
200
+ * validation should run their own check in the factory body.
201
+ */
202
+ function validateConfigShape(appName, config, schema) {
203
+ if (schema.type && schema.type !== 'object') {
204
+ return; // non-object schemas are out of scope for the guardrail
205
+ }
206
+ for (const key of schema.required ?? []) {
207
+ if (!(key in config)) {
208
+ throw new Error(`App "${appName}" stored config is missing required key "${key}" ` +
209
+ `declared in manifest.configSchema. Re-run the app's config flow or clear stale config.`);
210
+ }
211
+ }
212
+ for (const [key, rawPropSchema] of Object.entries(schema.properties ?? {})) {
213
+ if (!(key in config))
214
+ continue;
215
+ const propSchema = rawPropSchema;
216
+ if (!propSchema || typeof propSchema.type !== 'string')
217
+ continue;
218
+ const value = config[key];
219
+ if (!matchesPrimitiveType(value, propSchema.type)) {
220
+ throw new Error(`App "${appName}" stored config key "${key}" has type "${typeof value}" ` +
221
+ `but manifest.configSchema declares "${propSchema.type}". ` +
222
+ `Re-run the app's config flow or clear stale config.`);
223
+ }
224
+ }
225
+ }
226
+ function matchesPrimitiveType(value, declared) {
227
+ switch (declared) {
228
+ case 'string':
229
+ return typeof value === 'string';
230
+ case 'number':
231
+ case 'integer':
232
+ return typeof value === 'number';
233
+ case 'boolean':
234
+ return typeof value === 'boolean';
235
+ case 'array':
236
+ return Array.isArray(value);
237
+ case 'object':
238
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
239
+ case 'null':
240
+ return value === null;
241
+ default:
242
+ return true;
243
+ }
244
+ }
245
+ //# sourceMappingURL=registry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registry.js","sourceRoot":"","sources":["../src/registry.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;;AA+EH,8CAkJC;AA/ND,yCAA+D;AAE/D,8DAKoC;AASpC,yCAA6D;AAsC7D;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,QAAe,CAAC,CAAC,iBAAiB,CAChC,IAA2B;IAE3B,MAAM,EAAE,WAAW,EAAE,UAAU,EAAE,IAAI,EAAE,GAAG,IAAI,CAAC;IAC/C,MAAM,OAAO,GAAG,IAAI,GAAG,EAAyB,CAAC;IACjD,MAAM,KAAK,GAAa,EAA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,QAAQ,EAAE,CAAC;QACjB,KAAK,QAAQ;YACX,OAAO,OAAO,KAAK,KAAK,QAAQ,CAAC;QACnC,KAAK,QAAQ,CAAC;QACd,KAAK,SAAS;YACZ,OAAO,OAAO,KAAK,KAAK,QAAQ,CAAC;QACnC,KAAK,SAAS;YACZ,OAAO,OAAO,KAAK,KAAK,SAAS,CAAC;QACpC,KAAK,OAAO;YACV,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;QAC9B,KAAK,QAAQ;YACX,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;QAC9E,KAAK,MAAM;YACT,OAAO,KAAK,KAAK,IAAI,CAAC;QACxB;YACE,OAAO,IAAI,CAAC;IAChB,CAAC;AACH,CAAC"}
@@ -1,17 +1,35 @@
1
- import type { Reranker } from "./tools/types";
1
+ import type { Operation } from "effection";
2
+ import type { Reranker } from "@lloyal-labs/lloyal-agents";
2
3
  /**
3
- * Create a {@link Reranker} backed by a dedicated reranking model context
4
+ * Create a {@link Reranker} backed by a dedicated reranking model context,
5
+ * as an Effection `resource()`.
4
6
  *
5
7
  * Loads a separate model (typically a cross-encoder) into its own KV cache
6
- * and exposes `score`, `tokenizeChunks`, and `dispose` methods. The returned
7
- * `score` method yields {@link ScoredResult} batches as an async iterable,
8
- * mapping raw indices back to the original {@link Chunk} metadata.
8
+ * and exposes `score`, `scoreBatch`, `tokenizeChunks`, and `dispose`. The
9
+ * returned `score` method yields {@link ScoredResult} batches as an async
10
+ * iterable, mapping raw indices back to the original {@link Chunk} metadata.
11
+ *
12
+ * **Lifecycle.** The reranker owns its underlying `SessionContext` + `Rerank`
13
+ * and disposes them transitively when the yielding scope exits (success,
14
+ * error, or halt). The harness yields it once per process lifecycle and
15
+ * publishes it on `RerankerCtx` so App factories can read it via
16
+ * `RerankerCtx.expect()`. `dispose()` remains on the interface
17
+ * for callers that manage teardown explicitly; it is idempotent so the
18
+ * resource finally and an explicit call don't double-free.
9
19
  *
10
20
  * @param modelPath - Absolute path to the reranking model file (GGUF)
11
21
  * @param opts - Optional context sizing overrides
12
22
  * @param opts.nSeqMax - Maximum parallel scoring sequences (default 8)
13
23
  * @param opts.nCtx - Context window size for the reranker model (default 4096)
14
- * @returns A ready-to-use reranker instance; call `dispose()` when finished
24
+ * @returns An Effection resource yielding a ready-to-use reranker
25
+ *
26
+ * @example
27
+ * ```ts
28
+ * const reranker = yield* createReranker(rerankerPath, { nSeqMax: 8, nCtx: 4096 });
29
+ * yield* RerankerCtx.set(reranker);
30
+ * // ... pool work ...
31
+ * // reranker disposes automatically on scope exit
32
+ * ```
15
33
  *
16
34
  * @category Rig
17
35
  */
@@ -19,5 +37,5 @@ export declare function createReranker(modelPath: string, opts?: {
19
37
  nSeqMax?: number;
20
38
  nCtx?: number;
21
39
  nBatch?: number;
22
- }): Promise<Reranker>;
40
+ }): Operation<Reranker>;
23
41
  //# sourceMappingURL=reranker.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"reranker.d.ts","sourceRoot":"","sources":["../src/reranker.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,QAAQ,EAAgB,MAAM,eAAe,CAAC;AAE5D;;;;;;;;;;;;;;;GAeG;AACH,wBAAsB,cAAc,CAClC,SAAS,EAAE,MAAM,EACjB,IAAI,CAAC,EAAE;IAAE,OAAO,CAAC,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,GAC1D,OAAO,CAAC,QAAQ,CAAC,CAoEnB"}
1
+ {"version":3,"file":"reranker.d.ts","sourceRoot":"","sources":["../src/reranker.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAC3C,OAAO,KAAK,EAAS,QAAQ,EAAgB,MAAM,4BAA4B,CAAC;AAEhF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,wBAAgB,cAAc,CAC5B,SAAS,EAAE,MAAM,EACjB,IAAI,CAAC,EAAE;IAAE,OAAO,CAAC,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,GAC1D,SAAS,CAAC,QAAQ,CAAC,CA4FrB"}
package/dist/reranker.js CHANGED
@@ -3,81 +3,121 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createReranker = createReranker;
4
4
  const lloyal_node_1 = require("@lloyal-labs/lloyal.node");
5
5
  const sdk_1 = require("@lloyal-labs/sdk");
6
+ const effection_1 = require("effection");
6
7
  /**
7
- * Create a {@link Reranker} backed by a dedicated reranking model context
8
+ * Create a {@link Reranker} backed by a dedicated reranking model context,
9
+ * as an Effection `resource()`.
8
10
  *
9
11
  * Loads a separate model (typically a cross-encoder) into its own KV cache
10
- * and exposes `score`, `tokenizeChunks`, and `dispose` methods. The returned
11
- * `score` method yields {@link ScoredResult} batches as an async iterable,
12
- * mapping raw indices back to the original {@link Chunk} metadata.
12
+ * and exposes `score`, `scoreBatch`, `tokenizeChunks`, and `dispose`. The
13
+ * returned `score` method yields {@link ScoredResult} batches as an async
14
+ * iterable, mapping raw indices back to the original {@link Chunk} metadata.
15
+ *
16
+ * **Lifecycle.** The reranker owns its underlying `SessionContext` + `Rerank`
17
+ * and disposes them transitively when the yielding scope exits (success,
18
+ * error, or halt). The harness yields it once per process lifecycle and
19
+ * publishes it on `RerankerCtx` so App factories can read it via
20
+ * `RerankerCtx.expect()`. `dispose()` remains on the interface
21
+ * for callers that manage teardown explicitly; it is idempotent so the
22
+ * resource finally and an explicit call don't double-free.
13
23
  *
14
24
  * @param modelPath - Absolute path to the reranking model file (GGUF)
15
25
  * @param opts - Optional context sizing overrides
16
26
  * @param opts.nSeqMax - Maximum parallel scoring sequences (default 8)
17
27
  * @param opts.nCtx - Context window size for the reranker model (default 4096)
18
- * @returns A ready-to-use reranker instance; call `dispose()` when finished
28
+ * @returns An Effection resource yielding a ready-to-use reranker
29
+ *
30
+ * @example
31
+ * ```ts
32
+ * const reranker = yield* createReranker(rerankerPath, { nSeqMax: 8, nCtx: 4096 });
33
+ * yield* RerankerCtx.set(reranker);
34
+ * // ... pool work ...
35
+ * // reranker disposes automatically on scope exit
36
+ * ```
19
37
  *
20
38
  * @category Rig
21
39
  */
22
- async function createReranker(modelPath, opts) {
23
- const nSeqMax = opts?.nSeqMax ?? 8;
24
- const nCtx = opts?.nCtx ?? 4096;
25
- const nBatch = opts?.nBatch ?? Math.floor(nCtx / nSeqMax);
26
- const ctx = await (0, lloyal_node_1.createContext)({
27
- modelPath,
28
- nCtx,
29
- nSeqMax,
30
- nBatch,
31
- typeK: 'q4_0',
32
- typeV: 'q4_0',
33
- });
34
- const rerank = await sdk_1.Rerank.create(ctx, { nSeqMax, nCtx });
35
- return {
36
- score(query, chunks) {
37
- const inner = rerank.score(query, chunks.map((c) => c.tokens), 10);
38
- return {
39
- [Symbol.asyncIterator]() {
40
- const it = inner[Symbol.asyncIterator]();
41
- return {
42
- async next() {
43
- const { value, done } = await it.next();
44
- if (done)
40
+ function createReranker(modelPath, opts) {
41
+ return (0, effection_1.resource)(function* (provide) {
42
+ // Default bumped 8→10: warm-trunk + per-query branch consume 2 leases in
43
+ // the R3 Rerank composition, so leaves get N-2 slots; 10 keeps the leaf
44
+ // budget at the prior default of 8.
45
+ const nSeqMax = opts?.nSeqMax ?? 10;
46
+ const nCtx = opts?.nCtx ?? 4096;
47
+ const nBatch = opts?.nBatch ?? Math.floor(nCtx / nSeqMax);
48
+ const ctx = yield* (0, effection_1.call)(() => (0, lloyal_node_1.createContext)({
49
+ modelPath,
50
+ nCtx,
51
+ nSeqMax,
52
+ nBatch,
53
+ typeK: 'q4_0',
54
+ typeV: 'q4_0',
55
+ }));
56
+ const rerank = yield* (0, effection_1.call)(() => sdk_1.Rerank.create(ctx, { nSeqMax, nCtx }));
57
+ let disposed = false;
58
+ const reranker = {
59
+ score(query, chunks) {
60
+ const inner = rerank.score(query, chunks.map((c) => c.tokens), 10);
61
+ return {
62
+ [Symbol.asyncIterator]() {
63
+ const it = inner[Symbol.asyncIterator]();
64
+ return {
65
+ async next() {
66
+ const { value, done } = await it.next();
67
+ if (done)
68
+ return {
69
+ value: undefined,
70
+ done: true,
71
+ };
45
72
  return {
46
- value: undefined,
47
- done: true,
73
+ value: {
74
+ filled: value.filled,
75
+ total: value.total,
76
+ results: value.results.map((r) => ({
77
+ file: chunks[r.index].resource,
78
+ heading: chunks[r.index].heading,
79
+ section: chunks[r.index].section,
80
+ snippet: chunks[r.index].text.slice(0, 200),
81
+ score: r.score,
82
+ startLine: chunks[r.index].startLine,
83
+ endLine: chunks[r.index].endLine,
84
+ })),
85
+ },
86
+ done: false,
48
87
  };
49
- return {
50
- value: {
51
- filled: value.filled,
52
- total: value.total,
53
- results: value.results.map((r) => ({
54
- file: chunks[r.index].resource,
55
- heading: chunks[r.index].heading,
56
- section: chunks[r.index].section,
57
- snippet: chunks[r.index].text.slice(0, 200),
58
- score: r.score,
59
- startLine: chunks[r.index].startLine,
60
- endLine: chunks[r.index].endLine,
61
- })),
62
- },
63
- done: false,
64
- };
65
- },
66
- };
67
- },
68
- };
69
- },
70
- scoreBatch(query, texts) {
71
- return rerank.scoreBatch(query, texts);
72
- },
73
- async tokenizeChunks(chunks) {
74
- for (const chunk of chunks) {
75
- chunk.tokens = await rerank.tokenize(chunk.text);
76
- }
77
- },
78
- dispose() {
79
- rerank.dispose();
80
- },
81
- };
88
+ },
89
+ };
90
+ },
91
+ };
92
+ },
93
+ scoreBatch(query, texts) {
94
+ return rerank.scoreBatch(query, texts);
95
+ },
96
+ tokenize(text) {
97
+ return rerank.tokenize(text);
98
+ },
99
+ async tokenizeChunks(chunks) {
100
+ // Tokenize in parallel — _tokenize is N-API AsyncWorker dispatch, so
101
+ // Promise.all overlaps work across threadpool slots. Serial for-await
102
+ // was a bottleneck on large corpora (1000+ chunks).
103
+ const toks = await Promise.all(chunks.map((c) => rerank.tokenize(c.text)));
104
+ for (let i = 0; i < chunks.length; i++) {
105
+ chunks[i].tokens = toks[i];
106
+ }
107
+ },
108
+ dispose() {
109
+ if (disposed)
110
+ return;
111
+ disposed = true;
112
+ rerank.dispose();
113
+ },
114
+ };
115
+ try {
116
+ yield* provide(reranker);
117
+ }
118
+ finally {
119
+ reranker.dispose();
120
+ }
121
+ });
82
122
  }
83
123
  //# sourceMappingURL=reranker.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"reranker.js","sourceRoot":"","sources":["../src/reranker.ts"],"names":[],"mappings":";;AAsBA,wCAuEC;AA7FD,0DAAyD;AACzD,0CAA0C;AAK1C;;;;;;;;;;;;;;;GAeG;AACI,KAAK,UAAU,cAAc,CAClC,SAAiB,EACjB,IAA2D;IAE3D,MAAM,OAAO,GAAG,IAAI,EAAE,OAAO,IAAI,CAAC,CAAC;IACnC,MAAM,IAAI,GAAG,IAAI,EAAE,IAAI,IAAI,IAAI,CAAC;IAChC,MAAM,MAAM,GAAG,IAAI,EAAE,MAAM,IAAI,IAAI,CAAC,KAAK,CAAC,IAAI,GAAG,OAAO,CAAC,CAAC;IAC1D,MAAM,GAAG,GAAG,MAAM,IAAA,2BAAa,EAAC;QAC9B,SAAS;QACT,IAAI;QACJ,OAAO;QACP,MAAM;QACN,KAAK,EAAE,MAAM;QACb,KAAK,EAAE,MAAM;KACd,CAAC,CAAC;IACH,MAAM,MAAM,GAAG,MAAM,YAAM,CAAC,MAAM,CAAC,GAAgC,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;IAExF,OAAO;QACL,KAAK,CAAC,KAAa,EAAE,MAAe;YAClC,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CACxB,KAAK,EACL,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,EAC3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A loaded document available for search, read, and grep operations
3
- *
4
- * Represents a single file (typically Markdown) loaded into memory.
5
- * Resources are chunked into {@link Chunk} instances for reranking.
6
- *
7
- * @category Rig
8
- */
9
- export interface Resource {
10
- /** File name (basename, not full path) used as the resource identifier */
11
- name: string;
12
- /** Full text content of the file */
13
- content: string;
14
- }
15
- /**
16
- * A scored passage within a {@link Resource}, used for reranking and retrieval
17
- *
18
- * Chunks are produced by {@link chunkResources} (section-based for Markdown)
19
- * or {@link chunkFetchedPages} (paragraph-based for web content). The
20
- * {@link tokens} array is populated lazily by {@link Reranker.tokenizeChunks}
21
- * before scoring.
22
- *
2
+ * @deprecated `Resource` and `Chunk` now live in
3
+ * `@lloyal-labs/lloyal-agents` (abstract chunking types
4
+ * moved to agents to mirror the `Source` / `Tool` pattern: abstract
5
+ * types in agents, concrete chunking factories in rig). This module
6
+ * re-exports them so existing rig internal callers keep working
7
+ * during the Phase 3-6 refactor window; new code should import
8
+ * directly from `@lloyal-labs/lloyal-agents`.
9
+ *
10
+ * @packageDocumentation
23
11
  * @category Rig
24
12
  */
25
- export interface Chunk {
26
- /** Resource identifier (file name or URL) this chunk belongs to */
27
- resource: string;
28
- /** Leaf section heading (e.g. "Recovery loop") */
29
- heading: string;
30
- /** Hierarchical section path (e.g. "Agents > Lifecycle > Recovery loop"). Empty for web chunks. */
31
- section: string;
32
- /** Raw text content of the chunk */
33
- text: string;
34
- /** Pre-tokenized representation for the reranker — empty until {@link Reranker.tokenizeChunks} runs */
35
- tokens: number[];
36
- /** First line number (1-based) in the source resource */
37
- startLine: number;
38
- /** Last line number (1-based) in the source resource */
39
- endLine: number;
40
- }
13
+ export type { Resource, Chunk } from '@lloyal-labs/lloyal-agents';
41
14
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/resources/types.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,MAAM,WAAW,QAAQ;IACvB,0EAA0E;IAC1E,IAAI,EAAE,MAAM,CAAC;IACb,oCAAoC;IACpC,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;;;;;;;;GASG;AACH,MAAM,WAAW,KAAK;IACpB,mEAAmE;IACnE,QAAQ,EAAE,MAAM,CAAC;IACjB,kDAAkD;IAClD,OAAO,EAAE,MAAM,CAAC;IAChB,mGAAmG;IACnG,OAAO,EAAE,MAAM,CAAC;IAChB,oCAAoC;IACpC,IAAI,EAAE,MAAM,CAAC;IACb,uGAAuG;IACvG,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,yDAAyD;IACzD,SAAS,EAAE,MAAM,CAAC;IAClB,wDAAwD;IACxD,OAAO,EAAE,MAAM,CAAC;CACjB"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/resources/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,YAAY,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,4BAA4B,CAAC"}
@@ -1,3 +1,15 @@
1
1
  "use strict";
2
+ /**
3
+ * @deprecated `Resource` and `Chunk` now live in
4
+ * `@lloyal-labs/lloyal-agents` (abstract chunking types
5
+ * moved to agents to mirror the `Source` / `Tool` pattern: abstract
6
+ * types in agents, concrete chunking factories in rig). This module
7
+ * re-exports them so existing rig internal callers keep working
8
+ * during the Phase 3-6 refactor window; new code should import
9
+ * directly from `@lloyal-labs/lloyal-agents`.
10
+ *
11
+ * @packageDocumentation
12
+ * @category Rig
13
+ */
2
14
  Object.defineProperty(exports, "__esModule", { value: true });
3
15
  //# sourceMappingURL=types.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/resources/types.ts"],"names":[],"mappings":""}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/resources/types.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;GAWG"}