@g9tm/aiassistant 1.9.6 → 1.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api.d.ts +5 -0
- package/dist/api.js +2 -0
- package/dist/assistant.d.ts +8 -2
- package/dist/assistant.js +6 -3
- package/package.json +2 -2
package/dist/api.d.ts
CHANGED
|
@@ -25,6 +25,11 @@ export interface SendInput {
|
|
|
25
25
|
id: string;
|
|
26
26
|
label?: string;
|
|
27
27
|
}[];
|
|
28
|
+
/** Blind mode: the conversation's last lines, which the server keeps only in memory. */
|
|
29
|
+
history?: {
|
|
30
|
+
role: string;
|
|
31
|
+
text: string;
|
|
32
|
+
}[];
|
|
28
33
|
}
|
|
29
34
|
export interface EventPage {
|
|
30
35
|
events: RawEvent[];
|
package/dist/api.js
CHANGED
|
@@ -82,6 +82,8 @@ export class AssistantApi {
|
|
|
82
82
|
body["model"] = input.model;
|
|
83
83
|
if (input.refs?.length)
|
|
84
84
|
body["refs"] = input.refs;
|
|
85
|
+
if (input.history)
|
|
86
|
+
body["history"] = input.history;
|
|
85
87
|
return this.request("POST", path, body).then((r) => ({ conversationId: str(obj(r)["conversationId"]), runId: str(obj(r)["runId"]) }));
|
|
86
88
|
}
|
|
87
89
|
async events(runId, after, wait) {
|
package/dist/assistant.d.ts
CHANGED
|
@@ -30,6 +30,11 @@ export interface AssistantOptions {
|
|
|
30
30
|
flows?: boolean;
|
|
31
31
|
/** How the conversation reads and writes (every renderer follows it). */
|
|
32
32
|
chat?: ChatOptions;
|
|
33
|
+
/**
|
|
34
|
+
* The server runs in blind mode: it keeps no conversation at rest, so the device keeps them. Each question carries the
|
|
35
|
+
* last six lines, and `open` takes the messages the host saved instead of asking the server.
|
|
36
|
+
*/
|
|
37
|
+
blind?: boolean;
|
|
33
38
|
}
|
|
34
39
|
/** How the conversation reads and writes; every option has a safe default for every host. */
|
|
35
40
|
export interface ChatOptions {
|
|
@@ -99,13 +104,14 @@ export declare class Assistant {
|
|
|
99
104
|
private readonly answeredCalls;
|
|
100
105
|
/** The conversation's reading and writing options as given (`chatOf` in "@g9tm/aiassistant/pages" resolves the defaults). */
|
|
101
106
|
readonly chat: ChatOptions;
|
|
107
|
+
private readonly blind;
|
|
102
108
|
constructor(host: AssistantHost, options?: AssistantOptions);
|
|
103
109
|
/** Listens to every change; returns the function that stops listening. */
|
|
104
110
|
subscribe(listener: (s: AssistantSnapshot) => void): () => void;
|
|
105
111
|
snapshot(): AssistantSnapshot;
|
|
106
112
|
private emit;
|
|
107
|
-
/** Opens a conversation from its history (from the end; history never animates). */
|
|
108
|
-
open(conversationId: string): Promise<void>;
|
|
113
|
+
/** Opens a conversation from its history (from the end; history never animates); blind: from `saved`, the host's copy. */
|
|
114
|
+
open(conversationId: string, saved?: readonly unknown[]): Promise<void>;
|
|
109
115
|
/** Counts fresh(): a send that returns after one is dropped. */
|
|
110
116
|
private generation;
|
|
111
117
|
/** A new conversation. */
|
package/dist/assistant.js
CHANGED
|
@@ -35,6 +35,7 @@ export class Assistant {
|
|
|
35
35
|
this.answeredCalls = new Set();
|
|
36
36
|
/** Counts fresh(): a send that returns after one is dropped. */
|
|
37
37
|
this.generation = 0;
|
|
38
|
+
this.blind = options.blind === true;
|
|
38
39
|
this.api = new AssistantApi(host, options.base);
|
|
39
40
|
this.texts = createTexts(host.locale, options.texts);
|
|
40
41
|
this.transport = pickTransport(this.api, host, options);
|
|
@@ -69,11 +70,11 @@ export class Assistant {
|
|
|
69
70
|
for (const l of this.listeners)
|
|
70
71
|
l(s);
|
|
71
72
|
}
|
|
72
|
-
/** Opens a conversation from its history (from the end; history never animates). */
|
|
73
|
-
async open(conversationId) {
|
|
73
|
+
/** Opens a conversation from its history (from the end; history never animates); blind: from `saved`, the host's copy. */
|
|
74
|
+
async open(conversationId, saved) {
|
|
74
75
|
this.follow(null);
|
|
75
76
|
this.store.reset(conversationId);
|
|
76
|
-
const r = await this.api.messages(conversationId);
|
|
77
|
+
const r = this.blind ? saved ?? [] : await this.api.messages(conversationId);
|
|
77
78
|
const raw = Array.isArray(r) ? r : Array.isArray(r.messages) ? r.messages : [];
|
|
78
79
|
const added = this.store.merge(raw);
|
|
79
80
|
this.watched.history(added.map((m) => m.id));
|
|
@@ -111,6 +112,8 @@ export class Assistant {
|
|
|
111
112
|
this.store.optimistic(trimmed, new Date(timer(this.host).now()).toISOString());
|
|
112
113
|
this.emit();
|
|
113
114
|
const input = { text: trimmed };
|
|
115
|
+
if (this.blind)
|
|
116
|
+
input.history = this.store.messages.filter((m) => !m.pending && m.role !== "system" && m.text).slice(-6).map((m) => ({ role: m.role, text: m.text.slice(0, 500) }));
|
|
114
117
|
if (this.store.id)
|
|
115
118
|
input.conversationId = this.store.id;
|
|
116
119
|
if (this.attachments.length > 0)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@g9tm/aiassistant",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.10.0",
|
|
4
4
|
"description": "Headless client of the G9 AI assistant: API client, run state, transports, block view models, safe text and Persian helpers. No DOM, no framework.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": {
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"access": "public"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@g9tm/aiassistant-contracts": "1.
|
|
36
|
+
"@g9tm/aiassistant-contracts": "1.10.0"
|
|
37
37
|
},
|
|
38
38
|
"scripts": {
|
|
39
39
|
"build": "node -e \"require('node:fs').rmSync('dist', { recursive: true, force: true })\" && tsc -p tsconfig.json",
|