@anvia/core 0.26.0 → 1.0.0-rc.10
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/README.md +400 -94
- package/dist/agent/index.d.ts +67 -71
- package/dist/agent/index.js +36 -18
- package/dist/agent/interactions/index.d.ts +122 -0
- package/dist/agent/interactions/index.js +20 -0
- package/dist/agent-DWzW9SoH.d.ts +150 -0
- package/dist/chunk-3RM57ZT2.js +31 -0
- package/dist/chunk-3RM57ZT2.js.map +1 -0
- package/dist/chunk-3RWESPUG.js +331 -0
- package/dist/chunk-3RWESPUG.js.map +1 -0
- package/dist/{chunk-NCPN4SJR.js → chunk-3SKZ2BKP.js} +15 -13
- package/dist/chunk-3SKZ2BKP.js.map +1 -0
- package/dist/chunk-3XQGVDU5.js +69 -0
- package/dist/chunk-3XQGVDU5.js.map +1 -0
- package/dist/{chunk-MRQLEK2B.js → chunk-5C6B6ZRH.js} +69 -51
- package/dist/chunk-5C6B6ZRH.js.map +1 -0
- package/dist/chunk-6BBOCFHV.js +323 -0
- package/dist/chunk-6BBOCFHV.js.map +1 -0
- package/dist/chunk-7JLAIN6E.js +15 -0
- package/dist/chunk-7JLAIN6E.js.map +1 -0
- package/dist/chunk-7PHMK7W4.js +1516 -0
- package/dist/chunk-7PHMK7W4.js.map +1 -0
- package/dist/{chunk-CWUJUSOS.js → chunk-AZB6N7P4.js} +94 -65
- package/dist/chunk-AZB6N7P4.js.map +1 -0
- package/dist/chunk-D4PACGPA.js +37 -0
- package/dist/chunk-D4PACGPA.js.map +1 -0
- package/dist/chunk-EFLT7XZD.js +51 -0
- package/dist/chunk-EFLT7XZD.js.map +1 -0
- package/dist/chunk-EMZKPRE6.js +667 -0
- package/dist/chunk-EMZKPRE6.js.map +1 -0
- package/dist/chunk-I3Q7XSBB.js +59 -0
- package/dist/chunk-I3Q7XSBB.js.map +1 -0
- package/dist/chunk-J6LVLV6P.js +13 -0
- package/dist/chunk-J6LVLV6P.js.map +1 -0
- package/dist/chunk-LTXABCOO.js +127 -0
- package/dist/chunk-LTXABCOO.js.map +1 -0
- package/dist/chunk-OJBFDBLG.js +164 -0
- package/dist/chunk-OJBFDBLG.js.map +1 -0
- package/dist/chunk-QGX73TSQ.js +177 -0
- package/dist/chunk-QGX73TSQ.js.map +1 -0
- package/dist/chunk-QOUPWOGW.js +29 -0
- package/dist/chunk-QOUPWOGW.js.map +1 -0
- package/dist/chunk-SJMSS5SI.js +171 -0
- package/dist/chunk-SJMSS5SI.js.map +1 -0
- package/dist/chunk-T2C3CGDQ.js +56 -0
- package/dist/chunk-T2C3CGDQ.js.map +1 -0
- package/dist/chunk-VX3HS6PE.js +4569 -0
- package/dist/chunk-VX3HS6PE.js.map +1 -0
- package/dist/chunk-X4LK4ODN.js +86 -0
- package/dist/chunk-X4LK4ODN.js.map +1 -0
- package/dist/chunk-ZA564323.js +331 -0
- package/dist/chunk-ZA564323.js.map +1 -0
- package/dist/completion/index.d.ts +6 -36
- package/dist/completion/index.js +34 -29
- package/dist/documents/index.d.ts +34 -0
- package/dist/documents/index.js +340 -0
- package/dist/documents/index.js.map +1 -0
- package/dist/dynamic-tools-aIZlg5x1.d.ts +45 -0
- package/dist/embeddings/index.d.ts +11 -9
- package/dist/embeddings/index.js +3 -4
- package/dist/evals/index.d.ts +57 -21
- package/dist/evals/index.js +209 -104
- package/dist/evals/index.js.map +1 -1
- package/dist/extractor/index.d.ts +27 -42
- package/dist/extractor/index.js +9 -22
- package/dist/guardrails/index.d.ts +7 -129
- package/dist/guardrails/index.js +1 -1
- package/dist/image-generation/index.d.ts +23 -23
- package/dist/image-generation/index.js +7 -39
- package/dist/image-generation/index.js.map +1 -1
- package/dist/index.d.ts +24 -22
- package/dist/index.js +85 -68
- package/dist/internal/agent.d.ts +156 -10
- package/dist/internal/agent.js +58 -18
- package/dist/internal/agent.js.map +1 -1
- package/dist/mcp/index.d.ts +7 -15
- package/dist/mcp/index.js +3 -348
- package/dist/mcp/index.js.map +1 -1
- package/dist/memory/index.d.ts +20 -6
- package/dist/memory/index.js +11 -10
- package/dist/middleware-kcF8AusP.d.ts +59 -0
- package/dist/model-call-options-CZkSw_xN.d.ts +6 -0
- package/dist/model-listing/index.d.ts +3 -1
- package/dist/observability/index.d.ts +23 -4
- package/dist/observability/index.js +10 -5
- package/dist/observability/index.js.map +1 -1
- package/dist/pipeline/index.d.ts +111 -73
- package/dist/pipeline/index.js +471 -286
- package/dist/pipeline/index.js.map +1 -1
- package/dist/provider-output-error-BEwDgVv3.d.ts +99 -0
- package/dist/retry-CjvSlKGW.d.ts +16 -0
- package/dist/skills/index.d.ts +5 -4
- package/dist/skills/index.js +8 -8
- package/dist/speech-generation/index.d.ts +37 -0
- package/dist/speech-generation/index.js +10 -0
- package/dist/streaming/index.js +37 -3
- package/dist/streaming/index.js.map +1 -1
- package/dist/text-ZLECpQE7.d.ts +32 -0
- package/dist/think-tool-BwCsJ365.d.ts +40 -0
- package/dist/tool/index.d.ts +11 -6
- package/dist/tool/index.js +21 -21
- package/dist/tool-BpqpoRSE.d.ts +58 -0
- package/dist/transcription/index.d.ts +29 -22
- package/dist/transcription/index.js +7 -57
- package/dist/transcription/index.js.map +1 -1
- package/dist/type-utils-CtHVDRn_.d.ts +6 -0
- package/dist/types-CXNE592e.d.ts +130 -0
- package/dist/types-Cr4uiYo5.d.ts +99 -0
- package/dist/{types-04LqWrmy.d.ts → types-DC1U1XwW.d.ts} +1 -1
- package/dist/types-DKOXVTcq.d.ts +155 -0
- package/dist/types-DgvozfPc.d.ts +349 -0
- package/dist/types-DhkodEft.d.ts +105 -0
- package/dist/types-DjqRHeAi.d.ts +31 -0
- package/dist/types-Sue2hb_L.d.ts +403 -0
- package/dist/vector-store/index.d.ts +34 -34
- package/dist/vector-store/index.js +10 -6
- package/package.json +22 -24
- package/dist/agent-x3YTyv5i.d.ts +0 -222
- package/dist/audio-generation/index.d.ts +0 -33
- package/dist/audio-generation/index.js +0 -42
- package/dist/audio-generation/index.js.map +0 -1
- package/dist/chunk-2ODTMRHP.js +0 -54
- package/dist/chunk-2ODTMRHP.js.map +0 -1
- package/dist/chunk-ADH7NNCS.js +0 -512
- package/dist/chunk-ADH7NNCS.js.map +0 -1
- package/dist/chunk-BALBBVI3.js +0 -2732
- package/dist/chunk-BALBBVI3.js.map +0 -1
- package/dist/chunk-CQNNSZPG.js +0 -9
- package/dist/chunk-CQNNSZPG.js.map +0 -1
- package/dist/chunk-CWUJUSOS.js.map +0 -1
- package/dist/chunk-DALYP4PX.js +0 -225
- package/dist/chunk-DALYP4PX.js.map +0 -1
- package/dist/chunk-HYUYZEAJ.js +0 -223
- package/dist/chunk-HYUYZEAJ.js.map +0 -1
- package/dist/chunk-I6XOQ4LK.js +0 -466
- package/dist/chunk-I6XOQ4LK.js.map +0 -1
- package/dist/chunk-JI5YZWNT.js +0 -220
- package/dist/chunk-JI5YZWNT.js.map +0 -1
- package/dist/chunk-MC3CCKEB.js +0 -221
- package/dist/chunk-MC3CCKEB.js.map +0 -1
- package/dist/chunk-MELYDKWQ.js +0 -337
- package/dist/chunk-MELYDKWQ.js.map +0 -1
- package/dist/chunk-MNWK2USR.js +0 -243
- package/dist/chunk-MNWK2USR.js.map +0 -1
- package/dist/chunk-MRQLEK2B.js.map +0 -1
- package/dist/chunk-NCPN4SJR.js.map +0 -1
- package/dist/chunk-OIMLU4SF.js +0 -20
- package/dist/chunk-OIMLU4SF.js.map +0 -1
- package/dist/chunk-Q25IWLBT.js +0 -138
- package/dist/chunk-Q25IWLBT.js.map +0 -1
- package/dist/chunk-UQX6EXWG.js +0 -33
- package/dist/chunk-UQX6EXWG.js.map +0 -1
- package/dist/chunk-WQKHFADH.js +0 -12
- package/dist/chunk-WQKHFADH.js.map +0 -1
- package/dist/chunk-XUUY2L2D.js +0 -42
- package/dist/chunk-XUUY2L2D.js.map +0 -1
- package/dist/chunk-XWUC7CIT.js +0 -1
- package/dist/chunk-XWUC7CIT.js.map +0 -1
- package/dist/chunk-YLMDBQO4.js +0 -141
- package/dist/chunk-YLMDBQO4.js.map +0 -1
- package/dist/errors-2moLDuuN.d.ts +0 -17
- package/dist/hooks/index.d.ts +0 -12
- package/dist/hooks/index.js +0 -17
- package/dist/index-BxSbmOMr.d.ts +0 -257
- package/dist/json-BVPssigK.d.ts +0 -39
- package/dist/loaders/index.d.ts +0 -91
- package/dist/loaders/index.js +0 -299
- package/dist/loaders/index.js.map +0 -1
- package/dist/middleware-Dp3d_pxi.d.ts +0 -90
- package/dist/request/index.d.ts +0 -28
- package/dist/request/index.js +0 -25
- package/dist/think-tool-DfCMuO8e.d.ts +0 -26
- package/dist/tool-Cohdv5GC.d.ts +0 -65
- package/dist/types-BCTRUGex.d.ts +0 -47
- package/dist/types-BrLbKnEz.d.ts +0 -119
- package/dist/types-D9JpeAPF.d.ts +0 -114
- package/dist/types-G12i56s2.d.ts +0 -354
- package/dist/types-JJCxRnaZ.d.ts +0 -70
- package/dist/types-O-abTIin.d.ts +0 -79
- package/dist/ui/index.d.ts +0 -107
- package/dist/ui/index.js +0 -10
- package/dist/ui/index.js.map +0 -1
- /package/dist/{hooks → agent/interactions}/index.js.map +0 -0
- /package/dist/{request → speech-generation}/index.js.map +0 -0
package/dist/index-BxSbmOMr.d.ts
DELETED
|
@@ -1,257 +0,0 @@
|
|
|
1
|
-
import { Y as ReasoningContentType, p as ToolCall, h as CompletionSource, o as ProviderToolCall, U as Usage, j as ContextUsage, M as Message, f as CompletionRequest, u as ToolResultContent, g as CompletionResponse, _ as ToolCallArgumentsMode, J as JsonObject, O as CompletionModelCapabilities, r as ToolDefinition, l as JsonValue } from './types-G12i56s2.js';
|
|
2
|
-
import { GuardrailDecisionRecord } from './guardrails/index.js';
|
|
3
|
-
import { g as ToolCallStreamEvent } from './tool-Cohdv5GC.js';
|
|
4
|
-
|
|
5
|
-
type PromptResponse = {
|
|
6
|
-
output: string;
|
|
7
|
-
usage: Usage;
|
|
8
|
-
contextUsage?: ContextUsage | undefined;
|
|
9
|
-
messages: Message[];
|
|
10
|
-
trace?: AgentTraceInfo | undefined;
|
|
11
|
-
guardrails?: GuardrailDecisionRecord[] | undefined;
|
|
12
|
-
sources?: CompletionSource[] | undefined;
|
|
13
|
-
providerToolCalls?: ProviderToolCall[] | undefined;
|
|
14
|
-
};
|
|
15
|
-
type AgentDeltaEvent = {
|
|
16
|
-
type: "text_delta";
|
|
17
|
-
delta: string;
|
|
18
|
-
} | {
|
|
19
|
-
type: "reasoning_delta";
|
|
20
|
-
delta: string;
|
|
21
|
-
id?: string;
|
|
22
|
-
contentType?: ReasoningContentType;
|
|
23
|
-
signature?: string;
|
|
24
|
-
} | {
|
|
25
|
-
type: "tool_call";
|
|
26
|
-
toolCall: ToolCall;
|
|
27
|
-
} | {
|
|
28
|
-
type: "source";
|
|
29
|
-
source: CompletionSource;
|
|
30
|
-
} | {
|
|
31
|
-
type: "provider_tool_call";
|
|
32
|
-
toolCall: ProviderToolCall;
|
|
33
|
-
};
|
|
34
|
-
type AgentErrorStreamEvent = {
|
|
35
|
-
type: "error";
|
|
36
|
-
error: unknown;
|
|
37
|
-
usage: Usage;
|
|
38
|
-
};
|
|
39
|
-
type AgentStreamOptions = {
|
|
40
|
-
/** @default true */
|
|
41
|
-
includeToolCallDeltas?: boolean;
|
|
42
|
-
};
|
|
43
|
-
type AgentToolCallDeltaEvent = {
|
|
44
|
-
type: "tool_call_delta";
|
|
45
|
-
turn: number;
|
|
46
|
-
id: string;
|
|
47
|
-
callId?: string;
|
|
48
|
-
name?: string;
|
|
49
|
-
argumentsDelta?: string;
|
|
50
|
-
argumentsMode?: ToolCallArgumentsMode;
|
|
51
|
-
signature?: string;
|
|
52
|
-
};
|
|
53
|
-
type AgentChildStreamEventBase<RawResponse = unknown> = {
|
|
54
|
-
type: "turn_start";
|
|
55
|
-
turn: number;
|
|
56
|
-
prompt: Message;
|
|
57
|
-
history: Message[];
|
|
58
|
-
} | {
|
|
59
|
-
type: "generation_start";
|
|
60
|
-
turn: number;
|
|
61
|
-
request: CompletionRequest;
|
|
62
|
-
modelInfo: AgentGenerationModelInfo;
|
|
63
|
-
} | {
|
|
64
|
-
type: "text_delta";
|
|
65
|
-
turn: number;
|
|
66
|
-
delta: string;
|
|
67
|
-
} | {
|
|
68
|
-
type: "reasoning_delta";
|
|
69
|
-
turn: number;
|
|
70
|
-
delta: string;
|
|
71
|
-
id?: string;
|
|
72
|
-
contentType?: ReasoningContentType;
|
|
73
|
-
signature?: string;
|
|
74
|
-
} | {
|
|
75
|
-
type: "tool_call";
|
|
76
|
-
turn: number;
|
|
77
|
-
toolCall: ToolCall;
|
|
78
|
-
} | {
|
|
79
|
-
type: "source";
|
|
80
|
-
turn: number;
|
|
81
|
-
source: CompletionSource;
|
|
82
|
-
} | {
|
|
83
|
-
type: "provider_tool_call";
|
|
84
|
-
turn: number;
|
|
85
|
-
toolCall: ProviderToolCall;
|
|
86
|
-
} | {
|
|
87
|
-
type: "tool_result";
|
|
88
|
-
turn: number;
|
|
89
|
-
toolName: string;
|
|
90
|
-
toolCallId?: string;
|
|
91
|
-
internalCallId: string;
|
|
92
|
-
args: string;
|
|
93
|
-
result: string;
|
|
94
|
-
structuredResult?: ToolResultContent[] | undefined;
|
|
95
|
-
} | {
|
|
96
|
-
type: "turn_end";
|
|
97
|
-
turn: number;
|
|
98
|
-
response: CompletionResponse<RawResponse>;
|
|
99
|
-
firstDeltaMs?: number | undefined;
|
|
100
|
-
} | {
|
|
101
|
-
type: "guardrail_decision";
|
|
102
|
-
turn?: number | undefined;
|
|
103
|
-
decision: GuardrailDecisionRecord;
|
|
104
|
-
} | {
|
|
105
|
-
type: "final";
|
|
106
|
-
runId: string;
|
|
107
|
-
output: string;
|
|
108
|
-
usage: Usage;
|
|
109
|
-
contextUsage?: ContextUsage | undefined;
|
|
110
|
-
messages: Message[];
|
|
111
|
-
trace?: AgentTraceInfo | undefined;
|
|
112
|
-
guardrails?: GuardrailDecisionRecord[] | undefined;
|
|
113
|
-
sources?: CompletionSource[] | undefined;
|
|
114
|
-
providerToolCalls?: ProviderToolCall[] | undefined;
|
|
115
|
-
} | AgentErrorStreamEvent;
|
|
116
|
-
type AgentChildStreamEventWithoutToolCallDeltas<RawResponse = unknown> = AgentChildStreamEventBase<RawResponse>;
|
|
117
|
-
type AgentChildStreamEvent<RawResponse = unknown> = AgentChildStreamEventBase<RawResponse> | AgentToolCallDeltaEvent;
|
|
118
|
-
type AgentChildStreamEventWithToolCallDeltas<RawResponse = unknown> = AgentChildStreamEvent<RawResponse>;
|
|
119
|
-
type AgentToolStreamEvent<ChildEvent> = {
|
|
120
|
-
type: "agent_tool_event";
|
|
121
|
-
turn: number;
|
|
122
|
-
toolName: string;
|
|
123
|
-
toolCallId?: string;
|
|
124
|
-
internalCallId: string;
|
|
125
|
-
agentId: string;
|
|
126
|
-
agentName?: string;
|
|
127
|
-
event: ChildEvent;
|
|
128
|
-
};
|
|
129
|
-
type AgentStreamEventWithoutToolCallDeltas<RawResponse = unknown> = AgentChildStreamEventWithoutToolCallDeltas<RawResponse> | AgentToolStreamEvent<AgentChildStreamEventWithoutToolCallDeltas<RawResponse>>;
|
|
130
|
-
type AgentStreamEvent<RawResponse = unknown> = AgentChildStreamEvent<RawResponse> | AgentToolStreamEvent<AgentChildStreamEvent<RawResponse>>;
|
|
131
|
-
type AgentStreamEventWithToolCallDeltas<RawResponse = unknown> = AgentStreamEvent<RawResponse>;
|
|
132
|
-
|
|
133
|
-
type AgentTraceInfo = {
|
|
134
|
-
traceId?: string | undefined;
|
|
135
|
-
observationId?: string | undefined;
|
|
136
|
-
};
|
|
137
|
-
type AgentTraceOptions = {
|
|
138
|
-
name?: string | undefined;
|
|
139
|
-
userId?: string | undefined;
|
|
140
|
-
sessionId?: string | undefined;
|
|
141
|
-
metadata?: Record<string, unknown> | undefined;
|
|
142
|
-
tags?: string[] | undefined;
|
|
143
|
-
version?: string | undefined;
|
|
144
|
-
traceId?: string | undefined;
|
|
145
|
-
failOnObserverError?: boolean | undefined;
|
|
146
|
-
promptRef?: AgentRunPromptRef | undefined;
|
|
147
|
-
};
|
|
148
|
-
type AgentRunPromptRef = {
|
|
149
|
-
name: string;
|
|
150
|
-
version?: number | undefined;
|
|
151
|
-
};
|
|
152
|
-
type AgentRunStartArgs = {
|
|
153
|
-
agentName?: string | undefined;
|
|
154
|
-
agentDescription?: string | undefined;
|
|
155
|
-
instructions?: string | undefined;
|
|
156
|
-
trace?: AgentTraceOptions | undefined;
|
|
157
|
-
prompt: Message;
|
|
158
|
-
promptRef?: AgentRunPromptRef | undefined;
|
|
159
|
-
history: Message[];
|
|
160
|
-
maxTurns: number;
|
|
161
|
-
};
|
|
162
|
-
type AgentRunEndArgs = {
|
|
163
|
-
output: string;
|
|
164
|
-
usage: Usage;
|
|
165
|
-
messages: Message[];
|
|
166
|
-
sources?: CompletionSource[] | undefined;
|
|
167
|
-
providerToolCalls?: ProviderToolCall[] | undefined;
|
|
168
|
-
};
|
|
169
|
-
type AgentRunErrorArgs = {
|
|
170
|
-
error: unknown;
|
|
171
|
-
usage: Usage;
|
|
172
|
-
messages: Message[];
|
|
173
|
-
};
|
|
174
|
-
type AgentGenerationModelInfo = {
|
|
175
|
-
provider: string;
|
|
176
|
-
defaultModel: string;
|
|
177
|
-
capabilities?: CompletionModelCapabilities | undefined;
|
|
178
|
-
};
|
|
179
|
-
type AgentGenerationStartArgs = {
|
|
180
|
-
turn: number;
|
|
181
|
-
request: CompletionRequest;
|
|
182
|
-
providerRequest?: JsonObject | undefined;
|
|
183
|
-
modelInfo?: AgentGenerationModelInfo | undefined;
|
|
184
|
-
};
|
|
185
|
-
type AgentGenerationEndArgs<RawResponse = unknown> = {
|
|
186
|
-
turn: number;
|
|
187
|
-
response: CompletionResponse<RawResponse>;
|
|
188
|
-
firstDeltaMs?: number | undefined;
|
|
189
|
-
};
|
|
190
|
-
type AgentGenerationErrorArgs = {
|
|
191
|
-
turn: number;
|
|
192
|
-
error: unknown;
|
|
193
|
-
};
|
|
194
|
-
type AgentGenerationUpdateArgs = {
|
|
195
|
-
turn: number;
|
|
196
|
-
delta: AgentDeltaEvent;
|
|
197
|
-
};
|
|
198
|
-
type AgentRunEventArgs = {
|
|
199
|
-
name: string;
|
|
200
|
-
attributes?: Record<string, JsonValue | undefined> | undefined;
|
|
201
|
-
level?: "DEFAULT" | "WARNING" | "ERROR" | undefined;
|
|
202
|
-
timestamp?: Date | string | undefined;
|
|
203
|
-
};
|
|
204
|
-
type AgentToolStartArgs = {
|
|
205
|
-
turn: number;
|
|
206
|
-
toolCall: ToolCall;
|
|
207
|
-
toolName: string;
|
|
208
|
-
args: string;
|
|
209
|
-
internalCallId: string;
|
|
210
|
-
toolCallId?: string | undefined;
|
|
211
|
-
toolDefinition?: ToolDefinition | undefined;
|
|
212
|
-
toolMetadata?: JsonObject | undefined;
|
|
213
|
-
};
|
|
214
|
-
type AgentToolEndArgs = AgentToolStartArgs & {
|
|
215
|
-
result: string;
|
|
216
|
-
structuredResult?: ToolResultContent[] | undefined;
|
|
217
|
-
skipped: boolean;
|
|
218
|
-
};
|
|
219
|
-
type AgentToolErrorArgs = AgentToolStartArgs & {
|
|
220
|
-
error: unknown;
|
|
221
|
-
};
|
|
222
|
-
type AgentToolStreamEventArgs = AgentToolStartArgs & {
|
|
223
|
-
event: ToolCallStreamEvent;
|
|
224
|
-
};
|
|
225
|
-
interface AgentGenerationObserver {
|
|
226
|
-
end(args: AgentGenerationEndArgs): void | Promise<void>;
|
|
227
|
-
error?(args: AgentGenerationErrorArgs): void | Promise<void>;
|
|
228
|
-
update?(args: AgentGenerationUpdateArgs): void | Promise<void>;
|
|
229
|
-
}
|
|
230
|
-
interface AgentToolObserver {
|
|
231
|
-
streamEvent?(args: AgentToolStreamEventArgs): void | Promise<void>;
|
|
232
|
-
end(args: AgentToolEndArgs): void | Promise<void>;
|
|
233
|
-
error?(args: AgentToolErrorArgs): void | Promise<void>;
|
|
234
|
-
}
|
|
235
|
-
interface AgentRunObserver {
|
|
236
|
-
readonly trace?: AgentTraceInfo | undefined;
|
|
237
|
-
startGeneration?(args: AgentGenerationStartArgs): AgentGenerationObserver | undefined | Promise<AgentGenerationObserver | undefined>;
|
|
238
|
-
startTool?(args: AgentToolStartArgs): AgentToolObserver | undefined | Promise<AgentToolObserver | undefined>;
|
|
239
|
-
end(args: AgentRunEndArgs): void | Promise<void>;
|
|
240
|
-
error?(args: AgentRunErrorArgs): void | Promise<void>;
|
|
241
|
-
event?(args: AgentRunEventArgs): void | Promise<void>;
|
|
242
|
-
}
|
|
243
|
-
interface AgentObserver {
|
|
244
|
-
startRun(args: AgentRunStartArgs): AgentRunObserver | undefined | Promise<AgentRunObserver | undefined>;
|
|
245
|
-
flush?(): void | Promise<void>;
|
|
246
|
-
shutdown?(): void | Promise<void>;
|
|
247
|
-
}
|
|
248
|
-
type AgentObserverRegistration = {
|
|
249
|
-
observer: AgentObserver;
|
|
250
|
-
failOnObserverError?: boolean | undefined;
|
|
251
|
-
};
|
|
252
|
-
type ObserveOptions = {
|
|
253
|
-
failOnObserverError?: boolean | undefined;
|
|
254
|
-
};
|
|
255
|
-
declare function createObserver(observer: AgentObserver): AgentObserver;
|
|
256
|
-
|
|
257
|
-
export { type AgentChildStreamEvent as A, type AgentToolObserver as B, type AgentToolStartArgs as C, type AgentToolStreamEventArgs as D, type AgentTraceInfo as E, createObserver as F, type ObserveOptions as O, type PromptResponse as P, type AgentChildStreamEventWithToolCallDeltas as a, type AgentChildStreamEventWithoutToolCallDeltas as b, type AgentErrorStreamEvent as c, type AgentStreamEvent as d, type AgentStreamEventWithToolCallDeltas as e, type AgentStreamEventWithoutToolCallDeltas as f, type AgentStreamOptions as g, type AgentToolCallDeltaEvent as h, type AgentObserver as i, type AgentTraceOptions as j, type AgentObserverRegistration as k, type AgentDeltaEvent as l, type AgentGenerationEndArgs as m, type AgentGenerationErrorArgs as n, type AgentGenerationModelInfo as o, type AgentGenerationObserver as p, type AgentGenerationStartArgs as q, type AgentGenerationUpdateArgs as r, type AgentRunEndArgs as s, type AgentRunErrorArgs as t, type AgentRunEventArgs as u, type AgentRunObserver as v, type AgentRunPromptRef as w, type AgentRunStartArgs as x, type AgentToolEndArgs as y, type AgentToolErrorArgs as z };
|
package/dist/json-BVPssigK.d.ts
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { Z as ZodSchema } from './zod-schema-C7F4clpm.js';
|
|
2
|
-
import { M as Message, D as Document, i as CompletionTool, L as ToolChoice, J as JsonObject, l as JsonValue, A as AssistantContent, U as Usage, g as CompletionResponse, C as CompletionModel, Z as StreamingCompletionModel, Q as CompletionStreamEvent } from './types-G12i56s2.js';
|
|
3
|
-
|
|
4
|
-
type CreateCompletionInput = string | Message | Message[];
|
|
5
|
-
type CreateCompletionBaseOptions = {
|
|
6
|
-
input?: CreateCompletionInput | undefined;
|
|
7
|
-
messages?: Message[] | undefined;
|
|
8
|
-
instructions?: string | undefined;
|
|
9
|
-
documents?: Document[] | undefined;
|
|
10
|
-
tools?: CompletionTool[] | undefined;
|
|
11
|
-
temperature?: number | undefined;
|
|
12
|
-
maxTokens?: number | undefined;
|
|
13
|
-
toolChoice?: ToolChoice | undefined;
|
|
14
|
-
outputSchema?: JsonObject | undefined;
|
|
15
|
-
params?: JsonValue | undefined;
|
|
16
|
-
};
|
|
17
|
-
type CreateCompletionOptions = CreateCompletionBaseOptions;
|
|
18
|
-
type CreateCompletionStreamOptions = CreateCompletionBaseOptions;
|
|
19
|
-
type CreateParsedCompletionOptions<T> = Omit<CreateCompletionBaseOptions, "outputSchema"> & {
|
|
20
|
-
schema: ZodSchema<T>;
|
|
21
|
-
};
|
|
22
|
-
type CreateCompletionResult<RawResponse = unknown> = {
|
|
23
|
-
text: string;
|
|
24
|
-
content: AssistantContent[];
|
|
25
|
-
usage: Usage;
|
|
26
|
-
response: CompletionResponse<RawResponse>;
|
|
27
|
-
};
|
|
28
|
-
type CreateParsedCompletionResult<T, RawResponse = unknown> = CreateCompletionResult<RawResponse> & {
|
|
29
|
-
data: T;
|
|
30
|
-
};
|
|
31
|
-
type RawResponseOf<Model> = Model extends CompletionModel<infer RawResponse, infer _ModelName> ? RawResponse : unknown;
|
|
32
|
-
declare function createCompletion<Model extends CompletionModel>(model: Model, options: CreateCompletionOptions): Promise<CreateCompletionResult<RawResponseOf<Model>>>;
|
|
33
|
-
declare function createCompletionStream<Model extends StreamingCompletionModel>(model: Model, options: CreateCompletionStreamOptions): AsyncIterable<CompletionStreamEvent<RawResponseOf<Model>>>;
|
|
34
|
-
declare function createParsedCompletion<T, Model extends CompletionModel>(model: Model, options: CreateParsedCompletionOptions<T>): Promise<CreateParsedCompletionResult<T, RawResponseOf<Model>>>;
|
|
35
|
-
declare function isStreamingCompletionModel(model: CompletionModel): model is StreamingCompletionModel;
|
|
36
|
-
|
|
37
|
-
declare function isJsonValue(value: unknown): value is JsonValue;
|
|
38
|
-
|
|
39
|
-
export { type CreateCompletionBaseOptions as C, type CreateCompletionInput as a, type CreateCompletionOptions as b, type CreateCompletionResult as c, type CreateCompletionStreamOptions as d, type CreateParsedCompletionOptions as e, type CreateParsedCompletionResult as f, createCompletion as g, createCompletionStream as h, createParsedCompletion as i, isJsonValue as j, isStreamingCompletionModel as k };
|
package/dist/loaders/index.d.ts
DELETED
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
import { D as Document } from '../types-G12i56s2.js';
|
|
2
|
-
|
|
3
|
-
type LoaderResult<T> = {
|
|
4
|
-
ok: true;
|
|
5
|
-
value: T;
|
|
6
|
-
} | {
|
|
7
|
-
ok: false;
|
|
8
|
-
error: unknown;
|
|
9
|
-
};
|
|
10
|
-
type LoaderValue$1<T> = T extends {
|
|
11
|
-
ok: true;
|
|
12
|
-
value: infer Value;
|
|
13
|
-
} ? Value : never;
|
|
14
|
-
type UnwrapLoaderResult$1<T> = [LoaderValue$1<T>] extends [never] ? T : LoaderValue$1<T>;
|
|
15
|
-
type FileSource = {
|
|
16
|
-
path: string;
|
|
17
|
-
} | {
|
|
18
|
-
path: "<memory>";
|
|
19
|
-
bytes: Uint8Array;
|
|
20
|
-
};
|
|
21
|
-
type FileReadWithPath = {
|
|
22
|
-
path: string;
|
|
23
|
-
text: string;
|
|
24
|
-
};
|
|
25
|
-
type FileMode = "source" | "read" | "readWithPath";
|
|
26
|
-
type PdfSource = {
|
|
27
|
-
path: string;
|
|
28
|
-
} | {
|
|
29
|
-
path: "<memory>";
|
|
30
|
-
bytes: Uint8Array;
|
|
31
|
-
};
|
|
32
|
-
type PdfReadWithPath = {
|
|
33
|
-
path: string;
|
|
34
|
-
text: string;
|
|
35
|
-
};
|
|
36
|
-
type PdfPage = {
|
|
37
|
-
pageNumber: number;
|
|
38
|
-
text: string;
|
|
39
|
-
};
|
|
40
|
-
type PdfPageWithPath = {
|
|
41
|
-
path: string;
|
|
42
|
-
pageNumber: number;
|
|
43
|
-
text: string;
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
declare function fileToDocument(file: FileReadWithPath): Document;
|
|
47
|
-
declare function fileLoaderToDocuments(loader: AsyncIterable<FileReadWithPath>): Promise<Document[]>;
|
|
48
|
-
declare function pdfToDocument(pdf: PdfReadWithPath): Document;
|
|
49
|
-
declare function pdfLoaderToDocuments(loader: AsyncIterable<PdfReadWithPath>): Promise<Document[]>;
|
|
50
|
-
declare function pdfPageToDocument(page: PdfPageWithPath): Document;
|
|
51
|
-
declare function pdfPageLoaderToDocuments(loader: AsyncIterable<PdfPageWithPath>): Promise<Document[]>;
|
|
52
|
-
|
|
53
|
-
declare class FileLoader<T = LoaderResult<FileSource>> implements AsyncIterable<T> {
|
|
54
|
-
private readonly source;
|
|
55
|
-
private readonly mode;
|
|
56
|
-
private readonly skipErrors;
|
|
57
|
-
private constructor();
|
|
58
|
-
static withGlob(pattern: string): FileLoader<LoaderResult<FileSource>>;
|
|
59
|
-
static withDir(directory: string): FileLoader<LoaderResult<FileSource>>;
|
|
60
|
-
static fromBytes(bytes: Uint8Array | ArrayBuffer): FileLoader<LoaderResult<FileSource>>;
|
|
61
|
-
static fromBytesMany(bytes: Array<Uint8Array | ArrayBuffer>): FileLoader<LoaderResult<FileSource>>;
|
|
62
|
-
read(): FileLoader<LoaderResult<string>>;
|
|
63
|
-
readWithPath(): FileLoader<LoaderResult<FileReadWithPath>>;
|
|
64
|
-
ignoreErrors(): FileLoader<UnwrapLoaderResult$1<T>>;
|
|
65
|
-
[Symbol.asyncIterator](): AsyncIterator<T>;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
type LoaderValue<T> = T extends {
|
|
69
|
-
ok: true;
|
|
70
|
-
value: infer Value;
|
|
71
|
-
} ? Value : never;
|
|
72
|
-
type UnwrapLoaderResult<T> = [LoaderValue<T>] extends [never] ? T : LoaderValue<T>;
|
|
73
|
-
declare class PdfFileLoader<T = LoaderResult<PdfSource>> implements AsyncIterable<T> {
|
|
74
|
-
private readonly source;
|
|
75
|
-
private readonly mode;
|
|
76
|
-
private readonly skipErrors;
|
|
77
|
-
private constructor();
|
|
78
|
-
static withGlob(pattern: string): PdfFileLoader<LoaderResult<PdfSource>>;
|
|
79
|
-
static withDir(directory: string): PdfFileLoader<LoaderResult<PdfSource>>;
|
|
80
|
-
static fromBytes(bytes: Uint8Array | ArrayBuffer): PdfFileLoader<LoaderResult<PdfSource>>;
|
|
81
|
-
static fromBytesMany(bytes: Array<Uint8Array | ArrayBuffer>): PdfFileLoader<LoaderResult<PdfSource>>;
|
|
82
|
-
read(): PdfFileLoader<LoaderResult<string>>;
|
|
83
|
-
readWithPath(): PdfFileLoader<LoaderResult<PdfReadWithPath>>;
|
|
84
|
-
byPage(this: PdfFileLoader<LoaderResult<PdfReadWithPath>>): PdfFileLoader<LoaderResult<PdfPageWithPath>>;
|
|
85
|
-
byPage(this: PdfFileLoader<PdfReadWithPath>): PdfFileLoader<PdfPageWithPath>;
|
|
86
|
-
byPage(): PdfFileLoader<LoaderResult<PdfPage>>;
|
|
87
|
-
ignoreErrors(): PdfFileLoader<UnwrapLoaderResult<T>>;
|
|
88
|
-
[Symbol.asyncIterator](): AsyncIterator<T>;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
export { FileLoader, type FileMode, type FileReadWithPath, type FileSource, type LoaderResult, type LoaderValue$1 as LoaderValue, PdfFileLoader, type PdfPage, type PdfPageWithPath, type PdfReadWithPath, type PdfSource, type UnwrapLoaderResult$1 as UnwrapLoaderResult, fileLoaderToDocuments, fileToDocument, pdfLoaderToDocuments, pdfPageLoaderToDocuments, pdfPageToDocument, pdfToDocument };
|
package/dist/loaders/index.js
DELETED
|
@@ -1,299 +0,0 @@
|
|
|
1
|
-
// src/loaders/documents.ts
|
|
2
|
-
function fileToDocument(file) {
|
|
3
|
-
return {
|
|
4
|
-
id: file.path,
|
|
5
|
-
text: file.text,
|
|
6
|
-
additionalProps: {
|
|
7
|
-
source: file.path,
|
|
8
|
-
mediaType: "text/plain"
|
|
9
|
-
}
|
|
10
|
-
};
|
|
11
|
-
}
|
|
12
|
-
async function fileLoaderToDocuments(loader) {
|
|
13
|
-
const documents = [];
|
|
14
|
-
for await (const file of loader) {
|
|
15
|
-
documents.push(fileToDocument(file));
|
|
16
|
-
}
|
|
17
|
-
return documents;
|
|
18
|
-
}
|
|
19
|
-
function pdfToDocument(pdf) {
|
|
20
|
-
return {
|
|
21
|
-
id: pdf.path,
|
|
22
|
-
text: pdf.text,
|
|
23
|
-
additionalProps: {
|
|
24
|
-
source: pdf.path,
|
|
25
|
-
mediaType: "application/pdf"
|
|
26
|
-
}
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
async function pdfLoaderToDocuments(loader) {
|
|
30
|
-
const documents = [];
|
|
31
|
-
for await (const pdf of loader) {
|
|
32
|
-
documents.push(pdfToDocument(pdf));
|
|
33
|
-
}
|
|
34
|
-
return documents;
|
|
35
|
-
}
|
|
36
|
-
function pdfPageToDocument(page) {
|
|
37
|
-
return {
|
|
38
|
-
id: `${page.path}#page=${page.pageNumber}`,
|
|
39
|
-
text: page.text,
|
|
40
|
-
additionalProps: {
|
|
41
|
-
source: page.path,
|
|
42
|
-
mediaType: "application/pdf",
|
|
43
|
-
pageNumber: String(page.pageNumber)
|
|
44
|
-
}
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
async function pdfPageLoaderToDocuments(loader) {
|
|
48
|
-
const documents = [];
|
|
49
|
-
for await (const page of loader) {
|
|
50
|
-
documents.push(pdfPageToDocument(page));
|
|
51
|
-
}
|
|
52
|
-
return documents;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
// src/loaders/file.ts
|
|
56
|
-
import { readdir, readFile } from "fs/promises";
|
|
57
|
-
import { join } from "path";
|
|
58
|
-
|
|
59
|
-
// src/loaders/shared.ts
|
|
60
|
-
import { isAbsolute } from "path";
|
|
61
|
-
import { glob } from "tinyglobby";
|
|
62
|
-
function ok(value) {
|
|
63
|
-
return { ok: true, value };
|
|
64
|
-
}
|
|
65
|
-
function err(error) {
|
|
66
|
-
return { ok: false, error };
|
|
67
|
-
}
|
|
68
|
-
async function sortedGlob(pattern) {
|
|
69
|
-
return (await glob(pattern, { absolute: isAbsolute(pattern), onlyFiles: true })).sort(
|
|
70
|
-
(left, right) => left.localeCompare(right)
|
|
71
|
-
);
|
|
72
|
-
}
|
|
73
|
-
function toUint8Array(bytes) {
|
|
74
|
-
if (bytes instanceof Uint8Array) {
|
|
75
|
-
return new Uint8Array(
|
|
76
|
-
bytes.buffer.slice(bytes.byteOffset, bytes.byteOffset + bytes.byteLength)
|
|
77
|
-
);
|
|
78
|
-
}
|
|
79
|
-
return new Uint8Array(bytes);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
// src/loaders/file.ts
|
|
83
|
-
var FileLoader = class _FileLoader {
|
|
84
|
-
constructor(source, mode, skipErrors) {
|
|
85
|
-
this.source = source;
|
|
86
|
-
this.mode = mode;
|
|
87
|
-
this.skipErrors = skipErrors;
|
|
88
|
-
}
|
|
89
|
-
source;
|
|
90
|
-
mode;
|
|
91
|
-
skipErrors;
|
|
92
|
-
static withGlob(pattern) {
|
|
93
|
-
return new _FileLoader(
|
|
94
|
-
async function* () {
|
|
95
|
-
for (const path of await sortedGlob(pattern)) {
|
|
96
|
-
yield ok({ path });
|
|
97
|
-
}
|
|
98
|
-
},
|
|
99
|
-
"source",
|
|
100
|
-
false
|
|
101
|
-
);
|
|
102
|
-
}
|
|
103
|
-
static withDir(directory) {
|
|
104
|
-
return new _FileLoader(
|
|
105
|
-
async function* () {
|
|
106
|
-
const entries = await readdir(directory, { withFileTypes: true });
|
|
107
|
-
const files = entries.filter((entry) => entry.isFile()).map((entry) => join(directory, entry.name)).sort((left, right) => left.localeCompare(right));
|
|
108
|
-
for (const path of files) {
|
|
109
|
-
yield ok({ path });
|
|
110
|
-
}
|
|
111
|
-
},
|
|
112
|
-
"source",
|
|
113
|
-
false
|
|
114
|
-
);
|
|
115
|
-
}
|
|
116
|
-
static fromBytes(bytes) {
|
|
117
|
-
return _FileLoader.fromBytesMany([bytes]);
|
|
118
|
-
}
|
|
119
|
-
static fromBytesMany(bytes) {
|
|
120
|
-
return new _FileLoader(
|
|
121
|
-
async function* () {
|
|
122
|
-
for (const value of bytes) {
|
|
123
|
-
yield ok({ path: "<memory>", bytes: toUint8Array(value) });
|
|
124
|
-
}
|
|
125
|
-
},
|
|
126
|
-
"source",
|
|
127
|
-
false
|
|
128
|
-
);
|
|
129
|
-
}
|
|
130
|
-
read() {
|
|
131
|
-
return new _FileLoader(this.source, "read", this.skipErrors);
|
|
132
|
-
}
|
|
133
|
-
readWithPath() {
|
|
134
|
-
return new _FileLoader(this.source, "readWithPath", this.skipErrors);
|
|
135
|
-
}
|
|
136
|
-
ignoreErrors() {
|
|
137
|
-
return new _FileLoader(this.source, this.mode, true);
|
|
138
|
-
}
|
|
139
|
-
async *[Symbol.asyncIterator]() {
|
|
140
|
-
for await (const item of this.source()) {
|
|
141
|
-
const result = await mapFileResult(item, this.mode);
|
|
142
|
-
if (!result.ok && this.skipErrors) {
|
|
143
|
-
continue;
|
|
144
|
-
}
|
|
145
|
-
yield this.skipErrors && result.ok ? result.value : result;
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
};
|
|
149
|
-
async function mapFileResult(item, mode) {
|
|
150
|
-
if (!item.ok) {
|
|
151
|
-
return item;
|
|
152
|
-
}
|
|
153
|
-
if (mode === "source") {
|
|
154
|
-
return item;
|
|
155
|
-
}
|
|
156
|
-
try {
|
|
157
|
-
const text = await readFileSource(item.value);
|
|
158
|
-
return mode === "read" ? ok(text) : ok({ path: item.value.path, text });
|
|
159
|
-
} catch (error) {
|
|
160
|
-
return err(error);
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
async function readFileSource(source) {
|
|
164
|
-
if ("bytes" in source) {
|
|
165
|
-
return new TextDecoder().decode(source.bytes);
|
|
166
|
-
}
|
|
167
|
-
return readFile(source.path, "utf8");
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
// src/loaders/pdf.ts
|
|
171
|
-
import { readdir as readdir2, readFile as readFile2 } from "fs/promises";
|
|
172
|
-
import { join as join2 } from "path";
|
|
173
|
-
var PdfFileLoader = class _PdfFileLoader {
|
|
174
|
-
constructor(source, mode, skipErrors) {
|
|
175
|
-
this.source = source;
|
|
176
|
-
this.mode = mode;
|
|
177
|
-
this.skipErrors = skipErrors;
|
|
178
|
-
}
|
|
179
|
-
source;
|
|
180
|
-
mode;
|
|
181
|
-
skipErrors;
|
|
182
|
-
static withGlob(pattern) {
|
|
183
|
-
return new _PdfFileLoader(
|
|
184
|
-
async function* () {
|
|
185
|
-
for (const path of await sortedGlob(pattern)) {
|
|
186
|
-
yield ok({ path });
|
|
187
|
-
}
|
|
188
|
-
},
|
|
189
|
-
"source",
|
|
190
|
-
false
|
|
191
|
-
);
|
|
192
|
-
}
|
|
193
|
-
static withDir(directory) {
|
|
194
|
-
return new _PdfFileLoader(
|
|
195
|
-
async function* () {
|
|
196
|
-
const entries = await readdir2(directory, { withFileTypes: true });
|
|
197
|
-
const files = entries.filter((entry) => entry.isFile()).map((entry) => join2(directory, entry.name)).sort((left, right) => left.localeCompare(right));
|
|
198
|
-
for (const path of files) {
|
|
199
|
-
yield ok({ path });
|
|
200
|
-
}
|
|
201
|
-
},
|
|
202
|
-
"source",
|
|
203
|
-
false
|
|
204
|
-
);
|
|
205
|
-
}
|
|
206
|
-
static fromBytes(bytes) {
|
|
207
|
-
return _PdfFileLoader.fromBytesMany([bytes]);
|
|
208
|
-
}
|
|
209
|
-
static fromBytesMany(bytes) {
|
|
210
|
-
return new _PdfFileLoader(
|
|
211
|
-
async function* () {
|
|
212
|
-
for (const value of bytes) {
|
|
213
|
-
yield ok({ path: "<memory>", bytes: toUint8Array(value) });
|
|
214
|
-
}
|
|
215
|
-
},
|
|
216
|
-
"source",
|
|
217
|
-
false
|
|
218
|
-
);
|
|
219
|
-
}
|
|
220
|
-
read() {
|
|
221
|
-
return new _PdfFileLoader(this.source, "read", this.skipErrors);
|
|
222
|
-
}
|
|
223
|
-
readWithPath() {
|
|
224
|
-
return new _PdfFileLoader(this.source, "readWithPath", this.skipErrors);
|
|
225
|
-
}
|
|
226
|
-
byPage() {
|
|
227
|
-
const mode = this.mode === "readWithPath" ? "byPageWithPath" : "byPage";
|
|
228
|
-
return new _PdfFileLoader(this.source, mode, this.skipErrors);
|
|
229
|
-
}
|
|
230
|
-
ignoreErrors() {
|
|
231
|
-
return new _PdfFileLoader(this.source, this.mode, true);
|
|
232
|
-
}
|
|
233
|
-
async *[Symbol.asyncIterator]() {
|
|
234
|
-
for await (const item of this.source()) {
|
|
235
|
-
const results = await mapPdfResult(item, this.mode);
|
|
236
|
-
for (const result of results) {
|
|
237
|
-
if (!result.ok && this.skipErrors) {
|
|
238
|
-
continue;
|
|
239
|
-
}
|
|
240
|
-
yield this.skipErrors && result.ok ? result.value : result;
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
};
|
|
245
|
-
async function mapPdfResult(item, mode) {
|
|
246
|
-
if (!item.ok) {
|
|
247
|
-
return [item];
|
|
248
|
-
}
|
|
249
|
-
if (mode === "source") {
|
|
250
|
-
return [item];
|
|
251
|
-
}
|
|
252
|
-
try {
|
|
253
|
-
const pages = await readPdfPages(item.value);
|
|
254
|
-
if (mode === "read") {
|
|
255
|
-
return [ok(pages.map((page) => page.text).join(""))];
|
|
256
|
-
}
|
|
257
|
-
if (mode === "readWithPath") {
|
|
258
|
-
return [ok({ path: item.value.path, text: pages.map((page) => page.text).join("") })];
|
|
259
|
-
}
|
|
260
|
-
if (mode === "byPageWithPath") {
|
|
261
|
-
return pages.map((page) => ok({ path: item.value.path, ...page }));
|
|
262
|
-
}
|
|
263
|
-
return pages.map(ok);
|
|
264
|
-
} catch (error) {
|
|
265
|
-
return [err(error)];
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
async function readPdfPages(source) {
|
|
269
|
-
const pdfjs = await import("pdfjs-dist/legacy/build/pdf.mjs");
|
|
270
|
-
const bytes = "bytes" in source ? source.bytes : toUint8Array(await readFile2(source.path));
|
|
271
|
-
const loadingTask = pdfjs.getDocument({ data: bytes });
|
|
272
|
-
const document = await loadingTask.promise;
|
|
273
|
-
const pages = [];
|
|
274
|
-
try {
|
|
275
|
-
for (let index = 1; index <= document.numPages; index += 1) {
|
|
276
|
-
const page = await document.getPage(index);
|
|
277
|
-
const content = await page.getTextContent();
|
|
278
|
-
const text = content.items.flatMap(
|
|
279
|
-
(item) => typeof item === "object" && item !== null && "str" in item ? [String(item.str)] : []
|
|
280
|
-
).join("\n");
|
|
281
|
-
pages.push({ pageNumber: index - 1, text: text.length > 0 ? `${text}
|
|
282
|
-
` : "" });
|
|
283
|
-
}
|
|
284
|
-
} finally {
|
|
285
|
-
await loadingTask.destroy();
|
|
286
|
-
}
|
|
287
|
-
return pages;
|
|
288
|
-
}
|
|
289
|
-
export {
|
|
290
|
-
FileLoader,
|
|
291
|
-
PdfFileLoader,
|
|
292
|
-
fileLoaderToDocuments,
|
|
293
|
-
fileToDocument,
|
|
294
|
-
pdfLoaderToDocuments,
|
|
295
|
-
pdfPageLoaderToDocuments,
|
|
296
|
-
pdfPageToDocument,
|
|
297
|
-
pdfToDocument
|
|
298
|
-
};
|
|
299
|
-
//# sourceMappingURL=index.js.map
|