aira-sdk 0.1.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/README.md +306 -101
- package/dist/client.d.ts +41 -0
- package/dist/client.js +103 -0
- package/dist/extras/index.d.ts +21 -0
- package/dist/extras/index.js +31 -0
- package/dist/extras/langchain.d.ts +42 -0
- package/dist/extras/langchain.js +95 -0
- package/dist/extras/mcp.d.ts +49 -0
- package/dist/extras/mcp.js +163 -0
- package/dist/extras/openai-agents.d.ts +38 -0
- package/dist/extras/openai-agents.js +82 -0
- package/dist/extras/trust.d.ts +33 -0
- package/dist/extras/trust.js +77 -0
- package/dist/extras/vercel-ai.d.ts +48 -0
- package/dist/extras/vercel-ai.js +102 -0
- package/dist/extras/webhooks.d.ts +34 -0
- package/dist/extras/webhooks.js +59 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +5 -1
- package/dist/offline.d.ts +16 -0
- package/dist/offline.js +27 -0
- package/dist/session.d.ts +20 -0
- package/dist/session.js +24 -0
- package/package.json +57 -2
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Trust layer types and helpers shared across all framework integrations.
|
|
3
|
+
*/
|
|
4
|
+
import type { Aira } from "../client";
|
|
5
|
+
/** Policy for automated trust checks before tool execution. */
|
|
6
|
+
export interface TrustPolicy {
|
|
7
|
+
verifyCounterparty?: boolean;
|
|
8
|
+
minReputation?: number;
|
|
9
|
+
requireValidVc?: boolean;
|
|
10
|
+
blockRevokedVc?: boolean;
|
|
11
|
+
blockUnregistered?: boolean;
|
|
12
|
+
}
|
|
13
|
+
/** Result of a trust check against a counterparty agent. */
|
|
14
|
+
export interface TrustContext {
|
|
15
|
+
counterpartyId?: string;
|
|
16
|
+
didResolved?: boolean;
|
|
17
|
+
did?: string;
|
|
18
|
+
vcValid?: boolean | null;
|
|
19
|
+
reputationScore?: number | null;
|
|
20
|
+
reputationTier?: string | null;
|
|
21
|
+
reputationWarning?: string;
|
|
22
|
+
blocked?: boolean;
|
|
23
|
+
blockReason?: string;
|
|
24
|
+
recommendation?: string;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Run a trust check against a counterparty agent.
|
|
28
|
+
*
|
|
29
|
+
* Advisory by default — populates TrustContext with warnings.
|
|
30
|
+
* Only blocks when `blockRevokedVc` is set and the VC is revoked,
|
|
31
|
+
* or when `blockUnregistered` is set and the DID cannot be resolved.
|
|
32
|
+
*/
|
|
33
|
+
export declare function checkTrust(client: Aira, policy: TrustPolicy, counterpartyId: string): Promise<TrustContext>;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Trust layer types and helpers shared across all framework integrations.
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.checkTrust = checkTrust;
|
|
7
|
+
/**
|
|
8
|
+
* Run a trust check against a counterparty agent.
|
|
9
|
+
*
|
|
10
|
+
* Advisory by default — populates TrustContext with warnings.
|
|
11
|
+
* Only blocks when `blockRevokedVc` is set and the VC is revoked,
|
|
12
|
+
* or when `blockUnregistered` is set and the DID cannot be resolved.
|
|
13
|
+
*/
|
|
14
|
+
async function checkTrust(client, policy, counterpartyId) {
|
|
15
|
+
const ctx = {
|
|
16
|
+
counterpartyId,
|
|
17
|
+
blocked: false,
|
|
18
|
+
};
|
|
19
|
+
// Step 1: Resolve DID
|
|
20
|
+
if (policy.verifyCounterparty || policy.requireValidVc || policy.blockUnregistered) {
|
|
21
|
+
try {
|
|
22
|
+
const didResult = await client.resolveDid(`did:web:airaproof.com:agents:${counterpartyId}`);
|
|
23
|
+
ctx.didResolved = true;
|
|
24
|
+
ctx.did = didResult.did;
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
ctx.didResolved = false;
|
|
28
|
+
if (policy.blockUnregistered) {
|
|
29
|
+
ctx.blocked = true;
|
|
30
|
+
ctx.blockReason = `Agent '${counterpartyId}' DID could not be resolved`;
|
|
31
|
+
return ctx;
|
|
32
|
+
}
|
|
33
|
+
ctx.recommendation = `Could not resolve DID for '${counterpartyId}' — proceed with caution`;
|
|
34
|
+
return ctx;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
// Step 2: Verify credential
|
|
38
|
+
if (policy.requireValidVc || policy.blockRevokedVc) {
|
|
39
|
+
try {
|
|
40
|
+
const cred = await client.getAgentCredential(counterpartyId);
|
|
41
|
+
const verification = await client.verifyCredential(cred);
|
|
42
|
+
const valid = verification.valid;
|
|
43
|
+
ctx.vcValid = valid;
|
|
44
|
+
if (!valid && policy.blockRevokedVc) {
|
|
45
|
+
ctx.blocked = true;
|
|
46
|
+
ctx.blockReason = `Agent '${counterpartyId}' has a revoked or invalid credential`;
|
|
47
|
+
return ctx;
|
|
48
|
+
}
|
|
49
|
+
if (!valid) {
|
|
50
|
+
ctx.recommendation = `Credential for '${counterpartyId}' is invalid — proceed with caution`;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
catch {
|
|
54
|
+
ctx.vcValid = null;
|
|
55
|
+
if (policy.blockRevokedVc) {
|
|
56
|
+
ctx.recommendation = `Could not verify credential for '${counterpartyId}' — treating as unknown`;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
// Step 3: Check reputation
|
|
61
|
+
if (policy.minReputation != null) {
|
|
62
|
+
try {
|
|
63
|
+
const rep = await client.getReputation(counterpartyId);
|
|
64
|
+
ctx.reputationScore = rep.score;
|
|
65
|
+
ctx.reputationTier = rep.tier;
|
|
66
|
+
if (ctx.reputationScore != null && ctx.reputationScore < policy.minReputation) {
|
|
67
|
+
ctx.reputationWarning = `Reputation ${ctx.reputationScore} is below minimum ${policy.minReputation}`;
|
|
68
|
+
ctx.recommendation = ctx.reputationWarning;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
catch {
|
|
72
|
+
ctx.reputationScore = null;
|
|
73
|
+
ctx.reputationWarning = `Could not fetch reputation for '${counterpartyId}'`;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return ctx;
|
|
77
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vercel AI SDK integration — middleware that notarizes tool calls and completions.
|
|
3
|
+
*
|
|
4
|
+
* Requires: ai (Vercel AI SDK, peer dependency)
|
|
5
|
+
*
|
|
6
|
+
* Usage:
|
|
7
|
+
* import { AiraVercelMiddleware } from "aira-sdk/extras/vercel-ai";
|
|
8
|
+
* const middleware = new AiraVercelMiddleware(aira, "my-agent");
|
|
9
|
+
* // Use as wrap around tool calls or stream callbacks
|
|
10
|
+
*/
|
|
11
|
+
import type { Aira } from "../client";
|
|
12
|
+
import type { TrustPolicy, TrustContext } from "./trust";
|
|
13
|
+
export type { TrustPolicy, TrustContext } from "./trust";
|
|
14
|
+
export declare class AiraVercelMiddleware {
|
|
15
|
+
private client;
|
|
16
|
+
private agentId;
|
|
17
|
+
private modelId?;
|
|
18
|
+
private trustPolicy?;
|
|
19
|
+
constructor(client: Aira, agentId: string, options?: {
|
|
20
|
+
modelId?: string;
|
|
21
|
+
trustPolicy?: TrustPolicy;
|
|
22
|
+
});
|
|
23
|
+
/**
|
|
24
|
+
* Check trust for a counterparty agent before interacting.
|
|
25
|
+
* Advisory by default — only blocks on revoked VC or unregistered agent if configured.
|
|
26
|
+
*/
|
|
27
|
+
checkTrust(counterpartyId: string): Promise<TrustContext>;
|
|
28
|
+
private notarize;
|
|
29
|
+
/** Call after a tool execution to notarize it. */
|
|
30
|
+
onToolCall(toolName: string, argKeys?: string[]): void;
|
|
31
|
+
/** Call after a tool returns to notarize the result. */
|
|
32
|
+
onToolResult(toolName: string, resultLength: number): void;
|
|
33
|
+
/** Call when a text generation step completes. */
|
|
34
|
+
onStepFinish(stepType: string, tokenCount?: number): void;
|
|
35
|
+
/** Call when the full generation completes. */
|
|
36
|
+
onFinish(finishReason: string, totalTokens?: number): void;
|
|
37
|
+
/**
|
|
38
|
+
* Returns a Vercel AI SDK-compatible callbacks object for streamText/generateText.
|
|
39
|
+
*
|
|
40
|
+
* Usage:
|
|
41
|
+
* const result = await streamText({ ...opts, ...middleware.asCallbacks() });
|
|
42
|
+
*/
|
|
43
|
+
asCallbacks(): Record<string, (...args: unknown[]) => void>;
|
|
44
|
+
/**
|
|
45
|
+
* Wraps a tool's execute function to auto-notarize calls and results.
|
|
46
|
+
*/
|
|
47
|
+
wrapTool<T extends (...args: unknown[]) => unknown>(toolFn: T, toolName: string): T;
|
|
48
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Vercel AI SDK integration — middleware that notarizes tool calls and completions.
|
|
4
|
+
*
|
|
5
|
+
* Requires: ai (Vercel AI SDK, peer dependency)
|
|
6
|
+
*
|
|
7
|
+
* Usage:
|
|
8
|
+
* import { AiraVercelMiddleware } from "aira-sdk/extras/vercel-ai";
|
|
9
|
+
* const middleware = new AiraVercelMiddleware(aira, "my-agent");
|
|
10
|
+
* // Use as wrap around tool calls or stream callbacks
|
|
11
|
+
*/
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.AiraVercelMiddleware = void 0;
|
|
14
|
+
const trust_1 = require("./trust");
|
|
15
|
+
const MAX_DETAILS = 5000;
|
|
16
|
+
class AiraVercelMiddleware {
|
|
17
|
+
client;
|
|
18
|
+
agentId;
|
|
19
|
+
modelId;
|
|
20
|
+
trustPolicy;
|
|
21
|
+
constructor(client, agentId, options) {
|
|
22
|
+
this.client = client;
|
|
23
|
+
this.agentId = agentId;
|
|
24
|
+
this.modelId = options?.modelId;
|
|
25
|
+
this.trustPolicy = options?.trustPolicy;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Check trust for a counterparty agent before interacting.
|
|
29
|
+
* Advisory by default — only blocks on revoked VC or unregistered agent if configured.
|
|
30
|
+
*/
|
|
31
|
+
async checkTrust(counterpartyId) {
|
|
32
|
+
if (!this.trustPolicy) {
|
|
33
|
+
return { counterpartyId, blocked: false, recommendation: "No trust policy configured" };
|
|
34
|
+
}
|
|
35
|
+
return (0, trust_1.checkTrust)(this.client, this.trustPolicy, counterpartyId);
|
|
36
|
+
}
|
|
37
|
+
notarize(actionType, details) {
|
|
38
|
+
try {
|
|
39
|
+
const params = {
|
|
40
|
+
actionType,
|
|
41
|
+
details: details.slice(0, MAX_DETAILS),
|
|
42
|
+
agentId: this.agentId,
|
|
43
|
+
};
|
|
44
|
+
if (this.modelId)
|
|
45
|
+
params.modelId = this.modelId;
|
|
46
|
+
this.client.notarize(params).catch((e) => {
|
|
47
|
+
console.warn("Aira notarize failed (non-blocking):", e);
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
catch (e) {
|
|
51
|
+
console.warn("Aira notarize failed (non-blocking):", e);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
/** Call after a tool execution to notarize it. */
|
|
55
|
+
onToolCall(toolName, argKeys = []) {
|
|
56
|
+
this.notarize("tool_call", `Tool '${toolName}' called. Arg keys: [${argKeys.join(", ")}]`);
|
|
57
|
+
}
|
|
58
|
+
/** Call after a tool returns to notarize the result. */
|
|
59
|
+
onToolResult(toolName, resultLength) {
|
|
60
|
+
this.notarize("tool_completed", `Tool '${toolName}' completed. Result length: ${resultLength} chars`);
|
|
61
|
+
}
|
|
62
|
+
/** Call when a text generation step completes. */
|
|
63
|
+
onStepFinish(stepType, tokenCount) {
|
|
64
|
+
this.notarize("step_completed", `Step '${stepType}' completed.${tokenCount != null ? ` Tokens: ${tokenCount}` : ""}`);
|
|
65
|
+
}
|
|
66
|
+
/** Call when the full generation completes. */
|
|
67
|
+
onFinish(finishReason, totalTokens) {
|
|
68
|
+
this.notarize("generation_completed", `Generation completed. Reason: ${finishReason}.${totalTokens != null ? ` Total tokens: ${totalTokens}` : ""}`);
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Returns a Vercel AI SDK-compatible callbacks object for streamText/generateText.
|
|
72
|
+
*
|
|
73
|
+
* Usage:
|
|
74
|
+
* const result = await streamText({ ...opts, ...middleware.asCallbacks() });
|
|
75
|
+
*/
|
|
76
|
+
asCallbacks() {
|
|
77
|
+
return {
|
|
78
|
+
onStepFinish: (step) => {
|
|
79
|
+
const s = step;
|
|
80
|
+
this.onStepFinish(s?.stepType ?? "unknown", s?.usage?.totalTokens);
|
|
81
|
+
},
|
|
82
|
+
onFinish: (result) => {
|
|
83
|
+
const r = result;
|
|
84
|
+
this.onFinish(r?.finishReason ?? "unknown", r?.usage?.totalTokens);
|
|
85
|
+
},
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Wraps a tool's execute function to auto-notarize calls and results.
|
|
90
|
+
*/
|
|
91
|
+
wrapTool(toolFn, toolName) {
|
|
92
|
+
const self = this;
|
|
93
|
+
const wrapped = async function (...args) {
|
|
94
|
+
self.onToolCall(toolName, args.length > 0 && typeof args[0] === "object" && args[0] ? Object.keys(args[0]) : []);
|
|
95
|
+
const result = await toolFn.apply(this, args);
|
|
96
|
+
self.onToolResult(toolName, String(result).length);
|
|
97
|
+
return result;
|
|
98
|
+
};
|
|
99
|
+
return wrapped;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
exports.AiraVercelMiddleware = AiraVercelMiddleware;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Webhook signature verification and event parsing for Aira webhooks.
|
|
3
|
+
*/
|
|
4
|
+
/** Known Aira webhook event types. */
|
|
5
|
+
export declare const WebhookEventType: {
|
|
6
|
+
readonly CASE_COMPLETE: "case.complete";
|
|
7
|
+
readonly CASE_REQUIRES_REVIEW: "case.requires_human_review";
|
|
8
|
+
readonly ACTION_NOTARIZED: "action.notarized";
|
|
9
|
+
readonly ACTION_AUTHORIZED: "action.authorized";
|
|
10
|
+
readonly AGENT_REGISTERED: "agent.registered";
|
|
11
|
+
readonly AGENT_DECOMMISSIONED: "agent.decommissioned";
|
|
12
|
+
readonly EVIDENCE_SEALED: "evidence.sealed";
|
|
13
|
+
readonly ESCROW_DEPOSITED: "escrow.deposited";
|
|
14
|
+
readonly ESCROW_RELEASED: "escrow.released";
|
|
15
|
+
readonly ESCROW_DISPUTED: "escrow.disputed";
|
|
16
|
+
readonly COMPLIANCE_SNAPSHOT: "compliance.snapshot_created";
|
|
17
|
+
};
|
|
18
|
+
export type WebhookEventTypeName = (typeof WebhookEventType)[keyof typeof WebhookEventType];
|
|
19
|
+
/** Parsed webhook event. */
|
|
20
|
+
export interface WebhookEvent {
|
|
21
|
+
eventType: string;
|
|
22
|
+
data: Record<string, unknown>;
|
|
23
|
+
timestamp?: string;
|
|
24
|
+
deliveryId?: string;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Verify webhook signature.
|
|
28
|
+
* Signature format: sha256={hex_digest}
|
|
29
|
+
*/
|
|
30
|
+
export declare function verifySignature(payload: Buffer | string, signature: string, secret: string): boolean;
|
|
31
|
+
/**
|
|
32
|
+
* Parse raw webhook payload into a WebhookEvent.
|
|
33
|
+
*/
|
|
34
|
+
export declare function parseEvent(payload: Buffer | string): WebhookEvent;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Webhook signature verification and event parsing for Aira webhooks.
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.WebhookEventType = void 0;
|
|
7
|
+
exports.verifySignature = verifySignature;
|
|
8
|
+
exports.parseEvent = parseEvent;
|
|
9
|
+
const crypto_1 = require("crypto");
|
|
10
|
+
/** Known Aira webhook event types. */
|
|
11
|
+
exports.WebhookEventType = {
|
|
12
|
+
CASE_COMPLETE: "case.complete",
|
|
13
|
+
CASE_REQUIRES_REVIEW: "case.requires_human_review",
|
|
14
|
+
ACTION_NOTARIZED: "action.notarized",
|
|
15
|
+
ACTION_AUTHORIZED: "action.authorized",
|
|
16
|
+
AGENT_REGISTERED: "agent.registered",
|
|
17
|
+
AGENT_DECOMMISSIONED: "agent.decommissioned",
|
|
18
|
+
EVIDENCE_SEALED: "evidence.sealed",
|
|
19
|
+
ESCROW_DEPOSITED: "escrow.deposited",
|
|
20
|
+
ESCROW_RELEASED: "escrow.released",
|
|
21
|
+
ESCROW_DISPUTED: "escrow.disputed",
|
|
22
|
+
COMPLIANCE_SNAPSHOT: "compliance.snapshot_created",
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Verify webhook signature.
|
|
26
|
+
* Signature format: sha256={hex_digest}
|
|
27
|
+
*/
|
|
28
|
+
function verifySignature(payload, signature, secret) {
|
|
29
|
+
if (!signature.startsWith("sha256="))
|
|
30
|
+
return false;
|
|
31
|
+
const payloadBuf = typeof payload === "string" ? Buffer.from(payload, "utf-8") : payload;
|
|
32
|
+
const expected = (0, crypto_1.createHmac)("sha256", secret).update(payloadBuf).digest("hex");
|
|
33
|
+
const expectedSig = `sha256=${expected}`;
|
|
34
|
+
// Constant-time comparison
|
|
35
|
+
try {
|
|
36
|
+
return (0, crypto_1.timingSafeEqual)(Buffer.from(signature, "utf-8"), Buffer.from(expectedSig, "utf-8"));
|
|
37
|
+
}
|
|
38
|
+
catch {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Parse raw webhook payload into a WebhookEvent.
|
|
44
|
+
*/
|
|
45
|
+
function parseEvent(payload) {
|
|
46
|
+
let data;
|
|
47
|
+
try {
|
|
48
|
+
data = JSON.parse(typeof payload === "string" ? payload : payload.toString("utf-8"));
|
|
49
|
+
}
|
|
50
|
+
catch (e) {
|
|
51
|
+
throw new Error(`Invalid webhook payload: ${e}`);
|
|
52
|
+
}
|
|
53
|
+
return {
|
|
54
|
+
eventType: data.event ?? "unknown",
|
|
55
|
+
data: data.data ?? data,
|
|
56
|
+
timestamp: data.timestamp,
|
|
57
|
+
deliveryId: data.delivery_id,
|
|
58
|
+
};
|
|
59
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
1
|
export { Aira } from "./client";
|
|
2
2
|
export type { AiraOptions } from "./client";
|
|
3
|
+
export { AiraSession } from "./session";
|
|
4
|
+
export { OfflineQueue } from "./offline";
|
|
5
|
+
export type { QueuedRequest } from "./offline";
|
|
3
6
|
export { AiraError, type ActionReceipt, type ActionDetail, type AgentDetail, type AgentVersion, type EvidencePackage, type ComplianceSnapshot, type EscrowAccount, type EscrowTransaction, type VerifyResult, type PaginatedList, } from "./types";
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AiraError = exports.Aira = void 0;
|
|
3
|
+
exports.AiraError = exports.OfflineQueue = exports.AiraSession = exports.Aira = void 0;
|
|
4
4
|
var client_1 = require("./client");
|
|
5
5
|
Object.defineProperty(exports, "Aira", { enumerable: true, get: function () { return client_1.Aira; } });
|
|
6
|
+
var session_1 = require("./session");
|
|
7
|
+
Object.defineProperty(exports, "AiraSession", { enumerable: true, get: function () { return session_1.AiraSession; } });
|
|
8
|
+
var offline_1 = require("./offline");
|
|
9
|
+
Object.defineProperty(exports, "OfflineQueue", { enumerable: true, get: function () { return offline_1.OfflineQueue; } });
|
|
6
10
|
var types_1 = require("./types");
|
|
7
11
|
Object.defineProperty(exports, "AiraError", { enumerable: true, get: function () { return types_1.AiraError; } });
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Offline queue for Aira SDK — queues actions locally, syncs later.
|
|
3
|
+
*/
|
|
4
|
+
export interface QueuedRequest {
|
|
5
|
+
id: string;
|
|
6
|
+
method: string;
|
|
7
|
+
path: string;
|
|
8
|
+
body: Record<string, unknown>;
|
|
9
|
+
}
|
|
10
|
+
export declare class OfflineQueue {
|
|
11
|
+
private items;
|
|
12
|
+
enqueue(method: string, path: string, body: Record<string, unknown>): string;
|
|
13
|
+
get pendingCount(): number;
|
|
14
|
+
clear(): void;
|
|
15
|
+
drain(): QueuedRequest[];
|
|
16
|
+
}
|
package/dist/offline.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Offline queue for Aira SDK — queues actions locally, syncs later.
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.OfflineQueue = void 0;
|
|
7
|
+
const crypto_1 = require("crypto");
|
|
8
|
+
class OfflineQueue {
|
|
9
|
+
items = [];
|
|
10
|
+
enqueue(method, path, body) {
|
|
11
|
+
const id = `offline_${(0, crypto_1.randomUUID)().replace(/-/g, "").slice(0, 12)}`;
|
|
12
|
+
this.items.push({ id, method, path, body });
|
|
13
|
+
return id;
|
|
14
|
+
}
|
|
15
|
+
get pendingCount() {
|
|
16
|
+
return this.items.length;
|
|
17
|
+
}
|
|
18
|
+
clear() {
|
|
19
|
+
this.items = [];
|
|
20
|
+
}
|
|
21
|
+
drain() {
|
|
22
|
+
const drained = [...this.items];
|
|
23
|
+
this.items = [];
|
|
24
|
+
return drained;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
exports.OfflineQueue = OfflineQueue;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AiraSession — scoped session with pre-filled defaults.
|
|
3
|
+
*/
|
|
4
|
+
import type { Aira } from "./client";
|
|
5
|
+
import type { ActionReceipt } from "./types";
|
|
6
|
+
export declare class AiraSession {
|
|
7
|
+
private client;
|
|
8
|
+
private defaults;
|
|
9
|
+
constructor(client: Aira, agentId: string, defaults?: Record<string, unknown>);
|
|
10
|
+
notarize(params: {
|
|
11
|
+
actionType: string;
|
|
12
|
+
details: string;
|
|
13
|
+
modelId?: string;
|
|
14
|
+
modelVersion?: string;
|
|
15
|
+
instructionHash?: string;
|
|
16
|
+
parentActionId?: string;
|
|
17
|
+
storeDetails?: boolean;
|
|
18
|
+
idempotencyKey?: string;
|
|
19
|
+
}): Promise<ActionReceipt>;
|
|
20
|
+
}
|
package/dist/session.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* AiraSession — scoped session with pre-filled defaults.
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.AiraSession = void 0;
|
|
7
|
+
class AiraSession {
|
|
8
|
+
client;
|
|
9
|
+
defaults;
|
|
10
|
+
constructor(client, agentId, defaults) {
|
|
11
|
+
this.client = client;
|
|
12
|
+
this.defaults = { agentId, ...(defaults ?? {}) };
|
|
13
|
+
}
|
|
14
|
+
async notarize(params) {
|
|
15
|
+
const merged = {
|
|
16
|
+
agentId: this.defaults.agentId,
|
|
17
|
+
...(this.defaults.modelId ? { modelId: this.defaults.modelId } : {}),
|
|
18
|
+
...(this.defaults.agentVersion ? { agentVersion: this.defaults.agentVersion } : {}),
|
|
19
|
+
...params,
|
|
20
|
+
};
|
|
21
|
+
return this.client.notarize(merged);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
exports.AiraSession = AiraSession;
|
package/package.json
CHANGED
|
@@ -1,9 +1,39 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "aira-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "TypeScript SDK for Aira — legal infrastructure for AI agents",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"default": "./dist/index.js"
|
|
11
|
+
},
|
|
12
|
+
"./extras/langchain": {
|
|
13
|
+
"types": "./dist/extras/langchain.d.ts",
|
|
14
|
+
"default": "./dist/extras/langchain.js"
|
|
15
|
+
},
|
|
16
|
+
"./extras/vercel-ai": {
|
|
17
|
+
"types": "./dist/extras/vercel-ai.d.ts",
|
|
18
|
+
"default": "./dist/extras/vercel-ai.js"
|
|
19
|
+
},
|
|
20
|
+
"./extras/openai-agents": {
|
|
21
|
+
"types": "./dist/extras/openai-agents.d.ts",
|
|
22
|
+
"default": "./dist/extras/openai-agents.js"
|
|
23
|
+
},
|
|
24
|
+
"./extras/mcp": {
|
|
25
|
+
"types": "./dist/extras/mcp.d.ts",
|
|
26
|
+
"default": "./dist/extras/mcp.js"
|
|
27
|
+
},
|
|
28
|
+
"./extras/webhooks": {
|
|
29
|
+
"types": "./dist/extras/webhooks.d.ts",
|
|
30
|
+
"default": "./dist/extras/webhooks.js"
|
|
31
|
+
},
|
|
32
|
+
"./extras": {
|
|
33
|
+
"types": "./dist/extras/index.d.ts",
|
|
34
|
+
"default": "./dist/extras/index.js"
|
|
35
|
+
}
|
|
36
|
+
},
|
|
7
37
|
"files": [
|
|
8
38
|
"dist"
|
|
9
39
|
],
|
|
@@ -21,7 +51,11 @@
|
|
|
21
51
|
"notarization",
|
|
22
52
|
"compliance",
|
|
23
53
|
"eu-ai-act",
|
|
24
|
-
"cryptographic-receipts"
|
|
54
|
+
"cryptographic-receipts",
|
|
55
|
+
"langchain",
|
|
56
|
+
"vercel-ai",
|
|
57
|
+
"openai",
|
|
58
|
+
"mcp"
|
|
25
59
|
],
|
|
26
60
|
"scripts": {
|
|
27
61
|
"build": "tsc",
|
|
@@ -30,9 +64,30 @@
|
|
|
30
64
|
},
|
|
31
65
|
"devDependencies": {
|
|
32
66
|
"@types/node": "^25.5.0",
|
|
67
|
+
"@vitest/coverage-v8": "^2.0.0",
|
|
33
68
|
"typescript": "^5.4.0",
|
|
34
69
|
"vitest": "^2.0.0"
|
|
35
70
|
},
|
|
71
|
+
"peerDependencies": {
|
|
72
|
+
"@langchain/core": ">=0.2.0",
|
|
73
|
+
"@modelcontextprotocol/sdk": ">=1.0.0",
|
|
74
|
+
"ai": ">=3.0.0",
|
|
75
|
+
"openai": ">=4.0.0"
|
|
76
|
+
},
|
|
77
|
+
"peerDependenciesMeta": {
|
|
78
|
+
"@langchain/core": {
|
|
79
|
+
"optional": true
|
|
80
|
+
},
|
|
81
|
+
"ai": {
|
|
82
|
+
"optional": true
|
|
83
|
+
},
|
|
84
|
+
"openai": {
|
|
85
|
+
"optional": true
|
|
86
|
+
},
|
|
87
|
+
"@modelcontextprotocol/sdk": {
|
|
88
|
+
"optional": true
|
|
89
|
+
}
|
|
90
|
+
},
|
|
36
91
|
"engines": {
|
|
37
92
|
"node": ">=18"
|
|
38
93
|
}
|