@retinue/agentkit 0.2.0 → 0.3.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/README.md +1 -1
- package/dist/adapters/audio/openai.d.ts +36 -0
- package/dist/adapters/audio/openai.js +136 -0
- package/dist/adapters/bullmq/lock.d.ts +26 -2
- package/dist/adapters/memory/connections.d.ts +10 -0
- package/dist/adapters/memory/connections.js +87 -0
- package/dist/adapters/memory/graph.d.ts +17 -0
- package/dist/adapters/memory/graph.js +267 -0
- package/dist/adapters/memory/index.d.ts +3 -0
- package/dist/adapters/memory/index.js +3 -0
- package/dist/adapters/memory/rate-limit.d.ts +14 -0
- package/dist/adapters/memory/rate-limit.js +28 -0
- package/dist/adapters/memory/runtime.js +0 -0
- package/dist/adapters/postgres/connections.d.ts +15 -0
- package/dist/adapters/postgres/connections.js +134 -0
- package/dist/adapters/postgres/graph.d.ts +24 -0
- package/dist/adapters/postgres/graph.js +325 -0
- package/dist/adapters/postgres/index.d.ts +2 -0
- package/dist/adapters/postgres/index.js +2 -0
- package/dist/adapters/postgres/migrations.js +198 -0
- package/dist/adapters/postgres/run-store.js +26 -2
- package/dist/adapters/postgres/schema.d.ts +61 -2
- package/dist/adapters/postgres/schema.js +95 -10
- package/dist/adapters/redis/index.d.ts +1 -0
- package/dist/adapters/redis/index.js +1 -0
- package/dist/adapters/redis/rate-limit.d.ts +46 -0
- package/dist/adapters/redis/rate-limit.js +55 -0
- package/dist/adapters/supabase/index.d.ts +15 -0
- package/dist/adapters/supabase/index.js +15 -0
- package/dist/adapters/supabase/rls.js +33 -0
- package/dist/agents/agent.d.ts +78 -1
- package/dist/agents/agent.js +118 -5
- package/dist/agents/define.js +24 -4
- package/dist/agents/engine.d.ts +20 -0
- package/dist/agents/engine.js +177 -6
- package/dist/audio/index.d.ts +151 -0
- package/dist/audio/index.js +183 -0
- package/dist/connections/cipher.d.ts +103 -0
- package/dist/connections/cipher.js +141 -0
- package/dist/connections/index.d.ts +156 -0
- package/dist/connections/index.js +72 -0
- package/dist/connections/oauth/client.d.ts +84 -0
- package/dist/connections/oauth/client.js +141 -0
- package/dist/connections/oauth/index.d.ts +166 -0
- package/dist/connections/oauth/index.js +226 -0
- package/dist/connections/oauth/service.d.ts +90 -0
- package/dist/connections/oauth/service.js +132 -0
- package/dist/connections/pause.d.ts +68 -0
- package/dist/connections/pause.js +97 -0
- package/dist/connections/resolver.d.ts +59 -0
- package/dist/connections/resolver.js +138 -0
- package/dist/connections/resume.d.ts +64 -0
- package/dist/connections/resume.js +99 -0
- package/dist/connections/vault-cipher.d.ts +95 -0
- package/dist/connections/vault-cipher.js +206 -0
- package/dist/core/content-parts.d.ts +18 -2
- package/dist/core/content-parts.js +1 -0
- package/dist/core/context.d.ts +25 -0
- package/dist/core/errors.d.ts +1 -1
- package/dist/core/errors.js +15 -0
- package/dist/core/events.d.ts +44 -2
- package/dist/core/events.js +31 -2
- package/dist/core/validation.js +19 -0
- package/dist/entries/connections.d.ts +10 -0
- package/dist/entries/connections.js +10 -0
- package/dist/entries/knowledge.d.ts +8 -0
- package/dist/entries/knowledge.js +8 -0
- package/dist/entries/mcp-server.d.ts +9 -0
- package/dist/entries/mcp-server.js +9 -0
- package/dist/entries/runtime.d.ts +10 -0
- package/dist/entries/runtime.js +8 -0
- package/dist/entries/testing.d.ts +28 -0
- package/dist/entries/testing.js +28 -0
- package/dist/graphql/resolvers.d.ts +3 -1
- package/dist/graphql/resolvers.js +14 -0
- package/dist/knowledge/communities.d.ts +166 -0
- package/dist/knowledge/communities.js +377 -0
- package/dist/knowledge/graph-global.d.ts +153 -0
- package/dist/knowledge/graph-global.js +246 -0
- package/dist/knowledge/graph-retrieval.d.ts +150 -0
- package/dist/knowledge/graph-retrieval.js +303 -0
- package/dist/knowledge/graph.d.ts +223 -0
- package/dist/knowledge/graph.js +369 -0
- package/dist/knowledge/index.d.ts +24 -0
- package/dist/knowledge/index.js +36 -1
- package/dist/knowledge/retrieval.d.ts +26 -1
- package/dist/knowledge/retrieval.js +77 -1
- package/dist/mcp-server/index.d.ts +168 -0
- package/dist/mcp-server/index.js +175 -0
- package/dist/models/extraction.d.ts +73 -0
- package/dist/models/extraction.js +118 -0
- package/dist/models/index.d.ts +40 -1
- package/dist/models/index.js +22 -1
- package/dist/models/pricing.d.ts +2 -0
- package/dist/models/pricing.js +17 -1
- package/dist/models/provider-factory.js +9 -7
- package/dist/models/streaming.d.ts +89 -0
- package/dist/models/streaming.js +179 -2
- package/dist/persistence/index.d.ts +230 -0
- package/dist/persistence/index.js +2 -0
- package/dist/runtime/index.d.ts +1 -1
- package/dist/runtime/index.js +12 -0
- package/dist/runtime/worker.d.ts +36 -1
- package/dist/runtime/worker.js +37 -4
- package/dist/security/checklist.js +46 -0
- package/dist/server/bin.d.ts +19 -0
- package/dist/server/bin.js +226 -0
- package/dist/server/boot.d.ts +20 -2
- package/dist/server/boot.js +29 -3
- package/dist/server/cli.d.ts +13 -0
- package/dist/server/cli.js +7 -4
- package/dist/server/doctor.d.ts +74 -0
- package/dist/server/doctor.js +280 -0
- package/dist/skills/context.d.ts +61 -0
- package/dist/skills/context.js +107 -0
- package/dist/skills/index.d.ts +1 -0
- package/dist/skills/index.js +1 -0
- package/dist/telemetry/spans.js +5 -0
- package/dist/testing/conformance/artifact-exports.d.ts +20 -0
- package/dist/testing/conformance/artifact-exports.js +172 -0
- package/dist/testing/conformance/artifacts.d.ts +11 -0
- package/dist/testing/conformance/artifacts.js +316 -0
- package/dist/testing/conformance/audio.d.ts +38 -0
- package/dist/testing/conformance/audio.js +145 -0
- package/dist/testing/conformance/capability.d.ts +23 -0
- package/dist/testing/conformance/capability.js +27 -0
- package/dist/testing/conformance/checkpoint-store.d.ts +15 -0
- package/dist/testing/conformance/checkpoint-store.js +72 -0
- package/dist/testing/conformance/connections.d.ts +14 -0
- package/dist/testing/conformance/connections.js +171 -0
- package/dist/testing/conformance/conversation-store.d.ts +10 -0
- package/dist/testing/conformance/conversation-store.js +60 -0
- package/dist/testing/conformance/evaluation.d.ts +10 -0
- package/dist/testing/conformance/evaluation.js +295 -0
- package/dist/testing/conformance/files.d.ts +19 -0
- package/dist/testing/conformance/files.js +454 -0
- package/dist/testing/conformance/flows.d.ts +16 -0
- package/dist/testing/conformance/flows.js +193 -0
- package/dist/testing/conformance/graph.d.ts +22 -0
- package/dist/testing/conformance/graph.js +500 -0
- package/dist/testing/conformance/hitl.d.ts +25 -0
- package/dist/testing/conformance/hitl.js +523 -0
- package/dist/testing/conformance/index.d.ts +163 -0
- package/dist/testing/conformance/index.js +321 -0
- package/dist/testing/conformance/invariants.d.ts +23 -0
- package/dist/testing/conformance/invariants.js +80 -0
- package/dist/testing/conformance/knowledge.d.ts +41 -0
- package/dist/testing/conformance/knowledge.js +592 -0
- package/dist/testing/conformance/parents.d.ts +50 -0
- package/dist/testing/conformance/parents.js +39 -0
- package/dist/testing/conformance/rate-limit.d.ts +25 -0
- package/dist/testing/conformance/rate-limit.js +71 -0
- package/dist/testing/conformance/records.d.ts +36 -0
- package/dist/testing/conformance/records.js +400 -0
- package/dist/testing/conformance/rollups.d.ts +30 -0
- package/dist/testing/conformance/rollups.js +425 -0
- package/dist/testing/conformance/run-coordinator.d.ts +27 -0
- package/dist/testing/conformance/run-coordinator.js +150 -0
- package/dist/testing/conformance/run-event-log.d.ts +9 -0
- package/dist/testing/conformance/run-event-log.js +138 -0
- package/dist/testing/conformance/run-store.d.ts +12 -0
- package/dist/testing/conformance/run-store.js +294 -0
- package/dist/testing/conformance/session-state.d.ts +38 -0
- package/dist/testing/conformance/session-state.js +198 -0
- package/dist/testing/conformance/usage-limits.d.ts +10 -0
- package/dist/testing/conformance/usage-limits.js +309 -0
- package/dist/testing/conformance.d.ts +8 -0
- package/dist/testing/conformance.js +8 -0
- package/dist/testing/memory-backend.d.ts +39 -0
- package/dist/testing/memory-backend.js +41 -0
- package/dist/testing/pglite.d.ts +55 -0
- package/dist/testing/pglite.js +78 -0
- package/dist/testing/stub-model.d.ts +58 -0
- package/dist/testing/stub-model.js +71 -0
- package/dist/testing/supabase-storage-double.d.ts +35 -0
- package/dist/testing/supabase-storage-double.js +101 -0
- package/dist/toolkit/http.d.ts +27 -0
- package/dist/toolkit/http.js +48 -0
- package/dist/toolkit/index.d.ts +27 -1
- package/dist/toolkit/index.js +24 -1
- package/dist/toolkit/mime.d.ts +97 -0
- package/dist/toolkit/mime.js +233 -0
- package/dist/toolkit/ssrf.d.ts +139 -0
- package/dist/toolkit/ssrf.js +349 -0
- package/dist/toolkit/vendor.d.ts +91 -0
- package/dist/toolkit/vendor.js +153 -0
- package/dist/tools/credentials.d.ts +265 -6
- package/dist/tools/credentials.js +318 -3
- package/dist/tools/define.d.ts +14 -0
- package/dist/tools/define.js +3 -0
- package/dist/tools/index.d.ts +21 -0
- package/dist/tools/index.js +7 -0
- package/dist/tools/library/audio.d.ts +63 -0
- package/dist/tools/library/audio.js +148 -0
- package/dist/tools/library/index.d.ts +8 -0
- package/dist/tools/library/index.js +7 -0
- package/dist/tools/registry.d.ts +33 -0
- package/dist/tools/registry.js +72 -2
- package/dist/usage/index.d.ts +21 -0
- package/dist/usage/index.js +1 -0
- package/dist/usage/rate-limit.d.ts +122 -0
- package/dist/usage/rate-limit.js +131 -0
- package/dist/usage/recorder.js +3 -0
- package/package.json +29 -2
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@retinue/agentkit/mcp-server` — expose this deployment's tools to MCP clients (#250).
|
|
3
|
+
*
|
|
4
|
+
* Its own subpath, and separate from `./mcp`, because the two are opposite directions: `./mcp` consumes a
|
|
5
|
+
* tenant's MCP servers, and this **is** one. Sharing an entry would put the SDK's server half in the way of
|
|
6
|
+
* every consumer who only wanted the client half.
|
|
7
|
+
*/
|
|
8
|
+
export * from "../mcp-server/index.js";
|
|
9
|
+
//# sourceMappingURL=mcp-server.js.map
|
|
@@ -10,4 +10,14 @@ export * from "../models/index.js";
|
|
|
10
10
|
export * from "../capabilities/index.js";
|
|
11
11
|
export * from "../capabilities/runtime.js";
|
|
12
12
|
export * from "../core/index.js";
|
|
13
|
+
/**
|
|
14
|
+
* The audio ports and their OpenAI adapters — REQ-062 (#257).
|
|
15
|
+
*
|
|
16
|
+
* Here rather than in `tools`, because a `TranscriptionProvider` is a runtime capability a host wires once —
|
|
17
|
+
* the same place a `SearchProvider` is chosen. The two tools that use them live in the tool library.
|
|
18
|
+
*/
|
|
19
|
+
export { assertWithinBounds, AUDIO_MEDIA_TYPES, AudioRejected, boundTranscript, describeAudioFailure, isAudioMediaType, MAX_AUDIO_BYTES, MAX_AUDIO_SECONDS, MAX_SPEECH_CHARS, MAX_TRANSCRIPT_CHARS, } from "../audio/index.js";
|
|
20
|
+
export type { AudioBounds, AudioMediaType, SpeechProvider, SpeechRequest, SpeechResult, TranscriptionProvider, TranscriptionRequest, TranscriptionResult, } from "../audio/index.js";
|
|
21
|
+
export { openAiSpeech, openAiTranscription } from "../adapters/audio/openai.js";
|
|
22
|
+
export type { OpenAiAudioConfig } from "../adapters/audio/openai.js";
|
|
13
23
|
//# sourceMappingURL=runtime.d.ts.map
|
package/dist/entries/runtime.js
CHANGED
|
@@ -10,4 +10,12 @@ export * from "../models/index.js";
|
|
|
10
10
|
export * from "../capabilities/index.js";
|
|
11
11
|
export * from "../capabilities/runtime.js";
|
|
12
12
|
export * from "../core/index.js";
|
|
13
|
+
/**
|
|
14
|
+
* The audio ports and their OpenAI adapters — REQ-062 (#257).
|
|
15
|
+
*
|
|
16
|
+
* Here rather than in `tools`, because a `TranscriptionProvider` is a runtime capability a host wires once —
|
|
17
|
+
* the same place a `SearchProvider` is chosen. The two tools that use them live in the tool library.
|
|
18
|
+
*/
|
|
19
|
+
export { assertWithinBounds, AUDIO_MEDIA_TYPES, AudioRejected, boundTranscript, describeAudioFailure, isAudioMediaType, MAX_AUDIO_BYTES, MAX_AUDIO_SECONDS, MAX_SPEECH_CHARS, MAX_TRANSCRIPT_CHARS, } from "../audio/index.js";
|
|
20
|
+
export { openAiSpeech, openAiTranscription } from "../adapters/audio/openai.js";
|
|
13
21
|
//# sourceMappingURL=runtime.js.map
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@retinue/agentkit/testing` — the conformance suite and the fakes — task #253.
|
|
3
|
+
*
|
|
4
|
+
* The README's headline claim is *"Replaceable everything — 31 ports, three adapter families, one conformance
|
|
5
|
+
* suite held over all of them."* A consumer who took that invitation and wrote a fourth adapter family could not
|
|
6
|
+
* run the suite: it lived in `src/testing/`, which the build excluded and no export reached. The most valuable
|
|
7
|
+
* thing in the repository for anyone doing that was the one thing they could not have.
|
|
8
|
+
*
|
|
9
|
+
* ## Two audiences, one entry
|
|
10
|
+
*
|
|
11
|
+
* - **Implementing a port.** `<port>Conformance` runs the same contract tests the built-in families are held to.
|
|
12
|
+
* That is what makes "replaceable" checkable rather than an invitation.
|
|
13
|
+
* - **Implementing an agent or a tool.** `createStubModel` and `createMemoryStores` are for a test that must not
|
|
14
|
+
* call a provider or stand up a database.
|
|
15
|
+
*
|
|
16
|
+
* ## Why the test runner is an optional peer
|
|
17
|
+
*
|
|
18
|
+
* The harnesses call `describe`/`it`/`expect` at module scope, so importing this pulls `vitest`. It is an
|
|
19
|
+
* **optional peer dependency**, not a dependency: a consumer who never imports this subpath never installs it,
|
|
20
|
+
* and nothing in a production bundle can reach it — the only paths to these modules are through this entry.
|
|
21
|
+
* `@electric-sql/pglite` is optional for the same reason, and only `pgliteExecutor` needs it.
|
|
22
|
+
*/
|
|
23
|
+
export * from "../testing/conformance/index.js";
|
|
24
|
+
export * from "../testing/stub-model.js";
|
|
25
|
+
export * from "../testing/memory-backend.js";
|
|
26
|
+
export * from "../testing/pglite.js";
|
|
27
|
+
export * from "../testing/conformance/audio.js";
|
|
28
|
+
//# sourceMappingURL=testing.d.ts.map
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@retinue/agentkit/testing` — the conformance suite and the fakes — task #253.
|
|
3
|
+
*
|
|
4
|
+
* The README's headline claim is *"Replaceable everything — 31 ports, three adapter families, one conformance
|
|
5
|
+
* suite held over all of them."* A consumer who took that invitation and wrote a fourth adapter family could not
|
|
6
|
+
* run the suite: it lived in `src/testing/`, which the build excluded and no export reached. The most valuable
|
|
7
|
+
* thing in the repository for anyone doing that was the one thing they could not have.
|
|
8
|
+
*
|
|
9
|
+
* ## Two audiences, one entry
|
|
10
|
+
*
|
|
11
|
+
* - **Implementing a port.** `<port>Conformance` runs the same contract tests the built-in families are held to.
|
|
12
|
+
* That is what makes "replaceable" checkable rather than an invitation.
|
|
13
|
+
* - **Implementing an agent or a tool.** `createStubModel` and `createMemoryStores` are for a test that must not
|
|
14
|
+
* call a provider or stand up a database.
|
|
15
|
+
*
|
|
16
|
+
* ## Why the test runner is an optional peer
|
|
17
|
+
*
|
|
18
|
+
* The harnesses call `describe`/`it`/`expect` at module scope, so importing this pulls `vitest`. It is an
|
|
19
|
+
* **optional peer dependency**, not a dependency: a consumer who never imports this subpath never installs it,
|
|
20
|
+
* and nothing in a production bundle can reach it — the only paths to these modules are through this entry.
|
|
21
|
+
* `@electric-sql/pglite` is optional for the same reason, and only `pgliteExecutor` needs it.
|
|
22
|
+
*/
|
|
23
|
+
export * from "../testing/conformance/index.js";
|
|
24
|
+
export * from "../testing/stub-model.js";
|
|
25
|
+
export * from "../testing/memory-backend.js";
|
|
26
|
+
export * from "../testing/pglite.js";
|
|
27
|
+
export * from "../testing/conformance/audio.js";
|
|
28
|
+
//# sourceMappingURL=testing.js.map
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* shape and delegates to a service. No business logic lives in this layer.
|
|
6
6
|
*/
|
|
7
7
|
import type { ExecutionContext } from "../core/context.js";
|
|
8
|
-
import type { QuotaGuard } from "../usage/index.js";
|
|
8
|
+
import type { QuotaGuard, RateLimitGuard } from "../usage/index.js";
|
|
9
9
|
import type { UsageRollupStore } from "../persistence/index.js";
|
|
10
10
|
import type { ConversationId, RunId } from "../core/ids.js";
|
|
11
11
|
import type { ConversationStore, UsageStore } from "../persistence/index.js";
|
|
@@ -38,6 +38,8 @@ export type ResolverDeps = {
|
|
|
38
38
|
* that blocks nothing is a bill the rollups make visible.
|
|
39
39
|
*/
|
|
40
40
|
readonly quota?: QuotaGuard;
|
|
41
|
+
/** Capacity, as distinct from spend — task #248. Absent means unchecked. */
|
|
42
|
+
readonly rateLimit?: RateLimitGuard;
|
|
41
43
|
/**
|
|
42
44
|
* Rollups for the spend panel (#140).
|
|
43
45
|
*
|
|
@@ -201,6 +201,20 @@ export const createResolvers = (deps) => {
|
|
|
201
201
|
//
|
|
202
202
|
// Optional, because a deployment with no limits configured is valid; when it is absent nothing is
|
|
203
203
|
// checked, which is the same as an unbounded limit.
|
|
204
|
+
/**
|
|
205
|
+
* Rate before cost — task #248.
|
|
206
|
+
*
|
|
207
|
+
* This order is deliberate. A rate check is one atomic counter increment; a quota check reads a rollup.
|
|
208
|
+
* A tenant hammering the platform should be turned away by the cheaper check, not made to do the more
|
|
209
|
+
* expensive one first — otherwise the defence against a runaway client is itself proportional to how
|
|
210
|
+
* hard the client is running.
|
|
211
|
+
*
|
|
212
|
+
* Optional like the quota, and absent means unchecked. See `createRateLimitGuard`: an absent policy or a
|
|
213
|
+
* `max` of zero is unlimited, so adding this feature cannot refuse a deployment that has configured
|
|
214
|
+
* nothing.
|
|
215
|
+
*/
|
|
216
|
+
if (deps.rateLimit !== undefined)
|
|
217
|
+
await deps.rateLimit.assertAdmitted(ctx.execution);
|
|
204
218
|
if (deps.quota !== undefined)
|
|
205
219
|
await deps.quota.assertAdmitted(ctx.execution);
|
|
206
220
|
const started = await startOrEnqueueRun(deps.coordinator, { tenantId: tid(ctx), conversationId, runId });
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Community detection — REQ-064 (#270), task #272.
|
|
3
|
+
*
|
|
4
|
+
* `graph-global` answers "what are the main themes?" by reducing over summaries of clusters. This produces the
|
|
5
|
+
* clusters.
|
|
6
|
+
*
|
|
7
|
+
* ## Why this is implemented here rather than imported
|
|
8
|
+
*
|
|
9
|
+
* `backend` has exactly two runtime dependencies, `ai` and `zod`, and that is a property worth keeping. But the
|
|
10
|
+
* dependency count is the smaller argument. The larger one is **determinism**: Microsoft's GraphRAG uses
|
|
11
|
+
* hierarchical Leiden, and the widely-used implementations of Leiden and Louvain are seeded-random — they
|
|
12
|
+
* shuffle node order to escape local optima, which is good for modularity and fatal here. #275 measures
|
|
13
|
+
* GraphRAG against a fixed baseline, #272's own incremental rebuild is verified by comparing against a
|
|
14
|
+
* previous clustering, and both need the same graph to cluster the same way twice.
|
|
15
|
+
*
|
|
16
|
+
* So this is Louvain with every source of nondeterminism removed:
|
|
17
|
+
*
|
|
18
|
+
* - Nodes are visited in **sorted id order**, never shuffled.
|
|
19
|
+
* - A tie in modularity gain is broken by the **smallest community id**, so equal options resolve the same way.
|
|
20
|
+
* - Aggregation preserves that ordering into the next level.
|
|
21
|
+
*
|
|
22
|
+
* The cost is some modularity — a shuffled Louvain finds slightly better partitions on average. That is a
|
|
23
|
+
* trade worth making for a result that can be measured, diffed and debugged, and it is stated here rather than
|
|
24
|
+
* discovered later by somebody wondering why two runs disagree.
|
|
25
|
+
*
|
|
26
|
+
* Louvain rather than label propagation, which was the other candidate: label propagation is simpler and
|
|
27
|
+
* roughly as fast, but it produces one flat partition and #272 needs **hierarchy**. Louvain's aggregation
|
|
28
|
+
* phases *are* the levels — level 0 is fine-grained, each subsequent level coarser — which is exactly the
|
|
29
|
+
* granularity choice `graph-global` has to make between "what are the main themes" and "what are the themes in
|
|
30
|
+
* observability".
|
|
31
|
+
*/
|
|
32
|
+
import type { TenantId } from "../core/ids.js";
|
|
33
|
+
import type { GraphStore, KnowledgeRelationship, KnowledgeStore } from "../persistence/index.js";
|
|
34
|
+
/** A cluster of entities at one level of the hierarchy. */
|
|
35
|
+
export type Community = {
|
|
36
|
+
/**
|
|
37
|
+
* Deterministic and readable: `L<level>:<smallest member id>`.
|
|
38
|
+
*
|
|
39
|
+
* Derived from the membership rather than assigned by a counter, so the same cluster keeps the same id
|
|
40
|
+
* across runs — which is what lets a rebuild compare against the previous clustering at all. A counter would
|
|
41
|
+
* renumber everything whenever one entity moved.
|
|
42
|
+
*/
|
|
43
|
+
readonly id: string;
|
|
44
|
+
readonly level: number;
|
|
45
|
+
/** Sorted. */
|
|
46
|
+
readonly entityIds: readonly string[];
|
|
47
|
+
/** Edges with both endpoints inside this community, sorted. */
|
|
48
|
+
readonly relationshipIds: readonly string[];
|
|
49
|
+
/** Chunks behind those entities and edges, sorted. The provenance a summary inherits. */
|
|
50
|
+
readonly chunkIds: readonly string[];
|
|
51
|
+
/**
|
|
52
|
+
* A fingerprint of exactly what this community contains.
|
|
53
|
+
*
|
|
54
|
+
* The mechanism behind incremental summarisation and visible staleness: a summary records the fingerprint it
|
|
55
|
+
* was written against, and a community whose fingerprint no longer matches is stale — knowable without
|
|
56
|
+
* re-reading the summary or trusting a timestamp.
|
|
57
|
+
*/
|
|
58
|
+
readonly fingerprint: string;
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* How many levels of hierarchy to build.
|
|
62
|
+
*
|
|
63
|
+
* Two is the minimum AC-1 asks for and the useful default: level 0 is fine-grained clusters and level 1 groups
|
|
64
|
+
* them. More levels on a small graph collapse to the same partition repeated, which costs summarisation calls
|
|
65
|
+
* for no new information — so the loop stops early when a level stops merging anything.
|
|
66
|
+
*/
|
|
67
|
+
export declare const DEFAULT_COMMUNITY_LEVELS = 2;
|
|
68
|
+
/**
|
|
69
|
+
* Cluster a graph into a hierarchy of communities.
|
|
70
|
+
*
|
|
71
|
+
* Pure and deterministic: the same entities and relationships always produce the same result, which every test
|
|
72
|
+
* of incremental rebuild depends on.
|
|
73
|
+
*
|
|
74
|
+
* Singletons are kept rather than dropped. An entity nothing links to is a real part of the corpus and a
|
|
75
|
+
* `graph-global` answer that silently omitted every unconnected concept would be quietly wrong about what the
|
|
76
|
+
* corpus contains.
|
|
77
|
+
*/
|
|
78
|
+
export declare const detectCommunities: (input: {
|
|
79
|
+
readonly entityIds: readonly string[];
|
|
80
|
+
readonly relationships: readonly KnowledgeRelationship[];
|
|
81
|
+
readonly chunksOf: (entityId: string) => readonly string[];
|
|
82
|
+
readonly levels?: number;
|
|
83
|
+
}) => readonly Community[];
|
|
84
|
+
/**
|
|
85
|
+
* Writes a community's summary — REQ-064 (#270), task #272.
|
|
86
|
+
*
|
|
87
|
+
* A port, like `EntityExtractor`, and optional for the same reason: a deployment that clusters but never runs
|
|
88
|
+
* `graph-global` needs no language model for it. Given the community's entities, its relationships and the
|
|
89
|
+
* text behind them, and asked for a short description of what this cluster is *about*.
|
|
90
|
+
*/
|
|
91
|
+
export interface CommunitySummariser {
|
|
92
|
+
readonly id: string;
|
|
93
|
+
summarise(input: {
|
|
94
|
+
readonly community: Community;
|
|
95
|
+
/** The chunk text behind the community, already permission-free — it is all one tenant's own material. */
|
|
96
|
+
readonly excerpts: readonly string[];
|
|
97
|
+
readonly entityNames: readonly string[];
|
|
98
|
+
readonly relationshipDescriptions: readonly string[];
|
|
99
|
+
}): Promise<{
|
|
100
|
+
readonly summary: string;
|
|
101
|
+
readonly usage?: {
|
|
102
|
+
readonly inputTokens?: number;
|
|
103
|
+
readonly outputTokens?: number;
|
|
104
|
+
};
|
|
105
|
+
}>;
|
|
106
|
+
}
|
|
107
|
+
export type CommunityRebuildResult = {
|
|
108
|
+
readonly communities: number;
|
|
109
|
+
readonly levels: number;
|
|
110
|
+
/** Communities whose summary was reused because their membership did not change. The incremental saving. */
|
|
111
|
+
readonly summariesKept: number;
|
|
112
|
+
readonly summariesWritten: number;
|
|
113
|
+
/** Summarisation calls that failed. The community survives without a summary — AC-7. */
|
|
114
|
+
readonly summariesFailed: number;
|
|
115
|
+
readonly inputTokens: number;
|
|
116
|
+
readonly outputTokens: number;
|
|
117
|
+
};
|
|
118
|
+
export type CommunityBuilderDeps = {
|
|
119
|
+
readonly store: GraphStore;
|
|
120
|
+
/** Absent means cluster but do not summarise. Useful, and the honest default for a deployment without `graph-global`. */
|
|
121
|
+
readonly summariser?: CommunitySummariser;
|
|
122
|
+
readonly knowledge?: KnowledgeStore;
|
|
123
|
+
readonly levels?: number;
|
|
124
|
+
/** Chunk excerpts handed to the summariser per community. A ceiling, because a community can span hundreds. */
|
|
125
|
+
readonly maxExcerpts?: number;
|
|
126
|
+
/**
|
|
127
|
+
* Which levels to summarise. Absent means all of them.
|
|
128
|
+
*
|
|
129
|
+
* **Worth setting, because summarising a level nobody queries is pure cost.** `graph-global` reads *one*
|
|
130
|
+
* level per query — the coarsest by default — and a two-level hierarchy over a real corpus has far more
|
|
131
|
+
* fine-grained communities than coarse ones. Summarising every level can therefore multiply the bill several
|
|
132
|
+
* times over for content no query will ever reduce across.
|
|
133
|
+
*
|
|
134
|
+
* Not defaulted to the coarsest, deliberately: a deployment that lets callers ask at a finer granularity
|
|
135
|
+
* needs those summaries, and silently not writing them would make `graph-global` at that level return
|
|
136
|
+
* nothing with no explanation. The cost is real either way; this makes it a decision.
|
|
137
|
+
*/
|
|
138
|
+
readonly summariseLevels?: readonly number[];
|
|
139
|
+
readonly clock?: () => string;
|
|
140
|
+
readonly log?: (message: string, detail?: Readonly<Record<string, unknown>>) => void;
|
|
141
|
+
};
|
|
142
|
+
export declare const DEFAULT_MAX_EXCERPTS = 20;
|
|
143
|
+
/**
|
|
144
|
+
* Rebuilds the community hierarchy, and re-summarises **only what changed**.
|
|
145
|
+
*
|
|
146
|
+
* This is where AC-5's "incremental" honestly lives, and it is worth being precise about the split rather than
|
|
147
|
+
* claiming more than is true:
|
|
148
|
+
*
|
|
149
|
+
* - **Clustering is global and cheap.** Community detection is global by nature — one entity moving can change
|
|
150
|
+
* every level — so the whole graph is re-clustered. It is arithmetic over ids, with no model calls, and
|
|
151
|
+
* pretending to do it incrementally would mean a partition that disagrees with itself.
|
|
152
|
+
* - **Summarisation is incremental and expensive.** One model call per community, and that is the cost worth
|
|
153
|
+
* avoiding. A community whose membership fingerprint is unchanged keeps its summary untouched.
|
|
154
|
+
*
|
|
155
|
+
* So changing one source re-clusters everything and re-summarises the handful of communities that actually
|
|
156
|
+
* moved. The staleness window is therefore *zero for structure* and *one rebuild for summaries*, and a
|
|
157
|
+
* community caught between the two is visibly stale rather than silently wrong.
|
|
158
|
+
*/
|
|
159
|
+
export declare const createCommunityBuilder: (deps: CommunityBuilderDeps) => {
|
|
160
|
+
summariserId: string | null;
|
|
161
|
+
rebuild(context: {
|
|
162
|
+
readonly tenantId: TenantId;
|
|
163
|
+
}): Promise<CommunityRebuildResult>;
|
|
164
|
+
};
|
|
165
|
+
export type CommunityBuilder = ReturnType<typeof createCommunityBuilder>;
|
|
166
|
+
//# sourceMappingURL=communities.d.ts.map
|