@nexface/chat 0.1.20-alpha.1 → 0.1.20-alpha.2

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/client.d.ts CHANGED
@@ -67,8 +67,9 @@ declare class ChatClientImplementation implements ChatClient {
67
67
  subscribeEvents: (listener: (event: ProtocolEvent) => void) => (() => void);
68
68
  get cancelling(): boolean;
69
69
  get busy(): boolean;
70
+ get appendOnly(): boolean;
70
71
  setPageResolver(resolver: (name: string) => boolean): void;
71
- restore(messages: UIMessage[]): void;
72
+ restore(messages: UIMessage[], appendOnly?: boolean): void;
72
73
  recreateBefore(messageId: string): ChatClient;
73
74
  switchModel(model: AgentModelConfig): Promise<void>;
74
75
  sendMessage: (content: string | readonly AgentInputContent[]) => Promise<{
package/dist/client.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { decodeToolProxy } from "./shared/tool-proxy.js";
1
2
  import { pageDecisionSymbol } from "./shared/runtime-execution.js";
2
3
  import { createAgent, } from "@nexface/agent";
3
4
  import { decodeAgentResponse, } from "./protocol-response.js";
@@ -56,6 +57,7 @@ class ChatClientImplementation {
56
57
  #operation;
57
58
  #disposed = false;
58
59
  #state;
60
+ #appendOnly = false;
59
61
  #stateBeforeLastMessage;
60
62
  #resumeBeforeLastMessage;
61
63
  #recoveryUnavailable = false;
@@ -122,14 +124,18 @@ class ChatClientImplementation {
122
124
  get busy() {
123
125
  return Boolean(this.#controller);
124
126
  }
127
+ get appendOnly() {
128
+ return this.#appendOnly;
129
+ }
125
130
  setPageResolver(resolver) {
126
131
  this.#hasPageHook = resolver;
127
132
  if (this.agent)
128
133
  agentController(this.agent).setPageConfirmationResolver(resolver);
129
134
  }
130
- restore(messages) {
135
+ restore(messages, appendOnly = false) {
131
136
  if (this.busy || this.#messages.length)
132
137
  throw new Error("Restore requires a new Client.");
138
+ this.#appendOnly = appendOnly;
133
139
  const restored = structuredClone(messages);
134
140
  const conversation = conversationFromMessages(restored);
135
141
  this.#messages = restoreMessages(restored, conversation);
@@ -137,6 +143,8 @@ class ChatClientImplementation {
137
143
  agentController(this.agent).restoreConversation(conversation);
138
144
  }
139
145
  recreateBefore(messageId) {
146
+ if (this.#appendOnly)
147
+ throw new ClientError("INVALID_INPUT", "Messages in this chat cannot be edited. Start a new chat.");
140
148
  if (this.busy || this.#disposed)
141
149
  throw new ClientError("CHAT_RUN_ACTIVE", "Wait for the active task to finish.");
142
150
  const index = this.#messages.findIndex((message) => message.role === "user" && message.id === messageId);
@@ -187,7 +195,7 @@ class ChatClientImplementation {
187
195
  let name = call?.function.name;
188
196
  if (name === "nxf_callAppTool")
189
197
  try {
190
- name = JSON.parse(call.function.arguments).name;
198
+ name = decodeToolProxy(JSON.parse(call.function.arguments)).name;
191
199
  }
192
200
  catch {
193
201
  /* Incomplete calls have no local diagnostic. */
@@ -284,6 +292,8 @@ class ChatClientImplementation {
284
292
  catch (error) {
285
293
  throw new ClientError("INVALID_INPUT", error instanceof Error ? error.message : "Invalid chat message.");
286
294
  }
295
+ if (this.#replacement)
296
+ throw new ClientError("CHAT_RUN_ACTIVE", "The Client is already running.");
287
297
  if (this.busy) {
288
298
  if (this.#status !== "waiting" || !this.#pending || !this.#task)
289
299
  throw new ClientError("CHAT_RUN_ACTIVE", "The Client is already running.");
@@ -722,6 +732,8 @@ class ChatClientImplementation {
722
732
  if (started)
723
733
  throw new Error("Duplicate Agent start event.");
724
734
  started = true;
735
+ if (event.metadata?.nexface?.appendOnly === true)
736
+ this.#appendOnly = true;
725
737
  clientToolExecutionOnly = event.metadata?.nexface?.clientToolExecutionOnly === true;
726
738
  }
727
739
  if (event.type === EventType.MESSAGES_SNAPSHOT) {
@@ -801,7 +813,7 @@ class ChatClientImplementation {
801
813
  const unknown = (inFlight && (!signal.aborted || !clientToolExecutionOnly || uncommittedToolCall)) ||
802
814
  completedBrowserCall ||
803
815
  this.#executingBrowserCall !== undefined;
804
- if (unknown)
816
+ if (unknown || (this.#appendOnly && signal.aborted))
805
817
  this.#recoveryUnavailable = true;
806
818
  else
807
819
  this.#queueRemoteCancellation();
package/dist/config.d.ts CHANGED
@@ -12,7 +12,7 @@ export type NexfaceModelConfig = (CompletionsOptions & {
12
12
  }) | (GoogleOptions & {
13
13
  protocol: "google-generative-ai";
14
14
  });
15
- export type NexfaceAgentConfig = Pick<Parameters<typeof createAgent>[0], "tools" | "skills" | "maxSteps" | "maxRetries" | "applicationContext"> & {
15
+ export type NexfaceAgentConfig = Pick<Parameters<typeof createAgent>[0], "tools" | "useToolProxy" | "skills" | "maxSteps" | "maxRetries" | "applicationContext"> & {
16
16
  model: NexfaceModelConfig;
17
17
  /**
18
18
  * @experimental Page decisions may change in future releases.