@nextclaw/app-runtime 0.15.0 → 0.16.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.
- package/dist/index.d.ts +3 -3
- package/dist/package.js +1 -1
- package/dist/services/app-grant.service.d.ts.map +1 -1
- package/dist/services/app-grant.service.js +1 -4
- package/dist/services/app-grant.service.js.map +1 -1
- package/dist/services/app-installation-lifecycle.service.js +29 -2
- package/dist/services/app-installation-lifecycle.service.js.map +1 -1
- package/dist/services/app-manifest.service.d.ts +1 -0
- package/dist/services/app-manifest.service.d.ts.map +1 -1
- package/dist/services/app-manifest.service.js +27 -0
- package/dist/services/app-manifest.service.js.map +1 -1
- package/dist/services/app-permissions.service.d.ts.map +1 -1
- package/dist/services/app-permissions.service.js +0 -3
- package/dist/services/app-permissions.service.js.map +1 -1
- package/dist/services/app-registry-parser.service.js +200 -0
- package/dist/services/app-registry-parser.service.js.map +1 -0
- package/dist/services/app-registry.service.d.ts +4 -9
- package/dist/services/app-registry.service.d.ts.map +1 -1
- package/dist/services/app-registry.service.js +40 -164
- package/dist/services/app-registry.service.js.map +1 -1
- package/dist/services/app-rust-wasi-scaffold-template.service.d.ts.map +1 -1
- package/dist/services/app-rust-wasi-scaffold-template.service.js +37 -0
- package/dist/services/app-rust-wasi-scaffold-template.service.js.map +1 -1
- package/dist/types/app-manifest.types.d.ts +8 -1
- package/dist/types/app-manifest.types.d.ts.map +1 -1
- package/dist/types/app-manifest.types.js.map +1 -1
- package/dist/types/app-registry.types.d.ts +8 -1
- package/dist/types/app-registry.types.d.ts.map +1 -1
- package/package.json +1 -1
- package/resources/wit/deps/clocks@0.2.6/monotonic-clock.wit +50 -0
- package/resources/wit/deps/clocks@0.2.6/timezone.wit +55 -0
- package/resources/wit/deps/clocks@0.2.6/wall-clock.wit +46 -0
- package/resources/wit/deps/clocks@0.2.6/world.wit +11 -0
- package/resources/wit/deps/config@0.2.0-draft-2024-09-27/package.wit +1 -0
- package/resources/wit/deps/config@0.2.0-draft-2024-09-27/store.wit +9 -0
- package/resources/wit/deps/http@0.2.6/handler.wit +49 -0
- package/resources/wit/deps/http@0.2.6/package.wit +1 -0
- package/resources/wit/deps/http@0.2.6/types.wit +688 -0
- package/resources/wit/deps/io@0.2.6/error.wit +34 -0
- package/resources/wit/deps/io@0.2.6/poll.wit +47 -0
- package/resources/wit/deps/io@0.2.6/streams.wit +290 -0
- package/resources/wit/deps/io@0.2.6/world.wit +10 -0
- package/resources/wit/deps/spin@2.0.0/package.wit +1 -0
- package/resources/wit/deps/spin@2.0.0/sqlite.wit +50 -0
- package/resources/wit/portable-service.wit +73 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app-registry.service.js","names":[],"sources":["../../src/services/app-registry.service.ts"],"sourcesContent":["import { open, readFile, rename, rm } from \"node:fs/promises\";\nimport path from \"node:path\";\nimport type {\n AppPermissions,\n AppPlatformSecuritySummary,\n AppResolvedComponent,\n} from \"#app-runtime/types/app-manifest.types.js\";\nimport type { AppDocumentGrantMap } from \"#app-runtime/types/app-permissions.types.js\";\nimport { AppHomeService } from \"#app-runtime/services/app-home.service.js\";\nimport { AppInstanceStorageService } from \"#app-runtime/services/app-instance-storage.service.js\";\nimport { AppPlatformTargetService } from \"#app-runtime/services/app-platform-target.service.js\";\nimport { FileLockService } from \"#app-runtime/services/file-lock.service.js\";\nimport type { AppInstanceRecord } from \"#app-runtime/types/app-storage.types.js\";\nimport type {\n AppInstallSourceKind,\n AppRegistry,\n AppRegistryAppRecord,\n AppRegistryInstalledVersion,\n} from \"#app-runtime/types/app-registry.types.js\";\n\nconst SAFE_APP_ID_PATTERN = /^[a-z0-9]+(?:[.-][a-z0-9]+)*$/;\nconst SAFE_VERSION_PATTERN = /^[0-9A-Za-z]+(?:[._+-][0-9A-Za-z]+)*$/;\nconst SAFE_COMPONENT_ID_PATTERN = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;\n\nexport class AppRegistryService {\n private readonly instanceStorageService: AppInstanceStorageService;\n private readonly fileLockService = new FileLockService();\n private readonly platformTargetService = new AppPlatformTargetService();\n\n constructor(private readonly appHomeService: AppHomeService = new AppHomeService()) {\n this.instanceStorageService = new AppInstanceStorageService(appHomeService);\n }\n\n load = async (): Promise<AppRegistry> => {\n try {\n const raw = await readFile(this.appHomeService.getRegistryPath(), \"utf-8\");\n return this.parseRegistry(JSON.parse(raw) as unknown);\n } catch (error) {\n if (this.isMissingFileError(error)) {\n return { schemaVersion: 1, apps: {}, suppressedBuiltIns: {} };\n }\n throw error;\n }\n };\n\n save = async (registry: AppRegistry): Promise<void> => {\n await this.withMutation(async () => await this.saveUnlocked(registry));\n };\n\n private saveUnlocked = async (registry: AppRegistry): Promise<void> => {\n await this.appHomeService.ensureBaseDirectories();\n const registryPath = this.appHomeService.getRegistryPath();\n const temporaryPath = path.join(\n path.dirname(registryPath),\n `.${path.basename(registryPath)}.${process.pid}.${Date.now()}.tmp`,\n );\n const handle = await open(temporaryPath, \"wx\", 0o600);\n try {\n await handle.writeFile(`${JSON.stringify(registry, null, 2)}\\n`, \"utf-8\");\n await handle.sync();\n } finally {\n await handle.close();\n }\n try {\n await rename(temporaryPath, registryPath);\n } catch (error) {\n await rm(temporaryPath, { force: true });\n throw error;\n }\n };\n\n listApps = async (): Promise<AppRegistryAppRecord[]> => {\n const registry = await this.load();\n return Object.values(registry.apps).sort((left, right) => left.appId.localeCompare(right.appId));\n };\n\n getApp = async (appId: string): Promise<AppRegistryAppRecord | undefined> => {\n const registry = await this.load();\n return registry.apps[appId];\n };\n\n getActiveVersion = async (appId: string): Promise<AppRegistryInstalledVersion | undefined> => {\n const appRecord = await this.getApp(appId);\n return appRecord?.installedVersions[appRecord.activeVersion];\n };\n\n upsertInstallation = async (params: {\n appId: string;\n name: string;\n description?: string;\n version: string;\n installDirectory: string;\n defaultInstance: AppInstanceRecord;\n sourceKind: AppInstallSourceKind;\n sourceRef: string;\n installedAt: string;\n distributionMode?: AppRegistryInstalledVersion[\"distributionMode\"];\n permissions: AppPermissions;\n registryUrl?: string;\n bundleUrl?: string;\n sha256?: string;\n target?: AppRegistryInstalledVersion[\"target\"];\n publisher?: AppRegistryInstalledVersion[\"publisher\"];\n manifestSchemaVersion: 1 | 2;\n components?: AppResolvedComponent[];\n primaryPanelId?: string;\n security?: AppPlatformSecuritySummary;\n dataSchemaVersion: number;\n contentSha256?: string;\n enabled?: boolean;\n activate?: boolean;\n }): Promise<AppRegistryAppRecord> => {\n return await this.withMutation(async () => {\n const registry = await this.load();\n const currentRecord = registry.apps[params.appId];\n const currentPublisher = currentRecord?.publisher ??\n currentRecord?.installedVersions[currentRecord.activeVersion]?.publisher;\n if (currentPublisher && currentPublisher.id !== params.publisher?.id) {\n throw new Error(\n `应用 ${params.appId} 已绑定发布者 ${currentPublisher.id},拒绝由 ${params.publisher?.id ?? \"未验证本地来源\"} 覆盖。`,\n );\n }\n const nextRecord: AppRegistryAppRecord = {\n appId: params.appId,\n name: params.name,\n description: params.description,\n publisher: currentPublisher ?? params.publisher,\n activeVersion: params.activate === false && currentRecord\n ? currentRecord.activeVersion\n : params.version,\n enabled: params.enabled ?? currentRecord?.enabled ?? params.manifestSchemaVersion === 1,\n dataDirectory: params.defaultInstance.storage.dataDirectory,\n defaultInstance: params.defaultInstance,\n installedVersions: {\n ...(currentRecord?.installedVersions ?? {}),\n [params.version]: {\n version: params.version,\n installDirectory: params.installDirectory,\n sourceKind: params.sourceKind,\n sourceRef: params.sourceRef,\n installedAt: params.installedAt,\n distributionMode: params.distributionMode,\n permissions: params.permissions,\n registryUrl: params.registryUrl,\n bundleUrl: params.bundleUrl,\n sha256: params.sha256,\n target: params.target,\n publisher: params.publisher,\n manifestSchemaVersion: params.manifestSchemaVersion,\n components: params.components,\n primaryPanelId: params.primaryPanelId,\n security: params.security,\n dataSchemaVersion: params.dataSchemaVersion,\n contentSha256: params.contentSha256,\n },\n },\n grants: currentRecord?.grants ?? {},\n };\n registry.apps[params.appId] = nextRecord;\n await this.saveUnlocked(registry);\n return nextRecord;\n });\n };\n\n setEnabled = async (appId: string, enabled: boolean): Promise<AppRegistryAppRecord> => {\n return await this.updateApp(appId, (record) => ({ ...record, enabled }));\n };\n\n activateVersion = async (\n appId: string,\n version: string,\n ): Promise<AppRegistryAppRecord> => {\n return await this.updateApp(appId, (record) => {\n if (!record.installedVersions[version]) {\n throw new Error(`应用 ${appId} 未安装版本 ${version}。`);\n }\n return { ...record, activeVersion: version };\n });\n };\n\n setVersionContentDigest = async (\n appId: string,\n version: string,\n contentSha256: string,\n ): Promise<AppRegistryAppRecord> => {\n return await this.updateApp(appId, (record) => {\n const installedVersion = record.installedVersions[version];\n if (!installedVersion) {\n throw new Error(`应用 ${appId} 未安装版本 ${version}。`);\n }\n if (installedVersion.contentSha256 && installedVersion.contentSha256 !== contentSha256) {\n throw new Error(`应用 ${appId}@${version} 已存在不同的代码完整性摘要。`);\n }\n return {\n ...record,\n installedVersions: {\n ...record.installedVersions,\n [version]: { ...installedVersion, contentSha256 },\n },\n };\n });\n };\n\n updateGrants = async (\n appId: string,\n grants: AppDocumentGrantMap,\n ): Promise<AppRegistryAppRecord> => {\n return await this.updateApp(appId, (record) => ({\n ...record,\n grants: { ...record.grants, ...grants },\n }));\n };\n\n setDocumentGrant = async (\n appId: string,\n scopeId: string,\n directoryPath: string,\n ): Promise<AppRegistryAppRecord> => {\n return await this.updateGrants(appId, { [scopeId]: directoryPath });\n };\n\n removeDocumentGrant = async (appId: string, scopeId: string): Promise<boolean> => {\n let removed = false;\n await this.updateApp(appId, (record) => {\n if (!(scopeId in record.grants)) {\n return record;\n }\n const grants = { ...record.grants };\n delete grants[scopeId];\n removed = true;\n return { ...record, grants };\n });\n return removed;\n };\n\n removeApp = async (appId: string): Promise<AppRegistryAppRecord | undefined> => {\n return await this.withMutation(async () => {\n const registry = await this.load();\n const appRecord = registry.apps[appId];\n if (!appRecord) {\n return undefined;\n }\n delete registry.apps[appId];\n await this.saveUnlocked(registry);\n return appRecord;\n });\n };\n\n isBuiltInSuppressed = async (appId: string): Promise<boolean> => {\n const registry = await this.load();\n return Boolean(registry.suppressedBuiltIns[appId]);\n };\n\n setBuiltInSuppressed = async (appId: string, suppressed: boolean): Promise<void> => {\n await this.withMutation(async () => {\n const registry = await this.load();\n if (suppressed) {\n registry.suppressedBuiltIns[appId] = { suppressedAt: new Date().toISOString() };\n } else {\n delete registry.suppressedBuiltIns[appId];\n }\n await this.saveUnlocked(registry);\n });\n };\n\n private updateApp = async (\n appId: string,\n update: (record: AppRegistryAppRecord) => AppRegistryAppRecord,\n ): Promise<AppRegistryAppRecord> => {\n return await this.withMutation(async () => {\n const registry = await this.load();\n const appRecord = registry.apps[appId];\n if (!appRecord) {\n throw new Error(`未找到已安装应用:${appId}`);\n }\n const nextRecord = update(appRecord);\n registry.apps[appId] = nextRecord;\n await this.saveUnlocked(registry);\n return nextRecord;\n });\n };\n\n private withMutation = async <T>(operation: () => Promise<T>): Promise<T> => {\n const registryPath = path.resolve(this.appHomeService.getRegistryPath());\n return await this.fileLockService.withLock(`${registryPath}.lock`, operation);\n };\n\n private parseRegistry = (rawRegistry: unknown): AppRegistry => {\n const candidate = this.assertRecord(rawRegistry, \"registry.json\");\n if (candidate.schemaVersion !== 1) {\n throw new Error(\"当前只支持 registry schemaVersion = 1。\");\n }\n const rawApps = this.assertRecord(candidate.apps, \"registry.apps\");\n const apps: Record<string, AppRegistryAppRecord> = {};\n for (const [appId, rawApp] of Object.entries(rawApps)) {\n if (!SAFE_APP_ID_PATTERN.test(appId)) {\n throw new Error(`registry.apps 包含不安全的 appId:${appId}`);\n }\n const app = this.assertRecord(rawApp, `registry.apps.${appId}`) as Partial<AppRegistryAppRecord>;\n const installedVersions: Record<string, AppRegistryInstalledVersion> = {};\n const rawVersions = this.assertRecord(\n app.installedVersions,\n `registry.apps.${appId}.installedVersions`,\n );\n for (const [version, rawVersion] of Object.entries(rawVersions)) {\n if (!SAFE_VERSION_PATTERN.test(version)) {\n throw new Error(`registry.apps.${appId} 包含不安全的版本:${version}`);\n }\n const versionRecord = this.assertRecord(\n rawVersion,\n `registry.apps.${appId}.installedVersions.${version}`,\n ) as Partial<AppRegistryInstalledVersion>;\n const installDirectory = this.requireString(\n versionRecord.installDirectory,\n `registry.apps.${appId}.installedVersions.${version}.installDirectory`,\n );\n this.assertExactPath(\n installDirectory,\n this.appHomeService.getInstallDirectory(appId, version),\n `registry.apps.${appId}.installedVersions.${version}.installDirectory`,\n );\n installedVersions[version] = {\n ...(versionRecord as AppRegistryInstalledVersion),\n version,\n installDirectory: path.resolve(installDirectory),\n manifestSchemaVersion: versionRecord.manifestSchemaVersion === 2 ? 2 : 1,\n target: versionRecord.target === undefined\n ? undefined\n : this.platformTargetService.parseArtifactTarget(\n versionRecord.target,\n `registry.apps.${appId}.installedVersions.${version}.target`,\n ),\n components: this.parseComponents(\n versionRecord.components,\n installDirectory,\n `registry.apps.${appId}.installedVersions.${version}.components`,\n ),\n dataSchemaVersion: typeof versionRecord.dataSchemaVersion === \"number\" &&\n Number.isSafeInteger(versionRecord.dataSchemaVersion) &&\n versionRecord.dataSchemaVersion > 0\n ? versionRecord.dataSchemaVersion\n : 1,\n };\n }\n const activeVersion = this.requireString(app.activeVersion, `registry.apps.${appId}.activeVersion`);\n if (!installedVersions[activeVersion]) {\n throw new Error(`registry.apps.${appId} 缺少 activeVersion ${activeVersion}。`);\n }\n const dataDirectory = this.requireString(\n app.dataDirectory,\n `registry.apps.${appId}.dataDirectory`,\n );\n const firstInstalledAt = Object.values(installedVersions)\n .map((version) => version.installedAt)\n .filter((value): value is string => typeof value === \"string\")\n .sort()[0] ?? new Date(0).toISOString();\n const defaultInstance = this.parseDefaultInstance(\n app.defaultInstance,\n appId,\n dataDirectory,\n firstInstalledAt,\n );\n apps[appId] = {\n ...(app as AppRegistryAppRecord),\n appId,\n publisher: app.publisher ?? installedVersions[activeVersion]?.publisher,\n enabled: typeof app.enabled === \"boolean\" ? app.enabled : true,\n activeVersion,\n dataDirectory: defaultInstance.storage.dataDirectory,\n defaultInstance,\n installedVersions,\n grants: app.grants && typeof app.grants === \"object\" ? app.grants : {},\n };\n }\n const suppressedBuiltIns = candidate.suppressedBuiltIns &&\n typeof candidate.suppressedBuiltIns === \"object\" &&\n !Array.isArray(candidate.suppressedBuiltIns)\n ? Object.fromEntries(Object.entries(candidate.suppressedBuiltIns).flatMap(([appId, raw]) => {\n if (!raw || typeof raw !== \"object\" || Array.isArray(raw)) {\n return [];\n }\n const suppressedAt = (raw as { suppressedAt?: unknown }).suppressedAt;\n return typeof suppressedAt === \"string\" ? [[appId, { suppressedAt }]] : [];\n }))\n : {};\n return { schemaVersion: 1, apps, suppressedBuiltIns };\n };\n\n private parseDefaultInstance = (\n rawInstance: unknown,\n appId: string,\n dataDirectory: string,\n createdAt: string,\n ): AppInstanceRecord => {\n if (!rawInstance || typeof rawInstance !== \"object\" || Array.isArray(rawInstance)) {\n this.assertExactPath(\n dataDirectory,\n this.appHomeService.getAppDataDirectory(appId),\n `registry.apps.${appId}.dataDirectory`,\n );\n return this.instanceStorageService.buildLegacyDefaultInstance({\n appId,\n dataDirectory,\n createdAt,\n });\n }\n const instance = rawInstance as Partial<AppInstanceRecord>;\n if (\n instance.id !== \"default\" ||\n !instance.storage ||\n typeof instance.storage !== \"object\" ||\n (instance.storage.layout !== \"legacy\" && instance.storage.layout !== \"instance-v1\")\n ) {\n throw new Error(`registry.apps.${appId}.defaultInstance 无效。`);\n }\n if (instance.publisherId !== undefined && typeof instance.publisherId !== \"string\") {\n throw new Error(`registry.apps.${appId}.defaultInstance.publisherId 无效。`);\n }\n const dataSchemaVersion = typeof instance.dataSchemaVersion === \"number\" &&\n Number.isSafeInteger(instance.dataSchemaVersion) &&\n instance.dataSchemaVersion > 0\n ? instance.dataSchemaVersion\n : 1;\n const instanceCreatedAt = typeof instance.createdAt === \"string\"\n ? instance.createdAt\n : createdAt;\n const instanceDirectory = path.resolve(\n this.appHomeService.getAppInstanceDirectory(appId, \"default\"),\n );\n const expectedStorage = {\n layout: \"instance-v1\" as const,\n layoutVersion: 1 as const,\n instanceId: \"default\",\n instanceDirectory,\n dataDirectory: path.join(instanceDirectory, \"data\"),\n configDirectory: path.join(instanceDirectory, \"config\"),\n stateDirectory: path.join(instanceDirectory, \"state\"),\n cacheDirectory: path.join(instanceDirectory, \"cache\"),\n temporaryDirectory: path.join(instanceDirectory, \"tmp\"),\n logsDirectory: path.join(instanceDirectory, \"logs\"),\n };\n if (instance.storage.layout === \"legacy\") {\n const expectedLegacyDataDirectory = this.appHomeService.getAppDataDirectory(appId);\n this.assertExactPath(\n dataDirectory,\n expectedLegacyDataDirectory,\n `registry.apps.${appId}.dataDirectory`,\n );\n return {\n id: \"default\",\n publisherId: instance.publisherId,\n storage: {\n ...expectedStorage,\n layout: \"legacy\",\n dataDirectory: path.resolve(expectedLegacyDataDirectory),\n },\n dataSchemaVersion,\n createdAt: instanceCreatedAt,\n migratedAt: instance.migratedAt,\n legacyDataDirectory: path.resolve(expectedLegacyDataDirectory),\n };\n }\n for (const [field, expectedPath] of Object.entries({\n instanceDirectory: expectedStorage.instanceDirectory,\n dataDirectory: expectedStorage.dataDirectory,\n configDirectory: expectedStorage.configDirectory,\n stateDirectory: expectedStorage.stateDirectory,\n cacheDirectory: expectedStorage.cacheDirectory,\n temporaryDirectory: expectedStorage.temporaryDirectory,\n logsDirectory: expectedStorage.logsDirectory,\n })) {\n this.assertExactPath(\n instance.storage[field as keyof typeof instance.storage] as string,\n expectedPath,\n `registry.apps.${appId}.defaultInstance.storage.${field}`,\n );\n }\n this.assertExactPath(\n dataDirectory,\n expectedStorage.dataDirectory,\n `registry.apps.${appId}.dataDirectory`,\n );\n return {\n id: \"default\",\n publisherId: instance.publisherId,\n storage: expectedStorage,\n dataSchemaVersion,\n createdAt: instanceCreatedAt,\n migratedAt: instance.migratedAt,\n legacyDataDirectory: instance.legacyDataDirectory,\n };\n };\n\n private assertExactPath = (actual: unknown, expected: string, field: string): void => {\n if (typeof actual !== \"string\" || path.resolve(actual) !== path.resolve(expected)) {\n throw new Error(`${field} 必须位于受管路径 ${path.resolve(expected)}。`);\n }\n };\n\n private parseComponents = (\n rawComponents: unknown,\n installDirectory: string,\n field: string,\n ): AppResolvedComponent[] | undefined => {\n if (rawComponents === undefined) {\n return undefined;\n }\n if (!Array.isArray(rawComponents)) {\n throw new Error(`${field} 必须是数组。`);\n }\n return rawComponents.map((rawComponent, index) => {\n const component = this.assertRecord(rawComponent, `${field}[${index}]`);\n const kind = component.kind;\n if (kind !== \"panel\" && kind !== \"service\") {\n throw new Error(`${field}[${index}].kind 无效。`);\n }\n const id = this.requireString(component.id, `${field}[${index}].id`);\n if (!SAFE_COMPONENT_ID_PATTERN.test(id)) {\n throw new Error(`${field}[${index}].id 不安全。`);\n }\n const relativeComponentPath = this.requireString(\n component.path,\n `${field}[${index}].path`,\n );\n const expectedComponentDirectory = path.resolve(installDirectory, relativeComponentPath);\n const relativeToInstall = path.relative(\n path.resolve(installDirectory),\n expectedComponentDirectory,\n );\n if (\n !relativeToInstall ||\n relativeToInstall.startsWith(\"..\") ||\n path.isAbsolute(relativeToInstall)\n ) {\n throw new Error(`${field}[${index}].path 必须位于版本目录内。`);\n }\n const expectedManifestPath = path.join(\n expectedComponentDirectory,\n kind === \"panel\" ? \"panel-app.json\" : \"service-app.json\",\n );\n this.assertExactPath(\n component.componentDirectory,\n expectedComponentDirectory,\n `${field}[${index}].componentDirectory`,\n );\n this.assertExactPath(\n component.manifestPath,\n expectedManifestPath,\n `${field}[${index}].manifestPath`,\n );\n return {\n kind,\n id,\n path: relativeComponentPath,\n componentDirectory: expectedComponentDirectory,\n manifestPath: expectedManifestPath,\n };\n });\n };\n\n private assertRecord = (value: unknown, field: string): Record<string, unknown> => {\n if (!value || typeof value !== \"object\" || Array.isArray(value)) {\n throw new Error(`${field} 必须是对象。`);\n }\n return value as Record<string, unknown>;\n };\n\n private requireString = (value: unknown, field: string): string => {\n if (typeof value !== \"string\" || !value.trim()) {\n throw new Error(`${field} 必须是非空字符串。`);\n }\n return value;\n };\n\n private isMissingFileError = (error: unknown): boolean =>\n typeof error === \"object\" && error !== null &&\n \"code\" in error && (error as { code?: unknown }).code === \"ENOENT\";\n}\n"],"mappings":";;;;;;;AAoBA,MAAM,sBAAsB;AAC5B,MAAM,uBAAuB;AAC7B,MAAM,4BAA4B;AAElC,IAAa,qBAAb,MAAgC;CAC9B;CACA,kBAAmC,IAAI,iBAAiB;CACxD,wBAAyC,IAAI,0BAA0B;CAEvE,YAAY,iBAAkD,IAAI,gBAAgB,EAAE;AAAvD,OAAA,iBAAA;AAC3B,OAAK,yBAAyB,IAAI,0BAA0B,eAAe;;CAG7E,OAAO,YAAkC;AACvC,MAAI;GACF,MAAM,MAAM,MAAM,SAAS,KAAK,eAAe,iBAAiB,EAAE,QAAQ;AAC1E,UAAO,KAAK,cAAc,KAAK,MAAM,IAAI,CAAY;WAC9C,OAAO;AACd,OAAI,KAAK,mBAAmB,MAAM,CAChC,QAAO;IAAE,eAAe;IAAG,MAAM,EAAE;IAAE,oBAAoB,EAAE;IAAE;AAE/D,SAAM;;;CAIV,OAAO,OAAO,aAAyC;AACrD,QAAM,KAAK,aAAa,YAAY,MAAM,KAAK,aAAa,SAAS,CAAC;;CAGxE,eAAuB,OAAO,aAAyC;AACrE,QAAM,KAAK,eAAe,uBAAuB;EACjD,MAAM,eAAe,KAAK,eAAe,iBAAiB;EAC1D,MAAM,gBAAgB,KAAK,KACzB,KAAK,QAAQ,aAAa,EAC1B,IAAI,KAAK,SAAS,aAAa,CAAC,GAAG,QAAQ,IAAI,GAAG,KAAK,KAAK,CAAC,MAC9D;EACD,MAAM,SAAS,MAAM,KAAK,eAAe,MAAM,IAAM;AACrD,MAAI;AACF,SAAM,OAAO,UAAU,GAAG,KAAK,UAAU,UAAU,MAAM,EAAE,CAAC,KAAK,QAAQ;AACzE,SAAM,OAAO,MAAM;YACX;AACR,SAAM,OAAO,OAAO;;AAEtB,MAAI;AACF,SAAM,OAAO,eAAe,aAAa;W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M,YAAY;GAEhD,MAAM,KAAK,KAAK,cAAc,UAAU,IAAI,GAAG,MAAM,GAAG,MAAM,MAAM;AACpE,OAAI,CAAC,0BAA0B,KAAK,GAAG,CACrC,OAAM,IAAI,MAAM,GAAG,MAAM,GAAG,MAAM,WAAW;GAE/C,MAAM,wBAAwB,KAAK,cACjC,UAAU,MACV,GAAG,MAAM,GAAG,MAAM,QACnB;GACD,MAAM,6BAA6B,KAAK,QAAQ,kBAAkB,sBAAsB;GACxF,MAAM,oBAAoB,KAAK,SAC7B,KAAK,QAAQ,iBAAiB,EAC9B,2BACD;AACD,OACE,CAAC,qBACD,kBAAkB,WAAW,KAAK,IAClC,KAAK,WAAW,kBAAkB,CAElC,OAAM,IAAI,MAAM,GAAG,MAAM,GAAG,MAAM,mBAAmB;GAEvD,MAAM,uBAAuB,KAAK,KAChC,4BACA,SAAS,UAAU,mBAAmB,mBACvC;AACD,QAAK,gBACH,UAAU,oBACV,4BACA,GAAG,MAAM,GAAG,MAAM,sBACnB;AACD,QAAK,gBACH,UAAU,cACV,sBACA,GAAG,MAAM,GAAG,MAAM,gBACnB;AACD,UAAO;IACL;IACA;IACA,MAAM;IACN,oBAAoB;IACpB,cAAc;IACf;IACD;;CAGJ,gBAAwB,OAAgB,UAA2C;AACjF,MAAI,CAAC,SAAS,OAAO,UAAU,YAAY,MAAM,QAAQ,MAAM,CAC7D,OAAM,IAAI,MAAM,GAAG,MAAM,SAAS;AAEpC,SAAO;;CAGT,iBAAyB,OAAgB,UAA0B;AACjE,MAAI,OAAO,UAAU,YAAY,CAAC,MAAM,MAAM,CAC5C,OAAM,IAAI,MAAM,GAAG,MAAM,YAAY;AAEvC,SAAO;;CAGT,sBAA8B,UAC5B,OAAO,UAAU,YAAY,UAAU,QACvC,UAAU,SAAU,MAA6B,SAAS"}
|
|
1
|
+
{"version":3,"file":"app-registry.service.js","names":[],"sources":["../../src/services/app-registry.service.ts"],"sourcesContent":["import { open, readFile, rename, rm } from \"node:fs/promises\";\nimport path from \"node:path\";\nimport type { AppPermissions, AppPlatformSecuritySummary, AppResolvedComponent } from \"#app-runtime/types/app-manifest.types.js\";\nimport type { AppDocumentGrantMap } from \"#app-runtime/types/app-permissions.types.js\";\nimport { AppHomeService } from \"#app-runtime/services/app-home.service.js\";\nimport { AppRegistryParserService } from \"#app-runtime/services/app-registry-parser.service.js\";\nimport { FileLockService } from \"#app-runtime/services/file-lock.service.js\";\nimport type { AppInstanceRecord } from \"#app-runtime/types/app-storage.types.js\";\nimport type {\n AppInstallSourceKind,\n AppRegistry,\n AppRegistryAppRecord,\n AppRegistryInstalledVersion,\n AppSecretBinding,\n} from \"#app-runtime/types/app-registry.types.js\";\n\nexport class AppRegistryService {\n private readonly fileLockService = new FileLockService();\n private readonly parser: AppRegistryParserService;\n\n constructor(private readonly appHomeService: AppHomeService = new AppHomeService()) {\n this.parser = new AppRegistryParserService(appHomeService);\n }\n\n load = async (): Promise<AppRegistry> => {\n try {\n const raw = await readFile(this.appHomeService.getRegistryPath(), \"utf-8\");\n return this.parser.parse(JSON.parse(raw) as unknown);\n } catch (error) {\n if (this.isMissingFileError(error)) {\n return { schemaVersion: 1, apps: {}, suppressedBuiltIns: {} };\n }\n throw error;\n }\n };\n\n save = async (registry: AppRegistry): Promise<void> => {\n await this.withMutation(async () => await this.saveUnlocked(registry));\n };\n\n private saveUnlocked = async (registry: AppRegistry): Promise<void> => {\n await this.appHomeService.ensureBaseDirectories();\n const registryPath = this.appHomeService.getRegistryPath();\n const temporaryPath = path.join(\n path.dirname(registryPath),\n `.${path.basename(registryPath)}.${process.pid}.${Date.now()}.tmp`,\n );\n const handle = await open(temporaryPath, \"wx\", 0o600);\n try {\n await handle.writeFile(`${JSON.stringify(registry, null, 2)}\\n`, \"utf-8\");\n await handle.sync();\n } finally {\n await handle.close();\n }\n try {\n await rename(temporaryPath, registryPath);\n } catch (error) {\n await rm(temporaryPath, { force: true });\n throw error;\n }\n };\n\n listApps = async (): Promise<AppRegistryAppRecord[]> => {\n const registry = await this.load();\n return Object.values(registry.apps).sort((left, right) => left.appId.localeCompare(right.appId));\n };\n\n getApp = async (appId: string): Promise<AppRegistryAppRecord | undefined> => {\n const registry = await this.load();\n return registry.apps[appId];\n };\n\n getActiveVersion = async (appId: string): Promise<AppRegistryInstalledVersion | undefined> => {\n const appRecord = await this.getApp(appId);\n return appRecord?.installedVersions[appRecord.activeVersion];\n };\n\n upsertInstallation = async (params: {\n appId: string;\n name: string;\n description?: string;\n version: string;\n installDirectory: string;\n defaultInstance: AppInstanceRecord;\n sourceKind: AppInstallSourceKind;\n sourceRef: string;\n installedAt: string;\n distributionMode?: AppRegistryInstalledVersion[\"distributionMode\"];\n permissions: AppPermissions;\n registryUrl?: string;\n bundleUrl?: string;\n sha256?: string;\n target?: AppRegistryInstalledVersion[\"target\"];\n publisher?: AppRegistryInstalledVersion[\"publisher\"];\n manifestSchemaVersion: 1 | 2;\n components?: AppResolvedComponent[];\n primaryPanelId?: string;\n security?: AppPlatformSecuritySummary;\n dataSchemaVersion: number;\n contentSha256?: string;\n enabled?: boolean;\n activate?: boolean;\n }): Promise<AppRegistryAppRecord> => {\n return await this.withMutation(async () => {\n const registry = await this.load();\n const currentRecord = registry.apps[params.appId];\n const currentPublisher = currentRecord?.publisher ??\n currentRecord?.installedVersions[currentRecord.activeVersion]?.publisher;\n if (currentPublisher && currentPublisher.id !== params.publisher?.id) {\n throw new Error(\n `应用 ${params.appId} 已绑定发布者 ${currentPublisher.id},拒绝由 ${params.publisher?.id ?? \"未验证本地来源\"} 覆盖。`,\n );\n }\n const activeVersion = params.activate === false && currentRecord\n ? currentRecord.activeVersion\n : params.version;\n const activePermissions = activeVersion === params.version\n ? params.permissions\n : currentRecord?.installedVersions[activeVersion]?.permissions ?? {};\n const nextRecord: AppRegistryAppRecord = {\n appId: params.appId,\n name: params.name,\n description: params.description,\n publisher: currentPublisher ?? params.publisher,\n activeVersion,\n enabled: params.enabled ?? currentRecord?.enabled ?? params.manifestSchemaVersion === 1,\n dataDirectory: params.defaultInstance.storage.dataDirectory,\n defaultInstance: params.defaultInstance,\n installedVersions: {\n ...(currentRecord?.installedVersions ?? {}),\n [params.version]: {\n version: params.version,\n installDirectory: params.installDirectory,\n sourceKind: params.sourceKind,\n sourceRef: params.sourceRef,\n installedAt: params.installedAt,\n distributionMode: params.distributionMode,\n permissions: params.permissions,\n registryUrl: params.registryUrl,\n bundleUrl: params.bundleUrl,\n sha256: params.sha256,\n target: params.target,\n publisher: params.publisher,\n manifestSchemaVersion: params.manifestSchemaVersion,\n components: params.components,\n primaryPanelId: params.primaryPanelId,\n security: params.security,\n dataSchemaVersion: params.dataSchemaVersion,\n contentSha256: params.contentSha256,\n },\n },\n grants: currentRecord?.grants ?? {},\n // A SecretRef is an active permission, not retained App data. Keep only\n // bindings declared by the active version so an update cannot leave an\n // undeclared credential reachable by a later runtime snapshot.\n secretBindings: this.parser.retainDeclaredSecretBindings(\n currentRecord?.secretBindings ?? {},\n activePermissions,\n ),\n };\n registry.apps[params.appId] = nextRecord;\n await this.saveUnlocked(registry);\n return nextRecord;\n });\n };\n\n setEnabled = async (appId: string, enabled: boolean): Promise<AppRegistryAppRecord> => {\n return await this.updateApp(appId, (record) => ({ ...record, enabled }));\n };\n\n activateVersion = async (\n appId: string,\n version: string,\n ): Promise<AppRegistryAppRecord> => {\n return await this.updateApp(appId, (record) => {\n if (!record.installedVersions[version]) {\n throw new Error(`应用 ${appId} 未安装版本 ${version}。`);\n }\n return {\n ...record,\n activeVersion: version,\n secretBindings: this.parser.retainDeclaredSecretBindings(\n record.secretBindings,\n record.installedVersions[version].permissions,\n ),\n };\n });\n };\n\n setVersionContentDigest = async (\n appId: string,\n version: string,\n contentSha256: string,\n ): Promise<AppRegistryAppRecord> => {\n return await this.updateApp(appId, (record) => {\n const installedVersion = record.installedVersions[version];\n if (!installedVersion) {\n throw new Error(`应用 ${appId} 未安装版本 ${version}。`);\n }\n if (installedVersion.contentSha256 && installedVersion.contentSha256 !== contentSha256) {\n throw new Error(`应用 ${appId}@${version} 已存在不同的代码完整性摘要。`);\n }\n return {\n ...record,\n installedVersions: {\n ...record.installedVersions,\n [version]: { ...installedVersion, contentSha256 },\n },\n };\n });\n };\n\n updateGrants = async (\n appId: string,\n grants: AppDocumentGrantMap,\n ): Promise<AppRegistryAppRecord> => {\n return await this.updateApp(appId, (record) => ({\n ...record,\n grants: { ...record.grants, ...grants },\n }));\n };\n\n setDocumentGrant = async (\n appId: string,\n scopeId: string,\n directoryPath: string,\n ): Promise<AppRegistryAppRecord> => {\n return await this.updateGrants(appId, { [scopeId]: directoryPath });\n };\n\n removeDocumentGrant = async (appId: string, scopeId: string): Promise<boolean> => {\n let removed = false;\n await this.updateApp(appId, (record) => {\n if (!(scopeId in record.grants)) {\n return record;\n }\n const grants = { ...record.grants };\n delete grants[scopeId];\n removed = true;\n return { ...record, grants };\n });\n return removed;\n };\n\n bindSecret = async (\n appId: string,\n slotId: string,\n binding: AppSecretBinding,\n ): Promise<AppRegistryAppRecord> => {\n const normalizedSlotId = this.parser.parseSecretSlotId(slotId, \"secret slot id\");\n const normalizedBinding = this.parser.parseSecretBinding(binding, `secret binding ${normalizedSlotId}`);\n return await this.updateApp(appId, (record) => {\n const activeVersion = record.installedVersions[record.activeVersion];\n const declaredSlots = activeVersion?.permissions.secrets ?? [];\n if (!declaredSlots.some((slot) => slot.id === normalizedSlotId)) {\n throw new Error(`应用 ${appId} 未声明 Secret slot:${normalizedSlotId}`);\n }\n return {\n ...record,\n secretBindings: {\n ...record.secretBindings,\n [normalizedSlotId]: normalizedBinding,\n },\n };\n });\n };\n\n unbindSecret = async (appId: string, slotId: string): Promise<boolean> => {\n const normalizedSlotId = this.parser.parseSecretSlotId(slotId, \"secret slot id\");\n let removed = false;\n await this.updateApp(appId, (record) => {\n if (!(normalizedSlotId in record.secretBindings)) {\n return record;\n }\n const secretBindings = { ...record.secretBindings };\n delete secretBindings[normalizedSlotId];\n removed = true;\n return { ...record, secretBindings };\n });\n return removed;\n };\n\n removeApp = async (appId: string): Promise<AppRegistryAppRecord | undefined> => {\n return await this.withMutation(async () => {\n const registry = await this.load();\n const appRecord = registry.apps[appId];\n if (!appRecord) {\n return undefined;\n }\n delete registry.apps[appId];\n await this.saveUnlocked(registry);\n return appRecord;\n });\n };\n\n isBuiltInSuppressed = async (appId: string): Promise<boolean> => {\n const registry = await this.load();\n return Boolean(registry.suppressedBuiltIns[appId]);\n };\n\n setBuiltInSuppressed = async (appId: string, suppressed: boolean): Promise<void> => {\n await this.withMutation(async () => {\n const registry = await this.load();\n if (suppressed) {\n registry.suppressedBuiltIns[appId] = { suppressedAt: new Date().toISOString() };\n } else {\n delete registry.suppressedBuiltIns[appId];\n }\n await this.saveUnlocked(registry);\n });\n };\n\n private updateApp = async (\n appId: string,\n update: (record: AppRegistryAppRecord) => AppRegistryAppRecord,\n ): Promise<AppRegistryAppRecord> => {\n return await this.withMutation(async () => {\n const registry = await this.load();\n const appRecord = registry.apps[appId];\n if (!appRecord) {\n throw new Error(`未找到已安装应用:${appId}`);\n }\n const nextRecord = update(appRecord);\n registry.apps[appId] = nextRecord;\n await this.saveUnlocked(registry);\n return nextRecord;\n });\n };\n\n private withMutation = async <T>(operation: () => Promise<T>): Promise<T> => {\n const registryPath = path.resolve(this.appHomeService.getRegistryPath());\n return await this.fileLockService.withLock(`${registryPath}.lock`, operation);\n };\n\n\n private isMissingFileError = (error: unknown): boolean =>\n typeof error === \"object\" && error !== null &&\n \"code\" in error && (error as { code?: unknown }).code === \"ENOENT\";\n}\n"],"mappings":";;;;;;AAgBA,IAAa,qBAAb,MAAgC;CAC9B,kBAAmC,IAAI,iBAAiB;CACxD;CAEA,YAAY,iBAAkD,IAAI,gBAAgB,EAAE;AAAvD,OAAA,iBAAA;AAC3B,OAAK,SAAS,IAAI,yBAAyB,eAAe;;CAG5D,OAAO,YAAkC;AACvC,MAAI;GACF,MAAM,MAAM,MAAM,SAAS,KAAK,eAAe,iBAAiB,EAAE,QAAQ;AAC1E,UAAO,KAA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AClC,OAAI,WACF,UAAS,mBAAmB,SAAS,EAAE,+BAAc,IAAI,MAAM,EAAC,aAAa,EAAE;OAE/E,QAAO,SAAS,mBAAmB;AAErC,SAAM,KAAK,aAAa,SAAS;IACjC;;CAGJ,YAAoB,OAClB,OACA,WACkC;AAClC,SAAO,MAAM,KAAK,aAAa,YAAY;GACzC,MAAM,WAAW,MAAM,KAAK,MAAM;GAClC,MAAM,YAAY,SAAS,KAAK;AAChC,OAAI,CAAC,UACH,OAAM,IAAI,MAAM,YAAY,QAAQ;GAEtC,MAAM,aAAa,OAAO,UAAU;AACpC,YAAS,KAAK,SAAS;AACvB,SAAM,KAAK,aAAa,SAAS;AACjC,UAAO;IACP;;CAGJ,eAAuB,OAAU,cAA4C;EAC3E,MAAM,eAAe,KAAK,QAAQ,KAAK,eAAe,iBAAiB,CAAC;AACxE,SAAO,MAAM,KAAK,gBAAgB,SAAS,GAAG,aAAa,QAAQ,UAAU;;CAI/E,sBAA8B,UAC5B,OAAO,UAAU,YAAY,UAAU,QACvC,UAAU,SAAU,MAA6B,SAAS"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app-rust-wasi-scaffold-template.service.d.ts","names":[],"sources":["../../src/services/app-rust-wasi-scaffold-template.service.ts"],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"app-rust-wasi-scaffold-template.service.d.ts","names":[],"sources":["../../src/services/app-rust-wasi-scaffold-template.service.ts"],"mappings":";;;cAkCa,kCAAA;EACX,UAAA,GAAc,MAAA;IAAU,KAAA;IAAe,OAAA;EAAA,MAAoB,eAAA;EAAA,QAsCnD,aAAA;EAAA,QAwBA,kBAAA;EAAA,QASA,oBAAA;EAAA,QAoBA,wBAAA;EAAA,QAkBA,cAAA;EAAA,QA4BA,eAAA;EAAA,QAyEA,WAAA;EAAA,QAwCA,cAAA;EAAA,QA6BA,gBAAA;EAAA,QA4BA,wBAAA;EAAA,QAmBA,aAAA;EAAA,QAMA,YAAA;AAAA"}
|
|
@@ -2,6 +2,26 @@ import { readFileSync } from "node:fs";
|
|
|
2
2
|
//#region src/services/app-rust-wasi-scaffold-template.service.ts
|
|
3
3
|
const RUST_WASI_GUEST_CRATE_NAME = "nextclaw-rust-wasi-guest";
|
|
4
4
|
const PORTABLE_SERVICE_WIT = readFileSync(new URL("../../resources/wit/portable-service.wit", import.meta.url), "utf8");
|
|
5
|
+
const STANDARD_PORTABLE_WIT_DEPS = [
|
|
6
|
+
"deps/http@0.2.6/package.wit",
|
|
7
|
+
"deps/http@0.2.6/handler.wit",
|
|
8
|
+
"deps/http@0.2.6/types.wit",
|
|
9
|
+
"deps/io@0.2.6/error.wit",
|
|
10
|
+
"deps/io@0.2.6/poll.wit",
|
|
11
|
+
"deps/io@0.2.6/streams.wit",
|
|
12
|
+
"deps/io@0.2.6/world.wit",
|
|
13
|
+
"deps/clocks@0.2.6/monotonic-clock.wit",
|
|
14
|
+
"deps/clocks@0.2.6/timezone.wit",
|
|
15
|
+
"deps/clocks@0.2.6/wall-clock.wit",
|
|
16
|
+
"deps/clocks@0.2.6/world.wit",
|
|
17
|
+
"deps/config@0.2.0-draft-2024-09-27/package.wit",
|
|
18
|
+
"deps/config@0.2.0-draft-2024-09-27/store.wit",
|
|
19
|
+
"deps/spin@2.0.0/package.wit",
|
|
20
|
+
"deps/spin@2.0.0/sqlite.wit"
|
|
21
|
+
].map((relativePath) => ({
|
|
22
|
+
relativePath: `guest/wit/${relativePath}`,
|
|
23
|
+
content: readFileSync(new URL(`../../resources/wit/${relativePath}`, import.meta.url), "utf8")
|
|
24
|
+
}));
|
|
5
25
|
const RUST_WASI_CARGO_LOCK = readFileSync(new URL("../../resources/rust-wasi/Cargo.lock", import.meta.url), "utf8");
|
|
6
26
|
var AppRustWasiScaffoldTemplateService = class {
|
|
7
27
|
buildFiles = (params) => {
|
|
@@ -54,6 +74,7 @@ var AppRustWasiScaffoldTemplateService = class {
|
|
|
54
74
|
relativePath: "guest/wit/portable-service.wit",
|
|
55
75
|
content: PORTABLE_SERVICE_WIT
|
|
56
76
|
},
|
|
77
|
+
...STANDARD_PORTABLE_WIT_DEPS,
|
|
57
78
|
{
|
|
58
79
|
relativePath: "tests/service-smoke.json",
|
|
59
80
|
content: `${JSON.stringify(this.buildServiceSmokeFixture(serviceId), null, 2)}\n`
|
|
@@ -154,10 +175,26 @@ wit-bindgen = "0.44.0"
|
|
|
154
175
|
|
|
155
176
|
[lib]
|
|
156
177
|
crate-type = ["cdylib"]
|
|
178
|
+
|
|
179
|
+
[package.metadata.component]
|
|
180
|
+
package = "nextclaw:portable-service"
|
|
181
|
+
|
|
182
|
+
[package.metadata.component.target]
|
|
183
|
+
path = "wit"
|
|
184
|
+
world = "service-app"
|
|
185
|
+
|
|
186
|
+
[package.metadata.component.target.dependencies]
|
|
187
|
+
"fermyon:spin" = { path = "wit/deps/spin@2.0.0" }
|
|
188
|
+
"wasi:http" = { path = "wit/deps/http@0.2.6" }
|
|
189
|
+
"wasi:io" = { path = "wit/deps/io@0.2.6" }
|
|
190
|
+
"wasi:clocks" = { path = "wit/deps/clocks@0.2.6" }
|
|
191
|
+
"wasi:config" = { path = "wit/deps/config@0.2.0-draft-2024-09-27" }
|
|
157
192
|
`;
|
|
158
193
|
buildRustSource = () => `wit_bindgen::generate!({
|
|
159
194
|
path: "wit",
|
|
160
195
|
world: "service-app",
|
|
196
|
+
// Generate standard WASI HTTP's transitive interfaces for later use by a Guest.
|
|
197
|
+
generate_all,
|
|
161
198
|
});
|
|
162
199
|
|
|
163
200
|
use exports::nextclaw::portable_service::service::{Action, Guest};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app-rust-wasi-scaffold-template.service.js","names":[],"sources":["../../src/services/app-rust-wasi-scaffold-template.service.ts"],"sourcesContent":["import { readFileSync } from \"node:fs\";\nimport type { AppScaffoldFile } from \"./app-ts-http-scaffold-template.service.js\";\n\nconst RUST_WASI_GUEST_CRATE_NAME = \"nextclaw-rust-wasi-guest\";\nconst PORTABLE_SERVICE_WIT = readFileSync(\n new URL(\"../../resources/wit/portable-service.wit\", import.meta.url),\n \"utf8\",\n);\nconst RUST_WASI_CARGO_LOCK = readFileSync(\n new URL(\"../../resources/rust-wasi/Cargo.lock\", import.meta.url),\n \"utf8\",\n);\n\nexport class AppRustWasiScaffoldTemplateService {\n buildFiles = (params: { appId: string; appName: string }): AppScaffoldFile[] => {\n const { appId, appName } = params;\n const packageSlug = appId.replace(/[^a-z0-9]+/g, \"-\");\n const panelId = `${packageSlug}-panel`;\n const serviceId = `${packageSlug}-service`;\n return [\n {\n relativePath: \"manifest.json\",\n content: `${JSON.stringify(this.buildManifest(appId, appName, panelId, serviceId), null, 2)}\\n`,\n },\n {\n relativePath: \"marketplace.json\",\n content: `${JSON.stringify(this.buildMarketplaceMetadata(appName), null, 2)}\\n`,\n },\n { relativePath: \"README.md\", content: this.buildReadme(appName, serviceId) },\n {\n relativePath: `panels/${panelId}.panel/panel-app.json`,\n content: `${JSON.stringify(this.buildPanelManifest(panelId, appName, serviceId), null, 2)}\\n`,\n },\n { relativePath: `panels/${panelId}.panel/index.html`, content: this.buildPanelHtml(appName) },\n { relativePath: `panels/${panelId}.panel/app.js`, content: this.buildPanelScript(serviceId) },\n {\n relativePath: `service-components/${serviceId}/service-app.json`,\n content: `${JSON.stringify(this.buildServiceManifest(serviceId), null, 2)}\\n`,\n },\n { relativePath: \"guest/Cargo.toml\", content: this.buildCargoToml() },\n { relativePath: \"guest/Cargo.lock\", content: RUST_WASI_CARGO_LOCK },\n { relativePath: \"guest/src/lib.rs\", content: this.buildRustSource() },\n { relativePath: \"guest/wit/portable-service.wit\", content: PORTABLE_SERVICE_WIT },\n {\n relativePath: \"tests/service-smoke.json\",\n content: `${JSON.stringify(this.buildServiceSmokeFixture(serviceId), null, 2)}\\n`,\n },\n { relativePath: \"assets/icon.svg\", content: this.buildIconSvg() },\n ];\n };\n\n private buildManifest = (\n appId: string,\n appName: string,\n panelId: string,\n serviceId: string,\n ) => ({\n schemaVersion: 2,\n id: appId,\n name: appName,\n version: \"0.1.0\",\n description: `${appName},由 Rust/WASI Component 保存持久计数。`,\n icon: \"assets/icon.svg\",\n engines: { nextclaw: \">=0.45.4\" },\n presentation: { primaryPanel: panelId },\n runtime: { profile: \"wasi\" },\n distribution: { mode: \"universal\" },\n storage: { scope: \"global\", schemaVersion: 1 },\n permissions: { storage: { namespace: appId.replace(/\\./g, \"-\") } },\n components: [\n { kind: \"panel\", path: `panels/${panelId}.panel` },\n { kind: \"service\", path: `service-components/${serviceId}` },\n ],\n });\n\n private buildPanelManifest = (panelId: string, appName: string, serviceId: string) => ({\n id: panelId,\n title: appName,\n description: \"读取并增加由 Rust/WASI Component 持久保存的计数。\",\n icon: \"🦀\",\n entry: \"index.html\",\n actions: [`${serviceId}.counter_read`, `${serviceId}.counter_increment`],\n });\n\n private buildServiceManifest = (serviceId: string) => ({\n id: serviceId,\n title: \"Rust/WASI 持久计数组件\",\n description: \"通过宿主 KV 读取和增加持久计数。\",\n protocol: \"wasi-component\",\n component: { entry: \"service.wasm\" },\n actions: {\n counter_read: { risk: \"read\", title: \"读取持久计数\" },\n counter_increment: {\n risk: \"write\",\n title: \"增加持久计数\",\n inputSchema: {\n type: \"object\",\n properties: { step: { type: \"integer\", minimum: 1, maximum: 100 } },\n additionalProperties: false,\n },\n },\n },\n });\n\n private buildServiceSmokeFixture = (serviceId: string) => ({\n schemaVersion: 1,\n component: serviceId,\n resetData: true,\n steps: [\n {\n action: \"counter_increment\",\n input: { step: 3 },\n expect: { counter: 3, persistedBy: \"host.kv\" },\n },\n {\n action: \"counter_read\",\n input: {},\n expect: { counter: 3, persistedBy: \"host.kv\" },\n },\n ],\n });\n\n private buildCargoToml = (): string => `[package]\nname = \"${RUST_WASI_GUEST_CRATE_NAME}\"\nversion = \"0.1.0\"\nedition = \"2024\"\npublish = false\n\n[dependencies]\nserde_json = \"1.0\"\nwit-bindgen = \"0.44.0\"\n\n[lib]\ncrate-type = [\"cdylib\"]\n`;\n\n private buildRustSource = (): string => `wit_bindgen::generate!({\n path: \"wit\",\n world: \"service-app\",\n});\n\nuse exports::nextclaw::portable_service::service::{Action, Guest};\nuse nextclaw::portable_service::host;\nuse serde_json::{Value, json};\n\nstruct Component;\n\nimpl Guest for Component {\n fn list_actions() -> Vec<Action> {\n vec![\n Action {\n name: \"counter_read\".into(),\n title: \"读取持久计数\".into(),\n description: \"从宿主管理的 KV 存储读取计数。\".into(),\n },\n Action {\n name: \"counter_increment\".into(),\n title: \"增加持久计数\".into(),\n description: \"在 Rust/WASM 中计算,并通过宿主 KV 持久化。\".into(),\n },\n ]\n }\n\n fn invoke(action: String, input_json: String) -> Result<String, String> {\n host::log(host::LogLevel::Info, &format!(\"invoking {action}\"));\n let input: Value = serde_json::from_str(&input_json).unwrap_or_else(|_| json!({}));\n match action.as_str() {\n \"counter_read\" => Ok(counter_result(read_counter()?)),\n \"counter_increment\" => {\n let step = input.get(\"step\").and_then(Value::as_i64).unwrap_or(1);\n if !(1..=100).contains(&step) {\n return Err(\"INVALID_INPUT: step must be between 1 and 100\".into());\n }\n let counter = read_counter()?.saturating_add(step);\n host::kv_set(\"counter\", &counter.to_string())?;\n Ok(counter_result(counter))\n }\n _ => Err(format!(\"UNKNOWN_ACTION: {action}\")),\n }\n }\n\n fn start(_config_json: String) -> Result<String, String> {\n Ok(json!({ \"started\": true, \"mode\": \"action\" }).to_string())\n }\n\n fn handle_event(_event_json: String) -> Result<String, String> {\n Err(\"UNSUPPORTED_LIFECYCLE: action component does not accept resident events\".into())\n }\n\n fn stop(_reason_json: String) -> Result<String, String> {\n Ok(json!({ \"stopped\": true, \"mode\": \"action\" }).to_string())\n }\n}\n\nfn read_counter() -> Result<i64, String> {\n Ok(host::kv_get(\"counter\")?\n .and_then(|value| value.parse().ok())\n .unwrap_or(0))\n}\n\nfn counter_result(counter: i64) -> String {\n json!({ \"counter\": counter, \"persistedBy\": \"host.kv\" }).to_string()\n}\n\nexport!(Component with_types_in self);\n`;\n\n private buildReadme = (appName: string, serviceId: string): string => `# ${appName}\n\n这是一个可以独立构建的 Rust/WASI Component App。Panel 和 Agent 调用同一组 Service Action,计数通过 NextClaw 宿主 KV 持久保存。\n\n## 1. 准备 Rust 工具链\n\n\\`\\`\\`bash\nrustup target add wasm32-wasip2\n\\`\\`\\`\n\n## 2. 构建 Component\n\n\\`\\`\\`bash\ncd guest\ncargo build --release --target wasm32-wasip2\ncp target/wasm32-wasip2/release/nextclaw_rust_wasi_guest.wasm ../service-components/${serviceId}/service.wasm\ncd ..\n\\`\\`\\`\n\n项目内的 \\`guest/wit/portable-service.wit\\` 是当前 Service Action 与宿主能力合同;不需要 NextClaw 源码仓库。\n\n## 3. 检查和调试\n\n\\`\\`\\`bash\nnextclaw app check .\nnextclaw app dev .\nnextclaw app call . counter_read\nnextclaw app call . counter_increment --input '{\"step\":2}'\n\\`\\`\\`\n\n如果一个包包含多个 Service Component,请增加 \\`--component <component-id>\\`。\n\n## 4. 打包和安装\n\n\\`\\`\\`bash\nnextclaw app pack . --target universal --out ${this.normalizeSlug(appName)}.napp\nnextclaw app install ./${this.normalizeSlug(appName)}.napp\n\\`\\`\\`\n`;\n\n private buildPanelHtml = (appName: string): string => `<!doctype html>\n<html lang=\"zh-CN\">\n <head>\n <meta charset=\"utf-8\" />\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\" />\n <title>${appName}</title>\n <style>\n :root { font-family: ui-sans-serif, system-ui, sans-serif; color: #172033; background: #f5f7fb; }\n body { margin: 0; min-height: 100vh; display: grid; place-items: center; }\n main { width: min(420px, calc(100vw - 40px)); padding: 28px; border-radius: 24px; background: white; box-shadow: 0 18px 60px #24324a1f; }\n p { color: #667085; }\n output { display: block; margin: 24px 0; font-size: 64px; font-weight: 700; }\n button { border: 0; border-radius: 999px; padding: 12px 18px; background: #172033; color: white; cursor: pointer; }\n #error { color: #b42318; }\n </style>\n </head>\n <body>\n <main>\n <h1>${appName}</h1>\n <p>这个数字由 Rust/WASI Component 计算,并通过宿主 KV 持久保存。</p>\n <output id=\"counter\">…</output>\n <button id=\"increment\" type=\"button\">增加 1</button>\n <p id=\"error\" role=\"alert\"></p>\n </main>\n <script src=\"app.js\"></script>\n </body>\n</html>\n`;\n\n private buildPanelScript = (serviceId: string): string => `const counter = document.querySelector(\"#counter\");\nconst error = document.querySelector(\"#error\");\nconst increment = document.querySelector(\"#increment\");\n\nasync function readCounter() {\n error.textContent = \"\";\n try {\n const result = await window.nextclaw.serviceActions.invoke(\"${serviceId}.counter_read\", {});\n counter.textContent = String(result.counter ?? 0);\n } catch (cause) {\n error.textContent = cause instanceof Error ? cause.message : String(cause);\n }\n}\n\nasync function incrementCounter() {\n error.textContent = \"\";\n try {\n const result = await window.nextclaw.serviceActions.invoke(\"${serviceId}.counter_increment\", { step: 1 });\n counter.textContent = String(result.counter ?? 0);\n } catch (cause) {\n error.textContent = cause instanceof Error ? cause.message : String(cause);\n }\n}\n\nincrement.addEventListener(\"click\", incrementCounter);\nvoid readCounter();\n`;\n\n private buildMarketplaceMetadata = (appName: string) => ({\n slug: this.normalizeSlug(appName),\n summary: `${appName} Rust/WASI Component 示例。`,\n summaryI18n: {\n zh: `${appName} Rust/WASI Component 示例。`,\n en: `${appName}, a Rust/WASI Component example.`,\n },\n description: \"A minimal Rust/WASI Component App with a Panel and host-managed persistent KV.\",\n descriptionI18n: {\n zh: \"一个包含 Panel 和宿主持久 KV 的最小 Rust/WASI Component App。\",\n en: \"A minimal Rust/WASI Component App with a Panel and host-managed persistent KV.\",\n },\n author: \"NextClaw\",\n tags: [\"starter\", \"rust\", \"wasi-component\", \"official\"],\n sourceRepo: \"https://github.com/Peiiii/nextclaw\",\n homepage: \"https://nextclaw.io\",\n featured: false,\n });\n\n private normalizeSlug = (value: string): string => value\n .trim()\n .toLowerCase()\n .replace(/[^a-z0-9]+/g, \"-\")\n .replace(/^-+|-+$/g, \"\") || \"rust-wasi-app\";\n\n private buildIconSvg = (): string => `<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 128 128\">\n <rect width=\"128\" height=\"128\" rx=\"30\" fill=\"#172033\"/>\n <path d=\"M31 40h66v48H31z\" fill=\"#fff\" opacity=\".12\"/>\n <path d=\"M43 52h42v8H43zm0 16h28v8H43z\" fill=\"#fff\"/>\n <circle cx=\"88\" cy=\"76\" r=\"12\" fill=\"#f59e0b\"/>\n</svg>\n`;\n}\n"],"mappings":";;AAGA,MAAM,6BAA6B;AACnC,MAAM,uBAAuB,aAC3B,IAAI,IAAI,4CAA4C,OAAO,KAAK,IAAI,EACpE,OACD;AACD,MAAM,uBAAuB,aAC3B,IAAI,IAAI,wCAAwC,OAAO,KAAK,IAAI,EAChE,OACD;AAED,IAAa,qCAAb,MAAgD;CAC9C,cAAc,WAAkE;EAC9E,MAAM,EAAE,OAAO,YAAY;EAC3B,MAAM,cAAc,MAAM,QAAQ,eAAe,IAAI;EACrD,MAAM,UAAU,GAAG,YAAY;EAC/B,MAAM,YAAY,GAAG,YAAY;AACjC,SAAO;GACL;IACE,cAAc;IACd,SAAS,GAAG,KAAK,UAAU,KAAK,cAAc,OAAO,SAAS,SAAS,UAAU,EAAE,MAAM,EAAE,CAAC;IAC7F;GACD;IACE,cAAc;IACd,SAAS,GAAG,KAAK,UAAU,KAAK,yBAAyB,QAAQ,EAAE,MAAM,EAAE,CAAC;IAC7E;GACD;IAAE,cAAc;IAAa,SAAS,KAAK,YAAY,SAAS,UAAU;IAAE;GAC5E;IACE,cAAc,UAAU,QAAQ;IAChC,SAAS,GAAG,KAAK,UAAU,KAAK,mBAAmB,SAAS,SAAS,UAAU,EAAE,MAAM,EAAE,CAAC;IAC3F;GACD;IAAE,cAAc,UAAU,QAAQ;IAAoB,SAAS,KAAK,eAAe,QAAQ;IAAE;GAC7F;IAAE,cAAc,UAAU,QAAQ;IAAgB,SAAS,KAAK,iBAAiB,UAAU;IAAE;GAC7F;IACE,cAAc,sBAAsB,UAAU;IAC9C,SAAS,GAAG,KAAK,UAAU,KAAK,qBAAqB,UAAU,EAAE,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-template.service.js","names":[],"sources":["../../src/services/app-rust-wasi-scaffold-template.service.ts"],"sourcesContent":["import { readFileSync } from \"node:fs\";\nimport type { AppScaffoldFile } from \"./app-ts-http-scaffold-template.service.js\";\n\nconst RUST_WASI_GUEST_CRATE_NAME = \"nextclaw-rust-wasi-guest\";\nconst PORTABLE_SERVICE_WIT = readFileSync(\n new URL(\"../../resources/wit/portable-service.wit\", import.meta.url),\n \"utf8\",\n);\nconst STANDARD_PORTABLE_WIT_FILES = [\n \"deps/http@0.2.6/package.wit\",\n \"deps/http@0.2.6/handler.wit\",\n \"deps/http@0.2.6/types.wit\",\n \"deps/io@0.2.6/error.wit\",\n \"deps/io@0.2.6/poll.wit\",\n \"deps/io@0.2.6/streams.wit\",\n \"deps/io@0.2.6/world.wit\",\n \"deps/clocks@0.2.6/monotonic-clock.wit\",\n \"deps/clocks@0.2.6/timezone.wit\",\n \"deps/clocks@0.2.6/wall-clock.wit\",\n \"deps/clocks@0.2.6/world.wit\",\n \"deps/config@0.2.0-draft-2024-09-27/package.wit\",\n \"deps/config@0.2.0-draft-2024-09-27/store.wit\",\n \"deps/spin@2.0.0/package.wit\",\n \"deps/spin@2.0.0/sqlite.wit\",\n] as const;\nconst STANDARD_PORTABLE_WIT_DEPS: AppScaffoldFile[] = STANDARD_PORTABLE_WIT_FILES.map((relativePath) => ({\n relativePath: `guest/wit/${relativePath}`,\n content: readFileSync(new URL(`../../resources/wit/${relativePath}`, import.meta.url), \"utf8\"),\n}));\nconst RUST_WASI_CARGO_LOCK = readFileSync(\n new URL(\"../../resources/rust-wasi/Cargo.lock\", import.meta.url),\n \"utf8\",\n);\n\nexport class AppRustWasiScaffoldTemplateService {\n buildFiles = (params: { appId: string; appName: string }): AppScaffoldFile[] => {\n const { appId, appName } = params;\n const packageSlug = appId.replace(/[^a-z0-9]+/g, \"-\");\n const panelId = `${packageSlug}-panel`;\n const serviceId = `${packageSlug}-service`;\n return [\n {\n relativePath: \"manifest.json\",\n content: `${JSON.stringify(this.buildManifest(appId, appName, panelId, serviceId), null, 2)}\\n`,\n },\n {\n relativePath: \"marketplace.json\",\n content: `${JSON.stringify(this.buildMarketplaceMetadata(appName), null, 2)}\\n`,\n },\n { relativePath: \"README.md\", content: this.buildReadme(appName, serviceId) },\n {\n relativePath: `panels/${panelId}.panel/panel-app.json`,\n content: `${JSON.stringify(this.buildPanelManifest(panelId, appName, serviceId), null, 2)}\\n`,\n },\n { relativePath: `panels/${panelId}.panel/index.html`, content: this.buildPanelHtml(appName) },\n { relativePath: `panels/${panelId}.panel/app.js`, content: this.buildPanelScript(serviceId) },\n {\n relativePath: `service-components/${serviceId}/service-app.json`,\n content: `${JSON.stringify(this.buildServiceManifest(serviceId), null, 2)}\\n`,\n },\n { relativePath: \"guest/Cargo.toml\", content: this.buildCargoToml() },\n { relativePath: \"guest/Cargo.lock\", content: RUST_WASI_CARGO_LOCK },\n { relativePath: \"guest/src/lib.rs\", content: this.buildRustSource() },\n { relativePath: \"guest/wit/portable-service.wit\", content: PORTABLE_SERVICE_WIT },\n ...STANDARD_PORTABLE_WIT_DEPS,\n {\n relativePath: \"tests/service-smoke.json\",\n content: `${JSON.stringify(this.buildServiceSmokeFixture(serviceId), null, 2)}\\n`,\n },\n { relativePath: \"assets/icon.svg\", content: this.buildIconSvg() },\n ];\n };\n\n private buildManifest = (\n appId: string,\n appName: string,\n panelId: string,\n serviceId: string,\n ) => ({\n schemaVersion: 2,\n id: appId,\n name: appName,\n version: \"0.1.0\",\n description: `${appName},由 Rust/WASI Component 保存持久计数。`,\n icon: \"assets/icon.svg\",\n engines: { nextclaw: \">=0.45.4\" },\n presentation: { primaryPanel: panelId },\n runtime: { profile: \"wasi\" },\n distribution: { mode: \"universal\" },\n storage: { scope: \"global\", schemaVersion: 1 },\n permissions: { storage: { namespace: appId.replace(/\\./g, \"-\") } },\n components: [\n { kind: \"panel\", path: `panels/${panelId}.panel` },\n { kind: \"service\", path: `service-components/${serviceId}` },\n ],\n });\n\n private buildPanelManifest = (panelId: string, appName: string, serviceId: string) => ({\n id: panelId,\n title: appName,\n description: \"读取并增加由 Rust/WASI Component 持久保存的计数。\",\n icon: \"🦀\",\n entry: \"index.html\",\n actions: [`${serviceId}.counter_read`, `${serviceId}.counter_increment`],\n });\n\n private buildServiceManifest = (serviceId: string) => ({\n id: serviceId,\n title: \"Rust/WASI 持久计数组件\",\n description: \"通过宿主 KV 读取和增加持久计数。\",\n protocol: \"wasi-component\",\n component: { entry: \"service.wasm\" },\n actions: {\n counter_read: { risk: \"read\", title: \"读取持久计数\" },\n counter_increment: {\n risk: \"write\",\n title: \"增加持久计数\",\n inputSchema: {\n type: \"object\",\n properties: { step: { type: \"integer\", minimum: 1, maximum: 100 } },\n additionalProperties: false,\n },\n },\n },\n });\n\n private buildServiceSmokeFixture = (serviceId: string) => ({\n schemaVersion: 1,\n component: serviceId,\n resetData: true,\n steps: [\n {\n action: \"counter_increment\",\n input: { step: 3 },\n expect: { counter: 3, persistedBy: \"host.kv\" },\n },\n {\n action: \"counter_read\",\n input: {},\n expect: { counter: 3, persistedBy: \"host.kv\" },\n },\n ],\n });\n\n private buildCargoToml = (): string => `[package]\nname = \"${RUST_WASI_GUEST_CRATE_NAME}\"\nversion = \"0.1.0\"\nedition = \"2024\"\npublish = false\n\n[dependencies]\nserde_json = \"1.0\"\nwit-bindgen = \"0.44.0\"\n\n[lib]\ncrate-type = [\"cdylib\"]\n\n[package.metadata.component]\npackage = \"nextclaw:portable-service\"\n\n[package.metadata.component.target]\npath = \"wit\"\nworld = \"service-app\"\n\n[package.metadata.component.target.dependencies]\n\"fermyon:spin\" = { path = \"wit/deps/spin@2.0.0\" }\n\"wasi:http\" = { path = \"wit/deps/http@0.2.6\" }\n\"wasi:io\" = { path = \"wit/deps/io@0.2.6\" }\n\"wasi:clocks\" = { path = \"wit/deps/clocks@0.2.6\" }\n\"wasi:config\" = { path = \"wit/deps/config@0.2.0-draft-2024-09-27\" }\n`;\n\n private buildRustSource = (): string => `wit_bindgen::generate!({\n path: \"wit\",\n world: \"service-app\",\n // Generate standard WASI HTTP's transitive interfaces for later use by a Guest.\n generate_all,\n});\n\nuse exports::nextclaw::portable_service::service::{Action, Guest};\nuse nextclaw::portable_service::host;\nuse serde_json::{Value, json};\n\nstruct Component;\n\nimpl Guest for Component {\n fn list_actions() -> Vec<Action> {\n vec![\n Action {\n name: \"counter_read\".into(),\n title: \"读取持久计数\".into(),\n description: \"从宿主管理的 KV 存储读取计数。\".into(),\n },\n Action {\n name: \"counter_increment\".into(),\n title: \"增加持久计数\".into(),\n description: \"在 Rust/WASM 中计算,并通过宿主 KV 持久化。\".into(),\n },\n ]\n }\n\n fn invoke(action: String, input_json: String) -> Result<String, String> {\n host::log(host::LogLevel::Info, &format!(\"invoking {action}\"));\n let input: Value = serde_json::from_str(&input_json).unwrap_or_else(|_| json!({}));\n match action.as_str() {\n \"counter_read\" => Ok(counter_result(read_counter()?)),\n \"counter_increment\" => {\n let step = input.get(\"step\").and_then(Value::as_i64).unwrap_or(1);\n if !(1..=100).contains(&step) {\n return Err(\"INVALID_INPUT: step must be between 1 and 100\".into());\n }\n let counter = read_counter()?.saturating_add(step);\n host::kv_set(\"counter\", &counter.to_string())?;\n Ok(counter_result(counter))\n }\n _ => Err(format!(\"UNKNOWN_ACTION: {action}\")),\n }\n }\n\n fn start(_config_json: String) -> Result<String, String> {\n Ok(json!({ \"started\": true, \"mode\": \"action\" }).to_string())\n }\n\n fn handle_event(_event_json: String) -> Result<String, String> {\n Err(\"UNSUPPORTED_LIFECYCLE: action component does not accept resident events\".into())\n }\n\n fn stop(_reason_json: String) -> Result<String, String> {\n Ok(json!({ \"stopped\": true, \"mode\": \"action\" }).to_string())\n }\n}\n\nfn read_counter() -> Result<i64, String> {\n Ok(host::kv_get(\"counter\")?\n .and_then(|value| value.parse().ok())\n .unwrap_or(0))\n}\n\nfn counter_result(counter: i64) -> String {\n json!({ \"counter\": counter, \"persistedBy\": \"host.kv\" }).to_string()\n}\n\nexport!(Component with_types_in self);\n`;\n\n private buildReadme = (appName: string, serviceId: string): string => `# ${appName}\n\n这是一个可以独立构建的 Rust/WASI Component App。Panel 和 Agent 调用同一组 Service Action,计数通过 NextClaw 宿主 KV 持久保存。\n\n## 1. 准备 Rust 工具链\n\n\\`\\`\\`bash\nrustup target add wasm32-wasip2\n\\`\\`\\`\n\n## 2. 构建 Component\n\n\\`\\`\\`bash\ncd guest\ncargo build --release --target wasm32-wasip2\ncp target/wasm32-wasip2/release/nextclaw_rust_wasi_guest.wasm ../service-components/${serviceId}/service.wasm\ncd ..\n\\`\\`\\`\n\n项目内的 \\`guest/wit/portable-service.wit\\` 是当前 Service Action 与宿主能力合同;不需要 NextClaw 源码仓库。\n\n## 3. 检查和调试\n\n\\`\\`\\`bash\nnextclaw app check .\nnextclaw app dev .\nnextclaw app call . counter_read\nnextclaw app call . counter_increment --input '{\"step\":2}'\n\\`\\`\\`\n\n如果一个包包含多个 Service Component,请增加 \\`--component <component-id>\\`。\n\n## 4. 打包和安装\n\n\\`\\`\\`bash\nnextclaw app pack . --target universal --out ${this.normalizeSlug(appName)}.napp\nnextclaw app install ./${this.normalizeSlug(appName)}.napp\n\\`\\`\\`\n`;\n\n private buildPanelHtml = (appName: string): string => `<!doctype html>\n<html lang=\"zh-CN\">\n <head>\n <meta charset=\"utf-8\" />\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\" />\n <title>${appName}</title>\n <style>\n :root { font-family: ui-sans-serif, system-ui, sans-serif; color: #172033; background: #f5f7fb; }\n body { margin: 0; min-height: 100vh; display: grid; place-items: center; }\n main { width: min(420px, calc(100vw - 40px)); padding: 28px; border-radius: 24px; background: white; box-shadow: 0 18px 60px #24324a1f; }\n p { color: #667085; }\n output { display: block; margin: 24px 0; font-size: 64px; font-weight: 700; }\n button { border: 0; border-radius: 999px; padding: 12px 18px; background: #172033; color: white; cursor: pointer; }\n #error { color: #b42318; }\n </style>\n </head>\n <body>\n <main>\n <h1>${appName}</h1>\n <p>这个数字由 Rust/WASI Component 计算,并通过宿主 KV 持久保存。</p>\n <output id=\"counter\">…</output>\n <button id=\"increment\" type=\"button\">增加 1</button>\n <p id=\"error\" role=\"alert\"></p>\n </main>\n <script src=\"app.js\"></script>\n </body>\n</html>\n`;\n\n private buildPanelScript = (serviceId: string): string => `const counter = document.querySelector(\"#counter\");\nconst error = document.querySelector(\"#error\");\nconst increment = document.querySelector(\"#increment\");\n\nasync function readCounter() {\n error.textContent = \"\";\n try {\n const result = await window.nextclaw.serviceActions.invoke(\"${serviceId}.counter_read\", {});\n counter.textContent = String(result.counter ?? 0);\n } catch (cause) {\n error.textContent = cause instanceof Error ? cause.message : String(cause);\n }\n}\n\nasync function incrementCounter() {\n error.textContent = \"\";\n try {\n const result = await window.nextclaw.serviceActions.invoke(\"${serviceId}.counter_increment\", { step: 1 });\n counter.textContent = String(result.counter ?? 0);\n } catch (cause) {\n error.textContent = cause instanceof Error ? cause.message : String(cause);\n }\n}\n\nincrement.addEventListener(\"click\", incrementCounter);\nvoid readCounter();\n`;\n\n private buildMarketplaceMetadata = (appName: string) => ({\n slug: this.normalizeSlug(appName),\n summary: `${appName} Rust/WASI Component 示例。`,\n summaryI18n: {\n zh: `${appName} Rust/WASI Component 示例。`,\n en: `${appName}, a Rust/WASI Component example.`,\n },\n description: \"A minimal Rust/WASI Component App with a Panel and host-managed persistent KV.\",\n descriptionI18n: {\n zh: \"一个包含 Panel 和宿主持久 KV 的最小 Rust/WASI Component App。\",\n en: \"A minimal Rust/WASI Component App with a Panel and host-managed persistent KV.\",\n },\n author: \"NextClaw\",\n tags: [\"starter\", \"rust\", \"wasi-component\", \"official\"],\n sourceRepo: \"https://github.com/Peiiii/nextclaw\",\n homepage: \"https://nextclaw.io\",\n featured: false,\n });\n\n private normalizeSlug = (value: string): string => value\n .trim()\n .toLowerCase()\n .replace(/[^a-z0-9]+/g, \"-\")\n .replace(/^-+|-+$/g, \"\") || \"rust-wasi-app\";\n\n private buildIconSvg = (): string => `<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 128 128\">\n <rect width=\"128\" height=\"128\" rx=\"30\" fill=\"#172033\"/>\n <path d=\"M31 40h66v48H31z\" fill=\"#fff\" opacity=\".12\"/>\n <path d=\"M43 52h42v8H43zm0 16h28v8H43z\" fill=\"#fff\"/>\n <circle cx=\"88\" cy=\"76\" r=\"12\" fill=\"#f59e0b\"/>\n</svg>\n`;\n}\n"],"mappings":";;AAGA,MAAM,6BAA6B;AACnC,MAAM,uBAAuB,aAC3B,IAAI,IAAI,4CAA4C,OAAO,KAAK,IAAI,EACpE,OACD;AAkBD,MAAM,6BAjB8B;CAClC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD,CACiF,KAAK,kBAAkB;CACvG,cAAc,aAAa;CAC3B,SAAS,aAAa,IAAI,IAAI,uBAAuB,gBAAgB,OAAO,KAAK,IAAI,EAAE,OAAO;CAC/F,EAAE;AACH,MAAM,uBAAuB,aAC3B,IAAI,IAAI,wCAAwC,OAAO,KAAK,IAAI,EAChE,OACD;AAED,IAAa,qCAAb,MAAgD;CAC9C,cAAc,WAAkE;EAC9E,MAAM,EAAE,OAAO,YAAY;EAC3B,MAAM,cAAc,MAAM,QAAQ,eAAe,IAAI;EACrD,MAAM,UAAU,GAAG,YAAY;EAC/B,MAAM,YAAY,GAAG,YAAY;AACjC,SAAO;GACL;IACE,cAAc;IACd,SAAS,GAAG,KAAK,UAAU,KAAK,cAAc,OAAO,SAAS,SAAS,UAAU,EAAE,MAAM,EAAE,CAAC;IAC7F;GACD;IACE,cAAc;IACd,SAAS,GAAG,KAAK,UAAU,KAAK,yBAAyB,QAAQ,EAAE,MAAM,EAAE,CAAC;IAC7E;GACD;IAAE,cAAc;IAAa,SAAS,KAAK,YAAY,SAAS,UAAU;IAAE;GAC5E;IACE,cAAc,UAAU,QAAQ;IAChC,SAAS,GAAG,KAAK,UAAU,KAAK,mBAAmB,SAAS,SAAS,UAAU,EAAE,MAA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AiB;GACf,IAAI;GACJ,IAAI;GACL;EACD,QAAQ;EACR,MAAM;GAAC;GAAW;GAAQ;GAAkB;GAAW;EACvD,YAAY;EACZ,UAAU;EACV,UAAU;EACX;CAED,iBAAyB,UAA0B,MAChD,MAAM,CACN,aAAa,CACb,QAAQ,eAAe,IAAI,CAC3B,QAAQ,YAAY,GAAG,IAAI;CAE9B,qBAAqC"}
|
|
@@ -5,8 +5,15 @@ type AppDocumentAccessScope = {
|
|
|
5
5
|
mode: AppDocumentAccessMode;
|
|
6
6
|
description?: string;
|
|
7
7
|
};
|
|
8
|
+
type AppSecretSlot = {
|
|
9
|
+
id: string;
|
|
10
|
+
title: string;
|
|
11
|
+
description: string;
|
|
12
|
+
required: boolean;
|
|
13
|
+
};
|
|
8
14
|
type AppPermissions = {
|
|
9
15
|
documentAccess?: AppDocumentAccessScope[];
|
|
16
|
+
secrets?: AppSecretSlot[];
|
|
10
17
|
allowedDomains?: string[];
|
|
11
18
|
storage?: boolean | {
|
|
12
19
|
namespace?: string;
|
|
@@ -167,5 +174,5 @@ type AppManifestSummary = AppStandaloneManifestSummary | AppComponentManifestSum
|
|
|
167
174
|
declare function isAppStandaloneManifestBundle(bundle: AppManifestBundle): bundle is AppStandaloneManifestBundle;
|
|
168
175
|
declare function isAppComponentManifestBundle(bundle: AppManifestBundle): bundle is AppComponentManifestBundle;
|
|
169
176
|
//#endregion
|
|
170
|
-
export { AppArtifactArchitecture, AppArtifactTarget, AppComponentKind, AppComponentManifest, AppComponentManifestBundle, AppComponentManifestSummary, AppComponentReference, AppCoreWasmMainManifest, AppDarwinArtifactTarget, AppDistributionDeclaration, AppDocumentAccessMode, AppDocumentAccessScope, AppLinuxArtifactTarget, AppMainManifest, AppManifest, AppManifestBundle, AppManifestSummary, AppNativeArtifactTarget, AppPermissions, AppPlatformSecuritySummary, AppResolvedComponent, AppRuntimeDeclaration, AppRuntimeIsolation, AppRuntimeProfile, AppStandaloneManifest, AppStandaloneManifestBundle, AppStandaloneManifestSummary, AppStorageDeclaration, AppUiManifest, AppUniversalArtifactTarget, AppWasiHttpComponentMainManifest, AppWindowsArtifactTarget, isAppComponentManifestBundle, isAppStandaloneManifestBundle };
|
|
177
|
+
export { AppArtifactArchitecture, AppArtifactTarget, AppComponentKind, AppComponentManifest, AppComponentManifestBundle, AppComponentManifestSummary, AppComponentReference, AppCoreWasmMainManifest, AppDarwinArtifactTarget, AppDistributionDeclaration, AppDocumentAccessMode, AppDocumentAccessScope, AppLinuxArtifactTarget, AppMainManifest, AppManifest, AppManifestBundle, AppManifestSummary, AppNativeArtifactTarget, AppPermissions, AppPlatformSecuritySummary, AppResolvedComponent, AppRuntimeDeclaration, AppRuntimeIsolation, AppRuntimeProfile, AppSecretSlot, AppStandaloneManifest, AppStandaloneManifestBundle, AppStandaloneManifestSummary, AppStorageDeclaration, AppUiManifest, AppUniversalArtifactTarget, AppWasiHttpComponentMainManifest, AppWindowsArtifactTarget, isAppComponentManifestBundle, isAppStandaloneManifestBundle };
|
|
171
178
|
//# sourceMappingURL=app-manifest.types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app-manifest.types.d.ts","names":[],"sources":["../../src/types/app-manifest.types.ts"],"mappings":";KAAY,qBAAA;AAAA,KAEA,sBAAA;EACV,EAAA;EACA,IAAA,EAAM,qBAAA;EACN,WAAA;AAAA;AAAA,KAGU,cAAA;EACV,cAAA,GAAiB,sBAAA;EACjB,cAAA;EACA,OAAA;IAAsB,SAAA;EAAA;EACtB,YAAA;IACE,UAAA;IACA,aAAA;EAAA;AAAA;AAAA,KAIQ,iBAAA;AAAA,KACA,mBAAA;AAAA,KAEA,qBAAA;EACV,OAAA,EAAS,iBAAA;AAAA;AAAA,KAGC,uBAAA;AAAA,KAEA,uBAAA;EACV,IAAA;EACA,EAAA;EACA,IAAA,EAAM,uBAAA;AAAA;AAAA,KAGI,sBAAA;EACV,IAAA;EACA,EAAA;EACA,IAAA,EAAM,uBAAA;EACN,GAAA;AA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C,oBAAA,GAAuB,qBAAA;EACjC,EAAA;EACA,kBAAA;EACA,YAAA;AAAA;AAAA,KAGU,2BAAA;EACV,YAAA;EACA,YAAA;EACA,QAAA,EAAU,qBAAA;EACV,aAAA;EACA,WAAA;EACA,eAAA;EACA,mBAAA;EACA,QAAA;AAAA;AAAA,KAGU,0BAAA;EACV,YAAA;EACA,YAAA;EACA,QAAA,EAAU,oBAAA;EACV,UAAA,EAAY,oBAAA;EACZ,mBAAA;EACA,QAAA;EACA,cAAA;AAAA;AAAA,KAGU,iBAAA,GAAoB,2BAAA,GAA8B,0BAAA;AAAA,KAElD,4BAAA;EACV,aAAA;EACA,EAAA;EACA,IAAA;EACA,OAAA;EACA,WAAA;EACA,QAAA,EAAU,eAAA;EACV,MAAA;EACA,YAAA;EACA,aAAA;EACA,WAAA;EACA,QAAA;EACA,WAAA,EAAa,cAAA;AAAA;AAAA,KAGH,2BAAA;EACV,aAAA;EACA,EAAA;EACA,IAAA;EACA,OAAA;EACA,WAAA;EACA,YAAA;EACA,QAAA;EACA,cAAA;EACA,UAAA,EAAY,oBAAA;EACZ,YAAA,EAAc,0BAAA;EACd,QAAA,EAAU,0BAAA;AAAA;AAAA,KAGA,kBAAA,GAAqB,4BAAA,GAA+B,2BAAA;AAAA,iBAEhD,6BAAA,CACd,MAAA,EAAQ,iBAAA,GACP,MAAA,IAAU,2BAAA;AAAA,iBAIG,4BAAA,CACd,MAAA,EAAQ,iBAAA,GACP,MAAA,IAAU,0BAAA"}
|
|
1
|
+
{"version":3,"file":"app-manifest.types.d.ts","names":[],"sources":["../../src/types/app-manifest.types.ts"],"mappings":";KAAY,qBAAA;AAAA,KAEA,sBAAA;EACV,EAAA;EACA,IAAA,EAAM,qBAAA;EACN,WAAA;AAAA;AAAA,KAGU,aAAA;EACV,EAAA;EACA,KAAA;EACA,WAAA;EACA,QAAA;AAAA;AAAA,KAGU,cAAA;EACV,cAAA,GAAiB,sBAAA;EACjB,OAAA,GAAU,aAAA;EACV,cAA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,GACP,MAAA,IAAU,0BAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app-manifest.types.js","names":[],"sources":["../../src/types/app-manifest.types.ts"],"sourcesContent":["export type AppDocumentAccessMode = \"read\" | \"read-write\";\n\nexport type AppDocumentAccessScope = {\n id: string;\n mode: AppDocumentAccessMode;\n description?: string;\n};\n\nexport type AppPermissions = {\n documentAccess?: AppDocumentAccessScope[];\n allowedDomains?: string[];\n storage?: boolean | { namespace?: string };\n capabilities?: {\n hostBridge?: boolean;\n nativeProcess?: boolean;\n };\n};\n\nexport type AppRuntimeProfile = \"panel-only\" | \"wasi\" | \"native-process\";\nexport type AppRuntimeIsolation = \"sandboxed\" | \"host-mediated\" | \"full-user\";\n\nexport type AppRuntimeDeclaration = {\n profile: AppRuntimeProfile;\n};\n\nexport type AppArtifactArchitecture = \"x64\" | \"arm64\";\n\nexport type AppDarwinArtifactTarget = {\n kind: \"native\";\n os: \"darwin\";\n arch: AppArtifactArchitecture;\n};\n\nexport type AppLinuxArtifactTarget = {\n kind: \"native\";\n os: \"linux\";\n arch: AppArtifactArchitecture;\n abi: \"gnu\" | \"musl\";\n};\n\nexport type AppWindowsArtifactTarget = {\n kind: \"native\";\n os: \"win32\";\n arch: AppArtifactArchitecture;\n abi: \"msvc\";\n};\n\nexport type AppNativeArtifactTarget =\n | AppDarwinArtifactTarget\n | AppLinuxArtifactTarget\n | AppWindowsArtifactTarget;\n\nexport type AppUniversalArtifactTarget = {\n kind: \"universal\";\n};\n\nexport type AppArtifactTarget =\n | AppUniversalArtifactTarget\n | AppNativeArtifactTarget;\n\nexport type AppDistributionDeclaration =\n | { mode: \"universal\" }\n | {\n mode: \"targeted\";\n targets: AppNativeArtifactTarget[];\n };\n\nexport type AppStorageDeclaration = {\n scope: \"global\";\n schemaVersion: number;\n};\n\nexport type AppPlatformSecuritySummary = {\n runtimeProfile: AppRuntimeProfile;\n isolation: AppRuntimeIsolation;\n hasServiceComponents: boolean;\n inferred: boolean;\n permissions: AppPermissions;\n};\n\nexport type AppCoreWasmMainManifest = {\n kind: \"wasm\";\n entry: string;\n export: string;\n action: string;\n};\n\nexport type AppWasiHttpComponentMainManifest = {\n kind: \"wasi-http-component\";\n entry: string;\n};\n\nexport type AppMainManifest = AppCoreWasmMainManifest | AppWasiHttpComponentMainManifest;\n\nexport type AppUiManifest = {\n entry: string;\n};\n\nexport type AppStandaloneManifest = {\n schemaVersion: 1;\n id: string;\n name: string;\n version: string;\n description?: string;\n icon?: string;\n main: AppMainManifest;\n ui: AppUiManifest;\n permissions?: AppPermissions;\n};\n\nexport type AppComponentKind = \"panel\" | \"service\";\n\nexport type AppComponentReference = {\n kind: AppComponentKind;\n path: string;\n};\n\nexport type AppComponentManifest = {\n schemaVersion: 2;\n id: string;\n name: string;\n version: string;\n description?: string;\n icon?: string;\n engines?: {\n nextclaw?: string;\n };\n presentation?: {\n primaryPanel?: string;\n };\n runtime?: AppRuntimeDeclaration;\n distribution?: AppDistributionDeclaration;\n storage?: AppStorageDeclaration;\n permissions?: AppPermissions;\n components: AppComponentReference[];\n};\n\nexport type AppManifest = AppStandaloneManifest | AppComponentManifest;\n\nexport type AppResolvedComponent = AppComponentReference & {\n id: string;\n componentDirectory: string;\n manifestPath: string;\n};\n\nexport type AppStandaloneManifestBundle = {\n appDirectory: string;\n manifestPath: string;\n manifest: AppStandaloneManifest;\n mainEntryPath: string;\n uiEntryPath: string;\n uiDirectoryPath: string;\n assetsDirectoryPath: string;\n iconPath?: string;\n};\n\nexport type AppComponentManifestBundle = {\n appDirectory: string;\n manifestPath: string;\n manifest: AppComponentManifest;\n components: AppResolvedComponent[];\n assetsDirectoryPath: string;\n iconPath?: string;\n primaryPanelId?: string;\n};\n\nexport type AppManifestBundle = AppStandaloneManifestBundle | AppComponentManifestBundle;\n\nexport type AppStandaloneManifestSummary = {\n schemaVersion: 1;\n id: string;\n name: string;\n version: string;\n description?: string;\n mainKind: AppMainManifest[\"kind\"];\n action?: string;\n manifestPath: string;\n mainEntryPath: string;\n uiEntryPath: string;\n iconPath?: string;\n permissions: AppPermissions;\n};\n\nexport type AppComponentManifestSummary = {\n schemaVersion: 2;\n id: string;\n name: string;\n version: string;\n description?: string;\n manifestPath: string;\n iconPath?: string;\n primaryPanelId?: string;\n components: AppResolvedComponent[];\n distribution: AppDistributionDeclaration;\n security: AppPlatformSecuritySummary;\n};\n\nexport type AppManifestSummary = AppStandaloneManifestSummary | AppComponentManifestSummary;\n\nexport function isAppStandaloneManifestBundle(\n bundle: AppManifestBundle,\n): bundle is AppStandaloneManifestBundle {\n return bundle.manifest.schemaVersion === 1;\n}\n\nexport function isAppComponentManifestBundle(\n bundle: AppManifestBundle,\n): bundle is AppComponentManifestBundle {\n return bundle.manifest.schemaVersion === 2;\n}\n"],"mappings":";
|
|
1
|
+
{"version":3,"file":"app-manifest.types.js","names":[],"sources":["../../src/types/app-manifest.types.ts"],"sourcesContent":["export type AppDocumentAccessMode = \"read\" | \"read-write\";\n\nexport type AppDocumentAccessScope = {\n id: string;\n mode: AppDocumentAccessMode;\n description?: string;\n};\n\nexport type AppSecretSlot = {\n id: string;\n title: string;\n description: string;\n required: boolean;\n};\n\nexport type AppPermissions = {\n documentAccess?: AppDocumentAccessScope[];\n secrets?: AppSecretSlot[];\n allowedDomains?: string[];\n storage?: boolean | { namespace?: string };\n capabilities?: {\n hostBridge?: boolean;\n nativeProcess?: boolean;\n };\n};\n\nexport type AppRuntimeProfile = \"panel-only\" | \"wasi\" | \"native-process\";\nexport type AppRuntimeIsolation = \"sandboxed\" | \"host-mediated\" | \"full-user\";\n\nexport type AppRuntimeDeclaration = {\n profile: AppRuntimeProfile;\n};\n\nexport type AppArtifactArchitecture = \"x64\" | \"arm64\";\n\nexport type AppDarwinArtifactTarget = {\n kind: \"native\";\n os: \"darwin\";\n arch: AppArtifactArchitecture;\n};\n\nexport type AppLinuxArtifactTarget = {\n kind: \"native\";\n os: \"linux\";\n arch: AppArtifactArchitecture;\n abi: \"gnu\" | \"musl\";\n};\n\nexport type AppWindowsArtifactTarget = {\n kind: \"native\";\n os: \"win32\";\n arch: AppArtifactArchitecture;\n abi: \"msvc\";\n};\n\nexport type AppNativeArtifactTarget =\n | AppDarwinArtifactTarget\n | AppLinuxArtifactTarget\n | AppWindowsArtifactTarget;\n\nexport type AppUniversalArtifactTarget = {\n kind: \"universal\";\n};\n\nexport type AppArtifactTarget =\n | AppUniversalArtifactTarget\n | AppNativeArtifactTarget;\n\nexport type AppDistributionDeclaration =\n | { mode: \"universal\" }\n | {\n mode: \"targeted\";\n targets: AppNativeArtifactTarget[];\n };\n\nexport type AppStorageDeclaration = {\n scope: \"global\";\n schemaVersion: number;\n};\n\nexport type AppPlatformSecuritySummary = {\n runtimeProfile: AppRuntimeProfile;\n isolation: AppRuntimeIsolation;\n hasServiceComponents: boolean;\n inferred: boolean;\n permissions: AppPermissions;\n};\n\nexport type AppCoreWasmMainManifest = {\n kind: \"wasm\";\n entry: string;\n export: string;\n action: string;\n};\n\nexport type AppWasiHttpComponentMainManifest = {\n kind: \"wasi-http-component\";\n entry: string;\n};\n\nexport type AppMainManifest = AppCoreWasmMainManifest | AppWasiHttpComponentMainManifest;\n\nexport type AppUiManifest = {\n entry: string;\n};\n\nexport type AppStandaloneManifest = {\n schemaVersion: 1;\n id: string;\n name: string;\n version: string;\n description?: string;\n icon?: string;\n main: AppMainManifest;\n ui: AppUiManifest;\n permissions?: AppPermissions;\n};\n\nexport type AppComponentKind = \"panel\" | \"service\";\n\nexport type AppComponentReference = {\n kind: AppComponentKind;\n path: string;\n};\n\nexport type AppComponentManifest = {\n schemaVersion: 2;\n id: string;\n name: string;\n version: string;\n description?: string;\n icon?: string;\n engines?: {\n nextclaw?: string;\n };\n presentation?: {\n primaryPanel?: string;\n };\n runtime?: AppRuntimeDeclaration;\n distribution?: AppDistributionDeclaration;\n storage?: AppStorageDeclaration;\n permissions?: AppPermissions;\n components: AppComponentReference[];\n};\n\nexport type AppManifest = AppStandaloneManifest | AppComponentManifest;\n\nexport type AppResolvedComponent = AppComponentReference & {\n id: string;\n componentDirectory: string;\n manifestPath: string;\n};\n\nexport type AppStandaloneManifestBundle = {\n appDirectory: string;\n manifestPath: string;\n manifest: AppStandaloneManifest;\n mainEntryPath: string;\n uiEntryPath: string;\n uiDirectoryPath: string;\n assetsDirectoryPath: string;\n iconPath?: string;\n};\n\nexport type AppComponentManifestBundle = {\n appDirectory: string;\n manifestPath: string;\n manifest: AppComponentManifest;\n components: AppResolvedComponent[];\n assetsDirectoryPath: string;\n iconPath?: string;\n primaryPanelId?: string;\n};\n\nexport type AppManifestBundle = AppStandaloneManifestBundle | AppComponentManifestBundle;\n\nexport type AppStandaloneManifestSummary = {\n schemaVersion: 1;\n id: string;\n name: string;\n version: string;\n description?: string;\n mainKind: AppMainManifest[\"kind\"];\n action?: string;\n manifestPath: string;\n mainEntryPath: string;\n uiEntryPath: string;\n iconPath?: string;\n permissions: AppPermissions;\n};\n\nexport type AppComponentManifestSummary = {\n schemaVersion: 2;\n id: string;\n name: string;\n version: string;\n description?: string;\n manifestPath: string;\n iconPath?: string;\n primaryPanelId?: string;\n components: AppResolvedComponent[];\n distribution: AppDistributionDeclaration;\n security: AppPlatformSecuritySummary;\n};\n\nexport type AppManifestSummary = AppStandaloneManifestSummary | AppComponentManifestSummary;\n\nexport function isAppStandaloneManifestBundle(\n bundle: AppManifestBundle,\n): bundle is AppStandaloneManifestBundle {\n return bundle.manifest.schemaVersion === 1;\n}\n\nexport function isAppComponentManifestBundle(\n bundle: AppManifestBundle,\n): bundle is AppComponentManifestBundle {\n return bundle.manifest.schemaVersion === 2;\n}\n"],"mappings":";AA+MA,SAAgB,8BACd,QACuC;AACvC,QAAO,OAAO,SAAS,kBAAkB;;AAG3C,SAAgB,6BACd,QACsC;AACtC,QAAO,OAAO,SAAS,kBAAkB"}
|
|
@@ -5,6 +5,12 @@ import { AppInstanceRecord } from "./app-storage.types.js";
|
|
|
5
5
|
import { AppPublisher } from "./app-remote-registry.types.js";
|
|
6
6
|
|
|
7
7
|
//#region src/types/app-registry.types.d.ts
|
|
8
|
+
type AppSecretBinding = {
|
|
9
|
+
source: "env" | "file" | "exec";
|
|
10
|
+
provider?: string;
|
|
11
|
+
id: string;
|
|
12
|
+
};
|
|
13
|
+
type AppSecretBindingMap = Record<string, AppSecretBinding>;
|
|
8
14
|
type AppInstallSourceKind = "bundle" | "directory" | "registry";
|
|
9
15
|
type AppRegistryInstalledVersion = {
|
|
10
16
|
version: string;
|
|
@@ -37,6 +43,7 @@ type AppRegistryAppRecord = {
|
|
|
37
43
|
defaultInstance: AppInstanceRecord;
|
|
38
44
|
installedVersions: Record<string, AppRegistryInstalledVersion>;
|
|
39
45
|
grants: AppDocumentGrantMap;
|
|
46
|
+
secretBindings: AppSecretBindingMap;
|
|
40
47
|
};
|
|
41
48
|
type AppRegistry = {
|
|
42
49
|
schemaVersion: 1;
|
|
@@ -46,5 +53,5 @@ type AppRegistry = {
|
|
|
46
53
|
}>;
|
|
47
54
|
};
|
|
48
55
|
//#endregion
|
|
49
|
-
export { AppInstallSourceKind, AppRegistry, AppRegistryAppRecord, AppRegistryInstalledVersion };
|
|
56
|
+
export { AppInstallSourceKind, AppRegistry, AppRegistryAppRecord, AppRegistryInstalledVersion, AppSecretBinding, AppSecretBindingMap };
|
|
50
57
|
//# sourceMappingURL=app-registry.types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app-registry.types.d.ts","names":[],"sources":["../../src/types/app-registry.types.ts"],"mappings":";;;;;;;KAWY,oBAAA;AAAA,KAEA,2BAAA;EACV,OAAA;EACA,gBAAA;EACA,UAAA,EAAY,oBAAA;EACZ,SAAA;EACA,WAAA;EACA,gBAAA,GAAmB,mBAAA;EACnB,WAAA,EAAa,cAAA;EACb,WAAA;EACA,SAAA;EACA,MAAA;EACA,MAAA,GAAS,iBAAA;EACT,SAAA,GAAY,YAAA;EACZ,qBAAA;EACA,UAAA,GAAa,oBAAA;EACb,cAAA;EACA,QAAA,GAAW,0BAAA;EACX,iBAAA;EACA,aAAA;AAAA;AAAA,KAGU,oBAAA;EACV,KAAA;EACA,IAAA;EACA,WAAA;EACA,SAAA,GAAY,YAAA;EACZ,aAAA;EACA,OAAA;EACA,aAAA;EACA,eAAA,EAAiB,iBAAA;EACjB,iBAAA,EAAmB,MAAA,SAAe,2BAAA;EAClC,MAAA,EAAQ,mBAAA;AAAA;AAAA,
|
|
1
|
+
{"version":3,"file":"app-registry.types.d.ts","names":[],"sources":["../../src/types/app-registry.types.ts"],"mappings":";;;;;;;KAWY,gBAAA;EACV,MAAA;EACA,QAAA;EACA,EAAA;AAAA;AAAA,KAGU,mBAAA,GAAsB,MAAA,SAAe,gBAAA;AAAA,KAErC,oBAAA;AAAA,KAEA,2BAAA;EACV,OAAA;EACA,gBAAA;EACA,UAAA,EAAY,oBAAA;EACZ,SAAA;EACA,WAAA;EACA,gBAAA,GAAmB,mBAAA;EACnB,WAAA,EAAa,cAAA;EACb,WAAA;EACA,SAAA;EACA,MAAA;EACA,MAAA,GAAS,iBAAA;EACT,SAAA,GAAY,YAAA;EACZ,qBAAA;EACA,UAAA,GAAa,oBAAA;EACb,cAAA;EACA,QAAA,GAAW,0BAAA;EACX,iBAAA;EACA,aAAA;AAAA;AAAA,KAGU,oBAAA;EACV,KAAA;EACA,IAAA;EACA,WAAA;EACA,SAAA,GAAY,YAAA;EACZ,aAAA;EACA,OAAA;EACA,aAAA;EACA,eAAA,EAAiB,iBAAA;EACjB,iBAAA,EAAmB,MAAA,SAAe,2BAAA;EAClC,MAAA,EAAQ,mBAAA;EACR,cAAA,EAAgB,mBAAA;AAAA;AAAA,KAGN,WAAA;EACV,aAAA;EACA,IAAA,EAAM,MAAA,SAAe,oBAAA;EACrB,kBAAA,EAAoB,MAAA;IAClB,YAAA;EAAA;AAAA"}
|
package/package.json
CHANGED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
package wasi:clocks@0.2.6;
|
|
2
|
+
/// WASI Monotonic Clock is a clock API intended to let users measure elapsed
|
|
3
|
+
/// time.
|
|
4
|
+
///
|
|
5
|
+
/// It is intended to be portable at least between Unix-family platforms and
|
|
6
|
+
/// Windows.
|
|
7
|
+
///
|
|
8
|
+
/// A monotonic clock is a clock which has an unspecified initial value, and
|
|
9
|
+
/// successive reads of the clock will produce non-decreasing values.
|
|
10
|
+
@since(version = 0.2.0)
|
|
11
|
+
interface monotonic-clock {
|
|
12
|
+
@since(version = 0.2.0)
|
|
13
|
+
use wasi:io/poll@0.2.6.{pollable};
|
|
14
|
+
|
|
15
|
+
/// An instant in time, in nanoseconds. An instant is relative to an
|
|
16
|
+
/// unspecified initial value, and can only be compared to instances from
|
|
17
|
+
/// the same monotonic-clock.
|
|
18
|
+
@since(version = 0.2.0)
|
|
19
|
+
type instant = u64;
|
|
20
|
+
|
|
21
|
+
/// A duration of time, in nanoseconds.
|
|
22
|
+
@since(version = 0.2.0)
|
|
23
|
+
type duration = u64;
|
|
24
|
+
|
|
25
|
+
/// Read the current value of the clock.
|
|
26
|
+
///
|
|
27
|
+
/// The clock is monotonic, therefore calling this function repeatedly will
|
|
28
|
+
/// produce a sequence of non-decreasing values.
|
|
29
|
+
@since(version = 0.2.0)
|
|
30
|
+
now: func() -> instant;
|
|
31
|
+
|
|
32
|
+
/// Query the resolution of the clock. Returns the duration of time
|
|
33
|
+
/// corresponding to a clock tick.
|
|
34
|
+
@since(version = 0.2.0)
|
|
35
|
+
resolution: func() -> duration;
|
|
36
|
+
|
|
37
|
+
/// Create a `pollable` which will resolve once the specified instant
|
|
38
|
+
/// has occurred.
|
|
39
|
+
@since(version = 0.2.0)
|
|
40
|
+
subscribe-instant: func(
|
|
41
|
+
when: instant,
|
|
42
|
+
) -> pollable;
|
|
43
|
+
|
|
44
|
+
/// Create a `pollable` that will resolve after the specified duration has
|
|
45
|
+
/// elapsed from the time this function is invoked.
|
|
46
|
+
@since(version = 0.2.0)
|
|
47
|
+
subscribe-duration: func(
|
|
48
|
+
when: duration,
|
|
49
|
+
) -> pollable;
|
|
50
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
package wasi:clocks@0.2.6;
|
|
2
|
+
|
|
3
|
+
@unstable(feature = clocks-timezone)
|
|
4
|
+
interface timezone {
|
|
5
|
+
@unstable(feature = clocks-timezone)
|
|
6
|
+
use wall-clock.{datetime};
|
|
7
|
+
|
|
8
|
+
/// Return information needed to display the given `datetime`. This includes
|
|
9
|
+
/// the UTC offset, the time zone name, and a flag indicating whether
|
|
10
|
+
/// daylight saving time is active.
|
|
11
|
+
///
|
|
12
|
+
/// If the timezone cannot be determined for the given `datetime`, return a
|
|
13
|
+
/// `timezone-display` for `UTC` with a `utc-offset` of 0 and no daylight
|
|
14
|
+
/// saving time.
|
|
15
|
+
@unstable(feature = clocks-timezone)
|
|
16
|
+
display: func(when: datetime) -> timezone-display;
|
|
17
|
+
|
|
18
|
+
/// The same as `display`, but only return the UTC offset.
|
|
19
|
+
@unstable(feature = clocks-timezone)
|
|
20
|
+
utc-offset: func(when: datetime) -> s32;
|
|
21
|
+
|
|
22
|
+
/// Information useful for displaying the timezone of a specific `datetime`.
|
|
23
|
+
///
|
|
24
|
+
/// This information may vary within a single `timezone` to reflect daylight
|
|
25
|
+
/// saving time adjustments.
|
|
26
|
+
@unstable(feature = clocks-timezone)
|
|
27
|
+
record timezone-display {
|
|
28
|
+
/// The number of seconds difference between UTC time and the local
|
|
29
|
+
/// time of the timezone.
|
|
30
|
+
///
|
|
31
|
+
/// The returned value will always be less than 86400 which is the
|
|
32
|
+
/// number of seconds in a day (24*60*60).
|
|
33
|
+
///
|
|
34
|
+
/// In implementations that do not expose an actual time zone, this
|
|
35
|
+
/// should return 0.
|
|
36
|
+
utc-offset: s32,
|
|
37
|
+
|
|
38
|
+
/// The abbreviated name of the timezone to display to a user. The name
|
|
39
|
+
/// `UTC` indicates Coordinated Universal Time. Otherwise, this should
|
|
40
|
+
/// reference local standards for the name of the time zone.
|
|
41
|
+
///
|
|
42
|
+
/// In implementations that do not expose an actual time zone, this
|
|
43
|
+
/// should be the string `UTC`.
|
|
44
|
+
///
|
|
45
|
+
/// In time zones that do not have an applicable name, a formatted
|
|
46
|
+
/// representation of the UTC offset may be returned, such as `-04:00`.
|
|
47
|
+
name: string,
|
|
48
|
+
|
|
49
|
+
/// Whether daylight saving time is active.
|
|
50
|
+
///
|
|
51
|
+
/// In implementations that do not expose an actual time zone, this
|
|
52
|
+
/// should return false.
|
|
53
|
+
in-daylight-saving-time: bool,
|
|
54
|
+
}
|
|
55
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
package wasi:clocks@0.2.6;
|
|
2
|
+
/// WASI Wall Clock is a clock API intended to let users query the current
|
|
3
|
+
/// time. The name "wall" makes an analogy to a "clock on the wall", which
|
|
4
|
+
/// is not necessarily monotonic as it may be reset.
|
|
5
|
+
///
|
|
6
|
+
/// It is intended to be portable at least between Unix-family platforms and
|
|
7
|
+
/// Windows.
|
|
8
|
+
///
|
|
9
|
+
/// A wall clock is a clock which measures the date and time according to
|
|
10
|
+
/// some external reference.
|
|
11
|
+
///
|
|
12
|
+
/// External references may be reset, so this clock is not necessarily
|
|
13
|
+
/// monotonic, making it unsuitable for measuring elapsed time.
|
|
14
|
+
///
|
|
15
|
+
/// It is intended for reporting the current date and time for humans.
|
|
16
|
+
@since(version = 0.2.0)
|
|
17
|
+
interface wall-clock {
|
|
18
|
+
/// A time and date in seconds plus nanoseconds.
|
|
19
|
+
@since(version = 0.2.0)
|
|
20
|
+
record datetime {
|
|
21
|
+
seconds: u64,
|
|
22
|
+
nanoseconds: u32,
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/// Read the current value of the clock.
|
|
26
|
+
///
|
|
27
|
+
/// This clock is not monotonic, therefore calling this function repeatedly
|
|
28
|
+
/// will not necessarily produce a sequence of non-decreasing values.
|
|
29
|
+
///
|
|
30
|
+
/// The returned timestamps represent the number of seconds since
|
|
31
|
+
/// 1970-01-01T00:00:00Z, also known as [POSIX's Seconds Since the Epoch],
|
|
32
|
+
/// also known as [Unix Time].
|
|
33
|
+
///
|
|
34
|
+
/// The nanoseconds field of the output is always less than 1000000000.
|
|
35
|
+
///
|
|
36
|
+
/// [POSIX's Seconds Since the Epoch]: https://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_xbd_chap04.html#tag_21_04_16
|
|
37
|
+
/// [Unix Time]: https://en.wikipedia.org/wiki/Unix_time
|
|
38
|
+
@since(version = 0.2.0)
|
|
39
|
+
now: func() -> datetime;
|
|
40
|
+
|
|
41
|
+
/// Query the resolution of the clock.
|
|
42
|
+
///
|
|
43
|
+
/// The nanoseconds field of the output is always less than 1000000000.
|
|
44
|
+
@since(version = 0.2.0)
|
|
45
|
+
resolution: func() -> datetime;
|
|
46
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
package wasi:config@0.2.0-draft-2024-09-27;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/// This interface defines a handler of incoming HTTP Requests. It should
|
|
2
|
+
/// be exported by components which can respond to HTTP Requests.
|
|
3
|
+
@since(version = 0.2.0)
|
|
4
|
+
interface incoming-handler {
|
|
5
|
+
@since(version = 0.2.0)
|
|
6
|
+
use types.{incoming-request, response-outparam};
|
|
7
|
+
|
|
8
|
+
/// This function is invoked with an incoming HTTP Request, and a resource
|
|
9
|
+
/// `response-outparam` which provides the capability to reply with an HTTP
|
|
10
|
+
/// Response. The response is sent by calling the `response-outparam.set`
|
|
11
|
+
/// method, which allows execution to continue after the response has been
|
|
12
|
+
/// sent. This enables both streaming to the response body, and performing other
|
|
13
|
+
/// work.
|
|
14
|
+
///
|
|
15
|
+
/// The implementor of this function must write a response to the
|
|
16
|
+
/// `response-outparam` before returning, or else the caller will respond
|
|
17
|
+
/// with an error on its behalf.
|
|
18
|
+
@since(version = 0.2.0)
|
|
19
|
+
handle: func(
|
|
20
|
+
request: incoming-request,
|
|
21
|
+
response-out: response-outparam
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/// This interface defines a handler of outgoing HTTP Requests. It should be
|
|
26
|
+
/// imported by components which wish to make HTTP Requests.
|
|
27
|
+
@since(version = 0.2.0)
|
|
28
|
+
interface outgoing-handler {
|
|
29
|
+
@since(version = 0.2.0)
|
|
30
|
+
use types.{
|
|
31
|
+
outgoing-request, request-options, future-incoming-response, error-code
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
/// This function is invoked with an outgoing HTTP Request, and it returns
|
|
35
|
+
/// a resource `future-incoming-response` which represents an HTTP Response
|
|
36
|
+
/// which may arrive in the future.
|
|
37
|
+
///
|
|
38
|
+
/// The `options` argument accepts optional parameters for the HTTP
|
|
39
|
+
/// protocol's transport layer.
|
|
40
|
+
///
|
|
41
|
+
/// This function may return an error if the `outgoing-request` is invalid
|
|
42
|
+
/// or not allowed to be made. Otherwise, protocol errors are reported
|
|
43
|
+
/// through the `future-incoming-response`.
|
|
44
|
+
@since(version = 0.2.0)
|
|
45
|
+
handle: func(
|
|
46
|
+
request: outgoing-request,
|
|
47
|
+
options: option<request-options>
|
|
48
|
+
) -> result<future-incoming-response, error-code>;
|
|
49
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
package wasi:http@0.2.6;
|