@voltro/ai 0.84.0 → 0.86.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.
Files changed (61) hide show
  1. package/CHANGELOG.md +1215 -0
  2. package/THIRD-PARTY-NOTICES.md +5 -151
  3. package/dist/agent.d.ts +34 -41
  4. package/dist/agent.js +64 -2
  5. package/dist/agentConstants.js +4 -0
  6. package/dist/agentExecutor.js +51 -0
  7. package/dist/api.js +199 -0
  8. package/dist/appTools.js +80 -0
  9. package/dist/budget.js +201 -0
  10. package/dist/callEvidence.js +51 -0
  11. package/dist/copilot.js +126 -0
  12. package/dist/cost.js +242 -0
  13. package/dist/embed.js +41 -0
  14. package/dist/embeddingProvider.js +51 -0
  15. package/dist/eval.js +130 -0
  16. package/dist/events.d.ts +171 -168
  17. package/dist/events.js +81 -2
  18. package/dist/executableModalities.js +13 -0
  19. package/dist/gateway.js +58 -0
  20. package/dist/gatewayCatalog.js +47 -0
  21. package/dist/gatewayMedia.js +88 -0
  22. package/dist/index.d.ts +328 -326
  23. package/dist/index.js +42 -2581
  24. package/dist/inferenceDispatch.js +493 -0
  25. package/dist/inferenceQueue.js +96 -0
  26. package/dist/jsonOutputValidation.js +27 -0
  27. package/dist/mcpClient.js +332 -0
  28. package/dist/mcpTools.js +80 -0
  29. package/dist/media.js +182 -0
  30. package/dist/mediaBytes.js +19 -0
  31. package/dist/mediaCall.js +13 -0
  32. package/dist/mediaTaskProvider.js +16 -0
  33. package/dist/middleware.js +32 -0
  34. package/dist/observe.js +52 -0
  35. package/dist/prompts.js +103 -0
  36. package/dist/provider.js +303 -0
  37. package/dist/realtimeEvent.js +97 -0
  38. package/dist/realtimeSession.js +154 -0
  39. package/dist/rerank.js +61 -0
  40. package/dist/resumableStream.js +321 -0
  41. package/dist/retrieveReranked.js +16 -0
  42. package/dist/runAndPersist.js +148 -0
  43. package/dist/semanticCache.js +66 -0
  44. package/dist/speechProvider.js +16 -0
  45. package/dist/streamRegistry.js +14 -0
  46. package/dist/streamText.js +170 -0
  47. package/dist/streamTranscribe.js +74 -0
  48. package/dist/streamWakeups.js +44 -0
  49. package/dist/structuredEvidence.js +48 -0
  50. package/dist/test.js +1 -1
  51. package/dist/threads.js +92 -0
  52. package/dist/tools.js +68 -0
  53. package/dist/transcribe.js +64 -0
  54. package/dist/transcriptionEvent.js +46 -0
  55. package/dist/workflow.d.ts +12 -10
  56. package/dist/workflow.js +117 -112
  57. package/package.json +6 -6
  58. package/dist/agentDescriptor-DuxvWGDi.js +0 -63
  59. package/dist/agentEvent-BuXA7sRt.js +0 -152
  60. package/dist/inferenceQueue-BmtEm3YI.js +0 -1061
  61. package/dist/provider-BnemgE4D.js +0 -409
@@ -1,11 +1,11 @@
1
1
  # Third-Party Notices — @voltro/ai
2
2
 
3
- This package depends on the open-source software listed below. Each is the
3
+ This package uses the open-source software listed below. Each is the
4
4
  property of its respective copyright holders and is used under the terms of
5
5
  its license. This file is provided for attribution; it grants no rights in
6
6
  @voltro/ai itself, which is proprietary (see LICENSE).
7
7
 
8
- Generated from the resolved runtime dependency closure (37 packages).
8
+ Generated from the resolved runtime dependency closure (31 packages).
9
9
 
10
10
  ---
11
11
 
@@ -75,118 +75,6 @@ License: Apache-2.0
75
75
 
76
76
  _(no bundled license text found in the package; see its npm page.)_
77
77
 
