@handsforbots/conversation-state 0.0.0-stage → 2.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/dist/server.js ADDED
@@ -0,0 +1,128 @@
1
+ /**
2
+ * For the backend (Node, Deno, edge): reads the `conversation.state` the page
3
+ * sends (ADR 0019) and tells the model how to update it. No dependency on
4
+ * the browser or on `@handsforbots/core`.
5
+ *
6
+ * The state comes from the browser, so anyone can edit it: treat it as what
7
+ * the conversation says, not as authorization.
8
+ */
9
+ import { CONFIDENCE, isRecord, STATE_KEY, } from './shared.js';
10
+ export { conversationStatePrompt, DEFAULT_SECTIONS, STATE_ACTION, STATE_KEY, stateUpdateSchema, } from './shared.js';
11
+ const ORIGINS = ['user', 'assistant', 'tool', 'app', 'unsourced'];
12
+ /**
13
+ * Finds and checks the state in what the transport sent:
14
+ * - the AG-UI `context` array (`{ description, value: 'conversation.state: {…}' }`);
15
+ * - the context object of `@handsforbots/transport-http` (`{ 'conversation.state': [{…}] }`);
16
+ * - an array of H4B signals (a `data` part named `conversation.state`);
17
+ * - the value itself, as an object or a string.
18
+ *
19
+ * const state = readConversationState(input.context)
20
+ * const project = state?.sections.topic
21
+ *
22
+ * Returns undefined when there is none; drops malformed items. Never throws.
23
+ */
24
+ export function readConversationState(source, options = {}) {
25
+ const raw = locate(source);
26
+ if (!isRecord(raw) || !isRecord(raw.sections) || !Number.isInteger(raw.revision) || raw.revision < 0)
27
+ return undefined;
28
+ const maxItems = options.maxItems ?? 100;
29
+ const maxChars = options.maxChars ?? 2000;
30
+ const sections = {};
31
+ for (const [name, value] of Object.entries(raw.sections)) {
32
+ if (options.sections && !options.sections.includes(name))
33
+ continue;
34
+ if (value === null)
35
+ sections[name] = null;
36
+ else if (Array.isArray(value))
37
+ sections[name] = value.slice(0, maxItems).map((v) => item(v, maxChars)).filter((v) => !!v);
38
+ else {
39
+ const one = item(value, maxChars);
40
+ if (one)
41
+ sections[name] = one;
42
+ }
43
+ }
44
+ const view = { revision: raw.revision, sections };
45
+ if (Array.isArray(raw.rejected)) {
46
+ const rejected = raw.rejected.filter((r) => isRecord(r) && typeof r.reason === 'string' && typeof r.index === 'number').slice(0, 50);
47
+ if (rejected.length)
48
+ view.rejected = rejected;
49
+ }
50
+ return view;
51
+ }
52
+ /** Items of every section, flattened, optionally only those of one scope (`'acme'`). */
53
+ export function stateItems(view, filter = {}) {
54
+ if (!view)
55
+ return [];
56
+ const out = [];
57
+ for (const [section, value] of Object.entries(view.sections)) {
58
+ for (const entry of value === null ? [] : Array.isArray(value) ? value : [value]) {
59
+ if (filter.scope === undefined || entry.scope === filter.scope)
60
+ out.push({ ...entry, section });
61
+ }
62
+ }
63
+ return out;
64
+ }
65
+ function item(value, maxChars) {
66
+ if (!isRecord(value) || typeof value.id !== 'string' || typeof value.text !== 'string')
67
+ return undefined;
68
+ if (value.text.length > maxChars || value.id.length > 64)
69
+ return undefined;
70
+ const origin = ORIGINS.includes(value.origin) ? value.origin : 'unsourced';
71
+ const confidence = CONFIDENCE.includes(value.confidence) ? value.confidence : 'low';
72
+ const out = { id: value.id, text: value.text, origin, confidence };
73
+ if (typeof value.scope === 'string' && value.scope.length <= 64)
74
+ out.scope = value.scope;
75
+ if (isRecord(value.attrs)) {
76
+ const attrs = Object.entries(value.attrs).filter(([k, v]) => k.length <= 32 && (typeof v === 'boolean' || (typeof v === 'number' && Number.isFinite(v)) || (typeof v === 'string' && v.length <= 200)));
77
+ if (attrs.length)
78
+ out.attrs = Object.fromEntries(attrs.slice(0, 16));
79
+ }
80
+ if (Array.isArray(value.src)) {
81
+ const src = value.src.filter((s) => typeof s === 'string' && s.length <= 128).slice(0, 10);
82
+ if (src.length)
83
+ out.src = src;
84
+ }
85
+ if (typeof value.stated === 'string' && !Number.isNaN(Date.parse(value.stated)))
86
+ out.stated = value.stated;
87
+ if (value.locked === true)
88
+ out.locked = true;
89
+ return out;
90
+ }
91
+ function parse(text) {
92
+ const trimmed = text.trim();
93
+ const body = trimmed.startsWith(`${STATE_KEY}:`) ? trimmed.slice(STATE_KEY.length + 1) : trimmed;
94
+ try {
95
+ return JSON.parse(body);
96
+ }
97
+ catch {
98
+ return undefined;
99
+ }
100
+ }
101
+ function locate(source) {
102
+ if (typeof source === 'string')
103
+ return parse(source);
104
+ if (Array.isArray(source)) {
105
+ for (const entry of source) {
106
+ if (!isRecord(entry))
107
+ continue;
108
+ if (Array.isArray(entry.parts)) {
109
+ const part = entry.parts.find((p) => isRecord(p) && p.type === 'data' && p.name === STATE_KEY);
110
+ if (isRecord(part))
111
+ return part.value;
112
+ continue;
113
+ }
114
+ if (typeof entry.value === 'string' && entry.value.trim().startsWith(`${STATE_KEY}:`))
115
+ return parse(entry.value);
116
+ }
117
+ return undefined;
118
+ }
119
+ if (isRecord(source)) {
120
+ if (Object.hasOwn(source, STATE_KEY)) {
121
+ const value = source[STATE_KEY];
122
+ return Array.isArray(value) ? value[0] : value;
123
+ }
124
+ return source;
125
+ }
126
+ return undefined;
127
+ }
128
+ //# sourceMappingURL=server.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EACL,UAAU,EACV,QAAQ,EACR,SAAS,GAMV,MAAM,aAAa,CAAA;AAEpB,OAAO,EACL,uBAAuB,EACvB,gBAAgB,EAChB,YAAY,EACZ,SAAS,EACT,iBAAiB,GAWlB,MAAM,aAAa,CAAA;AAWpB,MAAM,OAAO,GAAsB,CAAC,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW,CAAC,CAAA;AAEpF;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,qBAAqB,CAAC,MAAe,EAAE,OAAO,GAAqB,EAAE;IACnF,MAAM,GAAG,GAAG,MAAM,CAAC,MAAM,CAAC,CAAA;IAC1B,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,QAA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MAAM,CAAA;IACf,CAAC;IACD,OAAO,SAAS,CAAA;AAClB,CAAC"}
@@ -0,0 +1,215 @@
1
+ /**
2
+ * Shapes and checks shared by the plugin (`.`) and the backend helpers
3
+ * (`./server`). No imports: the server entry must run without the browser
4
+ * or `@handsforbots/core`.
5
+ */
6
+ /** Context signal key, `ui.effect` name and `data` part name. */
7
+ export declare const STATE_KEY = "conversation.state";
8
+ /** Action the assistant may call to update the state. */
9
+ export declare const STATE_ACTION = "update_conversation_state";
10
+ export type AttrValue = string | number | boolean;
11
+ /**
12
+ * A section of the state. `value` holds one item (the active topic, the
13
+ * goal); `list` holds several (entities, decisions, facts, pending).
14
+ */
15
+ export type Section = {
16
+ kind: 'value' | 'list';
17
+ /** What goes here. Sent to the model in the action's schema and in `conversationStatePrompt`. */
18
+ description: string;
19
+ /** Most items in a list. Default 20. A `value` holds one. */
20
+ max?: number;
21
+ /** Most characters in an item's text. Default 300. */
22
+ maxChars?: number;
23
+ /** Closed vocabulary for the text (for example depth levels). */
24
+ values?: readonly string[];
25
+ /**
26
+ * What a backend write must point to: `'none'` (default), `'message'` (the
27
+ * id of a message that supports it) or `'quote'` (a message id and a
28
+ * verbatim quote found in that message). The page writes without it.
29
+ */
30
+ evidence?: 'none' | 'message' | 'quote';
31
+ /**
32
+ * An item the user stated (its evidence points to a user message) can only
33
+ * be changed or removed with evidence from a user message, or by the page.
34
+ * Default true; off for sections that move every turn, such as the topic.
35
+ */
36
+ keepUserStated?: boolean;
37
+ };
38
+ export type Sections = Readonly<Record<string, Section>>;
39
+ /** The sections used when `conversationState()` gets none. */
40
+ export declare const DEFAULT_SECTIONS: {
41
+ readonly topic: {
42
+ readonly kind: 'value';
43
+ readonly description: 'The subject being discussed right now, naming the project or product it belongs to.';
44
+ readonly maxChars: 160;
45
+ readonly keepUserStated: false;
46
+ };
47
+ readonly goal: {
48
+ readonly kind: 'value';
49
+ readonly description: 'What the user wants to achieve, in their terms.';
50
+ readonly maxChars: 240;
51
+ };
52
+ readonly depth: {
53
+ readonly kind: 'value';
54
+ readonly description: 'How deep the conversation is now (for example: overview, step by step, expert detail).';
55
+ readonly maxChars: 60;
56
+ readonly keepUserStated: false;
57
+ };
58
+ readonly entities: {
59
+ readonly kind: 'list';
60
+ readonly description: 'Things being talked about (projects, products, files, people), with versions and dates as attrs.';
61
+ readonly max: 20;
62
+ readonly maxChars: 120;
63
+ };
64
+ readonly decisions: {
65
+ readonly kind: 'list';
66
+ readonly description: 'What was decided, with the message where it was decided.';
67
+ readonly max: 15;
68
+ readonly maxChars: 240;
69
+ readonly evidence: 'message';
70
+ };
71
+ readonly facts: {
72
+ readonly kind: 'list';
73
+ readonly description: 'Facts already stated in the conversation, each with the message that states it and a verbatim quote.';
74
+ readonly max: 25;
75
+ readonly maxChars: 240;
76
+ readonly evidence: 'quote';
77
+ };
78
+ readonly pending: {
79
+ readonly kind: 'list';
80
+ readonly description: 'Open questions and things still to do.';
81
+ readonly max: 15;
82
+ readonly maxChars: 200;
83
+ };
84
+ };
85
+ /** Who wrote a change: the backend (response, action or updater) or the page. */
86
+ export type Writer = 'backend' | 'app';
87
+ /**
88
+ * Where an item's content comes from, worked out from its evidence (never
89
+ * taken from the writer's word): the role of the messages it points to,
90
+ * `'app'` for the page, `'unsourced'` for a backend write without evidence.
91
+ */
92
+ export type Origin = 'user' | 'assistant' | 'tool' | 'app' | 'unsourced';
93
+ /**
94
+ * How sure the writer is. The writer's word is capped by the evidence: a
95
+ * claim backed only by the assistant's own message is at most `'medium'`,
96
+ * and one without evidence is `'low'`.
97
+ */
98
+ export type Confidence = 'high' | 'medium' | 'low';
99
+ export declare const CONFIDENCE: readonly Confidence[];
100
+ export type Evidence = {
101
+ messageId: string;
102
+ /** Verbatim text found in that message when the change was applied. */
103
+ quote?: string;
104
+ /** Role of the message, recorded when the change was applied. */
105
+ role?: 'user' | 'assistant' | 'tool';
106
+ /** When that message was created (ms). */
107
+ at?: number;
108
+ };
109
+ /** Fields an item can carry besides its text. */
110
+ type ItemFields = {
111
+ attrs?: Record<string, AttrValue>;
112
+ /** What the item belongs to, such as a project (`'acme'`), so "the Terraform of that project" isn't mixed with another one. */
113
+ scope?: string;
114
+ confidence?: Confidence;
115
+ evidence?: EvidenceInput[];
116
+ };
117
+ export type StateOp =
118
+ /** Sets a `value` section. */
119
+ ({
120
+ op: 'set';
121
+ section: string;
122
+ text: string;
123
+ locked?: boolean;
124
+ } & ItemFields)
125
+ /** Adds to a `list` section. `id` is optional (one is made up). */
126
+ | ({
127
+ op: 'add';
128
+ section: string;
129
+ text: string;
130
+ id?: string;
131
+ locked?: boolean;
132
+ } & ItemFields)
133
+ /** Changes a list item: new text, attrs merged (`null` removes one), scope (`null` removes it), confidence, new evidence. */
134
+ | ({
135
+ op: 'update';
136
+ section: string;
137
+ id: string;
138
+ text?: string;
139
+ attrs?: Record<string, AttrValue | null>;
140
+ scope?: string | null;
141
+ } & Omit<ItemFields, 'attrs' | 'scope'>)
142
+ /** Removes a list item (`id`) or clears a value section. Always with a reason. */
143
+ | {
144
+ op: 'remove';
145
+ section: string;
146
+ id?: string;
147
+ reason: string;
148
+ evidence?: EvidenceInput[];
149
+ };
150
+ export type EvidenceInput = {
151
+ messageId: string;
152
+ quote?: string;
153
+ };
154
+ /**
155
+ * An update: operations on the state, never a whole new state. `base` is
156
+ * the revision it was computed from; changes to items modified after it are
157
+ * rejected as `stale`.
158
+ */
159
+ export type StateUpdate = {
160
+ base?: number;
161
+ ops: StateOp[];
162
+ };
163
+ export type RejectReason = 'invalid' | 'unknown-section' | 'unknown-item' | 'not-allowed-value' | 'too-long' | 'evidence-required' | 'evidence-not-found' | 'quote-not-found' | 'user-stated' | 'locked' | 'stale' | 'duplicate' | 'section-full' | 'reason-required' | 'screened' | 'over-budget' | 'too-many-removals';
164
+ export type Rejection = {
165
+ index: number;
166
+ reason: RejectReason;
167
+ op?: string;
168
+ section?: string;
169
+ id?: string;
170
+ detail?: string;
171
+ };
172
+ /** An item as the backend sees it. */
173
+ export type ViewItem = {
174
+ id: string;
175
+ text: string;
176
+ attrs?: Record<string, AttrValue>;
177
+ scope?: string;
178
+ origin: Origin;
179
+ confidence: Confidence;
180
+ /** Ids of the messages it points to. */
181
+ src?: string[];
182
+ /** When the newest of those messages was written (ISO 8601). */
183
+ stated?: string;
184
+ locked?: true;
185
+ };
186
+ /**
187
+ * What goes to the backend with each request, as the context signal
188
+ * `conversation.state`: the revision, each section (a value section is an
189
+ * item or null) and, once, what the last update had rejected.
190
+ */
191
+ export type StateView = {
192
+ revision: number;
193
+ sections: Record<string, ViewItem | ViewItem[] | null>;
194
+ rejected?: Rejection[];
195
+ };
196
+ /** Removes invisible characters and collapses whitespace into single spaces. */
197
+ export declare function cleanText(text: string): string;
198
+ /** For comparing: case, quote marks, dashes and whitespace don't matter. */
199
+ export declare function comparable(text: string): string;
200
+ export declare const ITEM_ID: RegExp;
201
+ export declare const ATTR_KEY: RegExp;
202
+ export declare const MAX_ATTRS = 8;
203
+ export declare const MAX_ATTR_CHARS = 120;
204
+ export declare const MAX_EVIDENCE = 5;
205
+ export declare const MAX_QUOTE_CHARS = 300;
206
+ export declare const MIN_QUOTE_CHARS = 3;
207
+ export declare const MAX_OPS = 50;
208
+ export declare const MAX_SCOPE_CHARS = 64;
209
+ export declare function isRecord(value: unknown): value is Record<string, unknown>;
210
+ /** JSON Schema of a `StateUpdate` for these sections (the action's parameters; also for structured output). */
211
+ export declare function stateUpdateSchema(sections?: Sections): Record<string, unknown>;
212
+ /** Instructions for the model that keeps the state (system prompt or updater prompt). */
213
+ export declare function conversationStatePrompt(sections?: Sections): string;
214
+ export {};
215
+ //# sourceMappingURL=shared.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../src/shared.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,iEAAiE;AACjE,eAAO,MAAM,SAAS,uBAAuB,CAAA;AAC7C,yDAAyD;AACzD,eAAO,MAAM,YAAY,8BAA8B,CAAA;AAEv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,MAAM,eAAe,IAAI,CAAA;AAChC,eAAO,MAAM,OAAO,KAAK,CAAA;AACzB,eAAO,MAAM,eAAe,KAAK,CAAA;AAEjC,wBAAgB,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAEzE;AAMD,+GAA+G;AAC/G,wBAAgB,iBAAiB,CAAC,QAAQ,GAAE,QAA2B,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAiDhG;AAED,yFAAyF;AACzF,wBAAgB,uBAAuB,CAAC,QAAQ,GAAE,QAA2B,GAAG,MAAM,CAwBrF"}
package/dist/shared.js ADDED
@@ -0,0 +1,152 @@
1
+ /**
2
+ * Shapes and checks shared by the plugin (`.`) and the backend helpers
3
+ * (`./server`). No imports: the server entry must run without the browser
4
+ * or `@handsforbots/core`.
5
+ */
6
+ /** Context signal key, `ui.effect` name and `data` part name. */
7
+ export const STATE_KEY = 'conversation.state';
8
+ /** Action the assistant may call to update the state. */
9
+ export const STATE_ACTION = 'update_conversation_state';
10
+ /** The sections used when `conversationState()` gets none. */
11
+ export const DEFAULT_SECTIONS = {
12
+ topic: {
13
+ kind: 'value',
14
+ description: 'The subject being discussed right now, naming the project or product it belongs to.',
15
+ maxChars: 160,
16
+ keepUserStated: false,
17
+ },
18
+ goal: { kind: 'value', description: 'What the user wants to achieve, in their terms.', maxChars: 240 },
19
+ depth: {
20
+ kind: 'value',
21
+ description: 'How deep the conversation is now (for example: overview, step by step, expert detail).',
22
+ maxChars: 60,
23
+ keepUserStated: false,
24
+ },
25
+ entities: {
26
+ kind: 'list',
27
+ description: 'Things being talked about (projects, products, files, people), with versions and dates as attrs.',
28
+ max: 20,
29
+ maxChars: 120,
30
+ },
31
+ decisions: { kind: 'list', description: 'What was decided, with the message where it was decided.', max: 15, maxChars: 240, evidence: 'message' },
32
+ facts: {
33
+ kind: 'list',
34
+ description: 'Facts already stated in the conversation, each with the message that states it and a verbatim quote.',
35
+ max: 25,
36
+ maxChars: 240,
37
+ evidence: 'quote',
38
+ },
39
+ pending: { kind: 'list', description: 'Open questions and things still to do.', max: 15, maxChars: 200 },
40
+ };
41
+ export const CONFIDENCE = ['high', 'medium', 'low'];
42
+ /* -------------------------------------------------------------------------- */
43
+ /* Text */
44
+ /* -------------------------------------------------------------------------- */
45
+ // Control characters, zero-width and bidi controls, tag characters: invisible text that can hide instructions.
46
+ const INVISIBLE = /[\u0000-\u0008\u000B\u000C\u000E-\u001F\u007F-\u009F­​-‏‪-‮⁠-⁤⁦-⁩\u{E0000}-\u{E007F}]/gu;
47
+ /** Removes invisible characters and collapses whitespace into single spaces. */
48
+ export function cleanText(text) {
49
+ return text.normalize('NFC').replace(INVISIBLE, '').replace(/\s+/g, ' ').trim();
50
+ }
51
+ /** For comparing: case, quote marks, dashes and whitespace don't matter. */
52
+ export function comparable(text) {
53
+ return cleanText(text.normalize('NFKC'))
54
+ .toLowerCase()
55
+ .replace(/[“”„«»]/g, '"')
56
+ .replace(/[‘’‚′]/g, "'")
57
+ .replace(/[–—]/g, '-')
58
+ .replace(/…/g, '...');
59
+ }
60
+ export const ITEM_ID = /^[A-Za-z0-9_.:-]{1,40}$/;
61
+ export const ATTR_KEY = /^[A-Za-z][A-Za-z0-9_.-]{0,31}$/;
62
+ export const MAX_ATTRS = 8;
63
+ export const MAX_ATTR_CHARS = 120;
64
+ export const MAX_EVIDENCE = 5;
65
+ export const MAX_QUOTE_CHARS = 300;
66
+ export const MIN_QUOTE_CHARS = 3;
67
+ export const MAX_OPS = 50;
68
+ export const MAX_SCOPE_CHARS = 64;
69
+ export function isRecord(value) {
70
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
71
+ }
72
+ /* -------------------------------------------------------------------------- */
73
+ /* What the model needs to know */
74
+ /* -------------------------------------------------------------------------- */
75
+ /** JSON Schema of a `StateUpdate` for these sections (the action's parameters; also for structured output). */
76
+ export function stateUpdateSchema(sections = DEFAULT_SECTIONS) {
77
+ const names = Object.keys(sections);
78
+ const evidence = {
79
+ type: 'array',
80
+ maxItems: MAX_EVIDENCE,
81
+ description: 'Messages that support this change. quote: text copied verbatim from that message.',
82
+ items: {
83
+ type: 'object',
84
+ properties: { messageId: { type: 'string' }, quote: { type: 'string', maxLength: MAX_QUOTE_CHARS } },
85
+ required: ['messageId'],
86
+ additionalProperties: false,
87
+ },
88
+ };
89
+ const attrs = {
90
+ type: 'object',
91
+ description: 'Short attributes such as version, date or project.',
92
+ additionalProperties: { type: ['string', 'number', 'boolean', 'null'] },
93
+ };
94
+ return {
95
+ type: 'object',
96
+ properties: {
97
+ base: { type: 'integer', description: 'The state revision this update was computed from.' },
98
+ ops: {
99
+ type: 'array',
100
+ maxItems: MAX_OPS,
101
+ description: `Changes, applied in order. Sections: ${names
102
+ .map((name) => `${name} (${sections[name].kind}${sections[name].evidence && sections[name].evidence !== 'none' ? `, evidence: ${sections[name].evidence}` : ''}): ${sections[name].description}`)
103
+ .join(' | ')}`,
104
+ items: {
105
+ type: 'object',
106
+ properties: {
107
+ op: { type: 'string', enum: ['set', 'add', 'update', 'remove'], description: 'set: value sections. add/update: list sections. remove: either (id for lists).' },
108
+ section: { type: 'string', enum: names },
109
+ id: { type: 'string', description: 'Item id (update, remove; optional on add).' },
110
+ text: { type: 'string' },
111
+ attrs,
112
+ scope: { type: ['string', 'null'], maxLength: MAX_SCOPE_CHARS, description: 'What it belongs to (a project, product or account), to tell apart things with the same name.' },
113
+ confidence: { type: 'string', enum: CONFIDENCE, description: 'high only for what the user or a tool result said; your own inferences are medium at most.' },
114
+ evidence,
115
+ reason: { type: 'string', description: 'Why it is removed (required on remove).' },
116
+ },
117
+ required: ['op', 'section'],
118
+ additionalProperties: false,
119
+ },
120
+ },
121
+ },
122
+ required: ['ops'],
123
+ additionalProperties: false,
124
+ };
125
+ }
126
+ /** Instructions for the model that keeps the state (system prompt or updater prompt). */
127
+ export function conversationStatePrompt(sections = DEFAULT_SECTIONS) {
128
+ const lines = Object.entries(sections).map(([name, s]) => {
129
+ const rules = [
130
+ s.kind === 'value' ? 'one value' : `list, at most ${s.max ?? 20}`,
131
+ `up to ${s.maxChars ?? 300} characters`,
132
+ s.values ? `only: ${s.values.join(', ')}` : '',
133
+ s.evidence === 'quote' ? 'needs a message id and a verbatim quote' : s.evidence === 'message' ? 'needs a message id' : '',
134
+ ].filter(Boolean);
135
+ return `- ${name}: ${s.description} (${rules.join('; ')})`;
136
+ });
137
+ return [
138
+ 'You keep a small explicit state of this conversation, sent as "conversation.state". It is not a summary: record only what the messages support, as short atomic claims (one claim per item), each with its source, scope and confidence.',
139
+ 'Sections:',
140
+ ...lines,
141
+ 'Rules:',
142
+ '- Send only changes (ops), never the whole state, with "base" set to the revision you read.',
143
+ '- Do not record guesses as facts. If nobody said it, leave it out or put it in pending.',
144
+ '- Give scope (the project, product or account) whenever the same name could belong to more than one.',
145
+ '- confidence: high only for what the user or a tool result said; medium for your own inferences; low when unsure.',
146
+ '- Evidence points to message ids from this conversation; a quote must be copied verbatim from that message.',
147
+ '- What the user stated (origin "user") changes only with evidence from a newer user message.',
148
+ '- Remove with a reason. Items marked locked are set by the page; do not change them.',
149
+ '- If "rejected" lists problems with your last update, fix them or drop the change.',
150
+ ].join('\n');
151
+ }
152
+ //# sourceMappingURL=shared.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shared.js","sourceRoot":"","sources":["../src/shared.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,iEAAiE;AACjE,MAAM,CAAC,MAAM,SAAS,GAAG,oBAAoB,CAAA;AAC7C,yDAAyD;AACzD,MAAM,CAAC,MAAM,YAAY,GAAG,2BAA2B,CAAA;AAkCvD,8DAA8D;AAC9D,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC9B,KAAK,EAAE;QACL,IAAI,EAAE,OAAO;QACb,WAAW,EAAE,qFAAqF;QAClG,QAAQ,EAAE,GAAG;QACb,cAAc,EAAE,KAAK;KACtB;IACD,IAAI,EAAE,EAAE,IAA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AO,CAAC,CAAC,CAAC,yCAAyC,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,oBAAoB,CAAC,CAAC,CAAC,EAAE;SAC1H,CAAC,MAAM,CAAC,OAAO,CAAC,CAAA;QACjB,OAAO,KAAK,IAAI,KAAK,CAAC,CAAC,WAAW,KAAK,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAA;IAC5D,CAAC,CAAC,CAAA;IACF,OAAO;QACL,0OAA0O;QAC1O,WAAW;QACX,GAAG,KAAK;QACR,QAAQ;QACR,6FAA6F;QAC7F,yFAAyF;QACzF,sGAAsG;QACtG,mHAAmH;QACnH,6GAA6G;QAC7G,8FAA8F;QAC9F,sFAAsF;QACtF,oFAAoF;KACrF,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;AACd,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,51 @@
1
1
  {
2
2
  "name": "@handsforbots/conversation-state",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "2.0.0-alpha.1",
4
+ "description": "Plugin. Explicit conversation state for Hands for Bots: a small, structured, auditable record of topic, goal, entities, decisions, sourced facts and pending items, changed only by checked operations and sent with every request.",
5
+ "keywords": [
6
+ "handsforbots",
7
+ "h4b",
8
+ "h4b-plugin"
9
+ ],
10
+ "license": "MIT",
11
+ "homepage": "https://github.com/handsforbots/handsforbots/blob/main/docs/en-us/plugins.md#conversation-state",
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "git+https://github.com/handsforbots/handsforbots.git",
15
+ "directory": "packages/conversation-state"
16
+ },
17
+ "bugs": {
18
+ "url": "https://github.com/handsforbots/handsforbots/issues"
19
+ },
20
+ "type": "module",
21
+ "sideEffects": false,
22
+ "exports": {
23
+ ".": {
24
+ "types": "./dist/index.d.ts",
25
+ "import": "./dist/index.js"
26
+ },
27
+ "./server": {
28
+ "types": "./dist/server.d.ts",
29
+ "import": "./dist/server.js"
30
+ }
31
+ },
32
+ "publishConfig": {
33
+ "access": "public"
34
+ },
35
+ "files": [
36
+ "dist"
37
+ ],
38
+ "peerDependencies": {
39
+ "@handsforbots/core": "^2.0.0-alpha.1"
40
+ },
41
+ "devDependencies": {
42
+ "@handsforbots/testkit": "^2.0.0-alpha.1",
43
+ "@handsforbots/transport-agui": "^2.0.0-alpha.1",
44
+ "@handsforbots/transport-http": "^2.0.0-alpha.1",
45
+ "@handsforbots/core": "^2.0.0-alpha.1"
46
+ },
47
+ "scripts": {
48
+ "build": "tsc -p tsconfig.build.json",
49
+ "typecheck": "tsc -p tsconfig.json --noEmit"
50
+ }
6
51
  }