@finchtech/cli 0.1.0 → 0.2.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 (3) hide show
  1. package/README.md +2 -2
  2. package/dist/finch.js +680 -338
  3. package/package.json +16 -15
package/dist/finch.js CHANGED
@@ -3738,7 +3738,7 @@ var init_testnet_purchase_v1 = __esm({
3738
3738
  });
3739
3739
  testnetPurchaseTransactionResponseSchema = strictObjectSchema({
3740
3740
  operationId: canonicalUuidSchema,
3741
- chainId: { const: "84532" },
3741
+ chainId: { type: "string", enum: ["84532", "8453"] },
3742
3742
  deploymentHash: hex32Schema,
3743
3743
  paymentTokenAddress: evmAddressSchema,
3744
3744
  totalPaidAtomic: positiveIntegerStringSchema,
@@ -28380,6 +28380,7 @@ function getAgentServiceDeployment(environment3) {
28380
28380
  );
28381
28381
  return Object.freeze({
28382
28382
  chainId: value.network.chainId,
28383
+ networkName: value.network.name,
28383
28384
  protocolAddress: value.contracts.protocol,
28384
28385
  protocolImplementationAddress: value.contracts.protocolImplementation ?? null,
28385
28386
  protocolProxyAdminAddress: value.contracts.protocolProxyAdmin ?? null,
@@ -35825,7 +35826,17 @@ var init_public = __esm({
35825
35826
  });
35826
35827
 
35827
35828
  // ../../packages/skill-market-contracts/src/deployment.ts
35828
- var environment2, deployment, delivery, SKILL_V3_SOURCE_COMMIT, SKILL_V3_CHAIN_ID, SKILL_V3_DEPLOYMENT_BLOCK, SKILL_V3_FACTORY_DEPLOYMENT_BLOCK, SKILL_V3_CHAIN_TAG, SKILL_V3_ADDRESSES, SKILL_V3_CHAIN_IDS;
35829
+ function skillV3SourceCommit(chainId) {
35830
+ const selected = SKILL_V3_DEPLOYMENTS.find((candidate) => candidate.chainId === chainId);
35831
+ if (selected === void 0) {
35832
+ throw new TypeError(`Skill V3 is not deployed to chain ${chainId} in this environment.`);
35833
+ }
35834
+ return selected.sourceCommit;
35835
+ }
35836
+ function skillV3ChainTag(chainId) {
35837
+ return getSkillDeliveryDeployment(environment2, chainId).chainTag;
35838
+ }
35839
+ var environment2, deployment, delivery, SKILL_V3_DEPLOYMENTS, SKILL_V3_CHAIN_IDS, SKILL_V3_CHAIN_ID, SKILL_V3_SOURCE_COMMIT, SKILL_V3_DEPLOYMENT_BLOCK, SKILL_V3_FACTORY_DEPLOYMENT_BLOCK, SKILL_V3_CHAIN_TAG, SKILL_V3_ADDRESSES;
35829
35840
  var init_deployment = __esm({
35830
35841
  "../../packages/skill-market-contracts/src/deployment.ts"() {
35831
35842
  "use strict";
@@ -35835,8 +35846,17 @@ var init_deployment = __esm({
35835
35846
  environment2 = resolveSkillProtocolEnvironment(process.env.FINCH_ENVIRONMENT);
35836
35847
  deployment = getSkillProtocolDeployment(environment2);
35837
35848
  delivery = getSkillDeliveryDeployment(environment2, deployment.chainId);
35838
- SKILL_V3_SOURCE_COMMIT = deployment.sourceCommit;
35849
+ SKILL_V3_DEPLOYMENTS = Object.freeze(
35850
+ getSkillProtocolChainIds(environment2).map((chainId) => {
35851
+ const selected = getSkillProtocolDeployment(environment2, chainId);
35852
+ return Object.freeze({ chainId, sourceCommit: selected.sourceCommit });
35853
+ })
35854
+ );
35855
+ SKILL_V3_CHAIN_IDS = Object.freeze(
35856
+ SKILL_V3_DEPLOYMENTS.map(({ chainId }) => chainId)
35857
+ );
35839
35858
  SKILL_V3_CHAIN_ID = deployment.chainId;
35859
+ SKILL_V3_SOURCE_COMMIT = skillV3SourceCommit(SKILL_V3_CHAIN_ID);
35840
35860
  SKILL_V3_DEPLOYMENT_BLOCK = BigInt(deployment.deploymentBlock);
35841
35861
  SKILL_V3_FACTORY_DEPLOYMENT_BLOCK = BigInt(deployment.factoryDeploymentBlock);
35842
35862
  SKILL_V3_CHAIN_TAG = delivery.chainTag;
@@ -35848,18 +35868,27 @@ var init_deployment = __esm({
35848
35868
  skillMarket: deployment.skillMarketAddress,
35849
35869
  feeRouter: deployment.feeRouterAddress
35850
35870
  });
35851
- SKILL_V3_CHAIN_IDS = getSkillProtocolChainIds(environment2);
35852
35871
  }
35853
35872
  });
35854
35873
 
35855
35874
  // ../../packages/skill-market-contracts/src/schemas.ts
35875
+ function authorityVariants(properties) {
35876
+ return Object.freeze(SKILL_V3_DEPLOYMENTS.map(({ chainId, sourceCommit }) => strictObjectSchema3({
35877
+ ...properties,
35878
+ sourceCommit: { const: sourceCommit },
35879
+ chainId: { const: chainId }
35880
+ })));
35881
+ }
35882
+ function authorityObjectSchema(properties) {
35883
+ return Object.freeze({ oneOf: authorityVariants(properties) });
35884
+ }
35856
35885
  function skillIntentConfirmationIdempotencyKey(chainId, transactionHash3) {
35857
- if (chainId !== 8453 && chainId !== 84532 || !/^0x[0-9a-f]{64}$/u.test(transactionHash3)) {
35886
+ if (!SKILL_V3_CHAIN_IDS.includes(chainId) || !/^0x[0-9a-f]{64}$/u.test(transactionHash3)) {
35858
35887
  throw new TypeError("Skill confirmation identity is invalid.");
35859
35888
  }
35860
35889
  return `skill-intent-confirm:${chainId}:${transactionHash3}`;
35861
35890
  }
35862
- var versionSchema, skillCategorySchema, nullableSkillCategorySchema, skillSigningAuthoritySchema, skillSourceKindSchema, skillContentModeSchema, skillListRequestSchema, skillDetailRequestSchema, skillDeliveryRequestSchema, skillPurchaseIntentRequestSchema, skillConvertIntentRequestSchema, skillPublicationPrepareRequestFields, skillPublicationPrepareRequestSchema, skillVersionPrepareRequestSchema, skillSetUnitPriceIntentRequestSchema, skillSetMaxSupplyIntentRequestSchema, skillDisplayCategoryUpdateRequestSchema, skillDisplayCategoryResponseSchema, sellStatusSchema, skillProjectionSchema, skillSearchProjectionSchema, skillListResponseSchema, skillLitDataSchema, skillDeliveryFields, skillDeliveryResponseSchema, intentResponseFields, skillBuyerIntentResponseSchema, skillSetUnitPriceIntentResponseSchema, skillSetMaxSupplyIntentResponseSchema, skillIntentResponseSchema, publishLocalActionSchema, versionLocalActionSchema, skillPublicationPrepareResponseSchema, skillVersionPrepareResponseSchema, nullableText, boundedTextList, skillPresentationSchema, skillDetailResponseSchema, skillManageRequestSchema, skillManageResponseSchema, skillPresentationPrepareRequestSchema, skillPresentationPrepareResponseSchema, skillAssetPrepareRequestSchema, skillAssetPrepareResponseSchema, skillIntentConfirmRequestSchema, skillIntentConfirmResponseSchema, skillErrorEnvelopeSchema;
35891
+ var versionSchema, skillChainIdSchema, skillCategorySchema, nullableSkillCategorySchema, skillSigningAuthoritySchema, skillSourceKindSchema, skillContentModeSchema, skillListRequestSchema, skillDetailRequestSchema, skillDeliveryRequestSchema, skillPurchaseIntentRequestSchema, skillConvertIntentRequestSchema, skillPublicationPrepareRequestFields, skillPublicationPrepareRequestSchema, skillVersionPrepareRequestSchema, skillSetUnitPriceIntentRequestSchema, skillSetMaxSupplyIntentRequestSchema, skillDisplayCategoryUpdateRequestSchema, skillDisplayCategoryResponseSchema, sellStatusSchema, skillProjectionSchema, skillSearchProjectionSchema, skillListResponseSchema, skillLitDataSchema, skillDeliveryFields, skillDeliveryResponseSchema, intentResponseFields, skillBuyerIntentResponseVariants, skillSetUnitPriceIntentResponseVariants, skillSetMaxSupplyIntentResponseVariants, skillIntentResponseSchema, publishLocalActionSchema, versionLocalActionSchema, skillPublicationPrepareResponseSchema, skillVersionPrepareResponseSchema, nullableText, boundedTextList, skillPresentationSchema, skillDetailResponseSchema, skillManageRequestSchema, skillManageResponseSchema, skillPresentationPrepareRequestSchema, skillPresentationPrepareResponseSchema, skillAssetPrepareRequestSchema, skillAssetPrepareResponseSchema, skillIntentConfirmRequestSchema, skillIntentConfirmResponseSchema, skillErrorEnvelopeSchema;
35863
35892
  var init_schemas4 = __esm({
35864
35893
  "../../packages/skill-market-contracts/src/schemas.ts"() {
35865
35894
  "use strict";
@@ -35868,6 +35897,7 @@ var init_schemas4 = __esm({
35868
35897
  init_public();
35869
35898
  init_public();
35870
35899
  versionSchema = { type: "integer", minimum: 1, maximum: 4294967295 };
35900
+ skillChainIdSchema = { type: "integer", enum: SKILL_V3_CHAIN_IDS };
35871
35901
  skillCategorySchema = { type: "string", enum: SKILL_CATEGORIES };
35872
35902
  nullableSkillCategorySchema = { type: ["string", "null"], enum: [...SKILL_CATEGORIES, null] };
35873
35903
  skillSigningAuthoritySchema = strictObjectSchema3({
@@ -35891,25 +35921,30 @@ var init_schemas4 = __esm({
35891
35921
  cursor: { type: "string", minLength: 1, maxLength: 512, pattern: "^[A-Za-z0-9_-]+$" }
35892
35922
  }, []);
35893
35923
  skillDetailRequestSchema = strictObjectSchema3({
35924
+ chainId: skillChainIdSchema,
35894
35925
  skillId: positiveIntegerStringSchema2,
35895
35926
  version: versionSchema
35896
- }, ["skillId"]);
35927
+ }, ["chainId", "skillId"]);
35897
35928
  skillDeliveryRequestSchema = strictObjectSchema3({
35929
+ chainId: skillChainIdSchema,
35898
35930
  skillId: positiveIntegerStringSchema2,
35899
35931
  version: versionSchema
35900
35932
  });
35901
35933
  skillPurchaseIntentRequestSchema = strictObjectSchema3({
35934
+ chainId: skillChainIdSchema,
35902
35935
  skillId: positiveIntegerStringSchema2,
35903
35936
  version: versionSchema,
35904
35937
  quantity: positiveIntegerStringSchema2
35905
35938
  });
35906
35939
  skillConvertIntentRequestSchema = strictObjectSchema3({
35940
+ chainId: skillChainIdSchema,
35907
35941
  skillId: positiveIntegerStringSchema2,
35908
35942
  fromVersion: versionSchema,
35909
35943
  toVersion: versionSchema,
35910
35944
  quantity: positiveIntegerStringSchema2
35911
35945
  });
35912
35946
  skillPublicationPrepareRequestFields = {
35947
+ chainId: skillChainIdSchema,
35913
35948
  slug: { type: "string", minLength: 9, maxLength: 200, pattern: "^[a-z0-9]+(?:-[a-z0-9]+)*_finchip$" },
35914
35949
  name: { type: "string", minLength: 1, maxLength: 200 },
35915
35950
  category: skillCategorySchema,
@@ -35924,23 +35959,28 @@ var init_schemas4 = __esm({
35924
35959
  };
35925
35960
  skillPublicationPrepareRequestSchema = strictObjectSchema3(skillPublicationPrepareRequestFields);
35926
35961
  skillVersionPrepareRequestSchema = strictObjectSchema3({
35962
+ chainId: skillChainIdSchema,
35927
35963
  skillId: positiveIntegerStringSchema2,
35928
35964
  sourceKind: skillSourceKindSchema,
35929
35965
  contentMode: skillContentModeSchema
35930
35966
  });
35931
35967
  skillSetUnitPriceIntentRequestSchema = strictObjectSchema3({
35968
+ chainId: skillChainIdSchema,
35932
35969
  skillId: positiveIntegerStringSchema2,
35933
35970
  unitPrice: unsignedIntegerStringSchema
35934
35971
  });
35935
35972
  skillSetMaxSupplyIntentRequestSchema = strictObjectSchema3({
35973
+ chainId: skillChainIdSchema,
35936
35974
  skillId: positiveIntegerStringSchema2,
35937
35975
  maxSupply: unsignedIntegerStringSchema
35938
35976
  });
35939
35977
  skillDisplayCategoryUpdateRequestSchema = strictObjectSchema3({
35978
+ chainId: skillChainIdSchema,
35940
35979
  skillId: positiveIntegerStringSchema2,
35941
35980
  displayCategory: nullableSkillCategorySchema
35942
35981
  });
35943
35982
  skillDisplayCategoryResponseSchema = strictObjectSchema3({
35983
+ chainId: skillChainIdSchema,
35944
35984
  skillId: positiveIntegerStringSchema2,
35945
35985
  declaredCategory: { type: "string", minLength: 1, maxLength: 100 },
35946
35986
  displayCategory: { type: ["string", "null"], minLength: 1, maxLength: 100 },
@@ -35953,7 +35993,7 @@ var init_schemas4 = __esm({
35953
35993
  supplyAvailable: { type: "boolean" }
35954
35994
  });
35955
35995
  skillProjectionSchema = strictObjectSchema3({
35956
- chainId: { const: SKILL_V3_CHAIN_ID },
35996
+ chainId: skillChainIdSchema,
35957
35997
  skillId: positiveIntegerStringSchema2,
35958
35998
  slug: { type: "string" },
35959
35999
  name: { type: "string" },
@@ -35977,7 +36017,7 @@ var init_schemas4 = __esm({
35977
36017
  sellStatus: sellStatusSchema
35978
36018
  });
35979
36019
  skillSearchProjectionSchema = strictObjectSchema3({
35980
- chainId: { const: SKILL_V3_CHAIN_ID },
36020
+ chainId: skillChainIdSchema,
35981
36021
  skillId: positiveIntegerStringSchema2,
35982
36022
  slug: { type: "string" },
35983
36023
  name: { type: "string" },
@@ -36012,7 +36052,7 @@ var init_schemas4 = __esm({
36012
36052
  chain: { type: "string", minLength: 1, maxLength: 100 }
36013
36053
  });
36014
36054
  skillDeliveryFields = {
36015
- chainId: { const: SKILL_V3_CHAIN_ID },
36055
+ chainId: skillChainIdSchema,
36016
36056
  skillId: positiveIntegerStringSchema2,
36017
36057
  version: versionSchema,
36018
36058
  packageURI: { type: "string", minLength: 1, maxLength: 2e3 },
@@ -36023,28 +36063,26 @@ var init_schemas4 = __esm({
36023
36063
  strictObjectSchema3({ ...skillDeliveryFields, entitledWallet: addressSchema2, plaintext: { const: false }, litData: skillLitDataSchema })
36024
36064
  ] });
36025
36065
  intentResponseFields = {
36026
- sourceCommit: { const: SKILL_V3_SOURCE_COMMIT },
36027
- chainId: { const: SKILL_V3_CHAIN_ID },
36028
36066
  to: addressSchema2,
36029
36067
  data: { type: "string", pattern: "^0x(?:[0-9a-fA-F]{2})+$" },
36030
36068
  value: unsignedIntegerStringSchema,
36031
36069
  summary: { type: "string", minLength: 1, maxLength: 500 }
36032
36070
  };
36033
- skillBuyerIntentResponseSchema = strictObjectSchema3({
36071
+ skillBuyerIntentResponseVariants = authorityVariants({
36034
36072
  kind: { type: "string", enum: ["purchase", "convert"] },
36035
36073
  ...intentResponseFields,
36036
36074
  walletAddress: addressSchema2,
36037
36075
  request: openObjectSchema2,
36038
36076
  signingAuthority: skillSigningAuthoritySchema
36039
36077
  });
36040
- skillSetUnitPriceIntentResponseSchema = strictObjectSchema3({
36078
+ skillSetUnitPriceIntentResponseVariants = authorityVariants({
36041
36079
  kind: { const: "set_unit_price" },
36042
36080
  ...intentResponseFields,
36043
36081
  walletAddress: addressSchema2,
36044
36082
  request: skillSetUnitPriceIntentRequestSchema,
36045
36083
  signingAuthority: skillSigningAuthoritySchema
36046
36084
  });
36047
- skillSetMaxSupplyIntentResponseSchema = strictObjectSchema3({
36085
+ skillSetMaxSupplyIntentResponseVariants = authorityVariants({
36048
36086
  kind: { const: "set_max_supply" },
36049
36087
  ...intentResponseFields,
36050
36088
  walletAddress: addressSchema2,
@@ -36052,9 +36090,9 @@ var init_schemas4 = __esm({
36052
36090
  signingAuthority: skillSigningAuthoritySchema
36053
36091
  });
36054
36092
  skillIntentResponseSchema = Object.freeze({ oneOf: [
36055
- skillBuyerIntentResponseSchema,
36056
- skillSetUnitPriceIntentResponseSchema,
36057
- skillSetMaxSupplyIntentResponseSchema
36093
+ ...skillBuyerIntentResponseVariants,
36094
+ ...skillSetUnitPriceIntentResponseVariants,
36095
+ ...skillSetMaxSupplyIntentResponseVariants
36058
36096
  ] });
36059
36097
  publishLocalActionSchema = strictObjectSchema3({
36060
36098
  client: { const: "finch" },
@@ -36065,10 +36103,8 @@ var init_schemas4 = __esm({
36065
36103
  command: { const: "skill version-submit" },
36066
36104
  arguments: strictObjectSchema3({ skillId: positiveIntegerStringSchema2 })
36067
36105
  });
36068
- skillPublicationPrepareResponseSchema = strictObjectSchema3({
36106
+ skillPublicationPrepareResponseSchema = authorityObjectSchema({
36069
36107
  kind: { const: "publish" },
36070
- sourceCommit: { const: SKILL_V3_SOURCE_COMMIT },
36071
- chainId: { const: SKILL_V3_CHAIN_ID },
36072
36108
  walletAddress: addressSchema2,
36073
36109
  signingAuthority: skillSigningAuthoritySchema,
36074
36110
  request: strictObjectSchema3({
@@ -36076,10 +36112,8 @@ var init_schemas4 = __esm({
36076
36112
  }),
36077
36113
  localAction: publishLocalActionSchema
36078
36114
  });
36079
- skillVersionPrepareResponseSchema = strictObjectSchema3({
36115
+ skillVersionPrepareResponseSchema = authorityObjectSchema({
36080
36116
  kind: { const: "version" },
36081
- sourceCommit: { const: SKILL_V3_SOURCE_COMMIT },
36082
- chainId: { const: SKILL_V3_CHAIN_ID },
36083
36117
  walletAddress: addressSchema2,
36084
36118
  signingAuthority: skillSigningAuthoritySchema,
36085
36119
  skillId: positiveIntegerStringSchema2,
@@ -36139,7 +36173,10 @@ var init_schemas4 = __esm({
36139
36173
  ...skillProjectionSchema.properties,
36140
36174
  presentation: { oneOf: [{ type: "null" }, skillPresentationSchema] }
36141
36175
  });
36142
- skillManageRequestSchema = strictObjectSchema3({ skillId: positiveIntegerStringSchema2 });
36176
+ skillManageRequestSchema = strictObjectSchema3({
36177
+ chainId: skillChainIdSchema,
36178
+ skillId: positiveIntegerStringSchema2
36179
+ });
36143
36180
  skillManageResponseSchema = strictObjectSchema3({
36144
36181
  skill: skillProjectionSchema,
36145
36182
  contentMode: skillContentModeSchema,
@@ -36147,13 +36184,12 @@ var init_schemas4 = __esm({
36147
36184
  presentation: { oneOf: [{ type: "null" }, skillPresentationSchema] }
36148
36185
  });
36149
36186
  skillPresentationPrepareRequestSchema = strictObjectSchema3({
36187
+ chainId: skillChainIdSchema,
36150
36188
  skillId: positiveIntegerStringSchema2,
36151
36189
  presentation: skillPresentationSchema
36152
36190
  });
36153
- skillPresentationPrepareResponseSchema = strictObjectSchema3({
36191
+ skillPresentationPrepareResponseSchema = authorityObjectSchema({
36154
36192
  kind: { const: "presentation" },
36155
- sourceCommit: { const: SKILL_V3_SOURCE_COMMIT },
36156
- chainId: { const: SKILL_V3_CHAIN_ID },
36157
36193
  walletAddress: addressSchema2,
36158
36194
  signingAuthority: skillSigningAuthoritySchema,
36159
36195
  skillId: positiveIntegerStringSchema2,
@@ -36167,13 +36203,12 @@ var init_schemas4 = __esm({
36167
36203
  })
36168
36204
  });
36169
36205
  skillAssetPrepareRequestSchema = strictObjectSchema3({
36206
+ chainId: skillChainIdSchema,
36170
36207
  skillId: positiveIntegerStringSchema2,
36171
36208
  assetKind: { const: "cover" }
36172
36209
  });
36173
- skillAssetPrepareResponseSchema = strictObjectSchema3({
36210
+ skillAssetPrepareResponseSchema = authorityObjectSchema({
36174
36211
  kind: { const: "asset_upload" },
36175
- sourceCommit: { const: SKILL_V3_SOURCE_COMMIT },
36176
- chainId: { const: SKILL_V3_CHAIN_ID },
36177
36212
  walletAddress: addressSchema2,
36178
36213
  skillId: positiveIntegerStringSchema2,
36179
36214
  assetKind: { const: "cover" },
@@ -36192,14 +36227,18 @@ var init_schemas4 = __esm({
36192
36227
  })
36193
36228
  });
36194
36229
  skillIntentConfirmRequestSchema = strictObjectSchema3({
36195
- chainId: { type: "integer", enum: [8453, 84532] },
36230
+ chainId: skillChainIdSchema,
36196
36231
  transactionHash: transactionHashSchema2
36197
36232
  });
36198
36233
  skillIntentConfirmResponseSchema = strictObjectSchema3({
36199
36234
  status: { type: "string", enum: ["projected", "indexing_pending"] }
36200
36235
  });
36201
36236
  skillErrorEnvelopeSchema = strictObjectSchema3({
36202
- error: strictObjectSchema3({ code: { type: "string" }, message: { type: "string" } })
36237
+ error: strictObjectSchema3({
36238
+ code: { type: "string" },
36239
+ message: { type: "string" },
36240
+ traceId: { type: "string", minLength: 1, maxLength: 128, pattern: "^[A-Za-z0-9_-]+$" }
36241
+ })
36203
36242
  });
36204
36243
  }
36205
36244
  });
@@ -36387,7 +36426,21 @@ function parseRemoteError(response, value) {
36387
36426
  }
36388
36427
  return envelope;
36389
36428
  }
36390
- var import_ajv, CLI_MERCHANT_OPERATION_IDS, CliHttpError, ajv, validatorCache, AgentCliHttpClient;
36429
+ function parseSkillRemoteError(value) {
36430
+ if (value === null || typeof value !== "object" || Array.isArray(value)) throw new TypeError("Skill error envelope is invalid.");
36431
+ const error51 = value.error;
36432
+ if (error51 === null || typeof error51 !== "object" || Array.isArray(error51)) throw new TypeError("Skill error envelope is invalid.");
36433
+ const candidate = error51;
36434
+ if (typeof candidate.code !== "string" || candidate.code.length < 1 || typeof candidate.message !== "string" || candidate.message.length < 1 || candidate.traceId !== void 0 && (typeof candidate.traceId !== "string" || !/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/u.test(candidate.traceId))) {
36435
+ throw new TypeError("Skill error envelope is invalid.");
36436
+ }
36437
+ return Object.freeze({ error: Object.freeze({
36438
+ code: candidate.code,
36439
+ message: candidate.message,
36440
+ ...candidate.traceId === void 0 ? {} : { traceId: candidate.traceId }
36441
+ }) });
36442
+ }
36443
+ var import_ajv, CLI_MERCHANT_OPERATION_IDS, CliHttpError, ajv, validatorCache, oauthAuthorizationResponseSchema, oauthErrorResponseSchema, AgentCliHttpClient;
36391
36444
  var init_api2 = __esm({
36392
36445
  "src/api.ts"() {
36393
36446
  "use strict";
@@ -36433,6 +36486,29 @@ var init_api2 = __esm({
36433
36486
  ajv.addFormat("date-time", (value) => Number.isFinite(Date.parse(value)));
36434
36487
  ajv.addFormat("uri", (value) => URL.canParse(value));
36435
36488
  validatorCache = /* @__PURE__ */ new WeakMap();
36489
+ oauthAuthorizationResponseSchema = {
36490
+ type: "object",
36491
+ additionalProperties: false,
36492
+ required: ["authorized", "accountId", "walletAddress", "clientName", "scopes", "callbackUrl"],
36493
+ properties: {
36494
+ authorized: { const: true },
36495
+ accountId: { type: "string", format: "uuid" },
36496
+ walletAddress: { type: "string", pattern: "^0x[0-9a-f]{40}$" },
36497
+ clientName: { type: "string", minLength: 1, maxLength: 128 },
36498
+ scopes: { type: "array", minItems: 1, uniqueItems: true, items: { type: "string", minLength: 1 } },
36499
+ callbackUrl: { type: "string", format: "uri" }
36500
+ }
36501
+ };
36502
+ oauthErrorResponseSchema = {
36503
+ type: "object",
36504
+ additionalProperties: false,
36505
+ required: ["error", "error_description"],
36506
+ properties: {
36507
+ error: { type: "string", minLength: 1 },
36508
+ error_description: { type: "string", minLength: 1 },
36509
+ trace_id: { type: "string", format: "uuid" }
36510
+ }
36511
+ };
36436
36512
  AgentCliHttpClient = class {
36437
36513
  origin;
36438
36514
  fetchImplementation;
@@ -36500,8 +36576,13 @@ var init_api2 = __esm({
36500
36576
  throw new CliHttpError("CLI_REMOTE_UNAVAILABLE", null, { cause });
36501
36577
  }
36502
36578
  if (response.status !== expectedStatus) {
36503
- await readBoundedJson(response).catch(() => null);
36504
- throw new CliHttpError("CLI_REMOTE_UNAVAILABLE", response.status);
36579
+ try {
36580
+ const envelope = parseSkillRemoteError(await readBoundedJson(response));
36581
+ throw new CliHttpError("CLI_REMOTE_UNAVAILABLE", response.status, { envelope });
36582
+ } catch (cause) {
36583
+ if (cause instanceof CliHttpError) throw cause;
36584
+ throw new CliHttpError("CLI_RESPONSE_INVALID", response.status, { cause });
36585
+ }
36505
36586
  }
36506
36587
  return response;
36507
36588
  }
@@ -36527,6 +36608,24 @@ var init_api2 = __esm({
36527
36608
  throw new CliHttpError("CLI_RESPONSE_INVALID", challenge2.status);
36528
36609
  }
36529
36610
  await challenge2.body?.cancel().catch(() => void 0);
36611
+ const resourceResponse = await this.publicFetch("/.well-known/oauth-protected-resource");
36612
+ if (resourceResponse.status !== 200) {
36613
+ await resourceResponse.body?.cancel().catch(() => void 0);
36614
+ throw new CliHttpError("CLI_REMOTE_UNAVAILABLE", resourceResponse.status);
36615
+ }
36616
+ const resource = jsonObject(await readBoundedJson(resourceResponse));
36617
+ if (resource.resource !== `${this.origin}/` || JSON.stringify(resource.authorization_servers) !== JSON.stringify([this.origin])) {
36618
+ throw new CliHttpError("CLI_RESPONSE_INVALID", resourceResponse.status);
36619
+ }
36620
+ const authorizationResponse = await this.publicFetch("/.well-known/oauth-authorization-server");
36621
+ if (authorizationResponse.status !== 200) {
36622
+ await authorizationResponse.body?.cancel().catch(() => void 0);
36623
+ throw new CliHttpError("CLI_REMOTE_UNAVAILABLE", authorizationResponse.status);
36624
+ }
36625
+ const authorization = jsonObject(await readBoundedJson(authorizationResponse));
36626
+ if (authorization.issuer !== this.origin || authorization.authorization_endpoint !== `${this.origin}/oauth/authorize` || authorization.token_endpoint !== `${this.origin}/oauth/token` || authorization.registration_endpoint !== `${this.origin}/oauth/register` || JSON.stringify(authorization.response_types_supported) !== JSON.stringify(["code"]) || JSON.stringify(authorization.grant_types_supported) !== JSON.stringify(["authorization_code", "refresh_token"]) || JSON.stringify(authorization.token_endpoint_auth_methods_supported) !== JSON.stringify(["none"]) || JSON.stringify(authorization.code_challenge_methods_supported) !== JSON.stringify(["S256"])) {
36627
+ throw new CliHttpError("CLI_RESPONSE_INVALID", authorizationResponse.status);
36628
+ }
36530
36629
  const manifestResponse = await this.publicFetch("/mcp/client-compatibility.json");
36531
36630
  if (manifestResponse.status !== 200) {
36532
36631
  await manifestResponse.body?.cancel().catch(() => void 0);
@@ -36539,15 +36638,16 @@ var init_api2 = __esm({
36539
36638
  throw new CliHttpError("CLI_RESPONSE_INVALID", manifestResponse.status);
36540
36639
  }
36541
36640
  const client = jsonObject(manifest.clients[0]);
36542
- const handoff = jsonObject(client.handoff);
36641
+ const install = jsonObject(client.install);
36642
+ const authorize = jsonObject(client.authorize);
36543
36643
  const verify = jsonObject(client.verify);
36544
- if (manifest.schemaVersion !== 2 || manifest.manifestId !== "finch.remote-mcp-clients" || mcp.serverName !== "finch" || mcp.url !== mcpUrl || mcp.transport !== "streamable_http" || mcp.authorization !== "agent_cli_session_handoff" || source.repository !== "https://github.com/FinchipAI/Finch-Site" || source.path !== "apps/mcp/src/client-compatibility.ts" || client.id !== "codex" || client.supportLevel !== "verified" || handoff.kind !== "finch_cli" || handoff.executable !== "finch" || JSON.stringify(handoff.arguments) !== JSON.stringify(["mcp", "launch", "codex"]) || verify.kind !== "harness_ui" || verify.surface !== "mcp_tools" || client.reload !== "new_session") {
36644
+ if (manifest.schemaVersion !== 3 || manifest.manifestId !== "finch.remote-mcp-clients" || mcp.serverName !== "finch" || mcp.url !== mcpUrl || mcp.transport !== "streamable_http" || mcp.authorization !== "oauth" || source.repository !== "https://github.com/FinchipAI/Finch-Site" || source.path !== "apps/mcp/src/client-compatibility.ts" || client.id !== "codex" || client.supportLevel !== "verified" || install.kind !== "native_cli" || install.executable !== "codex" || JSON.stringify(install.arguments) !== JSON.stringify(["mcp", "add", "finch", "--url", mcpUrl]) || authorize.kind !== "native_cli" || authorize.executable !== "codex" || JSON.stringify(authorize.arguments) !== JSON.stringify(["mcp", "login", "finch"]) || verify.kind !== "harness_ui" || verify.surface !== "mcp_tools" || client.reload !== "new_session") {
36545
36645
  throw new CliHttpError("CLI_RESPONSE_INVALID", manifestResponse.status);
36546
36646
  }
36547
36647
  return Object.freeze({
36548
36648
  url: mcpUrl,
36549
36649
  transport: "streamable_http",
36550
- authorization: "agent_cli_session_handoff",
36650
+ authorization: "oauth",
36551
36651
  compatibilityManifestUrl,
36552
36652
  supportedClients: Object.freeze(["codex"])
36553
36653
  });
@@ -36577,10 +36677,10 @@ var init_api2 = __esm({
36577
36677
  body: JSON.stringify(body)
36578
36678
  }));
36579
36679
  }
36580
- async resolveSkillId(slug, bearer) {
36680
+ async resolveSkillId(chainId, slug, bearer) {
36581
36681
  let response;
36582
36682
  try {
36583
- response = await this.fetchImplementation(`${this.origin}/api/skills/resolve?${new URLSearchParams({ slug })}`, {
36683
+ response = await this.fetchImplementation(`${this.origin}/api/skills/resolve?${new URLSearchParams({ chainId: String(chainId), slug })}`, {
36584
36684
  method: "GET",
36585
36685
  headers: { authorization: `Bearer ${bearer}` },
36586
36686
  redirect: "error",
@@ -36594,15 +36694,20 @@ var init_api2 = __esm({
36594
36694
  return null;
36595
36695
  }
36596
36696
  if (response.status !== 200) {
36597
- await readBoundedJson(response).catch(() => null);
36598
- throw new CliHttpError("CLI_REMOTE_UNAVAILABLE", response.status);
36697
+ try {
36698
+ const envelope = parseSkillRemoteError(await readBoundedJson(response));
36699
+ throw new CliHttpError("CLI_REMOTE_UNAVAILABLE", response.status, { envelope });
36700
+ } catch (cause) {
36701
+ if (cause instanceof CliHttpError) throw cause;
36702
+ throw new CliHttpError("CLI_RESPONSE_INVALID", response.status, { cause });
36703
+ }
36599
36704
  }
36600
36705
  const body = await readBoundedJson(response);
36601
36706
  if (typeof body?.skillId !== "string" || !/^[1-9][0-9]*$/u.test(body.skillId)) throw new CliHttpError("CLI_RESPONSE_INVALID", 200);
36602
36707
  return body.skillId;
36603
36708
  }
36604
- async readSkillCurrentVersion(skillId, bearer) {
36605
- const response = await this.skillFetch(`/api/skills/resolve?${new URLSearchParams({ skillId })}`, {
36709
+ async readSkillCurrentVersion(chainId, skillId, bearer) {
36710
+ const response = await this.skillFetch(`/api/skills/resolve?${new URLSearchParams({ chainId: String(chainId), skillId })}`, {
36606
36711
  method: "GET",
36607
36712
  headers: { authorization: `Bearer ${bearer}` },
36608
36713
  cache: "no-store"
@@ -36615,7 +36720,7 @@ var init_api2 = __esm({
36615
36720
  const response = await this.skillFetch("/api/skills/content-key", {
36616
36721
  method: "POST",
36617
36722
  headers: { authorization: `Bearer ${input.bearer}`, "content-type": "application/json" },
36618
- body: JSON.stringify({ skillId: input.skillId, version: input.version, wallet: input.wallet, message: input.message, signature: input.signature })
36723
+ body: JSON.stringify({ chainId: input.chainId, skillId: input.skillId, version: input.version, wallet: input.wallet, message: input.message, signature: input.signature })
36619
36724
  });
36620
36725
  const body = await readBoundedJson(response);
36621
36726
  if (body.scheme === "FINCHIP_V2" && typeof body.key === "string" && /^0x[0-9a-fA-F]{64}$/u.test(body.key) && body.contentKey === null) return Object.freeze({ scheme: body.scheme, key: body.key, contentKey: null });
@@ -36632,6 +36737,7 @@ var init_api2 = __esm({
36632
36737
  "content-type": "application/json"
36633
36738
  },
36634
36739
  body: JSON.stringify({
36740
+ chainId: input.chainId,
36635
36741
  skillId: input.skillId,
36636
36742
  version: input.version,
36637
36743
  contentKey: input.contentKey
@@ -36651,24 +36757,36 @@ var init_api2 = __esm({
36651
36757
  });
36652
36758
  return readBoundedBytes(response, 1, 10 * 1024 * 1024);
36653
36759
  }
36654
- async confirmSkillProjection(transactionHash3, bearer) {
36760
+ async confirmSkillProjection(chainId, transactionHash3, bearer) {
36655
36761
  let response;
36656
36762
  try {
36657
36763
  response = await this.fetchImplementation(`${this.origin}/api/skills/projection`, {
36658
36764
  method: "POST",
36659
36765
  redirect: "error",
36660
36766
  headers: { authorization: `Bearer ${bearer}`, "content-type": "application/json" },
36661
- body: JSON.stringify({ transactionHash: transactionHash3 })
36767
+ body: JSON.stringify({ chainId, transactionHash: transactionHash3 })
36662
36768
  });
36663
36769
  } catch {
36664
36770
  return "indexing_pending";
36665
36771
  }
36666
36772
  if (response.status !== 200 && response.status !== 202) {
36667
- await response.body?.cancel().catch(() => void 0);
36668
- return "indexing_pending";
36773
+ try {
36774
+ const envelope = parseSkillRemoteError(await readBoundedJson(response));
36775
+ throw new CliHttpError("CLI_REMOTE_UNAVAILABLE", response.status, { envelope });
36776
+ } catch (cause) {
36777
+ if (cause instanceof CliHttpError) throw cause;
36778
+ throw new CliHttpError("CLI_RESPONSE_INVALID", response.status, { cause });
36779
+ }
36780
+ }
36781
+ let body;
36782
+ try {
36783
+ body = await readBoundedJson(response);
36784
+ } catch (cause) {
36785
+ throw new CliHttpError("CLI_RESPONSE_INVALID", response.status, { cause });
36669
36786
  }
36670
- const body = await readBoundedJson(response).catch(() => null);
36671
- return body?.status === "projected" ? "projected" : "indexing_pending";
36787
+ if (response.status === 200 && body?.status === "projected") return "projected";
36788
+ if (response.status === 202 && body?.status === "indexing_pending") return "indexing_pending";
36789
+ throw new CliHttpError("CLI_RESPONSE_INVALID", response.status);
36672
36790
  }
36673
36791
  getSession(bearer) {
36674
36792
  const operation4 = IDENTITY_V1_OPERATIONS.session;
@@ -36680,6 +36798,26 @@ var init_api2 = __esm({
36680
36798
  bearer
36681
36799
  });
36682
36800
  }
36801
+ authorizeMcp(requestPath, bearer) {
36802
+ let parsed;
36803
+ try {
36804
+ parsed = new URL(requestPath, this.origin);
36805
+ } catch {
36806
+ throw new TypeError("MCP authorization request path is invalid.");
36807
+ }
36808
+ if (parsed.origin !== this.origin || parsed.pathname !== "/oauth/authorize" || parsed.hash !== "" || requestPath !== `${parsed.pathname}${parsed.search}` || parsed.search === "") {
36809
+ throw new TypeError("MCP authorization request path is invalid.");
36810
+ }
36811
+ return this.request({
36812
+ method: "post",
36813
+ path: requestPath,
36814
+ successStatus: 200,
36815
+ responseSchema: oauthAuthorizationResponseSchema,
36816
+ statusOnlyErrorSchema: oauthErrorResponseSchema,
36817
+ bearer,
36818
+ body: {}
36819
+ });
36820
+ }
36683
36821
  createChallenge(input) {
36684
36822
  const operation4 = IDENTITY_V1_OPERATIONS.challenge;
36685
36823
  return this.request({
@@ -37592,6 +37730,11 @@ function integer2(value, name, minimum = 1) {
37592
37730
  if (!Number.isInteger(value) || Number(value) < minimum || Number(value) > 4294967295) throw new TypeError(`${name} is invalid.`);
37593
37731
  return Number(value);
37594
37732
  }
37733
+ function skillChain(value, name = "Skill chain") {
37734
+ const chainId = integer2(value, name);
37735
+ if (!SKILL_V3_CHAIN_IDS.includes(chainId)) throw new TypeError(`${name} is not deployed in this environment.`);
37736
+ return chainId;
37737
+ }
37595
37738
  function deliveryPackageUri(value) {
37596
37739
  return string4(value, "Skill package URI", IPFS);
37597
37740
  }
@@ -37615,10 +37758,12 @@ function assertPublicationAuthority(authority, context) {
37615
37758
  return authority;
37616
37759
  }
37617
37760
  function assertAuthority(plan, kind, walletAddress2, requiresSigning = true) {
37618
- if (plan.kind !== kind || plan.sourceCommit !== SKILL_V3_SOURCE_COMMIT || plan.chainId !== SKILL_V3_CHAIN_ID || typeof plan.walletAddress !== "string" || plan.walletAddress.toLowerCase() !== walletAddress2.toLowerCase()) {
37619
- throw new TypeError("Skill local-action authority does not match the active TEST wallet and deployment.");
37761
+ const chainId = skillChain(plan.chainId);
37762
+ if (plan.kind !== kind || plan.sourceCommit !== skillV3SourceCommit(chainId) || typeof plan.walletAddress !== "string" || plan.walletAddress.toLowerCase() !== walletAddress2.toLowerCase()) {
37763
+ throw new TypeError("Skill local-action authority does not match the active wallet and deployment.");
37620
37764
  }
37621
37765
  if (requiresSigning) signingAuthority(plan.signingAuthority, walletAddress2);
37766
+ return chainId;
37622
37767
  }
37623
37768
  function assertLocalAction(value, command, skillId) {
37624
37769
  const action = object4(value, "Skill local action");
@@ -37633,9 +37778,9 @@ function assertLocalAction(value, command, skillId) {
37633
37778
  function intent(value, walletAddress2) {
37634
37779
  const parsed = object4(value, "Skill intent");
37635
37780
  exact(parsed, ["chainId", "to", "data", "value", "summary", "signingAuthority"], "Skill intent");
37636
- if (parsed.chainId !== SKILL_V3_CHAIN_ID) throw new TypeError("Skill intent chain is invalid.");
37781
+ const chainId = skillChain(parsed.chainId, "Skill intent chain");
37637
37782
  return Object.freeze({
37638
- chainId: SKILL_V3_CHAIN_ID,
37783
+ chainId,
37639
37784
  to: string4(parsed.to, "Skill intent target", /^0x[0-9a-fA-F]{40}$/u),
37640
37785
  data: string4(parsed.data, "Skill intent calldata", /^0x(?:[0-9a-fA-F]{2})+$/u),
37641
37786
  value: string4(parsed.value, "Skill intent value", DECIMAL),
@@ -37643,6 +37788,11 @@ function intent(value, walletAddress2) {
37643
37788
  signingAuthority: signingAuthority(parsed.signingAuthority, walletAddress2)
37644
37789
  });
37645
37790
  }
37791
+ function legacyIntent(value, walletAddress2, authority) {
37792
+ const prepared = object4(value, "Skill legacy intent");
37793
+ exact(prepared, ["chainId", "to", "data", "value", "summary"], "Skill legacy intent");
37794
+ return intent({ ...prepared, signingAuthority: authority }, walletAddress2);
37795
+ }
37646
37796
  async function readPublishablePath(inputPath) {
37647
37797
  const root = resolve2(inputPath);
37648
37798
  const rootStat = await lstat2(root);
@@ -37679,10 +37829,11 @@ function contentMode(value) {
37679
37829
  function publishPlan(value, context) {
37680
37830
  const plan = object4(value, "Skill publish plan");
37681
37831
  exact(plan, ["kind", "sourceCommit", "chainId", "walletAddress", "signingAuthority", "request", "localAction"], "Skill publish plan");
37682
- assertAuthority(plan, "publish", context.walletAddress);
37832
+ const chainId = assertAuthority(plan, "publish", context.walletAddress);
37683
37833
  assertLocalAction(plan.localAction, "skill publish-submit");
37684
37834
  const request = object4(plan.request, "Skill publish request");
37685
- exact(request, ["slug", "name", "category", "licenseTypeName", "imageURI", "sourceKind", "contentMode", "unitPrice", "maxSupply", "royaltyBPS", "usageLimit"], "Skill publish request");
37835
+ exact(request, ["chainId", "slug", "name", "category", "licenseTypeName", "imageURI", "sourceKind", "contentMode", "unitPrice", "maxSupply", "royaltyBPS", "usageLimit"], "Skill publish request");
37836
+ if (request.chainId !== chainId) throw new TypeError("Skill publish request chain is invalid.");
37686
37837
  string4(request.slug, "Skill slug");
37687
37838
  string4(request.name, "Skill name");
37688
37839
  string4(request.category, "Skill category");
@@ -37697,6 +37848,7 @@ function publishPlan(value, context) {
37697
37848
  string4(request.usageLimit, "Skill usageLimit", DECIMAL);
37698
37849
  if (!Number.isInteger(request.royaltyBPS) || Number(request.royaltyBPS) < 0 || Number(request.royaltyBPS) > 1e3) throw new TypeError("Skill royaltyBPS is invalid.");
37699
37850
  return {
37851
+ chainId,
37700
37852
  request,
37701
37853
  signingAuthority: assertPublicationAuthority(signingAuthority(plan.signingAuthority, context.walletAddress), context)
37702
37854
  };
@@ -37704,14 +37856,15 @@ function publishPlan(value, context) {
37704
37856
  function versionPlan(value, context) {
37705
37857
  const plan = object4(value, "Skill version plan");
37706
37858
  exact(plan, ["kind", "sourceCommit", "chainId", "walletAddress", "signingAuthority", "skillId", "currentVersion", "nextVersion", "currentManifestURI", "sourceKind", "contentMode", "localAction"], "Skill version plan");
37707
- assertAuthority(plan, "version", context.walletAddress);
37859
+ const chainId = assertAuthority(plan, "version", context.walletAddress);
37708
37860
  const skillId = string4(plan.skillId, "Skill id", /^[1-9][0-9]*$/u);
37709
37861
  assertLocalAction(plan.localAction, "skill version-submit", skillId);
37710
- const request = { skillId, sourceKind: sourceKind(plan.sourceKind), contentMode: contentMode(plan.contentMode) };
37862
+ const request = { chainId, skillId, sourceKind: sourceKind(plan.sourceKind), contentMode: contentMode(plan.contentMode) };
37711
37863
  const currentVersion = integer2(plan.currentVersion, "Current version");
37712
37864
  const nextVersion = integer2(plan.nextVersion, "Next version");
37713
37865
  if (nextVersion !== currentVersion + 1) throw new TypeError("Skill version plan does not advance exactly one version.");
37714
37866
  return {
37867
+ chainId,
37715
37868
  request,
37716
37869
  currentVersion,
37717
37870
  nextVersion,
@@ -37724,13 +37877,14 @@ function versionPlan(value, context) {
37724
37877
  function managePlan(value, walletAddress2, kind) {
37725
37878
  const plan = object4(value, `Skill ${kind} plan`);
37726
37879
  exact(plan, ["kind", "sourceCommit", "chainId", "to", "data", "value", "summary", "walletAddress", "signingAuthority", "request"], `Skill ${kind} plan`);
37727
- assertAuthority(plan, kind === "price" ? "set_unit_price" : "set_max_supply", walletAddress2);
37880
+ const chainId = assertAuthority(plan, kind === "price" ? "set_unit_price" : "set_max_supply", walletAddress2);
37728
37881
  const request = object4(plan.request, `Skill ${kind} request`);
37729
37882
  const field = kind === "price" ? "unitPrice" : "maxSupply";
37730
- exact(request, ["skillId", field], `Skill ${kind} request`);
37883
+ exact(request, ["chainId", "skillId", field], `Skill ${kind} request`);
37884
+ if (request.chainId !== chainId) throw new TypeError(`Skill ${kind} request chain is invalid.`);
37731
37885
  string4(request.skillId, "Skill id", /^[1-9][0-9]*$/u);
37732
37886
  string4(request[field], `Skill ${field}`, DECIMAL);
37733
- return { request, intent: intent({
37887
+ return { chainId, request, intent: intent({
37734
37888
  chainId: plan.chainId,
37735
37889
  to: plan.to,
37736
37890
  data: plan.data,
@@ -37753,14 +37907,16 @@ function presentationPlan(value, walletAddress2) {
37753
37907
  "presentation",
37754
37908
  "localAction"
37755
37909
  ], "Skill presentation plan");
37756
- assertAuthority(plan, "presentation", walletAddress2);
37910
+ const chainId = assertAuthority(plan, "presentation", walletAddress2);
37757
37911
  const skillId = string4(plan.skillId, "Skill id", /^[1-9][0-9]*$/u);
37758
37912
  assertLocalAction(plan.localAction, "skill presentation-submit", skillId);
37759
37913
  return {
37914
+ chainId,
37760
37915
  skillId,
37761
37916
  currentVersion: integer2(plan.currentVersion, "Current version"),
37762
37917
  currentManifestURI: string4(plan.currentManifestURI, "Current manifest URI", IPFS),
37763
- presentation: buildPresentation(plan.presentation)
37918
+ presentation: buildPresentation(plan.presentation),
37919
+ signingAuthority: signingAuthority(plan.signingAuthority, walletAddress2)
37764
37920
  };
37765
37921
  }
37766
37922
  function assetPlan(value, walletAddress2) {
@@ -37776,7 +37932,7 @@ function assetPlan(value, walletAddress2) {
37776
37932
  "maxBytes",
37777
37933
  "localAction"
37778
37934
  ], "Skill asset plan");
37779
- assertAuthority(plan, "asset_upload", walletAddress2, false);
37935
+ const chainId = assertAuthority(plan, "asset_upload", walletAddress2, false);
37780
37936
  const skillId = string4(plan.skillId, "Skill id", /^[1-9][0-9]*$/u);
37781
37937
  if (plan.assetKind !== "cover" || plan.maxBytes !== 5242880) throw new TypeError("Skill cover authority is invalid.");
37782
37938
  const accepted = plan.acceptedMediaTypes;
@@ -37790,7 +37946,7 @@ function assetPlan(value, walletAddress2) {
37790
37946
  if (action.client !== "finch" || action.command !== "skill asset-upload" || args.assetKind !== "cover") {
37791
37947
  throw new TypeError("Skill cover local action is invalid.");
37792
37948
  }
37793
- return { skillId, acceptedMediaTypes: accepted, maxBytes: plan.maxBytes };
37949
+ return { chainId, skillId, acceptedMediaTypes: accepted, maxBytes: plan.maxBytes };
37794
37950
  }
37795
37951
  function coverMediaType(bytes) {
37796
37952
  const png = [137, 80, 78, 71, 13, 10, 26, 10];
@@ -37807,9 +37963,7 @@ function isPlaintextSkillDelivery(value) {
37807
37963
  function deliveryPlan(value, context) {
37808
37964
  const delivery2 = object4(value, "Skill delivery");
37809
37965
  exact(delivery2, ["chainId", "skillId", "version", "packageURI", "packageHash", "plaintext", "litData", "entitledWallet"], "Skill delivery");
37810
- if (delivery2.chainId !== SKILL_V3_CHAIN_ID) {
37811
- throw new TypeError("Skill delivery authority is invalid.");
37812
- }
37966
+ const chainId = skillChain(delivery2.chainId, "Skill delivery chain");
37813
37967
  const skillId = string4(delivery2.skillId, "Skill id", /^[1-9][0-9]*$/u);
37814
37968
  const version6 = integer2(delivery2.version, "Skill version");
37815
37969
  const packageHash = string4(delivery2.packageHash, "Skill package hash", HASH);
@@ -37817,16 +37971,16 @@ function deliveryPlan(value, context) {
37817
37971
  const packageURI = deliveryPackageUri(delivery2.packageURI);
37818
37972
  if (delivery2.plaintext) {
37819
37973
  if (delivery2.litData !== null || delivery2.entitledWallet !== null) throw new TypeError("Plaintext Skill delivery cannot contain wallet or Lit authority.");
37820
- return { skillId, version: version6, packageURI, packageHash, plaintext: true, litData: null };
37974
+ return { chainId, skillId, version: version6, packageURI, packageHash, plaintext: true, litData: null };
37821
37975
  }
37822
37976
  if (context === null || typeof delivery2.entitledWallet !== "string" || !/^0x[0-9a-fA-F]{40}$/u.test(delivery2.entitledWallet) || delivery2.entitledWallet.toLowerCase() !== context.walletAddress.toLowerCase()) {
37823
- throw new TypeError("Protected Skill delivery is not entitled to the active TEST wallet.");
37977
+ throw new TypeError("Protected Skill delivery is not entitled to the active wallet.");
37824
37978
  }
37825
37979
  const litData = object4(delivery2.litData, "Skill Lit data");
37826
37980
  exact(litData, ["ciphertext", "scheme", "chain"], "Skill Lit data");
37827
- if (litData.scheme !== SKILL_V3_ENVELOPE_SCHEME && litData.scheme !== SKILL_V3_LIT_ENVELOPE_SCHEME || litData.chain !== SKILL_V3_CHAIN_TAG) throw new TypeError("Skill Lit data does not match the source-controlled deployment.");
37981
+ if (litData.scheme !== SKILL_V3_ENVELOPE_SCHEME && litData.scheme !== SKILL_V3_LIT_ENVELOPE_SCHEME || litData.chain !== skillV3ChainTag(chainId)) throw new TypeError("Skill Lit data does not match the source-controlled deployment.");
37828
37982
  string4(litData.ciphertext, "Skill Lit ciphertext");
37829
- return { skillId, version: version6, packageURI, packageHash, plaintext: false, litData };
37983
+ return { chainId, skillId, version: version6, packageURI, packageHash, plaintext: false, litData };
37830
37984
  }
37831
37985
  function required3(value, name) {
37832
37986
  if (value === void 0 || value === null) throw new TypeError(`${name} is unavailable.`);
@@ -37841,10 +37995,12 @@ function recoveryReceipt(value, name) {
37841
37995
  blockNumber: receipt.blockNumber === null ? null : string4(receipt.blockNumber, `${name} block number`, /^[1-9][0-9]*$/u)
37842
37996
  });
37843
37997
  }
37844
- function recoveryRequest(value, action, name) {
37998
+ function recoveryRequest(value, action, name, chainId) {
37845
37999
  const request = object4(value, name);
37846
- if (request.action !== action) throw new TypeError(`${name} action is invalid.`);
37847
- return request;
38000
+ if (request.action !== action || request.chainId !== void 0 && request.chainId !== chainId) {
38001
+ throw new TypeError(`${name} authority is invalid.`);
38002
+ }
38003
+ return { ...request, chainId };
37848
38004
  }
37849
38005
  function canonical(value) {
37850
38006
  if (Array.isArray(value)) return `[${value.map(canonical).join(",")}]`;
@@ -37852,7 +38008,15 @@ function canonical(value) {
37852
38008
  return JSON.stringify(value);
37853
38009
  }
37854
38010
  function recoveryFingerprint2(kind, plan, walletAddress2) {
37855
- return createHash2("sha256").update(canonical({ kind, plan, walletAddress: walletAddress2.toLowerCase(), chainId: SKILL_V3_CHAIN_ID, sourceCommit: SKILL_V3_SOURCE_COMMIT })).digest("hex");
38011
+ const authority = object4(plan, "Skill recovery plan");
38012
+ const chainId = skillChain(authority.chainId, "Skill recovery plan chain");
38013
+ return createHash2("sha256").update(canonical({
38014
+ kind,
38015
+ plan,
38016
+ walletAddress: walletAddress2.toLowerCase(),
38017
+ chainId,
38018
+ sourceCommit: skillV3SourceCommit(chainId)
38019
+ })).digest("hex");
37856
38020
  }
37857
38021
  function recoveryJournal(value, fingerprint2, kind, context) {
37858
38022
  const journal = object4(value, "Skill publication recovery");
@@ -37876,7 +38040,8 @@ function recoveryJournal(value, fingerprint2, kind, context) {
37876
38040
  "requests",
37877
38041
  "receipts"
37878
38042
  ], "Skill publication recovery");
37879
- if (journal.version !== 4 || journal.kind !== kind || journal.fingerprint !== fingerprint2 || !/^[0-9a-f]{64}$/u.test(fingerprint2) || journal.chainId !== SKILL_V3_CHAIN_ID || typeof journal.walletAddress !== "string" || journal.walletAddress.toLowerCase() !== context.walletAddress.toLowerCase()) throw new TypeError("Skill publication recovery authority does not match this command.");
38043
+ const chainId = skillChain(journal.chainId, "Skill recovery chain");
38044
+ if (journal.version !== 4 || journal.kind !== kind || journal.fingerprint !== fingerprint2 || !/^[0-9a-f]{64}$/u.test(fingerprint2) || typeof journal.walletAddress !== "string" || journal.walletAddress.toLowerCase() !== context.walletAddress.toLowerCase()) throw new TypeError("Skill publication recovery authority does not match this command.");
37880
38045
  const recoveredAuthority = assertPublicationAuthority(
37881
38046
  signingAuthority(journal.signingAuthority, context.walletAddress),
37882
38047
  context
@@ -37897,9 +38062,9 @@ function recoveryJournal(value, fingerprint2, kind, context) {
37897
38062
  exact(requests, ["primary", "uri", "lit"], "Skill recovery requests");
37898
38063
  const receipts = object4(journal.receipts, "Skill recovery receipts");
37899
38064
  exact(receipts, ["primary", "uri", "lit"], "Skill recovery receipts");
37900
- const primary = recoveryRequest(requests.primary, kind === "publish" ? "createSkill" : "updateSkill", "Skill primary recovery request");
37901
- const uri = requests.uri === null ? null : recoveryRequest(requests.uri, "setSkillURI", "Skill URI recovery request");
37902
- const lit = requests.lit === null ? null : recoveryRequest(requests.lit, "setLitData", "Skill Lit recovery request");
38065
+ const primary = recoveryRequest(requests.primary, kind === "publish" ? "createSkill" : "updateSkill", "Skill primary recovery request", chainId);
38066
+ const uri = requests.uri === null ? null : recoveryRequest(requests.uri, "setSkillURI", "Skill URI recovery request", chainId);
38067
+ const lit = requests.lit === null ? null : recoveryRequest(requests.lit, "setLitData", "Skill Lit recovery request", chainId);
37903
38068
  const parsedReceipts = {
37904
38069
  primary: recoveryReceipt(receipts.primary, "Skill primary recovery receipt"),
37905
38070
  uri: recoveryReceipt(receipts.uri, "Skill URI recovery receipt"),
@@ -37951,13 +38116,13 @@ var init_skill_local_flow = __esm({
37951
38116
  pause;
37952
38117
  nonce;
37953
38118
  recovery;
37954
- async send(context, action, request, prepared, onBroadcast) {
38119
+ async send(context, action, request, prepared, authority, onBroadcast) {
37955
38120
  return required3(this.sender.submitPrepared, "Skill prepared-intent sender").call(this.sender, {
37956
38121
  privateKey: context.privateKey,
37957
38122
  walletAddress: context.walletAddress,
37958
38123
  action,
37959
38124
  request,
37960
- intent: intent(prepared, context.walletAddress),
38125
+ intent: authority === void 0 ? intent(prepared, context.walletAddress) : legacyIntent(prepared, context.walletAddress, authority),
37961
38126
  onBroadcast
37962
38127
  });
37963
38128
  }
@@ -37971,10 +38136,18 @@ var init_skill_local_flow = __esm({
37971
38136
  string4(uri, "Skill package URI", IPFS);
37972
38137
  return required3(this.api.fetchSkillStoredContent, "Skill content relay").call(this.api, uri, bearer);
37973
38138
  }
37974
- async contentKey(context, skillId, version6) {
37975
- const message = buildKeyRequestMessage({ chainId: SKILL_V3_CHAIN_ID, skillId: BigInt(skillId), version: version6 }, context.walletAddress, this.nonce());
38139
+ async contentKey(context, chainId, skillId, version6) {
38140
+ const message = buildKeyRequestMessage({ chainId, skillId: BigInt(skillId), version: version6 }, context.walletAddress, this.nonce());
37976
38141
  const signature = await this.signer.signMessage({ privateKey: context.privateKey, message });
37977
- const result2 = await required3(this.api.requestSkillContentKey, "Skill content-key request").call(this.api, { skillId, version: version6, wallet: context.walletAddress, message, signature, bearer: context.bearer });
38142
+ const result2 = await required3(this.api.requestSkillContentKey, "Skill content-key request").call(this.api, {
38143
+ chainId,
38144
+ skillId,
38145
+ version: version6,
38146
+ wallet: context.walletAddress,
38147
+ message,
38148
+ signature,
38149
+ bearer: context.bearer
38150
+ });
37978
38151
  if (result2.scheme === SKILL_V3_ENVELOPE_SCHEME) {
37979
38152
  return Object.freeze({ scheme: result2.scheme, key: string4(result2.key, "Skill key-encryption key", HASH) });
37980
38153
  }
@@ -38001,32 +38174,35 @@ var init_skill_local_flow = __esm({
38001
38174
  excluded: sealed.excluded
38002
38175
  });
38003
38176
  }
38004
- async protectedEnvelope(context, skillId, version6, mode, packageContentKey) {
38177
+ async protectedEnvelope(context, chainId, skillId, version6, mode, packageContentKey) {
38005
38178
  if (mode === "finchip_v2") {
38006
- const wrapping = await this.contentKey(context, skillId, version6);
38179
+ const wrapping = await this.contentKey(context, chainId, skillId, version6);
38007
38180
  if (wrapping.scheme !== SKILL_V3_ENVELOPE_SCHEME) {
38008
38181
  throw new TypeError("Finch key authority returned the wrong envelope scheme.");
38009
38182
  }
38010
38183
  return {
38011
38184
  action: "setLitData",
38185
+ chainId,
38012
38186
  skillId,
38013
38187
  version: version6,
38014
38188
  ciphertext: await sealEnvelope(wrapping.key, packageContentKey),
38015
38189
  scheme: SKILL_V3_ENVELOPE_SCHEME,
38016
- chain: SKILL_V3_CHAIN_TAG
38190
+ chain: skillV3ChainTag(chainId)
38017
38191
  };
38018
38192
  }
38019
38193
  const sealed = await required3(this.api.sealSkillContentKeyWithLit, "Skill Lit sealing").call(this.api, {
38194
+ chainId,
38020
38195
  skillId,
38021
38196
  version: version6,
38022
38197
  contentKey: packageContentKey,
38023
38198
  bearer: context.bearer
38024
38199
  });
38025
- if (sealed.scheme !== SKILL_V3_LIT_ENVELOPE_SCHEME || sealed.chain !== SKILL_V3_CHAIN_TAG) {
38200
+ if (sealed.scheme !== SKILL_V3_LIT_ENVELOPE_SCHEME || sealed.chain !== skillV3ChainTag(chainId)) {
38026
38201
  throw new TypeError("Skill Lit sealing authority is invalid.");
38027
38202
  }
38028
38203
  return {
38029
38204
  action: "setLitData",
38205
+ chainId,
38030
38206
  skillId,
38031
38207
  version: version6,
38032
38208
  ciphertext: string4(sealed.ciphertext, "Skill Lit ciphertext"),
@@ -38047,24 +38223,31 @@ var init_skill_local_flow = __esm({
38047
38223
  async save(fingerprint2, journal) {
38048
38224
  await required3(this.recovery, "Skill publication recovery").saveSkillPublicationRecovery(fingerprint2, journal);
38049
38225
  }
38050
- async project(transactionHash3, bearer) {
38051
- await this.api.confirmSkillProjection?.(transactionHash3, bearer);
38226
+ async project(chainId, transactionHash3, bearer) {
38227
+ await this.api.confirmSkillProjection?.(chainId, transactionHash3, bearer);
38052
38228
  }
38053
38229
  async stage(context, fingerprint2, journal, stage, action, request, prepare) {
38054
38230
  const existing = journal.receipts[stage];
38055
38231
  if (existing !== null) {
38056
38232
  journal.receipts[stage] = await this.verify(context, action, request, existing);
38057
38233
  await this.save(fingerprint2, journal);
38058
- await this.project(journal.receipts[stage].transactionHash, context.bearer);
38234
+ await this.project(journal.chainId, journal.receipts[stage].transactionHash, context.bearer);
38059
38235
  return;
38060
38236
  }
38061
38237
  const prepared = await prepare();
38062
- journal.receipts[stage] = await this.send(context, action, request, prepared, async ({ transactionHash: transactionHash3 }) => {
38063
- journal.receipts[stage] = { transactionHash: transactionHash3, blockNumber: null };
38064
- await this.save(fingerprint2, journal);
38065
- });
38238
+ journal.receipts[stage] = await this.send(
38239
+ context,
38240
+ action,
38241
+ request,
38242
+ prepared,
38243
+ journal.signingAuthority,
38244
+ async ({ transactionHash: transactionHash3 }) => {
38245
+ journal.receipts[stage] = { transactionHash: transactionHash3, blockNumber: null };
38246
+ await this.save(fingerprint2, journal);
38247
+ }
38248
+ );
38066
38249
  await this.save(fingerprint2, journal);
38067
- await this.project(journal.receipts[stage].transactionHash, context.bearer);
38250
+ await this.project(journal.chainId, journal.receipts[stage].transactionHash, context.bearer);
38068
38251
  }
38069
38252
  async recoverPublication(fingerprint2, context) {
38070
38253
  if (!/^[0-9a-f]{64}$/u.test(fingerprint2)) throw new TypeError("Skill publication recovery fingerprint is invalid.");
@@ -38087,7 +38270,12 @@ var init_skill_local_flow = __esm({
38087
38270
  const slug = string4(journal.requests.primary.slug, "Skill recovery slug");
38088
38271
  let skillId2 = journal.skillId;
38089
38272
  await this.settle(async () => {
38090
- skillId2 = await required3(this.api.resolveSkillId, "Skill resolve API").call(this.api, slug, context.bearer);
38273
+ skillId2 = await required3(this.api.resolveSkillId, "Skill resolve API").call(
38274
+ this.api,
38275
+ journal.chainId,
38276
+ slug,
38277
+ context.bearer
38278
+ );
38091
38279
  return skillId2 !== null;
38092
38280
  }, `Skill ${slug} publication`);
38093
38281
  if (skillId2 === null) throw new TypeError("Published Skill slug did not resolve.");
@@ -38097,6 +38285,7 @@ var init_skill_local_flow = __esm({
38097
38285
  if (journal.requests.lit === null) {
38098
38286
  journal.requests.lit = await this.protectedEnvelope(
38099
38287
  context,
38288
+ journal.chainId,
38100
38289
  skillId2,
38101
38290
  1,
38102
38291
  journal.contentMode,
@@ -38117,6 +38306,7 @@ var init_skill_local_flow = __esm({
38117
38306
  }
38118
38307
  await store.clearSkillPublicationRecovery(fingerprint2);
38119
38308
  return {
38309
+ chainId: journal.chainId,
38120
38310
  skillId: skillId2,
38121
38311
  version: 1,
38122
38312
  contentMode: journal.contentMode,
@@ -38141,7 +38331,12 @@ var init_skill_local_flow = __esm({
38141
38331
  () => required3(this.api.requestSkillIntent, "Skill intent API").call(this.api, journal.requests.primary, context.bearer)
38142
38332
  );
38143
38333
  await this.settle(
38144
- async () => await required3(this.api.readSkillCurrentVersion, "Skill version API").call(this.api, skillId, context.bearer) === journal.targetVersion,
38334
+ async () => await required3(this.api.readSkillCurrentVersion, "Skill version API").call(
38335
+ this.api,
38336
+ journal.chainId,
38337
+ skillId,
38338
+ context.bearer
38339
+ ) === journal.targetVersion,
38145
38340
  `Skill ${skillId} version ${journal.targetVersion}`
38146
38341
  );
38147
38342
  const uriRequest = required3(journal.requests.uri, "Skill URI recovery request");
@@ -38158,6 +38353,7 @@ var init_skill_local_flow = __esm({
38158
38353
  if (journal.requests.lit === null) {
38159
38354
  journal.requests.lit = await this.protectedEnvelope(
38160
38355
  context,
38356
+ journal.chainId,
38161
38357
  skillId,
38162
38358
  journal.targetVersion,
38163
38359
  journal.contentMode,
@@ -38178,6 +38374,7 @@ var init_skill_local_flow = __esm({
38178
38374
  }
38179
38375
  await store.clearSkillPublicationRecovery(fingerprint2);
38180
38376
  return {
38377
+ chainId: journal.chainId,
38181
38378
  skillId,
38182
38379
  version: journal.targetVersion,
38183
38380
  contentMode: journal.contentMode,
@@ -38239,7 +38436,7 @@ var init_skill_local_flow = __esm({
38239
38436
  kind: "publish",
38240
38437
  fingerprint: fingerprint2,
38241
38438
  walletAddress: context.walletAddress.toLowerCase(),
38242
- chainId: SKILL_V3_CHAIN_ID,
38439
+ chainId: plan.chainId,
38243
38440
  signingAuthority: plan.signingAuthority,
38244
38441
  sourceKind: expectedSourceKind,
38245
38442
  contentMode: mode,
@@ -38267,7 +38464,12 @@ var init_skill_local_flow = __esm({
38267
38464
  );
38268
38465
  let skillId = journal.skillId;
38269
38466
  await this.settle(async () => {
38270
- skillId = await required3(this.api.resolveSkillId, "Skill resolve API").call(this.api, String(request.slug), context.bearer);
38467
+ skillId = await required3(this.api.resolveSkillId, "Skill resolve API").call(
38468
+ this.api,
38469
+ journal.chainId,
38470
+ String(request.slug),
38471
+ context.bearer
38472
+ );
38271
38473
  return skillId !== null;
38272
38474
  }, `Skill ${request.slug} publication`);
38273
38475
  if (skillId === null) throw new TypeError("Published Skill slug did not resolve.");
@@ -38277,6 +38479,7 @@ var init_skill_local_flow = __esm({
38277
38479
  if (journal.requests.lit === null) {
38278
38480
  journal.requests.lit = await this.protectedEnvelope(
38279
38481
  context,
38482
+ journal.chainId,
38280
38483
  skillId,
38281
38484
  1,
38282
38485
  journal.contentMode,
@@ -38296,14 +38499,19 @@ var init_skill_local_flow = __esm({
38296
38499
  );
38297
38500
  }
38298
38501
  await store.clearSkillPublicationRecovery(fingerprint2);
38299
- return { skillId, version: 1, contentMode: journal.contentMode, packageHash: journal.packageHash, excluded: journal.excluded, transactions: { create: required3(journal.receipts.primary, "Skill create receipt").transactionHash, ...journal.contentMode === "plaintext" ? {} : { setLitData: required3(journal.receipts.lit, "Skill Lit receipt").transactionHash } } };
38502
+ return { chainId: journal.chainId, skillId, version: 1, contentMode: journal.contentMode, packageHash: journal.packageHash, excluded: journal.excluded, transactions: { create: required3(journal.receipts.primary, "Skill create receipt").transactionHash, ...journal.contentMode === "plaintext" ? {} : { setLitData: required3(journal.receipts.lit, "Skill Lit receipt").transactionHash } } };
38300
38503
  }
38301
38504
  async publishVersion(path, planValue, context) {
38302
38505
  const plan = versionPlan(planValue, context);
38303
38506
  const fingerprint2 = recoveryFingerprint2("version", planValue, context.walletAddress);
38304
38507
  const store = required3(this.recovery, "Skill publication recovery");
38305
38508
  const prior = await store.readSkillPublicationRecovery(fingerprint2);
38306
- const observedVersion = await required3(this.api.readSkillCurrentVersion, "Skill version API").call(this.api, String(plan.request.skillId), context.bearer);
38509
+ const observedVersion = await required3(this.api.readSkillCurrentVersion, "Skill version API").call(
38510
+ this.api,
38511
+ plan.chainId,
38512
+ String(plan.request.skillId),
38513
+ context.bearer
38514
+ );
38307
38515
  if (prior === null && observedVersion !== plan.currentVersion) {
38308
38516
  throw new TypeError(`Skill current version ${observedVersion} no longer matches plan version ${plan.currentVersion}.`);
38309
38517
  }
@@ -38336,14 +38544,14 @@ var init_skill_local_flow = __esm({
38336
38544
  bearer: context.bearer,
38337
38545
  objectKind: "manifest"
38338
38546
  });
38339
- const updateRequest = { action: "updateSkill", skillId: plan.request.skillId, mdHash: packaged.packageHash, packageHash: packaged.packageHash };
38340
- const uriRequest2 = { action: "setSkillURI", skillId: plan.request.skillId, packageURI: manifestURI };
38547
+ const updateRequest = { action: "updateSkill", chainId: plan.chainId, skillId: plan.request.skillId, mdHash: packaged.packageHash, packageHash: packaged.packageHash };
38548
+ const uriRequest2 = { action: "setSkillURI", chainId: plan.chainId, skillId: plan.request.skillId, packageURI: manifestURI };
38341
38549
  journal = {
38342
38550
  version: 4,
38343
38551
  kind: "version",
38344
38552
  fingerprint: fingerprint2,
38345
38553
  walletAddress: context.walletAddress.toLowerCase(),
38346
- chainId: SKILL_V3_CHAIN_ID,
38554
+ chainId: plan.chainId,
38347
38555
  signingAuthority: plan.signingAuthority,
38348
38556
  sourceKind: plan.sourceKind,
38349
38557
  contentMode: plan.contentMode,
@@ -38369,7 +38577,12 @@ var init_skill_local_flow = __esm({
38369
38577
  journal.requests.primary,
38370
38578
  () => required3(this.api.requestSkillIntent, "Skill intent API").call(this.api, journal.requests.primary, context.bearer)
38371
38579
  );
38372
- await this.settle(async () => await required3(this.api.readSkillCurrentVersion, "Skill version API").call(this.api, String(plan.request.skillId), context.bearer) === plan.nextVersion, `Skill ${plan.request.skillId} version ${plan.nextVersion}`);
38580
+ await this.settle(async () => await required3(this.api.readSkillCurrentVersion, "Skill version API").call(
38581
+ this.api,
38582
+ journal.chainId,
38583
+ String(plan.request.skillId),
38584
+ context.bearer
38585
+ ) === plan.nextVersion, `Skill ${plan.request.skillId} version ${plan.nextVersion}`);
38373
38586
  const uriRequest = required3(journal.requests.uri, "Skill URI recovery request");
38374
38587
  await this.stage(
38375
38588
  context,
@@ -38384,6 +38597,7 @@ var init_skill_local_flow = __esm({
38384
38597
  if (journal.requests.lit === null) {
38385
38598
  journal.requests.lit = await this.protectedEnvelope(
38386
38599
  context,
38600
+ journal.chainId,
38387
38601
  String(plan.request.skillId),
38388
38602
  plan.nextVersion,
38389
38603
  journal.contentMode,
@@ -38403,18 +38617,18 @@ var init_skill_local_flow = __esm({
38403
38617
  );
38404
38618
  }
38405
38619
  await store.clearSkillPublicationRecovery(fingerprint2);
38406
- return { skillId: plan.request.skillId, version: plan.nextVersion, contentMode: journal.contentMode, packageHash: journal.packageHash, excluded: journal.excluded, transactions: { update: required3(journal.receipts.primary, "Skill update receipt").transactionHash, setSkillURI: required3(journal.receipts.uri, "Skill URI receipt").transactionHash, ...journal.contentMode === "plaintext" ? {} : { setLitData: required3(journal.receipts.lit, "Skill Lit receipt").transactionHash } } };
38620
+ return { chainId: journal.chainId, skillId: plan.request.skillId, version: plan.nextVersion, contentMode: journal.contentMode, packageHash: journal.packageHash, excluded: journal.excluded, transactions: { update: required3(journal.receipts.primary, "Skill update receipt").transactionHash, setSkillURI: required3(journal.receipts.uri, "Skill URI receipt").transactionHash, ...journal.contentMode === "plaintext" ? {} : { setLitData: required3(journal.receipts.lit, "Skill Lit receipt").transactionHash } } };
38407
38621
  }
38408
38622
  async manage(kind, planValue, context) {
38409
38623
  const plan = managePlan(planValue, context.walletAddress, kind);
38410
38624
  const action = kind === "price" ? "setUnitPrice" : "setMaxSupply";
38411
38625
  const submission = await this.send(context, action, { action, ...plan.request }, plan.intent);
38412
- await this.project(submission.transactionHash, context.bearer);
38413
- return { ...submission, skillId: plan.request.skillId, kind };
38626
+ await this.project(plan.chainId, submission.transactionHash, context.bearer);
38627
+ return { ...submission, chainId: plan.chainId, skillId: plan.request.skillId, kind };
38414
38628
  }
38415
38629
  async publishPresentation(planValue, context) {
38416
38630
  const plan = presentationPlan(planValue, context.walletAddress);
38417
- const liveVersion = await required3(this.api.readSkillCurrentVersion, "Skill version API").call(this.api, plan.skillId, context.bearer);
38631
+ const liveVersion = await required3(this.api.readSkillCurrentVersion, "Skill version API").call(this.api, plan.chainId, plan.skillId, context.bearer);
38418
38632
  if (liveVersion !== plan.currentVersion) {
38419
38633
  throw new TypeError(`Skill current version ${liveVersion} no longer matches presentation plan version ${plan.currentVersion}.`);
38420
38634
  }
@@ -38427,11 +38641,17 @@ var init_skill_local_flow = __esm({
38427
38641
  bearer: context.bearer,
38428
38642
  objectKind: "manifest"
38429
38643
  });
38430
- const request = { action: "setSkillURI", skillId: plan.skillId, packageURI: manifestURI };
38644
+ const request = { action: "setSkillURI", chainId: plan.chainId, skillId: plan.skillId, packageURI: manifestURI };
38431
38645
  const prepared = await required3(this.api.requestSkillIntent, "Skill intent API").call(this.api, request, context.bearer);
38432
- const submission = await this.send(context, "setSkillURI", request, prepared);
38433
- await this.project(submission.transactionHash, context.bearer);
38434
- return { ...submission, skillId: plan.skillId, currentVersion: plan.currentVersion, manifestURI };
38646
+ const submission = await this.send(
38647
+ context,
38648
+ "setSkillURI",
38649
+ request,
38650
+ prepared,
38651
+ plan.signingAuthority
38652
+ );
38653
+ await this.project(plan.chainId, submission.transactionHash, context.bearer);
38654
+ return { ...submission, chainId: plan.chainId, skillId: plan.skillId, currentVersion: plan.currentVersion, manifestURI };
38435
38655
  }
38436
38656
  async uploadCover(path, planValue, context) {
38437
38657
  const plan = assetPlan(planValue, context.walletAddress);
@@ -38451,7 +38671,7 @@ var init_skill_local_flow = __esm({
38451
38671
  objectKind: "cover",
38452
38672
  mediaType
38453
38673
  });
38454
- return { skillId: plan.skillId, assetKind: "cover", uri, mediaType, bytes: bytes.byteLength };
38674
+ return { chainId: plan.chainId, skillId: plan.skillId, assetKind: "cover", uri, mediaType, bytes: bytes.byteLength };
38455
38675
  }
38456
38676
  async download(planValue, context) {
38457
38677
  const plan = deliveryPlan(planValue, context);
@@ -38468,7 +38688,12 @@ var init_skill_local_flow = __esm({
38468
38688
  if (!HASH.test(expectedHash)) throw new TypeError("Skill delivery has no verifiable plaintext package hash.");
38469
38689
  let plaintext = stored;
38470
38690
  if (!plan.plaintext) {
38471
- const resolved = await this.contentKey(required3(context, "Protected Skill wallet context"), plan.skillId, plan.version);
38691
+ const resolved = await this.contentKey(
38692
+ required3(context, "Protected Skill wallet context"),
38693
+ plan.chainId,
38694
+ plan.skillId,
38695
+ plan.version
38696
+ );
38472
38697
  const envelopeScheme = String(plan.litData.scheme);
38473
38698
  if (resolved.scheme !== envelopeScheme) throw new TypeError("Skill content-key response does not match its on-chain envelope.");
38474
38699
  const contentKey = resolved.scheme === SKILL_V3_ENVELOPE_SCHEME ? await openEnvelope(resolved.key, String(plan.litData.ciphertext)) : resolved.key;
@@ -38476,7 +38701,7 @@ var init_skill_local_flow = __esm({
38476
38701
  }
38477
38702
  const actualHash = await sha256Hex(plaintext);
38478
38703
  if (actualHash.toLowerCase() !== expectedHash.toLowerCase()) throw new TypeError("Decrypted Skill package hash does not match its published authority.");
38479
- return Object.freeze({ bytes: plaintext, skillId: plan.skillId, version: plan.version, packageHash: actualHash });
38704
+ return Object.freeze({ bytes: plaintext, chainId: plan.chainId, skillId: plan.skillId, version: plan.version, packageHash: actualHash });
38480
38705
  }
38481
38706
  };
38482
38707
  }
@@ -38857,7 +39082,6 @@ var init_application = __esm({
38857
39082
  taskProtocolSender;
38858
39083
  skillIntentSender;
38859
39084
  skillLocalFlow;
38860
- mcpHarness;
38861
39085
  browserLauncher;
38862
39086
  constructor(dependencies) {
38863
39087
  this.api = dependencies.api;
@@ -38872,7 +39096,6 @@ var init_application = __esm({
38872
39096
  this.taskProtocolSender = dependencies.taskProtocolSender;
38873
39097
  this.skillIntentSender = dependencies.skillIntentSender;
38874
39098
  this.skillLocalFlow = dependencies.skillLocalFlow;
38875
- this.mcpHarness = dependencies.mcpHarness;
38876
39099
  this.browserLauncher = dependencies.browserLauncher;
38877
39100
  }
38878
39101
  async authorizedProfile() {
@@ -39052,11 +39275,11 @@ var init_application = __esm({
39052
39275
  await required4(this.state.activateSession, "state.activateSession").call(this.state, response);
39053
39276
  return response;
39054
39277
  }
39055
- async browserHandoffAuthority() {
39278
+ async verifiedAgentCliAuthority() {
39056
39279
  const profile = await this.authorizedProfile();
39057
39280
  const session = await this.networkSession(profile);
39058
39281
  const wallet = await required4(this.state.readWalletAddress, "state.readWalletAddress").call(this.state);
39059
- const remote = asObject(await required4(this.api.getSession, "api.getSession").call(this.api, session.rawBearer), "Browser handoff Session");
39282
+ const remote = asObject(await required4(this.api.getSession, "api.getSession").call(this.api, session.rawBearer), "AgentCLI Session");
39060
39283
  if (session.walletAddress.toLowerCase() !== wallet.walletAddress.toLowerCase() || remote.accountId !== session.accountId || String(remote.walletAddress).toLowerCase() !== wallet.walletAddress.toLowerCase() || remote.environment !== profile.environment || remote.audience !== "agent_cli") {
39061
39284
  throw new CliAuthorityError();
39062
39285
  }
@@ -39081,7 +39304,7 @@ var init_application = __esm({
39081
39304
  });
39082
39305
  }
39083
39306
  async openSite() {
39084
- const authority = await this.browserHandoffAuthority();
39307
+ const authority = await this.verifiedAgentCliAuthority();
39085
39308
  return this.openBrowserHandoff(authority);
39086
39309
  }
39087
39310
  async loginSite(requestUrl) {
@@ -39096,9 +39319,67 @@ var init_application = __esm({
39096
39319
  if (parsed.origin !== profile.origin || requestUrl !== `${profile.origin}${parsed.pathname}` || parsed.search !== "" || parsed.hash !== "" || match === null) {
39097
39320
  throw new TypeError("Browser login request origin or path does not match the active profile origin.");
39098
39321
  }
39099
- const authority = await this.browserHandoffAuthority();
39322
+ const authority = await this.verifiedAgentCliAuthority();
39100
39323
  return this.openBrowserHandoff({ ...authority, requestId: match[1] });
39101
39324
  }
39325
+ async authorizeMcp(requestUrl) {
39326
+ const profile = await this.authorizedProfile();
39327
+ let request;
39328
+ try {
39329
+ request = new URL(requestUrl);
39330
+ } catch {
39331
+ throw new TypeError("MCP OAuth request URL is invalid.");
39332
+ }
39333
+ const redirectValues = request.searchParams.getAll("redirect_uri");
39334
+ const stateValues = request.searchParams.getAll("state");
39335
+ const scopeValues = request.searchParams.getAll("scope");
39336
+ if (request.origin !== profile.origin || request.pathname !== "/oauth/authorize" || request.username !== "" || request.password !== "" || request.hash !== "" || requestUrl !== `${profile.origin}${request.pathname}${request.search}` || redirectValues.length !== 1 || stateValues.length > 1 || scopeValues.length !== 1) {
39337
+ throw new TypeError("MCP OAuth request URL does not match the active profile authority.");
39338
+ }
39339
+ let registeredRedirect;
39340
+ try {
39341
+ registeredRedirect = new URL(redirectValues[0]);
39342
+ } catch {
39343
+ throw new TypeError("MCP OAuth redirect URI is invalid.");
39344
+ }
39345
+ if (registeredRedirect.username !== "" || registeredRedirect.password !== "" || registeredRedirect.hash !== "") {
39346
+ throw new TypeError("MCP OAuth redirect URI is invalid.");
39347
+ }
39348
+ const authority = await this.verifiedAgentCliAuthority();
39349
+ const response = asObject(await required4(this.api.authorizeMcp, "api.authorizeMcp").call(this.api, `${request.pathname}${request.search}`, authority.session.rawBearer), "MCP authorization");
39350
+ if (response.authorized !== true || response.accountId !== authority.session.accountId || String(response.walletAddress).toLowerCase() !== authority.walletAddress || typeof response.clientName !== "string" || response.clientName.length < 1 || response.clientName.length > 128 || !Array.isArray(response.scopes) || response.scopes.some((scope) => typeof scope !== "string" || scope.length < 1) || typeof response.callbackUrl !== "string") {
39351
+ throw new CliAuthorityError();
39352
+ }
39353
+ const requestedScopes = scopeValues[0].split(" ").filter(Boolean).sort();
39354
+ const returnedScopes = [...response.scopes].sort();
39355
+ if (requestedScopes.length < 1 || requestedScopes.length !== returnedScopes.length || requestedScopes.some((scope, index2) => scope !== returnedScopes[index2])) {
39356
+ throw new CliAuthorityError();
39357
+ }
39358
+ let callback;
39359
+ try {
39360
+ callback = new URL(response.callbackUrl);
39361
+ } catch {
39362
+ throw new TypeError("MCP OAuth callback is invalid.");
39363
+ }
39364
+ const codes = callback.searchParams.getAll("code");
39365
+ if (codes.length !== 1 || !/^[A-Za-z0-9_-]{43}$/u.test(codes[0])) {
39366
+ throw new TypeError("MCP OAuth callback is invalid.");
39367
+ }
39368
+ const expectedCallback = new URL(registeredRedirect.href);
39369
+ expectedCallback.searchParams.set("code", codes[0]);
39370
+ if (stateValues.length === 1) expectedCallback.searchParams.set("state", stateValues[0]);
39371
+ if (callback.href !== expectedCallback.href) {
39372
+ throw new TypeError("MCP OAuth callback does not match the registered redirect and state.");
39373
+ }
39374
+ await required4(this.browserLauncher, "browser launcher").open(callback.href);
39375
+ return Object.freeze({
39376
+ authorized: true,
39377
+ clientName: response.clientName,
39378
+ walletAddress: authority.walletAddress,
39379
+ environment: profile.environment,
39380
+ scopes: Object.freeze([...returnedScopes])
39381
+ });
39382
+ }
39102
39383
  async createWallet() {
39103
39384
  const privateKey3 = generatePrivateKey();
39104
39385
  const walletAddress2 = privateKeyToAccount(privateKey3).address.toLowerCase();
@@ -39255,7 +39536,7 @@ var init_application = __esm({
39255
39536
  throw new TypeError("MCP doctor Session authority does not match the active wallet and profile.");
39256
39537
  }
39257
39538
  const mcp = await required4(this.api.inspectRemoteMcp, "api.inspectRemoteMcp").call(this.api);
39258
- if (mcp.url !== `${profile.origin}/mcp` || mcp.authorization !== "agent_cli_session_handoff" || JSON.stringify(mcp.supportedClients) !== JSON.stringify(["codex"])) {
39539
+ if (mcp.url !== `${profile.origin}/mcp` || mcp.authorization !== "oauth" || JSON.stringify(mcp.supportedClients) !== JSON.stringify(["codex"])) {
39259
39540
  throw new TypeError("MCP doctor discovery does not match the authoritative profile.");
39260
39541
  }
39261
39542
  return Object.freeze({
@@ -39270,64 +39551,6 @@ var init_application = __esm({
39270
39551
  mcp
39271
39552
  });
39272
39553
  }
39273
- async launchMcpHarness(client) {
39274
- if (client !== "codex") throw new TypeError("Only the verified Codex MCP handoff is supported.");
39275
- const profile = await this.authorizedProfile();
39276
- const session = await this.networkSession(profile);
39277
- const wallet = await required4(this.state.readWalletAddress, "state.readWalletAddress").call(this.state);
39278
- const remoteSession = asObject(await required4(this.api.getSession, "api.getSession").call(this.api, session.rawBearer), "MCP handoff Session");
39279
- if (remoteSession.sessionId !== session.sessionId || remoteSession.accountId !== session.accountId || remoteSession.walletAddress !== session.walletAddress || wallet.walletAddress !== session.walletAddress || remoteSession.environment !== session.environment || remoteSession.audience !== "agent_cli" || typeof remoteSession.sessionExpiresAt !== "string" || Date.parse(remoteSession.sessionExpiresAt) <= Date.now()) {
39280
- throw new TypeError("MCP handoff Session authority does not match the active wallet and profile.");
39281
- }
39282
- const mcp = await required4(this.api.inspectRemoteMcp, "api.inspectRemoteMcp").call(this.api);
39283
- if (mcp.url !== `${profile.origin}/mcp` || mcp.authorization !== "agent_cli_session_handoff" || !mcp.supportedClients.includes(client)) {
39284
- throw new TypeError("MCP handoff manifest does not match the authoritative profile.");
39285
- }
39286
- const readGrant = required4(this.state.readMcpGrantForScopes, "state.readMcpGrantForScopes");
39287
- let grant = await readGrant.call(this.state, {
39288
- scopes: identityScopeValues,
39289
- accountId: session.accountId,
39290
- environment: session.environment
39291
- });
39292
- if (grant === null) {
39293
- const parentExpiry = Date.parse(remoteSession.sessionExpiresAt);
39294
- const expiry = Math.min(Date.now() + 12 * 60 * 60 * 1e3, parentExpiry - 1e3);
39295
- if (expiry <= Date.now() + 6e4) {
39296
- throw new TypeError("The AgentCLI Session expires too soon to launch Finch MCP. Log in again.");
39297
- }
39298
- await this.createMcpGrant(identityScopeValues, new Date(expiry).toISOString());
39299
- grant = await readGrant.call(this.state, {
39300
- scopes: identityScopeValues,
39301
- accountId: session.accountId,
39302
- environment: session.environment
39303
- });
39304
- if (grant === null) throw new TypeError("The new MCP handoff grant is unavailable in protected local state.");
39305
- }
39306
- parseCanonicalUuid(grant.grantId, "MCP handoff grantId");
39307
- if (!/^[A-Za-z0-9_-]{43}$/u.test(grant.rawBearer)) {
39308
- throw new TypeError("The selected MCP handoff grant is invalid.");
39309
- }
39310
- const remoteGrant = asObject(await required4(this.api.showGrant, "api.showGrant").call(this.api, grant.grantId, session.rawBearer), "MCP handoff grant");
39311
- if (remoteGrant.grantId !== grant.grantId || remoteGrant.audience !== "finch_mcp" || remoteGrant.environment !== session.environment || remoteGrant.status !== "active" || remoteGrant.revokedAt !== null || remoteGrant.expiresAt !== grant.expiresAt || remoteGrant.parentSessionExpiresAt !== remoteSession.sessionExpiresAt || JSON.stringify(remoteGrant.scopes) !== JSON.stringify(identityScopeValues) || Date.parse(grant.expiresAt) <= Date.now()) {
39312
- throw new TypeError("MCP handoff grant does not inherit the active parent Session authority.");
39313
- }
39314
- const launched = await required4(this.mcpHarness, "MCP Harness").launch({
39315
- client,
39316
- mcpUrl: mcp.url,
39317
- bearer: grant.rawBearer
39318
- });
39319
- return Object.freeze({
39320
- client,
39321
- launched: true,
39322
- browserAuthorization: false,
39323
- exitCode: launched.exitCode,
39324
- environment: session.environment,
39325
- accountId: session.accountId,
39326
- walletAddress: session.walletAddress,
39327
- grantId: grant.grantId,
39328
- grantExpiresAt: grant.expiresAt
39329
- });
39330
- }
39331
39554
  async assertNoBlockingRecoveries() {
39332
39555
  const recoveries = await this.state.listBlockingRecoveries?.call(this.state) ?? [];
39333
39556
  if (recoveries.length > 0) {
@@ -39736,7 +39959,10 @@ var init_application = __esm({
39736
39959
  environment: authority.session.environment
39737
39960
  });
39738
39961
  const published = await required4(this.skillLocalFlow, "skill local flow").publish(path, plan, context);
39739
- return { ...published, nextAction: { operationId: "skill_market.skills.get", request: { skillId: published.skillId } } };
39962
+ return { ...published, nextAction: { operationId: "skill_market.skills.get", request: {
39963
+ chainId: published.chainId,
39964
+ skillId: published.skillId
39965
+ } } };
39740
39966
  }
39741
39967
  async submitSkillVersion(path, planFile) {
39742
39968
  const plan = await readBoundedJsonFile(planFile);
@@ -39750,7 +39976,11 @@ var init_application = __esm({
39750
39976
  environment: authority.session.environment
39751
39977
  });
39752
39978
  const published = await required4(this.skillLocalFlow, "skill local flow").publishVersion(path, plan, context);
39753
- return { ...published, nextAction: { operationId: "skill_market.skills.get", request: { skillId: published.skillId, version: published.version } } };
39979
+ return { ...published, nextAction: { operationId: "skill_market.skills.get", request: {
39980
+ chainId: published.chainId,
39981
+ skillId: published.skillId,
39982
+ version: published.version
39983
+ } } };
39754
39984
  }
39755
39985
  async submitSkillManage(kind, planFile) {
39756
39986
  const plan = await readBoundedJsonFile(planFile);
@@ -39758,7 +39988,10 @@ var init_application = __esm({
39758
39988
  assertSigningAuthority(plan, authority.session);
39759
39989
  const context = Object.freeze({ privateKey: authority.wallet.privateKey, walletAddress: authority.wallet.walletAddress, bearer: authority.session.rawBearer });
39760
39990
  const managed = await required4(this.skillLocalFlow, "skill local flow").manage(kind, plan, context);
39761
- return { ...managed, nextAction: { operationId: "skill_market.skills.get", request: { skillId: managed.skillId } } };
39991
+ return { ...managed, nextAction: { operationId: "skill_market.skills.get", request: {
39992
+ chainId: managed.chainId,
39993
+ skillId: managed.skillId
39994
+ } } };
39762
39995
  }
39763
39996
  async submitSkillPresentation(planFile) {
39764
39997
  const plan = await readBoundedJsonFile(planFile);
@@ -39766,7 +39999,10 @@ var init_application = __esm({
39766
39999
  assertSigningAuthority(plan, authority.session);
39767
40000
  const context = Object.freeze({ privateKey: authority.wallet.privateKey, walletAddress: authority.wallet.walletAddress, bearer: authority.session.rawBearer });
39768
40001
  const published = await required4(this.skillLocalFlow, "skill local flow").publishPresentation(plan, context);
39769
- return { ...published, nextAction: { operationId: "skill_market.manage.get", request: { skillId: published.skillId } } };
40002
+ return { ...published, nextAction: { operationId: "skill_market.manage.get", request: {
40003
+ chainId: published.chainId,
40004
+ skillId: published.skillId
40005
+ } } };
39770
40006
  }
39771
40007
  async uploadSkillAsset(path, planFile) {
39772
40008
  const plan = await readBoundedJsonFile(planFile);
@@ -39774,7 +40010,10 @@ var init_application = __esm({
39774
40010
  const uploaded = await required4(this.skillLocalFlow, "skill local flow").uploadCover(path, plan, context);
39775
40011
  return { ...uploaded, nextAction: {
39776
40012
  operationId: "skill_market.manage.get",
39777
- query: { skillId: uploaded.skillId }
40013
+ request: {
40014
+ chainId: uploaded.chainId,
40015
+ skillId: uploaded.skillId
40016
+ }
39778
40017
  } };
39779
40018
  }
39780
40019
  async recoverSkill(kind, fingerprint2) {
@@ -40109,7 +40348,7 @@ var init_package = __esm({
40109
40348
  "package.json"() {
40110
40349
  package_default = {
40111
40350
  name: "@finchtech/cli",
40112
- version: "0.1.0",
40351
+ version: "0.2.1",
40113
40352
  description: "Finch Agent CLI for wallet-owned marketplace and MCP workflows.",
40114
40353
  type: "module",
40115
40354
  bin: {
@@ -40273,8 +40512,8 @@ async function routeCommand(arguments_, application) {
40273
40512
  if (first === "mcp" && second === "doctor" && arguments_.length === 2) {
40274
40513
  return result("mcp.doctor", await method(application.doctorMcp, "mcp doctor").call(application));
40275
40514
  }
40276
- if (first === "mcp" && second === "launch" && third === "codex" && arguments_.length === 3) {
40277
- return result("mcp.launch.codex", await method(application.launchMcpHarness, "mcp launch codex").call(application, "codex"));
40515
+ if (first === "mcp" && second === "authorize" && arguments_.length === 3 && third !== void 0) {
40516
+ return result("mcp.authorize", await method(application.authorizeMcp, "mcp authorize").call(application, third));
40278
40517
  }
40279
40518
  if (first === "mcp" && second === "grant" && third === "create") {
40280
40519
  const scopes = exactOption(arguments_, "--scopes").split(",");
@@ -40595,7 +40834,7 @@ var init_command_router = __esm({
40595
40834
  "site open",
40596
40835
  "site login",
40597
40836
  "mcp doctor",
40598
- "mcp launch codex",
40837
+ "mcp authorize",
40599
40838
  "mcp grant create",
40600
40839
  "mcp grant show",
40601
40840
  "mcp grant revoke",
@@ -40661,7 +40900,7 @@ var init_command_router = __esm({
40661
40900
  "site open": "finch site open",
40662
40901
  "site login": "finch site login <REQUEST_URL>",
40663
40902
  "mcp doctor": "finch mcp doctor",
40664
- "mcp launch codex": "finch mcp launch codex",
40903
+ "mcp authorize": "finch mcp authorize <REQUEST_URL>",
40665
40904
  "mcp grant create": "finch mcp grant create --scopes <CSV> --expires-at <ISO-8601>",
40666
40905
  "mcp grant show": "finch mcp grant show <GRANT_ID>",
40667
40906
  "mcp grant revoke": "finch mcp grant revoke <GRANT_ID>",
@@ -55389,6 +55628,38 @@ var init_chainConfig = __esm({
55389
55628
  }
55390
55629
  });
55391
55630
 
55631
+ // ../../node_modules/.pnpm/viem@2.55.15_bufferutil@4.1_ce20031be19c56210207d462110a7a29/node_modules/viem/_esm/chains/definitions/arbitrum.js
55632
+ var arbitrum;
55633
+ var init_arbitrum = __esm({
55634
+ "../../node_modules/.pnpm/viem@2.55.15_bufferutil@4.1_ce20031be19c56210207d462110a7a29/node_modules/viem/_esm/chains/definitions/arbitrum.js"() {
55635
+ init_defineChain();
55636
+ arbitrum = /* @__PURE__ */ defineChain({
55637
+ id: 42161,
55638
+ name: "Arbitrum One",
55639
+ nativeCurrency: { name: "Ether", symbol: "ETH", decimals: 18 },
55640
+ blockTime: 250,
55641
+ rpcUrls: {
55642
+ default: {
55643
+ http: ["https://arb1.arbitrum.io/rpc"]
55644
+ }
55645
+ },
55646
+ blockExplorers: {
55647
+ default: {
55648
+ name: "Arbiscan",
55649
+ url: "https://arbiscan.io",
55650
+ apiUrl: "https://api.arbiscan.io/api"
55651
+ }
55652
+ },
55653
+ contracts: {
55654
+ multicall3: {
55655
+ address: "0xca11bde05977b3631167028862be2a173976ca11",
55656
+ blockCreated: 7654707
55657
+ }
55658
+ }
55659
+ });
55660
+ }
55661
+ });
55662
+
55392
55663
  // ../../node_modules/.pnpm/viem@2.55.15_bufferutil@4.1_ce20031be19c56210207d462110a7a29/node_modules/viem/_esm/chains/definitions/base.js
55393
55664
  var sourceId, base, basePreconf;
55394
55665
  var init_base2 = __esm({
@@ -55525,11 +55796,141 @@ var init_baseSepolia = __esm({
55525
55796
  }
55526
55797
  });
55527
55798
 
55799
+ // ../../node_modules/.pnpm/viem@2.55.15_bufferutil@4.1_ce20031be19c56210207d462110a7a29/node_modules/viem/_esm/chains/definitions/bsc.js
55800
+ var bsc;
55801
+ var init_bsc = __esm({
55802
+ "../../node_modules/.pnpm/viem@2.55.15_bufferutil@4.1_ce20031be19c56210207d462110a7a29/node_modules/viem/_esm/chains/definitions/bsc.js"() {
55803
+ init_defineChain();
55804
+ bsc = /* @__PURE__ */ defineChain({
55805
+ id: 56,
55806
+ name: "BNB Smart Chain",
55807
+ blockTime: 750,
55808
+ nativeCurrency: {
55809
+ decimals: 18,
55810
+ name: "BNB",
55811
+ symbol: "BNB"
55812
+ },
55813
+ rpcUrls: {
55814
+ default: { http: ["https://56.rpc.thirdweb.com"] }
55815
+ },
55816
+ blockExplorers: {
55817
+ default: {
55818
+ name: "BscScan",
55819
+ url: "https://bscscan.com",
55820
+ apiUrl: "https://api.bscscan.com/api"
55821
+ }
55822
+ },
55823
+ contracts: {
55824
+ multicall3: {
55825
+ address: "0xca11bde05977b3631167028862be2a173976ca11",
55826
+ blockCreated: 15921452
55827
+ }
55828
+ }
55829
+ });
55830
+ }
55831
+ });
55832
+
55833
+ // ../../node_modules/.pnpm/viem@2.55.15_bufferutil@4.1_ce20031be19c56210207d462110a7a29/node_modules/viem/_esm/chains/definitions/mainnet.js
55834
+ var mainnet;
55835
+ var init_mainnet = __esm({
55836
+ "../../node_modules/.pnpm/viem@2.55.15_bufferutil@4.1_ce20031be19c56210207d462110a7a29/node_modules/viem/_esm/chains/definitions/mainnet.js"() {
55837
+ init_defineChain();
55838
+ mainnet = /* @__PURE__ */ defineChain({
55839
+ id: 1,
55840
+ name: "Ethereum",
55841
+ nativeCurrency: { name: "Ether", symbol: "ETH", decimals: 18 },
55842
+ blockTime: 12e3,
55843
+ rpcUrls: {
55844
+ default: {
55845
+ http: ["https://ethereum.reth.rs/rpc"]
55846
+ }
55847
+ },
55848
+ blockExplorers: {
55849
+ default: {
55850
+ name: "Etherscan",
55851
+ url: "https://etherscan.io",
55852
+ apiUrl: "https://api.etherscan.io/api"
55853
+ }
55854
+ },
55855
+ contracts: {
55856
+ ensUniversalResolver: {
55857
+ address: "0xeeeeeeee14d718c2b47d9923deab1335e144eeee",
55858
+ blockCreated: 23085558
55859
+ },
55860
+ multicall3: {
55861
+ address: "0xca11bde05977b3631167028862be2a173976ca11",
55862
+ blockCreated: 14353601
55863
+ }
55864
+ }
55865
+ });
55866
+ }
55867
+ });
55868
+
55869
+ // ../../node_modules/.pnpm/viem@2.55.15_bufferutil@4.1_ce20031be19c56210207d462110a7a29/node_modules/viem/_esm/chains/definitions/optimism.js
55870
+ var sourceId3, optimism;
55871
+ var init_optimism = __esm({
55872
+ "../../node_modules/.pnpm/viem@2.55.15_bufferutil@4.1_ce20031be19c56210207d462110a7a29/node_modules/viem/_esm/chains/definitions/optimism.js"() {
55873
+ init_chainConfig();
55874
+ init_defineChain();
55875
+ sourceId3 = 1;
55876
+ optimism = /* @__PURE__ */ defineChain({
55877
+ ...chainConfig,
55878
+ id: 10,
55879
+ name: "OP Mainnet",
55880
+ nativeCurrency: { name: "Ether", symbol: "ETH", decimals: 18 },
55881
+ rpcUrls: {
55882
+ default: {
55883
+ http: ["https://mainnet.optimism.io"]
55884
+ }
55885
+ },
55886
+ blockExplorers: {
55887
+ default: {
55888
+ name: "Optimism Explorer",
55889
+ url: "https://optimistic.etherscan.io",
55890
+ apiUrl: "https://api-optimistic.etherscan.io/api"
55891
+ }
55892
+ },
55893
+ contracts: {
55894
+ ...chainConfig.contracts,
55895
+ disputeGameFactory: {
55896
+ [sourceId3]: {
55897
+ address: "0xe5965Ab5962eDc7477C8520243A95517CD252fA9"
55898
+ }
55899
+ },
55900
+ l2OutputOracle: {
55901
+ [sourceId3]: {
55902
+ address: "0xdfe97868233d1aa22e815a266982f2cf17685a27"
55903
+ }
55904
+ },
55905
+ multicall3: {
55906
+ address: "0xca11bde05977b3631167028862be2a173976ca11",
55907
+ blockCreated: 4286263
55908
+ },
55909
+ portal: {
55910
+ [sourceId3]: {
55911
+ address: "0xbEb5Fc579115071764c7423A4f12eDde41f106Ed"
55912
+ }
55913
+ },
55914
+ l1StandardBridge: {
55915
+ [sourceId3]: {
55916
+ address: "0x99C9fc46f92E8a1c0deC1b1747d010903E884bE1"
55917
+ }
55918
+ }
55919
+ },
55920
+ sourceId: sourceId3
55921
+ });
55922
+ }
55923
+ });
55924
+
55528
55925
  // ../../node_modules/.pnpm/viem@2.55.15_bufferutil@4.1_ce20031be19c56210207d462110a7a29/node_modules/viem/_esm/chains/index.js
55529
55926
  var init_chains2 = __esm({
55530
55927
  "../../node_modules/.pnpm/viem@2.55.15_bufferutil@4.1_ce20031be19c56210207d462110a7a29/node_modules/viem/_esm/chains/index.js"() {
55928
+ init_arbitrum();
55531
55929
  init_base2();
55532
55930
  init_baseSepolia();
55931
+ init_bsc();
55932
+ init_mainnet();
55933
+ init_optimism();
55533
55934
  }
55534
55935
  });
55535
55936
 
@@ -56135,40 +56536,10 @@ function textValue(value, name, allowEmpty = false) {
56135
56536
  return value;
56136
56537
  }
56137
56538
  function resolveSkillViemChain(chainId) {
56138
- if (chainId === base.id) return base;
56139
- if (chainId === baseSepolia.id) return baseSepolia;
56539
+ const chain = [mainnet, optimism, bsc, base, arbitrum, baseSepolia].find((candidate) => candidate.id === chainId);
56540
+ if (chain !== void 0) return chain;
56140
56541
  throw new TypeError(`Unsupported Skill chain ${String(chainId)}.`);
56141
56542
  }
56142
- function viemFactory2(rpcUrl) {
56143
- const transport = http2(parseRpcUrl3(rpcUrl), { retryCount: 0, timeout: 2e4 });
56144
- return (key, chainId) => {
56145
- const chain = resolveSkillViemChain(chainId);
56146
- const account = privateKeyToAccount(key);
56147
- const publicClient = createPublicClient({ chain, transport });
56148
- const walletClient = createWalletClient({ account, chain, transport });
56149
- return Object.freeze({
56150
- walletAddress: account.address.toLowerCase(),
56151
- getChainId: () => publicClient.getChainId(),
56152
- sendTransaction: (input) => walletClient.sendTransaction({ account, chain, ...input }),
56153
- waitForReceipt: async (hash5) => {
56154
- const receipt = await publicClient.waitForTransactionReceipt({ hash: hash5, confirmations: 1, timeout: 12e4 });
56155
- return Object.freeze({ status: receipt.status, blockNumber: receipt.blockNumber });
56156
- },
56157
- getTransactionCall: async (hash5) => {
56158
- const transaction2 = await publicClient.getTransaction({ hash: hash5 });
56159
- return Object.freeze({ from: transaction2.from, to: transaction2.to, data: transaction2.input, value: transaction2.value });
56160
- },
56161
- getTransactionRecord: async (hash5) => {
56162
- const [transaction2, receipt] = await Promise.all([
56163
- publicClient.getTransaction({ hash: hash5 }),
56164
- publicClient.getTransactionReceipt({ hash: hash5 })
56165
- ]);
56166
- if (transaction2.blockNumber === null || transaction2.blockNumber !== receipt.blockNumber) throw new TypeError("Skill recovery transaction is not settled in its recorded block.");
56167
- return Object.freeze({ from: transaction2.from, to: transaction2.to, data: transaction2.input, value: transaction2.value, status: receipt.status, blockNumber: receipt.blockNumber });
56168
- }
56169
- });
56170
- };
56171
- }
56172
56543
  function expectedCall(kind, request, deployment2) {
56173
56544
  const skillId = () => unsigned2(request.skillId, "Skill id", true);
56174
56545
  if (kind === "purchase") {
@@ -56228,7 +56599,7 @@ function assertIntentMatches(raw, expected, chainId) {
56228
56599
  throw new TypeError("Skill intent calldata, target, or value does not match its reviewed request.");
56229
56600
  }
56230
56601
  }
56231
- var import_ajv3, instanceAbi, tokenAbi, revenueAbi, factoryAbi, validateIntent2, InstalledSkillIntentSender;
56602
+ var import_ajv3, instanceAbi, tokenAbi, revenueAbi, factoryAbi, validateIntent2, viemFactory2, InstalledSkillIntentSender;
56232
56603
  var init_skill_intent_sender = __esm({
56233
56604
  "src/skill-intent-sender.ts"() {
56234
56605
  "use strict";
@@ -56256,34 +56627,80 @@ var init_skill_intent_sender = __esm({
56256
56627
  "function createSkill((bytes32 mdHash, bytes32 packageHash, string packageURI, string slug, string name, string category, string licenseTypeName, string imageURI, bool plaintext, uint256 unitPrice, uint256 maxSupply, uint96 royaltyBPS, uint256 usageLimit) params)"
56257
56628
  ]);
56258
56629
  validateIntent2 = new import_ajv3.default({ allErrors: true, strict: false }).compile(skillIntentResponseSchema);
56630
+ viemFactory2 = (key, chainId, rpcUrl) => {
56631
+ const transport = http2(parseRpcUrl3(rpcUrl), { retryCount: 0, timeout: 2e4 });
56632
+ const chain = resolveSkillViemChain(chainId);
56633
+ const account = privateKeyToAccount(key);
56634
+ const publicClient = createPublicClient({ chain, transport });
56635
+ const walletClient = createWalletClient({ account, chain, transport });
56636
+ return Object.freeze({
56637
+ walletAddress: account.address.toLowerCase(),
56638
+ getChainId: () => publicClient.getChainId(),
56639
+ sendTransaction: (input) => walletClient.sendTransaction({ account, chain, ...input }),
56640
+ waitForReceipt: async (hash5) => {
56641
+ const receipt = await publicClient.waitForTransactionReceipt({ hash: hash5, confirmations: 1, timeout: 12e4 });
56642
+ return Object.freeze({ status: receipt.status, blockNumber: receipt.blockNumber });
56643
+ },
56644
+ getTransactionCall: async (hash5) => {
56645
+ const transaction2 = await publicClient.getTransaction({ hash: hash5 });
56646
+ return Object.freeze({ from: transaction2.from, to: transaction2.to, data: transaction2.input, value: transaction2.value });
56647
+ },
56648
+ getTransactionRecord: async (hash5) => {
56649
+ const [transaction2, receipt] = await Promise.all([
56650
+ publicClient.getTransaction({ hash: hash5 }),
56651
+ publicClient.getTransactionReceipt({ hash: hash5 })
56652
+ ]);
56653
+ if (transaction2.blockNumber === null || transaction2.blockNumber !== receipt.blockNumber) throw new TypeError("Skill recovery transaction is not settled in its recorded block.");
56654
+ return Object.freeze({ from: transaction2.from, to: transaction2.to, data: transaction2.input, value: transaction2.value, status: receipt.status, blockNumber: receipt.blockNumber });
56655
+ }
56656
+ });
56657
+ };
56259
56658
  InstalledSkillIntentSender = class {
56659
+ constructor(environment3 = resolveSkillProtocolEnvironment(process.env.FINCH_ENVIRONMENT), environmentVariables = process.env, rpcFactory = viemFactory2) {
56660
+ this.environment = environment3;
56661
+ this.environmentVariables = environmentVariables;
56662
+ this.rpcFactory = rpcFactory;
56663
+ }
56664
+ environment;
56665
+ environmentVariables;
56260
56666
  rpcFactory;
56261
- deployment;
56262
- constructor(rpcUrl, factory, environment3 = resolveSkillProtocolEnvironment(process.env.FINCH_ENVIRONMENT)) {
56263
- parseRpcUrl3(rpcUrl);
56264
- this.rpcFactory = factory ?? viemFactory2(rpcUrl);
56265
- this.deployment = getSkillProtocolDeployment(resolveSkillProtocolEnvironment(environment3));
56667
+ authority(chainIdValue) {
56668
+ if (!Number.isInteger(chainIdValue) || Number(chainIdValue) < 1) {
56669
+ throw new TypeError("Skill request chain is invalid.");
56670
+ }
56671
+ return getSkillProtocolDeployment(resolveSkillProtocolEnvironment(this.environment), Number(chainIdValue));
56672
+ }
56673
+ async rpc(privateKey3, walletAddress2, deployment2) {
56674
+ const override = this.environmentVariables[`FINCHTECH_RPC_URL_${deployment2.chainId}`];
56675
+ const rpcUrl = parseRpcUrl3(override ?? deployment2.defaultRpcUrls[0]);
56676
+ const rpc = this.rpcFactory(installedPrivateKey2(privateKey3), deployment2.chainId, rpcUrl);
56677
+ if (rpc.walletAddress.toLowerCase() !== walletAddress2.toLowerCase() || await rpc.getChainId() !== deployment2.chainId) {
56678
+ throw new TypeError("The wallet or RPC chain does not match the selected Skill authority.");
56679
+ }
56680
+ return rpc;
56266
56681
  }
56267
56682
  buyerCall(input) {
56268
56683
  if (!validateIntent2(input.intent)) throw new TypeError("Skill intent does not match the frozen contract.");
56269
- if (input.intent.kind !== input.expectedKind || input.intent.sourceCommit !== this.deployment.sourceCommit || input.intent.chainId !== this.deployment.chainId) throw new TypeError("Skill intent authority is invalid.");
56684
+ const deployment2 = this.authority(input.intent.chainId);
56685
+ if (input.intent.kind !== input.expectedKind || input.intent.sourceCommit !== deployment2.sourceCommit) {
56686
+ throw new TypeError("Skill intent authority is invalid.");
56687
+ }
56270
56688
  if (typeof input.intent.walletAddress !== "string" || input.intent.walletAddress.toLowerCase() !== input.walletAddress.toLowerCase()) {
56271
56689
  throw new TypeError("Skill intent wallet does not match the active CLI wallet.");
56272
56690
  }
56273
- const expected = expectedCall(input.expectedKind, record4(input.intent.request, "Skill intent request"), this.deployment);
56274
- assertIntentMatches(input.intent, expected, this.deployment.chainId);
56275
- return expected;
56276
- }
56277
- async buyerRpc(privateKey3, walletAddress2) {
56278
- const rpc = this.rpcFactory(installedPrivateKey2(privateKey3), this.deployment.chainId);
56279
- if (rpc.walletAddress !== walletAddress2 || await rpc.getChainId() !== this.deployment.chainId) {
56280
- throw new TypeError("The wallet or RPC chain does not match the selected Skill authority.");
56281
- }
56282
- return rpc;
56691
+ const request = record4(input.intent.request, "Skill intent request");
56692
+ if (request.chainId !== deployment2.chainId) throw new TypeError("Skill intent request chain is invalid.");
56693
+ const expected = expectedCall(input.expectedKind, request, deployment2);
56694
+ assertIntentMatches(
56695
+ input.intent,
56696
+ expected,
56697
+ deployment2.chainId
56698
+ );
56699
+ return Object.freeze({ expected, deployment: deployment2 });
56283
56700
  }
56284
56701
  async submit(input) {
56285
- const expected = this.buyerCall(input);
56286
- const rpc = await this.buyerRpc(input.privateKey, input.walletAddress);
56702
+ const { expected, deployment: deployment2 } = this.buyerCall(input);
56703
+ const rpc = await this.rpc(input.privateKey, input.walletAddress, deployment2);
56287
56704
  const transactionHash3 = await rpc.sendTransaction(expected);
56288
56705
  await input.onBroadcast?.({ fingerprint: skillBuyerIntentFingerprint(input.intent), transactionHash: transactionHash3 });
56289
56706
  const receipt = await rpc.waitForReceipt(transactionHash3);
@@ -56291,8 +56708,8 @@ var init_skill_intent_sender = __esm({
56291
56708
  return Object.freeze({ transactionHash: transactionHash3, blockNumber: receipt.blockNumber.toString() });
56292
56709
  }
56293
56710
  async verifyBuyerIntent(input) {
56294
- const expected = this.buyerCall(input);
56295
- const rpc = await this.buyerRpc(input.privateKey, input.walletAddress);
56711
+ const { expected, deployment: deployment2 } = this.buyerCall(input);
56712
+ const rpc = await this.rpc(input.privateKey, input.walletAddress, deployment2);
56296
56713
  const transactionHash3 = hash4(input.transactionHash, "Skill buyer recovery transaction hash");
56297
56714
  const exactTransaction2 = (actual2) => actual2.from.toLowerCase() === input.walletAddress.toLowerCase() && actual2.to?.toLowerCase() === expected.to.toLowerCase() && actual2.data === expected.data && actual2.value === expected.value;
56298
56715
  if (input.blockNumber === null) {
@@ -56311,10 +56728,12 @@ var init_skill_intent_sender = __esm({
56311
56728
  return Object.freeze({ transactionHash: transactionHash3, blockNumber: actual.blockNumber.toString() });
56312
56729
  }
56313
56730
  async submitPrepared(input) {
56314
- const rpc = this.rpcFactory(installedPrivateKey2(input.privateKey), this.deployment.chainId);
56315
- if (rpc.walletAddress !== input.walletAddress || await rpc.getChainId() !== this.deployment.chainId) throw new TypeError("The wallet or RPC chain does not match the selected Skill authority.");
56316
- const expected = expectedPreparedCall(input.action, record4(input.request, "Skill prepared request"), this.deployment);
56317
- assertIntentMatches(input.intent, expected, this.deployment.chainId);
56731
+ const request = record4(input.request, "Skill prepared request");
56732
+ const deployment2 = this.authority(request.chainId);
56733
+ if (input.intent.chainId !== deployment2.chainId) throw new TypeError("Skill prepared intent chain is invalid.");
56734
+ const expected = expectedPreparedCall(input.action, request, deployment2);
56735
+ assertIntentMatches(input.intent, expected, deployment2.chainId);
56736
+ const rpc = await this.rpc(input.privateKey, input.walletAddress, deployment2);
56318
56737
  const transactionHash3 = await rpc.sendTransaction(expected);
56319
56738
  await input.onBroadcast?.({ transactionHash: transactionHash3 });
56320
56739
  const receipt = await rpc.waitForReceipt(transactionHash3);
@@ -56322,9 +56741,10 @@ var init_skill_intent_sender = __esm({
56322
56741
  return Object.freeze({ transactionHash: transactionHash3, blockNumber: receipt.blockNumber.toString() });
56323
56742
  }
56324
56743
  async verifyPrepared(input) {
56325
- const rpc = this.rpcFactory(installedPrivateKey2(input.privateKey), this.deployment.chainId);
56326
- if (rpc.walletAddress !== input.walletAddress || await rpc.getChainId() !== this.deployment.chainId) throw new TypeError("The wallet or RPC chain does not match the selected Skill authority.");
56327
- const expected = expectedPreparedCall(input.action, record4(input.request, "Skill prepared request"), this.deployment);
56744
+ const request = record4(input.request, "Skill prepared request");
56745
+ const deployment2 = this.authority(request.chainId);
56746
+ const expected = expectedPreparedCall(input.action, request, deployment2);
56747
+ const rpc = await this.rpc(input.privateKey, input.walletAddress, deployment2);
56328
56748
  const transactionHash3 = hash4(input.transactionHash, "Skill recovery transaction hash");
56329
56749
  const exactTransaction2 = (actual2) => actual2.from.toLowerCase() === input.walletAddress && actual2.to?.toLowerCase() === expected.to.toLowerCase() && actual2.data === expected.data && actual2.value === expected.value;
56330
56750
  if (input.blockNumber === null) {
@@ -56346,81 +56766,14 @@ var init_skill_intent_sender = __esm({
56346
56766
  }
56347
56767
  });
56348
56768
 
56349
- // src/mcp-handoff.ts
56350
- import { spawn } from "node:child_process";
56351
- function canonicalMcpUrl(value) {
56352
- const url2 = new URL(value);
56353
- const localHttp = url2.protocol === "http:" && ["127.0.0.1", "localhost", "[::1]"].includes(url2.hostname);
56354
- if (url2.protocol !== "https:" && !localHttp || url2.username !== "" || url2.password !== "" || url2.pathname !== "/mcp" || url2.search !== "" || url2.hash !== "") {
56355
- throw new TypeError("Finch MCP handoff URL is invalid.");
56356
- }
56357
- return url2.toString();
56358
- }
56359
- var MCP_HANDOFF_TOKEN_ENV, runInteractiveProcess, InstalledCodexMcpHarness;
56360
- var init_mcp_handoff = __esm({
56361
- "src/mcp-handoff.ts"() {
56362
- "use strict";
56363
- MCP_HANDOFF_TOKEN_ENV = "FINCHTECH_MCP_HANDOFF_TOKEN";
56364
- runInteractiveProcess = async (input) => new Promise((resolve4, reject5) => {
56365
- const child = spawn(input.executable, [...input.arguments], {
56366
- env: input.environment,
56367
- shell: false,
56368
- stdio: "inherit"
56369
- });
56370
- child.once("error", reject5);
56371
- child.once("exit", (code, signal) => {
56372
- if (signal !== null || code === null) {
56373
- reject5(new TypeError("Codex MCP handoff terminated without an exit code."));
56374
- return;
56375
- }
56376
- resolve4(Object.freeze({ exitCode: code }));
56377
- });
56378
- });
56379
- InstalledCodexMcpHarness = class {
56380
- baseEnvironment;
56381
- run;
56382
- platform;
56383
- constructor(baseEnvironment = process.env, run = runInteractiveProcess, platform = process.platform) {
56384
- this.baseEnvironment = { ...baseEnvironment };
56385
- this.run = run;
56386
- this.platform = platform;
56387
- }
56388
- async launch(input) {
56389
- if (input.client !== "codex" || !/^[A-Za-z0-9_-]{43}$/u.test(input.bearer)) {
56390
- throw new TypeError("Codex MCP handoff authority is invalid.");
56391
- }
56392
- const mcpUrl = canonicalMcpUrl(input.mcpUrl);
56393
- const codexArguments = Object.freeze([
56394
- "-c",
56395
- `mcp_servers.finch.url="${mcpUrl}"`,
56396
- "-c",
56397
- `mcp_servers.finch.bearer_token_env_var="${MCP_HANDOFF_TOKEN_ENV}"`,
56398
- "-c",
56399
- "mcp_servers.finch.enabled=true"
56400
- ]);
56401
- const windows = this.platform === "win32";
56402
- const result2 = await this.run(Object.freeze({
56403
- executable: windows ? this.baseEnvironment.ComSpec ?? "cmd.exe" : "codex",
56404
- arguments: windows ? Object.freeze(["/d", "/s", "/c", "codex", ...codexArguments]) : codexArguments,
56405
- environment: Object.freeze({ ...this.baseEnvironment, [MCP_HANDOFF_TOKEN_ENV]: input.bearer })
56406
- }));
56407
- if (!Number.isInteger(result2.exitCode) || result2.exitCode !== 0) {
56408
- throw new TypeError(`Codex exited with status ${String(result2.exitCode)}.`);
56409
- }
56410
- return Object.freeze({ exitCode: result2.exitCode });
56411
- }
56412
- };
56413
- }
56414
- });
56415
-
56416
56769
  // src/browser-launcher.ts
56417
- import { spawn as spawn2 } from "node:child_process";
56770
+ import { spawn } from "node:child_process";
56418
56771
  var launchBrowserCommand, InstalledBrowserLauncher;
56419
56772
  var init_browser_launcher = __esm({
56420
56773
  "src/browser-launcher.ts"() {
56421
56774
  "use strict";
56422
56775
  init_cli_error();
56423
- launchBrowserCommand = (command, arguments_) => spawn2(
56776
+ launchBrowserCommand = (command, arguments_) => spawn(
56424
56777
  command,
56425
56778
  [...arguments_],
56426
56779
  { stdio: "ignore", windowsHide: true }
@@ -56432,8 +56785,8 @@ var init_browser_launcher = __esm({
56432
56785
  launch;
56433
56786
  async open(url2) {
56434
56787
  await new Promise((resolve4, reject5) => {
56435
- const command = process.platform === "win32" ? "cmd" : process.platform === "darwin" ? "open" : "xdg-open";
56436
- const args = process.platform === "win32" ? ["/d", "/s", "/c", "start", "", url2] : [url2];
56788
+ const command = process.platform === "win32" ? "rundll32.exe" : process.platform === "darwin" ? "open" : "xdg-open";
56789
+ const args = process.platform === "win32" ? ["url.dll,FileProtocolHandler", url2] : [url2];
56437
56790
  const child = this.launch(command, args);
56438
56791
  child.once("error", () => reject5(new BrowserOpenError()));
56439
56792
  child.once("close", (code) => code === 0 ? resolve4() : reject5(new BrowserOpenError()));
@@ -56525,15 +56878,6 @@ function resolveInstalledRpcUrls(profile, explicitRpcUrl, command) {
56525
56878
  task: explicitRpcUrl ?? deployment2.defaultRpcUrls[0]
56526
56879
  });
56527
56880
  }
56528
- if (command === "skill") {
56529
- if (profile.environment === "local") {
56530
- return explicitRpcUrl === void 0 ? Object.freeze({}) : Object.freeze({ skill: explicitRpcUrl });
56531
- }
56532
- const deployment2 = getSkillProtocolDeployment(profile.environment);
56533
- return Object.freeze({
56534
- skill: explicitRpcUrl ?? deployment2.defaultRpcUrls[0]
56535
- });
56536
- }
56537
56881
  return Object.freeze({});
56538
56882
  }
56539
56883
  async function runInstalledCli(arguments_, environment3 = process.env, authorities = {}) {
@@ -56547,7 +56891,7 @@ async function runInstalledCli(arguments_, environment3 = process.env, authoriti
56547
56891
  const signer = new InstalledWalletSigner();
56548
56892
  const explicitRpcUrl = profile?.chainId === 8453 ? environment3.FINCHTECH_RPC_URL_8453 : environment3.FINCHTECH_RPC_URL_84532;
56549
56893
  const rpcUrls = resolveInstalledRpcUrls(profile, explicitRpcUrl, arguments_[0]);
56550
- const skillIntentSender = rpcUrls.skill === void 0 ? void 0 : new InstalledSkillIntentSender(rpcUrls.skill, void 0, profile?.environment);
56894
+ const skillIntentSender = profile === void 0 || arguments_[0] !== "skill" ? void 0 : new InstalledSkillIntentSender(profile.environment, environment3);
56551
56895
  const application = new FinchCliApplication({
56552
56896
  api,
56553
56897
  state,
@@ -56560,7 +56904,6 @@ async function runInstalledCli(arguments_, environment3 = process.env, authoriti
56560
56904
  taskProtocolSender: rpcUrls.task === void 0 ? void 0 : new InstalledTaskProtocolSender(rpcUrls.task),
56561
56905
  skillIntentSender,
56562
56906
  skillLocalFlow: profile === void 0 || skillIntentSender === void 0 ? void 0 : new SkillLocalFlow(api, skillIntentSender, signer, void 0, void 0, state),
56563
- mcpHarness: authorities.mcpHarness ?? new InstalledCodexMcpHarness(environment3),
56564
56907
  browserLauncher: new InstalledBrowserLauncher()
56565
56908
  });
56566
56909
  return routeCommand(arguments_, application);
@@ -56580,7 +56923,6 @@ var init_main = __esm({
56580
56923
  init_task_protocol_sender();
56581
56924
  init_skill_intent_sender();
56582
56925
  init_skill_local_flow();
56583
- init_mcp_handoff();
56584
56926
  init_browser_launcher();
56585
56927
  }
56586
56928
  });