weave-typescript 0.51.3 → 0.53.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.
Files changed (185) hide show
  1. package/dist/google/protobuf/duration.pb.d.ts +99 -0
  2. package/dist/google/protobuf/duration.pb.js +93 -0
  3. package/dist/index.d.ts +1 -0
  4. package/dist/index.js +2 -1
  5. package/dist/weave/authz/v1/index.d.ts +1 -0
  6. package/dist/weave/authz/v1/index.js +38 -0
  7. package/dist/weave/authz/v1/options.pb.d.ts +52 -0
  8. package/dist/weave/authz/v1/options.pb.js +403 -0
  9. package/dist/weave/filter/v1/index.d.ts +1 -0
  10. package/dist/weave/filter/v1/index.js +38 -0
  11. package/dist/{weaveapi/atc/v1/message.pb.d.ts → weave/filter/v1/options.pb.d.ts} +33 -21
  12. package/dist/weave/filter/v1/options.pb.js +417 -0
  13. package/dist/weave/index.d.ts +2 -0
  14. package/dist/weave/index.js +39 -0
  15. package/dist/weaveapi/agent/v1/agent.pb.d.ts +137 -188
  16. package/dist/weaveapi/agent/v1/agent.pb.js +891 -2151
  17. package/dist/weaveapi/agent/v1/index.d.ts +1 -1
  18. package/dist/weaveapi/agent/v1/index.js +2 -2
  19. package/dist/weaveapi/agent/v1/run.pb.d.ts +289 -0
  20. package/dist/weaveapi/agent/v1/run.pb.js +2763 -0
  21. package/dist/weaveapi/auth/v1/auth.pb.d.ts +67 -14
  22. package/dist/weaveapi/auth/v1/auth.pb.js +829 -89
  23. package/dist/weaveapi/auth/v1/index.d.ts +4 -1
  24. package/dist/weaveapi/auth/v1/index.js +5 -2
  25. package/dist/weaveapi/auth/v1/{service.pb.d.ts → organization_admin.pb.d.ts} +39 -530
  26. package/dist/weaveapi/auth/v1/{service.pb.js → organization_admin.pb.js} +2978 -5812
  27. package/dist/weaveapi/auth/v1/personal_access_token.pb.d.ts +114 -0
  28. package/dist/weaveapi/auth/v1/personal_access_token.pb.js +750 -0
  29. package/dist/weaveapi/auth/v1/profile.pb.d.ts +161 -0
  30. package/dist/weaveapi/auth/v1/profile.pb.js +1007 -0
  31. package/dist/weaveapi/auth/v1/session.pb.d.ts +460 -0
  32. package/dist/weaveapi/auth/v1/session.pb.js +3544 -0
  33. package/dist/weaveapi/chat/v1/chat.pb.d.ts +377 -149
  34. package/dist/weaveapi/chat/v1/chat.pb.js +3492 -1614
  35. package/dist/weaveapi/chat/v1/index.d.ts +0 -1
  36. package/dist/weaveapi/chat/v1/index.js +1 -2
  37. package/dist/weaveapi/consolidation/v1/consolidation.pb.d.ts +95 -0
  38. package/dist/weaveapi/consolidation/v1/consolidation.pb.js +770 -1
  39. package/dist/weaveapi/consolidation/v1/index.d.ts +0 -1
  40. package/dist/weaveapi/consolidation/v1/index.js +1 -2
  41. package/dist/weaveapi/content/v1/content.pb.d.ts +63 -0
  42. package/dist/weaveapi/content/v1/content.pb.js +470 -0
  43. package/dist/weaveapi/content/v1/index.d.ts +1 -0
  44. package/dist/weaveapi/content/v1/index.js +38 -0
  45. package/dist/weaveapi/gateway/v1/gateway.pb.d.ts +247 -523
  46. package/dist/weaveapi/gateway/v1/gateway.pb.js +1648 -5783
  47. package/dist/weaveapi/gateway/v1/index.d.ts +0 -1
  48. package/dist/weaveapi/gateway/v1/index.js +1 -2
  49. package/dist/weaveapi/index.d.ts +5 -5
  50. package/dist/weaveapi/index.js +6 -6
  51. package/dist/weaveapi/inference/v1/generate.pb.d.ts +120 -0
  52. package/dist/weaveapi/inference/v1/generate.pb.js +1159 -0
  53. package/dist/weaveapi/inference/v1/index.d.ts +4 -0
  54. package/dist/weaveapi/{provider → inference}/v1/index.js +4 -2
  55. package/dist/weaveapi/{model → inference}/v1/model.pb.d.ts +54 -15
  56. package/dist/weaveapi/{model → inference}/v1/model.pb.js +573 -116
  57. package/dist/weaveapi/{model/v1/service.pb.d.ts → inference/v1/model_route.pb.d.ts} +184 -110
  58. package/dist/weaveapi/{model/v1/service.pb.js → inference/v1/model_route.pb.js} +2240 -1061
  59. package/dist/weaveapi/inference/v1/provider.pb.d.ts +264 -0
  60. package/dist/weaveapi/inference/v1/provider.pb.js +2590 -0
  61. package/dist/weaveapi/ingestion/v1/index.d.ts +0 -2
  62. package/dist/weaveapi/ingestion/v1/index.js +1 -3
  63. package/dist/weaveapi/ingestion/v1/ingestion.pb.d.ts +543 -0
  64. package/dist/weaveapi/ingestion/v1/ingestion.pb.js +5550 -16
  65. package/dist/weaveapi/initialization/v1/index.d.ts +1 -0
  66. package/dist/weaveapi/initialization/v1/index.js +38 -0
  67. package/dist/weaveapi/initialization/v1/initialization.pb.d.ts +99 -0
  68. package/dist/weaveapi/initialization/v1/initialization.pb.js +510 -0
  69. package/dist/weaveapi/organization/v1/index.d.ts +0 -1
  70. package/dist/weaveapi/organization/v1/index.js +1 -2
  71. package/dist/weaveapi/organization/v1/organization.pb.d.ts +241 -0
  72. package/dist/weaveapi/organization/v1/organization.pb.js +1838 -1
  73. package/dist/weaveapi/reporting/index.d.ts +1 -0
  74. package/dist/weaveapi/reporting/index.js +38 -0
  75. package/dist/weaveapi/{task → reporting}/v1/index.d.ts +1 -1
  76. package/dist/weaveapi/{model → reporting}/v1/index.js +2 -2
  77. package/dist/weaveapi/reporting/v1/service.pb.d.ts +38 -0
  78. package/dist/weaveapi/reporting/v1/service.pb.js +167 -0
  79. package/dist/weaveapi/reporting/v1/usage.pb.d.ts +150 -0
  80. package/dist/weaveapi/reporting/v1/usage.pb.js +1837 -0
  81. package/dist/weaveapi/retrieval/v1/index.d.ts +0 -1
  82. package/dist/weaveapi/retrieval/v1/index.js +1 -2
  83. package/dist/weaveapi/retrieval/v1/retrieval.pb.d.ts +96 -2
  84. package/dist/weaveapi/retrieval/v1/retrieval.pb.js +690 -10
  85. package/dist/weaveapi/tool/index.d.ts +1 -0
  86. package/dist/weaveapi/tool/index.js +38 -0
  87. package/dist/weaveapi/tool/v1/index.d.ts +1 -0
  88. package/dist/weaveapi/tool/v1/index.js +38 -0
  89. package/dist/weaveapi/tool/v1/tool.pb.d.ts +370 -0
  90. package/dist/weaveapi/tool/v1/tool.pb.js +2717 -0
  91. package/dist/weaveapi/workflow/v1/index.d.ts +1 -1
  92. package/dist/weaveapi/workflow/v1/index.js +2 -2
  93. package/dist/weaveapi/workflow/v1/run.pb.d.ts +244 -0
  94. package/dist/weaveapi/workflow/v1/run.pb.js +2084 -0
  95. package/dist/weaveapi/workflow/v1/workflow.pb.d.ts +122 -275
  96. package/dist/weaveapi/workflow/v1/workflow.pb.js +790 -3261
  97. package/dist/weavesql/weavedb/agent_sql.d.ts +173 -477
  98. package/dist/weavesql/weavedb/agent_sql.js +281 -758
  99. package/dist/weavesql/weavedb/authorization_outbox_sql.d.ts +261 -0
  100. package/dist/weavesql/weavedb/authorization_outbox_sql.js +445 -0
  101. package/dist/weavesql/weavedb/chat_sql.d.ts +103 -345
  102. package/dist/weavesql/weavedb/chat_sql.js +312 -597
  103. package/dist/weavesql/weavedb/document_consolidation_sql.d.ts +217 -0
  104. package/dist/weavesql/weavedb/document_consolidation_sql.js +486 -0
  105. package/dist/weavesql/weavedb/document_ingestion_sql.d.ts +1433 -0
  106. package/dist/weavesql/weavedb/document_ingestion_sql.js +3488 -0
  107. package/dist/weavesql/weavedb/document_retrieval_sql.d.ts +314 -0
  108. package/dist/weavesql/weavedb/document_retrieval_sql.js +965 -0
  109. package/dist/weavesql/weavedb/document_table_sql.d.ts +6 -6
  110. package/dist/weavesql/weavedb/document_table_sql.js +12 -12
  111. package/dist/weavesql/weavedb/identity_sql.d.ts +1021 -0
  112. package/dist/weavesql/weavedb/identity_sql.js +1818 -0
  113. package/dist/weavesql/weavedb/inference_model_route_sql.d.ts +167 -0
  114. package/dist/weavesql/weavedb/inference_model_route_sql.js +483 -0
  115. package/dist/weavesql/weavedb/inference_provider_sql.d.ts +125 -0
  116. package/dist/weavesql/weavedb/inference_provider_sql.js +228 -0
  117. package/dist/weavesql/weavedb/initialization_sql.d.ts +15 -0
  118. package/dist/weavesql/weavedb/initialization_sql.js +33 -0
  119. package/dist/weavesql/weavedb/model_catalog_sql.d.ts +6 -6
  120. package/dist/weavesql/weavedb/model_catalog_sql.js +6 -6
  121. package/dist/weavesql/weavedb/organization_sql.d.ts +24 -102
  122. package/dist/weavesql/weavedb/organization_sql.js +56 -262
  123. package/dist/weavesql/weavedb/tool_sql.d.ts +209 -0
  124. package/dist/weavesql/weavedb/tool_sql.js +407 -0
  125. package/dist/weavesql/weavedb/usage_sql.d.ts +356 -0
  126. package/dist/weavesql/weavedb/usage_sql.js +568 -0
  127. package/dist/weavesql/weavedb/workflow_sql.d.ts +159 -546
  128. package/dist/weavesql/weavedb/workflow_sql.js +281 -909
  129. package/package.json +1 -1
  130. package/dist/weaveapi/agent/v1/service.pb.d.ts +0 -397
  131. package/dist/weaveapi/agent/v1/service.pb.js +0 -3152
  132. package/dist/weaveapi/atc/v1/event.pb.d.ts +0 -134
  133. package/dist/weaveapi/atc/v1/event.pb.js +0 -1124
  134. package/dist/weaveapi/atc/v1/index.d.ts +0 -5
  135. package/dist/weaveapi/atc/v1/index.js +0 -42
  136. package/dist/weaveapi/atc/v1/message.pb.js +0 -287
  137. package/dist/weaveapi/atc/v1/process.pb.d.ts +0 -91
  138. package/dist/weaveapi/atc/v1/process.pb.js +0 -658
  139. package/dist/weaveapi/atc/v1/run.pb.d.ts +0 -71
  140. package/dist/weaveapi/atc/v1/run.pb.js +0 -525
  141. package/dist/weaveapi/atc/v1/service.pb.d.ts +0 -472
  142. package/dist/weaveapi/atc/v1/service.pb.js +0 -3093
  143. package/dist/weaveapi/chat/v1/service.pb.d.ts +0 -345
  144. package/dist/weaveapi/chat/v1/service.pb.js +0 -2545
  145. package/dist/weaveapi/consolidation/v1/service.pb.d.ts +0 -93
  146. package/dist/weaveapi/consolidation/v1/service.pb.js +0 -427
  147. package/dist/weaveapi/gateway/v1/service.pb.d.ts +0 -235
  148. package/dist/weaveapi/gateway/v1/service.pb.js +0 -651
  149. package/dist/weaveapi/ingestion/v1/service.pb.d.ts +0 -420
  150. package/dist/weaveapi/ingestion/v1/service.pb.js +0 -2311
  151. package/dist/weaveapi/ingestion/v1/table.pb.d.ts +0 -121
  152. package/dist/weaveapi/ingestion/v1/table.pb.js +0 -1478
  153. package/dist/weaveapi/model/v1/index.d.ts +0 -2
  154. package/dist/weaveapi/organization/v1/service.pb.d.ts +0 -261
  155. package/dist/weaveapi/organization/v1/service.pb.js +0 -1561
  156. package/dist/weaveapi/project/v1/index.d.ts +0 -2
  157. package/dist/weaveapi/project/v1/index.js +0 -39
  158. package/dist/weaveapi/project/v1/project.pb.d.ts +0 -105
  159. package/dist/weaveapi/project/v1/project.pb.js +0 -1004
  160. package/dist/weaveapi/project/v1/service.pb.d.ts +0 -247
  161. package/dist/weaveapi/project/v1/service.pb.js +0 -1994
  162. package/dist/weaveapi/provider/v1/index.d.ts +0 -2
  163. package/dist/weaveapi/provider/v1/provider.pb.d.ts +0 -137
  164. package/dist/weaveapi/provider/v1/provider.pb.js +0 -1000
  165. package/dist/weaveapi/provider/v1/service.pb.d.ts +0 -223
  166. package/dist/weaveapi/provider/v1/service.pb.js +0 -1888
  167. package/dist/weaveapi/retrieval/v1/service.pb.d.ts +0 -93
  168. package/dist/weaveapi/retrieval/v1/service.pb.js +0 -385
  169. package/dist/weaveapi/task/v1/index.js +0 -39
  170. package/dist/weaveapi/task/v1/service.pb.d.ts +0 -172
  171. package/dist/weaveapi/task/v1/service.pb.js +0 -1436
  172. package/dist/weaveapi/task/v1/task.pb.d.ts +0 -85
  173. package/dist/weaveapi/task/v1/task.pb.js +0 -802
  174. package/dist/weaveapi/workflow/v1/service.pb.d.ts +0 -392
  175. package/dist/weaveapi/workflow/v1/service.pb.js +0 -3146
  176. /package/dist/{weaveapi/atc → weave/authz}/index.d.ts +0 -0
  177. /package/dist/{weaveapi/atc → weave/authz}/index.js +0 -0
  178. /package/dist/{weaveapi/model → weave/filter}/index.d.ts +0 -0
  179. /package/dist/{weaveapi/model → weave/filter}/index.js +0 -0
  180. /package/dist/weaveapi/{project → content}/index.d.ts +0 -0
  181. /package/dist/weaveapi/{project → content}/index.js +0 -0
  182. /package/dist/weaveapi/{provider → inference}/index.d.ts +0 -0
  183. /package/dist/weaveapi/{provider → inference}/index.js +0 -0
  184. /package/dist/weaveapi/{task → initialization}/index.d.ts +0 -0
  185. /package/dist/weaveapi/{task → initialization}/index.js +0 -0
