@kya-os/mcp-i 1.10.0 → 1.11.1

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 (51) hide show
  1. package/dist/317.js +1 -0
  2. package/dist/342.js +1 -0
  3. package/dist/354.js +1 -1
  4. package/dist/95.js +1 -1
  5. package/dist/auth/oauth/router.js +2 -2
  6. package/dist/cli-adapter/index.js +1 -1
  7. package/dist/providers/node-providers.d.ts +1 -1
  8. package/dist/providers/node-providers.js +9 -9
  9. package/dist/runtime/337.js +1 -0
  10. package/dist/runtime/adapter-express.js +3 -3
  11. package/dist/runtime/adapter-nextjs.js +5 -5
  12. package/dist/runtime/audit.d.ts +1 -1
  13. package/dist/runtime/auth-handshake.d.ts +1 -1
  14. package/dist/runtime/auth-handshake.js +4 -4
  15. package/dist/runtime/debug.d.ts +1 -1
  16. package/dist/runtime/debug.js +3 -2
  17. package/dist/runtime/delegation-hooks.d.ts +1 -1
  18. package/dist/runtime/delegation-verifier-agentshield.js +1 -0
  19. package/dist/runtime/http.js +3 -3
  20. package/dist/runtime/identity.d.ts +4 -4
  21. package/dist/runtime/identity.js +4 -4
  22. package/dist/runtime/index.d.ts +6 -2
  23. package/dist/runtime/index.js +10 -2
  24. package/dist/runtime/mcpi-runtime-wrapper.d.ts +1 -1
  25. package/dist/runtime/mcpi-runtime-wrapper.js +4 -4
  26. package/dist/runtime/mcpi-runtime.d.ts +9 -1
  27. package/dist/runtime/mcpi-runtime.js +21 -3
  28. package/dist/runtime/outbound-delegation.d.ts +5 -3
  29. package/dist/runtime/outbound-delegation.js +15 -8
  30. package/dist/runtime/outbound-identity-bridge.d.ts +40 -0
  31. package/dist/runtime/outbound-identity-bridge.js +119 -0
  32. package/dist/runtime/proof-batch-queue.d.ts +1 -1
  33. package/dist/runtime/proof.d.ts +2 -2
  34. package/dist/runtime/proof.js +3 -3
  35. package/dist/runtime/request-context.d.ts +10 -0
  36. package/dist/runtime/request-context.js +4 -0
  37. package/dist/runtime/resume-token-store-kv.d.ts +44 -0
  38. package/dist/runtime/resume-token-store-kv.js +93 -0
  39. package/dist/runtime/resume-token-store.d.ts +30 -0
  40. package/dist/runtime/resume-token-store.js +46 -0
  41. package/dist/runtime/session.d.ts +2 -2
  42. package/dist/runtime/session.js +12 -6
  43. package/dist/runtime/stdio.js +3 -3
  44. package/dist/runtime/utils/tools.d.ts +2 -2
  45. package/dist/runtime/utils/tools.js +33 -10
  46. package/dist/runtime/well-known.d.ts +12 -1
  47. package/dist/runtime/well-known.js +13 -2
  48. package/package.json +6 -4
  49. package/dist/225.js +0 -1
  50. package/dist/runtime/verifier-middleware.d.ts +0 -99
  51. package/dist/runtime/verifier-middleware.js +0 -416