78
- ## @effect/cluster@0.60.2
79
-
80
- License: MIT
81
-
82
- ```
83
- MIT License
84
-
85
- Copyright (c) 2023-present The Contributors
86
-
87
- Permission is hereby granted, free of charge, to any person obtaining a copy
88
- of this software and associated documentation files (the "Software"), to deal
89
- in the Software without restriction, including without limitation the rights
90
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
91
- copies of the Software, and to permit persons to whom the Software is
92
- furnished to do so, subject to the following conditions:
93
-
94
- The above copyright notice and this permission notice shall be included in all
95
- copies or substantial portions of the Software.
96
-
97
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
98
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
99
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
100
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
101
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
102
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
103
- SOFTWARE.
104
- ```
105
-
106
- ## @effect/experimental@0.61.1
107
-
108
- License: MIT
109
-
110
- ```
111
- MIT License
112
-
113
- Copyright (c) 2023-present The Contributors
114
-
115
- Permission is hereby granted, free of charge, to any person obtaining a copy
116
- of this software and associated documentation files (the "Software"), to deal
117
- in the Software without restriction, including without limitation the rights
118
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
119
- copies of the Software, and to permit persons to whom the Software is
120
- furnished to do so, subject to the following conditions:
121
-
122
- The above copyright notice and this permission notice shall be included in all
123
- copies or substantial portions of the Software.
124
-
125
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
126
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
127
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
128
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
129
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
130
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
131
- SOFTWARE.
132
- ```
133
-
134
- ## @effect/sql@0.52.1
135
-
136
- License: MIT
137
-
138
- ```
139
- MIT License
140
-
141
- Copyright (c) 2023-present The Contributors
142
-
143
- Permission is hereby granted, free of charge, to any person obtaining a copy
144
- of this software and associated documentation files (the "Software"), to deal
145
- in the Software without restriction, including without limitation the rights
146
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
147
- copies of the Software, and to permit persons to whom the Software is
148
- furnished to do so, subject to the following conditions:
149
-
150
- The above copyright notice and this permission notice shall be included in all
151
- copies or substantial portions of the Software.
152
-
153
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
154
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
155
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
156
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
157
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
158
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
159
- SOFTWARE.
160
- ```
161
-
162
- ## @effect/workflow@0.19.1
163
-
164
- License: MIT
165
-
166
- ```
167
- MIT License
168
-
169
- Copyright (c) 2023-present The Contributors
170
-
171
- Permission is hereby granted, free of charge, to any person obtaining a copy
172
- of this software and associated documentation files (the "Software"), to deal
173
- in the Software without restriction, including without limitation the rights
174
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
175
- copies of the Software, and to permit persons to whom the Software is
176
- furnished to do so, subject to the following conditions:
177
-
178
- The above copyright notice and this permission notice shall be included in all
179
- copies or substantial portions of the Software.
180
-
181
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
182
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
183
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
184
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
185
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
186
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
187
- SOFTWARE.
188
- ```
189
-
190
78
  ## @ioredis/commands@1.10.0
191
79
 
192
80
  License: MIT
@@ -971,40 +859,6 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
971
859
  SOFTWARE.
972
860
  ```
973
861
 
974
- ## kubernetes-types@1.30.0
975
-
976
- License: Apache-2.0
977
-
978
- _(no bundled license text found in the package; see its npm page.)_
979
-
980
- ## layerr@3.0.0
981
-
982
- License: MIT
983
-
984
- ```
985
- MIT License
986
-
987
- Copyright (c) 2020 Perry Mitchell
988
-
989
- Permission is hereby granted, free of charge, to any person obtaining a copy
990
- of this software and associated documentation files (the "Software"), to deal
991
- in the Software without restriction, including without limitation the rights
992
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
993
- copies of the Software, and to permit persons to whom the Software is
994
- furnished to do so, subject to the following conditions:
995
-
996
- The above copyright notice and this permission notice shall be included in all
997
- copies or substantial portions of the Software.
998
-
999
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1000
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1001
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1002
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1003
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
1004
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1005
- SOFTWARE.
1006
- ```
1007
-
1008
862
  ## ms@2.1.3
1009
863
 
1010
864
  License: MIT
@@ -1354,14 +1208,14 @@ Apache License
1354
1208
  limitations under the License.
1355
1209
  ```
1356
1210
 
1357
- ## ulidx@2.4.1
1211
+ ## ulid@3.0.2
1358
1212
 
1359
1213
  License: MIT
1360
1214
 
