@webtypen/webframez-core 0.3.42 → 0.3.44

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.
@@ -54,22 +54,86 @@ export declare function apiFunctionParamToJsonSchema(definition: ApiFunctionPara
54
54
  type: string;
55
55
  pattern?: undefined;
56
56
  items?: undefined;
57
+ anyOf?: undefined;
58
+ "x-webframez-type"?: undefined;
59
+ "x-openai-file-parameter"?: undefined;
57
60
  enum?: undefined;
58
61
  } | {
59
62
  type: string;
60
63
  pattern: string;
61
64
  items?: undefined;
65
+ anyOf?: undefined;
66
+ "x-webframez-type"?: undefined;
67
+ "x-openai-file-parameter"?: undefined;
62
68
  enum?: undefined;
63
69
  } | {
64
70
  type: string;
65
71
  items: {};
66
72
  pattern?: undefined;
73
+ anyOf?: undefined;
74
+ "x-webframez-type"?: undefined;
75
+ "x-openai-file-parameter"?: undefined;
76
+ enum?: undefined;
77
+ } | {
78
+ anyOf: ({
79
+ type: string;
80
+ description: string;
81
+ additionalProperties?: undefined;
82
+ properties?: undefined;
83
+ } | {
84
+ type: string;
85
+ additionalProperties: boolean;
86
+ properties: {
87
+ url: {
88
+ type: string;
89
+ };
90
+ download_url: {
91
+ type: string;
92
+ };
93
+ download_link: {
94
+ type: string;
95
+ };
96
+ file_url: {
97
+ type: string;
98
+ };
99
+ content_base64: {
100
+ type: string;
101
+ };
102
+ data_url: {
103
+ type: string;
104
+ };
105
+ id: {
106
+ type: string;
107
+ };
108
+ filename: {
109
+ type: string;
110
+ };
111
+ name: {
112
+ type: string;
113
+ };
114
+ mime: {
115
+ type: string;
116
+ };
117
+ mime_type: {
118
+ type: string;
119
+ };
120
+ };
121
+ description?: undefined;
122
+ })[];
123
+ "x-webframez-type": string;
124
+ "x-openai-file-parameter": boolean;
125
+ type?: undefined;
126
+ pattern?: undefined;
127
+ items?: undefined;
67
128
  enum?: undefined;
68
129
  } | {
69
130
  enum: any[];
70
131
  type?: undefined;
71
132
  pattern?: undefined;
72
133
  items?: undefined;
134
+ anyOf?: undefined;
135
+ "x-webframez-type"?: undefined;
136
+ "x-openai-file-parameter"?: undefined;
73
137
  };
74
138
  export declare function toApiFunctionHttpResult(res: Response, result: any): Response;
75
139
  export declare function toApiFunctionPayload(result: any): any;
@@ -250,6 +250,12 @@ function coerceApiFunctionParam(key, value, definition) {
250
250
  }
251
251
  throw new ApiFunctionRuntimeError(`Parameter "${key}" must be an object`, 400);
252
252
  }
253
+ if (type === "file") {
254
+ if (typeof value === "string" || isPlainApiObject(value)) {
255
+ return value;
256
+ }
257
+ throw new ApiFunctionRuntimeError(`Parameter "${key}" must be a file path/string or a file reference object`, 400);
258
+ }
253
259
  return value;
254
260
  }
255
261
  exports.coerceApiFunctionParam = coerceApiFunctionParam;
