asasvirtuais 0.7.8 → 0.7.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/package.json +2 -2
  2. package/packages/airtable/index.ts +189 -0
  3. package/packages/airtable/types.ts +722 -0
  4. package/packages/auth0.ts +43 -0
  5. package/packages/blob.ts +97 -0
  6. package/packages/chat/components/dialog.tsx +46 -0
  7. package/packages/chat/components/header/delete-dialog.tsx +48 -0
  8. package/packages/chat/components/header/menu.tsx +56 -0
  9. package/packages/chat/components/header/title.tsx +33 -0
  10. package/packages/chat/components/header/wrapper.tsx +12 -0
  11. package/packages/chat/components/input/index.tsx +52 -0
  12. package/packages/chat/components/input/menu.tsx +34 -0
  13. package/packages/chat/components/input/send.tsx +20 -0
  14. package/packages/chat/components/input/textarea.tsx +22 -0
  15. package/packages/chat/components/input/wrapper.tsx +11 -0
  16. package/packages/chat/components/layout.tsx +0 -0
  17. package/packages/chat/components/messages/index.tsx +4 -0
  18. package/packages/chat/components/messages/wrapper.tsx +21 -0
  19. package/packages/chat/components/settings/dialog.tsx +31 -0
  20. package/packages/chat/components/settings/model-selector.tsx +83 -0
  21. package/packages/chat/components/settings/temperature-slider.tsx +67 -0
  22. package/packages/dexie.ts +126 -0
  23. package/packages/env.ts +8 -0
  24. package/packages/fetch-interface.ts +75 -0
  25. package/packages/fields.tsx +169 -0
  26. package/packages/firebase.ts +13 -0
  27. package/packages/firestore.ts +51 -0
  28. package/packages/form.tsx +66 -0
  29. package/packages/hooks.tsx +123 -0
  30. package/packages/interface.ts +79 -0
  31. package/packages/message/components/edit.tsx +48 -0
  32. package/packages/message/components/menu.tsx +52 -0
  33. package/packages/message/components/message.tsx +41 -0
  34. package/packages/message/components/tool-results.tsx +32 -0
  35. package/packages/next-interface.ts +121 -0
  36. package/packages/next.ts +64 -0
  37. package/packages/novelai.ts +101 -0
  38. package/packages/openrouter.ts +4 -0
  39. package/packages/react-interface.tsx +369 -0
  40. package/packages/wretch.ts +22 -0
  41. package/packages/yaml.ts +163 -0
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "asasvirtuais",
3
- "version": "0.7.8",
3
+ "version": "0.7.9",
4
4
  "directories": {
5
5
  "packages": "./packages"
6
6
  },
7
7
  "files": [
8
- "dist",
8
+ "packages",
9
9
  "tsconfig.json"
10
10
  ],
