@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
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Agentic Trust Labs
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# @agenticprimitives/context
|
|
2
|
+
|
|
3
|
+
The two-tier context contract: **public** knowledge (reproducible from chain state — ADR-0040) and a
|
|
4
|
+
subject's **private** records (their relationships and rosters — ADR-0025), with the tier carried on every
|
|
5
|
+
fact so the two can never be quietly mixed.
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
import { resolveEntity, type EntityProvider } from '@agenticprimitives/context';
|
|
9
|
+
|
|
10
|
+
// "who did they mean by alice?" — asked only of the asker's own tier, because this answer
|
|
11
|
+
// will become the payee of a mandate.
|
|
12
|
+
const outcome = await resolveEntity(providers, { term: 'alice', tiers: ['private'], subject: askerSa });
|
|
13
|
+
|
|
14
|
+
switch (outcome.outcome) {
|
|
15
|
+
case 'certain': return outcome.candidate.agent;
|
|
16
|
+
case 'ambiguous': return ask(outcome.candidates); // the person chooses; nothing is ranked
|
|
17
|
+
case 'unknown': return refuse(outcome.looked); // and say where we looked
|
|
18
|
+
}
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
There is no `score`, and there will not be one: a ranked list with a confident top entry is
|
|
22
|
+
indistinguishable from certainty, which is how a payment reaches the wrong person.
|
|
23
|
+
|
|
24
|
+
See `CLAUDE.md` for the boundary and `spec.md` for the invariants.
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { ToolSpec, ToolInvoker } from '@agenticprimitives/orchestration';
|
|
2
|
+
import type { Address } from '@agenticprimitives/types';
|
|
3
|
+
import { type RelationshipRow } from './relationship-rows.js';
|
|
4
|
+
/** The words a person uses for each derived type, as the tool's argument enum. The KEYS are the ADR-0061
|
|
5
|
+
* suffixes — the ontology's own vocabulary — so a new type joins by being declared there, not here. */
|
|
6
|
+
export declare const AFFILIATION_TYPES: string[];
|
|
7
|
+
export declare const AFFILIATIONS_LIST_TOOL: ToolSpec;
|
|
8
|
+
export interface AffiliationsDeps {
|
|
9
|
+
readSubjectRecord?: (subject: string, recordType: string) => Promise<unknown>;
|
|
10
|
+
}
|
|
11
|
+
/** The class a link row claims: its recorded `kind` when it names a type, else the name's typed suffix
|
|
12
|
+
* (ADR-0061). A legacy untyped root (`.impact`, `.agent`) claims nothing — reported as such, never
|
|
13
|
+
* guessed into a class. */
|
|
14
|
+
export declare function affiliationTypeOf(row: Pick<RelationshipRow, 'name' | 'kind'>): {
|
|
15
|
+
type: string | null;
|
|
16
|
+
classIri: string | null;
|
|
17
|
+
};
|
|
18
|
+
export declare function affiliationsListInvoker(deps: AffiliationsDeps, principal?: Address): ToolInvoker;
|
|
19
|
+
//# sourceMappingURL=affiliations-read.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"affiliations-read.d.ts","sourceRoot":"","sources":["../src/affiliations-read.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,kCAAkC,CAAC;AAC9E,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AAExD,OAAO,EAAoB,KAAK,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAEhF;wGACwG;AACxG,eAAO,MAAM,iBAAiB,UAA0D,CAAC;AAEzF,eAAO,MAAM,sBAAsB,EAAE,QAYpC,CAAC;AAEF,MAAM,WAAW,gBAAgB;IAC/B,iBAAiB,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;CAC/E;AAED;;4BAE4B;AAC5B,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,IAAI,CAAC,eAAe,EAAE,MAAM,GAAG,MAAM,CAAC,GAAG;IAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,CAS/H;AAED,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,gBAAgB,EAAE,SAAS,CAAC,EAAE,OAAO,GAAG,WAAW,CAoChG"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { CLASS_FOR_SUFFIX, AGENT_CLASS } from '@agenticprimitives/ontology';
|
|
2
|
+
import { relationshipRows } from './relationship-rows.js';
|
|
3
|
+
/** The words a person uses for each derived type, as the tool's argument enum. The KEYS are the ADR-0061
|
|
4
|
+
* suffixes — the ontology's own vocabulary — so a new type joins by being declared there, not here. */
|
|
5
|
+
export const AFFILIATION_TYPES = Object.keys(CLASS_FOR_SUFFIX).filter((s) => s !== 'me');
|
|
6
|
+
export const AFFILIATIONS_LIST_TOOL = {
|
|
7
|
+
id: 'person.affiliations.list',
|
|
8
|
+
description: 'ANSWERS A QUESTION: which organizations, teams, workspaces, circles, churches or treasuries the person '
|
|
9
|
+
+ 'asking is linked to — "what teams am I on", "which organizations do I belong to", "what circles am I '
|
|
10
|
+
+ 'part of", "do I have a treasury". Their own private links, grouped by AGENT TYPE. Use this, never '
|
|
11
|
+
+ 'organization.membership.list (that lists WHO is in ONE organization) and never a records query. '
|
|
12
|
+
+ 'Args: type (optional) — one of ' + AFFILIATION_TYPES.join(', ') + '; omit it to list every type.',
|
|
13
|
+
inputSchema: {
|
|
14
|
+
type: 'object',
|
|
15
|
+
properties: { type: { type: 'string', enum: AFFILIATION_TYPES, description: 'The derived agent type asked about (team, org, circle, church, treasury, workspace…). Omit for all.' } },
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
/** The class a link row claims: its recorded `kind` when it names a type, else the name's typed suffix
|
|
19
|
+
* (ADR-0061). A legacy untyped root (`.impact`, `.agent`) claims nothing — reported as such, never
|
|
20
|
+
* guessed into a class. */
|
|
21
|
+
export function affiliationTypeOf(row) {
|
|
22
|
+
const kind = (row.kind ?? '').toLowerCase();
|
|
23
|
+
if (kind && CLASS_FOR_SUFFIX[kind])
|
|
24
|
+
return { type: kind, classIri: CLASS_FOR_SUFFIX[kind] };
|
|
25
|
+
// A recorded kind the suffix table does not know is app vocabulary that maps DOWN to a class (ADR-0046):
|
|
26
|
+
// `organization`/`organisation` → org. Anything else is left to the suffix.
|
|
27
|
+
if (kind === 'organization' || kind === 'organisation')
|
|
28
|
+
return { type: 'org', classIri: AGENT_CLASS.OrganizationAgent };
|
|
29
|
+
const suffix = row.name.toLowerCase().split('.').pop() ?? '';
|
|
30
|
+
if (row.name.includes('.') && CLASS_FOR_SUFFIX[suffix])
|
|
31
|
+
return { type: suffix, classIri: CLASS_FOR_SUFFIX[suffix] };
|
|
32
|
+
return { type: null, classIri: null };
|
|
33
|
+
}
|
|
34
|
+
export function affiliationsListInvoker(deps, principal) {
|
|
35
|
+
return async (_toolId, args) => {
|
|
36
|
+
const wanted = String(args.type ?? '').trim().toLowerCase() || null;
|
|
37
|
+
if (!principal)
|
|
38
|
+
return { count: 0, links: [], refused: 'this agent does not know who is asking' };
|
|
39
|
+
if (!deps.readSubjectRecord)
|
|
40
|
+
return { count: 0, links: [], refused: 'this agent cannot read your links' };
|
|
41
|
+
if (wanted && !CLASS_FOR_SUFFIX[wanted]) {
|
|
42
|
+
return { count: 0, links: [], refused: `“${wanted}” is not an agent type this estate has — the types are ${AFFILIATION_TYPES.join(', ')}` };
|
|
43
|
+
}
|
|
44
|
+
const doc = await deps.readSubjectRecord(principal, 'relationships.data');
|
|
45
|
+
const rows = relationshipRows(doc);
|
|
46
|
+
const links = rows.map((r) => {
|
|
47
|
+
const t = affiliationTypeOf(r);
|
|
48
|
+
return {
|
|
49
|
+
agent: r.agent, name: r.name,
|
|
50
|
+
type: t.type ?? 'untyped',
|
|
51
|
+
...(t.classIri ? { class: t.classIri } : {}),
|
|
52
|
+
// How they stand there: a steward holds a wire; a member does not. A treasury or workspace of their
|
|
53
|
+
// own is HELD (chartered under them), which the composer is told below — it is not "joined".
|
|
54
|
+
relationship: r.relationship,
|
|
55
|
+
...(r.parent ? { parent: r.parent } : {}),
|
|
56
|
+
};
|
|
57
|
+
});
|
|
58
|
+
const chosen = wanted ? links.filter((l) => l.type === wanted) : links;
|
|
59
|
+
const byType = {};
|
|
60
|
+
for (const l of links)
|
|
61
|
+
byType[l.type] = (byType[l.type] ?? 0) + 1;
|
|
62
|
+
const typeWord = wanted ? `${wanted}${chosen.length === 1 ? '' : 's'}` : 'links';
|
|
63
|
+
return {
|
|
64
|
+
subject: principal.toLowerCase(), asked: wanted ?? 'all', count: chosen.length, links: chosen, byType,
|
|
65
|
+
interpretation: wanted
|
|
66
|
+
? `the ${typeWord} in your own links — ${chosen.length} of ${links.length} link${links.length === 1 ? '' : 's'}, by the agent's typed name or recorded kind (ADR-0061)`
|
|
67
|
+
: `every agent in your own links, grouped by type — your private record, published nowhere`,
|
|
68
|
+
note: wanted && chosen.length === 0 && links.length > 0
|
|
69
|
+
? `answer that you are linked to no ${wanted}, then say what you ARE linked to from byType (e.g. ${Object.entries(byType).map(([k, v]) => `${v} ${k}`).join(', ')}). Never call a treasury, workspace or organization a ${wanted}.`
|
|
70
|
+
: `answer by naming each agent with its TYPE as given (a team is a team, a treasury is a treasury; "untyped" is a legacy name that claims no type — say so rather than guessing). A treasury or workspace is HELD by you, not joined. Say whether you are a steward or a member where it matters.`,
|
|
71
|
+
};
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=affiliations-read.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"affiliations-read.js","sourceRoot":"","sources":["../src/affiliations-read.ts"],"names":[],"mappings":"AAYA,OAAO,EAAE,gBAAgB,EAAoB,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAC9F,OAAO,EAAE,gBAAgB,EAAwB,MAAM,wBAAwB,CAAC;AAEhF;wGACwG;AACxG,MAAM,CAAC,MAAM,iBAAiB,GAAG,MAAM,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC;AAEzF,MAAM,CAAC,MAAM,sBAAsB,GAAa;IAC9C,EAAE,EAAE,0BAA0B;IAC9B,WAAW,EACT,yGAAyG;UACvG,uGAAuG;UACvG,oGAAoG;UACpG,kGAAkG;UAClG,iCAAiC,GAAG,iBAAiB,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,+BAA+B;IACtG,WAAW,EAAE;QACX,IAAI,EAAE,QAAQ;QACd,UAAU,EAAE,EAAE,IAAI,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,i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yDAAyD,MAAM,GAAG;gBACnO,CAAC,CAAC,gSAAgS;SACrS,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ToolSpec, ToolInvoker } from '@agenticprimitives/orchestration';
|
|
2
|
+
/** Reach the discovery MCP — a PORT, because how it is reached is deployment (a Cloudflare service
|
|
3
|
+
* binding, a base URL in dev) and this package is not. `null` = not configured, which the caller turns
|
|
4
|
+
* into an honest throw rather than an empty answer. */
|
|
5
|
+
export type DiscoveryFetch = (path: string, init?: RequestInit) => Promise<Response | null>;
|
|
6
|
+
/** The Ask's read tools. All `informational` — no `capability`, so the loop never asks for authority to
|
|
7
|
+
* read what the chain already publishes. */
|
|
8
|
+
export declare const ASK_DISCOVERY_TOOLS: ToolSpec[];
|
|
9
|
+
export declare const ASK_DISCOVERY_TOOL_IDS: Set<string>;
|
|
10
|
+
/** Invoke one discovery read. Public data only, in and out. */
|
|
11
|
+
export declare function askDiscoveryInvoker(deps: {
|
|
12
|
+
fetchDiscovery: DiscoveryFetch;
|
|
13
|
+
resolveName?: (name: string) => Promise<string | null>;
|
|
14
|
+
}): ToolInvoker;
|
|
15
|
+
//# sourceMappingURL=ask-discovery.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ask-discovery.d.ts","sourceRoot":"","sources":["../src/ask-discovery.ts"],"names":[],"mappings":"AAmCA,OAAO,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,kCAAkC,CAAC;AAC9E;;wDAEwD;AACxD,MAAM,MAAM,cAAc,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC,CAAC;AAY5F;6CAC6C;AAC7C,eAAO,MAAM,mBAAmB,EAAE,QAAQ,EAsCzC,CAAC;AAEF,eAAO,MAAM,sBAAsB,aAAgD,CAAC;AAEpF,+DAA+D;AAC/D,wBAAgB,mBAAmB,CAAC,IAAI,EAAE;IAAE,cAAc,EAAE,cAAc,CAAC;IAAC,WAAW,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAA;CAAE,GAAG,WAAW,CAkCjJ"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
const MAX_ROWS = 25;
|
|
2
|
+
async function discovery(fetchDiscovery, path, init) {
|
|
3
|
+
const res = await fetchDiscovery(path, init);
|
|
4
|
+
if (!res)
|
|
5
|
+
throw new Error('the public agent directory is not reachable from this agent (no discovery binding)');
|
|
6
|
+
const body = (await res.json().catch(() => null));
|
|
7
|
+
if (!res.ok || !body || body.ok !== true)
|
|
8
|
+
throw new Error(`the public agent directory returned ${res.status}${body?.error ? `: ${String(body.error)}` : ''}`);
|
|
9
|
+
return body;
|
|
10
|
+
}
|
|
11
|
+
/** The Ask's read tools. All `informational` — no `capability`, so the loop never asks for authority to
|
|
12
|
+
* read what the chain already publishes. */
|
|
13
|
+
export const ASK_DISCOVERY_TOOLS = [
|
|
14
|
+
{
|
|
15
|
+
id: 'find_agents',
|
|
16
|
+
description: 'KEYWORD SEARCH BY NAME — finds agents whose NAME or declared capabilities contain your search words. '
|
|
17
|
+
+ 'Use it when the ask names something ("the outreach team in greeley", "find alice"). '
|
|
18
|
+
+ 'It is NOT a census and NOT a category listing: searching for "organizations" matches agents CALLED '
|
|
19
|
+
+ 'that, and returns nothing in a directory full of them. For "what organizations are there", "how '
|
|
20
|
+
+ 'many teams", "which agents have X" — anything that counts, lists or filters a KIND — use '
|
|
21
|
+
+ 'kb.question instead. `terms` are search words only — never the user\'s full question, and never who '
|
|
22
|
+
+ 'is asking. Returns public, on-chain-derived facts: name, address, kind, declared capabilities.',
|
|
23
|
+
inputSchema: {
|
|
24
|
+
type: 'object',
|
|
25
|
+
properties: {
|
|
26
|
+
terms: { type: 'string', description: 'Search words, e.g. "outreach team greeley". Keep it to the entities being asked about.' },
|
|
27
|
+
limit: { type: 'number', description: `How many rows (max ${MAX_ROWS}).` },
|
|
28
|
+
},
|
|
29
|
+
required: ['terms'],
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
id: 'get_agent',
|
|
34
|
+
description: 'ANSWERS A QUESTION about one agent — never a way to turn a name into an address for another tool '
|
|
35
|
+
+ '(the capabilities take names directly). '
|
|
36
|
+
+ 'Read one agent from the PUBLIC directory by its typed name (e.g. "outreach.team") or its 0x smart-agent ' +
|
|
37
|
+
'address. Returns its public profile, declared type and capabilities. Use this when the ask names a ' +
|
|
38
|
+
'specific agent.',
|
|
39
|
+
inputSchema: { type: 'object', properties: { key: { type: 'string', description: 'A typed name or a 0x address.' } }, required: ['key'] },
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
id: 'list_agent_facets',
|
|
43
|
+
description: 'The shape of the PUBLIC directory: which agent types, name suffixes and capability ids exist, with ' +
|
|
44
|
+
'how many agents declare each. Use it to answer "what kinds of agents are there" and to pick valid ' +
|
|
45
|
+
'terms before searching. Needs no arguments.',
|
|
46
|
+
inputSchema: { type: 'object', properties: {} },
|
|
47
|
+
},
|
|
48
|
+
];
|
|
49
|
+
export const ASK_DISCOVERY_TOOL_IDS = new Set(ASK_DISCOVERY_TOOLS.map((t) => t.id));
|
|
50
|
+
/** Invoke one discovery read. Public data only, in and out. */
|
|
51
|
+
export function askDiscoveryInvoker(deps) {
|
|
52
|
+
return async (toolId, args) => {
|
|
53
|
+
if (toolId === 'find_agents') {
|
|
54
|
+
const terms = String(args.terms ?? '').trim();
|
|
55
|
+
if (!terms)
|
|
56
|
+
throw new Error('find_agents needs search terms');
|
|
57
|
+
const limit = Math.min(Number(args.limit ?? MAX_ROWS) || MAX_ROWS, MAX_ROWS);
|
|
58
|
+
const body = await discovery(deps.fetchDiscovery, `/search?q=${encodeURIComponent(terms)}&limit=${limit}`);
|
|
59
|
+
const agents = (body.agents ?? body.results ?? []);
|
|
60
|
+
// SAY WHAT WAS DONE, not just what came back. `{agents: [], count: 0}` reads as "there are none",
|
|
61
|
+
// and a composer duly wrote "The directory does not list any organizations" for a directory holding
|
|
62
|
+
// 37 of them — because the search was a NAME match for the word "organizations", which nothing is
|
|
63
|
+
// called. An empty result is an answer (ADR-0013); it is an answer to the question that was asked,
|
|
64
|
+
// and this says which question that was.
|
|
65
|
+
return {
|
|
66
|
+
agents, count: agents.length, searchedNamesFor: terms,
|
|
67
|
+
...(agents.length ? {} : {
|
|
68
|
+
note: `No agent's name or declared capabilities matched "${terms}". This was a keyword match, not a listing — it does NOT mean the directory holds none of that kind. To count or list a KIND of agent, use kb.question.`,
|
|
69
|
+
}),
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
if (toolId === 'get_agent') {
|
|
73
|
+
const key = String(args.key ?? '').trim();
|
|
74
|
+
if (!key)
|
|
75
|
+
throw new Error('get_agent needs a name or address');
|
|
76
|
+
const { ok, ...agent } = await discovery(deps.fetchDiscovery, `/agent?key=${encodeURIComponent(key)}`);
|
|
77
|
+
void ok;
|
|
78
|
+
return agent;
|
|
79
|
+
}
|
|
80
|
+
if (toolId === 'list_agent_facets') {
|
|
81
|
+
const { ok, ...facets } = await discovery(deps.fetchDiscovery, '/facets');
|
|
82
|
+
void ok;
|
|
83
|
+
return facets;
|
|
84
|
+
}
|
|
85
|
+
throw new Error(`${toolId} is not a discovery read`);
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
//# sourceMappingURL=ask-discovery.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ask-discovery.js","sourceRoot":"","sources":["../src/ask-discovery.ts"],"names":[],"mappings":"AAyCA,MAAM,QAAQ,GAAG,EAAE,CAAC;AAEpB,KAAK,UAAU,SAAS,CAAC,cAA8B,EAAE,IAAY,EAAE,IAAkB;IACvF,MAAM,GAAG,GAAG,MAAM,cAAc,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAC7C,IAA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D,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;oBACvB,IAAI,EAAE,qDAAqD,KAAK,yJAAyJ;iBAC1N,CAAC;aACH,CAAC;QACJ,CAAC;QACD,IAAI,MAAM,KAAK,WAAW,EAAE,CAAC;YAC3B,MAAM,GAAG,GAAG,MAAM,CAAE,IAA0B,CAAC,GAAG,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;YACjE,IAAI,CAAC,GAAG;gBAAE,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAC;YAC/D,MAAM,EAAE,EAAE,EAAE,GAAG,KAAK,EAAE,GAAG,MAAM,SAAS,CAAC,IAAI,CAAC,cAAc,EAAE,cAAc,kBAAkB,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;YACvG,KAAK,EAAE,CAAC;YACR,OAAO,KAAK,CAAC;QACf,CAAC;QACD,IAAI,MAAM,KAAK,mBAAmB,EAAE,CAAC;YACnC,MAAM,EAAE,EAAE,EAAE,GAAG,MAAM,EAAE,GAAG,MAAM,SAAS,CAAC,IAAI,CAAC,cAAc,EAAE,SAAS,CAAC,CAAC;YAC1E,KAAK,EAAE,CAAC;YACR,OAAO,MAAM,CAAC;QAChB,CAAC;QACD,MAAM,IAAI,KAAK,CAAC,GAAG,MAAM,0BAA0B,CAAC,CAAC;IACvD,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/** The person's vault record of their scoped confirmation preferences. */
|
|
2
|
+
export interface ConfirmationPreferencesV1 {
|
|
3
|
+
type: 'ap.context.confirmation-preferences.v1';
|
|
4
|
+
entries: ConfirmationEntryV1[];
|
|
5
|
+
}
|
|
6
|
+
export interface ConfirmationEntryV1 {
|
|
7
|
+
/** The word the person used, lower-cased ("david", "sam"). */
|
|
8
|
+
word: string;
|
|
9
|
+
/** The capability the resolution was FOR (an ADR-0051 id, e.g. `treasury.payment.execute`). */
|
|
10
|
+
capability: string;
|
|
11
|
+
/** The argument the word filled (`payee`, `member`, …). */
|
|
12
|
+
arg: string;
|
|
13
|
+
/** Spec 394 — the room the choice was made in: absent (the person's own agent) or the organization's address
|
|
14
|
+
* the ask was addressed to. Read for the same room first, then the room-less entry. */
|
|
15
|
+
context?: string;
|
|
16
|
+
/** The agent the person confirmed, lower-cased. Evidence, never authority. */
|
|
17
|
+
agent: string;
|
|
18
|
+
label?: string;
|
|
19
|
+
at: string;
|
|
20
|
+
runRef?: string;
|
|
21
|
+
}
|
|
22
|
+
export declare const CONFIRMATION_RECORD = "confirmation.preferences";
|
|
23
|
+
/**
|
|
24
|
+
* The preferences with one more confirmation, newest first, capped. A newer confirmation for the SAME scope
|
|
25
|
+
* (word + capability + arg) replaces the older one — the memory is correctable, and the last thing the person
|
|
26
|
+
* did is what it remembers. An empty word, capability, arg or a non-address agent writes nothing.
|
|
27
|
+
*/
|
|
28
|
+
export declare function rememberConfirmation(prefs: ConfirmationPreferencesV1 | null | undefined, c: {
|
|
29
|
+
word: string;
|
|
30
|
+
capability: string;
|
|
31
|
+
arg: string;
|
|
32
|
+
agent: string;
|
|
33
|
+
label?: string;
|
|
34
|
+
runRef?: string;
|
|
35
|
+
at?: string;
|
|
36
|
+
context?: string;
|
|
37
|
+
}): ConfirmationPreferencesV1;
|
|
38
|
+
/**
|
|
39
|
+
* The remembered choice for this scope IF it is still one of the candidates found now — revalidated, so a
|
|
40
|
+
* treasury that was deleted or a person who left the household is never silently reused. Scope is EXACT: a
|
|
41
|
+
* different capability or a different argument does not match, so the payee "David" never leaks into the
|
|
42
|
+
* invitee "David". `null` when nothing is remembered or the memory no longer holds.
|
|
43
|
+
*/
|
|
44
|
+
export declare function preferredChoice(prefs: ConfirmationPreferencesV1 | null | undefined, scope: {
|
|
45
|
+
word: string;
|
|
46
|
+
capability: string;
|
|
47
|
+
arg: string;
|
|
48
|
+
context?: string;
|
|
49
|
+
}, candidates: ReadonlyArray<{
|
|
50
|
+
agent: string;
|
|
51
|
+
}>): ConfirmationEntryV1 | null;
|
|
52
|
+
/** Drop one remembered scope (the person clearing it — W2's correct-in-the-open). */
|
|
53
|
+
export declare function forgetConfirmation(prefs: ConfirmationPreferencesV1 | null | undefined, scope: {
|
|
54
|
+
word: string;
|
|
55
|
+
capability: string;
|
|
56
|
+
arg: string;
|
|
57
|
+
context?: string;
|
|
58
|
+
}): ConfirmationPreferencesV1;
|
|
59
|
+
//# sourceMappingURL=confirmation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"confirmation.d.ts","sourceRoot":"","sources":["../src/confirmation.ts"],"names":[],"mappings":"AAOA,0EAA0E;AAC1E,MAAM,WAAW,yBAAyB;IACxC,IAAI,EAAE,wCAAwC,CAAC;IAC/C,OAAO,EAAE,mBAAmB,EAAE,CAAC;CAChC;AAED,MAAM,WAAW,mBAAmB;IAClC,8DAA8D;IAC9D,IAAI,EAAE,MAAM,CAAC;IACb,+FAA+F;IAC/F,UAAU,EAAE,MAAM,CAAC;IACnB,2DAA2D;IAC3D,GAAG,EAAE,MAAM,CAAC;IACZ;4FACwF;IACxF,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,8EAA8E;IAC9E,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,eAAO,MAAM,mBAAmB,6BAA6B,CAAC;AAM9D;;;;GAIG;AACH,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,yBAAyB,GAAG,IAAI,GAAG,SAAS,EACnD,CAAC,EAAE;IAAE,IAAI,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,EAAE,CAAC,EAAE,MAAM,CAAE;IAAC,OAAO,CAAC,EAAE,MAAM,CAAA;CAAE,GACnI,yBAAyB,CAW3B;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAC7B,KAAK,EAAE,yBAAyB,GAAG,IAAI,GAAG,SAAS,EACnD,KAAK,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAA;CAAE,EAC1E,UAAU,EAAE,aAAa,CAAC;IAAE,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC,GAC3C,mBAAmB,GAAG,IAAI,CAO5B;AAED,qFAAqF;AACrF,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,yBAAyB,GAAG,IAAI,GAAG,SAAS,EAAE,KAAK,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,yBAAyB,CAG7L"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// SCOPED CONFIRMATION MEMORY — spec 385 (367 W5). A confirmed choice is EVIDENCE about a choice, scoped to
|
|
2
|
+
// (word, capability, argument), and it authorizes nothing (ADR-0041). It is the person's OWN vault record
|
|
3
|
+
// (358 W5 / ADR-0055), written only from a trusted interaction event — the resume in which the person supplied
|
|
4
|
+
// the choice a prompt asked for — and used to prefill or rank the next ambiguous resolution of the same word
|
|
5
|
+
// in the same place, revalidated against the candidates found THAT time. Durable where the rolling conversation
|
|
6
|
+
// window (spec 370 P7) decays; scoped where it was only ever the words.
|
|
7
|
+
export const CONFIRMATION_RECORD = 'confirmation.preferences';
|
|
8
|
+
const CAP = 200;
|
|
9
|
+
const norm = (s) => s.trim().toLowerCase();
|
|
10
|
+
const contextOf = (c) => { const v = norm(c ?? ''); return /^0x[0-9a-f]{40}$/.test(v) ? v : ''; };
|
|
11
|
+
const keyOf = (e) => `${norm(e.word)} ${norm(e.capability)} ${norm(e.arg)}${contextOf(e.context) ? ` @${contextOf(e.context)}` : ''}`;
|
|
12
|
+
/**
|
|
13
|
+
* The preferences with one more confirmation, newest first, capped. A newer confirmation for the SAME scope
|
|
14
|
+
* (word + capability + arg) replaces the older one — the memory is correctable, and the last thing the person
|
|
15
|
+
* did is what it remembers. An empty word, capability, arg or a non-address agent writes nothing.
|
|
16
|
+
*/
|
|
17
|
+
export function rememberConfirmation(prefs, c) {
|
|
18
|
+
const word = norm(c.word);
|
|
19
|
+
const capability = norm(c.capability);
|
|
20
|
+
const arg = norm(c.arg);
|
|
21
|
+
const agent = norm(c.agent);
|
|
22
|
+
const existing = prefs?.entries ?? [];
|
|
23
|
+
if (!word || !capability || !arg || !/^0x[0-9a-f]{40}$/.test(agent)) {
|
|
24
|
+
return { type: 'ap.context.confirmation-preferences.v1', entries: existing.slice(0, CAP) };
|
|
25
|
+
}
|
|
26
|
+
const context = contextOf(c.context);
|
|
27
|
+
const entry = { word, capability, arg, ...(context ? { context } : {}), agent, ...(c.label ? { label: c.label } : {}), at: c.at ?? new Date().toISOString(), ...(c.runRef ? { runRef: c.runRef } : {}) };
|
|
28
|
+
const k = keyOf(entry);
|
|
29
|
+
const rest = existing.filter((e) => keyOf(e) !== k);
|
|
30
|
+
return { type: 'ap.context.confirmation-preferences.v1', entries: [entry, ...rest].slice(0, CAP) };
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* The remembered choice for this scope IF it is still one of the candidates found now — revalidated, so a
|
|
34
|
+
* treasury that was deleted or a person who left the household is never silently reused. Scope is EXACT: a
|
|
35
|
+
* different capability or a different argument does not match, so the payee "David" never leaks into the
|
|
36
|
+
* invitee "David". `null` when nothing is remembered or the memory no longer holds.
|
|
37
|
+
*/
|
|
38
|
+
export function preferredChoice(prefs, scope, candidates) {
|
|
39
|
+
const entries = prefs?.entries ?? [];
|
|
40
|
+
// Spec 394 — the same room first, then the room-less entry; a choice made for ANOTHER organization never matches.
|
|
41
|
+
const entry = entries.find((e) => keyOf(e) === keyOf(scope)) ?? (contextOf(scope.context) ? entries.find((e) => keyOf(e) === keyOf({ ...scope, context: undefined })) : undefined);
|
|
42
|
+
if (!entry)
|
|
43
|
+
return null;
|
|
44
|
+
const agents = new Set(candidates.map((c) => c.agent.toLowerCase()));
|
|
45
|
+
return agents.has(entry.agent) ? entry : null;
|
|
46
|
+
}
|
|
47
|
+
/** Drop one remembered scope (the person clearing it — W2's correct-in-the-open). */
|
|
48
|
+
export function forgetConfirmation(prefs, scope) {
|
|
49
|
+
const k = keyOf(scope);
|
|
50
|
+
return { type: 'ap.context.confirmation-preferences.v1', entries: (prefs?.entries ?? []).filter((e) => keyOf(e) !== k) };
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=confirmation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"confirmation.js","sourceRoot":"","sources":["../src/confirmation.ts"],"names":[],"mappings":"AAAA,2GAA2G;AAC3G,0GAA0G;AAC1G,+GAA+G;AAC/G,6GAA6G;AAC7G,gHAAgH;AAChH,wEAAwE;AAyBxE,MAAM,CAAC,MAAM,mBAAmB,GAAG,0BAA0B,CAAC;AAC9D,MAAM,GAAG,GAAG,GAAG,CAAC;AAChB,MAAM,IAAI,GAAG,CAAC,CAAS,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;AACnD,MAAM,SAAS,GAAG,CAAC,CAAqB,EAAE,EAAE,GAAG,MAAM,CAAC,GAAG,IAAI,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,OAAO,kBAAkB,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;AACtH,MAAM,KAAK,GAAG,CAAC,CAAsE,EAAE,EAAE,CA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AAI,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC;IACrE,OAAO,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC;AAChD,CAAC;AAED,qFAAqF;AACrF,MAAM,UAAU,kBAAkB,CAAC,KAAmD,EAAE,KAA0E;IAChK,MAAM,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC;IACvB,OAAO,EAAE,IAAI,EAAE,wCAAwC,EAAE,OAAO,EAAE,CAAC,KAAK,EAAE,OAAO,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC;AAC3H,CAAC"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
export interface RecentPartyV1 {
|
|
2
|
+
/** The argument it filled (payee, org, invitee…). */
|
|
3
|
+
arg: string;
|
|
4
|
+
/** The words the person used. */
|
|
5
|
+
raw: string;
|
|
6
|
+
/** What they resolved to. */
|
|
7
|
+
agent: string;
|
|
8
|
+
label?: string;
|
|
9
|
+
/** The agent's kind when known (person, org, team, treasury…). */
|
|
10
|
+
kind?: string;
|
|
11
|
+
}
|
|
12
|
+
export interface RecentTurnV1 {
|
|
13
|
+
at: string;
|
|
14
|
+
runRef: string;
|
|
15
|
+
addressee: string;
|
|
16
|
+
said: string;
|
|
17
|
+
/** What the turn came to: answer · done · prompt · authority_required · refused. */
|
|
18
|
+
kind: string;
|
|
19
|
+
parties: RecentPartyV1[];
|
|
20
|
+
}
|
|
21
|
+
export interface ConversationMemoryV1 {
|
|
22
|
+
type: 'ap.context.conversation-memory.v1';
|
|
23
|
+
turns: RecentTurnV1[];
|
|
24
|
+
}
|
|
25
|
+
export declare const CONVERSATION_RECORD = "conversation.recent";
|
|
26
|
+
/** The memory with one more turn, newest first, capped. A turn that resolved nobody and was an answer is
|
|
27
|
+
* still worth a line — "what was that?" is a real question — but it is the parties that pay rent. */
|
|
28
|
+
export declare function rememberTurn(memory: ConversationMemoryV1 | null | undefined, turn: RecentTurnV1): ConversationMemoryV1;
|
|
29
|
+
/** The recalled parties, newest first, the same addressee's first. */
|
|
30
|
+
export declare function recentParties(memory: ConversationMemoryV1 | null | undefined, opts?: {
|
|
31
|
+
addressee?: string;
|
|
32
|
+
limit?: number;
|
|
33
|
+
}): Array<RecentPartyV1 & {
|
|
34
|
+
at: string;
|
|
35
|
+
said: string;
|
|
36
|
+
addressee: string;
|
|
37
|
+
}>;
|
|
38
|
+
/** A pronoun, and whom it can stand for: a PERSON pronoun never resolves to an organization, and "it"
|
|
39
|
+
* never to a person. `null` when the words are not a pronoun at all. */
|
|
40
|
+
export declare function pronounOf(raw: string): {
|
|
41
|
+
wants: 'person' | 'thing' | 'any';
|
|
42
|
+
} | null;
|
|
43
|
+
/** The party a pronoun means: the most recent recalled party that fits the pronoun and the role's types. */
|
|
44
|
+
export declare function pronounRecall(raw: string, recalled: ReadonlyArray<RecentPartyV1 & {
|
|
45
|
+
said?: string;
|
|
46
|
+
}>, types?: readonly string[]): (RecentPartyV1 & {
|
|
47
|
+
said?: string;
|
|
48
|
+
}) | null;
|
|
49
|
+
/** "The one you chose last time": among several candidates for the SAME words, the one a recent turn
|
|
50
|
+
* resolved those words to. Exact words only — memory disambiguates a repeated shorthand, it does not
|
|
51
|
+
* fuzzy-match. Null when no recent turn settled these words on one of these candidates. */
|
|
52
|
+
export declare function chosenBefore(raw: string, candidates: ReadonlyArray<{
|
|
53
|
+
agent: string;
|
|
54
|
+
}>, recalled: ReadonlyArray<RecentPartyV1 & {
|
|
55
|
+
said?: string;
|
|
56
|
+
}>): (RecentPartyV1 & {
|
|
57
|
+
said?: string;
|
|
58
|
+
}) | null;
|
|
59
|
+
/** The compact form a planner is shown: the last few asks and what their words meant. */
|
|
60
|
+
export declare function conversationForPrompt(memory: ConversationMemoryV1 | null | undefined, addressee?: string, turns?: number): string;
|
|
61
|
+
//# sourceMappingURL=conversation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"conversation.d.ts","sourceRoot":"","sources":["../src/conversation.ts"],"names":[],"mappings":"AAWA,MAAM,WAAW,aAAa;IAC5B,qDAAqD;IACrD,GAAG,EAAE,MAAM,CAAC;IACZ,iCAAiC;IACjC,GAAG,EAAE,MAAM,CAAC;IACZ,6BAA6B;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,kEAAkE;IAClE,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,YAAY;IAC3B,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,oFAAoF;IACpF,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,aAAa,EAAE,CAAC;CAC1B;AAED,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,mCAAmC,CAAC;IAC1C,KAAK,EAAE,YAAY,EAAE,CAAC;CACvB;AAED,eAAO,MAAM,mBAAmB,wBAAwB,CAAC;AAGzD;sGACsG;AACtG,wBAAgB,YAAY,CAAC,MAAM,EAAE,oBAAoB,GAAG,IAAI,GAAG,SAAS,EAAE,IAAI,EAAE,YAAY,GAAG,oBAAoB,CAGtH;AAED,sEAAsE;AACtE,wBAAgB,aAAa,CAAC,MAAM,EAAE,oBAAoB,GAAG,IAAI,GAAG,SAAS,EAAE,IAAI,GAAE;IAAE,SAAS,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAO,GAAG,KAAK,CAAC,aAAa,GAAG;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,CAAC,CAMxM;AAED;yEACyE;AACzE,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG;IAAE,KAAK,EAAE,QAAQ,GAAG,OAAO,GAAG,KAAK,CAAA;CAAE,GAAG,IAAI,CAKnF;AAgBD,4GAA4G;AAC5G,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,aAAa,CAAC,aAAa,GAAG;IAAE,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,EAAE,KAAK,CAAC,EAAE,SAAS,MAAM,EAAE,GAAG,CAAC,aAAa,GAAG;IAAE,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,GAAG,IAAI,CAI5K;AAED;;4FAE4F;AAC5F,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,UAAU,EAAE,aAAa,CAAC;IAAE,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC,EAAE,QAAQ,EAAE,aAAa,CAAC,aAAa,GAAG;IAAE,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,GAAG,CAAC,aAAa,GAAG;IAAE,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,GAAG,IAAI,CAI9L;AAED,yFAAyF;AACzF,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,oBAAoB,GAAG,IAAI,GAAG,SAAS,EAAE,SAAS,CAAC,EAAE,MAAM,EAAE,KAAK,SAAI,GAAG,MAAM,CAK5H"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
export const CONVERSATION_RECORD = 'conversation.recent';
|
|
2
|
+
const WINDOW = 12;
|
|
3
|
+
/** The memory with one more turn, newest first, capped. A turn that resolved nobody and was an answer is
|
|
4
|
+
* still worth a line — "what was that?" is a real question — but it is the parties that pay rent. */
|
|
5
|
+
export function rememberTurn(memory, turn) {
|
|
6
|
+
const turns = [turn, ...(memory?.turns ?? []).filter((t) => t.runRef !== turn.runRef)].slice(0, WINDOW);
|
|
7
|
+
return { type: 'ap.context.conversation-memory.v1', turns };
|
|
8
|
+
}
|
|
9
|
+
/** The recalled parties, newest first, the same addressee's first. */
|
|
10
|
+
export function recentParties(memory, opts = {}) {
|
|
11
|
+
const turns = [...(memory?.turns ?? [])];
|
|
12
|
+
const same = opts.addressee ? turns.filter((t) => t.addressee.toLowerCase() === opts.addressee.toLowerCase()) : turns;
|
|
13
|
+
const other = opts.addressee ? turns.filter((t) => t.addressee.toLowerCase() !== opts.addressee.toLowerCase()) : [];
|
|
14
|
+
const out = [...same, ...other].flatMap((t) => t.parties.map((p) => ({ ...p, at: t.at, said: t.said, addressee: t.addressee })));
|
|
15
|
+
return out.slice(0, opts.limit ?? 24);
|
|
16
|
+
}
|
|
17
|
+
/** A pronoun, and whom it can stand for: a PERSON pronoun never resolves to an organization, and "it"
|
|
18
|
+
* never to a person. `null` when the words are not a pronoun at all. */
|
|
19
|
+
export function pronounOf(raw) {
|
|
20
|
+
const t = raw.trim().toLowerCase().replace(/[.!?]+$/, '');
|
|
21
|
+
if (/^(him|her|them|they|he|she|that person|the same person|the same one|the same)$/.test(t))
|
|
22
|
+
return { wants: 'person' };
|
|
23
|
+
if (/^(it|that|that one|this one|there|the same place|the same account|the same team|the same organization|the same treasury)$/.test(t))
|
|
24
|
+
return { wants: 'thing' };
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
const PERSON_KINDS = new Set(['person', 'me']);
|
|
28
|
+
function fits(p, wants, types) {
|
|
29
|
+
const kind = (p.kind ?? (p.label?.includes('.') ? p.label.split('.').pop() : undefined) ?? '').toLowerCase();
|
|
30
|
+
if (types?.length && kind && !types.includes(kind) && !(kind === 'person' && types.includes('me')))
|
|
31
|
+
return false;
|
|
32
|
+
// A PERSON'S ACCOUNT, REACHED BY THE PERSON'S NAME, IS STILL THE PERSON. "send nathan 1 USDC" resolves
|
|
33
|
+
// the words "nathan" to nathan.treasury (the account he is paid into); "send him 2 USDC" means nathan,
|
|
34
|
+
// and what he is paid into is that same account. So a treasury a BARE NAME resolved to fits a person
|
|
35
|
+
// pronoun; a treasury named by its typed name ("nathan.treasury", "the treasury") is a thing, never a him.
|
|
36
|
+
const bareName = !p.raw.includes('.') && /^[a-z][a-z' -]*$/i.test(p.raw.trim()) && !/\b(treasury|account|org|organization|team|household)\b/i.test(p.raw);
|
|
37
|
+
if (wants === 'person')
|
|
38
|
+
return !kind || PERSON_KINDS.has(kind) || (kind === 'treasury' && bareName);
|
|
39
|
+
if (wants === 'thing')
|
|
40
|
+
return !!kind && !PERSON_KINDS.has(kind);
|
|
41
|
+
return true;
|
|
42
|
+
}
|
|
43
|
+
/** The party a pronoun means: the most recent recalled party that fits the pronoun and the role's types. */
|
|
44
|
+
export function pronounRecall(raw, recalled, types) {
|
|
45
|
+
const pn = pronounOf(raw);
|
|
46
|
+
if (!pn)
|
|
47
|
+
return null;
|
|
48
|
+
return recalled.find((p) => fits(p, pn.wants, types)) ?? null;
|
|
49
|
+
}
|
|
50
|
+
/** "The one you chose last time": among several candidates for the SAME words, the one a recent turn
|
|
51
|
+
* resolved those words to. Exact words only — memory disambiguates a repeated shorthand, it does not
|
|
52
|
+
* fuzzy-match. Null when no recent turn settled these words on one of these candidates. */
|
|
53
|
+
export function chosenBefore(raw, candidates, recalled) {
|
|
54
|
+
const t = raw.trim().toLowerCase();
|
|
55
|
+
const agents = new Set(candidates.map((c) => c.agent.toLowerCase()));
|
|
56
|
+
return recalled.find((p) => p.raw.trim().toLowerCase() === t && agents.has(p.agent.toLowerCase())) ?? null;
|
|
57
|
+
}
|
|
58
|
+
/** The compact form a planner is shown: the last few asks and what their words meant. */
|
|
59
|
+
export function conversationForPrompt(memory, addressee, turns = 4) {
|
|
60
|
+
const recent = [...(memory?.turns ?? [])].filter((t) => !addressee || t.addressee.toLowerCase() === addressee.toLowerCase()).slice(0, turns);
|
|
61
|
+
if (!recent.length)
|
|
62
|
+
return '';
|
|
63
|
+
const lines = recent.map((t) => `- "${t.said}" → ${t.kind}${t.parties.length ? `; ${t.parties.map((p) => `${p.arg}: "${p.raw}" = ${p.label ?? p.agent}`).join(', ')}` : ''}`);
|
|
64
|
+
return `\n\nRECENT ASKS BY THIS PERSON (newest first; a pronoun or a repeated name refers to these — keep the person's WORDS as arguments, never these addresses):\n${lines.join('\n')}`;
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=conversation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"conversation.js","sourceRoot":"","sources":["../src/conversation.ts"],"names":[],"mappings":"AAsCA,MAAM,CAAC,MAAM,mBAAmB,GAAG,qBAAqB,CAAC;AACzD,MAAM,MAAM,GAAG,EAAE,CAAC;AAElB;sGACsG;AACtG,MAAM,UAAU,YAAY,CAAC,MAA+C,EAAE,IAAkB;IAC9F,MAAM,KAAK,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,MAAM,EAAE,KAAK,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,KAAK,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC;IACxG,OAAO,EAAE,IAAI,EAAE,mCAAmC,EAAE,KAAK,EAAE,CAAC;AAC9D,CAAC;AAED,sEAAsE;AACtE,MAAM,UAAU,aAAa,CAAC,MAA+C,EAAE,OAA+C,EAAE;IAC9H,MAAM,KAAK,GAAG,CAAC,GAAG,CAAC,MAAM,EAAE,KAAK,IAAI,EAAE,CAAC,CAAC,CAAC;IACzC,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,WAAW,EAAE,KAAK,IAAI,CAAC,SAAU,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,CAAC,KAAK,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O,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IAC9K,OAAO,+JAA+J,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;AAC3L,CAAC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
export interface RosterRow {
|
|
2
|
+
/** The member's SA address, lower-cased. */
|
|
3
|
+
agent: string;
|
|
4
|
+
/** What to call them: their public name, their org-local label, or their display name. */
|
|
5
|
+
name: string | null;
|
|
6
|
+
/** How this membership is evidenced — a self-published listing, or the org's own invitation record. */
|
|
7
|
+
via: 'listing' | 'invitation' | 'membership';
|
|
8
|
+
role?: string;
|
|
9
|
+
/** Household membership (spec 368): how this member is related to the founder — `aphh:kinRelation`. */
|
|
10
|
+
kin?: string;
|
|
11
|
+
/** An invitation's status (`pending` | `declined` | `redeemed`), when the record says. */
|
|
12
|
+
status?: string;
|
|
13
|
+
}
|
|
14
|
+
/** The roster, from `directory.data` in any shape it has ever been written. */
|
|
15
|
+
export declare function rosterRows(doc: unknown): RosterRow[];
|
|
16
|
+
/**
|
|
17
|
+
* MEMBERS THE ORGANIZATION ITSELF RECORDED — `org.invite:agent:<sa>` records in its own vault.
|
|
18
|
+
*
|
|
19
|
+
* A listing is SELF-published: a member who joined by invitation and never published one is a real member
|
|
20
|
+
* with no listing, and reading listings alone hides them. The organization's own invitation records name
|
|
21
|
+
* them, live in its own vault, and are exactly as authoritative as the roster: the org wrote them when it
|
|
22
|
+
* admitted somebody.
|
|
23
|
+
*
|
|
24
|
+
* This is the vault-side half of the union the Home's roster already computes. It is NOT complete for
|
|
25
|
+
* members admitted before that record existed — those are only in a Home cache, which is a finding, not
|
|
26
|
+
* something to paper over here.
|
|
27
|
+
*/
|
|
28
|
+
export declare function invitedMemberRows(recordTypes: readonly string[], bodies: Record<string, unknown>): RosterRow[];
|
|
29
|
+
/**
|
|
30
|
+
* THE ORGANIZATION'S OWN MEMBERSHIP RECORDS — `org.membership:member:<sa>`, spec 325's shape.
|
|
31
|
+
*
|
|
32
|
+
* This is the roster proper. A listing is what a member says about themselves; an invitation is how they
|
|
33
|
+
* came to be admitted (the T-box files invitations under "Enrollment instruments — NOT membership"). The
|
|
34
|
+
* membership record is the organization's own statement that they belong, carrying the role assignment
|
|
35
|
+
* and the delegation that materialises it.
|
|
36
|
+
*/
|
|
37
|
+
export declare function membershipRows(recordTypes: readonly string[], bodies: Record<string, unknown>): RosterRow[];
|
|
38
|
+
/** Listings and invitations are two views of one roster; a member in both is one member. A listing wins
|
|
39
|
+
* on the name, because the member wrote it about themselves. */
|
|
40
|
+
export declare function mergeRoster(listings: RosterRow[], invited: RosterRow[]): RosterRow[];
|
|
41
|
+
//# sourceMappingURL=directory-rows.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"directory-rows.d.ts","sourceRoot":"","sources":["../src/directory-rows.ts"],"names":[],"mappings":"AAeA,MAAM,WAAW,SAAS;IACxB,4CAA4C;IAC5C,KAAK,EAAE,MAAM,CAAC;IACd,0FAA0F;IAC1F,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,uGAAuG;IACvG,GAAG,EAAE,SAAS,GAAG,YAAY,GAAG,YAAY,CAAC;IAC7C,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,uGAAuG;IACvG,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,0FAA0F;IAC1F,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAkBD,+EAA+E;AAC/E,wBAAgB,UAAU,CAAC,GAAG,EAAE,OAAO,GAAG,SAAS,EAAE,CAepD;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,iBAAiB,CAAC,WAAW,EAAE,SAAS,MAAM,EAAE,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,EAAE,CAc9G;AAED;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAC,WAAW,EAAE,SAAS,MAAM,EAAE,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,EAAE,CAuB3G;AAED;iEACiE;AACjE,wBAAgB,WAAW,CAAC,QAAQ,EAAE,SAAS,EAAE,EAAE,OAAO,EAAE,SAAS,EAAE,GAAG,SAAS,EAAE,CAKpF"}
|