@agenticprimitives/context 0.0.0-alpha.1
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/LICENSE +21 -0
- package/README.md +24 -0
- package/dist/affiliations-read.d.ts +19 -0
- package/dist/affiliations-read.d.ts.map +1 -0
- package/dist/affiliations-read.js +74 -0
- package/dist/affiliations-read.js.map +1 -0
- package/dist/ask-discovery.d.ts +15 -0
- package/dist/ask-discovery.d.ts.map +1 -0
- package/dist/ask-discovery.js +88 -0
- package/dist/ask-discovery.js.map +1 -0
- package/dist/confirmation.d.ts +59 -0
- package/dist/confirmation.d.ts.map +1 -0
- package/dist/confirmation.js +52 -0
- package/dist/confirmation.js.map +1 -0
- package/dist/conversation.d.ts +61 -0
- package/dist/conversation.d.ts.map +1 -0
- package/dist/conversation.js +66 -0
- package/dist/conversation.js.map +1 -0
- package/dist/directory-rows.d.ts +41 -0
- package/dist/directory-rows.d.ts.map +1 -0
- package/dist/directory-rows.js +121 -0
- package/dist/directory-rows.js.map +1 -0
- package/dist/entities.d.ts +65 -0
- package/dist/entities.d.ts.map +1 -0
- package/dist/entities.js +56 -0
- package/dist/entities.js.map +1 -0
- package/dist/grounded-composition.d.ts +14 -0
- package/dist/grounded-composition.d.ts.map +1 -0
- package/dist/grounded-composition.js +89 -0
- package/dist/grounded-composition.js.map +1 -0
- package/dist/grounded-types.d.ts +11 -0
- package/dist/grounded-types.d.ts.map +1 -0
- package/dist/grounded-types.js +2 -0
- package/dist/grounded-types.js.map +1 -0
- package/dist/index.d.ts +32 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +31 -0
- package/dist/index.js.map +1 -0
- package/dist/instructions.d.ts +56 -0
- package/dist/instructions.d.ts.map +1 -0
- package/dist/instructions.js +61 -0
- package/dist/instructions.js.map +1 -0
- package/dist/invitations-read.d.ts +28 -0
- package/dist/invitations-read.d.ts.map +1 -0
- package/dist/invitations-read.js +93 -0
- package/dist/invitations-read.js.map +1 -0
- package/dist/kb-question.d.ts +24 -0
- package/dist/kb-question.d.ts.map +1 -0
- package/dist/kb-question.js +139 -0
- package/dist/kb-question.js.map +1 -0
- package/dist/membership-read.d.ts +37 -0
- package/dist/membership-read.d.ts.map +1 -0
- package/dist/membership-read.js +143 -0
- package/dist/membership-read.js.map +1 -0
- package/dist/memory.d.ts +49 -0
- package/dist/memory.d.ts.map +1 -0
- package/dist/memory.js +43 -0
- package/dist/memory.js.map +1 -0
- package/dist/name-match.d.ts +22 -0
- package/dist/name-match.d.ts.map +1 -0
- package/dist/name-match.js +109 -0
- package/dist/name-match.js.map +1 -0
- package/dist/party-resolution.d.ts +214 -0
- package/dist/party-resolution.d.ts.map +1 -0
- package/dist/party-resolution.js +687 -0
- package/dist/party-resolution.js.map +1 -0
- package/dist/private-context.d.ts +25 -0
- package/dist/private-context.d.ts.map +1 -0
- package/dist/private-context.js +134 -0
- package/dist/private-context.js.map +1 -0
- package/dist/provider.d.ts +45 -0
- package/dist/provider.d.ts.map +1 -0
- package/dist/provider.js +18 -0
- package/dist/provider.js.map +1 -0
- package/dist/relationship-rows.d.ts +14 -0
- package/dist/relationship-rows.d.ts.map +1 -0
- package/dist/relationship-rows.js +50 -0
- package/dist/relationship-rows.js.map +1 -0
- package/dist/self-only.d.ts +24 -0
- package/dist/self-only.d.ts.map +1 -0
- package/dist/self-only.js +48 -0
- package/dist/self-only.js.map +1 -0
- package/dist/standing.d.ts +75 -0
- package/dist/standing.d.ts.map +1 -0
- package/dist/standing.js +152 -0
- package/dist/standing.js.map +1 -0
- package/dist/structured-call.d.ts +16 -0
- package/dist/structured-call.d.ts.map +1 -0
- package/dist/structured-call.js +18 -0
- package/dist/structured-call.js.map +1 -0
- package/dist/tiers.d.ts +14 -0
- package/dist/tiers.d.ts.map +1 -0
- package/dist/tiers.js +2 -0
- package/dist/tiers.js.map +1 -0
- package/dist/vault-question.d.ts +75 -0
- package/dist/vault-question.d.ts.map +1 -0
- package/dist/vault-question.js +302 -0
- package/dist/vault-question.js.map +1 -0
- package/package.json +51 -0
- package/spec.md +20 -0
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
// READING AN ORGANIZATION'S ROSTER — one parser, for the same reason `relationship-rows.ts` exists.
|
|
2
|
+
//
|
|
3
|
+
// `directory.data` is stored as a bare ARRAY of `{ listing: DirectoryListingV1, label }` rows — that is
|
|
4
|
+
// what the DO writes (`readDoc<IndexedListing[]>(grant, DIRECTORY_RESOURCE, [])`) and what
|
|
5
|
+
// `directory.list` reads back. The membership tool read `doc.listings`, which is `undefined` for an
|
|
6
|
+
// array, so it answered "0 members" for every organization on the estate WHATEVER its roster held. The
|
|
7
|
+
// failure was invisible because zero is a plausible answer for a young org.
|
|
8
|
+
//
|
|
9
|
+
// This is the second time today the same shape has bitten: `relationships.data` is a MAP and was being
|
|
10
|
+
// read as `{rows:[…]}`. The lesson is not "be careful with shapes" — it is that a record's shape belongs
|
|
11
|
+
// in ONE place that every reader shares, and a reader that guesses will guess plausibly and be believed.
|
|
12
|
+
//
|
|
13
|
+
// So this normalises every shape we have written — the indexed array, a `{listings:[…]}` wrapper, a bare
|
|
14
|
+
// array of listings — and is the only place that knows any of them.
|
|
15
|
+
const addressIn = (v) => (typeof v === 'string' ? (v.match(/0x[0-9a-fA-F]{40}/)?.[0] ?? '').toLowerCase() : '');
|
|
16
|
+
const str = (v) => (typeof v === 'string' ? v.trim() : '');
|
|
17
|
+
/** One stored row → a roster row, whichever shape it was written in. */
|
|
18
|
+
function rowFrom(raw) {
|
|
19
|
+
if (!raw || typeof raw !== 'object')
|
|
20
|
+
return null;
|
|
21
|
+
const r = raw;
|
|
22
|
+
// The indexed form: `{ listing: {...}, label }`. The flat form: the listing (or a legacy row) itself.
|
|
23
|
+
const listing = (r.listing && typeof r.listing === 'object' ? r.listing : r);
|
|
24
|
+
const agent = addressIn(listing.subject) || addressIn(listing.smartAgent) || addressIn(listing.agent);
|
|
25
|
+
if (!agent)
|
|
26
|
+
return null;
|
|
27
|
+
const name = str(listing.displayName) || str(listing.name) || str(r.label) || null;
|
|
28
|
+
const role = str(listing.role) || str(listing.primaryRole);
|
|
29
|
+
return { agent, name, via: 'listing', ...(role ? { role } : {}) };
|
|
30
|
+
}
|
|
31
|
+
/** The roster, from `directory.data` in any shape it has ever been written. */
|
|
32
|
+
export function rosterRows(doc) {
|
|
33
|
+
const rows = Array.isArray(doc)
|
|
34
|
+
? doc
|
|
35
|
+
: Array.isArray(doc?.listings)
|
|
36
|
+
? doc.listings
|
|
37
|
+
: [];
|
|
38
|
+
const out = [];
|
|
39
|
+
const seen = new Set();
|
|
40
|
+
for (const raw of rows) {
|
|
41
|
+
const row = rowFrom(raw);
|
|
42
|
+
if (!row || seen.has(row.agent))
|
|
43
|
+
continue;
|
|
44
|
+
seen.add(row.agent);
|
|
45
|
+
out.push(row);
|
|
46
|
+
}
|
|
47
|
+
return out;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* MEMBERS THE ORGANIZATION ITSELF RECORDED — `org.invite:agent:<sa>` records in its own vault.
|
|
51
|
+
*
|
|
52
|
+
* A listing is SELF-published: a member who joined by invitation and never published one is a real member
|
|
53
|
+
* with no listing, and reading listings alone hides them. The organization's own invitation records name
|
|
54
|
+
* them, live in its own vault, and are exactly as authoritative as the roster: the org wrote them when it
|
|
55
|
+
* admitted somebody.
|
|
56
|
+
*
|
|
57
|
+
* This is the vault-side half of the union the Home's roster already computes. It is NOT complete for
|
|
58
|
+
* members admitted before that record existed — those are only in a Home cache, which is a finding, not
|
|
59
|
+
* something to paper over here.
|
|
60
|
+
*/
|
|
61
|
+
export function invitedMemberRows(recordTypes, bodies) {
|
|
62
|
+
const out = [];
|
|
63
|
+
for (const rt of recordTypes) {
|
|
64
|
+
const agent = addressIn(rt.slice('org.invite:agent:'.length));
|
|
65
|
+
if (!agent)
|
|
66
|
+
continue;
|
|
67
|
+
const body = bodies[rt];
|
|
68
|
+
const name = str(body?.displayName) || str(body?.name) || null;
|
|
69
|
+
const status = str(body?.status);
|
|
70
|
+
// A household invitation carries the facets it will put on the membership (spec 368).
|
|
71
|
+
const kin = str(body?.kin);
|
|
72
|
+
const role = str(body?.role);
|
|
73
|
+
out.push({ agent, name, via: 'invitation', ...(status ? { status } : {}), ...(role ? { role } : {}), ...(kin ? { kin } : {}) });
|
|
74
|
+
}
|
|
75
|
+
return out;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* THE ORGANIZATION'S OWN MEMBERSHIP RECORDS — `org.membership:member:<sa>`, spec 325's shape.
|
|
79
|
+
*
|
|
80
|
+
* This is the roster proper. A listing is what a member says about themselves; an invitation is how they
|
|
81
|
+
* came to be admitted (the T-box files invitations under "Enrollment instruments — NOT membership"). The
|
|
82
|
+
* membership record is the organization's own statement that they belong, carrying the role assignment
|
|
83
|
+
* and the delegation that materialises it.
|
|
84
|
+
*/
|
|
85
|
+
export function membershipRows(recordTypes, bodies) {
|
|
86
|
+
const out = [];
|
|
87
|
+
for (const rt of recordTypes) {
|
|
88
|
+
const body = bodies[rt];
|
|
89
|
+
const agent = addressIn(body?.memberAgent) || addressIn(rt.slice(rt.lastIndexOf(':') + 1));
|
|
90
|
+
if (!agent)
|
|
91
|
+
continue;
|
|
92
|
+
// An ended membership is not a member. Kept in the vault (a roster that forgets cannot answer "who
|
|
93
|
+
// was here then"), absent from the answer to "who is here now".
|
|
94
|
+
if (str(body?.endedAt))
|
|
95
|
+
continue;
|
|
96
|
+
const ra = body?.roleAssignment;
|
|
97
|
+
// A household membership's ROLE is its `aphh:householdRole` (guardian/dependent/member) when it carries
|
|
98
|
+
// one; the generic `assignedRole` otherwise. Kinship is a separate question (spec 368 / 363 W4).
|
|
99
|
+
const role = str(ra?.householdRole) || str(ra?.assignedRole);
|
|
100
|
+
const kin = str(ra?.kinRelation);
|
|
101
|
+
out.push({
|
|
102
|
+
agent,
|
|
103
|
+
name: str(body?.displayName) || null,
|
|
104
|
+
via: 'membership',
|
|
105
|
+
...(role ? { role } : {}),
|
|
106
|
+
...(kin ? { kin } : {}),
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
return out;
|
|
110
|
+
}
|
|
111
|
+
/** Listings and invitations are two views of one roster; a member in both is one member. A listing wins
|
|
112
|
+
* on the name, because the member wrote it about themselves. */
|
|
113
|
+
export function mergeRoster(listings, invited) {
|
|
114
|
+
const byAgent = new Map();
|
|
115
|
+
for (const r of invited)
|
|
116
|
+
byAgent.set(r.agent, r);
|
|
117
|
+
for (const r of listings)
|
|
118
|
+
byAgent.set(r.agent, { ...byAgent.get(r.agent), ...r });
|
|
119
|
+
return [...byAgent.values()];
|
|
120
|
+
}
|
|
121
|
+
//# sourceMappingURL=directory-rows.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"directory-rows.js","sourceRoot":"","sources":["../src/directory-rows.ts"],"names":[],"mappings":"AAAA,oGAAoG;AACpG,EAAE;AACF,wGAAwG;AACxG,2FAA2F;AAC3F,oGAAoG;AACpG,uGAAuG;AACvG,4EAA4E;AAC5E,EAAE;AACF,uGAAuG;AACvG,yGAAyG;AACzG,yGAAyG;AACzG,EAAE;AACF,yGAAyG;AACzG,oEAAoE;AAgBpE,MAAM,SAAS,GAAG,CAAC,CAAU,EAAU,EAAE,CAAC,CAAC,OAAO,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,mBAAmB,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;AACjI,MAAM,GAAG,GAAG,CAAC,CAAU,EAAU,EAAE,CAAC,CAAC,OAAO,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;AAE5E,wEAAwE;AACxE,SAAS,OAAO,CAAC,GAAY;IAC3B,IAAI,CAAC,GAAG,IAAI,OAAO,GAAG,KAAK,QAA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,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SACxB,CAAC,CAAC;IACL,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC;AAED;iEACiE;AACjE,MAAM,UAAU,WAAW,CAAC,QAAqB,EAAE,OAAoB;IACrE,MAAM,OAAO,GAAG,IAAI,GAAG,EAAqB,CAAC;IAC7C,KAAK,MAAM,CAAC,IAAI,OAAO;QAAE,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;IACjD,KAAK,MAAM,CAAC,IAAI,QAAQ;QAAE,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,EAAE,EAAE,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC;IAClF,OAAO,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;AAC/B,CAAC"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import type { ContextProvenance, ContextTier } from './tiers.js';
|
|
2
|
+
/** One agent that answers to the words, with the evidence for saying so. */
|
|
3
|
+
export interface EntityCandidate {
|
|
4
|
+
/** The canonical subject — an SA address (ADR-0010). */
|
|
5
|
+
agent: string;
|
|
6
|
+
/** What to call it when asking a person to choose: a name, a display name, both. */
|
|
7
|
+
label: string;
|
|
8
|
+
/** The agent's typed name when it has one (`alice.me`) — absent for an unnamed agent. */
|
|
9
|
+
name?: string;
|
|
10
|
+
/** Person / org / service, when known. A wrong-type match is a refusal, not a lower rank. */
|
|
11
|
+
kind?: string;
|
|
12
|
+
/** Spec 363 — the modelled ROLES this candidate carries (`ap:primaryPayer`, `ap:primaryPayee`), by
|
|
13
|
+
* IRI. The decision plane reads these; nothing else may, and carrying one grants nothing. */
|
|
14
|
+
roles?: readonly string[];
|
|
15
|
+
provenance: ContextProvenance;
|
|
16
|
+
}
|
|
17
|
+
/** What is being asked for. `kinds` narrows by type; `tiers` says which places may be consulted. */
|
|
18
|
+
export interface EntityQuery {
|
|
19
|
+
/** The words the person used — a name (`alice.me`), a bare label (`alice`), or an address. */
|
|
20
|
+
term: string;
|
|
21
|
+
/** Restrict to these agent kinds (person, org, service…). Empty ⇒ any. */
|
|
22
|
+
kinds?: string[];
|
|
23
|
+
/** Which tiers this lookup may read. A resolution that will bind an authority (a payee, a recipient)
|
|
24
|
+
* passes `['private']`: knowing OF somebody is not knowing them. */
|
|
25
|
+
tiers?: ContextTier[];
|
|
26
|
+
/** WHOSE private tier. Required when `private` is consulted — a private read with no subject has no
|
|
27
|
+
* authority behind it and must fail rather than fall back to a public search. */
|
|
28
|
+
subject?: string;
|
|
29
|
+
limit?: number;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* One place to look. Providers compose; each answers only for the tier it owns, and returning candidates
|
|
33
|
+
* from a tier it was not asked for is a defect the composer checks for.
|
|
34
|
+
*/
|
|
35
|
+
export interface EntityProvider {
|
|
36
|
+
/** A name a person could be told: `relationships`, `roster`, `naming`, `directory`. */
|
|
37
|
+
readonly source: string;
|
|
38
|
+
readonly tier: ContextTier;
|
|
39
|
+
candidates(query: EntityQuery): Promise<EntityCandidate[]>;
|
|
40
|
+
}
|
|
41
|
+
/** What a resolution concluded. Deliberately three cases, and `certain` is the only one that acts. */
|
|
42
|
+
export type EntityResolution = {
|
|
43
|
+
outcome: 'certain';
|
|
44
|
+
candidate: EntityCandidate;
|
|
45
|
+
} | {
|
|
46
|
+
outcome: 'ambiguous';
|
|
47
|
+
candidates: EntityCandidate[];
|
|
48
|
+
} | {
|
|
49
|
+
outcome: 'unknown';
|
|
50
|
+
looked: Array<{
|
|
51
|
+
source: string;
|
|
52
|
+
tier: ContextTier;
|
|
53
|
+
}>;
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* Ask each provider that owns a tier this query permits, in order, and report what was found — never
|
|
57
|
+
* which is likeliest.
|
|
58
|
+
*
|
|
59
|
+
* A provider that throws is skipped and NOT silently treated as empty for the purposes of the answer: an
|
|
60
|
+
* `unknown` says which sources actually answered, so "I could not find them" can be honest about where it
|
|
61
|
+
* looked. (A directory that was down is not the same as a directory that had nobody, and a person told the
|
|
62
|
+
* wrong one of those will make the wrong correction.)
|
|
63
|
+
*/
|
|
64
|
+
export declare function resolveEntity(providers: readonly EntityProvider[], query: EntityQuery): Promise<EntityResolution>;
|
|
65
|
+
//# sourceMappingURL=entities.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entities.d.ts","sourceRoot":"","sources":["../src/entities.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAEjE,4EAA4E;AAC5E,MAAM,WAAW,eAAe;IAC9B,wDAAwD;IACxD,KAAK,EAAE,MAAM,CAAC;IACd,oFAAoF;IACpF,KAAK,EAAE,MAAM,CAAC;IACd,yFAAyF;IACzF,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,6FAA6F;IAC7F,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;kGAC8F;IAC9F,KAAK,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC1B,UAAU,EAAE,iBAAiB,CAAC;CAC/B;AAED,oGAAoG;AACpG,MAAM,WAAW,WAAW;IAC1B,8FAA8F;IAC9F,IAAI,EAAE,MAAM,CAAC;IACb,0EAA0E;IAC1E,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;IACjB;yEACqE;IACrE,KAAK,CAAC,EAAE,WAAW,EAAE,CAAC;IACtB;sFACkF;IAClF,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;;GAGG;AACH,MAAM,WAAW,cAAc;IAC7B,uFAAuF;IACvF,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAC;IAC3B,UAAU,CAAC,KAAK,EAAE,WAAW,GAAG,OAAO,CAAC,eAAe,EAAE,CAAC,CAAC;CAC5D;AAED,sGAAsG;AACtG,MAAM,MAAM,gBAAgB,GACxB;IAAE,OAAO,EAAE,SAAS,CAAC;IAAC,SAAS,EAAE,eAAe,CAAA;CAAE,GAClD;IAAE,OAAO,EAAE,WAAW,CAAC;IAAC,UAAU,EAAE,eAAe,EAAE,CAAA;CAAE,GACvD;IAAE,OAAO,EAAE,SAAS,CAAC;IAAC,MAAM,EAAE,KAAK,CAAC;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,WAAW,CAAA;KAAE,CAAC,CAAA;CAAE,CAAC;AAajF;;;;;;;;GAQG;AACH,wBAAsB,aAAa,CAAC,SAAS,EAAE,SAAS,cAAc,EAAE,EAAE,KAAK,EAAE,WAAW,GAAG,OAAO,CAAC,gBAAgB,CAAC,CA4BvH"}
|
package/dist/entities.js
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
const dedupe = (found) => {
|
|
2
|
+
const byAgent = new Map();
|
|
3
|
+
for (const c of found) {
|
|
4
|
+
const key = c.agent.toLowerCase();
|
|
5
|
+
// FIRST WINS, and providers are consulted in the order the caller gave: a private answer outranks a
|
|
6
|
+
// public one about the same agent, because the private one carries the reason this person knows them.
|
|
7
|
+
if (!byAgent.has(key))
|
|
8
|
+
byAgent.set(key, { ...c, agent: key });
|
|
9
|
+
}
|
|
10
|
+
return [...byAgent.values()];
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Ask each provider that owns a tier this query permits, in order, and report what was found — never
|
|
14
|
+
* which is likeliest.
|
|
15
|
+
*
|
|
16
|
+
* A provider that throws is skipped and NOT silently treated as empty for the purposes of the answer: an
|
|
17
|
+
* `unknown` says which sources actually answered, so "I could not find them" can be honest about where it
|
|
18
|
+
* looked. (A directory that was down is not the same as a directory that had nobody, and a person told the
|
|
19
|
+
* wrong one of those will make the wrong correction.)
|
|
20
|
+
*/
|
|
21
|
+
export async function resolveEntity(providers, query) {
|
|
22
|
+
const permitted = query.tiers ?? ['private', 'public'];
|
|
23
|
+
const usable = providers.filter((p) => permitted.includes(p.tier));
|
|
24
|
+
const looked = [];
|
|
25
|
+
const found = [];
|
|
26
|
+
for (const p of usable) {
|
|
27
|
+
if (p.tier === 'private' && !query.subject)
|
|
28
|
+
continue; // a private read needs a subject, always
|
|
29
|
+
try {
|
|
30
|
+
const got = await p.candidates(query);
|
|
31
|
+
looked.push({ source: p.source, tier: p.tier });
|
|
32
|
+
for (const c of got) {
|
|
33
|
+
if (c.provenance.tier !== p.tier)
|
|
34
|
+
continue; // a provider may only answer for its own tier
|
|
35
|
+
if (query.kinds?.length && c.kind && !query.kinds.includes(c.kind))
|
|
36
|
+
continue;
|
|
37
|
+
found.push(c);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
// Skipped, and absent from `looked` — the refusal will not claim we checked somewhere we did not.
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
// THE WORDS THAT ARE A NAME OUTRANK THE WORDS THAT ARE NEAR ONE. "alice" with an exact `alice.me` and a
|
|
45
|
+
// close "Alicia" is Alice, not a question; with no exact hit the close ones are what there is — one is
|
|
46
|
+
// taken (and shown back as closest), several are asked.
|
|
47
|
+
const all = dedupe(found);
|
|
48
|
+
const exact = all.filter((c) => c.provenance.match !== 'close');
|
|
49
|
+
const unique = exact.length ? exact : all;
|
|
50
|
+
if (unique.length === 1)
|
|
51
|
+
return { outcome: 'certain', candidate: unique[0] };
|
|
52
|
+
if (unique.length === 0)
|
|
53
|
+
return { outcome: 'unknown', looked };
|
|
54
|
+
return { outcome: 'ambiguous', candidates: unique.slice(0, query.limit ?? 8) };
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=entities.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entities.js","sourceRoot":"","sources":["../src/entities.ts"],"names":[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interface CompositionViolation {
|
|
3
|
+
rule: 'false-emptiness' | 'unexplained-emptiness' | 'emptiness-without-how' | 'unattributed-subject' | 'question-unanswered' | 'base-units';
|
|
4
|
+
/** For the recompose turn: states what was claimed and what the evidence supports, as an instruction. */
|
|
5
|
+
correction: string;
|
|
6
|
+
}
|
|
7
|
+
export declare function checkGroundedComposition(text: string, evidence: AskEvidenceLike[], goal?: string): CompositionViolation[];
|
|
8
|
+
/**
|
|
9
|
+
* THE FLOOR — what is said when the composer, corrected once, still cannot stay inside its evidence.
|
|
10
|
+
* Deterministic, built FROM the evidence, and deliberately dry: after two ungrounded compositions the
|
|
11
|
+
* person gets the observations, not a third guess.
|
|
12
|
+
*/
|
|
13
|
+
export declare function groundedFallback(evidence: AskEvidenceLike[]): string;
|
|
14
|
+
//# sourceMappingURL=grounded-composition.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"grounded-composition.d.ts","sourceRoot":"","sources":["../src/grounded-composition.ts"],"names":[],"mappings":"AAsBA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAE3D,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,iBAAiB,GAAG,uBAAuB,GAAG,uBAAuB,GAAG,sBAAsB,GAAG,qBAAqB,GAAG,YAAY,CAAC;IAC5I,yGAAyG;IACzG,UAAU,EAAE,MAAM,CAAC;CACpB;AAoBD,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,eAAe,EAAE,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,oBAAoB,EAAE,CAyDzH;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,eAAe,EAAE,GAAG,MAAM,CAYpE"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/** Claims that something is absent/empty — the shapes the incidents used, kept deliberately narrow:
|
|
2
|
+
* a missed emptiness claim costs a recompose nobody sees; a false positive rewrites a good answer. */
|
|
3
|
+
const EMPTINESS_CLAIM = /\bnothing (?:matched|was found|found|came back)\b|\b(?:does not|doesn'?t|do not|don'?t)\s+(?:list|contain|hold|have|show)\s+any\b|\bthere (?:are|is) no\b|\bno \w+ (?:are |were |is |was )?(?:found|listed|recorded|exist)/i;
|
|
4
|
+
/** "How I looked" vocabulary — the qualifier that turns a world-claim into an observation-claim. */
|
|
5
|
+
const HOW_IT_LOOKED = /\bsearch(?:ed|ing)?\b|\bmatch(?:ed|ing)?\b|\bkeyword\b|\blook(?:ed)? (?:for|in|at)\b|\bquer(?:y|ied)\b|\bby name\b/i;
|
|
6
|
+
/** Possessive claims about whose records/data the answer presents. */
|
|
7
|
+
const ATTRIBUTION_CLAIM = /\b([a-z][\w .-]{1,40}?)(?:'s)?\s+(?:vault|records?|data)\s+(?:contains?|holds?|shows?|has|include)|\brecords?\s+(?:that\s+)?([a-z][\w.-]{1,40})\s+holds?\b/i;
|
|
8
|
+
/** Corrections that make a cross-subject sentence honest — "not Nathan's", "cannot be read". */
|
|
9
|
+
const CORRECTIVE = /\bnot\b|\bcannot\b|\bcould(?:n'?t| not)\b|\bunable\b|\bno (?:access|stewardship)\b|\byour own\b|\bunreadable\b/i;
|
|
10
|
+
/** A question that asks for a QUANTITY: the answer must carry one, or say the fact could not be read. */
|
|
11
|
+
const QUANTITY_QUESTION = /\b(how much|how many|what is (?:my|our|the) balance|balance|what do (?:i|we) (?:hold|have))\b/i;
|
|
12
|
+
const COULD_NOT = /\b(?:could not|couldn'?t|cannot|can'?t|unable to|not (?:readable|available)|no (?:balance|figure|amount)\b.*\b(?:read|found|available))\b/i;
|
|
13
|
+
export function checkGroundedComposition(text, evidence, goal) {
|
|
14
|
+
const out = [];
|
|
15
|
+
// ── The asked fact (spec 371) ──
|
|
16
|
+
// "what is my balance" answered with twenty receipts summed in base units was true and not an answer. A
|
|
17
|
+
// quantity question is answered by a quantity in the person's unit, or by one sentence saying the
|
|
18
|
+
// fact could not be read — never by adjacent data presented instead.
|
|
19
|
+
if (goal && QUANTITY_QUESTION.test(goal)) {
|
|
20
|
+
const hasNumber = /\d/.test(text);
|
|
21
|
+
if (!hasNumber && !COULD_NOT.test(text)) {
|
|
22
|
+
out.push({ rule: 'question-unanswered', correction: `The question asks for a quantity (“${goal}”). Lead with the figure in the person's unit, or say in one sentence that it could not be read from these results. Do not summarise other data instead.` });
|
|
23
|
+
}
|
|
24
|
+
else if (/\b\d{7,}\b/.test(text) && !/\b(usdc|usd|dollars?)\b/i.test(text)) {
|
|
25
|
+
out.push({ rule: 'base-units', correction: 'You quoted a raw seven-digit-or-longer figure with no unit. State amounts in the person\'s unit (USDC) as the results display them; never restate base units.' });
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
// ── Emptiness ──
|
|
29
|
+
const claim = text.match(EMPTINESS_CLAIM);
|
|
30
|
+
if (claim) {
|
|
31
|
+
const counted = evidence.filter((e) => typeof e.count === 'number');
|
|
32
|
+
const empties = counted.filter((e) => e.count === 0);
|
|
33
|
+
if (counted.length && !empties.length) {
|
|
34
|
+
// The false-empty incident exactly: the prose says "none" while every counted read found some.
|
|
35
|
+
out.push({
|
|
36
|
+
rule: 'false-emptiness',
|
|
37
|
+
correction: `You wrote “${claim[0]}”, but the results are not empty (${counted.map((e) => `${e.toolId}: ${e.count}`).join(', ')}). State what the results actually contain.`,
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
else if (empties.length && empties.every((e) => !e.reason && !e.searched)) {
|
|
41
|
+
out.push({
|
|
42
|
+
rule: 'unexplained-emptiness',
|
|
43
|
+
correction: `You claim emptiness but no result explains its own emptiness. Say only what was observed, without asserting that nothing exists.`,
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
else if (empties.length && !HOW_IT_LOOKED.test(text)) {
|
|
47
|
+
const how = empties.map((e) => e.searched ? `a search for “${e.searched}”` : e.reason).filter(Boolean).join('; ');
|
|
48
|
+
out.push({
|
|
49
|
+
rule: 'emptiness-without-how',
|
|
50
|
+
correction: `“${claim[0]}” states a fact about the world; the evidence supports only a fact about a lookup (${how}). Rephrase as what was searched and what matched — e.g. “nothing matched …” — not as what exists.`,
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
// ── Attribution ──
|
|
55
|
+
const attr = text.match(ATTRIBUTION_CLAIM);
|
|
56
|
+
if (attr) {
|
|
57
|
+
const possessor = (attr[1] ?? attr[2] ?? '').trim().toLowerCase().replace(/^(the|their|his|her)\s+/, '');
|
|
58
|
+
const subjects = evidence.flatMap((e) => e.subjects ?? []).map((s) => s.toLowerCase());
|
|
59
|
+
// Generic possessors ("your", "the organization") and first-person are not cross-subject claims.
|
|
60
|
+
const generic = !possessor || ['your', 'you', 'my', 'their', 'the', 'this', 'these', 'it', 'that'].includes(possessor);
|
|
61
|
+
if (!generic && subjects.length && !subjects.some((s) => s.includes(possessor)) && !CORRECTIVE.test(text)) {
|
|
62
|
+
out.push({
|
|
63
|
+
rule: 'unattributed-subject',
|
|
64
|
+
correction: `You present records as “${attr[0]}”, but the evidence read only: ${[...new Set(evidence.flatMap((e) => e.subjects ?? []))].join(', ')}. Attribute the data to whose it is, or state that ${possessor}'s could not be read.`,
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return out;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* THE FLOOR — what is said when the composer, corrected once, still cannot stay inside its evidence.
|
|
72
|
+
* Deterministic, built FROM the evidence, and deliberately dry: after two ungrounded compositions the
|
|
73
|
+
* person gets the observations, not a third guess.
|
|
74
|
+
*/
|
|
75
|
+
export function groundedFallback(evidence) {
|
|
76
|
+
if (!evidence.length)
|
|
77
|
+
return 'I have nothing I can state: no tool produced a readable result for this.';
|
|
78
|
+
const lines = evidence.map((e) => {
|
|
79
|
+
const bits = [
|
|
80
|
+
typeof e.count === 'number' ? `${e.count} result${e.count === 1 ? '' : 's'}` : null,
|
|
81
|
+
e.searched ? `searched names for “${e.searched}”` : null,
|
|
82
|
+
e.subjects?.length ? `records of ${e.subjects.join(', ')}` : null,
|
|
83
|
+
e.reason ?? null,
|
|
84
|
+
].filter(Boolean).join(' — ');
|
|
85
|
+
return `${e.toolId}: ${bits || 'ran'}`;
|
|
86
|
+
});
|
|
87
|
+
return `Here is exactly what was found, without interpretation:\n${lines.map((l) => `- ${l}`).join('\n')}`;
|
|
88
|
+
}
|
|
89
|
+
//# sourceMappingURL=grounded-composition.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"grounded-composition.js","sourceRoot":"","sources":["../src/grounded-composition.ts"],"names":[],"mappings":"AA8BA;uGACuG;AACvG,MAAM,eAAe,GACnB,6NAA6N,CAAC;AAEhO,oGAAoG;AACpG,MAAM,aAAa,GAAG,qHAAqH,CAAC;AAE5I,sEAAsE;AACtE,MAAM,iBAAiB,GAAG,6JAA6J,CAAC;AAExL,gGAAgG;AAChG,MAAM,UAAU,GAAG,iHAAiH,CAAC;AAErI,yGAAyG;AACzG,MAAM,iBAAiB,GAAG,gGAAgG,CAAC;AAC3H,MAAM,SAAS,GAAG,4IAA4I,CAAC;AAE/J,MAAM,UAAU,wBAAwB,CAAC,IAAY,EAAE,QAA2B,EAAE,IAAa;IAC/F,MAAM,GAAG,GAA2B,EAAE,CAAC;IAEvC,kCAAkC;IAClC,wGAAwG;IACxG,kGAAkG;IAClG,qEAAqE;IACrE,IAAI,IAAI,IAAI,iBAAiB,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;QACzC,MAAM,SAAS,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAClC,IAAI,CAAC,SAAS,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;YACxC,GAAG,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,qBAAqB,EAAE,UAAU,EAAE,sCAAsC,IAAI,0JAA0J,EAAE,CAAC,CAAC;QAC9P,CAAC;aAAM,IAAI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CAAC,EAAE,CAAC,CAAC,CAAC,IAAI;YACjE,CAAC,CAAC,MAAM,IAAI,IAAI;SACjB,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAC9B,OAAO,GAAG,CAAC,CAAC,MAAM,KAAK,IAAI,IAAI,KAAK,EAAE,CAAC;IACzC,CAAC,CAAC,CAAC;IACH,OAAO,4DAA4D,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;AAC7G,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export interface AskEvidenceLike {
|
|
2
|
+
toolId: string;
|
|
3
|
+
interpretation?: string;
|
|
4
|
+
query?: string;
|
|
5
|
+
count?: number;
|
|
6
|
+
searched?: string;
|
|
7
|
+
reason?: string;
|
|
8
|
+
/** WHOSE data the tool read — vault-question's `looked`/`recordsOf`, surfaced for attribution checks. */
|
|
9
|
+
subjects?: string[];
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=grounded-types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"grounded-types.d.ts","sourceRoot":"","sources":["../src/grounded-types.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,MAAM,CAAC;IACf,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,yGAAyG;IACzG,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;CACrB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"grounded-types.js","sourceRoot":"","sources":["../src/grounded-types.ts"],"names":[],"mappings":""}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export declare const PACKAGE_NAME: "@agenticprimitives/context";
|
|
2
|
+
export declare const PACKAGE_STATUS: "w1-ports";
|
|
3
|
+
export declare const SPEC_REF: "specs/351-agentic-primitives-substrate-program.md";
|
|
4
|
+
export type { ContextTier, ContextProvenance } from './tiers.js';
|
|
5
|
+
export type { EntityCandidate, EntityQuery, EntityProvider, EntityResolution } from './entities.js';
|
|
6
|
+
export { resolveEntity } from './entities.js';
|
|
7
|
+
export { nameMatch, nameWords, saidKind, labelForms, KIND_WORDS } from './name-match.js';
|
|
8
|
+
export type { ContextFact, ContextRequest, ContextBundle, ContextProvider } from './provider.js';
|
|
9
|
+
export { gatherContext } from './provider.js';
|
|
10
|
+
export type { StructuredCall } from './structured-call.js';
|
|
11
|
+
export type { AskEvidenceLike } from './grounded-types.js';
|
|
12
|
+
export { checkGroundedComposition, groundedFallback, type CompositionViolation } from './grounded-composition.js';
|
|
13
|
+
export { rememberPreference, learnedPreferences, preferenceFor, preferenceKey, PREFERENCE_PREFIX, type LearnedPreferenceV1, type MemoryDeps, } from './memory.js';
|
|
14
|
+
export * from './relationship-rows.js';
|
|
15
|
+
export * from './directory-rows.js';
|
|
16
|
+
export * from './private-context.js';
|
|
17
|
+
export * from './standing.js';
|
|
18
|
+
export * from './self-only.js';
|
|
19
|
+
export * from './party-resolution.js';
|
|
20
|
+
export * from './ask-discovery.js';
|
|
21
|
+
export * from './kb-question.js';
|
|
22
|
+
export * from './vault-question.js';
|
|
23
|
+
export * from './membership-read.js';
|
|
24
|
+
export * from './affiliations-read.js';
|
|
25
|
+
export * from './invitations-read.js';
|
|
26
|
+
export { rememberTurn, recentParties, pronounOf, pronounRecall, chosenBefore, conversationForPrompt, CONVERSATION_RECORD } from './conversation.js';
|
|
27
|
+
export type { RecentPartyV1, RecentTurnV1, ConversationMemoryV1 } from './conversation.js';
|
|
28
|
+
export { rememberConfirmation, preferredChoice, forgetConfirmation, CONFIRMATION_RECORD } from './confirmation.js';
|
|
29
|
+
export type { ConfirmationPreferencesV1, ConfirmationEntryV1 } from './confirmation.js';
|
|
30
|
+
export { declareInstruction, standingFor, forgetInstruction, instructionContextOf, STANDING_RECORD, ANY_CONTEXT } from './instructions.js';
|
|
31
|
+
export type { StandingInstructionsV1, StandingInstructionV1 } from './instructions.js';
|
|
32
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,YAAY,EAAG,4BAAqC,CAAC;AAClE,eAAO,MAAM,cAAc,EAAG,UAAmB,CAAC;AAClD,eAAO,MAAM,QAAQ,EAAG,mDAA4D,CAAC;AAErF,YAAY,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AACjE,YAAY,EAAE,eAAe,EAAE,WAAW,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACpG,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAE9C,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,QAAQ,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AACzF,YAAY,EAAE,WAAW,EAAE,cAAc,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AACjG,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAO9C,YAAY,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAC3D,YAAY,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAC3D,OAAO,EAAE,wBAAwB,EAAE,gBAAgB,EAAE,KAAK,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AAClH,OAAO,EACL,kBAAkB,EAAE,kBAAkB,EAAE,aAAa,EAAE,aAAa,EAAE,iBAAiB,EACvF,KAAK,mBAAmB,EAAE,KAAK,UAAU,GAC1C,MAAM,aAAa,CAAC;AACrB,cAAc,wBAAwB,CAAC;AACvC,cAAc,qBAAqB,CAAC;AACpC,cAAc,sBAAsB,CAAC;AACrC,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,uBAAuB,CAAC;AACtC,cAAc,oBAAoB,CAAC;AACnC,cAAc,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC;AACpC,cAAc,sBAAsB,CAAC;AACrC,cAAc,wBAAwB,CAAC;AACvC,cAAc,uBAAuB,CAAC;AACtC,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,SAAS,EAAE,aAAa,EAAE,YAAY,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AACpJ,YAAY,EAAE,aAAa,EAAE,YAAY,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAC3F,OAAO,EAAE,oBAAoB,EAAE,eAAe,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AACnH,YAAY,EAAE,yBAAyB,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AACxF,OAAO,EAAE,kBAAkB,EAAE,WAAW,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAC3I,YAAY,EAAE,sBAAsB,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// @agenticprimitives/context — the two-tier context contract (spec 351 P0.11 / spec 350 §6).
|
|
2
|
+
//
|
|
3
|
+
// Pure ports. No transport, no vault client, no chain read: an implementation lives where the data does
|
|
4
|
+
// (the app that holds the delegation, the service that owns the KB). What lives here is the SHAPE that
|
|
5
|
+
// makes a private fact distinguishable from a public one at the point of use, and the resolution contract
|
|
6
|
+
// that refuses to guess who somebody meant.
|
|
7
|
+
export const PACKAGE_NAME = '@agenticprimitives/context';
|
|
8
|
+
export const PACKAGE_STATUS = 'w1-ports';
|
|
9
|
+
export const SPEC_REF = 'specs/351-agentic-primitives-substrate-program.md';
|
|
10
|
+
export { resolveEntity } from './entities.js';
|
|
11
|
+
// A GRADE, never a score: `nameSimilarity` stays inside the module — the threshold is a matching rule.
|
|
12
|
+
export { nameMatch, nameWords, saidKind, labelForms, KIND_WORDS } from './name-match.js';
|
|
13
|
+
export { gatherContext } from './provider.js';
|
|
14
|
+
export { checkGroundedComposition, groundedFallback } from './grounded-composition.js';
|
|
15
|
+
export { rememberPreference, learnedPreferences, preferenceFor, preferenceKey, PREFERENCE_PREFIX, } from './memory.js';
|
|
16
|
+
export * from './relationship-rows.js';
|
|
17
|
+
export * from './directory-rows.js';
|
|
18
|
+
export * from './private-context.js';
|
|
19
|
+
export * from './standing.js';
|
|
20
|
+
export * from './self-only.js';
|
|
21
|
+
export * from './party-resolution.js';
|
|
22
|
+
export * from './ask-discovery.js';
|
|
23
|
+
export * from './kb-question.js';
|
|
24
|
+
export * from './vault-question.js';
|
|
25
|
+
export * from './membership-read.js';
|
|
26
|
+
export * from './affiliations-read.js';
|
|
27
|
+
export * from './invitations-read.js';
|
|
28
|
+
export { rememberTurn, recentParties, pronounOf, pronounRecall, chosenBefore, conversationForPrompt, CONVERSATION_RECORD } from './conversation.js';
|
|
29
|
+
export { rememberConfirmation, preferredChoice, forgetConfirmation, CONFIRMATION_RECORD } from './confirmation.js';
|
|
30
|
+
export { declareInstruction, standingFor, forgetInstruction, instructionContextOf, STANDING_RECORD, ANY_CONTEXT } from './instructions.js';
|
|
31
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,6FAA6F;AAC7F,EAAE;AACF,wGAAwG;AACxG,uGAAuG;AACvG,0GAA0G;AAC1G,4CAA4C;AAC5C,MAAM,CAAC,MAAM,YAAY,GA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
2
|
+
export interface StandingInstructionsV1 {
|
|
3
|
+
type: 'ap.context.standing-instructions.v1';
|
|
4
|
+
entries: StandingInstructionV1[];
|
|
5
|
+
}
|
|
6
|
+
export interface StandingInstructionV1 {
|
|
7
|
+
/** `any`, or the address of the organization the person was acting for when they declared it. */
|
|
8
|
+
context: string;
|
|
9
|
+
/** The capability the default is FOR (an ADR-0051 id, e.g. `treasury.payment.execute`). */
|
|
10
|
+
capability: string;
|
|
11
|
+
/** The argument it fills (`payer`, `org`, …). */
|
|
12
|
+
arg: string;
|
|
13
|
+
/** The default — an agent address, lower-cased. Evidence, never authority. */
|
|
14
|
+
value: string;
|
|
15
|
+
label?: string;
|
|
16
|
+
/** The person's own words, read back before it was kept. */
|
|
17
|
+
saidAs?: string;
|
|
18
|
+
at: string;
|
|
19
|
+
runRef?: string;
|
|
20
|
+
}
|
|
21
|
+
export declare const STANDING_RECORD = "standing.instructions";
|
|
22
|
+
export declare const ANY_CONTEXT = "any";
|
|
23
|
+
/** The room as a key: an organization's address, else `any`. */
|
|
24
|
+
export declare const instructionContextOf: (c: string | undefined) => string;
|
|
25
|
+
/**
|
|
26
|
+
* The instructions with one more, newest first, capped. A newer instruction for the SAME scope (context +
|
|
27
|
+
* capability + arg) replaces the older one — correctable, and the last thing the person said is what holds.
|
|
28
|
+
* An empty capability or arg, or a non-address value, writes nothing.
|
|
29
|
+
*/
|
|
30
|
+
export declare function declareInstruction(rec: StandingInstructionsV1 | null | undefined, i: {
|
|
31
|
+
context?: string;
|
|
32
|
+
capability: string;
|
|
33
|
+
arg: string;
|
|
34
|
+
value: string;
|
|
35
|
+
label?: string;
|
|
36
|
+
saidAs?: string;
|
|
37
|
+
runRef?: string;
|
|
38
|
+
at?: string;
|
|
39
|
+
}): StandingInstructionsV1;
|
|
40
|
+
/**
|
|
41
|
+
* The standing default for this capability's argument in this room: the exact context first, then `any`.
|
|
42
|
+
* A default declared for a DIFFERENT organization never matches. The caller revalidates the value against
|
|
43
|
+
* what the person may name now; this only remembers.
|
|
44
|
+
*/
|
|
45
|
+
export declare function standingFor(rec: StandingInstructionsV1 | null | undefined, scope: {
|
|
46
|
+
capability: string;
|
|
47
|
+
arg: string;
|
|
48
|
+
context?: string;
|
|
49
|
+
}): StandingInstructionV1 | null;
|
|
50
|
+
/** Drop one instruction (the person clearing it in the open). */
|
|
51
|
+
export declare function forgetInstruction(rec: StandingInstructionsV1 | null | undefined, scope: {
|
|
52
|
+
context?: string;
|
|
53
|
+
capability: string;
|
|
54
|
+
arg: string;
|
|
55
|
+
}): StandingInstructionsV1;
|
|
56
|
+
//# sourceMappingURL=instructions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"instructions.d.ts","sourceRoot":"","sources":["../src/instructions.ts"],"names":[],"mappings":"AAcA,gEAAgE;AAChE,MAAM,WAAW,sBAAsB;IACrC,IAAI,EAAE,qCAAqC,CAAC;IAC5C,OAAO,EAAE,qBAAqB,EAAE,CAAC;CAClC;AAED,MAAM,WAAW,qBAAqB;IACpC,iGAAiG;IACjG,OAAO,EAAE,MAAM,CAAC;IAChB,2FAA2F;IAC3F,UAAU,EAAE,MAAM,CAAC;IACnB,iDAAiD;IACjD,GAAG,EAAE,MAAM,CAAC;IACZ,8EAA8E;IAC9E,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,4DAA4D;IAC5D,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,eAAO,MAAM,eAAe,0BAA0B,CAAC;AACvD,eAAO,MAAM,WAAW,QAAQ,CAAC;AAGjC,gEAAgE;AAChE,eAAO,MAAM,oBAAoB,MAAO,MAAM,GAAG,SAAS,KAAG,MAA2F,CAAC;AAGzJ;;;;GAIG;AACH,wBAAgB,kBAAkB,CAChC,GAAG,EAAE,sBAAsB,GAAG,IAAI,GAAG,SAAS,EAC9C,CAAC,EAAE;IAAE,OAAO,CAAC,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,EAAE,CAAC,EAAE,MAAM,CAAA;CAAE,GACrI,sBAAsB,CAWxB;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CACzB,GAAG,EAAE,sBAAsB,GAAG,IAAI,GAAG,SAAS,EAC9C,KAAK,EAAE;IAAE,UAAU,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAA;CAAE,GAC3D,qBAAqB,GAAG,IAAI,CAO9B;AAED,iEAAiE;AACjE,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,sBAAsB,GAAG,IAAI,GAAG,SAAS,EAAE,KAAK,EAAE;IAAE,OAAO,CAAC,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,GAAG,sBAAsB,CAGtK"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
// STANDING INSTRUCTIONS — spec 394. A person's own DECLARED DEFAULT for one argument of one capability,
|
|
2
|
+
// scoped to the room they were standing in when they said it ("from now on, pay from alice3.treasury";
|
|
3
|
+
// "when I act for Missio Nexus, invitations come from the organization"). It fills an argument the person
|
|
4
|
+
// did NOT speak — never one they did — and it authorizes nothing (ADR-0041): the mandate is asked and
|
|
5
|
+
// signed as if nothing were remembered. Written only from a trusted event (the person's supplied "yes" to
|
|
6
|
+
// the read-back of the instruction), revalidated at every use by the caller, cited on the binding
|
|
7
|
+
// (`source: standing`), correctable in the open, and kept in the person's own vault (ADR-0055 / 358 W5).
|
|
8
|
+
//
|
|
9
|
+
// THE ACTING CONTEXT IS A NAMESPACE: `any` for the person's own agent; the organization's address when the
|
|
10
|
+
// ask was addressed to it. Read for the exact context first, then `any` — a default declared for one
|
|
11
|
+
// organization is not read in another, and a default declared at home applies wherever the person has not
|
|
12
|
+
// said otherwise. (Not `standing.ts` — that module is spec 353's STANDING, a person's derived footing in an
|
|
13
|
+
// organization; this is what they INSTRUCTED.)
|
|
14
|
+
export const STANDING_RECORD = 'standing.instructions';
|
|
15
|
+
export const ANY_CONTEXT = 'any';
|
|
16
|
+
const CAP = 200;
|
|
17
|
+
const norm = (s) => s.trim().toLowerCase();
|
|
18
|
+
/** The room as a key: an organization's address, else `any`. */
|
|
19
|
+
export const instructionContextOf = (c) => { const v = norm(c ?? ''); return /^0x[0-9a-f]{40}$/.test(v) ? v : ANY_CONTEXT; };
|
|
20
|
+
const keyOf = (e) => `${instructionContextOf(e.context)} ${norm(e.capability)} ${norm(e.arg)}`;
|
|
21
|
+
/**
|
|
22
|
+
* The instructions with one more, newest first, capped. A newer instruction for the SAME scope (context +
|
|
23
|
+
* capability + arg) replaces the older one — correctable, and the last thing the person said is what holds.
|
|
24
|
+
* An empty capability or arg, or a non-address value, writes nothing.
|
|
25
|
+
*/
|
|
26
|
+
export function declareInstruction(rec, i) {
|
|
27
|
+
const existing = rec?.entries ?? [];
|
|
28
|
+
const capability = norm(i.capability);
|
|
29
|
+
const arg = norm(i.arg);
|
|
30
|
+
const value = norm(i.value);
|
|
31
|
+
if (!capability || !arg || !/^0x[0-9a-f]{40}$/.test(value))
|
|
32
|
+
return { type: 'ap.context.standing-instructions.v1', entries: existing.slice(0, CAP) };
|
|
33
|
+
const entry = {
|
|
34
|
+
context: instructionContextOf(i.context), capability, arg, value,
|
|
35
|
+
...(i.label ? { label: i.label } : {}), ...(i.saidAs ? { saidAs: i.saidAs } : {}),
|
|
36
|
+
at: i.at ?? new Date().toISOString(), ...(i.runRef ? { runRef: i.runRef } : {}),
|
|
37
|
+
};
|
|
38
|
+
const k = keyOf(entry);
|
|
39
|
+
return { type: 'ap.context.standing-instructions.v1', entries: [entry, ...existing.filter((e) => keyOf(e) !== k)].slice(0, CAP) };
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* The standing default for this capability's argument in this room: the exact context first, then `any`.
|
|
43
|
+
* A default declared for a DIFFERENT organization never matches. The caller revalidates the value against
|
|
44
|
+
* what the person may name now; this only remembers.
|
|
45
|
+
*/
|
|
46
|
+
export function standingFor(rec, scope) {
|
|
47
|
+
const entries = rec?.entries ?? [];
|
|
48
|
+
const hit = entries.find((e) => keyOf(e) === keyOf(scope));
|
|
49
|
+
if (hit)
|
|
50
|
+
return hit;
|
|
51
|
+
if (instructionContextOf(scope.context) === ANY_CONTEXT)
|
|
52
|
+
return null;
|
|
53
|
+
const general = keyOf({ ...scope, context: ANY_CONTEXT });
|
|
54
|
+
return entries.find((e) => keyOf(e) === general) ?? null;
|
|
55
|
+
}
|
|
56
|
+
/** Drop one instruction (the person clearing it in the open). */
|
|
57
|
+
export function forgetInstruction(rec, scope) {
|
|
58
|
+
const k = keyOf(scope);
|
|
59
|
+
return { type: 'ap.context.standing-instructions.v1', entries: (rec?.entries ?? []).filter((e) => keyOf(e) !== k) };
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=instructions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"instructions.js","sourceRoot":"","sources":["../src/instructions.ts"],"names":[],"mappings":"AAAA,wGAAwG;AACxG,uGAAuG;AACvG,0GAA0G;AAC1G,sGAAsG;AACtG,0GAA0G;AAC1G,kGAAkG;AAClG,yGAAyG;AACzG,EAAE;AACF,2GAA2G;AAC3G,qGAAqG;AACrG,0GAA0G;AAC1G,4GAA4G;AAC5G,+CAA+C;AAwB/C,MAAM,CAAC,MAAM,eAAe,GAAG,uBAAuB,CAAC;AACvD,MAAM,CAAC,MAAM,WAAW,GAAG,KAAK,CAAC;AACjC,MAAM,GAAG,GAAG,GAAG,CAAC;AAChB,MAA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