@tenova/swt3-ai 0.5.6 → 0.5.7
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/README.md +41 -15
- package/dist/adapters/cohere.d.ts +28 -0
- package/dist/adapters/cohere.d.ts.map +1 -0
- package/dist/adapters/cohere.js +292 -0
- package/dist/adapters/cohere.js.map +1 -0
- package/dist/adapters/ollama.d.ts +20 -0
- package/dist/adapters/ollama.d.ts.map +1 -1
- package/dist/adapters/ollama.js +22 -0
- package/dist/adapters/ollama.js.map +1 -1
- package/dist/adapters/qdrant.d.ts +28 -0
- package/dist/adapters/qdrant.d.ts.map +1 -0
- package/dist/adapters/qdrant.js +136 -0
- package/dist/adapters/qdrant.js.map +1 -0
- package/dist/procedures.d.ts +1 -1
- package/dist/procedures.d.ts.map +1 -1
- package/dist/procedures.js +6 -1
- package/dist/procedures.js.map +1 -1
- package/dist/types.d.ts +1 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +5 -1
- package/dist/types.js.map +1 -1
- package/dist/witness.d.ts +48 -0
- package/dist/witness.d.ts.map +1 -1
- package/dist/witness.js +151 -0
- package/dist/witness.js.map +1 -1
- package/package.json +2 -2
- package/templates/multi-silicon.yaml +48 -0
package/dist/witness.js
CHANGED
|
@@ -3172,6 +3172,157 @@ export class Witness {
|
|
|
3172
3172
|
this.buffer.enqueueMany([payload]);
|
|
3173
3173
|
return payload;
|
|
3174
3174
|
}
|
|
3175
|
+
// ── Agent Transaction Witnessing (AI-FIN.1) ─────────────────────
|
|
3176
|
+
/**
|
|
3177
|
+
* Witness an agent-initiated financial transaction (AI-FIN.1).
|
|
3178
|
+
* Factors: fa=authorization_type code, fb=amount_cents, fc=status code.
|
|
3179
|
+
*/
|
|
3180
|
+
witnessTransaction(options) {
|
|
3181
|
+
const authCodes = { none: 0, pre_approved: 1, human: 2, policy: 3, budget_limit: 4 };
|
|
3182
|
+
const statusCodes = { pending: 0, authorized: 1, denied: 2, escalated: 3 };
|
|
3183
|
+
const fa = authCodes[options.authorizationType] ?? 0;
|
|
3184
|
+
const fb = options.amountCents;
|
|
3185
|
+
const fc = statusCodes[options.status] ?? 0;
|
|
3186
|
+
const [ts, epoch] = timestampMs();
|
|
3187
|
+
const fp = mintFingerprint(this.config.tenantId, "AI-FIN.1", fa, fb, fc, ts);
|
|
3188
|
+
const payload = {
|
|
3189
|
+
procedure_id: "AI-FIN.1", factor_a: fa, factor_b: fb, factor_c: fc,
|
|
3190
|
+
clearing_level: this.config.clearingLevel,
|
|
3191
|
+
anchor_fingerprint: fp, anchor_epoch: epoch, fingerprint_timestamp_ms: ts,
|
|
3192
|
+
};
|
|
3193
|
+
if (this.config.clearingLevel <= 1) {
|
|
3194
|
+
payload.ai_model_id = `transaction-${options.authorizationType}`;
|
|
3195
|
+
const ctx = {
|
|
3196
|
+
provider: "transaction-witness",
|
|
3197
|
+
authorization_type: options.authorizationType,
|
|
3198
|
+
status: options.status,
|
|
3199
|
+
};
|
|
3200
|
+
if (options.currency)
|
|
3201
|
+
ctx.currency = options.currency;
|
|
3202
|
+
if (options.recipientHash)
|
|
3203
|
+
ctx.recipient_hash = options.recipientHash;
|
|
3204
|
+
if (options.purpose)
|
|
3205
|
+
ctx.purpose = options.purpose;
|
|
3206
|
+
if (options.transactionRef)
|
|
3207
|
+
ctx.transaction_ref = options.transactionRef;
|
|
3208
|
+
payload.ai_context = ctx;
|
|
3209
|
+
}
|
|
3210
|
+
this.buffer.enqueueMany([payload]);
|
|
3211
|
+
return payload;
|
|
3212
|
+
}
|
|
3213
|
+
// ── Tool Permission Attestation (AI-TOOL.2) ────────────────────
|
|
3214
|
+
/**
|
|
3215
|
+
* Witness tool permission grants and changes (AI-TOOL.2).
|
|
3216
|
+
* Factors: fa=granted_tool_count, fb=charter_match (1/0), fc=permission_change_type code.
|
|
3217
|
+
*/
|
|
3218
|
+
witnessToolPermissions(options) {
|
|
3219
|
+
const changeCodes = { none: 0, added: 1, removed: 2, escalated: 3 };
|
|
3220
|
+
const fa = options.tools.length;
|
|
3221
|
+
const fb = options.charterMatch ? 1 : 0;
|
|
3222
|
+
const fc = changeCodes[options.changeType ?? "initial"] ?? 0;
|
|
3223
|
+
const [ts, epoch] = timestampMs();
|
|
3224
|
+
const fp = mintFingerprint(this.config.tenantId, "AI-TOOL.2", fa, fb, fc, ts);
|
|
3225
|
+
const payload = {
|
|
3226
|
+
procedure_id: "AI-TOOL.2", factor_a: fa, factor_b: fb, factor_c: fc,
|
|
3227
|
+
clearing_level: this.config.clearingLevel,
|
|
3228
|
+
anchor_fingerprint: fp, anchor_epoch: epoch, fingerprint_timestamp_ms: ts,
|
|
3229
|
+
};
|
|
3230
|
+
if (this.config.clearingLevel <= 1) {
|
|
3231
|
+
payload.ai_model_id = `tool-permissions-${options.changeType ?? "initial"}`;
|
|
3232
|
+
const ctx = {
|
|
3233
|
+
provider: "tool-permission-witness",
|
|
3234
|
+
tools: options.tools,
|
|
3235
|
+
charter_match: options.charterMatch,
|
|
3236
|
+
change_type: options.changeType ?? "initial",
|
|
3237
|
+
};
|
|
3238
|
+
if (options.charterHash)
|
|
3239
|
+
ctx.charter_hash = options.charterHash;
|
|
3240
|
+
if (options.driftDetails)
|
|
3241
|
+
ctx.drift_details = options.driftDetails;
|
|
3242
|
+
payload.ai_context = ctx;
|
|
3243
|
+
}
|
|
3244
|
+
this.buffer.enqueueMany([payload]);
|
|
3245
|
+
return payload;
|
|
3246
|
+
}
|
|
3247
|
+
// ── Agent Lifecycle Witnessing (AI-LCM.1) ──────────────────────
|
|
3248
|
+
/**
|
|
3249
|
+
* Witness agent lifecycle events (AI-LCM.1).
|
|
3250
|
+
* Factors: fa=event_type code, fb=context_tokens, fc=state_hash_present (1/0).
|
|
3251
|
+
*/
|
|
3252
|
+
witnessLifecycle(options) {
|
|
3253
|
+
const eventCodes = { spawn: 0, checkpoint: 1, migrate: 2, terminate: 3, crash: 4 };
|
|
3254
|
+
const fa = eventCodes[options.event] ?? 0;
|
|
3255
|
+
const fb = options.contextTokens ?? 0;
|
|
3256
|
+
const fc = options.stateHash ? 1 : 0;
|
|
3257
|
+
const [ts, epoch] = timestampMs();
|
|
3258
|
+
const fp = mintFingerprint(this.config.tenantId, "AI-LCM.1", fa, fb, fc, ts);
|
|
3259
|
+
const payload = {
|
|
3260
|
+
procedure_id: "AI-LCM.1", factor_a: fa, factor_b: fb, factor_c: fc,
|
|
3261
|
+
clearing_level: this.config.clearingLevel,
|
|
3262
|
+
anchor_fingerprint: fp, anchor_epoch: epoch, fingerprint_timestamp_ms: ts,
|
|
3263
|
+
};
|
|
3264
|
+
if (this.config.clearingLevel <= 1) {
|
|
3265
|
+
payload.ai_model_id = `lifecycle-${options.event}`;
|
|
3266
|
+
const ctx = {
|
|
3267
|
+
provider: "lifecycle-witness",
|
|
3268
|
+
event: options.event,
|
|
3269
|
+
};
|
|
3270
|
+
if (options.contextTokens !== undefined)
|
|
3271
|
+
ctx.context_tokens = options.contextTokens;
|
|
3272
|
+
if (options.stateHash)
|
|
3273
|
+
ctx.state_hash = options.stateHash;
|
|
3274
|
+
if (options.parentAgentId)
|
|
3275
|
+
ctx.parent_agent_id = options.parentAgentId;
|
|
3276
|
+
if (options.uptimeMs !== undefined)
|
|
3277
|
+
ctx.uptime_ms = options.uptimeMs;
|
|
3278
|
+
if (options.terminationReason)
|
|
3279
|
+
ctx.termination_reason = options.terminationReason;
|
|
3280
|
+
payload.ai_context = ctx;
|
|
3281
|
+
}
|
|
3282
|
+
this.buffer.enqueueMany([payload]);
|
|
3283
|
+
return payload;
|
|
3284
|
+
}
|
|
3285
|
+
// ── Cross-Border Inference Routing (AI-JUR.1) ──────────────────
|
|
3286
|
+
/**
|
|
3287
|
+
* Witness cross-border inference routing decisions (AI-JUR.1).
|
|
3288
|
+
* Factors: fa=serving_region ISO numeric, fb=user_region ISO numeric, fc=compliance_status code.
|
|
3289
|
+
*/
|
|
3290
|
+
witnessRouting(options) {
|
|
3291
|
+
const regionCodes = {
|
|
3292
|
+
US: 840, GB: 826, DE: 276, FR: 250, JP: 392, KR: 410, CN: 156,
|
|
3293
|
+
IN: 356, BR: 76, AU: 36, CA: 124, SG: 702, NL: 528, SE: 752, IE: 372,
|
|
3294
|
+
IL: 376, AE: 784, CH: 756, IT: 380, ES: 724,
|
|
3295
|
+
};
|
|
3296
|
+
const complianceCodes = { unchecked: 0, compliant: 1, blocked: 2, override: 3 };
|
|
3297
|
+
const fa = regionCodes[options.servingRegion] ?? 0;
|
|
3298
|
+
const fb = regionCodes[options.userRegion] ?? 0;
|
|
3299
|
+
const fc = complianceCodes[options.complianceStatus ?? "compliant"] ?? 0;
|
|
3300
|
+
const [ts, epoch] = timestampMs();
|
|
3301
|
+
const fp = mintFingerprint(this.config.tenantId, "AI-JUR.1", fa, fb, fc, ts);
|
|
3302
|
+
const payload = {
|
|
3303
|
+
procedure_id: "AI-JUR.1", factor_a: fa, factor_b: fb, factor_c: fc,
|
|
3304
|
+
clearing_level: this.config.clearingLevel,
|
|
3305
|
+
anchor_fingerprint: fp, anchor_epoch: epoch, fingerprint_timestamp_ms: ts,
|
|
3306
|
+
};
|
|
3307
|
+
if (this.config.clearingLevel <= 1) {
|
|
3308
|
+
payload.ai_model_id = `routing-${options.servingRegion}-${options.userRegion}`;
|
|
3309
|
+
const ctx = {
|
|
3310
|
+
provider: "routing-witness",
|
|
3311
|
+
serving_region: options.servingRegion,
|
|
3312
|
+
user_region: options.userRegion,
|
|
3313
|
+
compliance_status: options.complianceStatus ?? "compliant",
|
|
3314
|
+
};
|
|
3315
|
+
if (options.routingDecision)
|
|
3316
|
+
ctx.routing_decision = options.routingDecision;
|
|
3317
|
+
if (options.applicableFrameworks)
|
|
3318
|
+
ctx.applicable_frameworks = options.applicableFrameworks;
|
|
3319
|
+
if (options.dataResidencyRequired !== undefined)
|
|
3320
|
+
ctx.data_residency_required = options.dataResidencyRequired;
|
|
3321
|
+
payload.ai_context = ctx;
|
|
3322
|
+
}
|
|
3323
|
+
this.buffer.enqueueMany([payload]);
|
|
3324
|
+
return payload;
|
|
3325
|
+
}
|
|
3175
3326
|
// ── Trust Mesh (AI-TRUST.1 / AI-TRUST.2) ────────────────────────
|
|
3176
3327
|
_trustRegistry;
|
|
3177
3328
|
_witnessedProcedures = new Set();
|