@effect/ai-typesafe 0.0.1 → 4.0.0-rc.117
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/AGENTS.md +410 -0
- package/CLAUDE.md +410 -0
- package/LICENSE +21 -0
- package/README.md +3 -41
- package/ai-docs/README.md +44 -0
- package/ai-docs/package.json +36 -0
- package/ai-docs/src/01_effect/01_basics/01_effect-gen.ts +30 -0
- package/ai-docs/src/01_effect/01_basics/02_effect-fn.ts +52 -0
- package/ai-docs/src/01_effect/01_basics/10_creating-effects.ts +74 -0
- package/ai-docs/src/01_effect/01_basics/index.md +7 -0
- package/ai-docs/src/01_effect/02_schema/10_schema-basics.ts +43 -0
- package/ai-docs/src/01_effect/02_schema/index.md +7 -0
- package/ai-docs/src/01_effect/03_services/01_service.ts +45 -0
- package/ai-docs/src/01_effect/03_services/10_reference.ts +10 -0
- package/ai-docs/src/01_effect/03_services/20_layer-composition.ts +70 -0
- package/ai-docs/src/01_effect/03_services/20_layer-unwrap.ts +66 -0
- package/ai-docs/src/01_effect/03_services/index.md +5 -0
- package/ai-docs/src/01_effect/04_errors/01_error-handling.ts +30 -0
- package/ai-docs/src/01_effect/04_errors/10_catch-tags.ts +24 -0
- package/ai-docs/src/01_effect/04_errors/20_reason-errors.ts +64 -0
- package/ai-docs/src/01_effect/04_errors/index.md +1 -0
- package/ai-docs/src/01_effect/05_resources/10_acquire-release.ts +105 -0
- package/ai-docs/src/01_effect/05_resources/20_layer-side-effects.ts +31 -0
- package/ai-docs/src/01_effect/05_resources/30_layer-map.ts +86 -0
- package/ai-docs/src/01_effect/05_resources/index.md +3 -0
- package/ai-docs/src/01_effect/06_running/10_run-main.ts +30 -0
- package/ai-docs/src/01_effect/06_running/20_layer-launch.ts +27 -0
- package/ai-docs/src/01_effect/06_running/index.md +1 -0
- package/ai-docs/src/01_effect/07_pubsub/10_pubsub.ts +56 -0
- package/ai-docs/src/01_effect/07_pubsub/index.md +3 -0
- package/ai-docs/src/03_stream/10_creating-streams.ts +103 -0
- package/ai-docs/src/03_stream/20_consuming-streams.ts +137 -0
- package/ai-docs/src/03_stream/30_encoding.ts +163 -0
- package/ai-docs/src/03_stream/index.md +4 -0
- package/ai-docs/src/04_integration/10_managed-runtime.ts +129 -0
- package/ai-docs/src/04_integration/index.md +5 -0
- package/ai-docs/src/05_batching/10_request-resolver.ts +89 -0
- package/ai-docs/src/05_batching/index.md +3 -0
- package/ai-docs/src/06_schedule/10_schedules.ts +110 -0
- package/ai-docs/src/06_schedule/index.md +3 -0
- package/ai-docs/src/07_datetime/10_creating-and-formatting.ts +30 -0
- package/ai-docs/src/07_datetime/20_time-zones.ts +44 -0
- package/ai-docs/src/07_datetime/index.md +5 -0
- package/ai-docs/src/08_observability/10_logging.ts +66 -0
- package/ai-docs/src/08_observability/20_otlp-tracing.ts +95 -0
- package/ai-docs/src/08_observability/index.md +7 -0
- package/ai-docs/src/09_testing/10_effect-tests.ts +55 -0
- package/ai-docs/src/09_testing/20_layer-tests.ts +138 -0
- package/ai-docs/src/09_testing/index.md +1 -0
- package/ai-docs/src/10_predicate/01_basics.ts +14 -0
- package/ai-docs/src/10_predicate/index.md +9 -0
- package/ai-docs/src/40_sql/10_basics.ts +175 -0
- package/ai-docs/src/40_sql/index.md +6 -0
- package/ai-docs/src/50_http-client/10_basics.ts +102 -0
- package/ai-docs/src/50_http-client/index.md +3 -0
- package/ai-docs/src/51_http-server/10_basics.ts +118 -0
- package/ai-docs/src/51_http-server/20_testing.ts +100 -0
- package/ai-docs/src/51_http-server/fixtures/api/Api.ts +14 -0
- package/ai-docs/src/51_http-server/fixtures/api/Authorization.ts +36 -0
- package/ai-docs/src/51_http-server/fixtures/api/System.ts +10 -0
- package/ai-docs/src/51_http-server/fixtures/api/Users.ts +107 -0
- package/ai-docs/src/51_http-server/fixtures/domain/User.ts +21 -0
- package/ai-docs/src/51_http-server/fixtures/domain/UserErrors.ts +22 -0
- package/ai-docs/src/51_http-server/fixtures/server/Authorization.ts +37 -0
- package/ai-docs/src/51_http-server/fixtures/server/Users/http.ts +80 -0
- package/ai-docs/src/51_http-server/fixtures/server/Users.ts +183 -0
- package/ai-docs/src/51_http-server/index.md +3 -0
- package/ai-docs/src/60_child-process/10_working-with-child-processes.ts +117 -0
- package/ai-docs/src/60_child-process/index.md +3 -0
- package/ai-docs/src/70_cli/10_basics.ts +162 -0
- package/ai-docs/src/70_cli/index.md +5 -0
- package/ai-docs/src/71_ai/10_language-model.ts +156 -0
- package/ai-docs/src/71_ai/20_tools.ts +226 -0
- package/ai-docs/src/71_ai/30_chat.ts +158 -0
- package/ai-docs/src/71_ai/fixtures/domain/LaunchPlan.ts +9 -0
- package/ai-docs/src/71_ai/index.md +5 -0
- package/ai-docs/src/80_cluster/10_entities.ts +97 -0
- package/ai-docs/src/80_cluster/index.md +4 -0
- package/ai-docs/src/index.md +10 -0
- package/ai-docs/tsconfig.json +24 -0
- package/dist/TypeSafeClient.d.ts +71 -0
- package/dist/TypeSafeClient.d.ts.map +1 -0
- package/dist/TypeSafeClient.js +74 -0
- package/dist/TypeSafeClient.js.map +1 -0
- package/dist/TypeSafeConfig.d.ts +68 -0
- package/dist/TypeSafeConfig.d.ts.map +1 -0
- package/dist/TypeSafeConfig.js +36 -0
- package/dist/TypeSafeConfig.js.map +1 -0
- package/dist/TypeSafeDecisionModel.d.ts +44 -0
- package/dist/TypeSafeDecisionModel.d.ts.map +1 -0
- package/dist/TypeSafeDecisionModel.js +118 -0
- package/dist/TypeSafeDecisionModel.js.map +1 -0
- package/dist/TypeSafeSchema.d.ts +188 -0
- package/dist/TypeSafeSchema.d.ts.map +1 -0
- package/dist/TypeSafeSchema.js +130 -0
- package/dist/TypeSafeSchema.js.map +1 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +21 -0
- package/dist/index.js.map +1 -0
- package/dist/internal/errors.d.ts +7 -0
- package/dist/internal/errors.d.ts.map +1 -0
- package/dist/internal/errors.js +120 -0
- package/dist/internal/errors.js.map +1 -0
- package/package.json +58 -7
- package/src/TypeSafeClient.ts +143 -0
- package/src/TypeSafeConfig.ts +85 -0
- package/src/TypeSafeDecisionModel.ts +106 -0
- package/src/TypeSafeSchema.ts +134 -0
- package/src/index.ts +25 -0
- package/src/internal/errors.ts +113 -0
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @title Stateful chat sessions
|
|
3
|
+
*
|
|
4
|
+
* The AI `Chat` module maintains conversation history automatically. Build
|
|
5
|
+
* AI agents or chat assistants.
|
|
6
|
+
*/
|
|
7
|
+
import { OpenAiClient, OpenAiLanguageModel } from "@effect/ai-openai"
|
|
8
|
+
import { Config, Context, DateTime, Effect, Layer, Ref, Schema } from "effect"
|
|
9
|
+
import { AiError, Chat, Prompt, Tool, Toolkit } from "effect/unstable/ai"
|
|
10
|
+
import { FetchHttpClient } from "effect/unstable/http"
|
|
11
|
+
|
|
12
|
+
// ---------------------------------------------------------------------------
|
|
13
|
+
// Provider setup
|
|
14
|
+
// ---------------------------------------------------------------------------
|
|
15
|
+
|
|
16
|
+
const OpenAiClientLayer = OpenAiClient.layerConfig({
|
|
17
|
+
apiKey: Config.Redacted("OPENAI_API_KEY")
|
|
18
|
+
}).pipe(Layer.provide(FetchHttpClient.layer))
|
|
19
|
+
|
|
20
|
+
// ---------------------------------------------------------------------------
|
|
21
|
+
// Tools for the agentic loop
|
|
22
|
+
// ---------------------------------------------------------------------------
|
|
23
|
+
|
|
24
|
+
const Tools = Toolkit.make(Tool.make("getCurrentTime", {
|
|
25
|
+
description: "Get the current time in ISO format",
|
|
26
|
+
parameters: Schema.Struct({
|
|
27
|
+
id: Schema.String
|
|
28
|
+
}),
|
|
29
|
+
success: Schema.String
|
|
30
|
+
}))
|
|
31
|
+
|
|
32
|
+
const ToolsLayer = Tools.toLayer(Effect.gen(function*() {
|
|
33
|
+
yield* Effect.logDebug("Initializing tools...")
|
|
34
|
+
return Tools.of({
|
|
35
|
+
getCurrentTime: Effect.fn("Tools.getCurrentTime")(function*(_) {
|
|
36
|
+
const now = yield* DateTime.now
|
|
37
|
+
return DateTime.formatIso(now)
|
|
38
|
+
})
|
|
39
|
+
})
|
|
40
|
+
}))
|
|
41
|
+
|
|
42
|
+
// ---------------------------------------------------------------------------
|
|
43
|
+
// Service that wraps Chat for a domain use-case
|
|
44
|
+
// ---------------------------------------------------------------------------
|
|
45
|
+
|
|
46
|
+
export class AiAssistantError extends Schema.TaggedError<AiAssistantError>()("AiAssistantError", {
|
|
47
|
+
reason: AiError.AiErrorReason
|
|
48
|
+
}) {
|
|
49
|
+
static fromAiError(error: AiError.AiError) {
|
|
50
|
+
return new AiAssistantError({ reason: error.reason })
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export class AiAssistant extends Context.Service<AiAssistant, {
|
|
55
|
+
// Send a message while maintaining conversation history across turns.
|
|
56
|
+
chat(message: string): Effect.Effect<string, AiAssistantError>
|
|
57
|
+
// Ask a question and use an agentic loop with tool calls to answer it.
|
|
58
|
+
agent(question: string): Effect.Effect<string, AiAssistantError>
|
|
59
|
+
}>()("acme/AiAssistant") {
|
|
60
|
+
static readonly layer = Layer.effect(
|
|
61
|
+
AiAssistant,
|
|
62
|
+
Effect.gen(function*() {
|
|
63
|
+
// Choose the model you want to use for the chat sessions.
|
|
64
|
+
const modelLayer = yield* OpenAiLanguageModel.model("gpt-5.2").captureRequirements
|
|
65
|
+
|
|
66
|
+
// ---------------------------------------------------------------------------
|
|
67
|
+
// 1. Chat.empty — basic multi-turn conversation
|
|
68
|
+
// ---------------------------------------------------------------------------
|
|
69
|
+
|
|
70
|
+
// Create a new chat session with `Chat.empty` or `Chat.fromPrompt`. The
|
|
71
|
+
// session maintains conversation history automatically, so you can focus on
|
|
72
|
+
// the current turn without having to manage context.
|
|
73
|
+
const newSession = yield* Chat.fromPrompt(Prompt.empty.pipe(
|
|
74
|
+
Prompt.setSystem("You are a helpful assistant that answers questions.")
|
|
75
|
+
))
|
|
76
|
+
|
|
77
|
+
// You can also create a chat using a json export.
|
|
78
|
+
const json = yield* newSession.exportJson
|
|
79
|
+
const session = yield* Chat.fromJson(json)
|
|
80
|
+
|
|
81
|
+
const chat = Effect.fn("AiAssistant.chat")(
|
|
82
|
+
function*(message: string) {
|
|
83
|
+
// Create a new turn in the conversation by passing the user's message
|
|
84
|
+
// to `session.generateText`.
|
|
85
|
+
const response = yield* session.generateText({ prompt: message }).pipe(
|
|
86
|
+
// Provide the model layer to use.
|
|
87
|
+
// You could potentially use different models for different turns,
|
|
88
|
+
// or even switch models in the middle of a conversation.
|
|
89
|
+
Effect.provide(modelLayer)
|
|
90
|
+
)
|
|
91
|
+
|
|
92
|
+
// You can inspect the accumulated history at any point through the
|
|
93
|
+
// `history` ref on the chat instance.
|
|
94
|
+
const history = yield* Ref.get(session.history)
|
|
95
|
+
yield* Effect.logInfo(
|
|
96
|
+
`Conversation has ${history.content.length} messages`
|
|
97
|
+
)
|
|
98
|
+
|
|
99
|
+
return response.text
|
|
100
|
+
},
|
|
101
|
+
Effect.mapError((error) => AiAssistantError.fromAiError(error))
|
|
102
|
+
)
|
|
103
|
+
|
|
104
|
+
// ---------------------------------------------------------------------------
|
|
105
|
+
// 2. Create agentic loops with tools
|
|
106
|
+
// ---------------------------------------------------------------------------
|
|
107
|
+
|
|
108
|
+
const tools = yield* Tools
|
|
109
|
+
const agent = Effect.fn("AiAssistant.agent")(
|
|
110
|
+
function*(question: string) {
|
|
111
|
+
// We start the agent with a system prompt and the user question. The
|
|
112
|
+
// agent can then call tools in a loop until it decides to return a
|
|
113
|
+
// final answer.
|
|
114
|
+
const session = yield* Chat.fromPrompt([
|
|
115
|
+
{ role: "system", content: "You are an assistant that can use tools to answer questions." },
|
|
116
|
+
{ role: "user", content: question }
|
|
117
|
+
])
|
|
118
|
+
|
|
119
|
+
while (true) {
|
|
120
|
+
const response = yield* session.generateText({
|
|
121
|
+
prompt: [], // No additional prompt — the model has full access to the conversation history
|
|
122
|
+
toolkit: tools // Provide the tools to the model
|
|
123
|
+
}).pipe(
|
|
124
|
+
// Provide the model layer to use.
|
|
125
|
+
// You could potentially use different models for different turns,
|
|
126
|
+
// or even switch models in the middle of a conversation.
|
|
127
|
+
Effect.provide(modelLayer)
|
|
128
|
+
)
|
|
129
|
+
if (response.toolCalls.length > 0) {
|
|
130
|
+
// If the model called any tools, execute them and the Chat module
|
|
131
|
+
// will automatically add the tool results to the conversation
|
|
132
|
+
// history before the next turn.
|
|
133
|
+
continue
|
|
134
|
+
}
|
|
135
|
+
// If there are no tool calls, the model has returned a final answer
|
|
136
|
+
// and we can exit the loop.
|
|
137
|
+
return response.text
|
|
138
|
+
}
|
|
139
|
+
},
|
|
140
|
+
// Remap AI errors to our domain-specific error type, but die on
|
|
141
|
+
// unexpected errors.
|
|
142
|
+
Effect.catchTag(
|
|
143
|
+
"AiError",
|
|
144
|
+
(error) => Effect.fail(AiAssistantError.fromAiError(error)),
|
|
145
|
+
(e) => Effect.die(e)
|
|
146
|
+
)
|
|
147
|
+
)
|
|
148
|
+
|
|
149
|
+
return AiAssistant.of({
|
|
150
|
+
chat,
|
|
151
|
+
agent
|
|
152
|
+
})
|
|
153
|
+
})
|
|
154
|
+
).pipe(
|
|
155
|
+
// Provide the OpenAI client and tools layers to the AiAssistant service.
|
|
156
|
+
Layer.provide([OpenAiClientLayer, ToolsLayer])
|
|
157
|
+
)
|
|
158
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Schema } from "effect"
|
|
2
|
+
|
|
3
|
+
export class LaunchPlan extends Schema.Class<LaunchPlan>("LaunchPlan")({
|
|
4
|
+
audience: Schema.Literals(["developers", "operators", "platform teams"]),
|
|
5
|
+
channels: Schema.Array(Schema.String),
|
|
6
|
+
launchDate: Schema.String,
|
|
7
|
+
summary: Schema.String,
|
|
8
|
+
keyRisks: Schema.Array(Schema.String)
|
|
9
|
+
}) {}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @title Defining cluster entities
|
|
3
|
+
*
|
|
4
|
+
* Define distributed entity RPCs and run them in a cluster.
|
|
5
|
+
*/
|
|
6
|
+
import { NodeClusterSocket, NodeRuntime } from "@effect/platform-node"
|
|
7
|
+
import { Effect, Layer, Ref, Schema } from "effect"
|
|
8
|
+
import { ClusterSchema, Entity, TestRunner } from "effect/unstable/cluster"
|
|
9
|
+
import { Rpc } from "effect/unstable/rpc"
|
|
10
|
+
import type { SqlClient } from "effect/unstable/sql"
|
|
11
|
+
|
|
12
|
+
export const Increment = Rpc.make("Increment", {
|
|
13
|
+
payload: { amount: Schema.Int },
|
|
14
|
+
success: Schema.Int
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
export const GetCount = Rpc.make("GetCount", {
|
|
18
|
+
success: Schema.Int
|
|
19
|
+
})
|
|
20
|
+
// If you want GetCount messages to be persisted, you can annotate the RPC
|
|
21
|
+
// schema with `ClusterSchema.Persisted`.
|
|
22
|
+
//
|
|
23
|
+
// By default, messages are volatile and only sent over a network.
|
|
24
|
+
.annotate(ClusterSchema.Persisted, true)
|
|
25
|
+
|
|
26
|
+
// `Entity.make` takes an array of Rpc definitions
|
|
27
|
+
export const Counter = Entity.make("Counter", [Increment, GetCount])
|
|
28
|
+
|
|
29
|
+
// Entity handlers can keep in-memory state while the entity is active.
|
|
30
|
+
// `maxIdleTime` controls passivation: if the entity is idle long enough, it is
|
|
31
|
+
// stopped and later recreated on demand.
|
|
32
|
+
export const CounterEntityLayer = Counter.toLayer(
|
|
33
|
+
Effect.gen(function*() {
|
|
34
|
+
const count = yield* Ref.make(0)
|
|
35
|
+
|
|
36
|
+
return Counter.of({
|
|
37
|
+
Increment: ({ payload }) => Ref.updateAndGet(count, (current) => current + payload.amount),
|
|
38
|
+
GetCount: () =>
|
|
39
|
+
Ref.get(count).pipe(
|
|
40
|
+
// Add Rpc.fork to allow the GetCount handler to run concurrently with
|
|
41
|
+
// Increment handlers.
|
|
42
|
+
//
|
|
43
|
+
// This opts-out of the default behavior where all handlers for a
|
|
44
|
+
// given entity run sequentially.
|
|
45
|
+
Rpc.fork
|
|
46
|
+
)
|
|
47
|
+
})
|
|
48
|
+
}),
|
|
49
|
+
{ maxIdleTime: "5 minutes" }
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
// If you ever need to access an entity client, you can use the `client`
|
|
53
|
+
// property on the entity definition.
|
|
54
|
+
export const useCounter = Effect.gen(function*() {
|
|
55
|
+
const clientFor = yield* Counter.client
|
|
56
|
+
const counter = clientFor("counter-123")
|
|
57
|
+
|
|
58
|
+
const afterIncrement = yield* counter.Increment({ amount: 1 })
|
|
59
|
+
const currentCount = yield* counter.GetCount()
|
|
60
|
+
|
|
61
|
+
console.log(`Count after increment: ${afterIncrement}, current count: ${currentCount}`)
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
// `SingleRunner.layer` is useful for local development / tests where you still
|
|
65
|
+
// want the cluster entity runtime model.
|
|
66
|
+
declare const SqlClientLayer: Layer.Layer<SqlClient.SqlClient>
|
|
67
|
+
|
|
68
|
+
// Create the cluster layer using `NodeClusterSocket.layer`
|
|
69
|
+
const ClusterLayer = NodeClusterSocket.layer().pipe(
|
|
70
|
+
Layer.provide(SqlClientLayer)
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
// You can also use `TestRunner.layer` to run your entities in a single process,
|
|
74
|
+
// without any network communication and in-memory storage. This is useful for testing and
|
|
75
|
+
// development.
|
|
76
|
+
const ClusterLayerTest = TestRunner.layer
|
|
77
|
+
|
|
78
|
+
// Merge all your entity layers together and provide the cluster layer to run
|
|
79
|
+
// them in a cluster.
|
|
80
|
+
const EntitiesLayer = Layer.mergeAll(
|
|
81
|
+
CounterEntityLayer
|
|
82
|
+
)
|
|
83
|
+
|
|
84
|
+
const ProductionLayer = EntitiesLayer.pipe(
|
|
85
|
+
Layer.provide(ClusterLayer)
|
|
86
|
+
)
|
|
87
|
+
|
|
88
|
+
export const TestLayer = EntitiesLayer.pipe(
|
|
89
|
+
// For testing, we can use `Layer.provideMerge` to tests can access storage
|
|
90
|
+
// and other cluster services directly.
|
|
91
|
+
Layer.provideMerge(ClusterLayerTest)
|
|
92
|
+
)
|
|
93
|
+
|
|
94
|
+
// Finally, run your app with the entities layer.
|
|
95
|
+
Layer.launch(ProductionLayer).pipe(
|
|
96
|
+
NodeRuntime.runMain
|
|
97
|
+
)
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# Effect library documentation
|
|
2
|
+
|
|
3
|
+
This documentation covers the Effect library and its related packages.
|
|
4
|
+
|
|
5
|
+
When you need to find information about Effect, use this documentation and the
|
|
6
|
+
Effect source code available in your environment. Avoid unrelated copies of
|
|
7
|
+
Effect or external documentation, as they may be outdated or incorrect.
|
|
8
|
+
|
|
9
|
+
**Note**: The examples in this documentation contain comments for illustration
|
|
10
|
+
purposes. In practice, you would not include these comments in your code.
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json.schemastore.org/tsconfig",
|
|
3
|
+
"extends": "../tsconfig.base.json",
|
|
4
|
+
"include": ["src/**/*.ts", "src/**/*.tsx"],
|
|
5
|
+
"compilerOptions": {
|
|
6
|
+
"rootDir": ".",
|
|
7
|
+
"noEmit": true,
|
|
8
|
+
"declaration": false,
|
|
9
|
+
"declarationMap": false,
|
|
10
|
+
"composite": false,
|
|
11
|
+
"incremental": false,
|
|
12
|
+
"types": ["node"],
|
|
13
|
+
"plugins": [
|
|
14
|
+
{
|
|
15
|
+
"name": "@effect/language-service",
|
|
16
|
+
"namespaceImportPackages": [],
|
|
17
|
+
"diagnosticSeverity": {
|
|
18
|
+
"floatingEffect": "off",
|
|
19
|
+
"preferSchemaOverJson": "off"
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
]
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTTP client for TypeSafe System One and model discovery.
|
|
3
|
+
*
|
|
4
|
+
* @since 4.0.0
|
|
5
|
+
*/
|
|
6
|
+
import * as Config from "effect/Config";
|
|
7
|
+
import * as Context from "effect/Context";
|
|
8
|
+
import * as Effect from "effect/Effect";
|
|
9
|
+
import * as Layer from "effect/Layer";
|
|
10
|
+
import * as Redacted from "effect/Redacted";
|
|
11
|
+
import * as AiError from "effect/unstable/ai/AiError";
|
|
12
|
+
import * as HttpClient from "effect/unstable/http/HttpClient";
|
|
13
|
+
import * as TypeSafeSchema from "./TypeSafeSchema.ts";
|
|
14
|
+
/**
|
|
15
|
+
* Low-level TypeSafe operations.
|
|
16
|
+
*
|
|
17
|
+
* @category services
|
|
18
|
+
* @since 4.0.0
|
|
19
|
+
*/
|
|
20
|
+
export interface Service {
|
|
21
|
+
readonly client: HttpClient.HttpClient;
|
|
22
|
+
readonly systemOne: (request: typeof TypeSafeSchema.SystemOneRequest.Encoded) => Effect.Effect<typeof TypeSafeSchema.SystemOneResponse.Type, AiError.AiError>;
|
|
23
|
+
readonly listModels: () => Effect.Effect<typeof TypeSafeSchema.ListModelsResponse.Type, AiError.AiError>;
|
|
24
|
+
}
|
|
25
|
+
declare const TypeSafeClient_base: Context.ServiceClass<TypeSafeClient, "@effect/ai-typesafe/TypeSafeClient", Service>;
|
|
26
|
+
/**
|
|
27
|
+
* TypeSafe client service.
|
|
28
|
+
*
|
|
29
|
+
* @category services
|
|
30
|
+
* @since 4.0.0
|
|
31
|
+
*/
|
|
32
|
+
export declare class TypeSafeClient extends TypeSafeClient_base {
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Authentication, endpoint and HTTP customization options.
|
|
36
|
+
*
|
|
37
|
+
* @category options
|
|
38
|
+
* @since 4.0.0
|
|
39
|
+
*/
|
|
40
|
+
export interface Options {
|
|
41
|
+
readonly apiKey?: Redacted.Redacted<string> | undefined;
|
|
42
|
+
readonly apiUrl?: string | undefined;
|
|
43
|
+
readonly transformClient?: ((client: HttpClient.HttpClient) => HttpClient.HttpClient) | undefined;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Builds a client without automatic retries. Scoped transforms run after the constructor transform.
|
|
47
|
+
*
|
|
48
|
+
* @category constructors
|
|
49
|
+
* @since 4.0.0
|
|
50
|
+
*/
|
|
51
|
+
export declare const make: (options: Options) => Effect.Effect<Service, never, HttpClient.HttpClient>;
|
|
52
|
+
/**
|
|
53
|
+
* Provides a client from explicit options.
|
|
54
|
+
*
|
|
55
|
+
* @category layers
|
|
56
|
+
* @since 4.0.0
|
|
57
|
+
*/
|
|
58
|
+
export declare const layer: (options: Options) => Layer.Layer<TypeSafeClient, never, HttpClient.HttpClient>;
|
|
59
|
+
/**
|
|
60
|
+
* Provides a client from configuration, defaulting to TYPESAFE_API_KEY.
|
|
61
|
+
*
|
|
62
|
+
* @category layers
|
|
63
|
+
* @since 4.0.0
|
|
64
|
+
*/
|
|
65
|
+
export declare const layerConfig: (options?: {
|
|
66
|
+
readonly apiKey?: Config.Config<Redacted.Redacted<string> | undefined> | undefined;
|
|
67
|
+
readonly apiUrl?: Config.Config<string> | undefined;
|
|
68
|
+
readonly transformClient?: ((client: HttpClient.HttpClient) => HttpClient.HttpClient) | undefined;
|
|
69
|
+
}) => Layer.Layer<TypeSafeClient, Config.ConfigError, HttpClient.HttpClient>;
|
|
70
|
+
export {};
|
|
71
|
+
//# sourceMappingURL=TypeSafeClient.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TypeSafeClient.d.ts","sourceRoot":"","sources":["../src/TypeSafeClient.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAA;AACzC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAEvC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AACrC,OAAO,KAAK,QAAQ,MAAM,iBAAiB,CAAA;AAE3C,OAAO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CAAC,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,GAAG,SAAS,CAAC,GAAG,SAAS,CAAA;IAClF,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,SAAS,CAAA;IACnD,QAAQ,CAAC,eAAe,CAAC,EAAE,CAAC,CAAC,MAAM,EAAE,UAAU,CAAC,UAAU,KAAK,UAAU,CAAC,UAAU,CAAC,GAAG,SAAS,CAAA;CAClG,KAAG,KAAK,CAAC,KAAK,CAAC,cAAc,EAAE,MAAM,CAAC,WAAW,EAAE,UAAU,CAAC,UAAU,CAUtE,CAAA"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTTP client for TypeSafe System One and model discovery.
|
|
3
|
+
*
|
|
4
|
+
* @since 4.0.0
|
|
5
|
+
*/
|
|
6
|
+
import * as Config from "effect/Config";
|
|
7
|
+
import * as Context from "effect/Context";
|
|
8
|
+
import * as Effect from "effect/Effect";
|
|
9
|
+
import { flow, identity } from "effect/Function";
|
|
10
|
+
import * as Layer from "effect/Layer";
|
|
11
|
+
import * as Redacted from "effect/Redacted";
|
|
12
|
+
import * as AiError from "effect/unstable/ai/AiError";
|
|
13
|
+
import * as HttpClient from "effect/unstable/http/HttpClient";
|
|
14
|
+
import * as HttpClientRequest from "effect/unstable/http/HttpClientRequest";
|
|
15
|
+
import * as HttpClientResponse from "effect/unstable/http/HttpClientResponse";
|
|
16
|
+
import * as Errors from "./internal/errors.js";
|
|
17
|
+
import { TypeSafeConfig } from "./TypeSafeConfig.js";
|
|
18
|
+
import * as TypeSafeSchema from "./TypeSafeSchema.js";
|
|
19
|
+
/**
|
|
20
|
+
* TypeSafe client service.
|
|
21
|
+
*
|
|
22
|
+
* @category services
|
|
23
|
+
* @since 4.0.0
|
|
24
|
+
*/
|
|
25
|
+
export class TypeSafeClient extends /*#__PURE__*/Context.Service()("@effect/ai-typesafe/TypeSafeClient") {}
|
|
26
|
+
const decodeSystemOne = /*#__PURE__*/HttpClientResponse.schemaBodyJson(TypeSafeSchema.SystemOneResponse);
|
|
27
|
+
const decodeListModels = /*#__PURE__*/HttpClientResponse.schemaBodyJson(TypeSafeSchema.ListModelsResponse);
|
|
28
|
+
/**
|
|
29
|
+
* Builds a client without automatic retries. Scoped transforms run after the constructor transform.
|
|
30
|
+
*
|
|
31
|
+
* @category constructors
|
|
32
|
+
* @since 4.0.0
|
|
33
|
+
*/
|
|
34
|
+
export const make = /*#__PURE__*/Effect.fnUntraced(function* (options) {
|
|
35
|
+
const base = yield* HttpClient.HttpClient;
|
|
36
|
+
const client = base.pipe(HttpClient.mapRequest(flow(HttpClientRequest.prependUrl(options.apiUrl ?? "https://api.typesafe.ai/v1"), options.apiKey ? HttpClientRequest.bearerToken(Redacted.value(options.apiKey)) : identity, HttpClientRequest.acceptJson)), HttpClient.filterStatusOk, options.transformClient ?? identity);
|
|
37
|
+
const resolveClient = Effect.map(TypeSafeConfig.getOrUndefined, config => config?.transformClient?.(client) ?? client);
|
|
38
|
+
const execute = (request, decode, method) => resolveClient.pipe(Effect.flatMap(client => client.execute(request)), Effect.flatMap(decode), Effect.catchTags({
|
|
39
|
+
HttpClientError: error => Errors.mapHttpClientError(error, method),
|
|
40
|
+
SchemaError: error => Effect.fail(Errors.mapSchemaError(error, method))
|
|
41
|
+
}));
|
|
42
|
+
return TypeSafeClient.of({
|
|
43
|
+
client,
|
|
44
|
+
systemOne: payload => HttpClientRequest.bodyJson(HttpClientRequest.post("/systemone"), payload).pipe(Effect.mapError(error => AiError.make({
|
|
45
|
+
module: "TypeSafeClient",
|
|
46
|
+
method: "systemOne",
|
|
47
|
+
reason: new AiError.InvalidRequestError({
|
|
48
|
+
description: String(error)
|
|
49
|
+
})
|
|
50
|
+
})), Effect.flatMap(request => execute(request, decodeSystemOne, "systemOne"))),
|
|
51
|
+
listModels: () => execute(HttpClientRequest.get("/models"), decodeListModels, "listModels")
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
/**
|
|
55
|
+
* Provides a client from explicit options.
|
|
56
|
+
*
|
|
57
|
+
* @category layers
|
|
58
|
+
* @since 4.0.0
|
|
59
|
+
*/
|
|
60
|
+
export const layer = options => Layer.effect(TypeSafeClient, make(options));
|
|
61
|
+
/**
|
|
62
|
+
* Provides a client from configuration, defaulting to TYPESAFE_API_KEY.
|
|
63
|
+
*
|
|
64
|
+
* @category layers
|
|
65
|
+
* @since 4.0.0
|
|
66
|
+
*/
|
|
67
|
+
export const layerConfig = options => Layer.effect(TypeSafeClient, Effect.gen(function* () {
|
|
68
|
+
return yield* make({
|
|
69
|
+
apiKey: yield* options?.apiKey ?? Config.Redacted("TYPESAFE_API_KEY"),
|
|
70
|
+
apiUrl: options?.apiUrl ? yield* options.apiUrl : undefined,
|
|
71
|
+
transformClient: options?.transformClient
|
|
72
|
+
});
|
|
73
|
+
}));
|
|
74
|
+
//# sourceMappingURL=TypeSafeClient.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TypeSafeClient.js","names":[],"sources":["../src/TypeSafeClient.ts"],"sourcesContent":[null],"mappings":"AAAA;;;;;AAKA,OAAO,KAAK,MAAM,MAAM,eAAe;AACvC,OAAO,KAAK,OAAO,MAAM,gBAAgB;AACzC,OAAO,KAAK,MAAM,MAAM,eAAe;AACvC,SAAS,IAAI,EAAE,QAAQ,QAAQ,iBAAiB;AAChD,OAAO,KAAK,KAAK,MAAM,cAAc;AACrC,OAAO,KAAK,QAAQ,MAAM,iBAAiB;AAE3C,OAAO,KAAK,OAAO,MAAM,4BAA4B;AACrD,OAAO,KAAK,UAAU,MAAM,iCAAiC;AAE7D,OAAO,KAAK,iBAAiB,MAAM,wCAAwC;AAC3E,OAAO,KAAK,kBAAkB,MAAM,yCAAyC;AAC7E,OAAO,KAAK,MAAM,MAAM,sBAAsB;AAC9C,SAAS,cAAc,QAAQ,qBAAqB;AACpD,OAAO,KAAK,cAAc,MAAM,qBAAqB;AAgB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,CAAC,CAAC,CACH","ignoreList":[]}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Scoped HTTP client customization for TypeSafe requests.
|
|
3
|
+
*
|
|
4
|
+
* @since 4.0.0
|
|
5
|
+
*/
|
|
6
|
+
import * as Context from "effect/Context";
|
|
7
|
+
import * as Effect from "effect/Effect";
|
|
8
|
+
import type { HttpClient } from "effect/unstable/http/HttpClient";
|
|
9
|
+
declare const TypeSafeConfig_base: Context.ServiceClass<TypeSafeConfig, "@effect/ai-typesafe/TypeSafeConfig", TypeSafeConfig.Service>;
|
|
10
|
+
/**
|
|
11
|
+
* Scoped configuration read when executing TypeSafe requests.
|
|
12
|
+
*
|
|
13
|
+
* @see {@link withClientTransform} for scoping an HTTP client transformation
|
|
14
|
+
*
|
|
15
|
+
* @category services
|
|
16
|
+
* @since 4.0.0
|
|
17
|
+
*/
|
|
18
|
+
export declare class TypeSafeConfig extends TypeSafeConfig_base {
|
|
19
|
+
/**
|
|
20
|
+
* Reads the current configuration, if present.
|
|
21
|
+
*
|
|
22
|
+
* @since 4.0.0
|
|
23
|
+
*/
|
|
24
|
+
static readonly getOrUndefined: Effect.Effect<typeof TypeSafeConfig.Service | undefined>;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Types used by the `TypeSafeConfig` context service.
|
|
28
|
+
*
|
|
29
|
+
* @since 4.0.0
|
|
30
|
+
*/
|
|
31
|
+
export declare namespace TypeSafeConfig {
|
|
32
|
+
/**
|
|
33
|
+
* Per-request HTTP client configuration.
|
|
34
|
+
*
|
|
35
|
+
* @category services
|
|
36
|
+
* @since 4.0.0
|
|
37
|
+
*/
|
|
38
|
+
interface Service {
|
|
39
|
+
readonly transformClient?: ((client: HttpClient) => HttpClient) | undefined;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Transforms the TypeSafe HTTP client for requests made by the supplied effect.
|
|
44
|
+
* Replaces any existing scoped transform; compose them manually to apply both.
|
|
45
|
+
*
|
|
46
|
+
* @category configuration
|
|
47
|
+
* @since 4.0.0
|
|
48
|
+
*/
|
|
49
|
+
export declare const withClientTransform: {
|
|
50
|
+
/**
|
|
51
|
+
* Transforms the TypeSafe HTTP client for requests made by the supplied effect.
|
|
52
|
+
* Replaces any existing scoped transform; compose them manually to apply both.
|
|
53
|
+
*
|
|
54
|
+
* @category configuration
|
|
55
|
+
* @since 4.0.0
|
|
56
|
+
*/
|
|
57
|
+
(transform: (client: HttpClient) => HttpClient): <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>;
|
|
58
|
+
/**
|
|
59
|
+
* Transforms the TypeSafe HTTP client for requests made by the supplied effect.
|
|
60
|
+
* Replaces any existing scoped transform; compose them manually to apply both.
|
|
61
|
+
*
|
|
62
|
+
* @category configuration
|
|
63
|
+
* @since 4.0.0
|
|
64
|
+
*/
|
|
65
|
+
<A, E, R>(self: Effect.Effect<A, E, R>, transform: (client: HttpClient) => HttpClient): Effect.Effect<A, E, R>;
|
|
66
|
+
};
|
|
67
|
+
export {};
|
|
68
|
+
//# sourceMappingURL=TypeSafeConfig.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TypeSafeConfig.d.ts","sourceRoot":"","sources":["../src/TypeSafeConfig.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAA;AACzC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAEvC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAA;;AAEjE;;;;;;;GAOG;AACH,qBAAa,cAAe,SAAQ,mBAGK;IACvC;;;;OAIG;IACH,MAAM,CAAC,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC,MAAM,CAAC,OAAO,cAAc,CAAC,OAAO,GAAG,SAAS,CAAC,CAGvF;CACF;AAED;;;;GAIG;AACH,MAAM,CAAC,OAAO,WAAW,cAAc,CAAC;IACtC;;;;;OAKG;IACH,UAAiB,OAAO;QACtB,QAAQ,CAAC,eAAe,CAAC,EAAE,CAAC,CAAC,MAAM,EAAE,UAAU,KAAK,UAAU,CAAC,GAAG,SAAS,CAAA;KAC5E;CACF;AAED;;;;;;GAMG;AACH,eAAO,MAAM,mBAAmB,EAAE;IAChC;;;;;;OAMG;IACH,CAAC,SAAS,EAAE,CAAC,MAAM,EAAE,UAAU,KAAK,UAAU,GAAG,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,KAAK,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAA;IAClH;;;;;;OAMG;IACH,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EACN,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAC5B,SAAS,EAAE,CAAC,MAAM,EAAE,UAAU,KAAK,UAAU,GAC5C,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAA;CAQvB,CAAA"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Scoped HTTP client customization for TypeSafe requests.
|
|
3
|
+
*
|
|
4
|
+
* @since 4.0.0
|
|
5
|
+
*/
|
|
6
|
+
import * as Context from "effect/Context";
|
|
7
|
+
import * as Effect from "effect/Effect";
|
|
8
|
+
import { dual } from "effect/Function";
|
|
9
|
+
/**
|
|
10
|
+
* Scoped configuration read when executing TypeSafe requests.
|
|
11
|
+
*
|
|
12
|
+
* @see {@link withClientTransform} for scoping an HTTP client transformation
|
|
13
|
+
*
|
|
14
|
+
* @category services
|
|
15
|
+
* @since 4.0.0
|
|
16
|
+
*/
|
|
17
|
+
export class TypeSafeConfig extends /*#__PURE__*/Context.Service()("@effect/ai-typesafe/TypeSafeConfig") {
|
|
18
|
+
/**
|
|
19
|
+
* Reads the current configuration, if present.
|
|
20
|
+
*
|
|
21
|
+
* @since 4.0.0
|
|
22
|
+
*/
|
|
23
|
+
static getOrUndefined = /*#__PURE__*/Effect.map(/*#__PURE__*/Effect.context(), /*#__PURE__*/Context.getOrUndefined(TypeSafeConfig));
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Transforms the TypeSafe HTTP client for requests made by the supplied effect.
|
|
27
|
+
* Replaces any existing scoped transform; compose them manually to apply both.
|
|
28
|
+
*
|
|
29
|
+
* @category configuration
|
|
30
|
+
* @since 4.0.0
|
|
31
|
+
*/
|
|
32
|
+
export const withClientTransform = /*#__PURE__*/dual(2, (self, transformClient) => Effect.flatMap(TypeSafeConfig.getOrUndefined, config => Effect.provideService(self, TypeSafeConfig, {
|
|
33
|
+
...config,
|
|
34
|
+
transformClient
|
|
35
|
+
})));
|
|
36
|
+
//# sourceMappingURL=TypeSafeConfig.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TypeSafeConfig.js","names":[],"sources":["../src/TypeSafeConfig.ts"],"sourcesContent":[null],"mappings":"AAAA;;;;;AAKA,OAAO,KAAK,OAAO,MAAM,gBAAgB;AACzC,OAAO,KAAK,MAAM,MAAM,eAAe;AACvC,SAAS,IAAI,QAAQ,iBAAiB;AAGtC;;;;;;;;AAQA,OAAM,MAAO,cAAe,sBAAQ,OAAO,CAAC,OAAO,EAGhD,CAAC,oCAAoC,CAAC;EACvC;;;;;EAKA,OAAgB,cAAc,gBAA6D,MAAM,CAAC,GAAG,cACnG,MAAM,CAAC,OAAO,EAAS,eACvB,OAAO,CAAC,cAAc,CAAC,cAAc,CAAC,CACvC;;AAoBH;;;;;;;AAOA,OAAO,MAAM,mBAAmB,gBAoB5B,IAAI,CAAC,CAAC,EAAE,CACV,IAA4B,EAC5B,eAAmD,KAEnD,MAAM,CAAC,OAAO,CACZ,cAAc,CAAC,cAAc,EAC5B,MAAM,IAAK,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,cAAc,EAAE;EAAE,GAAG,MAAM;EAAE;AAAe,CAAE,CAAC,CACxF,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TypeSafe's System One implementation of DecisionModel.
|
|
3
|
+
*
|
|
4
|
+
* @since 4.0.0
|
|
5
|
+
*/
|
|
6
|
+
import * as Effect from "effect/Effect";
|
|
7
|
+
import * as Layer from "effect/Layer";
|
|
8
|
+
import * as DecisionModel from "effect/unstable/ai/DecisionModel";
|
|
9
|
+
import * as AiModel from "effect/unstable/ai/Model";
|
|
10
|
+
import { TypeSafeClient } from "./TypeSafeClient.ts";
|
|
11
|
+
/**
|
|
12
|
+
* Known TypeSafe model identifiers. Constructors also accept custom identifiers.
|
|
13
|
+
*
|
|
14
|
+
* @category models
|
|
15
|
+
* @since 4.0.0
|
|
16
|
+
*/
|
|
17
|
+
export type Model = "jev-latest" | "jev-preview" | "jev-1.13.0";
|
|
18
|
+
/**
|
|
19
|
+
* Creates a decision model with TypeSafe provider metadata.
|
|
20
|
+
*
|
|
21
|
+
* @category constructors
|
|
22
|
+
* @since 4.0.0
|
|
23
|
+
*/
|
|
24
|
+
export declare const model: (model: Model | (string & {})) => AiModel.Model<"typesafe", DecisionModel.DecisionModel, TypeSafeClient>;
|
|
25
|
+
/**
|
|
26
|
+
* Builds a decision service. Provider values are preserved without normalization;
|
|
27
|
+
* DecisionModel validates distributions and derives rating labels.
|
|
28
|
+
*
|
|
29
|
+
* @category constructors
|
|
30
|
+
* @since 4.0.0
|
|
31
|
+
*/
|
|
32
|
+
export declare const make: (options: {
|
|
33
|
+
readonly model: Model | (string & {});
|
|
34
|
+
}) => Effect.Effect<DecisionModel.DecisionModel, never, TypeSafeClient>;
|
|
35
|
+
/**
|
|
36
|
+
* Provides DecisionModel using an existing TypeSafeClient.
|
|
37
|
+
*
|
|
38
|
+
* @category layers
|
|
39
|
+
* @since 4.0.0
|
|
40
|
+
*/
|
|
41
|
+
export declare const layer: (options: {
|
|
42
|
+
readonly model: Model | (string & {});
|
|
43
|
+
}) => Layer.Layer<DecisionModel.DecisionModel, never, TypeSafeClient>;
|
|
44
|
+
//# sourceMappingURL=TypeSafeDecisionModel.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TypeSafeDecisionModel.d.ts","sourceRoot":"","sources":["../src/TypeSafeDecisionModel.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AACrC,OAAO,KAAK,aAAa,MAAM,kCAAkC,CAAA;AACjE,OAAO,KAAK,OAAO,MAAM,0BAA0B,CAAA;AACnD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;AAGpD;;;;;GAKG;AACH,MAAM,MAAM,KAAK,GAAG,YAAY,GAAG,aAAa,GAAG,YAAY,CAAA;AAE/D;;;;;GAKG;AACH,eAAO,MAAM,KAAK,UACT,KAAK,GAAG,CAAC,MAAM,GAAG,EAAE,CAAC,KAC3B,OAAO,CAAC,KAAK,CAAC,UAAU,EAAE,aAAa,CAAC,aAAa,EAAE,cAAc,CACrB,CAAA;AAEnD;;;;;;GAMG;AACH,eAAO,MAAM,IAAI;oBAEc,KAAK,GAAG,CAAC,MAAM,GAAG,EAAE,CAAC;uEAsDnD,CAAA;AAED;;;;;GAKG;AACH,eAAO,MAAM,KAAK,YACP;IAAE,QAAQ,CAAC,KAAK,EAAE,KAAK,GAAG,CAAC,MAAM,GAAG,EAAE,CAAC,CAAA;CAAE,KACjD,KAAK,CAAC,KAAK,CAAC,aAAa,CAAC,aAAa,EAAE,KAAK,EAAE,cAAc,CACP,CAAA"}
|