@tstdl/base 0.93.147 → 0.93.149

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,8 +1,7 @@
1
1
  import type { ObjectLiteral } from '../../types/types.js';
2
- import { type Instructions } from './instructions-formatter.js';
3
- export type FewShotExample = {
4
- input: ObjectLiteral | null;
5
- output: ObjectLiteral | null;
2
+ export type FewShotExample<Input = ObjectLiteral, Output = ObjectLiteral> = {
3
+ input: Input;
4
+ output: Output;
6
5
  /** Whether this is a negative example (showing what NOT to do). */
7
6
  isNegative?: boolean;
8
7
  /** Optional reason explaining why this example is positive or negative. */
@@ -13,7 +12,11 @@ export type FewShotExample = {
13
12
  * @param examples An array of input/output pairs.
14
13
  * @returns A formatted few-shot prompt.
15
14
  */
16
- export declare function fewShotPrompt(examples: FewShotExample[]): Instructions;
15
+ export declare function fewShotPrompt<Input = ObjectLiteral, Output = ObjectLiteral>(examples: FewShotExample<Input, Output>[]): {
16
+ Examples: string;
17
+ } | {
18
+ Examples: import("./instructions-formatter.js").InstructionsList;
19
+ };
17
20
  /**
18
21
  * Creates a prompt addition to specify the output language.
19
22
  * @param language The desired output language (e.g., 'English', 'German', 'en', 'de').
@@ -1,12 +1,6 @@
1
1
  import { fromEntries } from '../../utils/object/object.js';
2
2
  import { isDefined, isString } from '../../utils/type-guards.js';
3
3
  import { formatInstructions, orderedList, unorderedList } from './instructions-formatter.js';
4
- function formatExampleValue(value) {
5
- if (isString(value)) {
6
- return value;
7
- }
8
- return JSON.stringify(value);
9
- }
10
4
  /**
11
5
  * Creates a prompt addition for few-shot learning.
12
6
  * @param examples An array of input/output pairs.
@@ -14,7 +8,7 @@ function formatExampleValue(value) {
14
8
  */
15
9
  export function fewShotPrompt(examples) {
16
10
  if (examples.length === 0) {
17
- return {};
11
+ return { Examples: 'No examples provided.' };
18
12
  }
19
13
  // biome-ignore-start lint/style/useNamingConvention: prompt
20
14
  const entries = examples
@@ -54,3 +48,9 @@ ${formatInstructions({
54
48
  })}
55
49
  `.trim();
56
50
  }
51
+ function formatExampleValue(value) {
52
+ if (isString(value)) {
53
+ return value;
54
+ }
55
+ return JSON.stringify(value);
56
+ }
@@ -23,6 +23,7 @@ import { Logger } from '../../logger/index.js';
23
23
  import { MessageBus } from '../../message-bus/index.js';
24
24
  import { computed, signal, toObservable } from '../../signals/api.js';
25
25
  import { currentTimestampSeconds } from '../../utils/date-time.js';
26
+ import { clamp } from '../../utils/math.js';
26
27
  import { timeout } from '../../utils/timing.js';
27
28
  import { assertDefinedPass, isDefined, isInstanceOf, isNotFunction, isNullOrUndefined, isUndefined } from '../../utils/type-guards.js';
28
29
  import { millisecondsPerMinute, millisecondsPerSecond, secondsPerHour } from '../../utils/units.js';
@@ -36,6 +37,7 @@ const impersonatorAuthenticationDataStorageKey = 'AuthenticationService:imperson
36
37
  const tokenUpdateBusName = 'AuthenticationService:tokenUpdate';
37
38
  const loggedOutBusName = 'AuthenticationService:loggedOut';
38
39
  const refreshLockResource = 'AuthenticationService:refresh';
40
+ const minRefreshDelay = millisecondsPerMinute;
39
41
  const maxRefreshDelay = 15 * millisecondsPerMinute;
40
42
  const lockTimeout = 10_000;
41
43
  const logoutTimeout = 150;
@@ -438,11 +440,14 @@ let AuthenticationClientService = class AuthenticationClientService {
438
440
  }
439
441
  }
440
442
  const currentToken = this.token();
441
- const currentRefreshBufferSeconds = isDefined(currentToken) ? calculateRefreshBufferSeconds(currentToken) : 0;
442
- const delay = Math.min(maxRefreshDelay, ((currentToken?.exp ?? 0) - this.estimatedServerTimestampSeconds() - currentRefreshBufferSeconds) * millisecondsPerSecond);
443
+ if (isUndefined(currentToken)) {
444
+ continue;
445
+ }
446
+ const currentRefreshBufferSeconds = calculateRefreshBufferSeconds(currentToken);
447
+ const delay = clamp((currentToken.exp - this.estimatedServerTimestampSeconds() - currentRefreshBufferSeconds) * millisecondsPerSecond, minRefreshDelay, maxRefreshDelay);
443
448
  const wakeUpSignals = [
444
449
  from(this.disposeSignal),
445
- this.token$.pipe(filter((t) => t?.jti != currentToken?.jti)),
450
+ this.token$.pipe(filter((t) => t?.jti != currentToken.jti)),
446
451
  ];
447
452
  if (!forceRefresh) {
448
453
  wakeUpSignals.push(this.forceRefreshRequested$.pipe(filter((requested) => requested)));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tstdl/base",
3
- "version": "0.93.147",
3
+ "version": "0.93.149",
4
4
  "author": "Patrick Hein",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -190,13 +190,13 @@
190
190
  "@types/mjml": "4.7",
191
191
  "@types/node": "25",
192
192
  "@types/nodemailer": "7.0",
193
- "@types/pg": "8.16",
193
+ "@types/pg": "8.18",
194
194
  "@vitest/coverage-v8": "4.0",
195
195
  "@vitest/ui": "4.0",
196
196
  "concurrently": "9.2",
197
197
  "drizzle-kit": "0.31",
198
198
  "eslint": "9.39",
199
- "globals": "17.3",
199
+ "globals": "17.4",
200
200
  "tsc-alias": "1.8",
201
201
  "typedoc-github-wiki-theme": "2.1",
202
202
  "typedoc-plugin-markdown": "4.10",