@appaflytech/zeyrek-ai-mcp 0.0.36 → 0.0.40
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/.env.example +15 -0
- package/README.md +5 -5
- package/dist/config.js +37 -0
- package/dist/index.js +2 -0
- package/dist/knowledge/access.js +802 -0
- package/dist/knowledge/backendConstraints.js +18 -1
- package/dist/knowledge/case.js +41 -0
- package/dist/knowledge/componentCatalog.js +524 -53
- package/dist/knowledge/componentEvents.js +132 -7
- package/dist/knowledge/connectDataBind.js +851 -0
- package/dist/knowledge/connectDataDefinition.js +344 -0
- package/dist/knowledge/connectDataExecute.js +93 -0
- package/dist/knowledge/connectDataRules.js +128 -0
- package/dist/knowledge/decision.js +121 -0
- package/dist/knowledge/expressionPrelude.js +60 -0
- package/dist/knowledge/layoutSummary.js +140 -2
- package/dist/knowledge/microserviceParameters.js +58 -0
- package/dist/knowledge/mining.js +94 -0
- package/dist/knowledge/mobileComponentCatalog.js +876 -0
- package/dist/knowledge/mobileComponentEvents.js +259 -0
- package/dist/knowledge/mobileStore.js +396 -0
- package/dist/knowledge/normalize.js +240 -72
- package/dist/knowledge/outlines.js +36 -0
- package/dist/knowledge/platform/lint.js +385 -0
- package/dist/knowledge/platform/mobile.js +142 -0
- package/dist/knowledge/platform/mobileLayoutLint.js +324 -0
- package/dist/knowledge/platform/mobileRules.js +231 -0
- package/dist/knowledge/platform/mobileSpacing.js +82 -0
- package/dist/knowledge/platform/mobileTabs.js +108 -0
- package/dist/knowledge/platform/nativeBoxModel.js +44 -0
- package/dist/knowledge/platform/profile.js +25 -0
- package/dist/knowledge/platform/resolve.js +122 -0
- package/dist/knowledge/platform/web.js +39 -0
- package/dist/knowledge/policy.js +18 -4
- package/dist/knowledge/process.js +510 -0
- package/dist/knowledge/reservedTables.js +79 -0
- package/dist/knowledge/rowFilter.js +43 -0
- package/dist/knowledge/rules.js +485 -22
- package/dist/knowledge/schemaGuard.js +11 -0
- package/dist/knowledge/styleResolve.js +64 -10
- package/dist/knowledge/styleResolveNative.js +529 -0
- package/dist/knowledge/themeResolve.js +3 -3
- package/dist/observability/trace.js +13 -5
- package/dist/platform/argumentAliases.js +128 -0
- package/dist/platform/bodyFile.js +103 -0
- package/dist/platform/capture/actions.js +398 -0
- package/dist/platform/capture/browser.js +1 -0
- package/dist/platform/capture/capture.js +683 -0
- package/dist/platform/capture/console-log.js +122 -0
- package/dist/platform/capture/index.js +11 -0
- package/dist/platform/capture/readiness.js +103 -0
- package/dist/platform/capture/summary.js +77 -0
- package/dist/platform/capture/target.js +5 -0
- package/dist/platform/capture/targets/studio-mobile.js +15 -0
- package/dist/platform/capture/targets/studio-web.js +5 -0
- package/dist/platform/diagnostics.js +10 -4
- package/dist/platform/domSummary.js +1 -1
- package/dist/platform/errors.js +163 -10
- package/dist/platform/http.js +29 -8
- package/dist/platform/impersonation.js +45 -0
- package/dist/platform/jsonArray.js +24 -0
- package/dist/platform/responses.js +39 -5
- package/dist/platform/schemaReadMemory.js +60 -0
- package/dist/platform/secrets.js +68 -2
- package/dist/platform/strictArguments.js +68 -12
- package/dist/platform/tokenVault.js +187 -4
- package/dist/resources/examples/bpm-gorev-kontrol.json +294 -0
- package/dist/resources/examples/bpm-iso-dokuman.json +228 -0
- package/dist/resources/examples/bpm-satinalma.json +376 -0
- package/dist/resources/examples/connect-data-convert-verify.json +107 -0
- package/dist/resources/examples/connect-data-dropdown-roles.json +66 -0
- package/dist/resources/examples/connect-data-edit-m2m.json +73 -0
- package/dist/resources/examples/connect-data-query-params.json +50 -0
- package/dist/resources/examples/connect-data-table-entity.json +147 -0
- package/dist/resources/examples/connect-data-workflow-microservice.json +65 -0
- package/dist/resources/examples/middleware-authenticate.json +1 -1
- package/dist/resources/examples/mobile-app-shell-drawer.json +244 -0
- package/dist/resources/examples/mobile-app-shell-stack.json +157 -0
- package/dist/resources/examples/mobile-app-shell-tab.json +208 -0
- package/dist/resources/examples/mobile-form-screen.json +365 -0
- package/dist/resources/examples/mobile-list-detail-form.json +703 -0
- package/dist/resources/examples/page-detail-profile.json +2 -1
- package/dist/resources/examples/page-dynamic-form.json +3 -2
- package/dist/resources/examples/page-flex-sections.json +1 -1
- package/dist/resources/examples/page-html-embed.json +1 -1
- package/dist/resources/examples/workflow-basic.json +8 -2
- package/dist/resources/guides/access.md +810 -0
- package/dist/resources/guides/bpm.md +691 -0
- package/dist/resources/guides/case.md +153 -0
- package/dist/resources/guides/component.md +92 -5
- package/dist/resources/guides/decision.md +185 -0
- package/dist/resources/guides/entity.md +50 -8
- package/dist/resources/guides/expressions.md +14 -5
- package/dist/resources/guides/functions.md +1 -1
- package/dist/resources/guides/getting-started.md +38 -1
- package/dist/resources/guides/layout.md +11 -7
- package/dist/resources/guides/merge.md +42 -7
- package/dist/resources/guides/microservice.md +88 -3
- package/dist/resources/guides/middleware.md +69 -5
- package/dist/resources/guides/mobile-layout.md +193 -0
- package/dist/resources/guides/mobile-publish.md +148 -0
- package/dist/resources/guides/mobile.md +565 -0
- package/dist/resources/guides/page.md +469 -82
- package/dist/resources/guides/theme.md +8 -2
- package/dist/resources/guides/translation.md +1 -1
- package/dist/resources/guides/workflow.md +58 -1
- package/dist/resources/read.js +41 -0
- package/dist/resources/rules.js +11 -5
- package/dist/resources/schema-fingerprint.json +7 -5
- package/dist/resources/schemas/AccessExplanationDto.json +144 -0
- package/dist/resources/schemas/AccessMatrixDto.json +170 -0
- package/dist/resources/schemas/AccessPermissionDto.json +57 -0
- package/dist/resources/schemas/AccessPolicyDto.json +223 -0
- package/dist/resources/schemas/AccessResourceDto.json +86 -0
- package/dist/resources/schemas/AppSessionDto.json +53 -0
- package/dist/resources/schemas/ConnectDataDescribeDto.json +344 -0
- package/dist/resources/schemas/ConnectDataRequestModel.json +202 -0
- package/dist/resources/schemas/ConnectDataResultDto.json +421 -0
- package/dist/resources/schemas/ConnectorCredentialDto.json +70 -0
- package/dist/resources/schemas/ConvertConnectDataToMicroserviceCommand.json +37 -0
- package/dist/resources/schemas/CreateAccessPolicyCommand.json +209 -0
- package/dist/resources/schemas/CreateDecisionCommand.json +221 -0
- package/dist/resources/schemas/CreateEntityCommand.json +118 -0
- package/dist/resources/schemas/CreateMicroserviceCommand.json +13 -1
- package/dist/resources/schemas/CreateProcessDefinitionCommand.json +1337 -0
- package/dist/resources/schemas/CreateQueryCommand.json +4 -0
- package/dist/resources/schemas/CreateWorkflowCommand.json +146 -1
- package/dist/resources/schemas/DataJobDto.json +6 -1
- package/dist/resources/schemas/DecisionDto.json +302 -0
- package/dist/resources/schemas/DetachConnectDataMicroserviceCommand.json +28 -0
- package/dist/resources/schemas/ExplainAccessQuery.json +33 -0
- package/dist/resources/schemas/GenerateProcessDocumentCommand.json +116 -0
- package/dist/resources/schemas/GlobalFunctionUpdateResultDto.json +24 -0
- package/dist/resources/schemas/MicroserviceDto.json +15 -3
- package/dist/resources/schemas/OrganizationProjectDto.json +343 -0
- package/dist/resources/schemas/OrganizationSchemaDto.json +196 -0
- package/dist/resources/schemas/OrganizationSchemaVersionDto.json +207 -0
- package/dist/resources/schemas/PatchProcessDefinitionCommand.json +76 -0
- package/dist/resources/schemas/PreviewMicroserviceCommand.json +10 -1
- package/dist/resources/schemas/PreviewWorkflowCommand.json +25 -1
- package/dist/resources/schemas/ProcessDefinitionDto.json +1480 -0
- package/dist/resources/schemas/ProcessSimulationDto.json +96 -0
- package/dist/resources/schemas/SaveConnectorCredentialCommand.json +90 -0
- package/dist/resources/schemas/SaveProcessEventSourceCommand.json +61 -0
- package/dist/resources/schemas/SaveProcessMailSourceCommand.json +89 -0
- package/dist/resources/schemas/SignProcessTaskCommand.json +73 -0
- package/dist/resources/schemas/SimulateProcessDefinitionQuery.json +92 -0
- package/dist/resources/schemas/StartMobileBuildCommand.json +54 -0
- package/dist/resources/schemas/StepDto.json +25 -1
- package/dist/resources/schemas/UpdateAccessPolicyCommand.json +209 -0
- package/dist/resources/schemas/UpdateDecisionCommand.json +216 -0
- package/dist/resources/schemas/UpdateEntityCommand.json +118 -0
- package/dist/resources/schemas/UpdateMicroserviceCommand.json +13 -1
- package/dist/resources/schemas/UpdateProcessDefinitionCommand.json +1357 -0
- package/dist/resources/schemas/UpdateQueryCommand.json +4 -0
- package/dist/resources/schemas/UpdateViewCommand.json +0 -2
- package/dist/resources/schemas/UpdateWorkflowCommand.json +146 -1
- package/dist/resources/schemas/UpsertMobileStoreSettingsCommand.json +333 -0
- package/dist/resources/schemas/ValidateProcessDefinitionQuery.json +1339 -0
- package/dist/server.js +31 -1
- package/dist/tools/access.js +369 -2
- package/dist/tools/accessOperations.js +135 -0
- package/dist/tools/accessPolicies.js +170 -0
- package/dist/tools/accessRuntime.js +203 -0
- package/dist/tools/applications.js +63 -3
- package/dist/tools/bpm.js +343 -0
- package/dist/tools/bpmGovernance.js +266 -0
- package/dist/tools/bpmOperations.js +230 -0
- package/dist/tools/bpmReporting.js +154 -0
- package/dist/tools/bpmRouting.js +150 -0
- package/dist/tools/bpmRuntime.js +396 -0
- package/dist/tools/case.js +178 -0
- package/dist/tools/caseRuntime.js +89 -0
- package/dist/tools/common.js +19 -6
- package/dist/tools/components.js +118 -14
- package/dist/tools/connectData.js +450 -0
- package/dist/tools/connectors.js +193 -0
- package/dist/tools/datasources.js +3 -3
- package/dist/tools/decisions.js +206 -0
- package/dist/tools/dependencies.js +1 -1
- package/dist/tools/deployments.js +38 -3
- package/dist/tools/designSchemaPatch.js +34 -9
- package/dist/tools/dtos.js +36 -5
- package/dist/tools/entities.js +79 -12
- package/dist/tools/environments.js +1 -1
- package/dist/tools/externalComponents.js +26 -5
- package/dist/tools/flows.js +119 -13
- package/dist/tools/folders.js +1 -1
- package/dist/tools/imports.js +5 -2
- package/dist/tools/layouts.js +50 -17
- package/dist/tools/merges.js +2 -2
- package/dist/tools/microservices.js +77 -25
- package/dist/tools/mobile.js +280 -0
- package/dist/tools/mobileStore.js +572 -0
- package/dist/tools/modules.js +48 -0
- package/dist/tools/organizationStructure.js +137 -0
- package/dist/tools/pages.js +467 -100
- package/dist/tools/platformInfo.js +28 -8
- package/dist/tools/profileWrite.js +92 -0
- package/dist/tools/projects.js +71 -9
- package/dist/tools/rows.js +69 -13
- package/dist/tools/schemaOps.js +61 -1
- package/dist/tools/screenWrite.js +36 -7
- package/dist/tools/screens.js +95 -5
- package/dist/tools/templates.js +26 -1
- package/dist/tools/translations.js +1 -1
- package/dist/tools/variables.js +11 -5
- package/dist/tools/workflows.js +10 -5
- package/package.json +2 -2
- package/dist/platform/screenshot.js +0 -1162
package/dist/platform/secrets.js
CHANGED
|
@@ -1,22 +1,79 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Desen `trace.ts`'in eski kopyasından DARALTILDI: `pass` parçası `passed`/`bypass` gibi
|
|
3
3
|
* anahtarları da yakalıyordu. Günlükte zararsızdı, tool yanıtında veri kaybı olurdu.
|
|
4
|
+
*
|
|
5
|
+
* `cookie` yalnız TAM ad olarak eşleşir (g-01, 37 S-24): paketli şemalarda `StepRuleDto.cookieKey`
|
|
6
|
+
* çerezin ADINI taşır; parça eşleşmesi onu `***` yapıp workflow_get → update turunu bozardı (GW-001).
|
|
7
|
+
* `setcookie` de bilinçli dışarıda: workflow adım tipinin adıdır, sır değildir.
|
|
4
8
|
*/
|
|
5
|
-
export const secretKeyPattern = /password|passwd|secret|token|authorization|api[-_]?key|credential|connection[-_]?string
|
|
9
|
+
export const secretKeyPattern = /password|passwd|secret|token|authorization|api[-_]?key|credential|connection[-_]?string|^cookies?$/i;
|
|
10
|
+
/**
|
|
11
|
+
* Sırrın DEĞERİNİ değil adını, yerini ya da türünü taşıyan anahtarlar: `credentialRef`, `tokenUrl`,
|
|
12
|
+
* `apiKeyHeader`, `secretFields`, `credentialKind`. Maskelenirlerse süreç tanımındaki
|
|
13
|
+
* `connector.credentialRef` get → update turunda `***` olarak geri yazılır ve düğüm kasayı bulamaz
|
|
14
|
+
* (BPM-017, Faz 8 incelemesi). Yalnız yanıt maskesinde uygulanır; günlük maskesi (`trace.ts`) geniş kalır.
|
|
15
|
+
*/
|
|
16
|
+
export const secretNameKeyPattern = /(ref|refs|url|uri|header|fields|kind|name|names|id|ids)$/i;
|
|
6
17
|
import { looksLikeJwt, rememberToken } from './tokenVault.js';
|
|
7
18
|
const maskedValue = '***';
|
|
8
19
|
const maxPaths = 20;
|
|
9
20
|
const maxDepth = 12;
|
|
21
|
+
/**
|
|
22
|
+
* Ad/değer çiftinde `value`'nun yerine geçen ad (g-01, 37 S-24). Debug girdisi isteğin başlık ve
|
|
23
|
+
* çerezlerini `{ expression: 'Authorization', value: 'Bearer …', source, member }` olarak yazar; sırrın
|
|
24
|
+
* adı anahtarda değil kardeş alanda durduğu için anahtar kuralı hiçbirini görmüyordu.
|
|
25
|
+
*
|
|
26
|
+
* `type` ya da `order` taşıyan satır platform TANIMIDIR — `StepQueryParameterDto {name,value,type}`,
|
|
27
|
+
* `StepCustomParameterDto {name,value,order}`, `QueryParameter {name,type,value}`: değer bağlama
|
|
28
|
+
* ifadesidir (`input.token`), maskelenirse get → update turunda `***` geri yazılır (GW-001).
|
|
29
|
+
* `expression` + `value` hiçbir paketli şemada geçmez, o yüzden bu ayrımın dışındadır.
|
|
30
|
+
*/
|
|
31
|
+
export function secretPairName(record) {
|
|
32
|
+
if (!('value' in record))
|
|
33
|
+
return undefined;
|
|
34
|
+
if (typeof record.expression === 'string')
|
|
35
|
+
return record.expression;
|
|
36
|
+
if ('type' in record || 'order' in record)
|
|
37
|
+
return undefined;
|
|
38
|
+
if (typeof record.name === 'string')
|
|
39
|
+
return record.name;
|
|
40
|
+
return typeof record.key === 'string' ? record.key : undefined;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Anahtarsız string yapraktaki kimlik (g-01): `eyJ…` ile başlayan JWT ve `Bearer <jeton>`.
|
|
44
|
+
* `maskSecretText`'ten DAR: o konsol metni içindir ve her üç parçalı noktalı adı JWT sayar —
|
|
45
|
+
* yanıtta `organization.something.localhost` gibi bir adı körleştirirdi. Bearer'dan sonra en az
|
|
46
|
+
* 16 karakter aranır; rehber metnindeki "Bearer olarak" maskelenmez.
|
|
47
|
+
*/
|
|
48
|
+
export function maskSecretLeaf(text) {
|
|
49
|
+
return text
|
|
50
|
+
.replace(/Bearer\s+[A-Za-z0-9._~+/=-]{16,}/gi, `Bearer ${maskedValue}`)
|
|
51
|
+
.replace(/\beyJ[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]*/g, maskedValue);
|
|
52
|
+
}
|
|
10
53
|
function walk(value, path, masked, refs, depth) {
|
|
11
54
|
if (depth > maxDepth)
|
|
12
55
|
return value;
|
|
56
|
+
if (typeof value === 'string') {
|
|
57
|
+
const safe = maskSecretLeaf(value);
|
|
58
|
+
if (safe === value)
|
|
59
|
+
return value;
|
|
60
|
+
if (masked.length < maxPaths)
|
|
61
|
+
masked.push(path);
|
|
62
|
+
if (looksLikeJwt(value) && Object.keys(refs).length < maxPaths)
|
|
63
|
+
refs[path] = rememberToken(value);
|
|
64
|
+
return safe;
|
|
65
|
+
}
|
|
13
66
|
if (Array.isArray(value))
|
|
14
67
|
return value.map((entry, index) => walk(entry, `${path}[${index}]`, masked, refs, depth + 1));
|
|
15
68
|
if (value && typeof value === 'object') {
|
|
16
69
|
const result = {};
|
|
70
|
+
const pairName = secretPairName(value);
|
|
17
71
|
for (const [key, entry] of Object.entries(value)) {
|
|
18
72
|
const child = path === '' ? key : `${path}.${key}`;
|
|
19
|
-
|
|
73
|
+
const name = key === 'value' && pairName !== undefined ? pairName : key;
|
|
74
|
+
// Boole değer sır taşıyamaz: `hasExpoAccessToken: true` maskelenince ajan token'ın kayıtlı
|
|
75
|
+
// olup olmadığını öğrenemiyordu (push bildirimleri g-01, 2026-10-02; GW-001 ailesi).
|
|
76
|
+
if (secretKeyPattern.test(name) && !secretNameKeyPattern.test(name) && typeof entry !== 'boolean' && entry !== null && entry !== undefined && entry !== '') {
|
|
20
77
|
if (masked.length < maxPaths)
|
|
21
78
|
masked.push(child);
|
|
22
79
|
// Maskelenen değer bir JWT ise kimlik testinin yolu kapanmasın: jeton kasada tutulur ve
|
|
@@ -38,3 +95,12 @@ export function maskSecrets(payload) {
|
|
|
38
95
|
const tokenRefs = {};
|
|
39
96
|
return { payload: walk(payload, '', masked, tokenRefs, 0), masked, tokenRefs };
|
|
40
97
|
}
|
|
98
|
+
/**
|
|
99
|
+
* Serbest METİNDEKİ kimlik parçaları (konsol satırı, hata yığını): JWT biçimli dize ve `Bearer …`.
|
|
100
|
+
* `maskSecrets` anahtar adına bakar; tarayıcı konsolu anahtarsız düz metin taşır (g-06).
|
|
101
|
+
*/
|
|
102
|
+
export function maskSecretText(text) {
|
|
103
|
+
return text
|
|
104
|
+
.replace(/Bearer\s+[A-Za-z0-9._~+/=-]+/gi, `Bearer ${maskedValue}`)
|
|
105
|
+
.replace(/\b[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\b/g, maskedValue);
|
|
106
|
+
}
|
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { diagnosticsParam, runWithDiagnostics } from './diagnostics.js';
|
|
3
|
+
import { applyArgumentAliases, closestArgument, runWithArgumentNotes } from './argumentAliases.js';
|
|
4
|
+
import { BODY_FILE_ARGUMENTS, bodyFileParam, loadBodyFile } from './bodyFile.js';
|
|
5
|
+
import { PlatformApiError } from './errors.js';
|
|
6
|
+
import { logError } from '../observability/trace.js';
|
|
7
|
+
/** Doğrulanmış argümanlara takılan çeviri notları (`ArgumentNotes`); JSON'a ve platform isteğine girmez. */
|
|
8
|
+
const ARGUMENT_NOTES = Symbol('argumentNotes');
|
|
3
9
|
/**
|
|
4
10
|
* `writes`/`updates` açıklamalı ama KAYIT yazmayan tool'lar: çalıştırma, önizleme, dışa aktarma, indirme,
|
|
5
11
|
* bağlantı testi. Yanıtlarında yazma tanılaması (silentlyDropped) yoktur; parametre yalnız tool listesini
|
|
@@ -25,25 +31,75 @@ function isRawShape(value) {
|
|
|
25
31
|
* olmayan bir sorgu kusuruna yönlendirdi. Tek tek tool'lara alan eklemek sınıfı kapatmaz; sessizlik
|
|
26
32
|
* burada, SDK'ya şema verilmeden önce kaldırılır.
|
|
27
33
|
*/
|
|
28
|
-
export function rejectUnknownArguments(server) {
|
|
34
|
+
export function rejectUnknownArguments(server, platform) {
|
|
29
35
|
const registerTool = server.registerTool.bind(server);
|
|
36
|
+
// Zorunlu gövde argümanı `bodyFile` açıkken şemada isteğe bağlı yayınlanır (yoksa şemaya uyan istemci
|
|
37
|
+
// gövdeyi satır içinde yollamak zorunda kalır ve `bodyFile` "birlikte verilemez" ile reddedilirdi);
|
|
38
|
+
// zorunluluk dosya okunduktan sonra burada denetlenir.
|
|
39
|
+
const requiredBodies = new Map();
|
|
40
|
+
// g-07/g-08: `bodyFile` ve takma ad tablosu SDK'nın strict doğrulamasından ÖNCE koşmalı — sonra
|
|
41
|
+
// koşsa yanlış ad zaten reddedilmiş, dosyadan gelen gövde doğrulanmamış olur. SDK doğrulamayı
|
|
42
|
+
// `validateToolInput` içinde yapar; çeviri orada uygulanır ve notlar doğrulanmış argümanlara
|
|
43
|
+
// sembol anahtarla takılır.
|
|
44
|
+
if (platform) {
|
|
45
|
+
const validator = server;
|
|
46
|
+
const validate = validator.validateToolInput.bind(server);
|
|
47
|
+
validator.validateToolInput = async (tool, args, name) => {
|
|
48
|
+
try {
|
|
49
|
+
const loaded = await loadBodyFile(name, args, platform.config);
|
|
50
|
+
const requiredBody = requiredBodies.get(name);
|
|
51
|
+
if (requiredBody && loaded.args?.[requiredBody] === undefined) {
|
|
52
|
+
throw new PlatformApiError(`${name}: '${requiredBody}' zorunlu — satır içinde ya da bodyFile ile (.json dosyası) verin. İstek gönderilmedi.`, 400);
|
|
53
|
+
}
|
|
54
|
+
const { args: aliased, applied } = await applyArgumentAliases(name, loaded.args, { platform, shape: tool.inputSchema?.shape ?? {} });
|
|
55
|
+
const parsed = await validate(tool, aliased, name);
|
|
56
|
+
const notes = { aliasesApplied: applied, ...(loaded.note ? { bodyFile: loaded.note } : {}) };
|
|
57
|
+
return (applied.length > 0 || loaded.note) && parsed && typeof parsed === 'object' ? Object.assign(parsed, { [ARGUMENT_NOTES]: notes }) : parsed;
|
|
58
|
+
}
|
|
59
|
+
catch (error) {
|
|
60
|
+
// Doğrulamadan önceki çeviri (dosya, takma ad) `handle`'ın dışında koşar: hata burada günlüğe yazılır.
|
|
61
|
+
if (error instanceof PlatformApiError)
|
|
62
|
+
logError(error);
|
|
63
|
+
throw error;
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
}
|
|
30
67
|
server.registerTool = ((name, config, callback) => {
|
|
31
68
|
if (!isRawShape(config.inputSchema))
|
|
32
69
|
return registerTool(name, config, callback);
|
|
33
|
-
//
|
|
34
|
-
//
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
70
|
+
// Tanılama notları her tool'da compact döner (g-08: okuma ve çalıştırma yanıtında da 8 not +
|
|
71
|
+
// "N not daha"). `diagnostics` parametresi yalnız kayıt yazan tool'lara, microservice_execute'a ve
|
|
72
|
+
// *_preview'a açılır — ötekilerde tool listesini büyütmesin diye varsayılan kullanılır. Parametre
|
|
73
|
+
// handler'a ULAŞMAZ (gövdeyi `...rest` ile platforma geçiren tool'larda sızardı), yalnız
|
|
74
|
+
// toolResult'ın okuduğu bağlama konur.
|
|
75
|
+
const writesRecords = config.annotations?.readOnlyHint === false && config.annotations.destructiveHint !== true && !NON_WRITING_TOOLS.has(name);
|
|
76
|
+
const exposesDiagnostics = writesRecords || name === 'microservice_execute' || name.endsWith('_preview');
|
|
77
|
+
const bodyArgument = BODY_FILE_ARGUMENTS[name];
|
|
78
|
+
const bodySchema = bodyArgument ? config.inputSchema[bodyArgument] : undefined;
|
|
79
|
+
if (bodyArgument && bodySchema && !bodySchema.isOptional())
|
|
80
|
+
requiredBodies.set(name, bodyArgument);
|
|
81
|
+
const shape = {
|
|
82
|
+
...config.inputSchema,
|
|
83
|
+
...(bodyArgument && bodySchema ? { [bodyArgument]: bodySchema.optional(), bodyFile: bodyFileParam(bodyArgument) } : {}),
|
|
84
|
+
...(exposesDiagnostics ? { diagnostics: diagnosticsParam } : {})
|
|
85
|
+
};
|
|
86
|
+
const invoke = (args, extra) => {
|
|
87
|
+
const { diagnostics, ...rest } = exposesDiagnostics ? args ?? {} : { ...args, diagnostics: undefined };
|
|
88
|
+
return runWithDiagnostics(diagnostics === 'full' ? 'full' : 'compact', () => callback(exposesDiagnostics ? rest : args, extra), exposesDiagnostics);
|
|
89
|
+
};
|
|
90
|
+
const run = (args, extra) => {
|
|
91
|
+
const { [ARGUMENT_NOTES]: notes, ...rest } = args ?? {};
|
|
92
|
+
return runWithArgumentNotes(notes ?? { aliasesApplied: [] }, () => invoke(rest, extra));
|
|
93
|
+
};
|
|
43
94
|
const accepted = Object.keys(shape).join(', ');
|
|
95
|
+
const suggestions = (keys) => keys
|
|
96
|
+
.map(key => ({ key, near: closestArgument(key, Object.keys(shape)) }))
|
|
97
|
+
.filter(entry => entry.near !== undefined)
|
|
98
|
+
.map(entry => ` '${entry.key}' → '${entry.near}' mi demek istediniz?`)
|
|
99
|
+
.join('');
|
|
44
100
|
const inputSchema = z.object(shape, {
|
|
45
101
|
errorMap: (issue, context) => issue.code === 'unrecognized_keys'
|
|
46
|
-
? { message: `${name} şu üst düzey argümanları tanımıyor: ${issue.keys.map(key => `'${key}'`).join(', ')}. Tanınmayan alan sessizce yok sayılmaz — çağrı hiç gönderilmedi. Bu tool'un okuduğu alanlar: ${accepted}
|
|
102
|
+
? { message: `${name} şu üst düzey argümanları tanımıyor: ${issue.keys.map(key => `'${key}'`).join(', ')}. Tanınmayan alan sessizce yok sayılmaz — çağrı hiç gönderilmedi. Bu tool'un okuduğu alanlar: ${accepted}.${suggestions(issue.keys)}` }
|
|
47
103
|
: { message: context.defaultError }
|
|
48
104
|
}).strict();
|
|
49
105
|
return registerTool(name, { ...config, inputSchema }, run);
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { PlatformApiError } from './errors.js';
|
|
2
2
|
import { randomBytes } from 'node:crypto';
|
|
3
|
+
import { mkdirSync, readFileSync, renameSync, writeFileSync } from 'node:fs';
|
|
4
|
+
import { dirname, join } from 'node:path';
|
|
5
|
+
import { logStep } from '../observability/trace.js';
|
|
3
6
|
/**
|
|
4
7
|
* `page_screenshot`/`page_runtime_get` açıklaması "jetonu uygulamanın kendi giriş ucundan alın
|
|
5
8
|
* (`microservice_execute`)" diyor, ama gizli alan maskesi `access_token`'ı `***` yapıyor ve o yol
|
|
@@ -9,10 +12,19 @@ import { randomBytes } from 'node:crypto';
|
|
|
9
12
|
* Kasa bu çelişkiyi jetonu bağlama HİÇ sokmadan çözer: maskelenen JWT gateway sürecinde tutulur,
|
|
10
13
|
* yanıta yalnız kısa ömürlü bir referans (`tok_…`) döner ve kimlik isteyen tool'lar referansı
|
|
11
14
|
* çözer. Jeton ne yanıtta ne günlükte açık görünür.
|
|
15
|
+
*
|
|
16
|
+
* g-09 (`plans/mobil-plantcare-acigi`, K9): kasa süreç sınırını aşar. `.env` `MCP_STATE_DIR`
|
|
17
|
+
* verilmişse kayıtlar `token-vault.json`'a (0600) yazılır ve süreç açılışta onu okur; süre
|
|
18
|
+
* `MCP_TOKEN_TTL_MINUTES`'tan gelir (verilmezse eski 15 dk). Dosya YALNIZ lokal hedefte yazılır —
|
|
19
|
+
* uzak bir org'un jetonu diske inmez. Test kullanıcısının (`asUser: 'test:<ad>'`) jetonu da burada,
|
|
20
|
+
* etiketiyle tutulur; aynı kullanıcı TTL boyunca yeniden giriş yapmaz.
|
|
12
21
|
*/
|
|
13
|
-
const
|
|
22
|
+
const legacyTtlMinutes = 15;
|
|
14
23
|
const maxEntries = 64;
|
|
15
24
|
const vault = new Map();
|
|
25
|
+
let ttlMs = legacyTtlMinutes * 60 * 1000;
|
|
26
|
+
let vaultFile;
|
|
27
|
+
let warnedRemote = false;
|
|
16
28
|
export const tokenRefPattern = /^tok_[0-9a-f]{16}$/;
|
|
17
29
|
/** Üç base64url parçalı JWT — parola ya da API anahtarı bu şekle uymaz. */
|
|
18
30
|
export function looksLikeJwt(value) {
|
|
@@ -30,29 +42,132 @@ function sweep(now) {
|
|
|
30
42
|
vault.delete(oldest.value);
|
|
31
43
|
}
|
|
32
44
|
}
|
|
33
|
-
|
|
45
|
+
function isLocalTarget(baseUrl) {
|
|
46
|
+
try {
|
|
47
|
+
const host = new URL(baseUrl).hostname;
|
|
48
|
+
return host === 'localhost' || host === '127.0.0.1' || host === '[::1]' || host.endsWith('.localhost');
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Aynı dosyayı birden çok gateway süreci paylaşır (her Claude Code oturumu kendi stdio sürecini açar).
|
|
56
|
+
* Yazma "son yazan kazanır" olursa bir sürecin kaydı ötekinin yazmasıyla silinirdi: yazmadan önce ve
|
|
57
|
+
* bellekte olmayan referans istenince dosya okunur, süresi dolmamış yabancı kayıtlar belleğe katılır.
|
|
58
|
+
*/
|
|
59
|
+
function mergeFromFile() {
|
|
60
|
+
if (!vaultFile)
|
|
61
|
+
return;
|
|
62
|
+
try {
|
|
63
|
+
const stored = JSON.parse(readFileSync(vaultFile, 'utf8'));
|
|
64
|
+
const now = Date.now();
|
|
65
|
+
for (const [ref, entry] of Object.entries(stored.entries ?? {})) {
|
|
66
|
+
if (!vault.has(ref) && tokenRefPattern.test(ref) && typeof entry.token === 'string' && typeof entry.expires === 'number' && entry.expires > now) {
|
|
67
|
+
vault.set(ref, { token: entry.token, expires: entry.expires, ...(typeof entry.label === 'string' ? { label: entry.label } : {}) });
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
catch {
|
|
72
|
+
// dosya yok ya da okunamadı: bellekteki kasa geçerli
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
function persist() {
|
|
76
|
+
if (!vaultFile)
|
|
77
|
+
return;
|
|
78
|
+
mergeFromFile();
|
|
79
|
+
sweep(Date.now());
|
|
80
|
+
try {
|
|
81
|
+
const temporary = `${vaultFile}.${process.pid}.tmp`;
|
|
82
|
+
mkdirSync(dirname(vaultFile), { recursive: true, mode: 0o700 });
|
|
83
|
+
writeFileSync(temporary, JSON.stringify({ entries: Object.fromEntries(vault) }), { mode: 0o600 });
|
|
84
|
+
renameSync(temporary, vaultFile);
|
|
85
|
+
}
|
|
86
|
+
catch (error) {
|
|
87
|
+
logStep('jeton kasası ✕', `kasa dosyası yazılamadı (${vaultFile}) — jetonlar bu süreçte bellekte kalır`, [error instanceof Error ? error.message : String(error)]);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Süreç açılışında bir kez çağrılır (`index.ts`); testler yeniden başlamayı `clearTokenVault` +
|
|
92
|
+
* bu çağrıyla benzetir. Dosyadaki süresi dolmuş kayıtlar yüklenmez ve dosya onlarsız yeniden yazılır.
|
|
93
|
+
*/
|
|
94
|
+
export function configureTokenVault(config) {
|
|
95
|
+
ttlMs = (config.tokenTtlMinutes ?? legacyTtlMinutes) * 60 * 1000;
|
|
96
|
+
vaultFile = undefined;
|
|
97
|
+
if (!config.stateDirectory)
|
|
98
|
+
return;
|
|
99
|
+
if (!isLocalTarget(config.orgApiBaseUrl)) {
|
|
100
|
+
if (!warnedRemote) {
|
|
101
|
+
warnedRemote = true;
|
|
102
|
+
logStep('jeton kasası', `ORG_API_BASE_URL lokal değil — kasa dosyaya YAZILMAZ, jetonlar yalnız süreç belleğinde tutulur (MCP_STATE_DIR yok sayıldı)`);
|
|
103
|
+
}
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
vaultFile = join(config.stateDirectory, 'token-vault.json');
|
|
107
|
+
persist();
|
|
108
|
+
}
|
|
109
|
+
/** Kasanın geçerli ömrü (dakika) — yanıt notları sabit bir süre yazmasın. */
|
|
110
|
+
export const tokenTtlMinutes = () => Math.round(ttlMs / 60000);
|
|
111
|
+
export function rememberToken(token, label) {
|
|
34
112
|
const now = Date.now();
|
|
35
113
|
sweep(now);
|
|
36
114
|
for (const [ref, entry] of vault) {
|
|
37
115
|
if (entry.token === token) {
|
|
38
116
|
entry.expires = now + ttlMs;
|
|
117
|
+
if (label !== undefined)
|
|
118
|
+
entry.label = label;
|
|
119
|
+
persist();
|
|
39
120
|
return ref;
|
|
40
121
|
}
|
|
41
122
|
}
|
|
42
123
|
const ref = `tok_${randomBytes(8).toString('hex')}`;
|
|
43
|
-
vault.set(ref, { token, expires: now + ttlMs });
|
|
124
|
+
vault.set(ref, { token, expires: now + ttlMs, ...(label !== undefined ? { label } : {}) });
|
|
125
|
+
persist();
|
|
44
126
|
return ref;
|
|
45
127
|
}
|
|
46
128
|
export function resolveToken(reference) {
|
|
129
|
+
if (!vault.has(reference))
|
|
130
|
+
mergeFromFile();
|
|
47
131
|
const entry = vault.get(reference);
|
|
48
132
|
if (!entry)
|
|
49
133
|
return undefined;
|
|
50
134
|
if (entry.expires <= Date.now()) {
|
|
51
135
|
vault.delete(reference);
|
|
136
|
+
persist();
|
|
52
137
|
return undefined;
|
|
53
138
|
}
|
|
54
139
|
return entry.token;
|
|
55
140
|
}
|
|
141
|
+
/**
|
|
142
|
+
* Jetonun kendi süresi (`exp`) kasanın TTL'inden kısa olabilir: uygulamanın jetonu 15 dk yaşarken kasa
|
|
143
|
+
* 60 dk tutuyordu ve süresi dolmuş jetonla çekilen kare sessizce çıkış yapmış sayfayı gösterirdi.
|
|
144
|
+
* 30 sn pay bırakılır; `exp` okunamayan jeton geçerli sayılır (karar uygulamanındır).
|
|
145
|
+
*/
|
|
146
|
+
const jwtExpired = (token) => {
|
|
147
|
+
try {
|
|
148
|
+
const payload = JSON.parse(Buffer.from(token.split('.')[1] ?? '', 'base64url').toString('utf8'));
|
|
149
|
+
return typeof payload.exp === 'number' && payload.exp * 1000 <= Date.now() + 30_000;
|
|
150
|
+
}
|
|
151
|
+
catch {
|
|
152
|
+
return false;
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
function labeledToken(label) {
|
|
156
|
+
const find = () => {
|
|
157
|
+
const now = Date.now();
|
|
158
|
+
for (const entry of vault.values()) {
|
|
159
|
+
if (entry.label === label && entry.expires > now && !jwtExpired(entry.token))
|
|
160
|
+
return entry.token;
|
|
161
|
+
}
|
|
162
|
+
return undefined;
|
|
163
|
+
};
|
|
164
|
+
const found = find();
|
|
165
|
+
if (found || !vaultFile)
|
|
166
|
+
return found;
|
|
167
|
+
mergeFromFile();
|
|
168
|
+
return find();
|
|
169
|
+
}
|
|
170
|
+
/** Bellekteki kasayı boşaltır (süreç yeniden başlamasının benzetimi); dosyaya dokunmaz. */
|
|
56
171
|
export function clearTokenVault() {
|
|
57
172
|
vault.clear();
|
|
58
173
|
}
|
|
@@ -66,8 +181,76 @@ export function resolveIdentityToken(value) {
|
|
|
66
181
|
return value;
|
|
67
182
|
const token = resolveToken(value);
|
|
68
183
|
if (token === undefined) {
|
|
69
|
-
throw new PlatformApiError(`'${value}' referansı geçersiz ya da süresi dolmuş (
|
|
184
|
+
throw new PlatformApiError(`'${value}' referansı geçersiz ya da süresi dolmuş (${Math.round(ttlMs / 60000)} dk). Tercih edilen yol asUser: 'test:<ad>' — gateway kök .env'deki test kullanıcısıyla kendisi giriş yapar. Yoksa uygulamanın giriş ucunu microservice_execute ile yeniden çağırıp yanıttaki tokenRefs değerini kullanın.`, 400);
|
|
185
|
+
}
|
|
186
|
+
return token;
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Giriş yanıtındaki erişim jetonu: yanıt birden çok JWT taşıyabilir (erişim + yenileme). Anahtarı
|
|
190
|
+
* `access` içeren önce, sonra `refresh` içermeyen, en son ilk bulunan — yenileme jetonuyla istek atmak
|
|
191
|
+
* her uçta 401 demekti.
|
|
192
|
+
*/
|
|
193
|
+
function accessJwt(value) {
|
|
194
|
+
const found = [];
|
|
195
|
+
const collect = (node, key, depth) => {
|
|
196
|
+
if (depth > 12)
|
|
197
|
+
return;
|
|
198
|
+
if (looksLikeJwt(node)) {
|
|
199
|
+
found.push({ key, token: node });
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
if (Array.isArray(node))
|
|
203
|
+
node.forEach(entry => collect(entry, key, depth + 1));
|
|
204
|
+
else if (node && typeof node === 'object')
|
|
205
|
+
Object.entries(node).forEach(([name, entry]) => collect(entry, name, depth + 1));
|
|
206
|
+
};
|
|
207
|
+
collect(value, '', 0);
|
|
208
|
+
return (found.find(entry => /access/i.test(entry.key)) ?? found.find(entry => !/refresh/i.test(entry.key)) ?? found[0])?.token;
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* g-09: `asUser` üç şekil alır — ham JWT, `tok_…` referansı ve `test:<ad>`. Üçüncüsünde gateway kök
|
|
212
|
+
* `.env`'deki `MCP_TEST_USER_<AD>` satırının tarif ettiği giriş ucunu (uygulamanın kendi uç'u)
|
|
213
|
+
* anonim çağırır, yanıttaki ilk JWT'yi kasaya etiketiyle koyar ve TTL boyunca yeniden kullanır.
|
|
214
|
+
* Parola ne yanıta, ne günlüğe (`hideRequestBody`), ne hata metnine girer; satırın değeri hiçbir
|
|
215
|
+
* mesajda gösterilmez. AI `.env`'i düzenlemez: tanımsız kullanıcı, insanın ekleyeceği değişkenin
|
|
216
|
+
* adıyla reddedilir.
|
|
217
|
+
*/
|
|
218
|
+
export async function resolveIdentity(value, platform, project, environment) {
|
|
219
|
+
if (value === undefined || !value.startsWith('test:'))
|
|
220
|
+
return resolveIdentityToken(value);
|
|
221
|
+
const name = value.slice('test:'.length).trim().toLowerCase();
|
|
222
|
+
const variable = `MCP_TEST_USER_${name.toUpperCase()}`;
|
|
223
|
+
const label = `test:${name}@${platform.resolveProject(project)}/${environment ?? platform.config.defaultEnvironment}`;
|
|
224
|
+
const cached = labeledToken(label);
|
|
225
|
+
if (cached)
|
|
226
|
+
return cached;
|
|
227
|
+
const raw = platform.config.testUsers[name];
|
|
228
|
+
if (!raw) {
|
|
229
|
+
const defined = Object.keys(platform.config.testUsers);
|
|
230
|
+
throw new PlatformApiError(`Test kullanıcısı '${name}' tanımlı değil. Kök .env'e insan ekler: ${variable}={"application":"<uygulama slug>","microservice":"<giriş ucu slug>","body":{…giriş gövdesi…}} (biçim: docs/ortam.md §Test kullanıcıları); gateway yeniden başlatılır. AI .env'i düzenlemez. Tanımlı olanlar: ${defined.length > 0 ? defined.join(', ') : '(yok)'}.`, 400);
|
|
231
|
+
}
|
|
232
|
+
let login;
|
|
233
|
+
try {
|
|
234
|
+
login = JSON.parse(raw);
|
|
235
|
+
}
|
|
236
|
+
catch {
|
|
237
|
+
throw new PlatformApiError(`${variable} JSON olarak okunamadı (değer gösterilmez). Biçim: {"application":"…","microservice":"…","body":{…}} — docs/ortam.md §Test kullanıcıları.`, 400);
|
|
238
|
+
}
|
|
239
|
+
if (typeof login.application !== 'string' || typeof login.microservice !== 'string') {
|
|
240
|
+
throw new PlatformApiError(`${variable} 'application' ve 'microservice' alanlarını taşımalı (değer gösterilmez) — docs/ortam.md §Test kullanıcıları.`, 400);
|
|
241
|
+
}
|
|
242
|
+
const endpoint = `${login.application}/${login.microservice}`;
|
|
243
|
+
const response = await platform.tenantRaw(typeof login.method === 'string' ? login.method : 'POST', project, `/m/${endpoint}`, {
|
|
244
|
+
environment,
|
|
245
|
+
body: login.body,
|
|
246
|
+
anonymous: true,
|
|
247
|
+
hideRequestBody: true
|
|
248
|
+
});
|
|
249
|
+
const token = accessJwt(response.body);
|
|
250
|
+
if (!token) {
|
|
251
|
+
throw new PlatformApiError(`Test kullanıcısı '${name}' girişi jeton döndürmedi: ${endpoint} HTTP ${response.httpStatus}. Kök .env'deki ${variable} satırını (uç ve gövde) ve kullanıcının uygulamada var olduğunu kontrol edin; gövde ve kimlik bilgisi gösterilmez.`, 400);
|
|
70
252
|
}
|
|
253
|
+
rememberToken(token, label);
|
|
71
254
|
return token;
|
|
72
255
|
}
|
|
73
256
|
/**
|