@pegma/knowledge-base-mcp 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +81 -2
- package/dist/dispatcher.d.ts +7 -0
- package/dist/dispatcher.d.ts.map +1 -0
- package/dist/dispatcher.js +155 -0
- package/dist/dispatcher.js.map +1 -0
- package/dist/errors.d.ts +10 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +75 -0
- package/dist/errors.js.map +1 -0
- package/dist/http.d.ts +14 -0
- package/dist/http.d.ts.map +1 -0
- package/dist/http.js +28 -0
- package/dist/http.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/dist/mcp.d.ts +17 -0
- package/dist/mcp.d.ts.map +1 -0
- package/dist/mcp.js +313 -0
- package/dist/mcp.js.map +1 -0
- package/dist/schemas.d.ts +363 -0
- package/dist/schemas.d.ts.map +1 -0
- package/dist/schemas.js +416 -0
- package/dist/schemas.js.map +1 -0
- package/dist/transport-common.d.ts +57 -0
- package/dist/transport-common.d.ts.map +1 -0
- package/dist/transport-common.js +411 -0
- package/dist/transport-common.js.map +1 -0
- package/dist/types.d.ts +90 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +45 -0
- package/dist/types.js.map +1 -0
- package/package.json +43 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Pegma
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,82 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @pegma/knowledge-base-mcp
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Optional KB-04 agent transport source for Pegma Knowledge Base. This package
|
|
4
|
+
adapts the authorized application API to bounded agent commands and the Model
|
|
5
|
+
Context Protocol. It is unpublished at `0.1.0`; merging its source does not
|
|
6
|
+
publish it or establish a live hosted Knowledge Base.
|
|
7
|
+
|
|
8
|
+
The contracts, core, and application packages remain independent of MCP, HTTP,
|
|
9
|
+
provider SDKs, and login flows. Hosts choose this adapter when exposing agent
|
|
10
|
+
access. The adapter pins `@modelcontextprotocol/sdk` at `1.32.2` and `zod` at
|
|
11
|
+
`4.6.7`; it composes the same exact `0.1.0` Knowledge Base packages.
|
|
12
|
+
|
|
13
|
+
The MCP adapter explicitly uses the SDK's Workers-compatible JSON Schema
|
|
14
|
+
validator, which requires no generated code. Its `@cfworker/json-schema`
|
|
15
|
+
dependency is pinned at `4.1.6` and required by this package even though the
|
|
16
|
+
SDK declares it as an optional peer. Packed consumers receive the validator
|
|
17
|
+
without needing to discover or install that peer themselves.
|
|
18
|
+
|
|
19
|
+
## Trust and composition
|
|
20
|
+
|
|
21
|
+
The host owns credential issuance, authentication, resource binding, current
|
|
22
|
+
authorization, and evidence verification. Compose the adapter with the
|
|
23
|
+
Knowledge Base application and host authentication ports. Agent Access is a
|
|
24
|
+
separate producer; it is not a runtime dependency of this package. An opaque
|
|
25
|
+
credential, caller-supplied actor, or claimed evidence result does not establish
|
|
26
|
+
an authenticated `AccessContext` or trusted evidence.
|
|
27
|
+
|
|
28
|
+
Agent operations use the same current-resource authorization, application
|
|
29
|
+
generation, immutable evidence, replay, and publication rules as other
|
|
30
|
+
application callers. Agents can prepare drafts and submit evidence through the
|
|
31
|
+
declared tool surface. Review and publication remain separate staff authority.
|
|
32
|
+
The adapter never executes article steps, fetches evidence URLs, provisions a
|
|
33
|
+
runner, or creates a second database or identity system.
|
|
34
|
+
|
|
35
|
+
`createKnowledgeAgentDispatcher` provides the shared operation boundary.
|
|
36
|
+
`knowledgeAgentScopes`, `knowledgeAgentOperations`, and
|
|
37
|
+
`knowledgeAgentToolNames` declare its finite surface. Inputs are validated
|
|
38
|
+
against shared internal schemas and fixed component ceilings before dispatch.
|
|
39
|
+
Errors use bounded public responses rather than exposing internal exceptions
|
|
40
|
+
or private evidence and provenance.
|
|
41
|
+
|
|
42
|
+
`createKnowledgeAgentHttp` and `createKnowledgeAgentMcp` expose that dispatcher
|
|
43
|
+
through host-configured protected endpoints. Both require fresh host
|
|
44
|
+
authentication and admission control on every request; neither issues tokens.
|
|
45
|
+
|
|
46
|
+
The [host composition contract](https://github.com/pegma-dev/knowledge-base/blob/main/docs/HOST_COMPOSITION.md)
|
|
47
|
+
describes authenticated contexts, trusted evidence, replay, and safe DTOs. The
|
|
48
|
+
[retrieval contract](https://github.com/pegma-dev/knowledge-base/blob/main/docs/RETRIEVAL.md)
|
|
49
|
+
describes authoritative current-publication confirmation and audience boundaries.
|
|
50
|
+
|
|
51
|
+
## Local verification and release
|
|
52
|
+
|
|
53
|
+
Repository development uses Node 22.6.0+ or 24 with pnpm 10.34.5:
|
|
54
|
+
|
|
55
|
+
```sh
|
|
56
|
+
pnpm install --frozen-lockfile
|
|
57
|
+
pnpm run format:check
|
|
58
|
+
pnpm run check
|
|
59
|
+
pnpm test
|
|
60
|
+
pnpm example
|
|
61
|
+
pnpm run release:check
|
|
62
|
+
pnpm run agent:proof
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
`release:check` packs and installs all four unpublished Knowledge Base packages
|
|
66
|
+
in an isolated temporary consumer, verifies their actual artifact bytes and
|
|
67
|
+
inventory, and imports their public entry points without workspace links.
|
|
68
|
+
`agent:proof` exercises the authenticated SDK path with a pinned public Agent
|
|
69
|
+
Access producer packed only into a temporary test consumer. That producer
|
|
70
|
+
source is a test fixture, not a production release substitute or package
|
|
71
|
+
dependency. These local checks establish neither live host acceptance nor npm
|
|
72
|
+
publication.
|
|
73
|
+
|
|
74
|
+
Each package has its own README, MIT LICENSE, build-on-prepack hook, and
|
|
75
|
+
compiled-test exclusion. All four package versions remain synchronized at
|
|
76
|
+
`0.1.0`. First publication, release tags, trusted-publisher configuration, and
|
|
77
|
+
host activation are separate maintainer operations in the
|
|
78
|
+
[release procedure](https://github.com/pegma-dev/knowledge-base/blob/main/docs/RELEASING.md).
|
|
79
|
+
Development links above track `main`; release preparation must pin verified
|
|
80
|
+
release documentation before first publication.
|
|
81
|
+
|
|
82
|
+
Built in the open by RetireGolden, LLC.
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type KnowledgeAgentDispatcher, type KnowledgeAgentDispatcherOptions } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* One versioned least-authority boundary shared by HTTP and MCP. Authentication,
|
|
4
|
+
* credential issuance, current access resolution, and rate limits are host work.
|
|
5
|
+
*/
|
|
6
|
+
export declare function createKnowledgeAgentDispatcher(options: KnowledgeAgentDispatcherOptions): KnowledgeAgentDispatcher;
|
|
7
|
+
//# sourceMappingURL=dispatcher.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dispatcher.d.ts","sourceRoot":"","sources":["../src/dispatcher.ts"],"names":[],"mappings":"AAaA,OAAO,EAEL,KAAK,wBAAwB,EAC7B,KAAK,+BAA+B,EAKrC,MAAM,YAAY,CAAC;AAyHpB;;;GAGG;AACH,wBAAgB,8BAA8B,CAC5C,OAAO,EAAE,+BAA+B,GACvC,wBAAwB,CA0E1B"}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { createKnowledgeAgentErrorResponse, KnowledgeAgentBoundaryError, mapKnowledgeAgentError, } from "./errors.js";
|
|
2
|
+
import { knowledgeAgentEnvelopeSchema, knowledgeAgentResultSchemas, resolveKnowledgeAgentLimits, snapshotKnowledgeAgentJson, } from "./schemas.js";
|
|
3
|
+
import { knowledgeAgentScopes, } from "./types.js";
|
|
4
|
+
const initialPermissions = Object.freeze(Object.values(knowledgeAgentScopes));
|
|
5
|
+
// Trusted host authority is independently bounded. Client payload array limits
|
|
6
|
+
// must not reject an administrator's broad context before it can be attenuated.
|
|
7
|
+
const maximumAuthorityItems = 256;
|
|
8
|
+
const maximumAuthorityCharacters = 1_024;
|
|
9
|
+
function own(value, key) {
|
|
10
|
+
if (value === null ||
|
|
11
|
+
typeof value !== "object" ||
|
|
12
|
+
![Object.prototype, null].includes(Object.getPrototypeOf(value))) {
|
|
13
|
+
throw new KnowledgeAgentBoundaryError("forbidden");
|
|
14
|
+
}
|
|
15
|
+
const descriptor = Object.getOwnPropertyDescriptor(value, key);
|
|
16
|
+
if (descriptor === undefined || !("value" in descriptor))
|
|
17
|
+
throw new KnowledgeAgentBoundaryError("forbidden");
|
|
18
|
+
return descriptor.value;
|
|
19
|
+
}
|
|
20
|
+
function trustedText(value, maximum) {
|
|
21
|
+
if (typeof value !== "string" ||
|
|
22
|
+
value.length === 0 ||
|
|
23
|
+
value.length > maximum ||
|
|
24
|
+
value.trim() !== value ||
|
|
25
|
+
/[\u0000-\u001f\u007f\ud800-\udfff]/u.test(value)) {
|
|
26
|
+
throw new KnowledgeAgentBoundaryError("forbidden");
|
|
27
|
+
}
|
|
28
|
+
return value;
|
|
29
|
+
}
|
|
30
|
+
function knownPermissions(value) {
|
|
31
|
+
if (!Array.isArray(value) ||
|
|
32
|
+
Object.getPrototypeOf(value) !== Array.prototype) {
|
|
33
|
+
throw new KnowledgeAgentBoundaryError("forbidden");
|
|
34
|
+
}
|
|
35
|
+
const length = Object.getOwnPropertyDescriptor(value, "length");
|
|
36
|
+
if (length === undefined ||
|
|
37
|
+
!("value" in length) ||
|
|
38
|
+
typeof length.value !== "number" ||
|
|
39
|
+
length.value > maximumAuthorityItems ||
|
|
40
|
+
Reflect.ownKeys(value).length !== length.value + 1) {
|
|
41
|
+
throw new KnowledgeAgentBoundaryError("forbidden");
|
|
42
|
+
}
|
|
43
|
+
const result = new Set();
|
|
44
|
+
for (let index = 0; index < length.value; index += 1) {
|
|
45
|
+
const descriptor = Object.getOwnPropertyDescriptor(value, String(index));
|
|
46
|
+
if (descriptor === undefined ||
|
|
47
|
+
!("value" in descriptor) ||
|
|
48
|
+
!descriptor.enumerable) {
|
|
49
|
+
throw new KnowledgeAgentBoundaryError("forbidden");
|
|
50
|
+
}
|
|
51
|
+
const permission = descriptor.value;
|
|
52
|
+
if (typeof permission !== "string" ||
|
|
53
|
+
permission.length > maximumAuthorityCharacters) {
|
|
54
|
+
throw new KnowledgeAgentBoundaryError("forbidden");
|
|
55
|
+
}
|
|
56
|
+
if (initialPermissions.some((known) => known === permission))
|
|
57
|
+
result.add(permission);
|
|
58
|
+
}
|
|
59
|
+
return result;
|
|
60
|
+
}
|
|
61
|
+
/** Snapshot the exact least-authority context without reading host role data. */
|
|
62
|
+
function effectiveAccess(identity, resource) {
|
|
63
|
+
if (trustedText(own(identity, "resource"), 2_048) !== resource)
|
|
64
|
+
throw new KnowledgeAgentBoundaryError("forbidden");
|
|
65
|
+
trustedText(own(identity, "clientId"), 200);
|
|
66
|
+
const scopes = knownPermissions(own(identity, "scopes"));
|
|
67
|
+
const access = own(identity, "access");
|
|
68
|
+
const principalId = trustedText(own(access, "principalId"), 200);
|
|
69
|
+
const policyVersion = trustedText(own(access, "policyVersion"), 200);
|
|
70
|
+
const currentPermissions = knownPermissions(own(access, "permissions"));
|
|
71
|
+
return Object.freeze({
|
|
72
|
+
principalId,
|
|
73
|
+
policyVersion,
|
|
74
|
+
roles: Object.freeze([]),
|
|
75
|
+
entitlements: Object.freeze([]),
|
|
76
|
+
permissions: Object.freeze(initialPermissions.filter((permission) => scopes.has(permission) && currentPermissions.has(permission))),
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
function requireOperation(access, operation) {
|
|
80
|
+
const has = (permission) => access.permissions.includes(permission);
|
|
81
|
+
const allowed = operation === "getValidationRequirements"
|
|
82
|
+
? has(knowledgeAgentScopes.draftWrite) ||
|
|
83
|
+
has(knowledgeAgentScopes.evidenceSubmit)
|
|
84
|
+
: has(operation === "getDraft"
|
|
85
|
+
? knowledgeAgentScopes.draftRead
|
|
86
|
+
: operation === "submitEvidence"
|
|
87
|
+
? knowledgeAgentScopes.evidenceSubmit
|
|
88
|
+
: knowledgeAgentScopes.draftWrite);
|
|
89
|
+
if (!allowed)
|
|
90
|
+
throw new KnowledgeAgentBoundaryError("forbidden");
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* One versioned least-authority boundary shared by HTTP and MCP. Authentication,
|
|
94
|
+
* credential issuance, current access resolution, and rate limits are host work.
|
|
95
|
+
*/
|
|
96
|
+
export function createKnowledgeAgentDispatcher(options) {
|
|
97
|
+
const limits = resolveKnowledgeAgentLimits(options.limits);
|
|
98
|
+
const resource = trustedText(options.resource, 2_048);
|
|
99
|
+
const application = options.application;
|
|
100
|
+
return Object.freeze({
|
|
101
|
+
limits,
|
|
102
|
+
async dispatch(identity, request) {
|
|
103
|
+
let operation = null;
|
|
104
|
+
try {
|
|
105
|
+
// All caller-owned objects are detached before the first application
|
|
106
|
+
// await. The application still performs current resource/replay checks.
|
|
107
|
+
const access = effectiveAccess(identity, resource);
|
|
108
|
+
const snapshot = snapshotKnowledgeAgentJson(request, limits);
|
|
109
|
+
const parsed = knowledgeAgentEnvelopeSchema.safeParse(snapshot);
|
|
110
|
+
if (!parsed.success)
|
|
111
|
+
throw new KnowledgeAgentBoundaryError("invalid_request");
|
|
112
|
+
const envelope = snapshotKnowledgeAgentJson(parsed.data, limits);
|
|
113
|
+
operation = envelope.operation;
|
|
114
|
+
requireOperation(access, operation);
|
|
115
|
+
let result;
|
|
116
|
+
switch (envelope.operation) {
|
|
117
|
+
case "getDraft":
|
|
118
|
+
result = await application.getDraft(access, envelope.input);
|
|
119
|
+
break;
|
|
120
|
+
case "createDraft":
|
|
121
|
+
result = await application.createDraft(access, envelope.input);
|
|
122
|
+
break;
|
|
123
|
+
case "updateDraft":
|
|
124
|
+
result = await application.updateDraft(access, envelope.input);
|
|
125
|
+
break;
|
|
126
|
+
case "getValidationRequirements":
|
|
127
|
+
result = await application.getValidationRequirements(access, envelope.input);
|
|
128
|
+
break;
|
|
129
|
+
case "submitEvidence":
|
|
130
|
+
result = await application.submitEvidence(access, envelope.input);
|
|
131
|
+
break;
|
|
132
|
+
}
|
|
133
|
+
let detached;
|
|
134
|
+
try {
|
|
135
|
+
detached = snapshotKnowledgeAgentJson(result, limits, limits.maxResponseBytes);
|
|
136
|
+
}
|
|
137
|
+
catch (error) {
|
|
138
|
+
if (error instanceof KnowledgeAgentBoundaryError &&
|
|
139
|
+
error.code === "capacity") {
|
|
140
|
+
throw error;
|
|
141
|
+
}
|
|
142
|
+
throw new KnowledgeAgentBoundaryError("unavailable");
|
|
143
|
+
}
|
|
144
|
+
const safe = knowledgeAgentResultSchemas[operation].safeParse(detached);
|
|
145
|
+
if (!safe.success)
|
|
146
|
+
throw new KnowledgeAgentBoundaryError("unavailable");
|
|
147
|
+
return snapshotKnowledgeAgentJson({ apiVersion: "1", operation, result: safe.data }, limits, limits.maxResponseBytes);
|
|
148
|
+
}
|
|
149
|
+
catch (error) {
|
|
150
|
+
return createKnowledgeAgentErrorResponse(mapKnowledgeAgentError(error).code, operation);
|
|
151
|
+
}
|
|
152
|
+
},
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
//# sourceMappingURL=dispatcher.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dispatcher.js","sourceRoot":"","sources":["../src/dispatcher.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,iCAAiC,EACjC,2BAA2B,EAC3B,sBAAsB,GACvB,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,4BAA4B,EAC5B,2BAA2B,EAC3B,2BAA2B,EAC3B,0BAA0B,GAC3B,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,oBAAoB,GAOrB,MAAM,YAAY,CAAC;AAEpB,MAAM,kBAAkB,GAAG,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,oBAAoB,CAAC,CAAC,CAAC;AAC9E,+EAA+E;AAC/E,gFAAgF;AAChF,MAAM,qBAAqB,GAAG,GAAG,CAAC;AAClC,MAAM,0BAA0B,GAAG,KAAK,CAAC;AAEzC,SAAS,GAAG,CAAC,KAAc,EAAE,GAAW;IACtC,IACE,KAAK,KAAK,IAAI;QACd,OAAO,KAAK,KAAK,QAAQ;QACzB,CAAC,CAAC,MAAM,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC,EAChE,CAAC;QACD,MAAM,IAAI,2BAA2B,CAAC,WAAW,CAAC,CAAC;IACrD,CAAC;IACD,MAAM,UAAU,GAAG,MAAM,CAAC,wBAAwB,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IAC/D,IAAI,UAAU,KAAK,SAAS,IAAI,CAAC,CAAC,OAAO,IAAI,UAAU,CAAC;QACtD,MAAM,IAAI,2BAA2B,CAA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entErrorCode, KnowledgeAgentFailure, KnowledgeAgentOperation } from "./types.js";
|
|
2
|
+
/** Internal classification only; never exposes an exception or its message. */
|
|
3
|
+
export declare class KnowledgeAgentBoundaryError extends Error {
|
|
4
|
+
readonly code: KnowledgeAgentErrorCode;
|
|
5
|
+
constructor(code: KnowledgeAgentErrorCode);
|
|
6
|
+
}
|
|
7
|
+
/** Unknown application/storage/verifier failures become content-free 503s. */
|
|
8
|
+
export declare function mapKnowledgeAgentError(error: unknown): KnowledgeAgentError;
|
|
9
|
+
export declare function createKnowledgeAgentErrorResponse(code: KnowledgeAgentErrorCode, operation?: KnowledgeAgentOperation | null): KnowledgeAgentFailure;
|
|
10
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EACV,mBAAmB,EACnB,uBAAuB,EACvB,qBAAqB,EACrB,uBAAuB,EACxB,MAAM,YAAY,CAAC;AAyCpB,+EAA+E;AAC/E,qBAAa,2BAA4B,SAAQ,KAAK;IACxC,QAAQ,CAAC,IAAI,EAAE,uBAAuB;IAAlD,YAAqB,IAAI,EAAE,uBAAuB,EAGjD;CACF;AAED,8EAA8E;AAC9E,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,OAAO,GAAG,mBAAmB,CAc1E;AAED,wBAAgB,iCAAiC,CAC/C,IAAI,EAAE,uBAAuB,EAC7B,SAAS,GAAE,uBAAuB,GAAG,IAAW,GAC/C,qBAAqB,CAEvB"}
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { KnowledgeBaseAuthorizationError, KnowledgeBaseNotFoundError, KnowledgeBasePrerequisiteError, RepositoryCapacityError, RepositoryConflictError, } from "@pegma/knowledge-base-application";
|
|
2
|
+
import { KnowledgeBaseError } from "@pegma/knowledge-base-core";
|
|
3
|
+
const errors = Object.freeze({
|
|
4
|
+
invalid_request: Object.freeze({
|
|
5
|
+
code: "invalid_request",
|
|
6
|
+
status: 400,
|
|
7
|
+
message: "Invalid knowledge request.",
|
|
8
|
+
}),
|
|
9
|
+
forbidden: Object.freeze({
|
|
10
|
+
code: "forbidden",
|
|
11
|
+
status: 403,
|
|
12
|
+
message: "Knowledge access is forbidden.",
|
|
13
|
+
}),
|
|
14
|
+
not_found: Object.freeze({
|
|
15
|
+
code: "not_found",
|
|
16
|
+
status: 404,
|
|
17
|
+
message: "Knowledge resource is unavailable.",
|
|
18
|
+
}),
|
|
19
|
+
conflict: Object.freeze({
|
|
20
|
+
code: "conflict",
|
|
21
|
+
status: 409,
|
|
22
|
+
message: "Knowledge command conflicts with current state.",
|
|
23
|
+
}),
|
|
24
|
+
capacity: Object.freeze({
|
|
25
|
+
code: "capacity",
|
|
26
|
+
status: 413,
|
|
27
|
+
message: "Knowledge request or result exceeds capacity.",
|
|
28
|
+
}),
|
|
29
|
+
prerequisite: Object.freeze({
|
|
30
|
+
code: "prerequisite",
|
|
31
|
+
status: 412,
|
|
32
|
+
message: "Knowledge prerequisite is not ready.",
|
|
33
|
+
}),
|
|
34
|
+
unavailable: Object.freeze({
|
|
35
|
+
code: "unavailable",
|
|
36
|
+
status: 503,
|
|
37
|
+
message: "Knowledge service is unavailable.",
|
|
38
|
+
}),
|
|
39
|
+
});
|
|
40
|
+
/** Internal classification only; never exposes an exception or its message. */
|
|
41
|
+
export class KnowledgeAgentBoundaryError extends Error {
|
|
42
|
+
code;
|
|
43
|
+
constructor(code) {
|
|
44
|
+
super("Knowledge agent boundary rejected data");
|
|
45
|
+
this.code = code;
|
|
46
|
+
this.name = "KnowledgeAgentBoundaryError";
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
/** Unknown application/storage/verifier failures become content-free 503s. */
|
|
50
|
+
export function mapKnowledgeAgentError(error) {
|
|
51
|
+
if (error instanceof KnowledgeAgentBoundaryError)
|
|
52
|
+
return errors[error.code];
|
|
53
|
+
if (error instanceof KnowledgeBaseAuthorizationError)
|
|
54
|
+
return errors.forbidden;
|
|
55
|
+
if (error instanceof KnowledgeBaseNotFoundError)
|
|
56
|
+
return errors.not_found;
|
|
57
|
+
if (error instanceof RepositoryConflictError)
|
|
58
|
+
return errors.conflict;
|
|
59
|
+
if (error instanceof RepositoryCapacityError)
|
|
60
|
+
return errors.capacity;
|
|
61
|
+
if (error instanceof KnowledgeBasePrerequisiteError)
|
|
62
|
+
return errors.prerequisite;
|
|
63
|
+
if (error instanceof KnowledgeBaseError) {
|
|
64
|
+
if (error.code === "invalid")
|
|
65
|
+
return errors.invalid_request;
|
|
66
|
+
if (error.code === "conflict")
|
|
67
|
+
return errors.conflict;
|
|
68
|
+
return errors.prerequisite;
|
|
69
|
+
}
|
|
70
|
+
return errors.unavailable;
|
|
71
|
+
}
|
|
72
|
+
export function createKnowledgeAgentErrorResponse(code, operation = null) {
|
|
73
|
+
return Object.freeze({ apiVersion: "1", operation, error: errors[code] });
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,+BAA+B,EAC/B,0BAA0B,EAC1B,8BAA8B,EAC9B,uBAAuB,EACvB,uBAAuB,GACxB,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAShE,MAAM,MAAM,GACV,MAAM,CAAC,MAAM,CAAC;IACZ,eAAe,EAAE,MAAM,CAAC,MAAM,CAAC;QAC7B,IAAI,EAAE,iBAAiB;QACvB,MAAM,EAAE,GAAG;QACX,OAAO,EAAE,4BAA4B;KACtC,CAAC;IACF,SAAS,EAAE,MAAM,CAAC,MAAM,CAAC;QACvB,IAAI,EAAE,WAAW;QACjB,MAAM,EAAE,GAAG;QACX,OAAO,EAAE,gCAAgC;KAC1C,CAAC;IACF,SA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AuB;QAAE,OAAO,MAAM,CAAC,QAAQ,CAAC;IACrE,IAAI,KAAK,YAAY,8BAA8B;QACjD,OAAO,MAAM,CAAC,YAAY,CAAC;IAC7B,IAAI,KAAK,YAAY,kBAAkB,EAAE,CAAC;QACxC,IAAI,KAAK,CAAC,IAAI,KAAK,SAAS;YAAE,OAAO,MAAM,CAAC,eAAe,CAAC;QAC5D,IAAI,KAAK,CAAC,IAAI,KAAK,UAAU;YAAE,OAAO,MAAM,CAAC,QAAQ,CAAC;QACtD,OAAO,MAAM,CAAC,YAAY,CAAC;IAC7B,CAAC;IACD,OAAO,MAAM,CAAC,WAAW,CAAC;AAC5B,CAAC;AAED,MAAM,UAAU,iCAAiC,CAC/C,IAA6B,EAC7B,SAAS,GAAmC,IAAI;IAEhD,OAAO,MAAM,CAAC,MAAM,CAAC,EAAE,UAAU,EAAE,GAAG,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AAC5E,CAAC"}
|
package/dist/http.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { KnowledgeAgentDispatcher } from "./types.js";
|
|
2
|
+
import type { KnowledgeAgentTransportOptions } from "./transport-common.js";
|
|
3
|
+
export interface KnowledgeAgentHttpOptions extends KnowledgeAgentTransportOptions {
|
|
4
|
+
/** Exact canonical versioned API URL; the protected resource remains MCP. */
|
|
5
|
+
readonly apiUrl: string;
|
|
6
|
+
readonly dispatcher: KnowledgeAgentDispatcher;
|
|
7
|
+
}
|
|
8
|
+
export interface KnowledgeAgentHttp {
|
|
9
|
+
/** Null leaves unmatched paths to the host's router. */
|
|
10
|
+
handle(request: Request): Promise<Response | null>;
|
|
11
|
+
}
|
|
12
|
+
/** Portable Fetch adapter: host credentials and admission, shared application law. */
|
|
13
|
+
export declare function createKnowledgeAgentHttp(options: KnowledgeAgentHttpOptions): KnowledgeAgentHttp;
|
|
14
|
+
//# sourceMappingURL=http.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../src/http.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,YAAY,CAAC;AAU3D,OAAO,KAAK,EAAE,8BAA8B,EAAE,MAAM,uBAAuB,CAAC;AAE5E,MAAM,WAAW,yBAA0B,SAAQ,8BAA8B;IAC/E,6EAA6E;IAC7E,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,UAAU,EAAE,wBAAwB,CAAC;CAC/C;AAED,MAAM,WAAW,kBAAkB;IACjC,wDAAwD;IACxD,MAAM,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC,CAAC;CACpD;AAED,sFAAsF;AACtF,wBAAgB,wBAAwB,CACtC,OAAO,EAAE,yBAAyB,GACjC,kBAAkB,CA6CpB"}
|
package/dist/http.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { authorizeKnowledgeAgentRequest, knowledgeAgentJsonResponse, knowledgeAgentRequestMatches, knowledgeAgentTransportError, readKnowledgeAgentJsonRequest, secureKnowledgeAgentResponse, validateKnowledgeAgentTransportOptions, } from "./transport-common.js";
|
|
2
|
+
/** Portable Fetch adapter: host credentials and admission, shared application law. */
|
|
3
|
+
export function createKnowledgeAgentHttp(options) {
|
|
4
|
+
const configuration = validateKnowledgeAgentTransportOptions(options, options.apiUrl, "http");
|
|
5
|
+
const dispatcher = options.dispatcher;
|
|
6
|
+
return Object.freeze({
|
|
7
|
+
async handle(request) {
|
|
8
|
+
if (!knowledgeAgentRequestMatches(request, configuration))
|
|
9
|
+
return null;
|
|
10
|
+
const identity = await authorizeKnowledgeAgentRequest(request, configuration);
|
|
11
|
+
if (identity instanceof Response)
|
|
12
|
+
return identity;
|
|
13
|
+
if (request.method !== "POST")
|
|
14
|
+
return knowledgeAgentTransportError("method_not_allowed", request, configuration);
|
|
15
|
+
const parsed = await readKnowledgeAgentJsonRequest(request, dispatcher.limits);
|
|
16
|
+
if (parsed instanceof Response)
|
|
17
|
+
return secureKnowledgeAgentResponse(parsed, request, configuration);
|
|
18
|
+
try {
|
|
19
|
+
const response = await dispatcher.dispatch(identity, parsed.value);
|
|
20
|
+
return knowledgeAgentJsonResponse(response, "error" in response ? response.error.status : 200, dispatcher.limits.maxResponseBytes, request, configuration);
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
return knowledgeAgentTransportError("unavailable", request, configuration);
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=http.js.map
|
package/dist/http.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.js","sourceRoot":"","sources":["../src/http.ts"],"names":[],"mappings":"AACA,OAAO,EACL,8BAA8B,EAC9B,0BAA0B,EAC1B,4BAA4B,EAC5B,4BAA4B,EAC5B,6BAA6B,EAC7B,4BAA4B,EAC5B,sCAAsC,GACvC,MAAM,uBAAuB,CAAC;AAc/B,sFAAsF;AACtF,MAAM,UAAU,wBAAwB,CACtC,OAAkC;IAElC,MAAM,aAAa,GAAG,sCAAsC,CAC1D,OAAO,EACP,OAAO,CAAC,MAAM,EACd,MAAM,CACP,CAAC;IACF,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;IACtC,OAAO,MAAM,CAAC,MAAM,CAAC;QACnB,KAAK,CAAC,MAAM,CAAC,OAAgB;YAC3B,IAAI,CAAC,4BAA4B,CAAC,OAAO,EAAE,aAAa,CAAC;gBAAE,OAAO,IAAI,CAAC;YACvE,MAAM,QAAQ,GAAG,MAAM,8BAA8B,CACnD,OAAO,EACP,aAAa,CACd,CAAC;YACF,IAAI,QAAQ,YAAY,QAAQ;gBAAE,OAAO,QAAQ,CAAC;YAClD,IAAI,OAAO,CAAC,MAAM,KAAK,MAAM;gBAC3B,OAAO,4BAA4B,CACjC,oBAAoB,EACpB,OAAO,EACP,aAAa,CACd,CAAC;YACJ,MAAM,MAAM,GAAG,MAAM,6BAA6B,CAChD,OAAO,EACP,UAAU,CAAC,MAAM,CAClB,CAAC;YACF,IAAI,MAAM,YAAY,QAAQ;gBAC5B,OAAO,4BAA4B,CAAC,MAAM,EAAE,OAAO,EAAE,aAAa,CAAC,CAAC;YACtE,IAAI,CAAC;gBACH,MAAM,QAAQ,GAAG,MAAM,UAAU,CAAC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC;gBACnE,OAAO,0BAA0B,CAC/B,QAAQ,EACR,OAAO,IAAI,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,EACjD,UAAU,CAAC,MAAM,CAAC,gBAAgB,EAClC,OAAO,EACP,aAAa,CACd,CAAC;YACJ,CAAC;YAAC,MAAM,CAAC;gBACP,OAAO,4BAA4B,CACjC,aAAa,EACb,OAAO,EACP,aAAa,CACd,CAAC;YACJ,CAAC;QACH,CAAC;KACF,CAAC,CAAC;AACL,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { createKnowledgeAgentDispatcher } from "./dispatcher.js";
|
|
2
|
+
export { createKnowledgeAgentHttp } from "./http.js";
|
|
3
|
+
export { createKnowledgeAgentMcp } from "./mcp.js";
|
|
4
|
+
export { defaultKnowledgeAgentLimits, knowledgeAgentOperations, knowledgeAgentScopes, knowledgeAgentToolNames, } from "./types.js";
|
|
5
|
+
export type * from "./types.js";
|
|
6
|
+
export type * from "./http.js";
|
|
7
|
+
export type * from "./mcp.js";
|
|
8
|
+
export type { KnowledgeAgentLimitDecision, KnowledgeAgentTransport, KnowledgeAgentTransportOptions, } from "./transport-common.js";
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,8BAA8B,EAAE,MAAM,iBAAiB,CAAC;AACjE,OAAO,EAAE,wBAAwB,EAAE,MAAM,WAAW,CAAC;AACrD,OAAO,EAAE,uBAAuB,EAAE,MAAM,UAAU,CAAC;AACnD,OAAO,EACL,2BAA2B,EAC3B,wBAAwB,EACxB,oBAAoB,EACpB,uBAAuB,GACxB,MAAM,YAAY,CAAC;AACpB,mBAAmB,YAAY,CAAC;AAChC,mBAAmB,WAAW,CAAC;AAC/B,mBAAmB,UAAU,CAAC;AAC9B,YAAY,EACV,2BAA2B,EAC3B,uBAAuB,EACvB,8BAA8B,GAC/B,MAAM,uBAAuB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { createKnowledgeAgentDispatcher } from "./dispatcher.js";
|
|
2
|
+
export { createKnowledgeAgentHttp } from "./http.js";
|
|
3
|
+
export { createKnowledgeAgentMcp } from "./mcp.js";
|
|
4
|
+
export { defaultKnowledgeAgentLimits, knowledgeAgentOperations, knowledgeAgentScopes, knowledgeAgentToolNames, } from "./types.js";
|
|
5
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,8BAA8B,EAAE,MAAM,iBAAiB,CAAC;AACjE,OAAO,EAAE,wBAAwB,EAAE,MAAM,WAAW,CAAC;AACrD,OAAO,EAAE,uBAAuB,EAAE,MAAM,UAAU,CAAC;AACnD,OAAO,EACL,2BAA2B,EAC3B,wBAAwB,EACxB,oBAAoB,EACpB,uBAAuB,GACxB,MAAM,YAAY,CAAC"}
|
package/dist/mcp.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type KnowledgeAgentTransportOptions } from "./transport-common.js";
|
|
2
|
+
import { type KnowledgeAgentDispatcher } from "./types.js";
|
|
3
|
+
export interface KnowledgeAgentMcpOptions extends KnowledgeAgentTransportOptions {
|
|
4
|
+
/** Exact MCP endpoint; it must equal the canonical protected resource. */
|
|
5
|
+
readonly mcpUrl: string;
|
|
6
|
+
readonly dispatcher: KnowledgeAgentDispatcher;
|
|
7
|
+
}
|
|
8
|
+
export interface KnowledgeAgentMcp {
|
|
9
|
+
/** Null leaves unmatched paths to the host's router. */
|
|
10
|
+
handle(request: Request): Promise<Response | null>;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Stateless, JSON-response Streamable HTTP. Every request resolves fresh host
|
|
14
|
+
* authority and owns a short-lived SDK server; no session or credential is cached.
|
|
15
|
+
*/
|
|
16
|
+
export declare function createKnowledgeAgentMcp(options: KnowledgeAgentMcpOptions): KnowledgeAgentMcp;
|
|
17
|
+
//# sourceMappingURL=mcp.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp.d.ts","sourceRoot":"","sources":["../src/mcp.ts"],"names":[],"mappings":"AAmBA,OAAO,EAQL,KAAK,8BAA8B,EACpC,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAGL,KAAK,wBAAwB,EAG9B,MAAM,YAAY,CAAC;AAEpB,MAAM,WAAW,wBAAyB,SAAQ,8BAA8B;IAC9E,0EAA0E;IAC1E,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,UAAU,EAAE,wBAAwB,CAAC;CAC/C;AAED,MAAM,WAAW,iBAAiB;IAChC,wDAAwD;IACxD,MAAM,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC,CAAC;CACpD;AAyND;;;GAGG;AACH,wBAAgB,uBAAuB,CACrC,OAAO,EAAE,wBAAwB,GAChC,iBAAiB,CAuJnB"}
|