@elisym/cli 0.21.2 → 0.21.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -2,7 +2,7 @@
2
2
  import { ReadableStream } from 'node:stream/web';
3
3
  import { readFileSync, existsSync, readdirSync, statSync, renameSync, chmodSync, mkdirSync, writeFileSync } from 'node:fs';
4
4
  import { dirname, join, resolve, basename, relative, sep } from 'node:path';
5
- import { SolanaPaymentStrategy, validateAgentName, RELAYS, ElisymIdentity, formatSol, formatAssetAmount, USDC_SOLANA_DEVNET, ElisymClient, MediaService, POLICY_D_TAG_PREFIX, KIND_LONG_FORM_ARTICLE, POLICY_T_TAG, jobRequestKind, DEFAULT_KIND_OFFSET, toDTag, DEFAULTS, makeCensor, DEFAULT_REDACT_PATHS, createSlidingWindowLimiter, getProtocolProgramId, getProtocolConfig, utf8ByteLength, LIMITS, calculateProtocolFee, decodeJobPayload, BoundedSet, KIND_JOB_FEEDBACK, NATIVE_SOL } from '@elisym/sdk';
5
+ import { SolanaPaymentStrategy, validateAgentName, RELAYS, ElisymIdentity, formatSol, formatAssetAmount, USDC_SOLANA_DEVNET, ElisymClient, MediaService, POLICY_D_TAG_PREFIX, KIND_LONG_FORM_ARTICLE, jobRequestKind, DEFAULT_KIND_OFFSET, toDTag, DEFAULTS, makeCensor, DEFAULT_REDACT_PATHS, POLICY_T_TAG, createSlidingWindowLimiter, getProtocolProgramId, getProtocolConfig, utf8ByteLength, LIMITS, calculateProtocolFee, decodeJobPayload, BoundedSet, KIND_JOB_FEEDBACK, NATIVE_SOL } from '@elisym/sdk';
6
6
  import { ElisymYamlSchema, resolveInHome, resolveInProject, createAgentDir, writeYamlInitial, writeExampleSkillTemplate, writeSecrets, listAgents, loadAgent, writeYaml, agentPaths, readMediaCache, loadPoliciesFromDir, ensureGitignoreHasIrohEntry, lookupCachedUrl, newCacheEntry, writeMediaCache } from '@elisym/sdk/agent-store';
7
7
  import { isAddress, createSolanaRpc, address } from '@solana/kit';
8
8
  import { generateSecretKey, getPublicKey, nip19, verifyEvent } from 'nostr-tools';
@@ -4224,7 +4224,36 @@ async function cmdStart(nameArg, options = {}) {
4224
4224
  const localPolicyDTags = new Set(
4225
4225
  policies.map((policy) => `${POLICY_D_TAG_PREFIX}${policy.type}`)
4226
4226
  );
4227
+ async function fetchPublishedPolicies() {
4228
+ try {
4229
+ return await client.pool.querySync({
4230
+ kinds: [KIND_LONG_FORM_ARTICLE],
4231
+ authors: [identity.publicKey],
4232
+ "#t": [POLICY_T_TAG]
4233
+ });
4234
+ } catch {
4235
+ return [];
4236
+ }
4237
+ }
4238
+ const publishedPolicies = await fetchPublishedPolicies();
4239
+ const latestPolicyByDTag = /* @__PURE__ */ new Map();
4240
+ for (const event of publishedPolicies) {
4241
+ const dTag = event.tags.find((tag) => tag[0] === "d")?.[1];
4242
+ if (!dTag) {
4243
+ continue;
4244
+ }
4245
+ const prev = latestPolicyByDTag.get(dTag);
4246
+ if (!prev || event.created_at > prev.created_at) {
4247
+ latestPolicyByDTag.set(dTag, event);
4248
+ }
4249
+ }
4227
4250
  for (const policy of policies) {
4251
+ const onRelay = latestPolicyByDTag.get(`${POLICY_D_TAG_PREFIX}${policy.type}`);
4252
+ const relayVersion = onRelay?.tags.find((tag) => tag[0] === "policy_version")?.[1];
4253
+ if (onRelay && onRelay.content && relayVersion === policy.version && onRelay.content === policy.content) {
4254
+ console.log(` * Policy: ${policy.type}@${policy.version} (unchanged, skipped)`);
4255
+ continue;
4256
+ }
4228
4257
  try {
4229
4258
  const { naddr } = await client.policies.publishPolicy(identity, policy);
4230
4259
  console.log(` * Policy: ${policy.type}@${policy.version} -> ${naddr}`);
@@ -4245,31 +4274,23 @@ async function cmdStart(nameArg, options = {}) {
4245
4274
  );
4246
4275
  }
4247
4276
  }
4248
- try {
4249
- const existingPolicies = await client.pool.querySync({
4250
- kinds: [KIND_LONG_FORM_ARTICLE],
4251
- authors: [identity.publicKey],
4252
- "#t": [POLICY_T_TAG]
4253
- });
4254
- for (const event of existingPolicies) {
4255
- const dTag = event.tags.find((tag) => tag[0] === "d")?.[1];
4256
- if (!dTag || localPolicyDTags.has(dTag)) {
4257
- continue;
4258
- }
4259
- if (!event.content) {
4260
- continue;
4261
- }
4262
- const type = event.tags.find((tag) => tag[0] === "policy_type")?.[1];
4263
- if (!type) {
4264
- continue;
4265
- }
4266
- try {
4267
- await client.policies.deletePolicy(identity, type);
4268
- console.log(` Removed stale policy: ${type}`);
4269
- } catch {
4270
- }
4277
+ for (const event of publishedPolicies) {
4278
+ const dTag = event.tags.find((tag) => tag[0] === "d")?.[1];
4279
+ if (!dTag || localPolicyDTags.has(dTag)) {
4280
+ continue;
4281
+ }
4282
+ if (!event.content) {
4283
+ continue;
4284
+ }
4285
+ const type = event.tags.find((tag) => tag[0] === "policy_type")?.[1];
4286
+ if (!type) {
4287
+ continue;
4288
+ }
4289
+ try {
4290
+ await client.policies.deletePolicy(identity, type);
4291
+ console.log(` Removed stale policy: ${type}`);
4292
+ } catch {
4271
4293
  }
4272
- } catch {
4273
4294
  }
4274
4295
  const kinds = [jobRequestKind(DEFAULT_KIND_OFFSET)];
4275
4296
  function buildCard(skill) {