@niadra/sdk 0.1.0 → 0.7.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 +161 -20
- package/README.md +484 -38
- package/dist/ai-sdk.cjs +1037 -0
- package/dist/ai-sdk.cjs.map +1 -0
- package/dist/ai-sdk.d.cts +118 -0
- package/dist/ai-sdk.d.ts +118 -0
- package/dist/ai-sdk.js +1030 -0
- package/dist/ai-sdk.js.map +1 -0
- package/dist/anthropic.cjs +528 -0
- package/dist/anthropic.cjs.map +1 -0
- package/dist/anthropic.d.cts +35 -0
- package/dist/anthropic.d.ts +35 -0
- package/dist/anthropic.js +523 -0
- package/dist/anthropic.js.map +1 -0
- package/dist/bedrock.cjs +392 -0
- package/dist/bedrock.cjs.map +1 -0
- package/dist/bedrock.d.cts +25 -0
- package/dist/bedrock.d.ts +25 -0
- package/dist/bedrock.js +388 -0
- package/dist/bedrock.js.map +1 -0
- package/dist/cli.js +11045 -0
- package/dist/cli.js.map +1 -0
- package/dist/client-DsIxZxZk.d.cts +6905 -0
- package/dist/client-DsIxZxZk.d.ts +6905 -0
- package/dist/cloudflare-agents.cjs +626 -0
- package/dist/cloudflare-agents.cjs.map +1 -0
- package/dist/cloudflare-agents.d.cts +113 -0
- package/dist/cloudflare-agents.d.ts +113 -0
- package/dist/cloudflare-agents.js +622 -0
- package/dist/cloudflare-agents.js.map +1 -0
- package/dist/elevenlabs.cjs +738 -0
- package/dist/elevenlabs.cjs.map +1 -0
- package/dist/elevenlabs.d.cts +86 -0
- package/dist/elevenlabs.d.ts +86 -0
- package/dist/elevenlabs.js +733 -0
- package/dist/elevenlabs.js.map +1 -0
- package/dist/genkit.cjs +323 -0
- package/dist/genkit.cjs.map +1 -0
- package/dist/genkit.d.cts +67 -0
- package/dist/genkit.d.ts +67 -0
- package/dist/genkit.js +318 -0
- package/dist/genkit.js.map +1 -0
- package/dist/google-adk.cjs +705 -0
- package/dist/google-adk.cjs.map +1 -0
- package/dist/google-adk.d.cts +91 -0
- package/dist/google-adk.d.ts +91 -0
- package/dist/google-adk.js +701 -0
- package/dist/google-adk.js.map +1 -0
- package/dist/google-genai.cjs +422 -0
- package/dist/google-genai.cjs.map +1 -0
- package/dist/google-genai.d.cts +26 -0
- package/dist/google-genai.d.ts +26 -0
- package/dist/google-genai.js +418 -0
- package/dist/google-genai.js.map +1 -0
- package/dist/index.cjs +11449 -1796
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1006 -1247
- package/dist/index.d.ts +1006 -1247
- package/dist/index.js +11393 -1797
- package/dist/index.js.map +1 -1
- package/dist/intercept-0_lJE6k1.d.cts +20 -0
- package/dist/intercept-D7qFCaRb.d.ts +20 -0
- package/dist/langchain.cjs +1077 -0
- package/dist/langchain.cjs.map +1 -0
- package/dist/langchain.d.cts +102 -0
- package/dist/langchain.d.ts +102 -0
- package/dist/langchain.js +1068 -0
- package/dist/langchain.js.map +1 -0
- package/dist/livekit.cjs +404 -0
- package/dist/livekit.cjs.map +1 -0
- package/dist/livekit.d.cts +113 -0
- package/dist/livekit.d.ts +113 -0
- package/dist/livekit.js +398 -0
- package/dist/livekit.js.map +1 -0
- package/dist/llamaindex.cjs +349 -0
- package/dist/llamaindex.cjs.map +1 -0
- package/dist/llamaindex.d.cts +92 -0
- package/dist/llamaindex.d.ts +92 -0
- package/dist/llamaindex.js +344 -0
- package/dist/llamaindex.js.map +1 -0
- package/dist/mastra.cjs +1082 -0
- package/dist/mastra.cjs.map +1 -0
- package/dist/mastra.d.cts +86 -0
- package/dist/mastra.d.ts +86 -0
- package/dist/mastra.js +1075 -0
- package/dist/mastra.js.map +1 -0
- package/dist/openai-agents.cjs +465 -0
- package/dist/openai-agents.cjs.map +1 -0
- package/dist/openai-agents.d.cts +75 -0
- package/dist/openai-agents.d.ts +75 -0
- package/dist/openai-agents.js +459 -0
- package/dist/openai-agents.js.map +1 -0
- package/dist/retell.cjs +846 -0
- package/dist/retell.cjs.map +1 -0
- package/dist/retell.d.cts +161 -0
- package/dist/retell.d.ts +161 -0
- package/dist/retell.js +841 -0
- package/dist/retell.js.map +1 -0
- package/dist/shared-Bb5B59Bu.d.ts +39 -0
- package/dist/shared-DTPWVlWm.d.cts +39 -0
- package/dist/strands.cjs +352 -0
- package/dist/strands.cjs.map +1 -0
- package/dist/strands.d.cts +72 -0
- package/dist/strands.d.ts +72 -0
- package/dist/strands.js +347 -0
- package/dist/strands.js.map +1 -0
- package/dist/twilio.cjs +174 -0
- package/dist/twilio.cjs.map +1 -0
- package/dist/twilio.d.cts +64 -0
- package/dist/twilio.d.ts +64 -0
- package/dist/twilio.js +167 -0
- package/dist/twilio.js.map +1 -0
- package/dist/vapi.cjs +661 -0
- package/dist/vapi.cjs.map +1 -0
- package/dist/vapi.d.cts +78 -0
- package/dist/vapi.d.ts +78 -0
- package/dist/vapi.js +656 -0
- package/dist/vapi.js.map +1 -0
- package/dist/voltagent.cjs +509 -0
- package/dist/voltagent.cjs.map +1 -0
- package/dist/voltagent.d.cts +70 -0
- package/dist/voltagent.d.ts +70 -0
- package/dist/voltagent.js +503 -0
- package/dist/voltagent.js.map +1 -0
- package/dist/webhook-1ozGyksG.d.ts +37 -0
- package/dist/webhook-CG4om_DK.d.cts +37 -0
- package/dist/whatsapp.cjs +214 -0
- package/dist/whatsapp.cjs.map +1 -0
- package/dist/whatsapp.d.cts +81 -0
- package/dist/whatsapp.d.ts +81 -0
- package/dist/whatsapp.js +207 -0
- package/dist/whatsapp.js.map +1 -0
- package/package.json +355 -7
package/dist/index.d.cts
CHANGED
|
@@ -1,1326 +1,1047 @@
|
|
|
1
|
+
import { C as ConstraintsBlock, H as HardConstraint, N as NiadraError, a as ClaimRecord, b as ClaimCategory, I as InternalText, s as shingles, c as Niadra, R as Resolvers, d as ContextResponse, M as Mode, T as TurnPins, e as RawBinding, f as ContextResult, g as ModelUsage, L as Logger, S as SubjectKind, h as Handle, O as ObjectRef } from './client-DsIxZxZk.cjs';
|
|
2
|
+
export { A as AGENT_MEMORY_TOOL_DEFINITIONS, i as AGENT_MEMORY_TOOL_NAMES, j as ActionEvent, k as ActionInfo, l as Actions, m as Admin, n as AgentMemoryBlock, o as AgentMemoryParams, p as AgentMemoryResult, q as AgentMemorySearchRequest, r as AgentMemorySearchResponse, t as AgentMemorySource, u as AgentNote, v as AgentNoteKind, w as AgentNoteOrigin, x as AgentNoteProposal, y as AgentNoteStatus, z as AgentNoteVisibility, B as AgentSession, D as AgentState, E as AgentStateConflict, F as AgentStateHandle, G as AgentStateMeta, J as AgentStateMetaPage, K as AgentStateReadRequest, P as AgentStateScope, Q as AgentStateWrite, U as AgentStateWriteResult, V as AgentTurnOptions, W as AnchorEvidence, X as Api, Y as ArmComparison, Z as ArmOutcomes, _ as AskedAttribute, $ as AssertionMethod, a0 as AssertionOutcome, a1 as AssertionStats, a2 as Attribute, a3 as AttributeEntry, a4 as AttributionReport, a5 as AttributionRow, a6 as AttributionTotal, a7 as Backing, a8 as BackingReport, a9 as BackingSources, aa as BatchItem, ab as BatchRequest, ac as BatchResponse, ad as BiFile, ae as BiUpload, af as BiUploadRequest, ag as BlobError, ah as BlobStore, ai as BlockSubject, aj as BoundArg, ak as BoundTools, al as BudgetBlock, am as BudgetCut, an as BudgetPack, ao as BudgetUse, ap as CacheDirectives, aq as CacheOptions, ar as CallCapture, as as CaseClosed, at as CaseOpened, au as Change, av as ChangePage, aw as ChangeSinceSeen, ax as ChannelState, ay as CheckBatchRequest, az as CheckBatchResponse, aA as CheckOptions, aB as CheckRequest, aC as CheckResult, aD as ClaimCheck, aE as ClaimCheckOptions, aF as ClaimContractSummary, aG as ClaimEvidence, aH as ClaimEvidenceRef, aI as ClaimKind, aJ as ClaimOutputs, aK as ClaimParams, aL as ClaimRelease, aM as ClaimRequest, aN as ClaimValue, aO as ClaimVerdict, aP as ClaimVia, aQ as Claimed, aR as ClientOptions, aS as Closes, aT as Commitment, aU as CommitmentDecided, aV as CommitmentDecidedDetail, aW as CommitmentMade, aX as CommitmentMadeDetail, aY as CommitmentRef, aZ as CommitmentWithdrawn, a_ as CommitmentWithdrawnDetail, a$ as CompanyRule, b0 as Conflict, b1 as ConflictCounts, b2 as ConstraintOrigin, b3 as ConstraintsRequest, b4 as ContactBudget, b5 as ContactBudgetUse, b6 as ContactClaims, b7 as ContactCount, b8 as ContactGateway, b9 as ContactKey, ba as ContactKeys, bb as ContactMade, bc as ContactMadeDetail, bd as ContactTokenParams, be as ContactTokenRefusal, bf as Content, bg as ContentMarker, bh as ContentMode, bi as ContentRelease, bj as ContentReleaseResult, bk as ContentResolver, bl as ContextFormat, bm as ContextOptions, bn as ContextPack, bo as ContextParams, bp as ContextRequest, bq as ContextSource, br as ContextStamp, bs as ContextUseEntry, bt as Conversation, bu as ConversationAction, bv as ConversationEndedItem, bw as ConversationEvent, bx as ConversationParams, by as CoordinationBlock, bz as CoordinationOverview, bA as CoordinationReport, bB as CoordinationReportPage, bC as CorrectParams, bD as CorrectionAction, bE as CorrectionRequest, bF as CounterfactualCase, bG as CounterfactualEngaged, bH as CounterfactualEngagement, bI as CounterfactualRunCreate, bJ as CounterfactualRunPage, bK as CreateAgentNoteRequest, bL as DEFAULT_CACHE, bM as DEFAULT_QUEUE, bN as DEFAULT_TIMEOUTS, bO as DEFAULT_VOICE, bP as DELETE, bQ as DataIssue, bR as DataIssuePage, bS as Declarations, bT as DeclareRequest, bU as DeclareResult, bV as DeliveryPath, bW as Detect, bX as DriftChanges, bY as Effect, bZ as EffectCount, b_ as EffectDeclared, b$ as EffectDetail, c0 as EffectKind, c1 as EffectReserve, c2 as EffectSeen, c3 as EffectSettle, c4 as EffectState, c5 as EffectStatus, c6 as Engaged, c7 as EpisodeOut, c8 as Erasure, c9 as EventItem, ca as EventKind, cb as Evidence, cc as ExperimentReport, cd as ExperimentResult, ce as ExportPackage, cf as FAIL_CLOSED, cg as FactHistory, ch as FactOut, ci as Feature, cj as Feedback, ck as FeedbackAction, cl as FeedbackParams, cm as FeedbackRequest, cn as Fetched, co as FieldCoverage, cp as FieldState, cq as ForgetTarget, cr as GatewayOptions, cs as Guard, ct as GuardLike, cu as GuardOptions, cv as Guarded, cw as HandleType, cx as Handoff, cy as HandoffContext, cz as HandoffCreate, cA as HandoffDeclared, cB as HandoffDetail, cC as HandoffItem, cD as HandoffOutcome, cE as HandoffPackage, cF as HandoffParams, cG as HeartbeatItem, cH as HistoryFilters, cI as HistoryItem, cJ as HistoryItemKind, cK as IdentifyItem, cL as IdentifyParams, cM as IdentityCalibration, cN as Include, cO as Inference, cP as InferenceCorrection, cQ as InferencePage, cR as IngestStatus, cS as InterestState, cT as InterleavingReport, cU as InterleavingRow, cV as InterleavingTotal, cW as InternalText, cX as ItemError, cY as ItemVersion, cZ as KeyIdentity, c_ as LeaseDeclared, c$ as LeaseDetail, d0 as LegalHold, d1 as LegalHoldCreate, d2 as LegalHoldRelease, d3 as LiveTurn, d4 as Lock, d5 as MAX_BATCH_ITEMS, d6 as MAX_EVENT_TEXT, d7 as MAX_MEDIA_BYTES, d8 as MediaUpload, d9 as MediaUploadRequest, da as MediaUploadResponse, db as MemorySeen, dc as NOT_FOUND, dd as Natures, de as Negation, df as NiadraAPIError, dg as NiadraAbortError, dh as NiadraAuthenticationError, di as NiadraConfigError, dj as NiadraConnectionError, dk as NiadraContactTokenError, dl as NiadraPermissionError, dm as NiadraRateLimitError, dn as NiadraReplayRefusedError, dp as NiadraTimeoutError, dq as NiadraValidationError, dr as Notification, ds as NotificationPage, dt as ObjectCoverage, du as ObjectPush, dv as ObjectPushRequest, dw as ObjectPushResponse, dx as ObjectRead, dy as ObjectSnapshotResponse, dz as ObjectTimeline, dA as ObjectTimelineParams, dB as Observation, dC as OpenItemOut, dD as OpenItemRequest, dE as OpenObject, dF as OpenParams, dG as OpenedItem, dH as Origin, dI as OutcomeLink, dJ as OutcomePage, dK as OutcomeRequest, dL as OutcomeState, dM as Owner, dN as OwnershipClaim, dO as OwnershipCount, dP as PERSONAL_DATA_TOOL_ERROR, dQ as PackGuard, dR as PackLayer, dS as PackSection, dT as PackSlot, dU as PackSlotDerived, dV as PackStamp, dW as PowerRequest, dX as PowerResult, dY as Preference, dZ as PrefetchParams, d_ as PrefetchRequest, d$ as Presented, e0 as PresentedItem, e1 as PreviousValue, e2 as Problem, e3 as ProfileMatch, e4 as ProfileMemory, e5 as PromiseRef, e6 as PromoteRequest, e7 as PromoteResponse, e8 as ProposalStatus, e9 as Provenance, ea as QueueOptions, eb as ReadingResult, ec as ReconcileRequest, ed as ReconcileResult, ee as ReconciledLine, ef as RecordedToolOptions, eg as Recurrence, eh as Refetch, ei as RefreshRelease, ej as RefreshReleased, ek as RefreshRequest, el as RefreshRequestPage, em as Refusal, en as ReleaseDetail, eo as RememberParams, ep as RememberResult, eq as Rendered, er as ReplayAssertion, es as ReplayBlocker, et as ReplayCase, eu as ReplayCaseRequest, ev as ReplayHistoryEntry, ew as ReplayResult, ex as RequestOptions, ey as Resolved, ez as Resolver, eA as Result, eB as ResultObjects, eC as ReviewRequest, eD as ReviewRequestCreate, eE as ReviewRequestPage, eF as ReviewResolution, eG as Scenario, eH as ScenarioCreate, eI as ScenarioFromReport, eJ as ScenarioPage, eK as ScenarioRun, eL as ScenarioRunCreate, eM as ScenarioRunSummary, eN as ScenarioUpdate, eO as ScenarioVerdict, eP as SdkProfile, eQ as SearchRequest, eR as SearchResponse, eS as Seen, eT as SeenTokens, eU as ShadowRequest, eV as ShadowRun, eW as Shown, eX as SlotChannelRank, eY as SlotWhy, eZ as SoftConstraint, e_ as SourceCoverage, e$ as Speaker, f0 as SpeakerRef, f1 as StateMode, f2 as StateReadRequest, f3 as StateReadResponse, f4 as StateRef, f5 as StateVerifyRequest, f6 as StateVerifyResponse, f7 as StateView, f8 as StateViewRequest, f9 as StateWrite, fa as Subject, fb as SubjectToken, fc as SubjectTokenRequest, fd as Suppression, fe as SuppressionAdded, ff as SuppressionAddedDetail, fg as SuppressionLifted, fh as SuppressionLiftedDetail, fi as SuppressionPage, fj as SuppressionSalt, fk as TOOL_DEFINITIONS, fl as TOOL_NAMES, fm as TargetModel, fn as Task, fo as TaskAction, fp as TaskEndedItem, fq as TaskEvent, fr as TaskLockDeclared, fs as TaskLockDetail, ft as TaskParams, fu as TimeWindow, fv as TimelineRequest, fw as TimelineResponse, fx as Timeouts, fy as TimerState, fz as Timestamp, fA as Timings, fB as ToolBinding, fC as ToolCapabilities, fD as ToolDefinition, fE as ToolOptions, fF as TrackEvent, fG as TraitOut, fH as TurnAgent, fI as TurnBlob, fJ as TurnBuild, fK as TurnCall, fL as TurnCompilerPins, fM as TurnConstraints, fN as TurnCoordination, fO as TurnCost, fP as TurnEffect, fQ as TurnFlag, fR as TurnFrame, fS as TurnIndexEntry, fT as TurnIndexPage, fU as TurnKind, fV as TurnObservation, fW as TurnOptions, fX as TurnOutput, fY as TurnParams, fZ as TurnProvenance, f_ as TurnRead, f$ as TurnRecord, g0 as TurnRecorder, g1 as TurnRecordingOptions, g2 as TurnRecordingSummary, g3 as TurnSearchRequest, g4 as TurnSearchResponse, g5 as TurnSummary, g6 as TurnTokens, g7 as TurnView, g8 as TurnsRequest, g9 as TurnsResponse, ga as TypeCoverage, gb as TypeFingerprintRequest, gc as TypeFingerprintResponse, gd as UnbackedValue, ge as UnmetDemand, gf as UnmetDemandPage, gg as Unwatch, gh as UploadParams, gi as ValueEvidence, gj as ValueKind, gk as ValueState, gl as Verdict, gm as Verification, gn as VerificationResult, go as VerifyCheck, gp as VerifyItem, gq as VerifyMethod, gr as VerifyParams, gs as View, gt as Visibility, gu as VoiceInfo, gv as VoiceOptions, gw as Watch, gx as WhereExpression, gy as WorkingState, gz as WriteResult, gA as checkBacking, gB as consoleLogger, gC as currentCall, gD as currentTurn, gE as guardStream, gF as guardText, gG as recipientHash, gH as renderLive, gI as renderSuffix, gJ as silentLogger, gK as tool, gL as verifyContactToken, gM as violatesGuard } from './client-DsIxZxZk.cjs';
|
|
3
|
+
|
|
1
4
|
/**
|
|
2
|
-
* The
|
|
3
|
-
*
|
|
5
|
+
* The constraints block rendered for one tool call (`spec/constraints.md`, sections 6 and 7): what the
|
|
6
|
+
* call's arguments can carry through the tool's binding, what they cannot (the residual), and, after the
|
|
7
|
+
* call, how much of what was sent the results honored. The server runs the same rules for
|
|
8
|
+
* `POST /v1/constraints` with a tool.
|
|
9
|
+
*
|
|
10
|
+
* - A hard constraint renders through the binding argument of its field: `in` and `eq` to the argument,
|
|
11
|
+
* `not_in` and `ne` to its negation parameter, a comparison or `between` only to an argument that
|
|
12
|
+
* declares it in `ops`. One value renders as itself, several as a list; `transform` changes the case of
|
|
13
|
+
* text.
|
|
14
|
+
* - A hard constraint that lost a conflict of the block is not rendered at all.
|
|
15
|
+
* - A constraint of a category holds only for a call of that category.
|
|
16
|
+
* - An attribute renders through the argument of its family (`size` for `size.pants`) when it applies:
|
|
17
|
+
* `always`, or `when_asked` and the person asked for it this turn.
|
|
18
|
+
* - What no argument can express is residual: the SDK filters it from the results when the tool
|
|
19
|
+
* overfetches, and it is otherwise unenforced. `exclude` is always residual.
|
|
20
|
+
* - Advisory mode (the default) changes nothing and suggests. Apply mode adds only what the call left out,
|
|
21
|
+
* and only a hard constraint said in this turn or this session, or an attribute the person said; it never
|
|
22
|
+
* overrides an argument the call set (the current utterance wins, and the clash is reported as a
|
|
23
|
+
* conflict), and never adds an inferred size.
|
|
24
|
+
* - A block for another beneficiary than the call's does not apply at all.
|
|
25
|
+
*
|
|
26
|
+
* The same rules as the Python SDK's `niadra.constraints.render`.
|
|
4
27
|
*/
|
|
5
|
-
|
|
6
|
-
type
|
|
7
|
-
/**
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
28
|
+
|
|
29
|
+
type Op = HardConstraint["op"];
|
|
30
|
+
/** One argument of a tool's binding (`tool-bindings`): the field it carries and how. */
|
|
31
|
+
interface BindingArg {
|
|
32
|
+
/** The field, `type.field`. */
|
|
33
|
+
attr: string;
|
|
34
|
+
param: string;
|
|
35
|
+
transform?: "lower" | "upper" | null;
|
|
36
|
+
/** The parameter that carries the field's negation (`not_in`, `ne`). */
|
|
37
|
+
negation?: string | null;
|
|
38
|
+
/** The comparisons the parameter accepts besides `in` and `eq`. */
|
|
39
|
+
ops?: readonly string[];
|
|
40
|
+
/** The attribute family of the field (`size`), from the type registry. */
|
|
41
|
+
family?: string | null;
|
|
42
|
+
}
|
|
43
|
+
interface Binding {
|
|
44
|
+
tool: string;
|
|
45
|
+
args: readonly BindingArg[];
|
|
46
|
+
/** The tool returns more than asked, so the SDK can filter the residual from its results. */
|
|
47
|
+
overfetch?: boolean;
|
|
48
|
+
}
|
|
49
|
+
/** The call the model made. */
|
|
50
|
+
interface Call$1 {
|
|
51
|
+
args: Readonly<Record<string, unknown>>;
|
|
52
|
+
/** Whose call it is: `self` (the default), `beneficiary:<id>` or `gift`. */
|
|
53
|
+
for?: string;
|
|
54
|
+
category?: string | null;
|
|
55
|
+
/** The attributes the person asked to use this turn ("in my size": `size`). */
|
|
56
|
+
asked?: readonly string[];
|
|
57
|
+
}
|
|
58
|
+
interface Rendering {
|
|
59
|
+
applies: boolean;
|
|
60
|
+
/** What the call sends: its own arguments, plus what apply mode added. */
|
|
61
|
+
args: Record<string, unknown>;
|
|
62
|
+
suggested: Record<string, unknown>;
|
|
63
|
+
injected: string[];
|
|
64
|
+
hardSent: string[];
|
|
65
|
+
residual: string[];
|
|
66
|
+
postFilter: string[];
|
|
67
|
+
/** A hard constraint and the argument the call set against it. */
|
|
68
|
+
conflicts: {
|
|
69
|
+
id: string;
|
|
70
|
+
param: string;
|
|
71
|
+
}[];
|
|
72
|
+
}
|
|
73
|
+
/** What the results show of the hard constraints sent: "sent, verifiable, violated", never only sent. */
|
|
74
|
+
interface Honored {
|
|
75
|
+
resultsChecked: number;
|
|
76
|
+
violations: number;
|
|
77
|
+
/** Results without the constrained field: without this count, conformance lies upward. */
|
|
78
|
+
unverifiable: number;
|
|
79
|
+
}
|
|
80
|
+
/** The block for one call of the tool `binding` describes. */
|
|
81
|
+
declare function render(block: ConstraintsBlock, binding: Binding, call: Call$1, mode?: "advisory" | "apply"): Rendering;
|
|
13
82
|
/**
|
|
14
|
-
*
|
|
15
|
-
*
|
|
83
|
+
* Each result item, keyed by `type.field`, is a violation when it breaks a hard constraint that was sent,
|
|
84
|
+
* and unverifiable when it breaks none but lacks the field of one.
|
|
16
85
|
*/
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
|
|
86
|
+
declare function honored(block: ConstraintsBlock, sentIds: readonly string[], results: readonly Readonly<Record<string, unknown>>[]): Honored;
|
|
87
|
+
/** Whether `value` honors `op` over `values`; text is compared folded, numbers as exact decimals. */
|
|
88
|
+
declare function satisfies(op: Op, values: readonly unknown[], value: unknown): boolean;
|
|
89
|
+
|
|
20
90
|
/**
|
|
21
|
-
*
|
|
22
|
-
*
|
|
91
|
+
* The digest of a value a turn record carries: SHA-256 over its canonical JSON (RFC 8785).
|
|
92
|
+
*
|
|
93
|
+
* The canonical form leaves no whitespace, sorts object keys by their UTF-16 code units and writes numbers
|
|
94
|
+
* as ECMAScript does, so a producer in any language hashes the same value to the same digest. The Turn
|
|
95
|
+
* Record spec fixes it (section 6.2.1) with the vectors in `spec/vectors/turn-record-digest.v0.json`.
|
|
23
96
|
*/
|
|
24
|
-
type Verification = "V0" | "V1" | "V2" | "V3" | "V4" | "no_customer";
|
|
25
|
-
/** How a customer proved who they are in a `verify` call. */
|
|
26
|
-
type VerifyMethod = "otp_whatsapp" | "otp_sms" | "login" | "kba" | "network_attestation" | "human_agent";
|
|
27
97
|
/**
|
|
28
|
-
*
|
|
29
|
-
*
|
|
98
|
+
* `value` (JSON data: plain objects, arrays, strings, finite numbers, booleans and `null`) as its
|
|
99
|
+
* canonical JSON. A property whose value is `undefined` is left out, as `JSON.stringify` does; anything
|
|
100
|
+
* JSON cannot hold (`NaN`, a `bigint`, a `Date`) throws.
|
|
30
101
|
*/
|
|
31
|
-
|
|
32
|
-
/** Kinds of history items the navigation calls can filter on. */
|
|
33
|
-
type HistoryItemKind = "episode" | "fact" | "open_item" | "action" | "system_event" | "object" | "trait";
|
|
102
|
+
declare function canonicalJson(value: unknown): string;
|
|
34
103
|
/**
|
|
35
|
-
*
|
|
36
|
-
*
|
|
104
|
+
* `value`'s digest, written `sha256:<hex>`, and the size in bytes of its canonical JSON (UTF-8). Web
|
|
105
|
+
* Crypto hashes asynchronously, so the turn capture hashes when it sends, never on the agent's path.
|
|
37
106
|
*/
|
|
38
|
-
|
|
107
|
+
declare function jsonDigest(value: unknown): Promise<{
|
|
108
|
+
sha256: string;
|
|
109
|
+
size: number;
|
|
110
|
+
}>;
|
|
39
111
|
|
|
40
112
|
/**
|
|
41
|
-
*
|
|
42
|
-
* a CRM id. Handles carry personal data, so the SDK only ever sends them in request bodies.
|
|
113
|
+
* The four logical values of a field (`spec/object-type.md`, section 5.4): not observed is never false.
|
|
43
114
|
*/
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
value: string;
|
|
48
|
-
/**
|
|
49
|
-
* Namespace for scoped identifiers: the WhatsApp Business account for `wa_bsuid`, the
|
|
50
|
-
* system for `system_id`, the country for `gov_id_hmac`.
|
|
51
|
-
*/
|
|
52
|
-
scope?: string | null;
|
|
53
|
-
/** Defaults to `person` on the server, except for organization-only handle types. */
|
|
54
|
-
subject_kind?: SubjectKind | null;
|
|
55
|
-
}
|
|
56
|
-
/** A business object in a system of record, such as `invoice` / `erp` / `0823`. */
|
|
57
|
-
interface ObjectRef {
|
|
58
|
-
type: string;
|
|
59
|
-
namespace: string;
|
|
60
|
-
id: string;
|
|
61
|
-
}
|
|
62
|
-
/** A participant of an event other than the speaker, for example the account a person acts for. */
|
|
63
|
-
interface Subject {
|
|
64
|
-
kind: SubjectKind;
|
|
65
|
-
role?: string | null;
|
|
66
|
-
/** Between 1 and 16 handles. */
|
|
67
|
-
handles: Handle[];
|
|
68
|
-
}
|
|
69
|
-
/** Whether a source is still sending. `silent` means it stopped, so the pack may be missing recent turns. */
|
|
70
|
-
interface SourceCoverage {
|
|
71
|
-
source_id: string;
|
|
72
|
-
status: "ok" | "silent" | (string & {});
|
|
73
|
-
last_event_at?: string | null;
|
|
74
|
-
}
|
|
75
|
-
/** RFC 9457 problem details, as returned with `application/problem+json`. */
|
|
76
|
-
interface Problem {
|
|
77
|
-
type: string;
|
|
78
|
-
title: string;
|
|
79
|
-
status: number;
|
|
80
|
-
detail?: string | null;
|
|
81
|
-
/** Stable code from the versioned error catalog, such as `rate_limited` or `wrong_cell`. */
|
|
82
|
-
code: string;
|
|
83
|
-
request_id?: string | null;
|
|
84
|
-
}
|
|
115
|
+
type Logic = "yes" | "no" | "unobserved" | "known_defect";
|
|
116
|
+
/** The two logical values that say nothing about the value. */
|
|
117
|
+
type UnknownLogic = "unobserved" | "known_defect";
|
|
85
118
|
|
|
86
119
|
/**
|
|
87
|
-
*
|
|
88
|
-
*
|
|
120
|
+
* niadra-expr: the language of the type registry's conditions, timers, keys and readings
|
|
121
|
+
* (`spec/object-type.md`, section 5).
|
|
122
|
+
*
|
|
123
|
+
* Small, deterministic and total: literals, names, comparison, `in`, `and`, `or`, `not`, `+`, `-` and a
|
|
124
|
+
* fixed set of functions; no loop, no I/O, and bounded text, tokens and nesting. Every value carries one of
|
|
125
|
+
* the four logical values, so a comparison with a value nobody observed is itself unobserved, never false.
|
|
126
|
+
* The server and both SDKs implement the same language and pass the same vectors
|
|
127
|
+
* (`spec/vectors/niadra-expr.v0.json`).
|
|
128
|
+
*
|
|
129
|
+
* `parse` reads the text, `compileExpression` also resolves its names against a type declaration (the
|
|
130
|
+
* registry's validation), and `evaluate` computes it over an `Environment`, the object's slots at one
|
|
131
|
+
* instant. Time is integer arithmetic, never the machine's time zone: a datetime is milliseconds since the
|
|
132
|
+
* epoch, a date the days since 1970-01-01, and the environment's UTC offset says where a day starts.
|
|
89
133
|
*/
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
declare class
|
|
99
|
-
readonly
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
/**
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
134
|
+
|
|
135
|
+
/** The three errors of the language (`spec/object-type.md`, section 5.9). */
|
|
136
|
+
type ExprErrorCode = "expr_invalid" | "expr_type" | "expr_limit";
|
|
137
|
+
/**
|
|
138
|
+
* `expr_invalid`: the text is not a valid expression, or names what the type does not declare;
|
|
139
|
+
* `expr_type`: a value of the wrong kind, or out of its domain, met during evaluation; `expr_limit`: a bound
|
|
140
|
+
* of the language was exceeded. The message says what, in words; only the code is part of the contract.
|
|
141
|
+
*/
|
|
142
|
+
declare class ExprError extends NiadraError {
|
|
143
|
+
readonly code: ExprErrorCode;
|
|
144
|
+
readonly name = "ExprError";
|
|
145
|
+
constructor(code: ExprErrorCode, message: string);
|
|
146
|
+
}
|
|
147
|
+
/** The kind of a present value; business days and a quote exist only inside an expression. */
|
|
148
|
+
type Kind = "bool" | "number" | "string" | "duration" | "date" | "datetime" | "list" | "business_days" | "quote";
|
|
149
|
+
/** A named list of holidays and the weekdays that are never business days. */
|
|
150
|
+
interface Calendar {
|
|
151
|
+
/** Days since 1970-01-01, as `parseDate` gives them. */
|
|
152
|
+
readonly holidays?: ReadonlySet<number>;
|
|
153
|
+
/** ISO weekdays (1 is Monday) that are never business days; Saturday and Sunday unless given. */
|
|
154
|
+
readonly weekend?: ReadonlySet<number>;
|
|
155
|
+
}
|
|
156
|
+
/** A whole count of business days on a calendar, to add to or subtract from a date. */
|
|
157
|
+
interface BusinessDays {
|
|
158
|
+
readonly count: number;
|
|
159
|
+
readonly calendar: Calendar;
|
|
160
|
+
}
|
|
161
|
+
interface Unknown {
|
|
162
|
+
readonly logic: UnknownLogic;
|
|
163
|
+
readonly kind?: undefined;
|
|
164
|
+
}
|
|
165
|
+
interface Absent {
|
|
166
|
+
readonly logic: "no";
|
|
167
|
+
readonly kind?: undefined;
|
|
168
|
+
/** The declared name of the absence, when there is one. */
|
|
169
|
+
readonly absent?: string;
|
|
170
|
+
}
|
|
171
|
+
interface Bool {
|
|
172
|
+
readonly logic: "yes" | "no";
|
|
173
|
+
readonly kind: "bool";
|
|
174
|
+
readonly datum: boolean;
|
|
175
|
+
}
|
|
176
|
+
interface Present<K extends Kind, D> {
|
|
177
|
+
readonly logic: "yes";
|
|
178
|
+
readonly kind: K;
|
|
179
|
+
readonly datum: D;
|
|
180
|
+
}
|
|
181
|
+
type DateValue = Present<"date", number>;
|
|
182
|
+
type DatetimeValue = Present<"datetime", number>;
|
|
183
|
+
/**
|
|
184
|
+
* A value and its logical value. A known value is present (`yes`, or a boolean, `no` when false) or absent
|
|
185
|
+
* (`no` with no kind, and the declared name of the absence when there is one); an unknown one carries
|
|
186
|
+
* nothing.
|
|
187
|
+
*
|
|
188
|
+
* Data: a boolean, a number (an IEEE 754 double), a string, whole milliseconds for a duration, days since
|
|
189
|
+
* 1970-01-01 for a date, milliseconds since the epoch for a datetime, the values of a list, a count on a
|
|
190
|
+
* calendar for business days, and the slots of a quote by field.
|
|
191
|
+
*/
|
|
192
|
+
type Value$1 = Unknown | Absent | Bool | Present<"number", number> | Present<"string", string> | Present<"duration", number> | DateValue | DatetimeValue | Present<"list", readonly Value$1[]> | Present<"business_days", BusinessDays> | Present<"quote", Readonly<Record<string, Slot>>>;
|
|
193
|
+
/**
|
|
194
|
+
* One field, computed value, time axis or input of an object as a reading sees it: the value, when a
|
|
195
|
+
* source observed it (`at`, milliseconds since the epoch), by whom, its value before the latest change, and
|
|
196
|
+
* the completeness level of a content field.
|
|
197
|
+
*/
|
|
198
|
+
interface Slot {
|
|
199
|
+
readonly value: Value$1;
|
|
200
|
+
readonly at?: number;
|
|
201
|
+
/** `machine`, `human` or `source:<name>`. */
|
|
202
|
+
readonly observer?: string;
|
|
203
|
+
readonly was?: Value$1;
|
|
204
|
+
readonly completeness?: string;
|
|
114
205
|
}
|
|
115
206
|
/**
|
|
116
|
-
*
|
|
117
|
-
*
|
|
207
|
+
* What an evaluation reads (`spec/object-type.md`, section 5.11): the current instant, the object's slots
|
|
208
|
+
* (fields, computed values and time axes by name), the declared inputs by dotted path, the absence names,
|
|
209
|
+
* the company's configuration by key, the reader's quotes by source, the calendars by name, and the
|
|
210
|
+
* context names.
|
|
118
211
|
*/
|
|
119
|
-
|
|
212
|
+
interface Environment {
|
|
213
|
+
/** Milliseconds since the epoch. */
|
|
214
|
+
readonly now: number;
|
|
215
|
+
/** Minutes east of UTC, where a date's day starts; 0 unless given. */
|
|
216
|
+
readonly utcOffsetMin?: number;
|
|
217
|
+
readonly fields?: Readonly<Record<string, Slot>>;
|
|
218
|
+
readonly inputs?: Readonly<Record<string, Slot>>;
|
|
219
|
+
readonly absentNames?: ReadonlySet<string>;
|
|
220
|
+
readonly config?: Readonly<Record<string, Value$1>>;
|
|
221
|
+
readonly quotes?: Readonly<Record<string, Readonly<Record<string, Slot>>>>;
|
|
222
|
+
readonly calendars?: Readonly<Record<string, Calendar>>;
|
|
223
|
+
/** The lifecycle state; absent unless given. */
|
|
224
|
+
readonly state?: string;
|
|
225
|
+
readonly derivedStatus?: string;
|
|
226
|
+
/** 0 unless given. */
|
|
227
|
+
readonly watchCount?: number;
|
|
228
|
+
/** The read's purpose; `display` unless given. */
|
|
229
|
+
readonly purpose?: string;
|
|
230
|
+
/** The object's best position presented in the conversation. */
|
|
231
|
+
readonly presentedRank?: number;
|
|
232
|
+
}
|
|
233
|
+
/** `true` or `false`: `yes` or `no`, of kind `bool`. */
|
|
234
|
+
declare const boolean: (flag: boolean) => Value$1;
|
|
235
|
+
/** A value nobody observed, or one whose source is known to get it wrong. */
|
|
236
|
+
declare const unknown: (logic: UnknownLogic) => Value$1;
|
|
237
|
+
/** An absence: the source affirmed there is no value, under a declared name when it gives one. */
|
|
238
|
+
declare const absent: (name?: string) => Value$1;
|
|
239
|
+
interface NameNode {
|
|
240
|
+
readonly node: "name";
|
|
241
|
+
readonly parts: readonly [string, ...string[]];
|
|
242
|
+
}
|
|
243
|
+
type Comparison = "==" | "!=" | "<" | "<=" | ">" | ">=" | "in";
|
|
244
|
+
/** A call, with each function's arguments in their fixed form (`spec/object-type.md`, section 5.7). */
|
|
245
|
+
type Call = {
|
|
246
|
+
readonly node: "call";
|
|
247
|
+
readonly fn: "now";
|
|
248
|
+
} | {
|
|
249
|
+
readonly node: "call";
|
|
250
|
+
readonly fn: "age" | "observer" | "changed";
|
|
251
|
+
readonly ref: NameNode;
|
|
252
|
+
} | {
|
|
253
|
+
readonly node: "call";
|
|
254
|
+
readonly fn: "was" | "count";
|
|
255
|
+
readonly arg: Node;
|
|
256
|
+
} | {
|
|
257
|
+
readonly node: "call";
|
|
258
|
+
readonly fn: "business_days";
|
|
259
|
+
readonly count: Node;
|
|
260
|
+
readonly calendar: string;
|
|
261
|
+
} | {
|
|
262
|
+
readonly node: "call";
|
|
263
|
+
readonly fn: "quote";
|
|
264
|
+
readonly source: string;
|
|
265
|
+
} | {
|
|
266
|
+
readonly node: "call";
|
|
267
|
+
readonly fn: "presented_in_top";
|
|
268
|
+
readonly top: number;
|
|
269
|
+
} | {
|
|
270
|
+
readonly node: "call";
|
|
271
|
+
readonly fn: "sha256";
|
|
272
|
+
readonly args: readonly Node[];
|
|
273
|
+
};
|
|
274
|
+
/** The syntax tree of an expression (`spec/object-type.md`, section 5.3), as `parse` gives it. */
|
|
275
|
+
type Node = {
|
|
276
|
+
readonly node: "literal";
|
|
277
|
+
readonly value: Value$1;
|
|
278
|
+
} | {
|
|
279
|
+
readonly node: "logical";
|
|
280
|
+
readonly logic: Logic;
|
|
281
|
+
} | NameNode | {
|
|
282
|
+
readonly node: "member";
|
|
283
|
+
readonly target: Node;
|
|
120
284
|
readonly name: string;
|
|
121
|
-
|
|
122
|
-
readonly
|
|
123
|
-
readonly
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
readonly
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
readonly
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
readonly
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
/**
|
|
285
|
+
} | Call | {
|
|
286
|
+
readonly node: "list";
|
|
287
|
+
readonly items: readonly Node[];
|
|
288
|
+
} | {
|
|
289
|
+
readonly node: "not";
|
|
290
|
+
readonly operand: Node;
|
|
291
|
+
} | {
|
|
292
|
+
readonly node: "boolean";
|
|
293
|
+
readonly op: "and" | "or";
|
|
294
|
+
readonly operands: readonly Node[];
|
|
295
|
+
} | {
|
|
296
|
+
readonly node: "compare";
|
|
297
|
+
readonly op: Comparison;
|
|
298
|
+
readonly left: Node;
|
|
299
|
+
readonly right: Node;
|
|
300
|
+
} | {
|
|
301
|
+
readonly node: "arith";
|
|
302
|
+
readonly op: "+" | "-";
|
|
303
|
+
readonly left: Node;
|
|
304
|
+
readonly right: Node;
|
|
305
|
+
};
|
|
306
|
+
/** Names a type may not give a field, a value, a time axis or an absence (`spec/object-type.md`, section 5.5). */
|
|
307
|
+
declare const RESERVED: ReadonlySet<string>;
|
|
308
|
+
/** The syntax tree of an expression, or `ExprError` (`expr_invalid`, `expr_limit`). */
|
|
309
|
+
declare function parse(text: string): Node;
|
|
310
|
+
/**
|
|
311
|
+
* The value of a parsed expression over an environment, or `ExprError` (`expr_type`, `expr_limit`). A
|
|
312
|
+
* business-day count or a quote is a step, never a result.
|
|
313
|
+
*/
|
|
314
|
+
declare function evaluate(node: Node, env: Environment): Value$1;
|
|
315
|
+
/** A `YYYY-MM-DD` date as days since 1970-01-01; a `RangeError` for anything else. */
|
|
316
|
+
declare function parseDate(text: string): number;
|
|
317
|
+
/** A day since 1970-01-01 as `YYYY-MM-DD`. */
|
|
318
|
+
declare function formatDate(days: number): string;
|
|
319
|
+
/**
|
|
320
|
+
* An RFC 3339 time with its offset as milliseconds since the epoch; digits below the millisecond are
|
|
321
|
+
* dropped. A `RangeError` for anything else, a time without an offset included.
|
|
322
|
+
*/
|
|
323
|
+
declare function parseDatetime(text: string): number;
|
|
324
|
+
/** The canonical form of an instant: UTC, with milliseconds (`2026-09-29T12:00:00.000Z`). */
|
|
325
|
+
declare function formatDatetime(ms: number): string;
|
|
326
|
+
/**
|
|
327
|
+
* What a type declares, as the names of its expressions resolve: its fields with their kind (`null` when
|
|
328
|
+
* the declaration fixes none), the fields with completeness levels, computed values, time axes, absence
|
|
329
|
+
* names, inputs, states, and sources with their kind (`pull`, `quote`...).
|
|
330
|
+
*/
|
|
331
|
+
interface Scope {
|
|
332
|
+
readonly fields?: Readonly<Record<string, Kind | null>>;
|
|
333
|
+
readonly completeness?: ReadonlySet<string>;
|
|
334
|
+
readonly values?: ReadonlySet<string>;
|
|
335
|
+
readonly axes?: ReadonlySet<string>;
|
|
336
|
+
readonly absentNames?: ReadonlySet<string>;
|
|
337
|
+
readonly inputs?: ReadonlySet<string>;
|
|
338
|
+
readonly states?: ReadonlySet<string>;
|
|
339
|
+
readonly sources?: Readonly<Record<string, string>>;
|
|
340
|
+
}
|
|
341
|
+
/** What an entry of a type expects its expression to give: anything, a condition, or a time. */
|
|
342
|
+
type Expect = "any" | "condition" | "time";
|
|
343
|
+
/**
|
|
344
|
+
* Parses and resolves an expression of a type declaration (`spec/object-type.md`, section 5.12);
|
|
345
|
+
* `expr_invalid` names what is wrong.
|
|
346
|
+
*/
|
|
347
|
+
declare function compileExpression(text: string, scope: Scope, expect?: Expect): Node;
|
|
348
|
+
/** A duration literal (`30s`, `10min`, `24h`, `7d`) in milliseconds, as the declarations write them. */
|
|
349
|
+
declare function durationMs(text: string): number;
|
|
143
350
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
}
|
|
170
|
-
/** A recent turn from another channel that the compiled pack has not absorbed yet. */
|
|
171
|
-
interface LiveTurn {
|
|
172
|
-
at: string;
|
|
173
|
-
channel: string;
|
|
174
|
-
kind: EventKind;
|
|
175
|
-
speaker: string;
|
|
176
|
-
text: string;
|
|
177
|
-
source_id: string;
|
|
178
|
-
}
|
|
179
|
-
/** Where a prompt-cache breakpoint may go, and whether caching this pack is worth it. */
|
|
180
|
-
interface CacheDirectives {
|
|
181
|
-
/** Character offsets into `text` where a cache breakpoint may be placed. */
|
|
182
|
-
breakpoints: number[];
|
|
183
|
-
ttl_seconds?: number | null;
|
|
184
|
-
floor_tokens?: number | null;
|
|
185
|
-
cacheable: boolean;
|
|
186
|
-
/** Stable cache salt for self-hosted inference engines. */
|
|
187
|
-
salt: string;
|
|
188
|
-
}
|
|
189
|
-
/** Body of a `POST /v1/context` response. */
|
|
190
|
-
interface ContextResponse {
|
|
191
|
-
/** `true` when `known_etag` still matches; `text` is then omitted. */
|
|
192
|
-
not_modified: boolean;
|
|
193
|
-
text?: string | null;
|
|
194
|
-
variables: Record<string, string>;
|
|
195
|
-
version: string;
|
|
196
|
-
etag: string;
|
|
197
|
-
manifest_hash?: string | null;
|
|
198
|
-
as_of?: string | null;
|
|
199
|
-
lag_seconds?: number | null;
|
|
200
|
-
coverage: SourceCoverage[];
|
|
201
|
-
verification: VerificationResult;
|
|
202
|
-
/** How many items policy or verification kept out of the pack. */
|
|
203
|
-
withheld: number;
|
|
204
|
-
live: LiveTurn[];
|
|
205
|
-
live_complete: boolean;
|
|
206
|
-
delta?: string | null;
|
|
207
|
-
cache?: CacheDirectives | null;
|
|
208
|
-
timing: Record<string, number>;
|
|
209
|
-
path: DeliveryPath;
|
|
210
|
-
degraded: boolean;
|
|
211
|
-
}
|
|
212
|
-
interface HistoryFilters {
|
|
213
|
-
since?: string | null;
|
|
214
|
-
until?: string | null;
|
|
215
|
-
channels?: string[];
|
|
216
|
-
categories?: string[];
|
|
217
|
-
item_kinds?: HistoryItemKind[];
|
|
218
|
-
outcome?: string | null;
|
|
219
|
-
object?: ObjectRef | null;
|
|
220
|
-
}
|
|
221
|
-
/** Body of `POST /v1/history/search`. */
|
|
222
|
-
interface SearchRequest {
|
|
223
|
-
subject: Handle;
|
|
224
|
-
about?: Handle | null;
|
|
225
|
-
/** Between 1 and 2,000 characters. */
|
|
226
|
-
query: string;
|
|
227
|
-
filters?: HistoryFilters;
|
|
228
|
-
/** Token budget for the answer, between 50 and 4,000. Defaults to 800. */
|
|
229
|
-
max_tokens?: number;
|
|
230
|
-
verification?: Verification;
|
|
231
|
-
conversation_id?: string | null;
|
|
232
|
-
task_id?: string | null;
|
|
233
|
-
}
|
|
234
|
-
interface HistoryItem {
|
|
235
|
-
id: string;
|
|
236
|
-
kind: string;
|
|
237
|
-
text: string;
|
|
238
|
-
at: string;
|
|
239
|
-
channel?: string | null;
|
|
240
|
-
source_id?: string | null;
|
|
241
|
-
outcome?: string | null;
|
|
242
|
-
confidence?: number | null;
|
|
243
|
-
origin_event_id?: string | null;
|
|
244
|
-
}
|
|
245
|
-
/** How often the same kind of issue came back, computed by the same rule as the recurring-complaint pattern. */
|
|
246
|
-
interface Recurrence {
|
|
247
|
-
category: string;
|
|
248
|
-
occurrences: number;
|
|
249
|
-
window_days: number;
|
|
250
|
-
last_at?: string | null;
|
|
251
|
-
last_outcome?: string | null;
|
|
252
|
-
last_resolution?: string | null;
|
|
253
|
-
}
|
|
254
|
-
interface SearchResponse {
|
|
255
|
-
items: HistoryItem[];
|
|
256
|
-
recurrence?: Recurrence | null;
|
|
257
|
-
withheld: number;
|
|
258
|
-
as_of?: string | null;
|
|
259
|
-
tokens_used: number;
|
|
260
|
-
/** `text_only` when semantic search was unavailable and only keyword matching ran. */
|
|
261
|
-
degraded?: string | null;
|
|
262
|
-
}
|
|
263
|
-
/** Body of `POST /v1/history/timeline`. */
|
|
264
|
-
interface TimelineRequest {
|
|
265
|
-
subject: Handle;
|
|
266
|
-
about?: Handle | null;
|
|
267
|
-
filters?: HistoryFilters;
|
|
268
|
-
cursor?: string | null;
|
|
269
|
-
/** Between 1 and 100. Defaults to 20. */
|
|
270
|
-
limit?: number;
|
|
271
|
-
verification?: Verification;
|
|
272
|
-
conversation_id?: string | null;
|
|
273
|
-
}
|
|
274
|
-
interface TimelineResponse {
|
|
275
|
-
items: HistoryItem[];
|
|
276
|
-
next_cursor?: string | null;
|
|
277
|
-
withheld: number;
|
|
278
|
-
as_of?: string | null;
|
|
279
|
-
}
|
|
280
|
-
/** A commitment recorded in an episode, made by the company or by the customer. */
|
|
281
|
-
interface Commitment {
|
|
282
|
-
by: "company" | "customer";
|
|
283
|
-
what: string;
|
|
284
|
-
due_at?: string | null;
|
|
285
|
-
status: string;
|
|
286
|
-
}
|
|
287
|
-
/** One history item opened in full: structured summary, outcome and commitments. */
|
|
288
|
-
interface OpenedItem {
|
|
289
|
-
id: string;
|
|
290
|
-
kind: "episode" | "object";
|
|
291
|
-
summary: string;
|
|
292
|
-
requested?: string | null;
|
|
293
|
-
promises: Commitment[];
|
|
294
|
-
outcome?: string | null;
|
|
295
|
-
resolution?: string | null;
|
|
296
|
-
derived: HistoryItem[];
|
|
297
|
-
timeline: HistoryItem[];
|
|
298
|
-
/** Literal transcript excerpt. Only returned to keys with an elevated scope. */
|
|
299
|
-
excerpt?: string | null;
|
|
300
|
-
as_of?: string | null;
|
|
301
|
-
}
|
|
302
|
-
/** The derived state of a business object, from `GET /v1/objects/{type}/{namespace}/{id}`. */
|
|
303
|
-
interface ObjectState {
|
|
304
|
-
ref: ObjectRef;
|
|
305
|
-
state: Record<string, unknown>;
|
|
306
|
-
as_of: string;
|
|
307
|
-
source_id: string;
|
|
308
|
-
record_ref?: string | null;
|
|
309
|
-
open_items: HistoryItem[];
|
|
310
|
-
}
|
|
311
|
-
/** System events and agent actions about one object, newest first; never conversation content. */
|
|
312
|
-
interface ObjectTimeline {
|
|
313
|
-
ref: ObjectRef;
|
|
314
|
-
items: HistoryItem[];
|
|
315
|
-
next_cursor?: string | null;
|
|
316
|
-
as_of?: string | null;
|
|
317
|
-
}
|
|
318
|
-
/** A function-calling tool definition in the JSON Schema shape most model APIs accept. */
|
|
319
|
-
interface ToolDefinition {
|
|
320
|
-
type: "function";
|
|
321
|
-
function: {
|
|
322
|
-
name: string;
|
|
323
|
-
description: string;
|
|
324
|
-
parameters: Record<string, unknown>;
|
|
325
|
-
};
|
|
351
|
+
type expr_BusinessDays = BusinessDays;
|
|
352
|
+
type expr_Calendar = Calendar;
|
|
353
|
+
type expr_Environment = Environment;
|
|
354
|
+
type expr_Expect = Expect;
|
|
355
|
+
type expr_ExprError = ExprError;
|
|
356
|
+
declare const expr_ExprError: typeof ExprError;
|
|
357
|
+
type expr_ExprErrorCode = ExprErrorCode;
|
|
358
|
+
type expr_Kind = Kind;
|
|
359
|
+
type expr_Node = Node;
|
|
360
|
+
declare const expr_RESERVED: typeof RESERVED;
|
|
361
|
+
type expr_Scope = Scope;
|
|
362
|
+
type expr_Slot = Slot;
|
|
363
|
+
declare const expr_absent: typeof absent;
|
|
364
|
+
declare const expr_boolean: typeof boolean;
|
|
365
|
+
declare const expr_compileExpression: typeof compileExpression;
|
|
366
|
+
declare const expr_durationMs: typeof durationMs;
|
|
367
|
+
declare const expr_evaluate: typeof evaluate;
|
|
368
|
+
declare const expr_formatDate: typeof formatDate;
|
|
369
|
+
declare const expr_formatDatetime: typeof formatDatetime;
|
|
370
|
+
declare const expr_parse: typeof parse;
|
|
371
|
+
declare const expr_parseDate: typeof parseDate;
|
|
372
|
+
declare const expr_parseDatetime: typeof parseDatetime;
|
|
373
|
+
declare const expr_unknown: typeof unknown;
|
|
374
|
+
declare namespace expr {
|
|
375
|
+
export { type expr_BusinessDays as BusinessDays, type expr_Calendar as Calendar, type expr_Environment as Environment, type expr_Expect as Expect, expr_ExprError as ExprError, type expr_ExprErrorCode as ExprErrorCode, type expr_Kind as Kind, type expr_Node as Node, expr_RESERVED as RESERVED, type expr_Scope as Scope, type expr_Slot as Slot, type Value$1 as Value, expr_absent as absent, expr_boolean as boolean, expr_compileExpression as compileExpression, expr_durationMs as durationMs, expr_evaluate as evaluate, expr_formatDate as formatDate, expr_formatDatetime as formatDatetime, expr_parse as parse, expr_parseDate as parseDate, expr_parseDatetime as parseDatetime, expr_unknown as unknown };
|
|
326
376
|
}
|
|
327
377
|
|
|
328
|
-
/**
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
view?: View;
|
|
338
|
-
/**
|
|
339
|
-
* The level proven in this conversation. The server may answer with a lower effective level
|
|
340
|
-
* when the source's ceiling is lower; see `response.verification`.
|
|
341
|
-
*/
|
|
342
|
-
verification?: Verification;
|
|
343
|
-
/** Enables the per-conversation cache and the server's pinning of the pack. */
|
|
344
|
-
conversation_id?: string;
|
|
345
|
-
/** For internal agents: the task plays the role of the conversation. */
|
|
346
|
-
task_id?: string;
|
|
347
|
-
/** What the turn is about, so selection can favour relevant history. Up to 2,000 characters. */
|
|
348
|
-
query?: string;
|
|
349
|
-
/** Ask only for what changed since this source last read the subject. */
|
|
350
|
-
delta?: boolean;
|
|
351
|
-
/** The model that will read the pack, so the server can size it for that model's prompt cache. */
|
|
352
|
-
target?: TargetModel;
|
|
353
|
-
}
|
|
354
|
-
/** Per-call options shared by every read method. */
|
|
355
|
-
interface RequestOptions {
|
|
356
|
-
/** Overrides the method's default time budget, in milliseconds. */
|
|
357
|
-
timeout?: number | undefined;
|
|
358
|
-
/** Cancels the wait. A request shared with other callers keeps running for them. */
|
|
359
|
-
signal?: AbortSignal | undefined;
|
|
360
|
-
/** Extra headers, such as a W3C `traceparent`. */
|
|
361
|
-
headers?: Record<string, string> | undefined;
|
|
362
|
-
}
|
|
363
|
-
interface ContextOptions extends RequestOptions {
|
|
364
|
-
/** Pass `false` to skip the per-conversation cache for this call. */
|
|
365
|
-
cache?: boolean | undefined;
|
|
378
|
+
/**
|
|
379
|
+
* Decimals for the amounts the parser reads: `R$ 511,06` is 51106 hundredths, never a float, so every SDK
|
|
380
|
+
* writes and compares the same `"511.06"`. Arithmetic and the written form keep 28 significant digits, as
|
|
381
|
+
* the default context of Python's `decimal` does.
|
|
382
|
+
*/
|
|
383
|
+
/** `digits / 10 ** scale`; a negative scale multiplies. */
|
|
384
|
+
interface Decimal {
|
|
385
|
+
readonly digits: bigint;
|
|
386
|
+
readonly scale: number;
|
|
366
387
|
}
|
|
388
|
+
|
|
367
389
|
/**
|
|
368
|
-
*
|
|
390
|
+
* Offsets, words and sentences of an output, as every part of the claim checker reads them.
|
|
369
391
|
*
|
|
370
|
-
*
|
|
371
|
-
* - `
|
|
372
|
-
*
|
|
373
|
-
*
|
|
374
|
-
* - `none`: nothing was available; `text` is empty and `error` says why.
|
|
392
|
+
* Offsets are Unicode code points (the claim contract spec, section 2). The checker reads a text as one
|
|
393
|
+
* UTF-16 unit per code point (`units`), so every index a regular expression returns is a code point offset.
|
|
394
|
+
* Its patterns read `\w`, `\d`, `\s` and `\b` as Python's `re` does on text (`pattern`): the SDKs and the
|
|
395
|
+
* server's reference checker find the same numbers in the same places.
|
|
375
396
|
*/
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
/** The pack, ready for the system prompt. Empty when there is nothing to inject. */
|
|
380
|
-
text: string;
|
|
381
|
-
/**
|
|
382
|
-
* The parts that change turn by turn and belong at the end of the prompt, after the
|
|
383
|
-
* conversation: the delta and the live turns from other channels. Empty when there are none.
|
|
384
|
-
*/
|
|
385
|
-
suffix: string;
|
|
386
|
-
/** Named values from the pack, for templates that place them individually. */
|
|
387
|
-
variables: Record<string, string>;
|
|
388
|
-
source: ContextSource;
|
|
389
|
-
/** The response this result was built from; `null` when `source` is `none`. */
|
|
390
|
-
response: ContextResponse | null;
|
|
391
|
-
/** What went wrong, when `source` is `fallback` or `none`. */
|
|
392
|
-
error: NiadraError | null;
|
|
393
|
-
}
|
|
397
|
+
/** A start and an end, in code points, end excluded. */
|
|
398
|
+
type Span = readonly [number, number];
|
|
399
|
+
|
|
394
400
|
/**
|
|
395
|
-
*
|
|
396
|
-
*
|
|
397
|
-
*
|
|
401
|
+
* Numbers written in words, in Portuguese, English and Spanish, from zero to the millions: "quinze", "dois
|
|
402
|
+
* mil e quinhentos", "twenty-five", "doscientos treinta". The parser reads them only right before a unit, a
|
|
403
|
+
* currency or a percent word ("quinze dias úteis", "trezentos reais"): a number word alone is never a number,
|
|
404
|
+
* because "um", "one" and "un" are also articles.
|
|
398
405
|
*/
|
|
399
|
-
|
|
406
|
+
|
|
407
|
+
type Language = "pt" | "en" | "es";
|
|
408
|
+
|
|
400
409
|
/**
|
|
401
|
-
*
|
|
402
|
-
*
|
|
403
|
-
*
|
|
410
|
+
* The numbers of an output, read by rules (the claim contract spec, section 5): each one with its class,
|
|
411
|
+
* its normalized value and its span, in Portuguese, English or Spanish.
|
|
412
|
+
*
|
|
413
|
+
* Every number of the text lands in at most one mention, found in this order, and a later step never takes
|
|
414
|
+
* what an earlier one took:
|
|
415
|
+
*
|
|
416
|
+
* 1. labels by shape: a case number, a postal code, a tax id, a phone, a time of day;
|
|
417
|
+
* 2. labels by the word before them: an order, a protocol, a statute's article, a size, a list position;
|
|
418
|
+
* 3. dates: ISO, numeric (day first in `pt` and `es`, month first in `en`), with month names, a month of a
|
|
419
|
+
* year, "dia 20";
|
|
420
|
+
* 4. amounts with what follows or precedes them: money (a currency before or after, a scale like "mil"),
|
|
421
|
+
* percent, duration, dose, quantity, installments ("10x"); written in digits, or in words right before
|
|
422
|
+
* the unit; two of them joined by "a", "to", "-" (or "e", "and", "y" after "entre", "between") make a
|
|
423
|
+
* range;
|
|
424
|
+
* 5. codes that mix letters and digits, and ordinals: labels;
|
|
425
|
+
* 6. the rest: a number with two decimals is money; an integer before a word is a count; five digits or
|
|
426
|
+
* more, a leading zero or a year are labels; anything else is not read.
|
|
427
|
+
*
|
|
428
|
+
* A label is never a claim and is never rewritten.
|
|
404
429
|
*/
|
|
405
|
-
|
|
430
|
+
|
|
431
|
+
declare const LANGUAGES: readonly Language[];
|
|
432
|
+
/** What a number measures; a `label` names something instead. */
|
|
433
|
+
type MentionClass = "money" | "percent" | "date" | "duration" | "quantity" | "count" | "dosage" | "label";
|
|
434
|
+
/** A number's normalized value (the claim contract spec, section 5.3), as vectors and turn records write it. */
|
|
435
|
+
type Value = Readonly<Partial<Record<"amount" | "min" | "max" | "unit" | "date" | "date_from" | "date_to", string>>>;
|
|
436
|
+
interface MentionFields {
|
|
437
|
+
amount?: Decimal;
|
|
438
|
+
low?: Decimal;
|
|
439
|
+
high?: Decimal;
|
|
440
|
+
unit?: string | null;
|
|
441
|
+
date?: string;
|
|
442
|
+
dateFrom?: string;
|
|
443
|
+
dateTo?: string;
|
|
444
|
+
written?: "digits" | "words";
|
|
445
|
+
}
|
|
446
|
+
/** A number of an output: its class, its span in code points and its value. */
|
|
447
|
+
declare class Mention {
|
|
448
|
+
readonly cls: MentionClass;
|
|
449
|
+
readonly start: number;
|
|
450
|
+
readonly end: number;
|
|
451
|
+
/** Decimals as `decimalText` writes them. */
|
|
452
|
+
readonly amount: string | null;
|
|
453
|
+
readonly low: string | null;
|
|
454
|
+
readonly high: string | null;
|
|
455
|
+
readonly unit: string | null;
|
|
456
|
+
readonly date: string | null;
|
|
457
|
+
readonly dateFrom: string | null;
|
|
458
|
+
readonly dateTo: string | null;
|
|
459
|
+
readonly written: "digits" | "words";
|
|
460
|
+
constructor(cls: MentionClass, start: number, end: number, fields?: MentionFields);
|
|
461
|
+
/** The normalized value; a label has none. */
|
|
462
|
+
value(): Value | null;
|
|
463
|
+
get isRange(): boolean;
|
|
464
|
+
}
|
|
465
|
+
/** The numbers of `text` in the language `lang`, in the order they appear; offsets are code points. */
|
|
466
|
+
declare function mentions(text: string, lang: Language): readonly Mention[];
|
|
406
467
|
|
|
407
468
|
/**
|
|
408
|
-
*
|
|
409
|
-
*
|
|
469
|
+
* A number's role, from the words around it (the claim contract spec, section 6): the same R$ 511,06 is a
|
|
470
|
+
* full price, a discounted one or a price per person by what the sentence says next to it.
|
|
471
|
+
*
|
|
472
|
+
* A role's term counts within `WINDOW` words of the number, in the same sentence, and belongs to the nearest
|
|
473
|
+
* number of the same class (to both when two are as near). The nearest term gives the role, and at the same
|
|
474
|
+
* distance a term of the number's own beats one it shares; two terms of different roles still tied leave the
|
|
475
|
+
* number without one, `ambiguous`, which is never approved.
|
|
410
476
|
*/
|
|
411
477
|
|
|
412
|
-
/**
|
|
413
|
-
declare const
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
id?: string | null;
|
|
422
|
-
}
|
|
423
|
-
interface Content {
|
|
424
|
-
type?: "text" | "audio" | "image" | "file";
|
|
425
|
-
text?: string | null;
|
|
426
|
-
/** Reference returned by `/v1/media/uploads`; the media itself never travels in the event. */
|
|
427
|
-
media_ref?: string | null;
|
|
428
|
-
/** Lowercase hex SHA-256 of the media. */
|
|
429
|
-
media_sha256?: string | null;
|
|
430
|
-
transcript?: string | null;
|
|
431
|
-
/** Speech-to-text confidence between 0 and 1. Low-confidence agent turns are not measured. */
|
|
432
|
-
stt_confidence?: number | null;
|
|
433
|
-
}
|
|
434
|
-
interface VoiceInfo {
|
|
435
|
-
ani?: string | null;
|
|
436
|
-
dnis?: string | null;
|
|
437
|
-
trunk?: string | null;
|
|
438
|
-
network_attestation?: "A" | "B" | "C" | null;
|
|
439
|
-
answered_at?: string | null;
|
|
440
|
-
ended_at?: string | null;
|
|
441
|
-
end_reason?: string | null;
|
|
442
|
-
recording_ref?: string | null;
|
|
443
|
-
turn_offset_ms?: number | null;
|
|
444
|
-
}
|
|
478
|
+
/** Words between a number and a term of its role, at most. */
|
|
479
|
+
declare const WINDOW = 6;
|
|
480
|
+
interface Role {
|
|
481
|
+
readonly name: string | null;
|
|
482
|
+
readonly status: "matched" | "ambiguous" | "none";
|
|
483
|
+
}
|
|
484
|
+
/** The role of each of `numbers` (a category's mentions, in order), by the terms of `roles`. */
|
|
485
|
+
declare function rolesOf(text: string, numbers: readonly Mention[], roles: Readonly<Record<string, readonly string[]>>): Role[];
|
|
486
|
+
|
|
445
487
|
/**
|
|
446
|
-
* The
|
|
447
|
-
*
|
|
488
|
+
* The claim check (the claim contract spec, sections 4 to 8): the claims each category detects in an
|
|
489
|
+
* output, their nature, the verdict against what the turn holds, and the action the contract takes for the
|
|
490
|
+
* output's context.
|
|
491
|
+
*
|
|
492
|
+
* Detection: numbers of the category's classes (in a sentence with one of its terms, when it lists terms)
|
|
493
|
+
* that the output asserts (a hedged number, `hedges.ts`, is no claim), each occurrence of a term (when it
|
|
494
|
+
* lists terms and no classes), statute and precedent citations, and the sentences of named document
|
|
495
|
+
* sections. Nature, for a number: `quoted` inside quotation marks; `computed`
|
|
496
|
+
* when the turn holds a value of the same role, or the same value; `model` otherwise. Verdicts that stand
|
|
497
|
+
* (`matched`, `quoted_found`, `anchored`) take no action; `not_checked` is counted; every other one takes the
|
|
498
|
+
* category's action for the context, and `unsupported` the action its natures give to what the model said.
|
|
499
|
+
* A rewrite happens only when it is unequivocal (a stale copy of one field whose fresh value differs), and
|
|
500
|
+
* is a warning otherwise. Nothing is ever rewritten in an immutable output, and a block there sends the
|
|
501
|
+
* whole output to a person, untouched.
|
|
448
502
|
*/
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
/**
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
503
|
+
|
|
504
|
+
type Verdict = ClaimRecord["verdict"];
|
|
505
|
+
/** What happened to a claim, as the turn record writes it. */
|
|
506
|
+
type Action = ClaimRecord["action"];
|
|
507
|
+
type Nature = NonNullable<ClaimRecord["nature"]>;
|
|
508
|
+
/** A value with provenance the turn holds: a field of a tool's result or of a state read. */
|
|
509
|
+
interface TurnValue {
|
|
510
|
+
readonly cls: MentionClass;
|
|
511
|
+
/** As `Mention.value()` writes it. */
|
|
512
|
+
readonly value: Value;
|
|
513
|
+
readonly role?: string | null;
|
|
514
|
+
/** True unless said otherwise. */
|
|
515
|
+
readonly fresh?: boolean;
|
|
516
|
+
readonly objectType?: string | null;
|
|
517
|
+
/** The field or computed value it is. */
|
|
518
|
+
readonly name?: string | null;
|
|
519
|
+
readonly callId?: string | null;
|
|
520
|
+
readonly ref?: string | null;
|
|
521
|
+
readonly declaredGaps?: readonly string[];
|
|
522
|
+
}
|
|
523
|
+
/** A passage an output cites, as the tool or the agent emitted it: where, what it quotes, from what. */
|
|
524
|
+
interface Anchor {
|
|
525
|
+
readonly start: number;
|
|
526
|
+
readonly end: number;
|
|
527
|
+
readonly quote: string;
|
|
528
|
+
readonly document: string;
|
|
529
|
+
}
|
|
530
|
+
/** What the turn holds to check an output against. */
|
|
531
|
+
interface Turn {
|
|
532
|
+
readonly values?: readonly TurnValue[];
|
|
533
|
+
/** The tools called in the turn. */
|
|
534
|
+
readonly tools?: readonly string[];
|
|
535
|
+
/** The documents in hand, by id: what quotes and anchors are checked against. */
|
|
536
|
+
readonly documents?: Readonly<Record<string, string>>;
|
|
537
|
+
readonly anchors?: readonly Anchor[];
|
|
538
|
+
/** The output's named sections, as spans, when it is a document. */
|
|
539
|
+
readonly sections?: Readonly<Record<string, readonly Span[]>>;
|
|
540
|
+
}
|
|
541
|
+
/** One claim a category found, its verdict and what happened to it. */
|
|
542
|
+
interface Finding {
|
|
543
|
+
readonly category: string;
|
|
544
|
+
readonly start: number;
|
|
545
|
+
readonly end: number;
|
|
546
|
+
readonly verdict: Verdict;
|
|
547
|
+
readonly action: Action;
|
|
548
|
+
/** For a number. */
|
|
549
|
+
readonly cls: MentionClass | null;
|
|
550
|
+
readonly nature: Nature | null;
|
|
551
|
+
readonly role: string | null;
|
|
552
|
+
readonly value: Value | null;
|
|
553
|
+
readonly evidence: TurnValue | Anchor | null;
|
|
554
|
+
}
|
|
555
|
+
/** The text the check reads, in its language and context (`chat`, `proposal`, `contestacao`). */
|
|
556
|
+
interface Output {
|
|
557
|
+
readonly text: string;
|
|
558
|
+
readonly lang: Language;
|
|
559
|
+
readonly context: string;
|
|
560
|
+
readonly immutable: boolean;
|
|
561
|
+
readonly agent?: string | null;
|
|
462
562
|
}
|
|
463
563
|
/**
|
|
464
|
-
*
|
|
465
|
-
*
|
|
466
|
-
* it had and did not use.
|
|
564
|
+
* The same number: equal amounts (or ends of a range), or the same date; a unit only counts when both have
|
|
565
|
+
* one, so "511,06" is the R$ 511,06 of a tool's result.
|
|
467
566
|
*/
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
channel: string;
|
|
479
|
-
conversation_id?: string | null;
|
|
480
|
-
conversation_aliases?: string[];
|
|
481
|
-
task_id?: string | null;
|
|
482
|
-
handles?: Handle[];
|
|
483
|
-
subjects?: Subject[];
|
|
484
|
-
object_refs?: ObjectRef[];
|
|
485
|
-
speaker: SpeakerRef;
|
|
486
|
-
direction?: "inbound" | "outbound" | null;
|
|
487
|
-
content?: Content | null;
|
|
488
|
-
occurred_at: string;
|
|
489
|
-
visibility?: Visibility;
|
|
490
|
-
verification_hint?: Verification | null;
|
|
491
|
-
/** System events only, such as `invoice.credited`. */
|
|
492
|
-
canonical_type?: string | null;
|
|
493
|
-
/** Structured fields of a system event. */
|
|
494
|
-
fields?: Record<string, unknown>;
|
|
495
|
-
action?: ActionInfo | null;
|
|
496
|
-
corrects_event_id?: string | null;
|
|
497
|
-
voice?: VoiceInfo | null;
|
|
498
|
-
context_stamp?: ContextStamp | null;
|
|
499
|
-
}
|
|
500
|
-
/** States that several handles belong to the same subject. */
|
|
501
|
-
interface IdentifyItem {
|
|
502
|
-
type: "identify";
|
|
503
|
-
idempotency_key: string;
|
|
504
|
-
/** Between 2 and 16 handles. */
|
|
505
|
-
handles: Handle[];
|
|
506
|
-
method: AssertionMethod;
|
|
507
|
-
subject_kind: SubjectKind;
|
|
508
|
-
conversation_id?: string | null;
|
|
509
|
-
occurred_at: string;
|
|
510
|
-
}
|
|
511
|
-
/** Raises the verification level of one conversation or task. The server never infers it. */
|
|
512
|
-
interface VerifyItem {
|
|
513
|
-
type: "verify";
|
|
514
|
-
idempotency_key: string;
|
|
515
|
-
method: VerifyMethod;
|
|
516
|
-
level: Verification;
|
|
517
|
-
conversation_id?: string | null;
|
|
518
|
-
task_id?: string | null;
|
|
519
|
-
handle: Handle;
|
|
520
|
-
valid_until?: string | null;
|
|
521
|
-
occurred_at: string;
|
|
522
|
-
}
|
|
523
|
-
interface ConversationEndedItem {
|
|
524
|
-
type: "conversation.ended";
|
|
525
|
-
idempotency_key: string;
|
|
526
|
-
conversation_id: string;
|
|
527
|
-
occurred_at: string;
|
|
528
|
-
}
|
|
529
|
-
interface TaskEndedItem {
|
|
530
|
-
type: "task.ended";
|
|
531
|
-
idempotency_key: string;
|
|
532
|
-
task_id: string;
|
|
533
|
-
occurred_at: string;
|
|
534
|
-
}
|
|
535
|
-
/** A transfer to a human or another agent. */
|
|
536
|
-
interface HandoffItem {
|
|
537
|
-
type: "handoff";
|
|
538
|
-
idempotency_key: string;
|
|
539
|
-
conversation_id: string;
|
|
540
|
-
target: "human" | "agent";
|
|
541
|
-
target_source?: string | null;
|
|
542
|
-
reason?: string | null;
|
|
543
|
-
mode: "warm" | "cold";
|
|
544
|
-
occurred_at: string;
|
|
545
|
-
}
|
|
546
|
-
/** Periodic counter the SDK sends so the server can tell a quiet source from a broken one. */
|
|
547
|
-
interface HeartbeatItem {
|
|
548
|
-
type: "heartbeat";
|
|
549
|
-
window_start: string;
|
|
550
|
-
sent: number;
|
|
551
|
-
}
|
|
552
|
-
type BatchItem = EventItem | IdentifyItem | VerifyItem | ConversationEndedItem | TaskEndedItem | HandoffItem | HeartbeatItem;
|
|
553
|
-
interface BatchRequest {
|
|
554
|
-
items: BatchItem[];
|
|
555
|
-
}
|
|
556
|
-
interface ItemError {
|
|
557
|
-
/** Position of the rejected item in the batch that was sent. */
|
|
558
|
-
index: number;
|
|
559
|
-
code: string;
|
|
560
|
-
detail?: string | null;
|
|
561
|
-
}
|
|
562
|
-
interface BatchResponse {
|
|
563
|
-
accepted: number;
|
|
564
|
-
duplicates: number;
|
|
565
|
-
errors: ItemError[];
|
|
566
|
-
}
|
|
567
|
-
/** Body of `POST /v1/media/uploads`. */
|
|
568
|
-
interface MediaUploadRequest {
|
|
569
|
-
content_type: string;
|
|
570
|
-
/** Between 1 byte and 500 MiB. */
|
|
571
|
-
size_bytes: number;
|
|
572
|
-
/** Lowercase hex SHA-256 of the bytes. */
|
|
573
|
-
sha256: string;
|
|
574
|
-
/** Whose media it is. Stored under that person, so erasing them erases it too. */
|
|
575
|
-
subject?: Handle | null;
|
|
576
|
-
}
|
|
577
|
-
/** Where to send the bytes: a short-lived signed URL, and the reference events carry afterwards. */
|
|
578
|
-
interface MediaUploadResponse {
|
|
579
|
-
media_ref: string;
|
|
580
|
-
upload_url: string;
|
|
581
|
-
/** Send exactly these headers with the bytes; the store refuses anything else. */
|
|
582
|
-
upload_headers?: Record<string, string>;
|
|
583
|
-
expires_at: string;
|
|
584
|
-
}
|
|
585
|
-
type FeedbackAction = "retract_fact" | "correct_fact" | "resolve_open_item" | "conversation_outcome";
|
|
586
|
-
/** Body of `POST /v1/feedback`. The server records it as a `feedback.<action>` system event. */
|
|
587
|
-
interface FeedbackRequest {
|
|
588
|
-
idempotency_key: string;
|
|
589
|
-
subject: Handle;
|
|
590
|
-
action: FeedbackAction;
|
|
591
|
-
fact_id?: string | null;
|
|
592
|
-
open_item_id?: string | null;
|
|
593
|
-
conversation_id?: string | null;
|
|
594
|
-
/** Up to 2,000 characters. */
|
|
595
|
-
value?: string | null;
|
|
596
|
-
/** Up to 500 characters. */
|
|
597
|
-
reason?: string | null;
|
|
598
|
-
}
|
|
567
|
+
declare function sameValue(a: Value, b: Value): boolean;
|
|
568
|
+
/**
|
|
569
|
+
* `quoted` inside quotation marks; `computed` when the turn holds a value of the number's class with its
|
|
570
|
+
* role or its value; `model` otherwise.
|
|
571
|
+
*/
|
|
572
|
+
declare function natureOf(text: string, mention: Mention, role: Role, values: readonly TurnValue[]): Nature;
|
|
573
|
+
/** Every claim of `output` that a category detects, in the contract's order and then the text's. */
|
|
574
|
+
declare function check(categories: readonly ClaimCategory[], output: Output, turn?: Turn): Finding[];
|
|
575
|
+
/** The categories that detect anything in `output`: what a phrase of the negative corpus must never trigger. */
|
|
576
|
+
declare function detected(categories: readonly ClaimCategory[], output: Output): string[];
|
|
599
577
|
|
|
600
578
|
/**
|
|
601
|
-
*
|
|
602
|
-
*
|
|
603
|
-
*
|
|
579
|
+
* Hedges (the claim contract spec, section 5.4): a number the output says it cannot confirm, says as a value
|
|
580
|
+
* that no longer holds, or doubts, is not asserted, and no category detects it. "Não consigo confirmar se o
|
|
581
|
+
* frete de R$ 24,90 ainda vale" states no price.
|
|
582
|
+
*
|
|
583
|
+
* A number's clause is its sentence cut at clause breaks: a comma, semicolon or colon before a space, a
|
|
584
|
+
* parenthesis, a dash, and the clause words ("mas", "but", "porque"). A break inside a number does not count.
|
|
585
|
+
* A number is hedged when:
|
|
586
|
+
*
|
|
587
|
+
* 1. a denial stands before it in its clause ("não consigo confirmar", "I can't confirm", "whether");
|
|
588
|
+
* 2. it is the number of its clause nearest to a past marker ("o valor anterior", "previously listed"), on
|
|
589
|
+
* either side, within `WINDOW` words, with no word of the present between them ("now", "agora");
|
|
590
|
+
* 3. it is the number of its clause nearest before a doubt ("pode ter mudado", "has changed"), within
|
|
591
|
+
* `WINDOW` words;
|
|
592
|
+
* 4. its clause follows one that is only an opener ("Antes, ele estava em R$ 1.240,00");
|
|
593
|
+
* 5. its clause holds a past word ("foi", "was", "on file"), and a later clause of its sentence holds a
|
|
594
|
+
* denial followed by a word of continuity ("mas não consigo confirmar se esse total continua igual");
|
|
595
|
+
* 6. a negation stands right before it ("$689.00 per month, not $612.00").
|
|
596
|
+
*
|
|
597
|
+
* A hedge that governs something else leaves the number asserted: "O total é R$ 500, mas não consigo
|
|
598
|
+
* confirmar o prazo" states R$ 500. The words match whole words of the folded text, in sequence, with both
|
|
599
|
+
* apostrophes alike, and never inside a number.
|
|
604
600
|
*/
|
|
605
601
|
|
|
606
|
-
/**
|
|
607
|
-
|
|
608
|
-
/** Fields shared by everything `track()` records. */
|
|
609
|
-
interface EventBase {
|
|
610
|
-
/** Where it happened, such as `whatsapp`, `voice`, `app` or `erp`. */
|
|
611
|
-
channel: string;
|
|
612
|
-
/** Provider message id, when there is one; otherwise the SDK mints a UUIDv7. */
|
|
613
|
-
idempotency_key?: string;
|
|
614
|
-
conversation_id?: string | null;
|
|
615
|
-
/** Other ids the same conversation has in other systems. Up to 8. */
|
|
616
|
-
conversation_aliases?: string[];
|
|
617
|
-
task_id?: string | null;
|
|
618
|
-
/** Up to 16. An event needs at least one handle, subject or object. */
|
|
619
|
-
handles?: Handle[];
|
|
620
|
-
/** Up to 8. */
|
|
621
|
-
subjects?: Subject[];
|
|
622
|
-
/** Up to 16. Accepts `type:namespace:id` strings. */
|
|
623
|
-
object_refs?: (ObjectRef | string)[];
|
|
624
|
-
/** Defaults to now. */
|
|
625
|
-
occurred_at?: Timestamp;
|
|
626
|
-
visibility?: Visibility;
|
|
627
|
-
verification_hint?: Verification | null;
|
|
628
|
-
corrects_event_id?: string | null;
|
|
629
|
-
voice?: VoiceInfo | null;
|
|
630
|
-
/**
|
|
631
|
-
* Which context the agent acted on, for the agent's own turns and actions. Conversations and
|
|
632
|
-
* tasks set it from `markInjected()`.
|
|
633
|
-
*/
|
|
634
|
-
context_stamp?: ContextStamp | null;
|
|
635
|
-
}
|
|
636
|
-
/** An event for `track()`. `kind` defaults to `message`. */
|
|
637
|
-
interface TrackEvent extends EventBase {
|
|
638
|
-
kind?: EventKind;
|
|
639
|
-
/** Who produced it. A bare role is shorthand for `{ role }`. */
|
|
640
|
-
speaker: SpeakerRef | Speaker;
|
|
641
|
-
/** Defaults to `inbound` for customer messages and `outbound` for agent messages. */
|
|
642
|
-
direction?: "inbound" | "outbound" | null;
|
|
643
|
-
content?: Content | null;
|
|
644
|
-
/** Shorthand for `content: { type: "text", text }`. Cannot be combined with `content`. */
|
|
645
|
-
text?: string;
|
|
646
|
-
/** Required for `system_event`, such as `invoice.credited`. */
|
|
647
|
-
canonical_type?: string | null;
|
|
648
|
-
fields?: Record<string, unknown>;
|
|
649
|
-
/** Required for `action`, and only valid there. */
|
|
650
|
-
action?: ActionInfo | null;
|
|
651
|
-
}
|
|
652
|
-
/** An agent action for `action()`: what an agent did in a system of record. */
|
|
653
|
-
interface ActionEvent extends EventBase {
|
|
654
|
-
/** Canonical operation, such as `credit` or `reschedule`. */
|
|
655
|
-
operation: string;
|
|
656
|
-
/** What happened, up to 2,000 characters. */
|
|
657
|
-
result?: string | null;
|
|
658
|
-
purpose?: string | null;
|
|
659
|
-
/** The open item this action fulfils, which the server then marks resolved. */
|
|
660
|
-
closes?: Closes | null;
|
|
661
|
-
corrects_action_id?: string | null;
|
|
662
|
-
/** Defaults to `ai_agent`. */
|
|
663
|
-
speaker?: SpeakerRef | Speaker;
|
|
664
|
-
}
|
|
665
|
-
interface IdentifyParams {
|
|
666
|
-
/** Between 2 and 16 handles that belong to the same subject. */
|
|
667
|
-
handles: Handle[];
|
|
668
|
-
/** Defaults to `explicit_identify`. */
|
|
669
|
-
method?: AssertionMethod;
|
|
670
|
-
/** Defaults to `person`. */
|
|
671
|
-
subject_kind?: SubjectKind;
|
|
672
|
-
conversation_id?: string | null;
|
|
673
|
-
occurred_at?: Timestamp;
|
|
674
|
-
idempotency_key?: string;
|
|
675
|
-
}
|
|
676
|
-
interface VerifyParams {
|
|
677
|
-
/** The handle whose possession was proven. */
|
|
678
|
-
handle: Handle;
|
|
679
|
-
method: VerifyMethod;
|
|
680
|
-
/** The level reached. It applies to this conversation or task only. */
|
|
681
|
-
level: Verification;
|
|
682
|
-
conversation_id?: string | null;
|
|
683
|
-
task_id?: string | null;
|
|
684
|
-
/** When the proof stops counting. */
|
|
685
|
-
valid_until?: Timestamp | null;
|
|
686
|
-
occurred_at?: Timestamp;
|
|
687
|
-
idempotency_key?: string;
|
|
688
|
-
}
|
|
689
|
-
interface HandoffParams {
|
|
690
|
-
conversation_id: string;
|
|
691
|
-
target: "human" | "agent";
|
|
692
|
-
/** The source that takes over, when it is integrated with Niadra. */
|
|
693
|
-
target_source?: string | null;
|
|
694
|
-
reason?: string | null;
|
|
695
|
-
/** `warm` when the receiver gets a briefing. Defaults to `warm`. */
|
|
696
|
-
mode?: "warm" | "cold";
|
|
697
|
-
occurred_at?: Timestamp;
|
|
698
|
-
idempotency_key?: string;
|
|
699
|
-
}
|
|
700
|
-
/** Arguments of `feedback()`: a correction of what Niadra derived about a subject. */
|
|
701
|
-
interface FeedbackParams {
|
|
702
|
-
subject: Handle;
|
|
703
|
-
/**
|
|
704
|
-
* `retract_fact` or `correct_fact` (with `fact_id`, and `value` for the right one),
|
|
705
|
-
* `resolve_open_item` (with `open_item_id`) or `conversation_outcome` (with `conversation_id`
|
|
706
|
-
* and `value`).
|
|
707
|
-
*/
|
|
708
|
-
action: FeedbackAction;
|
|
709
|
-
fact_id?: string | null;
|
|
710
|
-
open_item_id?: string | null;
|
|
711
|
-
conversation_id?: string | null;
|
|
712
|
-
/** Up to 2,000 characters. */
|
|
713
|
-
value?: string | null;
|
|
714
|
-
/** Why, up to 500 characters. */
|
|
715
|
-
reason?: string | null;
|
|
716
|
-
idempotency_key?: string;
|
|
717
|
-
}
|
|
602
|
+
/** The numbers of `numbers` (the output's mentions that are not labels) the output does not assert. */
|
|
603
|
+
declare function hedged(text: string, numbers: readonly Mention[]): ReadonlySet<Mention>;
|
|
718
604
|
|
|
719
605
|
/**
|
|
720
|
-
*
|
|
721
|
-
*
|
|
606
|
+
* The text anchor (the claim contract spec, section 9): how closely a quoted passage matches the document
|
|
607
|
+
* it cites.
|
|
608
|
+
*
|
|
609
|
+
* Both texts are normalized the same way: lower case, no accents, every run of anything but letters and
|
|
610
|
+
* digits one space, trimmed. The score is `1 - d / len(quote)`, where `d` is the fewest insertions, deletions
|
|
611
|
+
* and substitutions that turn the quote into some passage of the document (any start, any end), and an anchor
|
|
612
|
+
* holds at 0.90 or above. The distance runs as Myers' bit-parallel algorithm, linear in the document's length.
|
|
722
613
|
*/
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
/**
|
|
729
|
-
declare
|
|
730
|
-
declare const silentLogger: Logger;
|
|
614
|
+
/** An anchor holds at this score or above; a contract may ask for more, never less. */
|
|
615
|
+
declare const MIN_ANCHOR_MATCH = 0.9;
|
|
616
|
+
declare function normalize$1(text: string): string;
|
|
617
|
+
/** The edit distance between `pattern` and the passage of `text` nearest to it. */
|
|
618
|
+
declare function distance(pattern: string, text: string): number;
|
|
619
|
+
/** 1 when the normalized quote is a passage of the normalized document; 0 for an empty quote. */
|
|
620
|
+
declare function score(quote: string, document: string): number;
|
|
731
621
|
|
|
732
|
-
/**
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
622
|
+
/**
|
|
623
|
+
* The claim contract's reference checker (`spec/claim-contract.md`), pure and without a model: the number and
|
|
624
|
+
* role parser, the hedges (a number the output does not assert), the category detection, the natures, verdicts
|
|
625
|
+
* and actions, and the text anchor. It passes the same conformance vectors as the server's and the Python
|
|
626
|
+
* SDK's (`spec/vectors/claim-*.v0.json`).
|
|
627
|
+
*/
|
|
737
628
|
|
|
738
|
-
|
|
739
|
-
type
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
629
|
+
type index_Action = Action;
|
|
630
|
+
type index_Anchor = Anchor;
|
|
631
|
+
type index_Finding = Finding;
|
|
632
|
+
declare const index_InternalText: typeof InternalText;
|
|
633
|
+
declare const index_LANGUAGES: typeof LANGUAGES;
|
|
634
|
+
type index_Language = Language;
|
|
635
|
+
declare const index_MIN_ANCHOR_MATCH: typeof MIN_ANCHOR_MATCH;
|
|
636
|
+
type index_Mention = Mention;
|
|
637
|
+
declare const index_Mention: typeof Mention;
|
|
638
|
+
type index_MentionClass = MentionClass;
|
|
639
|
+
type index_Nature = Nature;
|
|
640
|
+
type index_Output = Output;
|
|
641
|
+
type index_Role = Role;
|
|
642
|
+
type index_Span = Span;
|
|
643
|
+
type index_Turn = Turn;
|
|
644
|
+
type index_TurnValue = TurnValue;
|
|
645
|
+
type index_Value = Value;
|
|
646
|
+
type index_Verdict = Verdict;
|
|
647
|
+
declare const index_WINDOW: typeof WINDOW;
|
|
648
|
+
declare const index_check: typeof check;
|
|
649
|
+
declare const index_detected: typeof detected;
|
|
650
|
+
declare const index_distance: typeof distance;
|
|
651
|
+
declare const index_hedged: typeof hedged;
|
|
652
|
+
declare const index_mentions: typeof mentions;
|
|
653
|
+
declare const index_natureOf: typeof natureOf;
|
|
654
|
+
declare const index_rolesOf: typeof rolesOf;
|
|
655
|
+
declare const index_sameValue: typeof sameValue;
|
|
656
|
+
declare const index_score: typeof score;
|
|
657
|
+
declare const index_shingles: typeof shingles;
|
|
658
|
+
declare namespace index {
|
|
659
|
+
export { type index_Action as Action, type index_Anchor as Anchor, type index_Finding as Finding, index_InternalText as InternalText, index_LANGUAGES as LANGUAGES, type index_Language as Language, index_MIN_ANCHOR_MATCH as MIN_ANCHOR_MATCH, index_Mention as Mention, type index_MentionClass as MentionClass, type index_Nature as Nature, type index_Output as Output, type index_Role as Role, type index_Span as Span, type index_Turn as Turn, type index_TurnValue as TurnValue, type index_Value as Value, type index_Verdict as Verdict, index_WINDOW as WINDOW, index_check as check, index_detected as detected, index_distance as distance, index_hedged as hedged, index_mentions as mentions, index_natureOf as natureOf, normalize$1 as normalize, index_rolesOf as rolesOf, index_sameValue as sameValue, index_score as score, index_shingles as shingles };
|
|
754
660
|
}
|
|
661
|
+
|
|
755
662
|
/**
|
|
756
|
-
*
|
|
663
|
+
* A type derived from the company's own PostgreSQL schema (the object type spec, section 8), inside the
|
|
664
|
+
* company's boundary: the catalog is read, never a row, and neither the catalog nor the proposal leaves.
|
|
757
665
|
*
|
|
758
|
-
*
|
|
759
|
-
*
|
|
760
|
-
*
|
|
666
|
+
* `derive()` turns one table's catalog into a proposed type, with the fingerprint of what it read and the
|
|
667
|
+
* review a person must do before the proposal goes up as a configuration change: triggers are code, and a
|
|
668
|
+
* CHECK that is not a list of values is not read. `changes()` is the drift report `niadra types derive
|
|
669
|
+
* --check` sends with the fingerprint: counts, and the names the declaration already holds, never the schema.
|
|
670
|
+
* It passes the spec's vectors (`spec/vectors/type-derive.v0.json`), as the Python SDK does.
|
|
761
671
|
*/
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
672
|
+
type Json$2 = Record<string, unknown>;
|
|
673
|
+
/** A column as the catalog read lists it. */
|
|
674
|
+
interface CatalogColumn {
|
|
675
|
+
name: string;
|
|
676
|
+
type: string;
|
|
677
|
+
not_null: boolean;
|
|
678
|
+
enum?: string;
|
|
679
|
+
}
|
|
680
|
+
/** One table's catalog: its columns, keys, checks, enumerations and triggers, never a row. */
|
|
681
|
+
interface Catalog {
|
|
682
|
+
catalog: string;
|
|
683
|
+
table: string;
|
|
684
|
+
columns: CatalogColumn[];
|
|
685
|
+
primary_key: string[];
|
|
686
|
+
checks: string[];
|
|
687
|
+
enums: {
|
|
688
|
+
name: string;
|
|
689
|
+
labels: string[];
|
|
690
|
+
}[];
|
|
691
|
+
foreign_keys: {
|
|
692
|
+
columns: string[];
|
|
693
|
+
references: string;
|
|
694
|
+
referenced_columns: string[];
|
|
695
|
+
}[];
|
|
696
|
+
triggers: {
|
|
697
|
+
name: string;
|
|
698
|
+
definition: string;
|
|
699
|
+
enabled: boolean;
|
|
700
|
+
}[];
|
|
701
|
+
}
|
|
702
|
+
interface DeriveOptions {
|
|
703
|
+
/** The type's name; the table's by default. */
|
|
704
|
+
type?: string;
|
|
705
|
+
/** The system the type mirrors; `postgresql` by default. */
|
|
706
|
+
system?: string;
|
|
707
|
+
/** `subject` (the default) or `shared`: an agent's working state is never derived. */
|
|
708
|
+
ownership?: string;
|
|
709
|
+
}
|
|
710
|
+
/** A proposed type (it validates against `object-type.v0`), its catalog's fingerprint, and the review. */
|
|
711
|
+
interface Derived {
|
|
712
|
+
type: Json$2;
|
|
713
|
+
fingerprint: string;
|
|
714
|
+
review: Json$2[];
|
|
715
|
+
}
|
|
716
|
+
/** The counts `--check` sends with the fingerprint, and the declared fields they touch. */
|
|
717
|
+
interface Changes {
|
|
718
|
+
fields_added: number;
|
|
719
|
+
fields_removed: number;
|
|
720
|
+
fields_retyped: number;
|
|
721
|
+
states_added: number;
|
|
722
|
+
states_removed: number;
|
|
723
|
+
relations_added: number;
|
|
724
|
+
relations_removed: number;
|
|
725
|
+
key_changed: boolean;
|
|
726
|
+
fields: string[];
|
|
727
|
+
}
|
|
728
|
+
/** A catalog or an option the derivation refuses, named by `code`. */
|
|
729
|
+
declare class DeriveError extends Error {
|
|
730
|
+
readonly code: string;
|
|
731
|
+
constructor(code: string, message: string);
|
|
774
732
|
}
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
733
|
+
/** The catalog in the order the fingerprint hashes (section 8.2), every order by UTF-16 code units. */
|
|
734
|
+
declare function normalize(catalog: Catalog): Catalog;
|
|
735
|
+
/** `sha256:<hex>` over the canonical JSON of the normalized catalog (section 8.3). */
|
|
736
|
+
declare function fingerprint(catalog: Catalog): Promise<string>;
|
|
737
|
+
/**
|
|
738
|
+
* A catalog name as a name of the type (section 8.5): A to Z lowercased, every other code point outside
|
|
739
|
+
* `[a-z0-9_]` one `_`, `c_` before a name that does not start with a letter, cut at `limit`, and `_` after a
|
|
740
|
+
* reserved word.
|
|
741
|
+
*/
|
|
742
|
+
declare function toName(raw: string, limit?: number): string;
|
|
743
|
+
/** The proposed type of one table (section 8.4). */
|
|
744
|
+
declare function derive(catalog: Catalog, options?: DeriveOptions): Promise<Derived>;
|
|
745
|
+
/**
|
|
746
|
+
* What differs between the declaration and the type the live catalog derives (section 8.8): counts, and the
|
|
747
|
+
* declared fields the difference touches. Never a new name, a value or a definition.
|
|
748
|
+
*/
|
|
749
|
+
declare function changes(declared: Json$2, live: Json$2): Changes;
|
|
750
|
+
/**
|
|
751
|
+
* The column and the values of a CHECK that holds a column to a list, as `pg_get_constraintdef` writes it
|
|
752
|
+
* (section 8.6): `CHECK ((status = ANY (ARRAY['open'::text, 'paid'::text])))`, the same with a cast of the
|
|
753
|
+
* column and of the array, or `CHECK ((status = 'open'::text))`. Anything else is null.
|
|
754
|
+
*/
|
|
755
|
+
declare function listCheck(definition: string): [string, unknown[]] | null;
|
|
781
756
|
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
}
|
|
797
|
-
/** Optional details of one captured turn. */
|
|
798
|
-
interface TurnOptions {
|
|
799
|
-
/** The provider's message id, which makes retries of the same turn harmless. */
|
|
800
|
-
idempotency_key?: string;
|
|
801
|
-
occurred_at?: Timestamp;
|
|
802
|
-
/** The agent or attendant id inside your system. */
|
|
803
|
-
speaker_id?: string;
|
|
804
|
-
visibility?: Visibility;
|
|
805
|
-
/** Marks the text as a speech-to-text transcript with this confidence, between 0 and 1. */
|
|
806
|
-
stt_confidence?: number;
|
|
807
|
-
voice?: VoiceInfo;
|
|
808
|
-
/** Overrides the stamp an agent turn would carry from `markInjected()`. */
|
|
809
|
-
context_stamp?: ContextStamp;
|
|
810
|
-
}
|
|
811
|
-
type ConversationEvent = Omit<TrackEvent, "channel" | "conversation_id"> & {
|
|
812
|
-
channel?: string;
|
|
813
|
-
};
|
|
814
|
-
type ConversationAction = Omit<ActionEvent, "channel" | "conversation_id"> & {
|
|
815
|
-
channel?: string;
|
|
816
|
-
};
|
|
817
|
-
interface ConversationHooks {
|
|
818
|
-
endConversation(id: string): Promise<WriteResult>;
|
|
757
|
+
type derive$1_Catalog = Catalog;
|
|
758
|
+
type derive$1_CatalogColumn = CatalogColumn;
|
|
759
|
+
type derive$1_Changes = Changes;
|
|
760
|
+
type derive$1_DeriveError = DeriveError;
|
|
761
|
+
declare const derive$1_DeriveError: typeof DeriveError;
|
|
762
|
+
type derive$1_DeriveOptions = DeriveOptions;
|
|
763
|
+
type derive$1_Derived = Derived;
|
|
764
|
+
declare const derive$1_changes: typeof changes;
|
|
765
|
+
declare const derive$1_derive: typeof derive;
|
|
766
|
+
declare const derive$1_fingerprint: typeof fingerprint;
|
|
767
|
+
declare const derive$1_listCheck: typeof listCheck;
|
|
768
|
+
declare const derive$1_normalize: typeof normalize;
|
|
769
|
+
declare const derive$1_toName: typeof toName;
|
|
770
|
+
declare namespace derive$1 {
|
|
771
|
+
export { type derive$1_Catalog as Catalog, type derive$1_CatalogColumn as CatalogColumn, type derive$1_Changes as Changes, derive$1_DeriveError as DeriveError, type derive$1_DeriveOptions as DeriveOptions, type derive$1_Derived as Derived, derive$1_changes as changes, derive$1_derive as derive, derive$1_fingerprint as fingerprint, derive$1_listCheck as listCheck, derive$1_normalize as normalize, derive$1_toName as toName };
|
|
819
772
|
}
|
|
773
|
+
|
|
820
774
|
/**
|
|
821
|
-
*
|
|
775
|
+
* The canonical destination of a handle and its key per reader (`spec/suppression-list.md`, sections 3
|
|
776
|
+
* and 4).
|
|
822
777
|
*
|
|
823
|
-
*
|
|
824
|
-
*
|
|
825
|
-
*
|
|
826
|
-
*
|
|
827
|
-
* conversation keeps them, in order, in `suffix`, with the live turns, for the end of the
|
|
828
|
-
* prompt. A successful `verify()` starts over from the pack the server pins for the new level.
|
|
778
|
+
* A phone number, a WhatsApp id and an e-mail address each have one canonical form, `phone:+<E.164>` or
|
|
779
|
+
* `email:<address>`. The suppression list keys it with each reader's salt, and the contact token carries it
|
|
780
|
+
* keyed with the gateway's key as `rcpt` (`spec/contact-token.md`, section 4.1), so a reader matches the
|
|
781
|
+
* destination it is about to contact without the list ever carrying a handle.
|
|
829
782
|
*
|
|
830
|
-
*
|
|
831
|
-
* carry that moment and the pack's etag as `context_stamp`. `wrap()` does it for you.
|
|
832
|
-
*
|
|
833
|
-
* @example
|
|
834
|
-
* const convo = niadra.conversation({ subject: handles.waId("5511987654321"), channel: "whatsapp" });
|
|
835
|
-
* convo.customer(inbound.text, { idempotency_key: inbound.id });
|
|
836
|
-
* const ctx = await convo.context();
|
|
837
|
-
* convo.markInjected(ctx);
|
|
838
|
-
* const reply = await llm(ctx.text, history, ctx.suffix);
|
|
839
|
-
* convo.agent(reply);
|
|
783
|
+
* The same rules as the Python SDK's `niadra.coordination.destination`.
|
|
840
784
|
*/
|
|
841
|
-
declare class Conversation {
|
|
842
|
-
private readonly client;
|
|
843
|
-
private readonly params;
|
|
844
|
-
private readonly hooks;
|
|
845
|
-
readonly id: string;
|
|
846
|
-
readonly channel: string;
|
|
847
|
-
readonly subject: Handle;
|
|
848
|
-
private level;
|
|
849
|
-
private readonly view;
|
|
850
|
-
private readonly state;
|
|
851
|
-
private ending;
|
|
852
|
-
constructor(client: Niadra, params: ConversationParams, hooks: ConversationHooks);
|
|
853
|
-
/** The level in force for this conversation, raised by a successful `verify()`. */
|
|
854
|
-
get verification(): Verification;
|
|
855
|
-
/**
|
|
856
|
-
* When context first went into the prompt, and when the agent first spoke. Context injected
|
|
857
|
-
* after the agent's first turn is the "late context" signal the usage measurement reports.
|
|
858
|
-
*/
|
|
859
|
-
get timings(): Timings;
|
|
860
|
-
/** What the agent's next turn and action carry: the last `markInjected()`, or `null`. */
|
|
861
|
-
get contextStamp(): ContextStamp | null;
|
|
862
|
-
/** The last result `context()` returned for this conversation. */
|
|
863
|
-
get lastContext(): ContextResult | null;
|
|
864
|
-
/** Where `wrap()` reports what it swallowed: the client's logger. */
|
|
865
|
-
get logger(): Logger;
|
|
866
|
-
/**
|
|
867
|
-
* The pack for this turn: the pinned `text`, and a `suffix` with every delta since the pin
|
|
868
|
-
* and the current live turns. A read with `query` is compiled for that query and never
|
|
869
|
-
* pinned, so it leaves the conversation's deltas alone.
|
|
870
|
-
*/
|
|
871
|
-
context(options?: ContextOptions & {
|
|
872
|
-
query?: string;
|
|
873
|
-
}): Promise<ContextResult>;
|
|
874
|
-
/**
|
|
875
|
-
* Records that `context` (by default the last one this conversation returned) went into the
|
|
876
|
-
* prompt. Call it each time you build the prompt; `timings.contextInjectedAt` keeps the first.
|
|
877
|
-
*/
|
|
878
|
-
markInjected(context?: ContextResult | null, at?: Date): void;
|
|
879
|
-
/** Captures what the customer said. */
|
|
880
|
-
customer(text: string, options?: TurnOptions): string | null;
|
|
881
|
-
/** Captures what the AI agent said, stamped with the context its prompt carried. */
|
|
882
|
-
agent(text: string, options?: TurnOptions): string | null;
|
|
883
|
-
/** Captures what a human attendant said, for example after a handoff. */
|
|
884
|
-
human(text: string, options?: TurnOptions): string | null;
|
|
885
|
-
/** Records any event in this conversation. The customer's handle is attached unless you pass your own. */
|
|
886
|
-
track(event: ConversationEvent): string | null;
|
|
887
|
-
/** Records an action the agent took during this conversation, stamped like its turns. */
|
|
888
|
-
action(event: ConversationAction): string | null;
|
|
889
|
-
/**
|
|
890
|
-
* Records that the customer proved who they are, and raises the level for later reads.
|
|
891
|
-
* `handle` defaults to the conversation's subject.
|
|
892
|
-
*/
|
|
893
|
-
verify(params: {
|
|
894
|
-
method: VerifyMethod;
|
|
895
|
-
level: Verification;
|
|
896
|
-
handle?: Handle;
|
|
897
|
-
}): Promise<WriteResult>;
|
|
898
|
-
/** Records a transfer to a human or another agent. */
|
|
899
|
-
handoff(params: {
|
|
900
|
-
target: "human" | "agent";
|
|
901
|
-
target_source?: string;
|
|
902
|
-
reason?: string;
|
|
903
|
-
mode?: "warm" | "cold";
|
|
904
|
-
}): Promise<WriteResult>;
|
|
905
|
-
/**
|
|
906
|
-
* The navigation kit bound to this customer and conversation. The verification level is
|
|
907
|
-
* read at each call, so tools created before a `verify()` pick up the new level.
|
|
908
|
-
*/
|
|
909
|
-
tools(): BoundTools;
|
|
910
|
-
/** Emits `conversation.ended` and drops the conversation's cached packs. Safe to call twice. */
|
|
911
|
-
end(): Promise<WriteResult>;
|
|
912
|
-
private bind;
|
|
913
|
-
private turn;
|
|
914
|
-
}
|
|
915
785
|
|
|
916
|
-
/**
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
* erases it, even if no event ever references it.
|
|
925
|
-
*/
|
|
926
|
-
subject?: Handle;
|
|
927
|
-
}
|
|
928
|
-
/** A file handed to Niadra. Put `media_ref` and `media_sha256` in the event's `content`. */
|
|
929
|
-
interface MediaUpload {
|
|
930
|
-
media_ref: string;
|
|
931
|
-
media_sha256: string;
|
|
932
|
-
content_type: string;
|
|
933
|
-
size_bytes: number;
|
|
934
|
-
expires_at: string | null;
|
|
935
|
-
}
|
|
936
|
-
|
|
937
|
-
/** Paging of `objectTimeline()`. */
|
|
938
|
-
interface ObjectTimelineParams {
|
|
939
|
-
/** `next_cursor` from the previous page. */
|
|
940
|
-
cursor?: string;
|
|
941
|
-
/** Between 1 and 100. Defaults to 20. */
|
|
942
|
-
limit?: number;
|
|
786
|
+
/**
|
|
787
|
+
* A handle with no canonical destination: `invalid_handle` when the value is not a handle of its type,
|
|
788
|
+
* `unsupported_type` when the list does not cover the type.
|
|
789
|
+
*/
|
|
790
|
+
declare class NiadraDestinationError extends NiadraError {
|
|
791
|
+
readonly code: "invalid_handle" | "unsupported_type";
|
|
792
|
+
readonly name = "NiadraDestinationError";
|
|
793
|
+
constructor(code: "invalid_handle" | "unsupported_type");
|
|
943
794
|
}
|
|
795
|
+
/**
|
|
796
|
+
* The canonical form of a handle of `type` (`phone_e164`, `wa_id`, `wa_jid` or `email`), such as
|
|
797
|
+
* `phone:+5511987654321` for `"(11) 98765-4321"`. Throws `NiadraDestinationError`.
|
|
798
|
+
*/
|
|
799
|
+
declare function canonicalDestination(type: string, value: string): string;
|
|
800
|
+
/**
|
|
801
|
+
* A canonical destination keyed with a reader's salt, in base64url as `GET /v1/suppressions/salt` gives it:
|
|
802
|
+
* the base64url of HMAC-SHA256 over its UTF-8 bytes, 43 characters. Web Crypto signs asynchronously.
|
|
803
|
+
*/
|
|
804
|
+
declare function suppressionKey(salt: string, canonical: string): Promise<string>;
|
|
944
805
|
|
|
945
806
|
/**
|
|
946
|
-
*
|
|
947
|
-
*
|
|
948
|
-
*
|
|
807
|
+
* The exposure token (`spec/exposure-token.md`): `nx1.<id>.<position>.<verifier>`, the short string a card
|
|
808
|
+
* carries so that the order line the store's app copies it into names the list the agent showed and the
|
|
809
|
+
* card's place in it.
|
|
810
|
+
*
|
|
811
|
+
* The token carries no personal data. Its verifier catches a token copied wrong or cut short; it is not a
|
|
812
|
+
* signature. Building one is synchronous, so a card can carry it as it renders: the SHA-256 of the verifier
|
|
813
|
+
* is computed here, since Web Crypto only hashes asynchronously.
|
|
814
|
+
*
|
|
815
|
+
* The same rules as the Python SDK's `niadra.exposure`.
|
|
949
816
|
*/
|
|
950
|
-
interface Timeouts {
|
|
951
|
-
/** `context()` for every view except `voice`. */
|
|
952
|
-
context: number;
|
|
953
|
-
/** `context()` with `view: "voice"`, where the budget is a fraction of a spoken turn. */
|
|
954
|
-
contextVoice: number;
|
|
955
|
-
/** `search()`, `timeline()` and `open()`. */
|
|
956
|
-
navigation: number;
|
|
957
|
-
/** Navigation calls made through a voice conversation or voice-bound tools. */
|
|
958
|
-
navigationVoice: number;
|
|
959
|
-
/** Each attempt of a batch upload. Writes happen off the hot path, so this one is generous. */
|
|
960
|
-
write: number;
|
|
961
|
-
/** `subjectToken()`, usually called once when a session starts. */
|
|
962
|
-
token: number;
|
|
963
|
-
/** Each attempt of sending media bytes to storage in `uploadMedia()`, off the hot path. */
|
|
964
|
-
upload: number;
|
|
965
|
-
}
|
|
966
|
-
declare const DEFAULT_TIMEOUTS: Timeouts;
|
|
967
|
-
/** How `context()` reuses packs inside a conversation. */
|
|
968
|
-
interface CacheOptions {
|
|
969
|
-
/** A pack younger than this is returned without any request. */
|
|
970
|
-
ttlMs: number;
|
|
971
|
-
/**
|
|
972
|
-
* After `ttlMs`, the cached pack is still returned at once for this long while a single
|
|
973
|
-
* background request refreshes it.
|
|
974
|
-
*/
|
|
975
|
-
staleWhileRevalidateMs: number;
|
|
976
|
-
/**
|
|
977
|
-
* Oldest pack the SDK will fall back to when a request fails. Older packs are dropped
|
|
978
|
-
* rather than shown to a model as if they were current.
|
|
979
|
-
*/
|
|
980
|
-
maxStaleMs: number;
|
|
981
|
-
/** Least recently used packs are evicted past this many conversations. */
|
|
982
|
-
maxEntries: number;
|
|
983
|
-
}
|
|
984
|
-
declare const DEFAULT_CACHE: CacheOptions;
|
|
985
|
-
/** How `track()` and the other write methods batch events on their way to `POST /v1/batch`. */
|
|
986
|
-
interface QueueOptions {
|
|
987
|
-
/** Send as soon as this many items are waiting. */
|
|
988
|
-
flushAt: number;
|
|
989
|
-
/** Send whatever is waiting at least this often. */
|
|
990
|
-
flushIntervalMs: number;
|
|
991
|
-
/** Items per request. The server accepts up to 500. */
|
|
992
|
-
maxBatchSize: number;
|
|
993
|
-
/** Items held in memory before new ones are dropped. Keeps a long outage from exhausting memory. */
|
|
994
|
-
maxQueueSize: number;
|
|
995
|
-
/** Attempts per batch, including the first. 4xx answers other than 408, 421 and 429 are never retried. */
|
|
996
|
-
maxAttempts: number;
|
|
997
|
-
/** First backoff delay; each retry doubles it, with full jitter, up to `maxRetryDelayMs`. */
|
|
998
|
-
retryDelayMs: number;
|
|
999
|
-
maxRetryDelayMs: number;
|
|
1000
|
-
}
|
|
1001
|
-
declare const DEFAULT_QUEUE: QueueOptions;
|
|
1002
|
-
interface ClientOptions {
|
|
1003
|
-
/**
|
|
1004
|
-
* A source key, `nia_sk_<live|test>_<region>_<space>_<key_id>_<secret>`. Defaults to the
|
|
1005
|
-
* `NIADRA_API_KEY` environment variable where one exists. Without a key the client is a
|
|
1006
|
-
* no-op: every method resolves with an empty result and nothing is sent.
|
|
1007
|
-
*/
|
|
1008
|
-
apiKey?: string | undefined;
|
|
1009
|
-
/**
|
|
1010
|
-
* Overrides the address derived from the key, for the local emulator or a private endpoint.
|
|
1011
|
-
* Defaults to `NIADRA_BASE_URL`, then to `https://<space>.<region>.api.niadra.com`.
|
|
1012
|
-
*/
|
|
1013
|
-
baseURL?: string | undefined;
|
|
1014
|
-
timeouts?: Partial<Timeouts>;
|
|
1015
|
-
/** Pass `false` to send every `context()` call to the server. */
|
|
1016
|
-
cache?: Partial<CacheOptions> | false;
|
|
1017
|
-
queue?: Partial<QueueOptions>;
|
|
1018
|
-
/**
|
|
1019
|
-
* Throw errors instead of logging them and resolving with an empty result. Meant for tests
|
|
1020
|
-
* and development, where a silent failure hides a broken integration.
|
|
1021
|
-
*/
|
|
1022
|
-
strict?: boolean;
|
|
1023
|
-
/** Flush queued events when a Node process is about to exit. Defaults to `true`. */
|
|
1024
|
-
flushOnExit?: boolean;
|
|
1025
|
-
/** A `fetch` implementation. Defaults to the global one. */
|
|
1026
|
-
fetch?: typeof fetch;
|
|
1027
|
-
logger?: Logger;
|
|
1028
|
-
/** Extra headers sent with every request. */
|
|
1029
|
-
defaultHeaders?: Record<string, string>;
|
|
1030
|
-
}
|
|
1031
817
|
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
/** The business object the task is about, as an `ObjectRef` or `type:namespace:id`. */
|
|
1040
|
-
object?: ObjectRef | string;
|
|
1041
|
-
about?: Handle;
|
|
1042
|
-
/** A task view such as `task:billing`. Defaults to `brief`. */
|
|
1043
|
-
view?: View;
|
|
1044
|
-
verification?: Verification;
|
|
1045
|
-
target?: TargetModel;
|
|
818
|
+
/** Why a reader refuses a token: the first check of `spec/exposure-token.md`, section 4, that fails. */
|
|
819
|
+
type ExposureTokenRefusal = "malformed" | "unsupported_version" | "bad_position" | "bad_verifier";
|
|
820
|
+
/** A token a reader refuses, with the code of the first check it fails. */
|
|
821
|
+
declare class NiadraExposureTokenError extends NiadraError {
|
|
822
|
+
readonly code: ExposureTokenRefusal;
|
|
823
|
+
readonly name = "NiadraExposureTokenError";
|
|
824
|
+
constructor(code: ExposureTokenRefusal);
|
|
1046
825
|
}
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
826
|
+
/**
|
|
827
|
+
* The token of the card at `position` (1-based, up to 9999) of the exposure `exposureId`, a UUID: 33
|
|
828
|
+
* characters for the first card, at most 36.
|
|
829
|
+
*/
|
|
830
|
+
declare function exposureToken(exposureId: string, position: number): string;
|
|
831
|
+
/** The exposure id, written as a UUID, and the position a token names. Throws `NiadraExposureTokenError`. */
|
|
832
|
+
declare function parseExposureToken(token: string): {
|
|
833
|
+
exposureId: string;
|
|
834
|
+
position: number;
|
|
1052
835
|
};
|
|
1053
|
-
|
|
1054
|
-
endTask(id: string): Promise<WriteResult>;
|
|
1055
|
-
/** `verify()` for a task, which may have no subject to default the handle to. */
|
|
1056
|
-
verifyTask(params: Omit<VerifyParams, "handle"> & {
|
|
1057
|
-
handle: Handle | undefined;
|
|
1058
|
-
}): Promise<WriteResult>;
|
|
1059
|
-
}
|
|
836
|
+
|
|
1060
837
|
/**
|
|
1061
|
-
*
|
|
1062
|
-
*
|
|
1063
|
-
*
|
|
1064
|
-
*
|
|
1065
|
-
*
|
|
838
|
+
* Where the turn in progress lives: an `AsyncLocalStorage`, which follows promises, `await` and timers, so a
|
|
839
|
+
* tool called anywhere inside a turn lands in it, and two sub-agents started with `Promise.all` each keep
|
|
840
|
+
* their own.
|
|
841
|
+
*
|
|
842
|
+
* The SDK builds for every runtime and never imports `node:async_hooks` itself. It takes the class from
|
|
843
|
+
* `process.getBuiltinModule("node:async_hooks")` where that exists (Node 20.16 and later, Bun, Deno); a
|
|
844
|
+
* runtime without it passes the class to `useAsyncLocalStorage()`, as Cloudflare Workers do with the
|
|
845
|
+
* `nodejs_als` flag. Where there is none, `currentTurn()` is `undefined` and adapters pass the turn they
|
|
846
|
+
* opened explicitly: capture keeps working, only the implicit lookup is missing.
|
|
1066
847
|
*/
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
private ending;
|
|
1076
|
-
constructor(client: Niadra, params: TaskParams, hooks: TaskHooks);
|
|
1077
|
-
/** When context first went into the prompt, and when the agent first acted. */
|
|
1078
|
-
get timings(): Timings;
|
|
1079
|
-
/** What the agent's next turn and action carry: the last `markInjected()`, or `null`. */
|
|
1080
|
-
get contextStamp(): ContextStamp | null;
|
|
1081
|
-
/** The last result `context()` returned for this task. */
|
|
1082
|
-
get lastContext(): ContextResult | null;
|
|
1083
|
-
/** Where `wrap()` reports what it swallowed: the client's logger. */
|
|
1084
|
-
get logger(): Logger;
|
|
1085
|
-
/**
|
|
1086
|
-
* Context for the task, centered on its object when it has one, otherwise on its subject.
|
|
1087
|
-
* Resolves with an empty result, never rejects, unless the client is strict.
|
|
1088
|
-
*/
|
|
1089
|
-
context(options?: ContextOptions & {
|
|
1090
|
-
query?: string;
|
|
1091
|
-
}): Promise<ContextResult>;
|
|
1092
|
-
/** Records that `context` (by default the last one this task returned) went into the prompt. */
|
|
1093
|
-
markInjected(context?: ContextResult | null, at?: Date): void;
|
|
1094
|
-
/** Captures what the agent answered, stamped with the context its prompt carried. */
|
|
1095
|
-
agent(text: string, options?: TurnOptions): string | null;
|
|
1096
|
-
/**
|
|
1097
|
-
* Records that the person the task is about proved who they are, and reads at the new level
|
|
1098
|
-
* from then on. `handle` defaults to the task's subject.
|
|
1099
|
-
*/
|
|
1100
|
-
verify(params: {
|
|
1101
|
-
method: VerifyMethod;
|
|
1102
|
-
level: Verification;
|
|
1103
|
-
handle?: Handle;
|
|
1104
|
-
}): Promise<WriteResult>;
|
|
1105
|
-
/** Records an event in this task, attaching the task's subject and object unless you pass your own. */
|
|
1106
|
-
track(event: TaskEvent): string | null;
|
|
1107
|
-
/** Records an action taken in a system of record, such as `credit` on an invoice, stamped like its turns. */
|
|
1108
|
-
action(event: TaskAction): string | null;
|
|
1109
|
-
/**
|
|
1110
|
-
* The navigation kit bound to the task's subject, or `null` for a task about an object only.
|
|
1111
|
-
* The verification level is read at each call, so tools created before a `verify()` pick up
|
|
1112
|
-
* the new level.
|
|
1113
|
-
*/
|
|
1114
|
-
tools(): BoundTools | null;
|
|
1115
|
-
/** Emits `task.ended` and drops the task's cached packs. Safe to call twice. */
|
|
1116
|
-
end(): Promise<WriteResult>;
|
|
1117
|
-
private bind;
|
|
1118
|
-
}
|
|
848
|
+
interface AsyncStore<T> {
|
|
849
|
+
getStore(): T | undefined;
|
|
850
|
+
run<R>(store: T, fn: () => R): R;
|
|
851
|
+
enterWith(store: T): void;
|
|
852
|
+
}
|
|
853
|
+
type StoreClass = new <T>() => AsyncStore<T>;
|
|
854
|
+
/** The `AsyncLocalStorage` class to hold turns with, on a runtime where the SDK cannot find one itself. */
|
|
855
|
+
declare function useAsyncLocalStorage(storage: StoreClass): void;
|
|
1119
856
|
|
|
1120
857
|
/**
|
|
1121
|
-
*
|
|
1122
|
-
*
|
|
858
|
+
* The resolver worker: the space's refresh requests, served inside the company's boundary.
|
|
859
|
+
*
|
|
860
|
+
* Niadra never calls a company system. When a value must be read again (a claim waits on it, a timer is due,
|
|
861
|
+
* someone watches the object), Niadra queues a refresh request with the budget it admitted. The worker leases
|
|
862
|
+
* the waiting requests (`GET /v1/state/refresh-requests`, 60 s), reads each object with the company's resolver
|
|
863
|
+
* of its type (`niadra.resolvers`), at the resolver's rate and behind its circuit breaker, and pushes what it
|
|
864
|
+
* read (`POST /v1/objects/push`) with the request's id, which settles it.
|
|
865
|
+
*
|
|
866
|
+
* A watch fires only on a value its source confirmed: its `watch_revalidation` requests go first, and the
|
|
867
|
+
* answer decides every due watch of the object, even when the value did not change. A request the worker
|
|
868
|
+
* cannot answer, the object gone from the source (`NOT_FOUND`) or the resolver failing, is released at once
|
|
869
|
+
* (`POST .../release`), so a watch falls back to its type's rule without waiting out the leases. A request of a
|
|
870
|
+
* type with no resolver, or whose resolver's circuit is open, is left to its lease, for a worker that can read
|
|
871
|
+
* it. A worker that leases regularly is what tells Niadra a company worker is there to revalidate.
|
|
872
|
+
*
|
|
873
|
+
* ```ts
|
|
874
|
+
* const worker = new ResolverWorker(niadra);
|
|
875
|
+
* await worker.run(abortController.signal);
|
|
876
|
+
* ```
|
|
1123
877
|
*/
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
878
|
+
|
|
879
|
+
declare class ResolverWorker {
|
|
880
|
+
private readonly niadra;
|
|
881
|
+
private readonly options;
|
|
882
|
+
pushed: number;
|
|
883
|
+
skipped: number;
|
|
884
|
+
released: number;
|
|
885
|
+
private readonly missing;
|
|
886
|
+
constructor(niadra: Niadra, options?: {
|
|
887
|
+
limit?: number;
|
|
888
|
+
pollMs?: number;
|
|
889
|
+
budgetMs?: number;
|
|
890
|
+
resolvers?: Resolvers;
|
|
891
|
+
});
|
|
892
|
+
private get resolvers();
|
|
893
|
+
/** Leases the waiting requests, resolves them and pushes what was read. Resolves with how many were pushed. */
|
|
894
|
+
runOnce(): Promise<number>;
|
|
895
|
+
/** Gives back a request the worker cannot answer; one that failed to go back waits out its lease. */
|
|
896
|
+
private release;
|
|
897
|
+
/** Serves requests until `signal` aborts, pausing when none wait, and longer while Niadra does not answer. */
|
|
898
|
+
run(signal?: AbortSignal): Promise<void>;
|
|
1135
899
|
}
|
|
1136
900
|
|
|
1137
|
-
/**
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
}
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
901
|
+
/**
|
|
902
|
+
* Replay inside the company's boundary (`spec/replay.md`): Niadra keeps the scenarios and decides the verdict;
|
|
903
|
+
* the company's CI runs the agent again on recorded turns.
|
|
904
|
+
*
|
|
905
|
+
* ```ts
|
|
906
|
+
* const run = await new Replayer(niadra, buildAgent, { build: Niadra.build({ prompts: { core: "v17" }, model: MODEL }) })
|
|
907
|
+
* .run(["sc_quote_after_price_change"], { runs: 5, vary: ["prompts"] });
|
|
908
|
+
* if (run.verdict === "regression") process.exit(1);
|
|
909
|
+
* ```
|
|
910
|
+
*
|
|
911
|
+
* For each turn of each scenario the runner asks for the case (`POST /v1/replay/cases`) with the build it runs,
|
|
912
|
+
* checks the pins itself, fetches every recorded value it needs (by pointer through `niadra.content`, or
|
|
913
|
+
* `read`) and checks its digest. It then runs the agent N times: `buildAgent()` makes a fresh agent, called
|
|
914
|
+
* with a `ReplayInput`. Inside the run, tools wrapped with `niadra.tool()` answer from the record when their
|
|
915
|
+
* arguments match a recorded call; nothing the agent sends, declares or checks leaves for Niadra, and a read
|
|
916
|
+
* returns the pack of the time. The assertions are evaluated on the replayed record, which stays here, and the
|
|
917
|
+
* results go to `POST /v1/scenario-runs`, which answers with the statistical verdict.
|
|
918
|
+
*/
|
|
919
|
+
|
|
920
|
+
type Json$1 = Record<string, unknown>;
|
|
921
|
+
/** What a replayed agent receives: the turn's input (masked), the conversation before it, the pack of the time. */
|
|
922
|
+
interface ReplayInput {
|
|
923
|
+
turnId: string;
|
|
924
|
+
kind: string;
|
|
925
|
+
text: string | null;
|
|
926
|
+
history: Json$1[];
|
|
927
|
+
context: ContextResponse | null;
|
|
928
|
+
record: Json$1;
|
|
929
|
+
/** The execution's number, from 1. */
|
|
930
|
+
run: number;
|
|
931
|
+
paraphrase: boolean;
|
|
932
|
+
}
|
|
933
|
+
/** Answers one input: the text the agent emitted (or nothing), or a promise of it. */
|
|
934
|
+
type ReplayAgent = (input: ReplayInput) => unknown;
|
|
935
|
+
/**
|
|
936
|
+
* A run as Niadra judged it: `verdict` is the worst of its scenarios' (`pass`, `flaky`, `infrastructure_error`,
|
|
937
|
+
* `pin_mismatch`, `regression`), and `scenarios` holds each one's verdict with the statistics of each
|
|
938
|
+
* assertion. A report Niadra refused for a pin that does not match is `refused`, with no `runId`.
|
|
939
|
+
*/
|
|
940
|
+
interface ReplayRun {
|
|
941
|
+
runId: string;
|
|
942
|
+
status: string;
|
|
943
|
+
verdict: string | null;
|
|
944
|
+
scenarios: Json$1[];
|
|
945
|
+
}
|
|
946
|
+
interface RunOptions {
|
|
947
|
+
runs?: number;
|
|
948
|
+
mode?: Mode;
|
|
949
|
+
vary?: string[];
|
|
950
|
+
/** A paraphrase of the input for run `n`: intermittent results must hold with other words too. */
|
|
951
|
+
paraphrase?: (text: string, run: number) => string;
|
|
952
|
+
}
|
|
953
|
+
/** The pins that differ (the replay spec, 4.2): every pin outside `vary` the recording requires, or both builds carry. */
|
|
954
|
+
declare function pinDifferences(recorded: Json$1, running: Json$1, required: readonly string[], vary: readonly string[]): Json$1[];
|
|
955
|
+
/** Runs scenarios: see the module. `read(pointer)` reads values kept by pointer, by default the client's content resolver. */
|
|
956
|
+
declare class Replayer {
|
|
957
|
+
private readonly niadra;
|
|
958
|
+
private readonly agentFactory;
|
|
959
|
+
private readonly options;
|
|
960
|
+
private readonly build;
|
|
961
|
+
constructor(niadra: Niadra, agentFactory: () => ReplayAgent, options?: {
|
|
962
|
+
build?: TurnPins;
|
|
963
|
+
read?: (pointer: string) => Promise<string>;
|
|
964
|
+
});
|
|
965
|
+
/** Runs each turn of the scenarios `runs` times and resolves with the run and its verdict. */
|
|
966
|
+
run(scenarioIds: readonly string[], options?: RunOptions): Promise<ReplayRun>;
|
|
967
|
+
private scenario;
|
|
968
|
+
private caseOf;
|
|
969
|
+
private execute;
|
|
1152
970
|
}
|
|
971
|
+
|
|
1153
972
|
/**
|
|
1154
|
-
* The
|
|
973
|
+
* The tool counterfactual (`spec/counterfactual.md`): does one element of the constraints block change what a
|
|
974
|
+
* tool returns, beyond the tool's own noise? Run in the company's CI, inside its boundary.
|
|
1155
975
|
*
|
|
1156
|
-
*
|
|
1157
|
-
*
|
|
1158
|
-
*
|
|
1159
|
-
*
|
|
1160
|
-
*
|
|
976
|
+
* ```ts
|
|
977
|
+
* const run = await new Counterfactual(niadra, { search_products: searchProducts }).run(turnIds, {
|
|
978
|
+
* tool: "search_products",
|
|
979
|
+
* element: "hard",
|
|
980
|
+
* });
|
|
981
|
+
* console.log(run.report.effect, run.report.limits);
|
|
982
|
+
* ```
|
|
1161
983
|
*
|
|
1162
|
-
*
|
|
1163
|
-
*
|
|
984
|
+
* For each recorded call of the tool whose arguments or post filter carried the element (the call recorded the
|
|
985
|
+
* block it `applied`, and the block is in the record), the runner renders the call again without the element and
|
|
986
|
+
* calls the tool three times at the same moment: the recorded arguments twice (the base, whose two lists measure
|
|
987
|
+
* the tool's own noise) and the variant once. A tool marked safe to run again (`tool(..., { dryRun: true })`, or
|
|
988
|
+
* `safe`) runs as it is; any other runs as its dry run (the binding's `capabilities.dry_run_param`), and one
|
|
989
|
+
* with no dry run is never called (`no_dry_run`). It compares the lists after the post filter (exclusions, when
|
|
990
|
+
* the binding overfetches) with `overlapAtK`, finds where the items the person engaged with went, and sends
|
|
991
|
+
* only positions and overlaps to `POST /v1/measure/counterfactual-runs`, which answers with the report.
|
|
1164
992
|
*
|
|
1165
|
-
*
|
|
1166
|
-
*
|
|
1167
|
-
*
|
|
993
|
+
* The records come through the replay case route, so only turns that can be replayed are read. The element is
|
|
994
|
+
* `constraints` (the whole block), `hard`, `size` (its attributes) or `exclude`. The binding comes from
|
|
995
|
+
* `bindings`, the tool's own `binding` or the SDK profile; a result's objects are read with the binding's
|
|
996
|
+
* `results`, or else with the tool's `provenance`. It behaves as the Python SDK's `Counterfactual`.
|
|
1168
997
|
*/
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
/**
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
*/
|
|
1217
|
-
objectState(object: ObjectRef | string, options?: RequestOptions): Promise<Result<ObjectState>>;
|
|
1218
|
-
/**
|
|
1219
|
-
* System events and agent actions about one object, newest first, one line each and never
|
|
1220
|
-
* conversation content. Pass `next_cursor` back as `cursor` to go on.
|
|
1221
|
-
*/
|
|
1222
|
-
objectTimeline(object: ObjectRef | string, params?: ObjectTimelineParams, options?: RequestOptions): Promise<Result<ObjectTimeline>>;
|
|
1223
|
-
/**
|
|
1224
|
-
* The navigation kit as function-calling tools with the customer bound outside the model's
|
|
1225
|
-
* reach. Hand `definitions` to any model API and pass its tool calls to `call()`.
|
|
1226
|
-
*
|
|
1227
|
-
* @example
|
|
1228
|
-
* const kit = niadra.tools(handles.phone("+5511987654321"), { conversation_id: "wa-8812" });
|
|
1229
|
-
* const output = await kit.call(toolCall.function.name, toolCall.function.arguments);
|
|
1230
|
-
*/
|
|
1231
|
-
tools(subject: Handle, binding?: ToolBinding): BoundTools;
|
|
1232
|
-
/**
|
|
1233
|
-
* Mints a signed, 15-minute token that binds one customer to a session. Your backend calls
|
|
1234
|
-
* this and hands the token to the MCP connection, so tools served over MCP can only ever
|
|
1235
|
-
* read that customer. Resolves with `data: null` on failure.
|
|
1236
|
-
*/
|
|
1237
|
-
subjectToken(params: SubjectTokenRequest, options?: RequestOptions): Promise<Result<SubjectToken>>;
|
|
1238
|
-
/**
|
|
1239
|
-
* Records a message, a system event or an agent action. Returns at once with the event's
|
|
1240
|
-
* idempotency key, or `null` when the event was dropped: invalid, unserializable, the queue
|
|
1241
|
-
* full or the client disabled. Delivery happens in the background; `flush()` waits for it.
|
|
1242
|
-
*/
|
|
1243
|
-
track(event: TrackEvent): string | null;
|
|
1244
|
-
/**
|
|
1245
|
-
* Records what an agent did in a system of record, such as a credit or a reschedule.
|
|
1246
|
-
* With `closes`, the action also resolves the open item it fulfils.
|
|
1247
|
-
*/
|
|
1248
|
-
action(event: ActionEvent): string | null;
|
|
1249
|
-
/**
|
|
1250
|
-
* States that several handles belong to the same subject. Sent right away rather than on the
|
|
1251
|
-
* next batch, so the next `context()` call already sees the merged profile.
|
|
1252
|
-
*/
|
|
1253
|
-
identify(params: IdentifyParams): Promise<WriteResult>;
|
|
1254
|
-
/**
|
|
1255
|
-
* Raises the verification level of one conversation or task after the customer proved who
|
|
1256
|
-
* they are. Sent right away, and drops the conversation's cached packs, because a pack
|
|
1257
|
-
* compiled for the old level may be missing what the new level allows.
|
|
1258
|
-
*/
|
|
1259
|
-
verify(params: VerifyParams): Promise<WriteResult>;
|
|
1260
|
-
/**
|
|
1261
|
-
* Corrects what Niadra derived about a subject: retracts or corrects a fact, resolves an open
|
|
1262
|
-
* item, or records how a conversation ended. Sent right away; the server records it as an
|
|
1263
|
-
* event, so the correction is audited like any other. A rejected correction resolves with
|
|
1264
|
-
* `ok: false`.
|
|
1265
|
-
*/
|
|
1266
|
-
feedback(params: FeedbackParams): Promise<WriteResult>;
|
|
1267
|
-
/**
|
|
1268
|
-
* Hands a file to Niadra, such as a call recording, and returns the reference its event
|
|
1269
|
-
* carries. Media never travels inside an event: this reserves an upload, sends the bytes
|
|
1270
|
-
* straight to storage over a short-lived signed URL, and resolves with `media_ref` and
|
|
1271
|
-
* `media_sha256` for the event's `content`.
|
|
1272
|
-
*
|
|
1273
|
-
* @example
|
|
1274
|
-
* const { data } = await niadra.uploadMedia({ data: recording, content_type: "audio/wav" });
|
|
1275
|
-
* if (data) convo.track({ speaker: "customer", content: { type: "audio", media_ref: data.media_ref, media_sha256: data.media_sha256 } });
|
|
1276
|
-
*/
|
|
1277
|
-
uploadMedia(params: UploadParams, options?: {
|
|
1278
|
-
signal?: AbortSignal;
|
|
1279
|
-
}): Promise<Result<MediaUpload>>;
|
|
1280
|
-
/** Records a transfer to a human or another agent. Sent right away, so the receiver can read context at once. */
|
|
1281
|
-
handoff(params: HandoffParams): Promise<WriteResult>;
|
|
1282
|
-
/**
|
|
1283
|
-
* A helper for one customer conversation: pins the pack across turns, captures turns and
|
|
1284
|
-
* emits `conversation.ended` when you call `end()`.
|
|
1285
|
-
*/
|
|
1286
|
-
conversation(params: ConversationParams): Conversation;
|
|
1287
|
-
/** A helper for one internal-agent task: binds `task_id` to reads and writes and emits `task.ended`. */
|
|
1288
|
-
task(params: TaskParams): Task;
|
|
1289
|
-
/**
|
|
1290
|
-
* Sends every queued event and resolves when done. Call it before a serverless function
|
|
1291
|
-
* returns, or pass it to `waitUntil()` on edge runtimes. Rejects only with `strict` set.
|
|
1292
|
-
*/
|
|
1293
|
-
flush(): Promise<void>;
|
|
1294
|
-
/**
|
|
1295
|
-
* Flushes, stops the background timer and releases the exit hook. Events tracked after
|
|
1296
|
-
* this are dropped. Call it from your own SIGTERM handler in long-running services.
|
|
1297
|
-
*/
|
|
1298
|
-
shutdown(): Promise<void>;
|
|
1299
|
-
private verifyWith;
|
|
1300
|
-
/** Throws under `strict`; otherwise logs what failed, never with content, and returns the error. */
|
|
1301
|
-
private swallow;
|
|
1302
|
-
private voiceBudget;
|
|
1303
|
-
private readSpec;
|
|
1304
|
-
private navigate;
|
|
1305
|
-
private fetchContext;
|
|
1306
|
-
/**
|
|
1307
|
-
* One request for a key, shared by every caller that needs it meanwhile. It sends the
|
|
1308
|
-
* cached ETag, so an unchanged pack costs a `not_modified` answer instead of the full text.
|
|
1309
|
-
* The caller's signal is deliberately not passed down: other callers may be waiting too.
|
|
1310
|
-
*/
|
|
1311
|
-
private revalidate;
|
|
1312
|
-
private contextFailure;
|
|
1313
|
-
/**
|
|
1314
|
-
* 401 means the key itself is no longer valid, so every cached pack goes. 403 is specific to
|
|
1315
|
-
* what was asked, so only that pack goes.
|
|
1316
|
-
*/
|
|
1317
|
-
private observeAuth;
|
|
1318
|
-
private forgetScope;
|
|
1319
|
-
private disabledError;
|
|
1320
|
-
private enqueue;
|
|
1321
|
-
private sendNow;
|
|
1322
|
-
private endScope;
|
|
1323
|
-
private sendBatch;
|
|
998
|
+
|
|
999
|
+
type Element = "constraints" | "hard" | "size" | "exclude";
|
|
1000
|
+
type Json = Record<string, unknown>;
|
|
1001
|
+
type ToolFunction = (args: any) => unknown;
|
|
1002
|
+
/**
|
|
1003
|
+
* Depth-weighted average overlap of `a` and `b` down to `min(k, the longer list's length)`, with
|
|
1004
|
+
* `w(d) = 1 / log2(d + 1)`. An item repeated within a list counts once, at its first position. Two equal
|
|
1005
|
+
* lists overlap 1, and so do two empty lists; a list against an empty one overlaps 0.
|
|
1006
|
+
*/
|
|
1007
|
+
declare function overlapAtK(a: readonly string[], b: readonly string[], k: number): number;
|
|
1008
|
+
/** What the run sent and what Niadra answered, with the calls the element did not touch and the turns unread. */
|
|
1009
|
+
interface CounterfactualRun {
|
|
1010
|
+
report: Json;
|
|
1011
|
+
cases: Json[];
|
|
1012
|
+
untouched: number;
|
|
1013
|
+
unread: number;
|
|
1014
|
+
}
|
|
1015
|
+
interface CounterfactualOptions {
|
|
1016
|
+
/** Reads values kept by pointer; by default the client's content resolver. */
|
|
1017
|
+
read?: (pointer: string) => Promise<string>;
|
|
1018
|
+
/** A tool's binding, by tool name. */
|
|
1019
|
+
bindings?: Readonly<Record<string, RawBinding>>;
|
|
1020
|
+
/** Tools that may run again as they are. */
|
|
1021
|
+
safe?: readonly string[];
|
|
1022
|
+
}
|
|
1023
|
+
interface CounterfactualRunOptions {
|
|
1024
|
+
tool: string;
|
|
1025
|
+
element: Element;
|
|
1026
|
+
scenarioIds?: readonly string[];
|
|
1027
|
+
k?: number;
|
|
1028
|
+
label?: string;
|
|
1029
|
+
}
|
|
1030
|
+
/**
|
|
1031
|
+
* The tool counterfactual. `tools` maps each tool's name to the company's function, called with the recorded
|
|
1032
|
+
* arguments (one object).
|
|
1033
|
+
*/
|
|
1034
|
+
declare class Counterfactual {
|
|
1035
|
+
private readonly niadra;
|
|
1036
|
+
private readonly tools;
|
|
1037
|
+
private readonly options;
|
|
1038
|
+
constructor(niadra: Niadra, tools: Readonly<Record<string, ToolFunction>>, options?: CounterfactualOptions);
|
|
1039
|
+
/** Runs every recorded call of the tool the element touched; rejects when no call carried it. */
|
|
1040
|
+
run(turnIds: readonly string[], options: CounterfactualRunOptions): Promise<CounterfactualRun>;
|
|
1041
|
+
private case;
|
|
1042
|
+
private value;
|
|
1043
|
+
private served;
|
|
1044
|
+
private families;
|
|
1324
1045
|
}
|
|
1325
1046
|
|
|
1326
1047
|
/**
|
|
@@ -1332,7 +1053,11 @@ declare class Niadra {
|
|
|
1332
1053
|
* leading system or developer messages, and the suffix (deltas and live turns) as a system
|
|
1333
1054
|
* message at the end. The pack goes after the caller's instructions because those are the same
|
|
1334
1055
|
* for every customer: kept first, they stay the cacheable prefix of the prompt. The injection is
|
|
1335
|
-
* stamped on the conversation, and the model's answer is recorded as the agent's turn
|
|
1056
|
+
* stamped on the conversation, and the model's answer is recorded as the agent's turn, with the
|
|
1057
|
+
* usage the provider reported for the call: the prompt's tokens, the ones read from the provider's
|
|
1058
|
+
* prompt cache and the ones written to it (see `modelUsage()`). A stream reports its usage only when
|
|
1059
|
+
* the caller asks for it (`stream_options: { include_usage: true }`); the wrapper never changes the
|
|
1060
|
+
* request to get it.
|
|
1336
1061
|
*
|
|
1337
1062
|
* Nothing the wrapper does can fail the model call: a context that cannot be fetched is left
|
|
1338
1063
|
* out, and a failure to record the answer is logged, without content, and swallowed.
|
|
@@ -1342,7 +1067,9 @@ declare class Niadra {
|
|
|
1342
1067
|
interface WrapSession {
|
|
1343
1068
|
context(): Promise<ContextResult>;
|
|
1344
1069
|
markInjected(context?: ContextResult | null): void;
|
|
1345
|
-
agent(text: string
|
|
1070
|
+
agent(text: string, options?: {
|
|
1071
|
+
usage?: ModelUsage | null;
|
|
1072
|
+
}): string | null;
|
|
1346
1073
|
readonly logger: Logger;
|
|
1347
1074
|
}
|
|
1348
1075
|
/** A session, or a function that finds the one the current call belongs to (`null` passes the call through). */
|
|
@@ -1366,6 +1093,38 @@ declare function wrap<C extends object>(client: C, session: SessionSource): C;
|
|
|
1366
1093
|
*/
|
|
1367
1094
|
declare function injectContext(context: ContextResult, messages: readonly unknown[]): unknown[];
|
|
1368
1095
|
|
|
1096
|
+
/**
|
|
1097
|
+
* Reads what a model provider reported for one call: every input token, the ones read from the
|
|
1098
|
+
* provider's prompt cache and the ones written to it.
|
|
1099
|
+
*
|
|
1100
|
+
* Two shapes are understood, from the response or its `usage` (plain objects or class instances):
|
|
1101
|
+
*
|
|
1102
|
+
* - OpenAI chat completions and compatible gateways: `usage.prompt_tokens` (cached tokens included)
|
|
1103
|
+
* and `usage.prompt_tokens_details.cached_tokens`; the Responses API's `input_tokens` with
|
|
1104
|
+
* `input_tokens_details.cached_tokens` too. Gateways that pass Anthropic's cache fields through
|
|
1105
|
+
* (`cache_read_input_tokens`, `cache_creation_input_tokens`) are read as well.
|
|
1106
|
+
* - Anthropic messages: `usage.input_tokens` counts only the uncached rest, so the prompt is
|
|
1107
|
+
* `input_tokens + cache_read_input_tokens + cache_creation_input_tokens`.
|
|
1108
|
+
*
|
|
1109
|
+
* Nothing here throws: a response without usage gives `null`.
|
|
1110
|
+
*/
|
|
1111
|
+
|
|
1112
|
+
/** `prompt_tokens`, `cached_tokens` and `cache_write_tokens` from a provider's usage, or `null`. */
|
|
1113
|
+
declare function tokenCounts(usage: unknown): Pick<ModelUsage, "prompt_tokens" | "cached_tokens" | "cache_write_tokens"> | null;
|
|
1114
|
+
/**
|
|
1115
|
+
* Who served the call: the router prefix of `vendor/model` names, else what the name or the usage
|
|
1116
|
+
* shape says, else `openai` (the client `wrap()` takes).
|
|
1117
|
+
*/
|
|
1118
|
+
declare function providerOf(model: string, usage?: unknown): string;
|
|
1119
|
+
/**
|
|
1120
|
+
* The usage of an OpenAI or Anthropic response (or of its bare `usage`, with `options.model`), for
|
|
1121
|
+
* the agent's turn: `convo.agent(text, { usage: modelUsage(response) })`. `null` without usage.
|
|
1122
|
+
*/
|
|
1123
|
+
declare function modelUsage(response: unknown, options?: {
|
|
1124
|
+
provider?: string;
|
|
1125
|
+
model?: string;
|
|
1126
|
+
}): ModelUsage | null;
|
|
1127
|
+
|
|
1369
1128
|
interface HandleOptions {
|
|
1370
1129
|
/** Overrides the subject kind the server would infer from the handle type. */
|
|
1371
1130
|
subjectKind?: SubjectKind;
|
|
@@ -1410,7 +1169,7 @@ declare function toObjectRef(object: ObjectRef | string): ObjectRef;
|
|
|
1410
1169
|
interface ParsedApiKey {
|
|
1411
1170
|
/** `live` keys reach production spaces, `test` keys reach sandbox spaces. */
|
|
1412
1171
|
mode: "live" | "test";
|
|
1413
|
-
/** Data region, such as `
|
|
1172
|
+
/** Data region, such as `us-east-2`. */
|
|
1414
1173
|
region: string;
|
|
1415
1174
|
/** The space (project and environment) the key belongs to. */
|
|
1416
1175
|
space: string;
|
|
@@ -1436,6 +1195,6 @@ declare function baseURLFromKey(key: ParsedApiKey): string;
|
|
|
1436
1195
|
*/
|
|
1437
1196
|
declare function uuidv7(now?: number): string;
|
|
1438
1197
|
|
|
1439
|
-
declare const VERSION = "0.
|
|
1198
|
+
declare const VERSION = "0.7.0";
|
|
1440
1199
|
|
|
1441
|
-
export {
|
|
1200
|
+
export { ClaimCategory, ClaimRecord, type Binding as ConstraintBinding, type BindingArg as ConstraintBindingArg, type Call$1 as ConstraintCall, type Rendering as ConstraintRendering, ConstraintsBlock, type Honored as ConstraintsHonored, ContextResponse, ContextResult, Counterfactual, type Element as CounterfactualElement, type CounterfactualOptions, type CounterfactualRun, type CounterfactualRunOptions, type ExposureTokenRefusal, Handle, HardConstraint, Logger, type Logic, ModelUsage, Niadra, NiadraDestinationError, NiadraError, NiadraExposureTokenError, ObjectRef, type ParsedApiKey, type ReplayAgent, type ReplayInput, Mode as ReplayMode, type RunOptions as ReplayOptions, type ReplayRun, Replayer, ResolverWorker, Resolvers, type SessionSource, SubjectKind, TurnPins, VERSION, type WrapSession, baseURLFromKey, canonicalDestination, canonicalJson, index as claims, exposureToken, expr, handles, honored as honoredConstraints, injectContext, derive$1 as introspect, jsonDigest, modelUsage, overlapAtK, parseApiKey, parseExposureToken, pinDifferences, providerOf, render as renderConstraints, satisfies as satisfiesConstraint, suppressionKey, toObjectRef, tokenCounts, useAsyncLocalStorage, uuidv7, wrap };
|