@typegraph-ai/vercel-ai-provider 0.2.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.
- package/LICENSE +21 -0
- package/README.md +225 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/middleware.d.ts +50 -0
- package/dist/middleware.d.ts.map +1 -0
- package/dist/middleware.js +80 -0
- package/dist/middleware.js.map +1 -0
- package/dist/provider.d.ts +16 -0
- package/dist/provider.d.ts.map +1 -0
- package/dist/provider.js +397 -0
- package/dist/provider.js.map +1 -0
- package/package.json +42 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 TypeGraph
|
|
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,225 @@
|
|
|
1
|
+
# @typegraph-ai/vercel-ai-provider
|
|
2
|
+
|
|
3
|
+
Vercel AI SDK integration for TypeGraph tools and memory context helpers.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm add ai @ai-sdk/openai @typegraph-ai/sdk @typegraph-ai/vercel-ai-provider
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Basic Usage
|
|
12
|
+
|
|
13
|
+
Create tools per request and pass trusted context from your server. Do not ask
|
|
14
|
+
the model to provide tenant, user, group, agent, or thread IDs.
|
|
15
|
+
|
|
16
|
+
```ts
|
|
17
|
+
import { generateText, stepCountIs } from 'ai'
|
|
18
|
+
import { openai } from '@ai-sdk/openai'
|
|
19
|
+
import { AgentId, ThreadId, UserId, typegraphInit } from '@typegraph-ai/sdk'
|
|
20
|
+
import { typegraphTools } from '@typegraph-ai/vercel-ai-provider'
|
|
21
|
+
|
|
22
|
+
const tg = await typegraphInit({
|
|
23
|
+
apiKey: process.env.TYPEGRAPH_API_KEY!,
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
export async function answerQuestion(req: Request) {
|
|
27
|
+
const { prompt, userId, threadId } = await req.json()
|
|
28
|
+
|
|
29
|
+
const tools = typegraphTools(tg, {
|
|
30
|
+
context: {
|
|
31
|
+
userId: UserId(userId),
|
|
32
|
+
threadId: ThreadId(threadId),
|
|
33
|
+
agentId: AgentId('support-agent'),
|
|
34
|
+
},
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
return generateText({
|
|
38
|
+
model: openai('gpt-4.1-mini'),
|
|
39
|
+
tools,
|
|
40
|
+
stopWhen: stepCountIs(4),
|
|
41
|
+
prompt,
|
|
42
|
+
})
|
|
43
|
+
}
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Tools
|
|
47
|
+
|
|
48
|
+
| Tool | Purpose |
|
|
49
|
+
| --- | --- |
|
|
50
|
+
| `typegraph_buckets_list` | List buckets in the configured context |
|
|
51
|
+
| `typegraph_buckets_get` | Fetch one bucket by ID and verify context |
|
|
52
|
+
| `typegraph_buckets_create` | Create a bucket in the configured context |
|
|
53
|
+
| `typegraph_document_ingest` | Ingest one or more documents |
|
|
54
|
+
| `typegraph_search` | Search TypeGraph documents, events, threads, entities, and facts |
|
|
55
|
+
| `typegraph_remember` | Store scoped memory |
|
|
56
|
+
| `typegraph_correct` | Correct scoped memory |
|
|
57
|
+
| `typegraph_jobs_list` | List jobs |
|
|
58
|
+
| `typegraph_jobs_get` | Fetch one job by ID and verify context |
|
|
59
|
+
|
|
60
|
+
## Context Scoping
|
|
61
|
+
|
|
62
|
+
Pass `context` to `typegraphTools()` from your trusted auth/session layer:
|
|
63
|
+
|
|
64
|
+
```ts
|
|
65
|
+
const tools = typegraphTools(tg, {
|
|
66
|
+
context: {
|
|
67
|
+
groupId: project.id,
|
|
68
|
+
userId: user.id,
|
|
69
|
+
threadId: thread.id,
|
|
70
|
+
},
|
|
71
|
+
})
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
The provider merges that context into bucket, document ingest, search, memory,
|
|
75
|
+
and correction calls. Direct lookup tools such as `typegraph_buckets_get` and
|
|
76
|
+
`typegraph_jobs_get` reject records that conflict with the configured context.
|
|
77
|
+
|
|
78
|
+
Graph access is configured on TypeGraph graphs, not on model-selected tool
|
|
79
|
+
inputs. Use buckets to route document/event writes to the intended graph:
|
|
80
|
+
|
|
81
|
+
```ts
|
|
82
|
+
await tools.typegraph_document_ingest.execute({
|
|
83
|
+
document: {
|
|
84
|
+
name: 'Alice profile',
|
|
85
|
+
content: 'Alice prefers vegetarian meals.',
|
|
86
|
+
},
|
|
87
|
+
options: {
|
|
88
|
+
bucketId: 'bkt_profiles',
|
|
89
|
+
},
|
|
90
|
+
}, { toolCallId: 'manual', messages: [] })
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
The model cannot choose graph access through this tool surface. Set graph access
|
|
94
|
+
in trusted `typegraphInit({ graphs })` config and expose only the buckets/tools
|
|
95
|
+
your agent should use.
|
|
96
|
+
|
|
97
|
+
## External IDs
|
|
98
|
+
|
|
99
|
+
External IDs are stable IDs from your app or source systems. Use them in memory
|
|
100
|
+
subjects and entity scopes to keep TypeGraph entities aligned with users,
|
|
101
|
+
accounts, documents, tickets, or messages.
|
|
102
|
+
|
|
103
|
+
Attach external IDs when storing memory:
|
|
104
|
+
|
|
105
|
+
```ts
|
|
106
|
+
await tools.typegraph_remember.execute({
|
|
107
|
+
content: 'Alice prefers short status updates.',
|
|
108
|
+
subject: {
|
|
109
|
+
externalIds: [{ type: 'email', id: 'alice@example.com' }],
|
|
110
|
+
name: 'Alice',
|
|
111
|
+
entityType: 'person',
|
|
112
|
+
},
|
|
113
|
+
}, { toolCallId: 'manual', messages: [] })
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
Use external IDs in search to filter around the same entity:
|
|
117
|
+
|
|
118
|
+
```ts
|
|
119
|
+
await tools.typegraph_search.execute({
|
|
120
|
+
text: 'What should I know before replying to Alice?',
|
|
121
|
+
options: {
|
|
122
|
+
resources: ['documents', 'facts', 'entities'],
|
|
123
|
+
weights: { semantic: 1, bm25: 0.7, graph: 0.5, recency: 0.3 },
|
|
124
|
+
entityScope: {
|
|
125
|
+
externalIds: [{ type: 'email', id: 'alice@example.com' }],
|
|
126
|
+
mode: 'filter',
|
|
127
|
+
},
|
|
128
|
+
promptBuilder: {
|
|
129
|
+
format: 'markdown',
|
|
130
|
+
sections: ['facts', 'chunks'],
|
|
131
|
+
},
|
|
132
|
+
},
|
|
133
|
+
}, { toolCallId: 'manual', messages: [] })
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
## Smoke Test
|
|
137
|
+
|
|
138
|
+
This bypasses model tool selection and directly verifies the tools call your
|
|
139
|
+
TypeGraph instance with the expected context.
|
|
140
|
+
|
|
141
|
+
```ts
|
|
142
|
+
import { UserId, typegraphInit } from '@typegraph-ai/sdk'
|
|
143
|
+
import { typegraphTools } from '@typegraph-ai/vercel-ai-provider'
|
|
144
|
+
|
|
145
|
+
const tg = await typegraphInit({
|
|
146
|
+
apiKey: process.env.TYPEGRAPH_API_KEY!,
|
|
147
|
+
})
|
|
148
|
+
|
|
149
|
+
const tools = typegraphTools(tg, {
|
|
150
|
+
context: {
|
|
151
|
+
userId: UserId('demo-user'),
|
|
152
|
+
threadId: 'demo-thread',
|
|
153
|
+
},
|
|
154
|
+
})
|
|
155
|
+
|
|
156
|
+
const toolOptions = { toolCallId: 'manual', messages: [] }
|
|
157
|
+
|
|
158
|
+
await tools.typegraph_remember.execute({
|
|
159
|
+
content: 'Demo user likes concise answers.',
|
|
160
|
+
subject: {
|
|
161
|
+
externalIds: [{ type: 'user_id', id: 'demo-user' }],
|
|
162
|
+
name: 'Demo User',
|
|
163
|
+
},
|
|
164
|
+
}, toolOptions)
|
|
165
|
+
|
|
166
|
+
const memories = await tg.memory.recall('What answer style does this user prefer?', {
|
|
167
|
+
context: {
|
|
168
|
+
userId: UserId('demo-user'),
|
|
169
|
+
threadId: 'demo-thread',
|
|
170
|
+
},
|
|
171
|
+
limit: 5,
|
|
172
|
+
})
|
|
173
|
+
|
|
174
|
+
console.log(memories)
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
## Memory Middleware
|
|
178
|
+
|
|
179
|
+
`typegraphMemoryMiddleware()` enriches prompts from scoped memory recall and can
|
|
180
|
+
capture response turns back into a TypeGraph thread. Conversation artifact
|
|
181
|
+
extraction is opt-in.
|
|
182
|
+
|
|
183
|
+
```ts
|
|
184
|
+
import { typegraphMemoryMiddleware } from '@typegraph-ai/vercel-ai-provider'
|
|
185
|
+
|
|
186
|
+
const memory = typegraphMemoryMiddleware(tg, {
|
|
187
|
+
context: {
|
|
188
|
+
userId: UserId('demo-user'),
|
|
189
|
+
threadId: ThreadId('demo-thread'),
|
|
190
|
+
agentId: AgentId('support-agent'),
|
|
191
|
+
},
|
|
192
|
+
includeFacts: true,
|
|
193
|
+
format: 'xml',
|
|
194
|
+
conversationMemory: {
|
|
195
|
+
enabled: true,
|
|
196
|
+
mode: 'extract_and_consolidate',
|
|
197
|
+
},
|
|
198
|
+
})
|
|
199
|
+
|
|
200
|
+
const enrichedPrompt = await memory.enrichPrompt('How should I reply?')
|
|
201
|
+
|
|
202
|
+
await memory.afterResponse([
|
|
203
|
+
{ role: 'user', content: 'How should I reply?' },
|
|
204
|
+
{ role: 'assistant', content: 'Use a concise answer and mention the SSO workaround.' },
|
|
205
|
+
])
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
`afterResponse()` always stores supplied turns with `thread.addTurn()`. When
|
|
209
|
+
`conversationMemory.enabled` is true, it also calls `memory.extractThread()`.
|
|
210
|
+
When `mode` is `extract_and_consolidate`, it follows with
|
|
211
|
+
`memory.consolidate()`. Leave `conversationMemory` unset when you only want
|
|
212
|
+
prompt enrichment and turn capture.
|
|
213
|
+
|
|
214
|
+
## API
|
|
215
|
+
|
|
216
|
+
| Export | Description |
|
|
217
|
+
| --- | --- |
|
|
218
|
+
| `typegraphTools(typegraph, opts)` | Full Vercel AI SDK tool set |
|
|
219
|
+
| `typegraphMemoryTools(memory, opts)` | Memory-only subset for remember/correct |
|
|
220
|
+
| `typegraphMemoryMiddleware(typegraph, opts)` | Prompt enrichment, turn capture, and optional conversation memory extraction |
|
|
221
|
+
|
|
222
|
+
## Related
|
|
223
|
+
|
|
224
|
+
- [TypeGraph main repo](../../README.md)
|
|
225
|
+
- [AI SDK tools](https://ai-sdk.dev/docs/ai-sdk-core/tools-and-tool-calling)
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { typegraphTools, typegraphMemoryTools } from './provider.js';
|
|
2
|
+
export type { TypegraphToolDefinition, TypegraphToolName, TypegraphToolsOptions, TypegraphToolsTarget, TypegraphScopedMemoryTarget, } from './provider.js';
|
|
3
|
+
export { typegraphMemoryMiddleware } from './middleware.js';
|
|
4
|
+
export type { MemoryMiddlewareOpts } from './middleware.js';
|
|
5
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAA;AACpE,YAAY,EACV,uBAAuB,EACvB,iBAAiB,EACjB,qBAAqB,EACrB,oBAAoB,EACpB,2BAA2B,GAC5B,MAAM,eAAe,CAAA;AAEtB,OAAO,EAAE,yBAAyB,EAAE,MAAM,iBAAiB,CAAA;AAC3D,YAAY,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAA;AASpE,OAAO,EAAE,yBAAyB,EAAE,MAAM,iBAAiB,CAAA"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { TypeGraphContext, typegraphInstance } from '@typegraph-ai/sdk';
|
|
2
|
+
export interface MemoryMiddlewareOpts {
|
|
3
|
+
/** Trusted request context merged into recall and turn capture calls. */
|
|
4
|
+
context?: TypeGraphContext | undefined;
|
|
5
|
+
/** Run graph extraction when captured turns are stored. Default: false */
|
|
6
|
+
graphExtraction?: boolean | undefined;
|
|
7
|
+
/** Include semantic facts. Default: true */
|
|
8
|
+
includeFacts?: boolean | undefined;
|
|
9
|
+
/** Include episodic memories. Default: false */
|
|
10
|
+
includeEpisodes?: boolean | undefined;
|
|
11
|
+
/** Include procedural memories. Default: false */
|
|
12
|
+
includeProcedures?: boolean | undefined;
|
|
13
|
+
/** Maximum number of memories to recall. Default: 10 */
|
|
14
|
+
limit?: number | undefined;
|
|
15
|
+
/** Output format. Default: 'xml' */
|
|
16
|
+
format?: 'xml' | 'markdown' | 'plain' | undefined;
|
|
17
|
+
/** Opt-in conversation artifact extraction and consolidation after turns are captured. */
|
|
18
|
+
conversationMemory?: {
|
|
19
|
+
enabled?: boolean | undefined;
|
|
20
|
+
mode?: 'extract' | 'extract_and_consolidate' | undefined;
|
|
21
|
+
layoutId?: string | undefined;
|
|
22
|
+
includeRoles?: Array<'user' | 'assistant' | 'tool' | 'system'> | undefined;
|
|
23
|
+
maxTranscriptChars?: number | undefined;
|
|
24
|
+
maxRawMemories?: number | undefined;
|
|
25
|
+
} | undefined;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Create middleware that auto-injects memory context into LLM prompts.
|
|
29
|
+
*
|
|
30
|
+
* Returns a function that takes a prompt string and prepends memory context.
|
|
31
|
+
* Compatible with Vercel AI SDK's middleware pattern.
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```ts
|
|
35
|
+
* const middleware = typegraphMemoryMiddleware(memory)
|
|
36
|
+
* const enrichedPrompt = await middleware.enrichPrompt('What should Alice have for dinner?')
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
export declare function typegraphMemoryMiddleware(typegraph: Pick<typegraphInstance, 'memory' | 'thread'>, opts?: MemoryMiddlewareOpts): {
|
|
40
|
+
enrichPrompt(prompt: string): Promise<string>;
|
|
41
|
+
enrichSystem(systemPrompt: string, userQuery: string): Promise<string>;
|
|
42
|
+
/**
|
|
43
|
+
* After a response, ingest the thread turn into memory.
|
|
44
|
+
*/
|
|
45
|
+
afterResponse(messages: {
|
|
46
|
+
role: "user" | "assistant" | "tool" | "system";
|
|
47
|
+
content: string;
|
|
48
|
+
}[], threadId?: string): Promise<void>;
|
|
49
|
+
};
|
|
50
|
+
//# sourceMappingURL=middleware.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
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G,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;+BAOlB,MAAM,aAAa,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAO5E;;OAEG;4BAES;QAAE,IAAI,EAAE,MAAM,GAAG,WAAW,GAAG,MAAM,GAAG,QAAQ,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,EAAE,aACpE,MAAM,GAChB,OAAO,CAAC,IAAI,CAAC;EAgCnB"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
function typesFor(opts) {
|
|
2
|
+
const types = [];
|
|
3
|
+
if (opts.includeFacts !== false)
|
|
4
|
+
types.push('semantic');
|
|
5
|
+
if (opts.includeEpisodes)
|
|
6
|
+
types.push('episodic');
|
|
7
|
+
if (opts.includeProcedures)
|
|
8
|
+
types.push('procedural');
|
|
9
|
+
return types;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Create middleware that auto-injects memory context into LLM prompts.
|
|
13
|
+
*
|
|
14
|
+
* Returns a function that takes a prompt string and prepends memory context.
|
|
15
|
+
* Compatible with Vercel AI SDK's middleware pattern.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* const middleware = typegraphMemoryMiddleware(memory)
|
|
20
|
+
* const enrichedPrompt = await middleware.enrichPrompt('What should Alice have for dinner?')
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export function typegraphMemoryMiddleware(typegraph, opts = {}) {
|
|
24
|
+
const types = typesFor(opts);
|
|
25
|
+
const format = opts.format ?? 'xml';
|
|
26
|
+
const limit = opts.limit ?? 10;
|
|
27
|
+
return {
|
|
28
|
+
async enrichPrompt(prompt) {
|
|
29
|
+
if (types.length === 0)
|
|
30
|
+
return prompt;
|
|
31
|
+
const context = await typegraph.memory.recall(prompt, { context: opts.context, types, limit, format });
|
|
32
|
+
if (!context)
|
|
33
|
+
return prompt;
|
|
34
|
+
return `${context}\n\n${prompt}`;
|
|
35
|
+
},
|
|
36
|
+
async enrichSystem(systemPrompt, userQuery) {
|
|
37
|
+
if (types.length === 0)
|
|
38
|
+
return systemPrompt;
|
|
39
|
+
const context = await typegraph.memory.recall(userQuery, { context: opts.context, types, limit, format });
|
|
40
|
+
if (!context)
|
|
41
|
+
return systemPrompt;
|
|
42
|
+
return `${systemPrompt}\n\n${context}`;
|
|
43
|
+
},
|
|
44
|
+
/**
|
|
45
|
+
* After a response, ingest the thread turn into memory.
|
|
46
|
+
*/
|
|
47
|
+
async afterResponse(messages, threadId) {
|
|
48
|
+
const resolvedThreadId = threadId ?? opts.context?.threadId;
|
|
49
|
+
if (!resolvedThreadId) {
|
|
50
|
+
throw new Error('typegraphMemoryMiddleware.afterResponse requires a threadId argument or opts.context.threadId.');
|
|
51
|
+
}
|
|
52
|
+
for (const message of messages) {
|
|
53
|
+
await typegraph.thread.addTurn(String(resolvedThreadId), {
|
|
54
|
+
role: message.role,
|
|
55
|
+
content: message.content,
|
|
56
|
+
}, {
|
|
57
|
+
context: opts.context,
|
|
58
|
+
graphExtraction: opts.graphExtraction,
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
const conversationMemory = opts.conversationMemory;
|
|
62
|
+
if (conversationMemory?.enabled) {
|
|
63
|
+
await typegraph.memory.extractThread(String(resolvedThreadId), {
|
|
64
|
+
context: opts.context,
|
|
65
|
+
layoutId: conversationMemory.layoutId,
|
|
66
|
+
includeRoles: conversationMemory.includeRoles,
|
|
67
|
+
maxTranscriptChars: conversationMemory.maxTranscriptChars,
|
|
68
|
+
});
|
|
69
|
+
if (conversationMemory.mode === 'extract_and_consolidate') {
|
|
70
|
+
await typegraph.memory.consolidate({
|
|
71
|
+
context: opts.context,
|
|
72
|
+
layoutId: conversationMemory.layoutId,
|
|
73
|
+
maxRawMemories: conversationMemory.maxRawMemories,
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
//# sourceM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kBAAkB,CAAC,IAAI,KAAK,yBAAyB,EAAE,CAAC;oBAC1D,MAAM,SAAS,CAAC,MAAM,CAAC,WAAW,CAAC;wBACjC,OAAO,EAAE,IAAI,CAAC,OAAO;wBACrB,QAAQ,EAAE,kBAAkB,CAAC,QAAQ;wBACrC,cAAc,EAAE,kBAAkB,CAAC,cAAc;qBAClD,CAAC,CAAA;gBACJ,CAAC;YACH,CAAC;QACH,CAAC;KACF,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type Tool } from 'ai';
|
|
2
|
+
import type { TypeGraphContext, typegraphInstance } from '@typegraph-ai/sdk';
|
|
3
|
+
export type TypegraphToolName = 'typegraph_buckets_list' | 'typegraph_buckets_get' | 'typegraph_buckets_create' | 'typegraph_document_ingest' | 'typegraph_search' | 'typegraph_remember' | 'typegraph_correct' | 'typegraph_jobs_list' | 'typegraph_jobs_get';
|
|
4
|
+
export type TypegraphToolDefinition = Tool<any, unknown>;
|
|
5
|
+
export type TypegraphToolsTarget = Pick<typegraphInstance, 'bucket' | 'document' | 'search' | 'memory' | 'job'>;
|
|
6
|
+
export type TypegraphScopedMemoryTarget = Pick<typegraphInstance['memory'], 'remember' | 'correct'>;
|
|
7
|
+
export interface TypegraphToolsOptions {
|
|
8
|
+
/**
|
|
9
|
+
* Trusted request context supplied by your server. This is merged into every
|
|
10
|
+
* scoped TypeGraph call so the model cannot select another user/group/agent scope.
|
|
11
|
+
*/
|
|
12
|
+
context?: TypeGraphContext | undefined;
|
|
13
|
+
}
|
|
14
|
+
export declare function typegraphMemoryTools(memory: TypegraphScopedMemoryTarget, opts?: TypegraphToolsOptions): Pick<Record<TypegraphToolName, TypegraphToolDefinition>, 'typegraph_remember' | 'typegraph_correct'>;
|
|
15
|
+
export declare function typegraphTools(typegraph: TypegraphToolsTarget, opts?: TypegraphToolsOptions): Record<TypegraphToolName, TypegraphToolDefinition>;
|
|
16
|
+
//# sourceMappingURL=provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,KAAK,IAAI,EAAE,MAAM,IAAI,CAAA;AAC1C,OAAO,KAAK,EAUV,gBAAgB,EAChB,iBAAiB,EAClB,MAAM,mBAAmB,CAAA;AAE1B,MAAM,MAAM,iBAAiB,GACzB,wBAAwB,GACxB,uBAAuB,GACvB,0BAA0B,GAC1B,2BAA2B,GAC3B,kBAAkB,GAClB,oBAAoB,GACpB,mBAAmB,GACnB,qBAAqB,GACrB,oBAAoB,CAAA;AAExB,MAAM,MAAM,uBAAuB,GAAG,IAAI,CAAC,GAAG,EAAE,OAAO,CAAC,CAAA;AAExD,MAAM,MAAM,oBAAoB,GAAG,IAAI,CACrC,iBAAiB,EACjB,QAAQ,GAAG,UAAU,GAAG,QAAQ,GAAG,QAAQ,GAAG,KAAK,CACpD,CAAA;AAED,MAAM,MAAM,2BAA2B,GAAG,IAAI,CAC5C,iBAAiB,CAAC,QAAQ,CAAC,EAC3B,UAAU,GAAG,SAAS,CACvB,CAAA;AAED,MAAM,WAAW,qBAAqB;IACpC;;;OAGG;IACH,OAAO,CAAC,EAAE,gBAAgB,GAAG,SAAS,CAAA;CACvC;AAqOD,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,2BAA2B,EACnC,IAAI,GAAE,qBAA0B,GAC/B,IAAI,CAAC,MAAM,CAAC,iBAAiB,EAAE,uBAAuB,CAAC,EAAE,oBAAoB,GAAG,mBAAmB,CAAC,CAKtG;AAED,wBAAgB,cAAc,CAC5B,SAAS,EAAE,oBAAoB,EAC/B,IAAI,GAAE,qBAA0B,GAC/B,MAAM,CAAC,iBAAiB,EAAE,uBAAuB,CAAC,CA0NpD"}
|
package/dist/provider.js
ADDED
|
@@ -0,0 +1,397 @@
|
|
|
1
|
+
import { jsonSchema } from 'ai';
|
|
2
|
+
const IDENTITY_KEYS = [
|
|
3
|
+
'organizationId',
|
|
4
|
+
'groupId',
|
|
5
|
+
'userId',
|
|
6
|
+
'agentId',
|
|
7
|
+
'threadId',
|
|
8
|
+
];
|
|
9
|
+
function compactObject(value) {
|
|
10
|
+
const out = {};
|
|
11
|
+
for (const [key, item] of Object.entries(value)) {
|
|
12
|
+
if (item !== undefined && item !== null)
|
|
13
|
+
out[key] = item;
|
|
14
|
+
}
|
|
15
|
+
return out;
|
|
16
|
+
}
|
|
17
|
+
function compactContext(context) {
|
|
18
|
+
if (!context)
|
|
19
|
+
return undefined;
|
|
20
|
+
const out = {};
|
|
21
|
+
for (const key of IDENTITY_KEYS) {
|
|
22
|
+
const value = context[key];
|
|
23
|
+
if (value !== undefined && value !== null) {
|
|
24
|
+
;
|
|
25
|
+
out[key] = value;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
if (context.traceId)
|
|
29
|
+
out.traceId = context.traceId;
|
|
30
|
+
if (context.spanId)
|
|
31
|
+
out.spanId = context.spanId;
|
|
32
|
+
if (context.agentName)
|
|
33
|
+
out.agentName = context.agentName;
|
|
34
|
+
if (context.agentDescription)
|
|
35
|
+
out.agentDescription = context.agentDescription;
|
|
36
|
+
if (context.agentVersion)
|
|
37
|
+
out.agentVersion = context.agentVersion;
|
|
38
|
+
return Object.keys(out).length > 0 ? out : undefined;
|
|
39
|
+
}
|
|
40
|
+
function scopedOptions(value, opts) {
|
|
41
|
+
const context = compactContext(opts.context);
|
|
42
|
+
return compactObject({
|
|
43
|
+
...(value ?? {}),
|
|
44
|
+
...(context ? { context } : {}),
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
function scopedQueryOptions(value, opts) {
|
|
48
|
+
return scopedOptions((value ?? {}), opts);
|
|
49
|
+
}
|
|
50
|
+
function normalizeDocument(document) {
|
|
51
|
+
return compactObject({
|
|
52
|
+
...document,
|
|
53
|
+
updatedAt: coerceDate(document.updatedAt),
|
|
54
|
+
createdAt: coerceDate(document.createdAt),
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
function coerceDate(value) {
|
|
58
|
+
if (value instanceof Date)
|
|
59
|
+
return value;
|
|
60
|
+
if (typeof value === 'string' || typeof value === 'number')
|
|
61
|
+
return new Date(value);
|
|
62
|
+
return undefined;
|
|
63
|
+
}
|
|
64
|
+
function assertMatchesContext(record, context, label) {
|
|
65
|
+
if (!record || !context)
|
|
66
|
+
return;
|
|
67
|
+
for (const key of IDENTITY_KEYS) {
|
|
68
|
+
const expected = context[key];
|
|
69
|
+
if (expected === undefined)
|
|
70
|
+
continue;
|
|
71
|
+
const actual = record[key] ?? record['identity']?.[key];
|
|
72
|
+
if (actual !== undefined && actual !== expected) {
|
|
73
|
+
throw new Error(`${label} is outside the configured TypeGraph context.`);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
function schema(json) {
|
|
78
|
+
return jsonSchema(json);
|
|
79
|
+
}
|
|
80
|
+
const externalIdSchema = {
|
|
81
|
+
type: 'object',
|
|
82
|
+
additionalProperties: false,
|
|
83
|
+
properties: {
|
|
84
|
+
id: { type: 'string', description: 'Stable identifier from your app or source system.' },
|
|
85
|
+
type: { type: 'string', description: 'Identifier namespace, e.g. email, clerk_user_id, slack_user_id.' },
|
|
86
|
+
encoding: { type: 'string', enum: ['none', 'sha256'] },
|
|
87
|
+
metadata: { type: 'object', additionalProperties: true },
|
|
88
|
+
},
|
|
89
|
+
required: ['id', 'type'],
|
|
90
|
+
};
|
|
91
|
+
const subjectSchema = {
|
|
92
|
+
type: 'object',
|
|
93
|
+
additionalProperties: true,
|
|
94
|
+
properties: {
|
|
95
|
+
entityId: { type: 'string' },
|
|
96
|
+
externalIds: { type: 'array', items: externalIdSchema },
|
|
97
|
+
name: { type: 'string' },
|
|
98
|
+
entityType: { type: 'string' },
|
|
99
|
+
aliases: { type: 'array', items: { type: 'string' } },
|
|
100
|
+
description: { type: 'string' },
|
|
101
|
+
metadata: { type: 'object', additionalProperties: true },
|
|
102
|
+
},
|
|
103
|
+
};
|
|
104
|
+
const documentSchema = {
|
|
105
|
+
type: 'object',
|
|
106
|
+
additionalProperties: true,
|
|
107
|
+
properties: {
|
|
108
|
+
id: { type: 'string' },
|
|
109
|
+
name: { type: 'string' },
|
|
110
|
+
description: { type: 'string' },
|
|
111
|
+
content: { type: 'string' },
|
|
112
|
+
url: { type: 'string' },
|
|
113
|
+
createdAt: { type: 'string', description: 'ISO timestamp.' },
|
|
114
|
+
updatedAt: { type: 'string', description: 'ISO timestamp.' },
|
|
115
|
+
mimeType: { type: 'string' },
|
|
116
|
+
language: { type: 'string' },
|
|
117
|
+
metadata: { type: 'object', additionalProperties: true },
|
|
118
|
+
},
|
|
119
|
+
required: ['content', 'name'],
|
|
120
|
+
};
|
|
121
|
+
const paginationSchema = {
|
|
122
|
+
type: 'object',
|
|
123
|
+
additionalProperties: false,
|
|
124
|
+
properties: {
|
|
125
|
+
limit: { type: 'number' },
|
|
126
|
+
offset: { type: 'number' },
|
|
127
|
+
},
|
|
128
|
+
};
|
|
129
|
+
const indexDefaultsSchema = {
|
|
130
|
+
type: 'object',
|
|
131
|
+
additionalProperties: true,
|
|
132
|
+
properties: {
|
|
133
|
+
chunkSize: { type: 'number' },
|
|
134
|
+
chunkOverlap: { type: 'number' },
|
|
135
|
+
stripMarkdownForEmbedding: { type: 'boolean' },
|
|
136
|
+
propagateMetadata: { type: 'array', items: { type: 'string' } },
|
|
137
|
+
graphExtraction: { type: 'boolean' },
|
|
138
|
+
},
|
|
139
|
+
};
|
|
140
|
+
function memoryRememberTool(target, opts) {
|
|
141
|
+
return {
|
|
142
|
+
description: 'Store a scoped TypeGraph memory for future recall.',
|
|
143
|
+
inputSchema: schema({
|
|
144
|
+
type: 'object',
|
|
145
|
+
additionalProperties: false,
|
|
146
|
+
properties: {
|
|
147
|
+
content: { type: 'string', description: 'Memory content to store.' },
|
|
148
|
+
category: { type: 'string', enum: ['episodic', 'semantic', 'procedural'] },
|
|
149
|
+
importance: { type: 'number', minimum: 0, maximum: 1 },
|
|
150
|
+
metadata: { type: 'object', additionalProperties: true },
|
|
151
|
+
subject: subjectSchema,
|
|
152
|
+
relatedEntities: { type: 'array', items: subjectSchema },
|
|
153
|
+
},
|
|
154
|
+
required: ['content'],
|
|
155
|
+
}),
|
|
156
|
+
execute: async (input) => {
|
|
157
|
+
const { content, ...rest } = input;
|
|
158
|
+
return target.remember(content, scopedOptions(rest, opts));
|
|
159
|
+
},
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
function memoryCorrectTool(target, opts) {
|
|
163
|
+
return {
|
|
164
|
+
description: 'Correct scoped TypeGraph memory with a natural language correction.',
|
|
165
|
+
inputSchema: schema({
|
|
166
|
+
type: 'object',
|
|
167
|
+
additionalProperties: false,
|
|
168
|
+
properties: {
|
|
169
|
+
correction: { type: 'string', description: 'Natural language correction to apply.' },
|
|
170
|
+
subject: subjectSchema,
|
|
171
|
+
relatedEntities: { type: 'array', items: subjectSchema },
|
|
172
|
+
},
|
|
173
|
+
required: ['correction'],
|
|
174
|
+
}),
|
|
175
|
+
execute: async (input) => {
|
|
176
|
+
const { correction, ...rest } = input;
|
|
177
|
+
return target.correct(correction, scopedOptions(rest, opts));
|
|
178
|
+
},
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
export function typegraphMemoryTools(memory, opts = {}) {
|
|
182
|
+
return {
|
|
183
|
+
typegraph_remember: memoryRememberTool(memory, opts),
|
|
184
|
+
typegraph_correct: memoryCorrectTool(memory, opts),
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
export function typegraphTools(typegraph, opts = {}) {
|
|
188
|
+
return {
|
|
189
|
+
typegraph_buckets_list: {
|
|
190
|
+
description: 'List TypeGraph buckets in the configured context.',
|
|
191
|
+
inputSchema: schema({
|
|
192
|
+
type: 'object',
|
|
193
|
+
additionalProperties: false,
|
|
194
|
+
properties: {
|
|
195
|
+
filter: {
|
|
196
|
+
type: 'object',
|
|
197
|
+
additionalProperties: false,
|
|
198
|
+
properties: {
|
|
199
|
+
name: { type: 'string' },
|
|
200
|
+
},
|
|
201
|
+
description: 'Optional non-context bucket filters. Context is supplied by the server.',
|
|
202
|
+
},
|
|
203
|
+
pagination: paginationSchema,
|
|
204
|
+
},
|
|
205
|
+
}),
|
|
206
|
+
execute: async (input) => {
|
|
207
|
+
return typegraph.bucket.list(input.filter ?? {}, scopedOptions({}, opts), input.pagination);
|
|
208
|
+
},
|
|
209
|
+
},
|
|
210
|
+
typegraph_buckets_get: {
|
|
211
|
+
description: 'Get one TypeGraph bucket by ID.',
|
|
212
|
+
inputSchema: schema({
|
|
213
|
+
type: 'object',
|
|
214
|
+
additionalProperties: false,
|
|
215
|
+
properties: {
|
|
216
|
+
bucketId: { type: 'string' },
|
|
217
|
+
},
|
|
218
|
+
required: ['bucketId'],
|
|
219
|
+
}),
|
|
220
|
+
execute: async (input) => {
|
|
221
|
+
const bucket = await typegraph.bucket.get(input.bucketId);
|
|
222
|
+
assertMatchesContext(bucket, opts.context, 'Bucket');
|
|
223
|
+
return bucket;
|
|
224
|
+
},
|
|
225
|
+
},
|
|
226
|
+
typegraph_buckets_create: {
|
|
227
|
+
description: 'Create a TypeGraph bucket in the configured context.',
|
|
228
|
+
inputSchema: schema({
|
|
229
|
+
type: 'object',
|
|
230
|
+
additionalProperties: false,
|
|
231
|
+
properties: {
|
|
232
|
+
name: { type: 'string' },
|
|
233
|
+
description: { type: 'string' },
|
|
234
|
+
embeddingModel: { type: 'string' },
|
|
235
|
+
searchEmbeddingModel: { type: 'string' },
|
|
236
|
+
indexDefaults: indexDefaultsSchema,
|
|
237
|
+
},
|
|
238
|
+
required: ['name'],
|
|
239
|
+
}),
|
|
240
|
+
execute: async (input) => {
|
|
241
|
+
return typegraph.bucket.create(input, scopedOptions({}, opts));
|
|
242
|
+
},
|
|
243
|
+
},
|
|
244
|
+
typegraph_document_ingest: {
|
|
245
|
+
description: 'Ingest one or more documents into TypeGraph in the configured context.',
|
|
246
|
+
inputSchema: schema({
|
|
247
|
+
type: 'object',
|
|
248
|
+
additionalProperties: false,
|
|
249
|
+
properties: {
|
|
250
|
+
document: documentSchema,
|
|
251
|
+
documents: { type: 'array', items: documentSchema },
|
|
252
|
+
options: {
|
|
253
|
+
type: 'object',
|
|
254
|
+
additionalProperties: true,
|
|
255
|
+
properties: {
|
|
256
|
+
bucketId: { type: 'string' },
|
|
257
|
+
mode: { type: 'string', enum: ['upsert', 'replace'] },
|
|
258
|
+
chunkSize: { type: 'number' },
|
|
259
|
+
chunkOverlap: { type: 'number' },
|
|
260
|
+
stripMarkdownForEmbedding: { type: 'boolean' },
|
|
261
|
+
graphExtraction: { type: 'boolean' },
|
|
262
|
+
dryRun: { type: 'boolean' },
|
|
263
|
+
concurrency: { type: 'number' },
|
|
264
|
+
},
|
|
265
|
+
},
|
|
266
|
+
},
|
|
267
|
+
}),
|
|
268
|
+
execute: async (input) => {
|
|
269
|
+
const documents = [
|
|
270
|
+
...(input.document ? [input.document] : []),
|
|
271
|
+
...(input.documents ?? []),
|
|
272
|
+
].map(normalizeDocument);
|
|
273
|
+
if (documents.length === 0) {
|
|
274
|
+
throw new Error('typegraph_document_ingest requires document or documents.');
|
|
275
|
+
}
|
|
276
|
+
return typegraph.document.ingest(documents, {
|
|
277
|
+
...scopedOptions((input.options ?? {}), opts),
|
|
278
|
+
});
|
|
279
|
+
},
|
|
280
|
+
},
|
|
281
|
+
typegraph_search: {
|
|
282
|
+
description: 'Search TypeGraph retrieval results in the configured context.',
|
|
283
|
+
inputSchema: schema({
|
|
284
|
+
type: 'object',
|
|
285
|
+
additionalProperties: false,
|
|
286
|
+
properties: {
|
|
287
|
+
text: { type: 'string', description: 'Natural language query.' },
|
|
288
|
+
options: {
|
|
289
|
+
type: 'object',
|
|
290
|
+
additionalProperties: true,
|
|
291
|
+
properties: {
|
|
292
|
+
buckets: { type: 'array', items: { type: 'string' } },
|
|
293
|
+
limit: { type: 'number' },
|
|
294
|
+
resources: {
|
|
295
|
+
type: 'array',
|
|
296
|
+
items: {
|
|
297
|
+
type: 'string',
|
|
298
|
+
enum: ['documents', 'events', 'threads', 'entities', 'facts'],
|
|
299
|
+
},
|
|
300
|
+
},
|
|
301
|
+
weights: {
|
|
302
|
+
type: 'object',
|
|
303
|
+
additionalProperties: false,
|
|
304
|
+
properties: {
|
|
305
|
+
semantic: { anyOf: [{ type: 'number' }, { const: false }] },
|
|
306
|
+
bm25: { anyOf: [{ type: 'number' }, { const: false }] },
|
|
307
|
+
graph: { anyOf: [{ type: 'number' }, { const: false }] },
|
|
308
|
+
recency: { anyOf: [{ type: 'number' }, { const: false }] },
|
|
309
|
+
},
|
|
310
|
+
},
|
|
311
|
+
fusion: {
|
|
312
|
+
type: 'object',
|
|
313
|
+
additionalProperties: false,
|
|
314
|
+
properties: {
|
|
315
|
+
method: { type: 'string', enum: ['rrf'] },
|
|
316
|
+
k: { type: 'number' },
|
|
317
|
+
},
|
|
318
|
+
},
|
|
319
|
+
entityScope: {
|
|
320
|
+
type: 'object',
|
|
321
|
+
additionalProperties: false,
|
|
322
|
+
properties: {
|
|
323
|
+
entityIds: { type: 'array', items: { type: 'string' } },
|
|
324
|
+
externalIds: { type: 'array', items: externalIdSchema },
|
|
325
|
+
mode: { type: 'string', enum: ['filter', 'boost'] },
|
|
326
|
+
},
|
|
327
|
+
},
|
|
328
|
+
promptBuilder: {
|
|
329
|
+
anyOf: [
|
|
330
|
+
{ type: 'boolean' },
|
|
331
|
+
{
|
|
332
|
+
type: 'object',
|
|
333
|
+
additionalProperties: true,
|
|
334
|
+
properties: {
|
|
335
|
+
format: { type: 'string', enum: ['xml', 'markdown', 'plain'] },
|
|
336
|
+
sections: {
|
|
337
|
+
type: 'array',
|
|
338
|
+
items: { type: 'string', enum: ['facts', 'entities', 'chunks'] },
|
|
339
|
+
},
|
|
340
|
+
maxTotalTokens: { type: 'number' },
|
|
341
|
+
},
|
|
342
|
+
},
|
|
343
|
+
],
|
|
344
|
+
},
|
|
345
|
+
includeInvalidated: { type: 'boolean' },
|
|
346
|
+
explain: { type: 'boolean' },
|
|
347
|
+
},
|
|
348
|
+
},
|
|
349
|
+
},
|
|
350
|
+
required: ['text'],
|
|
351
|
+
}),
|
|
352
|
+
execute: async (input) => {
|
|
353
|
+
return typegraph.search(input.text, scopedQueryOptions(input.options, opts));
|
|
354
|
+
},
|
|
355
|
+
},
|
|
356
|
+
typegraph_remember: memoryRememberTool(typegraph.memory, opts),
|
|
357
|
+
typegraph_correct: memoryCorrectTool(typegraph.memory, opts),
|
|
358
|
+
typegraph_jobs_list: {
|
|
359
|
+
description: 'List TypeGraph jobs in the configured context.',
|
|
360
|
+
inputSchema: schema({
|
|
361
|
+
type: 'object',
|
|
362
|
+
additionalProperties: false,
|
|
363
|
+
properties: {
|
|
364
|
+
filter: {
|
|
365
|
+
type: 'object',
|
|
366
|
+
additionalProperties: false,
|
|
367
|
+
properties: {
|
|
368
|
+
bucketId: { type: 'string' },
|
|
369
|
+
status: { type: 'string', enum: ['pending', 'processing', 'complete', 'failed'] },
|
|
370
|
+
type: { type: 'string', enum: ['ingest', 'remember', 'thread_turn', 'correct', 'forget'] },
|
|
371
|
+
},
|
|
372
|
+
},
|
|
373
|
+
},
|
|
374
|
+
}),
|
|
375
|
+
execute: async (input) => {
|
|
376
|
+
return typegraph.job.list((input.filter ?? {}));
|
|
377
|
+
},
|
|
378
|
+
},
|
|
379
|
+
typegraph_jobs_get: {
|
|
380
|
+
description: 'Get one TypeGraph job by ID.',
|
|
381
|
+
inputSchema: schema({
|
|
382
|
+
type: 'object',
|
|
383
|
+
additionalProperties: false,
|
|
384
|
+
properties: {
|
|
385
|
+
jobId: { type: 'string' },
|
|
386
|
+
},
|
|
387
|
+
required: ['jobId'],
|
|
388
|
+
}),
|
|
389
|
+
execute: async (input) => {
|
|
390
|
+
const job = await typegraph.job.get(input.jobId);
|
|
391
|
+
assertMatchesContext(job, opts.context, 'Job');
|
|
392
|
+
return job;
|
|
393
|
+
},
|
|
394
|
+
},
|
|
395
|
+
};
|
|
396
|
+
}
|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ai-provider",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Vercel AI SDK tools and memory helpers for TypeGraph",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"main": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"sideEffects": false,
|
|
10
|
+
"files": [
|
|
11
|
+
"dist",
|
|
12
|
+
"README.md"
|
|
13
|
+
],
|
|
14
|
+
"exports": {
|
|
15
|
+
".": {
|
|
16
|
+
"import": "./dist/index.js",
|
|
17
|
+
"types": "./dist/index.d.ts"
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"@typegraph-ai/sdk": "0.6.0"
|
|
22
|
+
},
|
|
23
|
+
"peerDependencies": {
|
|
24
|
+
"ai": "^6.0.0"
|
|
25
|
+
},
|
|
26
|
+
"publishConfig": {
|
|
27
|
+
"registry": "https://registry.npmjs.org/",
|
|
28
|
+
"access": "public"
|
|
29
|
+
},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"ai": "^6.0.0",
|
|
32
|
+
"typescript": "^5.4.0",
|
|
33
|
+
"vitest": "^1.0.0"
|
|
34
|
+
},
|
|
35
|
+
"scripts": {
|
|
36
|
+
"build": "tsc",
|
|
37
|
+
"dev": "tsc --watch",
|
|
38
|
+
"test": "vitest run --passWithNoTests",
|
|
39
|
+
"typecheck": "tsc --noEmit",
|
|
40
|
+
"clean": "rm -rf dist"
|
|
41
|
+
}
|
|
42
|
+
}
|