1361
1215
  ```
1362
- MIT License
1216
+ The MIT License (MIT)
1363
1217
 
1364
- Copyright (c) 2021 Perry Mitchell
1218
+ Copyright (c) 2017 Alizain Feerasta
1365
1219
 
1366
1220
  Permission is hereby granted, free of charge, to any person obtaining a copy
1367
1221
  of this software and associated documentation files (the "Software"), to deal
package/dist/agent.d.ts CHANGED
@@ -2,6 +2,7 @@ import { ActionProcedureDescriptor } from '@voltro/protocol';
2
2
  import { Guards } from '@voltro/protocol';
3
3
  import { QueryProcedureDescriptor } from '@voltro/protocol';
4
4
  import { Schema } from 'effect';
5
+ import { YieldableError } from 'effect/Cause';
5
6
 
6
7
  declare const AGENT_DESCRIPTOR_BRAND: "@voltro/ai/AgentDescriptor";
7
8
 
@@ -30,7 +31,7 @@ export declare interface AgentAccessOptions {
30
31
  readonly openAccess?: string;
31
32
  }
32
33
 
33
- export declare interface AgentDescriptor<S extends Schema.Schema.Any = DefaultAgentInputSchema> {
34
+ export declare interface AgentDescriptor<S extends Schema.Top = DefaultAgentInputSchema> {
34
35
  readonly _brand: typeof AGENT_DESCRIPTOR_BRAND;
35
36
  /** Wire id → rpc tags `<name>.send` / `<name>.messages`. */
36
37
  readonly name: string;
@@ -43,25 +44,22 @@ export declare interface AgentDescriptor<S extends Schema.Schema.Any = DefaultAg
43
44
  }
44
45
 
45
46
  /** The decoded input an agent's executor sees, derived from its schema. */
46
- export declare type AgentInput<S extends Schema.Schema.Any> = Schema.Schema.Type<S>;
47
+ export declare type AgentInput<S extends Schema.Top> = Schema.Schema.Type<S>;
47
48
 
48
49
  /** The agent's input schema (default `{ prompt: string }`). */
49
- export declare const agentInputSchema: (desc: AnyAgentDescriptor) => Schema.Schema.Any;
50
+ export declare const agentInputSchema: (desc: AnyAgentDescriptor) => Schema.Top;
50
51
 
51
52
  export declare const agentMessageSchema: Schema.Struct<{
52
- id: typeof Schema.String;
53
- threadId: typeof Schema.String;
54
- role: typeof Schema.String;
55
- content: typeof Schema.String;
56
- streaming: typeof Schema.Boolean;
57
- order: typeof Schema.Number;
58
- stepOrder: typeof Schema.Number;
59
- parts: Schema.Array$<Schema.TypeLiteral<{
60
- type: typeof Schema.String;
61
- }, readonly [{
62
- readonly key: typeof Schema.String;
63
- readonly value: typeof Schema.Unknown;
64
- }]>>;
53
+ readonly id: Schema.String;
54
+ readonly threadId: Schema.String;
55
+ readonly role: Schema.String;
56
+ readonly content: Schema.String;
57
+ readonly streaming: Schema.Boolean;
58
+ readonly order: Schema.Number;
59
+ readonly stepOrder: Schema.Number;
60
+ readonly parts: Schema.$Array<Schema.StructWithRest<Schema.Struct<{
61
+ readonly type: Schema.String;
62
+ }>, readonly [Schema.$Record<Schema.String, Schema.Unknown>]>>;
65
63
  }>;
66
64
 
67
65
  /**
@@ -70,25 +68,22 @@ export declare const agentMessageSchema: Schema.Struct<{
70
68
  * so "what the server serves" and "what the client is typed for" can't drift.
71
69
  */
72
70
  export declare const agentRouteDescriptors: (desc: AnyAgentDescriptor) => {
73
- send: ActionProcedureDescriptor<`${string}.send`, Schema.Schema.Any, Schema.Struct<{
74
- text: typeof Schema.String;
71
+ send: ActionProcedureDescriptor<`${string}.send`, Schema.Top, Schema.Struct<{
72
+ readonly text: Schema.String;
75
73
  }>, typeof AgentThreadAccessDenied>;
76
74
  messages: QueryProcedureDescriptor<`${string}.messages`, Schema.Struct<{
77
- threadId: typeof Schema.String;
78
- }>, Schema.Array$<Schema.Struct<{
79
- id: typeof Schema.String;
80
- threadId: typeof Schema.String;
81
- role: typeof Schema.String;
82
- content: typeof Schema.String;
83
- streaming: typeof Schema.Boolean;
84
- order: typeof Schema.Number;
85
- stepOrder: typeof Schema.Number;
86
- parts: Schema.Array$<Schema.TypeLiteral<{
87
- type: typeof Schema.String;
88
- }, readonly [{
89
- readonly key: typeof Schema.String;
90
- readonly value: typeof Schema.Unknown;
91
- }]>>;
75
+ readonly threadId: Schema.String;
76
+ }>, Schema.$Array<Schema.Struct<{
77
+ readonly id: Schema.String;
78
+ readonly threadId: Schema.String;
79
+ readonly role: Schema.String;
80
+ readonly content: Schema.String;
81
+ readonly streaming: Schema.Boolean;
82
+ readonly order: Schema.Number;
83
+ readonly stepOrder: Schema.Number;
84
+ readonly parts: Schema.$Array<Schema.StructWithRest<Schema.Struct<{
85
+ readonly type: Schema.String;
86
+ }>, readonly [Schema.$Record<Schema.String, Schema.Unknown>]>>;
92
87
  }>>, typeof AgentThreadAccessDenied>;
93
88
  };
94
89
 
@@ -108,17 +103,15 @@ export declare class AgentThreadAccessDenied extends AgentThreadAccessDenied_bas
108
103
  get message(): string;
109
104
  }
110
105
 
111
- declare const AgentThreadAccessDenied_base: Schema.TaggedErrorClass<AgentThreadAccessDenied, "AgentThreadAccessDenied", {
112
- readonly _tag: Schema.tag<"AgentThreadAccessDenied">;
113
- } & {
114
- threadId: typeof Schema.String;
115
- }>;
106
+ declare const AgentThreadAccessDenied_base: Schema.Class<AgentThreadAccessDenied, Schema.TaggedStruct<"AgentThreadAccessDenied", {
107
+ readonly threadId: Schema.String;
108
+ }>, YieldableError>;
116
109
 
117
110
  /** A descriptor of any input shape — for the type-erased runtime helpers. */
118
- export declare type AnyAgentDescriptor = AgentDescriptor<Schema.Schema.Any>;
111
+ export declare type AnyAgentDescriptor = AgentDescriptor<Schema.Top>;
119
112
 
120
113
  declare const DEFAULT_INPUT: Schema.Struct<{
121
- prompt: typeof Schema.String;
114
+ readonly prompt: Schema.String;
122
115
  }>;
123
116
 
124
117
  /** Default input schema type when `input` is omitted (`{ prompt: string }`). */
@@ -138,7 +131,7 @@ export declare type DefaultAgentInputSchema = typeof DEFAULT_INPUT;
138
131
  * })
139
132
  * ```
