@manifest-network/manifest-mcp-fred 0.13.1 → 0.15.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/dist/client.d.ts +54 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +52 -0
- package/dist/client.js.map +1 -0
- package/dist/ctx.d.ts +19 -0
- package/dist/ctx.d.ts.map +1 -0
- package/dist/ctx.js +0 -0
- package/dist/http/auth-tokens-factory.d.ts +31 -0
- package/dist/http/auth-tokens-factory.d.ts.map +1 -0
- package/dist/http/auth-tokens-factory.js +53 -0
- package/dist/http/auth-tokens-factory.js.map +1 -0
- package/dist/http/fred.d.ts +21 -60
- package/dist/http/fred.d.ts.map +1 -1
- package/dist/http/fred.js +1 -1
- package/dist/http/fred.js.map +1 -1
- package/dist/http/provider-auth.d.ts +33 -0
- package/dist/http/provider-auth.d.ts.map +1 -0
- package/dist/http/provider-auth.js +21 -0
- package/dist/http/provider-auth.js.map +1 -0
- package/dist/http/provider.d.ts +3 -30
- package/dist/http/provider.d.ts.map +1 -1
- package/dist/http/provider.js.map +1 -1
- package/dist/index.d.ts +14 -9
- package/dist/index.js +9 -5
- package/dist/manifest.d.ts +3 -30
- package/dist/manifest.d.ts.map +1 -1
- package/dist/manifest.js.map +1 -1
- package/dist/server/register-prompts.js +3 -3
- package/dist/server/register-prompts.js.map +1 -1
- package/dist/server/register-tools.d.ts.map +1 -1
- package/dist/server/register-tools.js +94 -25
- package/dist/server/register-tools.js.map +1 -1
- package/dist/tools/appStatus.d.ts +8 -4
- package/dist/tools/appStatus.d.ts.map +1 -1
- package/dist/tools/appStatus.js +13 -6
- package/dist/tools/appStatus.js.map +1 -1
- package/dist/tools/browseCatalog.d.ts +11 -7
- package/dist/tools/browseCatalog.d.ts.map +1 -1
- package/dist/tools/browseCatalog.js +12 -14
- package/dist/tools/browseCatalog.js.map +1 -1
- package/dist/tools/checkDeploymentReadiness.d.ts +29 -3
- package/dist/tools/checkDeploymentReadiness.d.ts.map +1 -1
- package/dist/tools/checkDeploymentReadiness.js +45 -25
- package/dist/tools/checkDeploymentReadiness.js.map +1 -1
- package/dist/tools/deployApp.d.ts +7 -76
- package/dist/tools/deployApp.d.ts.map +1 -1
- package/dist/tools/deployApp.js +42 -39
- package/dist/tools/deployApp.js.map +1 -1
- package/dist/tools/deployManifest.d.ts +17 -36
- package/dist/tools/deployManifest.d.ts.map +1 -1
- package/dist/tools/deployManifest.js +64 -64
- package/dist/tools/deployManifest.js.map +1 -1
- package/dist/tools/fetchActiveLease.d.ts +2 -2
- package/dist/tools/fetchActiveLease.d.ts.map +1 -1
- package/dist/tools/fetchActiveLease.js +2 -2
- package/dist/tools/fetchActiveLease.js.map +1 -1
- package/dist/tools/getLeaseConnectionInfo.d.ts +12 -0
- package/dist/tools/getLeaseConnectionInfo.d.ts.map +1 -0
- package/dist/tools/getLeaseConnectionInfo.js +16 -0
- package/dist/tools/getLeaseConnectionInfo.js.map +1 -0
- package/dist/tools/getLogs.d.ts +6 -2
- package/dist/tools/getLogs.d.ts.map +1 -1
- package/dist/tools/getLogs.js +6 -2
- package/dist/tools/getLogs.js.map +1 -1
- package/dist/tools/resolveLeaseProvider.d.ts +2 -2
- package/dist/tools/resolveLeaseProvider.d.ts.map +1 -1
- package/dist/tools/resolveLeaseProvider.js +2 -2
- package/dist/tools/resolveLeaseProvider.js.map +1 -1
- package/dist/tools/restartApp.d.ts +5 -2
- package/dist/tools/restartApp.d.ts.map +1 -1
- package/dist/tools/restartApp.js +6 -2
- package/dist/tools/restartApp.js.map +1 -1
- package/dist/tools/subscribeLeaseStatus.d.ts +44 -0
- package/dist/tools/subscribeLeaseStatus.d.ts.map +1 -0
- package/dist/tools/subscribeLeaseStatus.js +143 -0
- package/dist/tools/subscribeLeaseStatus.js.map +1 -0
- package/dist/tools/updateApp.d.ts +7 -2
- package/dist/tools/updateApp.d.ts.map +1 -1
- package/dist/tools/updateApp.js +10 -6
- package/dist/tools/updateApp.js.map +1 -1
- package/dist/tools/waitForAppReady.d.ts +5 -2
- package/dist/tools/waitForAppReady.d.ts.map +1 -1
- package/dist/tools/waitForAppReady.js +9 -5
- package/dist/tools/waitForAppReady.js.map +1 -1
- package/package.json +5 -4
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { ProviderAuthPort } from "./http/provider-auth.js";
|
|
2
|
+
import { appStatus } from "./tools/appStatus.js";
|
|
3
|
+
import { browseCatalog } from "./tools/browseCatalog.js";
|
|
4
|
+
import { deployApp } from "./tools/deployApp.js";
|
|
5
|
+
import { getLeaseConnectionInfo } from "./tools/getLeaseConnectionInfo.js";
|
|
6
|
+
import { getAppLogs } from "./tools/getLogs.js";
|
|
7
|
+
import { restartApp } from "./tools/restartApp.js";
|
|
8
|
+
import { SubscribeLeaseStatusOptions } from "./tools/subscribeLeaseStatus.js";
|
|
9
|
+
import { updateApp } from "./tools/updateApp.js";
|
|
10
|
+
import { waitForAppReady } from "./tools/waitForAppReady.js";
|
|
11
|
+
import { BoundFn, FullClientOptions, LeaseUuid, ManifestClient } from "@manifest-network/manifest-mcp-core";
|
|
12
|
+
|
|
13
|
+
//#region src/client.d.ts
|
|
14
|
+
/** Provider-backed methods layered onto a core ManifestClient by createFredClient. */
|
|
15
|
+
interface FredActions {
|
|
16
|
+
subscribeLeaseStatus(leaseUuid: LeaseUuid, opts: SubscribeLeaseStatusOptions): () => void;
|
|
17
|
+
browseCatalog: BoundFn<typeof browseCatalog>;
|
|
18
|
+
appStatus: BoundFn<typeof appStatus>;
|
|
19
|
+
getAppLogs: BoundFn<typeof getAppLogs>;
|
|
20
|
+
restartApp: BoundFn<typeof restartApp>;
|
|
21
|
+
updateApp: BoundFn<typeof updateApp>;
|
|
22
|
+
waitForAppReady: BoundFn<typeof waitForAppReady>;
|
|
23
|
+
getLeaseConnectionInfo: BoundFn<typeof getLeaseConnectionInfo>;
|
|
24
|
+
deployApp: BoundFn<typeof deployApp>;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* A full Manifest client + the Fred provider methods. Carries `providerAuth` so the client object
|
|
28
|
+
* structurally satisfies `FredAuthCtx` — it IS the ctx the bound provider methods close over.
|
|
29
|
+
*/
|
|
30
|
+
type FredClient = ManifestClient & {
|
|
31
|
+
providerAuth: ProviderAuthPort;
|
|
32
|
+
} & FredActions;
|
|
33
|
+
/** The fred-action decorator: thin .bind(ctx) closures over the free fns (viem-style; ctx = the client). */
|
|
34
|
+
declare function fredActions(ctx: FredClient): FredActions;
|
|
35
|
+
/**
|
|
36
|
+
* Create a full app client: core's chain-backed ManifestClient plus the Fred provider methods. The
|
|
37
|
+
* fully-decorated factory lives in fred (not core) because the provider methods hit the Fred backend,
|
|
38
|
+
* not the chain ctx wraps (viem one-client-one-backend rule, #2535). Requires a walletProvider.
|
|
39
|
+
*
|
|
40
|
+
* The signer-backed `providerAuth` token provider is built once here (the composition root) over
|
|
41
|
+
* `client.signer`, and attached to the client object so it satisfies `FredAuthCtx` before
|
|
42
|
+
* `fredActions` binds the lifecycle methods onto it.
|
|
43
|
+
*
|
|
44
|
+
* @remarks
|
|
45
|
+
* Wraps {@link createManifestClient}, so the same shared-config-key caveat applies: each client acquires
|
|
46
|
+
* one reference on a `CosmosClientManager` instance keyed by config (`chainId:rpcUrl[:restUrl]`), and
|
|
47
|
+
* `getInstance` mutates the shared instance — do NOT construct a separate read/full client against a key
|
|
48
|
+
* this client already holds. Always `dispose()` each client; the shared clients tear down only once the
|
|
49
|
+
* last holder disposes.
|
|
50
|
+
*/
|
|
51
|
+
declare function createFredClient(opts: FullClientOptions): Promise<FredClient>;
|
|
52
|
+
//#endregion
|
|
53
|
+
export { FredActions, FredClient, createFredClient, fredActions };
|
|
54
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","names":[],"sources":["../src/client.ts"],"mappings":";;;;;;;;;;;;;;UAyBiB,WAAA;EACf,oBAAA,CACE,SAAA,EAAW,SAAA,EACX,IAAA,EAAM,2BAAA;EAER,aAAA,EAAe,OAAA,QAAe,aAAA;EAC9B,SAAA,EAAW,OAAA,QAAe,SAAA;EAC1B,UAAA,EAAY,OAAA,QAAe,UAAA;EAC3B,UAAA,EAAY,OAAA,QAAe,UAAA;EAC3B,SAAA,EAAW,OAAA,QAAe,SAAA;EAC1B,eAAA,EAAiB,OAAA,QAAe,eAAA;EAChC,sBAAA,EAAwB,OAAA,QAAe,sBAAA;EACvC,SAAA,EAAW,OAAA,QAAe,SAAA;AAAA;;;;;KAOhB,UAAA,GAAa,cAAA;EACvB,YAAA,EAAc,gBAAA;AAAA,IACZ,WAAA;;iBAGY,WAAA,CAAY,GAAA,EAAK,UAAA,GAAa,WAAW;;;;;;;;;;;;;;;;;iBA+BnC,gBAAA,CACpB,IAAA,EAAM,iBAAA,GACL,OAAA,CAAQ,UAAA"}
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { createProviderAuth } from "./http/provider-auth.js";
|
|
2
|
+
import { appStatus } from "./tools/appStatus.js";
|
|
3
|
+
import { browseCatalog } from "./tools/browseCatalog.js";
|
|
4
|
+
import { deployApp } from "./tools/deployApp.js";
|
|
5
|
+
import { getLeaseConnectionInfo } from "./tools/getLeaseConnectionInfo.js";
|
|
6
|
+
import { getAppLogs } from "./tools/getLogs.js";
|
|
7
|
+
import { restartApp } from "./tools/restartApp.js";
|
|
8
|
+
import { subscribeLeaseStatus } from "./tools/subscribeLeaseStatus.js";
|
|
9
|
+
import { updateApp } from "./tools/updateApp.js";
|
|
10
|
+
import { waitForAppReady } from "./tools/waitForAppReady.js";
|
|
11
|
+
import { createManifestClient } from "@manifest-network/manifest-mcp-core";
|
|
12
|
+
//#region src/client.ts
|
|
13
|
+
/** The fred-action decorator: thin .bind(ctx) closures over the free fns (viem-style; ctx = the client). */
|
|
14
|
+
function fredActions(ctx) {
|
|
15
|
+
return {
|
|
16
|
+
subscribeLeaseStatus: (leaseUuid, opts) => subscribeLeaseStatus(ctx, leaseUuid, opts),
|
|
17
|
+
browseCatalog: (...a) => browseCatalog(ctx, ...a),
|
|
18
|
+
appStatus: (...a) => appStatus(ctx, ...a),
|
|
19
|
+
getAppLogs: (...a) => getAppLogs(ctx, ...a),
|
|
20
|
+
restartApp: (...a) => restartApp(ctx, ...a),
|
|
21
|
+
updateApp: (...a) => updateApp(ctx, ...a),
|
|
22
|
+
waitForAppReady: (...a) => waitForAppReady(ctx, ...a),
|
|
23
|
+
getLeaseConnectionInfo: (...a) => getLeaseConnectionInfo(ctx, ...a),
|
|
24
|
+
deployApp: (...a) => deployApp(ctx, ...a)
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Create a full app client: core's chain-backed ManifestClient plus the Fred provider methods. The
|
|
29
|
+
* fully-decorated factory lives in fred (not core) because the provider methods hit the Fred backend,
|
|
30
|
+
* not the chain ctx wraps (viem one-client-one-backend rule, #2535). Requires a walletProvider.
|
|
31
|
+
*
|
|
32
|
+
* The signer-backed `providerAuth` token provider is built once here (the composition root) over
|
|
33
|
+
* `client.signer`, and attached to the client object so it satisfies `FredAuthCtx` before
|
|
34
|
+
* `fredActions` binds the lifecycle methods onto it.
|
|
35
|
+
*
|
|
36
|
+
* @remarks
|
|
37
|
+
* Wraps {@link createManifestClient}, so the same shared-config-key caveat applies: each client acquires
|
|
38
|
+
* one reference on a `CosmosClientManager` instance keyed by config (`chainId:rpcUrl[:restUrl]`), and
|
|
39
|
+
* `getInstance` mutates the shared instance — do NOT construct a separate read/full client against a key
|
|
40
|
+
* this client already holds. Always `dispose()` each client; the shared clients tear down only once the
|
|
41
|
+
* last holder disposes.
|
|
42
|
+
*/
|
|
43
|
+
async function createFredClient(opts) {
|
|
44
|
+
const client = await createManifestClient(opts);
|
|
45
|
+
const providerAuth = createProviderAuth(client.signer, { chainId: client.chain.getConfig().chainId });
|
|
46
|
+
const withAuth = Object.assign(client, { providerAuth });
|
|
47
|
+
return Object.assign(withAuth, fredActions(withAuth));
|
|
48
|
+
}
|
|
49
|
+
//#endregion
|
|
50
|
+
export { createFredClient, fredActions };
|
|
51
|
+
|
|
52
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","names":[],"sources":["../src/client.ts"],"sourcesContent":["import {\n type BoundFn,\n createManifestClient,\n type FullClientOptions,\n type LeaseUuid,\n type ManifestClient,\n} from '@manifest-network/manifest-mcp-core';\nimport {\n createProviderAuth,\n type ProviderAuthPort,\n} from './http/provider-auth.js';\nimport { appStatus } from './tools/appStatus.js';\nimport { browseCatalog } from './tools/browseCatalog.js';\nimport { deployApp } from './tools/deployApp.js';\nimport { getLeaseConnectionInfo } from './tools/getLeaseConnectionInfo.js';\nimport { getAppLogs } from './tools/getLogs.js';\nimport { restartApp } from './tools/restartApp.js';\nimport {\n type SubscribeLeaseStatusOptions,\n subscribeLeaseStatus,\n} from './tools/subscribeLeaseStatus.js';\nimport { updateApp } from './tools/updateApp.js';\nimport { waitForAppReady } from './tools/waitForAppReady.js';\n\n/** Provider-backed methods layered onto a core ManifestClient by createFredClient. */\nexport interface FredActions {\n subscribeLeaseStatus(\n leaseUuid: LeaseUuid,\n opts: SubscribeLeaseStatusOptions,\n ): () => void;\n browseCatalog: BoundFn<typeof browseCatalog>;\n appStatus: BoundFn<typeof appStatus>;\n getAppLogs: BoundFn<typeof getAppLogs>;\n restartApp: BoundFn<typeof restartApp>;\n updateApp: BoundFn<typeof updateApp>;\n waitForAppReady: BoundFn<typeof waitForAppReady>;\n getLeaseConnectionInfo: BoundFn<typeof getLeaseConnectionInfo>;\n deployApp: BoundFn<typeof deployApp>;\n}\n\n/**\n * A full Manifest client + the Fred provider methods. Carries `providerAuth` so the client object\n * structurally satisfies `FredAuthCtx` — it IS the ctx the bound provider methods close over.\n */\nexport type FredClient = ManifestClient & {\n providerAuth: ProviderAuthPort;\n} & FredActions;\n\n/** The fred-action decorator: thin .bind(ctx) closures over the free fns (viem-style; ctx = the client). */\nexport function fredActions(ctx: FredClient): FredActions {\n return {\n subscribeLeaseStatus: (leaseUuid, opts) =>\n subscribeLeaseStatus(ctx, leaseUuid, opts),\n browseCatalog: (...a) => browseCatalog(ctx, ...a),\n appStatus: (...a) => appStatus(ctx, ...a),\n getAppLogs: (...a) => getAppLogs(ctx, ...a),\n restartApp: (...a) => restartApp(ctx, ...a),\n updateApp: (...a) => updateApp(ctx, ...a),\n waitForAppReady: (...a) => waitForAppReady(ctx, ...a),\n getLeaseConnectionInfo: (...a) => getLeaseConnectionInfo(ctx, ...a),\n deployApp: (...a) => deployApp(ctx, ...a),\n };\n}\n\n/**\n * Create a full app client: core's chain-backed ManifestClient plus the Fred provider methods. The\n * fully-decorated factory lives in fred (not core) because the provider methods hit the Fred backend,\n * not the chain ctx wraps (viem one-client-one-backend rule, #2535). Requires a walletProvider.\n *\n * The signer-backed `providerAuth` token provider is built once here (the composition root) over\n * `client.signer`, and attached to the client object so it satisfies `FredAuthCtx` before\n * `fredActions` binds the lifecycle methods onto it.\n *\n * @remarks\n * Wraps {@link createManifestClient}, so the same shared-config-key caveat applies: each client acquires\n * one reference on a `CosmosClientManager` instance keyed by config (`chainId:rpcUrl[:restUrl]`), and\n * `getInstance` mutates the shared instance — do NOT construct a separate read/full client against a key\n * this client already holds. Always `dispose()` each client; the shared clients tear down only once the\n * last holder disposes.\n */\nexport async function createFredClient(\n opts: FullClientOptions,\n): Promise<FredClient> {\n const client = await createManifestClient(opts);\n const providerAuth = createProviderAuth(client.signer, {\n chainId: client.chain.getConfig().chainId,\n });\n // Attach providerAuth FIRST so the client object satisfies FredAuthCtx, then layer the bound\n // provider methods over that SAME object (it IS the ctx the actions close over).\n const withAuth = Object.assign(client, { providerAuth }) as FredClient;\n return Object.assign(withAuth, fredActions(withAuth));\n}\n"],"mappings":";;;;;;;;;;;;;AAiDA,SAAgB,YAAY,KAA8B;CACxD,OAAO;EACL,uBAAuB,WAAW,SAChC,qBAAqB,KAAK,WAAW,IAAI;EAC3C,gBAAgB,GAAG,MAAM,cAAc,KAAK,GAAG,CAAC;EAChD,YAAY,GAAG,MAAM,UAAU,KAAK,GAAG,CAAC;EACxC,aAAa,GAAG,MAAM,WAAW,KAAK,GAAG,CAAC;EAC1C,aAAa,GAAG,MAAM,WAAW,KAAK,GAAG,CAAC;EAC1C,YAAY,GAAG,MAAM,UAAU,KAAK,GAAG,CAAC;EACxC,kBAAkB,GAAG,MAAM,gBAAgB,KAAK,GAAG,CAAC;EACpD,yBAAyB,GAAG,MAAM,uBAAuB,KAAK,GAAG,CAAC;EAClE,YAAY,GAAG,MAAM,UAAU,KAAK,GAAG,CAAC;CAC1C;AACF;;;;;;;;;;;;;;;;;AAkBA,eAAsB,iBACpB,MACqB;CACrB,MAAM,SAAS,MAAM,qBAAqB,IAAI;CAC9C,MAAM,eAAe,mBAAmB,OAAO,QAAQ,EACrD,SAAS,OAAO,MAAM,UAAU,EAAE,QACpC,CAAC;CAGD,MAAM,WAAW,OAAO,OAAO,QAAQ,EAAE,aAAa,CAAC;CACvD,OAAO,OAAO,OAAO,UAAU,YAAY,QAAQ,CAAC;AACtD"}
|
package/dist/ctx.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ProviderAuthPort } from "./http/provider-auth.js";
|
|
2
|
+
import { CapabilityCtx } from "@manifest-network/manifest-mcp-core";
|
|
3
|
+
|
|
4
|
+
//#region src/ctx.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Non-auth Fred reads: chain reads (`query`/`chain`) + provider HTTP (`fetch`), no signer.
|
|
7
|
+
* A structural superset of the values a converted read fn needs.
|
|
8
|
+
*/
|
|
9
|
+
type FredReadCtx = Pick<CapabilityCtx, 'query' | 'chain' | 'fetch' | 'logger'>;
|
|
10
|
+
/**
|
|
11
|
+
* Provider-authenticated Fred fns: a read ctx + the signer-backed token provider.
|
|
12
|
+
* `signer` stays encapsulated inside `providerAuth` (built once at the composition root).
|
|
13
|
+
*/
|
|
14
|
+
type FredAuthCtx = FredReadCtx & {
|
|
15
|
+
providerAuth: ProviderAuthPort;
|
|
16
|
+
};
|
|
17
|
+
//#endregion
|
|
18
|
+
export { FredAuthCtx, FredReadCtx };
|
|
19
|
+
//# sourceMappingURL=ctx.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ctx.d.ts","names":[],"sources":["../src/ctx.ts"],"mappings":";;;;;;AAOA;;KAAY,WAAA,GAAc,IAAI,CAC5B,aAAA;;AAAa;AAQf;;KAAY,WAAA,GAAc,WAAA;EAAgB,YAAA,EAAc,gBAAgB;AAAA"}
|
package/dist/ctx.js
ADDED
|
File without changes
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { AuthSigner, LeaseUuid } from "@manifest-network/manifest-mcp-core";
|
|
2
|
+
|
|
3
|
+
//#region src/http/auth-tokens-factory.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Signer-bound ADR-036 auth-token factory. Replaces the per-call `makeFredAuthTokens` closures
|
|
6
|
+
* (Barney's `getProviderAuthToken`). Resolves the address from `signer.getAddress()` LAZILY on the
|
|
7
|
+
* first token call (memoized on SUCCESS only — construction has no wallet/network side effect; see
|
|
8
|
+
* the inline comment), then mints a FRESH token per call (serialized by `AuthTimestampTracker`). It
|
|
9
|
+
* does NOT cache tokens: ADR-036 signing is deterministic, so a reused token is a duplicate signature
|
|
10
|
+
* the provider's replay tracker rejects on protected endpoints (see `auth.ts` AuthTimestampTracker
|
|
11
|
+
* doc). Reuses the same stateless builders `AuthTokenService` uses, so behavior matches the proven
|
|
12
|
+
* server path.
|
|
13
|
+
*
|
|
14
|
+
* The returned `getAuthToken(leaseUuid)` is ADDRESS-BOUND (the address is closed over here, not a
|
|
15
|
+
* param). The deploy path's callbacks are `(address, leaseUuid) =>`, so when 4c wires this in it
|
|
16
|
+
* wraps with an address-closing thunk — `() => tokens.getAuthToken(uuid)` — the same idiom the real
|
|
17
|
+
* consumer (Barney `compositeTransactions.ts`) already uses. This is the intended SDK shape, not a
|
|
18
|
+
* mismatch. See plan OI-A1.
|
|
19
|
+
*
|
|
20
|
+
* `chainId` is accepted for forward-compat / API symmetry (spec §5.3); it is NOT yet embedded in the
|
|
21
|
+
* ADR-036 message — reserved for a future chain-scoped token format. See plan OI-CHAIN.
|
|
22
|
+
*/
|
|
23
|
+
declare function createAuthTokens(signer: AuthSigner, opts: {
|
|
24
|
+
chainId: string;
|
|
25
|
+
}): {
|
|
26
|
+
getAuthToken(leaseUuid: LeaseUuid): Promise<string>;
|
|
27
|
+
getLeaseDataAuthToken(leaseUuid: LeaseUuid, metaHashHex: string): Promise<string>;
|
|
28
|
+
};
|
|
29
|
+
//#endregion
|
|
30
|
+
export { createAuthTokens };
|
|
31
|
+
//# sourceMappingURL=auth-tokens-factory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth-tokens-factory.d.ts","names":[],"sources":["../../src/http/auth-tokens-factory.ts"],"mappings":";;;;;AA+BA;;;;;;;;;;;;;;;;;iBAAgB,gBAAA,CACd,MAAA,EAAQ,UAAA,EACR,IAAA;EAAQ,OAAA;AAAA;EAER,YAAA,CAAa,SAAA,EAAW,SAAA,GAAY,OAAA;EACpC,qBAAA,CACE,SAAA,EAAW,SAAA,EACX,WAAA,WACC,OAAA;AAAA"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { AuthTimestampTracker, createAuthToken, createLeaseDataSignMessage, createSignMessage } from "./auth.js";
|
|
2
|
+
//#region src/http/auth-tokens-factory.ts
|
|
3
|
+
/**
|
|
4
|
+
* Signer-bound ADR-036 auth-token factory. Replaces the per-call `makeFredAuthTokens` closures
|
|
5
|
+
* (Barney's `getProviderAuthToken`). Resolves the address from `signer.getAddress()` LAZILY on the
|
|
6
|
+
* first token call (memoized on SUCCESS only — construction has no wallet/network side effect; see
|
|
7
|
+
* the inline comment), then mints a FRESH token per call (serialized by `AuthTimestampTracker`). It
|
|
8
|
+
* does NOT cache tokens: ADR-036 signing is deterministic, so a reused token is a duplicate signature
|
|
9
|
+
* the provider's replay tracker rejects on protected endpoints (see `auth.ts` AuthTimestampTracker
|
|
10
|
+
* doc). Reuses the same stateless builders `AuthTokenService` uses, so behavior matches the proven
|
|
11
|
+
* server path.
|
|
12
|
+
*
|
|
13
|
+
* The returned `getAuthToken(leaseUuid)` is ADDRESS-BOUND (the address is closed over here, not a
|
|
14
|
+
* param). The deploy path's callbacks are `(address, leaseUuid) =>`, so when 4c wires this in it
|
|
15
|
+
* wraps with an address-closing thunk — `() => tokens.getAuthToken(uuid)` — the same idiom the real
|
|
16
|
+
* consumer (Barney `compositeTransactions.ts`) already uses. This is the intended SDK shape, not a
|
|
17
|
+
* mismatch. See plan OI-A1.
|
|
18
|
+
*
|
|
19
|
+
* `chainId` is accepted for forward-compat / API symmetry (spec §5.3); it is NOT yet embedded in the
|
|
20
|
+
* ADR-036 message — reserved for a future chain-scoped token format. See plan OI-CHAIN.
|
|
21
|
+
*/
|
|
22
|
+
function createAuthTokens(signer, opts) {
|
|
23
|
+
opts.chainId;
|
|
24
|
+
const timestamps = new AuthTimestampTracker();
|
|
25
|
+
let addressPromise;
|
|
26
|
+
const getAddress = () => {
|
|
27
|
+
addressPromise ?? (addressPromise = signer.getAddress().catch((err) => {
|
|
28
|
+
addressPromise = void 0;
|
|
29
|
+
throw err;
|
|
30
|
+
}));
|
|
31
|
+
return addressPromise;
|
|
32
|
+
};
|
|
33
|
+
return {
|
|
34
|
+
async getAuthToken(leaseUuid) {
|
|
35
|
+
const address = await getAddress();
|
|
36
|
+
const timestamp = await timestamps.next();
|
|
37
|
+
const message = createSignMessage(address, leaseUuid, timestamp);
|
|
38
|
+
const { pub_key, signature } = await signer.signArbitrary(address, message);
|
|
39
|
+
return createAuthToken(address, leaseUuid, timestamp, pub_key.value, signature);
|
|
40
|
+
},
|
|
41
|
+
async getLeaseDataAuthToken(leaseUuid, metaHashHex) {
|
|
42
|
+
const address = await getAddress();
|
|
43
|
+
const timestamp = await timestamps.next();
|
|
44
|
+
const message = createLeaseDataSignMessage(leaseUuid, metaHashHex, timestamp);
|
|
45
|
+
const { pub_key, signature } = await signer.signArbitrary(address, message);
|
|
46
|
+
return createAuthToken(address, leaseUuid, timestamp, pub_key.value, signature, metaHashHex);
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
//#endregion
|
|
51
|
+
export { createAuthTokens };
|
|
52
|
+
|
|
53
|
+
//# sourceMappingURL=auth-tokens-factory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth-tokens-factory.js","names":[],"sources":["../../src/http/auth-tokens-factory.ts"],"sourcesContent":["import type {\n Address,\n AuthSigner,\n LeaseUuid,\n} from '@manifest-network/manifest-mcp-core';\nimport {\n AuthTimestampTracker,\n createAuthToken,\n createLeaseDataSignMessage,\n createSignMessage,\n} from './auth.js';\n\n/**\n * Signer-bound ADR-036 auth-token factory. Replaces the per-call `makeFredAuthTokens` closures\n * (Barney's `getProviderAuthToken`). Resolves the address from `signer.getAddress()` LAZILY on the\n * first token call (memoized on SUCCESS only — construction has no wallet/network side effect; see\n * the inline comment), then mints a FRESH token per call (serialized by `AuthTimestampTracker`). It\n * does NOT cache tokens: ADR-036 signing is deterministic, so a reused token is a duplicate signature\n * the provider's replay tracker rejects on protected endpoints (see `auth.ts` AuthTimestampTracker\n * doc). Reuses the same stateless builders `AuthTokenService` uses, so behavior matches the proven\n * server path.\n *\n * The returned `getAuthToken(leaseUuid)` is ADDRESS-BOUND (the address is closed over here, not a\n * param). The deploy path's callbacks are `(address, leaseUuid) =>`, so when 4c wires this in it\n * wraps with an address-closing thunk — `() => tokens.getAuthToken(uuid)` — the same idiom the real\n * consumer (Barney `compositeTransactions.ts`) already uses. This is the intended SDK shape, not a\n * mismatch. See plan OI-A1.\n *\n * `chainId` is accepted for forward-compat / API symmetry (spec §5.3); it is NOT yet embedded in the\n * ADR-036 message — reserved for a future chain-scoped token format. See plan OI-CHAIN.\n */\nexport function createAuthTokens(\n signer: AuthSigner,\n opts: { chainId: string },\n): {\n getAuthToken(leaseUuid: LeaseUuid): Promise<string>;\n getLeaseDataAuthToken(\n leaseUuid: LeaseUuid,\n metaHashHex: string,\n ): Promise<string>;\n} {\n void opts.chainId; // reserved (OI-CHAIN); silences noUnusedParameters\n const timestamps = new AuthTimestampTracker();\n\n // Resolve the address LAZILY on first token mint, memoizing on SUCCESS only.\n // Two reasons (both mirror core's `createSignerAdapter`, signer.ts:34-49):\n // 1. No construction-time side effect — the signer's `getAddress()` triggers\n // wallet `connect()` internally, so an eager call would couple merely\n // constructing the factory to a wallet/network round-trip.\n // 2. No promise poisoning — `getAddress()` can reject with a TRANSIENT\n // WALLET_NOT_CONNECTED. Caching a rejected promise would permanently\n // poison this long-lived factory: every later token call would replay\n // the failure without retrying. Reset on rejection so a transient\n // failure can recover on the next call.\n let addressPromise: Promise<Address> | undefined;\n const getAddress = (): Promise<Address> => {\n addressPromise ??= signer.getAddress().catch((err) => {\n addressPromise = undefined;\n throw err;\n });\n return addressPromise;\n };\n\n return {\n async getAuthToken(leaseUuid) {\n const address = await getAddress();\n const timestamp = await timestamps.next();\n const message = createSignMessage(address, leaseUuid, timestamp);\n const { pub_key, signature } = await signer.signArbitrary(\n address,\n message,\n );\n return createAuthToken(\n address,\n leaseUuid,\n timestamp,\n pub_key.value,\n signature,\n );\n },\n async getLeaseDataAuthToken(leaseUuid, metaHashHex) {\n const address = await getAddress();\n const timestamp = await timestamps.next();\n const message = createLeaseDataSignMessage(\n leaseUuid,\n metaHashHex,\n timestamp,\n );\n const { pub_key, signature } = await signer.signArbitrary(\n address,\n message,\n );\n return createAuthToken(\n address,\n leaseUuid,\n timestamp,\n pub_key.value,\n signature,\n metaHashHex,\n );\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AA+BA,SAAgB,iBACd,QACA,MAOA;CACA,KAAU;CACV,MAAM,aAAa,IAAI,qBAAqB;CAY5C,IAAI;CACJ,MAAM,mBAAqC;EACzC,mBAAA,iBAAmB,OAAO,WAAW,EAAE,OAAO,QAAQ;GACpD,iBAAiB,KAAA;GACjB,MAAM;EACR,CAAC;EACD,OAAO;CACT;CAEA,OAAO;EACL,MAAM,aAAa,WAAW;GAC5B,MAAM,UAAU,MAAM,WAAW;GACjC,MAAM,YAAY,MAAM,WAAW,KAAK;GACxC,MAAM,UAAU,kBAAkB,SAAS,WAAW,SAAS;GAC/D,MAAM,EAAE,SAAS,cAAc,MAAM,OAAO,cAC1C,SACA,OACF;GACA,OAAO,gBACL,SACA,WACA,WACA,QAAQ,OACR,SACF;EACF;EACA,MAAM,sBAAsB,WAAW,aAAa;GAClD,MAAM,UAAU,MAAM,WAAW;GACjC,MAAM,YAAY,MAAM,WAAW,KAAK;GACxC,MAAM,UAAU,2BACd,WACA,aACA,SACF;GACA,MAAM,EAAE,SAAS,cAAc,MAAM,OAAO,cAC1C,SACA,OACF;GACA,OAAO,gBACL,SACA,WACA,WACA,QAAQ,OACR,WACA,WACF;EACF;CACF;AACF"}
|
package/dist/http/fred.d.ts
CHANGED
|
@@ -1,72 +1,14 @@
|
|
|
1
1
|
import { ProviderApiError } from "./provider.js";
|
|
2
|
-
import {
|
|
2
|
+
import { FredActionResponse, FredInstanceInfo, FredLeaseInfo, FredLeaseLogs, FredLeaseProvision, FredLeaseRelease, FredLeaseReleases, FredLeaseStatus, FredServiceStatus } from "@manifest-network/manifest-mcp-core";
|
|
3
3
|
|
|
4
4
|
//#region src/http/fred.d.ts
|
|
5
5
|
declare const MAX_TAIL = 1000;
|
|
6
|
-
interface FredInstanceInfo {
|
|
7
|
-
readonly name: string;
|
|
8
|
-
readonly status: string;
|
|
9
|
-
readonly ports?: Record<string, number>;
|
|
10
|
-
readonly fqdn?: string;
|
|
11
|
-
}
|
|
12
|
-
interface FredServiceStatus {
|
|
13
|
-
readonly instances: readonly FredInstanceInfo[];
|
|
14
|
-
}
|
|
15
|
-
interface FredLeaseStatus {
|
|
16
|
-
readonly state: LeaseState;
|
|
17
|
-
readonly provision_status?: string;
|
|
18
|
-
readonly phase?: string;
|
|
19
|
-
readonly steps?: Record<string, string>;
|
|
20
|
-
readonly instances?: readonly FredInstanceInfo[];
|
|
21
|
-
readonly endpoints?: Record<string, string>;
|
|
22
|
-
readonly last_error?: string;
|
|
23
|
-
readonly fail_count?: number;
|
|
24
|
-
readonly created_at?: string;
|
|
25
|
-
readonly services?: Record<string, FredServiceStatus>;
|
|
26
|
-
}
|
|
27
6
|
declare function getLeaseStatus(providerUrl: string, leaseUuid: string, authToken: string, fetchFn?: typeof globalThis.fetch): Promise<FredLeaseStatus>;
|
|
28
|
-
interface FredLeaseLogs {
|
|
29
|
-
readonly lease_uuid: string;
|
|
30
|
-
readonly tenant: string;
|
|
31
|
-
readonly provider_uuid: string;
|
|
32
|
-
readonly logs: Record<string, string>;
|
|
33
|
-
}
|
|
34
7
|
declare function getLeaseLogs(providerUrl: string, leaseUuid: string, authToken: string, tail?: number, fetchFn?: typeof globalThis.fetch): Promise<FredLeaseLogs>;
|
|
35
|
-
interface FredLeaseProvision {
|
|
36
|
-
readonly status: string;
|
|
37
|
-
readonly fail_count: number;
|
|
38
|
-
/**
|
|
39
|
-
* Set only when the most recent provisioning attempt failed. The Fred
|
|
40
|
-
* provider omits the field on success, so the optional marker matches
|
|
41
|
-
* the wire shape (and matches the same field on FredLeaseStatus above).
|
|
42
|
-
*/
|
|
43
|
-
readonly last_error?: string;
|
|
44
|
-
}
|
|
45
8
|
declare function getLeaseProvision(providerUrl: string, leaseUuid: string, authToken: string, fetchFn?: typeof globalThis.fetch): Promise<FredLeaseProvision>;
|
|
46
|
-
interface FredActionResponse {
|
|
47
|
-
readonly status: string;
|
|
48
|
-
}
|
|
49
9
|
declare function restartLease(providerUrl: string, leaseUuid: string, authToken: string, fetchFn?: typeof globalThis.fetch): Promise<FredActionResponse>;
|
|
50
10
|
declare function updateLease(providerUrl: string, leaseUuid: string, payload: Uint8Array, authToken: string, fetchFn?: typeof globalThis.fetch): Promise<FredActionResponse>;
|
|
51
|
-
interface FredLeaseRelease {
|
|
52
|
-
readonly version: number;
|
|
53
|
-
readonly image: string;
|
|
54
|
-
readonly status: string;
|
|
55
|
-
readonly created_at: string;
|
|
56
|
-
readonly error?: string;
|
|
57
|
-
readonly manifest?: string;
|
|
58
|
-
}
|
|
59
|
-
interface FredLeaseReleases {
|
|
60
|
-
readonly lease_uuid: string;
|
|
61
|
-
readonly tenant: string;
|
|
62
|
-
readonly provider_uuid: string;
|
|
63
|
-
readonly releases: readonly FredLeaseRelease[];
|
|
64
|
-
}
|
|
65
11
|
declare function getLeaseReleases(providerUrl: string, leaseUuid: string, authToken: string, fetchFn?: typeof globalThis.fetch): Promise<FredLeaseReleases>;
|
|
66
|
-
interface FredLeaseInfo {
|
|
67
|
-
readonly host: string;
|
|
68
|
-
readonly ports?: Record<string, unknown>;
|
|
69
|
-
}
|
|
70
12
|
declare function getLeaseInfo(providerUrl: string, leaseUuid: string, authToken: string, fetchFn?: typeof globalThis.fetch): Promise<FredLeaseInfo>;
|
|
71
13
|
type TerminalChainLeaseState = 'closed' | 'rejected' | 'expired';
|
|
72
14
|
interface TerminalChainState {
|
|
@@ -80,6 +22,25 @@ interface PollOptions {
|
|
|
80
22
|
/** Runs once per iteration before the provider is queried. Non-null return throws; errors propagate. */
|
|
81
23
|
readonly checkChainState?: () => Promise<TerminalChainState | null>;
|
|
82
24
|
}
|
|
25
|
+
/**
|
|
26
|
+
* Provider `provision_status` values (fred backend `ProvisionStatus`) that mean
|
|
27
|
+
* the lease is not yet confirmed healthy while the chain lease is already
|
|
28
|
+
* ACTIVE — keep polling. `failing` is the pre-terminal window before `failed`
|
|
29
|
+
* (the backend state machine only ever moves `failing → failed`, never back to
|
|
30
|
+
* provisioning, so waiting is bounded). `unknown` is the backend's indeterminate
|
|
31
|
+
* signal — an unrecognized container status or a state-machine read error — and
|
|
32
|
+
* likewise is "not confirmed ready", so we wait for it to settle to
|
|
33
|
+
* `ready`/`failed` rather than reporting it as success. A status string this
|
|
34
|
+
* client does not recognize at all (a genuinely future value) is NOT listed
|
|
35
|
+
* here; the ACTIVE branch treats it as settled (see below).
|
|
36
|
+
*/
|
|
37
|
+
declare const PROVISION_IN_PROGRESS: ReadonlySet<string>;
|
|
38
|
+
/**
|
|
39
|
+
* Provider `provision_status` values that mean provisioning will not become
|
|
40
|
+
* healthy. The chain lease is ACTIVE, but the deployment has effectively failed
|
|
41
|
+
* (or is being torn down) — surface it as an error instead of a ready lease.
|
|
42
|
+
*/
|
|
43
|
+
declare const PROVISION_FAILED: ReadonlySet<string>;
|
|
83
44
|
/**
|
|
84
45
|
* Thrown by pollLeaseUntilReady when the caller's checkChainState callback
|
|
85
46
|
* reports a terminal lease state on-chain. Extends ProviderApiError so
|
|
@@ -117,5 +78,5 @@ declare class TerminalChainStateError extends ProviderApiError {
|
|
|
117
78
|
}
|
|
118
79
|
declare function pollLeaseUntilReady(providerUrl: string, leaseUuid: string, authToken: string | (() => Promise<string>), opts?: PollOptions, fetchFn?: typeof globalThis.fetch): Promise<FredLeaseStatus>;
|
|
119
80
|
//#endregion
|
|
120
|
-
export { FredActionResponse, FredInstanceInfo, FredLeaseInfo, FredLeaseLogs, FredLeaseProvision, FredLeaseRelease, FredLeaseReleases, FredLeaseStatus, FredServiceStatus, MAX_TAIL, PollOptions, TerminalChainLeaseState, TerminalChainState, TerminalChainStateContext, TerminalChainStateError, getLeaseInfo, getLeaseLogs, getLeaseProvision, getLeaseReleases, getLeaseStatus, pollLeaseUntilReady, restartLease, updateLease };
|
|
81
|
+
export { type FredActionResponse, type FredInstanceInfo, type FredLeaseInfo, type FredLeaseLogs, type FredLeaseProvision, type FredLeaseRelease, type FredLeaseReleases, type FredLeaseStatus, type FredServiceStatus, MAX_TAIL, PROVISION_FAILED, PROVISION_IN_PROGRESS, PollOptions, TerminalChainLeaseState, TerminalChainState, TerminalChainStateContext, TerminalChainStateError, getLeaseInfo, getLeaseLogs, getLeaseProvision, getLeaseReleases, getLeaseStatus, pollLeaseUntilReady, restartLease, updateLease };
|
|
121
82
|
//# sourceMappingURL=fred.d.ts.map
|
package/dist/http/fred.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fred.d.ts","names":[],"sources":["../../src/http/fred.ts"],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"fred.d.ts","names":[],"sources":["../../src/http/fred.ts"],"mappings":";;;;cAoCa,QAAA;AAAA,iBAOS,cAAA,CACpB,WAAA,UACA,SAAA,UACA,SAAA,UACA,OAAA,UAAiB,UAAA,CAAW,KAAA,GAC3B,OAAA,CAAQ,eAAA;AAAA,iBAsBW,YAAA,CACpB,WAAA,UACA,SAAA,UACA,SAAA,UACA,IAAA,WACA,OAAA,UAAiB,UAAA,CAAW,KAAA,GAC3B,OAAA,CAAQ,aAAA;AAAA,iBAgBW,iBAAA,CACpB,WAAA,UACA,SAAA,UACA,SAAA,UACA,OAAA,UAAiB,UAAA,CAAW,KAAA,GAC3B,OAAA,CAAQ,kBAAA;AAAA,iBAcW,YAAA,CACpB,WAAA,UACA,SAAA,UACA,SAAA,UACA,OAAA,UAAiB,UAAA,CAAW,KAAA,GAC3B,OAAA,CAAQ,kBAAA;AAAA,iBAeW,WAAA,CACpB,WAAA,UACA,SAAA,UACA,OAAA,EAAS,UAAA,EACT,SAAA,UACA,OAAA,UAAiB,UAAA,CAAW,KAAA,GAC3B,OAAA,CAAQ,kBAAA;AAAA,iBAqBW,gBAAA,CACpB,WAAA,UACA,SAAA,UACA,SAAA,UACA,OAAA,UAAiB,UAAA,CAAW,KAAA,GAC3B,OAAA,CAAQ,iBAAA;AAAA,iBAcW,YAAA,CACpB,WAAA,UACA,SAAA,UACA,SAAA,UACA,OAAA,UAAiB,UAAA,CAAW,KAAA,GAC3B,OAAA,CAAQ,aAAA;AAAA,KAcC,uBAAA;AAAA,UAEK,kBAAA;EAAA,SACN,KAAA,EAAO,uBAAuB;AAAA;AAAA,UAGxB,WAAA;EAAA,SACN,UAAA;EAAA,SACA,SAAA;EAAA,SACA,WAAA,GAAc,WAAA;EAAA,SACd,UAAA,IAAc,MAAA,EAAQ,eAAA;EA/Jd;EAAA,SAiKR,eAAA,SAAwB,OAAA,CAAQ,kBAAA;AAAA;;;;AAhKjB;AAsB1B;;;;;;;;cAoKa,qBAAA,EAAuB,WAAW;;;;;;cAalC,gBAAA,EAAkB,WAAW;;;;AA3KlB;AAgBxB;;UAsKiB,yBAAA;EAAA,SACN,UAAA;EAAA,SACA,YAAA;EAAA,SACA,WAAA;AAAA;AAAA,cAGE,uBAAA,SAAgC,gBAAA;EAAA,SAC3B,UAAA,EAAY,uBAAA;EAAA,SACZ,SAAA;EAAA,SACA,YAAA;EAAA,SACA,WAAA;EA5KY;;;;;AACD;EADC,SAmLZ,OAAA;IAAA,SACL,UAAA;IAAA,SACA,aAAA;IAAA,SACA,YAAA;EAAA;cAIT,SAAA,UACA,UAAA,EAAY,uBAAA,EACZ,OAAA,GAAU,yBAAA;EAxKJ;;;;;EAiMR,WAAA,CAAY,OAAA,EAAS,yBAAA,GAA4B,uBAAA;AAAA;AAAA,iBA8B7B,mBAAA,CACpB,WAAA,UACA,SAAA,UACA,SAAA,kBAA2B,OAAA,WAC3B,IAAA,GAAM,WAAA,EACN,OAAA,UAAiB,UAAA,CAAW,KAAA,GAC3B,OAAA,CAAQ,eAAA"}
|
package/dist/http/fred.js
CHANGED
|
@@ -164,6 +164,6 @@ async function pollLeaseUntilReady(providerUrl, leaseUuid, authToken, opts = {},
|
|
|
164
164
|
throw new ProviderApiError(0, `Lease ${leaseUuid} poll timed out after ${timeoutMs}ms (last state: ${lastState !== void 0 ? leaseStateName(lastState) : "unknown"}, provision_status: ${lastProvisionStatus ?? "unknown"})`);
|
|
165
165
|
}
|
|
166
166
|
//#endregion
|
|
167
|
-
export { MAX_TAIL, TerminalChainStateError, getLeaseInfo, getLeaseLogs, getLeaseProvision, getLeaseReleases, getLeaseStatus, pollLeaseUntilReady, restartLease, updateLease };
|
|
167
|
+
export { MAX_TAIL, PROVISION_FAILED, PROVISION_IN_PROGRESS, TerminalChainStateError, getLeaseInfo, getLeaseLogs, getLeaseProvision, getLeaseReleases, getLeaseStatus, pollLeaseUntilReady, restartLease, updateLease };
|
|
168
168
|
|
|
169
169
|
//# sourceMappingURL=fred.js.map
|
package/dist/http/fred.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fred.js","names":[],"sources":["../../src/http/fred.ts"],"sourcesContent":["import { toBase64 } from '@cosmjs/encoding';\nimport {\n LeaseState,\n leaseStateFromJSON,\n logger,\n} from '@manifest-network/manifest-mcp-core';\nimport {\n checkedFetch,\n ProviderApiError,\n parseJsonResponse,\n validateProviderUrl,\n} from './provider.js';\n\nexport const MAX_TAIL = 1000;\n\nexport interface FredInstanceInfo {\n readonly name: string;\n readonly status: string;\n readonly ports?: Record<string, number>;\n readonly fqdn?: string;\n}\n\nexport interface FredServiceStatus {\n readonly instances: readonly FredInstanceInfo[];\n}\n\nexport interface FredLeaseStatus {\n readonly state: LeaseState;\n readonly provision_status?: string;\n readonly phase?: string;\n readonly steps?: Record<string, string>;\n readonly instances?: readonly FredInstanceInfo[];\n readonly endpoints?: Record<string, string>;\n readonly last_error?: string;\n readonly fail_count?: number;\n readonly created_at?: string;\n readonly services?: Record<string, FredServiceStatus>;\n}\n\n/** Raw wire shape before LeaseState conversion */\ninterface RawLeaseStatus extends Omit<FredLeaseStatus, 'state'> {\n readonly state: string;\n}\n\nexport async function getLeaseStatus(\n providerUrl: string,\n leaseUuid: string,\n authToken: string,\n fetchFn?: typeof globalThis.fetch,\n): Promise<FredLeaseStatus> {\n const validated = validateProviderUrl(providerUrl);\n const url = `${validated}/v1/leases/${encodeURIComponent(leaseUuid)}/status`;\n const res = await checkedFetch(\n url,\n {\n headers: { Authorization: `Bearer ${authToken}` },\n },\n undefined,\n fetchFn,\n );\n const raw = await parseJsonResponse<RawLeaseStatus>(res, url);\n const state = leaseStateFromJSON(raw.state);\n if (state === LeaseState.UNRECOGNIZED) {\n logger.warn(\n `[getLeaseStatus] Unrecognized lease state \"${raw.state}\" for lease ${leaseUuid}. ` +\n 'The provider may be running a newer version than the client supports.',\n );\n }\n return { ...raw, state };\n}\n\nexport interface FredLeaseLogs {\n readonly lease_uuid: string;\n readonly tenant: string;\n readonly provider_uuid: string;\n readonly logs: Record<string, string>;\n}\n\nexport async function getLeaseLogs(\n providerUrl: string,\n leaseUuid: string,\n authToken: string,\n tail?: number,\n fetchFn?: typeof globalThis.fetch,\n): Promise<FredLeaseLogs> {\n const validated = validateProviderUrl(providerUrl);\n const cappedTail = tail !== undefined ? Math.min(tail, MAX_TAIL) : undefined;\n const qs = cappedTail !== undefined ? `?tail=${cappedTail}` : '';\n const url = `${validated}/v1/leases/${encodeURIComponent(leaseUuid)}/logs${qs}`;\n const res = await checkedFetch(\n url,\n {\n headers: { Authorization: `Bearer ${authToken}` },\n },\n undefined,\n fetchFn,\n );\n return await parseJsonResponse<FredLeaseLogs>(res, url);\n}\n\nexport interface FredLeaseProvision {\n readonly status: string;\n readonly fail_count: number;\n /**\n * Set only when the most recent provisioning attempt failed. The Fred\n * provider omits the field on success, so the optional marker matches\n * the wire shape (and matches the same field on FredLeaseStatus above).\n */\n readonly last_error?: string;\n}\n\nexport async function getLeaseProvision(\n providerUrl: string,\n leaseUuid: string,\n authToken: string,\n fetchFn?: typeof globalThis.fetch,\n): Promise<FredLeaseProvision> {\n const validated = validateProviderUrl(providerUrl);\n const url = `${validated}/v1/leases/${encodeURIComponent(leaseUuid)}/provision`;\n const res = await checkedFetch(\n url,\n {\n headers: { Authorization: `Bearer ${authToken}` },\n },\n undefined,\n fetchFn,\n );\n return await parseJsonResponse<FredLeaseProvision>(res, url);\n}\n\nexport interface FredActionResponse {\n readonly status: string;\n}\n\nexport async function restartLease(\n providerUrl: string,\n leaseUuid: string,\n authToken: string,\n fetchFn?: typeof globalThis.fetch,\n): Promise<FredActionResponse> {\n const validated = validateProviderUrl(providerUrl);\n const url = `${validated}/v1/leases/${encodeURIComponent(leaseUuid)}/restart`;\n const res = await checkedFetch(\n url,\n {\n method: 'POST',\n headers: { Authorization: `Bearer ${authToken}` },\n },\n undefined,\n fetchFn,\n );\n return await parseJsonResponse<FredActionResponse>(res, url);\n}\n\nexport async function updateLease(\n providerUrl: string,\n leaseUuid: string,\n payload: Uint8Array,\n authToken: string,\n fetchFn?: typeof globalThis.fetch,\n): Promise<FredActionResponse> {\n const validated = validateProviderUrl(providerUrl);\n const url = `${validated}/v1/leases/${encodeURIComponent(leaseUuid)}/update`;\n // The provider expects JSON with a base64-encoded payload (Go []byte field).\n const b64 = toBase64(payload);\n const res = await checkedFetch(\n url,\n {\n method: 'POST',\n headers: {\n Authorization: `Bearer ${authToken}`,\n 'Content-Type': 'application/json',\n },\n body: JSON.stringify({ payload: b64 }),\n },\n undefined,\n fetchFn,\n );\n return await parseJsonResponse<FredActionResponse>(res, url);\n}\n\nexport interface FredLeaseRelease {\n readonly version: number;\n readonly image: string;\n readonly status: string;\n readonly created_at: string;\n readonly error?: string;\n readonly manifest?: string;\n}\n\nexport interface FredLeaseReleases {\n readonly lease_uuid: string;\n readonly tenant: string;\n readonly provider_uuid: string;\n readonly releases: readonly FredLeaseRelease[];\n}\n\nexport async function getLeaseReleases(\n providerUrl: string,\n leaseUuid: string,\n authToken: string,\n fetchFn?: typeof globalThis.fetch,\n): Promise<FredLeaseReleases> {\n const validated = validateProviderUrl(providerUrl);\n const url = `${validated}/v1/leases/${encodeURIComponent(leaseUuid)}/releases`;\n const res = await checkedFetch(\n url,\n {\n headers: { Authorization: `Bearer ${authToken}` },\n },\n undefined,\n fetchFn,\n );\n return await parseJsonResponse<FredLeaseReleases>(res, url);\n}\n\nexport interface FredLeaseInfo {\n readonly host: string;\n readonly ports?: Record<string, unknown>;\n}\n\nexport async function getLeaseInfo(\n providerUrl: string,\n leaseUuid: string,\n authToken: string,\n fetchFn?: typeof globalThis.fetch,\n): Promise<FredLeaseInfo> {\n const validated = validateProviderUrl(providerUrl);\n const url = `${validated}/v1/leases/${encodeURIComponent(leaseUuid)}/info`;\n const res = await checkedFetch(\n url,\n {\n headers: { Authorization: `Bearer ${authToken}` },\n },\n undefined,\n fetchFn,\n );\n return await parseJsonResponse<FredLeaseInfo>(res, url);\n}\n\nexport type TerminalChainLeaseState = 'closed' | 'rejected' | 'expired';\n\nexport interface TerminalChainState {\n readonly state: TerminalChainLeaseState;\n}\n\nexport interface PollOptions {\n readonly intervalMs?: number;\n readonly timeoutMs?: number;\n readonly abortSignal?: AbortSignal;\n readonly onProgress?: (status: FredLeaseStatus) => void;\n /** Runs once per iteration before the provider is queried. Non-null return throws; errors propagate. */\n readonly checkChainState?: () => Promise<TerminalChainState | null>;\n}\n\nconst CHAIN_STATE_TO_LEASE_STATE: Record<TerminalChainLeaseState, LeaseState> =\n {\n closed: LeaseState.LEASE_STATE_CLOSED,\n rejected: LeaseState.LEASE_STATE_REJECTED,\n expired: LeaseState.LEASE_STATE_EXPIRED,\n };\n\nfunction leaseStateName(state: LeaseState): string {\n return LeaseState[state] ?? String(state);\n}\n\n/**\n * Provider `provision_status` values (fred backend `ProvisionStatus`) that mean\n * the lease is not yet confirmed healthy while the chain lease is already\n * ACTIVE — keep polling. `failing` is the pre-terminal window before `failed`\n * (the backend state machine only ever moves `failing → failed`, never back to\n * provisioning, so waiting is bounded). `unknown` is the backend's indeterminate\n * signal — an unrecognized container status or a state-machine read error — and\n * likewise is \"not confirmed ready\", so we wait for it to settle to\n * `ready`/`failed` rather than reporting it as success. A status string this\n * client does not recognize at all (a genuinely future value) is NOT listed\n * here; the ACTIVE branch treats it as settled (see below).\n */\nconst PROVISION_IN_PROGRESS: ReadonlySet<string> = new Set([\n 'provisioning',\n 'restarting',\n 'updating',\n 'failing',\n 'unknown',\n]);\n\n/**\n * Provider `provision_status` values that mean provisioning will not become\n * healthy. The chain lease is ACTIVE, but the deployment has effectively failed\n * (or is being torn down) — surface it as an error instead of a ready lease.\n */\nconst PROVISION_FAILED: ReadonlySet<string> = new Set([\n 'failed',\n 'deprovisioning',\n]);\n\n/**\n * Thrown by pollLeaseUntilReady when the caller's checkChainState callback\n * reports a terminal lease state on-chain. Extends ProviderApiError so\n * existing catchers keep working; use `instanceof TerminalChainStateError`\n * or read `chainState` to distinguish from provider-reported terminal states.\n */\nexport interface TerminalChainStateContext {\n readonly lease_uuid?: string;\n readonly providerUuid?: string;\n readonly providerUrl?: string;\n}\n\nexport class TerminalChainStateError extends ProviderApiError {\n public readonly chainState: TerminalChainLeaseState;\n public readonly leaseUuid: string;\n public readonly providerUuid?: string;\n public readonly providerUrl?: string;\n /**\n * Structured context for downstream classifiers (e.g. agent-core's\n * classify-deploy-error). `lease_uuid` is always present so callers can name\n * the affected lease without re-deriving it from the message; provider keys\n * appear once `withContext` enriches the error.\n */\n public readonly details: {\n readonly lease_uuid: string;\n readonly provider_uuid?: string;\n readonly provider_url?: string;\n };\n\n constructor(\n leaseUuid: string,\n chainState: TerminalChainLeaseState,\n context?: TerminalChainStateContext,\n ) {\n const mapped = CHAIN_STATE_TO_LEASE_STATE[chainState];\n super(\n 0,\n `Lease ${leaseUuid} entered terminal state ${leaseStateName(mapped)} on chain`,\n );\n this.name = 'TerminalChainStateError';\n this.chainState = chainState;\n this.leaseUuid = leaseUuid;\n this.providerUuid = context?.providerUuid;\n this.providerUrl = context?.providerUrl;\n this.details = {\n lease_uuid: context?.lease_uuid ?? leaseUuid,\n provider_uuid: context?.providerUuid,\n provider_url: context?.providerUrl,\n };\n Object.setPrototypeOf(this, TerminalChainStateError.prototype);\n }\n\n /**\n * Returns a new instance with the same lease/state and the supplied context,\n * preserving the original stack trace so debugging points to where the\n * terminal state was first detected.\n */\n withContext(context: TerminalChainStateContext): TerminalChainStateError {\n const enriched = new TerminalChainStateError(\n this.leaseUuid,\n this.chainState,\n context,\n );\n if (this.stack) enriched.stack = this.stack;\n return enriched;\n }\n}\n\nfunction abortableSleep(ms: number, signal?: AbortSignal): Promise<void> {\n if (!signal) return new Promise((resolve) => setTimeout(resolve, ms));\n signal.throwIfAborted();\n return new Promise<void>((resolve, reject) => {\n const onAbort = () => {\n clearTimeout(timer);\n reject(\n signal.reason ??\n new DOMException('The operation was aborted', 'AbortError'),\n );\n };\n const timer = setTimeout(() => {\n signal.removeEventListener('abort', onAbort);\n resolve();\n }, ms);\n signal.addEventListener('abort', onAbort, { once: true });\n });\n}\n\nexport async function pollLeaseUntilReady(\n providerUrl: string,\n leaseUuid: string,\n authToken: string | (() => Promise<string>),\n opts: PollOptions = {},\n fetchFn?: typeof globalThis.fetch,\n): Promise<FredLeaseStatus> {\n const {\n intervalMs = 3_000,\n timeoutMs = 120_000,\n abortSignal,\n onProgress,\n checkChainState,\n } = opts;\n const deadline = Date.now() + timeoutMs;\n let lastState: LeaseState | undefined;\n let lastProvisionStatus: string | undefined;\n\n while (Date.now() < deadline) {\n abortSignal?.throwIfAborted();\n if (checkChainState) {\n const chainState = await checkChainState();\n if (chainState) {\n throw new TerminalChainStateError(leaseUuid, chainState.state);\n }\n abortSignal?.throwIfAborted();\n }\n const token =\n typeof authToken === 'function' ? await authToken() : authToken;\n abortSignal?.throwIfAborted();\n const status = await getLeaseStatus(providerUrl, leaseUuid, token, fetchFn);\n lastState = status.state;\n lastProvisionStatus = status.provision_status;\n onProgress?.(status);\n switch (status.state) {\n case LeaseState.LEASE_STATE_ACTIVE: {\n // The chain lease is ACTIVE, but the provider may still be pulling the\n // image / starting the container — or the container may have crashed.\n // Gate readiness on provision_status so callers never observe a lease as\n // ready mid-provision. An absent field, or a status string this client\n // does not recognize (a future value), is treated as settled —\n // forward-compat, and it preserves the original ACTIVE-returns behavior\n // for providers that don't populate the field.\n const ps = status.provision_status;\n if (ps !== undefined) {\n if (PROVISION_FAILED.has(ps)) {\n throw new ProviderApiError(\n 0,\n `Lease ${leaseUuid} is ACTIVE but provisioning ${ps}${\n status.last_error ? `: ${status.last_error}` : ''\n }`,\n );\n }\n if (PROVISION_IN_PROGRESS.has(ps)) {\n break; // still provisioning — keep polling\n }\n }\n return status;\n }\n case LeaseState.LEASE_STATE_PENDING:\n break;\n case LeaseState.LEASE_STATE_CLOSED:\n case LeaseState.LEASE_STATE_REJECTED:\n case LeaseState.LEASE_STATE_EXPIRED:\n throw new ProviderApiError(\n 0,\n `Lease ${leaseUuid} entered terminal state ${leaseStateName(status.state)}`,\n );\n default:\n throw new ProviderApiError(\n 0,\n `Lease ${leaseUuid} returned unexpected state ${leaseStateName(status.state)}`,\n );\n }\n await abortableSleep(intervalMs, abortSignal);\n }\n\n throw new ProviderApiError(\n 0,\n `Lease ${leaseUuid} poll timed out after ${timeoutMs}ms (last state: ${lastState !== undefined ? leaseStateName(lastState) : 'unknown'}, provision_status: ${lastProvisionStatus ?? 'unknown'})`,\n );\n}\n"],"mappings":";;;;AAaA,MAAa,WAAW;AA+BxB,eAAsB,eACpB,aACA,WACA,WACA,SAC0B;CAE1B,MAAM,MAAM,GADM,oBAAoB,WACf,EAAE,aAAa,mBAAmB,SAAS,EAAE;CASpE,MAAM,MAAM,MAAM,kBAAkC,MARlC,aAChB,KACA,EACE,SAAS,EAAE,eAAe,UAAU,YAAY,EAClD,GACA,KAAA,GACA,OACF,GACyD,GAAG;CAC5D,MAAM,QAAQ,mBAAmB,IAAI,KAAK;CAC1C,IAAI,UAAU,WAAW,cACvB,OAAO,KACL,8CAA8C,IAAI,MAAM,cAAc,UAAU,wEAElF;CAEF,OAAO;EAAE,GAAG;EAAK;CAAM;AACzB;AASA,eAAsB,aACpB,aACA,WACA,WACA,MACA,SACwB;CACxB,MAAM,YAAY,oBAAoB,WAAW;CACjD,MAAM,aAAa,SAAS,KAAA,IAAY,KAAK,IAAI,MAAM,QAAQ,IAAI,KAAA;CACnE,MAAM,KAAK,eAAe,KAAA,IAAY,SAAS,eAAe;CAC9D,MAAM,MAAM,GAAG,UAAU,aAAa,mBAAmB,SAAS,EAAE,OAAO;CAS3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BACR,GACA,SAAS,UAAU,6BAA6B,eAAe,OAAO,KAAK,GAC7E;EACJ;EACA,MAAM,eAAe,YAAY,WAAW;CAC9C;CAEA,MAAM,IAAI,iBACR,GACA,SAAS,UAAU,wBAAwB,UAAU,kBAAkB,cAAc,KAAA,IAAY,eAAe,SAAS,IAAI,UAAU,sBAAsB,uBAAuB,UAAU,EAChM;AACF"}
|
|
1
|
+
{"version":3,"file":"fred.js","names":[],"sources":["../../src/http/fred.ts"],"sourcesContent":["import { toBase64 } from '@cosmjs/encoding';\nimport type {\n FredActionResponse,\n FredInstanceInfo,\n FredLeaseInfo,\n FredLeaseLogs,\n FredLeaseProvision,\n FredLeaseRelease,\n FredLeaseReleases,\n FredLeaseStatus,\n FredServiceStatus,\n} from '@manifest-network/manifest-mcp-core';\nimport {\n LeaseState,\n leaseStateFromJSON,\n logger,\n} from '@manifest-network/manifest-mcp-core';\nimport {\n checkedFetch,\n ProviderApiError,\n parseJsonResponse,\n validateProviderUrl,\n} from './provider.js';\n\nexport type {\n FredActionResponse,\n FredInstanceInfo,\n FredLeaseInfo,\n FredLeaseLogs,\n FredLeaseProvision,\n FredLeaseRelease,\n FredLeaseReleases,\n FredLeaseStatus,\n FredServiceStatus,\n};\n\nexport const MAX_TAIL = 1000;\n\n/** Raw wire shape before LeaseState conversion */\ninterface RawLeaseStatus extends Omit<FredLeaseStatus, 'state'> {\n readonly state: string;\n}\n\nexport async function getLeaseStatus(\n providerUrl: string,\n leaseUuid: string,\n authToken: string,\n fetchFn?: typeof globalThis.fetch,\n): Promise<FredLeaseStatus> {\n const validated = validateProviderUrl(providerUrl);\n const url = `${validated}/v1/leases/${encodeURIComponent(leaseUuid)}/status`;\n const res = await checkedFetch(\n url,\n {\n headers: { Authorization: `Bearer ${authToken}` },\n },\n undefined,\n fetchFn,\n );\n const raw = await parseJsonResponse<RawLeaseStatus>(res, url);\n const state = leaseStateFromJSON(raw.state);\n if (state === LeaseState.UNRECOGNIZED) {\n logger.warn(\n `[getLeaseStatus] Unrecognized lease state \"${raw.state}\" for lease ${leaseUuid}. ` +\n 'The provider may be running a newer version than the client supports.',\n );\n }\n return { ...raw, state };\n}\n\nexport async function getLeaseLogs(\n providerUrl: string,\n leaseUuid: string,\n authToken: string,\n tail?: number,\n fetchFn?: typeof globalThis.fetch,\n): Promise<FredLeaseLogs> {\n const validated = validateProviderUrl(providerUrl);\n const cappedTail = tail !== undefined ? Math.min(tail, MAX_TAIL) : undefined;\n const qs = cappedTail !== undefined ? `?tail=${cappedTail}` : '';\n const url = `${validated}/v1/leases/${encodeURIComponent(leaseUuid)}/logs${qs}`;\n const res = await checkedFetch(\n url,\n {\n headers: { Authorization: `Bearer ${authToken}` },\n },\n undefined,\n fetchFn,\n );\n return await parseJsonResponse<FredLeaseLogs>(res, url);\n}\n\nexport async function getLeaseProvision(\n providerUrl: string,\n leaseUuid: string,\n authToken: string,\n fetchFn?: typeof globalThis.fetch,\n): Promise<FredLeaseProvision> {\n const validated = validateProviderUrl(providerUrl);\n const url = `${validated}/v1/leases/${encodeURIComponent(leaseUuid)}/provision`;\n const res = await checkedFetch(\n url,\n {\n headers: { Authorization: `Bearer ${authToken}` },\n },\n undefined,\n fetchFn,\n );\n return await parseJsonResponse<FredLeaseProvision>(res, url);\n}\n\nexport async function restartLease(\n providerUrl: string,\n leaseUuid: string,\n authToken: string,\n fetchFn?: typeof globalThis.fetch,\n): Promise<FredActionResponse> {\n const validated = validateProviderUrl(providerUrl);\n const url = `${validated}/v1/leases/${encodeURIComponent(leaseUuid)}/restart`;\n const res = await checkedFetch(\n url,\n {\n method: 'POST',\n headers: { Authorization: `Bearer ${authToken}` },\n },\n undefined,\n fetchFn,\n );\n return await parseJsonResponse<FredActionResponse>(res, url);\n}\n\nexport async function updateLease(\n providerUrl: string,\n leaseUuid: string,\n payload: Uint8Array,\n authToken: string,\n fetchFn?: typeof globalThis.fetch,\n): Promise<FredActionResponse> {\n const validated = validateProviderUrl(providerUrl);\n const url = `${validated}/v1/leases/${encodeURIComponent(leaseUuid)}/update`;\n // The provider expects JSON with a base64-encoded payload (Go []byte field).\n const b64 = toBase64(payload);\n const res = await checkedFetch(\n url,\n {\n method: 'POST',\n headers: {\n Authorization: `Bearer ${authToken}`,\n 'Content-Type': 'application/json',\n },\n body: JSON.stringify({ payload: b64 }),\n },\n undefined,\n fetchFn,\n );\n return await parseJsonResponse<FredActionResponse>(res, url);\n}\n\nexport async function getLeaseReleases(\n providerUrl: string,\n leaseUuid: string,\n authToken: string,\n fetchFn?: typeof globalThis.fetch,\n): Promise<FredLeaseReleases> {\n const validated = validateProviderUrl(providerUrl);\n const url = `${validated}/v1/leases/${encodeURIComponent(leaseUuid)}/releases`;\n const res = await checkedFetch(\n url,\n {\n headers: { Authorization: `Bearer ${authToken}` },\n },\n undefined,\n fetchFn,\n );\n return await parseJsonResponse<FredLeaseReleases>(res, url);\n}\n\nexport async function getLeaseInfo(\n providerUrl: string,\n leaseUuid: string,\n authToken: string,\n fetchFn?: typeof globalThis.fetch,\n): Promise<FredLeaseInfo> {\n const validated = validateProviderUrl(providerUrl);\n const url = `${validated}/v1/leases/${encodeURIComponent(leaseUuid)}/info`;\n const res = await checkedFetch(\n url,\n {\n headers: { Authorization: `Bearer ${authToken}` },\n },\n undefined,\n fetchFn,\n );\n return await parseJsonResponse<FredLeaseInfo>(res, url);\n}\n\nexport type TerminalChainLeaseState = 'closed' | 'rejected' | 'expired';\n\nexport interface TerminalChainState {\n readonly state: TerminalChainLeaseState;\n}\n\nexport interface PollOptions {\n readonly intervalMs?: number;\n readonly timeoutMs?: number;\n readonly abortSignal?: AbortSignal;\n readonly onProgress?: (status: FredLeaseStatus) => void;\n /** Runs once per iteration before the provider is queried. Non-null return throws; errors propagate. */\n readonly checkChainState?: () => Promise<TerminalChainState | null>;\n}\n\nconst CHAIN_STATE_TO_LEASE_STATE: Record<TerminalChainLeaseState, LeaseState> =\n {\n closed: LeaseState.LEASE_STATE_CLOSED,\n rejected: LeaseState.LEASE_STATE_REJECTED,\n expired: LeaseState.LEASE_STATE_EXPIRED,\n };\n\nfunction leaseStateName(state: LeaseState): string {\n return LeaseState[state] ?? String(state);\n}\n\n/**\n * Provider `provision_status` values (fred backend `ProvisionStatus`) that mean\n * the lease is not yet confirmed healthy while the chain lease is already\n * ACTIVE — keep polling. `failing` is the pre-terminal window before `failed`\n * (the backend state machine only ever moves `failing → failed`, never back to\n * provisioning, so waiting is bounded). `unknown` is the backend's indeterminate\n * signal — an unrecognized container status or a state-machine read error — and\n * likewise is \"not confirmed ready\", so we wait for it to settle to\n * `ready`/`failed` rather than reporting it as success. A status string this\n * client does not recognize at all (a genuinely future value) is NOT listed\n * here; the ACTIVE branch treats it as settled (see below).\n */\nexport const PROVISION_IN_PROGRESS: ReadonlySet<string> = new Set([\n 'provisioning',\n 'restarting',\n 'updating',\n 'failing',\n 'unknown',\n]);\n\n/**\n * Provider `provision_status` values that mean provisioning will not become\n * healthy. The chain lease is ACTIVE, but the deployment has effectively failed\n * (or is being torn down) — surface it as an error instead of a ready lease.\n */\nexport const PROVISION_FAILED: ReadonlySet<string> = new Set([\n 'failed',\n 'deprovisioning',\n]);\n\n/**\n * Thrown by pollLeaseUntilReady when the caller's checkChainState callback\n * reports a terminal lease state on-chain. Extends ProviderApiError so\n * existing catchers keep working; use `instanceof TerminalChainStateError`\n * or read `chainState` to distinguish from provider-reported terminal states.\n */\nexport interface TerminalChainStateContext {\n readonly lease_uuid?: string;\n readonly providerUuid?: string;\n readonly providerUrl?: string;\n}\n\nexport class TerminalChainStateError extends ProviderApiError {\n public readonly chainState: TerminalChainLeaseState;\n public readonly leaseUuid: string;\n public readonly providerUuid?: string;\n public readonly providerUrl?: string;\n /**\n * Structured context for downstream classifiers (e.g. agent-core's\n * classify-deploy-error). `lease_uuid` is always present so callers can name\n * the affected lease without re-deriving it from the message; provider keys\n * appear once `withContext` enriches the error.\n */\n public readonly details: {\n readonly lease_uuid: string;\n readonly provider_uuid?: string;\n readonly provider_url?: string;\n };\n\n constructor(\n leaseUuid: string,\n chainState: TerminalChainLeaseState,\n context?: TerminalChainStateContext,\n ) {\n const mapped = CHAIN_STATE_TO_LEASE_STATE[chainState];\n super(\n 0,\n `Lease ${leaseUuid} entered terminal state ${leaseStateName(mapped)} on chain`,\n );\n this.name = 'TerminalChainStateError';\n this.chainState = chainState;\n this.leaseUuid = leaseUuid;\n this.providerUuid = context?.providerUuid;\n this.providerUrl = context?.providerUrl;\n this.details = {\n lease_uuid: context?.lease_uuid ?? leaseUuid,\n provider_uuid: context?.providerUuid,\n provider_url: context?.providerUrl,\n };\n Object.setPrototypeOf(this, TerminalChainStateError.prototype);\n }\n\n /**\n * Returns a new instance with the same lease/state and the supplied context,\n * preserving the original stack trace so debugging points to where the\n * terminal state was first detected.\n */\n withContext(context: TerminalChainStateContext): TerminalChainStateError {\n const enriched = new TerminalChainStateError(\n this.leaseUuid,\n this.chainState,\n context,\n );\n if (this.stack) enriched.stack = this.stack;\n return enriched;\n }\n}\n\nfunction abortableSleep(ms: number, signal?: AbortSignal): Promise<void> {\n if (!signal) return new Promise((resolve) => setTimeout(resolve, ms));\n signal.throwIfAborted();\n return new Promise<void>((resolve, reject) => {\n const onAbort = () => {\n clearTimeout(timer);\n reject(\n signal.reason ??\n new DOMException('The operation was aborted', 'AbortError'),\n );\n };\n const timer = setTimeout(() => {\n signal.removeEventListener('abort', onAbort);\n resolve();\n }, ms);\n signal.addEventListener('abort', onAbort, { once: true });\n });\n}\n\nexport async function pollLeaseUntilReady(\n providerUrl: string,\n leaseUuid: string,\n authToken: string | (() => Promise<string>),\n opts: PollOptions = {},\n fetchFn?: typeof globalThis.fetch,\n): Promise<FredLeaseStatus> {\n const {\n intervalMs = 3_000,\n timeoutMs = 120_000,\n abortSignal,\n onProgress,\n checkChainState,\n } = opts;\n const deadline = Date.now() + timeoutMs;\n let lastState: LeaseState | undefined;\n let lastProvisionStatus: string | undefined;\n\n while (Date.now() < deadline) {\n abortSignal?.throwIfAborted();\n if (checkChainState) {\n const chainState = await checkChainState();\n if (chainState) {\n throw new TerminalChainStateError(leaseUuid, chainState.state);\n }\n abortSignal?.throwIfAborted();\n }\n const token =\n typeof authToken === 'function' ? await authToken() : authToken;\n abortSignal?.throwIfAborted();\n const status = await getLeaseStatus(providerUrl, leaseUuid, token, fetchFn);\n lastState = status.state;\n lastProvisionStatus = status.provision_status;\n onProgress?.(status);\n switch (status.state) {\n case LeaseState.LEASE_STATE_ACTIVE: {\n // The chain lease is ACTIVE, but the provider may still be pulling the\n // image / starting the container — or the container may have crashed.\n // Gate readiness on provision_status so callers never observe a lease as\n // ready mid-provision. An absent field, or a status string this client\n // does not recognize (a future value), is treated as settled —\n // forward-compat, and it preserves the original ACTIVE-returns behavior\n // for providers that don't populate the field.\n const ps = status.provision_status;\n if (ps !== undefined) {\n if (PROVISION_FAILED.has(ps)) {\n throw new ProviderApiError(\n 0,\n `Lease ${leaseUuid} is ACTIVE but provisioning ${ps}${\n status.last_error ? `: ${status.last_error}` : ''\n }`,\n );\n }\n if (PROVISION_IN_PROGRESS.has(ps)) {\n break; // still provisioning — keep polling\n }\n }\n return status;\n }\n case LeaseState.LEASE_STATE_PENDING:\n break;\n case LeaseState.LEASE_STATE_CLOSED:\n case LeaseState.LEASE_STATE_REJECTED:\n case LeaseState.LEASE_STATE_EXPIRED:\n throw new ProviderApiError(\n 0,\n `Lease ${leaseUuid} entered terminal state ${leaseStateName(status.state)}`,\n );\n default:\n throw new ProviderApiError(\n 0,\n `Lease ${leaseUuid} returned unexpected state ${leaseStateName(status.state)}`,\n );\n }\n await abortableSleep(intervalMs, abortSignal);\n }\n\n throw new ProviderApiError(\n 0,\n `Lease ${leaseUuid} poll timed out after ${timeoutMs}ms (last state: ${lastState !== undefined ? leaseStateName(lastState) : 'unknown'}, provision_status: ${lastProvisionStatus ?? 'unknown'})`,\n );\n}\n"],"mappings":";;;;AAoCA,MAAa,WAAW;AAOxB,eAAsB,eACpB,aACA,WACA,WACA,SAC0B;CAE1B,MAAM,MAAM,GADM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;EACxD,aAAa,eAAe;EAC5B,MAAM,SAAS,MAAM,eAAe,aAAa,WAAW,OAAO,OAAO;EAC1E,YAAY,OAAO;EACnB,sBAAsB,OAAO;EAC7B,aAAa,MAAM;EACnB,QAAQ,OAAO,OAAf;GACE,KAAK,WAAW,oBAAoB;IAQlC,MAAM,KAAK,OAAO;IAClB,IAAI,OAAO,KAAA,GAAW;KACpB,IAAI,iBAAiB,IAAI,EAAE,GACzB,MAAM,IAAI,iBACR,GACA,SAAS,UAAU,8BAA8B,KAC/C,OAAO,aAAa,KAAK,OAAO,eAAe,IAEnD;KAEF,IAAI,sBAAsB,IAAI,EAAE,GAC9B;IAEJ;IACA,OAAO;GACT;GACA,KAAK,WAAW,qBACd;GACF,KAAK,WAAW;GAChB,KAAK,WAAW;GAChB,KAAK,WAAW,qBACd,MAAM,IAAI,iBACR,GACA,SAAS,UAAU,0BAA0B,eAAe,OAAO,KAAK,GAC1E;GACF,SACE,MAAM,IAAI,iBACR,GACA,SAAS,UAAU,6BAA6B,eAAe,OAAO,KAAK,GAC7E;EACJ;EACA,MAAM,eAAe,YAAY,WAAW;CAC9C;CAEA,MAAM,IAAI,iBACR,GACA,SAAS,UAAU,wBAAwB,UAAU,kBAAkB,cAAc,KAAA,IAAY,eAAe,SAAS,IAAI,UAAU,sBAAsB,uBAAuB,UAAU,EAChM;AACF"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Signer } from "@manifest-network/manifest-mcp-core";
|
|
2
|
+
|
|
3
|
+
//#region src/http/provider-auth.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Fred-owned driven port: mints ADR-036 provider/lease-data auth tokens. The AWS
|
|
6
|
+
* credential-provider idiom (an injected token provider), backed by core's `Signer`
|
|
7
|
+
* at the `createFredClient` root and by an `AuthTokenService` instance at the server.
|
|
8
|
+
* Address-PARAM (not address-bound) so it composes onto `FredAuthCtx`.
|
|
9
|
+
*/
|
|
10
|
+
interface ProviderAuthPort {
|
|
11
|
+
providerToken(input: {
|
|
12
|
+
address: string;
|
|
13
|
+
leaseUuid: string;
|
|
14
|
+
}): Promise<string>;
|
|
15
|
+
leaseDataToken(input: {
|
|
16
|
+
address: string;
|
|
17
|
+
leaseUuid: string;
|
|
18
|
+
metaHashHex: string;
|
|
19
|
+
}): Promise<string>;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Build a `ProviderAuthPort` from core's `Signer`. Instantiates `new AuthTokenService(signer)`
|
|
23
|
+
* — `Signer` (= `AuthSigner`) is structurally assignable to `AuthTokenService`'s `WalletProvider`
|
|
24
|
+
* ctor param (both expose `getAddress`/`signArbitrary`; method-param bivariance), verified by tsc.
|
|
25
|
+
* Fresh-per-call (ADR-036 deterministic signing makes a reused token a replay-rejected duplicate),
|
|
26
|
+
* so no caching. `chainId` is reserved (OI-CHAIN) — NOT embedded in the message yet.
|
|
27
|
+
*/
|
|
28
|
+
declare function createProviderAuth(signer: Signer, opts: {
|
|
29
|
+
chainId: string;
|
|
30
|
+
}): ProviderAuthPort;
|
|
31
|
+
//#endregion
|
|
32
|
+
export { ProviderAuthPort, createProviderAuth };
|
|
33
|
+
//# sourceMappingURL=provider-auth.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider-auth.d.ts","names":[],"sources":["../../src/http/provider-auth.ts"],"mappings":";;;;;AASA;;;;UAAiB,gBAAA;EACf,aAAA,CAAc,KAAA;IAAS,OAAA;IAAiB,SAAA;EAAA,IAAsB,OAAA;EAC9D,cAAA,CAAe,KAAA;IACb,OAAA;IACA,SAAA;IACA,WAAA;EAAA,IACE,OAAO;AAAA;;AAAA;AAUb;;;;;iBAAgB,kBAAA,CACd,MAAA,EAAQ,MAAA,EACR,IAAA;EAAQ,OAAA;AAAA,IACP,gBAAgB"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { AuthTokenService } from "./auth-token-service.js";
|
|
2
|
+
//#region src/http/provider-auth.ts
|
|
3
|
+
/**
|
|
4
|
+
* Build a `ProviderAuthPort` from core's `Signer`. Instantiates `new AuthTokenService(signer)`
|
|
5
|
+
* — `Signer` (= `AuthSigner`) is structurally assignable to `AuthTokenService`'s `WalletProvider`
|
|
6
|
+
* ctor param (both expose `getAddress`/`signArbitrary`; method-param bivariance), verified by tsc.
|
|
7
|
+
* Fresh-per-call (ADR-036 deterministic signing makes a reused token a replay-rejected duplicate),
|
|
8
|
+
* so no caching. `chainId` is reserved (OI-CHAIN) — NOT embedded in the message yet.
|
|
9
|
+
*/
|
|
10
|
+
function createProviderAuth(signer, opts) {
|
|
11
|
+
opts.chainId;
|
|
12
|
+
const svc = new AuthTokenService(signer);
|
|
13
|
+
return {
|
|
14
|
+
providerToken: ({ address, leaseUuid }) => svc.providerToken(address, leaseUuid),
|
|
15
|
+
leaseDataToken: ({ address, leaseUuid, metaHashHex }) => svc.leaseDataToken(address, leaseUuid, metaHashHex)
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
//#endregion
|
|
19
|
+
export { createProviderAuth };
|
|
20
|
+
|
|
21
|
+
//# sourceMappingURL=provider-auth.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider-auth.js","names":[],"sources":["../../src/http/provider-auth.ts"],"sourcesContent":["import type { Signer } from '@manifest-network/manifest-mcp-core';\nimport { AuthTokenService } from './auth-token-service.js';\n\n/**\n * Fred-owned driven port: mints ADR-036 provider/lease-data auth tokens. The AWS\n * credential-provider idiom (an injected token provider), backed by core's `Signer`\n * at the `createFredClient` root and by an `AuthTokenService` instance at the server.\n * Address-PARAM (not address-bound) so it composes onto `FredAuthCtx`.\n */\nexport interface ProviderAuthPort {\n providerToken(input: { address: string; leaseUuid: string }): Promise<string>;\n leaseDataToken(input: {\n address: string;\n leaseUuid: string;\n metaHashHex: string;\n }): Promise<string>;\n}\n\n/**\n * Build a `ProviderAuthPort` from core's `Signer`. Instantiates `new AuthTokenService(signer)`\n * — `Signer` (= `AuthSigner`) is structurally assignable to `AuthTokenService`'s `WalletProvider`\n * ctor param (both expose `getAddress`/`signArbitrary`; method-param bivariance), verified by tsc.\n * Fresh-per-call (ADR-036 deterministic signing makes a reused token a replay-rejected duplicate),\n * so no caching. `chainId` is reserved (OI-CHAIN) — NOT embedded in the message yet.\n */\nexport function createProviderAuth(\n signer: Signer,\n opts: { chainId: string },\n): ProviderAuthPort {\n void opts.chainId; // reserved (OI-CHAIN); silences noUnusedParameters\n const svc = new AuthTokenService(signer);\n return {\n providerToken: ({ address, leaseUuid }) =>\n svc.providerToken(address, leaseUuid),\n leaseDataToken: ({ address, leaseUuid, metaHashHex }) =>\n svc.leaseDataToken(address, leaseUuid, metaHashHex),\n };\n}\n"],"mappings":";;;;;;;;;AAyBA,SAAgB,mBACd,QACA,MACkB;CAClB,KAAU;CACV,MAAM,MAAM,IAAI,iBAAiB,MAAM;CACvC,OAAO;EACL,gBAAgB,EAAE,SAAS,gBACzB,IAAI,cAAc,SAAS,SAAS;EACtC,iBAAiB,EAAE,SAAS,WAAW,kBACrC,IAAI,eAAe,SAAS,WAAW,WAAW;CACtD;AACF"}
|
package/dist/http/provider.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { ConnectionDetails, InstanceInfo, LeaseConnectionResponse, ServiceConnectionDetails } from "@manifest-network/manifest-mcp-core";
|
|
2
|
+
|
|
1
3
|
//#region src/http/provider.d.ts
|
|
2
4
|
declare class ProviderApiError extends Error {
|
|
3
5
|
readonly status: number;
|
|
@@ -16,37 +18,8 @@ interface ProviderHealthResponse {
|
|
|
16
18
|
};
|
|
17
19
|
}
|
|
18
20
|
declare function getProviderHealth(providerApiUrl: string, timeoutMs?: number, fetchFn?: typeof globalThis.fetch): Promise<ProviderHealthResponse>;
|
|
19
|
-
interface InstanceInfo {
|
|
20
|
-
readonly instance_index: number;
|
|
21
|
-
readonly container_id: string;
|
|
22
|
-
readonly image: string;
|
|
23
|
-
readonly status: string;
|
|
24
|
-
readonly ports?: Record<string, unknown>;
|
|
25
|
-
readonly fqdn?: string;
|
|
26
|
-
}
|
|
27
|
-
interface ServiceConnectionDetails {
|
|
28
|
-
readonly host?: string;
|
|
29
|
-
readonly fqdn?: string;
|
|
30
|
-
readonly ports?: Record<string, unknown>;
|
|
31
|
-
readonly instances?: readonly InstanceInfo[];
|
|
32
|
-
}
|
|
33
|
-
interface ConnectionDetails {
|
|
34
|
-
readonly host: string;
|
|
35
|
-
readonly fqdn?: string;
|
|
36
|
-
readonly ports?: Record<string, unknown>;
|
|
37
|
-
readonly instances?: readonly InstanceInfo[];
|
|
38
|
-
readonly protocol?: string;
|
|
39
|
-
readonly metadata?: Record<string, string>;
|
|
40
|
-
readonly services?: Record<string, ServiceConnectionDetails>;
|
|
41
|
-
}
|
|
42
|
-
interface LeaseConnectionResponse {
|
|
43
|
-
readonly lease_uuid: string;
|
|
44
|
-
readonly tenant: string;
|
|
45
|
-
readonly provider_uuid: string;
|
|
46
|
-
readonly connection: ConnectionDetails;
|
|
47
|
-
}
|
|
48
21
|
declare function getLeaseConnectionInfo(providerApiUrl: string, leaseUuid: string, authToken: string, fetchFn?: typeof globalThis.fetch): Promise<LeaseConnectionResponse>;
|
|
49
22
|
declare function uploadLeaseData(providerApiUrl: string, leaseUuid: string, payload: Uint8Array, authToken: string, fetchFn?: typeof globalThis.fetch, abortSignal?: AbortSignal): Promise<void>;
|
|
50
23
|
//#endregion
|
|
51
|
-
export { ConnectionDetails, InstanceInfo, LeaseConnectionResponse, ProviderApiError, ProviderHealthResponse, ServiceConnectionDetails, checkedFetch, getLeaseConnectionInfo, getProviderHealth, parseJsonResponse, uploadLeaseData, validateProviderUrl };
|
|
24
|
+
export { type ConnectionDetails, type InstanceInfo, type LeaseConnectionResponse, ProviderApiError, ProviderHealthResponse, type ServiceConnectionDetails, checkedFetch, getLeaseConnectionInfo, getProviderHealth, parseJsonResponse, uploadLeaseData, validateProviderUrl };
|
|
52
25
|
//# sourceMappingURL=provider.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider.d.ts","names":[],"sources":["../../src/http/provider.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"provider.d.ts","names":[],"sources":["../../src/http/provider.ts"],"mappings":";;;cAAa,gBAAA,SAAyB,KAAK;EAAA,SACzB,MAAA;cAEJ,MAAA,UAAgB,OAAA;AAAA;AAAA,iBAUd,mBAAA,CAAoB,GAAW;AAAA,iBAwBzB,YAAA,CACpB,GAAA,UACA,IAAA,GAAO,WAAA,EACP,SAAA,WACA,OAAA,UAAgB,UAAA,CAAW,KAAA,GAC1B,OAAA,CAAQ,QAAA;AAAA,iBAyEW,iBAAA,IACpB,GAAA,EAAK,QAAA,EACL,GAAA,WACC,OAAA,CAAQ,CAAA;AAAA,UAcM,sBAAA;EAAA,SACN,MAAA;EAAA,SACA,aAAA;EAAA,SACA,MAAA;IAAA,SACE,KAAA;MAAA,SAAmB,MAAA;IAAA;EAAA;AAAA;AAAA,iBAIV,iBAAA,CACpB,cAAA,UACA,SAAA,WACA,OAAA,UAAiB,UAAA,CAAW,KAAA,GAC3B,OAAA,CAAQ,sBAAA;AAAA,iBAqBW,sBAAA,CACpB,cAAA,UACA,SAAA,UACA,SAAA,UACA,OAAA,UAAiB,UAAA,CAAW,KAAA,GAC3B,OAAA,CAAQ,uBAAA;AAAA,iBAcW,eAAA,CACpB,cAAA,UACA,SAAA,UACA,OAAA,EAAS,UAAA,EACT,SAAA,UACA,OAAA,UAAiB,UAAA,CAAW,KAAA,EAC5B,WAAA,GAAc,WAAA,GACb,OAAA"}
|