@adminforth/agent 1.9.0 → 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.
@@ -1,4 +1,5 @@
1
1
  import { AIMessage } from "@langchain/core/messages";
2
+ import { convertMessagesToResponsesInput } from "@langchain/openai";
2
3
  import { createMiddleware } from "langchain";
3
4
  import YAML from "yaml";
4
5
  import type { ToolCallEvent } from "../toolCallEvents.js";
@@ -120,44 +121,36 @@ function finalizeSequenceDebug(sequence: PendingSequenceDebug): SequenceDebug {
120
121
  };
121
122
  }
122
123
 
124
+ type OpenAiResponsesDebugModel = {
125
+ model: string;
126
+ zdrEnabled?: boolean;
127
+ invocationParams: (options?: Record<string, unknown>) => Record<string, unknown>;
128
+ };
129
+
123
130
  function stringifyPromptForDebug(params: {
124
- systemMessage: { toDict(): unknown };
125
- messages: Array<{ toDict(): unknown }>;
131
+ model: OpenAiResponsesDebugModel;
132
+ systemMessage: { text: string };
133
+ messages: unknown[];
126
134
  tools: unknown[];
135
+ toolChoice?: unknown;
127
136
  modelSettings?: Record<string, unknown>;
128
137
  }) {
129
- const { systemMessage, messages, tools, modelSettings } = params;
138
+ const { model, systemMessage, messages, tools, toolChoice, modelSettings } = params;
130
139
 
131
140
  return YAML.stringify({
132
- systemMessage: systemMessage.toDict(),
133
- messages: messages.map((message) => message.toDict()),
134
- tools: tools.map((tool) => {
135
- if (
136
- typeof tool === "object" &&
137
- tool !== null &&
138
- "name" in tool &&
139
- typeof tool.name === "string"
140
- ) {
141
- return tool.name;
142
- }
143
-
144
- if (
145
- typeof tool === "object" &&
146
- tool !== null &&
147
- "schema" in tool &&
148
- typeof tool.schema === "object" &&
149
- tool.schema !== null &&
150
- "name" in tool.schema &&
151
- typeof tool.schema.name === "string"
152
- ) {
153
- return tool.schema.name;
154
- }
155
-
156
- return "";
141
+ input: convertMessagesToResponsesInput({
142
+ messages: [
143
+ ...(systemMessage.text === "" ? [] : [systemMessage]),
144
+ ...messages,
145
+ ] as any[],
146
+ zdrEnabled: model.zdrEnabled ?? false,
147
+ model: model.model,
148
+ }),
149
+ ...model.invocationParams({
150
+ ...(modelSettings ?? {}),
151
+ ...(tools.length > 0 ? { tools } : {}),
152
+ ...(toolChoice !== undefined ? { tool_choice: toolChoice } : {}),
157
153
  }),
158
- ...(modelSettings && Object.keys(modelSettings).length > 0
159
- ? { modelSettings }
160
- : {}),
161
154
  });
162
155
  }
163
156
 
@@ -356,9 +349,11 @@ export function createSequenceDebugMiddleware(
356
349
  name: "SequenceDebugMiddleware",
357
350
  async wrapModelCall(request, handler) {
358
351
  const prompt = stringifyPromptForDebug({
352
+ model: request.model as unknown as OpenAiResponsesDebugModel,
359
353
  systemMessage: request.systemMessage,
360
354
  messages: request.messages,
361
355
  tools: request.tools,
356
+ toolChoice: request.toolChoice,
362
357
  modelSettings: request.modelSettings,
363
358
  });
364
359
 
@@ -25,14 +25,6 @@ export const contextSchema = z.object({
25
25
  emitToolCallEvent: z.custom<ToolCallEventSink>(),
26
26
  });
27
27
 
28
- type AgentReasoning =
29
- | "none"
30
- | "minimal"
31
- | "low"
32
- | "medium"
33
- | "high"
34
- | "xhigh";
35
-
36
28
  type OpenAIBackedCompletionAdapter = CompletionAdapter & {
37
29
  options?: {
38
30
  openAiApiKey?: string;
package/build.log CHANGED
@@ -29,5 +29,5 @@ custom/skills/fetch_data/SKILL.md
29
29
  custom/skills/mutate_data/
30
30
  custom/skills/mutate_data/SKILL.md
31
31
 
32
- sent 174,667 bytes received 413 bytes 350,160.00 bytes/sec
33
- total size is 173,014 speedup is 0.99
32
+ sent 175,146 bytes received 413 bytes 351,118.00 bytes/sec
33
+ total size is 173,468 speedup is 0.99
@@ -4,7 +4,7 @@ import { ref, nextTick, computed, watch, onMounted, shallowRef } from 'vue';
4
4
  import { callAdminForthApi } from '@/utils';
5
5
  import { useAdminforth } from '@/adminforth';
6
6
  import { Chat } from './chat';
7
- import { DefaultChatTransport } from 'ai';
7
+ import { cosineSimilarity, DefaultChatTransport } from 'ai';
8
8
  import { useCoreStore } from '@/stores/core';
9
9
 
10
10
  type AgentMode = {
@@ -76,10 +76,24 @@ export const useAgentStore = defineStore('agent', () => {
76
76
  });
77
77
  }
78
78
  })
79
- function setChatWidth(width: number) {
79
+ const isFullScreen = ref(false);
80
+ function setFullScreen(fullScreen: boolean) {
81
+ isFullScreen.value = fullScreen;
82
+ console.log('setFullScreen', fullScreen);
83
+ if (fullScreen) {
84
+ setChatWidth(window.innerWidth, true);
85
+ } else {
86
+ console.log('setChatWidth to default');
87
+ chatWidth.value = 600;
88
+ }
89
+ }
90
+
91
+ function setChatWidth(width: number, blockTransition = false) {
80
92
  if (appRoot.value && header.value) {
81
- appRoot.value.style.transition = '';
82
- header.value.style.transition = '';
93
+ if (blockTransition) {
94
+ appRoot.value.style.transition = '';
95
+ header.value.style.transition = '';
96
+ }
83
97
  }
84
98
  chatWidth.value = width;
85
99
 
@@ -213,14 +227,14 @@ export const useAgentStore = defineStore('agent', () => {
213
227
  //create a pre-session, until user will type something, so we can save session
214
228
  async function createPreSession() {
215
229
  saveCurrentSessionInCache();
216
- if (sessionList.value.some((s: ISessionsListItem) => s.sessionId === 'pre-session')) {
217
- return;
230
+ if (!sessionList.value.some((s: ISessionsListItem) => s.sessionId === 'pre-session')) {
231
+ sessionList.value.unshift({
232
+ sessionId: 'pre-session',
233
+ title: 'New Session',
234
+ timestamp: new Date().toISOString(),
235
+ });
218
236
  }
219
- sessionList.value.unshift({
220
- sessionId: 'pre-session',
221
- title: 'New Session',
222
- timestamp: new Date().toISOString(),
223
- })
237
+
224
238
  activeSessionId.value = 'pre-session';
225
239
  currentSession.value = {
226
240
  sessionId: 'pre-session',
@@ -394,6 +408,8 @@ export const useAgentStore = defineStore('agent', () => {
394
408
  chatWidth,
395
409
  setChatWidth,
396
410
  focusTextInput,
411
+ setFullScreen,
412
+ isFullScreen,
397
413
  availableModes,
398
414
  activeModeName,
399
415
  setAvailableModes,
@@ -18,6 +18,7 @@ var __rest = (this && this.__rest) || function (s, e) {
18
18
  }
19
19
  return t;
20
20
  };
21
+ import { convertMessagesToResponsesInput } from "@langchain/openai";
21
22
  import { createMiddleware } from "langchain";
22
23
  import YAML from "yaml";
23
24
  function createPendingSequenceDebug(sequenceId) {
@@ -66,27 +67,16 @@ function finalizeSequenceDebug(sequence) {
66
67
  };
67
68
  }
68
69
  function stringifyPromptForDebug(params) {
69
- const { systemMessage, messages, tools, modelSettings } = params;
70
- return YAML.stringify(Object.assign({ systemMessage: systemMessage.toDict(), messages: messages.map((message) => message.toDict()), tools: tools.map((tool) => {
71
- if (typeof tool === "object" &&
72
- tool !== null &&
73
- "name" in tool &&
74
- typeof tool.name === "string") {
75
- return tool.name;
76
- }
77
- if (typeof tool === "object" &&
78
- tool !== null &&
79
- "schema" in tool &&
80
- typeof tool.schema === "object" &&
81
- tool.schema !== null &&
82
- "name" in tool.schema &&
83
- typeof tool.schema.name === "string") {
84
- return tool.schema.name;
85
- }
86
- return "";
87
- }) }, (modelSettings && Object.keys(modelSettings).length > 0
88
- ? { modelSettings }
89
- : {})));
70
+ var _a;
71
+ const { model, systemMessage, messages, tools, toolChoice, modelSettings } = params;
72
+ return YAML.stringify(Object.assign({ input: convertMessagesToResponsesInput({
73
+ messages: [
74
+ ...(systemMessage.text === "" ? [] : [systemMessage]),
75
+ ...messages,
76
+ ],
77
+ zdrEnabled: (_a = model.zdrEnabled) !== null && _a !== void 0 ? _a : false,
78
+ model: model.model,
79
+ }) }, model.invocationParams(Object.assign(Object.assign(Object.assign({}, (modelSettings !== null && modelSettings !== void 0 ? modelSettings : {})), (tools.length > 0 ? { tools } : {})), (toolChoice !== undefined ? { tool_choice: toolChoice } : {})))));
90
80
  }
91
81
  function getMessageBlocks(message) {
92
82
  if (Array.isArray(message.contentBlocks)) {
@@ -234,9 +224,11 @@ export function createSequenceDebugMiddleware(sink) {
234
224
  wrapModelCall(request, handler) {
235
225
  return __awaiter(this, void 0, void 0, function* () {
236
226
  const prompt = stringifyPromptForDebug({
227
+ model: request.model,
237
228
  systemMessage: request.systemMessage,
238
229
  messages: request.messages,
239
230
  tools: request.tools,
231
+ toolChoice: request.toolChoice,
240
232
  modelSettings: request.modelSettings,
241
233
  });
242
234
  sink.handleModelCallStart(prompt);
@@ -4,7 +4,7 @@ import { ref, nextTick, computed, watch, onMounted, shallowRef } from 'vue';
4
4
  import { callAdminForthApi } from '@/utils';
5
5
  import { useAdminforth } from '@/adminforth';
6
6
  import { Chat } from './chat';
7
- import { DefaultChatTransport } from 'ai';
7
+ import { cosineSimilarity, DefaultChatTransport } from 'ai';
8
8
  import { useCoreStore } from '@/stores/core';
9
9
 
10
10
  type AgentMode = {
@@ -76,10 +76,24 @@ export const useAgentStore = defineStore('agent', () => {
76
76
  });
77
77
  }
78
78
  })
79
- function setChatWidth(width: number) {
79
+ const isFullScreen = ref(false);
80
+ function setFullScreen(fullScreen: boolean) {
81
+ isFullScreen.value = fullScreen;
82
+ console.log('setFullScreen', fullScreen);
83
+ if (fullScreen) {
84
+ setChatWidth(window.innerWidth, true);
85
+ } else {
86
+ console.log('setChatWidth to default');
87
+ chatWidth.value = 600;
88
+ }
89
+ }
90
+
91
+ function setChatWidth(width: number, blockTransition = false) {
80
92
  if (appRoot.value && header.value) {
81
- appRoot.value.style.transition = '';
82
- header.value.style.transition = '';
93
+ if (blockTransition) {
94
+ appRoot.value.style.transition = '';
95
+ header.value.style.transition = '';
96
+ }
83
97
  }
84
98
  chatWidth.value = width;
85
99
 
@@ -213,14 +227,14 @@ export const useAgentStore = defineStore('agent', () => {
213
227
  //create a pre-session, until user will type something, so we can save session
214
228
  async function createPreSession() {
215
229
  saveCurrentSessionInCache();
216
- if (sessionList.value.some((s: ISessionsListItem) => s.sessionId === 'pre-session')) {
217
- return;
230
+ if (!sessionList.value.some((s: ISessionsListItem) => s.sessionId === 'pre-session')) {
231
+ sessionList.value.unshift({
232
+ sessionId: 'pre-session',
233
+ title: 'New Session',
234
+ timestamp: new Date().toISOString(),
235
+ });
218
236
  }
219
- sessionList.value.unshift({
220
- sessionId: 'pre-session',
221
- title: 'New Session',
222
- timestamp: new Date().toISOString(),
223
- })
237
+
224
238
  activeSessionId.value = 'pre-session';
225
239
  currentSession.value = {
226
240
  sessionId: 'pre-session',
@@ -394,6 +408,8 @@ export const useAgentStore = defineStore('agent', () => {
394
408
  chatWidth,
395
409
  setChatWidth,
396
410
  focusTextInput,
411
+ setFullScreen,
412
+ isFullScreen,
397
413
  availableModes,
398
414
  activeModeName,
399
415
  setAvailableModes,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adminforth/agent",
3
- "version": "1.9.0",
3
+ "version": "1.10.0",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "type": "module",