@sylphx/sdk 0.20.1 → 0.21.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.
@@ -1,4 +1,5 @@
1
1
  import { SdkBillingPlan, SdkConsentType } from '@sylphx/contract';
2
+ export { LEGACY_PLATFORM_PROJECT_ID, PLATFORM_CONSOLE_SLUG, isPlatformProjectIdentity } from '@sylphx/contract';
2
3
 
3
4
  /**
4
5
  * REST Client for Sylphx Platform
@@ -983,6 +984,28 @@ interface AIClientOptions {
983
984
  platformUrl?: string;
984
985
  }
985
986
 
987
+ interface ChatCompletionTool {
988
+ type?: 'function';
989
+ function: {
990
+ name: string;
991
+ description?: string;
992
+ parameters?: Record<string, unknown>;
993
+ };
994
+ }
995
+ type ChatCompletionToolChoice = 'auto' | 'none' | 'required' | {
996
+ type: 'function';
997
+ function: {
998
+ name: string;
999
+ };
1000
+ };
1001
+ interface ChatCompletionToolCall {
1002
+ id: string;
1003
+ type?: 'function';
1004
+ function: {
1005
+ name: string;
1006
+ arguments: string;
1007
+ };
1008
+ }
986
1009
  interface ChatCompletionOptions {
987
1010
  model: string;
988
1011
  messages: ChatMessage[];
@@ -993,6 +1016,8 @@ interface ChatCompletionOptions {
993
1016
  presence_penalty?: number;
994
1017
  stop?: string | string[];
995
1018
  stream?: false;
1019
+ tools?: ChatCompletionTool[];
1020
+ tool_choice?: ChatCompletionToolChoice;
996
1021
  user?: string;
997
1022
  }
998
1023
  interface ChatCompletionStreamOptions extends Omit<ChatCompletionOptions, 'stream'> {
@@ -1008,6 +1033,7 @@ interface ChatCompletionResponse {
1008
1033
  message: {
1009
1034
  role: 'assistant';
1010
1035
  content: string;
1036
+ tool_calls?: ChatCompletionToolCall[];
1011
1037
  };
1012
1038
  finish_reason: 'stop' | 'length' | 'tool_calls' | 'content_filter' | null;
1013
1039
  }>;
@@ -1027,6 +1053,15 @@ interface ChatCompletionChunk {
1027
1053
  delta: {
1028
1054
  role?: 'assistant';
1029
1055
  content?: string;
1056
+ tool_calls?: Array<{
1057
+ index: number;
1058
+ id?: string;
1059
+ type?: 'function';
1060
+ function?: {
1061
+ name?: string;
1062
+ arguments?: string;
1063
+ };
1064
+ }>;
1030
1065
  };
1031
1066
  finish_reason: 'stop' | 'length' | 'tool_calls' | 'content_filter' | null;
1032
1067
  }>;
@@ -1473,8 +1508,6 @@ declare function getStreams(): StreamsClient;
1473
1508
  * ```
1474
1509
  */
1475
1510
 
1476
- declare const PLATFORM_CONSOLE_SLUG = "keen-wave-x3m9p2";
1477
- declare const LEGACY_PLATFORM_PROJECT_ID = "00000000-0000-0000-0000-000000000001";
1478
1511
  declare const PLATFORM_TENANT_BAAS_URL = "https://keen-wave-x3m9p2.api.sylphx.com/v1";