140
133
  */
141
- export declare const defineAgent: <S extends Schema.Schema.Any = DefaultAgentInputSchema>(config: {
134
+ export declare const defineAgent: <S extends Schema.Top = DefaultAgentInputSchema>(config: {
142
135
  readonly name: string;
143
136
  readonly input?: S;
144
137
  } & AgentAccessOptions) => AgentDescriptor<S>;
package/dist/agent.js CHANGED
@@ -1,2 +1,64 @@
1
- import { a as e, i as t, n, o as r, r as i, t as a } from "./agentDescriptor-DuxvWGDi.js";
2
- export { a as AgentThreadAccessDenied, n as agentInputSchema, i as agentMessageSchema, t as agentRouteDescriptors, e as defineAgent, r as isAgentDescriptor };
1
+ import { AGENT_MESSAGES_TABLE as e } from "./agentConstants.js";
2
+ import { Schema as t } from "effect";
3
+ import { defineAction as n, defineQuery as r } from "@voltro/protocol";
4
+ //#region src/agentDescriptor.ts
5
+ var i = t.Struct({ prompt: t.String }), a = "@voltro/ai/AgentDescriptor", o = class extends t.TaggedError()("AgentThreadAccessDenied", { threadId: t.String }) {
6
+ get message() {
7
+ return `agent thread '${this.threadId}' belongs to another subject`;
8
+ }
9
+ }, s = (e) => {
10
+ if (e.guards !== void 0 && e.guards.length === 0) throw Error(`defineAgent("${e.name}"): \`guards: []\` is empty, so it enforces nothing —\n but it reads at the call site as if the agent were protected. Omit the field
11
+ and decide with \`openAccess\`, or list the scopes that may talk to it.`);
12
+ if (e.openAccess !== void 0 && e.guards !== void 0 && e.guards.length > 0) throw Error(`defineAgent("${e.name}"): \`openAccess\` and \`guards\` are two different access\n decisions, so declaring both says the agent is protected AND open. Keep the
13
+ guards if a caller must hold a scope; drop them if anyone may talk to it.`);
14
+ return {
15
+ _brand: a,
16
+ name: e.name,
17
+ ...e.input === void 0 ? {} : { input: e.input },
18
+ ...e.guards === void 0 ? {} : { guards: e.guards },
19
+ ...e.openAccess === void 0 ? {} : { openAccess: e.openAccess }
20
+ };
21
+ }, c = (e) => typeof e == "object" && !!e && e._brand === a, l = (e) => e.input ?? i, u = t.StructWithRest(t.Struct({ type: t.String }), [t.Record(t.String, t.Unknown)]), d = t.Struct({
22
+ id: t.String,
23
+ threadId: t.String,
24
+ role: t.String,
25
+ content: t.String,
26
+ streaming: t.Boolean,
27
+ order: t.Number,
28
+ stepOrder: t.Number,
29
+ parts: t.Array(u)
30
+ }), f = (e) => {
31
+ let n = l(e), r = t.Struct({
32
+ threadId: t.String,
33
+ order: t.Number
34
+ });
35
+ try {
36
+ return t.Struct({
37
+ ...n.fields,
38
+ ...r.fields
39
+ });
40
+ } catch {
41
+ return r;
42
+ }
43
+ }, p = (i) => {
44
+ let a = {};
45
+ return i.openAccess === void 0 ? i.guards !== void 0 && (a.guards = i.guards) : a.openAccess = i.openAccess, {
46
+ send: n({
47
+ name: `${i.name}.send`,
48
+ input: f(i),
49
+ output: t.Struct({ text: t.String }),
50
+ error: o,
51
+ ...a
52
+ }),
53
+ messages: r({
54
+ name: `${i.name}.messages`,
55
+ input: t.Struct({ threadId: t.String }),
56
+ output: t.Array(d),
57
+ source: e,
58
+ error: o,
59
+ ...a
60
+ })
61
+ };
62
+ };
63
+ //#endregion
64
+ export { o as AgentThreadAccessDenied, l as agentInputSchema, d as agentMessageSchema, p as agentRouteDescriptors, s as defineAgent, c as isAgentDescriptor };
@@ -0,0 +1,4 @@
1
+ //#region src/agentConstants.ts
2
+ var e = "_voltro_agent_threads", t = "_voltro_agent_messages";
3
+ //#endregion
4
+ export { t as AGENT_MESSAGES_TABLE, e as AGENT_THREADS_TABLE };
@@ -0,0 +1,51 @@
1
+ import { AgentThreadAccessDenied as e } from "./agent.js";
2
+ import { appendMessage as t, ensureThreadOwned as n, getMessages as r, getThread as i } from "./threads.js";
3
+ import { historyToModelMessages as a, runAssistant as o } from "./runAndPersist.js";
4
+ import { Effect as s } from "effect";
5
+ //#region src/agentExecutor.ts
6
+ var c = "@voltro/ai/AgentExecutor", l = (e, t) => ({
7
+ _brand: c,
8
+ descriptor: e,
9
+ config: t
10
+ }), u = (e) => typeof e == "object" && !!e && e._brand === c, d = (e, t) => {
11
+ let n = e.config.system;
12
+ if (n !== void 0) return typeof n == "function" ? n(t) : n;
13
+ }, f = (e, t) => {
14
+ let n = e.config.model;
15
+ return typeof n == "function" ? n(t) : n;
16
+ }, p = (e, i, c) => s.gen(function* () {
17
+ yield* n(i, {
18
+ threadId: c.threadId,
19
+ subjectId: c.subjectId ?? null,
20
+ tenantId: c.tenantId ?? null
21
+ });
22
+ let s = c.promptOf ? c.promptOf(c.input) : String(c.input?.prompt ?? ""), l = d(e, c.input), u = f(e, c.input);
23
+ yield* t(i, {
24
+ threadId: c.threadId,
25
+ role: "user",
26
+ content: s,
27
+ tenantId: c.tenantId ?? null,
28
+ order: c.order
29
+ });
30
+ let p = yield* r(i, c.threadId), m = a(p);
31
+ return yield* o(i, {
32
+ threadId: c.threadId,
33
+ tenantId: c.tenantId ?? null,
34
+ prompt: s,
35
+ ...m.length > 0 ? { messages: m } : {},
36
+ ...l === void 0 ? {} : { system: l },
37
+ ...e.config.tools === void 0 ? {} : { tools: e.config.tools },
38
+ ...u === void 0 ? {} : { provider: u },
39
+ ...e.config.maxSteps === void 0 ? {} : { maxSteps: e.config.maxSteps },
40
+ ...e.config.providerOptions === void 0 ? {} : { providerOptions: e.config.providerOptions },
41
+ ...c.toolContext === void 0 ? {} : { toolContext: c.toolContext },
42
+ order: c.order + 1,
43
+ ...c.throttleMs === void 0 ? {} : { throttleMs: c.throttleMs },
44
+ agent: e.descriptor.name
45
+ });
46
+ }), m = (t, n, a = null) => s.gen(function* () {
47
+ let o = yield* i(t, n);
48
+ return o !== null && o.subjectId !== null && o.subjectId !== a ? yield* s.fail(new e({ threadId: n })) : yield* r(t, n);
49
+ });
50
+ //#endregion
51
+ export { l as defineAgentExecutor, u as isAgentExecutor, m as loadAgentMessages, f as resolveAgentModel, d as resolveSystem, p as runAgentTurn };
package/dist/api.js ADDED
@@ -0,0 +1,199 @@
1
+ import { providerFromEnv as e, resolveModel as t } from "./provider.js";
2
+ import { buildSdkTools as n } from "./tools.js";
3
+ import { aiCallAttributes as r, withAiCallSpan as i } from "./observe.js";
4
+ import { validatedOutputSchema as a } from "./jsonOutputValidation.js";
5
+ import { AiCallEvidenceSchema as o, normalizeAiCallEvidence as s } from "./callEvidence.js";
6
+ import { captureStructuredEvidence as c } from "./structuredEvidence.js";
7
+ import { NoObjectGeneratedError as l, Output as u, generateObject as d, generateText as f, jsonSchema as p, stepCountIs as m } from "ai";
8
+ import { Context as h, Effect as g, Schema as _ } from "effect";
9
+ import { jsonSchemaOf as v } from "@voltro/protocol";
10
+ //#region src/api.ts
11
+ var y = class extends _.TaggedError()("AiError", {
12
+ reason: _.Literals(["generation", "decode"]),
13
+ message: _.String,
14
+ evidence: _.optional(o)
15
+ }) {}, b = (e, t = {}) => {
16
+ let n = String(e?.message ?? e), r = x(e), i = new y({
17
+ reason: "generation",
18
+ message: `${t.prefix === void 0 ? "" : `${t.prefix}: `}${n}${r.length > 0 ? ` (${r.join(" <- ")})` : ""}`,
19
+ ...t.evidence === void 0 ? {} : { evidence: t.evidence }
20
+ });
21
+ return Object.defineProperty(i, "cause", {
22
+ value: e,
23
+ enumerable: !1,
24
+ configurable: !0,
25
+ writable: !0
26
+ }), i;
27
+ }, x = (e) => {
28
+ let t = [], n = e;
29
+ for (let e = 0; e < 8 && typeof n == "object" && n; e++) {
30
+ let e = n;
31
+ typeof e.code == "string" && e.code.length > 0 && !t.includes(e.code) && t.push(e.code), n = typeof e.lastError == "object" && e.lastError !== null ? e.lastError : e.cause;
32
+ }
33
+ return t;
34
+ }, S = (e, t, n) => {
35
+ let r = [e, ...t ?? []], i = (e) => n(r[e]).pipe(g.catchTag("AiError", (t) => t.reason === "generation" && e + 1 < r.length ? i(e + 1) : g.fail(t)));
36
+ return i(0);
37
+ }, C = (a) => g.gen(function* () {
38
+ let o = a.messages === void 0 ? a.prompt === void 0 ? void 0 : { prompt: a.prompt } : { messages: [...a.messages] };
39
+ if (o === void 0 || a.prompt !== void 0 && a.messages !== void 0) return yield* g.fail(new y({
40
+ reason: "generation",
41
+ message: "generateText: supply exactly one of prompt or messages"
42
+ }));
43
+ let s = a.tools === void 0 ? void 0 : yield* g.context(), c = a.tools === void 0 || s === void 0 ? void 0 : n(a.tools, {
44
+ store: void 0,
45
+ ...a.toolContext,
46
+ ...a.abortSignal === void 0 ? {} : { abortSignal: a.abortSignal },
47
+ runtime: s
48
+ });
49
+ return yield* S(a.provider ?? e(), a.fallbacks, (e) => i(r(e, "generateText"), (e) => e.usage, g.tryPromise({
50
+ try: async () => {
51
+ let n = t(e), r = await f({
52
+ model: n,
53
+ ...o,
54
+ ...a.abortSignal === void 0 ? {} : { abortSignal: a.abortSignal },
55
+ ...c === void 0 ? {} : {
56
+ tools: c,
57
+ stopWhen: m(a.maxSteps ?? 8)
58
+ },
59
+ ...a.system === void 0 ? {} : { system: a.system },
60
+ ...a.maxTokens === void 0 ? {} : { maxOutputTokens: a.maxTokens },
61
+ ...a.temperature === void 0 ? {} : { temperature: a.temperature },
62
+ ...a.providerOptions === void 0 ? {} : { providerOptions: a.providerOptions }
63
+ }), i = c !== void 0 && r.totalUsage !== void 0 ? r.totalUsage : r.usage;
64
+ return {
65
+ text: r.text,
66
+ sources: r.sources,
67
+ usage: {
68
+ inputTokens: i.inputTokens,
69
+ outputTokens: i.outputTokens,
70
+ totalTokens: i.totalTokens
71
+ },
72
+ providerMetadata: r.providerMetadata
73
+ };
74
+ },
75
+ catch: (e) => b(e)
76
+ })));
77
+ }), w = (e, t) => g.gen(function* () {
78
+ let n = v(e);
79
+ if (n?.type !== "object") {
80
+ let e = n?.anyOf === void 0 ? `type:${JSON.stringify(n?.type ?? null)}` : "anyOf (e.g. Schema.Struct({}) or a union)";
81
+ return yield* g.fail(new y({
82
+ reason: "generation",
83
+ message: `${t}: the output schema must render as a top-level JSON object (type:"object"), but got ${e}. Use a Schema.Struct({ ... }) as the output schema — wrap arrays/scalars in a field (e.g. Schema.Struct({ items: Schema.Array(...) })).`
84
+ }));
85
+ }
86
+ return n;
87
+ }), T = (e, t) => w(e, t), E = (n) => S(n.provider ?? e(), n.fallbacks, (e) => i(r(e, "generateObject"), (e) => e.usage, g.gen(function* () {
88
+ let r = yield* g.try({
89
+ try: () => a(n.jsonSchema),
90
+ catch: () => new y({
91
+ reason: "decode",
92
+ message: "generateObjectJson: invalid or unsupported output JSON Schema; no provider call was made"
93
+ })
94
+ }), i = c(e.name, t(e)), o = i.model, u = yield* g.tryPromise({
95
+ try: () => d({
96
+ model: o,
97
+ schema: r,
98
+ prompt: n.prompt,
99
+ ...n.system === void 0 ? {} : { system: n.system },
100
+ ...n.maxTokens === void 0 ? {} : { maxOutputTokens: n.maxTokens },
101
+ ...n.temperature === void 0 ? {} : { temperature: n.temperature },
102
+ ...n.providerOptions === void 0 ? {} : { providerOptions: n.providerOptions }
103
+ }),
104
+ catch: (t) => l.isInstance(t) ? new y({
105
+ reason: "decode",
106
+ message: "model output failed JSON Schema validation",
107
+ evidence: i.evidence(t.usage)
108
+ }) : b(t, {
109
+ prefix: "structured provider call failed",
110
+ evidence: s(e.name, o.modelId, void 0)
111
+ })
112
+ });
113
+ return {
114
+ object: u.object,
115
+ evidence: s(e.name, o.modelId, u.usage, u.providerMetadata),
116
+ usage: {
117
+ inputTokens: u.usage.inputTokens,
118
+ outputTokens: u.usage.outputTokens,
119
+ totalTokens: u.usage.totalTokens
120
+ },
121
+ providerMetadata: u.providerMetadata
122
+ };
123
+ }))), D = (e) => g.gen(function* () {
124
+ let t = yield* E({
125
+ jsonSchema: yield* w(e.schema, "generateObject"),
126
+ prompt: e.prompt,
127
+ ...e.system === void 0 ? {} : { system: e.system },
128
+ ...e.provider === void 0 ? {} : { provider: e.provider },
129
+ ...e.fallbacks === void 0 ? {} : { fallbacks: e.fallbacks },
130
+ ...e.maxTokens === void 0 ? {} : { maxTokens: e.maxTokens },
131
+ ...e.temperature === void 0 ? {} : { temperature: e.temperature },
132
+ ...e.providerOptions === void 0 ? {} : { providerOptions: e.providerOptions }
133
+ }), n = yield* _.decodeUnknownEffect(e.schema)(t.object).pipe(g.mapError(() => new y({
134
+ reason: "decode",
135
+ message: "model output failed schema decode",
136
+ evidence: t.evidence
137
+ })));
138
+ return {
139
+ ...t,
140
+ object: n
141
+ };
142
+ }), O = (a) => g.gen(function* () {
143
+ let o = yield* g.context(), d = yield* w(a.schema, "generateObjectWithTools"), h = {
144
+ store: void 0,
145
+ ...a.toolContext,
146
+ ...a.abortSignal === void 0 ? {} : { abortSignal: a.abortSignal },
147
+ runtime: o
148
+ }, v = n(a.tools, h);
149
+ return yield* S(a.provider ?? e(), a.fallbacks, (e) => i(r(e, "generateObjectWithTools"), (e) => e.usage, g.gen(function* () {
150
+ let n = c(e.name, t(e)), r = n.model, i = yield* g.tryPromise({
151
+ try: () => f({
152
+ model: r,
153
+ prompt: a.prompt,
154
+ tools: v,
155
+ ...a.abortSignal === void 0 ? {} : { abortSignal: a.abortSignal },
156
+ stopWhen: m(a.maxSteps ?? 8),
157
+ output: u.object({ schema: p(d) }),
158
+ ...a.system === void 0 ? {} : { system: a.system },
159
+ ...a.maxTokens === void 0 ? {} : { maxOutputTokens: a.maxTokens },
160
+ ...a.temperature === void 0 ? {} : { temperature: a.temperature },
161
+ ...a.providerOptions === void 0 ? {} : { providerOptions: a.providerOptions }
162
+ }),
163
+ catch: (t) => l.isInstance(t) ? new y({
164
+ reason: "decode",
165
+ message: "model output failed structured decode",
166
+ evidence: n.evidence(t.usage)
167
+ }) : b(t, {
168
+ prefix: "structured provider call failed",
169
+ evidence: s(e.name, r.modelId, void 0)
170
+ })
171
+ }), o = i.totalUsage, h = n.evidence(o), x = yield* g.try({
172
+ try: () => i.output,
173
+ catch: () => new y({
174
+ reason: "decode",
175
+ message: "model output failed structured decode",
176
+ evidence: h
177
+ })
178
+ });
179
+ return {
180
+ object: yield* _.decodeUnknownEffect(a.schema)(x).pipe(g.mapError(() => new y({
181
+ reason: "decode",
182
+ message: "model output failed schema decode",
183
+ evidence: h
184
+ }))),
185
+ evidence: h,
186
+ usage: {
187
+ inputTokens: o.inputTokens,
188
+ outputTokens: o.outputTokens,
189
+ totalTokens: o.totalTokens
190
+ },
191
+ providerMetadata: i.providerMetadata
192
+ };
193
+ })));
194
+ }), k = class extends h.Service()("@voltro/AiService") {}, A = {
195
+ generateText: (e) => C(e),
196
+ generateObject: (e) => D(e)
197
+ };
198
+ //#endregion
199
+ export { y as AiError, k as AiService, b as aiGenerationError, A as defaultAiService, D as generateObject, E as generateObjectJson, O as generateObjectWithTools, C as generateText, T as outputJsonSchema };