@@ -0,0 +1,93 @@
1
+ "use strict";
2
+ /**
3
+ * Cloudflare KV Resume Token Store
4
+ *
5
+ * Durable resume-token store backed by a Cloudflare Workers KV namespace, so a
6
+ * resume token minted at consent time survives cold starts, process restarts,
7
+ * and multi-instance deployments (the failure mode the in-memory store causes —
8
+ * the user gets re-prompted because the token vanished). Mirrors the
9
+ * delegation-verifier-kv.ts adapter shape.
10
+ *
11
+ * Key structure:
12
+ * - `resume:{token}` — JSON-encoded {@link StoredResumeToken}
13
+ *
14
+ * Tokens are minted with CSPRNG entropy (see generateResumeToken in
15
+ * @kya-os/mcp-i-core), never time+Math.random.
16
+ */
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.CloudflareKVResumeTokenStore = void 0;
19
+ const mcp_i_core_1 = require("@kya-os/mcp-i-core");
20
+ // Cloudflare KV requires expirationTtl >= 60 seconds.
21
+ const MIN_KV_TTL_SECONDS = 60;
22
+ function toTtlSeconds(ms) {
23
+ return Math.max(MIN_KV_TTL_SECONDS, Math.ceil(ms / 1000));
24
+ }
25
+ class CloudflareKVResumeTokenStore {
26
+ kv;
27
+ ttlMs;
28
+ constructor(kv, ttlMs = 600_000) {
29
+ this.kv = kv;
30
+ this.ttlMs = ttlMs;
31
+ }
32
+ key(token) {
33
+ return `resume:${token}`;
34
+ }
35
+ async read(token) {
36
+ const raw = await this.kv.get(this.key(token));
37
+ if (!raw)
38
+ return null;
39
+ try {
40
+ return JSON.parse(raw);
41
+ }
42
+ catch {
43
+ return null;
44
+ }
45
+ }
46
+ async create(agentDid, scopes, metadata) {
47
+ const token = (0, mcp_i_core_1.generateResumeToken)("rt");
48
+ const now = Date.now();
49
+ const record = {
50
+ agentDid,
51
+ scopes,
52
+ createdAt: now,
53
+ expiresAt: now + this.ttlMs,
54
+ metadata,
55
+ fulfilled: false,
56
+ };
57
+ await this.kv.put(this.key(token), JSON.stringify(record), {
58
+ expirationTtl: toTtlSeconds(this.ttlMs),
59
+ });
60
+ return token;
61
+ }
62
+ async get(token) {
63
+ const record = await this.read(token);
64
+ if (!record)
65
+ return null;
66
+ if (Date.now() > record.expiresAt) {
67
+ await this.kv.delete(this.key(token));
68
+ return null;
69
+ }
70
+ if (record.fulfilled)
71
+ return null;
72
+ return {
73
+ agentDid: record.agentDid,
74
+ scopes: record.scopes,
75
+ createdAt: record.createdAt,
76
+ expiresAt: record.expiresAt,
77
+ metadata: record.metadata,
78
+ };
79
+ }
80
+ async fulfill(token) {
81
+ const record = await this.read(token);
82
+ if (!record)
83
+ return;
84
+ record.fulfilled = true;
85
+ // Preserve the original expiry window so a fulfilled token can't outlive
86
+ // its TTL; floor at the KV minimum.
87
+ const remainingMs = Math.max(0, record.expiresAt - Date.now());
88
+ await this.kv.put(this.key(token), JSON.stringify(record), {
89
+ expirationTtl: toTtlSeconds(remainingMs),
90
+ });
91
+ }
92
+ }
93
+ exports.CloudflareKVResumeTokenStore = CloudflareKVResumeTokenStore;
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Resume Token Store Factory
3
+ *
4
+ * Selects a {@link ResumeTokenStore} implementation from config, mirroring the
5
+ * delegation-verifier factory (`createDelegationVerifier`). This replaces the
6
+ * hardcoded in-memory store in the runtime so consent→reuse can be made durable
7
+ * (Cloudflare KV) on multi-instance / serverless deployments, while keeping the
8
+ * in-memory store as an EXPLICIT single-process dev default.
9
+ */
10
+ import { type ResumeTokenStore } from "@kya-os/mcp-i-core";
11
+ import { type ResumeTokenKVNamespace } from "./resume-token-store-kv";
12
+ /**
13
+ * Configuration for resume-token stores.
14
+ *
15
+ * - `memory` — in-memory TTL map. Single-process dev only; tokens are lost on
16
+ * restart and not shared across instances.
17
+ * - `cloudflare-kv` — durable, edge-replicated. Survives cold starts/restarts.
18
+ */
19
+ export interface ResumeTokenStoreConfig {
20
+ type: "memory" | "cloudflare-kv";
21
+ /** Token TTL in milliseconds (default: 600_000 = 10 minutes). */
22
+ ttlMs?: number;
23
+ /** Cloudflare KV namespace (required for `cloudflare-kv`). */
24
+ kvNamespace?: ResumeTokenKVNamespace;
25
+ }
26
+ /**
27
+ * Create a resume-token store from config. Memory is an explicit opt-in for
28
+ * single-process development; durable stores must be selected deliberately.
29
+ */
30
+ export declare function createResumeTokenStore(config: ResumeTokenStoreConfig): ResumeTokenStore;
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ /**
3
+ * Resume Token Store Factory
4
+ *
5
+ * Selects a {@link ResumeTokenStore} implementation from config, mirroring the
6
+ * delegation-verifier factory (`createDelegationVerifier`). This replaces the
7
+ * hardcoded in-memory store in the runtime so consent→reuse can be made durable
8
+ * (Cloudflare KV) on multi-instance / serverless deployments, while keeping the
9
+ * in-memory store as an EXPLICIT single-process dev default.
10
+ */
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.createResumeTokenStore = createResumeTokenStore;
13
+ const mcp_i_core_1 = require("@kya-os/mcp-i-core");
14
+ const resume_token_store_kv_1 = require("./resume-token-store-kv");
15
+ const DEFAULT_TTL_MS = 600_000;
16
+ function invalidConfig(message) {
17
+ const runtimeError = {
18
+ error: "invalid_config",
19
+ message,
20
+ httpStatus: 500,
21
+ };
22
+ const error = new Error(runtimeError.message);
23
+ Object.assign(error, runtimeError);
24
+ return error;
25
+ }
26
+ /**
27
+ * Create a resume-token store from config. Memory is an explicit opt-in for
28
+ * single-process development; durable stores must be selected deliberately.
29
+ */
30
+ function createResumeTokenStore(config) {
31
+ const ttlMs = config.ttlMs ?? DEFAULT_TTL_MS;
32
+ switch (config.type) {
33
+ case "cloudflare-kv": {
34
+ if (!config.kvNamespace) {
35
+ throw invalidConfig("Resume token store 'cloudflare-kv' requires kvNamespace in config");
36
+ }
37
+ return new resume_token_store_kv_1.CloudflareKVResumeTokenStore(config.kvNamespace, ttlMs);
38
+ }
39
+ case "memory":
40
+ return new mcp_i_core_1.MemoryResumeTokenStore(ttlMs);
41
+ default: {
42
+ const configType = "type" in config ? config.type : "unknown";
43
+ throw invalidConfig(`Unknown resume token store type: ${configType}`);
44
+ }
45
+ }
46
+ }
@@ -7,8 +7,8 @@
7
7
  *
