@jaypie/llm 1.1.6 → 1.1.8

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,100 @@
1
- import { JsonObject, NaturalSchema } from "@jaypie/types";
1
+ import { AnyValue, JsonObject, JsonReturn, NaturalMap, NaturalSchema } from "@jaypie/types";
2
2
  import { z } from "zod";
3
3
  import { LlmTool } from "./LlmTool.interface.js";
4
+ export declare enum LlmMessageRole {
5
+ Assistant = "assistant",
6
+ Developer = "developer",
7
+ System = "system",
8
+ User = "user"
9
+ }
10
+ export declare enum LlmMessageType {
11
+ FunctionCall = "function_call",
12
+ FunctionCallOutput = "function_call_output",
13
+ InputFile = "input_file",
14
+ InputImage = "input_image",
15
+ InputText = "input_text",
16
+ ItemReference = "item_reference",
17
+ Message = "message",
18
+ OutputText = "output_text",
19
+ Refusal = "refusal"
20
+ }
21
+ export declare enum LlmResponseStatus {
22
+ Completed = "completed",
23
+ Incomplete = "incomplete",
24
+ InProgress = "in_progress"
25
+ }
26
+ interface LlmError {
27
+ detail?: string;
28
+ status: number | string;
29
+ title: string;
30
+ }
31
+ interface LlmInputContentFile {
32
+ type: LlmMessageType.InputFile;
33
+ file_data: File;
34
+ file_id?: string;
35
+ filename?: string;
36
+ }
37
+ interface LlmInputContentImage {
38
+ type: LlmMessageType.InputImage;
39
+ detail: File;
40
+ file_id?: string;
41
+ image_url?: string;
42
+ }
43
+ interface LlmInputContentText {
44
+ type: LlmMessageType.InputText;
45
+ text: string;
46
+ }
47
+ type LlmInputContent = LlmInputContentFile | LlmInputContentImage | LlmInputContentText;
48
+ /**
49
+ * Represents the "Input message object" in the "input item list"
50
+ * from [OpenAI Responses API](https://platform.openai.com/docs/api-reference/responses/create)
51
+ */
52
+ export interface LlmInputMessage {
53
+ content: string | Array<LlmInputContent>;
54
+ role: LlmMessageRole;
55
+ type: LlmMessageType.Message;
56
+ }
57
+ export interface LlmOutputContentText {
58
+ annotations?: AnyValue[];
59
+ text: string;
60
+ type: LlmMessageType.OutputText;
61
+ }
62
+ interface LlmOutputRefusal {
63
+ refusal: string;
64
+ type: LlmMessageType.Refusal;
65
+ }
66
+ type LlmOutputContent = LlmOutputContentText | LlmOutputRefusal;
67
+ export interface LlmOutputMessage {
68
+ content: Array<LlmOutputContent>;
69
+ id?: string;
70
+ role: LlmMessageRole.Assistant;
71
+ status: LlmResponseStatus;
72
+ type: LlmMessageType.Message;
73
+ }
74
+ type LlmOutputItem = LlmToolCall | LlmToolResult | LlmOutputMessage;
75
+ type LlmOutput = LlmOutputItem[];
76
+ export interface LlmToolCall {
77
+ arguments: string;
78
+ call_id: string;
79
+ id: string;
80
+ name: string;
81
+ type: LlmMessageType.FunctionCall;
82
+ status: LlmResponseStatus;
83
+ }
84
+ export interface LlmToolResult {
85
+ call_id: string;
86
+ output: string;
87
+ status?: LlmResponseStatus;
88
+ type: LlmMessageType.FunctionCallOutput;
89
+ }
90
+ interface LlmItemReference {
91
+ type: LlmMessageType.ItemReference;
92
+ id: string;
93
+ }
94
+ export type LlmHistoryItem = LlmInputMessage | LlmItemReference | LlmOutputItem | LlmToolResult;
95
+ export type LlmHistory = LlmHistoryItem[];
4
96
  export interface LlmMessageOptions {
5
- data?: Record<string, string>;
97
+ data?: NaturalMap;
6
98
  model?: string;
7
99
  placeholders?: {
8
100
  message?: boolean;
@@ -12,16 +104,19 @@ export interface LlmMessageOptions {
12
104
  system?: string;
13
105
  }
14
106
  export interface LlmOperateOptions {
15
- data?: Record<string, string>;
107
+ data?: NaturalMap;
16
108
  explain?: boolean;
17
109
  format?: JsonObject | NaturalSchema | z.ZodType;
110
+ history?: LlmHistory;
18
111
  instructions?: string;
19
112
  model?: string;
20
113
  placeholders?: {
21
114
  input?: boolean;
22
115
  instructions?: boolean;
116
+ system?: boolean;
23
117
  };
24
- providerOptions?: Record<string, unknown>;
118
+ providerOptions?: JsonObject;
119
+ system?: string;
25
120
  tools?: LlmTool[];
26
121
  turns?: boolean | number;
27
122
  user?: string;
@@ -30,7 +125,23 @@ export interface LlmOptions {
30
125
  apiKey?: string;
31
126
  model?: string;
32
127
  }
128
+ interface LlmUsage {
129
+ input: number;
130
+ output: number;
131
+ reasoning: number;
132
+ total: number;
133
+ }
134
+ export interface LlmOperateResponse {
135
+ content?: string;
136
+ error?: LlmError;
137
+ history: LlmHistory;
138
+ output: LlmOutput;
139
+ responses: JsonReturn[];
140
+ status: LlmResponseStatus;
141
+ usage: LlmUsage;
142
+ }
33
143
  export interface LlmProvider {
34
- operate?(input: string, options?: LlmOperateOptions): Promise<unknown>;
144
+ operate?(input: string | LlmHistory | LlmInputMessage, options?: LlmOperateOptions): Promise<LlmOperateResponse>;
35
145
  send(message: string, options?: LlmMessageOptions): Promise<string | JsonObject>;
36
146
  }
147
+ export {};
@@ -1,8 +1,8 @@
1
- import { JsonObject } from "@jaypie/types";
1
+ import { AnyValue, JsonObject } from "@jaypie/types";
2
2
  export interface LlmTool {
3
3
  description: string;
4
4
  name: string;
5
5
  parameters: JsonObject;
6
6
  type: "function" | string;
7
- call: (...args: any[]) => Promise<any> | any;
7
+ call: (args?: JsonObject) => Promise<AnyValue> | AnyValue;
8
8
  }
@@ -0,0 +1,24 @@
1
+ import { LlmHistory, LlmInputMessage, LlmMessageRole } from "../types/LlmProvider.interface.js";
2
+ import { NaturalMap } from "@jaypie/types";
3
+ /**
4
+ * Options for formatOperateInput function
5
+ */
6
+ export interface FormatOperateInputOptions {
7
+ /**
8
+ * Data to use for placeholder substitution
9
+ */
10
+ data?: NaturalMap;
11
+ /**
12
+ * Role to use when converting a string to LlmInputMessage
13
+ */
14
+ role?: LlmMessageRole;
15
+ }
16
+ /**
17
+ * Converts various input types to a standardized LlmHistory format
18
+ * @param input - String, LlmInputMessage, or LlmHistory to format
19
+ * @param options - Optional configuration
20
+ * @param options.data - Data to use for placeholder substitution
21
+ * @param options.role - Role to use when converting a string to LlmInputMessage (defaults to User)
22
+ * @returns Standardized LlmHistory array
23
+ */
24
+ export declare function formatOperateInput(input: string | LlmInputMessage | LlmHistory, options?: FormatOperateInputOptions): LlmHistory;
@@ -0,0 +1,24 @@
1
+ import { LlmInputMessage, LlmMessageRole } from "../types/LlmProvider.interface.js";
2
+ import { NaturalMap } from "@jaypie/types";
3
+ /**
4
+ * Options for formatOperateMessage function
5
+ */
6
+ export interface FormatOperateMessageOptions {
7
+ /**
8
+ * Data to use for placeholder substitution
9
+ */
10
+ data?: NaturalMap;
11
+ /**
12
+ * Role to use for the message
13
+ */
14
+ role?: LlmMessageRole;
15
+ }
16
+ /**
17
+ * Converts a string to a standardized LlmInputMessage
18
+ * @param input - String to format
19
+ * @param options - Optional configuration
20
+ * @param options.data - Data to use for placeholder substitution
21
+ * @param options.role - Role to use for the message (defaults to User)
22
+ * @returns LlmInputMessage
23
+ */
24
+ export declare function formatOperateMessage(input: string, options?: FormatOperateMessageOptions): LlmInputMessage;
@@ -0,0 +1,7 @@
1
+ export * from "./formatOperateInput.js";
2
+ export * from "./formatOperateMessage.js";
3
+ export * from "./logger.js";
4
+ export * from "./maxTurnsFromOptions.js";
5
+ export * from "./naturalZodSchema.js";
6
+ export * from "./random.js";
7
+ export * from "./tryParseNumber.js";
@@ -0,0 +1,71 @@
1
+ import { log as defaultLog } from "@jaypie/core";
2
+ export declare const getLogger: () => {
3
+ debug: {
4
+ (...args: unknown[]): void;
5
+ var(key: string | Record<string, unknown>, value?: unknown): void;
6
+ };
7
+ error: {
8
+ (...args: unknown[]): void;
9
+ var(key: string | Record<string, unknown>, value?: unknown): void;
10
+ };
11
+ fatal: {
12
+ (...args: unknown[]): void;
13
+ var(key: string | Record<string, unknown>, value?: unknown): void;
14
+ };
15
+ info: {
16
+ (...args: unknown[]): void;
17
+ var(key: string | Record<string, unknown>, value?: unknown): void;
18
+ };
19
+ trace: {
20
+ (...args: unknown[]): void;
21
+ var(key: string | Record<string, unknown>, value?: unknown): void;
22
+ };
23
+ warn: {
24
+ (...args: unknown[]): void;
25
+ var(key: string | Record<string, unknown>, value?: unknown): void;
26
+ };
27
+ var(key: string | Record<string, unknown>, value?: unknown): void;
28
+ with(tags: Record<string, unknown>): typeof defaultLog;
29
+ tag(key: string | string[] | Record<string, unknown> | null, value?: string): void;
30
+ untag(tags: string | string[] | Record<string, unknown> | null): void;
31
+ lib(options: {
32
+ level?: string;
33
+ lib?: string;
34
+ tags?: Record<string, unknown>;
35
+ }): typeof defaultLog;
36
+ };
37
+ export declare const log: {
38
+ debug: {
39
+ (...args: unknown[]): void;
40
+ var(key: string | Record<string, unknown>, value?: unknown): void;
41
+ };
42
+ error: {
43
+ (...args: unknown[]): void;
44
+ var(key: string | Record<string, unknown>, value?: unknown): void;
45
+ };
46
+ fatal: {
47
+ (...args: unknown[]): void;
48
+ var(key: string | Record<string, unknown>, value?: unknown): void;
49
+ };
50
+ info: {
51
+ (...args: unknown[]): void;
52
+ var(key: string | Record<string, unknown>, value?: unknown): void;
53
+ };
54
+ trace: {
55
+ (...args: unknown[]): void;
56
+ var(key: string | Record<string, unknown>, value?: unknown): void;
57
+ };
58
+ warn: {
59
+ (...args: unknown[]): void;
60
+ var(key: string | Record<string, unknown>, value?: unknown): void;
61
+ };
62
+ var(key: string | Record<string, unknown>, value?: unknown): void;
63
+ with(tags: Record<string, unknown>): typeof defaultLog;
64
+ tag(key: string | string[] | Record<string, unknown> | null, value?: string): void;
65
+ untag(tags: string | string[] | Record<string, unknown> | null): void;
66
+ lib(options: {
67
+ level?: string;
68
+ lib?: string;
69
+ tags?: Record<string, unknown>;
70
+ }): typeof defaultLog;
71
+ };
@@ -0,0 +1,10 @@
1
+ import { LlmOperateOptions } from "../types/LlmProvider.interface.js";
2
+ export declare const MAX_TURNS_ABSOLUTE_LIMIT = 72;
3
+ export declare const MAX_TURNS_DEFAULT_LIMIT = 12;
4
+ /**
5
+ * Determines the maximum number of turns based on the provided options
6
+ *
7
+ * @param options - The LLM operate options
8
+ * @returns The maximum number of turns
9
+ */
10
+ export declare function maxTurnsFromOptions(options: LlmOperateOptions): number;
@@ -1,3 +1,3 @@
1
1
  import { z } from "zod";
2
2
  import { NaturalSchema } from "@jaypie/types";
3
- export default function naturalZodSchema(definition: NaturalSchema): z.ZodTypeAny;
3
+ export declare function naturalZodSchema(definition: NaturalSchema): z.ZodTypeAny;
@@ -35,5 +35,5 @@ export declare const DEFAULT_MAX = 1;
35
35
  * // Use consistent seeding
36
36
  * const seeded = rng({ seed: "my-seed" });
37
37
  */
38
- declare const random: (defaultSeed?: string) => RandomFunction;
39
- export default random;
38
+ export declare function random(defaultSeed?: string): RandomFunction;
39
+ export {};
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Options for tryParseNumber function
3
+ */
4
+ export interface TryParseNumberOptions {
5
+ /**
6
+ * Default value to return if parsing fails or results in NaN
7
+ */
8
+ defaultValue?: number;
9
+ /**
10
+ * Function to call with warning message if parsing fails or results in NaN
11
+ */
12
+ warnFunction?: (message: string) => void;
13
+ }
14
+ /**
15
+ * Attempts to parse a value as a number. Returns the original input if parsing fails or results in NaN.
16
+ * @param input - The value to attempt to parse as a number
17
+ * @param options - Optional configuration
18
+ * @param options.defaultValue - Default value to return if parsing fails or results in NaN
19
+ * @param options.warnFunction - Function to call with warning message if parsing fails or results in NaN
20
+ * @returns The parsed number, defaultValue (if specified and parsing fails), or the original input
21
+ */
22
+ export declare function tryParseNumber(input: unknown, options?: TryParseNumberOptions): number | unknown;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jaypie/llm",
3
- "version": "1.1.6",
3
+ "version": "1.1.8",
4
4
  "description": "Large language model utilities",
5
5
  "license": "MIT",
6
6
  "author": "Finlayson Studio",
@@ -37,5 +37,5 @@
37
37
  "publishConfig": {
38
38
  "access": "public"
39
39
  },
40
- "gitHead": "1026f2fc0b3f6ae0ca2e1b6495437364f1c4e6fe"
40
+ "gitHead": "147d2cc66ce944e37e2225760fd71a72e761a37a"
41
41
  }