@kya-os/mcp-i-runtime 1.0.0 → 1.2.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/.turbo/turbo-build.log +1 -1
- package/dist/config.d.ts +5 -7
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +4 -6
- package/dist/config.js.map +1 -1
- package/dist/index.d.ts +4 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +16 -2
- package/dist/index.js.map +1 -1
- package/dist/runtime/audit-logger.d.ts +6 -28
- package/dist/runtime/audit-logger.d.ts.map +1 -1
- package/dist/runtime/audit-logger.js +5 -3
- package/dist/runtime/audit-logger.js.map +1 -1
- package/dist/runtime/audit.d.ts +132 -0
- package/dist/runtime/audit.d.ts.map +1 -0
- package/dist/runtime/audit.js +424 -0
- package/dist/runtime/audit.js.map +1 -0
- package/dist/runtime/base.d.ts +9 -48
- package/dist/runtime/base.d.ts.map +1 -1
- package/dist/runtime/base.js +109 -89
- package/dist/runtime/base.js.map +1 -1
- package/dist/runtime/needs-authorization.d.ts +33 -0
- package/dist/runtime/needs-authorization.d.ts.map +1 -0
- package/dist/runtime/needs-authorization.js +43 -0
- package/dist/runtime/needs-authorization.js.map +1 -0
- package/dist/services/oauth-config.service.d.ts.map +1 -1
- package/dist/services/oauth-config.service.js +29 -0
- package/dist/services/oauth-config.service.js.map +1 -1
- package/package.json +7 -3
- package/src/__tests__/config/provider-runtime-config.test.ts +2 -9
- package/src/__tests__/config.test.ts +12 -11
- package/src/__tests__/integration/full-flow.test.ts +0 -5
- package/src/__tests__/integration.test.ts +2 -6
- package/src/__tests__/runtime/audit.test.ts +327 -0
- package/src/__tests__/runtime/base-extensions.test.ts +0 -46
- package/src/__tests__/runtime/base.test.ts +71 -102
- package/src/__tests__/runtime/delegation-flow.test.ts +0 -4
- package/src/__tests__/runtime/process-tool-call-security.test.ts +5 -11
- package/src/__tests__/runtime/proof-client-did.test.ts +0 -4
- package/src/__tests__/runtime/provider-selection.test.ts +0 -2
- package/src/__tests__/runtime/route-interception.test.ts +7 -4
- package/src/__tests__/runtime/tool-protection-enforcement.test.ts +23 -31
- package/src/__tests__/services/tool-protection-merged-config.test.ts +0 -40
- package/src/config/__tests__/merged-config.spec.ts +0 -26
- package/src/config.ts +9 -10
- package/src/index.ts +30 -5
- package/src/runtime/__tests__/audit-logger-compat.test.ts +15 -0
- package/src/runtime/__tests__/needs-authorization.test.ts +41 -0
- package/src/runtime/audit-logger.ts +6 -29
- package/src/runtime/audit.ts +598 -0
- package/src/runtime/base.ts +154 -99
- package/src/runtime/needs-authorization.ts +47 -0
- package/src/services/__tests__/oauth-config.service.test.ts +66 -0
- package/src/services/__tests__/proof-verifier.integration.test.ts +1 -1
- package/src/services/__tests__/proof-verifier.test.ts +6 -3
- package/src/services/oauth-config.service.ts +44 -1
- package/src/__tests__/runtime/audit-logger.test.ts +0 -154
package/src/config.ts
CHANGED
|
@@ -25,6 +25,7 @@ import type {
|
|
|
25
25
|
} from './providers/base';
|
|
26
26
|
|
|
27
27
|
import type { ToolProtectionService } from './services/tool-protection.service';
|
|
28
|
+
import type { RuntimeAuditConfig } from './runtime/audit';
|
|
28
29
|
|
|
29
30
|
/**
|
|
30
31
|
* Provider-based runtime configuration
|
|
@@ -35,6 +36,9 @@ import type { ToolProtectionService } from './services/tool-protection.service';
|
|
|
35
36
|
* for Node.js, Cloudflare Workers, and other environments.
|
|
36
37
|
*/
|
|
37
38
|
export interface ProviderRuntimeConfig extends MCPIBaseConfig {
|
|
39
|
+
/** Canonical KYA-OS audit trail integration. */
|
|
40
|
+
auditTrail?: RuntimeAuditConfig;
|
|
41
|
+
|
|
38
42
|
/**
|
|
39
43
|
* Cryptographic operations provider
|
|
40
44
|
* Handles signing, verification, and key generation
|
|
@@ -204,14 +208,9 @@ export class ProviderRuntimeConfigBuilder {
|
|
|
204
208
|
return this;
|
|
205
209
|
}
|
|
206
210
|
|
|
207
|
-
/**
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
withAudit(audit: {
|
|
211
|
-
enabled: boolean;
|
|
212
|
-
includeProofHashes?: boolean;
|
|
213
|
-
}): this {
|
|
214
|
-
this.config.audit = audit;
|
|
211
|
+
/** Configure the canonical KYA-OS audit trail. */
|
|
212
|
+
withAuditTrail(auditTrail: RuntimeAuditConfig | undefined): this {
|
|
213
|
+
this.config.auditTrail = auditTrail;
|
|
215
214
|
return this;
|
|
216
215
|
}
|
|
217
216
|
|
|
@@ -306,7 +305,7 @@ export function createProviderRuntimeConfig(
|
|
|
306
305
|
enabled: false,
|
|
307
306
|
verifier: { type: 'memory' }
|
|
308
307
|
})
|
|
309
|
-
.
|
|
308
|
+
.withAuditTrail(options?.auditTrail)
|
|
310
309
|
.withWellKnown(options?.wellKnown || { enabled: true })
|
|
311
310
|
.build();
|
|
312
|
-
}
|
|
311
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -45,8 +45,32 @@ export {
|
|
|
45
45
|
type WireForm,
|
|
46
46
|
} from "./wire-format";
|
|
47
47
|
|
|
48
|
-
//
|
|
49
|
-
export
|
|
48
|
+
// C4 (#2918) 3c envelope flip — DelegationRequiredError → needs_authorization mapper.
|
|
49
|
+
export { toNeedsAuthorization } from "./runtime/needs-authorization";
|
|
50
|
+
|
|
51
|
+
// Canonical KYA-OS audit trail integration
|
|
52
|
+
export {
|
|
53
|
+
RuntimeToolAuditInvocation,
|
|
54
|
+
attachRuntimeAuditMetadata,
|
|
55
|
+
beginRuntimeToolAudit,
|
|
56
|
+
createHmacRuntimeAuditContextFactory,
|
|
57
|
+
recordRuntimeConsentAudit,
|
|
58
|
+
recordRuntimeDelegationAudit,
|
|
59
|
+
terminalForToolError,
|
|
60
|
+
terminalForToolResult,
|
|
61
|
+
} from "./runtime/audit";
|
|
62
|
+
export type {
|
|
63
|
+
HmacRuntimeAuditContextOptions,
|
|
64
|
+
RuntimeAuditCallContext,
|
|
65
|
+
RuntimeAuditConfig,
|
|
66
|
+
RuntimeAuditContextFactory,
|
|
67
|
+
RuntimeAuditToolInput,
|
|
68
|
+
RuntimeAuditTrailPort,
|
|
69
|
+
RuntimeConsentAuditInput,
|
|
70
|
+
RuntimeDelegationAuditInput,
|
|
71
|
+
RuntimeToolTerminal,
|
|
72
|
+
RuntimeToolTerminalPhase,
|
|
73
|
+
} from "./runtime/audit";
|
|
50
74
|
|
|
51
75
|
// Utilities
|
|
52
76
|
export * from "./utils";
|
|
@@ -104,7 +128,10 @@ export type { OAuthConfigServiceConfig } from "./services/oauth-config.service";
|
|
|
104
128
|
// OAuth Service (Phase 1)
|
|
105
129
|
export { OAuthService, defaultSecretResolver } from "./services/oauth-service";
|
|
106
130
|
|
|
107
|
-
export type {
|
|
131
|
+
export type {
|
|
132
|
+
OAuthServiceConfig,
|
|
133
|
+
SecretResolver,
|
|
134
|
+
} from "./services/oauth-service";
|
|
108
135
|
|
|
109
136
|
// Tool Context Builder (Phase 1)
|
|
110
137
|
export { ToolContextBuilder } from "./services/tool-context-builder";
|
|
@@ -192,7 +219,6 @@ export type {
|
|
|
192
219
|
ClientMessagesConfig,
|
|
193
220
|
} from "./services/delegation-error-formatter";
|
|
194
221
|
|
|
195
|
-
|
|
196
222
|
// Base58 Utilities (for did:key encoding/decoding)
|
|
197
223
|
export { base58Encode, base58Decode, isValidBase58 } from "./utils/base58";
|
|
198
224
|
|
|
@@ -215,7 +241,6 @@ export {
|
|
|
215
241
|
getSchemaStats,
|
|
216
242
|
} from "./compliance/schema-registry";
|
|
217
243
|
|
|
218
|
-
|
|
219
244
|
// Base64 utilities for VC JWT encoding
|
|
220
245
|
export {
|
|
221
246
|
base64urlEncodeFromBytes,
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { describe, expectTypeOf, it } from "vitest";
|
|
2
|
+
|
|
3
|
+
import type { AuditContext, AuditEventContext } from "@kya-os/contracts/audit";
|
|
4
|
+
import type { IAuditLogger } from "../audit-logger.js";
|
|
5
|
+
|
|
6
|
+
describe("legacy audit logger compatibility", () => {
|
|
7
|
+
it("keeps the published type-only interface during the minor train", () => {
|
|
8
|
+
expectTypeOf<IAuditLogger["logAuditRecord"]>().toEqualTypeOf<
|
|
9
|
+
(context: AuditContext) => Promise<void>
|
|
10
|
+
>();
|
|
11
|
+
expectTypeOf<IAuditLogger["logEvent"]>().toEqualTypeOf<
|
|
12
|
+
(context: AuditEventContext) => Promise<void>
|
|
13
|
+
>();
|
|
14
|
+
});
|
|
15
|
+
});
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* C4 (#2918) 3c envelope flip — mapper unit tests.
|
|
3
|
+
*
|
|
4
|
+
* `toNeedsAuthorization` projects the internal `DelegationRequiredError` control-flow
|
|
5
|
+
* signal onto the ratified DIF `needs_authorization` envelope. Envelope-flip ONLY —
|
|
6
|
+
* N-of-M step-up (`needs_approval`) is deferred to T3-edge #3222.
|
|
7
|
+
*/
|
|
8
|
+
import { describe, it, expect } from "vitest";
|
|
9
|
+
import { isNeedsAuthorizationError } from "@kya-os/contracts/runtime";
|
|
10
|
+
import { DelegationRequiredError } from "../../types/tool-protection.js";
|
|
11
|
+
import { toNeedsAuthorization } from "../needs-authorization.js";
|
|
12
|
+
|
|
13
|
+
describe("toNeedsAuthorization", () => {
|
|
14
|
+
const makeErr = () =>
|
|
15
|
+
new DelegationRequiredError(
|
|
16
|
+
"checkout",
|
|
17
|
+
["cart:write", "payment:process"],
|
|
18
|
+
"https://consent.example.com/authorize?resume_token=abc",
|
|
19
|
+
undefined,
|
|
20
|
+
"resume_abc123"
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
it("projects DelegationRequiredError onto the ratified needs_authorization envelope", () => {
|
|
24
|
+
const expiresAt = 1_900_000_000_000; // ms epoch (calculateExpiry returns ms)
|
|
25
|
+
const out = toNeedsAuthorization(makeErr(), expiresAt);
|
|
26
|
+
|
|
27
|
+
expect(out.error).toBe("needs_authorization");
|
|
28
|
+
expect(out.message).toMatch(/checkout/);
|
|
29
|
+
expect(out.authorizationUrl).toBe(
|
|
30
|
+
"https://consent.example.com/authorize?resume_token=abc"
|
|
31
|
+
);
|
|
32
|
+
expect(out.resumeToken).toBe("resume_abc123");
|
|
33
|
+
expect(out.expiresAt).toBe(expiresAt);
|
|
34
|
+
expect(out.scopes).toEqual(["cart:write", "payment:process"]);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it("produces an envelope that satisfies isNeedsAuthorizationError", () => {
|
|
38
|
+
const out = toNeedsAuthorization(makeErr(), Date.now() + 1_800_000);
|
|
39
|
+
expect(isNeedsAuthorizationError(out)).toBe(true);
|
|
40
|
+
});
|
|
41
|
+
});
|
|
@@ -1,39 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Legacy diagnostic-audit logger interface.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
4
|
+
* @deprecated New integrations must implement `RuntimeAuditTrailPort` from
|
|
5
|
+
* `@kya-os/mcp-i-runtime/runtime/audit` and use the canonical protocol from
|
|
6
|
+
* `@kya-os/mcp/audit`. This type-only shim preserves the published import path
|
|
7
|
+
* without retaining a second audit implementation.
|
|
6
8
|
*/
|
|
7
9
|
|
|
8
10
|
import type { AuditContext, AuditEventContext } from "@kya-os/contracts/audit";
|
|
9
11
|
|
|
10
|
-
/**
|
|
11
|
-
* Interface for audit logging implementations
|
|
12
|
-
*
|
|
13
|
-
* This interface is platform-agnostic and can be implemented by:
|
|
14
|
-
* - Node.js implementations (using Node.js crypto)
|
|
15
|
-
* - Cloudflare Workers implementations (using Web Crypto API)
|
|
16
|
-
* - Other platform-specific implementations
|
|
17
|
-
*/
|
|
12
|
+
/** @deprecated Implement `RuntimeAuditTrailPort` for canonical audit events. */
|
|
18
13
|
export interface IAuditLogger {
|
|
19
|
-
/**
|
|
20
|
-
* Log an audit record (with session deduplication)
|
|
21
|
-
*
|
|
22
|
-
* This method logs audit records using the frozen audit.v1 format.
|
|
23
|
-
* Only the first call per session is logged (deduplication).
|
|
24
|
-
*
|
|
25
|
-
* @param context - Audit context with identity, session, hashes, and verification status
|
|
26
|
-
*/
|
|
27
14
|
logAuditRecord(context: AuditContext): Promise<void>;
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Log an event (without session deduplication)
|
|
31
|
-
*
|
|
32
|
-
* This method logs events using the frozen audit.v1 format.
|
|
33
|
-
* Unlike logAuditRecord(), this always logs the event, allowing
|
|
34
|
-
* multiple events per session (e.g., consent events).
|
|
35
|
-
*
|
|
36
|
-
* @param context - Event context with eventType, identity, session, and optional eventData
|
|
37
|
-
*/
|
|
38
15
|
logEvent(context: AuditEventContext): Promise<void>;
|
|
39
16
|
}
|