8
8
  * Requirements: 4.5-4.9, 19.1-19.2
9
9
  */
10
- import { SessionManager as CoreSessionManager, createHandshakeRequest, validateHandshakeFormat, type SessionConfig, type HandshakeResult } from "@kya-os/mcp-i-core";
11
- import { CryptoProvider } from "@kya-os/mcp-i-core";
10
+ import { SessionManager as CoreSessionManager, createHandshakeRequest, validateHandshakeFormat, type SessionConfig, type HandshakeResult } from "@kya-os/mcp-i-runtime";
11
+ import { CryptoProvider } from "@kya-os/mcp-i-runtime";
12
12
  export type { SessionConfig, HandshakeResult };
13
13
  export { createHandshakeRequest, validateHandshakeFormat };
14
14
  export declare class SessionManager extends CoreSessionManager {
@@ -10,10 +10,16 @@
10
10
  */
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.defaultSessionManager = exports.SessionManager = exports.validateHandshakeFormat = exports.createHandshakeRequest = void 0;
13
- const mcp_i_core_1 = require("@kya-os/mcp-i-core");
14
- Object.defineProperty(exports, "createHandshakeRequest", { enumerable: true, get: function () { return mcp_i_core_1.createHandshakeRequest; } });
15
- Object.defineProperty(exports, "validateHandshakeFormat", { enumerable: true, get: function () { return mcp_i_core_1.validateHandshakeFormat; } });
16
- const mcp_i_core_2 = require("@kya-os/mcp-i-core");
13
+ const mcp_i_runtime_1 = require("@kya-os/mcp-i-runtime");
14
+ Object.defineProperty(exports, "createHandshakeRequest", { enumerable: true, get: function () { return mcp_i_runtime_1.createHandshakeRequest; } });
15
+ Object.defineProperty(exports, "validateHandshakeFormat", { enumerable: true, get: function () { return mcp_i_runtime_1.validateHandshakeFormat; } });
16
+ const mcp_i_runtime_2 = require("@kya-os/mcp-i-runtime");
17
+ // C2 (#2916): the CJS/ESM (TS1479) blocker is resolved — PR-0's loadDifCore()
18
+ // seam (mcp-i-core/src/runtime/dif-core.ts) reaches the ESM-only @kya-os/mcp from
19
+ // CJS. The SessionManager re-home stays deferred on the remaining blocker: DIF
20
+ // emits kyaos_* session IDs, a wire-format change owned by the C4 (#2918)
21
+ // dual-accept window. Keep importing the OLD SessionManager from @kya-os/mcp-i-core
22
+ // until then.
17
23
  const node_providers_1 = require("../providers/node-providers");
18
24
  function resolveNodeConfig(config) {
19
25
  const skewEnv = process.env["XMCP_I_TS_SKEW_SEC"];
@@ -28,9 +34,9 @@ function resolveNodeConfig(config) {
28
34
  (parsedTtl !== undefined && !isNaN(parsedTtl) ? parsedTtl : undefined),
29
35
  };
30
36
  }
31
- class SessionManager extends mcp_i_core_1.SessionManager {
37
+ class SessionManager extends mcp_i_runtime_1.SessionManager {
32
38
  constructor(configOrCrypto, config) {
33
- if (configOrCrypto instanceof mcp_i_core_2.CryptoProvider) {
39
+ if (configOrCrypto instanceof mcp_i_runtime_2.CryptoProvider) {
34
40
  super(configOrCrypto, resolveNodeConfig(config ?? {}));
35
41
  }
36
42
  else {