11
11
  "exports": {
@@ -0,0 +1,189 @@
1
+ import wretch from 'wretch'
2
+ import QueryStringAddon from 'wretch/addons/queryString'
3
+
4
+ import { ratePerSec } from 'asasvirtuais/wretch'
5
+
6
+ // Usage and explanation: this file maps urls to wretch endpoints
7
+ // https://api.airtable.com/v0/meta/bases/{baseId}/tables
8
+ // wairtable(token).base(baseId).table(tableId).record(recordId).get().json()
9
+ // https://api.airtable.com/v0/meta/bases/{baseId}/tables
10
+ // wairtable(token).meta().bases().base(baseId).tables().get().json()
11
+ // wairtable(token).meta().bases().base(baseId).tables().table(tableId).fields().json(newField).post().json() // Object.assign allows accessing further endpoints with ease.
12
+ export function wairtable(token: string) {
13
+ const api = wretch('https://api.airtable.com/v0')
14
+ .middlewares([ratePerSec(5)])
15
+ .addon(QueryStringAddon)
16
+ .auth(`Bearer ${token}`)
17
+
18
+ return Object.assign(api, {
19
+ meta: () => {
20
+ const meta = api.url(`/meta`)
21
+
22
+ return Object.assign(meta, {
23
+ bases: () => {
24
+ const bases = api.url(`/meta/bases`)
25
+
26
+ return Object.assign(bases, {
27
+ base: (baseId: string) => {
28
+ const base = bases.url(`/${baseId}`)
29
+
30
+ return Object.assign(base, {
31
+ tables: () => {
32
+ const tables = base.url(`/tables`)
33
+
34
+ return Object.assign(tables, {
35
+ table: (tableId: string) => {
36
+ const table = tables.url(`/${tableId}`)
37
+
38
+ return Object.assign(table, {
39
+ fields: () => table.url(`/fields`),
40
+ field: (fieldId: string) => table.url(`/${fieldId}`),
41
+ })
42
+ },
43
+ })
44
+ },
45
+ })
46
+ },
47
+ })
48
+ },
49
+ })
50
+ },
51
+ base: (baseId: string) => {
52
+ const base = api.url(`/${baseId}`)
53
+
54
+ return Object.assign(base, {
55
+ table: (tableId: string) => {
56
+ const table = base.url(`/${encodeURIComponent(tableId)}`)
57
+
58
+ const record = (id: string) => table.url(`/${id}`)
59
+
60
+ // Add endpoints for records collection and single record
61
+ const records = () => table.url(`/records`)
62
+
63
+ return Object.assign(table, {
64
+ // List records: GET /records
65
+ records,
66
+ // Retrieve, update, delete a single record: /records/{id}
67
+ record,
68
+ fields: () => table.url(`/fields`),
69
+ })
70
+ },
71
+ })
72
+ },
73
+ })
74
+ }
75
+
76
+ import type {
77
+ DatabaseInterface,
78
+ Query,
79
+ TableInterface,
80
+ } from 'asasvirtuais/interface'
81
+ import z from 'zod'
82
+ import env from 'asasvirtuais/env'
83
+ import { Airtable } from './types'
84
+
85
+ // Convert Query to Airtable query format
86
+ function convertQuery<T>(query?: Query<T>): Record<string, any> {
87
+ if (!query) return {}
88
+
89
+ const airtableQuery: Record<string, any> = {}
90
+
91
+ // Handle filters
92
+ if (query.$limit) airtableQuery.maxRecords = query.$limit
93
+ if (query.$skip) airtableQuery.offset = query.$skip
94
+ if (query.$sort) {
95
+ const sortEntries = Object.entries(query.$sort)
96
+ if (sortEntries.length > 0) {
97
+ airtableQuery.sort = sortEntries.map(([field, direction]) => ({
98
+ field,
99
+ direction: direction === 1 ? 'asc' : 'desc'
100
+ }))
101
+ }
102
+ }
103
+ if (query.$select) {
104
+ airtableQuery.fields = query.$select
105
+ }
106
+
107
+ // Handle field filters - convert to Airtable formula format
108
+ const fieldFilters: string[] = []
109
+ Object.entries(query).forEach(([key, value]) => {
110
+ if (key.startsWith('$')) return // Skip special operators
111
+
112
+ if (typeof value === 'object' && value !== null) {
113
+ // Handle operators
114
+ if ('$ne' in value) fieldFilters.push(`{${key}} != '${value.$ne}'`)
115
+ if ('$in' in value && Array.isArray(value.$in)) {
116
+ fieldFilters.push(`OR(${value.$in.map(v => `{${key}} = '${v}'`).join(', ')})`)
117
+ }
118
+ if ('$nin' in value && Array.isArray(value.$nin)) {
119
+ fieldFilters.push(`NOT(OR(${value.$nin.map(v => `{${key}} = '${v}'`).join(', ')}))`)
120
+ }
121
+ if ('$lt' in value) fieldFilters.push(`{${key}} < ${value.$lt}`)
122
+ if ('$lte' in value) fieldFilters.push(`{${key}} <= ${value.$lte}`)
123
+ if ('$gt' in value) fieldFilters.push(`{${key}} > ${value.$gt}`)
124
+ if ('$gte' in value) fieldFilters.push(`{${key}} >= ${value.$gte}`)
125
+ } else {
126
+ // Direct equality
127
+ fieldFilters.push(`{${key}} = '${value}'`)
128
+ }
129
+ })
130
+
131
+ // Handle $or and $and
132
+ const queryAny = query as any
133
+ if (queryAny.$or) {
134
+ const orFilters = queryAny.$or.map((subQuery: Query<T>) => convertQuery(subQuery).filterByFormula).filter(Boolean)
135
+ if (orFilters.length > 0) {
136
+ fieldFilters.push(`OR(${orFilters.join(', ')})`)
137
+ }
138
+ }
139
+
140
+ if (queryAny.$and) {
141
+ const andFilters = queryAny.$and.map((subQuery: Query<T>) => convertQuery(subQuery).filterByFormula).filter(Boolean)
142
+ if (andFilters.length > 0) {
143
+ fieldFilters.push(`AND(${andFilters.join(', ')})`)
144
+ }
145
+ }
146
+
147
+ if (fieldFilters.length > 0) {
148
+ airtableQuery.filterByFormula = fieldFilters.length === 1 ? fieldFilters[0] : `AND(${fieldFilters.join(', ')})`
149
+ }
150
+
151
+ return airtableQuery
152
+ }
153
+
154
+ export default function airtable(apiKey?: string) {
155
+ if (!apiKey)
156
+ apiKey = env('AIRTABLE_TOKEN')
157
+
158
+ const api = wairtable(apiKey)
159
+
160
+ return {
161
+ api,
162
+ base<Schema extends DatabaseInterface>(baseId: string, schema: Schema) {
163
+ return {
164
+ interface<Table extends keyof Schema = keyof Schema>(defaultTable?: Table & string): TableInterface<z.infer<Schema[Table]['readable']>, z.infer<Schema[Table]['writable']>> {
165
+ type Readable = z.infer<Schema[Table]['readable']>
166
+ type Writable = z.infer<Schema[Table]['writable']>
167
+ const mapRecordToObject = (record: { id: string, fields: Airtable.RecordFieldsreadable }) => ({ id: record.id, ...record.fields }) as Readable
168
+ return {
169
+ async list({ table = defaultTable, query }) {
170
+ return api.base(baseId).table(table as string).query(convertQuery(query) ?? {}).get().json<{ records: Array<{ id: string, fields: Airtable.RecordFieldsreadable }> }>().then(({ records }) => records.map(mapRecordToObject))
171
+ },
172
+ async find({ table = defaultTable, id }) {
173
+ return api.base(baseId).table(table as string).record(id).get().json<{ id: string, fields: Airtable.RecordFieldsreadable }>().then(mapRecordToObject)
174
+ },
175
+ async create({ table = defaultTable, data }) {
176
+ return api.base(baseId).table(table as string).post({ fields: data }).json<{ id: string, fields: Airtable.RecordFieldsreadable }>().then(mapRecordToObject)
177
+ },
178
+ async update({ table = defaultTable, id, data }) {
179
+ return api.base(baseId).table(table as string).record(id).patch({ fields: data }).json<{ id: string, fields: Airtable.RecordFieldsreadable }>().then(mapRecordToObject)
180
+ },
181
+ async remove({ table = defaultTable, id }) {
182
+ return api.base(baseId).table(table as string).record(id).delete().json<{ id: string }>()
183
+ }
184
+ }
185
+ }
186
+ }
187
+ }
188
+ }
189
+ }