@@ -0,0 +1,167 @@
1
+ import { QueryArrayConfig, QueryArrayResult } from "pg";
2
+ interface Client {
3
+ query: (config: QueryArrayConfig) => Promise<QueryArrayResult>;
4
+ }
5
+ export declare const upsertInferenceModelQuery = "-- name: UpsertInferenceModel :one\nWITH inserted AS (\n INSERT INTO weave.inference_model (\n organization_id,\n model_id\n ) VALUES (\n $1,\n $2\n )\n ON CONFLICT (organization_id, model_id) DO NOTHING\n RETURNING\n id,\n organization_id,\n model_id,\n created_at,\n updated_at,\n true::boolean AS created\n)\nSELECT\n id,\n organization_id,\n model_id,\n created_at,\n updated_at,\n created\nFROM inserted\nUNION ALL\nSELECT\n im.id,\n im.organization_id,\n im.model_id,\n im.created_at,\n im.updated_at,\n false::boolean AS created\nFROM weave.inference_model im\nWHERE im.organization_id = $1\n AND im.model_id = $2\n AND NOT EXISTS (SELECT 1 FROM inserted)\nLIMIT 1";
6
+ export interface UpsertInferenceModelArgs {
7
+ organizationId: string;
8
+ modelId: string;
9
+ }
10
+ export interface UpsertInferenceModelRow {
11
+ id: string;
12
+ organizationId: string;
13
+ modelId: string;
14
+ createdAt: Date;
15
+ updatedAt: Date;
16
+ created: boolean;
17
+ }
18
+ export declare function upsertInferenceModel(client: Client, args: UpsertInferenceModelArgs): Promise<UpsertInferenceModelRow | null>;
19
+ export declare const getInferenceModelByModelIDQuery = "-- name: GetInferenceModelByModelID :one\nSELECT id, organization_id, model_id, created_at, updated_at\nFROM weave.inference_model\nWHERE organization_id = $1\n AND model_id = $2";
20
+ export interface GetInferenceModelByModelIDArgs {
21
+ organizationId: string;
22
+ modelId: string;
23
+ }
24
+ export interface GetInferenceModelByModelIDRow {
25
+ id: string;
26
+ organizationId: string;
27
+ modelId: string;
28
+ createdAt: Date;
29
+ updatedAt: Date;
30
+ }
31
+ export declare function getInferenceModelByModelID(client: Client, args: GetInferenceModelByModelIDArgs): Promise<GetInferenceModelByModelIDRow | null>;
32
+ export declare const createInferenceModelRouteQuery = "-- name: CreateInferenceModelRoute :one\nWITH created AS (\n INSERT INTO weave.inference_model_route (\n organization_id,\n inference_model_id,\n inference_provider_configuration_id,\n provider_model_id,\n priority\n ) VALUES (\n $1,\n $2,\n $3,\n $4,\n COALESCE($5::integer, 100)\n )\n RETURNING id, organization_id, inference_model_id, inference_provider_configuration_id, provider_model_id, priority, created_at, updated_at\n)\nSELECT\n r.id,\n r.organization_id,\n r.inference_model_id,\n im.model_id,\n r.inference_provider_configuration_id,\n r.provider_model_id,\n r.priority,\n r.created_at,\n r.updated_at\nFROM created r\n JOIN weave.inference_model im\n ON im.organization_id = r.organization_id\n AND im.id = r.inference_model_id";
33
+ export interface CreateInferenceModelRouteArgs {
34
+ organizationId: string;
35
+ inferenceModelId: string;
36
+ inferenceProviderConfigurationId: string;
37
+ providerModelId: string;
38
+ priority: number | null;
39
+ }
40
+ export interface CreateInferenceModelRouteRow {
41
+ id: string;
42
+ organizationId: string;
43
+ inferenceModelId: string;
44
+ modelId: string;
45
+ inferenceProviderConfigurationId: string;
46
+ providerModelId: string;
47
+ priority: number;
48
+ createdAt: Date;
49
+ updatedAt: Date;
50
+ }
51
+ export declare function createInferenceModelRoute(client: Client, args: CreateInferenceModelRouteArgs): Promise<CreateInferenceModelRouteRow | null>;
52
+ export declare const getInferenceModelRouteQuery = "-- name: GetInferenceModelRoute :one\nSELECT\n r.id,\n r.organization_id,\n r.inference_model_id,\n im.model_id,\n r.inference_provider_configuration_id,\n r.provider_model_id,\n r.priority,\n r.created_at,\n r.updated_at\nFROM weave.inference_model_route r\n JOIN weave.inference_model im\n ON im.organization_id = r.organization_id\n AND im.id = r.inference_model_id\nWHERE r.organization_id = $1\n AND r.id = $2";
53
+ export interface GetInferenceModelRouteArgs {
54
+ organizationId: string;
55
+ inferenceModelRouteId: string;
56
+ }
57
+ export interface GetInferenceModelRouteRow {
58
+ id: string;
59
+ organizationId: string;
60
+ inferenceModelId: string;
61
+ modelId: string;
62
+ inferenceProviderConfigurationId: string;
63
+ providerModelId: string;
64
+ priority: number;
65
+ createdAt: Date;
66
+ updatedAt: Date;
67
+ }
68
+ export declare function getInferenceModelRoute(client: Client, args: GetInferenceModelRouteArgs): Promise<GetInferenceModelRouteRow | null>;
69
+ export declare const updateInferenceModelRouteQuery = "-- name: UpdateInferenceModelRoute :one\nWITH updated AS (\n UPDATE weave.inference_model_route\n SET inference_model_id = $1,\n inference_provider_configuration_id = $2,\n provider_model_id = $3,\n priority = $4\n WHERE weave.inference_model_route.organization_id = $5\n AND weave.inference_model_route.id = $6\n RETURNING id, organization_id, inference_model_id, inference_provider_configuration_id, provider_model_id, priority, created_at, updated_at\n)\nSELECT\n r.id,\n r.organization_id,\n r.inference_model_id,\n im.model_id,\n r.inference_provider_configuration_id,\n r.provider_model_id,\n r.priority,\n r.created_at,\n r.updated_at\nFROM updated r\n JOIN weave.inference_model im\n ON im.organization_id = r.organization_id\n AND im.id = r.inference_model_id";
70
+ export interface UpdateInferenceModelRouteArgs {
71
+ inferenceModelId: string;
72
+ inferenceProviderConfigurationId: string;
73
+ providerModelId: string;
74
+ priority: number;
75
+ organizationId: string;
76
+ inferenceModelRouteId: string;
77
+ }
78
+ export interface UpdateInferenceModelRouteRow {
79
+ id: string;
80
+ organizationId: string;
81
+ inferenceModelId: string;
82
+ modelId: string;
83
+ inferenceProviderConfigurationId: string;
84
+ providerModelId: string;
85
+ priority: number;
86
+ createdAt: Date;
87
+ updatedAt: Date;
88
+ }
89
+ export declare function updateInferenceModelRoute(client: Client, args: UpdateInferenceModelRouteArgs): Promise<UpdateInferenceModelRouteRow | null>;
90
+ export declare const deleteInferenceModelRouteQuery = "-- name: DeleteInferenceModelRoute :exec\nDELETE FROM weave.inference_model_route\nWHERE organization_id = $1\n AND id = $2";
91
+ export interface DeleteInferenceModelRouteArgs {
92
+ organizationId: string;
93
+ inferenceModelRouteId: string;
94
+ }
95
+ export declare function deleteInferenceModelRoute(client: Client, args: DeleteInferenceModelRouteArgs): Promise<void>;
96
+ export declare const listInferenceModelRoutesQuery = "-- name: ListInferenceModelRoutes :many\nSELECT\n r.id,\n r.organization_id,\n r.inference_model_id,\n im.model_id,\n r.inference_provider_configuration_id,\n r.provider_model_id,\n r.priority,\n r.created_at,\n r.updated_at\nFROM weave.inference_model_route r\n JOIN weave.inference_model im\n ON im.organization_id = r.organization_id\n AND im.id = r.inference_model_id\nWHERE r.organization_id = $1\n AND ($2::text IS NULL OR im.model_id = $2::text)\nORDER BY im.model_id ASC, r.priority ASC, r.id ASC\nLIMIT COALESCE($4::integer, 100)\nOFFSET COALESCE($3::integer, 0)";
97
+ export interface ListInferenceModelRoutesArgs {
98
+ organizationId: string;
99
+ modelId: string | null;
100
+ pageOffset: number | null;
101
+ pageSize: number | null;
102
+ }
103
+ export interface ListInferenceModelRoutesRow {
104
+ id: string;
105
+ organizationId: string;
106
+ inferenceModelId: string;
107
+ modelId: string;
108
+ inferenceProviderConfigurationId: string;
109
+ providerModelId: string;
110
+ priority: number;
111
+ createdAt: Date;
112
+ updatedAt: Date;
113
+ }
114
+ export declare function listInferenceModelRoutes(client: Client, args: ListInferenceModelRoutesArgs): Promise<ListInferenceModelRoutesRow[]>;
115
+ export declare const getOrganizationChatSettingsQuery = "-- name: GetOrganizationChatSettings :one\nSELECT\n o.id AS organization_id,\n chat_im.model_id AS default_chat_model_id,\n chat_r.inference_provider_configuration_id AS default_provider_configuration_id,\n fast_im.model_id AS default_fast_model_id,\n fast_r.inference_provider_configuration_id AS default_fast_provider_configuration_id\nFROM weave.organization o\n LEFT JOIN weave.inference_model_route chat_r\n ON chat_r.organization_id = o.id\n AND chat_r.id = o.default_chat_model_route_id\n LEFT JOIN weave.inference_model chat_im\n ON chat_im.organization_id = chat_r.organization_id\n AND chat_im.id = chat_r.inference_model_id\n LEFT JOIN weave.inference_model_route fast_r\n ON fast_r.organization_id = o.id\n AND fast_r.id = o.default_fast_model_route_id\n LEFT JOIN weave.inference_model fast_im\n ON fast_im.organization_id = fast_r.organization_id\n AND fast_im.id = fast_r.inference_model_id\nWHERE o.id = $1";
116
+ export interface GetOrganizationChatSettingsArgs {
117
+ organizationId: string;
118
+ }
119
+ export interface GetOrganizationChatSettingsRow {
120
+ organizationId: string;
121
+ defaultChatModelId: string | null;
122
+ defaultProviderConfigurationId: string | null;
123
+ defaultFastModelId: string | null;
124
+ defaultFastProviderConfigurationId: string | null;
125
+ }
126
+ export declare function getOrganizationChatSettings(client: Client, args: GetOrganizationChatSettingsArgs): Promise<GetOrganizationChatSettingsRow | null>;
127
+ export declare const setOrganizationChatSettingsQuery = "-- name: SetOrganizationChatSettings :one\nWITH requested_defaults AS (\n SELECT\n $1::uuid AS organization_id,\n $2::text AS default_chat_model_id,\n $3::uuid AS default_provider_configuration_id,\n $4::text AS default_fast_model_id,\n $5::uuid AS default_fast_provider_configuration_id\n),\nselected_chat_route AS (\n SELECT\n r.id,\n requested_defaults.organization_id,\n requested_defaults.default_chat_model_id,\n requested_defaults.default_provider_configuration_id,\n requested_defaults.default_fast_model_id,\n requested_defaults.default_fast_provider_configuration_id\n FROM requested_defaults\n JOIN weave.inference_model_route r\n ON r.organization_id = requested_defaults.organization_id\n JOIN weave.inference_model im\n ON im.organization_id = r.organization_id\n AND im.id = r.inference_model_id\n WHERE im.model_id = requested_defaults.default_chat_model_id\n AND r.inference_provider_configuration_id =\n requested_defaults.default_provider_configuration_id\n),\nselected_fast_route AS (\n SELECT r.id\n FROM requested_defaults\n JOIN weave.inference_model_route r\n ON r.organization_id = requested_defaults.organization_id\n JOIN weave.inference_model im\n ON im.organization_id = r.organization_id\n AND im.id = r.inference_model_id\n WHERE requested_defaults.default_fast_model_id IS NOT NULL\n AND requested_defaults.default_fast_provider_configuration_id IS NOT NULL\n AND im.model_id = requested_defaults.default_fast_model_id\n AND r.inference_provider_configuration_id =\n requested_defaults.default_fast_provider_configuration_id\n),\nupdated_organization AS (\n UPDATE weave.organization o\n SET default_chat_model_route_id = selected_chat_route.id,\n default_fast_model_route_id = COALESCE(\n selected_fast_route.id,\n o.default_fast_model_route_id\n )\n FROM selected_chat_route\n LEFT JOIN selected_fast_route ON TRUE\n WHERE o.id = selected_chat_route.organization_id\n AND (\n (\n selected_chat_route.default_fast_model_id IS NULL\n AND selected_chat_route.default_fast_provider_configuration_id IS NULL\n )\n OR selected_fast_route.id IS NOT NULL\n )\n RETURNING\n o.id AS organization_id,\n o.default_chat_model_route_id,\n o.default_fast_model_route_id\n)\nSELECT\n updated_organization.organization_id,\n chat_im.model_id AS default_chat_model_id,\n chat_r.inference_provider_configuration_id AS default_provider_configuration_id,\n fast_im.model_id AS default_fast_model_id,\n fast_r.inference_provider_configuration_id AS default_fast_provider_configuration_id\nFROM updated_organization\n JOIN weave.inference_model_route chat_r\n ON chat_r.organization_id = updated_organization.organization_id\n AND chat_r.id = updated_organization.default_chat_model_route_id\n JOIN weave.inference_model chat_im\n ON chat_im.organization_id = chat_r.organization_id\n AND chat_im.id = chat_r.inference_model_id\n LEFT JOIN weave.inference_model_route fast_r\n ON fast_r.organization_id = updated_organization.organization_id\n AND fast_r.id = updated_organization.default_fast_model_route_id\n LEFT JOIN weave.inference_model fast_im\n ON fast_im.organization_id = fast_r.organization_id\n AND fast_im.id = fast_r.inference_model_id";
128
+ export interface SetOrganizationChatSettingsArgs {
129
+ organizationId: string;
130
+ defaultChatModelId: string;
131
+ defaultProviderConfigurationId: string;
132
+ defaultFastModelId: string | null;
133
+ defaultFastProviderConfigurationId: string | null;
134
+ }
135
+ export interface SetOrganizationChatSettingsRow {
136
+ organizationId: string;
137
+ defaultChatModelId: string;
138
+ defaultProviderConfigurationId: string;
139
+ defaultFastModelId: string | null;
140
+ defaultFastProviderConfigurationId: string | null;
141
+ }
142
+ export declare function setOrganizationChatSettings(client: Client, args: SetOrganizationChatSettingsArgs): Promise<SetOrganizationChatSettingsRow | null>;
143
+ export declare const getModelRuntimeConfigurationQuery = "-- name: GetModelRuntimeConfiguration :one\nSELECT\n imr.id AS inference_model_route_id,\n imr.organization_id,\n im.id AS inference_model_id,\n im.model_id,\n imr.provider_model_id,\n imr.priority,\n p.id AS inference_provider_configuration_id,\n p.kind AS provider_kind,\n p.name AS provider_name,\n p.slug AS provider_slug,\n p.base_url AS provider_base_url,\n c.credential_kind,\n c.encrypted_credentials,\n c.credential_hint,\n c.key_id,\n c.last_rotated_at\nFROM weave.inference_model_route imr\n JOIN weave.inference_model im\n ON im.organization_id = imr.organization_id\n AND im.id = imr.inference_model_id\n JOIN weave.inference_provider_configuration p\n ON p.organization_id = imr.organization_id\n AND p.id = imr.inference_provider_configuration_id\n JOIN weave.inference_provider_credential c\n ON c.inference_provider_configuration_id = p.id\nWHERE imr.organization_id = $1\n AND im.model_id = $2\nORDER BY imr.priority ASC\nLIMIT 1";
144
+ export interface GetModelRuntimeConfigurationArgs {
145
+ organizationId: string;
146
+ modelId: string;
147
+ }
148
+ export interface GetModelRuntimeConfigurationRow {
149
+ inferenceModelRouteId: string;
150
+ organizationId: string;
151
+ inferenceModelId: string;
152
+ modelId: string;
153
+ providerModelId: string;
154
+ priority: number;
155
+ inferenceProviderConfigurationId: string;
156
+ providerKind: string;
157
+ providerName: string;
158
+ providerSlug: string;
159
+ providerBaseUrl: string | null;
160
+ credentialKind: string;
161
+ encryptedCredentials: Buffer;
162
+ credentialHint: string;
163
+ keyId: string;
164
+ lastRotatedAt: Date;
165
+ }
166
+ export declare function getModelRuntimeConfiguration(client: Client, args: GetModelRuntimeConfigurationArgs): Promise<GetModelRuntimeConfigurationRow | null>;
167
+ export {};
@@ -0,0 +1,483 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getModelRuntimeConfigurationQuery = exports.setOrganizationChatSettingsQuery = exports.getOrganizationChatSettingsQuery = exports.listInferenceModelRoutesQuery = exports.deleteInferenceModelRouteQuery = exports.updateInferenceModelRouteQuery = exports.getInferenceModelRouteQuery = exports.createInferenceModelRouteQuery = exports.getInferenceModelByModelIDQuery = exports.upsertInferenceModelQuery = void 0;
4
+ exports.upsertInferenceModel = upsertInferenceModel;
5
+ exports.getInferenceModelByModelID = getInferenceModelByModelID;
6
+ exports.createInferenceModelRoute = createInferenceModelRoute;
7
+ exports.getInferenceModelRoute = getInferenceModelRoute;
8
+ exports.updateInferenceModelRoute = updateInferenceModelRoute;
9
+ exports.deleteInferenceModelRoute = deleteInferenceModelRoute;
10
+ exports.listInferenceModelRoutes = listInferenceModelRoutes;
11
+ exports.getOrganizationChatSettings = getOrganizationChatSettings;
12
+ exports.setOrganizationChatSettings = setOrganizationChatSettings;
13
+ exports.getModelRuntimeConfiguration = getModelRuntimeConfiguration;
14
+ exports.upsertInferenceModelQuery = `-- name: UpsertInferenceModel :one
15
+ WITH inserted AS (
16
+ INSERT INTO weave.inference_model (
17
+ organization_id,
18
+ model_id
19
+ ) VALUES (
20
+ $1,
21
+ $2
22
+ )
23
+ ON CONFLICT (organization_id, model_id) DO NOTHING
24
+ RETURNING
25
+ id,
26
+ organization_id,
27
+ model_id,
28
+ created_at,
29
+ updated_at,
30
+ true::boolean AS created
31
+ )
32
+ SELECT
33
+ id,
34
+ organization_id,
35
+ model_id,
36
+ created_at,
37
+ updated_at,
38
+ created
39
+ FROM inserted
40
+ UNION ALL
41
+ SELECT
42
+ im.id,
43
+ im.organization_id,
44
+ im.model_id,
45
+ im.created_at,
46
+ im.updated_at,
47
+ false::boolean AS created
48
+ FROM weave.inference_model im
49
+ WHERE im.organization_id = $1
50
+ AND im.model_id = $2
51
+ AND NOT EXISTS (SELECT 1 FROM inserted)
52
+ LIMIT 1`;
53
+ async function upsertInferenceModel(client, args) {
54
+ const result = await client.query({
55
+ text: exports.upsertInferenceModelQuery,
56
+ values: [args.organizationId, args.modelId],
57
+ rowMode: "array"
58
+ });
59
+ if (result.rows.length !== 1) {
60
+ return null;
61
+ }
62
+ const row = result.rows[0];
63
+ return {
64
+ id: row[0],
65
+ organizationId: row[1],
66
+ modelId: row[2],
67
+ createdAt: row[3],
68
+ updatedAt: row[4],
69
+ created: row[5]
70
+ };
71
+ }
72
+ exports.getInferenceModelByModelIDQuery = `-- name: GetInferenceModelByModelID :one
73
+ SELECT id, organization_id, model_id, created_at, updated_at
74
+ FROM weave.inference_model
75
+ WHERE organization_id = $1
76
+ AND model_id = $2`;
77
+ async function getInferenceModelByModelID(client, args) {
78
+ const result = await client.query({
79
+ text: exports.getInferenceModelByModelIDQuery,
80
+ values: [args.organizationId, args.modelId],
81
+ rowMode: "array"
82
+ });
83
+ if (result.rows.length !== 1) {
84
+ return null;
85
+ }
86
+ const row = result.rows[0];
87
+ return {
88
+ id: row[0],
89
+ organizationId: row[1],
90
+ modelId: row[2],
91
+ createdAt: row[3],
92
+ updatedAt: row[4]
93
+ };
94
+ }
95
+ exports.createInferenceModelRouteQuery = `-- name: CreateInferenceModelRoute :one
96
+ WITH created AS (
97
+ INSERT INTO weave.inference_model_route (
98
+ organization_id,
99
+ inference_model_id,
100
+ inference_provider_configuration_id,
101
+ provider_model_id,
102
+ priority
103
+ ) VALUES (
104
+ $1,
105
+ $2,
106
+ $3,
107
+ $4,
108
+ COALESCE($5::integer, 100)
109
+ )
110
+ RETURNING id, organization_id, inference_model_id, inference_provider_configuration_id, provider_model_id, priority, created_at, updated_at
111
+ )
112
+ SELECT
113
+ r.id,
114
+ r.organization_id,
115
+ r.inference_model_id,
116
+ im.model_id,
117
+ r.inference_provider_configuration_id,
118
+ r.provider_model_id,
119
+ r.priority,
120
+ r.created_at,
121
+ r.updated_at
122
+ FROM created r
123
+ JOIN weave.inference_model im
124
+ ON im.organization_id = r.organization_id
125
+ AND im.id = r.inference_model_id`;
126
+ async function createInferenceModelRoute(client, args) {
127
+ const result = await client.query({
128
+ text: exports.createInferenceModelRouteQuery,
129
+ values: [args.organizationId, args.inferenceModelId, args.inferenceProviderConfigurationId, args.providerModelId, args.priority],
130
+ rowMode: "array"
131
+ });
132
+ if (result.rows.length !== 1) {
133
+ return null;
134
+ }
135
+ const row = result.rows[0];
136
+ return {
137
+ id: row[0],
138
+ organizationId: row[1],
139
+ inferenceModelId: row[2],
140
+ modelId: row[3],
141
+ inferenceProviderConfigurationId: row[4],
142
+ providerModelId: row[5],
143
+ priority: row[6],
144
+ createdAt: row[7],
145
+ updatedAt: row[8]
146
+ };
147
+ }
148
+ exports.getInferenceModelRouteQuery = `-- name: GetInferenceModelRoute :one
149
+ SELECT
150
+ r.id,
151
+ r.organization_id,
152
+ r.inference_model_id,
153
+ im.model_id,
154
+ r.inference_provider_configuration_id,
155
+ r.provider_model_id,
156
+ r.priority,
157
+ r.created_at,
158
+ r.updated_at
159
+ FROM weave.inference_model_route r
160
+ JOIN weave.inference_model im
161
+ ON im.organization_id = r.organization_id
162
+ AND im.id = r.inference_model_id
163
+ WHERE r.organization_id = $1
164
+ AND r.id = $2`;
165
+ async function getInferenceModelRoute(client, args) {
166
+ const result = await client.query({
167
+ text: exports.getInferenceModelRouteQuery,
168
+ values: [args.organizationId, args.inferenceModelRouteId],
169
+ rowMode: "array"
170
+ });
171
+ if (result.rows.length !== 1) {
172
+ return null;
173
+ }
174
+ const row = result.rows[0];
175
+ return {
176
+ id: row[0],
177
+ organizationId: row[1],
178
+ inferenceModelId: row[2],
179
+ modelId: row[3],
180
+ inferenceProviderConfigurationId: row[4],
181
+ providerModelId: row[5],
182
+ priority: row[6],
183
+ createdAt: row[7],
184
+ updatedAt: row[8]
185
+ };
186
+ }
187
+ exports.updateInferenceModelRouteQuery = `-- name: UpdateInferenceModelRoute :one
188
+ WITH updated AS (
189
+ UPDATE weave.inference_model_route
190
+ SET inference_model_id = $1,
191
+ inference_provider_configuration_id = $2,
192
+ provider_model_id = $3,
193
+ priority = $4
194
+ WHERE weave.inference_model_route.organization_id = $5
195
+ AND weave.inference_model_route.id = $6
196
+ RETURNING id, organization_id, inference_model_id, inference_provider_configuration_id, provider_model_id, priority, created_at, updated_at
197
+ )
198
+ SELECT
199
+ r.id,
200
+ r.organization_id,
201
+ r.inference_model_id,
202
+ im.model_id,
203
+ r.inference_provider_configuration_id,
204
+ r.provider_model_id,
205
+ r.priority,
206
+ r.created_at,
207
+ r.updated_at
208
+ FROM updated r
209
+ JOIN weave.inference_model im
210
+ ON im.organization_id = r.organization_id
211
+ AND im.id = r.inference_model_id`;
212
+ async function updateInferenceModelRoute(client, args) {
213
+ const result = await client.query({
214
+ text: exports.updateInferenceModelRouteQuery,
215
+ values: [args.inferenceModelId, args.inferenceProviderConfigurationId, args.providerModelId, args.priority, args.organizationId, args.inferenceModelRouteId],
216
+ rowMode: "array"
217
+ });
218
+ if (result.rows.length !== 1) {
219
+ return null;
220
+ }
221
+ const row = result.rows[0];
222
+ return {
223
+ id: row[0],
224
+ organizationId: row[1],
225
+ inferenceModelId: row[2],
226
+ modelId: row[3],
227
+ inferenceProviderConfigurationId: row[4],
228
+ providerModelId: row[5],
229
+ priority: row[6],
230
+ createdAt: row[7],
231
+ updatedAt: row[8]
232
+ };
233
+ }
234
+ exports.deleteInferenceModelRouteQuery = `-- name: DeleteInferenceModelRoute :exec
235
+ DELETE FROM weave.inference_model_route
236
+ WHERE organization_id = $1
237
+ AND id = $2`;
238
+ async function deleteInferenceModelRoute(client, args) {
239
+ await client.query({
240
+ text: exports.deleteInferenceModelRouteQuery,
241
+ values: [args.organizationId, args.inferenceModelRouteId],
242
+ rowMode: "array"
243
+ });
244
+ }
245
+ exports.listInferenceModelRoutesQuery = `-- name: ListInferenceModelRoutes :many
246
+ SELECT
247
+ r.id,
248
+ r.organization_id,
249
+ r.inference_model_id,
250
+ im.model_id,
251
+ r.inference_provider_configuration_id,
252
+ r.provider_model_id,
253
+ r.priority,
254
+ r.created_at,
255
+ r.updated_at
256
+ FROM weave.inference_model_route r
257
+ JOIN weave.inference_model im
258
+ ON im.organization_id = r.organization_id
259
+ AND im.id = r.inference_model_id
260
+ WHERE r.organization_id = $1
261
+ AND ($2::text IS NULL OR im.model_id = $2::text)
262
+ ORDER BY im.model_id ASC, r.priority ASC, r.id ASC
263
+ LIMIT COALESCE($4::integer, 100)
264
+ OFFSET COALESCE($3::integer, 0)`;
265
+ async function listInferenceModelRoutes(client, args) {
266
+ const result = await client.query({
267
+ text: exports.listInferenceModelRoutesQuery,
268
+ values: [args.organizationId, args.modelId, args.pageOffset, args.pageSize],
269
+ rowMode: "array"
270
+ });
271
+ return result.rows.map(row => {
272
+ return {
273
+ id: row[0],
274
+ organizationId: row[1],
275
+ inferenceModelId: row[2],
276
+ modelId: row[3],
277
+ inferenceProviderConfigurationId: row[4],
278
+ providerModelId: row[5],
279
+ priority: row[6],
280
+ createdAt: row[7],
281
+ updatedAt: row[8]
282
+ };
283
+ });
284
+ }
285
+ exports.getOrganizationChatSettingsQuery = `-- name: GetOrganizationChatSettings :one
286
+ SELECT
287
+ o.id AS organization_id,
288
+ chat_im.model_id AS default_chat_model_id,
289
+ chat_r.inference_provider_configuration_id AS default_provider_configuration_id,
290
+ fast_im.model_id AS default_fast_model_id,
291
+ fast_r.inference_provider_configuration_id AS default_fast_provider_configuration_id
292
+ FROM weave.organization o
293
+ LEFT JOIN weave.inference_model_route chat_r
294
+ ON chat_r.organization_id = o.id
295
+ AND chat_r.id = o.default_chat_model_route_id
296
+ LEFT JOIN weave.inference_model chat_im
297
+ ON chat_im.organization_id = chat_r.organization_id
298
+ AND chat_im.id = chat_r.inference_model_id
299
+ LEFT JOIN weave.inference_model_route fast_r
300
+ ON fast_r.organization_id = o.id
301
+ AND fast_r.id = o.default_fast_model_route_id
302
+ LEFT JOIN weave.inference_model fast_im
303
+ ON fast_im.organization_id = fast_r.organization_id
304
+ AND fast_im.id = fast_r.inference_model_id
305
+ WHERE o.id = $1`;
306
+ async function getOrganizationChatSettings(client, args) {
307
+ const result = await client.query({
308
+ text: exports.getOrganizationChatSettingsQuery,
309
+ values: [args.organizationId],
310
+ rowMode: "array"
311
+ });
312
+ if (result.rows.length !== 1) {
313
+ return null;
314
+ }
315
+ const row = result.rows[0];
316
+ return {
317
+ organizationId: row[0],
318
+ defaultChatModelId: row[1],
319
+ defaultProviderConfigurationId: row[2],
320
+ defaultFastModelId: row[3],
321
+ defaultFastProviderConfigurationId: row[4]
322
+ };
323
+ }
324
+ exports.setOrganizationChatSettingsQuery = `-- name: SetOrganizationChatSettings :one
325
+ WITH requested_defaults AS (
326
+ SELECT
327
+ $1::uuid AS organization_id,
328
+ $2::text AS default_chat_model_id,
329
+ $3::uuid AS default_provider_configuration_id,
330
+ $4::text AS default_fast_model_id,
331
+ $5::uuid AS default_fast_provider_configuration_id
332
+ ),
333
+ selected_chat_route AS (
334
+ SELECT
335
+ r.id,
336
+ requested_defaults.organization_id,
337
+ requested_defaults.default_chat_model_id,
338
+ requested_defaults.default_provider_configuration_id,
339
+ requested_defaults.default_fast_model_id,
340
+ requested_defaults.default_fast_provider_configuration_id
341
+ FROM requested_defaults
342
+ JOIN weave.inference_model_route r
343
+ ON r.organization_id = requested_defaults.organization_id
344
+ JOIN weave.inference_model im
345
+ ON im.organization_id = r.organization_id
346
+ AND im.id = r.inference_model_id
347
+ WHERE im.model_id = requested_defaults.default_chat_model_id
348
+ AND r.inference_provider_configuration_id =
349
+ requested_defaults.default_provider_configuration_id
350
+ ),
351
+ selected_fast_route AS (
352
+ SELECT r.id
353
+ FROM requested_defaults
354
+ JOIN weave.inference_model_route r
355
+ ON r.organization_id = requested_defaults.organization_id
356
+ JOIN weave.inference_model im
357
+ ON im.organization_id = r.organization_id
358
+ AND im.id = r.inference_model_id
359
+ WHERE requested_defaults.default_fast_model_id IS NOT NULL
360
+ AND requested_defaults.default_fast_provider_configuration_id IS NOT NULL
361
+ AND im.model_id = requested_defaults.default_fast_model_id
362
+ AND r.inference_provider_configuration_id =
363
+ requested_defaults.default_fast_provider_configuration_id
364
+ ),
365
+ updated_organization AS (
366
+ UPDATE weave.organization o
367
+ SET default_chat_model_route_id = selected_chat_route.id,
368
+ default_fast_model_route_id = COALESCE(
369
+ selected_fast_route.id,
370
+ o.default_fast_model_route_id
371
+ )
372
+ FROM selected_chat_route
373
+ LEFT JOIN selected_fast_route ON TRUE
374
+ WHERE o.id = selected_chat_route.organization_id
375
+ AND (
376
+ (
377
+ selected_chat_route.default_fast_model_id IS NULL
378
+ AND selected_chat_route.default_fast_provider_configuration_id IS NULL
379
+ )
380
+ OR selected_fast_route.id IS NOT NULL
381
+ )
382
+ RETURNING
383
+ o.id AS organization_id,
384
+ o.default_chat_model_route_id,
385
+ o.default_fast_model_route_id
386
+ )
387
+ SELECT
388
+ updated_organization.organization_id,
389
+ chat_im.model_id AS default_chat_model_id,
390
+ chat_r.inference_provider_configuration_id AS default_provider_configuration_id,
391
+ fast_im.model_id AS default_fast_model_id,
392
+ fast_r.inference_provider_configuration_id AS default_fast_provider_configuration_id
393
+ FROM updated_organization
394
+ JOIN weave.inference_model_route chat_r
395
+ ON chat_r.organization_id = updated_organization.organization_id
396
+ AND chat_r.id = updated_organization.default_chat_model_route_id
397
+ JOIN weave.inference_model chat_im
398
+ ON chat_im.organization_id = chat_r.organization_id
399
+ AND chat_im.id = chat_r.inference_model_id
400
+ LEFT JOIN weave.inference_model_route fast_r
401
+ ON fast_r.organization_id = updated_organization.organization_id
402
+ AND fast_r.id = updated_organization.default_fast_model_route_id
403
+ LEFT JOIN weave.inference_model fast_im
404
+ ON fast_im.organization_id = fast_r.organization_id
405
+ AND fast_im.id = fast_r.inference_model_id`;
406
+ async function setOrganizationChatSettings(client, args) {
407
+ const result = await client.query({
408
+ text: exports.setOrganizationChatSettingsQuery,
409
+ values: [args.organizationId, args.defaultChatModelId, args.defaultProviderConfigurationId, args.defaultFastModelId, args.defaultFastProviderConfigurationId],
410
+ rowMode: "array"
411
+ });
412
+ if (result.rows.length !== 1) {
413
+ return null;
414
+ }
415
+ const row = result.rows[0];
416
+ return {
417
+ organizationId: row[0],
418
+ defaultChatModelId: row[1],
419
+ defaultProviderConfigurationId: row[2],
420
+ defaultFastModelId: row[3],
421
+ defaultFastProviderConfigurationId: row[4]
422
+ };
423
+ }
424
+ exports.getModelRuntimeConfigurationQuery = `-- name: GetModelRuntimeConfiguration :one
425
+ SELECT
426
+ imr.id AS inference_model_route_id,
427
+ imr.organization_id,
428
+ im.id AS inference_model_id,
429
+ im.model_id,
430
+ imr.provider_model_id,
431
+ imr.priority,
432
+ p.id AS inference_provider_configuration_id,
433
+ p.kind AS provider_kind,
434
+ p.name AS provider_name,
435
+ p.slug AS provider_slug,
436
+ p.base_url AS provider_base_url,
437
+ c.credential_kind,
438
+ c.encrypted_credentials,
439
+ c.credential_hint,
440
+ c.key_id,
441
+ c.last_rotated_at
442
+ FROM weave.inference_model_route imr
443
+ JOIN weave.inference_model im
444
+ ON im.organization_id = imr.organization_id
445
+ AND im.id = imr.inference_model_id
446
+ JOIN weave.inference_provider_configuration p
447
+ ON p.organization_id = imr.organization_id
448
+ AND p.id = imr.inference_provider_configuration_id
449
+ JOIN weave.inference_provider_credential c
450
+ ON c.inference_provider_configuration_id = p.id
451
+ WHERE imr.organization_id = $1
452
+ AND im.model_id = $2
453
+ ORDER BY imr.priority ASC
454
+ LIMIT 1`;
455
+ async function getModelRuntimeConfiguration(client, args) {
456
+ const result = await client.query({
457
+ text: exports.getModelRuntimeConfigurationQuery,
458
+ values: [args.organizationId, args.modelId],
459
+ rowMode: "array"
460
+ });
461
+ if (result.rows.length !== 1) {
462
+ return null;
463
+ }
464
+ const row = result.rows[0];
465
+ return {
466
+ inferenceModelRouteId: row[0],
467
+ organizationId: row[1],
468
+ inferenceModelId: row[2],
469
+ modelId: row[3],
470
+ providerModelId: row[4],
471
+ priority: row[5],
472
+ inferenceProviderConfigurationId: row[6],
473
+ providerKind: row[7],
474
+ providerName: row[8],
475
+ providerSlug: row[9],
476
+ providerBaseUrl: row[10],
477
+ credentialKind: row[11],
478
+ encryptedCredentials: row[12],
479
+ credentialHint: row[13],
480
+ keyId: row[14],
481
+ lastRotatedAt: row[15]
482
+ };
483
+ }