1479
1512
  interface PlatformBaasUrlEnv {
1480
1513
  readonly [key: string]: string | undefined;
@@ -1482,10 +1515,6 @@ interface PlatformBaasUrlEnv {
1482
1515
  readonly SYLPHX_URL?: string;
1483
1516
  readonly SYLPHX_RUNTIME_URL?: string;
1484
1517
  }
1485
- declare function isPlatformProjectIdentity(input: {
1486
- readonly projectId?: string | null;
1487
- readonly projectSlug?: string | null;
1488
- }): boolean;
1489
1518
  declare function resolvePlatformBaasUrl(env?: PlatformBaasUrlEnv): string;
1490
1519
  interface ServerConfig {
1491
1520
  /**
@@ -1974,4 +2003,4 @@ declare function getDatabaseConnection(options: AuthenticatedFetchOptions): Prom
1974
2003
  */
1975
2004
  declare function getDatabaseStatus(options: AuthenticatedFetchOptions): Promise<DatabaseStatusInfo>;
1976
2005
 
1977
- export { type AIClient, type AIClientOptions, type AppConfig, type AppMetadata, type ChannelHelper, type ChatCompletionChunk, type ChatCompletionOptions, type ChatCompletionResponse, type ChatCompletionStreamOptions, type ChatMessage, type ConsentType, type DatabaseConnectionInfo, type DatabaseStatusInfo, type EmbeddingOptions, type EmbeddingResponse, type EngagementLeaderboardEntry, type EngagementLeaderboardResult, type EnvironmentType, type FeatureFlagDefinition, type FunctionDeployOptions, type FunctionDeployResult, type FunctionInvokeOptions, type FunctionListOptions, type FunctionLogEntry, type FunctionLogsOptions, type FunctionRecord, type FunctionRuntime, type FunctionStatus, FunctionsClient, type GetAppConfigOptions, InvalidConnectionUrlError, type KeyType, type KeyValidationResult, type KvClient, type KvClientOptions, type KvRateLimitResult, type KvSetOptions, type KvZMember, LEGACY_PLATFORM_PROJECT_ID, type ModelInfo, type ModelsResponse, type OAuthProvider, type OAuthProviderInfo, PLATFORM_CONSOLE_SLUG, PLATFORM_TENANT_BAAS_URL, type Plan, type PlatformBaasUrlEnv, type ReferralLeaderboardEntry, type ReferralLeaderboardResult, type RestClient, type RestClientConfig as ServerClientConfig, type ServerConfig, type StreamHistoryOptions, type StreamMessage, type StreamsClient, type StreamsClientOptions, type SylphxClientInput, type SylphxConfig, type WebhookPayload, type WebhookVerifyOptions, type WebhookVerifyResult, createAI, createAuthenticatedServerClient, createClient, createKv, createServerClient, createServerRestClient, createStreams, createWebhookHandler, decodeUserId, detectEnvironment, detectKeyType, encodeUserId, getAI, getAppConfig, getAppMetadata, getConsentTypes, getCookieNamespace, getDatabaseConnection, getDatabaseStatus, getEngagementLeaderboard, getFeatureFlags, getJwks, getKv, getOAuthProviders, getOAuthProvidersWithInfo, getPlans, getReferralLeaderboard, getStreams, isAppId, isDevelopmentKey, isDevelopmentRuntime, isPlatformProjectIdentity, isProductionKey, isSecretKey, resetJwksCache, resolvePlatformBaasUrl, validateAndSanitizeAppId, validateAndSanitizeKey, validateAndSanitizeSecretKey, validateAppId, validateKey, validateSecretKey, verifyAccessToken, verifyWebhook };
2006
+ export { type AIClient, type AIClientOptions, type AppConfig, type AppMetadata, type ChannelHelper, type ChatCompletionChunk, type ChatCompletionOptions, type ChatCompletionResponse, type ChatCompletionStreamOptions, type ChatMessage, type ConsentType, type DatabaseConnectionInfo, type DatabaseStatusInfo, type EmbeddingOptions, type EmbeddingResponse, type EngagementLeaderboardEntry, type EngagementLeaderboardResult, type EnvironmentType, type FeatureFlagDefinition, type FunctionDeployOptions, type FunctionDeployResult, type FunctionInvokeOptions, type FunctionListOptions, type FunctionLogEntry, type FunctionLogsOptions, type FunctionRecord, type FunctionRuntime, type FunctionStatus, FunctionsClient, type GetAppConfigOptions, InvalidConnectionUrlError, type KeyType, type KeyValidationResult, type KvClient, type KvClientOptions, type KvRateLimitResult, type KvSetOptions, type KvZMember, type ModelInfo, type ModelsResponse, type OAuthProvider, type OAuthProviderInfo, PLATFORM_TENANT_BAAS_URL, type Plan, type PlatformBaasUrlEnv, type ReferralLeaderboardEntry, type ReferralLeaderboardResult, type RestClient, type RestClientConfig as ServerClientConfig, type ServerConfig, type StreamHistoryOptions, type StreamMessage, type StreamsClient, type StreamsClientOptions, type SylphxClientInput, type SylphxConfig, type WebhookPayload, type WebhookVerifyOptions, type WebhookVerifyResult, createAI, createAuthenticatedServerClient, createClient, createKv, createServerClient, createServerRestClient, createStreams, createWebhookHandler, decodeUserId, detectEnvironment, detectKeyType, encodeUserId, getAI, getAppConfig, getAppMetadata, getConsentTypes, getCookieNamespace, getDatabaseConnection, getDatabaseStatus, getEngagementLeaderboard, getFeatureFlags, getJwks, getKv, getOAuthProviders, getOAuthProvidersWithInfo, getPlans, getReferralLeaderboard, getStreams, isAppId, isDevelopmentKey, isDevelopmentRuntime, isProductionKey, isSecretKey, resetJwksCache, resolvePlatformBaasUrl, validateAndSanitizeAppId, validateAndSanitizeKey, validateAndSanitizeSecretKey, validateAppId, validateKey, validateSecretKey, verifyAccessToken, verifyWebhook };
@@ -1,4 +1,11 @@
1
- // ../../node_modules/jose/dist/webapi/lib/buffer_utils.js
1
+ // src/server/index.ts
2
+ import {
3
+ isPlatformProjectIdentity,
4
+ LEGACY_PLATFORM_PROJECT_ID,
5
+ PLATFORM_CONSOLE_SLUG
6
+ } from "@sylphx/contract";
7
+
8
+ // ../../../../.bun-cache/links/jose@6.1.3-bb9fbb1164201cee/node_modules/jose/dist/webapi/lib/buffer_utils.js
2
9
  var encoder = new TextEncoder();
3
10
  var decoder = new TextDecoder();
4
11
  var MAX_INT32 = 2 ** 32;
@@ -24,7 +31,7 @@ function encode(string) {
24
31
  return bytes;
25
32
  }
26
33
 
27
- // ../../node_modules/jose/dist/webapi/lib/base64.js
34
+ // ../../../../.bun-cache/links/jose@6.1.3-bb9fbb1164201cee/node_modules/jose/dist/webapi/lib/base64.js
28
35
  function decodeBase64(encoded) {
29
36
  if (Uint8Array.fromBase64) {
30
37
  return Uint8Array.fromBase64(encoded);
@@ -37,7 +44,7 @@ function decodeBase64(encoded) {
37
44
  return bytes;
38
45
  }
39
46
 
40
- // ../../node_modules/jose/dist/webapi/util/base64url.js
47
+ // ../../../../.bun-cache/links/jose@6.1.3-bb9fbb1164201cee/node_modules/jose/dist/webapi/util/base64url.js
41
48
  function decode(input) {
42
49
  if (Uint8Array.fromBase64) {
43
50
  return Uint8Array.fromBase64(typeof input === "string" ? input : decoder.decode(input), {
@@ -56,7 +63,7 @@ function decode(input) {
56
63
  }
57
64
  }
58
65
 
59
- // ../../node_modules/jose/dist/webapi/util/errors.js
66
+ // ../../../../.bun-cache/links/jose@6.1.3-bb9fbb1164201cee/node_modules/jose/dist/webapi/util/errors.js
60
67
  var JOSEError = class extends Error {
61
68
  static code = "ERR_JOSE_GENERIC";
62
69
  code = "ERR_JOSE_GENERIC";
@@ -116,7 +123,7 @@ var JWSSignatureVerificationFailed = class extends JOSEError {
116
123
  }
117
124
  };
118
125
 
119
- // ../../node_modules/jose/dist/webapi/lib/crypto_key.js
126
+ // ../../../../.bun-cache/links/jose@6.1.3-bb9fbb1164201cee/node_modules/jose/dist/webapi/lib/crypto_key.js
120
127
  var unusable = (name, prop = "algorithm.name") => new TypeError(`CryptoKey does not support this operation, its ${prop} must be ${name}`);
121
128
  var isAlgorithm = (algorithm, name) => algorithm.name === name;
122
129
  function getHashLength(hash) {
@@ -204,7 +211,7 @@ function checkSigCryptoKey(key, alg, usage) {
204
211
  checkUsage(key, usage);
205
212
  }
206
213
 
207
- // ../../node_modules/jose/dist/webapi/lib/invalid_key_input.js
214
+ // ../../../../.bun-cache/links/jose@6.1.3-bb9fbb1164201cee/node_modules/jose/dist/webapi/lib/invalid_key_input.js
208
215
  function message(msg, actual, ...types) {
209
216
  types = types.filter(Boolean);
210
217
  if (types.length > 2) {
@@ -229,7 +236,7 @@ function message(msg, actual, ...types) {
229
236
  var invalidKeyInput = (actual, ...types) => message("Key must be ", actual, ...types);
230
237
  var withAlg = (alg, actual, ...types) => message(`Key for the ${alg} algorithm must be `, actual, ...types);
231
238
 
232
- // ../../node_modules/jose/dist/webapi/lib/is_key_like.js
239
+ // ../../../../.bun-cache/links/jose@6.1.3-bb9fbb1164201cee/node_modules/jose/dist/webapi/lib/is_key_like.js
233
240
  var isCryptoKey = (key) => {
234
241
  if (key?.[Symbol.toStringTag] === "CryptoKey")
235
242
  return true;
@@ -242,7 +249,7 @@ var isCryptoKey = (key) => {
242
249
  var isKeyObject = (key) => key?.[Symbol.toStringTag] === "KeyObject";
243
250
  var isKeyLike = (key) => isCryptoKey(key) || isKeyObject(key);
244
251
 
245
- // ../../node_modules/jose/dist/webapi/lib/is_disjoint.js
252
+ // ../../../../.bun-cache/links/jose@6.1.3-bb9fbb1164201cee/node_modules/jose/dist/webapi/lib/is_disjoint.js
246
253
  function isDisjoint(...headers) {
247
254
  const sources = headers.filter(Boolean);
248
255
  if (sources.length === 0 || sources.length === 1) {
@@ -265,7 +272,7 @@ function isDisjoint(...headers) {
265
272
  return true;
266
273
  }
267
274
 
268
- // ../../node_modules/jose/dist/webapi/lib/is_object.js
275
+ // ../../../../.bun-cache/links/jose@6.1.3-bb9fbb1164201cee/node_modules/jose/dist/webapi/lib/is_object.js
269
276
  var isObjectLike = (value) => typeof value === "object" && value !== null;
270
277
  function isObject(input) {
271
278
  if (!isObjectLike(input) || Object.prototype.toString.call(input) !== "[object Object]") {
@@ -281,7 +288,7 @@ function isObject(input) {
281
288
  return Object.getPrototypeOf(input) === proto;
282
289
  }
283
290
 
284
- // ../../node_modules/jose/dist/webapi/lib/check_key_length.js
291
+ // ../../../../.bun-cache/links/jose@6.1.3-bb9fbb1164201cee/node_modules/jose/dist/webapi/lib/check_key_length.js
285
292
  function checkKeyLength(alg, key) {
286
293
  if (alg.startsWith("RS") || alg.startsWith("PS")) {
287
294
  const { modulusLength } = key.algorithm;
@@ -291,7 +298,7 @@ function checkKeyLength(alg, key) {
291
298
  }
292
299
  }
293
300
 
294
- // ../../node_modules/jose/dist/webapi/lib/jwk_to_key.js
301
+ // ../../../../.bun-cache/links/jose@6.1.3-bb9fbb1164201cee/node_modules/jose/dist/webapi/lib/jwk_to_key.js
295
302
  function subtleMapping(jwk) {
296
303
  let algorithm;
297
304
  let keyUsages;
@@ -401,7 +408,7 @@ async function jwkToKey(jwk) {
401
408
  return crypto.subtle.importKey("jwk", keyData, algorithm, jwk.ext ?? (jwk.d || jwk.priv ? false : true), jwk.key_ops ?? keyUsages);
402
409
  }
403
410
 
404
- // ../../node_modules/jose/dist/webapi/key/import.js
411
+ // ../../../../.bun-cache/links/jose@6.1.3-bb9fbb1164201cee/node_modules/jose/dist/webapi/key/import.js
405
412
  async function importJWK(jwk, alg, options) {
406
413
  if (!isObject(jwk)) {
407
414
  throw new TypeError("JWK must be an object");
@@ -437,7 +444,7 @@ async function importJWK(jwk, alg, options) {
437
444
  }
438
445
  }
439
446
 
440
- // ../../node_modules/jose/dist/webapi/lib/validate_crit.js
447
+ // ../../../../.bun-cache/links/jose@6.1.3-bb9fbb1164201cee/node_modules/jose/dist/webapi/lib/validate_crit.js
441
448
  function validateCrit(Err, recognizedDefault, recognizedOption, protectedHeader, joseHeader) {
442
449
  if (joseHeader.crit !== void 0 && protectedHeader?.crit === void 0) {
443
450
  throw new Err('"crit" (Critical) Header Parameter MUST be integrity protected');
@@ -468,7 +475,7 @@ function validateCrit(Err, recognizedDefault, recognizedOption, protectedHeader,
468
475
  return new Set(protectedHeader.crit);
469
476
  }
470
477
 
471
- // ../../node_modules/jose/dist/webapi/lib/validate_algorithms.js
478
+ // ../../../../.bun-cache/links/jose@6.1.3-bb9fbb1164201cee/node_modules/jose/dist/webapi/lib/validate_algorithms.js
472
479
  function validateAlgorithms(option, algorithms) {
473
480
  if (algorithms !== void 0 && (!Array.isArray(algorithms) || algorithms.some((s) => typeof s !== "string"))) {
474
481
  throw new TypeError(`"${option}" option must be an array of strings`);
@@ -479,13 +486,13 @@ function validateAlgorithms(option, algorithms) {
479
486
  return new Set(algorithms);
480
487
  }
481
488
 
482
- // ../../node_modules/jose/dist/webapi/lib/is_jwk.js
489
+ // ../../../../.bun-cache/links/jose@6.1.3-bb9fbb1164201cee/node_modules/jose/dist/webapi/lib/is_jwk.js
483
490
  var isJWK = (key) => isObject(key) && typeof key.kty === "string";
484
491
  var isPrivateJWK = (key) => key.kty !== "oct" && (key.kty === "AKP" && typeof key.priv === "string" || typeof key.d === "string");
485
492
  var isPublicJWK = (key) => key.kty !== "oct" && key.d === void 0 && key.priv === void 0;
486
493
  var isSecretJWK = (key) => key.kty === "oct" && typeof key.k === "string";
487
494
 
488
- // ../../node_modules/jose/dist/webapi/lib/normalize_key.js
495
+ // ../../../../.bun-cache/links/jose@6.1.3-bb9fbb1164201cee/node_modules/jose/dist/webapi/lib/normalize_key.js
489
496
  var cache;
490
497
  var handleJWK = async (key, jwk, alg, freeze = false) => {
491
498
  cache ||= /* @__PURE__ */ new WeakMap();
@@ -656,7 +663,7 @@ async function normalizeKey(key, alg) {
656
663
  throw new Error("unreachable");
657
664
  }
658
665
 
659
- // ../../node_modules/jose/dist/webapi/lib/check_key_type.js
666
+ // ../../../../.bun-cache/links/jose@6.1.3-bb9fbb1164201cee/node_modules/jose/dist/webapi/lib/check_key_type.js
660
667
  var tag = (key) => key?.[Symbol.toStringTag];
661
668
  var jwkMatchesOp = (alg, key, usage) => {
662
669
  if (key.use !== void 0) {
@@ -776,7 +783,7 @@ function checkKeyType(alg, key, usage) {
776
783
  }
777
784
  }
778
785
 
779
- // ../../node_modules/jose/dist/webapi/lib/subtle_dsa.js
786
+ // ../../../../.bun-cache/links/jose@6.1.3-bb9fbb1164201cee/node_modules/jose/dist/webapi/lib/subtle_dsa.js
780
787
  function subtleAlgorithm(alg, algorithm) {
781
788
  const hash = `SHA-${alg.slice(-3)}`;
782
789
  switch (alg) {
@@ -808,7 +815,7 @@ function subtleAlgorithm(alg, algorithm) {
808
815
  }
809
816
  }
810
817
 
811
- // ../../node_modules/jose/dist/webapi/lib/get_sign_verify_key.js
818
+ // ../../../../.bun-cache/links/jose@6.1.3-bb9fbb1164201cee/node_modules/jose/dist/webapi/lib/get_sign_verify_key.js
812
819
  async function getSigKey(alg, key, usage) {
813
820
  if (key instanceof Uint8Array) {
814
821
  if (!alg.startsWith("HS")) {
@@ -820,7 +827,7 @@ async function getSigKey(alg, key, usage) {
820
827
  return key;
821
828
  }
822
829
 
823
- // ../../node_modules/jose/dist/webapi/lib/verify.js
830
+ // ../../../../.bun-cache/links/jose@6.1.3-bb9fbb1164201cee/node_modules/jose/dist/webapi/lib/verify.js
824
831
  async function verify(alg, key, signature, data) {
825
832
  const cryptoKey = await getSigKey(alg, key, "verify");
826
833
  checkKeyLength(alg, cryptoKey);
@@ -832,7 +839,7 @@ async function verify(alg, key, signature, data) {
832
839
  }
833
840
  }
834
841
 
835
- // ../../node_modules/jose/dist/webapi/jws/flattened/verify.js
842
+ // ../../../../.bun-cache/links/jose@6.1.3-bb9fbb1164201cee/node_modules/jose/dist/webapi/jws/flattened/verify.js
836
843
  async function flattenedVerify(jws, key, options) {
837
844
  if (!isObject(jws)) {
838
845
  throw new JWSInvalid("Flattened JWS must be an object");
@@ -934,7 +941,7 @@ async function flattenedVerify(jws, key, options) {
934
941
  return result;
935
942
  }
936
943
 
937
- // ../../node_modules/jose/dist/webapi/jws/compact/verify.js
944
+ // ../../../../.bun-cache/links/jose@6.1.3-bb9fbb1164201cee/node_modules/jose/dist/webapi/jws/compact/verify.js
938
945
  async function compactVerify(jws, key, options) {
939
946
  if (jws instanceof Uint8Array) {
940
947
  jws = decoder.decode(jws);
@@ -954,7 +961,7 @@ async function compactVerify(jws, key, options) {
954
961
  return result;
955
962
  }
956
963
 
957
- // ../../node_modules/jose/dist/webapi/lib/jwt_claims_set.js
964
+ // ../../../../.bun-cache/links/jose@6.1.3-bb9fbb1164201cee/node_modules/jose/dist/webapi/lib/jwt_claims_set.js
958
965
  var epoch = (date) => Math.floor(date.getTime() / 1e3);
959
966
  var minute = 60;
960
967
  var hour = minute * 60;
@@ -1111,7 +1118,7 @@ function validateClaimsSet(protectedHeader, encodedPayload, options = {}) {
1111
1118
  return payload;
1112
1119
  }
1113
1120
 
1114
- // ../../node_modules/jose/dist/webapi/jwt/verify.js
1121
+ // ../../../../.bun-cache/links/jose@6.1.3-bb9fbb1164201cee/node_modules/jose/dist/webapi/jwt/verify.js
1115
1122
  async function jwtVerify(jwt, key, options) {
1116
1123
  const verified = await compactVerify(jwt, key, options);
1117
1124
  if (verified.protectedHeader.crit?.includes("b64") && verified.protectedHeader.b64 === false) {
@@ -2935,12 +2942,7 @@ function getStreams() {
2935
2942
  }
2936
2943
 
2937
2944
  // src/server/index.ts
2938
- var PLATFORM_CONSOLE_SLUG = "keen-wave-x3m9p2";
2939
- var LEGACY_PLATFORM_PROJECT_ID = "00000000-0000-0000-0000-000000000001";
2940
2945
  var PLATFORM_TENANT_BAAS_URL = `https://${PLATFORM_CONSOLE_SLUG}.${DEFAULT_SDK_API_HOST}${SDK_API_PATH}`;
2941
- function isPlatformProjectIdentity(input) {
2942
- return input.projectSlug === PLATFORM_CONSOLE_SLUG || input.projectId === LEGACY_PLATFORM_PROJECT_ID;
2943
- }
2944
2946
  function resolvePlatformBaasUrl(env = process.env) {
2945
2947
  if (env.SYLPHX_BAAS_URL?.trim()) return normalizeV1BaseUrl(env.SYLPHX_BAAS_URL);
2946
2948
  const fromConnectionUrl = env.SYLPHX_URL?.trim() ? baasUrlFromConnectionUrl(env.SYLPHX_URL) : null;