@chaoschain/sdk 0.2.3 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +35 -0
- package/README.md +167 -16
- package/dist/{IPFSLocal-BCIADaOU.d.ts → IPFSLocal-B4hnMEfS.d.ts} +1 -1
- package/dist/{IPFSLocal-DqzD3Y7I.d.cts → IPFSLocal-zRj6kG8e.d.cts} +1 -1
- package/dist/index.cjs +269 -50
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +167 -7
- package/dist/index.d.ts +167 -7
- package/dist/index.js +268 -52
- package/dist/index.js.map +1 -1
- package/dist/providers/compute/index.d.cts +1 -1
- package/dist/providers/compute/index.d.ts +1 -1
- package/dist/providers/storage/index.d.cts +2 -2
- package/dist/providers/storage/index.d.ts +2 -2
- package/dist/{types-CEFAgoAM.d.cts → types-BBVtx_jV.d.cts} +45 -13
- package/dist/{types-CEFAgoAM.d.ts → types-BBVtx_jV.d.ts} +45 -13
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -4,7 +4,7 @@ import fs3__default from 'fs';
|
|
|
4
4
|
import * as path3 from 'path';
|
|
5
5
|
import path3__default from 'path';
|
|
6
6
|
import * as crypto2 from 'crypto';
|
|
7
|
-
import { createHash } from 'crypto';
|
|
7
|
+
import { randomUUID, createHash } from 'crypto';
|
|
8
8
|
import axios2 from 'axios';
|
|
9
9
|
import * as http from 'http';
|
|
10
10
|
import * as jose from 'jose';
|
|
@@ -12009,10 +12009,10 @@ var X402PaymentManager = class {
|
|
|
12009
12009
|
*/
|
|
12010
12010
|
getTreasuryAddress(network) {
|
|
12011
12011
|
const treasuries = {
|
|
12012
|
-
"base-sepolia": "
|
|
12013
|
-
"ethereum-sepolia": "
|
|
12014
|
-
"optimism-sepolia": "
|
|
12015
|
-
"linea-sepolia": "
|
|
12012
|
+
"base-sepolia": "0x20E7B2A2c8969725b88Dd3EF3a11Bc3353C83F70",
|
|
12013
|
+
"ethereum-sepolia": "0x20E7B2A2c8969725b88Dd3EF3a11Bc3353C83F70",
|
|
12014
|
+
"optimism-sepolia": "0x20E7B2A2c8969725b88Dd3EF3a11Bc3353C83F70",
|
|
12015
|
+
"linea-sepolia": "0x20E7B2A2c8969725b88Dd3EF3a11Bc3353C83F70"
|
|
12016
12016
|
};
|
|
12017
12017
|
return treasuries[network] || treasuries["base-sepolia"];
|
|
12018
12018
|
}
|
|
@@ -15365,10 +15365,189 @@ var StudioClient = class {
|
|
|
15365
15365
|
return ethers.hexlify(ethers.randomBytes(32));
|
|
15366
15366
|
}
|
|
15367
15367
|
};
|
|
15368
|
+
var STEP_TYPE_MAP = {
|
|
15369
|
+
planning: "plan_created",
|
|
15370
|
+
testing: "test_run",
|
|
15371
|
+
debugging: "debug_step",
|
|
15372
|
+
implementing: "file_written",
|
|
15373
|
+
completing: "submission_created"
|
|
15374
|
+
};
|
|
15375
|
+
var Session = class {
|
|
15376
|
+
/** Session ID returned by the gateway. */
|
|
15377
|
+
sessionId;
|
|
15378
|
+
gatewayUrl;
|
|
15379
|
+
apiKey;
|
|
15380
|
+
studioAddress;
|
|
15381
|
+
agentAddress;
|
|
15382
|
+
studioPolicyVersion;
|
|
15383
|
+
workMandateId;
|
|
15384
|
+
taskType;
|
|
15385
|
+
lastEventId;
|
|
15386
|
+
/** @internal — use {@link SessionClient.start} to create instances. */
|
|
15387
|
+
constructor(opts) {
|
|
15388
|
+
this.sessionId = opts.sessionId;
|
|
15389
|
+
this.gatewayUrl = opts.gatewayUrl;
|
|
15390
|
+
this.apiKey = opts.apiKey;
|
|
15391
|
+
this.lastEventId = opts.lastEventId ?? null;
|
|
15392
|
+
this.studioAddress = opts.studioAddress;
|
|
15393
|
+
this.agentAddress = opts.agentAddress;
|
|
15394
|
+
this.studioPolicyVersion = opts.studioPolicyVersion;
|
|
15395
|
+
this.workMandateId = opts.workMandateId;
|
|
15396
|
+
this.taskType = opts.taskType;
|
|
15397
|
+
}
|
|
15398
|
+
/**
|
|
15399
|
+
* Log a session event.
|
|
15400
|
+
*
|
|
15401
|
+
* Automatically generates `event_id`, `timestamp`, and chains `parent_event_ids`
|
|
15402
|
+
* from the previous event so the gateway can build a causal DAG.
|
|
15403
|
+
*
|
|
15404
|
+
* @param opts - Event details. Only `summary` is required.
|
|
15405
|
+
* @throws Error if the gateway returns a non-2xx status.
|
|
15406
|
+
*/
|
|
15407
|
+
async log(opts) {
|
|
15408
|
+
const eventId = randomUUID();
|
|
15409
|
+
const event = {
|
|
15410
|
+
event_id: eventId,
|
|
15411
|
+
event_type: opts.event_type ?? "artifact_created",
|
|
15412
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
15413
|
+
summary: opts.summary,
|
|
15414
|
+
causality: {
|
|
15415
|
+
parent_event_ids: this.lastEventId ? [this.lastEventId] : []
|
|
15416
|
+
},
|
|
15417
|
+
agent: { agent_address: this.agentAddress, role: "worker" },
|
|
15418
|
+
studio: {
|
|
15419
|
+
studio_address: this.studioAddress,
|
|
15420
|
+
studio_policy_version: this.studioPolicyVersion
|
|
15421
|
+
},
|
|
15422
|
+
task: {
|
|
15423
|
+
work_mandate_id: this.workMandateId,
|
|
15424
|
+
task_type: this.taskType
|
|
15425
|
+
},
|
|
15426
|
+
...opts.metadata ? { metadata: opts.metadata } : {}
|
|
15427
|
+
};
|
|
15428
|
+
await this.post(`/v1/sessions/${this.sessionId}/events`, [event]);
|
|
15429
|
+
this.lastEventId = eventId;
|
|
15430
|
+
}
|
|
15431
|
+
/**
|
|
15432
|
+
* Convenience wrapper around {@link log} that maps human-friendly step names
|
|
15433
|
+
* to canonical event types.
|
|
15434
|
+
*
|
|
15435
|
+
* Mappings:
|
|
15436
|
+
* - `"planning"` → `plan_created`
|
|
15437
|
+
* - `"testing"` → `test_run`
|
|
15438
|
+
* - `"debugging"` → `debug_step`
|
|
15439
|
+
* - `"implementing"` → `file_written`
|
|
15440
|
+
* - `"completing"` → `submission_created`
|
|
15441
|
+
*
|
|
15442
|
+
* Unknown step types fall back to `artifact_created`.
|
|
15443
|
+
*
|
|
15444
|
+
* @param stepType - Friendly step name.
|
|
15445
|
+
* @param summary - What happened in this step.
|
|
15446
|
+
*/
|
|
15447
|
+
async step(stepType, summary) {
|
|
15448
|
+
const eventType = STEP_TYPE_MAP[stepType] ?? "artifact_created";
|
|
15449
|
+
await this.log({ event_type: eventType, summary });
|
|
15450
|
+
}
|
|
15451
|
+
/**
|
|
15452
|
+
* Complete the session.
|
|
15453
|
+
*
|
|
15454
|
+
* Triggers the on-chain WorkSubmission workflow (if the gateway is configured for it)
|
|
15455
|
+
* and returns `workflow_id` + `data_hash` for downstream verification/scoring.
|
|
15456
|
+
*
|
|
15457
|
+
* @param opts - Optional status (`"completed"` | `"failed"`) and summary.
|
|
15458
|
+
* @returns `{ workflow_id, data_hash }` — both may be `null` if the gateway
|
|
15459
|
+
* workflow engine is not configured.
|
|
15460
|
+
* @throws Error if the gateway returns a non-2xx status.
|
|
15461
|
+
*/
|
|
15462
|
+
async complete(opts) {
|
|
15463
|
+
const body = {};
|
|
15464
|
+
if (opts?.status) body.status = opts.status;
|
|
15465
|
+
if (opts?.summary) body.summary = opts.summary;
|
|
15466
|
+
const data = await this.post(`/v1/sessions/${this.sessionId}/complete`, body);
|
|
15467
|
+
return {
|
|
15468
|
+
workflow_id: data.data?.workflow_id ?? null,
|
|
15469
|
+
data_hash: data.data?.data_hash ?? null
|
|
15470
|
+
};
|
|
15471
|
+
}
|
|
15472
|
+
// ---------------------------------------------------------------------------
|
|
15473
|
+
// Internal HTTP helper
|
|
15474
|
+
// ---------------------------------------------------------------------------
|
|
15475
|
+
async post(path4, body) {
|
|
15476
|
+
const url = `${this.gatewayUrl}${path4}`;
|
|
15477
|
+
const headers = { "Content-Type": "application/json" };
|
|
15478
|
+
if (this.apiKey) headers["X-API-Key"] = this.apiKey;
|
|
15479
|
+
try {
|
|
15480
|
+
const res = await axios2({ method: "POST", url, data: body, headers, timeout: 3e4 });
|
|
15481
|
+
return res.data;
|
|
15482
|
+
} catch (err) {
|
|
15483
|
+
const axiosErr = err;
|
|
15484
|
+
const status = axiosErr.response?.status ?? 0;
|
|
15485
|
+
const detail = JSON.stringify(axiosErr.response?.data ?? axiosErr.message);
|
|
15486
|
+
throw new Error(`Session request failed: POST ${path4} \u2192 ${status} ${detail}`);
|
|
15487
|
+
}
|
|
15488
|
+
}
|
|
15489
|
+
};
|
|
15490
|
+
|
|
15491
|
+
// src/session/SessionClient.ts
|
|
15492
|
+
var SessionClient = class {
|
|
15493
|
+
gatewayUrl;
|
|
15494
|
+
apiKey;
|
|
15495
|
+
constructor(config = {}) {
|
|
15496
|
+
this.gatewayUrl = (config.gatewayUrl ?? "https://gateway.chaoscha.in").replace(/\/$/, "");
|
|
15497
|
+
this.apiKey = config.apiKey;
|
|
15498
|
+
}
|
|
15499
|
+
/**
|
|
15500
|
+
* Create a new coding session on the gateway.
|
|
15501
|
+
*
|
|
15502
|
+
* Returns a {@link Session} instance that can be used to log events, run steps,
|
|
15503
|
+
* and complete the session. The gateway persists all events and constructs the
|
|
15504
|
+
* Evidence DAG automatically.
|
|
15505
|
+
*
|
|
15506
|
+
* @param opts - Session creation parameters.
|
|
15507
|
+
* @returns A live {@link Session} bound to the newly created session ID.
|
|
15508
|
+
* @throws Error if the gateway returns a non-2xx status.
|
|
15509
|
+
*/
|
|
15510
|
+
async start(opts) {
|
|
15511
|
+
const body = {
|
|
15512
|
+
studio_address: opts.studio_address,
|
|
15513
|
+
agent_address: opts.agent_address
|
|
15514
|
+
};
|
|
15515
|
+
if (opts.work_mandate_id) body.work_mandate_id = opts.work_mandate_id;
|
|
15516
|
+
if (opts.task_type) body.task_type = opts.task_type;
|
|
15517
|
+
if (opts.studio_policy_version) body.studio_policy_version = opts.studio_policy_version;
|
|
15518
|
+
if (opts.session_id) body.session_id = opts.session_id;
|
|
15519
|
+
const url = `${this.gatewayUrl}/v1/sessions`;
|
|
15520
|
+
const headers = { "Content-Type": "application/json" };
|
|
15521
|
+
if (this.apiKey) headers["X-API-Key"] = this.apiKey;
|
|
15522
|
+
let data;
|
|
15523
|
+
try {
|
|
15524
|
+
const res = await axios2({ method: "POST", url, data: body, headers, timeout: 3e4 });
|
|
15525
|
+
data = res.data;
|
|
15526
|
+
} catch (err) {
|
|
15527
|
+
const axiosErr = err;
|
|
15528
|
+
const status = axiosErr.response?.status ?? 0;
|
|
15529
|
+
const detail = JSON.stringify(axiosErr.response?.data ?? axiosErr.message);
|
|
15530
|
+
throw new Error(`Failed to create session: POST /v1/sessions \u2192 ${status} ${detail}`);
|
|
15531
|
+
}
|
|
15532
|
+
const sessionId = data.data?.session_id;
|
|
15533
|
+
if (!sessionId) {
|
|
15534
|
+
throw new Error("Gateway response missing session_id");
|
|
15535
|
+
}
|
|
15536
|
+
return new Session({
|
|
15537
|
+
sessionId,
|
|
15538
|
+
gatewayUrl: this.gatewayUrl,
|
|
15539
|
+
apiKey: this.apiKey,
|
|
15540
|
+
studioAddress: opts.studio_address,
|
|
15541
|
+
agentAddress: opts.agent_address,
|
|
15542
|
+
studioPolicyVersion: opts.studio_policy_version ?? "engineering-studio-default-v1",
|
|
15543
|
+
workMandateId: opts.work_mandate_id ?? "generic-task",
|
|
15544
|
+
taskType: opts.task_type ?? "general"
|
|
15545
|
+
});
|
|
15546
|
+
}
|
|
15547
|
+
};
|
|
15368
15548
|
|
|
15369
15549
|
// src/ChaosChainSDK.ts
|
|
15370
15550
|
var ChaosChainSDK = class _ChaosChainSDK {
|
|
15371
|
-
static warnedGatewayMissing = false;
|
|
15372
15551
|
static warnedStudioClientProduction = false;
|
|
15373
15552
|
// Core components
|
|
15374
15553
|
walletManager;
|
|
@@ -15383,8 +15562,10 @@ var ChaosChainSDK = class _ChaosChainSDK {
|
|
|
15383
15562
|
a2aX402Extension;
|
|
15384
15563
|
processIntegrity;
|
|
15385
15564
|
mandateManager;
|
|
15386
|
-
// Gateway client for workflow submission (
|
|
15387
|
-
gateway
|
|
15565
|
+
// Gateway client for workflow submission (always initialized)
|
|
15566
|
+
gateway;
|
|
15567
|
+
/** Session client for Engineering Studio session management. */
|
|
15568
|
+
session;
|
|
15388
15569
|
// Studio client for direct on-chain operations
|
|
15389
15570
|
studio;
|
|
15390
15571
|
// Configuration
|
|
@@ -15546,41 +15727,25 @@ var ChaosChainSDK = class _ChaosChainSDK {
|
|
|
15546
15727
|
this.computeProvider
|
|
15547
15728
|
);
|
|
15548
15729
|
}
|
|
15549
|
-
|
|
15550
|
-
|
|
15551
|
-
|
|
15552
|
-
|
|
15553
|
-
|
|
15554
|
-
|
|
15555
|
-
}
|
|
15730
|
+
const gatewayConfig = config.gatewayConfig ?? (config.gatewayUrl ? { gatewayUrl: config.gatewayUrl } : {});
|
|
15731
|
+
this.gateway = new GatewayClient(gatewayConfig);
|
|
15732
|
+
const gatewayBaseUrl = gatewayConfig.baseUrl ?? gatewayConfig.gatewayUrl ?? "https://gateway.chaoscha.in";
|
|
15733
|
+
this.session = new SessionClient({
|
|
15734
|
+
gatewayUrl: gatewayBaseUrl,
|
|
15735
|
+
apiKey: gatewayConfig.auth?.apiKey
|
|
15736
|
+
});
|
|
15556
15737
|
this.studio = new StudioClient({
|
|
15557
15738
|
provider: this.provider,
|
|
15558
15739
|
signer: this.walletManager.getWallet(),
|
|
15559
15740
|
network: typeof config.network === "string" ? config.network : config.network
|
|
15560
15741
|
});
|
|
15561
15742
|
const isLocalNetwork = String(config.network) === "local" /* LOCAL */ || String(config.network) === "local";
|
|
15562
|
-
if (!this.gateway && !isLocalNetwork && !_ChaosChainSDK.warnedGatewayMissing) {
|
|
15563
|
-
console.warn(
|
|
15564
|
-
"\u26A0\uFE0F Gateway is not configured. For production workflows, use gatewayConfig to enable Gateway orchestration."
|
|
15565
|
-
);
|
|
15566
|
-
_ChaosChainSDK.warnedGatewayMissing = true;
|
|
15567
|
-
}
|
|
15568
15743
|
if (process.env.NODE_ENV === "production" && !isLocalNetwork && !_ChaosChainSDK.warnedStudioClientProduction) {
|
|
15569
15744
|
console.warn(
|
|
15570
15745
|
"\u26A0\uFE0F StudioClient is intended for low-level or testing use. In production, prefer Gateway workflows."
|
|
15571
15746
|
);
|
|
15572
15747
|
_ChaosChainSDK.warnedStudioClientProduction = true;
|
|
15573
15748
|
}
|
|
15574
|
-
console.log(`\u{1F680} ChaosChain SDK initialized for ${this.agentName}`);
|
|
15575
|
-
console.log(` Network: ${this.network}`);
|
|
15576
|
-
console.log(` Wallet: ${this.walletManager.getAddress()}`);
|
|
15577
|
-
console.log(` Features:`);
|
|
15578
|
-
console.log(` - ERC-8004: \u2705`);
|
|
15579
|
-
console.log(` - x402 Payments: ${this.x402PaymentManager ? "\u2705" : "\u274C"}`);
|
|
15580
|
-
console.log(` - Multi-Payment: ${this.paymentManager ? "\u2705" : "\u274C"}`);
|
|
15581
|
-
console.log(` - Google AP2: ${this.googleAP2 ? "\u2705" : "\u274C"}`);
|
|
15582
|
-
console.log(` - Process Integrity: ${this.processIntegrity ? "\u2705" : "\u274C"}`);
|
|
15583
|
-
console.log(` - Storage: \u2705`);
|
|
15584
15749
|
}
|
|
15585
15750
|
// ============================================================================
|
|
15586
15751
|
// ERC-8004 Identity Methods
|
|
@@ -15989,7 +16154,7 @@ var ChaosChainSDK = class _ChaosChainSDK {
|
|
|
15989
16154
|
* Get SDK version
|
|
15990
16155
|
*/
|
|
15991
16156
|
getVersion() {
|
|
15992
|
-
return "0.
|
|
16157
|
+
return "0.3.0";
|
|
15993
16158
|
}
|
|
15994
16159
|
/**
|
|
15995
16160
|
* Get SDK capabilities summary
|
|
@@ -16019,9 +16184,11 @@ var ChaosChainSDK = class _ChaosChainSDK {
|
|
|
16019
16184
|
}
|
|
16020
16185
|
/**
|
|
16021
16186
|
* Check if Gateway is configured.
|
|
16187
|
+
* Always returns true in v0.3.0+. Gateway is always initialized pointing to
|
|
16188
|
+
* https://gateway.chaoscha.in unless overridden via gatewayConfig.
|
|
16022
16189
|
*/
|
|
16023
16190
|
isGatewayEnabled() {
|
|
16024
|
-
return
|
|
16191
|
+
return true;
|
|
16025
16192
|
}
|
|
16026
16193
|
/**
|
|
16027
16194
|
* Get Gateway client instance.
|
|
@@ -16444,24 +16611,51 @@ function resolveScoring(policy, mandate) {
|
|
|
16444
16611
|
}
|
|
16445
16612
|
function computeObserved(evidence) {
|
|
16446
16613
|
const totalNodes = evidence.length;
|
|
16614
|
+
const byId = /* @__PURE__ */ new Map();
|
|
16447
16615
|
const childrenOf = /* @__PURE__ */ new Map();
|
|
16448
16616
|
for (const e of evidence) {
|
|
16617
|
+
byId.set(e.arweave_tx_id, e);
|
|
16449
16618
|
childrenOf.set(e.arweave_tx_id, []);
|
|
16450
16619
|
}
|
|
16451
16620
|
let edgeCount = 0;
|
|
16452
16621
|
let rootCount = 0;
|
|
16453
|
-
let integrationNodeCount = 0;
|
|
16454
16622
|
let artifactCount = 0;
|
|
16455
16623
|
for (const e of evidence) {
|
|
16456
16624
|
edgeCount += e.parent_ids.length;
|
|
16457
16625
|
if (e.parent_ids.length === 0) rootCount++;
|
|
16458
|
-
if (e.parent_ids.length > 1) integrationNodeCount++;
|
|
16459
16626
|
if (e.artifact_ids.length > 0) artifactCount++;
|
|
16460
16627
|
for (const pid of e.parent_ids) {
|
|
16461
16628
|
const c = childrenOf.get(pid);
|
|
16462
16629
|
if (c) c.push(e.arweave_tx_id);
|
|
16463
16630
|
}
|
|
16464
16631
|
}
|
|
16632
|
+
const rootOrigins = /* @__PURE__ */ new Map();
|
|
16633
|
+
function getRootOrigins(id) {
|
|
16634
|
+
if (rootOrigins.has(id)) return rootOrigins.get(id);
|
|
16635
|
+
const node = byId.get(id);
|
|
16636
|
+
if (!node || node.parent_ids.length === 0) {
|
|
16637
|
+
const s = /* @__PURE__ */ new Set([id]);
|
|
16638
|
+
rootOrigins.set(id, s);
|
|
16639
|
+
return s;
|
|
16640
|
+
}
|
|
16641
|
+
const origins = /* @__PURE__ */ new Set();
|
|
16642
|
+
for (const pid of node.parent_ids) {
|
|
16643
|
+
for (const r of getRootOrigins(pid)) origins.add(r);
|
|
16644
|
+
}
|
|
16645
|
+
rootOrigins.set(id, origins);
|
|
16646
|
+
return origins;
|
|
16647
|
+
}
|
|
16648
|
+
for (const e of evidence) getRootOrigins(e.arweave_tx_id);
|
|
16649
|
+
let integrationNodeCount = 0;
|
|
16650
|
+
for (const e of evidence) {
|
|
16651
|
+
if (e.parent_ids.length < 2) continue;
|
|
16652
|
+
const parentRootSets = e.parent_ids.filter((pid) => byId.has(pid)).map((pid) => rootOrigins.get(pid));
|
|
16653
|
+
const uniqueRoots = /* @__PURE__ */ new Set();
|
|
16654
|
+
for (const s of parentRootSets) {
|
|
16655
|
+
for (const r of s) uniqueRoots.add(r);
|
|
16656
|
+
}
|
|
16657
|
+
if (uniqueRoots.size >= 2) integrationNodeCount++;
|
|
16658
|
+
}
|
|
16465
16659
|
let terminalCount = 0;
|
|
16466
16660
|
for (const [, children] of childrenOf) {
|
|
16467
16661
|
if (children.length === 0) terminalCount++;
|
|
@@ -16594,12 +16788,13 @@ function extractAgencySignals(evidence, context) {
|
|
|
16594
16788
|
durationMs: observed.durationMs
|
|
16595
16789
|
};
|
|
16596
16790
|
if (!scoring) {
|
|
16597
|
-
|
|
16598
|
-
|
|
16599
|
-
|
|
16791
|
+
const SOFT_CAP = 0.9;
|
|
16792
|
+
initiativeSignal = Math.max(0, Math.min(SOFT_CAP, rootRatio));
|
|
16793
|
+
collaborationSignal = Math.max(0, Math.min(SOFT_CAP, edgeDensity));
|
|
16794
|
+
reasoningSignal = Math.max(0, Math.min(SOFT_CAP, depthRatio));
|
|
16600
16795
|
} else {
|
|
16601
16796
|
const ir = scoring.initiative.rootRatio;
|
|
16602
|
-
|
|
16797
|
+
const initiativeBase = rangeFit(rootRatio, ir.min, ir.target, ir.max);
|
|
16603
16798
|
const cw = scoring.collaboration.weights;
|
|
16604
16799
|
const ed = scoring.collaboration.edgeDensity;
|
|
16605
16800
|
const intR = scoring.collaboration.integrationRatio;
|
|
@@ -16611,7 +16806,13 @@ function extractAgencySignals(evidence, context) {
|
|
|
16611
16806
|
}
|
|
16612
16807
|
collaborationSignal = Math.max(0, Math.min(1, collaborationSignal));
|
|
16613
16808
|
const dr = scoring.reasoning.depthRatio;
|
|
16614
|
-
|
|
16809
|
+
const reasoningBase = rangeFit(depthRatio, dr.min, dr.target, dr.max);
|
|
16810
|
+
const fragmentationPenalty = rootRatio > ir.max ? (rootRatio - ir.max) * 0.5 : 0;
|
|
16811
|
+
const overcomplexityPenalty = depthRatio > dr.max ? (depthRatio - dr.max) * 0.5 : 0;
|
|
16812
|
+
initiativeSignal = Math.max(0, Math.min(1, initiativeBase - fragmentationPenalty));
|
|
16813
|
+
reasoningSignal = Math.max(0, Math.min(1, reasoningBase - overcomplexityPenalty));
|
|
16814
|
+
observedBlock.fragmentationPenalty = fragmentationPenalty;
|
|
16815
|
+
observedBlock.overcomplexityPenalty = overcomplexityPenalty;
|
|
16615
16816
|
const compResult = computeComplianceSignal(evidence, observed, scoring, context?.workMandate);
|
|
16616
16817
|
complianceSignal = compResult.signal;
|
|
16617
16818
|
observedBlock.testsPresent = compResult.testsPresent;
|
|
@@ -16660,17 +16861,32 @@ function normalizeInput(value) {
|
|
|
16660
16861
|
return Math.max(0, Math.min(1, v));
|
|
16661
16862
|
}
|
|
16662
16863
|
var CLAMP_100 = (v) => Math.max(0, Math.min(100, Math.round(v)));
|
|
16864
|
+
function resolveDimension(override, signal) {
|
|
16865
|
+
if (override !== void 0) return normalizeInput(override);
|
|
16866
|
+
return signal ?? 0;
|
|
16867
|
+
}
|
|
16663
16868
|
function composeScoreVector(signals, assessment) {
|
|
16664
|
-
|
|
16665
|
-
|
|
16666
|
-
|
|
16667
|
-
|
|
16869
|
+
if (assessment.complianceScore === void 0 || assessment.complianceScore === null) {
|
|
16870
|
+
throw new Error("complianceScore is required for production scoring");
|
|
16871
|
+
}
|
|
16872
|
+
if (assessment.efficiencyScore === void 0 || assessment.efficiencyScore === null) {
|
|
16873
|
+
throw new Error("efficiencyScore is required for production scoring");
|
|
16874
|
+
}
|
|
16875
|
+
return [
|
|
16876
|
+
CLAMP_100(resolveDimension(assessment.initiativeScore, signals.initiativeSignal) * 100),
|
|
16877
|
+
CLAMP_100(resolveDimension(assessment.collaborationScore, signals.collaborationSignal) * 100),
|
|
16878
|
+
CLAMP_100(resolveDimension(assessment.reasoningScore, signals.reasoningSignal) * 100),
|
|
16879
|
+
CLAMP_100(normalizeInput(assessment.complianceScore) * 100),
|
|
16880
|
+
CLAMP_100(normalizeInput(assessment.efficiencyScore) * 100)
|
|
16881
|
+
];
|
|
16882
|
+
}
|
|
16883
|
+
function composeScoreVectorWithDefaults(signals, assessment) {
|
|
16668
16884
|
return [
|
|
16669
|
-
CLAMP_100(
|
|
16670
|
-
CLAMP_100(
|
|
16671
|
-
CLAMP_100(
|
|
16672
|
-
CLAMP_100(
|
|
16673
|
-
CLAMP_100(
|
|
16885
|
+
CLAMP_100(resolveDimension(assessment?.initiativeScore, signals.initiativeSignal) * 100),
|
|
16886
|
+
CLAMP_100(resolveDimension(assessment?.collaborationScore, signals.collaborationSignal) * 100),
|
|
16887
|
+
CLAMP_100(resolveDimension(assessment?.reasoningScore, signals.reasoningSignal) * 100),
|
|
16888
|
+
CLAMP_100(resolveDimension(assessment?.complianceScore, signals.complianceSignal) * 100),
|
|
16889
|
+
CLAMP_100(resolveDimension(assessment?.efficiencyScore, signals.efficiencySignal) * 100)
|
|
16674
16890
|
];
|
|
16675
16891
|
}
|
|
16676
16892
|
function derivePoAScores(evidence, options) {
|
|
@@ -16684,7 +16900,7 @@ function derivePoAScores(evidence, options) {
|
|
|
16684
16900
|
];
|
|
16685
16901
|
}
|
|
16686
16902
|
const signals = extractAgencySignals(evidence);
|
|
16687
|
-
return
|
|
16903
|
+
return composeScoreVectorWithDefaults(signals, {
|
|
16688
16904
|
complianceScore: options?.compliance,
|
|
16689
16905
|
efficiencyScore: options?.efficiency
|
|
16690
16906
|
});
|
|
@@ -16736,7 +16952,7 @@ function verifyWorkEvidence(evidence, context) {
|
|
|
16736
16952
|
}
|
|
16737
16953
|
|
|
16738
16954
|
// src/index.ts
|
|
16739
|
-
var SDK_VERSION = "0.
|
|
16955
|
+
var SDK_VERSION = "0.3.0";
|
|
16740
16956
|
var ERC8004_VERSION = "1.0";
|
|
16741
16957
|
var X402_VERSION = "1.0";
|
|
16742
16958
|
var src_default = ChaosChainSDK;
|
|
@@ -16762,6 +16978,6 @@ mime-types/index.js:
|
|
|
16762
16978
|
*)
|
|
16763
16979
|
*/
|
|
16764
16980
|
|
|
16765
|
-
export { A2AX402Extension, AgentRegistrationError, AgentRole, AutoStorageManager, CHAOS_CORE_ABI, ChaosAgent, ChaosChainSDK, ChaosChainSDKError, ConfigurationError, ContractError, ERC8004_VERSION, GatewayClient, GatewayConnectionError, GatewayError, GatewayTimeoutError, GoogleAP2Integration, IDENTITY_REGISTRY_ABI, IPFSLocalStorage, PinataStorage as IPFSPinataStorage, IntegrityVerificationError, IrysStorage, IrysStorage as IrysStorageProvider, LocalIPFSStorage, MandateManager, NetworkConfig, PaymentError, PaymentManager, PaymentMethod, PinataStorage, REPUTATION_REGISTRY_ABI, REWARDS_DISTRIBUTOR_ABI, ValidationError as SDKValidationError, SDK_VERSION, STUDIO_FACTORY_ABI, STUDIO_PROXY_ABI, StorageError, StudioClient, StudioManager, VALIDATION_REGISTRY_ABI, ValidationStatus, WalletManager, WorkflowFailedError, WorkflowState, WorkflowType, X402PaymentManager, X402Server, X402_VERSION, ZeroGStorage, composeScoreVector, computeDepth, src_default as default, derivePoAScores, extractAgencySignals, getContractAddresses2 as getContractAddresses, getNetworkInfo, initChaosChainSDK, rangeFit, validateEvidenceGraph, verifyWorkEvidence };
|
|
16981
|
+
export { A2AX402Extension, AgentRegistrationError, AgentRole, AutoStorageManager, CHAOS_CORE_ABI, ChaosAgent, ChaosChainSDK, ChaosChainSDKError, ConfigurationError, ContractError, ERC8004_VERSION, GatewayClient, GatewayConnectionError, GatewayError, GatewayTimeoutError, GoogleAP2Integration, IDENTITY_REGISTRY_ABI, IPFSLocalStorage, PinataStorage as IPFSPinataStorage, IntegrityVerificationError, IrysStorage, IrysStorage as IrysStorageProvider, LocalIPFSStorage, MandateManager, NetworkConfig, PaymentError, PaymentManager, PaymentMethod, PinataStorage, REPUTATION_REGISTRY_ABI, REWARDS_DISTRIBUTOR_ABI, ValidationError as SDKValidationError, SDK_VERSION, STUDIO_FACTORY_ABI, STUDIO_PROXY_ABI, Session, SessionClient, StorageError, StudioClient, StudioManager, VALIDATION_REGISTRY_ABI, ValidationStatus, WalletManager, WorkflowFailedError, WorkflowState, WorkflowType, X402PaymentManager, X402Server, X402_VERSION, ZeroGStorage, composeScoreVector, composeScoreVectorWithDefaults, computeDepth, src_default as default, derivePoAScores, extractAgencySignals, getContractAddresses2 as getContractAddresses, getNetworkInfo, initChaosChainSDK, rangeFit, validateEvidenceGraph, verifyWorkEvidence };
|
|
16766
16982
|
//# sourceMappingURL=index.js.map
|
|
16767
16983
|
//# sourceMappingURL=index.js.map
|