@christianriedl/utils 1.0.153 → 1.0.155

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@christianriedl/utils",
3
- "version": "1.0.153",
3
+ "version": "1.0.155",
4
4
  "description": "Interfaces, local storage, service worker, configuration, application state",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -25,7 +25,6 @@
25
25
  const isUpload = ref(false);
26
26
  const showConfig = ref(false);
27
27
  const showFilter = ref(false);
28
- const files = ref<File[]>([]);
29
28
  const imageUrl = ref("");
30
29
  const camera = ref<InstanceType<typeof Camera>>();
31
30
  const htmlText = ref('');
@@ -42,7 +41,6 @@
42
41
 
43
42
  async function onComplete() {
44
43
  htmlText.value = "<h4>WAITING ...</h4>";
45
- files.value = [];
46
44
  isUpload.value = false;
47
45
  let answer: IResponseResult;
48
46
  if (camera.value) {
@@ -124,17 +122,44 @@
124
122
  camera.value = undefined;
125
123
  }
126
124
  }
127
- function onFile() {
125
+ async function fileUpload() {
126
+ replyLines.value = [];
127
+ htmlText.value = '';
128
+ isCamera.value = false;
129
+ if (camera.value) {
130
+ camera.value.stop();
131
+ camera.value = undefined;
132
+ }
128
133
  if (!question.value) {
129
134
  question.value = "Was erkennst du auf dem Bild ?";
130
135
  }
131
- if (files.value && files.value.length > 0) {
136
+ const clipboardUrl = await window.navigator.clipboard.readText();
137
+ if (clipboardUrl && clipboardUrl.startsWith("http")) {
138
+ if (window.confirm(`Use '${clipboardUrl}' ?`)) {
139
+ imageUrl.value = clipboardUrl;
140
+ isUpload.value = true;
141
+ return;
142
+ }
143
+ await window.navigator.clipboard.writeText('');
144
+ }
145
+ const pickerOpts = {
146
+ types: [{
147
+ description: "Images",
148
+ accept: { "image/*": [".png", ".gif", ".jpeg", ".jpg"] }
149
+ }],
150
+ excludeAcceptAllOption: true,
151
+ multiple: false,
152
+ };
153
+ const files: FileSystemFileHandle[] = await(window as any).showOpenFilePicker(pickerOpts);
154
+ if (files && files.length > 0) {
155
+ const file = await files[0].getFile();
132
156
  const reader = new FileReader();
133
157
  reader.addEventListener("load", async () => {
134
158
  // convert image file to base64 string
135
159
  imageUrl.value = reader.result as string;
160
+ isUpload.value = true;
136
161
  }, false,);
137
- reader.readAsDataURL(files.value[0]);
162
+ reader.readAsDataURL(file);
138
163
  }
139
164
  }
140
165
  function onUse(usetools: string[], persist: boolean) {
@@ -189,7 +214,7 @@
189
214
  <v-btn variant="tonal" class="bg-office aibutton" @click="onCamera">
190
215
  <v-icon size="large" icon="$webcam" color="primary"></v-icon>
191
216
  </v-btn>
192
- <v-btn variant="tonal" class="bg-office aibutton" @click="isUpload=true;replyLines=[]">
217
+ <v-btn variant="tonal" class="bg-office aibutton" @click="fileUpload">
193
218
  <v-icon size="large" icon="$image" color="primary"></v-icon>
194
219
  </v-btn>
195
220
  </v-col>
@@ -205,12 +230,8 @@
205
230
  </v-col>
206
231
  </v-row>
207
232
  <v-row v-if="isUpload" dense align="center">
208
- <v-col cols="6">
209
- <v-file-input show-size clearable multiple hide-details v-model="files" accept="image/*" label="Select File" prepend-icon="" append-icon="" @update:modelValue="onFile">
210
- </v-file-input>
211
- </v-col>
212
- <v-col cols="6">
213
- <img width="100%" :src="imageUrl">
233
+ <v-col cols="12">
234
+ <v-img :src="imageUrl"></v-img>
214
235
  </v-col>
215
236
  </v-row>
216
237
  <v-row v-if="htmlText" dense>
@@ -1,5 +1,5 @@
1
1
  <script setup lang="ts">
2
- import { inject, ref, reactive } from 'vue';
2
+ import { inject, ref, reactive, onBeforeUnmount } from 'vue';
3
3
  import { appConfigSymbol, AppConfig, Dictionary, IDataItem, ItemType, IVectorFile } from '@christianriedl/utils';
4
4
  import { getOpenAISymbol, IOpenAIServiceWithVectorStore, IOpenAIAppConfig, IOpenAIOptions, ITool, IMcpTool, IFileSearchTool } from '@christianriedl/utils';
5
5
  import OpenAIMetaData from '@christianriedl/utils/src/components/OpenAIMetaData.vue';
@@ -40,6 +40,8 @@
40
40
  let fileHandle: FileSystemFileHandle | null = null;
41
41
  let vsSelected = false;
42
42
 
43
+ onBeforeUnmount(() => onBack());
44
+
43
45
  initializeTools();
44
46
  checkAllFilter();
45
47
 
@@ -99,8 +101,11 @@
99
101
  showFunctions.value = true;
100
102
  }
101
103
  }
102
- function onSave() {
103
- const persist = window.confirm('Do you want to persist the changes?');
104
+ function onSave(ask: boolean) {
105
+ let persist = false;
106
+ if (ask) {
107
+ persist = window.confirm('Do you want to persist the changes?');
108
+ }
104
109
  if (toolsChanged.value) {
105
110
  for (const key in fileSearch) {
106
111
  const vsNames = fileSearch[key];
@@ -125,8 +130,11 @@
125
130
  optionsChanged.value = false;
126
131
  }
127
132
  }
128
- function onSaveUsage() {
129
- const persist = window.confirm('Do you want to persist the changes?');
133
+ function onSaveUsage(ask: boolean) {
134
+ let persist = false;
135
+ if (ask) {
136
+ persist = window.confirm('Do you want to persist the changes?');
137
+ }
130
138
  const useTools: string[] = [];
131
139
  for (const key in use) {
132
140
  if (use[key]) {
@@ -136,6 +144,13 @@
136
144
  emits('use', useTools, persist);
137
145
  useChanged.value = false;
138
146
  }
147
+ function onBack() {
148
+ if (optionsChanged.value)
149
+ onSave(false);
150
+ if (useChanged.value)
151
+ onSaveUsage(false);
152
+ emits("back");
153
+ }
139
154
  function onAddMcp() {
140
155
  const name = window.prompt('Enter MCP name:');
141
156
  if (name && name.length > 0) {
@@ -510,19 +525,19 @@
510
525
  </template>
511
526
  <v-row dense align="center">
512
527
  <v-col cols="2">
513
- <v-btn class="bg-office" @click="emits('back')">
528
+ <v-btn class="bg-office" @click="onBack">
514
529
  BACK
515
530
  <v-icon icon="$back"></v-icon>
516
531
  </v-btn>
517
532
  </v-col>
518
533
  <v-col cols="2">
519
- <v-btn :disabled="!optionsChanged && !toolsChanged" class="bg-office" @click="onSave">
534
+ <v-btn :disabled="!optionsChanged && !toolsChanged" class="bg-office" @click="onSave(true)">
520
535
  SAVE
521
536
  <v-icon icon="$save"></v-icon>
522
537
  </v-btn>
523
538
  </v-col>
524
539
  <v-col cols="2">
525
- <v-btn :disabled="!useChanged" class="bg-office" @click="onSaveUsage">
540
+ <v-btn :disabled="!useChanged" class="bg-office" @click="onSaveUsage(true)">
526
541
  SAVE TOOL USE
527
542
  <v-icon icon="$save"></v-icon>
528
543
  </v-btn>
@@ -1,5 +1,5 @@
1
1
  <script setup lang="ts">
2
- import { inject, reactive, computed, ref, StyleValue } from 'vue';
2
+ import { inject, reactive, computed, ref, onBeforeUnmount, StyleValue } from 'vue';
3
3
  import { IDataItem, Dictionary, IComparisonFilter, ICompoundFilter, IOpenAIFilter, ITool } from '@christianriedl/utils'
4
4
  import SettingsLine from '../components/SettingsLine.vue';
5
5
 
@@ -12,6 +12,8 @@
12
12
  const numvs = props.vsmetadata.length;
13
13
  const tools = reactive<Dictionary<boolean>>({});
14
14
 
15
+ onBeforeUnmount(() => onBack());
16
+
15
17
  for (const key in props.alltools) {
16
18
  tools[key] = props.tools ? props.tools.indexOf(key) >= 0 : false;
17
19
  }