@orpc/ai-sdk 0.0.0-next.d92c7aa
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/LICENSE +21 -0
- package/README.md +81 -0
- package/dist/index.d.mts +114 -0
- package/dist/index.d.ts +114 -0
- package/dist/index.mjs +32 -0
- package/package.json +44 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 oRPC
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
<image align="center" src="https://orpc.unnoq.com/logo.webp" width=280 alt="oRPC logo" />
|
|
3
|
+
</div>
|
|
4
|
+
|
|
5
|
+
<h1></h1>
|
|
6
|
+
|
|
7
|
+
<div align="center">
|
|
8
|
+
<a href="https://codecov.io/gh/unnoq/orpc">
|
|
9
|
+
<img alt="codecov" src="https://codecov.io/gh/unnoq/orpc/branch/main/graph/badge.svg">
|
|
10
|
+
</a>
|
|
11
|
+
<a href="https://www.npmjs.com/package/@orpc/ai-sdk">
|
|
12
|
+
<img alt="weekly downloads" src="https://img.shields.io/npm/dw/%40orpc%2Fai-sdk?logo=npm" />
|
|
13
|
+
</a>
|
|
14
|
+
<a href="https://github.com/unnoq/orpc/blob/main/LICENSE">
|
|
15
|
+
<img alt="MIT License" src="https://img.shields.io/github/license/unnoq/orpc?logo=open-source-initiative" />
|
|
16
|
+
</a>
|
|
17
|
+
<a href="https://discord.gg/TXEbwRBvQn">
|
|
18
|
+
<img alt="Discord" src="https://img.shields.io/discord/1308966753044398161?color=7389D8&label&logo=discord&logoColor=ffffff" />
|
|
19
|
+
</a>
|
|
20
|
+
<a href="https://deepwiki.com/unnoq/orpc">
|
|
21
|
+
<img src="https://deepwiki.com/badge.svg" alt="Ask DeepWiki">
|
|
22
|
+
</a>
|
|
23
|
+
</div>
|
|
24
|
+
|
|
25
|
+
<h3 align="center">Typesafe APIs Made Simple 🪄</h3>
|
|
26
|
+
|
|
27
|
+
**oRPC is a powerful combination of RPC and OpenAPI**, makes it easy to build APIs that are end-to-end type-safe and adhere to OpenAPI standards
|
|
28
|
+
|
|
29
|
+
---
|
|
30
|
+
|
|
31
|
+
## Highlights
|
|
32
|
+
|
|
33
|
+
- **🔗 End-to-End Type Safety**: Ensure type-safe inputs, outputs, and errors from client to server.
|
|
34
|
+
- **📘 First-Class OpenAPI**: Built-in support that fully adheres to the OpenAPI standard.
|
|
35
|
+
- **📝 Contract-First Development**: Optionally define your API contract before implementation.
|
|
36
|
+
- **🔍 First-Class OpenTelemetry**: Seamlessly integrate with OpenTelemetry for observability.
|
|
37
|
+
- **⚙️ Framework Integrations**: Seamlessly integrate with TanStack Query (React, Vue, Solid, Svelte, Angular), SWR, Pinia Colada, and more.
|
|
38
|
+
- **🚀 Server Actions**: Fully compatible with React Server Actions on Next.js, TanStack Start, and other platforms.
|
|
39
|
+
- **🔠 Standard Schema Support**: Works out of the box with Zod, Valibot, ArkType, and other schema validators.
|
|
40
|
+
- **🗃️ Native Types**: Supports native types like Date, File, Blob, BigInt, URL, and more.
|
|
41
|
+
- **⏱️ Lazy Router**: Enhance cold start times with our lazy routing feature.
|
|
42
|
+
- **📡 SSE & Streaming**: Enjoy full type-safe support for SSE and streaming.
|
|
43
|
+
- **🌍 Multi-Runtime Support**: Fast and lightweight on Cloudflare, Deno, Bun, Node.js, and beyond.
|
|
44
|
+
- **🔌 Extendability**: Easily extend functionality with plugins, middleware, and interceptors.
|
|
45
|
+
|
|
46
|
+
## Documentation
|
|
47
|
+
|
|
48
|
+
You can find the full documentation [here](https://orpc.unnoq.com).
|
|
49
|
+
|
|
50
|
+
## Packages
|
|
51
|
+
|
|
52
|
+
- [@orpc/contract](https://www.npmjs.com/package/@orpc/contract): Build your API contract.
|
|
53
|
+
- [@orpc/server](https://www.npmjs.com/package/@orpc/server): Build your API or implement API contract.
|
|
54
|
+
- [@orpc/client](https://www.npmjs.com/package/@orpc/client): Consume your API on the client with type-safety.
|
|
55
|
+
- [@orpc/openapi](https://www.npmjs.com/package/@orpc/openapi): Generate OpenAPI specs and handle OpenAPI requests.
|
|
56
|
+
- [@orpc/otel](https://www.npmjs.com/package/@orpc/otel): [OpenTelemetry](https://opentelemetry.io/) integration for observability.
|
|
57
|
+
- [@orpc/nest](https://www.npmjs.com/package/@orpc/nest): Deeply integrate oRPC with [NestJS](https://nestjs.com/).
|
|
58
|
+
- [@orpc/react](https://www.npmjs.com/package/@orpc/react): Utilities for integrating oRPC with React and React Server Actions.
|
|
59
|
+
- [@orpc/tanstack-query](https://www.npmjs.com/package/@orpc/tanstack-query): [TanStack Query](https://tanstack.com/query/latest) integration.
|
|
60
|
+
- [@orpc/experimental-react-swr](https://www.npmjs.com/package/@orpc/experimental-react-swr): [SWR](https://swr.vercel.app/) integration.
|
|
61
|
+
- [@orpc/vue-colada](https://www.npmjs.com/package/@orpc/vue-colada): Integration with [Pinia Colada](https://pinia-colada.esm.dev/).
|
|
62
|
+
- [@orpc/hey-api](https://www.npmjs.com/package/@orpc/hey-api): [Hey API](https://heyapi.dev/) integration.
|
|
63
|
+
- [@orpc/zod](https://www.npmjs.com/package/@orpc/zod): More schemas that [Zod](https://zod.dev/) doesn't support yet.
|
|
64
|
+
- [@orpc/valibot](https://www.npmjs.com/package/@orpc/valibot): OpenAPI spec generation from [Valibot](https://valibot.dev/).
|
|
65
|
+
- [@orpc/arktype](https://www.npmjs.com/package/@orpc/arktype): OpenAPI spec generation from [ArkType](https://arktype.io/).
|
|
66
|
+
|
|
67
|
+
## `@orpc/ai-sdk`
|
|
68
|
+
|
|
69
|
+
The [AI SDK](https://ai-sdk.dev/) integration for oRPC.
|
|
70
|
+
|
|
71
|
+
## Sponsors
|
|
72
|
+
|
|
73
|
+
<p align="center">
|
|
74
|
+
<a href="https://cdn.jsdelivr.net/gh/unnoq/unnoq/sponsors.svg">
|
|
75
|
+
<img src='https://cdn.jsdelivr.net/gh/unnoq/unnoq/sponsors.svg'/>
|
|
76
|
+
</a>
|
|
77
|
+
</p>
|
|
78
|
+
|
|
79
|
+
## License
|
|
80
|
+
|
|
81
|
+
Distributed under the MIT License. See [LICENSE](https://github.com/unnoq/orpc/blob/main/LICENSE) for more information.
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { ClientOptions } from '@orpc/client';
|
|
2
|
+
import { Meta, ContractProcedure, Schema, AnySchema, ErrorMap, InferSchemaOutput, InferSchemaInput } from '@orpc/contract';
|
|
3
|
+
import { Context, Procedure, CreateProcedureClientOptions } from '@orpc/server';
|
|
4
|
+
import { MaybeOptionalOptions, SetOptional } from '@orpc/shared';
|
|
5
|
+
export { AsyncIteratorClass, asyncIteratorToStream as eventIteratorToStream, asyncIteratorToUnproxiedDataStream as eventIteratorToUnproxiedDataStream, streamToAsyncIteratorClass as streamToEventIterator } from '@orpc/shared';
|
|
6
|
+
import { Tool } from 'ai';
|
|
7
|
+
|
|
8
|
+
declare const AI_SDK_TOOL_META_SYMBOL: unique symbol;
|
|
9
|
+
interface AiSdkToolMeta extends Meta {
|
|
10
|
+
[AI_SDK_TOOL_META_SYMBOL]?: Partial<Tool<unknown, unknown>>;
|
|
11
|
+
}
|
|
12
|
+
declare class CreateToolError extends Error {
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Implements [procedure contract](https://orpc.unnoq.com/docs/contract-first/define-contract#procedure-contract)
|
|
16
|
+
* as an [AI SDK Tool](https://ai-sdk.dev/docs/foundations/tools) by leveraging existing contract definitions.
|
|
17
|
+
*
|
|
18
|
+
* @warning Requires a contract with an `input` schema defined.
|
|
19
|
+
* @info Standard [procedures](https://orpc.unnoq.com/docs/procedure) are also compatible with [procedure contracts](https://orpc.unnoq.com/docs/contract-first/define-contract).
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```ts
|
|
23
|
+
* import { oc } from '@orpc/contract'
|
|
24
|
+
* import {
|
|
25
|
+
* AI_SDK_TOOL_META_SYMBOL,
|
|
26
|
+
* AiSdkToolMeta,
|
|
27
|
+
* implementTool,
|
|
28
|
+
* } from '@orpc/ai-sdk'
|
|
29
|
+
* import { z } from 'zod'
|
|
30
|
+
*
|
|
31
|
+
* interface ORPCMeta extends AiSdkToolMeta {} // optional extend meta
|
|
32
|
+
* const base = oc.$meta<ORPCMeta>({})
|
|
33
|
+
*
|
|
34
|
+
* const getWeatherContract = base
|
|
35
|
+
* .meta({
|
|
36
|
+
* [AI_SDK_TOOL_META_SYMBOL]: {
|
|
37
|
+
* name: 'custom-tool-name', // AI SDK tool name
|
|
38
|
+
* },
|
|
39
|
+
* })
|
|
40
|
+
* .route({
|
|
41
|
+
* summary: 'Get the weather in a location', // AI SDK tool description
|
|
42
|
+
* })
|
|
43
|
+
* .input(
|
|
44
|
+
* z.object({
|
|
45
|
+
* location: z.string().describe('The location to get the weather for'),
|
|
46
|
+
* }),
|
|
47
|
+
* )
|
|
48
|
+
* .output(
|
|
49
|
+
* z.object({
|
|
50
|
+
* location: z.string().describe('The location the weather is for'),
|
|
51
|
+
* temperature: z.number().describe('The temperature in Celsius'),
|
|
52
|
+
* }),
|
|
53
|
+
* )
|
|
54
|
+
*
|
|
55
|
+
* const getWeatherTool = implementTool(getWeatherContract, {
|
|
56
|
+
* execute: async ({ location }) => ({
|
|
57
|
+
* location,
|
|
58
|
+
* temperature: 72 + Math.floor(Math.random() * 21) - 10,
|
|
59
|
+
* }),
|
|
60
|
+
* })
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
declare function implementTool<TOutInput, TInOutput>(contract: ContractProcedure<Schema<any, TOutInput>, Schema<TInOutput, any>, any, AiSdkToolMeta>, ...rest: MaybeOptionalOptions<SetOptional<Tool<TOutInput, TInOutput>, 'inputSchema' | 'outputSchema'>>): Tool<TOutInput, TInOutput>;
|
|
64
|
+
/**
|
|
65
|
+
* Converts a [procedure](https://orpc.unnoq.com/docs/procedure) into an [AI SDK Tool](https://ai-sdk.dev/docs/foundations/tools)
|
|
66
|
+
* by leveraging existing procedure definitions.
|
|
67
|
+
*
|
|
68
|
+
* @warning Requires a contract with an `input` schema defined.
|
|
69
|
+
* @warning Validation occurs twice (once for the tool, once for the procedure call).
|
|
70
|
+
* So validation may fail if inputSchema or outputSchema transform the data into different shapes.
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* ```ts
|
|
74
|
+
* import { os } from '@orpc/server'
|
|
75
|
+
* import {
|
|
76
|
+
* AI_SDK_TOOL_META_SYMBOL,
|
|
77
|
+
* AiSdkToolMeta,
|
|
78
|
+
* createTool
|
|
79
|
+
* } from '@orpc/ai-sdk'
|
|
80
|
+
* import { z } from 'zod'
|
|
81
|
+
*
|
|
82
|
+
* interface ORPCMeta extends AiSdkToolMeta {} // optional extend meta
|
|
83
|
+
* const base = os.$meta<ORPCMeta>({})
|
|
84
|
+
*
|
|
85
|
+
* const getWeatherProcedure = base
|
|
86
|
+
* .meta({
|
|
87
|
+
* [AI_SDK_TOOL_META_SYMBOL]: {
|
|
88
|
+
* name: 'custom-tool-name', // AI SDK tool name
|
|
89
|
+
* },
|
|
90
|
+
* })
|
|
91
|
+
* .route({
|
|
92
|
+
* summary: 'Get the weather in a location',
|
|
93
|
+
* })
|
|
94
|
+
* .input(z.object({
|
|
95
|
+
* location: z.string().describe('The location to get the weather for'),
|
|
96
|
+
* }))
|
|
97
|
+
* .output(z.object({
|
|
98
|
+
* location: z.string().describe('The location the weather is for'),
|
|
99
|
+
* temperature: z.number().describe('The temperature in Celsius'),
|
|
100
|
+
* }))
|
|
101
|
+
* .handler(async ({ input }) => ({
|
|
102
|
+
* location: input.location,
|
|
103
|
+
* temperature: 72 + Math.floor(Math.random() * 21) - 10,
|
|
104
|
+
* }))
|
|
105
|
+
*
|
|
106
|
+
* const getWeatherTool = createTool(getWeatherProcedure, {
|
|
107
|
+
* context: {}, // provide initial context if needed
|
|
108
|
+
* })
|
|
109
|
+
* ```
|
|
110
|
+
*/
|
|
111
|
+
declare function createTool<TInitialContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends AiSdkToolMeta>(procedure: Procedure<TInitialContext, any, TInputSchema, TOutputSchema, TErrorMap, TMeta>, ...rest: MaybeOptionalOptions<SetOptional<Tool<InferSchemaOutput<TInputSchema>, InferSchemaInput<TOutputSchema>>, 'inputSchema' | 'outputSchema' | 'execute'> & CreateProcedureClientOptions<TInitialContext, TOutputSchema, TErrorMap, TMeta, Record<never, never>> & Omit<ClientOptions<Record<never, never>>, 'context'>>): Tool<InferSchemaOutput<TInputSchema>, InferSchemaInput<TOutputSchema>>;
|
|
112
|
+
|
|
113
|
+
export { AI_SDK_TOOL_META_SYMBOL, CreateToolError, createTool, implementTool };
|
|
114
|
+
export type { AiSdkToolMeta };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { ClientOptions } from '@orpc/client';
|
|
2
|
+
import { Meta, ContractProcedure, Schema, AnySchema, ErrorMap, InferSchemaOutput, InferSchemaInput } from '@orpc/contract';
|
|
3
|
+
import { Context, Procedure, CreateProcedureClientOptions } from '@orpc/server';
|
|
4
|
+
import { MaybeOptionalOptions, SetOptional } from '@orpc/shared';
|
|
5
|
+
export { AsyncIteratorClass, asyncIteratorToStream as eventIteratorToStream, asyncIteratorToUnproxiedDataStream as eventIteratorToUnproxiedDataStream, streamToAsyncIteratorClass as streamToEventIterator } from '@orpc/shared';
|
|
6
|
+
import { Tool } from 'ai';
|
|
7
|
+
|
|
8
|
+
declare const AI_SDK_TOOL_META_SYMBOL: unique symbol;
|
|
9
|
+
interface AiSdkToolMeta extends Meta {
|
|
10
|
+
[AI_SDK_TOOL_META_SYMBOL]?: Partial<Tool<unknown, unknown>>;
|
|
11
|
+
}
|
|
12
|
+
declare class CreateToolError extends Error {
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Implements [procedure contract](https://orpc.unnoq.com/docs/contract-first/define-contract#procedure-contract)
|
|
16
|
+
* as an [AI SDK Tool](https://ai-sdk.dev/docs/foundations/tools) by leveraging existing contract definitions.
|
|
17
|
+
*
|
|
18
|
+
* @warning Requires a contract with an `input` schema defined.
|
|
19
|
+
* @info Standard [procedures](https://orpc.unnoq.com/docs/procedure) are also compatible with [procedure contracts](https://orpc.unnoq.com/docs/contract-first/define-contract).
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```ts
|
|
23
|
+
* import { oc } from '@orpc/contract'
|
|
24
|
+
* import {
|
|
25
|
+
* AI_SDK_TOOL_META_SYMBOL,
|
|
26
|
+
* AiSdkToolMeta,
|
|
27
|
+
* implementTool,
|
|
28
|
+
* } from '@orpc/ai-sdk'
|
|
29
|
+
* import { z } from 'zod'
|
|
30
|
+
*
|
|
31
|
+
* interface ORPCMeta extends AiSdkToolMeta {} // optional extend meta
|
|
32
|
+
* const base = oc.$meta<ORPCMeta>({})
|
|
33
|
+
*
|
|
34
|
+
* const getWeatherContract = base
|
|
35
|
+
* .meta({
|
|
36
|
+
* [AI_SDK_TOOL_META_SYMBOL]: {
|
|
37
|
+
* name: 'custom-tool-name', // AI SDK tool name
|
|
38
|
+
* },
|
|
39
|
+
* })
|
|
40
|
+
* .route({
|
|
41
|
+
* summary: 'Get the weather in a location', // AI SDK tool description
|
|
42
|
+
* })
|
|
43
|
+
* .input(
|
|
44
|
+
* z.object({
|
|
45
|
+
* location: z.string().describe('The location to get the weather for'),
|
|
46
|
+
* }),
|
|
47
|
+
* )
|
|
48
|
+
* .output(
|
|
49
|
+
* z.object({
|
|
50
|
+
* location: z.string().describe('The location the weather is for'),
|
|
51
|
+
* temperature: z.number().describe('The temperature in Celsius'),
|
|
52
|
+
* }),
|
|
53
|
+
* )
|
|
54
|
+
*
|
|
55
|
+
* const getWeatherTool = implementTool(getWeatherContract, {
|
|
56
|
+
* execute: async ({ location }) => ({
|
|
57
|
+
* location,
|
|
58
|
+
* temperature: 72 + Math.floor(Math.random() * 21) - 10,
|
|
59
|
+
* }),
|
|
60
|
+
* })
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
declare function implementTool<TOutInput, TInOutput>(contract: ContractProcedure<Schema<any, TOutInput>, Schema<TInOutput, any>, any, AiSdkToolMeta>, ...rest: MaybeOptionalOptions<SetOptional<Tool<TOutInput, TInOutput>, 'inputSchema' | 'outputSchema'>>): Tool<TOutInput, TInOutput>;
|
|
64
|
+
/**
|
|
65
|
+
* Converts a [procedure](https://orpc.unnoq.com/docs/procedure) into an [AI SDK Tool](https://ai-sdk.dev/docs/foundations/tools)
|
|
66
|
+
* by leveraging existing procedure definitions.
|
|
67
|
+
*
|
|
68
|
+
* @warning Requires a contract with an `input` schema defined.
|
|
69
|
+
* @warning Validation occurs twice (once for the tool, once for the procedure call).
|
|
70
|
+
* So validation may fail if inputSchema or outputSchema transform the data into different shapes.
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* ```ts
|
|
74
|
+
* import { os } from '@orpc/server'
|
|
75
|
+
* import {
|
|
76
|
+
* AI_SDK_TOOL_META_SYMBOL,
|
|
77
|
+
* AiSdkToolMeta,
|
|
78
|
+
* createTool
|
|
79
|
+
* } from '@orpc/ai-sdk'
|
|
80
|
+
* import { z } from 'zod'
|
|
81
|
+
*
|
|
82
|
+
* interface ORPCMeta extends AiSdkToolMeta {} // optional extend meta
|
|
83
|
+
* const base = os.$meta<ORPCMeta>({})
|
|
84
|
+
*
|
|
85
|
+
* const getWeatherProcedure = base
|
|
86
|
+
* .meta({
|
|
87
|
+
* [AI_SDK_TOOL_META_SYMBOL]: {
|
|
88
|
+
* name: 'custom-tool-name', // AI SDK tool name
|
|
89
|
+
* },
|
|
90
|
+
* })
|
|
91
|
+
* .route({
|
|
92
|
+
* summary: 'Get the weather in a location',
|
|
93
|
+
* })
|
|
94
|
+
* .input(z.object({
|
|
95
|
+
* location: z.string().describe('The location to get the weather for'),
|
|
96
|
+
* }))
|
|
97
|
+
* .output(z.object({
|
|
98
|
+
* location: z.string().describe('The location the weather is for'),
|
|
99
|
+
* temperature: z.number().describe('The temperature in Celsius'),
|
|
100
|
+
* }))
|
|
101
|
+
* .handler(async ({ input }) => ({
|
|
102
|
+
* location: input.location,
|
|
103
|
+
* temperature: 72 + Math.floor(Math.random() * 21) - 10,
|
|
104
|
+
* }))
|
|
105
|
+
*
|
|
106
|
+
* const getWeatherTool = createTool(getWeatherProcedure, {
|
|
107
|
+
* context: {}, // provide initial context if needed
|
|
108
|
+
* })
|
|
109
|
+
* ```
|
|
110
|
+
*/
|
|
111
|
+
declare function createTool<TInitialContext extends Context, TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap, TMeta extends AiSdkToolMeta>(procedure: Procedure<TInitialContext, any, TInputSchema, TOutputSchema, TErrorMap, TMeta>, ...rest: MaybeOptionalOptions<SetOptional<Tool<InferSchemaOutput<TInputSchema>, InferSchemaInput<TOutputSchema>>, 'inputSchema' | 'outputSchema' | 'execute'> & CreateProcedureClientOptions<TInitialContext, TOutputSchema, TErrorMap, TMeta, Record<never, never>> & Omit<ClientOptions<Record<never, never>>, 'context'>>): Tool<InferSchemaOutput<TInputSchema>, InferSchemaInput<TOutputSchema>>;
|
|
112
|
+
|
|
113
|
+
export { AI_SDK_TOOL_META_SYMBOL, CreateToolError, createTool, implementTool };
|
|
114
|
+
export type { AiSdkToolMeta };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { call } from '@orpc/server';
|
|
2
|
+
import { resolveMaybeOptionalOptions } from '@orpc/shared';
|
|
3
|
+
export { AsyncIteratorClass, asyncIteratorToStream as eventIteratorToStream, asyncIteratorToUnproxiedDataStream as eventIteratorToUnproxiedDataStream, streamToAsyncIteratorClass as streamToEventIterator } from '@orpc/shared';
|
|
4
|
+
import { tool } from 'ai';
|
|
5
|
+
|
|
6
|
+
const AI_SDK_TOOL_META_SYMBOL = Symbol("ORPC_AI_SDK_TOOL_META");
|
|
7
|
+
class CreateToolError extends Error {
|
|
8
|
+
}
|
|
9
|
+
function implementTool(contract, ...rest) {
|
|
10
|
+
if (contract["~orpc"].inputSchema === void 0) {
|
|
11
|
+
throw new CreateToolError("Cannot implement tool from a contract procedure without input schema.");
|
|
12
|
+
}
|
|
13
|
+
const options = resolveMaybeOptionalOptions(rest);
|
|
14
|
+
return tool({
|
|
15
|
+
inputSchema: contract["~orpc"].inputSchema,
|
|
16
|
+
outputSchema: contract["~orpc"].outputSchema,
|
|
17
|
+
description: contract["~orpc"].route.summary ?? contract["~orpc"].route.description,
|
|
18
|
+
...contract["~orpc"].meta[AI_SDK_TOOL_META_SYMBOL],
|
|
19
|
+
...options
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
function createTool(procedure, ...rest) {
|
|
23
|
+
const options = resolveMaybeOptionalOptions(rest);
|
|
24
|
+
return implementTool(procedure, {
|
|
25
|
+
execute: (input) => {
|
|
26
|
+
return call(procedure, input, options);
|
|
27
|
+
},
|
|
28
|
+
...options
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export { AI_SDK_TOOL_META_SYMBOL, CreateToolError, createTool, implementTool };
|
package/package.json
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@orpc/ai-sdk",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "0.0.0-next.d92c7aa",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"homepage": "https://orpc.unnoq.com",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/unnoq/orpc.git",
|
|
10
|
+
"directory": "packages/ai-sdk"
|
|
11
|
+
},
|
|
12
|
+
"keywords": [
|
|
13
|
+
"ai-sdk",
|
|
14
|
+
"orpc"
|
|
15
|
+
],
|
|
16
|
+
"exports": {
|
|
17
|
+
".": {
|
|
18
|
+
"types": "./dist/index.d.mts",
|
|
19
|
+
"import": "./dist/index.mjs",
|
|
20
|
+
"default": "./dist/index.mjs"
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
"files": [
|
|
24
|
+
"dist"
|
|
25
|
+
],
|
|
26
|
+
"peerDependencies": {
|
|
27
|
+
"ai": ">=5.0.76"
|
|
28
|
+
},
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"@orpc/client": "0.0.0-next.d92c7aa",
|
|
31
|
+
"@orpc/contract": "0.0.0-next.d92c7aa",
|
|
32
|
+
"@orpc/server": "0.0.0-next.d92c7aa",
|
|
33
|
+
"@orpc/shared": "0.0.0-next.d92c7aa"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"ai": "6.0.0-beta.85",
|
|
37
|
+
"zod": "^4.1.12"
|
|
38
|
+
},
|
|
39
|
+
"scripts": {
|
|
40
|
+
"build": "unbuild",
|
|
41
|
+
"build:watch": "pnpm run build --watch",
|
|
42
|
+
"type:check": "tsc -b"
|
|
43
|
+
}
|
|
44
|
+
}
|