@@ -292,6 +298,35 @@ function apiFunctionParamToJsonSchema(definition) {
292
298
  return { type: "array", items: {} };
293
299
  if (type === "object")
294
300
  return { type: "object" };
301
+ if (type === "file") {
302
+ return {
303
+ anyOf: [
304
+ {
305
+ type: "string",
306
+ description: "Local ChatGPT runtime file path, downloadable URL, Data-URL, or Base64 content.",
307
+ },
308
+ {
309
+ type: "object",
310
+ additionalProperties: true,
311
+ properties: {
312
+ url: { type: "string" },
313
+ download_url: { type: "string" },
314
+ download_link: { type: "string" },
315
+ file_url: { type: "string" },
316
+ content_base64: { type: "string" },
317
+ data_url: { type: "string" },
318
+ id: { type: "string" },
319
+ filename: { type: "string" },
320
+ name: { type: "string" },
321
+ mime: { type: "string" },
322
+ mime_type: { type: "string" },
323
+ },
324
+ },
325
+ ],
326
+ "x-webframez-type": "file",
327
+ "x-openai-file-parameter": true,
328
+ };
329
+ }
295
330
  if (type === "option" && Array.isArray(definition.options) && definition.options.length > 0) {
296
331
  return { enum: definition.options.map((option) => option.value) };
297
332
  }
@@ -15,6 +15,8 @@ export type WebframezOperationContext = {
15
15
  timestamp: Date;
16
16
  attributes?: WebframezHookAttributes;
17
17
  error?: unknown;
18
+ request?: unknown;
19
+ response?: unknown;
18
20
  };
19
21
  export type WebframezLifecycleEvent<TEventName extends WebframezHookEventName = WebframezHookEventName> = {
20
22
  type: TEventName;
@@ -20,6 +20,18 @@ const querystring_1 = __importDefault(require("querystring"));
20
20
  const url_1 = __importDefault(require("url"));
21
21
  const ErrorHandler_1 = require("../ErrorHandling/ErrorHandler");
22
22
  const WebframezHooks_1 = require("../Hooks/WebframezHooks");
23
+ function requestTelemetryAttributes(request) {
24
+ if (!request || !request.url) {
25
+ return {};
26
+ }
27
+ const target = request.url;
28
+ const path = target.indexOf("?") >= 0 ? target.substring(0, target.indexOf("?")) : target;
29
+ return {
30
+ "url.path": path,
31
+ "http.target": target,
32
+ "webframez.request.path": path,
33
+ };
34
+ }
23
35
  class RouterFacade {
24
36
  constructor() {
25
37
  /**
@@ -467,11 +479,9 @@ class RouterFacade {
467
479
  name: `${fallbackRequest.method || "HTTP"} unmatched`,
468
480
  status: "error",
469
481
  error: e,
470
- attributes: {
471
- "http.request.method": fallbackRequest.method || null,
472
- "http.response.status_code": statusCode,
473
- "webframez.mode": this.mode,
474
- },
482
+ request: fallbackRequest,
483
+ response,
484
+ attributes: Object.assign(Object.assign({ "http.request.method": fallbackRequest.method || null, "http.response.status_code": statusCode }, requestTelemetryAttributes(fallbackRequest)), { "webframez.mode": this.mode }),
475
485
  });
476
486
  return errorResult;
477
487
  }
@@ -486,11 +496,9 @@ class RouterFacade {
486
496
  operationId: httpOperationId,
487
497
  name: `${request.method} unmatched`,
488
498
  status: "ok",
489
- attributes: {
490
- "http.request.method": request.method,
491
- "http.response.status_code": 404,
492
- "webframez.mode": this.mode,
493
- },
499
+ request,
500
+ response,
501
+ attributes: Object.assign(Object.assign({ "http.request.method": request.method, "http.response.status_code": 404 }, requestTelemetryAttributes(request)), { "webframez.mode": this.mode }),
494
502
  });
495
503
  return notFoundResult;
496
504
  }
@@ -500,13 +508,9 @@ class RouterFacade {
500
508
  operationId: httpOperationId,
501
509
  name: `${request.method} ${route.path}`,
502
510
  status: "ok",
503
- attributes: {
504
- "http.request.method": request.method,
505
- "http.response.status_code": 404,
506
- "url.template": route.path,
507
- "webframez.route": route.path,
508
- "webframez.mode": this.mode,
509
- },
511
+ request,
512
+ response,
513
+ attributes: Object.assign(Object.assign({ "http.request.method": request.method, "http.response.status_code": 404, "url.template": route.path, "webframez.route": route.path }, requestTelemetryAttributes(request)), { "webframez.mode": this.mode }),
510
514
  });
511
515
  return missingRouteResult;
512
516
  }
@@ -518,13 +522,9 @@ class RouterFacade {
518
522
  operationId: httpOperationId,
519
523
  name: `${request.method} ${route.path}`,
520
524
  status: "ok",
521
- attributes: {
522
- "http.request.method": request.method,
523
- "http.response.status_code": response.statusCode || 200,
524
- "url.template": route.path,
525
- "webframez.route": route.path,
526
- "webframez.mode": this.mode,
527
- },
525
+ request,
526
+ response,
527
+ attributes: Object.assign(Object.assign({ "http.request.method": request.method, "http.response.status_code": response.statusCode || 200, "url.template": route.path, "webframez.route": route.path }, requestTelemetryAttributes(request)), { "webframez.mode": this.mode }),
528
528
  });
529
529
  return optionsResult;
530
530
  }
@@ -565,13 +565,9 @@ class RouterFacade {
565
565
  operationId: httpOperationId,
566
566
  name: `${request.method} ${route.path}`,
567
567
  status: "ok",
568
- attributes: {
569
- "http.request.method": request.method,
570
- "http.response.status_code": 404,
571
- "url.template": route.path,
572
- "webframez.route": route.path,
573
- "webframez.mode": this.mode,
574
- },
568
+ request,
569
+ response,
570
+ attributes: Object.assign(Object.assign({ "http.request.method": request.method, "http.response.status_code": 404, "url.template": route.path, "webframez.route": route.path }, requestTelemetryAttributes(request)), { "webframez.mode": this.mode }),
575
571
  });
576
572
  return unknownMethodResult;
577
573
  }
@@ -597,13 +593,9 @@ class RouterFacade {
597
593
  operationId: httpOperationId,
598
594
  name: `${request.method} ${route.path}`,
599
595
  status: "ok",
600
- attributes: {
601
- "http.request.method": request.method,
602
- "http.response.status_code": response.statusCode || 200,
603
- "url.template": route.path,
604
- "webframez.route": route.path,
605
- "webframez.mode": this.mode,
606
- },
596
+ request,
597
+ response,
598
+ attributes: Object.assign(Object.assign({ "http.request.method": request.method, "http.response.status_code": response.statusCode || 200, "url.template": route.path, "webframez.route": route.path }, requestTelemetryAttributes(request)), { "webframez.mode": this.mode }),
607
599
  });
608
600
  return returnResult;
609
601
  }
@@ -615,13 +607,9 @@ class RouterFacade {
615
607
  name: `${request.method} ${route.path}`,
616
608
  status: "error",
617
609
  error: e.reason || e,
618
- attributes: {
619
- "http.request.method": request.method,
620
- "http.response.status_code": 500,
621
- "url.template": route.path,
622
- "webframez.route": route.path,
623
- "webframez.mode": this.mode,
624
- },
610
+ request,
611
+ response,
612
+ attributes: Object.assign(Object.assign({ "http.request.method": request.method, "http.response.status_code": 500, "url.template": route.path, "webframez.route": route.path }, requestTelemetryAttributes(request)), { "webframez.mode": this.mode }),
625
613
  });
626
614
  return middlewareErrorResult;
627
615
  }
@@ -659,13 +647,9 @@ class RouterFacade {
659
647
  name: `${request.method} ${route.path}`,
660
648
  status: "error",
661
649
  error: e,
662
- attributes: {
663
- "http.request.method": request.method,
664
- "http.response.status_code": 500,
665
- "url.template": route.path,
666
- "webframez.route": route.path,
667
- "webframez.mode": this.mode,
668
- },
650
+ request,
651
+ response,
652
+ attributes: Object.assign(Object.assign({ "http.request.method": request.method, "http.response.status_code": 500, "url.template": route.path, "webframez.route": route.path }, requestTelemetryAttributes(request)), { "webframez.mode": this.mode }),
669
653
  });
670
654
  return errorResult;
671
655
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webtypen/webframez-core",
3
- "version": "0.3.42",
3
+ "version": "0.3.44",
4
4
  "description": "The core package of the typescript based webframez (web-framework) by webtypen.de",
5
5
  "homepage": "https://webtypen.de/",
6
6
  "license": "MIT",