@sf-ai/sdk 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 +20 -0
- package/README.md +125 -0
- package/client.d.ts +10 -0
- package/client.d.ts.map +1 -0
- package/client.js +9 -0
- package/esm/client.d.ts +10 -0
- package/esm/client.d.ts.map +1 -0
- package/esm/client.js +6 -0
- package/esm/index.d.ts +3 -0
- package/esm/index.d.ts.map +1 -0
- package/esm/index.js +1 -0
- package/index.d.ts +3 -0
- package/index.d.ts.map +1 -0
- package/index.js +5 -0
- package/package.json +47 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
The San Francisco License (SF License)
|
|
2
|
+
|
|
3
|
+
Copyright (c) San Francisco License Contributors 2026
|
|
4
|
+
|
|
5
|
+
Permission is granted, free of charge, to any person or organization
|
|
6
|
+
obtaining a copy of this software and associated documentation files
|
|
7
|
+
(the "Software"), to use, copy, modify, merge, publish, distribute,
|
|
8
|
+
sublicense, and/or sell copies of the Software, and to permit others
|
|
9
|
+
to whom the Software is furnished to do the same.
|
|
10
|
+
|
|
11
|
+
The only requirement is that this license notice and copyright notice
|
|
12
|
+
shall be included in all copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NONINFRINGEMENT.
|
|
17
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
18
|
+
CLAIM, DAMAGES, OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
19
|
+
TORT, OR OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION WITH THE
|
|
20
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
# @sf-ai/sdk
|
|
2
|
+
|
|
3
|
+
Type-safe SDK for the San Francisco database with GraphQL codegen.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
This package provides a type-safe SDK generated from the San Francisco RAG database schema using `@constructive-io/graphql-codegen`. It generates both React Query hooks and a Prisma-like ORM client from the PGPM modules.
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
pnpm add @sf-ai/sdk
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
### ORM Client
|
|
18
|
+
|
|
19
|
+
```typescript
|
|
20
|
+
import { createClient } from '@sf-ai/sdk';
|
|
21
|
+
|
|
22
|
+
const db = createClient({
|
|
23
|
+
endpoint: process.env.GRAPHQL_ENDPOINT,
|
|
24
|
+
headers: {
|
|
25
|
+
Authorization: `Bearer ${process.env.API_TOKEN}`,
|
|
26
|
+
},
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
// Query documents
|
|
30
|
+
const documents = await db.document.findMany({
|
|
31
|
+
select: { id: true, title: true, content: true },
|
|
32
|
+
first: 10,
|
|
33
|
+
}).execute().unwrap();
|
|
34
|
+
|
|
35
|
+
// Query chunks with embeddings
|
|
36
|
+
const chunks = await db.chunk.findMany({
|
|
37
|
+
select: {
|
|
38
|
+
id: true,
|
|
39
|
+
content: true,
|
|
40
|
+
document: { select: { id: true, title: true } },
|
|
41
|
+
},
|
|
42
|
+
}).execute().unwrap();
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### React Query Hooks
|
|
46
|
+
|
|
47
|
+
```typescript
|
|
48
|
+
import { useDocumentsQuery, useChunksQuery } from '@sf-ai/sdk';
|
|
49
|
+
|
|
50
|
+
function DocumentList() {
|
|
51
|
+
const { data, isLoading } = useDocumentsQuery({ first: 10 });
|
|
52
|
+
|
|
53
|
+
if (isLoading) return <div>Loading...</div>;
|
|
54
|
+
|
|
55
|
+
return (
|
|
56
|
+
<ul>
|
|
57
|
+
{data?.documents.nodes.map((doc) => (
|
|
58
|
+
<li key={doc.id}>{doc.title}</li>
|
|
59
|
+
))}
|
|
60
|
+
</ul>
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## Regenerating the SDK
|
|
66
|
+
|
|
67
|
+
The SDK is generated from the PGPM modules in this repository. To regenerate:
|
|
68
|
+
|
|
69
|
+
### Locally
|
|
70
|
+
|
|
71
|
+
Requires a running PostgreSQL database with the schema deployed:
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
cd packages/sf-sdk
|
|
75
|
+
pnpm run codegen:all
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### Via GitHub Actions
|
|
79
|
+
|
|
80
|
+
Use the "Generate SDK" workflow which:
|
|
81
|
+
|
|
82
|
+
1. Spins up an ephemeral PostgreSQL database
|
|
83
|
+
2. Deploys the PGPM modules
|
|
84
|
+
3. Generates the SDK types
|
|
85
|
+
4. Optionally commits the changes
|
|
86
|
+
|
|
87
|
+
Run the workflow from the Actions tab with the "commit_changes" option enabled to automatically commit regenerated types.
|
|
88
|
+
|
|
89
|
+
## Configuration
|
|
90
|
+
|
|
91
|
+
The codegen configuration is in `graphql-codegen.config.ts`:
|
|
92
|
+
|
|
93
|
+
```typescript
|
|
94
|
+
import { defineConfig } from '@constructive-io/graphql-codegen';
|
|
95
|
+
|
|
96
|
+
export default defineConfig({
|
|
97
|
+
targets: {
|
|
98
|
+
default: {
|
|
99
|
+
db: {
|
|
100
|
+
pgpm: {
|
|
101
|
+
modulePath: '../rag-core',
|
|
102
|
+
},
|
|
103
|
+
schemas: ['rag'],
|
|
104
|
+
},
|
|
105
|
+
output: './src/generated',
|
|
106
|
+
// ... other options
|
|
107
|
+
},
|
|
108
|
+
},
|
|
109
|
+
});
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
## Schema
|
|
113
|
+
|
|
114
|
+
The SDK is generated from the `rag` schema which includes:
|
|
115
|
+
|
|
116
|
+
- `embedding_model` - Embedding model configurations
|
|
117
|
+
- `collection` - Document collections
|
|
118
|
+
- `collection_model` - Collection-model associations
|
|
119
|
+
- `document` - Full documents
|
|
120
|
+
- `chunk` - Document chunks for RAG
|
|
121
|
+
- `embedding` - Vector embeddings
|
|
122
|
+
|
|
123
|
+
## License
|
|
124
|
+
|
|
125
|
+
MIT
|
package/client.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export interface SFClientConfig {
|
|
2
|
+
endpoint: string;
|
|
3
|
+
headers?: Record<string, string>;
|
|
4
|
+
}
|
|
5
|
+
export interface SFClient {
|
|
6
|
+
endpoint: string;
|
|
7
|
+
headers: Record<string, string>;
|
|
8
|
+
}
|
|
9
|
+
export declare function createClient(config: SFClientConfig): SFClient;
|
|
10
|
+
//# sourceMappingURL=client.d.ts.map
|
package/client.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,cAAc;IAC7B,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAClC;AAED,MAAM,WAAW,QAAQ;IACvB,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACjC;AAED,wBAAgB,YAAY,CAAC,MAAM,EAAE,cAAc,GAAG,QAAQ,CAK7D"}
|
package/client.js
ADDED
package/esm/client.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export interface SFClientConfig {
|
|
2
|
+
endpoint: string;
|
|
3
|
+
headers?: Record<string, string>;
|
|
4
|
+
}
|
|
5
|
+
export interface SFClient {
|
|
6
|
+
endpoint: string;
|
|
7
|
+
headers: Record<string, string>;
|
|
8
|
+
}
|
|
9
|
+
export declare function createClient(config: SFClientConfig): SFClient;
|
|
10
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,cAAc;IAC7B,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAClC;AAED,MAAM,WAAW,QAAQ;IACvB,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACjC;AAED,wBAAgB,YAAY,CAAC,MAAM,EAAE,cAAc,GAAG,QAAQ,CAK7D"}
|
package/esm/client.js
ADDED
package/esm/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACxC,YAAY,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC"}
|
package/esm/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { createClient } from './client';
|
package/index.d.ts
ADDED
package/index.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACxC,YAAY,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC"}
|
package/index.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createClient = void 0;
|
|
4
|
+
var client_1 = require("./client");
|
|
5
|
+
Object.defineProperty(exports, "createClient", { enumerable: true, get: function () { return client_1.createClient; } });
|
package/package.json
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@sf-ai/sdk",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Type-safe SDK for the San Francisco database with GraphQL codegen",
|
|
5
|
+
"author": "City of San Francisco <opensource@sfgov.org>",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"main": "index.js",
|
|
8
|
+
"module": "esm/index.js",
|
|
9
|
+
"types": "index.d.ts",
|
|
10
|
+
"homepage": "https://github.com/city-of-san-francisco/sf-rag-utils",
|
|
11
|
+
"publishConfig": {
|
|
12
|
+
"access": "public",
|
|
13
|
+
"directory": "dist"
|
|
14
|
+
},
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "https://github.com/city-of-san-francisco/sf-rag-utils"
|
|
18
|
+
},
|
|
19
|
+
"bugs": {
|
|
20
|
+
"url": "https://github.com/city-of-san-francisco/sf-rag-utils/issues"
|
|
21
|
+
},
|
|
22
|
+
"scripts": {
|
|
23
|
+
"copy": "makage assets",
|
|
24
|
+
"clean": "makage clean",
|
|
25
|
+
"prepublishOnly": "npm run build",
|
|
26
|
+
"build": "makage build",
|
|
27
|
+
"lint": "eslint . --fix",
|
|
28
|
+
"test": "jest --passWithNoTests",
|
|
29
|
+
"test:watch": "jest --watch",
|
|
30
|
+
"codegen": "npx @constructive-io/graphql-codegen generate -c graphql-codegen.config.ts",
|
|
31
|
+
"codegen:orm": "npx @constructive-io/graphql-codegen generate-orm -c graphql-codegen.config.ts",
|
|
32
|
+
"codegen:all": "npm run codegen && npm run codegen:orm"
|
|
33
|
+
},
|
|
34
|
+
"keywords": [
|
|
35
|
+
"san-francisco",
|
|
36
|
+
"sdk",
|
|
37
|
+
"graphql",
|
|
38
|
+
"codegen",
|
|
39
|
+
"orm",
|
|
40
|
+
"postgresql"
|
|
41
|
+
],
|
|
42
|
+
"devDependencies": {
|
|
43
|
+
"@constructive-io/graphql-codegen": "^3.0.3",
|
|
44
|
+
"makage": "0.1.9"
|
|
45
|
+
},
|
|
46
|
+
"gitHead": "1d766c1022d0be8029c9f7be968ed33050c25e3a"
|
|
47
|
+
}
|